Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-tween

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-tween - npm Package Compare versions

Comparing version 3.7.1 to 3.8.0

full/Tween.js

1550

lite/Tween.js

@@ -10,11 +10,16 @@ (function (global, factory) {

if (!Array.isArray) {
Array.isArray = function (source) { return source && source.push && source.splice; };
}
var root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this;
var requestAnimationFrame = root.requestAnimationFrame || function (fn) { return root.setTimeout(fn, 16) };
var cancelAnimationFrame = root.cancelAnimationFrame || function (id) { return root.clearTimeout(id) };
var requestAnimationFrame = root.requestAnimationFrame || (function (fn) { return root.setTimeout(fn, 16); });
var cancelAnimationFrame = root.cancelAnimationFrame || (function (id) { return root.clearTimeout(id); });
/* global process */
/**
* Lightweight, effecient and modular ES6 version of tween.js
* @copyright 2017 @dalisoft and es6-tween contributors
* @license MIT
* @namespace TWEEN
* @example
* // ES6
* const {add, remove, isRunning, autoPlay} = TWEEN
*/
var _tweens = [];

@@ -26,831 +31,856 @@ var isStarted = false;

var _stopTicker = cancelAnimationFrame;
/**
* Adds tween to list
* @param {Tween} tween Tween instance
* @memberof TWEEN
* @example
* let tween = new Tween({x:0})
* tween.to({x:200}, 1000)
* TWEEN.add(tween)
*/
var add = function (tween) {
_tweens.push(tween);
if (_autoPlay && !isStarted) {
_tick = _ticker(update);
isStarted = true;
}
_tweens.push(tween);
if (_autoPlay && !isStarted) {
_tick = _ticker(update);
isStarted = true;
}
};
/**
* @returns {Array<Tween>} List of tweens in Array
* @memberof TWEEN
* TWEEN.getAll() // list of tweens
*/
var getAll = function () { return _tweens; };
/**
* Runs update loop automaticlly
* @param {Boolean} state State of auto-run of update loop
* @example TWEEN.autoPlay(true)
* @memberof TWEEN
*/
var autoPlay = function (state) {
_autoPlay = state;
_autoPlay = state;
};
/**
* Removes all tweens from list
* @example TWEEN.removeAll() // removes all tweens, stored in global tweens list
* @memberof TWEEN
*/
var removeAll = function () {
_tweens.length = 0;
_tweens.length = 0;
};
/**
* @param {Tween} tween Tween Instance to be matched
* @return {Tween} Matched tween
* @memberof TWEEN
* @example
* TWEEN.get(tween)
*/
var get = function (tween) {
for (var i = 0; i < _tweens.length; i++) {
if (tween === _tweens[i]) {
return _tweens[i]
for (var i = 0; i < _tweens.length; i++) {
if (tween === _tweens[i]) {
return _tweens[i];
}
}
}
return null
return null;
};
/**
* @param {Tween} tween Tween Instance to be matched
* @return {Boolean} Status of Exists tween or not
* @memberof TWEEN
* @example
* TWEEN.has(tween)
*/
var has = function (tween) {
return get(tween) !== null
return get(tween) !== null;
};
/**
* Removes tween from list
* @param {Tween} tween Tween instance
* @memberof TWEEN
* @example
* TWEEN.remove(tween)
*/
var remove = function (tween) {
var i = _tweens.indexOf(tween);
if (i !== -1) {
_tweens.splice(i, 1);
}
var i = _tweens.indexOf(tween);
if (i !== -1) {
_tweens.splice(i, 1);
}
};
var now = (function () {
if (typeof (process) !== 'undefined' && process.hrtime !== undefined) {
return function () {
var time = process.hrtime();
// Convert [seconds, nanoseconds] to milliseconds.
return time[0] * 1000 + time[1] / 1000000
if (typeof (process) !== 'undefined' && process.hrtime !== undefined) {
return function () {
var time = process.hrtime();
// Convert [seconds, nanoseconds] to milliseconds.
return time[0] * 1000 + time[1] / 1000000;
};
// In a browser, use window.performance.now if it is available.
}
// In a browser, use window.performance.now if it is available.
} else if (root.performance !== undefined &&
root.performance.now !== undefined) {
// This must be bound, because directly assigning this function
// leads to an invocation exception in Chrome.
return root.performance.now.bind(root.performance)
// Use Date.now if it is available.
} else {
var offset = root.performance && root.performance.timing && root.performance.timing.navigationStart ? root.performance.timing.navigationStart : Date.now();
return function () {
return Date.now() - offset
else if (root.performance !== undefined &&
root.performance.now !== undefined) {
// This must be bound, because directly assigning this function
// leads to an invocation exception in Chrome.
return root.performance.now.bind(root.performance);
// Use Date.now if it is available.
}
}
else {
var offset = root.performance && root.performance.timing && root.performance.timing.navigationStart ? root.performance.timing.navigationStart : Date.now();
return function () {
return Date.now() - offset;
};
}
}());
/**
* Updates global tweens by given time
* @param {number|Time} time Timestamp
* @param {Boolean=} preserve Prevents tween to be removed after finish
* @memberof TWEEN
* @example
* TWEEN.update(500)
*/
var update = function (time, preserve) {
time = time !== undefined ? time : now();
_tick = _ticker(update);
if (_tweens.length === 0) {
_stopTicker(_tick);
isStarted = false;
return false
}
var i = 0;
while (i < _tweens.length) {
_tweens[i].update(time, preserve);
i++;
}
return true
time = time !== undefined ? time : now();
_tick = _ticker(update);
if (_tweens.length === 0) {
_stopTicker(_tick);
isStarted = false;
return false;
}
var i = 0;
while (i < _tweens.length) {
_tweens[i].update(time, preserve);
i++;
}
return true;
};
/**
* The state of ticker running
* @return {Boolean} Status of running updates on all tweens
* @memberof TWEEN
* @example TWEEN.isRunning()
*/
var isRunning = function () { return isStarted; };
/**
* The plugins store object
* @namespace TWEEN.Plugins
* @memberof TWEEN
* @example
* let num = Plugins.num = function (node, start, end) {
* return t => start + (end - start) * t
* }
*
* @static
*/
var Plugins = {};
// Normalise time when visiblity is changed (if available) ...
if (root.document && root.document.addEventListener) {
var doc = root.document;
var timeDiff = 0;
var timePause = 0;
doc.addEventListener('visibilitychange', function () {
if (document.hidden) {
timePause = now();
_stopTicker(_tick);
isStarted = false;
} else {
timeDiff = now() - timePause;
for (var i = 0, length = _tweens.length; i < length; i++) {
_tweens[i]._startTime += timeDiff;
}
_tick = _ticker(update);
isStarted = true;
}
return true
});
var doc = root.document;
var timeDiff = 0;
var timePause = 0;
doc.addEventListener('visibilitychange', function () {
if (document.hidden) {
timePause = now();
_stopTicker(_tick);
isStarted = false;
}
else {
timeDiff = now() - timePause;
for (var i = 0, length = _tweens.length; i < length; i++) {
_tweens[i]._startTime += timeDiff;
}
_tick = _ticker(update);
isStarted = true;
}
return true;
});
}
/**
* List of full easings
* @namespace TWEEN.Easing
* @example
* import {Tween, Easing} from 'es6-tween'
*
* // then set via new Tween({x:0}).to({x:100}, 1000).easing(Easing.Quadratic.InOut).start()
*/
var Easing = {
Linear: {
None: function None (k) {
return k
}
},
Quadratic: {
In: function In (k) {
return k * k
Linear: {
None: function None(k) {
return k;
}
},
Out: function Out (k) {
return k * (2 - k)
Quadratic: {
In: function In(k) {
return k * k;
},
Out: function Out(k) {
return k * (2 - k);
},
InOut: function InOut(k) {
if ((k *= 2) < 1) {
return 0.5 * k * k;
}
return -0.5 * (--k * (k - 2) - 1);
}
},
InOut: function InOut (k) {
if ((k *= 2) < 1) {
return 0.5 * k * k
}
return -0.5 * (--k * (k - 2) - 1)
}
},
Cubic: {
In: function In (k) {
return k * k * k
Cubic: {
In: function In(k) {
return k * k * k;
},
Out: function Out(k) {
return --k * k * k + 1;
},
InOut: function InOut(k) {
if ((k *= 2) < 1) {
return 0.5 * k * k * k;
}
return 0.5 * ((k -= 2) * k * k + 2);
}
},
Out: function Out (k) {
return --k * k * k + 1
Quartic: {
In: function In(k) {
return k * k * k * k;
},
Out: function Out(k) {
return 1 - (--k * k * k * k);
},
InOut: function InOut(k) {
if ((k *= 2) < 1) {
return 0.5 * k * k * k * k;
}
return -0.5 * ((k -= 2) * k * k * k - 2);
}
},
InOut: function InOut (k) {
if ((k *= 2) < 1) {
return 0.5 * k * k * k
}
return 0.5 * ((k -= 2) * k * k + 2)
}
},
Quartic: {
In: function In (k) {
return k * k * k * k
Quintic: {
In: function In(k) {
return k * k * k * k * k;
},
Out: function Out(k) {
return --k * k * k * k * k + 1;
},
InOut: function InOut(k) {
if ((k *= 2) < 1) {
return 0.5 * k * k * k * k * k;
}
return 0.5 * ((k -= 2) * k * k * k * k + 2);
}
},
Out: function Out (k) {
return 1 - (--k * k * k * k)
Sinusoidal: {
In: function In(k) {
return 1 - Math.cos(k * Math.PI / 2);
},
Out: function Out(k) {
return Math.sin(k * Math.PI / 2);
},
InOut: function InOut(k) {
return 0.5 * (1 - Math.cos(Math.PI * k));
}
},
InOut: function InOut (k) {
if ((k *= 2) < 1) {
return 0.5 * k * k * k * k
}
return -0.5 * ((k -= 2) * k * k * k - 2)
}
},
Quintic: {
In: function In (k) {
return k * k * k * k * k
Exponential: {
In: function In(k) {
return k === 0 ? 0 : Math.pow(1024, k - 1);
},
Out: function Out(k) {
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
},
InOut: function InOut(k) {
if (k === 0) {
return 0;
}
if (k === 1) {
return 1;
}
if ((k *= 2) < 1) {
return 0.5 * Math.pow(1024, k - 1);
}
return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
}
},
Out: function Out (k) {
return --k * k * k * k * k + 1
Circular: {
In: function In(k) {
return 1 - Math.sqrt(1 - k * k);
},
Out: function Out(k) {
return Math.sqrt(1 - (--k * k));
},
InOut: function InOut(k) {
if ((k *= 2) < 1) {
return -0.5 * (Math.sqrt(1 - k * k) - 1);
}
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
}
},
InOut: function InOut (k) {
if ((k *= 2) < 1) {
return 0.5 * k * k * k * k * k
}
return 0.5 * ((k -= 2) * k * k * k * k + 2)
}
},
Sinusoidal: {
In: function In (k) {
return 1 - Math.cos(k * Math.PI / 2)
Elastic: {
In: function In(k) {
if (k === 0) {
return 0;
}
if (k === 1) {
return 1;
}
return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
},
Out: function Out(k) {
if (k === 0) {
return 0;
}
if (k === 1) {
return 1;
}
return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1;
},
InOut: function InOut(k) {
if (k === 0) {
return 0;
}
if (k === 1) {
return 1;
}
k *= 2;
if (k < 1) {
return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
}
return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1;
}
},
Out: function Out (k) {
return Math.sin(k * Math.PI / 2)
Back: {
In: function In(k) {
var s = 1.70158;
return k * k * ((s + 1) * k - s);
},
Out: function Out(k) {
var s = 1.70158;
return --k * k * ((s + 1) * k + s) + 1;
},
InOut: function InOut(k) {
var s = 1.70158 * 1.525;
if ((k *= 2) < 1) {
return 0.5 * (k * k * ((s + 1) * k - s));
}
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
}
},
InOut: function InOut (k) {
return 0.5 * (1 - Math.cos(Math.PI * k))
Bounce: {
In: function In(k) {
return 1 - Easing.Bounce.Out(1 - k);
},
Out: function Out(k) {
if (k < (1 / 2.75)) {
return 7.5625 * k * k;
}
else if (k < (2 / 2.75)) {
return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
}
else if (k < (2.5 / 2.75)) {
return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
}
else {
return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
}
},
InOut: function InOut(k) {
if (k < 0.5) {
return Easing.Bounce.In(k * 2) * 0.5;
}
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
}
}
},
Exponential: {
In: function In (k) {
return k === 0 ? 0 : Math.pow(1024, k - 1)
},
Out: function Out (k) {
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k)
},
InOut: function InOut (k) {
if (k === 0) {
return 0
}
if (k === 1) {
return 1
}
if ((k *= 2) < 1) {
return 0.5 * Math.pow(1024, k - 1)
}
return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2)
}
},
Circular: {
In: function In (k) {
return 1 - Math.sqrt(1 - k * k)
},
Out: function Out (k) {
return Math.sqrt(1 - (--k * k))
},
InOut: function InOut (k) {
if ((k *= 2) < 1) {
return -0.5 * (Math.sqrt(1 - k * k) - 1)
}
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1)
}
},
Elastic: {
In: function In (k) {
if (k === 0) {
return 0
}
if (k === 1) {
return 1
}
return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI)
},
Out: function Out (k) {
if (k === 0) {
return 0
}
if (k === 1) {
return 1
}
return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1
},
InOut: function InOut (k) {
if (k === 0) {
return 0
}
if (k === 1) {
return 1
}
k *= 2;
if (k < 1) {
return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI)
}
return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1
}
},
Back: {
In: function In (k) {
var s = 1.70158;
return k * k * ((s + 1) * k - s)
},
Out: function Out (k) {
var s = 1.70158;
return --k * k * ((s + 1) * k + s) + 1
},
InOut: function InOut (k) {
var s = 1.70158 * 1.525;
if ((k *= 2) < 1) {
return 0.5 * (k * k * ((s + 1) * k - s))
}
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2)
}
},
Bounce: {
In: function In (k) {
return 1 - Easing.Bounce.Out(1 - k)
},
Out: function Out (k) {
if (k < (1 / 2.75)) {
return 7.5625 * k * k
} else if (k < (2 / 2.75)) {
return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75
} else if (k < (2.5 / 2.75)) {
return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375
} else {
return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375
}
},
InOut: function InOut (k) {
if (k < 0.5) {
return Easing.Bounce.In(k * 2) * 0.5
}
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5
}
}
};
/**
* List of full Interpolation
* @namespace TWEEN.Interpolation
* @example
* import {Interpolation, Tween} from 'es6-tween'
*
* let bezier = Interpolation.Bezier
* new Tween({x:0}).to({x:[0, 4, 8, 12, 15, 20, 30, 40, 20, 40, 10, 50]}, 1000).interpolation(bezier).start()
* @memberof TWEEN
*/
var Interpolation = {
Linear: function Linear (v, k) {
var m = v.length - 1;
var f = m * k;
var i = Math.floor(f);
var fn = Interpolation.Utils.Linear;
if (k < 0) {
return fn(v[0], v[1], f)
}
if (k > 1) {
return fn(v[m], v[m - 1], m - f)
}
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i)
},
Bezier: function Bezier (v, k) {
var b = 0;
var n = v.length - 1;
var pw = Math.pow;
var bn = Interpolation.Utils.Bernstein;
for (var i = 0; i <= n; i++) {
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
}
return b
},
CatmullRom: function CatmullRom (v, k) {
var m = v.length - 1;
var f = m * k;
var i = Math.floor(f);
var fn = Interpolation.Utils.CatmullRom;
if (v[0] === v[m]) {
if (k < 0) {
i = Math.floor(f = m * (1 + k));
}
return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i)
} else {
if (k < 0) {
return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0])
}
if (k > 1) {
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m])
}
return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i)
}
},
Utils: {
Linear: function Linear (p0, p1, t) {
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0
Linear: function Linear(v, k) {
var m = v.length - 1;
var f = m * k;
var i = Math.floor(f);
var fn = Interpolation.Utils.Linear;
if (k < 0) {
return fn(v[0], v[1], f);
}
if (k > 1) {
return fn(v[m], v[m - 1], m - f);
}
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
},
Bernstein: function Bernstein (n, i) {
var fc = Interpolation.Utils.Factorial;
return fc(n) / fc(i) / fc(n - i)
Bezier: function Bezier(v, k) {
var b = 0;
var n = v.length - 1;
var pw = Math.pow;
var bn = Interpolation.Utils.Bernstein;
for (var i = 0; i <= n; i++) {
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
}
return b;
},
Factorial: (function () {
var a = [1];
return function (n) {
var s = 1;
if (a[n]) {
return a[n]
CatmullRom: function CatmullRom(v, k) {
var m = v.length - 1;
var f = m * k;
var i = Math.floor(f);
var fn = Interpolation.Utils.CatmullRom;
if (v[0] === v[m]) {
if (k < 0) {
i = Math.floor(f = m * (1 + k));
}
return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
}
for (var i = n; i > 1; i--) {
s *= i;
else {
if (k < 0) {
return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
}
if (k > 1) {
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
}
return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
}
a[n] = s;
return s
}
})(),
CatmullRom: function CatmullRom (p0, p1, p2, p3, t) {
var v0 = (p2 - p0) * 0.5;
var v1 = (p3 - p1) * 0.5;
var t2 = t * t;
var t3 = t * t2;
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1
},
Utils: {
Linear: function Linear(p0, p1, t) {
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0;
},
Bernstein: function Bernstein(n, i) {
var fc = Interpolation.Utils.Factorial;
return fc(n) / fc(i) / fc(n - i);
},
Factorial: (function () {
var a = [1];
return function (n) {
var s = 1;
if (a[n]) {
return a[n];
}
for (var i = n; i > 1; i--) {
s *= i;
}
a[n] = s;
return s;
};
})(),
CatmullRom: function CatmullRom(p0, p1, p2, p3, t) {
var v0 = (p2 - p0) * 0.5;
var v1 = (p3 - p1) * 0.5;
var t2 = t * t;
var t3 = t * t2;
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
}
}
}
};
var _id = 0; // Unique ID
var Tween = function Tween (object) {
this.id = _id++;
this.object = object;
this._valuesStart = {};
this._valuesEnd = null;
this._valuesStartRepeat = {};
this._duration = 1000;
this._easingFunction = Easing.Linear.None;
this._interpolationFunction = Interpolation.Linear;
this._startTime = 0;
this._delayTime = 0;
this._repeat = 0;
this._r = 0;
this._isPlaying = false;
this._yoyo = false;
this._reversed = false;
this._onStartCallbackFired = false;
this._pausedTime = null;
this._isFinite = true;
/* Callbacks */
this._onStartCallback = null;
this._onUpdateCallback = null;
this._onCompleteCallback = null;
return this
/**
* Tween Lite main constructor
* @constructor
* @param {object} object initial object
* @example
* import {Tween} from 'es6-tween/src/Tween.Lite'
*
* let tween = new Tween({x:0}).to({x:100}, 2000).start()
*/
var Lite = function Lite(object) {
this.id = _id++;
this.object = object;
this._valuesStart = {};
this._valuesEnd = null;
this._valuesStartRepeat = {};
this._duration = 1000;
this._easingFunction = Easing.Linear.None;
this._interpolationFunction = Interpolation.Linear;
this._startTime = 0;
this._delayTime = 0;
this._repeat = 0;
this._r = 0;
this._isPlaying = false;
this._yoyo = false;
this._reversed = false;
this._onStartCallbackFired = false;
this._pausedTime = null;
this._isFinite = true;
/* Callbacks */
this._onStartCallback = null;
this._onUpdateCallback = null;
this._onCompleteCallback = null;
return this;
};
Tween.prototype.onStart = function onStart (callback) {
this._onStartCallback = callback;
return this
/**
* onStart callback
* @param {Function} callback Function should be fired after tween is started
* @example tween.onStart(object => console.log(object))
* @memberof Lite
*/
Lite.prototype.onStart = function onStart (callback) {
this._onStartCallback = callback;
return this;
};
Tween.prototype.onUpdate = function onUpdate (callback) {
this._onUpdateCallback = callback;
return this
/**
* onUpdate callback
* @param {Function} callback Function should be fired while tween is in progress
* @example tween.onUpdate(object => console.log(object))
* @memberof Lite
*/
Lite.prototype.onUpdate = function onUpdate (callback) {
this._onUpdateCallback = callback;
return this;
};
Tween.prototype.onComplete = function onComplete (callback) {
this._onCompleteCallback = callback;
return this
/**
* onComplete callback
* @param {Function} callback Function should be fired after tween is finished
* @example tween.onComplete(object => console.log(object))
* @memberof Lite
*/
Lite.prototype.onComplete = function onComplete (callback) {
this._onCompleteCallback = callback;
return this;
};
Tween.prototype.isPlaying = function isPlaying () {
return this._isPlaying
/**
* @return {boolean} State of playing of tween
* @example tween.isPlaying() // returns `true` if tween in progress
* @memberof Lite
*/
Lite.prototype.isPlaying = function isPlaying () {
return this._isPlaying;
};
Tween.prototype.isStarted = function isStarted () {
return this._onStartCallbackFired
/**
* @return {boolean} State of started of tween
* @example tween.isStarted() // returns `true` if tween in started
* @memberof Lite
*/
Lite.prototype.isStarted = function isStarted () {
return this._onStartCallbackFired;
};
Tween.prototype.pause = function pause () {
if (!this._isPlaying) {
return this
}
this._isPlaying = false;
remove(this);
this._pausedTime = now();
return this
/**
* Pauses tween
* @example tween.pause()
* @memberof Lite
*/
Lite.prototype.pause = function pause () {
if (!this._isPlaying) {
return this;
}
this._isPlaying = false;
remove(this);
this._pausedTime = now();
return this;
};
Tween.prototype.play = function play () {
if (this._isPlaying) {
return this
}
this._isPlaying = true;
this._startTime += now() - this._pausedTime;
add(this);
this._pausedTime = now();
return this
/**
* Play/Resume the tween
* @example tween.play()
* @memberof Lite
*/
Lite.prototype.play = function play () {
if (this._isPlaying) {
return this;
}
this._isPlaying = true;
this._startTime += now() - this._pausedTime;
add(this);
this._pausedTime = now();
return this;
};
Tween.prototype.duration = function duration (amount) {
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount;
return this
/**
* Sets tween duration
* @param {number} amount Duration is milliseconds
* @example tween.duration(2000)
* @memberof Lite
*/
Lite.prototype.duration = function duration (amount) {
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount;
return this;
};
/**
* Sets target value and duration
* @param {object} properties Target value (to value)
* @param {number} [duration=1000] Duration of tween
* @example new Tween({x:0}).to({x:200}, 2000)
* @memberof Lite
*/
Lite.prototype.to = function to (properties, duration) {
if ( duration === void 0 ) duration = 1000;
Tween.prototype.to = function to (properties, duration) {
if ( duration === void 0 ) duration = 1000;
this._valuesEnd = properties;
this._duration = duration;
return this
this._valuesEnd = properties;
this._duration = duration;
return this;
};
Tween.prototype.start = function start (time) {
this._startTime = time !== undefined ? time : now();
this._startTime += this._delayTime;
var ref = this;
var _valuesEnd = ref._valuesEnd;
var _valuesStartRepeat = ref._valuesStartRepeat;
var _valuesStart = ref._valuesStart;
var _interpolationFunction = ref._interpolationFunction;
var object = ref.object;
var loop = function ( property ) {
var start = object[property];
var end = _valuesEnd[property];
if (!object || object[property] === undefined) {
return
}
var obj = object[property];
if (typeof start === 'number') {
if (typeof end === 'string') {
_valuesStartRepeat[property] = end;
end = start + parseFloat(end);
} else if (Array.isArray(end)) {
end.unshift(start);
var _endArr = end;
end = function (t) {
return _interpolationFunction(_endArr, t)
};
}
} else if (typeof end === 'object') {
if (Array.isArray(end)) {
var _endArr$1 = end;
var _start = start.map(function (item) { return item; });
var i = (void 0);
var len = end.length;
end = function (t) {
i = 0;
for (; i < len; i++) {
obj[i] = typeof _start[i] === 'number' ? _start[i] + (_endArr$1[i] - _start[i]) * t : _endArr$1[i];
}
return obj
};
} else {
var _endObj = end;
var _start$1 = {};
for (var p in start) {
_start$1[p] = start[p];
/**
* Start the tweening
* @param {number} time setting manual time instead of Current browser timestamp
* @example tween.start()
* @memberof Lite
*/
Lite.prototype.start = function start (time) {
this._startTime = time !== undefined ? time : now();
this._startTime += this._delayTime;
var ref = this;
var _valuesEnd = ref._valuesEnd;
var _valuesStartRepeat = ref._valuesStartRepeat;
var _valuesStart = ref._valuesStart;
var _interpolationFunction = ref._interpolationFunction;
var object = ref.object;
var loop = function ( property ) {
var start = object[property];
var end = _valuesEnd[property];
if (!object || object[property] === undefined) {
return;
}
end = function (t) {
for (var i in end) {
obj[i] = typeof _start$1[i] === 'number' ? _start$1[i] + (_endObj[i] - _start$1[i]) * t : _endObj[i];
}
return obj
};
}
}
var obj = object[property];
if (typeof start === 'number') {
if (typeof end === 'string') {
_valuesStartRepeat[property] = end;
end = start + parseFloat(end);
}
else if (Array.isArray(end)) {
end.unshift(start);
var _endArr = end;
end = function (t) {
return _interpolationFunction(_endArr, t);
};
}
}
else if (typeof end === 'object') {
if (Array.isArray(end)) {
var _endArr$1 = end;
var _start = start.map(function (item) { return item; });
var i = (void 0);
var len = end.length;
end = function (t) {
i = 0;
for (; i < len; i++) {
obj[i] = typeof _start[i] === 'number' ? _start[i] + (_endArr$1[i] - _start[i]) * t : _endArr$1[i];
}
return obj;
};
}
else {
var _endObj = end;
var _start$1 = {};
for (var p in start) {
_start$1[p] = start[p];
}
end = function (t) {
for (var i in end) {
obj[i] = typeof _start$1[i] === 'number' ? _start$1[i] + (_endObj[i] - _start$1[i]) * t : _endObj[i];
}
return obj;
};
}
}
_valuesStart[property] = start;
_valuesEnd[property] = end;
};
_valuesStart[property] = start;
_valuesEnd[property] = end;
};
for (var property in _valuesEnd) loop( property );
add(this);
this._isPlaying = true;
return this
for (var property in _valuesEnd) loop( property );
add(this);
this._isPlaying = true;
return this;
};
Tween.prototype.stop = function stop () {
var ref = this;
var _isPlaying = ref._isPlaying;
var _startTime = ref._startTime;
var _duration = ref._duration;
if (!_isPlaying) {
return this
}
this.update(_startTime + _duration);
remove(this);
this._isPlaying = false;
return this
/**
* Stops the tween
* @example tween.stop()
* @memberof Lite
*/
Lite.prototype.stop = function stop () {
var ref = this;
var _isPlaying = ref._isPlaying;
var _startTime = ref._startTime;
var _duration = ref._duration;
if (!_isPlaying) {
return this;
}
this.update(_startTime + _duration);
remove(this);
this._isPlaying = false;
return this;
};
Tween.prototype.delay = function delay (amount) {
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount;
return this
/**
* Set delay of tween
* @param {number} amount Sets tween delay / wait duration
* @example tween.delay(500)
* @memberof Lite
*/
Lite.prototype.delay = function delay (amount) {
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount;
return this;
};
Tween.prototype.repeat = function repeat (amount) {
this._repeat = typeof (amount) === 'function' ? amount(this._repeat) : amount;
this._r = this._repeat;
this._isFinite = isFinite(amount);
return this
/**
* Sets how times tween is repeating
* @param {amount} amount the times of repeat
* @example tween.repeat(2)
* @memberof Lite
*/
Lite.prototype.repeat = function repeat (amount) {
this._repeat = typeof (amount) === 'function' ? amount(this._repeat) : amount;
this._r = this._repeat;
this._isFinite = isFinite(amount);
return this;
};
Tween.prototype.repeatDelay = function repeatDelay (amount) {
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount;
return this
/**
* Set delay of each repeat of tween
* @param {number} amount Sets tween repeat delay / repeat wait duration
* @example tween.repeatDelay(500)
* @memberof Lite
*/
Lite.prototype.repeatDelay = function repeatDelay (amount) {
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount;
return this;
};
Tween.prototype.reverseDelay = function reverseDelay (amount) {
this._reverseDelayTime = typeof (amount) === 'function' ? amount(this._reverseDelayTime) : amount;
return this
/**
* Set delay of each repeat alternate of tween
* @param {number} amount Sets tween repeat alternate delay / repeat alternate wait duration
* @example tween.reverseDelay(500)
* @memberof Lite
*/
Lite.prototype.reverseDelay = function reverseDelay (amount) {
this._reverseDelayTime = typeof (amount) === 'function' ? amount(this._reverseDelayTime) : amount;
return this;
};
Tween.prototype.yoyo = function yoyo (state) {
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state;
return this
/**
* Set `yoyo` state (enables reverse in repeat)
* @param {boolean} state Enables alternate direction for repeat
* @example tween.yoyo(true)
* @memberof Lite
*/
Lite.prototype.yoyo = function yoyo (state) {
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state;
return this;
};
Tween.prototype.easing = function easing (fn) {
if (typeof fn === 'function') {
this._easingFunction = fn;
}
return this
/**
* Set easing
* @param {Function} _easingFunction Easing function
* @example tween.easing(Easing.Quadratic.InOut)
* @memberof Lite
*/
Lite.prototype.easing = function easing (fn) {
if (typeof fn === 'function') {
this._easingFunction = fn;
}
return this;
};
Tween.prototype.interpolation = function interpolation (fn) {
if (typeof fn === 'function') {
this._interpolationFunction = fn;
}
return this
/**
* Set interpolation
* @param {Function} _interpolationFunction Interpolation function
* @example tween.interpolation(Interpolation.Bezier)
* @memberof Lite
*/
Lite.prototype.interpolation = function interpolation (_interpolationFunction) {
if (typeof _interpolationFunction === 'function') {
this._interpolationFunction = _interpolationFunction;
}
return this;
};
Tween.prototype.reassignValues = function reassignValues () {
var ref = this;
var _valuesStart = ref._valuesStart;
var _valuesEnd = ref._valuesEnd;
var object = ref.object;
for (var property in _valuesEnd) {
var start = _valuesStart[property];
object[property] = start;
}
return this
Lite.prototype.reassignValues = function reassignValues () {
var ref = this;
var _valuesStart = ref._valuesStart;
var _valuesEnd = ref._valuesEnd;
var object = ref.object;
for (var property in _valuesEnd) {
var start = _valuesStart[property];
object[property] = start;
}
return this;
};
Tween.prototype.update = function update$$1 (time, preserve) {
var ref = this;
var _onStartCallbackFired = ref._onStartCallbackFired;
var _easingFunction = ref._easingFunction;
var _repeat = ref._repeat;
var _repeatDelayTime = ref._repeatDelayTime;
var _reverseDelayTime = ref._reverseDelayTime;
var _yoyo = ref._yoyo;
var _reversed = ref._reversed;
var _startTime = ref._startTime;
var _duration = ref._duration;
var _valuesStart = ref._valuesStart;
var _valuesEnd = ref._valuesEnd;
var _valuesStartRepeat = ref._valuesStartRepeat;
var object = ref.object;
var _isFinite = ref._isFinite;
var _isPlaying = ref._isPlaying;
var _onStartCallback = ref._onStartCallback;
var _onUpdateCallback = ref._onUpdateCallback;
var _onCompleteCallback = ref._onCompleteCallback;
var elapsed;
var value;
var property;
time = time !== undefined ? time : now();
if (!_isPlaying || time < _startTime) {
return true
}
if (!_onStartCallbackFired) {
if (_onStartCallback) {
_onStartCallback(object);
/**
* Updates initial object to target value by given `time`
* @param {Time} time Current time
* @param {boolean=} preserve Prevents from removing tween from store
* @example tween.update(500)
* @memberof Lite
*/
Lite.prototype.update = function update$$1 (time, preserve) {
var ref = this;
var _onStartCallbackFired = ref._onStartCallbackFired;
var _easingFunction = ref._easingFunction;
var _repeat = ref._repeat;
var _repeatDelayTime = ref._repeatDelayTime;
var _reverseDelayTime = ref._reverseDelayTime;
var _yoyo = ref._yoyo;
var _reversed = ref._reversed;
var _startTime = ref._startTime;
var _duration = ref._duration;
var _valuesStart = ref._valuesStart;
var _valuesEnd = ref._valuesEnd;
var _valuesStartRepeat = ref._valuesStartRepeat;
var object = ref.object;
var _isFinite = ref._isFinite;
var _isPlaying = ref._isPlaying;
var _onStartCallback = ref._onStartCallback;
var _onUpdateCallback = ref._onUpdateCallback;
var _onCompleteCallback = ref._onCompleteCallback;
var elapsed;
var value;
var property;
time = time !== undefined ? time : now();
if (!_isPlaying || time < _startTime) {
return true;
}
this._onStartCallbackFired = true;
}
elapsed = (time - _startTime) / _duration;
elapsed = elapsed > 1 ? 1 : elapsed;
elapsed = _reversed ? 1 - elapsed : elapsed;
value = _easingFunction(elapsed);
for (property in _valuesEnd) {
var start = _valuesStart[property];
var end = _valuesEnd[property];
if (start === undefined) {
continue
} else if (typeof end === 'function') {
object[property] = end(value);
} else if (typeof end === 'number') {
object[property] = start + (end - start) * value;
if (!_onStartCallbackFired) {
if (_onStartCallback) {
_onStartCallback(object);
}
this._onStartCallbackFired = true;
}
}
if (_onUpdateCallback) {
_onUpdateCallback(object, elapsed);
}
if (elapsed === 1 || (_reversed && elapsed === 0)) {
if (_repeat) {
if (_isFinite) {
this._repeat--;
}
if (!_reversed) {
for (property in _valuesStartRepeat) {
_valuesStart[property] = _valuesEnd[property];
_valuesEnd[property] += parseFloat(_valuesStartRepeat[property]);
elapsed = (time - _startTime) / _duration;
elapsed = elapsed > 1 ? 1 : elapsed;
elapsed = _reversed ? 1 - elapsed : elapsed;
value = _easingFunction(elapsed);
for (property in _valuesEnd) {
var start = _valuesStart[property];
var end = _valuesEnd[property];
if (start === undefined) {
continue;
}
}
if (_yoyo) {
this._reversed = !_reversed;
}
if (!_reversed && _repeatDelayTime) {
this._startTime = time + _repeatDelayTime;
} else if (_reversed && _reverseDelayTime) {
this._startTime = time + _reverseDelayTime;
} else {
this._startTime = time;
}
return true
} else {
if (!preserve) {
remove(this);
}
this._isPlaying = false;
if (_onCompleteCallback) {
_onCompleteCallback();
}
this._repeat = this._r;
_id--;
return false
else if (typeof end === 'function') {
object[property] = end(value);
}
else if (typeof end === 'number') {
object[property] = start + (end - start) * value;
}
}
}
return true
if (_onUpdateCallback) {
_onUpdateCallback(object, elapsed);
}
if (elapsed === 1 || (_reversed && elapsed === 0)) {
if (_repeat) {
if (_isFinite) {
this._repeat--;
}
if (!_reversed) {
for (property in _valuesStartRepeat) {
_valuesStart[property] = _valuesEnd[property];
_valuesEnd[property] += parseFloat(_valuesStartRepeat[property]);
}
}
if (_yoyo) {
this._reversed = !_reversed;
}
if (!_reversed && _repeatDelayTime) {
this._startTime = time + _repeatDelayTime;
}
else if (_reversed && _reverseDelayTime) {
this._startTime = time + _reverseDelayTime;
}
else {
this._startTime = time;
}
return true;
}
else {
if (!preserve) {
remove(this);
}
this._isPlaying = false;
if (_onCompleteCallback) {
_onCompleteCallback();
}
this._repeat = this._r;
_id--;
return false;
}
}
return true;
};

@@ -869,3 +899,3 @@

exports.isRunning = isRunning;
exports.Tween = Tween;
exports.Tween = Lite;
exports.Easing = Easing;

@@ -872,0 +902,0 @@

@@ -1,3 +0,3 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.TWEEN={})}(this,function(t){"use strict";Array.isArray||(Array.isArray=function(t){return t&&t.push&&t.splice});var n,e="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,i=[],r=!1,o=!1,u=e.requestAnimationFrame||function(t){return e.setTimeout(t,16)},a=e.cancelAnimationFrame||function(t){return e.clearTimeout(t)},s=function(t){i.push(t),o&&!r&&(n=u(l),r=!0)},f=function(t){for(var n=0;n<i.length;n++)if(t===i[n])return i[n];return null},c=function(t){var n=i.indexOf(t);-1!==n&&i.splice(n,1)},h=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==e.performance&&void 0!==e.performance.now)return e.performance.now.bind(e.performance);var t=e.performance&&e.performance.timing&&e.performance.timing.navigationStart?e.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),l=function(t,e){if(t=void 0!==t?t:h(),n=u(l),0===i.length)return a(n),r=!1,!1;for(var o=0;o<i.length;)i[o].update(t,e),o++;return!0},p={};if(e.document&&e.document.addEventListener){var _=0,y=0;e.document.addEventListener("visibilitychange",function(){if(document.hidden)y=h(),a(n),r=!1;else{_=h()-y;for(var t=0,e=i.length;t<e;t++)i[t]._startTime+=_;n=u(l),r=!0}return!0})}var d={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var n=1.70158;return t*t*((n+1)*t-n)},Out:function(t){var n=1.70158;return--t*t*((n+1)*t+n)+1},InOut:function(t){var n=2.5949095;return(t*=2)<1?t*t*((n+1)*t-n)*.5:.5*((t-=2)*t*((n+1)*t+n)+2)}},Bounce:{In:function(t){return 1-d.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*d.Bounce.In(2*t):.5*d.Bounce.Out(2*t-1)+.5}}},v={Linear:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.Linear;return n<0?o(t[0],t[1],i):n>1?o(t[e],t[e-1],e-i):o(t[r],t[r+1>e?e:r+1],i-r)},Bezier:function(t,n){for(var e=0,i=t.length-1,r=Math.pow,o=v.Utils.Bernstein,u=0;u<=i;u++)e+=r(1-n,i-u)*r(n,u)*t[u]*o(i,u);return e},CatmullRom:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.CatmullRom;return t[0]===t[e]?(n<0&&(r=Math.floor(i=e*(1+n))),o(t[(r-1+e)%e],t[r],t[(r+1)%e],t[(r+2)%e],i-r)):n<0?t[0]-(o(t[0],t[0],t[1],t[1],-i)-t[0]):n>1?t[e]-(o(t[e],t[e],t[e-1],t[e-1],i-e)-t[e]):o(t[r?r-1:0],t[r],t[e<r+1?e:r+1],t[e<r+2?e:r+2],i-r)},Utils:{Linear:function(t,n,e){return"function"==typeof t?t(e):(n-t)*e+t},Bernstein:function(t,n){var e=v.Utils.Factorial;return e(t)/e(n)/e(t-n)},Factorial:function(){var t=[1];return function(n){var e=1;if(t[n])return t[n];for(var i=n;i>1;i--)e*=i;return t[n]=e,e}}(),CatmullRom:function(t,n,e,i,r){var o=.5*(e-t),u=.5*(i-n),a=r*r;return(2*n-2*e+o+u)*(r*a)+(-3*n+3*e-2*o-u)*a+o*r+n}}},m=0,g=function(t){return this.id=m++,this.object=t,this._valuesStart={},this._valuesEnd=null,this._valuesStartRepeat={},this._duration=1e3,this._easingFunction=d.Linear.None,this._interpolationFunction=v.Linear,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._pausedTime=null,this._isFinite=!0,this._onStartCallback=null,this._onUpdateCallback=null,this._onCompleteCallback=null,this};g.prototype.onStart=function(t){return this._onStartCallback=t,this},g.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},g.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},g.prototype.isPlaying=function(){return this._isPlaying},g.prototype.isStarted=function(){return this._onStartCallbackFired},g.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,c(this),this._pausedTime=h(),this):this},g.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=h()-this._pausedTime,s(this),this._pausedTime=h(),this)},g.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},g.prototype.to=function(t,n){return void 0===n&&(n=1e3),this._valuesEnd=t,this._duration=n,this},g.prototype.start=function(t){this._startTime=void 0!==t?t:h(),this._startTime+=this._delayTime;var n=this,e=n._valuesEnd,i=n._valuesStartRepeat,r=n._valuesStart,o=n._interpolationFunction,u=n.object;for(var a in e)!function(t){var n=u[t],a=e[t];if(u&&void 0!==u[t]){var s=u[t];if("number"==typeof n){if("string"==typeof a)i[t]=a,a=n+parseFloat(a);else if(Array.isArray(a)){a.unshift(n);var f=a;a=function(t){return o(f,t)}}}else if("object"==typeof a)if(Array.isArray(a)){var c=a,h=n.map(function(t){return t}),l=void 0,p=a.length;a=function(t){for(l=0;l<p;l++)s[l]="number"==typeof h[l]?h[l]+(c[l]-h[l])*t:c[l];return s}}else{var _=a,y={};for(var d in n)y[d]=n[d];a=function(t){for(var n in a)s[n]="number"==typeof y[n]?y[n]+(_[n]-y[n])*t:_[n];return s}}r[t]=n,e[t]=a}}(a);return s(this),this._isPlaying=!0,this},g.prototype.stop=function(){var t=this,n=t._isPlaying,e=t._startTime,i=t._duration;return n?(this.update(e+i),c(this),this._isPlaying=!1,this):this},g.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},g.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},g.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},g.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},g.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},g.prototype.easing=function(t){return"function"==typeof t&&(this._easingFunction=t),this},g.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},g.prototype.reassignValues=function(){var t=this,n=t._valuesStart,e=t._valuesEnd,i=t.object;for(var r in e){var o=n[r];i[r]=o}return this},g.prototype.update=function(t,n){var e,i,r,o=this,u=o._onStartCallbackFired,a=o._easingFunction,s=o._repeat,f=o._repeatDelayTime,l=o._reverseDelayTime,p=o._yoyo,_=o._reversed,y=o._startTime,d=o._duration,v=o._valuesStart,g=o._valuesEnd,M=o._valuesStartRepeat,b=o.object,I=o._isFinite,T=o._isPlaying,O=o._onStartCallback,C=o._onUpdateCallback,P=o._onCompleteCallback;if(t=void 0!==t?t:h(),!T||t<y)return!0;u||(O&&O(b),this._onStartCallbackFired=!0),e=(e=(t-y)/d)>1?1:e,i=a(e=_?1-e:e);for(r in g){var F=v[r],w=g[r];void 0!==F&&("function"==typeof w?b[r]=w(i):"number"==typeof w&&(b[r]=F+(w-F)*i))}if(C&&C(b,e),1===e||_&&0===e){if(s){if(I&&this._repeat--,!_)for(r in M)v[r]=g[r],g[r]+=parseFloat(M[r]);return p&&(this._reversed=!_),this._startTime=!_&&f?t+f:_&&l?t+l:t,!0}return n||c(this),this._isPlaying=!1,P&&P(),this._repeat=this._r,m--,!1}return!0},t.Plugins=p,t.has=function(t){return null!==f(t)},t.get=f,t.getAll=function(){return i},t.removeAll=function(){i.length=0},t.remove=c,t.add=s,t.now=h,t.update=l,t.autoPlay=function(t){o=t},t.isRunning=function(){return r},t.Tween=g,t.Easing=d,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.TWEEN={})}(this,function(t){"use strict";var n,e="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,i=[],r=!1,o=!1,u=e.requestAnimationFrame||function(t){return e.setTimeout(t,16)},a=e.cancelAnimationFrame||function(t){return e.clearTimeout(t)},s=function(t){i.push(t),o&&!r&&(n=u(l),r=!0)},f=function(t){for(var n=0;n<i.length;n++)if(t===i[n])return i[n];return null},c=function(t){var n=i.indexOf(t);-1!==n&&i.splice(n,1)},h=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==e.performance&&void 0!==e.performance.now)return e.performance.now.bind(e.performance);var t=e.performance&&e.performance.timing&&e.performance.timing.navigationStart?e.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),l=function(t,e){if(t=void 0!==t?t:h(),n=u(l),0===i.length)return a(n),r=!1,!1;for(var o=0;o<i.length;)i[o].update(t,e),o++;return!0},p={};if(e.document&&e.document.addEventListener){var _=0,y=0;e.document.addEventListener("visibilitychange",function(){if(document.hidden)y=h(),a(n),r=!1;else{_=h()-y;for(var t=0,e=i.length;t<e;t++)i[t]._startTime+=_;n=u(l),r=!0}return!0})}var d={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var n=1.70158;return t*t*((n+1)*t-n)},Out:function(t){var n=1.70158;return--t*t*((n+1)*t+n)+1},InOut:function(t){var n=2.5949095;return(t*=2)<1?t*t*((n+1)*t-n)*.5:.5*((t-=2)*t*((n+1)*t+n)+2)}},Bounce:{In:function(t){return 1-d.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*d.Bounce.In(2*t):.5*d.Bounce.Out(2*t-1)+.5}}},v={Linear:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.Linear;return n<0?o(t[0],t[1],i):n>1?o(t[e],t[e-1],e-i):o(t[r],t[r+1>e?e:r+1],i-r)},Bezier:function(t,n){for(var e=0,i=t.length-1,r=Math.pow,o=v.Utils.Bernstein,u=0;u<=i;u++)e+=r(1-n,i-u)*r(n,u)*t[u]*o(i,u);return e},CatmullRom:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.CatmullRom;return t[0]===t[e]?(n<0&&(r=Math.floor(i=e*(1+n))),o(t[(r-1+e)%e],t[r],t[(r+1)%e],t[(r+2)%e],i-r)):n<0?t[0]-(o(t[0],t[0],t[1],t[1],-i)-t[0]):n>1?t[e]-(o(t[e],t[e],t[e-1],t[e-1],i-e)-t[e]):o(t[r?r-1:0],t[r],t[e<r+1?e:r+1],t[e<r+2?e:r+2],i-r)},Utils:{Linear:function(t,n,e){return"function"==typeof t?t(e):(n-t)*e+t},Bernstein:function(t,n){var e=v.Utils.Factorial;return e(t)/e(n)/e(t-n)},Factorial:function(){var t=[1];return function(n){var e=1;if(t[n])return t[n];for(var i=n;i>1;i--)e*=i;return t[n]=e,e}}(),CatmullRom:function(t,n,e,i,r){var o=.5*(e-t),u=.5*(i-n),a=r*r;return(2*n-2*e+o+u)*(r*a)+(-3*n+3*e-2*o-u)*a+o*r+n}}},m=0,g=function(t){return this.id=m++,this.object=t,this._valuesStart={},this._valuesEnd=null,this._valuesStartRepeat={},this._duration=1e3,this._easingFunction=d.Linear.None,this._interpolationFunction=v.Linear,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._pausedTime=null,this._isFinite=!0,this._onStartCallback=null,this._onUpdateCallback=null,this._onCompleteCallback=null,this};g.prototype.onStart=function(t){return this._onStartCallback=t,this},g.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},g.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},g.prototype.isPlaying=function(){return this._isPlaying},g.prototype.isStarted=function(){return this._onStartCallbackFired},g.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,c(this),this._pausedTime=h(),this):this},g.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=h()-this._pausedTime,s(this),this._pausedTime=h(),this)},g.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},g.prototype.to=function(t,n){return void 0===n&&(n=1e3),this._valuesEnd=t,this._duration=n,this},g.prototype.start=function(t){this._startTime=void 0!==t?t:h(),this._startTime+=this._delayTime;var n=this,e=n._valuesEnd,i=n._valuesStartRepeat,r=n._valuesStart,o=n._interpolationFunction,u=n.object;for(var a in e)!function(t){var n=u[t],a=e[t];if(u&&void 0!==u[t]){var s=u[t];if("number"==typeof n){if("string"==typeof a)i[t]=a,a=n+parseFloat(a);else if(Array.isArray(a)){a.unshift(n);var f=a;a=function(t){return o(f,t)}}}else if("object"==typeof a)if(Array.isArray(a)){var c=a,h=n.map(function(t){return t}),l=void 0,p=a.length;a=function(t){for(l=0;l<p;l++)s[l]="number"==typeof h[l]?h[l]+(c[l]-h[l])*t:c[l];return s}}else{var _=a,y={};for(var d in n)y[d]=n[d];a=function(t){for(var n in a)s[n]="number"==typeof y[n]?y[n]+(_[n]-y[n])*t:_[n];return s}}r[t]=n,e[t]=a}}(a);return s(this),this._isPlaying=!0,this},g.prototype.stop=function(){var t=this,n=t._isPlaying,e=t._startTime,i=t._duration;return n?(this.update(e+i),c(this),this._isPlaying=!1,this):this},g.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},g.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},g.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},g.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},g.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},g.prototype.easing=function(t){return"function"==typeof t&&(this._easingFunction=t),this},g.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},g.prototype.reassignValues=function(){var t=this,n=t._valuesStart,e=t._valuesEnd,i=t.object;for(var r in e){var o=n[r];i[r]=o}return this},g.prototype.update=function(t,n){var e,i,r,o=this,u=o._onStartCallbackFired,a=o._easingFunction,s=o._repeat,f=o._repeatDelayTime,l=o._reverseDelayTime,p=o._yoyo,_=o._reversed,y=o._startTime,d=o._duration,v=o._valuesStart,g=o._valuesEnd,M=o._valuesStartRepeat,b=o.object,I=o._isFinite,T=o._isPlaying,O=o._onStartCallback,C=o._onUpdateCallback,P=o._onCompleteCallback;if(t=void 0!==t?t:h(),!T||t<y)return!0;u||(O&&O(b),this._onStartCallbackFired=!0),e=(e=(t-y)/d)>1?1:e,i=a(e=_?1-e:e);for(r in g){var F=v[r],w=g[r];void 0!==F&&("function"==typeof w?b[r]=w(i):"number"==typeof w&&(b[r]=F+(w-F)*i))}if(C&&C(b,e),1===e||_&&0===e){if(s){if(I&&this._repeat--,!_)for(r in M)v[r]=g[r],g[r]+=parseFloat(M[r]);return p&&(this._reversed=!_),this._startTime=!_&&f?t+f:_&&l?t+l:t,!0}return n||c(this),this._isPlaying=!1,P&&P(),this._repeat=this._r,m--,!1}return!0},t.Plugins=p,t.has=function(t){return null!==f(t)},t.get=f,t.getAll=function(){return i},t.removeAll=function(){i.length=0},t.remove=c,t.add=s,t.now=h,t.update=l,t.autoPlay=function(t){o=t},t.isRunning=function(){return r},t.Tween=g,t.Easing=d,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=lite/Tween.min.js.map
//# sourceMappingURL=Tween.min.js.map
{
"name": "es6-tween",
"version": "3.7.1",
"version": "3.8.0",
"description": "ES6 implementation of amazing tween.js",
"browser": "dist/Tween.min.js",
"cdn": "dist/Tween.min.js",
"main": "dist/Tween.min.js",
"browser": "full/Tween.min.js",
"cdn": "full/Tween.min.js",
"main": "full/Tween.min.js",
"module": "src/index.js",
"directories": {
"example": "examples"
},
"types": "Tween.d.ts",
"types": "typings/Tween.d.ts",
"scripts": {

@@ -16,16 +17,13 @@ "source": "rollup -c --environment min:false",

"build": "npm run source && npm run minify",
"source-lite": "rollup -c lite.js --environment min:false",
"minify-lite": "rollup -c lite.js --environment min:true",
"source-lite": "rollup -c rollup.config.lite.js --environment min:false",
"minify-lite": "rollup -c rollup.config.lite.js --environment min:true",
"build-lite": "npm run source-lite && npm run minify-lite",
"prepare": "npm run build && npm run build-lite",
"prepare": "tsc && npm run build && npm run build-lite",
"dev": "rollup -c -w",
"dev-lite": "rollup -c lite.js -w",
"lint": "eslint src",
"fix": "eslint --fix src",
"dev-lite": "rollup -c rollup.config.lite.js -w",
"lint": "eslint --fix src",
"test": "npm run lint && ava --verbose",
"doc-build-html": "documentation bin/documentation.js build src/** -f html -o doc",
"doc-live-html": "documentation bin/documentation.js build src/** -f html -o doc --watch",
"doc-build-md": "documentation bin/documentation.js build src/** -f md -o API.md",
"doc-live-md": "documentation bin/documentation.js build src/** -f md -o API.md --watch",
"prepublishOnly": "npm run lint && npm run doc-build-md && npm run prepare && ava --verbose"
"prepublish": "npm run prepare && npm run lint && npm run doc-md && ava --verbose",
"doc": "node_modules/.bin/jsdoc --readme README.md --configure jsdoc.json --verbose",
"doc-md": "jsdoc2md src/** > API.md"
},

@@ -53,5 +51,7 @@ "repository": {

"ava": "^0.22.0",
"documentation": "^5.3.1",
"docdash": "^0.4.0",
"eslint": "latest",
"eslint-plugin-import": "latest",
"jsdoc": "^3.5.5",
"jsdoc-to-markdown": "next",
"rollup": "^0.49.2",

@@ -63,2 +63,3 @@ "rollup-plugin-buble": "latest",

"rollup-watch": "latest",
"typescript": "^2.5.2",
"uglify-es": "latest"

@@ -65,0 +66,0 @@ },

@@ -39,3 +39,3 @@ # es6-tween

You can use the `Lite` version of ES6 which lighter (~9Kb minified, ~3Kb min&gzip), faster (~10% faster executioin), simpler (like the original one), memory effecient and better (can tween second-level Objects/Array). Optimized for runtime performance, no-lag anymore.
You can use the `Lite` version of ES6 which lighter (~9Kb minified, ~3Kb min&gzip), faster (~10% faster execution speed), simpler (like the original one), memory effecient and better (can tween second-level Objects/Array). Optimized for runtime performance, no-lag anymore.
When you want building mobile apps that loading files from server, use `Lite` for better performance.

@@ -210,2 +210,4 @@ Differences when using `Lite`:

* Original source: <a href="https://github.com/tweenjs/tween.js">check out at here</a>
* [Full documentation](https://tweenjs.github.io/es6-tween/)
* [API documentation](./API.md)
* [User guide](./docs/user_guide.md)

@@ -212,0 +214,0 @@ * [Wiki page](https://github.com/tweenjs/es6-tween/wiki)

@@ -11,2 +11,4 @@ import buble from 'rollup-plugin-buble'

let mode = (isMinify ? '' : 'un') + 'compressed'
const plugins = [

@@ -37,4 +39,4 @@ // ES6->ES5 syntax/code transpiler

sourceMap: {
filename: `src/Tween.js`,
url: `dist/Tween${minSuffix}.js.map`
filename: `src/index.js`,
url: `full/Tween${minSuffix}.js.map`
}

@@ -46,6 +48,6 @@ }, minify)

export default {
input: 'src/Tween.js',
input: 'src/index.js',
output: {
format: 'umd',
file: `dist/Tween${minSuffix}.js`
file: `full/Tween${minSuffix}.js`
},

@@ -52,0 +54,0 @@ sourcemap: true,

/* global global */
export let create = Object.create || function (source) {
export let create = Object.create || ((source) => {
return Object.assign({}, source || {})
}
export let assign = Object.assign || function (source, ...args) {
})
export let assign = Object.assign || ((source, ...args) => {
for (let i = 0, len = args.length; i < len; i++) {
let arg = args[i]
for (let p in arg) {
const arg = args[i]
for (const p in arg) {
source[p] = arg[p]

@@ -13,9 +13,5 @@ }

return source
}
if (!Array.isArray) {
Array.isArray = source => source && source.push && source.splice
}
})
export let root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this
export let requestAnimationFrame = root.requestAnimationFrame || function (fn) { return root.setTimeout(fn, 16) }
export let cancelAnimationFrame = root.cancelAnimationFrame || function (id) { return root.clearTimeout(id) }
export let requestAnimationFrame = root.requestAnimationFrame || (fn => root.setTimeout(fn, 16))
export let cancelAnimationFrame = root.cancelAnimationFrame || (id => root.clearTimeout(id))

@@ -1,7 +0,463 @@

import './shim'
import { has, get, getAll, removeAll, remove, add, now, update, autoPlay, Plugins, isRunning } from './dist/core'
import Easing from './dist/Easing'
import Tween from './dist/Tween'
import Timeline from './dist/Timeline'
import Interpolator from 'intertween'
export { Plugins, Interpolator, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }
import InterTween from 'intertween'
import { create } from './shim'
import { add, now, Plugins, remove } from './core'
import Easing from './Easing'
import EventClass from './Event'
import NodeCache from './NodeCache'
Object.create = create
// Events list
export const EVENT_UPDATE = 'update'
export const EVENT_COMPLETE = 'complete'
export const EVENT_START = 'start'
export const EVENT_REPEAT = 'repeat'
export const EVENT_REVERSE = 'reverse'
export const EVENT_PAUSE = 'pause'
export const EVENT_PLAY = 'play'
export const EVENT_RS = 'restart'
export const EVENT_STOP = 'stop'
export const EVENT_SEEK = 'seek'
let _id = 0 // Unique ID
const defaultEasing = Easing.Linear.None
/**
* Tween main constructor
* @constructor
* @extends EventClass
* @param {Object|Element} node Node Element or Tween initial object
* @param {Object=} object If Node Element is using, second argument is used for Tween initial object
* @example let tween = new Tween(myNode, {width:'100px'}).to({width:'300px'}, 2000).start()
*/
class Tween extends EventClass {
/**
* Easier way to call the Tween
* @param {Element} node DOM Element
* @param {object} object - Initial value
* @param {object} to - Target value
* @param {object} params - Options of tweens
* @example Tween.fromTo(node, {x:0}, {x:200}, {duration:1000})
* @memberof Tween
* @static
*/
static fromTo (node, object, to, params = {}) {
params.quickRender = params.quickRender ? params.quickRender : !to
const tween = new Tween(node, object).to(to, params)
if (params.quickRender) {
tween.render().update(tween._startTime)
tween._rendered = false
tween._onStartCallbackFired = false
}
return tween
}
/**
* Easier way calling constructor only applies the `to` value, useful for CSS Animation
* @param {Element} node DOM Element
* @param {object} to - Target value
* @param {object} params - Options of tweens
* @example Tween.to(node, {x:200}, {duration:1000})
* @memberof Tween
* @static
*/
static to (node, to, params) {
return Tween.fromTo(node, null, to, params)
}
/**
* Easier way calling constructor only applies the `from` value, useful for CSS Animation
* @param {Element} node DOM Element
* @param {object} from - Initial value
* @param {object} params - Options of tweens
* @example Tween.from(node, {x:200}, {duration:1000})
* @memberof Tween
* @static
*/
static from (node, from, params) {
return Tween.fromTo(node, from, null, params)
}
constructor (node, object) {
super()
this.id = _id++
if (typeof node !== 'undefined' && !object && !node.nodeType) {
object = this.object = node
node = null
} else if (typeof node !== 'undefined') {
this.node = node
if (typeof object === 'object') {
object = this.object = NodeCache(node, object)
} else {
this.object = object
}
}
const isArr = this.isArr = Array.isArray(object)
this._valuesStart = isArr ? [] : {}
this._valuesEnd = null
this._valuesFunc = {}
this._duration = 1000
this._easingFunction = defaultEasing
this._easingReverse = defaultEasing
this._startTime = 0
this._delayTime = 0
this._repeat = 0
this._r = 0
this._isPlaying = false
this._yoyo = false
this._reversed = false
this._onStartCallbackFired = false
this._pausedTime = null
this._isFinite = true
this._elapsed = 0
return this
}
/**
* @return {boolean} State of playing of tween
* @example tween.isPlaying() // returns `true` if tween in progress
* @memberof Tween
*/
isPlaying () {
return this._isPlaying
}
/**
* @return {boolean} State of started of tween
* @example tween.isStarted() // returns `true` if tween in started
* @memberof Tween
*/
isStarted () {
return this._onStartCallbackFired
}
/**
* Reverses the tween state/direction
* @example tween.reverse()
* @memberof Tween
*/
reverse () {
const { _reversed } = this
this._reversed = !_reversed
return this
}
/**
* @return {boolean} State of reversed
* @example tween.reversed() // returns `true` if tween in reversed state
* @memberof Tween
*/
reversed () {
return this._reversed
}
/**
* Pauses tween
* @example tween.pause()
* @memberof Tween
*/
pause () {
if (!this._isPlaying) {
return this
}
this._isPlaying = false
remove(this)
this._pausedTime = now()
return this.emit(EVENT_PAUSE, this.object)
}
/**
* Play/Resume the tween
* @example tween.play()
* @memberof Tween
*/
play () {
if (this._isPlaying) {
return this
}
this._isPlaying = true
this._startTime += now() - this._pausedTime
add(this)
this._pausedTime = now()
return this.emit(EVENT_PLAY, this.object)
}
/**
* Restarts tween from initial value
* @param {boolean=} noDelay If this param is set to `true`, restarts tween without `delay`
* @example tween.restart()
* @memberof Tween
*/
restart (noDelay) {
this._repeat = this._r
this._startTime = now() + (noDelay ? 0 : this._delayTime)
if (!this._isPlaying) {
add(this)
}
return this.emit(EVENT_RS, this.object)
}
/**
* Seek tween value by `time`
* @param {Time} time Tween update time
* @param {boolean=} keepPlaying When this param is set to `false`, tween pausing after seek
* @example tween.seek(500)
* @memberof Tween
*/
seek (time, keepPlaying) {
this._startTime = now() + Math.max(0, Math.min(time, this._duration))
this.emit(EVENT_SEEK, time, this.object)
return keepPlaying ? this : this.pause()
}
/**
* Sets tween duration
* @param {number} amount Duration is milliseconds
* @example tween.duration(2000)
* @memberof Tween
*/
duration (amount) {
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount
return this
}
/**
* Sets target value and duration
* @param {object} properties Target value (to value)
* @param {number|Object=} [duration=1000] Duration of tween
* @example let tween = new Tween({x:0}).to({x:100}, 2000)
* @memberof Tween
*/
to (properties, duration = 1000, maybeUsed) {
this._valuesEnd = properties
if (typeof duration === 'number' || typeof (duration) === 'function') {
this._duration = typeof (duration) === 'function' ? duration(this._duration) : duration
} else if (typeof duration === 'object') {
for (const prop in duration) {
if (typeof this[prop] === 'function') {
const [arg1 = null, arg2 = null, arg3 = null, arg4 = null] = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]]
this[prop](arg1, arg2, arg3, arg4)
}
}
}
return this
}
/**
* Renders and computes value at first render
* @private
* @memberof Tween
*/
render () {
if (this._rendered) {
return this
}
let { _valuesEnd, _valuesFunc, _valuesStart, object, Renderer, node, InitialValues } = this
if (node && InitialValues) {
if (!object) {
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd))
} else if (!_valuesEnd) {
_valuesEnd = this._valuesEnd = InitialValues(node, object)
}
}
for (const property in _valuesEnd) {
const start = object && object[property]
const end = _valuesEnd[property]
if (Plugins[property]) {
const plugin = Plugins[property].prototype.update ? new Plugins[property](this, start, end, property, object) : Plugins[property](this, start, end, property, object)
if (plugin) {
_valuesFunc[property] = plugin
}
continue
}
if (!object || object[property] === undefined) {
continue
}
if (typeof end === 'number' && typeof start === 'number') {
_valuesStart[property] = start
_valuesEnd[property] = end
} else {
_valuesFunc[property] = InterTween(start, end)
}
}
if (Renderer && this.node) {
this.__render = new Renderer(this, object, _valuesEnd)
}
return this
}
/**
* Start the tweening
* @param {number} time setting manual time instead of Current browser timestamp
* @example tween.start()
* @memberof Tween
*/
start (time) {
this._startTime = time !== undefined ? time : now()
this._startTime += this._delayTime
add(this)
this._isPlaying = true
return this
}
/**
* Stops the tween
* @example tween.stop()
* @memberof Tween
*/
stop () {
const { _isPlaying, object, _startTime, _duration } = this
if (!_isPlaying) {
return this
}
this.update(_startTime + _duration)
remove(this)
this._isPlaying = false
return this.emit(EVENT_STOP, object)
}
/**
* Set delay of tween
* @param {number} amount Sets tween delay / wait duration
* @example tween.delay(500)
* @memberof Tween
*/
delay (amount) {
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount
this._startTime += this._delayTime
return this
}
/**
* Sets how times tween is repeating
* @param {amount} amount the times of repeat
* @example tween.repeat(5)
* @memberof Tween
*/
repeat (amount) {
this._repeat = typeof (amount) === 'function' ? amount(this._repeat) : amount
this._r = this._repeat
this._isFinite = isFinite(amount)
return this
}
/**
* Set delay of each repeat of tween
* @param {number} amount Sets tween repeat delay / repeat wait duration
* @example tween.repeatDelay(400)
* @memberof Tween
*/
repeatDelay (amount) {
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount
return this
}
/**
* Set delay of each repeat alternate of tween
* @param {number} amount Sets tween repeat alternate delay / repeat alternate wait duration
* @example tween.reverseDelay(500)
* @memberof Tween
*/
reverseDelay (amount) {
this._reverseDelayTime = typeof (amount) === 'function' ? amount(this._reverseDelayTime) : amount
return this
}
/**
* Set `yoyo` state (enables reverse in repeat)
* @param {boolean} state Enables alternate direction for repeat
* @param {Function=} _easingReverse Easing function in reverse direction
* @example tween.yoyo(true)
* @memberof Tween
*/
yoyo (state, _easingReverse) {
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state === null ? this._yoyo : state
this._easingReverse = _easingReverse || defaultEasing
return this
}
/**
* Set easing
* @param {Function} _easingFunction Easing function in non-reverse direction
* @example tween.easing(Easing.Elastic.InOut)
* @memberof Tween
*/
easing (_easingFunction) {
this._easingFunction = _easingFunction
return this
}
/**
* Reassigns value for rare-case like Tween#restart or for Timeline
* @private
* @memberof Tween
*/
reassignValues () {
const { _valuesStart, _valuesEnd, object, isArr } = this
let property
for (property in _valuesEnd) {
if (isArr) {
property = parseInt(property)
}
const start = _valuesStart[property]
const end = _valuesEnd[property]
object[property] = typeof end === 'function' ? end(0) : start
}
return this
}
/**
* Updates initial object to target value by given `time`
* @param {Time} time Current time
* @param {boolean=} preserve Prevents from removing tween from store
* @example tween.update(100)
* @memberof Tween
*/
update (time, preserve) {
const { _onStartCallbackFired, _easingFunction, _easingReverse, _repeat, _repeatDelayTime, _reverseDelayTime, _yoyo, _reversed, _startTime, _duration, _valuesStart, _valuesEnd, _valuesFunc, object, _isFinite, _isPlaying, __render } = this
let elapsed
let value
let property
let currentEasing
time = time !== undefined ? time : now()
if (!_isPlaying || time < _startTime) {
return true
}
if (!_onStartCallbackFired) {
if (!this._rendered) {
this.render()
this._rendered = true
}
this.emit(EVENT_START, object)
this._onStartCallbackFired = true
}
elapsed = (time - _startTime) / _duration
elapsed = elapsed > 1 ? 1 : elapsed
elapsed = _reversed ? 1 - elapsed : elapsed
currentEasing = _reversed ? _easingReverse : _easingFunction
if (!object) {
return true
}
for (property in _valuesEnd) {
value = currentEasing[property] ? currentEasing[property](elapsed) : typeof currentEasing === 'function' ? currentEasing(elapsed) : defaultEasing(elapsed)
const start = _valuesStart[property]
const end = _valuesEnd[property]
const fnc = _valuesFunc[property]
if (fnc && fnc.update) {
fnc.update(value, elapsed)
} else if (fnc) {
object[property] = fnc(value)
} else if (typeof end === 'number') {
object[property] = start + (end - start) * value
} else {
object[property] = end
}
}
if (__render) {
__render.update(object, elapsed)
}
this.emit(EVENT_UPDATE, object, elapsed)
if (elapsed === 1 || (_reversed && elapsed === 0)) {
if (_repeat) {
if (_isFinite) {
this._repeat--
}
if (_yoyo) {
this._reversed = !_reversed
}
this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object)
if (!_reversed && _repeatDelayTime) {
this._startTime = time + _repeatDelayTime
} else if (_reversed && _reverseDelayTime) {
this._startTime = time + _reverseDelayTime
} else {
this._startTime = time
}
return true
} else {
if (!preserve) {
this._isPlaying = false
remove(this)
_id--
}
this.emit(EVENT_COMPLETE, object)
this._repeat = this._r
return false
}
}
return true
}
}
export default Tween
import test from 'ava'
const { Easing, Tween, update, getAll, removeAll } = require('./dist/Tween')
const { Easing, Tween, update, getAll, removeAll } = require('./full/Tween')

@@ -4,0 +4,0 @@ test('Events', t => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc