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