@mkbabb/keyframes.js 6.4.0 → 6.5.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 CHANGED
@@ -628,7 +628,38 @@ Math.max(...Array.from({ length: 101 }, (_, i) => spring.fn(i / 100))) > 1; // =
628
628
  spring.css === springLinearStops({ response: 0.5, dampingFraction: 0.45 }); // => true
629
629
  ```
630
630
 
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).
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
+
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`).
634
+
635
+ ```ts run
636
+ const seeded = springTimingFunction({
637
+ response: 0.5,
638
+ dampingFraction: 0.86,
639
+ initialVelocity: -2, // still moving away from the new target
640
+ maxDuration: "settle",
641
+ });
642
+ seeded.fn(0.02) < 0; // => true
643
+ seeded.fn(1); // => 1
644
+ // The span it used, to set the animation's duration (P = T):
645
+ const T = settleTime({ response: 0.5, dampingFraction: 0.86, initialVelocity: -2 });
646
+ T > 0.85 && T < 0.95; // => true
647
+ ```
648
+
649
+ ### `settleTime`
650
+
651
+ The spring's own settle clock: the seconds until the `0 → 1` step response enters the rest envelope `|x − 1| < settleThreshold` and `|v| < velocitySettleThreshold` and stays there (the last exit, so a ringing spring that passes through the envelope early is not counted as settled). It reads the closed form and never steps. Take a duration from the spring itself instead of a hand-tuned clock.
652
+
653
+ ```ts run
654
+ const seconds = settleTime({ response: 0.5, dampingFraction: 0.45 });
655
+ seconds > 1.6 && seconds < 1.62; // => true
656
+ // Position only (a settle band, no velocity check):
657
+ settleTime({ response: 0.5, dampingFraction: 0.45, velocitySettleThreshold: Infinity }) < seconds; // => true
658
+ // An undamped spring never settles (Infinity):
659
+ Number.isFinite(settleTime({ response: 0.5, dampingFraction: 0 })); // => false
660
+ ```
661
+
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`.
632
663
 
633
664
  ### `RAFPlayback`
634
665
 
@@ -2634,11 +2634,13 @@ declare interface SpringProgressOptions {
2634
2634
  * - `true` — the classic binary snap: under an active query the spring
2635
2635
  * jumps to target at zero velocity (amplitude scale `0`). SSR-safe.
2636
2636
  * - a `number` ∈ [0, 1] — the AMPLITUDE INTENSITY: under an active query
2637
- * the spring keeps its trajectory SHAPE (curve + settle time) but scales
2638
- * its displacement-from-rest (`originValue − targetValue`) to this
2639
- * fraction. At `0.3` the peak overshoot is 30 % of the full-intensity
2640
- * peak; the envelope is preserved by construction (the analytic form
2641
- * makes the scaling exact and free). `1` ≈ full motion, `0` ≡ the snap.
2637
+ * the spring keeps its trajectory SHAPE (the normalised curve) but
2638
+ * scales its displacement-from-rest (`originValue − targetValue`) to
2639
+ * this fraction. At `0.3` the peak overshoot is 30 % of the
2640
+ * full-intensity peak (the analytic form makes the scaling exact and
2641
+ * free). The thresholds are absolute, so the shorter travel settles
2642
+ * SOONER: `settleTime` over `s · D` (see `settleTime`). `1` ≈ full
2643
+ * motion, `0` ≡ the snap.
2642
2644
  *
2643
2645
  * The scale is the CONSUMER's policy (a settings slider, a per-animation
2644
2646
  * field) — the OS exposes only a binary signal; kf provides the mechanism.