Skip to content

Commit 0e87eaa

Browse files
authored
Merge branch 'main' into patch-1
2 parents c880846 + d5ed238 commit 0e87eaa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+5552
-2385
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 21 deletions
This file was deleted.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist/
22
.tmp/
33
.vscode/
44
examples/js/stats.min.js
5+
examples/example-projects/plain-typescript-modules/**/*.js

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ import * as TWEEN from '@tweenjs/tween.js'
153153
- [Contributor guide](./docs/contributor_guide.md)
154154
- [Tutorial](https://web.archive.org/web/20220601192930/http://learningthreejs.com/blog/2011/08/17/tweenjs-for-smooth-animation/) using tween.js with three.js
155155
- Also: [libtween](https://github.com/jsm174/libtween), a port of tween.js to C by [jsm174](https://github.com/jsm174)
156-
- [Understanding tween.js](https://mikebolt.me/article/understanding-tweenjs.html)
157156

158157
# Examples
159158

@@ -369,7 +368,7 @@ If you want to add any feature or change existing features, you _must_ run the t
369368

370369
# People
371370

372-
Maintainers: [mikebolt](https://github.com/mikebolt), [sole](https://github.com/sole), [Joe Pea (@trusktr)](https://github.com/trusktr).
371+
Maintainers: [Joe Pea (@trusktr)](https://github.com/trusktr).
373372

374373
[All contributors](http://github.com/tweenjs/tween.js/contributors).
375374

dist/tween.amd.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ define(['exports'], (function (exports) { 'use strict';
415415
Tween.prototype.isPaused = function () {
416416
return this._isPaused;
417417
};
418+
Tween.prototype.getDuration = function () {
419+
return this._duration;
420+
};
418421
Tween.prototype.to = function (target, duration) {
419422
if (duration === void 0) { duration = 1000; }
420423
if (this._isPlaying)
@@ -675,12 +678,13 @@ define(['exports'], (function (exports) { 'use strict';
675678
* it is still playing, just paused).
676679
*/
677680
Tween.prototype.update = function (time, autoStart) {
681+
var _this = this;
682+
var _a;
678683
if (time === void 0) { time = now(); }
679684
if (autoStart === void 0) { autoStart = true; }
680685
if (this._isPaused)
681686
return true;
682687
var property;
683-
var elapsed;
684688
var endTime = this._startTime + this._duration;
685689
if (!this._goToEnd && !this._isPlaying) {
686690
if (time > endTime)
@@ -704,18 +708,37 @@ define(['exports'], (function (exports) { 'use strict';
704708
}
705709
this._onEveryStartCallbackFired = true;
706710
}
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();
709731
var value = this._easingFunction(elapsed);
710732
// properties transformations
711733
this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
712734
if (this._onUpdateCallback) {
713735
this._onUpdateCallback(this._object, elapsed);
714736
}
715-
if (elapsed === 1) {
737+
if (this._duration === 0 || elapsedTime >= this._duration) {
716738
if (this._repeat > 0) {
739+
var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
717740
if (isFinite(this._repeat)) {
718-
this._repeat--;
741+
this._repeat -= completeCount;
719742
}
720743
// Reassign starting values, restart by making startTime = now
721744
for (property in this._valuesStartRepeat) {
@@ -733,12 +756,7 @@ define(['exports'], (function (exports) { 'use strict';
733756
if (this._yoyo) {
734757
this._reversed = !this._reversed;
735758
}
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;
742760
if (this._onRepeatCallback) {
743761
this._onRepeatCallback(this._object);
744762
}
@@ -814,7 +832,7 @@ define(['exports'], (function (exports) { 'use strict';
814832
return Tween;
815833
}());
816834

817-
var VERSION = '21.0.0';
835+
var VERSION = '23.1.0';
818836

819837
/**
820838
* Tween.js - Licensed under the MIT license

dist/tween.cjs.js renamed to dist/tween.cjs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ var Tween = /** @class */ (function () {
417417
Tween.prototype.isPaused = function () {
418418
return this._isPaused;
419419
};
420+
Tween.prototype.getDuration = function () {
421+
return this._duration;
422+
};
420423
Tween.prototype.to = function (target, duration) {
421424
if (duration === void 0) { duration = 1000; }
422425
if (this._isPlaying)
@@ -677,12 +680,13 @@ var Tween = /** @class */ (function () {
677680
* it is still playing, just paused).
678681
*/
679682
Tween.prototype.update = function (time, autoStart) {
683+
var _this = this;
684+
var _a;
680685
if (time === void 0) { time = now(); }
681686
if (autoStart === void 0) { autoStart = true; }
682687
if (this._isPaused)
683688
return true;
684689
var property;
685-
var elapsed;
686690
var endTime = this._startTime + this._duration;
687691
if (!this._goToEnd && !this._isPlaying) {
688692
if (time > endTime)
@@ -706,18 +710,37 @@ var Tween = /** @class */ (function () {
706710
}
707711
this._onEveryStartCallbackFired = true;
708712
}
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();
711733
var value = this._easingFunction(elapsed);
712734
// properties transformations
713735
this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
714736
if (this._onUpdateCallback) {
715737
this._onUpdateCallback(this._object, elapsed);
716738
}
717-
if (elapsed === 1) {
739+
if (this._duration === 0 || elapsedTime >= this._duration) {
718740
if (this._repeat > 0) {
741+
var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
719742
if (isFinite(this._repeat)) {
720-
this._repeat--;
743+
this._repeat -= completeCount;
721744
}
722745
// Reassign starting values, restart by making startTime = now
723746
for (property in this._valuesStartRepeat) {
@@ -735,12 +758,7 @@ var Tween = /** @class */ (function () {
735758
if (this._yoyo) {
736759
this._reversed = !this._reversed;
737760
}
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;
744762
if (this._onRepeatCallback) {
745763
this._onRepeatCallback(this._object);
746764
}
@@ -816,7 +834,7 @@ var Tween = /** @class */ (function () {
816834
return Tween;
817835
}());
818836

819-
var VERSION = '21.0.0';
837+
var VERSION = '23.1.0';
820838

821839
/**
822840
* Tween.js - Licensed under the MIT license

dist/tween.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ declare class Tween<T extends UnknownProps> {
104104
getId(): number;
105105
isPlaying(): boolean;
106106
isPaused(): boolean;
107+
getDuration(): number;
107108
to(target: UnknownProps, duration?: number): this;
108109
duration(duration?: number): this;
109110
dynamic(dynamic?: boolean): this;
@@ -152,7 +153,7 @@ declare class Sequence {
152153
static nextId(): number;
153154
}
154155

155-
declare const VERSION = "21.0.0";
156+
declare const VERSION = "23.1.0";
156157

157158
declare const nextId: typeof Sequence.nextId;
158159
declare const getAll: () => Tween<UnknownProps>[];

dist/tween.esm.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ var Tween = /** @class */ (function () {
413413
Tween.prototype.isPaused = function () {
414414
return this._isPaused;
415415
};
416+
Tween.prototype.getDuration = function () {
417+
return this._duration;
418+
};
416419
Tween.prototype.to = function (target, duration) {
417420
if (duration === void 0) { duration = 1000; }
418421
if (this._isPlaying)
@@ -673,12 +676,13 @@ var Tween = /** @class */ (function () {
673676
* it is still playing, just paused).
674677
*/
675678
Tween.prototype.update = function (time, autoStart) {
679+
var _this = this;
680+
var _a;
676681
if (time === void 0) { time = now(); }
677682
if (autoStart === void 0) { autoStart = true; }
678683
if (this._isPaused)
679684
return true;
680685
var property;
681-
var elapsed;
682686
var endTime = this._startTime + this._duration;
683687
if (!this._goToEnd && !this._isPlaying) {
684688
if (time > endTime)
@@ -702,18 +706,37 @@ var Tween = /** @class */ (function () {
702706
}
703707
this._onEveryStartCallbackFired = true;
704708
}
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();
707729
var value = this._easingFunction(elapsed);
708730
// properties transformations
709731
this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
710732
if (this._onUpdateCallback) {
711733
this._onUpdateCallback(this._object, elapsed);
712734
}
713-
if (elapsed === 1) {
735+
if (this._duration === 0 || elapsedTime >= this._duration) {
714736
if (this._repeat > 0) {
737+
var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
715738
if (isFinite(this._repeat)) {
716-
this._repeat--;
739+
this._repeat -= completeCount;
717740
}
718741
// Reassign starting values, restart by making startTime = now
719742
for (property in this._valuesStartRepeat) {
@@ -731,12 +754,7 @@ var Tween = /** @class */ (function () {
731754
if (this._yoyo) {
732755
this._reversed = !this._reversed;
733756
}
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;
740758
if (this._onRepeatCallback) {
741759
this._onRepeatCallback(this._object);
742760
}
@@ -812,7 +830,7 @@ var Tween = /** @class */ (function () {
812830
return Tween;
813831
}());
814832

815-
var VERSION = '21.0.0';
833+
var VERSION = '23.1.0';
816834

817835
/**
818836
* Tween.js - Licensed under the MIT license

0 commit comments

Comments
 (0)