@mkbabb/keyframes.js 2.1.1 → 2.2.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.
@@ -133,6 +133,27 @@ declare class Animation_2<V extends Vars = any> {
133
133
  }
134
134
  export { Animation_2 as Animation }
135
135
 
136
+ /**
137
+ * The value.js-bearing engine surface, resolved through `loadAnimationEngine()`.
138
+ *
139
+ * Spelled as an explicit interface (rather than `typeof import("./engine")`)
140
+ * because the dts roll-up — API Extractor — cannot resolve a `typeof import()`
141
+ * type node that points at an internal module. The shape stays in lockstep
142
+ * with `./engine`'s runtime exports.
143
+ */
144
+ export declare interface AnimationEngine {
145
+ Animation: typeof Animation_2;
146
+ CSSKeyframesAnimation: typeof CSSKeyframesAnimation;
147
+ AnimationGroup: typeof AnimationGroup;
148
+ getAnimationId: (animation: Animation_2 | string) => string;
149
+ getTimingFunction: (timingFunction: TimingFunction | TimingFunctionNames | string | undefined) => TimingFunction | undefined;
150
+ resolveKeyframes: (input: string | Stylesheet) => ResolvedKeyframes;
151
+ DIRECTIONS: readonly AnimationOptions["direction"][];
152
+ FILL_MODES: readonly AnimationOptions["fillMode"][];
153
+ defaultOptions: AnimationOptions;
154
+ defaultLayerConfig: AnimationLayerConfig;
155
+ }
156
+
136
157
  export declare interface AnimationFrame<V extends Vars> {
137
158
  id: number;
138
159
  start: ValueUnit;
@@ -269,7 +290,7 @@ export declare class AnimationGroup<V extends Vars> {
269
290
  getLayerConfig(nameOrAnim: string | Animation_2<V>): AnimationLayerConfig | undefined;
270
291
  }
271
292
 
272
- declare interface AnimationGroupEntry<V extends Vars> {
293
+ export declare interface AnimationGroupEntry<V extends Vars> {
273
294
  animation: Animation_2<V>;
274
295
  values: Record<string, unknown>;
275
296
  layer: AnimationLayerConfig;
@@ -328,11 +349,7 @@ export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V
328
349
  transform(vars: V): void;
329
350
  }
330
351
 
331
- export declare const defaultLayerConfig: AnimationLayerConfig;
332
-
333
- export declare const defaultOptions: AnimationOptions;
334
-
335
- export declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
352
+ declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
336
353
 
337
354
  /**
338
355
  * Interpolate position and scale between two elements or rects.
@@ -350,6 +367,14 @@ export declare class ElementMorph {
350
367
  constructor(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect, options?: ElementMorphOptions);
351
368
  /** Re-measure source and destination, rebuilding the internal animation. */
352
369
  measure(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect): this;
370
+ /**
371
+ * Resolve a pending string easing *name* through the dynamic engine
372
+ * boundary. No-op for callable / omitted easing. Stateless `.at()` /
373
+ * `.toCSSTransform()` consumers that pass a name can `await .ready()`
374
+ * first to interpolate with the resolved easing; `.play()` awaits it
375
+ * automatically before the first frame.
376
+ */
377
+ ready(): Promise<void>;
353
378
  /** Get raw transform values at the given progress [0, 1]. */
354
379
  at(progress: number): MorphValues;
355
380
  /** Get a CSS transform string at the given progress [0, 1]. */
@@ -368,34 +393,20 @@ export declare class ElementMorph {
368
393
  }
369
394
 
370
395
  export declare interface ElementMorphOptions {
396
+ /**
397
+ * Easing as a callable `TimingFunction`, OR a string easing *name*
398
+ * from value.js's registry (`"ease-out-cubic"`, `"easeOutCubic"`, …).
399
+ * `ElementMorph` composes `NumericAnimation`, so a callable keeps the
400
+ * path value.js-free while a string name resolves LAZILY through the
401
+ * dynamic engine boundary on the first `.play()` (or `await .ready()`).
402
+ */
371
403
  timingFunction?: TimingFunction | TimingFunctionNames;
372
404
  /** Playback duration in milliseconds. Required for `.play()`. */
373
405
  duration?: number;
374
406
  transformOrigin?: string;
375
407
  }
376
408
 
377
- export declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
378
-
379
- export declare const getAnimationId: (animation: Animation_2 | string) => string;
380
-
381
- /**
382
- * Resolve a timing-function input to a callable `TimingFunction`.
383
- *
384
- * Accepts:
385
- * - a `TimingFunction` — returned as-is
386
- * - a named entry in `timingFunctions` (`ease-out-cubic`,
387
- * `easeOutCubic`, `linear`, etc.) — looked up in the registry
388
- * - a CSS `cubic-bezier(x1, y1, x2, y2)` literal string —
389
- * parsed to control points and resolved via `CSSCubicBezier`
390
- * - `undefined` or a name/literal the registry can't find —
391
- * returns `undefined` so callers can fall back to their
392
- * default (usually `easeInOutCubic`)
393
- *
394
- * Higher-arity factory entries (`steps`, `step-start`, `step-end`)
395
- * live in the registry but require construction arguments; they
396
- * return `undefined` here so callers can invoke them explicitly.
397
- */
398
- export declare const getTimingFunction: (timingFunction: TimingFunction | TimingFunctionNames | string | undefined) => TimingFunction | undefined;
409
+ declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
399
410
 
400
411
  export declare type InputAnimationOptions = Partial<{
401
412
  duration: number | string;
@@ -412,6 +423,26 @@ export declare type InputAnimationOptions = Partial<{
412
423
 
413
424
  export { InterpolatedVar }
414
425
 
426
+ /**
427
+ * Load the heavy CSS-keyframe parsing engine — `Animation`,
428
+ * `CSSKeyframesAnimation`, `AnimationGroup`, `getTimingFunction`,
429
+ * `resolveKeyframes`, and the animation-options constants (`DIRECTIONS`,
430
+ * `FILL_MODES`, `defaultOptions`, `defaultLayerConfig`).
431
+ *
432
+ * This is the dynamic boundary: the `import("./engine")` pulls value.js into
433
+ * the consumer's graph only when first awaited, so a light-only consumer
434
+ * (spring / smooth / numeric / morph / timeline) never loads it.
435
+ *
436
+ * ```ts
437
+ * const { CSSKeyframesAnimation } = await loadAnimationEngine();
438
+ * const anim = new CSSKeyframesAnimation(opts).fromString(css);
439
+ * ```
440
+ *
441
+ * The browser caches the dynamic module after the first load, so repeat
442
+ * calls resolve from the module cache without a second fetch.
443
+ */
444
+ export declare const loadAnimationEngine: () => Promise<AnimationEngine>;
445
+
415
446
  export declare class ManualTimeline extends Timeline {
416
447
  private value;
417
448
  constructor(options?: TimelineOptions);
@@ -455,10 +486,23 @@ export declare class NumericAnimation<T extends Record<string, number>> {
455
486
  private result;
456
487
  private _duration;
457
488
  private _respectReducedMotion;
489
+ private _pendingEasingName;
490
+ private _easingReady;
458
491
  private _playback;
459
492
  constructor(keyframes: T[], options?: NumericAnimationOptions);
460
493
  private buildSegments;
461
494
  private buildSegment;
495
+ /**
496
+ * Resolve a pending string easing *name* through the dynamic engine
497
+ * 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.
500
+ *
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.
504
+ */
505
+ ready(): Promise<void>;
462
506
  /**
463
507
  * Map [0, 1] progress to interpolated values. Zero allocation —
464
508
  * returns the same pre-allocated result object on every call.
@@ -485,6 +529,22 @@ export declare class NumericAnimation<T extends Record<string, number>> {
485
529
  }
486
530
 
487
531
  export declare interface NumericAnimationOptions {
532
+ /**
533
+ * Easing as a callable `TimingFunction`, OR a string easing *name*
534
+ * from value.js's registry (`"ease-out-cubic"`, `"easeOutCubic"`,
535
+ * `"linear"`, …).
536
+ *
537
+ * A **callable** is used directly and keeps this engine value.js-free —
538
+ * no dynamic import, nothing pulled into the static graph.
539
+ *
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.
547
+ */
488
548
  timingFunction?: TimingFunction | TimingFunctionNames | undefined;
489
549
  /** Playback duration in milliseconds. Required for `.play()`. */
490
550
  duration?: number | undefined;
@@ -507,6 +567,32 @@ export declare type NumericFrameCallback<T extends Record<string, number>> = (va
507
567
 
508
568
  declare type ParsedVarMap = Record<string, ValueArray>;
509
569
 
570
+ /**
571
+ * Shared rAF playback lifecycle for stateless interpolators
572
+ * (`NumericAnimation`, `ElementMorph`). Owns the rAF handle, start
573
+ * timestamp, and resolve callback so the interpolator classes don't
574
+ * each reimplement the same loop.
575
+ *
576
+ * Not used by the full `Animation` class — that engine has a richer
577
+ * lifecycle (iteration, direction, fill modes, events) that doesn't
578
+ * factor into this primitive.
579
+ */
580
+ export declare class RAFPlayback {
581
+ private _rafId;
582
+ private _startTime;
583
+ private _resolve;
584
+ /**
585
+ * Drive `onTick(progress)` once per frame for `duration` ms.
586
+ * `progress` is clamped to [0, 1]; the loop terminates after the
587
+ * frame at `progress === 1`. The returned promise resolves when
588
+ * the animation completes naturally or is interrupted by `stop()`.
589
+ */
590
+ play(duration: number, onTick: (progress: number) => void): Promise<void>;
591
+ /** Cancel a running playback. The play promise resolves immediately. */
592
+ stop(): void;
593
+ private _cleanup;
594
+ }
595
+
510
596
  /**
511
597
  * Result of normalising a CSS keyframes input down to the shape the
512
598
  * `CSSKeyframesAnimation.fromString` flow expects: a `Map<percent →
@@ -529,14 +615,6 @@ export declare interface ResolvedKeyframes {
529
615
  options: ReturnType<typeof extractAnimationOptions>;
530
616
  }
531
617
 
532
- /**
533
- * Normalise a CSS string (or pre-parsed Stylesheet) into the shape
534
- * `CSSKeyframesAnimation.fromString` consumes. The single entry
535
- * point: replaces the legacy `parseCSSKeyframes` /
536
- * `parseCSSStyleBlock` / `parseCSSAnimationKeyframes` fork.
537
- */
538
- export declare const resolveKeyframes: (input: string | Stylesheet) => ResolvedKeyframes;
539
-
540
618
  declare class ScrollTimeline_2 extends Timeline {
541
619
  private threshold;
542
620
  private getScrollY;
@@ -896,7 +974,21 @@ export declare abstract class Timeline {
896
974
  private easingFn;
897
975
  private currentProgress;
898
976
  private boundaryEpsilon;
977
+ private _easingReady;
899
978
  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
+ /**
986
+ * Resolve a pending string easing *name* through the dynamic engine
987
+ * 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.
990
+ */
991
+ ready(): Promise<void>;
900
992
  /** Subclass returns raw [0,1] progress from its source. */
901
993
  protected abstract sample(): number;
902
994
  /**
@@ -931,6 +1023,19 @@ export declare abstract class Timeline {
931
1023
  }
932
1024
 
933
1025
  export declare interface TimelineOptions {
1026
+ /**
1027
+ * Easing as a callable `TimingFunction`, OR a string easing *name*
1028
+ * from value.js's registry (`"ease-out-cubic"`, `"easeOutCubic"`, …).
1029
+ *
1030
+ * A **callable** is applied directly and keeps `Timeline` value.js-free.
1031
+ *
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
1037
+ * `await timeline.ready()` first.
1038
+ */
934
1039
  easing?: TimingFunction | TimingFunctionNames | undefined;
935
1040
  /** SmoothProgress config. `false` disables smoothing. Default: enabled. */
936
1041
  smoothing?: Partial<SmoothProgressOptions> | false | undefined;