@mkbabb/keyframes.js 1.2.0 → 2.1.1
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 +99 -2
- package/dist/_redirects +1 -0
- package/dist/keyframes.d.ts +615 -108
- package/dist/keyframes.js +1169 -1270
- package/package.json +100 -96
package/dist/keyframes.d.ts
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { bounceInEaseHalf } from '@mkbabb/value.js';
|
|
4
|
-
import { bounceInOutEase } from '@mkbabb/value.js';
|
|
5
|
-
import { bounceOutEase } from '@mkbabb/value.js';
|
|
6
|
-
import { bounceOutEaseHalf } from '@mkbabb/value.js';
|
|
7
|
-
import { CSSCubicBezier } from '@mkbabb/value.js';
|
|
8
|
-
import { easeInBounce } from '@mkbabb/value.js';
|
|
9
|
-
import { easeInCirc } from '@mkbabb/value.js';
|
|
10
|
-
import { easeInCubic } from '@mkbabb/value.js';
|
|
11
|
-
import { easeInExpo } from '@mkbabb/value.js';
|
|
12
|
-
import { easeInOutCirc } from '@mkbabb/value.js';
|
|
13
|
-
import { easeInOutCubic } from '@mkbabb/value.js';
|
|
14
|
-
import { easeInOutExpo } from '@mkbabb/value.js';
|
|
15
|
-
import { easeInOutQuad } from '@mkbabb/value.js';
|
|
16
|
-
import { easeInOutSine } from '@mkbabb/value.js';
|
|
17
|
-
import { easeInQuad } from '@mkbabb/value.js';
|
|
18
|
-
import { easeInSine } from '@mkbabb/value.js';
|
|
19
|
-
import { easeOutCirc } from '@mkbabb/value.js';
|
|
20
|
-
import { easeOutCubic } from '@mkbabb/value.js';
|
|
21
|
-
import { easeOutExpo } from '@mkbabb/value.js';
|
|
22
|
-
import { easeOutQuad } from '@mkbabb/value.js';
|
|
23
|
-
import { easeOutSine } from '@mkbabb/value.js';
|
|
1
|
+
import { ColorSpace } from '@mkbabb/value.js';
|
|
2
|
+
import { extractAnimationOptions } from '@mkbabb/value.js';
|
|
24
3
|
import { HueInterpolationMethod } from '@mkbabb/value.js';
|
|
25
4
|
import { InterpolatedVar } from '@mkbabb/value.js';
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import { smoothStep3 } from '@mkbabb/value.js';
|
|
29
|
-
import { stepEnd } from '@mkbabb/value.js';
|
|
30
|
-
import { steppedEase } from '@mkbabb/value.js';
|
|
31
|
-
import { stepStart } from '@mkbabb/value.js';
|
|
5
|
+
import { PropertyDescriptor as PropertyDescriptor_2 } from '@mkbabb/value.js';
|
|
6
|
+
import { Stylesheet } from '@mkbabb/value.js';
|
|
32
7
|
import { timingFunctions } from '@mkbabb/value.js';
|
|
33
8
|
import { ValueArray } from '@mkbabb/value.js';
|
|
34
9
|
import { ValueUnit } from '@mkbabb/value.js';
|
|
@@ -46,24 +21,53 @@ declare class Animation_2<V extends Vars = any> {
|
|
|
46
21
|
handleId: number | any;
|
|
47
22
|
startTime: number | undefined;
|
|
48
23
|
pausedTime: number;
|
|
49
|
-
prevTime: number;
|
|
50
24
|
t: number;
|
|
51
25
|
iteration: number;
|
|
52
26
|
started: boolean;
|
|
53
27
|
done: boolean;
|
|
54
28
|
reversed: boolean;
|
|
55
29
|
paused: boolean;
|
|
56
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* True when an `AnimationGroup` is driving this animation's
|
|
32
|
+
* `tick()` and `interpFrames()` from its own rAF loop. Set by
|
|
33
|
+
* the group at construction; standalone `.play()` / `.draw()`
|
|
34
|
+
* throw when this is true rather than racing the group.
|
|
35
|
+
*/
|
|
57
36
|
managed: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* If the most recent `play()` was rejected by WAAPI eligibility
|
|
39
|
+
* but `useWAAPI: true` was requested, this records the reason.
|
|
40
|
+
* Queryable by debug builds — no console output is produced.
|
|
41
|
+
*/
|
|
42
|
+
waapiIneligibleReason: string | undefined;
|
|
58
43
|
unflatten: boolean;
|
|
59
44
|
private resolvePromise;
|
|
60
45
|
private _playingPromise;
|
|
46
|
+
/**
|
|
47
|
+
* Pre-bound draw callback — allocated once to avoid creating a new
|
|
48
|
+
* closure on every requestAnimationFrame reschedule.
|
|
49
|
+
*/
|
|
50
|
+
private _boundDraw;
|
|
61
51
|
private dispatchAnimationEvent;
|
|
62
52
|
constructor(options?: Partial<InputAnimationOptions>, targets?: HTMLElement[] | HTMLElement | undefined, name?: string | undefined, superKey?: string | undefined);
|
|
63
53
|
convertFrameStart(frame: TemplateAnimationFrame<V>): TemplateAnimationFrame<V>;
|
|
64
54
|
addFrame<K extends V>(start: number | string | ValueUnit<number>, vars: Partial<K>, transform?: TransformFunction<K>, timingFunction?: TimingFunction | TimingFunctionNames): Animation_2<K>;
|
|
65
55
|
createFrame(startIx: number, endIx: number): AnimationFrame<V>;
|
|
66
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Build an index mapping each variable name to the frame indices where
|
|
58
|
+
* it appears. Used by reconcileVars() for O(1) "next occurrence" lookups
|
|
59
|
+
* instead of O(N) findIndex scans per variable.
|
|
60
|
+
*/
|
|
61
|
+
private buildVarIndex;
|
|
62
|
+
/**
|
|
63
|
+
* Reconcile interpolation variables across non-adjacent keyframes.
|
|
64
|
+
* For each variable at frame `ix`, find the next frame that also
|
|
65
|
+
* defines that variable and create an interpolation segment between them.
|
|
66
|
+
*
|
|
67
|
+
* Uses a pre-built variable index (from buildVarIndex) to avoid
|
|
68
|
+
* O(frames²) findIndex scans.
|
|
69
|
+
*/
|
|
70
|
+
reconcileVars(ix: number, varIndex: Map<string, number[]>): void;
|
|
67
71
|
parse(): this;
|
|
68
72
|
setTimingFunction(timingFunction: InputAnimationOptions["timingFunction"]): this;
|
|
69
73
|
setIterationCount(iterationCount: InputAnimationOptions["iterationCount"]): this;
|
|
@@ -83,14 +87,38 @@ declare class Animation_2<V extends Vars = any> {
|
|
|
83
87
|
* regardless of playback direction. `apply=true` invokes transform callbacks.
|
|
84
88
|
*/
|
|
85
89
|
at(progress: number, apply?: boolean): Record<string, ValueUnit[]>;
|
|
86
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Interpolate all active frames at time `t`. This is the hot path —
|
|
92
|
+
* called once per rAF frame during playback.
|
|
93
|
+
*
|
|
94
|
+
* Uses binary search (O(log N)) to find the first matching frame,
|
|
95
|
+
* then scans neighbors to collect all overlapping frames at `t`
|
|
96
|
+
* (multiple properties may share the same time range).
|
|
97
|
+
*
|
|
98
|
+
* @param t - Current animation time in milliseconds
|
|
99
|
+
* @param transformFrames - If true, applies each frame's transform function to targets
|
|
100
|
+
* @param out - Optional output object to write results into. When
|
|
101
|
+
* provided, its keys are cleared first so no stale keys from a
|
|
102
|
+
* previous call leak through. Pass this per-animation to achieve
|
|
103
|
+
* zero-allocation steady-state playback.
|
|
104
|
+
* @returns Merged flat vars from all active frames
|
|
105
|
+
*/
|
|
106
|
+
interpFrames(t: number, transformFrames?: boolean, out?: Record<string, ValueUnit[]>): Record<string, ValueUnit<any, string>[]>;
|
|
87
107
|
onStart(): Promise<void>;
|
|
88
108
|
onEnd(): Promise<void>;
|
|
89
109
|
tick(t: number): Promise<number>;
|
|
90
110
|
draw(t: number): Promise<void>;
|
|
91
111
|
/** Internal rAF-based play loop. */
|
|
92
112
|
private _playRAF;
|
|
93
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Play via the Web Animations API. WAAPI handles visuals on the
|
|
115
|
+
* compositor thread; a shadow rAF loop in `playWAAPI` drives
|
|
116
|
+
* `tick()` so events, iteration count, pause/resume, and other
|
|
117
|
+
* lifecycle state stay coherent with the rAF path.
|
|
118
|
+
*
|
|
119
|
+
* No silent fallback — eligibility is decided once in `play()`
|
|
120
|
+
* before this is invoked, and runtime errors propagate.
|
|
121
|
+
*/
|
|
94
122
|
private _playWAAPI;
|
|
95
123
|
play(): Promise<void>;
|
|
96
124
|
pause(draw?: boolean): this;
|
|
@@ -105,7 +133,7 @@ declare class Animation_2<V extends Vars = any> {
|
|
|
105
133
|
}
|
|
106
134
|
export { Animation_2 as Animation }
|
|
107
135
|
|
|
108
|
-
declare interface AnimationFrame<V extends Vars> {
|
|
136
|
+
export declare interface AnimationFrame<V extends Vars> {
|
|
109
137
|
id: number;
|
|
110
138
|
start: ValueUnit;
|
|
111
139
|
ixs: {
|
|
@@ -121,6 +149,12 @@ declare interface AnimationFrame<V extends Vars> {
|
|
|
121
149
|
interpVars: {
|
|
122
150
|
[arg: string]: Array<InterpolatedVar<V>>;
|
|
123
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* Pre-flattened array of all interpolation variables across all properties.
|
|
154
|
+
* Built once during parse() to avoid Object.values().flat() allocation
|
|
155
|
+
* on every interpFrames() call in the hot path.
|
|
156
|
+
*/
|
|
157
|
+
allInterpVars: Array<InterpolatedVar<V>>;
|
|
124
158
|
transform: TransformFunction<V>;
|
|
125
159
|
timingFunction: TimingFunction;
|
|
126
160
|
}
|
|
@@ -136,22 +170,98 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
136
170
|
lastTickTime: number;
|
|
137
171
|
handleId: number | any;
|
|
138
172
|
resolvePromise: ((value: void | PromiseLike<void>) => void) | null;
|
|
173
|
+
/**
|
|
174
|
+
* Pre-bound draw callback — allocated once in constructor to avoid
|
|
175
|
+
* creating a new closure on every requestAnimationFrame reschedule.
|
|
176
|
+
*/
|
|
177
|
+
private _boundDraw;
|
|
178
|
+
/**
|
|
179
|
+
* Cached entries array, sorted by layer zIndex. Rebuilt on demand
|
|
180
|
+
* via dirty flag to avoid Object.values() allocation on every frame.
|
|
181
|
+
*/
|
|
182
|
+
private _entries;
|
|
183
|
+
private _entriesDirty;
|
|
139
184
|
constructor(...inputs: (Animation_2<V> | AnimationGroupInput<V>)[]);
|
|
185
|
+
/**
|
|
186
|
+
* Returns the animation entries sorted by layer zIndex.
|
|
187
|
+
* Uses dirty-flag caching — only rebuilds when the animations object
|
|
188
|
+
* or layer configs are mutated. All hot-path iteration (tick, draw,
|
|
189
|
+
* transformFramesGrouped) uses this instead of Object.values().
|
|
190
|
+
*/
|
|
191
|
+
private getEntries;
|
|
192
|
+
/** Mark entries cache stale. Called at all mutation boundaries. */
|
|
193
|
+
private invalidateEntries;
|
|
140
194
|
setSuperKey(superKey: string): this;
|
|
141
195
|
setTargets(...targets: HTMLElement[]): this;
|
|
142
196
|
onStart(): this;
|
|
143
197
|
onEnd(): this;
|
|
198
|
+
/**
|
|
199
|
+
* Composite all animation values into a single grouped transform.
|
|
200
|
+
* Called per-frame for single-target groups. Applies layer blending
|
|
201
|
+
* (replace / add / weighted) in zIndex order, then calls the group
|
|
202
|
+
* transform function with the merged values.
|
|
203
|
+
*
|
|
204
|
+
* Refreshes every child's values at its current `t` in place —
|
|
205
|
+
* `interpFrames(t, false, entry.values)` clears and rewrites the
|
|
206
|
+
* long-lived buffer, so no stale keys leak across frames and no
|
|
207
|
+
* fresh object is allocated per entry per frame.
|
|
208
|
+
*/
|
|
144
209
|
transformFramesGrouped(t: number): Record<string, unknown>;
|
|
210
|
+
/**
|
|
211
|
+
* Render the current composition as a static frame using each
|
|
212
|
+
* child's current `t`. Single-target groups go through the
|
|
213
|
+
* blended transform; multi-target groups apply each child's
|
|
214
|
+
* interpolated vars directly to its own targets.
|
|
215
|
+
*
|
|
216
|
+
* This is the public entry point for scenarios that mutate a
|
|
217
|
+
* child's state outside the rAF loop (scrubbing, state restore,
|
|
218
|
+
* pause snapshots) and need the visual to update immediately.
|
|
219
|
+
*/
|
|
220
|
+
render(): void;
|
|
221
|
+
/**
|
|
222
|
+
* Set a child animation's current time without touching its
|
|
223
|
+
* siblings. Updates `pausedTime` so the child resumes correctly
|
|
224
|
+
* from the scrub position. Chainable. Call `render()` afterwards
|
|
225
|
+
* to reflect the change visually.
|
|
226
|
+
*/
|
|
227
|
+
setChildTime(nameOrAnim: string | Animation_2<V>, t: number): this;
|
|
228
|
+
/**
|
|
229
|
+
* Advance all child animations to timestamp `t`.
|
|
230
|
+
* Awaits all child tick() promises so deferred state updates
|
|
231
|
+
* (startTime, this.t) resolve before interpFrames reads them.
|
|
232
|
+
*/
|
|
145
233
|
tick(t: number): Promise<this>;
|
|
234
|
+
/**
|
|
235
|
+
* Main animation frame callback. Ticks all children, then renders
|
|
236
|
+
* (single-target: grouped blending; multi-target: per-child).
|
|
237
|
+
* Reschedules itself via rAF until done.
|
|
238
|
+
*/
|
|
146
239
|
draw(t: number): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Start the animation group. Returns a promise that resolves
|
|
242
|
+
* when all child animations complete (or on explicit stop/reset).
|
|
243
|
+
*/
|
|
147
244
|
play(): Promise<unknown>;
|
|
245
|
+
/**
|
|
246
|
+
* Toggle pause state. Calling pause() when playing pauses; calling
|
|
247
|
+
* pause() when paused resumes. (Toggle semantics preserved for
|
|
248
|
+
* backward compatibility with demo's toggleAnimationGroup.)
|
|
249
|
+
*
|
|
250
|
+
* On pause: explicitly cancels the rAF loop and renders a final
|
|
251
|
+
* frame snapshot so the visual matches the exact pause moment.
|
|
252
|
+
* On resume: re-registers the rAF loop.
|
|
253
|
+
*/
|
|
148
254
|
pause(): this;
|
|
149
255
|
reset(): this;
|
|
150
256
|
stop(): this;
|
|
151
257
|
playing(): boolean;
|
|
152
258
|
forcePause(): void;
|
|
153
259
|
forcePlay(): void;
|
|
154
|
-
/**
|
|
260
|
+
/**
|
|
261
|
+
* Set layer config for an animation by name or reference.
|
|
262
|
+
* Chainable. Throws when the key doesn't match a registered
|
|
263
|
+
* animation — silent no-ops were hiding consumer bugs.
|
|
264
|
+
*/
|
|
155
265
|
setLayerConfig(nameOrAnim: string | Animation_2<V>, config: Partial<AnimationLayerConfig>): this;
|
|
156
266
|
/** Convenience toggle for enabling/disabling a layer. Chainable. */
|
|
157
267
|
setLayerEnabled(nameOrAnim: string | Animation_2<V>, enabled: boolean): this;
|
|
@@ -175,7 +285,7 @@ declare interface AnimationGroupObject<V extends Vars> {
|
|
|
175
285
|
[key: string]: AnimationGroupEntry<V>;
|
|
176
286
|
}
|
|
177
287
|
|
|
178
|
-
declare interface AnimationLayerConfig {
|
|
288
|
+
export declare interface AnimationLayerConfig {
|
|
179
289
|
/** Higher wins. Default: 0 */
|
|
180
290
|
zIndex: number;
|
|
181
291
|
/** 0–1 for 'weighted' blend mode. Default: 1 */
|
|
@@ -188,7 +298,7 @@ declare interface AnimationLayerConfig {
|
|
|
188
298
|
properties?: Set<string>;
|
|
189
299
|
}
|
|
190
300
|
|
|
191
|
-
declare type AnimationOptions = {
|
|
301
|
+
export declare type AnimationOptions = {
|
|
192
302
|
duration: number;
|
|
193
303
|
delay: number;
|
|
194
304
|
iterationCount: number;
|
|
@@ -196,72 +306,47 @@ declare type AnimationOptions = {
|
|
|
196
306
|
fillMode: (typeof FILL_MODES)[number];
|
|
197
307
|
timingFunction: TimingFunction;
|
|
198
308
|
useWAAPI: boolean;
|
|
199
|
-
colorSpace:
|
|
309
|
+
colorSpace: ColorSpace;
|
|
200
310
|
hueMethod?: HueInterpolationMethod;
|
|
201
311
|
};
|
|
202
312
|
|
|
203
|
-
export
|
|
204
|
-
|
|
205
|
-
declare type BlendMode = "replace" | "add" | "weighted";
|
|
206
|
-
|
|
207
|
-
export { bounceInEase }
|
|
208
|
-
|
|
209
|
-
export { bounceInEaseHalf }
|
|
210
|
-
|
|
211
|
-
export { bounceInOutEase }
|
|
212
|
-
|
|
213
|
-
export { bounceOutEase }
|
|
214
|
-
|
|
215
|
-
export { bounceOutEaseHalf }
|
|
216
|
-
|
|
217
|
-
export { CSSCubicBezier }
|
|
313
|
+
export declare type BlendMode = "replace" | "add" | "weighted";
|
|
218
314
|
|
|
219
315
|
export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V> {
|
|
220
316
|
constructor(options?: Partial<InputAnimationOptions>, ...targets: HTMLElement[]);
|
|
221
317
|
fromVars(vars: V[], transform?: TransformFunction<V>): this;
|
|
222
318
|
fromKeyframes(keyframes: Map<string, Partial<V>> | Record<string, Partial<V>>, transform?: TransformFunction<V>): this;
|
|
319
|
+
/**
|
|
320
|
+
* Property registry from `@property` declarations parsed by
|
|
321
|
+
* `fromString`. Empty when the input had no `@property` rules.
|
|
322
|
+
* Consumers can read this to recover the type metadata for
|
|
323
|
+
* custom properties (syntax string, initial value, inheritance
|
|
324
|
+
* flag) without re-parsing the source CSS.
|
|
325
|
+
*/
|
|
326
|
+
propertyRegistry: Map<string, PropertyDescriptor_2>;
|
|
223
327
|
fromString(keyframes: string, transform?: TransformFunction<V>): this;
|
|
224
328
|
transform(vars: V): void;
|
|
225
329
|
}
|
|
226
330
|
|
|
227
|
-
declare const
|
|
228
|
-
|
|
229
|
-
export { easeInBounce }
|
|
230
|
-
|
|
231
|
-
export { easeInCirc }
|
|
232
|
-
|
|
233
|
-
export { easeInCubic }
|
|
234
|
-
|
|
235
|
-
export { easeInExpo }
|
|
236
|
-
|
|
237
|
-
export { easeInOutCirc }
|
|
238
|
-
|
|
239
|
-
export { easeInOutCubic }
|
|
240
|
-
|
|
241
|
-
export { easeInOutExpo }
|
|
331
|
+
export declare const defaultLayerConfig: AnimationLayerConfig;
|
|
242
332
|
|
|
243
|
-
export
|
|
333
|
+
export declare const defaultOptions: AnimationOptions;
|
|
244
334
|
|
|
245
|
-
export
|
|
246
|
-
|
|
247
|
-
export { easeInQuad }
|
|
248
|
-
|
|
249
|
-
export { easeInSine }
|
|
250
|
-
|
|
251
|
-
export { easeOutCirc }
|
|
252
|
-
|
|
253
|
-
export { easeOutCubic }
|
|
254
|
-
|
|
255
|
-
export { easeOutExpo }
|
|
256
|
-
|
|
257
|
-
export { easeOutQuad }
|
|
258
|
-
|
|
259
|
-
export { easeOutSine }
|
|
335
|
+
export declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
|
|
260
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Interpolate position and scale between two elements or rects.
|
|
339
|
+
*
|
|
340
|
+
* Two usage modes:
|
|
341
|
+
* - **Stateless**: call `.at(progress)` or `.toCSSTransform(progress)`
|
|
342
|
+
* - **Managed**: call `.play(element)` to animate an element from source
|
|
343
|
+
* to destination over the configured duration
|
|
344
|
+
*/
|
|
261
345
|
export declare class ElementMorph {
|
|
262
346
|
private animation;
|
|
263
347
|
private transformOrigin;
|
|
264
348
|
private timingFunction;
|
|
349
|
+
private duration;
|
|
265
350
|
constructor(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect, options?: ElementMorphOptions);
|
|
266
351
|
/** Re-measure source and destination, rebuilding the internal animation. */
|
|
267
352
|
measure(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect): this;
|
|
@@ -271,18 +356,48 @@ export declare class ElementMorph {
|
|
|
271
356
|
toCSSTransform(progress: number): string;
|
|
272
357
|
/** Apply the morph transform to an element at the given progress [0, 1]. */
|
|
273
358
|
apply(element: HTMLElement, progress: number): void;
|
|
359
|
+
/**
|
|
360
|
+
* Animate an element from source to destination over the configured duration.
|
|
361
|
+
*
|
|
362
|
+
* @param element — the element to apply transforms to
|
|
363
|
+
* @param duration — override the duration set in constructor options (ms)
|
|
364
|
+
*/
|
|
365
|
+
play(element: HTMLElement, duration?: number): Promise<void>;
|
|
366
|
+
/** Cancel a running `.play()` animation. */
|
|
367
|
+
stop(): void;
|
|
274
368
|
}
|
|
275
369
|
|
|
276
370
|
export declare interface ElementMorphOptions {
|
|
277
371
|
timingFunction?: TimingFunction | TimingFunctionNames;
|
|
372
|
+
/** Playback duration in milliseconds. Required for `.play()`. */
|
|
373
|
+
duration?: number;
|
|
278
374
|
transformOrigin?: string;
|
|
279
375
|
}
|
|
280
376
|
|
|
281
|
-
declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
|
|
377
|
+
export declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
|
|
282
378
|
|
|
283
379
|
export declare const getAnimationId: (animation: Animation_2 | string) => string;
|
|
284
380
|
|
|
285
|
-
|
|
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;
|
|
399
|
+
|
|
400
|
+
export declare type InputAnimationOptions = Partial<{
|
|
286
401
|
duration: number | string;
|
|
287
402
|
delay: number | string;
|
|
288
403
|
iterationCount: number | string | "infinite" | undefined;
|
|
@@ -291,13 +406,11 @@ declare type InputAnimationOptions = Partial<{
|
|
|
291
406
|
timingFunction: TimingFunction | TimingFunctionNames | undefined;
|
|
292
407
|
/** When true (default), eligible animations may use the Web Animations API for compositor-thread execution. Set to false to force rAF. */
|
|
293
408
|
useWAAPI: boolean;
|
|
294
|
-
colorSpace?:
|
|
409
|
+
colorSpace?: ColorSpace;
|
|
295
410
|
hueMethod?: HueInterpolationMethod;
|
|
296
411
|
}>;
|
|
297
412
|
|
|
298
|
-
export {
|
|
299
|
-
|
|
300
|
-
export { linear }
|
|
413
|
+
export { InterpolatedVar }
|
|
301
414
|
|
|
302
415
|
export declare class ManualTimeline extends Timeline {
|
|
303
416
|
private value;
|
|
@@ -322,38 +435,118 @@ declare interface MorphValues {
|
|
|
322
435
|
scaleY: number;
|
|
323
436
|
}
|
|
324
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Zero-allocation numeric keyframe interpolator.
|
|
440
|
+
*
|
|
441
|
+
* Interpolates plain `Record<string, number>` keyframes using O(log N)
|
|
442
|
+
* binary-search segment lookup. Designed for canvas/WebGL render loops
|
|
443
|
+
* where CSS value parsing and DOM targets are unnecessary overhead.
|
|
444
|
+
*
|
|
445
|
+
* Two usage modes:
|
|
446
|
+
* - **Stateless**: call `.at(progress)` from your own render loop
|
|
447
|
+
* - **Managed**: call `.play(onFrame?)` to run a rAF-driven playback
|
|
448
|
+
* that resolves when the animation completes
|
|
449
|
+
*/
|
|
325
450
|
export declare class NumericAnimation<T extends Record<string, number>> {
|
|
326
451
|
private keyframes;
|
|
327
452
|
private segments;
|
|
328
453
|
private positions;
|
|
329
454
|
private timingFn;
|
|
330
455
|
private result;
|
|
456
|
+
private _duration;
|
|
457
|
+
private _respectReducedMotion;
|
|
458
|
+
private _playback;
|
|
331
459
|
constructor(keyframes: T[], options?: NumericAnimationOptions);
|
|
332
460
|
private buildSegments;
|
|
333
461
|
private buildSegment;
|
|
334
|
-
/**
|
|
462
|
+
/**
|
|
463
|
+
* Map [0, 1] progress to interpolated values. Zero allocation —
|
|
464
|
+
* returns the same pre-allocated result object on every call.
|
|
465
|
+
*
|
|
466
|
+
* Uses O(log N) binary search over segments. Falls back to the
|
|
467
|
+
* last segment if progress is past the final stop position.
|
|
468
|
+
*/
|
|
335
469
|
at(progress: number): T;
|
|
336
470
|
/** Update a keyframe's values in-place, recomputing adjacent segments. */
|
|
337
471
|
updateKeyframe(index: number, values: Partial<T>): this;
|
|
472
|
+
/**
|
|
473
|
+
* Play the animation over its duration using requestAnimationFrame.
|
|
474
|
+
*
|
|
475
|
+
* Calls `onFrame` each frame with the interpolated values (the same
|
|
476
|
+
* zero-allocation object returned by `.at()`). Returns a Promise that
|
|
477
|
+
* resolves when the animation completes or is stopped.
|
|
478
|
+
*
|
|
479
|
+
* @param onFrame — optional per-frame callback receiving interpolated values
|
|
480
|
+
* @param duration — override the duration set in constructor options (ms)
|
|
481
|
+
*/
|
|
482
|
+
play(onFrame?: NumericFrameCallback<T>, duration?: number): Promise<void>;
|
|
483
|
+
/** Cancel a running `.play()` animation. The play promise resolves immediately. */
|
|
484
|
+
stop(): void;
|
|
338
485
|
}
|
|
339
486
|
|
|
340
487
|
export declare interface NumericAnimationOptions {
|
|
341
488
|
timingFunction?: TimingFunction | TimingFunctionNames | undefined;
|
|
489
|
+
/** Playback duration in milliseconds. Required for `.play()`. */
|
|
490
|
+
duration?: number | undefined;
|
|
342
491
|
/** Explicit positions as percentages [0-100]. Auto-distributes if omitted. */
|
|
343
492
|
positions?: number[] | undefined;
|
|
493
|
+
/**
|
|
494
|
+
* When true, honor `prefers-reduced-motion: reduce` by snapping to the
|
|
495
|
+
* final keyframe values immediately rather than interpolating over
|
|
496
|
+
* `duration`. The play promise resolves on the next microtask. Default
|
|
497
|
+
* false (back-compat — consumers opt in).
|
|
498
|
+
*
|
|
499
|
+
* The check uses `matchMedia` if available; on SSR / Node the option
|
|
500
|
+
* is a no-op (animations proceed normally).
|
|
501
|
+
*/
|
|
502
|
+
respectReducedMotion?: boolean | undefined;
|
|
344
503
|
}
|
|
345
504
|
|
|
505
|
+
/** Callback invoked each frame during `.play()` with the interpolated values. */
|
|
506
|
+
export declare type NumericFrameCallback<T extends Record<string, number>> = (values: T) => void;
|
|
507
|
+
|
|
346
508
|
declare type ParsedVarMap = Record<string, ValueArray>;
|
|
347
509
|
|
|
348
|
-
|
|
510
|
+
/**
|
|
511
|
+
* Result of normalising a CSS keyframes input down to the shape the
|
|
512
|
+
* `CSSKeyframesAnimation.fromString` flow expects: a `Map<percent →
|
|
513
|
+
* vars>` of ready-to-add frames, plus side data (per-keyframe timing
|
|
514
|
+
* functions, the `@property` registry, and any animation-shorthand
|
|
515
|
+
* options that came from a sibling style rule).
|
|
516
|
+
*/
|
|
517
|
+
export declare interface ResolvedKeyframes {
|
|
518
|
+
/** percent-string → flat `{prop: value}` snapshot */
|
|
519
|
+
keyframes: Map<string, Record<string, unknown>>;
|
|
520
|
+
/** per-keyframe `animation-timing-function`, keyed by percent string */
|
|
521
|
+
timingFunctions: Map<string, string>;
|
|
522
|
+
/** `@property --foo { ... }` registry */
|
|
523
|
+
properties: Map<string, PropertyDescriptor_2>;
|
|
524
|
+
/**
|
|
525
|
+
* Animation options recovered from a top-level style rule's
|
|
526
|
+
* `animation` shorthand or longhand declarations (if any). Empty
|
|
527
|
+
* when the input has no matching style rule.
|
|
528
|
+
*/
|
|
529
|
+
options: ReturnType<typeof extractAnimationOptions>;
|
|
530
|
+
}
|
|
531
|
+
|
|
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
|
+
declare class ScrollTimeline_2 extends Timeline {
|
|
349
541
|
private threshold;
|
|
350
542
|
private getScrollY;
|
|
351
543
|
private getViewportHeight;
|
|
352
|
-
constructor(options?:
|
|
544
|
+
constructor(options?: ScrollTimelineOptions_2);
|
|
353
545
|
protected sample(): number;
|
|
354
546
|
}
|
|
547
|
+
export { ScrollTimeline_2 as ScrollTimeline }
|
|
355
548
|
|
|
356
|
-
|
|
549
|
+
declare interface ScrollTimelineOptions_2 extends TimelineOptions {
|
|
357
550
|
/** Viewport fraction for full progress. Default 0.35. */
|
|
358
551
|
threshold?: number | undefined;
|
|
359
552
|
/** Custom scroll position supplier. Default: window.scrollY. */
|
|
@@ -361,12 +554,19 @@ export declare interface ScrollTimelineOptions extends TimelineOptions {
|
|
|
361
554
|
/** Custom viewport height supplier. Default: window.innerHeight. */
|
|
362
555
|
getViewportHeight?: (() => number) | undefined;
|
|
363
556
|
}
|
|
557
|
+
export { ScrollTimelineOptions_2 as ScrollTimelineOptions }
|
|
558
|
+
|
|
559
|
+
/** Per-frame callback for `.play()` mode. Receives the smoothed current value. */
|
|
560
|
+
declare type SmoothFrameCallback = (value: number) => void;
|
|
364
561
|
|
|
365
562
|
export declare class SmoothProgress {
|
|
366
563
|
private options;
|
|
367
564
|
private targetValue;
|
|
368
565
|
private currentValue;
|
|
369
566
|
private isSettled;
|
|
567
|
+
private _rafId;
|
|
568
|
+
private _lastFrameT;
|
|
569
|
+
private _onFrame;
|
|
370
570
|
constructor(options?: Partial<SmoothProgressOptions>);
|
|
371
571
|
get target(): number;
|
|
372
572
|
get current(): number;
|
|
@@ -380,6 +580,26 @@ export declare class SmoothProgress {
|
|
|
380
580
|
snap(): void;
|
|
381
581
|
/** Reset to a specific value (default 0). */
|
|
382
582
|
reset(value?: number): void;
|
|
583
|
+
/**
|
|
584
|
+
* Start a managed rAF loop that calls `tickDt(dt)` each frame until
|
|
585
|
+
* `settled`, invoking `onFrame(current)` per tick. Idempotent — repeat
|
|
586
|
+
* calls re-bind the callback without spawning a second loop. Once
|
|
587
|
+
* settled the loop auto-stops; `setTarget()` while a callback is
|
|
588
|
+
* bound auto-resumes the loop without needing another `.play()`.
|
|
589
|
+
*
|
|
590
|
+
* Symmetric with `NumericAnimation.play(onFrame)`: library owns rAF,
|
|
591
|
+
* consumer provides a per-frame callback. Consumers that already
|
|
592
|
+
* drive their own rAF (e.g. canvas renderers) should continue to
|
|
593
|
+
* call `.tickDt(dt)` directly and never invoke `.play()`.
|
|
594
|
+
*/
|
|
595
|
+
play(onFrame?: SmoothFrameCallback): void;
|
|
596
|
+
/**
|
|
597
|
+
* Cancel the managed rAF loop and detach the per-frame callback.
|
|
598
|
+
* Pairs with `.play()`. Does not touch current/target/settled state.
|
|
599
|
+
*/
|
|
600
|
+
stop(): void;
|
|
601
|
+
private _startLoop;
|
|
602
|
+
private _stopLoop;
|
|
383
603
|
}
|
|
384
604
|
|
|
385
605
|
export declare interface SmoothProgressOptions {
|
|
@@ -387,21 +607,283 @@ export declare interface SmoothProgressOptions {
|
|
|
387
607
|
damping: number;
|
|
388
608
|
/** Snap to target when |target - current| < threshold. Default 0.001 */
|
|
389
609
|
snapThreshold: number;
|
|
610
|
+
/**
|
|
611
|
+
* Minimum change required to update the target. Changes smaller than this
|
|
612
|
+
* are ignored, filtering high-frequency noise (e.g. sub-pixel scroll jitter).
|
|
613
|
+
* Default 0 (disabled — every change is accepted).
|
|
614
|
+
*/
|
|
615
|
+
targetEpsilon: number;
|
|
390
616
|
/** Starting value. Default 0 */
|
|
391
617
|
initial: number;
|
|
392
618
|
/** Clamp current to [0, 1]. Default true */
|
|
393
619
|
clamp: boolean;
|
|
620
|
+
/**
|
|
621
|
+
* When true, honor `prefers-reduced-motion: reduce` by snapping to
|
|
622
|
+
* target immediately rather than damping. `setTarget` short-circuits
|
|
623
|
+
* the smooth-toward path; `play()` invokes `onFrame` once with the
|
|
624
|
+
* target value. Default false (back-compat — consumers opt in).
|
|
625
|
+
*
|
|
626
|
+
* The check uses `matchMedia` if available; on SSR / Node the option
|
|
627
|
+
* is a no-op (animations proceed normally).
|
|
628
|
+
*/
|
|
629
|
+
respectReducedMotion: boolean;
|
|
394
630
|
}
|
|
395
631
|
|
|
396
|
-
|
|
632
|
+
/** Per-frame callback for `.play()` mode. */
|
|
633
|
+
export declare type SpringFrameCallback = (value: number, velocity: number) => void;
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Sample a `SpringProgress(target=1, initial=0)` solver and emit a CSS
|
|
637
|
+
* `linear()` timing-function string. Suitable for
|
|
638
|
+
* `transition-timing-function` / `animation-timing-function` / token
|
|
639
|
+
* generation (the four `--spring-*` glass-ui tokens regenerate from
|
|
640
|
+
* this helper).
|
|
641
|
+
*
|
|
642
|
+
* The emitted curve passes through `(0%, 0)` and `(100%, 1)` exactly.
|
|
643
|
+
* Intermediate stops carry the unitless spring position; values may
|
|
644
|
+
* exceed 1 (overshoot) for ζ < 1, which CSS `linear()` honors natively.
|
|
645
|
+
*
|
|
646
|
+
* @returns e.g. `"linear(0, 0.234 4.17%, ..., 1)"`
|
|
647
|
+
*/
|
|
648
|
+
export declare function springLinearStops(opts: SpringLinearStopsOptions): string;
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Options for sampling a spring response curve into CSS `linear()` stops.
|
|
652
|
+
*/
|
|
653
|
+
export declare interface SpringLinearStopsOptions {
|
|
654
|
+
/** Angular period of oscillation in seconds. */
|
|
655
|
+
response: number;
|
|
656
|
+
/** Damping ratio ζ. */
|
|
657
|
+
dampingFraction: number;
|
|
658
|
+
/**
|
|
659
|
+
* Number of intermediate sample points. Default 24. The emitted
|
|
660
|
+
* string also includes the implicit `0` start and `1` end stops,
|
|
661
|
+
* so the total stop count is `sampleCount + 2`.
|
|
662
|
+
*/
|
|
663
|
+
sampleCount?: number;
|
|
664
|
+
/**
|
|
665
|
+
* Position + velocity envelope below which the spring is treated
|
|
666
|
+
* as settled and sampling stops early (subsequent positions are
|
|
667
|
+
* pinned to 1). Default 1e-3. Increase for shorter `linear()`
|
|
668
|
+
* strings on overdamped springs (which take longer to settle).
|
|
669
|
+
*/
|
|
670
|
+
settleThreshold?: number;
|
|
671
|
+
/**
|
|
672
|
+
* Upper bound on the sampled time span in seconds. Default 4 ×
|
|
673
|
+
* response (covers ~99% of the envelope for ζ ≥ 0.3). Increase
|
|
674
|
+
* if a very-underdamped spring (ζ < 0.3) is being sampled and
|
|
675
|
+
* the tail keeps ringing past the default cap.
|
|
676
|
+
*/
|
|
677
|
+
maxDuration?: number;
|
|
678
|
+
}
|
|
397
679
|
|
|
398
|
-
|
|
680
|
+
/**
|
|
681
|
+
* Live-target spring tracker. Sibling of `SmoothProgress` for animations
|
|
682
|
+
* where the target may change mid-flight (gesture follows, drag, live
|
|
683
|
+
* data) and overshoot / oscillation is desired.
|
|
684
|
+
*
|
|
685
|
+
* The solver integrates the second-order damped harmonic oscillator
|
|
686
|
+
* analytically between target-change events. Mid-frame target changes
|
|
687
|
+
* re-seat the closed-form solution from the current `(x, v)` state, so
|
|
688
|
+
* the trajectory never jumps.
|
|
689
|
+
*
|
|
690
|
+
* Three integration cases (chosen by ζ):
|
|
691
|
+
*
|
|
692
|
+
* - **Underdamped** (ζ < 1): decaying sinusoid. Overshoots; rings.
|
|
693
|
+
* - **Critically damped** (ζ = 1): fastest settle without overshoot.
|
|
694
|
+
* - **Overdamped** (ζ > 1): two exponential modes, monotone settle.
|
|
695
|
+
*
|
|
696
|
+
* API mirrors SwiftUI's `.spring(response:dampingFraction:)`.
|
|
697
|
+
*/
|
|
698
|
+
export declare class SpringProgress {
|
|
699
|
+
private options;
|
|
700
|
+
private targetValue;
|
|
701
|
+
private currentValue;
|
|
702
|
+
private currentVelocity;
|
|
703
|
+
private isSettled;
|
|
704
|
+
/** Time elapsed since the last target re-seat, in seconds. */
|
|
705
|
+
private elapsed;
|
|
706
|
+
/** Cached `(x, v)` at the most recent target re-seat. */
|
|
707
|
+
private originValue;
|
|
708
|
+
private originVelocity;
|
|
709
|
+
private omega;
|
|
710
|
+
private zeta;
|
|
711
|
+
private omegaD;
|
|
712
|
+
private subscribers;
|
|
713
|
+
private disposed;
|
|
714
|
+
private _rafId;
|
|
715
|
+
private _lastFrameT;
|
|
716
|
+
private _onFrame;
|
|
717
|
+
constructor(options?: Partial<SpringProgressOptions>);
|
|
718
|
+
get target(): number;
|
|
719
|
+
get value(): number;
|
|
720
|
+
get velocity(): number;
|
|
721
|
+
get settled(): boolean;
|
|
722
|
+
/**
|
|
723
|
+
* Set the target. The closed-form solution is re-seated from the
|
|
724
|
+
* current `(value, velocity)` so the trajectory is continuous.
|
|
725
|
+
* Idempotent if the target is unchanged.
|
|
726
|
+
*/
|
|
727
|
+
set target(value: number);
|
|
728
|
+
private reseatTarget;
|
|
729
|
+
/**
|
|
730
|
+
* Advance by `dt` seconds. Uses the analytic closed-form solution
|
|
731
|
+
* accumulated from the last target re-seat (so per-frame error is
|
|
732
|
+
* O(machine epsilon), not O(dt²) like Euler).
|
|
733
|
+
*/
|
|
734
|
+
tick(dt: number): number;
|
|
735
|
+
/**
|
|
736
|
+
* Evaluate the solver at elapsed time `t` (seconds) from the most
|
|
737
|
+
* recent target re-seat. Equivalent to `tick(t - elapsed)` but
|
|
738
|
+
* accepts absolute elapsed time — useful when consumers track their
|
|
739
|
+
* own clock.
|
|
740
|
+
*/
|
|
741
|
+
tickToTime(t: number): number;
|
|
742
|
+
/**
|
|
743
|
+
* Analytic step. Updates `currentValue` + `currentVelocity` to
|
|
744
|
+
* `(x(t), v(t))` of the underlying second-order system, with
|
|
745
|
+
* `x(0) = originValue - targetValue`, `v(0) = originVelocity`.
|
|
746
|
+
*
|
|
747
|
+
* Cases:
|
|
748
|
+
* underdamped: x(t) = e^(-ζω t) [A cos(ω_d t) + B sin(ω_d t)]
|
|
749
|
+
* critical: x(t) = e^(-ω t) [A + B t]
|
|
750
|
+
* overdamped: x(t) = A e^(r₁ t) + B e^(r₂ t)
|
|
751
|
+
*/
|
|
752
|
+
private evaluateAt;
|
|
753
|
+
private checkSettled;
|
|
754
|
+
/** Immediately set value = target, zero velocity. */
|
|
755
|
+
snap(): void;
|
|
756
|
+
/** Reset position + velocity to a specified value (default 0). */
|
|
757
|
+
reset(value?: number, velocity?: number): void;
|
|
758
|
+
/**
|
|
759
|
+
* Subscribe to per-tick updates. Returns an unsubscribe handle.
|
|
760
|
+
* Called with `(value, velocity)` on every `tick`/`snap`/`reset`/
|
|
761
|
+
* `target` set.
|
|
762
|
+
*/
|
|
763
|
+
subscribe(fn: SpringSubscriber): () => void;
|
|
764
|
+
private emit;
|
|
765
|
+
/** Tear down the spring. Cancels the rAF loop and clears subscribers. */
|
|
766
|
+
dispose(): void;
|
|
767
|
+
/**
|
|
768
|
+
* Start a managed rAF loop that calls `tick(dt)` each frame until
|
|
769
|
+
* `settled`, invoking `onFrame(value, velocity)` per tick. Idempotent
|
|
770
|
+
* — repeat calls re-bind the callback without spawning a second loop.
|
|
771
|
+
* Once settled the loop auto-stops; setting `target` while a callback
|
|
772
|
+
* is bound auto-resumes the loop without needing another `.play()`.
|
|
773
|
+
*/
|
|
774
|
+
play(onFrame?: SpringFrameCallback): void;
|
|
775
|
+
/** Cancel the managed rAF loop and detach the per-frame callback. */
|
|
776
|
+
stop(): void;
|
|
777
|
+
private _startLoop;
|
|
778
|
+
private _stopLoop;
|
|
779
|
+
}
|
|
399
780
|
|
|
400
|
-
|
|
781
|
+
/**
|
|
782
|
+
* iOS-style spring physics options. The pair `(response, dampingFraction)`
|
|
783
|
+
* is the SwiftUI-canonical surface — designer-tunable, normalized so
|
|
784
|
+
* `dampingFraction = 1` is critically damped (no overshoot), `< 1` rings,
|
|
785
|
+
* `> 1` is overdamped (sluggish). Internally these map onto a standard
|
|
786
|
+
* second-order linear ODE
|
|
787
|
+
*
|
|
788
|
+
* x'' + 2ζω₀ x' + ω₀² x = ω₀² target
|
|
789
|
+
*
|
|
790
|
+
* with `ω₀ = 2π / response` and `ζ = dampingFraction`, unit mass.
|
|
791
|
+
*/
|
|
792
|
+
export declare interface SpringProgressOptions {
|
|
793
|
+
/**
|
|
794
|
+
* Angular period of the oscillation in seconds. Roughly the time the
|
|
795
|
+
* spring takes to swing through one cycle if undamped. Default 0.5.
|
|
796
|
+
* Smaller values → snappier; larger → looser.
|
|
797
|
+
*/
|
|
798
|
+
response: number;
|
|
799
|
+
/**
|
|
800
|
+
* Damping ratio ζ. `1` critically damped (fastest no-overshoot);
|
|
801
|
+
* `< 1` underdamped (rings); `> 1` overdamped (sluggish). Default
|
|
802
|
+
* 0.86 — the iOS "smooth" preset.
|
|
803
|
+
*/
|
|
804
|
+
dampingFraction: number;
|
|
805
|
+
/** Starting position. Default 0. */
|
|
806
|
+
initial: number;
|
|
807
|
+
/** Starting velocity (units/s). Default 0. */
|
|
808
|
+
initialVelocity: number;
|
|
809
|
+
/**
|
|
810
|
+
* Position settle threshold. When |x - target| AND |v| both drop
|
|
811
|
+
* below `settleThreshold` and `velocitySettleThreshold` respectively,
|
|
812
|
+
* the spring snaps to target and stops integrating. Default 1e-3.
|
|
813
|
+
*/
|
|
814
|
+
settleThreshold: number;
|
|
815
|
+
/** Velocity settle threshold (units/s). Default 1e-3. */
|
|
816
|
+
velocitySettleThreshold: number;
|
|
817
|
+
/**
|
|
818
|
+
* When true, honor `prefers-reduced-motion: reduce` by snapping to
|
|
819
|
+
* target immediately rather than springing. SSR-safe (no-op on
|
|
820
|
+
* non-browser environments). Default false.
|
|
821
|
+
*/
|
|
822
|
+
respectReducedMotion: boolean;
|
|
823
|
+
}
|
|
401
824
|
|
|
402
|
-
|
|
825
|
+
/** Subscriber callback. Receives current position + velocity each emission. */
|
|
826
|
+
export declare type SpringSubscriber = (value: number, velocity: number) => void;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Sample a `SpringProgress(target=1, initial=0)` solver and return a
|
|
830
|
+
* pure `TimingFunction` — `(t: number) => number` over t∈[0,1] — that
|
|
831
|
+
* `ElementMorph`, `NumericAnimation`, and `Animation.addFrame` accept
|
|
832
|
+
* directly (anywhere a `TimingFunction` is taken).
|
|
833
|
+
*
|
|
834
|
+
* This is the JS-easing sibling of `springLinearStops`: same solver,
|
|
835
|
+
* same `(response, dampingFraction)` surface, same default
|
|
836
|
+
* `maxDuration = response * 4`. Where `springLinearStops` emits a CSS
|
|
837
|
+
* `linear()` string for stylesheets/tokens, this returns a closure for
|
|
838
|
+
* code paths that drive interpolation directly and cannot consume a
|
|
839
|
+
* `linear()` string.
|
|
840
|
+
*
|
|
841
|
+
* The returned curve satisfies `f(0) = 0` and `f(1) = 1` exactly.
|
|
842
|
+
* Interior values may exceed 1 for ζ < 1 (overshoot) — e.g. the bouncy
|
|
843
|
+
* `response 0.5 / ζ 0.45` preset peaks at ≈ 1.205 mid-curve — which is
|
|
844
|
+
* the whole point: feeding this into `ElementMorph` produces the
|
|
845
|
+
* canonical iOS spring overshoot without hand-rolling stops or a
|
|
846
|
+
* second ODE integrator.
|
|
847
|
+
*
|
|
848
|
+
* @example
|
|
849
|
+
* const spring = springTimingFunction({ response: 0.5, dampingFraction: 0.45 });
|
|
850
|
+
* const morph = new ElementMorph(from, to, { timingFunction: spring });
|
|
851
|
+
*/
|
|
852
|
+
export declare function springTimingFunction(opts: SpringTimingFunctionOptions): TimingFunction;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Options for sampling a spring response curve into a callable
|
|
856
|
+
* `TimingFunction`. Mirrors `SpringLinearStopsOptions` so the same
|
|
857
|
+
* preset (`response`, `dampingFraction`, ...) produces an identical
|
|
858
|
+
* curve whether emitted as a CSS `linear()` string or a JS easing.
|
|
859
|
+
*/
|
|
860
|
+
export declare interface SpringTimingFunctionOptions {
|
|
861
|
+
/** Angular period of oscillation in seconds. */
|
|
862
|
+
response: number;
|
|
863
|
+
/** Damping ratio ζ. `< 1` overshoots/rings; `≥ 1` monotone. */
|
|
864
|
+
dampingFraction: number;
|
|
865
|
+
/**
|
|
866
|
+
* Number of intermediate sample points between t=0 and t=1.
|
|
867
|
+
* Default 64 — higher than `springLinearStops` (24) because the
|
|
868
|
+
* lerp between samples is the only smoothing a JS easing gets,
|
|
869
|
+
* whereas CSS `linear()` is consumed at sub-pixel cadence.
|
|
870
|
+
*/
|
|
871
|
+
sampleCount?: number;
|
|
872
|
+
/**
|
|
873
|
+
* Position + velocity envelope below which the spring is treated
|
|
874
|
+
* as settled (subsequent positions pin to 1). Default 1e-3.
|
|
875
|
+
*/
|
|
876
|
+
settleThreshold?: number;
|
|
877
|
+
/**
|
|
878
|
+
* Upper bound on the sampled time span in seconds — the spring
|
|
879
|
+
* time that normalized `t = 1` maps to. Default 4 × response
|
|
880
|
+
* (covers ~99% of the envelope for ζ ≥ 0.3). Increase for very
|
|
881
|
+
* underdamped springs (ζ < 0.3) whose tail rings past the cap.
|
|
882
|
+
*/
|
|
883
|
+
maxDuration?: number;
|
|
884
|
+
}
|
|
403
885
|
|
|
404
|
-
declare interface TemplateAnimationFrame<V extends Vars> {
|
|
886
|
+
export declare interface TemplateAnimationFrame<V extends Vars> {
|
|
405
887
|
id: number;
|
|
406
888
|
start: ValueUnit;
|
|
407
889
|
vars: V;
|
|
@@ -413,12 +895,31 @@ export declare abstract class Timeline {
|
|
|
413
895
|
private smoother;
|
|
414
896
|
private easingFn;
|
|
415
897
|
private currentProgress;
|
|
898
|
+
private boundaryEpsilon;
|
|
416
899
|
constructor(options?: TimelineOptions);
|
|
417
900
|
/** Subclass returns raw [0,1] progress from its source. */
|
|
418
901
|
protected abstract sample(): number;
|
|
419
|
-
/**
|
|
902
|
+
/**
|
|
903
|
+
* Shared progress pipeline: sample → clamp → easing → boundary snap.
|
|
904
|
+
* Returns the processed raw value. Does NOT advance the smoother —
|
|
905
|
+
* the caller (tick or tickDt) drives the smoother with the appropriate
|
|
906
|
+
* time-step method.
|
|
907
|
+
*/
|
|
908
|
+
private applyPipeline;
|
|
909
|
+
/**
|
|
910
|
+
* Finalize progress after the smoother has been advanced (or bypassed).
|
|
911
|
+
* Snaps the smoother at boundaries [0, 1] for instant convergence.
|
|
912
|
+
*/
|
|
913
|
+
private finalizeProgress;
|
|
914
|
+
/**
|
|
915
|
+
* Shared advance step. When `dt` is undefined, drives the
|
|
916
|
+
* smoother in frame-rate-dependent mode (`tick()`); when given,
|
|
917
|
+
* uses the frame-rate-independent variant (`tickDt(dt)`).
|
|
918
|
+
*/
|
|
919
|
+
private _advance;
|
|
920
|
+
/** Advance one frame. Applies easing → boundary snap → smoothing. */
|
|
420
921
|
tick(): number;
|
|
421
|
-
/** Frame-rate independent variant. dt in
|
|
922
|
+
/** Frame-rate independent variant. `dt` in milliseconds. */
|
|
422
923
|
tickDt(dt: number): number;
|
|
423
924
|
get progress(): number;
|
|
424
925
|
/** True if no smoother or smoother is settled. */
|
|
@@ -433,17 +934,23 @@ export declare interface TimelineOptions {
|
|
|
433
934
|
easing?: TimingFunction | TimingFunctionNames | undefined;
|
|
434
935
|
/** SmoothProgress config. `false` disables smoothing. Default: enabled. */
|
|
435
936
|
smoothing?: Partial<SmoothProgressOptions> | false | undefined;
|
|
937
|
+
/**
|
|
938
|
+
* Boundary snap zone. When the eased progress is within this distance of
|
|
939
|
+
* 0 or 1, the smoother snaps instantly instead of lerping. Prevents
|
|
940
|
+
* oscillation at scroll endpoints where micro-jitter alternates between
|
|
941
|
+
* boundary and non-boundary values each frame.
|
|
942
|
+
* Default 0.005.
|
|
943
|
+
*/
|
|
944
|
+
boundaryEpsilon?: number | undefined;
|
|
436
945
|
}
|
|
437
946
|
|
|
438
|
-
declare type TimingFunction = (t: number) => number;
|
|
439
|
-
|
|
440
|
-
declare type TimingFunctionNames = keyof typeof timingFunctions;
|
|
947
|
+
export declare type TimingFunction = (t: number) => number;
|
|
441
948
|
|
|
442
|
-
export
|
|
949
|
+
export declare type TimingFunctionNames = keyof typeof timingFunctions;
|
|
443
950
|
|
|
444
|
-
declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
|
|
951
|
+
export declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
|
|
445
952
|
|
|
446
|
-
declare type Vars<T = any> = {
|
|
953
|
+
export declare type Vars<T = any> = {
|
|
447
954
|
[arg: string]: number | string | T;
|
|
448
955
|
};
|
|
449
956
|
|