@mkbabb/keyframes.js 1.2.1 → 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/dist/_redirects +1 -0
- package/dist/keyframes.d.ts +436 -146
- package/dist/keyframes.js +1169 -1521
- package/package.json +100 -93
package/dist/keyframes.d.ts
CHANGED
|
@@ -1,46 +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 { cancelAnimationFrame as cancelAnimationFrame_2 } from '@mkbabb/value.js';
|
|
8
|
-
import { clamp } from '@mkbabb/value.js';
|
|
9
|
-
import { CSSCubicBezier } from '@mkbabb/value.js';
|
|
10
|
-
import { cubicBezier } from '@mkbabb/value.js';
|
|
11
|
-
import { cubicBezierToString } from '@mkbabb/value.js';
|
|
12
|
-
import { cubicBezierToSVG } from '@mkbabb/value.js';
|
|
13
|
-
import { deCasteljau } from '@mkbabb/value.js';
|
|
14
|
-
import { easeInBounce } from '@mkbabb/value.js';
|
|
15
|
-
import { easeInCirc } from '@mkbabb/value.js';
|
|
16
|
-
import { easeInCubic } from '@mkbabb/value.js';
|
|
17
|
-
import { easeInExpo } from '@mkbabb/value.js';
|
|
18
|
-
import { easeInOutCirc } from '@mkbabb/value.js';
|
|
19
|
-
import { easeInOutCubic } from '@mkbabb/value.js';
|
|
20
|
-
import { easeInOutExpo } from '@mkbabb/value.js';
|
|
21
|
-
import { easeInOutQuad } from '@mkbabb/value.js';
|
|
22
|
-
import { easeInOutSine } from '@mkbabb/value.js';
|
|
23
|
-
import { easeInQuad } from '@mkbabb/value.js';
|
|
24
|
-
import { easeInSine } from '@mkbabb/value.js';
|
|
25
|
-
import { easeOutCirc } from '@mkbabb/value.js';
|
|
26
|
-
import { easeOutCubic } from '@mkbabb/value.js';
|
|
27
|
-
import { easeOutExpo } from '@mkbabb/value.js';
|
|
28
|
-
import { easeOutQuad } from '@mkbabb/value.js';
|
|
29
|
-
import { easeOutSine } from '@mkbabb/value.js';
|
|
1
|
+
import { ColorSpace } from '@mkbabb/value.js';
|
|
2
|
+
import { extractAnimationOptions } from '@mkbabb/value.js';
|
|
30
3
|
import { HueInterpolationMethod } from '@mkbabb/value.js';
|
|
31
|
-
import { interpBezier } from '@mkbabb/value.js';
|
|
32
4
|
import { InterpolatedVar } from '@mkbabb/value.js';
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import { linear } from '@mkbabb/value.js';
|
|
36
|
-
import { logerp } from '@mkbabb/value.js';
|
|
37
|
-
import { requestAnimationFrame as requestAnimationFrame_2 } from '@mkbabb/value.js';
|
|
38
|
-
import { scale } from '@mkbabb/value.js';
|
|
39
|
-
import { sleep } from '@mkbabb/value.js';
|
|
40
|
-
import { smoothStep3 } from '@mkbabb/value.js';
|
|
41
|
-
import { stepEnd } from '@mkbabb/value.js';
|
|
42
|
-
import { steppedEase } from '@mkbabb/value.js';
|
|
43
|
-
import { stepStart } from '@mkbabb/value.js';
|
|
5
|
+
import { PropertyDescriptor as PropertyDescriptor_2 } from '@mkbabb/value.js';
|
|
6
|
+
import { Stylesheet } from '@mkbabb/value.js';
|
|
44
7
|
import { timingFunctions } from '@mkbabb/value.js';
|
|
45
8
|
import { ValueArray } from '@mkbabb/value.js';
|
|
46
9
|
import { ValueUnit } from '@mkbabb/value.js';
|
|
@@ -58,15 +21,25 @@ declare class Animation_2<V extends Vars = any> {
|
|
|
58
21
|
handleId: number | any;
|
|
59
22
|
startTime: number | undefined;
|
|
60
23
|
pausedTime: number;
|
|
61
|
-
prevTime: number;
|
|
62
24
|
t: number;
|
|
63
25
|
iteration: number;
|
|
64
26
|
started: boolean;
|
|
65
27
|
done: boolean;
|
|
66
28
|
reversed: boolean;
|
|
67
29
|
paused: boolean;
|
|
68
|
-
/**
|
|
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
|
+
*/
|
|
69
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;
|
|
70
43
|
unflatten: boolean;
|
|
71
44
|
private resolvePromise;
|
|
72
45
|
private _playingPromise;
|
|
@@ -124,16 +97,28 @@ declare class Animation_2<V extends Vars = any> {
|
|
|
124
97
|
*
|
|
125
98
|
* @param t - Current animation time in milliseconds
|
|
126
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.
|
|
127
104
|
* @returns Merged flat vars from all active frames
|
|
128
105
|
*/
|
|
129
|
-
interpFrames(t: number, transformFrames?: boolean): Record<string, ValueUnit<any, string
|
|
106
|
+
interpFrames(t: number, transformFrames?: boolean, out?: Record<string, ValueUnit[]>): Record<string, ValueUnit<any, string>[]>;
|
|
130
107
|
onStart(): Promise<void>;
|
|
131
108
|
onEnd(): Promise<void>;
|
|
132
109
|
tick(t: number): Promise<number>;
|
|
133
110
|
draw(t: number): Promise<void>;
|
|
134
111
|
/** Internal rAF-based play loop. */
|
|
135
112
|
private _playRAF;
|
|
136
|
-
/**
|
|
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
|
+
*/
|
|
137
122
|
private _playWAAPI;
|
|
138
123
|
play(): Promise<void>;
|
|
139
124
|
pause(draw?: boolean): this;
|
|
@@ -148,7 +133,7 @@ declare class Animation_2<V extends Vars = any> {
|
|
|
148
133
|
}
|
|
149
134
|
export { Animation_2 as Animation }
|
|
150
135
|
|
|
151
|
-
declare interface AnimationFrame<V extends Vars> {
|
|
136
|
+
export declare interface AnimationFrame<V extends Vars> {
|
|
152
137
|
id: number;
|
|
153
138
|
start: ValueUnit;
|
|
154
139
|
ixs: {
|
|
@@ -215,15 +200,31 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
215
200
|
* Called per-frame for single-target groups. Applies layer blending
|
|
216
201
|
* (replace / add / weighted) in zIndex order, then calls the group
|
|
217
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.
|
|
218
208
|
*/
|
|
219
209
|
transformFramesGrouped(t: number): Record<string, unknown>;
|
|
220
210
|
/**
|
|
221
|
-
* Render the current
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
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.
|
|
225
219
|
*/
|
|
226
|
-
|
|
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;
|
|
227
228
|
/**
|
|
228
229
|
* Advance all child animations to timestamp `t`.
|
|
229
230
|
* Awaits all child tick() promises so deferred state updates
|
|
@@ -256,7 +257,11 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
256
257
|
playing(): boolean;
|
|
257
258
|
forcePause(): void;
|
|
258
259
|
forcePlay(): void;
|
|
259
|
-
/**
|
|
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
|
+
*/
|
|
260
265
|
setLayerConfig(nameOrAnim: string | Animation_2<V>, config: Partial<AnimationLayerConfig>): this;
|
|
261
266
|
/** Convenience toggle for enabling/disabling a layer. Chainable. */
|
|
262
267
|
setLayerEnabled(nameOrAnim: string | Animation_2<V>, enabled: boolean): this;
|
|
@@ -280,7 +285,7 @@ declare interface AnimationGroupObject<V extends Vars> {
|
|
|
280
285
|
[key: string]: AnimationGroupEntry<V>;
|
|
281
286
|
}
|
|
282
287
|
|
|
283
|
-
declare interface AnimationLayerConfig {
|
|
288
|
+
export declare interface AnimationLayerConfig {
|
|
284
289
|
/** Higher wins. Default: 0 */
|
|
285
290
|
zIndex: number;
|
|
286
291
|
/** 0–1 for 'weighted' blend mode. Default: 1 */
|
|
@@ -293,7 +298,7 @@ declare interface AnimationLayerConfig {
|
|
|
293
298
|
properties?: Set<string>;
|
|
294
299
|
}
|
|
295
300
|
|
|
296
|
-
declare type AnimationOptions = {
|
|
301
|
+
export declare type AnimationOptions = {
|
|
297
302
|
duration: number;
|
|
298
303
|
delay: number;
|
|
299
304
|
iterationCount: number;
|
|
@@ -301,79 +306,33 @@ declare type AnimationOptions = {
|
|
|
301
306
|
fillMode: (typeof FILL_MODES)[number];
|
|
302
307
|
timingFunction: TimingFunction;
|
|
303
308
|
useWAAPI: boolean;
|
|
304
|
-
colorSpace:
|
|
309
|
+
colorSpace: ColorSpace;
|
|
305
310
|
hueMethod?: HueInterpolationMethod;
|
|
306
311
|
};
|
|
307
312
|
|
|
308
|
-
export
|
|
309
|
-
|
|
310
|
-
declare type BlendMode = "replace" | "add" | "weighted";
|
|
311
|
-
|
|
312
|
-
export { bounceInEase }
|
|
313
|
-
|
|
314
|
-
export { bounceInEaseHalf }
|
|
315
|
-
|
|
316
|
-
export { bounceInOutEase }
|
|
317
|
-
|
|
318
|
-
export { bounceOutEase }
|
|
319
|
-
|
|
320
|
-
export { bounceOutEaseHalf }
|
|
321
|
-
|
|
322
|
-
export { cancelAnimationFrame_2 as cancelAnimationFrame }
|
|
323
|
-
|
|
324
|
-
export { clamp }
|
|
325
|
-
|
|
326
|
-
export { CSSCubicBezier }
|
|
313
|
+
export declare type BlendMode = "replace" | "add" | "weighted";
|
|
327
314
|
|
|
328
315
|
export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V> {
|
|
329
316
|
constructor(options?: Partial<InputAnimationOptions>, ...targets: HTMLElement[]);
|
|
330
317
|
fromVars(vars: V[], transform?: TransformFunction<V>): this;
|
|
331
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>;
|
|
332
327
|
fromString(keyframes: string, transform?: TransformFunction<V>): this;
|
|
333
328
|
transform(vars: V): void;
|
|
334
329
|
}
|
|
335
330
|
|
|
336
|
-
export
|
|
337
|
-
|
|
338
|
-
export { cubicBezierToString }
|
|
339
|
-
|
|
340
|
-
export { cubicBezierToSVG }
|
|
341
|
-
|
|
342
|
-
export { deCasteljau }
|
|
343
|
-
|
|
344
|
-
declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
|
|
345
|
-
|
|
346
|
-
export { easeInBounce }
|
|
347
|
-
|
|
348
|
-
export { easeInCirc }
|
|
349
|
-
|
|
350
|
-
export { easeInCubic }
|
|
351
|
-
|
|
352
|
-
export { easeInExpo }
|
|
353
|
-
|
|
354
|
-
export { easeInOutCirc }
|
|
355
|
-
|
|
356
|
-
export { easeInOutCubic }
|
|
357
|
-
|
|
358
|
-
export { easeInOutExpo }
|
|
359
|
-
|
|
360
|
-
export { easeInOutQuad }
|
|
361
|
-
|
|
362
|
-
export { easeInOutSine }
|
|
363
|
-
|
|
364
|
-
export { easeInQuad }
|
|
331
|
+
export declare const defaultLayerConfig: AnimationLayerConfig;
|
|
365
332
|
|
|
366
|
-
export
|
|
333
|
+
export declare const defaultOptions: AnimationOptions;
|
|
367
334
|
|
|
368
|
-
export
|
|
369
|
-
|
|
370
|
-
export { easeOutCubic }
|
|
371
|
-
|
|
372
|
-
export { easeOutExpo }
|
|
373
|
-
|
|
374
|
-
export { easeOutQuad }
|
|
375
|
-
|
|
376
|
-
export { easeOutSine }
|
|
335
|
+
export declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
|
|
377
336
|
|
|
378
337
|
/**
|
|
379
338
|
* Interpolate position and scale between two elements or rects.
|
|
@@ -415,11 +374,30 @@ export declare interface ElementMorphOptions {
|
|
|
415
374
|
transformOrigin?: string;
|
|
416
375
|
}
|
|
417
376
|
|
|
418
|
-
declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
|
|
377
|
+
export declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
|
|
419
378
|
|
|
420
379
|
export declare const getAnimationId: (animation: Animation_2 | string) => string;
|
|
421
380
|
|
|
422
|
-
|
|
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<{
|
|
423
401
|
duration: number | string;
|
|
424
402
|
delay: number | string;
|
|
425
403
|
iterationCount: number | string | "infinite" | undefined;
|
|
@@ -428,19 +406,11 @@ declare type InputAnimationOptions = Partial<{
|
|
|
428
406
|
timingFunction: TimingFunction | TimingFunctionNames | undefined;
|
|
429
407
|
/** When true (default), eligible animations may use the Web Animations API for compositor-thread execution. Set to false to force rAF. */
|
|
430
408
|
useWAAPI: boolean;
|
|
431
|
-
colorSpace?:
|
|
409
|
+
colorSpace?: ColorSpace;
|
|
432
410
|
hueMethod?: HueInterpolationMethod;
|
|
433
411
|
}>;
|
|
434
412
|
|
|
435
|
-
export {
|
|
436
|
-
|
|
437
|
-
export { jumpTerms }
|
|
438
|
-
|
|
439
|
-
export { lerp }
|
|
440
|
-
|
|
441
|
-
export { linear }
|
|
442
|
-
|
|
443
|
-
export { logerp }
|
|
413
|
+
export { InterpolatedVar }
|
|
444
414
|
|
|
445
415
|
export declare class ManualTimeline extends Timeline {
|
|
446
416
|
private value;
|
|
@@ -484,9 +454,8 @@ export declare class NumericAnimation<T extends Record<string, number>> {
|
|
|
484
454
|
private timingFn;
|
|
485
455
|
private result;
|
|
486
456
|
private _duration;
|
|
487
|
-
private
|
|
488
|
-
private
|
|
489
|
-
private _startTime;
|
|
457
|
+
private _respectReducedMotion;
|
|
458
|
+
private _playback;
|
|
490
459
|
constructor(keyframes: T[], options?: NumericAnimationOptions);
|
|
491
460
|
private buildSegments;
|
|
492
461
|
private buildSegment;
|
|
@@ -513,7 +482,6 @@ export declare class NumericAnimation<T extends Record<string, number>> {
|
|
|
513
482
|
play(onFrame?: NumericFrameCallback<T>, duration?: number): Promise<void>;
|
|
514
483
|
/** Cancel a running `.play()` animation. The play promise resolves immediately. */
|
|
515
484
|
stop(): void;
|
|
516
|
-
private _cleanup;
|
|
517
485
|
}
|
|
518
486
|
|
|
519
487
|
export declare interface NumericAnimationOptions {
|
|
@@ -522,6 +490,16 @@ export declare interface NumericAnimationOptions {
|
|
|
522
490
|
duration?: number | undefined;
|
|
523
491
|
/** Explicit positions as percentages [0-100]. Auto-distributes if omitted. */
|
|
524
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;
|
|
525
503
|
}
|
|
526
504
|
|
|
527
505
|
/** Callback invoked each frame during `.play()` with the interpolated values. */
|
|
@@ -529,19 +507,46 @@ export declare type NumericFrameCallback<T extends Record<string, number>> = (va
|
|
|
529
507
|
|
|
530
508
|
declare type ParsedVarMap = Record<string, ValueArray>;
|
|
531
509
|
|
|
532
|
-
|
|
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
|
+
}
|
|
533
531
|
|
|
534
|
-
|
|
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;
|
|
535
539
|
|
|
536
|
-
|
|
540
|
+
declare class ScrollTimeline_2 extends Timeline {
|
|
537
541
|
private threshold;
|
|
538
542
|
private getScrollY;
|
|
539
543
|
private getViewportHeight;
|
|
540
|
-
constructor(options?:
|
|
544
|
+
constructor(options?: ScrollTimelineOptions_2);
|
|
541
545
|
protected sample(): number;
|
|
542
546
|
}
|
|
547
|
+
export { ScrollTimeline_2 as ScrollTimeline }
|
|
543
548
|
|
|
544
|
-
|
|
549
|
+
declare interface ScrollTimelineOptions_2 extends TimelineOptions {
|
|
545
550
|
/** Viewport fraction for full progress. Default 0.35. */
|
|
546
551
|
threshold?: number | undefined;
|
|
547
552
|
/** Custom scroll position supplier. Default: window.scrollY. */
|
|
@@ -549,14 +554,19 @@ export declare interface ScrollTimelineOptions extends TimelineOptions {
|
|
|
549
554
|
/** Custom viewport height supplier. Default: window.innerHeight. */
|
|
550
555
|
getViewportHeight?: (() => number) | undefined;
|
|
551
556
|
}
|
|
557
|
+
export { ScrollTimelineOptions_2 as ScrollTimelineOptions }
|
|
552
558
|
|
|
553
|
-
|
|
559
|
+
/** Per-frame callback for `.play()` mode. Receives the smoothed current value. */
|
|
560
|
+
declare type SmoothFrameCallback = (value: number) => void;
|
|
554
561
|
|
|
555
562
|
export declare class SmoothProgress {
|
|
556
563
|
private options;
|
|
557
564
|
private targetValue;
|
|
558
565
|
private currentValue;
|
|
559
566
|
private isSettled;
|
|
567
|
+
private _rafId;
|
|
568
|
+
private _lastFrameT;
|
|
569
|
+
private _onFrame;
|
|
560
570
|
constructor(options?: Partial<SmoothProgressOptions>);
|
|
561
571
|
get target(): number;
|
|
562
572
|
get current(): number;
|
|
@@ -570,6 +580,26 @@ export declare class SmoothProgress {
|
|
|
570
580
|
snap(): void;
|
|
571
581
|
/** Reset to a specific value (default 0). */
|
|
572
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;
|
|
573
603
|
}
|
|
574
604
|
|
|
575
605
|
export declare interface SmoothProgressOptions {
|
|
@@ -587,17 +617,273 @@ export declare interface SmoothProgressOptions {
|
|
|
587
617
|
initial: number;
|
|
588
618
|
/** Clamp current to [0, 1]. Default true */
|
|
589
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;
|
|
590
630
|
}
|
|
591
631
|
|
|
592
|
-
|
|
632
|
+
/** Per-frame callback for `.play()` mode. */
|
|
633
|
+
export declare type SpringFrameCallback = (value: number, velocity: number) => void;
|
|
593
634
|
|
|
594
|
-
|
|
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
|
+
}
|
|
679
|
+
|
|
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
|
+
}
|
|
595
780
|
|
|
596
|
-
|
|
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
|
+
}
|
|
597
824
|
|
|
598
|
-
|
|
825
|
+
/** Subscriber callback. Receives current position + velocity each emission. */
|
|
826
|
+
export declare type SpringSubscriber = (value: number, velocity: number) => void;
|
|
599
827
|
|
|
600
|
-
|
|
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
|
+
}
|
|
885
|
+
|
|
886
|
+
export declare interface TemplateAnimationFrame<V extends Vars> {
|
|
601
887
|
id: number;
|
|
602
888
|
start: ValueUnit;
|
|
603
889
|
vars: V;
|
|
@@ -625,6 +911,12 @@ export declare abstract class Timeline {
|
|
|
625
911
|
* Snaps the smoother at boundaries [0, 1] for instant convergence.
|
|
626
912
|
*/
|
|
627
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;
|
|
628
920
|
/** Advance one frame. Applies easing → boundary snap → smoothing. */
|
|
629
921
|
tick(): number;
|
|
630
922
|
/** Frame-rate independent variant. `dt` in milliseconds. */
|
|
@@ -652,15 +944,13 @@ export declare interface TimelineOptions {
|
|
|
652
944
|
boundaryEpsilon?: number | undefined;
|
|
653
945
|
}
|
|
654
946
|
|
|
655
|
-
declare type TimingFunction = (t: number) => number;
|
|
656
|
-
|
|
657
|
-
declare type TimingFunctionNames = keyof typeof timingFunctions;
|
|
947
|
+
export declare type TimingFunction = (t: number) => number;
|
|
658
948
|
|
|
659
|
-
export
|
|
949
|
+
export declare type TimingFunctionNames = keyof typeof timingFunctions;
|
|
660
950
|
|
|
661
|
-
declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
|
|
951
|
+
export declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
|
|
662
952
|
|
|
663
|
-
declare type Vars<T = any> = {
|
|
953
|
+
export declare type Vars<T = any> = {
|
|
664
954
|
[arg: string]: number | string | T;
|
|
665
955
|
};
|
|
666
956
|
|