@mkbabb/keyframes.js 1.2.1 → 2.2.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/LICENSE +1 -1
- package/README.md +10 -1
- package/dist/_redirects +1 -0
- package/dist/engine-DuAFoqZF.js +699 -0
- package/dist/keyframes.d.ts +543 -148
- package/dist/keyframes.js +501 -1530
- package/dist/leaves-Bu89334e.js +39 -0
- package/package.json +101 -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,28 @@ declare class Animation_2<V extends Vars = any> {
|
|
|
148
133
|
}
|
|
149
134
|
export { Animation_2 as Animation }
|
|
150
135
|
|
|
151
|
-
|
|
136
|
+
/**
|
|
137
|
+
* The value.js-bearing engine surface, resolved through `loadAnimationEngine()`.
|
|
138
|
+
*
|
|
139
|
+
* Spelled as an explicit interface (rather than `typeof import("./engine")`)
|
|
140
|
+
* because the dts roll-up — API Extractor — cannot resolve a `typeof import()`
|
|
141
|
+
* type node that points at an internal module. The shape stays in lockstep
|
|
142
|
+
* with `./engine`'s runtime exports.
|
|
143
|
+
*/
|
|
144
|
+
export declare interface AnimationEngine {
|
|
145
|
+
Animation: typeof Animation_2;
|
|
146
|
+
CSSKeyframesAnimation: typeof CSSKeyframesAnimation;
|
|
147
|
+
AnimationGroup: typeof AnimationGroup;
|
|
148
|
+
getAnimationId: (animation: Animation_2 | string) => string;
|
|
149
|
+
getTimingFunction: (timingFunction: TimingFunction | TimingFunctionNames | string | undefined) => TimingFunction | undefined;
|
|
150
|
+
resolveKeyframes: (input: string | Stylesheet) => ResolvedKeyframes;
|
|
151
|
+
DIRECTIONS: readonly AnimationOptions["direction"][];
|
|
152
|
+
FILL_MODES: readonly AnimationOptions["fillMode"][];
|
|
153
|
+
defaultOptions: AnimationOptions;
|
|
154
|
+
defaultLayerConfig: AnimationLayerConfig;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export declare interface AnimationFrame<V extends Vars> {
|
|
152
158
|
id: number;
|
|
153
159
|
start: ValueUnit;
|
|
154
160
|
ixs: {
|
|
@@ -215,15 +221,31 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
215
221
|
* Called per-frame for single-target groups. Applies layer blending
|
|
216
222
|
* (replace / add / weighted) in zIndex order, then calls the group
|
|
217
223
|
* transform function with the merged values.
|
|
224
|
+
*
|
|
225
|
+
* Refreshes every child's values at its current `t` in place —
|
|
226
|
+
* `interpFrames(t, false, entry.values)` clears and rewrites the
|
|
227
|
+
* long-lived buffer, so no stale keys leak across frames and no
|
|
228
|
+
* fresh object is allocated per entry per frame.
|
|
218
229
|
*/
|
|
219
230
|
transformFramesGrouped(t: number): Record<string, unknown>;
|
|
220
231
|
/**
|
|
221
|
-
* Render the current
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
232
|
+
* Render the current composition as a static frame using each
|
|
233
|
+
* child's current `t`. Single-target groups go through the
|
|
234
|
+
* blended transform; multi-target groups apply each child's
|
|
235
|
+
* interpolated vars directly to its own targets.
|
|
236
|
+
*
|
|
237
|
+
* This is the public entry point for scenarios that mutate a
|
|
238
|
+
* child's state outside the rAF loop (scrubbing, state restore,
|
|
239
|
+
* pause snapshots) and need the visual to update immediately.
|
|
240
|
+
*/
|
|
241
|
+
render(): void;
|
|
242
|
+
/**
|
|
243
|
+
* Set a child animation's current time without touching its
|
|
244
|
+
* siblings. Updates `pausedTime` so the child resumes correctly
|
|
245
|
+
* from the scrub position. Chainable. Call `render()` afterwards
|
|
246
|
+
* to reflect the change visually.
|
|
225
247
|
*/
|
|
226
|
-
|
|
248
|
+
setChildTime(nameOrAnim: string | Animation_2<V>, t: number): this;
|
|
227
249
|
/**
|
|
228
250
|
* Advance all child animations to timestamp `t`.
|
|
229
251
|
* Awaits all child tick() promises so deferred state updates
|
|
@@ -256,7 +278,11 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
256
278
|
playing(): boolean;
|
|
257
279
|
forcePause(): void;
|
|
258
280
|
forcePlay(): void;
|
|
259
|
-
/**
|
|
281
|
+
/**
|
|
282
|
+
* Set layer config for an animation by name or reference.
|
|
283
|
+
* Chainable. Throws when the key doesn't match a registered
|
|
284
|
+
* animation — silent no-ops were hiding consumer bugs.
|
|
285
|
+
*/
|
|
260
286
|
setLayerConfig(nameOrAnim: string | Animation_2<V>, config: Partial<AnimationLayerConfig>): this;
|
|
261
287
|
/** Convenience toggle for enabling/disabling a layer. Chainable. */
|
|
262
288
|
setLayerEnabled(nameOrAnim: string | Animation_2<V>, enabled: boolean): this;
|
|
@@ -264,7 +290,7 @@ export declare class AnimationGroup<V extends Vars> {
|
|
|
264
290
|
getLayerConfig(nameOrAnim: string | Animation_2<V>): AnimationLayerConfig | undefined;
|
|
265
291
|
}
|
|
266
292
|
|
|
267
|
-
declare interface AnimationGroupEntry<V extends Vars> {
|
|
293
|
+
export declare interface AnimationGroupEntry<V extends Vars> {
|
|
268
294
|
animation: Animation_2<V>;
|
|
269
295
|
values: Record<string, unknown>;
|
|
270
296
|
layer: AnimationLayerConfig;
|
|
@@ -280,7 +306,7 @@ declare interface AnimationGroupObject<V extends Vars> {
|
|
|
280
306
|
[key: string]: AnimationGroupEntry<V>;
|
|
281
307
|
}
|
|
282
308
|
|
|
283
|
-
declare interface AnimationLayerConfig {
|
|
309
|
+
export declare interface AnimationLayerConfig {
|
|
284
310
|
/** Higher wins. Default: 0 */
|
|
285
311
|
zIndex: number;
|
|
286
312
|
/** 0–1 for 'weighted' blend mode. Default: 1 */
|
|
@@ -293,7 +319,7 @@ declare interface AnimationLayerConfig {
|
|
|
293
319
|
properties?: Set<string>;
|
|
294
320
|
}
|
|
295
321
|
|
|
296
|
-
declare type AnimationOptions = {
|
|
322
|
+
export declare type AnimationOptions = {
|
|
297
323
|
duration: number;
|
|
298
324
|
delay: number;
|
|
299
325
|
iterationCount: number;
|
|
@@ -301,80 +327,30 @@ declare type AnimationOptions = {
|
|
|
301
327
|
fillMode: (typeof FILL_MODES)[number];
|
|
302
328
|
timingFunction: TimingFunction;
|
|
303
329
|
useWAAPI: boolean;
|
|
304
|
-
colorSpace:
|
|
330
|
+
colorSpace: ColorSpace;
|
|
305
331
|
hueMethod?: HueInterpolationMethod;
|
|
306
332
|
};
|
|
307
333
|
|
|
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 }
|
|
334
|
+
export declare type BlendMode = "replace" | "add" | "weighted";
|
|
327
335
|
|
|
328
336
|
export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V> {
|
|
329
337
|
constructor(options?: Partial<InputAnimationOptions>, ...targets: HTMLElement[]);
|
|
330
338
|
fromVars(vars: V[], transform?: TransformFunction<V>): this;
|
|
331
339
|
fromKeyframes(keyframes: Map<string, Partial<V>> | Record<string, Partial<V>>, transform?: TransformFunction<V>): this;
|
|
340
|
+
/**
|
|
341
|
+
* Property registry from `@property` declarations parsed by
|
|
342
|
+
* `fromString`. Empty when the input had no `@property` rules.
|
|
343
|
+
* Consumers can read this to recover the type metadata for
|
|
344
|
+
* custom properties (syntax string, initial value, inheritance
|
|
345
|
+
* flag) without re-parsing the source CSS.
|
|
346
|
+
*/
|
|
347
|
+
propertyRegistry: Map<string, PropertyDescriptor_2>;
|
|
332
348
|
fromString(keyframes: string, transform?: TransformFunction<V>): this;
|
|
333
349
|
transform(vars: V): void;
|
|
334
350
|
}
|
|
335
351
|
|
|
336
|
-
export { cubicBezier }
|
|
337
|
-
|
|
338
|
-
export { cubicBezierToString }
|
|
339
|
-
|
|
340
|
-
export { cubicBezierToSVG }
|
|
341
|
-
|
|
342
|
-
export { deCasteljau }
|
|
343
|
-
|
|
344
352
|
declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
|
|
345
353
|
|
|
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 }
|
|
365
|
-
|
|
366
|
-
export { easeInSine }
|
|
367
|
-
|
|
368
|
-
export { easeOutCirc }
|
|
369
|
-
|
|
370
|
-
export { easeOutCubic }
|
|
371
|
-
|
|
372
|
-
export { easeOutExpo }
|
|
373
|
-
|
|
374
|
-
export { easeOutQuad }
|
|
375
|
-
|
|
376
|
-
export { easeOutSine }
|
|
377
|
-
|
|
378
354
|
/**
|
|
379
355
|
* Interpolate position and scale between two elements or rects.
|
|
380
356
|
*
|
|
@@ -391,6 +367,14 @@ export declare class ElementMorph {
|
|
|
391
367
|
constructor(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect, options?: ElementMorphOptions);
|
|
392
368
|
/** Re-measure source and destination, rebuilding the internal animation. */
|
|
393
369
|
measure(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect): this;
|
|
370
|
+
/**
|
|
371
|
+
* Resolve a pending string easing *name* through the dynamic engine
|
|
372
|
+
* boundary. No-op for callable / omitted easing. Stateless `.at()` /
|
|
373
|
+
* `.toCSSTransform()` consumers that pass a name can `await .ready()`
|
|
374
|
+
* first to interpolate with the resolved easing; `.play()` awaits it
|
|
375
|
+
* automatically before the first frame.
|
|
376
|
+
*/
|
|
377
|
+
ready(): Promise<void>;
|
|
394
378
|
/** Get raw transform values at the given progress [0, 1]. */
|
|
395
379
|
at(progress: number): MorphValues;
|
|
396
380
|
/** Get a CSS transform string at the given progress [0, 1]. */
|
|
@@ -409,6 +393,13 @@ export declare class ElementMorph {
|
|
|
409
393
|
}
|
|
410
394
|
|
|
411
395
|
export declare interface ElementMorphOptions {
|
|
396
|
+
/**
|
|
397
|
+
* Easing as a callable `TimingFunction`, OR a string easing *name*
|
|
398
|
+
* from value.js's registry (`"ease-out-cubic"`, `"easeOutCubic"`, …).
|
|
399
|
+
* `ElementMorph` composes `NumericAnimation`, so a callable keeps the
|
|
400
|
+
* path value.js-free while a string name resolves LAZILY through the
|
|
401
|
+
* dynamic engine boundary on the first `.play()` (or `await .ready()`).
|
|
402
|
+
*/
|
|
412
403
|
timingFunction?: TimingFunction | TimingFunctionNames;
|
|
413
404
|
/** Playback duration in milliseconds. Required for `.play()`. */
|
|
414
405
|
duration?: number;
|
|
@@ -417,9 +408,7 @@ export declare interface ElementMorphOptions {
|
|
|
417
408
|
|
|
418
409
|
declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
|
|
419
410
|
|
|
420
|
-
export declare
|
|
421
|
-
|
|
422
|
-
declare type InputAnimationOptions = Partial<{
|
|
411
|
+
export declare type InputAnimationOptions = Partial<{
|
|
423
412
|
duration: number | string;
|
|
424
413
|
delay: number | string;
|
|
425
414
|
iterationCount: number | string | "infinite" | undefined;
|
|
@@ -428,19 +417,31 @@ declare type InputAnimationOptions = Partial<{
|
|
|
428
417
|
timingFunction: TimingFunction | TimingFunctionNames | undefined;
|
|
429
418
|
/** When true (default), eligible animations may use the Web Animations API for compositor-thread execution. Set to false to force rAF. */
|
|
430
419
|
useWAAPI: boolean;
|
|
431
|
-
colorSpace?:
|
|
420
|
+
colorSpace?: ColorSpace;
|
|
432
421
|
hueMethod?: HueInterpolationMethod;
|
|
433
422
|
}>;
|
|
434
423
|
|
|
435
|
-
export {
|
|
436
|
-
|
|
437
|
-
export { jumpTerms }
|
|
438
|
-
|
|
439
|
-
export { lerp }
|
|
424
|
+
export { InterpolatedVar }
|
|
440
425
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
426
|
+
/**
|
|
427
|
+
* Load the heavy CSS-keyframe parsing engine — `Animation`,
|
|
428
|
+
* `CSSKeyframesAnimation`, `AnimationGroup`, `getTimingFunction`,
|
|
429
|
+
* `resolveKeyframes`, and the animation-options constants (`DIRECTIONS`,
|
|
430
|
+
* `FILL_MODES`, `defaultOptions`, `defaultLayerConfig`).
|
|
431
|
+
*
|
|
432
|
+
* This is the dynamic boundary: the `import("./engine")` pulls value.js into
|
|
433
|
+
* the consumer's graph only when first awaited, so a light-only consumer
|
|
434
|
+
* (spring / smooth / numeric / morph / timeline) never loads it.
|
|
435
|
+
*
|
|
436
|
+
* ```ts
|
|
437
|
+
* const { CSSKeyframesAnimation } = await loadAnimationEngine();
|
|
438
|
+
* const anim = new CSSKeyframesAnimation(opts).fromString(css);
|
|
439
|
+
* ```
|
|
440
|
+
*
|
|
441
|
+
* The browser caches the dynamic module after the first load, so repeat
|
|
442
|
+
* calls resolve from the module cache without a second fetch.
|
|
443
|
+
*/
|
|
444
|
+
export declare const loadAnimationEngine: () => Promise<AnimationEngine>;
|
|
444
445
|
|
|
445
446
|
export declare class ManualTimeline extends Timeline {
|
|
446
447
|
private value;
|
|
@@ -484,12 +485,24 @@ export declare class NumericAnimation<T extends Record<string, number>> {
|
|
|
484
485
|
private timingFn;
|
|
485
486
|
private result;
|
|
486
487
|
private _duration;
|
|
487
|
-
private
|
|
488
|
-
private
|
|
489
|
-
private
|
|
488
|
+
private _respectReducedMotion;
|
|
489
|
+
private _pendingEasingName;
|
|
490
|
+
private _easingReady;
|
|
491
|
+
private _playback;
|
|
490
492
|
constructor(keyframes: T[], options?: NumericAnimationOptions);
|
|
491
493
|
private buildSegments;
|
|
492
494
|
private buildSegment;
|
|
495
|
+
/**
|
|
496
|
+
* Resolve a pending string easing *name* through the dynamic engine
|
|
497
|
+
* boundary. A no-op (resolved promise) when easing was supplied as a
|
|
498
|
+
* callable or omitted. Memoized — the `await import("./engine")` and
|
|
499
|
+
* `getTimingFunction` lookup run at most once per instance.
|
|
500
|
+
*
|
|
501
|
+
* `.play()` awaits this before the first frame; stateless `.at()`
|
|
502
|
+
* consumers that pass a name can `await animation.ready()` first to
|
|
503
|
+
* interpolate with the resolved easing rather than the linear fallback.
|
|
504
|
+
*/
|
|
505
|
+
ready(): Promise<void>;
|
|
493
506
|
/**
|
|
494
507
|
* Map [0, 1] progress to interpolated values. Zero allocation —
|
|
495
508
|
* returns the same pre-allocated result object on every call.
|
|
@@ -513,15 +526,40 @@ export declare class NumericAnimation<T extends Record<string, number>> {
|
|
|
513
526
|
play(onFrame?: NumericFrameCallback<T>, duration?: number): Promise<void>;
|
|
514
527
|
/** Cancel a running `.play()` animation. The play promise resolves immediately. */
|
|
515
528
|
stop(): void;
|
|
516
|
-
private _cleanup;
|
|
517
529
|
}
|
|
518
530
|
|
|
519
531
|
export declare interface NumericAnimationOptions {
|
|
532
|
+
/**
|
|
533
|
+
* Easing as a callable `TimingFunction`, OR a string easing *name*
|
|
534
|
+
* from value.js's registry (`"ease-out-cubic"`, `"easeOutCubic"`,
|
|
535
|
+
* `"linear"`, …).
|
|
536
|
+
*
|
|
537
|
+
* A **callable** is used directly and keeps this engine value.js-free —
|
|
538
|
+
* no dynamic import, nothing pulled into the static graph.
|
|
539
|
+
*
|
|
540
|
+
* A **string name** is resolved LAZILY through the dynamic engine
|
|
541
|
+
* boundary: on the first `.play()` (or an explicit `await .ready()`)
|
|
542
|
+
* the engine module is `await import(...)`-ed and the name looked up
|
|
543
|
+
* via `getTimingFunction`, so the value.js-bearing easing registry
|
|
544
|
+
* loads only when a named easing is actually used. The resolved
|
|
545
|
+
* callable is cached on the instance (resolved once per animation).
|
|
546
|
+
* Until resolution, `.at()` interpolates with a linear fallback.
|
|
547
|
+
*/
|
|
520
548
|
timingFunction?: TimingFunction | TimingFunctionNames | undefined;
|
|
521
549
|
/** Playback duration in milliseconds. Required for `.play()`. */
|
|
522
550
|
duration?: number | undefined;
|
|
523
551
|
/** Explicit positions as percentages [0-100]. Auto-distributes if omitted. */
|
|
524
552
|
positions?: number[] | undefined;
|
|
553
|
+
/**
|
|
554
|
+
* When true, honor `prefers-reduced-motion: reduce` by snapping to the
|
|
555
|
+
* final keyframe values immediately rather than interpolating over
|
|
556
|
+
* `duration`. The play promise resolves on the next microtask. Default
|
|
557
|
+
* false (back-compat — consumers opt in).
|
|
558
|
+
*
|
|
559
|
+
* The check uses `matchMedia` if available; on SSR / Node the option
|
|
560
|
+
* is a no-op (animations proceed normally).
|
|
561
|
+
*/
|
|
562
|
+
respectReducedMotion?: boolean | undefined;
|
|
525
563
|
}
|
|
526
564
|
|
|
527
565
|
/** Callback invoked each frame during `.play()` with the interpolated values. */
|
|
@@ -529,19 +567,64 @@ export declare type NumericFrameCallback<T extends Record<string, number>> = (va
|
|
|
529
567
|
|
|
530
568
|
declare type ParsedVarMap = Record<string, ValueArray>;
|
|
531
569
|
|
|
532
|
-
|
|
570
|
+
/**
|
|
571
|
+
* Shared rAF playback lifecycle for stateless interpolators
|
|
572
|
+
* (`NumericAnimation`, `ElementMorph`). Owns the rAF handle, start
|
|
573
|
+
* timestamp, and resolve callback so the interpolator classes don't
|
|
574
|
+
* each reimplement the same loop.
|
|
575
|
+
*
|
|
576
|
+
* Not used by the full `Animation` class — that engine has a richer
|
|
577
|
+
* lifecycle (iteration, direction, fill modes, events) that doesn't
|
|
578
|
+
* factor into this primitive.
|
|
579
|
+
*/
|
|
580
|
+
export declare class RAFPlayback {
|
|
581
|
+
private _rafId;
|
|
582
|
+
private _startTime;
|
|
583
|
+
private _resolve;
|
|
584
|
+
/**
|
|
585
|
+
* Drive `onTick(progress)` once per frame for `duration` ms.
|
|
586
|
+
* `progress` is clamped to [0, 1]; the loop terminates after the
|
|
587
|
+
* frame at `progress === 1`. The returned promise resolves when
|
|
588
|
+
* the animation completes naturally or is interrupted by `stop()`.
|
|
589
|
+
*/
|
|
590
|
+
play(duration: number, onTick: (progress: number) => void): Promise<void>;
|
|
591
|
+
/** Cancel a running playback. The play promise resolves immediately. */
|
|
592
|
+
stop(): void;
|
|
593
|
+
private _cleanup;
|
|
594
|
+
}
|
|
533
595
|
|
|
534
|
-
|
|
596
|
+
/**
|
|
597
|
+
* Result of normalising a CSS keyframes input down to the shape the
|
|
598
|
+
* `CSSKeyframesAnimation.fromString` flow expects: a `Map<percent →
|
|
599
|
+
* vars>` of ready-to-add frames, plus side data (per-keyframe timing
|
|
600
|
+
* functions, the `@property` registry, and any animation-shorthand
|
|
601
|
+
* options that came from a sibling style rule).
|
|
602
|
+
*/
|
|
603
|
+
export declare interface ResolvedKeyframes {
|
|
604
|
+
/** percent-string → flat `{prop: value}` snapshot */
|
|
605
|
+
keyframes: Map<string, Record<string, unknown>>;
|
|
606
|
+
/** per-keyframe `animation-timing-function`, keyed by percent string */
|
|
607
|
+
timingFunctions: Map<string, string>;
|
|
608
|
+
/** `@property --foo { ... }` registry */
|
|
609
|
+
properties: Map<string, PropertyDescriptor_2>;
|
|
610
|
+
/**
|
|
611
|
+
* Animation options recovered from a top-level style rule's
|
|
612
|
+
* `animation` shorthand or longhand declarations (if any). Empty
|
|
613
|
+
* when the input has no matching style rule.
|
|
614
|
+
*/
|
|
615
|
+
options: ReturnType<typeof extractAnimationOptions>;
|
|
616
|
+
}
|
|
535
617
|
|
|
536
|
-
|
|
618
|
+
declare class ScrollTimeline_2 extends Timeline {
|
|
537
619
|
private threshold;
|
|
538
620
|
private getScrollY;
|
|
539
621
|
private getViewportHeight;
|
|
540
|
-
constructor(options?:
|
|
622
|
+
constructor(options?: ScrollTimelineOptions_2);
|
|
541
623
|
protected sample(): number;
|
|
542
624
|
}
|
|
625
|
+
export { ScrollTimeline_2 as ScrollTimeline }
|
|
543
626
|
|
|
544
|
-
|
|
627
|
+
declare interface ScrollTimelineOptions_2 extends TimelineOptions {
|
|
545
628
|
/** Viewport fraction for full progress. Default 0.35. */
|
|
546
629
|
threshold?: number | undefined;
|
|
547
630
|
/** Custom scroll position supplier. Default: window.scrollY. */
|
|
@@ -549,14 +632,19 @@ export declare interface ScrollTimelineOptions extends TimelineOptions {
|
|
|
549
632
|
/** Custom viewport height supplier. Default: window.innerHeight. */
|
|
550
633
|
getViewportHeight?: (() => number) | undefined;
|
|
551
634
|
}
|
|
635
|
+
export { ScrollTimelineOptions_2 as ScrollTimelineOptions }
|
|
552
636
|
|
|
553
|
-
|
|
637
|
+
/** Per-frame callback for `.play()` mode. Receives the smoothed current value. */
|
|
638
|
+
declare type SmoothFrameCallback = (value: number) => void;
|
|
554
639
|
|
|
555
640
|
export declare class SmoothProgress {
|
|
556
641
|
private options;
|
|
557
642
|
private targetValue;
|
|
558
643
|
private currentValue;
|
|
559
644
|
private isSettled;
|
|
645
|
+
private _rafId;
|
|
646
|
+
private _lastFrameT;
|
|
647
|
+
private _onFrame;
|
|
560
648
|
constructor(options?: Partial<SmoothProgressOptions>);
|
|
561
649
|
get target(): number;
|
|
562
650
|
get current(): number;
|
|
@@ -570,6 +658,26 @@ export declare class SmoothProgress {
|
|
|
570
658
|
snap(): void;
|
|
571
659
|
/** Reset to a specific value (default 0). */
|
|
572
660
|
reset(value?: number): void;
|
|
661
|
+
/**
|
|
662
|
+
* Start a managed rAF loop that calls `tickDt(dt)` each frame until
|
|
663
|
+
* `settled`, invoking `onFrame(current)` per tick. Idempotent — repeat
|
|
664
|
+
* calls re-bind the callback without spawning a second loop. Once
|
|
665
|
+
* settled the loop auto-stops; `setTarget()` while a callback is
|
|
666
|
+
* bound auto-resumes the loop without needing another `.play()`.
|
|
667
|
+
*
|
|
668
|
+
* Symmetric with `NumericAnimation.play(onFrame)`: library owns rAF,
|
|
669
|
+
* consumer provides a per-frame callback. Consumers that already
|
|
670
|
+
* drive their own rAF (e.g. canvas renderers) should continue to
|
|
671
|
+
* call `.tickDt(dt)` directly and never invoke `.play()`.
|
|
672
|
+
*/
|
|
673
|
+
play(onFrame?: SmoothFrameCallback): void;
|
|
674
|
+
/**
|
|
675
|
+
* Cancel the managed rAF loop and detach the per-frame callback.
|
|
676
|
+
* Pairs with `.play()`. Does not touch current/target/settled state.
|
|
677
|
+
*/
|
|
678
|
+
stop(): void;
|
|
679
|
+
private _startLoop;
|
|
680
|
+
private _stopLoop;
|
|
573
681
|
}
|
|
574
682
|
|
|
575
683
|
export declare interface SmoothProgressOptions {
|
|
@@ -587,17 +695,273 @@ export declare interface SmoothProgressOptions {
|
|
|
587
695
|
initial: number;
|
|
588
696
|
/** Clamp current to [0, 1]. Default true */
|
|
589
697
|
clamp: boolean;
|
|
698
|
+
/**
|
|
699
|
+
* When true, honor `prefers-reduced-motion: reduce` by snapping to
|
|
700
|
+
* target immediately rather than damping. `setTarget` short-circuits
|
|
701
|
+
* the smooth-toward path; `play()` invokes `onFrame` once with the
|
|
702
|
+
* target value. Default false (back-compat — consumers opt in).
|
|
703
|
+
*
|
|
704
|
+
* The check uses `matchMedia` if available; on SSR / Node the option
|
|
705
|
+
* is a no-op (animations proceed normally).
|
|
706
|
+
*/
|
|
707
|
+
respectReducedMotion: boolean;
|
|
590
708
|
}
|
|
591
709
|
|
|
592
|
-
|
|
710
|
+
/** Per-frame callback for `.play()` mode. */
|
|
711
|
+
export declare type SpringFrameCallback = (value: number, velocity: number) => void;
|
|
593
712
|
|
|
594
|
-
|
|
713
|
+
/**
|
|
714
|
+
* Sample a `SpringProgress(target=1, initial=0)` solver and emit a CSS
|
|
715
|
+
* `linear()` timing-function string. Suitable for
|
|
716
|
+
* `transition-timing-function` / `animation-timing-function` / token
|
|
717
|
+
* generation (the four `--spring-*` glass-ui tokens regenerate from
|
|
718
|
+
* this helper).
|
|
719
|
+
*
|
|
720
|
+
* The emitted curve passes through `(0%, 0)` and `(100%, 1)` exactly.
|
|
721
|
+
* Intermediate stops carry the unitless spring position; values may
|
|
722
|
+
* exceed 1 (overshoot) for ζ < 1, which CSS `linear()` honors natively.
|
|
723
|
+
*
|
|
724
|
+
* @returns e.g. `"linear(0, 0.234 4.17%, ..., 1)"`
|
|
725
|
+
*/
|
|
726
|
+
export declare function springLinearStops(opts: SpringLinearStopsOptions): string;
|
|
595
727
|
|
|
596
|
-
|
|
728
|
+
/**
|
|
729
|
+
* Options for sampling a spring response curve into CSS `linear()` stops.
|
|
730
|
+
*/
|
|
731
|
+
export declare interface SpringLinearStopsOptions {
|
|
732
|
+
/** Angular period of oscillation in seconds. */
|
|
733
|
+
response: number;
|
|
734
|
+
/** Damping ratio ζ. */
|
|
735
|
+
dampingFraction: number;
|
|
736
|
+
/**
|
|
737
|
+
* Number of intermediate sample points. Default 24. The emitted
|
|
738
|
+
* string also includes the implicit `0` start and `1` end stops,
|
|
739
|
+
* so the total stop count is `sampleCount + 2`.
|
|
740
|
+
*/
|
|
741
|
+
sampleCount?: number;
|
|
742
|
+
/**
|
|
743
|
+
* Position + velocity envelope below which the spring is treated
|
|
744
|
+
* as settled and sampling stops early (subsequent positions are
|
|
745
|
+
* pinned to 1). Default 1e-3. Increase for shorter `linear()`
|
|
746
|
+
* strings on overdamped springs (which take longer to settle).
|
|
747
|
+
*/
|
|
748
|
+
settleThreshold?: number;
|
|
749
|
+
/**
|
|
750
|
+
* Upper bound on the sampled time span in seconds. Default 4 ×
|
|
751
|
+
* response (covers ~99% of the envelope for ζ ≥ 0.3). Increase
|
|
752
|
+
* if a very-underdamped spring (ζ < 0.3) is being sampled and
|
|
753
|
+
* the tail keeps ringing past the default cap.
|
|
754
|
+
*/
|
|
755
|
+
maxDuration?: number;
|
|
756
|
+
}
|
|
597
757
|
|
|
598
|
-
|
|
758
|
+
/**
|
|
759
|
+
* Live-target spring tracker. Sibling of `SmoothProgress` for animations
|
|
760
|
+
* where the target may change mid-flight (gesture follows, drag, live
|
|
761
|
+
* data) and overshoot / oscillation is desired.
|
|
762
|
+
*
|
|
763
|
+
* The solver integrates the second-order damped harmonic oscillator
|
|
764
|
+
* analytically between target-change events. Mid-frame target changes
|
|
765
|
+
* re-seat the closed-form solution from the current `(x, v)` state, so
|
|
766
|
+
* the trajectory never jumps.
|
|
767
|
+
*
|
|
768
|
+
* Three integration cases (chosen by ζ):
|
|
769
|
+
*
|
|
770
|
+
* - **Underdamped** (ζ < 1): decaying sinusoid. Overshoots; rings.
|
|
771
|
+
* - **Critically damped** (ζ = 1): fastest settle without overshoot.
|
|
772
|
+
* - **Overdamped** (ζ > 1): two exponential modes, monotone settle.
|
|
773
|
+
*
|
|
774
|
+
* API mirrors SwiftUI's `.spring(response:dampingFraction:)`.
|
|
775
|
+
*/
|
|
776
|
+
export declare class SpringProgress {
|
|
777
|
+
private options;
|
|
778
|
+
private targetValue;
|
|
779
|
+
private currentValue;
|
|
780
|
+
private currentVelocity;
|
|
781
|
+
private isSettled;
|
|
782
|
+
/** Time elapsed since the last target re-seat, in seconds. */
|
|
783
|
+
private elapsed;
|
|
784
|
+
/** Cached `(x, v)` at the most recent target re-seat. */
|
|
785
|
+
private originValue;
|
|
786
|
+
private originVelocity;
|
|
787
|
+
private omega;
|
|
788
|
+
private zeta;
|
|
789
|
+
private omegaD;
|
|
790
|
+
private subscribers;
|
|
791
|
+
private disposed;
|
|
792
|
+
private _rafId;
|
|
793
|
+
private _lastFrameT;
|
|
794
|
+
private _onFrame;
|
|
795
|
+
constructor(options?: Partial<SpringProgressOptions>);
|
|
796
|
+
get target(): number;
|
|
797
|
+
get value(): number;
|
|
798
|
+
get velocity(): number;
|
|
799
|
+
get settled(): boolean;
|
|
800
|
+
/**
|
|
801
|
+
* Set the target. The closed-form solution is re-seated from the
|
|
802
|
+
* current `(value, velocity)` so the trajectory is continuous.
|
|
803
|
+
* Idempotent if the target is unchanged.
|
|
804
|
+
*/
|
|
805
|
+
set target(value: number);
|
|
806
|
+
private reseatTarget;
|
|
807
|
+
/**
|
|
808
|
+
* Advance by `dt` seconds. Uses the analytic closed-form solution
|
|
809
|
+
* accumulated from the last target re-seat (so per-frame error is
|
|
810
|
+
* O(machine epsilon), not O(dt²) like Euler).
|
|
811
|
+
*/
|
|
812
|
+
tick(dt: number): number;
|
|
813
|
+
/**
|
|
814
|
+
* Evaluate the solver at elapsed time `t` (seconds) from the most
|
|
815
|
+
* recent target re-seat. Equivalent to `tick(t - elapsed)` but
|
|
816
|
+
* accepts absolute elapsed time — useful when consumers track their
|
|
817
|
+
* own clock.
|
|
818
|
+
*/
|
|
819
|
+
tickToTime(t: number): number;
|
|
820
|
+
/**
|
|
821
|
+
* Analytic step. Updates `currentValue` + `currentVelocity` to
|
|
822
|
+
* `(x(t), v(t))` of the underlying second-order system, with
|
|
823
|
+
* `x(0) = originValue - targetValue`, `v(0) = originVelocity`.
|
|
824
|
+
*
|
|
825
|
+
* Cases:
|
|
826
|
+
* underdamped: x(t) = e^(-ζω t) [A cos(ω_d t) + B sin(ω_d t)]
|
|
827
|
+
* critical: x(t) = e^(-ω t) [A + B t]
|
|
828
|
+
* overdamped: x(t) = A e^(r₁ t) + B e^(r₂ t)
|
|
829
|
+
*/
|
|
830
|
+
private evaluateAt;
|
|
831
|
+
private checkSettled;
|
|
832
|
+
/** Immediately set value = target, zero velocity. */
|
|
833
|
+
snap(): void;
|
|
834
|
+
/** Reset position + velocity to a specified value (default 0). */
|
|
835
|
+
reset(value?: number, velocity?: number): void;
|
|
836
|
+
/**
|
|
837
|
+
* Subscribe to per-tick updates. Returns an unsubscribe handle.
|
|
838
|
+
* Called with `(value, velocity)` on every `tick`/`snap`/`reset`/
|
|
839
|
+
* `target` set.
|
|
840
|
+
*/
|
|
841
|
+
subscribe(fn: SpringSubscriber): () => void;
|
|
842
|
+
private emit;
|
|
843
|
+
/** Tear down the spring. Cancels the rAF loop and clears subscribers. */
|
|
844
|
+
dispose(): void;
|
|
845
|
+
/**
|
|
846
|
+
* Start a managed rAF loop that calls `tick(dt)` each frame until
|
|
847
|
+
* `settled`, invoking `onFrame(value, velocity)` per tick. Idempotent
|
|
848
|
+
* — repeat calls re-bind the callback without spawning a second loop.
|
|
849
|
+
* Once settled the loop auto-stops; setting `target` while a callback
|
|
850
|
+
* is bound auto-resumes the loop without needing another `.play()`.
|
|
851
|
+
*/
|
|
852
|
+
play(onFrame?: SpringFrameCallback): void;
|
|
853
|
+
/** Cancel the managed rAF loop and detach the per-frame callback. */
|
|
854
|
+
stop(): void;
|
|
855
|
+
private _startLoop;
|
|
856
|
+
private _stopLoop;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* iOS-style spring physics options. The pair `(response, dampingFraction)`
|
|
861
|
+
* is the SwiftUI-canonical surface — designer-tunable, normalized so
|
|
862
|
+
* `dampingFraction = 1` is critically damped (no overshoot), `< 1` rings,
|
|
863
|
+
* `> 1` is overdamped (sluggish). Internally these map onto a standard
|
|
864
|
+
* second-order linear ODE
|
|
865
|
+
*
|
|
866
|
+
* x'' + 2ζω₀ x' + ω₀² x = ω₀² target
|
|
867
|
+
*
|
|
868
|
+
* with `ω₀ = 2π / response` and `ζ = dampingFraction`, unit mass.
|
|
869
|
+
*/
|
|
870
|
+
export declare interface SpringProgressOptions {
|
|
871
|
+
/**
|
|
872
|
+
* Angular period of the oscillation in seconds. Roughly the time the
|
|
873
|
+
* spring takes to swing through one cycle if undamped. Default 0.5.
|
|
874
|
+
* Smaller values → snappier; larger → looser.
|
|
875
|
+
*/
|
|
876
|
+
response: number;
|
|
877
|
+
/**
|
|
878
|
+
* Damping ratio ζ. `1` critically damped (fastest no-overshoot);
|
|
879
|
+
* `< 1` underdamped (rings); `> 1` overdamped (sluggish). Default
|
|
880
|
+
* 0.86 — the iOS "smooth" preset.
|
|
881
|
+
*/
|
|
882
|
+
dampingFraction: number;
|
|
883
|
+
/** Starting position. Default 0. */
|
|
884
|
+
initial: number;
|
|
885
|
+
/** Starting velocity (units/s). Default 0. */
|
|
886
|
+
initialVelocity: number;
|
|
887
|
+
/**
|
|
888
|
+
* Position settle threshold. When |x - target| AND |v| both drop
|
|
889
|
+
* below `settleThreshold` and `velocitySettleThreshold` respectively,
|
|
890
|
+
* the spring snaps to target and stops integrating. Default 1e-3.
|
|
891
|
+
*/
|
|
892
|
+
settleThreshold: number;
|
|
893
|
+
/** Velocity settle threshold (units/s). Default 1e-3. */
|
|
894
|
+
velocitySettleThreshold: number;
|
|
895
|
+
/**
|
|
896
|
+
* When true, honor `prefers-reduced-motion: reduce` by snapping to
|
|
897
|
+
* target immediately rather than springing. SSR-safe (no-op on
|
|
898
|
+
* non-browser environments). Default false.
|
|
899
|
+
*/
|
|
900
|
+
respectReducedMotion: boolean;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/** Subscriber callback. Receives current position + velocity each emission. */
|
|
904
|
+
export declare type SpringSubscriber = (value: number, velocity: number) => void;
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Sample a `SpringProgress(target=1, initial=0)` solver and return a
|
|
908
|
+
* pure `TimingFunction` — `(t: number) => number` over t∈[0,1] — that
|
|
909
|
+
* `ElementMorph`, `NumericAnimation`, and `Animation.addFrame` accept
|
|
910
|
+
* directly (anywhere a `TimingFunction` is taken).
|
|
911
|
+
*
|
|
912
|
+
* This is the JS-easing sibling of `springLinearStops`: same solver,
|
|
913
|
+
* same `(response, dampingFraction)` surface, same default
|
|
914
|
+
* `maxDuration = response * 4`. Where `springLinearStops` emits a CSS
|
|
915
|
+
* `linear()` string for stylesheets/tokens, this returns a closure for
|
|
916
|
+
* code paths that drive interpolation directly and cannot consume a
|
|
917
|
+
* `linear()` string.
|
|
918
|
+
*
|
|
919
|
+
* The returned curve satisfies `f(0) = 0` and `f(1) = 1` exactly.
|
|
920
|
+
* Interior values may exceed 1 for ζ < 1 (overshoot) — e.g. the bouncy
|
|
921
|
+
* `response 0.5 / ζ 0.45` preset peaks at ≈ 1.205 mid-curve — which is
|
|
922
|
+
* the whole point: feeding this into `ElementMorph` produces the
|
|
923
|
+
* canonical iOS spring overshoot without hand-rolling stops or a
|
|
924
|
+
* second ODE integrator.
|
|
925
|
+
*
|
|
926
|
+
* @example
|
|
927
|
+
* const spring = springTimingFunction({ response: 0.5, dampingFraction: 0.45 });
|
|
928
|
+
* const morph = new ElementMorph(from, to, { timingFunction: spring });
|
|
929
|
+
*/
|
|
930
|
+
export declare function springTimingFunction(opts: SpringTimingFunctionOptions): TimingFunction;
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Options for sampling a spring response curve into a callable
|
|
934
|
+
* `TimingFunction`. Mirrors `SpringLinearStopsOptions` so the same
|
|
935
|
+
* preset (`response`, `dampingFraction`, ...) produces an identical
|
|
936
|
+
* curve whether emitted as a CSS `linear()` string or a JS easing.
|
|
937
|
+
*/
|
|
938
|
+
export declare interface SpringTimingFunctionOptions {
|
|
939
|
+
/** Angular period of oscillation in seconds. */
|
|
940
|
+
response: number;
|
|
941
|
+
/** Damping ratio ζ. `< 1` overshoots/rings; `≥ 1` monotone. */
|
|
942
|
+
dampingFraction: number;
|
|
943
|
+
/**
|
|
944
|
+
* Number of intermediate sample points between t=0 and t=1.
|
|
945
|
+
* Default 64 — higher than `springLinearStops` (24) because the
|
|
946
|
+
* lerp between samples is the only smoothing a JS easing gets,
|
|
947
|
+
* whereas CSS `linear()` is consumed at sub-pixel cadence.
|
|
948
|
+
*/
|
|
949
|
+
sampleCount?: number;
|
|
950
|
+
/**
|
|
951
|
+
* Position + velocity envelope below which the spring is treated
|
|
952
|
+
* as settled (subsequent positions pin to 1). Default 1e-3.
|
|
953
|
+
*/
|
|
954
|
+
settleThreshold?: number;
|
|
955
|
+
/**
|
|
956
|
+
* Upper bound on the sampled time span in seconds — the spring
|
|
957
|
+
* time that normalized `t = 1` maps to. Default 4 × response
|
|
958
|
+
* (covers ~99% of the envelope for ζ ≥ 0.3). Increase for very
|
|
959
|
+
* underdamped springs (ζ < 0.3) whose tail rings past the cap.
|
|
960
|
+
*/
|
|
961
|
+
maxDuration?: number;
|
|
962
|
+
}
|
|
599
963
|
|
|
600
|
-
declare interface TemplateAnimationFrame<V extends Vars> {
|
|
964
|
+
export declare interface TemplateAnimationFrame<V extends Vars> {
|
|
601
965
|
id: number;
|
|
602
966
|
start: ValueUnit;
|
|
603
967
|
vars: V;
|
|
@@ -610,7 +974,21 @@ export declare abstract class Timeline {
|
|
|
610
974
|
private easingFn;
|
|
611
975
|
private currentProgress;
|
|
612
976
|
private boundaryEpsilon;
|
|
977
|
+
private _easingReady;
|
|
613
978
|
constructor(options?: TimelineOptions);
|
|
979
|
+
/**
|
|
980
|
+
* Lazily resolve a string easing *name* through the dynamic engine
|
|
981
|
+
* boundary. Memoized — the `await import("./engine")` and
|
|
982
|
+
* `getTimingFunction` lookup run at most once.
|
|
983
|
+
*/
|
|
984
|
+
private resolveEasingName;
|
|
985
|
+
/**
|
|
986
|
+
* Resolve a pending string easing *name* through the dynamic engine
|
|
987
|
+
* boundary. No-op (resolved promise) for callable / omitted easing.
|
|
988
|
+
* `await timeline.ready()` before the first `tick()` to apply the
|
|
989
|
+
* eased value immediately rather than letting it land asynchronously.
|
|
990
|
+
*/
|
|
991
|
+
ready(): Promise<void>;
|
|
614
992
|
/** Subclass returns raw [0,1] progress from its source. */
|
|
615
993
|
protected abstract sample(): number;
|
|
616
994
|
/**
|
|
@@ -625,6 +1003,12 @@ export declare abstract class Timeline {
|
|
|
625
1003
|
* Snaps the smoother at boundaries [0, 1] for instant convergence.
|
|
626
1004
|
*/
|
|
627
1005
|
private finalizeProgress;
|
|
1006
|
+
/**
|
|
1007
|
+
* Shared advance step. When `dt` is undefined, drives the
|
|
1008
|
+
* smoother in frame-rate-dependent mode (`tick()`); when given,
|
|
1009
|
+
* uses the frame-rate-independent variant (`tickDt(dt)`).
|
|
1010
|
+
*/
|
|
1011
|
+
private _advance;
|
|
628
1012
|
/** Advance one frame. Applies easing → boundary snap → smoothing. */
|
|
629
1013
|
tick(): number;
|
|
630
1014
|
/** Frame-rate independent variant. `dt` in milliseconds. */
|
|
@@ -639,6 +1023,19 @@ export declare abstract class Timeline {
|
|
|
639
1023
|
}
|
|
640
1024
|
|
|
641
1025
|
export declare interface TimelineOptions {
|
|
1026
|
+
/**
|
|
1027
|
+
* Easing as a callable `TimingFunction`, OR a string easing *name*
|
|
1028
|
+
* from value.js's registry (`"ease-out-cubic"`, `"easeOutCubic"`, …).
|
|
1029
|
+
*
|
|
1030
|
+
* A **callable** is applied directly and keeps `Timeline` value.js-free.
|
|
1031
|
+
*
|
|
1032
|
+
* A **string name** is resolved LAZILY through the dynamic engine
|
|
1033
|
+
* boundary: the constructor kicks off an `await import(...)` and the
|
|
1034
|
+
* resolved easing is applied once it lands (subsequent `tick()`s use
|
|
1035
|
+
* it). Until then `tick()` runs with the identity easing. Consumers
|
|
1036
|
+
* that need the eased value on the very first `tick()` can
|
|
1037
|
+
* `await timeline.ready()` first.
|
|
1038
|
+
*/
|
|
642
1039
|
easing?: TimingFunction | TimingFunctionNames | undefined;
|
|
643
1040
|
/** SmoothProgress config. `false` disables smoothing. Default: enabled. */
|
|
644
1041
|
smoothing?: Partial<SmoothProgressOptions> | false | undefined;
|
|
@@ -652,15 +1049,13 @@ export declare interface TimelineOptions {
|
|
|
652
1049
|
boundaryEpsilon?: number | undefined;
|
|
653
1050
|
}
|
|
654
1051
|
|
|
655
|
-
declare type TimingFunction = (t: number) => number;
|
|
656
|
-
|
|
657
|
-
declare type TimingFunctionNames = keyof typeof timingFunctions;
|
|
1052
|
+
export declare type TimingFunction = (t: number) => number;
|
|
658
1053
|
|
|
659
|
-
export
|
|
1054
|
+
export declare type TimingFunctionNames = keyof typeof timingFunctions;
|
|
660
1055
|
|
|
661
|
-
declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
|
|
1056
|
+
export declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
|
|
662
1057
|
|
|
663
|
-
declare type Vars<T = any> = {
|
|
1058
|
+
export declare type Vars<T = any> = {
|
|
664
1059
|
[arg: string]: number | string | T;
|
|
665
1060
|
};
|
|
666
1061
|
|