@mkbabb/keyframes.js 4.2.0 → 4.3.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.
@@ -1,58 +1,70 @@
1
- import { _ as e, c as t, d as n, f as r, h as i, o as a, s as o } from "./timeline-CPT7qUV1.js";
2
- import { COLOR_SPACE_RANGES as s, COMPUTED_UNITS as c, CSSCubicBezier as l, CSSFunction as u, CSSValues as d, FunctionValue as f, ValueArray as p, ValueUnit as m, clamp as h, cssLinear as ee, easeInOutCubic as te, extractAnimationOptions as ne, extractKeyframes as re, extractProperties as ie, flattenObject as g, isObject as ae, jumpTerms as _, lerp as v, lerpValue as oe, normalizeValueUnits as se, parseCSSStylesheet as y, parseCSSTime as ce, parseCSSValueUnit as le, prepareInterpVar as ue, scale as b, seekPreviousValue as x, sleep as S, steppedEase as C, timingFunctions as w, tryParse as de, unflattenObject as fe, unflattenObjectToString as T } from "@mkbabb/value.js";
3
- import { any as pe } from "@mkbabb/parse-that";
1
+ import { a as e, b as t, d as n, h as r, l as i, v as a } from "./timeline-BjcmprQ6.js";
2
+ import { t as o } from "./binarySearch-DOP8erk-.js";
3
+ import { n as s, r as c } from "./waapi-Bd5QadtA.js";
4
+ import { COLOR_SPACE_RANGES as l, CSSCubicBezier as u, CSSFunction as d, CSSValues as f, FunctionValue as p, ValueArray as m, ValueUnit as h, clamp as g, cssLinear as ee, easeInOutCubic as te, extractAnimationOptions as ne, extractKeyframes as re, extractProperties as _, flattenObject as v, functionIdentityValue as y, isObject as b, lerp as x, lerpValue as S, memoize as C, normalizeValueUnits as w, parseCSSStylesheet as T, parseCSSTime as ie, parseCSSValueUnit as ae, parseLinearStops as oe, parseSteps as se, prepareInterpVar as ce, scale as le, seekPreviousValue as E, sleep as ue, steppedEase as D, timingFunctions as de, tryParse as fe, unflattenObject as pe, unflattenObjectToString as me } from "@mkbabb/value.js";
5
+ import { any as he } from "@mkbabb/parse-that";
4
6
  //#region src/animation/adapter.ts
