pixi-effects 0.19.0 → 0.21.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +6 -6
  3. package/ai/SKILL.md +3 -2
  4. package/ai/chat-template.html +3 -3
  5. package/ai/reference/cheatsheet.md +10 -9
  6. package/ai/reference/pitfalls.md +8 -0
  7. package/ai/reference/recipes.md +77 -0
  8. package/ai/template.html +5 -5
  9. package/ai/tools/check.mjs +16 -4
  10. package/dist/{Base-B4WbUJO2.d.ts → Base-CzfLGoDr.d.ts} +9 -1
  11. package/dist/{Base-i88XXaiP.d.cts → Base-wYJQ2g5Q.d.cts} +9 -1
  12. package/dist/Composition-2UFPSNVN.cjs +14 -0
  13. package/dist/{Composition-KYNPRWK3.cjs.map → Composition-2UFPSNVN.cjs.map} +1 -1
  14. package/dist/Composition-BVI236ZR.js +5 -0
  15. package/dist/{Composition-QBKEEJBV.js.map → Composition-BVI236ZR.js.map} +1 -1
  16. package/dist/Controller.cjs +2 -2
  17. package/dist/Controller.d.cts +2 -2
  18. package/dist/Controller.d.ts +2 -2
  19. package/dist/Controller.js +1 -1
  20. package/dist/{Movie-8IrqL3kO.d.ts → Movie-CgYwa5QG.d.ts} +10 -2
  21. package/dist/{Movie-CpmdNadg.d.cts → Movie-mtX9AkQ-.d.cts} +10 -2
  22. package/dist/Presenter.cjs +2 -2
  23. package/dist/Presenter.d.cts +2 -2
  24. package/dist/Presenter.d.ts +2 -2
  25. package/dist/Presenter.js +1 -1
  26. package/dist/{chunk-CTZRFSVU.cjs → chunk-6JJC37ZD.cjs} +326 -41
  27. package/dist/chunk-6JJC37ZD.cjs.map +1 -0
  28. package/dist/{chunk-VTBT6NNE.cjs → chunk-BPW42X7C.cjs} +385 -32
  29. package/dist/chunk-BPW42X7C.cjs.map +1 -0
  30. package/dist/{chunk-YRXTKOV5.js → chunk-DDIXIWXK.js} +366 -25
  31. package/dist/chunk-DDIXIWXK.js.map +1 -0
  32. package/dist/{chunk-DKGG7WD4.js → chunk-MNM56B3X.js} +6 -3
  33. package/dist/chunk-MNM56B3X.js.map +1 -0
  34. package/dist/{chunk-B3YB2TNY.js → chunk-NGYGFGDS.js} +304 -19
  35. package/dist/chunk-NGYGFGDS.js.map +1 -0
  36. package/dist/{chunk-UQBGW5DO.cjs → chunk-WTRKDIKH.cjs} +6 -3
  37. package/dist/chunk-WTRKDIKH.cjs.map +1 -0
  38. package/dist/index.cjs +215 -91
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +4 -4
  41. package/dist/index.d.ts +4 -4
  42. package/dist/index.js +156 -32
  43. package/dist/index.js.map +1 -1
  44. package/dist/loader.css +1 -1
  45. package/dist/{music-4HDFULNR.js → music-CFEC7HKL.js} +3 -3
  46. package/dist/{music-4HDFULNR.js.map → music-CFEC7HKL.js.map} +1 -1
  47. package/dist/{music-3OF5C6X5.cjs → music-UAN7DXK4.cjs} +7 -7
  48. package/dist/{music-3OF5C6X5.cjs.map → music-UAN7DXK4.cjs.map} +1 -1
  49. package/dist/{sfx-MZJZXYY3.cjs → sfx-EX4PUBMV.cjs} +8 -8
  50. package/dist/{sfx-MZJZXYY3.cjs.map → sfx-EX4PUBMV.cjs.map} +1 -1
  51. package/dist/{sfx-S37DDC66.js → sfx-U3GM2MED.js} +3 -3
  52. package/dist/{sfx-S37DDC66.js.map → sfx-U3GM2MED.js.map} +1 -1
  53. package/dist/three.cjs +6 -6
  54. package/dist/three.d.cts +2 -2
  55. package/dist/three.d.ts +2 -2
  56. package/dist/three.js +2 -2
  57. package/dist/{types-bzLJ7aUx.d.ts → types-YmUaViL1.d.cts} +24 -0
  58. package/dist/{types-bzLJ7aUx.d.cts → types-YmUaViL1.d.ts} +24 -0
  59. package/docs/dsl.md +62 -2
  60. package/llms-full.txt +160 -13
  61. package/package.json +3 -1
  62. package/dist/Composition-KYNPRWK3.cjs +0 -14
  63. package/dist/Composition-QBKEEJBV.js +0 -5
  64. package/dist/chunk-B3YB2TNY.js.map +0 -1
  65. package/dist/chunk-CTZRFSVU.cjs.map +0 -1
  66. package/dist/chunk-DKGG7WD4.js.map +0 -1
  67. package/dist/chunk-UQBGW5DO.cjs.map +0 -1
  68. package/dist/chunk-VTBT6NNE.cjs.map +0 -1
  69. package/dist/chunk-YRXTKOV5.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { suggestName, warnUnknownOptions } from './chunk-DKGG7WD4.js';
1
+ import { suggestName, warnUnknownOptions } from './chunk-MNM56B3X.js';
2
2
  import * as PIXI from 'pixi.js';
3
3
  import { Rectangle, Container, GraphicsPath, Graphics, Assets, Texture, Sprite, FillGradient, Text, Filter, GlProgram, defaultFilterVert, GpuProgram, UniformGroup, Color } from 'pixi.js';
