@linorabolini/tween.js 25.0.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/LICENSE +23 -0
- package/README.md +484 -0
- package/dist/tween.amd.js +1441 -0
- package/dist/tween.cjs +1439 -0
- package/dist/tween.d.ts +727 -0
- package/dist/tween.esm.js +1421 -0
- package/dist/tween.umd.js +1445 -0
- package/package.json +67 -0
|
@@ -0,0 +1,1421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Ease class provides a collection of easing functions for use with tween.js.
|
|
3
|
+
*/
|
|
4
|
+
var Easing = Object.freeze({
|
|
5
|
+
Linear: Object.freeze({
|
|
6
|
+
None: function (amount) {
|
|
7
|
+
return amount;
|
|
8
|
+
},
|
|
9
|
+
In: function (amount) {
|
|
10
|
+
return amount;
|
|
11
|
+
},
|
|
12
|
+
Out: function (amount) {
|
|
13
|
+
return amount;
|
|
14
|
+
},
|
|
15
|
+
InOut: function (amount) {
|
|
16
|
+
return amount;
|
|
17
|
+
},
|
|
18
|
+
}),
|
|
19
|
+
Quadratic: Object.freeze({
|
|
20
|
+
In: function (amount) {
|
|
21
|
+
return amount * amount;
|
|
22
|
+
},
|
|
23
|
+
Out: function (amount) {
|
|
24
|
+
return amount * (2 - amount);
|
|
25
|
+
},
|
|
26
|
+
InOut: function (amount) {
|
|
27
|
+
if ((amount *= 2) < 1) {
|
|
28
|
+
return 0.5 * amount * amount;
|
|
29
|
+
}
|
|
30
|
+
return -0.5 * (--amount * (amount - 2) - 1);
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
Cubic: Object.freeze({
|
|
34
|
+
In: function (amount) {
|
|
35
|
+
return amount * amount * amount;
|
|
36
|
+
},
|
|
37
|
+
Out: function (amount) {
|
|
38
|
+
return --amount * amount * amount + 1;
|
|
39
|
+
},
|
|
40
|
+
InOut: function (amount) {
|
|
41
|
+
if ((amount *= 2) < 1) {
|
|
42
|
+
return 0.5 * amount * amount * amount;
|
|
43
|
+
}
|
|
44
|
+
return 0.5 * ((amount -= 2) * amount * amount + 2);
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
Quartic: Object.freeze({
|
|
48
|
+
In: function (amount) {
|
|
49
|
+
return amount * amount * amount * amount;
|
|
50
|
+
},
|
|
51
|
+
Out: function (amount) {
|
|
52
|
+
return 1 - --amount * amount * amount * amount;
|
|
53
|
+
},
|
|
54
|
+
InOut: function (amount) {
|
|
55
|
+
if ((amount *= 2) < 1) {
|
|
56
|
+
return 0.5 * amount * amount * amount * amount;
|
|
57
|
+
}
|
|
58
|
+
return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
Quintic: Object.freeze({
|
|
62
|
+
In: function (amount) {
|
|
63
|
+
return amount * amount * amount * amount * amount;
|
|
64
|
+
},
|
|
65
|
+
Out: function (amount) {
|
|
66
|
+
return --amount * amount * amount * amount * amount + 1;
|
|
67
|
+
},
|
|
68
|
+
InOut: function (amount) {
|
|
69
|
+
if ((amount *= 2) < 1) {
|
|
70
|
+
return 0.5 * amount * amount * amount * amount * amount;
|
|
71
|
+
}
|
|
72
|
+
return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
Sinusoidal: Object.freeze({
|
|
76
|
+
In: function (amount) {
|
|
77
|
+
return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);
|
|
78
|
+
},
|
|
79
|
+
Out: function (amount) {
|
|
80
|
+
return Math.sin((amount * Math.PI) / 2);
|
|
81
|
+
},
|
|
82
|
+
InOut: function (amount) {
|
|
83
|
+
return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
Exponential: Object.freeze({
|
|
87
|
+
In: function (amount) {
|
|
88
|
+
return amount === 0 ? 0 : Math.pow(1024, amount - 1);
|
|
89
|
+
},
|
|
90
|
+
Out: function (amount) {
|
|
91
|
+
return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
|
|
92
|
+
},
|
|
93
|
+
InOut: function (amount) {
|
|
94
|
+
if (amount === 0) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
if (amount === 1) {
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
if ((amount *= 2) < 1) {
|
|
101
|
+
return 0.5 * Math.pow(1024, amount - 1);
|
|
102
|
+
}
|
|
103
|
+
return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
Circular: Object.freeze({
|
|
107
|
+
In: function (amount) {
|
|
108
|
+
return 1 - Math.sqrt(1 - amount * amount);
|
|
109
|
+
},
|
|
110
|
+
Out: function (amount) {
|
|
111
|
+
return Math.sqrt(1 - --amount * amount);
|
|
112
|
+
},
|
|
113
|
+
InOut: function (amount) {
|
|
114
|
+
if ((amount *= 2) < 1) {
|
|
115
|
+
return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
|
|
116
|
+
}
|
|
117
|
+
return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
Elastic: Object.freeze({
|
|
121
|
+
In: function (amount) {
|
|
122
|
+
if (amount === 0) {
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
if (amount === 1) {
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
|
|
129
|
+
},
|
|
130
|
+
Out: function (amount) {
|
|
131
|
+
if (amount === 0) {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
if (amount === 1) {
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
|
|
138
|
+
},
|
|
139
|
+
InOut: function (amount) {
|
|
140
|
+
if (amount === 0) {
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
if (amount === 1) {
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
amount *= 2;
|
|
147
|
+
if (amount < 1) {
|
|
148
|
+
return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
|
|
149
|
+
}
|
|
150
|
+
return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
153
|
+
Back: Object.freeze({
|
|
154
|
+
In: function (amount) {
|
|
155
|
+
var s = 1.70158;
|
|
156
|
+
return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
|
|
157
|
+
},
|
|
158
|
+
Out: function (amount) {
|
|
159
|
+
var s = 1.70158;
|
|
160
|
+
return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
|
|
161
|
+
},
|
|
162
|
+
InOut: function (amount) {
|
|
163
|
+
var s = 1.70158 * 1.525;
|
|
164
|
+
if ((amount *= 2) < 1) {
|
|
165
|
+
return 0.5 * (amount * amount * ((s + 1) * amount - s));
|
|
166
|
+
}
|
|
167
|
+
return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
Bounce: Object.freeze({
|
|
171
|
+
In: function (amount) {
|
|
172
|
+
return 1 - Easing.Bounce.Out(1 - amount);
|
|
173
|
+
},
|
|
174
|
+
Out: function (amount) {
|
|
175
|
+
if (amount < 1 / 2.75) {
|
|
176
|
+
return 7.5625 * amount * amount;
|
|
177
|
+
}
|
|
178
|
+
else if (amount < 2 / 2.75) {
|
|
179
|
+
return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
|
|
180
|
+
}
|
|
181
|
+
else if (amount < 2.5 / 2.75) {
|
|
182
|
+
return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
InOut: function (amount) {
|
|
189
|
+
if (amount < 0.5) {
|
|
190
|
+
return Easing.Bounce.In(amount * 2) * 0.5;
|
|
191
|
+
}
|
|
192
|
+
return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
generatePow: function (power) {
|
|
196
|
+
if (power === void 0) { power = 4; }
|
|
197
|
+
power = power < Number.EPSILON ? Number.EPSILON : power;
|
|
198
|
+
power = power > 10000 ? 10000 : power;
|
|
199
|
+
return {
|
|
200
|
+
In: function (amount) {
|
|
201
|
+
return Math.pow(amount, power);
|
|
202
|
+
},
|
|
203
|
+
Out: function (amount) {
|
|
204
|
+
return 1 - Math.pow((1 - amount), power);
|
|
205
|
+
},
|
|
206
|
+
InOut: function (amount) {
|
|
207
|
+
if (amount < 0.5) {
|
|
208
|
+
return Math.pow((amount * 2), power) / 2;
|
|
209
|
+
}
|
|
210
|
+
return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
var _nowFunc = function () { return performance.now(); };
|
|
217
|
+
var now = function () {
|
|
218
|
+
return _nowFunc();
|
|
219
|
+
};
|
|
220
|
+
function setNow(nowFunction) {
|
|
221
|
+
_nowFunc = nowFunction;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Controlling groups of tweens
|
|
226
|
+
*
|
|
227
|
+
* Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
|
|
228
|
+
* In these cases, you may want to create your own smaller groups of tween
|
|
229
|
+
*/
|
|
230
|
+
var Group = /** @class */ (function () {
|
|
231
|
+
function Group() {
|
|
232
|
+
var tweens = [];
|
|
233
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
234
|
+
tweens[_i] = arguments[_i];
|
|
235
|
+
}
|
|
236
|
+
this._tweens = {};
|
|
237
|
+
this._tweensAddedDuringUpdate = {};
|
|
238
|
+
this.add.apply(this, tweens);
|
|
239
|
+
}
|
|
240
|
+
Group.prototype.getAll = function () {
|
|
241
|
+
var _this = this;
|
|
242
|
+
return Object.keys(this._tweens).map(function (tweenId) { return _this._tweens[tweenId]; });
|
|
243
|
+
};
|
|
244
|
+
Group.prototype.removeAll = function () {
|
|
245
|
+
this._tweens = {};
|
|
246
|
+
};
|
|
247
|
+
Group.prototype.add = function () {
|
|
248
|
+
var _a;
|
|
249
|
+
var tweens = [];
|
|
250
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
251
|
+
tweens[_i] = arguments[_i];
|
|
252
|
+
}
|
|
253
|
+
for (var _b = 0, tweens_1 = tweens; _b < tweens_1.length; _b++) {
|
|
254
|
+
var tween = tweens_1[_b];
|
|
255
|
+
// Remove from any other group first, a tween can only be in one group at a time.
|
|
256
|
+
// @ts-expect-error library internal access
|
|
257
|
+
(_a = tween._group) === null || _a === void 0 ? void 0 : _a.remove(tween);
|
|
258
|
+
// @ts-expect-error library internal access
|
|
259
|
+
tween._group = this;
|
|
260
|
+
this._tweens[tween.getId()] = tween;
|
|
261
|
+
this._tweensAddedDuringUpdate[tween.getId()] = tween;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
Group.prototype.remove = function () {
|
|
265
|
+
var tweens = [];
|
|
266
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
267
|
+
tweens[_i] = arguments[_i];
|
|
268
|
+
}
|
|
269
|
+
for (var _a = 0, tweens_2 = tweens; _a < tweens_2.length; _a++) {
|
|
270
|
+
var tween = tweens_2[_a];
|
|
271
|
+
// @ts-expect-error library internal access
|
|
272
|
+
tween._group = undefined;
|
|
273
|
+
delete this._tweens[tween.getId()];
|
|
274
|
+
delete this._tweensAddedDuringUpdate[tween.getId()];
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
/** Return true if all tweens in the group are not paused or playing. */
|
|
278
|
+
Group.prototype.allStopped = function () {
|
|
279
|
+
return this.getAll().every(function (tween) { return !tween.isPlaying(); });
|
|
280
|
+
};
|
|
281
|
+
Group.prototype.update = function (time, preserve) {
|
|
282
|
+
if (time === void 0) { time = now(); }
|
|
283
|
+
if (preserve === void 0) { preserve = true; }
|
|
284
|
+
var tweenIds = Object.keys(this._tweens);
|
|
285
|
+
if (tweenIds.length === 0)
|
|
286
|
+
return;
|
|
287
|
+
// Tweens are updated in "batches". If you add a new tween during an
|
|
288
|
+
// update, then the new tween will be updated in the next batch.
|
|
289
|
+
// If you remove a tween during an update, it may or may not be updated.
|
|
290
|
+
// However, if the removed tween was added during the current batch,
|
|
291
|
+
// then it will not be updated.
|
|
292
|
+
while (tweenIds.length > 0) {
|
|
293
|
+
this._tweensAddedDuringUpdate = {};
|
|
294
|
+
for (var i = 0; i < tweenIds.length; i++) {
|
|
295
|
+
var tween = this._tweens[tweenIds[i]];
|
|
296
|
+
var autoStart = !preserve;
|
|
297
|
+
if (tween && tween.update(time, autoStart) === false && !preserve)
|
|
298
|
+
this.remove(tween);
|
|
299
|
+
}
|
|
300
|
+
tweenIds = Object.keys(this._tweensAddedDuringUpdate);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
Group.prototype.onComplete = function (callback) {
|
|
304
|
+
var group = this.getAll();
|
|
305
|
+
group.forEach(function (tween) {
|
|
306
|
+
var prevCallback = tween.getCompleteCallback();
|
|
307
|
+
tween.onComplete(function () {
|
|
308
|
+
prevCallback === null || prevCallback === void 0 ? void 0 : prevCallback(tween);
|
|
309
|
+
// After the onComplete callback completes, _isPlaying is updated to false, so if the total number of completed tweens is -1, then they are all complete.
|
|
310
|
+
var completedGroup = group.filter(function (tween) { return !tween.isPlaying(); });
|
|
311
|
+
if (completedGroup.length === group.length - 1)
|
|
312
|
+
callback(group);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
return Group;
|
|
317
|
+
}());
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
*
|
|
321
|
+
*/
|
|
322
|
+
var Interpolation = {
|
|
323
|
+
Linear: function (v, k) {
|
|
324
|
+
var m = v.length - 1;
|
|
325
|
+
var f = m * k;
|
|
326
|
+
var i = Math.floor(f);
|
|
327
|
+
var fn = Interpolation.Utils.Linear;
|
|
328
|
+
if (k < 0) {
|
|
329
|
+
return fn(v[0], v[1], f);
|
|
330
|
+
}
|
|
331
|
+
if (k > 1) {
|
|
332
|
+
return fn(v[m], v[m - 1], m - f);
|
|
333
|
+
}
|
|
334
|
+
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
|
|
335
|
+
},
|
|
336
|
+
Bezier: function (v, k) {
|
|
337
|
+
var b = 0;
|
|
338
|
+
var n = v.length - 1;
|
|
339
|
+
var pw = Math.pow;
|
|
340
|
+
var bn = Interpolation.Utils.Bernstein;
|
|
341
|
+
for (var i = 0; i <= n; i++) {
|
|
342
|
+
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
|
|
343
|
+
}
|
|
344
|
+
return b;
|
|
345
|
+
},
|
|
346
|
+
CatmullRom: function (v, k) {
|
|
347
|
+
var m = v.length - 1;
|
|
348
|
+
var f = m * k;
|
|
349
|
+
var i = Math.floor(f);
|
|
350
|
+
var fn = Interpolation.Utils.CatmullRom;
|
|
351
|
+
if (v[0] === v[m]) {
|
|
352
|
+
if (k < 0) {
|
|
353
|
+
i = Math.floor((f = m * (1 + k)));
|
|
354
|
+
}
|
|
355
|
+
return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
if (k < 0) {
|
|
359
|
+
return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
|
|
360
|
+
}
|
|
361
|
+
if (k > 1) {
|
|
362
|
+
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
|
|
363
|
+
}
|
|
364
|
+
return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
Utils: {
|
|
368
|
+
Linear: function (p0, p1, t) {
|
|
369
|
+
return (p1 - p0) * t + p0;
|
|
370
|
+
},
|
|
371
|
+
Bernstein: function (n, i) {
|
|
372
|
+
var fc = Interpolation.Utils.Factorial;
|
|
373
|
+
return fc(n) / fc(i) / fc(n - i);
|
|
374
|
+
},
|
|
375
|
+
Factorial: (function () {
|
|
376
|
+
var a = [1];
|
|
377
|
+
return function (n) {
|
|
378
|
+
var s = 1;
|
|
379
|
+
if (a[n]) {
|
|
380
|
+
return a[n];
|
|
381
|
+
}
|
|
382
|
+
for (var i = n; i > 1; i--) {
|
|
383
|
+
s *= i;
|
|
384
|
+
}
|
|
385
|
+
a[n] = s;
|
|
386
|
+
return s;
|
|
387
|
+
};
|
|
388
|
+
})(),
|
|
389
|
+
CatmullRom: function (p0, p1, p2, p3, t) {
|
|
390
|
+
var v0 = (p2 - p0) * 0.5;
|
|
391
|
+
var v1 = (p3 - p1) * 0.5;
|
|
392
|
+
var t2 = t * t;
|
|
393
|
+
var t3 = t * t2;
|
|
394
|
+
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Utils
|
|
401
|
+
*/
|
|
402
|
+
var Sequence = /** @class */ (function () {
|
|
403
|
+
function Sequence() {
|
|
404
|
+
}
|
|
405
|
+
Sequence.nextId = function () {
|
|
406
|
+
return Sequence._nextId++;
|
|
407
|
+
};
|
|
408
|
+
Sequence._nextId = 0;
|
|
409
|
+
return Sequence;
|
|
410
|
+
}());
|
|
411
|
+
|
|
412
|
+
var mainGroup = new Group();
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Tween.js - Licensed under the MIT license
|
|
416
|
+
* https://github.com/tweenjs/tween.js
|
|
417
|
+
* ----------------------------------------------
|
|
418
|
+
*
|
|
419
|
+
* See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
|
|
420
|
+
* Thank you all, you're awesome!
|
|
421
|
+
*/
|
|
422
|
+
var Tween = /** @class */ (function () {
|
|
423
|
+
function Tween(object, group) {
|
|
424
|
+
this._isPaused = false;
|
|
425
|
+
this._pauseStart = 0;
|
|
426
|
+
this._valuesStart = {};
|
|
427
|
+
this._valuesEnd = {};
|
|
428
|
+
this._valuesStartRepeat = {};
|
|
429
|
+
this._duration = 0;
|
|
430
|
+
this._isDynamic = false;
|
|
431
|
+
this._initialRepeat = 0;
|
|
432
|
+
this._repeat = 0;
|
|
433
|
+
this._yoyo = false;
|
|
434
|
+
this._isPlaying = false;
|
|
435
|
+
this._reversed = false;
|
|
436
|
+
this._delayTime = 0;
|
|
437
|
+
this._startTime = 0;
|
|
438
|
+
this._easingFunction = Easing.Linear.None;
|
|
439
|
+
this._interpolationFunction = Interpolation.Linear;
|
|
440
|
+
// eslint-disable-next-line
|
|
441
|
+
this._chainedTweens = [];
|
|
442
|
+
this._onStartCallbackFired = false;
|
|
443
|
+
this._onEveryStartCallbackFired = false;
|
|
444
|
+
this._id = Sequence.nextId();
|
|
445
|
+
this._isChainStopped = false;
|
|
446
|
+
this._propertiesAreSetUp = false;
|
|
447
|
+
this._goToEnd = false;
|
|
448
|
+
this._object = object !== null && object !== void 0 ? object : {};
|
|
449
|
+
if (typeof group === 'object') {
|
|
450
|
+
this._group = group;
|
|
451
|
+
group.add(this);
|
|
452
|
+
}
|
|
453
|
+
// Use "true" to restore old behavior (will be removed in future release).
|
|
454
|
+
else if (group === true) {
|
|
455
|
+
this._group = mainGroup;
|
|
456
|
+
mainGroup.add(this);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
Tween.prototype.getId = function () {
|
|
460
|
+
return this._id;
|
|
461
|
+
};
|
|
462
|
+
Tween.prototype.getCompleteCallback = function () {
|
|
463
|
+
return this._onCompleteCallback;
|
|
464
|
+
};
|
|
465
|
+
Tween.prototype.isPlaying = function () {
|
|
466
|
+
return this._isPlaying;
|
|
467
|
+
};
|
|
468
|
+
Tween.prototype.isPaused = function () {
|
|
469
|
+
return this._isPaused;
|
|
470
|
+
};
|
|
471
|
+
Tween.prototype.getDuration = function () {
|
|
472
|
+
return this._duration;
|
|
473
|
+
};
|
|
474
|
+
Tween.prototype.to = function (target, duration) {
|
|
475
|
+
if (this._isPlaying)
|
|
476
|
+
throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');
|
|
477
|
+
this._valuesEnd = target;
|
|
478
|
+
this._propertiesAreSetUp = false;
|
|
479
|
+
if (duration !== undefined) {
|
|
480
|
+
this._duration = duration < 0 ? 0 : duration;
|
|
481
|
+
}
|
|
482
|
+
return this;
|
|
483
|
+
};
|
|
484
|
+
Tween.prototype.duration = function (duration) {
|
|
485
|
+
if (duration === void 0) { duration = 1000; }
|
|
486
|
+
this._duration = duration < 0 ? 0 : duration;
|
|
487
|
+
return this;
|
|
488
|
+
};
|
|
489
|
+
Tween.prototype.dynamic = function (dynamic) {
|
|
490
|
+
if (dynamic === void 0) { dynamic = false; }
|
|
491
|
+
this._isDynamic = dynamic;
|
|
492
|
+
return this;
|
|
493
|
+
};
|
|
494
|
+
Tween.prototype.start = function (time, overrideStartingValues) {
|
|
495
|
+
if (time === void 0) { time = now(); }
|
|
496
|
+
if (overrideStartingValues === void 0) { overrideStartingValues = false; }
|
|
497
|
+
if (this._isPlaying) {
|
|
498
|
+
return this;
|
|
499
|
+
}
|
|
500
|
+
this._repeat = this._initialRepeat;
|
|
501
|
+
if (this._reversed) {
|
|
502
|
+
// If we were reversed (f.e. using the yoyo feature) then we need to
|
|
503
|
+
// flip the tween direction back to forward.
|
|
504
|
+
this._reversed = false;
|
|
505
|
+
for (var property in this._valuesStartRepeat) {
|
|
506
|
+
this._swapEndStartRepeatValues(property);
|
|
507
|
+
this._valuesStart[property] = this._valuesStartRepeat[property];
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
this._isPlaying = true;
|
|
511
|
+
this._isPaused = false;
|
|
512
|
+
this._onStartCallbackFired = false;
|
|
513
|
+
this._onEveryStartCallbackFired = false;
|
|
514
|
+
this._isChainStopped = false;
|
|
515
|
+
this._startTime = time;
|
|
516
|
+
this._startTime += this._delayTime;
|
|
517
|
+
if (!this._propertiesAreSetUp || overrideStartingValues) {
|
|
518
|
+
this._propertiesAreSetUp = true;
|
|
519
|
+
// If dynamic is not enabled, clone the end values instead of using the passed-in end values.
|
|
520
|
+
if (!this._isDynamic) {
|
|
521
|
+
var tmp = {};
|
|
522
|
+
for (var prop in this._valuesEnd)
|
|
523
|
+
tmp[prop] = this._valuesEnd[prop];
|
|
524
|
+
this._valuesEnd = tmp;
|
|
525
|
+
}
|
|
526
|
+
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
|
|
527
|
+
}
|
|
528
|
+
return this;
|
|
529
|
+
};
|
|
530
|
+
Tween.prototype.startFromCurrentValues = function (time) {
|
|
531
|
+
return this.start(time, true);
|
|
532
|
+
};
|
|
533
|
+
Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
|
|
534
|
+
for (var property in _valuesEnd) {
|
|
535
|
+
var startValue = _object[property];
|
|
536
|
+
var startValueIsArray = Array.isArray(startValue);
|
|
537
|
+
var propType = startValueIsArray ? 'array' : typeof startValue;
|
|
538
|
+
var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
|
|
539
|
+
// If `to()` specifies a property that doesn't exist in the source object,
|
|
540
|
+
// we should not set that property in the object
|
|
541
|
+
if (propType === 'undefined' || propType === 'function') {
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
// Check if an Array was provided as property value
|
|
545
|
+
if (isInterpolationList) {
|
|
546
|
+
var endValues = _valuesEnd[property];
|
|
547
|
+
if (endValues.length === 0) {
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
// Handle an array of relative values.
|
|
551
|
+
// Creates a local copy of the Array with the start value at the front
|
|
552
|
+
var temp = [startValue];
|
|
553
|
+
for (var i = 0, l = endValues.length; i < l; i += 1) {
|
|
554
|
+
var value = this._handleRelativeValue(startValue, endValues[i]);
|
|
555
|
+
if (isNaN(value)) {
|
|
556
|
+
isInterpolationList = false;
|
|
557
|
+
console.warn('Found invalid interpolation list. Skipping.');
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
temp.push(value);
|
|
561
|
+
}
|
|
562
|
+
if (isInterpolationList) {
|
|
563
|
+
// if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
|
|
564
|
+
_valuesEnd[property] = temp;
|
|
565
|
+
// }
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
// handle the deepness of the values
|
|
569
|
+
if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
|
|
570
|
+
_valuesStart[property] = startValueIsArray ? [] : {};
|
|
571
|
+
var nestedObject = startValue;
|
|
572
|
+
for (var prop in nestedObject) {
|
|
573
|
+
_valuesStart[property][prop] = nestedObject[prop];
|
|
574
|
+
}
|
|
575
|
+
// TODO? repeat nested values? And yoyo? And array values?
|
|
576
|
+
_valuesStartRepeat[property] = startValueIsArray ? [] : {};
|
|
577
|
+
var endValues = _valuesEnd[property];
|
|
578
|
+
// If dynamic is not enabled, clone the end values instead of using the passed-in end values.
|
|
579
|
+
if (!this._isDynamic) {
|
|
580
|
+
var tmp = {};
|
|
581
|
+
for (var prop in endValues)
|
|
582
|
+
tmp[prop] = endValues[prop];
|
|
583
|
+
_valuesEnd[property] = endValues = tmp;
|
|
584
|
+
}
|
|
585
|
+
this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
// Save the starting value, but only once unless override is requested.
|
|
589
|
+
if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
|
|
590
|
+
_valuesStart[property] = startValue;
|
|
591
|
+
}
|
|
592
|
+
if (!startValueIsArray) {
|
|
593
|
+
// eslint-disable-next-line
|
|
594
|
+
// @ts-ignore FIXME?
|
|
595
|
+
_valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
|
|
596
|
+
}
|
|
597
|
+
if (isInterpolationList) {
|
|
598
|
+
// eslint-disable-next-line
|
|
599
|
+
// @ts-ignore FIXME?
|
|
600
|
+
_valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
_valuesStartRepeat[property] = _valuesStart[property] || 0;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
Tween.prototype.stop = function () {
|
|
609
|
+
if (!this._isChainStopped) {
|
|
610
|
+
this._isChainStopped = true;
|
|
611
|
+
this.stopChainedTweens();
|
|
612
|
+
}
|
|
613
|
+
if (!this._isPlaying) {
|
|
614
|
+
return this;
|
|
615
|
+
}
|
|
616
|
+
this._isPlaying = false;
|
|
617
|
+
this._isPaused = false;
|
|
618
|
+
if (this._onStopCallback) {
|
|
619
|
+
this._onStopCallback(this._object);
|
|
620
|
+
}
|
|
621
|
+
return this;
|
|
622
|
+
};
|
|
623
|
+
Tween.prototype.end = function () {
|
|
624
|
+
this._goToEnd = true;
|
|
625
|
+
this.update(this._startTime + this._duration);
|
|
626
|
+
return this;
|
|
627
|
+
};
|
|
628
|
+
Tween.prototype.pause = function (time) {
|
|
629
|
+
if (time === void 0) { time = now(); }
|
|
630
|
+
if (this._isPaused || !this._isPlaying) {
|
|
631
|
+
return this;
|
|
632
|
+
}
|
|
633
|
+
this._isPaused = true;
|
|
634
|
+
this._pauseStart = time;
|
|
635
|
+
return this;
|
|
636
|
+
};
|
|
637
|
+
Tween.prototype.resume = function (time) {
|
|
638
|
+
if (time === void 0) { time = now(); }
|
|
639
|
+
if (!this._isPaused || !this._isPlaying) {
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
this._isPaused = false;
|
|
643
|
+
this._startTime += time - this._pauseStart;
|
|
644
|
+
this._pauseStart = 0;
|
|
645
|
+
return this;
|
|
646
|
+
};
|
|
647
|
+
Tween.prototype.stopChainedTweens = function () {
|
|
648
|
+
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
|
|
649
|
+
this._chainedTweens[i].stop();
|
|
650
|
+
}
|
|
651
|
+
return this;
|
|
652
|
+
};
|
|
653
|
+
Tween.prototype.group = function (group) {
|
|
654
|
+
if (!group) {
|
|
655
|
+
console.warn('tween.group() without args has been removed, use group.add(tween) instead.');
|
|
656
|
+
return this;
|
|
657
|
+
}
|
|
658
|
+
group.add(this);
|
|
659
|
+
return this;
|
|
660
|
+
};
|
|
661
|
+
/**
|
|
662
|
+
* Removes the tween from whichever group it is in.
|
|
663
|
+
*/
|
|
664
|
+
Tween.prototype.remove = function () {
|
|
665
|
+
var _a;
|
|
666
|
+
(_a = this._group) === null || _a === void 0 ? void 0 : _a.remove(this);
|
|
667
|
+
return this;
|
|
668
|
+
};
|
|
669
|
+
Tween.prototype.delay = function (amount) {
|
|
670
|
+
if (amount === void 0) { amount = 0; }
|
|
671
|
+
this._delayTime = amount;
|
|
672
|
+
return this;
|
|
673
|
+
};
|
|
674
|
+
Tween.prototype.repeat = function (times) {
|
|
675
|
+
if (times === void 0) { times = 0; }
|
|
676
|
+
this._initialRepeat = times;
|
|
677
|
+
this._repeat = times;
|
|
678
|
+
return this;
|
|
679
|
+
};
|
|
680
|
+
Tween.prototype.repeatDelay = function (amount) {
|
|
681
|
+
this._repeatDelayTime = amount;
|
|
682
|
+
return this;
|
|
683
|
+
};
|
|
684
|
+
Tween.prototype.yoyo = function (yoyo) {
|
|
685
|
+
if (yoyo === void 0) { yoyo = false; }
|
|
686
|
+
this._yoyo = yoyo;
|
|
687
|
+
return this;
|
|
688
|
+
};
|
|
689
|
+
Tween.prototype.easing = function (easingFunction) {
|
|
690
|
+
if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
|
|
691
|
+
this._easingFunction = easingFunction;
|
|
692
|
+
return this;
|
|
693
|
+
};
|
|
694
|
+
Tween.prototype.interpolation = function (interpolationFunction) {
|
|
695
|
+
if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
|
|
696
|
+
this._interpolationFunction = interpolationFunction;
|
|
697
|
+
return this;
|
|
698
|
+
};
|
|
699
|
+
// eslint-disable-next-line
|
|
700
|
+
Tween.prototype.chain = function () {
|
|
701
|
+
var tweens = [];
|
|
702
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
703
|
+
tweens[_i] = arguments[_i];
|
|
704
|
+
}
|
|
705
|
+
this._chainedTweens = tweens;
|
|
706
|
+
return this;
|
|
707
|
+
};
|
|
708
|
+
Tween.prototype.onStart = function (callback) {
|
|
709
|
+
this._onStartCallback = callback;
|
|
710
|
+
return this;
|
|
711
|
+
};
|
|
712
|
+
Tween.prototype.onEveryStart = function (callback) {
|
|
713
|
+
this._onEveryStartCallback = callback;
|
|
714
|
+
return this;
|
|
715
|
+
};
|
|
716
|
+
Tween.prototype.onUpdate = function (callback) {
|
|
717
|
+
this._onUpdateCallback = callback;
|
|
718
|
+
return this;
|
|
719
|
+
};
|
|
720
|
+
Tween.prototype.onRepeat = function (callback) {
|
|
721
|
+
this._onRepeatCallback = callback;
|
|
722
|
+
return this;
|
|
723
|
+
};
|
|
724
|
+
Tween.prototype.onComplete = function (callback) {
|
|
725
|
+
this._onCompleteCallback = callback;
|
|
726
|
+
return this;
|
|
727
|
+
};
|
|
728
|
+
Tween.prototype.onStop = function (callback) {
|
|
729
|
+
this._onStopCallback = callback;
|
|
730
|
+
return this;
|
|
731
|
+
};
|
|
732
|
+
/**
|
|
733
|
+
* @returns true if the tween is still playing after the update, false
|
|
734
|
+
* otherwise (calling update on a paused tween still returns true because
|
|
735
|
+
* it is still playing, just paused).
|
|
736
|
+
*
|
|
737
|
+
* @param autoStart - When true, calling update will implicitly call start()
|
|
738
|
+
* as well. Note, if you stop() or end() the tween, but are still calling
|
|
739
|
+
* update(), it will start again!
|
|
740
|
+
*/
|
|
741
|
+
Tween.prototype.update = function (time, autoStart) {
|
|
742
|
+
var _this = this;
|
|
743
|
+
var _a;
|
|
744
|
+
if (time === void 0) { time = now(); }
|
|
745
|
+
if (autoStart === void 0) { autoStart = Tween.autoStartOnUpdate; }
|
|
746
|
+
if (this._isPaused)
|
|
747
|
+
return true;
|
|
748
|
+
var property;
|
|
749
|
+
if (!this._goToEnd && !this._isPlaying) {
|
|
750
|
+
if (autoStart)
|
|
751
|
+
this.start(time, true);
|
|
752
|
+
else
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
this._goToEnd = false;
|
|
756
|
+
if (time < this._startTime) {
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
if (this._onStartCallbackFired === false) {
|
|
760
|
+
if (this._onStartCallback) {
|
|
761
|
+
this._onStartCallback(this._object);
|
|
762
|
+
}
|
|
763
|
+
this._onStartCallbackFired = true;
|
|
764
|
+
}
|
|
765
|
+
if (this._onEveryStartCallbackFired === false) {
|
|
766
|
+
if (this._onEveryStartCallback) {
|
|
767
|
+
this._onEveryStartCallback(this._object);
|
|
768
|
+
}
|
|
769
|
+
this._onEveryStartCallbackFired = true;
|
|
770
|
+
}
|
|
771
|
+
var elapsedTime = time - this._startTime;
|
|
772
|
+
var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
|
|
773
|
+
var totalTime = this._duration + this._repeat * durationAndDelay;
|
|
774
|
+
var calculateElapsedPortion = function () {
|
|
775
|
+
if (_this._duration === 0)
|
|
776
|
+
return 1;
|
|
777
|
+
if (elapsedTime > totalTime) {
|
|
778
|
+
return 1;
|
|
779
|
+
}
|
|
780
|
+
var timesRepeated = Math.trunc(elapsedTime / durationAndDelay);
|
|
781
|
+
var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay;
|
|
782
|
+
// TODO use %?
|
|
783
|
+
// const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
|
|
784
|
+
var portion = Math.min(timeIntoCurrentRepeat / _this._duration, 1);
|
|
785
|
+
if (portion === 0 && elapsedTime === _this._duration) {
|
|
786
|
+
return 1;
|
|
787
|
+
}
|
|
788
|
+
return portion;
|
|
789
|
+
};
|
|
790
|
+
var elapsed = calculateElapsedPortion();
|
|
791
|
+
var value = this._easingFunction(elapsed);
|
|
792
|
+
// properties transformations
|
|
793
|
+
this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
|
|
794
|
+
if (this._onUpdateCallback) {
|
|
795
|
+
this._onUpdateCallback(this._object, elapsed);
|
|
796
|
+
}
|
|
797
|
+
if (this._duration === 0 || elapsedTime >= this._duration) {
|
|
798
|
+
if (this._repeat > 0) {
|
|
799
|
+
var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
|
|
800
|
+
if (isFinite(this._repeat)) {
|
|
801
|
+
this._repeat -= completeCount;
|
|
802
|
+
}
|
|
803
|
+
// Reassign starting values, restart by making startTime = now
|
|
804
|
+
for (property in this._valuesStartRepeat) {
|
|
805
|
+
if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
|
|
806
|
+
this._valuesStartRepeat[property] =
|
|
807
|
+
// eslint-disable-next-line
|
|
808
|
+
// @ts-ignore FIXME?
|
|
809
|
+
this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
|
|
810
|
+
}
|
|
811
|
+
if (this._yoyo) {
|
|
812
|
+
this._swapEndStartRepeatValues(property);
|
|
813
|
+
}
|
|
814
|
+
this._valuesStart[property] = this._valuesStartRepeat[property];
|
|
815
|
+
}
|
|
816
|
+
if (this._yoyo) {
|
|
817
|
+
this._reversed = !this._reversed;
|
|
818
|
+
}
|
|
819
|
+
this._startTime += durationAndDelay * completeCount;
|
|
820
|
+
if (this._onRepeatCallback) {
|
|
821
|
+
this._onRepeatCallback(this._object);
|
|
822
|
+
}
|
|
823
|
+
this._onEveryStartCallbackFired = false;
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
else {
|
|
827
|
+
if (this._onCompleteCallback) {
|
|
828
|
+
this._onCompleteCallback(this._object);
|
|
829
|
+
}
|
|
830
|
+
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
|
|
831
|
+
// Make the chained tweens start exactly at the time they should,
|
|
832
|
+
// even if the `update()` method was called way past the duration of the tween
|
|
833
|
+
this._chainedTweens[i].start(this._startTime + this._duration, false);
|
|
834
|
+
}
|
|
835
|
+
this._isPlaying = false;
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return true;
|
|
840
|
+
};
|
|
841
|
+
Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
|
|
842
|
+
for (var property in _valuesEnd) {
|
|
843
|
+
// Don't update properties that do not exist in the source object
|
|
844
|
+
if (_valuesStart[property] === undefined) {
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
var start = _valuesStart[property] || 0;
|
|
848
|
+
var end = _valuesEnd[property];
|
|
849
|
+
var startIsArray = Array.isArray(_object[property]);
|
|
850
|
+
var endIsArray = Array.isArray(end);
|
|
851
|
+
var isInterpolationList = !startIsArray && endIsArray;
|
|
852
|
+
if (isInterpolationList) {
|
|
853
|
+
_object[property] = this._interpolationFunction(end, value);
|
|
854
|
+
}
|
|
855
|
+
else if (typeof end === 'object' && end) {
|
|
856
|
+
// eslint-disable-next-line
|
|
857
|
+
// @ts-ignore FIXME?
|
|
858
|
+
this._updateProperties(_object[property], start, end, value);
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
// Parses relative end values with start as base (e.g.: +10, -3)
|
|
862
|
+
end = this._handleRelativeValue(start, end);
|
|
863
|
+
// Protect against non numeric properties.
|
|
864
|
+
if (typeof end === 'number') {
|
|
865
|
+
// eslint-disable-next-line
|
|
866
|
+
// @ts-ignore FIXME?
|
|
867
|
+
_object[property] = start + (end - start) * value;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
Tween.prototype._handleRelativeValue = function (start, end) {
|
|
873
|
+
if (typeof end !== 'string') {
|
|
874
|
+
return end;
|
|
875
|
+
}
|
|
876
|
+
if (end.charAt(0) === '+' || end.charAt(0) === '-') {
|
|
877
|
+
return start + parseFloat(end);
|
|
878
|
+
}
|
|
879
|
+
return parseFloat(end);
|
|
880
|
+
};
|
|
881
|
+
Tween.prototype._swapEndStartRepeatValues = function (property) {
|
|
882
|
+
var tmp = this._valuesStartRepeat[property];
|
|
883
|
+
var endValue = this._valuesEnd[property];
|
|
884
|
+
if (typeof endValue === 'string') {
|
|
885
|
+
this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
this._valuesStartRepeat[property] = this._valuesEnd[property];
|
|
889
|
+
}
|
|
890
|
+
this._valuesEnd[property] = tmp;
|
|
891
|
+
};
|
|
892
|
+
Tween.autoStartOnUpdate = false;
|
|
893
|
+
Tween.Sequence = function () {
|
|
894
|
+
var tweens = [];
|
|
895
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
896
|
+
tweens[_i] = arguments[_i];
|
|
897
|
+
}
|
|
898
|
+
tweens.reduce(function (prev, next) {
|
|
899
|
+
prev === null || prev === void 0 ? void 0 : prev.chain(next);
|
|
900
|
+
return next;
|
|
901
|
+
});
|
|
902
|
+
return tweens[0];
|
|
903
|
+
};
|
|
904
|
+
return Tween;
|
|
905
|
+
}());
|
|
906
|
+
|
|
907
|
+
var VERSION = '25.0.0';
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Tween.js - Licensed under the MIT license
|
|
911
|
+
* https://github.com/tweenjs/tween.js
|
|
912
|
+
* ----------------------------------------------
|
|
913
|
+
*
|
|
914
|
+
* See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
|
|
915
|
+
* Thank you all, you're awesome!
|
|
916
|
+
*/
|
|
917
|
+
var nextId = Sequence.nextId;
|
|
918
|
+
/**
|
|
919
|
+
* Controlling groups of tweens
|
|
920
|
+
*
|
|
921
|
+
* Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
|
|
922
|
+
* In these cases, you may want to create your own smaller groups of tweens.
|
|
923
|
+
*/
|
|
924
|
+
var TWEEN = mainGroup;
|
|
925
|
+
// This is the best way to export things in a way that's compatible with both ES
|
|
926
|
+
// Modules and CommonJS, without build hacks, and so as not to break the
|
|
927
|
+
// existing API.
|
|
928
|
+
// https://github.com/rollup/rollup/issues/1961#issuecomment-423037881
|
|
929
|
+
/**
|
|
930
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
931
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
932
|
+
* group.
|
|
933
|
+
*
|
|
934
|
+
* Old code:
|
|
935
|
+
*
|
|
936
|
+
* ```js
|
|
937
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
938
|
+
*
|
|
939
|
+
* //...
|
|
940
|
+
*
|
|
941
|
+
* const tween = new TWEEN.Tween(obj)
|
|
942
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
943
|
+
*
|
|
944
|
+
* //...
|
|
945
|
+
*
|
|
946
|
+
* requestAnimationFrame(function loop(time) {
|
|
947
|
+
* TWEEN.update(time)
|
|
948
|
+
* requestAnimationFrame(loop)
|
|
949
|
+
* })
|
|
950
|
+
* ```
|
|
951
|
+
*
|
|
952
|
+
* New code:
|
|
953
|
+
*
|
|
954
|
+
* ```js
|
|
955
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
956
|
+
*
|
|
957
|
+
* //...
|
|
958
|
+
*
|
|
959
|
+
* const tween = new Tween(obj)
|
|
960
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
961
|
+
*
|
|
962
|
+
* //...
|
|
963
|
+
*
|
|
964
|
+
* const group = new Group()
|
|
965
|
+
* group.add(tween)
|
|
966
|
+
* group.add(tween2)
|
|
967
|
+
*
|
|
968
|
+
* //...
|
|
969
|
+
*
|
|
970
|
+
* requestAnimationFrame(function loop(time) {
|
|
971
|
+
* group.update(time)
|
|
972
|
+
* requestAnimationFrame(loop)
|
|
973
|
+
* })
|
|
974
|
+
* ```
|
|
975
|
+
*/
|
|
976
|
+
var getAll = TWEEN.getAll.bind(TWEEN);
|
|
977
|
+
/**
|
|
978
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
979
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
980
|
+
* group.
|
|
981
|
+
*
|
|
982
|
+
* Old code:
|
|
983
|
+
*
|
|
984
|
+
* ```js
|
|
985
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
986
|
+
*
|
|
987
|
+
* //...
|
|
988
|
+
*
|
|
989
|
+
* const tween = new TWEEN.Tween(obj)
|
|
990
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
991
|
+
*
|
|
992
|
+
* //...
|
|
993
|
+
*
|
|
994
|
+
* requestAnimationFrame(function loop(time) {
|
|
995
|
+
* TWEEN.update(time)
|
|
996
|
+
* requestAnimationFrame(loop)
|
|
997
|
+
* })
|
|
998
|
+
* ```
|
|
999
|
+
*
|
|
1000
|
+
* New code:
|
|
1001
|
+
*
|
|
1002
|
+
* ```js
|
|
1003
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1004
|
+
*
|
|
1005
|
+
* //...
|
|
1006
|
+
*
|
|
1007
|
+
* const tween = new Tween(obj)
|
|
1008
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1009
|
+
*
|
|
1010
|
+
* //...
|
|
1011
|
+
*
|
|
1012
|
+
* const group = new Group()
|
|
1013
|
+
* group.add(tween)
|
|
1014
|
+
* group.add(tween2)
|
|
1015
|
+
*
|
|
1016
|
+
* //...
|
|
1017
|
+
*
|
|
1018
|
+
* requestAnimationFrame(function loop(time) {
|
|
1019
|
+
* group.update(time)
|
|
1020
|
+
* requestAnimationFrame(loop)
|
|
1021
|
+
* })
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
var removeAll = TWEEN.removeAll.bind(TWEEN);
|
|
1025
|
+
/**
|
|
1026
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1027
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1028
|
+
* group.
|
|
1029
|
+
*
|
|
1030
|
+
* Old code:
|
|
1031
|
+
*
|
|
1032
|
+
* ```js
|
|
1033
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1034
|
+
*
|
|
1035
|
+
* //...
|
|
1036
|
+
*
|
|
1037
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1038
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1039
|
+
*
|
|
1040
|
+
* //...
|
|
1041
|
+
*
|
|
1042
|
+
* requestAnimationFrame(function loop(time) {
|
|
1043
|
+
* TWEEN.update(time)
|
|
1044
|
+
* requestAnimationFrame(loop)
|
|
1045
|
+
* })
|
|
1046
|
+
* ```
|
|
1047
|
+
*
|
|
1048
|
+
* New code:
|
|
1049
|
+
*
|
|
1050
|
+
* ```js
|
|
1051
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1052
|
+
*
|
|
1053
|
+
* //...
|
|
1054
|
+
*
|
|
1055
|
+
* const tween = new Tween(obj)
|
|
1056
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1057
|
+
*
|
|
1058
|
+
* //...
|
|
1059
|
+
*
|
|
1060
|
+
* const group = new Group()
|
|
1061
|
+
* group.add(tween)
|
|
1062
|
+
* group.add(tween2)
|
|
1063
|
+
*
|
|
1064
|
+
* //...
|
|
1065
|
+
*
|
|
1066
|
+
* requestAnimationFrame(function loop(time) {
|
|
1067
|
+
* group.update(time)
|
|
1068
|
+
* requestAnimationFrame(loop)
|
|
1069
|
+
* })
|
|
1070
|
+
* ```
|
|
1071
|
+
*/
|
|
1072
|
+
var add = TWEEN.add.bind(TWEEN);
|
|
1073
|
+
/**
|
|
1074
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1075
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1076
|
+
* group.
|
|
1077
|
+
*
|
|
1078
|
+
* Old code:
|
|
1079
|
+
*
|
|
1080
|
+
* ```js
|
|
1081
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1082
|
+
*
|
|
1083
|
+
* //...
|
|
1084
|
+
*
|
|
1085
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1086
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1087
|
+
*
|
|
1088
|
+
* //...
|
|
1089
|
+
*
|
|
1090
|
+
* requestAnimationFrame(function loop(time) {
|
|
1091
|
+
* TWEEN.update(time)
|
|
1092
|
+
* requestAnimationFrame(loop)
|
|
1093
|
+
* })
|
|
1094
|
+
* ```
|
|
1095
|
+
*
|
|
1096
|
+
* New code:
|
|
1097
|
+
*
|
|
1098
|
+
* ```js
|
|
1099
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1100
|
+
*
|
|
1101
|
+
* //...
|
|
1102
|
+
*
|
|
1103
|
+
* const tween = new Tween(obj)
|
|
1104
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1105
|
+
*
|
|
1106
|
+
* //...
|
|
1107
|
+
*
|
|
1108
|
+
* const group = new Group()
|
|
1109
|
+
* group.add(tween)
|
|
1110
|
+
* group.add(tween2)
|
|
1111
|
+
*
|
|
1112
|
+
* //...
|
|
1113
|
+
*
|
|
1114
|
+
* requestAnimationFrame(function loop(time) {
|
|
1115
|
+
* group.update(time)
|
|
1116
|
+
* requestAnimationFrame(loop)
|
|
1117
|
+
* })
|
|
1118
|
+
* ```
|
|
1119
|
+
*/
|
|
1120
|
+
var remove = TWEEN.remove.bind(TWEEN);
|
|
1121
|
+
/**
|
|
1122
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1123
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1124
|
+
* group.
|
|
1125
|
+
*
|
|
1126
|
+
* Old code:
|
|
1127
|
+
*
|
|
1128
|
+
* ```js
|
|
1129
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1130
|
+
*
|
|
1131
|
+
* //...
|
|
1132
|
+
*
|
|
1133
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1134
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1135
|
+
*
|
|
1136
|
+
* //...
|
|
1137
|
+
*
|
|
1138
|
+
* requestAnimationFrame(function loop(time) {
|
|
1139
|
+
* TWEEN.update(time)
|
|
1140
|
+
* requestAnimationFrame(loop)
|
|
1141
|
+
* })
|
|
1142
|
+
* ```
|
|
1143
|
+
*
|
|
1144
|
+
* New code:
|
|
1145
|
+
*
|
|
1146
|
+
* ```js
|
|
1147
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1148
|
+
*
|
|
1149
|
+
* //...
|
|
1150
|
+
*
|
|
1151
|
+
* const tween = new Tween(obj)
|
|
1152
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1153
|
+
*
|
|
1154
|
+
* //...
|
|
1155
|
+
*
|
|
1156
|
+
* const group = new Group()
|
|
1157
|
+
* group.add(tween)
|
|
1158
|
+
* group.add(tween2)
|
|
1159
|
+
*
|
|
1160
|
+
* //...
|
|
1161
|
+
*
|
|
1162
|
+
* requestAnimationFrame(function loop(time) {
|
|
1163
|
+
* group.update(time)
|
|
1164
|
+
* requestAnimationFrame(loop)
|
|
1165
|
+
* })
|
|
1166
|
+
* ```
|
|
1167
|
+
*/
|
|
1168
|
+
var update = TWEEN.update.bind(TWEEN);
|
|
1169
|
+
var exports = {
|
|
1170
|
+
Easing: Easing,
|
|
1171
|
+
Group: Group,
|
|
1172
|
+
Interpolation: Interpolation,
|
|
1173
|
+
now: now,
|
|
1174
|
+
setNow: setNow,
|
|
1175
|
+
Sequence: Sequence,
|
|
1176
|
+
nextId: nextId,
|
|
1177
|
+
Tween: Tween,
|
|
1178
|
+
VERSION: VERSION,
|
|
1179
|
+
/**
|
|
1180
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1181
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1182
|
+
* group.
|
|
1183
|
+
*
|
|
1184
|
+
* Old code:
|
|
1185
|
+
*
|
|
1186
|
+
* ```js
|
|
1187
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1188
|
+
*
|
|
1189
|
+
* //...
|
|
1190
|
+
*
|
|
1191
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1192
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1193
|
+
*
|
|
1194
|
+
* //...
|
|
1195
|
+
*
|
|
1196
|
+
* requestAnimationFrame(function loop(time) {
|
|
1197
|
+
* TWEEN.update(time)
|
|
1198
|
+
* requestAnimationFrame(loop)
|
|
1199
|
+
* })
|
|
1200
|
+
* ```
|
|
1201
|
+
*
|
|
1202
|
+
* New code:
|
|
1203
|
+
*
|
|
1204
|
+
* ```js
|
|
1205
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1206
|
+
*
|
|
1207
|
+
* //...
|
|
1208
|
+
*
|
|
1209
|
+
* const tween = new Tween(obj)
|
|
1210
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1211
|
+
*
|
|
1212
|
+
* //...
|
|
1213
|
+
*
|
|
1214
|
+
* const group = new Group()
|
|
1215
|
+
* group.add(tween)
|
|
1216
|
+
* group.add(tween2)
|
|
1217
|
+
*
|
|
1218
|
+
* //...
|
|
1219
|
+
*
|
|
1220
|
+
* requestAnimationFrame(function loop(time) {
|
|
1221
|
+
* group.update(time)
|
|
1222
|
+
* requestAnimationFrame(loop)
|
|
1223
|
+
* })
|
|
1224
|
+
* ```
|
|
1225
|
+
*/
|
|
1226
|
+
getAll: getAll,
|
|
1227
|
+
/**
|
|
1228
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1229
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1230
|
+
* group.
|
|
1231
|
+
*
|
|
1232
|
+
* Old code:
|
|
1233
|
+
*
|
|
1234
|
+
* ```js
|
|
1235
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1236
|
+
*
|
|
1237
|
+
* //...
|
|
1238
|
+
*
|
|
1239
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1240
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1241
|
+
*
|
|
1242
|
+
* //...
|
|
1243
|
+
*
|
|
1244
|
+
* requestAnimationFrame(function loop(time) {
|
|
1245
|
+
* TWEEN.update(time)
|
|
1246
|
+
* requestAnimationFrame(loop)
|
|
1247
|
+
* })
|
|
1248
|
+
* ```
|
|
1249
|
+
*
|
|
1250
|
+
* New code:
|
|
1251
|
+
*
|
|
1252
|
+
* ```js
|
|
1253
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1254
|
+
*
|
|
1255
|
+
* //...
|
|
1256
|
+
*
|
|
1257
|
+
* const tween = new Tween(obj)
|
|
1258
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1259
|
+
*
|
|
1260
|
+
* //...
|
|
1261
|
+
*
|
|
1262
|
+
* const group = new Group()
|
|
1263
|
+
* group.add(tween)
|
|
1264
|
+
* group.add(tween2)
|
|
1265
|
+
*
|
|
1266
|
+
* //...
|
|
1267
|
+
*
|
|
1268
|
+
* requestAnimationFrame(function loop(time) {
|
|
1269
|
+
* group.update(time)
|
|
1270
|
+
* requestAnimationFrame(loop)
|
|
1271
|
+
* })
|
|
1272
|
+
* ```
|
|
1273
|
+
*/
|
|
1274
|
+
removeAll: removeAll,
|
|
1275
|
+
/**
|
|
1276
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1277
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1278
|
+
* group.
|
|
1279
|
+
*
|
|
1280
|
+
* Old code:
|
|
1281
|
+
*
|
|
1282
|
+
* ```js
|
|
1283
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1284
|
+
*
|
|
1285
|
+
* //...
|
|
1286
|
+
*
|
|
1287
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1288
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1289
|
+
*
|
|
1290
|
+
* //...
|
|
1291
|
+
*
|
|
1292
|
+
* requestAnimationFrame(function loop(time) {
|
|
1293
|
+
* TWEEN.update(time)
|
|
1294
|
+
* requestAnimationFrame(loop)
|
|
1295
|
+
* })
|
|
1296
|
+
* ```
|
|
1297
|
+
*
|
|
1298
|
+
* New code:
|
|
1299
|
+
*
|
|
1300
|
+
* ```js
|
|
1301
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1302
|
+
*
|
|
1303
|
+
* //...
|
|
1304
|
+
*
|
|
1305
|
+
* const tween = new Tween(obj)
|
|
1306
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1307
|
+
*
|
|
1308
|
+
* //...
|
|
1309
|
+
*
|
|
1310
|
+
* const group = new Group()
|
|
1311
|
+
* group.add(tween)
|
|
1312
|
+
* group.add(tween2)
|
|
1313
|
+
*
|
|
1314
|
+
* //...
|
|
1315
|
+
*
|
|
1316
|
+
* requestAnimationFrame(function loop(time) {
|
|
1317
|
+
* group.update(time)
|
|
1318
|
+
* requestAnimationFrame(loop)
|
|
1319
|
+
* })
|
|
1320
|
+
* ```
|
|
1321
|
+
*/
|
|
1322
|
+
add: add,
|
|
1323
|
+
/**
|
|
1324
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1325
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1326
|
+
* group.
|
|
1327
|
+
*
|
|
1328
|
+
* Old code:
|
|
1329
|
+
*
|
|
1330
|
+
* ```js
|
|
1331
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1332
|
+
*
|
|
1333
|
+
* //...
|
|
1334
|
+
*
|
|
1335
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1336
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1337
|
+
*
|
|
1338
|
+
* //...
|
|
1339
|
+
*
|
|
1340
|
+
* requestAnimationFrame(function loop(time) {
|
|
1341
|
+
* TWEEN.update(time)
|
|
1342
|
+
* requestAnimationFrame(loop)
|
|
1343
|
+
* })
|
|
1344
|
+
* ```
|
|
1345
|
+
*
|
|
1346
|
+
* New code:
|
|
1347
|
+
*
|
|
1348
|
+
* ```js
|
|
1349
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1350
|
+
*
|
|
1351
|
+
* //...
|
|
1352
|
+
*
|
|
1353
|
+
* const tween = new Tween(obj)
|
|
1354
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1355
|
+
*
|
|
1356
|
+
* //...
|
|
1357
|
+
*
|
|
1358
|
+
* const group = new Group()
|
|
1359
|
+
* group.add(tween)
|
|
1360
|
+
* group.add(tween2)
|
|
1361
|
+
*
|
|
1362
|
+
* //...
|
|
1363
|
+
*
|
|
1364
|
+
* requestAnimationFrame(function loop(time) {
|
|
1365
|
+
* group.update(time)
|
|
1366
|
+
* requestAnimationFrame(loop)
|
|
1367
|
+
* })
|
|
1368
|
+
* ```
|
|
1369
|
+
*/
|
|
1370
|
+
remove: remove,
|
|
1371
|
+
/**
|
|
1372
|
+
* @deprecated The global TWEEN Group will be removed in a following major
|
|
1373
|
+
* release. To migrate, create a `new Group()` instead of using `TWEEN` as a
|
|
1374
|
+
* group.
|
|
1375
|
+
*
|
|
1376
|
+
* Old code:
|
|
1377
|
+
*
|
|
1378
|
+
* ```js
|
|
1379
|
+
* import * as TWEEN from '@tweenjs/tween.js'
|
|
1380
|
+
*
|
|
1381
|
+
* //...
|
|
1382
|
+
*
|
|
1383
|
+
* const tween = new TWEEN.Tween(obj)
|
|
1384
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1385
|
+
*
|
|
1386
|
+
* //...
|
|
1387
|
+
*
|
|
1388
|
+
* requestAnimationFrame(function loop(time) {
|
|
1389
|
+
* TWEEN.update(time)
|
|
1390
|
+
* requestAnimationFrame(loop)
|
|
1391
|
+
* })
|
|
1392
|
+
* ```
|
|
1393
|
+
*
|
|
1394
|
+
* New code:
|
|
1395
|
+
*
|
|
1396
|
+
* ```js
|
|
1397
|
+
* import {Tween, Group} from '@tweenjs/tween.js'
|
|
1398
|
+
*
|
|
1399
|
+
* //...
|
|
1400
|
+
*
|
|
1401
|
+
* const tween = new Tween(obj)
|
|
1402
|
+
* const tween2 = new TWEEN.Tween(obj2)
|
|
1403
|
+
*
|
|
1404
|
+
* //...
|
|
1405
|
+
*
|
|
1406
|
+
* const group = new Group()
|
|
1407
|
+
* group.add(tween)
|
|
1408
|
+
* group.add(tween2)
|
|
1409
|
+
*
|
|
1410
|
+
* //...
|
|
1411
|
+
*
|
|
1412
|
+
* requestAnimationFrame(function loop(time) {
|
|
1413
|
+
* group.update(time)
|
|
1414
|
+
* requestAnimationFrame(loop)
|
|
1415
|
+
* })
|
|
1416
|
+
* ```
|
|
1417
|
+
*/
|
|
1418
|
+
update: update,
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1421
|
+
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };
|