@mkbabb/keyframes.js 1.2.1 → 2.1.1
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/dist/_redirects +1 -0
- package/dist/keyframes.d.ts +436 -146
- package/dist/keyframes.js +1169 -1521
- package/package.json +100 -93
package/dist/keyframes.js
CHANGED
|
@@ -1,1539 +1,1187 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { COMPUTED_UNITS as e, CSSCubicBezier as t, CSSFunction as n, CSSValues as r, FunctionValue as i, ValueArray as a, ValueUnit as o, cancelAnimationFrame as s, clamp as c, convertToMs as l, easeInOutCubic as u, extractAnimationOptions as d, extractKeyframes as f, extractProperties as p, flattenObject as m, isObject as ee, lerp as h, lerpValue as te, normalizeValueUnits as g, parseCSSStylesheet as _, parseCSSTime as v, parseCSSValueUnit as ne, prepareInterpVar as re, requestAnimationFrame as y, scale as b, seekPreviousValue as x, sleep as ie, timingFunctions as S, tryParse as ae, unflattenObject as oe, unflattenObjectToString as C } from "@mkbabb/value.js";
|
|
2
|
+
import { any as se } from "@mkbabb/parse-that";
|
|
3
|
+
//#region src/animation/internal/binarySearch.ts
|
|
4
|
+
function w(e, t, n, r) {
|
|
5
|
+
let i = 0, a = e.length - 1;
|
|
6
|
+
for (; i <= a;) {
|
|
7
|
+
let o = i + a >> 1, s = e[o];
|
|
8
|
+
if (t < n(s)) a = o - 1;
|
|
9
|
+
else if (t > r(s)) i = o + 1;
|
|
10
|
+
else return o;
|
|
11
|
+
}
|
|
12
|
+
return -1;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Start the animation group. Returns a promise that resolves
|
|
298
|
-
* when all child animations complete (or on explicit stop/reset).
|
|
299
|
-
*/
|
|
300
|
-
async play() {
|
|
301
|
-
return new Promise((t) => {
|
|
302
|
-
this.resolvePromise = t, this.handleId = w(this._boundDraw);
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Toggle pause state. Calling pause() when playing pauses; calling
|
|
307
|
-
* pause() when paused resumes. (Toggle semantics preserved for
|
|
308
|
-
* backward compatibility with demo's toggleAnimationGroup.)
|
|
309
|
-
*
|
|
310
|
-
* On pause: explicitly cancels the rAF loop and renders a final
|
|
311
|
-
* frame snapshot so the visual matches the exact pause moment.
|
|
312
|
-
* On resume: re-registers the rAF loop.
|
|
313
|
-
*/
|
|
314
|
-
pause() {
|
|
315
|
-
if (!this.started) return this;
|
|
316
|
-
this.paused = !this.paused;
|
|
317
|
-
const t = this.lastTickTime || performance.now();
|
|
318
|
-
for (const e of this.getEntries()) {
|
|
319
|
-
const i = e.animation;
|
|
320
|
-
this.paused ? (i.pause(!1), i.pausedTime === 0 && (i.pausedTime = t)) : i.paused = !1;
|
|
321
|
-
}
|
|
322
|
-
return this.paused ? (k(this.handleId), this.handleId = void 0, this.renderPauseFrame()) : this.handleId = w(this._boundDraw), this;
|
|
323
|
-
}
|
|
324
|
-
reset() {
|
|
325
|
-
for (const t of this.getEntries()) {
|
|
326
|
-
const e = t.animation;
|
|
327
|
-
e.started && e.frames.length > 0 && e.interpFrames(0, !0), e.managed = !1, e.reset();
|
|
328
|
-
}
|
|
329
|
-
return this.started = !1, this.done = !1, this.paused = !1, this.lastTickTime = 0, this;
|
|
330
|
-
}
|
|
331
|
-
stop() {
|
|
332
|
-
return k(this.handleId), this.handleId = void 0, this.reset(), this;
|
|
333
|
-
}
|
|
334
|
-
playing() {
|
|
335
|
-
return !(!this.started || this.paused);
|
|
336
|
-
}
|
|
337
|
-
forcePause() {
|
|
338
|
-
this.paused = !0;
|
|
339
|
-
for (const t of this.getEntries())
|
|
340
|
-
t.animation.paused = !0;
|
|
341
|
-
}
|
|
342
|
-
forcePlay() {
|
|
343
|
-
this.paused = !1;
|
|
344
|
-
for (const t of this.getEntries())
|
|
345
|
-
t.animation.paused = !1;
|
|
346
|
-
}
|
|
347
|
-
// ── Layer management API ─────────────────────────────────────────
|
|
348
|
-
/** Set layer config for an animation by name or reference. Chainable. */
|
|
349
|
-
setLayerConfig(t, e) {
|
|
350
|
-
const i = typeof t == "string" ? t : x(t), r = this.animations[i];
|
|
351
|
-
return r && (Object.assign(r.layer, e), this.invalidateEntries()), this;
|
|
352
|
-
}
|
|
353
|
-
/** Convenience toggle for enabling/disabling a layer. Chainable. */
|
|
354
|
-
setLayerEnabled(t, e) {
|
|
355
|
-
return this.setLayerConfig(t, { enabled: e });
|
|
356
|
-
}
|
|
357
|
-
/** Read the layer config for an animation. */
|
|
358
|
-
getLayerConfig(t) {
|
|
359
|
-
const e = typeof t == "string" ? t : x(t);
|
|
360
|
-
return this.animations[e]?.layer;
|
|
361
|
-
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/animation/adapter.ts
|
|
16
|
+
var ce = (e) => {
|
|
17
|
+
let t = {};
|
|
18
|
+
for (let n of e.declarations) t[n.name] = n.value;
|
|
19
|
+
return t;
|
|
20
|
+
}, T = (e) => {
|
|
21
|
+
let t = [];
|
|
22
|
+
for (let n of e.selectors) n.kind === "percent" ? t.push(`${n.value}%`) : t.push(n.name);
|
|
23
|
+
return t;
|
|
24
|
+
}, E = (e) => {
|
|
25
|
+
let t = f(e);
|
|
26
|
+
for (let e of t.values()) if (e.length > 0) return e;
|
|
27
|
+
return [];
|
|
28
|
+
}, D = (e) => {
|
|
29
|
+
let t = e.trim();
|
|
30
|
+
return /@keyframes\b/i.test(t) || t.length === 0 ? e : `@keyframes anonymous {\n${t}\n}`;
|
|
31
|
+
}, O = (e) => {
|
|
32
|
+
let t = typeof e == "string" ? _(D(e)) : e, n = E(t), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
33
|
+
for (let e of n) {
|
|
34
|
+
let t = ce(e);
|
|
35
|
+
for (let n of T(e)) {
|
|
36
|
+
let a = r.get(n);
|
|
37
|
+
r.set(n, {
|
|
38
|
+
...a ?? {},
|
|
39
|
+
...t
|
|
40
|
+
}), e.timingFunction != null && i.set(n, e.timingFunction);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
keyframes: r,
|
|
45
|
+
timingFunctions: i,
|
|
46
|
+
properties: p(t),
|
|
47
|
+
options: d(t)
|
|
48
|
+
};
|
|
49
|
+
}, le = [
|
|
50
|
+
"normal",
|
|
51
|
+
"reverse",
|
|
52
|
+
"alternate",
|
|
53
|
+
"alternate-reverse"
|
|
54
|
+
], ue = [
|
|
55
|
+
"none",
|
|
56
|
+
"forwards",
|
|
57
|
+
"backwards",
|
|
58
|
+
"both"
|
|
59
|
+
], k = {
|
|
60
|
+
duration: 1e3,
|
|
61
|
+
delay: 0,
|
|
62
|
+
iterationCount: 1,
|
|
63
|
+
direction: "normal",
|
|
64
|
+
fillMode: "forwards",
|
|
65
|
+
timingFunction: u,
|
|
66
|
+
useWAAPI: !0,
|
|
67
|
+
colorSpace: "oklab"
|
|
68
|
+
}, A = {
|
|
69
|
+
zIndex: 0,
|
|
70
|
+
weight: 1,
|
|
71
|
+
blendMode: "replace",
|
|
72
|
+
enabled: !0
|
|
73
|
+
}, j = (e) => typeof e != "object" || !e ? !1 : "value" in e && typeof e.value == "number", M = class {
|
|
74
|
+
animations = {};
|
|
75
|
+
transform;
|
|
76
|
+
superKey;
|
|
77
|
+
paused = !1;
|
|
78
|
+
started = !1;
|
|
79
|
+
done = !1;
|
|
80
|
+
singleTarget = !0;
|
|
81
|
+
lastTickTime = 0;
|
|
82
|
+
handleId = void 0;
|
|
83
|
+
resolvePromise = null;
|
|
84
|
+
_boundDraw;
|
|
85
|
+
_entries = [];
|
|
86
|
+
_entriesDirty = !0;
|
|
87
|
+
constructor(...e) {
|
|
88
|
+
this._boundDraw = this.draw.bind(this);
|
|
89
|
+
let t = [];
|
|
90
|
+
for (let n of e) {
|
|
91
|
+
let e, r;
|
|
92
|
+
n instanceof $ ? e = n : (e = n.animation, r = n.layer), this.transform == null && e.frames[0] != null && (this.transform = e.frames[0].transform);
|
|
93
|
+
let i = Q(e);
|
|
94
|
+
this.animations[i] = {
|
|
95
|
+
values: {},
|
|
96
|
+
animation: e,
|
|
97
|
+
layer: {
|
|
98
|
+
...A,
|
|
99
|
+
...r
|
|
100
|
+
}
|
|
101
|
+
}, e.managed = !0, t.push(e);
|
|
102
|
+
}
|
|
103
|
+
this.singleTarget = t.every((e) => e.targets[0] === t[0]?.targets[0]), this.invalidateEntries();
|
|
104
|
+
}
|
|
105
|
+
getEntries() {
|
|
106
|
+
return this._entriesDirty &&= (this._entries = Object.values(this.animations), this._entries.sort((e, t) => e.layer.zIndex - t.layer.zIndex), !1), this._entries;
|
|
107
|
+
}
|
|
108
|
+
invalidateEntries() {
|
|
109
|
+
this._entriesDirty = !0;
|
|
110
|
+
}
|
|
111
|
+
setSuperKey(e) {
|
|
112
|
+
this.superKey = e;
|
|
113
|
+
for (let t of this.getEntries()) t.animation.superKey = e;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
setTargets(...e) {
|
|
117
|
+
let t = this.getEntries();
|
|
118
|
+
for (let n of t) n.animation.setTargets(...e);
|
|
119
|
+
return this.singleTarget = t.every((e) => e.animation.targets[0] === t[0]?.animation.targets[0]), this;
|
|
120
|
+
}
|
|
121
|
+
onStart() {
|
|
122
|
+
return this.started = !0, this;
|
|
123
|
+
}
|
|
124
|
+
onEnd() {
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
transformFramesGrouped(e) {
|
|
128
|
+
let t = {}, n = this.getEntries(), r = !0;
|
|
129
|
+
for (let e of n) {
|
|
130
|
+
let { animation: n, layer: i, values: a } = e;
|
|
131
|
+
if (r &&= n.done, !i.enabled) continue;
|
|
132
|
+
n.interpFrames(n.t, !1, a);
|
|
133
|
+
let o = i.properties ? Object.fromEntries(Object.entries(a).filter(([e]) => i.properties.has(e))) : a;
|
|
134
|
+
switch (i.blendMode) {
|
|
135
|
+
case "replace":
|
|
136
|
+
Object.assign(t, o);
|
|
137
|
+
break;
|
|
138
|
+
case "add":
|
|
139
|
+
for (let [e, n] of Object.entries(o)) if (e in t) {
|
|
140
|
+
let r = t[e], i = n;
|
|
141
|
+
j(r) && j(i) ? r.value += i.value : t[e] = n;
|
|
142
|
+
} else t[e] = n;
|
|
143
|
+
break;
|
|
144
|
+
case "weighted":
|
|
145
|
+
for (let [e, n] of Object.entries(o)) if (e in t) {
|
|
146
|
+
let r = t[e], a = n;
|
|
147
|
+
j(r) && j(a) ? r.value = h(r.value, a.value, i.weight) : t[e] = n;
|
|
148
|
+
} else t[e] = n;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return this.done = r, this.transform(t, e), t;
|
|
153
|
+
}
|
|
154
|
+
render() {
|
|
155
|
+
let e = this.lastTickTime || performance.now();
|
|
156
|
+
if (this.singleTarget) this.transformFramesGrouped(e);
|
|
157
|
+
else for (let e of this.getEntries()) e.animation.interpFrames(e.animation.t, !0);
|
|
158
|
+
}
|
|
159
|
+
setChildTime(e, t) {
|
|
160
|
+
let n = typeof e == "string" ? e : Q(e), r = this.animations[n];
|
|
161
|
+
if (!r) throw Error(`AnimationGroup.setChildTime: no animation registered for key "${n}". Known keys: ${Object.keys(this.animations).join(", ") || "(none)"}.`);
|
|
162
|
+
let i = r.animation;
|
|
163
|
+
return i.t = t, i.startTime !== void 0 && (i.pausedTime = i.startTime + t), this;
|
|
164
|
+
}
|
|
165
|
+
async tick(e) {
|
|
166
|
+
this.lastTickTime = e, this.started || this.onStart();
|
|
167
|
+
let t = [];
|
|
168
|
+
for (let n of this.getEntries()) {
|
|
169
|
+
let r = n.animation;
|
|
170
|
+
(!r.paused || r.pausedTime === 0) && t.push(r.tick(e));
|
|
171
|
+
}
|
|
172
|
+
return await Promise.all(t), this.done && this.onEnd(), this;
|
|
173
|
+
}
|
|
174
|
+
async draw(e) {
|
|
175
|
+
if (await this.tick(e), !this.paused) {
|
|
176
|
+
if (this.singleTarget) this.transformFramesGrouped(e);
|
|
177
|
+
else {
|
|
178
|
+
let e = !0;
|
|
179
|
+
for (let t of this.getEntries()) t.animation.interpFrames(t.animation.t, !0), e &&= t.animation.done;
|
|
180
|
+
this.done = e;
|
|
181
|
+
}
|
|
182
|
+
this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = y(this._boundDraw);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async play() {
|
|
186
|
+
return new Promise((e) => {
|
|
187
|
+
this.resolvePromise = e, this.handleId = y(this._boundDraw);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
pause() {
|
|
191
|
+
if (!this.started) return this;
|
|
192
|
+
this.paused = !this.paused;
|
|
193
|
+
let e = this.lastTickTime || performance.now();
|
|
194
|
+
for (let t of this.getEntries()) {
|
|
195
|
+
let n = t.animation;
|
|
196
|
+
this.paused ? (n.pause(!1), n.pausedTime === 0 && (n.pausedTime = e)) : n.paused = !1;
|
|
197
|
+
}
|
|
198
|
+
return this.paused ? (s(this.handleId), this.handleId = void 0, this.render()) : this.handleId = y(this._boundDraw), this;
|
|
199
|
+
}
|
|
200
|
+
reset() {
|
|
201
|
+
for (let e of this.getEntries()) {
|
|
202
|
+
let t = e.animation;
|
|
203
|
+
t.started && t.frames.length > 0 && t.interpFrames(0, !0), t.managed = !1, t.reset();
|
|
204
|
+
}
|
|
205
|
+
return this.started = !1, this.done = !1, this.paused = !1, this.lastTickTime = 0, this;
|
|
206
|
+
}
|
|
207
|
+
stop() {
|
|
208
|
+
return s(this.handleId), this.handleId = void 0, this.reset(), this;
|
|
209
|
+
}
|
|
210
|
+
playing() {
|
|
211
|
+
return !(!this.started || this.paused);
|
|
212
|
+
}
|
|
213
|
+
forcePause() {
|
|
214
|
+
this.paused = !0;
|
|
215
|
+
for (let e of this.getEntries()) e.animation.paused = !0;
|
|
216
|
+
}
|
|
217
|
+
forcePlay() {
|
|
218
|
+
this.paused = !1;
|
|
219
|
+
for (let e of this.getEntries()) e.animation.paused = !1;
|
|
220
|
+
}
|
|
221
|
+
setLayerConfig(e, t) {
|
|
222
|
+
let n = typeof e == "string" ? e : Q(e), r = this.animations[n];
|
|
223
|
+
if (!r) throw Error(`AnimationGroup.setLayerConfig: no animation registered for key "${n}". Known keys: ${Object.keys(this.animations).join(", ") || "(none)"}.`);
|
|
224
|
+
return Object.assign(r.layer, t), this.invalidateEntries(), this;
|
|
225
|
+
}
|
|
226
|
+
setLayerEnabled(e, t) {
|
|
227
|
+
return this.setLayerConfig(e, { enabled: t });
|
|
228
|
+
}
|
|
229
|
+
getLayerConfig(e) {
|
|
230
|
+
let t = typeof e == "string" ? e : Q(e);
|
|
231
|
+
return this.animations[t]?.layer;
|
|
232
|
+
}
|
|
233
|
+
}, de = class {
|
|
234
|
+
_rafId = null;
|
|
235
|
+
_startTime = void 0;
|
|
236
|
+
_resolve = null;
|
|
237
|
+
play(e, t) {
|
|
238
|
+
if (e <= 0) throw Error("RAFPlayback.play() requires a duration > 0.");
|
|
239
|
+
return this.stop(), new Promise((n) => {
|
|
240
|
+
this._resolve = n, this._startTime = void 0;
|
|
241
|
+
let r = (n) => {
|
|
242
|
+
this._startTime === void 0 && (this._startTime = n);
|
|
243
|
+
let i = c((n - this._startTime) / e, 0, 1);
|
|
244
|
+
t(i), i < 1 ? this._rafId = y(r) : this._cleanup();
|
|
245
|
+
};
|
|
246
|
+
this._rafId = y(r);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
stop() {
|
|
250
|
+
this._rafId !== null && s(this._rafId), this._cleanup();
|
|
251
|
+
}
|
|
252
|
+
_cleanup() {
|
|
253
|
+
this._rafId = null, this._startTime = void 0;
|
|
254
|
+
let e = this._resolve;
|
|
255
|
+
this._resolve = null, e?.();
|
|
256
|
+
}
|
|
257
|
+
}, N = (e) => {
|
|
258
|
+
if (e instanceof o) return [e.clone()];
|
|
259
|
+
if (e instanceof i) return e.values.flatMap((e) => N(e));
|
|
260
|
+
if (e instanceof a) return e.flatMap((e) => N(e));
|
|
261
|
+
throw TypeError(`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof e}`);
|
|
262
|
+
}, P = (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
|
+
}, F = (e, t, n) => (e.setProperty(t), n !== t && e.setSubProperty(n), e), I = /^\s*cubic-bezier\s*\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)\s*$/i, L = (e) => {
|
|
270
|
+
if (e == null) return;
|
|
271
|
+
if (typeof e != "string") return e;
|
|
272
|
+
let n = e.match(I);
|
|
273
|
+
if (n) {
|
|
274
|
+
let e = n.slice(1, 5).map((e) => Number.parseFloat(e ?? ""));
|
|
275
|
+
if (e.length === 4 && e.every((e) => Number.isFinite(e))) {
|
|
276
|
+
let [n, r, i, a] = e;
|
|
277
|
+
return t(n, r, i, a);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
let r = S[e];
|
|
281
|
+
if (typeof r == "function" && r.length <= 1) return r;
|
|
282
|
+
}, R = /* @__PURE__ */ new Map();
|
|
283
|
+
function z(e) {
|
|
284
|
+
let t = m(e), s = (e, t) => {
|
|
285
|
+
let { childKey: c, mainKey: l } = P(e);
|
|
286
|
+
if (t instanceof o) return F(new a(...N(t)), l, c);
|
|
287
|
+
if (t instanceof i) return F(new a(...t.values.flatMap((t) => N(s(e, t)))), l, c);
|
|
288
|
+
if (t instanceof a) return F(new a(...t.flatMap((t) => N(s(e, t)))), l, c);
|
|
289
|
+
let u = String(t), d = `${c}:${u}`, f = R.get(d);
|
|
290
|
+
if (f) return F(f.clone(), l, c);
|
|
291
|
+
let p = F(new a(...N(ae(se(n.FunctionArgs.map((e) => (e.setSubProperty(c), e)), r.Value), u))), l, c);
|
|
292
|
+
return R.set(d, p.clone()), p;
|
|
293
|
+
};
|
|
294
|
+
return Object.entries(t).reduce((e, [t, n]) => (e[t] = s(t, n), e), {});
|
|
362
295
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
)
|
|
383
|
-
if (typeof s != "number" || !Number.isFinite(s))
|
|
384
|
-
throw new TypeError(
|
|
385
|
-
`Expected numeric ${t}, got ${String(s)}.`
|
|
386
|
-
);
|
|
387
|
-
return s;
|
|
388
|
-
}, H = (s) => {
|
|
389
|
-
if (s.unit !== "color")
|
|
390
|
-
throw new TypeError("Expected a color ValueUnit.");
|
|
391
|
-
return s;
|
|
392
|
-
}, ce = (s) => s, G = /* @__PURE__ */ new WeakMap();
|
|
393
|
-
let he = 0;
|
|
394
|
-
const fe = (s) => {
|
|
395
|
-
let t = G.get(s);
|
|
396
|
-
return t === void 0 && (t = he++, G.set(s, t)), t;
|
|
397
|
-
}, q = V(
|
|
398
|
-
(s, t) => (() => {
|
|
399
|
-
if (!t)
|
|
400
|
-
return s;
|
|
401
|
-
if (s.unit === "var") {
|
|
402
|
-
const r = getComputedStyle(t).getPropertyValue(
|
|
403
|
-
s.value
|
|
404
|
-
);
|
|
405
|
-
return st(r);
|
|
406
|
-
}
|
|
407
|
-
if (s.unit === "calc" && s.property && s.subProperty && s.value && t) {
|
|
408
|
-
const r = ce(t.style), o = r[s.property] ?? "", n = s.subProperty ? `${s.subProperty}(${s.toString()})` : s.toString();
|
|
409
|
-
r[s.property] = n;
|
|
410
|
-
const u = getComputedStyle(t).getPropertyValue(
|
|
411
|
-
s.property
|
|
412
|
-
);
|
|
413
|
-
r[s.property] = o;
|
|
414
|
-
const a = Qt(u);
|
|
415
|
-
if (a instanceof f)
|
|
416
|
-
return a;
|
|
417
|
-
if (a.name.startsWith("matrix")) {
|
|
418
|
-
const c = Tt(a);
|
|
419
|
-
if (ue(s.subProperty)) {
|
|
420
|
-
const l = c[s.subProperty];
|
|
421
|
-
if (l != null)
|
|
422
|
-
return new f(l, "px", [
|
|
423
|
-
"length",
|
|
424
|
-
"absolute"
|
|
425
|
-
]);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
return s;
|
|
430
|
-
})().coalesce(s),
|
|
431
|
-
{
|
|
432
|
-
keyFn: (s, t) => `${s.toString()}-${t ? fe(t) : "null"}`,
|
|
433
|
-
// Don't cache when the element is disconnected (e.g. inside a Teleport
|
|
434
|
-
// defer DocumentFragment). Layout-dependent units like cqw/vh resolve
|
|
435
|
-
// to 0 without a live DOM context.
|
|
436
|
-
shouldCache: (s, t, e) => !e || e.isConnected
|
|
437
|
-
}
|
|
438
|
-
), pe = (s, t, e = !1) => {
|
|
439
|
-
if (s?.superType?.[0] !== t?.superType?.[0])
|
|
440
|
-
return e ? [s, t] : [s.clone(), t.clone()];
|
|
441
|
-
const i = (n) => {
|
|
442
|
-
const u = n?.superType?.[0], a = le(n.value, "ValueUnit");
|
|
443
|
-
switch (u) {
|
|
444
|
-
case "length":
|
|
445
|
-
if (!re(n.unit))
|
|
446
|
-
throw new TypeError(
|
|
447
|
-
`Unsupported length unit: ${String(n.unit)}`
|
|
448
|
-
);
|
|
449
|
-
return {
|
|
450
|
-
value: Ft(
|
|
451
|
-
a,
|
|
452
|
-
n.unit,
|
|
453
|
-
n.targets?.[0]
|
|
454
|
-
),
|
|
455
|
-
unit: "px"
|
|
456
|
-
};
|
|
457
|
-
case "angle":
|
|
458
|
-
if (!ne(n.unit))
|
|
459
|
-
throw new TypeError(
|
|
460
|
-
`Unsupported angle unit: ${String(n.unit)}`
|
|
461
|
-
);
|
|
462
|
-
return {
|
|
463
|
-
value: vt(a, n.unit),
|
|
464
|
-
unit: "deg"
|
|
465
|
-
};
|
|
466
|
-
case "time":
|
|
467
|
-
if (!oe(n.unit))
|
|
468
|
-
throw new TypeError(
|
|
469
|
-
`Unsupported time unit: ${String(n.unit)}`
|
|
470
|
-
);
|
|
471
|
-
return {
|
|
472
|
-
value: it(a, n.unit),
|
|
473
|
-
unit: "ms"
|
|
474
|
-
};
|
|
475
|
-
case "resolution":
|
|
476
|
-
if (!ae(n.unit))
|
|
477
|
-
throw new TypeError(
|
|
478
|
-
`Unsupported resolution unit: ${String(n.unit)}`
|
|
479
|
-
);
|
|
480
|
-
return {
|
|
481
|
-
value: St(a, n.unit),
|
|
482
|
-
unit: "dpi"
|
|
483
|
-
};
|
|
484
|
-
default:
|
|
485
|
-
return {
|
|
486
|
-
value: a,
|
|
487
|
-
unit: typeof n.unit == "string" ? n.unit : ""
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
}, [r, o] = [
|
|
491
|
-
i(s),
|
|
492
|
-
i(t)
|
|
493
|
-
];
|
|
494
|
-
return e ? (s.value = r.value, s.unit = r.unit, t.value = o.value, t.unit = o.unit, [s, t]) : [
|
|
495
|
-
new f(
|
|
496
|
-
r.value,
|
|
497
|
-
r.unit,
|
|
498
|
-
s.superType,
|
|
499
|
-
s.subProperty,
|
|
500
|
-
s.property,
|
|
501
|
-
s.targets
|
|
502
|
-
),
|
|
503
|
-
new f(
|
|
504
|
-
o.value,
|
|
505
|
-
o.unit,
|
|
506
|
-
t.superType,
|
|
507
|
-
t.subProperty,
|
|
508
|
-
t.property,
|
|
509
|
-
t.targets
|
|
510
|
-
)
|
|
511
|
-
];
|
|
296
|
+
var B = (e, t, n, r, i = "oklab", a) => {
|
|
297
|
+
let s = r[t], c = r[n];
|
|
298
|
+
if (!s || !c) throw Error(`Invalid interpolation frame bounds (${t} -> ${n}).`);
|
|
299
|
+
let l = s[e], u = c[e];
|
|
300
|
+
if (!l || !u) throw Error(`Missing variable "${e}" in interpolation bounds.`);
|
|
301
|
+
let d = Math.max(l.length, u.length), f = (t) => {
|
|
302
|
+
let n = t.map((t) => {
|
|
303
|
+
if (!(t instanceof o)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
304
|
+
return t;
|
|
305
|
+
});
|
|
306
|
+
for (; n.length < d;) n.push(new o(0));
|
|
307
|
+
return n;
|
|
308
|
+
}, p = f(l), m = f(u);
|
|
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 o) || !(r instanceof o)) throw TypeError(`Interpolation for "${e}" requires ValueUnit leaves.`);
|
|
313
|
+
let s = { colorSpace: i };
|
|
314
|
+
return a !== void 0 && (s.hueMethod = a), re(g(t, r, s));
|
|
315
|
+
});
|
|
512
316
|
};
|
|
513
|
-
function
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
computed: !1
|
|
520
|
-
};
|
|
521
|
-
if (s.unit === "color" && t.unit === "color") {
|
|
522
|
-
const [o, n] = bt(
|
|
523
|
-
H(s),
|
|
524
|
-
H(t),
|
|
525
|
-
e,
|
|
526
|
-
!1,
|
|
527
|
-
!0,
|
|
528
|
-
!1,
|
|
529
|
-
i
|
|
530
|
-
);
|
|
531
|
-
r.start = o, r.stop = n, r.value = o.clone();
|
|
532
|
-
}
|
|
533
|
-
if (s.unit !== t.unit) {
|
|
534
|
-
const [o, n] = pe(
|
|
535
|
-
s,
|
|
536
|
-
t,
|
|
537
|
-
!0
|
|
538
|
-
);
|
|
539
|
-
r.start = o, r.stop = n, r.value = o.clone();
|
|
540
|
-
}
|
|
541
|
-
return r.computed = X(s.unit) || X(t.unit), r;
|
|
317
|
+
function V(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
|
+
};
|
|
542
323
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
`Expected ValueUnit/FunctionValue/ValueArray, got ${typeof s}`
|
|
552
|
-
);
|
|
553
|
-
}, de = (s) => {
|
|
554
|
-
const t = s.split(".").pop(), e = s.split(".").shift();
|
|
555
|
-
if (!t || !e)
|
|
556
|
-
throw new Error(`Invalid flattened key: ${s}`);
|
|
557
|
-
return { mainKey: e, childKey: t };
|
|
558
|
-
}, P = (s, t, e) => (s.setProperty(t), e !== t && s.setSubProperty(e), s), M = (s) => {
|
|
559
|
-
if (typeof s == "string") {
|
|
560
|
-
const t = rt[s];
|
|
561
|
-
return typeof t == "function" && t.length <= 1 ? t : void 0;
|
|
562
|
-
} else if (s == null)
|
|
563
|
-
return;
|
|
564
|
-
return s;
|
|
565
|
-
};
|
|
566
|
-
function ft(s, { start: t, stop: e, value: i }) {
|
|
567
|
-
const r = t.targets?.[0] ?? e.targets?.[0];
|
|
568
|
-
if (!r)
|
|
569
|
-
throw new Error(
|
|
570
|
-
"Cannot interpolate computed values without a target element."
|
|
571
|
-
);
|
|
572
|
-
const o = q(t, r), n = q(e, r), u = $.includes(o.unit) ? n.unit : o.unit, a = I(s, o.value, n.value);
|
|
573
|
-
return i.value = a, i.unit = u, i;
|
|
574
|
-
}
|
|
575
|
-
function pt(s, { start: t, stop: e, value: i }) {
|
|
576
|
-
return t.value.keys().forEach((r) => {
|
|
577
|
-
const o = t.value[r], n = e.value[r], u = o instanceof f ? o.value : o, a = n instanceof f ? n.value : n, c = I(s, u, a), l = i.value[r];
|
|
578
|
-
l instanceof f ? l.value = c : i.value[r] = c;
|
|
579
|
-
}), i;
|
|
580
|
-
}
|
|
581
|
-
function ge(s, { start: t, stop: e, value: i }) {
|
|
582
|
-
return i.value = I(s, t.value, e.value), i;
|
|
324
|
+
function H(e, t, n = !0) {
|
|
325
|
+
e = n ? e : m(e);
|
|
326
|
+
let r = C(e);
|
|
327
|
+
t.forEach((e) => {
|
|
328
|
+
Object.entries(r).forEach(([t, n]) => {
|
|
329
|
+
e.style.setProperty(t, n);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
583
332
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
return typeof i.value == "number" && typeof r.value == "number" ? t.value.value = I(s, i.value, r.value) : i.unit === "color" ? pt(s, t) : o && ft(s, t), t;
|
|
333
|
+
H[Symbol.for("keyframes.defaultRenderer")] = !0;
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/animation/numeric.ts
|
|
336
|
+
function fe() {
|
|
337
|
+
return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
590
338
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
return S;
|
|
657
|
-
});
|
|
658
|
-
for (; b.length < l; )
|
|
659
|
-
b.push(new f(0));
|
|
660
|
-
return b;
|
|
661
|
-
}, m = h(a), p = h(c);
|
|
662
|
-
return m.map((y, b) => {
|
|
663
|
-
const S = p[b];
|
|
664
|
-
if (!S)
|
|
665
|
-
throw new Error(
|
|
666
|
-
`Missing right-hand interpolation value at index ${b}.`
|
|
667
|
-
);
|
|
668
|
-
if (!(y instanceof f) || !(S instanceof f))
|
|
669
|
-
throw new TypeError(
|
|
670
|
-
`Interpolation for "${s}" requires ValueUnit leaves.`
|
|
671
|
-
);
|
|
672
|
-
const O = me(y, S, r, o);
|
|
673
|
-
return O._lerp = O.computed ? ft : O.start.unit === "color" ? pt : ge, O;
|
|
674
|
-
});
|
|
339
|
+
var pe = (e) => e, U = class {
|
|
340
|
+
keyframes;
|
|
341
|
+
segments;
|
|
342
|
+
positions;
|
|
343
|
+
timingFn;
|
|
344
|
+
result;
|
|
345
|
+
_duration;
|
|
346
|
+
_respectReducedMotion;
|
|
347
|
+
_playback = new de();
|
|
348
|
+
constructor(e, t) {
|
|
349
|
+
if (e.length < 2) throw Error("NumericAnimation requires at least 2 keyframes.");
|
|
350
|
+
if (this.keyframes = e.map((e) => ({ ...e })), this._duration = t?.duration ?? 0, this._respectReducedMotion = t?.respectReducedMotion ?? !1, this.timingFn = (t?.timingFunction ? L(t.timingFunction) : void 0) ?? pe, t?.positions) {
|
|
351
|
+
if (t.positions.length !== e.length) throw Error("positions length must match keyframes length.");
|
|
352
|
+
this.positions = t.positions;
|
|
353
|
+
} else this.positions = e.map((t, n) => n / (e.length - 1) * 100);
|
|
354
|
+
this.result = { ...e[0] }, this.segments = this.buildSegments();
|
|
355
|
+
}
|
|
356
|
+
buildSegments() {
|
|
357
|
+
let e = [];
|
|
358
|
+
for (let t = 0; t < this.keyframes.length - 1; t++) e.push(this.buildSegment(t));
|
|
359
|
+
return e;
|
|
360
|
+
}
|
|
361
|
+
buildSegment(e) {
|
|
362
|
+
let t = this.keyframes[e], n = this.keyframes[e + 1], r = Object.keys(t);
|
|
363
|
+
return {
|
|
364
|
+
startPos: this.positions[e],
|
|
365
|
+
stopPos: this.positions[e + 1],
|
|
366
|
+
keys: r,
|
|
367
|
+
startVals: r.map((e) => t[e]),
|
|
368
|
+
stopVals: r.map((e) => n[e]),
|
|
369
|
+
timingFunction: this.timingFn
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
at(e) {
|
|
373
|
+
let t = c(e, 0, 1) * 100, n = w(this.segments, t, (e) => e.startPos, (e) => e.stopPos);
|
|
374
|
+
n === -1 && (n = this.segments.length - 1);
|
|
375
|
+
let r = this.segments[n], i = b(c(t, r.startPos, r.stopPos), r.startPos, r.stopPos, 0, 1), a = r.timingFunction(i);
|
|
376
|
+
for (let e = 0; e < r.keys.length; e++) this.result[r.keys[e]] = h(r.startVals[e], r.stopVals[e], a);
|
|
377
|
+
return this.result;
|
|
378
|
+
}
|
|
379
|
+
updateKeyframe(e, t) {
|
|
380
|
+
if (e < 0 || e >= this.keyframes.length) throw RangeError(`Keyframe index ${e} out of range [0, ${this.keyframes.length - 1}].`);
|
|
381
|
+
return Object.assign(this.keyframes[e], t), e > 0 && (this.segments[e - 1] = this.buildSegment(e - 1)), e < this.keyframes.length - 1 && (this.segments[e] = this.buildSegment(e)), this;
|
|
382
|
+
}
|
|
383
|
+
play(e, t) {
|
|
384
|
+
let n = t ?? this._duration;
|
|
385
|
+
if (this._respectReducedMotion && fe()) {
|
|
386
|
+
let t = this.at(1);
|
|
387
|
+
return e?.(t), Promise.resolve();
|
|
388
|
+
}
|
|
389
|
+
return this._playback.play(n, (t) => {
|
|
390
|
+
let n = this.at(t);
|
|
391
|
+
e?.(n);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
stop() {
|
|
395
|
+
this._playback.stop();
|
|
396
|
+
}
|
|
397
|
+
}, me = {
|
|
398
|
+
damping: .1,
|
|
399
|
+
snapThreshold: .001,
|
|
400
|
+
targetEpsilon: 0,
|
|
401
|
+
initial: 0,
|
|
402
|
+
clamp: !0,
|
|
403
|
+
respectReducedMotion: !1
|
|
675
404
|
};
|
|
676
|
-
function
|
|
677
|
-
|
|
678
|
-
return {
|
|
679
|
-
start: i.value * e / 100,
|
|
680
|
-
stop: r.value * e / 100
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
function mt(s, t, e = !0) {
|
|
684
|
-
s = e ? s : nt(s);
|
|
685
|
-
const i = ot(s);
|
|
686
|
-
t.forEach((r) => {
|
|
687
|
-
Object.entries(i).forEach(([o, n]) => {
|
|
688
|
-
r.style.setProperty(o, n);
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
const be = (s) => s;
|
|
693
|
-
class Se {
|
|
694
|
-
keyframes;
|
|
695
|
-
segments;
|
|
696
|
-
positions;
|
|
697
|
-
timingFn;
|
|
698
|
-
result;
|
|
699
|
-
_duration;
|
|
700
|
-
// Playback state
|
|
701
|
-
_rafId = null;
|
|
702
|
-
_resolve = null;
|
|
703
|
-
_startTime = void 0;
|
|
704
|
-
constructor(t, e) {
|
|
705
|
-
if (t.length < 2)
|
|
706
|
-
throw new Error(
|
|
707
|
-
"NumericAnimation requires at least 2 keyframes."
|
|
708
|
-
);
|
|
709
|
-
if (this.keyframes = t.map((i) => ({ ...i })), this._duration = e?.duration ?? 0, this.timingFn = (e?.timingFunction ? M(e.timingFunction) : void 0) ?? be, e?.positions) {
|
|
710
|
-
if (e.positions.length !== t.length)
|
|
711
|
-
throw new Error(
|
|
712
|
-
"positions length must match keyframes length."
|
|
713
|
-
);
|
|
714
|
-
this.positions = e.positions;
|
|
715
|
-
} else
|
|
716
|
-
this.positions = t.map(
|
|
717
|
-
(i, r) => r / (t.length - 1) * 100
|
|
718
|
-
);
|
|
719
|
-
this.result = { ...t[0] }, this.segments = this.buildSegments();
|
|
720
|
-
}
|
|
721
|
-
buildSegments() {
|
|
722
|
-
const t = [];
|
|
723
|
-
for (let e = 0; e < this.keyframes.length - 1; e++)
|
|
724
|
-
t.push(this.buildSegment(e));
|
|
725
|
-
return t;
|
|
726
|
-
}
|
|
727
|
-
buildSegment(t) {
|
|
728
|
-
const e = this.keyframes[t], i = this.keyframes[t + 1], r = Object.keys(e);
|
|
729
|
-
return {
|
|
730
|
-
startPos: this.positions[t],
|
|
731
|
-
stopPos: this.positions[t + 1],
|
|
732
|
-
keys: r,
|
|
733
|
-
startVals: r.map((o) => e[o]),
|
|
734
|
-
stopVals: r.map((o) => i[o]),
|
|
735
|
-
timingFunction: this.timingFn
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Map [0, 1] progress to interpolated values. Zero allocation —
|
|
740
|
-
* returns the same pre-allocated result object on every call.
|
|
741
|
-
*
|
|
742
|
-
* Uses O(log N) binary search over segments. Falls back to the
|
|
743
|
-
* last segment if progress is past the final stop position.
|
|
744
|
-
*/
|
|
745
|
-
at(t) {
|
|
746
|
-
const e = E(t, 0, 1) * 100;
|
|
747
|
-
let i = lt(
|
|
748
|
-
this.segments,
|
|
749
|
-
e,
|
|
750
|
-
(u) => u.startPos,
|
|
751
|
-
(u) => u.stopPos
|
|
752
|
-
);
|
|
753
|
-
i === -1 && (i = this.segments.length - 1);
|
|
754
|
-
const r = this.segments[i], o = at(
|
|
755
|
-
E(e, r.startPos, r.stopPos),
|
|
756
|
-
r.startPos,
|
|
757
|
-
r.stopPos,
|
|
758
|
-
0,
|
|
759
|
-
1
|
|
760
|
-
), n = r.timingFunction(o);
|
|
761
|
-
for (let u = 0; u < r.keys.length; u++)
|
|
762
|
-
this.result[r.keys[u]] = I(
|
|
763
|
-
n,
|
|
764
|
-
r.startVals[u],
|
|
765
|
-
r.stopVals[u]
|
|
766
|
-
);
|
|
767
|
-
return this.result;
|
|
768
|
-
}
|
|
769
|
-
/** Update a keyframe's values in-place, recomputing adjacent segments. */
|
|
770
|
-
updateKeyframe(t, e) {
|
|
771
|
-
if (t < 0 || t >= this.keyframes.length)
|
|
772
|
-
throw new RangeError(
|
|
773
|
-
`Keyframe index ${t} out of range [0, ${this.keyframes.length - 1}].`
|
|
774
|
-
);
|
|
775
|
-
return Object.assign(this.keyframes[t], e), t > 0 && (this.segments[t - 1] = this.buildSegment(t - 1)), t < this.keyframes.length - 1 && (this.segments[t] = this.buildSegment(t)), this;
|
|
776
|
-
}
|
|
777
|
-
// ── Playback ─────────────────────────────────────────────────────
|
|
778
|
-
/**
|
|
779
|
-
* Play the animation over its duration using requestAnimationFrame.
|
|
780
|
-
*
|
|
781
|
-
* Calls `onFrame` each frame with the interpolated values (the same
|
|
782
|
-
* zero-allocation object returned by `.at()`). Returns a Promise that
|
|
783
|
-
* resolves when the animation completes or is stopped.
|
|
784
|
-
*
|
|
785
|
-
* @param onFrame — optional per-frame callback receiving interpolated values
|
|
786
|
-
* @param duration — override the duration set in constructor options (ms)
|
|
787
|
-
*/
|
|
788
|
-
play(t, e) {
|
|
789
|
-
const i = e ?? this._duration;
|
|
790
|
-
if (i <= 0)
|
|
791
|
-
throw new Error(
|
|
792
|
-
"NumericAnimation.play() requires a duration > 0. Pass it in the constructor options or as a parameter to play()."
|
|
793
|
-
);
|
|
794
|
-
return this.stop(), new Promise((r) => {
|
|
795
|
-
this._resolve = r, this._startTime = void 0;
|
|
796
|
-
const o = (n) => {
|
|
797
|
-
this._startTime === void 0 && (this._startTime = n);
|
|
798
|
-
const u = E((n - this._startTime) / i, 0, 1), a = this.at(u);
|
|
799
|
-
t?.(a), u < 1 ? this._rafId = w(o) : this._cleanup();
|
|
800
|
-
};
|
|
801
|
-
this._rafId = w(o);
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
/** Cancel a running `.play()` animation. The play promise resolves immediately. */
|
|
805
|
-
stop() {
|
|
806
|
-
this._rafId !== null && k(this._rafId), this._cleanup();
|
|
807
|
-
}
|
|
808
|
-
_cleanup() {
|
|
809
|
-
this._rafId = null, this._startTime = void 0;
|
|
810
|
-
const t = this._resolve;
|
|
811
|
-
this._resolve = null, t?.();
|
|
812
|
-
}
|
|
405
|
+
function W() {
|
|
406
|
+
return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
813
407
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
408
|
+
var G = class {
|
|
409
|
+
options;
|
|
410
|
+
targetValue;
|
|
411
|
+
currentValue;
|
|
412
|
+
isSettled;
|
|
413
|
+
_rafId = null;
|
|
414
|
+
_lastFrameT = 0;
|
|
415
|
+
_onFrame = void 0;
|
|
416
|
+
constructor(e) {
|
|
417
|
+
this.options = {
|
|
418
|
+
...me,
|
|
419
|
+
...e
|
|
420
|
+
}, this.targetValue = this.options.initial, this.currentValue = this.options.initial, this.isSettled = !0;
|
|
421
|
+
}
|
|
422
|
+
get target() {
|
|
423
|
+
return this.targetValue;
|
|
424
|
+
}
|
|
425
|
+
get current() {
|
|
426
|
+
return this.currentValue;
|
|
427
|
+
}
|
|
428
|
+
get settled() {
|
|
429
|
+
return this.isSettled;
|
|
430
|
+
}
|
|
431
|
+
setTarget(e) {
|
|
432
|
+
this.options.clamp && (e = Math.max(0, Math.min(1, e)));
|
|
433
|
+
let t = Math.abs(e - this.targetValue);
|
|
434
|
+
if (t > 0 && t >= this.options.targetEpsilon) {
|
|
435
|
+
if (this.targetValue = e, this.options.respectReducedMotion && W()) {
|
|
436
|
+
this.currentValue = e, this.isSettled = !0, this._onFrame?.(e);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
this.isSettled = !1, this._onFrame && this._rafId === null && this._startLoop();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
tick() {
|
|
443
|
+
return this.isSettled ? this.currentValue : (this.currentValue += (this.targetValue - this.currentValue) * this.options.damping, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(0, Math.min(1, this.currentValue))), this.currentValue);
|
|
444
|
+
}
|
|
445
|
+
tickDt(e) {
|
|
446
|
+
if (this.isSettled) return this.currentValue;
|
|
447
|
+
let t = 1 - Math.exp(-this.options.damping * e / 16.667);
|
|
448
|
+
return this.currentValue += (this.targetValue - this.currentValue) * t, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(0, Math.min(1, this.currentValue))), this.currentValue;
|
|
449
|
+
}
|
|
450
|
+
snap() {
|
|
451
|
+
this.currentValue = this.targetValue, this.isSettled = !0, this._stopLoop();
|
|
452
|
+
}
|
|
453
|
+
reset(e) {
|
|
454
|
+
let t = e ?? 0;
|
|
455
|
+
this.targetValue = t, this.currentValue = t, this.isSettled = !0, this._stopLoop();
|
|
456
|
+
}
|
|
457
|
+
play(e) {
|
|
458
|
+
if (this._onFrame = e, this.options.respectReducedMotion && W()) {
|
|
459
|
+
this.currentValue = this.targetValue, this.isSettled = !0, e?.(this.currentValue);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (this.isSettled) {
|
|
463
|
+
e?.(this.currentValue);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
this._startLoop();
|
|
467
|
+
}
|
|
468
|
+
stop() {
|
|
469
|
+
this._onFrame = void 0, this._stopLoop();
|
|
470
|
+
}
|
|
471
|
+
_startLoop() {
|
|
472
|
+
if (this._rafId !== null) return;
|
|
473
|
+
this._lastFrameT = 0;
|
|
474
|
+
let e = (t) => {
|
|
475
|
+
let n = this._lastFrameT ? t - this._lastFrameT : 16.667;
|
|
476
|
+
this._lastFrameT = t;
|
|
477
|
+
let r = this.tickDt(n);
|
|
478
|
+
if (this._onFrame?.(r), this.isSettled) {
|
|
479
|
+
this._stopLoop();
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
this._rafId = y(e);
|
|
483
|
+
};
|
|
484
|
+
this._rafId = y(e);
|
|
485
|
+
}
|
|
486
|
+
_stopLoop() {
|
|
487
|
+
this._rafId !== null && (s(this._rafId), this._rafId = null), this._lastFrameT = 0;
|
|
488
|
+
}
|
|
489
|
+
}, he = {
|
|
490
|
+
response: .5,
|
|
491
|
+
dampingFraction: .86,
|
|
492
|
+
initial: 0,
|
|
493
|
+
initialVelocity: 0,
|
|
494
|
+
settleThreshold: .001,
|
|
495
|
+
velocitySettleThreshold: .001,
|
|
496
|
+
respectReducedMotion: !1
|
|
820
497
|
};
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
targetValue;
|
|
824
|
-
currentValue;
|
|
825
|
-
isSettled;
|
|
826
|
-
constructor(t) {
|
|
827
|
-
this.options = { ...ve, ...t }, this.targetValue = this.options.initial, this.currentValue = this.options.initial, this.isSettled = !0;
|
|
828
|
-
}
|
|
829
|
-
get target() {
|
|
830
|
-
return this.targetValue;
|
|
831
|
-
}
|
|
832
|
-
get current() {
|
|
833
|
-
return this.currentValue;
|
|
834
|
-
}
|
|
835
|
-
get settled() {
|
|
836
|
-
return this.isSettled;
|
|
837
|
-
}
|
|
838
|
-
setTarget(t) {
|
|
839
|
-
this.options.clamp && (t = Math.max(0, Math.min(1, t)));
|
|
840
|
-
const e = Math.abs(t - this.targetValue);
|
|
841
|
-
e > 0 && e >= this.options.targetEpsilon && (this.targetValue = t, this.isSettled = !1);
|
|
842
|
-
}
|
|
843
|
-
/** Advance one step using fixed damping. Returns current value. */
|
|
844
|
-
tick() {
|
|
845
|
-
return this.isSettled ? this.currentValue : (this.currentValue += (this.targetValue - this.currentValue) * this.options.damping, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(
|
|
846
|
-
0,
|
|
847
|
-
Math.min(1, this.currentValue)
|
|
848
|
-
)), this.currentValue);
|
|
849
|
-
}
|
|
850
|
-
/** Frame-rate independent tick. dt is in milliseconds. */
|
|
851
|
-
tickDt(t) {
|
|
852
|
-
if (this.isSettled) return this.currentValue;
|
|
853
|
-
const e = 1 - Math.exp(-this.options.damping * t / 16.667);
|
|
854
|
-
return this.currentValue += (this.targetValue - this.currentValue) * e, Math.abs(this.targetValue - this.currentValue) < this.options.snapThreshold && (this.currentValue = this.targetValue, this.isSettled = !0), this.options.clamp && (this.currentValue = Math.max(
|
|
855
|
-
0,
|
|
856
|
-
Math.min(1, this.currentValue)
|
|
857
|
-
)), this.currentValue;
|
|
858
|
-
}
|
|
859
|
-
/** Immediately set current = target. */
|
|
860
|
-
snap() {
|
|
861
|
-
this.currentValue = this.targetValue, this.isSettled = !0;
|
|
862
|
-
}
|
|
863
|
-
/** Reset to a specific value (default 0). */
|
|
864
|
-
reset(t) {
|
|
865
|
-
const e = t ?? 0;
|
|
866
|
-
this.targetValue = e, this.currentValue = e, this.isSettled = !0;
|
|
867
|
-
}
|
|
498
|
+
function K() {
|
|
499
|
+
return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
868
500
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
501
|
+
var q = class {
|
|
502
|
+
options;
|
|
503
|
+
targetValue;
|
|
504
|
+
currentValue;
|
|
505
|
+
currentVelocity;
|
|
506
|
+
isSettled;
|
|
507
|
+
elapsed;
|
|
508
|
+
originValue;
|
|
509
|
+
originVelocity;
|
|
510
|
+
omega;
|
|
511
|
+
zeta;
|
|
512
|
+
omegaD;
|
|
513
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
514
|
+
disposed = !1;
|
|
515
|
+
_rafId = null;
|
|
516
|
+
_lastFrameT = 0;
|
|
517
|
+
_onFrame = void 0;
|
|
518
|
+
constructor(e) {
|
|
519
|
+
this.options = {
|
|
520
|
+
...he,
|
|
521
|
+
...e
|
|
522
|
+
}, this.targetValue = this.options.initial, this.currentValue = this.options.initial, this.currentVelocity = this.options.initialVelocity, this.isSettled = this.options.initialVelocity === 0, this.elapsed = 0, this.originValue = this.currentValue, this.originVelocity = this.currentVelocity, this.omega = 2 * Math.PI / this.options.response, this.zeta = this.options.dampingFraction, this.omegaD = this.zeta < 1 ? this.omega * Math.sqrt(1 - this.zeta * this.zeta) : 0;
|
|
523
|
+
}
|
|
524
|
+
get target() {
|
|
525
|
+
return this.targetValue;
|
|
526
|
+
}
|
|
527
|
+
get value() {
|
|
528
|
+
return this.currentValue;
|
|
529
|
+
}
|
|
530
|
+
get velocity() {
|
|
531
|
+
return this.currentVelocity;
|
|
532
|
+
}
|
|
533
|
+
get settled() {
|
|
534
|
+
return this.isSettled;
|
|
535
|
+
}
|
|
536
|
+
set target(e) {
|
|
537
|
+
e === this.targetValue && !this.options.initialVelocity || this.reseatTarget(e);
|
|
538
|
+
}
|
|
539
|
+
reseatTarget(e) {
|
|
540
|
+
if (this.targetValue = e, this.options.respectReducedMotion && K()) {
|
|
541
|
+
this.currentValue = e, this.currentVelocity = 0, this.isSettled = !0, this.originValue = e, this.originVelocity = 0, this.elapsed = 0, this.emit(), this._stopLoop();
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
this.originValue = this.currentValue, this.originVelocity = this.currentVelocity, this.elapsed = 0, this.isSettled = !1, this._onFrame && this._rafId === null && this._startLoop();
|
|
545
|
+
}
|
|
546
|
+
tick(e) {
|
|
547
|
+
return this.disposed || this.isSettled || e <= 0 ? this.currentValue : (this.elapsed += e, this.evaluateAt(this.elapsed), this.checkSettled(), this.emit(), this.currentValue);
|
|
548
|
+
}
|
|
549
|
+
tickToTime(e) {
|
|
550
|
+
return this.disposed || this.isSettled ? this.currentValue : (this.elapsed = Math.max(0, e), this.evaluateAt(this.elapsed), this.checkSettled(), this.emit(), this.currentValue);
|
|
551
|
+
}
|
|
552
|
+
evaluateAt(e) {
|
|
553
|
+
let t = this.originValue - this.targetValue, n = this.originVelocity, r = this.omega, i = this.zeta, a, o;
|
|
554
|
+
if (i < 1) {
|
|
555
|
+
let s = this.omegaD, c = Math.exp(-i * r * e), l = t, u = (n + i * r * t) / s, d = Math.cos(s * e), f = Math.sin(s * e);
|
|
556
|
+
a = c * (l * d + u * f), o = c * ((u * s - l * i * r) * d - (l * s + u * i * r) * f);
|
|
557
|
+
} else if (i === 1) {
|
|
558
|
+
let i = Math.exp(-r * e), s = t, c = n + r * t;
|
|
559
|
+
a = i * (s + c * e), o = i * (c - r * (s + c * e));
|
|
560
|
+
} else {
|
|
561
|
+
let s = r * Math.sqrt(i * i - 1), c = -i * r + s, l = -i * r - s, u = (n - l * t) / (c - l), d = t - u, f = Math.exp(c * e), p = Math.exp(l * e);
|
|
562
|
+
a = u * f + d * p, o = u * c * f + d * l * p;
|
|
563
|
+
}
|
|
564
|
+
this.currentValue = this.targetValue + a, this.currentVelocity = o;
|
|
565
|
+
}
|
|
566
|
+
checkSettled() {
|
|
567
|
+
let e = Math.abs(this.currentValue - this.targetValue), t = Math.abs(this.currentVelocity);
|
|
568
|
+
e < this.options.settleThreshold && t < this.options.velocitySettleThreshold && (this.currentValue = this.targetValue, this.currentVelocity = 0, this.isSettled = !0);
|
|
569
|
+
}
|
|
570
|
+
snap() {
|
|
571
|
+
this.currentValue = this.targetValue, this.currentVelocity = 0, this.originValue = this.targetValue, this.originVelocity = 0, this.elapsed = 0, this.isSettled = !0, this.emit(), this._stopLoop();
|
|
572
|
+
}
|
|
573
|
+
reset(e, t) {
|
|
574
|
+
let n = e ?? 0, r = t ?? 0;
|
|
575
|
+
this.targetValue = n, this.currentValue = n, this.currentVelocity = r, this.originValue = n, this.originVelocity = r, this.elapsed = 0, this.isSettled = r === 0, this.emit(), this._stopLoop();
|
|
576
|
+
}
|
|
577
|
+
subscribe(e) {
|
|
578
|
+
return this.subscribers.add(e), () => {
|
|
579
|
+
this.subscribers.delete(e);
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
emit() {
|
|
583
|
+
if (this.subscribers.size !== 0) for (let e of this.subscribers) e(this.currentValue, this.currentVelocity);
|
|
584
|
+
}
|
|
585
|
+
dispose() {
|
|
586
|
+
this.disposed = !0, this._stopLoop(), this.subscribers.clear();
|
|
587
|
+
}
|
|
588
|
+
play(e) {
|
|
589
|
+
if (!this.disposed) {
|
|
590
|
+
if (this._onFrame = e, this.options.respectReducedMotion && K()) {
|
|
591
|
+
this.currentValue = this.targetValue, this.currentVelocity = 0, this.isSettled = !0, e?.(this.currentValue, this.currentVelocity);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
if (this.isSettled) {
|
|
595
|
+
e?.(this.currentValue, this.currentVelocity);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
this._startLoop();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
stop() {
|
|
602
|
+
this._onFrame = void 0, this._stopLoop();
|
|
603
|
+
}
|
|
604
|
+
_startLoop() {
|
|
605
|
+
if (this._rafId !== null) return;
|
|
606
|
+
this._lastFrameT = 0;
|
|
607
|
+
let e = (t) => {
|
|
608
|
+
let n = this._lastFrameT ? t - this._lastFrameT : 16.667;
|
|
609
|
+
if (this._lastFrameT = t, this.tick(n / 1e3), this._onFrame?.(this.currentValue, this.currentVelocity), this.isSettled) {
|
|
610
|
+
this._stopLoop();
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
this._rafId = y(e);
|
|
614
|
+
};
|
|
615
|
+
this._rafId = y(e);
|
|
616
|
+
}
|
|
617
|
+
_stopLoop() {
|
|
618
|
+
this._rafId !== null && (s(this._rafId), this._rafId = null), this._lastFrameT = 0;
|
|
619
|
+
}
|
|
875
620
|
};
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
895
|
-
/** Get raw transform values at the given progress [0, 1]. */
|
|
896
|
-
at(t) {
|
|
897
|
-
return this.animation.at(t);
|
|
898
|
-
}
|
|
899
|
-
/** Get a CSS transform string at the given progress [0, 1]. */
|
|
900
|
-
toCSSTransform(t) {
|
|
901
|
-
const { translateX: e, translateY: i, scaleX: r, scaleY: o } = this.animation.at(t);
|
|
902
|
-
return `translate(${e}px, ${i}px) scale(${r}, ${o})`;
|
|
903
|
-
}
|
|
904
|
-
/** Apply the morph transform to an element at the given progress [0, 1]. */
|
|
905
|
-
apply(t, e) {
|
|
906
|
-
t.style.transform = this.toCSSTransform(e), t.style.transformOrigin = this.transformOrigin;
|
|
907
|
-
}
|
|
908
|
-
/**
|
|
909
|
-
* Animate an element from source to destination over the configured duration.
|
|
910
|
-
*
|
|
911
|
-
* @param element — the element to apply transforms to
|
|
912
|
-
* @param duration — override the duration set in constructor options (ms)
|
|
913
|
-
*/
|
|
914
|
-
play(t, e) {
|
|
915
|
-
return this.animation.play((i) => {
|
|
916
|
-
const { translateX: r, translateY: o, scaleX: n, scaleY: u } = i;
|
|
917
|
-
t.style.transform = `translate(${r}px, ${o}px) scale(${n}, ${u})`, t.style.transformOrigin = this.transformOrigin;
|
|
918
|
-
}, e ?? this.duration);
|
|
919
|
-
}
|
|
920
|
-
/** Cancel a running `.play()` animation. */
|
|
921
|
-
stop() {
|
|
922
|
-
this.animation.stop();
|
|
923
|
-
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/animation/springLinearStops.ts
|
|
623
|
+
function ge(e) {
|
|
624
|
+
let t = e.sampleCount ?? 24, n = e.settleThreshold ?? .001, r = e.maxDuration ?? e.response * 4, i = new q({
|
|
625
|
+
response: e.response,
|
|
626
|
+
dampingFraction: e.dampingFraction,
|
|
627
|
+
initial: 0,
|
|
628
|
+
settleThreshold: n,
|
|
629
|
+
velocitySettleThreshold: n
|
|
630
|
+
});
|
|
631
|
+
i.target = 1;
|
|
632
|
+
let a = ["0"], o = r / (t + 1);
|
|
633
|
+
for (let e = 1; e <= t; e++) {
|
|
634
|
+
i.tick(o);
|
|
635
|
+
let n = e / (t + 1) * 100, r = i.settled ? 1 : i.value;
|
|
636
|
+
a.push(`${r.toFixed(5)} ${n.toFixed(3)}%`);
|
|
637
|
+
}
|
|
638
|
+
return a.push("1"), i.dispose(), `linear(${a.join(", ")})`;
|
|
924
639
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
*/
|
|
947
|
-
applyPipeline() {
|
|
948
|
-
let t = Pe(this.sample());
|
|
949
|
-
this.easingFn && (t = this.easingFn(t));
|
|
950
|
-
const e = this.boundaryEpsilon;
|
|
951
|
-
return t <= e ? t = 0 : t >= 1 - e && (t = 1), t;
|
|
952
|
-
}
|
|
953
|
-
/**
|
|
954
|
-
* Finalize progress after the smoother has been advanced (or bypassed).
|
|
955
|
-
* Snaps the smoother at boundaries [0, 1] for instant convergence.
|
|
956
|
-
*/
|
|
957
|
-
finalizeProgress(t) {
|
|
958
|
-
return this.smoother && (this.smoother.setTarget(t), (t <= 0 || t >= 1) && this.smoother.snap()), this.currentProgress = this.smoother ? this.smoother.current : t, this.currentProgress;
|
|
959
|
-
}
|
|
960
|
-
/** Advance one frame. Applies easing → boundary snap → smoothing. */
|
|
961
|
-
tick() {
|
|
962
|
-
const t = this.applyPipeline();
|
|
963
|
-
return this.smoother && t > 0 && t < 1 ? (this.smoother.setTarget(t), this.smoother.tick(), this.currentProgress = this.smoother.current) : this.finalizeProgress(t), this.currentProgress;
|
|
964
|
-
}
|
|
965
|
-
/** Frame-rate independent variant. `dt` in milliseconds. */
|
|
966
|
-
tickDt(t) {
|
|
967
|
-
const e = this.applyPipeline();
|
|
968
|
-
return this.smoother && e > 0 && e < 1 ? (this.smoother.setTarget(e), this.smoother.tickDt(t), this.currentProgress = this.smoother.current) : this.finalizeProgress(e), this.currentProgress;
|
|
969
|
-
}
|
|
970
|
-
get progress() {
|
|
971
|
-
return this.currentProgress;
|
|
972
|
-
}
|
|
973
|
-
/** True if no smoother or smoother is settled. */
|
|
974
|
-
get settled() {
|
|
975
|
-
return this.smoother == null || this.smoother.settled;
|
|
976
|
-
}
|
|
977
|
-
/** Immediately converge smoother to current target. */
|
|
978
|
-
snap() {
|
|
979
|
-
this.smoother?.snap(), this.smoother && (this.currentProgress = this.smoother.current);
|
|
980
|
-
}
|
|
981
|
-
/** Reset progress to a specific value (default 0). */
|
|
982
|
-
reset(t) {
|
|
983
|
-
const e = t ?? 0;
|
|
984
|
-
this.smoother && this.smoother.reset(e), this.currentProgress = e;
|
|
985
|
-
}
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/animation/springTimingFunction.ts
|
|
642
|
+
function _e(e) {
|
|
643
|
+
let t = e.sampleCount ?? 64, n = e.settleThreshold ?? .001, r = e.maxDuration ?? e.response * 4, i = new q({
|
|
644
|
+
response: e.response,
|
|
645
|
+
dampingFraction: e.dampingFraction,
|
|
646
|
+
initial: 0,
|
|
647
|
+
settleThreshold: n,
|
|
648
|
+
velocitySettleThreshold: n
|
|
649
|
+
});
|
|
650
|
+
i.target = 1;
|
|
651
|
+
let a = new Float64Array(t + 1);
|
|
652
|
+
a[0] = 0;
|
|
653
|
+
let o = r / t;
|
|
654
|
+
for (let e = 1; e <= t; e++) i.tick(o), a[e] = i.settled ? 1 : i.value;
|
|
655
|
+
return a[t] = 1, i.dispose(), (e) => {
|
|
656
|
+
if (e <= 0) return 0;
|
|
657
|
+
if (e >= 1) return 1;
|
|
658
|
+
let n = e * t, r = Math.floor(n), i = n - r, o = a[r];
|
|
659
|
+
return o + (a[r + 1] - o) * i;
|
|
660
|
+
};
|
|
986
661
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/animation/morph.ts
|
|
664
|
+
var J = (e) => {
|
|
665
|
+
if (e instanceof HTMLElement) {
|
|
666
|
+
let t = e.getBoundingClientRect();
|
|
667
|
+
return {
|
|
668
|
+
x: t.x,
|
|
669
|
+
y: t.y,
|
|
670
|
+
width: t.width,
|
|
671
|
+
height: t.height
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
return e;
|
|
675
|
+
}, ve = class {
|
|
676
|
+
animation;
|
|
677
|
+
transformOrigin;
|
|
678
|
+
timingFunction;
|
|
679
|
+
duration;
|
|
680
|
+
constructor(e, t, n) {
|
|
681
|
+
this.transformOrigin = n?.transformOrigin ?? "top left", this.timingFunction = n?.timingFunction, this.duration = n?.duration ?? 0, this.measure(e, t);
|
|
682
|
+
}
|
|
683
|
+
measure(e, t) {
|
|
684
|
+
let n = J(e), r = J(t), i = r.x - n.x, a = r.y - n.y, o = n.width === 0 ? 1 : r.width / n.width, s = n.height === 0 ? 1 : r.height / n.height;
|
|
685
|
+
return this.animation = new U([{
|
|
686
|
+
translateX: 0,
|
|
687
|
+
translateY: 0,
|
|
688
|
+
scaleX: 1,
|
|
689
|
+
scaleY: 1
|
|
690
|
+
}, {
|
|
691
|
+
translateX: i,
|
|
692
|
+
translateY: a,
|
|
693
|
+
scaleX: o,
|
|
694
|
+
scaleY: s
|
|
695
|
+
}], {
|
|
696
|
+
timingFunction: this.timingFunction,
|
|
697
|
+
duration: this.duration
|
|
698
|
+
}), this;
|
|
699
|
+
}
|
|
700
|
+
at(e) {
|
|
701
|
+
return this.animation.at(e);
|
|
702
|
+
}
|
|
703
|
+
toCSSTransform(e) {
|
|
704
|
+
let { translateX: t, translateY: n, scaleX: r, scaleY: i } = this.animation.at(e);
|
|
705
|
+
return `translate(${t}px, ${n}px) scale(${r}, ${i})`;
|
|
706
|
+
}
|
|
707
|
+
apply(e, t) {
|
|
708
|
+
e.style.transform = this.toCSSTransform(t), e.style.transformOrigin = this.transformOrigin;
|
|
709
|
+
}
|
|
710
|
+
play(e, t) {
|
|
711
|
+
return this.animation.play((t) => {
|
|
712
|
+
let { translateX: n, translateY: r, scaleX: i, scaleY: a } = t;
|
|
713
|
+
e.style.transform = `translate(${n}px, ${r}px) scale(${i}, ${a})`, e.style.transformOrigin = this.transformOrigin;
|
|
714
|
+
}, t ?? this.duration);
|
|
715
|
+
}
|
|
716
|
+
stop() {
|
|
717
|
+
this.animation.stop();
|
|
718
|
+
}
|
|
719
|
+
}, ye = (e) => {
|
|
720
|
+
if (e == null) return null;
|
|
721
|
+
if (typeof e == "function") return e;
|
|
722
|
+
let t = S[e];
|
|
723
|
+
return typeof t == "function" && t.length <= 1 ? t : null;
|
|
724
|
+
}, be = (e) => Math.max(0, Math.min(1, e)), Y = class {
|
|
725
|
+
smoother;
|
|
726
|
+
easingFn;
|
|
727
|
+
currentProgress = 0;
|
|
728
|
+
boundaryEpsilon;
|
|
729
|
+
constructor(e) {
|
|
730
|
+
this.easingFn = ye(e?.easing), this.boundaryEpsilon = e?.boundaryEpsilon ?? .005, e?.smoothing === !1 ? this.smoother = null : this.smoother = new G(e?.smoothing);
|
|
731
|
+
}
|
|
732
|
+
applyPipeline() {
|
|
733
|
+
let e = be(this.sample());
|
|
734
|
+
this.easingFn && (e = this.easingFn(e));
|
|
735
|
+
let t = this.boundaryEpsilon;
|
|
736
|
+
return e <= t ? e = 0 : e >= 1 - t && (e = 1), e;
|
|
737
|
+
}
|
|
738
|
+
finalizeProgress(e) {
|
|
739
|
+
return this.smoother && (this.smoother.setTarget(e), (e <= 0 || e >= 1) && this.smoother.snap()), this.currentProgress = this.smoother ? this.smoother.current : e, this.currentProgress;
|
|
740
|
+
}
|
|
741
|
+
_advance(e) {
|
|
742
|
+
let t = this.applyPipeline();
|
|
743
|
+
return this.smoother && t > 0 && t < 1 ? (this.smoother.setTarget(t), e === void 0 ? this.smoother.tick() : this.smoother.tickDt(e), this.currentProgress = this.smoother.current) : this.finalizeProgress(t), this.currentProgress;
|
|
744
|
+
}
|
|
745
|
+
tick() {
|
|
746
|
+
return this._advance();
|
|
747
|
+
}
|
|
748
|
+
tickDt(e) {
|
|
749
|
+
return this._advance(e);
|
|
750
|
+
}
|
|
751
|
+
get progress() {
|
|
752
|
+
return this.currentProgress;
|
|
753
|
+
}
|
|
754
|
+
get settled() {
|
|
755
|
+
return this.smoother == null || this.smoother.settled;
|
|
756
|
+
}
|
|
757
|
+
snap() {
|
|
758
|
+
this.smoother?.snap(), this.smoother && (this.currentProgress = this.smoother.current);
|
|
759
|
+
}
|
|
760
|
+
reset(e) {
|
|
761
|
+
let t = e ?? 0;
|
|
762
|
+
this.smoother && this.smoother.reset(t), this.currentProgress = t;
|
|
763
|
+
}
|
|
764
|
+
}, xe = class extends Y {
|
|
765
|
+
threshold;
|
|
766
|
+
getScrollY;
|
|
767
|
+
getViewportHeight;
|
|
768
|
+
constructor(e) {
|
|
769
|
+
super(e), this.threshold = e?.threshold ?? .35, this.getScrollY = e?.getScrollY ?? (() => window.scrollY), this.getViewportHeight = e?.getViewportHeight ?? (() => window.innerHeight);
|
|
770
|
+
}
|
|
771
|
+
sample() {
|
|
772
|
+
let e = this.getViewportHeight() * this.threshold;
|
|
773
|
+
return e <= 0 ? 0 : this.getScrollY() / e;
|
|
774
|
+
}
|
|
775
|
+
}, Se = class extends Y {
|
|
776
|
+
value = 0;
|
|
777
|
+
constructor(e) {
|
|
778
|
+
super({
|
|
779
|
+
smoothing: !1,
|
|
780
|
+
...e
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
set(e) {
|
|
784
|
+
this.value = e;
|
|
785
|
+
}
|
|
786
|
+
sample() {
|
|
787
|
+
return this.value;
|
|
788
|
+
}
|
|
789
|
+
}, X = (t) => typeof t == "string" && e.includes(t), Z = Symbol.for("keyframes.defaultRenderer"), Ce = (e) => typeof e == "function" && e[Z] === !0;
|
|
790
|
+
function we(e) {
|
|
791
|
+
if (!e.targets || e.targets.length === 0) return {
|
|
792
|
+
eligible: !1,
|
|
793
|
+
reason: "no DOM targets"
|
|
794
|
+
};
|
|
795
|
+
if (typeof e.targets[0]?.animate != "function") return {
|
|
796
|
+
eligible: !1,
|
|
797
|
+
reason: "target does not implement Element.animate()"
|
|
798
|
+
};
|
|
799
|
+
for (let t of e.frames) if (!Ce(t.transform)) return {
|
|
800
|
+
eligible: !1,
|
|
801
|
+
reason: "custom transform function (not the default DOM renderer)"
|
|
802
|
+
};
|
|
803
|
+
if (e.frames.length > 1) {
|
|
804
|
+
let t = e.frames[0].timingFunction;
|
|
805
|
+
for (let n = 1; n < e.frames.length; n++) if (e.frames[n].timingFunction !== t) return {
|
|
806
|
+
eligible: !1,
|
|
807
|
+
reason: "non-uniform per-frame timing function (WAAPI supports one easing per animation)"
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
for (let t of e.frames) for (let e of Object.values(t.interpVars)) for (let t of e) {
|
|
811
|
+
if (X(t.start?.unit) || X(t.stop?.unit)) return {
|
|
812
|
+
eligible: !1,
|
|
813
|
+
reason: `computed unit (${String(t.start?.unit ?? t.stop?.unit)}) requires DOM resolution`
|
|
814
|
+
};
|
|
815
|
+
if (t.start?.unit === "color" || t.stop?.unit === "color") return {
|
|
816
|
+
eligible: !1,
|
|
817
|
+
reason: "color interpolation requires perceptual lerp"
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
return { eligible: !0 };
|
|
998
821
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
822
|
+
function Te(e) {
|
|
823
|
+
let t = e.options.duration, n = [], r = /* @__PURE__ */ new Set();
|
|
824
|
+
for (let t of e.frames) r.add(t.time.start), r.add(t.time.stop);
|
|
825
|
+
let i = [...r].sort((e, t) => e - t);
|
|
826
|
+
for (let r of i) {
|
|
827
|
+
let i = e.interpFrames(r, !1);
|
|
828
|
+
if (Object.keys(i).length === 0) continue;
|
|
829
|
+
let a = C(i);
|
|
830
|
+
n.push({
|
|
831
|
+
offset: Math.max(0, Math.min(1, r / t)),
|
|
832
|
+
...a
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
return n;
|
|
1011
836
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
for (const e of s.frames)
|
|
1036
|
-
for (const i of Object.values(e.interpVars))
|
|
1037
|
-
for (const r of i)
|
|
1038
|
-
if (r.start?.unit === "color" || r.stop?.unit === "color")
|
|
1039
|
-
return !1;
|
|
1040
|
-
return !0;
|
|
1041
|
-
}
|
|
1042
|
-
function Oe(s) {
|
|
1043
|
-
const t = s.options.duration, e = [], i = /* @__PURE__ */ new Set();
|
|
1044
|
-
for (const o of s.frames)
|
|
1045
|
-
i.add(o.time.start), i.add(o.time.stop);
|
|
1046
|
-
const r = [...i].sort((o, n) => o - n);
|
|
1047
|
-
for (const o of r) {
|
|
1048
|
-
const n = s.interpFrames(o, !1);
|
|
1049
|
-
if (Object.keys(n).length === 0) continue;
|
|
1050
|
-
const u = ot(n), a = {
|
|
1051
|
-
offset: Math.max(0, Math.min(1, o / t)),
|
|
1052
|
-
...u
|
|
1053
|
-
};
|
|
1054
|
-
e.push(a);
|
|
1055
|
-
}
|
|
1056
|
-
return e;
|
|
1057
|
-
}
|
|
1058
|
-
function _e(s) {
|
|
1059
|
-
const t = s.options, e = {
|
|
1060
|
-
normal: "normal",
|
|
1061
|
-
reverse: "reverse",
|
|
1062
|
-
alternate: "alternate",
|
|
1063
|
-
"alternate-reverse": "alternate-reverse"
|
|
1064
|
-
}, i = {
|
|
1065
|
-
none: "none",
|
|
1066
|
-
forwards: "forwards",
|
|
1067
|
-
backwards: "backwards",
|
|
1068
|
-
both: "both"
|
|
1069
|
-
};
|
|
1070
|
-
return {
|
|
1071
|
-
duration: t.duration,
|
|
1072
|
-
delay: t.delay,
|
|
1073
|
-
iterations: t.iterationCount === 1 / 0 ? 1 / 0 : t.iterationCount,
|
|
1074
|
-
// TODO(HIGH): Remove enum fallbacks; throw when direction/fill values are outside supported WAAPI maps.
|
|
1075
|
-
direction: e[t.direction] ?? "normal",
|
|
1076
|
-
fill: i[t.fillMode] ?? "forwards",
|
|
1077
|
-
// WAAPI easing is set per-animation — we use the frame's timing function name
|
|
1078
|
-
// For custom functions we fall back to linear (the JS interpolation handles easing)
|
|
1079
|
-
easing: "linear"
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
async function ke(s) {
|
|
1083
|
-
const t = Oe(s), e = _e(s), i = [];
|
|
1084
|
-
for (const r of s.targets) {
|
|
1085
|
-
const o = r.animate(t, e);
|
|
1086
|
-
i.push(o);
|
|
1087
|
-
}
|
|
1088
|
-
return await Promise.all(i.map((r) => r.finished)), i;
|
|
1089
|
-
}
|
|
1090
|
-
const Me = (s) => typeof s != "object" || s == null ? !1 : typeof s.clone == "function", x = (s) => typeof s == "string" ? s : s.name ?? String(s.id);
|
|
1091
|
-
let Ae = 0;
|
|
1092
|
-
class gt {
|
|
1093
|
-
id = Ae++;
|
|
1094
|
-
name;
|
|
1095
|
-
superKey;
|
|
1096
|
-
targets;
|
|
1097
|
-
options;
|
|
1098
|
-
templateFrames = [];
|
|
1099
|
-
parsedVars = [];
|
|
1100
|
-
frameId = 0;
|
|
1101
|
-
frames = [];
|
|
1102
|
-
handleId = void 0;
|
|
1103
|
-
startTime = void 0;
|
|
1104
|
-
pausedTime = 0;
|
|
1105
|
-
prevTime = 0;
|
|
1106
|
-
t = 0;
|
|
1107
|
-
iteration = 0;
|
|
1108
|
-
started = !1;
|
|
1109
|
-
done = !1;
|
|
1110
|
-
reversed = !1;
|
|
1111
|
-
paused = !1;
|
|
1112
|
-
/** When true, this animation is managed by an AnimationGroup and should not run its own rAF loop. */
|
|
1113
|
-
managed = !1;
|
|
1114
|
-
unflatten = !0;
|
|
1115
|
-
resolvePromise = null;
|
|
1116
|
-
_playingPromise = null;
|
|
1117
|
-
/**
|
|
1118
|
-
* Pre-bound draw callback — allocated once to avoid creating a new
|
|
1119
|
-
* closure on every requestAnimationFrame reschedule.
|
|
1120
|
-
*/
|
|
1121
|
-
_boundDraw = this.draw.bind(this);
|
|
1122
|
-
dispatchAnimationEvent(t) {
|
|
1123
|
-
if (!(typeof AnimationEvent > "u"))
|
|
1124
|
-
for (const e of this.targets)
|
|
1125
|
-
typeof e?.dispatchEvent == "function" && e.dispatchEvent(
|
|
1126
|
-
new AnimationEvent(t, {
|
|
1127
|
-
animationName: this.name ?? "",
|
|
1128
|
-
elapsedTime: this.t / 1e3
|
|
1129
|
-
})
|
|
1130
|
-
);
|
|
1131
|
-
}
|
|
1132
|
-
constructor(t, e, i, r) {
|
|
1133
|
-
this.options = {}, this.setOptions({ ...te, ...t ?? {} }), this.targets = e == null ? [] : Array.isArray(e) ? e : [e], this.name = i, this.superKey = r;
|
|
1134
|
-
}
|
|
1135
|
-
convertFrameStart(t) {
|
|
1136
|
-
if (t.start.unit === "s" || t.start.unit === "ms" || !t.start.unit) {
|
|
1137
|
-
const e = t.start.unit === "s" ? "s" : "ms", i = it(t.start.value, e);
|
|
1138
|
-
t.start.value = i / this.options.duration * 100, t.start.unit = "%";
|
|
1139
|
-
}
|
|
1140
|
-
return t.start.value = E(t.start.value, 0, 100), t;
|
|
1141
|
-
}
|
|
1142
|
-
addFrame(t, e, i, r) {
|
|
1143
|
-
typeof t == "number" ? t = String(t) + "%" : typeof t == "string" ? t = t : t instanceof f && (t = String(t));
|
|
1144
|
-
const o = st(t);
|
|
1145
|
-
let n = {
|
|
1146
|
-
id: this.frameId,
|
|
1147
|
-
start: o,
|
|
1148
|
-
vars: e,
|
|
1149
|
-
transform: i,
|
|
1150
|
-
timingFunction: M(r) ?? this.options.timingFunction
|
|
1151
|
-
};
|
|
1152
|
-
return this.convertFrameStart(
|
|
1153
|
-
n
|
|
1154
|
-
), this.templateFrames.push(
|
|
1155
|
-
n
|
|
1156
|
-
), this.frameId += 1, this;
|
|
1157
|
-
}
|
|
1158
|
-
createFrame(t, e) {
|
|
1159
|
-
const i = this.templateFrames[t], r = this.templateFrames[e], o = {
|
|
1160
|
-
start: t,
|
|
1161
|
-
stop: e
|
|
1162
|
-
}, n = Te(i, r, this.options.duration);
|
|
1163
|
-
let u = i.transform;
|
|
1164
|
-
if (u == null) {
|
|
1165
|
-
const l = B(
|
|
1166
|
-
t,
|
|
1167
|
-
this.frames,
|
|
1168
|
-
(h) => h.transform != null
|
|
1169
|
-
);
|
|
1170
|
-
u = this.frames[l].transform;
|
|
1171
|
-
}
|
|
1172
|
-
let a = i.timingFunction;
|
|
1173
|
-
if (a == null) {
|
|
1174
|
-
const l = B(
|
|
1175
|
-
t,
|
|
1176
|
-
this.frames,
|
|
1177
|
-
(h) => h.timingFunction != null
|
|
1178
|
-
);
|
|
1179
|
-
a = this.frames[l].timingFunction;
|
|
1180
|
-
}
|
|
1181
|
-
return {
|
|
1182
|
-
id: this.frameId++,
|
|
1183
|
-
ixs: o,
|
|
1184
|
-
start: i.start,
|
|
1185
|
-
time: n,
|
|
1186
|
-
vars: void 0,
|
|
1187
|
-
flatVars: void 0,
|
|
1188
|
-
interpVars: {},
|
|
1189
|
-
allInterpVars: [],
|
|
1190
|
-
transform: u,
|
|
1191
|
-
timingFunction: a
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Build an index mapping each variable name to the frame indices where
|
|
1196
|
-
* it appears. Used by reconcileVars() for O(1) "next occurrence" lookups
|
|
1197
|
-
* instead of O(N) findIndex scans per variable.
|
|
1198
|
-
*/
|
|
1199
|
-
buildVarIndex() {
|
|
1200
|
-
const t = /* @__PURE__ */ new Map();
|
|
1201
|
-
for (let e = 0; e < this.parsedVars.length; e++)
|
|
1202
|
-
for (const i of Object.keys(this.parsedVars[e])) {
|
|
1203
|
-
let r = t.get(i);
|
|
1204
|
-
r || (r = [], t.set(i, r)), r.push(e);
|
|
1205
|
-
}
|
|
1206
|
-
return t;
|
|
1207
|
-
}
|
|
1208
|
-
/**
|
|
1209
|
-
* Reconcile interpolation variables across non-adjacent keyframes.
|
|
1210
|
-
* For each variable at frame `ix`, find the next frame that also
|
|
1211
|
-
* defines that variable and create an interpolation segment between them.
|
|
1212
|
-
*
|
|
1213
|
-
* Uses a pre-built variable index (from buildVarIndex) to avoid
|
|
1214
|
-
* O(frames²) findIndex scans.
|
|
1215
|
-
*/
|
|
1216
|
-
reconcileVars(t, e) {
|
|
1217
|
-
const i = this.parsedVars[t];
|
|
1218
|
-
if (i)
|
|
1219
|
-
for (const r of Object.keys(i)) {
|
|
1220
|
-
const o = e.get(r);
|
|
1221
|
-
if (!o) continue;
|
|
1222
|
-
let n = -1;
|
|
1223
|
-
for (const h of o)
|
|
1224
|
-
if (h > t) {
|
|
1225
|
-
n = h;
|
|
1226
|
-
break;
|
|
1227
|
-
}
|
|
1228
|
-
if (n === -1) continue;
|
|
1229
|
-
const [u, a] = [t, n], c = this.frames.findIndex(
|
|
1230
|
-
(h) => h.ixs.start === u && h.ixs.stop === a
|
|
1231
|
-
), l = c !== -1 ? this.frames[c] : this.createFrame(u, a);
|
|
1232
|
-
l.interpVars[r] = Ve(
|
|
1233
|
-
r,
|
|
1234
|
-
u,
|
|
1235
|
-
a,
|
|
1236
|
-
this.parsedVars,
|
|
1237
|
-
this.options.colorSpace,
|
|
1238
|
-
this.options.hueMethod
|
|
1239
|
-
), c === -1 && this.frames.push(l);
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
parse() {
|
|
1243
|
-
this.frames = [], this.templateFrames.sort((e, i) => e.start.value - i.start.value), this.parsedVars = this.templateFrames.map((e) => {
|
|
1244
|
-
const i = we(
|
|
1245
|
-
e.vars
|
|
1246
|
-
);
|
|
1247
|
-
return Object.values(i).forEach((r) => {
|
|
1248
|
-
r.setTargets(this.targets);
|
|
1249
|
-
}), i;
|
|
1250
|
-
});
|
|
1251
|
-
for (let e = 0; e < this.templateFrames.length - 1; e++)
|
|
1252
|
-
this.frames.push(this.createFrame(e, e + 1));
|
|
1253
|
-
const t = this.buildVarIndex();
|
|
1254
|
-
return this.frames.forEach((e, i) => this.reconcileVars(i, t)), this.frames.sort((e, i) => e.time.start === i.time.start ? e.time.stop - i.time.stop : e.time.start - i.time.start), this.frames = this.frames.filter(
|
|
1255
|
-
(e) => e.interpVars != null && Object.keys(e.interpVars).length > 0
|
|
1256
|
-
), this.frames.forEach((e) => {
|
|
1257
|
-
const i = Object.entries(e.interpVars).reduce((r, [o, n]) => (r[o] = n.map((u) => u.value), r), {});
|
|
1258
|
-
e.flatVars = i, e.vars = Ot(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
|
|
1259
|
-
}), this;
|
|
1260
|
-
}
|
|
1261
|
-
setTimingFunction(t) {
|
|
1262
|
-
return this.options.timingFunction = M(t) ?? et, this;
|
|
1263
|
-
}
|
|
1264
|
-
setIterationCount(t) {
|
|
1265
|
-
if (!t || t === "infinite" || t === "∞" || t === "Infinity")
|
|
1266
|
-
this.options.iterationCount = 1 / 0;
|
|
1267
|
-
else if (typeof t == "string") {
|
|
1268
|
-
const e = parseFloat(t.trim());
|
|
1269
|
-
if (isNaN(e) || e < 0) return this;
|
|
1270
|
-
this.options.iterationCount = e;
|
|
1271
|
-
} else {
|
|
1272
|
-
if (isNaN(t) || t < 0) return this;
|
|
1273
|
-
this.options.iterationCount = t;
|
|
1274
|
-
}
|
|
1275
|
-
return this;
|
|
1276
|
-
}
|
|
1277
|
-
setDuration(t) {
|
|
1278
|
-
typeof t == "string" && (t = L(t));
|
|
1279
|
-
const e = t ?? this.options.duration;
|
|
1280
|
-
if (!isFinite(e) || e <= 0) return this;
|
|
1281
|
-
const i = this.options.duration, r = e / i;
|
|
1282
|
-
for (let o = 0; o < this.frames.length; o++) {
|
|
1283
|
-
const n = this.frames[o];
|
|
1284
|
-
n.time.start *= r, n.time.stop *= r;
|
|
1285
|
-
}
|
|
1286
|
-
return this.options.duration = e, this;
|
|
1287
|
-
}
|
|
1288
|
-
setDelay(t) {
|
|
1289
|
-
return typeof t == "string" && (t = L(t)), this.options.delay = t ?? 0, this;
|
|
1290
|
-
}
|
|
1291
|
-
setDirection(t) {
|
|
1292
|
-
return this.options.direction = t ?? "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;
|
|
1293
|
-
}
|
|
1294
|
-
setFillMode(t) {
|
|
1295
|
-
return this.options.fillMode = t ?? "forwards", this;
|
|
1296
|
-
}
|
|
1297
|
-
setUseWAAPI(t) {
|
|
1298
|
-
return this.options.useWAAPI = t ?? !0, this;
|
|
1299
|
-
}
|
|
1300
|
-
setColorSpace(t) {
|
|
1301
|
-
return this.options.colorSpace = t ?? "oklab", this;
|
|
1302
|
-
}
|
|
1303
|
-
setHueMethod(t) {
|
|
1304
|
-
return t !== void 0 && (this.options.hueMethod = t), this;
|
|
1305
|
-
}
|
|
1306
|
-
setOptions(t) {
|
|
1307
|
-
return this.setTimingFunction(t.timingFunction), this.setDuration(t.duration), this.setIterationCount(t.iterationCount), this.setDelay(t.delay), this.setDirection(t.direction), this.setFillMode(t.fillMode), this.setUseWAAPI(t.useWAAPI), this.setColorSpace(t.colorSpace), this.setHueMethod(t.hueMethod), this;
|
|
1308
|
-
}
|
|
1309
|
-
reverse() {
|
|
1310
|
-
if (this.startTime !== void 0) {
|
|
1311
|
-
const t = this.t, e = this.options.duration - 2 * t;
|
|
1312
|
-
this.startTime -= e;
|
|
1313
|
-
}
|
|
1314
|
-
return this.reversed = !this.reversed, this;
|
|
1315
|
-
}
|
|
1316
|
-
fillForwards() {
|
|
1317
|
-
this.interpFrames(this.options.duration, !0);
|
|
1318
|
-
}
|
|
1319
|
-
fillBackwards() {
|
|
1320
|
-
this.interpFrames(0, !0);
|
|
1321
|
-
}
|
|
1322
|
-
/**
|
|
1323
|
-
* Stateless progress query. Maps [0,1] from first keyframe to last,
|
|
1324
|
-
* regardless of playback direction. `apply=true` invokes transform callbacks.
|
|
1325
|
-
*/
|
|
1326
|
-
at(t, e = !1) {
|
|
1327
|
-
const i = this.reversed;
|
|
1328
|
-
this.reversed = !1;
|
|
1329
|
-
const r = E(t, 0, 1) * this.options.duration, o = this.interpFrames(r, e);
|
|
1330
|
-
return this.reversed = i, o;
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* Interpolate all active frames at time `t`. This is the hot path —
|
|
1334
|
-
* called once per rAF frame during playback.
|
|
1335
|
-
*
|
|
1336
|
-
* Uses binary search (O(log N)) to find the first matching frame,
|
|
1337
|
-
* then scans neighbors to collect all overlapping frames at `t`
|
|
1338
|
-
* (multiple properties may share the same time range).
|
|
1339
|
-
*
|
|
1340
|
-
* @param t - Current animation time in milliseconds
|
|
1341
|
-
* @param transformFrames - If true, applies each frame's transform function to targets
|
|
1342
|
-
* @returns Merged flat vars from all active frames
|
|
1343
|
-
*/
|
|
1344
|
-
interpFrames(t, e = !1) {
|
|
1345
|
-
t = this.reversed ? this.options.duration - t : t;
|
|
1346
|
-
const i = {}, r = this.frames, o = r.length, n = lt(
|
|
1347
|
-
r,
|
|
1348
|
-
t,
|
|
1349
|
-
(a) => a.time.start,
|
|
1350
|
-
(a) => a.time.stop
|
|
1351
|
-
);
|
|
1352
|
-
if (n === -1) return i;
|
|
1353
|
-
const u = (a) => {
|
|
1354
|
-
const { start: c, stop: l } = a.time, h = at(t, c, l, 0, 1), m = a.timingFunction(h);
|
|
1355
|
-
for (const p of a.allInterpVars)
|
|
1356
|
-
ye(m, p);
|
|
1357
|
-
e && a.transform(
|
|
1358
|
-
this.unflatten ? a.vars : a.flatVars,
|
|
1359
|
-
t
|
|
1360
|
-
), Object.assign(i, a.flatVars);
|
|
1361
|
-
};
|
|
1362
|
-
for (let a = n; a >= 0; a--) {
|
|
1363
|
-
const c = r[a];
|
|
1364
|
-
if (t < c.time.start || t > c.time.stop) break;
|
|
1365
|
-
u(c);
|
|
1366
|
-
}
|
|
1367
|
-
for (let a = n + 1; a < o; a++) {
|
|
1368
|
-
const c = r[a];
|
|
1369
|
-
if (t < c.time.start || t > c.time.stop) break;
|
|
1370
|
-
u(c);
|
|
1371
|
-
}
|
|
1372
|
-
return i;
|
|
1373
|
-
}
|
|
1374
|
-
async onStart() {
|
|
1375
|
-
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 _t(this.options.delay), this.paused = !1), this.started = !0;
|
|
1376
|
-
}
|
|
1377
|
-
async onEnd() {
|
|
1378
|
-
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"));
|
|
1379
|
-
}
|
|
1380
|
-
async tick(t) {
|
|
1381
|
-
if (this.startTime === void 0 && (await this.onStart(), this.startTime = t + this.options.delay, this.dispatchAnimationEvent("animationstart")), this.paused && this.pausedTime === 0)
|
|
1382
|
-
return this.pausedTime = t, this.t;
|
|
1383
|
-
if (this.pausedTime > 0 && !this.paused) {
|
|
1384
|
-
const e = t - this.pausedTime;
|
|
1385
|
-
this.startTime += e, this.pausedTime = 0;
|
|
1386
|
-
}
|
|
1387
|
-
return this.t = t - this.startTime, this.t >= this.options.duration && (await this.onEnd(), this.t = this.options.duration), this.t;
|
|
1388
|
-
}
|
|
1389
|
-
async draw(t) {
|
|
1390
|
-
this.managed || (t = await this.tick(t), !this.paused && (this.interpFrames(t, !0), this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = w(this._boundDraw)));
|
|
1391
|
-
}
|
|
1392
|
-
/** Internal rAF-based play loop. */
|
|
1393
|
-
_playRAF() {
|
|
1394
|
-
return new Promise((t) => {
|
|
1395
|
-
this.resolvePromise = t, this.handleId = w(this._boundDraw);
|
|
1396
|
-
});
|
|
1397
|
-
}
|
|
1398
|
-
/** Play via the Web Animations API for compositor-thread execution. */
|
|
1399
|
-
async _playWAAPI() {
|
|
1400
|
-
try {
|
|
1401
|
-
await ke(this), this.reset();
|
|
1402
|
-
} catch {
|
|
1403
|
-
return this._playRAF();
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
async play() {
|
|
1407
|
-
if (this.managed)
|
|
1408
|
-
return;
|
|
1409
|
-
if (this._playingPromise) return this._playingPromise;
|
|
1410
|
-
let t;
|
|
1411
|
-
return this.options.useWAAPI && this.targets.length > 0 && typeof this.targets[0]?.animate == "function" && Ce(this) ? t = this._playWAAPI() : t = this._playRAF(), this._playingPromise = t, t.finally(() => {
|
|
1412
|
-
this._playingPromise = null;
|
|
1413
|
-
}), t;
|
|
1414
|
-
}
|
|
1415
|
-
pause(t = !0) {
|
|
1416
|
-
return this.paused && t ? this.resume() : (this.started && (this.paused = !0), this);
|
|
1417
|
-
}
|
|
1418
|
-
resume() {
|
|
1419
|
-
return this.started && this.paused && (this.paused = !1, this.handleId = w(this._boundDraw)), this;
|
|
1420
|
-
}
|
|
1421
|
-
stop() {
|
|
1422
|
-
k(this.handleId), this.reset();
|
|
1423
|
-
}
|
|
1424
|
-
playing() {
|
|
1425
|
-
return !(!this.started || this.paused);
|
|
1426
|
-
}
|
|
1427
|
-
/** Returns the effective time accounting for direction reversal. */
|
|
1428
|
-
get effectiveT() {
|
|
1429
|
-
return this.reversed ? this.options.duration - this.t : this.t;
|
|
1430
|
-
}
|
|
1431
|
-
reset() {
|
|
1432
|
-
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;
|
|
1433
|
-
}
|
|
1434
|
-
setTargets(...t) {
|
|
1435
|
-
return this.targets = t, this.frames.forEach((e) => {
|
|
1436
|
-
Object.values(e.interpVars).forEach((i) => {
|
|
1437
|
-
i.forEach(({ start: r, stop: o, value: n }) => {
|
|
1438
|
-
r.setTargets(this.targets), o.setTargets(this.targets), n.setTargets(this.targets);
|
|
1439
|
-
});
|
|
1440
|
-
});
|
|
1441
|
-
}), this;
|
|
1442
|
-
}
|
|
1443
|
-
group(...t) {
|
|
1444
|
-
return new se(this, ...t);
|
|
1445
|
-
}
|
|
837
|
+
var Ee = {
|
|
838
|
+
normal: "normal",
|
|
839
|
+
reverse: "reverse",
|
|
840
|
+
alternate: "alternate",
|
|
841
|
+
"alternate-reverse": "alternate-reverse"
|
|
842
|
+
}, De = {
|
|
843
|
+
none: "none",
|
|
844
|
+
forwards: "forwards",
|
|
845
|
+
backwards: "backwards",
|
|
846
|
+
both: "both"
|
|
847
|
+
};
|
|
848
|
+
function Oe(e) {
|
|
849
|
+
let t = e.options, n = Ee[t.direction], r = De[t.fillMode];
|
|
850
|
+
if (n == null) throw TypeError(`Unrecognised animation direction "${t.direction}".`);
|
|
851
|
+
if (r == null) throw TypeError(`Unrecognised animation fill mode "${t.fillMode}".`);
|
|
852
|
+
return {
|
|
853
|
+
duration: t.duration,
|
|
854
|
+
delay: t.delay,
|
|
855
|
+
iterations: t.iterationCount === Infinity ? Infinity : t.iterationCount,
|
|
856
|
+
direction: n,
|
|
857
|
+
fill: r,
|
|
858
|
+
easing: "linear"
|
|
859
|
+
};
|
|
1446
860
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
const i = t instanceof Map ? t.entries() : Object.entries(t);
|
|
1462
|
-
for (const [r, o] of i)
|
|
1463
|
-
this.addFrame(r, o, e);
|
|
1464
|
-
return this.parse(), this;
|
|
1465
|
-
}
|
|
1466
|
-
fromString(t, e) {
|
|
1467
|
-
this.unflatten = e != null, e ??= this.transform.bind(this);
|
|
1468
|
-
const i = Jt(t);
|
|
1469
|
-
for (const [r, o] of i.entries()) {
|
|
1470
|
-
const n = Object.fromEntries(
|
|
1471
|
-
Object.entries(o).map(([c, l]) => [
|
|
1472
|
-
c,
|
|
1473
|
-
Me(l) ? l.clone() : l
|
|
1474
|
-
])
|
|
1475
|
-
), u = n.animationTimingFunction ?? n.timingFunction;
|
|
1476
|
-
delete n.animationTimingFunction, delete n.timingFunction;
|
|
1477
|
-
const a = u ? M(u.toString()) : void 0;
|
|
1478
|
-
this.addFrame(r, n, e, a);
|
|
1479
|
-
}
|
|
1480
|
-
return this.parse(), this;
|
|
1481
|
-
}
|
|
1482
|
-
transform(t) {
|
|
1483
|
-
mt(t, this.targets);
|
|
1484
|
-
}
|
|
861
|
+
async function ke(e) {
|
|
862
|
+
let t = Te(e), n = Oe(e), r = e.targets.map((e) => e.animate(t, n)), i = !1, a = (t) => {
|
|
863
|
+
if (!(i || e.done)) {
|
|
864
|
+
if (e.tick(t), e.paused) for (let e of r) e.pause();
|
|
865
|
+
else for (let e of r) e.playState === "paused" && e.play();
|
|
866
|
+
e.handleId = requestAnimationFrame(a);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
e.handleId = requestAnimationFrame(a);
|
|
870
|
+
try {
|
|
871
|
+
await Promise.all(r.map((e) => e.finished));
|
|
872
|
+
} finally {
|
|
873
|
+
i = !0;
|
|
874
|
+
}
|
|
1485
875
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
876
|
+
//#endregion
|
|
877
|
+
//#region src/animation/index.ts
|
|
878
|
+
var Ae = (e) => typeof e != "object" || !e ? !1 : typeof e.clone == "function", Q = (e) => typeof e == "string" ? e : e.name ?? String(e.id), je = 0, $ = class {
|
|
879
|
+
id = je++;
|
|
880
|
+
name;
|
|
881
|
+
superKey;
|
|
882
|
+
targets;
|
|
883
|
+
options;
|
|
884
|
+
templateFrames = [];
|
|
885
|
+
parsedVars = [];
|
|
886
|
+
frameId = 0;
|
|
887
|
+
frames = [];
|
|
888
|
+
handleId = void 0;
|
|
889
|
+
startTime = void 0;
|
|
890
|
+
pausedTime = 0;
|
|
891
|
+
t = 0;
|
|
892
|
+
iteration = 0;
|
|
893
|
+
started = !1;
|
|
894
|
+
done = !1;
|
|
895
|
+
reversed = !1;
|
|
896
|
+
paused = !1;
|
|
897
|
+
managed = !1;
|
|
898
|
+
waapiIneligibleReason = void 0;
|
|
899
|
+
unflatten = !0;
|
|
900
|
+
resolvePromise = null;
|
|
901
|
+
_playingPromise = null;
|
|
902
|
+
_boundDraw = this.draw.bind(this);
|
|
903
|
+
dispatchAnimationEvent(e) {
|
|
904
|
+
if (!(typeof AnimationEvent > "u")) for (let t of this.targets) typeof t?.dispatchEvent == "function" && t.dispatchEvent(new AnimationEvent(e, {
|
|
905
|
+
animationName: this.name ?? "",
|
|
906
|
+
elapsedTime: this.t / 1e3
|
|
907
|
+
}));
|
|
908
|
+
}
|
|
909
|
+
constructor(e, t, n, r) {
|
|
910
|
+
this.options = {}, this.setOptions({
|
|
911
|
+
...k,
|
|
912
|
+
...e ?? {}
|
|
913
|
+
}), this.targets = t == null ? [] : Array.isArray(t) ? t : [t], this.name = n, this.superKey = r;
|
|
914
|
+
}
|
|
915
|
+
convertFrameStart(e) {
|
|
916
|
+
if (e.start.unit === "s" || e.start.unit === "ms" || !e.start.unit) {
|
|
917
|
+
let t = e.start.unit === "s" ? "s" : "ms", n = l(e.start.value, t);
|
|
918
|
+
e.start.value = n / this.options.duration * 100, e.start.unit = "%";
|
|
919
|
+
}
|
|
920
|
+
return e.start.value = c(e.start.value, 0, 100), e;
|
|
921
|
+
}
|
|
922
|
+
addFrame(e, t, n, r) {
|
|
923
|
+
typeof e == "number" ? e = String(e) + "%" : typeof e == "string" ? e = e : e instanceof o && (e = String(e));
|
|
924
|
+
let i = ne(e), a = {
|
|
925
|
+
id: this.frameId,
|
|
926
|
+
start: i,
|
|
927
|
+
vars: t,
|
|
928
|
+
transform: n,
|
|
929
|
+
timingFunction: L(r) ?? this.options.timingFunction
|
|
930
|
+
};
|
|
931
|
+
return this.convertFrameStart(a), this.templateFrames.push(a), this.frameId += 1, this;
|
|
932
|
+
}
|
|
933
|
+
createFrame(e, t) {
|
|
934
|
+
let n = this.templateFrames[e], r = this.templateFrames[t], i = {
|
|
935
|
+
start: e,
|
|
936
|
+
stop: t
|
|
937
|
+
}, a = V(n, r, this.options.duration), o = n.transform;
|
|
938
|
+
if (o == null) {
|
|
939
|
+
let t = x(e, this.frames, (e) => e.transform != null);
|
|
940
|
+
o = this.frames[t].transform;
|
|
941
|
+
}
|
|
942
|
+
let s = n.timingFunction;
|
|
943
|
+
if (s == null) {
|
|
944
|
+
let t = x(e, this.frames, (e) => e.timingFunction != null);
|
|
945
|
+
s = this.frames[t].timingFunction;
|
|
946
|
+
}
|
|
947
|
+
return {
|
|
948
|
+
id: this.frameId++,
|
|
949
|
+
ixs: i,
|
|
950
|
+
start: n.start,
|
|
951
|
+
time: a,
|
|
952
|
+
vars: void 0,
|
|
953
|
+
flatVars: void 0,
|
|
954
|
+
interpVars: {},
|
|
955
|
+
allInterpVars: [],
|
|
956
|
+
transform: o,
|
|
957
|
+
timingFunction: s
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
buildVarIndex() {
|
|
961
|
+
let e = /* @__PURE__ */ new Map();
|
|
962
|
+
for (let t = 0; t < this.parsedVars.length; t++) for (let n of Object.keys(this.parsedVars[t])) {
|
|
963
|
+
let r = e.get(n);
|
|
964
|
+
r || (r = [], e.set(n, r)), r.push(t);
|
|
965
|
+
}
|
|
966
|
+
return e;
|
|
967
|
+
}
|
|
968
|
+
reconcileVars(e, t) {
|
|
969
|
+
let n = this.parsedVars[e];
|
|
970
|
+
if (n) for (let r of Object.keys(n)) {
|
|
971
|
+
let n = t.get(r);
|
|
972
|
+
if (!n) continue;
|
|
973
|
+
let i = -1;
|
|
974
|
+
for (let t of n) if (t > e) {
|
|
975
|
+
i = t;
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
if (i === -1) continue;
|
|
979
|
+
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];
|
|
980
|
+
c.interpVars[r] = B(r, a, o, this.parsedVars, this.options.colorSpace, this.options.hueMethod), s === -1 && this.frames.push(c);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
parse() {
|
|
984
|
+
this.frames = [], this.templateFrames.sort((e, t) => e.start.value - t.start.value), this.parsedVars = this.templateFrames.map((e) => {
|
|
985
|
+
let t = z(e.vars);
|
|
986
|
+
return Object.values(t).forEach((e) => {
|
|
987
|
+
e.setTargets(this.targets);
|
|
988
|
+
}), t;
|
|
989
|
+
});
|
|
990
|
+
for (let e = 0; e < this.templateFrames.length - 1; e++) this.frames.push(this.createFrame(e, e + 1));
|
|
991
|
+
let e = this.buildVarIndex();
|
|
992
|
+
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) => {
|
|
993
|
+
e.flatVars = Object.entries(e.interpVars).reduce((e, [t, n]) => (e[t] = n.map((e) => e.value), e), {}), e.vars = oe(e.flatVars), e.allInterpVars = Object.values(e.interpVars).flat();
|
|
994
|
+
}), this;
|
|
995
|
+
}
|
|
996
|
+
setTimingFunction(e) {
|
|
997
|
+
return this.options.timingFunction = L(e) ?? u, this;
|
|
998
|
+
}
|
|
999
|
+
setIterationCount(e) {
|
|
1000
|
+
if (!e || e === "infinite" || e === "∞" || e === "Infinity") this.options.iterationCount = Infinity;
|
|
1001
|
+
else if (typeof e == "string") {
|
|
1002
|
+
let t = parseFloat(e.trim());
|
|
1003
|
+
if (isNaN(t) || t < 0) return this;
|
|
1004
|
+
this.options.iterationCount = t;
|
|
1005
|
+
} else {
|
|
1006
|
+
if (isNaN(e) || e < 0) return this;
|
|
1007
|
+
this.options.iterationCount = e;
|
|
1008
|
+
}
|
|
1009
|
+
return this;
|
|
1010
|
+
}
|
|
1011
|
+
setDuration(e) {
|
|
1012
|
+
typeof e == "string" && (e = v(e));
|
|
1013
|
+
let t = e ?? this.options.duration;
|
|
1014
|
+
if (!isFinite(t) || t <= 0) return this;
|
|
1015
|
+
let n = t / this.options.duration;
|
|
1016
|
+
for (let e = 0; e < this.frames.length; e++) {
|
|
1017
|
+
let t = this.frames[e];
|
|
1018
|
+
t.time.start *= n, t.time.stop *= n;
|
|
1019
|
+
}
|
|
1020
|
+
return this.options.duration = t, this;
|
|
1021
|
+
}
|
|
1022
|
+
setDelay(e) {
|
|
1023
|
+
return typeof e == "string" && (e = v(e)), this.options.delay = e ?? 0, this;
|
|
1024
|
+
}
|
|
1025
|
+
setDirection(e) {
|
|
1026
|
+
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;
|
|
1027
|
+
}
|
|
1028
|
+
setFillMode(e) {
|
|
1029
|
+
return this.options.fillMode = e ?? "forwards", this;
|
|
1030
|
+
}
|
|
1031
|
+
setUseWAAPI(e) {
|
|
1032
|
+
return this.options.useWAAPI = e ?? !0, this;
|
|
1033
|
+
}
|
|
1034
|
+
setColorSpace(e) {
|
|
1035
|
+
return this.options.colorSpace = e ?? "oklab", this;
|
|
1036
|
+
}
|
|
1037
|
+
setHueMethod(e) {
|
|
1038
|
+
return e !== void 0 && (this.options.hueMethod = e), this;
|
|
1039
|
+
}
|
|
1040
|
+
setOptions(e) {
|
|
1041
|
+
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;
|
|
1042
|
+
}
|
|
1043
|
+
reverse() {
|
|
1044
|
+
if (this.startTime !== void 0) {
|
|
1045
|
+
let e = this.t, t = this.options.duration - 2 * e;
|
|
1046
|
+
this.startTime -= t;
|
|
1047
|
+
}
|
|
1048
|
+
return this.reversed = !this.reversed, this;
|
|
1049
|
+
}
|
|
1050
|
+
fillForwards() {
|
|
1051
|
+
this.interpFrames(this.options.duration, !0);
|
|
1052
|
+
}
|
|
1053
|
+
fillBackwards() {
|
|
1054
|
+
this.interpFrames(0, !0);
|
|
1055
|
+
}
|
|
1056
|
+
at(e, t = !1) {
|
|
1057
|
+
let n = this.reversed;
|
|
1058
|
+
this.reversed = !1;
|
|
1059
|
+
let r = c(e, 0, 1) * this.options.duration, i = this.interpFrames(r, t);
|
|
1060
|
+
return this.reversed = n, i;
|
|
1061
|
+
}
|
|
1062
|
+
interpFrames(e, t = !1, n = {}) {
|
|
1063
|
+
e = this.reversed ? this.options.duration - e : e;
|
|
1064
|
+
let r = n;
|
|
1065
|
+
for (let e in r) delete r[e];
|
|
1066
|
+
let i = this.frames, a = i.length, o = w(i, e, (e) => e.time.start, (e) => e.time.stop);
|
|
1067
|
+
if (o === -1) return r;
|
|
1068
|
+
let s = (n) => {
|
|
1069
|
+
let { start: i, stop: a } = n.time, o = b(e, i, a, 0, 1), s = n.timingFunction(o);
|
|
1070
|
+
for (let e of n.allInterpVars) te(s, e);
|
|
1071
|
+
t && n.transform(this.unflatten ? n.vars : n.flatVars, e), Object.assign(r, n.flatVars);
|
|
1072
|
+
};
|
|
1073
|
+
for (let t = o; t >= 0; t--) {
|
|
1074
|
+
let n = i[t];
|
|
1075
|
+
if (e < n.time.start || e > n.time.stop) break;
|
|
1076
|
+
s(n);
|
|
1077
|
+
}
|
|
1078
|
+
for (let t = o + 1; t < a; t++) {
|
|
1079
|
+
let n = i[t];
|
|
1080
|
+
if (e < n.time.start || e > n.time.stop) break;
|
|
1081
|
+
s(n);
|
|
1082
|
+
}
|
|
1083
|
+
return r;
|
|
1084
|
+
}
|
|
1085
|
+
async onStart() {
|
|
1086
|
+
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 ie(this.options.delay), this.paused = !1), this.started = !0;
|
|
1087
|
+
}
|
|
1088
|
+
async onEnd() {
|
|
1089
|
+
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"));
|
|
1090
|
+
}
|
|
1091
|
+
async tick(e) {
|
|
1092
|
+
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;
|
|
1093
|
+
if (this.pausedTime > 0 && !this.paused) {
|
|
1094
|
+
let t = e - this.pausedTime;
|
|
1095
|
+
this.startTime += t, this.pausedTime = 0;
|
|
1096
|
+
}
|
|
1097
|
+
return this.t = e - this.startTime, this.t >= this.options.duration && (await this.onEnd(), this.t = this.options.duration), this.t;
|
|
1098
|
+
}
|
|
1099
|
+
async draw(e) {
|
|
1100
|
+
if (this.managed) throw Error("Animation.draw() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play()/pause()/stop() instead.");
|
|
1101
|
+
e = await this.tick(e), !this.paused && (this.interpFrames(e, !0), this.done ? (this.reset(), this.resolvePromise && this.resolvePromise()) : this.handleId = y(this._boundDraw));
|
|
1102
|
+
}
|
|
1103
|
+
_playRAF() {
|
|
1104
|
+
return new Promise((e) => {
|
|
1105
|
+
this.resolvePromise = e, this.handleId = y(this._boundDraw);
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
async _playWAAPI() {
|
|
1109
|
+
await ke(this), this.reset();
|
|
1110
|
+
}
|
|
1111
|
+
async play() {
|
|
1112
|
+
if (this.managed) throw Error("Animation.play() called on a managed animation — the AnimationGroup owns the rAF loop. Call group.play() instead.");
|
|
1113
|
+
if (this._playingPromise) return this._playingPromise;
|
|
1114
|
+
let e;
|
|
1115
|
+
if (this.options.useWAAPI) {
|
|
1116
|
+
let t = we(this);
|
|
1117
|
+
t.eligible ? (this.waapiIneligibleReason = void 0, e = this._playWAAPI()) : (this.waapiIneligibleReason = t.reason, e = this._playRAF());
|
|
1118
|
+
} else this.waapiIneligibleReason = void 0, e = this._playRAF();
|
|
1119
|
+
return this._playingPromise = e, e.finally(() => {
|
|
1120
|
+
this._playingPromise = null;
|
|
1121
|
+
}), e;
|
|
1122
|
+
}
|
|
1123
|
+
pause(e = !0) {
|
|
1124
|
+
return this.paused && e ? this.resume() : (this.started && (this.paused = !0), this);
|
|
1125
|
+
}
|
|
1126
|
+
resume() {
|
|
1127
|
+
return this.started && this.paused && (this.paused = !1, this.handleId = y(this._boundDraw)), this;
|
|
1128
|
+
}
|
|
1129
|
+
stop() {
|
|
1130
|
+
s(this.handleId), this.reset();
|
|
1131
|
+
}
|
|
1132
|
+
playing() {
|
|
1133
|
+
return !(!this.started || this.paused);
|
|
1134
|
+
}
|
|
1135
|
+
get effectiveT() {
|
|
1136
|
+
return this.reversed ? this.options.duration - this.t : this.t;
|
|
1137
|
+
}
|
|
1138
|
+
reset() {
|
|
1139
|
+
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;
|
|
1140
|
+
}
|
|
1141
|
+
setTargets(...e) {
|
|
1142
|
+
return this.targets = e, this.frames.forEach((e) => {
|
|
1143
|
+
Object.values(e.interpVars).forEach((e) => {
|
|
1144
|
+
e.forEach(({ start: e, stop: t, value: n }) => {
|
|
1145
|
+
e.setTargets(this.targets), t.setTargets(this.targets), n.setTargets(this.targets);
|
|
1146
|
+
});
|
|
1147
|
+
});
|
|
1148
|
+
}), this;
|
|
1149
|
+
}
|
|
1150
|
+
group(...e) {
|
|
1151
|
+
return new M(this, ...e);
|
|
1152
|
+
}
|
|
1153
|
+
}, Me = class extends $ {
|
|
1154
|
+
constructor(e, ...t) {
|
|
1155
|
+
super(e, t), this.unflatten = !1;
|
|
1156
|
+
}
|
|
1157
|
+
fromVars(e, t) {
|
|
1158
|
+
this.unflatten = t != null, t ??= this.transform.bind(this);
|
|
1159
|
+
for (let n = 0; n < e.length; n++) {
|
|
1160
|
+
let r = e[n], i = Math.round(n / (e.length - 1) * 100);
|
|
1161
|
+
this.addFrame(i, r, t);
|
|
1162
|
+
}
|
|
1163
|
+
return this.parse(), this;
|
|
1164
|
+
}
|
|
1165
|
+
fromKeyframes(e, t) {
|
|
1166
|
+
this.unflatten = t != null, t ??= this.transform.bind(this), ee(e) && (e = new Map(Object.entries(e)));
|
|
1167
|
+
let n = e instanceof Map ? e.entries() : Object.entries(e);
|
|
1168
|
+
for (let [e, r] of n) this.addFrame(e, r, t);
|
|
1169
|
+
return this.parse(), this;
|
|
1170
|
+
}
|
|
1171
|
+
propertyRegistry = /* @__PURE__ */ new Map();
|
|
1172
|
+
fromString(e, t) {
|
|
1173
|
+
this.unflatten = t != null, t ??= this.transform.bind(this);
|
|
1174
|
+
let n = O(e);
|
|
1175
|
+
this.propertyRegistry = n.properties;
|
|
1176
|
+
for (let [e, r] of n.keyframes.entries()) {
|
|
1177
|
+
let i = Object.fromEntries(Object.entries(r).map(([e, t]) => [e, Ae(t) ? t.clone() : t])), a = n.timingFunctions.get(e), o = a ? L(a) : void 0;
|
|
1178
|
+
this.addFrame(e, i, t, o);
|
|
1179
|
+
}
|
|
1180
|
+
return this.parse(), this;
|
|
1181
|
+
}
|
|
1182
|
+
transform(e) {
|
|
1183
|
+
H(e, this.targets);
|
|
1184
|
+
}
|
|
1539
1185
|
};
|
|
1186
|
+
//#endregion
|
|
1187
|
+
export { $ as Animation, M as AnimationGroup, Me as CSSKeyframesAnimation, le as DIRECTIONS, ve as ElementMorph, ue as FILL_MODES, Se as ManualTimeline, U as NumericAnimation, xe as ScrollTimeline, G as SmoothProgress, q as SpringProgress, Y as Timeline, A as defaultLayerConfig, k as defaultOptions, Q as getAnimationId, L as getTimingFunction, O as resolveKeyframes, ge as springLinearStops, _e as springTimingFunction };
|