4
4
  import { gsap } from 'gsap';
@@ -396,6 +396,58 @@ function looksLikeColorString(s) {
396
396
  if (s.charCodeAt(0) === 35) return true;
397
397
  return /^(rgb|hsl|oklab|oklch|lab|lch)\b/i.test(s);
398
398
  }
399
+ function cubicBezierEase(x1, y1, x2, y2) {
400
+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;
401
+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;
402
+ const X = (t) => ((ax * t + bx) * t + cx) * t;
403
+ const Y = (t) => ((ay * t + by) * t + cy) * t;
404
+ const dX = (t) => (3 * ax * t + 2 * bx) * t + cx;
405
+ return (p) => {
406
+ if (p <= 0) return 0;
407
+ if (p >= 1) return 1;
408
+ let t = p;
409
+ for (let i = 0; i < 8; i++) {
410
+ const err = X(t) - p;
411
+ if (Math.abs(err) < 1e-9) return Y(t);
412
+ const d = dX(t);
413
+ if (Math.abs(d) < 1e-6) break;
414
+ t -= err / d;
415
+ }
416
+ let lo = 0, hi = 1;
417
+ t = p;
418
+ for (let i = 0; i < 60; i++) {
419
+ const x = X(t);
420
+ if (Math.abs(x - p) < 1e-10) break;
421
+ if (x < p) lo = t;
422
+ else hi = t;
423
+ t = (lo + hi) / 2;
424
+ }
425
+ return Y(t);
426
+ };
427
+ }
428
+ var NUM = String.raw`\s*(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)\s*`;
429
+ var RE = new RegExp(`^\\s*cubic-bezier\\(${NUM},${NUM},${NUM},${NUM}\\)\\s*$`, "i");
430
+ function cubicBezierProblem(name) {
431
+ const m = RE.exec(name);
432
+ if (!m) return 'expected "cubic-bezier(x1, y1, x2, y2)" with four numbers, like CSS';
433
+ const x1 = Number(m[1]), x2 = Number(m[3]);
434
+ if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1) return "x1 and x2 must be between 0 and 1 (y1 and y2 may overshoot)";
435
+ return null;
436
+ }
437
+ var registered2 = false;
438
+ function registerCubicBezierEase() {
439
+ if (registered2) return;
440
+ registered2 = true;
441
+ const base = ((p) => p);
442
+ base.config = (x1, y1, x2, y2) => {
443
+ const bad = [x1, y1, x2, y2].some((v) => typeof v !== "number" || !Number.isFinite(v)) || x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1;
444
+ return bad ? (p) => p : cubicBezierEase(x1, y1, x2, y2);
445
+ };
446
+ gsap.registerEase("cubic-bezier", base);
447
+ }
448
+ registerCubicBezierEase();
449
+
450
+ // src/core/ease.ts
399
451
  var FAMILIES = ["power1", "power2", "power3", "power4", "back", "elastic", "bounce", "circ", "expo", "sine"];
400
452
  var EASE_NAMES = ["none", ...FAMILIES.flatMap((f) => [`${f}.in`, `${f}.out`, `${f}.inOut`])];
401
453
  var warned = /* @__PURE__ */ new Set();
@@ -408,6 +460,13 @@ function checkEase(ease, where) {
408
460
  console.warn(`pixi-effects: ${where}: unknown ease "${ease}" \u2014 ${problem}. GSAP would run it as its default ease, power1.out.`);
409
461
  return;
410
462
  }
463
+ if (/^\s*cubic-bezier/i.test(ease)) {
464
+ const problem = cubicBezierProblem(ease);
465
+ if (!problem || warned.has(ease)) return;
466
+ warned.add(ease);
467
+ console.warn(`pixi-effects: ${where}: unknown ease "${ease}" \u2014 ${problem}. It runs as 'none' (a straight line).`);
468
+ return;
469
+ }
411
470
  const found = gsap.parseEase(ease);
412
471
  if (typeof found === "function") return;
413
472
  if (warned.has(ease)) return;
@@ -1082,7 +1141,7 @@ var GrainFilter = class extends Filter {
1082
1141
  }
1083
1142
  /** The movie calls this with the time (s) of the frame it is about to draw: the grain is new every 1/fps s. */
1084
1143
  setTime(t) {
1085
- this.u.uFrame = this._fps > 0 ? Math.floor(t * this._fps + 1e-6) : 0;
1144
+ this.u.uFrame = this._fps > 0 ? Math.floor(t * this._fps + 1e-3) : 0;
1086
1145
  }
1087
1146
  };
1088
1147
 
