@ue-too/animate 0.5.2 → 0.7.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.
Files changed (31) hide show
  1. package/README.md +5 -0
  2. package/animate.tsbuildinfo +1 -0
  3. package/{dist/index.js → index.js} +1 -1
  4. package/index.js.map +1 -0
  5. package/package.json +9 -10
  6. package/.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/animatable-attribute.js +0 -112
  7. package/.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/animatable-attribute.js.map +0 -1
  8. package/.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/animate.tsbuildinfo +0 -1
  9. package/.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/composite-animation.js +0 -792
  10. package/.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/composite-animation.js.map +0 -1
  11. package/.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/index.js +0 -3
  12. package/.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/index.js.map +0 -1
  13. package/dist/animatable-attribute.d.ts +0 -39
  14. package/dist/animate.tsbuildinfo +0 -1
  15. package/dist/composite-animation.d.ts +0 -181
  16. package/dist/index.d.ts +0 -2
  17. package/dist/index.js.map +0 -1
  18. package/dist/package.json +0 -22
  19. package/jest.config.js +0 -18
  20. package/project.json +0 -33
  21. package/rollup.config.js +0 -20
  22. package/src/animatable-attribute.ts +0 -146
  23. package/src/composite-animation.ts +0 -950
  24. package/src/index.ts +0 -2
  25. package/test/animatable-attributes.test.ts +0 -156
  26. package/test/composite-animation.test.ts +0 -238
  27. package/tsconfig.json +0 -22
  28. package/tsconfig.spec.json +0 -12
  29. /package/{.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/animatable-attribute.d.ts → animatable-attribute.d.ts} +0 -0
  30. /package/{.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/composite-animation.d.ts → composite-animation.d.ts} +0 -0
  31. /package/{.rollup.cache/home/runner/work/ue-too/ue-too/packages/animate/dist/index.d.ts → index.d.ts} +0 -0
