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