reframe-video 0.6.12 → 0.6.14
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/bin.js +38 -7
- package/dist/browserEntry.js +3 -2
- package/dist/cli.js +3 -2
- package/dist/diff.js +1189 -0
- package/dist/index.js +4 -2
- package/dist/labels.js +3 -2
- package/dist/types/ir.d.ts +3 -0
- package/guides/directing-guide.md +101 -0
- package/guides/edsl-guide.md +6 -1
- package/package.json +1 -1
package/dist/diff.js
ADDED
|
@@ -0,0 +1,1189 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
|
|
3
|
+
// ../render-cli/src/diff.ts
|
|
4
|
+
import { readFile as readFile5, writeFile } from "node:fs/promises";
|
|
5
|
+
import { dirname as dirname4, extname as extname3, resolve as resolve4 } from "node:path";
|
|
6
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
7
|
+
import { chromium as chromium2 } from "playwright";
|
|
8
|
+
|
|
9
|
+
// ../render-cli/src/loadScene.ts
|
|
10
|
+
import { build } from "esbuild";
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { dirname, resolve } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
// ../core/src/ir.ts
|
|
16
|
+
var DEFAULT_TO_DURATION = 0.5;
|
|
17
|
+
var DEFAULT_TWEEN_DURATION = 0.5;
|
|
18
|
+
var DEFAULT_MOTIONPATH_DURATION = 1;
|
|
19
|
+
var DEFAULT_STILL_DURATION = 1;
|
|
20
|
+
|
|
21
|
+
// ../core/src/path.ts
|
|
22
|
+
function locate(segCount, u) {
|
|
23
|
+
if (segCount <= 0) return { i: 0, t: 0 };
|
|
24
|
+
const clamped = Math.max(0, Math.min(1, u));
|
|
25
|
+
const scaled = clamped * segCount;
|
|
26
|
+
let i = Math.floor(scaled);
|
|
27
|
+
if (i >= segCount) i = segCount - 1;
|
|
28
|
+
return { i, t: scaled - i };
|
|
29
|
+
}
|
|
30
|
+
function controls(points, closed, i) {
|
|
31
|
+
const n = points.length;
|
|
32
|
+
const at = (k) => {
|
|
33
|
+
if (closed) return points[(k % n + n) % n];
|
|
34
|
+
return points[Math.max(0, Math.min(n - 1, k))];
|
|
35
|
+
};
|
|
36
|
+
return [at(i - 1), at(i), at(i + 1), at(i + 2)];
|
|
37
|
+
}
|
|
38
|
+
function segCountOf(points, closed) {
|
|
39
|
+
const n = points.length;
|
|
40
|
+
if (n < 2) return 0;
|
|
41
|
+
return closed ? n : n - 1;
|
|
42
|
+
}
|
|
43
|
+
function pathPoint(points, closed, u, curviness = 1) {
|
|
44
|
+
const n = points.length;
|
|
45
|
+
if (n === 0) return [0, 0];
|
|
46
|
+
if (n === 1) return [points[0][0], points[0][1]];
|
|
47
|
+
const segs = segCountOf(points, closed);
|
|
48
|
+
const { i, t } = locate(segs, u);
|
|
49
|
+
const [p0, p1, p2, p3] = controls(points, closed, i);
|
|
50
|
+
const t2 = t * t;
|
|
51
|
+
const t3 = t2 * t;
|
|
52
|
+
if (curviness === 1) {
|
|
53
|
+
const f = (a, b, c, d) => 0.5 * (2 * b + (-a + c) * t + (2 * a - 5 * b + 4 * c - d) * t2 + (-a + 3 * b - 3 * c + d) * t3);
|
|
54
|
+
return [f(p0[0], p1[0], p2[0], p3[0]), f(p0[1], p1[1], p2[1], p3[1])];
|
|
55
|
+
}
|
|
56
|
+
const h00 = 2 * t3 - 3 * t2 + 1;
|
|
57
|
+
const h10 = t3 - 2 * t2 + t;
|
|
58
|
+
const h01 = -2 * t3 + 3 * t2;
|
|
59
|
+
const h11 = t3 - t2;
|
|
60
|
+
const k = curviness * 0.5;
|
|
61
|
+
const H = (a, b, c, d) => h00 * b + h10 * k * (c - a) + h01 * c + h11 * k * (d - b);
|
|
62
|
+
return [H(p0[0], p1[0], p2[0], p3[0]), H(p0[1], p1[1], p2[1], p3[1])];
|
|
63
|
+
}
|
|
64
|
+
function pathTangentAngle(points, closed, u, curviness = 1) {
|
|
65
|
+
const n = points.length;
|
|
66
|
+
if (n < 2) return 0;
|
|
67
|
+
const segs = segCountOf(points, closed);
|
|
68
|
+
const { i, t } = locate(segs, u);
|
|
69
|
+
const [p0, p1, p2, p3] = controls(points, closed, i);
|
|
70
|
+
const t2 = t * t;
|
|
71
|
+
let dx;
|
|
72
|
+
let dy;
|
|
73
|
+
if (curviness === 1) {
|
|
74
|
+
const d = (a, b, c, e) => 0.5 * (-a + c + 2 * (2 * a - 5 * b + 4 * c - e) * t + 3 * (-a + 3 * b - 3 * c + e) * t2);
|
|
75
|
+
dx = d(p0[0], p1[0], p2[0], p3[0]);
|
|
76
|
+
dy = d(p0[1], p1[1], p2[1], p3[1]);
|
|
77
|
+
} else {
|
|
78
|
+
const g00 = 6 * t2 - 6 * t;
|
|
79
|
+
const g10 = 3 * t2 - 4 * t + 1;
|
|
80
|
+
const g01 = -6 * t2 + 6 * t;
|
|
81
|
+
const g11 = 3 * t2 - 2 * t;
|
|
82
|
+
const k = curviness * 0.5;
|
|
83
|
+
const D = (a, b, c, e) => g00 * b + g10 * k * (c - a) + g01 * c + g11 * k * (e - b);
|
|
84
|
+
dx = D(p0[0], p1[0], p2[0], p3[0]);
|
|
85
|
+
dy = D(p0[1], p1[1], p2[1], p3[1]);
|
|
86
|
+
}
|
|
87
|
+
if (dx === 0 && dy === 0) return 0;
|
|
88
|
+
return Math.atan2(dy, dx) * 180 / Math.PI;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ../core/src/compile.ts
|
|
92
|
+
var key = (target, prop) => `${target}.${prop}`;
|
|
93
|
+
function scaleTimeline(tl, k) {
|
|
94
|
+
switch (tl.kind) {
|
|
95
|
+
case "seq":
|
|
96
|
+
case "par":
|
|
97
|
+
return { ...tl, children: tl.children.map((c) => scaleTimeline(c, k)) };
|
|
98
|
+
case "stagger":
|
|
99
|
+
return { ...tl, interval: tl.interval * k, children: tl.children.map((c) => scaleTimeline(c, k)) };
|
|
100
|
+
case "wait":
|
|
101
|
+
return { ...tl, duration: tl.duration * k };
|
|
102
|
+
case "tween":
|
|
103
|
+
return { ...tl, duration: (tl.duration ?? DEFAULT_TWEEN_DURATION) * k };
|
|
104
|
+
case "motionPath":
|
|
105
|
+
return { ...tl, duration: (tl.duration ?? DEFAULT_MOTIONPATH_DURATION) * k };
|
|
106
|
+
case "to":
|
|
107
|
+
return {
|
|
108
|
+
...tl,
|
|
109
|
+
duration: (tl.duration ?? DEFAULT_TO_DURATION) * k,
|
|
110
|
+
...tl.stagger !== void 0 && { stagger: tl.stagger * k }
|
|
111
|
+
};
|
|
112
|
+
case "beat":
|
|
113
|
+
return {
|
|
114
|
+
...tl,
|
|
115
|
+
children: tl.children.map((c) => scaleTimeline(c, k)),
|
|
116
|
+
...tl.gap !== void 0 && { gap: tl.gap * k }
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function orderBeats(children) {
|
|
121
|
+
return children.map((c, i) => ({ c, i, key: c.kind === "beat" && c.order !== void 0 ? c.order : i })).sort((a, b) => a.key - b.key || a.i - b.i).map((x) => x.c);
|
|
122
|
+
}
|
|
123
|
+
function compileScene(ir) {
|
|
124
|
+
const nodeById = /* @__PURE__ */ new Map();
|
|
125
|
+
const nodeOrder = [];
|
|
126
|
+
const collect = (nodes) => {
|
|
127
|
+
for (const node of nodes) {
|
|
128
|
+
nodeById.set(node.id, node);
|
|
129
|
+
nodeOrder.push(node.id);
|
|
130
|
+
if (node.type === "group") collect(node.children);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
collect(ir.nodes);
|
|
134
|
+
const initialValues = /* @__PURE__ */ new Map();
|
|
135
|
+
for (const [id, node] of nodeById) {
|
|
136
|
+
for (const [prop, value] of Object.entries(node.props)) {
|
|
137
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
138
|
+
initialValues.set(key(id, prop), value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (ir.initial !== void 0) {
|
|
143
|
+
const override = ir.states?.[ir.initial] ?? {};
|
|
144
|
+
for (const [id, props] of Object.entries(override)) {
|
|
145
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
146
|
+
initialValues.set(key(id, prop), value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const cameraIsNode = nodeById.has("camera");
|
|
151
|
+
if (!cameraIsNode) {
|
|
152
|
+
const cam = ir.camera ?? {};
|
|
153
|
+
initialValues.set(key("camera", "x"), cam.x ?? ir.size.width / 2);
|
|
154
|
+
initialValues.set(key("camera", "y"), cam.y ?? ir.size.height / 2);
|
|
155
|
+
initialValues.set(key("camera", "zoom"), cam.zoom ?? 1);
|
|
156
|
+
initialValues.set(key("camera", "rotation"), cam.rotation ?? 0);
|
|
157
|
+
if (cam.perspective !== void 0) initialValues.set(key("camera", "perspective"), cam.perspective);
|
|
158
|
+
}
|
|
159
|
+
const segments = /* @__PURE__ */ new Map();
|
|
160
|
+
const motionPaths = /* @__PURE__ */ new Map();
|
|
161
|
+
const current = new Map(initialValues);
|
|
162
|
+
const pushSegment = (seg) => {
|
|
163
|
+
const k = key(seg.target, seg.prop);
|
|
164
|
+
let list = segments.get(k);
|
|
165
|
+
if (!list) segments.set(k, list = []);
|
|
166
|
+
list.push(seg);
|
|
167
|
+
current.set(k, seg.to);
|
|
168
|
+
};
|
|
169
|
+
const currentValue = (target, prop) => {
|
|
170
|
+
const v = current.get(key(target, prop));
|
|
171
|
+
if (v !== void 0) return v;
|
|
172
|
+
if (prop === "opacity" || prop === "scale" || prop === "progress" || prop === "scaleX" || prop === "scaleY") return 1;
|
|
173
|
+
if (prop === "rotation" || prop === "skewX" || prop === "skewY") return 0;
|
|
174
|
+
throw new Error(`cannot animate "${prop}" of "${target}": no base value to start from`);
|
|
175
|
+
};
|
|
176
|
+
const labelTimes = /* @__PURE__ */ new Map();
|
|
177
|
+
const beatTimes = /* @__PURE__ */ new Map();
|
|
178
|
+
const durationOf = (tl, start) => {
|
|
179
|
+
switch (tl.kind) {
|
|
180
|
+
case "seq": {
|
|
181
|
+
let t = start;
|
|
182
|
+
for (const child of orderBeats(tl.children)) t = durationOf(child, t);
|
|
183
|
+
return t;
|
|
184
|
+
}
|
|
185
|
+
case "par": {
|
|
186
|
+
let end = start;
|
|
187
|
+
for (const child of tl.children) end = Math.max(end, durationOf(child, start));
|
|
188
|
+
return end;
|
|
189
|
+
}
|
|
190
|
+
case "stagger": {
|
|
191
|
+
let end = start;
|
|
192
|
+
tl.children.forEach((child, i) => {
|
|
193
|
+
end = Math.max(end, durationOf(child, start + i * tl.interval));
|
|
194
|
+
});
|
|
195
|
+
return end;
|
|
196
|
+
}
|
|
197
|
+
case "wait":
|
|
198
|
+
return start + tl.duration;
|
|
199
|
+
case "tween":
|
|
200
|
+
return start + (tl.duration ?? DEFAULT_TWEEN_DURATION);
|
|
201
|
+
case "motionPath":
|
|
202
|
+
return start + (tl.duration ?? DEFAULT_MOTIONPATH_DURATION);
|
|
203
|
+
case "to": {
|
|
204
|
+
const override = ir.states?.[tl.state] ?? {};
|
|
205
|
+
const duration = tl.duration ?? DEFAULT_TO_DURATION;
|
|
206
|
+
const si = tl.stagger ?? 0;
|
|
207
|
+
const targets = nodeOrder.filter(
|
|
208
|
+
(id) => id in override && (tl.filter === void 0 || tl.filter.includes(id))
|
|
209
|
+
);
|
|
210
|
+
return start + duration + Math.max(0, targets.length - 1) * si;
|
|
211
|
+
}
|
|
212
|
+
case "beat": {
|
|
213
|
+
const grouping = { kind: tl.parallel ? "par" : "seq", children: tl.children };
|
|
214
|
+
const natural = durationOf(grouping, 0);
|
|
215
|
+
const k = tl.scale ?? (tl.duration !== void 0 ? tl.duration / Math.max(1e-9, natural) : 1);
|
|
216
|
+
const beatStart = tl.at ?? start + (tl.gap ?? 0);
|
|
217
|
+
return beatStart + k * natural;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const walk = (tl, start) => {
|
|
222
|
+
const end = walkInner(tl, start);
|
|
223
|
+
if ("label" in tl && tl.label !== void 0) labelTimes.set(tl.label, { t0: start, t1: end });
|
|
224
|
+
return end;
|
|
225
|
+
};
|
|
226
|
+
const walkInner = (tl, start) => {
|
|
227
|
+
switch (tl.kind) {
|
|
228
|
+
case "seq": {
|
|
229
|
+
let t = start;
|
|
230
|
+
for (const child of orderBeats(tl.children)) t = walk(child, t);
|
|
231
|
+
return t;
|
|
232
|
+
}
|
|
233
|
+
case "beat": {
|
|
234
|
+
const grouping = { kind: tl.parallel ? "par" : "seq", children: tl.children };
|
|
235
|
+
const k = tl.scale ?? (tl.duration !== void 0 ? tl.duration / Math.max(1e-9, durationOf(grouping, 0)) : 1);
|
|
236
|
+
const inner = k === 1 ? grouping : scaleTimeline(grouping, k);
|
|
237
|
+
const beatStart = tl.at ?? start + (tl.gap ?? 0);
|
|
238
|
+
const end = walk(inner, beatStart);
|
|
239
|
+
beatTimes.set(tl.name, { t0: beatStart, t1: end });
|
|
240
|
+
labelTimes.set(tl.name, { t0: beatStart, t1: end });
|
|
241
|
+
return end;
|
|
242
|
+
}
|
|
243
|
+
case "par": {
|
|
244
|
+
let end = start;
|
|
245
|
+
for (const child of tl.children) end = Math.max(end, walk(child, start));
|
|
246
|
+
return end;
|
|
247
|
+
}
|
|
248
|
+
case "stagger": {
|
|
249
|
+
let end = start;
|
|
250
|
+
tl.children.forEach((child, i) => {
|
|
251
|
+
end = Math.max(end, walk(child, start + i * tl.interval));
|
|
252
|
+
});
|
|
253
|
+
return end;
|
|
254
|
+
}
|
|
255
|
+
case "wait":
|
|
256
|
+
return start + tl.duration;
|
|
257
|
+
case "tween": {
|
|
258
|
+
const duration = tl.duration ?? DEFAULT_TWEEN_DURATION;
|
|
259
|
+
for (const [prop, toValue] of Object.entries(tl.props)) {
|
|
260
|
+
pushSegment({
|
|
261
|
+
target: tl.target,
|
|
262
|
+
prop,
|
|
263
|
+
t0: start,
|
|
264
|
+
t1: start + duration,
|
|
265
|
+
from: currentValue(tl.target, prop),
|
|
266
|
+
to: toValue,
|
|
267
|
+
...tl.ease !== void 0 && { ease: tl.ease }
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return start + duration;
|
|
271
|
+
}
|
|
272
|
+
case "motionPath": {
|
|
273
|
+
const duration = tl.duration ?? DEFAULT_MOTIONPATH_DURATION;
|
|
274
|
+
const points = tl.points;
|
|
275
|
+
const closed = tl.closed ?? false;
|
|
276
|
+
const curviness = tl.curviness ?? 1;
|
|
277
|
+
const autoRotate = tl.autoRotate ?? false;
|
|
278
|
+
const rotateOffset = tl.rotateOffset ?? 0;
|
|
279
|
+
let list = motionPaths.get(tl.target);
|
|
280
|
+
if (!list) motionPaths.set(tl.target, list = []);
|
|
281
|
+
list.push({ t0: start, t1: start + duration, points, closed, curviness, autoRotate, rotateOffset, ...tl.ease !== void 0 && { ease: tl.ease } });
|
|
282
|
+
if (points.length > 0) {
|
|
283
|
+
const [ex, ey] = pathPoint(points, closed, 1, curviness);
|
|
284
|
+
current.set(key(tl.target, "x"), ex);
|
|
285
|
+
current.set(key(tl.target, "y"), ey);
|
|
286
|
+
if (autoRotate) current.set(key(tl.target, "rotation"), pathTangentAngle(points, closed, 1, curviness) + rotateOffset);
|
|
287
|
+
}
|
|
288
|
+
return start + duration;
|
|
289
|
+
}
|
|
290
|
+
case "to": {
|
|
291
|
+
const override = ir.states?.[tl.state] ?? {};
|
|
292
|
+
const duration = tl.duration ?? DEFAULT_TO_DURATION;
|
|
293
|
+
const staggerInterval = tl.stagger ?? 0;
|
|
294
|
+
const targets = nodeOrder.filter(
|
|
295
|
+
(id) => id in override && (tl.filter === void 0 || tl.filter.includes(id))
|
|
296
|
+
);
|
|
297
|
+
targets.forEach((id, i) => {
|
|
298
|
+
const t0 = start + i * staggerInterval;
|
|
299
|
+
for (const [prop, toValue] of Object.entries(override[id])) {
|
|
300
|
+
pushSegment({
|
|
301
|
+
target: id,
|
|
302
|
+
prop,
|
|
303
|
+
t0,
|
|
304
|
+
t1: t0 + duration,
|
|
305
|
+
from: currentValue(id, prop),
|
|
306
|
+
to: toValue,
|
|
307
|
+
...tl.ease !== void 0 && { ease: tl.ease }
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
const last = Math.max(0, targets.length - 1);
|
|
312
|
+
return start + duration + last * staggerInterval;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const inferredEnd = (ir.timeline ? walk(ir.timeline, 0) : 0) || 0;
|
|
317
|
+
for (const list of segments.values()) list.sort((a, b) => a.t0 - b.t0);
|
|
318
|
+
for (const list of motionPaths.values()) list.sort((a, b) => a.t0 - b.t0);
|
|
319
|
+
const hasCamera = !cameraIsNode && (ir.camera !== void 0 || motionPaths.has("camera") || [...segments.keys()].some((k) => k.startsWith("camera.")));
|
|
320
|
+
const hasPerspective = !cameraIsNode && (ir.camera?.perspective !== void 0 || segments.has("camera.perspective"));
|
|
321
|
+
return {
|
|
322
|
+
ir,
|
|
323
|
+
duration: ir.duration ?? (inferredEnd > 0 ? inferredEnd : DEFAULT_STILL_DURATION),
|
|
324
|
+
segments,
|
|
325
|
+
motionPaths,
|
|
326
|
+
initialValues,
|
|
327
|
+
nodeById,
|
|
328
|
+
nodeOrder,
|
|
329
|
+
labelTimes,
|
|
330
|
+
beatTimes,
|
|
331
|
+
hasCamera,
|
|
332
|
+
hasPerspective
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ../core/src/validate.ts
|
|
337
|
+
var FX_PROPS = ["blur", "shadowColor", "shadowBlur", "shadowX", "shadowY", "blend"];
|
|
338
|
+
var BLEND_MODES = /* @__PURE__ */ new Set([
|
|
339
|
+
"normal",
|
|
340
|
+
"multiply",
|
|
341
|
+
"screen",
|
|
342
|
+
"overlay",
|
|
343
|
+
"lighten",
|
|
344
|
+
"darken",
|
|
345
|
+
"add",
|
|
346
|
+
"color-dodge",
|
|
347
|
+
"soft-light",
|
|
348
|
+
"hard-light",
|
|
349
|
+
"difference"
|
|
350
|
+
]);
|
|
351
|
+
var IMAGE_FITS = /* @__PURE__ */ new Set(["fill", "cover"]);
|
|
352
|
+
var COMMON_PROPS = ["x", "y", "opacity", "rotation", "scale", "scaleX", "scaleY", "skewX", "skewY", "z", "rotateX", "rotateY", "anchor", "fixed", ...FX_PROPS];
|
|
353
|
+
var CAMERA_PROPS = ["x", "y", "zoom", "rotation", "perspective"];
|
|
354
|
+
var PROPS_BY_TYPE = {
|
|
355
|
+
rect: [...COMMON_PROPS, "width", "height", "fill", "stroke", "strokeWidth", "radius"],
|
|
356
|
+
ellipse: [...COMMON_PROPS, "width", "height", "fill", "stroke", "strokeWidth"],
|
|
357
|
+
line: ["x1", "y1", "x2", "y2", "stroke", "strokeWidth", "opacity", "progress", ...FX_PROPS],
|
|
358
|
+
text: [...COMMON_PROPS, "content", "contentDecimals", "contentThousands", "prefix", "suffix", "fontFamily", "fontSize", "fontWeight", "fill", "letterSpacing"],
|
|
359
|
+
image: [...COMMON_PROPS, "src", "width", "height", "fit"],
|
|
360
|
+
video: [...COMMON_PROPS, "src", "width", "height", "fit", "start", "rate", "clipStart", "volume"],
|
|
361
|
+
path: [...COMMON_PROPS, "d", "fill", "stroke", "strokeWidth", "progress", "originX", "originY"],
|
|
362
|
+
group: COMMON_PROPS
|
|
363
|
+
};
|
|
364
|
+
var SceneValidationError = class extends Error {
|
|
365
|
+
constructor(problems) {
|
|
366
|
+
super(`Scene validation failed:
|
|
367
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
368
|
+
this.problems = problems;
|
|
369
|
+
this.name = "SceneValidationError";
|
|
370
|
+
}
|
|
371
|
+
problems;
|
|
372
|
+
};
|
|
373
|
+
function validateScene(ir) {
|
|
374
|
+
const problems = [];
|
|
375
|
+
const nodeById = /* @__PURE__ */ new Map();
|
|
376
|
+
const checkPaint = (where, value) => {
|
|
377
|
+
if (typeof value !== "object" || value === null) return;
|
|
378
|
+
const g = value;
|
|
379
|
+
if (g.kind !== "linear" && g.kind !== "radial" && g.kind !== "conic") {
|
|
380
|
+
problems.push(`${where}: a paint object must be a gradient with kind "linear" / "radial" / "conic"`);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (!Array.isArray(g.stops) || g.stops.length === 0) {
|
|
384
|
+
problems.push(`${where}: gradient "${g.kind}" needs at least one color stop`);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
g.stops.forEach((s, i) => {
|
|
388
|
+
const st = s;
|
|
389
|
+
if (typeof st?.color !== "string") problems.push(`${where}: gradient stop ${i} needs a color string`);
|
|
390
|
+
if (typeof st?.offset !== "number" || st.offset < 0 || st.offset > 1) {
|
|
391
|
+
problems.push(`${where}: gradient stop ${i} "offset" must be a number in 0..1`);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
};
|
|
395
|
+
const collect = (nodes) => {
|
|
396
|
+
for (const node of nodes) {
|
|
397
|
+
if (nodeById.has(node.id)) {
|
|
398
|
+
problems.push(`duplicate node id "${node.id}" \u2014 every node id must be unique`);
|
|
399
|
+
}
|
|
400
|
+
nodeById.set(node.id, node);
|
|
401
|
+
const props = node.props;
|
|
402
|
+
checkPaint(`node "${node.id}" fill`, props.fill);
|
|
403
|
+
checkPaint(`node "${node.id}" stroke`, props.stroke);
|
|
404
|
+
if (typeof props.blur === "number" && props.blur < 0) problems.push(`node "${node.id}": blur must be >= 0`);
|
|
405
|
+
if (typeof props.shadowBlur === "number" && props.shadowBlur < 0) problems.push(`node "${node.id}": shadowBlur must be >= 0`);
|
|
406
|
+
if (typeof props.blend === "string" && !BLEND_MODES.has(props.blend)) problems.push(`node "${node.id}": unknown blend "${props.blend}" \u2014 use ${[...BLEND_MODES].join(", ")}`);
|
|
407
|
+
if (typeof props.fit === "string" && !IMAGE_FITS.has(props.fit)) problems.push(`node "${node.id}": unknown fit "${props.fit}" \u2014 use ${[...IMAGE_FITS].join(", ")}`);
|
|
408
|
+
if (node.type === "group") {
|
|
409
|
+
const clip = node.props.clip;
|
|
410
|
+
if (clip) {
|
|
411
|
+
if (clip.kind !== "rect" && clip.kind !== "ellipse") {
|
|
412
|
+
problems.push(`group "${node.id}" clip: unknown kind "${clip.kind}" \u2014 use "rect" or "ellipse"`);
|
|
413
|
+
}
|
|
414
|
+
if (!(clip.width > 0) || !(clip.height > 0)) {
|
|
415
|
+
problems.push(`group "${node.id}" clip: width and height must be > 0`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const matte = node.props.matte;
|
|
419
|
+
if (matte !== void 0) {
|
|
420
|
+
if (matte !== "alpha" && matte !== "luma") {
|
|
421
|
+
problems.push(`group "${node.id}" matte: unknown mode "${String(matte)}" \u2014 use "alpha" or "luma"`);
|
|
422
|
+
} else if (node.children.length < 2) {
|
|
423
|
+
problems.push(`group "${node.id}" matte: needs \u22652 children (first masks the rest)`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
collect(node.children);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
collect(ir.nodes);
|
|
431
|
+
const checkProps = (where, nodeId, props) => {
|
|
432
|
+
if (nodeId === "camera" && !nodeById.has("camera")) {
|
|
433
|
+
for (const key2 of Object.keys(props)) {
|
|
434
|
+
if (!CAMERA_PROPS.includes(key2)) {
|
|
435
|
+
problems.push(`${where}: "${key2}" is not a camera prop \u2014 valid props: ${CAMERA_PROPS.join(", ")}`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const node = nodeById.get(nodeId);
|
|
441
|
+
if (!node) {
|
|
442
|
+
problems.push(
|
|
443
|
+
`${where} targets unknown node "${nodeId}" \u2014 known ids: ${[...nodeById.keys()].join(", ")}`
|
|
444
|
+
);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const allowed = PROPS_BY_TYPE[node.type];
|
|
448
|
+
for (const key2 of Object.keys(props)) {
|
|
449
|
+
if (!allowed.includes(key2)) {
|
|
450
|
+
problems.push(
|
|
451
|
+
`${where}: "${key2}" is not a prop of ${node.type} "${nodeId}" \u2014 valid props: ${allowed.join(", ")}`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const states = ir.states ?? {};
|
|
457
|
+
for (const [stateName, overrides] of Object.entries(states)) {
|
|
458
|
+
for (const [nodeId, props] of Object.entries(overrides)) {
|
|
459
|
+
checkProps(`state "${stateName}"`, nodeId, props);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (ir.initial !== void 0 && !(ir.initial in states)) {
|
|
463
|
+
problems.push(
|
|
464
|
+
`initial state "${ir.initial}" is not defined \u2014 defined states: ${Object.keys(states).join(", ") || "(none)"}`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
const labels = /* @__PURE__ */ new Set();
|
|
468
|
+
const checkTimeline = (tl, path2) => {
|
|
469
|
+
if ("label" in tl && tl.label !== void 0) {
|
|
470
|
+
if (labels.has(tl.label)) {
|
|
471
|
+
problems.push(
|
|
472
|
+
`${path2}: duplicate timeline label "${tl.label}" \u2014 labels are overlay addresses and must be unique`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
labels.add(tl.label);
|
|
476
|
+
}
|
|
477
|
+
switch (tl.kind) {
|
|
478
|
+
case "seq":
|
|
479
|
+
case "par":
|
|
480
|
+
tl.children.forEach((c, i) => checkTimeline(c, `${path2}.${tl.kind}[${i}]`));
|
|
481
|
+
break;
|
|
482
|
+
case "stagger":
|
|
483
|
+
if (tl.interval < 0) problems.push(`${path2}: stagger interval must be >= 0`);
|
|
484
|
+
tl.children.forEach((c, i) => checkTimeline(c, `${path2}.stagger[${i}]`));
|
|
485
|
+
break;
|
|
486
|
+
case "to":
|
|
487
|
+
if (!(tl.state in states)) {
|
|
488
|
+
problems.push(
|
|
489
|
+
`${path2}: to("${tl.state}") references an undefined state \u2014 defined states: ${Object.keys(states).join(", ") || "(none)"}`
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
493
|
+
problems.push(`${path2}: to("${tl.state}") duration must be > 0`);
|
|
494
|
+
}
|
|
495
|
+
for (const id of tl.filter ?? []) {
|
|
496
|
+
if (!nodeById.has(id)) problems.push(`${path2}: filter contains unknown node "${id}"`);
|
|
497
|
+
}
|
|
498
|
+
break;
|
|
499
|
+
case "tween":
|
|
500
|
+
checkProps(path2, tl.target, tl.props);
|
|
501
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
502
|
+
problems.push(`${path2}: tween duration must be > 0`);
|
|
503
|
+
}
|
|
504
|
+
break;
|
|
505
|
+
case "motionPath": {
|
|
506
|
+
const node = nodeById.get(tl.target);
|
|
507
|
+
const isSceneCamera = tl.target === "camera" && !node;
|
|
508
|
+
if (!isSceneCamera) {
|
|
509
|
+
if (!node) {
|
|
510
|
+
problems.push(
|
|
511
|
+
`${path2}: motionPath targets unknown node "${tl.target}" \u2014 known ids: ${[...nodeById.keys()].join(", ")}`
|
|
512
|
+
);
|
|
513
|
+
} else if (node.type === "line") {
|
|
514
|
+
problems.push(`${path2}: motionPath cannot target a line (no x/y) \u2014 "${tl.target}"`);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (tl.points.length < 1) problems.push(`${path2}: motionPath "${tl.target}" needs at least 1 point`);
|
|
518
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
519
|
+
problems.push(`${path2}: motionPath "${tl.target}" duration must be > 0`);
|
|
520
|
+
}
|
|
521
|
+
if (tl.curviness !== void 0 && tl.curviness < 0) {
|
|
522
|
+
problems.push(`${path2}: motionPath "${tl.target}" curviness must be >= 0`);
|
|
523
|
+
}
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
case "wait":
|
|
527
|
+
if (tl.duration < 0) problems.push(`${path2}: wait duration must be >= 0`);
|
|
528
|
+
break;
|
|
529
|
+
case "beat":
|
|
530
|
+
if (labels.has(tl.name)) {
|
|
531
|
+
problems.push(
|
|
532
|
+
`${path2}: duplicate timeline label "${tl.name}" (beat name) \u2014 labels are overlay addresses and must be unique`
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
labels.add(tl.name);
|
|
536
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
537
|
+
problems.push(`${path2}: beat "${tl.name}" duration must be > 0`);
|
|
538
|
+
}
|
|
539
|
+
if (tl.scale !== void 0 && tl.scale <= 0) {
|
|
540
|
+
problems.push(`${path2}: beat "${tl.name}" scale must be > 0`);
|
|
541
|
+
}
|
|
542
|
+
for (const id of tl.nodes ?? []) {
|
|
543
|
+
if (!nodeById.has(id)) {
|
|
544
|
+
problems.push(
|
|
545
|
+
`${path2}: beat "${tl.name}" owns unknown node "${id}" \u2014 known ids: ${[...nodeById.keys()].join(", ")}`
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
tl.children.forEach((c, i) => checkTimeline(c, `${path2}.beat(${tl.name})[${i}]`));
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
if (ir.timeline) checkTimeline(ir.timeline, "timeline");
|
|
554
|
+
for (const [i, b] of (ir.behaviors ?? []).entries()) {
|
|
555
|
+
checkProps(`behaviors[${i}]`, b.target, { [b.prop]: 0 });
|
|
556
|
+
}
|
|
557
|
+
if (ir.duration !== void 0 && ir.duration <= 0) {
|
|
558
|
+
problems.push("scene duration must be > 0");
|
|
559
|
+
}
|
|
560
|
+
if (ir.camera) {
|
|
561
|
+
if (nodeById.has("camera")) {
|
|
562
|
+
problems.push(`camera: a node is already named "camera" \u2014 rename that node or drop the scene camera (the id "camera" can't be both)`);
|
|
563
|
+
}
|
|
564
|
+
for (const [key2, value] of Object.entries(ir.camera)) {
|
|
565
|
+
if (!CAMERA_PROPS.includes(key2)) {
|
|
566
|
+
problems.push(`camera: "${key2}" is not a camera prop \u2014 valid props: ${CAMERA_PROPS.join(", ")}`);
|
|
567
|
+
} else if (typeof value !== "number") {
|
|
568
|
+
problems.push(`camera.${key2} must be a number`);
|
|
569
|
+
} else if (key2 === "perspective" && value <= 0) {
|
|
570
|
+
problems.push(`camera.perspective must be > 0 (focal distance in px) \u2014 drop it to disable perspective`);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const SFX_NAMES = ["whoosh", "pop", "tick", "rise", "shimmer", "thud"];
|
|
575
|
+
for (const [i, cue] of (ir.audio?.cues ?? []).entries()) {
|
|
576
|
+
if (typeof cue.at === "string" && !labels.has(cue.at)) {
|
|
577
|
+
problems.push(
|
|
578
|
+
`audio.cues[${i}]: unknown timeline label "${cue.at}" \u2014 known labels: ${[...labels].join(", ") || "(none)"}`
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
if (typeof cue.at === "number" && cue.at < 0) {
|
|
582
|
+
problems.push(`audio.cues[${i}]: "at" must be >= 0`);
|
|
583
|
+
}
|
|
584
|
+
if (cue.sfx === void 0 === (cue.file === void 0)) {
|
|
585
|
+
problems.push(`audio.cues[${i}]: exactly one of "sfx" or "file" is required`);
|
|
586
|
+
}
|
|
587
|
+
if (cue.sfx !== void 0 && !SFX_NAMES.includes(cue.sfx)) {
|
|
588
|
+
problems.push(`audio.cues[${i}]: unknown sfx "${cue.sfx}" \u2014 valid: ${SFX_NAMES.join(", ")}`);
|
|
589
|
+
}
|
|
590
|
+
if (cue.gain !== void 0 && cue.gain < 0) {
|
|
591
|
+
problems.push(`audio.cues[${i}]: gain must be >= 0`);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const duck = ir.audio?.bgm?.duck;
|
|
595
|
+
if (typeof duck === "object" && duck !== null && duck.depth !== void 0 && (duck.depth < 0 || duck.depth > 1)) {
|
|
596
|
+
problems.push("audio.bgm.duck.depth must be in [0, 1]");
|
|
597
|
+
}
|
|
598
|
+
if (ir.audio?.bgm?.file !== void 0 && ir.audio.bgm.synth !== void 0) {
|
|
599
|
+
problems.push('audio.bgm: use either "file" or "synth", not both');
|
|
600
|
+
}
|
|
601
|
+
if (problems.length > 0) throw new SceneValidationError(problems);
|
|
602
|
+
}
|
|
603
|
+
var TRANSITIONS = ["cut", "crossfade"];
|
|
604
|
+
function validateComposition(comp) {
|
|
605
|
+
const problems = [];
|
|
606
|
+
if (comp.scenes.length === 0) problems.push("composition has no scenes");
|
|
607
|
+
const seen = /* @__PURE__ */ new Set();
|
|
608
|
+
for (const [i, entry] of comp.scenes.entries()) {
|
|
609
|
+
const where = `scenes[${i}]`;
|
|
610
|
+
try {
|
|
611
|
+
validateScene(entry.scene);
|
|
612
|
+
} catch (err) {
|
|
613
|
+
if (err instanceof SceneValidationError) {
|
|
614
|
+
for (const p of err.problems) problems.push(`${where} (scene "${entry.scene.id}"): ${p}`);
|
|
615
|
+
} else throw err;
|
|
616
|
+
}
|
|
617
|
+
if (seen.has(entry.scene.id)) {
|
|
618
|
+
problems.push(`${where}: duplicate scene id "${entry.scene.id}" \u2014 scene ids must be unique in a composition`);
|
|
619
|
+
}
|
|
620
|
+
seen.add(entry.scene.id);
|
|
621
|
+
if (entry.transition !== void 0 && !TRANSITIONS.includes(entry.transition)) {
|
|
622
|
+
problems.push(`${where}: unknown transition "${entry.transition}" \u2014 valid: ${TRANSITIONS.join(", ")}`);
|
|
623
|
+
}
|
|
624
|
+
if (typeof entry.at === "string" && Number.isNaN(Number(entry.at))) {
|
|
625
|
+
problems.push(`${where}: "at" string "${entry.at}" is not a number (use "-0.5"/"+0.5" or a number)`);
|
|
626
|
+
}
|
|
627
|
+
if (typeof entry.at === "number" && entry.at < 0) {
|
|
628
|
+
problems.push(`${where}: absolute "at" must be >= 0`);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (problems.length > 0) throw new SceneValidationError(problems);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// ../core/src/presets.ts
|
|
635
|
+
var SET = 1 / 120;
|
|
636
|
+
|
|
637
|
+
// ../core/src/interpolate.ts
|
|
638
|
+
var BACK_C1 = 1.70158;
|
|
639
|
+
var BACK_C2 = BACK_C1 * 1.525;
|
|
640
|
+
var BACK_C3 = BACK_C1 + 1;
|
|
641
|
+
var ELASTIC_C4 = 2 * Math.PI / 3;
|
|
642
|
+
var ELASTIC_C5 = 2 * Math.PI / 4.5;
|
|
643
|
+
function easeOutBounce(u) {
|
|
644
|
+
const n1 = 7.5625;
|
|
645
|
+
const d1 = 2.75;
|
|
646
|
+
if (u < 1 / d1) return n1 * u * u;
|
|
647
|
+
if (u < 2 / d1) return n1 * (u -= 1.5 / d1) * u + 0.75;
|
|
648
|
+
if (u < 2.5 / d1) return n1 * (u -= 2.25 / d1) * u + 0.9375;
|
|
649
|
+
return n1 * (u -= 2.625 / d1) * u + 0.984375;
|
|
650
|
+
}
|
|
651
|
+
var EASE_TABLE = {
|
|
652
|
+
linear: (u) => u,
|
|
653
|
+
easeInQuad: (u) => u * u,
|
|
654
|
+
easeOutQuad: (u) => 1 - (1 - u) * (1 - u),
|
|
655
|
+
easeInOutQuad: (u) => u < 0.5 ? 2 * u * u : 1 - (-2 * u + 2) ** 2 / 2,
|
|
656
|
+
easeInCubic: (u) => u ** 3,
|
|
657
|
+
easeOutCubic: (u) => 1 - (1 - u) ** 3,
|
|
658
|
+
easeInOutCubic: (u) => u < 0.5 ? 4 * u ** 3 : 1 - (-2 * u + 2) ** 3 / 2,
|
|
659
|
+
easeInQuart: (u) => u ** 4,
|
|
660
|
+
easeOutQuart: (u) => 1 - (1 - u) ** 4,
|
|
661
|
+
easeInOutQuart: (u) => u < 0.5 ? 8 * u ** 4 : 1 - (-2 * u + 2) ** 4 / 2,
|
|
662
|
+
easeInExpo: (u) => u === 0 ? 0 : 2 ** (10 * u - 10),
|
|
663
|
+
easeOutExpo: (u) => u === 1 ? 1 : 1 - 2 ** (-10 * u),
|
|
664
|
+
easeInOutExpo: (u) => u === 0 ? 0 : u === 1 ? 1 : u < 0.5 ? 2 ** (20 * u - 10) / 2 : (2 - 2 ** (-20 * u + 10)) / 2,
|
|
665
|
+
// --- expressive eases (GSAP's signature feel) — standard Penner equations ---
|
|
666
|
+
// back: overshoots past the target then settles (pop / snap)
|
|
667
|
+
easeInBack: (u) => BACK_C3 * u ** 3 - BACK_C1 * u * u,
|
|
668
|
+
easeOutBack: (u) => 1 + BACK_C3 * (u - 1) ** 3 + BACK_C1 * (u - 1) ** 2,
|
|
669
|
+
easeInOutBack: (u) => u < 0.5 ? (2 * u) ** 2 * ((BACK_C2 + 1) * 2 * u - BACK_C2) / 2 : ((2 * u - 2) ** 2 * ((BACK_C2 + 1) * (2 * u - 2) + BACK_C2) + 2) / 2,
|
|
670
|
+
// elastic: rings around the target before settling (playful spring)
|
|
671
|
+
easeInElastic: (u) => u === 0 ? 0 : u === 1 ? 1 : -(2 ** (10 * u - 10)) * Math.sin((u * 10 - 10.75) * ELASTIC_C4),
|
|
672
|
+
easeOutElastic: (u) => u === 0 ? 0 : u === 1 ? 1 : 2 ** (-10 * u) * Math.sin((u * 10 - 0.75) * ELASTIC_C4) + 1,
|
|
673
|
+
easeInOutElastic: (u) => u === 0 ? 0 : u === 1 ? 1 : u < 0.5 ? -(2 ** (20 * u - 10) * Math.sin((20 * u - 11.125) * ELASTIC_C5)) / 2 : 2 ** (-20 * u + 10) * Math.sin((20 * u - 11.125) * ELASTIC_C5) / 2 + 1,
|
|
674
|
+
// bounce: drops and bounces to rest (lands without overshoot)
|
|
675
|
+
easeInBounce: (u) => 1 - easeOutBounce(1 - u),
|
|
676
|
+
easeOutBounce,
|
|
677
|
+
easeInOutBounce: (u) => u < 0.5 ? (1 - easeOutBounce(1 - 2 * u)) / 2 : (1 + easeOutBounce(2 * u - 1)) / 2
|
|
678
|
+
};
|
|
679
|
+
var EASE_NAMES = Object.keys(EASE_TABLE);
|
|
680
|
+
|
|
681
|
+
// ../core/src/evaluate.ts
|
|
682
|
+
var DEG = Math.PI / 180;
|
|
683
|
+
|
|
684
|
+
// ../core/src/assets.ts
|
|
685
|
+
function collectSrcs(ir, type) {
|
|
686
|
+
const srcs = /* @__PURE__ */ new Set();
|
|
687
|
+
const ids = /* @__PURE__ */ new Set();
|
|
688
|
+
const walkNodes = (nodes) => {
|
|
689
|
+
for (const node of nodes) {
|
|
690
|
+
if (node.type === type) {
|
|
691
|
+
ids.add(node.id);
|
|
692
|
+
srcs.add(node.props.src);
|
|
693
|
+
}
|
|
694
|
+
if (node.type === "group") walkNodes(node.children);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
walkNodes(ir.nodes);
|
|
698
|
+
for (const overrides of Object.values(ir.states ?? {})) {
|
|
699
|
+
for (const [nodeId, props] of Object.entries(overrides)) {
|
|
700
|
+
if (ids.has(nodeId) && typeof props.src === "string") srcs.add(props.src);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const walkTimeline = (step) => {
|
|
704
|
+
if (!step) return;
|
|
705
|
+
if (step.kind === "seq" || step.kind === "par" || step.kind === "stagger") {
|
|
706
|
+
for (const child of step.children) walkTimeline(child);
|
|
707
|
+
} else if (step.kind === "tween" && ids.has(step.target)) {
|
|
708
|
+
const src = step.props.src;
|
|
709
|
+
if (typeof src === "string") srcs.add(src);
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
walkTimeline(ir.timeline);
|
|
713
|
+
return [...srcs];
|
|
714
|
+
}
|
|
715
|
+
function collectImageSrcs(ir) {
|
|
716
|
+
return collectSrcs(ir, "image");
|
|
717
|
+
}
|
|
718
|
+
function collectVideoSrcs(ir) {
|
|
719
|
+
return collectSrcs(ir, "video");
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// ../render-cli/src/loadScene.ts
|
|
723
|
+
var HERE = dirname(fileURLToPath(import.meta.url));
|
|
724
|
+
var CORE_ENTRY = true ? resolve(HERE, "index.js") : resolve(HERE, "..", "..", "core", "src", "index.ts");
|
|
725
|
+
async function loadDefault(path2) {
|
|
726
|
+
if (path2.endsWith(".json")) return JSON.parse(await readFile(path2, "utf8"));
|
|
727
|
+
let code;
|
|
728
|
+
try {
|
|
729
|
+
const out = await build({
|
|
730
|
+
entryPoints: [path2],
|
|
731
|
+
bundle: true,
|
|
732
|
+
format: "esm",
|
|
733
|
+
platform: "neutral",
|
|
734
|
+
write: false,
|
|
735
|
+
logLevel: "silent",
|
|
736
|
+
sourcemap: "inline",
|
|
737
|
+
// both specifiers accepted: the guide's canonical "@reframe/core" and
|
|
738
|
+
// the published package name
|
|
739
|
+
alias: { "@reframe/core": CORE_ENTRY, "reframe-video": CORE_ENTRY }
|
|
740
|
+
});
|
|
741
|
+
code = out.outputFiles[0].text;
|
|
742
|
+
} catch (err) {
|
|
743
|
+
throw new Error(`failed to bundle ${path2}:
|
|
744
|
+
${err instanceof Error ? err.message : String(err)}`);
|
|
745
|
+
}
|
|
746
|
+
const mod = await import(`data:text/javascript;base64,${Buffer.from(code).toString("base64")}`);
|
|
747
|
+
if (mod.default === void 0) throw new Error(`${path2} must default-export a scene or composition`);
|
|
748
|
+
return mod.default;
|
|
749
|
+
}
|
|
750
|
+
function isComposition(def) {
|
|
751
|
+
return typeof def === "object" && def !== null && Array.isArray(def.scenes);
|
|
752
|
+
}
|
|
753
|
+
async function loadModule(path2) {
|
|
754
|
+
const def = await loadDefault(path2);
|
|
755
|
+
if (isComposition(def)) {
|
|
756
|
+
validateComposition(def);
|
|
757
|
+
return { kind: "composition", ir: def };
|
|
758
|
+
}
|
|
759
|
+
validateScene(def);
|
|
760
|
+
return { kind: "scene", ir: def };
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// ../render-cli/src/frameLoop.ts
|
|
764
|
+
import { join as join3, dirname as dirname3 } from "node:path";
|
|
765
|
+
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
766
|
+
import { build as build2 } from "esbuild";
|
|
767
|
+
import { chromium } from "playwright";
|
|
768
|
+
|
|
769
|
+
// ../render-cli/src/fonts.ts
|
|
770
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
771
|
+
import { dirname as dirname2, join } from "node:path";
|
|
772
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
773
|
+
var FONTS_DIR = true ? join(dirname2(fileURLToPath2(import.meta.url)), "..", "assets", "fonts") : join(dirname2(fileURLToPath2(import.meta.url)), "..", "..", "..", "assets", "fonts");
|
|
774
|
+
var WEIGHTS = [400, 700, 800];
|
|
775
|
+
var cssCache = null;
|
|
776
|
+
async function fontFaceCss() {
|
|
777
|
+
if (cssCache) return cssCache;
|
|
778
|
+
const rules = await Promise.all(
|
|
779
|
+
WEIGHTS.map(async (weight) => {
|
|
780
|
+
const data = await readFile2(join(FONTS_DIR, `inter-${weight}.woff2`));
|
|
781
|
+
return `@font-face {
|
|
782
|
+
font-family: "Inter";
|
|
783
|
+
font-style: normal;
|
|
784
|
+
font-weight: ${weight};
|
|
785
|
+
src: url(data:font/woff2;base64,${data.toString("base64")}) format("woff2");
|
|
786
|
+
}`;
|
|
787
|
+
})
|
|
788
|
+
);
|
|
789
|
+
cssCache = rules.join("\n");
|
|
790
|
+
return cssCache;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// ../render-cli/src/images.ts
|
|
794
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
795
|
+
import { existsSync } from "node:fs";
|
|
796
|
+
import { extname, isAbsolute, resolve as resolve2 } from "node:path";
|
|
797
|
+
var MIME = {
|
|
798
|
+
".png": "image/png",
|
|
799
|
+
".jpg": "image/jpeg",
|
|
800
|
+
".jpeg": "image/jpeg",
|
|
801
|
+
".webp": "image/webp"
|
|
802
|
+
};
|
|
803
|
+
async function buildImageAssets(ir, sceneDir) {
|
|
804
|
+
const assets = {};
|
|
805
|
+
for (const src of collectImageSrcs(ir)) {
|
|
806
|
+
const mime = MIME[extname(src).toLowerCase()];
|
|
807
|
+
if (!mime) {
|
|
808
|
+
throw new Error(
|
|
809
|
+
`image "${src}": unsupported format "${extname(src)}" \u2014 supported: ${Object.keys(MIME).join(" ")}`
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
const candidates = [isAbsolute(src) ? src : null, resolve2(sceneDir, src)].filter(
|
|
813
|
+
(c) => c !== null
|
|
814
|
+
);
|
|
815
|
+
const found = candidates.find((c) => existsSync(c));
|
|
816
|
+
if (!found) {
|
|
817
|
+
throw new Error(`image "${src}" not found (tried: ${candidates.join(", ")})`);
|
|
818
|
+
}
|
|
819
|
+
const data = await readFile3(found);
|
|
820
|
+
assets[src] = `data:${mime};base64,${data.toString("base64")}`;
|
|
821
|
+
}
|
|
822
|
+
return assets;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// ../render-cli/src/videos.ts
|
|
826
|
+
import { spawn } from "node:child_process";
|
|
827
|
+
import { mkdtemp, readFile as readFile4, readdir, rm } from "node:fs/promises";
|
|
828
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
829
|
+
import { tmpdir } from "node:os";
|
|
830
|
+
import { extname as extname2, isAbsolute as isAbsolute2, join as join2, resolve as resolve3 } from "node:path";
|
|
831
|
+
var VIDEO_EXT = /* @__PURE__ */ new Set([".mp4", ".mov", ".webm", ".m4v", ".mkv"]);
|
|
832
|
+
function runFfmpeg(args) {
|
|
833
|
+
return new Promise((resolve5, reject) => {
|
|
834
|
+
const proc = spawn("ffmpeg", args, { stdio: ["ignore", "ignore", "pipe"] });
|
|
835
|
+
let stderr = "";
|
|
836
|
+
proc.stderr.on("data", (d) => stderr += d.toString());
|
|
837
|
+
proc.on(
|
|
838
|
+
"close",
|
|
839
|
+
(code) => code === 0 ? resolve5() : reject(new Error(`ffmpeg exited ${code}:
|
|
840
|
+
${stderr.slice(-2e3)}`))
|
|
841
|
+
);
|
|
842
|
+
proc.on("error", reject);
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
function neededSeconds(node, duration) {
|
|
846
|
+
const start = node.props.start ?? 0;
|
|
847
|
+
const rate = node.props.rate ?? 1;
|
|
848
|
+
const clipStart = node.props.clipStart ?? 0;
|
|
849
|
+
return clipStart + Math.max(0, duration - start) * Math.max(0, rate) + 1 / 30;
|
|
850
|
+
}
|
|
851
|
+
function videoNodes(ir) {
|
|
852
|
+
const out = [];
|
|
853
|
+
const walk = (nodes) => {
|
|
854
|
+
for (const n of nodes) {
|
|
855
|
+
if (n.type === "video") out.push(n);
|
|
856
|
+
if (n.type === "group") walk(n.children);
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
walk(ir.nodes);
|
|
860
|
+
return out;
|
|
861
|
+
}
|
|
862
|
+
async function buildVideoFrameAssets(ir, sceneDir, fps, duration) {
|
|
863
|
+
const srcs = collectVideoSrcs(ir);
|
|
864
|
+
if (srcs.length === 0) return {};
|
|
865
|
+
const nodes = videoNodes(ir);
|
|
866
|
+
const reachBySrc = /* @__PURE__ */ new Map();
|
|
867
|
+
for (const n of nodes) {
|
|
868
|
+
const reach = neededSeconds(n, duration);
|
|
869
|
+
reachBySrc.set(n.props.src, Math.max(reachBySrc.get(n.props.src) ?? 0, reach));
|
|
870
|
+
}
|
|
871
|
+
const assets = {};
|
|
872
|
+
for (const src of srcs) {
|
|
873
|
+
if (!VIDEO_EXT.has(extname2(src).toLowerCase())) {
|
|
874
|
+
throw new Error(
|
|
875
|
+
`video "${src}": unsupported format "${extname2(src)}" \u2014 supported: ${[...VIDEO_EXT].join(" ")}`
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
const candidates = [isAbsolute2(src) ? src : null, resolve3(sceneDir, src)].filter(
|
|
879
|
+
(c) => c !== null
|
|
880
|
+
);
|
|
881
|
+
const found = candidates.find((c) => existsSync2(c));
|
|
882
|
+
if (!found) throw new Error(`video "${src}" not found (tried: ${candidates.join(", ")})`);
|
|
883
|
+
const dir = await mkdtemp(join2(tmpdir(), "reframe-vframes-"));
|
|
884
|
+
try {
|
|
885
|
+
const seconds = Math.max(1 / fps, reachBySrc.get(src) ?? duration);
|
|
886
|
+
await runFfmpeg([
|
|
887
|
+
"-y",
|
|
888
|
+
"-i",
|
|
889
|
+
found,
|
|
890
|
+
"-t",
|
|
891
|
+
seconds.toFixed(3),
|
|
892
|
+
"-vf",
|
|
893
|
+
`fps=${fps},scale='min(iw,1280)':-2`,
|
|
894
|
+
"-q:v",
|
|
895
|
+
"4",
|
|
896
|
+
join2(dir, "%05d.jpg")
|
|
897
|
+
]);
|
|
898
|
+
const files = (await readdir(dir)).filter((f) => f.endsWith(".jpg")).sort();
|
|
899
|
+
assets[src] = await Promise.all(
|
|
900
|
+
files.map(async (f) => `data:image/jpeg;base64,${(await readFile4(join2(dir, f))).toString("base64")}`)
|
|
901
|
+
);
|
|
902
|
+
if (assets[src].length === 0) throw new Error(`video "${src}": ffmpeg extracted no frames`);
|
|
903
|
+
} finally {
|
|
904
|
+
await rm(dir, { recursive: true, force: true });
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return assets;
|
|
908
|
+
}
|
|
909
|
+
function resolveTiming(ir, opts) {
|
|
910
|
+
const fps = opts.fps ?? ir.fps ?? 30;
|
|
911
|
+
const duration = opts.duration ?? compileScene(ir).duration;
|
|
912
|
+
return { fps, duration };
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// ../render-cli/src/vclock.ts
|
|
916
|
+
var VCLOCK_SOURCE = String.raw`
|
|
917
|
+
(() => {
|
|
918
|
+
let now = 0;
|
|
919
|
+
let nextId = 1;
|
|
920
|
+
let rafQueue = [];
|
|
921
|
+
const timers = [];
|
|
922
|
+
|
|
923
|
+
Date.now = () => now;
|
|
924
|
+
performance.now = () => now;
|
|
925
|
+
|
|
926
|
+
window.requestAnimationFrame = (cb) => {
|
|
927
|
+
const id = nextId++;
|
|
928
|
+
rafQueue.push({ id, cb });
|
|
929
|
+
return id;
|
|
930
|
+
};
|
|
931
|
+
window.cancelAnimationFrame = (id) => {
|
|
932
|
+
rafQueue = rafQueue.filter((r) => r.id !== id);
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
const addTimer = (cb, delay, args, interval) => {
|
|
936
|
+
const id = nextId++;
|
|
937
|
+
timers.push({
|
|
938
|
+
id,
|
|
939
|
+
cb: () => cb(...args),
|
|
940
|
+
due: now + Math.max(Number(delay) || 0, 0),
|
|
941
|
+
interval: interval ? Math.max(Number(delay) || 0, 1) : undefined,
|
|
942
|
+
});
|
|
943
|
+
return id;
|
|
944
|
+
};
|
|
945
|
+
const removeTimer = (id) => {
|
|
946
|
+
const i = timers.findIndex((t) => t.id === id);
|
|
947
|
+
if (i >= 0) timers.splice(i, 1);
|
|
948
|
+
};
|
|
949
|
+
window.setTimeout = (cb, delay = 0, ...args) =>
|
|
950
|
+
typeof cb === "function" ? addTimer(cb, delay, args, false) : 0;
|
|
951
|
+
window.setInterval = (cb, delay = 0, ...args) =>
|
|
952
|
+
typeof cb === "function" ? addTimer(cb, delay, args, true) : 0;
|
|
953
|
+
window.clearTimeout = removeTimer;
|
|
954
|
+
window.clearInterval = removeTimer;
|
|
955
|
+
|
|
956
|
+
window.__vclock = {
|
|
957
|
+
now: () => now,
|
|
958
|
+
advanceTo(targetMs) {
|
|
959
|
+
// Fire due timers in order, letting fired callbacks schedule new ones.
|
|
960
|
+
for (;;) {
|
|
961
|
+
timers.sort((a, b) => a.due - b.due);
|
|
962
|
+
const next = timers[0];
|
|
963
|
+
if (!next || next.due > targetMs) break;
|
|
964
|
+
now = next.due;
|
|
965
|
+
if (next.interval !== undefined) next.due += next.interval;
|
|
966
|
+
else timers.shift();
|
|
967
|
+
next.cb();
|
|
968
|
+
}
|
|
969
|
+
now = targetMs;
|
|
970
|
+
// One rAF batch per frame; callbacks registered during the batch run
|
|
971
|
+
// on the next advanceTo (matching real browser semantics).
|
|
972
|
+
const batch = rafQueue;
|
|
973
|
+
rafQueue = [];
|
|
974
|
+
for (const { cb } of batch) cb(now);
|
|
975
|
+
},
|
|
976
|
+
};
|
|
977
|
+
})();
|
|
978
|
+
`;
|
|
979
|
+
|
|
980
|
+
// ../render-cli/src/frameLoop.ts
|
|
981
|
+
async function injectFonts(page) {
|
|
982
|
+
await page.addStyleTag({ content: await fontFaceCss() });
|
|
983
|
+
await page.evaluate(async () => {
|
|
984
|
+
await Promise.all([...document.fonts].map((f) => f.load()));
|
|
985
|
+
await document.fonts.ready;
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
async function withPage(size, fn) {
|
|
989
|
+
const browser = await chromium.launch({
|
|
990
|
+
args: ["--force-color-profile=srgb", "--font-render-hinting=none"]
|
|
991
|
+
});
|
|
992
|
+
try {
|
|
993
|
+
const page = await browser.newPage({ viewport: size, deviceScaleFactor: 1 });
|
|
994
|
+
return await fn(page);
|
|
995
|
+
} finally {
|
|
996
|
+
await browser.close();
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
var bundleCache = null;
|
|
1000
|
+
async function browserBundle() {
|
|
1001
|
+
if (bundleCache) return bundleCache;
|
|
1002
|
+
if (true) {
|
|
1003
|
+
const { readFile: readFile6 } = await import("node:fs/promises");
|
|
1004
|
+
bundleCache = await readFile6(
|
|
1005
|
+
join3(dirname3(fileURLToPath3(import.meta.url)), "browserEntry.js"),
|
|
1006
|
+
"utf8"
|
|
1007
|
+
);
|
|
1008
|
+
return bundleCache;
|
|
1009
|
+
}
|
|
1010
|
+
const entry = join3(dirname3(fileURLToPath3(import.meta.url)), "browserEntry.ts");
|
|
1011
|
+
const result = await build2({
|
|
1012
|
+
entryPoints: [entry],
|
|
1013
|
+
bundle: true,
|
|
1014
|
+
write: false,
|
|
1015
|
+
format: "iife",
|
|
1016
|
+
target: "es2022"
|
|
1017
|
+
});
|
|
1018
|
+
bundleCache = result.outputFiles[0].text;
|
|
1019
|
+
return bundleCache;
|
|
1020
|
+
}
|
|
1021
|
+
async function renderFrameAt(ir, t, opts = {}) {
|
|
1022
|
+
const sceneDir = opts.sceneDir ?? process.cwd();
|
|
1023
|
+
const assets = await buildImageAssets(ir, sceneDir);
|
|
1024
|
+
const { fps, duration } = resolveTiming(ir, {});
|
|
1025
|
+
const videoAssets = await buildVideoFrameAssets(ir, sceneDir, fps, duration);
|
|
1026
|
+
const bundle = await browserBundle();
|
|
1027
|
+
return withPage(ir.size, async (page) => {
|
|
1028
|
+
await page.setContent(`<!DOCTYPE html><html><body style="margin:0;background:#000"></body></html>`);
|
|
1029
|
+
await injectFonts(page);
|
|
1030
|
+
await page.addScriptTag({ content: bundle });
|
|
1031
|
+
await page.evaluate(
|
|
1032
|
+
([sceneIr, imageAssets, vAssets]) => window.__reframe.init(sceneIr, imageAssets, vAssets),
|
|
1033
|
+
[ir, assets, videoAssets]
|
|
1034
|
+
);
|
|
1035
|
+
const dataUrl2 = await page.evaluate((tt) => window.__reframe.renderFrame(tt), t);
|
|
1036
|
+
return Buffer.from(dataUrl2.slice(22), "base64");
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// ../render-cli/src/diff.ts
|
|
1041
|
+
var MODES = ["side", "blend", "diff", "grid"];
|
|
1042
|
+
var dataUrl = (buf, ext) => `data:image/${ext === ".jpg" || ext === ".jpeg" ? "jpeg" : ext === ".webp" ? "webp" : "png"};base64,${buf.toString("base64")}`;
|
|
1043
|
+
async function composite(refUrl, renderUrl, mode, outPath) {
|
|
1044
|
+
const browser = await chromium2.launch({ args: ["--force-color-profile=srgb"] });
|
|
1045
|
+
try {
|
|
1046
|
+
const page = await browser.newPage({ deviceScaleFactor: 1 });
|
|
1047
|
+
await page.evaluate("globalThis.__name = globalThis.__name || ((f) => f)");
|
|
1048
|
+
const png = await page.evaluate(
|
|
1049
|
+
async ([ref, render, m]) => {
|
|
1050
|
+
const load = (src) => new Promise((res, rej) => {
|
|
1051
|
+
const im = new Image();
|
|
1052
|
+
im.onload = () => res(im);
|
|
1053
|
+
im.onerror = rej;
|
|
1054
|
+
im.src = src;
|
|
1055
|
+
});
|
|
1056
|
+
const refImg = await load(ref);
|
|
1057
|
+
const canvas = document.createElement("canvas");
|
|
1058
|
+
const ctx = canvas.getContext("2d");
|
|
1059
|
+
const tag = (s, x, y) => {
|
|
1060
|
+
ctx.save();
|
|
1061
|
+
ctx.font = "600 18px sans-serif";
|
|
1062
|
+
const w = ctx.measureText(s).width + 16;
|
|
1063
|
+
ctx.fillStyle = "rgba(0,0,0,0.6)";
|
|
1064
|
+
ctx.fillRect(x, y, w, 28);
|
|
1065
|
+
ctx.fillStyle = "#fff";
|
|
1066
|
+
ctx.fillText(s, x + 8, y + 20);
|
|
1067
|
+
ctx.restore();
|
|
1068
|
+
};
|
|
1069
|
+
if (m === "grid") {
|
|
1070
|
+
canvas.width = refImg.width;
|
|
1071
|
+
canvas.height = refImg.height;
|
|
1072
|
+
ctx.drawImage(refImg, 0, 0);
|
|
1073
|
+
ctx.save();
|
|
1074
|
+
ctx.font = "14px sans-serif";
|
|
1075
|
+
ctx.lineWidth = 1;
|
|
1076
|
+
for (let x = 0; x <= canvas.width; x += 100) {
|
|
1077
|
+
ctx.strokeStyle = x % 500 === 0 ? "rgba(255,90,90,0.85)" : "rgba(255,90,90,0.4)";
|
|
1078
|
+
ctx.beginPath();
|
|
1079
|
+
ctx.moveTo(x, 0);
|
|
1080
|
+
ctx.lineTo(x, canvas.height);
|
|
1081
|
+
ctx.stroke();
|
|
1082
|
+
ctx.fillStyle = "rgba(255,150,150,0.95)";
|
|
1083
|
+
ctx.fillText(String(x), x + 3, 15);
|
|
1084
|
+
}
|
|
1085
|
+
for (let y = 0; y <= canvas.height; y += 100) {
|
|
1086
|
+
ctx.strokeStyle = y % 500 === 0 ? "rgba(255,90,90,0.85)" : "rgba(255,90,90,0.4)";
|
|
1087
|
+
ctx.beginPath();
|
|
1088
|
+
ctx.moveTo(0, y);
|
|
1089
|
+
ctx.lineTo(canvas.width, y);
|
|
1090
|
+
ctx.stroke();
|
|
1091
|
+
ctx.fillStyle = "rgba(255,150,150,0.95)";
|
|
1092
|
+
ctx.fillText(String(y), 3, y + 15);
|
|
1093
|
+
}
|
|
1094
|
+
ctx.restore();
|
|
1095
|
+
} else {
|
|
1096
|
+
const rImg = render ? await load(render) : null;
|
|
1097
|
+
if (m === "side") {
|
|
1098
|
+
const H = Math.min(refImg.height, rImg ? rImg.height : refImg.height, 1e3);
|
|
1099
|
+
const rw = refImg.width * (H / refImg.height);
|
|
1100
|
+
const rrw = rImg ? rImg.width * (H / rImg.height) : 0;
|
|
1101
|
+
const gap = rImg ? 24 : 0;
|
|
1102
|
+
canvas.width = Math.round(rw + (rImg ? gap + rrw : 0));
|
|
1103
|
+
canvas.height = Math.round(H);
|
|
1104
|
+
ctx.fillStyle = "#0a0a0a";
|
|
1105
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
1106
|
+
ctx.drawImage(refImg, 0, 0, rw, H);
|
|
1107
|
+
if (rImg) ctx.drawImage(rImg, rw + gap, 0, rrw, H);
|
|
1108
|
+
tag("reference", 10, 10);
|
|
1109
|
+
if (rImg) tag("render", Math.round(rw + gap) + 10, 10);
|
|
1110
|
+
} else {
|
|
1111
|
+
canvas.width = refImg.width;
|
|
1112
|
+
canvas.height = refImg.height;
|
|
1113
|
+
ctx.drawImage(refImg, 0, 0);
|
|
1114
|
+
if (rImg) {
|
|
1115
|
+
ctx.globalAlpha = m === "blend" ? 0.5 : 1;
|
|
1116
|
+
ctx.globalCompositeOperation = m === "diff" ? "difference" : "source-over";
|
|
1117
|
+
ctx.drawImage(rImg, 0, 0, canvas.width, canvas.height);
|
|
1118
|
+
ctx.globalAlpha = 1;
|
|
1119
|
+
ctx.globalCompositeOperation = "source-over";
|
|
1120
|
+
}
|
|
1121
|
+
tag(m, 10, 10);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return canvas.toDataURL("image/png");
|
|
1125
|
+
},
|
|
1126
|
+
[refUrl, renderUrl, mode]
|
|
1127
|
+
);
|
|
1128
|
+
await writeFile(outPath, Buffer.from(png.slice(22), "base64"));
|
|
1129
|
+
} finally {
|
|
1130
|
+
await browser.close();
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
async function main() {
|
|
1134
|
+
const argv = process.argv.slice(2);
|
|
1135
|
+
const ref = argv[0];
|
|
1136
|
+
if (!ref || ref.startsWith("-")) {
|
|
1137
|
+
console.error("usage: reframe diff <ref-image> [<scene.ts>] [--t <sec>] [--mode side|blend|diff|grid] [-o out.png]");
|
|
1138
|
+
process.exit(2);
|
|
1139
|
+
}
|
|
1140
|
+
let scene;
|
|
1141
|
+
let t = 0;
|
|
1142
|
+
let mode = "side";
|
|
1143
|
+
let out = "";
|
|
1144
|
+
for (let i = 1; i < argv.length; i++) {
|
|
1145
|
+
const a = argv[i];
|
|
1146
|
+
if (a === "--t") t = Number(argv[++i]);
|
|
1147
|
+
else if (a === "--mode") mode = argv[++i];
|
|
1148
|
+
else if (a === "-o") out = argv[++i];
|
|
1149
|
+
else if (!a.startsWith("-") && !scene) scene = a;
|
|
1150
|
+
else {
|
|
1151
|
+
console.error(`unknown argument: ${a}`);
|
|
1152
|
+
process.exit(2);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
if (!MODES.includes(mode)) {
|
|
1156
|
+
console.error(`unknown --mode "${mode}" \u2014 use ${MODES.join(", ")}`);
|
|
1157
|
+
process.exit(2);
|
|
1158
|
+
}
|
|
1159
|
+
const refPath = resolve4(ref);
|
|
1160
|
+
const refUrl = dataUrl(await readFile5(refPath), extname3(refPath).toLowerCase());
|
|
1161
|
+
let renderUrl = null;
|
|
1162
|
+
if (mode !== "grid") {
|
|
1163
|
+
if (!scene) {
|
|
1164
|
+
console.error(`--mode ${mode} needs a scene file (only --mode grid works on the reference alone)`);
|
|
1165
|
+
process.exit(2);
|
|
1166
|
+
}
|
|
1167
|
+
const scenePath = resolve4(scene);
|
|
1168
|
+
const loaded = await loadModule(scenePath);
|
|
1169
|
+
if (loaded.kind !== "scene") {
|
|
1170
|
+
console.error("diff needs a single scene (not a composition)");
|
|
1171
|
+
process.exit(2);
|
|
1172
|
+
}
|
|
1173
|
+
const buf = await renderFrameAt(loaded.ir, t, { sceneDir: dirname4(scenePath) });
|
|
1174
|
+
renderUrl = dataUrl(buf, ".png");
|
|
1175
|
+
}
|
|
1176
|
+
const outPath = out ? resolve4(out) : resolve4(`diff-${mode}.png`);
|
|
1177
|
+
await composite(refUrl, renderUrl, mode, outPath);
|
|
1178
|
+
console.log(outPath);
|
|
1179
|
+
}
|
|
1180
|
+
if (process.argv[1] && import.meta.url === pathToFileURL2(process.argv[1]).href) {
|
|
1181
|
+
main().catch((e) => {
|
|
1182
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
1183
|
+
process.exit(1);
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
export {
|
|
1187
|
+
composite,
|
|
1188
|
+
dataUrl
|
|
1189
|
+
};
|