@mkbabb/keyframes.js 6.5.0 → 6.6.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/README.md +77 -4
- package/dist/engine/index.d.ts +5 -0
- package/dist/engine/index.js +933 -931
- package/dist/keyframes.d.ts +101 -5
- package/dist/keyframes.js +250 -153
- package/dist/{registry-DIMQ5-f9.js → registry-BZOrCZZh.js} +1 -1
- package/dist/{registry-BgJd9srG.js → registry-D3fj1upb.js} +1 -1
- package/dist/{sequence-BRhiigt1.js → sequence-BzJ-b_HG.js} +126 -114
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -630,7 +630,7 @@ spring.css === springLinearStops({ response: 0.5, dampingFraction: 0.45 }); // =
|
|
|
630
630
|
|
|
631
631
|
Options (both): `response`, `dampingFraction`, `sampleCount` (default 24 stops / 64 samples), `settleThreshold` (default `1e-3`), `maxDuration` (default `4 × response` — raise it for very underdamped springs, ζ < 0.3; or `"settle"` to span exactly `settleTime` of the same options, so the pinned end stop jumps by at most `settleThreshold`; it throws a `RangeError` when that is `Infinity` or 0), `initialVelocity` (default 0; see below).
|
|
632
632
|
|
|
633
|
-
**Seeded curves.** `initialVelocity` starts the curve already moving, in travel/s on the spring's clock (travel is the leg's distance, so the curve still runs 0 → 1; `< 0` is still heading away). A reversed glide picks up the running speed and bends round instead of turning a corner: `.fn` and `.css` add finer knots inside their first interval (down to 1/4096 of it), so the first segment leaves at the seed's speed to within 2 % at the default sample counts. Time on the curve is `u = t / T` (`T` the resolved `maxDuration`), so for a motion moving at `v` units/s that now has `D = to − current` to go and plays over `P` seconds, pass `initialVelocity = (v / D) · (P / T)` (just `v / D` when `P = T`). Prefer `maxDuration: "settle"`, so `T` includes the seed, and read `T` back as `settleTime(options)` with the same options to set the duration. If `D` is about 0, there is no curve to seed: hand the motion to a live `SpringProgress` (`reset(x, v)`, then `target`).
|
|
633
|
+
**Seeded curves.** `initialVelocity` starts the curve already moving, in travel/s on the spring's clock (travel is the leg's distance, so the curve still runs 0 → 1; `< 0` is still heading away). A reversed glide picks up the running speed and bends round instead of turning a corner: `.fn` and `.css` add finer knots inside their first interval (down to 1/4096 of it), so the first segment leaves at the seed's speed to within 2 % at the default sample counts. Time on the curve is `u = t / T` (`T` the resolved `maxDuration`), so for a motion moving at `v` units/s that now has `D = to − current` to go and plays over `P` seconds, pass `initialVelocity = (v / D) · (P / T)` (just `v / D` when `P = T`). Prefer `maxDuration: "settle"`, so `T` includes the seed, and read `T` back as `settleTime(options)` with the same options to set the duration. If `D` is about 0, there is no curve to seed: hand the motion to a live `SpringProgress` (`reset(x, v)`, then `target`), or sample it with [`springKeyframes`](#springkeyframes), which takes absolute positions.
|
|
634
634
|
|
|
635
635
|
```ts run
|
|
636
636
|
const seeded = springTimingFunction({
|
|
@@ -661,6 +661,61 @@ Number.isFinite(settleTime({ response: 0.5, dampingFraction: 0 })); // => false
|
|
|
661
661
|
|
|
662
662
|
Options: `response`, `dampingFraction`, `initialVelocity` (travel/s, default 0), `settleThreshold` / `velocitySettleThreshold` (default `1e-3`, the same envelope as `SpringProgress`; `Infinity` drops the velocity check). Throws `RangeError` on a non-positive or non-finite `response` or `settleThreshold`, a non-positive `velocitySettleThreshold`, a negative or non-finite `dampingFraction`, or a non-finite velocity. It returns `Infinity` when the spring never settles: undamped (ζ = 0), or damped so hard (ζ ≳ 1e8) that the solver's slow root rounds to 0. It finds an exit however brief, down to `response / 2^32` s. The system is linear, so a live spring over distance `D` with absolute thresholds `ε` / `εv` and velocity `v` settles at `settleTime({ …, initialVelocity: v / D, settleThreshold: ε / D, velocitySettleThreshold: εv / D })`. Reduced motion is not an input: under `respectReducedMotion: true` the spring snaps (duration 0); under a numeric intensity `s` it travels only `s · D`, so with absolute thresholds it settles sooner, at the same formula with `s · D` for `D`.
|
|
663
663
|
|
|
664
|
+
### `springKeyframes`
|
|
665
|
+
|
|
666
|
+
A spring as keyframes, for a player that runs them itself: give it the spring (`response`, `dampingFraction`), where it starts (`initial`, moving at `initialVelocity` units/s), its `target` and a `tolerance`, and it returns keyframe `offsets` and `values`, the `duration` they span (the spring's settle time, in seconds), and `at(t)`, the spring's position and velocity at any time. Hand them to `element.animate()` and the browser plays the spring, overshoot and all, with no script per frame and no `linear()` easing to depend on.
|
|
667
|
+
|
|
668
|
+
The keyframes are placed adaptively, not at even steps: each segment is the longest straight line that stays within `tolerance` of the true curve, so a near-linear stretch takes few keyframes and a bend takes many, and a looser tolerance takes fewer. The bound holds between keyframes too, not just at them. The first value is `initial` and the last is exactly `target`. Positions are absolute (px, degrees, a 0–1 progress), so a spring released on its own rest (`initial === target`, `initialVelocity ≠ 0`) samples like any other.
|
|
669
|
+
|
|
670
|
+
```ts run
|
|
671
|
+
const spring = {
|
|
672
|
+
response: 0.4,
|
|
673
|
+
dampingFraction: 0.8,
|
|
674
|
+
tolerance: 0.25, // px
|
|
675
|
+
settleThreshold: 0.1, // px: done once within a tenth of a pixel for good
|
|
676
|
+
velocitySettleThreshold: Infinity, // a position band alone
|
|
677
|
+
};
|
|
678
|
+
const kf = springKeyframes({ ...spring, initial: 0, initialVelocity: 900, target: 240 });
|
|
679
|
+
kf.offsets[0]; // => 0
|
|
680
|
+
kf.offsets[kf.offsets.length - 1]; // => 1
|
|
681
|
+
kf.values[0]; // => 0
|
|
682
|
+
kf.values[kf.values.length - 1]; // => 240
|
|
683
|
+
kf.offsets.length < 40; // => true
|
|
684
|
+
kf.at(0); // => { value: 0, velocity: 900 }
|
|
685
|
+
kf.at(kf.duration); // => { value: 240, velocity: 0 }
|
|
686
|
+
|
|
687
|
+
// Retarget mid-glide: start the next spring from where the body is, at the
|
|
688
|
+
// speed it has, so position and velocity carry across the seam.
|
|
689
|
+
const now = kf.at(0.12);
|
|
690
|
+
const next = springKeyframes({ ...spring, initial: now.value, initialVelocity: now.velocity, target: 80 });
|
|
691
|
+
next.values[0] === now.value; // => true
|
|
692
|
+
next.at(0).velocity === now.velocity; // => true
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
Playing them, and retargeting a running one:
|
|
696
|
+
|
|
697
|
+
```ts
|
|
698
|
+
const play = (kf: SpringKeyframes) =>
|
|
699
|
+
element.animate(
|
|
700
|
+
kf.offsets.map((offset, i) => ({ offset, transform: `translateX(${kf.values[i]}px)` })),
|
|
701
|
+
{ duration: kf.duration * 1000, fill: "forwards" }, // linear between keyframes
|
|
702
|
+
);
|
|
703
|
+
|
|
704
|
+
let kf = springKeyframes({ ...spring, initial: 0, initialVelocity: 900, target: 240 });
|
|
705
|
+
let animation = play(kf);
|
|
706
|
+
|
|
707
|
+
// Later, a new target while it glides. Read the time off the animation: it
|
|
708
|
+
// starts a frame or more after animate() is called, so a clock started at the
|
|
709
|
+
// call runs ahead of what is on screen.
|
|
710
|
+
const here = kf.at((animation.currentTime as number) / 1000);
|
|
711
|
+
kf = springKeyframes({ ...spring, initial: here.value, initialVelocity: here.velocity, target: 80 });
|
|
712
|
+
animation = play(kf);
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
At the seam the element is on a straight chord between keyframes, which can sit up to `tolerance` off `at(t)`, so the handover can step by as much as `tolerance`.
|
|
716
|
+
|
|
717
|
+
Options: everything `SpringProgress` takes, with its defaults (`response` 0.5, `dampingFraction` 0.86, `initial` 0, `initialVelocity` 0, `settleThreshold` / `velocitySettleThreshold` `1e-3`, absolute, in value units; `velocitySettleThreshold: Infinity` is a position band alone, which is usually what a played span wants), except `respectReducedMotion` (the sampler is pure; apply reduced motion as you would for `settleTime`), plus `target` and `tolerance` (required; value units, finite and > 0). The span is the last exit from the rest envelope, as `settleTime` counts it, with the position band narrowed to `tolerance / 2` when that is tighter, so the pinned last keyframe is within the tolerance too. `at(t)` takes seconds since the start: before it, the start; from `duration` on, `(target, 0)`. Throws `RangeError` on a non-finite input, a `response`, `tolerance` or `settleThreshold` that is not > 0, a negative `dampingFraction`, a spring that never settles (undamped, or damped past floating-point range), or a tolerance so tight it would need more than 10 000 keyframes.
|
|
718
|
+
|
|
664
719
|
### `RAFPlayback`
|
|
665
720
|
|
|
666
721
|
THE managed rAF driver — every loop in the engine rides this one generation-guarded core, through three entry shapes: `play(duration, onTick)` (progress loop), `drive(tickable)` (step a `Tickable` — `SpringProgress`, `SmoothProgress` — until it settles), and `loop(cb)` (self-rescheduling async frame loop).
|
|
@@ -758,7 +813,19 @@ unsubscribe();
|
|
|
758
813
|
draggable.detach(); // remove listeners; `.dispose()` tears down spring and all
|
|
759
814
|
```
|
|
760
815
|
|
|
761
|
-
Options: `axis` (`"x"` | `"y"`, default `"x"`), `transform` (map a client px coordinate → your value domain), `spring` (bring your own `SpringProgress`) or `springOptions`, `velocityWindow` (ms, default 100)
|
|
816
|
+
Options: `axis` (`"x"` | `"y"`, default `"x"`), `transform` (map a client px coordinate → your value domain), `spring` (bring your own `SpringProgress`) or `springOptions`, `velocityWindow` (ms, default 100, per `Draggable`), `passThrough` (default `false`; below), `bounds`, `rubberBand`, `snap`. Reads: `.value`, `.velocity`, `.dragging`, `.settled`, and `.spring` (the physics core). `drag(element, options)` is the one-call form of `new Draggable(options)` + `.attach(element)`.
|
|
817
|
+
|
|
818
|
+
**Pass-through.** With `passThrough: true` the pointer's value is written straight through while the pointer is down: each move seats the spring at the pointer's value (rubber-banded past `bounds`) at rest and emits it once, so `.value` is the pointer's with no spring chasing it and no frame loop running. The spring starts only at release, from that value at its release speed (the `velocityWindow` estimate of the value on show, so past `bounds` the rubber-banded speed), then snaps, bounds and flings as it does without the option. The release emission comes once the snap or bounds target is set: read `.value`, `.velocity` and `.spring.target` there to play the rest as keyframes with [`springKeyframes`](#springkeyframes).
|
|
819
|
+
|
|
820
|
+
```ts run
|
|
821
|
+
const held = drag(element, { passThrough: true, velocityWindow: 80 });
|
|
822
|
+
held.subscribe((value, velocity) => {
|
|
823
|
+
if (held.dragging) element.style.transform = `translateX(${value}px)`; // the pointer, exactly
|
|
824
|
+
// else: the release — springKeyframes({ initial: value, initialVelocity: velocity, target: held.spring.target, … })
|
|
825
|
+
});
|
|
826
|
+
held.dragging; // => false
|
|
827
|
+
held.dispose();
|
|
828
|
+
```
|
|
762
829
|
|
|
763
830
|
### `decay` / `decayRest`
|
|
764
831
|
|
|
@@ -896,9 +963,15 @@ npm run bench # vitest bench
|
|
|
896
963
|
npm test -- --run && npm run proof:publish # correctness + packaged public surface
|
|
897
964
|
```
|
|
898
965
|
|
|
899
|
-
###
|
|
966
|
+
### Browser checks (local, before a ship)
|
|
967
|
+
|
|
968
|
+
CI runs types, build, the jsdom suites, lint and the publish boundary; it runs no browser. The browser oracles, the demo roster and the Lighthouse audit run locally before a ship:
|
|
969
|
+
|
|
970
|
+
```sh
|
|
971
|
+
npm run preship # scripts/preship.sh: oracles · build · roster · lighthouse
|
|
972
|
+
```
|
|
900
973
|
|
|
901
|
-
|
|
974
|
+
To run the demo roster inside a Linux container instead (a macOS-pass / Linux-fail render race):
|
|
902
975
|
|
|
903
976
|
```sh
|
|
904
977
|
make ci-linux # node:24-slim container · npm ci → gh-pages → demo:correctness
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -192,6 +192,11 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
192
192
|
* still runs its shadow transport loop so events and completion retain the
|
|
193
193
|
* rAF contract, but it does not overwrite native compositor output. */
|
|
194
194
|
_waapiDelegated: boolean;
|
|
195
|
+
/** True from a reduced-motion snap until the next rewind. The snap paints
|
|
196
|
+
* every child's FINAL frame and then settles (each child's `started` and
|
|
197
|
+
* `t` back to 0), so nothing else records that the pixels left the initial
|
|
198
|
+
* frame; `reset()` reads this to rewind them. INTERNAL (`./lifecycle`). */
|
|
199
|
+
_snappedToFinal: boolean;
|
|
195
200
|
resolvePromise: ((value: void | PromiseLike<void>) => void) | null;
|
|
196
201
|
/** The ONE held play promise the `finished` front-door exposes. INTERNAL
|
|
197
202
|
* (S.B5) — read/written by the transport free functions in `./lifecycle`. */
|