@mkbabb/keyframes.js 1.2.1 → 2.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.
package/dist/keyframes.js CHANGED
@@ -1,1539 +1,510 @@
1
- import { CSSFunction as tt, ValueUnit as f, CSSValueUnit as A, identifier as j, hyphenToCamelCase as yt, ValueArray as T, number as wt, camelCaseToHyphen as Vt, memoize as V, tryParse as F, FunctionValue as U, easeInOutCubic as et, lerp as I, requestAnimationFrame as w, cancelAnimationFrame as k, parseCSSValueUnit as st, unpackMatrixValues as Tt, normalizeColorUnits as bt, COMPUTED_UNITS as $, convertToDPI as St, convertToMs as it, convertToDegrees as vt, convertToPixels as Ft, RESOLUTION_UNITS as It, TIME_UNITS as Pt, ANGLE_UNITS as Et, LENGTH_UNITS as Ct, timingFunctions as rt, flattenObject as nt, unflattenObjectToString as ot, clamp as E, scale as at, seekPreviousValue as B, unflattenObject as Ot, sleep as _t, isObject as kt } from "@mkbabb/value.js";
2
- import { CSSCubicBezier as Ye, bezierPresets as Be, bounceInEase as Re, bounceInEaseHalf as We, bounceInOutEase as Le, bounceOutEase as Xe, bounceOutEaseHalf as He, cancelAnimationFrame as Ge, clamp as qe, cubicBezier as Ze, cubicBezierToSVG as Qe, cubicBezierToString as Je, deCasteljau as ts, easeInBounce as es, easeInCirc as ss, easeInCubic as is, easeInExpo as rs, easeInOutCirc as ns, easeInOutCubic as os, easeInOutExpo as as, easeInOutQuad as us, easeInOutSine as ls, easeInQuad as cs, easeInSine as hs, easeOutCirc as fs, easeOutCubic as ps, easeOutExpo as ms, easeOutQuad as ds, easeOutSine as gs, interpBezier as ys, jumpTerms as ws, lerp as Vs, linear as Ts, logerp as bs, requestAnimationFrame as Ss, scale as vs, sleep as Fs, smoothStep3 as Is, stepEnd as Ps, stepStart as Es, steppedEase as Cs, timingFunctions as Os } from "@mkbabb/value.js";
3
- import { string as g, all as D, regex as ut, any as C, whitespace as Mt } from "@mkbabb/parse-that";
4
- function lt(s, t, e, i) {
5
- let r = 0, o = s.length - 1;
6
- for (; r <= o; ) {
7
- const n = r + o >> 1, u = s[n];
8
- if (t < e(u)) o = n - 1;
9
- else if (t > i(u)) r = n + 1;
10
- else return n;
11
- }
12
- return -1;
13
- }
14
- const At = (s) => s.replace(/\/\*[\s\S]*?\*\//g, ""), xt = (s) => s.replace(/\s*!important/gi, ""), N = (s) => xt(At(s));
15
- g("(");
16
- g(")");
17
- const jt = g(";"), Ut = g(":"), K = g("{"), z = g("}"), $t = g(","), Dt = g("."), d = Mt, Nt = (s) => {
18
- const t = [];
19
- for (const e of s.flat(1 / 0)) {
20
- if (e instanceof f || e instanceof U) {
21
- t.push(e);
22
- continue;
23
- }
24
- throw new TypeError(
25
- `Expected parsed CSS value node, got ${typeof e}.`
26
- );
27
- }
28
- return t;
29
- }, Kt = tt.Function, zt = D(K, ut(/[^{}]+/), z).map(
30
- (s) => {
31
- const t = s.join(`
32
- `), e = JSON.parse(t);
33
- return new f(e, "json");
34
- }
35
- ), Y = C(
36
- A.Value,
37
- Kt,
38
- zt,
39
- ut(/[^\(\)\{\}\s,;]+/).map((s) => new f(s))
40
- ).trim(d), Yt = Y.sepBy(d), Bt = D(
41
- j.skip(Ut).trim(d).map((s) => yt(s)),
42
- Yt.skip(jt.opt()).trim(d)
43
- ).map((s) => {
44
- const [t, e] = s, i = new T(...Nt(e));
45
- return i.setProperty(t), {
46
- [t]: i
47
- };
48
- }), Rt = C(
49
- A.TimePercentage.trim(d).map((s) => s.toString()),
50
- wt.map((s) => `${s}%`)
51
- ), Wt = Rt.sepBy($t).trim(d), ct = Bt.many().trim(d).wrap(K, z).map((s) => Object.assign({}, ...s)), Lt = g("@keyframes").trim(d).next(j), R = D(Wt, ct).map(
52
- ([s, t]) => s.reduce((e, i) => (e.set(i, t), e), /* @__PURE__ */ new Map())
53
- ), ht = C(
54
- Lt.next(R.many(1).trim(d).wrap(K, z).trim(d)),
55
- R.many(1).trim(d)
56
- ).map((s) => s.reduce(
57
- (t, e) => {
58
- for (const [i, r] of e)
59
- t.has(i) ? t.set(i, { ...t.get(i), ...r }) : t.set(i, r);
60
- return t;
61
- },
62
- /* @__PURE__ */ new Map()
63
- )), Xt = Dt.trim(d).next(j).trim(d), Ht = ct.map((s) => {
64
- const t = {};
65
- for (const [e, i] of Object.entries(s))
66
- if (e.includes("animation")) {
67
- const r = e.replace(/^animation/i, "").replace(/^\w/, (n) => n.toLowerCase()), o = Vt(i.toString());
68
- t[r] = o, delete s[e];
69
- }
70
- return {
71
- options: t,
72
- values: s
73
- };
74
- }), Gt = Xt.next(Ht), qt = C(
75
- Gt.map((s) => s),
76
- ht.map((s) => ({
77
- keyframes: s
78
- }))
79
- ), Zt = qt.sepBy(d).map((s) => Object.assign({}, ...s)), W = {
80
- Value: Y,
81
- FunctionArgs: tt.FunctionArgs
82
- }, Qt = V(
83
- (s) => F(Y, N(s))
84
- ), Jt = V(
85
- (s) => F(ht, N(s))
86
- );
87
- V((s) => {
88
- const t = F(
89
- Zt,
90
- N(s)
91
- ), e = {
92
- keyframes: t.keyframes
93
- };
94
- return t.options != null && (e.options = t.options), t.values != null && (e.values = t.values), e;
95
- });
96
- V(
97
- (s) => F(A.Percentage, String(s)).valueOf()
98
- );
99
- const L = V((s) => F(
100
- A.Time.map((t) => t.unit === "ms" ? t.value : t.unit === "s" ? t.value * 1e3 : t.value),
101
- s
102
- ));
103
- V((s) => s >= 5e3 ? `${s / 1e3}s` : `${s}ms`);
104
- V((s) => s === 1 / 0 ? "infinite" : String(s));
105
- const te = {
106
- duration: 1e3,
107
- delay: 0,
108
- iterationCount: 1,
109
- direction: "normal",
110
- fillMode: "forwards",
111
- timingFunction: et,
112
- useWAAPI: !0,
113
- colorSpace: "oklab"
114
- }, ee = {
115
- zIndex: 0,
116
- weight: 1,
117
- blendMode: "replace",
118
- enabled: !0
119
- }, _ = (s) => typeof s != "object" || s == null ? !1 : "value" in s && typeof s.value == "number";
120
- class se {
121
- animations = {};
122
- transform;
123
- superKey;
124
- paused = !1;
125
- started = !1;
126
- done = !1;
127
- singleTarget = !0;
128
- lastTickTime = 0;
129
- handleId = void 0;
130
- resolvePromise = null;
131
- /**
132
- * Pre-bound draw callback — allocated once in constructor to avoid
133
- * creating a new closure on every requestAnimationFrame reschedule.
134
- */
135
- _boundDraw;
136
- /**
137
- * Cached entries array, sorted by layer zIndex. Rebuilt on demand
138
- * via dirty flag to avoid Object.values() allocation on every frame.
139
- */
140
- _entries = [];
141
- _entriesDirty = !0;
142
- constructor(...t) {
143
- this._boundDraw = this.draw.bind(this);
144
- const e = [];
145
- for (const i of t) {
146
- let r, o;
147
- i instanceof gt ? r = i : (r = i.animation, o = i.layer), this.transform ??= r.frames[0].transform;
148
- const n = x(r);
149
- this.animations[n] = {
150
- values: {},
151
- animation: r,
152
- layer: { ...ee, ...o }
153
- }, r.managed = !0, e.push(r);
154
- }
155
- this.singleTarget = e.every(
156
- (i) => i.targets[0] === e[0]?.targets[0]
157
- ), this.invalidateEntries();
158
- }
159
- // ── Entry cache ──────────────────────────────────────────────────
160
- /**
161
- * Returns the animation entries sorted by layer zIndex.
162
- * Uses dirty-flag caching — only rebuilds when the animations object
163
- * or layer configs are mutated. All hot-path iteration (tick, draw,
164
- * transformFramesGrouped) uses this instead of Object.values().
165
- */
166
- getEntries() {
167
- return this._entriesDirty && (this._entries = Object.values(this.animations), this._entries.sort((t, e) => t.layer.zIndex - e.layer.zIndex), this._entriesDirty = !1), this._entries;
168
- }
169
- /** Mark entries cache stale. Called at all mutation boundaries. */
170
- invalidateEntries() {
171
- this._entriesDirty = !0;
172
- }
173
- // ── Setup ────────────────────────────────────────────────────────
174
- setSuperKey(t) {
175
- this.superKey = t;
176
- for (const e of this.getEntries())
177
- e.animation.superKey = t;
178
- return this;
179
- }
180
- setTargets(...t) {
181
- const e = this.getEntries();
182
- for (const i of e)
183
- i.animation.setTargets(...t);
184
- return this.singleTarget = e.every(
185
- (i) => i.animation.targets[0] === e[0]?.animation.targets[0]
186
- ), this;
187
- }
188
- // ── Lifecycle hooks ──────────────────────────────────────────────
189
- onStart() {
190
- return this.started = !0, this;
191
- }
192
- onEnd() {
193
- return this;
194
- }
195
- // ── Frame rendering ──────────────────────────────────────────────
196
- /**
197
- * Composite all animation values into a single grouped transform.
198
- * Called per-frame for single-target groups. Applies layer blending
199
- * (replace / add / weighted) in zIndex order, then calls the group
200
- * transform function with the merged values.
201
- */
202
- transformFramesGrouped(t) {
203
- const e = {}, i = this.getEntries();
204
- let r = !0;
205
- for (const o of i) {
206
- const { animation: n, values: u, layer: a } = o;
207
- if (r = r && n.done, !a.enabled) continue;
208
- if (!(n.done || n.paused)) {
209
- const l = n.interpFrames(n.t, !1);
210
- Object.assign(u, l);
211
- }
212
- const c = a.properties ? Object.fromEntries(
213
- Object.entries(u).filter(
214
- ([l]) => a.properties.has(l)
215
- )
216
- ) : u;
217
- switch (a.blendMode) {
218
- case "replace":
219
- Object.assign(e, c);
220
- break;
221
- case "add":
222
- for (const [l, h] of Object.entries(c))
223
- if (l in e) {
224
- const m = e[l], p = h;
225
- _(m) && _(p) ? m.value = m.value + p.value : e[l] = h;
226
- } else
227
- e[l] = h;
228
- break;
229
- case "weighted":
230
- for (const [l, h] of Object.entries(c))
231
- if (l in e && a.weight < 1) {
232
- const m = e[l], p = h;
233
- _(m) && _(p) ? m.value = I(
234
- a.weight,
235
- m.value,
236
- p.value
237
- ) : e[l] = h;
238
- } else
239
- e[l] = h;
240
- break;
241
- }
242
- }
243
- return this.done = r, this.transform(e, t), e;
244
- }
245
- /**
246
- * Render the current animation state as a static frame.
247
- * Called on pause to ensure the visual matches the exact pause moment.
248
- * Handles both single-target (grouped blending) and multi-target
249
- * (per-child interpFrames) paths.
250
- */
251
- renderPauseFrame() {
252
- const t = this.getEntries(), e = this.lastTickTime || performance.now();
253
- for (const i of t) {
254
- const r = i.animation.interpFrames(i.animation.t, !1);
255
- this.singleTarget && Object.assign(i.values, r);
256
- }
257
- if (this.singleTarget)
258
- this.transformFramesGrouped(e);
259
- else
260
- for (const i of t)
261
- i.animation.interpFrames(i.animation.t, !0);
262
- }
263
- // ── Playback loop ────────────────────────────────────────────────
264
- /**
265
- * Advance all child animations to timestamp `t`.
266
- * Awaits all child tick() promises so deferred state updates
267
- * (startTime, this.t) resolve before interpFrames reads them.
268
- */
269
- async tick(t) {
270
- this.lastTickTime = t, this.started || this.onStart();
271
- const e = [];
272
- for (const i of this.getEntries()) {
273
- const r = i.animation;
274
- (!r.paused || r.pausedTime === 0) && e.push(r.tick(t));
275
- }
276
- return await Promise.all(e), this.done && this.onEnd(), this;
277
- }
278
- /**
279
- * Main animation frame callback. Ticks all children, then renders
280
- * (single-target: grouped blending; multi-target: per-child).
281
- * Reschedules itself via rAF until done.
282
- */
283
- async draw(t) {
284
- if (await this.tick(t), !this.paused) {
285
- if (this.singleTarget)
286
- this.transformFramesGrouped(t);
287
- else {
288
- let e = !0;
289
- for (const i of this.getEntries())
290
- i.animation.interpFrames(i.animation.t, !0), e = e && i.animation.done;
291
- this.done = e;
292
- }
293
- this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = w(this._boundDraw);
294
- }
295
- }
296
- /**
297
- * Start the animation group. Returns a promise that resolves
298
- * when all child animations complete (or on explicit stop/reset).
299
- */
300
- async play() {
301
- return new Promise((t) => {
302
- this.resolvePromise = t, this.handleId = w(this._boundDraw);
303
- });
304
- }
305
- /**
306
- * Toggle pause state. Calling pause() when playing pauses; calling
307
- * pause() when paused resumes. (Toggle semantics preserved for
308
- * backward compatibility with demo's toggleAnimationGroup.)
309
- *
310
- * On pause: explicitly cancels the rAF loop and renders a final
311
- * frame snapshot so the visual matches the exact pause moment.
312
- * On resume: re-registers the rAF loop.
313
- */
314
- pause() {
315
- if (!this.started) return this;
316
- this.paused = !this.paused;
317
- const t = this.lastTickTime || performance.now();
318
- for (const e of this.getEntries()) {
319
- const i = e.animation;
320
- this.paused ? (i.pause(!1), i.pausedTime === 0 && (i.pausedTime = t)) : i.paused = !1;
321
- }
322
- return this.paused ? (k(this.handleId), this.handleId = void 0, this.renderPauseFrame()) : this.handleId = w(this._boundDraw), this;
323
- }
324
- reset() {
325
- for (const t of this.getEntries()) {
326
- const e = t.animation;
327
- e.started && e.frames.length > 0 && e.interpFrames(0, !0), e.managed = !1, e.reset();
328
- }
329
- return this.started = !1, this.done = !1, this.paused = !1, this.lastTickTime = 0, this;
330
- }
331
- stop() {
332
- return k(this.handleId), this.handleId = void 0, this.reset(), this;
333
- }
334
- playing() {
335
- return !(!this.started || this.paused);
336
- }
337
- forcePause() {
338
- this.paused = !0;
339
- for (const t of this.getEntries())
340
- t.animation.paused = !0;
341
- }
342
- forcePlay() {
343
- this.paused = !1;
344
- for (const t of this.getEntries())
345
- t.animation.paused = !1;
346
- }
347
- // ── Layer management API ─────────────────────────────────────────
348
- /** Set layer config for an animation by name or reference. Chainable. */
349
- setLayerConfig(t, e) {
350
- const i = typeof t == "string" ? t : x(t), r = this.animations[i];
351
- return r && (Object.assign(r.layer, e), this.invalidateEntries()), this;
352
- }
353
- /** Convenience toggle for enabling/disabling a layer. Chainable. */
354
- setLayerEnabled(t, e) {
355
- return this.setLayerConfig(t, { enabled: e });
356
- }
357
- /** Read the layer config for an animation. */
358
- getLayerConfig(t) {
359
- const e = typeof t == "string" ? t : x(t);
360
- return this.animations[e]?.layer;
361
- }
362
- }
363
- const ie = /* @__PURE__ */ new Set([
364
- "scaleX",
365
- "scaleY",
366
- "scaleZ",
367
- "skewX",
368
- "skewY",
369
- "skewZ",
370
- "translateX",
371
- "translateY",
372
- "translateZ",
373
- "rotateX",
374
- "rotateY",
375
- "rotateZ",
376
- "perspectiveX",
377
- "perspectiveY",
378
- "perspectiveZ",
379
- "perspectiveW"
380
- ]), re = (s) => typeof s == "string" && Ct.includes(s), ne = (s) => typeof s == "string" && Et.includes(s), oe = (s) => typeof s == "string" && Pt.includes(s), ae = (s) => typeof s == "string" && It.includes(s), X = (s) => typeof s == "string" && $.includes(s), ue = (s) => ie.has(
381
- s
382
- ), le = (s, t) => {
383
- if (typeof s != "number" || !Number.isFinite(s))
384
- throw new TypeError(
385
- `Expected numeric ${t}, got ${String(s)}.`
386
- );
387
- return s;
388
- }, H = (s) => {
389
- if (s.unit !== "color")
390
- throw new TypeError("Expected a color ValueUnit.");
391
- return s;
392
- }, ce = (s) => s, G = /* @__PURE__ */ new WeakMap();
393
- let he = 0;
394
- const fe = (s) => {
395
- let t = G.get(s);
396
- return t === void 0 && (t = he++, G.set(s, t)), t;
397
- }, q = V(
398
- (s, t) => (() => {
399
- if (!t)
400
- return s;
401
- if (s.unit === "var") {
402
- const r = getComputedStyle(t).getPropertyValue(
403
- s.value
404
- );
405
- return st(r);
406
- }
407
- if (s.unit === "calc" && s.property && s.subProperty && s.value && t) {
408
- const r = ce(t.style), o = r[s.property] ?? "", n = s.subProperty ? `${s.subProperty}(${s.toString()})` : s.toString();
409
- r[s.property] = n;
410
- const u = getComputedStyle(t).getPropertyValue(
411
- s.property
412
- );
413
- r[s.property] = o;
414
- const a = Qt(u);
415
- if (a instanceof f)
416
- return a;
417
- if (a.name.startsWith("matrix")) {
418
- const c = Tt(a);
419
- if (ue(s.subProperty)) {
420
- const l = c[s.subProperty];
421
- if (l != null)
422
- return new f(l, "px", [
423
- "length",
424
- "absolute"
425
- ]);
426
- }
427
- }
428
- }
429
- return s;
430
- })().coalesce(s),
431
- {
432
- keyFn: (s, t) => `${s.toString()}-${t ? fe(t) : "null"}`,
433
- // Don't cache when the element is disconnected (e.g. inside a Teleport
434
- // defer DocumentFragment). Layout-dependent units like cqw/vh resolve
435
- // to 0 without a live DOM context.
436
- shouldCache: (s, t, e) => !e || e.isConnected
437
- }
438
- ), pe = (s, t, e = !1) => {
439
- if (s?.superType?.[0] !== t?.superType?.[0])
440
- return e ? [s, t] : [s.clone(), t.clone()];
441
- const i = (n) => {
442
- const u = n?.superType?.[0], a = le(n.value, "ValueUnit");
443
- switch (u) {
444
- case "length":
445
- if (!re(n.unit))
446
- throw new TypeError(
447
- `Unsupported length unit: ${String(n.unit)}`
448
- );
449
- return {
450
- value: Ft(
451
- a,
452
- n.unit,
453
- n.targets?.[0]
454
- ),
455
- unit: "px"
456
- };
457
- case "angle":
458
- if (!ne(n.unit))
459
- throw new TypeError(
460
- `Unsupported angle unit: ${String(n.unit)}`
461
- );
462
- return {
463
- value: vt(a, n.unit),
464
- unit: "deg"
465
- };
466
- case "time":
467
- if (!oe(n.unit))
468
- throw new TypeError(
469
- `Unsupported time unit: ${String(n.unit)}`
470
- );
471
- return {
472
- value: it(a, n.unit),
473
- unit: "ms"
474
- };
475
- case "resolution":
476
- if (!ae(n.unit))
477
- throw new TypeError(
478
- `Unsupported resolution unit: ${String(n.unit)}`
479
- );
480
- return {
481
- value: St(a, n.unit),
482
- unit: "dpi"
483
- };
484
- default:
485
- return {
486
- value: a,
487
- unit: typeof n.unit == "string" ? n.unit : ""
488
- };
489
- }
490
- }, [r, o] = [
491
- i(s),
492
- i(t)
493
- ];
494
- return e ? (s.value = r.value, s.unit = r.unit, t.value = o.value, t.unit = o.unit, [s, t]) : [
495
- new f(
496
- r.value,
497
- r.unit,
498
- s.superType,
499
- s.subProperty,
500
- s.property,
501
- s.targets
502
- ),
503
- new f(
504
- o.value,
505
- o.unit,
506
- t.superType,
507
- t.subProperty,
508
- t.property,
509
- t.targets
510
- )
511
- ];
1
+ import { a as e, i as t, n, o as r, r as i, t as a } from "./leaves-Bu89334e.js";
2
+ //#region src/animation/playback.ts
3
+ var o = class {
4
+ _rafId = null;
5
+ _startTime = void 0;
6
+ _resolve = null;
7
+ play(e, r) {
8
+ if (e <= 0) throw Error("RAFPlayback.play() requires a duration > 0.");
9
+ return this.stop(), new Promise((i) => {
10
+ this._resolve = i, this._startTime = void 0;
11
+ let a = (i) => {
12
+ this._startTime === void 0 && (this._startTime = i);
13
+ let o = n((i - this._startTime) / e, 0, 1);
14
+ r(o), o < 1 ? this._rafId = t(a) : this._cleanup();
15
+ };
16
+ this._rafId = t(a);
17
+ });
18
+ }
19
+ stop() {
20
+ this._rafId !== null && a(this._rafId), this._cleanup();
21
+ }
22
+ _cleanup() {
23
+ this._rafId = null, this._startTime = void 0;
24
+ let e = this._resolve;
25
+ this._resolve = null, e?.();
26
+ }
512
27
  };
513
- function me(s, t, e = "oklab", i) {
514
- s = s.coalesce(t), t = t.coalesce(s);
515
- const r = {
516
- start: s,
517
- stop: t,
518
- value: s.clone(),
519
- computed: !1
520
- };
521
- if (s.unit === "color" && t.unit === "color") {
522
- const [o, n] = bt(
523
- H(s),
524
- H(t),
525
- e,
526
- !1,
527
- !0,
528
- !1,
529
- i
530
- );
531
- r.start = o, r.stop = n, r.value = o.clone();
532
- }
533
- if (s.unit !== t.unit) {
534
- const [o, n] = pe(
535
- s,
536
- t,
537
- !0
538
- );
539
- r.start = o, r.stop = n, r.value = o.clone();
540
- }
541
- return r.computed = X(s.unit) || X(t.unit), r;
542
- }
543
- const v = (s) => {
544
- if (s instanceof f)
545
- return [s.clone()];
546
- if (s instanceof U)
547
- return s.values.flatMap((t) => v(t));
548
- if (s instanceof T)
549
- return s.flatMap((t) => v(t));
550
- throw new TypeError(
551
- `Expected ValueUnit/FunctionValue/ValueArray, got ${typeof s}`
552
- );
553
- }, de = (s) => {
554
- const t = s.split(".").pop(), e = s.split(".").shift();
555
- if (!t || !e)
556
- throw new Error(`Invalid flattened key: ${s}`);
557
- return { mainKey: e, childKey: t };
558
- }, P = (s, t, e) => (s.setProperty(t), e !== t && s.setSubProperty(e), s), M = (s) => {
559
- if (typeof s == "string") {
560
- const t = rt[s];
561
- return typeof t == "function" && t.length <= 1 ? t : void 0;
562
- } else if (s == null)
563
- return;
564
- return s;
565
- };
566
- function ft(s, { start: t, stop: e, value: i }) {
567
- const r = t.targets?.[0] ?? e.targets?.[0];
568
- if (!r)
569
- throw new Error(
570
- "Cannot interpolate computed values without a target element."
571
- );
572
- const o = q(t, r), n = q(e, r), u = $.includes(o.unit) ? n.unit : o.unit, a = I(s, o.value, n.value);
573
- return i.value = a, i.unit = u, i;
574
- }
575
- function pt(s, { start: t, stop: e, value: i }) {
576
- return t.value.keys().forEach((r) => {
577
- const o = t.value[r], n = e.value[r], u = o instanceof f ? o.value : o, a = n instanceof f ? n.value : n, c = I(s, u, a), l = i.value[r];
578
- l instanceof f ? l.value = c : i.value[r] = c;
579
- }), i;
28
+ //#endregion
29
+ //#region src/animation/numeric.ts
30
+ function s() {
31
+ return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
580
32
  }
581
- function ge(s, { start: t, stop: e, value: i }) {
582
- return i.value = I(s, t.value, e.value), i;
583
- }
584
- function ye(s, t) {
585
- const e = t._lerp;
586
- if (e)
587
- return e(s, t), t;
588
- const { start: i, stop: r, computed: o } = t;
589
- return typeof i.value == "number" && typeof r.value == "number" ? t.value.value = I(s, i.value, r.value) : i.unit === "color" ? pt(s, t) : o && ft(s, t), t;
590
- }
591
- const Z = /* @__PURE__ */ new Map();
592
- function we(s) {
593
- const t = nt(s), e = (r, o) => {
594
- const { childKey: n, mainKey: u } = de(r);
595
- if (o instanceof f)
596
- return P(
597
- new T(...v(o)),
598
- u,
599
- n
600
- );
601
- if (o instanceof U) {
602
- const p = o.values.flatMap(
603
- (y) => v(e(r, y))
604
- );
605
- return P(
606
- new T(...p),
607
- u,
608
- n
609
- );
610
- } else if (o instanceof T) {
611
- const p = o.flatMap(
612
- (y) => v(e(r, y))
613
- );
614
- return P(
615
- new T(...p),
616
- u,
617
- n
618
- );
619
- }
620
- const a = String(o), c = `${n}:${a}`, l = Z.get(c);
621
- if (l)
622
- return P(l.clone(), u, n);
623
- const h = F(
624
- C(
625
- W.FunctionArgs.map((p) => (p.setSubProperty(n), p)),
626
- W.Value
627
- ),
628
- a
629
- ), m = P(
630
- new T(...v(h)),
631
- u,
632
- n
633
- );
634
- return Z.set(c, m.clone()), m;
635
- };
636
- return Object.entries(t).reduce(
637
- (r, [o, n]) => (r[o] = e(o, n), r),
638
- {}
639
- );
640
- }
641
- const Ve = (s, t, e, i, r = "oklab", o) => {
642
- const n = i[t], u = i[e];
643
- if (!n || !u)
644
- throw new Error(
645
- `Invalid interpolation frame bounds (${t} -> ${e}).`
646
- );
647
- const a = n[s], c = u[s];
648
- if (!a || !c)
649
- throw new Error(`Missing variable "${s}" in interpolation bounds.`);
650
- const l = Math.max(a.length, c.length), h = (y) => {
651
- const b = y.map((S) => {
652
- if (!(S instanceof f))
653
- throw new TypeError(
654
- `Interpolation for "${s}" requires ValueUnit leaves.`
655
- );
656
- return S;
657
- });
658
- for (; b.length < l; )
659
- b.push(new f(0));
660
- return b;
661
- }, m = h(a), p = h(c);
662
- return m.map((y, b) => {
663
- const S = p[b];
664
- if (!S)
665
- throw new Error(
666
- `Missing right-hand interpolation value at index ${b}.`
667
- );
668
- if (!(y instanceof f) || !(S instanceof f))
669
- throw new TypeError(
670
- `Interpolation for "${s}" requires ValueUnit leaves.`
671
- );
672
- const O = me(y, S, r, o);
673
- return O._lerp = O.computed ? ft : O.start.unit === "color" ? pt : ge, O;
674
- });
33
+ var c = (e) => e, l = class {
34
+ keyframes;
35
+ segments;
36
+ positions;
37
+ timingFn;
38
+ result;
39
+ _duration;
40
+ _respectReducedMotion;
41
+ _pendingEasingName = null;
42
+ _easingReady = null;
43
+ _playback = new o();
44
+ constructor(e, t) {
45
+ if (e.length < 2) throw Error("NumericAnimation requires at least 2 keyframes.");
46
+ this.keyframes = e.map((e) => ({ ...e })), this._duration = t?.duration ?? 0, this._respectReducedMotion = t?.respectReducedMotion ?? !1;
47
+ let n = t?.timingFunction;
48
+ if (typeof n == "function" ? this.timingFn = n : typeof n == "string" ? (this.timingFn = c, this._pendingEasingName = n) : this.timingFn = c, t?.positions) {
49
+ if (t.positions.length !== e.length) throw Error("positions length must match keyframes length.");
50
+ this.positions = t.positions;
51
+ } else this.positions = e.map((t, n) => n / (e.length - 1) * 100);
52
+ this.result = { ...e[0] }, this.segments = this.buildSegments();
53
+ }
54
+ buildSegments() {
55
+ let e = [];
56
+ for (let t = 0; t < this.keyframes.length - 1; t++) e.push(this.buildSegment(t));
57
+ return e;
58
+ }
59
+ buildSegment(e) {
60
+ let t = this.keyframes[e], n = this.keyframes[e + 1], r = Object.keys(t);
61
+ return {
62
+ startPos: this.positions[e],
63
+ stopPos: this.positions[e + 1],
64
+ keys: r,
65
+ startVals: r.map((e) => t[e]),
66
+ stopVals: r.map((e) => n[e]),
67
+ timingFunction: this.timingFn
68
+ };
69
+ }
70
+ ready() {
71
+ if (this._pendingEasingName === null) return Promise.resolve();
72
+ if (this._easingReady) return this._easingReady;
73
+ let e = this._pendingEasingName;
74
+ return this._easingReady = import("./engine-DuAFoqZF.js").then((t) => {
75
+ let n = t.getTimingFunction(e);
76
+ n && (this.timingFn = n, this.segments = this.buildSegments()), this._pendingEasingName = null;
77
+ }), this._easingReady;
78
+ }
79
+ at(t) {
80
+ let a = n(t, 0, 1) * 100, o = r(this.segments, a, (e) => e.startPos, (e) => e.stopPos);
81
+ o === -1 && (o = this.segments.length - 1);
82
+ let s = this.segments[o], c = e(n(a, s.startPos, s.stopPos), s.startPos, s.stopPos, 0, 1), l = s.timingFunction(c);
83
+ for (let e = 0; e < s.keys.length; e++) this.result[s.keys[e]] = i(s.startVals[e], s.stopVals[e], l);
84
+ return this.result;
85
+ }
86
+ updateKeyframe(e, t) {
87
+ if (e < 0 || e >= this.keyframes.length) throw RangeError(`Keyframe index ${e} out of range [0, ${this.keyframes.length - 1}].`);
88
+ return Object.assign(this.keyframes[e], t), e > 0 && (this.segments[e - 1] = this.buildSegment(e - 1)), e < this.keyframes.length - 1 && (this.segments[e] = this.buildSegment(e)), this;
89
+ }
90
+ async play(e, t) {
91
+ await this.ready();
92
+ let n = t ?? this._duration;
93
+ if (this._respectReducedMotion && s()) {
94
+ let t = this.at(1);
95
+ e?.(t);
96
+ return;
97
+ }
98
+ await this._playback.play(n, (t) => {
99
+ let n = this.at(t);
100
+ e?.(n);
101
+ });
102
+ }
103
+ stop() {
104
+ this._playback.stop();
105
+ }
106
+ }, u = {
107
+ damping: .1,
108
+ snapThreshold: .001,
109
+ targetEpsilon: 0,
110
+ initial: 0,
111
+ clamp: !0,
112
+ respectReducedMotion: !1
675
113
  };
676
- function Te(s, t, e) {
677
- const [i, r] = [s.start, t.start];
678
- return {
679
- start: i.value * e / 100,
680
- stop: r.value * e / 100
681
- };
682
- }
683
- function mt(s, t, e = !0) {
684
- s = e ? s : nt(s);
685
- const i = ot(s);
686
- t.forEach((r) => {
687
- Object.entries(i).forEach(([o, n]) => {
688
- r.style.setProperty(o, n);
689
- });
690
- });
691
- }
692
- const be = (s) => s;
693
- class Se {
694
- keyframes;
695
- segments;
696
- positions;
697
- timingFn;
698
- result;
699
- _duration;
700
- // Playback state
701
- _rafId = null;
702
- _resolve = null;
703
- _startTime = void 0;
704
- constructor(t, e) {
705
- if (t.length < 2)
706
- throw new Error(
707
- "NumericAnimation requires at least 2 keyframes."
708
- );
709
- if (this.keyframes = t.map((i) => ({ ...i })), this._duration = e?.duration ?? 0, this.timingFn = (e?.timingFunction ? M(e.timingFunction) : void 0) ?? be, e?.positions) {
710
- if (e.positions.length !== t.length)
711
- throw new Error(
712
- "positions length must match keyframes length."
713
- );
714
- this.positions = e.positions;
715
- } else
716
- this.positions = t.map(
717
- (i, r) => r / (t.length - 1) * 100
718
- );
719
- this.result = { ...t[0] }, this.segments = this.buildSegments();
720
- }
721
- buildSegments() {
722
- const t = [];
723
- for (let e = 0; e < this.keyframes.length - 1; e++)
724
- t.push(this.buildSegment(e));
725
- return t;
726
- }
727
- buildSegment(t) {
728
- const e = this.keyframes[t], i = this.keyframes[t + 1], r = Object.keys(e);
729
- return {
730
- startPos: this.positions[t],
731
- stopPos: this.positions[t + 1],
732
- keys: r,
733
- startVals: r.map((o) => e[o]),
734
- stopVals: r.map((o) => i[o]),
735
- timingFunction: this.timingFn
736
- };
737
- }
738
- /**
739
- * Map [0, 1] progress to interpolated values. Zero allocation —
740
- * returns the same pre-allocated result object on every call.
741
- *
742
- * Uses O(log N) binary search over segments. Falls back to the
743
- * last segment if progress is past the final stop position.
744
- */
745
- at(t) {
746
- const e = E(t, 0, 1) * 100;
747
- let i = lt(
748
- this.segments,
749
- e,
750
- (u) => u.startPos,
751
- (u) => u.stopPos
752
- );
753
- i === -1 && (i = this.segments.length - 1);
754
- const r = this.segments[i], o = at(
755
- E(e, r.startPos, r.stopPos),
756
- r.startPos,
757
- r.stopPos,
758
- 0,
759
- 1
760
- ), n = r.timingFunction(o);
761
- for (let u = 0; u < r.keys.length; u++)
762
- this.result[r.keys[u]] = I(
763
- n,
764
- r.startVals[u],
765
- r.stopVals[u]
766
- );
767
- return this.result;
768
- }
769
- /** Update a keyframe's values in-place, recomputing adjacent segments. */
770
- updateKeyframe(t, e) {
771
- if (t < 0 || t >= this.keyframes.length)
772
- throw new RangeError(
773
- `Keyframe index ${t} out of range [0, ${this.keyframes.length - 1}].`
774
- );
775
- return Object.assign(this.keyframes[t], e), t > 0 && (this.segments[t - 1] = this.buildSegment(t - 1)), t < this.keyframes.length - 1 && (this.segments[t] = this.buildSegment(t)), this;
776
- }
777
- // ── Playback ─────────────────────────────────────────────────────
778
- /**
779
- * Play the animation over its duration using requestAnimationFrame.
780
- *
781
- * Calls `onFrame` each frame with the interpolated values (the same
782
- * zero-allocation object returned by `.at()`). Returns a Promise that
783
- * resolves when the animation completes or is stopped.
784
- *
785
- * @param onFrame — optional per-frame callback receiving interpolated values
786
- * @param duration — override the duration set in constructor options (ms)
787
- */
788
- play(t, e) {
789
- const i = e ?? this._duration;
790
- if (i <= 0)
791
- throw new Error(
792
- "NumericAnimation.play() requires a duration > 0. Pass it in the constructor options or as a parameter to play()."
793
- );
794
- return this.stop(), new Promise((r) => {
795
- this._resolve = r, this._startTime = void 0;
796
- const o = (n) => {
797
- this._startTime === void 0 && (this._startTime = n);
798
- const u = E((n - this._startTime) / i, 0, 1), a = this.at(u);
799
- t?.(a), u < 1 ? this._rafId = w(o) : this._cleanup();
800
- };
801
- this._rafId = w(o);
802
- });
803
- }
804
- /** Cancel a running `.play()` animation. The play promise resolves immediately. */
805
- stop() {
806
- this._rafId !== null && k(this._rafId), this._cleanup();
807
- }
808
- _cleanup() {
809
- this._rafId = null, this._startTime = void 0;
810
- const t = this._resolve;
811
- this._resolve = null, t?.();
812
- }
114
+ function d() {
115
+ return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
813
116
  }
814
- const ve = {
815
- damping: 0.1,
816
- snapThreshold: 1e-3,
817
- targetEpsilon: 0,
818
- initial: 0,
819
- clamp: !0
117
+ var f = class {
118
+ options;
119
+ targetValue;
120
+ currentValue;
121
+ isSettled;
122
+ _rafId = null;
123
+ _lastFrameT = 0;
124
+ _onFrame = void 0;
125
+ constructor(e) {
126
+ this.options = {
127
+ ...u,
128
+ ...e
129
+ }, this.targetValue = this.options.initial, this.currentValue = this.options.initial, this.isSettled = !0;
130
+ }
131
+ get target() {
132
+ return this.targetValue;
133
+ }
134
+ get current() {
135
+ return this.currentValue;
136
+ }
137
+ get settled() {
138
+ return this.isSettled;
139
+ }
140
+ setTarget(e) {
141
+ this.options.clamp && (e = Math.max(0, Math.min(1, e)));
142
+ let t = Math.abs(e - this.targetValue);
143
+ if (t > 0 && t >= this.options.targetEpsilon) {
144
+ if (this.targetValue = e, this.options.respectReducedMotion && d()) {
145
+ this.currentValue = e, this.isSettled = !0, this._onFrame?.(e);
146
+ return;
147
+ }
148
+ this.isSettled = !1, this._onFrame && this._rafId === null && this._startLoop();
149
+ }
150
+ }
151
+ tick() {
152
+ return this.isSettled ? this.currentValue : (this.currentValue += (this.targetValue - this.currentValue) * this.options.damping, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(0, Math.min(1, this.currentValue))), this.currentValue);
153
+ }
154
+ tickDt(e) {
155
+ if (this.isSettled) return this.currentValue;
156
+ let t = 1 - Math.exp(-this.options.damping * e / 16.667);
157
+ return this.currentValue += (this.targetValue - this.currentValue) * t, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(0, Math.min(1, this.currentValue))), this.currentValue;
158
+ }
159
+ snap() {
160
+ this.currentValue = this.targetValue, this.isSettled = !0, this._stopLoop();
161
+ }
162
+ reset(e) {
163
+ let t = e ?? 0;
164
+ this.targetValue = t, this.currentValue = t, this.isSettled = !0, this._stopLoop();
165
+ }
166
+ play(e) {
167
+ if (this._onFrame = e, this.options.respectReducedMotion && d()) {
168
+ this.currentValue = this.targetValue, this.isSettled = !0, e?.(this.currentValue);
169
+ return;
170
+ }
171
+ if (this.isSettled) {
172
+ e?.(this.currentValue);
173
+ return;
174
+ }
175
+ this._startLoop();
176
+ }
177
+ stop() {
178
+ this._onFrame = void 0, this._stopLoop();
179
+ }
180
+ _startLoop() {
181
+ if (this._rafId !== null) return;
182
+ this._lastFrameT = 0;
183
+ let e = (n) => {
184
+ let r = this._lastFrameT ? n - this._lastFrameT : 16.667;
185
+ this._lastFrameT = n;
186
+ let i = this.tickDt(r);
187
+ if (this._onFrame?.(i), this.isSettled) {
188
+ this._stopLoop();
189
+ return;
190
+ }
191
+ this._rafId = t(e);
192
+ };
193
+ this._rafId = t(e);
194
+ }
195
+ _stopLoop() {
196
+ this._rafId !== null && (a(this._rafId), this._rafId = null), this._lastFrameT = 0;
197
+ }
198
+ }, p = {
199
+ response: .5,
200
+ dampingFraction: .86,
201
+ initial: 0,
202
+ initialVelocity: 0,
203
+ settleThreshold: .001,
204
+ velocitySettleThreshold: .001,
205
+ respectReducedMotion: !1
820
206
  };
821
- class Fe {
822
- options;
823
- targetValue;
824
- currentValue;
825
- isSettled;
826
- constructor(t) {
827
- this.options = { ...ve, ...t }, this.targetValue = this.options.initial, this.currentValue = this.options.initial, this.isSettled = !0;
828
- }
829
- get target() {
830
- return this.targetValue;
831
- }
832
- get current() {
833
- return this.currentValue;
834
- }
835
- get settled() {
836
- return this.isSettled;
837
- }
838
- setTarget(t) {
839
- this.options.clamp && (t = Math.max(0, Math.min(1, t)));
840
- const e = Math.abs(t - this.targetValue);
841
- e > 0 && e >= this.options.targetEpsilon && (this.targetValue = t, this.isSettled = !1);
842
- }
843
- /** Advance one step using fixed damping. Returns current value. */
844
- tick() {
845
- return this.isSettled ? this.currentValue : (this.currentValue += (this.targetValue - this.currentValue) * this.options.damping, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(
846
- 0,
847
- Math.min(1, this.currentValue)
848
- )), this.currentValue);
849
- }
850
- /** Frame-rate independent tick. dt is in milliseconds. */
851
- tickDt(t) {
852
- if (this.isSettled) return this.currentValue;
853
- const e = 1 - Math.exp(-this.options.damping * t / 16.667);
854
- return this.currentValue += (this.targetValue - this.currentValue) * e, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(
855
- 0,
856
- Math.min(1, this.currentValue)
857
- )), this.currentValue;
858
- }
859
- /** Immediately set current = target. */
860
- snap() {
861
- this.currentValue = this.targetValue, this.isSettled = !0;
862
- }
863
- /** Reset to a specific value (default 0). */
864
- reset(t) {
865
- const e = t ?? 0;
866
- this.targetValue = e, this.currentValue = e, this.isSettled = !0;
867
- }
207
+ function m() {
208
+ return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
868
209
  }
869
- const Q = (s) => {
870
- if (s instanceof HTMLElement) {
871
- const t = s.getBoundingClientRect();
872
- return { x: t.x, y: t.y, width: t.width, height: t.height };
873
- }
874
- return s;
210
+ var h = class {
211
+ options;
212
+ targetValue;
213
+ currentValue;
214
+ currentVelocity;
215
+ isSettled;
216
+ elapsed;
217
+ originValue;
218
+ originVelocity;
219
+ omega;
220
+ zeta;
221
+ omegaD;
222
+ subscribers = /* @__PURE__ */ new Set();
223
+ disposed = !1;
224
+ _rafId = null;
225
+ _lastFrameT = 0;
226
+ _onFrame = void 0;
227
+ constructor(e) {
228
+ this.options = {
229
+ ...p,
230
+ ...e
231
+ }, this.targetValue = this.options.initial, this.currentValue = this.options.initial, this.currentVelocity = this.options.initialVelocity, this.isSettled = this.options.initialVelocity === 0, this.elapsed = 0, this.originValue = this.currentValue, this.originVelocity = this.currentVelocity, this.omega = 2 * Math.PI / this.options.response, this.zeta = this.options.dampingFraction, this.omegaD = this.zeta < 1 ? this.omega * Math.sqrt(1 - this.zeta * this.zeta) : 0;
232
+ }
233
+ get target() {
234
+ return this.targetValue;
235
+ }
236
+ get value() {
237
+ return this.currentValue;
238
+ }
239
+ get velocity() {
240
+ return this.currentVelocity;
241
+ }
242
+ get settled() {
243
+ return this.isSettled;
244
+ }
245
+ set target(e) {
246
+ e === this.targetValue && !this.options.initialVelocity || this.reseatTarget(e);
247
+ }
248
+ reseatTarget(e) {
249
+ if (this.targetValue = e, this.options.respectReducedMotion && m()) {
250
+ this.currentValue = e, this.currentVelocity = 0, this.isSettled = !0, this.originValue = e, this.originVelocity = 0, this.elapsed = 0, this.emit(), this._stopLoop();
251
+ return;
252
+ }
253
+ this.originValue = this.currentValue, this.originVelocity = this.currentVelocity, this.elapsed = 0, this.isSettled = !1, this._onFrame && this._rafId === null && this._startLoop();
254
+ }
255
+ tick(e) {
256
+ return this.disposed || this.isSettled || e <= 0 ? this.currentValue : (this.elapsed += e, this.evaluateAt(this.elapsed), this.checkSettled(), this.emit(), this.currentValue);
257
+ }
258
+ tickToTime(e) {
259
+ return this.disposed || this.isSettled ? this.currentValue : (this.elapsed = Math.max(0, e), this.evaluateAt(this.elapsed), this.checkSettled(), this.emit(), this.currentValue);
260
+ }
261
+ evaluateAt(e) {
262
+ let t = this.originValue - this.targetValue, n = this.originVelocity, r = this.omega, i = this.zeta, a, o;
263
+ if (i < 1) {
264
+ let s = this.omegaD, c = Math.exp(-i * r * e), l = t, u = (n + i * r * t) / s, d = Math.cos(s * e), f = Math.sin(s * e);
265
+ a = c * (l * d + u * f), o = c * ((u * s - l * i * r) * d - (l * s + u * i * r) * f);
266
+ } else if (i === 1) {
267
+ let i = Math.exp(-r * e), s = t, c = n + r * t;
268
+ a = i * (s + c * e), o = i * (c - r * (s + c * e));
269
+ } else {
270
+ let s = r * Math.sqrt(i * i - 1), c = -i * r + s, l = -i * r - s, u = (n - l * t) / (c - l), d = t - u, f = Math.exp(c * e), p = Math.exp(l * e);
271
+ a = u * f + d * p, o = u * c * f + d * l * p;
272
+ }
273
+ this.currentValue = this.targetValue + a, this.currentVelocity = o;
274
+ }
275
+ checkSettled() {
276
+ let e = Math.abs(this.currentValue - this.targetValue), t = Math.abs(this.currentVelocity);
277
+ e < this.options.settleThreshold && t < this.options.velocitySettleThreshold && (this.currentValue = this.targetValue, this.currentVelocity = 0, this.isSettled = !0);
278
+ }
279
+ snap() {
280
+ this.currentValue = this.targetValue, this.currentVelocity = 0, this.originValue = this.targetValue, this.originVelocity = 0, this.elapsed = 0, this.isSettled = !0, this.emit(), this._stopLoop();
281
+ }
282
+ reset(e, t) {
283
+ let n = e ?? 0, r = t ?? 0;
284
+ this.targetValue = n, this.currentValue = n, this.currentVelocity = r, this.originValue = n, this.originVelocity = r, this.elapsed = 0, this.isSettled = r === 0, this.emit(), this._stopLoop();
285
+ }
286
+ subscribe(e) {
287
+ return this.subscribers.add(e), () => {
288
+ this.subscribers.delete(e);
289
+ };
290
+ }
291
+ emit() {
292
+ if (this.subscribers.size !== 0) for (let e of this.subscribers) e(this.currentValue, this.currentVelocity);
293
+ }
294
+ dispose() {
295
+ this.disposed = !0, this._stopLoop(), this.subscribers.clear();
296
+ }
297
+ play(e) {
298
+ if (!this.disposed) {
299
+ if (this._onFrame = e, this.options.respectReducedMotion && m()) {
300
+ this.currentValue = this.targetValue, this.currentVelocity = 0, this.isSettled = !0, e?.(this.currentValue, this.currentVelocity);
301
+ return;
302
+ }
303
+ if (this.isSettled) {
304
+ e?.(this.currentValue, this.currentVelocity);
305
+ return;
306
+ }
307
+ this._startLoop();
308
+ }
309
+ }
310
+ stop() {
311
+ this._onFrame = void 0, this._stopLoop();
312
+ }
313
+ _startLoop() {
314
+ if (this._rafId !== null) return;
315
+ this._lastFrameT = 0;
316
+ let e = (n) => {
317
+ let r = this._lastFrameT ? n - this._lastFrameT : 16.667;
318
+ if (this._lastFrameT = n, this.tick(r / 1e3), this._onFrame?.(this.currentValue, this.currentVelocity), this.isSettled) {
319
+ this._stopLoop();
320
+ return;
321
+ }
322
+ this._rafId = t(e);
323
+ };
324
+ this._rafId = t(e);
325
+ }
326
+ _stopLoop() {
327
+ this._rafId !== null && (a(this._rafId), this._rafId = null), this._lastFrameT = 0;
328
+ }
875
329
  };
876
- class Ue {
877
- animation;
878
- transformOrigin;
879
- timingFunction;
880
- duration;
881
- constructor(t, e, i) {
882
- this.transformOrigin = i?.transformOrigin ?? "top left", this.timingFunction = i?.timingFunction, this.duration = i?.duration ?? 0, this.measure(t, e);
883
- }
884
- /** Re-measure source and destination, rebuilding the internal animation. */
885
- measure(t, e) {
886
- const i = Q(t), r = Q(e), o = r.x - i.x, n = r.y - i.y, u = i.width === 0 ? 1 : r.width / i.width, a = i.height === 0 ? 1 : r.height / i.height;
887
- return this.animation = new Se(
888
- [
889
- { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1 },
890
- { translateX: o, translateY: n, scaleX: u, scaleY: a }
891
- ],
892
- { timingFunction: this.timingFunction, duration: this.duration }
893
- ), this;
894
- }
895
- /** Get raw transform values at the given progress [0, 1]. */
896
- at(t) {
897
- return this.animation.at(t);
898
- }
899
- /** Get a CSS transform string at the given progress [0, 1]. */
900
- toCSSTransform(t) {
901
- const { translateX: e, translateY: i, scaleX: r, scaleY: o } = this.animation.at(t);
902
- return `translate(${e}px, ${i}px) scale(${r}, ${o})`;
903
- }
904
- /** Apply the morph transform to an element at the given progress [0, 1]. */
905
- apply(t, e) {
906
- t.style.transform = this.toCSSTransform(e), t.style.transformOrigin = this.transformOrigin;
907
- }
908
- /**
909
- * Animate an element from source to destination over the configured duration.
910
- *
911
- * @param element — the element to apply transforms to
912
- * @param duration — override the duration set in constructor options (ms)
913
- */
914
- play(t, e) {
915
- return this.animation.play((i) => {
916
- const { translateX: r, translateY: o, scaleX: n, scaleY: u } = i;
917
- t.style.transform = `translate(${r}px, ${o}px) scale(${n}, ${u})`, t.style.transformOrigin = this.transformOrigin;
918
- }, e ?? this.duration);
919
- }
920
- /** Cancel a running `.play()` animation. */
921
- stop() {
922
- this.animation.stop();
923
- }
330
+ //#endregion
331
+ //#region src/animation/springLinearStops.ts
332
+ function g(e) {
333
+ let t = e.sampleCount ?? 24, n = e.settleThreshold ?? .001, r = e.maxDuration ?? e.response * 4, i = new h({
334
+ response: e.response,
335
+ dampingFraction: e.dampingFraction,
336
+ initial: 0,
337
+ settleThreshold: n,
338
+ velocitySettleThreshold: n
339
+ });
340
+ i.target = 1;
341
+ let a = ["0"], o = r / (t + 1);
342
+ for (let e = 1; e <= t; e++) {
343
+ i.tick(o);
344
+ let n = e / (t + 1) * 100, r = i.settled ? 1 : i.value;
345
+ a.push(`${r.toFixed(5)} ${n.toFixed(3)}%`);
346
+ }
347
+ return a.push("1"), i.dispose(), `linear(${a.join(", ")})`;
924
348
  }
925
- const Ie = (s) => {
926
- if (s == null) return null;
927
- if (typeof s == "function") return s;
928
- const t = rt[s];
929
- return typeof t == "function" && t.length <= 1 ? t : null;
930
- }, Pe = (s) => Math.max(0, Math.min(1, s));
931
- class dt {
932
- smoother;
933
- easingFn;
934
- currentProgress = 0;
935
- boundaryEpsilon;
936
- constructor(t) {
937
- this.easingFn = Ie(t?.easing), this.boundaryEpsilon = t?.boundaryEpsilon ?? 5e-3, t?.smoothing === !1 ? this.smoother = null : this.smoother = new Fe(
938
- t?.smoothing
939
- );
940
- }
941
- /**
942
- * Shared progress pipeline: sample → clamp → easing → boundary snap.
943
- * Returns the processed raw value. Does NOT advance the smoother —
944
- * the caller (tick or tickDt) drives the smoother with the appropriate
945
- * time-step method.
946
- */
947
- applyPipeline() {
948
- let t = Pe(this.sample());
949
- this.easingFn && (t = this.easingFn(t));
950
- const e = this.boundaryEpsilon;
951
- return t <= e ? t = 0 : t >= 1 - e && (t = 1), t;
952
- }
953
- /**
954
- * Finalize progress after the smoother has been advanced (or bypassed).
955
- * Snaps the smoother at boundaries [0, 1] for instant convergence.
956
- */
957
- finalizeProgress(t) {
958
- return this.smoother && (this.smoother.setTarget(t), (t <= 0 || t >= 1) && this.smoother.snap()), this.currentProgress = this.smoother ? this.smoother.current : t, this.currentProgress;
959
- }
960
- /** Advance one frame. Applies easing → boundary snap → smoothing. */
961
- tick() {
962
- const t = this.applyPipeline();
963
- return this.smoother && t > 0 && t < 1 ? (this.smoother.setTarget(t), this.smoother.tick(), this.currentProgress = this.smoother.current) : this.finalizeProgress(t), this.currentProgress;
964
- }
965
- /** Frame-rate independent variant. `dt` in milliseconds. */
966
- tickDt(t) {
967
- const e = this.applyPipeline();
968
- return this.smoother && e > 0 && e < 1 ? (this.smoother.setTarget(e), this.smoother.tickDt(t), this.currentProgress = this.smoother.current) : this.finalizeProgress(e), this.currentProgress;
969
- }
970
- get progress() {
971
- return this.currentProgress;
972
- }
973
- /** True if no smoother or smoother is settled. */
974
- get settled() {
975
- return this.smoother == null || this.smoother.settled;
976
- }
977
- /** Immediately converge smoother to current target. */
978
- snap() {
979
- this.smoother?.snap(), this.smoother && (this.currentProgress = this.smoother.current);
980
- }
981
- /** Reset progress to a specific value (default 0). */
982
- reset(t) {
983
- const e = t ?? 0;
984
- this.smoother && this.smoother.reset(e), this.currentProgress = e;
985
- }
349
+ //#endregion
350
+ //#region src/animation/springTimingFunction.ts
351
+ function _(e) {
352
+ let t = e.sampleCount ?? 64, n = e.settleThreshold ?? .001, r = e.maxDuration ?? e.response * 4, i = new h({
353
+ response: e.response,
354
+ dampingFraction: e.dampingFraction,
355
+ initial: 0,
356
+ settleThreshold: n,
357
+ velocitySettleThreshold: n
358
+ });
359
+ i.target = 1;
360
+ let a = new Float64Array(t + 1);
361
+ a[0] = 0;
362
+ let o = r / t;
363
+ for (let e = 1; e <= t; e++) i.tick(o), a[e] = i.settled ? 1 : i.value;
364
+ return a[t] = 1, i.dispose(), (e) => {
365
+ if (e <= 0) return 0;
366
+ if (e >= 1) return 1;
367
+ let n = e * t, r = Math.floor(n), i = n - r, o = a[r];
368
+ return o + (a[r + 1] - o) * i;
369
+ };
986
370
  }
987
- class $e extends dt {
988
- threshold;
989
- getScrollY;
990
- getViewportHeight;
991
- constructor(t) {
992
- super(t), this.threshold = t?.threshold ?? 0.35, this.getScrollY = t?.getScrollY ?? (() => window.scrollY), this.getViewportHeight = t?.getViewportHeight ?? (() => window.innerHeight);
993
- }
994
- sample() {
995
- const t = this.getViewportHeight() * this.threshold;
996
- return t <= 0 ? 0 : this.getScrollY() / t;
997
- }
998
- }
999
- class De extends dt {
1000
- value = 0;
1001
- constructor(t) {
1002
- super({ smoothing: !1, ...t });
1003
- }
1004
- /** Set the raw progress value. */
1005
- set(t) {
1006
- this.value = t;
1007
- }
1008
- sample() {
1009
- return this.value;
1010
- }
1011
- }
1012
- const Ee = (s) => typeof s.transform == "function", J = (s) => typeof s == "string" && $.includes(s);
1013
- function Ce(s) {
1014
- if (!s.targets || s.targets.length === 0)
1015
- return !1;
1016
- const t = Ee(s) ? s.transform : void 0;
1017
- for (const e of s.frames) {
1018
- const i = e.transform;
1019
- if (i !== mt && i !== t)
1020
- return !1;
1021
- }
1022
- if (s.frames.length > 1) {
1023
- const e = s.frames[0].timingFunction;
1024
- for (let i = 1; i < s.frames.length; i++)
1025
- if (s.frames[i].timingFunction !== e)
1026
- return !1;
1027
- }
1028
- for (const e of s.frames)
1029
- for (const i of Object.values(e.interpVars))
1030
- for (const r of i) {
1031
- const o = r.start?.unit, n = r.stop?.unit;
1032
- if (J(o) || J(n))
1033
- return !1;
1034
- }
1035
- for (const e of s.frames)
1036
- for (const i of Object.values(e.interpVars))
1037
- for (const r of i)
1038
- if (r.start?.unit === "color" || r.stop?.unit === "color")
1039
- return !1;
1040
- return !0;
1041
- }
1042
- function Oe(s) {
1043
- const t = s.options.duration, e = [], i = /* @__PURE__ */ new Set();
1044
- for (const o of s.frames)
1045
- i.add(o.time.start), i.add(o.time.stop);
1046
- const r = [...i].sort((o, n) => o - n);
1047
- for (const o of r) {
1048
- const n = s.interpFrames(o, !1);
1049
- if (Object.keys(n).length === 0) continue;
1050
- const u = ot(n), a = {
1051
- offset: Math.max(0, Math.min(1, o / t)),
1052
- ...u
1053
- };
1054
- e.push(a);
1055
- }
1056
- return e;
1057
- }
1058
- function _e(s) {
1059
- const t = s.options, e = {
1060
- normal: "normal",
1061
- reverse: "reverse",
1062
- alternate: "alternate",
1063
- "alternate-reverse": "alternate-reverse"
1064
- }, i = {
1065
- none: "none",
1066
- forwards: "forwards",
1067
- backwards: "backwards",
1068
- both: "both"
1069
- };
1070
- return {
1071
- duration: t.duration,
1072
- delay: t.delay,
1073
- iterations: t.iterationCount === 1 / 0 ? 1 / 0 : t.iterationCount,
1074
- // TODO(HIGH): Remove enum fallbacks; throw when direction/fill values are outside supported WAAPI maps.
1075
- direction: e[t.direction] ?? "normal",
1076
- fill: i[t.fillMode] ?? "forwards",
1077
- // WAAPI easing is set per-animation — we use the frame's timing function name
1078
- // For custom functions we fall back to linear (the JS interpolation handles easing)
1079
- easing: "linear"
1080
- };
1081
- }
1082
- async function ke(s) {
1083
- const t = Oe(s), e = _e(s), i = [];
1084
- for (const r of s.targets) {
1085
- const o = r.animate(t, e);
1086
- i.push(o);
1087
- }
1088
- return await Promise.all(i.map((r) => r.finished)), i;
1089
- }
1090
- const Me = (s) => typeof s != "object" || s == null ? !1 : typeof s.clone == "function", x = (s) => typeof s == "string" ? s : s.name ?? String(s.id);
1091
- let Ae = 0;
1092
- class gt {
1093
- id = Ae++;
1094
- name;
1095
- superKey;
1096
- targets;
1097
- options;
1098
- templateFrames = [];
1099
- parsedVars = [];
1100
- frameId = 0;
1101
- frames = [];
1102
- handleId = void 0;
1103
- startTime = void 0;
1104
- pausedTime = 0;
1105
- prevTime = 0;
1106
- t = 0;
1107
- iteration = 0;
1108
- started = !1;
1109
- done = !1;
1110
- reversed = !1;
1111
- paused = !1;
1112
- /** When true, this animation is managed by an AnimationGroup and should not run its own rAF loop. */
1113
- managed = !1;
1114
- unflatten = !0;
1115
- resolvePromise = null;
1116
- _playingPromise = null;
1117
- /**
1118
- * Pre-bound draw callback — allocated once to avoid creating a new
1119
- * closure on every requestAnimationFrame reschedule.
1120
- */
1121
- _boundDraw = this.draw.bind(this);
1122
- dispatchAnimationEvent(t) {
1123
- if (!(typeof AnimationEvent > "u"))
1124
- for (const e of this.targets)
1125
- typeof e?.dispatchEvent == "function" && e.dispatchEvent(
1126
- new AnimationEvent(t, {
1127
- animationName: this.name ?? "",
1128
- elapsedTime: this.t / 1e3
1129
- })
1130
- );
1131
- }
1132
- constructor(t, e, i, r) {
1133
- this.options = {}, this.setOptions({ ...te, ...t ?? {} }), this.targets = e == null ? [] : Array.isArray(e) ? e : [e], this.name = i, this.superKey = r;
1134
- }
1135
- convertFrameStart(t) {
1136
- if (t.start.unit === "s" || t.start.unit === "ms" || !t.start.unit) {
1137
- const e = t.start.unit === "s" ? "s" : "ms", i = it(t.start.value, e);
1138
- t.start.value = i / this.options.duration * 100, t.start.unit = "%";
1139
- }
1140
- return t.start.value = E(t.start.value, 0, 100), t;
1141
- }
1142
- addFrame(t, e, i, r) {
1143
- typeof t == "number" ? t = String(t) + "%" : typeof t == "string" ? t = t : t instanceof f && (t = String(t));
1144
- const o = st(t);
1145
- let n = {
1146
- id: this.frameId,
1147
- start: o,
1148
- vars: e,
1149
- transform: i,
1150
- timingFunction: M(r) ?? this.options.timingFunction
1151
- };
1152
- return this.convertFrameStart(
1153
- n
1154
- ), this.templateFrames.push(
1155
- n
1156
- ), this.frameId += 1, this;
1157
- }
1158
- createFrame(t, e) {
1159
- const i = this.templateFrames[t], r = this.templateFrames[e], o = {
1160
- start: t,
1161
- stop: e
1162
- }, n = Te(i, r, this.options.duration);
1163
- let u = i.transform;
1164
- if (u == null) {
1165
- const l = B(
1166
- t,
1167
- this.frames,
1168
- (h) => h.transform != null
1169
- );
1170
- u = this.frames[l].transform;
1171
- }
1172
- let a = i.timingFunction;
1173
- if (a == null) {
1174
- const l = B(
1175
- t,
1176
- this.frames,
1177
- (h) => h.timingFunction != null
1178
- );
1179
- a = this.frames[l].timingFunction;
1180
- }
1181
- return {
1182
- id: this.frameId++,
1183
- ixs: o,
1184
- start: i.start,
1185
- time: n,
1186
- vars: void 0,
1187
- flatVars: void 0,
1188
- interpVars: {},
1189
- allInterpVars: [],
1190
- transform: u,
1191
- timingFunction: a
1192
- };
1193
- }
1194
- /**
1195
- * Build an index mapping each variable name to the frame indices where
1196
- * it appears. Used by reconcileVars() for O(1) "next occurrence" lookups
1197
- * instead of O(N) findIndex scans per variable.
1198
- */
1199
- buildVarIndex() {
1200
- const t = /* @__PURE__ */ new Map();
1201
- for (let e = 0; e < this.parsedVars.length; e++)
1202
- for (const i of Object.keys(this.parsedVars[e])) {
1203
- let r = t.get(i);
1204
- r || (r = [], t.set(i, r)), r.push(e);
1205
- }
1206
- return t;
1207
- }
1208
- /**
1209
- * Reconcile interpolation variables across non-adjacent keyframes.
1210
- * For each variable at frame `ix`, find the next frame that also
1211
- * defines that variable and create an interpolation segment between them.
1212
- *
1213
- * Uses a pre-built variable index (from buildVarIndex) to avoid
1214
- * O(frames²) findIndex scans.
1215
- */
1216
- reconcileVars(t, e) {
1217
- const i = this.parsedVars[t];
1218
- if (i)
1219
- for (const r of Object.keys(i)) {
1220
- const o = e.get(r);
1221
- if (!o) continue;
1222
- let n = -1;
1223
- for (const h of o)
1224
- if (h > t) {
1225
- n = h;
1226
- break;
1227
- }
1228
- if (n === -1) continue;
1229
- const [u, a] = [t, n], c = this.frames.findIndex(
1230
- (h) => h.ixs.start === u && h.ixs.stop === a
1231
- ), l = c !== -1 ? this.frames[c] : this.createFrame(u, a);
1232
- l.interpVars[r] = Ve(
1233
- r,
1234
- u,
1235
- a,
1236
- this.parsedVars,
1237
- this.options.colorSpace,
1238
- this.options.hueMethod
1239
- ), c === -1 && this.frames.push(l);
1240
- }
1241
- }
1242
- parse() {
1243
- this.frames = [], this.templateFrames.sort((e, i) => e.start.value - i.start.value), this.parsedVars = this.templateFrames.map((e) => {
1244
- const i = we(
1245
- e.vars
1246
- );
1247
- return Object.values(i).forEach((r) => {
1248
- r.setTargets(this.targets);
1249
- }), i;
1250
- });
1251
- for (let e = 0; e < this.templateFrames.length - 1; e++)
1252
- this.frames.push(this.createFrame(e, e + 1));
1253
- const t = this.buildVarIndex();
1254
- return this.frames.forEach((e, i) => this.reconcileVars(i, t)), this.frames.sort((e, i) => e.time.start === i.time.start ? e.time.stop - i.time.stop : e.time.start - i.time.start), this.frames = this.frames.filter(
1255
- (e) => e.interpVars != null && Object.keys(e.interpVars).length > 0
1256
- ), this.frames.forEach((e) => {
1257
- const i = Object.entries(e.interpVars).reduce((r, [o, n]) => (r[o] = n.map((u) => u.value), r), {});
1258
- e.flatVars = i, e.vars = Ot(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
1259
- }), this;
1260
- }
1261
- setTimingFunction(t) {
1262
- return this.options.timingFunction = M(t) ?? et, this;
1263
- }
1264
- setIterationCount(t) {
1265
- if (!t || t === "infinite" || t === "∞" || t === "Infinity")
1266
- this.options.iterationCount = 1 / 0;
1267
- else if (typeof t == "string") {
1268
- const e = parseFloat(t.trim());
1269
- if (isNaN(e) || e < 0) return this;
1270
- this.options.iterationCount = e;
1271
- } else {
1272
- if (isNaN(t) || t < 0) return this;
1273
- this.options.iterationCount = t;
1274
- }
1275
- return this;
1276
- }
1277
- setDuration(t) {
1278
- typeof t == "string" && (t = L(t));
1279
- const e = t ?? this.options.duration;
1280
- if (!isFinite(e) || e <= 0) return this;
1281
- const i = this.options.duration, r = e / i;
1282
- for (let o = 0; o < this.frames.length; o++) {
1283
- const n = this.frames[o];
1284
- n.time.start *= r, n.time.stop *= r;
1285
- }
1286
- return this.options.duration = e, this;
1287
- }
1288
- setDelay(t) {
1289
- return typeof t == "string" && (t = L(t)), this.options.delay = t ?? 0, this;
1290
- }
1291
- setDirection(t) {
1292
- return this.options.direction = t ?? "normal", 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;
1293
- }
1294
- setFillMode(t) {
1295
- return this.options.fillMode = t ?? "forwards", this;
1296
- }
1297
- setUseWAAPI(t) {
1298
- return this.options.useWAAPI = t ?? !0, this;
1299
- }
1300
- setColorSpace(t) {
1301
- return this.options.colorSpace = t ?? "oklab", this;
1302
- }
1303
- setHueMethod(t) {
1304
- return t !== void 0 && (this.options.hueMethod = t), this;
1305
- }
1306
- setOptions(t) {
1307
- return this.setTimingFunction(t.timingFunction), this.setDuration(t.duration), this.setIterationCount(t.iterationCount), this.setDelay(t.delay), this.setDirection(t.direction), this.setFillMode(t.fillMode), this.setUseWAAPI(t.useWAAPI), this.setColorSpace(t.colorSpace), this.setHueMethod(t.hueMethod), this;
1308
- }
1309
- reverse() {
1310
- if (this.startTime !== void 0) {
1311
- const t = this.t, e = this.options.duration - 2 * t;
1312
- this.startTime -= e;
1313
- }
1314
- return this.reversed = !this.reversed, this;
1315
- }
1316
- fillForwards() {
1317
- this.interpFrames(this.options.duration, !0);
1318
- }
1319
- fillBackwards() {
1320
- this.interpFrames(0, !0);
1321
- }
1322
- /**
1323
- * Stateless progress query. Maps [0,1] from first keyframe to last,
1324
- * regardless of playback direction. `apply=true` invokes transform callbacks.
1325
- */
1326
- at(t, e = !1) {
1327
- const i = this.reversed;
1328
- this.reversed = !1;
1329
- const r = E(t, 0, 1) * this.options.duration, o = this.interpFrames(r, e);
1330
- return this.reversed = i, o;
1331
- }
1332
- /**
1333
- * Interpolate all active frames at time `t`. This is the hot path —
1334
- * called once per rAF frame during playback.
1335
- *
1336
- * Uses binary search (O(log N)) to find the first matching frame,
1337
- * then scans neighbors to collect all overlapping frames at `t`
1338
- * (multiple properties may share the same time range).
1339
- *
1340
- * @param t - Current animation time in milliseconds
1341
- * @param transformFrames - If true, applies each frame's transform function to targets
1342
- * @returns Merged flat vars from all active frames
1343
- */
1344
- interpFrames(t, e = !1) {
1345
- t = this.reversed ? this.options.duration - t : t;
1346
- const i = {}, r = this.frames, o = r.length, n = lt(
1347
- r,
1348
- t,
1349
- (a) => a.time.start,
1350
- (a) => a.time.stop
1351
- );
1352
- if (n === -1) return i;
1353
- const u = (a) => {
1354
- const { start: c, stop: l } = a.time, h = at(t, c, l, 0, 1), m = a.timingFunction(h);
1355
- for (const p of a.allInterpVars)
1356
- ye(m, p);
1357
- e && a.transform(
1358
- this.unflatten ? a.vars : a.flatVars,
1359
- t
1360
- ), Object.assign(i, a.flatVars);
1361
- };
1362
- for (let a = n; a >= 0; a--) {
1363
- const c = r[a];
1364
- if (t < c.time.start || t > c.time.stop) break;
1365
- u(c);
1366
- }
1367
- for (let a = n + 1; a < o; a++) {
1368
- const c = r[a];
1369
- if (t < c.time.start || t > c.time.stop) break;
1370
- u(c);
1371
- }
1372
- return i;
1373
- }
1374
- async onStart() {
1375
- 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 _t(this.options.delay), this.paused = !1), this.started = !0;
1376
- }
1377
- async onEnd() {
1378
- this.options.fillMode === "forwards" || this.options.fillMode === "both" ? this.fillForwards() : (this.options.fillMode === "none" || this.options.fillMode === "backwards") && this.fillBackwards(), 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"));
1379
- }
1380
- async tick(t) {
1381
- if (this.startTime === void 0 && (await this.onStart(), this.startTime = t + this.options.delay, this.dispatchAnimationEvent("animationstart")), this.paused && this.pausedTime === 0)
1382
- return this.pausedTime = t, this.t;
1383
- if (this.pausedTime > 0 && !this.paused) {
1384
- const e = t - this.pausedTime;
1385
- this.startTime += e, this.pausedTime = 0;
1386
- }
1387
- return this.t = t - this.startTime, this.t >= this.options.duration && (await this.onEnd(), this.t = this.options.duration), this.t;
1388
- }
1389
- async draw(t) {
1390
- this.managed || (t = await this.tick(t), !this.paused && (this.interpFrames(t, !0), this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = w(this._boundDraw)));
1391
- }
1392
- /** Internal rAF-based play loop. */
1393
- _playRAF() {
1394
- return new Promise((t) => {
1395
- this.resolvePromise = t, this.handleId = w(this._boundDraw);
1396
- });
1397
- }
1398
- /** Play via the Web Animations API for compositor-thread execution. */
1399
- async _playWAAPI() {
1400
- try {
1401
- await ke(this), this.reset();
1402
- } catch {
1403
- return this._playRAF();
1404
- }
1405
- }
1406
- async play() {
1407
- if (this.managed)
1408
- return;
1409
- if (this._playingPromise) return this._playingPromise;
1410
- let t;
1411
- return this.options.useWAAPI && this.targets.length > 0 && typeof this.targets[0]?.animate == "function" && Ce(this) ? t = this._playWAAPI() : t = this._playRAF(), this._playingPromise = t, t.finally(() => {
1412
- this._playingPromise = null;
1413
- }), t;
1414
- }
1415
- pause(t = !0) {
1416
- return this.paused && t ? this.resume() : (this.started && (this.paused = !0), this);
1417
- }
1418
- resume() {
1419
- return this.started && this.paused && (this.paused = !1, this.handleId = w(this._boundDraw)), this;
1420
- }
1421
- stop() {
1422
- k(this.handleId), this.reset();
1423
- }
1424
- playing() {
1425
- return !(!this.started || this.paused);
1426
- }
1427
- /** Returns the effective time accounting for direction reversal. */
1428
- get effectiveT() {
1429
- return this.reversed ? this.options.duration - this.t : this.t;
1430
- }
1431
- reset() {
1432
- return this.done = !1, this.started = !1, this.paused = !1, this.reversed = !1, this.iteration = 0, this.startTime = void 0, this.pausedTime = 0, this.t = 0, this;
1433
- }
1434
- setTargets(...t) {
1435
- return this.targets = t, this.frames.forEach((e) => {
1436
- Object.values(e.interpVars).forEach((i) => {
1437
- i.forEach(({ start: r, stop: o, value: n }) => {
1438
- r.setTargets(this.targets), o.setTargets(this.targets), n.setTargets(this.targets);
1439
- });
1440
- });
1441
- }), this;
1442
- }
1443
- group(...t) {
1444
- return new se(this, ...t);
1445
- }
1446
- }
1447
- class Ne extends gt {
1448
- constructor(t, ...e) {
1449
- super(t, e), this.unflatten = !1;
1450
- }
1451
- fromVars(t, e) {
1452
- this.unflatten = e != null, e ??= this.transform.bind(this);
1453
- for (let i = 0; i < t.length; i++) {
1454
- const r = t[i], o = Math.round(i / (t.length - 1) * 100);
1455
- this.addFrame(o, r, e);
1456
- }
1457
- return this.parse(), this;
1458
- }
1459
- fromKeyframes(t, e) {
1460
- this.unflatten = e != null, e ??= this.transform.bind(this), kt(t) && (t = new Map(Object.entries(t)));
1461
- const i = t instanceof Map ? t.entries() : Object.entries(t);
1462
- for (const [r, o] of i)
1463
- this.addFrame(r, o, e);
1464
- return this.parse(), this;
1465
- }
1466
- fromString(t, e) {
1467
- this.unflatten = e != null, e ??= this.transform.bind(this);
1468
- const i = Jt(t);
1469
- for (const [r, o] of i.entries()) {
1470
- const n = Object.fromEntries(
1471
- Object.entries(o).map(([c, l]) => [
1472
- c,
1473
- Me(l) ? l.clone() : l
1474
- ])
1475
- ), u = n.animationTimingFunction ?? n.timingFunction;
1476
- delete n.animationTimingFunction, delete n.timingFunction;
1477
- const a = u ? M(u.toString()) : void 0;
1478
- this.addFrame(r, n, e, a);
1479
- }
1480
- return this.parse(), this;
1481
- }
1482
- transform(t) {
1483
- mt(t, this.targets);
1484
- }
1485
- }
1486
- export {
1487
- gt as Animation,
1488
- se as AnimationGroup,
1489
- Ye as CSSCubicBezier,
1490
- Ne as CSSKeyframesAnimation,
1491
- Ue as ElementMorph,
1492
- De as ManualTimeline,
1493
- Se as NumericAnimation,
1494
- $e as ScrollTimeline,
1495
- Fe as SmoothProgress,
1496
- dt as Timeline,
1497
- Be as bezierPresets,
1498
- Re as bounceInEase,
1499
- We as bounceInEaseHalf,
1500
- Le as bounceInOutEase,
1501
- Xe as bounceOutEase,
1502
- He as bounceOutEaseHalf,
1503
- Ge as cancelAnimationFrame,
1504
- qe as clamp,
1505
- Ze as cubicBezier,
1506
- Qe as cubicBezierToSVG,
1507
- Je as cubicBezierToString,
1508
- ts as deCasteljau,
1509
- es as easeInBounce,
1510
- ss as easeInCirc,
1511
- is as easeInCubic,
1512
- rs as easeInExpo,
1513
- ns as easeInOutCirc,
1514
- os as easeInOutCubic,
1515
- as as easeInOutExpo,
1516
- us as easeInOutQuad,
1517
- ls as easeInOutSine,
1518
- cs as easeInQuad,
1519
- hs as easeInSine,
1520
- fs as easeOutCirc,
1521
- ps as easeOutCubic,
1522
- ms as easeOutExpo,
1523
- ds as easeOutQuad,
1524
- gs as easeOutSine,
1525
- x as getAnimationId,
1526
- ys as interpBezier,
1527
- ws as jumpTerms,
1528
- Vs as lerp,
1529
- Ts as linear,
1530
- bs as logerp,
1531
- Ss as requestAnimationFrame,
1532
- vs as scale,
1533
- Fs as sleep,
1534
- Is as smoothStep3,
1535
- Ps as stepEnd,
1536
- Es as stepStart,
1537
- Cs as steppedEase,
1538
- Os as timingFunctions
1539
- };
371
+ //#endregion
372
+ //#region src/animation/morph.ts
373
+ var v = (e) => {
374
+ if (e instanceof HTMLElement) {
375
+ let t = e.getBoundingClientRect();
376
+ return {
377
+ x: t.x,
378
+ y: t.y,
379
+ width: t.width,
380
+ height: t.height
381
+ };
382
+ }
383
+ return e;
384
+ }, y = class {
385
+ animation;
386
+ transformOrigin;
387
+ timingFunction;
388
+ duration;
389
+ constructor(e, t, n) {
390
+ this.transformOrigin = n?.transformOrigin ?? "top left", this.timingFunction = n?.timingFunction, this.duration = n?.duration ?? 0, this.measure(e, t);
391
+ }
392
+ measure(e, t) {
393
+ let n = v(e), r = v(t), i = r.x - n.x, a = r.y - n.y, o = n.width === 0 ? 1 : r.width / n.width, s = n.height === 0 ? 1 : r.height / n.height;
394
+ return this.animation = new l([{
395
+ translateX: 0,
396
+ translateY: 0,
397
+ scaleX: 1,
398
+ scaleY: 1
399
+ }, {
400
+ translateX: i,
401
+ translateY: a,
402
+ scaleX: o,
403
+ scaleY: s
404
+ }], {
405
+ timingFunction: this.timingFunction,
406
+ duration: this.duration
407
+ }), this;
408
+ }
409
+ ready() {
410
+ return this.animation.ready();
411
+ }
412
+ at(e) {
413
+ return this.animation.at(e);
414
+ }
415
+ toCSSTransform(e) {
416
+ let { translateX: t, translateY: n, scaleX: r, scaleY: i } = this.animation.at(e);
417
+ return `translate(${t}px, ${n}px) scale(${r}, ${i})`;
418
+ }
419
+ apply(e, t) {
420
+ e.style.transform = this.toCSSTransform(t), e.style.transformOrigin = this.transformOrigin;
421
+ }
422
+ play(e, t) {
423
+ return this.animation.play((t) => {
424
+ let { translateX: n, translateY: r, scaleX: i, scaleY: a } = t;
425
+ e.style.transform = `translate(${n}px, ${r}px) scale(${i}, ${a})`, e.style.transformOrigin = this.transformOrigin;
426
+ }, t ?? this.duration);
427
+ }
428
+ stop() {
429
+ this.animation.stop();
430
+ }
431
+ }, b = (e) => Math.max(0, Math.min(1, e)), x = class {
432
+ smoother;
433
+ easingFn;
434
+ currentProgress = 0;
435
+ boundaryEpsilon;
436
+ _easingReady = null;
437
+ constructor(e) {
438
+ this.boundaryEpsilon = e?.boundaryEpsilon ?? .005;
439
+ let t = e?.easing;
440
+ typeof t == "function" ? this.easingFn = t : typeof t == "string" ? (this.easingFn = null, this.resolveEasingName(t)) : this.easingFn = null, e?.smoothing === !1 ? this.smoother = null : this.smoother = new f(e?.smoothing);
441
+ }
442
+ resolveEasingName(e) {
443
+ return this._easingReady ||= import("./engine-DuAFoqZF.js").then((t) => {
444
+ let n = t.getTimingFunction(e);
445
+ n && (this.easingFn = n);
446
+ }), this._easingReady;
447
+ }
448
+ ready() {
449
+ return this._easingReady ?? Promise.resolve();
450
+ }
451
+ applyPipeline() {
452
+ let e = b(this.sample());
453
+ this.easingFn && (e = this.easingFn(e));
454
+ let t = this.boundaryEpsilon;
455
+ return e <= t ? e = 0 : e >= 1 - t && (e = 1), e;
456
+ }
457
+ finalizeProgress(e) {
458
+ return this.smoother && (this.smoother.setTarget(e), (e <= 0 || e >= 1) && this.smoother.snap()), this.currentProgress = this.smoother ? this.smoother.current : e, this.currentProgress;
459
+ }
460
+ _advance(e) {
461
+ let t = this.applyPipeline();
462
+ return this.smoother && t > 0 && t < 1 ? (this.smoother.setTarget(t), e === void 0 ? this.smoother.tick() : this.smoother.tickDt(e), this.currentProgress = this.smoother.current) : this.finalizeProgress(t), this.currentProgress;
463
+ }
464
+ tick() {
465
+ return this._advance();
466
+ }
467
+ tickDt(e) {
468
+ return this._advance(e);
469
+ }
470
+ get progress() {
471
+ return this.currentProgress;
472
+ }
473
+ get settled() {
474
+ return this.smoother == null || this.smoother.settled;
475
+ }
476
+ snap() {
477
+ this.smoother?.snap(), this.smoother && (this.currentProgress = this.smoother.current);
478
+ }
479
+ reset(e) {
480
+ let t = e ?? 0;
481
+ this.smoother && this.smoother.reset(t), this.currentProgress = t;
482
+ }
483
+ }, S = class extends x {
484
+ threshold;
485
+ getScrollY;
486
+ getViewportHeight;
487
+ constructor(e) {
488
+ super(e), this.threshold = e?.threshold ?? .35, this.getScrollY = e?.getScrollY ?? (() => window.scrollY), this.getViewportHeight = e?.getViewportHeight ?? (() => window.innerHeight);
489
+ }
490
+ sample() {
491
+ let e = this.getViewportHeight() * this.threshold;
492
+ return e <= 0 ? 0 : this.getScrollY() / e;
493
+ }
494
+ }, C = class extends x {
495
+ value = 0;
496
+ constructor(e) {
497
+ super({
498
+ smoothing: !1,
499
+ ...e
500
+ });
501
+ }
502
+ set(e) {
503
+ this.value = e;
504
+ }
505
+ sample() {
506
+ return this.value;
507
+ }
508
+ }, w = () => import("./engine-DuAFoqZF.js");
509
+ //#endregion
510
+ export { y as ElementMorph, C as ManualTimeline, l as NumericAnimation, o as RAFPlayback, S as ScrollTimeline, f as SmoothProgress, h as SpringProgress, x as Timeline, w as loadAnimationEngine, g as springLinearStops, _ as springTimingFunction };