@mkbabb/keyframes.js 6.4.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 +108 -4
- package/dist/engine/index.d.ts +12 -5
- package/dist/engine/index.js +133 -131
- package/dist/keyframes.d.ts +161 -16
- package/dist/keyframes.js +251 -154
- package/dist/{registry-8bG0FhGi.js → registry-BZOrCZZh.js} +1 -1
- package/dist/{registry-Bs7A0T_s.js → registry-D3fj1upb.js} +1 -1
- package/dist/{sequence-CPGHHEVM.js → sequence-BzJ-b_HG.js} +291 -149
- package/package.json +6 -4
package/dist/keyframes.d.ts
CHANGED
|
@@ -251,6 +251,11 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
251
251
|
* still runs its shadow transport loop so events and completion retain the
|
|
252
252
|
* rAF contract, but it does not overwrite native compositor output. */
|
|
253
253
|
_waapiDelegated: boolean;
|
|
254
|
+
/** True from a reduced-motion snap until the next rewind. The snap paints
|
|
255
|
+
* every child's FINAL frame and then settles (each child's `started` and
|
|
256
|
+
* `t` back to 0), so nothing else records that the pixels left the initial
|
|
257
|
+
* frame; `reset()` reads this to rewind them. INTERNAL (`./lifecycle`). */
|
|
258
|
+
_snappedToFinal: boolean;
|
|
254
259
|
resolvePromise: ((value: void | PromiseLike<void>) => void) | null;
|
|
255
260
|
/** The ONE held play promise the `finished` front-door exposes. INTERNAL
|
|
256
261
|
* (S.B5) — read/written by the transport free functions in `./lifecycle`. */
|
|
@@ -1130,6 +1135,7 @@ export declare class Draggable {
|
|
|
1130
1135
|
private readonly axis;
|
|
1131
1136
|
private readonly transform;
|
|
1132
1137
|
private readonly velocityWindow;
|
|
1138
|
+
private readonly passThrough;
|
|
1133
1139
|
/** Hard `[min, max]` value-domain constraint, or `undefined` (free). */
|
|
1134
1140
|
private readonly bounds;
|
|
1135
1141
|
/** Rubber-band resistance over `bounds` (only consulted when bounds set). */
|
|
@@ -1142,6 +1148,7 @@ export declare class Draggable {
|
|
|
1142
1148
|
private samples;
|
|
1143
1149
|
private subscribers;
|
|
1144
1150
|
private springUnsub;
|
|
1151
|
+
private heldEmissions;
|
|
1145
1152
|
private readonly onPointerDown;
|
|
1146
1153
|
private readonly onPointerMove;
|
|
1147
1154
|
private readonly onPointerUp;
|
|
@@ -1194,6 +1201,7 @@ export declare class Draggable {
|
|
|
1194
1201
|
*/
|
|
1195
1202
|
private applyBounds;
|
|
1196
1203
|
private handleUp;
|
|
1204
|
+
private seatRelease;
|
|
1197
1205
|
/** The snap target nearest `value` (ties → the first encountered). */
|
|
1198
1206
|
private nearestSnap;
|
|
1199
1207
|
/**
|
|
@@ -1203,7 +1211,7 @@ export declare class Draggable {
|
|
|
1203
1211
|
private endGesture;
|
|
1204
1212
|
private pushSample;
|
|
1205
1213
|
/**
|
|
1206
|
-
* Release velocity = average
|
|
1214
|
+
* Release velocity = average sampled velocity over the sample window,
|
|
1207
1215
|
* in units PER SECOND (the spring's clock). Estimated as `Δvalue / Δt`
|
|
1208
1216
|
* across the oldest and newest retained samples — robust to a single
|
|
1209
1217
|
* jittery last frame, unlike a two-point last-pair difference. Returns
|
|
@@ -1236,12 +1244,20 @@ export declare interface DragOptions {
|
|
|
1236
1244
|
*/
|
|
1237
1245
|
springOptions?: Partial<SpringProgressOptions>;
|
|
1238
1246
|
/**
|
|
1239
|
-
* Velocity-sampling window in milliseconds
|
|
1240
|
-
*
|
|
1241
|
-
*
|
|
1242
|
-
* 100ms.
|
|
1247
|
+
* Velocity-sampling window in milliseconds, per `Draggable`: the release
|
|
1248
|
+
* velocity averages the last `velocityWindow` ms of moves (a short window
|
|
1249
|
+
* tracks flicks, a longer one smooths jitter). Default 100ms.
|
|
1243
1250
|
*/
|
|
1244
1251
|
velocityWindow?: number;
|
|
1252
|
+
/**
|
|
1253
|
+
* Write the pointer's value straight through while the pointer is down:
|
|
1254
|
+
* each move seats the spring at rest on the mapped value (rubber-banded
|
|
1255
|
+
* past {@link bounds}) and emits it once, with no spring chasing it and no
|
|
1256
|
+
* frame loop. At release it starts from that value at that value's speed
|
|
1257
|
+
* ({@link velocityWindow}), snaps, bounds and flings as usual, and emits
|
|
1258
|
+
* once that target is set. Default `false`: the pointer is a live target.
|
|
1259
|
+
*/
|
|
1260
|
+
passThrough?: boolean;
|
|
1245
1261
|
/**
|
|
1246
1262
|
* Hard constraint on the value domain `[min, max]`. The drag cannot pull
|
|
1247
1263
|
* the spring target beyond these limits (a clamp in value domain, BEFORE
|
|
@@ -3489,6 +3505,24 @@ export declare const serializeSelector: (selector: KeyframeSelector) => string;
|
|
|
3489
3505
|
|
|
3490
3506
|
export declare const serializeTimingFunction: (value: NonNullable<CSSAnimationOptions["timingFunction"]>) => CssEasingLiteral;
|
|
3491
3507
|
|
|
3508
|
+
/**
|
|
3509
|
+
* Seconds on the spring's own clock until the normalised step response (from 0
|
|
3510
|
+
* to a target of 1, starting at `initialVelocity` travel/s) enters the rest
|
|
3511
|
+
* envelope `|x − 1| < settleThreshold ∧ |v| < velocitySettleThreshold` and stays
|
|
3512
|
+
* there: the LAST time it is outside. After it, the spring never leaves.
|
|
3513
|
+
*
|
|
3514
|
+
* Pass `velocitySettleThreshold: Infinity` for an envelope on position alone.
|
|
3515
|
+
* Returns `Infinity` when the solver's trajectory never settles: an undamped
|
|
3516
|
+
* spring (ζ = 0) that starts outside the envelope, or one damped so hard
|
|
3517
|
+
* (ζ ≳ 1e8) that the solver's slow root rounds to 0 in floating point and the
|
|
3518
|
+
* spring never moves. An exit is found down to `response / 2^32` s. Pure and
|
|
3519
|
+
* server-safe; reduced motion is not an input.
|
|
3520
|
+
*
|
|
3521
|
+
* @example
|
|
3522
|
+
* settleTime({ response: 0.5, dampingFraction: 0.45 }); // ≈ 1.6 (seconds)
|
|
3523
|
+
*/
|
|
3524
|
+
export declare function settleTime(opts: SpringSettleOptions): number;
|
|
3525
|
+
|
|
3492
3526
|
declare const shake: PresetFactory;
|
|
3493
3527
|
|
|
3494
3528
|
declare const skeletonLoading: PresetFactory;
|
|
@@ -3746,6 +3780,80 @@ export declare interface SpringDurationOptions extends Partial<Pick<SpringProgre
|
|
|
3746
3780
|
/** Per-frame callback for `.play()` mode. */
|
|
3747
3781
|
export declare type SpringFrameCallback = (value: number, velocity: number) => void;
|
|
3748
3782
|
|
|
3783
|
+
/** The keyframes {@link springKeyframes} returns, and the spring behind them. */
|
|
3784
|
+
export declare interface SpringKeyframes {
|
|
3785
|
+
/** Keyframe offsets in `[0, 1]`, strictly increasing: `0` first, `1` last. */
|
|
3786
|
+
readonly offsets: readonly number[];
|
|
3787
|
+
/** The spring's position at each offset: `initial` first, `target` last. */
|
|
3788
|
+
readonly values: readonly number[];
|
|
3789
|
+
/**
|
|
3790
|
+
* Seconds the keyframes span (offset `1`): the spring's settle time. Play
|
|
3791
|
+
* them over `duration * 1000` ms with linear interpolation between frames.
|
|
3792
|
+
*/
|
|
3793
|
+
readonly duration: number;
|
|
3794
|
+
/**
|
|
3795
|
+
* The spring's position and velocity `t` seconds after the start, from the
|
|
3796
|
+
* closed form: `(initial, initialVelocity)` at `t ≤ 0`, at rest
|
|
3797
|
+
* `(target, 0)` from `duration` on. Seed a retarget from it and the body
|
|
3798
|
+
* carries on from where it is, at the speed it has.
|
|
3799
|
+
*/
|
|
3800
|
+
at(t: number): SpringState;
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
/**
|
|
3804
|
+
* Sample a spring from `initial` (moving at `initialVelocity` units/s) to
|
|
3805
|
+
* `target` into keyframes whose straight segments stay within `tolerance` of
|
|
3806
|
+
* the true curve, plus the duration they span and the spring's state at any
|
|
3807
|
+
* time. Feed them to `element.animate()` (linear between frames, the WAAPI
|
|
3808
|
+
* default) and the browser plays the spring, overshoot and all, with no script
|
|
3809
|
+
* per frame and no `linear()` easing.
|
|
3810
|
+
*
|
|
3811
|
+
* Knots sit on the curve, placed adaptively: each segment is the longest that
|
|
3812
|
+
* keeps the chord within `tolerance`, so a near-linear stretch takes few knots
|
|
3813
|
+
* and a bend takes many. The bound holds between samples too: each segment is
|
|
3814
|
+
* checked at 17 points plus a bound on the spring's acceleration between them,
|
|
3815
|
+
* from the closed form's decay envelope.
|
|
3816
|
+
*
|
|
3817
|
+
* The span is the spring's settle time (`settleTime`'s last exit) for its rest
|
|
3818
|
+
* envelope, `settleThreshold` on position (narrowed to `tolerance / 2` when that
|
|
3819
|
+
* is tighter, so the pinned last keyframe is inside the tolerance too) and
|
|
3820
|
+
* `velocitySettleThreshold` on velocity, both absolute, in value units.
|
|
3821
|
+
*
|
|
3822
|
+
* @throws RangeError on a non-finite input, a `response`, `tolerance` or
|
|
3823
|
+
* `settleThreshold` that is not > 0, a negative `dampingFraction`, a spring
|
|
3824
|
+
* that never settles (undamped, or damped past floating-point range), or a
|
|
3825
|
+
* tolerance so tight it would take more than 10 000 keyframes.
|
|
3826
|
+
*
|
|
3827
|
+
* @example
|
|
3828
|
+
* const kf = springKeyframes({
|
|
3829
|
+
* response: 0.4, dampingFraction: 0.8,
|
|
3830
|
+
* initial: 0, initialVelocity: 900, target: 240, tolerance: 0.25,
|
|
3831
|
+
* });
|
|
3832
|
+
* element.animate(
|
|
3833
|
+
* kf.offsets.map((offset, i) => ({ offset, transform: `translateX(${kf.values[i]}px)` })),
|
|
3834
|
+
* { duration: kf.duration * 1000, fill: "forwards" },
|
|
3835
|
+
* );
|
|
3836
|
+
*/
|
|
3837
|
+
export declare function springKeyframes(opts: SpringKeyframesOptions): SpringKeyframes;
|
|
3838
|
+
|
|
3839
|
+
/**
|
|
3840
|
+
* Options for {@link springKeyframes}: the spring config `SpringProgress`
|
|
3841
|
+
* takes (`response`, `dampingFraction`, the start `initial` /
|
|
3842
|
+
* `initialVelocity` and the rest envelope, with the same defaults), plus the
|
|
3843
|
+
* `target` and the `tolerance`. `respectReducedMotion` is not an input: the
|
|
3844
|
+
* sampler is pure, and reduced motion is the caller's to apply.
|
|
3845
|
+
*/
|
|
3846
|
+
export declare interface SpringKeyframesOptions extends Partial<Omit<SpringProgressOptions, "respectReducedMotion">> {
|
|
3847
|
+
/** The value the spring travels to and rests at. */
|
|
3848
|
+
target: number;
|
|
3849
|
+
/**
|
|
3850
|
+
* The most, in value units, the piecewise-linear keyframes may stray from
|
|
3851
|
+
* the true spring curve at any time in the span. Finite and > 0. Looser
|
|
3852
|
+
* means fewer keyframes.
|
|
3853
|
+
*/
|
|
3854
|
+
tolerance: number;
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3749
3857
|
/**
|
|
3750
3858
|
* Sample a `SpringProgress(target=1, initial=0)` solver and emit a CSS
|
|
3751
3859
|
* `linear()` timing-function string. Suitable for
|
|
@@ -3786,9 +3894,20 @@ export declare interface SpringLinearStopsOptions {
|
|
|
3786
3894
|
* Upper bound on the sampled time span in seconds. Default 4 ×
|
|
3787
3895
|
* response (covers ~99% of the envelope for ζ ≥ 0.3). Increase
|
|
3788
3896
|
* if a very-underdamped spring (ζ < 0.3) is being sampled and
|
|
3789
|
-
* the tail keeps ringing past the default cap.
|
|
3897
|
+
* the tail keeps ringing past the default cap. `"settle"` spans
|
|
3898
|
+
* exactly `settleTime(opts)` (call it with the same options to read
|
|
3899
|
+
* the span), so the pinned end stop jumps by at most
|
|
3900
|
+
* `settleThreshold`; it throws a `RangeError` when that is `Infinity`
|
|
3901
|
+
* (ζ = 0, or ζ past floating-point range) or 0.
|
|
3902
|
+
*/
|
|
3903
|
+
maxDuration?: number | "settle";
|
|
3904
|
+
/**
|
|
3905
|
+
* Starting velocity, travel/s on the spring's clock (travel = this
|
|
3906
|
+
* leg's distance, so the curve runs 0 → 1). `> 0` is already moving
|
|
3907
|
+
* toward the target; `< 0` is still heading away. Default 0 (the
|
|
3908
|
+
* unseeded curve).
|
|
3790
3909
|
*/
|
|
3791
|
-
|
|
3910
|
+
initialVelocity?: number;
|
|
3792
3911
|
}
|
|
3793
3912
|
|
|
3794
3913
|
declare const springPop: PresetFactory;
|
|
@@ -3831,8 +3950,8 @@ export declare class SpringProgress {
|
|
|
3831
3950
|
* active query); a numeric policy under an active `prefers-reduced-motion`
|
|
3832
3951
|
* query yields the intensity. `evaluateAt` solves toward a SCALED target
|
|
3833
3952
|
* `origin + s·(target − origin)`, so the spring still starts at the origin
|
|
3834
|
-
* but travels only `s ×` the full distance — the peak overshoot scales
|
|
3835
|
-
*
|
|
3953
|
+
* but travels only `s ×` the full distance — the peak overshoot scales, the
|
|
3954
|
+
* normalised curve is kept (absolute thresholds: it settles sooner). Re-resolved
|
|
3836
3955
|
* per re-seat (not per frame) so a live OS toggle is honored at the next
|
|
3837
3956
|
* target change, and the per-frame `evaluateAt` stays a field read — zero
|
|
3838
3957
|
* extra `matchMedia` cost in the hot path.
|
|
@@ -4011,11 +4130,13 @@ export declare interface SpringProgressOptions {
|
|
|
4011
4130
|
* - `true` — the classic binary snap: under an active query the spring
|
|
4012
4131
|
* jumps to target at zero velocity (amplitude scale `0`). SSR-safe.
|
|
4013
4132
|
* - a `number` ∈ [0, 1] — the AMPLITUDE INTENSITY: under an active query
|
|
4014
|
-
* the spring keeps its trajectory SHAPE (
|
|
4015
|
-
* its displacement-from-rest (`originValue − targetValue`) to
|
|
4016
|
-
* fraction. At `0.3` the peak overshoot is 30 % of the
|
|
4017
|
-
* peak
|
|
4018
|
-
*
|
|
4133
|
+
* the spring keeps its trajectory SHAPE (the normalised curve) but
|
|
4134
|
+
* scales its displacement-from-rest (`originValue − targetValue`) to
|
|
4135
|
+
* this fraction. At `0.3` the peak overshoot is 30 % of the
|
|
4136
|
+
* full-intensity peak (the analytic form makes the scaling exact and
|
|
4137
|
+
* free). The thresholds are absolute, so the shorter travel settles
|
|
4138
|
+
* SOONER: `settleTime` over `s · D` (see `settleTime`). `1` ≈ full
|
|
4139
|
+
* motion, `0` ≡ the snap.
|
|
4019
4140
|
*
|
|
4020
4141
|
* The scale is the CONSUMER's policy (a settings slider, a per-animation
|
|
4021
4142
|
* field) — the OS exposes only a binary signal; kf provides the mechanism.
|
|
@@ -4025,8 +4146,18 @@ export declare interface SpringProgressOptions {
|
|
|
4025
4146
|
|
|
4026
4147
|
declare const springScaleIn: PresetFactory;
|
|
4027
4148
|
|
|
4149
|
+
/** Options for {@link settleTime}: the spring, its starting velocity, its rest envelope. */
|
|
4150
|
+
export declare interface SpringSettleOptions extends Pick<SpringProgressOptions, "response" | "dampingFraction">, Partial<Pick<SpringProgressOptions, "initialVelocity" | "settleThreshold" | "velocitySettleThreshold">> {
|
|
4151
|
+
}
|
|
4152
|
+
|
|
4028
4153
|
declare const springSlideIn: PresetFactory;
|
|
4029
4154
|
|
|
4155
|
+
/** A spring's position and velocity (units/s) at one moment. */
|
|
4156
|
+
export declare interface SpringState {
|
|
4157
|
+
value: number;
|
|
4158
|
+
velocity: number;
|
|
4159
|
+
}
|
|
4160
|
+
|
|
4030
4161
|
/** Subscriber callback. Receives current position + velocity each emission. */
|
|
4031
4162
|
export declare type SpringSubscriber = (value: number, velocity: number) => void;
|
|
4032
4163
|
|
|
@@ -4085,8 +4216,22 @@ export declare interface SpringTimingFunctionOptions {
|
|
|
4085
4216
|
* time that normalized `t = 1` maps to. Default 4 × response
|
|
4086
4217
|
* (covers ~99% of the envelope for ζ ≥ 0.3). Increase for very
|
|
4087
4218
|
* underdamped springs (ζ < 0.3) whose tail rings past the cap.
|
|
4088
|
-
|
|
4089
|
-
|
|
4219
|
+
* `"settle"` spans exactly `settleTime(opts)` (call it with the same
|
|
4220
|
+
* options to read the span), so the pinned `fn(1) = 1` jumps by at most
|
|
4221
|
+
* `settleThreshold`; it throws a `RangeError` when that is `Infinity`
|
|
4222
|
+
* (ζ = 0, or ζ past floating-point range) or 0.
|
|
4223
|
+
*/
|
|
4224
|
+
maxDuration?: number | "settle";
|
|
4225
|
+
/**
|
|
4226
|
+
* Starting velocity, travel/s on the spring's clock (travel = this
|
|
4227
|
+
* leg's distance, so the curve runs 0 → 1). `> 0` is already moving
|
|
4228
|
+
* toward the target; `< 0` is still heading away. Default 0 (the
|
|
4229
|
+
* unseeded curve). Time on the curve is `u = t / maxDuration`, so the
|
|
4230
|
+
* slope at `u = 0` is `initialVelocity × maxDuration`; `.fn` and `.css`
|
|
4231
|
+
* add finer knots inside their first interval so their first segment
|
|
4232
|
+
* leaves at that slope (within 2 %) instead of a whole step's chord.
|
|
4233
|
+
*/
|
|
4234
|
+
initialVelocity?: number;
|
|
4090
4235
|
}
|
|
4091
4236
|
|
|
4092
4237
|
/**
|