@mkbabb/keyframes.js 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/{leaves-Bu89334e.js → css-easing-DoPNckiS.js} +17 -1
- package/dist/{engine-DuAFoqZF.js → engine-B7JGZTdU.js} +153 -110
- package/dist/keyframes.d.ts +104 -34
- package/dist/keyframes.js +100 -102
- package/package.json +9 -4
- package/dist/_redirects +0 -1
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { i as e,
|
|
2
|
-
import { COMPUTED_UNITS as
|
|
3
|
-
import { any as
|
|
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
4
|
//#region src/animation/adapter.ts
|
|
5
|
-
var
|
|
5
|
+
var j = (e) => {
|
|
6
6
|
let t = {};
|
|
7
7
|
for (let n of e.declarations) t[n.name] = n.value;
|
|
8
8
|
return t;
|
|
9
|
-
},
|
|
9
|
+
}, M = (e) => {
|
|
10
10
|
let t = [];
|
|
11
11
|
for (let n of e.selectors) n.kind === "percent" ? t.push(`${n.value}%`) : t.push(n.name);
|
|
12
12
|
return t;
|
|
13
|
-
},
|
|
14
|
-
let t =
|
|
13
|
+
}, N = (e) => {
|
|
14
|
+
let t = v(e);
|
|
15
15
|
for (let e of t.values()) if (e.length > 0) return e;
|
|
16
16
|
return [];
|
|
17
|
-
},
|
|
17
|
+
}, P = (e) => {
|
|
18
18
|
let t = e.trim();
|
|
19
19
|
return /@keyframes\b/i.test(t) || t.length === 0 ? e : `@keyframes anonymous {\n${t}\n}`;
|
|
20
|
-
},
|
|
21
|
-
let t = typeof e == "string" ?
|
|
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
22
|
for (let e of n) {
|
|
23
|
-
let t =
|
|
24
|
-
for (let n of
|
|
23
|
+
let t = j(e);
|
|
24
|
+
for (let n of M(e)) {
|
|
25
25
|
let a = r.get(n);
|
|
26
26
|
r.set(n, {
|
|
27
27
|
...a ?? {},
|
|
@@ -32,40 +32,57 @@ var k = (e) => {
|
|
|
32
32
|
return {
|
|
33
33
|
keyframes: r,
|
|
34
34
|
timingFunctions: i,
|
|
35
|
-
properties:
|
|
36
|
-
options:
|
|
35
|
+
properties: ee(t),
|
|
36
|
+
options: _(t)
|
|
37
37
|
};
|
|
38
|
-
},
|
|
38
|
+
}, I = [
|
|
39
39
|
"normal",
|
|
40
40
|
"reverse",
|
|
41
41
|
"alternate",
|
|
42
42
|
"alternate-reverse"
|
|
43
|
-
],
|
|
43
|
+
], L = [
|
|
44
44
|
"none",
|
|
45
45
|
"forwards",
|
|
46
46
|
"backwards",
|
|
47
47
|
"both"
|
|
48
|
-
],
|
|
48
|
+
], R = {
|
|
49
49
|
duration: 1e3,
|
|
50
50
|
delay: 0,
|
|
51
51
|
iterationCount: 1,
|
|
52
52
|
direction: "normal",
|
|
53
53
|
fillMode: "forwards",
|
|
54
|
-
timingFunction:
|
|
54
|
+
timingFunction: g,
|
|
55
55
|
useWAAPI: !0,
|
|
56
|
+
respectReducedMotion: !1,
|
|
56
57
|
colorSpace: "oklab"
|
|
57
|
-
},
|
|
58
|
+
}, z = {
|
|
58
59
|
zIndex: 0,
|
|
59
60
|
weight: 1,
|
|
60
61
|
blendMode: "replace",
|
|
61
62
|
enabled: !0
|
|
62
|
-
}
|
|
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 {
|
|
63
78
|
animations = {};
|
|
64
79
|
transform;
|
|
65
80
|
superKey;
|
|
66
81
|
paused = !1;
|
|
67
82
|
started = !1;
|
|
68
83
|
done = !1;
|
|
84
|
+
respectReducedMotion = !1;
|
|
85
|
+
static YIELD_BATCH = 32;
|
|
69
86
|
singleTarget = !0;
|
|
70
87
|
lastTickTime = 0;
|
|
71
88
|
handleId = void 0;
|
|
@@ -84,7 +101,7 @@ var k = (e) => {
|
|
|
84
101
|
values: {},
|
|
85
102
|
animation: e,
|
|
86
103
|
layer: {
|
|
87
|
-
...
|
|
104
|
+
...z,
|
|
88
105
|
...r
|
|
89
106
|
}
|
|
90
107
|
}, e.managed = !0, t.push(e);
|
|
@@ -127,13 +144,13 @@ var k = (e) => {
|
|
|
127
144
|
case "add":
|
|
128
145
|
for (let [e, n] of Object.entries(s)) if (e in t) {
|
|
129
146
|
let r = t[e], i = n;
|
|
130
|
-
|
|
147
|
+
V(r) && V(i) ? r.value += i.value : t[e] = n;
|
|
131
148
|
} else t[e] = n;
|
|
132
149
|
break;
|
|
133
150
|
case "weighted":
|
|
134
151
|
for (let [e, r] of Object.entries(s)) if (e in t) {
|
|
135
152
|
let i = t[e], o = r;
|
|
136
|
-
|
|
153
|
+
V(i) && V(o) ? i.value = n(i.value, o.value, a.weight) : t[e] = r;
|
|
137
154
|
} else t[e] = r;
|
|
138
155
|
break;
|
|
139
156
|
}
|
|
@@ -153,29 +170,47 @@ var k = (e) => {
|
|
|
153
170
|
}
|
|
154
171
|
async tick(e) {
|
|
155
172
|
this.lastTickTime = e, this.started || this.onStart();
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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));
|
|
160
183
|
}
|
|
161
|
-
|
|
184
|
+
await Promise.all(n);
|
|
162
185
|
}
|
|
163
|
-
async draw(
|
|
164
|
-
if (await this.tick(
|
|
165
|
-
if (this.singleTarget) this.transformFramesGrouped(
|
|
186
|
+
async draw(e) {
|
|
187
|
+
if (await this.tick(e), !this.paused) {
|
|
188
|
+
if (this.singleTarget) this.transformFramesGrouped(e);
|
|
166
189
|
else {
|
|
167
190
|
let e = !0;
|
|
168
191
|
for (let t of this.getEntries()) t.animation.interpFrames(t.animation.t, !0), e &&= t.animation.done;
|
|
169
192
|
this.done = e;
|
|
170
193
|
}
|
|
171
|
-
this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId =
|
|
194
|
+
this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = i(this._boundDraw);
|
|
172
195
|
}
|
|
173
196
|
}
|
|
174
197
|
async play() {
|
|
175
|
-
return new Promise((
|
|
176
|
-
this.resolvePromise =
|
|
198
|
+
return this.respectReducedMotion && r() ? this._playReducedMotion() : new Promise((e) => {
|
|
199
|
+
this.resolvePromise = e, this.handleId = i(this._boundDraw);
|
|
177
200
|
});
|
|
178
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
|
+
}
|
|
179
214
|
pause() {
|
|
180
215
|
if (!this.started) return this;
|
|
181
216
|
this.paused = !this.paused;
|
|
@@ -184,7 +219,7 @@ var k = (e) => {
|
|
|
184
219
|
let n = e.animation;
|
|
185
220
|
this.paused ? (n.pause(!1), n.pausedTime === 0 && (n.pausedTime = t)) : n.paused = !1;
|
|
186
221
|
}
|
|
187
|
-
return this.paused ? (
|
|
222
|
+
return this.paused ? (e(this.handleId), this.handleId = void 0, this.render()) : this.handleId = i(this._boundDraw), this;
|
|
188
223
|
}
|
|
189
224
|
reset() {
|
|
190
225
|
for (let e of this.getEntries()) {
|
|
@@ -194,7 +229,7 @@ var k = (e) => {
|
|
|
194
229
|
return this.started = !1, this.done = !1, this.paused = !1, this.lastTickTime = 0, this;
|
|
195
230
|
}
|
|
196
231
|
stop() {
|
|
197
|
-
return
|
|
232
|
+
return e(this.handleId), this.handleId = void 0, this.reset(), this;
|
|
198
233
|
}
|
|
199
234
|
playing() {
|
|
200
235
|
return !(!this.started || this.paused);
|
|
@@ -219,67 +254,67 @@ var k = (e) => {
|
|
|
219
254
|
let t = typeof e == "string" ? e : Q(e);
|
|
220
255
|
return this.animations[t]?.layer;
|
|
221
256
|
}
|
|
222
|
-
},
|
|
223
|
-
if (e instanceof
|
|
224
|
-
if (e instanceof
|
|
225
|
-
if (e instanceof
|
|
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));
|
|
226
261
|
throw TypeError(`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof e}`);
|
|
227
|
-
},
|
|
262
|
+
}, W = (e) => {
|
|
228
263
|
let t = e.split(".").pop(), n = e.split(".").shift();
|
|
229
264
|
if (!t || !n) throw Error(`Invalid flattened key: ${e}`);
|
|
230
265
|
return {
|
|
231
266
|
mainKey: n,
|
|
232
267
|
childKey: t
|
|
233
268
|
};
|
|
234
|
-
},
|
|
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) => {
|
|
235
270
|
if (e == null) return;
|
|
236
271
|
if (typeof e != "string") return e;
|
|
237
|
-
let t = e.match(
|
|
272
|
+
let t = e.match(K);
|
|
238
273
|
if (t) {
|
|
239
274
|
let e = t.slice(1, 5).map((e) => Number.parseFloat(e ?? ""));
|
|
240
275
|
if (e.length === 4 && e.every((e) => Number.isFinite(e))) {
|
|
241
276
|
let [t, n, r, i] = e;
|
|
242
|
-
return
|
|
277
|
+
return s(t, n, r, i);
|
|
243
278
|
}
|
|
244
279
|
}
|
|
245
280
|
let n = re[e];
|
|
246
281
|
if (typeof n == "function" && n.length <= 1) return n;
|
|
247
|
-
},
|
|
248
|
-
function
|
|
249
|
-
let t =
|
|
250
|
-
let { childKey: r, mainKey: i } =
|
|
251
|
-
if (t instanceof
|
|
252
|
-
if (t instanceof
|
|
253
|
-
if (t instanceof
|
|
254
|
-
let a = String(t),
|
|
255
|
-
if (
|
|
256
|
-
let p =
|
|
257
|
-
return
|
|
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;
|
|
258
293
|
};
|
|
259
294
|
return Object.entries(t).reduce((e, [t, r]) => (e[t] = n(t, r), e), {});
|
|
260
295
|
}
|
|
261
|
-
var
|
|
296
|
+
var se = (e, t, n, r, i = "oklab", a) => {
|
|
262
297
|
let o = r[t], s = r[n];
|
|
263
298
|
if (!o || !s) throw Error(`Invalid interpolation frame bounds (${t} -> ${n}).`);
|
|
264
299
|
let c = o[e], l = s[e];
|
|
265
300
|
if (!c || !l) throw Error(`Missing variable "${e}" in interpolation bounds.`);
|
|
266
|
-
let
|
|
301
|
+
let u = Math.max(c.length, l.length), d = (t) => {
|
|
267
302
|
let n = t.map((t) => {
|
|
268
|
-
if (!(t instanceof
|
|
303
|
+
if (!(t instanceof f)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
269
304
|
return t;
|
|
270
305
|
});
|
|
271
|
-
for (; n.length <
|
|
306
|
+
for (; n.length < u;) n.push(new f(0));
|
|
272
307
|
return n;
|
|
273
|
-
}, p =
|
|
308
|
+
}, p = d(c), m = d(l);
|
|
274
309
|
return p.map((t, n) => {
|
|
275
310
|
let r = m[n];
|
|
276
311
|
if (!r) throw Error(`Missing right-hand interpolation value at index ${n}.`);
|
|
277
|
-
if (!(t instanceof
|
|
312
|
+
if (!(t instanceof f) || !(r instanceof f)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
278
313
|
let o = { colorSpace: i };
|
|
279
|
-
return a !== void 0 && (o.hueMethod = a),
|
|
314
|
+
return a !== void 0 && (o.hueMethod = a), te(S(t, r, o));
|
|
280
315
|
});
|
|
281
316
|
};
|
|
282
|
-
function
|
|
317
|
+
function ce(e, t, n) {
|
|
283
318
|
let [r, i] = [e.start, t.start];
|
|
284
319
|
return {
|
|
285
320
|
start: r.value * n / 100,
|
|
@@ -287,8 +322,8 @@ function J(e, t, n) {
|
|
|
287
322
|
};
|
|
288
323
|
}
|
|
289
324
|
function Y(e, t, n = !0) {
|
|
290
|
-
e = n ? e :
|
|
291
|
-
let r =
|
|
325
|
+
e = n ? e : y(e);
|
|
326
|
+
let r = k(e);
|
|
292
327
|
t.forEach((e) => {
|
|
293
328
|
Object.entries(r).forEach(([t, n]) => {
|
|
294
329
|
e.style.setProperty(t, n);
|
|
@@ -298,8 +333,8 @@ function Y(e, t, n = !0) {
|
|
|
298
333
|
Y[Symbol.for("keyframes.defaultRenderer")] = !0;
|
|
299
334
|
//#endregion
|
|
300
335
|
//#region src/animation/waapi.ts
|
|
301
|
-
var X = (e) => typeof e == "string" &&
|
|
302
|
-
function
|
|
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) {
|
|
303
338
|
if (!e.targets || e.targets.length === 0) return {
|
|
304
339
|
eligible: !1,
|
|
305
340
|
reason: "no DOM targets"
|
|
@@ -308,7 +343,7 @@ function ce(e) {
|
|
|
308
343
|
eligible: !1,
|
|
309
344
|
reason: "target does not implement Element.animate()"
|
|
310
345
|
};
|
|
311
|
-
for (let t of e.frames) if (!
|
|
346
|
+
for (let t of e.frames) if (!ue(t.transform)) return {
|
|
312
347
|
eligible: !1,
|
|
313
348
|
reason: "custom transform function (not the default DOM renderer)"
|
|
314
349
|
};
|
|
@@ -331,14 +366,14 @@ function ce(e) {
|
|
|
331
366
|
}
|
|
332
367
|
return { eligible: !0 };
|
|
333
368
|
}
|
|
334
|
-
function
|
|
369
|
+
function fe(e) {
|
|
335
370
|
let t = e.options.duration, n = [], r = /* @__PURE__ */ new Set();
|
|
336
371
|
for (let t of e.frames) r.add(t.time.start), r.add(t.time.stop);
|
|
337
372
|
let i = [...r].sort((e, t) => e - t);
|
|
338
373
|
for (let r of i) {
|
|
339
374
|
let i = e.interpFrames(r, !1);
|
|
340
375
|
if (Object.keys(i).length === 0) continue;
|
|
341
|
-
let a =
|
|
376
|
+
let a = k(i);
|
|
342
377
|
n.push({
|
|
343
378
|
offset: Math.max(0, Math.min(1, r / t)),
|
|
344
379
|
...a
|
|
@@ -346,32 +381,33 @@ function le(e) {
|
|
|
346
381
|
}
|
|
347
382
|
return n;
|
|
348
383
|
}
|
|
349
|
-
var
|
|
384
|
+
var pe = {
|
|
350
385
|
normal: "normal",
|
|
351
386
|
reverse: "reverse",
|
|
352
387
|
alternate: "alternate",
|
|
353
388
|
"alternate-reverse": "alternate-reverse"
|
|
354
|
-
},
|
|
389
|
+
}, me = {
|
|
355
390
|
none: "none",
|
|
356
391
|
forwards: "forwards",
|
|
357
392
|
backwards: "backwards",
|
|
358
393
|
both: "both"
|
|
359
394
|
};
|
|
360
|
-
function
|
|
361
|
-
let t = e.options, n =
|
|
395
|
+
function he(e) {
|
|
396
|
+
let t = e.options, n = pe[t.direction], r = me[t.fillMode];
|
|
362
397
|
if (n == null) throw TypeError(`Unrecognised animation direction "${t.direction}".`);
|
|
363
398
|
if (r == null) throw TypeError(`Unrecognised animation fill mode "${t.fillMode}".`);
|
|
399
|
+
let i = a(e.frames[0]?.timingFunction ?? e.options.timingFunction) ?? "linear";
|
|
364
400
|
return {
|
|
365
401
|
duration: t.duration,
|
|
366
402
|
delay: t.delay,
|
|
367
403
|
iterations: t.iterationCount === Infinity ? Infinity : t.iterationCount,
|
|
368
404
|
direction: n,
|
|
369
405
|
fill: r,
|
|
370
|
-
easing:
|
|
406
|
+
easing: i
|
|
371
407
|
};
|
|
372
408
|
}
|
|
373
|
-
async function
|
|
374
|
-
let t =
|
|
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) => {
|
|
375
411
|
if (!(i || e.done)) {
|
|
376
412
|
if (e.tick(t), e.paused) for (let e of r) e.pause();
|
|
377
413
|
else for (let e of r) e.playState === "paused" && e.play();
|
|
@@ -387,8 +423,8 @@ async function fe(e) {
|
|
|
387
423
|
}
|
|
388
424
|
//#endregion
|
|
389
425
|
//#region src/animation/engine.ts
|
|
390
|
-
var
|
|
391
|
-
id =
|
|
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++;
|
|
392
428
|
name;
|
|
393
429
|
superKey;
|
|
394
430
|
targets;
|
|
@@ -420,25 +456,25 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
420
456
|
}
|
|
421
457
|
constructor(e, t, n, r) {
|
|
422
458
|
this.options = {}, this.setOptions({
|
|
423
|
-
...
|
|
459
|
+
...R,
|
|
424
460
|
...e ?? {}
|
|
425
461
|
}), this.targets = t == null ? [] : Array.isArray(t) ? t : [t], this.name = n, this.superKey = r;
|
|
426
462
|
}
|
|
427
463
|
convertFrameStart(e) {
|
|
428
464
|
if (e.start.unit === "s" || e.start.unit === "ms" || !e.start.unit) {
|
|
429
|
-
let t = e.start.unit === "s" ? "s" : "ms", n =
|
|
465
|
+
let t = e.start.unit === "s" ? "s" : "ms", n = h(e.start.value, t);
|
|
430
466
|
e.start.value = n / this.options.duration * 100, e.start.unit = "%";
|
|
431
467
|
}
|
|
432
|
-
return e.start.value =
|
|
468
|
+
return e.start.value = m(e.start.value, 0, 100), e;
|
|
433
469
|
}
|
|
434
470
|
addFrame(e, t, n, r) {
|
|
435
|
-
typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof
|
|
436
|
-
let i =
|
|
471
|
+
typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof f && (e = String(e));
|
|
472
|
+
let i = T(e), a = {
|
|
437
473
|
id: this.frameId,
|
|
438
474
|
start: i,
|
|
439
475
|
vars: t,
|
|
440
476
|
transform: n,
|
|
441
|
-
timingFunction:
|
|
477
|
+
timingFunction: q(r) ?? this.options.timingFunction
|
|
442
478
|
};
|
|
443
479
|
return this.convertFrameStart(a), this.templateFrames.push(a), this.frameId += 1, this;
|
|
444
480
|
}
|
|
@@ -446,14 +482,14 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
446
482
|
let n = this.templateFrames[e], r = this.templateFrames[t], i = {
|
|
447
483
|
start: e,
|
|
448
484
|
stop: t
|
|
449
|
-
}, a =
|
|
485
|
+
}, a = ce(n, r, this.options.duration), o = n.transform;
|
|
450
486
|
if (o == null) {
|
|
451
|
-
let t =
|
|
487
|
+
let t = O(e, this.frames, (e) => e.transform != null);
|
|
452
488
|
o = this.frames[t].transform;
|
|
453
489
|
}
|
|
454
490
|
let s = n.timingFunction;
|
|
455
491
|
if (s == null) {
|
|
456
|
-
let t =
|
|
492
|
+
let t = O(e, this.frames, (e) => e.timingFunction != null);
|
|
457
493
|
s = this.frames[t].timingFunction;
|
|
458
494
|
}
|
|
459
495
|
return {
|
|
@@ -489,12 +525,12 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
489
525
|
}
|
|
490
526
|
if (i === -1) continue;
|
|
491
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];
|
|
492
|
-
c.interpVars[r] =
|
|
528
|
+
c.interpVars[r] = se(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
|
|
493
529
|
}
|
|
494
530
|
}
|
|
495
531
|
parse() {
|
|
496
532
|
this.frames = [], this.templateFrames.sort((e, t) => e.start.value - t.start.value), this.parsedVars = this.templateFrames.map((e) => {
|
|
497
|
-
let t =
|
|
533
|
+
let t = oe(e.vars);
|
|
498
534
|
return Object.values(t).forEach((e) => {
|
|
499
535
|
e.setTargets(this.targets);
|
|
500
536
|
}), t;
|
|
@@ -506,7 +542,7 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
506
542
|
}), this;
|
|
507
543
|
}
|
|
508
544
|
setTimingFunction(e) {
|
|
509
|
-
return this.options.timingFunction =
|
|
545
|
+
return this.options.timingFunction = q(e) ?? g, this;
|
|
510
546
|
}
|
|
511
547
|
setIterationCount(e) {
|
|
512
548
|
if (!e || e === "infinite" || e === "∞" || e === "Infinity") this.options.iterationCount = Infinity;
|
|
@@ -521,7 +557,7 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
521
557
|
return this;
|
|
522
558
|
}
|
|
523
559
|
setDuration(e) {
|
|
524
|
-
typeof e == "string" && (e =
|
|
560
|
+
typeof e == "string" && (e = w(e));
|
|
525
561
|
let t = e ?? this.options.duration;
|
|
526
562
|
if (!isFinite(t) || t <= 0) return this;
|
|
527
563
|
let n = t / this.options.duration;
|
|
@@ -532,7 +568,7 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
532
568
|
return this.options.duration = t, this;
|
|
533
569
|
}
|
|
534
570
|
setDelay(e) {
|
|
535
|
-
return typeof e == "string" && (e =
|
|
571
|
+
return typeof e == "string" && (e = w(e)), this.options.delay = e ?? 0, this;
|
|
536
572
|
}
|
|
537
573
|
setDirection(e) {
|
|
538
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;
|
|
@@ -543,6 +579,9 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
543
579
|
setUseWAAPI(e) {
|
|
544
580
|
return this.options.useWAAPI = e ?? !0, this;
|
|
545
581
|
}
|
|
582
|
+
setRespectReducedMotion(e) {
|
|
583
|
+
return this.options.respectReducedMotion = e ?? !1, this;
|
|
584
|
+
}
|
|
546
585
|
setColorSpace(e) {
|
|
547
586
|
return this.options.colorSpace = e ?? "oklab", this;
|
|
548
587
|
}
|
|
@@ -550,7 +589,7 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
550
589
|
return e !== void 0 && (this.options.hueMethod = e), this;
|
|
551
590
|
}
|
|
552
591
|
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;
|
|
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;
|
|
554
593
|
}
|
|
555
594
|
reverse() {
|
|
556
595
|
if (this.startTime !== void 0) {
|
|
@@ -568,7 +607,7 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
568
607
|
at(e, t = !1) {
|
|
569
608
|
let n = this.reversed;
|
|
570
609
|
this.reversed = !1;
|
|
571
|
-
let r =
|
|
610
|
+
let r = m(e, 0, 1) * this.options.duration, i = this.interpFrames(r, t);
|
|
572
611
|
return this.reversed = n, i;
|
|
573
612
|
}
|
|
574
613
|
interpFrames(e, n = !1, r = {}) {
|
|
@@ -578,8 +617,8 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
578
617
|
let a = this.frames, o = a.length, s = t(a, e, (e) => e.time.start, (e) => e.time.stop);
|
|
579
618
|
if (s === -1) return i;
|
|
580
619
|
let c = (t) => {
|
|
581
|
-
let { start: r, stop: a } = t.time, o =
|
|
582
|
-
for (let e of t.allInterpVars)
|
|
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);
|
|
583
622
|
n && t.transform(this.unflatten ? t.vars : t.flatVars, e), Object.assign(i, t.flatVars);
|
|
584
623
|
};
|
|
585
624
|
for (let t = s; t >= 0; t--) {
|
|
@@ -610,22 +649,26 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
610
649
|
}
|
|
611
650
|
async draw(e) {
|
|
612
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.");
|
|
613
|
-
e = await this.tick(e), !this.paused && (this.interpFrames(e, !0), this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId =
|
|
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));
|
|
614
653
|
}
|
|
615
654
|
_playRAF() {
|
|
616
655
|
return new Promise((e) => {
|
|
617
|
-
this.resolvePromise = e, this.handleId =
|
|
656
|
+
this.resolvePromise = e, this.handleId = E(this._boundDraw);
|
|
618
657
|
});
|
|
619
658
|
}
|
|
620
659
|
async _playWAAPI() {
|
|
621
|
-
await
|
|
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();
|
|
622
664
|
}
|
|
623
665
|
async play() {
|
|
624
666
|
if (this.managed) throw Error("Animation.play() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play() instead.");
|
|
625
667
|
if (this._playingPromise) return this._playingPromise;
|
|
626
668
|
let e;
|
|
627
|
-
if (this.options.
|
|
628
|
-
|
|
669
|
+
if (this.options.respectReducedMotion && r()) this.waapiIneligibleReason = void 0, e = this._playReducedMotion();
|
|
670
|
+
else if (this.options.useWAAPI) {
|
|
671
|
+
let t = de(this);
|
|
629
672
|
t.eligible ? (this.waapiIneligibleReason = void 0, e = this._playWAAPI()) : (this.waapiIneligibleReason = t.reason, e = this._playRAF());
|
|
630
673
|
} else this.waapiIneligibleReason = void 0, e = this._playRAF();
|
|
631
674
|
return this._playingPromise = e, e.finally(() => {
|
|
@@ -636,10 +679,10 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
636
679
|
return this.paused && e ? this.resume() : (this.started && (this.paused = !0), this);
|
|
637
680
|
}
|
|
638
681
|
resume() {
|
|
639
|
-
return this.started && this.paused && (this.paused = !1, this.handleId =
|
|
682
|
+
return this.started && this.paused && (this.paused = !1, this.handleId = E(this._boundDraw)), this;
|
|
640
683
|
}
|
|
641
684
|
stop() {
|
|
642
|
-
|
|
685
|
+
p(this.handleId), this.reset();
|
|
643
686
|
}
|
|
644
687
|
playing() {
|
|
645
688
|
return !(!this.started || this.paused);
|
|
@@ -660,9 +703,9 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
660
703
|
}), this;
|
|
661
704
|
}
|
|
662
705
|
group(...e) {
|
|
663
|
-
return new
|
|
706
|
+
return new H(this, ...e);
|
|
664
707
|
}
|
|
665
|
-
},
|
|
708
|
+
}, ve = class extends $ {
|
|
666
709
|
constructor(e, ...t) {
|
|
667
710
|
super(e, t), this.unflatten = !1;
|
|
668
711
|
}
|
|
@@ -675,7 +718,7 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
675
718
|
return this.parse(), this;
|
|
676
719
|
}
|
|
677
720
|
fromKeyframes(e, t) {
|
|
678
|
-
this.unflatten = t != null, t ??= this.transform.bind(this),
|
|
721
|
+
this.unflatten = t != null, t ??= this.transform.bind(this), b(e) && (e = new Map(Object.entries(e)));
|
|
679
722
|
let n = e instanceof Map ? e.entries() : Object.entries(e);
|
|
680
723
|
for (let [e, r] of n) this.addFrame(e, r, t);
|
|
681
724
|
return this.parse(), this;
|
|
@@ -683,10 +726,10 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
683
726
|
propertyRegistry = /* @__PURE__ */ new Map();
|
|
684
727
|
fromString(e, t) {
|
|
685
728
|
this.unflatten = t != null, t ??= this.transform.bind(this);
|
|
686
|
-
let n =
|
|
729
|
+
let n = F(e);
|
|
687
730
|
this.propertyRegistry = n.properties;
|
|
688
731
|
for (let [e, r] of n.keyframes.entries()) {
|
|
689
|
-
let i = Object.fromEntries(Object.entries(r).map(([e, t]) => [e,
|
|
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;
|
|
690
733
|
this.addFrame(e, i, t, o);
|
|
691
734
|
}
|
|
692
735
|
return this.parse(), this;
|
|
@@ -696,4 +739,4 @@ var pe = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function",
|
|
|
696
739
|
}
|
|
697
740
|
};
|
|
698
741
|
//#endregion
|
|
699
|
-
export { $ as Animation,
|
|
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 };
|