@motionhub/runtime 0.5.0 → 0.6.0
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 +3 -0
- package/index.d.ts +2 -0
- package/index.js +20 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,9 @@ check it scene by scene without running it:
|
|
|
49
49
|
- **`<Line id text>`**: what a scene says, its words as children (`text` where the caption differs). It draws nothing; an engine may speak
|
|
50
50
|
it or caption it.
|
|
51
51
|
- Anything else among `<Film>`'s children is drawn across the whole film.
|
|
52
|
+
- `<FilmScene id>` around a film draws its scene `id` alone, on the engine's clock, with the film's own layers on the film's: for an
|
|
53
|
+
engine that places each scene itself. A Remotion project exported from the Open Motion Studio puts each scene in a `Series.Sequence`
|
|
54
|
+
this way, so the scenes are named clips on Remotion Studio's timeline. A scene the film does not have is an error.
|
|
52
55
|
- `filmOutline(children, {width, height})` reads that structure from the elements themselves, without drawing them: `{seconds, scenes:
|
|
53
56
|
[{id, start, duration, layers, lines}], layers}`. `<Film>` reports it to the engine's `onFilm` while it is drawn, once for each structure (a new `onFilm` function on every
|
|
54
57
|
render is not called again for the same structure), when its value has one. A scene without an
|
package/index.d.ts
CHANGED
|
@@ -61,5 +61,7 @@ export declare const Film: FC<{children?: ReactNode}>;
|
|
|
61
61
|
export declare const Scene: FC<{id: string; duration: number; children?: ReactNode}>;
|
|
62
62
|
/** A box of the frame (`x`, `y`, `w`, `h` in pixels, the whole frame when left out), stacked by `z`, shown for its whole scene */
|
|
63
63
|
export declare const Layer: FC<{id: string; x?: number; y?: number; w?: number; h?: number; z?: number; style?: CSSProperties; children?: ReactNode}>;
|
|
64
|
+
/** The <Film> under it drawn as its scene `id` alone, on the engine's clock (its own layers on the film's), for an engine that places each scene */
|
|
65
|
+
export declare const FilmScene: FC<{id: string; children?: ReactNode}>;
|
|
64
66
|
/** What a scene says; it draws nothing */
|
|
65
67
|
export declare const Line: FC<{id: string; text?: string; children?: ReactNode}>;
|
package/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import {resolveTokens, tokenVariables} from './tokens.js';
|
|
|
37
37
|
const Runtime = createContext(null);
|
|
38
38
|
/**
|
|
39
39
|
* The engine's side: `value` has `useTime()` (seconds since the component's sequence began, a hook), `useCompositionTime()` (seconds since the film
|
|
40
|
-
* began, a hook), `fps`, `width`, `height`, `tokens` (resolved, as resolveTokens gives them), if the engine plays video `Video`,
|
|
40
|
+
* began, a hook), `fps`, `width`, `height`, `tokens` (resolved, as resolveTokens gives them), if the engine plays video `Video`, if it wants a
|
|
41
41
|
* <Film>'s structure, `onFilm(outline)`.
|
|
42
42
|
*/
|
|
43
43
|
export const MotionRuntimeProvider = ({value, children}) => createElement(Runtime.Provider, {value}, children);
|
|
@@ -183,17 +183,33 @@ export const Film = ({children}) => {
|
|
|
183
183
|
const onFilm = r.onFilm;
|
|
184
184
|
useMemo(() => onFilm?.(JSON.parse(reported)), [reported]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
185
185
|
const t = r.useTime();
|
|
186
|
+
const only = useContext(OnlyScene);
|
|
187
|
+
if (only !== null && !outline.scenes.some((scene) => scene.id === only)) {
|
|
188
|
+
throw new Error(`<FilmScene id="${only}">: the film has no scene "${only}", only ${outline.scenes.map((scene) => `"${scene.id}"`).join(', ')}`);
|
|
189
|
+
}
|
|
190
|
+
// Drawn one scene at a time (an engine that places each scene itself, as Remotion does in a <Series>), the scene keeps the engine's clock
|
|
191
|
+
// and the rest of the film, its own layers, is drawn on the film's.
|
|
192
|
+
const engine = only === null ? r : {...r, useTime: r.useCompositionTime};
|
|
186
193
|
let index = 0;
|
|
187
|
-
return createElement(InFilm.Provider, {value: true}, elements(children).map((e) => {
|
|
194
|
+
return createElement(Runtime.Provider, {value: engine}, createElement(InFilm.Provider, {value: true}, elements(children).map((e) => {
|
|
188
195
|
if (!isValidElement(e) || e.type !== Scene) return e;
|
|
189
196
|
const scene = outline.scenes[index++];
|
|
197
|
+
const key = e.key ?? scene.id;
|
|
198
|
+
if (only !== null) return scene.id === only ? createElement(Runtime.Provider, {key, value: r}, e) : null;
|
|
190
199
|
const last = index === outline.scenes.length;
|
|
191
200
|
if (t < scene.start || (t >= scene.start + scene.duration && !(last && t <= outline.seconds))) return null;
|
|
192
201
|
const value = {...r, useTime: () => r.useTime() - scene.start};
|
|
193
|
-
return createElement(Runtime.Provider, {key
|
|
194
|
-
}));
|
|
202
|
+
return createElement(Runtime.Provider, {key, value}, e);
|
|
203
|
+
})));
|
|
195
204
|
};
|
|
196
205
|
|
|
206
|
+
const OnlyScene = createContext(null);
|
|
207
|
+
/**
|
|
208
|
+
* The <Film> under it drawn as its scene `id` alone, on the engine's clock, with the film's own layers on the film's: for an engine that places
|
|
209
|
+
* each scene itself (Remotion: one in each Series.Sequence)
|
|
210
|
+
*/
|
|
211
|
+
export const FilmScene = ({id, children}) => createElement(OnlyScene.Provider, {value: id}, children);
|
|
212
|
+
|
|
197
213
|
/** One scene of a <Film>: `duration` seconds of it, `id` naming it. Its children (<Layer>s, <Line>s) belong to it and end with it */
|
|
198
214
|
export const Scene = ({id, children}) => {
|
|
199
215
|
if (!useContext(InFilm)) throw new Error(`<Scene id="${id}"> is drawn only inside a <Film>`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionhub/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "What a motion's React components draw with (time, frame, tokens, seeded randomness, video, caption), in any engine that provides it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|