@tweenjs/tween.js 18.6.4 → 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 +95 -38
- package/dist/tween.cjs.js +95 -38
- package/dist/tween.d.ts +57 -126
- package/dist/tween.esm.js +95 -38
- package/dist/tween.umd.js +95 -38
- package/package.json +4 -2
package/dist/tween.umd.js
CHANGED
|
@@ -7,13 +7,22 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* The Ease class provides a collection of easing functions for use with tween.js.
|
|
9
9
|
*/
|
|
10
|
-
var Easing = {
|
|
11
|
-
Linear: {
|
|
10
|
+
var Easing = Object.freeze({
|
|
11
|
+
Linear: Object.freeze({
|
|
12
12
|
None: function (amount) {
|
|
13
13
|
return amount;
|
|
14
14
|
},
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
In: function (amount) {
|
|
16
|
+
return this.None(amount);
|
|
17
|
+
},
|
|
18
|
+
Out: function (amount) {
|
|
19
|
+
return this.None(amount);
|
|
20
|
+
},
|
|
21
|
+
InOut: function (amount) {
|
|
22
|
+
return this.None(amount);
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
Quadratic: Object.freeze({
|
|
17
26
|
In: function (amount) {
|
|
18
27
|
return amount * amount;
|
|
19
28
|
},
|
|
@@ -26,8 +35,8 @@
|
|
|
26
35
|
}
|
|
27
36
|
return -0.5 * (--amount * (amount - 2) - 1);
|
|
28
37
|
},
|
|
29
|
-
},
|
|
30
|
-
Cubic: {
|
|
38
|
+
}),
|
|
39
|
+
Cubic: Object.freeze({
|
|
31
40
|
In: function (amount) {
|
|
32
41
|
return amount * amount * amount;
|
|
33
42
|
},
|
|
@@ -40,8 +49,8 @@
|
|
|
40
49
|
}
|
|
41
50
|
return 0.5 * ((amount -= 2) * amount * amount + 2);
|
|
42
51
|
},
|
|
43
|
-
},
|
|
44
|
-
Quartic: {
|
|
52
|
+
}),
|
|
53
|
+
Quartic: Object.freeze({
|
|
45
54
|
In: function (amount) {
|
|
46
55
|
return amount * amount * amount * amount;
|
|
47
56
|
},
|
|
@@ -54,8 +63,8 @@
|
|
|
54
63
|
}
|
|
55
64
|
return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
|
|
56
65
|
},
|
|
57
|
-
},
|
|
58
|
-
Quintic: {
|
|
66
|
+
}),
|
|
67
|
+
Quintic: Object.freeze({
|
|
59
68
|
In: function (amount) {
|
|
60
69
|
return amount * amount * amount * amount * amount;
|
|
61
70
|
},
|
|
@@ -68,19 +77,19 @@
|
|
|
68
77
|
}
|
|
69
78
|
return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
|
|
70
79
|
},
|
|
71
|
-
},
|
|
72
|
-
Sinusoidal: {
|
|
80
|
+
}),
|
|
81
|
+
Sinusoidal: Object.freeze({
|
|
73
82
|
In: function (amount) {
|
|
74
|
-
return 1 - Math.
|
|
83
|
+
return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);
|
|
75
84
|
},
|
|
76
85
|
Out: function (amount) {
|
|
77
86
|
return Math.sin((amount * Math.PI) / 2);
|
|
78
87
|
},
|
|
79
88
|
InOut: function (amount) {
|
|
80
|
-
return 0.5 * (1 - Math.
|
|
89
|
+
return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
|
|
81
90
|
},
|
|
82
|
-
},
|
|
83
|
-
Exponential: {
|
|
91
|
+
}),
|
|
92
|
+
Exponential: Object.freeze({
|
|
84
93
|
In: function (amount) {
|
|
85
94
|
return amount === 0 ? 0 : Math.pow(1024, amount - 1);
|
|
86
95
|
},
|
|
@@ -99,8 +108,8 @@
|
|
|
99
108
|
}
|
|
100
109
|
return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
|
|
101
110
|
},
|
|
102
|
-
},
|
|
103
|
-
Circular: {
|
|
111
|
+
}),
|
|
112
|
+
Circular: Object.freeze({
|
|
104
113
|
In: function (amount) {
|
|
105
114
|
return 1 - Math.sqrt(1 - amount * amount);
|
|
106
115
|
},
|
|
@@ -113,8 +122,8 @@
|
|
|
113
122
|
}
|
|
114
123
|
return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
|
|
115
124
|
},
|
|
116
|
-
},
|
|
117
|
-
Elastic: {
|
|
125
|
+
}),
|
|
126
|
+
Elastic: Object.freeze({
|
|
118
127
|
In: function (amount) {
|
|
119
128
|
if (amount === 0) {
|
|
120
129
|
return 0;
|
|
@@ -146,15 +155,15 @@
|
|
|
146
155
|
}
|
|
147
156
|
return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
|
|
148
157
|
},
|
|
149
|
-
},
|
|
150
|
-
Back: {
|
|
158
|
+
}),
|
|
159
|
+
Back: Object.freeze({
|
|
151
160
|
In: function (amount) {
|
|
152
161
|
var s = 1.70158;
|
|
153
|
-
return amount * amount * ((s + 1) * amount - s);
|
|
162
|
+
return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
|
|
154
163
|
},
|
|
155
164
|
Out: function (amount) {
|
|
156
165
|
var s = 1.70158;
|
|
157
|
-
return --amount * amount * ((s + 1) * amount + s) + 1;
|
|
166
|
+
return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
|
|
158
167
|
},
|
|
159
168
|
InOut: function (amount) {
|
|
160
169
|
var s = 1.70158 * 1.525;
|
|
@@ -163,8 +172,8 @@
|
|
|
163
172
|
}
|
|
164
173
|
return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
|
|
165
174
|
},
|
|
166
|
-
},
|
|
167
|
-
Bounce: {
|
|
175
|
+
}),
|
|
176
|
+
Bounce: Object.freeze({
|
|
168
177
|
In: function (amount) {
|
|
169
178
|
return 1 - Easing.Bounce.Out(1 - amount);
|
|
170
179
|
},
|
|
@@ -188,8 +197,27 @@
|
|
|
188
197
|
}
|
|
189
198
|
return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
|
|
190
199
|
},
|
|
200
|
+
}),
|
|
201
|
+
generatePow: function (power) {
|
|
202
|
+
if (power === void 0) { power = 4; }
|
|
203
|
+
power = power < Number.EPSILON ? Number.EPSILON : power;
|
|
204
|
+
power = power > 10000 ? 10000 : power;
|
|
205
|
+
return {
|
|
206
|
+
In: function (amount) {
|
|
207
|
+
return Math.pow(amount, power);
|
|
208
|
+
},
|
|
209
|
+
Out: function (amount) {
|
|
210
|
+
return 1 - Math.pow((1 - amount), power);
|
|
211
|
+
},
|
|
212
|
+
InOut: function (amount) {
|
|
213
|
+
if (amount < 0.5) {
|
|
214
|
+
return Math.pow((amount * 2), power) / 2;
|
|
215
|
+
}
|
|
216
|
+
return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;
|
|
217
|
+
},
|
|
218
|
+
};
|
|
191
219
|
},
|
|
192
|
-
};
|
|
220
|
+
});
|
|
193
221
|
|
|
194
222
|
var now;
|
|
195
223
|
// Include a performance.now polyfill.
|
|
@@ -402,8 +430,10 @@
|
|
|
402
430
|
this._startTime = 0;
|
|
403
431
|
this._easingFunction = Easing.Linear.None;
|
|
404
432
|
this._interpolationFunction = Interpolation.Linear;
|
|
433
|
+
// eslint-disable-next-line
|
|
405
434
|
this._chainedTweens = [];
|
|
406
435
|
this._onStartCallbackFired = false;
|
|
436
|
+
this._onEveryStartCallbackFired = false;
|
|
407
437
|
this._id = Sequence.nextId();
|
|
408
438
|
this._isChainStopped = false;
|
|
409
439
|
this._goToEnd = false;
|
|
@@ -429,10 +459,13 @@
|
|
|
429
459
|
return this;
|
|
430
460
|
};
|
|
431
461
|
Tween.prototype.duration = function (d) {
|
|
462
|
+
if (d === void 0) { d = 1000; }
|
|
432
463
|
this._duration = d;
|
|
433
464
|
return this;
|
|
434
465
|
};
|
|
435
|
-
Tween.prototype.start = function (time) {
|
|
466
|
+
Tween.prototype.start = function (time, overrideStartingValues) {
|
|
467
|
+
if (time === void 0) { time = now$1(); }
|
|
468
|
+
if (overrideStartingValues === void 0) { overrideStartingValues = false; }
|
|
436
469
|
if (this._isPlaying) {
|
|
437
470
|
return this;
|
|
438
471
|
}
|
|
@@ -451,13 +484,17 @@
|
|
|
451
484
|
this._isPlaying = true;
|
|
452
485
|
this._isPaused = false;
|
|
453
486
|
this._onStartCallbackFired = false;
|
|
487
|
+
this._onEveryStartCallbackFired = false;
|
|
454
488
|
this._isChainStopped = false;
|
|
455
|
-
this._startTime = time
|
|
489
|
+
this._startTime = time;
|
|
456
490
|
this._startTime += this._delayTime;
|
|
457
|
-
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
|
|
491
|
+
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
|
|
458
492
|
return this;
|
|
459
493
|
};
|
|
460
|
-
Tween.prototype.
|
|
494
|
+
Tween.prototype.startFromCurrentValues = function (time) {
|
|
495
|
+
return this.start(time, true);
|
|
496
|
+
};
|
|
497
|
+
Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
|
|
461
498
|
for (var property in _valuesEnd) {
|
|
462
499
|
var startValue = _object[property];
|
|
463
500
|
var startValueIsArray = Array.isArray(startValue);
|
|
@@ -477,7 +514,9 @@
|
|
|
477
514
|
// handle an array of relative values
|
|
478
515
|
endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
|
|
479
516
|
// Create a local copy of the Array with the start value at the front
|
|
480
|
-
|
|
517
|
+
if (_valuesStart[property] === undefined) {
|
|
518
|
+
_valuesEnd[property] = [startValue].concat(endValues);
|
|
519
|
+
}
|
|
481
520
|
}
|
|
482
521
|
// handle the deepness of the values
|
|
483
522
|
if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
|
|
@@ -491,11 +530,11 @@
|
|
|
491
530
|
_valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
|
|
492
531
|
// eslint-disable-next-line
|
|
493
532
|
// @ts-ignore FIXME?
|
|
494
|
-
this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
|
|
533
|
+
this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property], overrideStartingValues);
|
|
495
534
|
}
|
|
496
535
|
else {
|
|
497
|
-
// Save the starting value, but only once.
|
|
498
|
-
if (typeof _valuesStart[property] === 'undefined') {
|
|
536
|
+
// Save the starting value, but only once unless override is requested.
|
|
537
|
+
if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
|
|
499
538
|
_valuesStart[property] = startValue;
|
|
500
539
|
}
|
|
501
540
|
if (!startValueIsArray) {
|
|
@@ -566,14 +605,17 @@
|
|
|
566
605
|
return this;
|
|
567
606
|
};
|
|
568
607
|
Tween.prototype.group = function (group) {
|
|
608
|
+
if (group === void 0) { group = mainGroup; }
|
|
569
609
|
this._group = group;
|
|
570
610
|
return this;
|
|
571
611
|
};
|
|
572
612
|
Tween.prototype.delay = function (amount) {
|
|
613
|
+
if (amount === void 0) { amount = 0; }
|
|
573
614
|
this._delayTime = amount;
|
|
574
615
|
return this;
|
|
575
616
|
};
|
|
576
617
|
Tween.prototype.repeat = function (times) {
|
|
618
|
+
if (times === void 0) { times = 0; }
|
|
577
619
|
this._initialRepeat = times;
|
|
578
620
|
this._repeat = times;
|
|
579
621
|
return this;
|
|
@@ -583,17 +625,21 @@
|
|
|
583
625
|
return this;
|
|
584
626
|
};
|
|
585
627
|
Tween.prototype.yoyo = function (yoyo) {
|
|
628
|
+
if (yoyo === void 0) { yoyo = false; }
|
|
586
629
|
this._yoyo = yoyo;
|
|
587
630
|
return this;
|
|
588
631
|
};
|
|
589
632
|
Tween.prototype.easing = function (easingFunction) {
|
|
633
|
+
if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
|
|
590
634
|
this._easingFunction = easingFunction;
|
|
591
635
|
return this;
|
|
592
636
|
};
|
|
593
637
|
Tween.prototype.interpolation = function (interpolationFunction) {
|
|
638
|
+
if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
|
|
594
639
|
this._interpolationFunction = interpolationFunction;
|
|
595
640
|
return this;
|
|
596
641
|
};
|
|
642
|
+
// eslint-disable-next-line
|
|
597
643
|
Tween.prototype.chain = function () {
|
|
598
644
|
var tweens = [];
|
|
599
645
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -606,6 +652,10 @@
|
|
|
606
652
|
this._onStartCallback = callback;
|
|
607
653
|
return this;
|
|
608
654
|
};
|
|
655
|
+
Tween.prototype.onEveryStart = function (callback) {
|
|
656
|
+
this._onEveryStartCallback = callback;
|
|
657
|
+
return this;
|
|
658
|
+
};
|
|
609
659
|
Tween.prototype.onUpdate = function (callback) {
|
|
610
660
|
this._onUpdateCallback = callback;
|
|
611
661
|
return this;
|
|
@@ -639,7 +689,7 @@
|
|
|
639
689
|
if (time > endTime)
|
|
640
690
|
return false;
|
|
641
691
|
if (autoStart)
|
|
642
|
-
this.start(time);
|
|
692
|
+
this.start(time, true);
|
|
643
693
|
}
|
|
644
694
|
this._goToEnd = false;
|
|
645
695
|
if (time < this._startTime) {
|
|
@@ -651,6 +701,12 @@
|
|
|
651
701
|
}
|
|
652
702
|
this._onStartCallbackFired = true;
|
|
653
703
|
}
|
|
704
|
+
if (this._onEveryStartCallbackFired === false) {
|
|
705
|
+
if (this._onEveryStartCallback) {
|
|
706
|
+
this._onEveryStartCallback(this._object);
|
|
707
|
+
}
|
|
708
|
+
this._onEveryStartCallbackFired = true;
|
|
709
|
+
}
|
|
654
710
|
elapsed = (time - this._startTime) / this._duration;
|
|
655
711
|
elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
|
|
656
712
|
var value = this._easingFunction(elapsed);
|
|
@@ -689,6 +745,7 @@
|
|
|
689
745
|
if (this._onRepeatCallback) {
|
|
690
746
|
this._onRepeatCallback(this._object);
|
|
691
747
|
}
|
|
748
|
+
this._onEveryStartCallbackFired = false;
|
|
692
749
|
return true;
|
|
693
750
|
}
|
|
694
751
|
else {
|
|
@@ -698,7 +755,7 @@
|
|
|
698
755
|
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
|
|
699
756
|
// Make the chained tweens start exactly at the time they should,
|
|
700
757
|
// even if the `update()` method was called way past the duration of the tween
|
|
701
|
-
this._chainedTweens[i].start(this._startTime + this._duration);
|
|
758
|
+
this._chainedTweens[i].start(this._startTime + this._duration, false);
|
|
702
759
|
}
|
|
703
760
|
this._isPlaying = false;
|
|
704
761
|
return false;
|
|
@@ -762,7 +819,7 @@
|
|
|
762
819
|
return Tween;
|
|
763
820
|
}());
|
|
764
821
|
|
|
765
|
-
var VERSION = '
|
|
822
|
+
var VERSION = '19.0.0';
|
|
766
823
|
|
|
767
824
|
/**
|
|
768
825
|
* Tween.js - Licensed under the MIT license
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tweenjs/tween.js",
|
|
3
3
|
"description": "Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equations.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "19.0.0",
|
|
5
5
|
"main": "dist/tween.cjs.js",
|
|
6
6
|
"types": "dist/tween.d.ts",
|
|
7
7
|
"module": "dist/tween.esm.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"tsc": "tsc",
|
|
32
32
|
"tsc-watch": "tsc --watch",
|
|
33
33
|
"examples": "npx serve .",
|
|
34
|
-
"test": "npm run build && npm run test-
|
|
34
|
+
"test": "npm run build && npm run test-lint && npm run test-unit",
|
|
35
35
|
"test-unit": "nodeunit test/unit/nodeunitheadless.js",
|
|
36
36
|
"test-lint": "npm run prettier -- --check && eslint 'src/**/*.ts'",
|
|
37
37
|
"lint": "npm run prettier -- --write && eslint 'src/**/*.ts' --fix",
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"author": "tween.js contributors (https://github.com/tweenjs/tween.js/graphs/contributors)",
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"@sinonjs/fake-timers": "^6.0.1",
|
|
49
|
+
"@types/sinonjs__fake-timers": "^6.0.2",
|
|
48
50
|
"@typescript-eslint/eslint-plugin": "^3.1.0",
|
|
49
51
|
"@typescript-eslint/parser": "^3.1.0",
|
|
50
52
|
"eslint": "^7.1.0",
|