remotion-ffmpeg-skill 0.0.0-stage → 0.2.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.
Files changed (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -2
  3. package/SKILL.md +66 -0
  4. package/bin/remotion-ffmpeg-skill.js +100 -0
  5. package/mcp/server.py +150 -0
  6. package/package.json +12 -4
  7. package/references/timeline.md +93 -0
  8. package/scripts/_captions.py +79 -0
  9. package/scripts/_common.py +538 -0
  10. package/scripts/_contract.py +202 -0
  11. package/scripts/analyze.py +240 -0
  12. package/scripts/deliver.py +79 -0
  13. package/scripts/doctor.py +83 -0
  14. package/scripts/init.py +62 -0
  15. package/scripts/pipeline.py +122 -0
  16. package/scripts/render.py +215 -0
  17. package/scripts/still.py +84 -0
  18. package/templates/remotion-project/package.json +20 -0
  19. package/templates/remotion-project/public/.gitkeep +0 -0
  20. package/templates/remotion-project/remotion.config.ts +6 -0
  21. package/templates/remotion-project/src/Root.tsx +32 -0
  22. package/templates/remotion-project/src/compositions/BeatMontage.tsx +60 -0
  23. package/templates/remotion-project/src/compositions/Captioned.tsx +95 -0
  24. package/templates/remotion-project/src/compositions/Highlights.tsx +98 -0
  25. package/templates/remotion-project/src/compositions/Jumpcut.tsx +52 -0
  26. package/templates/remotion-project/src/compositions/PeakPulse.tsx +73 -0
  27. package/templates/remotion-project/src/compositions/Titled.tsx +138 -0
  28. package/templates/remotion-project/src/index.ts +4 -0
  29. package/templates/remotion-project/src/lib/SourceVideo.tsx +84 -0
  30. package/templates/remotion-project/src/lib/useStagedFont.ts +25 -0
  31. package/templates/remotion-project/src/timeline.ts +214 -0
  32. package/templates/remotion-project/tsconfig.json +15 -0
@@ -0,0 +1,98 @@
1
+ import React from "react";
2
+ import { AbsoluteFill, Series, interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion";
3
+ import { SourceVideo } from "../lib/SourceVideo";
4
+ import { useStagedFont } from "../lib/useStagedFont";
5
+ import { Props, fontStack, highlightRanges, outputFrame, resolveOptions, secToFrames, type Options } from "../timeline";
6
+
7
+ /**
8
+ * Highlights: the highlight ranges ffmpeg-skill ranked (analyze.py --highlights, audio energy) played
9
+ * back to back in source order, a flash on each cut, a "2 / 5" counter, and the user's title over the
10
+ * first one. Which ranges count as highlights is ffmpeg-skill's measured proposal, not a verdict.
11
+ */
12
+ export const Highlights: React.FC<Props> = (props) => {
13
+ const { timeline, options, font } = props;
14
+ useStagedFont(font);
15
+ const o = resolveOptions(options);
16
+ const family = fontStack(o, font);
17
+ const fit = outputFrame(props).fit;
18
+ const { fps } = useVideoConfig();
19
+ const ranges = highlightRanges(timeline);
20
+ return (
21
+ <AbsoluteFill style={{ backgroundColor: "black" }}>
22
+ <Series>
23
+ {ranges.map(([s, e], i) => {
24
+ const a = secToFrames(s, fps);
25
+ const len = Math.max(1, secToFrames(e, fps) - a);
26
+ return (
27
+ <Series.Sequence key={i} durationInFrames={len} name={`highlight ${i + 1}`}>
28
+ <SourceVideo source={timeline.source} fit={fit} trimBefore={a} trimAfter={a + len} />
29
+ {i > 0 ? <CutFlash /> : null}
30
+ <Counter index={i} total={ranges.length} o={o} fontFamily={family} />
31
+ {i === 0 && o.title ? <Title text={o.title} len={len} o={o} fontFamily={family} /> : null}
32
+ </Series.Sequence>
33
+ );
34
+ })}
35
+ </Series>
36
+ </AbsoluteFill>
37
+ );
38
+ };
39
+
40
+ const CutFlash: React.FC = () => {
41
+ const frame = useCurrentFrame();
42
+ const { fps } = useVideoConfig();
43
+ const a = interpolate(frame, [0, fps * 0.2], [0.5, 0], { extrapolateRight: "clamp" });
44
+ return a > 0 ? <AbsoluteFill style={{ backgroundColor: "white", opacity: a }} /> : null;
45
+ };
46
+
47
+ const Counter: React.FC<{ index: number; total: number; o: Options; fontFamily: string }> = ({ index, total, o, fontFamily }) => {
48
+ const { width, height } = useVideoConfig();
49
+ if (total <= 1) return null;
50
+ const size = Math.round(Math.min(width, height) * 0.035);
51
+ return (
52
+ <AbsoluteFill style={{ justifyContent: "flex-start", alignItems: "flex-end", padding: size }}>
53
+ <div
54
+ style={{
55
+ fontFamily,
56
+ fontWeight: 800,
57
+ fontSize: size,
58
+ color: o.textColor,
59
+ background: "rgba(0,0,0,0.55)",
60
+ borderLeft: `${Math.max(3, size * 0.15)}px solid ${o.accent}`,
61
+ padding: `${size * 0.2}px ${size * 0.5}px`,
62
+ }}
63
+ >
64
+ {index + 1} / {total}
65
+ </div>
66
+ </AbsoluteFill>
67
+ );
68
+ };
69
+
70
+ const Title: React.FC<{ text: string; len: number; o: Options; fontFamily: string }> = ({ text, len, o, fontFamily }) => {
71
+ const frame = useCurrentFrame();
72
+ const { fps, width, height } = useVideoConfig();
73
+ const enter = spring({ frame, fps, config: { damping: 15 } });
74
+ const shown = Math.min(len, Math.round(fps * 2.5));
75
+ const exit = interpolate(frame, [shown - 8, shown], [1, 0], { extrapolateLeft: "clamp", extrapolateRight: "clamp" });
76
+ const size = Math.round(Math.min(width, height) * 0.075);
77
+ return (
78
+ <AbsoluteFill style={{ justifyContent: "center", alignItems: "center" }}>
79
+ <div
80
+ style={{
81
+ fontFamily,
82
+ fontWeight: 900,
83
+ fontSize: size,
84
+ color: o.textColor,
85
+ maxWidth: width * 0.84,
86
+ textAlign: "center",
87
+ whiteSpace: "pre-wrap",
88
+ textWrap: "balance",
89
+ opacity: Math.min(enter, exit),
90
+ transform: `translateY(${(1 - enter) * size}px)`,
91
+ textShadow: `0 0 ${size * 0.4}px rgba(0,0,0,0.8)`,
92
+ }}
93
+ >
94
+ {text}
95
+ </div>
96
+ </AbsoluteFill>
97
+ );
98
+ };
@@ -0,0 +1,52 @@
1
+ import React from "react";
2
+ import { AbsoluteFill, Sequence, Series, interpolate, useCurrentFrame, useVideoConfig } from "remotion";
3
+ import { SourceVideo } from "../lib/SourceVideo";
4
+ import { useStagedFont } from "../lib/useStagedFont";
5
+ import { CaptionCard } from "./Captioned";
6
+ import { Props, fontStack, outputFrame, resolveOptions, retimeCaptions, secToFrames, speechRanges } from "../timeline";
7
+
8
+ /**
9
+ * Jumpcut: plays only the speech ranges ffmpeg-skill measured (silences removed), and punches
10
+ * in on every other cut so the jumps read as intentional. Captions are re-timed onto the new
11
+ * timeline; the part of a cue that falls inside a removed silence is dropped, its text is never rewritten.
12
+ */
13
+ export const Jumpcut: React.FC<Props> = (props) => {
14
+ const { timeline, options, font } = props;
15
+ useStagedFont(font);
16
+ const o = resolveOptions(options);
17
+ const family = fontStack(o, font);
18
+ const fit = outputFrame(props).fit;
19
+ const { fps } = useVideoConfig();
20
+ const ranges = speechRanges(timeline);
21
+ const cues = retimeCaptions(timeline);
22
+ return (
23
+ <AbsoluteFill style={{ backgroundColor: "black" }}>
24
+ <Series>
25
+ {ranges.map(([s, e], i) => {
26
+ const a = secToFrames(s, fps);
27
+ const len = Math.max(1, secToFrames(e, fps) - a);
28
+ const zoom = i % 2 === 1 ? o.punchIn : 1;
29
+ return (
30
+ <Series.Sequence key={i} durationInFrames={len} name={`cut ${i + 1}`}>
31
+ <Punch zoom={zoom} len={len}>
32
+ <SourceVideo source={timeline.source} fit={fit} trimBefore={a} trimAfter={a + len} />
33
+ </Punch>
34
+ </Series.Sequence>
35
+ );
36
+ })}
37
+ </Series>
38
+ {cues.map((c, i) => (
39
+ <Sequence key={i} from={c.from} durationInFrames={c.durationInFrames} name={`cue ${i + 1}`} layout="none">
40
+ <CaptionCard text={c.text} durationInFrames={c.durationInFrames} o={o} fontFamily={family} />
41
+ </Sequence>
42
+ ))}
43
+ </AbsoluteFill>
44
+ );
45
+ };
46
+
47
+ const Punch: React.FC<{ zoom: number; len: number; children: React.ReactNode }> = ({ zoom, len, children }) => {
48
+ const frame = useCurrentFrame();
49
+ // A slow drift inside each cut keeps the frame alive; the step between cuts is the jump.
50
+ const drift = interpolate(frame, [0, len], [0, 0.015], { extrapolateRight: "clamp" });
51
+ return <AbsoluteFill style={{ transform: `scale(${zoom + drift})` }}>{children}</AbsoluteFill>;
52
+ };
@@ -0,0 +1,73 @@
1
+ import React from "react";
2
+ import { AbsoluteFill, interpolate, useCurrentFrame, useVideoConfig } from "remotion";
3
+ import { SourceVideo } from "../lib/SourceVideo";
4
+ import { Props, beatTimes, outputFrame, resolveOptions, secToFrames } from "../timeline";
5
+
6
+ /**
7
+ * PeakPulse: the source, full length, with motion driven by measurements instead of guesses --
8
+ * a frame-edge glow that hits on each audio peak ffmpeg-skill found (scaled by its loudness), or on
9
+ * every measured beat when the beat grid was measured (options.driver), a flash at every scene cut,
10
+ * and a progress bar.
11
+ */
12
+ export const PeakPulse: React.FC<Props> = (props) => {
13
+ const { timeline, options, overlay } = props;
14
+ const o = resolveOptions(options);
15
+ const frame = useCurrentFrame();
16
+ const { fps, width, height, durationInFrames } = useVideoConfig();
17
+
18
+ // What drives the pulse: measured beats (equal strength) or measured peaks (scaled by loudness).
19
+ const beats = beatTimes(timeline);
20
+ const useBeats = o.driver === "beats" || (o.driver === "auto" && beats.length > 0);
21
+ const maxRms = Math.max(1e-6, ...timeline.peaks.map((p) => p.rms));
22
+ const events = useBeats
23
+ ? beats.map((time) => ({ time, strength: 1 }))
24
+ : timeline.peaks.map((p) => ({ time: p.time, strength: p.rms / maxRms }));
25
+ // Strongest decaying hit among events at or before this frame.
26
+ let hit = 0;
27
+ for (const ev of events) {
28
+ const pf = secToFrames(ev.time, fps);
29
+ if (pf > frame) continue;
30
+ const age = frame - pf;
31
+ const decay = Math.exp(-age / (fps * (useBeats ? 0.12 : 0.18)));
32
+ hit = Math.max(hit, decay * ev.strength);
33
+ }
34
+ const glow = Math.round(Math.min(width, height) * 0.06 * o.pulse * hit);
35
+
36
+ const cuts = timeline.scenes.slice(1).map((s) => secToFrames(s.start, fps));
37
+ const flash = cuts.reduce((m, cf) => {
38
+ const age = frame - cf;
39
+ return age >= 0 && age < fps * 0.25 ? Math.max(m, 1 - age / (fps * 0.25)) : m;
40
+ }, 0);
41
+
42
+ const progress = interpolate(frame, [0, Math.max(1, durationInFrames - 1)], [0, 1], { extrapolateRight: "clamp" });
43
+ const barH = Math.max(4, Math.round(height * 0.008));
44
+
45
+ return (
46
+ <AbsoluteFill style={{ backgroundColor: overlay ? "transparent" : "black" }}>
47
+ {/* In overlay mode the source (and its slight zoom on peaks) is left to the composite step. */}
48
+ {overlay ? null : <SourceVideo source={timeline.source} fit={outputFrame(props).fit} style={{ transform: `scale(${1 + 0.02 * o.pulse * hit})` }} />}
49
+ <AbsoluteFill style={{ boxShadow: `inset 0 0 ${glow * 2}px ${glow}px ${o.accent}`, opacity: 0.85, pointerEvents: "none" }} />
50
+ {flash > 0 ? <AbsoluteFill style={{ backgroundColor: "white", opacity: 0.18 * flash }} /> : null}
51
+ {o.progressBar ? (
52
+ <AbsoluteFill style={{ justifyContent: "flex-end" }}>
53
+ <div style={{ position: "relative", height: barH, background: "rgba(255,255,255,0.18)" }}>
54
+ <div style={{ width: `${progress * 100}%`, height: "100%", background: o.accent }} />
55
+ {cuts.map((cf, i) => (
56
+ <div
57
+ key={i}
58
+ style={{
59
+ position: "absolute",
60
+ left: `${(cf / Math.max(1, durationInFrames - 1)) * 100}%`,
61
+ top: -barH,
62
+ width: Math.max(2, Math.round(barH / 2)),
63
+ height: barH * 3,
64
+ background: o.textColor,
65
+ }}
66
+ />
67
+ ))}
68
+ </div>
69
+ </AbsoluteFill>
70
+ ) : null}
71
+ </AbsoluteFill>
72
+ );
73
+ };
@@ -0,0 +1,138 @@
1
+ import React from "react";
2
+ import { AbsoluteFill, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion";
3
+ import { SourceVideo } from "../lib/SourceVideo";
4
+ import { useStagedFont } from "../lib/useStagedFont";
5
+ import { Props, fontStack, outputFrame, resolveOptions, secToFrames, type Options } from "../timeline";
6
+
7
+ /**
8
+ * Titled: the source, full length, with lower thirds the user wrote (options.lowerThirds) and a
9
+ * title card at the start of each measured scene (options.sceneTitles, in scene order). The skill
10
+ * places text where the measurements say; it never writes the text.
11
+ */
12
+ export const Titled: React.FC<Props> = (props) => {
13
+ const { timeline, options, font, overlay } = props;
14
+ useStagedFont(font);
15
+ const o = resolveOptions(options);
16
+ const family = fontStack(o, font);
17
+ const { fps } = useVideoConfig();
18
+ const sceneCards = timeline.scenes
19
+ .map((sc, i) => ({ sc, text: o.sceneTitles[i] }))
20
+ .filter((x): x is { sc: { start: number; end: number }; text: string } => Boolean(x.text));
21
+ return (
22
+ <AbsoluteFill style={{ backgroundColor: overlay ? "transparent" : "black" }}>
23
+ {overlay ? null : <SourceVideo source={timeline.source} fit={outputFrame(props).fit} />}
24
+ {sceneCards.map(({ sc, text }, i) => {
25
+ const from = secToFrames(sc.start, fps);
26
+ const dur = Math.max(1, Math.min(secToFrames(sc.end, fps), from + Math.round(fps * 2.5)) - from);
27
+ return (
28
+ <Sequence key={`s${i}`} from={from} durationInFrames={dur} name={`scene title ${i + 1}`} layout="none">
29
+ <SceneCard text={text} len={dur} o={o} fontFamily={family} />
30
+ </Sequence>
31
+ );
32
+ })}
33
+ {o.lowerThirds.map((lt, i) => {
34
+ const from = secToFrames(lt.start, fps);
35
+ const dur = Math.max(1, secToFrames(lt.end, fps) - from);
36
+ return (
37
+ <Sequence key={`l${i}`} from={from} durationInFrames={dur} name={`lower third ${i + 1}`} layout="none">
38
+ <LowerThirdCard text={lt.text} sub={lt.sub} len={dur} o={o} fontFamily={family} />
39
+ </Sequence>
40
+ );
41
+ })}
42
+ </AbsoluteFill>
43
+ );
44
+ };
45
+
46
+ const useInOut = (len: number) => {
47
+ const frame = useCurrentFrame();
48
+ const { fps } = useVideoConfig();
49
+ const enter = spring({ frame, fps, config: { damping: 16, stiffness: 160 } });
50
+ const fade = Math.min(8, Math.floor(len / 3));
51
+ const exit = fade > 0 ? interpolate(frame, [len - fade, len], [1, 0], { extrapolateLeft: "clamp", extrapolateRight: "clamp" }) : 1;
52
+ return { enter, exit };
53
+ };
54
+
55
+ const LowerThirdCard: React.FC<{ text: string; sub?: string; len: number; o: Options; fontFamily: string }> = ({
56
+ text,
57
+ sub,
58
+ len,
59
+ o,
60
+ fontFamily,
61
+ }) => {
62
+ const { width, height } = useVideoConfig();
63
+ const { enter, exit } = useInOut(len);
64
+ const short = Math.min(width, height);
65
+ const size = Math.round(short * 0.05);
66
+ const portrait = height > width;
67
+ return (
68
+ <AbsoluteFill
69
+ style={{
70
+ justifyContent: "flex-end",
71
+ alignItems: "flex-start",
72
+ padding: `0 0 ${height * (portrait ? 0.26 : 0.1)}px ${width * 0.06}px`,
73
+ }}
74
+ >
75
+ <div style={{ opacity: exit, transform: `translateX(${(1 - enter) * -width * 0.08}px)` }}>
76
+ <div
77
+ style={{
78
+ display: "inline-block",
79
+ background: o.accent,
80
+ color: "#111",
81
+ fontFamily,
82
+ fontWeight: 800,
83
+ fontSize: size,
84
+ padding: `${size * 0.2}px ${size * 0.45}px`,
85
+ whiteSpace: "pre-wrap",
86
+ }}
87
+ >
88
+ {text}
89
+ </div>
90
+ {sub ? (
91
+ <div
92
+ style={{
93
+ background: "rgba(0,0,0,0.7)",
94
+ color: o.textColor,
95
+ fontFamily,
96
+ fontWeight: 500,
97
+ fontSize: Math.round(size * 0.62),
98
+ padding: `${size * 0.16}px ${size * 0.45}px`,
99
+ whiteSpace: "pre-wrap",
100
+ width: "fit-content",
101
+ opacity: interpolate(enter, [0.4, 1], [0, 1], { extrapolateLeft: "clamp" }),
102
+ }}
103
+ >
104
+ {sub}
105
+ </div>
106
+ ) : null}
107
+ </div>
108
+ </AbsoluteFill>
109
+ );
110
+ };
111
+
112
+ const SceneCard: React.FC<{ text: string; len: number; o: Options; fontFamily: string }> = ({ text, len, o, fontFamily }) => {
113
+ const { width, height } = useVideoConfig();
114
+ const { enter, exit } = useInOut(len);
115
+ const size = Math.round(Math.min(width, height) * 0.08);
116
+ return (
117
+ <AbsoluteFill style={{ justifyContent: "center", alignItems: "center", background: `rgba(0,0,0,${0.35 * exit})` }}>
118
+ <div
119
+ style={{
120
+ color: o.textColor,
121
+ fontFamily,
122
+ fontWeight: 800,
123
+ fontSize: size,
124
+ maxWidth: width * 0.84,
125
+ textAlign: "center",
126
+ whiteSpace: "pre-wrap",
127
+ textWrap: "balance",
128
+ opacity: Math.min(enter, exit),
129
+ transform: `scale(${0.9 + 0.1 * enter})`,
130
+ textShadow: "0 4px 24px rgba(0,0,0,0.6)",
131
+ }}
132
+ >
133
+ {text}
134
+ <div style={{ height: Math.max(3, size * 0.06), background: o.accent, marginTop: size * 0.2, transform: `scaleX(${enter})` }} />
135
+ </div>
136
+ </AbsoluteFill>
137
+ );
138
+ };
@@ -0,0 +1,4 @@
1
+ import { registerRoot } from "remotion";
2
+ import { RemotionRoot } from "./Root";
3
+
4
+ registerRoot(RemotionRoot);
@@ -0,0 +1,84 @@
1
+ import React from "react";
2
+ import { AbsoluteFill, Audio, OffthreadVideo, staticFile, useCurrentFrame, useVideoConfig } from "remotion";
3
+ import type { Fit, Source } from "../timeline";
4
+
5
+ type Props = {
6
+ source: Source;
7
+ /** How the source fills the output frame when the shapes differ. */
8
+ fit?: Fit;
9
+ /** First source frame to play (composition fps = source fps). */
10
+ trimBefore?: number;
11
+ /** Source frame to stop at. */
12
+ trimAfter?: number;
13
+ style?: React.CSSProperties;
14
+ };
15
+
16
+ /**
17
+ * The measured source as the bottom layer.
18
+ * - video: OffthreadVideo, placed by `fit` (contain / cover / blur)
19
+ * - audio only: a neutral placeholder picture with the audio playing under it
20
+ * - nothing staged: the placeholder alone (Studio previews)
21
+ */
22
+ export const SourceVideo: React.FC<Props> = ({ source, fit = "contain", trimBefore, trimAfter, style }) => {
23
+ if (!source.src) {
24
+ return <Placeholder label={source.name} />;
25
+ }
26
+ const src = staticFile(source.src);
27
+ if (!source.has_video) {
28
+ return (
29
+ <AbsoluteFill style={style}>
30
+ <Placeholder label={source.name} />
31
+ {source.has_audio ? <Audio src={src} trimBefore={trimBefore} trimAfter={trimAfter} /> : null}
32
+ </AbsoluteFill>
33
+ );
34
+ }
35
+ const layer = (objectFit: "contain" | "cover", extra: React.CSSProperties = {}, muted = !source.has_audio) => (
36
+ <OffthreadVideo
37
+ src={src}
38
+ trimBefore={trimBefore}
39
+ trimAfter={trimAfter}
40
+ muted={muted}
41
+ style={{ width: "100%", height: "100%", objectFit, ...extra }}
42
+ />
43
+ );
44
+ if (fit === "blur") {
45
+ return (
46
+ <AbsoluteFill style={style}>
47
+ <AbsoluteFill style={{ overflow: "hidden" }}>
48
+ {/* The background copy is silent: the foreground carries the audio once. */}
49
+ {layer("cover", { filter: "blur(40px) brightness(0.55)", transform: "scale(1.15)" }, true)}
50
+ </AbsoluteFill>
51
+ <AbsoluteFill>{layer("contain")}</AbsoluteFill>
52
+ </AbsoluteFill>
53
+ );
54
+ }
55
+ return <AbsoluteFill style={style}>{layer(fit === "cover" ? "cover" : "contain")}</AbsoluteFill>;
56
+ };
57
+
58
+ const Placeholder: React.FC<{ label: string }> = ({ label }) => {
59
+ const frame = useCurrentFrame();
60
+ const { width, height, fps } = useVideoConfig();
61
+ const short = Math.min(width, height);
62
+ const grid = Math.round(short / 12);
63
+ return (
64
+ <AbsoluteFill
65
+ style={{
66
+ backgroundImage:
67
+ `linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),` +
68
+ `linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px),` +
69
+ `linear-gradient(135deg, #1b1f2a 0%, #2b3245 100%)`,
70
+ backgroundSize: `${grid}px ${grid}px, ${grid}px ${grid}px, 100% 100%`,
71
+ alignItems: "center",
72
+ justifyContent: "center",
73
+ color: "rgba(255,255,255,0.55)",
74
+ fontFamily: "monospace",
75
+ fontSize: Math.round(short * 0.035),
76
+ }}
77
+ >
78
+ <div>{label}</div>
79
+ <div style={{ fontSize: Math.round(short * 0.028), marginTop: short * 0.01 }}>
80
+ {width}x{height} · {(frame / fps).toFixed(2)}s
81
+ </div>
82
+ </AbsoluteFill>
83
+ );
84
+ };
@@ -0,0 +1,25 @@
1
+ import { useEffect, useState } from "react";
2
+ import { cancelRender, continueRender, delayRender, staticFile } from "remotion";
3
+ import type { FontAsset } from "../timeline";
4
+
5
+ /**
6
+ * Load the font render.py staged into public/ before any frame is captured, so the first
7
+ * frame already uses it (no fallback-font flash, no tofu). Fails the render loudly if the
8
+ * font cannot be loaded rather than silently drawing in another font.
9
+ */
10
+ export const useStagedFont = (font?: FontAsset | null): void => {
11
+ const [handle] = useState(() => (font ? delayRender(`font ${font.family}`) : null));
12
+ useEffect(() => {
13
+ if (!font || handle === null) return;
14
+ const face = new FontFace(font.family, `url(${staticFile(font.src)})`, { weight: "100 900" });
15
+ face
16
+ .load()
17
+ .then((loaded) => {
18
+ document.fonts.add(loaded);
19
+ continueRender(handle);
20
+ })
21
+ .catch((err: unknown) => {
22
+ cancelRender(new Error(`could not load font ${font.src}: ${String(err)}`));
23
+ });
24
+ }, [font, handle]);
25
+ };