@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/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
|
|
@@ -3764,6 +3780,80 @@ export declare interface SpringDurationOptions extends Partial<Pick<SpringProgre
|
|
|
3764
3780
|
/** Per-frame callback for `.play()` mode. */
|
|
3765
3781
|
export declare type SpringFrameCallback = (value: number, velocity: number) => void;
|
|
3766
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
|
+
|
|
3767
3857
|
/**
|
|
3768
3858
|
* Sample a `SpringProgress(target=1, initial=0)` solver and emit a CSS
|
|
3769
3859
|
* `linear()` timing-function string. Suitable for
|
|
@@ -4062,6 +4152,12 @@ export declare interface SpringSettleOptions extends Pick<SpringProgressOptions,
|
|
|
4062
4152
|
|
|
4063
4153
|
declare const springSlideIn: PresetFactory;
|
|
4064
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
|
+
|
|
4065
4161
|
/** Subscriber callback. Receives current position + velocity each emission. */
|
|
4066
4162
|
export declare type SpringSubscriber = (value: number, velocity: number) => void;
|
|
4067
4163
|
|