@senseihq/emaki-react 0.1.1 → 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
@@ -21,12 +21,12 @@ Call `setupMotion({ source, site, logos })` once on the client first (`emaki ini
21
21
  | Export | What |
22
22
  |---|---|
23
23
  | `MotionScene` | `film`, `scene`, `layout` (`figure`), `locale`, `mode` (`auto`), `autoplay` |
24
- | `MotionShow` | `film`, `locale`, `layout`, `mode` (`auto`), `controls`, `slide`, `loop`, `onReady(show)` |
24
+ | `MotionShow` | `film`, `locale`, `layout`, `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`, `slide`, `loop`, `onReady(show)`; the controls show a progress tick per scene |
25
25
  | `ScenePlayer` | `player`, `locale`, `mode` (`auto`), `controls` |
26
26
  | `ShowPage` | `film`, `layout`, `locale`, `mode` (capture: `light`), `src` (`json`/`js`, forces the scene source), `capture` |
27
27
  | `useScenePlayer(player)` | re-renders on every change of a `ScenePlayerState` (useSyncExternalStore) |
28
28
  | `usePlayerFor(ref)` | a player you own, pointed at `{ film, scene, layout }` |
29
- | `useShowState(show)` | `{ index, playing, sound, layout }` of a player controller |
29
+ | `useShowState(show)` | `{ index, local, playing, sound, layout, started }` of a player controller (the playhead followed once a frame) |
30
30
 
31
31
  `mode` is `light`, `dark` or `auto`. Auto follows the page's `data-mode` (as rokkit's `themable` sets it), else the
32
32
  OS, and the scenes redraw when it changes. A film draws dark only if it has a dark look (see @senseihq/emaki).
@@ -30,13 +30,24 @@ export interface MotionShowProps {
30
30
  controls?: boolean;
31
31
  slide?: number;
32
32
  loop?: boolean;
33
+ /** Open on the film's cover frame with a play button; the first click plays it from the top with sound on. */
34
+ poster?: boolean;
35
+ /** An image (URL) to show with the play button; the show is created on the first click (then plays, sound on). */
36
+ cover?: string;
37
+ /** The film's name and running time, for the play button's label and chip. */
38
+ title?: string;
39
+ length?: string;
40
+ /** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */
41
+ fullscreenHref?: string;
33
42
  /** The controller once ready (next/prev/play/pause/setSound/setLayout/seek/on), for custom chrome. */
34
43
  onReady?: (show: Show) => void;
35
44
  className?: string;
36
45
  style?: CSSProperties;
37
46
  }
38
- /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→, Space, M (sound), O (orientation). */
39
- export declare function MotionShow({ film, locale, layout, mode, controls, slide, loop, onReady, className, style }: MotionShowProps): import("react").JSX.Element;
47
+ /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→ scene, Space play/pause, M sound,
48
+ * O orientation, R replay, Home from the top, F fullscreen. `poster` opens on the cover frame; `cover` paints an
49
+ * image and creates nothing until the first click. */
50
+ export declare function MotionShow({ film, locale, layout, mode, controls, slide, loop, poster, cover, title, length, fullscreenHref, onReady, className, style }: MotionShowProps): import("react").JSX.Element;
40
51
  /** mode: capture renders light unless asked; the interactive player follows the page (auto). */
41
52
  export interface ShowPageProps {
42
53
  film: string;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // React components over @senseihq/emaki. All are client components (they need the DOM); in Next.js import them
3
3
  // from a file marked 'use client'. Call setupMotion({ source, site, logos }) once on the client first.
4
4
  import { useEffect, useRef, useState } from 'react';
5
- import { attachScene, createShow, installCapture, showKey } from '@senseihq/emaki';
5
+ import { attachScene, createShow, installCapture, showKey, ticks } from '@senseihq/emaki';
6
6
  import { usePlayerFor, useScenePlayer, useShowState, useSize, useWidth } from './hooks.js';
7
7
  /** Mounts a player's scene into a div and keeps it fitted (shared by MotionScene and ScenePlayer). */
8
8
  function useAttached(player, locale, mode, autoplay) {
@@ -32,31 +32,53 @@ export function ScenePlayer({ player, locale = 'en', mode = 'auto', controls = f
32
32
  const msg = { position: 'absolute', inset: 0, display: 'grid', placeItems: 'center', margin: 0, font: '14px system-ui' };
33
33
  return (_jsxs("div", { ref: ref, className: className, style: { position: 'relative', width: '100%' }, children: [_jsx("div", { ref: host }), p.status === 'error' && _jsx("p", { role: "alert", style: { ...msg, color: '#b42318' }, children: p.error }), p.status === 'idle' && _jsx("p", { style: { ...msg, opacity: 0.7 }, children: "Loading the scene\u2026" }), controls && p.status === 'ready' && (_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 12, marginTop: 10, font: '12px ui-monospace, monospace' }, children: [_jsx("button", { onClick: () => p.toggle(), "aria-label": p.playing ? 'Pause' : 'Play', children: p.playing ? '❚❚' : '▶' }), _jsx("input", { type: "range", "aria-label": "Seek", min: 0, max: p.dur, step: 0.05, value: p.t, onChange: (e) => p.seek(Number(e.target.value)), style: { flex: 1 } }), _jsxs("span", { children: [p.t.toFixed(1), " / ", p.dur.toFixed(1)] })] }))] }));
34
34
  }
35
- /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→, Space, M (sound), O (orientation). */
36
- export function MotionShow({ film, locale = 'en', layout = 'landscape', mode = 'auto', controls = true, slide = 1, loop = false, onReady, className, style }) {
35
+ const btn = { minWidth: 34, height: 34, borderRadius: 17, border: '1px solid currentColor', background: 'none', color: 'inherit', cursor: 'pointer', padding: '0 10px' };
36
+ const tickTrack = 'linear-gradient(color-mix(in srgb, currentColor 18%, transparent), color-mix(in srgb, currentColor 18%, transparent)) center / 100% 4px no-repeat';
37
+ /** The play button over a poster or a cover image: the label and the chip name the film and its length. */
38
+ function PlayButton({ title, length, cover, onClick }) {
39
+ return (_jsxs("button", { onClick: onClick, "aria-label": `Play the film${title ? `: ${title}` : ''}`, style: { position: 'absolute', inset: 0, border: 0, padding: 0, background: 'none', cursor: 'pointer', color: 'inherit' }, children: [cover && _jsx("img", { src: cover, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } }), _jsx("span", { "aria-hidden": "true", style: { position: 'absolute', right: 18, bottom: 14, width: 64, height: 64, borderRadius: '50%', background: 'color-mix(in srgb, currentColor 85%, transparent)', display: 'grid', placeItems: 'center' }, children: _jsx("svg", { viewBox: "0 0 24 24", style: { width: 28, height: 28, fill: 'Canvas', marginLeft: 3 }, children: _jsx("path", { d: "M8 5.5v13l11-6.5z" }) }) }), _jsxs("span", { style: { position: 'absolute', left: 16, bottom: 14, padding: '6px 12px', borderRadius: 999, font: '11px/1 system-ui', letterSpacing: '.1em', textTransform: 'uppercase', background: 'color-mix(in srgb, Canvas 88%, transparent)', border: '1px solid color-mix(in srgb, currentColor 20%, transparent)' }, children: ["Play the film", length ? ` · ${length}` : ''] })] }));
40
+ }
41
+ /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→ scene, Space play/pause, M sound,
42
+ * O orientation, R replay, Home from the top, F fullscreen. `poster` opens on the cover frame; `cover` paints an
43
+ * image and creates nothing until the first click. */
44
+ export function MotionShow({ film, locale = 'en', layout = 'landscape', mode = 'auto', controls = true, slide = 1, loop = false, poster = false, cover = '', title = '', length = '', fullscreenHref = '', onReady, className, style }) {
37
45
  const stage = useRef(null);
38
46
  const [fitRef, size] = useSize();
39
47
  const [show, setShow] = useState(null);
48
+ // With a cover nothing is created until the reader clicks; that click then starts the show (sound on). The poster
49
+ // shows only until the reader first plays: a language or mode change after that restarts without it.
50
+ const [waiting, setWaiting] = useState(() => !!cover);
51
+ const autoplay = useRef(false), begun = useRef(false);
40
52
  const st = useShowState(show);
53
+ useEffect(() => { if (st?.started && show)
54
+ begun.current = true; }, [st?.started, show]);
41
55
  useEffect(() => {
56
+ if (waiting)
57
+ return;
42
58
  let alive = true, made = null;
43
- createShow(stage.current, film, { locale, layout, mode, slide, loop }).then((s) => {
59
+ const play = autoplay.current;
60
+ autoplay.current = false;
61
+ createShow(stage.current, film, { locale, layout, mode, slide, loop, poster: (poster || play) && !begun.current }).then(async (s) => {
44
62
  if (!alive)
45
63
  return s.destroy();
46
64
  made = s;
47
65
  setShow(s);
48
66
  onReady?.(s);
67
+ if (play)
68
+ await s.start();
49
69
  });
50
70
  return () => { alive = false; made?.destroy(); setShow(null); };
51
- }, [film, locale, mode]); // eslint-disable-line react-hooks/exhaustive-deps
71
+ }, [film, locale, mode, waiting]); // eslint-disable-line react-hooks/exhaustive-deps
52
72
  useEffect(() => { if (show && show.state.layout !== layout)
53
73
  show.setLayout(layout); }, [show, layout]);
54
74
  useEffect(() => { show?.fit(size.w, size.h); }, [show, size, st?.layout]);
55
75
  // Every key (←/→, Space, M, O, R, Home, F) from the core, so all players answer the same way.
56
76
  const onKeyDown = (e) => { if (show && showKey(show, e.nativeEvent, e.currentTarget))
57
77
  e.preventDefault(); };
58
- const btn = { minWidth: 34, height: 34, borderRadius: 17, border: '1px solid currentColor', background: 'none', color: 'inherit', cursor: 'pointer', padding: '0 10px' };
59
- return (_jsxs("div", { tabIndex: 0, role: "application", "aria-label": "Story player", onKeyDown: onKeyDown, className: className, style: { position: 'relative', width: '100%', height: '100%', display: 'flex', flexDirection: 'column', outline: 'none', ...style }, children: [_jsx("div", { ref: fitRef, style: { position: 'relative', flex: 1, minHeight: 0, display: 'grid', placeItems: 'center', overflow: 'hidden' }, children: _jsx("div", { ref: stage, style: { position: 'relative' } }) }), controls && show && st && (_jsxs("div", { style: { display: 'flex', gap: 8, alignItems: 'center', justifyContent: 'center', padding: 8, font: '13px system-ui' }, children: [_jsx("button", { style: btn, onClick: () => show.prev(), "aria-label": "Previous scene", children: "\u2039" }), _jsx("button", { style: btn, onClick: () => show.toggle(), "aria-label": st.playing ? 'Pause' : 'Play', children: st.playing ? '❚❚' : '▶' }), _jsx("button", { style: btn, onClick: () => show.next(), "aria-label": "Next scene", children: "\u203A" }), _jsxs("span", { style: { opacity: 0.7 }, children: [st.index + 1, " / ", show.timeline.scenes.length] }), _jsx("button", { style: btn, onClick: () => show.setSound(!st.sound), "aria-pressed": st.sound, children: st.sound ? 'Sound on' : 'Sound off' })] }))] }));
78
+ const open = () => { autoplay.current = true; setWaiting(false); };
79
+ return (_jsxs("div", { tabIndex: 0, role: "application", "aria-label": "Story player", onKeyDown: onKeyDown, className: className, style: { position: 'relative', width: '100%', height: '100%', display: 'flex', flexDirection: 'column', outline: 'none', ...style }, children: [_jsx("div", { ref: fitRef, style: { position: 'relative', flex: 1, minHeight: 0, display: 'grid', placeItems: 'center', overflow: 'hidden' }, children: _jsx("div", { ref: stage, style: { position: 'relative' } }) }), waiting ? _jsx(PlayButton, { title: title, length: length, cover: cover, onClick: open })
80
+ : show && st && !st.started ? _jsx(PlayButton, { title: title, length: length, onClick: () => show.start() })
81
+ : controls && show && st && (_jsxs("div", { style: { display: 'flex', gap: 8, alignItems: 'center', justifyContent: 'center', padding: 8, font: '13px system-ui' }, children: [_jsx("button", { style: btn, onClick: () => show.prev(), "aria-label": "Previous scene", children: "\u2039" }), _jsx("button", { style: btn, onClick: () => show.toggle(), "aria-label": st.playing ? 'Pause' : 'Play', children: st.playing ? '❚❚' : '▶' }), _jsx("button", { style: btn, onClick: () => show.next(), "aria-label": "Next scene", children: "\u203A" }), _jsx("div", { style: { flex: 1, display: 'flex', gap: 3, maxWidth: 360 }, children: ticks(show).map((tk, i) => (_jsx("button", { onClick: () => show.go(i), "aria-label": tk.name, style: { flex: tk.dur, minWidth: 0, height: 18, padding: '7px 0', border: 0, borderRadius: 0, background: tickTrack, cursor: 'pointer', color: 'inherit' }, children: _jsx("span", { style: { display: 'block', height: 4, borderRadius: 2, background: 'currentColor', width: `${tk.fill * 100}%` } }) }, tk.id))) }), _jsxs("span", { style: { opacity: 0.7, fontVariantNumeric: 'tabular-nums' }, children: [st.index + 1, " / ", show.timeline.scenes.length] }), _jsx("button", { style: btn, onClick: () => show.setSound(!st.sound), "aria-pressed": st.sound, children: st.sound ? 'Sound on' : 'Sound off' }), fullscreenHref && _jsx("a", { href: fullscreenHref, "aria-label": "Open full screen", title: "Full screen", style: { ...btn, display: 'grid', placeItems: 'center', textDecoration: 'none', padding: 0 }, children: "\u2922" })] }))] }));
60
82
  }
61
83
  /** The /show/<film> page the video pipeline drives: with `capture`, the stage at 1:1, no chrome, window.__show. */
62
84
  export function ShowPage({ film, layout = 'landscape', locale = 'en', mode, src, capture = false }) {
package/dist/hooks.d.ts CHANGED
@@ -10,8 +10,10 @@ export interface ShowState {
10
10
  playing: boolean;
11
11
  sound: boolean;
12
12
  layout: Layout;
13
+ started: boolean;
13
14
  }
14
- /** State of a story player controller (from <MotionShow onReady>): re-renders on scene, play, sound, layout changes. */
15
+ /** State of a story player controller (from <MotionShow onReady>): re-renders on scene, play, sound, layout changes,
16
+ * and follows the playhead (read once a frame; it moves without notifications). `started` is false on a poster. */
15
17
  export declare function useShowState(show: Show | null): ShowState | null;
16
18
  /** Width of an element, tracked with a ResizeObserver. */
17
19
  export declare function useWidth<T extends HTMLElement>(): readonly [import("react").RefObject<T | null>, number];
package/dist/hooks.js CHANGED
@@ -14,17 +14,23 @@ export function usePlayerFor(ref) {
14
14
  player.load(ref); }, [key]); // eslint-disable-line react-hooks/exhaustive-deps
15
15
  return useScenePlayer(player);
16
16
  }
17
- /** State of a story player controller (from <MotionShow onReady>): re-renders on scene, play, sound, layout changes. */
17
+ /** State of a story player controller (from <MotionShow onReady>): re-renders on scene, play, sound, layout changes,
18
+ * and follows the playhead (read once a frame; it moves without notifications). `started` is false on a poster. */
18
19
  export function useShowState(show) {
19
20
  const [st, setSt] = useState(show ? show.state : null);
20
- const last = useRef(show);
21
21
  useEffect(() => {
22
- last.current = show;
23
22
  if (!show)
24
23
  return setSt(null);
25
24
  setSt(show.state);
26
25
  const off = show.on((s) => setSt({ ...s }));
27
- return () => { off(); };
26
+ let raf = 0;
27
+ const follow = () => {
28
+ const local = show.state.local;
29
+ setSt((s) => (s && s.local !== local ? { ...s, local } : s));
30
+ raf = requestAnimationFrame(follow);
31
+ };
32
+ raf = requestAnimationFrame(follow);
33
+ return () => { off(); cancelAnimationFrame(raf); };
28
34
  }, [show]);
29
35
  return st;
30
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senseihq/emaki-react",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "React components and hooks 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",
@@ -31,7 +31,7 @@
31
31
  "react": ">=18"
32
32
  },
33
33
  "dependencies": {
34
- "@senseihq/emaki": "0.1.1"
34
+ "@senseihq/emaki": "0.1.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/react": "^19.1.0",
@@ -1,7 +1,7 @@
1
1
  // React components over @senseihq/emaki. All are client components (they need the DOM); in Next.js import them
2
2
  // from a file marked 'use client'. Call setupMotion({ source, site, logos }) once on the client first.
3
3
  import { useEffect, useRef, useState, type CSSProperties } from 'react';
4
- import { attachScene, createShow, installCapture, showKey, type AttachedScene, type Layout, type Mode, type ScenePlayerState } from '@senseihq/emaki';
4
+ import { attachScene, createShow, installCapture, showKey, ticks, type AttachedScene, type Layout, type Mode, type ScenePlayerState } from '@senseihq/emaki';
5
5
  import { usePlayerFor, useScenePlayer, useShowState, useSize, useWidth, type Show } from './hooks.js';
6
6
 
7
7
  /** Mounts a player's scene into a div and keeps it fitted (shared by MotionScene and ScenePlayer). */
@@ -53,43 +53,93 @@ export function ScenePlayer({ player, locale = 'en', mode = 'auto', controls = f
53
53
 
54
54
  export interface MotionShowProps {
55
55
  film: string; locale?: string; layout?: Layout; mode?: Mode; controls?: boolean; slide?: number; loop?: boolean;
56
+ /** Open on the film's cover frame with a play button; the first click plays it from the top with sound on. */
57
+ poster?: boolean;
58
+ /** An image (URL) to show with the play button; the show is created on the first click (then plays, sound on). */
59
+ cover?: string;
60
+ /** The film's name and running time, for the play button's label and chip. */
61
+ title?: string; length?: string;
62
+ /** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */
63
+ fullscreenHref?: string;
56
64
  /** The controller once ready (next/prev/play/pause/setSound/setLayout/seek/on), for custom chrome. */
57
65
  onReady?: (show: Show) => void;
58
66
  className?: string; style?: CSSProperties;
59
67
  }
60
68
 
61
- /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→, Space, M (sound), O (orientation). */
62
- export function MotionShow({ film, locale = 'en', layout = 'landscape', mode = 'auto', controls = true, slide = 1, loop = false, onReady, className, style }: MotionShowProps) {
69
+ const btn: CSSProperties = { minWidth: 34, height: 34, borderRadius: 17, border: '1px solid currentColor', background: 'none', color: 'inherit', cursor: 'pointer', padding: '0 10px' };
70
+ const tickTrack = 'linear-gradient(color-mix(in srgb, currentColor 18%, transparent), color-mix(in srgb, currentColor 18%, transparent)) center / 100% 4px no-repeat';
71
+
72
+ /** The play button over a poster or a cover image: the label and the chip name the film and its length. */
73
+ function PlayButton({ title, length, cover, onClick }: { title: string; length: string; cover?: string; onClick: () => void }) {
74
+ return (
75
+ <button onClick={onClick} aria-label={`Play the film${title ? `: ${title}` : ''}`}
76
+ style={{ position: 'absolute', inset: 0, border: 0, padding: 0, background: 'none', cursor: 'pointer', color: 'inherit' }}>
77
+ {cover && <img src={cover} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />}
78
+ <span aria-hidden="true" style={{ position: 'absolute', right: 18, bottom: 14, width: 64, height: 64, borderRadius: '50%', background: 'color-mix(in srgb, currentColor 85%, transparent)', display: 'grid', placeItems: 'center' }}>
79
+ <svg viewBox="0 0 24 24" style={{ width: 28, height: 28, fill: 'Canvas', marginLeft: 3 }}><path d="M8 5.5v13l11-6.5z" /></svg>
80
+ </span>
81
+ <span style={{ position: 'absolute', left: 16, bottom: 14, padding: '6px 12px', borderRadius: 999, font: '11px/1 system-ui', letterSpacing: '.1em', textTransform: 'uppercase', background: 'color-mix(in srgb, Canvas 88%, transparent)', border: '1px solid color-mix(in srgb, currentColor 20%, transparent)' }}>
82
+ Play the film{length ? ` · ${length}` : ''}
83
+ </span>
84
+ </button>
85
+ );
86
+ }
87
+
88
+ /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→ scene, Space play/pause, M sound,
89
+ * O orientation, R replay, Home from the top, F fullscreen. `poster` opens on the cover frame; `cover` paints an
90
+ * image and creates nothing until the first click. */
91
+ export function MotionShow({ film, locale = 'en', layout = 'landscape', mode = 'auto', controls = true, slide = 1, loop = false, poster = false, cover = '', title = '', length = '', fullscreenHref = '', onReady, className, style }: MotionShowProps) {
63
92
  const stage = useRef<HTMLDivElement>(null);
64
93
  const [fitRef, size] = useSize<HTMLDivElement>();
65
94
  const [show, setShow] = useState<Show | null>(null);
95
+ // With a cover nothing is created until the reader clicks; that click then starts the show (sound on). The poster
96
+ // shows only until the reader first plays: a language or mode change after that restarts without it.
97
+ const [waiting, setWaiting] = useState(() => !!cover);
98
+ const autoplay = useRef(false), begun = useRef(false);
66
99
  const st = useShowState(show);
100
+ useEffect(() => { if (st?.started && show) begun.current = true; }, [st?.started, show]);
67
101
  useEffect(() => {
102
+ if (waiting) return;
68
103
  let alive = true, made: Show | null = null;
69
- createShow(stage.current!, film, { locale, layout, mode, slide, loop }).then((s) => {
104
+ const play = autoplay.current;
105
+ autoplay.current = false;
106
+ createShow(stage.current!, film, { locale, layout, mode, slide, loop, poster: (poster || play) && !begun.current }).then(async (s) => {
70
107
  if (!alive) return s.destroy();
71
108
  made = s; setShow(s); onReady?.(s);
109
+ if (play) await s.start();
72
110
  });
73
111
  return () => { alive = false; made?.destroy(); setShow(null); };
74
- }, [film, locale, mode]); // eslint-disable-line react-hooks/exhaustive-deps
112
+ }, [film, locale, mode, waiting]); // eslint-disable-line react-hooks/exhaustive-deps
75
113
  useEffect(() => { if (show && show.state.layout !== layout) show.setLayout(layout); }, [show, layout]);
76
114
  useEffect(() => { show?.fit(size.w, size.h); }, [show, size, st?.layout]);
77
115
  // Every key (←/→, Space, M, O, R, Home, F) from the core, so all players answer the same way.
78
116
  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => { if (show && showKey(show, e.nativeEvent, e.currentTarget)) e.preventDefault(); };
79
- const btn: CSSProperties = { minWidth: 34, height: 34, borderRadius: 17, border: '1px solid currentColor', background: 'none', color: 'inherit', cursor: 'pointer', padding: '0 10px' };
117
+ const open = () => { autoplay.current = true; setWaiting(false); };
80
118
  return (
81
119
  <div tabIndex={0} role="application" aria-label="Story player" onKeyDown={onKeyDown} className={className}
82
120
  style={{ position: 'relative', width: '100%', height: '100%', display: 'flex', flexDirection: 'column', outline: 'none', ...style }}>
83
121
  <div ref={fitRef} style={{ position: 'relative', flex: 1, minHeight: 0, display: 'grid', placeItems: 'center', overflow: 'hidden' }}>
84
122
  <div ref={stage} style={{ position: 'relative' }} />
85
123
  </div>
86
- {controls && show && st && (
124
+ {waiting ? <PlayButton title={title} length={length} cover={cover} onClick={open} />
125
+ : show && st && !st.started ? <PlayButton title={title} length={length} onClick={() => show.start()} />
126
+ : controls && show && st && (
87
127
  <div style={{ display: 'flex', gap: 8, alignItems: 'center', justifyContent: 'center', padding: 8, font: '13px system-ui' }}>
88
128
  <button style={btn} onClick={() => show.prev()} aria-label="Previous scene">‹</button>
89
129
  <button style={btn} onClick={() => show.toggle()} aria-label={st.playing ? 'Pause' : 'Play'}>{st.playing ? '❚❚' : '▶'}</button>
90
130
  <button style={btn} onClick={() => show.next()} aria-label="Next scene">›</button>
91
- <span style={{ opacity: 0.7 }}>{st.index + 1} / {show.timeline.scenes.length}</span>
131
+ <div style={{ flex: 1, display: 'flex', gap: 3, maxWidth: 360 }}>
132
+ {ticks(show).map((tk, i) => (
133
+ <button key={tk.id} onClick={() => show.go(i)} aria-label={tk.name}
134
+ style={{ flex: tk.dur, minWidth: 0, height: 18, padding: '7px 0', border: 0, borderRadius: 0, background: tickTrack, cursor: 'pointer', color: 'inherit' }}>
135
+ <span style={{ display: 'block', height: 4, borderRadius: 2, background: 'currentColor', width: `${tk.fill * 100}%` }} />
136
+ </button>
137
+ ))}
138
+ </div>
139
+ <span style={{ opacity: 0.7, fontVariantNumeric: 'tabular-nums' }}>{st.index + 1} / {show.timeline.scenes.length}</span>
92
140
  <button style={btn} onClick={() => show.setSound(!st.sound)} aria-pressed={st.sound}>{st.sound ? 'Sound on' : 'Sound off'}</button>
141
+ {fullscreenHref && <a href={fullscreenHref} aria-label="Open full screen" title="Full screen"
142
+ style={{ ...btn, display: 'grid', placeItems: 'center', textDecoration: 'none', padding: 0 }}>⤢</a>}
93
143
  </div>
94
144
  )}
95
145
  </div>
package/src/hooks.ts CHANGED
@@ -21,18 +21,24 @@ export function usePlayerFor(ref: SceneRef | null) {
21
21
  }
22
22
 
23
23
  export type Show = Awaited<ReturnType<typeof createShow>>;
24
- export interface ShowState { index: number; local: number; playing: boolean; sound: boolean; layout: Layout }
24
+ export interface ShowState { index: number; local: number; playing: boolean; sound: boolean; layout: Layout; started: boolean }
25
25
 
26
- /** State of a story player controller (from <MotionShow onReady>): re-renders on scene, play, sound, layout changes. */
26
+ /** State of a story player controller (from <MotionShow onReady>): re-renders on scene, play, sound, layout changes,
27
+ * and follows the playhead (read once a frame; it moves without notifications). `started` is false on a poster. */
27
28
  export function useShowState(show: Show | null): ShowState | null {
28
29
  const [st, setSt] = useState<ShowState | null>(show ? show.state : null);
29
- const last = useRef(show);
30
30
  useEffect(() => {
31
- last.current = show;
32
31
  if (!show) return setSt(null);
33
32
  setSt(show.state);
34
33
  const off = show.on((s) => setSt({ ...s }));
35
- return () => { off(); };
34
+ let raf = 0;
35
+ const follow = () => {
36
+ const local = show.state.local;
37
+ setSt((s) => (s && s.local !== local ? { ...s, local } : s));
38
+ raf = requestAnimationFrame(follow);
39
+ };
40
+ raf = requestAnimationFrame(follow);
41
+ return () => { off(); cancelAnimationFrame(raf); };
36
42
  }, [show]);
37
43
  return st;
38
44
  }