@freestylejs/ani-core 1.1.0 → 1.2.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/index.d.ts CHANGED
@@ -46,37 +46,6 @@ interface Coord {
46
46
  y: number;
47
47
  }
48
48
 
49
- declare class LinearTimingFunction extends TimingFunction {
50
- step(time: number, context: TimingFunctionContext): {
51
- value: number;
52
- endOfAnimation: boolean;
53
- };
54
- }
55
-
56
- /** biome-ignore-all lint/style/noMagicNumbers: <>*/
57
-
58
- interface BezierTimingFunctionOpt {
59
- p2: Coord;
60
- p3: Coord;
61
- }
62
- declare class BezierTimingFunction extends TimingFunction {
63
- readonly opt: {
64
- p2: Coord;
65
- p3: Coord;
66
- };
67
- constructor(opt: {
68
- p2: Coord;
69
- p3: Coord;
70
- });
71
- private readonly p1;
72
- private readonly p4;
73
- private _bezierFunction;
74
- step(time: number, context: TimingFunctionContext): {
75
- value: number;
76
- endOfAnimation: boolean;
77
- };
78
- }
79
-
80
49
  interface SpringTimingFunctionOpt {
81
50
  /**
82
51
  * Mass constant.
@@ -119,6 +88,38 @@ declare class DynamicSpringTimingFunction extends TimingFunction {
119
88
  };
120
89
  }
121
90
 
91
+ interface BezierTimingFunctionOpt {
92
+ p2: Coord;
93
+ p3: Coord;
94
+ }
95
+ declare class BezierTimingFunction extends TimingFunction {
96
+ readonly opt: {
97
+ p2: Coord;
98
+ p3: Coord;
99
+ };
100
+ private sampleValues;
101
+ constructor(opt: {
102
+ p2: Coord;
103
+ p3: Coord;
104
+ });
105
+ private calcBezier;
106
+ private getSlope;
107
+ private getTForX;
108
+ private binarySubdivide;
109
+ private newtonRaphsonIterate;
110
+ step(time: number, context: TimingFunctionContext): {
111
+ value: number;
112
+ endOfAnimation: boolean;
113
+ };
114
+ }
115
+
116
+ declare class LinearTimingFunction extends TimingFunction {
117
+ step(time: number, context: TimingFunctionContext): {
118
+ value: number;
119
+ endOfAnimation: boolean;
120
+ };
121
+ }
122
+
122
123
  /**
123
124
  * Core timing functions
124
125
  */
@@ -145,41 +146,158 @@ declare const T: {
145
146
  * Creates linear timing function instance.
146
147
  */
147
148
  readonly linear: () => LinearTimingFunction;
149
+ /**
150
+ * Standard CSS 'ease' timing function (0.25, 0.1, 0.25, 1.0).
151
+ */
152
+ readonly ease: () => BezierTimingFunction;
153
+ /**
154
+ * Standard CSS 'ease-in' timing function (0.42, 0, 1.0, 1.0).
155
+ */
156
+ readonly easeIn: () => BezierTimingFunction;
157
+ /**
158
+ * Standard CSS 'ease-out' timing function (0, 0, 0.58, 1.0).
159
+ */
160
+ readonly easeOut: () => BezierTimingFunction;
161
+ /**
162
+ * Standard CSS 'ease-in-out' timing function (0.42, 0, 0.58, 1.0).
163
+ */
164
+ readonly easeInOut: () => BezierTimingFunction;
148
165
  };
149
166
 
150
- interface Animatable {
167
+ type AnimationId = string;
168
+ type AnimationNodeType = string;
169
+ type AnimationDuration = number;
170
+ /**
171
+ * Nodes in the animation tree
172
+ */
173
+ declare abstract class AnimationNode<G extends Groupable> {
174
+ abstract readonly type: AnimationNodeType;
175
+ abstract readonly duration: AnimationDuration;
176
+ readonly id?: AnimationId;
177
+ constructor(id?: AnimationId);
151
178
  /**
152
- * Update animation based on dt
153
- * @param dt delta time
179
+ * Constructs self node and its children into a flat execution plan.
180
+ * @param plan Execution plans to which segments will be added.
181
+ * @param startTime The absolute current start time for this node within the master timeline.
154
182
  */
155
- update(dt: number): void;
183
+ abstract construct(plan: ExecutionPlan<G>, startTime: number): void;
156
184
  }
185
+ type ExtractAnimationNode<AnimeNode> = AnimeNode extends AnimationNode<infer Group> ? Group : never;
186
+
187
+ type CompositionChildren = readonly AnimationNode<Groupable>[];
188
+ type CompositionPlan<Children extends CompositionChildren> = ExecutionPlan<ExtractAnimationNode<Children[number]>>;
157
189
  /**
158
- * Animation clock interface, can be user-injected.
190
+ * Composition animation
159
191
  */
160
- interface AnimationClockInterface {
161
- subscribe(animatable: Animatable): void;
162
- unsubscribe(animatable: Animatable): void;
163
- }
164
- declare class AnimationClock implements AnimationClockInterface {
165
- private subscribers;
166
- private animationFrameId;
167
- private lastTimestamp;
168
- private maxDeltaTime;
169
- protected static clock: AnimationClock;
192
+ declare abstract class CompositionNode<const Children extends CompositionChildren> extends AnimationNode<ExtractAnimationNode<Children[number]>> {
170
193
  /**
171
- * Crete new clock(singleton)
172
- * @param maxDeltaTime default maxDt = 100ms
173
- * @returns clock
194
+ * Composition children nodes.
174
195
  */
175
- static create(maxDeltaTime?: number): AnimationClock;
176
- private constructor();
177
- subscribe(animatable: Animatable): void;
178
- unsubscribe(animatable: Animatable): void;
179
- private start;
180
- private stop;
181
- private tick;
196
+ readonly children: Children;
197
+ constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
198
+ }
199
+
200
+ interface SegmentNodeProps<G extends Groupable> {
201
+ readonly to: G;
202
+ readonly duration: number;
203
+ readonly timing?: SegmentTiming<G>;
182
204
  }
205
+ /**
206
+ * Leaf node in the animation tree
207
+ */
208
+ declare class SegmentNode<G extends Groupable> extends AnimationNode<G> {
209
+ readonly type = "SEGMENT";
210
+ readonly props: SegmentNodeProps<G>;
211
+ constructor(props: SegmentNodeProps<G>, id?: AnimationId);
212
+ get duration(): number;
213
+ construct(plan: ExecutionPlan<G>, startTime: number): void;
214
+ }
215
+ /**
216
+ * Single animation segment.
217
+ *
218
+ * @param props Animation config.
219
+ * @param id Optional ID for the node.
220
+ */
221
+ declare function ani<G extends Groupable>(props: SegmentNodeProps<G>, id?: AnimationId): SegmentNode<G>;
222
+
223
+ type PreserveRecord = Record<string, any>;
224
+ /**
225
+ * Creates a pause in an animation sequence.
226
+ * @param duration Duration of the delay in `seconds`.
227
+ * @param id Optional ID for the node.
228
+ */
229
+ declare function delay(duration: number, id?: AnimationId): SegmentNode<PreserveRecord>;
230
+
231
+ /**
232
+ * Composition node that repeats a child animation node a specified number of times.
233
+ */
234
+ declare class LoopNode<G extends Groupable> extends CompositionNode<readonly AnimationNode<G>[]> {
235
+ readonly type = "LOOP";
236
+ readonly duration: number;
237
+ readonly count: number;
238
+ readonly child: AnimationNode<G>;
239
+ constructor(child: AnimationNode<G>, loopCount: number, timing?: TimingFunction, id?: AnimationId);
240
+ construct(plan: CompositionPlan<readonly AnimationNode<G>[]>, startTime: number): void;
241
+ }
242
+ /**
243
+ * Create loop for children animation.
244
+ *
245
+ * @param child Target animation node to repeat.
246
+ * @param loopCount Loop count.
247
+ * @param timing Loop timing function.
248
+ * @param id Optional ID for the node.
249
+ */
250
+ declare function loop<G extends Groupable>(child: AnimationNode<G>, loopCount: number, timing?: TimingFunction, id?: AnimationId): LoopNode<G>;
251
+
252
+ /**
253
+ * Composition node that runs all of its children at the same time.
254
+ */
255
+ declare class ParallelNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
256
+ readonly type = "PARALLEL";
257
+ readonly duration: number;
258
+ constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
259
+ construct(plan: CompositionPlan<Children>, startTime: number): void;
260
+ }
261
+ /**
262
+ * Parallel composition animation
263
+ * @param timing Loop timing function.
264
+ * @param id Optional ID for the node.
265
+ */
266
+ declare function parallel<const Children extends CompositionChildren>(children: Children, timing?: TimingFunction, id?: AnimationId): ParallelNode<Children>;
267
+
268
+ /**
269
+ * Composition node that runs its children one after another.
270
+ */
271
+ declare class SequenceNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
272
+ readonly type = "SEQUENCE";
273
+ readonly duration: number;
274
+ constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
275
+ construct(plan: CompositionPlan<Children>, startTime: number): void;
276
+ }
277
+ /**
278
+ * Sequence composition animation
279
+ * @param timing Loop timing function.
280
+ * @param id Optional ID for the node.
281
+ */
282
+ declare function sequence<const Children extends CompositionChildren>(children: Children, timing?: TimingFunction, id?: AnimationId): SequenceNode<Children>;
283
+
284
+ /**
285
+ * Composition node that runs its children with a fixed delay between each start time.
286
+ */
287
+ declare class StaggerNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
288
+ readonly type = "STAGGER";
289
+ readonly duration: number;
290
+ readonly offset: number;
291
+ constructor(children: Children, offset: number, timing?: TimingFunction, id?: AnimationId);
292
+ construct(plan: CompositionPlan<Children>, startTime: number): void;
293
+ }
294
+ /**
295
+ * Stagger composition animation
296
+ * @param offset Children animation offset, in seconds.
297
+ * @param timing Loop timing function.
298
+ * @param id Optional ID for the node.
299
+ */
300
+ declare function stagger<const Children extends CompositionChildren>(children: Children, offset: number, timing?: TimingFunction, id?: AnimationId): StaggerNode<Children>;
183
301
 