5
- var me = (e) => {
7
+ var ge = (e) => {
6
8
  let t = {};
7
9
  for (let n of e.declarations) t[n.name] = n.value;
8
10
  return t;
9
- }, he = (e) => {
11
+ }, _e = (e) => {
10
12
  let t = [];
11
13
  for (let n of e.selectors) n.kind === "percent" ? t.push(`${n.value}%`) : t.push(n.name);
12
14
  return t;
13
- }, E = (e) => {
15
+ }, O = (e) => {
14
16
  let t = re(e);
15
17
  for (let e of t.values()) if (e.length > 0) return e;
16
18
  return [];
17
- }, D = (e) => {
18
- let t = typeof e == "string" ? y(e) : e, n = E(t);
19
- typeof e == "string" && n.length === 0 && e.trim() && (t = y(`@keyframes anonymous {\n${e.trim()}\n}`), n = E(t));
20
- let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
21
- for (let e of n) {
22
- let t = me(e);
23
- for (let n of he(e)) {
24
- let o = r.get(n);
25
- r.set(n, {
26
- ...o ?? {},
19
+ }, k = (e) => {
20
+ let t = [], n = (e, n) => {
21
+ t.push({
22
+ code: e,
23
+ message: n.message ?? e,
24
+ ...n
25
+ });
26
+ }, r = typeof e == "string" ? T(e) : e, i = O(r);
27
+ typeof e == "string" && i.length === 0 && e.trim() && (r = T(`@keyframes anonymous {\n${e.trim()}\n}`), i = O(r)), typeof e == "string" && i.length === 0 && e.trim() && n("EMPTY_PARSE", {
28
+ message: "the input is non-empty but parsed to zero @keyframes rules (no animatable stops) — the resulting animation has no frames",
29
+ input: e
30
+ });
31
+ let a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
32
+ for (let e of i) {
33
+ let t = ge(e);
34
+ for (let n of _e(e)) {
35
+ let r = a.get(n);
36
+ a.set(n, {
37
+ ...r ?? {},
27
38
  ...t
28
- }), e.timingFunction != null && i.set(n, e.timingFunction);
29
- let s = e.composition;
30
- s != null && a.set(n, s);
39
+ }), e.timingFunction != null && o.set(n, e.timingFunction);
40
+ let i = e.composition;
41
+ i != null && s.set(n, i);
31
42
  }
32
43
  }
33
44
  return {
34
- keyframes: r,
35
- timingFunctions: i,
36
- composition: a,
37
- properties: ie(t),
38
- options: ne(t)
45
+ keyframes: a,
46
+ timingFunctions: o,
47
+ composition: s,
48
+ properties: _(r),
49
+ options: ne(r),
50
+ diagnostics: t
39
51
  };
40
- }, O = [
52
+ }, A = [
41
53
  "normal",
42
54
  "reverse",
43
55
  "alternate",
44
56
  "alternate-reverse"
45
- ], k = [
57
+ ], j = [
46
58
  "none",
47
59
  "forwards",
48
60
  "backwards",
49
61
  "both"
50
- ], A = Object.keys(s), j = [
62
+ ], M = Object.keys(l), N = [
51
63
  "shorter",
52
64
  "longer",
53
65
  "increasing",
54
66
  "decreasing"
55
- ], M = () => {}, N = {
67
+ ], P = () => {}, F = {
56
68
  duration: 1e3,
57
69
  delay: 0,
58
70
  iterationCount: 1,
@@ -62,26 +74,26 @@ var me = (e) => {
62
74
  useWAAPI: !0,
63
75
  respectReducedMotion: !1,
64
76
  colorSpace: "oklab"
65
- }, P = {
77
+ }, I = {
66
78
  zIndex: 0,
67
79
  weight: 1,
68
80
  blendMode: "replace",
69
81
  enabled: !0
70
- }, F = null, I = () => typeof MessageChannel == "function" ? () => new Promise((e) => {
82
+ }, L = null, ve = () => typeof MessageChannel == "function" ? () => new Promise((e) => {
71
83
  let t = new MessageChannel();
72
84
  t.port1.onmessage = () => {
73
85
  t.port1.close(), e();
74
86
  }, t.port2.postMessage(void 0);
75
87
  }) : () => new Promise((e) => setTimeout(e, 0));
76
- function L() {
88
+ function ye() {
77
89
  let e = globalThis.scheduler;
78
- return e && typeof e.yield == "function" ? e.yield() : (F ??= I(), F());
90
+ return e && typeof e.yield == "function" ? e.yield() : (L ??= ve(), L());
79
91
  }
80
92
  //#endregion
81
93
  //#region src/animation/group.ts
82
- var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
94
+ var R = (e) => e instanceof h && typeof e.value == "number", z = class t {
83
95
  animations = {};
84
- transform = M;
96
+ transform = P;
85
97
  superKey;
86
98
  paused = !1;
87
99
  started = !1;
@@ -90,7 +102,7 @@ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
90
102
  static YIELD_BATCH = 32;
91
103
  singleTarget = !0;
92
104
  lastTickTime = 0;
93
- playback = new a();
105
+ playback = new i();
94
106
  resolvePromise = null;
95
107
  _playingPromise = null;
96
108
  _boundFrame;
@@ -99,18 +111,19 @@ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
99
111
  _grouped = {};
100
112
  _groupedKeys = [];
101
113
  _groupedKeysDirty = !0;
114
+ _hasLayerSprings = !1;
102
115
  constructor(...e) {
103
116
  this._boundFrame = this._frame.bind(this);
104
117
  let t = [];
105
118
  for (let n of e) {
106
119
  let e, r;
107
- n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform === M && e.frames[0] != null && (this.transform = e.frames[0].transform);
120
+ n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform === P && e.frames[0] != null && (this.transform = e.frames[0].transform);
108
121
  let i = Q(e);
109
122
  this.animations[i] = {
110
123
  values: {},
111
124
  animation: e,
112
125
  layer: {
113
- ...P,
126
+ ...I,
114
127
  ...r
115
128
  }
116
129
  }, e.managed = !0, t.push(e);
@@ -178,18 +191,20 @@ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
178
191
  } else t[e] = n;
179
192
  }
180
193
  break;
181
- case "weighted":
182
- for (let e in a) {
183
- if (o && !o.has(e)) continue;
184
- let n = a[e];
185
- if (n === void 0) continue;
186
- let i = t[e];
187
- if (Array.isArray(i) && Array.isArray(n)) {
188
- let e = Math.min(i.length, n.length);
189
- for (let t = 0; t < e; t++) R(i[t]) && R(n[t]) ? i[t].value = v(i[t].value, n[t].value, r.weight) : i[t] = n[t];
190
- } else t[e] = n;
194
+ case "weighted": {
195
+ let e = r.weightSpring?.value ?? r.weight;
196
+ for (let n in a) {
197
+ if (o && !o.has(n)) continue;
198
+ let r = a[n];
199
+ if (r === void 0) continue;
200
+ let i = t[n];
201
+ if (Array.isArray(i) && Array.isArray(r)) {
202
+ let t = Math.min(i.length, r.length);
203
+ for (let n = 0; n < t; n++) R(i[n]) && R(r[n]) ? i[n].value = x(i[n].value, r[n].value, e) : i[n] = r[n];
204
+ } else t[n] = r;
191
205
  }
192
206
  break;
207
+ }
193
208
  }
194
209
  }
195
210
  this.done = i;
@@ -197,7 +212,7 @@ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
197
212
  let r = n[e];
198
213
  t[r] === void 0 && delete t[r];
199
214
  }
200
- if (this.transform === M) for (let e of this.getEntries()) {
215
+ if (this.transform === P) for (let e of this.getEntries()) {
201
216
  let t = e.animation.frames[0];
202
217
  if (t != null && t.transform != null) {
203
218
  this.transform = t.transform;
@@ -217,13 +232,14 @@ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
217
232
  let i = r.animation;
218
233
  return i.t = t, i.startTime !== void 0 && (i.pausedTime = i.startTime + t), this;
219
234
  }
220
- advanceTo(t) {
221
- this.lastTickTime = t, this.started || this.onStart();
222
- let n = this.getEntries(), r = e.YIELD_BATCH, i = n.length <= r ? this._advanceSlice(n, t) : this._advanceBatched(n, t, r);
223
- return i ? i.then(() => this._endAdvance()) : this._endAdvance();
235
+ advanceTo(e) {
236
+ let n = this.lastTickTime === 0 ? 0 : e - this.lastTickTime;
237
+ this._hasLayerSprings && this.advanceLayerSprings(n), this.lastTickTime = e, this.started || this.onStart();
238
+ let r = this.getEntries(), i = t.YIELD_BATCH, a = r.length <= i ? this._advanceSlice(r, e) : this._advanceBatched(r, e, i);
239
+ return a ? a.then(() => this._endAdvance()) : this._endAdvance();
224
240
  }
225
241
  async _advanceBatched(e, t, n) {
226
- for (let r = 0; r < e.length; r += n) await this._advanceSlice(e.slice(r, r + n), t), r + n < e.length && await L();
242
+ for (let r = 0; r < e.length; r += n) await this._advanceSlice(e.slice(r, r + n), t), r + n < e.length && await ye();
227
243
  }
228
244
  _endAdvance() {
229
245
  return this.done && this.onEnd(), this;
@@ -261,7 +277,7 @@ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
261
277
  }
262
278
  async play() {
263
279
  if (this._playingPromise) return this._playingPromise;
264
- let e = o(this.respectReducedMotion, () => this._playReducedMotion(), () => new Promise((e) => {
280
+ let e = n(this.respectReducedMotion, () => this._playReducedMotion(), () => new Promise((e) => {
265
281
  this.resolvePromise = e, this.playback.loop(this._boundFrame);
266
282
  }));
267
283
  return this._playingPromise = e, e.finally(() => {
@@ -334,110 +350,125 @@ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
334
350
  let t = typeof e == "string" ? e : Q(e);
335
351
  return this.animations[t]?.layer;
336
352
  }
337
- }, B = (e) => {
338
- if (e instanceof m) return [e.clone()];
339
- if (e instanceof f) return e.values.flatMap((e) => B(e));
340
- if (e instanceof p) return e.flatMap((e) => B(e));
353
+ requireEntry(e, t) {
354
+ let n = typeof e == "string" ? e : Q(e), r = this.animations[n];
355
+ if (!r) throw Error(`AnimationGroup.${t}: no animation registered for key "${n}". Known keys: ${Object.keys(this.animations).join(", ") || "(none)"}.`);
356
+ return r;
357
+ }
358
+ transitionLayer(t, n) {
359
+ let r = this.requireEntry(t, "transitionLayer").layer;
360
+ r.blendMode = "weighted";
361
+ let i = r.weightSpring;
362
+ if (i instanceof e) i.target = n.weight;
363
+ else {
364
+ let t = new e({
365
+ ...n.spring,
366
+ initial: r.weight
367
+ });
368
+ t.target = n.weight, r.weightSpring = t;
369
+ }
370
+ return this._hasLayerSprings = !0, this.invalidateEntries(), this;
371
+ }
372
+ crossfade(e, t, n) {
373
+ let r = n?.spring;
374
+ return this.transitionLayer(e, {
375
+ weight: 0,
376
+ ...r ? { spring: r } : {}
377
+ }), this.transitionLayer(t, {
378
+ weight: 1,
379
+ ...r ? { spring: r } : {}
380
+ }), this;
381
+ }
382
+ advanceLayerSprings(e) {
383
+ let t = !1;
384
+ for (let n of this.getEntries()) {
385
+ let r = n.layer.weightSpring;
386
+ r !== void 0 && (e > 0 && r.tickDt(e), r.settled ? (n.layer.weight = r.value, delete n.layer.weightSpring) : t = !0);
387
+ }
388
+ this._hasLayerSprings = t;
389
+ }
390
+ }, B = Symbol("kf.fnName"), V = (e) => e[B], H = (e, t) => (t !== void 0 && (e[B] = t), e), U = (e, t) => {
391
+ if (e instanceof h) return [H(e.clone(), t ?? V(e))];
392
+ if (e instanceof p) return e.values.flatMap((t) => U(t, e.name));
393
+ if (e instanceof m) return e.flatMap((e) => U(e, t));
341
394
  throw TypeError(`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof e}`);
342
- }, ge = (e) => {
395
+ }, be = (e) => {
343
396
  let t = e.split(".").pop(), n = e.split(".").shift();
344
397
  if (!t || !n) throw Error(`Invalid flattened key: ${e}`);
345
398
  return {
346
399
  mainKey: n,
347
400
  childKey: t
348
401
  };
349
- }, V = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), _e = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, ve = /^\s*steps\s*\(\s*(\d+)\s*(?:,\s*(jump-start|jump-end|jump-none|jump-both|start|end|both)\s*)?\)\s*$/i, ye = /^\s*linear\s*\(\s*(.+)\s*\)\s*$/i, H = (e) => {
350
- let t = [];
351
- for (let n of e.split(",")) {
352
- let e = n.trim().split(/\s+/).filter(Boolean);
353
- if (e.length === 0) return;
354
- let r = Number.parseFloat(e[0]);
355
- if (!Number.isFinite(r)) return;
356
- let i = e.slice(1);
357
- if (i.length === 0) {
358
- t.push({ output: r });
359
- continue;
360
- }
361
- for (let e of i) {
362
- let n = Number.parseFloat(e.endsWith("%") ? e.slice(0, -1) : e);
363
- if (!Number.isFinite(n)) return;
364
- t.push({
365
- output: r,
366
- input: n
367
- });
368
- }
369
- }
370
- return t.length >= 2 ? t : void 0;
371
- }, U = (e) => {
402
+ }, W = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), xe = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, Se = /^\s*steps\s*\(/i, Ce = /^\s*linear\s*\(/i, G = (e) => {
372
403
  if (e == null) return;
373
404
  if (typeof e != "string") return e;
374
- let t = e.match(_e);
405
+ let t = e.match(xe);
375
406
  if (t) {
376
407
  let e = t.slice(1, 5).map((e) => Number.parseFloat(e ?? ""));
377
408
  if (e.length === 4 && e.every((e) => Number.isFinite(e))) {
378
409
  let [t, n, r, i] = e;
379
- return l(t, n, r, i);
410
+ return u(t, n, r, i);
380
411
  }
381
412
  }
382
- let n = e.match(ve);
383
- if (n) {
384
- let e = Number.parseInt(n[1], 10), t = n[2]?.toLowerCase() ?? "end";
385
- if (e > 0 && _.includes(t)) return C(e, t);
386
- }
387
- if (e === "step-start") return C(1, "jump-start");
388
- if (e === "step-end") return C(1, "jump-end");
389
- let r = e.match(ye);
390
- if (r) {
391
- let e = H(r[1]);
392
- if (e) return ee(e);
393
- }
394
- let i = w[e];
395
- if (typeof i == "function" && i.length <= 1) return i;
396
- }, W = /* @__PURE__ */ new Map();
397
- function be(e) {
398
- let t = g(e), n = (e, t) => {
399
- let { childKey: r, mainKey: i } = ge(e);
400
- if (t instanceof m) return V(new p(...B(t)), i, r);
401
- if (t instanceof f) return V(new p(...t.values.flatMap((t) => B(n(e, t)))), i, r);
402
- if (t instanceof p) return V(new p(...t.flatMap((t) => B(n(e, t)))), i, r);
403
- let a = String(t), o = `${r}:${a}`, s = W.get(o);
404
- if (s) return V(s.clone(), i, r);
405
- let c = V(new p(...B(de(pe(u.FunctionArgs.map((e) => (e.setSubProperty(r), e)), d.Value), a))), i, r);
406
- return W.set(o, c.clone()), c;
413
+ if (Se.test(e)) try {
414
+ let { count: t, jumpTerm: n } = se(e);
415
+ return D(t, n);
416
+ } catch {}
417
+ if (e === "step-start") return D(1, "jump-start");
418
+ if (e === "step-end") return D(1, "jump-end");
419
+ if (Ce.test(e)) {
420
+ let t = e.replace(/,\s*(-?[\d.]+%)/g, " $1");
421
+ try {
422
+ return ee(oe(t));
423
+ } catch {}
424
+ }
425
+ let n = de[e];
426
+ if (typeof n == "function" && n.length <= 1) return n;
427
+ }, we = C((e, t) => U(fe(he(d.FunctionArgs.map((t) => (t.setSubProperty(e), t)), f.Value), t)), {
428
+ maxCacheSize: 2048,
429
+ keyFn: (e, t) => `${e}:${t}`
430
+ });
431
+ function Te(e) {
432
+ let t = v(e), n = (e, t) => {
433
+ let { childKey: r, mainKey: i } = be(e);
434
+ return t instanceof h ? W(new m(...U(t)), i, r) : t instanceof p ? W(new m(...t.values.flatMap((r) => U(n(e, r), t.name))), i, r) : t instanceof m ? W(new m(...t.flatMap((t) => U(n(e, t)))), i, r) : W(new m(...we(r, String(t)).map((e) => H(e.clone(), V(e)))), i, r);
407
435
  };
408
436
  return Object.entries(t).reduce((e, [t, r]) => (e[t] = n(t, r), e), {});
409
437
  }
410
- var G = (e, t, n, r, i = "oklab", a) => {
438
+ var K = (e, t, n, r, i = "oklab", a) => {
411
439
  let o = r[t], s = r[n];
412
440
  if (!o || !s) throw Error(`Invalid interpolation frame bounds (${t} -> ${n}).`);
413
441
  let c = o[e], l = s[e];
414
442
  if (!c || !l) throw Error(`Missing variable "${e}" in interpolation bounds.`);
415
- let u = Math.max(c.length, l.length), d = (t) => {
416
- let n = t.map((t) => {
417
- if (!(t instanceof m)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
443
+ let u = Math.max(c.length, l.length), d = (t, n) => {
444
+ let r = t.map((t) => {
445
+ if (!(t instanceof h)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
418
446
  return t;
419
447
  });
420
- for (; n.length < u;) n.push(new m(0));
421
- return n;
422
- }, f = d(c), p = d(l);
448
+ for (; r.length < u;) {
449
+ let e = n[r.length], t = e instanceof h ? V(e) : void 0, i = t ? y(t) : void 0;
450
+ r.push(i ?? new h(0));
451
+ }
452
+ return r;
453
+ }, f = d(c, l), p = d(l, c);
423
454
  return f.map((t, n) => {
424
455
  let r = p[n];
425
456
  if (!r) throw Error(`Missing right-hand interpolation value at index ${n}.`);
426
- if (!(t instanceof m) || !(r instanceof m)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
457
+ if (!(t instanceof h) || !(r instanceof h)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
427
458
  let o = { colorSpace: i };
428
- return a !== void 0 && (o.hueMethod = a), ue(se(t, r, o));
459
+ return a !== void 0 && (o.hueMethod = a), ce(w(t, r, o));
429
460
  });
430
461
  };
431
- function xe(e, t, n) {
462
+ function Ee(e, t, n) {
432
463
  let [r, i] = [e.start, t.start];
433
464
  return {
434
465
  start: r.value * n / 100,
435
466
  stop: i.value * n / 100
436
467
  };
437
468
  }
438
- function K(e, t, n = !0) {
439
- e = n ? e : g(e);
440
- let r = T(e);
469
+ function q(e, t, n = !0) {
470
+ e = n ? e : v(e);
471
+ let r = me(e);
441
472
  t.forEach((e) => {
442
473
  Object.entries(r).forEach(([t, n]) => {
443
474
  e.style.setProperty(t, n);
@@ -446,20 +477,20 @@ function K(e, t, n = !0) {
446
477
  }
447
478
  //#endregion
448
479
  //#region src/animation/frame-compiler.ts
449
- var q = (e, t) => {
480
+ var J = (e, t) => {
450
481
  if (typeof t == "function") return { fn: t };
451
482
  if (typeof t == "object") {
452
483
  if (typeof t.fn == "function") return t;
453
- throw new i(e, t, "an Easing must carry a callable `fn`");
484
+ throw new a(e, t, "an Easing must carry a callable `fn`");
454
485
  }
455
- let n = U(t);
456
- if (!n) throw new i(e, t, "unknown timing function — pass a callable TimingFunction, a typed Easing, a registry name, or a cubic-bezier() literal", "UNKNOWN_TIMING_FN");
457
- let a = r(t);
458
- return a ? {
486
+ let n = G(t);
487
+ if (!n) throw new a(e, t, "unknown timing function — pass a callable TimingFunction, a typed Easing, a registry name, or a cubic-bezier() literal", "UNKNOWN_TIMING_FN");
488
+ let i = r(t);
489
+ return i ? {
459
490
  fn: n,
460
- css: a
491
+ css: i
461
492
  } : { fn: n };
462
- }, Se = 1e6, Ce = /^(?:from|to)$/i, we = /^(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?%$/, J = "a keyframe selector must be a percentage 0%–100% (e.g. \"0%\", \"50%\") or the keyword 'from'/'to'", Te = class {
493
+ }, De = 1e6, Y = /^(?:from|to)$/i, Oe = /^(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?%$/, X = "a keyframe selector must be a percentage 0%–100% (e.g. \"0%\", \"50%\") or the keyword 'from'/'to'", ke = class {
463
494
  _options;
464
495
  templateFrames = [];
465
496
  parsedVars = [];
@@ -471,36 +502,38 @@ var q = (e, t) => {
471
502
  get options() {
472
503
  return this._options;
473
504
  }
474
- addFrame(e, t, n, r) {
475
- typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof m && (e = String(e));
476
- let a = e.trim();
477
- if (a === "") throw new i("start", e, `${J} — got an empty/blank string`, "EMPTY_PARSE");
478
- if (!Ce.test(a) && !(we.test(a) && parseFloat(a) <= 100)) throw new i("start", e, `${J} — got ${JSON.stringify(e)}`);
479
- let o = le(a), s = {
505
+ addFrame(e, t, n, r, i) {
506
+ typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof h && (e = String(e));
507
+ let o = e.trim();
508
+ if (o === "") throw new a("start", e, `${X} — got an empty/blank string`, "EMPTY_PARSE");
509
+ if (!Y.test(o) && !(Oe.test(o) && parseFloat(o) <= 100)) throw new a("start", e, `${X} — got ${JSON.stringify(e)}`);
510
+ let s = ae(o), c = {
480
511
  id: this.frameId,
481
- start: o,
512
+ start: s,
482
513
  vars: t,
483
514
  transform: n,
484
- timingFunction: r == null ? this.options.timingFunction : q("timingFunction", r)
515
+ timingFunction: r == null ? this.options.timingFunction : J("timingFunction", r),
516
+ composition: i
485
517
  };
486
- this.templateFrames.push(s), this.frameId += 1;
518
+ this.templateFrames.push(c), this.frameId += 1;
487
519
  }
488
520
  createFrame(e, t) {
489
521
  let n = this.templateFrames[e], r = this.templateFrames[t], i = {
490
522
  start: e,
491
523
  stop: t
492
- }, a = xe(n, r, this.options.duration), o = n.transform;
524
+ }, a = Ee(n, r, this.options.duration), o = n.transform;
493
525
  if (o == null) {
494
- let t = x(e, this.templateFrames, (e) => e.transform != null);
495
- o = (t === void 0 ? void 0 : this.templateFrames[t].transform) ?? M;
526
+ let t = E(e, this.templateFrames, (e) => e.transform != null);
527
+ o = (t === void 0 ? void 0 : this.templateFrames[t].transform) ?? P;
496
528
  }
497
529
  let s = n.timingFunction;
498
530
  if (s == null) {
499
- let t = x(e, this.templateFrames, (e) => e.timingFunction != null);
531
+ let t = E(e, this.templateFrames, (e) => e.timingFunction != null);
500
532
  s = (t === void 0 ? void 0 : this.templateFrames[t].timingFunction) ?? this.options.timingFunction;
501
533
  }
534
+ let c = e * De + t, l = r.composition;
502
535
  return {
503
- id: e * Se + t,
536
+ id: c,
504
537
  ixs: i,
505
538
  start: n.start,
506
539
  time: a,
@@ -509,7 +542,8 @@ var q = (e, t) => {
509
542
  interpVars: {},
510
543
  allInterpVars: [],
511
544
  transform: o,
512
- timingFunction: s
545
+ timingFunction: s,
546
+ ...l == null ? {} : { composition: l }
513
547
  };
514
548
  }
515
549
  buildVarIndex() {
@@ -532,12 +566,12 @@ var q = (e, t) => {
532
566
  }
533
567
  if (i === -1) continue;
534
568
  let [a, o] = [e, i], s = this.frames.findIndex((e) => e.ixs.start === a && e.ixs.stop === o), c = s === -1 ? this.createFrame(a, o) : this.frames[s];
535
- c.interpVars[r] = G(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
569
+ c.interpVars[r] = K(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
536
570
  }
537
571
  }
538
572
  parse(e) {
539
573
  this.frames = [], this.templateFrames.sort((e, t) => e.start.value - t.start.value), this.parsedVars = this.templateFrames.map((t) => {
540
- let n = be(t.vars);
574
+ let n = Te(t.vars);
541
575
  return Object.values(n).forEach((t) => {
542
576
  t.setTargets(e);
543
577
  }), n;
@@ -547,169 +581,23 @@ var q = (e, t) => {
547
581
  this.frames.forEach((e, n) => this.reconcileVars(n, t)), this.frames.sort((e, t) => e.time.start === t.time.start ? e.time.stop - t.time.stop : e.time.start - t.time.start), this.frames = this.frames.filter((e) => e.interpVars != null && Object.keys(e.interpVars).length > 0), this.frames.forEach((e) => this.finalizeFrameVars(e));
548
582
  }
549
583
  finalizeFrameVars(e) {
550
- e.flatVars = Object.entries(e.interpVars).reduce((e, [t, n]) => (e[t] = n.map((e) => e.value), e), {}), e.vars = fe(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
584
+ e.flatVars = Object.entries(e.interpVars).reduce((e, [t, n]) => (e[t] = n.map((e) => e.value), e), {}), e.vars = pe(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
551
585
  }
552
586
  renormalizeColors() {
553
587
  for (let e of this.frames) {
554
- for (let t of Object.keys(e.interpVars)) e.interpVars[t] = G(t, e.ixs.start, e.ixs.stop, this.parsedVars, this.options.colorSpace, this.options.hueMethod);
588
+ for (let t of Object.keys(e.interpVars)) e.interpVars[t] = K(t, e.ixs.start, e.ixs.stop, this.parsedVars, this.options.colorSpace, this.options.hueMethod);
555
589
  this.finalizeFrameVars(e);
556
590
  }
557
591
  }
558
- }, Ee = new Set([
559
- ...c,
560
- "%",
561
- "vh",
562
- "vw",
563
- "vmin",
564
- "vmax",
565
- "vi",
566
- "vb",
567
- "svh",
568
- "svw",
569
- "svmin",
570
- "svmax",
571
- "svi",
572
- "svb",
573
- "lvh",
574
- "lvw",
575
- "lvmin",
576
- "lvmax",
577
- "lvi",
578
- "lvb",
579
- "dvh",
580
- "dvw",
581
- "dvmin",
582
- "dvmax",
583
- "dvi",
584
- "dvb",
585
- "cqw",
586
- "cqh",
587
- "cqi",
588
- "cqb",
589
- "cqmin",
590
- "cqmax"
591
- ]), Y = (e) => typeof e == "string" && Ee.has(e), X = new Set(["offset-distance"]), De = (e) => X.has(e) || X.has(e.split(".").pop() ?? e), Oe = () => typeof globalThis.webkitConvertPointFromNodeToPage == "function";
592
- function ke(e) {
593
- if (!e.targets || e.targets.length === 0) return {
594
- eligible: !1,
595
- reason: "no DOM targets"
596
- };
597
- if (typeof e.targets[0]?.animate != "function") return {
598
- eligible: !1,
599
- reason: "target does not implement Element.animate()"
600
- };
601
- for (let t of e.frames) if (!e.usesDefaultRenderer(t.transform)) return {
602
- eligible: !1,
603
- reason: "custom transform function (not the default DOM renderer)"
604
- };
605
- let t = e.frames[0]?.timingFunction;
606
- if (t && e.frames.length > 1) {
607
- for (let n = 1; n < e.frames.length; n++) if (e.frames[n].timingFunction.fn !== t.fn) return {
608
- eligible: !1,
609
- reason: "non-uniform per-frame timing function (WAAPI supports one easing per animation)"
610
- };
611
- if (t.css !== void 0) return {
612
- eligible: !1,
613
- reason: "CSS-twinned easing across multiple segments (WAAPI restarts the curve per segment)"
614
- };
615
- }
616
- if (t && t.css === void 0) return {
617
- eligible: !1,
618
- reason: "easing has no faithful CSS twin (would run bare linear on the compositor)"
619
- };
620
- if (t?.css?.startsWith("linear(") && Oe()) return {
621
- eligible: !1,
622
- reason: "WebKit refuses HW-accel for linear() easing — the spring twin stays on the rAF path (CE-1.0)"
623
- };
624
- for (let t of e.frames) for (let [e, n] of Object.entries(t.interpVars)) {
625
- let t = De(e);
626
- for (let e of n) {
627
- let n = Y(e.start?.unit) && !(t && e.start?.unit === "%"), r = Y(e.stop?.unit) && !(t && e.stop?.unit === "%");
628
- if (n || r) return {
629
- eligible: !1,
630
- reason: `layout-dependent unit (${String(e.start?.unit ?? e.stop?.unit)}) would freeze to px under WAAPI`
631
- };
632
- if (e.start?.unit === "color" || e.stop?.unit === "color") return {
633
- eligible: !1,
634
- reason: "color interpolation requires perceptual lerp"
635
- };
636
- }
637
- }
638
- return { eligible: !0 };
639
- }
640
- var Ae = 8;
641
- function je(e) {
642
- let n = e.options.duration, r = [], i = /* @__PURE__ */ new Set();
643
- for (let t of e.frames) i.add(t.time.start), i.add(t.time.stop);
644
- let a = [...i].sort((e, t) => e - t), o = new Set(a);
645
- if (n > 0) for (let e = 1; e < a.length; e++) {
646
- let t = a[e - 1], n = a[e] - t;
647
- if (!(n <= 0)) for (let e = 1; e <= Ae; e++) o.add(t + n * e / 9);
648
- }
649
- for (let i of [...o].sort((e, t) => e - t)) {
650
- let a = e.interpFrames(i, !1);
651
- if (Object.keys(a).length === 0) continue;
652
- let o = T(a);
653
- r.push({
654
- offset: t(i / n, 0, 1),
655
- ...o
656
- });
657
- }
658
- return r;
659
- }
660
- var Me = {
661
- normal: "normal",
662
- reverse: "reverse",
663
- alternate: "alternate",
664
- "alternate-reverse": "alternate-reverse"
665
- }, Ne = {
666
- none: "none",
667
- forwards: "forwards",
668
- backwards: "backwards",
669
- both: "both"
670
- };
671
- function Pe(e) {
672
- let t = e.options, n = Me[t.direction], r = Ne[t.fillMode];
673
- if (n == null) throw TypeError(`Unrecognised animation direction "${t.direction}".`);
674
- if (r == null) throw TypeError(`Unrecognised animation fill mode "${t.fillMode}".`);
675
- let i = (e.frames[0]?.timingFunction ?? e.options.timingFunction).css ?? "linear";
676
- return {
677
- duration: t.duration,
678
- delay: t.delay,
679
- iterations: t.iterationCount === Infinity ? Infinity : t.iterationCount,
680
- direction: n,
681
- fill: r,
682
- easing: i
683
- };
684
- }
685
- async function Fe(e) {
686
- let t = je(e), n = Pe(e), r = e.targets.map((e) => e.animate(t, n));
687
- e._waAnimations = r, e.playback.loop(async (t) => {
688
- if (e.done) return !1;
689
- if (await e.advanceTo(t), e.paused) for (let e of r) e.pause();
690
- else for (let e of r) e.playState === "paused" && e.play();
691
- return !e.done;
692
- });
693
- try {
694
- await Promise.all(r.map((e) => e.finished));
695
- for (let t of r) try {
696
- e.restPosition === "final" && typeof t.commitStyles == "function" && t.commitStyles(), t.cancel();
697
- } catch {}
698
- } catch {} finally {
699
- e.playback.stop(), e._waAnimations = [];
700
- }
701
- }
702
- //#endregion
703
- //#region src/animation/engine.ts
704
- var Z = (e) => {
592
+ }, Z = (e) => {
705
593
  try {
706
- let t = ce(e);
594
+ let t = ie(e);
707
595
  return Number.isFinite(t) ? t : void 0;
708
596
  } catch {
709
597
  return;
710
598
  }
711
- }, Ie = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function", Q = (e) => typeof e == "string" ? e : e.name ?? String(e.id), Le = 0, $ = class {
712
- id = Le++;
599
+ }, Ae = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function", Q = (e) => typeof e == "string" ? e : e.name ?? String(e.id), je = 0, $ = class {
600
+ id = je++;
713
601
  name;
714
602
  superKey;
715
603
  targets;
@@ -718,12 +606,16 @@ var Z = (e) => {
718
606
  get compiler() {
719
607
  return this._compiler;
720
608
  }
721
- playback = new a();
609
+ playback = new i();
722
610
  _waAnimations = [];
723
611
  startTime = void 0;
724
612
  pausedTime = 0;
725
613
  t = 0;
726
614
  iteration = 0;
615
+ diagnostics = [];
616
+ _compositionBase = /* @__PURE__ */ new Map();
617
+ _compositionFallbackSeen = /* @__PURE__ */ new Set();
618
+ _hasComposition = !1;
727
619
  started = !1;
728
620
  done = !1;
729
621
  reversed = !1;
@@ -740,7 +632,7 @@ var Z = (e) => {
740
632
  get flatKeys() {
741
633
  return this._stableKeys;
742
634
  }
743
- _defaultTransform = (e) => K(e, this.targets);
635
+ _defaultTransform = (e) => q(e, this.targets);
744
636
  usesDefaultRenderer(e) {
745
637
  return e === this._defaultTransform;
746
638
  }
@@ -751,8 +643,8 @@ var Z = (e) => {
751
643
  }));
752
644
  }
753
645
  constructor(e, t, n, r) {
754
- this.options = {}, this._compiler = new Te(this.options), this._ctorOptions = e ?? {}, this.setOptions({
755
- ...N,
646
+ this.options = {}, this._compiler = new ke(this.options), this._ctorOptions = e ?? {}, this.setOptions({
647
+ ...F,
756
648
  ...this._ctorOptions
757
649
  }), this.targets = t == null ? [] : Array.isArray(t) ? t : [t], this.name = n, this.superKey = r;
758
650
  }
@@ -771,14 +663,22 @@ var Z = (e) => {
771
663
  get frameId() {
772
664
  return this.compiler.frameId;
773
665
  }
774
- addFrame(e, t, n, r) {
775
- return this.compiler.addFrame(e, t, n, r), this;
666
+ addFrame(e, t, n, r, i) {
667
+ return this.compiler.addFrame(e, t, n, r, i), this;
776
668
  }
777
669
  parse() {
778
- return this.compiler.parse(this.targets), this.computeStableKeys(), this;
670
+ return this.compiler.parse(this.targets), this.computeStableKeys(), this.computeHasComposition(), this;
671
+ }
672
+ computeHasComposition() {
673
+ let e = !1;
674
+ for (let t of this.frames) if (t.composition != null && t.composition !== "replace") {
675
+ e = !0;
676
+ break;
677
+ }
678
+ this._hasComposition = e, this._compositionBase.clear(), this._compositionFallbackSeen.clear();
779
679
  }
780
680
  adoptCompiled(e) {
781
- return this._compiler = e.compiler, this.options = this.compiler.options, this.unflatten = e.unflatten, this.computeStableKeys(), this;
681
+ return this._compiler = e.compiler, this.options = this.compiler.options, this.unflatten = e.unflatten, this.computeStableKeys(), this.computeHasComposition(), this;
782
682
  }
783
683
  computeStableKeys() {
784
684
  let e = /* @__PURE__ */ new Set();
@@ -786,17 +686,17 @@ var Z = (e) => {
786
686
  this._stableKeys = [...e];
787
687
  }
788
688
  setTimingFunction(e) {
789
- return this.options.timingFunction = e == null ? N.timingFunction : q("timingFunction", e), this;
689
+ return this.options.timingFunction = e == null ? F.timingFunction : J("timingFunction", e), this;
790
690
  }
791
- setIterationCount(t) {
792
- return t == null ? (this.options.iterationCount = N.iterationCount, this) : t === "infinite" || t === "∞" || t === "Infinity" || t === Infinity ? (this.options.iterationCount = Infinity, this) : (this.options.iterationCount = e("iterationCount", t, (e) => {
691
+ setIterationCount(e) {
692
+ return e == null ? (this.options.iterationCount = F.iterationCount, this) : e === "infinite" || e === "∞" || e === "Infinity" || e === Infinity ? (this.options.iterationCount = Infinity, this) : (this.options.iterationCount = t("iterationCount", e, (e) => {
793
693
  let t = typeof e == "string" ? Number.parseFloat(e.trim()) : e;
794
694
  return typeof t == "number" && !Number.isNaN(t) && t >= 0 ? t : void 0;
795
695
  }, "expected a non-negative count, \"infinite\", or Infinity"), this);
796
696
  }
797
- setDuration(t) {
798
- if (t == null) return this;
799
- let n = e("duration", t, (e) => {
697
+ setDuration(e) {
698
+ if (e == null) return this;
699
+ let n = t("duration", e, (e) => {
800
700
  let t = typeof e == "string" ? Z(e) : e;
801
701
  return typeof t == "number" && isFinite(t) && t > 0 ? t : void 0;
802
702
  }, "expected a positive duration in milliseconds or a CSS time string"), r = n / this.options.duration;
@@ -806,40 +706,40 @@ var Z = (e) => {
806
706
  }
807
707
  return this.options.duration = n, this;
808
708
  }
809
- setDelay(t) {
810
- return t == null ? (this.options.delay = N.delay, this) : (this.options.delay = e("delay", t, (e) => {
709
+ setDelay(e) {
710
+ return e == null ? (this.options.delay = F.delay, this) : (this.options.delay = t("delay", e, (e) => {
811
711
  let t = typeof e == "string" ? Z(e) : e;
812
712
  return typeof t == "number" && isFinite(t) ? t : void 0;
813
713
  }, "expected a delay in milliseconds or a CSS time string"), this);
814
714
  }
815
715
  setDirection(e) {
816
- if (e == null) e = N.direction;
817
- else if (!O.includes(e)) throw new i("direction", e, `expected one of: ${O.join(", ")}`);
716
+ if (e == null) e = F.direction;
717
+ else if (!A.includes(e)) throw new a("direction", e, `expected one of: ${A.join(", ")}`);
818
718
  return this.options.direction = e, this.reversed = !1, (this.options.direction === "reverse" || this.options.direction === "alternate-reverse" && this.iteration % 2 == 0 || this.options.direction === "alternate" && this.iteration % 2 == 1) && (this.reversed = !0), this;
819
719
  }
820
720
  setFillMode(e) {
821
- if (e == null) e = N.fillMode;
822
- else if (!k.includes(e)) throw new i("fillMode", e, `expected one of: ${k.join(", ")}`);
721
+ if (e == null) e = F.fillMode;
722
+ else if (!j.includes(e)) throw new a("fillMode", e, `expected one of: ${j.join(", ")}`);
823
723
  return this.options.fillMode = e, this;
824
724
  }
825
725
  setUseWAAPI(e) {
826
- if (e == null) return this.options.useWAAPI = N.useWAAPI, this;
827
- if (typeof e != "boolean") throw new i("useWAAPI", e, "expected a boolean");
726
+ if (e == null) return this.options.useWAAPI = F.useWAAPI, this;
727
+ if (typeof e != "boolean") throw new a("useWAAPI", e, "expected a boolean");
828
728
  return this.options.useWAAPI = e, this;
829
729
  }
830
730
  setRespectReducedMotion(e) {
831
- if (e == null) return this.options.respectReducedMotion = N.respectReducedMotion, this;
832
- if (typeof e != "boolean") throw new i("respectReducedMotion", e, "expected a boolean");
731
+ if (e == null) return this.options.respectReducedMotion = F.respectReducedMotion, this;
732
+ if (typeof e != "boolean") throw new a("respectReducedMotion", e, "expected a boolean");
833
733
  return this.options.respectReducedMotion = e, this;
834
734
  }
835
735
  setColorSpace(e) {
836
- if (e == null) return this.options.colorSpace = N.colorSpace, this;
837
- if (!A.includes(e)) throw new i("colorSpace", e, `expected one of: ${A.join(", ")}`);
736
+ if (e == null) return this.options.colorSpace = F.colorSpace, this;
737
+ if (!M.includes(e)) throw new a("colorSpace", e, `expected one of: ${M.join(", ")}`);
838
738
  return this.options.colorSpace = e, this.frames.length > 0 && this.compiler.renormalizeColors(), this;
839
739
  }
840
740
  setHueMethod(e) {
841
741
  if (e == null) return this;
842
- if (!j.includes(e)) throw new i("hueMethod", e, `expected one of: ${j.join(", ")}`);
742
+ if (!N.includes(e)) throw new a("hueMethod", e, `expected one of: ${N.join(", ")}`);
843
743
  return this.options.hueMethod = e, this.frames.length > 0 && this.compiler.renormalizeColors(), this;
844
744
  }
845
745
  setOptions(e) {
@@ -867,32 +767,32 @@ var Z = (e) => {
867
767
  at(e, t = !1) {
868
768
  let n = this.reversed;
869
769
  this.reversed = !1;
870
- let r = h(e, 0, 1) * this.options.duration, i = this.interpFrames(r, t);
770
+ let r = g(e, 0, 1) * this.options.duration, i = this.interpFrames(r, t);
871
771
  return this.reversed = n, i;
872
772
  }
873
- interpFrames(e, t = !1, r) {
773
+ interpFrames(e, t = !1, n) {
874
774
  e = this.reversed ? this.options.duration - e : e;
875
- let i = this.frames, a = i.length, o = n(i, e, (e) => e.time.start, (e) => e.time.stop);
876
- if (o === -1) return r === void 0 ? {} : (this.clearBuffer(r), r);
877
- let s = o, c = o;
878
- for (let t = o - 1; t >= 0; t--) {
879
- let n = i[t];
775
+ let r = this.frames, i = r.length, a = o(r, e, (e) => e.time.start, (e) => e.time.stop);
776
+ if (a === -1) return n === void 0 ? {} : (this.clearBuffer(n), n);
777
+ let s = a, c = a;
778
+ for (let t = a - 1; t >= 0; t--) {
779
+ let n = r[t];
880
780
  if (e < n.time.start || e > n.time.stop) break;
881
781
  s = t;
882
782
  }
883
- for (let t = o + 1; t < a; t++) {
884
- let n = i[t];
783
+ for (let t = a + 1; t < i; t++) {
784
+ let n = r[t];
885
785
  if (e < n.time.start || e > n.time.stop) break;
886
786
  c = t;
887
787
  }
888
- for (let n = s; n <= c; n++) this.processFrame(i[n], e, t);
788
+ for (let n = s; n <= c; n++) this.processFrame(r[n], e, t);
889
789
  if (s === c) {
890
- let e = i[o].flatVars;
891
- return r === void 0 ? e : (this.clearBuffer(r), Object.assign(r, e), r);
790
+ let e = r[a].flatVars;
791
+ return n === void 0 ? e : (this.clearBuffer(n), Object.assign(n, e), n);
892
792
  }
893
- let l = r ?? {};
894
- r !== void 0 && this.clearBuffer(r);
895
- for (let e = s; e <= c; e++) Object.assign(l, i[e].flatVars);
793
+ let l = n ?? {};
794
+ n !== void 0 && this.clearBuffer(n);
795
+ for (let e = s; e <= c; e++) Object.assign(l, r[e].flatVars);
896
796
  return l;
897
797
  }
898
798
  clearBuffer(e) {
@@ -900,12 +800,56 @@ var Z = (e) => {
900
800
  for (let n = 0; n < t.length; n++) e[t[n]] = void 0;
901
801
  }
902
802
  processFrame(e, t, n) {
903
- let { start: r, stop: i } = e.time, a = r === i ? 1 : b(t, r, i, 0, 1), o = e.timingFunction.fn(a);
904
- for (let t of e.allInterpVars) oe(o, t);
905
- n && e.transform(this.unflatten ? e.vars : e.flatVars, t);
803
+ let { start: r, stop: i } = e.time, a = r === i ? 1 : le(t, r, i, 0, 1), o = e.timingFunction.fn(a);
804
+ for (let t of e.allInterpVars) S(o, t);
805
+ n && this._hasComposition && e.composition != null && this.applyComposition(e), n && e.transform(this.unflatten ? e.vars : e.flatVars, t);
806
+ }
807
+ applyComposition(e) {
808
+ let t = e.composition;
809
+ if (t == null || t === "replace") return;
810
+ let n = e.flatVars;
811
+ for (let r in n) {
812
+ let i = n[r];
813
+ if (!Array.isArray(i) || i.length === 0) continue;
814
+ if (!i.every((e) => e instanceof h && typeof e.value == "number")) {
815
+ this.emitCompositionFallback(r, t);
816
+ continue;
817
+ }
818
+ let a = this._compositionBase.get(r);
819
+ a === void 0 && (a = this.captureUnderlyingBase(r, i.length), this._compositionBase.set(r, a));
820
+ let o = t === "accumulate" ? this.iteration : 0;
821
+ for (let t = 0; t < i.length; t++) {
822
+ let n = i[t], s = a[t] ?? 0;
823
+ o > 0 ? n.value = s + o * (this.endValueFor(e, r, t) - s) + n.value : n.value = s + n.value;
824
+ }
825
+ }
826
+ }
827
+ captureUnderlyingBase(e, t) {
828
+ let n = Array(t).fill(0), r = this.targets[0];
829
+ if (r == null || r.style == null) return n;
830
+ let i = e.split(".").pop() ?? e, a = r.style.getPropertyValue(i) || r.style[i] || "";
831
+ if (!a) return n;
832
+ let o = a.match(/-?\d*\.?\d+(?:e[+-]?\d+)?/gi);
833
+ if (o == null) return n;
834
+ for (let e = 0; e < t && e < o.length; e++) {
835
+ let t = Number.parseFloat(o[e]);
836
+ Number.isFinite(t) && (n[e] = t);
837
+ }
838
+ return n;
839
+ }
840
+ endValueFor(e, t, n) {
841
+ let r = e.interpVars[t]?.[n]?.stop;
842
+ return r instanceof h && typeof r.value == "number" ? r.value : this._compositionBase.get(t)?.[n] ?? 0;
843
+ }
844
+ emitCompositionFallback(e, t) {
845
+ this._compositionFallbackSeen.has(e) || (this._compositionFallbackSeen.add(e), this.diagnostics.push({
846
+ code: "COMPOSITION_FALLBACK",
847
+ message: `animation-composition: ${t} on a non-numeric leaf "${e}" has no faithful numeric add — composited as \`replace\` (the lerped value), never a wrong sum`,
848
+ property: e
849
+ }));
906
850
  }
907
851
  onStart() {
908
- if (this.reversed = !1, (this.options.direction === "reverse" || this.options.direction === "alternate-reverse" && this.iteration % 2 == 0 || this.options.direction === "alternate" && this.iteration % 2 == 1) && this.reverse(), (this.options.fillMode === "backwards" || this.options.fillMode === "both") && this.fillBackwards(), this.options.delay > 0) return this.paused = !0, S(this.options.delay).then(() => {
852
+ if (this.reversed = !1, (this.options.direction === "reverse" || this.options.direction === "alternate-reverse" && this.iteration % 2 == 0 || this.options.direction === "alternate" && this.iteration % 2 == 1) && this.reverse(), (this.options.fillMode === "backwards" || this.options.fillMode === "both") && this.fillBackwards(), this.options.delay > 0) return this.paused = !0, ue(this.options.delay).then(() => {
909
853
  this.paused = !1, this.started = !0;
910
854
  });
911
855
  this.started = !0;
@@ -929,7 +873,7 @@ var Z = (e) => {
929
873
  return this.t = e - this.startTime, this.t >= this.options.duration && (this.onEnd(), this.t = this.options.duration), this.t;
930
874
  }
931
875
  _frame(e) {
932
- if (o(this.options.respectReducedMotion, () => !0, () => !1)) return this._snapToReducedMotion(), !1;
876
+ if (n(this.options.respectReducedMotion, () => !0, () => !1)) return this._snapToReducedMotion(), !1;
933
877
  let t = this.advanceTo(e);
934
878
  return typeof t == "number" ? this._renderFrame(t) : t.then((e) => this._renderFrame(e));
935
879
  }
@@ -946,7 +890,7 @@ var Z = (e) => {
946
890
  });
947
891
  }
948
892
  async _playWAAPI() {
949
- await Fe(this), this.settle();
893
+ await c(this), this.settle();
950
894
  }
951
895
  _cancelWAAPI() {
952
896
  if (this._waAnimations.length !== 0) {
@@ -968,9 +912,9 @@ var Z = (e) => {
968
912
  async play() {
969
913
  if (this.managed) throw Error("Animation.play() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play() instead.");
970
914
  if (this._playingPromise) return this._playingPromise;
971
- let e = o(this.options.respectReducedMotion, () => (this.waapiIneligibleReason = void 0, this._playReducedMotion()), () => {
915
+ let e = n(this.options.respectReducedMotion, () => (this.waapiIneligibleReason = void 0, this._playReducedMotion()), () => {
972
916
  if (this.options.useWAAPI) {
973
- let e = ke(this);
917
+ let e = s(this);
974
918
  return e.eligible ? (this.waapiIneligibleReason = void 0, this._playWAAPI()) : (this.waapiIneligibleReason = e.reason, this._playRAF());
975
919
  }
976
920
  return this.waapiIneligibleReason = void 0, this._playRAF();
@@ -1017,7 +961,7 @@ var Z = (e) => {
1017
961
  group(...e) {
1018
962
  return new z(this, ...e);
1019
963
  }
1020
- }, Re = class extends $ {
964
+ }, Me = class extends $ {
1021
965
  constructor(e, ...t) {
1022
966
  super(e, t), this.unflatten = !1;
1023
967
  }
@@ -1033,7 +977,7 @@ var Z = (e) => {
1033
977
  return this.parse(), this;
1034
978
  }
1035
979
  fromKeyframes(e, t) {
1036
- t = this.resolveTransform(t), ae(e) && (e = new Map(Object.entries(e)));
980
+ t = this.resolveTransform(t), b(e) && (e = new Map(Object.entries(e)));
1037
981
  let n = e instanceof Map ? e.entries() : Object.entries(e);
1038
982
  for (let [e, r] of n) this.addFrame(e, r, t);
1039
983
  return this.parse(), this;
@@ -1041,15 +985,15 @@ var Z = (e) => {
1041
985
  propertyRegistry = /* @__PURE__ */ new Map();
1042
986
  fromString(e, t) {
1043
987
  t = this.resolveTransform(t);
1044
- let n = D(e);
1045
- this.propertyRegistry = n.properties;
988
+ let n = k(e);
989
+ this.propertyRegistry = n.properties, this.diagnostics = [...n.diagnostics];
1046
990
  let i = n.options, a = {};
1047
991
  i.duration != null && (a.duration = i.duration), i.timingFunction != null && (a.timingFunction = i.timingFunction), i.iterationCount !== void 0 && (a.iterationCount = i.iterationCount === null ? Infinity : i.iterationCount), i.direction != null && (a.direction = i.direction), i.delay != null && (a.delay = i.delay), i.fillMode != null && (a.fillMode = i.fillMode), Object.keys(a).length > 0 && this.setOptions({
1048
992
  ...a,
1049
993
  ...this._ctorOptions
1050
994
  });
1051
995
  for (let [e, i] of n.keyframes.entries()) {
1052
- let a = Object.fromEntries(Object.entries(i).map(([e, t]) => [e, Ie(t) ? t.clone() : t])), o = n.timingFunctions.get(e), s = o ? U(o) : void 0, c;
996
+ let a = Object.fromEntries(Object.entries(i).map(([e, t]) => [e, Ae(t) ? t.clone() : t])), o = n.timingFunctions.get(e), s = o ? G(o) : void 0, c;
1053
997
  if (s) {
1054
998
  let e = o ? r(o) : void 0;
1055
999
  c = e ? {
@@ -1057,7 +1001,8 @@ var Z = (e) => {
1057
1001
  css: e
1058
1002
  } : { fn: s };
1059
1003
  }
1060
- this.addFrame(e, a, t, c);
1004
+ let l = n.composition.get(e);
1005
+ this.addFrame(e, a, t, c, l);
1061
1006
  }
1062
1007
  return this.parse(), this.registerProperties(), this;
1063
1008
  }
@@ -1076,8 +1021,8 @@ var Z = (e) => {
1076
1021
  }
1077
1022
  }
1078
1023
  transform(e) {
1079
- K(e, this.targets);
1024
+ q(e, this.targets);
1080
1025
  }
1081
1026
  };
1082
1027
  //#endregion
1083
- export { $ as Animation, z as AnimationGroup, Re as CSSKeyframesAnimation, O as DIRECTIONS, k as FILL_MODES, P as defaultLayerConfig, N as defaultOptions, Q as getAnimationId, U as getTimingFunction, D as resolveKeyframes };
1028
+ export { $ as Animation, z as AnimationGroup, Me as CSSKeyframesAnimation, A as DIRECTIONS, j as FILL_MODES, I as defaultLayerConfig, F as defaultOptions, Q as getAnimationId, G as getTimingFunction, k as resolveKeyframes };