@senseihq/emaki-svelte 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 +1 -1
- package/dist/MotionShow.svelte +25 -9
- package/dist/MotionShow.svelte.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ render the article text on the server and let the components hydrate.
|
|
|
24
24
|
| Component | Props |
|
|
25
25
|
|---|---|
|
|
26
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) |
|
|
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
28
|
| `ScenePlayer` | `player: ScenePlayerState`, `locale`, `mode` (`auto`), `controls` |
|
|
29
29
|
| `ShowPage` | `film`, `layout`, `locale`, `mode` (capture: `light`), `src` (`json`/`js`, forces the scene source), `capture` |
|
|
30
30
|
|
package/dist/MotionShow.svelte
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
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
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.
|
|
5
|
-
//
|
|
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.
|
|
6
7
|
import { onMount, untrack } from 'svelte';
|
|
7
8
|
import { createShow, showKey, type Layout, type Mode } from '@senseihq/emaki';
|
|
8
9
|
import { reactiveShow, type ShowHandle } from './player.svelte.js';
|
|
9
10
|
|
|
10
11
|
let {
|
|
11
12
|
film, locale = 'en', layout = 'landscape', mode = 'auto', controls = true, slide = 1, loop = false,
|
|
12
|
-
poster = false, title = '', length = '', fullscreenHref = '', show = $bindable(),
|
|
13
|
+
poster = false, cover = '', title = '', length = '', fullscreenHref = '', show = $bindable(),
|
|
13
14
|
}: {
|
|
14
15
|
film: string; locale?: string; layout?: Layout; mode?: Mode; controls?: boolean; slide?: number; loop?: boolean;
|
|
15
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;
|
|
16
18
|
/** The film's name and running time, for the poster's label and chip. */ title?: string; length?: string;
|
|
17
19
|
/** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */ fullscreenHref?: string;
|
|
18
20
|
show?: ShowHandle;
|
|
@@ -25,19 +27,24 @@
|
|
|
25
27
|
// Each (re)start gets a ticket, so a slow createShow that a newer one overtook is thrown away. The poster shows
|
|
26
28
|
// only until the reader first plays: a language or mode change after that restarts without it.
|
|
27
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;
|
|
28
32
|
$effect(() => { if (s.started && s.api) begun = true; });
|
|
29
33
|
async function start() {
|
|
30
|
-
const mine = ++ticket;
|
|
34
|
+
const mine = ++ticket, play = autoplay;
|
|
35
|
+
autoplay = false;
|
|
31
36
|
s.detach();
|
|
32
|
-
const made = await createShow(stage, film, { locale, layout, mode, slide, loop, poster: poster && !begun });
|
|
37
|
+
const made = await createShow(stage, film, { locale, layout, mode, slide, loop, poster: (poster || play) && !begun });
|
|
33
38
|
if (mine !== ticket) return made.destroy();
|
|
34
39
|
s.attach(made);
|
|
35
40
|
show = s;
|
|
36
41
|
made.fit(w, h);
|
|
42
|
+
if (play) await made.start();
|
|
37
43
|
}
|
|
44
|
+
function open() { autoplay = true; waiting = false; }
|
|
38
45
|
onMount(() => () => { ticket++; s.detach(); });
|
|
39
46
|
// Starts on mount and restarts when the film, language or mode changes (and on nothing else: untrack).
|
|
40
|
-
$effect(() => { film; locale; mode; untrack(start); });
|
|
47
|
+
$effect(() => { film; locale; mode; if (!waiting) untrack(start); });
|
|
41
48
|
$effect(() => { if (s.api && s.layout !== layout) s.api.setLayout(layout); });
|
|
42
49
|
$effect(() => { s.layout; s.api?.fit(w, h); });
|
|
43
50
|
|
|
@@ -49,10 +56,18 @@
|
|
|
49
56
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
50
57
|
<div class="motion-show" bind:this={box} tabindex="0" role="application" aria-label="Story player" {onkeydown}>
|
|
51
58
|
<div class="ms-fit" bind:clientWidth={w} bind:clientHeight={h}><div class="ms-stage" bind:this={stage}></div></div>
|
|
52
|
-
{#
|
|
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}
|
|
53
69
|
<button class="ms-poster" onclick={() => s.api?.start()} aria-label="Play the film{title ? `: ${title}` : ''}">
|
|
54
|
-
|
|
55
|
-
<span class="ms-chip">Play the film{length ? ` · ${length}` : ''}</span>
|
|
70
|
+
{@render play()}
|
|
56
71
|
</button>
|
|
57
72
|
{:else if controls && s.api}
|
|
58
73
|
<div class="ms-bar">
|
|
@@ -83,6 +98,7 @@
|
|
|
83
98
|
.ms-ticks span { display: block; height: 4px; border-radius: 2px; background: currentColor; }
|
|
84
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; }
|
|
85
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; }
|
|
86
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; }
|
|
87
103
|
.ms-poster:hover .ms-play { transform: scale(1.06); }
|
|
88
104
|
.ms-play svg { width: 28px; height: 28px; fill: Canvas; margin-left: 3px; }
|
|
@@ -9,6 +9,7 @@ type $$ComponentProps = {
|
|
|
9
9
|
slide?: number;
|
|
10
10
|
loop?: boolean;
|
|
11
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;
|
|
12
13
|
/** The film's name and running time, for the poster's label and chip. */ title?: string;
|
|
13
14
|
length?: string;
|
|
14
15
|
/** Where the full-screen link goes (e.g. /show/<film>); no link when empty. */ fullscreenHref?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senseihq/emaki-svelte",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
36
|
+
"@senseihq/emaki": "0.1.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@sveltejs/package": "^2.3.10",
|