reframe-video 0.6.18 → 0.6.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/bin.js +92 -31
- package/dist/cli.js +67 -25
- package/dist/compile-api.d.ts +6 -0
- package/dist/compile-api.js +477 -0
- package/dist/compile.js +477 -0
- package/dist/diff.js +67 -25
- package/dist/labels.js +71 -31
- package/dist/renderer-canvas.d.ts +1 -0
- package/dist/renderer-canvas.js +1 -1
- package/dist/types-renderer/index.d.ts +34 -0
- package/package.json +11 -2
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
// ../render-cli/src/loadScene.ts
|
|
2
|
+
import { build } from "esbuild";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
// ../core/src/validate.ts
|
|
8
|
+
var FX_PROPS = ["blur", "shadowColor", "shadowBlur", "shadowX", "shadowY", "blend"];
|
|
9
|
+
var BLEND_MODES = /* @__PURE__ */ new Set([
|
|
10
|
+
"normal",
|
|
11
|
+
"multiply",
|
|
12
|
+
"screen",
|
|
13
|
+
"overlay",
|
|
14
|
+
"lighten",
|
|
15
|
+
"darken",
|
|
16
|
+
"add",
|
|
17
|
+
"color-dodge",
|
|
18
|
+
"soft-light",
|
|
19
|
+
"hard-light",
|
|
20
|
+
"difference"
|
|
21
|
+
]);
|
|
22
|
+
var IMAGE_FITS = /* @__PURE__ */ new Set(["fill", "cover"]);
|
|
23
|
+
var COMMON_PROPS = ["x", "y", "opacity", "rotation", "scale", "scaleX", "scaleY", "skewX", "skewY", "z", "rotateX", "rotateY", "anchor", "fixed", ...FX_PROPS];
|
|
24
|
+
var CAMERA_PROPS = ["x", "y", "zoom", "rotation", "perspective", "focus", "aperture"];
|
|
25
|
+
var PROPS_BY_TYPE = {
|
|
26
|
+
rect: [...COMMON_PROPS, "width", "height", "fill", "stroke", "strokeWidth", "radius"],
|
|
27
|
+
ellipse: [...COMMON_PROPS, "width", "height", "fill", "stroke", "strokeWidth"],
|
|
28
|
+
line: ["x1", "y1", "x2", "y2", "stroke", "strokeWidth", "opacity", "progress", ...FX_PROPS],
|
|
29
|
+
text: [...COMMON_PROPS, "content", "contentDecimals", "contentThousands", "prefix", "suffix", "fontFamily", "fontSize", "fontWeight", "fill", "letterSpacing"],
|
|
30
|
+
image: [...COMMON_PROPS, "src", "width", "height", "fit"],
|
|
31
|
+
video: [...COMMON_PROPS, "src", "width", "height", "fit", "start", "rate", "clipStart", "volume", "fadeIn", "pan"],
|
|
32
|
+
path: [...COMMON_PROPS, "d", "fill", "stroke", "strokeWidth", "progress", "originX", "originY"],
|
|
33
|
+
group: COMMON_PROPS
|
|
34
|
+
};
|
|
35
|
+
var SceneValidationError = class extends Error {
|
|
36
|
+
constructor(problems) {
|
|
37
|
+
super(`Scene validation failed:
|
|
38
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
39
|
+
this.problems = problems;
|
|
40
|
+
this.name = "SceneValidationError";
|
|
41
|
+
}
|
|
42
|
+
problems;
|
|
43
|
+
};
|
|
44
|
+
function validateScene(ir) {
|
|
45
|
+
const problems = [];
|
|
46
|
+
const nodeById = /* @__PURE__ */ new Map();
|
|
47
|
+
const checkPaint = (where, value) => {
|
|
48
|
+
if (typeof value !== "object" || value === null) return;
|
|
49
|
+
const g = value;
|
|
50
|
+
if (g.kind !== "linear" && g.kind !== "radial" && g.kind !== "conic") {
|
|
51
|
+
problems.push(`${where}: a paint object must be a gradient with kind "linear" / "radial" / "conic"`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!Array.isArray(g.stops) || g.stops.length === 0) {
|
|
55
|
+
problems.push(`${where}: gradient "${g.kind}" needs at least one color stop`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
g.stops.forEach((s, i) => {
|
|
59
|
+
const st = s;
|
|
60
|
+
if (typeof st?.color !== "string") problems.push(`${where}: gradient stop ${i} needs a color string`);
|
|
61
|
+
if (typeof st?.offset !== "number" || st.offset < 0 || st.offset > 1) {
|
|
62
|
+
problems.push(`${where}: gradient stop ${i} "offset" must be a number in 0..1`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const collect = (nodes) => {
|
|
67
|
+
for (const node of nodes) {
|
|
68
|
+
if (nodeById.has(node.id)) {
|
|
69
|
+
problems.push(`duplicate node id "${node.id}" \u2014 every node id must be unique`);
|
|
70
|
+
}
|
|
71
|
+
nodeById.set(node.id, node);
|
|
72
|
+
const props = node.props;
|
|
73
|
+
checkPaint(`node "${node.id}" fill`, props.fill);
|
|
74
|
+
checkPaint(`node "${node.id}" stroke`, props.stroke);
|
|
75
|
+
if (typeof props.blur === "number" && props.blur < 0) problems.push(`node "${node.id}": blur must be >= 0`);
|
|
76
|
+
if (typeof props.shadowBlur === "number" && props.shadowBlur < 0) problems.push(`node "${node.id}": shadowBlur must be >= 0`);
|
|
77
|
+
if (typeof props.blend === "string" && !BLEND_MODES.has(props.blend)) problems.push(`node "${node.id}": unknown blend "${props.blend}" \u2014 use ${[...BLEND_MODES].join(", ")}`);
|
|
78
|
+
if (typeof props.fit === "string" && !IMAGE_FITS.has(props.fit)) problems.push(`node "${node.id}": unknown fit "${props.fit}" \u2014 use ${[...IMAGE_FITS].join(", ")}`);
|
|
79
|
+
if (node.type === "group") {
|
|
80
|
+
const clip = node.props.clip;
|
|
81
|
+
if (clip) {
|
|
82
|
+
if (clip.kind !== "rect" && clip.kind !== "ellipse") {
|
|
83
|
+
problems.push(`group "${node.id}" clip: unknown kind "${clip.kind}" \u2014 use "rect" or "ellipse"`);
|
|
84
|
+
}
|
|
85
|
+
if (!(clip.width > 0) || !(clip.height > 0)) {
|
|
86
|
+
problems.push(`group "${node.id}" clip: width and height must be > 0`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const matte = node.props.matte;
|
|
90
|
+
if (matte !== void 0) {
|
|
91
|
+
if (matte !== "alpha" && matte !== "luma") {
|
|
92
|
+
problems.push(`group "${node.id}" matte: unknown mode "${String(matte)}" \u2014 use "alpha" or "luma"`);
|
|
93
|
+
} else if (node.children.length < 2) {
|
|
94
|
+
problems.push(`group "${node.id}" matte: needs \u22652 children (first masks the rest)`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
collect(node.children);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
collect(ir.nodes);
|
|
102
|
+
const checkProps = (where, nodeId, props) => {
|
|
103
|
+
if (nodeId === "camera" && !nodeById.has("camera")) {
|
|
104
|
+
for (const key of Object.keys(props)) {
|
|
105
|
+
if (!CAMERA_PROPS.includes(key)) {
|
|
106
|
+
problems.push(`${where}: "${key}" is not a camera prop \u2014 valid props: ${CAMERA_PROPS.join(", ")}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const node = nodeById.get(nodeId);
|
|
112
|
+
if (!node) {
|
|
113
|
+
problems.push(
|
|
114
|
+
`${where} targets unknown node "${nodeId}" \u2014 known ids: ${[...nodeById.keys()].join(", ")}`
|
|
115
|
+
);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const allowed = PROPS_BY_TYPE[node.type];
|
|
119
|
+
for (const key of Object.keys(props)) {
|
|
120
|
+
if (!allowed.includes(key)) {
|
|
121
|
+
problems.push(
|
|
122
|
+
`${where}: "${key}" is not a prop of ${node.type} "${nodeId}" \u2014 valid props: ${allowed.join(", ")}`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const states = ir.states ?? {};
|
|
128
|
+
for (const [stateName, overrides] of Object.entries(states)) {
|
|
129
|
+
for (const [nodeId, props] of Object.entries(overrides)) {
|
|
130
|
+
checkProps(`state "${stateName}"`, nodeId, props);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (ir.initial !== void 0 && !(ir.initial in states)) {
|
|
134
|
+
problems.push(
|
|
135
|
+
`initial state "${ir.initial}" is not defined \u2014 defined states: ${Object.keys(states).join(", ") || "(none)"}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const labels = /* @__PURE__ */ new Set();
|
|
139
|
+
const checkTimeline = (tl, path2) => {
|
|
140
|
+
if ("label" in tl && tl.label !== void 0) {
|
|
141
|
+
if (labels.has(tl.label)) {
|
|
142
|
+
problems.push(
|
|
143
|
+
`${path2}: duplicate timeline label "${tl.label}" \u2014 labels are overlay addresses and must be unique`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
labels.add(tl.label);
|
|
147
|
+
}
|
|
148
|
+
switch (tl.kind) {
|
|
149
|
+
case "seq":
|
|
150
|
+
case "par":
|
|
151
|
+
tl.children.forEach((c, i) => checkTimeline(c, `${path2}.${tl.kind}[${i}]`));
|
|
152
|
+
break;
|
|
153
|
+
case "stagger":
|
|
154
|
+
if (tl.interval < 0) problems.push(`${path2}: stagger interval must be >= 0`);
|
|
155
|
+
tl.children.forEach((c, i) => checkTimeline(c, `${path2}.stagger[${i}]`));
|
|
156
|
+
break;
|
|
157
|
+
case "to":
|
|
158
|
+
if (!(tl.state in states)) {
|
|
159
|
+
problems.push(
|
|
160
|
+
`${path2}: to("${tl.state}") references an undefined state \u2014 defined states: ${Object.keys(states).join(", ") || "(none)"}`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
164
|
+
problems.push(`${path2}: to("${tl.state}") duration must be > 0`);
|
|
165
|
+
}
|
|
166
|
+
for (const id of tl.filter ?? []) {
|
|
167
|
+
if (!nodeById.has(id)) problems.push(`${path2}: filter contains unknown node "${id}"`);
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case "tween":
|
|
171
|
+
checkProps(path2, tl.target, tl.props);
|
|
172
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
173
|
+
problems.push(`${path2}: tween duration must be > 0`);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case "motionPath": {
|
|
177
|
+
const node = nodeById.get(tl.target);
|
|
178
|
+
const isSceneCamera = tl.target === "camera" && !node;
|
|
179
|
+
if (!isSceneCamera) {
|
|
180
|
+
if (!node) {
|
|
181
|
+
problems.push(
|
|
182
|
+
`${path2}: motionPath targets unknown node "${tl.target}" \u2014 known ids: ${[...nodeById.keys()].join(", ")}`
|
|
183
|
+
);
|
|
184
|
+
} else if (node.type === "line") {
|
|
185
|
+
problems.push(`${path2}: motionPath cannot target a line (no x/y) \u2014 "${tl.target}"`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (tl.points.length < 1) problems.push(`${path2}: motionPath "${tl.target}" needs at least 1 point`);
|
|
189
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
190
|
+
problems.push(`${path2}: motionPath "${tl.target}" duration must be > 0`);
|
|
191
|
+
}
|
|
192
|
+
if (tl.curviness !== void 0 && tl.curviness < 0) {
|
|
193
|
+
problems.push(`${path2}: motionPath "${tl.target}" curviness must be >= 0`);
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "wait":
|
|
198
|
+
if (tl.duration < 0) problems.push(`${path2}: wait duration must be >= 0`);
|
|
199
|
+
break;
|
|
200
|
+
case "beat":
|
|
201
|
+
if (labels.has(tl.name)) {
|
|
202
|
+
problems.push(
|
|
203
|
+
`${path2}: duplicate timeline label "${tl.name}" (beat name) \u2014 labels are overlay addresses and must be unique`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
labels.add(tl.name);
|
|
207
|
+
if (tl.duration !== void 0 && tl.duration <= 0) {
|
|
208
|
+
problems.push(`${path2}: beat "${tl.name}" duration must be > 0`);
|
|
209
|
+
}
|
|
210
|
+
if (tl.scale !== void 0 && tl.scale <= 0) {
|
|
211
|
+
problems.push(`${path2}: beat "${tl.name}" scale must be > 0`);
|
|
212
|
+
}
|
|
213
|
+
for (const id of tl.nodes ?? []) {
|
|
214
|
+
if (!nodeById.has(id)) {
|
|
215
|
+
problems.push(
|
|
216
|
+
`${path2}: beat "${tl.name}" owns unknown node "${id}" \u2014 known ids: ${[...nodeById.keys()].join(", ")}`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
tl.children.forEach((c, i) => checkTimeline(c, `${path2}.beat(${tl.name})[${i}]`));
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
if (ir.timeline) checkTimeline(ir.timeline, "timeline");
|
|
225
|
+
for (const [i, b] of (ir.behaviors ?? []).entries()) {
|
|
226
|
+
checkProps(`behaviors[${i}]`, b.target, { [b.prop]: 0 });
|
|
227
|
+
}
|
|
228
|
+
if (ir.duration !== void 0 && ir.duration <= 0) {
|
|
229
|
+
problems.push("scene duration must be > 0");
|
|
230
|
+
}
|
|
231
|
+
if (ir.camera) {
|
|
232
|
+
if (nodeById.has("camera")) {
|
|
233
|
+
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)`);
|
|
234
|
+
}
|
|
235
|
+
for (const [key, value] of Object.entries(ir.camera)) {
|
|
236
|
+
if (key === "zSort") {
|
|
237
|
+
if (typeof value !== "boolean") problems.push(`camera.zSort must be a boolean`);
|
|
238
|
+
} else if (!CAMERA_PROPS.includes(key)) {
|
|
239
|
+
problems.push(`camera: "${key}" is not a camera prop \u2014 valid props: ${CAMERA_PROPS.join(", ")}, zSort`);
|
|
240
|
+
} else if (typeof value !== "number") {
|
|
241
|
+
problems.push(`camera.${key} must be a number`);
|
|
242
|
+
} else if (key === "perspective" && value <= 0) {
|
|
243
|
+
problems.push(`camera.perspective must be > 0 (focal distance in px) \u2014 drop it to disable perspective`);
|
|
244
|
+
} else if (key === "aperture" && value < 0) {
|
|
245
|
+
problems.push(`camera.aperture must be >= 0 (blur px per unit depth) \u2014 0 disables depth of field`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const SFX_NAMES = ["whoosh", "pop", "tick", "rise", "shimmer", "thud"];
|
|
250
|
+
for (const [i, cue] of (ir.audio?.cues ?? []).entries()) {
|
|
251
|
+
if (typeof cue.at === "string" && !labels.has(cue.at)) {
|
|
252
|
+
problems.push(
|
|
253
|
+
`audio.cues[${i}]: unknown timeline label "${cue.at}" \u2014 known labels: ${[...labels].join(", ") || "(none)"}`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
if (typeof cue.at === "number" && cue.at < 0) {
|
|
257
|
+
problems.push(`audio.cues[${i}]: "at" must be >= 0`);
|
|
258
|
+
}
|
|
259
|
+
if (cue.sfx === void 0 === (cue.file === void 0)) {
|
|
260
|
+
problems.push(`audio.cues[${i}]: exactly one of "sfx" or "file" is required`);
|
|
261
|
+
}
|
|
262
|
+
if (cue.sfx !== void 0 && !SFX_NAMES.includes(cue.sfx)) {
|
|
263
|
+
problems.push(`audio.cues[${i}]: unknown sfx "${cue.sfx}" \u2014 valid: ${SFX_NAMES.join(", ")}`);
|
|
264
|
+
}
|
|
265
|
+
if (cue.gain !== void 0 && cue.gain < 0) {
|
|
266
|
+
problems.push(`audio.cues[${i}]: gain must be >= 0`);
|
|
267
|
+
}
|
|
268
|
+
if (cue.fadeIn !== void 0 && cue.fadeIn < 0) {
|
|
269
|
+
problems.push(`audio.cues[${i}]: fadeIn must be >= 0`);
|
|
270
|
+
}
|
|
271
|
+
if (cue.fadeOut !== void 0 && cue.fadeOut < 0) {
|
|
272
|
+
problems.push(`audio.cues[${i}]: fadeOut must be >= 0`);
|
|
273
|
+
}
|
|
274
|
+
if (cue.pan !== void 0 && (cue.pan < -1 || cue.pan > 1)) {
|
|
275
|
+
problems.push(`audio.cues[${i}]: pan must be in [-1, 1] (-1 left \u2026 +1 right)`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const duck = ir.audio?.bgm?.duck;
|
|
279
|
+
if (typeof duck === "object" && duck !== null && duck.depth !== void 0 && (duck.depth < 0 || duck.depth > 1)) {
|
|
280
|
+
problems.push("audio.bgm.duck.depth must be in [0, 1]");
|
|
281
|
+
}
|
|
282
|
+
if (ir.audio?.bgm?.file !== void 0 && ir.audio.bgm.synth !== void 0) {
|
|
283
|
+
problems.push('audio.bgm: use either "file" or "synth", not both');
|
|
284
|
+
}
|
|
285
|
+
if (problems.length > 0) throw new SceneValidationError(problems);
|
|
286
|
+
}
|
|
287
|
+
var TRANSITIONS = ["cut", "crossfade"];
|
|
288
|
+
function validateComposition(comp) {
|
|
289
|
+
const problems = [];
|
|
290
|
+
if (comp.scenes.length === 0) problems.push("composition has no scenes");
|
|
291
|
+
const seen = /* @__PURE__ */ new Set();
|
|
292
|
+
for (const [i, entry] of comp.scenes.entries()) {
|
|
293
|
+
const where = `scenes[${i}]`;
|
|
294
|
+
try {
|
|
295
|
+
validateScene(entry.scene);
|
|
296
|
+
} catch (err) {
|
|
297
|
+
if (err instanceof SceneValidationError) {
|
|
298
|
+
for (const p of err.problems) problems.push(`${where} (scene "${entry.scene.id}"): ${p}`);
|
|
299
|
+
} else throw err;
|
|
300
|
+
}
|
|
301
|
+
if (seen.has(entry.scene.id)) {
|
|
302
|
+
problems.push(`${where}: duplicate scene id "${entry.scene.id}" \u2014 scene ids must be unique in a composition`);
|
|
303
|
+
}
|
|
304
|
+
seen.add(entry.scene.id);
|
|
305
|
+
if (entry.transition !== void 0 && !TRANSITIONS.includes(entry.transition)) {
|
|
306
|
+
problems.push(`${where}: unknown transition "${entry.transition}" \u2014 valid: ${TRANSITIONS.join(", ")}`);
|
|
307
|
+
}
|
|
308
|
+
if (typeof entry.at === "string" && Number.isNaN(Number(entry.at))) {
|
|
309
|
+
problems.push(`${where}: "at" string "${entry.at}" is not a number (use "-0.5"/"+0.5" or a number)`);
|
|
310
|
+
}
|
|
311
|
+
if (typeof entry.at === "number" && entry.at < 0) {
|
|
312
|
+
problems.push(`${where}: absolute "at" must be >= 0`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (problems.length > 0) throw new SceneValidationError(problems);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ../core/src/presets.ts
|
|
319
|
+
var SET = 1 / 120;
|
|
320
|
+
|
|
321
|
+
// ../core/src/interpolate.ts
|
|
322
|
+
var BACK_C1 = 1.70158;
|
|
323
|
+
var BACK_C2 = BACK_C1 * 1.525;
|
|
324
|
+
var BACK_C3 = BACK_C1 + 1;
|
|
325
|
+
var ELASTIC_C4 = 2 * Math.PI / 3;
|
|
326
|
+
var ELASTIC_C5 = 2 * Math.PI / 4.5;
|
|
327
|
+
function springEase(stiffness, damping, velocity) {
|
|
328
|
+
const K = 5;
|
|
329
|
+
const zeta = Math.min(0.999, Math.max(0.05, damping / (2 * Math.sqrt(Math.max(1e-6, stiffness)))));
|
|
330
|
+
const wd = K / zeta * Math.sqrt(1 - zeta * zeta);
|
|
331
|
+
const coef = (K - velocity) / wd;
|
|
332
|
+
return (u) => {
|
|
333
|
+
if (u <= 0) return 0;
|
|
334
|
+
if (u >= 1) return 1;
|
|
335
|
+
return 1 - Math.exp(-K * u) * (Math.cos(wd * u) + coef * Math.sin(wd * u));
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function easeOutBounce(u) {
|
|
339
|
+
const n1 = 7.5625;
|
|
340
|
+
const d1 = 2.75;
|
|
341
|
+
if (u < 1 / d1) return n1 * u * u;
|
|
342
|
+
if (u < 2 / d1) return n1 * (u -= 1.5 / d1) * u + 0.75;
|
|
343
|
+
if (u < 2.5 / d1) return n1 * (u -= 2.25 / d1) * u + 0.9375;
|
|
344
|
+
return n1 * (u -= 2.625 / d1) * u + 0.984375;
|
|
345
|
+
}
|
|
346
|
+
var EASE_TABLE = {
|
|
347
|
+
linear: (u) => u,
|
|
348
|
+
easeInQuad: (u) => u * u,
|
|
349
|
+
easeOutQuad: (u) => 1 - (1 - u) * (1 - u),
|
|
350
|
+
easeInOutQuad: (u) => u < 0.5 ? 2 * u * u : 1 - (-2 * u + 2) ** 2 / 2,
|
|
351
|
+
easeInCubic: (u) => u ** 3,
|
|
352
|
+
easeOutCubic: (u) => 1 - (1 - u) ** 3,
|
|
353
|
+
easeInOutCubic: (u) => u < 0.5 ? 4 * u ** 3 : 1 - (-2 * u + 2) ** 3 / 2,
|
|
354
|
+
easeInQuart: (u) => u ** 4,
|
|
355
|
+
easeOutQuart: (u) => 1 - (1 - u) ** 4,
|
|
356
|
+
easeInOutQuart: (u) => u < 0.5 ? 8 * u ** 4 : 1 - (-2 * u + 2) ** 4 / 2,
|
|
357
|
+
easeInExpo: (u) => u === 0 ? 0 : 2 ** (10 * u - 10),
|
|
358
|
+
easeOutExpo: (u) => u === 1 ? 1 : 1 - 2 ** (-10 * u),
|
|
359
|
+
easeInOutExpo: (u) => u === 0 ? 0 : u === 1 ? 1 : u < 0.5 ? 2 ** (20 * u - 10) / 2 : (2 - 2 ** (-20 * u + 10)) / 2,
|
|
360
|
+
// --- expressive eases (GSAP's signature feel) — standard Penner equations ---
|
|
361
|
+
// back: overshoots past the target then settles (pop / snap)
|
|
362
|
+
easeInBack: (u) => BACK_C3 * u ** 3 - BACK_C1 * u * u,
|
|
363
|
+
easeOutBack: (u) => 1 + BACK_C3 * (u - 1) ** 3 + BACK_C1 * (u - 1) ** 2,
|
|
364
|
+
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,
|
|
365
|
+
// elastic: rings around the target before settling (playful spring)
|
|
366
|
+
easeInElastic: (u) => u === 0 ? 0 : u === 1 ? 1 : -(2 ** (10 * u - 10)) * Math.sin((u * 10 - 10.75) * ELASTIC_C4),
|
|
367
|
+
easeOutElastic: (u) => u === 0 ? 0 : u === 1 ? 1 : 2 ** (-10 * u) * Math.sin((u * 10 - 0.75) * ELASTIC_C4) + 1,
|
|
368
|
+
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,
|
|
369
|
+
// bounce: drops and bounces to rest (lands without overshoot)
|
|
370
|
+
easeInBounce: (u) => 1 - easeOutBounce(1 - u),
|
|
371
|
+
easeOutBounce,
|
|
372
|
+
easeInOutBounce: (u) => u < 0.5 ? (1 - easeOutBounce(1 - 2 * u)) / 2 : (1 + easeOutBounce(2 * u - 1)) / 2,
|
|
373
|
+
// damped-spring presets (ζ from damping/(2√stiffness)): 0.5 / 0.30 / 0.90
|
|
374
|
+
spring: springEase(100, 10, 0),
|
|
375
|
+
springBouncy: springEase(180, 8, 0),
|
|
376
|
+
springStiff: springEase(210, 26, 0)
|
|
377
|
+
};
|
|
378
|
+
var EASE_NAMES = Object.keys(EASE_TABLE);
|
|
379
|
+
|
|
380
|
+
// ../core/src/evaluate.ts
|
|
381
|
+
var DEG = Math.PI / 180;
|
|
382
|
+
|
|
383
|
+
// ../render-cli/src/loadScene.ts
|
|
384
|
+
var HERE = dirname(fileURLToPath(import.meta.url));
|
|
385
|
+
var CORE_ENTRY = true ? resolve(HERE, "index.js") : resolve(HERE, "..", "..", "core", "src", "index.ts");
|
|
386
|
+
var SceneLoadError = class extends Error {
|
|
387
|
+
kind;
|
|
388
|
+
constructor(kind, message, options) {
|
|
389
|
+
super(message, options);
|
|
390
|
+
this.name = "SceneLoadError";
|
|
391
|
+
this.kind = kind;
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
var clean = (err) => (err instanceof Error ? err.message : String(err)).replace(
|
|
395
|
+
/data:text\/javascript;base64,[A-Za-z0-9+/=]+/g,
|
|
396
|
+
"<scene bundle>"
|
|
397
|
+
);
|
|
398
|
+
var ALIAS = { "@reframe/core": CORE_ENTRY, "reframe-video": CORE_ENTRY };
|
|
399
|
+
async function bundle(input) {
|
|
400
|
+
const common = {
|
|
401
|
+
bundle: true,
|
|
402
|
+
format: "esm",
|
|
403
|
+
platform: "neutral",
|
|
404
|
+
write: false,
|
|
405
|
+
logLevel: "silent",
|
|
406
|
+
sourcemap: "inline",
|
|
407
|
+
alias: ALIAS
|
|
408
|
+
};
|
|
409
|
+
try {
|
|
410
|
+
const out = await build(
|
|
411
|
+
"path" in input ? { ...common, entryPoints: [input.path] } : { ...common, stdin: { contents: input.code, resolveDir: input.resolveDir, loader: "ts", sourcefile: "scene.ts" } }
|
|
412
|
+
);
|
|
413
|
+
return out.outputFiles[0].text;
|
|
414
|
+
} catch (err) {
|
|
415
|
+
throw new SceneLoadError("bundle", clean(err), { cause: err });
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async function importDefault(code, label) {
|
|
419
|
+
let mod;
|
|
420
|
+
try {
|
|
421
|
+
mod = await import(`data:text/javascript;base64,${Buffer.from(code).toString("base64")}`);
|
|
422
|
+
} catch (err) {
|
|
423
|
+
const kind = err instanceof Error && err.name === "SceneValidationError" ? "validation" : "eval";
|
|
424
|
+
throw new SceneLoadError(kind, clean(err), { cause: err });
|
|
425
|
+
}
|
|
426
|
+
if (mod.default === void 0) throw new SceneLoadError("eval", `${label} must default-export a scene or composition`);
|
|
427
|
+
return mod.default;
|
|
428
|
+
}
|
|
429
|
+
async function loadDefault(path2) {
|
|
430
|
+
if (path2.endsWith(".json")) {
|
|
431
|
+
try {
|
|
432
|
+
return JSON.parse(await readFile(path2, "utf8"));
|
|
433
|
+
} catch (err) {
|
|
434
|
+
throw new SceneLoadError("eval", `failed to read ${path2}: ${clean(err)}`, { cause: err });
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return importDefault(await bundle({ path: path2 }), path2);
|
|
438
|
+
}
|
|
439
|
+
function isComposition(def) {
|
|
440
|
+
return typeof def === "object" && def !== null && Array.isArray(def.scenes);
|
|
441
|
+
}
|
|
442
|
+
function asScene(def, label) {
|
|
443
|
+
if (isComposition(def)) {
|
|
444
|
+
throw new SceneLoadError("validation", `${label} is a composition \u2014 render it directly, not as a single scene`);
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
validateScene(def);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
throw new SceneLoadError("validation", clean(err), { cause: err });
|
|
450
|
+
}
|
|
451
|
+
return def;
|
|
452
|
+
}
|
|
453
|
+
async function loadScene(path2) {
|
|
454
|
+
return asScene(await loadDefault(path2), path2);
|
|
455
|
+
}
|
|
456
|
+
async function loadSceneFromCode(code, resolveDir = process.cwd()) {
|
|
457
|
+
return asScene(await importDefault(await bundle({ code, resolveDir }), "<source>"), "<source>");
|
|
458
|
+
}
|
|
459
|
+
async function loadModule(path2) {
|
|
460
|
+
const def = await loadDefault(path2);
|
|
461
|
+
if (isComposition(def)) {
|
|
462
|
+
try {
|
|
463
|
+
validateComposition(def);
|
|
464
|
+
} catch (err) {
|
|
465
|
+
throw new SceneLoadError("validation", clean(err), { cause: err });
|
|
466
|
+
}
|
|
467
|
+
return { kind: "composition", ir: def };
|
|
468
|
+
}
|
|
469
|
+
return { kind: "scene", ir: asScene(def, path2) };
|
|
470
|
+
}
|
|
471
|
+
export {
|
|
472
|
+
SceneLoadError,
|
|
473
|
+
isComposition,
|
|
474
|
+
loadModule,
|
|
475
|
+
loadScene,
|
|
476
|
+
loadSceneFromCode
|
|
477
|
+
};
|