agentcut 0.2.25 → 0.2.27
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 +177 -148
- package/dist/config.d.ts +0 -1
- package/dist/config.js +0 -5
- package/dist/config.js.map +1 -1
- package/dist/studio/agents/claude.js +3 -2
- package/dist/studio/agents/claude.js.map +1 -1
- package/dist/studio/chat.js +1 -1
- package/dist/studio/chat.js.map +1 -1
- package/dist/studio/cli.js +40 -21
- package/dist/studio/cli.js.map +1 -1
- package/dist/studio/download.d.ts +24 -0
- package/dist/studio/download.js +234 -0
- package/dist/studio/download.js.map +1 -0
- package/dist/studio/host.d.ts +1 -2
- package/dist/studio/host.js +36 -8
- package/dist/studio/host.js.map +1 -1
- package/dist/studio/housekeeping.d.ts +2 -2
- package/dist/studio/housekeeping.js +18 -17
- package/dist/studio/housekeeping.js.map +1 -1
- package/dist/studio/mcp-guides.js +1 -18
- package/dist/studio/mcp-guides.js.map +1 -1
- package/dist/studio/proc.js +16 -6
- package/dist/studio/proc.js.map +1 -1
- package/dist/studio/proxies.d.ts +4 -0
- package/dist/studio/proxies.js +15 -6
- package/dist/studio/proxies.js.map +1 -1
- package/dist/studio/release-cursor.js +21 -21
- package/dist/studio/release-video.js +10 -10
- package/dist/studio/schema.d.ts +0 -1
- package/dist/studio/schema.js +0 -1
- package/dist/studio/schema.js.map +1 -1
- package/dist/studio/tools.d.ts +0 -4
- package/dist/studio/tools.js +32 -31
- package/dist/studio/tools.js.map +1 -1
- package/dist/studio/voice/kokoro-catalog.d.ts +56 -28
- package/dist/studio/voice/kokoro-catalog.js +56 -28
- package/dist/studio/voice/kokoro-catalog.js.map +1 -1
- package/dist/studio/voice/ming-catalog.d.ts +19 -0
- package/dist/studio/voice/ming-catalog.js +40 -0
- package/dist/studio/voice/ming-catalog.js.map +1 -0
- package/dist/studio/voice/ming.d.ts +12 -0
- package/dist/studio/voice/ming.js +397 -0
- package/dist/studio/voice/ming.js.map +1 -0
- package/dist/studio/voice/previews.d.ts +5 -0
- package/dist/studio/voice/previews.js +50 -0
- package/dist/studio/voice/previews.js.map +1 -0
- package/dist/studio/voice/registry.js +2 -0
- package/dist/studio/voice/registry.js.map +1 -1
- package/dist/studio/voice.d.ts +1 -1
- package/dist/studio/voice.js +5 -6
- package/dist/studio/voice.js.map +1 -1
- package/package.json +56 -56
- package/template/AGENTS.md +14 -14
- package/template/components/README.md +70 -70
- package/template/components/before-after/BeforeAfter.tsx +89 -89
- package/template/components/catalog.ts +107 -107
- package/template/components/cinematic/Device3D.tsx +324 -324
- package/template/components/cinematic/devices3d/display-model.ts +184 -184
- package/template/components/cinematic/devices3d/iphone-model.ts +643 -643
- package/template/components/cinematic/devices3d/macbook-model.ts +608 -608
- package/template/components/cinematic/devices3d/models.ts +657 -657
- package/template/components/cinematic/devices3d/runtime.ts +267 -267
- package/template/components/cinematic/math.ts +100 -100
- package/template/components/color/grade-effect.ts +650 -650
- package/template/components/color/grade.ts +512 -512
- package/template/components/color/looks.ts +154 -154
- package/template/components/countdown/Countdown.tsx +166 -166
- package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -181
- package/template/components/dot-trace-title/meta.json +51 -51
- package/template/components/generate/GenerateReveal.tsx +381 -381
- package/template/components/hook-card/HookCard.tsx +554 -554
- package/template/components/index.ts +199 -199
- package/template/components/lib.ts +191 -191
- package/template/components/line-diagram/LineDiagram.tsx +205 -205
- package/template/components/line-diagram/meta.json +215 -215
- package/template/components/list-card/ListCard.tsx +104 -104
- package/template/components/live-clip.ts +75 -75
- package/template/components/looks.tsx +1447 -1447
- package/template/components/loops/LoopCanvas.tsx +132 -132
- package/template/components/loops/engine.ts +184 -184
- package/template/components/loops/library.ts +667 -667
- package/template/components/loops/library2.ts +777 -777
- package/template/components/motion-loop/MotionLoop.tsx +37 -37
- package/template/components/motion-loop/meta.json +311 -311
- package/template/components/props.ts +73 -73
- package/template/components/quote-card/QuoteCard.tsx +71 -71
- package/template/components/style-layer.tsx +233 -233
- package/template/components/styles.ts +113 -113
- package/template/components/types.ts +66 -66
- package/template/components/word-pop/WordPop.tsx +59 -59
- package/template/components/word-stack/WordStack.tsx +122 -122
- package/template/presets/charcoal-sketch/PROMPT.md +48 -48
- package/template/presets/charcoal-sketch/scripts/duck_music.py +34 -34
- package/template/presets/punk-cut-paper/scenes/Motif.tsx +376 -376
- package/template/presets/punk-cut-paper/scenes/Photo.tsx +73 -73
- package/template/presets/punk-cut-paper/scenes/Ransom.tsx +119 -119
- package/template/runtime/composition.tsx +1189 -1185
- package/template/runtime/helpers.tsx +230 -230
- package/template/runtime/index.tsx +22 -22
- package/template/runtime/types.ts +315 -315
- package/template/skill/SKILL.md +186 -351
- package/template/skill/references/broll.md +44 -44
- package/template/skill/references/browser-export.md +61 -61
- package/template/skill/references/cinematic.md +206 -206
- package/template/skill/references/color.md +79 -79
- package/template/skill/references/craft.md +54 -10
- package/template/skill/references/editing-styles.md +57 -57
- package/template/skill/references/feature-launch.md +5 -1
- package/template/skill/references/footage.md +72 -72
- package/template/skill/references/format.md +142 -142
- package/template/skill/references/how-to.md +0 -15
- package/template/skill/references/launch-direction.md +89 -0
- package/template/skill/references/loops.md +151 -151
- package/template/skill/references/mcp-external.md +19 -0
- package/template/skill/references/performance.md +93 -93
- package/template/skill/references/person-cutout.md +19 -19
- package/template/skill/references/presets.md +60 -60
- package/template/skill/references/product-launch.md +4 -1
- package/template/skill/references/release-capture.md +53 -0
- package/template/skill/references/sound.md +167 -155
- package/template/skill/references/style-spy.md +160 -160
- package/template/skill/references/website-howto.md +45 -45
- package/template/starter/.studio/chat.json +1 -1
- package/template/starter/layers.json +46 -46
- package/template/starter/notes.md +4 -4
- package/template/starter/project.json +13 -13
- package/template/starter/scenes/Title.tsx +38 -38
|
@@ -1,1185 +1,1189 @@
|
|
|
1
|
-
// StudioComposition: draws a project's layers.json with Remotion.
|
|
2
|
-
// Tracks are drawn bottom → top (tracks[0] is the top layer) so stacking never
|
|
3
|
-
// depends on z-index, which the browser export ignores.
|
|
4
|
-
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType, type CSSProperties, type ReactNode } from "react";
|
|
5
|
-
import {
|
|
6
|
-
AbsoluteFill,
|
|
7
|
-
Img,
|
|
8
|
-
Internals,
|
|
9
|
-
Sequence,
|
|
10
|
-
continueRender,
|
|
11
|
-
delayRender,
|
|
12
|
-
interpolate,
|
|
13
|
-
useCurrentFrame,
|
|
14
|
-
useRemotionEnvironment,
|
|
15
|
-
useVideoConfig,
|
|
16
|
-
} from "remotion";
|
|
17
|
-
import { Audio, Video } from "@remotion/media";
|
|
18
|
-
import type { EffectDescriptor } from "remotion";
|
|
19
|
-
import { framingCropAt } from "./framing";
|
|
20
|
-
// The Agentcut component library, provided by the studio page (and by a copy in
|
|
21
|
-
// .agentcut/components for local renders).
|
|
22
|
-
import * as ComponentLibrary from "agentcut/components";
|
|
23
|
-
import { MOTION_COMPONENTS, resolveComponentProps } from "agentcut/components";
|
|
24
|
-
|
|
25
|
-
// Project styles (project.json "style") come from the library too. Pages from before styles don't
|
|
26
|
-
// provide them: the project then renders as if it had none.
|
|
27
|
-
type LibraryStyle = { captions: CaptionsClip["style"]; text: TextClip["style"] };
|
|
28
|
-
function projectStyle(id: string | undefined): LibraryStyle | null {
|
|
29
|
-
const get = (ComponentLibrary as { getMotionStyle?: (id?: string) => LibraryStyle | null }).getMotionStyle;
|
|
30
|
-
return id && typeof get === "function" ? get(id) : null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type StyleLayer = {
|
|
34
|
-
styleCamera?: (
|
|
35
|
-
id: string | undefined,
|
|
36
|
-
at: { frame: number; durationInFrames: number; width: number; height: number },
|
|
37
|
-
) => CSSProperties | null;
|
|
38
|
-
StyleOverlay?: ComponentType<{ styleId: string | undefined }>;
|
|
39
|
-
StyledCaptions?: ComponentType<{
|
|
40
|
-
styleId: string | undefined;
|
|
41
|
-
words: CaptionsClip["words"];
|
|
42
|
-
position?: string;
|
|
43
|
-
wordsPerLine?: number;
|
|
44
|
-
fontSize?: number;
|
|
45
|
-
}>;
|
|
46
|
-
};
|
|
47
|
-
const styleLayer = ComponentLibrary as StyleLayer;
|
|
48
|
-
|
|
49
|
-
/** Loads the library's fonts (the style's caption and text fonts) and holds the render until they're in. */
|
|
50
|
-
function StyleFonts() {
|
|
51
|
-
const use = (ComponentLibrary as { useMotionFonts?: () => void }).useMotionFonts;
|
|
52
|
-
use?.();
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
import {
|
|
56
|
-
StudioRuntimeContext,
|
|
57
|
-
asset,
|
|
58
|
-
clamp,
|
|
59
|
-
setRuntimeState,
|
|
60
|
-
type StudioRuntimeContextValue,
|
|
61
|
-
} from "./helpers";
|
|
62
|
-
import type {
|
|
63
|
-
AudioClip,
|
|
64
|
-
AdjustmentClip,
|
|
65
|
-
Box,
|
|
66
|
-
CaptionsClip,
|
|
67
|
-
ClipAnim,
|
|
68
|
-
ColorGrade,
|
|
69
|
-
ImageClip,
|
|
70
|
-
SceneClip,
|
|
71
|
-
SceneProps,
|
|
72
|
-
StudioClip,
|
|
73
|
-
StudioCompositionProps,
|
|
74
|
-
StudioFont,
|
|
75
|
-
StudioTrack,
|
|
76
|
-
TextClip,
|
|
77
|
-
CursorTrack,
|
|
78
|
-
VideoClip,
|
|
79
|
-
VideoCursor,
|
|
80
|
-
} from "./types";
|
|
81
|
-
|
|
82
|
-
export type SceneRegistry = Record<string, ComponentType<SceneProps & Record<string, unknown>>>;
|
|
83
|
-
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
// Fonts
|
|
86
|
-
|
|
87
|
-
const loadedFontSpecs = new Map<string, Promise<void>>();
|
|
88
|
-
|
|
89
|
-
function fontSpecToCss(spec: string) {
|
|
90
|
-
// "Inter:400;700;900" → family=Inter:wght@400;700;900 ; "Inter" → family=Inter
|
|
91
|
-
const [family, weights] = spec.split(":");
|
|
92
|
-
const name = family.trim().replace(/\s+/g, "+");
|
|
93
|
-
return weights ? `family=${name}:wght@${weights.trim()}` : `family=${name}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function loadLocalFont(font: Exclude<StudioFont, string>): Promise<void> {
|
|
97
|
-
const key = `${font.family}|${font.src}|${font.weight ?? ""}|${font.style ?? ""}`;
|
|
98
|
-
const existing = loadedFontSpecs.get(key);
|
|
99
|
-
if (existing) return existing;
|
|
100
|
-
const promise = (async () => {
|
|
101
|
-
if (typeof document === "undefined") return;
|
|
102
|
-
const face = new FontFace(font.family, `url(${JSON.stringify(asset(font.src))})`, {
|
|
103
|
-
weight: font.weight ?? "400",
|
|
104
|
-
style: font.style ?? "normal",
|
|
105
|
-
});
|
|
106
|
-
try {
|
|
107
|
-
document.fonts.add(await face.load());
|
|
108
|
-
} catch {
|
|
109
|
-
// Missing font file: keep rendering with the fallback font.
|
|
110
|
-
}
|
|
111
|
-
})();
|
|
112
|
-
loadedFontSpecs.set(key, promise);
|
|
113
|
-
return promise;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function loadFont(font: StudioFont): Promise<void> {
|
|
117
|
-
return typeof font === "string" ? loadFontSpec(font) : loadLocalFont(font);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function loadFontSpec(spec: string): Promise<void> {
|
|
121
|
-
const existing = loadedFontSpecs.get(spec);
|
|
122
|
-
if (existing) return existing;
|
|
123
|
-
const promise = (async () => {
|
|
124
|
-
if (typeof document === "undefined") return;
|
|
125
|
-
const href = `https://fonts.googleapis.com/css2?${fontSpecToCss(spec)}&display=block`;
|
|
126
|
-
if (!document.querySelector(`link[data-studio-font="${CSS.escape(spec)}"]`)) {
|
|
127
|
-
const link = document.createElement("link");
|
|
128
|
-
link.rel = "stylesheet";
|
|
129
|
-
link.href = href;
|
|
130
|
-
link.crossOrigin = "anonymous";
|
|
131
|
-
link.dataset.studioFont = spec;
|
|
132
|
-
await new Promise<void>((resolve) => {
|
|
133
|
-
link.onload = () => resolve();
|
|
134
|
-
link.onerror = () => resolve();
|
|
135
|
-
document.head.appendChild(link);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
const [family, weights] = spec.split(":");
|
|
139
|
-
const list = weights ? weights.split(";").map((w) => w.trim()) : ["400"];
|
|
140
|
-
await Promise.all(
|
|
141
|
-
list.map((weight) =>
|
|
142
|
-
document.fonts.load(`${weight} 32px "${family.trim()}"`).catch(() => undefined),
|
|
143
|
-
),
|
|
144
|
-
);
|
|
145
|
-
})();
|
|
146
|
-
loadedFontSpecs.set(spec, promise);
|
|
147
|
-
return promise;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function useProjectFonts(fonts: StudioFont[]) {
|
|
151
|
-
const key = fonts.map((font) => (typeof font === "string" ? font : `${font.family}|${font.src}|${font.weight ?? ""}`)).join("||");
|
|
152
|
-
const [handle] = useState(() =>
|
|
153
|
-
fonts.length > 0 ? delayRender(`Loading fonts ${key}`, { timeoutInMilliseconds: 20_000 }) : null,
|
|
154
|
-
);
|
|
155
|
-
useEffect(() => {
|
|
156
|
-
if (handle === null) return;
|
|
157
|
-
let cancelled = false;
|
|
158
|
-
Promise.all(fonts.map(loadFont)).finally(() => {
|
|
159
|
-
if (!cancelled) continueRender(handle);
|
|
160
|
-
});
|
|
161
|
-
return () => {
|
|
162
|
-
cancelled = true;
|
|
163
|
-
};
|
|
164
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
165
|
-
}, [handle, key]);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ---------------------------------------------------------------------------
|
|
169
|
-
// Clip helpers
|
|
170
|
-
|
|
171
|
-
export function resolveClip<T extends StudioClip>(clip: T, variant: string): T {
|
|
172
|
-
const override = (clip as { variants?: Record<string, Partial<T>> }).variants?.[variant];
|
|
173
|
-
return override ? ({ ...clip, ...override } as T) : clip;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function animState(anim: ClipAnim | undefined, t: number) {
|
|
177
|
-
// t: 0 = fully hidden, 1 = fully shown
|
|
178
|
-
const preset = anim?.preset ?? "none";
|
|
179
|
-
const out: { opacity: number; transform: string; filter?: string } = { opacity: 1, transform: "" };
|
|
180
|
-
if (preset === "none" || t >= 1) return out;
|
|
181
|
-
const inv = 1 - t;
|
|
182
|
-
switch (preset) {
|
|
183
|
-
case "fade":
|
|
184
|
-
out.opacity = t;
|
|
185
|
-
break;
|
|
186
|
-
case "slide-up":
|
|
187
|
-
out.opacity = t;
|
|
188
|
-
out.transform = `translateY(${inv * 8}%)`;
|
|
189
|
-
break;
|
|
190
|
-
case "slide-down":
|
|
191
|
-
out.opacity = t;
|
|
192
|
-
out.transform = `translateY(${-inv * 8}%)`;
|
|
193
|
-
break;
|
|
194
|
-
case "slide-left":
|
|
195
|
-
out.opacity = t;
|
|
196
|
-
out.transform = `translateX(${inv * 8}%)`;
|
|
197
|
-
break;
|
|
198
|
-
case "slide-right":
|
|
199
|
-
out.opacity = t;
|
|
200
|
-
out.transform = `translateX(${-inv * 8}%)`;
|
|
201
|
-
break;
|
|
202
|
-
case "pop": {
|
|
203
|
-
// overshoot: 0 → 1.08 → 1
|
|
204
|
-
const s = t < 0.7 ? interpolate(t, [0, 0.7], [0.6, 1.08]) : interpolate(t, [0.7, 1], [1.08, 1]);
|
|
205
|
-
out.opacity = Math.min(1, t * 2);
|
|
206
|
-
out.transform = `scale(${s})`;
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
case "scale":
|
|
210
|
-
out.opacity = t;
|
|
211
|
-
out.transform = `scale(${0.85 + 0.15 * t})`;
|
|
212
|
-
break;
|
|
213
|
-
case "blur":
|
|
214
|
-
out.opacity = t;
|
|
215
|
-
out.filter = `blur(${inv * 16}px)`;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
return out;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const easeOutCubic = (t: number) => 1 - Math.pow(1 - t, 3);
|
|
222
|
-
|
|
223
|
-
/** Enter/exit + opacity wrapper for one visual clip; frame is local to the clip. */
|
|
224
|
-
function useClipStyle(clip: StudioClip): CSSProperties {
|
|
225
|
-
const frame = useCurrentFrame();
|
|
226
|
-
const enterFrames = clip.enter && clip.enter.preset !== "none" ? Math.max(1, clip.enter.frames) : 0;
|
|
227
|
-
const exitFrames = clip.exit && clip.exit.preset !== "none" ? Math.max(1, clip.exit.frames) : 0;
|
|
228
|
-
const tIn = enterFrames ? easeOutCubic(interpolate(frame, [0, enterFrames], [0, 1], clamp)) : 1;
|
|
229
|
-
const tOut = exitFrames
|
|
230
|
-
? easeOutCubic(interpolate(frame, [clip.duration - exitFrames, clip.duration], [1, 0], clamp))
|
|
231
|
-
: 1;
|
|
232
|
-
const a = animState(clip.enter, tIn);
|
|
233
|
-
const b = animState(clip.exit, tOut);
|
|
234
|
-
const transform = [a.transform, b.transform].filter(Boolean).join(" ");
|
|
235
|
-
const filter = [a.filter, b.filter].filter(Boolean).join(" ");
|
|
236
|
-
return {
|
|
237
|
-
opacity: a.opacity * b.opacity * (clip.opacity ?? 1),
|
|
238
|
-
transform: transform || undefined,
|
|
239
|
-
filter: filter || undefined,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function boxStyle(box: Box | undefined): CSSProperties {
|
|
244
|
-
if (!box) return { position: "absolute", left: 0, top: 0, width: "100%", height: "100%" };
|
|
245
|
-
return {
|
|
246
|
-
position: "absolute",
|
|
247
|
-
left: `${box.x * 100}%`,
|
|
248
|
-
top: `${box.y * 100}%`,
|
|
249
|
-
width: `${box.width * 100}%`,
|
|
250
|
-
height: `${box.height * 100}%`,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// ---------------------------------------------------------------------------
|
|
255
|
-
// Clip renderers (all frames local to the clip's <Sequence>)
|
|
256
|
-
|
|
257
|
-
function SceneClipView({
|
|
258
|
-
clip: saved,
|
|
259
|
-
scenes,
|
|
260
|
-
ctx,
|
|
261
|
-
}: {
|
|
262
|
-
clip: SceneClip;
|
|
263
|
-
scenes: SceneRegistry;
|
|
264
|
-
ctx: StudioRuntimeContextValue;
|
|
265
|
-
}) {
|
|
266
|
-
const clip = useLive(saved);
|
|
267
|
-
const style = useClipStyle(clip);
|
|
268
|
-
if (clip.component) {
|
|
269
|
-
const entry = MOTION_COMPONENTS[clip.component];
|
|
270
|
-
if (!entry) {
|
|
271
|
-
return (
|
|
272
|
-
<AbsoluteFill
|
|
273
|
-
style={{
|
|
274
|
-
alignItems: "center",
|
|
275
|
-
justifyContent: "center",
|
|
276
|
-
background: "rgba(220,38,38,0.25)",
|
|
277
|
-
color: "#fff",
|
|
278
|
-
fontFamily: "sans-serif",
|
|
279
|
-
fontSize: Math.round(ctx.height * 0.03),
|
|
280
|
-
}}
|
|
281
|
-
>
|
|
282
|
-
Unknown component “{clip.component}”
|
|
283
|
-
</AbsoluteFill>
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
const Component = entry.Component;
|
|
287
|
-
return (
|
|
288
|
-
<AbsoluteFill style={style}>
|
|
289
|
-
<Component
|
|
290
|
-
{...resolveComponentProps(clip.component, clip.props, ctx.project.style)}
|
|
291
|
-
width={ctx.width}
|
|
292
|
-
height={ctx.height}
|
|
293
|
-
fps={ctx.fps}
|
|
294
|
-
durationInFrames={clip.duration}
|
|
295
|
-
variant={ctx.variant}
|
|
296
|
-
/>
|
|
297
|
-
</AbsoluteFill>
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
const Scene = clip.scene ? scenes[clip.scene] : undefined;
|
|
301
|
-
if (!Scene) {
|
|
302
|
-
return (
|
|
303
|
-
<AbsoluteFill
|
|
304
|
-
style={{
|
|
305
|
-
alignItems: "center",
|
|
306
|
-
justifyContent: "center",
|
|
307
|
-
background: "rgba(220,38,38,0.25)",
|
|
308
|
-
color: "#fff",
|
|
309
|
-
fontFamily: "sans-serif",
|
|
310
|
-
fontSize: Math.round(ctx.height * 0.03),
|
|
311
|
-
}}
|
|
312
|
-
>
|
|
313
|
-
Missing scene “{clip.scene}” (scenes/{clip.scene}.tsx)
|
|
314
|
-
</AbsoluteFill>
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
return (
|
|
318
|
-
<AbsoluteFill style={style}>
|
|
319
|
-
<Scene
|
|
320
|
-
{...(clip.props ?? {})}
|
|
321
|
-
clip={{ id: clip.id, from: clip.from, duration: clip.duration }}
|
|
322
|
-
variant={ctx.variant}
|
|
323
|
-
width={ctx.width}
|
|
324
|
-
height={ctx.height}
|
|
325
|
-
fps={ctx.fps}
|
|
326
|
-
/>
|
|
327
|
-
</AbsoluteFill>
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function ImageClipView({ clip: saved, ctx }: { clip: ImageClip; ctx: TrackContext }) {
|
|
332
|
-
const clip = useLive(saved);
|
|
333
|
-
const style = useClipStyle(clip);
|
|
334
|
-
const { filter, effects } = useClipGrade(clip, ctx, clip.inheritGrade === true);
|
|
335
|
-
return (
|
|
336
|
-
<div style={{ ...boxStyle(clip.box), ...style, overflow: "hidden", borderRadius: clip.radius }}>
|
|
337
|
-
{effects.length ? (
|
|
338
|
-
// Effects draw images on a canvas, which needs its size in pixels.
|
|
339
|
-
<Img
|
|
340
|
-
src={asset(clip.src)}
|
|
341
|
-
width={Math.max(1, Math.round((clip.box?.width ?? 1) * ctx.width))}
|
|
342
|
-
height={Math.max(1, Math.round((clip.box?.height ?? 1) * ctx.height))}
|
|
343
|
-
effects={effects}
|
|
344
|
-
style={{ width: "100%", height: "100%", display: "block", objectFit: clip.fit ?? "cover" }}
|
|
345
|
-
/>
|
|
346
|
-
) : (
|
|
347
|
-
<Img
|
|
348
|
-
src={asset(clip.src)}
|
|
349
|
-
style={{ width: "100%", height: "100%", objectFit: clip.fit ?? "cover", display: "block", filter }}
|
|
350
|
-
/>
|
|
351
|
-
)}
|
|
352
|
-
</div>
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/** The runtime context plus what a clip needs to know about the stack it sits in. */
|
|
357
|
-
type TrackContext = StudioRuntimeContextValue & {
|
|
358
|
-
adjustments: { clip: AdjustmentClip; order: number }[];
|
|
359
|
-
/** Position in the stack, bottom to top. */
|
|
360
|
-
order: number;
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// The grade engine comes from the library too. Pages from before it don't provide it: those keep the
|
|
364
|
-
// CSS filter below, which covers the original controls.
|
|
365
|
-
const LIVE_PROJECT = "project";
|
|
366
|
-
type GradeEntry = { grade: ColorGrade; frame: number; strength?: number };
|
|
367
|
-
type GradeEngine = {
|
|
368
|
-
gradeEffects?: (grades: GradeEntry[], options: { seed: number; luts?: ReadonlyMap<string, unknown> }) => EffectDescriptor<unknown>[];
|
|
369
|
-
gradeLutPaths?: (grade: ColorGrade | undefined) => string[];
|
|
370
|
-
isCssGrade?: (grade: ColorGrade | undefined) => boolean;
|
|
371
|
-
canDrawGrade?: () => boolean;
|
|
372
|
-
parseCube?: (text: string) => unknown;
|
|
373
|
-
};
|
|
374
|
-
const gradeEngine = ComponentLibrary as GradeEngine;
|
|
375
|
-
|
|
376
|
-
// A moving slider's value, straight from the inspector. Older pages don't provide it.
|
|
377
|
-
type LiveEdits = {
|
|
378
|
-
useLiveClip?: <T extends { id: string }>(clip: T, isRendering?: boolean) => T;
|
|
379
|
-
useLiveClips?: (ids: string[], isRendering?: boolean) => void;
|
|
380
|
-
getLiveClip?: (id: string) => Record<string, unknown> | undefined;
|
|
381
|
-
};
|
|
382
|
-
const liveEdits = ComponentLibrary as LiveEdits;
|
|
383
|
-
const useLiveClipEngine = liveEdits.useLiveClip;
|
|
384
|
-
const useLiveClipsEngine = liveEdits.useLiveClips;
|
|
385
|
-
|
|
386
|
-
function useLive<T extends { id: string }>(clip: T): T {
|
|
387
|
-
const { isRendering } = useRemotionEnvironment();
|
|
388
|
-
// The library is fixed for the page's lifetime, so this always calls the same hooks.
|
|
389
|
-
return useLiveClipEngine ? useLiveClipEngine(clip, isRendering) : clip;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
const loadedLuts = new Map<string, unknown>();
|
|
393
|
-
const pendingLuts = new Map<string, Promise<void>>();
|
|
394
|
-
|
|
395
|
-
/** Load a .cube file once. A missing or broken file warns and the grade draws without it. */
|
|
396
|
-
function loadLut(path: string) {
|
|
397
|
-
let pending = pendingLuts.get(path);
|
|
398
|
-
if (!pending) {
|
|
399
|
-
pending = fetch(asset(path))
|
|
400
|
-
.then((response) => {
|
|
401
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
402
|
-
return response.text();
|
|
403
|
-
})
|
|
404
|
-
.then((text) => {
|
|
405
|
-
loadedLuts.set(path, gradeEngine.parseCube?.(text) ?? null);
|
|
406
|
-
})
|
|
407
|
-
.catch((error) => {
|
|
408
|
-
loadedLuts.set(path, null);
|
|
409
|
-
console.warn(`Could not load the LUT ${path}: ${error instanceof Error ? error.message : error}`);
|
|
410
|
-
});
|
|
411
|
-
pendingLuts.set(path, pending);
|
|
412
|
-
}
|
|
413
|
-
return pending;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/** Holds the render until these .cube files have loaded; later additions (preview edits) just redraw. */
|
|
417
|
-
function useGradeLuts(paths: string[]) {
|
|
418
|
-
const key = paths.join("\n");
|
|
419
|
-
const [, setLoaded] = useState(0);
|
|
420
|
-
const [handle] = useState(() =>
|
|
421
|
-
paths.some((path) => !loadedLuts.has(path)) ? delayRender(`Loading LUT ${paths.join(", ")}`, { timeoutInMilliseconds: 20_000 }) : null,
|
|
422
|
-
);
|
|
423
|
-
useEffect(() => {
|
|
424
|
-
let cancelled = false;
|
|
425
|
-
const wanted = key ? key.split("\n") : [];
|
|
426
|
-
Promise.all(wanted.map(loadLut))
|
|
427
|
-
.then(() => {
|
|
428
|
-
if (!cancelled) setLoaded((n) => n + 1);
|
|
429
|
-
})
|
|
430
|
-
.finally(() => {
|
|
431
|
-
if (handle !== null) continueRender(handle);
|
|
432
|
-
});
|
|
433
|
-
return () => {
|
|
434
|
-
cancelled = true;
|
|
435
|
-
};
|
|
436
|
-
}, [key, handle]);
|
|
437
|
-
return loadedLuts;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/** How far an adjustment clip is faded in at `local`: its enter and exit lengths ramp the grade. */
|
|
441
|
-
function adjustmentStrength(clip: AdjustmentClip, local: number) {
|
|
442
|
-
let strength = clip.opacity ?? 1;
|
|
443
|
-
if (clip.enter?.frames) strength *= Math.min(1, (local + 1) / clip.enter.frames);
|
|
444
|
-
if (clip.exit?.frames) strength *= Math.min(1, (clip.duration - local) / clip.exit.frames);
|
|
445
|
-
return strength;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* What draws a clip's colour: its own grade, then the adjustment layers above it and the project
|
|
450
|
-
* grade. A lone clip grade using only the original controls stays a CSS filter, so existing projects
|
|
451
|
-
* render exactly as they did.
|
|
452
|
-
*/
|
|
453
|
-
function useClipGrade(clip: VideoClip | ImageClip, ctx: TrackContext, inherits: boolean) {
|
|
454
|
-
const local = useCurrentFrame();
|
|
455
|
-
const frame = local + clip.from;
|
|
456
|
-
const { isRendering } = useRemotionEnvironment();
|
|
457
|
-
const liveIds = inherits ? [...ctx.adjustments.map((layer) => layer.clip.id), LIVE_PROJECT] : [];
|
|
458
|
-
useLiveClipsEngine?.(liveIds, isRendering);
|
|
459
|
-
const liveGrade = (id: string, saved: ColorGrade | undefined) => {
|
|
460
|
-
const fields = isRendering ? undefined : liveEdits.getLiveClip?.(id);
|
|
461
|
-
return fields && "grade" in fields ? (fields.grade as ColorGrade | undefined) : saved;
|
|
462
|
-
};
|
|
463
|
-
const grades: GradeEntry[] = [];
|
|
464
|
-
if (clip.grade) grades.push({ grade: clip.grade, frame: local });
|
|
465
|
-
const inherited: GradeEntry[] = [];
|
|
466
|
-
if (inherits) {
|
|
467
|
-
for (const layer of ctx.adjustments) {
|
|
468
|
-
if (layer.order <= ctx.order) continue;
|
|
469
|
-
const at = frame - layer.clip.from;
|
|
470
|
-
if (at < 0 || at >= layer.clip.duration) continue;
|
|
471
|
-
const grade = liveGrade(layer.clip.id, layer.clip.grade);
|
|
472
|
-
if (grade) inherited.push({ grade, frame: at, strength: adjustmentStrength(layer.clip, at) });
|
|
473
|
-
}
|
|
474
|
-
const projectGrade = liveGrade(LIVE_PROJECT, ctx.project.grade);
|
|
475
|
-
if (projectGrade) inherited.push({ grade: projectGrade, frame });
|
|
476
|
-
}
|
|
477
|
-
const paths = [...new Set([...grades, ...inherited].flatMap((entry) => gradeEngine.gradeLutPaths?.(entry.grade) ?? []))];
|
|
478
|
-
const luts = useGradeLuts(paths);
|
|
479
|
-
const useCss =
|
|
480
|
-
!gradeEngine.gradeEffects ||
|
|
481
|
-
!gradeEngine.canDrawGrade?.() ||
|
|
482
|
-
(inherited.length === 0 && (grades.length === 0 || gradeEngine.isCssGrade?.(grades[0].grade)));
|
|
483
|
-
if (useCss) return { filter: gradeFilter(clip.grade), effects: [] as EffectDescriptor<unknown>[] };
|
|
484
|
-
return {
|
|
485
|
-
filter: undefined,
|
|
486
|
-
effects: gradeEngine.gradeEffects!([...grades, ...inherited], { seed: frame, luts: luts as ReadonlyMap<string, unknown> }),
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/** CSS filter for a color grade (supported by the browser export). */
|
|
491
|
-
function gradeFilter(grade: VideoClip["grade"]): string | undefined {
|
|
492
|
-
if (!grade) return undefined;
|
|
493
|
-
const parts: string[] = [];
|
|
494
|
-
if (grade.brightness !== undefined && grade.brightness !== 1) parts.push(`brightness(${grade.brightness})`);
|
|
495
|
-
if (grade.contrast !== undefined && grade.contrast !== 1) parts.push(`contrast(${grade.contrast})`);
|
|
496
|
-
if (grade.saturation !== undefined && grade.saturation !== 1) parts.push(`saturate(${grade.saturation})`);
|
|
497
|
-
const warmth = grade.warmth ?? 0;
|
|
498
|
-
if (warmth > 0) parts.push(`sepia(${(warmth * 0.35).toFixed(3)})`, `saturate(${(1 + warmth * 0.25).toFixed(3)})`);
|
|
499
|
-
const hue = (grade.hue ?? 0) + (warmth < 0 ? warmth * -12 : warmth * -4);
|
|
500
|
-
if (hue) parts.push(`hue-rotate(${hue.toFixed(1)}deg)`);
|
|
501
|
-
return parts.length ? parts.join(" ") : undefined;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Frames this preview drew while paused, small and already graded. Coming back to one during a drag
|
|
505
|
-
// (the usual back-and-forth when looking for a cut) puts it on screen at once, over the player, until
|
|
506
|
-
// the decoder has redrawn it. Preview only; a wrong guess lasts only until that redraw.
|
|
507
|
-
const HELD_FRAME_WIDTH = 960;
|
|
508
|
-
/** About 200 MB at 16:9, across every clip. */
|
|
509
|
-
const MAX_HELD_FRAMES = 96;
|
|
510
|
-
const heldFrames = new Map<string, ImageBitmap>();
|
|
511
|
-
|
|
512
|
-
function holdFrame(key: string, frame: ImageBitmap) {
|
|
513
|
-
heldFrames.get(key)?.close();
|
|
514
|
-
heldFrames.delete(key);
|
|
515
|
-
heldFrames.set(key, frame);
|
|
516
|
-
if (heldFrames.size > MAX_HELD_FRAMES) {
|
|
517
|
-
const oldest = heldFrames.keys().next().value!;
|
|
518
|
-
heldFrames.get(oldest)?.close();
|
|
519
|
-
heldFrames.delete(oldest);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
function useHeldFrames(version: string, frame: number, enabled: boolean) {
|
|
524
|
-
const boxRef = useRef<HTMLDivElement>(null);
|
|
525
|
-
const overlayRef = useRef<HTMLCanvasElement>(null);
|
|
526
|
-
const latest = useRef({ version, frame, enabled });
|
|
527
|
-
/** The frame the decoder's picture shows: nothing needs to cover it. */
|
|
528
|
-
const drawn = useRef<number | null>(null);
|
|
529
|
-
useLayoutEffect(() => {
|
|
530
|
-
latest.current = { version, frame, enabled };
|
|
531
|
-
const overlay = overlayRef.current;
|
|
532
|
-
if (!overlay) return;
|
|
533
|
-
if (!enabled || drawn.current === frame) {
|
|
534
|
-
overlay.style.visibility = "hidden";
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const picture = heldFrames.get(`${version}:${frame}`);
|
|
538
|
-
if (!picture) return;
|
|
539
|
-
if (overlay.width !== picture.width) overlay.width = picture.width;
|
|
540
|
-
if (overlay.height !== picture.height) overlay.height = picture.height;
|
|
541
|
-
overlay.getContext("2d")?.drawImage(picture, 0, 0);
|
|
542
|
-
overlay.style.visibility = "visible";
|
|
543
|
-
}, [version, frame, enabled]);
|
|
544
|
-
const onDrawn = useCallback(() => {
|
|
545
|
-
const now = latest.current;
|
|
546
|
-
drawn.current = now.frame;
|
|
547
|
-
const overlay = overlayRef.current;
|
|
548
|
-
if (overlay) overlay.style.visibility = "hidden";
|
|
549
|
-
if (!now.enabled) return;
|
|
550
|
-
// The player's own canvas, which has the grade on it (the callback's frame doesn't yet).
|
|
551
|
-
const canvas = boxRef.current?.querySelector<HTMLCanvasElement>("canvas");
|
|
552
|
-
if (!canvas || canvas === overlay || !canvas.width || !canvas.height) return;
|
|
553
|
-
const width = Math.min(HELD_FRAME_WIDTH, canvas.width);
|
|
554
|
-
const key = `${now.version}:${now.frame}`;
|
|
555
|
-
void createImageBitmap(canvas, {
|
|
556
|
-
resizeWidth: width,
|
|
557
|
-
resizeHeight: Math.max(1, Math.round((canvas.height * width) / canvas.width)),
|
|
558
|
-
resizeQuality: "low",
|
|
559
|
-
}).then((picture) => holdFrame(key, picture), () => undefined);
|
|
560
|
-
}, []);
|
|
561
|
-
return { boxRef, overlayRef, onDrawn };
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
function VideoClipView({
|
|
565
|
-
clip: saved,
|
|
566
|
-
trackMuted,
|
|
567
|
-
gain,
|
|
568
|
-
ctx,
|
|
569
|
-
}: {
|
|
570
|
-
clip: VideoClip;
|
|
571
|
-
trackMuted: boolean;
|
|
572
|
-
gain: number;
|
|
573
|
-
ctx: TrackContext;
|
|
574
|
-
}) {
|
|
575
|
-
const clip = useLive(saved);
|
|
576
|
-
const style = useClipStyle(clip);
|
|
577
|
-
const frame = useCurrentFrame();
|
|
578
|
-
const grade = useClipGrade(clip, ctx, clip.inheritGrade !== false);
|
|
579
|
-
const { isRendering } = useRemotionEnvironment();
|
|
580
|
-
const playing = Internals.Timeline.usePlaying();
|
|
581
|
-
const source = (!isRendering && ctx.previewProxies?.[clip.src]) || asset(clip.src);
|
|
582
|
-
const held = useHeldFrames(
|
|
583
|
-
`${clip.id}|${source}|${clip.trimStart ?? 0}|${clip.playbackRate ?? 1}|${clip.fit ?? ""}|${grade.filter ?? ""}|${JSON.stringify(clip.grade ?? null)}|${JSON.stringify(ctx.project.grade ?? null)}|${ctx.adjustments.length}`,
|
|
584
|
-
frame,
|
|
585
|
-
!isRendering && !playing,
|
|
586
|
-
);
|
|
587
|
-
// The project style's camera (punch-ins, drift, …) moves the footage inside its box.
|
|
588
|
-
const crop = clip.framing ? framingCropAt(clip.framing, (clip.trimStart ?? 0) / ctx.project.fps + frame / ctx.project.fps * (clip.playbackRate ?? 1)) : null;
|
|
589
|
-
const camera =
|
|
590
|
-
ctx.project.style && clip.camera !== "none" && styleLayer.styleCamera
|
|
591
|
-
? styleLayer.styleCamera(ctx.project.style, { frame, durationInFrames: clip.duration, width: ctx.width, height: ctx.height })
|
|
592
|
-
: null;
|
|
593
|
-
return (
|
|
594
|
-
<div style={{ ...boxStyle(clip.box), ...style, overflow: "hidden", borderRadius: clip.radius }}>
|
|
595
|
-
<div style={{ position: "absolute", inset: 0, ...(clip.framing ? { filter: camera?.filter } : camera) }}>
|
|
596
|
-
<div ref={held.boxRef} style={crop ? {
|
|
597
|
-
position: "absolute", left: `${-crop.x / crop.width * 100}%`,
|
|
598
|
-
top: `${-crop.y / crop.height * 100}%`,
|
|
599
|
-
width: `${100 / crop.width}%`, height: `${100 / crop.height}%`,
|
|
600
|
-
} : { position: "absolute", inset: 0 }}>
|
|
601
|
-
<Video
|
|
602
|
-
src={source}
|
|
603
|
-
trimBefore={clip.trimStart && clip.trimStart > 0 ? clip.trimStart : undefined}
|
|
604
|
-
volume={(clip.volume ?? 1) * gain}
|
|
605
|
-
muted={trackMuted || clip.muted}
|
|
606
|
-
playbackRate={clip.playbackRate}
|
|
607
|
-
// @remotion/media draws the frame itself: fit has to be its prop (CSS object-fit is ignored).
|
|
608
|
-
objectFit={clip.framing ? "fill" : clip.fit ?? "cover"}
|
|
609
|
-
style={{ width: "100%", height: "100%", filter: grade.filter }}
|
|
610
|
-
{...(grade.effects.length ? { effects: grade.effects } : {})}
|
|
611
|
-
{...(isRendering ? {} : { onVideoFrame: held.onDrawn })}
|
|
612
|
-
/>
|
|
613
|
-
{isRendering ? null : (
|
|
614
|
-
<canvas
|
|
615
|
-
ref={held.overlayRef}
|
|
616
|
-
style={{ position: "absolute", inset: 0, width: "100%", height: "100%", filter: grade.filter, visibility: "hidden" }}
|
|
617
|
-
/>
|
|
618
|
-
)}
|
|
619
|
-
{clip.cursor ? <CursorOverlay cursor={clip.cursor} clip={clip} /> : null}
|
|
620
|
-
</div>
|
|
621
|
-
</div>
|
|
622
|
-
</div>
|
|
623
|
-
);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// ---------------------------------------------------------------------------
|
|
627
|
-
// Recorded cursor (`cursor` on a video clip): the pointer and click ripples from a
|
|
628
|
-
// `<video>.cursor.json`, drawn inside the clip so it follows its trim, speed and box.
|
|
629
|
-
|
|
630
|
-
const loadedCursorTracks = new Map<string, CursorTrack | null>();
|
|
631
|
-
const pendingCursorTracks = new Map<string, Promise<CursorTrack | null>>();
|
|
632
|
-
|
|
633
|
-
function loadCursorTrack(url: string) {
|
|
634
|
-
let pending = pendingCursorTracks.get(url);
|
|
635
|
-
if (!pending) {
|
|
636
|
-
pending = fetch(url)
|
|
637
|
-
.then((response) => (response.ok ? (response.json() as Promise<CursorTrack>) : null))
|
|
638
|
-
.catch(() => null)
|
|
639
|
-
.then((track) => {
|
|
640
|
-
loadedCursorTracks.set(url, track);
|
|
641
|
-
return track;
|
|
642
|
-
});
|
|
643
|
-
pendingCursorTracks.set(url, pending);
|
|
644
|
-
}
|
|
645
|
-
return pending;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
function useCursorTrack(src: string) {
|
|
649
|
-
const url = asset(src);
|
|
650
|
-
const [track, setTrack] = useState(() => loadedCursorTracks.get(url) ?? null);
|
|
651
|
-
const [handle] = useState(() =>
|
|
652
|
-
loadedCursorTracks.has(url) ? null : delayRender(`Loading cursor ${src}`, { timeoutInMilliseconds: 20_000 }),
|
|
653
|
-
);
|
|
654
|
-
useEffect(() => {
|
|
655
|
-
let cancelled = false;
|
|
656
|
-
loadCursorTrack(url)
|
|
657
|
-
.then((loaded) => {
|
|
658
|
-
if (!cancelled) setTrack(loaded);
|
|
659
|
-
})
|
|
660
|
-
.finally(() => {
|
|
661
|
-
if (handle !== null) continueRender(handle);
|
|
662
|
-
});
|
|
663
|
-
return () => {
|
|
664
|
-
cancelled = true;
|
|
665
|
-
};
|
|
666
|
-
}, [url, handle]);
|
|
667
|
-
return track;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function cursorPointAt(path: CursorTrack["path"], frame: number) {
|
|
671
|
-
let low = 0;
|
|
672
|
-
let high = path.length - 1;
|
|
673
|
-
let index = -1;
|
|
674
|
-
while (low <= high) {
|
|
675
|
-
const mid = (low + high) >> 1;
|
|
676
|
-
if (path[mid][0] <= frame) {
|
|
677
|
-
index = mid;
|
|
678
|
-
low = mid + 1;
|
|
679
|
-
} else {
|
|
680
|
-
high = mid - 1;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
if (index < 0) return null;
|
|
684
|
-
const [from, x, y] = path[index];
|
|
685
|
-
if (x === null || y === null) return null;
|
|
686
|
-
const next = path[index + 1];
|
|
687
|
-
if (!next || next[1] === null || next[2] === null || next[0] <= from) return { x, y };
|
|
688
|
-
const t = Math.min(1, (frame - from) / (next[0] - from));
|
|
689
|
-
return { x: x + (next[1] - x) * t, y: y + (next[2] - y) * t };
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
const CURSOR_POINTER_PATH =
|
|
693
|
-
"M3.55 1.75Q2.65 1.4 2.65 2.45L2.65 19.95Q2.65 21.45 3.6 21.75Q4.2 21.95 4.85 21.3L8.25 17.85Q8.65 17.45 8.9 17.98L11.65 23.4Q12.15 24.35 13.1 23.88L15.55 22.7Q16.55 22.22 16.05 21.25L13.3 15.8Q13.02 15.25 13.65 15.25L19.1 15.25Q20.55 15.25 20.78 14.2Q20.95 13.42 20.05 12.78L4.45 1.95Q3.98 1.62 3.55 1.75Z";
|
|
694
|
-
const CURSOR_GREEN = "#2dd47a";
|
|
695
|
-
const HAND_EMOJI = "\u{1F446}";
|
|
696
|
-
|
|
697
|
-
function CursorOverlay({ cursor, clip }: { cursor: VideoCursor; clip: VideoClip }) {
|
|
698
|
-
const frame = useCurrentFrame();
|
|
699
|
-
const { width: compWidth, height: compHeight } = useVideoConfig();
|
|
700
|
-
const track = useCursorTrack(cursor.src);
|
|
701
|
-
// Edits ("source" space) carry clicks for timing only: their positions don't match the picture.
|
|
702
|
-
if (!track || track.space !== "video") return null;
|
|
703
|
-
|
|
704
|
-
const style = cursor.style ?? "classic";
|
|
705
|
-
const fps = track.fps;
|
|
706
|
-
const sourceFrame = (clip.trimStart ?? 0) + frame * (clip.playbackRate ?? 1);
|
|
707
|
-
|
|
708
|
-
// Where the video's picture sits inside the clip box (contain letterboxes, cover crops).
|
|
709
|
-
const box = clip.box ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
710
|
-
const boxWidth = box.width * compWidth;
|
|
711
|
-
const boxHeight = box.height * compHeight;
|
|
712
|
-
const videoWidth = track.width ?? boxWidth;
|
|
713
|
-
const videoHeight = track.height ?? boxHeight;
|
|
714
|
-
const scale =
|
|
715
|
-
(clip.fit ?? "cover") === "contain"
|
|
716
|
-
? Math.min(boxWidth / videoWidth, boxHeight / videoHeight)
|
|
717
|
-
: Math.max(boxWidth / videoWidth, boxHeight / videoHeight);
|
|
718
|
-
const offsetX = (boxWidth - videoWidth * scale) / 2;
|
|
719
|
-
const offsetY = (boxHeight - videoHeight * scale) / 2;
|
|
720
|
-
const toBox = (x: number, y: number) => ({
|
|
721
|
-
left: offsetX + x * videoWidth * scale,
|
|
722
|
-
top: offsetY + y * videoHeight * scale,
|
|
723
|
-
});
|
|
724
|
-
|
|
725
|
-
// Sized to the frame, not the box, so a punch-in doesn't blow the pointer up.
|
|
726
|
-
const size =
|
|
727
|
-
Math.max(18, Math.min(44, Math.min(compWidth, compHeight) * 0.032)) * ((cursor.size ?? 100) / 100);
|
|
728
|
-
|
|
729
|
-
// Smoothing averages the path over a short window around this frame.
|
|
730
|
-
const reach = Math.round((cursor.smoothing ?? 0.3) * 0.2 * fps);
|
|
731
|
-
let sumX = 0;
|
|
732
|
-
let sumY = 0;
|
|
733
|
-
let count = 0;
|
|
734
|
-
for (let offset = -reach; offset <= reach; offset += 1) {
|
|
735
|
-
const sample = cursorPointAt(track.path, sourceFrame + offset);
|
|
736
|
-
if (!sample) continue;
|
|
737
|
-
sumX += sample.x;
|
|
738
|
-
sumY += sample.y;
|
|
739
|
-
count += 1;
|
|
740
|
-
}
|
|
741
|
-
const point = cursorPointAt(track.path, sourceFrame) && count ? toBox(sumX / count, sumY / count) : null;
|
|
742
|
-
|
|
743
|
-
const rippleFrames = 0.6 * fps;
|
|
744
|
-
const ripples =
|
|
745
|
-
cursor.clicks === false
|
|
746
|
-
? []
|
|
747
|
-
: track.clicks.filter((click) => sourceFrame >= click.frame && sourceFrame - click.frame < rippleFrames);
|
|
748
|
-
let lastPressFrame: number | null = null;
|
|
749
|
-
for (const click of track.clicks) {
|
|
750
|
-
if (click.frame > sourceFrame) break;
|
|
751
|
-
lastPressFrame = click.frame;
|
|
752
|
-
}
|
|
753
|
-
const press = lastPressFrame === null ? 0 : Math.max(0, 1 - (sourceFrame - lastPressFrame) / (0.3 * fps));
|
|
754
|
-
const rippleColor = style === "accent" || style === "spotlight" ? CURSOR_GREEN : "#ffffff";
|
|
755
|
-
|
|
756
|
-
return (
|
|
757
|
-
<div style={{ position: "absolute", inset: 0, pointerEvents: "none" }}>
|
|
758
|
-
{ripples.map((click) => {
|
|
759
|
-
const progress = (sourceFrame - click.frame) / rippleFrames;
|
|
760
|
-
const diameter = size * (0.6 + 2.2 * progress);
|
|
761
|
-
const at = toBox(click.x, click.y);
|
|
762
|
-
return (
|
|
763
|
-
<div
|
|
764
|
-
key={click.frame}
|
|
765
|
-
style={{
|
|
766
|
-
position: "absolute",
|
|
767
|
-
left: at.left - diameter / 2,
|
|
768
|
-
top: at.top - diameter / 2,
|
|
769
|
-
width: diameter,
|
|
770
|
-
height: diameter,
|
|
771
|
-
borderRadius: "50%",
|
|
772
|
-
border: `${Math.max(2, size * 0.09)}px solid ${rippleColor}`,
|
|
773
|
-
boxShadow: "0 0 6px rgba(0,0,0,0.45)",
|
|
774
|
-
boxSizing: "border-box",
|
|
775
|
-
opacity: 0.9 * (1 - progress),
|
|
776
|
-
}}
|
|
777
|
-
/>
|
|
778
|
-
);
|
|
779
|
-
})}
|
|
780
|
-
{point && style === "spotlight" ? (
|
|
781
|
-
<div
|
|
782
|
-
style={{
|
|
783
|
-
position: "absolute",
|
|
784
|
-
left: point.left - size * 0.42,
|
|
785
|
-
top: point.top - size * 0.42,
|
|
786
|
-
width: size * 0.84,
|
|
787
|
-
height: size * 0.84,
|
|
788
|
-
borderRadius: "50%",
|
|
789
|
-
border: `${Math.max(2, size * 0.08)}px solid ${CURSOR_GREEN}`,
|
|
790
|
-
background: "rgba(45, 212, 122, 0.16)",
|
|
791
|
-
boxShadow: "0 1px 4px rgba(0,0,0,0.45)",
|
|
792
|
-
boxSizing: "border-box",
|
|
793
|
-
transform: `scale(${1 - press * 0.15})`,
|
|
794
|
-
}}
|
|
795
|
-
/>
|
|
796
|
-
) : null}
|
|
797
|
-
{point && style === "hand" ? (
|
|
798
|
-
<div
|
|
799
|
-
style={{
|
|
800
|
-
position: "absolute",
|
|
801
|
-
left: point.left - size * 0.42,
|
|
802
|
-
top: point.top - size * 0.16,
|
|
803
|
-
fontSize: size,
|
|
804
|
-
lineHeight: 1,
|
|
805
|
-
textShadow: "0 1px 3px rgba(0,0,0,0.55)",
|
|
806
|
-
transform: `rotate(${press * 9}deg) scale(${1 - press * 0.05})`,
|
|
807
|
-
transformOrigin: "42% 16%",
|
|
808
|
-
}}
|
|
809
|
-
>
|
|
810
|
-
{HAND_EMOJI}
|
|
811
|
-
</div>
|
|
812
|
-
) : null}
|
|
813
|
-
{point && (style === "classic" || style === "accent") ? (
|
|
814
|
-
<svg
|
|
815
|
-
width={size}
|
|
816
|
-
height={size * 1.1}
|
|
817
|
-
viewBox="0 0 24 26.4"
|
|
818
|
-
style={{
|
|
819
|
-
position: "absolute",
|
|
820
|
-
left: point.left - (3.55 / 24) * size,
|
|
821
|
-
top: point.top - (1.75 / 24) * size,
|
|
822
|
-
overflow: "visible",
|
|
823
|
-
transform: `scale(${1 - press * 0.08})`,
|
|
824
|
-
transformOrigin: `${(3.55 / 24) * 100}% ${(1.75 / 26.4) * 100}%`,
|
|
825
|
-
}}
|
|
826
|
-
>
|
|
827
|
-
<defs>
|
|
828
|
-
<filter id="studio-cursor-shadow" x="-50%" y="-50%" width="200%" height="200%">
|
|
829
|
-
<feDropShadow dx="0" dy="1.5" stdDeviation="1.1" floodColor="#000000" floodOpacity="0.65" />
|
|
830
|
-
</filter>
|
|
831
|
-
</defs>
|
|
832
|
-
<path
|
|
833
|
-
d={CURSOR_POINTER_PATH}
|
|
834
|
-
fill={style === "accent" ? CURSOR_GREEN : "#ffffff"}
|
|
835
|
-
stroke="#000000"
|
|
836
|
-
strokeWidth={2.4}
|
|
837
|
-
strokeLinejoin="round"
|
|
838
|
-
filter="url(#studio-cursor-shadow)"
|
|
839
|
-
/>
|
|
840
|
-
</svg>
|
|
841
|
-
) : null}
|
|
842
|
-
</div>
|
|
843
|
-
);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
function TextClipView({ clip: saved, ctx }: { clip: TextClip; ctx: StudioRuntimeContextValue }) {
|
|
847
|
-
const clip = useLive(saved);
|
|
848
|
-
const style = useClipStyle(clip);
|
|
849
|
-
const s = { ...projectStyle(ctx.project.style)?.text, ...clip.style };
|
|
850
|
-
const align = s.align ?? "center";
|
|
851
|
-
return (
|
|
852
|
-
<div
|
|
853
|
-
style={{
|
|
854
|
-
...boxStyle(clip.box ?? { x: 0.05, y: 0.4, width: 0.9, height: 0.2 }),
|
|
855
|
-
...style,
|
|
856
|
-
display: "flex",
|
|
857
|
-
alignItems: "center",
|
|
858
|
-
justifyContent: align === "left" ? "flex-start" : align === "right" ? "flex-end" : "center",
|
|
859
|
-
}}
|
|
860
|
-
>
|
|
861
|
-
<div
|
|
862
|
-
style={{
|
|
863
|
-
fontFamily: s.fontFamily ? `"${s.fontFamily}", sans-serif` : "sans-serif",
|
|
864
|
-
fontSize: s.fontSize ?? Math.round(ctx.height * 0.07),
|
|
865
|
-
fontWeight: s.fontWeight ?? 800,
|
|
866
|
-
color: s.color ?? "#ffffff",
|
|
867
|
-
textAlign: align,
|
|
868
|
-
lineHeight: s.lineHeight ?? 1.1,
|
|
869
|
-
letterSpacing: s.letterSpacing,
|
|
870
|
-
textTransform: s.textTransform,
|
|
871
|
-
textShadow: s.shadow,
|
|
872
|
-
whiteSpace: "pre-wrap",
|
|
873
|
-
width: "100%",
|
|
874
|
-
}}
|
|
875
|
-
>
|
|
876
|
-
{clip.text}
|
|
877
|
-
</div>
|
|
878
|
-
</div>
|
|
879
|
-
);
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
function CaptionsClipView({ clip: saved, ctx }: { clip: CaptionsClip; ctx: StudioRuntimeContextValue }) {
|
|
883
|
-
const clip = useLive(saved);
|
|
884
|
-
const StyledCaptions = styleLayer.StyledCaptions;
|
|
885
|
-
if (ctx.project.style && !clip.style?.preset && StyledCaptions && projectStyle(ctx.project.style)) {
|
|
886
|
-
return (
|
|
887
|
-
<StyledCaptionsClip clip={clip} ctx={ctx}>
|
|
888
|
-
<StyledCaptions
|
|
889
|
-
styleId={ctx.project.style}
|
|
890
|
-
words={clip.words}
|
|
891
|
-
position={clip.style?.position}
|
|
892
|
-
wordsPerLine={clip.style?.maxWordsPerLine}
|
|
893
|
-
fontSize={clip.style?.fontSize}
|
|
894
|
-
/>
|
|
895
|
-
</StyledCaptionsClip>
|
|
896
|
-
);
|
|
897
|
-
}
|
|
898
|
-
return <PlainCaptionsClipView clip={clip} ctx={ctx} />;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
function StyledCaptionsClip({ clip, children }: { clip: CaptionsClip; ctx: StudioRuntimeContextValue; children: ReactNode }) {
|
|
902
|
-
const style = useClipStyle(clip);
|
|
903
|
-
return <AbsoluteFill style={{ ...style, pointerEvents: "none" }}>{children}</AbsoluteFill>;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
function PlainCaptionsClipView({ clip, ctx }: { clip: CaptionsClip; ctx: StudioRuntimeContextValue }) {
|
|
907
|
-
const frame = useCurrentFrame();
|
|
908
|
-
const style = useClipStyle(clip);
|
|
909
|
-
const s = { ...projectStyle(ctx.project.style)?.captions, ...clip.style };
|
|
910
|
-
const perLine = Math.max(1, s.maxWordsPerLine ?? 4);
|
|
911
|
-
const words = clip.words;
|
|
912
|
-
// Group words into lines of N; show the line containing the current (or last spoken) word.
|
|
913
|
-
let current = -1;
|
|
914
|
-
for (let i = 0; i < words.length; i += 1) {
|
|
915
|
-
if (words[i].from <= frame) current = i;
|
|
916
|
-
else break;
|
|
917
|
-
}
|
|
918
|
-
if (current < 0) return null;
|
|
919
|
-
const lineStart = Math.floor(current / perLine) * perLine;
|
|
920
|
-
const line = words.slice(lineStart, lineStart + perLine);
|
|
921
|
-
const lastWord = line[line.length - 1];
|
|
922
|
-
// Hide the line once its last word ended and the next line hasn't started (pause > 12 frames).
|
|
923
|
-
const next = words[lineStart + perLine];
|
|
924
|
-
if (frame > lastWord.to + 12 && (!next || next.from > frame)) return null;
|
|
925
|
-
|
|
926
|
-
const fontSize = s.fontSize ?? Math.round(ctx.height * (ctx.height > ctx.width ? 0.045 : 0.06));
|
|
927
|
-
const top = s.position === "top" ? "8%" : s.position === "center" ? "50%" : undefined;
|
|
928
|
-
const bottom = s.position === "top" || s.position === "center" ? undefined : "10%";
|
|
929
|
-
const preset = s.preset ?? "pop";
|
|
930
|
-
return (
|
|
931
|
-
<AbsoluteFill style={{ ...style, pointerEvents: "none" }}>
|
|
932
|
-
<div
|
|
933
|
-
style={{
|
|
934
|
-
position: "absolute",
|
|
935
|
-
left: "6%",
|
|
936
|
-
right: "6%",
|
|
937
|
-
top,
|
|
938
|
-
bottom,
|
|
939
|
-
transform: s.position === "center" ? "translateY(-50%)" : undefined,
|
|
940
|
-
display: "flex",
|
|
941
|
-
flexWrap: "wrap",
|
|
942
|
-
justifyContent: "center",
|
|
943
|
-
gap: `0 ${Math.round(fontSize * 0.28)}px`,
|
|
944
|
-
fontFamily: s.fontFamily ? `"${s.fontFamily}", sans-serif` : "sans-serif",
|
|
945
|
-
fontWeight: s.fontWeight ?? 900,
|
|
946
|
-
fontSize,
|
|
947
|
-
lineHeight: 1.15,
|
|
948
|
-
textAlign: "center",
|
|
949
|
-
}}
|
|
950
|
-
>
|
|
951
|
-
{line.map((word, i) => {
|
|
952
|
-
const index = lineStart + i;
|
|
953
|
-
const active = index === current && frame <= word.to + 2;
|
|
954
|
-
const spoken = index <= current;
|
|
955
|
-
let scale = 1;
|
|
956
|
-
if (preset === "pop" && index === current) {
|
|
957
|
-
scale = interpolate(frame, [word.from, word.from + 4, word.from + 8], [0.85, 1.12, 1], clamp);
|
|
958
|
-
}
|
|
959
|
-
const color =
|
|
960
|
-
preset === "plain"
|
|
961
|
-
? (s.color ?? "#fff")
|
|
962
|
-
: active || (preset === "karaoke" && spoken)
|
|
963
|
-
? (s.highlight ?? "#facc15")
|
|
964
|
-
: (s.color ?? "#fff");
|
|
965
|
-
return (
|
|
966
|
-
<span
|
|
967
|
-
key={`${index}-${word.text}`}
|
|
968
|
-
style={{
|
|
969
|
-
display: "inline-block",
|
|
970
|
-
color,
|
|
971
|
-
opacity: preset === "pop" && !spoken ? 0 : 1,
|
|
972
|
-
transform: `scale(${scale})`,
|
|
973
|
-
textShadow: "0 4px 18px rgba(0,0,0,0.55)",
|
|
974
|
-
}}
|
|
975
|
-
>
|
|
976
|
-
{word.text}
|
|
977
|
-
</span>
|
|
978
|
-
);
|
|
979
|
-
})}
|
|
980
|
-
</div>
|
|
981
|
-
</AbsoluteFill>
|
|
982
|
-
);
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
function AudioClipView({ clip: saved, trackMuted, gain }: { clip: AudioClip; trackMuted: boolean; gain: number }) {
|
|
986
|
-
const clip = useLive(saved);
|
|
987
|
-
const base = (clip.volume ?? 1) * gain;
|
|
988
|
-
const fadeIn = Math.max(0, clip.fadeIn ?? 0);
|
|
989
|
-
const fadeOut = Math.max(0, clip.fadeOut ?? 0);
|
|
990
|
-
const duration = clip.duration;
|
|
991
|
-
return (
|
|
992
|
-
<Audio
|
|
993
|
-
src={asset(clip.src)}
|
|
994
|
-
trimBefore={clip.trimStart && clip.trimStart > 0 ? clip.trimStart : undefined}
|
|
995
|
-
muted={trackMuted}
|
|
996
|
-
loop={clip.loop}
|
|
997
|
-
playbackRate={clip.playbackRate}
|
|
998
|
-
volume={
|
|
999
|
-
fadeIn || fadeOut
|
|
1000
|
-
? (f: number) => {
|
|
1001
|
-
const a = fadeIn ? interpolate(f, [0, fadeIn], [0, 1], clamp) : 1;
|
|
1002
|
-
const b = fadeOut ? interpolate(f, [duration - fadeOut, duration], [1, 0], clamp) : 1;
|
|
1003
|
-
return base * a * b;
|
|
1004
|
-
}
|
|
1005
|
-
: base
|
|
1006
|
-
}
|
|
1007
|
-
/>
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
const PREMOUNT_SECONDS = 1;
|
|
1012
|
-
|
|
1013
|
-
/** Keep in sync with `clipClass` in lib/studio/preview-perf.ts. */
|
|
1014
|
-
function clipClass(id: string) {
|
|
1015
|
-
return `ac-clip--${id.replace(/\s+/g, "_")}`;
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
function TrackView({
|
|
1019
|
-
track,
|
|
1020
|
-
scenes,
|
|
1021
|
-
ctx,
|
|
1022
|
-
masterGain,
|
|
1023
|
-
order,
|
|
1024
|
-
}: {
|
|
1025
|
-
track: StudioTrack;
|
|
1026
|
-
scenes: SceneRegistry;
|
|
1027
|
-
ctx: Omit<TrackContext, "order">;
|
|
1028
|
-
masterGain: number;
|
|
1029
|
-
order: number;
|
|
1030
|
-
}) {
|
|
1031
|
-
const visual = track.kind !== "audio";
|
|
1032
|
-
const { isRendering } = useRemotionEnvironment();
|
|
1033
|
-
const trackCtx = useMemo<TrackContext>(() => ({ ...ctx, order }), [ctx, order]);
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
{
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
//
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
{
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
//
|
|
1112
|
-
//
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
document.
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
};
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
)
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
{project.style &&
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1
|
+
// StudioComposition: draws a project's layers.json with Remotion.
|
|
2
|
+
// Tracks are drawn bottom → top (tracks[0] is the top layer) so stacking never
|
|
3
|
+
// depends on z-index, which the browser export ignores.
|
|
4
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType, type CSSProperties, type ReactNode } from "react";
|
|
5
|
+
import {
|
|
6
|
+
AbsoluteFill,
|
|
7
|
+
Img,
|
|
8
|
+
Internals,
|
|
9
|
+
Sequence,
|
|
10
|
+
continueRender,
|
|
11
|
+
delayRender,
|
|
12
|
+
interpolate,
|
|
13
|
+
useCurrentFrame,
|
|
14
|
+
useRemotionEnvironment,
|
|
15
|
+
useVideoConfig,
|
|
16
|
+
} from "remotion";
|
|
17
|
+
import { Audio, Video } from "@remotion/media";
|
|
18
|
+
import type { EffectDescriptor } from "remotion";
|
|
19
|
+
import { framingCropAt } from "./framing";
|
|
20
|
+
// The Agentcut component library, provided by the studio page (and by a copy in
|
|
21
|
+
// .agentcut/components for local renders).
|
|
22
|
+
import * as ComponentLibrary from "agentcut/components";
|
|
23
|
+
import { MOTION_COMPONENTS, resolveComponentProps } from "agentcut/components";
|
|
24
|
+
|
|
25
|
+
// Project styles (project.json "style") come from the library too. Pages from before styles don't
|
|
26
|
+
// provide them: the project then renders as if it had none.
|
|
27
|
+
type LibraryStyle = { captions: CaptionsClip["style"]; text: TextClip["style"] };
|
|
28
|
+
function projectStyle(id: string | undefined): LibraryStyle | null {
|
|
29
|
+
const get = (ComponentLibrary as { getMotionStyle?: (id?: string) => LibraryStyle | null }).getMotionStyle;
|
|
30
|
+
return id && typeof get === "function" ? get(id) : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type StyleLayer = {
|
|
34
|
+
styleCamera?: (
|
|
35
|
+
id: string | undefined,
|
|
36
|
+
at: { frame: number; durationInFrames: number; width: number; height: number },
|
|
37
|
+
) => CSSProperties | null;
|
|
38
|
+
StyleOverlay?: ComponentType<{ styleId: string | undefined }>;
|
|
39
|
+
StyledCaptions?: ComponentType<{
|
|
40
|
+
styleId: string | undefined;
|
|
41
|
+
words: CaptionsClip["words"];
|
|
42
|
+
position?: string;
|
|
43
|
+
wordsPerLine?: number;
|
|
44
|
+
fontSize?: number;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
const styleLayer = ComponentLibrary as StyleLayer;
|
|
48
|
+
|
|
49
|
+
/** Loads the library's fonts (the style's caption and text fonts) and holds the render until they're in. */
|
|
50
|
+
function StyleFonts() {
|
|
51
|
+
const use = (ComponentLibrary as { useMotionFonts?: () => void }).useMotionFonts;
|
|
52
|
+
use?.();
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
import {
|
|
56
|
+
StudioRuntimeContext,
|
|
57
|
+
asset,
|
|
58
|
+
clamp,
|
|
59
|
+
setRuntimeState,
|
|
60
|
+
type StudioRuntimeContextValue,
|
|
61
|
+
} from "./helpers";
|
|
62
|
+
import type {
|
|
63
|
+
AudioClip,
|
|
64
|
+
AdjustmentClip,
|
|
65
|
+
Box,
|
|
66
|
+
CaptionsClip,
|
|
67
|
+
ClipAnim,
|
|
68
|
+
ColorGrade,
|
|
69
|
+
ImageClip,
|
|
70
|
+
SceneClip,
|
|
71
|
+
SceneProps,
|
|
72
|
+
StudioClip,
|
|
73
|
+
StudioCompositionProps,
|
|
74
|
+
StudioFont,
|
|
75
|
+
StudioTrack,
|
|
76
|
+
TextClip,
|
|
77
|
+
CursorTrack,
|
|
78
|
+
VideoClip,
|
|
79
|
+
VideoCursor,
|
|
80
|
+
} from "./types";
|
|
81
|
+
|
|
82
|
+
export type SceneRegistry = Record<string, ComponentType<SceneProps & Record<string, unknown>>>;
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Fonts
|
|
86
|
+
|
|
87
|
+
const loadedFontSpecs = new Map<string, Promise<void>>();
|
|
88
|
+
|
|
89
|
+
function fontSpecToCss(spec: string) {
|
|
90
|
+
// "Inter:400;700;900" → family=Inter:wght@400;700;900 ; "Inter" → family=Inter
|
|
91
|
+
const [family, weights] = spec.split(":");
|
|
92
|
+
const name = family.trim().replace(/\s+/g, "+");
|
|
93
|
+
return weights ? `family=${name}:wght@${weights.trim()}` : `family=${name}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function loadLocalFont(font: Exclude<StudioFont, string>): Promise<void> {
|
|
97
|
+
const key = `${font.family}|${font.src}|${font.weight ?? ""}|${font.style ?? ""}`;
|
|
98
|
+
const existing = loadedFontSpecs.get(key);
|
|
99
|
+
if (existing) return existing;
|
|
100
|
+
const promise = (async () => {
|
|
101
|
+
if (typeof document === "undefined") return;
|
|
102
|
+
const face = new FontFace(font.family, `url(${JSON.stringify(asset(font.src))})`, {
|
|
103
|
+
weight: font.weight ?? "400",
|
|
104
|
+
style: font.style ?? "normal",
|
|
105
|
+
});
|
|
106
|
+
try {
|
|
107
|
+
document.fonts.add(await face.load());
|
|
108
|
+
} catch {
|
|
109
|
+
// Missing font file: keep rendering with the fallback font.
|
|
110
|
+
}
|
|
111
|
+
})();
|
|
112
|
+
loadedFontSpecs.set(key, promise);
|
|
113
|
+
return promise;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function loadFont(font: StudioFont): Promise<void> {
|
|
117
|
+
return typeof font === "string" ? loadFontSpec(font) : loadLocalFont(font);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function loadFontSpec(spec: string): Promise<void> {
|
|
121
|
+
const existing = loadedFontSpecs.get(spec);
|
|
122
|
+
if (existing) return existing;
|
|
123
|
+
const promise = (async () => {
|
|
124
|
+
if (typeof document === "undefined") return;
|
|
125
|
+
const href = `https://fonts.googleapis.com/css2?${fontSpecToCss(spec)}&display=block`;
|
|
126
|
+
if (!document.querySelector(`link[data-studio-font="${CSS.escape(spec)}"]`)) {
|
|
127
|
+
const link = document.createElement("link");
|
|
128
|
+
link.rel = "stylesheet";
|
|
129
|
+
link.href = href;
|
|
130
|
+
link.crossOrigin = "anonymous";
|
|
131
|
+
link.dataset.studioFont = spec;
|
|
132
|
+
await new Promise<void>((resolve) => {
|
|
133
|
+
link.onload = () => resolve();
|
|
134
|
+
link.onerror = () => resolve();
|
|
135
|
+
document.head.appendChild(link);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const [family, weights] = spec.split(":");
|
|
139
|
+
const list = weights ? weights.split(";").map((w) => w.trim()) : ["400"];
|
|
140
|
+
await Promise.all(
|
|
141
|
+
list.map((weight) =>
|
|
142
|
+
document.fonts.load(`${weight} 32px "${family.trim()}"`).catch(() => undefined),
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
})();
|
|
146
|
+
loadedFontSpecs.set(spec, promise);
|
|
147
|
+
return promise;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function useProjectFonts(fonts: StudioFont[]) {
|
|
151
|
+
const key = fonts.map((font) => (typeof font === "string" ? font : `${font.family}|${font.src}|${font.weight ?? ""}`)).join("||");
|
|
152
|
+
const [handle] = useState(() =>
|
|
153
|
+
fonts.length > 0 ? delayRender(`Loading fonts ${key}`, { timeoutInMilliseconds: 20_000 }) : null,
|
|
154
|
+
);
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (handle === null) return;
|
|
157
|
+
let cancelled = false;
|
|
158
|
+
Promise.all(fonts.map(loadFont)).finally(() => {
|
|
159
|
+
if (!cancelled) continueRender(handle);
|
|
160
|
+
});
|
|
161
|
+
return () => {
|
|
162
|
+
cancelled = true;
|
|
163
|
+
};
|
|
164
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
165
|
+
}, [handle, key]);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// Clip helpers
|
|
170
|
+
|
|
171
|
+
export function resolveClip<T extends StudioClip>(clip: T, variant: string): T {
|
|
172
|
+
const override = (clip as { variants?: Record<string, Partial<T>> }).variants?.[variant];
|
|
173
|
+
return override ? ({ ...clip, ...override } as T) : clip;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function animState(anim: ClipAnim | undefined, t: number) {
|
|
177
|
+
// t: 0 = fully hidden, 1 = fully shown
|
|
178
|
+
const preset = anim?.preset ?? "none";
|
|
179
|
+
const out: { opacity: number; transform: string; filter?: string } = { opacity: 1, transform: "" };
|
|
180
|
+
if (preset === "none" || t >= 1) return out;
|
|
181
|
+
const inv = 1 - t;
|
|
182
|
+
switch (preset) {
|
|
183
|
+
case "fade":
|
|
184
|
+
out.opacity = t;
|
|
185
|
+
break;
|
|
186
|
+
case "slide-up":
|
|
187
|
+
out.opacity = t;
|
|
188
|
+
out.transform = `translateY(${inv * 8}%)`;
|
|
189
|
+
break;
|
|
190
|
+
case "slide-down":
|
|
191
|
+
out.opacity = t;
|
|
192
|
+
out.transform = `translateY(${-inv * 8}%)`;
|
|
193
|
+
break;
|
|
194
|
+
case "slide-left":
|
|
195
|
+
out.opacity = t;
|
|
196
|
+
out.transform = `translateX(${inv * 8}%)`;
|
|
197
|
+
break;
|
|
198
|
+
case "slide-right":
|
|
199
|
+
out.opacity = t;
|
|
200
|
+
out.transform = `translateX(${-inv * 8}%)`;
|
|
201
|
+
break;
|
|
202
|
+
case "pop": {
|
|
203
|
+
// overshoot: 0 → 1.08 → 1
|
|
204
|
+
const s = t < 0.7 ? interpolate(t, [0, 0.7], [0.6, 1.08]) : interpolate(t, [0.7, 1], [1.08, 1]);
|
|
205
|
+
out.opacity = Math.min(1, t * 2);
|
|
206
|
+
out.transform = `scale(${s})`;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case "scale":
|
|
210
|
+
out.opacity = t;
|
|
211
|
+
out.transform = `scale(${0.85 + 0.15 * t})`;
|
|
212
|
+
break;
|
|
213
|
+
case "blur":
|
|
214
|
+
out.opacity = t;
|
|
215
|
+
out.filter = `blur(${inv * 16}px)`;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const easeOutCubic = (t: number) => 1 - Math.pow(1 - t, 3);
|
|
222
|
+
|
|
223
|
+
/** Enter/exit + opacity wrapper for one visual clip; frame is local to the clip. */
|
|
224
|
+
function useClipStyle(clip: StudioClip): CSSProperties {
|
|
225
|
+
const frame = useCurrentFrame();
|
|
226
|
+
const enterFrames = clip.enter && clip.enter.preset !== "none" ? Math.max(1, clip.enter.frames) : 0;
|
|
227
|
+
const exitFrames = clip.exit && clip.exit.preset !== "none" ? Math.max(1, clip.exit.frames) : 0;
|
|
228
|
+
const tIn = enterFrames ? easeOutCubic(interpolate(frame, [0, enterFrames], [0, 1], clamp)) : 1;
|
|
229
|
+
const tOut = exitFrames
|
|
230
|
+
? easeOutCubic(interpolate(frame, [clip.duration - exitFrames, clip.duration], [1, 0], clamp))
|
|
231
|
+
: 1;
|
|
232
|
+
const a = animState(clip.enter, tIn);
|
|
233
|
+
const b = animState(clip.exit, tOut);
|
|
234
|
+
const transform = [a.transform, b.transform].filter(Boolean).join(" ");
|
|
235
|
+
const filter = [a.filter, b.filter].filter(Boolean).join(" ");
|
|
236
|
+
return {
|
|
237
|
+
opacity: a.opacity * b.opacity * (clip.opacity ?? 1),
|
|
238
|
+
transform: transform || undefined,
|
|
239
|
+
filter: filter || undefined,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function boxStyle(box: Box | undefined): CSSProperties {
|
|
244
|
+
if (!box) return { position: "absolute", left: 0, top: 0, width: "100%", height: "100%" };
|
|
245
|
+
return {
|
|
246
|
+
position: "absolute",
|
|
247
|
+
left: `${box.x * 100}%`,
|
|
248
|
+
top: `${box.y * 100}%`,
|
|
249
|
+
width: `${box.width * 100}%`,
|
|
250
|
+
height: `${box.height * 100}%`,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
// Clip renderers (all frames local to the clip's <Sequence>)
|
|
256
|
+
|
|
257
|
+
function SceneClipView({
|
|
258
|
+
clip: saved,
|
|
259
|
+
scenes,
|
|
260
|
+
ctx,
|
|
261
|
+
}: {
|
|
262
|
+
clip: SceneClip;
|
|
263
|
+
scenes: SceneRegistry;
|
|
264
|
+
ctx: StudioRuntimeContextValue;
|
|
265
|
+
}) {
|
|
266
|
+
const clip = useLive(saved);
|
|
267
|
+
const style = useClipStyle(clip);
|
|
268
|
+
if (clip.component) {
|
|
269
|
+
const entry = MOTION_COMPONENTS[clip.component];
|
|
270
|
+
if (!entry) {
|
|
271
|
+
return (
|
|
272
|
+
<AbsoluteFill
|
|
273
|
+
style={{
|
|
274
|
+
alignItems: "center",
|
|
275
|
+
justifyContent: "center",
|
|
276
|
+
background: "rgba(220,38,38,0.25)",
|
|
277
|
+
color: "#fff",
|
|
278
|
+
fontFamily: "sans-serif",
|
|
279
|
+
fontSize: Math.round(ctx.height * 0.03),
|
|
280
|
+
}}
|
|
281
|
+
>
|
|
282
|
+
Unknown component “{clip.component}”
|
|
283
|
+
</AbsoluteFill>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const Component = entry.Component;
|
|
287
|
+
return (
|
|
288
|
+
<AbsoluteFill style={style}>
|
|
289
|
+
<Component
|
|
290
|
+
{...resolveComponentProps(clip.component, clip.props, ctx.project.style)}
|
|
291
|
+
width={ctx.width}
|
|
292
|
+
height={ctx.height}
|
|
293
|
+
fps={ctx.fps}
|
|
294
|
+
durationInFrames={clip.duration}
|
|
295
|
+
variant={ctx.variant}
|
|
296
|
+
/>
|
|
297
|
+
</AbsoluteFill>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
const Scene = clip.scene ? scenes[clip.scene] : undefined;
|
|
301
|
+
if (!Scene) {
|
|
302
|
+
return (
|
|
303
|
+
<AbsoluteFill
|
|
304
|
+
style={{
|
|
305
|
+
alignItems: "center",
|
|
306
|
+
justifyContent: "center",
|
|
307
|
+
background: "rgba(220,38,38,0.25)",
|
|
308
|
+
color: "#fff",
|
|
309
|
+
fontFamily: "sans-serif",
|
|
310
|
+
fontSize: Math.round(ctx.height * 0.03),
|
|
311
|
+
}}
|
|
312
|
+
>
|
|
313
|
+
Missing scene “{clip.scene}” (scenes/{clip.scene}.tsx)
|
|
314
|
+
</AbsoluteFill>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
return (
|
|
318
|
+
<AbsoluteFill style={style}>
|
|
319
|
+
<Scene
|
|
320
|
+
{...(clip.props ?? {})}
|
|
321
|
+
clip={{ id: clip.id, from: clip.from, duration: clip.duration }}
|
|
322
|
+
variant={ctx.variant}
|
|
323
|
+
width={ctx.width}
|
|
324
|
+
height={ctx.height}
|
|
325
|
+
fps={ctx.fps}
|
|
326
|
+
/>
|
|
327
|
+
</AbsoluteFill>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function ImageClipView({ clip: saved, ctx }: { clip: ImageClip; ctx: TrackContext }) {
|
|
332
|
+
const clip = useLive(saved);
|
|
333
|
+
const style = useClipStyle(clip);
|
|
334
|
+
const { filter, effects } = useClipGrade(clip, ctx, clip.inheritGrade === true);
|
|
335
|
+
return (
|
|
336
|
+
<div style={{ ...boxStyle(clip.box), ...style, overflow: "hidden", borderRadius: clip.radius }}>
|
|
337
|
+
{effects.length ? (
|
|
338
|
+
// Effects draw images on a canvas, which needs its size in pixels.
|
|
339
|
+
<Img
|
|
340
|
+
src={asset(clip.src)}
|
|
341
|
+
width={Math.max(1, Math.round((clip.box?.width ?? 1) * ctx.width))}
|
|
342
|
+
height={Math.max(1, Math.round((clip.box?.height ?? 1) * ctx.height))}
|
|
343
|
+
effects={effects}
|
|
344
|
+
style={{ width: "100%", height: "100%", display: "block", objectFit: clip.fit ?? "cover" }}
|
|
345
|
+
/>
|
|
346
|
+
) : (
|
|
347
|
+
<Img
|
|
348
|
+
src={asset(clip.src)}
|
|
349
|
+
style={{ width: "100%", height: "100%", objectFit: clip.fit ?? "cover", display: "block", filter }}
|
|
350
|
+
/>
|
|
351
|
+
)}
|
|
352
|
+
</div>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** The runtime context plus what a clip needs to know about the stack it sits in. */
|
|
357
|
+
type TrackContext = StudioRuntimeContextValue & {
|
|
358
|
+
adjustments: { clip: AdjustmentClip; order: number }[];
|
|
359
|
+
/** Position in the stack, bottom to top. */
|
|
360
|
+
order: number;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// The grade engine comes from the library too. Pages from before it don't provide it: those keep the
|
|
364
|
+
// CSS filter below, which covers the original controls.
|
|
365
|
+
const LIVE_PROJECT = "project";
|
|
366
|
+
type GradeEntry = { grade: ColorGrade; frame: number; strength?: number };
|
|
367
|
+
type GradeEngine = {
|
|
368
|
+
gradeEffects?: (grades: GradeEntry[], options: { seed: number; luts?: ReadonlyMap<string, unknown> }) => EffectDescriptor<unknown>[];
|
|
369
|
+
gradeLutPaths?: (grade: ColorGrade | undefined) => string[];
|
|
370
|
+
isCssGrade?: (grade: ColorGrade | undefined) => boolean;
|
|
371
|
+
canDrawGrade?: () => boolean;
|
|
372
|
+
parseCube?: (text: string) => unknown;
|
|
373
|
+
};
|
|
374
|
+
const gradeEngine = ComponentLibrary as GradeEngine;
|
|
375
|
+
|
|
376
|
+
// A moving slider's value, straight from the inspector. Older pages don't provide it.
|
|
377
|
+
type LiveEdits = {
|
|
378
|
+
useLiveClip?: <T extends { id: string }>(clip: T, isRendering?: boolean) => T;
|
|
379
|
+
useLiveClips?: (ids: string[], isRendering?: boolean) => void;
|
|
380
|
+
getLiveClip?: (id: string) => Record<string, unknown> | undefined;
|
|
381
|
+
};
|
|
382
|
+
const liveEdits = ComponentLibrary as LiveEdits;
|
|
383
|
+
const useLiveClipEngine = liveEdits.useLiveClip;
|
|
384
|
+
const useLiveClipsEngine = liveEdits.useLiveClips;
|
|
385
|
+
|
|
386
|
+
function useLive<T extends { id: string }>(clip: T): T {
|
|
387
|
+
const { isRendering } = useRemotionEnvironment();
|
|
388
|
+
// The library is fixed for the page's lifetime, so this always calls the same hooks.
|
|
389
|
+
return useLiveClipEngine ? useLiveClipEngine(clip, isRendering) : clip;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const loadedLuts = new Map<string, unknown>();
|
|
393
|
+
const pendingLuts = new Map<string, Promise<void>>();
|
|
394
|
+
|
|
395
|
+
/** Load a .cube file once. A missing or broken file warns and the grade draws without it. */
|
|
396
|
+
function loadLut(path: string) {
|
|
397
|
+
let pending = pendingLuts.get(path);
|
|
398
|
+
if (!pending) {
|
|
399
|
+
pending = fetch(asset(path))
|
|
400
|
+
.then((response) => {
|
|
401
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
402
|
+
return response.text();
|
|
403
|
+
})
|
|
404
|
+
.then((text) => {
|
|
405
|
+
loadedLuts.set(path, gradeEngine.parseCube?.(text) ?? null);
|
|
406
|
+
})
|
|
407
|
+
.catch((error) => {
|
|
408
|
+
loadedLuts.set(path, null);
|
|
409
|
+
console.warn(`Could not load the LUT ${path}: ${error instanceof Error ? error.message : error}`);
|
|
410
|
+
});
|
|
411
|
+
pendingLuts.set(path, pending);
|
|
412
|
+
}
|
|
413
|
+
return pending;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Holds the render until these .cube files have loaded; later additions (preview edits) just redraw. */
|
|
417
|
+
function useGradeLuts(paths: string[]) {
|
|
418
|
+
const key = paths.join("\n");
|
|
419
|
+
const [, setLoaded] = useState(0);
|
|
420
|
+
const [handle] = useState(() =>
|
|
421
|
+
paths.some((path) => !loadedLuts.has(path)) ? delayRender(`Loading LUT ${paths.join(", ")}`, { timeoutInMilliseconds: 20_000 }) : null,
|
|
422
|
+
);
|
|
423
|
+
useEffect(() => {
|
|
424
|
+
let cancelled = false;
|
|
425
|
+
const wanted = key ? key.split("\n") : [];
|
|
426
|
+
Promise.all(wanted.map(loadLut))
|
|
427
|
+
.then(() => {
|
|
428
|
+
if (!cancelled) setLoaded((n) => n + 1);
|
|
429
|
+
})
|
|
430
|
+
.finally(() => {
|
|
431
|
+
if (handle !== null) continueRender(handle);
|
|
432
|
+
});
|
|
433
|
+
return () => {
|
|
434
|
+
cancelled = true;
|
|
435
|
+
};
|
|
436
|
+
}, [key, handle]);
|
|
437
|
+
return loadedLuts;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** How far an adjustment clip is faded in at `local`: its enter and exit lengths ramp the grade. */
|
|
441
|
+
function adjustmentStrength(clip: AdjustmentClip, local: number) {
|
|
442
|
+
let strength = clip.opacity ?? 1;
|
|
443
|
+
if (clip.enter?.frames) strength *= Math.min(1, (local + 1) / clip.enter.frames);
|
|
444
|
+
if (clip.exit?.frames) strength *= Math.min(1, (clip.duration - local) / clip.exit.frames);
|
|
445
|
+
return strength;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* What draws a clip's colour: its own grade, then the adjustment layers above it and the project
|
|
450
|
+
* grade. A lone clip grade using only the original controls stays a CSS filter, so existing projects
|
|
451
|
+
* render exactly as they did.
|
|
452
|
+
*/
|
|
453
|
+
function useClipGrade(clip: VideoClip | ImageClip, ctx: TrackContext, inherits: boolean) {
|
|
454
|
+
const local = useCurrentFrame();
|
|
455
|
+
const frame = local + clip.from;
|
|
456
|
+
const { isRendering } = useRemotionEnvironment();
|
|
457
|
+
const liveIds = inherits ? [...ctx.adjustments.map((layer) => layer.clip.id), LIVE_PROJECT] : [];
|
|
458
|
+
useLiveClipsEngine?.(liveIds, isRendering);
|
|
459
|
+
const liveGrade = (id: string, saved: ColorGrade | undefined) => {
|
|
460
|
+
const fields = isRendering ? undefined : liveEdits.getLiveClip?.(id);
|
|
461
|
+
return fields && "grade" in fields ? (fields.grade as ColorGrade | undefined) : saved;
|
|
462
|
+
};
|
|
463
|
+
const grades: GradeEntry[] = [];
|
|
464
|
+
if (clip.grade) grades.push({ grade: clip.grade, frame: local });
|
|
465
|
+
const inherited: GradeEntry[] = [];
|
|
466
|
+
if (inherits) {
|
|
467
|
+
for (const layer of ctx.adjustments) {
|
|
468
|
+
if (layer.order <= ctx.order) continue;
|
|
469
|
+
const at = frame - layer.clip.from;
|
|
470
|
+
if (at < 0 || at >= layer.clip.duration) continue;
|
|
471
|
+
const grade = liveGrade(layer.clip.id, layer.clip.grade);
|
|
472
|
+
if (grade) inherited.push({ grade, frame: at, strength: adjustmentStrength(layer.clip, at) });
|
|
473
|
+
}
|
|
474
|
+
const projectGrade = liveGrade(LIVE_PROJECT, ctx.project.grade);
|
|
475
|
+
if (projectGrade) inherited.push({ grade: projectGrade, frame });
|
|
476
|
+
}
|
|
477
|
+
const paths = [...new Set([...grades, ...inherited].flatMap((entry) => gradeEngine.gradeLutPaths?.(entry.grade) ?? []))];
|
|
478
|
+
const luts = useGradeLuts(paths);
|
|
479
|
+
const useCss =
|
|
480
|
+
!gradeEngine.gradeEffects ||
|
|
481
|
+
!gradeEngine.canDrawGrade?.() ||
|
|
482
|
+
(inherited.length === 0 && (grades.length === 0 || gradeEngine.isCssGrade?.(grades[0].grade)));
|
|
483
|
+
if (useCss) return { filter: gradeFilter(clip.grade), effects: [] as EffectDescriptor<unknown>[] };
|
|
484
|
+
return {
|
|
485
|
+
filter: undefined,
|
|
486
|
+
effects: gradeEngine.gradeEffects!([...grades, ...inherited], { seed: frame, luts: luts as ReadonlyMap<string, unknown> }),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** CSS filter for a color grade (supported by the browser export). */
|
|
491
|
+
function gradeFilter(grade: VideoClip["grade"]): string | undefined {
|
|
492
|
+
if (!grade) return undefined;
|
|
493
|
+
const parts: string[] = [];
|
|
494
|
+
if (grade.brightness !== undefined && grade.brightness !== 1) parts.push(`brightness(${grade.brightness})`);
|
|
495
|
+
if (grade.contrast !== undefined && grade.contrast !== 1) parts.push(`contrast(${grade.contrast})`);
|
|
496
|
+
if (grade.saturation !== undefined && grade.saturation !== 1) parts.push(`saturate(${grade.saturation})`);
|
|
497
|
+
const warmth = grade.warmth ?? 0;
|
|
498
|
+
if (warmth > 0) parts.push(`sepia(${(warmth * 0.35).toFixed(3)})`, `saturate(${(1 + warmth * 0.25).toFixed(3)})`);
|
|
499
|
+
const hue = (grade.hue ?? 0) + (warmth < 0 ? warmth * -12 : warmth * -4);
|
|
500
|
+
if (hue) parts.push(`hue-rotate(${hue.toFixed(1)}deg)`);
|
|
501
|
+
return parts.length ? parts.join(" ") : undefined;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// Frames this preview drew while paused, small and already graded. Coming back to one during a drag
|
|
505
|
+
// (the usual back-and-forth when looking for a cut) puts it on screen at once, over the player, until
|
|
506
|
+
// the decoder has redrawn it. Preview only; a wrong guess lasts only until that redraw.
|
|
507
|
+
const HELD_FRAME_WIDTH = 960;
|
|
508
|
+
/** About 200 MB at 16:9, across every clip. */
|
|
509
|
+
const MAX_HELD_FRAMES = 96;
|
|
510
|
+
const heldFrames = new Map<string, ImageBitmap>();
|
|
511
|
+
|
|
512
|
+
function holdFrame(key: string, frame: ImageBitmap) {
|
|
513
|
+
heldFrames.get(key)?.close();
|
|
514
|
+
heldFrames.delete(key);
|
|
515
|
+
heldFrames.set(key, frame);
|
|
516
|
+
if (heldFrames.size > MAX_HELD_FRAMES) {
|
|
517
|
+
const oldest = heldFrames.keys().next().value!;
|
|
518
|
+
heldFrames.get(oldest)?.close();
|
|
519
|
+
heldFrames.delete(oldest);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function useHeldFrames(version: string, frame: number, enabled: boolean) {
|
|
524
|
+
const boxRef = useRef<HTMLDivElement>(null);
|
|
525
|
+
const overlayRef = useRef<HTMLCanvasElement>(null);
|
|
526
|
+
const latest = useRef({ version, frame, enabled });
|
|
527
|
+
/** The frame the decoder's picture shows: nothing needs to cover it. */
|
|
528
|
+
const drawn = useRef<number | null>(null);
|
|
529
|
+
useLayoutEffect(() => {
|
|
530
|
+
latest.current = { version, frame, enabled };
|
|
531
|
+
const overlay = overlayRef.current;
|
|
532
|
+
if (!overlay) return;
|
|
533
|
+
if (!enabled || drawn.current === frame) {
|
|
534
|
+
overlay.style.visibility = "hidden";
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
const picture = heldFrames.get(`${version}:${frame}`);
|
|
538
|
+
if (!picture) return;
|
|
539
|
+
if (overlay.width !== picture.width) overlay.width = picture.width;
|
|
540
|
+
if (overlay.height !== picture.height) overlay.height = picture.height;
|
|
541
|
+
overlay.getContext("2d")?.drawImage(picture, 0, 0);
|
|
542
|
+
overlay.style.visibility = "visible";
|
|
543
|
+
}, [version, frame, enabled]);
|
|
544
|
+
const onDrawn = useCallback(() => {
|
|
545
|
+
const now = latest.current;
|
|
546
|
+
drawn.current = now.frame;
|
|
547
|
+
const overlay = overlayRef.current;
|
|
548
|
+
if (overlay) overlay.style.visibility = "hidden";
|
|
549
|
+
if (!now.enabled) return;
|
|
550
|
+
// The player's own canvas, which has the grade on it (the callback's frame doesn't yet).
|
|
551
|
+
const canvas = boxRef.current?.querySelector<HTMLCanvasElement>("canvas");
|
|
552
|
+
if (!canvas || canvas === overlay || !canvas.width || !canvas.height) return;
|
|
553
|
+
const width = Math.min(HELD_FRAME_WIDTH, canvas.width);
|
|
554
|
+
const key = `${now.version}:${now.frame}`;
|
|
555
|
+
void createImageBitmap(canvas, {
|
|
556
|
+
resizeWidth: width,
|
|
557
|
+
resizeHeight: Math.max(1, Math.round((canvas.height * width) / canvas.width)),
|
|
558
|
+
resizeQuality: "low",
|
|
559
|
+
}).then((picture) => holdFrame(key, picture), () => undefined);
|
|
560
|
+
}, []);
|
|
561
|
+
return { boxRef, overlayRef, onDrawn };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function VideoClipView({
|
|
565
|
+
clip: saved,
|
|
566
|
+
trackMuted,
|
|
567
|
+
gain,
|
|
568
|
+
ctx,
|
|
569
|
+
}: {
|
|
570
|
+
clip: VideoClip;
|
|
571
|
+
trackMuted: boolean;
|
|
572
|
+
gain: number;
|
|
573
|
+
ctx: TrackContext;
|
|
574
|
+
}) {
|
|
575
|
+
const clip = useLive(saved);
|
|
576
|
+
const style = useClipStyle(clip);
|
|
577
|
+
const frame = useCurrentFrame();
|
|
578
|
+
const grade = useClipGrade(clip, ctx, clip.inheritGrade !== false);
|
|
579
|
+
const { isRendering } = useRemotionEnvironment();
|
|
580
|
+
const playing = Internals.Timeline.usePlaying();
|
|
581
|
+
const source = (!isRendering && ctx.previewProxies?.[clip.src]) || asset(clip.src);
|
|
582
|
+
const held = useHeldFrames(
|
|
583
|
+
`${clip.id}|${source}|${clip.trimStart ?? 0}|${clip.playbackRate ?? 1}|${clip.fit ?? ""}|${grade.filter ?? ""}|${JSON.stringify(clip.grade ?? null)}|${JSON.stringify(ctx.project.grade ?? null)}|${ctx.adjustments.length}`,
|
|
584
|
+
frame,
|
|
585
|
+
!isRendering && !playing,
|
|
586
|
+
);
|
|
587
|
+
// The project style's camera (punch-ins, drift, …) moves the footage inside its box.
|
|
588
|
+
const crop = clip.framing ? framingCropAt(clip.framing, (clip.trimStart ?? 0) / ctx.project.fps + frame / ctx.project.fps * (clip.playbackRate ?? 1)) : null;
|
|
589
|
+
const camera =
|
|
590
|
+
ctx.project.style && clip.camera !== "none" && styleLayer.styleCamera
|
|
591
|
+
? styleLayer.styleCamera(ctx.project.style, { frame, durationInFrames: clip.duration, width: ctx.width, height: ctx.height })
|
|
592
|
+
: null;
|
|
593
|
+
return (
|
|
594
|
+
<div style={{ ...boxStyle(clip.box), ...style, overflow: "hidden", borderRadius: clip.radius }}>
|
|
595
|
+
<div style={{ position: "absolute", inset: 0, ...(clip.framing ? { filter: camera?.filter } : camera) }}>
|
|
596
|
+
<div ref={held.boxRef} style={crop ? {
|
|
597
|
+
position: "absolute", left: `${-crop.x / crop.width * 100}%`,
|
|
598
|
+
top: `${-crop.y / crop.height * 100}%`,
|
|
599
|
+
width: `${100 / crop.width}%`, height: `${100 / crop.height}%`,
|
|
600
|
+
} : { position: "absolute", inset: 0 }}>
|
|
601
|
+
<Video
|
|
602
|
+
src={source}
|
|
603
|
+
trimBefore={clip.trimStart && clip.trimStart > 0 ? clip.trimStart : undefined}
|
|
604
|
+
volume={(clip.volume ?? 1) * gain}
|
|
605
|
+
muted={trackMuted || clip.muted}
|
|
606
|
+
playbackRate={clip.playbackRate}
|
|
607
|
+
// @remotion/media draws the frame itself: fit has to be its prop (CSS object-fit is ignored).
|
|
608
|
+
objectFit={clip.framing ? "fill" : clip.fit ?? "cover"}
|
|
609
|
+
style={{ width: "100%", height: "100%", filter: grade.filter }}
|
|
610
|
+
{...(grade.effects.length ? { effects: grade.effects } : {})}
|
|
611
|
+
{...(isRendering ? {} : { onVideoFrame: held.onDrawn })}
|
|
612
|
+
/>
|
|
613
|
+
{isRendering ? null : (
|
|
614
|
+
<canvas
|
|
615
|
+
ref={held.overlayRef}
|
|
616
|
+
style={{ position: "absolute", inset: 0, width: "100%", height: "100%", filter: grade.filter, visibility: "hidden" }}
|
|
617
|
+
/>
|
|
618
|
+
)}
|
|
619
|
+
{clip.cursor ? <CursorOverlay cursor={clip.cursor} clip={clip} /> : null}
|
|
620
|
+
</div>
|
|
621
|
+
</div>
|
|
622
|
+
</div>
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// ---------------------------------------------------------------------------
|
|
627
|
+
// Recorded cursor (`cursor` on a video clip): the pointer and click ripples from a
|
|
628
|
+
// `<video>.cursor.json`, drawn inside the clip so it follows its trim, speed and box.
|
|
629
|
+
|
|
630
|
+
const loadedCursorTracks = new Map<string, CursorTrack | null>();
|
|
631
|
+
const pendingCursorTracks = new Map<string, Promise<CursorTrack | null>>();
|
|
632
|
+
|
|
633
|
+
function loadCursorTrack(url: string) {
|
|
634
|
+
let pending = pendingCursorTracks.get(url);
|
|
635
|
+
if (!pending) {
|
|
636
|
+
pending = fetch(url)
|
|
637
|
+
.then((response) => (response.ok ? (response.json() as Promise<CursorTrack>) : null))
|
|
638
|
+
.catch(() => null)
|
|
639
|
+
.then((track) => {
|
|
640
|
+
loadedCursorTracks.set(url, track);
|
|
641
|
+
return track;
|
|
642
|
+
});
|
|
643
|
+
pendingCursorTracks.set(url, pending);
|
|
644
|
+
}
|
|
645
|
+
return pending;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function useCursorTrack(src: string) {
|
|
649
|
+
const url = asset(src);
|
|
650
|
+
const [track, setTrack] = useState(() => loadedCursorTracks.get(url) ?? null);
|
|
651
|
+
const [handle] = useState(() =>
|
|
652
|
+
loadedCursorTracks.has(url) ? null : delayRender(`Loading cursor ${src}`, { timeoutInMilliseconds: 20_000 }),
|
|
653
|
+
);
|
|
654
|
+
useEffect(() => {
|
|
655
|
+
let cancelled = false;
|
|
656
|
+
loadCursorTrack(url)
|
|
657
|
+
.then((loaded) => {
|
|
658
|
+
if (!cancelled) setTrack(loaded);
|
|
659
|
+
})
|
|
660
|
+
.finally(() => {
|
|
661
|
+
if (handle !== null) continueRender(handle);
|
|
662
|
+
});
|
|
663
|
+
return () => {
|
|
664
|
+
cancelled = true;
|
|
665
|
+
};
|
|
666
|
+
}, [url, handle]);
|
|
667
|
+
return track;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function cursorPointAt(path: CursorTrack["path"], frame: number) {
|
|
671
|
+
let low = 0;
|
|
672
|
+
let high = path.length - 1;
|
|
673
|
+
let index = -1;
|
|
674
|
+
while (low <= high) {
|
|
675
|
+
const mid = (low + high) >> 1;
|
|
676
|
+
if (path[mid][0] <= frame) {
|
|
677
|
+
index = mid;
|
|
678
|
+
low = mid + 1;
|
|
679
|
+
} else {
|
|
680
|
+
high = mid - 1;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (index < 0) return null;
|
|
684
|
+
const [from, x, y] = path[index];
|
|
685
|
+
if (x === null || y === null) return null;
|
|
686
|
+
const next = path[index + 1];
|
|
687
|
+
if (!next || next[1] === null || next[2] === null || next[0] <= from) return { x, y };
|
|
688
|
+
const t = Math.min(1, (frame - from) / (next[0] - from));
|
|
689
|
+
return { x: x + (next[1] - x) * t, y: y + (next[2] - y) * t };
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const CURSOR_POINTER_PATH =
|
|
693
|
+
"M3.55 1.75Q2.65 1.4 2.65 2.45L2.65 19.95Q2.65 21.45 3.6 21.75Q4.2 21.95 4.85 21.3L8.25 17.85Q8.65 17.45 8.9 17.98L11.65 23.4Q12.15 24.35 13.1 23.88L15.55 22.7Q16.55 22.22 16.05 21.25L13.3 15.8Q13.02 15.25 13.65 15.25L19.1 15.25Q20.55 15.25 20.78 14.2Q20.95 13.42 20.05 12.78L4.45 1.95Q3.98 1.62 3.55 1.75Z";
|
|
694
|
+
const CURSOR_GREEN = "#2dd47a";
|
|
695
|
+
const HAND_EMOJI = "\u{1F446}";
|
|
696
|
+
|
|
697
|
+
function CursorOverlay({ cursor, clip }: { cursor: VideoCursor; clip: VideoClip }) {
|
|
698
|
+
const frame = useCurrentFrame();
|
|
699
|
+
const { width: compWidth, height: compHeight } = useVideoConfig();
|
|
700
|
+
const track = useCursorTrack(cursor.src);
|
|
701
|
+
// Edits ("source" space) carry clicks for timing only: their positions don't match the picture.
|
|
702
|
+
if (!track || track.space !== "video") return null;
|
|
703
|
+
|
|
704
|
+
const style = cursor.style ?? "classic";
|
|
705
|
+
const fps = track.fps;
|
|
706
|
+
const sourceFrame = (clip.trimStart ?? 0) + frame * (clip.playbackRate ?? 1);
|
|
707
|
+
|
|
708
|
+
// Where the video's picture sits inside the clip box (contain letterboxes, cover crops).
|
|
709
|
+
const box = clip.box ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
710
|
+
const boxWidth = box.width * compWidth;
|
|
711
|
+
const boxHeight = box.height * compHeight;
|
|
712
|
+
const videoWidth = track.width ?? boxWidth;
|
|
713
|
+
const videoHeight = track.height ?? boxHeight;
|
|
714
|
+
const scale =
|
|
715
|
+
(clip.fit ?? "cover") === "contain"
|
|
716
|
+
? Math.min(boxWidth / videoWidth, boxHeight / videoHeight)
|
|
717
|
+
: Math.max(boxWidth / videoWidth, boxHeight / videoHeight);
|
|
718
|
+
const offsetX = (boxWidth - videoWidth * scale) / 2;
|
|
719
|
+
const offsetY = (boxHeight - videoHeight * scale) / 2;
|
|
720
|
+
const toBox = (x: number, y: number) => ({
|
|
721
|
+
left: offsetX + x * videoWidth * scale,
|
|
722
|
+
top: offsetY + y * videoHeight * scale,
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
// Sized to the frame, not the box, so a punch-in doesn't blow the pointer up.
|
|
726
|
+
const size =
|
|
727
|
+
Math.max(18, Math.min(44, Math.min(compWidth, compHeight) * 0.032)) * ((cursor.size ?? 100) / 100);
|
|
728
|
+
|
|
729
|
+
// Smoothing averages the path over a short window around this frame.
|
|
730
|
+
const reach = Math.round((cursor.smoothing ?? 0.3) * 0.2 * fps);
|
|
731
|
+
let sumX = 0;
|
|
732
|
+
let sumY = 0;
|
|
733
|
+
let count = 0;
|
|
734
|
+
for (let offset = -reach; offset <= reach; offset += 1) {
|
|
735
|
+
const sample = cursorPointAt(track.path, sourceFrame + offset);
|
|
736
|
+
if (!sample) continue;
|
|
737
|
+
sumX += sample.x;
|
|
738
|
+
sumY += sample.y;
|
|
739
|
+
count += 1;
|
|
740
|
+
}
|
|
741
|
+
const point = cursorPointAt(track.path, sourceFrame) && count ? toBox(sumX / count, sumY / count) : null;
|
|
742
|
+
|
|
743
|
+
const rippleFrames = 0.6 * fps;
|
|
744
|
+
const ripples =
|
|
745
|
+
cursor.clicks === false
|
|
746
|
+
? []
|
|
747
|
+
: track.clicks.filter((click) => sourceFrame >= click.frame && sourceFrame - click.frame < rippleFrames);
|
|
748
|
+
let lastPressFrame: number | null = null;
|
|
749
|
+
for (const click of track.clicks) {
|
|
750
|
+
if (click.frame > sourceFrame) break;
|
|
751
|
+
lastPressFrame = click.frame;
|
|
752
|
+
}
|
|
753
|
+
const press = lastPressFrame === null ? 0 : Math.max(0, 1 - (sourceFrame - lastPressFrame) / (0.3 * fps));
|
|
754
|
+
const rippleColor = style === "accent" || style === "spotlight" ? CURSOR_GREEN : "#ffffff";
|
|
755
|
+
|
|
756
|
+
return (
|
|
757
|
+
<div style={{ position: "absolute", inset: 0, pointerEvents: "none" }}>
|
|
758
|
+
{ripples.map((click) => {
|
|
759
|
+
const progress = (sourceFrame - click.frame) / rippleFrames;
|
|
760
|
+
const diameter = size * (0.6 + 2.2 * progress);
|
|
761
|
+
const at = toBox(click.x, click.y);
|
|
762
|
+
return (
|
|
763
|
+
<div
|
|
764
|
+
key={click.frame}
|
|
765
|
+
style={{
|
|
766
|
+
position: "absolute",
|
|
767
|
+
left: at.left - diameter / 2,
|
|
768
|
+
top: at.top - diameter / 2,
|
|
769
|
+
width: diameter,
|
|
770
|
+
height: diameter,
|
|
771
|
+
borderRadius: "50%",
|
|
772
|
+
border: `${Math.max(2, size * 0.09)}px solid ${rippleColor}`,
|
|
773
|
+
boxShadow: "0 0 6px rgba(0,0,0,0.45)",
|
|
774
|
+
boxSizing: "border-box",
|
|
775
|
+
opacity: 0.9 * (1 - progress),
|
|
776
|
+
}}
|
|
777
|
+
/>
|
|
778
|
+
);
|
|
779
|
+
})}
|
|
780
|
+
{point && style === "spotlight" ? (
|
|
781
|
+
<div
|
|
782
|
+
style={{
|
|
783
|
+
position: "absolute",
|
|
784
|
+
left: point.left - size * 0.42,
|
|
785
|
+
top: point.top - size * 0.42,
|
|
786
|
+
width: size * 0.84,
|
|
787
|
+
height: size * 0.84,
|
|
788
|
+
borderRadius: "50%",
|
|
789
|
+
border: `${Math.max(2, size * 0.08)}px solid ${CURSOR_GREEN}`,
|
|
790
|
+
background: "rgba(45, 212, 122, 0.16)",
|
|
791
|
+
boxShadow: "0 1px 4px rgba(0,0,0,0.45)",
|
|
792
|
+
boxSizing: "border-box",
|
|
793
|
+
transform: `scale(${1 - press * 0.15})`,
|
|
794
|
+
}}
|
|
795
|
+
/>
|
|
796
|
+
) : null}
|
|
797
|
+
{point && style === "hand" ? (
|
|
798
|
+
<div
|
|
799
|
+
style={{
|
|
800
|
+
position: "absolute",
|
|
801
|
+
left: point.left - size * 0.42,
|
|
802
|
+
top: point.top - size * 0.16,
|
|
803
|
+
fontSize: size,
|
|
804
|
+
lineHeight: 1,
|
|
805
|
+
textShadow: "0 1px 3px rgba(0,0,0,0.55)",
|
|
806
|
+
transform: `rotate(${press * 9}deg) scale(${1 - press * 0.05})`,
|
|
807
|
+
transformOrigin: "42% 16%",
|
|
808
|
+
}}
|
|
809
|
+
>
|
|
810
|
+
{HAND_EMOJI}
|
|
811
|
+
</div>
|
|
812
|
+
) : null}
|
|
813
|
+
{point && (style === "classic" || style === "accent") ? (
|
|
814
|
+
<svg
|
|
815
|
+
width={size}
|
|
816
|
+
height={size * 1.1}
|
|
817
|
+
viewBox="0 0 24 26.4"
|
|
818
|
+
style={{
|
|
819
|
+
position: "absolute",
|
|
820
|
+
left: point.left - (3.55 / 24) * size,
|
|
821
|
+
top: point.top - (1.75 / 24) * size,
|
|
822
|
+
overflow: "visible",
|
|
823
|
+
transform: `scale(${1 - press * 0.08})`,
|
|
824
|
+
transformOrigin: `${(3.55 / 24) * 100}% ${(1.75 / 26.4) * 100}%`,
|
|
825
|
+
}}
|
|
826
|
+
>
|
|
827
|
+
<defs>
|
|
828
|
+
<filter id="studio-cursor-shadow" x="-50%" y="-50%" width="200%" height="200%">
|
|
829
|
+
<feDropShadow dx="0" dy="1.5" stdDeviation="1.1" floodColor="#000000" floodOpacity="0.65" />
|
|
830
|
+
</filter>
|
|
831
|
+
</defs>
|
|
832
|
+
<path
|
|
833
|
+
d={CURSOR_POINTER_PATH}
|
|
834
|
+
fill={style === "accent" ? CURSOR_GREEN : "#ffffff"}
|
|
835
|
+
stroke="#000000"
|
|
836
|
+
strokeWidth={2.4}
|
|
837
|
+
strokeLinejoin="round"
|
|
838
|
+
filter="url(#studio-cursor-shadow)"
|
|
839
|
+
/>
|
|
840
|
+
</svg>
|
|
841
|
+
) : null}
|
|
842
|
+
</div>
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function TextClipView({ clip: saved, ctx }: { clip: TextClip; ctx: StudioRuntimeContextValue }) {
|
|
847
|
+
const clip = useLive(saved);
|
|
848
|
+
const style = useClipStyle(clip);
|
|
849
|
+
const s = { ...projectStyle(ctx.project.style)?.text, ...clip.style };
|
|
850
|
+
const align = s.align ?? "center";
|
|
851
|
+
return (
|
|
852
|
+
<div
|
|
853
|
+
style={{
|
|
854
|
+
...boxStyle(clip.box ?? { x: 0.05, y: 0.4, width: 0.9, height: 0.2 }),
|
|
855
|
+
...style,
|
|
856
|
+
display: "flex",
|
|
857
|
+
alignItems: "center",
|
|
858
|
+
justifyContent: align === "left" ? "flex-start" : align === "right" ? "flex-end" : "center",
|
|
859
|
+
}}
|
|
860
|
+
>
|
|
861
|
+
<div
|
|
862
|
+
style={{
|
|
863
|
+
fontFamily: s.fontFamily ? `"${s.fontFamily}", sans-serif` : "sans-serif",
|
|
864
|
+
fontSize: s.fontSize ?? Math.round(ctx.height * 0.07),
|
|
865
|
+
fontWeight: s.fontWeight ?? 800,
|
|
866
|
+
color: s.color ?? "#ffffff",
|
|
867
|
+
textAlign: align,
|
|
868
|
+
lineHeight: s.lineHeight ?? 1.1,
|
|
869
|
+
letterSpacing: s.letterSpacing,
|
|
870
|
+
textTransform: s.textTransform,
|
|
871
|
+
textShadow: s.shadow,
|
|
872
|
+
whiteSpace: "pre-wrap",
|
|
873
|
+
width: "100%",
|
|
874
|
+
}}
|
|
875
|
+
>
|
|
876
|
+
{clip.text}
|
|
877
|
+
</div>
|
|
878
|
+
</div>
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
function CaptionsClipView({ clip: saved, ctx }: { clip: CaptionsClip; ctx: StudioRuntimeContextValue }) {
|
|
883
|
+
const clip = useLive(saved);
|
|
884
|
+
const StyledCaptions = styleLayer.StyledCaptions;
|
|
885
|
+
if (ctx.project.style && !clip.style?.preset && StyledCaptions && projectStyle(ctx.project.style)) {
|
|
886
|
+
return (
|
|
887
|
+
<StyledCaptionsClip clip={clip} ctx={ctx}>
|
|
888
|
+
<StyledCaptions
|
|
889
|
+
styleId={ctx.project.style}
|
|
890
|
+
words={clip.words}
|
|
891
|
+
position={clip.style?.position}
|
|
892
|
+
wordsPerLine={clip.style?.maxWordsPerLine}
|
|
893
|
+
fontSize={clip.style?.fontSize}
|
|
894
|
+
/>
|
|
895
|
+
</StyledCaptionsClip>
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
return <PlainCaptionsClipView clip={clip} ctx={ctx} />;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function StyledCaptionsClip({ clip, children }: { clip: CaptionsClip; ctx: StudioRuntimeContextValue; children: ReactNode }) {
|
|
902
|
+
const style = useClipStyle(clip);
|
|
903
|
+
return <AbsoluteFill style={{ ...style, pointerEvents: "none" }}>{children}</AbsoluteFill>;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function PlainCaptionsClipView({ clip, ctx }: { clip: CaptionsClip; ctx: StudioRuntimeContextValue }) {
|
|
907
|
+
const frame = useCurrentFrame();
|
|
908
|
+
const style = useClipStyle(clip);
|
|
909
|
+
const s = { ...projectStyle(ctx.project.style)?.captions, ...clip.style };
|
|
910
|
+
const perLine = Math.max(1, s.maxWordsPerLine ?? 4);
|
|
911
|
+
const words = clip.words;
|
|
912
|
+
// Group words into lines of N; show the line containing the current (or last spoken) word.
|
|
913
|
+
let current = -1;
|
|
914
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
915
|
+
if (words[i].from <= frame) current = i;
|
|
916
|
+
else break;
|
|
917
|
+
}
|
|
918
|
+
if (current < 0) return null;
|
|
919
|
+
const lineStart = Math.floor(current / perLine) * perLine;
|
|
920
|
+
const line = words.slice(lineStart, lineStart + perLine);
|
|
921
|
+
const lastWord = line[line.length - 1];
|
|
922
|
+
// Hide the line once its last word ended and the next line hasn't started (pause > 12 frames).
|
|
923
|
+
const next = words[lineStart + perLine];
|
|
924
|
+
if (frame > lastWord.to + 12 && (!next || next.from > frame)) return null;
|
|
925
|
+
|
|
926
|
+
const fontSize = s.fontSize ?? Math.round(ctx.height * (ctx.height > ctx.width ? 0.045 : 0.06));
|
|
927
|
+
const top = s.position === "top" ? "8%" : s.position === "center" ? "50%" : undefined;
|
|
928
|
+
const bottom = s.position === "top" || s.position === "center" ? undefined : "10%";
|
|
929
|
+
const preset = s.preset ?? "pop";
|
|
930
|
+
return (
|
|
931
|
+
<AbsoluteFill style={{ ...style, pointerEvents: "none" }}>
|
|
932
|
+
<div
|
|
933
|
+
style={{
|
|
934
|
+
position: "absolute",
|
|
935
|
+
left: "6%",
|
|
936
|
+
right: "6%",
|
|
937
|
+
top,
|
|
938
|
+
bottom,
|
|
939
|
+
transform: s.position === "center" ? "translateY(-50%)" : undefined,
|
|
940
|
+
display: "flex",
|
|
941
|
+
flexWrap: "wrap",
|
|
942
|
+
justifyContent: "center",
|
|
943
|
+
gap: `0 ${Math.round(fontSize * 0.28)}px`,
|
|
944
|
+
fontFamily: s.fontFamily ? `"${s.fontFamily}", sans-serif` : "sans-serif",
|
|
945
|
+
fontWeight: s.fontWeight ?? 900,
|
|
946
|
+
fontSize,
|
|
947
|
+
lineHeight: 1.15,
|
|
948
|
+
textAlign: "center",
|
|
949
|
+
}}
|
|
950
|
+
>
|
|
951
|
+
{line.map((word, i) => {
|
|
952
|
+
const index = lineStart + i;
|
|
953
|
+
const active = index === current && frame <= word.to + 2;
|
|
954
|
+
const spoken = index <= current;
|
|
955
|
+
let scale = 1;
|
|
956
|
+
if (preset === "pop" && index === current) {
|
|
957
|
+
scale = interpolate(frame, [word.from, word.from + 4, word.from + 8], [0.85, 1.12, 1], clamp);
|
|
958
|
+
}
|
|
959
|
+
const color =
|
|
960
|
+
preset === "plain"
|
|
961
|
+
? (s.color ?? "#fff")
|
|
962
|
+
: active || (preset === "karaoke" && spoken)
|
|
963
|
+
? (s.highlight ?? "#facc15")
|
|
964
|
+
: (s.color ?? "#fff");
|
|
965
|
+
return (
|
|
966
|
+
<span
|
|
967
|
+
key={`${index}-${word.text}`}
|
|
968
|
+
style={{
|
|
969
|
+
display: "inline-block",
|
|
970
|
+
color,
|
|
971
|
+
opacity: preset === "pop" && !spoken ? 0 : 1,
|
|
972
|
+
transform: `scale(${scale})`,
|
|
973
|
+
textShadow: "0 4px 18px rgba(0,0,0,0.55)",
|
|
974
|
+
}}
|
|
975
|
+
>
|
|
976
|
+
{word.text}
|
|
977
|
+
</span>
|
|
978
|
+
);
|
|
979
|
+
})}
|
|
980
|
+
</div>
|
|
981
|
+
</AbsoluteFill>
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
function AudioClipView({ clip: saved, trackMuted, gain }: { clip: AudioClip; trackMuted: boolean; gain: number }) {
|
|
986
|
+
const clip = useLive(saved);
|
|
987
|
+
const base = (clip.volume ?? 1) * gain;
|
|
988
|
+
const fadeIn = Math.max(0, clip.fadeIn ?? 0);
|
|
989
|
+
const fadeOut = Math.max(0, clip.fadeOut ?? 0);
|
|
990
|
+
const duration = clip.duration;
|
|
991
|
+
return (
|
|
992
|
+
<Audio
|
|
993
|
+
src={asset(clip.src)}
|
|
994
|
+
trimBefore={clip.trimStart && clip.trimStart > 0 ? clip.trimStart : undefined}
|
|
995
|
+
muted={trackMuted}
|
|
996
|
+
loop={clip.loop}
|
|
997
|
+
playbackRate={clip.playbackRate}
|
|
998
|
+
volume={
|
|
999
|
+
fadeIn || fadeOut
|
|
1000
|
+
? (f: number) => {
|
|
1001
|
+
const a = fadeIn ? interpolate(f, [0, fadeIn], [0, 1], clamp) : 1;
|
|
1002
|
+
const b = fadeOut ? interpolate(f, [duration - fadeOut, duration], [1, 0], clamp) : 1;
|
|
1003
|
+
return base * a * b;
|
|
1004
|
+
}
|
|
1005
|
+
: base
|
|
1006
|
+
}
|
|
1007
|
+
/>
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const PREMOUNT_SECONDS = 1;
|
|
1012
|
+
|
|
1013
|
+
/** Keep in sync with `clipClass` in lib/studio/preview-perf.ts. */
|
|
1014
|
+
function clipClass(id: string) {
|
|
1015
|
+
return `ac-clip--${id.replace(/\s+/g, "_")}`;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function TrackView({
|
|
1019
|
+
track,
|
|
1020
|
+
scenes,
|
|
1021
|
+
ctx,
|
|
1022
|
+
masterGain,
|
|
1023
|
+
order,
|
|
1024
|
+
}: {
|
|
1025
|
+
track: StudioTrack;
|
|
1026
|
+
scenes: SceneRegistry;
|
|
1027
|
+
ctx: Omit<TrackContext, "order">;
|
|
1028
|
+
masterGain: number;
|
|
1029
|
+
order: number;
|
|
1030
|
+
}) {
|
|
1031
|
+
const visual = track.kind !== "audio";
|
|
1032
|
+
const { isRendering } = useRemotionEnvironment();
|
|
1033
|
+
const trackCtx = useMemo<TrackContext>(() => ({ ...ctx, order }), [ctx, order]);
|
|
1034
|
+
const frame = useCurrentFrame();
|
|
1035
|
+
if (visual && track.hidden) return null;
|
|
1036
|
+
// Adjustment layers draw nothing themselves: the clips below them read them (useClipGrade).
|
|
1037
|
+
if (track.kind === "adjustment") return null;
|
|
1038
|
+
const gain = (track.volume ?? 1) * masterGain;
|
|
1039
|
+
const trackMuted = Boolean(track.muted);
|
|
1040
|
+
return (
|
|
1041
|
+
<>
|
|
1042
|
+
{(track.clips as StudioClip[]).map((raw) => {
|
|
1043
|
+
const clip = resolveClip(raw, ctx.variant);
|
|
1044
|
+
if (clip.duration <= 0) return null;
|
|
1045
|
+
const premountFor = clip.from > 0 ? Math.round(ctx.fps * PREMOUNT_SECONDS) : undefined;
|
|
1046
|
+
// Only clips on screen (or about to be) get a <Sequence>: one for every clip on every frame
|
|
1047
|
+
// is what made long edits drop frames. A <Sequence> outside this range draws nothing anyway.
|
|
1048
|
+
if (frame < clip.from - (premountFor ?? 0) || frame >= clip.from + clip.duration) return null;
|
|
1049
|
+
let body: ReactNode = null;
|
|
1050
|
+
switch (track.kind) {
|
|
1051
|
+
case "scene":
|
|
1052
|
+
body = <SceneClipView clip={clip as SceneClip} scenes={scenes} ctx={trackCtx} />;
|
|
1053
|
+
break;
|
|
1054
|
+
case "image":
|
|
1055
|
+
body = <ImageClipView clip={clip as ImageClip} ctx={trackCtx} />;
|
|
1056
|
+
break;
|
|
1057
|
+
case "video":
|
|
1058
|
+
body = <VideoClipView clip={clip as VideoClip} trackMuted={trackMuted} gain={gain} ctx={trackCtx} />;
|
|
1059
|
+
break;
|
|
1060
|
+
case "text":
|
|
1061
|
+
body = <TextClipView clip={clip as TextClip} ctx={trackCtx} />;
|
|
1062
|
+
break;
|
|
1063
|
+
case "captions":
|
|
1064
|
+
body = <CaptionsClipView clip={clip as CaptionsClip} ctx={trackCtx} />;
|
|
1065
|
+
break;
|
|
1066
|
+
case "audio":
|
|
1067
|
+
body = <AudioClipView clip={clip as AudioClip} trackMuted={trackMuted} gain={gain} />;
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1070
|
+
const name = `${track.name} · ${clip.name ?? clip.id}`;
|
|
1071
|
+
if (!visual && !isRendering) {
|
|
1072
|
+
// Audio in the preview. Remotion only premounts a <Sequence> that has a layout box
|
|
1073
|
+
// (layout="none" silently skips premountFor), and an <Audio> that mounts on its start frame
|
|
1074
|
+
// pauses the player while it fetches and decodes the file, which is the hitch you feel on
|
|
1075
|
+
// every voice line, SFX and music cut. So give it an invisible box purely to enable premount.
|
|
1076
|
+
return (
|
|
1077
|
+
<Sequence
|
|
1078
|
+
key={clip.id}
|
|
1079
|
+
from={clip.from}
|
|
1080
|
+
durationInFrames={clip.duration}
|
|
1081
|
+
premountFor={premountFor}
|
|
1082
|
+
name={name}
|
|
1083
|
+
style={{ display: "none" }}
|
|
1084
|
+
>
|
|
1085
|
+
{body}
|
|
1086
|
+
</Sequence>
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1089
|
+
return (
|
|
1090
|
+
<Sequence
|
|
1091
|
+
key={clip.id}
|
|
1092
|
+
from={clip.from}
|
|
1093
|
+
durationInFrames={clip.duration}
|
|
1094
|
+
// Mount each clip a moment early in the preview (hidden), so heavy scene setup
|
|
1095
|
+
// (WebGL, big DOM) and media buffering happen before the cut instead of on it.
|
|
1096
|
+
// No effect on captures or the export.
|
|
1097
|
+
premountFor={premountFor}
|
|
1098
|
+
name={name}
|
|
1099
|
+
layout={visual ? "absolute-fill" : "none"}
|
|
1100
|
+
// Lets the studio count what each clip draws (lib/studio/preview-perf.ts). No style.
|
|
1101
|
+
className={visual ? clipClass(clip.id) : undefined}
|
|
1102
|
+
>
|
|
1103
|
+
{body}
|
|
1104
|
+
</Sequence>
|
|
1105
|
+
);
|
|
1106
|
+
})}
|
|
1107
|
+
</>
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// Compositions render inside the Agentcut page (Player, captures, browser export). Its global CSS
|
|
1112
|
+
// (Tailwind preflight: border-box everywhere, line-height 1.5, image rules…) must not leak in, or a
|
|
1113
|
+
// project would lay out differently than in a plain Remotion render. Revert author styles inside the
|
|
1114
|
+
// composition to browser defaults; inline styles (everything scenes set) still win.
|
|
1115
|
+
// SVG content is excluded: its presentation attributes (fill, stroke…) lose to any CSS rule.
|
|
1116
|
+
// Then Remotion's own page defaults (remotion/dist default-css: * { box-sizing: border-box }).
|
|
1117
|
+
const ISOLATION_CSS = `.studio-composition, .studio-composition :not(svg, svg *) { all: revert; }
|
|
1118
|
+
.studio-composition, .studio-composition :not(svg, svg *), .studio-composition svg, .studio-composition svg * { box-sizing: border-box; }
|
|
1119
|
+
.studio-composition svg { display: inline; vertical-align: baseline; }`;
|
|
1120
|
+
|
|
1121
|
+
function useStyleIsolation() {
|
|
1122
|
+
if (typeof document === "undefined") return;
|
|
1123
|
+
if (document.getElementById("studio-composition-isolation")) return;
|
|
1124
|
+
const style = document.createElement("style");
|
|
1125
|
+
style.id = "studio-composition-isolation";
|
|
1126
|
+
style.textContent = ISOLATION_CSS;
|
|
1127
|
+
document.head.appendChild(style);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
export function createStudioComposition(scenes: SceneRegistry) {
|
|
1131
|
+
function StudioComposition(props: StudioCompositionProps) {
|
|
1132
|
+
const { project, layers, variant, assetBase, libraryBase, previewProxies } = props;
|
|
1133
|
+
const size = project.variants[variant] ?? project.variants[project.defaultVariant] ?? {
|
|
1134
|
+
width: 1920,
|
|
1135
|
+
height: 1080,
|
|
1136
|
+
};
|
|
1137
|
+
setRuntimeState({ fps: project.fps, assetBase, libraryBase });
|
|
1138
|
+
useStyleIsolation();
|
|
1139
|
+
useProjectFonts(project.fonts ?? []);
|
|
1140
|
+
const ctx = useMemo<StudioRuntimeContextValue>(
|
|
1141
|
+
() => ({
|
|
1142
|
+
project,
|
|
1143
|
+
variant,
|
|
1144
|
+
width: size.width,
|
|
1145
|
+
height: size.height,
|
|
1146
|
+
fps: project.fps,
|
|
1147
|
+
assetBase,
|
|
1148
|
+
libraryBase,
|
|
1149
|
+
previewProxies,
|
|
1150
|
+
}),
|
|
1151
|
+
[project, variant, size.width, size.height, assetBase, libraryBase, previewProxies],
|
|
1152
|
+
);
|
|
1153
|
+
const masterGain = props.masterGain ?? 1;
|
|
1154
|
+
const ordered = [...layers.tracks].reverse();
|
|
1155
|
+
const adjustments = useMemo(
|
|
1156
|
+
() =>
|
|
1157
|
+
ordered.flatMap((track, order) =>
|
|
1158
|
+
track.kind === "adjustment" && !track.hidden
|
|
1159
|
+
? (track.clips as AdjustmentClip[]).map((clip) => ({ clip: resolveClip(clip, variant) as AdjustmentClip, order }))
|
|
1160
|
+
: [],
|
|
1161
|
+
),
|
|
1162
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `ordered` is rebuilt from layers each render
|
|
1163
|
+
[layers, variant],
|
|
1164
|
+
);
|
|
1165
|
+
const stackCtx = useMemo(() => ({ ...ctx, adjustments }), [ctx, adjustments]);
|
|
1166
|
+
return (
|
|
1167
|
+
<StudioRuntimeContext.Provider value={ctx}>
|
|
1168
|
+
<AbsoluteFill
|
|
1169
|
+
className="studio-composition"
|
|
1170
|
+
style={{
|
|
1171
|
+
background: project.background || "#000",
|
|
1172
|
+
overflow: "hidden",
|
|
1173
|
+
// Same starting point as a bare Remotion page: browser default font, size, color, line height.
|
|
1174
|
+
font: "initial",
|
|
1175
|
+
color: "black",
|
|
1176
|
+
letterSpacing: "normal",
|
|
1177
|
+
}}
|
|
1178
|
+
>
|
|
1179
|
+
{project.style && projectStyle(project.style) ? <StyleFonts /> : null}
|
|
1180
|
+
{ordered.map((track, index) => (
|
|
1181
|
+
<TrackView key={`${track.id}:${index}`} track={track} scenes={scenes} ctx={stackCtx} masterGain={masterGain} order={index} />
|
|
1182
|
+
))}
|
|
1183
|
+
{project.style && styleLayer.StyleOverlay ? <styleLayer.StyleOverlay styleId={project.style} /> : null}
|
|
1184
|
+
</AbsoluteFill>
|
|
1185
|
+
</StudioRuntimeContext.Provider>
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
return StudioComposition;
|
|
1189
|
+
}
|