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