@mkbabb/keyframes.js 4.4.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,84 @@
1
+ import { t as e } from "./errors-W8zkvPw4.js";
2
+ import { CSSKeyframesAnimation as t } from "./engine-DQcb7CLW.js";
3
+ import { PathGeometry as n } from "@mkbabb/value.js";
4
+ //#region src/animation/morph-svg.ts
5
+ var r = 64, i = (e) => `--morph-${e}-x`, a = (e) => `--morph-${e}-y`, o = (e) => `--morph-${e}-angle`, s = (e, t, n) => {
6
+ let r = Array(t + 1);
7
+ for (let i = 0; i <= t; i++) if (n) {
8
+ let n = e.sampleAtLength(e.totalLength * (i / t));
9
+ r[i] = {
10
+ x: n.x,
11
+ y: n.y,
12
+ angle: n.angle
13
+ };
14
+ } else r[i] = e.getPointAtT(i / t);
15
+ return r;
16
+ }, c = (e) => Number.isInteger(e) ? `${e}` : e.toFixed(3), l = (e) => {
17
+ if (e.length === 0) return "";
18
+ let t = `M ${c(e[0].x)} ${c(e[0].y)}`;
19
+ for (let n = 1; n < e.length; n++) t += ` L ${c(e[n].x)} ${c(e[n].y)}`;
20
+ return t;
21
+ }, u = (e, t) => {
22
+ let n = Array(t + 1);
23
+ for (let e = 0; e <= t; e++) n[e] = {
24
+ x: 0,
25
+ y: 0
26
+ };
27
+ return (r) => {
28
+ let o = r;
29
+ for (let e = 0; e <= t; e++) {
30
+ let t = n[e];
31
+ t.x = o[i(e)]?.[0]?.value ?? 0, t.y = o[a(e)]?.[0]?.value ?? 0;
32
+ }
33
+ let s = l(n);
34
+ e.style.setProperty("--morph-d", s), e.style.setProperty("d", `path("${s}")`);
35
+ };
36
+ };
37
+ function d(c, l, d = {}) {
38
+ let { samples: f = r, target: p, orient: m = !1, autoPlay: h = !0, ...g } = d;
39
+ if (typeof c != "string" || c.length === 0) throw new e("from", c, "fromMorphSVG(): `from` must be a non-empty SVG path `d` string.");
40
+ if (typeof l != "string" || l.length === 0) throw new e("to", l, "fromMorphSVG(): `to` must be a non-empty SVG path `d` string.");
41
+ if (!Number.isInteger(f) || f < 2) throw new e("samples", f, "fromMorphSVG(): `samples` must be an integer >= 2 (a 1-sample morph is just the two endpoints, with no body to interpolate).");
42
+ let _ = new n(c), v = new n(l);
43
+ if (_.totalLength === 0) throw new e("from", c, "fromMorphSVG(): the `from` path has zero arc-length — a morph between a zero-length path and anything is malformed input, not an identity animation.");
44
+ if (v.totalLength === 0) throw new e("to", l, "fromMorphSVG(): the `to` path has zero arc-length — a morph between a zero-length path and anything is malformed input, not an identity animation.");
45
+ let y = s(_, f, m), b = s(v, f, m), x = {}, S = {};
46
+ for (let e = 0; e <= f; e++) x[i(e)] = y[e].x, x[a(e)] = y[e].y, S[i(e)] = b[e].x, S[a(e)] = b[e].y, m && (x[o(e)] = y[e].angle ?? 0, S[o(e)] = b[e].angle ?? 0);
47
+ let C = {
48
+ "0%": x,
49
+ "100%": S
50
+ }, w = p == null ? void 0 : u(p, f), T = new t(g).fromKeyframes(C, w);
51
+ return h && T.play(), T;
52
+ }
53
+ var f = class {
54
+ animation;
55
+ samples;
56
+ constructor(e, t, n = {}) {
57
+ this.animation = d(e, t, n), this.samples = n.samples ?? r;
58
+ }
59
+ sampleD(e) {
60
+ let t = (e < 0 ? 0 : e > 1 ? 1 : e) * this.animation.options.duration, n = this.animation.interpFrames(t, !1), r = Array(this.samples + 1);
61
+ for (let e = 0; e <= this.samples; e++) {
62
+ let t = n[i(e)]?.[0]?.value, o = n[a(e)]?.[0]?.value;
63
+ r[e] = {
64
+ x: t ?? 0,
65
+ y: o ?? 0
66
+ };
67
+ }
68
+ return l(r);
69
+ }
70
+ play() {
71
+ return this.animation.play();
72
+ }
73
+ pause() {
74
+ return this.animation.pause(), this;
75
+ }
76
+ stop() {
77
+ return this.animation.stop(), this;
78
+ }
79
+ get finished() {
80
+ return this.animation.finished;
81
+ }
82
+ };
83
+ //#endregion
84
+ export { f as MorphSVG, d as fromMorphSVG };
@@ -1,4 +1,4 @@
1
- import { CSSKeyframesAnimation as e } from "./engine-CNHvTgpw.js";
1
+ import { CSSKeyframesAnimation as e } from "./engine-DQcb7CLW.js";
2
2
  //#region src/animation/motion-path.ts
