@freestylejs/ani-core 1.0.0 → 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.
- package/dist/index.cjs +753 -383
- package/dist/index.d.cts +389 -263
- package/dist/index.d.ts +389 -263
- package/dist/index.js +745 -369
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -46,14 +46,47 @@ interface Coord {
|
|
|
46
46
|
y: number;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
interface SpringTimingFunctionOpt {
|
|
50
|
+
/**
|
|
51
|
+
* Mass constant.
|
|
52
|
+
*/
|
|
53
|
+
m: number;
|
|
54
|
+
/**
|
|
55
|
+
* Spring constant.
|
|
56
|
+
*/
|
|
57
|
+
k: number;
|
|
58
|
+
/**
|
|
59
|
+
* Damping constant.
|
|
60
|
+
*/
|
|
61
|
+
c: number;
|
|
62
|
+
/**
|
|
63
|
+
* End of spring animation threshold.
|
|
64
|
+
* @default 1e-3
|
|
65
|
+
*/
|
|
66
|
+
tolerance?: number;
|
|
67
|
+
}
|
|
68
|
+
declare class SpringTimingFunction extends TimingFunction {
|
|
69
|
+
readonly opt: SpringTimingFunctionOpt;
|
|
70
|
+
constructor(opt: SpringTimingFunctionOpt);
|
|
50
71
|
step(time: number, context: TimingFunctionContext): {
|
|
51
72
|
value: number;
|
|
52
73
|
endOfAnimation: boolean;
|
|
53
74
|
};
|
|
54
75
|
}
|
|
55
76
|
|
|
56
|
-
|
|
77
|
+
declare class DynamicSpringTimingFunction extends TimingFunction {
|
|
78
|
+
readonly opt: SpringTimingFunctionOpt;
|
|
79
|
+
constructor(opt: SpringTimingFunctionOpt);
|
|
80
|
+
private currentValue;
|
|
81
|
+
private currentVelocity;
|
|
82
|
+
private isInitialized;
|
|
83
|
+
init(startValue: number): void;
|
|
84
|
+
private getDerivatives;
|
|
85
|
+
step(_time: number, context: TimingFunctionContext): {
|
|
86
|
+
value: number;
|
|
87
|
+
endOfAnimation: boolean;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
57
90
|
|
|
58
91
|
interface BezierTimingFunctionOpt {
|
|
59
92
|
p2: Coord;
|
|
@@ -64,41 +97,23 @@ declare class BezierTimingFunction extends TimingFunction {
|
|
|
64
97
|
p2: Coord;
|
|
65
98
|
p3: Coord;
|
|
66
99
|
};
|
|
100
|
+
private sampleValues;
|
|
67
101
|
constructor(opt: {
|
|
68
102
|
p2: Coord;
|
|
69
103
|
p3: Coord;
|
|
70
104
|
});
|
|
71
|
-
private
|
|
72
|
-
private
|
|
73
|
-
private
|
|
105
|
+
private calcBezier;
|
|
106
|
+
private getSlope;
|
|
107
|
+
private getTForX;
|
|
108
|
+
private binarySubdivide;
|
|
109
|
+
private newtonRaphsonIterate;
|
|
74
110
|
step(time: number, context: TimingFunctionContext): {
|
|
75
111
|
value: number;
|
|
76
112
|
endOfAnimation: boolean;
|
|
77
113
|
};
|
|
78
114
|
}
|
|
79
115
|
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Mass constant.
|
|
83
|
-
*/
|
|
84
|
-
m: number;
|
|
85
|
-
/**
|
|
86
|
-
* Spring constant.
|
|
87
|
-
*/
|
|
88
|
-
k: number;
|
|
89
|
-
/**
|
|
90
|
-
* Damping constant.
|
|
91
|
-
*/
|
|
92
|
-
c: number;
|
|
93
|
-
/**
|
|
94
|
-
* End of spring animation threshold.
|
|
95
|
-
* @default 1e-3
|
|
96
|
-
*/
|
|
97
|
-
tolerance?: number;
|
|
98
|
-
}
|
|
99
|
-
declare class SpringTimingFunction extends TimingFunction {
|
|
100
|
-
readonly opt: SpringTimingFunctionOpt;
|
|
101
|
-
constructor(opt: SpringTimingFunctionOpt);
|
|
116
|
+
declare class LinearTimingFunction extends TimingFunction {
|
|
102
117
|
step(time: number, context: TimingFunctionContext): {
|
|
103
118
|
value: number;
|
|
104
119
|
endOfAnimation: boolean;
|
|
@@ -113,55 +128,176 @@ declare const T: {
|
|
|
113
128
|
* Creates a new Bezier timing function instance.
|
|
114
129
|
*
|
|
115
130
|
* @param {Bezier.BezierTimingFunctionOpt} opt - Options for configuring the Bezier curve.
|
|
116
|
-
* A new instance of BezierTimingFunction.
|
|
117
131
|
*/
|
|
118
132
|
readonly bezier: (opt: BezierTimingFunctionOpt) => BezierTimingFunction;
|
|
119
133
|
/**
|
|
120
134
|
* Creates a new Spring timing function instance.
|
|
121
135
|
*
|
|
122
|
-
* @param {
|
|
123
|
-
* A new instance of SpringTimingFunction.
|
|
136
|
+
* @param {SpringTimingFunctionOpt} opt - Options for configuring the Spring timing function.
|
|
124
137
|
*/
|
|
125
138
|
readonly spring: (opt: SpringTimingFunctionOpt) => SpringTimingFunction;
|
|
139
|
+
/**
|
|
140
|
+
* Creates a new Dynamic Spring timing function instance.
|
|
141
|
+
*
|
|
142
|
+
* @param SpringTimingFunctionOpt} opt - Options for configuring the Spring timing function.
|
|
143
|
+
*/
|
|
144
|
+
readonly dynamicSpring: (opt: SpringTimingFunctionOpt) => DynamicSpringTimingFunction;
|
|
126
145
|
/**
|
|
127
146
|
* Creates linear timing function instance.
|
|
128
147
|
*/
|
|
129
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;
|
|
130
165
|
};
|
|
131
166
|
|
|
132
|
-
|
|
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);
|
|
133
178
|
/**
|
|
134
|
-
*
|
|
135
|
-
* @param
|
|
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.
|
|
136
182
|
*/
|
|
137
|
-
|
|
183
|
+
abstract construct(plan: ExecutionPlan<G>, startTime: number): void;
|
|
138
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]>>;
|
|
139
189
|
/**
|
|
140
|
-
*
|
|
190
|
+
* Composition animation
|
|
141
191
|
*/
|
|
142
|
-
|
|
143
|
-
subscribe(animatable: Animatable): void;
|
|
144
|
-
unsubscribe(animatable: Animatable): void;
|
|
145
|
-
}
|
|
146
|
-
declare class AnimationClock implements AnimationClockInterface {
|
|
147
|
-
private subscribers;
|
|
148
|
-
private animationFrameId;
|
|
149
|
-
private lastTimestamp;
|
|
150
|
-
private maxDeltaTime;
|
|
151
|
-
protected static clock: AnimationClock;
|
|
192
|
+
declare abstract class CompositionNode<const Children extends CompositionChildren> extends AnimationNode<ExtractAnimationNode<Children[number]>> {
|
|
152
193
|
/**
|
|
153
|
-
*
|
|
154
|
-
* @param maxDeltaTime default maxDt = 100ms
|
|
155
|
-
* @returns clock
|
|
194
|
+
* Composition children nodes.
|
|
156
195
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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>;
|
|
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;
|
|
164
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>;
|
|
165
301
|
|
|
166
302
|
declare const TransformFunctionMap: {
|
|
167
303
|
readonly rotate: {
|
|
@@ -250,9 +386,6 @@ type WithLiteralRecord<Literal extends string, Value> = {
|
|
|
250
386
|
[Key in Literal]?: Value;
|
|
251
387
|
};
|
|
252
388
|
|
|
253
|
-
type AnimePrimitive = readonly number[];
|
|
254
|
-
type SegmentTiming = TimingFunction | readonly TimingFunction[];
|
|
255
|
-
|
|
256
389
|
/**
|
|
257
390
|
* Animatable target values
|
|
258
391
|
*/
|
|
@@ -275,37 +408,50 @@ interface ExecutionSegment<G extends Groupable> {
|
|
|
275
408
|
endTime: number;
|
|
276
409
|
}
|
|
277
410
|
type ExecutionPlan<G extends Groupable> = Array<ExecutionSegment<G>>;
|
|
278
|
-
type
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
type
|
|
286
|
-
interface
|
|
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> {
|
|
287
435
|
/**
|
|
288
436
|
* Starting dynamic value.
|
|
289
437
|
*/
|
|
290
|
-
from:
|
|
438
|
+
from: G;
|
|
291
439
|
/**
|
|
292
|
-
*
|
|
440
|
+
* Animation repeat count.
|
|
293
441
|
*/
|
|
294
|
-
|
|
442
|
+
repeat?: number;
|
|
295
443
|
/**
|
|
296
|
-
*
|
|
444
|
+
* Initial delay before animation starts (ms).
|
|
297
445
|
*/
|
|
298
|
-
|
|
446
|
+
delay?: number;
|
|
299
447
|
/**
|
|
300
|
-
*
|
|
448
|
+
* Dynamic target overrides. Matches the order of SEGMENT nodes in the plan.
|
|
301
449
|
*/
|
|
302
|
-
|
|
450
|
+
keyframes?: Array<G | 'keep'>;
|
|
303
451
|
/**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* - if `Infinity` goes infinity repeat
|
|
452
|
+
* Dynamic duration overrides. Matches the order of SEGMENT nodes in the plan.
|
|
307
453
|
*/
|
|
308
|
-
|
|
454
|
+
durations?: Array<number | 'keep'>;
|
|
309
455
|
/**
|
|
310
456
|
* Custom style property resolver.
|
|
311
457
|
*
|
|
@@ -321,225 +467,147 @@ interface TimelineStartingConfig<G extends Groupable, Ctx = any> {
|
|
|
321
467
|
*/
|
|
322
468
|
propertyResolver?: G extends AnimePrimitive ? never : Resolver<G>;
|
|
323
469
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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>);
|
|
328
476
|
/**
|
|
329
|
-
*
|
|
330
|
-
* @param config Timeline starting configuration
|
|
331
|
-
* @param canBeIntercepted if `true`, will play animation again even if already PLAYING.
|
|
477
|
+
* flatten the AST into a linear execution plan.
|
|
332
478
|
*/
|
|
333
|
-
|
|
479
|
+
private _constructExecutionPlan;
|
|
334
480
|
/**
|
|
335
|
-
*
|
|
481
|
+
* Merges the base plan with runtime dynamic overrides.
|
|
336
482
|
*/
|
|
337
|
-
|
|
483
|
+
protected _resolveExecutionPlan(keyframes?: Array<G | 'keep'>, durations?: Array<number | 'keep'>): ExecutionPlan<G>;
|
|
484
|
+
abstract play(...args: unknown[]): void;
|
|
338
485
|
/**
|
|
339
|
-
*
|
|
486
|
+
* Pause animation.
|
|
340
487
|
*/
|
|
341
|
-
|
|
488
|
+
abstract pause(): void;
|
|
342
489
|
/**
|
|
343
|
-
*
|
|
344
|
-
* @param time
|
|
490
|
+
* Resume animation.
|
|
345
491
|
*/
|
|
346
|
-
|
|
492
|
+
abstract resume(): void;
|
|
347
493
|
/**
|
|
348
|
-
* Reset
|
|
494
|
+
* Reset(cancel) animation.
|
|
349
495
|
*/
|
|
350
|
-
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;
|
|
351
502
|
}
|
|
352
|
-
|
|
503
|
+
|
|
504
|
+
interface Animatable {
|
|
353
505
|
/**
|
|
354
|
-
*
|
|
506
|
+
* Update animation based on dt
|
|
507
|
+
* @param dt delta time
|
|
355
508
|
*/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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 {
|
|
360
556
|
private readonly _clock;
|
|
361
557
|
private _masterTime;
|
|
558
|
+
private _delay;
|
|
362
559
|
private _status;
|
|
363
560
|
private _currentConfig;
|
|
364
|
-
|
|
365
|
-
* Current animation running config.
|
|
366
|
-
*/
|
|
367
|
-
get currentConfig(): TimelineStartingConfig<G, Ctx> | null;
|
|
561
|
+
get currentConfig(): RafTimelineConfig<G, Ctx> | null;
|
|
368
562
|
private _state;
|
|
369
563
|
private _initialState;
|
|
370
564
|
private _repeatCount;
|
|
371
565
|
private _propertyKeyMap;
|
|
372
|
-
private _segmentStartStates;
|
|
373
566
|
private _onUpdateCallbacks;
|
|
374
|
-
constructor(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
rootNode: AnimationNode<G>, clock?: AnimationClockInterface);
|
|
379
|
-
/**
|
|
380
|
-
* Resolves a Group (like {x, y}) into keys and values.
|
|
381
|
-
*/
|
|
382
|
-
private _resolveGroup;
|
|
383
|
-
/**
|
|
384
|
-
* Resolves the internal state (a number array) back into Group.
|
|
385
|
-
*/
|
|
386
|
-
private _resolveStateToGroup;
|
|
567
|
+
constructor(rootNode: AnimationNode<G>, clock?: AnimationClockInterface);
|
|
568
|
+
getCurrentValue(): AniGroup<G> | null;
|
|
569
|
+
private _calculateStateAtTime;
|
|
570
|
+
private notify;
|
|
387
571
|
/**
|
|
388
|
-
*
|
|
572
|
+
* @private Internal clock subscription callback.
|
|
389
573
|
*/
|
|
390
|
-
|
|
574
|
+
update(dt: number): void;
|
|
391
575
|
/**
|
|
392
|
-
*
|
|
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.
|
|
393
579
|
*/
|
|
394
|
-
|
|
395
|
-
private _resolveExecutionPlan;
|
|
396
|
-
private notify;
|
|
397
|
-
play(config: TimelineStartingConfig<G, Ctx>, canBeIntercepted?: boolean): void;
|
|
580
|
+
play(config: RafTimelineConfig<G, Ctx>, canBeIntercepted?: boolean): void;
|
|
398
581
|
pause(): void;
|
|
399
582
|
resume(): void;
|
|
400
583
|
reset(notify?: boolean): void;
|
|
401
584
|
seek(targetTime: number): void;
|
|
402
|
-
getCurrentValue(): AniGroup<G> | null;
|
|
403
|
-
onUpdate(callback: OnUpdateCallback<G>): () => void;
|
|
404
|
-
update(dt: number): void;
|
|
405
|
-
}
|
|
406
|
-
declare function timeline<G extends Groupable, Ctx = any>(rootNode: AnimationNode<G>, clock?: AnimationClockInterface): Timeline<G, Ctx>;
|
|
407
|
-
|
|
408
|
-
type AnimationId = string;
|
|
409
|
-
type AnimationNodeType = string;
|
|
410
|
-
type AnimationDuration = number;
|
|
411
|
-
/**
|
|
412
|
-
* Nodes in the animation tree
|
|
413
|
-
*/
|
|
414
|
-
declare abstract class AnimationNode<G extends Groupable> {
|
|
415
|
-
abstract readonly type: AnimationNodeType;
|
|
416
|
-
abstract readonly duration: AnimationDuration;
|
|
417
|
-
readonly id?: AnimationId;
|
|
418
|
-
constructor(id?: AnimationId);
|
|
419
585
|
/**
|
|
420
|
-
*
|
|
421
|
-
* @param
|
|
422
|
-
* @
|
|
586
|
+
* When timeline updates, subscribes on update callback.
|
|
587
|
+
* @param callback Subscription callback.
|
|
588
|
+
* @returns Unsubscribe.
|
|
423
589
|
*/
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
type ExtractAnimationNode<AnimeNode> = AnimeNode extends AnimationNode<infer Group> ? Group : never;
|
|
427
|
-
|
|
428
|
-
type CompositionChildren = readonly AnimationNode<Groupable>[];
|
|
429
|
-
type CompositionPlan<Children extends CompositionChildren> = ExecutionPlan<ExtractAnimationNode<Children[number]>>;
|
|
430
|
-
/**
|
|
431
|
-
* Composition animation
|
|
432
|
-
*/
|
|
433
|
-
declare abstract class CompositionNode<const Children extends CompositionChildren> extends AnimationNode<ExtractAnimationNode<Children[number]>> {
|
|
434
|
-
/**
|
|
435
|
-
* Composition children nodes.
|
|
436
|
-
*/
|
|
437
|
-
readonly children: Children;
|
|
438
|
-
constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
interface SegmentNodeProps<G extends Groupable> {
|
|
442
|
-
readonly to: G;
|
|
443
|
-
readonly duration?: number;
|
|
444
|
-
readonly timing?: SegmentTiming;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Leaf node in the animation tree
|
|
448
|
-
*/
|
|
449
|
-
declare class SegmentNode<G extends Groupable> extends AnimationNode<G> {
|
|
450
|
-
readonly type = "SEGMENT";
|
|
451
|
-
readonly props: SegmentNodeProps<G>;
|
|
452
|
-
constructor(props: SegmentNodeProps<G>, id?: AnimationId);
|
|
453
|
-
get duration(): number;
|
|
454
|
-
construct(plan: ExecutionPlan<G>, startTime: number): void;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Factory function to create a ani SegmentNode.
|
|
458
|
-
*/
|
|
459
|
-
declare function ani<G extends Groupable>(props: SegmentNodeProps<G>, id?: AnimationId): SegmentNode<G>;
|
|
460
|
-
|
|
461
|
-
type PreserveRecord = Record<string, any>;
|
|
462
|
-
/**
|
|
463
|
-
* Creates a pause in an animation sequence.
|
|
464
|
-
* @param duration The duration of the delay in seconds.
|
|
465
|
-
* @param id Optional ID for the node.
|
|
466
|
-
*/
|
|
467
|
-
declare function delay(duration: number, id?: AnimationId): SegmentNode<PreserveRecord>;
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Composition node that repeats a child animation node a specified number of times.
|
|
471
|
-
*/
|
|
472
|
-
declare class LoopNode<G extends Groupable> extends CompositionNode<readonly AnimationNode<G>[]> {
|
|
473
|
-
readonly type = "LOOP";
|
|
474
|
-
readonly duration: number;
|
|
475
|
-
readonly count: number;
|
|
476
|
-
readonly child: AnimationNode<G>;
|
|
477
|
-
constructor(child: AnimationNode<G>, loopCount: number, timing?: TimingFunction, id?: AnimationId);
|
|
478
|
-
construct(plan: CompositionPlan<readonly AnimationNode<G>[]>, startTime: number): void;
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Repeats a child animation node a specified number of times.
|
|
482
|
-
* @param child The animation node to repeat.
|
|
483
|
-
* @param loopCount The number of times to repeat the child node.
|
|
484
|
-
* @param timing loop timing function.
|
|
485
|
-
* @param id Optional ID for the node.
|
|
486
|
-
*/
|
|
487
|
-
declare function loop<G extends Groupable>(child: AnimationNode<G>, loopCount: number, timing?: TimingFunction, id?: AnimationId): LoopNode<G>;
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Composition node that runs all of its children at the same time.
|
|
491
|
-
*/
|
|
492
|
-
declare class ParallelNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
|
|
493
|
-
readonly type = "PARALLEL";
|
|
494
|
-
readonly duration: number;
|
|
495
|
-
constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
|
|
496
|
-
construct(plan: CompositionPlan<Children>, startTime: number): void;
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Parallel composition animation
|
|
500
|
-
*/
|
|
501
|
-
declare function parallel<const Children extends CompositionChildren>(children: Children, timing?: TimingFunction, id?: AnimationId): ParallelNode<Children>;
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Composition node that runs its children one after another.
|
|
505
|
-
*/
|
|
506
|
-
declare class SequenceNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
|
|
507
|
-
readonly type = "SEQUENCE";
|
|
508
|
-
readonly duration: number;
|
|
509
|
-
constructor(children: Children, timing?: TimingFunction, id?: AnimationId);
|
|
510
|
-
construct(plan: CompositionPlan<Children>, startTime: number): void;
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Sequence composition animation
|
|
514
|
-
*/
|
|
515
|
-
declare function sequence<const Children extends CompositionChildren>(children: Children, timing?: TimingFunction, id?: AnimationId): SequenceNode<Children>;
|
|
516
|
-
|
|
517
|
-
interface StaggerNodeProps {
|
|
518
|
-
offset: number;
|
|
519
|
-
timing?: TimingFunction;
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Composition node that runs its children with a fixed delay between each start time.
|
|
523
|
-
*/
|
|
524
|
-
declare class StaggerNode<const Children extends CompositionChildren> extends CompositionNode<Children> {
|
|
525
|
-
readonly type = "STAGGER";
|
|
526
|
-
readonly duration: number;
|
|
527
|
-
readonly offset: number;
|
|
528
|
-
constructor(children: Children, props: StaggerNodeProps, id?: AnimationId);
|
|
529
|
-
construct(plan: CompositionPlan<Children>, startTime: number): void;
|
|
590
|
+
onUpdate(callback: OnUpdateCallback<G>): () => void;
|
|
530
591
|
}
|
|
531
592
|
/**
|
|
532
|
-
*
|
|
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]
|
|
533
596
|
*/
|
|
534
|
-
declare function
|
|
597
|
+
declare function rafTimeline<G extends Groupable, Ctx = any>(rootNode: AnimationNode<G>, clock?: AnimationClockInterface): RafAniTimeline<G, Ctx>;
|
|
535
598
|
|
|
536
599
|
type AnimationStateShape = Record<string, AnimationNode<Groupable>>;
|
|
537
|
-
type GetTimeline<State extends AnimationStateShape> =
|
|
600
|
+
type GetTimeline<State extends AnimationStateShape> = RafAniTimeline<ExtractAnimationNode<State[keyof State]>, any>;
|
|
601
|
+
type TimelineChangeCallback<AnimationStates extends AnimationStateShape> = (timeline: GetTimeline<AnimationStates>) => void;
|
|
538
602
|
interface StateController<AnimationStates extends AnimationStateShape> {
|
|
539
603
|
/**
|
|
540
604
|
* Get current timeline.
|
|
541
605
|
*/
|
|
542
606
|
timeline: () => GetTimeline<AnimationStates>;
|
|
607
|
+
/**
|
|
608
|
+
* Get current state.
|
|
609
|
+
*/
|
|
610
|
+
state: () => keyof AnimationStates;
|
|
543
611
|
/**
|
|
544
612
|
* Transition timeline animation into another state.
|
|
545
613
|
* @param newState transition target.
|
|
@@ -547,13 +615,13 @@ interface StateController<AnimationStates extends AnimationStateShape> {
|
|
|
547
615
|
* @param timelineConfig animation play config.
|
|
548
616
|
* @param canBeIntercepted animation canBeIntercepted config.
|
|
549
617
|
*/
|
|
550
|
-
transitionTo(newState: keyof AnimationStates, timelineConfig?:
|
|
618
|
+
transitionTo(newState: keyof AnimationStates, timelineConfig?: RafTimelineConfig<ExtractAnimationNode<AnimationStates[keyof AnimationStates]>, any>, canBeIntercepted?: boolean): void;
|
|
551
619
|
/**
|
|
552
620
|
* Subscribe to timeline changes.
|
|
553
621
|
* @param callback
|
|
554
622
|
* @returns unsubscribe function
|
|
555
623
|
*/
|
|
556
|
-
onTimelineChange(callback:
|
|
624
|
+
onTimelineChange(callback: TimelineChangeCallback<AnimationStates>): () => void;
|
|
557
625
|
}
|
|
558
626
|
interface StateProps<AnimationStates extends AnimationStateShape> {
|
|
559
627
|
/**
|
|
@@ -582,6 +650,52 @@ interface StateProps<AnimationStates extends AnimationStateShape> {
|
|
|
582
650
|
*/
|
|
583
651
|
declare function createStates<AnimationStates extends AnimationStateShape>(config: StateProps<AnimationStates>): StateController<AnimationStates>;
|
|
584
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
|
+
|
|
585
699
|
type EventHandler<AnimationContext = any, EvtKeys extends EventKey = EventKey> = (animationContext: AnimationContext, ev: HTMLElementEventMap[EvtKeys]) => any;
|
|
586
700
|
type EventHandlerRegistration<AnimationContext = any, Keys extends EventKey = EventKey> = PartialRecord<WithPrefix<'on', Capitalize<Keys>>, EventHandler<AnimationContext, Keys>>;
|
|
587
701
|
type EventKey = keyof HTMLElementEventMap;
|
|
@@ -607,17 +721,17 @@ declare class EventManager<SupportedEventList extends readonly EventKey[] = Even
|
|
|
607
721
|
bind(element: HTMLElement): void;
|
|
608
722
|
}
|
|
609
723
|
|
|
610
|
-
type AniRefContext<G extends Groupable> =
|
|
724
|
+
type AniRefContext<G extends Groupable> = TimelineBase<G> & {
|
|
611
725
|
/**
|
|
612
726
|
* Current animation value
|
|
613
727
|
*/
|
|
614
728
|
current: AniGroup<G> | null;
|
|
615
729
|
};
|
|
616
|
-
interface AniRefProps<G extends Groupable, AsGetter extends boolean = false> {
|
|
730
|
+
interface AniRefProps<Timeline extends TimelineBase<G>, G extends Groupable, AsGetter extends boolean = false> {
|
|
617
731
|
/**
|
|
618
732
|
* The compositional timeline to bind to the element.
|
|
619
733
|
*/
|
|
620
|
-
timeline: AsGetter extends true ? () => Timeline
|
|
734
|
+
timeline: AsGetter extends true ? () => Timeline : Timeline;
|
|
621
735
|
/**
|
|
622
736
|
* The initial style to apply to the element before the animation plays.
|
|
623
737
|
*/
|
|
@@ -638,16 +752,28 @@ declare const a: {
|
|
|
638
752
|
readonly timing: {
|
|
639
753
|
readonly bezier: (opt: BezierTimingFunctionOpt) => BezierTimingFunction;
|
|
640
754
|
readonly spring: (opt: SpringTimingFunctionOpt) => SpringTimingFunction;
|
|
755
|
+
readonly dynamicSpring: (opt: SpringTimingFunctionOpt) => DynamicSpringTimingFunction;
|
|
641
756
|
readonly linear: () => LinearTimingFunction;
|
|
757
|
+
readonly ease: () => BezierTimingFunction;
|
|
758
|
+
readonly easeIn: () => BezierTimingFunction;
|
|
759
|
+
readonly easeOut: () => BezierTimingFunction;
|
|
760
|
+
readonly easeInOut: () => BezierTimingFunction;
|
|
642
761
|
};
|
|
762
|
+
readonly dynamicTimeline: typeof rafTimeline;
|
|
763
|
+
readonly timeline: typeof webTimeline;
|
|
764
|
+
/**
|
|
765
|
+
* Create animation segment.
|
|
766
|
+
*/
|
|
643
767
|
readonly ani: typeof ani;
|
|
644
|
-
|
|
768
|
+
/**
|
|
769
|
+
* Add delay
|
|
770
|
+
*/
|
|
645
771
|
readonly delay: typeof delay;
|
|
646
772
|
readonly loop: typeof loop;
|
|
647
773
|
readonly parallel: typeof parallel;
|
|
648
774
|
readonly sequence: typeof sequence;
|
|
649
775
|
readonly stagger: typeof stagger;
|
|
650
|
-
readonly
|
|
776
|
+
readonly createStates: typeof createStates;
|
|
651
777
|
};
|
|
652
778
|
|
|
653
|
-
export { type AniGroup, type AniRefContext, type AniRefProps, type Animatable, AnimationClock, type AnimationClockInterface, type
|
|
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 };
|