콘텐츠로 이동

Svelte

이 콘텐츠는 아직 번역되지 않았습니다.

<script>
import { shallowEqual } from "@lumen-timeline/core";
import { editorSelector, setTimelineContext, timeline } from "@lumen-timeline/svelte";
import "@lumen-timeline/timeline/style.css";
const { editor, transport, tiles } = $props();
let snap = $state({ gridTicks: 28224000 });
let view = null;
setTimelineContext({ editor, transport });
const clip = editorSelector(
editor,
({ snapshot, selection }) => {
const found = snapshot.clips.find((c) => c.id === selection.at(-1));
return found ? { name: found.name, take: found.activeTakeId } : null;
},
shallowEqual,
);
</script>
<div {@attach timeline(() => ({ editor, transport, snap, waveforms: tiles, onview: (v) => (view = v) }))}></div>
<aside>{clip.current ? `${clip.current.name}: ${clip.current.take}` : "No clip selected"}</aside>
  • {@attach timeline(() => options)} mounts the view in its element and disposes it when the element goes. Pass a function that returns the options, so they are read inside the attachment: a changed editor, transport or renderer mounts a new view, and other options reach the mounted view. onview receives the view, and null once it is disposed.
  • editorSelector(editor, select, isEqual) returns { current }. Read current in markup, a derived value or an effect. An effect that reads it subscribes, and the subscription ends when no effect reads it. editor may be a function returning it, which a host that switches editors passes.
  • transportSelector(transport, select, isEqual) does the same for a transport’s snapshot.
  • setTimelineContext({ editor, transport }) and getTimelineContext() hand the host’s editor and transport down during component setup. A host that switches them passes an object whose properties are getters of its state.
  • The attachment uses $effect, so the package ships it as attach.svelte.js and the application’s Svelte compiles its runes, as Svelte libraries do. The package’s svelte export condition tells Vite so.