@motionhub/remotion 0.3.0 → 0.4.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 CHANGED
@@ -75,6 +75,31 @@ made in a loop, they would show as one row. A scene's seconds are put on whole f
75
75
  the film follows by itself; a scene added, taken out or moved is an error until the `Series` places it. The film's own motions are its
76
76
  `<MotionScope>`s, so the provider's tokens can be empty.
77
77
 
78
+ ## A component's parameters in Remotion Studio
79
+
80
+ `paramsSchema(meta, z)` turns a component's `meta.params` into a composition's schema, so Remotion Studio's props editor edits
81
+ them; `paramDefaults(meta)` gives its `defaultProps`. Pass your project's `zod` (Remotion wants its own version):
82
+
83
+ ```tsx
84
+ import {z} from 'zod';
85
+ import {Composition} from 'remotion';
86
+ import {MotionProvider, paramDefaults, paramsSchema} from '@motionhub/remotion';
87
+ import tokens from '../motions/@iamsuosi/lab-notebook/tokens.json';
88
+ import {CurveArrow, meta} from '../motions/@iamsuosi/lab-notebook/react/parts/arrow.tsx';
89
+
90
+ const Arrow = (props) => <MotionProvider tokens={tokens}><CurveArrow {...props} /></MotionProvider>;
91
+
92
+ // paramDefaults gives what the meta has defaults for; a param with none (here from and to) is yours to give
93
+ <Composition id="arrow" component={Arrow} schema={paramsSchema(meta, z)} defaultProps={{...paramDefaults(meta), from: [400, 700], to: [1500, 380]}}
94
+ durationInFrames={90} fps={30} width={1920} height={1080} />
95
+ ```
96
+
97
+ A param whose `type` is in the vocabulary of SPEC.md §12 (`text`, `string`, `color`, `number`, `px`, `degrees`, `progress`, `boolean`,
98
+ `[x, y]`, `text[]`, or choices written `a | b | c`) is a field described by its `doc`: `progress` from 0 to 1, choices as a list.
99
+ One with no default is optional, one whose default is `null` is nullable. A param of any other type is not in the schema and passes
100
+ through untouched, for code to give. Remotion Studio edits the props live either way; to save them back into the source it needs
101
+ `defaultProps` written as an object literal, so write out what `paramDefaults(meta)` gives once you have it.
102
+
78
103
  ## Several motions in one film
79
104
 
