@tweenjs/tween.js 22.0.0 → 23.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/tween.amd.js CHANGED
@@ -415,6 +415,9 @@ define(['exports'], (function (exports) { 'use strict';
415
415
  Tween.prototype.isPaused = function () {
416
416
  return this._isPaused;
417
417
  };
418
+ Tween.prototype.getDuration = function () {
419
+ return this._duration;
420
+ };
418
421
  Tween.prototype.to = function (target, duration) {
419
422
  if (duration === void 0) { duration = 1000; }
420
423
  if (this._isPlaying)
@@ -675,12 +678,13 @@ define(['exports'], (function (exports) { 'use strict';
675
678
  * it is still playing, just paused).
676
679
  */
677
680
  Tween.prototype.update = function (time, autoStart) {
681
+ var _this = this;
682
+ var _a;
678
683
  if (time === void 0) { time = now(); }
679
684
  if (autoStart === void 0) { autoStart = true; }
680
685
  if (this._isPaused)
681
686
  return true;
682
687
  var property;
683
- var elapsed;
684
688
  var endTime = this._startTime + this._duration;
685
689
  if (!this._goToEnd && !this._isPlaying) {
686
690
  if (time > endTime)
@@ -704,18 +708,37 @@ define(['exports'], (function (exports) { 'use strict';
704
708
  }
705
709
  this._onEveryStartCallbackFired = true;
706
710
  }
707
- elapsed = (time - this._startTime) / this._duration;
708
- elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
711
+ var elapsedTime = time - this._startTime;
712
+ var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
713
+ var totalTime = this._duration + this._repeat * durationAndDelay;
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();
709
731
  var value = this._easingFunction(elapsed);
710
732
  // properties transformations
711
733
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
712
734
  if (this._onUpdateCallback) {
713
735
  this._onUpdateCallback(this._object, elapsed);
714
736
  }
715
- if (elapsed === 1) {
737
+ if (this._duration === 0 || elapsedTime >= this._duration) {
716
738
  if (this._repeat > 0) {
739
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
717
740
  if (isFinite(this._repeat)) {
718
- this._repeat--;
741
+ this._repeat -= completeCount;
719
742
  }
720
743
  // Reassign starting values, restart by making startTime = now
721
744
  for (property in this._valuesStartRepeat) {
@@ -733,12 +756,7 @@ define(['exports'], (function (exports) { 'use strict';
733
756
  if (this._yoyo) {
734
757
  this._reversed = !this._reversed;
735
758
  }
736
- if (this._repeatDelayTime !== undefined) {
737
- this._startTime = time + this._repeatDelayTime;
738
- }
739
- else {
740
- this._startTime = time + this._delayTime;
741
- }
759
+ this._startTime += durationAndDelay * completeCount;
742
760
  if (this._onRepeatCallback) {
743
761
  this._onRepeatCallback(this._object);
744
762
  }
@@ -814,7 +832,7 @@ define(['exports'], (function (exports) { 'use strict';
814
832
  return Tween;
815
833
  }());
816
834
 
817
- var VERSION = '22.0.0';
835
+ var VERSION = '23.1.0';
818
836
 
819
837
  /**
820
838
  * Tween.js - Licensed under the MIT license
package/dist/tween.cjs CHANGED
@@ -417,6 +417,9 @@ var Tween = /** @class */ (function () {
417
417
  Tween.prototype.isPaused = function () {
418
418
  return this._isPaused;
419
419
  };
420
+ Tween.prototype.getDuration = function () {
421
+ return this._duration;
422
+ };
420
423
  Tween.prototype.to = function (target, duration) {
421
424
  if (duration === void 0) { duration = 1000; }
422
425
  if (this._isPlaying)
@@ -677,12 +680,13 @@ var Tween = /** @class */ (function () {
677
680
  * it is still playing, just paused).
678
681
  */
679
682
  Tween.prototype.update = function (time, autoStart) {
683
+ var _this = this;
684
+ var _a;
680
685
  if (time === void 0) { time = now(); }
681
686
  if (autoStart === void 0) { autoStart = true; }
682
687
  if (this._isPaused)
683
688
  return true;
684
689
  var property;
685
- var elapsed;
686
690
  var endTime = this._startTime + this._duration;
687
691
  if (!this._goToEnd && !this._isPlaying) {
688
692
  if (time > endTime)
@@ -706,18 +710,37 @@ var Tween = /** @class */ (function () {
706
710
  }
707
711
  this._onEveryStartCallbackFired = true;
708
712
  }
709
- elapsed = (time - this._startTime) / this._duration;
710
- elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
713
+ var elapsedTime = time - this._startTime;
714
+ var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
715
+ var totalTime = this._duration + this._repeat * durationAndDelay;
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();
711
733
  var value = this._easingFunction(elapsed);
712
734
  // properties transformations
713
735
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
714
736
  if (this._onUpdateCallback) {
715
737
  this._onUpdateCallback(this._object, elapsed);
716
738
  }
717
- if (elapsed === 1) {
739
+ if (this._duration === 0 || elapsedTime >= this._duration) {
718
740
  if (this._repeat > 0) {
741
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
719
742
  if (isFinite(this._repeat)) {
720
- this._repeat--;
743
+ this._repeat -= completeCount;
721
744
  }
722
745
  // Reassign starting values, restart by making startTime = now
723
746
  for (property in this._valuesStartRepeat) {
@@ -735,12 +758,7 @@ var Tween = /** @class */ (function () {
735
758
  if (this._yoyo) {
736
759
  this._reversed = !this._reversed;
737
760
  }
738
- if (this._repeatDelayTime !== undefined) {
739
- this._startTime = time + this._repeatDelayTime;
740
- }
741
- else {
742
- this._startTime = time + this._delayTime;
743
- }
761
+ this._startTime += durationAndDelay * completeCount;
744
762
  if (this._onRepeatCallback) {
745
763
  this._onRepeatCallback(this._object);
746
764
  }
@@ -816,7 +834,7 @@ var Tween = /** @class */ (function () {
816
834
  return Tween;
817
835
  }());
818
836
 
819
- var VERSION = '22.0.0';
837
+ var VERSION = '23.1.0';
820
838
 
821
839
  /**
822
840
  * Tween.js - Licensed under the MIT license
package/dist/tween.d.ts CHANGED
@@ -104,6 +104,7 @@ declare class Tween<T extends UnknownProps> {
104
104
  getId(): number;
105
105
  isPlaying(): boolean;
106
106
  isPaused(): boolean;
107
+ getDuration(): number;
107
108
  to(target: UnknownProps, duration?: number): this;
108
109
  duration(duration?: number): this;
109
110
  dynamic(dynamic?: boolean): this;
@@ -152,7 +153,7 @@ declare class Sequence {
152
153
  static nextId(): number;
153
154
  }
154
155
 
155
- declare const VERSION = "22.0.0";
156
+ declare const VERSION = "23.1.0";
156
157
 
157
158
  declare const nextId: typeof Sequence.nextId;
158
159
  declare const getAll: () => Tween<UnknownProps>[];
package/dist/tween.esm.js CHANGED
@@ -413,6 +413,9 @@ var Tween = /** @class */ (function () {
413
413
  Tween.prototype.isPaused = function () {
414
414
  return this._isPaused;
415
415
  };
416
+ Tween.prototype.getDuration = function () {
417
+ return this._duration;
418
+ };
416
419
  Tween.prototype.to = function (target, duration) {
417
420
  if (duration === void 0) { duration = 1000; }
418
421
  if (this._isPlaying)
@@ -673,12 +676,13 @@ var Tween = /** @class */ (function () {
673
676
  * it is still playing, just paused).
674
677
  */
675
678
  Tween.prototype.update = function (time, autoStart) {
679
+ var _this = this;
680
+ var _a;
676
681
  if (time === void 0) { time = now(); }
677
682
  if (autoStart === void 0) { autoStart = true; }
678
683
  if (this._isPaused)
679
684
  return true;
680
685
  var property;
681
- var elapsed;
682
686
  var endTime = this._startTime + this._duration;
683
687
  if (!this._goToEnd && !this._isPlaying) {
684
688
  if (time > endTime)
@@ -702,18 +706,37 @@ var Tween = /** @class */ (function () {
702
706
  }
703
707
  this._onEveryStartCallbackFired = true;
704
708
  }
705
- elapsed = (time - this._startTime) / this._duration;
706
- elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
709
+ var elapsedTime = time - this._startTime;
710
+ var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
711
+ var totalTime = this._duration + this._repeat * durationAndDelay;
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();
707
729
  var value = this._easingFunction(elapsed);
708
730
  // properties transformations
709
731
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
710
732
  if (this._onUpdateCallback) {
711
733
  this._onUpdateCallback(this._object, elapsed);
712
734
  }
713
- if (elapsed === 1) {
735
+ if (this._duration === 0 || elapsedTime >= this._duration) {
714
736
  if (this._repeat > 0) {
737
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
715
738
  if (isFinite(this._repeat)) {
716
- this._repeat--;
739
+ this._repeat -= completeCount;
717
740
  }
718
741
  // Reassign starting values, restart by making startTime = now
719
742
  for (property in this._valuesStartRepeat) {
@@ -731,12 +754,7 @@ var Tween = /** @class */ (function () {
731
754
  if (this._yoyo) {
732
755
  this._reversed = !this._reversed;
733
756
  }
734
- if (this._repeatDelayTime !== undefined) {
735
- this._startTime = time + this._repeatDelayTime;
736
- }
737
- else {
738
- this._startTime = time + this._delayTime;
739
- }
757
+ this._startTime += durationAndDelay * completeCount;
740
758
  if (this._onRepeatCallback) {
741
759
  this._onRepeatCallback(this._object);
742
760
  }
@@ -812,7 +830,7 @@ var Tween = /** @class */ (function () {
812
830
  return Tween;
813
831
  }());
814
832
 
815
- var VERSION = '22.0.0';
833
+ var VERSION = '23.1.0';
816
834
 
817
835
  /**
818
836
  * Tween.js - Licensed under the MIT license
package/dist/tween.umd.js CHANGED
@@ -419,6 +419,9 @@
419
419
  Tween.prototype.isPaused = function () {
420
420
  return this._isPaused;
421
421
  };
422
+ Tween.prototype.getDuration = function () {
423
+ return this._duration;
424
+ };
422
425
  Tween.prototype.to = function (target, duration) {
423
426
  if (duration === void 0) { duration = 1000; }
424
427
  if (this._isPlaying)
@@ -679,12 +682,13 @@
679
682
  * it is still playing, just paused).
680
683
  */
681
684
  Tween.prototype.update = function (time, autoStart) {
685
+ var _this = this;
686
+ var _a;
682
687
  if (time === void 0) { time = now(); }
683
688
  if (autoStart === void 0) { autoStart = true; }
684
689
  if (this._isPaused)
685
690
  return true;
686
691
  var property;
687
- var elapsed;
688
692
  var endTime = this._startTime + this._duration;
689
693
  if (!this._goToEnd && !this._isPlaying) {
690
694
  if (time > endTime)
@@ -708,18 +712,37 @@
708
712
  }
709
713
  this._onEveryStartCallbackFired = true;
710
714
  }
711
- elapsed = (time - this._startTime) / this._duration;
712
- elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
715
+ var elapsedTime = time - this._startTime;
716
+ var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
717
+ var totalTime = this._duration + this._repeat * durationAndDelay;
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();
713
735
  var value = this._easingFunction(elapsed);
714
736
  // properties transformations
715
737
  this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
716
738
  if (this._onUpdateCallback) {
717
739
  this._onUpdateCallback(this._object, elapsed);
718
740
  }
719
- if (elapsed === 1) {
741
+ if (this._duration === 0 || elapsedTime >= this._duration) {
720
742
  if (this._repeat > 0) {
743
+ var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
721
744
  if (isFinite(this._repeat)) {
722
- this._repeat--;
745
+ this._repeat -= completeCount;
723
746
  }
724
747
  // Reassign starting values, restart by making startTime = now
725
748
  for (property in this._valuesStartRepeat) {
@@ -737,12 +760,7 @@
737
760
  if (this._yoyo) {
738
761
  this._reversed = !this._reversed;
739
762
  }
740
- if (this._repeatDelayTime !== undefined) {
741
- this._startTime = time + this._repeatDelayTime;
742
- }
743
- else {
744
- this._startTime = time + this._delayTime;
745
- }
763
+ this._startTime += durationAndDelay * completeCount;
746
764
  if (this._onRepeatCallback) {
747
765
  this._onRepeatCallback(this._object);
748
766
  }
@@ -818,7 +836,7 @@
818
836
  return Tween;
819
837
  }());
820
838
 
821
- var VERSION = '22.0.0';
839
+ var VERSION = '23.1.0';
822
840
 
823
841
  /**
824
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": "22.0.0",
4
+ "version": "23.1.0",
5
5
  "type": "module",
6
6
  "main": "dist/tween.cjs",
7
7
  "types": "dist/tween.d.ts",