@mkbabb/keyframes.js 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -76,6 +76,7 @@ declare class Animation_2<V extends Vars = any> {
76
76
  setDirection(direction: InputAnimationOptions["direction"]): this;
77
77
  setFillMode(fillMode: InputAnimationOptions["fillMode"]): this;
78
78
  setUseWAAPI(useWAAPI: InputAnimationOptions["useWAAPI"]): this;
79
+ setRespectReducedMotion(respectReducedMotion: InputAnimationOptions["respectReducedMotion"]): this;
79
80
  setColorSpace(colorSpace: InputAnimationOptions["colorSpace"]): this;
80
81
  setHueMethod(hueMethod: InputAnimationOptions["hueMethod"]): this;
81
82
  setOptions(options: Partial<InputAnimationOptions>): this;
@@ -120,6 +121,13 @@ declare class Animation_2<V extends Vars = any> {
120
121
  * before this is invoked, and runtime errors propagate.
121
122
  */
122
123
  private _playWAAPI;
124
+ /**
125
+ * `prefers-reduced-motion` snap: jump to the final frame in a single
126
+ * paint — no rAF/WAAPI loop. The lifecycle stays observable
127
+ * (`animationstart` → fill final → `animationend`) so consumers' event
128
+ * wiring is identical to a completed normal play.
129
+ */
130
+ private _playReducedMotion;
123
131
  play(): Promise<void>;
124
132
  pause(draw?: boolean): this;
125
133
  resume(): this;
@@ -187,6 +195,19 @@ export declare class AnimationGroup<V extends Vars> {
187
195
  paused: boolean;
188
196
  started: boolean;
189
197
  done: boolean;
198
+ /**
199
+ * When true, `play()` honors `prefers-reduced-motion: reduce` by snapping
200
+ * every child to its final frame in a single composite instead of running
201
+ * the rAF draw loop. SSR-safe no-op off-DOM. Default false.
202
+ */
203
+ respectReducedMotion: boolean;
204
+ /**
205
+ * Children-per-slice before `tick()` yields to the main thread. Groups at
206
+ * or under this size tick in one slice (fast path); larger groups tick in
207
+ * batches with a `scheduler.yield()` between them so a big per-frame
208
+ * composite doesn't run as one long task (INP relief).
209
+ */
210
+ static readonly YIELD_BATCH = 32;
190
211
  singleTarget: boolean;
191
212
  lastTickTime: number;
192
213
  handleId: number | any;
@@ -252,6 +273,8 @@ export declare class AnimationGroup<V extends Vars> {
252
273
  * (startTime, this.t) resolve before interpFrames reads them.
253
274
  */
254
275
  tick(t: number): Promise<this>;
276
+ /** Advance one slice of children to timestamp `t`, awaiting their ticks together. */
277
+ private _tickSlice;
255
278
  /**
256
279
  * Main animation frame callback. Ticks all children, then renders
257
280
  * (single-target: grouped blending; multi-target: per-child).
@@ -261,8 +284,26 @@ export declare class AnimationGroup<V extends Vars> {
261
284
  /**
262
285
  * Start the animation group. Returns a promise that resolves
263
286
  * when all child animations complete (or on explicit stop/reset).
287
+ *
288
+ * Under `respectReducedMotion` + an active `prefers-reduced-motion`
289
+ * query, snaps every child to its final frame in a single composite —
290
+ * no rAF draw loop — then settles exactly as a completed play would.
264
291
  */
265
292
  play(): Promise<unknown>;
293
+ /**
294
+ * `prefers-reduced-motion` snap for the group: advance every child to its
295
+ * final frame, composite a single paint, then settle child + group state
296
+ * for replay — no rAF loop, no motion. The final frame STAYS on the
297
+ * target(s): reduced motion shows the END state, matching
298
+ * `Animation._playReducedMotion`.
299
+ *
300
+ * Deliberately does NOT route through `reset()` — `reset()` repaints every
301
+ * child to frame 0 (`interpFrames(0, true)`, the fillBackwards
302
+ * cube-cutoff workaround), which would clobber the snapped final frame and
303
+ * leave, e.g., a `fadeIn` group invisible. The child `Animation.reset()`
304
+ * clears state flags only and does not repaint, so it is safe here.
305
+ */
306
+ private _playReducedMotion;
266
307
  /**
267
308
  * Toggle pause state. Calling pause() when playing pauses; calling
268
309
  * pause() when paused resumes. (Toggle semantics preserved for
@@ -327,6 +368,13 @@ export declare type AnimationOptions = {
327
368
  fillMode: (typeof FILL_MODES)[number];
328
369
  timingFunction: TimingFunction;
329
370
  useWAAPI: boolean;
371
+ /**
372
+ * When true, honor `prefers-reduced-motion: reduce` by snapping the
373
+ * `Animation`/`AnimationGroup` `play()` path to the final frame in a
374
+ * single paint instead of running the rAF/WAAPI loop. SSR-safe no-op
375
+ * off-DOM. Default false (consumers opt in).
376
+ */
377
+ respectReducedMotion: boolean;
330
378
  colorSpace: ColorSpace;
331
379
  hueMethod?: HueInterpolationMethod;
332
380
  };
@@ -417,6 +465,8 @@ export declare type InputAnimationOptions = Partial<{
417
465
  timingFunction: TimingFunction | TimingFunctionNames | undefined;
418
466
  /** When true (default), eligible animations may use the Web Animations API for compositor-thread execution. Set to false to force rAF. */
419
467
  useWAAPI: boolean;
468
+ /** When true, snap `play()` to the final frame under `prefers-reduced-motion: reduce`. Default false. */
469
+ respectReducedMotion: boolean;
420
470
  colorSpace?: ColorSpace;
421
471
  hueMethod?: HueInterpolationMethod;
422
472
  }>;
@@ -482,12 +532,10 @@ export declare class NumericAnimation<T extends Record<string, number>> {
482
532
  private keyframes;
483
533
  private segments;
484
534
  private positions;
485
- private timingFn;
486
535
  private result;
487
536
  private _duration;
488
537
  private _respectReducedMotion;
489
- private _pendingEasingName;
490
- private _easingReady;
538
+ private _easing;
491
539
  private _playback;
492
540
  constructor(keyframes: T[], options?: NumericAnimationOptions);
493
541
  private buildSegments;
@@ -495,12 +543,14 @@ export declare class NumericAnimation<T extends Record<string, number>> {
495
543
  /**
496
544
  * Resolve a pending string easing *name* through the dynamic engine
497
545
  * boundary. A no-op (resolved promise) when easing was supplied as a
498
- * callable or omitted. Memoized — the `await import("./engine")` and
499
- * `getTimingFunction` lookup run at most once per instance.
546
+ * callable or omitted. Memoized via the shared `EasingResolvable` — the
547
+ * `await import("./engine")` and `getTimingFunction` lookup run at most
548
+ * once per instance.
500
549
  *
501
- * `.play()` awaits this before the first frame; stateless `.at()`
502
- * consumers that pass a name can `await animation.ready()` first to
503
- * interpolate with the resolved easing rather than the linear fallback.
550
+ * Resolution is already kicked off eagerly at construction; `.play()`
551
+ * awaits this before the first frame, and stateless `.at()` consumers
552
+ * that pass a name can `await animation.ready()` first to interpolate
553
+ * with the resolved easing rather than the identity fallback.
504
554
  */
505
555
  ready(): Promise<void>;
506
556
  /**
@@ -537,13 +587,15 @@ export declare interface NumericAnimationOptions {
537
587
  * A **callable** is used directly and keeps this engine value.js-free —
538
588
  * no dynamic import, nothing pulled into the static graph.
539
589
  *
540
- * A **string name** is resolved LAZILY through the dynamic engine
541
- * boundary: on the first `.play()` (or an explicit `await .ready()`)
542
- * the engine module is `await import(...)`-ed and the name looked up
543
- * via `getTimingFunction`, so the value.js-bearing easing registry
544
- * loads only when a named easing is actually used. The resolved
545
- * callable is cached on the instance (resolved once per animation).
546
- * Until resolution, `.at()` interpolates with a linear fallback.
590
+ * A **string name** is resolved through the dynamic engine boundary via
591
+ * the shared `EasingResolvable` contract: resolution is kicked off
592
+ * EAGERLY at construction (an `await import("./engine")` looks the name
593
+ * up via `getTimingFunction`), so the value.js-bearing easing registry
594
+ * loads only when a named easing is actually used and the named curve
595
+ * lands by the first frame. Until it lands, `.at()` interpolates with the
596
+ * identity fallback and emits a one-time dev-only warning; `await
597
+ * .ready()` first to interpolate with the named curve from the very first
598
+ * synchronous `.at()`.
547
599
  */
548
600
  timingFunction?: TimingFunction | TimingFunctionNames | undefined;
549
601
  /** Playback duration in milliseconds. Required for `.play()`. */
@@ -570,12 +622,13 @@ declare type ParsedVarMap = Record<string, ValueArray>;
570
622
  /**
571
623
  * Shared rAF playback lifecycle for stateless interpolators
572
624
  * (`NumericAnimation`, `ElementMorph`). Owns the rAF handle, start
573
- * timestamp, and resolve callback so the interpolator classes don't
574
- * each reimplement the same loop.
625
+ * timestamp, resolve callback, AND the `prefers-reduced-motion` gate so the
626
+ * interpolator classes don't each reimplement the same loop or the same
627
+ * reduced-motion snap.
575
628
  *
576
629
  * Not used by the full `Animation` class — that engine has a richer
577
630
  * lifecycle (iteration, direction, fill modes, events) that doesn't
578
- * factor into this primitive.
631
+ * factor into this primitive; it carries its own reduced-motion snap.
579
632
  */
580
633
  export declare class RAFPlayback {
581
634
  private _rafId;
@@ -586,13 +639,35 @@ export declare class RAFPlayback {
586
639
  * `progress` is clamped to [0, 1]; the loop terminates after the
587
640
  * frame at `progress === 1`. The returned promise resolves when
588
641
  * the animation completes naturally or is interrupted by `stop()`.
642
+ *
643
+ * Under `options.respectReducedMotion` + an active
644
+ * `prefers-reduced-motion: reduce` query, snaps to the final frame —
645
+ * `onTick(1)` fires once, no rAF loop is spawned, and the promise
646
+ * resolves on the next microtask.
589
647
  */
590
- play(duration: number, onTick: (progress: number) => void): Promise<void>;
648
+ play(duration: number, onTick: (progress: number) => void, options?: RAFPlaybackOptions): Promise<void>;
591
649
  /** Cancel a running playback. The play promise resolves immediately. */
592
650
  stop(): void;
593
651
  private _cleanup;
594
652
  }
595
653
 
654
+ /** Per-playback options for {@link RAFPlayback.play}. */
655
+ declare interface RAFPlaybackOptions {
656
+ /**
657
+ * Honor `prefers-reduced-motion: reduce` by snapping to the final frame
658
+ * (`onTick(1)`) in a single paint instead of running the rAF loop. The
659
+ * returned promise resolves on the next microtask. Default false.
660
+ *
661
+ * This is THE shared reduced-motion gate for the light managed-playback
662
+ * surface: `NumericAnimation` (and `ElementMorph`, which composes it)
663
+ * route their `respectReducedMotion` option straight through here, so the
664
+ * snap lives in one place rather than re-implemented per interpolator.
665
+ * SSR-safe — off-DOM `prefersReducedMotion()` is false, so playback runs
666
+ * normally.
667
+ */
668
+ respectReducedMotion?: boolean | undefined;
669
+ }
670
+
596
671
  /**
597
672
  * Result of normalising a CSS keyframes input down to the shape the
598
673
  * `CSSKeyframesAnimation.fromString` flow expects: a `Map<percent →
@@ -971,22 +1046,16 @@ export declare interface TemplateAnimationFrame<V extends Vars> {
971
1046
 
972
1047
  export declare abstract class Timeline {
973
1048
  private smoother;
974
- private easingFn;
1049
+ private _easing;
975
1050
  private currentProgress;
976
1051
  private boundaryEpsilon;
977
- private _easingReady;
978
1052
  constructor(options?: TimelineOptions);
979
- /**
980
- * Lazily resolve a string easing *name* through the dynamic engine
981
- * boundary. Memoized — the `await import("./engine")` and
982
- * `getTimingFunction` lookup run at most once.
983
- */
984
- private resolveEasingName;
985
1053
  /**
986
1054
  * Resolve a pending string easing *name* through the dynamic engine
987
1055
  * boundary. No-op (resolved promise) for callable / omitted easing.
988
- * `await timeline.ready()` before the first `tick()` to apply the
989
- * eased value immediately rather than letting it land asynchronously.
1056
+ * Resolution is already kicked off eagerly at construction; `await
1057
+ * timeline.ready()` before the first `tick()` to apply the eased value
1058
+ * immediately rather than letting it land asynchronously.
990
1059
  */
991
1060
  ready(): Promise<void>;
992
1061
  /** Subclass returns raw [0,1] progress from its source. */
@@ -1029,11 +1098,12 @@ export declare interface TimelineOptions {
1029
1098
  *
1030
1099
  * A **callable** is applied directly and keeps `Timeline` value.js-free.
1031
1100
  *
1032
- * A **string name** is resolved LAZILY through the dynamic engine
1033
- * boundary: the constructor kicks off an `await import(...)` and the
1034
- * resolved easing is applied once it lands (subsequent `tick()`s use
1035
- * it). Until then `tick()` runs with the identity easing. Consumers
1036
- * that need the eased value on the very first `tick()` can
1101
+ * A **string name** is resolved through the dynamic engine boundary via
1102
+ * the shared `EasingResolvable` contract: the constructor kicks off an
1103
+ * eager `await import(...)` and the resolved easing is applied once it
1104
+ * lands (subsequent `tick()`s use it). Until then `tick()` runs with the
1105
+ * identity easing and emits a one-time dev-only warning. Consumers that
1106
+ * need the eased value on the very first `tick()` can
1037
1107
  * `await timeline.ready()` first.
1038
1108
  */
1039
1109
  easing?: TimingFunction | TimingFunctionNames | undefined;
package/dist/keyframes.js CHANGED
@@ -1,51 +1,70 @@
1
- import { a as e, i as t, n, o as r, r as i, t as a } from "./leaves-Bu89334e.js";
2
- //#region src/animation/playback.ts
3
- var o = class {
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s } from "./css-easing-DoPNckiS.js";
2
+ //#region src/animation/internal/easing-resolvable.ts
3
+ var c = (e) => e, l = class {
4
+ _fn;
5
+ _pendingName = null;
6
+ _ready = null;
7
+ _onResolved;
8
+ _warned = !1;
9
+ constructor(e, t) {
10
+ this._onResolved = t, typeof e == "function" ? this._fn = e : typeof e == "string" ? (this._fn = c, this._pendingName = e, this.ready()) : this._fn = c;
11
+ }
12
+ get fn() {
13
+ return this._fn;
14
+ }
15
+ get pending() {
16
+ return this._pendingName !== null;
17
+ }
18
+ ready() {
19
+ if (this._pendingName === null) return Promise.resolve();
20
+ if (this._ready) return this._ready;
21
+ let e = this._pendingName;
22
+ return this._ready = import("./engine-B7JGZTdU.js").then((t) => {
23
+ let n = t.getTimingFunction(e);
24
+ n && (this._fn = n, this._onResolved?.(n)), this._pendingName = null;
25
+ }), this._ready;
26
+ }
27
+ warnIfPending(e) {
28
+ this._pendingName !== null && !this._warned && (this._warned = !0, console.warn(`[keyframes] ${e}: easing "${this._pendingName}" is still resolving — interpolating with the identity fallback until it lands. \`await .ready()\` before the first synchronous \`.at()\` to interpolate with the named curve from the first frame.`));
29
+ }
30
+ }, u = class {
4
31
  _rafId = null;
5
32
  _startTime = void 0;
6
33
  _resolve = null;
7
- play(e, r) {
8
- if (e <= 0) throw Error("RAFPlayback.play() requires a duration > 0.");
9
- return this.stop(), new Promise((i) => {
10
- this._resolve = i, this._startTime = void 0;
11
- let a = (i) => {
12
- this._startTime === void 0 && (this._startTime = i);
13
- let o = n((i - this._startTime) / e, 0, 1);
14
- r(o), o < 1 ? this._rafId = t(a) : this._cleanup();
34
+ play(t, n, r) {
35
+ if (t <= 0) throw Error("RAFPlayback.play() requires a duration > 0.");
36
+ return this.stop(), r?.respectReducedMotion && o() ? (n(1), Promise.resolve()) : new Promise((r) => {
37
+ this._resolve = r, this._startTime = void 0;
38
+ let i = (r) => {
39
+ this._startTime === void 0 && (this._startTime = r);
40
+ let a = e((r - this._startTime) / t, 0, 1);
41
+ n(a), a < 1 ? this._rafId = s(i) : this._cleanup();
15
42
  };
16
- this._rafId = t(a);
43
+ this._rafId = s(i);
17
44
  });
18
45
  }
19
46
  stop() {
20
- this._rafId !== null && a(this._rafId), this._cleanup();
47
+ this._rafId !== null && n(this._rafId), this._cleanup();
21
48
  }
22
49
  _cleanup() {
23
50
  this._rafId = null, this._startTime = void 0;
24
51
  let e = this._resolve;
25
52
  this._resolve = null, e?.();
26
53
  }
27
- };
28
- //#endregion
29
- //#region src/animation/numeric.ts
30
- function s() {
31
- return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
32
- }
33
- var c = (e) => e, l = class {
54
+ }, d = class {
34
55
  keyframes;
35
56
  segments;
36
57
  positions;
37
- timingFn;
38
58
  result;
39
59
  _duration;
40
60
  _respectReducedMotion;
41
- _pendingEasingName = null;
42
- _easingReady = null;
43
- _playback = new o();
61
+ _easing;
62
+ _playback = new u();
44
63
  constructor(e, t) {
45
64
  if (e.length < 2) throw Error("NumericAnimation requires at least 2 keyframes.");
46
- this.keyframes = e.map((e) => ({ ...e })), this._duration = t?.duration ?? 0, this._respectReducedMotion = t?.respectReducedMotion ?? !1;
47
- let n = t?.timingFunction;
48
- if (typeof n == "function" ? this.timingFn = n : typeof n == "string" ? (this.timingFn = c, this._pendingEasingName = n) : this.timingFn = c, t?.positions) {
65
+ if (this.keyframes = e.map((e) => ({ ...e })), this._duration = t?.duration ?? 0, this._respectReducedMotion = t?.respectReducedMotion ?? !1, this._easing = new l(t?.timingFunction, () => {
66
+ this.segments = this.buildSegments();
67
+ }), t?.positions) {
49
68
  if (t.positions.length !== e.length) throw Error("positions length must match keyframes length.");
50
69
  this.positions = t.positions;
51
70
  } else this.positions = e.map((t, n) => n / (e.length - 1) * 100);
@@ -64,23 +83,18 @@ var c = (e) => e, l = class {
64
83
  keys: r,
65
84
  startVals: r.map((e) => t[e]),
66
85
  stopVals: r.map((e) => n[e]),
67
- timingFunction: this.timingFn
86
+ timingFunction: this._easing.fn
68
87
  };
69
88
  }
70
89
  ready() {
71
- if (this._pendingEasingName === null) return Promise.resolve();
72
- if (this._easingReady) return this._easingReady;
73
- let e = this._pendingEasingName;
74
- return this._easingReady = import("./engine-DuAFoqZF.js").then((t) => {
75
- let n = t.getTimingFunction(e);
76
- n && (this.timingFn = n, this.segments = this.buildSegments()), this._pendingEasingName = null;
77
- }), this._easingReady;
90
+ return this._easing.ready();
78
91
  }
79
- at(t) {
80
- let a = n(t, 0, 1) * 100, o = r(this.segments, a, (e) => e.startPos, (e) => e.stopPos);
92
+ at(n) {
93
+ this._easing.warnIfPending("NumericAnimation.at()");
94
+ let i = e(n, 0, 1) * 100, o = r(this.segments, i, (e) => e.startPos, (e) => e.stopPos);
81
95
  o === -1 && (o = this.segments.length - 1);
82
- let s = this.segments[o], c = e(n(a, s.startPos, s.stopPos), s.startPos, s.stopPos, 0, 1), l = s.timingFunction(c);
83
- for (let e = 0; e < s.keys.length; e++) this.result[s.keys[e]] = i(s.startVals[e], s.stopVals[e], l);
96
+ let s = this.segments[o], c = t(e(i, s.startPos, s.stopPos), s.startPos, s.stopPos, 0, 1), l = s.timingFunction(c);
97
+ for (let e = 0; e < s.keys.length; e++) this.result[s.keys[e]] = a(s.startVals[e], s.stopVals[e], l);
84
98
  return this.result;
85
99
  }
86
100
  updateKeyframe(e, t) {
@@ -90,31 +104,22 @@ var c = (e) => e, l = class {
90
104
  async play(e, t) {
91
105
  await this.ready();
92
106
  let n = t ?? this._duration;
93
- if (this._respectReducedMotion && s()) {
94
- let t = this.at(1);
95
- e?.(t);
96
- return;
97
- }
98
107
  await this._playback.play(n, (t) => {
99
108
  let n = this.at(t);
100
109
  e?.(n);
101
- });
110
+ }, { respectReducedMotion: this._respectReducedMotion });
102
111
  }
103
112
  stop() {
104
113
  this._playback.stop();
105
114
  }
106
- }, u = {
115
+ }, f = {
107
116
  damping: .1,
108
117
  snapThreshold: .001,
109
118
  targetEpsilon: 0,
110
119
  initial: 0,
111
120
  clamp: !0,
112
121
  respectReducedMotion: !1
113
- };
114
- function d() {
115
- return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
116
- }
117
- var f = class {
122
+ }, p = class {
118
123
  options;
119
124
  targetValue;
120
125
  currentValue;
@@ -124,7 +129,7 @@ var f = class {
124
129
  _onFrame = void 0;
125
130
  constructor(e) {
126
131
  this.options = {
127
- ...u,
132
+ ...f,
128
133
  ...e
129
134
  }, this.targetValue = this.options.initial, this.currentValue = this.options.initial, this.isSettled = !0;
130
135
  }
@@ -141,7 +146,7 @@ var f = class {
141
146
  this.options.clamp && (e = Math.max(0, Math.min(1, e)));
142
147
  let t = Math.abs(e - this.targetValue);
143
148
  if (t > 0 && t >= this.options.targetEpsilon) {
144
- if (this.targetValue = e, this.options.respectReducedMotion && d()) {
149
+ if (this.targetValue = e, this.options.respectReducedMotion && o()) {
145
150
  this.currentValue = e, this.isSettled = !0, this._onFrame?.(e);
146
151
  return;
147
152
  }
@@ -164,7 +169,7 @@ var f = class {
164
169
  this.targetValue = t, this.currentValue = t, this.isSettled = !0, this._stopLoop();
165
170
  }
166
171
  play(e) {
167
- if (this._onFrame = e, this.options.respectReducedMotion && d()) {
172
+ if (this._onFrame = e, this.options.respectReducedMotion && o()) {
168
173
  this.currentValue = this.targetValue, this.isSettled = !0, e?.(this.currentValue);
169
174
  return;
170
175
  }
@@ -180,22 +185,22 @@ var f = class {
180
185
  _startLoop() {
181
186
  if (this._rafId !== null) return;
182
187
  this._lastFrameT = 0;
183
- let e = (n) => {
184
- let r = this._lastFrameT ? n - this._lastFrameT : 16.667;
185
- this._lastFrameT = n;
186
- let i = this.tickDt(r);
187
- if (this._onFrame?.(i), this.isSettled) {
188
+ let e = (t) => {
189
+ let n = this._lastFrameT ? t - this._lastFrameT : 16.667;
190
+ this._lastFrameT = t;
191
+ let r = this.tickDt(n);
192
+ if (this._onFrame?.(r), this.isSettled) {
188
193
  this._stopLoop();
189
194
  return;
190
195
  }
191
- this._rafId = t(e);
196
+ this._rafId = s(e);
192
197
  };
193
- this._rafId = t(e);
198
+ this._rafId = s(e);
194
199
  }
195
200
  _stopLoop() {
196
- this._rafId !== null && (a(this._rafId), this._rafId = null), this._lastFrameT = 0;
201
+ this._rafId !== null && (n(this._rafId), this._rafId = null), this._lastFrameT = 0;
197
202
  }
198
- }, p = {
203
+ }, m = {
199
204
  response: .5,
200
205
  dampingFraction: .86,
201
206
  initial: 0,
@@ -203,11 +208,7 @@ var f = class {
203
208
  settleThreshold: .001,
204
209
  velocitySettleThreshold: .001,
205
210
  respectReducedMotion: !1
206
- };
207
- function m() {
208
- return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
209
- }
210
- var h = class {
211
+ }, h = class {
211
212
  options;
212
213
  targetValue;
213
214
  currentValue;
@@ -226,7 +227,7 @@ var h = class {
226
227
  _onFrame = void 0;
227
228
  constructor(e) {
228
229
  this.options = {
229
- ...p,
230
+ ...m,
230
231
  ...e
231
232
  }, 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;
232
233
  }
@@ -246,7 +247,7 @@ var h = class {
246
247
  e === this.targetValue && !this.options.initialVelocity || this.reseatTarget(e);
247
248
  }
248
249
  reseatTarget(e) {
249
- if (this.targetValue = e, this.options.respectReducedMotion && m()) {
250
+ if (this.targetValue = e, this.options.respectReducedMotion && o()) {
250
251
  this.currentValue = e, this.currentVelocity = 0, this.isSettled = !0, this.originValue = e, this.originVelocity = 0, this.elapsed = 0, this.emit(), this._stopLoop();
251
252
  return;
252
253
  }
@@ -296,7 +297,7 @@ var h = class {
296
297
  }
297
298
  play(e) {
298
299
  if (!this.disposed) {
299
- if (this._onFrame = e, this.options.respectReducedMotion && m()) {
300
+ if (this._onFrame = e, this.options.respectReducedMotion && o()) {
300
301
  this.currentValue = this.targetValue, this.currentVelocity = 0, this.isSettled = !0, e?.(this.currentValue, this.currentVelocity);
301
302
  return;
302
303
  }
@@ -313,18 +314,18 @@ var h = class {
313
314
  _startLoop() {
314
315
  if (this._rafId !== null) return;
315
316
  this._lastFrameT = 0;
316
- let e = (n) => {
317
- let r = this._lastFrameT ? n - this._lastFrameT : 16.667;
318
- if (this._lastFrameT = n, this.tick(r / 1e3), this._onFrame?.(this.currentValue, this.currentVelocity), this.isSettled) {
317
+ let e = (t) => {
318
+ let n = this._lastFrameT ? t - this._lastFrameT : 16.667;
319
+ if (this._lastFrameT = t, this.tick(n / 1e3), this._onFrame?.(this.currentValue, this.currentVelocity), this.isSettled) {
319
320
  this._stopLoop();
320
321
  return;
321
322
  }
322
- this._rafId = t(e);
323
+ this._rafId = s(e);
323
324
  };
324
- this._rafId = t(e);
325
+ this._rafId = s(e);
325
326
  }
326
327
  _stopLoop() {
327
- this._rafId !== null && (a(this._rafId), this._rafId = null), this._lastFrameT = 0;
328
+ this._rafId !== null && (n(this._rafId), this._rafId = null), this._lastFrameT = 0;
328
329
  }
329
330
  };
330
331
  //#endregion
@@ -349,24 +350,29 @@ function g(e) {
349
350
  //#endregion
350
351
  //#region src/animation/springTimingFunction.ts
351
352
  function _(e) {
352
- let t = e.sampleCount ?? 64, n = e.settleThreshold ?? .001, r = e.maxDuration ?? e.response * 4, i = new h({
353
+ let t = e.sampleCount ?? 64, n = e.settleThreshold ?? .001, r = e.maxDuration ?? e.response * 4, a = new h({
353
354
  response: e.response,
354
355
  dampingFraction: e.dampingFraction,
355
356
  initial: 0,
356
357
  settleThreshold: n,
357
358
  velocitySettleThreshold: n
358
359
  });
359
- i.target = 1;
360
- let a = new Float64Array(t + 1);
361
- a[0] = 0;
362
- let o = r / t;
363
- for (let e = 1; e <= t; e++) i.tick(o), a[e] = i.settled ? 1 : i.value;
364
- return a[t] = 1, i.dispose(), (e) => {
360
+ a.target = 1;
361
+ let o = new Float64Array(t + 1);
362
+ o[0] = 0;
363
+ let s = r / t;
364
+ for (let e = 1; e <= t; e++) a.tick(s), o[e] = a.settled ? 1 : a.value;
365
+ o[t] = 1, a.dispose();
366
+ let c = (e) => {
365
367
  if (e <= 0) return 0;
366
368
  if (e >= 1) return 1;
367
- let n = e * t, r = Math.floor(n), i = n - r, o = a[r];
368
- return o + (a[r + 1] - o) * i;
369
+ let n = e * t, r = Math.floor(n), i = n - r, a = o[r];
370
+ return a + (o[r + 1] - a) * i;
371
+ }, l = {
372
+ response: e.response,
373
+ dampingFraction: e.dampingFraction
369
374
  };
375
+ return e.settleThreshold !== void 0 && (l.settleThreshold = e.settleThreshold), e.maxDuration !== void 0 && (l.maxDuration = e.maxDuration), i(c, g(l));
370
376
  }
371
377
  //#endregion
372
378
  //#region src/animation/morph.ts
@@ -391,7 +397,7 @@ var v = (e) => {
391
397
  }
392
398
  measure(e, t) {
393
399
  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;
394
- return this.animation = new l([{
400
+ return this.animation = new d([{
395
401
  translateX: 0,
396
402
  translateY: 0,
397
403
  scaleX: 1,
@@ -430,27 +436,19 @@ var v = (e) => {
430
436
  }
431
437
  }, b = (e) => Math.max(0, Math.min(1, e)), x = class {
432
438
  smoother;
433
- easingFn;
439
+ _easing;
434
440
  currentProgress = 0;
435
441
  boundaryEpsilon;
436
- _easingReady = null;
437
442
  constructor(e) {
438
- this.boundaryEpsilon = e?.boundaryEpsilon ?? .005;
439
- let t = e?.easing;
440
- typeof t == "function" ? this.easingFn = t : typeof t == "string" ? (this.easingFn = null, this.resolveEasingName(t)) : this.easingFn = null, e?.smoothing === !1 ? this.smoother = null : this.smoother = new f(e?.smoothing);
441
- }
442
- resolveEasingName(e) {
443
- return this._easingReady ||= import("./engine-DuAFoqZF.js").then((t) => {
444
- let n = t.getTimingFunction(e);
445
- n && (this.easingFn = n);
446
- }), this._easingReady;
443
+ this.boundaryEpsilon = e?.boundaryEpsilon ?? .005, this._easing = new l(e?.easing), e?.smoothing === !1 ? this.smoother = null : this.smoother = new p(e?.smoothing);
447
444
  }
448
445
  ready() {
449
- return this._easingReady ?? Promise.resolve();
446
+ return this._easing.ready();
450
447
  }
451
448
  applyPipeline() {
449
+ this._easing.warnIfPending("Timeline.tick()");
452
450
  let e = b(this.sample());
453
- this.easingFn && (e = this.easingFn(e));
451
+ e = this._easing.fn(e);
454
452
  let t = this.boundaryEpsilon;
455
453
  return e <= t ? e = 0 : e >= 1 - t && (e = 1), e;
456
454
  }
@@ -505,6 +503,6 @@ var v = (e) => {
505
503
  sample() {
506
504
  return this.value;
507
505
  }
508
- }, w = () => import("./engine-DuAFoqZF.js");
506
+ }, w = () => import("./engine-B7JGZTdU.js");
509
507
  //#endregion
510
- export { y as ElementMorph, C as ManualTimeline, l as NumericAnimation, o as RAFPlayback, S as ScrollTimeline, f as SmoothProgress, h as SpringProgress, x as Timeline, w as loadAnimationEngine, g as springLinearStops, _ as springTimingFunction };
508
+ export { y as ElementMorph, C as ManualTimeline, d as NumericAnimation, u as RAFPlayback, S as ScrollTimeline, p as SmoothProgress, h as SpringProgress, x as Timeline, w as loadAnimationEngine, g as springLinearStops, _ as springTimingFunction };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mkbabb/keyframes.js",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "Create keyframe animations for anything in JavaScript; specify your keyframes in standards-complaint CSS.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -29,13 +29,16 @@
29
29
  "dist"
30
30
  ],
31
31
  "scripts": {
32
- "prepare": "vite build --mode production",
32
+ "prepare": "npm run build:lib",
33
33
  "check": "tsc --noEmit",
34
+ "check:lib": "tsc --noEmit -p tsconfig.lib.json",
34
35
  "dev": "vite",
35
36
  "dev:playground": "vite --mode playground",
36
- "build": "vite build --mode production",
37
+ "build": "npm run build:lib",
38
+ "build:lib": "vite build --mode production",
37
39
  "build:watch": "vite build --watch --mode production",
38
40
  "gh-pages": "vite build --mode gh-pages",
41
+ "proof:boundary": "node scripts/proof-boundary.mjs",
39
42
  "test": "vitest",
40
43
  "bench": "vitest bench"
41
44
  },
@@ -58,11 +61,13 @@
58
61
  "@mkbabb/parse-that": "^0.8.2",
59
62
  "@mkbabb/value.js": "^0.10.0"
60
63
  },
64
+ "optionalDependencies": {
65
+ "@mkbabb/glass-ui": "file:../glass-ui"
66
+ },
61
67
  "devDependencies": {
62
68
  "@iconify-json/radix-icons": "^1.2.6",
63
69
  "@iconify/vue": "^4.1.2",
64
70
  "@lucide/vue": "^1.16.0",
65
- "@mkbabb/glass-ui": "file:../glass-ui",
66
71
  "@tailwindcss/postcss": "^4.3.0",
67
72
  "@types/node": "^24.12.4",
68
73
  "@types/three": "^0.166.0",
package/dist/_redirects DELETED
@@ -1 +0,0 @@
1
- /* /index.html 200