@tweenjs/tween.js 18.6.3 → 19.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/README.md +2 -4
- package/dist/tween.amd.js +98 -42
- package/dist/tween.cjs.js +98 -42
- package/dist/tween.d.ts +64 -133
- package/dist/tween.esm.js +98 -42
- package/dist/tween.umd.js +98 -42
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -239,15 +239,13 @@ You need to install `npm` first--this comes with node.js, so install that one fi
|
|
|
239
239
|
npm install
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
-
|
|
242
|
+
To run the tests run:
|
|
243
243
|
|
|
244
244
|
```bash
|
|
245
245
|
npm test
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
If you want to add any feature or change existing features, you _must_ run the tests to make sure you didn't break anything else. If you send a pull request (PR) to add something new and it doesn't have tests, or the tests don't pass, the PR won't be accepted. See [contributing](CONTRIBUTING.md) for more information.
|
|
248
|
+
If you want to add any feature or change existing features, you _must_ run the tests to make sure you didn't break anything else. Any pull request (PR) needs to have updated passing tests for feature changes (or new passing tests for new features) in `src/tests.ts`, otherwise the PR won't be accepted. See [contributing](CONTRIBUTING.md) for more information.
|
|
251
249
|
|
|
252
250
|
## People
|
|
253
251
|
|
package/dist/tween.amd.js
CHANGED
|
@@ -3,13 +3,22 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
3
3
|
/**
|
|
4
4
|
* The Ease class provides a collection of easing functions for use with tween.js.
|
|
5
5
|
*/
|
|
6
|
-
var Easing = {
|
|
7
|
-
Linear: {
|
|
6
|
+
var Easing = Object.freeze({
|
|
7
|
+
Linear: Object.freeze({
|
|
8
8
|
None: function (amount) {
|
|
9
9
|
return amount;
|
|
10
10
|
},
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
In: function (amount) {
|
|
12
|
+
return this.None(amount);
|
|
13
|
+
},
|
|
14
|
+
Out: function (amount) {
|
|
15
|
+
return this.None(amount);
|
|
16
|
+
},
|
|
17
|
+
InOut: function (amount) {
|
|
18
|
+
return this.None(amount);
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
Quadratic: Object.freeze({
|
|
13
22
|
In: function (amount) {
|
|
14
23
|
return amount * amount;
|
|
15
24
|
},
|
|
@@ -22,8 +31,8 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
22
31
|
}
|
|
23
32
|
return -0.5 * (--amount * (amount - 2) - 1);
|
|
24
33
|
},
|
|
25
|
-
},
|
|
26
|
-
Cubic: {
|
|
34
|
+
}),
|
|
35
|
+
Cubic: Object.freeze({
|
|
27
36
|
In: function (amount) {
|
|
28
37
|
return amount * amount * amount;
|
|
29
38
|
},
|
|
@@ -36,8 +45,8 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
36
45
|
}
|
|
37
46
|
return 0.5 * ((amount -= 2) * amount * amount + 2);
|
|
38
47
|
},
|
|
39
|
-
},
|
|
40
|
-
Quartic: {
|
|
48
|
+
}),
|
|
49
|
+
Quartic: Object.freeze({
|
|
41
50
|
In: function (amount) {
|
|
42
51
|
return amount * amount * amount * amount;
|
|
43
52
|
},
|
|
@@ -50,8 +59,8 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
50
59
|
}
|
|
51
60
|
return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
|
|
52
61
|
},
|
|
53
|
-
},
|
|
54
|
-
Quintic: {
|
|
62
|
+
}),
|
|
63
|
+
Quintic: Object.freeze({
|
|
55
64
|
In: function (amount) {
|
|
56
65
|
return amount * amount * amount * amount * amount;
|
|
57
66
|
},
|
|
@@ -64,19 +73,19 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
64
73
|
}
|
|
65
74
|
return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
|
|
66
75
|
},
|
|
67
|
-
},
|
|
68
|
-
Sinusoidal: {
|
|
76
|
+
}),
|
|
77
|
+
Sinusoidal: Object.freeze({
|
|
69
78
|
In: function (amount) {
|
|
70
|
-
return 1 - Math.
|
|
79
|
+
return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);
|
|
71
80
|
},
|
|
72
81
|
Out: function (amount) {
|
|
73
82
|
return Math.sin((amount * Math.PI) / 2);
|
|
74
83
|
},
|
|
75
84
|
InOut: function (amount) {
|
|
76
|
-
return 0.5 * (1 - Math.
|
|
85
|
+
return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
|
|
77
86
|
},
|
|
78
|
-
},
|
|
79
|
-
Exponential: {
|
|
87
|
+
}),
|
|
88
|
+
Exponential: Object.freeze({
|
|
80
89
|
In: function (amount) {
|
|
81
90
|
return amount === 0 ? 0 : Math.pow(1024, amount - 1);
|
|
82
91
|
},
|
|
@@ -95,8 +104,8 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
95
104
|
}
|
|
96
105
|
return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
|
|
97
106
|
},
|
|
98
|
-
},
|
|
99
|
-
Circular: {
|
|
107
|
+
}),
|
|
108
|
+
Circular: Object.freeze({
|
|
100
109
|
In: function (amount) {
|
|
101
110
|
return 1 - Math.sqrt(1 - amount * amount);
|
|
102
111
|
},
|
|
@@ -109,8 +118,8 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
109
118
|
}
|
|
110
119
|
return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
|
|
111
120
|
},
|
|
112
|
-
},
|
|
113
|
-
Elastic: {
|
|
121
|
+
}),
|
|
122
|
+
Elastic: Object.freeze({
|
|
114
123
|
In: function (amount) {
|
|
115
124
|
if (amount === 0) {
|
|
116
125
|
return 0;
|
|
@@ -142,15 +151,15 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
142
151
|
}
|
|
143
152
|
return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
|
|
144
153
|
},
|
|
145
|
-
},
|
|
146
|
-
Back: {
|
|
154
|
+
}),
|
|
155
|
+
Back: Object.freeze({
|
|
147
156
|
In: function (amount) {
|
|
148
157
|
var s = 1.70158;
|
|
149
|
-
return amount * amount * ((s + 1) * amount - s);
|
|
158
|
+
return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
|
|
150
159
|
},
|
|
151
160
|
Out: function (amount) {
|
|
152
161
|
var s = 1.70158;
|
|
153
|
-
return --amount * amount * ((s + 1) * amount + s) + 1;
|
|
162
|
+
return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
|
|
154
163
|
},
|
|
155
164
|
InOut: function (amount) {
|
|
156
165
|
var s = 1.70158 * 1.525;
|
|
@@ -159,8 +168,8 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
159
168
|
}
|
|
160
169
|
return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
|
|
161
170
|
},
|
|
162
|
-
},
|
|
163
|
-
Bounce: {
|
|
171
|
+
}),
|
|
172
|
+
Bounce: Object.freeze({
|
|
164
173
|
In: function (amount) {
|
|
165
174
|
return 1 - Easing.Bounce.Out(1 - amount);
|
|
166
175
|
},
|
|
@@ -184,8 +193,27 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
184
193
|
}
|
|
185
194
|
return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
|
|
186
195
|
},
|
|
196
|
+
}),
|
|
197
|
+
generatePow: function (power) {
|
|
198
|
+
if (power === void 0) { power = 4; }
|
|
199
|
+
power = power < Number.EPSILON ? Number.EPSILON : power;
|
|
200
|
+
power = power > 10000 ? 10000 : power;
|
|
201
|
+
return {
|
|
202
|
+
In: function (amount) {
|
|
203
|
+
return Math.pow(amount, power);
|
|
204
|
+
},
|
|
205
|
+
Out: function (amount) {
|
|
206
|
+
return 1 - Math.pow((1 - amount), power);
|
|
207
|
+
},
|
|
208
|
+
InOut: function (amount) {
|
|
209
|
+
if (amount < 0.5) {
|
|
210
|
+
return Math.pow((amount * 2), power) / 2;
|
|
211
|
+
}
|
|
212
|
+
return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;
|
|
213
|
+
},
|
|
214
|
+
};
|
|
187
215
|
},
|
|
188
|
-
};
|
|
216
|
+
});
|
|
189
217
|
|
|
190
218
|
var now;
|
|
191
219
|
// Include a performance.now polyfill.
|
|
@@ -398,8 +426,10 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
398
426
|
this._startTime = 0;
|
|
399
427
|
this._easingFunction = Easing.Linear.None;
|
|
400
428
|
this._interpolationFunction = Interpolation.Linear;
|
|
429
|
+
// eslint-disable-next-line
|
|
401
430
|
this._chainedTweens = [];
|
|
402
431
|
this._onStartCallbackFired = false;
|
|
432
|
+
this._onEveryStartCallbackFired = false;
|
|
403
433
|
this._id = Sequence.nextId();
|
|
404
434
|
this._isChainStopped = false;
|
|
405
435
|
this._goToEnd = false;
|
|
@@ -425,10 +455,13 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
425
455
|
return this;
|
|
426
456
|
};
|
|
427
457
|
Tween.prototype.duration = function (d) {
|
|
458
|
+
if (d === void 0) { d = 1000; }
|
|
428
459
|
this._duration = d;
|
|
429
460
|
return this;
|
|
430
461
|
};
|
|
431
|
-
Tween.prototype.start = function (time) {
|
|
462
|
+
Tween.prototype.start = function (time, overrideStartingValues) {
|
|
463
|
+
if (time === void 0) { time = now$1(); }
|
|
464
|
+
if (overrideStartingValues === void 0) { overrideStartingValues = false; }
|
|
432
465
|
if (this._isPlaying) {
|
|
433
466
|
return this;
|
|
434
467
|
}
|
|
@@ -447,13 +480,17 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
447
480
|
this._isPlaying = true;
|
|
448
481
|
this._isPaused = false;
|
|
449
482
|
this._onStartCallbackFired = false;
|
|
483
|
+
this._onEveryStartCallbackFired = false;
|
|
450
484
|
this._isChainStopped = false;
|
|
451
|
-
this._startTime = time
|
|
485
|
+
this._startTime = time;
|
|
452
486
|
this._startTime += this._delayTime;
|
|
453
|
-
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
|
|
487
|
+
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
|
|
454
488
|
return this;
|
|
455
489
|
};
|
|
456
|
-
Tween.prototype.
|
|
490
|
+
Tween.prototype.startFromCurrentValues = function (time) {
|
|
491
|
+
return this.start(time, true);
|
|
492
|
+
};
|
|
493
|
+
Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
|
|
457
494
|
for (var property in _valuesEnd) {
|
|
458
495
|
var startValue = _object[property];
|
|
459
496
|
var startValueIsArray = Array.isArray(startValue);
|
|
@@ -473,7 +510,9 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
473
510
|
// handle an array of relative values
|
|
474
511
|
endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
|
|
475
512
|
// Create a local copy of the Array with the start value at the front
|
|
476
|
-
|
|
513
|
+
if (_valuesStart[property] === undefined) {
|
|
514
|
+
_valuesEnd[property] = [startValue].concat(endValues);
|
|
515
|
+
}
|
|
477
516
|
}
|
|
478
517
|
// handle the deepness of the values
|
|
479
518
|
if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
|
|
@@ -487,11 +526,11 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
487
526
|
_valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
|
|
488
527
|
// eslint-disable-next-line
|
|
489
528
|
// @ts-ignore FIXME?
|
|
490
|
-
this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
|
|
529
|
+
this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property], overrideStartingValues);
|
|
491
530
|
}
|
|
492
531
|
else {
|
|
493
|
-
// Save the starting value, but only once.
|
|
494
|
-
if (typeof _valuesStart[property] === 'undefined') {
|
|
532
|
+
// Save the starting value, but only once unless override is requested.
|
|
533
|
+
if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
|
|
495
534
|
_valuesStart[property] = startValue;
|
|
496
535
|
}
|
|
497
536
|
if (!startValueIsArray) {
|
|
@@ -562,14 +601,17 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
562
601
|
return this;
|
|
563
602
|
};
|
|
564
603
|
Tween.prototype.group = function (group) {
|
|
604
|
+
if (group === void 0) { group = mainGroup; }
|
|
565
605
|
this._group = group;
|
|
566
606
|
return this;
|
|
567
607
|
};
|
|
568
608
|
Tween.prototype.delay = function (amount) {
|
|
609
|
+
if (amount === void 0) { amount = 0; }
|
|
569
610
|
this._delayTime = amount;
|
|
570
611
|
return this;
|
|
571
612
|
};
|
|
572
613
|
Tween.prototype.repeat = function (times) {
|
|
614
|
+
if (times === void 0) { times = 0; }
|
|
573
615
|
this._initialRepeat = times;
|
|
574
616
|
this._repeat = times;
|
|
575
617
|
return this;
|
|
@@ -579,17 +621,21 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
579
621
|
return this;
|
|
580
622
|
};
|
|
581
623
|
Tween.prototype.yoyo = function (yoyo) {
|
|
624
|
+
if (yoyo === void 0) { yoyo = false; }
|
|
582
625
|
this._yoyo = yoyo;
|
|
583
626
|
return this;
|
|
584
627
|
};
|
|
585
628
|
Tween.prototype.easing = function (easingFunction) {
|
|
629
|
+
if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
|
|
586
630
|
this._easingFunction = easingFunction;
|
|
587
631
|
return this;
|
|
588
632
|
};
|
|
589
633
|
Tween.prototype.interpolation = function (interpolationFunction) {
|
|
634
|
+
if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
|
|
590
635
|
this._interpolationFunction = interpolationFunction;
|
|
591
636
|
return this;
|
|
592
637
|
};
|
|
638
|
+
// eslint-disable-next-line
|
|
593
639
|
Tween.prototype.chain = function () {
|
|
594
640
|
var tweens = [];
|
|
595
641
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -602,6 +648,10 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
602
648
|
this._onStartCallback = callback;
|
|
603
649
|
return this;
|
|
604
650
|
};
|
|
651
|
+
Tween.prototype.onEveryStart = function (callback) {
|
|
652
|
+
this._onEveryStartCallback = callback;
|
|
653
|
+
return this;
|
|
654
|
+
};
|
|
605
655
|
Tween.prototype.onUpdate = function (callback) {
|
|
606
656
|
this._onUpdateCallback = callback;
|
|
607
657
|
return this;
|
|
@@ -635,7 +685,7 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
635
685
|
if (time > endTime)
|
|
636
686
|
return false;
|
|
637
687
|
if (autoStart)
|
|
638
|
-
this.start(time);
|
|
688
|
+
this.start(time, true);
|
|
639
689
|
}
|
|
640
690
|
this._goToEnd = false;
|
|
641
691
|
if (time < this._startTime) {
|
|
@@ -647,6 +697,12 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
647
697
|
}
|
|
648
698
|
this._onStartCallbackFired = true;
|
|
649
699
|
}
|
|
700
|
+
if (this._onEveryStartCallbackFired === false) {
|
|
701
|
+
if (this._onEveryStartCallback) {
|
|
702
|
+
this._onEveryStartCallback(this._object);
|
|
703
|
+
}
|
|
704
|
+
this._onEveryStartCallbackFired = true;
|
|
705
|
+
}
|
|
650
706
|
elapsed = (time - this._startTime) / this._duration;
|
|
651
707
|
elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
|
|
652
708
|
var value = this._easingFunction(elapsed);
|
|
@@ -685,6 +741,7 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
685
741
|
if (this._onRepeatCallback) {
|
|
686
742
|
this._onRepeatCallback(this._object);
|
|
687
743
|
}
|
|
744
|
+
this._onEveryStartCallbackFired = false;
|
|
688
745
|
return true;
|
|
689
746
|
}
|
|
690
747
|
else {
|
|
@@ -694,7 +751,7 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
694
751
|
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
|
|
695
752
|
// Make the chained tweens start exactly at the time they should,
|
|
696
753
|
// even if the `update()` method was called way past the duration of the tween
|
|
697
|
-
this._chainedTweens[i].start(this._startTime + this._duration);
|
|
754
|
+
this._chainedTweens[i].start(this._startTime + this._duration, false);
|
|
698
755
|
}
|
|
699
756
|
this._isPlaying = false;
|
|
700
757
|
return false;
|
|
@@ -746,10 +803,9 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
746
803
|
};
|
|
747
804
|
Tween.prototype._swapEndStartRepeatValues = function (property) {
|
|
748
805
|
var tmp = this._valuesStartRepeat[property];
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
|
|
806
|
+
var endValue = this._valuesEnd[property];
|
|
807
|
+
if (typeof endValue === 'string') {
|
|
808
|
+
this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
|
|
753
809
|
}
|
|
754
810
|
else {
|
|
755
811
|
this._valuesStartRepeat[property] = this._valuesEnd[property];
|
|
@@ -759,7 +815,7 @@ define(['exports'], function (exports) { 'use strict';
|
|
|
759
815
|
return Tween;
|
|
760
816
|
}());
|
|
761
817
|
|
|
762
|
-
var VERSION = '
|
|
818
|
+
var VERSION = '19.0.0';
|
|
763
819
|
|
|
764
820
|
/**
|
|
765
821
|
* Tween.js - Licensed under the MIT license
|