@mkbabb/keyframes.js 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/keyframes.js CHANGED
@@ -1,7 +1,10 @@
1
- import { a as e, c as t, d as n, g as r, h as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, t as f, u as p } from "./timeline-CPT7qUV1.js";
2
- import { n as m, r as h, t as g } from "./springTimingFunction-DMb11kBe.js";
1
+ import { n as e, t } from "./errors-W8zkvPw4.js";
2
+ import { _ as n, a as r, c as i, f as a, g as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g } from "./timeline-B7SV3T_E.js";
3
+ import { n as _, r as v, t as y } from "./springTimingFunction-CDHZ00JQ.js";
4
+ import { n as b, t as x } from "./decay-BvNmFk51.js";
5
+ import { t as S } from "./sequence-CF5hazqz.js";
3
6
  //#region src/animation/numeric.ts
4
- var _ = class {
7
+ var C = new Float64Array(), w = class {
5
8
  keyframes;
6
9
  segments;
7
10
  positions;
@@ -9,15 +12,15 @@ var _ = class {
9
12
  _duration;
10
13
  _respectReducedMotion;
11
14
  _easingFn;
12
- _playback = new l();
13
- constructor(e, t) {
15
+ _playback = new c();
16
+ constructor(e, r) {
14
17
  if (e.length < 2) throw Error("NumericAnimation requires at least 2 keyframes.");
15
- this.keyframes = e.map((e) => ({ ...e })), this._duration = t?.duration ?? 0, this._respectReducedMotion = t?.respectReducedMotion ?? !1;
16
- let n = t?.timingFunction;
17
- if (typeof n == "string") throw new i("timingFunction", n, "NumericAnimation accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
18
- if (this._easingFn = n == null ? (e) => e : s(n).fn, t?.positions) {
19
- if (t.positions.length !== e.length) throw Error("positions length must match keyframes length.");
20
- this.positions = t.positions;
18
+ this.keyframes = e.map((e) => ({ ...e })), this._duration = r?.duration ?? 0, this._respectReducedMotion = r?.respectReducedMotion ?? !1;
19
+ let i = r?.timingFunction;
20
+ if (typeof i == "string") throw new t("timingFunction", i, "NumericAnimation accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
21
+ if (this._easingFn = i == null ? (e) => e : n(i).fn, r?.positions) {
22
+ if (r.positions.length !== e.length) throw Error("positions length must match keyframes length.");
23
+ this.positions = r.positions;
21
24
  } else this.positions = e.map((t, n) => n / (e.length - 1) * 100);
22
25
  this.result = { ...e[0] }, this.segments = this.buildSegments();
23
26
  }
@@ -27,21 +30,27 @@ var _ = class {
27
30
  return e;
28
31
  }
29
32
  buildSegment(e) {
30
- let t = this.keyframes[e], n = this.keyframes[e + 1], r = Object.keys(t);
33
+ let t = this.keyframes[e], n = this.keyframes[e + 1], r = Object.keys(t), i = new Float64Array(r.length), a = new Float64Array(r.length);
34
+ for (let e = 0; e < r.length; e++) {
35
+ let o = r[e];
36
+ i[e] = t[o], a[e] = n[o];
37
+ }
31
38
  return {
32
39
  startPos: this.positions[e],
33
40
  stopPos: this.positions[e + 1],
34
41
  keys: r,
35
- startVals: r.map((e) => t[e]),
36
- stopVals: r.map((e) => n[e]),
42
+ from: i,
43
+ to: a,
37
44
  timingFunction: this._easingFn
38
45
  };
39
46
  }
40
47
  at(e) {
41
- let r = t(e, 0, 1) * 100, i = n(this.segments, r, (e) => e.startPos, (e) => e.stopPos);
42
- i === -1 && (i = this.segments.length - 1);
43
- let a = this.segments[i], s = p(t(r, a.startPos, a.stopPos), a.startPos, a.stopPos, 0, 1), c = a.timingFunction(s);
44
- for (let e = 0; e < a.keys.length; e++) this.result[a.keys[e]] = o(a.startVals[e], a.stopVals[e], c);
48
+ let t = a(e, 0, 1) * 100, n = v(this.segments, t, (e) => e.startPos, (e) => e.stopPos);
49
+ n === -1 && (n = this.segments.length - 1);
50
+ let r = this.segments[n], i = l(a(t, r.startPos, r.stopPos), r.startPos, r.stopPos, 0, 1), o = r.timingFunction(i), s = r.keys.length;
51
+ C.length < s && (C = new Float64Array(s)), f(r.from, r.to, o, C);
52
+ let c = this.result;
53
+ for (let e = 0; e < s; e++) c[r.keys[e]] = C[e];
45
54
  return this.result;
46
55
  }
47
56
  updateKeyframe(e, t) {
@@ -58,7 +67,7 @@ var _ = class {
58
67
  stop() {
59
68
  this._playback.stop();
60
69
  }
61
- }, v = (e) => {
70
+ }, T = (e) => {
62
71
  if (e instanceof HTMLElement) {
63
72
  let t = e.getBoundingClientRect();
64
73
  return {
@@ -69,7 +78,7 @@ var _ = class {
69
78
  };
70
79
  }
71
80
  return e;
72
- }, y = class {
81
+ }, E = class {
73
82
  animation;
74
83
  transformOrigin;
75
84
  timingFunction;
@@ -78,8 +87,8 @@ var _ = class {
78
87
  this.transformOrigin = n?.transformOrigin ?? "top left", this.timingFunction = n?.timingFunction, this.duration = n?.duration ?? 0, this.measure(e, t);
79
88
  }
80
89
  measure(e, t) {
81
- let n = v(e), r = v(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;
82
- return this.animation = new _([{
90
+ let n = T(e), r = T(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;
91
+ return this.animation = new w([{
83
92
  translateX: 0,
84
93
  translateY: 0,
85
94
  scaleX: 1,
@@ -113,35 +122,65 @@ var _ = class {
113
122
  stop() {
114
123
  this.animation.stop();
115
124
  }
116
- }, b = (e, n) => {
117
- if (typeof e == "number") return t(e, 0, Math.max(0, n - 1));
125
+ }, D = 2 * Math.PI;
126
+ function O(e, t) {
127
+ let n = e - Math.floor(e);
128
+ switch (t) {
129
+ case "sine": return Math.sin(D * n);
130
+ case "triangle": return n < .5 ? 4 * n - 1 : 3 - 4 * n;
131
+ case "square": return n < .5 ? 1 : -1;
132
+ case "sawtooth": return 2 * n - 1;
133
+ }
134
+ }
135
+ var k = class {
136
+ frequency;
137
+ waveform;
138
+ phase = 0;
139
+ constructor(e) {
140
+ this.frequency = e.frequency, this.waveform = e.waveform ?? "sine";
141
+ }
142
+ tick(e) {
143
+ let t = this.phase + this.frequency * e;
144
+ return this.phase = t - Math.floor(t), this.phase;
145
+ }
146
+ get value() {
147
+ return O(this.phase, this.waveform);
148
+ }
149
+ sample(e) {
150
+ return O(e * this.frequency, this.waveform);
151
+ }
152
+ reset(e = 0) {
153
+ this.phase = e - Math.floor(e);
154
+ }
155
+ }, A = (e, t) => {
156
+ if (typeof e == "number") return a(e, 0, Math.max(0, t - 1));
118
157
  switch (e) {
119
158
  case "first": return 0;
120
- case "last": return n - 1;
121
- case "center": return (n - 1) / 2;
159
+ case "last": return t - 1;
160
+ case "center": return (t - 1) / 2;
122
161
  case "edges": return -1;
123
162
  }
124
- }, x = (e, t, n) => n === "edges" ? Math.min(e, t - 1 - e) : Math.abs(e - b(n, t)), S = (e, t) => {
163
+ }, ee = (e, t, n) => n === "edges" ? Math.min(e, t - 1 - e) : Math.abs(e - A(n, t)), j = (e, t) => {
125
164
  if (e <= 1) return 0;
126
165
  if (t === "edges") return Math.floor((e - 1) / 2);
127
- let n = b(t, e);
166
+ let n = A(t, e);
128
167
  return Math.max(n, e - 1 - n);
129
168
  };
130
- function C(e, t = {}) {
131
- let { each: n = 100, from: r = "first", ease: a } = t;
132
- if (typeof a == "string") throw new i("ease", a, "stagger accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
133
- let o = a ? s(a).fn : void 0, c = typeof e == "number" ? e : e.length, l = (e, t) => {
169
+ function M(e, r = {}) {
170
+ let { each: i = 100, from: a = "first", ease: o } = r;
171
+ if (typeof o == "string") throw new t("ease", o, "stagger accepts a callable TimingFunction or a typed Easing; resolve a string name first via `await resolveEasing(name)`.");
172
+ let s = o ? n(o).fn : void 0, c = typeof e == "number" ? e : e.length, l = (e, t) => {
134
173
  if (t <= 1) return 0;
135
- let i = S(t, r);
136
- if (i === 0) return 0;
137
- let a = x(e, t, r);
138
- return o ? o(a / i) * n * i : a * n;
174
+ let n = j(t, a);
175
+ if (n === 0) return 0;
176
+ let r = ee(e, t, a);
177
+ return s ? s(r / n) * i * n : r * i;
139
178
  }, u = ((e, t = c) => l(e, t));
140
179
  return u.delays = (e = c) => Array.from({ length: e }, (t, n) => l(n, e)), u;
141
180
  }
142
181
  //#endregion
143
182
  //#region src/animation/flip.ts
144
- var w = 300, T = (e) => {
183
+ var N = 300, P = (e) => {
145
184
  let t = e.getBoundingClientRect();
146
185
  return {
147
186
  x: t.x,
@@ -149,21 +188,21 @@ var w = 300, T = (e) => {
149
188
  width: t.width,
150
189
  height: t.height
151
190
  };
152
- }, E = (e, t) => {
191
+ }, F = (e, t) => {
153
192
  let n = e.at(1), r = n.translateX, i = n.translateY, a = n.scaleX, o = n.scaleY, s = e.at(t);
154
193
  return `translate(${s.translateX - r}px, ${s.translateY - i}px) scale(${a === 0 ? 1 : s.scaleX / a}, ${o === 0 ? 1 : s.scaleY / o})`;
155
- }, D = (e, t, n, r) => (e.style.transformOrigin = r, e.style.transform = E(t, 0), n <= 0 ? (e.style.transform = E(t, 1), Promise.resolve()) : new l().play(n, (n) => {
156
- e.style.transform = E(t, n);
194
+ }, I = (e, t, n, r) => (e.style.transformOrigin = r, e.style.transform = F(t, 0), n <= 0 ? (e.style.transform = F(t, 1), Promise.resolve()) : new c().play(n, (n) => {
195
+ e.style.transform = F(t, n);
157
196
  }));
158
- function O(e, t, n = {}) {
159
- let { duration: r = w, timingFunction: i, transformOrigin: a = "top left" } = n, o = T(e);
160
- return t(), D(e, new y(o, T(e), {
197
+ function L(e, t, n = {}) {
198
+ let { duration: r = N, timingFunction: i, transformOrigin: a = "top left" } = n, o = P(e);
199
+ return t(), I(e, new E(o, P(e), {
161
200
  ...i === void 0 ? {} : { timingFunction: i },
162
201
  transformOrigin: a
163
202
  }), r, a);
164
203
  }
165
- function k(e, t, n = {}) {
166
- let { duration: r = w, timingFunction: i, transformOrigin: a = "top left" } = n, o = new y(T(e), T(t), {
204
+ function R(e, t, n = {}) {
205
+ let { duration: r = N, timingFunction: i, transformOrigin: a = "top left" } = n, o = new E(P(e), P(t), {
167
206
  ...i === void 0 ? {} : { timingFunction: i },
168
207
  duration: r,
169
208
  transformOrigin: a
@@ -171,12 +210,56 @@ function k(e, t, n = {}) {
171
210
  return o.apply(e, 0), r <= 0 ? (o.apply(e, 1), Promise.resolve()) : o.play(e, r);
172
211
  }
173
212
  //#endregion
213
+ //#region src/animation/drag-2d.ts
214
+ function z(e, t) {
215
+ let n = new U({
216
+ ...t?.x,
217
+ axis: "x"
218
+ }), r = new U({
219
+ ...t?.y,
220
+ axis: "y"
221
+ });
222
+ n.attach(e), r.attach(e);
223
+ let i = /* @__PURE__ */ new Set(), a = (e) => e.dragging ? e.spring.target : e.spring.value, o = () => {
224
+ let e = a(n), t = a(r), o = n.velocity, s = r.velocity;
225
+ for (let n of i) n(e, t, o, s);
226
+ }, s = n.subscribe(() => o()), c = r.subscribe(() => o());
227
+ return {
228
+ x: n,
229
+ y: r,
230
+ get value() {
231
+ return {
232
+ x: a(n),
233
+ y: a(r)
234
+ };
235
+ },
236
+ get velocity() {
237
+ return {
238
+ x: n.velocity,
239
+ y: r.velocity
240
+ };
241
+ },
242
+ get settled() {
243
+ return n.settled && r.settled;
244
+ },
245
+ subscribe(e) {
246
+ return i.add(e), () => i.delete(e);
247
+ },
248
+ dispose() {
249
+ i.clear(), s(), c(), n.dispose(), r.dispose();
250
+ }
251
+ };
252
+ }
253
+ //#endregion
174
254
  //#region src/animation/drag.ts
175
- var A = 100, j = class {
255
+ var B = 100, V = .4, H = 5, U = class {
176
256
  spring;
177
257
  axis;
178
258
  transform;
179
259
  velocityWindow;
260
+ bounds;
261
+ rubberBand;
262
+ snap;
180
263
  element;
181
264
  capturedPointerId;
182
265
  samples = [];
@@ -186,7 +269,7 @@ var A = 100, j = class {
186
269
  onPointerMove = (e) => this.handleMove(e);
187
270
  onPointerUp = (e) => this.handleUp(e);
188
271
  constructor(e) {
189
- this.axis = e?.axis ?? "x", this.transform = e?.transform ?? ((e) => e), this.velocityWindow = e?.velocityWindow ?? A, this.spring = e?.spring ?? new h(e?.springOptions);
272
+ this.axis = e?.axis ?? "x", this.transform = e?.transform ?? ((e) => e), this.velocityWindow = e?.velocityWindow ?? B, this.bounds = e?.bounds, this.rubberBand = e?.rubberBand ?? V, this.snap = e?.snap !== void 0 && e.snap.length > 0 ? e.snap : void 0, this.spring = e?.spring ?? new r(e?.springOptions);
190
273
  }
191
274
  get dragging() {
192
275
  return this.capturedPointerId !== void 0;
@@ -234,14 +317,38 @@ var A = 100, j = class {
234
317
  handleMove(e) {
235
318
  if (e.pointerId !== this.capturedPointerId) return;
236
319
  let t = this.coordOf(e);
237
- this.spring.target = t, this.pushSample(t, e.timeStamp);
320
+ this.spring.target = this.applyBounds(t), this.pushSample(t, e.timeStamp);
321
+ }
322
+ applyBounds(e) {
323
+ let t = this.bounds;
324
+ return t ? e < t.min ? t.min + (e - t.min) * this.rubberBand : e > t.max ? t.max + (e - t.max) * this.rubberBand : e : e;
238
325
  }
239
326
  handleUp(e) {
240
327
  if (e.pointerId !== this.capturedPointerId) return;
241
328
  let t = this.element, n = this.coordOf(e);
242
329
  this.pushSample(n, e.timeStamp);
243
330
  let r = this.estimateVelocity();
244
- t && this.endGesture(t), this.spring.reset(n, r);
331
+ if (t && this.endGesture(t), this.snap) {
332
+ let e = b({
333
+ initial: n,
334
+ velocity: r,
335
+ friction: H
336
+ }), t = this.nearestSnap(e);
337
+ this.bounds && (t = a(t, this.bounds.min, this.bounds.max)), this.spring.reset(n, r), this.spring.target = t;
338
+ return;
339
+ }
340
+ if (this.spring.reset(n, r), this.bounds) {
341
+ let e = this.spring.value;
342
+ (e < this.bounds.min || e > this.bounds.max) && (this.spring.target = a(e, this.bounds.min, this.bounds.max));
343
+ }
344
+ }
345
+ nearestSnap(e) {
346
+ let t = this.snap, n = t[0], r = Math.abs(e - n);
347
+ for (let i = 1; i < t.length; i++) {
348
+ let a = t[i], o = Math.abs(e - a);
349
+ o < r && (n = a, r = o);
350
+ }
351
+ return n;
245
352
  }
246
353
  endGesture(e) {
247
354
  this.capturedPointerId !== void 0 && e.releasePointerCapture?.(this.capturedPointerId), e.removeEventListener("pointermove", this.onPointerMove), e.removeEventListener("pointerup", this.onPointerUp), e.removeEventListener("pointercancel", this.onPointerUp), this.capturedPointerId = void 0;
@@ -262,203 +369,78 @@ var A = 100, j = class {
262
369
  return r <= 0 ? 0 : (n.value - t.value) / r * 1e3;
263
370
  }
264
371
  };
265
- function M(e, t) {
266
- let n = new j(t);
372
+ function W(e, t) {
373
+ let n = new U(t);
267
374
  return n.attach(e), n;
268
375
  }
269
376
  //#endregion
270
- //#region src/animation/decay.ts
271
- var N = 5;
272
- function P(e) {
273
- let t = e.initial ?? 0, n = e.velocity, r = e.friction ?? N;
274
- if (r <= 0) throw Error("decay() requires a friction coefficient > 0.");
275
- let i = t + n / r;
276
- return (e) => {
277
- if (e <= 0) return {
278
- value: t,
279
- velocity: n
280
- };
281
- let a = Math.exp(-r * e);
282
- return {
283
- value: i - n / r * a,
284
- velocity: n * a
285
- };
286
- };
287
- }
288
- function F(e) {
289
- let t = e.friction ?? N;
290
- if (t <= 0) throw Error("decayRest() requires a friction coefficient > 0.");
291
- return (e.initial ?? 0) + e.velocity / t;
292
- }
293
- //#endregion
294
- //#region src/animation/sequence.ts
295
- var I = class {
296
- entries = [];
297
- labels = /* @__PURE__ */ new Map();
298
- cursor = 0;
299
- _time = 0;
300
- respectReducedMotion;
301
- playback = new l();
302
- _boundFrame;
303
- _resolvePlay = null;
304
- _playOrigin = void 0;
305
- _playingPromise = null;
306
- _rate = 1;
307
- _repeatCount = 1;
308
- _yoyoOn = !1;
309
- _paused = !1;
310
- _lastClock = void 0;
311
- constructor(e) {
312
- this.respectReducedMotion = e?.respectReducedMotion ?? !1, this._boundFrame = this._frame.bind(this);
313
- }
314
- get duration() {
315
- let e = 0;
316
- for (let t of this.entries) {
317
- let n = t.at + t.animation.options.duration;
318
- n > e && (e = n);
319
- }
320
- return e;
321
- }
322
- get time() {
323
- return this._time;
324
- }
325
- get progress() {
326
- return this.duration === 0 ? 0 : this._time / this.duration;
327
- }
328
- set progress(e) {
329
- this.seek(t(e, 0, 1) * this.duration);
330
- }
331
- get rate() {
332
- return this._rate;
333
- }
334
- label(e, t) {
335
- return this.labels.set(e, this.resolvePosition(t)), this;
336
- }
337
- add(e, t) {
338
- let n = this.resolvePosition(t);
339
- return this.entries.push({
340
- animation: e,
341
- at: n
342
- }), this.entries.sort((e, t) => e.at - t.at), this.cursor = n + e.options.duration, this;
343
- }
344
- resolvePosition(e) {
345
- if (e === void 0) return this.cursor;
346
- if (typeof e == "number") return e;
347
- let t = /^([+-])=(\d*\.?\d+)$/.exec(e);
348
- if (t) {
349
- let e = t[1] === "+" ? 1 : -1;
350
- return this.cursor + e * Number.parseFloat(t[2]);
351
- }
352
- let n = this.labels.get(e);
353
- if (n === void 0) throw Error(`Sequence: unknown position "${e}". Register it with .label("${e}", at) first, or pass a number / "+=n" / "-=n".`);
354
- return n;
355
- }
356
- seek(e) {
357
- return this._time = e, this._applyAt(e), this;
358
- }
359
- _applyAt(e) {
360
- for (let { animation: n, at: r } of this.entries) {
361
- let i = t(e - r, 0, n.options.duration);
362
- n.interpFrames(i, !0);
363
- }
364
- }
365
- _fold(e) {
366
- let n = this.duration;
367
- if (n <= 0) return 0;
368
- let r = t(e, 0, n * this._repeatCount), i = Math.floor(r / n), a = r - i * n;
369
- return a === 0 && i > 0 && (--i, a = n), this._yoyoOn && i % 2 == 1 ? n - a : a;
370
- }
371
- setTargets(...e) {
372
- for (let { animation: t } of this.entries) t.setTargets(...e);
373
- return this;
374
- }
375
- get finished() {
376
- return this._playingPromise ?? Promise.resolve();
377
- }
378
- play() {
379
- if (this._playingPromise) return this._playingPromise;
380
- if (this.respectReducedMotion && L()) return this.seek(this.duration), Promise.resolve();
381
- for (let { animation: e, at: t } of this.entries) e.startTime = t, e.started = !0, e.managed = !0;
382
- this._time = 0, this._paused = !1, this._playOrigin = void 0, this._lastClock = void 0;
383
- let e = new Promise((e) => {
384
- this._resolvePlay = e, this.playback.loop(this._boundFrame);
385
- });
386
- return this._playingPromise = e, e.finally(() => {
387
- this._playingPromise = null;
388
- }), e;
389
- }
390
- async _frame(e) {
391
- this._playOrigin === void 0 && (this._playOrigin = this._rate === 0 ? e : e - this._time / this._rate), this._lastClock = e;
392
- let t = (e - this._playOrigin) * this._rate, n = this.duration * this._repeatCount, r = this._rate >= 0 ? t >= n : t <= 0, i = r ? this._rate >= 0 ? this._restPhase() : 0 : this._fold(t);
393
- if (this._time = i, this._isForwardMonotone()) for (let { animation: e, at: t } of this.entries) i >= t && i - t < e.options.duration && await e.advanceTo(i);
394
- if (this._applyAt(i), r) {
395
- this._settle();
396
- let e = this._resolvePlay;
397
- return this._resolvePlay = null, e?.(), !1;
398
- }
399
- return !0;
400
- }
401
- _isForwardMonotone() {
402
- return this._rate === 1 && this._repeatCount === 1 && !this._yoyoOn;
403
- }
404
- _restPhase() {
405
- let e = this.duration;
406
- return this._yoyoOn && (this._repeatCount - 1) % 2 == 1 ? 0 : e;
407
- }
408
- _reanchor() {
409
- if (!this._playingPromise) return;
410
- let e = this._lastClock;
411
- if (e === void 0) {
412
- this._playOrigin = void 0;
413
- return;
414
- }
415
- this._playOrigin = this._rate === 0 ? e : e - this._time / this._rate;
416
- }
417
- _settle() {
418
- for (let { animation: e } of this.entries) e.managed = !1, e.started = !1, e.startTime = void 0;
419
- this._playOrigin = void 0, this._lastClock = void 0, this._paused = !1;
420
- }
421
- stop() {
422
- this.playback.stop(), this._settle();
423
- let e = this._resolvePlay;
424
- return this._resolvePlay = null, e?.(), this;
425
- }
426
- pause() {
427
- return !this._playingPromise || this._paused ? this : (this._paused = !0, this.playback.stop(), this._playOrigin = void 0, this);
428
- }
429
- resume() {
430
- return !this._playingPromise || !this._paused ? this : (this._paused = !1, this._playOrigin = void 0, this._lastClock = void 0, this.playback.loop(this._boundFrame), this);
431
- }
432
- timeScale(e) {
433
- if (!Number.isFinite(e)) throw Error(`Sequence.timeScale(n): n must be a finite number, got ${e}.`);
434
- return this._rate = e, this._reanchor(), this;
435
- }
436
- reverse() {
437
- return this._rate = -this._rate, this._reanchor(), this;
438
- }
439
- repeat(e) {
440
- if (e !== Infinity && (!Number.isInteger(e) || e < 1)) throw Error(`Sequence.repeat(count): count must be a positive integer or Infinity, got ${e}.`);
441
- return this._repeatCount = e, this;
442
- }
443
- yoyo(e = !0) {
444
- return this._yoyoOn = e, this;
445
- }
446
- }, L = () => typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches, R = async () => {
447
- let [e, t, n, r, i] = await Promise.all([
448
- import("./engine-Gk4Q7ltr.js"),
449
- import("./animate-WjeAtXAe.js"),
450
- import("./motion-path-DQ73oD2j.js"),
451
- import("./draw-svg-Dm9f0vTl.js"),
452
- import("./animations-WlZvjmDT.js")
453
- ]);
454
- return Object.assign({
455
- animate: t.animate,
456
- MotionPath: n.MotionPath,
457
- fromMotionPath: n.fromMotionPath,
458
- DrawSVG: r.DrawSVG,
459
- fromDrawSVG: r.fromDrawSVG,
460
- presets: i
461
- }, e);
377
+ //#region src/animation/load-engine.ts
378
+ var G = null, K = null, q = null, J = null, Y = () => G ??= import("./engine-CNHvTgpw.js"), X = null, Z = () => X ??= Y(), Q = null, te = () => Q ??= Promise.all([Y(), K ??= import("./compile-DgNRG6Lo.js")]).then(([e, t]) => Object.assign({ compileToCSS: t.compileToCSS }, e)), ne = null, re = () => ne ??= Promise.all([
379
+ Y(),
380
+ q ??= import("./ingest-CNM5xkQT.js"),
381
+ J ??= import("./scroll-scene-CXEgM49Q.js")
382
+ ]).then(([e, t, n]) => Object.assign({
383
+ fromStyleSheets: t.fromStyleSheets,
384
+ fromLiveAnimations: t.fromLiveAnimations,
385
+ resolveLiveKeyframes: t.resolveLiveKeyframes,
386
+ adoptRunning: t.adoptRunning,
387
+ ScrollScene: n.ScrollScene,
388
+ createScrollScene: n.createScrollScene,
389
+ parseScrollCSS: n.parseScrollCSS,
390
+ parseScrollTimeline: n.parseScrollTimeline,
391
+ parseScrollRange: n.parseScrollRange,
392
+ serializeScrollOptions: n.serializeScrollOptions,
393
+ roundTripScrollCSS: n.roundTripScrollCSS,
394
+ dispatchScrollBackend: n.dispatchScrollBackend,
395
+ resolveRange: n.resolveRange,
396
+ pinCSS: n.pinCSS
397
+ }, e)), ie = null, $ = () => ie ??= Promise.all([
398
+ Y(),
399
+ import("./animate-CuUJt2Tb.js"),
400
+ import("./motion-path-J-RSNmRQ.js"),
401
+ import("./draw-svg-DYRDxBlL.js"),
402
+ import("./morph-svg-DRjl9Hfz.js"),
403
+ q ??= import("./ingest-CNM5xkQT.js"),
404
+ J ??= import("./scroll-scene-CXEgM49Q.js"),
405
+ K ??= import("./compile-DgNRG6Lo.js"),
406
+ import("./validate-8r6Yo-uc.js"),
407
+ import("./animations-5nf2kBkv.js"),
408
+ import("./format-BUgCTjmr.js").then((e) => e.r),
409
+ import("./utils-D7nuAND5.js").then((e) => e.o),
410
+ import("./scheduler-7eIr_q1g.js").then((e) => e.t)
411
+ ]).then(([e, t, n, r, i, a, o, s, c, l, u, d, f]) => Object.assign({
412
+ animate: t.animate,
413
+ MotionPath: n.MotionPath,
414
+ fromMotionPath: n.fromMotionPath,
415
+ DrawSVG: r.DrawSVG,
416
+ fromDrawSVG: r.fromDrawSVG,
417
+ MorphSVG: i.MorphSVG,
418
+ fromMorphSVG: i.fromMorphSVG,
419
+ fromStyleSheets: a.fromStyleSheets,
420
+ fromLiveAnimations: a.fromLiveAnimations,
421
+ resolveLiveKeyframes: a.resolveLiveKeyframes,
422
+ adoptRunning: a.adoptRunning,
423
+ ScrollScene: o.ScrollScene,
424
+ createScrollScene: o.createScrollScene,
425
+ parseScrollCSS: o.parseScrollCSS,
426
+ parseScrollTimeline: o.parseScrollTimeline,
427
+ parseScrollRange: o.parseScrollRange,
428
+ serializeScrollOptions: o.serializeScrollOptions,
429
+ roundTripScrollCSS: o.roundTripScrollCSS,
430
+ dispatchScrollBackend: o.dispatchScrollBackend,
431
+ resolveRange: o.resolveRange,
432
+ pinCSS: o.pinCSS,
433
+ compileToCSS: s.compileToCSS,
434
+ validate: c.validate,
435
+ explain: c.explain,
436
+ presets: l,
437
+ CSSKeyframesToString: u.CSSKeyframesToString,
438
+ CSSKeyframesToStrings: u.CSSKeyframesToStrings,
439
+ formatCSSKeyframeString: u.formatCSSKeyframeString,
440
+ transformTargetsStyle: d.transformTargetsStyle,
441
+ yieldToMain: f.yieldToMain
442
+ }, e)), ae = () => {
443
+ $();
462
444
  };
463
445
  //#endregion
464
- export { i as AnimationOptionError, j as Draggable, y as ElementMorph, f as ManualTimeline, _ as NumericAnimation, l as RAFPlayback, c as ScrollTimeline, I as Sequence, e as SmoothProgress, h as SpringProgress, d as Timeline, r as UnknownEasingError, a as createNativeTimeline, P as decay, F as decayRest, M as drag, O as flip, k as flipShared, R as loadAnimationEngine, u as resolveEasing, m as springLinearStops, g as springTimingFunction, C as stagger, s as toEasing };
446
+ export { t as AnimationOptionError, U as Draggable, E as ElementMorph, h as KeyframesScrollTimeline, h as ScrollTimeline, u as ManualTimeline, w as NumericAnimation, k as Oscillator, c as RAFPlayback, S as Sequence, i as SmoothProgress, r as SpringProgress, p as Timeline, e as UnknownEasingError, s as createNativeTimeline, x as decay, b as decayRest, W as drag, z as drag2D, L as flip, R as flipShared, $ as loadAnimationEngine, te as loadCompiler, Z as loadEngine, re as loadIngest, d as probeVelocity, g as reducedMotionScale, m as reseatToSpring, o as resolveEasing, _ as springLinearStops, y as springTimingFunction, M as stagger, n as toEasing, ae as warmEngine, O as waveformValue };
@@ -0,0 +1,62 @@
1
+ import { t as e } from "./errors-W8zkvPw4.js";
2
+ import { CSSKeyframesAnimation as t } from "./engine-CNHvTgpw.js";
3
+ import { PathGeometry as n } from "@mkbabb/value.js";
4
+ //#region src/animation/morph-svg.ts
5
+ var r = 64, i = (e) => `--morph-${e}-x`, a = (e) => `--morph-${e}-y`, o = (e, t) => {
6
+ let n = Array(t + 1);
7
+ for (let r = 0; r <= t; r++) n[r] = e.getPointAtT(r / t);
8
+ return n;
9
+ }, s = (e) => {
10
+ if (e.length === 0) return "";
11
+ let t = (e) => Number.isInteger(e) ? `${e}` : e.toFixed(3), n = `M ${t(e[0].x)} ${t(e[0].y)}`;
12
+ for (let r = 1; r < e.length; r++) n += ` L ${t(e[r].x)} ${t(e[r].y)}`;
13
+ return n;
14
+ };
15
+ function c(s, c, l = {}) {
16
+ let { samples: u = r, target: d, autoPlay: f = !0, ...p } = l;
17
+ if (typeof s != "string" || s.length === 0) throw new e("from", s, "fromMorphSVG(): `from` must be a non-empty SVG path `d` string.");
18
+ if (typeof c != "string" || c.length === 0) throw new e("to", c, "fromMorphSVG(): `to` must be a non-empty SVG path `d` string.");
19
+ if (!Number.isInteger(u) || u < 2) throw new e("samples", u, "fromMorphSVG(): `samples` must be an integer >= 2 (a 1-sample morph is just the two endpoints, with no body to interpolate).");
20
+ let m = new n(s), h = new n(c);
21
+ if (m.totalLength === 0) throw new e("from", s, "fromMorphSVG(): the `from` path has zero arc-length — a morph between a zero-length path and anything is malformed input, not an identity animation.");
22
+ if (h.totalLength === 0) throw new e("to", c, "fromMorphSVG(): the `to` path has zero arc-length — a morph between a zero-length path and anything is malformed input, not an identity animation.");
23
+ let g = o(m, u), _ = o(h, u), v = {}, y = {};
24
+ for (let e = 0; e <= u; e++) v[i(e)] = g[e].x, v[a(e)] = g[e].y, y[i(e)] = _[e].x, y[a(e)] = _[e].y;
25
+ let b = {
26
+ "0%": v,
27
+ "100%": y
28
+ }, x = new t(p).fromKeyframes(b);
29
+ return d != null && x.setTargets(d), f && x.play(), x;
30
+ }
31
+ var l = class {
32
+ animation;
33
+ samples;
34
+ constructor(e, t, n = {}) {
35
+ this.animation = c(e, t, n), this.samples = n.samples ?? r;
36
+ }
37
+ sampleD(e) {
38
+ let t = (e < 0 ? 0 : e > 1 ? 1 : e) * this.animation.options.duration, n = this.animation.interpFrames(t, !1), r = Array(this.samples + 1);
39
+ for (let e = 0; e <= this.samples; e++) {
40
+ let t = n[i(e)]?.[0]?.value, o = n[a(e)]?.[0]?.value;
41
+ r[e] = {
42
+ x: t ?? 0,
43
+ y: o ?? 0
44
+ };
45
+ }
46
+ return s(r);
47
+ }
48
+ play() {
49
+ return this.animation.play();
50
+ }
51
+ pause() {
52
+ return this.animation.pause(), this;
53
+ }
54
+ stop() {
55
+ return this.animation.stop(), this;
56
+ }
57
+ get finished() {
58
+ return this.animation.finished;
59
+ }
60
+ };
61
+ //#endregion
62
+ export { l as MorphSVG, c as fromMorphSVG };
@@ -1,4 +1,4 @@
1
- import { CSSKeyframesAnimation as e } from "./engine-Gk4Q7ltr.js";
1
+ import { CSSKeyframesAnimation as e } from "./engine-CNHvTgpw.js";
2
2
  //#region src/animation/motion-path.ts
3
3
  var t = (e) => typeof e == "number" ? `${e}%` : e;
4
4
  function n(n, r) {