@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
|
@@ -0,0 +1,1051 @@
|
|
|
1
|
+
import { _ as e, c as t, d as n, f as r, h as i, o as a, s as o } from "./timeline-BHz0o8dZ.js";
|
|
2
|
+
import { COLOR_SPACE_RANGES as s, COMPUTED_UNITS as c, CSSCubicBezier as l, CSSFunction as u, CSSValues as d, FunctionValue as f, ValueArray as p, ValueUnit as m, clamp as h, convertToMs as g, cssLinear as _, easeInOutCubic as v, extractAnimationOptions as y, extractKeyframes as ee, extractProperties as te, flattenObject as b, isObject as ne, jumpTerms as re, lerp as ie, lerpValue as ae, normalizeValueUnits as oe, parseCSSStylesheet as x, parseCSSTime as S, parseCSSValueUnit as se, prepareInterpVar as ce, scale as le, seekPreviousValue as C, sleep as w, steppedEase as T, timingFunctions as E, tryParse as ue, unflattenObject as de, unflattenObjectToString as D } from "@mkbabb/value.js";
|
|
3
|
+
import { any as fe } from "@mkbabb/parse-that";
|
|
4
|
+
//#region src/animation/adapter.ts
|
|
5
|
+
var pe = (e) => {
|
|
6
|
+
let t = {};
|
|
7
|
+
for (let n of e.declarations) t[n.name] = n.value;
|
|
8
|
+
return t;
|
|
9
|
+
}, me = (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
|
+
}, O = (e) => {
|
|
14
|
+
let t = ee(e);
|
|
15
|
+
for (let e of t.values()) if (e.length > 0) return e;
|
|
16
|
+
return [];
|
|
17
|
+
}, k = (e) => {
|
|
18
|
+
let t = typeof e == "string" ? x(e) : e, n = O(t);
|
|
19
|
+
typeof e == "string" && n.length === 0 && e.trim() && (t = x(`@keyframes anonymous {\n${e.trim()}\n}`), n = O(t));
|
|
20
|
+
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
|
|
21
|
+
for (let e of n) {
|
|
22
|
+
let t = pe(e);
|
|
23
|
+
for (let n of me(e)) {
|
|
24
|
+
let o = r.get(n);
|
|
25
|
+
r.set(n, {
|
|
26
|
+
...o ?? {},
|
|
27
|
+
...t
|
|
28
|
+
}), e.timingFunction != null && i.set(n, e.timingFunction);
|
|
29
|
+
let s = e.composition;
|
|
30
|
+
s != null && a.set(n, s);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
keyframes: r,
|
|
35
|
+
timingFunctions: i,
|
|
36
|
+
composition: a,
|
|
37
|
+
properties: te(t),
|
|
38
|
+
options: y(t)
|
|
39
|
+
};
|
|
40
|
+
}, A = [
|
|
41
|
+
"normal",
|
|
42
|
+
"reverse",
|
|
43
|
+
"alternate",
|
|
44
|
+
"alternate-reverse"
|
|
45
|
+
], j = [
|
|
46
|
+
"none",
|
|
47
|
+
"forwards",
|
|
48
|
+
"backwards",
|
|
49
|
+
"both"
|
|
50
|
+
], M = Object.keys(s), N = [
|
|
51
|
+
"shorter",
|
|
52
|
+
"longer",
|
|
53
|
+
"increasing",
|
|
54
|
+
"decreasing"
|
|
55
|
+
], P = {
|
|
56
|
+
duration: 1e3,
|
|
57
|
+
delay: 0,
|
|
58
|
+
iterationCount: 1,
|
|
59
|
+
direction: "normal",
|
|
60
|
+
fillMode: "forwards",
|
|
61
|
+
timingFunction: { fn: v },
|
|
62
|
+
useWAAPI: !0,
|
|
63
|
+
respectReducedMotion: !1,
|
|
64
|
+
colorSpace: "oklab"
|
|
65
|
+
}, F = {
|
|
66
|
+
zIndex: 0,
|
|
67
|
+
weight: 1,
|
|
68
|
+
blendMode: "replace",
|
|
69
|
+
enabled: !0
|
|
70
|
+
}, I = null, L = () => typeof MessageChannel == "function" ? () => new Promise((e) => {
|
|
71
|
+
let t = new MessageChannel();
|
|
72
|
+
t.port1.onmessage = () => {
|
|
73
|
+
t.port1.close(), e();
|
|
74
|
+
}, t.port2.postMessage(void 0);
|
|
75
|
+
}) : () => new Promise((e) => setTimeout(e, 0));
|
|
76
|
+
function R() {
|
|
77
|
+
let e = globalThis.scheduler;
|
|
78
|
+
return e && typeof e.yield == "function" ? e.yield() : (I ??= L(), I());
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/animation/group.ts
|
|
82
|
+
var z = (e) => e instanceof m && typeof e.value == "number", B = class e {
|
|
83
|
+
animations = {};
|
|
84
|
+
transform;
|
|
85
|
+
superKey;
|
|
86
|
+
paused = !1;
|
|
87
|
+
started = !1;
|
|
88
|
+
done = !1;
|
|
89
|
+
respectReducedMotion = !1;
|
|
90
|
+
static YIELD_BATCH = 32;
|
|
91
|
+
singleTarget = !0;
|
|
92
|
+
lastTickTime = 0;
|
|
93
|
+
playback = new a();
|
|
94
|
+
resolvePromise = null;
|
|
95
|
+
_playingPromise = null;
|
|
96
|
+
_boundFrame;
|
|
97
|
+
_entries = [];
|
|
98
|
+
_entriesDirty = !0;
|
|
99
|
+
_grouped = {};
|
|
100
|
+
_groupedKeys = [];
|
|
101
|
+
_groupedKeysDirty = !0;
|
|
102
|
+
constructor(...e) {
|
|
103
|
+
this._boundFrame = this._frame.bind(this);
|
|
104
|
+
let t = [];
|
|
105
|
+
for (let n of e) {
|
|
106
|
+
let e, r;
|
|
107
|
+
n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform == null && e.frames[0] != null && (this.transform = e.frames[0].transform);
|
|
108
|
+
let i = Q(e);
|
|
109
|
+
this.animations[i] = {
|
|
110
|
+
values: {},
|
|
111
|
+
animation: e,
|
|
112
|
+
layer: {
|
|
113
|
+
...F,
|
|
114
|
+
...r
|
|
115
|
+
}
|
|
116
|
+
}, e.managed = !0, t.push(e);
|
|
117
|
+
}
|
|
118
|
+
this.singleTarget = t.every((e) => e.targets[0] === t[0]?.targets[0]), this.invalidateEntries();
|
|
119
|
+
}
|
|
120
|
+
getEntries() {
|
|
121
|
+
return this._entriesDirty &&= (this._entries = Object.values(this.animations), this._entries.sort((e, t) => e.layer.zIndex - t.layer.zIndex), !1), this._entries;
|
|
122
|
+
}
|
|
123
|
+
invalidateEntries() {
|
|
124
|
+
this._entriesDirty = !0, this._groupedKeysDirty = !0;
|
|
125
|
+
}
|
|
126
|
+
computeGroupedKeys() {
|
|
127
|
+
let e = /* @__PURE__ */ new Set();
|
|
128
|
+
for (let t of this.getEntries()) {
|
|
129
|
+
let n = t.layer.properties;
|
|
130
|
+
for (let r of t.animation.flatKeys) n && !n.has(r) || e.add(r);
|
|
131
|
+
}
|
|
132
|
+
this._groupedKeys = [...e];
|
|
133
|
+
}
|
|
134
|
+
setSuperKey(e) {
|
|
135
|
+
this.superKey = e;
|
|
136
|
+
for (let t of this.getEntries()) t.animation.superKey = e;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
setTargets(...e) {
|
|
140
|
+
let t = this.getEntries();
|
|
141
|
+
for (let n of t) n.animation.setTargets(...e);
|
|
142
|
+
return this.singleTarget = t.every((e) => e.animation.targets[0] === t[0]?.animation.targets[0]), this;
|
|
143
|
+
}
|
|
144
|
+
onStart() {
|
|
145
|
+
return this.started = !0, this;
|
|
146
|
+
}
|
|
147
|
+
onEnd() {
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
transformFramesGrouped(e) {
|
|
151
|
+
let t = this._grouped;
|
|
152
|
+
this._groupedKeysDirty &&= (this.computeGroupedKeys(), !1);
|
|
153
|
+
let n = this._groupedKeys;
|
|
154
|
+
for (let e = 0; e < n.length; e++) t[n[e]] = void 0;
|
|
155
|
+
let r = this.getEntries(), i = !0;
|
|
156
|
+
for (let e of r) {
|
|
157
|
+
let { animation: n, layer: r, values: a } = e;
|
|
158
|
+
if (i &&= n.done, !r.enabled) continue;
|
|
159
|
+
n.interpFrames(n.t, !1, a);
|
|
160
|
+
let o = r.properties;
|
|
161
|
+
switch (r.blendMode) {
|
|
162
|
+
case "replace":
|
|
163
|
+
for (let e in a) {
|
|
164
|
+
if (o && !o.has(e)) continue;
|
|
165
|
+
let n = a[e];
|
|
166
|
+
n !== void 0 && (t[e] = n);
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
case "add":
|
|
170
|
+
for (let e in a) {
|
|
171
|
+
if (o && !o.has(e)) continue;
|
|
172
|
+
let n = a[e];
|
|
173
|
+
if (n === void 0) continue;
|
|
174
|
+
let r = t[e];
|
|
175
|
+
if (Array.isArray(r) && Array.isArray(n)) {
|
|
176
|
+
let e = Math.min(r.length, n.length);
|
|
177
|
+
for (let t = 0; t < e; t++) z(r[t]) && z(n[t]) ? r[t].value += n[t].value : r[t] = n[t];
|
|
178
|
+
} else t[e] = n;
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
case "weighted":
|
|
182
|
+
for (let e in a) {
|
|
183
|
+
if (o && !o.has(e)) continue;
|
|
184
|
+
let n = a[e];
|
|
185
|
+
if (n === void 0) continue;
|
|
186
|
+
let i = t[e];
|
|
187
|
+
if (Array.isArray(i) && Array.isArray(n)) {
|
|
188
|
+
let e = Math.min(i.length, n.length);
|
|
189
|
+
for (let t = 0; t < e; t++) z(i[t]) && z(n[t]) ? i[t].value = ie(i[t].value, n[t].value, r.weight) : i[t] = n[t];
|
|
190
|
+
} else t[e] = n;
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
this.done = i;
|
|
196
|
+
for (let e = 0; e < n.length; e++) {
|
|
197
|
+
let r = n[e];
|
|
198
|
+
t[r] === void 0 && delete t[r];
|
|
199
|
+
}
|
|
200
|
+
return this.transform(t, e), t;
|
|
201
|
+
}
|
|
202
|
+
render() {
|
|
203
|
+
let e = this.lastTickTime || performance.now();
|
|
204
|
+
if (this.singleTarget) this.transformFramesGrouped(e);
|
|
205
|
+
else for (let e of this.getEntries()) e.animation.interpFrames(e.animation.t, !0);
|
|
206
|
+
}
|
|
207
|
+
setChildTime(e, t) {
|
|
208
|
+
let n = typeof e == "string" ? e : Q(e), r = this.animations[n];
|
|
209
|
+
if (!r) throw Error(`AnimationGroup.setChildTime: no animation registered for key "${n}". Known keys: ${Object.keys(this.animations).join(", ") || "(none)"}.`);
|
|
210
|
+
let i = r.animation;
|
|
211
|
+
return i.t = t, i.startTime !== void 0 && (i.pausedTime = i.startTime + t), this;
|
|
212
|
+
}
|
|
213
|
+
async advanceTo(t) {
|
|
214
|
+
this.lastTickTime = t, this.started || this.onStart();
|
|
215
|
+
let n = this.getEntries(), r = e.YIELD_BATCH;
|
|
216
|
+
if (n.length <= r) await this._advanceSlice(n, t);
|
|
217
|
+
else for (let e = 0; e < n.length; e += r) await this._advanceSlice(n.slice(e, e + r), t), e + r < n.length && await R();
|
|
218
|
+
return this.done && this.onEnd(), this;
|
|
219
|
+
}
|
|
220
|
+
async _advanceSlice(e, t) {
|
|
221
|
+
let n = [];
|
|
222
|
+
for (let r of e) {
|
|
223
|
+
let e = r.animation;
|
|
224
|
+
(!e.paused || e.pausedTime === 0) && n.push(e.advanceTo(t));
|
|
225
|
+
}
|
|
226
|
+
await Promise.all(n);
|
|
227
|
+
}
|
|
228
|
+
async _frame(e) {
|
|
229
|
+
if (await this.advanceTo(e), this.paused) return !1;
|
|
230
|
+
if (this.singleTarget) this.transformFramesGrouped(e);
|
|
231
|
+
else {
|
|
232
|
+
let e = !0;
|
|
233
|
+
for (let t of this.getEntries()) t.animation.interpFrames(t.animation.t, !0), e &&= t.animation.done;
|
|
234
|
+
this.done = e;
|
|
235
|
+
}
|
|
236
|
+
return this.done ? (this.settle(), this._resolvePlay(), !1) : !0;
|
|
237
|
+
}
|
|
238
|
+
_resolvePlay() {
|
|
239
|
+
let e = this.resolvePromise;
|
|
240
|
+
this.resolvePromise = null, e?.();
|
|
241
|
+
}
|
|
242
|
+
get finished() {
|
|
243
|
+
return this._playingPromise ?? Promise.resolve();
|
|
244
|
+
}
|
|
245
|
+
async play() {
|
|
246
|
+
if (this._playingPromise) return this._playingPromise;
|
|
247
|
+
let e = o(this.respectReducedMotion, () => this._playReducedMotion(), () => new Promise((e) => {
|
|
248
|
+
this.resolvePromise = e, this.playback.loop(this._boundFrame);
|
|
249
|
+
}));
|
|
250
|
+
return this._playingPromise = e, e.finally(() => {
|
|
251
|
+
this._playingPromise = null;
|
|
252
|
+
}), e;
|
|
253
|
+
}
|
|
254
|
+
_playReducedMotion() {
|
|
255
|
+
this.onStart();
|
|
256
|
+
let e = this.lastTickTime || performance.now();
|
|
257
|
+
this.lastTickTime = e;
|
|
258
|
+
for (let e of this.getEntries()) {
|
|
259
|
+
let t = e.animation;
|
|
260
|
+
t.started = !0, t.t = t.options.duration, t.interpFrames(t.t, !0);
|
|
261
|
+
}
|
|
262
|
+
return this.singleTarget && this.transformFramesGrouped(e), this.settle(), Promise.resolve();
|
|
263
|
+
}
|
|
264
|
+
pause() {
|
|
265
|
+
if (!this.started || this.paused) return this;
|
|
266
|
+
this.paused = !0;
|
|
267
|
+
let e = this.lastTickTime || performance.now();
|
|
268
|
+
for (let t of this.getEntries()) {
|
|
269
|
+
let n = t.animation;
|
|
270
|
+
n.pause(), n.pausedTime === 0 && (n.pausedTime = e);
|
|
271
|
+
}
|
|
272
|
+
return this.playback.stop(), this.render(), this;
|
|
273
|
+
}
|
|
274
|
+
resume() {
|
|
275
|
+
if (!this.started || !this.paused) return this;
|
|
276
|
+
this.paused = !1;
|
|
277
|
+
for (let e of this.getEntries()) e.animation.paused = !1;
|
|
278
|
+
return this.playback.loop(this._boundFrame), this;
|
|
279
|
+
}
|
|
280
|
+
toggle() {
|
|
281
|
+
return this.paused ? this.resume() : this.pause();
|
|
282
|
+
}
|
|
283
|
+
settle() {
|
|
284
|
+
for (let e of this.getEntries()) e.animation.managed = !1, e.animation.settle();
|
|
285
|
+
return this.started = !1, this.done = !1, this.paused = !1, this.lastTickTime = 0, this;
|
|
286
|
+
}
|
|
287
|
+
reset() {
|
|
288
|
+
for (let e of this.getEntries()) {
|
|
289
|
+
let t = e.animation;
|
|
290
|
+
t.started && t.frames.length > 0 && t.interpFrames(0, !0);
|
|
291
|
+
}
|
|
292
|
+
return this.settle();
|
|
293
|
+
}
|
|
294
|
+
stop() {
|
|
295
|
+
return this.playback.stop(), this.reset(), this._resolvePlay(), this;
|
|
296
|
+
}
|
|
297
|
+
playing() {
|
|
298
|
+
return !(!this.started || this.paused);
|
|
299
|
+
}
|
|
300
|
+
forcePause() {
|
|
301
|
+
this.paused = !0;
|
|
302
|
+
for (let e of this.getEntries()) e.animation.paused = !0;
|
|
303
|
+
}
|
|
304
|
+
forcePlay() {
|
|
305
|
+
this.paused = !1;
|
|
306
|
+
for (let e of this.getEntries()) e.animation.paused = !1;
|
|
307
|
+
}
|
|
308
|
+
setLayerConfig(e, t) {
|
|
309
|
+
let n = typeof e == "string" ? e : Q(e), r = this.animations[n];
|
|
310
|
+
if (!r) throw Error(`AnimationGroup.setLayerConfig: no animation registered for key "${n}". Known keys: ${Object.keys(this.animations).join(", ") || "(none)"}.`);
|
|
311
|
+
return Object.assign(r.layer, t), this.invalidateEntries(), this;
|
|
312
|
+
}
|
|
313
|
+
setLayerEnabled(e, t) {
|
|
314
|
+
return this.setLayerConfig(e, { enabled: t });
|
|
315
|
+
}
|
|
316
|
+
getLayerConfig(e) {
|
|
317
|
+
let t = typeof e == "string" ? e : Q(e);
|
|
318
|
+
return this.animations[t]?.layer;
|
|
319
|
+
}
|
|
320
|
+
}, V = (e) => {
|
|
321
|
+
if (e instanceof m) return [e.clone()];
|
|
322
|
+
if (e instanceof f) return e.values.flatMap((e) => V(e));
|
|
323
|
+
if (e instanceof p) return e.flatMap((e) => V(e));
|
|
324
|
+
throw TypeError(`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof e}`);
|
|
325
|
+
}, he = (e) => {
|
|
326
|
+
let t = e.split(".").pop(), n = e.split(".").shift();
|
|
327
|
+
if (!t || !n) throw Error(`Invalid flattened key: ${e}`);
|
|
328
|
+
return {
|
|
329
|
+
mainKey: n,
|
|
330
|
+
childKey: t
|
|
331
|
+
};
|
|
332
|
+
}, H = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), ge = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, _e = /^\s*steps\s*\(\s*(\d+)\s*(?:,\s*(jump-start|jump-end|jump-none|jump-both|start|end|both)\s*)?\)\s*$/i, U = /^\s*linear\s*\(\s*(.+)\s*\)\s*$/i, ve = (e) => {
|
|
333
|
+
let t = [];
|
|
334
|
+
for (let n of e.split(",")) {
|
|
335
|
+
let e = n.trim().split(/\s+/).filter(Boolean);
|
|
336
|
+
if (e.length === 0) return;
|
|
337
|
+
let r = Number.parseFloat(e[0]);
|
|
338
|
+
if (!Number.isFinite(r)) return;
|
|
339
|
+
let i = e.slice(1);
|
|
340
|
+
if (i.length === 0) {
|
|
341
|
+
t.push({ output: r });
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
for (let e of i) {
|
|
345
|
+
let n = Number.parseFloat(e.endsWith("%") ? e.slice(0, -1) : e);
|
|
346
|
+
if (!Number.isFinite(n)) return;
|
|
347
|
+
t.push({
|
|
348
|
+
output: r,
|
|
349
|
+
input: n
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return t.length >= 2 ? t : void 0;
|
|
354
|
+
}, W = (e) => {
|
|
355
|
+
if (e == null) return;
|
|
356
|
+
if (typeof e != "string") return e;
|
|
357
|
+
let t = e.match(ge);
|
|
358
|
+
if (t) {
|
|
359
|
+
let e = t.slice(1, 5).map((e) => Number.parseFloat(e ?? ""));
|
|
360
|
+
if (e.length === 4 && e.every((e) => Number.isFinite(e))) {
|
|
361
|
+
let [t, n, r, i] = e;
|
|
362
|
+
return l(t, n, r, i);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
let n = e.match(_e);
|
|
366
|
+
if (n) {
|
|
367
|
+
let e = Number.parseInt(n[1], 10), t = n[2]?.toLowerCase() ?? "end";
|
|
368
|
+
if (e > 0 && re.includes(t)) return T(e, t);
|
|
369
|
+
}
|
|
370
|
+
if (e === "step-start") return T(1, "jump-start");
|
|
371
|
+
if (e === "step-end") return T(1, "jump-end");
|
|
372
|
+
let r = e.match(U);
|
|
373
|
+
if (r) {
|
|
374
|
+
let e = ve(r[1]);
|
|
375
|
+
if (e) return _(e);
|
|
376
|
+
}
|
|
377
|
+
let i = E[e];
|
|
378
|
+
if (typeof i == "function" && i.length <= 1) return i;
|
|
379
|
+
}, G = /* @__PURE__ */ new Map();
|
|
380
|
+
function ye(e) {
|
|
381
|
+
let t = b(e), n = (e, t) => {
|
|
382
|
+
let { childKey: r, mainKey: i } = he(e);
|
|
383
|
+
if (t instanceof m) return H(new p(...V(t)), i, r);
|
|
384
|
+
if (t instanceof f) return H(new p(...t.values.flatMap((t) => V(n(e, t)))), i, r);
|
|
385
|
+
if (t instanceof p) return H(new p(...t.flatMap((t) => V(n(e, t)))), i, r);
|
|
386
|
+
let a = String(t), o = `${r}:${a}`, s = G.get(o);
|
|
387
|
+
if (s) return H(s.clone(), i, r);
|
|
388
|
+
let c = H(new p(...V(ue(fe(u.FunctionArgs.map((e) => (e.setSubProperty(r), e)), d.Value), a))), i, r);
|
|
389
|
+
return G.set(o, c.clone()), c;
|
|
390
|
+
};
|
|
391
|
+
return Object.entries(t).reduce((e, [t, r]) => (e[t] = n(t, r), e), {});
|
|
392
|
+
}
|
|
393
|
+
var K = (e, t, n, r, i = "oklab", a) => {
|
|
394
|
+
let o = r[t], s = r[n];
|
|
395
|
+
if (!o || !s) throw Error(`Invalid interpolation frame bounds (${t} -> ${n}).`);
|
|
396
|
+
let c = o[e], l = s[e];
|
|
397
|
+
if (!c || !l) throw Error(`Missing variable "${e}" in interpolation bounds.`);
|
|
398
|
+
let u = Math.max(c.length, l.length), d = (t) => {
|
|
399
|
+
let n = t.map((t) => {
|
|
400
|
+
if (!(t instanceof m)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
401
|
+
return t;
|
|
402
|
+
});
|
|
403
|
+
for (; n.length < u;) n.push(new m(0));
|
|
404
|
+
return n;
|
|
405
|
+
}, f = d(c), p = d(l);
|
|
406
|
+
return f.map((t, n) => {
|
|
407
|
+
let r = p[n];
|
|
408
|
+
if (!r) throw Error(`Missing right-hand interpolation value at index ${n}.`);
|
|
409
|
+
if (!(t instanceof m) || !(r instanceof m)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
410
|
+
let o = { colorSpace: i };
|
|
411
|
+
return a !== void 0 && (o.hueMethod = a), ce(oe(t, r, o));
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
function be(e, t, n) {
|
|
415
|
+
let [r, i] = [e.start, t.start];
|
|
416
|
+
return {
|
|
417
|
+
start: r.value * n / 100,
|
|
418
|
+
stop: i.value * n / 100
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
function q(e, t, n = !0) {
|
|
422
|
+
e = n ? e : b(e);
|
|
423
|
+
let r = D(e);
|
|
424
|
+
t.forEach((e) => {
|
|
425
|
+
Object.entries(r).forEach(([t, n]) => {
|
|
426
|
+
e.style.setProperty(t, n);
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/animation/frame-compiler.ts
|
|
432
|
+
var J = (e, t) => {
|
|
433
|
+
if (typeof t == "function") return { fn: t };
|
|
434
|
+
if (typeof t == "object") {
|
|
435
|
+
if (typeof t.fn == "function") return t;
|
|
436
|
+
throw new i(e, t, "an Easing must carry a callable `fn`");
|
|
437
|
+
}
|
|
438
|
+
let n = W(t);
|
|
439
|
+
if (!n) throw new i(e, t, "unknown timing function — pass a callable TimingFunction, a typed Easing, a registry name, or a cubic-bezier() literal");
|
|
440
|
+
let a = r(t);
|
|
441
|
+
return a ? {
|
|
442
|
+
fn: n,
|
|
443
|
+
css: a
|
|
444
|
+
} : { fn: n };
|
|
445
|
+
}, xe = 1e6, Se = class {
|
|
446
|
+
_options;
|
|
447
|
+
templateFrames = [];
|
|
448
|
+
parsedVars = [];
|
|
449
|
+
frames = [];
|
|
450
|
+
frameId = 0;
|
|
451
|
+
constructor(e) {
|
|
452
|
+
this._options = e;
|
|
453
|
+
}
|
|
454
|
+
get options() {
|
|
455
|
+
return this._options;
|
|
456
|
+
}
|
|
457
|
+
convertFrameStart(e) {
|
|
458
|
+
if (e.start.unit === "s" || e.start.unit === "ms" || !e.start.unit) {
|
|
459
|
+
let t = e.start.unit === "s" ? "s" : "ms", n = g(e.start.value, t);
|
|
460
|
+
e.start.value = n / this.options.duration * 100, e.start.unit = "%";
|
|
461
|
+
}
|
|
462
|
+
return e.start.value = h(e.start.value, 0, 100), e;
|
|
463
|
+
}
|
|
464
|
+
addFrame(e, t, n, r) {
|
|
465
|
+
typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof m && (e = String(e));
|
|
466
|
+
let i = se(e), a = {
|
|
467
|
+
id: this.frameId,
|
|
468
|
+
start: i,
|
|
469
|
+
vars: t,
|
|
470
|
+
transform: n,
|
|
471
|
+
timingFunction: r == null ? this.options.timingFunction : J("timingFunction", r)
|
|
472
|
+
};
|
|
473
|
+
this.convertFrameStart(a), this.templateFrames.push(a), this.frameId += 1;
|
|
474
|
+
}
|
|
475
|
+
createFrame(e, t) {
|
|
476
|
+
let n = this.templateFrames[e], r = this.templateFrames[t], i = {
|
|
477
|
+
start: e,
|
|
478
|
+
stop: t
|
|
479
|
+
}, a = be(n, r, this.options.duration), o = n.transform;
|
|
480
|
+
if (o == null) {
|
|
481
|
+
let t = C(e, this.templateFrames, (e) => e.transform != null);
|
|
482
|
+
o = this.templateFrames[t].transform;
|
|
483
|
+
}
|
|
484
|
+
let s = n.timingFunction;
|
|
485
|
+
if (s == null) {
|
|
486
|
+
let t = C(e, this.templateFrames, (e) => e.timingFunction != null);
|
|
487
|
+
s = this.templateFrames[t].timingFunction;
|
|
488
|
+
}
|
|
489
|
+
return {
|
|
490
|
+
id: e * xe + t,
|
|
491
|
+
ixs: i,
|
|
492
|
+
start: n.start,
|
|
493
|
+
time: a,
|
|
494
|
+
vars: void 0,
|
|
495
|
+
flatVars: void 0,
|
|
496
|
+
interpVars: {},
|
|
497
|
+
allInterpVars: [],
|
|
498
|
+
transform: o,
|
|
499
|
+
timingFunction: s
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
buildVarIndex() {
|
|
503
|
+
let e = /* @__PURE__ */ new Map();
|
|
504
|
+
for (let t = 0; t < this.parsedVars.length; t++) for (let n of Object.keys(this.parsedVars[t])) {
|
|
505
|
+
let r = e.get(n);
|
|
506
|
+
r || (r = [], e.set(n, r)), r.push(t);
|
|
507
|
+
}
|
|
508
|
+
return e;
|
|
509
|
+
}
|
|
510
|
+
reconcileVars(e, t) {
|
|
511
|
+
let n = this.parsedVars[e];
|
|
512
|
+
if (n) for (let r of Object.keys(n)) {
|
|
513
|
+
let n = t.get(r);
|
|
514
|
+
if (!n) continue;
|
|
515
|
+
let i = -1;
|
|
516
|
+
for (let t of n) if (t > e) {
|
|
517
|
+
i = t;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
if (i === -1) continue;
|
|
521
|
+
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];
|
|
522
|
+
c.interpVars[r] = K(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
parse(e) {
|
|
526
|
+
this.frames = [], this.templateFrames.sort((e, t) => e.start.value - t.start.value), this.parsedVars = this.templateFrames.map((t) => {
|
|
527
|
+
let n = ye(t.vars);
|
|
528
|
+
return Object.values(n).forEach((t) => {
|
|
529
|
+
t.setTargets(e);
|
|
530
|
+
}), n;
|
|
531
|
+
});
|
|
532
|
+
for (let e = 0; e < this.templateFrames.length - 1; e++) this.frames.push(this.createFrame(e, e + 1));
|
|
533
|
+
let t = this.buildVarIndex();
|
|
534
|
+
this.frames.forEach((e, n) => this.reconcileVars(n, t)), 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) => this.finalizeFrameVars(e));
|
|
535
|
+
}
|
|
536
|
+
finalizeFrameVars(e) {
|
|
537
|
+
e.flatVars = Object.entries(e.interpVars).reduce((e, [t, n]) => (e[t] = n.map((e) => e.value), e), {}), e.vars = de(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
|
|
538
|
+
}
|
|
539
|
+
renormalizeColors() {
|
|
540
|
+
for (let e of this.frames) {
|
|
541
|
+
for (let t of Object.keys(e.interpVars)) e.interpVars[t] = K(t, e.ixs.start, e.ixs.stop, this.parsedVars, this.options.colorSpace, this.options.hueMethod);
|
|
542
|
+
this.finalizeFrameVars(e);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}, Ce = new Set([
|
|
546
|
+
...c,
|
|
547
|
+
"%",
|
|
548
|
+
"vh",
|
|
549
|
+
"vw",
|
|
550
|
+
"vmin",
|
|
551
|
+
"vmax",
|
|
552
|
+
"vi",
|
|
553
|
+
"vb",
|
|
554
|
+
"svh",
|
|
555
|
+
"svw",
|
|
556
|
+
"svmin",
|
|
557
|
+
"svmax",
|
|
558
|
+
"svi",
|
|
559
|
+
"svb",
|
|
560
|
+
"lvh",
|
|
561
|
+
"lvw",
|
|
562
|
+
"lvmin",
|
|
563
|
+
"lvmax",
|
|
564
|
+
"lvi",
|
|
565
|
+
"lvb",
|
|
566
|
+
"dvh",
|
|
567
|
+
"dvw",
|
|
568
|
+
"dvmin",
|
|
569
|
+
"dvmax",
|
|
570
|
+
"dvi",
|
|
571
|
+
"dvb",
|
|
572
|
+
"cqw",
|
|
573
|
+
"cqh",
|
|
574
|
+
"cqi",
|
|
575
|
+
"cqb",
|
|
576
|
+
"cqmin",
|
|
577
|
+
"cqmax"
|
|
578
|
+
]), Y = (e) => typeof e == "string" && Ce.has(e), X = new Set(["offset-distance"]), we = (e) => X.has(e) || X.has(e.split(".").pop() ?? e);
|
|
579
|
+
function Te(e) {
|
|
580
|
+
if (!e.targets || e.targets.length === 0) return {
|
|
581
|
+
eligible: !1,
|
|
582
|
+
reason: "no DOM targets"
|
|
583
|
+
};
|
|
584
|
+
if (typeof e.targets[0]?.animate != "function") return {
|
|
585
|
+
eligible: !1,
|
|
586
|
+
reason: "target does not implement Element.animate()"
|
|
587
|
+
};
|
|
588
|
+
for (let t of e.frames) if (!e.usesDefaultRenderer(t.transform)) return {
|
|
589
|
+
eligible: !1,
|
|
590
|
+
reason: "custom transform function (not the default DOM renderer)"
|
|
591
|
+
};
|
|
592
|
+
let t = e.frames[0]?.timingFunction;
|
|
593
|
+
if (t && e.frames.length > 1) {
|
|
594
|
+
for (let n = 1; n < e.frames.length; n++) if (e.frames[n].timingFunction.fn !== t.fn) return {
|
|
595
|
+
eligible: !1,
|
|
596
|
+
reason: "non-uniform per-frame timing function (WAAPI supports one easing per animation)"
|
|
597
|
+
};
|
|
598
|
+
if (t.css !== void 0) return {
|
|
599
|
+
eligible: !1,
|
|
600
|
+
reason: "CSS-twinned easing across multiple segments (WAAPI restarts the curve per segment)"
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
if (t && t.css === void 0) return {
|
|
604
|
+
eligible: !1,
|
|
605
|
+
reason: "easing has no faithful CSS twin (would run bare linear on the compositor)"
|
|
606
|
+
};
|
|
607
|
+
for (let t of e.frames) for (let [e, n] of Object.entries(t.interpVars)) {
|
|
608
|
+
let t = we(e);
|
|
609
|
+
for (let e of n) {
|
|
610
|
+
let n = Y(e.start?.unit) && !(t && e.start?.unit === "%"), r = Y(e.stop?.unit) && !(t && e.stop?.unit === "%");
|
|
611
|
+
if (n || r) return {
|
|
612
|
+
eligible: !1,
|
|
613
|
+
reason: `layout-dependent unit (${String(e.start?.unit ?? e.stop?.unit)}) would freeze to px under WAAPI`
|
|
614
|
+
};
|
|
615
|
+
if (e.start?.unit === "color" || e.stop?.unit === "color") return {
|
|
616
|
+
eligible: !1,
|
|
617
|
+
reason: "color interpolation requires perceptual lerp"
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return { eligible: !0 };
|
|
622
|
+
}
|
|
623
|
+
var Ee = 8;
|
|
624
|
+
function De(e) {
|
|
625
|
+
let n = e.options.duration, r = [], i = /* @__PURE__ */ new Set();
|
|
626
|
+
for (let t of e.frames) i.add(t.time.start), i.add(t.time.stop);
|
|
627
|
+
let a = [...i].sort((e, t) => e - t), o = new Set(a);
|
|
628
|
+
if (n > 0) for (let e = 1; e < a.length; e++) {
|
|
629
|
+
let t = a[e - 1], n = a[e] - t;
|
|
630
|
+
if (!(n <= 0)) for (let e = 1; e <= Ee; e++) o.add(t + n * e / 9);
|
|
631
|
+
}
|
|
632
|
+
for (let i of [...o].sort((e, t) => e - t)) {
|
|
633
|
+
let a = e.interpFrames(i, !1);
|
|
634
|
+
if (Object.keys(a).length === 0) continue;
|
|
635
|
+
let o = D(a);
|
|
636
|
+
r.push({
|
|
637
|
+
offset: t(i / n, 0, 1),
|
|
638
|
+
...o
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
return r;
|
|
642
|
+
}
|
|
643
|
+
var Oe = {
|
|
644
|
+
normal: "normal",
|
|
645
|
+
reverse: "reverse",
|
|
646
|
+
alternate: "alternate",
|
|
647
|
+
"alternate-reverse": "alternate-reverse"
|
|
648
|
+
}, ke = {
|
|
649
|
+
none: "none",
|
|
650
|
+
forwards: "forwards",
|
|
651
|
+
backwards: "backwards",
|
|
652
|
+
both: "both"
|
|
653
|
+
};
|
|
654
|
+
function Ae(e) {
|
|
655
|
+
let t = e.options, n = Oe[t.direction], r = ke[t.fillMode];
|
|
656
|
+
if (n == null) throw TypeError(`Unrecognised animation direction "${t.direction}".`);
|
|
657
|
+
if (r == null) throw TypeError(`Unrecognised animation fill mode "${t.fillMode}".`);
|
|
658
|
+
let i = (e.frames[0]?.timingFunction ?? e.options.timingFunction).css ?? "linear";
|
|
659
|
+
return {
|
|
660
|
+
duration: t.duration,
|
|
661
|
+
delay: t.delay,
|
|
662
|
+
iterations: t.iterationCount === Infinity ? Infinity : t.iterationCount,
|
|
663
|
+
direction: n,
|
|
664
|
+
fill: r,
|
|
665
|
+
easing: i
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
async function je(e) {
|
|
669
|
+
let t = De(e), n = Ae(e), r = e.targets.map((e) => e.animate(t, n));
|
|
670
|
+
e._waAnimations = r, e.playback.loop(async (t) => {
|
|
671
|
+
if (e.done) return !1;
|
|
672
|
+
if (await e.advanceTo(t), e.paused) for (let e of r) e.pause();
|
|
673
|
+
else for (let e of r) e.playState === "paused" && e.play();
|
|
674
|
+
return !e.done;
|
|
675
|
+
});
|
|
676
|
+
try {
|
|
677
|
+
await Promise.all(r.map((e) => e.finished));
|
|
678
|
+
for (let t of r) try {
|
|
679
|
+
e.restPosition === "final" && typeof t.commitStyles == "function" && t.commitStyles(), t.cancel();
|
|
680
|
+
} catch {}
|
|
681
|
+
} catch {} finally {
|
|
682
|
+
e.playback.stop(), e._waAnimations = [];
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/animation/engine.ts
|
|
687
|
+
var Z = (e) => {
|
|
688
|
+
try {
|
|
689
|
+
let t = S(e);
|
|
690
|
+
return Number.isFinite(t) ? t : void 0;
|
|
691
|
+
} catch {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
}, Me = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function", Q = (e) => typeof e == "string" ? e : e.name ?? String(e.id), Ne = 0, $ = class {
|
|
695
|
+
id = Ne++;
|
|
696
|
+
name;
|
|
697
|
+
superKey;
|
|
698
|
+
targets;
|
|
699
|
+
options;
|
|
700
|
+
_compiler;
|
|
701
|
+
get compiler() {
|
|
702
|
+
return this._compiler;
|
|
703
|
+
}
|
|
704
|
+
playback = new a();
|
|
705
|
+
_waAnimations = [];
|
|
706
|
+
startTime = void 0;
|
|
707
|
+
pausedTime = 0;
|
|
708
|
+
t = 0;
|
|
709
|
+
iteration = 0;
|
|
710
|
+
started = !1;
|
|
711
|
+
done = !1;
|
|
712
|
+
reversed = !1;
|
|
713
|
+
paused = !1;
|
|
714
|
+
managed = !1;
|
|
715
|
+
waapiIneligibleReason = void 0;
|
|
716
|
+
unflatten = !0;
|
|
717
|
+
resolvePromise = null;
|
|
718
|
+
_playingPromise = null;
|
|
719
|
+
_boundFrame = this._frame.bind(this);
|
|
720
|
+
_interpOut = {};
|
|
721
|
+
_stableKeys = [];
|
|
722
|
+
_ctorOptions = {};
|
|
723
|
+
get flatKeys() {
|
|
724
|
+
return this._stableKeys;
|
|
725
|
+
}
|
|
726
|
+
_defaultTransform = (e) => q(e, this.targets);
|
|
727
|
+
usesDefaultRenderer(e) {
|
|
728
|
+
return e === this._defaultTransform;
|
|
729
|
+
}
|
|
730
|
+
dispatchAnimationEvent(e) {
|
|
731
|
+
if (!(typeof AnimationEvent > "u")) for (let t of this.targets) typeof t?.dispatchEvent == "function" && t.dispatchEvent(new AnimationEvent(e, {
|
|
732
|
+
animationName: this.name ?? "",
|
|
733
|
+
elapsedTime: this.t / 1e3
|
|
734
|
+
}));
|
|
735
|
+
}
|
|
736
|
+
constructor(e, t, n, r) {
|
|
737
|
+
this.options = {}, this._compiler = new Se(this.options), this._ctorOptions = e ?? {}, this.setOptions({
|
|
738
|
+
...P,
|
|
739
|
+
...this._ctorOptions
|
|
740
|
+
}), this.targets = t == null ? [] : Array.isArray(t) ? t : [t], this.name = n, this.superKey = r;
|
|
741
|
+
}
|
|
742
|
+
get templateFrames() {
|
|
743
|
+
return this.compiler.templateFrames;
|
|
744
|
+
}
|
|
745
|
+
set templateFrames(e) {
|
|
746
|
+
this.compiler.templateFrames = e;
|
|
747
|
+
}
|
|
748
|
+
get parsedVars() {
|
|
749
|
+
return this.compiler.parsedVars;
|
|
750
|
+
}
|
|
751
|
+
get frames() {
|
|
752
|
+
return this.compiler.frames;
|
|
753
|
+
}
|
|
754
|
+
get frameId() {
|
|
755
|
+
return this.compiler.frameId;
|
|
756
|
+
}
|
|
757
|
+
addFrame(e, t, n, r) {
|
|
758
|
+
return this.compiler.addFrame(e, t, n, r), this;
|
|
759
|
+
}
|
|
760
|
+
parse() {
|
|
761
|
+
return this.compiler.parse(this.targets), this.computeStableKeys(), this;
|
|
762
|
+
}
|
|
763
|
+
adoptCompiled(e) {
|
|
764
|
+
return this._compiler = e.compiler, this.options = this.compiler.options, this.unflatten = e.unflatten, this.computeStableKeys(), this;
|
|
765
|
+
}
|
|
766
|
+
computeStableKeys() {
|
|
767
|
+
let e = /* @__PURE__ */ new Set();
|
|
768
|
+
for (let t of this.frames) for (let n in t.flatVars) e.add(n);
|
|
769
|
+
this._stableKeys = [...e];
|
|
770
|
+
}
|
|
771
|
+
setTimingFunction(e) {
|
|
772
|
+
return this.options.timingFunction = e == null ? P.timingFunction : J("timingFunction", e), this;
|
|
773
|
+
}
|
|
774
|
+
setIterationCount(t) {
|
|
775
|
+
return t == null ? (this.options.iterationCount = P.iterationCount, this) : t === "infinite" || t === "∞" || t === "Infinity" || t === Infinity ? (this.options.iterationCount = Infinity, this) : (this.options.iterationCount = e("iterationCount", t, (e) => {
|
|
776
|
+
let t = typeof e == "string" ? Number.parseFloat(e.trim()) : e;
|
|
777
|
+
return typeof t == "number" && !Number.isNaN(t) && t >= 0 ? t : void 0;
|
|
778
|
+
}, "expected a non-negative count, \"infinite\", or Infinity"), this);
|
|
779
|
+
}
|
|
780
|
+
setDuration(t) {
|
|
781
|
+
if (t == null) return this;
|
|
782
|
+
let n = e("duration", t, (e) => {
|
|
783
|
+
let t = typeof e == "string" ? Z(e) : e;
|
|
784
|
+
return typeof t == "number" && isFinite(t) && t > 0 ? t : void 0;
|
|
785
|
+
}, "expected a positive duration in milliseconds or a CSS time string"), r = n / this.options.duration;
|
|
786
|
+
for (let e = 0; e < this.frames.length; e++) {
|
|
787
|
+
let t = this.frames[e];
|
|
788
|
+
t.time.start *= r, t.time.stop *= r;
|
|
789
|
+
}
|
|
790
|
+
return this.options.duration = n, this;
|
|
791
|
+
}
|
|
792
|
+
setDelay(t) {
|
|
793
|
+
return t == null ? (this.options.delay = P.delay, this) : (this.options.delay = e("delay", t, (e) => {
|
|
794
|
+
let t = typeof e == "string" ? Z(e) : e;
|
|
795
|
+
return typeof t == "number" && isFinite(t) ? t : void 0;
|
|
796
|
+
}, "expected a delay in milliseconds or a CSS time string"), this);
|
|
797
|
+
}
|
|
798
|
+
setDirection(e) {
|
|
799
|
+
if (e == null) e = P.direction;
|
|
800
|
+
else if (!A.includes(e)) throw new i("direction", e, `expected one of: ${A.join(", ")}`);
|
|
801
|
+
return this.options.direction = e, 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;
|
|
802
|
+
}
|
|
803
|
+
setFillMode(e) {
|
|
804
|
+
if (e == null) e = P.fillMode;
|
|
805
|
+
else if (!j.includes(e)) throw new i("fillMode", e, `expected one of: ${j.join(", ")}`);
|
|
806
|
+
return this.options.fillMode = e, this;
|
|
807
|
+
}
|
|
808
|
+
setUseWAAPI(e) {
|
|
809
|
+
if (e == null) return this.options.useWAAPI = P.useWAAPI, this;
|
|
810
|
+
if (typeof e != "boolean") throw new i("useWAAPI", e, "expected a boolean");
|
|
811
|
+
return this.options.useWAAPI = e, this;
|
|
812
|
+
}
|
|
813
|
+
setRespectReducedMotion(e) {
|
|
814
|
+
if (e == null) return this.options.respectReducedMotion = P.respectReducedMotion, this;
|
|
815
|
+
if (typeof e != "boolean") throw new i("respectReducedMotion", e, "expected a boolean");
|
|
816
|
+
return this.options.respectReducedMotion = e, this;
|
|
817
|
+
}
|
|
818
|
+
setColorSpace(e) {
|
|
819
|
+
if (e == null) return this.options.colorSpace = P.colorSpace, this;
|
|
820
|
+
if (!M.includes(e)) throw new i("colorSpace", e, `expected one of: ${M.join(", ")}`);
|
|
821
|
+
return this.options.colorSpace = e, this.frames.length > 0 && this.compiler.renormalizeColors(), this;
|
|
822
|
+
}
|
|
823
|
+
setHueMethod(e) {
|
|
824
|
+
if (e == null) return this;
|
|
825
|
+
if (!N.includes(e)) throw new i("hueMethod", e, `expected one of: ${N.join(", ")}`);
|
|
826
|
+
return this.options.hueMethod = e, this.frames.length > 0 && this.compiler.renormalizeColors(), this;
|
|
827
|
+
}
|
|
828
|
+
setOptions(e) {
|
|
829
|
+
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;
|
|
830
|
+
}
|
|
831
|
+
reverse() {
|
|
832
|
+
if (this.startTime !== void 0) {
|
|
833
|
+
let e = this.t, t = this.options.duration - 2 * e;
|
|
834
|
+
this.startTime -= t;
|
|
835
|
+
}
|
|
836
|
+
return this.reversed = !this.reversed, this;
|
|
837
|
+
}
|
|
838
|
+
fillForwards() {
|
|
839
|
+
this.interpFrames(this.options.duration, !0);
|
|
840
|
+
}
|
|
841
|
+
fillBackwards() {
|
|
842
|
+
this.interpFrames(0, !0);
|
|
843
|
+
}
|
|
844
|
+
get restPosition() {
|
|
845
|
+
return this.options.fillMode === "forwards" || this.options.fillMode === "both" ? "final" : "initial";
|
|
846
|
+
}
|
|
847
|
+
paintRest() {
|
|
848
|
+
this.restPosition === "final" ? this.fillForwards() : this.fillBackwards();
|
|
849
|
+
}
|
|
850
|
+
at(e, t = !1) {
|
|
851
|
+
let n = this.reversed;
|
|
852
|
+
this.reversed = !1;
|
|
853
|
+
let r = h(e, 0, 1) * this.options.duration, i = this.interpFrames(r, t);
|
|
854
|
+
return this.reversed = n, i;
|
|
855
|
+
}
|
|
856
|
+
interpFrames(e, t = !1, r) {
|
|
857
|
+
e = this.reversed ? this.options.duration - e : e;
|
|
858
|
+
let i = this.frames, a = i.length, o = n(i, e, (e) => e.time.start, (e) => e.time.stop);
|
|
859
|
+
if (o === -1) return r === void 0 ? {} : (this.clearBuffer(r), r);
|
|
860
|
+
let s = o, c = o;
|
|
861
|
+
for (let t = o - 1; t >= 0; t--) {
|
|
862
|
+
let n = i[t];
|
|
863
|
+
if (e < n.time.start || e > n.time.stop) break;
|
|
864
|
+
s = t;
|
|
865
|
+
}
|
|
866
|
+
for (let t = o + 1; t < a; t++) {
|
|
867
|
+
let n = i[t];
|
|
868
|
+
if (e < n.time.start || e > n.time.stop) break;
|
|
869
|
+
c = t;
|
|
870
|
+
}
|
|
871
|
+
for (let n = s; n <= c; n++) this.processFrame(i[n], e, t);
|
|
872
|
+
if (s === c) {
|
|
873
|
+
let e = i[o].flatVars;
|
|
874
|
+
return r === void 0 ? e : (this.clearBuffer(r), Object.assign(r, e), r);
|
|
875
|
+
}
|
|
876
|
+
let l = r ?? {};
|
|
877
|
+
r !== void 0 && this.clearBuffer(r);
|
|
878
|
+
for (let e = s; e <= c; e++) Object.assign(l, i[e].flatVars);
|
|
879
|
+
return l;
|
|
880
|
+
}
|
|
881
|
+
clearBuffer(e) {
|
|
882
|
+
let t = this._stableKeys;
|
|
883
|
+
for (let n = 0; n < t.length; n++) e[t[n]] = void 0;
|
|
884
|
+
}
|
|
885
|
+
processFrame(e, t, n) {
|
|
886
|
+
let { start: r, stop: i } = e.time, a = r === i ? 1 : le(t, r, i, 0, 1), o = e.timingFunction.fn(a);
|
|
887
|
+
for (let t of e.allInterpVars) ae(o, t);
|
|
888
|
+
n && e.transform(this.unflatten ? e.vars : e.flatVars, t);
|
|
889
|
+
}
|
|
890
|
+
async onStart() {
|
|
891
|
+
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 w(this.options.delay), this.paused = !1), this.started = !0;
|
|
892
|
+
}
|
|
893
|
+
async onEnd() {
|
|
894
|
+
this.paintRest(), 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"));
|
|
895
|
+
}
|
|
896
|
+
async advanceTo(e) {
|
|
897
|
+
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;
|
|
898
|
+
if (this.pausedTime > 0 && !this.paused) {
|
|
899
|
+
let t = e - this.pausedTime;
|
|
900
|
+
this.startTime += t, this.pausedTime = 0;
|
|
901
|
+
}
|
|
902
|
+
return this.t = e - this.startTime, this.t >= this.options.duration && (await this.onEnd(), this.t = this.options.duration), this.t;
|
|
903
|
+
}
|
|
904
|
+
async _frame(e) {
|
|
905
|
+
return o(this.options.respectReducedMotion, () => !0, () => !1) ? (await this._snapToReducedMotion(), !1) : (e = await this.advanceTo(e), this.paused ? !1 : this.done ? (this.settle(), this._resolvePlay(), !1) : (this.interpFrames(e, !0, this._interpOut), !0));
|
|
906
|
+
}
|
|
907
|
+
_resolvePlay() {
|
|
908
|
+
let e = this.resolvePromise;
|
|
909
|
+
this.resolvePromise = null, e?.();
|
|
910
|
+
}
|
|
911
|
+
_playRAF() {
|
|
912
|
+
return new Promise((e) => {
|
|
913
|
+
this.resolvePromise = e, this.playback.loop(this._boundFrame);
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
async _playWAAPI() {
|
|
917
|
+
await je(this), this.settle();
|
|
918
|
+
}
|
|
919
|
+
_cancelWAAPI() {
|
|
920
|
+
if (this._waAnimations.length !== 0) {
|
|
921
|
+
for (let e of this._waAnimations) try {
|
|
922
|
+
e.cancel();
|
|
923
|
+
} catch {}
|
|
924
|
+
this._waAnimations = [];
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
async _playReducedMotion() {
|
|
928
|
+
this.started = !0, this.dispatchAnimationEvent("animationstart"), this.fillForwards(), this.iteration = 0, this.done = !0, this.dispatchAnimationEvent("animationend"), this.settle();
|
|
929
|
+
}
|
|
930
|
+
async _snapToReducedMotion() {
|
|
931
|
+
this._cancelWAAPI(), this.fillForwards(), this.iteration = 0, this.done = !0, this.dispatchAnimationEvent("animationend"), this.settle(), this._resolvePlay();
|
|
932
|
+
}
|
|
933
|
+
get finished() {
|
|
934
|
+
return this._playingPromise ?? Promise.resolve();
|
|
935
|
+
}
|
|
936
|
+
async play() {
|
|
937
|
+
if (this.managed) throw Error("Animation.play() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play() instead.");
|
|
938
|
+
if (this._playingPromise) return this._playingPromise;
|
|
939
|
+
let e = o(this.options.respectReducedMotion, () => (this.waapiIneligibleReason = void 0, this._playReducedMotion()), () => {
|
|
940
|
+
if (this.options.useWAAPI) {
|
|
941
|
+
let e = Te(this);
|
|
942
|
+
return e.eligible ? (this.waapiIneligibleReason = void 0, this._playWAAPI()) : (this.waapiIneligibleReason = e.reason, this._playRAF());
|
|
943
|
+
}
|
|
944
|
+
return this.waapiIneligibleReason = void 0, this._playRAF();
|
|
945
|
+
});
|
|
946
|
+
return this._playingPromise = e, e.finally(() => {
|
|
947
|
+
this._playingPromise = null;
|
|
948
|
+
}), e;
|
|
949
|
+
}
|
|
950
|
+
pause() {
|
|
951
|
+
return this.started && (this.paused = !0), this;
|
|
952
|
+
}
|
|
953
|
+
resume() {
|
|
954
|
+
if (this.started && this.paused) if (this.paused = !1, this._waAnimations.length > 0) for (let e of this._waAnimations) e.play();
|
|
955
|
+
else this.playback.running || this.playback.loop(this._boundFrame);
|
|
956
|
+
return this;
|
|
957
|
+
}
|
|
958
|
+
toggle() {
|
|
959
|
+
return this.paused ? this.resume() : this.pause();
|
|
960
|
+
}
|
|
961
|
+
stop() {
|
|
962
|
+
this._cancelWAAPI(), this.playback.stop(), this.settle(), this._resolvePlay();
|
|
963
|
+
}
|
|
964
|
+
playing() {
|
|
965
|
+
return !(!this.started || this.paused);
|
|
966
|
+
}
|
|
967
|
+
get effectiveT() {
|
|
968
|
+
return this.reversed ? this.options.duration - this.t : this.t;
|
|
969
|
+
}
|
|
970
|
+
settle() {
|
|
971
|
+
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;
|
|
972
|
+
}
|
|
973
|
+
reset() {
|
|
974
|
+
return this._cancelWAAPI(), this.started && this.frames.length > 0 && this.fillBackwards(), this.settle();
|
|
975
|
+
}
|
|
976
|
+
setTargets(...e) {
|
|
977
|
+
return this.targets = e, this.frames.forEach((e) => {
|
|
978
|
+
Object.values(e.interpVars).forEach((e) => {
|
|
979
|
+
e.forEach(({ start: e, stop: t, value: n }) => {
|
|
980
|
+
e.setTargets(this.targets), t.setTargets(this.targets), n.setTargets(this.targets);
|
|
981
|
+
});
|
|
982
|
+
});
|
|
983
|
+
}), this;
|
|
984
|
+
}
|
|
985
|
+
group(...e) {
|
|
986
|
+
return new B(this, ...e);
|
|
987
|
+
}
|
|
988
|
+
}, Pe = class extends $ {
|
|
989
|
+
constructor(e, ...t) {
|
|
990
|
+
super(e, t), this.unflatten = !1;
|
|
991
|
+
}
|
|
992
|
+
resolveTransform(e) {
|
|
993
|
+
return this.unflatten = e != null, e ?? this._defaultTransform;
|
|
994
|
+
}
|
|
995
|
+
fromVars(e, t) {
|
|
996
|
+
t = this.resolveTransform(t);
|
|
997
|
+
for (let n = 0; n < e.length; n++) {
|
|
998
|
+
let r = e[n], i = Math.round(n / (e.length - 1) * 100);
|
|
999
|
+
this.addFrame(i, r, t);
|
|
1000
|
+
}
|
|
1001
|
+
return this.parse(), this;
|
|
1002
|
+
}
|
|
1003
|
+
fromKeyframes(e, t) {
|
|
1004
|
+
t = this.resolveTransform(t), ne(e) && (e = new Map(Object.entries(e)));
|
|
1005
|
+
let n = e instanceof Map ? e.entries() : Object.entries(e);
|
|
1006
|
+
for (let [e, r] of n) this.addFrame(e, r, t);
|
|
1007
|
+
return this.parse(), this;
|
|
1008
|
+
}
|
|
1009
|
+
propertyRegistry = /* @__PURE__ */ new Map();
|
|
1010
|
+
fromString(e, t) {
|
|
1011
|
+
t = this.resolveTransform(t);
|
|
1012
|
+
let n = k(e);
|
|
1013
|
+
this.propertyRegistry = n.properties;
|
|
1014
|
+
let i = n.options, a = {};
|
|
1015
|
+
i.duration != null && (a.duration = i.duration), i.timingFunction != null && (a.timingFunction = i.timingFunction), i.iterationCount !== void 0 && (a.iterationCount = i.iterationCount === null ? Infinity : i.iterationCount), i.direction != null && (a.direction = i.direction), i.delay != null && (a.delay = i.delay), i.fillMode != null && (a.fillMode = i.fillMode), Object.keys(a).length > 0 && this.setOptions({
|
|
1016
|
+
...a,
|
|
1017
|
+
...this._ctorOptions
|
|
1018
|
+
});
|
|
1019
|
+
for (let [e, i] of n.keyframes.entries()) {
|
|
1020
|
+
let a = Object.fromEntries(Object.entries(i).map(([e, t]) => [e, Me(t) ? t.clone() : t])), o = n.timingFunctions.get(e), s = o ? W(o) : void 0, c;
|
|
1021
|
+
if (s) {
|
|
1022
|
+
let e = o ? r(o) : void 0;
|
|
1023
|
+
c = e ? {
|
|
1024
|
+
fn: s,
|
|
1025
|
+
css: e
|
|
1026
|
+
} : { fn: s };
|
|
1027
|
+
}
|
|
1028
|
+
this.addFrame(e, a, t, c);
|
|
1029
|
+
}
|
|
1030
|
+
return this.parse(), this.registerProperties(), this;
|
|
1031
|
+
}
|
|
1032
|
+
registerProperties() {
|
|
1033
|
+
if (!(typeof CSS > "u" || typeof CSS.registerProperty != "function")) for (let [e, t] of this.propertyRegistry) {
|
|
1034
|
+
if (t.syntax == null) continue;
|
|
1035
|
+
let n = {
|
|
1036
|
+
name: e,
|
|
1037
|
+
syntax: t.syntax,
|
|
1038
|
+
inherits: t.inherits ?? !1
|
|
1039
|
+
};
|
|
1040
|
+
t.initialValue != null && (n.initialValue = t.initialValue.toString());
|
|
1041
|
+
try {
|
|
1042
|
+
CSS.registerProperty(n);
|
|
1043
|
+
} catch {}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
transform(e) {
|
|
1047
|
+
q(e, this.targets);
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
//#endregion
|
|
1051
|
+
export { $ as Animation, B as AnimationGroup, Pe as CSSKeyframesAnimation, A as DIRECTIONS, j as FILL_MODES, F as defaultLayerConfig, P as defaultOptions, Q as getAnimationId, W as getTimingFunction, k as resolveKeyframes };
|