pixi-effects 0.30.0 → 0.31.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/CHANGELOG.md +25 -0
- package/README.md +6 -5
- package/ai/chat-template.html +3 -3
- package/ai/tools/check.mjs +42 -2
- package/ai/tools/lookup.mjs +12 -6
- package/ai/tools/render.mjs +15 -2
- package/ai/tools/varArgs.mjs +75 -0
- package/dist/{Base-CB1_FPZD.d.cts → Base-BKagtWc0.d.cts} +1 -1
- package/dist/{Base-Ne74ztNl.d.ts → Base-jRiMHcWT.d.ts} +1 -1
- package/dist/Composition-DQCPJPFE.js +7 -0
- package/dist/{Composition-RJGA7KDU.js.map → Composition-DQCPJPFE.js.map} +1 -1
- package/dist/Composition-V2XYSW6P.cjs +16 -0
- package/dist/{Composition-MUKR3FYD.cjs.map → Composition-V2XYSW6P.cjs.map} +1 -1
- package/dist/Controller.cjs +42 -1
- package/dist/Controller.cjs.map +1 -1
- package/dist/Controller.d.cts +10 -2
- package/dist/Controller.d.ts +10 -2
- package/dist/Controller.js +42 -1
- package/dist/Controller.js.map +1 -1
- package/dist/{Movie-DdnpLpw1.d.cts → Movie-BH81stkb.d.cts} +90 -3
- package/dist/{Movie-C2rZFkrO.d.ts → Movie-CfFPItoL.d.ts} +90 -3
- package/dist/{chunk-A3Q3SDSH.js → chunk-BGMCZA36.js} +3 -3
- package/dist/{chunk-A3Q3SDSH.js.map → chunk-BGMCZA36.js.map} +1 -1
- package/dist/{chunk-ZVUO325O.cjs → chunk-DJ5B7IKT.cjs} +9 -3
- package/dist/chunk-DJ5B7IKT.cjs.map +1 -0
- package/dist/{chunk-WHNADXXG.cjs → chunk-L73KRFXI.cjs} +61 -61
- package/dist/{chunk-WHNADXXG.cjs.map → chunk-L73KRFXI.cjs.map} +1 -1
- package/dist/{chunk-ZAXYPXKW.js → chunk-MMTESMJ5.js} +9 -4
- package/dist/chunk-MMTESMJ5.js.map +1 -0
- package/dist/{chunk-CRQFDY7E.js → chunk-UTIBYMIO.js} +461 -56
- package/dist/chunk-UTIBYMIO.js.map +1 -0
- package/dist/{chunk-HREBQAY4.cjs → chunk-X3WHETQ3.cjs} +485 -80
- package/dist/chunk-X3WHETQ3.cjs.map +1 -0
- package/dist/index.cjs +31 -31
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/loader.css +1 -1
- package/dist/present.cjs +3 -3
- package/dist/present.d.cts +2 -2
- package/dist/present.d.ts +2 -2
- package/dist/present.js +3 -3
- package/dist/three.cjs +5 -5
- package/dist/three.d.cts +2 -2
- package/dist/three.d.ts +2 -2
- package/dist/three.js +1 -1
- package/dist/{types-BzIB65Vk.d.cts → types-CK_crNAI.d.cts} +2 -0
- package/dist/{types-BzIB65Vk.d.ts → types-CK_crNAI.d.ts} +2 -0
- package/docs/api.md +28 -1
- package/docs/dsl.md +32 -1
- package/llms-full.txt +145 -11
- package/package.json +83 -20
- package/skills/pixi-effects/SKILL.md +1 -1
- package/skills/pixi-effects/reference/cheatsheet.md +3 -0
- package/skills/pixi-effects/reference/pitfalls.md +4 -0
- package/skills/pixi-effects/reference/recipes.md +79 -8
- package/skills/pixi-effects/template.html +6 -6
- package/dist/Composition-MUKR3FYD.cjs +0 -16
- package/dist/Composition-RJGA7KDU.js +0 -7
- package/dist/chunk-CRQFDY7E.js.map +0 -1
- package/dist/chunk-HREBQAY4.cjs.map +0 -1
- package/dist/chunk-ZAXYPXKW.js.map +0 -1
- package/dist/chunk-ZVUO325O.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CompositionSequence, maskSourceOf } from './chunk-
|
|
2
|
-
import { createTimeline, lengthen, ensureFilterLibrary, checkEase, parseEase, homeDistance, DEFAULT_FOV, random, noise, flattenSvgPath, rand, DEG, timeRemapOf, contentLength, resolveAt } from './chunk-
|
|
1
|
+
import { CompositionSequence, maskSourceOf } from './chunk-BGMCZA36.js';
|
|
2
|
+
import { EXPRESSION_NAMES, createTimeline, lengthen, ensureFilterLibrary, checkEase, parseEase, homeDistance, DEFAULT_FOV, random, noise, flattenSvgPath, rand, DEG, timeRemapOf, contentLength, resolveAt } from './chunk-MMTESMJ5.js';
|
|
3
3
|
import { usesAdvancedBlend, enableAdvancedBlend } from './chunk-4KB3GUEK.js';
|
|
4
4
|
import { collectPropKeys } from './chunk-RCVZX2JP.js';
|
|
5
5
|
import { warnUnknownOptions, suggestName } from './chunk-BXOCEZ4U.js';
|
|
@@ -2171,6 +2171,124 @@ function sheetLayout(n, columns, cellW, srcW, srcH, labelH) {
|
|
|
2171
2171
|
return { cols, rows, cellW, cellH, width: cols * cellW, height: rows * (cellH + labelH), positions };
|
|
2172
2172
|
}
|
|
2173
2173
|
|
|
2174
|
+
// src/core/vars.ts
|
|
2175
|
+
var RESERVED_NAMES = ["w", "h", "W", "H", "GW", "GH", "t", "d", "T", "contain", "cover", "value", ...EXPRESSION_NAMES];
|
|
2176
|
+
var NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
2177
|
+
var isPlain = (v) => !!v && typeof v === "object" && (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
|
|
2178
|
+
function normalizeVars(raw, where, warn = (m) => console.warn(m)) {
|
|
2179
|
+
if (raw === void 0) return {};
|
|
2180
|
+
if (!isPlain(raw)) {
|
|
2181
|
+
warn(`pixi-effects: ${where}: vars must be an object of names and values ({ title: 'NORD', shift: 40 }); ignored`);
|
|
2182
|
+
return {};
|
|
2183
|
+
}
|
|
2184
|
+
const out = {};
|
|
2185
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
2186
|
+
if (!NAME.test(name)) {
|
|
2187
|
+
warn(`pixi-effects: ${where}: "${name}" is not a name for a variable (letters, digits and _, not starting with a digit); ignored`);
|
|
2188
|
+
continue;
|
|
2189
|
+
}
|
|
2190
|
+
if (RESERVED_NAMES.includes(name)) {
|
|
2191
|
+
warn(`pixi-effects: ${where}: "${name}" is reserved (an expression word, a function, PI or the {value} counter); choose another name; ignored`);
|
|
2192
|
+
continue;
|
|
2193
|
+
}
|
|
2194
|
+
if (typeof value === "boolean") {
|
|
2195
|
+
warn(`pixi-effects: ${where}: variable "${name}" is a boolean; write 0 or 1 (a variable is a number or a string); ignored`);
|
|
2196
|
+
continue;
|
|
2197
|
+
}
|
|
2198
|
+
if (typeof value === "number" && Number.isFinite(value)) out[name] = value;
|
|
2199
|
+
else if (typeof value === "string") out[name] = value;
|
|
2200
|
+
else warn(`pixi-effects: ${where}: variable "${name}" must be a number or a string, got ${JSON.stringify(value)}; ignored`);
|
|
2201
|
+
}
|
|
2202
|
+
return out;
|
|
2203
|
+
}
|
|
2204
|
+
function numericVars(vars) {
|
|
2205
|
+
const out = {};
|
|
2206
|
+
for (const [k, v] of Object.entries(vars)) if (typeof v === "number") out[k] = v;
|
|
2207
|
+
return out;
|
|
2208
|
+
}
|
|
2209
|
+
var TOKEN = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
2210
|
+
function substitute(s, vars) {
|
|
2211
|
+
return s.replace(TOKEN, (whole, name) => Object.prototype.hasOwnProperty.call(vars, name) ? String(vars[name]) : whole);
|
|
2212
|
+
}
|
|
2213
|
+
function applyVars(spec, vars) {
|
|
2214
|
+
if (Object.keys(vars).length === 0) return spec;
|
|
2215
|
+
const walk2 = (v) => {
|
|
2216
|
+
if (typeof v === "string") return substitute(v, vars);
|
|
2217
|
+
if (Array.isArray(v)) return v.map(walk2);
|
|
2218
|
+
if (isPlain(v)) {
|
|
2219
|
+
const o = {};
|
|
2220
|
+
for (const [k, x] of Object.entries(v)) o[k] = walk2(x);
|
|
2221
|
+
return o;
|
|
2222
|
+
}
|
|
2223
|
+
return v;
|
|
2224
|
+
};
|
|
2225
|
+
return walk2(spec);
|
|
2226
|
+
}
|
|
2227
|
+
var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2228
|
+
function lintVars(spec, vars) {
|
|
2229
|
+
const declared = Object.keys(vars);
|
|
2230
|
+
const strings = [];
|
|
2231
|
+
const walk2 = (v) => {
|
|
2232
|
+
if (typeof v === "string") strings.push(v);
|
|
2233
|
+
else if (Array.isArray(v)) v.forEach(walk2);
|
|
2234
|
+
else if (isPlain(v)) Object.values(v).forEach(walk2);
|
|
2235
|
+
};
|
|
2236
|
+
walk2(spec);
|
|
2237
|
+
const out = [];
|
|
2238
|
+
for (const name of declared) {
|
|
2239
|
+
const word = new RegExp(`(?<![A-Za-z0-9_.])${escapeRe(name)}(?![A-Za-z0-9_])`);
|
|
2240
|
+
if (!strings.some((s) => word.test(s))) out.push(`pixi-effects: vars: variable "${name}" is declared but nothing uses it (write {${name}} in a string, or "${name}" in an expression); a typo on one side?`);
|
|
2241
|
+
}
|
|
2242
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2243
|
+
for (const s of strings) {
|
|
2244
|
+
for (const m of s.matchAll(TOKEN)) {
|
|
2245
|
+
const name = m[1];
|
|
2246
|
+
if (seen.has(name) || Object.prototype.hasOwnProperty.call(vars, name) || RESERVED_NAMES.includes(name) || declared.length === 0) continue;
|
|
2247
|
+
seen.add(name);
|
|
2248
|
+
const guess = suggestName(name, declared);
|
|
2249
|
+
out.push(`pixi-effects: vars: {${name}} is not a declared variable${guess ? ` \u2014 did you mean "${guess}"?` : ` (declared: ${declared.join(", ")})`}`);
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
return out;
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
// src/core/mixCache.ts
|
|
2256
|
+
var ids = /* @__PURE__ */ new WeakMap();
|
|
2257
|
+
var nextId = 1;
|
|
2258
|
+
var idOf = (o) => {
|
|
2259
|
+
let n = ids.get(o);
|
|
2260
|
+
if (!n) {
|
|
2261
|
+
n = nextId++;
|
|
2262
|
+
ids.set(o, n);
|
|
2263
|
+
}
|
|
2264
|
+
return n;
|
|
2265
|
+
};
|
|
2266
|
+
function mixKey(audios, duration, sampleRate) {
|
|
2267
|
+
const parts = [];
|
|
2268
|
+
for (const a of audios) {
|
|
2269
|
+
if (a.warp || a.sourceMap) return null;
|
|
2270
|
+
const what = a.buffer ? `b${idOf(a.buffer)}` : a.synth ? `s${a.synth.key}` : null;
|
|
2271
|
+
if (what === null) return null;
|
|
2272
|
+
parts.push([what, a.loop, a.start, a.end, a.initialVolume, a.volumeKeyframes.map((k) => [k.time, k.value])]);
|
|
2273
|
+
}
|
|
2274
|
+
return JSON.stringify([duration, sampleRate, parts]);
|
|
2275
|
+
}
|
|
2276
|
+
var MixCache = class {
|
|
2277
|
+
key = null;
|
|
2278
|
+
buffer = null;
|
|
2279
|
+
extra;
|
|
2280
|
+
get(key) {
|
|
2281
|
+
if (key === null || key !== this.key || !this.buffer) return null;
|
|
2282
|
+
return { buffer: this.buffer, extra: this.extra };
|
|
2283
|
+
}
|
|
2284
|
+
/** Keep this mix for `key`; a null key (not comparable) keeps nothing. */
|
|
2285
|
+
set(key, buffer, extra) {
|
|
2286
|
+
this.key = key;
|
|
2287
|
+
this.buffer = key === null ? null : buffer;
|
|
2288
|
+
this.extra = extra;
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
2291
|
+
|
|
2174
2292
|
// src/core/startWhenRunning.ts
|
|
2175
2293
|
function startWhenRunning(ctx, start, gesture) {
|
|
2176
2294
|
if (ctx.state === "running") {
|
|
@@ -2454,6 +2572,7 @@ var Movie = class {
|
|
|
2454
2572
|
_quiet = 0;
|
|
2455
2573
|
_volume = 1;
|
|
2456
2574
|
_muted = false;
|
|
2575
|
+
_loop = false;
|
|
2457
2576
|
isPlaying = false;
|
|
2458
2577
|
currentFrame = 0;
|
|
2459
2578
|
totalFrames = 0;
|
|
@@ -2475,6 +2594,21 @@ var Movie = class {
|
|
|
2475
2594
|
}
|
|
2476
2595
|
_rootContainer = null;
|
|
2477
2596
|
_raf = null;
|
|
2597
|
+
/** The variables now, and the names that were declared (a `setVars` of any other name is refused). */
|
|
2598
|
+
_vars = {};
|
|
2599
|
+
_declared = /* @__PURE__ */ new Set();
|
|
2600
|
+
/** The composition as the author wrote it (before `{name}` is replaced): a rebuild starts from it. */
|
|
2601
|
+
_composition;
|
|
2602
|
+
/** True once `resize()` was called: the size of the movie then replaces an explicit `width` / `height` of the composition. */
|
|
2603
|
+
_resized = false;
|
|
2604
|
+
_mixCache = new MixCache();
|
|
2605
|
+
_rebuildRun = null;
|
|
2606
|
+
_rebuildNext = null;
|
|
2607
|
+
/** > 0 while a rebuild stops and restarts playback: `play` / `pause` are not announced then (a player's button must not flicker). */
|
|
2608
|
+
_silent = 0;
|
|
2609
|
+
/** render() / peek() in flight: a rebuild does not swap the composition under them. */
|
|
2610
|
+
_busy = 0;
|
|
2611
|
+
_idleWaiters = [];
|
|
2478
2612
|
/** What went into the mix, and its peak before limiting — kept for inspectAudio(). */
|
|
2479
2613
|
_audioSources = [];
|
|
2480
2614
|
_mixStats = null;
|
|
@@ -2550,7 +2684,7 @@ var Movie = class {
|
|
|
2550
2684
|
return this._audioContext;
|
|
2551
2685
|
}
|
|
2552
2686
|
async init(options = {}) {
|
|
2553
|
-
warnUnknownOptions("movie.init()", options, ["width", "height", "duration", "frameRate", "background", "canvas", "assets", "composition", "poster", "motionBlur", "loader"]);
|
|
2687
|
+
warnUnknownOptions("movie.init()", options, ["width", "height", "duration", "frameRate", "background", "canvas", "assets", "composition", "vars", "poster", "motionBlur", "loader", "loop"]);
|
|
2554
2688
|
this._initState = "pending";
|
|
2555
2689
|
try {
|
|
2556
2690
|
this.width = options.width ?? 1920;
|
|
@@ -2561,7 +2695,14 @@ var Movie = class {
|
|
|
2561
2695
|
const poster = normalizePoster(options.poster, this.duration, this.frameRate);
|
|
2562
2696
|
this.poster = poster.seconds;
|
|
2563
2697
|
this.motionBlur = resolveMotionBlur(options.motionBlur, "movie.init()");
|
|
2564
|
-
this.
|
|
2698
|
+
this._loop = options.loop === true;
|
|
2699
|
+
this._vars = normalizeVars(options.vars, "movie.init()");
|
|
2700
|
+
this._declared = new Set(Object.keys(this._vars));
|
|
2701
|
+
this._composition = options.composition;
|
|
2702
|
+
this._resized = false;
|
|
2703
|
+
for (const w of lintVars(options.composition, this._vars)) console.warn(w);
|
|
2704
|
+
this._mixCache.set(null, null);
|
|
2705
|
+
this.stops = normalizeStops(applyVars(options.composition, this._vars)?.stops, this.duration, this.frameRate);
|
|
2565
2706
|
this._posterFrame = poster.frame;
|
|
2566
2707
|
this.background = options.background ?? "#000000";
|
|
2567
2708
|
this.timeline = createTimeline({ paused: true, defaults: { ease: "none" } });
|
|
@@ -2584,7 +2725,6 @@ var Movie = class {
|
|
|
2584
2725
|
this.app = new Application();
|
|
2585
2726
|
await this.app.init({ ...baseAppOptions, preference: "webgl" });
|
|
2586
2727
|
}
|
|
2587
|
-
if (usesAdvancedBlend(options.composition)) await enableAdvancedBlend(this.app.renderer);
|
|
2588
2728
|
const root = new Container();
|
|
2589
2729
|
root.cullable = true;
|
|
2590
2730
|
root.cullableChildren = true;
|
|
@@ -2608,51 +2748,13 @@ var Movie = class {
|
|
|
2608
2748
|
assetsSeen = n;
|
|
2609
2749
|
}
|
|
2610
2750
|
});
|
|
2611
|
-
const
|
|
2612
|
-
width: this.width,
|
|
2613
|
-
height: this.height,
|
|
2614
|
-
duration: this.duration,
|
|
2615
|
-
frameRate: this.frameRate,
|
|
2616
|
-
onLayerBuilt: async () => {
|
|
2617
|
-
lp.tick();
|
|
2618
|
-
await lp.yieldIfDue();
|
|
2619
|
-
}
|
|
2620
|
-
};
|
|
2621
|
-
const seededComposition = options.composition ? {
|
|
2622
|
-
...options.composition,
|
|
2623
|
-
width: options.composition.width ?? this.width,
|
|
2624
|
-
height: options.composition.height ?? this.height,
|
|
2625
|
-
duration: options.composition.duration ?? this.duration
|
|
2626
|
-
} : void 0;
|
|
2627
|
-
await ensureFilterLibrary(seededComposition);
|
|
2628
|
-
const userComposition = seededComposition ? expandTransitions(seededComposition) : void 0;
|
|
2629
|
-
const rootSeqSpec = {
|
|
2630
|
-
type: "composition",
|
|
2631
|
-
width: this.width,
|
|
2632
|
-
height: this.height,
|
|
2633
|
-
duration: this.duration,
|
|
2634
|
-
...userComposition
|
|
2635
|
-
};
|
|
2636
|
-
if (userComposition) carryTransitionWindows(userComposition, rootSeqSpec);
|
|
2637
|
-
const composition = new CompositionSequence(rootSeqSpec, null, rootShape);
|
|
2638
|
-
lp.begin("build", countLayers(rootSeqSpec));
|
|
2639
|
-
await composition.build();
|
|
2751
|
+
const composition = await this._construct(this._composition, this._vars, this.width, this.height, lp);
|
|
2640
2752
|
this._rootSequence = composition;
|
|
2641
2753
|
if (composition.target) root.addChild(composition.target);
|
|
2642
2754
|
composition.bindTimeline(this.timeline);
|
|
2643
2755
|
this._timeFilters = collectTimeFilters(composition);
|
|
2644
|
-
const audios = [];
|
|
2645
|
-
composition.collectAudio(audios, 0);
|
|
2646
2756
|
lp.begin("sound", 1);
|
|
2647
|
-
|
|
2648
|
-
this.audioBuffer = await mixdown(audios, this.duration, audioContext.sampleRate, async (done) => {
|
|
2649
|
-
lp.part(done);
|
|
2650
|
-
await lp.yieldIfDue();
|
|
2651
|
-
});
|
|
2652
|
-
lp.tick();
|
|
2653
|
-
if (this.audioBuffer) this._mixStats = limitMix(this.audioBuffer, audios);
|
|
2654
|
-
}
|
|
2655
|
-
this._audioSources = audios;
|
|
2757
|
+
await this._mixSound(composition, audioContext, lp);
|
|
2656
2758
|
lp.begin("frames", 0);
|
|
2657
2759
|
this.timeline.time(this._timeOf(0));
|
|
2658
2760
|
await this._awaitVideoFrames();
|
|
@@ -2675,6 +2777,254 @@ var Movie = class {
|
|
|
2675
2777
|
throw err;
|
|
2676
2778
|
}
|
|
2677
2779
|
}
|
|
2780
|
+
/**
|
|
2781
|
+
* Build the composition tree for these variables and this size, off stage: `{name}` replaced, the root shape (with the numeric variables for the
|
|
2782
|
+
* expressions), transitions expanded, every layer built. Used by `init` and by `rebuild`.
|
|
2783
|
+
*/
|
|
2784
|
+
async _construct(composition, vars, width, height, lp, sizeWins = this._resized) {
|
|
2785
|
+
const spec = applyVars(composition, vars);
|
|
2786
|
+
const rootShape = {
|
|
2787
|
+
width,
|
|
2788
|
+
height,
|
|
2789
|
+
duration: this.duration,
|
|
2790
|
+
frameRate: this.frameRate,
|
|
2791
|
+
vars: numericVars(vars),
|
|
2792
|
+
...lp ? { onLayerBuilt: async () => {
|
|
2793
|
+
lp.tick();
|
|
2794
|
+
await lp.yieldIfDue();
|
|
2795
|
+
} } : {}
|
|
2796
|
+
};
|
|
2797
|
+
const seededComposition = spec ? {
|
|
2798
|
+
...spec,
|
|
2799
|
+
width: sizeWins ? width : spec.width ?? width,
|
|
2800
|
+
height: sizeWins ? height : spec.height ?? height,
|
|
2801
|
+
duration: spec.duration ?? this.duration
|
|
2802
|
+
} : void 0;
|
|
2803
|
+
await ensureFilterLibrary(seededComposition);
|
|
2804
|
+
if (usesAdvancedBlend(seededComposition)) await enableAdvancedBlend(this.app.renderer);
|
|
2805
|
+
const userComposition = seededComposition ? expandTransitions(seededComposition) : void 0;
|
|
2806
|
+
const rootSeqSpec = {
|
|
2807
|
+
type: "composition",
|
|
2808
|
+
width,
|
|
2809
|
+
height,
|
|
2810
|
+
duration: this.duration,
|
|
2811
|
+
...userComposition
|
|
2812
|
+
};
|
|
2813
|
+
if (userComposition) carryTransitionWindows(userComposition, rootSeqSpec);
|
|
2814
|
+
const sequence = new CompositionSequence(rootSeqSpec, null, rootShape);
|
|
2815
|
+
lp?.begin("build", countLayers(rootSeqSpec));
|
|
2816
|
+
try {
|
|
2817
|
+
await sequence.build();
|
|
2818
|
+
} catch (err) {
|
|
2819
|
+
safeRun(() => sequence.destroy());
|
|
2820
|
+
throw err;
|
|
2821
|
+
}
|
|
2822
|
+
return sequence;
|
|
2823
|
+
}
|
|
2824
|
+
/** Make the sound of a built composition: the same mix as last time when the sounds are the same (`'reused'`), else mix it. */
|
|
2825
|
+
async _mixSound(sequence, audioContext, lp) {
|
|
2826
|
+
const audios = [];
|
|
2827
|
+
sequence.collectAudio(audios, 0);
|
|
2828
|
+
let status = "none";
|
|
2829
|
+
if (audios.length === 0) {
|
|
2830
|
+
this.audioBuffer = null;
|
|
2831
|
+
this._mixStats = null;
|
|
2832
|
+
this._mixCache.set(null, null);
|
|
2833
|
+
} else {
|
|
2834
|
+
const key = mixKey(audios, this.duration, audioContext.sampleRate);
|
|
2835
|
+
const hit = this._mixCache.get(key);
|
|
2836
|
+
if (hit) {
|
|
2837
|
+
this.audioBuffer = hit.buffer;
|
|
2838
|
+
this._mixStats = hit.extra;
|
|
2839
|
+
status = "reused";
|
|
2840
|
+
} else {
|
|
2841
|
+
this.audioBuffer = await mixdown(audios, this.duration, audioContext.sampleRate, lp ? async (done) => {
|
|
2842
|
+
lp.part(done);
|
|
2843
|
+
await lp.yieldIfDue();
|
|
2844
|
+
} : void 0);
|
|
2845
|
+
this._mixStats = this.audioBuffer ? limitMix(this.audioBuffer, audios) : null;
|
|
2846
|
+
this._mixCache.set(key, this.audioBuffer, this._mixStats);
|
|
2847
|
+
status = "mixed";
|
|
2848
|
+
}
|
|
2849
|
+
lp?.tick();
|
|
2850
|
+
}
|
|
2851
|
+
this._audioSources = audios;
|
|
2852
|
+
return status;
|
|
2853
|
+
}
|
|
2854
|
+
/** The variables now (a copy; change them with `setVars()`). */
|
|
2855
|
+
get vars() {
|
|
2856
|
+
return { ...this._vars };
|
|
2857
|
+
}
|
|
2858
|
+
/**
|
|
2859
|
+
* Change variables and rebuild at the same time. Only the declared names (`movie.init({ vars })`) are accepted; another name says which one it
|
|
2860
|
+
* looks like and is ignored. Values it already has change nothing: no rebuild (`unchanged: true`).
|
|
2861
|
+
*/
|
|
2862
|
+
async setVars(changes) {
|
|
2863
|
+
this._requireReady("setVars");
|
|
2864
|
+
return this.rebuild({ vars: changes }, "vars");
|
|
2865
|
+
}
|
|
2866
|
+
/** Make the movie `width` x `height` pixels (the canvas, and `W` / `H` / `GW` / `GH` in every expression) and rebuild at the same time. */
|
|
2867
|
+
async resize(width, height) {
|
|
2868
|
+
this._requireReady("resize");
|
|
2869
|
+
return this.rebuild({ width, height }, "resize");
|
|
2870
|
+
}
|
|
2871
|
+
/**
|
|
2872
|
+
* Build the composition again, with what `change` replaces (variables, the composition, the size), and put the movie back where it was: the
|
|
2873
|
+
* same frame, playing or not, the poster if that was shown. The new composition is built first: when that fails the old one stays, `error` is
|
|
2874
|
+
* emitted and the promise rejects. The sound is mixed again only when it changed (`audio: 'reused'` otherwise). Calls that arrive while a
|
|
2875
|
+
* rebuild runs are joined into one more rebuild (the latest values win), so a slider can call it on every move.
|
|
2876
|
+
*/
|
|
2877
|
+
async rebuild(change = {}, reason = "rebuild") {
|
|
2878
|
+
this._requireReady("rebuild");
|
|
2879
|
+
warnUnknownOptions("movie.rebuild()", change, ["composition", "vars", "width", "height"]);
|
|
2880
|
+
if (this._rebuildRun) {
|
|
2881
|
+
if (!this._rebuildNext) {
|
|
2882
|
+
let resolve, reject;
|
|
2883
|
+
const promise = new Promise((res, rej) => {
|
|
2884
|
+
resolve = res;
|
|
2885
|
+
reject = rej;
|
|
2886
|
+
});
|
|
2887
|
+
this._rebuildNext = { change: {}, reason, promise, resolve, reject };
|
|
2888
|
+
}
|
|
2889
|
+
const next = this._rebuildNext;
|
|
2890
|
+
next.change = { ...next.change, ...change, vars: { ...next.change.vars ?? {}, ...change.vars ?? {} } };
|
|
2891
|
+
if (reason !== "vars") next.reason = reason;
|
|
2892
|
+
return next.promise;
|
|
2893
|
+
}
|
|
2894
|
+
return this._runRebuild(change, reason);
|
|
2895
|
+
}
|
|
2896
|
+
_runRebuild(change, reason) {
|
|
2897
|
+
const run = this._doRebuild(change, reason);
|
|
2898
|
+
this._rebuildRun = run;
|
|
2899
|
+
const settled = () => {
|
|
2900
|
+
if (this._rebuildRun === run) this._rebuildRun = null;
|
|
2901
|
+
const next = this._rebuildNext;
|
|
2902
|
+
if (next && this._initState === "ready") {
|
|
2903
|
+
this._rebuildNext = null;
|
|
2904
|
+
this._runRebuild(next.change, next.reason).then(next.resolve, next.reject);
|
|
2905
|
+
} else if (next) {
|
|
2906
|
+
this._rebuildNext = null;
|
|
2907
|
+
next.reject(new Error("pixi-effects: the movie was destroyed before the rebuild could run"));
|
|
2908
|
+
}
|
|
2909
|
+
};
|
|
2910
|
+
run.then(settled, settled);
|
|
2911
|
+
return run;
|
|
2912
|
+
}
|
|
2913
|
+
async _doRebuild(change, reason) {
|
|
2914
|
+
const started = performance.now();
|
|
2915
|
+
const root = this._rootContainer, app = this.app;
|
|
2916
|
+
if (!root || !app) throw new Error("pixi-effects: movie.rebuild() needs a ready movie \u2014 await movie.init(...) first");
|
|
2917
|
+
const who = `movie.${reason === "vars" ? "setVars" : "rebuild"}()`;
|
|
2918
|
+
let sequence = null;
|
|
2919
|
+
const alive = () => {
|
|
2920
|
+
if (this._initState !== "ready") throw new Error("pixi-effects: the movie was destroyed while it was being rebuilt");
|
|
2921
|
+
};
|
|
2922
|
+
try {
|
|
2923
|
+
const vars = { ...this._vars };
|
|
2924
|
+
let changed = false;
|
|
2925
|
+
if (change.vars !== void 0) {
|
|
2926
|
+
const given = normalizeVars(change.vars, who);
|
|
2927
|
+
for (const [name, value] of Object.entries(given)) {
|
|
2928
|
+
if (!this._declared.has(name)) {
|
|
2929
|
+
const guess = suggestName(name, [...this._declared]);
|
|
2930
|
+
console.warn(`pixi-effects: ${who}: "${name}" is not a declared variable${guess ? ` \u2014 did you mean "${guess}"?` : ""} (declared in movie.init({ vars }): ${[...this._declared].join(", ") || "none"}); ignored`);
|
|
2931
|
+
continue;
|
|
2932
|
+
}
|
|
2933
|
+
if (vars[name] !== value) {
|
|
2934
|
+
vars[name] = value;
|
|
2935
|
+
changed = true;
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
for (const [k, v] of [["width", change.width], ["height", change.height]]) {
|
|
2940
|
+
if (v !== void 0 && !(Number.isFinite(v) && v >= 1)) throw new Error(`pixi-effects: movie.rebuild(): ${k} must be a number of pixels (1 or more), got ${JSON.stringify(v)}`);
|
|
2941
|
+
}
|
|
2942
|
+
const width = change.width ?? this.width, height = change.height ?? this.height;
|
|
2943
|
+
const sizeChanged = width !== this.width || height !== this.height;
|
|
2944
|
+
const composition = change.composition ?? this._composition;
|
|
2945
|
+
if (change.composition !== void 0) for (const w of lintVars(change.composition, vars)) console.warn(w);
|
|
2946
|
+
changed = changed || sizeChanged || change.composition !== void 0 || reason === "rebuild";
|
|
2947
|
+
if (!changed) return { reason, ms: 0, audio: "none", frame: this.currentFrame, playing: this.isPlaying, unchanged: true };
|
|
2948
|
+
sequence = await this._construct(composition, vars, width, height, void 0, this._resized || sizeChanged);
|
|
2949
|
+
alive();
|
|
2950
|
+
const timeline = createTimeline({ paused: true, defaults: { ease: "none" } });
|
|
2951
|
+
lengthen(timeline, this.duration);
|
|
2952
|
+
sequence.bindTimeline(timeline);
|
|
2953
|
+
const hadSound = this.audioBuffer !== null;
|
|
2954
|
+
const audio = await this._mixSound(sequence, this._ensureAudioContext());
|
|
2955
|
+
const soundChanged = audio === "mixed" || audio === "none" && hadSound;
|
|
2956
|
+
while (this._busy > 0) {
|
|
2957
|
+
await new Promise((r) => this._idleWaiters.push(r));
|
|
2958
|
+
}
|
|
2959
|
+
alive();
|
|
2960
|
+
const wasPlaying = this.isPlaying, frame = this.currentFrame, wasAtPoster = this._atPoster;
|
|
2961
|
+
const oldSize = { w: this.width, h: this.height }, oldResized = this._resized;
|
|
2962
|
+
const goOn = wasPlaying && !soundChanged;
|
|
2963
|
+
this._silent++;
|
|
2964
|
+
try {
|
|
2965
|
+
if (goOn) this._cancelUntil();
|
|
2966
|
+
else this.pause();
|
|
2967
|
+
if (sizeChanged) {
|
|
2968
|
+
try {
|
|
2969
|
+
this.width = width;
|
|
2970
|
+
this.height = height;
|
|
2971
|
+
this._resized = true;
|
|
2972
|
+
app.renderer.resize(width, height);
|
|
2973
|
+
root.cullArea = new Rectangle(0, 0, width, height);
|
|
2974
|
+
} catch (e) {
|
|
2975
|
+
this.width = oldSize.w;
|
|
2976
|
+
this.height = oldSize.h;
|
|
2977
|
+
this._resized = oldResized;
|
|
2978
|
+
safeRun(() => app.renderer.resize(oldSize.w, oldSize.h));
|
|
2979
|
+
root.cullArea = new Rectangle(0, 0, oldSize.w, oldSize.h);
|
|
2980
|
+
if (wasPlaying && !goOn) this.play();
|
|
2981
|
+
throw e;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
const old = this._rootSequence, oldTimeline = this.timeline;
|
|
2985
|
+
if (old?.target) root.removeChild(old.target);
|
|
2986
|
+
if (sequence.target) root.addChild(sequence.target);
|
|
2987
|
+
this._rootSequence = sequence;
|
|
2988
|
+
this.timeline = timeline;
|
|
2989
|
+
this._timeFilters = collectTimeFilters(sequence);
|
|
2990
|
+
const unmute = muteBoundTextureWarning();
|
|
2991
|
+
try {
|
|
2992
|
+
safeRun(() => old?.destroy());
|
|
2993
|
+
} finally {
|
|
2994
|
+
unmute();
|
|
2995
|
+
}
|
|
2996
|
+
safeRun(() => oldTimeline?.kill());
|
|
2997
|
+
this._vars = vars;
|
|
2998
|
+
this._composition = composition;
|
|
2999
|
+
this.stops = normalizeStops(applyVars(composition, vars)?.stops, this.duration, this.frameRate);
|
|
3000
|
+
sequence = null;
|
|
3001
|
+
} finally {
|
|
3002
|
+
this._silent--;
|
|
3003
|
+
}
|
|
3004
|
+
try {
|
|
3005
|
+
if (wasAtPoster) await this._showPoster();
|
|
3006
|
+
else await this._quietly(() => this.gotoFrame(frame, true));
|
|
3007
|
+
} catch (e) {
|
|
3008
|
+
console.warn("pixi-effects: could not draw the frame after a rebuild:", e);
|
|
3009
|
+
this._emitError("playback", e);
|
|
3010
|
+
}
|
|
3011
|
+
if (wasPlaying && !goOn && this._initState === "ready" && !this.isPlaying) {
|
|
3012
|
+
this._silent++;
|
|
3013
|
+
try {
|
|
3014
|
+
this.play();
|
|
3015
|
+
} finally {
|
|
3016
|
+
this._silent--;
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
const report = { reason, ms: Math.round((performance.now() - started) * 10) / 10, audio, frame, playing: wasPlaying };
|
|
3020
|
+
this.emit("rebuilt", report);
|
|
3021
|
+
return report;
|
|
3022
|
+
} catch (err) {
|
|
3023
|
+
if (sequence) safeRun(() => sequence.destroy());
|
|
3024
|
+
this._emitError("rebuild", err);
|
|
3025
|
+
throw err;
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
2678
3028
|
async gotoFrame(frame, force = false) {
|
|
2679
3029
|
if (this._initState !== "ready") return;
|
|
2680
3030
|
this._cancelUntil();
|
|
@@ -2987,13 +3337,30 @@ var Movie = class {
|
|
|
2987
3337
|
*/
|
|
2988
3338
|
async peek(fn) {
|
|
2989
3339
|
this._requireReady("peek");
|
|
2990
|
-
this.
|
|
2991
|
-
|
|
3340
|
+
return this._exclusive(async () => {
|
|
3341
|
+
this.pause();
|
|
3342
|
+
const back = this.currentFrame, wasAtPoster = this._atPoster;
|
|
3343
|
+
try {
|
|
3344
|
+
return await this._quietly(fn);
|
|
3345
|
+
} finally {
|
|
3346
|
+
if (wasAtPoster) await this._showPoster();
|
|
3347
|
+
else await this._quietly(() => this.gotoFrame(back, true));
|
|
3348
|
+
}
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
/** Run `fn` as the only thing that moves the composition: waits for a rebuild in flight, and holds the next one's swap until `fn` is done. */
|
|
3352
|
+
async _exclusive(fn) {
|
|
3353
|
+
while (this._rebuildRun) await this._rebuildRun.catch(() => {
|
|
3354
|
+
});
|
|
3355
|
+
this._busy++;
|
|
2992
3356
|
try {
|
|
2993
|
-
return await
|
|
3357
|
+
return await fn();
|
|
2994
3358
|
} finally {
|
|
2995
|
-
if (
|
|
2996
|
-
|
|
3359
|
+
if (--this._busy === 0) {
|
|
3360
|
+
const waiting = this._idleWaiters;
|
|
3361
|
+
this._idleWaiters = [];
|
|
3362
|
+
waiting.forEach((w) => w());
|
|
3363
|
+
}
|
|
2997
3364
|
}
|
|
2998
3365
|
}
|
|
2999
3366
|
_settleUntil(landed) {
|
|
@@ -3027,6 +3394,7 @@ var Movie = class {
|
|
|
3027
3394
|
if (this.currentFrame >= this.totalFrames) this.currentFrame = 0;
|
|
3028
3395
|
const wasPlaying = this.isPlaying;
|
|
3029
3396
|
this.isPlaying = true;
|
|
3397
|
+
const startFrame = this.currentFrame;
|
|
3030
3398
|
const startTime = performance.now() - this.currentFrame / this.frameRate * 1e3;
|
|
3031
3399
|
let inFlight = false;
|
|
3032
3400
|
const tick = (time) => {
|
|
@@ -3036,7 +3404,7 @@ var Movie = class {
|
|
|
3036
3404
|
return;
|
|
3037
3405
|
}
|
|
3038
3406
|
const elapsed = (time - startTime) / 1e3;
|
|
3039
|
-
const frame = Math.floor(elapsed * this.frameRate);
|
|
3407
|
+
const frame = Math.max(startFrame, Math.floor(elapsed * this.frameRate));
|
|
3040
3408
|
if (this._until !== null && frame >= this._until) {
|
|
3041
3409
|
void this._arriveUntil();
|
|
3042
3410
|
return;
|
|
@@ -3050,6 +3418,18 @@ var Movie = class {
|
|
|
3050
3418
|
inFlight = false;
|
|
3051
3419
|
});
|
|
3052
3420
|
this._raf = requestAnimationFrame(tick);
|
|
3421
|
+
} else if (this._loop && this._untilWaiters.length === 0) {
|
|
3422
|
+
this._silent++;
|
|
3423
|
+
try {
|
|
3424
|
+
this.pause();
|
|
3425
|
+
this._goto(0).catch((err) => {
|
|
3426
|
+
console.warn("pixi-effects: gotoFrame failed at the loop:", err);
|
|
3427
|
+
this._emitError("playback", err);
|
|
3428
|
+
});
|
|
3429
|
+
this.play();
|
|
3430
|
+
} finally {
|
|
3431
|
+
this._silent--;
|
|
3432
|
+
}
|
|
3053
3433
|
} else {
|
|
3054
3434
|
const toEnd = this._untilWaiters;
|
|
3055
3435
|
this._untilWaiters = [];
|
|
@@ -3078,7 +3458,7 @@ var Movie = class {
|
|
|
3078
3458
|
this.audioSource.start(0, Math.min(this.currentFrame / this.frameRate, buffer.duration));
|
|
3079
3459
|
}, typeof window !== "undefined" ? window : void 0);
|
|
3080
3460
|
}
|
|
3081
|
-
if (!wasPlaying) this.emit("play");
|
|
3461
|
+
if (!wasPlaying && !this._silent) this.emit("play");
|
|
3082
3462
|
}
|
|
3083
3463
|
pause() {
|
|
3084
3464
|
const wasPlaying = this.isPlaying;
|
|
@@ -3101,7 +3481,7 @@ var Movie = class {
|
|
|
3101
3481
|
this.gainNode.disconnect();
|
|
3102
3482
|
this.gainNode = null;
|
|
3103
3483
|
}
|
|
3104
|
-
if (wasPlaying) this.emit("pause");
|
|
3484
|
+
if (wasPlaying && !this._silent) this.emit("pause");
|
|
3105
3485
|
this._cancelUntil();
|
|
3106
3486
|
}
|
|
3107
3487
|
set volume(v) {
|
|
@@ -3127,10 +3507,23 @@ var Movie = class {
|
|
|
3127
3507
|
this.muted = !this.muted;
|
|
3128
3508
|
return this.muted;
|
|
3129
3509
|
}
|
|
3510
|
+
/**
|
|
3511
|
+
* At the end of an ordinary `play()` the movie goes back to the start and plays on (no `ended`, no `pause` / `play` events at the wrap; the sound
|
|
3512
|
+
* starts again). Default false. `playUntil()` and `render()` ignore it. Can be changed at any time; `loopchange` says so.
|
|
3513
|
+
*/
|
|
3514
|
+
set loop(v) {
|
|
3515
|
+
const next = !!v;
|
|
3516
|
+
if (next === this._loop) return;
|
|
3517
|
+
this._loop = next;
|
|
3518
|
+
this.emit("loopchange", { loop: next });
|
|
3519
|
+
}
|
|
3520
|
+
get loop() {
|
|
3521
|
+
return this._loop;
|
|
3522
|
+
}
|
|
3130
3523
|
async render(options) {
|
|
3131
3524
|
warnUnknownOptions("movie.render()", options, ["format", "video", "audio", "motionBlur", "range", "scale", "draft"]);
|
|
3132
3525
|
try {
|
|
3133
|
-
return await this._quietly(() => exportFrames(this, options));
|
|
3526
|
+
return await this._exclusive(() => this._quietly(() => exportFrames(this, options)));
|
|
3134
3527
|
} catch (err) {
|
|
3135
3528
|
this._emitError("render", err);
|
|
3136
3529
|
throw err;
|
|
@@ -3148,6 +3541,7 @@ var Movie = class {
|
|
|
3148
3541
|
this.audioBuffer = null;
|
|
3149
3542
|
this._audioSources = [];
|
|
3150
3543
|
this._mixStats = null;
|
|
3544
|
+
this._mixCache.set(null, null);
|
|
3151
3545
|
safeRun(() => this._audioContext?.close().catch(() => {
|
|
3152
3546
|
}));
|
|
3153
3547
|
this._audioContext = null;
|
|
@@ -3155,6 +3549,17 @@ var Movie = class {
|
|
|
3155
3549
|
}
|
|
3156
3550
|
};
|
|
3157
3551
|
var END_MARGIN = 1e-4;
|
|
3552
|
+
function muteBoundTextureWarning() {
|
|
3553
|
+
const original = console.warn;
|
|
3554
|
+
const ours = (...args) => {
|
|
3555
|
+
if (args.some((a) => /destroyed while still bound/.test(String(a)))) return;
|
|
3556
|
+
original.apply(console, args);
|
|
3557
|
+
};
|
|
3558
|
+
console.warn = ours;
|
|
3559
|
+
return () => {
|
|
3560
|
+
if (console.warn === ours) console.warn = original;
|
|
3561
|
+
};
|
|
3562
|
+
}
|
|
3158
3563
|
var clampFrame = (f, last) => Math.max(0, Math.min(Math.round(f), last));
|
|
3159
3564
|
function encodeCanvas(canvas, type, as, quality) {
|
|
3160
3565
|
if (as === "dataURL") return Promise.resolve(canvas.toDataURL(type, quality));
|
|
@@ -4178,5 +4583,5 @@ function withFade(spec, opts) {
|
|
|
4178
4583
|
}
|
|
4179
4584
|
|
|
4180
4585
|
export { Movie, animateText, audioEnvelope, bpmEnvelope, cameraPath, computeEnvelope, dismissLoader, failLoader, followPath, kenBurns, measureText, musicBuffer, musicEnvelope, musicEvents, orbit, parseEase2 as parseEase, particles, react, resolveLoader, splitText, stagger, wiggle, withFade };
|
|
4181
|
-
//# sourceMappingURL=chunk-
|
|
4182
|
-
//# sourceMappingURL=chunk-
|
|
4586
|
+
//# sourceMappingURL=chunk-UTIBYMIO.js.map
|
|
4587
|
+
//# sourceMappingURL=chunk-UTIBYMIO.js.map
|