@mkbabb/keyframes.js 4.0.0 → 4.2.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,26 +1,26 @@
1
- import { _ as e, c as t, d as n, f as r, h as i, o as a, s as o } from "./timeline-5rnU0j6r.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, convertToMs as g, cssLinear as _, easeInOutCubic as v, extractAnimationOptions as y, extractKeyframes as ee, extractProperties as te, flattenObject as b, isObject as ne, jumpTerms as re, lerp as ie, lerpValue as ae, normalizeValueUnits as oe, parseCSSStylesheet as x, parseCSSTime as S, parseCSSValueUnit as se, prepareInterpVar as ce, scale as le, seekPreviousValue as C, sleep as w, steppedEase as T, timingFunctions as E, tryParse as ue, unflattenObject as de, unflattenObjectToString as D } from "@mkbabb/value.js";
3
- import { any as fe } from "@mkbabb/parse-that";
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";
4
4
  //#region src/animation/adapter.ts
5
- var pe = (e) => {
5
+ var me = (e) => {
6
6
  let t = {};
7
7
  for (let n of e.declarations) t[n.name] = n.value;
8
8
  return t;
9
- }, me = (e) => {
9
+ }, he = (e) => {
10
10
  let t = [];
11
11
  for (let n of e.selectors) n.kind === "percent" ? t.push(`${n.value}%`) : t.push(n.name);
12
12
  return t;
13
- }, O = (e) => {
14
- let t = ee(e);
13
+ }, E = (e) => {
14
+ let t = re(e);
15
15
  for (let e of t.values()) if (e.length > 0) return e;
16
16
  return [];
17
- }, k = (e) => {
18
- let t = typeof e == "string" ? x(e) : e, n = O(t);
19
- typeof e == "string" && n.length === 0 && e.trim() && (t = x(`@keyframes anonymous {\n${e.trim()}\n}`), n = O(t));
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
20
  let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
21
21
  for (let e of n) {
22
- let t = pe(e);
23
- for (let n of me(e)) {
22
+ let t = me(e);
23
+ for (let n of he(e)) {
24
24
  let o = r.get(n);
25
25
  r.set(n, {
26
26
  ...o ?? {},
@@ -34,54 +34,54 @@ var pe = (e) => {
34
34
  keyframes: r,
35
35
  timingFunctions: i,
36
36
  composition: a,
37
- properties: te(t),
38
- options: y(t)
37
+ properties: ie(t),
38
+ options: ne(t)
39
39
  };
40
- }, A = [
40
+ }, O = [
41
41
  "normal",
42
42
  "reverse",
43
43
  "alternate",
44
44
  "alternate-reverse"
45
- ], j = [
45
+ ], k = [
46
46
  "none",
47
47
  "forwards",
48
48
  "backwards",
49
49
  "both"
50
- ], M = Object.keys(s), N = [
50
+ ], A = Object.keys(s), j = [
51
51
  "shorter",
52
52
  "longer",
53
53
  "increasing",
54
54
  "decreasing"
55
- ], P = {
55
+ ], M = () => {}, N = {
56
56
  duration: 1e3,
57
57
  delay: 0,
58
58
  iterationCount: 1,
59
59
  direction: "normal",
60
60
  fillMode: "forwards",
61
- timingFunction: { fn: v },
61
+ timingFunction: { fn: te },
62
62
  useWAAPI: !0,
63
63
  respectReducedMotion: !1,
64
64
  colorSpace: "oklab"
65
- }, F = {
65
+ }, P = {
66
66
  zIndex: 0,
67
67
  weight: 1,
68
68
  blendMode: "replace",
69
69
  enabled: !0
70
- }, I = null, L = () => typeof MessageChannel == "function" ? () => new Promise((e) => {
70
+ }, F = null, I = () => typeof MessageChannel == "function" ? () => new Promise((e) => {
71
71
  let t = new MessageChannel();
72
72
  t.port1.onmessage = () => {
73
73
  t.port1.close(), e();
74
74
  }, t.port2.postMessage(void 0);
75
75
  }) : () => new Promise((e) => setTimeout(e, 0));
76
- function R() {
76
+ function L() {
77
77
  let e = globalThis.scheduler;
78
- return e && typeof e.yield == "function" ? e.yield() : (I ??= L(), I());
78
+ return e && typeof e.yield == "function" ? e.yield() : (F ??= I(), F());
79
79
  }
80
80
  //#endregion
81
81
  //#region src/animation/group.ts
82
- var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
82
+ var R = (e) => e instanceof m && typeof e.value == "number", z = class e {
83
83
  animations = {};
84
- transform;
84
+ transform = M;
85
85
  superKey;
86
86
  paused = !1;
87
87
  started = !1;
@@ -104,13 +104,13 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
104
104
  let t = [];
105
105
  for (let n of e) {
106
106
  let e, r;
107
- n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform == null && e.frames[0] != null && (this.transform = e.frames[0].transform);
107
+ n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform === M && e.frames[0] != null && (this.transform = e.frames[0].transform);
108
108
  let i = Q(e);
109
109
  this.animations[i] = {
110
110
  values: {},
111
111
  animation: e,
112
112
  layer: {
113
- ...F,
113
+ ...P,
114
114
  ...r
115
115
  }
116
116
  }, e.managed = !0, t.push(e);
@@ -172,16 +172,21 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
172
172
  let n = a[e];
173
173
  if (n === void 0) continue;
174
174
  let r = t[e];
175
- r === void 0 ? t[e] = n : z(r) && z(n) ? r.value += n.value : t[e] = n;
175
+ if (Array.isArray(r) && Array.isArray(n)) {
176
+ let e = Math.min(r.length, n.length);
177
+ for (let t = 0; t < e; t++) R(r[t]) && R(n[t]) ? r[t].value += n[t].value : r[t] = n[t];
178
+ } else t[e] = n;
176
179
  }
177
180
  break;
178
181
  case "weighted":
179
182
  for (let e in a) {
180
183
  if (o && !o.has(e)) continue;
181
184
  let n = a[e];
182
- if (n !== void 0) if (t[e] !== void 0) {
183
- let i = t[e];
184
- z(i) && z(n) ? i.value = ie(i.value, n.value, r.weight) : t[e] = n;
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];
185
190
  } else t[e] = n;
186
191
  }
187
192
  break;
@@ -192,6 +197,13 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
192
197
  let r = n[e];
193
198
  t[r] === void 0 && delete t[r];
194
199
  }
200
+ if (this.transform === M) for (let e of this.getEntries()) {
201
+ let t = e.animation.frames[0];
202
+ if (t != null && t.transform != null) {
203
+ this.transform = t.transform;
204
+ break;
205
+ }
206
+ }
195
207
  return this.transform(t, e), t;
196
208
  }
197
209
  render() {
@@ -205,23 +217,33 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
205
217
  let i = r.animation;
206
218
  return i.t = t, i.startTime !== void 0 && (i.pausedTime = i.startTime + t), this;
207
219
  }
208
- async advanceTo(t) {
220
+ advanceTo(t) {
209
221
  this.lastTickTime = t, this.started || this.onStart();
210
- let n = this.getEntries(), r = e.YIELD_BATCH;
211
- if (n.length <= r) await this._advanceSlice(n, t);
212
- else for (let e = 0; e < n.length; e += r) await this._advanceSlice(n.slice(e, e + r), t), e + r < n.length && await R();
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();
224
+ }
225
+ 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();
227
+ }
228
+ _endAdvance() {
213
229
  return this.done && this.onEnd(), this;
214
230
  }
215
- async _advanceSlice(e, t) {
216
- let n = [];
231
+ _advanceSlice(e, t) {
232
+ let n;
217
233
  for (let r of e) {
218
234
  let e = r.animation;
219
- (!e.paused || e.pausedTime === 0) && n.push(e.advanceTo(t));
235
+ if (e.paused && e.pausedTime !== 0) continue;
236
+ let i = e.advanceTo(t);
237
+ typeof i != "number" && (n ??= []).push(i);
220
238
  }
221
- await Promise.all(n);
239
+ return n && Promise.all(n).then(() => void 0);
240
+ }
241
+ _frame(e) {
242
+ let t = this.advanceTo(e);
243
+ return typeof t.then == "function" ? t.then(() => this._renderFrame(e)) : this._renderFrame(e);
222
244
  }
223
- async _frame(e) {
224
- if (await this.advanceTo(e), this.paused) return !1;
245
+ _renderFrame(e) {
246
+ if (this.paused) return !1;
225
247
  if (this.singleTarget) this.transformFramesGrouped(e);
226
248
  else {
227
249
  let e = !0;
@@ -234,6 +256,9 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
234
256
  let e = this.resolvePromise;
235
257
  this.resolvePromise = null, e?.();
236
258
  }
259
+ get finished() {
260
+ return this._playingPromise ?? Promise.resolve();
261
+ }
237
262
  async play() {
238
263
  if (this._playingPromise) return this._playingPromise;
239
264
  let e = o(this.respectReducedMotion, () => this._playReducedMotion(), () => new Promise((e) => {
@@ -309,19 +334,19 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
309
334
  let t = typeof e == "string" ? e : Q(e);
310
335
  return this.animations[t]?.layer;
311
336
  }
312
- }, V = (e) => {
337
+ }, B = (e) => {
313
338
  if (e instanceof m) return [e.clone()];
314
- if (e instanceof f) return e.values.flatMap((e) => V(e));
315
- if (e instanceof p) return e.flatMap((e) => V(e));
339
+ if (e instanceof f) return e.values.flatMap((e) => B(e));
340
+ if (e instanceof p) return e.flatMap((e) => B(e));
316
341
  throw TypeError(`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof e}`);
317
- }, he = (e) => {
342
+ }, ge = (e) => {
318
343
  let t = e.split(".").pop(), n = e.split(".").shift();
319
344
  if (!t || !n) throw Error(`Invalid flattened key: ${e}`);
320
345
  return {
321
346
  mainKey: n,
322
347
  childKey: t
323
348
  };
324
- }, H = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), ge = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, _e = /^\s*steps\s*\(\s*(\d+)\s*(?:,\s*(jump-start|jump-end|jump-none|jump-both|start|end|both)\s*)?\)\s*$/i, U = /^\s*linear\s*\(\s*(.+)\s*\)\s*$/i, ve = (e) => {
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) => {
325
350
  let t = [];
326
351
  for (let n of e.split(",")) {
327
352
  let e = n.trim().split(/\s+/).filter(Boolean);
@@ -343,10 +368,10 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
343
368
  }
344
369
  }
345
370
  return t.length >= 2 ? t : void 0;
346
- }, W = (e) => {
371
+ }, U = (e) => {
347
372
  if (e == null) return;
348
373
  if (typeof e != "string") return e;
349
- let t = e.match(ge);
374
+ let t = e.match(_e);
350
375
  if (t) {
351
376
  let e = t.slice(1, 5).map((e) => Number.parseFloat(e ?? ""));
352
377
  if (e.length === 4 && e.every((e) => Number.isFinite(e))) {
@@ -354,35 +379,35 @@ var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
354
379
  return l(t, n, r, i);
355
380
  }
356
381
  }
357
- let n = e.match(_e);
382
+ let n = e.match(ve);
358
383
  if (n) {
359
384
  let e = Number.parseInt(n[1], 10), t = n[2]?.toLowerCase() ?? "end";
360
- if (e > 0 && re.includes(t)) return T(e, t);
385
+ if (e > 0 && _.includes(t)) return C(e, t);
361
386
  }
362
- if (e === "step-start") return T(1, "jump-start");
363
- if (e === "step-end") return T(1, "jump-end");
364
- let r = e.match(U);
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);
365
390
  if (r) {
366
- let e = ve(r[1]);
367
- if (e) return _(e);
391
+ let e = H(r[1]);
392
+ if (e) return ee(e);
368
393
  }
369
- let i = E[e];
394
+ let i = w[e];
370
395
  if (typeof i == "function" && i.length <= 1) return i;
371
- }, G = /* @__PURE__ */ new Map();
372
- function ye(e) {
373
- let t = b(e), n = (e, t) => {
374
- let { childKey: r, mainKey: i } = he(e);
375
- if (t instanceof m) return H(new p(...V(t)), i, r);
376
- if (t instanceof f) return H(new p(...t.values.flatMap((t) => V(n(e, t)))), i, r);
377
- if (t instanceof p) return H(new p(...t.flatMap((t) => V(n(e, t)))), i, r);
378
- let a = String(t), o = `${r}:${a}`, s = G.get(o);
379
- if (s) return H(s.clone(), i, r);
380
- let c = H(new p(...V(ue(fe(u.FunctionArgs.map((e) => (e.setSubProperty(r), e)), d.Value), a))), i, r);
381
- return G.set(o, c.clone()), c;
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;
382
407
  };
383
408
  return Object.entries(t).reduce((e, [t, r]) => (e[t] = n(t, r), e), {});
384
409
  }
385
- var K = (e, t, n, r, i = "oklab", a) => {
410
+ var G = (e, t, n, r, i = "oklab", a) => {
386
411
  let o = r[t], s = r[n];
387
412
  if (!o || !s) throw Error(`Invalid interpolation frame bounds (${t} -> ${n}).`);
388
413
  let c = o[e], l = s[e];
@@ -400,19 +425,19 @@ var K = (e, t, n, r, i = "oklab", a) => {
400
425
  if (!r) throw Error(`Missing right-hand interpolation value at index ${n}.`);
401
426
  if (!(t instanceof m) || !(r instanceof m)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
402
427
  let o = { colorSpace: i };
403
- return a !== void 0 && (o.hueMethod = a), ce(oe(t, r, o));
428
+ return a !== void 0 && (o.hueMethod = a), ue(se(t, r, o));
404
429
  });
405
430
  };
406
- function be(e, t, n) {
431
+ function xe(e, t, n) {
407
432
  let [r, i] = [e.start, t.start];
408
433
  return {
409
434
  start: r.value * n / 100,
410
435
  stop: i.value * n / 100
411
436
  };
412
437
  }
413
- function q(e, t, n = !0) {
414
- e = n ? e : b(e);
415
- let r = D(e);
438
+ function K(e, t, n = !0) {
439
+ e = n ? e : g(e);
440
+ let r = T(e);
416
441
  t.forEach((e) => {
417
442
  Object.entries(r).forEach(([t, n]) => {
418
443
  e.style.setProperty(t, n);
@@ -421,62 +446,61 @@ function q(e, t, n = !0) {
421
446
  }
422
447
  //#endregion
423
448
  //#region src/animation/frame-compiler.ts
424
- var J = (e, t) => {
449
+ var q = (e, t) => {
425
450
  if (typeof t == "function") return { fn: t };
426
451
  if (typeof t == "object") {
427
452
  if (typeof t.fn == "function") return t;
428
453
  throw new i(e, t, "an Easing must carry a callable `fn`");
429
454
  }
430
- let n = W(t);
431
- 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");
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");
432
457
  let a = r(t);
433
458
  return a ? {
434
459
  fn: n,
435
460
  css: a
436
461
  } : { fn: n };
437
- }, xe = 1e6, Se = class {
438
- options;
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 {
463
+ _options;
439
464
  templateFrames = [];
440
465
  parsedVars = [];
441
466
  frames = [];
442
467
  frameId = 0;
443
468
  constructor(e) {
444
- this.options = e;
469
+ this._options = e;
445
470
  }
446
- convertFrameStart(e) {
447
- if (e.start.unit === "s" || e.start.unit === "ms" || !e.start.unit) {
448
- let t = e.start.unit === "s" ? "s" : "ms", n = g(e.start.value, t);
449
- e.start.value = n / this.options.duration * 100, e.start.unit = "%";
450
- }
451
- return e.start.value = h(e.start.value, 0, 100), e;
471
+ get options() {
472
+ return this._options;
452
473
  }
453
474
  addFrame(e, t, n, r) {
454
475
  typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof m && (e = String(e));
455
- let i = se(e), a = {
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 = {
456
480
  id: this.frameId,
457
- start: i,
481
+ start: o,
458
482
  vars: t,
459
483
  transform: n,
460
- timingFunction: r == null ? this.options.timingFunction : J("timingFunction", r)
484
+ timingFunction: r == null ? this.options.timingFunction : q("timingFunction", r)
461
485
  };
462
- this.convertFrameStart(a), this.templateFrames.push(a), this.frameId += 1;
486
+ this.templateFrames.push(s), this.frameId += 1;
463
487
  }
464
488
  createFrame(e, t) {
465
489
  let n = this.templateFrames[e], r = this.templateFrames[t], i = {
466
490
  start: e,
467
491
  stop: t
468
- }, a = be(n, r, this.options.duration), o = n.transform;
492
+ }, a = xe(n, r, this.options.duration), o = n.transform;
469
493
  if (o == null) {
470
- let t = C(e, this.templateFrames, (e) => e.transform != null);
471
- o = this.templateFrames[t].transform;
494
+ let t = x(e, this.templateFrames, (e) => e.transform != null);
495
+ o = (t === void 0 ? void 0 : this.templateFrames[t].transform) ?? M;
472
496
  }
473
497
  let s = n.timingFunction;
474
498
  if (s == null) {
475
- let t = C(e, this.templateFrames, (e) => e.timingFunction != null);
476
- s = this.templateFrames[t].timingFunction;
499
+ let t = x(e, this.templateFrames, (e) => e.timingFunction != null);
500
+ s = (t === void 0 ? void 0 : this.templateFrames[t].timingFunction) ?? this.options.timingFunction;
477
501
  }
478
502
  return {
479
- id: e * xe + t,
503
+ id: e * Se + t,
480
504
  ixs: i,
481
505
  start: n.start,
482
506
  time: a,
@@ -508,12 +532,12 @@ var J = (e, t) => {
508
532
  }
509
533
  if (i === -1) continue;
510
534
  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];
511
- c.interpVars[r] = K(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
535
+ c.interpVars[r] = G(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
512
536
  }
513
537
  }
514
538
  parse(e) {
515
539
  this.frames = [], this.templateFrames.sort((e, t) => e.start.value - t.start.value), this.parsedVars = this.templateFrames.map((t) => {
516
- let n = ye(t.vars);
540
+ let n = be(t.vars);
517
541
  return Object.values(n).forEach((t) => {
518
542
  t.setTargets(e);
519
543
  }), n;
@@ -523,15 +547,15 @@ var J = (e, t) => {
523
547
  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));
524
548
  }
525
549
  finalizeFrameVars(e) {
526
- e.flatVars = Object.entries(e.interpVars).reduce((e, [t, n]) => (e[t] = n.map((e) => e.value), e), {}), e.vars = de(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
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();
527
551
  }
528
552
  renormalizeColors() {
529
553
  for (let e of this.frames) {
530
- 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);
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);
531
555
  this.finalizeFrameVars(e);
532
556
  }
533
557
  }
534
- }, Ce = new Set([
558
+ }, Ee = new Set([
535
559
  ...c,
536
560
  "%",
537
561
  "vh",
@@ -564,8 +588,8 @@ var J = (e, t) => {
564
588
  "cqb",
565
589
  "cqmin",
566
590
  "cqmax"
567
- ]), Y = (e) => typeof e == "string" && Ce.has(e), X = new Set(["offset-distance"]), we = (e) => X.has(e) || X.has(e.split(".").pop() ?? e);
568
- function Te(e) {
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) {
569
593
  if (!e.targets || e.targets.length === 0) return {
570
594
  eligible: !1,
571
595
  reason: "no DOM targets"
@@ -593,8 +617,12 @@ function Te(e) {
593
617
  eligible: !1,
594
618
  reason: "easing has no faithful CSS twin (would run bare linear on the compositor)"
595
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
+ };
596
624
  for (let t of e.frames) for (let [e, n] of Object.entries(t.interpVars)) {
597
- let t = we(e);
625
+ let t = De(e);
598
626
  for (let e of n) {
599
627
  let n = Y(e.start?.unit) && !(t && e.start?.unit === "%"), r = Y(e.stop?.unit) && !(t && e.stop?.unit === "%");
600
628
  if (n || r) return {
@@ -609,19 +637,19 @@ function Te(e) {
609
637
  }
610
638
  return { eligible: !0 };
611
639
  }
612
- var Ee = 8;
613
- function De(e) {
640
+ var Ae = 8;
641
+ function je(e) {
614
642
  let n = e.options.duration, r = [], i = /* @__PURE__ */ new Set();
615
643
  for (let t of e.frames) i.add(t.time.start), i.add(t.time.stop);
616
644
  let a = [...i].sort((e, t) => e - t), o = new Set(a);
617
645
  if (n > 0) for (let e = 1; e < a.length; e++) {
618
646
  let t = a[e - 1], n = a[e] - t;
619
- if (!(n <= 0)) for (let e = 1; e <= Ee; e++) o.add(t + n * e / 9);
647
+ if (!(n <= 0)) for (let e = 1; e <= Ae; e++) o.add(t + n * e / 9);
620
648
  }
621
649
  for (let i of [...o].sort((e, t) => e - t)) {
622
650
  let a = e.interpFrames(i, !1);
623
651
  if (Object.keys(a).length === 0) continue;
624
- let o = D(a);
652
+ let o = T(a);
625
653
  r.push({
626
654
  offset: t(i / n, 0, 1),
627
655
  ...o
@@ -629,19 +657,19 @@ function De(e) {
629
657
  }
630
658
  return r;
631
659
  }
632
- var Oe = {
660
+ var Me = {
633
661
  normal: "normal",
634
662
  reverse: "reverse",
635
663
  alternate: "alternate",
636
664
  "alternate-reverse": "alternate-reverse"
637
- }, ke = {
665
+ }, Ne = {
638
666
  none: "none",
639
667
  forwards: "forwards",
640
668
  backwards: "backwards",
641
669
  both: "both"
642
670
  };
643
- function Ae(e) {
644
- let t = e.options, n = Oe[t.direction], r = ke[t.fillMode];
671
+ function Pe(e) {
672
+ let t = e.options, n = Me[t.direction], r = Ne[t.fillMode];
645
673
  if (n == null) throw TypeError(`Unrecognised animation direction "${t.direction}".`);
646
674
  if (r == null) throw TypeError(`Unrecognised animation fill mode "${t.fillMode}".`);
647
675
  let i = (e.frames[0]?.timingFunction ?? e.options.timingFunction).css ?? "linear";
@@ -654,8 +682,8 @@ function Ae(e) {
654
682
  easing: i
655
683
  };
656
684
  }
657
- async function je(e) {
658
- let t = De(e), n = Ae(e), r = e.targets.map((e) => e.animate(t, n));
685
+ async function Fe(e) {
686
+ let t = je(e), n = Pe(e), r = e.targets.map((e) => e.animate(t, n));
659
687
  e._waAnimations = r, e.playback.loop(async (t) => {
660
688
  if (e.done) return !1;
661
689
  if (await e.advanceTo(t), e.paused) for (let e of r) e.pause();
@@ -675,18 +703,21 @@ async function je(e) {
675
703
  //#region src/animation/engine.ts
676
704
  var Z = (e) => {
677
705
  try {
678
- let t = S(e);
706
+ let t = ce(e);
679
707
  return Number.isFinite(t) ? t : void 0;
680
708
  } catch {
681
709
  return;
682
710
  }
683
- }, Me = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function", Q = (e) => typeof e == "string" ? e : e.name ?? String(e.id), Ne = 0, $ = class {
684
- id = Ne++;
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++;
685
713
  name;
686
714
  superKey;
687
715
  targets;
688
716
  options;
689
- compiler;
717
+ _compiler;
718
+ get compiler() {
719
+ return this._compiler;
720
+ }
690
721
  playback = new a();
691
722
  _waAnimations = [];
692
723
  startTime = void 0;
@@ -709,7 +740,7 @@ var Z = (e) => {
709
740
  get flatKeys() {
710
741
  return this._stableKeys;
711
742
  }
712
- _defaultTransform = (e) => q(e, this.targets);
743
+ _defaultTransform = (e) => K(e, this.targets);
713
744
  usesDefaultRenderer(e) {
714
745
  return e === this._defaultTransform;
715
746
  }
@@ -720,8 +751,8 @@ var Z = (e) => {
720
751
  }));
721
752
  }
722
753
  constructor(e, t, n, r) {
723
- this.options = {}, this.compiler = new Se(this.options), this._ctorOptions = e ?? {}, this.setOptions({
724
- ...P,
754
+ this.options = {}, this._compiler = new Te(this.options), this._ctorOptions = e ?? {}, this.setOptions({
755
+ ...N,
725
756
  ...this._ctorOptions
726
757
  }), this.targets = t == null ? [] : Array.isArray(t) ? t : [t], this.name = n, this.superKey = r;
727
758
  }
@@ -746,16 +777,19 @@ var Z = (e) => {
746
777
  parse() {
747
778
  return this.compiler.parse(this.targets), this.computeStableKeys(), this;
748
779
  }
780
+ adoptCompiled(e) {
781
+ return this._compiler = e.compiler, this.options = this.compiler.options, this.unflatten = e.unflatten, this.computeStableKeys(), this;
782
+ }
749
783
  computeStableKeys() {
750
784
  let e = /* @__PURE__ */ new Set();
751
785
  for (let t of this.frames) for (let n in t.flatVars) e.add(n);
752
786
  this._stableKeys = [...e];
753
787
  }
754
788
  setTimingFunction(e) {
755
- return this.options.timingFunction = e == null ? P.timingFunction : J("timingFunction", e), this;
789
+ return this.options.timingFunction = e == null ? N.timingFunction : q("timingFunction", e), this;
756
790
  }
757
791
  setIterationCount(t) {
758
- return t == null ? (this.options.iterationCount = P.iterationCount, this) : t === "infinite" || t === "∞" || t === "Infinity" || t === Infinity ? (this.options.iterationCount = Infinity, this) : (this.options.iterationCount = e("iterationCount", t, (e) => {
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) => {
759
793
  let t = typeof e == "string" ? Number.parseFloat(e.trim()) : e;
760
794
  return typeof t == "number" && !Number.isNaN(t) && t >= 0 ? t : void 0;
761
795
  }, "expected a non-negative count, \"infinite\", or Infinity"), this);
@@ -773,39 +807,39 @@ var Z = (e) => {
773
807
  return this.options.duration = n, this;
774
808
  }
775
809
  setDelay(t) {
776
- return t == null ? (this.options.delay = P.delay, this) : (this.options.delay = e("delay", t, (e) => {
810
+ return t == null ? (this.options.delay = N.delay, this) : (this.options.delay = e("delay", t, (e) => {
777
811
  let t = typeof e == "string" ? Z(e) : e;
778
812
  return typeof t == "number" && isFinite(t) ? t : void 0;
779
813
  }, "expected a delay in milliseconds or a CSS time string"), this);
780
814
  }
781
815
  setDirection(e) {
782
- if (e == null) e = P.direction;
783
- else if (!A.includes(e)) throw new i("direction", e, `expected one of: ${A.join(", ")}`);
816
+ if (e == null) e = N.direction;
817
+ else if (!O.includes(e)) throw new i("direction", e, `expected one of: ${O.join(", ")}`);
784
818
  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;
785
819
  }
786
820
  setFillMode(e) {
787
- if (e == null) e = P.fillMode;
788
- else if (!j.includes(e)) throw new i("fillMode", e, `expected one of: ${j.join(", ")}`);
821
+ if (e == null) e = N.fillMode;
822
+ else if (!k.includes(e)) throw new i("fillMode", e, `expected one of: ${k.join(", ")}`);
789
823
  return this.options.fillMode = e, this;
790
824
  }
791
825
  setUseWAAPI(e) {
792
- if (e == null) return this.options.useWAAPI = P.useWAAPI, this;
826
+ if (e == null) return this.options.useWAAPI = N.useWAAPI, this;
793
827
  if (typeof e != "boolean") throw new i("useWAAPI", e, "expected a boolean");
794
828
  return this.options.useWAAPI = e, this;
795
829
  }
796
830
  setRespectReducedMotion(e) {
797
- if (e == null) return this.options.respectReducedMotion = P.respectReducedMotion, this;
831
+ if (e == null) return this.options.respectReducedMotion = N.respectReducedMotion, this;
798
832
  if (typeof e != "boolean") throw new i("respectReducedMotion", e, "expected a boolean");
799
833
  return this.options.respectReducedMotion = e, this;
800
834
  }
801
835
  setColorSpace(e) {
802
- if (e == null) return this.options.colorSpace = P.colorSpace, this;
803
- if (!M.includes(e)) throw new i("colorSpace", e, `expected one of: ${M.join(", ")}`);
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(", ")}`);
804
838
  return this.options.colorSpace = e, this.frames.length > 0 && this.compiler.renormalizeColors(), this;
805
839
  }
806
840
  setHueMethod(e) {
807
841
  if (e == null) return this;
808
- if (!N.includes(e)) throw new i("hueMethod", e, `expected one of: ${N.join(", ")}`);
842
+ if (!j.includes(e)) throw new i("hueMethod", e, `expected one of: ${j.join(", ")}`);
809
843
  return this.options.hueMethod = e, this.frames.length > 0 && this.compiler.renormalizeColors(), this;
810
844
  }
811
845
  setOptions(e) {
@@ -866,26 +900,41 @@ var Z = (e) => {
866
900
  for (let n = 0; n < t.length; n++) e[t[n]] = void 0;
867
901
  }
868
902
  processFrame(e, t, n) {
869
- let { start: r, stop: i } = e.time, a = r === i ? 1 : le(t, r, i, 0, 1), o = e.timingFunction.fn(a);
870
- for (let t of e.allInterpVars) ae(o, t);
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);
871
905
  n && e.transform(this.unflatten ? e.vars : e.flatVars, t);
872
906
  }
873
- async onStart() {
874
- 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 && (this.paused = !0, await w(this.options.delay), this.paused = !1), this.started = !0;
907
+ 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(() => {
909
+ this.paused = !1, this.started = !0;
910
+ });
911
+ this.started = !0;
875
912
  }
876
- async onEnd() {
913
+ onEnd() {
877
914
  this.paintRest(), this.startTime = void 0, this.iteration >= this.options.iterationCount - 1 ? (this.done = !0, this.iteration = 0, this.dispatchAnimationEvent("animationend")) : (this.iteration += 1, this.dispatchAnimationEvent("animationiteration"));
878
915
  }
879
- async advanceTo(e) {
880
- if (this.startTime === void 0 && (await this.onStart(), this.startTime = e + this.options.delay, this.dispatchAnimationEvent("animationstart")), this.paused && this.pausedTime === 0) return this.pausedTime = e, this.t;
916
+ advanceTo(e) {
917
+ if (this.startTime === void 0) {
918
+ let t = this.onStart(), n = () => (this.startTime = e + this.options.delay, this.dispatchAnimationEvent("animationstart"), this._advance(e));
919
+ return t ? t.then(n) : n();
920
+ }
921
+ return this._advance(e);
922
+ }
923
+ _advance(e) {
924
+ if (this.paused && this.pausedTime === 0) return this.pausedTime = e, this.t;
881
925
  if (this.pausedTime > 0 && !this.paused) {
882
926
  let t = e - this.pausedTime;
883
927
  this.startTime += t, this.pausedTime = 0;
884
928
  }
885
- return this.t = e - this.startTime, this.t >= this.options.duration && (await this.onEnd(), this.t = this.options.duration), this.t;
929
+ return this.t = e - this.startTime, this.t >= this.options.duration && (this.onEnd(), this.t = this.options.duration), this.t;
930
+ }
931
+ _frame(e) {
932
+ if (o(this.options.respectReducedMotion, () => !0, () => !1)) return this._snapToReducedMotion(), !1;
933
+ let t = this.advanceTo(e);
934
+ return typeof t == "number" ? this._renderFrame(t) : t.then((e) => this._renderFrame(e));
886
935
  }
887
- async _frame(e) {
888
- return o(this.options.respectReducedMotion, () => !0, () => !1) ? (await this._snapToReducedMotion(), !1) : (e = await this.advanceTo(e), this.paused ? !1 : this.done ? (this.settle(), this._resolvePlay(), !1) : (this.interpFrames(e, !0, this._interpOut), !0));
936
+ _renderFrame(e) {
937
+ return this.paused ? !1 : this.done ? (this.settle(), this._resolvePlay(), !1) : (this.interpFrames(e, !0, this._interpOut), !0);
889
938
  }
890
939
  _resolvePlay() {
891
940
  let e = this.resolvePromise;
@@ -897,7 +946,7 @@ var Z = (e) => {
897
946
  });
898
947
  }
899
948
  async _playWAAPI() {
900
- await je(this), this.settle();
949
+ await Fe(this), this.settle();
901
950
  }
902
951
  _cancelWAAPI() {
903
952
  if (this._waAnimations.length !== 0) {
@@ -910,15 +959,18 @@ var Z = (e) => {
910
959
  async _playReducedMotion() {
911
960
  this.started = !0, this.dispatchAnimationEvent("animationstart"), this.fillForwards(), this.iteration = 0, this.done = !0, this.dispatchAnimationEvent("animationend"), this.settle();
912
961
  }
913
- async _snapToReducedMotion() {
962
+ _snapToReducedMotion() {
914
963
  this._cancelWAAPI(), this.fillForwards(), this.iteration = 0, this.done = !0, this.dispatchAnimationEvent("animationend"), this.settle(), this._resolvePlay();
915
964
  }
965
+ get finished() {
966
+ return this._playingPromise ?? Promise.resolve();
967
+ }
916
968
  async play() {
917
969
  if (this.managed) throw Error("Animation.play() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play() instead.");
918
970
  if (this._playingPromise) return this._playingPromise;
919
971
  let e = o(this.options.respectReducedMotion, () => (this.waapiIneligibleReason = void 0, this._playReducedMotion()), () => {
920
972
  if (this.options.useWAAPI) {
921
- let e = Te(this);
973
+ let e = ke(this);
922
974
  return e.eligible ? (this.waapiIneligibleReason = void 0, this._playWAAPI()) : (this.waapiIneligibleReason = e.reason, this._playRAF());
923
975
  }
924
976
  return this.waapiIneligibleReason = void 0, this._playRAF();
@@ -963,9 +1015,9 @@ var Z = (e) => {
963
1015
  }), this;
964
1016
  }
965
1017
  group(...e) {
966
- return new B(this, ...e);
1018
+ return new z(this, ...e);
967
1019
  }
968
- }, Pe = class extends $ {
1020
+ }, Re = class extends $ {
969
1021
  constructor(e, ...t) {
970
1022
  super(e, t), this.unflatten = !1;
971
1023
  }
@@ -981,7 +1033,7 @@ var Z = (e) => {
981
1033
  return this.parse(), this;
982
1034
  }
983
1035
  fromKeyframes(e, t) {
984
- t = this.resolveTransform(t), ne(e) && (e = new Map(Object.entries(e)));
1036
+ t = this.resolveTransform(t), ae(e) && (e = new Map(Object.entries(e)));
985
1037
  let n = e instanceof Map ? e.entries() : Object.entries(e);
986
1038
  for (let [e, r] of n) this.addFrame(e, r, t);
987
1039
  return this.parse(), this;
@@ -989,7 +1041,7 @@ var Z = (e) => {
989
1041
  propertyRegistry = /* @__PURE__ */ new Map();
990
1042
  fromString(e, t) {
991
1043
  t = this.resolveTransform(t);
992
- let n = k(e);
1044
+ let n = D(e);
993
1045
  this.propertyRegistry = n.properties;
994
1046
  let i = n.options, a = {};
995
1047
  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({
@@ -997,7 +1049,7 @@ var Z = (e) => {
997
1049
  ...this._ctorOptions
998
1050
  });
999
1051
  for (let [e, i] of n.keyframes.entries()) {
1000
- let a = Object.fromEntries(Object.entries(i).map(([e, t]) => [e, Me(t) ? t.clone() : t])), o = n.timingFunctions.get(e), s = o ? W(o) : void 0, c;
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;
1001
1053
  if (s) {
1002
1054
  let e = o ? r(o) : void 0;
1003
1055
  c = e ? {
@@ -1024,8 +1076,8 @@ var Z = (e) => {
1024
1076
  }
1025
1077
  }
1026
1078
  transform(e) {
1027
- q(e, this.targets);
1079
+ K(e, this.targets);
1028
1080
  }
1029
1081
  };
1030
1082
  //#endregion
1031
- export { $ as Animation, B as AnimationGroup, Pe as CSSKeyframesAnimation, A as DIRECTIONS, j as FILL_MODES, F as defaultLayerConfig, P as defaultOptions, Q as getAnimationId, W as getTimingFunction, k as resolveKeyframes };
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 };