184
302
  declare const TransformFunctionMap: {
185
303
  readonly rotate: {
@@ -268,9 +386,6 @@ type WithLiteralRecord<Literal extends string, Value> = {
268
386
  [Key in Literal]?: Value;
269
387
  };
270
388
 
271
- type AnimePrimitive = readonly number[];
272
- type SegmentTiming<G extends Groupable = Groupable> = G extends AnimePrimitive ? readonly TimingFunction[] | TimingFunction : G extends GroupableRecord ? Record<keyof G, TimingFunction> | TimingFunction : never;
273
-
274
389
  /**
275
390
  * Animatable target values
276
391
  */
@@ -293,43 +408,50 @@ interface ExecutionSegment<G extends Groupable> {
293
408
  endTime: number;
294
409
  }
295
410
  type ExecutionPlan<G extends Groupable> = Array<ExecutionSegment<G>>;
296
- type TimelineStatus = 'IDLE' | 'PLAYING' | 'PAUSED' | 'ENDED';
297
- type OnUpdateCallback<G extends Groupable> = (current: {
298
- state: AniGroup<G>;
299
- status: TimelineStatus;
300
- }) => void;
301
- type ShouldKeepSymbol = 'keep';
302
- type Keyframe<G extends Groupable> = Array<G | ShouldKeepSymbol>;
303
- type Duration = Array<number | ShouldKeepSymbol>;
304
- interface TimelineStartingConfig<G extends Groupable, Ctx = any> {
411
+ type AnimePrimitive = readonly number[];
412
+ interface SegmentDefinition {
413
+ from: AnimePrimitive;
414
+ to: AnimePrimitive;
415
+ duration: number;
416
+ timing: SegmentTiming;
417
+ }
418
+ type SegmentTiming<G extends Groupable = Groupable> = G extends AnimePrimitive ? readonly TimingFunction[] | TimingFunction : G extends GroupableRecord ? Record<keyof G, TimingFunction> | TimingFunction : never;
419
+ interface SegmentState {
420
+ values: AnimePrimitive;
421
+ isComplete: boolean;
422
+ }
423
+
424
+ /**
425
+ * Calculates the animated values for a single segment at a specific local time.
426
+ *
427
+ * @param localTime Time elapsed within this specific segment (from 0 to duration).
428
+ * @param segmentDef Target segment def
429
+ * @parma dt Delta time
430
+ * @returns Calculated values and whether the segment is complete.
431
+ */
432
+ declare function calculateSegmentState(localTime: number, segmentDef: SegmentDefinition, dt?: number): SegmentState;
433
+
434
+ interface TimelineCommonConfig<G extends Groupable> {
305
435
  /**
306
436
  * Starting dynamic value.
307
437
  */
308
- from: AniGroup<G>;
438
+ from: G;
309
439
  /**
310
- * Dynamic `from` values, if passed `keep` for specific index, keep original timeline config.
440
+ * Animation repeat count.
311
441
  */
312
- keyframes?: Keyframe<G>;
442
+ repeat?: number;
313
443
  /**
314
- * Dynamic `duration` values, if passed `keep` for specific index, keep original timeline config.
444
+ * Initial delay before animation starts (ms).
315
445
  */
316
- durations?: Duration;
446
+ delay?: number;
317
447
  /**
318
- * Custom context definition during animation cycle.
448
+ * Dynamic target overrides. Matches the order of SEGMENT nodes in the plan.
319
449
  */
320
- context?: Ctx;
450
+ keyframes?: Array<G | 'keep'>;
321
451
  /**
322
- * Animation repeat count.
323
- *
324
- * - if `Infinity` goes infinity repeat
452
+ * Dynamic duration overrides. Matches the order of SEGMENT nodes in the plan.
325
453
  */
326
- repeat?: number;
327
- /**
328
- * Initial delay before animation starts.
329
- *
330
- * - unit = `MS`
331
- */
332
- delay?: number;
454
+ durations?: Array<number | 'keep'>;
333
455
  /**
334
456
  * Custom style property resolver.
335
457
  *
@@ -345,226 +467,147 @@ interface TimelineStartingConfig<G extends Groupable, Ctx = any> {
345
467
  */
346
468
  propertyResolver?: G extends AnimePrimitive ? never : Resolver<G>;
347
469
  }
348
- /**
349
- * Public timeline controller
350
- */
351
- interface TimelineController<G extends Groupable, Ctx = any> {
470
+ declare abstract class TimelineBase<G extends Groupable> {
471
+ protected readonly rootNode: AnimationNode<G>;
472
+ readonly duration: number;
473
+ protected readonly _baseExecutionPlan: ExecutionPlan<G>;
474
+ protected _currentExecutionPlan: ExecutionPlan<G> | null;
475
+ constructor(rootNode: AnimationNode<G>);
352
476
  /**
353
- * Play timeline
354
- * @param config Timeline starting configuration
355
- * @param canBeIntercepted if `true`, will play animation again even if already PLAYING.
477
+ * flatten the AST into a linear execution plan.
356
478
  */
357
- play(config: TimelineStartingConfig<G, Ctx>, canBeIntercepted?: boolean): void;
479
+ private _constructExecutionPlan;
358
480
  /**
359
- * Pause timeline
481
+ * Merges the base plan with runtime dynamic overrides.
360
482
  */
361
- pause(): void;
483
+ protected _resolveExecutionPlan(keyframes?: Array<G | 'keep'>, durations?: Array<number | 'keep'>): ExecutionPlan<G>;
484
+ abstract play(...args: unknown[]): void;
362
485
  /**
363
- * Resume timeline
486
+ * Pause animation.
364
487
  */
365
- resume(): void;
488
+ abstract pause(): void;
366
489
  /**
367
- * Seek to target time
368
- * @param time
490
+ * Resume animation.
369
491
  */
370
- seek(time: number): void;
492
+ abstract resume(): void;
371
493
  /**
372
- * Reset timeline
494
+ * Reset(cancel) animation.
373
495
  */
374
- reset(): void;
496
+ abstract reset(): void;
497
+ /**
498
+ * Seek to specific target time.
499
+ * @param targetTime Target seek time.
500
+ */
501
+ abstract seek(targetTime: number): void;
375
502
  }
376
- declare class Timeline<G extends Groupable, Ctx = any> implements TimelineController<G, Ctx>, Animatable {
503
+
504
+ interface Animatable {
377
505
  /**
378
- * Animation construction root node.
506
+ * Update animation based on dt
507
+ * @param dt delta time
379
508
  */
380
- protected readonly rootNode: AnimationNode<G>;
381
- readonly duration: number;
382
- private readonly _baseExecutionPlan;
383
- private _currentExecutionPlan;
509
+ update(dt: number): void;
510
+ }
511
+ /**
512
+ * Animation clock interface, can be user-injected.
513
+ */
514
+ interface AnimationClockInterface {
515
+ subscribe(animatable: Animatable): void;
516
+ unsubscribe(animatable: Animatable): void;
517
+ }
518
+ declare class AnimationClock implements AnimationClockInterface {
519
+ private subscribers;
520
+ private animationFrameId;
521
+ private lastTimestamp;
522
+ private maxDeltaTime;
523
+ protected static clock: AnimationClock;
524
+ /**
525
+ * Crete new clock(singleton)
526
+ * @param maxDeltaTime default maxDt = 100ms
527
+ * @returns clock
528
+ */
529
+ static create(maxDeltaTime?: number): AnimationClock;
530
+ private constructor();
531
+ subscribe(animatable: Animatable): void;
532
+ unsubscribe(animatable: Animatable): void;
533
+ private start;
534
+ private stop;
535
+ private tick;
536
+ }
537
+
538
+ interface RafTimelineConfig<G extends Groupable, Ctx = any> extends TimelineCommonConfig<G> {
539
+ /**
540
+ * Custom context definition during animation cycle.
541
+ */
542
+ context?: Ctx;
543
+ }
544
+ type TimelineStatus = 'IDLE' | 'PLAYING' | 'PAUSED' | 'ENDED';
545
+ type OnUpdateCallback<G extends Groupable> = (current: {
546
+ /**
547
+ * Current animation state
548
+ */
549
+ state: AniGroup<G>;
550
+ /**
551
+ * Current animation status
552
+ */
553
+ status: TimelineStatus;
554
+ }) => void;
555
+ declare class RafAniTimeline<G extends Groupable, Ctx = any> extends TimelineBase<G> implements Animatable {
384
556
  private readonly _clock;
385
557
  private _masterTime;
386
558
  private _delay;
387
559
  private _status;
388
560
  private _currentConfig;
389
- /**
390
- * Current animation running config.
391
- */
392
- get currentConfig(): TimelineStartingConfig<G, Ctx> | null;
561
+ get currentConfig(): RafTimelineConfig<G, Ctx> | null;
393
562
  private _state;
394
563
  private _initialState;
395
564
  private _repeatCount;
396
565
  private _propertyKeyMap;
397
- private _segmentStartStates;
398
566
  private _onUpdateCallbacks;
399
- constructor(
400
- /**
401
- * Animation construction root node.
402
- */
403
- rootNode: AnimationNode<G>, clock?: AnimationClockInterface);
404
- /**
405
- * Resolves a Group (like {x, y}) into keys and values.
406
- */
407
- private _resolveGroup;
408
- /**
409
- * Resolves the internal state (a number array) back into Group.
410
- */
411
- private _resolveStateToGroup;
567
+ constructor(rootNode: AnimationNode<G>, clock?: AnimationClockInterface);
568
+ getCurrentValue(): AniGroup<G> | null;
569
+ private _calculateStateAtTime;
570
+ private notify;
412
571
  /**
413
- * Compile animation execution plan
572
+ * @private Internal clock subscription callback.
414
573
  */
415
- private _constructExecutionPlan;
574
+ update(dt: number): void;
416
575
  /**
417
- * Calculates the exact state of the animation at point.
576
+ * Plays animation.
577
+ * @param config {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame RequestAnimationFrame API} based config.
578
+ * @param canBeIntercepted if `true` animation can be intercepted even if already animation started.
418
579
  */
419
- private _calculateStateAtTime;
420
- private _resolveExecutionPlan;
421
- private notify;
422
- play(config: TimelineStartingConfig<G, Ctx>, canBeIntercepted?: boolean): void;
580
+ play(config: RafTimelineConfig<G, Ctx>, canBeIntercepted?: boolean): void;
423
581
  pause(): void;
424
582
  resume(): void;
425
- reset(notify?: boolean): void;
583
+ reset(notify?: boolean, unsubscribeClock?: boolean): void;
426
584
  seek(targetTime: number): void;
427
- getCurrentValue(): AniGroup<G> | null;
428
- onUpdate(callback: OnUpdateCallback<G>): () => void;
429
- update(dt: number): void;
430
- }
431
- declare function timeline<G extends Groupable, Ctx = any>(rootNode: AnimationNode<G>, clock?: AnimationClockInterface): Timeline<G, Ctx>;
432
-
433
- type AnimationId = string;
434
- type AnimationNodeType = string;
435
- type AnimationDuration = number;
436
- /**
437
- * Nodes in the animation tree
438
- */
439
- declare abstract class AnimationNode<G extends Groupable> {
440
- abstract readonly type: AnimationNodeType;
441
- abstract readonly duration: AnimationDuration;
442
- readonly id?: AnimationId;
443
- constructor(id?: AnimationId);
444
- /**
445
- * Constructs self node and its children into a flat execution plan.
446
- * @param plan Execution plans to which segments will be added.
447
- * @param startTime The absolute current start time for this node within the master timeline.
448
- */
449
- abstract construct(plan: ExecutionPlan<G>, startTime: number): void;
450
- }
451
- type ExtractAnimationNode<AnimeNode> = AnimeNode extends AnimationNode<infer Group> ? Group : never;
452
-
453
- type CompositionChildren = readonly AnimationNode<Groupable>[];
454
- type CompositionPlan<Children extends CompositionChildren> = ExecutionPlan<ExtractAnimationNode<Children[number]>>;
455
- /**
456
- * Composition animation
457
- */
458
- declare abstract class CompositionNode<const Children extends CompositionChildren> extends AnimationNode<ExtractAnimationNode<Children[number]>> {
459
585
  /**
460
- * Composition children nodes.
586
+ * When timeline updates, subscribes on update callback.
587
+ * @param callback Subscription callback.
588
+ * @returns Unsubscribe.
461
589
  */
462
- readonly children: Children;
463
- constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
464
- }
465
-
466
- interface SegmentNodeProps<G extends Groupable> {
467
- readonly to: G;
468
- readonly duration: number;
469
- readonly timing?: SegmentTiming<G>;
470
- }
471
- /**
472
- * Leaf node in the animation tree
473
- */
474
- declare class SegmentNode<G extends Groupable> extends AnimationNode<G> {
475
- readonly type = "SEGMENT";
476
- readonly props: SegmentNodeProps<G>;
477
- constructor(props: SegmentNodeProps<G>, id?: AnimationId);
478
- get duration(): number;
479
- construct(plan: ExecutionPlan<G>, startTime: number): void;
480
- }
481
- /**
482
- * Factory function to create a ani SegmentNode.
483
- */
484
- declare function ani<G extends Groupable>(props: SegmentNodeProps<G>, id?: AnimationId): SegmentNode<G>;
485
-
486
- type PreserveRecord = Record<string, any>;
487
- /**
488
- * Creates a pause in an animation sequence.
489
- * @param duration The duration of the delay in seconds.
490
- * @param id Optional ID for the node.
491
- */
492
- declare function delay(duration: number, id?: AnimationId): SegmentNode<PreserveRecord>;
493
-
494
- /**
495
- * Composition node that repeats a child animation node a specified number of times.
496
- */
497
- declare class LoopNode<G extends Groupable> extends CompositionNode<readonly AnimationNode<G>[]> {
498
- readonly type = "LOOP";
499
- readonly duration: number;
500
- readonly count: number;
501
- readonly child: AnimationNode<G>;
502
- constructor(child: AnimationNode<G>, loopCount: number, timing?: TimingFunction, id?: AnimationId);
503
- construct(plan: CompositionPlan<readonly AnimationNode<G>[]>, startTime: number): void;
504
- }
505
- /**
506
- * Repeats a child animation node a specified number of times.
507
- * @param child The animation node to repeat.
508
- * @param loopCount The number of times to repeat the child node.
509
- * @param timing loop timing function.
510
- * @param id Optional ID for the node.
511
- */
512
- declare function loop<G extends Groupable>(child: AnimationNode<G>, loopCount: number, timing?: TimingFunction, id?: AnimationId): LoopNode<G>;
513
-
514
- /**
515
- * Composition node that runs all of its children at the same time.
516
- */
517
- declare class ParallelNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
518
- readonly type = "PARALLEL";
519
- readonly duration: number;
520
- constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
521
- construct(plan: CompositionPlan<Children>, startTime: number): void;
522
- }
523
- /**
524
- * Parallel composition animation
525
- */
526
- declare function parallel<const Children extends CompositionChildren>(children: Children, timing?: TimingFunction, id?: AnimationId): ParallelNode<Children>;
527
-
528
- /**
529
- * Composition node that runs its children one after another.
530
- */
531
- declare class SequenceNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
532
- readonly type = "SEQUENCE";
533
- readonly duration: number;
534
- constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
535
- construct(plan: CompositionPlan<Children>, startTime: number): void;
536
- }
537
- /**
538
- * Sequence composition animation
539
- */
540
- declare function sequence<const Children extends CompositionChildren>(children: Children, timing?: TimingFunction, id?: AnimationId): SequenceNode<Children>;
541
-
542
- interface StaggerNodeProps {
543
- offset: number;
544
- timing?: TimingFunction;
545
- }
546
- /**
547
- * Composition node that runs its children with a fixed delay between each start time.
548
- */
549
- declare class StaggerNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
550
- readonly type = "STAGGER";
551
- readonly duration: number;
552
- readonly offset: number;
553
- constructor(children: Children, props: StaggerNodeProps, id?: AnimationId);
554
- construct(plan: CompositionPlan<Children>, startTime: number): void;
590
+ onUpdate(callback: OnUpdateCallback<G>): () => void;
555
591
  }
556
592
  /**
557
- * Stagger composition animation
593
+ * Create dynamic timeline. {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame RequestAnimationFrame API} based.
594
+ * @param rootNode Root animation node.
595
+ * @param clock [Custom clock]
558
596
  */
559
- declare function stagger<const Children extends CompositionChildren>(children: Children, props: StaggerNodeProps, id?: AnimationId): StaggerNode<Children>;
597
+ declare function rafTimeline<G extends Groupable, Ctx = any>(rootNode: AnimationNode<G>, clock?: AnimationClockInterface): RafAniTimeline<G, Ctx>;
560
598
 
561
599
  type AnimationStateShape = Record<string, AnimationNode<Groupable>>;
562
- type GetTimeline<State extends AnimationStateShape> = Timeline<ExtractAnimationNode<State[keyof State]>, any>;
600
+ type GetTimeline<State extends AnimationStateShape> = RafAniTimeline<ExtractAnimationNode<State[keyof State]>, any>;
601
+ type TimelineChangeCallback<AnimationStates extends AnimationStateShape> = (timeline: GetTimeline<AnimationStates>) => void;
563
602
  interface StateController<AnimationStates extends AnimationStateShape> {
564
603
  /**
565
604
  * Get current timeline.
566
605
  */
567
606
  timeline: () => GetTimeline<AnimationStates>;
607
+ /**
608
+ * Get current state.
609
+ */
610
+ state: () => keyof AnimationStates;
568
611
  /**
569
612
  * Transition timeline animation into another state.
570
613
  * @param newState transition target.
@@ -572,13 +615,13 @@ interface StateController<AnimationStates extends AnimationStateShape> {
572
615
  * @param timelineConfig animation play config.
573
616
  * @param canBeIntercepted animation canBeIntercepted config.
574
617
  */
575
- transitionTo(newState: keyof AnimationStates, timelineConfig?: TimelineStartingConfig<ExtractAnimationNode<AnimationStates[keyof AnimationStates]>, any>, canBeIntercepted?: boolean): void;
618
+ transitionTo(newState: keyof AnimationStates, timelineConfig?: RafTimelineConfig<ExtractAnimationNode<AnimationStates[keyof AnimationStates]>, any>, canBeIntercepted?: boolean): void;
576
619
  /**
577
620
  * Subscribe to timeline changes.
578
621
  * @param callback
579
622
  * @returns unsubscribe function
580
623
  */
581
- onTimelineChange(callback: (newTimeline: GetTimeline<AnimationStates>) => void): () => void;
624
+ onTimelineChange(callback: TimelineChangeCallback<AnimationStates>): () => void;
582
625
  }
583
626
  interface StateProps<AnimationStates extends AnimationStateShape> {
584
627
  /**
@@ -607,6 +650,52 @@ interface StateProps<AnimationStates extends AnimationStateShape> {
607
650
  */
608
651
  declare function createStates<AnimationStates extends AnimationStateShape>(config: StateProps<AnimationStates>): StateController<AnimationStates>;
609
652
 
653
+ interface WebAniKeyframe extends Record<string, string | number | null> {
654
+ offset: number;
655
+ easing?: string;
656
+ }
657
+ /**
658
+ * Compiles an ExecutionPlan into WAAPI Keyframes.
659
+ * @param plan The resolved execution plan (from TimelineBase).
660
+ * @param initialFrom The initial state (values).
661
+ */
662
+ declare function compileToKeyframes<G extends Groupable>(plan: ExecutionPlan<G>, initialFrom: G): WebAniKeyframe[];
663
+
664
+ interface WebAniTimelineConfig<G extends Groupable> extends TimelineCommonConfig<G> {
665
+ /**
666
+ * Web Animations API config.
667
+ *
668
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options KeyframeEffect Options}.
669
+ */
670
+ keyframeEffect?: Omit<KeyframeEffectOptions, 'duration' | 'iterations' | 'delay'>;
671
+ }
672
+ declare class WebAniTimeline<G extends Groupable> extends TimelineBase<G> {
673
+ private _animation;
674
+ private _keyframes;
675
+ constructor(rootNode: AnimationNode<G>);
676
+ /**
677
+ * Plays animation.
678
+ * @param target Target element.
679
+ * @param config {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API Web Animations API} based config.
680
+ */
681
+ play(target: Element, config: WebAniTimelineConfig<G>): Animation | null;
682
+ pause(): void;
683
+ resume(): void;
684
+ reset(): void;
685
+ seek(targetTime: number): void;
686
+ /**
687
+ * Native animation object.
688
+ *
689
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Animation Animation}.
690
+ */
691
+ get nativeAnimation(): Animation | null;
692
+ }
693
+ /**
694
+ * Create web timeline. {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API Web Animations API} based.
695
+ * @param rootNode Root animation node.
696
+ */
697
+ declare function webTimeline<G extends Groupable>(rootNode: AnimationNode<G>): WebAniTimeline<G>;
698
+
610
699
  type EventHandler<AnimationContext = any, EvtKeys extends EventKey = EventKey> = (animationContext: AnimationContext, ev: HTMLElementEventMap[EvtKeys]) => any;
611
700
  type EventHandlerRegistration<AnimationContext = any, Keys extends EventKey = EventKey> = PartialRecord<WithPrefix<'on', Capitalize<Keys>>, EventHandler<AnimationContext, Keys>>;
612
701
  type EventKey = keyof HTMLElementEventMap;
@@ -632,17 +721,17 @@ declare class EventManager<SupportedEventList extends readonly EventKey[] = Even
632
721
  bind(element: HTMLElement): void;
633
722
  }
634
723
 
635
- type AniRefContext<G extends Groupable> = TimelineController<G> & {
724
+ type AniRefContext<G extends Groupable> = TimelineBase<G> & {
636
725
  /**
637
726
  * Current animation value
638
727
  */
639
728
  current: AniGroup<G> | null;
640
729
  };
641
- interface AniRefProps<G extends Groupable, AsGetter extends boolean = false> {
730
+ interface AniRefProps<Timeline extends TimelineBase<G>, G extends Groupable, AsGetter extends boolean = false> {
642
731
  /**
643
732
  * The compositional timeline to bind to the element.
644
733
  */
645
- timeline: AsGetter extends true ? () => Timeline<G> : Timeline<G>;
734
+ timeline: AsGetter extends true ? () => Timeline : Timeline;
646
735
  /**
647
736
  * The initial style to apply to the element before the animation plays.
648
737
  */
@@ -665,15 +754,26 @@ declare const a: {
665
754
  readonly spring: (opt: SpringTimingFunctionOpt) => SpringTimingFunction;
666
755
  readonly dynamicSpring: (opt: SpringTimingFunctionOpt) => DynamicSpringTimingFunction;
667
756
  readonly linear: () => LinearTimingFunction;
757
+ readonly ease: () => BezierTimingFunction;
758
+ readonly easeIn: () => BezierTimingFunction;
759
+ readonly easeOut: () => BezierTimingFunction;
760
+ readonly easeInOut: () => BezierTimingFunction;
668
761
  };
762
+ readonly dynamicTimeline: typeof rafTimeline;
763
+ readonly timeline: typeof webTimeline;
764
+ /**
765
+ * Create animation segment.
766
+ */
669
767
  readonly ani: typeof ani;
670
- readonly createStates: typeof createStates;
768
+ /**
769
+ * Add delay
770
+ */
671
771
  readonly delay: typeof delay;
672
772
  readonly loop: typeof loop;
673
773
  readonly parallel: typeof parallel;
674
774
  readonly sequence: typeof sequence;
675
775
  readonly stagger: typeof stagger;
676
- readonly timeline: typeof timeline;
776
+ readonly createStates: typeof createStates;
677
777
  };
678
778
 
679
- export { type AniGroup, type AniRefContext, type AniRefProps, type Animatable, AnimationClock, type AnimationClockInterface, type AnimationDuration, type AnimationId, AnimationNode, type AnimationNodeType, type AnimationStateShape, CompositionNode, type Coord, type EventHandler, type EventHandlerRegistration, type EventKey, EventManager, type ExecutionPlan, type ExecutionSegment, type GetTimeline, type Groupable, type GroupableRecord, type GroupableRecordKey, LinearTimingFunction, type OnUpdateCallback, ParallelNode, type Resolver, SegmentNode, SequenceNode, StaggerNode, type StateController, type StateProps, type StylesheetSupportedLiteral, T, Timeline, type TimelineController, type TimelineStartingConfig, TimingFunction, type TimingFunctionContext, a, ani, createStates, createStyleSheet, delay, loop, parallel, sequence, stagger, timeline };
779
+ export { type AniGroup, type AniRefContext, type AniRefProps, type Animatable, AnimationClock, type AnimationClockInterface, type AnimationStateShape, type AnimePrimitive, BezierTimingFunction, type BezierTimingFunctionOpt, type Coord, type EventHandler, type EventHandlerRegistration, type EventKey, EventManager, type ExecutionPlan, type ExecutionSegment, type GetTimeline, type Groupable, type GroupableRecord, type GroupableRecordKey, LinearTimingFunction, type OnUpdateCallback, RafAniTimeline, type RafTimelineConfig, type Resolver, type SegmentDefinition, type SegmentState, type SegmentTiming, type StateController, type StateProps, type StylesheetSupportedLiteral, T, TimelineBase, type TimelineCommonConfig, TimingFunction, type TimingFunctionContext, type WebAniKeyframe, WebAniTimeline, type WebAniTimelineConfig, a, calculateSegmentState, compileToKeyframes, createStates, createStyleSheet, rafTimeline, webTimeline };