@open-take/compositor 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,415 @@
1
+ import { Circle, Line, makeScene2D, Node, Rect, Txt, Video } from "@revideo/2d";
2
+ import { createSignal, linear, tween } from "@revideo/core";
3
+ import {
4
+ evaluateUiMorph,
5
+ launchEase,
6
+ launchSceneWindows,
7
+ transitionOpacity,
8
+ } from "../launch-evaluate";
9
+ import comp from "./.launch-composition.json";
10
+ import { createMotionLayers } from "./motion-layers";
11
+
12
+ const W = comp.output.width,
13
+ H = comp.output.height;
14
+ const sx = W / 1920,
15
+ sy = H / 1080,
16
+ k = Math.min(sx, sy);
17
+ const windows = launchSceneWindows(comp);
18
+ const color = (scene, key) => scene.colors?.[key] ?? comp.theme[key];
19
+ const bg = (scene) => (scene.background === "dark" ? color(scene, "dark") : color(scene, "canvas"));
20
+ const fg = (scene) => (scene.background === "dark" ? color(scene, "canvas") : color(scene, "ink"));
21
+ const wrap = (text, max = 34) => {
22
+ if (text.length <= max) return text;
23
+ const words = text.split(" ");
24
+ let line = "",
25
+ out = [];
26
+ for (const word of words) {
27
+ if ((line + " " + word).trim().length > max) {
28
+ out.push(line);
29
+ line = word;
30
+ } else line = (line + " " + word).trim();
31
+ }
32
+ if (line) out.push(line);
33
+ return out.join("\n");
34
+ };
35
+ const sceneLocal = (t, win) => t - win.startS;
36
+
37
+ function Icon({ icon, color, size }) {
38
+ const s = size / 24;
39
+ if (icon === "record" || icon === "camera")
40
+ return (
41
+ <Node>
42
+ <Rect width={18 * s} height={13 * s} radius={3 * s} stroke={color} lineWidth={2.2 * s} />
43
+ <Circle size={6 * s} stroke={color} lineWidth={2 * s} />
44
+ </Node>
45
+ );
46
+ if (icon === "style" || icon === "spark")
47
+ return (
48
+ <Node>
49
+ <Line
50
+ points={[
51
+ [0, -10 * s],
52
+ [0, 10 * s],
53
+ ]}
54
+ stroke={color}
55
+ lineWidth={2 * s}
56
+ />
57
+ <Line
58
+ points={[
59
+ [-10 * s, 0],
60
+ [10 * s, 0],
61
+ ]}
62
+ stroke={color}
63
+ lineWidth={2 * s}
64
+ />
65
+ <Line
66
+ points={[
67
+ [-7 * s, -7 * s],
68
+ [7 * s, 7 * s],
69
+ ]}
70
+ stroke={color}
71
+ lineWidth={1.5 * s}
72
+ />
73
+ <Line
74
+ points={[
75
+ [7 * s, -7 * s],
76
+ [-7 * s, 7 * s],
77
+ ]}
78
+ stroke={color}
79
+ lineWidth={1.5 * s}
80
+ />
81
+ </Node>
82
+ );
83
+ return (
84
+ <Node>
85
+ <Circle size={19 * s} stroke={color} lineWidth={2 * s} />
86
+ <Circle size={8 * s} stroke={color} lineWidth={2 * s} />
87
+ <Circle size={2.8 * s} fill={color} />
88
+ </Node>
89
+ );
90
+ }
91
+
92
+ export default makeScene2D("launch", function* (view) {
93
+ const t = createSignal(0);
94
+ const sceneAt = () =>
95
+ windows.find((item) => t() >= item.startS && t() < item.endS)?.scene ?? windows.at(-1).scene;
96
+ view.add(<Rect width={W} height={H} fill={() => bg(sceneAt())} />);
97
+ for (const win of windows) {
98
+ const scene = win.scene;
99
+ const font = scene.colors?.fontFamily ?? comp.theme.fontFamily;
100
+ const active = () => t() >= win.startS && t() < win.endS;
101
+ const local = () => sceneLocal(t(), win);
102
+ const opacity = () => (active() ? transitionOpacity(scene, local()) : 0);
103
+ const slide = () =>
104
+ scene.motion !== "off" && scene.transition?.type === "slide"
105
+ ? (1 - launchEase(Math.min(1, local() / (scene.transition.durationS ?? 0.5)))) * 42 * k
106
+ : 0;
107
+ const root = <Node opacity={opacity} position={() => [0, slide()]} />;
108
+ if (scene.type === "title") {
109
+ const lines = scene.lines;
110
+ lines.forEach((line, i) => {
111
+ root.add(
112
+ <Txt
113
+ text={line}
114
+ fontFamily={scene.colors?.fontFamily ?? comp.theme.fontFamily}
115
+ fontSize={(lines.length > 2 ? 92 : 112) * k}
116
+ fontWeight={600}
117
+ letterSpacing={-3 * k}
118
+ fill={fg(scene)}
119
+ position={[0, (i - (lines.length - 1) / 2) * 120 * k]}
120
+ opacity={() =>
121
+ scene.motion === "off"
122
+ ? 1
123
+ : active()
124
+ ? launchEase((local() - 0.18 - i * (scene.staggerS ?? 0.36)) / 0.45)
125
+ : 0
126
+ }
127
+ y={() =>
128
+ (i - (lines.length - 1) / 2) * 120 * k +
129
+ (scene.motion === "off"
130
+ ? 0
131
+ : 26 * k * (1 - launchEase((local() - 0.18 - i * (scene.staggerS ?? 0.36)) / 0.45)))
132
+ }
133
+ />,
134
+ );
135
+ });
136
+ if (scene.brand)
137
+ root.add(
138
+ <Txt
139
+ text={scene.brand}
140
+ fontFamily={font}
141
+ fontSize={28 * k}
142
+ fontWeight={600}
143
+ letterSpacing={4 * k}
144
+ fill={fg(scene)}
145
+ position={[-W / 2 + 76 * k, -H / 2 + 64 * k]}
146
+ offset={[-1, -1]}
147
+ />,
148
+ );
149
+ } else if (scene.type === "footage") {
150
+ const inset = (scene.frame?.inset ?? 86) * k;
151
+ const fw = W - 2 * inset,
152
+ fh = H - 2 * inset;
153
+ root.add(
154
+ <Rect
155
+ width={fw}
156
+ height={fh}
157
+ radius={(scene.frame?.radius ?? 28) * k}
158
+ clip
159
+ fill="#08100e"
160
+ shadowColor="rgba(0,0,0,.22)"
161
+ shadowBlur={40 * k}
162
+ shadowOffset={[0, 18 * k]}
163
+ >
164
+ <Video
165
+ src={scene.asset}
166
+ time={() =>
167
+ (scene.trimStartS ?? 0) +
168
+ Math.max(0, Math.min(scene.durationS - 1 / comp.output.fps, local()))
169
+ }
170
+ alpha={() => (active() ? 1 : 0)}
171
+ decoder="slow"
172
+ width={fw}
173
+ height={fh}
174
+ />
175
+ </Rect>,
176
+ );
177
+ if (scene.caption)
178
+ root.add(
179
+ <Rect
180
+ layout
181
+ padding={[15 * k, 24 * k]}
182
+ radius={999}
183
+ fill={scene.background === "dark" ? "rgba(245,242,234,.92)" : "rgba(23,46,40,.92)"}
184
+ position={[0, H / 2 - 70 * k]}
185
+ offset={[0, 1]}
186
+ >
187
+ <Txt
188
+ text={scene.caption}
189
+ fontFamily={font}
190
+ fontSize={34 * k}
191
+ fontWeight={600}
192
+ fill={scene.background === "dark" ? comp.theme.ink : comp.theme.canvas}
193
+ />
194
+ </Rect>,
195
+ );
196
+ } else if (scene.type === "ui-morph") {
197
+ const ev = () => evaluateUiMorph(scene, local());
198
+ const panelY = 20 * k;
199
+ const intro = () => launchEase(local() / 0.55);
200
+ const panel = (
201
+ <Rect
202
+ width={() => ev().panelWidth * k}
203
+ height={() => ev().panelHeight * k}
204
+ radius={(scene.panel?.radius ?? 34) * k}
205
+ fill={scene.colors?.surface ?? comp.theme.surface}
206
+ position={() => [0, panelY + 24 * k * (1 - intro())]}
207
+ scale={() => [0.97 + 0.03 * intro(), 0.97 + 0.03 * intro()]}
208
+ opacity={intro}
209
+ shadowColor="rgba(23,46,40,.12)"
210
+ shadowBlur={34 * k}
211
+ shadowOffset={[0, 14 * k]}
212
+ />
213
+ );
214
+ root.add(panel);
215
+ const chipY = () => panelY - (ev().panelHeight * k) / 2 + 48 * k;
216
+ const chipWidth = () => ev().chipWidth * k;
217
+ root.add(
218
+ <Rect
219
+ width={chipWidth}
220
+ height={52 * k}
221
+ radius={26 * k}
222
+ fill={scene.colors?.canvas ?? comp.theme.canvas}
223
+ position={() => [(-ev().panelWidth * k) / 2 + chipWidth() / 2 + 30 * k, chipY()]}
224
+ />,
225
+ );
226
+ scene.states.forEach((state) => {
227
+ const currentOpacity = () =>
228
+ ev().to === state
229
+ ? ev().newOpacity
230
+ : ev().from === state && ev().from !== ev().to
231
+ ? ev().oldOpacity
232
+ : 0;
233
+ const stateY = () => (ev().to === state ? ev().newY * k : ev().oldY * k);
234
+ root.add(
235
+ <Node
236
+ position={() => [(-ev().panelWidth * k) / 2 + 58 * k, chipY() + stateY()]}
237
+ rotation={() => (ev().to === state ? ev().iconRotation : 0)}
238
+ opacity={currentOpacity}
239
+ >
240
+ <Icon
241
+ icon={state.icon}
242
+ color={scene.colors?.accent ?? comp.theme.accent}
243
+ size={24 * k}
244
+ />
245
+ </Node>,
246
+ );
247
+ root.add(
248
+ <Txt
249
+ text={state.label}
250
+ fontFamily={font}
251
+ fontSize={30 * k}
252
+ fontWeight={600}
253
+ fill={scene.colors?.accent ?? comp.theme.accent}
254
+ position={() => [(-ev().panelWidth * k) / 2 + 87 * k, chipY() + stateY()]}
255
+ offset={[-1, 0]}
256
+ opacity={currentOpacity}
257
+ />,
258
+ );
259
+ });
260
+ root.add(
261
+ <Txt
262
+ text="×"
263
+ fontFamily={font}
264
+ fontSize={30 * k}
265
+ fill={scene.colors?.accent ?? comp.theme.accent}
266
+ position={() => [(-ev().panelWidth * k) / 2 + chipWidth() + 14 * k, chipY()]}
267
+ opacity={() => ev().newOpacity}
268
+ />,
269
+ );
270
+ const promptPosition = () => [
271
+ (-ev().panelWidth * k) / 2 + 34 * k,
272
+ panelY + (ev().panelHeight * k) / 2 - 58 * k,
273
+ ];
274
+ const oldPrompt = (
275
+ <Txt
276
+ text=""
277
+ fontFamily={scene.colors?.fontFamily ?? comp.theme.fontFamily}
278
+ fontSize={46 * k}
279
+ fontWeight={500}
280
+ fill={scene.colors?.ink ?? comp.theme.ink}
281
+ position={promptPosition}
282
+ offset={[-1, 0]}
283
+ opacity={() => ev().oldOpacity}
284
+ />
285
+ );
286
+ oldPrompt.text(() => ev().from.prompt);
287
+ root.add(oldPrompt);
288
+ const newPrompt = (
289
+ <Txt
290
+ text=""
291
+ fontFamily={scene.colors?.fontFamily ?? comp.theme.fontFamily}
292
+ fontSize={46 * k}
293
+ fontWeight={500}
294
+ fill={scene.colors?.ink ?? comp.theme.ink}
295
+ position={promptPosition}
296
+ offset={[-1, 0]}
297
+ />
298
+ );
299
+ newPrompt.text(() => ev().to.prompt.slice(0, ev().promptChars));
300
+ root.add(newPrompt);
301
+ root.add(
302
+ <Circle
303
+ size={54 * k}
304
+ fill={scene.colors?.accent ?? comp.theme.accent}
305
+ position={() => [ev().sendX * k, panelY + (ev().panelHeight * k) / 2 - 58 * k]}
306
+ scale={() => [ev().sendScale, ev().sendScale]}
307
+ opacity={() => launchEase((local() - 0.08) / 0.47)}
308
+ >
309
+ <Line
310
+ points={[
311
+ [0, 8 * k],
312
+ [0, -8 * k],
313
+ [-7 * k, -1 * k],
314
+ [0, -8 * k],
315
+ [7 * k, -1 * k],
316
+ ]}
317
+ stroke={scene.colors?.canvas ?? comp.theme.canvas}
318
+ lineWidth={3 * k}
319
+ lineCap="round"
320
+ lineJoin="round"
321
+ />
322
+ </Circle>,
323
+ );
324
+ root.add(
325
+ <Circle
326
+ size={52 * k}
327
+ fill={scene.colors?.surface ?? comp.theme.surface}
328
+ position={() => [ev().plusX * k, panelY]}
329
+ opacity={() => launchEase((local() - 0.08) / 0.47)}
330
+ >
331
+ <Txt
332
+ text="+"
333
+ fontFamily={font}
334
+ fontSize={40 * k}
335
+ fontWeight={400}
336
+ fill={scene.colors?.accent ?? comp.theme.accent}
337
+ />
338
+ </Circle>,
339
+ );
340
+ if (scene.eyebrow)
341
+ root.add(
342
+ <Txt
343
+ text={scene.eyebrow}
344
+ fontFamily={scene.colors?.fontFamily ?? comp.theme.fontFamily}
345
+ fontSize={22 * k}
346
+ fontWeight={600}
347
+ letterSpacing={5 * k}
348
+ fill={scene.colors?.accent ?? comp.theme.accent}
349
+ opacity={0.52}
350
+ position={[0, -220 * k]}
351
+ />,
352
+ );
353
+ } else if (scene.type === "motion") {
354
+ root.add(
355
+ createMotionLayers({
356
+ scene,
357
+ localS: local,
358
+ output: comp.output,
359
+ theme: {
360
+ ink: scene.colors?.ink ?? comp.theme.ink,
361
+ surface: scene.colors?.surface ?? comp.theme.surface,
362
+ accent: scene.colors?.accent ?? comp.theme.accent,
363
+ fontFamily: scene.colors?.fontFamily ?? comp.theme.fontFamily,
364
+ },
365
+ }),
366
+ );
367
+ } else {
368
+ root.add(
369
+ <Txt
370
+ text={wrap(scene.headline, 30)}
371
+ fontFamily={scene.colors?.fontFamily ?? comp.theme.fontFamily}
372
+ fontSize={92 * k}
373
+ fontWeight={600}
374
+ lineHeight={108 * k}
375
+ letterSpacing={-2 * k}
376
+ fill={fg(scene)}
377
+ position={[0, -90 * k]}
378
+ opacity={() => (scene.motion === "off" ? 1 : launchEase((local() - 0.2) / 0.5))}
379
+ />,
380
+ );
381
+ root.add(
382
+ <Txt
383
+ text={scene.brand}
384
+ fontFamily={scene.colors?.fontFamily ?? comp.theme.fontFamily}
385
+ fontSize={30 * k}
386
+ fontWeight={600}
387
+ letterSpacing={4 * k}
388
+ fill={fg(scene)}
389
+ position={[0, 104 * k]}
390
+ opacity={() => (scene.motion === "off" ? 1 : launchEase((local() - 0.6) / 0.45))}
391
+ />,
392
+ );
393
+ root.add(
394
+ <Rect
395
+ layout
396
+ padding={[16 * k, 26 * k]}
397
+ radius={12 * k}
398
+ fill={scene.colors?.accent ?? comp.theme.accent}
399
+ position={[0, 190 * k]}
400
+ opacity={() => (scene.motion === "off" ? 1 : launchEase((local() - 0.85) / 0.45))}
401
+ >
402
+ <Txt
403
+ text={scene.cta}
404
+ fontFamily="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"
405
+ fontSize={28 * k}
406
+ fontWeight={600}
407
+ fill={scene.colors?.canvas ?? comp.theme.canvas}
408
+ />
409
+ </Rect>,
410
+ );
411
+ }
412
+ view.add(root);
413
+ }
414
+ yield* tween(windows.at(-1).endS, (v) => t(v * windows.at(-1).endS), linear);
415
+ });
@@ -0,0 +1,260 @@
1
+ import { Circle, Img, Line, Node, Rect, Txt, Video } from "@revideo/2d";
2
+ import { evaluateMotionScene } from "../motion-evaluate";
3
+ import type { EvaluatedMotionLayer, MotionLayer, MotionScene } from "../motion-types";
4
+
5
+ export type MotionLayerTheme = {
6
+ ink: string;
7
+ surface: string;
8
+ accent: string;
9
+ fontFamily: string;
10
+ };
11
+
12
+ type MotionLayerType = MotionLayer["type"];
13
+ type EvaluatedLayerOf<T extends MotionLayerType> = Extract<EvaluatedMotionLayer, { type: T }>;
14
+ type LayerState<T extends MotionLayerType> = () => EvaluatedLayerOf<T>;
15
+
16
+ type MotionLayerRendererOptions = {
17
+ scene: MotionScene;
18
+ localS: () => number;
19
+ output: { width: number; height: number; fps: number };
20
+ theme: MotionLayerTheme;
21
+ };
22
+
23
+ /** Revideo exposes normal wrapping and preformatted text separately; motion
24
+ * text needs both automatic wrapping and authored editorial line breaks. */
25
+ class WrappedTxt extends Txt {
26
+ protected override applyFont(): void {
27
+ super.applyFont();
28
+ this.element.style.whiteSpace = "pre-wrap";
29
+ this.element.style.overflowWrap = "anywhere";
30
+ }
31
+ }
32
+
33
+ /** Video does not expose its decoded pixel size, but fit needs that size after
34
+ * readiness. This signal is reevaluated with scene time, so the initial 0x0
35
+ * state is replaced as soon as the stable media element has metadata. */
36
+ class FittedVideo extends Video {
37
+ public sourceSize(): [number, number] {
38
+ const media = this.mediaElement() as HTMLVideoElement;
39
+ return [media.videoWidth, media.videoHeight];
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Build stable Revideo nodes whose signals read from the shared pure evaluator.
45
+ * The evaluator is cached once per local timeline value so every node observes
46
+ * one coherent tree without duplicating easing or interpolation in the scene.
47
+ */
48
+ export function createMotionLayers({
49
+ scene,
50
+ localS,
51
+ output,
52
+ theme,
53
+ }: MotionLayerRendererOptions): Node {
54
+ let cachedS = Number.NaN;
55
+ let byId = new Map<string, EvaluatedMotionLayer>();
56
+
57
+ const evaluateFrame = () => {
58
+ const time = localS();
59
+ if (time !== cachedS) {
60
+ cachedS = time;
61
+ byId = new Map();
62
+ const visit = (layers: EvaluatedMotionLayer[]) => {
63
+ for (const layer of layers) {
64
+ byId.set(layer.id, layer);
65
+ if (layer.type === "group") visit(layer.children);
66
+ }
67
+ };
68
+ visit(evaluateMotionScene(scene, time).layers);
69
+ }
70
+ };
71
+
72
+ const state =
73
+ <T extends MotionLayerType>(id: string, type: T): LayerState<T> =>
74
+ () => {
75
+ evaluateFrame();
76
+ const layer = byId.get(id);
77
+ if (!layer || layer.type !== type) {
78
+ throw new Error(`motion layer ${id} is missing from the evaluated ${type} tree`);
79
+ }
80
+ return layer as EvaluatedLayerOf<T>;
81
+ };
82
+
83
+ const transform = <T extends MotionLayerType>(get: LayerState<T>) => ({
84
+ position: () => [get().x, get().y] as [number, number],
85
+ opacity: () => get().opacity,
86
+ scale: () => [get().scaleX, get().scaleY] as [number, number],
87
+ rotation: () => get().rotation,
88
+ });
89
+
90
+ const createLayer = (authored: MotionLayer): Node => {
91
+ if (authored.type === "group") {
92
+ const get = state(authored.id, "group");
93
+ const group = authored.clip ? (
94
+ <Rect
95
+ {...transform(get)}
96
+ width={() => get().width ?? 0}
97
+ height={() => get().height ?? 0}
98
+ radius={() => get().radius}
99
+ clip
100
+ />
101
+ ) : (
102
+ <Node {...transform(get)} />
103
+ );
104
+ for (const child of authored.children) group.add(createLayer(child));
105
+ return group;
106
+ }
107
+
108
+ if (authored.type === "rect") {
109
+ const get = state(authored.id, "rect");
110
+ return (
111
+ <Rect
112
+ {...transform(get)}
113
+ width={() => get().width}
114
+ height={() => get().height}
115
+ radius={() => get().radius}
116
+ fill={() => get().fill ?? theme.surface}
117
+ stroke={() => get().stroke ?? theme.accent}
118
+ lineWidth={() => get().strokeWidth}
119
+ shadowColor={() => get().shadow?.color ?? "rgba(0,0,0,0)"}
120
+ shadowBlur={() => get().shadow?.blur ?? 0}
121
+ shadowOffset={() => [get().shadow?.offsetX ?? 0, get().shadow?.offsetY ?? 0]}
122
+ />
123
+ );
124
+ }
125
+
126
+ if (authored.type === "ellipse") {
127
+ const get = state(authored.id, "ellipse");
128
+ return (
129
+ <Circle
130
+ {...transform(get)}
131
+ width={() => get().width}
132
+ height={() => get().height}
133
+ fill={() => get().fill ?? theme.surface}
134
+ stroke={() => get().stroke ?? theme.accent}
135
+ lineWidth={() => get().strokeWidth}
136
+ />
137
+ );
138
+ }
139
+
140
+ if (authored.type === "text") {
141
+ const get = state(authored.id, "text");
142
+ const box = (
143
+ <Rect {...transform(get)} width={() => get().width} height={() => get().height} clip />
144
+ );
145
+ const text = (
146
+ <WrappedTxt
147
+ text=""
148
+ width={() => get().width}
149
+ height={() => get().height}
150
+ fontFamily={() => get().fontFamily ?? theme.fontFamily}
151
+ fontSize={() => get().fontSize}
152
+ fontWeight={() => get().fontWeight}
153
+ lineHeight={() => get().lineHeight}
154
+ textAlign={() => get().align}
155
+ fill={() => get().fill ?? theme.ink}
156
+ />
157
+ ) as Txt;
158
+ // Txt's constructor interprets function-valued text as children. Binding
159
+ // after construction routes the signal through TxtLeaf as intended.
160
+ text.text(() => get().text);
161
+ box.add(text);
162
+ return box;
163
+ }
164
+
165
+ if (authored.type === "image") {
166
+ const get = state(authored.id, "image");
167
+ const frame = (
168
+ <Rect
169
+ {...transform(get)}
170
+ width={() => get().width}
171
+ height={() => get().height}
172
+ radius={() => get().radius}
173
+ clip
174
+ shadowColor={() => get().shadow?.color ?? "rgba(0,0,0,0)"}
175
+ shadowBlur={() => get().shadow?.blur ?? 0}
176
+ shadowOffset={() => [get().shadow?.offsetX ?? 0, get().shadow?.offsetY ?? 0]}
177
+ />
178
+ );
179
+ const image = (<Img src={authored.asset} />) as Img;
180
+ const fittedSize = () => {
181
+ const layer = get();
182
+ const natural = image.naturalSize();
183
+ if (natural.x <= 0 || natural.y <= 0) {
184
+ return [layer.width, layer.height] as [number, number];
185
+ }
186
+ const fit =
187
+ layer.fit === "cover"
188
+ ? Math.max(layer.width / natural.x, layer.height / natural.y)
189
+ : Math.min(layer.width / natural.x, layer.height / natural.y);
190
+ return [natural.x * fit, natural.y * fit] as [number, number];
191
+ };
192
+ image.size(fittedSize);
193
+ frame.add(image);
194
+ return frame;
195
+ }
196
+
197
+ if (authored.type === "video") {
198
+ const get = state(authored.id, "video");
199
+ const frame = (
200
+ <Rect
201
+ {...transform(get)}
202
+ width={() => get().width}
203
+ height={() => get().height}
204
+ radius={() => get().radius}
205
+ clip
206
+ shadowColor={() => get().shadow?.color ?? "rgba(0,0,0,0)"}
207
+ shadowBlur={() => get().shadow?.blur ?? 0}
208
+ shadowOffset={() => [get().shadow?.offsetX ?? 0, get().shadow?.offsetY ?? 0]}
209
+ />
210
+ );
211
+ const video = (
212
+ <FittedVideo
213
+ src={authored.asset}
214
+ decoder="slow"
215
+ volume={0}
216
+ time={() => {
217
+ const layer = get();
218
+ const lastSample = layer.trimStartS + Math.max(0, layer.durationS - 1 / output.fps);
219
+ return Math.min(layer.mediaTimeS, lastSample);
220
+ }}
221
+ />
222
+ ) as FittedVideo;
223
+ const fittedSize = () => {
224
+ const layer = get();
225
+ const [width, height] = video.sourceSize();
226
+ if (width <= 0 || height <= 0) {
227
+ return [layer.width, layer.height] as [number, number];
228
+ }
229
+ const fit =
230
+ layer.fit === "cover"
231
+ ? Math.max(layer.width / width, layer.height / height)
232
+ : Math.min(layer.width / width, layer.height / height);
233
+ return [width * fit, height * fit] as [number, number];
234
+ };
235
+ video.size(fittedSize);
236
+ frame.add(video);
237
+ return frame;
238
+ }
239
+
240
+ const get = state(authored.id, "line");
241
+ return (
242
+ <Line
243
+ {...transform(get)}
244
+ points={authored.points}
245
+ opacity={() => (get().end > 0 ? get().opacity : 0)}
246
+ stroke={() => get().stroke ?? theme.accent}
247
+ lineWidth={() => get().strokeWidth}
248
+ end={() => get().end}
249
+ lineCap="round"
250
+ lineJoin="round"
251
+ />
252
+ );
253
+ };
254
+
255
+ const design = scene.designSize ?? { width: 1920, height: 1080 };
256
+ const fit = Math.min(output.width / design.width, output.height / design.height);
257
+ const root = <Node scale={[fit, fit]} />;
258
+ for (const layer of scene.layers) root.add(createLayer(layer));
259
+ return root;
260
+ }
package/src/types.ts CHANGED
@@ -162,6 +162,23 @@ export type CaptureLog = {
162
162
  /** the ordered ground-truth actions (click / type / drag) */
163
163
  events: CaptureEvent[];
164
164
  tEndMs?: number;
165
+ /** Delivered frame timing, not a unique-content or smoothness measurement.
166
+ * Static pages may legitimately send no frames. Compare image changes in
167
+ * active action windows; encoded video.fps alone does not establish cadence. */
168
+ captureCadence?: {
169
+ rasterRefresh?: "idle" | "off";
170
+ frameCount: number;
171
+ timestampSource: "frame-swap" | "arrival" | "mixed";
172
+ /** Sorted presentation offsets; paired arrivals can expose delivery lag. */
173
+ frameOffsetsMs: number[];
174
+ arrivalOffsetsMs: number[];
175
+ medianIntervalMs: number;
176
+ p95IntervalMs: number;
177
+ maxIntervalMs: number;
178
+ maxArrivalDelayMs: number;
179
+ outOfOrderFrames: number;
180
+ note: string;
181
+ };
165
182
  /** Steps the capture DROPPED (target not found / endpoint unresolved) — the
166
183
  * take still completes, but a missing beat must reach the end-of-run
167
184
  * summary and (strict by default) the exit code, not just an early stderr line