@mkbabb/keyframes.js 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { CSSKeyframesAnimation as e } from "./engine-Cj0T6OIH.js";
2
- import { fromMotionPath as t } from "./motion-path-683GcEZK.js";
1
+ import { CSSKeyframesAnimation as e } from "./engine-BKm1GcJT.js";
2
+ import { fromMotionPath as t } from "./motion-path-CqmlG74k.js";
3
3
  //#region src/animation/animate.ts
4
4
  var n = (e) => typeof e == "object" && !!e && !Array.isArray(e) && !(e instanceof Map) && typeof e.path == "string", r = (e) => e instanceof Map || typeof e == "object" && !!e && !Array.isArray(e);
5
5
  function i(i, a, o) {
@@ -1,5 +1,5 @@
1
- import { t as e } from "./springTimingFunction-cMJnhbug.js";
2
- import { CSSKeyframesAnimation as t } from "./engine-Cj0T6OIH.js";
1
+ import { t as e } from "./springTimingFunction-CcJEvGwN.js";
2
+ import { CSSKeyframesAnimation as t } from "./engine-BKm1GcJT.js";
3
3
  import { CSSCubicBezier as n, steppedEase as r } from "@mkbabb/value.js";
4
4
  //#region src/animation/animations.ts
5
5
  var ee = "\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n", i = (e) => new t({
@@ -0,0 +1,13 @@
1
+ //#region src/animation/internal/binarySearch.ts
2
+ function e(e, t, n, r) {
3
+ let i = 0, a = e.length - 1;
4
+ for (; i <= a;) {
5
+ let o = i + a >> 1, s = e[o];
6
+ if (t < n(s)) a = o - 1;
7
+ else if (t > r(s)) i = o + 1;
8
+ else return o;
9
+ }
10
+ return -1;
11
+ }
12
+ //#endregion
13
+ export { e as t };
@@ -0,0 +1,249 @@
1
+ import { v as e } from "./timeline-BjcmprQ6.js";
2
+ import { t } from "./sequence-COn8zk5o.js";
3
+ import { AnimationGroup as n, getAnimationId as r } from "./engine-BKm1GcJT.js";
4
+ import { COLOR_SPACE_RANGES as i, camelCaseToHyphen as a, color2 as o, deltaEOK as s, formatCSS as c, normalizeColorUnit as l, reverseAnimationShorthand as u, sampleColorRamp as d, scale as f, timingFunctions as p, unflattenObjectToString as m } from "@mkbabb/value.js";
5
+ //#region src/animation/format.ts
6
+ function h(t) {
7
+ if (t.css !== void 0) return t.css;
8
+ let n = Object.entries(p).find(([e, n]) => n === t.fn)?.[0];
9
+ if (n === void 0) throw new e("timingFunction", t.fn, "a custom TimingFunction has no CSS animation-timing-function representation — attach a faithful Easing.css twin, or use a registry name / cubic-bezier() / linear() literal");
10
+ return a(n);
11
+ }
12
+ function g(e, t, n) {
13
+ let r = e.parsedVars[t] ?? {}, i = Object.entries(m(r)).map(([e, t]) => ` ${a(e)}: ${t};`), o = e.templateFrames[t], s = o.timingFunction ? h(o.timingFunction) : n;
14
+ return s !== n && i.push(` animation-timing-function: ${s};`), `{\n${i.join("\n").trim()}\n}`;
15
+ }
16
+ function _(e, t, n) {
17
+ let r = h(e.options.timingFunction), i = /* @__PURE__ */ new Map();
18
+ e.templateFrames.forEach((t, a) => {
19
+ let o = n?.get(a) ?? g(e, a, r), s = i.get(o);
20
+ s ? s.push(t.start) : i.set(o, [t.start]);
21
+ });
22
+ let a = "";
23
+ for (let [e, t] of i) a += `${t.join(", ")} ${e}\n`;
24
+ return `@keyframes ${t} {\n${a}}`;
25
+ }
26
+ function v(e, t) {
27
+ let n = {
28
+ name: t,
29
+ duration: e.duration,
30
+ timingFunction: h(e.timingFunction),
31
+ iterationCount: isFinite(e.iterationCount) ? e.iterationCount : Infinity,
32
+ direction: e.direction,
33
+ fillMode: e.fillMode
34
+ };
35
+ return e.delay > 0 && (n.delay = e.delay), u(n);
36
+ }
37
+ function y(e) {
38
+ return e === "replace" ? void 0 : `animation-composition: ${e};`;
39
+ }
40
+ //#endregion
41
+ //#region src/animation/compile-color.ts
42
+ var b = i.oklab.a.number.min, x = i.oklab.a.number.max, S = i.oklab.b.number.min, C = i.oklab.b.number.max, w = (e) => Math.round(e * 1e4) / 1e4, T = (e) => typeof e == "object" && !!e && e.unit === "color", E = (e) => l(e).value, D = (e) => {
43
+ let t = o(e, "oklab");
44
+ return [
45
+ t.l,
46
+ f(t.a, 0, 1, b, x),
47
+ f(t.b, 0, 1, S, C)
48
+ ];
49
+ }, O = (e) => {
50
+ let [t, n, r] = D(e);
51
+ return `oklab(${w(t)} ${w(n)} ${w(r)})`;
52
+ }, k = (e, t) => {
53
+ let [n, r, i] = D(e), [a, o, c] = D(t);
54
+ return s(n, r, i, a, o, c);
55
+ }, A = (e, t, n) => o({
56
+ colorSpace: "oklab",
57
+ l: e,
58
+ a: f(t, b, x, 0, 1),
59
+ b: f(n, S, C, 0, 1),
60
+ alpha: 1
61
+ }, "oklab"), j = (e, t) => {
62
+ let [n, r, i] = D(e), [a, o, s] = D(t);
63
+ return A((n + a) / 2, (r + o) / 2, (i + s) / 2);
64
+ }, M = (e) => {
65
+ let t = /([\d.]+)\s*%/.exec(e.toString());
66
+ return t ? parseFloat(t[1]) : 0;
67
+ }, N = (e, t, n) => {
68
+ let r = (e.parsedVars[t] ?? {})[n];
69
+ if (Array.isArray(r)) return r.find((e) => T(e));
70
+ };
71
+ function P(e, t, n, r) {
72
+ let i = [], a = /* @__PURE__ */ new Set();
73
+ for (let t = 0; t + 1 < e.templateFrames.length; t++) {
74
+ let n = e.parsedVars[t] ?? {};
75
+ for (let [r, o] of Object.entries(n)) {
76
+ if (a.has(r) || !Array.isArray(o) || !o.some((e) => T(e))) continue;
77
+ let n = N(e, t, r), s = N(e, t + 1, r);
78
+ n && s && n.toString() !== s.toString() && (i.push(r), a.add(r));
79
+ }
80
+ }
81
+ if (i.length === 0 || i.length > 1) return null;
82
+ let o = i[0], s = Math.max(3, n), c = o.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), l = e.options.colorSpace === "oklch" ? "oklch" : "oklab", u = e.options.hueMethod ? { hueMethod: e.options.hueMethod } : {}, f = [], p = 0;
83
+ for (let t = 0; t + 1 < e.templateFrames.length; t++) {
84
+ let n = N(e, t, o), r = N(e, t + 1, o);
85
+ if (!n || !r) continue;
86
+ let i = M(e.templateFrames[t].start), a = M(e.templateFrames[t + 1].start);
87
+ if (n.toString() === r.toString()) {
88
+ f.push({
89
+ pct: i,
90
+ css: n.toString()
91
+ });
92
+ continue;
93
+ }
94
+ let c = E(n), m = E(r), h = d(c, m, s, {
95
+ space: l,
96
+ ...u
97
+ });
98
+ for (let e = 0; e < h.length; e++) {
99
+ let t = e / (h.length - 1), n = i + (a - i) * t;
100
+ f.push({
101
+ pct: w(n),
102
+ css: O(h[e])
103
+ });
104
+ }
105
+ for (let e = 0; e + 1 < h.length; e++) {
106
+ let t = (e + .5) / (h.length - 1), n = d(c, m, 1024, {
107
+ space: l,
108
+ ...u
109
+ })[Math.round(t * 1023)], r = j(h[e], h[e + 1]);
110
+ p = Math.max(p, k(r, n));
111
+ }
112
+ }
113
+ let m = e.templateFrames.length - 1, h = N(e, m, o);
114
+ if (h) {
115
+ let t = M(e.templateFrames[m].start);
116
+ f[f.length - 1]?.pct !== t && f.push({
117
+ pct: t,
118
+ css: h.toString()
119
+ });
120
+ }
121
+ if (p > r) return {
122
+ refused: !0,
123
+ delta: p
124
+ };
125
+ let g = "";
126
+ for (let { pct: e, css: t } of f) g += `${e}% {\n ${c}: ${t};\n}\n`;
127
+ return { block: `@keyframes ${t} {\n${g}}` };
128
+ }
129
+ //#endregion
130
+ //#region src/animation/compile.ts
131
+ var F = .04, I = 16;
132
+ function L(e) {
133
+ let t = [];
134
+ for (let n of Object.keys(e.animations)) {
135
+ let i = e.animations[n], a = i.layer.blendMode, o = a === "weighted" || i.layer.weightSpring != null, s = a === "add" ? "add" : "replace";
136
+ t.push({
137
+ animation: i.animation,
138
+ name: B(r(i.animation)),
139
+ composition: s,
140
+ weighted: o,
141
+ delay: 0
142
+ });
143
+ }
144
+ return t;
145
+ }
146
+ function R(e) {
147
+ return e.entries.map((e) => ({
148
+ animation: e.animation,
149
+ name: B(r(e.animation)),
150
+ composition: "replace",
151
+ weighted: !1,
152
+ delay: e.at
153
+ }));
154
+ }
155
+ function z(e) {
156
+ return e.map((e, t) => {
157
+ let n = "animation" in e ? e.animation : e;
158
+ return {
159
+ animation: n,
160
+ name: B(r(n) || `anim-${t}`),
161
+ composition: "replace",
162
+ weighted: !1,
163
+ delay: 0
164
+ };
165
+ });
166
+ }
167
+ function B(e) {
168
+ let t = e.replace(/[^a-zA-Z0-9_-]/g, "-");
169
+ return /^[a-zA-Z_]/.test(t) ? t : `a${t}`;
170
+ }
171
+ var V = (e) => e % 1e3 == 0 ? `${e / 1e3}s` : `${e}ms`;
172
+ function H(e) {
173
+ for (let t = 0; t < e.templateFrames.length; t++) {
174
+ let n = e.parsedVars[t] ?? {};
175
+ for (let [e, t] of Object.entries(n)) if (!Array.isArray(t) || t.length === 0) return e;
176
+ }
177
+ }
178
+ function U(e, t, n) {
179
+ let { animation: r, name: i } = e;
180
+ if (e.weighted) return n.push({
181
+ name: i,
182
+ reason: "weighted-blend",
183
+ message: "weighted layer blend has no animation-composition equivalent (CSS composites replace/add/accumulate only); the weighted axis is kf's unique blend tier — the JS playback is the only faithful path"
184
+ }), null;
185
+ for (let e of r.frames) if (!r.usesDefaultRenderer(e.transform)) return n.push({
186
+ name: i,
187
+ reason: "custom-renderer",
188
+ message: "custom renderer (a transform closure, not the default DOM-style renderer) cannot be expressed as CSS — the JS playback is the only faithful path"
189
+ }), null;
190
+ let a = H(r);
191
+ if (a) return n.push({
192
+ name: i,
193
+ reason: "computed-unit-drift",
194
+ message: `computed-unit drift on "${a}" — the declared value cannot be re-emitted as a faithful authored string; the JS playback is the only faithful path`
195
+ }), null;
196
+ let o = P(r, i, t.densifyStops ?? 16, t.deltaEEpsilon ?? .04);
197
+ if (o && "refused" in o) return n.push({
198
+ name: i,
199
+ reason: "perceptual-oklab",
200
+ message: `perceptual oklab color track exceeds the densify ΔE-ε threshold (ΔE ${w(o.delta)} > ${t.deltaEEpsilon ?? .04}) — a faithful pure-CSS twin is not available; the JS playback is the only faithful path`
201
+ }), null;
202
+ let s = o && "block" in o ? o.block : _(r, i), c;
203
+ try {
204
+ c = v(r.options, i);
205
+ } catch {
206
+ return n.push({
207
+ name: i,
208
+ reason: "custom-renderer",
209
+ message: "easing has no faithful CSS timing-function twin (a custom closure cannot be CSS) — attach an Easing.css twin or use a registry name / cubic-bezier() / linear(); the JS playback is the only faithful path"
210
+ }), null;
211
+ }
212
+ let l = y(e.composition), u = l ? `\n ${l}` : "", d = e.delay > 0 ? `\n animation-delay: ${V(e.delay)};` : "";
213
+ return `${s}\n\n${`.${i} {\n animation: ${c};${u}${d}\n}`}`;
214
+ }
215
+ async function W(e, r = {}) {
216
+ let i = e instanceof n ? L(e) : e instanceof t ? R(e) : z(e), a = /* @__PURE__ */ new Map();
217
+ for (let e of i) {
218
+ let t = a.get(e.name) ?? 0;
219
+ a.set(e.name, t + 1), t > 0 && (e.name = `${e.name}-${t + 1}`);
220
+ }
221
+ r.staggerDelays && i.forEach((e, t) => {
222
+ let n = r.staggerDelays[t];
223
+ typeof n == "number" && n > 0 && (e.delay += n);
224
+ });
225
+ let o = [], s = [];
226
+ for (let e of i) {
227
+ let t = U(e, r, o);
228
+ t && s.push(t);
229
+ }
230
+ let l = o.length === 0;
231
+ if (s.length === 0) return {
232
+ css: "",
233
+ eligible: l,
234
+ refusals: o
235
+ };
236
+ let u = s.join("\n\n"), d;
237
+ try {
238
+ d = await c(u, r.printWidth);
239
+ } catch {
240
+ d = u;
241
+ }
242
+ return {
243
+ css: d,
244
+ eligible: l,
245
+ refusals: o
246
+ };
247
+ }
248
+ //#endregion
249
+ export { F as DEFAULT_DELTA_E_EPSILON, I as DEFAULT_DENSIFY_STOPS, W as compileToCSS };
@@ -0,0 +1,25 @@
1
+ //#region src/animation/decay.ts
2
+ var e = 5;
3
+ function t(t) {
4
+ let n = t.initial ?? 0, r = t.velocity, i = t.friction ?? e;
5
+ if (i <= 0) throw Error("decay() requires a friction coefficient > 0.");
6
+ let a = n + r / i;
7
+ return (e) => {
8
+ if (e <= 0) return {
9
+ value: n,
10
+ velocity: r
11
+ };
12
+ let t = Math.exp(-i * e);
13
+ return {
14
+ value: a - r / i * t,
15
+ velocity: r * t
16
+ };
17
+ };
18
+ }
19
+ function n(t) {
20
+ let n = t.friction ?? e;
21
+ if (n <= 0) throw Error("decayRest() requires a friction coefficient > 0.");
22
+ return (t.initial ?? 0) + t.velocity / n;
23
+ }
24
+ //#endregion
25
+ export { n, t };
@@ -1,4 +1,4 @@
1
- import { CSSKeyframesAnimation as e } from "./engine-Cj0T6OIH.js";
1
+ import { CSSKeyframesAnimation as e } from "./engine-BKm1GcJT.js";
2
2
  //#region src/animation/draw-svg.ts
3
3
  var t = (e) => {
4
4
  if (typeof e == "number") {