@senseihq/emaki-svelte 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,12 +23,16 @@ render the article text on the server and let the components hydrate.
23
23
 
24
24
  | Component | Props |
25
25
  |---|---|
26
- | `MotionScene` | `film`, `scene`, `layout` (`figure`), `locale`, `autoplay` (true) |
27
- | `MotionShow` | `film`, `locale`, `layout` (`landscape`), `controls` (true), `slide`, `loop`, `bind:show` (state + controller) |
28
- | `ScenePlayer` | `player: ScenePlayerState`, `locale`, `controls` |
29
- | `ShowPage` | `film`, `layout`, `locale`, `capture` |
26
+ | `MotionScene` | `film`, `scene`, `layout` (`figure`), `locale`, `mode` (`auto`), `autoplay` (true), `t` (drive it yourself), `hold` (2 s rest before looping), `label` (alt text); a still under reduced motion; a sound button when the scene has sound (its slice of the score, its narration) |
27
+ | `MotionShow` | `film`, `locale`, `layout` (`landscape`), `mode` (`auto`), `poster` (cover frame first; `title`, `length` on it), `cover` (an image URL shown with the play button; the show is created on the first click, sound on), `fullscreenHref`, `controls` (true), `slide`, `loop`, `bind:show` (state + controller) |
28
+ | `ScenePlayer` | `player: ScenePlayerState`, `locale`, `mode` (`auto`), `controls` |
29
+ | `ShowPage` | `film`, `layout`, `locale`, `mode` (capture: `light`), `src` (`json`/`js`, forces the scene source), `capture` |
30
+
31
+ `mode` is `light`, `dark` or `auto`. Auto follows the page's `data-mode` (as rokkit's `themable` sets it), else the
32
+ OS, and the scenes redraw when it changes. A film draws dark only if it has a dark look (see @senseihq/emaki).
30
33
 
31
34
  `reactivePlayer(() => player)` and `reactiveShow()` give Svelte-reactive reads of the core's state classes for your
32
- own chrome. Keys on the player: ←/→ scene, Space play/pause, M sound, O orientation.
35
+ own chrome. Keys on the player: ←/→ scene, Space play/pause, M sound, O orientation, R replay the scene, Home from
36
+ the top, F fullscreen (`showKey` in the core, the same in every wrapper). The bar shows a progress tick per scene.
33
37
 
34
38
  MIT © SenecaGlobal
@@ -1,26 +1,64 @@
1
1
  <script lang="ts">
2
- // An article figure: one scene, looping while it is on screen. <MotionScene film="..." scene="..." />
2
+ // An article figure: one scene, looping while it is on screen with a `hold` s rest on its last frame, or a still
3
+ // under reduced motion. Pass `t` to drive it yourself. When the scene has sound (its slice of the film's score, its
4
+ // narration, or both), a speaker button plays it in step with the loop (off until the reader turns it on). <MotionScene film="..." scene="..." />
3
5
  import { onMount, untrack } from 'svelte';
4
- import { attachScene, figurePlayer, type Layout } from '@senseihq/emaki';
6
+ import { attachScene, figurePlayer, sceneSound, type Layout, type Mode } from '@senseihq/emaki';
5
7
 
6
- let { film, scene, layout = 'figure', locale = 'en', autoplay = true, class: cls = '' }:
7
- { film: string; scene: string; layout?: Layout; locale?: string; autoplay?: boolean; class?: string } = $props();
8
+ let { film, scene, layout = 'figure', locale = 'en', mode = 'auto', autoplay = true, t = undefined, hold = 2, label = '', class: cls = '' }:
9
+ { film: string; scene: string; layout?: Layout; locale?: string; mode?: Mode; autoplay?: boolean; t?: number; hold?: number; label?: string; class?: string } = $props();
8
10
 
9
11
  let host: HTMLDivElement;
10
12
  let width = $state(0);
13
+ let hasSound = $state(false), soundOn = $state(false);
11
14
  const player = figurePlayer({ film: '', scene: '', layout: 'figure' });
12
15
  let view: ReturnType<typeof attachScene> | null = null;
