@tweenjs/tween.js 18.6.4 → 20.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/dist/tween.amd.js CHANGED
@@ -1,15 +1,24 @@
1
- define(['exports'], function (exports) { 'use strict';
1
+ define(['exports'], (function (exports) { 'use strict';
2
2
 
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
- Quadratic: {
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.cos((amount * Math.PI) / 2);
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.cos(Math.PI * amount));
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,40 +193,29 @@ 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
- var now;
191
- // Include a performance.now polyfill.
192
- // In node.js, use process.hrtime.
193
- // eslint-disable-next-line
194
- // @ts-ignore
195
- if (typeof self === 'undefined' && typeof process !== 'undefined' && process.hrtime) {
196
- now = function () {
197
- // eslint-disable-next-line
198
- // @ts-ignore
199
- var time = process.hrtime();
200
- // Convert [seconds, nanoseconds] to milliseconds.
201
- return time[0] * 1000 + time[1] / 1000000;
202
- };
203
- }
204
- // In a browser, use self.performance.now if it is available.
205
- else if (typeof self !== 'undefined' && self.performance !== undefined && self.performance.now !== undefined) {
206
- // This must be bound, because directly assigning this function
207
- // leads to an invocation exception in Chrome.
208
- now = self.performance.now.bind(self.performance);
209
- }
210
- // Use Date.now if it is available.
211
- else if (Date.now !== undefined) {
212
- now = Date.now;
213
- }
214
- // Otherwise, use 'new Date().getTime()'.
215
- else {
216
- now = function () {
217
- return new Date().getTime();
218
- };
219
- }
220
- var now$1 = now;
218
+ var now = function () { return performance.now(); };
221
219
 
222
220
  /**
223
221
  * Controlling groups of tweens
@@ -248,7 +246,7 @@ define(['exports'], function (exports) { 'use strict';
248
246
  delete this._tweensAddedDuringUpdate[tween.getId()];
249
247
  };
250
248
  Group.prototype.update = function (time, preserve) {
251
- if (time === void 0) { time = now$1(); }
249
+ if (time === void 0) { time = now(); }
252
250
  if (preserve === void 0) { preserve = false; }
253
251
  var tweenIds = Object.keys(this._tweens);
254
252
  if (tweenIds.length === 0) {
@@ -389,6 +387,7 @@ define(['exports'], function (exports) { 'use strict';
389
387
  this._valuesEnd = {};
390
388
  this._valuesStartRepeat = {};
391
389
  this._duration = 1000;
390
+ this._isDynamic = false;
392
391
  this._initialRepeat = 0;
393
392
  this._repeat = 0;
394
393
  this._yoyo = false;
@@ -398,10 +397,13 @@ define(['exports'], function (exports) { 'use strict';
398
397
  this._startTime = 0;
399
398
  this._easingFunction = Easing.Linear.None;
400
399
  this._interpolationFunction = Interpolation.Linear;
400
+ // eslint-disable-next-line
401
401
  this._chainedTweens = [];
402
402
  this._onStartCallbackFired = false;
403
+ this._onEveryStartCallbackFired = false;
403
404
  this._id = Sequence.nextId();
404
405
  this._isChainStopped = false;
406
+ this._propertiesAreSetUp = false;
405
407
  this._goToEnd = false;
406
408
  }
407
409
  Tween.prototype.getId = function () {
@@ -413,22 +415,28 @@ define(['exports'], function (exports) { 'use strict';
413
415
  Tween.prototype.isPaused = function () {
414
416
  return this._isPaused;
415
417
  };
416
- Tween.prototype.to = function (properties, duration) {
417
- // TODO? restore this, then update the 07_dynamic_to example to set fox
418
- // tween's to on each update. That way the behavior is opt-in (there's
419
- // currently no opt-out).
420
- // for (const prop in properties) this._valuesEnd[prop] = properties[prop]
421
- this._valuesEnd = Object.create(properties);
422
- if (duration !== undefined) {
423
- this._duration = duration;
424
- }
418
+ Tween.prototype.to = function (target, duration) {
419
+ if (duration === void 0) { duration = 1000; }
420
+ if (this._isPlaying)
421
+ throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');
422
+ this._valuesEnd = target;
423
+ this._propertiesAreSetUp = false;
424
+ this._duration = duration;
425
425
  return this;
426
426
  };
427
- Tween.prototype.duration = function (d) {
428
- this._duration = d;
427
+ Tween.prototype.duration = function (duration) {
428
+ if (duration === void 0) { duration = 1000; }
429
+ this._duration = duration;
429
430
  return this;
430
431
  };
431
- Tween.prototype.start = function (time) {
432
+ Tween.prototype.dynamic = function (dynamic) {
433
+ if (dynamic === void 0) { dynamic = false; }
434
+ this._isDynamic = dynamic;
435
+ return this;
436
+ };
437
+ Tween.prototype.start = function (time, overrideStartingValues) {
438
+ if (time === void 0) { time = now(); }
439
+ if (overrideStartingValues === void 0) { overrideStartingValues = false; }
432
440
  if (this._isPlaying) {
433
441
  return this;
434
442
  }
@@ -447,13 +455,27 @@ define(['exports'], function (exports) { 'use strict';
447
455
  this._isPlaying = true;
448
456
  this._isPaused = false;
449
457
  this._onStartCallbackFired = false;
458
+ this._onEveryStartCallbackFired = false;
450
459
  this._isChainStopped = false;
451
- this._startTime = time !== undefined ? (typeof time === 'string' ? now$1() + parseFloat(time) : time) : now$1();
460
+ this._startTime = time;
452
461
  this._startTime += this._delayTime;
453
- this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
462
+ if (!this._propertiesAreSetUp || overrideStartingValues) {
463
+ this._propertiesAreSetUp = true;
464
+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
465
+ if (!this._isDynamic) {
466
+ var tmp = {};
467
+ for (var prop in this._valuesEnd)
468
+ tmp[prop] = this._valuesEnd[prop];
469
+ this._valuesEnd = tmp;
470
+ }
471
+ this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
472
+ }
454
473
  return this;
455
474
  };
456
- Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat) {
475
+ Tween.prototype.startFromCurrentValues = function (time) {
476
+ return this.start(time, true);
477
+ };
478
+ Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
457
479
  for (var property in _valuesEnd) {
458
480
  var startValue = _object[property];
459
481
  var startValueIsArray = Array.isArray(startValue);
@@ -470,28 +492,46 @@ define(['exports'], function (exports) { 'use strict';
470
492
  if (endValues.length === 0) {
471
493
  continue;
472
494
  }
473
- // handle an array of relative values
474
- endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
475
- // Create a local copy of the Array with the start value at the front
476
- _valuesEnd[property] = [startValue].concat(endValues);
495
+ // Handle an array of relative values.
496
+ // Creates a local copy of the Array with the start value at the front
497
+ var temp = [startValue];
498
+ for (var i = 0, l = endValues.length; i < l; i += 1) {
499
+ var value = this._handleRelativeValue(startValue, endValues[i]);
500
+ if (isNaN(value)) {
501
+ isInterpolationList = false;
502
+ console.warn('Found invalid interpolation list. Skipping.');
503
+ break;
504
+ }
505
+ temp.push(value);
506
+ }
507
+ if (isInterpolationList) {
508
+ // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
509
+ _valuesEnd[property] = temp;
510
+ // }
511
+ }
477
512
  }
478
513
  // handle the deepness of the values
479
514
  if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
480
515
  _valuesStart[property] = startValueIsArray ? [] : {};
481
- // eslint-disable-next-line
482
- for (var prop in startValue) {
483
- // eslint-disable-next-line
484
- // @ts-ignore FIXME?
485
- _valuesStart[property][prop] = startValue[prop];
516
+ var nestedObject = startValue;
517
+ for (var prop in nestedObject) {
518
+ _valuesStart[property][prop] = nestedObject[prop];
486
519
  }
487
- _valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
488
- // eslint-disable-next-line
489
- // @ts-ignore FIXME?
490
- this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
520
+ // TODO? repeat nested values? And yoyo? And array values?
521
+ _valuesStartRepeat[property] = startValueIsArray ? [] : {};
522
+ var endValues = _valuesEnd[property];
523
+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
524
+ if (!this._isDynamic) {
525
+ var tmp = {};
526
+ for (var prop in endValues)
527
+ tmp[prop] = endValues[prop];
528
+ _valuesEnd[property] = endValues = tmp;
529
+ }
530
+ this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);
491
531
  }
492
532
  else {
493
- // Save the starting value, but only once.
494
- if (typeof _valuesStart[property] === 'undefined') {
533
+ // Save the starting value, but only once unless override is requested.
534
+ if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
495
535
  _valuesStart[property] = startValue;
496
536
  }
497
537
  if (!startValueIsArray) {
@@ -533,7 +573,7 @@ define(['exports'], function (exports) { 'use strict';
533
573
  return this;
534
574
  };
535
575
  Tween.prototype.pause = function (time) {
536
- if (time === void 0) { time = now$1(); }
576
+ if (time === void 0) { time = now(); }
537
577
  if (this._isPaused || !this._isPlaying) {
538
578
  return this;
539
579
  }
@@ -544,7 +584,7 @@ define(['exports'], function (exports) { 'use strict';
544
584
  return this;
545
585
  };
546
586
  Tween.prototype.resume = function (time) {
547
- if (time === void 0) { time = now$1(); }
587
+ if (time === void 0) { time = now(); }
548
588
  if (!this._isPaused || !this._isPlaying) {
549
589
  return this;
550
590
  }
@@ -562,14 +602,17 @@ define(['exports'], function (exports) { 'use strict';
562
602
  return this;
563
603
  };
564
604
  Tween.prototype.group = function (group) {
605
+ if (group === void 0) { group = mainGroup; }
565
606
  this._group = group;
566
607
  return this;
567
608
  };
568
609
  Tween.prototype.delay = function (amount) {
610
+ if (amount === void 0) { amount = 0; }
569
611
  this._delayTime = amount;
570
612
  return this;
571
613
  };
572
614
  Tween.prototype.repeat = function (times) {
615
+ if (times === void 0) { times = 0; }
573
616
  this._initialRepeat = times;
574
617
  this._repeat = times;
575
618
  return this;
@@ -579,17 +622,21 @@ define(['exports'], function (exports) { 'use strict';
579
622
  return this;
580
623
  };
581
624
  Tween.prototype.yoyo = function (yoyo) {
625
+ if (yoyo === void 0) { yoyo = false; }
582
626
  this._yoyo = yoyo;
583
627
  return this;
584
628
  };
585
629
  Tween.prototype.easing = function (easingFunction) {
630
+ if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
586
631
  this._easingFunction = easingFunction;
587
632
  return this;
588
633
  };
589
634
  Tween.prototype.interpolation = function (interpolationFunction) {
635
+ if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
590
636
  this._interpolationFunction = interpolationFunction;
591
637
  return this;
592
638
  };
639
+ // eslint-disable-next-line
593
640
  Tween.prototype.chain = function () {
594
641
  var tweens = [];
595
642
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -602,6 +649,10 @@ define(['exports'], function (exports) { 'use strict';
602
649
  this._onStartCallback = callback;
603
650
  return this;
604
651
  };
652
+ Tween.prototype.onEveryStart = function (callback) {
653
+ this._onEveryStartCallback = callback;
654
+ return this;
655
+ };
605
656
  Tween.prototype.onUpdate = function (callback) {
606
657
  this._onUpdateCallback = callback;
607
658
  return this;
@@ -624,7 +675,7 @@ define(['exports'], function (exports) { 'use strict';
624
675
  * it is still playing, just paused).
625
676
  */
626
677
  Tween.prototype.update = function (time, autoStart) {
627
- if (time === void 0) { time = now$1(); }
678
+ if (time === void 0) { time = now(); }
628
679
  if (autoStart === void 0) { autoStart = true; }
629
680
  if (this._isPaused)
630
681
  return true;
@@ -635,7 +686,7 @@ define(['exports'], function (exports) { 'use strict';
635
686
  if (time > endTime)
636
687
  return false;
637
688
  if (autoStart)
638
- this.start(time);
689
+ this.start(time, true);
639
690
  }
640
691
  this._goToEnd = false;
641
692
  if (time < this._startTime) {
@@ -647,6 +698,12 @@ define(['exports'], function (exports) { 'use strict';
647
698
  }
648
699
  this._onStartCallbackFired = true;
649
700
  }
701
+ if (this._onEveryStartCallbackFired === false) {
702
+ if (this._onEveryStartCallback) {
703
+ this._onEveryStartCallback(this._object);
704
+ }
705
+ this._onEveryStartCallbackFired = true;
706
+ }
650
707
  elapsed = (time - this._startTime) / this._duration;
651
708
  elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
652
709
  var value = this._easingFunction(elapsed);
@@ -685,6 +742,7 @@ define(['exports'], function (exports) { 'use strict';
685
742
  if (this._onRepeatCallback) {
686
743
  this._onRepeatCallback(this._object);
687
744
  }
745
+ this._onEveryStartCallbackFired = false;
688
746
  return true;
689
747
  }
690
748
  else {
@@ -694,7 +752,7 @@ define(['exports'], function (exports) { 'use strict';
694
752
  for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
695
753
  // Make the chained tweens start exactly at the time they should,
696
754
  // even if the `update()` method was called way past the duration of the tween
697
- this._chainedTweens[i].start(this._startTime + this._duration);
755
+ this._chainedTweens[i].start(this._startTime + this._duration, false);
698
756
  }
699
757
  this._isPlaying = false;
700
758
  return false;
@@ -740,9 +798,7 @@ define(['exports'], function (exports) { 'use strict';
740
798
  if (end.charAt(0) === '+' || end.charAt(0) === '-') {
741
799
  return start + parseFloat(end);
742
800
  }
743
- else {
744
- return parseFloat(end);
745
- }
801
+ return parseFloat(end);
746
802
  };
747
803
  Tween.prototype._swapEndStartRepeatValues = function (property) {
748
804
  var tmp = this._valuesStartRepeat[property];
@@ -758,7 +814,7 @@ define(['exports'], function (exports) { 'use strict';
758
814
  return Tween;
759
815
  }());
760
816
 
761
- var VERSION = '18.6.4';
817
+ var VERSION = '20.0.0';
762
818
 
763
819
  /**
764
820
  * Tween.js - Licensed under the MIT license
@@ -789,7 +845,7 @@ define(['exports'], function (exports) { 'use strict';
789
845
  Easing: Easing,
790
846
  Group: Group,
791
847
  Interpolation: Interpolation,
792
- now: now$1,
848
+ now: now,
793
849
  Sequence: Sequence,
794
850
  nextId: nextId,
795
851
  Tween: Tween,
@@ -811,11 +867,11 @@ define(['exports'], function (exports) { 'use strict';
811
867
  exports.default = exports$1;
812
868
  exports.getAll = getAll;
813
869
  exports.nextId = nextId;
814
- exports.now = now$1;
870
+ exports.now = now;
815
871
  exports.remove = remove;
816
872
  exports.removeAll = removeAll;
817
873
  exports.update = update;
818
874
 
819
875
  Object.defineProperty(exports, '__esModule', { value: true });
820
876
 
821
- });
877
+ }));