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