@senseihq/emaki-svelte 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/MotionScene.svelte +64 -0
- package/dist/MotionScene.svelte.d.ts +16 -0
- package/dist/MotionShow.svelte +90 -0
- package/dist/MotionShow.svelte.d.ts +19 -0
- package/dist/ScenePlayer.svelte +46 -0
- package/dist/ScenePlayer.svelte.d.ts +10 -0
- package/dist/ShowPage.svelte +19 -0
- package/dist/ShowPage.svelte.d.ts +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/player.svelte.d.ts +73 -0
- package/dist/player.svelte.js +48 -0
- package/package.json +44 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SenecaGlobal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @senseihq/emaki-svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Svelte 5 components for motion stories, over `@senseihq/emaki`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm i @senseihq/emaki @senseihq/emaki-svelte
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```svelte
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { MotionScene, MotionShow, ScenePlayer, ShowPage, ScenePlayerState } from '@senseihq/emaki-svelte';
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<MotionScene film="phishing-101" scene="signs" locale="es" /> <!-- an article figure: loops while visible -->
|
|
15
|
+
<div style="aspect-ratio:16/10"><MotionShow film="phishing-101" locale="es" bind:show /></div> <!-- the player -->
|
|
16
|
+
<ScenePlayer {player} controls /> <!-- a scene you drive (editors, previews) -->
|
|
17
|
+
<ShowPage film={data.film} capture={data.capture} layout={data.layout} locale={data.locale} /> <!-- /show/[film] -->
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Call `setupMotion({ source, site, logos })` once on the client before these mount (`emaki init` writes
|
|
21
|
+
`emaki-source.ts` with a `startMotion()` for this). In SvelteKit, set `ssr = false` on the `/show/[film]` route;
|
|
22
|
+
render the article text on the server and let the components hydrate.
|
|
23
|
+
|
|
24
|
+
| Component | Props |
|
|
25
|
+
|---|---|
|
|
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).
|
|
33
|
+
|
|
34
|
+
`reactivePlayer(() => player)` and `reactiveShow()` give Svelte-reactive reads of the core's state classes for your
|
|
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.
|
|
37
|
+
|
|
38
|
+
MIT © SenecaGlobal
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script lang="ts">
|
|
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="..." />
|
|
5
|
+
import { onMount, untrack } from 'svelte';
|
|
6
|
+
import { attachScene, figurePlayer, sceneSound, type Layout, type Mode } from '@senseihq/emaki';
|
|
7
|
+
|
|
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();
|
|
10
|
+
|
|
11
|
+
let host: HTMLDivElement;
|
|
12
|
+
let width = $state(0);
|
|
13
|
+
let hasSound = $state(false), soundOn = $state(false);
|
|
14
|
+
const player = figurePlayer({ film: '', scene: '', layout: 'figure' });
|
|
15
|
+
let view: ReturnType<typeof attachScene> | null = null;
|
|
16
|
+
let sound: ReturnType<typeof sceneSound> | null = null;
|
|
17
|
+
|
|
18
|
+
onMount(() => {
|
|
19
|
+
player.load({ film, scene, layout });
|
|
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));
|
|
24
|
+
return () => view?.destroy();
|
|
25
|
+
});
|
|
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); }); });
|
|
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!); }); });
|
|
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
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
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>
|
|
51
|
+
|
|
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>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Layout, type Mode } from '@senseihq/emaki';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
film: string;
|
|
4
|
+
scene: string;
|
|
5
|
+
layout?: Layout;
|
|
6
|
+
locale?: string;
|
|
7
|
+
mode?: Mode;
|
|
8
|
+
autoplay?: boolean;
|
|
9
|
+
t?: number;
|
|
10
|
+
hold?: number;
|
|
11
|
+
label?: string;
|
|
12
|
+
class?: string;
|
|
13
|
+
};
|
|
14
|
+
declare const MotionScene: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
15
|
+
type MotionScene = ReturnType<typeof MotionScene>;
|
|
16
|
+
export default MotionScene;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// The story player: a film's scenes as slides, fitted to its box. Keys: ←/→ scene, Space play/pause, M sound,
|
|
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.
|
|
6
|
+
import { onMount, untrack } from 'svelte';
|
|
7
|
+
import { createShow, showKey, type Layout, type Mode } from '@senseihq/emaki';
|
|
8
|
+
import { reactiveShow, type ShowHandle } from './player.svelte.js';
|
|
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();
|
|
20
|
+
|
|
21
|
+
let box: HTMLDivElement, stage: HTMLDivElement;
|
|
22
|
+
let w = $state(0), h = $state(0);
|
|
23
|
+
const s = reactiveShow();
|
|
24
|
+
|
|
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; });
|
|
29
|
+
async function start() {
|
|
30
|
+
const mine = ++ticket;
|
|
31
|
+
s.detach();
|
|
32
|
+
const made = await createShow(stage, film, { locale, layout, mode, slide, loop, poster: poster && !begun });
|
|
33
|
+
if (mine !== ticket) return made.destroy();
|
|
34
|
+
s.attach(made);
|
|
35
|
+
show = s;
|
|
36
|
+
made.fit(w, h);
|
|
37
|
+
}
|
|
38
|
+
onMount(() => () => { ticket++; s.detach(); });
|
|
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); });
|
|
41
|
+
$effect(() => { if (s.api && s.layout !== layout) s.api.setLayout(layout); });
|
|
42
|
+
$effect(() => { s.layout; s.api?.fit(w, h); });
|
|
43
|
+
|
|
44
|
+
function onkeydown(e: KeyboardEvent) {
|
|
45
|
+
if (s.api && showKey(s.api, e, box)) e.preventDefault();
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
50
|
+
<div class="motion-show" bind:this={box} tabindex="0" role="application" aria-label="Story player" {onkeydown}>
|
|
51
|
+
<div class="ms-fit" bind:clientWidth={w} bind:clientHeight={h}><div class="ms-stage" bind:this={stage}></div></div>
|
|
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}
|
|
58
|
+
<div class="ms-bar">
|
|
59
|
+
<button onclick={() => s.api?.prev()} aria-label="Previous scene">‹</button>
|
|
60
|
+
<button onclick={() => s.api?.toggle()} aria-label={s.playing ? 'Pause' : 'Play'}>{s.playing ? '❚❚' : '▶'}</button>
|
|
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>
|
|
67
|
+
<span class="ms-count">{s.index + 1} / {s.count}</span>
|
|
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}
|
|
70
|
+
</div>
|
|
71
|
+
{/if}
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<style>
|
|
75
|
+
.motion-show { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; outline: none; }
|
|
76
|
+
.ms-fit { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; }
|
|
77
|
+
.ms-stage { position: relative; }
|
|
78
|
+
.ms-bar { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 8px; font: 13px system-ui; }
|
|
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; }
|
|
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); }
|
|
90
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Layout, type Mode } from '@senseihq/emaki';
|
|
2
|
+
import { type ShowHandle } from './player.svelte.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
film: string;
|
|
5
|
+
locale?: string;
|
|
6
|
+
layout?: Layout;
|
|
7
|
+
mode?: Mode;
|
|
8
|
+
controls?: boolean;
|
|
9
|
+
slide?: number;
|
|
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;
|
|
15
|
+
show?: ShowHandle;
|
|
16
|
+
};
|
|
17
|
+
declare const MotionShow: import("svelte").Component<$$ComponentProps, {}, "show">;
|
|
18
|
+
type MotionShow = ReturnType<typeof MotionShow>;
|
|
19
|
+
export default MotionShow;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// A scene driven by a ScenePlayerState you own (an editor, an admin preview, a step-through): the state holds what
|
|
3
|
+
// is loaded and where the playhead is; this mounts, renders and runs the clock. Remounts when player.key changes.
|
|
4
|
+
import { onMount } from 'svelte';
|
|
5
|
+
import { attachScene, type Mode, type ScenePlayerState } from '@senseihq/emaki';
|
|
6
|
+
import { reactivePlayer } from './player.svelte.js';
|
|
7
|
+
|
|
8
|
+
let { player, locale = 'en', mode = 'auto', controls = false }: { player: ScenePlayerState; locale?: string; mode?: Mode; controls?: boolean } = $props();
|
|
9
|
+
const p = reactivePlayer(() => player);
|
|
10
|
+
let host: HTMLDivElement;
|
|
11
|
+
let width = $state(0);
|
|
12
|
+
let view: ReturnType<typeof attachScene> | null = null;
|
|
13
|
+
|
|
14
|
+
onMount(() => {
|
|
15
|
+
view = attachScene(host, player, { locale, mode });
|
|
16
|
+
return () => view?.destroy();
|
|
17
|
+
});
|
|
18
|
+
$effect(() => { view?.setLocale(locale); });
|
|
19
|
+
$effect(() => { view?.setMode(mode); });
|
|
20
|
+
$effect(() => { if (width) view?.fit(width); });
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<div class="motion-player" bind:clientWidth={width}>
|
|
24
|
+
<div bind:this={host}></div>
|
|
25
|
+
{#if p.status === 'error'}
|
|
26
|
+
<p class="mp-msg mp-error" role="alert">{p.error}</p>
|
|
27
|
+
{:else if p.status === 'idle'}
|
|
28
|
+
<p class="mp-msg">Loading the scene…</p>
|
|
29
|
+
{/if}
|
|
30
|
+
{#if controls && p.status === 'ready'}
|
|
31
|
+
<div class="mp-bar">
|
|
32
|
+
<button onclick={() => player.toggle()} aria-label={p.playing ? 'Pause' : 'Play'}>{p.playing ? '❚❚' : '▶'}</button>
|
|
33
|
+
<input type="range" aria-label="Seek" min="0" max={p.dur} step="0.05" value={p.t} oninput={(e) => player.seek(Number(e.currentTarget.value))} />
|
|
34
|
+
<span>{p.t.toFixed(1)} / {p.dur.toFixed(1)}</span>
|
|
35
|
+
</div>
|
|
36
|
+
{/if}
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<style>
|
|
40
|
+
.motion-player { position: relative; width: 100%; }
|
|
41
|
+
.mp-msg { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font: 14px system-ui; opacity: .7; }
|
|
42
|
+
.mp-error { color: #b42318; padding: 0 24px; text-align: center; opacity: 1; }
|
|
43
|
+
.mp-bar { display: flex; align-items: center; gap: 12px; margin-top: 10px; font: 12px ui-monospace, monospace; }
|
|
44
|
+
.mp-bar button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid currentColor; background: none; cursor: pointer; color: inherit; }
|
|
45
|
+
.mp-bar input { flex: 1; }
|
|
46
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Mode, type ScenePlayerState } from '@senseihq/emaki';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
player: ScenePlayerState;
|
|
4
|
+
locale?: string;
|
|
5
|
+
mode?: Mode;
|
|
6
|
+
controls?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const ScenePlayer: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type ScenePlayer = ReturnType<typeof ScenePlayer>;
|
|
10
|
+
export default ScenePlayer;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// The capture page the video pipeline drives (`emaki render` opens /show/<film>?capture=1&o=landscape&lang=en):
|
|
3
|
+
// the stage at 1:1, no chrome, window.__show = { meta, ready, seek, audio }. Turn SSR off for this route.
|
|
4
|
+
import { onMount } from 'svelte';
|
|
5
|
+
import { installCapture, type Layout, type Mode } from '@senseihq/emaki';
|
|
6
|
+
import MotionShow from './MotionShow.svelte';
|
|
7
|
+
|
|
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();
|
|
11
|
+
let host: HTMLDivElement | undefined = $state();
|
|
12
|
+
onMount(() => { if (capture && host) installCapture(host, film, layout, locale, { mode: mode ?? 'light', src }); });
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
{#if capture}
|
|
16
|
+
<div bind:this={host}></div>
|
|
17
|
+
{:else}
|
|
18
|
+
<div style="position:fixed;inset:0"><MotionShow {film} {layout} {locale} mode={mode ?? 'auto'} /></div>
|
|
19
|
+
{/if}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Layout, type Mode } from '@senseihq/emaki';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
film: string;
|
|
4
|
+
layout?: Layout;
|
|
5
|
+
locale?: string;
|
|
6
|
+
mode?: Mode;
|
|
7
|
+
src?: 'json' | 'js';
|
|
8
|
+
capture?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const ShowPage: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
11
|
+
type ShowPage = ReturnType<typeof ShowPage>;
|
|
12
|
+
export default ShowPage;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as MotionScene } from './MotionScene.svelte';
|
|
2
|
+
export { default as MotionShow } from './MotionShow.svelte';
|
|
3
|
+
export { default as ScenePlayer } from './ScenePlayer.svelte';
|
|
4
|
+
export { default as ShowPage } from './ShowPage.svelte';
|
|
5
|
+
export { reactivePlayer, reactiveShow, type ShowHandle } from './player.svelte.js';
|
|
6
|
+
export { setupMotion, ScenePlayerState, type MotionSetup } from '@senseihq/emaki';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Svelte 5 components over @senseihq/emaki. Call setupMotion({ source, site, logos }) once on the client first.
|
|
2
|
+
export { default as MotionScene } from './MotionScene.svelte';
|
|
3
|
+
export { default as MotionShow } from './MotionShow.svelte';
|
|
4
|
+
export { default as ScenePlayer } from './ScenePlayer.svelte';
|
|
5
|
+
export { default as ShowPage } from './ShowPage.svelte';
|
|
6
|
+
export { reactivePlayer, reactiveShow } from './player.svelte.js';
|
|
7
|
+
export { setupMotion, ScenePlayerState } from '@senseihq/emaki';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type createShow, type Layout, type ScenePlayerState } from '@senseihq/emaki';
|
|
2
|
+
/** Reactive reads of a ScenePlayerState: `p.t`, `p.playing`, `p.status` update the UI as the player changes. */
|
|
3
|
+
export declare function reactivePlayer(get: () => ScenePlayerState): {
|
|
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
|
+
};
|
|
12
|
+
type Show = Awaited<ReturnType<typeof createShow>>;
|
|
13
|
+
export type ShowHandle = ReturnType<typeof reactiveShow>;
|
|
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. */
|
|
16
|
+
export declare function reactiveShow(): {
|
|
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;
|
|
57
|
+
readonly index: number;
|
|
58
|
+
readonly local: number;
|
|
59
|
+
readonly playing: boolean;
|
|
60
|
+
readonly sound: boolean;
|
|
61
|
+
readonly layout: Layout;
|
|
62
|
+
readonly started: boolean;
|
|
63
|
+
readonly count: number;
|
|
64
|
+
readonly ticks: {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
dur: number;
|
|
68
|
+
fill: number;
|
|
69
|
+
}[];
|
|
70
|
+
attach(s: Show): void;
|
|
71
|
+
detach(): void;
|
|
72
|
+
};
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
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';
|
|
3
|
+
/** Reactive reads of a ScenePlayerState: `p.t`, `p.playing`, `p.status` update the UI as the player changes. */
|
|
4
|
+
export function reactivePlayer(get) {
|
|
5
|
+
let v = $state(0);
|
|
6
|
+
$effect(() => get().subscribe(() => { v++; }));
|
|
7
|
+
const read = (f) => () => { v; return f(get()); };
|
|
8
|
+
return {
|
|
9
|
+
get t() { return read((p) => p.t)(); },
|
|
10
|
+
get dur() { return read((p) => p.dur)(); },
|
|
11
|
+
get status() { return read((p) => p.status)(); },
|
|
12
|
+
get error() { return read((p) => p.error)(); },
|
|
13
|
+
get playing() { return read((p) => p.playing)(); },
|
|
14
|
+
get key() { return read((p) => p.key)(); },
|
|
15
|
+
get ref() { return read((p) => p.ref)(); },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
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. */
|
|
20
|
+
export function reactiveShow() {
|
|
21
|
+
let api = $state(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
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
get api() { return api; },
|
|
31
|
+
get index() { return st.index; },
|
|
32
|
+
get local() { return st.local; },
|
|
33
|
+
get playing() { return st.playing; },
|
|
34
|
+
get sound() { return st.sound; },
|
|
35
|
+
get layout() { return st.layout; },
|
|
36
|
+
get started() { return st.started; },
|
|
37
|
+
get count() { return api?.timeline.scenes.length ?? 0; },
|
|
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; },
|
|
47
|
+
};
|
|
48
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senseihq/emaki-svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Svelte 5 components for motion stories: article figures, the story player, a controlled scene player and the video capture page.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "SenecaGlobal",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/sensei-hq/emaki.git",
|
|
11
|
+
"directory": "packages/emaki-svelte"
|
|
12
|
+
},
|
|
13
|
+
"keywords": ["emaki", "svelte", "sveltekit", "motion", "animation", "explainer", "i18n"],
|
|
14
|
+
"sideEffects": ["**/*.css"],
|
|
15
|
+
"files": ["dist", "!dist/**/*.spec.*", "README.md", "LICENSE"],
|
|
16
|
+
"svelte": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"./package.json": "./package.json",
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"svelte": "./dist/index.js",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "svelte-package -i src/lib -o dist",
|
|
28
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
29
|
+
"prepublishOnly": "cp ../../LICENSE . && bun run build",
|
|
30
|
+
"postpublish": "rm -f LICENSE"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"svelte": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@senseihq/emaki": "0.1.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@sveltejs/package": "^2.3.10",
|
|
40
|
+
"svelte": "^5.28.0",
|
|
41
|
+
"svelte-check": "^4.2.1"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|