@senseihq/emaki-vue 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 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,31 @@
1
- # Temporary Holding Version
1
+ # @senseihq/emaki-vue
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vue 3 components and composables for motion stories, over `@senseihq/emaki`. Written as render functions, so no
4
+ SFC compiler is needed. Client-only (in Nuxt, wrap them in `<ClientOnly>`).
5
+
6
+ ```sh
7
+ npm i @senseihq/emaki @senseihq/emaki-vue
8
+ ```
9
+
10
+ ```vue
11
+ <script setup lang="ts">
12
+ import { MotionScene, MotionShow, ScenePlayer, ShowPage } from '@senseihq/emaki-vue';
13
+ </script>
14
+
15
+ <template>
16
+ <MotionScene film="phishing-101" scene="signs" locale="es" />
17
+ <div style="aspect-ratio:16/10"><MotionShow film="phishing-101" locale="es" @ready="(s) => (show = s)" /></div>
18
+ <ScenePlayer :player="player" controls />
19
+ <ShowPage :film="film" capture layout="portrait" locale="es" />
20
+ </template>
21
+ ```
22
+
23
+ Every component takes `mode`: `light`, `dark` or `auto` (the default). Auto follows the page's `data-mode` (as rokkit's
24
+ `themable` sets it), else the OS, and the scenes redraw when it changes. A film draws dark only if it has a dark look
25
+ (see @senseihq/emaki); `ShowPage` captures light unless asked, and its `src` (`json`/`js`) forces where scenes come
26
+ from.
27
+
28
+ Call `setupMotion({ source, site, logos })` once on the client first. Composables: `useScenePlayer(player)` (a
29
+ reactive snapshot of a `ScenePlayerState`) and `useShowState(showRef)`.
30
+
31
+ MIT © SenecaGlobal
@@ -0,0 +1,280 @@
1
+ import { type PropType } from 'vue';
2
+ import { type Layout, type Mode, type ScenePlayerState } from '@senseihq/emaki';
3
+ import { type Show } from './composables.js';
4
+ /** An article figure: one scene, looping while it is on screen. */
5
+ export declare const MotionScene: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
6
+ film: {
7
+ type: StringConstructor;
8
+ required: true;
9
+ };
10
+ scene: {
11
+ type: StringConstructor;
12
+ required: true;
13
+ };
14
+ layout: {
15
+ type: PropType<Layout>;
16
+ default: string;
17
+ };
18
+ locale: {
19
+ type: StringConstructor;
20
+ default: string;
21
+ };
22
+ mode: {
23
+ type: PropType<Mode>;
24
+ default: string;
25
+ };
26
+ autoplay: {
27
+ type: BooleanConstructor;
28
+ default: boolean;
29
+ };
30
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
31
+ [key: string]: any;
32
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
33
+ film: {
34
+ type: StringConstructor;
35
+ required: true;
36
+ };
37
+ scene: {
38
+ type: StringConstructor;
39
+ required: true;
40
+ };
41
+ layout: {
42
+ type: PropType<Layout>;
43
+ default: string;
44
+ };
45
+ locale: {
46
+ type: StringConstructor;
47
+ default: string;
48
+ };
49
+ mode: {
50
+ type: PropType<Mode>;
51
+ default: string;
52
+ };
53
+ autoplay: {
54
+ type: BooleanConstructor;
55
+ default: boolean;
56
+ };
57
+ }>> & Readonly<{}>, {
58
+ layout: Layout;
59
+ locale: string;
60
+ mode: Mode;
61
+ autoplay: boolean;
62
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
63
+ /** A scene driven by a ScenePlayerState you own (editors, previews, step-throughs). */
64
+ export declare const ScenePlayer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
65
+ player: {
66
+ type: PropType<ScenePlayerState>;
67
+ required: true;
68
+ };
69
+ locale: {
70
+ type: StringConstructor;
71
+ default: string;
72
+ };
73
+ mode: {
74
+ type: PropType<Mode>;
75
+ default: string;
76
+ };
77
+ controls: {
78
+ type: BooleanConstructor;
79
+ default: boolean;
80
+ };
81
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
82
+ [key: string]: any;
83
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
84
+ player: {
85
+ type: PropType<ScenePlayerState>;
86
+ required: true;
87
+ };
88
+ locale: {
89
+ type: StringConstructor;
90
+ default: string;
91
+ };
92
+ mode: {
93
+ type: PropType<Mode>;
94
+ default: string;
95
+ };
96
+ controls: {
97
+ type: BooleanConstructor;
98
+ default: boolean;
99
+ };
100
+ }>> & Readonly<{}>, {
101
+ locale: string;
102
+ mode: Mode;
103
+ controls: boolean;
104
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
105
+ /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→, Space, M (sound), O (orientation). */
106
+ export declare const MotionShow: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
107
+ film: {
108
+ type: StringConstructor;
109
+ required: true;
110
+ };
111
+ locale: {
112
+ type: StringConstructor;
113
+ default: string;
114
+ };
115
+ layout: {
116
+ type: PropType<Layout>;
117
+ default: string;
118
+ };
119
+ mode: {
120
+ type: PropType<Mode>;
121
+ default: string;
122
+ };
123
+ controls: {
124
+ type: BooleanConstructor;
125
+ default: boolean;
126
+ };
127
+ slide: {
128
+ type: NumberConstructor;
129
+ default: number;
130
+ };
131
+ loop: {
132
+ type: BooleanConstructor;
133
+ default: boolean;
134
+ };
135
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
136
+ [key: string]: any;
137
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
138
+ ready: (_show: Show) => true;
139
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
140
+ film: {
141
+ type: StringConstructor;
142
+ required: true;
143
+ };
144
+ locale: {
145
+ type: StringConstructor;
146
+ default: string;
147
+ };
148
+ layout: {
149
+ type: PropType<Layout>;
150
+ default: string;
151
+ };
152
+ mode: {
153
+ type: PropType<Mode>;
154
+ default: string;
155
+ };
156
+ controls: {
157
+ type: BooleanConstructor;
158
+ default: boolean;
159
+ };
160
+ slide: {
161
+ type: NumberConstructor;
162
+ default: number;
163
+ };
164
+ loop: {
165
+ type: BooleanConstructor;
166
+ default: boolean;
167
+ };
168
+ }>> & Readonly<{
169
+ onReady?: ((_show: {
170
+ film: import("@senseihq/emaki").FilmMeta;
171
+ timeline: {
172
+ duration: number;
173
+ scenes: {
174
+ start: number;
175
+ design: number;
176
+ holds: [number, number][];
177
+ voice?: number;
178
+ id: string;
179
+ name: string;
180
+ dur: number;
181
+ desc?: string;
182
+ settle?: number;
183
+ }[];
184
+ };
185
+ readonly state: {
186
+ index: number;
187
+ local: number;
188
+ playing: boolean;
189
+ sound: boolean;
190
+ layout: Layout;
191
+ started: boolean;
192
+ };
193
+ start(): Promise<void>;
194
+ replay(): void;
195
+ restart(): void;
196
+ fit(w: number, h: number): void;
197
+ go: (i: number) => void;
198
+ next: () => void;
199
+ prev: () => void;
200
+ play(): void;
201
+ pause(): void;
202
+ toggle(): void;
203
+ setSound(on: boolean): void;
204
+ setLayout(l: Layout): void;
205
+ seek(t: number): Promise<void>;
206
+ on(l: import("@senseihq/emaki").ShowListener): () => boolean;
207
+ destroy(): void;
208
+ }) => any) | undefined;
209
+ }>, {
210
+ layout: Layout;
211
+ locale: string;
212
+ mode: Mode;
213
+ controls: boolean;
214
+ slide: number;
215
+ loop: boolean;
216
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
217
+ /** The /show/<film> page the video pipeline drives: with `capture`, the stage at 1:1, no chrome, window.__show. */
218
+ export declare const ShowPage: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
219
+ film: {
220
+ type: StringConstructor;
221
+ required: true;
222
+ };
223
+ layout: {
224
+ type: PropType<Layout>;
225
+ default: string;
226
+ };
227
+ locale: {
228
+ type: StringConstructor;
229
+ default: string;
230
+ };
231
+ /** Capture renders light unless asked; the interactive player follows the page (auto). */
232
+ mode: {
233
+ type: PropType<Mode>;
234
+ default: undefined;
235
+ };
236
+ /** Force scenes from their JSON or their code modules (parity checks). */
237
+ src: {
238
+ type: PropType<"json" | "js">;
239
+ default: undefined;
240
+ };
241
+ capture: {
242
+ type: BooleanConstructor;
243
+ default: boolean;
244
+ };
245
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
246
+ [key: string]: any;
247
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
248
+ film: {
249
+ type: StringConstructor;
250
+ required: true;
251
+ };
252
+ layout: {
253
+ type: PropType<Layout>;
254
+ default: string;
255
+ };
256
+ locale: {
257
+ type: StringConstructor;
258
+ default: string;
259
+ };
260
+ /** Capture renders light unless asked; the interactive player follows the page (auto). */
261
+ mode: {
262
+ type: PropType<Mode>;
263
+ default: undefined;
264
+ };
265
+ /** Force scenes from their JSON or their code modules (parity checks). */
266
+ src: {
267
+ type: PropType<"json" | "js">;
268
+ default: undefined;
269
+ };
270
+ capture: {
271
+ type: BooleanConstructor;
272
+ default: boolean;
273
+ };
274
+ }>> & Readonly<{}>, {
275
+ layout: Layout;
276
+ locale: string;
277
+ mode: Mode;
278
+ src: "json" | "js";
279
+ capture: boolean;
280
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,144 @@
1
+ // Vue 3 components over @senseihq/emaki, written as render functions so they need no SFC compiler.
2
+ // Client-only (they need the DOM): in Nuxt wrap them in <ClientOnly>. Call setupMotion(...) once on the client first.
3
+ import { defineComponent, h, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue';
4
+ import { attachScene, createShow, figurePlayer, installCapture, showKey } from '@senseihq/emaki';
5
+ import { useScenePlayer, useShowState, useSize } from './composables.js';
6
+ function attach(player, locale, mode, autoplay) {
7
+ const box = ref(null), host = ref(null);
8
+ const size = useSize(box);
9
+ let view = null;
10
+ onMounted(() => { view = attachScene(host.value, player(), { locale: locale(), mode: mode(), autoplay }); });
11
+ onBeforeUnmount(() => view?.destroy());
12
+ watch(locale, (l) => view?.setLocale(l));
13
+ watch(mode, (m) => view?.setMode(m));
14
+ watch(size, (s) => { if (s.w)
15
+ view?.fit(s.w); });
16
+ return { box, host };
17
+ }
18
+ /** An article figure: one scene, looping while it is on screen. */
19
+ export const MotionScene = defineComponent({
20
+ name: 'MotionScene',
21
+ props: {
22
+ film: { type: String, required: true },
23
+ scene: { type: String, required: true },
24
+ layout: { type: String, default: 'figure' },
25
+ locale: { type: String, default: 'en' },
26
+ mode: { type: String, default: 'auto' },
27
+ autoplay: { type: Boolean, default: true },
28
+ },
29
+ setup(props) {
30
+ const player = figurePlayer({ film: props.film, scene: props.scene, layout: props.layout });
31
+ watch(() => [props.film, props.scene, props.layout], ([film, scene, layout]) => player.load({ film, scene, layout }));
32
+ const { box, host } = attach(() => player, () => props.locale, () => props.mode, props.autoplay);
33
+ return () => h('div', { ref: box, class: 'motion-scene', style: 'width:100%' }, [h('div', { ref: host })]);
34
+ },
35
+ });
36
+ /** A scene driven by a ScenePlayerState you own (editors, previews, step-throughs). */
37
+ export const ScenePlayer = defineComponent({
38
+ name: 'ScenePlayer',
39
+ props: {
40
+ player: { type: Object, required: true },
41
+ locale: { type: String, default: 'en' },
42
+ mode: { type: String, default: 'auto' },
43
+ controls: { type: Boolean, default: false },
44
+ },
45
+ setup(props) {
46
+ const st = useScenePlayer(props.player);
47
+ const { box, host } = attach(() => props.player, () => props.locale, () => props.mode, false);
48
+ const msg = 'position:absolute;inset:0;display:grid;place-items:center;margin:0;font:14px system-ui';
49
+ return () => {
50
+ const s = st.value, p = props.player;
51
+ return h('div', { ref: box, style: 'position:relative;width:100%' }, [
52
+ h('div', { ref: host }),
53
+ s.status === 'error' ? h('p', { role: 'alert', style: msg + ';color:#b42318' }, s.error) : null,
54
+ s.status === 'idle' ? h('p', { style: msg + ';opacity:.7' }, 'Loading the scene…') : null,
55
+ props.controls && s.status === 'ready'
56
+ ? h('div', { style: 'display:flex;align-items:center;gap:12px;margin-top:10px;font:12px ui-monospace,monospace' }, [
57
+ h('button', { onClick: () => p.toggle(), 'aria-label': s.playing ? 'Pause' : 'Play' }, s.playing ? '❚❚' : '▶'),
58
+ h('input', { type: 'range', 'aria-label': 'Seek', min: 0, max: s.dur, step: 0.05, value: s.t, style: 'flex:1',
59
+ onInput: (e) => p.seek(Number(e.target.value)) }),
60
+ h('span', `${s.t.toFixed(1)} / ${s.dur.toFixed(1)}`),
61
+ ])
62
+ : null,
63
+ ]);
64
+ };
65
+ },
66
+ });
67
+ /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→, Space, M (sound), O (orientation). */
68
+ export const MotionShow = defineComponent({
69
+ name: 'MotionShow',
70
+ props: {
71
+ film: { type: String, required: true },
72
+ locale: { type: String, default: 'en' },
73
+ layout: { type: String, default: 'landscape' },
74
+ mode: { type: String, default: 'auto' },
75
+ controls: { type: Boolean, default: true },
76
+ slide: { type: Number, default: 1 },
77
+ loop: { type: Boolean, default: false },
78
+ },
79
+ emits: { ready: (_show) => true },
80
+ setup(props, { emit, expose }) {
81
+ const stage = ref(null), fit = ref(null);
82
+ const show = shallowRef(null);
83
+ const st = useShowState(show);
84
+ const size = useSize(fit);
85
+ async function start() {
86
+ show.value?.destroy();
87
+ show.value = null;
88
+ const s = await createShow(stage.value, props.film, { locale: props.locale, layout: props.layout, mode: props.mode, slide: props.slide, loop: props.loop });
89
+ show.value = s;
90
+ s.fit(size.value.w, size.value.h);
91
+ emit('ready', s);
92
+ }
93
+ onMounted(start);
94
+ onBeforeUnmount(() => show.value?.destroy());
95
+ watch(() => [props.film, props.locale, props.mode], start);
96
+ watch(() => props.layout, (l) => show.value?.setLayout(l));
97
+ watch([size, () => st.value?.layout], () => show.value?.fit(size.value.w, size.value.h));
98
+ expose({ show });
99
+ // Every key (←/→, Space, M, O, R, Home, F) from the core, so all players answer the same way.
100
+ const onKeydown = (e) => { if (show.value && showKey(show.value, e, e.currentTarget))
101
+ e.preventDefault(); };
102
+ const btn = 'min-width:34px;height:34px;border-radius:17px;border:1px solid currentColor;background:none;color:inherit;cursor:pointer;padding:0 10px';
103
+ return () => {
104
+ const s = show.value, x = st.value;
105
+ return h('div', { tabindex: 0, role: 'application', 'aria-label': 'Story player', onKeydown,
106
+ style: 'position:relative;width:100%;height:100%;display:flex;flex-direction:column;outline:none' }, [
107
+ h('div', { ref: fit, style: 'position:relative;flex:1;min-height:0;display:grid;place-items:center;overflow:hidden' }, [h('div', { ref: stage, style: 'position:relative' })]),
108
+ props.controls && s && x
109
+ ? h('div', { style: 'display:flex;gap:8px;align-items:center;justify-content:center;padding:8px;font:13px system-ui' }, [
110
+ h('button', { style: btn, onClick: () => s.prev(), 'aria-label': 'Previous scene' }, '‹'),
111
+ h('button', { style: btn, onClick: () => s.toggle(), 'aria-label': x.playing ? 'Pause' : 'Play' }, x.playing ? '❚❚' : '▶'),
112
+ h('button', { style: btn, onClick: () => s.next(), 'aria-label': 'Next scene' }, '›'),
113
+ h('span', { style: 'opacity:.7' }, `${x.index + 1} / ${s.timeline.scenes.length}`),
114
+ h('button', { style: btn, onClick: () => s.setSound(!x.sound), 'aria-pressed': x.sound }, x.sound ? 'Sound on' : 'Sound off'),
115
+ ])
116
+ : null,
117
+ ]);
118
+ };
119
+ },
120
+ });
121
+ /** The /show/<film> page the video pipeline drives: with `capture`, the stage at 1:1, no chrome, window.__show. */
122
+ export const ShowPage = defineComponent({
123
+ name: 'ShowPage',
124
+ props: {
125
+ film: { type: String, required: true },
126
+ layout: { type: String, default: 'landscape' },
127
+ locale: { type: String, default: 'en' },
128
+ /** Capture renders light unless asked; the interactive player follows the page (auto). */
129
+ mode: { type: String, default: undefined },
130
+ /** Force scenes from their JSON or their code modules (parity checks). */
131
+ src: { type: String, default: undefined },
132
+ capture: { type: Boolean, default: false },
133
+ },
134
+ setup(props) {
135
+ const host = ref(null);
136
+ let s = null;
137
+ onMounted(async () => { if (props.capture)
138
+ s = await installCapture(host.value, props.film, props.layout, props.locale, { mode: props.mode ?? 'light', src: props.src }); });
139
+ onBeforeUnmount(() => s?.destroy());
140
+ return () => props.capture
141
+ ? h('div', { ref: host })
142
+ : h('div', { style: 'position:fixed;inset:0' }, [h(MotionShow, { film: props.film, layout: props.layout, locale: props.locale, mode: props.mode ?? 'auto' })]);
143
+ },
144
+ });
@@ -0,0 +1,38 @@
1
+ import { type Ref } from 'vue';
2
+ import type { createShow, Layout, ScenePlayerState } from '@senseihq/emaki';
3
+ /** A reactive view of a ScenePlayerState: read `state.value.t` etc. in templates; call methods on the player. */
4
+ export declare function useScenePlayer(player: ScenePlayerState): import("vue").ShallowRef<{
5
+ t: number;
6
+ dur: number;
7
+ status: import("@senseihq/emaki").PlayerStatus;
8
+ error: string;
9
+ playing: boolean;
10
+ key: string;
11
+ version: number;
12
+ }, {
13
+ t: number;
14
+ dur: number;
15
+ status: import("@senseihq/emaki").PlayerStatus;
16
+ error: string;
17
+ playing: boolean;
18
+ key: string;
19
+ version: number;
20
+ }>;
21
+ export type Show = Awaited<ReturnType<typeof createShow>>;
22
+ export interface ShowState {
23
+ index: number;
24
+ local: number;
25
+ playing: boolean;
26
+ sound: boolean;
27
+ layout: Layout;
28
+ }
29
+ /** Reactive state of a story player controller (from <MotionShow @ready>). */
30
+ export declare function useShowState(show: Ref<Show | null>): import("vue").ShallowRef<ShowState | null, ShowState | null>;
31
+ /** Size of an element via ResizeObserver. */
32
+ export declare function useSize(el: Ref<HTMLElement | null>): import("vue").ShallowRef<{
33
+ w: number;
34
+ h: number;
35
+ }, {
36
+ w: number;
37
+ h: number;
38
+ }>;
@@ -0,0 +1,40 @@
1
+ // Vue reactivity over the core: the core notifies, a shallowRef version makes reads tracked.
2
+ import { onBeforeUnmount, shallowRef, ref, watch } from 'vue';
3
+ /** A reactive view of a ScenePlayerState: read `state.value.t` etc. in templates; call methods on the player. */
4
+ export function useScenePlayer(player) {
5
+ const version = ref(player.version);
6
+ const off = player.subscribe(() => { version.value = player.version; });
7
+ onBeforeUnmount(off);
8
+ const snap = () => ({ t: player.t, dur: player.dur, status: player.status, error: player.error, playing: player.playing, key: player.key, version: version.value });
9
+ const state = shallowRef(snap());
10
+ watch(version, () => { state.value = snap(); });
11
+ return state;
12
+ }
13
+ /** Reactive state of a story player controller (from <MotionShow @ready>). */
14
+ export function useShowState(show) {
15
+ const state = shallowRef(null);
16
+ let off = null;
17
+ watch(show, (s) => {
18
+ off?.();
19
+ off = null;
20
+ state.value = s ? { ...s.state } : null;
21
+ if (s)
22
+ off = s.on((x) => { state.value = { ...x }; });
23
+ }, { immediate: true });
24
+ onBeforeUnmount(() => off?.());
25
+ return state;
26
+ }
27
+ /** Size of an element via ResizeObserver. */
28
+ export function useSize(el) {
29
+ const size = shallowRef({ w: 0, h: 0 });
30
+ let ro = null;
31
+ watch(el, (e) => {
32
+ ro?.disconnect();
33
+ if (!e)
34
+ return;
35
+ ro = new ResizeObserver(([x]) => { size.value = { w: x.contentRect.width, h: x.contentRect.height }; });
36
+ ro.observe(e);
37
+ }, { immediate: true, flush: 'post' });
38
+ onBeforeUnmount(() => ro?.disconnect());
39
+ return size;
40
+ }
@@ -0,0 +1,3 @@
1
+ export { MotionScene, MotionShow, ScenePlayer, ShowPage } from './components.js';
2
+ export { useScenePlayer, useShowState, type Show, type ShowState } from './composables.js';
3
+ export { setupMotion, ScenePlayerState, type MotionSetup } from '@senseihq/emaki';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { MotionScene, MotionShow, ScenePlayer, ShowPage } from './components.js';
2
+ export { useScenePlayer, useShowState } from './composables.js';
3
+ export { setupMotion, ScenePlayerState } from '@senseihq/emaki';
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@senseihq/emaki-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Vue 3 components and composables 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-vue"
12
+ },
13
+ "keywords": ["emaki", "vue", "nuxt", "motion", "animation", "explainer", "i18n"],
14
+ "sideEffects": false,
15
+ "files": ["dist/**/*.js", "dist/**/*.d.ts", "src", "README.md", "LICENSE"],
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ "./package.json": "./package.json",
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
25
+ "scripts": {
26
+ "build": "rm -rf dist && bunx tsc --project tsconfig.build.json",
27
+ "prepublishOnly": "cp ../../LICENSE . && bun run build",
28
+ "postpublish": "rm -f LICENSE"
29
+ },
30
+ "peerDependencies": {
31
+ "vue": "^3.4.0"
32
+ },
33
+ "dependencies": {
34
+ "@senseihq/emaki": "0.1.1"
35
+ },
36
+ "devDependencies": {
37
+ "vue": "^3.5.13"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ }
42
+ }
@@ -0,0 +1,143 @@
1
+ // Vue 3 components over @senseihq/emaki, written as render functions so they need no SFC compiler.
2
+ // Client-only (they need the DOM): in Nuxt wrap them in <ClientOnly>. Call setupMotion(...) once on the client first.
3
+ import { defineComponent, h, onBeforeUnmount, onMounted, ref, shallowRef, watch, type PropType } from 'vue';
4
+ import { attachScene, createShow, figurePlayer, installCapture, showKey, type AttachedScene, type Layout, type Mode, type ScenePlayerState } from '@senseihq/emaki';
5
+ import { useScenePlayer, useShowState, useSize, type Show } from './composables.js';
6
+
7
+ function attach(player: () => ScenePlayerState, locale: () => string, mode: () => Mode, autoplay: boolean) {
8
+ const box = ref<HTMLElement | null>(null), host = ref<HTMLElement | null>(null);
9
+ const size = useSize(box);
10
+ let view: AttachedScene | null = null;
11
+ onMounted(() => { view = attachScene(host.value!, player(), { locale: locale(), mode: mode(), autoplay }); });
12
+ onBeforeUnmount(() => view?.destroy());
13
+ watch(locale, (l) => view?.setLocale(l));
14
+ watch(mode, (m) => view?.setMode(m));
15
+ watch(size, (s) => { if (s.w) view?.fit(s.w); });
16
+ return { box, host };
17
+ }
18
+
19
+ /** An article figure: one scene, looping while it is on screen. */
20
+ export const MotionScene = defineComponent({
21
+ name: 'MotionScene',
22
+ props: {
23
+ film: { type: String, required: true },
24
+ scene: { type: String, required: true },
25
+ layout: { type: String as PropType<Layout>, default: 'figure' },
26
+ locale: { type: String, default: 'en' },
27
+ mode: { type: String as PropType<Mode>, default: 'auto' },
28
+ autoplay: { type: Boolean, default: true },
29
+ },
30
+ setup(props) {
31
+ const player = figurePlayer({ film: props.film, scene: props.scene, layout: props.layout });
32
+ watch(() => [props.film, props.scene, props.layout] as const, ([film, scene, layout]) => player.load({ film, scene, layout }));
33
+ const { box, host } = attach(() => player, () => props.locale, () => props.mode, props.autoplay);
34
+ return () => h('div', { ref: box, class: 'motion-scene', style: 'width:100%' }, [h('div', { ref: host })]);
35
+ },
36
+ });
37
+
38
+ /** A scene driven by a ScenePlayerState you own (editors, previews, step-throughs). */
39
+ export const ScenePlayer = defineComponent({
40
+ name: 'ScenePlayer',
41
+ props: {
42
+ player: { type: Object as PropType<ScenePlayerState>, required: true },
43
+ locale: { type: String, default: 'en' },
44
+ mode: { type: String as PropType<Mode>, default: 'auto' },
45
+ controls: { type: Boolean, default: false },
46
+ },
47
+ setup(props) {
48
+ const st = useScenePlayer(props.player);
49
+ const { box, host } = attach(() => props.player, () => props.locale, () => props.mode, false);
50
+ const msg = 'position:absolute;inset:0;display:grid;place-items:center;margin:0;font:14px system-ui';
51
+ return () => {
52
+ const s = st.value, p = props.player;
53
+ return h('div', { ref: box, style: 'position:relative;width:100%' }, [
54
+ h('div', { ref: host }),
55
+ s.status === 'error' ? h('p', { role: 'alert', style: msg + ';color:#b42318' }, s.error) : null,
56
+ s.status === 'idle' ? h('p', { style: msg + ';opacity:.7' }, 'Loading the scene…') : null,
57
+ props.controls && s.status === 'ready'
58
+ ? h('div', { style: 'display:flex;align-items:center;gap:12px;margin-top:10px;font:12px ui-monospace,monospace' }, [
59
+ h('button', { onClick: () => p.toggle(), 'aria-label': s.playing ? 'Pause' : 'Play' }, s.playing ? '❚❚' : '▶'),
60
+ h('input', { type: 'range', 'aria-label': 'Seek', min: 0, max: s.dur, step: 0.05, value: s.t, style: 'flex:1',
61
+ onInput: (e: Event) => p.seek(Number((e.target as HTMLInputElement).value)) }),
62
+ h('span', `${s.t.toFixed(1)} / ${s.dur.toFixed(1)}`),
63
+ ])
64
+ : null,
65
+ ]);
66
+ };
67
+ },
68
+ });
69
+
70
+ /** The story player: a film's scenes as slides, fitted to its box. Keys: ←/→, Space, M (sound), O (orientation). */
71
+ export const MotionShow = defineComponent({
72
+ name: 'MotionShow',
73
+ props: {
74
+ film: { type: String, required: true },
75
+ locale: { type: String, default: 'en' },
76
+ layout: { type: String as PropType<Layout>, default: 'landscape' },
77
+ mode: { type: String as PropType<Mode>, default: 'auto' },
78
+ controls: { type: Boolean, default: true },
79
+ slide: { type: Number, default: 1 },
80
+ loop: { type: Boolean, default: false },
81
+ },
82
+ emits: { ready: (_show: Show) => true },
83
+ setup(props, { emit, expose }) {
84
+ const stage = ref<HTMLElement | null>(null), fit = ref<HTMLElement | null>(null);
85
+ const show = shallowRef<Show | null>(null);
86
+ const st = useShowState(show);
87
+ const size = useSize(fit);
88
+ async function start() {
89
+ show.value?.destroy(); show.value = null;
90
+ const s = await createShow(stage.value!, props.film, { locale: props.locale, layout: props.layout, mode: props.mode, slide: props.slide, loop: props.loop });
91
+ show.value = s; s.fit(size.value.w, size.value.h); emit('ready', s);
92
+ }
93
+ onMounted(start);
94
+ onBeforeUnmount(() => show.value?.destroy());
95
+ watch(() => [props.film, props.locale, props.mode], start);
96
+ watch(() => props.layout, (l) => show.value?.setLayout(l));
97
+ watch([size, () => st.value?.layout], () => show.value?.fit(size.value.w, size.value.h));
98
+ expose({ show });
99
+ // Every key (←/→, Space, M, O, R, Home, F) from the core, so all players answer the same way.
100
+ const onKeydown = (e: KeyboardEvent) => { if (show.value && showKey(show.value, e, e.currentTarget as Element)) e.preventDefault(); };
101
+ const btn = 'min-width:34px;height:34px;border-radius:17px;border:1px solid currentColor;background:none;color:inherit;cursor:pointer;padding:0 10px';
102
+ return () => {
103
+ const s = show.value, x = st.value;
104
+ return h('div', { tabindex: 0, role: 'application', 'aria-label': 'Story player', onKeydown,
105
+ style: 'position:relative;width:100%;height:100%;display:flex;flex-direction:column;outline:none' }, [
106
+ h('div', { ref: fit, style: 'position:relative;flex:1;min-height:0;display:grid;place-items:center;overflow:hidden' }, [h('div', { ref: stage, style: 'position:relative' })]),
107
+ props.controls && s && x
108
+ ? h('div', { style: 'display:flex;gap:8px;align-items:center;justify-content:center;padding:8px;font:13px system-ui' }, [
109
+ h('button', { style: btn, onClick: () => s.prev(), 'aria-label': 'Previous scene' }, '‹'),
110
+ h('button', { style: btn, onClick: () => s.toggle(), 'aria-label': x.playing ? 'Pause' : 'Play' }, x.playing ? '❚❚' : '▶'),
111
+ h('button', { style: btn, onClick: () => s.next(), 'aria-label': 'Next scene' }, '›'),
112
+ h('span', { style: 'opacity:.7' }, `${x.index + 1} / ${s.timeline.scenes.length}`),
113
+ h('button', { style: btn, onClick: () => s.setSound(!x.sound), 'aria-pressed': x.sound }, x.sound ? 'Sound on' : 'Sound off'),
114
+ ])
115
+ : null,
116
+ ]);
117
+ };
118
+ },
119
+ });
120
+
121
+ /** The /show/<film> page the video pipeline drives: with `capture`, the stage at 1:1, no chrome, window.__show. */
122
+ export const ShowPage = defineComponent({
123
+ name: 'ShowPage',
124
+ props: {
125
+ film: { type: String, required: true },
126
+ layout: { type: String as PropType<Layout>, default: 'landscape' },
127
+ locale: { type: String, default: 'en' },
128
+ /** Capture renders light unless asked; the interactive player follows the page (auto). */
129
+ mode: { type: String as PropType<Mode>, default: undefined },
130
+ /** Force scenes from their JSON or their code modules (parity checks). */
131
+ src: { type: String as PropType<'json' | 'js'>, default: undefined },
132
+ capture: { type: Boolean, default: false },
133
+ },
134
+ setup(props) {
135
+ const host = ref<HTMLElement | null>(null);
136
+ let s: Show | null = null;
137
+ onMounted(async () => { if (props.capture) s = await installCapture(host.value!, props.film, props.layout, props.locale, { mode: props.mode ?? 'light', src: props.src }); });
138
+ onBeforeUnmount(() => s?.destroy());
139
+ return () => props.capture
140
+ ? h('div', { ref: host })
141
+ : h('div', { style: 'position:fixed;inset:0' }, [h(MotionShow, { film: props.film, layout: props.layout, locale: props.locale, mode: props.mode ?? 'auto' })]);
142
+ },
143
+ });
@@ -0,0 +1,44 @@
1
+ // Vue reactivity over the core: the core notifies, a shallowRef version makes reads tracked.
2
+ import { onBeforeUnmount, shallowRef, ref, watch, type Ref } from 'vue';
3
+ import type { createShow, Layout, ScenePlayerState } from '@senseihq/emaki';
4
+
5
+ /** A reactive view of a ScenePlayerState: read `state.value.t` etc. in templates; call methods on the player. */
6
+ export function useScenePlayer(player: ScenePlayerState) {
7
+ const version = ref(player.version);
8
+ const off = player.subscribe(() => { version.value = player.version; });
9
+ onBeforeUnmount(off);
10
+ const snap = () => ({ t: player.t, dur: player.dur, status: player.status, error: player.error, playing: player.playing, key: player.key, version: version.value });
11
+ const state = shallowRef(snap());
12
+ watch(version, () => { state.value = snap(); });
13
+ return state;
14
+ }
15
+
16
+ export type Show = Awaited<ReturnType<typeof createShow>>;
17
+ export interface ShowState { index: number; local: number; playing: boolean; sound: boolean; layout: Layout }
18
+
19
+ /** Reactive state of a story player controller (from <MotionShow @ready>). */
20
+ export function useShowState(show: Ref<Show | null>) {
21
+ const state = shallowRef<ShowState | null>(null);
22
+ let off: (() => void) | null = null;
23
+ watch(show, (s) => {
24
+ off?.(); off = null;
25
+ state.value = s ? { ...s.state } : null;
26
+ if (s) off = s.on((x) => { state.value = { ...x }; }) as () => void;
27
+ }, { immediate: true });
28
+ onBeforeUnmount(() => off?.());
29
+ return state;
30
+ }
31
+
32
+ /** Size of an element via ResizeObserver. */
33
+ export function useSize(el: Ref<HTMLElement | null>) {
34
+ const size = shallowRef({ w: 0, h: 0 });
35
+ let ro: ResizeObserver | null = null;
36
+ watch(el, (e) => {
37
+ ro?.disconnect();
38
+ if (!e) return;
39
+ ro = new ResizeObserver(([x]) => { size.value = { w: x.contentRect.width, h: x.contentRect.height }; });
40
+ ro.observe(e);
41
+ }, { immediate: true, flush: 'post' });
42
+ onBeforeUnmount(() => ro?.disconnect());
43
+ return size;
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { MotionScene, MotionShow, ScenePlayer, ShowPage } from './components.js';
2
+ export { useScenePlayer, useShowState, type Show, type ShowState } from './composables.js';
3
+ export { setupMotion, ScenePlayerState, type MotionSetup } from '@senseihq/emaki';