@@ -1,792 +0,0 @@
1
- export const linear = (percentage) => {
2
- return percentage;
3
- };
4
- export class CompositeAnimation {
5
- constructor(animations = new Map(), loop = false, parent = undefined, setupFn = () => { }, tearDownFn = () => { }) {
6
- this.endCallbacks = [];
7
- this.startCallbacks = [];
8
- this.animations = animations;
9
- this._duration = 0;
10
- this.calculateDuration();
11
- this.localTime = -1;
12
- this.onGoing = false;
13
- this.loop = loop;
14
- this.setUpFn = setupFn;
15
- this.tearDownFn = tearDownFn;
16
- this._delayTime = 0;
17
- this._dragTime = 0;
18
- this.parent = parent;
19
- this.animations.forEach((animation) => {
20
- animation.animator.setParent(this);
21
- });
22
- this.reverse = false;
23
- this.playedTime = 0;
24
- }
25
- toggleReverse(reverse) {
26
- if (this.reverse == reverse) {
27
- return;
28
- }
29
- this.reverse = reverse;
30
- this.animations.forEach((animation) => {
31
- animation.animator.toggleReverse(reverse);
32
- });
33
- }
34
- setParent(parent) {
35
- this.parent = parent;
36
- }
37
- detachParent() {
38
- this.parent = undefined;
39
- }
40
- animate(deltaTime) {
41
- if (!this.onGoing || this.localTime > this._duration + this._delayTime + this._dragTime || this.localTime < 0 || this.animations.size == 0) {
42
- return;
43
- }
44
- this.localTime += deltaTime;
45
- if (this.localTime - deltaTime <= 0 && deltaTime > 0) {
46
- // console.log("composite animation start");
47
- this.startCallbacks.forEach((callback) => {
48
- queueMicrotask(() => { callback(); });
49
- });
50
- }
51
- this.animateChildren(deltaTime);
52
- this.checkTerminalAndLoop();
53
- }
54
- checkTerminalAndLoop() {
55
- if (this.localTime >= this._duration + this._delayTime + this._dragTime) {
56
- // console.log("composite animation end");
57
- this.playedTime += 1;
58
- this.endCallbacks.forEach((callback) => {
59
- queueMicrotask(() => { callback(); });
60
- });
61
- if (!this.loops || (this.maxLoopCount != undefined && this.playedTime >= this.maxLoopCount)) {
62
- // this.onGoing = false;
63
- this.stop();
64
- }
65
- else {
66
- // if loop is true and current loop is not the last loop, then prepare to start the animations again
67
- // this.onGoing = true;
68
- // this.localTime = 0;
69
- // this.animations.forEach((animation) => {
70
- // if(animation.animator.loops){
71
- // animation.animator.startAnimation();
72
- // }
73
- // });
74
- this.start();
75
- }
76
- }
77
- }
78
- animateChildren(deltaTime) {
79
- const prevLocalTime = this.localTime - deltaTime;
80
- if (this.localTime < this._delayTime) {
81
- return;
82
- }
83
- this.animations.forEach((animation, name) => {
84
- if (animation.startTime == undefined) {
85
- animation.startTime = 0;
86
- }
87
- if (!this.childShouldAnimate(animation, prevLocalTime)) {
88
- this.wrapUpAnimator({ animator: animation.animator, startTime: animation.startTime, name: name }, prevLocalTime);
89
- return;
90
- }
91
- if (prevLocalTime - this._delayTime < animation.startTime) {
92
- animation.animator.animate(this.localTime - this._delayTime - animation.startTime);
93
- }
94
- else {
95
- animation.animator.animate(deltaTime);
96
- }
97
- });
98
- }
99
- childShouldAnimate(animation, prevLocalTime) {
100
- if (animation.startTime == undefined) {
101
- animation.startTime = 0;
102
- }
103
- if (this.localTime - this._delayTime >= animation.startTime && this.localTime - this._delayTime <= animation.startTime + animation.animator.duration) {
104
- return true;
105
- }
106
- return false;
107
- }
108
- wrapUpAnimator(animation, prevLocalTime) {
109
- if (animation.startTime == undefined) {
110
- animation.startTime = 0;
111
- }
112
- if (this.localTime - this._delayTime > animation.startTime + animation.animator.duration && prevLocalTime - this._delayTime < animation.startTime + animation.animator.duration) {
113
- // console.log("wrap up", animation.name);
114
- // console.log("time remaining", animation.startTime + animation.animator.duration - (prevLocalTime - this._delayTime));
115
- animation.animator.animate(animation.startTime + animation.animator.duration - (prevLocalTime - this._delayTime));
116
- }
117
- }
118
- pause() {
119
- this.onGoing = false;
120
- this.animations.forEach((animation) => {
121
- animation.animator.pause();
122
- });
123
- }
124
- resume() {
125
- this.onGoing = true;
126
- this.animations.forEach((animation) => {
127
- animation.animator.resume();
128
- });
129
- }
130
- start() {
131
- this.onGoing = true;
132
- this.setUp();
133
- this.localTime = 0;
134
- this.animations.forEach((animation) => {
135
- animation.animator.start();
136
- });
137
- }
138
- stop() {
139
- this.onGoing = false;
140
- this.playedTime = 0;
141
- this.localTime = this._duration + 0.1;
142
- this.animations.forEach((animation) => {
143
- animation.animator.stop();
144
- });
145
- this.tearDown();
146
- }
147
- get duration() {
148
- return this._duration + this._delayTime + this._dragTime;
149
- }
150
- set duration(duration) {
151
- if (duration < 0) {
152
- return;
153
- }
154
- const originalDuration = this._duration + this._delayTime + this._dragTime;
155
- const scale = duration / originalDuration;
156
- const newDelayTime = this._delayTime * scale;
157
- const newDragTime = this._dragTime * scale;
158
- this._delayTime = newDelayTime;
159
- this._dragTime = newDragTime;
160
- this.animations.forEach((animation) => {
161
- if (animation.startTime == undefined) {
162
- animation.startTime = 0;
163
- }
164
- animation.startTime *= scale;
165
- const newDuration = animation.animator.duration * scale;
166
- animation.animator.nonCascadingDuration(newDuration);
167
- });
168
- this.calculateDuration();
169
- if (this.parent != undefined) {
170
- this.parent.updateDuration();
171
- }
172
- }
173
- nonCascadingDuration(newDuration) {
174
- if (newDuration < 0) {
175
- return;
176
- }
177
- const originalDuration = this._duration + this._delayTime + this._dragTime;
178
- const scale = newDuration / originalDuration;
179
- const newDelayTime = this._delayTime * scale;
180
- const newDragTime = this._dragTime * scale;
181
- this._delayTime = newDelayTime;
182
- this._dragTime = newDragTime;
183
- this.animations.forEach((animation) => {
184
- if (animation.startTime == undefined) {
185
- animation.startTime = 0;
186
- }
187
- animation.startTime *= scale;
188
- const newDuration = animation.animator.duration * scale;
189
- animation.animator.nonCascadingDuration(newDuration);
190
- });
191
- this.calculateDuration();
192
- }
193
- resetAnimationState() {
194
- this.onGoing = false;
195
- this.animations.forEach((animation) => {
196
- animation.animator.resetAnimationState();
197
- });
198
- }
199
- getTrueDuration() {
200
- return this._duration;
201
- }
202
- setUp() {
203
- this.setUpFn();
204
- this.animations.forEach((animation) => {
205
- animation.animator.setUp();
206
- });
207
- }
208
- tearDown() {
209
- this.tearDownFn();
210
- this.animations.forEach((animation) => {
211
- animation.animator.tearDown();
212
- });
213
- }
214
- addAnimation(name, animation, startTime = 0, endCallback = () => { }) {
215
- if (this.animations.has(name)) {
216
- return;
217
- }
218
- if (this.parent !== undefined && this.parent.containsAnimation(animation)) {
219
- return;
220
- }
221
- this.animations.set(name, { animator: animation, startTime: startTime });
222
- animation.setParent(this);
223
- if (this.localTime > startTime) {
224
- animation.animate(this.localTime - startTime);
225
- }
226
- const endTime = startTime + animation.duration;
227
- this._duration = Math.max(this._duration, endTime);
228
- if (this.parent != undefined) {
229
- this.parent.updateDuration();
230
- }
231
- }
232
- addAnimationAfter(name, animation, afterName, delay = 0) {
233
- let afterAnimation = this.animations.get(afterName);
234
- if (afterAnimation == undefined) {
235
- return;
236
- }
237
- if (afterAnimation.startTime == undefined) {
238
- afterAnimation.startTime = 0;
239
- }
240
- let startTime = afterAnimation.startTime + afterAnimation.animator.duration;
241
- startTime += delay;
242
- this.addAnimation(name, animation, startTime);
243
- this.calculateDuration();
244
- if (this.parent != undefined) {
245
- this.parent.updateDuration();
246
- }
247
- }
248
- addAnimationAdmist(name, animation, admistName, delay) {
249
- let admistAnimation = this.animations.get(admistName);
250
- if (admistAnimation == undefined) {
251
- return;
252
- }
253
- if (admistAnimation.startTime == undefined) {
254
- admistAnimation.startTime = 0;
255
- }
256
- let startTime = admistAnimation.startTime + delay;
257
- this.addAnimation(name, animation, startTime);
258
- this.calculateDuration();
259
- if (this.parent != undefined) {
260
- this.parent.updateDuration();
261
- }
262
- }
263
- addAnimationBefore(name, animation, beforeName, aheadTime = 0) {
264
- let beforeAnimation = this.animations.get(beforeName);
265
- if (beforeAnimation == undefined) {
266
- return;
267
- }
268
- if (beforeAnimation.startTime == undefined) {
269
- beforeAnimation.startTime = 0;
270
- }
271
- let startTime = beforeAnimation.startTime;
272
- startTime -= aheadTime;
273
- this.addAnimation(name, animation, startTime);
274
- if (startTime < 0) {
275
- const pushOver = 0 - startTime;
276
- this.animations.forEach((animation) => {
277
- if (animation.startTime == undefined) {
278
- animation.startTime = 0;
279
- }
280
- animation.startTime += pushOver;
281
- });
282
- }
283
- this.calculateDuration();
284
- if (this.parent != undefined) {
285
- this.parent.updateDuration();
286
- }
287
- }
288
- removeAnimation(name) {
289
- let animation = this.animations.get(name);
290
- let deleted = this.animations.delete(name);
291
- if (deleted) {
292
- if (animation != undefined) {
293
- animation.animator.detachParent();
294
- }
295
- this.calculateDuration();
296
- if (this.parent != undefined) {
297
- this.parent.updateDuration();
298
- }
299
- }
300
- }
301
- set delay(delayTime) {
302
- this._delayTime = delayTime;
303
- if (this.parent != undefined) {
304
- this.parent.updateDuration();
305
- }
306
- }
307
- get delay() {
308
- return this._delayTime;
309
- }
310
- set drag(dragTime) {
311
- this._dragTime = dragTime;
312
- if (this.parent != undefined) {
313
- this.parent.updateDuration();
314
- }
315
- }
316
- get drag() {
317
- return this._dragTime;
318
- }
319
- removeDelay() {
320
- this._delayTime = 0;
321
- if (this.parent != undefined) {
322
- this.parent.updateDuration();
323
- }
324
- }
325
- removeDrag() {
326
- this._dragTime = 0;
327
- if (this.parent != undefined) {
328
- this.parent.updateDuration();
329
- }
330
- }
331
- updateDuration() {
332
- if (this.checkCyclicChildren()) {
333
- return;
334
- }
335
- this.calculateDuration();
336
- if (this.parent != undefined) {
337
- this.parent.updateDuration();
338
- }
339
- }
340
- calculateDuration() {
341
- this._duration = 0;
342
- this.animations.forEach((animation) => {
343
- if (animation.startTime == undefined) {
344
- animation.startTime = 0;
345
- }
346
- const endTime = animation.startTime + animation.animator.duration;
347
- this._duration = Math.max(this._duration, endTime);
348
- });
349
- }
350
- get loops() {
351
- return this.loop;
352
- }
353
- set loops(loop) {
354
- this.loop = loop;
355
- }
356
- checkCyclicChildren() {
357
- const allChildren = [];
358
- allChildren.push(this);
359
- const visited = new Set();
360
- while (allChildren.length > 0) {
361
- const current = allChildren.pop();
362
- if (current == undefined) {
363
- continue;
364
- }
365
- if (visited.has(current)) {
366
- return true;
367
- }
368
- visited.add(current);
369
- if (current instanceof CompositeAnimation) {
370
- current.animations.forEach((animation) => {
371
- allChildren.push(animation.animator);
372
- });
373
- }
374
- }
375
- return false;
376
- }
377
- forceToggleLoop(loop) {
378
- this.loop = true;
379
- this.animations.forEach((animation) => {
380
- animation.animator.loops = true;
381
- });
382
- }
383
- containsAnimation(animationInInterest) {
384
- if (this.parent !== undefined) {
385
- return this.parent.containsAnimation(animationInInterest);
386
- }
387
- const allChildren = [];
388
- allChildren.push(this);
389
- const visited = new Set();
390
- while (allChildren.length > 0) {
391
- const current = allChildren.pop();
392
- if (current == undefined) {
393
- continue;
394
- }
395
- if (current == animationInInterest) {
396
- return true;
397
- }
398
- if (visited.has(current)) {
399
- continue;
400
- }
401
- visited.add(current);
402
- if (current instanceof CompositeAnimation) {
403
- current.animations.forEach((animation) => {
404
- allChildren.push(animation.animator);
405
- });
406
- }
407
- }
408
- return false;
409
- }
410
- onEnd(callback) {
411
- this.endCallbacks.push(callback);
412
- return () => {
413
- this.endCallbacks = this.endCallbacks.filter((cb) => cb != callback);
414
- };
415
- }
416
- onStart(callback) {
417
- this.startCallbacks.push(callback);
418
- return () => {
419
- this.startCallbacks = this.startCallbacks.filter((cb) => cb != callback);
420
- };
421
- }
422
- clearOnEnd() {
423
- this.endCallbacks = [];
424
- }
425
- clearOnStart() {
426
- this.startCallbacks = [];
427
- }
428
- get playing() {
429
- return this.onGoing;
430
- }
431
- get maxLoopCount() {
432
- return this._maxLoopCount;
433
- }
434
- set maxLoopCount(maxLoopCount) {
435
- this._maxLoopCount = maxLoopCount;
436
- }
437
- }
438
- export class Animation {
439
- constructor(keyFrames, applyAnimationValue, animatableAttributeHelper, duration = 1000, loop = false, parent = undefined, setUpFn = () => { }, tearDownFn = () => { }, easeFn = linear) {
440
- this.delayTime = 0;
441
- this.dragTime = 0;
442
- this.reverse = false;
443
- this.endCallbacks = [];
444
- this.startCallbacks = [];
445
- this.startAfterDelayCallbacks = [];
446
- this._fillMode = 'none';
447
- this._duration = duration;
448
- this.keyframes = keyFrames;
449
- this.animatableAttributeHelper = animatableAttributeHelper;
450
- this.applyAnimationValue = applyAnimationValue;
451
- this.easeFn = easeFn;
452
- this.onGoing = false;
453
- this.localTime = duration + 0.1;
454
- this.currentKeyframeIndex = 0;
455
- this.loop = loop;
456
- this.setUpFn = setUpFn;
457
- this.tearDownFn = tearDownFn;
458
- this.parent = parent;
459
- this.playedTime = 0;
460
- this.zeroPercentageValue = this.findValue(0, keyFrames, animatableAttributeHelper);
461
- }
462
- toggleReverse(reverse) {
463
- this.reverse = reverse;
464
- }
465
- start() {
466
- this.localTime = 0;
467
- this.currentKeyframeIndex = 0;
468
- this.onGoing = true;
469
- // this.applyAnimationValue(this.zeroPercentageValue);
470
- this.setUp();
471
- }
472
- stop() {
473
- this.onGoing = false;
474
- this.localTime = this._duration + this.dragTime + this.delayTime + 0.1;
475
- this.playedTime = 0;
476
- this.tearDown();
477
- }
478
- pause() {
479
- this.onGoing = false;
480
- }
481
- resume() {
482
- this.onGoing = true;
483
- }
484
- get playing() {
485
- return this.onGoing;
486
- }
487
- animate(deltaTime) {
488
- if (this.onGoing != true || this.localTime < 0) {
489
- return;
490
- }
491
- if (deltaTime == 0) {
492
- return;
493
- }
494
- this.localTime += deltaTime;
495
- // console.log("--------------------");
496
- // console.log("local time", this.localTime);
497
- // console.log("delta time", deltaTime);
498
- if (this.localTime - deltaTime <= 0 && deltaTime > 0) {
499
- // console.log("--------------------");
500
- // console.log("current localtime", this.localTime);
501
- // console.log("current delta time", deltaTime);
502
- // console.log("previous local time", this.localTime - deltaTime);
503
- // console.log("animation start");
504
- // console.log(`the animation has been played ${this.playedTime} times`);
505
- // console.log(`the animation is now playing for the ${this.playedTime + 1} time`);
506
- this.startCallbacks.forEach((callback) => {
507
- queueMicrotask(() => { callback(); });
508
- });
509
- }
510
- if (this.localTime >= this.delayTime && (this.localTime <= this.delayTime + this._duration + this.dragTime || this.localTime - deltaTime <= this.delayTime + this._duration + this.dragTime)) {
511
- // console.log("local time", this.localTime);
512
- // console.log("duration", this.duration);
513
- // console.log("local time would trigger end", this.localTime >= this._duration + this.delayTime + this.dragTime);
514
- // console.log("delta time", deltaTime);
515
- if (this.localTime - deltaTime <= this.delayTime && this.delayTime !== 0 && deltaTime > 0) {
516
- this.startAfterDelayCallbacks.forEach((callback) => {
517
- queueMicrotask(() => { callback(); });
518
- });
519
- this.applyAnimationValue(this.zeroPercentageValue);
520
- }
521
- let localTimePercentage = (this.localTime - this.delayTime) / (this._duration);
522
- let targetPercentage = this.easeFn(localTimePercentage);
523
- if (localTimePercentage > 1) {
524
- targetPercentage = this.easeFn(1);
525
- }
526
- let value;
527
- // console.log("currentKeyframeIndex", this.currentKeyframeIndex, "length", this.keyFrames.length);
528
- if (this.currentKeyframeIndex < this.keyframes.length && this.currentKeyframeIndex >= 0 && (this.reverse ? 1 - this.keyframes[this.currentKeyframeIndex].percentage == targetPercentage : this.keyframes[this.currentKeyframeIndex].percentage == targetPercentage)) {
529
- value = this.keyframes[this.currentKeyframeIndex].value;
530
- }
531
- else {
532
- value = this.findValue(targetPercentage, this.keyframes, this.animatableAttributeHelper);
533
- }
534
- if (this.reverse) {
535
- while (this.currentKeyframeIndex >= 0 && 1 - this.keyframes[this.currentKeyframeIndex].percentage <= targetPercentage) {
536
- this.currentKeyframeIndex -= 1;
537
- }
538
- }
539
- else {
540
- while (this.currentKeyframeIndex < this.keyframes.length && this.keyframes[this.currentKeyframeIndex].percentage <= targetPercentage) {
541
- this.currentKeyframeIndex += 1;
542
- }
543
- }
544
- this.applyAnimationValue(value);
545
- if (this.localTime >= this._duration + this.dragTime + this.delayTime) {
546
- // console.log("animation should end");
547
- this.playedTime += 1;
548
- this.endCallbacks.forEach((callback) => {
549
- queueMicrotask(() => { callback(); });
550
- });
551
- if (!this.loops || (this._maxLoopCount != undefined && this.playedTime >= this.maxLoopCount)) {
552
- // this.onGoing = false;
553
- // console.log("animation should stop after ", this.playedTime, " loops");
554
- this.stop();
555
- }
556
- else {
557
- // console.log("animation should restart");
558
- this.onGoing = true;
559
- this.localTime = 0;
560
- this.currentKeyframeIndex = 0;
561
- this.start();
562
- }
563
- }
564
- // if((this.localTime >= this._duration + this.delayTime + this.dragTime) && this.loop){
565
- // // this.startAnimation();
566
- // this.localTime = 0;
567
- // this.onGoing = true;
568
- // this.currentKeyframeIndex = 0;
569
- // }
570
- }
571
- }
572
- findValue(valuePercentage, keyframes, animatableAttributeHelper) {
573
- if (valuePercentage > 1) {
574
- if (this.reverse) {
575
- return animatableAttributeHelper.lerp(valuePercentage, keyframes[1], keyframes[0]);
576
- }
577
- return animatableAttributeHelper.lerp(valuePercentage, keyframes[keyframes.length - 2], keyframes[keyframes.length - 1]);
578
- }
579
- if (valuePercentage < 0) {
580
- if (this.reverse) {
581
- return animatableAttributeHelper.lerp(valuePercentage, keyframes[keyframes.length - 2], keyframes[keyframes.length - 1]);
582
- }
583
- return animatableAttributeHelper.lerp(valuePercentage, keyframes[1], keyframes[0]);
584
- }
585
- let left = 0;
586
- let right = keyframes.length - 1;
587
- while (left <= right) {
588
- let mid = left + Math.floor((right - left) / 2);
589
- const midPercentage = this.reverse ? 1 - keyframes[mid].percentage : keyframes[mid].percentage;
590
- if (midPercentage == valuePercentage) {
591
- return keyframes[mid].value;
592
- }
593
- else if (midPercentage < valuePercentage) {
594
- if (this.reverse) {
595
- right = mid - 1;
596
- }
597
- else {
598
- left = mid + 1;
599
- }
600
- }
601
- else {
602
- if (this.reverse) {
603
- left = mid + 1;
604
- }
605
- else {
606
- right = mid - 1;
607
- }
608
- }
609
- }
610
- if (left > keyframes.length - 1) {
611
- // excceding the keyframes
612
- left = keyframes.length - 1;
613
- }
614
- const interpolateStartFrame = this.reverse ? { percentage: 1 - keyframes[left].percentage, value: keyframes[left].value } : keyframes[left - 1];
615
- const interplateEndFrame = this.reverse ? { percentage: 1 - keyframes[left - 1].percentage, value: keyframes[left - 1].value } : keyframes[left];
616
- // return animatableAttributeHelper.lerp(valuePercentage, keyframes[left - 1], keyframes[left]);
617
- return animatableAttributeHelper.lerp(valuePercentage, interpolateStartFrame, interplateEndFrame);
618
- }
619
- setUp() {
620
- // this.applyAnimationValue(this.keyframes[0].value);
621
- this.setUpFn();
622
- }
623
- tearDown() {
624
- this.tearDownFn();
625
- }
626
- get loops() {
627
- return this.loop;
628
- }
629
- set loops(loop) {
630
- this.loop = loop;
631
- }
632
- get duration() {
633
- return this._duration + this.delayTime + this.dragTime;
634
- }
635
- set duration(duration) {
636
- if (duration < 0) {
637
- return;
638
- }
639
- const originalDuration = this._duration + this.delayTime + this.dragTime;
640
- const scale = duration / originalDuration;
641
- const newDelayTime = this.delayTime * scale;
642
- const newDragTime = this.dragTime * scale;
643
- this.delayTime = newDelayTime;
644
- this.dragTime = newDragTime;
645
- this._duration = this._duration * scale;
646
- if (this.parent != undefined) {
647
- this.parent.updateDuration();
648
- }
649
- }
650
- nonCascadingDuration(newDuration) {
651
- if (newDuration < 0) {
652
- return;
653
- }
654
- const originalDuration = this._duration + this.delayTime + this.dragTime;
655
- const scale = newDuration / originalDuration;
656
- const newDelayTime = this.delayTime * scale;
657
- const newDragTime = this.dragTime * scale;
658
- this.delayTime = newDelayTime;
659
- this.dragTime = newDragTime;
660
- this._duration = newDuration;
661
- }
662
- resetAnimationState() {
663
- this.onGoing = false;
664
- this.applyAnimationValue(this.keyframes[0].value);
665
- this.currentKeyframeIndex = 0;
666
- this.setUp();
667
- }
668
- wrapUp() {
669
- this.onGoing = false;
670
- this.localTime = this._duration + this.dragTime + this.delayTime + 0.1;
671
- this.currentKeyframeIndex = 0;
672
- }
673
- get delay() {
674
- return this.delayTime;
675
- }
676
- set delay(delayTime) {
677
- this.delayTime = delayTime;
678
- if (this.parent != undefined) {
679
- this.parent.updateDuration();
680
- }
681
- }
682
- get drag() {
683
- return this.dragTime;
684
- }
685
- set drag(dragTime) {
686
- this.dragTime = dragTime;
687
- if (this.parent != undefined) {
688
- this.parent.updateDuration();
689
- }
690
- }
691
- get trueDuration() {
692
- return this._duration;
693
- }
694
- set trueDuration(duration) {
695
- this._duration = duration;
696
- if (this.parent != undefined) {
697
- this.parent.updateDuration();
698
- }
699
- }
700
- setParent(parent) {
701
- this.parent = parent;
702
- }
703
- detachParent() {
704
- this.parent = undefined;
705
- }
706
- set keyFrames(keyFrames) {
707
- this.keyframes = keyFrames;
708
- this.zeroPercentageValue = this.findValue(0, keyFrames, this.animatableAttributeHelper);
709
- }
710
- get keyFrames() {
711
- return this.keyframes;
712
- }
713
- get easeFunction() {
714
- return this.easeFn;
715
- }
716
- set easeFunction(easeFn) {
717
- this.easeFn = easeFn;
718
- }
719
- onEnd(callback) {
720
- this.endCallbacks.push(callback);
721
- return () => {
722
- this.endCallbacks = this.endCallbacks.filter((cb) => cb != callback);
723
- };
724
- }
725
- onStart(callback) {
726
- this.startCallbacks.push(callback);
727
- return () => {
728
- this.startCallbacks = this.startCallbacks.filter((cb) => cb != callback);
729
- };
730
- }
731
- onStartAfterDelay(callback) {
732
- this.startAfterDelayCallbacks.push(callback);
733
- return () => {
734
- this.startAfterDelayCallbacks = this.startAfterDelayCallbacks.filter((cb) => cb != callback);
735
- };
736
- }
737
- clearOnEnd() {
738
- this.endCallbacks = [];
739
- }
740
- clearOnStart() {
741
- this.startCallbacks = [];
742
- }
743
- get maxLoopCount() {
744
- return this._maxLoopCount;
745
- }
746
- set maxLoopCount(maxLoopCount) {
747
- this._maxLoopCount = maxLoopCount;
748
- }
749
- }
750
- export class KeyFramesContiner {
751
- constructor() {
752
- this._keyframes = [];
753
- }
754
- get keyframes() {
755
- return this._keyframes;
756
- }
757
- from(value) {
758
- if (this._keyframes.length == 0) {
759
- this._keyframes.push({ percentage: 0, value: value });
760
- }
761
- else {
762
- if (this._keyframes[0].percentage == 0) {
763
- this._keyframes[0].value = value;
764
- }
765
- else {
766
- this._keyframes.unshift({ percentage: 0, value: value });
767
- }
768
- }
769
- return this;
770
- }
771
- to(value) {
772
- if (this._keyframes.length == 0) {
773
- this._keyframes.push({ percentage: 1, value: value });
774
- }
775
- else {
776
- if (this._keyframes[this._keyframes.length - 1].percentage == 1) {
777
- this._keyframes[this._keyframes.length - 1].value = value;
778
- }
779
- else {
780
- this._keyframes.push({ percentage: 1, value: value });
781
- }
782
- }
783
- return this;
784
- }
785
- insertAt(percentage, value) {
786
- this._keyframes.push({ percentage: percentage, value: value });
787
- }
788
- clearFrames() {
789
- this._keyframes = [];
790
- }
791
- }
792
- //# sourceMappingURL=composite-animation.js.map