3
3
  var t = (e) => typeof e == "number" ? `${e}%` : e;
4
4
  function n(n, r) {
@@ -1,6 +1,6 @@
1
- import { a as e, c as t, f as n, i as r } from "./timeline-B7SV3T_E.js";
1
+ import { a as e, c as t, f as n, i as r } from "./timeline-vY3eD3Ax.js";
2
2
  import { n as i } from "./decay-BvNmFk51.js";
3
- import { n as a, t as o } from "./waapi-D9MHMm_9.js";
3
+ import { n as a, t as o } from "./waapi-D0ssxKy1.js";
4
4
  import { a as s, i as c, n as l, r as u, t as d } from "./scroll-grammar-B4kPvGh5.js";
5
5
  //#region src/animation/scroll-scene.ts
6
6
  var f = {
@@ -1,4 +1,4 @@
1
- import { f as e, l as t } from "./timeline-B7SV3T_E.js";
1
+ import { f as e, l as t } from "./timeline-vY3eD3Ax.js";
2
2
  //#region src/animation/sequence-events.ts
3
3
  var n = class {
4
4
  subscribers = new Map([
@@ -1,4 +1,4 @@
1
- import { a as e } from "./timeline-B7SV3T_E.js";
1
+ import { a as e } from "./timeline-vY3eD3Ax.js";
2
2
  //#region src/animation/internal/binarySearch.ts
3
3
  function t(e, t, n, r) {
4
4
  let i = 0, a = e.length - 1;
@@ -1,43 +1,31 @@
1
1
  import { n as e, t } from "./errors-W8zkvPw4.js";
2
+ import { clamp as n, lerpArray as r, scale as i } from "@mkbabb/value.js/math";
2
3
  //#region src/animation/easing.ts
3
- var n = (e) => typeof e == "function" ? { fn: e } : e, r = /^(linear|ease|ease-in|ease-out|ease-in-out)$/, i = /^(cubic-bezier\(|steps\(|linear\(|step-start$|step-end$)/, a = (e) => {
4
+ var a = (e) => typeof e == "function" ? { fn: e } : e, o = /^(linear|ease|ease-in|ease-out|ease-in-out)$/, s = /^(cubic-bezier\(|steps\(|linear\(|step-start$|step-end$)/, c = (e) => {
4
5
  let t = e.trim();
5
- if (r.test(t) || i.test(t)) return t;
6
+ if (o.test(t) || s.test(t)) return t;
6
7
  };
7
- async function o(t) {
8
+ async function l(t) {
8
9
  let n;
9
10
  try {
10
- n = await import("./engine-CNHvTgpw.js");
11
+ n = await import("./engine-DQcb7CLW.js");
11
12
  } catch (e) {
12
13
  throw Error(`keyframes: the engine chunk failed to load while resolving easing "${t}" — the easing registry is unreachable.`, { cause: e });
13
14
  }
14
15
  let r = n.getTimingFunction(t);
15
16
  if (!r) throw new e(t);
16
- let i = { fn: r }, o = a(t);
17
- return o && (i.css = o), i;
17
+ let i = { fn: r }, a = c(t);
18
+ return a && (i.css = a), i;
18
19
  }
19
20
  //#endregion
20
21
  //#region src/animation/internal/leaves.ts
21
- var s = 1e3 / 60;
22
- function c(e, t, n) {
23
- return Math.min(Math.max(e, t), n);
24
- }
25
- function l(e, t, n, r = 0, i = 1) {
26
- if (n === t) throw Error("fromMax and fromMin cannot be equal");
27
- let a = (i - r) / (n - t);
28
- return (e - t) * a + r;
29
- }
30
- function u(e, t, n, r) {
31
- let i = e.length, a = 1 - n;
32
- for (let o = 0; o < i; o++) r[o] = a * e[o] + n * t[o];
33
- return r;
34
- }
22
+ var u = 1e3 / 60;
35
23
  function d(e) {
36
24
  if (typeof window < "u" && window.requestAnimationFrame) return window.requestAnimationFrame(e);
37
- let t = s, n = Date.now();
25
+ let t = u, n = Date.now();
38
26
  return setTimeout(() => {
39
27
  let r = Date.now(), i = r - n;
40
- n = r, t = Math.max(0, s - i), e(r);
28
+ n = r, t = Math.max(0, u - i), e(r);
41
29
  }, t);
42
30
  }
43
31
  function f(e) {
@@ -82,13 +70,13 @@ var b = class {
82
70
  };
83
71
  this._rafId = d(r);
84
72
  }
85
- play = (e, t, n) => {
73
+ play = (e, t, r) => {
86
74
  if (e <= 0) throw Error("RAFPlayback.play() requires a duration > 0.");
87
- return this.stop(), y(n?.respectReducedMotion, () => (t(1), Promise.resolve()), () => new Promise((n) => {
88
- this._resolve = n, this._startTime = void 0, this._run((n) => {
89
- this._startTime === void 0 && (this._startTime = n);
90
- let r = c((n - this._startTime) / e, 0, 1);
91
- return t(r), r < 1;
75
+ return this.stop(), y(r?.respectReducedMotion, () => (t(1), Promise.resolve()), () => new Promise((r) => {
76
+ this._resolve = r, this._startTime = void 0, this._run((r) => {
77
+ this._startTime === void 0 && (this._startTime = r);
78
+ let i = n((r - this._startTime) / e, 0, 1);
79
+ return t(i), i < 1;
92
80
  });
93
81
  }));
94
82
  };
@@ -139,7 +127,7 @@ var b = class {
139
127
  return this.isSettled;
140
128
  }
141
129
  setTarget(e) {
142
- this.options.clamp && (e = c(e, 0, 1));
130
+ this.options.clamp && (e = n(e, 0, 1));
143
131
  let t = Math.abs(e - this.targetValue);
144
132
  t > 0 && t >= this.options.targetEpsilon && (this.targetValue = e, y(this.options.respectReducedMotion, () => this._snapSettled(), () => {
145
133
  this.isSettled = !1, this._onFrame && this._startLoop();
@@ -151,7 +139,7 @@ var b = class {
151
139
  tickDt(e) {
152
140
  if (this.isSettled) return this.currentValue;
153
141
  let t = 1 - Math.exp(-this.options.damping * e / 16.667);
154
- 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 = c(this.currentValue, 0, 1)), this.currentValue;
142
+ 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 = n(this.currentValue, 0, 1)), this.currentValue;
155
143
  }
156
144
  snap() {
157
145
  this.currentValue = this.targetValue, this.isSettled = !0, this._playback.stop();
@@ -179,11 +167,11 @@ var b = class {
179
167
  //#endregion
180
168
  //#region src/animation/spring-duration.ts
181
169
  function C(e) {
182
- let { visualDuration: t, duration: n, bounce: r = 0, ...i } = e, a = t ?? n ?? .5, o = 1 - c(r, -1, 1);
170
+ let { visualDuration: t, duration: r, bounce: i = 0, ...a } = e, o = t ?? r ?? .5, s = 1 - n(i, -1, 1);
183
171
  return {
184
- ...i,
185
- response: a,
186
- dampingFraction: o
172
+ ...a,
173
+ response: o,
174
+ dampingFraction: s
187
175
  };
188
176
  }
189
177
  //#endregion
@@ -368,12 +356,12 @@ var E = new Float64Array(), D = {
368
356
  boundaryEpsilon;
369
357
  constructor(e) {
370
358
  this.boundaryEpsilon = e?.boundaryEpsilon ?? .005;
371
- let r = e?.easing;
372
- if (typeof r == "string") throw new t("easing", r, "Timeline accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
373
- this._easingFn = r == null ? (e) => e : n(r).fn, e?.smoothing === !1 ? this.smoother = null : this.smoother = new S(e?.smoothing);
359
+ let n = e?.easing;
360
+ if (typeof n == "string") throw new t("easing", n, "Timeline accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
361
+ this._easingFn = n == null ? (e) => e : a(n).fn, e?.smoothing === !1 ? this.smoother = null : this.smoother = new S(e?.smoothing);
374
362
  }
375
363
  applyPipeline() {
376
- let e = c(this.sample(), 0, 1);
364
+ let e = n(this.sample(), 0, 1);
377
365
  e = this._easingFn(e);
378
366
  let t = this.boundaryEpsilon;
379
367
  return e <= t ? e = 0 : e >= 1 - t && (e = 1), e;
@@ -439,4 +427,4 @@ function M(e) {
439
427
  return e.axis !== void 0 && (t.axis = e.axis), e.inset !== void 0 && (t.inset = e.inset), new globalThis.ViewTimeline(t);
440
428
  }
441
429
  //#endregion
442
- export { n as _, O as a, S as c, y as d, c as f, o as g, a as h, M as i, b as l, l as m, j as n, w as o, u as p, k as r, T as s, A as t, v as u };
430
+ export { a as _, O as a, S as c, y as d, n as f, l as g, c as h, M as i, b as l, i as m, j as n, w as o, r as p, k as r, T as s, A as t, v as u };
@@ -2,27 +2,30 @@ import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
2
  import { CSSCubicBezier as t, FunctionValue as n, ValueArray as r, ValueUnit as i, cssLinear as a, flattenObject as o, functionIdentityValue as s, memoize as c, normalizeValueUnits as l, parseCSSSubValue as u, parseLinearStops as d, parseSteps as f, prepareInterpVar as p, steppedEase as m, timingFunctions as h, unflattenObjectToString as g } from "@mkbabb/value.js";
3
3
  //#region src/animation/utils.ts
4
4
  var _ = /* @__PURE__ */ e({
5
- calcFrameTime: () => j,
6
- createInterpVarValue: () => A,
7
- getTimingFunction: () => D,
8
- parseAndFlattenObject: () => k,
9
- transformTargetsStyle: () => N
10
- }), v = /* @__PURE__ */ new WeakMap(), y = (e) => v.get(e), b = (e, t) => (t !== void 0 && v.set(e, t), e), x = (e, t) => {
11
- if (e instanceof i) return [b(e.clone(), t ?? y(e))];
12
- if (e instanceof n) return e.values.flatMap((t) => x(t, e.name));
13
- if (e instanceof r) return e.flatMap((e) => x(e, t));
5
+ calcFrameTime: () => k,
6
+ createInterpVarValue: () => O,
7
+ getTimingFunction: () => T,
8
+ parseAndFlattenObject: () => D,
9
+ transformTargetsStyle: () => j
10
+ }), v = (e) => e.fnName, y = (e, t) => {
11
+ if (e instanceof i) {
12
+ let n = e.clone();
13
+ return t !== void 0 && (n.fnName = t), [n];
14
+ }
15
+ if (e instanceof n) return e.values.flatMap((t) => y(t, e.name));
16
+ if (e instanceof r) return e.flatMap((e) => y(e, t));
14
17
  throw TypeError(`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof e}`);
15
- }, S = (e) => {
18
+ }, b = (e) => {
16
19
  let t = e.split(".").pop(), n = e.split(".").shift();
17
20
  if (!t || !n) throw Error(`Invalid flattened key: ${e}`);
18
21
  return {
19
22
  mainKey: n,
20
23
  childKey: t
21
24
  };
22
- }, C = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), w = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, T = /^\s*steps\s*\(/i, E = /^\s*linear\s*\(/i, D = (e) => {
25
+ }, x = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), S = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, C = /^\s*steps\s*\(/i, w = /^\s*linear\s*\(/i, T = (e) => {
23
26
  if (e == null) return;
24
27
  if (typeof e != "string") return e;
25
- let n = e.match(w);
28
+ let n = e.match(S);
26
29
  if (n) {
27
30
  let e = n.slice(1, 5).map((e) => Number.parseFloat(e ?? ""));
28
31
  if (e.length === 4 && e.every((e) => Number.isFinite(e))) {
@@ -30,29 +33,29 @@ var _ = /* @__PURE__ */ e({
30
33
  return t(n, r, i, a);
31
34
  }
32
35
  }
33
- if (T.test(e)) try {
36
+ if (C.test(e)) try {
34
37
  let { count: t, jumpTerm: n } = f(e);
35
38
  return m(t, n);
36
39
  } catch {}
37
40
  if (e === "step-start") return m(1, "jump-start");
38
41
  if (e === "step-end") return m(1, "jump-end");
39
- if (E.test(e)) try {
42
+ if (w.test(e)) try {
40
43
  return a(d(e));
41
44
  } catch {}
42
45
  let r = h[e];
43
46
  if (typeof r == "function" && r.length <= 1) return r;
44
- }, O = c((e, t) => x(u(t, { subProperty: e })), {
47
+ }, E = c((e, t) => y(u(t, { subProperty: e })), {
45
48
  maxCacheSize: 2048,
46
49
  keyFn: (e, t) => `${e}:${t}`
47
50
  });
48
- function k(e) {
51
+ function D(e) {
49
52
  let t = o(e), a = (e, t) => {
50
- let { childKey: o, mainKey: s } = S(e);
51
- return t instanceof i ? C(new r(...x(t)), s, o) : t instanceof n ? C(new r(...t.values.flatMap((n) => x(a(e, n), t.name))), s, o) : t instanceof r ? C(new r(...t.flatMap((t) => x(a(e, t)))), s, o) : C(new r(...O(o, String(t)).map((e) => b(e.clone(), y(e)))), s, o);
53
+ let { childKey: o, mainKey: s } = b(e);
54
+ return t instanceof i ? x(new r(...y(t)), s, o) : t instanceof n ? x(new r(...t.values.flatMap((n) => y(a(e, n), t.name))), s, o) : t instanceof r ? x(new r(...t.flatMap((t) => y(a(e, t)))), s, o) : x(new r(...E(o, String(t)).map((e) => e.clone())), s, o);
52
55
  };
53
56
  return Object.entries(t).reduce((e, [t, n]) => (e[t] = a(t, n), e), {});
54
57
  }
55
- var A = (e, t, n, r, a = "oklab", o) => {
58
+ var O = (e, t, n, r, a = "oklab", o) => {
56
59
  let c = r[t], u = r[n];
57
60
  if (!c || !u) throw Error(`Invalid interpolation frame bounds (${t} -> ${n}).`);
58
61
  let d = c[e], f = u[e];
@@ -63,7 +66,7 @@ var A = (e, t, n, r, a = "oklab", o) => {
63
66
  return t;
64
67
  });
65
68
  for (; r.length < m;) {
66
- let e = n[r.length], t = e instanceof i ? y(e) : void 0, a = t ? s(t) : void 0;
69
+ let e = n[r.length], t = e instanceof i ? v(e) : void 0, a = t ? s(t) : void 0;
67
70
  r.push(a ?? new i(0));
68
71
  }
69
72
  return r;
@@ -76,17 +79,17 @@ var A = (e, t, n, r, a = "oklab", o) => {
76
79
  return o !== void 0 && (s.hueMethod = o), p(l(t, r, s));
77
80
  });
78
81
  };
79
- function j(e, t, n) {
82
+ function k(e, t, n) {
80
83
  let [r, i] = [e.start, t.start];
81
84
  return {
82
85
  start: r.value * n / 100,
83
86
  stop: i.value * n / 100
84
87
  };
85
88
  }
86
- var M = {};
87
- function N(e, t, n = !0) {
89
+ var A = {};
90
+ function j(e, t, n = !0) {
88
91
  e = n ? e : o(e);
89
- let r = g(e, M);
92
+ let r = g(e, A);
90
93
  t.forEach((e) => {
91
94
  Object.entries(r).forEach(([t, n]) => {
92
95
  e.style.setProperty(t, n);
@@ -94,4 +97,4 @@ function N(e, t, n = !0) {
94
97
  });
95
98
  }
96
99
  //#endregion
97
- export { N as a, k as i, A as n, _ as o, D as r, j as t };
100
+ export { j as a, D as i, O as n, _ as o, T as r, k as t };
@@ -1,6 +1,6 @@
1
- import { n as e } from "./waapi-D9MHMm_9.js";
2
- import { CSSKeyframesAnimation as t } from "./engine-CNHvTgpw.js";
3
- import { compileToCSS as n } from "./compile-DgNRG6Lo.js";
1
+ import { n as e } from "./waapi-D0ssxKy1.js";
2
+ import { CSSKeyframesAnimation as t } from "./engine-DQcb7CLW.js";
3
+ import { compileToCSS as n } from "./compile-YRJRdpKF.js";
4
4
  import { extractKeyframes as r, parseCSSStylesheet as i } from "@mkbabb/value.js";
5
5
  //#region src/animation/validate.ts
6
6
  var a = (e) => new t().fromString(e);
@@ -1,7 +1,73 @@
1
- import { f as e, i as t } from "./timeline-B7SV3T_E.js";
1
+ import { f as e, i as t } from "./timeline-vY3eD3Ax.js";
2
2
  import { COMPUTED_UNITS as n, unflattenObjectToString as r } from "@mkbabb/value.js";
3
+ var i = .005, a = (e, t) => {
4
+ let n = /* @__PURE__ */ new Map(), r = e.interpFrames(t, !1);
5
+ for (let e in r) {
6
+ let t = r[e];
7
+ if (t !== void 0) for (let r = 0; r < t.length; r++) {
8
+ let i = t[r]?.value;
9
+ typeof i == "number" && Number.isFinite(i) && n.set(t.length > 1 ? `${e}.${r}` : e, i);
10
+ }
11
+ }
12
+ return n;
13
+ }, o = 64, s = (e, t, n) => {
14
+ let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = n - t;
15
+ for (let n = 0; n <= o; n++) {
16
+ let c = a(e, t + s * n / o);
17
+ for (let [e, t] of c) {
18
+ let n = r.get(e), a = i.get(e);
19
+ (n === void 0 || t < n) && r.set(e, t), (a === void 0 || t > a) && i.set(e, t);
20
+ }
21
+ }
22
+ let c = /* @__PURE__ */ new Map();
23
+ for (let [e, t] of r) c.set(e, (i.get(e) ?? t) - t);
24
+ return c;
25
+ }, c = (e, t, n, r, i, o) => {
26
+ let s = r - t, c = 0;
27
+ for (let r of [.25, .75]) {
28
+ let l = a(e, t + s * r);
29
+ for (let [e, t] of l) {
30
+ let a = n.get(e), s = i.get(e);
31
+ if (a === void 0 || s === void 0) continue;
32
+ let l = o.get(e);
33
+ if (l === void 0 || l === 0) continue;
34
+ let u = a + (s - a) * r, d = Math.abs(t - u) / l;
35
+ d > c && (c = d);
36
+ }
37
+ }
38
+ return c;
39
+ };
40
+ function l(e, t, n) {
41
+ let r = /* @__PURE__ */ new Set();
42
+ if (n <= 0) return r;
43
+ for (let n = 1; n < t.length; n++) {
44
+ let o = t[n - 1], l = t[n];
45
+ if (l - o <= 0) continue;
46
+ let u = s(e, o, l), d = a(e, o), f = a(e, l), p = (t, n, r, i) => ({
47
+ a: t,
48
+ sampleA: n,
49
+ b: r,
50
+ sampleB: i,
51
+ error: c(e, t, n, r, i, u)
52
+ }), m = [p(o, d, l, f)], h = 16;
53
+ for (; h > 0;) {
54
+ let t = -1, n = i;
55
+ for (let e = 0; e < m.length; e++) m[e].error > n && (n = m[e].error, t = e);
56
+ if (t === -1) break;
57
+ let o = m[t], s = (o.a + o.b) / 2;
58
+ if (s <= o.a || s >= o.b) {
59
+ m.splice(t, 1);
60
+ continue;
61
+ }
62
+ let c = a(e, s);
63
+ r.add(s), h--, m.splice(t, 1, p(o.a, o.sampleA, s, c), p(s, c, o.b, o.sampleB));
64
+ }
65
+ }
66
+ return r;
67
+ }
68
+ //#endregion
3
69
  //#region src/animation/waapi.ts
4
- var i = new Set([
70
+ var u = new Set([
5
71
  ...n,
6
72
  "%",
7
73
  "vh",
@@ -34,8 +100,8 @@ var i = new Set([
34
100
  "cqb",
35
101
  "cqmin",
36
102
  "cqmax"
37
- ]), a = (e) => typeof e == "string" && i.has(e), o = new Set(["offset-distance"]), s = (e) => o.has(e) || o.has(e.split(".").pop() ?? e), c = () => typeof globalThis.webkitConvertPointFromNodeToPage == "function";
38
- function l(e) {
103
+ ]), d = (e) => typeof e == "string" && u.has(e), f = new Set(["offset-distance"]), p = (e) => f.has(e) || f.has(e.split(".").pop() ?? e), m = () => typeof globalThis.webkitConvertPointFromNodeToPage == "function";
104
+ function h(e) {
39
105
  if (!e.targets || e.targets.length === 0) return {
40
106
  eligible: !1,
41
107
  reason: "no DOM targets"
@@ -63,14 +129,14 @@ function l(e) {
63
129
  eligible: !1,
64
130
  reason: "easing has no faithful CSS twin (would run bare linear on the compositor)"
65
131
  };
66
- if (t?.css?.startsWith("linear(") && c()) return {
132
+ if (t?.css?.startsWith("linear(") && m()) return {
67
133
  eligible: !1,
68
134
  reason: "WebKit refuses HW-accel for linear() easing — the spring twin stays on the rAF path (CE-1.0)"
69
135
  };
70
136
  for (let t of e.frames) for (let [e, n] of Object.entries(t.interpVars)) {
71
- let t = s(e);
137
+ let t = p(e);
72
138
  for (let e of n) {
73
- let n = a(e.start?.unit) && !(t && e.start?.unit === "%"), r = a(e.stop?.unit) && !(t && e.stop?.unit === "%");
139
+ let n = d(e.start?.unit) && !(t && e.start?.unit === "%"), r = d(e.stop?.unit) && !(t && e.stop?.unit === "%");
74
140
  if (n || r) return {
75
141
  eligible: !1,
76
142
  reason: `layout-dependent unit (${String(e.start?.unit ?? e.stop?.unit)}) would freeze to px under WAAPI`
@@ -83,15 +149,11 @@ function l(e) {
83
149
  }
84
150
  return { eligible: !0 };
85
151
  }
86
- var u = 8;
87
- function d(t) {
152
+ function g(t) {
88
153
  let n = t.options.duration, i = [], a = /* @__PURE__ */ new Set();
89
154
  for (let e of t.frames) a.add(e.time.start), a.add(e.time.stop);
90
155
  let o = [...a].sort((e, t) => e - t), s = new Set(o);
91
- if (n > 0) for (let e = 1; e < o.length; e++) {
92
- let t = o[e - 1], n = o[e] - t;
93
- if (!(n <= 0)) for (let e = 1; e <= u; e++) s.add(t + n * e / 9);
94
- }
156
+ for (let e of l(t, o, n)) s.add(e);
95
157
  for (let a of [...s].sort((e, t) => e - t)) {
96
158
  let o = t.interpFrames(a, !1);
97
159
  if (Object.keys(o).length === 0) continue;
@@ -103,32 +165,32 @@ function d(t) {
103
165
  }
104
166
  return i;
105
167
  }
106
- var f = {
168
+ var _ = {
107
169
  normal: "normal",
108
170
  reverse: "reverse",
109
171
  alternate: "alternate",
110
172
  "alternate-reverse": "alternate-reverse"
111
- }, p = {
173
+ }, v = {
112
174
  none: "none",
113
175
  forwards: "forwards",
114
176
  backwards: "backwards",
115
177
  both: "both"
116
- }, m = {
178
+ }, y = {
117
179
  replace: "replace",
118
180
  add: "add",
119
181
  accumulate: "accumulate"
120
- }, h = (e) => {
182
+ }, b = (e) => {
121
183
  for (let t of e.frames) {
122
184
  let e = t.composition;
123
- if (e != null && e !== "replace") return m[e] ?? "replace";
185
+ if (e != null && e !== "replace") return y[e] ?? "replace";
124
186
  }
125
187
  return "replace";
126
188
  };
127
- function g(e) {
128
- let t = e.options, n = f[t.direction], r = p[t.fillMode];
189
+ function x(e) {
190
+ let t = e.options, n = _[t.direction], r = v[t.fillMode];
129
191
  if (n == null) throw TypeError(`Unrecognised animation direction "${t.direction}".`);
130
192
  if (r == null) throw TypeError(`Unrecognised animation fill mode "${t.fillMode}".`);
131
- let i = (e.frames[0]?.timingFunction ?? e.options.timingFunction).css ?? "linear", a = h(e), o = {
193
+ let i = (e.frames[0]?.timingFunction ?? e.options.timingFunction).css ?? "linear", a = b(e), o = {
132
194
  duration: t.duration,
133
195
  delay: t.delay,
134
196
  iterations: t.iterationCount === Infinity ? Infinity : t.iterationCount,
@@ -138,8 +200,8 @@ function g(e) {
138
200
  };
139
201
  return a !== "replace" && (o.composite = a), o;
140
202
  }
141
- async function _(e) {
142
- let t = d(e), n = g(e), r = e.targets.map((e) => e.animate(t, n));
203
+ async function S(e) {
204
+ let t = g(e), n = x(e), r = e.targets.map((e) => e.animate(t, n));
143
205
  e._waAnimations = r, e.playback.loop(async (t) => {
144
206
  if (e.done) return !1;
145
207
  if (await e.advanceTo(t), e.paused) for (let e of r) e.pause();
@@ -155,8 +217,8 @@ async function _(e) {
155
217
  e.playback.stop(), e._waAnimations = [];
156
218
  }
157
219
  }
158
- function v(e, n) {
159
- let r = l(e);
220
+ function C(e, n) {
221
+ let r = h(e);
160
222
  if (!r.eligible) return {
161
223
  attached: !1,
162
224
  reason: r.reason
@@ -166,8 +228,8 @@ function v(e, n) {
166
228
  attached: !1,
167
229
  reason: "native scroll/view timeline unavailable (feature absent)"
168
230
  };
169
- let a = d(e), o = {
170
- ...g(e),
231
+ let a = g(e), o = {
232
+ ...x(e),
171
233
  timeline: i
172
234
  }, s = e.targets.map((e) => e.animate(a, o));
173
235
  return e._waAnimations = s, {
@@ -176,4 +238,4 @@ function v(e, n) {
176
238
  };
177
239
  }
178
240
  //#endregion
179
- export { l as n, _ as r, v as t };
241
+ export { h as n, S as r, C as t };