@pixerate/editor 0.160.0 → 0.162.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.cjs +36 -35
- package/dist/agent/index.js +7 -6
- package/dist/animation/index.cjs +5 -4
- package/dist/animation/index.js +4 -3
- package/dist/animation-editor/index.cjs +62 -61
- package/dist/animation-editor/index.js +6 -5
- package/dist/canvas/index.cjs +33 -32
- package/dist/canvas/index.js +6 -5
- package/dist/chart/index.cjs +88 -87
- package/dist/chart/index.js +7 -6
- package/dist/{chunk-QMI5HZWA.cjs → chunk-236TKNUR.cjs} +3 -3
- package/dist/{chunk-6UPGM3JB.js → chunk-2TKHLX6H.js} +1 -1
- package/dist/{chunk-3YDQLQH2.cjs → chunk-32MMQYCQ.cjs} +81 -81
- package/dist/{chunk-MHEXLG3M.cjs → chunk-3GJH2MGH.cjs} +37 -37
- package/dist/{chunk-AKDWAWSY.cjs → chunk-3IHNXRUV.cjs} +45 -45
- package/dist/{chunk-VKF3PWKR.cjs → chunk-3OSXHLIT.cjs} +259 -28
- package/dist/{chunk-TVO6W2Q6.cjs → chunk-4NGVHHJB.cjs} +17 -17
- package/dist/chunk-4VU4CP7R.js +769 -0
- package/dist/chunk-6DM3PUQD.cjs +767 -0
- package/dist/{chunk-DBIVICAO.js → chunk-7CKPUUN4.js} +1 -1
- package/dist/{chunk-57JLBGJ5.cjs → chunk-7YBDRJXT.cjs} +8 -8
- package/dist/{chunk-KY3FYKP3.js → chunk-BQWGN5WH.js} +1 -1
- package/dist/{chunk-LEUZ4FRC.cjs → chunk-CIPIESX4.cjs} +3 -3
- package/dist/chunk-CJE5MOIS.js +347 -0
- package/dist/{chunk-5QBRAIVK.js → chunk-CX6JLDFC.js} +3 -3
- package/dist/{chunk-R3QY7PPL.js → chunk-DTSTNRPH.js} +1 -1
- package/dist/{chunk-6LUYFHHN.cjs → chunk-EQ46F75O.cjs} +51 -51
- package/dist/{chunk-UKCJ43YL.cjs → chunk-ES3UEVUT.cjs} +130 -898
- package/dist/{chunk-UM3RPYC5.js → chunk-EVPZ5IKN.js} +1 -1
- package/dist/{chunk-XNQ5EFB4.cjs → chunk-EY22AY6R.cjs} +16 -16
- package/dist/chunk-FKUKJ3XA.cjs +347 -0
- package/dist/{chunk-YABNLNY7.js → chunk-GLMP22FT.js} +3 -3
- package/dist/{chunk-SUF6WRXR.cjs → chunk-GTELFJRE.cjs} +2 -2
- package/dist/{chunk-72BGL3I2.js → chunk-GWV4T5NZ.js} +1 -1
- package/dist/{chunk-AY65VQSU.js → chunk-H3OEM3Q2.js} +1 -1
- package/dist/{chunk-4YWAEV4W.cjs → chunk-HDGBM7EA.cjs} +26 -26
- package/dist/{chunk-H5XX4KHB.js → chunk-HLOKB7WW.js} +5 -3
- package/dist/{chunk-WNAAWLZ5.js → chunk-KGTF55R3.js} +2 -2
- package/dist/{chunk-WPPJH6X4.cjs → chunk-LL3H5XUH.cjs} +6 -4
- package/dist/{chunk-4T44CJ5K.cjs → chunk-NA4UVVJ4.cjs} +15 -15
- package/dist/{chunk-Q6PA362P.js → chunk-NO5QQDHZ.js} +2 -2
- package/dist/{chunk-AA34BA7G.js → chunk-QYZGBVNC.js} +30 -798
- package/dist/chunk-S6X2QRVU.cjs +769 -0
- package/dist/{chunk-SSCL7QQ4.js → chunk-XDCFJEU7.js} +2 -2
- package/dist/{chunk-IQ6KKXOU.js → chunk-YN4AYYBJ.js} +243 -12
- package/dist/chunk-ZGOHKS3X.js +767 -0
- package/dist/color/index.cjs +6 -2
- package/dist/color/index.d.cts +1 -0
- package/dist/color/index.d.ts +1 -0
- package/dist/color/index.js +28 -24
- package/dist/color/suggest.d.cts +12 -0
- package/dist/color/suggest.d.ts +12 -0
- package/dist/effects/index.cjs +44 -771
- package/dist/effects/index.js +34 -761
- package/dist/effects/ui.d.cts +20 -3
- package/dist/effects/ui.d.ts +20 -3
- package/dist/export/index.cjs +6 -5
- package/dist/export/index.js +5 -4
- package/dist/extensions/index.cjs +9 -8
- package/dist/extensions/index.js +8 -7
- package/dist/gradient/index.cjs +28 -26
- package/dist/gradient/index.js +7 -5
- package/dist/image-editor/index.cjs +638 -637
- package/dist/image-editor/index.js +5 -4
- package/dist/index.cjs +15 -14
- package/dist/index.js +9 -8
- package/dist/paint-editor/index.cjs +17 -16
- package/dist/paint-editor/index.js +6 -5
- package/dist/typography/accessibility.d.cts +44 -0
- package/dist/typography/accessibility.d.ts +44 -0
- package/dist/typography/catalog.d.cts +98 -0
- package/dist/typography/catalog.d.ts +98 -0
- package/dist/typography/index.cjs +1099 -0
- package/dist/typography/index.d.cts +16 -0
- package/dist/typography/index.d.ts +16 -0
- package/dist/typography/index.js +1099 -0
- package/dist/typography/metrics.d.cts +31 -0
- package/dist/typography/metrics.d.ts +31 -0
- package/dist/typography/picker.d.cts +132 -0
- package/dist/typography/picker.d.ts +132 -0
- package/dist/typography/registry.d.cts +66 -0
- package/dist/typography/registry.d.ts +66 -0
- package/dist/typography/scale.d.cts +62 -0
- package/dist/typography/scale.d.ts +62 -0
- package/dist/typography/segment.d.cts +26 -0
- package/dist/typography/segment.d.ts +26 -0
- package/dist/typography/stack.d.cts +26 -0
- package/dist/typography/stack.d.ts +26 -0
- package/dist/typography/tools.d.cts +34 -0
- package/dist/typography/tools.d.ts +34 -0
- package/dist/typography/types.d.cts +96 -0
- package/dist/typography/types.d.ts +96 -0
- package/dist/typography/weight.d.cts +13 -0
- package/dist/typography/weight.d.ts +13 -0
- package/dist/vector/index.cjs +950 -949
- package/dist/vector/index.js +5 -4
- package/dist/video-editor/audio.d.cts +9 -0
- package/dist/video-editor/audio.d.ts +9 -0
- package/dist/video-editor/check.d.cts +1 -1
- package/dist/video-editor/check.d.ts +1 -1
- package/dist/video-editor/controller.d.cts +47 -0
- package/dist/video-editor/controller.d.ts +47 -0
- package/dist/video-editor/dialogue-tools.d.cts +19 -0
- package/dist/video-editor/dialogue-tools.d.ts +19 -0
- package/dist/video-editor/effect-authoring.d.cts +54 -0
- package/dist/video-editor/effect-authoring.d.ts +54 -0
- package/dist/video-editor/evaluate.d.cts +11 -0
- package/dist/video-editor/evaluate.d.ts +11 -0
- package/dist/video-editor/export.d.cts +7 -1
- package/dist/video-editor/export.d.ts +7 -1
- package/dist/video-editor/index.cjs +1857 -531
- package/dist/video-editor/index.d.cts +7 -0
- package/dist/video-editor/index.d.ts +7 -0
- package/dist/video-editor/index.js +1516 -190
- package/dist/video-editor/lut.d.cts +12 -2
- package/dist/video-editor/lut.d.ts +12 -2
- package/dist/video-editor/mask.d.cts +48 -0
- package/dist/video-editor/mask.d.ts +48 -0
- package/dist/video-editor/mix.d.cts +107 -0
- package/dist/video-editor/mix.d.ts +107 -0
- package/dist/video-editor/music-tools.d.cts +19 -0
- package/dist/video-editor/music-tools.d.ts +19 -0
- package/dist/video-editor/parse.d.cts +3 -1
- package/dist/video-editor/parse.d.ts +3 -1
- package/dist/video-editor/plan.d.cts +75 -0
- package/dist/video-editor/plan.d.ts +75 -0
- package/dist/video-editor/render.d.cts +1 -1
- package/dist/video-editor/render.d.ts +1 -1
- package/dist/video-editor/timeline.d.cts +2 -0
- package/dist/video-editor/timeline.d.ts +2 -0
- package/dist/video-editor/tools.d.cts +90 -0
- package/dist/video-editor/tools.d.ts +90 -0
- package/dist/video-editor/transcript-controller.d.cts +106 -0
- package/dist/video-editor/transcript-controller.d.ts +106 -0
- package/dist/video-editor/transcript.d.cts +40 -0
- package/dist/video-editor/transcript.d.ts +40 -0
- package/dist/video-editor/types.d.cts +62 -2
- package/dist/video-editor/types.d.ts +62 -2
- package/dist/video-editor/ui.d.cts +21 -1
- package/dist/video-editor/ui.d.ts +21 -1
- package/package.json +11 -1
- package/skills/README.md +3 -0
- package/skills/pixerate-bgm-alignment/SKILL.md +82 -0
- package/skills/pixerate-talking-head-edit/SKILL.md +80 -0
- package/skills/pixerate-typography/SKILL.md +91 -0
- package/skills/pixerate-video-editor/SKILL.md +40 -2
package/dist/effects/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SYSTEM_FONT_CATALOG
|
|
3
|
+
} from "../chunk-CJE5MOIS.js";
|
|
4
|
+
import {
|
|
5
|
+
createEffectAuthoringSession
|
|
6
|
+
} from "../chunk-ZGOHKS3X.js";
|
|
1
7
|
import {
|
|
2
8
|
EffectRendererPool
|
|
3
9
|
} from "../chunk-EHLOCVWB.js";
|
|
@@ -25,13 +31,9 @@ import {
|
|
|
25
31
|
srgbToLinear
|
|
26
32
|
} from "../chunk-7KWJEYIK.js";
|
|
27
33
|
import "../chunk-V2ZCJRDM.js";
|
|
34
|
+
import "../chunk-RNSANXPT.js";
|
|
28
35
|
import {
|
|
29
|
-
|
|
30
|
-
} from "../chunk-RNSANXPT.js";
|
|
31
|
-
import {
|
|
32
|
-
ANIMATION_EASING_PRESETS,
|
|
33
|
-
evaluateEasing,
|
|
34
|
-
isAnimationEasing
|
|
36
|
+
ANIMATION_EASING_PRESETS
|
|
35
37
|
} from "../chunk-5UJHB3BW.js";
|
|
36
38
|
|
|
37
39
|
// src/effects/conformance.ts
|
|
@@ -213,756 +215,6 @@ async function checkEffectProvider(provider, options = {}) {
|
|
|
213
215
|
return issues;
|
|
214
216
|
}
|
|
215
217
|
|
|
216
|
-
// src/effects/authoring-session.ts
|
|
217
|
-
var HEX_RE = /^#([0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
218
|
-
function valueErrorMessage(errors) {
|
|
219
|
-
return errors.map((e) => {
|
|
220
|
-
const [control, ...rest] = e.path.replace(/^\//, "").split("/");
|
|
221
|
-
return `control "${control}"${rest.length ? ` (item ${rest.join("/")})` : ""}: ${e.message}`;
|
|
222
|
-
}).join("; ");
|
|
223
|
-
}
|
|
224
|
-
function documentErrors(doc, description) {
|
|
225
|
-
const errors = [];
|
|
226
|
-
const controls = Object.keys(description.controls.properties);
|
|
227
|
-
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
228
|
-
if (doc.values !== void 0) {
|
|
229
|
-
if (!isRecord(doc.values)) errors.push({ path: "/values", message: "must be an object of control values" });
|
|
230
|
-
else errors.push(...effectValueErrors(description, doc.values).map((e) => ({ ...e, path: `/values${e.path}` })));
|
|
231
|
-
}
|
|
232
|
-
if (doc.tracks !== void 0) {
|
|
233
|
-
if (!isRecord(doc.tracks)) errors.push({ path: "/tracks", message: "must be an object of keyframe lists" });
|
|
234
|
-
else
|
|
235
|
-
for (const [control, kfs] of Object.entries(doc.tracks)) {
|
|
236
|
-
const at = `/tracks/${control}`;
|
|
237
|
-
if (!controls.includes(control)) errors.push({ path: at, message: `there is no control "${control}"; the controls are ${controls.join(", ")}` });
|
|
238
|
-
else if (!Array.isArray(kfs)) errors.push({ path: at, message: "must be a list of keyframes" });
|
|
239
|
-
else
|
|
240
|
-
kfs.forEach((kf, i) => {
|
|
241
|
-
if (!isRecord(kf)) return errors.push({ path: `${at}/${i}`, message: "must be a keyframe object" });
|
|
242
|
-
if (typeof kf.time !== "number" || !Number.isFinite(kf.time) || kf.time < 0) errors.push({ path: `${at}/${i}/time`, message: "must be a finite number of ms >= 0" });
|
|
243
|
-
errors.push(...effectValueErrors(description, { [control]: kf.value }).map((e) => ({ ...e, path: `${at}/${i}/value` })));
|
|
244
|
-
if (kf.easing !== void 0 && !isAnimationEasing(kf.easing)) errors.push({ path: `${at}/${i}/easing`, message: "is not a valid easing" });
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
if (doc.presets !== void 0) {
|
|
249
|
-
if (!Array.isArray(doc.presets)) errors.push({ path: "/presets", message: "must be a list of presets" });
|
|
250
|
-
else
|
|
251
|
-
doc.presets.forEach((p, i) => {
|
|
252
|
-
if (!isRecord(p) || typeof p.name !== "string" || !p.name) return errors.push({ path: `/presets/${i}`, message: "must have a name" });
|
|
253
|
-
errors.push(...effectValueErrors(description, p.values).map((e) => ({ ...e, path: `/presets/${i}/values${e.path}` })));
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
if (doc.duration !== void 0 && (typeof doc.duration !== "number" || !Number.isFinite(doc.duration) || !(doc.duration > 0))) {
|
|
257
|
-
errors.push({ path: "/duration", message: "must be a finite number of ms > 0" });
|
|
258
|
-
}
|
|
259
|
-
if (doc.loop !== void 0 && typeof doc.loop !== "boolean") errors.push({ path: "/loop", message: "must be a boolean" });
|
|
260
|
-
return errors;
|
|
261
|
-
}
|
|
262
|
-
function parseHex(hex) {
|
|
263
|
-
if (!HEX_RE.test(hex)) return null;
|
|
264
|
-
const body = hex.slice(1);
|
|
265
|
-
const r = parseInt(body.slice(0, 2), 16);
|
|
266
|
-
const g = parseInt(body.slice(2, 4), 16);
|
|
267
|
-
const b = parseInt(body.slice(4, 6), 16);
|
|
268
|
-
const hasAlpha = body.length === 8;
|
|
269
|
-
const a = hasAlpha ? parseInt(body.slice(6, 8), 16) : 255;
|
|
270
|
-
return { r, g, b, a, hasAlpha };
|
|
271
|
-
}
|
|
272
|
-
function toHex2(n) {
|
|
273
|
-
const clamped = Math.round(Math.max(0, Math.min(255, n)));
|
|
274
|
-
return clamped.toString(16).padStart(2, "0");
|
|
275
|
-
}
|
|
276
|
-
function lerpHex(c1, c2, t) {
|
|
277
|
-
const p1 = parseHex(c1);
|
|
278
|
-
const p2 = parseHex(c2);
|
|
279
|
-
if (!p1 || !p2) return t >= 1 ? c2 : c1;
|
|
280
|
-
const r = p1.r + (p2.r - p1.r) * t;
|
|
281
|
-
const g = p1.g + (p2.g - p1.g) * t;
|
|
282
|
-
const b = p1.b + (p2.b - p1.b) * t;
|
|
283
|
-
const a = p1.a + (p2.a - p1.a) * t;
|
|
284
|
-
const withAlpha = p1.hasAlpha || p2.hasAlpha;
|
|
285
|
-
return `#${toHex2(r)}${toHex2(g)}${toHex2(b)}${withAlpha ? toHex2(a) : ""}`;
|
|
286
|
-
}
|
|
287
|
-
function interpolateValue(v1, v2, progress) {
|
|
288
|
-
if (typeof v1 === "number" && typeof v2 === "number") {
|
|
289
|
-
return v1 + (v2 - v1) * progress;
|
|
290
|
-
}
|
|
291
|
-
if (Array.isArray(v1) && Array.isArray(v2) && v1.length === v2.length) {
|
|
292
|
-
return v1.map((num, i) => {
|
|
293
|
-
const other = v2[i];
|
|
294
|
-
return typeof num === "number" && typeof other === "number" ? num + (other - num) * progress : num;
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
if (typeof v1 === "string" && typeof v2 === "string" && v1.startsWith("#") && v2.startsWith("#")) {
|
|
298
|
-
return lerpHex(v1, v2, progress);
|
|
299
|
-
}
|
|
300
|
-
return progress >= 1 ? v2 : v1;
|
|
301
|
-
}
|
|
302
|
-
function valuesAtTime(time, baseValues, tracks) {
|
|
303
|
-
const result = { ...baseValues };
|
|
304
|
-
for (const [control, kfs] of Object.entries(tracks)) {
|
|
305
|
-
if (!kfs || kfs.length === 0) continue;
|
|
306
|
-
if (kfs.length === 1) {
|
|
307
|
-
result[control] = kfs[0].value;
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
if (time <= kfs[0].time) {
|
|
311
|
-
result[control] = kfs[0].value;
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
const last = kfs[kfs.length - 1];
|
|
315
|
-
if (time >= last.time) {
|
|
316
|
-
result[control] = last.value;
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
let idx = 0;
|
|
320
|
-
while (idx < kfs.length - 1 && kfs[idx + 1].time <= time) {
|
|
321
|
-
idx++;
|
|
322
|
-
}
|
|
323
|
-
const kf1 = kfs[idx];
|
|
324
|
-
const kf2 = kfs[idx + 1];
|
|
325
|
-
const span = kf2.time - kf1.time;
|
|
326
|
-
const rawProgress = span > 0 ? (time - kf1.time) / span : 0;
|
|
327
|
-
const easing = kf1.easing ?? "linear";
|
|
328
|
-
const eased = evaluateEasing(easing, rawProgress);
|
|
329
|
-
result[control] = interpolateValue(kf1.value, kf2.value, eased);
|
|
330
|
-
}
|
|
331
|
-
return result;
|
|
332
|
-
}
|
|
333
|
-
var defaultSchedule = (frame) => {
|
|
334
|
-
if (typeof requestAnimationFrame === "function") {
|
|
335
|
-
let handle2;
|
|
336
|
-
let running2 = true;
|
|
337
|
-
const tick2 = (now) => {
|
|
338
|
-
if (!running2) return;
|
|
339
|
-
frame(now);
|
|
340
|
-
if (running2) handle2 = requestAnimationFrame(tick2);
|
|
341
|
-
};
|
|
342
|
-
handle2 = requestAnimationFrame(tick2);
|
|
343
|
-
return () => {
|
|
344
|
-
running2 = false;
|
|
345
|
-
cancelAnimationFrame(handle2);
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
let handle;
|
|
349
|
-
let running = true;
|
|
350
|
-
const interval = 16;
|
|
351
|
-
const tick = () => {
|
|
352
|
-
if (!running) return;
|
|
353
|
-
frame(Date.now());
|
|
354
|
-
if (running) handle = setTimeout(tick, interval);
|
|
355
|
-
};
|
|
356
|
-
handle = setTimeout(tick, interval);
|
|
357
|
-
return () => {
|
|
358
|
-
running = false;
|
|
359
|
-
clearTimeout(handle);
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
function isDocumentSource(source) {
|
|
363
|
-
return "document" in source && typeof source.document === "object" && source.document !== null;
|
|
364
|
-
}
|
|
365
|
-
async function createEffectAuthoringSession(source, options) {
|
|
366
|
-
const { provider, history = new HistoryManager(), mergeWindowMs = 400 } = options;
|
|
367
|
-
const scheduleFn = options.schedule ?? defaultSchedule;
|
|
368
|
-
let effectId;
|
|
369
|
-
let requestedPreset;
|
|
370
|
-
let initialDoc = null;
|
|
371
|
-
if (isDocumentSource(source)) {
|
|
372
|
-
const doc = source.document;
|
|
373
|
-
if (doc.version !== 1 || !doc.effectId) {
|
|
374
|
-
throw new EffectUnsupportedError("Invalid effect authoring document: version 1 required");
|
|
375
|
-
}
|
|
376
|
-
effectId = doc.effectId;
|
|
377
|
-
initialDoc = doc;
|
|
378
|
-
} else if ("effectId" in source && typeof source.effectId === "string") {
|
|
379
|
-
effectId = source.effectId;
|
|
380
|
-
requestedPreset = source.preset;
|
|
381
|
-
} else {
|
|
382
|
-
throw new EffectUnsupportedError("Invalid effect authoring source");
|
|
383
|
-
}
|
|
384
|
-
const description = await provider.describe(effectId);
|
|
385
|
-
if (initialDoc) {
|
|
386
|
-
const problems = documentErrors(initialDoc, description);
|
|
387
|
-
if (problems.length) throw new EffectControlError(effectId, problems);
|
|
388
|
-
}
|
|
389
|
-
if (description.kind === "motion") {
|
|
390
|
-
throw new EffectUnsupportedError("Motion effects cannot be authored as pixel effects", effectId);
|
|
391
|
-
}
|
|
392
|
-
let disposed = false;
|
|
393
|
-
let playing = false;
|
|
394
|
-
let cancelSchedule = null;
|
|
395
|
-
let lastScheduleTime = null;
|
|
396
|
-
let playheadTime = 0;
|
|
397
|
-
let duration = initialDoc?.duration ?? description.duration ?? 1e3;
|
|
398
|
-
if (!(duration > 0)) duration = 1e3;
|
|
399
|
-
let loop = initialDoc?.loop ?? description.loop ?? false;
|
|
400
|
-
let compiled = null;
|
|
401
|
-
let savedPresets = initialDoc ? [...initialDoc.presets ?? []] : [];
|
|
402
|
-
let baseValues = { ...description.defaults };
|
|
403
|
-
if (initialDoc?.values) {
|
|
404
|
-
baseValues = { ...baseValues, ...initialDoc.values };
|
|
405
|
-
} else if (requestedPreset) {
|
|
406
|
-
const found = description.presets.find((p) => p.name === requestedPreset);
|
|
407
|
-
if (!found) {
|
|
408
|
-
const validNames = description.presets.map((p) => `"${p.name}"`).join(", ");
|
|
409
|
-
throw new EffectUnsupportedError(
|
|
410
|
-
`Unknown preset "${requestedPreset}" for effect "${effectId}". Valid presets are: ${validNames || "none"}`,
|
|
411
|
-
effectId
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
baseValues = { ...baseValues, ...found.values };
|
|
415
|
-
}
|
|
416
|
-
let tracks = {};
|
|
417
|
-
if (initialDoc?.tracks) {
|
|
418
|
-
for (const [k, kfs] of Object.entries(initialDoc.tracks)) {
|
|
419
|
-
tracks[k] = [...kfs].sort((a, b) => a.time - b.time);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
const livePreviews = /* @__PURE__ */ new Set();
|
|
423
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
424
|
-
let cachedState = null;
|
|
425
|
-
function mergePresets() {
|
|
426
|
-
const result = [];
|
|
427
|
-
const seen = /* @__PURE__ */ new Set();
|
|
428
|
-
for (const p of savedPresets) {
|
|
429
|
-
result.push(p);
|
|
430
|
-
seen.add(p.name);
|
|
431
|
-
}
|
|
432
|
-
for (const p of description.presets) {
|
|
433
|
-
if (!seen.has(p.name)) {
|
|
434
|
-
result.push(p);
|
|
435
|
-
seen.add(p.name);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return result;
|
|
439
|
-
}
|
|
440
|
-
function currentMergedDescription() {
|
|
441
|
-
return {
|
|
442
|
-
...description,
|
|
443
|
-
presets: mergePresets()
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
function buildState() {
|
|
447
|
-
const desc = currentMergedDescription();
|
|
448
|
-
const currentValues = valuesAtTime(playheadTime, baseValues, tracks);
|
|
449
|
-
const historyState = history.getState();
|
|
450
|
-
return {
|
|
451
|
-
providerId: provider.id,
|
|
452
|
-
effectId,
|
|
453
|
-
name: initialDoc?.name ?? description.name,
|
|
454
|
-
kind: description.kind,
|
|
455
|
-
description: desc,
|
|
456
|
-
source: null,
|
|
457
|
-
sourceLanguage: null,
|
|
458
|
-
values: currentValues,
|
|
459
|
-
tracks: { ...tracks },
|
|
460
|
-
issues: [],
|
|
461
|
-
compiled,
|
|
462
|
-
time: playheadTime,
|
|
463
|
-
duration,
|
|
464
|
-
loop,
|
|
465
|
-
playing,
|
|
466
|
-
canUndo: historyState.canUndo,
|
|
467
|
-
canRedo: historyState.canRedo
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
function getState() {
|
|
471
|
-
if (!cachedState) {
|
|
472
|
-
cachedState = buildState();
|
|
473
|
-
}
|
|
474
|
-
return cachedState;
|
|
475
|
-
}
|
|
476
|
-
function invalidateState() {
|
|
477
|
-
cachedState = null;
|
|
478
|
-
const next = getState();
|
|
479
|
-
listeners.forEach((l) => l(next));
|
|
480
|
-
}
|
|
481
|
-
function validControlNames() {
|
|
482
|
-
return Object.keys(description.controls.properties);
|
|
483
|
-
}
|
|
484
|
-
function checkDisposed() {
|
|
485
|
-
if (disposed) {
|
|
486
|
-
return { ok: false, message: "the session is closed" };
|
|
487
|
-
}
|
|
488
|
-
return null;
|
|
489
|
-
}
|
|
490
|
-
function pauseInternal() {
|
|
491
|
-
if (!playing) return;
|
|
492
|
-
playing = false;
|
|
493
|
-
if (cancelSchedule) {
|
|
494
|
-
cancelSchedule();
|
|
495
|
-
cancelSchedule = null;
|
|
496
|
-
}
|
|
497
|
-
lastScheduleTime = null;
|
|
498
|
-
invalidateState();
|
|
499
|
-
}
|
|
500
|
-
function seekInternal(t) {
|
|
501
|
-
const clamped = Math.max(0, Math.min(duration, t));
|
|
502
|
-
if (clamped !== playheadTime) {
|
|
503
|
-
playheadTime = clamped;
|
|
504
|
-
invalidateState();
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
const session = {
|
|
508
|
-
getState,
|
|
509
|
-
subscribe(listener) {
|
|
510
|
-
listeners.add(listener);
|
|
511
|
-
return () => {
|
|
512
|
-
listeners.delete(listener);
|
|
513
|
-
};
|
|
514
|
-
},
|
|
515
|
-
setValue(name, value, opts) {
|
|
516
|
-
const disp = checkDisposed();
|
|
517
|
-
if (disp) return disp;
|
|
518
|
-
const validNames = validControlNames();
|
|
519
|
-
if (!validNames.includes(name)) {
|
|
520
|
-
return { ok: false, message: `there is no control "${name}"; the controls are ${validNames.join(", ")}` };
|
|
521
|
-
}
|
|
522
|
-
const errors = effectValueErrors(description, { [name]: value });
|
|
523
|
-
if (errors.length > 0) {
|
|
524
|
-
return { ok: false, message: valueErrorMessage(errors) };
|
|
525
|
-
}
|
|
526
|
-
const isAnimated = (tracks[name]?.length ?? 0) > 0;
|
|
527
|
-
if (isAnimated) {
|
|
528
|
-
const oldTracks = { ...tracks };
|
|
529
|
-
const t = playheadTime;
|
|
530
|
-
const currentTrack = [...tracks[name] ?? []];
|
|
531
|
-
const existingIdx = currentTrack.findIndex((kf) => kf.time === t);
|
|
532
|
-
const prevKf = existingIdx >= 0 ? currentTrack[existingIdx] : void 0;
|
|
533
|
-
const execute2 = () => {
|
|
534
|
-
const track = [...tracks[name] ?? []];
|
|
535
|
-
const idx = track.findIndex((kf) => kf.time === t);
|
|
536
|
-
if (idx >= 0) {
|
|
537
|
-
track[idx] = { ...track[idx], value };
|
|
538
|
-
} else {
|
|
539
|
-
track.push({ time: t, value });
|
|
540
|
-
track.sort((a, b) => a.time - b.time);
|
|
541
|
-
}
|
|
542
|
-
tracks[name] = track;
|
|
543
|
-
invalidateState();
|
|
544
|
-
};
|
|
545
|
-
const undo2 = () => {
|
|
546
|
-
tracks = { ...oldTracks };
|
|
547
|
-
invalidateState();
|
|
548
|
-
};
|
|
549
|
-
const cmd2 = {
|
|
550
|
-
name: `Set ${name}`,
|
|
551
|
-
tag: name,
|
|
552
|
-
execute: execute2,
|
|
553
|
-
undo: undo2
|
|
554
|
-
};
|
|
555
|
-
if (opts?.gesture) {
|
|
556
|
-
history.executeMerged(cmd2, { key: opts.gesture });
|
|
557
|
-
} else {
|
|
558
|
-
history.executeMerged(cmd2, { windowMs: mergeWindowMs });
|
|
559
|
-
}
|
|
560
|
-
invalidateState();
|
|
561
|
-
return { ok: true };
|
|
562
|
-
}
|
|
563
|
-
const prevVal = baseValues[name];
|
|
564
|
-
const execute = () => {
|
|
565
|
-
baseValues[name] = value;
|
|
566
|
-
};
|
|
567
|
-
const undo = () => {
|
|
568
|
-
baseValues[name] = prevVal;
|
|
569
|
-
};
|
|
570
|
-
const cmd = {
|
|
571
|
-
name: `Set ${name}`,
|
|
572
|
-
tag: name,
|
|
573
|
-
execute,
|
|
574
|
-
undo
|
|
575
|
-
};
|
|
576
|
-
if (opts?.gesture) {
|
|
577
|
-
history.executeMerged(cmd, { key: opts.gesture });
|
|
578
|
-
} else {
|
|
579
|
-
history.executeMerged(cmd, { windowMs: mergeWindowMs });
|
|
580
|
-
}
|
|
581
|
-
invalidateState();
|
|
582
|
-
return { ok: true };
|
|
583
|
-
},
|
|
584
|
-
setValues(values, opts) {
|
|
585
|
-
const disp = checkDisposed();
|
|
586
|
-
if (disp) return disp;
|
|
587
|
-
const validNames = validControlNames();
|
|
588
|
-
for (const [k, v] of Object.entries(values)) {
|
|
589
|
-
if (!validNames.includes(k)) {
|
|
590
|
-
return { ok: false, message: `there is no control "${k}"; the controls are ${validNames.join(", ")}` };
|
|
591
|
-
}
|
|
592
|
-
const errors = effectValueErrors(description, { [k]: v });
|
|
593
|
-
if (errors.length > 0) {
|
|
594
|
-
return { ok: false, message: valueErrorMessage(errors) };
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
const prevBase = { ...baseValues };
|
|
598
|
-
const prevTracks = { ...tracks };
|
|
599
|
-
const t = playheadTime;
|
|
600
|
-
const execute = () => {
|
|
601
|
-
for (const [k, v] of Object.entries(values)) {
|
|
602
|
-
const isAnimated = (tracks[k]?.length ?? 0) > 0;
|
|
603
|
-
if (isAnimated) {
|
|
604
|
-
const track = [...tracks[k] ?? []];
|
|
605
|
-
const idx = track.findIndex((kf) => kf.time === t);
|
|
606
|
-
if (idx >= 0) {
|
|
607
|
-
track[idx] = { ...track[idx], value: v };
|
|
608
|
-
} else {
|
|
609
|
-
track.push({ time: t, value: v });
|
|
610
|
-
track.sort((a, b) => a.time - b.time);
|
|
611
|
-
}
|
|
612
|
-
tracks[k] = track;
|
|
613
|
-
} else {
|
|
614
|
-
baseValues[k] = v;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
const undo = () => {
|
|
619
|
-
baseValues = { ...prevBase };
|
|
620
|
-
tracks = { ...prevTracks };
|
|
621
|
-
};
|
|
622
|
-
const cmd = {
|
|
623
|
-
name: "Set values",
|
|
624
|
-
execute,
|
|
625
|
-
undo
|
|
626
|
-
};
|
|
627
|
-
if (opts?.gesture) {
|
|
628
|
-
history.executeMerged(cmd, { key: opts.gesture });
|
|
629
|
-
} else {
|
|
630
|
-
history.execute(cmd);
|
|
631
|
-
}
|
|
632
|
-
invalidateState();
|
|
633
|
-
return { ok: true };
|
|
634
|
-
},
|
|
635
|
-
resetValues(names) {
|
|
636
|
-
const disp = checkDisposed();
|
|
637
|
-
if (disp) return disp;
|
|
638
|
-
const targets = names ? [...names] : validControlNames();
|
|
639
|
-
const prevBase = { ...baseValues };
|
|
640
|
-
const prevTracks = { ...tracks };
|
|
641
|
-
const execute = () => {
|
|
642
|
-
for (const name of targets) {
|
|
643
|
-
if (name in description.defaults) {
|
|
644
|
-
baseValues[name] = description.defaults[name];
|
|
645
|
-
}
|
|
646
|
-
delete tracks[name];
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
const undo = () => {
|
|
650
|
-
baseValues = { ...prevBase };
|
|
651
|
-
tracks = { ...prevTracks };
|
|
652
|
-
};
|
|
653
|
-
history.execute({
|
|
654
|
-
name: "Reset values",
|
|
655
|
-
execute,
|
|
656
|
-
undo
|
|
657
|
-
});
|
|
658
|
-
invalidateState();
|
|
659
|
-
return { ok: true };
|
|
660
|
-
},
|
|
661
|
-
applyPreset(name) {
|
|
662
|
-
const disp = checkDisposed();
|
|
663
|
-
if (disp) return disp;
|
|
664
|
-
const allPresets = mergePresets();
|
|
665
|
-
const preset = allPresets.find((p) => p.name === name);
|
|
666
|
-
if (!preset) {
|
|
667
|
-
const available = allPresets.map((p) => `"${p.name}"`).join(", ");
|
|
668
|
-
return { ok: false, message: `unknown preset "${name}"; available presets are: ${available || "none"}` };
|
|
669
|
-
}
|
|
670
|
-
const prevBase = { ...baseValues };
|
|
671
|
-
const prevTracks = { ...tracks };
|
|
672
|
-
const execute = () => {
|
|
673
|
-
for (const [k, v] of Object.entries(preset.values)) {
|
|
674
|
-
baseValues[k] = v;
|
|
675
|
-
delete tracks[k];
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
const undo = () => {
|
|
679
|
-
baseValues = { ...prevBase };
|
|
680
|
-
tracks = { ...prevTracks };
|
|
681
|
-
};
|
|
682
|
-
history.execute({
|
|
683
|
-
name: `Apply preset "${name}"`,
|
|
684
|
-
execute,
|
|
685
|
-
undo
|
|
686
|
-
});
|
|
687
|
-
invalidateState();
|
|
688
|
-
return { ok: true };
|
|
689
|
-
},
|
|
690
|
-
savePreset(name) {
|
|
691
|
-
const disp = checkDisposed();
|
|
692
|
-
if (disp) return disp;
|
|
693
|
-
if (!name || !name.trim()) {
|
|
694
|
-
return { ok: false, message: "preset name cannot be empty" };
|
|
695
|
-
}
|
|
696
|
-
const trimmed = name.trim();
|
|
697
|
-
const currentValues = valuesAtTime(playheadTime, baseValues, tracks);
|
|
698
|
-
const prevSaved = [...savedPresets];
|
|
699
|
-
const execute = () => {
|
|
700
|
-
const next = savedPresets.filter((p) => p.name !== trimmed);
|
|
701
|
-
next.push({ name: trimmed, values: { ...currentValues } });
|
|
702
|
-
savedPresets = next;
|
|
703
|
-
};
|
|
704
|
-
const undo = () => {
|
|
705
|
-
savedPresets = [...prevSaved];
|
|
706
|
-
};
|
|
707
|
-
history.execute({
|
|
708
|
-
name: `Save preset "${trimmed}"`,
|
|
709
|
-
execute,
|
|
710
|
-
undo
|
|
711
|
-
});
|
|
712
|
-
invalidateState();
|
|
713
|
-
return { ok: true };
|
|
714
|
-
},
|
|
715
|
-
setKeyframe(name, time, value, easing) {
|
|
716
|
-
const disp = checkDisposed();
|
|
717
|
-
if (disp) return disp;
|
|
718
|
-
const validNames = validControlNames();
|
|
719
|
-
if (!validNames.includes(name)) {
|
|
720
|
-
return { ok: false, message: `there is no control "${name}"; the controls are ${validNames.join(", ")}` };
|
|
721
|
-
}
|
|
722
|
-
if (typeof time !== "number" || !Number.isFinite(time) || time < 0) {
|
|
723
|
-
return { ok: false, message: "keyframe time must be a finite number >= 0" };
|
|
724
|
-
}
|
|
725
|
-
if (easing !== void 0 && !isAnimationEasing(easing)) {
|
|
726
|
-
return { ok: false, message: `invalid easing: ${String(easing)}` };
|
|
727
|
-
}
|
|
728
|
-
const targetValue = value !== void 0 ? value : valuesAtTime(time, baseValues, tracks)[name];
|
|
729
|
-
const errors = effectValueErrors(description, { [name]: targetValue });
|
|
730
|
-
if (errors.length > 0) {
|
|
731
|
-
return { ok: false, message: valueErrorMessage(errors) };
|
|
732
|
-
}
|
|
733
|
-
const prevTrack = tracks[name] ? [...tracks[name]] : void 0;
|
|
734
|
-
const execute = () => {
|
|
735
|
-
const track = prevTrack ? [...prevTrack] : [];
|
|
736
|
-
const idx = track.findIndex((kf2) => kf2.time === time);
|
|
737
|
-
const kf = {
|
|
738
|
-
time,
|
|
739
|
-
value: targetValue,
|
|
740
|
-
...easing !== void 0 ? { easing } : {}
|
|
741
|
-
};
|
|
742
|
-
if (idx >= 0) {
|
|
743
|
-
track[idx] = kf;
|
|
744
|
-
} else {
|
|
745
|
-
track.push(kf);
|
|
746
|
-
track.sort((a, b) => a.time - b.time);
|
|
747
|
-
}
|
|
748
|
-
tracks[name] = track;
|
|
749
|
-
};
|
|
750
|
-
const undo = () => {
|
|
751
|
-
if (prevTrack === void 0) {
|
|
752
|
-
delete tracks[name];
|
|
753
|
-
} else {
|
|
754
|
-
tracks[name] = [...prevTrack];
|
|
755
|
-
}
|
|
756
|
-
};
|
|
757
|
-
history.execute({
|
|
758
|
-
name: `Set keyframe on ${name}`,
|
|
759
|
-
execute,
|
|
760
|
-
undo
|
|
761
|
-
});
|
|
762
|
-
invalidateState();
|
|
763
|
-
return { ok: true };
|
|
764
|
-
},
|
|
765
|
-
removeKeyframe(name, time) {
|
|
766
|
-
const disp = checkDisposed();
|
|
767
|
-
if (disp) return disp;
|
|
768
|
-
const validNames = validControlNames();
|
|
769
|
-
if (!validNames.includes(name)) {
|
|
770
|
-
return { ok: false, message: `there is no control "${name}"; the controls are ${validNames.join(", ")}` };
|
|
771
|
-
}
|
|
772
|
-
const track = tracks[name];
|
|
773
|
-
if (!track || !track.some((kf) => kf.time === time)) {
|
|
774
|
-
const times = track?.map((kf) => `${kf.time}`).join(", ");
|
|
775
|
-
return {
|
|
776
|
-
ok: false,
|
|
777
|
-
message: times ? `no keyframe at ${time} ms on control "${name}"; its keyframes are at ${times} ms` : `control "${name}" has no keyframes`
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
const prevTrack = [...track];
|
|
781
|
-
const execute = () => {
|
|
782
|
-
const next = tracks[name].filter((kf) => kf.time !== time);
|
|
783
|
-
if (next.length === 0) {
|
|
784
|
-
delete tracks[name];
|
|
785
|
-
} else {
|
|
786
|
-
tracks[name] = next;
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
const undo = () => {
|
|
790
|
-
tracks[name] = [...prevTrack];
|
|
791
|
-
};
|
|
792
|
-
history.execute({
|
|
793
|
-
name: `Remove keyframe on ${name}`,
|
|
794
|
-
execute,
|
|
795
|
-
undo
|
|
796
|
-
});
|
|
797
|
-
invalidateState();
|
|
798
|
-
return { ok: true };
|
|
799
|
-
},
|
|
800
|
-
clearTrack(name) {
|
|
801
|
-
const disp = checkDisposed();
|
|
802
|
-
if (disp) return disp;
|
|
803
|
-
const validNames = validControlNames();
|
|
804
|
-
if (!validNames.includes(name)) {
|
|
805
|
-
return { ok: false, message: `there is no control "${name}"; the controls are ${validNames.join(", ")}` };
|
|
806
|
-
}
|
|
807
|
-
const prevTrack = tracks[name] ? [...tracks[name]] : void 0;
|
|
808
|
-
if (!prevTrack || prevTrack.length === 0) {
|
|
809
|
-
const animated = Object.keys(tracks).filter((k) => tracks[k]?.length);
|
|
810
|
-
return {
|
|
811
|
-
ok: false,
|
|
812
|
-
message: `control "${name}" is not animated, so there is nothing to clear; ${animated.length ? `the animated controls are ${animated.join(", ")}` : "no control is animated"}`
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
const currentValue = valuesAtTime(playheadTime, baseValues, tracks)[name];
|
|
816
|
-
const prevBase = baseValues[name];
|
|
817
|
-
const execute = () => {
|
|
818
|
-
delete tracks[name];
|
|
819
|
-
baseValues[name] = currentValue;
|
|
820
|
-
};
|
|
821
|
-
const undo = () => {
|
|
822
|
-
tracks[name] = [...prevTrack];
|
|
823
|
-
baseValues[name] = prevBase;
|
|
824
|
-
};
|
|
825
|
-
history.execute({
|
|
826
|
-
name: `Clear animation on ${name}`,
|
|
827
|
-
execute,
|
|
828
|
-
undo
|
|
829
|
-
});
|
|
830
|
-
invalidateState();
|
|
831
|
-
return { ok: true };
|
|
832
|
-
},
|
|
833
|
-
setTiming(timing) {
|
|
834
|
-
const disp = checkDisposed();
|
|
835
|
-
if (disp) return disp;
|
|
836
|
-
if (timing.duration !== void 0 && (!(timing.duration > 0) || !Number.isFinite(timing.duration))) {
|
|
837
|
-
return { ok: false, message: "duration must be a finite number > 0" };
|
|
838
|
-
}
|
|
839
|
-
const prevDuration = duration;
|
|
840
|
-
const prevLoop = loop;
|
|
841
|
-
const prevTime = playheadTime;
|
|
842
|
-
const execute = () => {
|
|
843
|
-
if (timing.duration !== void 0) {
|
|
844
|
-
duration = timing.duration;
|
|
845
|
-
if (playheadTime > duration) playheadTime = duration;
|
|
846
|
-
}
|
|
847
|
-
if (timing.loop !== void 0) {
|
|
848
|
-
loop = timing.loop;
|
|
849
|
-
}
|
|
850
|
-
};
|
|
851
|
-
const undo = () => {
|
|
852
|
-
duration = prevDuration;
|
|
853
|
-
loop = prevLoop;
|
|
854
|
-
playheadTime = prevTime;
|
|
855
|
-
};
|
|
856
|
-
history.execute({
|
|
857
|
-
name: "Set timing",
|
|
858
|
-
execute,
|
|
859
|
-
undo
|
|
860
|
-
});
|
|
861
|
-
invalidateState();
|
|
862
|
-
return { ok: true };
|
|
863
|
-
},
|
|
864
|
-
play() {
|
|
865
|
-
if (disposed || playing) return;
|
|
866
|
-
playing = true;
|
|
867
|
-
lastScheduleTime = null;
|
|
868
|
-
cancelSchedule = scheduleFn((now) => {
|
|
869
|
-
if (!playing) return;
|
|
870
|
-
const delta = lastScheduleTime === null ? 0 : Math.max(0, now - lastScheduleTime);
|
|
871
|
-
lastScheduleTime = now;
|
|
872
|
-
let nextTime = playheadTime + delta;
|
|
873
|
-
if (nextTime >= duration) {
|
|
874
|
-
if (loop) {
|
|
875
|
-
nextTime = duration > 0 ? nextTime % duration : 0;
|
|
876
|
-
} else {
|
|
877
|
-
nextTime = duration;
|
|
878
|
-
pauseInternal();
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
seekInternal(nextTime);
|
|
882
|
-
});
|
|
883
|
-
invalidateState();
|
|
884
|
-
},
|
|
885
|
-
pause() {
|
|
886
|
-
pauseInternal();
|
|
887
|
-
},
|
|
888
|
-
seek(time) {
|
|
889
|
-
if (disposed) return;
|
|
890
|
-
seekInternal(time);
|
|
891
|
-
},
|
|
892
|
-
undo() {
|
|
893
|
-
if (disposed) return false;
|
|
894
|
-
const changed = history.undo();
|
|
895
|
-
if (changed) invalidateState();
|
|
896
|
-
return changed;
|
|
897
|
-
},
|
|
898
|
-
redo() {
|
|
899
|
-
if (disposed) return false;
|
|
900
|
-
const changed = history.redo();
|
|
901
|
-
if (changed) invalidateState();
|
|
902
|
-
return changed;
|
|
903
|
-
},
|
|
904
|
-
async createPreview(opts) {
|
|
905
|
-
if (disposed) {
|
|
906
|
-
throw new EffectDisposedError(effectId);
|
|
907
|
-
}
|
|
908
|
-
const renderer = await provider.createRenderer(effectId, opts);
|
|
909
|
-
livePreviews.add(renderer);
|
|
910
|
-
const preview = {
|
|
911
|
-
effectId: renderer.effectId,
|
|
912
|
-
width: renderer.width,
|
|
913
|
-
height: renderer.height,
|
|
914
|
-
depth: renderer.depth,
|
|
915
|
-
render: async (req) => {
|
|
916
|
-
if (disposed) throw new EffectDisposedError(effectId);
|
|
917
|
-
const effectiveValues = req.values ?? valuesAtTime(req.time, baseValues, tracks);
|
|
918
|
-
const pixels = await renderer.render({
|
|
919
|
-
...req,
|
|
920
|
-
values: effectiveValues
|
|
921
|
-
});
|
|
922
|
-
if (compiled !== true) {
|
|
923
|
-
compiled = true;
|
|
924
|
-
invalidateState();
|
|
925
|
-
}
|
|
926
|
-
return pixels;
|
|
927
|
-
},
|
|
928
|
-
dispose: () => {
|
|
929
|
-
livePreviews.delete(renderer);
|
|
930
|
-
renderer.dispose();
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
return preview;
|
|
934
|
-
},
|
|
935
|
-
exportDocument() {
|
|
936
|
-
const currentValues = valuesAtTime(playheadTime, baseValues, tracks);
|
|
937
|
-
return {
|
|
938
|
-
version: 1,
|
|
939
|
-
providerId: provider.id,
|
|
940
|
-
effectId,
|
|
941
|
-
name: initialDoc?.name ?? description.name,
|
|
942
|
-
values: { ...currentValues },
|
|
943
|
-
tracks: JSON.parse(JSON.stringify(tracks)),
|
|
944
|
-
presets: JSON.parse(JSON.stringify(savedPresets)),
|
|
945
|
-
duration,
|
|
946
|
-
loop
|
|
947
|
-
};
|
|
948
|
-
},
|
|
949
|
-
dispose() {
|
|
950
|
-
if (disposed) return;
|
|
951
|
-
disposed = true;
|
|
952
|
-
pauseInternal();
|
|
953
|
-
listeners.clear();
|
|
954
|
-
for (const p of livePreviews) {
|
|
955
|
-
try {
|
|
956
|
-
p.dispose();
|
|
957
|
-
} catch {
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
livePreviews.clear();
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
return session;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
218
|
// src/effects/fake.ts
|
|
967
219
|
var HEX = "^#[0-9a-fA-F]{6}$";
|
|
968
220
|
var colour = (description) => ({ type: "string", pattern: HEX, description });
|
|
@@ -1334,13 +586,16 @@ var EFFECT_USE_LABELS = {
|
|
|
1334
586
|
};
|
|
1335
587
|
var HEX2 = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
|
|
1336
588
|
var typeOf = (s) => Array.isArray(s.type) ? s.type.find((t) => t !== "null") : s.type;
|
|
1337
|
-
function
|
|
589
|
+
function isEffectFontControl(schema) {
|
|
590
|
+
return typeOf(schema) === "string" && (schema.format === "font" || schema["x-pixerate-control"] === "font");
|
|
591
|
+
}
|
|
592
|
+
function effectControlField(name, schema, fallback, options = {}) {
|
|
1338
593
|
const base = { id: name, ...schema.title ? { label: schema.title } : {}, ...schema.description ? { description: schema.description } : {} };
|
|
1339
594
|
const def = schema.default ?? fallback;
|
|
1340
595
|
const type = typeOf(schema);
|
|
1341
596
|
if (Array.isArray(schema.enum) && schema.enum.length) {
|
|
1342
|
-
const
|
|
1343
|
-
return { ...base, type: "choice", options, default: typeof def === "string" || typeof def === "number" ? def :
|
|
597
|
+
const options2 = schema.enum.filter((v) => typeof v === "string" || typeof v === "number");
|
|
598
|
+
return { ...base, type: "choice", options: options2, default: typeof def === "string" || typeof def === "number" ? def : options2[0], control: options2.length <= 4 ? "segmented" : "select" };
|
|
1344
599
|
}
|
|
1345
600
|
if (type === "number" || type === "integer") {
|
|
1346
601
|
const min = schema.minimum ?? schema.exclusiveMinimum;
|
|
@@ -1348,6 +603,13 @@ function effectControlField(name, schema, fallback) {
|
|
|
1348
603
|
return { ...base, type: type === "integer" ? "int" : "number", default: typeof def === "number" ? def : min ?? 0, ...min !== void 0 ? { min } : {}, ...max !== void 0 ? { max } : {}, ...schema.multipleOf ? { step: schema.multipleOf } : {} };
|
|
1349
604
|
}
|
|
1350
605
|
if (type === "boolean") return { ...base, type: "boolean", default: def === true };
|
|
606
|
+
if (isEffectFontControl(schema)) {
|
|
607
|
+
const fonts = options.fonts ?? SYSTEM_FONT_CATALOG;
|
|
608
|
+
const opts = fonts.map((f) => ({ value: f.family, label: f.family, description: f.category }));
|
|
609
|
+
const current = typeof def === "string" && def ? def : opts[0]?.value ?? "sans-serif";
|
|
610
|
+
if (!opts.some((o) => o.value.toLowerCase() === current.toLowerCase())) opts.unshift({ value: current, label: current, description: "current" });
|
|
611
|
+
return { ...base, type: "choice", options: opts, default: opts.find((o) => o.value.toLowerCase() === current.toLowerCase()).value, control: "select" };
|
|
612
|
+
}
|
|
1351
613
|
if (type === "string") {
|
|
1352
614
|
if (typeof def === "string" && HEX2.test(def)) return { ...base, type: "color", alpha: def.length === 9, default: def };
|
|
1353
615
|
return { ...base, type: "text", default: typeof def === "string" ? def : "", ...schema.maxLength ? { maxLength: schema.maxLength } : {} };
|
|
@@ -1358,8 +620,17 @@ function effectControlField(name, schema, fallback) {
|
|
|
1358
620
|
}
|
|
1359
621
|
return null;
|
|
1360
622
|
}
|
|
1361
|
-
function effectParameterFields(description) {
|
|
1362
|
-
return Object.entries(description.controls.properties).map(([name, schema]) => effectControlField(name, schema, description.defaults[name])).filter((f) => !!f);
|
|
623
|
+
function effectParameterFields(description, options = {}) {
|
|
624
|
+
return Object.entries(description.controls.properties).map(([name, schema]) => effectControlField(name, schema, description.defaults[name], options)).filter((f) => !!f);
|
|
625
|
+
}
|
|
626
|
+
function effectFontFamilies(description, values = {}) {
|
|
627
|
+
const out = [];
|
|
628
|
+
for (const [name, schema] of Object.entries(description.controls.properties)) {
|
|
629
|
+
if (!isEffectFontControl(schema)) continue;
|
|
630
|
+
const v = values[name] ?? description.defaults[name] ?? schema.default;
|
|
631
|
+
if (typeof v === "string" && v && !out.includes(v)) out.push(v);
|
|
632
|
+
}
|
|
633
|
+
return out;
|
|
1363
634
|
}
|
|
1364
635
|
var effectFieldValue = (field, value) => value === void 0 || value === null || typeof value === "object" && !Array.isArray(value) ? field.default : value;
|
|
1365
636
|
function effectSamplePicture(width, height, variant = 0) {
|
|
@@ -1821,6 +1092,7 @@ export {
|
|
|
1821
1092
|
createFakeEffectProvider,
|
|
1822
1093
|
effectControlField,
|
|
1823
1094
|
effectFieldValue,
|
|
1095
|
+
effectFontFamilies,
|
|
1824
1096
|
effectParameterFields,
|
|
1825
1097
|
effectSampleInputs,
|
|
1826
1098
|
effectSamplePicture,
|
|
@@ -1828,6 +1100,7 @@ export {
|
|
|
1828
1100
|
encodeEffectFloat,
|
|
1829
1101
|
groupEffectsByCategory,
|
|
1830
1102
|
isEffectError,
|
|
1103
|
+
isEffectFontControl,
|
|
1831
1104
|
isEffectPixels,
|
|
1832
1105
|
linearToSrgb,
|
|
1833
1106
|
renderEffectThumbnail,
|