@senseihq/emaki-react 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 +1 -1
- package/dist/components.d.ts +2 -1
- package/dist/components.js +7 -21
- package/package.json +2 -2
- package/src/components.tsx +7 -13
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Call `setupMotion({ source, site, logos })` once on the client first (`emaki ini
|
|
|
23
23
|
| `MotionScene` | `film`, `scene`, `layout` (`figure`), `locale`, `mode` (`auto`), `autoplay` |
|
|
24
24
|
| `MotionShow` | `film`, `locale`, `layout`, `mode` (`auto`), `controls`, `slide`, `loop`, `onReady(show)` |
|
|
25
25
|
| `ScenePlayer` | `player`, `locale`, `mode` (`auto`), `controls` |
|
|
26
|
-
| `ShowPage` | `film`, `layout`, `locale`, `mode` (capture: `light`), `capture` |
|
|
26
|
+
| `ShowPage` | `film`, `layout`, `locale`, `mode` (capture: `light`), `src` (`json`/`js`, forces the scene source), `capture` |
|
|
27
27
|
| `useScenePlayer(player)` | re-renders on every change of a `ScenePlayerState` (useSyncExternalStore) |
|
|
28
28
|
| `usePlayerFor(ref)` | a player you own, pointed at `{ film, scene, layout }` |
|
|
29
29
|
| `useShowState(show)` | `{ index, playing, sound, layout }` of a player controller |
|
package/dist/components.d.ts
CHANGED
|
@@ -43,7 +43,8 @@ export interface ShowPageProps {
|
|
|
43
43
|
layout?: Layout;
|
|
44
44
|
locale?: string;
|
|
45
45
|
mode?: Mode;
|
|
46
|
+
src?: 'json' | 'js';
|
|
46
47
|
capture?: boolean;
|
|
47
48
|
}
|
|
48
49
|
/** The /show/<film> page the video pipeline drives: with `capture`, the stage at 1:1, no chrome, window.__show. */
|
|
49
|
-
export declare function ShowPage({ film, layout, locale, mode, capture }: ShowPageProps): import("react").JSX.Element;
|
|
50
|
+
export declare function ShowPage({ film, layout, locale, mode, src, capture }: ShowPageProps): import("react").JSX.Element;
|
package/dist/components.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// React components over @senseihq/emaki. All are client components (they need the DOM); in Next.js import them
|
|
3
3
|
// from a file marked 'use client'. Call setupMotion({ source, site, logos }) once on the client first.
|
|
4
4
|
import { useEffect, useRef, useState } from 'react';
|
|
5
|
-
import { attachScene, createShow, installCapture } from '@senseihq/emaki';
|
|
5
|
+
import { attachScene, createShow, installCapture, showKey } from '@senseihq/emaki';
|
|
6
6
|
import { usePlayerFor, useScenePlayer, useShowState, useSize, useWidth } from './hooks.js';
|
|
7
7
|
/** Mounts a player's scene into a div and keeps it fitted (shared by MotionScene and ScenePlayer). */
|
|
8
8
|
function useAttached(player, locale, mode, autoplay) {
|
|
@@ -52,36 +52,22 @@ export function MotionShow({ film, locale = 'en', layout = 'landscape', mode = '
|
|
|
52
52
|
useEffect(() => { if (show && show.state.layout !== layout)
|
|
53
53
|
show.setLayout(layout); }, [show, layout]);
|
|
54
54
|
useEffect(() => { show?.fit(size.w, size.h); }, [show, size, st?.layout]);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const k = e.key.toLowerCase();
|
|
59
|
-
if (k === 'arrowright')
|
|
60
|
-
show.next();
|
|
61
|
-
else if (k === 'arrowleft')
|
|
62
|
-
show.prev();
|
|
63
|
-
else if (k === ' ') {
|
|
64
|
-
show.toggle();
|
|
65
|
-
e.preventDefault();
|
|
66
|
-
}
|
|
67
|
-
else if (k === 'm')
|
|
68
|
-
show.setSound(!show.state.sound);
|
|
69
|
-
else if (k === 'o')
|
|
70
|
-
show.setLayout(show.state.layout === 'landscape' ? 'portrait' : 'landscape');
|
|
71
|
-
};
|
|
55
|
+
// Every key (←/→, Space, M, O, R, Home, F) from the core, so all players answer the same way.
|
|
56
|
+
const onKeyDown = (e) => { if (show && showKey(show, e.nativeEvent, e.currentTarget))
|
|
57
|
+
e.preventDefault(); };
|
|
72
58
|
const btn = { minWidth: 34, height: 34, borderRadius: 17, border: '1px solid currentColor', background: 'none', color: 'inherit', cursor: 'pointer', padding: '0 10px' };
|
|
73
59
|
return (_jsxs("div", { tabIndex: 0, role: "application", "aria-label": "Story player", onKeyDown: onKeyDown, className: className, style: { position: 'relative', width: '100%', height: '100%', display: 'flex', flexDirection: 'column', outline: 'none', ...style }, children: [_jsx("div", { ref: fitRef, style: { position: 'relative', flex: 1, minHeight: 0, display: 'grid', placeItems: 'center', overflow: 'hidden' }, children: _jsx("div", { ref: stage, style: { position: 'relative' } }) }), controls && show && st && (_jsxs("div", { style: { display: 'flex', gap: 8, alignItems: 'center', justifyContent: 'center', padding: 8, font: '13px system-ui' }, children: [_jsx("button", { style: btn, onClick: () => show.prev(), "aria-label": "Previous scene", children: "\u2039" }), _jsx("button", { style: btn, onClick: () => show.toggle(), "aria-label": st.playing ? 'Pause' : 'Play', children: st.playing ? '❚❚' : '▶' }), _jsx("button", { style: btn, onClick: () => show.next(), "aria-label": "Next scene", children: "\u203A" }), _jsxs("span", { style: { opacity: 0.7 }, children: [st.index + 1, " / ", show.timeline.scenes.length] }), _jsx("button", { style: btn, onClick: () => show.setSound(!st.sound), "aria-pressed": st.sound, children: st.sound ? 'Sound on' : 'Sound off' })] }))] }));
|
|
74
60
|
}
|
|
75
61
|
/** The /show/<film> page the video pipeline drives: with `capture`, the stage at 1:1, no chrome, window.__show. */
|
|
76
|
-
export function ShowPage({ film, layout = 'landscape', locale = 'en', mode, capture = false }) {
|
|
62
|
+
export function ShowPage({ film, layout = 'landscape', locale = 'en', mode, src, capture = false }) {
|
|
77
63
|
const host = useRef(null);
|
|
78
64
|
useEffect(() => {
|
|
79
65
|
if (!capture)
|
|
80
66
|
return;
|
|
81
67
|
let s = null;
|
|
82
|
-
installCapture(host.current, film, layout, locale, mode ?? 'light').then((x) => { s = x; });
|
|
68
|
+
installCapture(host.current, film, layout, locale, { mode: mode ?? 'light', src }).then((x) => { s = x; });
|
|
83
69
|
return () => s?.destroy();
|
|
84
|
-
}, [capture, film, layout, locale, mode]);
|
|
70
|
+
}, [capture, film, layout, locale, mode, src]);
|
|
85
71
|
if (capture)
|
|
86
72
|
return _jsx("div", { ref: host });
|
|
87
73
|
return _jsx("div", { style: { position: 'fixed', inset: 0 }, children: _jsx(MotionShow, { film: film, layout: layout, locale: locale, mode: mode ?? 'auto' }) });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senseihq/emaki-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React components and hooks for motion stories: article figures, the story player, a controlled scene player and the video capture page.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"react": ">=18"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@senseihq/emaki": "0.1.
|
|
34
|
+
"@senseihq/emaki": "0.1.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "^19.1.0",
|
package/src/components.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// React components over @senseihq/emaki. All are client components (they need the DOM); in Next.js import them
|
|
2
2
|
// from a file marked 'use client'. Call setupMotion({ source, site, logos }) once on the client first.
|
|
3
3
|
import { useEffect, useRef, useState, type CSSProperties } from 'react';
|
|
4
|
-
import { attachScene, createShow, installCapture, type AttachedScene, type Layout, type Mode, type ScenePlayerState } from '@senseihq/emaki';
|
|
4
|
+
import { attachScene, createShow, installCapture, showKey, type AttachedScene, type Layout, type Mode, type ScenePlayerState } from '@senseihq/emaki';
|
|
5
5
|
import { usePlayerFor, useScenePlayer, useShowState, useSize, useWidth, type Show } from './hooks.js';
|
|
6
6
|
|
|
7
7
|
/** Mounts a player's scene into a div and keeps it fitted (shared by MotionScene and ScenePlayer). */
|
|
@@ -74,14 +74,8 @@ export function MotionShow({ film, locale = 'en', layout = 'landscape', mode = '
|
|
|
74
74
|
}, [film, locale, mode]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
75
75
|
useEffect(() => { if (show && show.state.layout !== layout) show.setLayout(layout); }, [show, layout]);
|
|
76
76
|
useEffect(() => { show?.fit(size.w, size.h); }, [show, size, st?.layout]);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const k = e.key.toLowerCase();
|
|
80
|
-
if (k === 'arrowright') show.next(); else if (k === 'arrowleft') show.prev();
|
|
81
|
-
else if (k === ' ') { show.toggle(); e.preventDefault(); }
|
|
82
|
-
else if (k === 'm') show.setSound(!show.state.sound);
|
|
83
|
-
else if (k === 'o') show.setLayout(show.state.layout === 'landscape' ? 'portrait' : 'landscape');
|
|
84
|
-
};
|
|
77
|
+
// Every key (←/→, Space, M, O, R, Home, F) from the core, so all players answer the same way.
|
|
78
|
+
const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => { if (show && showKey(show, e.nativeEvent, e.currentTarget)) e.preventDefault(); };
|
|
85
79
|
const btn: CSSProperties = { minWidth: 34, height: 34, borderRadius: 17, border: '1px solid currentColor', background: 'none', color: 'inherit', cursor: 'pointer', padding: '0 10px' };
|
|
86
80
|
return (
|
|
87
81
|
<div tabIndex={0} role="application" aria-label="Story player" onKeyDown={onKeyDown} className={className}
|
|
@@ -103,17 +97,17 @@ export function MotionShow({ film, locale = 'en', layout = 'landscape', mode = '
|
|
|
103
97
|
}
|
|
104
98
|
|
|
105
99
|
/** mode: capture renders light unless asked; the interactive player follows the page (auto). */
|
|
106
|
-
export interface ShowPageProps { film: string; layout?: Layout; locale?: string; mode?: Mode; capture?: boolean }
|
|
100
|
+
export interface ShowPageProps { film: string; layout?: Layout; locale?: string; mode?: Mode; src?: 'json' | 'js'; capture?: boolean }
|
|
107
101
|
|
|
108
102
|
/** The /show/<film> page the video pipeline drives: with `capture`, the stage at 1:1, no chrome, window.__show. */
|
|
109
|
-
export function ShowPage({ film, layout = 'landscape', locale = 'en', mode, capture = false }: ShowPageProps) {
|
|
103
|
+
export function ShowPage({ film, layout = 'landscape', locale = 'en', mode, src, capture = false }: ShowPageProps) {
|
|
110
104
|
const host = useRef<HTMLDivElement>(null);
|
|
111
105
|
useEffect(() => {
|
|
112
106
|
if (!capture) return;
|
|
113
107
|
let s: Show | null = null;
|
|
114
|
-
installCapture(host.current!, film, layout, locale, mode ?? 'light').then((x) => { s = x; });
|
|
108
|
+
installCapture(host.current!, film, layout, locale, { mode: mode ?? 'light', src }).then((x) => { s = x; });
|
|
115
109
|
return () => s?.destroy();
|
|
116
|
-
}, [capture, film, layout, locale, mode]);
|
|
110
|
+
}, [capture, film, layout, locale, mode, src]);
|
|
117
111
|
if (capture) return <div ref={host} />;
|
|
118
112
|
return <div style={{ position: 'fixed', inset: 0 }}><MotionShow film={film} layout={layout} locale={locale} mode={mode ?? 'auto'} /></div>;
|
|
119
113
|
}
|