@mkbabb/keyframes.js 1.1.6 → 1.2.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # keyframes.js ![image](./assets/cube.png)
2
2
 
3
- CSS keyframe animations for anything in JavaScript. Specify your keyframes in standards-compliant CSS; animate any object, DOM element, or data structure.
3
+ CSS keyframe animations for anything in JavaScript. Specify your keyframes in standards-compliant CSS; animate any object, DOM element, or data structure. General-purpose interpolation primitives — smoothing, morphing, scroll-driven timelines — ship alongside.
4
4
 
5
5
  [Try the demo here!](https://keyframes.babb.dev/)
6
6
 
@@ -51,6 +51,12 @@ Plucked directly from the [`demo/simple`](demo/simple/App.vue) Vue file.
51
51
  - [Units](#units)
52
52
  - [AnimationGroup](#animationgroup)
53
53
  - [Presets](#presets)
54
+ - [Web Animations API](#web-animations-api)
55
+ - [Beyond CSS](#beyond-css)
56
+ - [NumericAnimation](#numericanimation)
57
+ - [SmoothProgress](#smoothprogress)
58
+ - [ElementMorph](#elementmorph)
59
+ - [Timeline](#timeline)
54
60
  - [Build & Development](#build--development)
55
61
 
56
62
  ## Installation
@@ -68,6 +74,10 @@ src/
68
74
  ├── animation/ # Animation engine: classes, group, presets, interpolation, WAAPI
69
75
  │ ├── index.ts # Animation, CSSKeyframesAnimation
70
76
  │ ├── group.ts # AnimationGroup — multi-animation compositor
77
+ │ ├── numeric.ts # NumericAnimation — keyframe interpolation over plain objects
78
+ │ ├── smooth.ts # SmoothProgress — exponential smoothing
79
+ │ ├── morph.ts # ElementMorph — position/scale interpolation between elements
80
+ │ ├── timeline.ts # Timeline, ScrollTimeline, ManualTimeline — progress drivers
71
81
  │ ├── animations.ts # 30+ preset animations
72
82
  │ ├── constants.ts # Types & defaults
73
83
  │ ├── utils.ts # Frame calc, value interpolation
@@ -96,7 +106,7 @@ demo/ # Vue 3 demo apps
96
106
  ├── boxes/ # Vanilla JS: matrix3d transforms
97
107
  └── bench/ # Performance benchmarks (rAF vs CSS vs WAAPI)
98
108
 
99
- test/ # Vitest (jsdom) — 11 suites
109
+ test/ # Vitest (jsdom) — 15 suites, 261 tests
100
110
  bench/ # Vitest benchmarks — 3 suites
101
111
  ```
102
112
 
@@ -287,6 +297,93 @@ anim.play();
287
297
 
288
298
  When `useWAAPI` is `true` (default), eligible animations run on the compositor thread via `Element.animate()`. Eligibility requires: DOM targets, uniform timing function across frames, no computed units, no custom transform function, no color interpolation. Falls back to `requestAnimationFrame` silently.
289
299
 
300
+ ## Beyond CSS
301
+
302
+ The library also ships general-purpose interpolation primitives, decoupled from CSS and the DOM. These compose into a pipeline: `timeline → progress → interpolator → values → apply`.
303
+
304
+ ### `NumericAnimation`
305
+
306
+ Keyframe interpolation over plain `{key: number}` objects. Zero-allocation hot path — returns the same object reference each call. Two usage modes: stateless `.at()` queries, or managed `.play()` with rAF-driven playback.
307
+
308
+ ```ts
309
+ // Stateless — drive from your own render loop
310
+ const anim = new NumericAnimation([
311
+ { x: 0, y: 0, opacity: 0 },
312
+ { x: 100, y: 200, opacity: 1 },
313
+ ]);
314
+ anim.at(0.5); // => { x: 50, y: 100, opacity: 0.5 }
315
+
316
+ // Managed — rAF playback with per-frame callback
317
+ const anim = new NumericAnimation(
318
+ [{ angle: 0 }, { angle: Math.PI * 4 }],
319
+ { duration: 2500, timingFunction: easeOutCubic },
320
+ );
321
+ await anim.play(({ angle }) => {
322
+ ctx.clearRect(0, 0, w, h);
323
+ drawDial(angle);
324
+ });
325
+ ```
326
+
327
+ Options: `duration` (ms, required for `.play()`), `timingFunction`, `positions` (explicit keyframe positions as percentages). Call `.stop()` to cancel a running playback — the play promise resolves immediately.
328
+
329
+ ### `SmoothProgress`
330
+
331
+ Exponential smoothing for progress values. Frame-rate independent via `tickDt(dt)`.
332
+
333
+ ```ts
334
+ const smooth = new SmoothProgress({ damping: 0.15 });
335
+ smooth.setTarget(1);
336
+ smooth.tick(); // asymptotically approaches 1
337
+ smooth.snap(); // instantly converge
338
+ ```
339
+
340
+ Options: `damping` (lerp factor, default 0.1), `snapThreshold` (auto-snap distance, default 0.001), `targetEpsilon` (ignore target changes smaller than this — filters scroll jitter, default 0), `initial`, `clamp`.
341
+
342
+ ### `ElementMorph`
343
+
344
+ Interpolates position and scale between two DOM elements (or rects). Produces CSS transforms. Stateless `.apply()` or managed `.play()`.
345
+
346
+ ```ts
347
+ // Stateless
348
+ const morph = new ElementMorph(sourceEl, targetEl);
349
+ morph.apply(element, progress); // writes transform + transformOrigin
350
+
351
+ // Managed playback
352
+ const morph = new ElementMorph(sourceEl, targetEl, {
353
+ duration: 400,
354
+ timingFunction: easeOutCubic,
355
+ });
356
+ await morph.play(element);
357
+ ```
358
+
359
+ Re-measures on demand via `morph.measure(from, to)`. Call `.stop()` to cancel.
360
+
361
+ ### `Timeline`
362
+
363
+ Abstract progress driver. Pipeline: `sample() → clamp → easing → boundary snap → smoothing`.
364
+
365
+ ```ts
366
+ const timeline = new ScrollTimeline({
367
+ threshold: 0.35,
368
+ easing: easeOutCubic,
369
+ boundaryEpsilon: 0.005,
370
+ smoothing: { damping: 0.15, targetEpsilon: 0.002 },
371
+ });
372
+
373
+ function update() {
374
+ const p = timeline.tick();
375
+ requestAnimationFrame(update);
376
+ }
377
+ ```
378
+
379
+ Options: `easing`, `smoothing` (`SmoothProgressOptions` or `false`), `boundaryEpsilon` (snap eased values within this distance of 0/1 to the boundary — prevents scroll-endpoint oscillation, default 0.005).
380
+
381
+ Subclasses:
382
+ - **`ScrollTimeline`** — scroll position → progress. `threshold` sets viewport fraction for full progress (default 0.35). Injectable `getScrollY`/`getViewportHeight`.
383
+ - **`ManualTimeline`** — externally set value → progress. Smoothing off by default.
384
+
385
+ See [`docs/scroll-morph.md`](docs/scroll-morph.md) for an architecture guide on building jitter-free scroll-driven morph animations.
386
+
290
387
  ## Build & Development
291
388
 
292
389
  ```sh
@@ -1,5 +1,46 @@
1
+ import { bezierPresets } from '@mkbabb/value.js';
2
+ import { bounceInEase } from '@mkbabb/value.js';
3
+ import { bounceInEaseHalf } from '@mkbabb/value.js';
4
+ import { bounceInOutEase } from '@mkbabb/value.js';
5
+ import { bounceOutEase } from '@mkbabb/value.js';
6
+ import { bounceOutEaseHalf } from '@mkbabb/value.js';
7
+ import { cancelAnimationFrame as cancelAnimationFrame_2 } from '@mkbabb/value.js';
8
+ import { clamp } from '@mkbabb/value.js';
9
+ import { CSSCubicBezier } from '@mkbabb/value.js';
10
+ import { cubicBezier } from '@mkbabb/value.js';
11
+ import { cubicBezierToString } from '@mkbabb/value.js';
12
+ import { cubicBezierToSVG } from '@mkbabb/value.js';
13
+ import { deCasteljau } from '@mkbabb/value.js';
14
+ import { easeInBounce } from '@mkbabb/value.js';
15
+ import { easeInCirc } from '@mkbabb/value.js';
16
+ import { easeInCubic } from '@mkbabb/value.js';
17
+ import { easeInExpo } from '@mkbabb/value.js';
18
+ import { easeInOutCirc } from '@mkbabb/value.js';
19
+ import { easeInOutCubic } from '@mkbabb/value.js';
20
+ import { easeInOutExpo } from '@mkbabb/value.js';
21
+ import { easeInOutQuad } from '@mkbabb/value.js';
22
+ import { easeInOutSine } from '@mkbabb/value.js';
23
+ import { easeInQuad } from '@mkbabb/value.js';
24
+ import { easeInSine } from '@mkbabb/value.js';
25
+ import { easeOutCirc } from '@mkbabb/value.js';
26
+ import { easeOutCubic } from '@mkbabb/value.js';
27
+ import { easeOutExpo } from '@mkbabb/value.js';
28
+ import { easeOutQuad } from '@mkbabb/value.js';
29
+ import { easeOutSine } from '@mkbabb/value.js';
1
30
  import { HueInterpolationMethod } from '@mkbabb/value.js';
31
+ import { interpBezier } from '@mkbabb/value.js';
2
32
  import { InterpolatedVar } from '@mkbabb/value.js';
33
+ import { jumpTerms } from '@mkbabb/value.js';
34
+ import { lerp } from '@mkbabb/value.js';
35
+ import { linear } from '@mkbabb/value.js';
36
+ import { logerp } from '@mkbabb/value.js';
37
+ import { requestAnimationFrame as requestAnimationFrame_2 } from '@mkbabb/value.js';
38
+ import { scale } from '@mkbabb/value.js';
39
+ import { sleep } from '@mkbabb/value.js';
40
+ import { smoothStep3 } from '@mkbabb/value.js';
41
+ import { stepEnd } from '@mkbabb/value.js';
42
+ import { steppedEase } from '@mkbabb/value.js';
43
+ import { stepStart } from '@mkbabb/value.js';
3
44
  import { timingFunctions } from '@mkbabb/value.js';
4
45
  import { ValueArray } from '@mkbabb/value.js';
5
46
  import { ValueUnit } from '@mkbabb/value.js';
@@ -29,12 +70,31 @@ declare class Animation_2<V extends Vars = any> {
29
70
  unflatten: boolean;
30
71
  private resolvePromise;
31
72
  private _playingPromise;
73
+ /**
74
+ * Pre-bound draw callback — allocated once to avoid creating a new
75
+ * closure on every requestAnimationFrame reschedule.
76
+ */
77
+ private _boundDraw;
32
78
  private dispatchAnimationEvent;
33
79
  constructor(options?: Partial<InputAnimationOptions>, targets?: HTMLElement[] | HTMLElement | undefined, name?: string | undefined, superKey?: string | undefined);
34
80
  convertFrameStart(frame: TemplateAnimationFrame<V>): TemplateAnimationFrame<V>;
35
81
  addFrame<K extends V>(start: number | string | ValueUnit<number>, vars: Partial<K>, transform?: TransformFunction<K>, timingFunction?: TimingFunction | TimingFunctionNames): Animation_2<K>;
36
82
  createFrame(startIx: number, endIx: number): AnimationFrame<V>;
37
- reconcileVars(ix: number): void;
83
+ /**
84
+ * Build an index mapping each variable name to the frame indices where
85
+ * it appears. Used by reconcileVars() for O(1) "next occurrence" lookups
86
+ * instead of O(N) findIndex scans per variable.
87
+ */
88
+ private buildVarIndex;
89
+ /**
90
+ * Reconcile interpolation variables across non-adjacent keyframes.
91
+ * For each variable at frame `ix`, find the next frame that also
92
+ * defines that variable and create an interpolation segment between them.
93
+ *
94
+ * Uses a pre-built variable index (from buildVarIndex) to avoid
95
+ * O(frames²) findIndex scans.
96
+ */
97
+ reconcileVars(ix: number, varIndex: Map<string, number[]>): void;
38
98
  parse(): this;
39
99
  setTimingFunction(timingFunction: InputAnimationOptions["timingFunction"]): this;
40
100
  setIterationCount(iterationCount: InputAnimationOptions["iterationCount"]): this;
@@ -49,6 +109,23 @@ declare class Animation_2<V extends Vars = any> {
49
109
  reverse(): this;
50
110
  fillForwards(): void;
51
111
  fillBackwards(): void;
112
+ /**
113
+ * Stateless progress query. Maps [0,1] from first keyframe to last,
114
+ * regardless of playback direction. `apply=true` invokes transform callbacks.
115
+ */
116
+ at(progress: number, apply?: boolean): Record<string, ValueUnit[]>;
117
+ /**
118
+ * Interpolate all active frames at time `t`. This is the hot path —
119
+ * called once per rAF frame during playback.
120
+ *
121
+ * Uses binary search (O(log N)) to find the first matching frame,
122
+ * then scans neighbors to collect all overlapping frames at `t`
123
+ * (multiple properties may share the same time range).
124
+ *
125
+ * @param t - Current animation time in milliseconds
126
+ * @param transformFrames - If true, applies each frame's transform function to targets
127
+ * @returns Merged flat vars from all active frames
128
+ */
52
129
  interpFrames(t: number, transformFrames?: boolean): Record<string, ValueUnit<any, string | undefined>[]>;
53
130
  onStart(): Promise<void>;
54
131
  onEnd(): Promise<void>;
@@ -87,6 +164,12 @@ declare interface AnimationFrame<V extends Vars> {
87
164
  interpVars: {
88
165
  [arg: string]: Array<InterpolatedVar<V>>;
89
166
  };
167
+ /**
168
+ * Pre-flattened array of all interpolation variables across all properties.
169
+ * Built once during parse() to avoid Object.values().flat() allocation
170
+ * on every interpFrames() call in the hot path.
171
+ */
172
+ allInterpVars: Array<InterpolatedVar<V>>;
90
173
  transform: TransformFunction<V>;
91
174
  timingFunction: TimingFunction;
92
175
  }
@@ -102,15 +185,71 @@ export declare class AnimationGroup<V extends Vars> {
102
185
  lastTickTime: number;
103
186
  handleId: number | any;
104
187
  resolvePromise: ((value: void | PromiseLike<void>) => void) | null;
188
+ /**
189
+ * Pre-bound draw callback — allocated once in constructor to avoid
190
+ * creating a new closure on every requestAnimationFrame reschedule.
191
+ */
192
+ private _boundDraw;
193
+ /**
194
+ * Cached entries array, sorted by layer zIndex. Rebuilt on demand
195
+ * via dirty flag to avoid Object.values() allocation on every frame.
196
+ */
197
+ private _entries;
198
+ private _entriesDirty;
105
199
  constructor(...inputs: (Animation_2<V> | AnimationGroupInput<V>)[]);
200
+ /**
201
+ * Returns the animation entries sorted by layer zIndex.
202
+ * Uses dirty-flag caching — only rebuilds when the animations object
203
+ * or layer configs are mutated. All hot-path iteration (tick, draw,
204
+ * transformFramesGrouped) uses this instead of Object.values().
205
+ */
206
+ private getEntries;
207
+ /** Mark entries cache stale. Called at all mutation boundaries. */
208
+ private invalidateEntries;
106
209
  setSuperKey(superKey: string): this;
107
210
  setTargets(...targets: HTMLElement[]): this;
108
211
  onStart(): this;
109
212
  onEnd(): this;
213
+ /**
214
+ * Composite all animation values into a single grouped transform.
215
+ * Called per-frame for single-target groups. Applies layer blending
216
+ * (replace / add / weighted) in zIndex order, then calls the group
217
+ * transform function with the merged values.
218
+ */
110
219
  transformFramesGrouped(t: number): Record<string, unknown>;
220
+ /**
221
+ * Render the current animation state as a static frame.
222
+ * Called on pause to ensure the visual matches the exact pause moment.
223
+ * Handles both single-target (grouped blending) and multi-target
224
+ * (per-child interpFrames) paths.
225
+ */
226
+ private renderPauseFrame;
227
+ /**
228
+ * Advance all child animations to timestamp `t`.
229
+ * Awaits all child tick() promises so deferred state updates
230
+ * (startTime, this.t) resolve before interpFrames reads them.
231
+ */
111
232
  tick(t: number): Promise<this>;
233
+ /**
234
+ * Main animation frame callback. Ticks all children, then renders
235
+ * (single-target: grouped blending; multi-target: per-child).
236
+ * Reschedules itself via rAF until done.
237
+ */
112
238
  draw(t: number): Promise<void>;
239
+ /**
240
+ * Start the animation group. Returns a promise that resolves
241
+ * when all child animations complete (or on explicit stop/reset).
242
+ */
113
243
  play(): Promise<unknown>;
244
+ /**
245
+ * Toggle pause state. Calling pause() when playing pauses; calling
246
+ * pause() when paused resumes. (Toggle semantics preserved for
247
+ * backward compatibility with demo's toggleAnimationGroup.)
248
+ *
249
+ * On pause: explicitly cancels the rAF loop and renders a final
250
+ * frame snapshot so the visual matches the exact pause moment.
251
+ * On resume: re-registers the rAF loop.
252
+ */
114
253
  pause(): this;
115
254
  reset(): this;
116
255
  stop(): this;
@@ -166,8 +305,26 @@ declare type AnimationOptions = {
166
305
  hueMethod?: HueInterpolationMethod;
167
306
  };
168
307
 
308
+ export { bezierPresets }
309
+
169
310
  declare type BlendMode = "replace" | "add" | "weighted";
170
311
 
312
+ export { bounceInEase }
313
+
314
+ export { bounceInEaseHalf }
315
+
316
+ export { bounceInOutEase }
317
+
318
+ export { bounceOutEase }
319
+
320
+ export { bounceOutEaseHalf }
321
+
322
+ export { cancelAnimationFrame_2 as cancelAnimationFrame }
323
+
324
+ export { clamp }
325
+
326
+ export { CSSCubicBezier }
327
+
171
328
  export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V> {
172
329
  constructor(options?: Partial<InputAnimationOptions>, ...targets: HTMLElement[]);
173
330
  fromVars(vars: V[], transform?: TransformFunction<V>): this;
@@ -176,8 +333,88 @@ export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V
176
333
  transform(vars: V): void;
177
334
  }
178
335
 
336
+ export { cubicBezier }
337
+
338
+ export { cubicBezierToString }
339
+
340
+ export { cubicBezierToSVG }
341
+
342
+ export { deCasteljau }
343
+
179
344
  declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
180
345
 
346
+ export { easeInBounce }
347
+
348
+ export { easeInCirc }
349
+
350
+ export { easeInCubic }
351
+
352
+ export { easeInExpo }
353
+
354
+ export { easeInOutCirc }
355
+
356
+ export { easeInOutCubic }
357
+
358
+ export { easeInOutExpo }
359
+
360
+ export { easeInOutQuad }
361
+
362
+ export { easeInOutSine }
363
+
364
+ export { easeInQuad }
365
+
366
+ export { easeInSine }
367
+
368
+ export { easeOutCirc }
369
+
370
+ export { easeOutCubic }
371
+
372
+ export { easeOutExpo }
373
+
374
+ export { easeOutQuad }
375
+
376
+ export { easeOutSine }
377
+
378
+ /**
379
+ * Interpolate position and scale between two elements or rects.
380
+ *
381
+ * Two usage modes:
382
+ * - **Stateless**: call `.at(progress)` or `.toCSSTransform(progress)`
383
+ * - **Managed**: call `.play(element)` to animate an element from source
384
+ * to destination over the configured duration
385
+ */
386
+ export declare class ElementMorph {
387
+ private animation;
388
+ private transformOrigin;
389
+ private timingFunction;
390
+ private duration;
391
+ constructor(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect, options?: ElementMorphOptions);
392
+ /** Re-measure source and destination, rebuilding the internal animation. */
393
+ measure(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect): this;
394
+ /** Get raw transform values at the given progress [0, 1]. */
395
+ at(progress: number): MorphValues;
396
+ /** Get a CSS transform string at the given progress [0, 1]. */
397
+ toCSSTransform(progress: number): string;
398
+ /** Apply the morph transform to an element at the given progress [0, 1]. */
399
+ apply(element: HTMLElement, progress: number): void;
400
+ /**
401
+ * Animate an element from source to destination over the configured duration.
402
+ *
403
+ * @param element — the element to apply transforms to
404
+ * @param duration — override the duration set in constructor options (ms)
405
+ */
406
+ play(element: HTMLElement, duration?: number): Promise<void>;
407
+ /** Cancel a running `.play()` animation. */
408
+ stop(): void;
409
+ }
410
+
411
+ export declare interface ElementMorphOptions {
412
+ timingFunction?: TimingFunction | TimingFunctionNames;
413
+ /** Playback duration in milliseconds. Required for `.play()`. */
414
+ duration?: number;
415
+ transformOrigin?: string;
416
+ }
417
+
181
418
  declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
182
419
 
183
420
  export declare const getAnimationId: (animation: Animation_2 | string) => string;
@@ -195,8 +432,171 @@ declare type InputAnimationOptions = Partial<{
195
432
  hueMethod?: HueInterpolationMethod;
196
433
  }>;
197
434
 
435
+ export { interpBezier }
436
+
437
+ export { jumpTerms }
438
+
439
+ export { lerp }
440
+
441
+ export { linear }
442
+
443
+ export { logerp }
444
+
445
+ export declare class ManualTimeline extends Timeline {
446
+ private value;
447
+ constructor(options?: TimelineOptions);
448
+ /** Set the raw progress value. */
449
+ set(value: number): void;
450
+ protected sample(): number;
451
+ }
452
+
453
+ export declare interface MorphRect {
454
+ x: number;
455
+ y: number;
456
+ width: number;
457
+ height: number;
458
+ }
459
+
460
+ declare interface MorphValues {
461
+ [key: string]: number;
462
+ translateX: number;
463
+ translateY: number;
464
+ scaleX: number;
465
+ scaleY: number;
466
+ }
467
+
468
+ /**
469
+ * Zero-allocation numeric keyframe interpolator.
470
+ *
471
+ * Interpolates plain `Record<string, number>` keyframes using O(log N)
472
+ * binary-search segment lookup. Designed for canvas/WebGL render loops
473
+ * where CSS value parsing and DOM targets are unnecessary overhead.
474
+ *
475
+ * Two usage modes:
476
+ * - **Stateless**: call `.at(progress)` from your own render loop
477
+ * - **Managed**: call `.play(onFrame?)` to run a rAF-driven playback
478
+ * that resolves when the animation completes
479
+ */
480
+ export declare class NumericAnimation<T extends Record<string, number>> {
481
+ private keyframes;
482
+ private segments;
483
+ private positions;
484
+ private timingFn;
485
+ private result;
486
+ private _duration;
487
+ private _rafId;
488
+ private _resolve;
489
+ private _startTime;
490
+ constructor(keyframes: T[], options?: NumericAnimationOptions);
491
+ private buildSegments;
492
+ private buildSegment;
493
+ /**
494
+ * Map [0, 1] progress to interpolated values. Zero allocation —
495
+ * returns the same pre-allocated result object on every call.
496
+ *
497
+ * Uses O(log N) binary search over segments. Falls back to the
498
+ * last segment if progress is past the final stop position.
499
+ */
500
+ at(progress: number): T;
501
+ /** Update a keyframe's values in-place, recomputing adjacent segments. */
502
+ updateKeyframe(index: number, values: Partial<T>): this;
503
+ /**
504
+ * Play the animation over its duration using requestAnimationFrame.
505
+ *
506
+ * Calls `onFrame` each frame with the interpolated values (the same
507
+ * zero-allocation object returned by `.at()`). Returns a Promise that
508
+ * resolves when the animation completes or is stopped.
509
+ *
510
+ * @param onFrame — optional per-frame callback receiving interpolated values
511
+ * @param duration — override the duration set in constructor options (ms)
512
+ */
513
+ play(onFrame?: NumericFrameCallback<T>, duration?: number): Promise<void>;
514
+ /** Cancel a running `.play()` animation. The play promise resolves immediately. */
515
+ stop(): void;
516
+ private _cleanup;
517
+ }
518
+
519
+ export declare interface NumericAnimationOptions {
520
+ timingFunction?: TimingFunction | TimingFunctionNames | undefined;
521
+ /** Playback duration in milliseconds. Required for `.play()`. */
522
+ duration?: number | undefined;
523
+ /** Explicit positions as percentages [0-100]. Auto-distributes if omitted. */
524
+ positions?: number[] | undefined;
525
+ }
526
+
527
+ /** Callback invoked each frame during `.play()` with the interpolated values. */
528
+ export declare type NumericFrameCallback<T extends Record<string, number>> = (values: T) => void;
529
+
198
530
  declare type ParsedVarMap = Record<string, ValueArray>;
199
531
 
532
+ export { requestAnimationFrame_2 as requestAnimationFrame }
533
+
534
+ export { scale }
535
+
536
+ export declare class ScrollTimeline extends Timeline {
537
+ private threshold;
538
+ private getScrollY;
539
+ private getViewportHeight;
540
+ constructor(options?: ScrollTimelineOptions);
541
+ protected sample(): number;
542
+ }
543
+
544
+ export declare interface ScrollTimelineOptions extends TimelineOptions {
545
+ /** Viewport fraction for full progress. Default 0.35. */
546
+ threshold?: number | undefined;
547
+ /** Custom scroll position supplier. Default: window.scrollY. */
548
+ getScrollY?: (() => number) | undefined;
549
+ /** Custom viewport height supplier. Default: window.innerHeight. */
550
+ getViewportHeight?: (() => number) | undefined;
551
+ }
552
+
553
+ export { sleep }
554
+
555
+ export declare class SmoothProgress {
556
+ private options;
557
+ private targetValue;
558
+ private currentValue;
559
+ private isSettled;
560
+ constructor(options?: Partial<SmoothProgressOptions>);
561
+ get target(): number;
562
+ get current(): number;
563
+ get settled(): boolean;
564
+ setTarget(target: number): void;
565
+ /** Advance one step using fixed damping. Returns current value. */
566
+ tick(): number;
567
+ /** Frame-rate independent tick. dt is in milliseconds. */
568
+ tickDt(dt: number): number;
569
+ /** Immediately set current = target. */
570
+ snap(): void;
571
+ /** Reset to a specific value (default 0). */
572
+ reset(value?: number): void;
573
+ }
574
+
575
+ export declare interface SmoothProgressOptions {
576
+ /** Damping factor (0, 1]. Higher = faster convergence. Default 0.1 */
577
+ damping: number;
578
+ /** Snap to target when |target - current| < threshold. Default 0.001 */
579
+ snapThreshold: number;
580
+ /**
581
+ * Minimum change required to update the target. Changes smaller than this
582
+ * are ignored, filtering high-frequency noise (e.g. sub-pixel scroll jitter).
583
+ * Default 0 (disabled — every change is accepted).
584
+ */
585
+ targetEpsilon: number;
586
+ /** Starting value. Default 0 */
587
+ initial: number;
588
+ /** Clamp current to [0, 1]. Default true */
589
+ clamp: boolean;
590
+ }
591
+
592
+ export { smoothStep3 }
593
+
594
+ export { stepEnd }
595
+
596
+ export { steppedEase }
597
+
598
+ export { stepStart }
599
+
200
600
  declare interface TemplateAnimationFrame<V extends Vars> {
201
601
  id: number;
202
602
  start: ValueUnit;
@@ -205,10 +605,59 @@ declare interface TemplateAnimationFrame<V extends Vars> {
205
605
  timingFunction?: TimingFunction;
206
606
  }
207
607
 
608
+ export declare abstract class Timeline {
609
+ private smoother;
610
+ private easingFn;
611
+ private currentProgress;
612
+ private boundaryEpsilon;
613
+ constructor(options?: TimelineOptions);
614
+ /** Subclass returns raw [0,1] progress from its source. */
615
+ protected abstract sample(): number;
616
+ /**
617
+ * Shared progress pipeline: sample → clamp → easing → boundary snap.
618
+ * Returns the processed raw value. Does NOT advance the smoother —
619
+ * the caller (tick or tickDt) drives the smoother with the appropriate
620
+ * time-step method.
621
+ */
622
+ private applyPipeline;
623
+ /**
624
+ * Finalize progress after the smoother has been advanced (or bypassed).
625
+ * Snaps the smoother at boundaries [0, 1] for instant convergence.
626
+ */
627
+ private finalizeProgress;
628
+ /** Advance one frame. Applies easing → boundary snap → smoothing. */
629
+ tick(): number;
630
+ /** Frame-rate independent variant. `dt` in milliseconds. */
631
+ tickDt(dt: number): number;
632
+ get progress(): number;
633
+ /** True if no smoother or smoother is settled. */
634
+ get settled(): boolean;
635
+ /** Immediately converge smoother to current target. */
636
+ snap(): void;
637
+ /** Reset progress to a specific value (default 0). */
638
+ reset(value?: number): void;
639
+ }
640
+
641
+ export declare interface TimelineOptions {
642
+ easing?: TimingFunction | TimingFunctionNames | undefined;
643
+ /** SmoothProgress config. `false` disables smoothing. Default: enabled. */
644
+ smoothing?: Partial<SmoothProgressOptions> | false | undefined;
645
+ /**
646
+ * Boundary snap zone. When the eased progress is within this distance of
647
+ * 0 or 1, the smoother snaps instantly instead of lerping. Prevents
648
+ * oscillation at scroll endpoints where micro-jitter alternates between
649
+ * boundary and non-boundary values each frame.
650
+ * Default 0.005.
651
+ */
652
+ boundaryEpsilon?: number | undefined;
653
+ }
654
+
208
655
  declare type TimingFunction = (t: number) => number;
209
656
 
210
657
  declare type TimingFunctionNames = keyof typeof timingFunctions;
211
658
 
659
+ export { timingFunctions }
660
+
212
661
  declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
213
662
 
214
663
  declare type Vars<T = any> = {