16
+ let sound: ReturnType<typeof sceneSound> | null = null;
13
17
 
14
18
  onMount(() => {
15
19
  player.load({ film, scene, layout });
16
- view = attachScene(host, player, { locale, autoplay });
20
+ player.hold = hold;
21
+ sound = sceneSound(film, scene, locale);
22
+ view = attachScene(host, player, { locale, mode, autoplay: autoplay && t === undefined, sound });
23
+ sound.available.then((ok) => (hasSound = ok && t === undefined && !player.still));
17
24
  return () => view?.destroy();
18
25
  });
19
26
  $effect(() => { const ref = { film, scene, layout }; untrack(() => { if (view && (ref.film !== player.ref?.film || ref.scene !== player.ref?.scene || ref.layout !== player.ref?.layout)) player.load(ref); }); });
20
27
  $effect(() => { view?.setLocale(locale); });
28
+ $effect(() => { view?.setMode(mode); });
29
+ $effect(() => { player.hold = hold; });
30
+ $effect(() => { if (t !== undefined && view) untrack(() => { player.pause(); player.seek(t!); }); });
21
31
  $effect(() => { if (width) view?.fit(width); });
32
+
33
+ async function toggleSound() {
34
+ if (!sound) return;
35
+ await sound.toggle(player.t);
36
+ soundOn = sound.on;
37
+ }
22
38
  </script>
23
39
 
