-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathdemos-root.tsx
More file actions
94 lines (86 loc) · 3.32 KB
/
Copy pathdemos-root.tsx
File metadata and controls
94 lines (86 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import type { ComponentType } from "react";
import { loadFont } from "@remotion/google-fonts/Geist";
import { AbsoluteFill, Composition, Loop, registerRoot } from "remotion";
import { aiExamples } from "@/components/docs/examples/ai";
import { examples } from "@/components/docs/examples";
import { blockExamples } from "@/components/docs/examples/blocks";
/**
* Every renderable scene: the ui-tier `examples` (keyed `<name>-example`) plus
* the composition `blockExamples` (keyed `<name>-flow`). Key namespaces don't
* overlap, and both records share the timing/scene shape this root consumes.
*/
const ALL_SCENES = { ...examples, ...blockExamples, ...aiExamples };
/**
* Demos bundle root. Auto-declares one Remotion composition per docs example
* (the `examples` record is the single source of truth for timing + scene), so
* `scripts/render-demos.mts` can render every example to an mp4. Kept separate
* from `Root.tsx`/`index.ts` (the github-stars server bundle) — that entry is
* untouched; this one is bundled only by the demos render script.
*
* Two fidelity bridges make the mp4 match the on-site @remotion/player preview:
* - white stage background (= `--card` light = the `.surface-card` the preview
* sits on); self-painting scenes (e.g. blur-in) just cover it.
* - Geist loaded via @remotion/google-fonts, exposed as `--font-geist-sans` so
* the CSS var the scenes reference resolves to the real face (the site gets
* this from next/font, which doesn't exist in a standalone Remotion bundle).
*/
const { fontFamily: GEIST } = loadFont();
interface StageProps {
// Remotion requires composition props to extend Record<string, unknown>.
[key: string]: unknown;
/** One animation cycle, in frames (from the example's `durationInFrames`). */
loopFrames: number;
/** Repeat the cycle this many times (CLI `--loops`, default 1). */
loops: number;
}
/**
* Bind each example's scene at bundle time via closure — components are not
* JSON-serializable, so they can't ride through `defaultProps`/`inputProps`.
* Only the numeric loop knobs cross that boundary.
*/
function makeStage(Example: ComponentType) {
return function DemoStage({ loopFrames }: StageProps) {
return (
<AbsoluteFill
style={{
backgroundColor: "#ffffff",
["--font-geist-sans" as string]: GEIST,
fontFamily: GEIST,
}}
>
<Loop durationInFrames={loopFrames}>
<Example />
</Loop>
</AbsoluteFill>
);
};
}
// Stable component reference per composition (don't re-create inside render).
const STAGES: Record<string, ReturnType<typeof makeStage>> = Object.fromEntries(
Object.entries(ALL_SCENES).map(([id, entry]) => [
id,
makeStage(entry.Component),
]),
);
export function DemosRoot() {
return (
<>
{Object.entries(ALL_SCENES).map(([id, entry]) => (
<Composition
key={id}
id={id}
component={STAGES[id]}
durationInFrames={entry.durationInFrames}
fps={entry.fps}
width={entry.width}
height={entry.height}
defaultProps={{ loopFrames: entry.durationInFrames, loops: 1 }}
calculateMetadata={({ props }) => ({
durationInFrames: props.loopFrames * Math.max(1, props.loops),
})}
/>
))}
</>
);
}
registerRoot(DemosRoot);