Skip to content

Commit

Permalink
v19.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
trusktr committed Apr 2, 2023
1 parent fee407c commit 351810c
Show file tree
Hide file tree
Showing 8 changed files with 441 additions and 282 deletions.
133 changes: 95 additions & 38 deletions dist/tween.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ define(['exports'], function (exports) { 'use strict';
/**
* The Ease class provides a collection of easing functions for use with tween.js.
*/
var Easing = {
Linear: {
var Easing = Object.freeze({
Linear: Object.freeze({
None: function (amount) {
return amount;
},
},
Quadratic: {
In: function (amount) {
return this.None(amount);
},
Out: function (amount) {
return this.None(amount);
},
InOut: function (amount) {
return this.None(amount);
},
}),
Quadratic: Object.freeze({
In: function (amount) {
return amount * amount;
},
Expand All @@ -22,8 +31,8 @@ define(['exports'], function (exports) { 'use strict';
}
return -0.5 * (--amount * (amount - 2) - 1);
},
},
Cubic: {
}),
Cubic: Object.freeze({
In: function (amount) {
return amount * amount * amount;
},
Expand All @@ -36,8 +45,8 @@ define(['exports'], function (exports) { 'use strict';
}
return 0.5 * ((amount -= 2) * amount * amount + 2);
},
},
Quartic: {
}),
Quartic: Object.freeze({
In: function (amount) {
return amount * amount * amount * amount;
},
Expand All @@ -50,8 +59,8 @@ define(['exports'], function (exports) { 'use strict';
}
return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
},
},
Quintic: {
}),
Quintic: Object.freeze({
In: function (amount) {
return amount * amount * amount * amount * amount;
},
Expand All @@ -64,19 +73,19 @@ define(['exports'], function (exports) { 'use strict';
}
return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
},
},
Sinusoidal: {
}),
Sinusoidal: Object.freeze({
In: function (amount) {
return 1 - Math.cos((amount * Math.PI) / 2);
return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);
},
Out: function (amount) {
return Math.sin((amount * Math.PI) / 2);
},
InOut: function (amount) {
return 0.5 * (1 - Math.cos(Math.PI * amount));
return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
},
},
Exponential: {
}),
Exponential: Object.freeze({
In: function (amount) {
return amount === 0 ? 0 : Math.pow(1024, amount - 1);
},
Expand All @@ -95,8 +104,8 @@ define(['exports'], function (exports) { 'use strict';
}
return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
},
},
Circular: {
}),
Circular: Object.freeze({
In: function (amount) {
return 1 - Math.sqrt(1 - amount * amount);
},
Expand All @@ -109,8 +118,8 @@ define(['exports'], function (exports) { 'use strict';
}
return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
},
},
Elastic: {
}),
Elastic: Object.freeze({
In: function (amount) {
if (amount === 0) {
return 0;
Expand Down Expand Up @@ -142,15 +151,15 @@ define(['exports'], function (exports) { 'use strict';
}
return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
},
},
Back: {
}),
Back: Object.freeze({
In: function (amount) {
var s = 1.70158;
return amount * amount * ((s + 1) * amount - s);
return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
},
Out: function (amount) {
var s = 1.70158;
return --amount * amount * ((s + 1) * amount + s) + 1;
return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
},
InOut: function (amount) {
var s = 1.70158 * 1.525;
Expand All @@ -159,8 +168,8 @@ define(['exports'], function (exports) { 'use strict';
}
return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
},
},
Bounce: {
}),
Bounce: Object.freeze({
In: function (amount) {
return 1 - Easing.Bounce.Out(1 - amount);
},
Expand All @@ -184,8 +193,27 @@ define(['exports'], function (exports) { 'use strict';
}
return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
},
}),
generatePow: function (power) {
if (power === void 0) { power = 4; }
power = power < Number.EPSILON ? Number.EPSILON : power;
power = power > 10000 ? 10000 : power;
return {
In: function (amount) {
return Math.pow(amount, power);
},
Out: function (amount) {
return 1 - Math.pow((1 - amount), power);
},
InOut: function (amount) {
if (amount < 0.5) {
return Math.pow((amount * 2), power) / 2;
}
return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;
},
};
},
};
});

var now;
// Include a performance.now polyfill.
Expand Down Expand Up @@ -398,8 +426,10 @@ define(['exports'], function (exports) { 'use strict';
this._startTime = 0;
this._easingFunction = Easing.Linear.None;
this._interpolationFunction = Interpolation.Linear;
// eslint-disable-next-line
this._chainedTweens = [];
this._onStartCallbackFired = false;
this._onEveryStartCallbackFired = false;
this._id = Sequence.nextId();
this._isChainStopped = false;
this._goToEnd = false;
Expand All @@ -425,10 +455,13 @@ define(['exports'], function (exports) { 'use strict';
return this;
};
Tween.prototype.duration = function (d) {
if (d === void 0) { d = 1000; }
this._duration = d;
return this;
};
Tween.prototype.start = function (time) {
Tween.prototype.start = function (time, overrideStartingValues) {
if (time === void 0) { time = now$1(); }
if (overrideStartingValues === void 0) { overrideStartingValues = false; }
if (this._isPlaying) {
return this;
}
Expand All @@ -447,13 +480,17 @@ define(['exports'], function (exports) { 'use strict';
this._isPlaying = true;
this._isPaused = false;
this._onStartCallbackFired = false;
this._onEveryStartCallbackFired = false;
this._isChainStopped = false;
this._startTime = time !== undefined ? (typeof time === 'string' ? now$1() + parseFloat(time) : time) : now$1();
this._startTime = time;
this._startTime += this._delayTime;
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
return this;
};
Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat) {
Tween.prototype.startFromCurrentValues = function (time) {
return this.start(time, true);
};
Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
for (var property in _valuesEnd) {
var startValue = _object[property];
var startValueIsArray = Array.isArray(startValue);
Expand All @@ -473,7 +510,9 @@ define(['exports'], function (exports) { 'use strict';
// handle an array of relative values
endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
// Create a local copy of the Array with the start value at the front
_valuesEnd[property] = [startValue].concat(endValues);
if (_valuesStart[property] === undefined) {
_valuesEnd[property] = [startValue].concat(endValues);
}
}
// handle the deepness of the values
if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
Expand All @@ -487,11 +526,11 @@ define(['exports'], function (exports) { 'use strict';
_valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
// eslint-disable-next-line
// @ts-ignore FIXME?
this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property], overrideStartingValues);
}
else {
// Save the starting value, but only once.
if (typeof _valuesStart[property] === 'undefined') {
// Save the starting value, but only once unless override is requested.
if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
_valuesStart[property] = startValue;
}
if (!startValueIsArray) {
Expand Down Expand Up @@ -562,14 +601,17 @@ define(['exports'], function (exports) { 'use strict';
return this;
};
Tween.prototype.group = function (group) {
if (group === void 0) { group = mainGroup; }
this._group = group;
return this;
};
Tween.prototype.delay = function (amount) {
if (amount === void 0) { amount = 0; }
this._delayTime = amount;
return this;
};
Tween.prototype.repeat = function (times) {
if (times === void 0) { times = 0; }
this._initialRepeat = times;
this._repeat = times;
return this;
Expand All @@ -579,17 +621,21 @@ define(['exports'], function (exports) { 'use strict';
return this;
};
Tween.prototype.yoyo = function (yoyo) {
if (yoyo === void 0) { yoyo = false; }
this._yoyo = yoyo;
return this;
};
Tween.prototype.easing = function (easingFunction) {
if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
this._easingFunction = easingFunction;
return this;
};
Tween.prototype.interpolation = function (interpolationFunction) {
if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
this._interpolationFunction = interpolationFunction;
return this;
};
// eslint-disable-next-line
Tween.prototype.chain = function () {
var tweens = [];
for (var _i = 0; _i < arguments.length; _i++) {
Expand All @@ -602,6 +648,10 @@ define(['exports'], function (exports) { 'use strict';
this._onStartCallback = callback;
return this;
};
Tween.prototype.onEveryStart = function (callback) {
this._onEveryStartCallback = callback;
return this;
};
Tween.prototype.onUpdate = function (callback) {
this._onUpdateCallback = callback;
return this;
Expand Down Expand Up @@ -635,7 +685,7 @@ define(['exports'], function (exports) { 'use strict';
if (time > endTime)
return false;
if (autoStart)
this.start(time);
this.start(time, true);
}
this._goToEnd = false;
if (time < this._startTime) {
Expand All @@ -647,6 +697,12 @@ define(['exports'], function (exports) { 'use strict';
}
this._onStartCallbackFired = true;
}
if (this._onEveryStartCallbackFired === false) {
if (this._onEveryStartCallback) {
this._onEveryStartCallback(this._object);
}
this._onEveryStartCallbackFired = true;
}
elapsed = (time - this._startTime) / this._duration;
elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
var value = this._easingFunction(elapsed);
Expand Down Expand Up @@ -685,6 +741,7 @@ define(['exports'], function (exports) { 'use strict';
if (this._onRepeatCallback) {
this._onRepeatCallback(this._object);
}
this._onEveryStartCallbackFired = false;
return true;
}
else {
Expand All @@ -694,7 +751,7 @@ define(['exports'], function (exports) { 'use strict';
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
// Make the chained tweens start exactly at the time they should,
// even if the `update()` method was called way past the duration of the tween
this._chainedTweens[i].start(this._startTime + this._duration);
this._chainedTweens[i].start(this._startTime + this._duration, false);
}
this._isPlaying = false;
return false;
Expand Down Expand Up @@ -758,7 +815,7 @@ define(['exports'], function (exports) { 'use strict';
return Tween;
}());

var VERSION = '18.6.4';
var VERSION = '19.0.0';

/**
* Tween.js - Licensed under the MIT license
Expand Down
Loading

0 comments on commit 351810c

Please sign in to comment.