@mkbabb/keyframes.js 4.3.0 → 5.0.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.
@@ -0,0 +1,1349 @@
1
+ import { r as e, t } from "./errors-W8zkvPw4.js";
2
+ import { a as n, d as r, h as i, l as a } from "./timeline-vY3eD3Ax.js";
3
+ import { r as o } from "./springTimingFunction-D26gPkAy.js";
4
+ import { n as s } from "./scheduler-7eIr_q1g.js";
5
+ import { a as c, i as l, n as u, r as d, t as ee } from "./utils-BPRImVl5.js";
6
+ import { n as te, r as ne } from "./waapi-D0ssxKy1.js";
7
+ import { COLOR_SPACE_RANGES as re, FunctionValue as f, ValueArray as p, ValueUnit as m, clamp as ie, coerceToSyntax as ae, easeInOutCubic as oe, extractAnimationOptions as se, extractFunctions as ce, extractKeyframes as le, extractProperties as ue, extractTimelineOptions as de, isObject as fe, lerp as pe, lerpArray as me, lerpValue as he, parseCSSStylesheet as h, parseCSSTime as ge, parseCSSValue as g, parseCSSValueUnit as _e, scale as ve, seekPreviousValue as _, sleep as ye, unflattenObject as be } from "@mkbabb/value.js";
8
+ //#region src/animation/resolve-values.ts
9
+ var xe = 32, Se = () => {
10
+ let e = typeof globalThis < "u" && typeof globalThis.CSS?.supports == "function", t = typeof globalThis < "u" && typeof globalThis.matchMedia == "function";
11
+ return {
12
+ supports: e ? (e) => globalThis.CSS.supports(e) : () => !1,
13
+ matchMedia: t ? (e) => globalThis.matchMedia(e) : () => ({ matches: !1 })
14
+ };
15
+ }, v = (e, t) => ({
16
+ functions: e,
17
+ env: {
18
+ ...Se(),
19
+ ...t
20
+ },
21
+ seen: /* @__PURE__ */ new Set(),
22
+ depth: 0
23
+ }), y = Symbol("kf.resolve.drop"), b = (e) => {
24
+ let t = e.indexOf("(");
25
+ if (t <= 0 || !e.trimEnd().endsWith(")")) return;
26
+ let n = e.slice(0, t).trim().toLowerCase(), r = e.slice(t + 1, e.lastIndexOf(")")).trim();
27
+ if (!(!n || !r)) return {
28
+ name: n,
29
+ query: r
30
+ };
31
+ }, Ce = (e, t) => {
32
+ let n = String(e instanceof m ? e.value : e).trim();
33
+ if (n === "else" || n === "") return !0;
34
+ let r = b(n);
35
+ if (!r) return !1;
36
+ let { name: i, query: a } = r;
37
+ return i === "supports" ? t.env.supports?.(a) ?? !1 : i === "media" ? t.env.matchMedia?.(a)?.matches ?? !1 : i === "style" ? t.env.customProps === void 0 ? void 0 : we(a, t.env.customProps) : !1;
38
+ }, we = (e, t) => {
39
+ let n = e.indexOf(":");
40
+ if (n === -1) {
41
+ let n = e.trim();
42
+ return n === "" ? !1 : t(n) !== void 0;
43
+ }
44
+ let r = e.slice(0, n).trim(), i = e.slice(n + 1).trim();
45
+ if (r === "") return !1;
46
+ let a = t(r);
47
+ if (a === void 0) return !1;
48
+ let o = (e) => e.trim().replace(/\s+/g, " ");
49
+ return o(a) === o(i);
50
+ }, Te = (e) => e instanceof m && String(e.value).trim() === "", x = (e) => {
51
+ if (e === y) return e;
52
+ if (e instanceof m && e.unit === "string") try {
53
+ return g(String(e.value));
54
+ } catch {
55
+ return e;
56
+ }
57
+ return e;
58
+ }, Ee = (e) => {
59
+ let t = e.name.trim(), n = t.search(/\s/), r = n === -1 ? t : t.slice(0, n), i = n === -1 ? "" : t.slice(n).trim(), a = i.startsWith("<") && i.endsWith(">") ? i : void 0, o = e.type !== void 0 && !(e.type.startsWith("<") && e.type.endsWith(">")) ? e.type : void 0;
60
+ return {
61
+ ident: r,
62
+ syntax: a,
63
+ defaultValue: e.defaultValue ?? o
64
+ };
65
+ }, De = (e, t) => {
66
+ if (t.syntax === void 0) return e;
67
+ let n = ae(String(e), t.syntax);
68
+ if (n !== null) return n;
69
+ if (t.defaultValue === void 0) return y;
70
+ try {
71
+ return g(t.defaultValue);
72
+ } catch {
73
+ return y;
74
+ }
75
+ }, Oe = (e, t) => !(e instanceof m) || e.unit !== "var" ? !1 : String(e.value).split(",", 1)[0]?.trim() === t, S = (e, t) => {
76
+ if (e instanceof m) {
77
+ if (e.unit === "var") {
78
+ for (let [n, r] of t) if (Oe(e, n)) return r.clone();
79
+ }
80
+ return e;
81
+ }
82
+ let n = e.values.map((e) => S(e, t));
83
+ return new f(e.name, n);
84
+ }, ke = (e, t) => {
85
+ if (t.seen.has(e.name)) return y;
86
+ let n = t.functions.get(e.name);
87
+ if (n === void 0 || n.result === void 0) return y;
88
+ let r = (n.parameters ?? []).map(Ee), i = e.values;
89
+ if (i.length > r.length) return y;
90
+ let a = /* @__PURE__ */ new Map();
91
+ for (let e = 0; e < r.length; e++) {
92
+ let t = r[e], n = i[e], o;
93
+ if (n === void 0) {
94
+ if (t.defaultValue === void 0) return y;
95
+ try {
96
+ o = g(t.defaultValue);
97
+ } catch {
98
+ return y;
99
+ }
100
+ } else o = De(n, t);
101
+ if (o === y) return y;
102
+ a.set(t.ident, o);
103
+ }
104
+ let o = n.result.clone().map((e) => S(e, a));
105
+ t.seen.add(e.name);
106
+ let s = [];
107
+ for (let e of o) {
108
+ let n = C(e, {
109
+ ...t,
110
+ depth: t.depth + 1
111
+ });
112
+ n !== y && s.push(n);
113
+ }
114
+ return t.seen.delete(e.name), s.length === 0 ? y : s[0];
115
+ }, Ae = (e, t) => {
116
+ let n = e.values, r = n[0], i = n[1], a = n[2];
117
+ if (r === void 0 || i === void 0) return y;
118
+ let o = Ce(r, t);
119
+ return o === void 0 ? e : o ? x(C(i, t)) : a !== void 0 && !Te(a) ? x(C(a, t)) : y;
120
+ }, C = (e, t) => {
121
+ if (t.depth > xe) return y;
122
+ if (e instanceof m || !(e instanceof f)) return e;
123
+ if (e.name === "if") return Ae(e, {
124
+ ...t,
125
+ depth: t.depth + 1
126
+ });
127
+ if (e.name === "sibling-index") {
128
+ let n = t.env.siblingIndex;
129
+ return n === void 0 ? e : new m(n(), "");
130
+ }
131
+ if (e.name === "sibling-count") {
132
+ let n = t.env.siblingCount;
133
+ return n === void 0 ? e : new m(n(), "");
134
+ }
135
+ if (e.name.startsWith("--") && t.functions.has(e.name)) return ke(e, t);
136
+ let n = [], r = !1;
137
+ for (let i of e.values) {
138
+ let e = C(i, {
139
+ ...t,
140
+ depth: t.depth + 1
141
+ });
142
+ if (e === y) {
143
+ r = !0;
144
+ continue;
145
+ }
146
+ e !== i && (r = !0), n.push(e);
147
+ }
148
+ return r ? new f(e.name, n) : e;
149
+ }, w = (e, t) => {
150
+ let n = [], r = !1;
151
+ for (let i of e) {
152
+ let e = C(i, t);
153
+ if (e === y) {
154
+ r = !0;
155
+ continue;
156
+ }
157
+ e !== i && (r = !0), n.push(e);
158
+ }
159
+ return n.length === 0 ? y : r ? new p(...n) : e;
160
+ }, je = (e) => {
161
+ if (e.name !== "if") return !1;
162
+ let t = e.values[0];
163
+ return t === void 0 ? !1 : b(String(t instanceof m ? t.value : t).trim())?.name === "style";
164
+ }, T = (e) => e instanceof f ? e.name === "if" || e.name === "spring" || e.name === "sibling-index" || e.name === "sibling-count" || e.name.startsWith("--") ? !0 : e.values.some((e) => T(e)) : e instanceof p ? e.some((e) => T(e)) : !1, E = (e) => e instanceof f ? e.name === "sibling-index" || e.name === "sibling-count" || je(e) ? !0 : e.values.some((e) => E(e)) : e instanceof p ? e.some((e) => E(e)) : !1, Me = (e, t) => {
165
+ let n = {};
166
+ for (let r of e.declarations) {
167
+ let e = r.value;
168
+ if (e instanceof p && T(e)) {
169
+ let n = w(e, t);
170
+ if (n === y) continue;
171
+ e = n;
172
+ }
173
+ n[r.name] = e;
174
+ }
175
+ return n;
176
+ }, Ne = (e) => {
177
+ let t = [];
178
+ for (let n of e.selectors) n.kind === "percent" ? t.push(`${n.value}%`) : t.push(n.name);
179
+ return t;
180
+ }, D = (e) => {
181
+ let t = le(e);
182
+ for (let e of t.values()) if (e.length > 0) return e;
183
+ return [];
184
+ }, O = (e, t) => {
185
+ let n = [], r = (e, t) => {
186
+ n.push({
187
+ code: e,
188
+ message: t.message ?? e,
189
+ ...t
190
+ });
191
+ }, i = typeof e == "string" ? h(e) : e, a = D(i);
192
+ typeof e == "string" && a.length === 0 && e.trim() && (i = h(`@keyframes anonymous {\n${e.trim()}\n}`), a = D(i)), typeof e == "string" && a.length === 0 && e.trim() && r("EMPTY_PARSE", {
193
+ message: "the input is non-empty but parsed to zero @keyframes rules (no animatable stops) — the resulting animation has no frames",
194
+ input: e
195
+ });
196
+ let o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = ce(i), u = v(l, t);
197
+ for (let e of a) {
198
+ let t = Me(e, u);
199
+ for (let n of Ne(e)) {
200
+ let r = o.get(n);
201
+ o.set(n, {
202
+ ...r ?? {},
203
+ ...t
204
+ }), e.timingFunction != null && s.set(n, e.timingFunction);
205
+ let i = e.composition;
206
+ i != null && c.set(n, i);
207
+ }
208
+ }
209
+ return {
210
+ keyframes: o,
211
+ timingFunctions: s,
212
+ composition: c,
213
+ properties: ue(i),
214
+ functions: l,
215
+ options: se(i),
216
+ diagnostics: n,
217
+ stylesheet: i
218
+ };
219
+ }, k = [
220
+ "normal",
221
+ "reverse",
222
+ "alternate",
223
+ "alternate-reverse"
224
+ ], A = [
225
+ "none",
226
+ "forwards",
227
+ "backwards",
228
+ "both"
229
+ ], j = Object.keys(re), M = [
230
+ "shorter",
231
+ "longer",
232
+ "increasing",
233
+ "decreasing"
234
+ ], N = () => {}, P = {
235
+ duration: 1e3,
236
+ delay: 0,
237
+ iterationCount: 1,
238
+ direction: "normal",
239
+ fillMode: "forwards",
240
+ timingFunction: { fn: oe },
241
+ useWAAPI: !0,
242
+ respectReducedMotion: !1,
243
+ colorSpace: "oklab"
244
+ }, F = {
245
+ zIndex: 0,
246
+ weight: 1,
247
+ blendMode: "replace",
248
+ enabled: !0
249
+ }, I = (e) => typeof e == "string" ? e : Q(e), L = (e, t, n) => {
250
+ let r = I(t), i = e[r];
251
+ if (!i) throw Error(`AnimationGroup.${n}: no animation registered for key "${r}". Known keys: ${Object.keys(e).join(", ") || "(none)"}.`);
252
+ return i;
253
+ }, Pe = (e, t, r) => {
254
+ let i = new n({
255
+ ...r,
256
+ initial: e
257
+ });
258
+ return i.target = t, i;
259
+ }, Fe = (e) => {
260
+ let t = /* @__PURE__ */ new Set();
261
+ for (let n of e) {
262
+ let e = n.layer.properties;
263
+ for (let r of n.animation.flatKeys) e && !e.has(r) || t.add(r);
264
+ }
265
+ return [...t];
266
+ }, R = (e, t) => {
267
+ let n;
268
+ for (let r of e) {
269
+ let e = r.animation;
270
+ if (e.paused && e.pausedTime !== 0) continue;
271
+ let i = e.advanceTo(t);
272
+ typeof i != "number" && (n ??= []).push(i);
273
+ }
274
+ return n && Promise.all(n).then(() => void 0);
275
+ }, Ie = async (e, t, n) => {
276
+ for (let r = 0; r < e.length; r += n) await R(e.slice(r, r + n), t), r + n < e.length && await s();
277
+ }, z = (e) => {
278
+ let t = !0;
279
+ for (let n of e) n.animation.interpFrames(n.animation.t, !0), t &&= n.animation.done;
280
+ return t;
281
+ }, Le = (e) => {
282
+ for (let t of e) {
283
+ let e = t.animation;
284
+ e.started = !0, e.t = e.options.duration, e.interpFrames(e.t, !0);
285
+ }
286
+ }, B = (e, t) => {
287
+ for (let n of e) n.animation.paused = t;
288
+ }, V = (e) => e instanceof m && typeof e.value == "number", Re = (e, t) => {
289
+ let { carriers: n, incomings: r } = t, i = n.length;
290
+ if (i !== 0) {
291
+ for (let t = 0; t < i; t++) e[t] = n[t].value;
292
+ if (t.weighted) {
293
+ let n = t.layer.weightSpring?.value ?? t.layer.weight;
294
+ for (let t = 0; t < i; t++) e[t] = pe(e[t], r[t].value, n);
295
+ } else for (let t = 0; t < i; t++) e[t] = e[t] + r[t].value;
296
+ for (let t = 0; t < i; t++) n[t].value = e[t];
297
+ }
298
+ }, ze = (e, t) => {
299
+ let n = [], r = {}, i = 0;
300
+ for (let t of e) {
301
+ let { layer: e, values: a } = t;
302
+ if (!e.enabled) continue;
303
+ let o = e.properties, s = e.blendMode === "weighted";
304
+ if (e.blendMode === "replace") {
305
+ for (let e in a) {
306
+ if (o && !o.has(e)) continue;
307
+ let t = a[e];
308
+ t !== void 0 && (r[e] = t);
309
+ }
310
+ continue;
311
+ }
312
+ let c = [], l = [], u = [];
313
+ for (let e in a) {
314
+ if (o && !o.has(e)) continue;
315
+ let t = a[e];
316
+ if (t === void 0) continue;
317
+ let n = r[e];
318
+ if (Array.isArray(n) && Array.isArray(t)) {
319
+ let r = Math.min(n.length, t.length), i = !0;
320
+ for (let e = 0; e < r; e++) if (!V(n[e]) || !V(t[e])) {
321
+ i = !1;
322
+ break;
323
+ }
324
+ if (i) for (let e = 0; e < r; e++) c.push(n[e]), l.push(t[e]);
325
+ else u.push(e);
326
+ } else u.push(e), r[e] = t;
327
+ }
328
+ c.length > i && (i = c.length), n.push({
329
+ layer: e,
330
+ weighted: s,
331
+ carriers: c,
332
+ incomings: l,
333
+ boxedKeys: u
334
+ });
335
+ }
336
+ let a = t;
337
+ return i > 0 && (a === null || a.length < i) && (a = new Float64Array(i)), {
338
+ plans: n,
339
+ compositeBuf: a
340
+ };
341
+ }, H = class e {
342
+ animations = {};
343
+ transform = N;
344
+ superKey;
345
+ paused = !1;
346
+ started = !1;
347
+ done = !1;
348
+ respectReducedMotion = !1;
349
+ static YIELD_BATCH = 32;
350
+ singleTarget = !0;
351
+ lastTickTime = 0;
352
+ playback = new a();
353
+ resolvePromise = null;
354
+ _playingPromise = null;
355
+ _boundFrame;
356
+ _entries = [];
357
+ _entriesDirty = !0;
358
+ _grouped = {};
359
+ _groupedKeys = [];
360
+ _groupedKeysDirty = !0;
361
+ _soaPlans = null;
362
+ _compositeBuf = null;
363
+ _hasLayerSprings = !1;
364
+ constructor(...e) {
365
+ this._boundFrame = this._frame.bind(this);
366
+ let t = [];
367
+ for (let n of e) {
368
+ let e, r;
369
+ n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform === N && e.frames[0] != null && (this.transform = e.frames[0].transform);
370
+ let i = Q(e);
371
+ this.animations[i] = {
372
+ values: {},
373
+ animation: e,
374
+ layer: {
375
+ ...F,
376
+ ...r
377
+ }
378
+ }, e.managed = !0, t.push(e);
379
+ }
380
+ this.singleTarget = t.every((e) => e.targets[0] === t[0]?.targets[0]), this.invalidateEntries();
381
+ }
382
+ getEntries() {
383
+ return this._entriesDirty &&= (this._entries = Object.values(this.animations), this._entries.sort((e, t) => e.layer.zIndex - t.layer.zIndex), !1), this._entries;
384
+ }
385
+ invalidateEntries() {
386
+ this._entriesDirty = !0, this._groupedKeysDirty = !0;
387
+ }
388
+ setSuperKey(e) {
389
+ this.superKey = e;
390
+ for (let t of this.getEntries()) t.animation.superKey = e;
391
+ return this;
392
+ }
393
+ setTargets(...e) {
394
+ let t = this.getEntries();
395
+ for (let n of t) n.animation.setTargets(...e);
396
+ return this.singleTarget = t.every((e) => e.animation.targets[0] === t[0]?.animation.targets[0]), this;
397
+ }
398
+ onStart() {
399
+ return this.started = !0, this;
400
+ }
401
+ onEnd() {
402
+ return this;
403
+ }
404
+ transformFramesGrouped(e) {
405
+ let t = this._grouped;
406
+ this._groupedKeysDirty && (this._groupedKeys = Fe(this.getEntries()), this._groupedKeysDirty = !1, this._soaPlans = null);
407
+ let n = this._groupedKeys;
408
+ for (let e = 0; e < n.length; e++) t[n[e]] = void 0;
409
+ let r = this.getEntries(), i = this._soaPlans !== null, a = 0, o = !0;
410
+ for (let e of r) {
411
+ let { animation: n, layer: r, values: s } = e;
412
+ if (o &&= n.done, !r.enabled) continue;
413
+ n.interpFrames(n.t, !1, s);
414
+ let c = r.properties;
415
+ if (r.blendMode === "replace") {
416
+ for (let e in s) {
417
+ if (c && !c.has(e)) continue;
418
+ let n = s[e];
419
+ n !== void 0 && (t[e] = n);
420
+ }
421
+ continue;
422
+ }
423
+ if (i) {
424
+ let e = this._soaPlans[a++];
425
+ this.soaBlendLayer(e), e.boxedKeys.length > 0 && this.boxedBlendArm(r, s, t, c, e.boxedKeys);
426
+ } else this.boxedBlendArm(r, s, t, c);
427
+ }
428
+ if (!i) {
429
+ let { plans: e, compositeBuf: t } = ze(r, this._compositeBuf);
430
+ this._soaPlans = e, this._compositeBuf = t;
431
+ }
432
+ this.done = o;
433
+ for (let e = 0; e < n.length; e++) {
434
+ let r = n[e];
435
+ t[r] === void 0 && delete t[r];
436
+ }
437
+ if (this.transform === N) for (let e of this.getEntries()) {
438
+ let t = e.animation.frames[0];
439
+ if (t != null && t.transform != null) {
440
+ this.transform = t.transform;
441
+ break;
442
+ }
443
+ }
444
+ return this.transform(t, e), t;
445
+ }
446
+ boxedBlendArm(e, t, n, r, i) {
447
+ let a = i ? new Set(i) : void 0;
448
+ if (e.blendMode === "add") {
449
+ for (let e in t) {
450
+ if (a && !a.has(e) || r && !r.has(e)) continue;
451
+ let i = t[e];
452
+ if (i === void 0) continue;
453
+ let o = n[e];
454
+ if (Array.isArray(o) && Array.isArray(i)) {
455
+ let e = Math.min(o.length, i.length);
456
+ for (let t = 0; t < e; t++) V(o[t]) && V(i[t]) ? o[t].value += i[t].value : o[t] = i[t];
457
+ } else n[e] = i;
458
+ }
459
+ return;
460
+ }
461
+ let o = e.weightSpring?.value ?? e.weight;
462
+ for (let e in t) {
463
+ if (a && !a.has(e) || r && !r.has(e)) continue;
464
+ let i = t[e];
465
+ if (i === void 0) continue;
466
+ let s = n[e];
467
+ if (Array.isArray(s) && Array.isArray(i)) {
468
+ let e = Math.min(s.length, i.length);
469
+ for (let t = 0; t < e; t++) V(s[t]) && V(i[t]) ? s[t].value = pe(s[t].value, i[t].value, o) : s[t] = i[t];
470
+ } else n[e] = i;
471
+ }
472
+ }
473
+ soaBlendLayer(e) {
474
+ Re(this._compositeBuf, e);
475
+ }
476
+ render() {
477
+ let e = this.lastTickTime || performance.now();
478
+ this.singleTarget ? this.transformFramesGrouped(e) : z(this.getEntries());
479
+ }
480
+ setChildTime(e, t) {
481
+ let n = L(this.animations, e, "setChildTime").animation;
482
+ return n.t = t, n.startTime !== void 0 && (n.pausedTime = n.startTime + t), this;
483
+ }
484
+ advanceTo(t) {
485
+ let n = this.lastTickTime === 0 ? 0 : t - this.lastTickTime;
486
+ this._hasLayerSprings && this.advanceLayerSprings(n), this.lastTickTime = t, this.started || this.onStart();
487
+ let r = this.getEntries(), i = e.YIELD_BATCH, a = r.length <= i ? R(r, t) : Ie(r, t, i);
488
+ return a ? a.then(() => this._endAdvance()) : this._endAdvance();
489
+ }
490
+ _endAdvance() {
491
+ return this.done && this.onEnd(), this;
492
+ }
493
+ _frame(e) {
494
+ let t = this.advanceTo(e);
495
+ return typeof t.then == "function" ? t.then(() => this._renderFrame(e)) : this._renderFrame(e);
496
+ }
497
+ _renderFrame(e) {
498
+ return this.paused ? !1 : (this.singleTarget ? this.transformFramesGrouped(e) : this.done = z(this.getEntries()), this.done ? (this.settle(), this._resolvePlay(), !1) : !0);
499
+ }
500
+ _resolvePlay() {
501
+ let e = this.resolvePromise;
502
+ this.resolvePromise = null, e?.();
503
+ }
504
+ get finished() {
505
+ return this._playingPromise ?? Promise.resolve();
506
+ }
507
+ async play() {
508
+ if (this._playingPromise) return this._playingPromise;
509
+ let e = r(this.respectReducedMotion, () => this._playReducedMotion(), () => new Promise((e) => {
510
+ this.resolvePromise = e, this.playback.loop(this._boundFrame);
511
+ }));
512
+ return this._playingPromise = e, e.finally(() => {
513
+ this._playingPromise = null;
514
+ }), e;
515
+ }
516
+ _playReducedMotion() {
517
+ this.onStart();
518
+ let e = this.lastTickTime || performance.now();
519
+ return this.lastTickTime = e, Le(this.getEntries()), this.singleTarget && this.transformFramesGrouped(e), this.settle(), Promise.resolve();
520
+ }
521
+ pause() {
522
+ if (!this.started || this.paused) return this;
523
+ this.paused = !0;
524
+ let e = this.lastTickTime || performance.now();
525
+ for (let t of this.getEntries()) {
526
+ let n = t.animation;
527
+ n.pause(), n.pausedTime === 0 && (n.pausedTime = e);
528
+ }
529
+ return this.playback.stop(), this.render(), this;
530
+ }
531
+ resume() {
532
+ return !this.started || !this.paused ? this : (this.paused = !1, B(this.getEntries(), !1), this.playback.loop(this._boundFrame), this);
533
+ }
534
+ toggle() {
535
+ return this.paused ? this.resume() : this.pause();
536
+ }
537
+ settle() {
538
+ for (let e of this.getEntries()) e.animation.managed = !1, e.animation.settle();
539
+ return this.started = !1, this.done = !1, this.paused = !1, this.lastTickTime = 0, this;
540
+ }
541
+ reset() {
542
+ for (let e of this.getEntries()) {
543
+ let t = e.animation;
544
+ t.started && t.frames.length > 0 && t.interpFrames(0, !0);
545
+ }
546
+ return this.settle();
547
+ }
548
+ stop() {
549
+ return this.playback.stop(), this.reset(), this._resolvePlay(), this;
550
+ }
551
+ playing() {
552
+ return !(!this.started || this.paused);
553
+ }
554
+ forcePause() {
555
+ this.paused = !0, B(this.getEntries(), !0);
556
+ }
557
+ forcePlay() {
558
+ this.paused = !1, B(this.getEntries(), !1);
559
+ }
560
+ setLayerConfig(e, t) {
561
+ let n = L(this.animations, e, "setLayerConfig");
562
+ return Object.assign(n.layer, t), this.invalidateEntries(), this;
563
+ }
564
+ setLayerEnabled(e, t) {
565
+ return this.setLayerConfig(e, { enabled: t });
566
+ }
567
+ getLayerConfig(e) {
568
+ return this.animations[I(e)]?.layer;
569
+ }
570
+ transitionLayer(e, t) {
571
+ let r = L(this.animations, e, "transitionLayer").layer;
572
+ r.blendMode = "weighted";
573
+ let i = r.weightSpring;
574
+ return i instanceof n ? i.target = t.weight : r.weightSpring = Pe(r.weight, t.weight, t.spring), this._hasLayerSprings = !0, this.invalidateEntries(), this;
575
+ }
576
+ crossfade(e, t, n) {
577
+ let r = n?.spring;
578
+ return this.transitionLayer(e, {
579
+ weight: 0,
580
+ ...r ? { spring: r } : {}
581
+ }), this.transitionLayer(t, {
582
+ weight: 1,
583
+ ...r ? { spring: r } : {}
584
+ }), this;
585
+ }
586
+ advanceLayerSprings(e) {
587
+ let t = !1;
588
+ for (let n of this.getEntries()) {
589
+ let r = n.layer.weightSpring;
590
+ r !== void 0 && (e > 0 && r.tickDt(e), r.settled ? (n.layer.weight = r.value, delete n.layer.weightSpring) : t = !0);
591
+ }
592
+ this._hasLayerSprings = t;
593
+ }
594
+ };
595
+ //#endregion
596
+ //#region src/animation/engine-composition.ts
597
+ function Be(e) {
598
+ for (let t of e) if (t.composition != null && t.composition !== "replace") return !0;
599
+ return !1;
600
+ }
601
+ function Ve(e, t) {
602
+ e.clear(), t.clear();
603
+ }
604
+ function He(e, t) {
605
+ let n = e.composition;
606
+ if (n == null || n === "replace") return;
607
+ let r = e.flatVars;
608
+ for (let i in r) {
609
+ let a = r[i];
610
+ if (!Array.isArray(a) || a.length === 0) continue;
611
+ if (!a.every((e) => e instanceof m && typeof e.value == "number")) {
612
+ Ge(i, n, t);
613
+ continue;
614
+ }
615
+ let o = t.compositionBase.get(i);
616
+ o === void 0 && (o = Ue(t.target, i, a.length), t.compositionBase.set(i, o));
617
+ let s = n === "accumulate" ? t.iteration : 0;
618
+ for (let n = 0; n < a.length; n++) {
619
+ let r = a[n], c = o[n] ?? 0;
620
+ s > 0 ? r.value = c + s * (We(e, i, n, t.compositionBase) - c) + r.value : r.value = c + r.value;
621
+ }
622
+ }
623
+ }
624
+ function Ue(e, t, n) {
625
+ let r = Array(n).fill(0);
626
+ if (e == null || e.style == null) return r;
627
+ let i = t.split(".").pop() ?? t, a = e.style.getPropertyValue(i) || e.style[i] || "";
628
+ if (!a) return r;
629
+ let o = a.match(/-?\d*\.?\d+(?:e[+-]?\d+)?/gi);
630
+ if (o == null) return r;
631
+ for (let e = 0; e < n && e < o.length; e++) {
632
+ let t = Number.parseFloat(o[e]);
633
+ Number.isFinite(t) && (r[e] = t);
634
+ }
635
+ return r;
636
+ }
637
+ function We(e, t, n, r) {
638
+ let i = e.interpVars[t]?.[n]?.stop;
639
+ return i instanceof m && typeof i.value == "number" ? i.value : r.get(t)?.[n] ?? 0;
640
+ }
641
+ function Ge(e, t, n) {
642
+ n.compositionFallbackSeen.has(e) || (n.compositionFallbackSeen.add(e), n.diagnostics.push({
643
+ code: "COMPOSITION_FALLBACK",
644
+ 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`,
645
+ property: e
646
+ }));
647
+ }
648
+ //#endregion
649
+ //#region src/animation/frame-compiler-numeric.ts
650
+ var Ke = (e) => typeof e.start.value == "number" && typeof e.stop.value == "number" && e.computed !== !0 && e.value.unit !== "color" && e._colorPlan == null, qe = (e) => {
651
+ let t = [], n = [];
652
+ for (let r of e) Ke(r) ? t.push(r) : n.push(r);
653
+ let r = t.length, i = new Float64Array(r), a = new Float64Array(r);
654
+ for (let e = 0; e < r; e++) i[e] = t[e].start.value, a[e] = t[e].stop.value;
655
+ return {
656
+ numeric: t,
657
+ from: i,
658
+ to: a,
659
+ out: new Float64Array(r),
660
+ boxed: n
661
+ };
662
+ }, U = (e, n) => {
663
+ if (typeof n == "function") return { fn: n };
664
+ if (typeof n == "object") {
665
+ if (typeof n.fn == "function") return n;
666
+ throw new t(e, n, "an Easing must carry a callable `fn`");
667
+ }
668
+ let r = d(n);
669
+ if (!r) throw new t(e, n, "unknown timing function — pass a callable TimingFunction, a typed Easing, a registry name, or a cubic-bezier() literal", "UNKNOWN_TIMING_FN");
670
+ let a = i(n);
671
+ return a ? {
672
+ fn: r,
673
+ css: a
674
+ } : { fn: r };
675
+ }, Je = 1e6, Ye = /^(?:from|to)$/i, Xe = /^(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?%$/, Ze = /^(?:entry|exit|cover|contain)(?:\s+\d+(?:\.\d+)?%)?$/i, W = "named-selector", Qe = /^(entry|exit|cover|contain)(?:\s+(\d+(?:\.\d+)?)%)?$/i, $e = {
676
+ entry: {
677
+ start: 0,
678
+ end: .25
679
+ },
680
+ cover: {
681
+ start: .25,
682
+ end: .75
683
+ },
684
+ contain: {
685
+ start: .375,
686
+ end: .625
687
+ },
688
+ exit: {
689
+ start: .75,
690
+ end: 1
691
+ }
692
+ }, et = (e) => {
693
+ let n = Qe.exec(e.trim());
694
+ if (n === null) throw new t("start", e, "not a conforming scroll-range named selector (entry/exit/cover/contain, optionally with a range fraction like 'entry 50%')", "NAMED_SELECTOR_NO_TIMELINE");
695
+ let r = $e[n[1].toLowerCase()], i = n[2];
696
+ if (i === void 0) return r.start;
697
+ let a = Number.parseFloat(i) / 100;
698
+ return r.start + a * (r.end - r.start);
699
+ }, G = "a keyframe selector must be a percentage 0%–100% (e.g. \"0%\", \"50%\"), the keyword 'from'/'to', or a scroll-range named selector (entry/exit/cover/contain, optionally with a range fraction like 'entry 0%')", tt = class {
700
+ _options;
701
+ templateFrames = [];
702
+ parsedVars = [];
703
+ frames = [];
704
+ frameId = 0;
705
+ constructor(e) {
706
+ this._options = e;
707
+ }
708
+ get options() {
709
+ return this._options;
710
+ }
711
+ addFrame(e, n, r, i, a) {
712
+ typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof m && (e = String(e));
713
+ let o = e.trim();
714
+ if (o === "") throw new t("start", e, `${G} — got an empty/blank string`, "EMPTY_PARSE");
715
+ let s;
716
+ if (Ze.test(o)) s = new m(o, void 0, [W]);
717
+ else {
718
+ if (!Ye.test(o) && !(Xe.test(o) && parseFloat(o) <= 100)) throw new t("start", e, `${G} — got ${JSON.stringify(e)}`);
719
+ s = _e(o);
720
+ }
721
+ let c = {
722
+ id: this.frameId,
723
+ start: s,
724
+ vars: n,
725
+ transform: r,
726
+ timingFunction: i == null ? this.options.timingFunction : U("timingFunction", i),
727
+ composition: a
728
+ };
729
+ this.templateFrames.push(c), this.frameId += 1;
730
+ }
731
+ createFrame(e, t) {
732
+ let n = this.templateFrames[e], r = this.templateFrames[t], i = {
733
+ start: e,
734
+ stop: t
735
+ }, a = ee(n, r, this.options.duration), o = n.transform;
736
+ if (o == null) {
737
+ let t = _(e, this.templateFrames, (e) => e.transform != null);
738
+ o = (t === void 0 ? void 0 : this.templateFrames[t].transform) ?? N;
739
+ }
740
+ let s = n.timingFunction;
741
+ if (s == null) {
742
+ let t = _(e, this.templateFrames, (e) => e.timingFunction != null);
743
+ s = (t === void 0 ? void 0 : this.templateFrames[t].timingFunction) ?? this.options.timingFunction;
744
+ }
745
+ let c = e * Je + t, l = r.composition;
746
+ return {
747
+ id: c,
748
+ ixs: i,
749
+ start: n.start,
750
+ time: a,
751
+ vars: void 0,
752
+ flatVars: void 0,
753
+ interpVars: {},
754
+ allInterpVars: [],
755
+ transform: o,
756
+ timingFunction: s,
757
+ ...l == null ? {} : { composition: l }
758
+ };
759
+ }
760
+ buildVarIndex() {
761
+ let e = /* @__PURE__ */ new Map();
762
+ for (let t = 0; t < this.parsedVars.length; t++) for (let n of Object.keys(this.parsedVars[t])) {
763
+ let r = e.get(n);
764
+ r || (r = [], e.set(n, r)), r.push(t);
765
+ }
766
+ return e;
767
+ }
768
+ reconcileVars(e, t) {
769
+ let n = this.parsedVars[e];
770
+ if (n) for (let r of Object.keys(n)) {
771
+ let n = t.get(r);
772
+ if (!n) continue;
773
+ let i = -1;
774
+ for (let t of n) if (t > e) {
775
+ i = t;
776
+ break;
777
+ }
778
+ if (i === -1) continue;
779
+ 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];
780
+ c.interpVars[r] = u(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
781
+ }
782
+ }
783
+ parse(e) {
784
+ this.frames = [], this.templateFrames.sort((e, t) => e.start.value - t.start.value), this.parsedVars = this.templateFrames.map((t) => {
785
+ let n = l(t.vars);
786
+ return Object.values(n).forEach((t) => {
787
+ t.setTargets(e);
788
+ }), n;
789
+ });
790
+ for (let e = 0; e < this.templateFrames.length - 1; e++) this.frames.push(this.createFrame(e, e + 1));
791
+ let t = this.buildVarIndex();
792
+ 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));
793
+ }
794
+ finalizeFrameVars(e) {
795
+ e.flatVars = Object.entries(e.interpVars).reduce((e, [t, n]) => (e[t] = n.map((e) => e.value), e), {}), e.vars = be(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat(), e._numericPlan = qe(e.allInterpVars);
796
+ }
797
+ renormalizeColors() {
798
+ for (let e of this.frames) {
799
+ for (let t of Object.keys(e.interpVars)) e.interpVars[t] = u(t, e.ixs.start, e.ixs.stop, this.parsedVars, this.options.colorSpace, this.options.hueMethod);
800
+ this.finalizeFrameVars(e);
801
+ }
802
+ }
803
+ }, K = (e) => {
804
+ try {
805
+ let t = ge(e);
806
+ return Number.isFinite(t) ? t : void 0;
807
+ } catch {
808
+ return;
809
+ }
810
+ };
811
+ function nt(e) {
812
+ return e == null ? P.timingFunction : U("timingFunction", e);
813
+ }
814
+ function rt(t) {
815
+ return t == null ? P.iterationCount : t === "infinite" || t === "∞" || t === "Infinity" || t === Infinity ? Infinity : e("iterationCount", t, (e) => {
816
+ let t = typeof e == "string" ? Number.parseFloat(e.trim()) : e;
817
+ return typeof t == "number" && !Number.isNaN(t) && t >= 0 ? t : void 0;
818
+ }, "expected a non-negative count, \"infinite\", or Infinity");
819
+ }
820
+ function it(t) {
821
+ if (t != null) return e("duration", t, (e) => {
822
+ let t = typeof e == "string" ? K(e) : e;
823
+ return typeof t == "number" && isFinite(t) && t > 0 ? t : void 0;
824
+ }, "expected a positive duration in milliseconds or a CSS time string");
825
+ }
826
+ function at(t) {
827
+ return t == null ? P.delay : e("delay", t, (e) => {
828
+ let t = typeof e == "string" ? K(e) : e;
829
+ return typeof t == "number" && isFinite(t) ? t : void 0;
830
+ }, "expected a delay in milliseconds or a CSS time string");
831
+ }
832
+ function ot(e) {
833
+ if (e == null) return P.direction;
834
+ if (!k.includes(e)) throw new t("direction", e, `expected one of: ${k.join(", ")}`);
835
+ return e;
836
+ }
837
+ function st(e) {
838
+ if (e == null) return P.fillMode;
839
+ if (!A.includes(e)) throw new t("fillMode", e, `expected one of: ${A.join(", ")}`);
840
+ return e;
841
+ }
842
+ function q(e, n) {
843
+ if (n == null) return P[e];
844
+ if (typeof n != "boolean") throw new t(e, n, "expected a boolean");
845
+ return n;
846
+ }
847
+ function ct(e) {
848
+ if (e == null) return P.colorSpace;
849
+ if (!j.includes(e)) throw new t("colorSpace", e, `expected one of: ${j.join(", ")}`);
850
+ return e;
851
+ }
852
+ function lt(e) {
853
+ if (e != null) {
854
+ if (!M.includes(e)) throw new t("hueMethod", e, `expected one of: ${M.join(", ")}`);
855
+ return e;
856
+ }
857
+ }
858
+ //#endregion
859
+ //#region src/animation/engine-css-metadata.ts
860
+ function ut(e) {
861
+ let t = {};
862
+ return e.duration != null && (t.duration = e.duration), e.timingFunction != null && (t.timingFunction = e.timingFunction), e.iterationCount !== void 0 && (t.iterationCount = e.iterationCount === null ? Infinity : e.iterationCount), e.direction != null && (t.direction = e.direction), e.delay != null && (t.delay = e.delay), e.fillMode != null && (t.fillMode = e.fillMode), e.composition != null && (t.composite = e.composition), t;
863
+ }
864
+ function dt(e) {
865
+ let t = de(e);
866
+ return Object.keys(t).length > 0 ? t : void 0;
867
+ }
868
+ function ft(e) {
869
+ if (!(typeof CSS > "u" || typeof CSS.registerProperty != "function")) for (let [t, n] of e) {
870
+ if (n.syntax == null) continue;
871
+ let e = {
872
+ name: t,
873
+ syntax: n.syntax,
874
+ inherits: n.inherits ?? !1
875
+ };
876
+ n.initialValue != null && (e.initialValue = n.initialValue.toString());
877
+ try {
878
+ CSS.registerProperty(e);
879
+ } catch {}
880
+ }
881
+ }
882
+ //#endregion
883
+ //#region src/animation/engine-playback.ts
884
+ function J(e) {
885
+ if (e.reversed = !1, (e.options.direction === "reverse" || e.options.direction === "alternate-reverse" && e.iteration % 2 == 0 || e.options.direction === "alternate" && e.iteration % 2 == 1) && e.reverse(), (e.options.fillMode === "backwards" || e.options.fillMode === "both") && e.fillBackwards(), e.options.delay > 0) return e.paused = !0, ye(e.options.delay).then(() => {
886
+ e.paused = !1, e.started = !0;
887
+ });
888
+ e.started = !0;
889
+ }
890
+ function pt(e) {
891
+ e.paintRest(), e.startTime = void 0, e.iteration >= e.options.iterationCount - 1 ? (e.done = !0, e.iteration = 0, e.dispatchAnimationEvent("animationend")) : (e.iteration += 1, e.dispatchAnimationEvent("animationiteration"));
892
+ }
893
+ function mt(e, t) {
894
+ if (e.startTime === void 0) {
895
+ let n = J(e), r = () => (e.startTime = t + e.options.delay, e.dispatchAnimationEvent("animationstart"), ht(e, t));
896
+ return n ? n.then(r) : r();
897
+ }
898
+ return ht(e, t);
899
+ }
900
+ function ht(e, t) {
901
+ if (e.paused && e.pausedTime === 0) return e.pausedTime = t, e.t;
902
+ if (e.pausedTime > 0 && !e.paused) {
903
+ let n = t - e.pausedTime;
904
+ e.startTime += n, e.pausedTime = 0;
905
+ }
906
+ return e.t = t - e.startTime, e.t >= e.options.duration && (pt(e), e.t = e.options.duration), e.t;
907
+ }
908
+ function gt(e, t) {
909
+ if (r(e.options.respectReducedMotion, () => !0, () => !1)) return xt(e), !1;
910
+ let n = e.advanceTo(t);
911
+ return typeof n == "number" ? _t(e, n) : n.then((t) => _t(e, t));
912
+ }
913
+ function _t(e, t) {
914
+ return e.paused ? !1 : e.done ? (Z(e), Y(e), !1) : (e.interpFrames(t, !0, e._interpOut), !0);
915
+ }
916
+ function Y(e) {
917
+ let t = e.resolvePromise;
918
+ e.resolvePromise = null, t?.();
919
+ }
920
+ function vt(e) {
921
+ return new Promise((t) => {
922
+ e.resolvePromise = t, e.playback.loop(e._boundFrame);
923
+ });
924
+ }
925
+ async function yt(e) {
926
+ await ne(e), Z(e);
927
+ }
928
+ function X(e) {
929
+ if (e._waAnimations.length !== 0) {
930
+ for (let t of e._waAnimations) try {
931
+ t.cancel();
932
+ } catch {}
933
+ e._waAnimations = [];
934
+ }
935
+ }
936
+ async function bt(e) {
937
+ e.started = !0, e.dispatchAnimationEvent("animationstart"), e.fillForwards(), e.iteration = 0, e.done = !0, e.dispatchAnimationEvent("animationend"), Z(e);
938
+ }
939
+ function xt(e) {
940
+ X(e), e.fillForwards(), e.iteration = 0, e.done = !0, e.dispatchAnimationEvent("animationend"), Z(e), Y(e);
941
+ }
942
+ async function St(e) {
943
+ if (e.managed) throw Error("Animation.play() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play() instead.");
944
+ if (e.assertNoUnresolvedNamedSelector(), e._playingPromise) return e._playingPromise;
945
+ let t = r(e.options.respectReducedMotion, () => (e.waapiIneligibleReason = void 0, bt(e)), () => {
946
+ if (e.options.useWAAPI) {
947
+ let t = te(e);
948
+ return t.eligible ? (e.waapiIneligibleReason = void 0, yt(e)) : (e.waapiIneligibleReason = t.reason, vt(e));
949
+ }
950
+ return e.waapiIneligibleReason = void 0, vt(e);
951
+ });
952
+ return e._playingPromise = t, t.finally(() => {
953
+ e._playingPromise = null;
954
+ }), t;
955
+ }
956
+ function Ct(e) {
957
+ e.started && (e.paused = !0);
958
+ }
959
+ function wt(e) {
960
+ if (e.started && e.paused) if (e.paused = !1, e._waAnimations.length > 0) for (let t of e._waAnimations) t.play();
961
+ else e.playback.running || e.playback.loop(e._boundFrame);
962
+ }
963
+ function Tt(e) {
964
+ X(e), e.playback.stop(), Z(e), Y(e);
965
+ }
966
+ function Et(e) {
967
+ return !(!e.started || e.paused);
968
+ }
969
+ function Dt(e) {
970
+ return e.reversed ? e.options.duration - e.t : e.t;
971
+ }
972
+ function Z(e) {
973
+ e.done = !1, e.started = !1, e.paused = !1, e.reversed = !1, e.iteration = 0, e.startTime = void 0, e.pausedTime = 0, e.t = 0;
974
+ }
975
+ function Ot(e) {
976
+ X(e), e.started && e.frames.length > 0 && e.fillBackwards(), Z(e);
977
+ }
978
+ //#endregion
979
+ //#region src/animation/engine.ts
980
+ var kt = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function", Q = (e) => typeof e == "string" ? e : e.name ?? String(e.id), At = 0, $ = class {
981
+ id = At++;
982
+ name;
983
+ superKey;
984
+ targets;
985
+ options;
986
+ _compiler;
987
+ get compiler() {
988
+ return this._compiler;
989
+ }
990
+ playback = new a();
991
+ _waAnimations = [];
992
+ startTime = void 0;
993
+ pausedTime = 0;
994
+ t = 0;
995
+ iteration = 0;
996
+ diagnostics = [];
997
+ _compositionBase = /* @__PURE__ */ new Map();
998
+ _compositionFallbackSeen = /* @__PURE__ */ new Set();
999
+ _hasComposition = !1;
1000
+ started = !1;
1001
+ done = !1;
1002
+ reversed = !1;
1003
+ paused = !1;
1004
+ managed = !1;
1005
+ waapiIneligibleReason = void 0;
1006
+ unflatten = !0;
1007
+ resolvePromise = null;
1008
+ _playingPromise = null;
1009
+ _boundFrame = this._frame.bind(this);
1010
+ _interpOut = {};
1011
+ _stableKeys = [];
1012
+ _ctorOptions = {};
1013
+ get flatKeys() {
1014
+ return this._stableKeys;
1015
+ }
1016
+ _defaultTransform = (e) => c(e, this.targets);
1017
+ usesDefaultRenderer(e) {
1018
+ return e === this._defaultTransform;
1019
+ }
1020
+ dispatchAnimationEvent(e) {
1021
+ if (!(typeof AnimationEvent > "u")) for (let t of this.targets) typeof t?.dispatchEvent == "function" && t.dispatchEvent(new AnimationEvent(e, {
1022
+ animationName: this.name ?? "",
1023
+ elapsedTime: this.t / 1e3
1024
+ }));
1025
+ }
1026
+ constructor(e, t, n, r) {
1027
+ this.options = {}, this._compiler = new tt(this.options), this._ctorOptions = e ?? {}, this.setOptions({
1028
+ ...P,
1029
+ ...this._ctorOptions
1030
+ }), this.targets = t == null ? [] : Array.isArray(t) ? t : [t], this.name = n, this.superKey = r;
1031
+ }
1032
+ get templateFrames() {
1033
+ return this.compiler.templateFrames;
1034
+ }
1035
+ set templateFrames(e) {
1036
+ this.compiler.templateFrames = e;
1037
+ }
1038
+ get parsedVars() {
1039
+ return this.compiler.parsedVars;
1040
+ }
1041
+ get frames() {
1042
+ return this.compiler.frames;
1043
+ }
1044
+ get frameId() {
1045
+ return this.compiler.frameId;
1046
+ }
1047
+ addFrame(e, t, n, r, i) {
1048
+ return this.compiler.addFrame(e, t, n, r, i), this;
1049
+ }
1050
+ parse() {
1051
+ return this.compiler.parse(this.targets), this.computeStableKeys(), this.computeHasComposition(), this;
1052
+ }
1053
+ computeHasComposition() {
1054
+ this._hasComposition = Be(this.frames), Ve(this._compositionBase, this._compositionFallbackSeen);
1055
+ }
1056
+ adoptCompiled(e) {
1057
+ return this._compiler = e.compiler, this.options = this.compiler.options, this.unflatten = e.unflatten, this.computeStableKeys(), this.computeHasComposition(), this;
1058
+ }
1059
+ computeStableKeys() {
1060
+ let e = /* @__PURE__ */ new Set();
1061
+ for (let t of this.frames) for (let n in t.flatVars) e.add(n);
1062
+ this._stableKeys = [...e];
1063
+ }
1064
+ setTimingFunction(e) {
1065
+ return this.options.timingFunction = nt(e), this;
1066
+ }
1067
+ setIterationCount(e) {
1068
+ return this.options.iterationCount = rt(e), this;
1069
+ }
1070
+ setDuration(e) {
1071
+ let t = it(e);
1072
+ if (t === void 0) return this;
1073
+ let n = t / this.options.duration;
1074
+ for (let e = 0; e < this.frames.length; e++) {
1075
+ let t = this.frames[e];
1076
+ t.time.start *= n, t.time.stop *= n;
1077
+ }
1078
+ return this.options.duration = t, this;
1079
+ }
1080
+ setDelay(e) {
1081
+ return this.options.delay = at(e), this;
1082
+ }
1083
+ setDirection(e) {
1084
+ return this.options.direction = ot(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;
1085
+ }
1086
+ setFillMode(e) {
1087
+ return this.options.fillMode = st(e), this;
1088
+ }
1089
+ setUseWAAPI(e) {
1090
+ return this.options.useWAAPI = q("useWAAPI", e), this;
1091
+ }
1092
+ setRespectReducedMotion(e) {
1093
+ return this.options.respectReducedMotion = q("respectReducedMotion", e), this;
1094
+ }
1095
+ setColorSpace(e) {
1096
+ return this.options.colorSpace = ct(e), this.frames.length > 0 && this.compiler.renormalizeColors(), this;
1097
+ }
1098
+ setHueMethod(e) {
1099
+ let t = lt(e);
1100
+ return t === void 0 ? this : (this.options.hueMethod = t, this.frames.length > 0 && this.compiler.renormalizeColors(), this);
1101
+ }
1102
+ setComposite(e) {
1103
+ return e === void 0 || (this.options.composite = e), this;
1104
+ }
1105
+ setOptions(e) {
1106
+ return this.setTimingFunction(e.timingFunction), this.setDuration(e.duration), this.setIterationCount(e.iterationCount), this.setDelay(e.delay), this.setDirection(e.direction), this.setFillMode(e.fillMode), this.setUseWAAPI(e.useWAAPI), this.setRespectReducedMotion(e.respectReducedMotion), this.setColorSpace(e.colorSpace), this.setHueMethod(e.hueMethod), this.setComposite(e.composite), this;
1107
+ }
1108
+ reverse() {
1109
+ if (this.startTime !== void 0) {
1110
+ let e = this.t, t = this.options.duration - 2 * e;
1111
+ this.startTime -= t;
1112
+ }
1113
+ return this.reversed = !this.reversed, this;
1114
+ }
1115
+ fillForwards() {
1116
+ this.interpFrames(this.options.duration, !0);
1117
+ }
1118
+ fillBackwards() {
1119
+ this.interpFrames(0, !0);
1120
+ }
1121
+ get restPosition() {
1122
+ return this.options.fillMode === "forwards" || this.options.fillMode === "both" ? "final" : "initial";
1123
+ }
1124
+ paintRest() {
1125
+ this.restPosition === "final" ? this.fillForwards() : this.fillBackwards();
1126
+ }
1127
+ assertNoUnresolvedNamedSelector() {
1128
+ let e = this.compiler.templateFrames.find((e) => e.start.superType?.includes(W));
1129
+ if (e != null) {
1130
+ let n = String(e.start.value);
1131
+ throw new t("start", n, `named scroll-range selector ("${n}") requires a ScrollTimeline or ManualTimeline — call bindTimeline(timeline) before play() to resolve the named phase to a numeric position`, "NAMED_SELECTOR_NO_TIMELINE");
1132
+ }
1133
+ }
1134
+ at(e, t = !1) {
1135
+ this.assertNoUnresolvedNamedSelector();
1136
+ let n = this.reversed;
1137
+ this.reversed = !1;
1138
+ let r = ie(e, 0, 1) * this.options.duration, i = this.interpFrames(r, t);
1139
+ return this.reversed = n, i;
1140
+ }
1141
+ interpFrames(e, t = !1, n) {
1142
+ e = this.reversed ? this.options.duration - e : e;
1143
+ let r = this.frames, i = r.length, a = o(r, e, (e) => e.time.start, (e) => e.time.stop);
1144
+ if (a === -1) return n === void 0 ? {} : (this.clearBuffer(n), n);
1145
+ let s = a, c = a;
1146
+ for (let t = a - 1; t >= 0; t--) {
1147
+ let n = r[t];
1148
+ if (e < n.time.start || e > n.time.stop) break;
1149
+ s = t;
1150
+ }
1151
+ for (let t = a + 1; t < i; t++) {
1152
+ let n = r[t];
1153
+ if (e < n.time.start || e > n.time.stop) break;
1154
+ c = t;
1155
+ }
1156
+ for (let n = s; n <= c; n++) this.processFrame(r[n], e, t);
1157
+ if (s === c) {
1158
+ let e = r[a].flatVars;
1159
+ return n === void 0 ? e : (this.clearBuffer(n), Object.assign(n, e), n);
1160
+ }
1161
+ let l = n ?? {};
1162
+ n !== void 0 && this.clearBuffer(n);
1163
+ for (let e = s; e <= c; e++) Object.assign(l, r[e].flatVars);
1164
+ return l;
1165
+ }
1166
+ clearBuffer(e) {
1167
+ let t = this._stableKeys;
1168
+ for (let n = 0; n < t.length; n++) e[t[n]] = void 0;
1169
+ }
1170
+ processFrame(e, t, n) {
1171
+ let { start: r, stop: i } = e.time, a = r === i ? 1 : ve(t, r, i, 0, 1), o = e.timingFunction.fn(a), s = e._numericPlan;
1172
+ if (s !== void 0 && s.numeric.length > 0) {
1173
+ let { numeric: e, from: t, to: n, out: r } = s;
1174
+ me(t, n, o, r);
1175
+ for (let t = 0; t < e.length; t++) e[t].value.value = r[t];
1176
+ for (let e of s.boxed) he(o, e);
1177
+ } else for (let t of e.allInterpVars) he(o, t);
1178
+ n && this._hasComposition && e.composition != null && this.applyComposition(e), n && e.transform(this.unflatten ? e.vars : e.flatVars, t);
1179
+ }
1180
+ applyComposition(e) {
1181
+ He(e, {
1182
+ iteration: this.iteration,
1183
+ target: this.targets[0],
1184
+ compositionBase: this._compositionBase,
1185
+ compositionFallbackSeen: this._compositionFallbackSeen,
1186
+ diagnostics: this.diagnostics
1187
+ });
1188
+ }
1189
+ onStart() {
1190
+ return J(this._host);
1191
+ }
1192
+ onEnd() {
1193
+ pt(this._host);
1194
+ }
1195
+ advanceTo(e) {
1196
+ return mt(this._host, e);
1197
+ }
1198
+ get _host() {
1199
+ return this;
1200
+ }
1201
+ _frame(e) {
1202
+ return gt(this._host, e);
1203
+ }
1204
+ get finished() {
1205
+ return this._playingPromise ?? Promise.resolve();
1206
+ }
1207
+ async play() {
1208
+ return St(this._host);
1209
+ }
1210
+ pause() {
1211
+ return Ct(this._host), this;
1212
+ }
1213
+ resume() {
1214
+ return wt(this._host), this;
1215
+ }
1216
+ toggle() {
1217
+ return this.paused ? this.resume() : this.pause();
1218
+ }
1219
+ stop() {
1220
+ Tt(this._host);
1221
+ }
1222
+ playing() {
1223
+ return Et(this._host);
1224
+ }
1225
+ get effectiveT() {
1226
+ return Dt(this._host);
1227
+ }
1228
+ settle() {
1229
+ return Z(this._host), this;
1230
+ }
1231
+ reset() {
1232
+ return Ot(this._host), this;
1233
+ }
1234
+ setTargets(...e) {
1235
+ return this.targets = e, this._resolveElementAwareValues() || this.frames.forEach((e) => {
1236
+ Object.values(e.interpVars).forEach((e) => {
1237
+ e.forEach(({ start: e, stop: t, value: n }) => {
1238
+ e.setTargets(this.targets), t.setTargets(this.targets), n.setTargets(this.targets);
1239
+ });
1240
+ });
1241
+ }), this;
1242
+ }
1243
+ _resolveElementAwareValues() {
1244
+ let e = this.compiler.templateFrames, t = !1;
1245
+ for (let n of e) {
1246
+ let e = n.vars;
1247
+ for (let n in e) if (E(e[n])) {
1248
+ t = !0;
1249
+ break;
1250
+ }
1251
+ if (t) break;
1252
+ }
1253
+ if (!t) return !1;
1254
+ let n = this._buildElementAwareEnv();
1255
+ if (n === void 0) return !1;
1256
+ let r = v(/* @__PURE__ */ new Map(), n), i = !1;
1257
+ for (let t of e) {
1258
+ let e = t.vars;
1259
+ for (let t in e) {
1260
+ let n = e[t];
1261
+ if (!(n instanceof p) || !E(n)) continue;
1262
+ let a = w(n, r);
1263
+ if (a === y) {
1264
+ delete e[t], i = !0;
1265
+ continue;
1266
+ }
1267
+ a !== n && (e[t] = a, i = !0);
1268
+ }
1269
+ }
1270
+ return i ? (this.parse(), !0) : !1;
1271
+ }
1272
+ _buildElementAwareEnv() {
1273
+ let e = this.targets[0];
1274
+ if (e == null) return;
1275
+ let t = { customProps: (t) => {
1276
+ let n = "";
1277
+ if (typeof getComputedStyle == "function") try {
1278
+ n = getComputedStyle(e).getPropertyValue(t).trim();
1279
+ } catch {
1280
+ n = "";
1281
+ }
1282
+ return n === "" && (n = e.style.getPropertyValue(t).trim()), n === "" ? void 0 : n;
1283
+ } }, n = e.parentElement;
1284
+ return n != null && (t.siblingIndex = () => Array.prototype.indexOf.call(n.children, e) + 1, t.siblingCount = () => n.children.length), t;
1285
+ }
1286
+ group(...e) {
1287
+ return new H(this, ...e);
1288
+ }
1289
+ }, jt = class extends $ {
1290
+ _boundTimeline;
1291
+ constructor(e, ...t) {
1292
+ super(e, t), this.unflatten = !1;
1293
+ }
1294
+ bindTimeline(e) {
1295
+ this._boundTimeline = e;
1296
+ let t = !1;
1297
+ for (let e of this.compiler.templateFrames) e.start.superType?.includes("named-selector") && (e.start = new m(et(String(e.start.value)) * 100, "%"), t = !0);
1298
+ return t && this.compiler.frames.length > 0 && this.parse(), this;
1299
+ }
1300
+ resolveTransform(e) {
1301
+ return this.unflatten = e != null, e ?? this._defaultTransform;
1302
+ }
1303
+ fromVars(e, t) {
1304
+ t = this.resolveTransform(t);
1305
+ for (let n = 0; n < e.length; n++) {
1306
+ let r = e[n], i = Math.round(n / (e.length - 1) * 100);
1307
+ this.addFrame(i, r, t);
1308
+ }
1309
+ return this.parse(), this;
1310
+ }
1311
+ fromKeyframes(e, t) {
1312
+ t = this.resolveTransform(t), fe(e) && (e = new Map(Object.entries(e)));
1313
+ let n = e instanceof Map ? e.entries() : Object.entries(e);
1314
+ for (let [e, r] of n) this.addFrame(e, r, t);
1315
+ return this.parse(), this;
1316
+ }
1317
+ propertyRegistry = /* @__PURE__ */ new Map();
1318
+ scrollOptions;
1319
+ fromString(e, t) {
1320
+ t = this.resolveTransform(t);
1321
+ let n = O(e);
1322
+ this.propertyRegistry = n.properties;
1323
+ let r = dt(n.stylesheet);
1324
+ r === void 0 ? delete this.scrollOptions : this.scrollOptions = r, this.diagnostics = [...n.diagnostics];
1325
+ let a = ut(n.options);
1326
+ Object.keys(a).length > 0 && this.setOptions({
1327
+ ...a,
1328
+ ...this._ctorOptions
1329
+ });
1330
+ for (let [e, r] of n.keyframes.entries()) {
1331
+ let a = Object.fromEntries(Object.entries(r).map(([e, t]) => [e, kt(t) ? t.clone() : t])), o = n.timingFunctions.get(e), s = o ? d(o) : void 0, c;
1332
+ if (s) {
1333
+ let e = o ? i(o) : void 0;
1334
+ c = e ? {
1335
+ fn: s,
1336
+ css: e
1337
+ } : { fn: s };
1338
+ }
1339
+ let l = n.composition.get(e);
1340
+ this.addFrame(e, a, t, c, l);
1341
+ }
1342
+ return this.parse(), ft(this.propertyRegistry), this;
1343
+ }
1344
+ transform(e) {
1345
+ c(e, this.targets);
1346
+ }
1347
+ };
1348
+ //#endregion
1349
+ export { H as AnimationGroup, jt as CSSKeyframesAnimation, k as DIRECTIONS, A as FILL_MODES, $ as KeyframesAnimation, F as defaultLayerConfig, P as defaultOptions, Q as getAnimationId, d as getTimingFunction, O as resolveKeyframes };