@tweenjs/tween.js 23.1.2 → 23.1.3

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 CHANGED
@@ -9,7 +9,7 @@ JavaScript (TypeScript) tweening engine for easy animations, incorporating optim
9
9
 
10
10
  More languages: [English](./README.md), [简体中文](./README_zh-CN.md)
11
11
 
12
- # Example
12
+ ---
13
13
 
14
14
  ```html
15
15
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/20.0.0/tween.umd.js"></script>
@@ -48,10 +48,7 @@ More languages: [English](./README.md), [简体中文](./README_zh-CN.md)
48
48
  </script>
49
49
  ```
50
50
 
51
- [Try the above example on CodePen](https://codepen.io/trusktr/pen/KKGaBVz?editors=1000)
52
-
53
- Animate numbers in any JavaScript object. For example, [rotate a 3D box made
54
- with Three.js](https://codepen.io/trusktr/pen/ExJqvgZ):
51
+ [Try this example on CodePen](https://codepen.io/trusktr/pen/KKGaBVz?editors=1000)
55
52
 
56
53
  # Installation
57
54
 
package/dist/tween.amd.js CHANGED
@@ -678,11 +678,13 @@ define(['exports'], (function (exports) { 'use strict';
678
678
  * it is still playing, just paused).
679
679
  */
680
680
  Tween.prototype.update = function (time, autoStart) {
681
+ var _this = this;
681
682
  var _a;
682
683
  if (time === void 0) { time = now(); }
683
684
  if (autoStart === void 0) { autoStart = true; }
684
685
  if (this._isPaused)
685
686
  return true;
687
+ var property;
686
688
  var endTime = this._startTime + this._duration;
687
689
  if (!this._goToEnd && !this._isPlaying) {
688
690
  if (time > endTime)
@@ -709,85 +711,72 @@ define(['exports'], (function (exports) { 'use strict';
709
711
  var elapsedTime = time - this._startTime;
710
712
  var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
711
713
  var totalTime = this._duration + this._repeat * durationAndDelay;
712
- var elapsed = this._calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime);
714
+ var calculateElapsedPortion = function () {
715
+ if (_this._duration === 0)
716
+ return 1;
717
+ if (elapsedTime > totalTime) {
718
+ return 1;
719
+ }
720
+ var timesRepeated = Math.trunc(elapsedTime / durationAndDelay);
721
+ var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay;
722
+ // TODO use %?
723
+ // const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
724
+ var portion = Math.min(timeIntoCurrentRepeat / _this._duration, 1);
725
+ if (portion === 0 && elapsedTime === _this._duration) {
726
+ return 1;
727
+ }
728
+ return portion;
729
+ };
730
+ var elapsed = calculateElapsedPortion();
713
731
  var value = this._easingFunction(elapsed);
714
- var status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
715
- if (status === 'repeat') {
716
- // the current update is happening after the instant the tween repeated
717
- this._processRepetition(elapsedTime, durationAndDelay);
718
- }
732
+ // properties transformations
719
733
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
720
- if (status === 'about-to-repeat') {
721
- // the current update is happening at the exact instant the tween is going to repeat
722
- // the values should match the end of the tween, not the beginning,
723
- // that's why _processRepetition happens after _updateProperties
724
- this._processRepetition(elapsedTime, durationAndDelay);
725
- }
726
734
  if (this._onUpdateCallback) {
727
735
  this._onUpdateCallback(this._object, elapsed);
728
736
  }
729
- if (status === 'repeat' || status === 'about-to-repeat') {
730
- if (this._onRepeatCallback) {
731
- this._onRepeatCallback(this._object);
732
- }
733
- this._onEveryStartCallbackFired = false;
734
- }
735
- else if (status === 'completed') {
736
- this._isPlaying = false;
737
- if (this._onCompleteCallback) {
738
- this._onCompleteCallback(this._object);
739
- }
740
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
741
- // Make the chained tweens start exactly at the time they should,
742
- // even if the `update()` method was called way past the duration of the tween
743
- this._chainedTweens[i].start(this._startTime + this._duration, false);
744
- }
745
- }
746
- return status !== 'completed';
747
- };
748
- Tween.prototype._calculateElapsedPortion = function (elapsedTime, durationAndDelay, totalTime) {
749
- if (this._duration === 0 || elapsedTime > totalTime) {
750
- return 1;
751
- }
752
- var timeIntoCurrentRepeat = elapsedTime % durationAndDelay;
753
- var portion = Math.min(timeIntoCurrentRepeat / this._duration, 1);
754
- if (portion === 0 && elapsedTime !== 0 && elapsedTime % this._duration === 0) {
755
- return 1;
756
- }
757
- return portion;
758
- };
759
- Tween.prototype._calculateCompletionStatus = function (elapsedTime, durationAndDelay) {
760
- if (this._duration !== 0 && elapsedTime < this._duration) {
761
- return 'playing';
762
- }
763
- if (this._repeat <= 0) {
764
- return 'completed';
765
- }
766
- if (elapsedTime === this._duration) {
767
- return 'about-to-repeat';
768
- }
769
- return 'repeat';
770
- };
771
- Tween.prototype._processRepetition = function (elapsedTime, durationAndDelay) {
772
- var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
773
- if (isFinite(this._repeat)) {
774
- this._repeat -= completeCount;
775
- }
776
- // Reassign starting values, restart by making startTime = now
777
- for (var property in this._valuesStartRepeat) {
778
- var valueEnd = this._valuesEnd[property];
779
- if (!this._yoyo && typeof valueEnd === 'string') {
780
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(valueEnd);
737
+ if (this._duration === 0 || elapsedTime >= this._duration) {
738
+ if (this._repeat > 0) {
739
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
740
+ if (isFinite(this._repeat)) {
741
+ this._repeat -= completeCount;
742
+ }
743
+ // Reassign starting values, restart by making startTime = now
744
+ for (property in this._valuesStartRepeat) {
745
+ if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
746
+ this._valuesStartRepeat[property] =
747
+ // eslint-disable-next-line
748
+ // @ts-ignore FIXME?
749
+ this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
750
+ }
751
+ if (this._yoyo) {
752
+ this._swapEndStartRepeatValues(property);
753
+ }
754
+ this._valuesStart[property] = this._valuesStartRepeat[property];
755
+ }
756
+ if (this._yoyo) {
757
+ this._reversed = !this._reversed;
758
+ }
759
+ this._startTime += durationAndDelay * completeCount;
760
+ if (this._onRepeatCallback) {
761
+ this._onRepeatCallback(this._object);
762
+ }
763
+ this._onEveryStartCallbackFired = false;
764
+ return true;
781
765
  }
782
- if (this._yoyo) {
783
- this._swapEndStartRepeatValues(property);
766
+ else {
767
+ if (this._onCompleteCallback) {
768
+ this._onCompleteCallback(this._object);
769
+ }
770
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
771
+ // Make the chained tweens start exactly at the time they should,
772
+ // even if the `update()` method was called way past the duration of the tween
773
+ this._chainedTweens[i].start(this._startTime + this._duration, false);
774
+ }
775
+ this._isPlaying = false;
776
+ return false;
784
777
  }
785
- this._valuesStart[property] = this._valuesStartRepeat[property];
786
778
  }
787
- if (this._yoyo) {
788
- this._reversed = !this._reversed;
789
- }
790
- this._startTime += durationAndDelay * completeCount;
779
+ return true;
791
780
  };
792
781
  Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
793
782
  for (var property in _valuesEnd) {
@@ -843,7 +832,7 @@ define(['exports'], (function (exports) { 'use strict';
843
832
  return Tween;
844
833
  }());
845
834
 
846
- var VERSION = '23.1.2';
835
+ var VERSION = '23.1.3';
847
836
 
848
837
  /**
849
838
  * Tween.js - Licensed under the MIT license
package/dist/tween.cjs CHANGED
@@ -680,11 +680,13 @@ var Tween = /** @class */ (function () {
680
680
  * it is still playing, just paused).
681
681
  */
682
682
  Tween.prototype.update = function (time, autoStart) {
683
+ var _this = this;
683
684
  var _a;
684
685
  if (time === void 0) { time = now(); }
685
686
  if (autoStart === void 0) { autoStart = true; }
686
687
  if (this._isPaused)
687
688
  return true;
689
+ var property;
688
690
  var endTime = this._startTime + this._duration;
689
691
  if (!this._goToEnd && !this._isPlaying) {
690
692
  if (time > endTime)
@@ -711,85 +713,72 @@ var Tween = /** @class */ (function () {
711
713
  var elapsedTime = time - this._startTime;
712
714
  var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
713
715
  var totalTime = this._duration + this._repeat * durationAndDelay;
714
- var elapsed = this._calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime);
716
+ var calculateElapsedPortion = function () {
717
+ if (_this._duration === 0)
718
+ return 1;
719
+ if (elapsedTime > totalTime) {
720
+ return 1;
721
+ }
722
+ var timesRepeated = Math.trunc(elapsedTime / durationAndDelay);
723
+ var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay;
724
+ // TODO use %?
725
+ // const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
726
+ var portion = Math.min(timeIntoCurrentRepeat / _this._duration, 1);
727
+ if (portion === 0 && elapsedTime === _this._duration) {
728
+ return 1;
729
+ }
730
+ return portion;
731
+ };
732
+ var elapsed = calculateElapsedPortion();
715
733
  var value = this._easingFunction(elapsed);
716
- var status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
717
- if (status === 'repeat') {
718
- // the current update is happening after the instant the tween repeated
719
- this._processRepetition(elapsedTime, durationAndDelay);
720
- }
734
+ // properties transformations
721
735
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
722
- if (status === 'about-to-repeat') {
723
- // the current update is happening at the exact instant the tween is going to repeat
724
- // the values should match the end of the tween, not the beginning,
725
- // that's why _processRepetition happens after _updateProperties
726
- this._processRepetition(elapsedTime, durationAndDelay);
727
- }
728
736
  if (this._onUpdateCallback) {
729
737
  this._onUpdateCallback(this._object, elapsed);
730
738
  }
731
- if (status === 'repeat' || status === 'about-to-repeat') {
732
- if (this._onRepeatCallback) {
733
- this._onRepeatCallback(this._object);
734
- }
735
- this._onEveryStartCallbackFired = false;
736
- }
737
- else if (status === 'completed') {
738
- this._isPlaying = false;
739
- if (this._onCompleteCallback) {
740
- this._onCompleteCallback(this._object);
741
- }
742
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
743
- // Make the chained tweens start exactly at the time they should,
744
- // even if the `update()` method was called way past the duration of the tween
745
- this._chainedTweens[i].start(this._startTime + this._duration, false);
746
- }
747
- }
748
- return status !== 'completed';
749
- };
750
- Tween.prototype._calculateElapsedPortion = function (elapsedTime, durationAndDelay, totalTime) {
751
- if (this._duration === 0 || elapsedTime > totalTime) {
752
- return 1;
753
- }
754
- var timeIntoCurrentRepeat = elapsedTime % durationAndDelay;
755
- var portion = Math.min(timeIntoCurrentRepeat / this._duration, 1);
756
- if (portion === 0 && elapsedTime !== 0 && elapsedTime % this._duration === 0) {
757
- return 1;
758
- }
759
- return portion;
760
- };
761
- Tween.prototype._calculateCompletionStatus = function (elapsedTime, durationAndDelay) {
762
- if (this._duration !== 0 && elapsedTime < this._duration) {
763
- return 'playing';
764
- }
765
- if (this._repeat <= 0) {
766
- return 'completed';
767
- }
768
- if (elapsedTime === this._duration) {
769
- return 'about-to-repeat';
770
- }
771
- return 'repeat';
772
- };
773
- Tween.prototype._processRepetition = function (elapsedTime, durationAndDelay) {
774
- var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
775
- if (isFinite(this._repeat)) {
776
- this._repeat -= completeCount;
777
- }
778
- // Reassign starting values, restart by making startTime = now
779
- for (var property in this._valuesStartRepeat) {
780
- var valueEnd = this._valuesEnd[property];
781
- if (!this._yoyo && typeof valueEnd === 'string') {
782
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(valueEnd);
739
+ if (this._duration === 0 || elapsedTime >= this._duration) {
740
+ if (this._repeat > 0) {
741
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
742
+ if (isFinite(this._repeat)) {
743
+ this._repeat -= completeCount;
744
+ }
745
+ // Reassign starting values, restart by making startTime = now
746
+ for (property in this._valuesStartRepeat) {
747
+ if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
748
+ this._valuesStartRepeat[property] =
749
+ // eslint-disable-next-line
750
+ // @ts-ignore FIXME?
751
+ this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
752
+ }
753
+ if (this._yoyo) {
754
+ this._swapEndStartRepeatValues(property);
755
+ }
756
+ this._valuesStart[property] = this._valuesStartRepeat[property];
757
+ }
758
+ if (this._yoyo) {
759
+ this._reversed = !this._reversed;
760
+ }
761
+ this._startTime += durationAndDelay * completeCount;
762
+ if (this._onRepeatCallback) {
763
+ this._onRepeatCallback(this._object);
764
+ }
765
+ this._onEveryStartCallbackFired = false;
766
+ return true;
783
767
  }
784
- if (this._yoyo) {
785
- this._swapEndStartRepeatValues(property);
768
+ else {
769
+ if (this._onCompleteCallback) {
770
+ this._onCompleteCallback(this._object);
771
+ }
772
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
773
+ // Make the chained tweens start exactly at the time they should,
774
+ // even if the `update()` method was called way past the duration of the tween
775
+ this._chainedTweens[i].start(this._startTime + this._duration, false);
776
+ }
777
+ this._isPlaying = false;
778
+ return false;
786
779
  }
787
- this._valuesStart[property] = this._valuesStartRepeat[property];
788
780
  }
789
- if (this._yoyo) {
790
- this._reversed = !this._reversed;
791
- }
792
- this._startTime += durationAndDelay * completeCount;
781
+ return true;
793
782
  };
794
783
  Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
795
784
  for (var property in _valuesEnd) {
@@ -845,7 +834,7 @@ var Tween = /** @class */ (function () {
845
834
  return Tween;
846
835
  }());
847
836
 
848
- var VERSION = '23.1.2';
837
+ var VERSION = '23.1.3';
849
838
 
850
839
  /**
851
840
  * Tween.js - Licensed under the MIT license
package/dist/tween.d.ts CHANGED
@@ -137,9 +137,6 @@ declare class Tween<T extends UnknownProps> {
137
137
  * it is still playing, just paused).
138
138
  */
139
139
  update(time?: number, autoStart?: boolean): boolean;
140
- private _calculateElapsedPortion;
141
- private _calculateCompletionStatus;
142
- private _processRepetition;
143
140
  private _updateProperties;
144
141
  private _handleRelativeValue;
145
142
  private _swapEndStartRepeatValues;
@@ -156,7 +153,7 @@ declare class Sequence {
156
153
  static nextId(): number;
157
154
  }
158
155
 
159
- declare const VERSION = "23.1.2";
156
+ declare const VERSION = "23.1.3";
160
157
 
161
158
  declare const nextId: typeof Sequence.nextId;
162
159
  declare const getAll: () => Tween<UnknownProps>[];
package/dist/tween.esm.js CHANGED
@@ -676,11 +676,13 @@ var Tween = /** @class */ (function () {
676
676
  * it is still playing, just paused).
677
677
  */
678
678
  Tween.prototype.update = function (time, autoStart) {
679
+ var _this = this;
679
680
  var _a;
680
681
  if (time === void 0) { time = now(); }
681
682
  if (autoStart === void 0) { autoStart = true; }
682
683
  if (this._isPaused)
683
684
  return true;
685
+ var property;
684
686
  var endTime = this._startTime + this._duration;
685
687
  if (!this._goToEnd && !this._isPlaying) {
686
688
  if (time > endTime)
@@ -707,85 +709,72 @@ var Tween = /** @class */ (function () {
707
709
  var elapsedTime = time - this._startTime;
708
710
  var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
709
711
  var totalTime = this._duration + this._repeat * durationAndDelay;
710
- var elapsed = this._calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime);
712
+ var calculateElapsedPortion = function () {
713
+ if (_this._duration === 0)
714
+ return 1;
715
+ if (elapsedTime > totalTime) {
716
+ return 1;
717
+ }
718
+ var timesRepeated = Math.trunc(elapsedTime / durationAndDelay);
719
+ var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay;
720
+ // TODO use %?
721
+ // const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
722
+ var portion = Math.min(timeIntoCurrentRepeat / _this._duration, 1);
723
+ if (portion === 0 && elapsedTime === _this._duration) {
724
+ return 1;
725
+ }
726
+ return portion;
727
+ };
728
+ var elapsed = calculateElapsedPortion();
711
729
  var value = this._easingFunction(elapsed);
712
- var status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
713
- if (status === 'repeat') {
714
- // the current update is happening after the instant the tween repeated
715
- this._processRepetition(elapsedTime, durationAndDelay);
716
- }
730
+ // properties transformations
717
731
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
718
- if (status === 'about-to-repeat') {
719
- // the current update is happening at the exact instant the tween is going to repeat
720
- // the values should match the end of the tween, not the beginning,
721
- // that's why _processRepetition happens after _updateProperties
722
- this._processRepetition(elapsedTime, durationAndDelay);
723
- }
724
732
  if (this._onUpdateCallback) {
725
733
  this._onUpdateCallback(this._object, elapsed);
726
734
  }
727
- if (status === 'repeat' || status === 'about-to-repeat') {
728
- if (this._onRepeatCallback) {
729
- this._onRepeatCallback(this._object);
730
- }
731
- this._onEveryStartCallbackFired = false;
732
- }
733
- else if (status === 'completed') {
734
- this._isPlaying = false;
735
- if (this._onCompleteCallback) {
736
- this._onCompleteCallback(this._object);
737
- }
738
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
739
- // Make the chained tweens start exactly at the time they should,
740
- // even if the `update()` method was called way past the duration of the tween
741
- this._chainedTweens[i].start(this._startTime + this._duration, false);
742
- }
743
- }
744
- return status !== 'completed';
745
- };
746
- Tween.prototype._calculateElapsedPortion = function (elapsedTime, durationAndDelay, totalTime) {
747
- if (this._duration === 0 || elapsedTime > totalTime) {
748
- return 1;
749
- }
750
- var timeIntoCurrentRepeat = elapsedTime % durationAndDelay;
751
- var portion = Math.min(timeIntoCurrentRepeat / this._duration, 1);
752
- if (portion === 0 && elapsedTime !== 0 && elapsedTime % this._duration === 0) {
753
- return 1;
754
- }
755
- return portion;
756
- };
757
- Tween.prototype._calculateCompletionStatus = function (elapsedTime, durationAndDelay) {
758
- if (this._duration !== 0 && elapsedTime < this._duration) {
759
- return 'playing';
760
- }
761
- if (this._repeat <= 0) {
762
- return 'completed';
763
- }
764
- if (elapsedTime === this._duration) {
765
- return 'about-to-repeat';
766
- }
767
- return 'repeat';
768
- };
769
- Tween.prototype._processRepetition = function (elapsedTime, durationAndDelay) {
770
- var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
771
- if (isFinite(this._repeat)) {
772
- this._repeat -= completeCount;
773
- }
774
- // Reassign starting values, restart by making startTime = now
775
- for (var property in this._valuesStartRepeat) {
776
- var valueEnd = this._valuesEnd[property];
777
- if (!this._yoyo && typeof valueEnd === 'string') {
778
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(valueEnd);
735
+ if (this._duration === 0 || elapsedTime >= this._duration) {
736
+ if (this._repeat > 0) {
737
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
738
+ if (isFinite(this._repeat)) {
739
+ this._repeat -= completeCount;
740
+ }
741
+ // Reassign starting values, restart by making startTime = now
742
+ for (property in this._valuesStartRepeat) {
743
+ if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
744
+ this._valuesStartRepeat[property] =
745
+ // eslint-disable-next-line
746
+ // @ts-ignore FIXME?
747
+ this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
748
+ }
749
+ if (this._yoyo) {
750
+ this._swapEndStartRepeatValues(property);
751
+ }
752
+ this._valuesStart[property] = this._valuesStartRepeat[property];
753
+ }
754
+ if (this._yoyo) {
755
+ this._reversed = !this._reversed;
756
+ }
757
+ this._startTime += durationAndDelay * completeCount;
758
+ if (this._onRepeatCallback) {
759
+ this._onRepeatCallback(this._object);
760
+ }
761
+ this._onEveryStartCallbackFired = false;
762
+ return true;
779
763
  }
780
- if (this._yoyo) {
781
- this._swapEndStartRepeatValues(property);
764
+ else {
765
+ if (this._onCompleteCallback) {
766
+ this._onCompleteCallback(this._object);
767
+ }
768
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
769
+ // Make the chained tweens start exactly at the time they should,
770
+ // even if the `update()` method was called way past the duration of the tween
771
+ this._chainedTweens[i].start(this._startTime + this._duration, false);
772
+ }
773
+ this._isPlaying = false;
774
+ return false;
782
775
  }
783
- this._valuesStart[property] = this._valuesStartRepeat[property];
784
776
  }
785
- if (this._yoyo) {
786
- this._reversed = !this._reversed;
787
- }
788
- this._startTime += durationAndDelay * completeCount;
777
+ return true;
789
778
  };
790
779
  Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
791
780
  for (var property in _valuesEnd) {
@@ -841,7 +830,7 @@ var Tween = /** @class */ (function () {
841
830
  return Tween;
842
831
  }());
843
832
 
844
- var VERSION = '23.1.2';
833
+ var VERSION = '23.1.3';
845
834
 
846
835
  /**
847
836
  * Tween.js - Licensed under the MIT license
package/dist/tween.umd.js CHANGED
@@ -682,11 +682,13 @@
682
682
  * it is still playing, just paused).
683
683
  */
684
684
  Tween.prototype.update = function (time, autoStart) {
685
+ var _this = this;
685
686
  var _a;
686
687
  if (time === void 0) { time = now(); }
687
688
  if (autoStart === void 0) { autoStart = true; }
688
689
  if (this._isPaused)
689
690
  return true;
691
+ var property;
690
692
  var endTime = this._startTime + this._duration;
691
693
  if (!this._goToEnd && !this._isPlaying) {
692
694
  if (time > endTime)
@@ -713,85 +715,72 @@
713
715
  var elapsedTime = time - this._startTime;
714
716
  var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
715
717
  var totalTime = this._duration + this._repeat * durationAndDelay;
716
- var elapsed = this._calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime);
718
+ var calculateElapsedPortion = function () {
719
+ if (_this._duration === 0)
720
+ return 1;
721
+ if (elapsedTime > totalTime) {
722
+ return 1;
723
+ }
724
+ var timesRepeated = Math.trunc(elapsedTime / durationAndDelay);
725
+ var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay;
726
+ // TODO use %?
727
+ // const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
728
+ var portion = Math.min(timeIntoCurrentRepeat / _this._duration, 1);
729
+ if (portion === 0 && elapsedTime === _this._duration) {
730
+ return 1;
731
+ }
732
+ return portion;
733
+ };
734
+ var elapsed = calculateElapsedPortion();
717
735
  var value = this._easingFunction(elapsed);
718
- var status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
719
- if (status === 'repeat') {
720
- // the current update is happening after the instant the tween repeated
721
- this._processRepetition(elapsedTime, durationAndDelay);
722
- }
736
+ // properties transformations
723
737
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
724
- if (status === 'about-to-repeat') {
725
- // the current update is happening at the exact instant the tween is going to repeat
726
- // the values should match the end of the tween, not the beginning,
727
- // that's why _processRepetition happens after _updateProperties
728
- this._processRepetition(elapsedTime, durationAndDelay);
729
- }
730
738
  if (this._onUpdateCallback) {
731
739
  this._onUpdateCallback(this._object, elapsed);
732
740
  }
733
- if (status === 'repeat' || status === 'about-to-repeat') {
734
- if (this._onRepeatCallback) {
735
- this._onRepeatCallback(this._object);
736
- }
737
- this._onEveryStartCallbackFired = false;
738
- }
739
- else if (status === 'completed') {
740
- this._isPlaying = false;
741
- if (this._onCompleteCallback) {
742
- this._onCompleteCallback(this._object);
743
- }
744
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
745
- // Make the chained tweens start exactly at the time they should,
746
- // even if the `update()` method was called way past the duration of the tween
747
- this._chainedTweens[i].start(this._startTime + this._duration, false);
748
- }
749
- }
750
- return status !== 'completed';
751
- };
752
- Tween.prototype._calculateElapsedPortion = function (elapsedTime, durationAndDelay, totalTime) {
753
- if (this._duration === 0 || elapsedTime > totalTime) {
754
- return 1;
755
- }
756
- var timeIntoCurrentRepeat = elapsedTime % durationAndDelay;
757
- var portion = Math.min(timeIntoCurrentRepeat / this._duration, 1);
758
- if (portion === 0 && elapsedTime !== 0 && elapsedTime % this._duration === 0) {
759
- return 1;
760
- }
761
- return portion;
762
- };
763
- Tween.prototype._calculateCompletionStatus = function (elapsedTime, durationAndDelay) {
764
- if (this._duration !== 0 && elapsedTime < this._duration) {
765
- return 'playing';
766
- }
767
- if (this._repeat <= 0) {
768
- return 'completed';
769
- }
770
- if (elapsedTime === this._duration) {
771
- return 'about-to-repeat';
772
- }
773
- return 'repeat';
774
- };
775
- Tween.prototype._processRepetition = function (elapsedTime, durationAndDelay) {
776
- var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
777
- if (isFinite(this._repeat)) {
778
- this._repeat -= completeCount;
779
- }
780
- // Reassign starting values, restart by making startTime = now
781
- for (var property in this._valuesStartRepeat) {
782
- var valueEnd = this._valuesEnd[property];
783
- if (!this._yoyo && typeof valueEnd === 'string') {
784
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(valueEnd);
741
+ if (this._duration === 0 || elapsedTime >= this._duration) {
742
+ if (this._repeat > 0) {
743
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
744
+ if (isFinite(this._repeat)) {
745
+ this._repeat -= completeCount;
746
+ }
747
+ // Reassign starting values, restart by making startTime = now
748
+ for (property in this._valuesStartRepeat) {
749
+ if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
750
+ this._valuesStartRepeat[property] =
751
+ // eslint-disable-next-line
752
+ // @ts-ignore FIXME?
753
+ this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
754
+ }
755
+ if (this._yoyo) {
756
+ this._swapEndStartRepeatValues(property);
757
+ }
758
+ this._valuesStart[property] = this._valuesStartRepeat[property];
759
+ }
760
+ if (this._yoyo) {
761
+ this._reversed = !this._reversed;
762
+ }
763
+ this._startTime += durationAndDelay * completeCount;
764
+ if (this._onRepeatCallback) {
765
+ this._onRepeatCallback(this._object);
766
+ }
767
+ this._onEveryStartCallbackFired = false;
768
+ return true;
785
769
  }
786
- if (this._yoyo) {
787
- this._swapEndStartRepeatValues(property);
770
+ else {
771
+ if (this._onCompleteCallback) {
772
+ this._onCompleteCallback(this._object);
773
+ }
774
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
775
+ // Make the chained tweens start exactly at the time they should,
776
+ // even if the `update()` method was called way past the duration of the tween
777
+ this._chainedTweens[i].start(this._startTime + this._duration, false);
778
+ }
779
+ this._isPlaying = false;
780
+ return false;
788
781
  }
789
- this._valuesStart[property] = this._valuesStartRepeat[property];
790
782
  }
791
- if (this._yoyo) {
792
- this._reversed = !this._reversed;
793
- }
794
- this._startTime += durationAndDelay * completeCount;
783
+ return true;
795
784
  };
796
785
  Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
797
786
  for (var property in _valuesEnd) {
@@ -847,7 +836,7 @@
847
836
  return Tween;
848
837
  }());
849
838
 
850
- var VERSION = '23.1.2';
839
+ var VERSION = '23.1.3';
851
840
 
852
841
  /**
853
842
  * 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": "Simple and fast tweening engine with optimised Robert Penner's equations.",
4
- "version": "23.1.2",
4
+ "version": "23.1.3",
5
5
  "type": "module",
6
6
  "main": "dist/tween.cjs",
7
7
  "types": "dist/tween.d.ts",
@@ -39,10 +39,10 @@
39
39
  "tsc": "tsc",
40
40
  "tsc-watch": "tsc --watch",
41
41
  "examples": "npx serve .",
42
- "test": "npm run build && npm run format-check && npm run test-unit",
42
+ "test": "npm run build && npm run test-lint && npm run test-unit",
43
43
  "test-unit": "nodeunit test/unit/nodeunitheadless.cjs",
44
- "format-check": "npm run prettier -- --check",
45
- "format": "npm run prettier -- --write",
44
+ "test-lint": "npm run prettier -- --check",
45
+ "lint": "npm run prettier -- --write",
46
46
  "prettier": "prettier .",
47
47
  "prepare": "npm run build",
48
48
  "version": "npm test && git add .",