80
105
  A film can change motion from scene to scene, or hold two in one frame ([a project's motions](../../SPEC.md#13-a-projects-motions)). Keep one `<MotionProvider>` outside every `<Sequence>`, and wrap each scene in `<MotionScope tokens>` from `@motionhub/runtime` (0.4 or later): the components under it read that motion's tokens and custom properties, and keep Remotion's frame and the film's time. Load every motion's faces before the first frame, each `<MotionFonts>` in its own scope with `root={false}`:
package/index.d.ts CHANGED
@@ -2,6 +2,16 @@ import type {FC, ReactNode} from 'react';
2
2
  import type {Tokens} from '@motionhub/runtime';
3
3
 
4
4
  export declare const MotionProvider: FC<{tokens: unknown; root?: boolean; children?: ReactNode}>;
5
+ /** A component's meta, as SPEC.md §12 has it */
6
+ type MetaOf = {params?: Record<string, {type: string; doc: string; default?: unknown}>};
7
+ /** The types of the vocabulary (SPEC.md §12, Parameters) a schema field is made for */
8
+ export declare const PARAM_TYPES: string[];
9
+ /** The choices of a type written `a | b | c`, or null */
10
+ export declare function paramChoices(type: string): string[] | null;
11
+ /** A composition's schema for a component, from its meta, built with the project's zod (`paramsSchema(meta, z)`) */
12
+ export declare function paramsSchema<Z>(meta: MetaOf, z: Z): any;
13
+ /** A composition's defaultProps for a component: every param's default, where it has one */
14
+ export declare function paramDefaults(meta: MetaOf): Record<string, unknown>;
5
15
  type FilmOf<P> = {fps?: number; width?: number; height?: number; props?: P};
6
16
  /** Each scene of the <Film> a component draws, by id, in whole frames that meet end to end */
7
17
  export declare function sceneFrames<P extends object>(Component: FC<P>, film?: FilmOf<P>): Record<string, number>;
package/index.js CHANGED
@@ -7,6 +7,7 @@ import {Easing, OffthreadVideo, Sequence, continueRender, delayRender, interpola
7
7
  import {MotionRoot, MotionRuntimeProvider, resolveTokens, useTokens} from '@motionhub/runtime';
8
8
 
9
9
  export {filmMetadata, sceneFrames} from './film.js';
10
+ export {PARAM_TYPES, paramChoices, paramDefaults, paramsSchema} from './params.js';
10
11
 
11
12
  const sequenceSeconds = () => useCurrentFrame() / useVideoConfig().fps;
12
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionhub/remotion",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Use a motion from motionhub.dev in Remotion: its React components as they are, and its tokens as Remotion values.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,6 +21,7 @@
21
21
  "files": [
22
22
  "index.js",
23
23
  "film.js",
24
+ "params.js",
24
25
  "index.d.ts",
25
26
  "README.md"
26
27
  ],
@@ -36,6 +37,7 @@
36
37
  "devDependencies": {
37
38
  "@motionhub/runtime": "file:../runtime",
38
39
  "react": "19.1.1",
39
- "react-dom": "19.1.1"
40
+ "react-dom": "19.1.1",
41
+ "zod": "4.6.7"
40
42
  }
41
43
  }
package/params.js ADDED
@@ -0,0 +1,55 @@
1
+ // A component's params (SPEC.md §12, Parameters) as a Remotion composition's schema: each param whose type is in the vocabulary
2
+ // becomes a zod field, described by its doc, so Remotion Studio edits it; any other is left to code and kept as it is. zod is the
3
+ // project's own (pass `z`), since Remotion wants its version. No Remotion here, so it is tested on its own (test.mjs).
4
+
5
+ const TYPES = {
6
+ text: (z) => z.string(),
7
+ string: (z) => z.string(),
8
+ color: (z) => z.string(),
9
+ number: (z) => z.number(),
10
+ px: (z) => z.number(),
11
+ degrees: (z) => z.number(),
12
+ progress: (z) => z.number().min(0).max(1),
13
+ boolean: (z) => z.boolean(),
14
+ '[x, y]': (z) => z.tuple([z.number(), z.number()]),
15
+ 'text[]': (z) => z.array(z.string()),
16
+ };
17
+
18
+ /** The types of the vocabulary a field is made for */
19
+ export const PARAM_TYPES = Object.keys(TYPES);
20
+
21
+ /** The choices of a type written `a | b | c` (words or numbers, none of them a type of the vocabulary or null); null for any other type */
22
+ export function paramChoices(type) {
23
+ const words = type.split(' | ');
24
+ if (words.length < 2 || !words.every((w) => /^(-?\d+(\.\d+)?|[a-z0-9-]+)$/.test(w))) return null;
25
+ return words.some((w) => w in TYPES || w === 'null') ? null : words;
26
+ }
27
+
28
+ /** The zod field for one param, or null when its type is outside the vocabulary */
29
+ function field(param, z) {
30
+ let f = TYPES[param.type]?.(z) ?? null;
31
+ const choices = f ? null : paramChoices(param.type);
32
+ if (choices) f = choices.every((c) => /^-?\d+(\.\d+)?$/.test(c)) ? z.union(choices.map((c) => z.literal(Number(c)))) : z.enum(choices);
33
+ if (!f) return null;
34
+ if (param.default === null) f = f.nullable();
35
+ else if (param.default === undefined) f = f.optional();
36
+ return f.describe(param.doc);
37
+ }
38
+
39
+ /**
40
+ * A composition's `schema` for a component, from its `meta`: `schema={paramsSchema(meta, z)}`. A param of a type outside the
41
+ * vocabulary is not in it, and passes through untouched; one with no default is optional, one whose default is null is nullable.
42
+ */
43
+ export function paramsSchema(meta, z) {
44
+ const shape = {};
45
+ for (const [name, param] of Object.entries(meta?.params ?? {})) {
46
+ const f = field(param, z);
47
+ if (f) shape[name] = f;
48
+ }
49
+ return z.looseObject ? z.looseObject(shape) : z.object(shape).passthrough();
50
+ }
51
+
52
+ /** A composition's `defaultProps` for a component, from its `meta`: every param's default, where it has one */
53
+ export function paramDefaults(meta) {
54
+ return Object.fromEntries(Object.entries(meta?.params ?? {}).filter(([, p]) => p.default !== undefined).map(([name, p]) => [name, p.default]));
55
+ }