@@ -1297,13 +1356,21 @@ var Sequence = class {
1297
1356
  pathRouters() {
1298
1357
  return {};
1299
1358
  }
1359
+ /**
1360
+ * The `initial` and `keyframes` that go onto the display object. A layer whose `time` runs a clock (video, composition) takes `time`
1361
+ * out of them: it is not a property of the display object.
1362
+ */
1363
+ displayProps() {
1364
+ return { initial: this.spec.initial, keyframes: this.spec.keyframes };
1365
+ }
1300
1366
  bindTimeline(timeline, offset = 0) {
1301
1367
  if (!this.target) return;
1302
1368
  const scope = this.scope();
1303
1369
  const routers = this.pathRouters();
1304
1370
  const startTime = offset + this.at;
1305
- applyInitial(this.target, this.spec.initial, scope, [], routers);
1306
- applyKeyframes(timeline, this.target, this.spec.keyframes, this.duration, scope, [], startTime, routers);
1371
+ const { initial, keyframes } = this.displayProps();
1372
+ applyInitial(this.target, initial, scope, [], routers);
1373
+ applyKeyframes(timeline, this.target, keyframes, this.duration, scope, [], startTime, routers);
1307
1374
  const endTime = startTime + this.duration;
1308
1375
  this.absoluteStart = startTime;
1309
1376
  if (this.keepHidden) return;
@@ -1356,11 +1423,11 @@ function collectPropKeys(spec) {
1356
1423
 
1357
1424
  // src/core/layerKeys.ts
1358
1425
  var COMMON = ["type", "name", "parent", "at", "duration", "initial", "keyframes", "filters", "filterArea", "mask", "maskInverted", "blendMode", "threeD", "hideBehindCamera"];
1359
- var VIDEO = [...COMMON, "asset", "loop", "audio", "volume"];
1426
+ var VIDEO = [...COMMON, "asset", "loop", "audio", "volume", "speed"];
1360
1427
  var IMAGE = [...COMMON, "asset", "colorSpace"];
1361
1428
  var TEXT = [...COMMON, "text", "format", "style", "colorSpace", "fillGradient"];
1362
- var AUDIO = [...COMMON, "volume", "asset", "loop", "sfx", "music"];
1363
- var COMPOSITION = [...COMMON, "width", "height", "sequences", "transitions"];
1429
+ var AUDIO = [...COMMON, "volume", "asset", "loop", "sfx", "music", "speed"];
1430
+ var COMPOSITION = [...COMMON, "width", "height", "sequences", "transitions", "speed"];
1364
1431
  var CAMERA = [...COMMON];
1365
1432
  var NULL = [...COMMON];
1366
1433
  var SHAPE = [...COMMON, "shape", "fillGradient", "colorSpace", "strokeCap", "strokeJoin"];
@@ -1450,11 +1517,14 @@ var PROP_KEYS = /* @__PURE__ */ new Set([
1450
1517
  "visibleChars",
1451
1518
  "text",
1452
1519
  "volume",
1520
+ "time",
1453
1521
  // camera
1454
1522
  "lookAtX",
1455
1523
  "lookAtY",
1456
1524
  "lookAtZ",
1457
1525
  "fov",
1526
+ "focus",
1527
+ "aperture",
1458
1528
  "offsetX",
1459
1529
  "offsetY",
1460
1530
  "offsetZ",
@@ -1526,12 +1596,54 @@ function lintText(spec, warn = defaultWarn) {
1526
1596
  warn(`pixi-effects: ${describeLayer(spec)}: \`value\` is set or animated but the text has no {value} placeholder, so nothing shows it. Use text: '{value}' (or e.g. '{value} users').`);
1527
1597
  }
1528
1598
  }
1599
+ var REMAPPABLE = /* @__PURE__ */ new Set(["video", "audio", "composition"]);
1600
+ var REMAP_NAMES = /* @__PURE__ */ new Set(["time", "timeRemap", "reverse"]);
1601
+ var TIME_BAGS = ["set", "to", "from"];
1602
+ function lintRemap(spec, warn) {
1603
+ const s = spec;
1604
+ const who = describeLayer(spec);
1605
+ const kfs = s.keyframes ?? [];
1606
+ const bags = [s.initial, ...kfs.flatMap((kf) => TIME_BAGS.map((b) => kf[b]))];
1607
+ const timeInInitial = !!s.initial && s.initial.time !== void 0;
1608
+ const timeInKeyframes = kfs.some((kf) => TIME_BAGS.some((b) => kf[b] && kf[b].time !== void 0));
1609
+ const timed = timeInInitial || timeInKeyframes;
1610
+ if (bags.some((bag) => bag && bag.speed !== void 0)) {
1611
+ warn(`pixi-effects: ${who}: speed is a fixed setting, not an animatable property: write it on the layer (speed: 2); to change the speed over time, animate time (keyframes: [{ at: 0, from: { time: 0 }, to: { time: 4 }, duration: 2, ease: 'power2.in' }])`);
1612
+ }
1613
+ if (!REMAPPABLE.has(spec.type)) {
1614
+ if (timed) warn(`pixi-effects: ${who}: "time" only works on video, audio and composition layers; put this layer in a composition and remap that (it is ignored here)`);
1615
+ return;
1616
+ }
1617
+ if (s.reverse !== void 0) warn(`pixi-effects: ${who}: "reverse" is not a key: write speed: -1 to play backward`);
1618
+ if (s.timeRemap !== void 0) warn(`pixi-effects: ${who}: "timeRemap" is not a key: animate time in keyframes (from / to / set), or write speed`);
1619
+ if (s.time !== void 0) warn(`pixi-effects: ${who}: "time" belongs in initial or keyframes (initial: { time: 2 }), not on the layer`);
1620
+ if (spec.type === "audio" && (s.sfx !== void 0 || s.music !== void 0) && (s.speed !== void 0 || timed)) {
1621
+ warn(`pixi-effects: ${who}: speed and time do not apply to a synthesised sound (sfx, music); change an sfx's pitch with pitch (semitones), or put it in a composition and remap that`);
1622
+ return;
1623
+ }
1624
+ if (s.speed !== void 0 && (typeof s.speed !== "number" || !Number.isFinite(s.speed) || s.speed === 0)) {
1625
+ warn(`pixi-effects: ${who}: speed ${JSON.stringify(s.speed)} cannot be used: write a number other than 0 (negative plays backward); to hold a moment, key time to the same value twice`);
1626
+ }
1627
+ if (s.speed !== void 0 && timeInKeyframes) {
1628
+ warn(`pixi-effects: ${who}: speed and keyframed time are both set; time wins and speed is ignored. Use one of them`);
1629
+ }
1630
+ if (timeInInitial && typeof s.initial.time !== "number") {
1631
+ warn(`pixi-effects: ${who}: initial.time must be a number of seconds, got ${JSON.stringify(s.initial.time)}`);
1632
+ }
1633
+ kfs.forEach((kf, i) => {
1634
+ for (const b of TIME_BAGS) {
1635
+ const v = kf[b]?.time;
1636
+ if (v !== void 0 && typeof v !== "number" && typeof v !== "string") warn(`pixi-effects: ${who}: keyframes[${i}].${b}.time must be a number of seconds, got ${JSON.stringify(v)}`);
1637
+ }
1638
+ });
1639
+ }
1529
1640
  function lintKeys(spec, warn = defaultWarn) {
1530
1641
  const who = describeLayer(spec);
1531
1642
  const valid = layerKeys(spec);
1532
1643
  if (valid) {
1533
1644
  for (const key of Object.keys(spec)) {
1534
1645
  if (valid.includes(key) || spec[key] === void 0) continue;
1646
+ if (REMAPPABLE.has(spec.type) && REMAP_NAMES.has(key)) continue;
1535
1647
  const guess = suggestName(key, valid.filter((k) => k !== "type"));
1536
1648
  const owners = kindsWithKey(key);
1537
1649
  const belongs = owners.length ? ` (it belongs to ${owners.slice(0, 3).join(", ")})` : "";
@@ -1539,12 +1651,13 @@ function lintKeys(spec, warn = defaultWarn) {
1539
1651
  warn(`pixi-effects: ${who}: "${key}" is not a ${kindName(spec)} key${hint}. Valid keys: ${valid.join(", ")}`);
1540
1652
  }
1541
1653
  }
1654
+ lintRemap(spec, warn);
1542
1655
  const said = /* @__PURE__ */ new Set();
1543
1656
  const bags = [spec.initial, ...(spec.keyframes ?? []).flatMap((kf) => [kf.set, kf.to, kf.from])];
1544
1657
  for (const bag of bags) {
1545
1658
  for (const key of Object.keys(bag ?? {})) {
1546
1659
  if (bag[key] === void 0) continue;
1547
- if (PROP_KEYS.has(key) || key.includes(".") || /^gradient/i.test(key) || said.has(key)) continue;
1660
+ if (PROP_KEYS.has(key) || key.includes(".") || /^gradient/i.test(key) || said.has(key) || key === "speed") continue;
1548
1661
  said.add(key);
1549
1662
  const guess = suggestName(key, [...PROP_KEYS]);
1550
1663
  warn(`pixi-effects: ${who}: "${key}" is not an animatable property${guess ? ` \u2014 did you mean "${guess}"?` : ""} (in initial, set, to or from). See the cheatsheet for the properties of this kind of layer`);
@@ -1558,6 +1671,116 @@ function lintKeys(spec, warn = defaultWarn) {
1558
1671
  }
1559
1672
  }
1560
1673
  }
1674
+ var BAGS = ["set", "to", "from"];
1675
+ function timeRemapOf(spec, prop = "time") {
1676
+ const hasInitial = !!spec.initial && "time" in spec.initial;
1677
+ const hasKf = (spec.keyframes ?? []).some((kf) => BAGS.some((b) => kf[b] && "time" in kf[b]));
1678
+ const speed = typeof spec.speed === "number" && Number.isFinite(spec.speed) && spec.speed !== 0 ? spec.speed : void 0;
1679
+ if (!hasInitial && !hasKf && speed === void 0) return null;
1680
+ const timeKfs = [];
1681
+ const restKfs = [];
1682
+ for (const kf of spec.keyframes ?? []) {
1683
+ const t = { ...kf }, r = { ...kf };
1684
+ let touched = false, left = false;
1685
+ for (const b of BAGS) {
1686
+ const bag = kf[b];
1687
+ if (!bag) {
1688
+ delete t[b];
1689
+ delete r[b];
1690
+ continue;
1691
+ }
1692
+ const { time, ...others } = bag;
1693
+ if ("time" in bag) {
1694
+ touched = true;
1695
+ t[b] = { [prop]: time };
1696
+ } else delete t[b];
1697
+ if (Object.keys(others).length) {
1698
+ r[b] = others;
1699
+ left = true;
1700
+ } else delete r[b];
1701
+ }
1702
+ if (touched) timeKfs.push(t);
1703
+ if (!touched || left) restKfs.push(r);
1704
+ }
1705
+ let restInitial = spec.initial;
1706
+ let start;
1707
+ if (hasInitial) {
1708
+ const { time, ...others } = spec.initial;
1709
+ start = typeof time === "number" && Number.isFinite(time) ? time : void 0;
1710
+ restInitial = others;
1711
+ }
1712
+ return { timeKfs, restKfs: restKfs.length ? restKfs : void 0, restInitial, start, speed };
1713
+ }
1714
+ function resolveFromEnd(remap, length, prop) {
1715
+ const fix = (v) => typeof v === "number" && v < 0 ? Math.max(0, length + v) : v;
1716
+ const timeKfs = remap.timeKfs.map((kf) => {
1717
+ const out = { ...kf };
1718
+ for (const b of BAGS) {
1719
+ const bag = kf[b];
1720
+ if (bag && prop in bag) out[b] = { ...bag, [prop]: fix(bag[prop]) };
1721
+ }
1722
+ return out;
1723
+ });
1724
+ return { ...remap, timeKfs, start: remap.start === void 0 ? void 0 : fix(remap.start) };
1725
+ }
1726
+ function remapOf(spec, prop, length) {
1727
+ const r = timeRemapOf(spec, prop);
1728
+ return r && length !== null ? resolveFromEnd(r, length, prop) : r;
1729
+ }
1730
+ function contentLength(remap, duration) {
1731
+ let m = duration;
1732
+ if (remap.speed !== void 0) m = Math.max(m, Math.abs(remap.speed) * duration);
1733
+ if (remap.start !== void 0) m = Math.max(m, remap.start + (remap.speed ?? 1) * duration);
1734
+ for (const kf of remap.timeKfs) {
1735
+ for (const b of BAGS) {
1736
+ const bag = kf[b];
1737
+ const v = bag && Object.values(bag)[0];
1738
+ if (typeof v === "number") m = Math.max(m, v);
1739
+ }
1740
+ }
1741
+ return m;
1742
+ }
1743
+ function bindClock(timeline, clock, prop, remap, duration, at, scope) {
1744
+ if (remap.timeKfs.length) {
1745
+ if (remap.start !== void 0) timeline.set(clock, { [prop]: remap.start }, at);
1746
+ applyKeyframes(timeline, clock, remap.timeKfs, duration, scope, [], at);
1747
+ return;
1748
+ }
1749
+ const s = remap.speed ?? 1;
1750
+ const from = remap.start ?? (s < 0 ? -s * duration : 0);
1751
+ timeline.fromTo(clock, { [prop]: from }, { [prop]: from + s * duration, duration, ease: "none" }, at);
1752
+ }
1753
+ function clockTable(remap, prop, duration, at, scope, to) {
1754
+ const probe = gsap.timeline({ paused: true });
1755
+ const clock = { [prop]: remap.start ?? 0 };
1756
+ bindClock(probe, clock, prop, remap, duration, at, scope);
1757
+ probe.time(probe.duration());
1758
+ probe.time(0);
1759
+ const h = 1 / 1e3;
1760
+ const n = Math.max(2, Math.ceil(to / h) + 2);
1761
+ const tab = new Float64Array(n);
1762
+ let min = Infinity, max = -Infinity;
1763
+ for (let k = 0; k < n; k++) {
1764
+ probe.time(k * h);
1765
+ const v = clock[prop];
1766
+ tab[k] = v;
1767
+ const t = k * h;
1768
+ if (t >= at && t <= at + duration) {
1769
+ if (v < min) min = v;
1770
+ if (v > max) max = v;
1771
+ }
1772
+ }
1773
+ probe.kill();
1774
+ return {
1775
+ at(t) {
1776
+ const x = Math.min(Math.max(t / h, 0), n - 1.000001);
1777
+ const k = Math.floor(x), f = x - k;
1778
+ return tab[k] * (1 - f) + tab[k + 1] * f;
1779
+ },
1780
+ min: Number.isFinite(min) ? min : 0,
1781
+ max: Number.isFinite(max) ? max : 0
1782
+ };
1783
+ }
1561
1784
 
1562
1785
  // src/space/math.ts
1563
1786
  var DEG = Math.PI / 180;
@@ -1670,12 +1893,77 @@ function projectLayer(t, frame, b) {
1670
1893
  const origin = projectPoint(b, { x: t.x, y: t.y, z: t.z });
1671
1894
  return { corners, depth: origin.depth, visible };
1672
1895
  }
1896
+
1897
+ // src/space/focus.ts
1898
+ var DEFAULT_APERTURE = 30;
1899
+ var MIN_BLUR = 0.05;
1900
+ var MAX_BLUR = 32;
1901
+ var MANY_BLURRED = 20;
1902
+ function blurRadius(aperture, focal, depth, focusDepth) {
1903
+ if (!(aperture > 0) || !(focal > 0) || !(depth > 0) || !(focusDepth > 0)) return 0;
1904
+ const r = aperture * focal * Math.abs(1 / depth - 1 / focusDepth) / 2;
1905
+ return Math.min(r, MAX_BLUR);
1906
+ }
1907
+ var SCOPE_NAMES = /* @__PURE__ */ new Set(["w", "h", "W", "H", "GW", "GH", "contain", "cover", "t", "d", "T"]);
1908
+ function looksLikeLayerName(s) {
1909
+ return /^[A-Za-z_][\w-]*$/.test(s) && !SCOPE_NAMES.has(s);
1910
+ }
1911
+ var isName = (v, known) => typeof v === "string" && (known.has(v) || looksLikeLayerName(v));
1912
+ function focusNames(props, known) {
1913
+ const out = [];
1914
+ const read = (bag) => {
1915
+ const v = bag?.focus;
1916
+ if (isName(v, known)) out.push(v);
1917
+ };
1918
+ read(props.initial);
1919
+ for (const kf of props.keyframes ?? []) for (const bag of [kf.set, kf.to, kf.from]) read(bag);
1920
+ return out;
1921
+ }
1922
+ function withFocusResolved(props, zOf, known = /* @__PURE__ */ new Set()) {
1923
+ if (focusNames(props, known).length === 0) return props;
1924
+ const fix = (bag) => {
1925
+ const v = bag?.focus;
1926
+ if (!bag || !isName(v, known)) return bag;
1927
+ return { ...bag, focus: zOf(v) ?? 0 };
1928
+ };
1929
+ return {
1930
+ ...props,
1931
+ initial: fix(props.initial),
1932
+ keyframes: props.keyframes?.map((kf) => ({ ...kf, set: fix(kf.set), to: fix(kf.to), from: fix(kf.from) }))
1933
+ };
1934
+ }
1935
+ function layerInitialZ(spec, scope) {
1936
+ const z = spec.initial?.z;
1937
+ if (typeof z === "number") return z;
1938
+ if (typeof z === "string") return evaluateExpr(z, scope);
1939
+ return 0;
1940
+ }
1941
+ var movesZ = (spec) => (spec.keyframes ?? []).some((kf) => [kf.set, kf.to, kf.from].some((bag) => bag && "z" in bag));
1942
+ function focusProblems(camera, siblings) {
1943
+ const out = [];
1944
+ const said = /* @__PURE__ */ new Set();
1945
+ const threeD = siblings.filter((s) => s.threeD && s.name).map((s) => s.name);
1946
+ const known = new Set(siblings.map((s) => s.name).filter((n) => !!n));
1947
+ for (const name of focusNames(camera, known)) {
1948
+ if (said.has(name)) continue;
1949
+ said.add(name);
1950
+ const hit = siblings.find((s) => s.name === name);
1951
+ if (!hit) out.push({ kind: "missing", name, hint: suggestName(name, threeD) });
1952
+ else if (!hit.threeD) out.push({ kind: "not-threeD", name });
1953
+ else if (movesZ(hit)) out.push({ kind: "moving", name });
1954
+ }
1955
+ return out;
1956
+ }
1673
1957
  var CameraSequence = class extends Sequence {
1674
1958
  /** True when `z` is never specified anywhere: z then follows `fov`. */
1675
1959
  autoZ = true;
1676
1960
  compH = 0;
1677
1961
  warnedFov = false;
1678
1962
  warnedLookAt = false;
1963
+ /** True when the camera writes `focus` or `aperture` anywhere: depth of field is on. */
1964
+ dof = false;
1965
+ zOfName = null;
1966
+ layerNames = /* @__PURE__ */ new Set();
1679
1967
  async build() {
1680
1968
  const compW = this.parent?.width ?? this.root.width;
1681
1969
  this.compH = this.parent?.height ?? this.root.height;
@@ -1691,10 +1979,23 @@ var CameraSequence = class extends Sequence {
1691
1979
  carrier.lookAtY = home.lookAtY;
1692
1980
  carrier.lookAtZ = home.lookAtZ;
1693
1981
  carrier.fov = home.fov;
1982
+ carrier.focus = 0;
1983
+ carrier.aperture = DEFAULT_APERTURE;
1694
1984
  carrier.offsetX = carrier.offsetY = carrier.offsetZ = 0;
1695
1985
  carrier.lookOffsetX = carrier.lookOffsetY = carrier.lookOffsetZ = 0;
1696
1986
  this.target = carrier;
1697
- this.autoZ = !collectPropKeys(this.spec).has("z");
1987
+ const keys = collectPropKeys(this.spec);
1988
+ this.autoZ = !keys.has("z");
1989
+ this.dof = keys.has("focus") || keys.has("aperture");
1990
+ }
1991
+ /** Called by the composition once its children exist: how a layer name in `focus` becomes the z of that layer. */
1992
+ resolveFocusNames(zOf, names = /* @__PURE__ */ new Set()) {
1993
+ this.zOfName = zOf;
1994
+ this.layerNames = names;
1995
+ }
1996
+ displayProps() {
1997
+ const base = super.displayProps();
1998
+ return this.zOfName ? withFocusResolved(base, this.zOfName, this.layerNames) : base;
1698
1999
  }
1699
2000
  /** The camera's state at the current timeline position. */
1700
2001
  state() {
@@ -1718,7 +2019,9 @@ var CameraSequence = class extends Sequence {
1718
2019
  lookAtX: c.lookAtX + c.lookOffsetX,
1719
2020
  lookAtY: c.lookAtY + c.lookOffsetY,
1720
2021
  lookAtZ: c.lookAtZ + c.lookOffsetZ,
1721
- fov
2022
+ fov,
2023
+ focus: Number.isFinite(c.focus) ? c.focus : 0,
2024
+ aperture: this.dof && c.aperture > 0 ? c.aperture : 0
1722
2025
  };
1723
2026
  }
1724
2027
  /** Lifespan on the global timeline (valid after bindTimeline). */
@@ -2458,6 +2761,7 @@ var AudioSequence = class extends Sequence {
2458
2761
  _audioBuffer = null;
2459
2762
  _synth = null;
2460
2763
  _source = "";
2764
+ _remap = null;
2461
2765
  async build() {
2462
2766
  this.target = null;
2463
2767
  if (this.spec.music !== void 0) return this._buildMusic(this.spec);
@@ -2466,13 +2770,16 @@ var AudioSequence = class extends Sequence {
2466
2770
  this._source = `asset "${spec.asset}"`;
2467
2771
  const data = await Assets.get(spec.asset);
2468
2772
  this._audioBuffer = data.audioBuffer;
2773
+ this._remap = remapOf(spec, "time", data.duration ?? null);
2774
+ const constant = this._remap && this._remap.timeKfs.length === 0 ? Math.abs(this._remap.speed ?? 1) : 1;
2469
2775
  if (this.duration === void 0) {
2470
2776
  const rest = Math.max(0, (this.parent?.duration ?? this.root.duration) - this.at);
2471
- this.duration = spec.duration ?? (spec.loop ? rest : data.duration) ?? this.root.duration;
2777
+ this.duration = spec.duration ?? (spec.loop ? rest : data.duration !== void 0 ? data.duration / constant : void 0) ?? this.root.duration;
2472
2778
  }
2473
- if (!spec.loop && data.duration !== void 0 && this.duration > data.duration + 0.05) {
2779
+ const playable = this._remap && this._remap.timeKfs.length > 0 ? Infinity : (data.duration ?? Infinity) / constant;
2780
+ if (!spec.loop && Number.isFinite(playable) && this.duration > playable + 0.05) {
2474
2781
  console.warn(
2475
- `pixi-effects: ${describeLayer(spec)}: audio asset "${spec.asset}" is ${data.duration.toFixed(1)}s but the layer lasts ${this.duration.toFixed(1)}s, so it goes silent after ${data.duration.toFixed(1)}s. Add loop: true, or shorten the layer's duration.`
2782
+ `pixi-effects: ${describeLayer(spec)}: audio asset "${spec.asset}" plays for ${playable.toFixed(1)}s (${data.duration.toFixed(1)}s at speed ${constant}) but the layer lasts ${this.duration.toFixed(1)}s, so it goes silent after ${playable.toFixed(1)}s. Add loop: true, or shorten the layer's duration.`
2476
2783
  );
2477
2784
  }
2478
2785
  }
@@ -2481,7 +2788,7 @@ var AudioSequence = class extends Sequence {
2481
2788
  const raw = spec;
2482
2789
  if (raw.asset !== void 0) console.warn(`pixi-effects: ${who}: has both asset and sfx \u2014 the sfx plays; remove one`);
2483
2790
  if (raw.loop) console.warn(`pixi-effects: ${who}: loop has no effect on an sfx \u2014 to repeat it, add one audio layer per hit (a JS loop)`);
2484
- const { resolveSfx, renderSfx, sfxKey } = await import('./sfx-S37DDC66.js');
2791
+ const { resolveSfx, renderSfx, sfxKey } = await import('./sfx-U3GM2MED.js');
2485
2792
  const sfx = resolveSfx(spec.sfx, spec.duration, who);
2486
2793
  if (!sfx) return;
2487
2794
  this.duration = sfx.length;
@@ -2500,7 +2807,7 @@ var AudioSequence = class extends Sequence {
2500
2807
  const raw = spec;
2501
2808
  if (raw.asset !== void 0) console.warn(`pixi-effects: ${who}: has both asset and music \u2014 the music plays; remove one`);
2502
2809
  if (raw.sfx !== void 0) console.warn(`pixi-effects: ${who}: has both sfx and music \u2014 the music plays; remove one`);
2503
- const { resolveMusic, renderMusic, musicLength, musicKey } = await import('./music-4HDFULNR.js');
2810
+ const { resolveMusic, renderMusic, musicLength, musicKey } = await import('./music-CFEC7HKL.js');
2504
2811
  const music = resolveMusic(spec.music, who);
2505
2812
  if (!music) return;
2506
2813
  const natural = musicLength(music);
@@ -2526,7 +2833,9 @@ var AudioSequence = class extends Sequence {
2526
2833
  const initialVolume = this.spec.volume ?? this.spec.initial?.volume ?? 1;
2527
2834
  const t0 = baseTime + this.at;
2528
2835
  const dur = this.duration;
2836
+ const sourceMap = this._remap ? clockTable(this._remap, "time", dur, t0, this.scope(), t0 + dur).at : void 0;
2529
2837
  out.push({
2838
+ ...sourceMap ? { sourceMap } : {},
2530
2839
  ...this._audioBuffer ? { buffer: this._audioBuffer } : { synth: this._synth },
2531
2840
  layer: describeLayer(this.spec),
2532
2841
  source: this._source,
@@ -2585,7 +2894,7 @@ var FrameCache = class {
2585
2894
  this.capacity = options.capacity ?? 30;
2586
2895
  }
2587
2896
  _key(time) {
2588
- return Math.round(time * 1e3);
2897
+ return Math.round(time * 1e6);
2589
2898
  }
2590
2899
  async getFrameAt(time) {
2591
2900
  const key = this._key(time);
@@ -2650,6 +2959,15 @@ var FrameCache = class {
2650
2959
  }
2651
2960
  };
2652
2961
 
2962
+ // src/core/sourceTime.ts
2963
+ var FRAME_EPS = 5e-5;
2964
+ function sourceLookup(v, sourceDuration, loop) {
2965
+ if (!(sourceDuration > 0)) return Math.max(0, v);
2966
+ const w = v + FRAME_EPS;
2967
+ if (loop) return (w % sourceDuration + sourceDuration) % sourceDuration;
2968
+ return Math.min(Math.max(w, 0), sourceDuration);
2969
+ }
2970
+
2653
2971
  // src/sequences/Video.ts
2654
2972
  var VideoSequence = class extends Sequence {
2655
2973
  _sourceDuration = 0;
@@ -2658,9 +2976,15 @@ var VideoSequence = class extends Sequence {
2658
2976
  _canvas = null;
2659
2977
  _ctx = null;
2660
2978
  _drawSeq = 0;
2979
+ /** The playhead value (seconds in the file) the timeline last wrote: already remapped, and local inside a remapped composition. */
2980
+ _cur = 0;
2981
+ _remap = null;
2982
+ /** Movie asks this layer to draw the frame its own timeline is at, not the one for a time it computed. */
2983
+ selfTimed = true;
2661
2984
  async build() {
2662
2985
  const data = await Assets.get(this.spec.asset);
2663
2986
  this._sourceDuration = data.duration;
2987
+ this._remap = remapOf(this.spec, "currentTime", this._sourceDuration);
2664
2988
  this._audioBuffer = this.spec.audio !== false ? data.audioBuffer : null;
2665
2989
  this._cache = new FrameCache(data.sink, { capacity: 30 });
2666
2990
  const probeFrame = await this._cache.getFrameAt(0);
@@ -2679,7 +3003,8 @@ var VideoSequence = class extends Sequence {
2679
3003
  this.intrinsicWidth = w;
2680
3004
  this.intrinsicHeight = h;
2681
3005
  if (this.duration === void 0) {
2682
- this.duration = this.spec.duration ?? data.duration ?? this.root.duration;
3006
+ const constant = this._remap && this._remap.timeKfs.length === 0 ? Math.abs(this._remap.speed ?? 1) : 1;
3007
+ this.duration = this.spec.duration ?? (data.duration ?? this.root.duration * constant) / constant;
2683
3008
  }
2684
3009
  let currentTime = 0;
2685
3010
  const seq = this;
@@ -2689,8 +3014,9 @@ var VideoSequence = class extends Sequence {
2689
3014
  },
2690
3015
  set(v) {
2691
3016
  currentTime = v;
3017
+ seq._cur = v;
2692
3018
  const mySeq = ++seq._drawSeq;
2693
- const lookup = seq.spec.loop && seq._sourceDuration > 0 ? v % seq._sourceDuration : v;
3019
+ const lookup = sourceLookup(v, seq._sourceDuration, !!seq.spec.loop);
2694
3020
  seq._cache.getFrameAt(lookup).then((frame) => {
2695
3021
  if (mySeq !== seq._drawSeq) return;
2696
3022
  if (!frame || !seq._ctx) return;
@@ -2703,21 +3029,33 @@ var VideoSequence = class extends Sequence {
2703
3029
  });
2704
3030
  this.buildFilters();
2705
3031
  }
3032
+ displayProps() {
3033
+ const r = this._remap;
3034
+ return r ? { initial: r.restInitial, keyframes: r.restKfs } : super.displayProps();
3035
+ }
2706
3036
  bindTimeline(timeline, offset = 0) {
2707
3037
  super.bindTimeline(timeline, offset);
3038
+ const at = offset + this.at;
3039
+ if (this._remap) {
3040
+ bindClock(timeline, this.target, "currentTime", this._remap, this.duration, at, this.scope());
3041
+ return;
3042
+ }
2708
3043
  const playDuration = this.spec.loop ? this.duration : Math.min(this.duration, this._sourceDuration);
2709
3044
  timeline.fromTo(
2710
3045
  this.target,
2711
3046
  { currentTime: 0 },
2712
3047
  { currentTime: playDuration, duration: playDuration, ease: "none" },
2713
- offset + this.at
3048
+ at
2714
3049
  // offset = start of the enclosing composition(s); dropping it misplaced videos inside nested compositions
2715
3050
  );
2716
3051
  }
2717
3052
  collectAudio(out, baseTime) {
2718
3053
  if (!this._audioBuffer) return;
2719
3054
  const initialVolume = this.spec.volume ?? 1;
3055
+ const t0 = baseTime + this.at;
3056
+ const sourceMap = this._remap ? clockTable(this._remap, "currentTime", this.duration, t0, this.scope(), t0 + this.duration).at : void 0;
2720
3057
  out.push({
3058
+ ...sourceMap ? { sourceMap } : {},
2721
3059
  buffer: this._audioBuffer,
2722
3060
  layer: describeLayer(this.spec),
2723
3061
  source: `video "${this.spec.asset}"`,
@@ -2728,9 +3066,12 @@ var VideoSequence = class extends Sequence {
2728
3066
  volumeKeyframes: []
2729
3067
  });
2730
3068
  }
2731
- async awaitFrameAt(time) {
3069
+ /** Draw the frame the playhead is at NOW (`_cur`). The argument (a time Movie worked out for layers that need it) is not used. */
3070
+ async awaitFrameAt(_time) {
3071
+ const time = this._cur;
3072
+ if (!this.keepHidden && !this.target?.renderable) return;
2732
3073
  const mySeq = ++this._drawSeq;
2733
- const lookup = this.spec.loop && this._sourceDuration > 0 ? time % this._sourceDuration : time;
3074
+ const lookup = sourceLookup(time, this._sourceDuration, !!this.spec.loop);
2734
3075
  let frame = null;
2735
3076
  try {
2736
3077
  frame = await this._cache.getFrameAt(lookup);
@@ -3460,7 +3801,7 @@ function numOrZero(v, scope) {
3460
3801
  var _CompositionSequence = null;
3461
3802
  async function getCompositionSequence() {
3462
3803
  if (!_CompositionSequence) {
3463
- _CompositionSequence = (await import('./Composition-QBKEEJBV.js')).CompositionSequence;
3804
+ _CompositionSequence = (await import('./Composition-BVI236ZR.js')).CompositionSequence;
3464
3805
  }
3465
3806
  return _CompositionSequence;
3466
3807
  }
@@ -3498,6 +3839,6 @@ async function buildSequenceTree(specs, parent, root) {
3498
3839
  return out;
3499
3840
  }
3500
3841
 
3501
- export { CameraSequence, DEFAULT_FOV, DEG, NEAR, NullSequence, Sequence, buildScope, buildSequenceTree, cameraBasis, checkEase, collectPropKeys, describeLayer, ensureFilterLibrary, evaluateExpr, flattenSvgPath, homeCamera, homeDistance, lintKeys, lintText, lintTiming, noise, projectLayer, rand, random, registerSequenceType, resolveAt, summarizeWarnings };
3502
- //# sourceMappingURL=chunk-YRXTKOV5.js.map
3503
- //# sourceMappingURL=chunk-YRXTKOV5.js.map
3842
+ export { CameraSequence, DEFAULT_FOV, DEG, MANY_BLURRED, MAX_BLUR, MIN_BLUR, NEAR, NullSequence, Sequence, bindClock, blurRadius, buildScope, buildSequenceTree, cameraBasis, checkEase, clockTable, collectPropKeys, contentLength, describeLayer, ensureFilterLibrary, evaluateExpr, flattenSvgPath, focusProblems, homeCamera, homeDistance, layerInitialZ, lintKeys, lintText, lintTiming, noise, projectLayer, projectPoint, rand, random, registerSequenceType, remapOf, resolveAt, summarizeWarnings, timeRemapOf };
3843
+ //# sourceMappingURL=chunk-DDIXIWXK.js.map
3844
+ //# sourceMappingURL=chunk-DDIXIWXK.js.map