@senseihq/emaki-svelte 0.1.0 → 0.1.1
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 +9 -5
- package/dist/MotionScene.svelte +45 -7
- package/dist/MotionScene.svelte.d.ts +5 -1
- package/dist/MotionShow.svelte +43 -16
- package/dist/MotionShow.svelte.d.ts +6 -1
- package/dist/ScenePlayer.svelte +4 -3
- package/dist/ScenePlayer.svelte.d.ts +2 -1
- package/dist/ShowPage.svelte +6 -4
- package/dist/ShowPage.svelte.d.ts +3 -1
- package/dist/player.svelte.d.ts +59 -11
- package/dist/player.svelte.js +22 -5
- package/package.json +2 -2
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 first; `title`, `length` on it), `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
|
package/dist/MotionScene.svelte
CHANGED
|
@@ -1,26 +1,64 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
// An article figure: one scene, looping while it is on screen
|
|
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
|
-
|
|
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}
|
|
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
|
|
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, {}, "">;
|
package/dist/MotionShow.svelte
CHANGED
|
@@ -1,54 +1,72 @@
|
|
|
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
|
|
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. Give it a size (it fills its
|
|
5
|
+
// parent). bind:show to drive it from your own chrome.
|
|
4
6
|
import { onMount, untrack } from 'svelte';
|
|
5
|
-
import { createShow, type Layout } from '@senseihq/emaki';
|
|
7
|
+
import { createShow, showKey, type Layout, type Mode } from '@senseihq/emaki';
|
|
6
8
|
import { reactiveShow, type ShowHandle } from './player.svelte.js';
|
|
7
9
|
|
|
8
|
-
let {
|
|
9
|
-
|
|
10
|
+
let {
|
|
11
|
+
film, locale = 'en', layout = 'landscape', mode = 'auto', controls = true, slide = 1, loop = false,
|
|
12
|
+
poster = false, title = '', length = '', fullscreenHref = '', show = $bindable(),
|
|
13
|
+
}: {
|
|
14
|
+
film: string; locale?: string; layout?: Layout; mode?: Mode; controls?: boolean; slide?: number; loop?: boolean;
|
|
15
|
+
/** Open on the cover with a play button. */ poster?: boolean;
|
|
16
|
+
/** The film's name and running time, for the poster's label and chip. */ title?: string; length?: string;
|
|
17
|
+
/** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */ fullscreenHref?: string;
|
|
18
|
+
show?: ShowHandle;
|
|
19
|
+
} = $props();
|
|
10
20
|
|
|
11
21
|
let box: HTMLDivElement, stage: HTMLDivElement;
|
|
12
22
|
let w = $state(0), h = $state(0);
|
|
13
23
|
const s = reactiveShow();
|
|
14
24
|
|
|
15
|
-
// Each (re)start gets a ticket, so a slow createShow that a newer one overtook is thrown away.
|
|
16
|
-
|
|
25
|
+
// Each (re)start gets a ticket, so a slow createShow that a newer one overtook is thrown away. The poster shows
|
|
26
|
+
// only until the reader first plays: a language or mode change after that restarts without it.
|
|
27
|
+
let ticket = 0, begun = false;
|
|
28
|
+
$effect(() => { if (s.started && s.api) begun = true; });
|
|
17
29
|
async function start() {
|
|
18
30
|
const mine = ++ticket;
|
|
19
31
|
s.detach();
|
|
20
|
-
const made = await createShow(stage, film, { locale, layout, slide, loop });
|
|
32
|
+
const made = await createShow(stage, film, { locale, layout, mode, slide, loop, poster: poster && !begun });
|
|
21
33
|
if (mine !== ticket) return made.destroy();
|
|
22
34
|
s.attach(made);
|
|
23
35
|
show = s;
|
|
24
36
|
made.fit(w, h);
|
|
25
37
|
}
|
|
26
38
|
onMount(() => () => { ticket++; s.detach(); });
|
|
27
|
-
// Starts on mount and restarts when the film or
|
|
28
|
-
$effect(() => { film; locale; untrack(start); });
|
|
39
|
+
// Starts on mount and restarts when the film, language or mode changes (and on nothing else: untrack).
|
|
40
|
+
$effect(() => { film; locale; mode; untrack(start); });
|
|
29
41
|
$effect(() => { if (s.api && s.layout !== layout) s.api.setLayout(layout); });
|
|
30
42
|
$effect(() => { s.layout; s.api?.fit(w, h); });
|
|
31
43
|
|
|
32
44
|
function onkeydown(e: KeyboardEvent) {
|
|
33
|
-
|
|
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');
|
|
45
|
+
if (s.api && showKey(s.api, e, box)) e.preventDefault();
|
|
39
46
|
}
|
|
40
47
|
</script>
|
|
41
48
|
|
|
42
49
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
43
50
|
<div class="motion-show" bind:this={box} tabindex="0" role="application" aria-label="Story player" {onkeydown}>
|
|
44
51
|
<div class="ms-fit" bind:clientWidth={w} bind:clientHeight={h}><div class="ms-stage" bind:this={stage}></div></div>
|
|
45
|
-
{#if
|
|
52
|
+
{#if s.api && !s.started}
|
|
53
|
+
<button class="ms-poster" onclick={() => s.api?.start()} aria-label="Play the film{title ? `: ${title}` : ''}">
|
|
54
|
+
<span class="ms-play" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M8 5.5v13l11-6.5z" /></svg></span>
|
|
55
|
+
<span class="ms-chip">Play the film{length ? ` · ${length}` : ''}</span>
|
|
56
|
+
</button>
|
|
57
|
+
{:else if controls && s.api}
|
|
46
58
|
<div class="ms-bar">
|
|
47
59
|
<button onclick={() => s.api?.prev()} aria-label="Previous scene">‹</button>
|
|
48
60
|
<button onclick={() => s.api?.toggle()} aria-label={s.playing ? 'Pause' : 'Play'}>{s.playing ? '❚❚' : '▶'}</button>
|
|
49
61
|
<button onclick={() => s.api?.next()} aria-label="Next scene">›</button>
|
|
62
|
+
<div class="ms-ticks">
|
|
63
|
+
{#each s.ticks as tk, i (tk.id)}
|
|
64
|
+
<button style="flex:{tk.dur}" onclick={() => s.api?.go(i)} aria-label={tk.name}><span style="width:{tk.fill * 100}%"></span></button>
|
|
65
|
+
{/each}
|
|
66
|
+
</div>
|
|
50
67
|
<span class="ms-count">{s.index + 1} / {s.count}</span>
|
|
51
68
|
<button onclick={() => s.api?.setSound(!s.sound)} aria-pressed={s.sound}>{s.sound ? 'Sound on' : 'Sound off'}</button>
|
|
69
|
+
{#if fullscreenHref}<a class="ms-full" href={fullscreenHref} aria-label="Open full screen" title="Full screen">⤢</a>{/if}
|
|
52
70
|
</div>
|
|
53
71
|
{/if}
|
|
54
72
|
</div>
|
|
@@ -60,4 +78,13 @@
|
|
|
60
78
|
.ms-bar { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 8px; font: 13px system-ui; }
|
|
61
79
|
.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
80
|
.ms-count { font-variant-numeric: tabular-nums; opacity: .7; }
|
|
81
|
+
.ms-ticks { flex: 1; display: flex; gap: 3px; max-width: 360px; }
|
|
82
|
+
.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; }
|
|
83
|
+
.ms-ticks span { display: block; height: 4px; border-radius: 2px; background: currentColor; }
|
|
84
|
+
.ms-full { min-width: 34px; height: 34px; border-radius: 17px; border: 1px solid currentColor; display: grid; place-items: center; color: inherit; text-decoration: none; }
|
|
85
|
+
.ms-poster { position: absolute; inset: 0; border: 0; padding: 0; background: none; cursor: pointer; color: inherit; }
|
|
86
|
+
.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; }
|
|
87
|
+
.ms-poster:hover .ms-play { transform: scale(1.06); }
|
|
88
|
+
.ms-play svg { width: 28px; height: 28px; fill: Canvas; margin-left: 3px; }
|
|
89
|
+
.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
90
|
</style>
|
|
@@ -1,12 +1,17 @@
|
|
|
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
|
+
/** The film's name and running time, for the poster's label and chip. */ title?: string;
|
|
13
|
+
length?: string;
|
|
14
|
+
/** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */ fullscreenHref?: string;
|
|
10
15
|
show?: ShowHandle;
|
|
11
16
|
};
|
|
12
17
|
declare const MotionShow: import("svelte").Component<$$ComponentProps, {}, "show">;
|
package/dist/ScenePlayer.svelte
CHANGED
|
@@ -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, {}, "">;
|
package/dist/ShowPage.svelte
CHANGED
|
@@ -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
|
-
|
|
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, {}, "">;
|
package/dist/player.svelte.d.ts
CHANGED
|
@@ -1,24 +1,72 @@
|
|
|
1
|
-
import type
|
|
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:
|
|
5
|
-
readonly dur:
|
|
6
|
-
readonly status:
|
|
7
|
-
readonly error:
|
|
8
|
-
readonly playing:
|
|
9
|
-
readonly key:
|
|
10
|
-
readonly ref:
|
|
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,
|
|
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:
|
|
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
|
|
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
|
};
|
package/dist/player.svelte.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
29
|
-
|
|
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.
|
|
3
|
+
"version": "0.1.1",
|
|
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.
|
|
36
|
+
"@senseihq/emaki": "0.1.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@sveltejs/package": "^2.3.10",
|