@mkbabb/keyframes.js 1.1.5 → 1.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.
@@ -0,0 +1,450 @@
1
+ import { bezierPresets } from '@mkbabb/value.js';
2
+ import { bounceInEase } from '@mkbabb/value.js';
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';
24
+ import { HueInterpolationMethod } from '@mkbabb/value.js';
25
+ import { InterpolatedVar } from '@mkbabb/value.js';
26
+ import { jumpTerms } from '@mkbabb/value.js';
27
+ import { linear } from '@mkbabb/value.js';
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';
32
+ import { timingFunctions } from '@mkbabb/value.js';
33
+ import { ValueArray } from '@mkbabb/value.js';
34
+ import { ValueUnit } from '@mkbabb/value.js';
35
+
36
+ declare class Animation_2<V extends Vars = any> {
37
+ id: number;
38
+ name: string | undefined;
39
+ superKey: string | undefined;
40
+ targets: HTMLElement[];
41
+ options: AnimationOptions;
42
+ templateFrames: TemplateAnimationFrame<V>[];
43
+ parsedVars: ParsedVarMap[];
44
+ frameId: number;
45
+ frames: AnimationFrame<V>[];
46
+ handleId: number | any;
47
+ startTime: number | undefined;
48
+ pausedTime: number;
49
+ prevTime: number;
50
+ t: number;
51
+ iteration: number;
52
+ started: boolean;
53
+ done: boolean;
54
+ reversed: boolean;
55
+ paused: boolean;
56
+ /** When true, this animation is managed by an AnimationGroup and should not run its own rAF loop. */
57
+ managed: boolean;
58
+ unflatten: boolean;
59
+ private resolvePromise;
60
+ private _playingPromise;
61
+ private dispatchAnimationEvent;
62
+ constructor(options?: Partial<InputAnimationOptions>, targets?: HTMLElement[] | HTMLElement | undefined, name?: string | undefined, superKey?: string | undefined);
63
+ convertFrameStart(frame: TemplateAnimationFrame<V>): TemplateAnimationFrame<V>;
64
+ addFrame<K extends V>(start: number | string | ValueUnit<number>, vars: Partial<K>, transform?: TransformFunction<K>, timingFunction?: TimingFunction | TimingFunctionNames): Animation_2<K>;
65
+ createFrame(startIx: number, endIx: number): AnimationFrame<V>;
66
+ reconcileVars(ix: number): void;
67
+ parse(): this;
68
+ setTimingFunction(timingFunction: InputAnimationOptions["timingFunction"]): this;
69
+ setIterationCount(iterationCount: InputAnimationOptions["iterationCount"]): this;
70
+ setDuration(duration: InputAnimationOptions["duration"]): this;
71
+ setDelay(delay: InputAnimationOptions["delay"]): this;
72
+ setDirection(direction: InputAnimationOptions["direction"]): this;
73
+ setFillMode(fillMode: InputAnimationOptions["fillMode"]): this;
74
+ setUseWAAPI(useWAAPI: InputAnimationOptions["useWAAPI"]): this;
75
+ setColorSpace(colorSpace: InputAnimationOptions["colorSpace"]): this;
76
+ setHueMethod(hueMethod: InputAnimationOptions["hueMethod"]): this;
77
+ setOptions(options: Partial<InputAnimationOptions>): this;
78
+ reverse(): this;
79
+ fillForwards(): void;
80
+ fillBackwards(): void;
81
+ /**
82
+ * Stateless progress query. Maps [0,1] from first keyframe to last,
83
+ * regardless of playback direction. `apply=true` invokes transform callbacks.
84
+ */
85
+ at(progress: number, apply?: boolean): Record<string, ValueUnit[]>;
86
+ interpFrames(t: number, transformFrames?: boolean): Record<string, ValueUnit<any, string | undefined>[]>;
87
+ onStart(): Promise<void>;
88
+ onEnd(): Promise<void>;
89
+ tick(t: number): Promise<number>;
90
+ draw(t: number): Promise<void>;
91
+ /** Internal rAF-based play loop. */
92
+ private _playRAF;
93
+ /** Play via the Web Animations API for compositor-thread execution. */
94
+ private _playWAAPI;
95
+ play(): Promise<void>;
96
+ pause(draw?: boolean): this;
97
+ resume(): this;
98
+ stop(): void;
99
+ playing(): boolean;
100
+ /** Returns the effective time accounting for direction reversal. */
101
+ get effectiveT(): number;
102
+ reset(): this;
103
+ setTargets(...targets: HTMLElement[]): this;
104
+ group(...animations: Animation_2<V>[]): AnimationGroup<V>;
105
+ }
106
+ export { Animation_2 as Animation }
107
+
108
+ declare interface AnimationFrame<V extends Vars> {
109
+ id: number;
110
+ start: ValueUnit;
111
+ ixs: {
112
+ start: number;
113
+ stop: number;
114
+ };
115
+ time: {
116
+ start: number;
117
+ stop: number;
118
+ };
119
+ flatVars: V;
120
+ vars: V;
121
+ interpVars: {
122
+ [arg: string]: Array<InterpolatedVar<V>>;
123
+ };
124
+ transform: TransformFunction<V>;
125
+ timingFunction: TimingFunction;
126
+ }
127
+
128
+ export declare class AnimationGroup<V extends Vars> {
129
+ animations: AnimationGroupObject<V>;
130
+ transform: TransformFunction<V>;
131
+ superKey: string | undefined;
132
+ paused: boolean;
133
+ started: boolean;
134
+ done: boolean;
135
+ singleTarget: boolean;
136
+ lastTickTime: number;
137
+ handleId: number | any;
138
+ resolvePromise: ((value: void | PromiseLike<void>) => void) | null;
139
+ constructor(...inputs: (Animation_2<V> | AnimationGroupInput<V>)[]);
140
+ setSuperKey(superKey: string): this;
141
+ setTargets(...targets: HTMLElement[]): this;
142
+ onStart(): this;
143
+ onEnd(): this;
144
+ transformFramesGrouped(t: number): Record<string, unknown>;
145
+ tick(t: number): Promise<this>;
146
+ draw(t: number): Promise<void>;
147
+ play(): Promise<unknown>;
148
+ pause(): this;
149
+ reset(): this;
150
+ stop(): this;
151
+ playing(): boolean;
152
+ forcePause(): void;
153
+ forcePlay(): void;
154
+ /** Set layer config for an animation by name or reference. Chainable. */
155
+ setLayerConfig(nameOrAnim: string | Animation_2<V>, config: Partial<AnimationLayerConfig>): this;
156
+ /** Convenience toggle for enabling/disabling a layer. Chainable. */
157
+ setLayerEnabled(nameOrAnim: string | Animation_2<V>, enabled: boolean): this;
158
+ /** Read the layer config for an animation. */
159
+ getLayerConfig(nameOrAnim: string | Animation_2<V>): AnimationLayerConfig | undefined;
160
+ }
161
+
162
+ declare interface AnimationGroupEntry<V extends Vars> {
163
+ animation: Animation_2<V>;
164
+ values: Record<string, unknown>;
165
+ layer: AnimationLayerConfig;
166
+ }
167
+
168
+ /** Input type for AnimationGroup constructor — bare Animation or Animation with layer config. */
169
+ declare type AnimationGroupInput<V extends Vars> = Animation_2<V> | {
170
+ animation: Animation_2<V>;
171
+ layer?: Partial<AnimationLayerConfig>;
172
+ };
173
+
174
+ declare interface AnimationGroupObject<V extends Vars> {
175
+ [key: string]: AnimationGroupEntry<V>;
176
+ }
177
+
178
+ declare interface AnimationLayerConfig {
179
+ /** Higher wins. Default: 0 */
180
+ zIndex: number;
181
+ /** 0–1 for 'weighted' blend mode. Default: 1 */
182
+ weight: number;
183
+ /** Default: 'replace' (backward compat) */
184
+ blendMode: BlendMode;
185
+ /** Layer toggle. Default: true */
186
+ enabled: boolean;
187
+ /** Optional property whitelist — only these properties will be output from this layer */
188
+ properties?: Set<string>;
189
+ }
190
+
191
+ declare type AnimationOptions = {
192
+ duration: number;
193
+ delay: number;
194
+ iterationCount: number;
195
+ direction: (typeof DIRECTIONS)[number];
196
+ fillMode: (typeof FILL_MODES)[number];
197
+ timingFunction: TimingFunction;
198
+ useWAAPI: boolean;
199
+ colorSpace: string;
200
+ hueMethod?: HueInterpolationMethod;
201
+ };
202
+
203
+ export { bezierPresets }
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 }
218
+
219
+ export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V> {
220
+ constructor(options?: Partial<InputAnimationOptions>, ...targets: HTMLElement[]);
221
+ fromVars(vars: V[], transform?: TransformFunction<V>): this;
222
+ fromKeyframes(keyframes: Map<string, Partial<V>> | Record<string, Partial<V>>, transform?: TransformFunction<V>): this;
223
+ fromString(keyframes: string, transform?: TransformFunction<V>): this;
224
+ transform(vars: V): void;
225
+ }
226
+
227
+ declare const DIRECTIONS: readonly ["normal", "reverse", "alternate", "alternate-reverse"];
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 }
242
+
243
+ export { easeInOutQuad }
244
+
245
+ export { easeInOutSine }
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 }
260
+
261
+ export declare class ElementMorph {
262
+ private animation;
263
+ private transformOrigin;
264
+ private timingFunction;
265
+ constructor(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect, options?: ElementMorphOptions);
266
+ /** Re-measure source and destination, rebuilding the internal animation. */
267
+ measure(from: HTMLElement | MorphRect, to: HTMLElement | MorphRect): this;
268
+ /** Get raw transform values at the given progress [0, 1]. */
269
+ at(progress: number): MorphValues;
270
+ /** Get a CSS transform string at the given progress [0, 1]. */
271
+ toCSSTransform(progress: number): string;
272
+ /** Apply the morph transform to an element at the given progress [0, 1]. */
273
+ apply(element: HTMLElement, progress: number): void;
274
+ }
275
+
276
+ export declare interface ElementMorphOptions {
277
+ timingFunction?: TimingFunction | TimingFunctionNames;
278
+ transformOrigin?: string;
279
+ }
280
+
281
+ declare const FILL_MODES: readonly ["none", "forwards", "backwards", "both"];
282
+
283
+ export declare const getAnimationId: (animation: Animation_2 | string) => string;
284
+
285
+ declare type InputAnimationOptions = Partial<{
286
+ duration: number | string;
287
+ delay: number | string;
288
+ iterationCount: number | string | "infinite" | undefined;
289
+ direction: (typeof DIRECTIONS)[number];
290
+ fillMode: (typeof FILL_MODES)[number];
291
+ timingFunction: TimingFunction | TimingFunctionNames | undefined;
292
+ /** When true (default), eligible animations may use the Web Animations API for compositor-thread execution. Set to false to force rAF. */
293
+ useWAAPI: boolean;
294
+ colorSpace?: string;
295
+ hueMethod?: HueInterpolationMethod;
296
+ }>;
297
+
298
+ export { jumpTerms }
299
+
300
+ export { linear }
301
+
302
+ export declare class ManualTimeline extends Timeline {
303
+ private value;
304
+ constructor(options?: TimelineOptions);
305
+ /** Set the raw progress value. */
306
+ set(value: number): void;
307
+ protected sample(): number;
308
+ }
309
+
310
+ export declare interface MorphRect {
311
+ x: number;
312
+ y: number;
313
+ width: number;
314
+ height: number;
315
+ }
316
+
317
+ declare interface MorphValues {
318
+ [key: string]: number;
319
+ translateX: number;
320
+ translateY: number;
321
+ scaleX: number;
322
+ scaleY: number;
323
+ }
324
+
325
+ export declare class NumericAnimation<T extends Record<string, number>> {
326
+ private keyframes;
327
+ private segments;
328
+ private positions;
329
+ private timingFn;
330
+ private result;
331
+ constructor(keyframes: T[], options?: NumericAnimationOptions);
332
+ private buildSegments;
333
+ private buildSegment;
334
+ /** Map [0, 1] progress to interpolated values. Zero allocation. */
335
+ at(progress: number): T;
336
+ /** Update a keyframe's values in-place, recomputing adjacent segments. */
337
+ updateKeyframe(index: number, values: Partial<T>): this;
338
+ }
339
+
340
+ export declare interface NumericAnimationOptions {
341
+ timingFunction?: TimingFunction | TimingFunctionNames | undefined;
342
+ /** Explicit positions as percentages [0-100]. Auto-distributes if omitted. */
343
+ positions?: number[] | undefined;
344
+ }
345
+
346
+ declare type ParsedVarMap = Record<string, ValueArray>;
347
+
348
+ export declare class ScrollTimeline extends Timeline {
349
+ private threshold;
350
+ private getScrollY;
351
+ private getViewportHeight;
352
+ constructor(options?: ScrollTimelineOptions);
353
+ protected sample(): number;
354
+ }
355
+
356
+ export declare interface ScrollTimelineOptions extends TimelineOptions {
357
+ /** Viewport fraction for full progress. Default 0.35. */
358
+ threshold?: number | undefined;
359
+ /** Custom scroll position supplier. Default: window.scrollY. */
360
+ getScrollY?: (() => number) | undefined;
361
+ /** Custom viewport height supplier. Default: window.innerHeight. */
362
+ getViewportHeight?: (() => number) | undefined;
363
+ }
364
+
365
+ export declare class SmoothProgress {
366
+ private options;
367
+ private targetValue;
368
+ private currentValue;
369
+ private isSettled;
370
+ constructor(options?: Partial<SmoothProgressOptions>);
371
+ get target(): number;
372
+ get current(): number;
373
+ get settled(): boolean;
374
+ setTarget(target: number): void;
375
+ /** Advance one step using fixed damping. Returns current value. */
376
+ tick(): number;
377
+ /** Frame-rate independent tick. dt is in milliseconds. */
378
+ tickDt(dt: number): number;
379
+ /** Immediately set current = target. */
380
+ snap(): void;
381
+ /** Reset to a specific value (default 0). */
382
+ reset(value?: number): void;
383
+ }
384
+
385
+ export declare interface SmoothProgressOptions {
386
+ /** Damping factor (0, 1]. Higher = faster convergence. Default 0.1 */
387
+ damping: number;
388
+ /** Snap to target when |target - current| < threshold. Default 0.001 */
389
+ snapThreshold: number;
390
+ /** Starting value. Default 0 */
391
+ initial: number;
392
+ /** Clamp current to [0, 1]. Default true */
393
+ clamp: boolean;
394
+ }
395
+
396
+ export { smoothStep3 }
397
+
398
+ export { stepEnd }
399
+
400
+ export { steppedEase }
401
+
402
+ export { stepStart }
403
+
404
+ declare interface TemplateAnimationFrame<V extends Vars> {
405
+ id: number;
406
+ start: ValueUnit;
407
+ vars: V;
408
+ transform?: TransformFunction<V>;
409
+ timingFunction?: TimingFunction;
410
+ }
411
+
412
+ export declare abstract class Timeline {
413
+ private smoother;
414
+ private easingFn;
415
+ private currentProgress;
416
+ constructor(options?: TimelineOptions);
417
+ /** Subclass returns raw [0,1] progress from its source. */
418
+ protected abstract sample(): number;
419
+ /** Advance one frame. Applies easing -> boundary snap -> smoothing. */
420
+ tick(): number;
421
+ /** Frame-rate independent variant. dt in ms. */
422
+ tickDt(dt: number): number;
423
+ get progress(): number;
424
+ /** True if no smoother or smoother is settled. */
425
+ get settled(): boolean;
426
+ /** Immediately converge smoother to current target. */
427
+ snap(): void;
428
+ /** Reset progress to a specific value (default 0). */
429
+ reset(value?: number): void;
430
+ }
431
+
432
+ export declare interface TimelineOptions {
433
+ easing?: TimingFunction | TimingFunctionNames | undefined;
434
+ /** SmoothProgress config. `false` disables smoothing. Default: enabled. */
435
+ smoothing?: Partial<SmoothProgressOptions> | false | undefined;
436
+ }
437
+
438
+ declare type TimingFunction = (t: number) => number;
439
+
440
+ declare type TimingFunctionNames = keyof typeof timingFunctions;
441
+
442
+ export { timingFunctions }
443
+
444
+ declare type TransformFunction<V extends Vars> = (v: V, t: number) => void;
445
+
446
+ declare type Vars<T = any> = {
447
+ [arg: string]: number | string | T;
448
+ };
449
+
450
+ export { }