@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/LICENSE +1 -1
- package/README.md +10 -1
- package/dist/_redirects +1 -0
- package/dist/engine-DuAFoqZF.js +699 -0
- package/dist/keyframes.d.ts +543 -148
- package/dist/keyframes.js +501 -1530
- package/dist/leaves-Bu89334e.js +39 -0
- package/package.json +101 -93
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import { i as e, o as t, r as n, t as r } from "./leaves-Bu89334e.js";
|
|
2
|
+
import { COMPUTED_UNITS as i, CSSCubicBezier as a, CSSFunction as o, CSSValues as s, FunctionValue as c, ValueArray as l, ValueUnit as u, cancelAnimationFrame as d, clamp as f, convertToMs as p, easeInOutCubic as m, extractAnimationOptions as h, extractKeyframes as g, extractProperties as _, flattenObject as v, isObject as ee, lerpValue as y, normalizeValueUnits as b, parseCSSStylesheet as x, parseCSSTime as S, parseCSSValueUnit as C, prepareInterpVar as w, requestAnimationFrame as T, scale as te, seekPreviousValue as E, sleep as ne, timingFunctions as re, tryParse as ie, unflattenObject as ae, unflattenObjectToString as D } from "@mkbabb/value.js";
|
|
3
|
+
import { any as O } from "@mkbabb/parse-that";
|
|
4
|
+
//#region src/animation/adapter.ts
|
|
5
|
+
var k = (e) => {
|
|
6
|
+
let t = {};
|
|
7
|
+
for (let n of e.declarations) t[n.name] = n.value;
|
|
8
|
+
return t;
|
|
9
|
+
}, A = (e) => {
|
|
10
|
+
let t = [];
|
|
11
|
+
for (let n of e.selectors) n.kind === "percent" ? t.push(`${n.value}%`) : t.push(n.name);
|
|
12
|
+
return t;
|
|
13
|
+
}, j = (e) => {
|
|
14
|
+
let t = g(e);
|
|
15
|
+
for (let e of t.values()) if (e.length > 0) return e;
|
|
16
|
+
return [];
|
|
17
|
+
}, M = (e) => {
|
|
18
|
+
let t = e.trim();
|
|
19
|
+
return /@keyframes\b/i.test(t) || t.length === 0 ? e : `@keyframes anonymous {\n${t}\n}`;
|
|
20
|
+
}, N = (e) => {
|
|
21
|
+
let t = typeof e == "string" ? x(M(e)) : e, n = j(t), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
22
|
+
for (let e of n) {
|
|
23
|
+
let t = k(e);
|
|
24
|
+
for (let n of A(e)) {
|
|
25
|
+
let a = r.get(n);
|
|
26
|
+
r.set(n, {
|
|
27
|
+
...a ?? {},
|
|
28
|
+
...t
|
|
29
|
+
}), e.timingFunction != null && i.set(n, e.timingFunction);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
keyframes: r,
|
|
34
|
+
timingFunctions: i,
|
|
35
|
+
properties: _(t),
|
|
36
|
+
options: h(t)
|
|
37
|
+
};
|
|
38
|
+
}, P = [
|
|
39
|
+
"normal",
|
|
40
|
+
"reverse",
|
|
41
|
+
"alternate",
|
|
42
|
+
"alternate-reverse"
|
|
43
|
+
], F = [
|
|
44
|
+
"none",
|
|
45
|
+
"forwards",
|
|
46
|
+
"backwards",
|
|
47
|
+
"both"
|
|
48
|
+
], I = {
|
|
49
|
+
duration: 1e3,
|
|
50
|
+
delay: 0,
|
|
51
|
+
iterationCount: 1,
|
|
52
|
+
direction: "normal",
|
|
53
|
+
fillMode: "forwards",
|
|
54
|
+
timingFunction: m,
|
|
55
|
+
useWAAPI: !0,
|
|
56
|
+
colorSpace: "oklab"
|
|
57
|
+
}, L = {
|
|
58
|
+
zIndex: 0,
|
|
59
|
+
weight: 1,
|
|
60
|
+
blendMode: "replace",
|
|
61
|
+
enabled: !0
|
|
62
|
+
}, R = (e) => typeof e != "object" || !e ? !1 : "value" in e && typeof e.value == "number", z = class {
|
|
63
|
+
animations = {};
|
|
64
|
+
transform;
|
|
65
|
+
superKey;
|
|
66
|
+
paused = !1;
|
|
67
|
+
started = !1;
|
|
68
|
+
done = !1;
|
|
69
|
+
singleTarget = !0;
|
|
70
|
+
lastTickTime = 0;
|
|
71
|
+
handleId = void 0;
|
|
72
|
+
resolvePromise = null;
|
|
73
|
+
_boundDraw;
|
|
74
|
+
_entries = [];
|
|
75
|
+
_entriesDirty = !0;
|
|
76
|
+
constructor(...e) {
|
|
77
|
+
this._boundDraw = this.draw.bind(this);
|
|
78
|
+
let t = [];
|
|
79
|
+
for (let n of e) {
|
|
80
|
+
let e, r;
|
|
81
|
+
n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform == null && e.frames[0] != null && (this.transform = e.frames[0].transform);
|
|
82
|
+
let i = Q(e);
|
|
83
|
+
this.animations[i] = {
|
|
84
|
+
values: {},
|
|
85
|
+
animation: e,
|
|
86
|
+
layer: {
|
|
87
|
+
...L,
|
|
88
|
+
...r
|
|
89
|
+
}
|
|
90
|
+
}, e.managed = !0, t.push(e);
|
|
91
|
+
}
|
|
92
|
+
this.singleTarget = t.every((e) => e.targets[0] === t[0]?.targets[0]), this.invalidateEntries();
|
|
93
|
+
}
|
|
94
|
+
getEntries() {
|
|
95
|
+
return this._entriesDirty &&= (this._entries = Object.values(this.animations), this._entries.sort((e, t) => e.layer.zIndex - t.layer.zIndex), !1), this._entries;
|
|
96
|
+
}
|
|
97
|
+
invalidateEntries() {
|
|
98
|
+
this._entriesDirty = !0;
|
|
99
|
+
}
|
|
100
|
+
setSuperKey(e) {
|
|
101
|
+
this.superKey = e;
|
|
102
|
+
for (let t of this.getEntries()) t.animation.superKey = e;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
setTargets(...e) {
|
|
106
|
+
let t = this.getEntries();
|
|
107
|
+
for (let n of t) n.animation.setTargets(...e);
|
|
108
|
+
return this.singleTarget = t.every((e) => e.animation.targets[0] === t[0]?.animation.targets[0]), this;
|
|
109
|
+
}
|
|
110
|
+
onStart() {
|
|
111
|
+
return this.started = !0, this;
|
|
112
|
+
}
|
|
113
|
+
onEnd() {
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
transformFramesGrouped(e) {
|
|
117
|
+
let t = {}, r = this.getEntries(), i = !0;
|
|
118
|
+
for (let e of r) {
|
|
119
|
+
let { animation: r, layer: a, values: o } = e;
|
|
120
|
+
if (i &&= r.done, !a.enabled) continue;
|
|
121
|
+
r.interpFrames(r.t, !1, o);
|
|
122
|
+
let s = a.properties ? Object.fromEntries(Object.entries(o).filter(([e]) => a.properties.has(e))) : o;
|
|
123
|
+
switch (a.blendMode) {
|
|
124
|
+
case "replace":
|
|
125
|
+
Object.assign(t, s);
|
|
126
|
+
break;
|
|
127
|
+
case "add":
|
|
128
|
+
for (let [e, n] of Object.entries(s)) if (e in t) {
|
|
129
|
+
let r = t[e], i = n;
|
|
130
|
+
R(r) && R(i) ? r.value += i.value : t[e] = n;
|
|
131
|
+
} else t[e] = n;
|
|
132
|
+
break;
|
|
133
|
+
case "weighted":
|
|
134
|
+
for (let [e, r] of Object.entries(s)) if (e in t) {
|
|
135
|
+
let i = t[e], o = r;
|
|
136
|
+
R(i) && R(o) ? i.value = n(i.value, o.value, a.weight) : t[e] = r;
|
|
137
|
+
} else t[e] = r;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return this.done = i, this.transform(t, e), t;
|
|
142
|
+
}
|
|
143
|
+
render() {
|
|
144
|
+
let e = this.lastTickTime || performance.now();
|
|
145
|
+
if (this.singleTarget) this.transformFramesGrouped(e);
|
|
146
|
+
else for (let e of this.getEntries()) e.animation.interpFrames(e.animation.t, !0);
|
|
147
|
+
}
|
|
148
|
+
setChildTime(e, t) {
|
|
149
|
+
let n = typeof e == "string" ? e : Q(e), r = this.animations[n];
|
|
150
|
+
if (!r) throw Error(`AnimationGroup.setChildTime: no animation registered for key "${n}". Known keys: ${Object.keys(this.animations).join(", ") || "(none)"}.`);
|
|
151
|
+
let i = r.animation;
|
|
152
|
+
return i.t = t, i.startTime !== void 0 && (i.pausedTime = i.startTime + t), this;
|
|
153
|
+
}
|
|
154
|
+
async tick(e) {
|
|
155
|
+
this.lastTickTime = e, this.started || this.onStart();
|
|
156
|
+
let t = [];
|
|
157
|
+
for (let n of this.getEntries()) {
|
|
158
|
+
let r = n.animation;
|
|
159
|
+
(!r.paused || r.pausedTime === 0) && t.push(r.tick(e));
|
|
160
|
+
}
|
|
161
|
+
return await Promise.all(t), this.done && this.onEnd(), this;
|
|
162
|
+
}
|
|
163
|
+
async draw(t) {
|
|
164
|
+
if (await this.tick(t), !this.paused) {
|
|
165
|
+
if (this.singleTarget) this.transformFramesGrouped(t);
|
|
166
|
+
else {
|
|
167
|
+
let e = !0;
|
|
168
|
+
for (let t of this.getEntries()) t.animation.interpFrames(t.animation.t, !0), e &&= t.animation.done;
|
|
169
|
+
this.done = e;
|
|
170
|
+
}
|
|
171
|
+
this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = e(this._boundDraw);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async play() {
|
|
175
|
+
return new Promise((t) => {
|
|
176
|
+
this.resolvePromise = t, this.handleId = e(this._boundDraw);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
pause() {
|
|
180
|
+
if (!this.started) return this;
|
|
181
|
+
this.paused = !this.paused;
|
|
182
|
+
let t = this.lastTickTime || performance.now();
|
|
183
|
+
for (let e of this.getEntries()) {
|
|
184
|
+
let n = e.animation;
|
|
185
|
+
this.paused ? (n.pause(!1), n.pausedTime === 0 && (n.pausedTime = t)) : n.paused = !1;
|
|
186
|
+
}
|
|
187
|
+
return this.paused ? (r(this.handleId), this.handleId = void 0, this.render()) : this.handleId = e(this._boundDraw), this;
|
|
188
|
+
}
|
|
189
|
+
reset() {
|
|
190
|
+
for (let e of this.getEntries()) {
|
|
191
|
+
let t = e.animation;
|
|
192
|
+
t.started && t.frames.length > 0 && t.interpFrames(0, !0), t.managed = !1, t.reset();
|
|
193
|
+
}
|
|
194
|
+
return this.started = !1, this.done = !1, this.paused = !1, this.lastTickTime = 0, this;
|
|
195
|
+
}
|
|
196
|
+
stop() {
|
|
197
|
+
return r(this.handleId), this.handleId = void 0, this.reset(), this;
|
|
198
|
+
}
|
|
199
|
+
playing() {
|
|
200
|
+
return !(!this.started || this.paused);
|
|
201
|
+
}
|
|
202
|
+
forcePause() {
|
|
203
|
+
this.paused = !0;
|
|
204
|
+
for (let e of this.getEntries()) e.animation.paused = !0;
|
|
205
|
+
}
|
|
206
|
+
forcePlay() {
|
|
207
|
+
this.paused = !1;
|
|
208
|
+
for (let e of this.getEntries()) e.animation.paused = !1;
|
|
209
|
+
}
|
|
210
|
+
setLayerConfig(e, t) {
|
|
211
|
+
let n = typeof e == "string" ? e : Q(e), r = this.animations[n];
|
|
212
|
+
if (!r) throw Error(`AnimationGroup.setLayerConfig: no animation registered for key "${n}". Known keys: ${Object.keys(this.animations).join(", ") || "(none)"}.`);
|
|
213
|
+
return Object.assign(r.layer, t), this.invalidateEntries(), this;
|
|
214
|
+
}
|
|
215
|
+
setLayerEnabled(e, t) {
|
|
216
|
+
return this.setLayerConfig(e, { enabled: t });
|
|
217
|
+
}
|
|
218
|
+
getLayerConfig(e) {
|
|
219
|
+
let t = typeof e == "string" ? e : Q(e);
|
|
220
|
+
return this.animations[t]?.layer;
|
|
221
|
+
}
|
|
222
|
+
}, B = (e) => {
|
|
223
|
+
if (e instanceof u) return [e.clone()];
|
|
224
|
+
if (e instanceof c) return e.values.flatMap((e) => B(e));
|
|
225
|
+
if (e instanceof l) return e.flatMap((e) => B(e));
|
|
226
|
+
throw TypeError(`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof e}`);
|
|
227
|
+
}, V = (e) => {
|
|
228
|
+
let t = e.split(".").pop(), n = e.split(".").shift();
|
|
229
|
+
if (!t || !n) throw Error(`Invalid flattened key: ${e}`);
|
|
230
|
+
return {
|
|
231
|
+
mainKey: n,
|
|
232
|
+
childKey: t
|
|
233
|
+
};
|
|
234
|
+
}, H = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), U = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, W = (e) => {
|
|
235
|
+
if (e == null) return;
|
|
236
|
+
if (typeof e != "string") return e;
|
|
237
|
+
let t = e.match(U);
|
|
238
|
+
if (t) {
|
|
239
|
+
let e = t.slice(1, 5).map((e) => Number.parseFloat(e ?? ""));
|
|
240
|
+
if (e.length === 4 && e.every((e) => Number.isFinite(e))) {
|
|
241
|
+
let [t, n, r, i] = e;
|
|
242
|
+
return a(t, n, r, i);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
let n = re[e];
|
|
246
|
+
if (typeof n == "function" && n.length <= 1) return n;
|
|
247
|
+
}, G = /* @__PURE__ */ new Map();
|
|
248
|
+
function K(e) {
|
|
249
|
+
let t = v(e), n = (e, t) => {
|
|
250
|
+
let { childKey: r, mainKey: i } = V(e);
|
|
251
|
+
if (t instanceof u) return H(new l(...B(t)), i, r);
|
|
252
|
+
if (t instanceof c) return H(new l(...t.values.flatMap((t) => B(n(e, t)))), i, r);
|
|
253
|
+
if (t instanceof l) return H(new l(...t.flatMap((t) => B(n(e, t)))), i, r);
|
|
254
|
+
let a = String(t), d = `${r}:${a}`, f = G.get(d);
|
|
255
|
+
if (f) return H(f.clone(), i, r);
|
|
256
|
+
let p = H(new l(...B(ie(O(o.FunctionArgs.map((e) => (e.setSubProperty(r), e)), s.Value), a))), i, r);
|
|
257
|
+
return G.set(d, p.clone()), p;
|
|
258
|
+
};
|
|
259
|
+
return Object.entries(t).reduce((e, [t, r]) => (e[t] = n(t, r), e), {});
|
|
260
|
+
}
|
|
261
|
+
var q = (e, t, n, r, i = "oklab", a) => {
|
|
262
|
+
let o = r[t], s = r[n];
|
|
263
|
+
if (!o || !s) throw Error(`Invalid interpolation frame bounds (${t} -> ${n}).`);
|
|
264
|
+
let c = o[e], l = s[e];
|
|
265
|
+
if (!c || !l) throw Error(`Missing variable "${e}" in interpolation bounds.`);
|
|
266
|
+
let d = Math.max(c.length, l.length), f = (t) => {
|
|
267
|
+
let n = t.map((t) => {
|
|
268
|
+
if (!(t instanceof u)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
269
|
+
return t;
|
|
270
|
+
});
|
|
271
|
+
for (; n.length < d;) n.push(new u(0));
|
|
272
|
+
return n;
|
|
273
|
+
}, p = f(c), m = f(l);
|
|
274
|
+
return p.map((t, n) => {
|
|
275
|
+
let r = m[n];
|
|
276
|
+
if (!r) throw Error(`Missing right-hand interpolation value at index ${n}.`);
|
|
277
|
+
if (!(t instanceof u) || !(r instanceof u)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
278
|
+
let o = { colorSpace: i };
|
|
279
|
+
return a !== void 0 && (o.hueMethod = a), w(b(t, r, o));
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
function J(e, t, n) {
|
|
283
|
+
let [r, i] = [e.start, t.start];
|
|
284
|
+
return {
|
|
285
|
+
start: r.value * n / 100,
|
|
286
|
+
stop: i.value * n / 100
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function Y(e, t, n = !0) {
|
|
290
|
+
e = n ? e : v(e);
|
|
291
|
+
let r = D(e);
|
|
292
|
+
t.forEach((e) => {
|
|
293
|
+
Object.entries(r).forEach(([t, n]) => {
|
|
294
|
+
e.style.setProperty(t, n);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
Y[Symbol.for("keyframes.defaultRenderer")] = !0;
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/animation/waapi.ts
|
|
301
|
+
var X = (e) => typeof e == "string" && i.includes(e), oe = Symbol.for("keyframes.defaultRenderer"), se = (e) => typeof e == "function" && e[oe] === !0;
|
|
302
|
+
function ce(e) {
|
|
303
|
+
if (!e.targets || e.targets.length === 0) return {
|
|
304
|
+
eligible: !1,
|
|
305
|
+
reason: "no DOM targets"
|
|
306
|
+
};
|
|
307
|
+
if (typeof e.targets[0]?.animate != "function") return {
|
|
308
|
+
eligible: !1,
|
|
309
|
+
reason: "target does not implement Element.animate()"
|
|
310
|
+
};
|
|
311
|
+
for (let t of e.frames) if (!se(t.transform)) return {
|
|
312
|
+
eligible: !1,
|
|
313
|
+
reason: "custom transform function (not the default DOM renderer)"
|
|
314
|
+
};
|
|
315
|
+
if (e.frames.length > 1) {
|
|
316
|
+
let t = e.frames[0].timingFunction;
|
|
317
|
+
for (let n = 1; n < e.frames.length; n++) if (e.frames[n].timingFunction !== t) return {
|
|
318
|
+
eligible: !1,
|
|
319
|
+
reason: "non-uniform per-frame timing function (WAAPI supports one easing per animation)"
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
for (let t of e.frames) for (let e of Object.values(t.interpVars)) for (let t of e) {
|
|
323
|
+
if (X(t.start?.unit) || X(t.stop?.unit)) return {
|
|
324
|
+
eligible: !1,
|
|
325
|
+
reason: `computed unit (${String(t.start?.unit ?? t.stop?.unit)}) requires DOM resolution`
|
|
326
|
+
};
|
|
327
|
+
if (t.start?.unit === "color" || t.stop?.unit === "color") return {
|
|
328
|
+
eligible: !1,
|
|
329
|
+
reason: "color interpolation requires perceptual lerp"
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
return { eligible: !0 };
|
|
333
|
+
}
|
|
334
|
+
function le(e) {
|
|
335
|
+
let t = e.options.duration, n = [], r = /* @__PURE__ */ new Set();
|
|
336
|
+
for (let t of e.frames) r.add(t.time.start), r.add(t.time.stop);
|
|
337
|
+
let i = [...r].sort((e, t) => e - t);
|
|
338
|
+
for (let r of i) {
|
|
339
|
+
let i = e.interpFrames(r, !1);
|
|
340
|
+
if (Object.keys(i).length === 0) continue;
|
|
341
|
+
let a = D(i);
|
|
342
|
+
n.push({
|
|
343
|
+
offset: Math.max(0, Math.min(1, r / t)),
|
|
344
|
+
...a
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
return n;
|
|
348
|
+
}
|
|
349
|
+
var ue = {
|
|
350
|
+
normal: "normal",
|
|
351
|
+
reverse: "reverse",
|
|
352
|
+
alternate: "alternate",
|
|
353
|
+
"alternate-reverse": "alternate-reverse"
|
|
354
|
+
}, de = {
|
|
355
|
+
none: "none",
|
|
356
|
+
forwards: "forwards",
|
|
357
|
+
backwards: "backwards",
|
|
358
|
+
both: "both"
|
|
359
|
+
};
|
|
360
|
+
function Z(e) {
|
|
361
|
+
let t = e.options, n = ue[t.direction], r = de[t.fillMode];
|
|
362
|
+
if (n == null) throw TypeError(`Unrecognised animation direction "${t.direction}".`);
|
|
363
|
+
if (r == null) throw TypeError(`Unrecognised animation fill mode "${t.fillMode}".`);
|
|
364
|
+
return {
|
|
365
|
+
duration: t.duration,
|
|
366
|
+
delay: t.delay,
|
|
367
|
+
iterations: t.iterationCount === Infinity ? Infinity : t.iterationCount,
|
|
368
|
+
direction: n,
|
|
369
|
+
fill: r,
|
|
370
|
+
easing: "linear"
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
async function fe(e) {
|
|
374
|
+
let t = le(e), n = Z(e), r = e.targets.map((e) => e.animate(t, n)), i = !1, a = (t) => {
|
|
375
|
+
if (!(i || e.done)) {
|
|
376
|
+
if (e.tick(t), e.paused) for (let e of r) e.pause();
|
|
377
|
+
else for (let e of r) e.playState === "paused" && e.play();
|
|
378
|
+
e.handleId = requestAnimationFrame(a);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
e.handleId = requestAnimationFrame(a);
|
|
382
|
+
try {
|
|
383
|
+
await Promise.all(r.map((e) => e.finished));
|
|
384
|
+
} finally {
|
|
385
|
+
i = !0;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/animation/engine.ts
|
|
390
|
+
var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function", Q = (e) => typeof e == "string" ? e : e.name ?? String(e.id), me = 0, $ = class {
|
|
391
|
+
id = me++;
|
|
392
|
+
name;
|
|
393
|
+
superKey;
|
|
394
|
+
targets;
|
|
395
|
+
options;
|
|
396
|
+
templateFrames = [];
|
|
397
|
+
parsedVars = [];
|
|
398
|
+
frameId = 0;
|
|
399
|
+
frames = [];
|
|
400
|
+
handleId = void 0;
|
|
401
|
+
startTime = void 0;
|
|
402
|
+
pausedTime = 0;
|
|
403
|
+
t = 0;
|
|
404
|
+
iteration = 0;
|
|
405
|
+
started = !1;
|
|
406
|
+
done = !1;
|
|
407
|
+
reversed = !1;
|
|
408
|
+
paused = !1;
|
|
409
|
+
managed = !1;
|
|
410
|
+
waapiIneligibleReason = void 0;
|
|
411
|
+
unflatten = !0;
|
|
412
|
+
resolvePromise = null;
|
|
413
|
+
_playingPromise = null;
|
|
414
|
+
_boundDraw = this.draw.bind(this);
|
|
415
|
+
dispatchAnimationEvent(e) {
|
|
416
|
+
if (!(typeof AnimationEvent > "u")) for (let t of this.targets) typeof t?.dispatchEvent == "function" && t.dispatchEvent(new AnimationEvent(e, {
|
|
417
|
+
animationName: this.name ?? "",
|
|
418
|
+
elapsedTime: this.t / 1e3
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
constructor(e, t, n, r) {
|
|
422
|
+
this.options = {}, this.setOptions({
|
|
423
|
+
...I,
|
|
424
|
+
...e ?? {}
|
|
425
|
+
}), this.targets = t == null ? [] : Array.isArray(t) ? t : [t], this.name = n, this.superKey = r;
|
|
426
|
+
}
|
|
427
|
+
convertFrameStart(e) {
|
|
428
|
+
if (e.start.unit === "s" || e.start.unit === "ms" || !e.start.unit) {
|
|
429
|
+
let t = e.start.unit === "s" ? "s" : "ms", n = p(e.start.value, t);
|
|
430
|
+
e.start.value = n / this.options.duration * 100, e.start.unit = "%";
|
|
431
|
+
}
|
|
432
|
+
return e.start.value = f(e.start.value, 0, 100), e;
|
|
433
|
+
}
|
|
434
|
+
addFrame(e, t, n, r) {
|
|
435
|
+
typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof u && (e = String(e));
|
|
436
|
+
let i = C(e), a = {
|
|
437
|
+
id: this.frameId,
|
|
438
|
+
start: i,
|
|
439
|
+
vars: t,
|
|
440
|
+
transform: n,
|
|
441
|
+
timingFunction: W(r) ?? this.options.timingFunction
|
|
442
|
+
};
|
|
443
|
+
return this.convertFrameStart(a), this.templateFrames.push(a), this.frameId += 1, this;
|
|
444
|
+
}
|
|
445
|
+
createFrame(e, t) {
|
|
446
|
+
let n = this.templateFrames[e], r = this.templateFrames[t], i = {
|
|
447
|
+
start: e,
|
|
448
|
+
stop: t
|
|
449
|
+
}, a = J(n, r, this.options.duration), o = n.transform;
|
|
450
|
+
if (o == null) {
|
|
451
|
+
let t = E(e, this.frames, (e) => e.transform != null);
|
|
452
|
+
o = this.frames[t].transform;
|
|
453
|
+
}
|
|
454
|
+
let s = n.timingFunction;
|
|
455
|
+
if (s == null) {
|
|
456
|
+
let t = E(e, this.frames, (e) => e.timingFunction != null);
|
|
457
|
+
s = this.frames[t].timingFunction;
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
id: this.frameId++,
|
|
461
|
+
ixs: i,
|
|
462
|
+
start: n.start,
|
|
463
|
+
time: a,
|
|
464
|
+
vars: void 0,
|
|
465
|
+
flatVars: void 0,
|
|
466
|
+
interpVars: {},
|
|
467
|
+
allInterpVars: [],
|
|
468
|
+
transform: o,
|
|
469
|
+
timingFunction: s
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
buildVarIndex() {
|
|
473
|
+
let e = /* @__PURE__ */ new Map();
|
|
474
|
+
for (let t = 0; t < this.parsedVars.length; t++) for (let n of Object.keys(this.parsedVars[t])) {
|
|
475
|
+
let r = e.get(n);
|
|
476
|
+
r || (r = [], e.set(n, r)), r.push(t);
|
|
477
|
+
}
|
|
478
|
+
return e;
|
|
479
|
+
}
|
|
480
|
+
reconcileVars(e, t) {
|
|
481
|
+
let n = this.parsedVars[e];
|
|
482
|
+
if (n) for (let r of Object.keys(n)) {
|
|
483
|
+
let n = t.get(r);
|
|
484
|
+
if (!n) continue;
|
|
485
|
+
let i = -1;
|
|
486
|
+
for (let t of n) if (t > e) {
|
|
487
|
+
i = t;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
if (i === -1) continue;
|
|
491
|
+
let [a, o] = [e, i], s = this.frames.findIndex((e) => e.ixs.start === a && e.ixs.stop === o), c = s === -1 ? this.createFrame(a, o) : this.frames[s];
|
|
492
|
+
c.interpVars[r] = q(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
parse() {
|
|
496
|
+
this.frames = [], this.templateFrames.sort((e, t) => e.start.value - t.start.value), this.parsedVars = this.templateFrames.map((e) => {
|
|
497
|
+
let t = K(e.vars);
|
|
498
|
+
return Object.values(t).forEach((e) => {
|
|
499
|
+
e.setTargets(this.targets);
|
|
500
|
+
}), t;
|
|
501
|
+
});
|
|
502
|
+
for (let e = 0; e < this.templateFrames.length - 1; e++) this.frames.push(this.createFrame(e, e + 1));
|
|
503
|
+
let e = this.buildVarIndex();
|
|
504
|
+
return this.frames.forEach((t, n) => this.reconcileVars(n, e)), this.frames.sort((e, t) => e.time.start === t.time.start ? e.time.stop - t.time.stop : e.time.start - t.time.start), this.frames = this.frames.filter((e) => e.interpVars != null && Object.keys(e.interpVars).length > 0), this.frames.forEach((e) => {
|
|
505
|
+
e.flatVars = Object.entries(e.interpVars).reduce((e, [t, n]) => (e[t] = n.map((e) => e.value), e), {}), e.vars = ae(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
|
|
506
|
+
}), this;
|
|
507
|
+
}
|
|
508
|
+
setTimingFunction(e) {
|
|
509
|
+
return this.options.timingFunction = W(e) ?? m, this;
|
|
510
|
+
}
|
|
511
|
+
setIterationCount(e) {
|
|
512
|
+
if (!e || e === "infinite" || e === "∞" || e === "Infinity") this.options.iterationCount = Infinity;
|
|
513
|
+
else if (typeof e == "string") {
|
|
514
|
+
let t = parseFloat(e.trim());
|
|
515
|
+
if (isNaN(t) || t < 0) return this;
|
|
516
|
+
this.options.iterationCount = t;
|
|
517
|
+
} else {
|
|
518
|
+
if (isNaN(e) || e < 0) return this;
|
|
519
|
+
this.options.iterationCount = e;
|
|
520
|
+
}
|
|
521
|
+
return this;
|
|
522
|
+
}
|
|
523
|
+
setDuration(e) {
|
|
524
|
+
typeof e == "string" && (e = S(e));
|
|
525
|
+
let t = e ?? this.options.duration;
|
|
526
|
+
if (!isFinite(t) || t <= 0) return this;
|
|
527
|
+
let n = t / this.options.duration;
|
|
528
|
+
for (let e = 0; e < this.frames.length; e++) {
|
|
529
|
+
let t = this.frames[e];
|
|
530
|
+
t.time.start *= n, t.time.stop *= n;
|
|
531
|
+
}
|
|
532
|
+
return this.options.duration = t, this;
|
|
533
|
+
}
|
|
534
|
+
setDelay(e) {
|
|
535
|
+
return typeof e == "string" && (e = S(e)), this.options.delay = e ?? 0, this;
|
|
536
|
+
}
|
|
537
|
+
setDirection(e) {
|
|
538
|
+
return this.options.direction = e ?? "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;
|
|
539
|
+
}
|
|
540
|
+
setFillMode(e) {
|
|
541
|
+
return this.options.fillMode = e ?? "forwards", this;
|
|
542
|
+
}
|
|
543
|
+
setUseWAAPI(e) {
|
|
544
|
+
return this.options.useWAAPI = e ?? !0, this;
|
|
545
|
+
}
|
|
546
|
+
setColorSpace(e) {
|
|
547
|
+
return this.options.colorSpace = e ?? "oklab", this;
|
|
548
|
+
}
|
|
549
|
+
setHueMethod(e) {
|
|
550
|
+
return e !== void 0 && (this.options.hueMethod = e), this;
|
|
551
|
+
}
|
|
552
|
+
setOptions(e) {
|
|
553
|
+
return this.setTimingFunction(e.timingFunction), this.setDuration(e.duration), this.setIterationCount(e.iterationCount), this.setDelay(e.delay), this.setDirection(e.direction), this.setFillMode(e.fillMode), this.setUseWAAPI(e.useWAAPI), this.setColorSpace(e.colorSpace), this.setHueMethod(e.hueMethod), this;
|
|
554
|
+
}
|
|
555
|
+
reverse() {
|
|
556
|
+
if (this.startTime !== void 0) {
|
|
557
|
+
let e = this.t, t = this.options.duration - 2 * e;
|
|
558
|
+
this.startTime -= t;
|
|
559
|
+
}
|
|
560
|
+
return this.reversed = !this.reversed, this;
|
|
561
|
+
}
|
|
562
|
+
fillForwards() {
|
|
563
|
+
this.interpFrames(this.options.duration, !0);
|
|
564
|
+
}
|
|
565
|
+
fillBackwards() {
|
|
566
|
+
this.interpFrames(0, !0);
|
|
567
|
+
}
|
|
568
|
+
at(e, t = !1) {
|
|
569
|
+
let n = this.reversed;
|
|
570
|
+
this.reversed = !1;
|
|
571
|
+
let r = f(e, 0, 1) * this.options.duration, i = this.interpFrames(r, t);
|
|
572
|
+
return this.reversed = n, i;
|
|
573
|
+
}
|
|
574
|
+
interpFrames(e, n = !1, r = {}) {
|
|
575
|
+
e = this.reversed ? this.options.duration - e : e;
|
|
576
|
+
let i = r;
|
|
577
|
+
for (let e in i) delete i[e];
|
|
578
|
+
let a = this.frames, o = a.length, s = t(a, e, (e) => e.time.start, (e) => e.time.stop);
|
|
579
|
+
if (s === -1) return i;
|
|
580
|
+
let c = (t) => {
|
|
581
|
+
let { start: r, stop: a } = t.time, o = te(e, r, a, 0, 1), s = t.timingFunction(o);
|
|
582
|
+
for (let e of t.allInterpVars) y(s, e);
|
|
583
|
+
n && t.transform(this.unflatten ? t.vars : t.flatVars, e), Object.assign(i, t.flatVars);
|
|
584
|
+
};
|
|
585
|
+
for (let t = s; t >= 0; t--) {
|
|
586
|
+
let n = a[t];
|
|
587
|
+
if (e < n.time.start || e > n.time.stop) break;
|
|
588
|
+
c(n);
|
|
589
|
+
}
|
|
590
|
+
for (let t = s + 1; t < o; t++) {
|
|
591
|
+
let n = a[t];
|
|
592
|
+
if (e < n.time.start || e > n.time.stop) break;
|
|
593
|
+
c(n);
|
|
594
|
+
}
|
|
595
|
+
return i;
|
|
596
|
+
}
|
|
597
|
+
async onStart() {
|
|
598
|
+
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 ne(this.options.delay), this.paused = !1), this.started = !0;
|
|
599
|
+
}
|
|
600
|
+
async onEnd() {
|
|
601
|
+
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"));
|
|
602
|
+
}
|
|
603
|
+
async tick(e) {
|
|
604
|
+
if (this.startTime === void 0 && (await this.onStart(), this.startTime = e + this.options.delay, this.dispatchAnimationEvent("animationstart")), this.paused && this.pausedTime === 0) return this.pausedTime = e, this.t;
|
|
605
|
+
if (this.pausedTime > 0 && !this.paused) {
|
|
606
|
+
let t = e - this.pausedTime;
|
|
607
|
+
this.startTime += t, this.pausedTime = 0;
|
|
608
|
+
}
|
|
609
|
+
return this.t = e - this.startTime, this.t >= this.options.duration && (await this.onEnd(), this.t = this.options.duration), this.t;
|
|
610
|
+
}
|
|
611
|
+
async draw(e) {
|
|
612
|
+
if (this.managed) throw Error("Animation.draw() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play()/pause()/stop() instead.");
|
|
613
|
+
e = await this.tick(e), !this.paused && (this.interpFrames(e, !0), this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = T(this._boundDraw));
|
|
614
|
+
}
|
|
615
|
+
_playRAF() {
|
|
616
|
+
return new Promise((e) => {
|
|
617
|
+
this.resolvePromise = e, this.handleId = T(this._boundDraw);
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
async _playWAAPI() {
|
|
621
|
+
await fe(this), this.reset();
|
|
622
|
+
}
|
|
623
|
+
async play() {
|
|
624
|
+
if (this.managed) throw Error("Animation.play() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play() instead.");
|
|
625
|
+
if (this._playingPromise) return this._playingPromise;
|
|
626
|
+
let e;
|
|
627
|
+
if (this.options.useWAAPI) {
|
|
628
|
+
let t = ce(this);
|
|
629
|
+
t.eligible ? (this.waapiIneligibleReason = void 0, e = this._playWAAPI()) : (this.waapiIneligibleReason = t.reason, e = this._playRAF());
|
|
630
|
+
} else this.waapiIneligibleReason = void 0, e = this._playRAF();
|
|
631
|
+
return this._playingPromise = e, e.finally(() => {
|
|
632
|
+
this._playingPromise = null;
|
|
633
|
+
}), e;
|
|
634
|
+
}
|
|
635
|
+
pause(e = !0) {
|
|
636
|
+
return this.paused && e ? this.resume() : (this.started && (this.paused = !0), this);
|
|
637
|
+
}
|
|
638
|
+
resume() {
|
|
639
|
+
return this.started && this.paused && (this.paused = !1, this.handleId = T(this._boundDraw)), this;
|
|
640
|
+
}
|
|
641
|
+
stop() {
|
|
642
|
+
d(this.handleId), this.reset();
|
|
643
|
+
}
|
|
644
|
+
playing() {
|
|
645
|
+
return !(!this.started || this.paused);
|
|
646
|
+
}
|
|
647
|
+
get effectiveT() {
|
|
648
|
+
return this.reversed ? this.options.duration - this.t : this.t;
|
|
649
|
+
}
|
|
650
|
+
reset() {
|
|
651
|
+
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;
|
|
652
|
+
}
|
|
653
|
+
setTargets(...e) {
|
|
654
|
+
return this.targets = e, this.frames.forEach((e) => {
|
|
655
|
+
Object.values(e.interpVars).forEach((e) => {
|
|
656
|
+
e.forEach(({ start: e, stop: t, value: n }) => {
|
|
657
|
+
e.setTargets(this.targets), t.setTargets(this.targets), n.setTargets(this.targets);
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
}), this;
|
|
661
|
+
}
|
|
662
|
+
group(...e) {
|
|
663
|
+
return new z(this, ...e);
|
|
664
|
+
}
|
|
665
|
+
}, he = class extends $ {
|
|
666
|
+
constructor(e, ...t) {
|
|
667
|
+
super(e, t), this.unflatten = !1;
|
|
668
|
+
}
|
|
669
|
+
fromVars(e, t) {
|
|
670
|
+
this.unflatten = t != null, t ??= this.transform.bind(this);
|
|
671
|
+
for (let n = 0; n < e.length; n++) {
|
|
672
|
+
let r = e[n], i = Math.round(n / (e.length - 1) * 100);
|
|
673
|
+
this.addFrame(i, r, t);
|
|
674
|
+
}
|
|
675
|
+
return this.parse(), this;
|
|
676
|
+
}
|
|
677
|
+
fromKeyframes(e, t) {
|
|
678
|
+
this.unflatten = t != null, t ??= this.transform.bind(this), ee(e) && (e = new Map(Object.entries(e)));
|
|
679
|
+
let n = e instanceof Map ? e.entries() : Object.entries(e);
|
|
680
|
+
for (let [e, r] of n) this.addFrame(e, r, t);
|
|
681
|
+
return this.parse(), this;
|
|
682
|
+
}
|
|
683
|
+
propertyRegistry = /* @__PURE__ */ new Map();
|
|
684
|
+
fromString(e, t) {
|
|
685
|
+
this.unflatten = t != null, t ??= this.transform.bind(this);
|
|
686
|
+
let n = N(e);
|
|
687
|
+
this.propertyRegistry = n.properties;
|
|
688
|
+
for (let [e, r] of n.keyframes.entries()) {
|
|
689
|
+
let i = Object.fromEntries(Object.entries(r).map(([e, t]) => [e, pe(t) ? t.clone() : t])), a = n.timingFunctions.get(e), o = a ? W(a) : void 0;
|
|
690
|
+
this.addFrame(e, i, t, o);
|
|
691
|
+
}
|
|
692
|
+
return this.parse(), this;
|
|
693
|
+
}
|
|
694
|
+
transform(e) {
|
|
695
|
+
Y(e, this.targets);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
//#endregion
|
|
699
|
+
export { $ as Animation, z as AnimationGroup, he as CSSKeyframesAnimation, P as DIRECTIONS, F as FILL_MODES, L as defaultLayerConfig, I as defaultOptions, Q as getAnimationId, W as getTimingFunction, N as resolveKeyframes };
|