24
- <div class="motion-scene {cls}" bind:clientWidth={width}><div bind:this={host}></div></div>
40
+ <div class="motion-scene {cls}" bind:clientWidth={width} role="img" aria-label={label || undefined}>
41
+ <div bind:this={host}></div>
42
+ {#if hasSound}
43
+ <button class="ms-snd" onclick={toggleSound} aria-pressed={soundOn} aria-label={soundOn ? 'Turn sound off' : 'Turn sound on'} title={soundOn ? 'Sound on' : 'Sound off'}>
44
+ <svg viewBox="0 0 24 24" aria-hidden="true">
45
+ <path d="M4 9h4l5-4v14l-5-4H4z" />
46
+ {#if soundOn}<path class="w" d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12" />{:else}<path class="w" d="M17 9l5 6M22 9l-5 6" />{/if}
47
+ </svg>
48
+ </button>
49
+ {/if}
50
+ </div>
25
51
 
26
- <style>.motion-scene { width: 100%; }</style>
52
+ <style>
53
+ .motion-scene { position: relative; width: 100%; }
54
+ .ms-snd {
55
+ position: absolute; right: 10px; bottom: 10px; width: 34px; height: 34px; padding: 6px; border-radius: 50%;
56
+ /* Its own colours, like video controls: it sits on the scene, whose mode can differ from the page's, so it must
57
+ not borrow the page's text colour or system colours (Canvas turns dark with the OS). */
58
+ border: 1px solid rgb(255 255 255 / 0.3); background: rgb(20 18 15 / 0.7); color: #fff;
59
+ cursor: pointer; opacity: 0.8; transition: opacity 0.15s;
60
+ }
61
+ .ms-snd:hover, .ms-snd:focus-visible, .ms-snd[aria-pressed='true'] { opacity: 1; }
62
+ .ms-snd svg { width: 100%; height: 100%; fill: currentColor; }
63
+ .ms-snd .w { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
64
+ </style>
@@ -1,10 +1,14 @@
1
- import { type Layout } from '@senseihq/emaki';
1
+ import { type Layout, type Mode } from '@senseihq/emaki';
2
2
  type $$ComponentProps = {
3
3
  film: string;
4
4
  scene: string;
5
5
  layout?: Layout;
6
6
  locale?: string;
7
+ mode?: Mode;
7
8
  autoplay?: boolean;
9
+ t?: number;
10
+ hold?: number;
11
+ label?: string;
8
12
  class?: string;
9
13
  };
10
14
  declare const MotionScene: import("svelte").Component<$$ComponentProps, {}, "">;
@@ -1,54 +1,87 @@
1
1
  <script lang="ts">
2
2
  // The story player: a film's scenes as slides, fitted to its box. Keys: ←/→ scene, Space play/pause, M sound,
3
- // O orientation. Give it a size (it fills its parent). bind:show to drive it from your own chrome.
3
+ // O orientation, R replay the scene, Home from the top, F fullscreen. With `poster` it opens on the film's cover
4
+ // with a play button, and the first click plays it from the top with sound on. With `cover` it paints that image
5
+ // instead and creates nothing until the first click (a fast first paint, and a sensible page without JS). Give it a
6
+ // size (it fills its parent). bind:show to drive it from your own chrome.
4
7
  import { onMount, untrack } from 'svelte';
5
- import { createShow, type Layout } from '@senseihq/emaki';
8
+ import { createShow, showKey, type Layout, type Mode } from '@senseihq/emaki';
6
9
  import { reactiveShow, type ShowHandle } from './player.svelte.js';
7
10
 
8
- let { film, locale = 'en', layout = 'landscape', controls = true, slide = 1, loop = false, show = $bindable() }:
9
- { film: string; locale?: string; layout?: Layout; controls?: boolean; slide?: number; loop?: boolean; show?: ShowHandle } = $props();
11
+ let {
12
+ film, locale = 'en', layout = 'landscape', mode = 'auto', controls = true, slide = 1, loop = false,
13
+ poster = false, cover = '', title = '', length = '', fullscreenHref = '', show = $bindable(),
14
+ }: {
15
+ film: string; locale?: string; layout?: Layout; mode?: Mode; controls?: boolean; slide?: number; loop?: boolean;
16
+ /** Open on the cover with a play button. */ poster?: boolean;
17
+ /** An image (URL) to show with the play button; the show is created on the first click. */ cover?: string;
18
+ /** The film's name and running time, for the poster's label and chip. */ title?: string; length?: string;
19
+ /** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */ fullscreenHref?: string;
20
+ show?: ShowHandle;
21
+ } = $props();
10
22
 
11
23
  let box: HTMLDivElement, stage: HTMLDivElement;
12
24
  let w = $state(0), h = $state(0);
13
25
  const s = reactiveShow();
14
26
 
15
- // Each (re)start gets a ticket, so a slow createShow that a newer one overtook is thrown away.
16
- let ticket = 0;
27
+ // Each (re)start gets a ticket, so a slow createShow that a newer one overtook is thrown away. The poster shows
28
+ // only until the reader first plays: a language or mode change after that restarts without it.
29
+ let ticket = 0, begun = false;
30
+ // With a cover nothing is created until the reader clicks it; that click then starts the show (sound on).
31
+ let waiting = $state(untrack(() => !!cover)), autoplay = false;
32
+ $effect(() => { if (s.started && s.api) begun = true; });
17
33
  async function start() {
18
- const mine = ++ticket;
34
+ const mine = ++ticket, play = autoplay;
35
+ autoplay = false;
19
36
  s.detach();
20
- const made = await createShow(stage, film, { locale, layout, slide, loop });
37
+ const made = await createShow(stage, film, { locale, layout, mode, slide, loop, poster: (poster || play) && !begun });
21
38
  if (mine !== ticket) return made.destroy();
22
39
  s.attach(made);
23
40
  show = s;
24
41
  made.fit(w, h);
42
+ if (play) await made.start();
25
43
  }
44
+ function open() { autoplay = true; waiting = false; }
26
45
  onMount(() => () => { ticket++; s.detach(); });
27
- // Starts on mount and restarts when the film or language changes (and on nothing else: untrack).
28
- $effect(() => { film; locale; untrack(start); });
46
+ // Starts on mount and restarts when the film, language or mode changes (and on nothing else: untrack).
47
+ $effect(() => { film; locale; mode; if (!waiting) untrack(start); });
29
48
  $effect(() => { if (s.api && s.layout !== layout) s.api.setLayout(layout); });
30
49
  $effect(() => { s.layout; s.api?.fit(w, h); });
31
50
 
32
51
  function onkeydown(e: KeyboardEvent) {
33
- const a = s.api; if (!a) return;
34
- const k = e.key.toLowerCase();
35
- if (k === 'arrowright') a.next(); else if (k === 'arrowleft') a.prev();
36
- else if (k === ' ') { a.toggle(); e.preventDefault(); }
37
- else if (k === 'm') a.setSound(!s.sound);
38
- else if (k === 'o') a.setLayout(s.layout === 'landscape' ? 'portrait' : 'landscape');
52
+ if (s.api && showKey(s.api, e, box)) e.preventDefault();
39
53
  }
40
54
  </script>
41
55
 
42
56
  <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
43
57
  <div class="motion-show" bind:this={box} tabindex="0" role="application" aria-label="Story player" {onkeydown}>
44
58
  <div class="ms-fit" bind:clientWidth={w} bind:clientHeight={h}><div class="ms-stage" bind:this={stage}></div></div>
45
- {#if controls && s.api}
59
+ {#snippet play()}
60
+ <span class="ms-play" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M8 5.5v13l11-6.5z" /></svg></span>
61
+ <span class="ms-chip">Play the film{length ? ` · ${length}` : ''}</span>
62
+ {/snippet}
63
+ {#if waiting}
64
+ <button class="ms-poster" onclick={open} aria-label="Play the film{title ? `: ${title}` : ''}">
65
+ <img class="ms-cover" src={cover} alt="" />
66
+ {@render play()}
67
+ </button>
68
+ {:else if s.api && !s.started}
69
+ <button class="ms-poster" onclick={() => s.api?.start()} aria-label="Play the film{title ? `: ${title}` : ''}">
70
+ {@render play()}
71
+ </button>
72
+ {:else if controls && s.api}
46
73
  <div class="ms-bar">
47
74
  <button onclick={() => s.api?.prev()} aria-label="Previous scene">‹</button>
48
75
  <button onclick={() => s.api?.toggle()} aria-label={s.playing ? 'Pause' : 'Play'}>{s.playing ? '❚❚' : '▶'}</button>
49
76
  <button onclick={() => s.api?.next()} aria-label="Next scene">›</button>
77
+ <div class="ms-ticks">
78
+ {#each s.ticks as tk, i (tk.id)}
79
+ <button style="flex:{tk.dur}" onclick={() => s.api?.go(i)} aria-label={tk.name}><span style="width:{tk.fill * 100}%"></span></button>
80
+ {/each}
81
+ </div>
50
82
  <span class="ms-count">{s.index + 1} / {s.count}</span>
51
83
  <button onclick={() => s.api?.setSound(!s.sound)} aria-pressed={s.sound}>{s.sound ? 'Sound on' : 'Sound off'}</button>
84
+ {#if fullscreenHref}<a class="ms-full" href={fullscreenHref} aria-label="Open full screen" title="Full screen">⤢</a>{/if}
52
85
  </div>
53
86
  {/if}
54
87
  </div>
@@ -60,4 +93,14 @@
60
93
  .ms-bar { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 8px; font: 13px system-ui; }
61
94
  .ms-bar button { min-width: 34px; height: 34px; border-radius: 17px; border: 1px solid currentColor; background: none; color: inherit; cursor: pointer; padding: 0 10px; }
62
95
  .ms-count { font-variant-numeric: tabular-nums; opacity: .7; }
96
+ .ms-ticks { flex: 1; display: flex; gap: 3px; max-width: 360px; }
97
+ .ms-bar .ms-ticks button { min-width: 0; height: 18px; padding: 7px 0; border: 0; border-radius: 0; background: linear-gradient(color-mix(in srgb, currentColor 18%, transparent), color-mix(in srgb, currentColor 18%, transparent)) center / 100% 4px no-repeat; }
98
+ .ms-ticks span { display: block; height: 4px; border-radius: 2px; background: currentColor; }
99
+ .ms-full { min-width: 34px; height: 34px; border-radius: 17px; border: 1px solid currentColor; display: grid; place-items: center; color: inherit; text-decoration: none; }
100
+ .ms-poster { position: absolute; inset: 0; border: 0; padding: 0; background: none; cursor: pointer; color: inherit; }
101
+ .ms-cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
102
+ .ms-play { position: absolute; right: 18px; bottom: 14px; width: 64px; height: 64px; border-radius: 50%; background: color-mix(in srgb, currentColor 85%, transparent); display: grid; place-items: center; transition: transform .2s; }
103
+ .ms-poster:hover .ms-play { transform: scale(1.06); }
104
+ .ms-play svg { width: 28px; height: 28px; fill: Canvas; margin-left: 3px; }
105
+ .ms-chip { position: absolute; left: 16px; bottom: 14px; padding: 6px 12px; border-radius: 999px; font: 11px/1 system-ui; letter-spacing: .1em; text-transform: uppercase; background: color-mix(in srgb, Canvas 88%, transparent); border: 1px solid color-mix(in srgb, currentColor 20%, transparent); }
63
106
  </style>
@@ -1,12 +1,18 @@
1
- import { type Layout } from '@senseihq/emaki';
1
+ import { type Layout, type Mode } from '@senseihq/emaki';
2
2
  import { type ShowHandle } from './player.svelte.js';
3
3
  type $$ComponentProps = {
4
4
  film: string;
5
5
  locale?: string;
6
6
  layout?: Layout;
7
+ mode?: Mode;
7
8
  controls?: boolean;
8
9
  slide?: number;
9
10
  loop?: boolean;
11
+ /** Open on the cover with a play button. */ poster?: boolean;
12
+ /** An image (URL) to show with the play button; the show is created on the first click. */ cover?: string;
13
+ /** The film's name and running time, for the poster's label and chip. */ title?: string;
14
+ length?: string;
15
+ /** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */ fullscreenHref?: string;
10
16
  show?: ShowHandle;
11
17
  };
12
18
  declare const MotionShow: import("svelte").Component<$$ComponentProps, {}, "show">;
@@ -2,20 +2,21 @@
2
2
  // A scene driven by a ScenePlayerState you own (an editor, an admin preview, a step-through): the state holds what
3
3
  // is loaded and where the playhead is; this mounts, renders and runs the clock. Remounts when player.key changes.
4
4
  import { onMount } from 'svelte';
5
- import { attachScene, type ScenePlayerState } from '@senseihq/emaki';
5
+ import { attachScene, type Mode, type ScenePlayerState } from '@senseihq/emaki';
6
6
  import { reactivePlayer } from './player.svelte.js';
7
7
 
8
- let { player, locale = 'en', controls = false }: { player: ScenePlayerState; locale?: string; controls?: boolean } = $props();
8
+ let { player, locale = 'en', mode = 'auto', controls = false }: { player: ScenePlayerState; locale?: string; mode?: Mode; controls?: boolean } = $props();
9
9
  const p = reactivePlayer(() => player);
10
10
  let host: HTMLDivElement;
11
11
  let width = $state(0);
12
12
  let view: ReturnType<typeof attachScene> | null = null;
13
13
 
14
14
  onMount(() => {
15
- view = attachScene(host, player, { locale });
15
+ view = attachScene(host, player, { locale, mode });
16
16
  return () => view?.destroy();
17
17
  });
18
18
  $effect(() => { view?.setLocale(locale); });
19
+ $effect(() => { view?.setMode(mode); });
19
20
  $effect(() => { if (width) view?.fit(width); });
20
21
  </script>
21
22
 
@@ -1,7 +1,8 @@
1
- import { type ScenePlayerState } from '@senseihq/emaki';
1
+ import { type Mode, type ScenePlayerState } from '@senseihq/emaki';
2
2
  type $$ComponentProps = {
3
3
  player: ScenePlayerState;
4
4
  locale?: string;
5
+ mode?: Mode;
5
6
  controls?: boolean;
6
7
  };
7
8
  declare const ScenePlayer: import("svelte").Component<$$ComponentProps, {}, "">;
@@ -2,16 +2,18 @@
2
2
  // The capture page the video pipeline drives (`emaki render` opens /show/<film>?capture=1&o=landscape&lang=en):
3
3
  // the stage at 1:1, no chrome, window.__show = { meta, ready, seek, audio }. Turn SSR off for this route.
4
4
  import { onMount } from 'svelte';
5
- import { installCapture, type Layout } from '@senseihq/emaki';
5
+ import { installCapture, type Layout, type Mode } from '@senseihq/emaki';
6
6
  import MotionShow from './MotionShow.svelte';
7
7
 
8
- let { film, layout = 'landscape', locale = 'en', capture = false }: { film: string; layout?: Layout; locale?: string; capture?: boolean } = $props();
8
+ // mode: capture renders light unless asked; the interactive player follows the page (auto).
9
+ let { film, layout = 'landscape', locale = 'en', mode, src, capture = false }:
10
+ { film: string; layout?: Layout; locale?: string; mode?: Mode; src?: 'json' | 'js'; capture?: boolean } = $props();
9
11
  let host: HTMLDivElement | undefined = $state();
10
- onMount(() => { if (capture && host) installCapture(host, film, layout, locale); });
12
+ onMount(() => { if (capture && host) installCapture(host, film, layout, locale, { mode: mode ?? 'light', src }); });
11
13
  </script>
12
14
 
13
15
  {#if capture}
14
16
  <div bind:this={host}></div>
15
17
  {:else}
16
- <div style="position:fixed;inset:0"><MotionShow {film} {layout} {locale} /></div>
18
+ <div style="position:fixed;inset:0"><MotionShow {film} {layout} {locale} mode={mode ?? 'auto'} /></div>
17
19
  {/if}
@@ -1,8 +1,10 @@
1
- import { type Layout } from '@senseihq/emaki';
1
+ import { type Layout, type Mode } from '@senseihq/emaki';
2
2
  type $$ComponentProps = {
3
3
  film: string;
4
4
  layout?: Layout;
5
5
  locale?: string;
6
+ mode?: Mode;
7
+ src?: 'json' | 'js';
6
8
  capture?: boolean;
7
9
  };
8
10
  declare const ShowPage: import("svelte").Component<$$ComponentProps, {}, "">;
@@ -1,24 +1,72 @@
1
- import type { createShow, ScenePlayerState } from '@senseihq/emaki';
1
+ import { type createShow, type Layout, type ScenePlayerState } from '@senseihq/emaki';
2
2
  /** Reactive reads of a ScenePlayerState: `p.t`, `p.playing`, `p.status` update the UI as the player changes. */
3
3
  export declare function reactivePlayer(get: () => ScenePlayerState): {
4
- readonly t: any;
5
- readonly dur: any;
6
- readonly status: any;
7
- readonly error: any;
8
- readonly playing: any;
9
- readonly key: any;
10
- readonly ref: any;
4
+ readonly t: number;
5
+ readonly dur: number;
6
+ readonly status: import("@senseihq/emaki").PlayerStatus;
7
+ readonly error: string;
8
+ readonly playing: boolean;
9
+ readonly key: string;
10
+ readonly ref: import("@senseihq/emaki").SceneRef | null;
11
11
  };
12
12
  type Show = Awaited<ReturnType<typeof createShow>>;
13
13
  export type ShowHandle = ReturnType<typeof reactiveShow>;
14
- /** Reactive state of a story player (createShow): index, playing, sound, layout, plus the controller as `api`. */
14
+ /** Reactive state of a story player (createShow): index, playhead, playing, sound, layout, whether it has started
15
+ * (a poster has not), per-scene progress ticks, plus the controller as `api`. The playhead is read once a frame. */
15
16
  export declare function reactiveShow(): {
16
- readonly api: any;
17
+ readonly api: {
18
+ film: import("@senseihq/emaki").FilmMeta;
19
+ timeline: {
20
+ duration: number;
21
+ scenes: {
22
+ start: number;
23
+ design: number;
24
+ holds: [number, number][];
25
+ voice?: number;
26
+ id: string;
27
+ name: string;
28
+ dur: number;
29
+ desc?: string;
30
+ settle?: number;
31
+ }[];
32
+ };
33
+ readonly state: {
34
+ index: number;
35
+ local: number;
36
+ playing: boolean;
37
+ sound: boolean;
38
+ layout: Layout;
39
+ started: boolean;
40
+ };
41
+ start(): Promise<void>;
42
+ replay(): void;
43
+ restart(): void;
44
+ fit(w: number, h: number): void;
45
+ go: (i: number) => void;
46
+ next: () => void;
47
+ prev: () => void;
48
+ play(): void;
49
+ pause(): void;
50
+ toggle(): void;
51
+ setSound(on: boolean): void;
52
+ setLayout(l: Layout): void;
53
+ seek(t: number): Promise<void>;
54
+ on(l: import("@senseihq/emaki").ShowListener): () => boolean;
55
+ destroy(): void;
56
+ } | null;
17
57
  readonly index: number;
58
+ readonly local: number;
18
59
  readonly playing: boolean;
19
60
  readonly sound: boolean;
20
61
  readonly layout: Layout;
21
- readonly count: any;
62
+ readonly started: boolean;
63
+ readonly count: number;
64
+ readonly ticks: {
65
+ id: string;
66
+ name: string;
67
+ dur: number;
68
+ fill: number;
69
+ }[];
22
70
  attach(s: Show): void;
23
71
  detach(): void;
24
72
  };
@@ -1,3 +1,5 @@
1
+ // Svelte 5 reactivity over the core's framework-free state: the core notifies, a $state counter makes reads tracked.
2
+ import { ticks as showTicks } from '@senseihq/emaki';
1
3
  /** Reactive reads of a ScenePlayerState: `p.t`, `p.playing`, `p.status` update the UI as the player changes. */
2
4
  export function reactivePlayer(get) {
3
5
  let v = $state(0);
@@ -13,19 +15,34 @@ export function reactivePlayer(get) {
13
15
  get ref() { return read((p) => p.ref)(); },
14
16
  };
15
17
  }
16
- /** Reactive state of a story player (createShow): index, playing, sound, layout, plus the controller as `api`. */
18
+ /** Reactive state of a story player (createShow): index, playhead, playing, sound, layout, whether it has started
19
+ * (a poster has not), per-scene progress ticks, plus the controller as `api`. The playhead is read once a frame. */
17
20
  export function reactiveShow() {
18
21
  let api = $state(null);
19
- let st = $state({ index: 0, local: 0, playing: false, sound: false, layout: 'landscape' });
20
- let off = null;
22
+ let st = $state({ index: 0, local: 0, playing: false, sound: false, layout: 'landscape', started: true });
23
+ let off = null, raf = 0;
24
+ const follow = () => {
25
+ if (api && api.state.local !== st.local)
26
+ st.local = api.state.local;
27
+ raf = requestAnimationFrame(follow);
28
+ };
21
29
  return {
22
30
  get api() { return api; },
23
31
  get index() { return st.index; },
32
+ get local() { return st.local; },
24
33
  get playing() { return st.playing; },
25
34
  get sound() { return st.sound; },
26
35
  get layout() { return st.layout; },
36
+ get started() { return st.started; },
27
37
  get count() { return api?.timeline.scenes.length ?? 0; },
28
- attach(s) { api = s; st = { ...s.state }; off = s.on((x) => { st = { ...x }; }); },
29
- detach() { off?.(); api?.destroy(); api = null; },
38
+ get ticks() { void st.index; void st.local; return api ? showTicks(api) : []; },
39
+ attach(s) {
40
+ api = s;
41
+ st = { ...s.state };
42
+ off = s.on((x) => { st = { ...x }; });
43
+ cancelAnimationFrame(raf);
44
+ raf = requestAnimationFrame(follow);
45
+ },
46
+ detach() { cancelAnimationFrame(raf); off?.(); api?.destroy(); api = null; },
30
47
  };
31
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senseihq/emaki-svelte",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Svelte 5 components for motion stories: article figures, the story player, a controlled scene player and the video capture page.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "svelte": "^5.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@senseihq/emaki": "0.1.0"
36
+ "@senseihq/emaki": "0.1.2"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@sveltejs/package": "^2.3.10",