es6-tween
Advanced tools
Comparing version 5.1.0 to 5.2.0
2911
bundled/Tween.js
@@ -7,12 +7,221 @@ (function (global, factory) { | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function _AwaitValue(value) { | ||
this.wrapped = value; | ||
} | ||
function _AsyncGenerator(gen) { | ||
var front, back; | ||
function send(key, arg) { | ||
return new Promise(function (resolve, reject) { | ||
var request = { | ||
key: key, | ||
arg: arg, | ||
resolve: resolve, | ||
reject: reject, | ||
next: null | ||
}; | ||
if (back) { | ||
back = back.next = request; | ||
} else { | ||
front = back = request; | ||
resume(key, arg); | ||
} | ||
}); | ||
} | ||
function resume(key, arg) { | ||
try { | ||
var result = gen[key](arg); | ||
var value = result.value; | ||
var wrappedAwait = value instanceof _AwaitValue; | ||
Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) { | ||
if (wrappedAwait) { | ||
resume("next", arg); | ||
return; | ||
} | ||
settle(result.done ? "return" : "normal", arg); | ||
}, function (err) { | ||
resume("throw", err); | ||
}); | ||
} catch (err) { | ||
settle("throw", err); | ||
} | ||
} | ||
function settle(type, value) { | ||
switch (type) { | ||
case "return": | ||
front.resolve({ | ||
value: value, | ||
done: true | ||
}); | ||
break; | ||
case "throw": | ||
front.reject(value); | ||
break; | ||
default: | ||
front.resolve({ | ||
value: value, | ||
done: false | ||
}); | ||
break; | ||
} | ||
front = front.next; | ||
if (front) { | ||
resume(front.key, front.arg); | ||
} else { | ||
back = null; | ||
} | ||
} | ||
this._invoke = send; | ||
if (typeof gen.return !== "function") { | ||
this.return = undefined; | ||
} | ||
} | ||
if (typeof Symbol === "function" && Symbol.asyncIterator) { | ||
_AsyncGenerator.prototype[Symbol.asyncIterator] = function () { | ||
return this; | ||
}; | ||
} | ||
_AsyncGenerator.prototype.next = function (arg) { | ||
return this._invoke("next", arg); | ||
}; | ||
_AsyncGenerator.prototype.throw = function (arg) { | ||
return this._invoke("throw", arg); | ||
}; | ||
_AsyncGenerator.prototype.return = function (arg) { | ||
return this._invoke("return", arg); | ||
}; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
/* global global */ | ||
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 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); | ||
}; | ||
@@ -27,29 +236,21 @@ /* global process */ | ||
*/ | ||
var now = (function () { | ||
if (typeof process !== 'undefined' && process.hrtime !== undefined && (!process.versions || process.versions.electron === 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. | ||
} | ||
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_1 = root.performance && | ||
root.performance.timing && | ||
root.performance.timing.navigationStart | ||
? root.performance.timing.navigationStart | ||
: Date.now(); | ||
return function () { | ||
return Date.now() - offset_1; | ||
}; | ||
} | ||
})(); | ||
var now = function () { | ||
if (typeof process !== 'undefined' && process.hrtime !== undefined && (!process.versions || process.versions.electron === 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. | ||
} 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; | ||
}; | ||
} | ||
}(); | ||
/** | ||
@@ -64,6 +265,10 @@ * Lightweight, effecient and modular ES6 version of tween.js | ||
*/ | ||
var _tweens = []; | ||
var isStarted = false; | ||
var _autoPlay = false; | ||
var _tick; | ||
var _ticker = requestAnimationFrame; | ||
@@ -82,13 +287,18 @@ var _stopTicker = cancelAnimationFrame; | ||
*/ | ||
var add = function (tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i > -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
_tweens.push(tween); | ||
emptyFrame = 0; | ||
if (_autoPlay && !isStarted) { | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
var add = function add(tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i > -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
_tweens.push(tween); | ||
emptyFrame = 0; | ||
if (_autoPlay && !isStarted) { | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
}; | ||
@@ -102,3 +312,9 @@ /** | ||
*/ | ||
var onTick = function (fn) { return _tweens.push({ update: fn }); }; | ||
var onTick = function onTick(fn) { | ||
return _tweens.push({ | ||
update: fn | ||
}); | ||
}; | ||
/** | ||
@@ -109,3 +325,7 @@ * @returns {Array<Tween>} List of tweens in Array | ||
*/ | ||
var getAll = function () { return _tweens; }; | ||
var getAll = function getAll() { | ||
return _tweens; | ||
}; | ||
/** | ||
@@ -117,4 +337,6 @@ * Runs update loop automaticlly | ||
*/ | ||
var autoPlay = function (state) { | ||
_autoPlay = state; | ||
var autoPlay = function autoPlay(state) { | ||
_autoPlay = state; | ||
}; | ||
@@ -126,4 +348,6 @@ /** | ||
*/ | ||
var removeAll = function () { | ||
_tweens.length = 0; | ||
var removeAll = function removeAll() { | ||
_tweens.length = 0; | ||
}; | ||
@@ -137,9 +361,12 @@ /** | ||
*/ | ||
var get = function (tween) { | ||
for (var i = 0; i < _tweens.length; i++) { | ||
if (tween === _tweens[i]) { | ||
return _tweens[i]; | ||
} | ||
var get = function get(tween) { | ||
for (var i = 0; i < _tweens.length; i++) { | ||
if (tween === _tweens[i]) { | ||
return _tweens[i]; | ||
} | ||
return null; | ||
} | ||
return null; | ||
}; | ||
@@ -153,4 +380,6 @@ /** | ||
*/ | ||
var has = function (tween) { | ||
return get(tween) !== null; | ||
var has = function has(tween) { | ||
return get(tween) !== null; | ||
}; | ||
@@ -164,7 +393,10 @@ /** | ||
*/ | ||
var remove = function (tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i !== -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
var remove = function remove(tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i !== -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
}; | ||
@@ -179,21 +411,30 @@ /** | ||
*/ | ||
var update = function (time, preserve) { | ||
time = time !== undefined ? time : now(); | ||
if (_autoPlay && isStarted) { | ||
_tick = _ticker(update); | ||
} | ||
if (!_tweens.length) { | ||
emptyFrame++; | ||
} | ||
if (emptyFrame > powerModeThrottle) { | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
emptyFrame = 0; | ||
return false; | ||
} | ||
var i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i++].update(time, preserve); | ||
} | ||
return true; | ||
var update = function update() { | ||
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : now(); | ||
var preserve = arguments.length > 1 ? arguments[1] : undefined; | ||
if (_autoPlay && isStarted) { | ||
_tick = _ticker(update); | ||
} | ||
if (!_tweens.length) { | ||
emptyFrame++; | ||
} | ||
if (emptyFrame > powerModeThrottle) { | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
emptyFrame = 0; | ||
return false; | ||
} | ||
var i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i++].update(time, preserve); | ||
} | ||
return true; | ||
}; | ||
@@ -206,3 +447,7 @@ /** | ||
*/ | ||
var isRunning = function () { return isStarted; }; | ||
var isRunning = function isRunning() { | ||
return isStarted; | ||
}; | ||
/** | ||
@@ -219,2 +464,4 @@ * The plugins store object | ||
*/ | ||
var Plugins = {}; | ||
@@ -231,186 +478,206 @@ | ||
var Easing = { | ||
Linear: { | ||
None: function (k) { | ||
return k; | ||
} | ||
Linear: { | ||
None: function None(k) { | ||
return k; | ||
} | ||
}, | ||
Quadratic: { | ||
In: function In(k) { | ||
return k * k; | ||
}, | ||
Quadratic: { | ||
In: function (k) { | ||
return k * k; | ||
}, | ||
Out: function (k) { | ||
return k * (2 - k); | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k; | ||
} | ||
return -0.5 * (--k * (k - 2) - 1); | ||
} | ||
Out: function Out(k) { | ||
return k * (2 - k); | ||
}, | ||
Cubic: { | ||
In: function (k) { | ||
return k * k * k; | ||
}, | ||
Out: function (k) { | ||
return --k * k * k + 1; | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k; | ||
} | ||
return 0.5 * ((k -= 2) * k * k + 2); | ||
} | ||
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; | ||
}, | ||
Quartic: { | ||
In: function (k) { | ||
return k * k * k * k; | ||
}, | ||
Out: function (k) { | ||
return 1 - --k * k * k * k; | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k; | ||
} | ||
return -0.5 * ((k -= 2) * k * k * k - 2); | ||
} | ||
Out: function Out(k) { | ||
return --k * k * k + 1; | ||
}, | ||
Quintic: { | ||
In: function (k) { | ||
return k * k * k * k * k; | ||
}, | ||
Out: function (k) { | ||
return --k * k * k * k * k + 1; | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k * k; | ||
} | ||
return 0.5 * ((k -= 2) * k * 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; | ||
}, | ||
Sinusoidal: { | ||
In: function (k) { | ||
return 1 - Math.cos(k * Math.PI / 2); | ||
}, | ||
Out: function (k) { | ||
return Math.sin(k * Math.PI / 2); | ||
}, | ||
InOut: function (k) { | ||
return 0.5 * (1 - Math.cos(Math.PI * k)); | ||
} | ||
Out: function Out(k) { | ||
return 1 - --k * k * k * k; | ||
}, | ||
Exponential: { | ||
In: function (k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1); | ||
}, | ||
Out: function (k) { | ||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k); | ||
}, | ||
InOut: function (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); | ||
} | ||
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; | ||
}, | ||
Circular: { | ||
In: function (k) { | ||
return 1 - Math.sqrt(1 - k * k); | ||
}, | ||
Out: function (k) { | ||
return Math.sqrt(1 - --k * k); | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return -0.5 * (Math.sqrt(1 - k * k) - 1); | ||
} | ||
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1); | ||
} | ||
Out: function Out(k) { | ||
return --k * k * k * k * k + 1; | ||
}, | ||
Elastic: { | ||
In: function (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 (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 (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); | ||
} | ||
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); | ||
}, | ||
Back: { | ||
In: function (k) { | ||
var s = 1.70158; | ||
return k * k * ((s + 1) * k - s); | ||
}, | ||
Out: function (k) { | ||
var s = 1.70158; | ||
return --k * k * ((s + 1) * k + s) + 1; | ||
}, | ||
InOut: function (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); | ||
} | ||
Out: function Out(k) { | ||
return Math.sin(k * Math.PI / 2); | ||
}, | ||
Bounce: { | ||
In: function (k) { | ||
return 1 - Easing.Bounce.Out(1 - k); | ||
}, | ||
Out: function (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 (k) { | ||
if (k < 0.5) { | ||
return Easing.Bounce.In(k * 2) * 0.5; | ||
} | ||
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; | ||
} | ||
InOut: function InOut(k) { | ||
return 0.5 * (1 - Math.cos(Math.PI * k)); | ||
} | ||
}, | ||
Exponential: { | ||
In: function In(k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1); | ||
}, | ||
Stepped: { | ||
steps: function (steps) { return function (k) { return ((k * steps) | 0) / steps; }; } | ||
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; | ||
} | ||
}, | ||
Stepped: { | ||
steps: function steps(_steps) { | ||
return function (k) { | ||
return (k * _steps | 0) / _steps; | ||
}; | ||
} | ||
} | ||
}; | ||
@@ -421,4 +688,4 @@ | ||
var TOO_LONG_FRAME_MS = 250; | ||
var CHAINED_TWEENS = '_chainedTweens'; | ||
// Event System | ||
var CHAINED_TWEENS = '_chainedTweens'; // Event System | ||
var EVENT_CALLBACK = 'Callback'; | ||
@@ -434,267 +701,282 @@ var EVENT_UPDATE = 'update'; | ||
var EVENT_STOP = 'stop'; | ||
var EVENT_SEEK = 'seek'; | ||
// For String tweening stuffs | ||
var STRING_PROP = 'STRING_PROP'; | ||
// Also RegExp's for string tweening | ||
var EVENT_SEEK = 'seek'; // For String tweening stuffs | ||
var STRING_PROP = 'STRING_PROP'; // Also RegExp's for string tweening | ||
var NUM_REGEX = /\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]=+)?([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]=?\d+)?/g; | ||
// Copies everything, duplicates, no shallow-copy | ||
// Copies everything, duplicates, no shallow-copy | ||
function deepCopy(source) { | ||
if ((source && source.nodeType) || source === undefined || typeof source !== 'object') { | ||
return source; | ||
if (source && source.nodeType || source === undefined || _typeof(source) !== 'object') { | ||
return source; | ||
} else if (Array.isArray(source)) { | ||
return [].concat(source); | ||
} else if (_typeof(source) === 'object') { | ||
var target = {}; | ||
for (var prop in source) { | ||
target[prop] = deepCopy(source[prop]); | ||
} | ||
else if (Array.isArray(source)) { | ||
return [].concat(source); | ||
} | ||
else if (typeof source === 'object') { | ||
var target = {}; | ||
for (var prop in source) { | ||
target[prop] = deepCopy(source[prop]); | ||
} | ||
return target; | ||
} | ||
return source; | ||
return target; | ||
} | ||
return source; | ||
} | ||
var isNaNForST = function (v) { | ||
return isNaN(+v) || ((v[0] === '+' || v[0] === '-') && v[1] === '=') || v === '' || v === ' '; | ||
var isNaNForST = function isNaNForST(v) { | ||
return isNaN(+v) || (v[0] === '+' || v[0] === '-') && v[1] === '=' || v === '' || v === ' '; | ||
}; | ||
var hexColor = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i; | ||
var hex2rgb = function (all, hex) { | ||
var r; | ||
var g; | ||
var b; | ||
if (hex.length === 3) { | ||
r = hex[0]; | ||
g = hex[1]; | ||
b = hex[2]; | ||
hex = r + r + g + g + b + b; | ||
} | ||
var color = parseInt(hex, 16); | ||
r = color >> 16 & 255; | ||
g = color >> 8 & 255; | ||
b = color & 255; | ||
return "rgb(" + r + "," + g + "," + b + ")"; | ||
var hex2rgb = function hex2rgb(all, hex) { | ||
var r; | ||
var g; | ||
var b; | ||
if (hex.length === 3) { | ||
r = hex[0]; | ||
g = hex[1]; | ||
b = hex[2]; | ||
hex = r + r + g + g + b + b; | ||
} | ||
var color = parseInt(hex, 16); | ||
r = color >> 16 & 255; | ||
g = color >> 8 & 255; | ||
b = color & 255; | ||
return "rgb(" + r + "," + g + "," + b + ")"; | ||
}; | ||
function decomposeString(fromValue) { | ||
return typeof fromValue !== 'string' ? fromValue : fromValue.replace(hexColor, hex2rgb).match(NUM_REGEX).map(function (v) { return (isNaNForST(v) ? v : +v); }); | ||
} | ||
// Decompose value, now for only `string` that required | ||
return typeof fromValue !== 'string' ? fromValue : fromValue.replace(hexColor, hex2rgb).match(NUM_REGEX).map(function (v) { | ||
return isNaNForST(v) ? v : +v; | ||
}); | ||
} // Decompose value, now for only `string` that required | ||
function decompose(prop, obj, from, to, stringBuffer) { | ||
var fromValue = from[prop]; | ||
var toValue = to[prop]; | ||
if (typeof fromValue === 'string' || typeof toValue === 'string') { | ||
var fromValue1 = Array.isArray(fromValue) && fromValue[0] === STRING_PROP ? fromValue : decomposeString(fromValue); | ||
var toValue1 = Array.isArray(toValue) && toValue[0] === STRING_PROP ? toValue : decomposeString(toValue); | ||
var i = 1; | ||
while (i < fromValue1.length) { | ||
if (fromValue1[i] === toValue1[i] && typeof fromValue1[i - 1] === 'string') { | ||
fromValue1.splice(i - 1, 2, fromValue1[i - 1] + fromValue1[i]); | ||
toValue1.splice(i - 1, 2, toValue1[i - 1] + toValue1[i]); | ||
} | ||
else { | ||
i++; | ||
} | ||
} | ||
i = 0; | ||
if (fromValue1[0] === STRING_PROP) { | ||
fromValue1.shift(); | ||
} | ||
if (toValue1[0] === STRING_PROP) { | ||
toValue1.shift(); | ||
} | ||
var fromValue2 = { isString: true, length: fromValue1.length }; | ||
var toValue2 = { isString: true, length: toValue1.length }; | ||
while (i < fromValue2.length) { | ||
fromValue2[i] = fromValue1[i]; | ||
toValue2[i] = toValue1[i]; | ||
i++; | ||
} | ||
from[prop] = fromValue2; | ||
to[prop] = toValue2; | ||
return true; | ||
var fromValue = from[prop]; | ||
var toValue = to[prop]; | ||
if (typeof fromValue === 'string' || typeof toValue === 'string') { | ||
var fromValue1 = Array.isArray(fromValue) && fromValue[0] === STRING_PROP ? fromValue : decomposeString(fromValue); | ||
var toValue1 = Array.isArray(toValue) && toValue[0] === STRING_PROP ? toValue : decomposeString(toValue); | ||
var i = 1; | ||
while (i < fromValue1.length) { | ||
if (fromValue1[i] === toValue1[i] && typeof fromValue1[i - 1] === 'string') { | ||
fromValue1.splice(i - 1, 2, fromValue1[i - 1] + fromValue1[i]); | ||
toValue1.splice(i - 1, 2, toValue1[i - 1] + toValue1[i]); | ||
} else { | ||
i++; | ||
} | ||
} | ||
else if (typeof fromValue === 'object' && typeof toValue === 'object') { | ||
if (Array.isArray(fromValue)) { | ||
return fromValue.map(function (v, i) { | ||
return decompose(i, obj[prop], fromValue, toValue); | ||
}); | ||
} | ||
else { | ||
for (var prop2 in toValue) { | ||
decompose(prop2, obj[prop], fromValue, toValue); | ||
} | ||
} | ||
return true; | ||
i = 0; | ||
if (fromValue1[0] === STRING_PROP) { | ||
fromValue1.shift(); | ||
} | ||
return false; | ||
} | ||
// Recompose value | ||
if (toValue1[0] === STRING_PROP) { | ||
toValue1.shift(); | ||
} | ||
var fromValue2 = { | ||
isString: true, | ||
length: fromValue1.length | ||
}; | ||
var toValue2 = { | ||
isString: true, | ||
length: toValue1.length | ||
}; | ||
while (i < fromValue2.length) { | ||
fromValue2[i] = fromValue1[i]; | ||
toValue2[i] = toValue1[i]; | ||
i++; | ||
} | ||
from[prop] = fromValue2; | ||
to[prop] = toValue2; | ||
return true; | ||
} else if (_typeof(fromValue) === 'object' && _typeof(toValue) === 'object') { | ||
if (Array.isArray(fromValue)) { | ||
return fromValue.map(function (v, i) { | ||
return decompose(i, obj[prop], fromValue, toValue); | ||
}); | ||
} else { | ||
for (var prop2 in toValue) { | ||
decompose(prop2, obj[prop], fromValue, toValue); | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
} // Recompose value | ||
var DECIMAL = Math.pow(10, 4); | ||
var RGB = 'rgb('; | ||
var RGBA = 'rgba('; | ||
var isRGBColor = function (v, i, r) { | ||
if (r === void 0) { r = RGB; } | ||
return typeof v[i] === 'number' && | ||
(v[i - 1] === r || v[i - 3] === r || v[i - 5] === r); | ||
var isRGBColor = function isRGBColor(v, i) { | ||
var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : RGB; | ||
return typeof v[i] === 'number' && (v[i - 1] === r || v[i - 3] === r || v[i - 5] === r); | ||
}; | ||
function recompose(prop, obj, from, to, t, originalT, stringBuffer) { | ||
var fromValue = stringBuffer ? from : from[prop]; | ||
var toValue = stringBuffer ? to : to[prop]; | ||
if (toValue === undefined) { | ||
return fromValue; | ||
var fromValue = stringBuffer ? from : from[prop]; | ||
var toValue = stringBuffer ? to : to[prop]; | ||
if (toValue === undefined) { | ||
return fromValue; | ||
} | ||
if (fromValue === undefined || typeof fromValue === 'string' || fromValue === toValue) { | ||
return toValue; | ||
} else if (_typeof(fromValue) === 'object' && _typeof(toValue) === 'object') { | ||
if (!fromValue || !toValue) { | ||
return obj[prop]; | ||
} | ||
if (fromValue === undefined || | ||
typeof fromValue === 'string' || | ||
fromValue === toValue) { | ||
return toValue; | ||
} | ||
else if (typeof fromValue === 'object' && typeof toValue === 'object') { | ||
if (!fromValue || !toValue) { | ||
return obj[prop]; | ||
if (_typeof(fromValue) === 'object' && !!fromValue && fromValue.isString) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 0, len = fromValue.length; i < len; i++) { | ||
var isRelative = typeof fromValue[i] === 'number' && typeof toValue[i] === 'string' && toValue[i][1] === '='; | ||
var currentValue = typeof fromValue[i] !== 'number' ? fromValue[i] : ((isRelative ? fromValue[i] + parseFloat(toValue[i][0] + toValue[i].substr(2)) * t : fromValue[i] + (toValue[i] - fromValue[i]) * t) * DECIMAL | 0) / DECIMAL; | ||
if (isRGBColor(fromValue, i) || isRGBColor(fromValue, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
if (typeof fromValue === 'object' && !!fromValue && fromValue.isString) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 0, len = fromValue.length; i < len; i++) { | ||
var isRelative = typeof fromValue[i] === 'number' && typeof toValue[i] === 'string' && toValue[i][1] === '='; | ||
var currentValue = typeof fromValue[i] !== 'number' | ||
? fromValue[i] | ||
: (((isRelative | ||
? fromValue[i] + | ||
parseFloat(toValue[i][0] + toValue[i].substr(2)) * t | ||
: fromValue[i] + (toValue[i] - fromValue[i]) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (isRGBColor(fromValue, i) || isRGBColor(fromValue, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
if (isRelative && originalT === 1) { | ||
fromValue[i] = | ||
fromValue[i] + | ||
parseFloat(toValue[i][0] + toValue[i].substr(2)); | ||
} | ||
} | ||
if (!stringBuffer) { | ||
obj[prop] = STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
STRING_BUFFER += currentValue; | ||
if (isRelative && originalT === 1) { | ||
fromValue[i] = fromValue[i] + parseFloat(toValue[i][0] + toValue[i].substr(2)); | ||
} | ||
else if (Array.isArray(fromValue) && fromValue[0] !== STRING_PROP) { | ||
for (var i = 0, len = fromValue.length; i < len; i++) { | ||
if (fromValue[i] === toValue[i]) { | ||
continue; | ||
} | ||
recompose(i, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
} | ||
if (!stringBuffer) { | ||
obj[prop] = STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
} else if (Array.isArray(fromValue) && fromValue[0] !== STRING_PROP) { | ||
for (var _i = 0, _len = fromValue.length; _i < _len; _i++) { | ||
if (fromValue[_i] === toValue[_i]) { | ||
continue; | ||
} | ||
else if (typeof fromValue === 'object' && !!fromValue && !fromValue.isString) { | ||
for (var i in fromValue) { | ||
if (fromValue[i] === toValue[i]) { | ||
continue; | ||
} | ||
recompose(i, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
recompose(_i, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
} else if (_typeof(fromValue) === 'object' && !!fromValue && !fromValue.isString) { | ||
for (var _i2 in fromValue) { | ||
if (fromValue[_i2] === toValue[_i2]) { | ||
continue; | ||
} | ||
recompose(_i2, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
} | ||
else if (typeof fromValue === 'number') { | ||
var isRelative = typeof toValue === 'string'; | ||
obj[prop] = | ||
(((isRelative | ||
? fromValue + parseFloat(toValue[0] + toValue.substr(2)) * t | ||
: fromValue + (toValue - fromValue) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (isRelative && originalT === 1) { | ||
from[prop] = obj[prop]; | ||
} | ||
} else if (typeof fromValue === 'number') { | ||
var _isRelative = typeof toValue === 'string'; | ||
obj[prop] = ((_isRelative ? fromValue + parseFloat(toValue[0] + toValue.substr(2)) * t : fromValue + (toValue - fromValue) * t) * DECIMAL | 0) / DECIMAL; | ||
if (_isRelative && originalT === 1) { | ||
from[prop] = obj[prop]; | ||
} | ||
else if (typeof toValue === 'function') { | ||
obj[prop] = toValue(t); | ||
} | ||
return obj[prop]; | ||
} | ||
// Dot notation => Object structure converter | ||
} else if (typeof toValue === 'function') { | ||
obj[prop] = toValue(t); | ||
} | ||
return obj[prop]; | ||
} // Dot notation => Object structure converter | ||
// example | ||
// {'scale.x.y.z':'VALUE'} => {scale:{x:{y:{z:'VALUE'}}}} | ||
// Only works for 3-level parsing, after 3-level, parsing dot-notation not works as it's not affects | ||
var propRegExp = /([.\[])/g; | ||
var replaceBrace = /\]/g; | ||
var propExtract = function (obj, property) { | ||
var value = obj[property]; | ||
var props = property.replace(replaceBrace, '').split(propRegExp); | ||
var propsLastIndex = props.length - 1; | ||
var lastArr = Array.isArray(obj); | ||
var lastObj = typeof obj === 'object' && !lastArr; | ||
if (lastObj) { | ||
obj[property] = null; | ||
delete obj[property]; | ||
var propExtract = function propExtract(obj, property) { | ||
var value = obj[property]; | ||
var props = property.replace(replaceBrace, '').split(propRegExp); | ||
var propsLastIndex = props.length - 1; | ||
var lastArr = Array.isArray(obj); | ||
var lastObj = _typeof(obj) === 'object' && !lastArr; | ||
if (lastObj) { | ||
obj[property] = null; | ||
delete obj[property]; | ||
} else if (lastArr) { | ||
obj.splice(property, 1); | ||
} | ||
return props.reduce(function (nested, prop, index) { | ||
if (lastArr) { | ||
if (prop !== '.' && prop !== '[') { | ||
prop *= 1; | ||
} | ||
} | ||
else if (lastArr) { | ||
obj.splice(property, 1); | ||
var nextProp = props[index + 1]; | ||
var nextIsArray = nextProp === '['; | ||
if (prop === '.' || prop === '[') { | ||
if (prop === '.') { | ||
lastObj = true; | ||
lastArr = false; | ||
} else if (prop === '[') { | ||
lastObj = false; | ||
lastArr = true; | ||
} | ||
return nested; | ||
} else if (nested[prop] === undefined) { | ||
if (lastArr || lastObj) { | ||
nested[prop] = index === propsLastIndex ? value : lastArr || nextIsArray ? [] : lastObj ? {} : null; | ||
lastObj = lastArr = false; | ||
return nested[prop]; | ||
} | ||
} else if (nested[prop] !== undefined) { | ||
if (index === propsLastIndex) { | ||
nested[prop] = value; | ||
} | ||
return nested[prop]; | ||
} | ||
return props.reduce(function (nested, prop, index) { | ||
if (lastArr) { | ||
if (prop !== '.' && prop !== '[') { | ||
prop *= 1; | ||
} | ||
} | ||
var nextProp = props[index + 1]; | ||
var nextIsArray = nextProp === '['; | ||
if (prop === '.' || prop === '[') { | ||
if (prop === '.') { | ||
lastObj = true; | ||
lastArr = false; | ||
} | ||
else if (prop === '[') { | ||
lastObj = false; | ||
lastArr = true; | ||
} | ||
return nested; | ||
} | ||
else if (nested[prop] === undefined) { | ||
if (lastArr || lastObj) { | ||
nested[prop] = | ||
index === propsLastIndex | ||
? value | ||
: lastArr || nextIsArray ? [] : lastObj ? {} : null; | ||
lastObj = lastArr = false; | ||
return nested[prop]; | ||
} | ||
} | ||
else if (nested[prop] !== undefined) { | ||
if (index === propsLastIndex) { | ||
nested[prop] = value; | ||
} | ||
return nested[prop]; | ||
} | ||
return nested; | ||
}, obj); | ||
return nested; | ||
}, obj); | ||
}; | ||
var SET_NESTED = function (nested) { | ||
if (typeof nested === 'object' && !!nested) { | ||
for (var prop in nested) { | ||
if (prop.indexOf('.') !== -1 || prop.indexOf('[') !== -1) { | ||
propExtract(nested, prop); | ||
var SET_NESTED = function SET_NESTED(nested) { | ||
if (_typeof(nested) === 'object' && !!nested) { | ||
for (var prop in nested) { | ||
if (prop.indexOf('.') !== -1 || prop.indexOf('[') !== -1) { | ||
propExtract(nested, prop); | ||
} else if (_typeof(nested[prop]) === 'object' && !!nested[prop]) { | ||
var nested2 = nested[prop]; | ||
for (var prop2 in nested2) { | ||
if (prop2.indexOf('.') !== -1 || prop2.indexOf('[') !== -1) { | ||
propExtract(nested2, prop2); | ||
} else if (_typeof(nested2[prop2]) === 'object' && !!nested2[prop2]) { | ||
var nested3 = nested2[prop2]; | ||
for (var prop3 in nested3) { | ||
if (prop3.indexOf('.') !== -1 || prop3.indexOf('[') !== -1) { | ||
propExtract(nested3, prop3); | ||
} | ||
} | ||
else if (typeof nested[prop] === 'object' && !!nested[prop]) { | ||
var nested2 = nested[prop]; | ||
for (var prop2 in nested2) { | ||
if (prop2.indexOf('.') !== -1 || prop2.indexOf('[') !== -1) { | ||
propExtract(nested2, prop2); | ||
} | ||
else if (typeof nested2[prop2] === 'object' && !!nested2[prop2]) { | ||
var nested3 = nested2[prop2]; | ||
for (var prop3 in nested3) { | ||
if (prop3.indexOf('.') !== -1 || prop3.indexOf('[') !== -1) { | ||
propExtract(nested3, prop3); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return nested; | ||
} | ||
return nested; | ||
}; | ||
@@ -712,260 +994,261 @@ | ||
*/ | ||
var Interpolation = { | ||
Linear: function (v, k, value) { | ||
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, value); | ||
Linear: function Linear(v, k, value) { | ||
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, value); | ||
} | ||
if (k > 1) { | ||
return fn(v[m], v[m - 1], m - f, value); | ||
} | ||
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i, value); | ||
}, | ||
Bezier: function Bezier(v, k, value) { | ||
var b = Interpolation.Utils.Reset(value); | ||
var n = v.length - 1; | ||
var pw = Math.pow; | ||
var fn = Interpolation.Utils.Bernstein; | ||
var isBArray = Array.isArray(b); | ||
for (var i = 0; i <= n; i++) { | ||
if (typeof b === 'number') { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * fn(n, i); | ||
} else if (isBArray) { | ||
for (var p = 0, len = b.length; p < len; p++) { | ||
if (typeof b[p] === 'number') { | ||
b[p] += pw(1 - k, n - i) * pw(k, i) * v[i][p] * fn(n, i); | ||
} else { | ||
b[p] = v[i][p]; | ||
} | ||
} | ||
if (k > 1) { | ||
return fn(v[m], v[m - 1], m - f, value); | ||
} else if (_typeof(b) === 'object') { | ||
for (var _p in b) { | ||
if (typeof b[_p] === 'number') { | ||
b[_p] += pw(1 - k, n - i) * pw(k, i) * v[i][_p] * fn(n, i); | ||
} else { | ||
b[_p] = v[i][_p]; | ||
} | ||
} | ||
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i, value); | ||
}, | ||
Bezier: function (v, k, value) { | ||
var b = Interpolation.Utils.Reset(value); | ||
var n = v.length - 1; | ||
var pw = Math.pow; | ||
var fn = Interpolation.Utils.Bernstein; | ||
var isBArray = Array.isArray(b); | ||
for (var i = 0; i <= n; i++) { | ||
if (typeof b === 'number') { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * fn(n, i); | ||
} else if (typeof b === 'string') { | ||
var STRING_BUFFER = '', | ||
idx = Math.round(n * k), | ||
pidx = idx - 1 < 0 ? 0 : idx - 1, | ||
nidx = idx + 1 > n ? n : idx + 1, | ||
vCurr = v[idx]; | ||
for (var ks = 1, _len = vCurr.length; ks < _len; ks++) { | ||
STRING_BUFFER += vCurr[ks]; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
} | ||
return b; | ||
}, | ||
CatmullRom: function CatmullRom(v, k, value) { | ||
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, value); | ||
} else { | ||
if (k < 0) { | ||
return fn(v[1], v[1], v[0], v[0], -k, value); | ||
} | ||
if (k > 1) { | ||
return fn(v[m - 1], v[m - 1], v[m], v[m], (k | 0) - k, value); | ||
} | ||
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, value); | ||
} | ||
}, | ||
Utils: { | ||
Linear: function Linear(p0, p1, t, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} else if (typeof p0 === 'number') { | ||
return typeof p0 === 'function' ? p0(t) : p0 + (p1 - p0) * t; | ||
} else if (_typeof(p0) === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = p0.length; i < len; i++) { | ||
var currentValue = typeof p0[i] === 'number' ? p0[i] + (p1[i] - p0[i]) * t : p1[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
else if (isBArray) { | ||
for (var p = 0, len = b.length; p < len; p++) { | ||
if (typeof b[p] === 'number') { | ||
b[p] += pw(1 - k, n - i) * pw(k, i) * v[i][p] * fn(n, i); | ||
} | ||
else { | ||
b[p] = v[i][p]; | ||
} | ||
} | ||
} | ||
else if (typeof b === 'object') { | ||
for (var p in b) { | ||
if (typeof b[p] === 'number') { | ||
b[p] += pw(1 - k, n - i) * pw(k, i) * v[i][p] * fn(n, i); | ||
} | ||
else { | ||
b[p] = v[i][p]; | ||
} | ||
} | ||
} | ||
else if (typeof b === 'string') { | ||
var STRING_BUFFER = '', idx = Math.round(n * k), pidx = idx - 1 < 0 ? 0 : idx - 1, nidx = idx + 1 > n ? n : idx + 1, vCurr = v[idx]; | ||
for (var ks = 1, len = vCurr.length; ks < len; ks++) { | ||
STRING_BUFFER += vCurr[ks]; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (var p = 0, _len2 = v.length; p < _len2; p++) { | ||
v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
} | ||
} else { | ||
for (var _p2 in v) { | ||
v[_p2] = Interpolation.Utils.Linear(p0[_p2], p1[_p2], t, v[_p2]); | ||
} | ||
} | ||
return b; | ||
return v; | ||
} | ||
}, | ||
CatmullRom: function (v, k, value) { | ||
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, value); | ||
Reset: function Reset(value) { | ||
if (Array.isArray(value)) { | ||
for (var i = 0, len = value.length; i < len; i++) { | ||
value[i] = Interpolation.Utils.Reset(value[i]); | ||
} | ||
else { | ||
if (k < 0) { | ||
return fn(v[1], v[1], v[0], v[0], -k, value); | ||
} | ||
if (k > 1) { | ||
return fn(v[m - 1], v[m - 1], v[m], v[m], (k | 0) - k, value); | ||
} | ||
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, value); | ||
return value; | ||
} else if (_typeof(value) === 'object') { | ||
for (var _i in value) { | ||
value[_i] = Interpolation.Utils.Reset(value[_i]); | ||
} | ||
return value; | ||
} else if (typeof value === 'number') { | ||
return 0; | ||
} | ||
return value; | ||
}, | ||
Utils: { | ||
Linear: function (p0, p1, t, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
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, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} else if (typeof p0 === 'number') { | ||
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; | ||
} else if (_typeof(p0) === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = p0.length; i < len; i++) { | ||
var currentValue = typeof p0[i] === 'number' ? Interpolation.Utils.CatmullRom(p0[i], p1[i], p2[i], p3[i], t) : p3[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
else if (typeof p0 === 'number') { | ||
return typeof p0 === 'function' ? p0(t) : p0 + (p1 - p0) * t; | ||
} | ||
else if (typeof p0 === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = p0.length; i < len; i++) { | ||
var currentValue = typeof p0[i] === 'number' ? p0[i] + (p1[i] - p0[i]) * t : p1[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (var p = 0, len = v.length; p < len; p++) { | ||
v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
} | ||
} | ||
else { | ||
for (var p in v) { | ||
v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
} | ||
} | ||
return v; | ||
} | ||
}, | ||
Reset: function (value) { | ||
if (Array.isArray(value)) { | ||
for (var i = 0, len = value.length; i < len; i++) { | ||
value[i] = Interpolation.Utils.Reset(value[i]); | ||
} | ||
return value; | ||
} | ||
else if (typeof value === 'object') { | ||
for (var i in value) { | ||
value[i] = Interpolation.Utils.Reset(value[i]); | ||
} | ||
return value; | ||
} | ||
else if (typeof value === 'number') { | ||
return 0; | ||
} | ||
return value; | ||
}, | ||
Bernstein: function (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 (p0, p1, p2, p3, t, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} | ||
else if (typeof p0 === 'number') { | ||
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); | ||
} | ||
else if (typeof p0 === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = p0.length; i < len; i++) { | ||
var currentValue = typeof p0[i] === 'number' | ||
? Interpolation.Utils.CatmullRom(p0[i], p1[i], p2[i], p3[i], t) | ||
: p3[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (var p = 0, len = v.length; p < len; p++) { | ||
v[p] = Interpolation.Utils.CatmullRom(p0[p], p1[p], p2[p], p3[p], t, v[p]); | ||
} | ||
} | ||
else { | ||
for (var p in v) { | ||
v[p] = Interpolation.Utils.CatmullRom(p0[p], p1[p], p2[p], p3[p], t, v[p]); | ||
} | ||
} | ||
return v; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (var p = 0, _len3 = v.length; p < _len3; p++) { | ||
v[p] = Interpolation.Utils.CatmullRom(p0[p], p1[p], p2[p], p3[p], t, v[p]); | ||
} | ||
} else { | ||
for (var _p3 in v) { | ||
v[_p3] = Interpolation.Utils.CatmullRom(p0[_p3], p1[_p3], p2[_p3], p3[_p3], t, v[_p3]); | ||
} | ||
} | ||
return v; | ||
} | ||
} | ||
} | ||
}; | ||
var __assign$1 = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var Store = {}; | ||
var NodeCache = function (node, object, tween) { | ||
if (!node || !node.nodeType) { | ||
return object; | ||
} | ||
var ID = node.queueID || 'q_' + Date.now(); | ||
if (!node.queueID) { | ||
node.queueID = ID; | ||
} | ||
var storeID = Store[ID]; | ||
if (storeID) { | ||
if (storeID.object === object && | ||
node === storeID.tween.node && | ||
tween._startTime === storeID.tween._startTime) { | ||
remove(storeID.tween); | ||
if (!node || !node.nodeType) { | ||
return object; | ||
} | ||
var ID = node.queueID || 'q_' + Date.now(); | ||
if (!node.queueID) { | ||
node.queueID = ID; | ||
} | ||
var storeID = Store[ID]; | ||
if (storeID) { | ||
if (storeID.object === object && node === storeID.tween.node && tween._startTime === storeID.tween._startTime) { | ||
remove(storeID.tween); | ||
} else if (_typeof(object) === 'object' && !!object && !!storeID.object) { | ||
for (var prop in object) { | ||
if (prop in storeID.object) { | ||
if (tween._startTime === storeID.tween._startTime) { | ||
delete storeID.object[prop]; | ||
} else { | ||
storeID.propNormaliseRequired = true; | ||
} | ||
} | ||
else if (typeof object === 'object' && !!object && !!storeID.object) { | ||
for (var prop in object) { | ||
if (prop in storeID.object) { | ||
if (tween._startTime === storeID.tween._startTime) { | ||
delete storeID.object[prop]; | ||
} | ||
else { | ||
storeID.propNormaliseRequired = true; | ||
} | ||
} | ||
} | ||
storeID.object = __assign$1({}, storeID.object, object); | ||
} | ||
return storeID.object; | ||
} | ||
storeID.object = _objectSpread({}, storeID.object, object); | ||
} | ||
if (typeof object === 'object' && !!object) { | ||
Store[ID] = { tween: tween, object: object, propNormaliseRequired: false }; | ||
return Store[ID].object; | ||
} | ||
return object; | ||
return storeID.object; | ||
} | ||
if (_typeof(object) === 'object' && !!object) { | ||
Store[ID] = { | ||
tween: tween, | ||
object: object, | ||
propNormaliseRequired: false | ||
}; | ||
return Store[ID].object; | ||
} | ||
return object; | ||
}; | ||
var Selector = function (selector, collection) { | ||
if (collection) { | ||
return !selector | ||
? null | ||
: selector === window || selector === document | ||
? [selector] | ||
: typeof selector === 'string' | ||
? !!document.querySelectorAll && document.querySelectorAll(selector) | ||
: Array.isArray(selector) | ||
? selector | ||
: selector.nodeType ? [selector] : []; | ||
} | ||
return !selector | ||
? null | ||
: selector === window || selector === document | ||
? selector | ||
: typeof selector === 'string' | ||
? !!document.querySelector && document.querySelector(selector) | ||
: Array.isArray(selector) | ||
? selector[0] | ||
: selector.nodeType ? selector : null; | ||
if (collection) { | ||
return !selector ? null : selector === window || selector === document ? [selector] : typeof selector === 'string' ? !!document.querySelectorAll && document.querySelectorAll(selector) : Array.isArray(selector) ? selector : selector.nodeType ? [selector] : []; | ||
} | ||
return !selector ? null : selector === window || selector === document ? selector : typeof selector === 'string' ? !!document.querySelector && document.querySelector(selector) : Array.isArray(selector) ? selector[0] : selector.nodeType ? selector : null; | ||
}; | ||
var _id = 0; // Unique ID | ||
var defaultEasing = Easing.Linear.None; | ||
@@ -981,36 +1264,9 @@ /** | ||
*/ | ||
var Tween = /** @class */ (function () { | ||
function Tween(node, object) { | ||
this._chainedTweensCount = 0; | ||
this.id = _id++; | ||
if (!!node && typeof node === 'object' && !object && !node.nodeType) { | ||
object = this.object = node; | ||
node = null; | ||
} | ||
else if (!!node && | ||
(node.nodeType || node.length || typeof node === 'string')) { | ||
node = this.node = Selector(node); | ||
object = this.object = NodeCache(node, object, this); | ||
} | ||
this._valuesEnd = null; | ||
this._valuesStart = {}; | ||
this._duration = 1000; | ||
this._easingFunction = defaultEasing; | ||
this._easingReverse = defaultEasing; | ||
this._interpolationFunction = Interpolation.Linear; | ||
this._startTime = 0; | ||
this._initTime = 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._maxListener = 15; | ||
this._prevTime = null; | ||
return this; | ||
} | ||
var Tween = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Tween, null, [{ | ||
key: "fromTo", | ||
/** | ||
@@ -1026,13 +1282,15 @@ * Easier way to call the Tween | ||
*/ | ||
Tween.fromTo = function (node, object, to, params) { | ||
if (params === void 0) { params = {}; } | ||
params.quickRender = params.quickRender ? params.quickRender : !to; | ||
var tween = new Tween(node, object).to(to, params); | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime); | ||
tween._rendered = false; | ||
tween._onStartCallbackFired = false; | ||
} | ||
return tween; | ||
}; | ||
value: function fromTo(node, object, to) { | ||
var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
params.quickRender = params.quickRender ? params.quickRender : !to; | ||
var tween = new Tween(node, object).to(to, params); | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime); | ||
tween._rendered = false; | ||
tween._onStartCallbackFired = false; | ||
} | ||
return tween; | ||
} | ||
/** | ||
@@ -1047,5 +1305,8 @@ * Easier way calling constructor only applies the `to` value, useful for CSS Animation | ||
*/ | ||
Tween.to = function (node, to, params) { | ||
return Tween.fromTo(node, null, to, params); | ||
}; | ||
}, { | ||
key: "to", | ||
value: function to(node, _to, params) { | ||
return Tween.fromTo(node, null, _to, params); | ||
} | ||
/** | ||
@@ -1060,16 +1321,65 @@ * Easier way calling constructor only applies the `from` value, useful for CSS Animation | ||
*/ | ||
Tween.from = function (node, from, params) { | ||
return Tween.fromTo(node, from, null, params); | ||
}; | ||
}, { | ||
key: "from", | ||
value: function from(node, _from, params) { | ||
return Tween.fromTo(node, _from, null, params); | ||
} | ||
}]); | ||
function Tween(node, object) { | ||
_classCallCheck(this, Tween); | ||
Object.defineProperty(this, "_chainedTweensCount", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: 0 | ||
}); | ||
this.id = _id++; | ||
if (!!node && _typeof(node) === 'object' && !object && !node.nodeType) { | ||
object = this.object = node; | ||
node = null; | ||
} else if (!!node && (node.nodeType || node.length || typeof node === 'string')) { | ||
node = this.node = Selector(node); | ||
object = this.object = NodeCache(node, object, this); | ||
} | ||
this._valuesEnd = null; | ||
this._valuesStart = {}; | ||
this._duration = 1000; | ||
this._easingFunction = defaultEasing; | ||
this._easingReverse = defaultEasing; | ||
this._interpolationFunction = Interpolation.Linear; | ||
this._startTime = 0; | ||
this._initTime = 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._maxListener = 15; | ||
this._prevTime = null; | ||
return this; | ||
} | ||
/** | ||
* Sets max `event` listener's count to Events system | ||
* @param {number} count - Event listener's count | ||
* @memberof TWEEN.Tween | ||
*/ | ||
_createClass(Tween, [{ | ||
key: "setMaxListener", | ||
value: function setMaxListener() { | ||
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 15; | ||
this._maxListener = count; | ||
return this; | ||
} | ||
/** | ||
* Sets max `event` listener's count to Events system | ||
* @param {number} count - Event listener's count | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.setMaxListener = function (count) { | ||
if (count === void 0) { count = 15; } | ||
this._maxListener = count; | ||
return this; | ||
}; | ||
/** | ||
* Adds `event` to Events system | ||
@@ -1080,14 +1390,20 @@ * @param {string} event - Event listener name | ||
*/ | ||
Tween.prototype.on = function (event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (!this[callbackId]) { | ||
this[callbackId] = callback; | ||
break; | ||
} | ||
}, { | ||
key: "on", | ||
value: function on(event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (!this[callbackId]) { | ||
this[callbackId] = callback; | ||
break; | ||
} | ||
return this; | ||
}; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1100,5 +1416,8 @@ * Adds `event` to Events system. | ||
*/ | ||
Tween.prototype.once = function (event, callback) { | ||
return this; | ||
}; | ||
}, { | ||
key: "once", | ||
value: function once(event, callback) { | ||
return this; | ||
} | ||
/** | ||
@@ -1110,13 +1429,19 @@ * Removes `event` from Events system | ||
*/ | ||
Tween.prototype.off = function (event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId] === callback) { | ||
this[callbackId] = null; | ||
} | ||
}, { | ||
key: "off", | ||
value: function off(event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId] === callback) { | ||
this[callbackId] = null; | ||
} | ||
return this; | ||
}; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1127,16 +1452,23 @@ * Emits/Fired/Trigger `event` from Events system listeners | ||
*/ | ||
Tween.prototype.emit = function (event, arg1, arg2, arg3, arg4) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
if (!this[callbackName + 0]) { | ||
return this; | ||
}, { | ||
key: "emit", | ||
value: function emit(event, arg1, arg2, arg3, arg4) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
if (!this[callbackName + 0]) { | ||
return this; | ||
} | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId]) { | ||
this[callbackId](arg1, arg2, arg3, arg4); | ||
} | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId]) { | ||
this[callbackId](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
return this; | ||
}; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1147,5 +1479,8 @@ * @return {boolean} State of playing of tween | ||
*/ | ||
Tween.prototype.isPlaying = function () { | ||
return this._isPlaying; | ||
}; | ||
}, { | ||
key: "isPlaying", | ||
value: function isPlaying() { | ||
return this._isPlaying; | ||
} | ||
/** | ||
@@ -1156,5 +1491,8 @@ * @return {boolean} State of started of tween | ||
*/ | ||
Tween.prototype.isStarted = function () { | ||
return this._onStartCallbackFired; | ||
}; | ||
}, { | ||
key: "isStarted", | ||
value: function isStarted() { | ||
return this._onStartCallbackFired; | ||
} | ||
/** | ||
@@ -1166,7 +1504,10 @@ * Reverses the tween state/direction | ||
*/ | ||
Tween.prototype.reverse = function (state) { | ||
var _reversed = this._reversed; | ||
this._reversed = state !== undefined ? state : !_reversed; | ||
return this; | ||
}; | ||
}, { | ||
key: "reverse", | ||
value: function reverse(state) { | ||
var _reversed = this._reversed; | ||
this._reversed = state !== undefined ? state : !_reversed; | ||
return this; | ||
} | ||
/** | ||
@@ -1177,5 +1518,8 @@ * @return {boolean} State of reversed | ||
*/ | ||
Tween.prototype.reversed = function () { | ||
return this._reversed; | ||
}; | ||
}, { | ||
key: "reversed", | ||
value: function reversed() { | ||
return this._reversed; | ||
} | ||
/** | ||
@@ -1186,11 +1530,15 @@ * Pauses tween | ||
*/ | ||
Tween.prototype.pause = function () { | ||
if (!this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PAUSE, this.object); | ||
}; | ||
}, { | ||
key: "pause", | ||
value: function pause() { | ||
if (!this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PAUSE, this.object); | ||
} | ||
/** | ||
@@ -1201,13 +1549,17 @@ * Play/Resume the tween | ||
*/ | ||
Tween.prototype.play = function () { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
this._initTime = this._startTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PLAY, this.object); | ||
}; | ||
}, { | ||
key: "play", | ||
value: function play() { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
this._initTime = this._startTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PLAY, this.object); | ||
} | ||
/** | ||
@@ -1219,8 +1571,11 @@ * Restarts tween from initial value | ||
*/ | ||
Tween.prototype.restart = function (noDelay) { | ||
this._repeat = this._r; | ||
this.reassignValues(); | ||
add(this); | ||
return this.emit(EVENT_RESTART, this.object); | ||
}; | ||
}, { | ||
key: "restart", | ||
value: function restart(noDelay) { | ||
this._repeat = this._r; | ||
this.reassignValues(); | ||
add(this); | ||
return this.emit(EVENT_RESTART, this.object); | ||
} | ||
/** | ||
@@ -1234,14 +1589,24 @@ * Seek tween value by `time`. Note: Not works as excepted. PR are welcome | ||
*/ | ||
Tween.prototype.seek = function (time, keepPlaying) { | ||
var _a = this, _duration = _a._duration, _repeat = _a._repeat, _initTime = _a._initTime, _startTime = _a._startTime, _delayTime = _a._delayTime, _reversed = _a._reversed; | ||
var updateTime = _initTime + time; | ||
this._isPlaying = true; | ||
if (updateTime < _startTime && _startTime >= _initTime) { | ||
this._startTime -= _duration; | ||
this._reversed = !_reversed; | ||
} | ||
this.update(time, false); | ||
this.emit(EVENT_SEEK, time, this.object); | ||
return keepPlaying ? this : this.pause(); | ||
}; | ||
}, { | ||
key: "seek", | ||
value: function seek(time, keepPlaying) { | ||
var _duration = this._duration, | ||
_repeat = this._repeat, | ||
_initTime = this._initTime, | ||
_startTime = this._startTime, | ||
_delayTime = this._delayTime, | ||
_reversed = this._reversed; | ||
var updateTime = _initTime + time; | ||
this._isPlaying = true; | ||
if (updateTime < _startTime && _startTime >= _initTime) { | ||
this._startTime -= _duration; | ||
this._reversed = !_reversed; | ||
} | ||
this.update(time, false); | ||
this.emit(EVENT_SEEK, time, this.object); | ||
return keepPlaying ? this : this.pause(); | ||
} | ||
/** | ||
@@ -1253,7 +1618,9 @@ * Sets tween duration | ||
*/ | ||
Tween.prototype.duration = function (amount) { | ||
this._duration = | ||
typeof amount === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
}; | ||
}, { | ||
key: "duration", | ||
value: function duration(amount) { | ||
this._duration = typeof amount === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
} | ||
/** | ||
@@ -1266,19 +1633,32 @@ * Sets target value and duration | ||
*/ | ||
Tween.prototype.to = function (properties, duration, maybeUsed) { | ||
if (duration === void 0) { duration = 1000; } | ||
this._valuesEnd = properties; | ||
if (typeof duration === 'number' || typeof duration === 'function') { | ||
this._duration = | ||
typeof duration === 'function' ? duration(this._duration) : duration; | ||
}, { | ||
key: "to", | ||
value: function to(properties) { | ||
var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000; | ||
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 (var prop in duration) { | ||
if (typeof this[prop] === 'function') { | ||
var _ref = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]], | ||
_ref2 = _slicedToArray(_ref, 4), | ||
_ref2$ = _ref2[0], | ||
arg1 = _ref2$ === void 0 ? null : _ref2$, | ||
_ref2$2 = _ref2[1], | ||
arg2 = _ref2$2 === void 0 ? null : _ref2$2, | ||
_ref2$3 = _ref2[2], | ||
arg3 = _ref2$3 === void 0 ? null : _ref2$3, | ||
_ref2$4 = _ref2[3], | ||
arg4 = _ref2$4 === void 0 ? null : _ref2$4; | ||
this[prop](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
else if (typeof duration === 'object') { | ||
for (var prop in duration) { | ||
if (typeof this[prop] === 'function') { | ||
var _a = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]], _b = _a[0], arg1 = _b === void 0 ? null : _b, _c = _a[1], arg2 = _c === void 0 ? null : _c, _d = _a[2], arg3 = _d === void 0 ? null : _d, _e = _a[3], arg4 = _e === void 0 ? null : _e; | ||
this[prop](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1289,75 +1669,91 @@ * Renders and computes value at first render | ||
*/ | ||
Tween.prototype.render = function () { | ||
if (this._rendered) { | ||
return this; | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
if (this._rendered) { | ||
return this; | ||
} | ||
var _valuesStart = this._valuesStart, | ||
_valuesEnd = this._valuesEnd, | ||
object = this.object, | ||
node = this.node, | ||
InitialValues = this.InitialValues; | ||
SET_NESTED(object); | ||
SET_NESTED(_valuesEnd); | ||
if (node && node.queueID && Store[node.queueID]) { | ||
var prevTweenByNode = Store[node.queueID]; | ||
if (prevTweenByNode.propNormaliseRequired && prevTweenByNode.tween !== this) { | ||
prevTweenByNode.normalisedProp = true; | ||
prevTweenByNode.propNormaliseRequired = false; | ||
} | ||
var _a = this, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, node = _a.node, InitialValues = _a.InitialValues; | ||
SET_NESTED(object); | ||
SET_NESTED(_valuesEnd); | ||
if (node && node.queueID && Store[node.queueID]) { | ||
var prevTweenByNode = Store[node.queueID]; | ||
if (prevTweenByNode.propNormaliseRequired && | ||
prevTweenByNode.tween !== this) { | ||
for (var property in _valuesEnd) { | ||
} | ||
prevTweenByNode.normalisedProp = true; | ||
prevTweenByNode.propNormaliseRequired = false; | ||
} | ||
} | ||
if (node && InitialValues) { | ||
if (!object || Object.keys(object).length === 0) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd), this); | ||
} else if (!_valuesEnd || Object.keys(_valuesEnd).length === 0) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
} | ||
if (node && InitialValues) { | ||
if (!object || Object.keys(object).length === 0) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd), this); | ||
} | ||
else if (!_valuesEnd || Object.keys(_valuesEnd).length === 0) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
} | ||
} | ||
for (var _property in _valuesEnd) { | ||
var start = object && object[_property] && deepCopy(object[_property]); | ||
var end = _valuesEnd[_property]; | ||
if (Plugins[_property] && Plugins[_property].init) { | ||
Plugins[_property].init.call(this, start, end, _property, object); | ||
if (start === undefined && _valuesStart[_property]) { | ||
start = _valuesStart[_property]; | ||
} | ||
if (Plugins[_property].skipProcess) { | ||
continue; | ||
} | ||
} | ||
for (var property in _valuesEnd) { | ||
var start = object && object[property] && deepCopy(object[property]); | ||
var end = _valuesEnd[property]; | ||
if (Plugins[property] && Plugins[property].init) { | ||
Plugins[property].init.call(this, start, end, property, object); | ||
if (start === undefined && _valuesStart[property]) { | ||
start = _valuesStart[property]; | ||
} | ||
if (Plugins[property].skipProcess) { | ||
continue; | ||
} | ||
if (typeof start === 'number' && isNaN(start) || start === null || end === null || start === false || end === false || start === undefined || end === undefined || start === end) { | ||
continue; | ||
} | ||
if (Array.isArray(end) && !Array.isArray(start)) { | ||
end.unshift(start); | ||
for (var i = 0, len = end.length; i < len; i++) { | ||
if (typeof end[i] === 'string') { | ||
var arrayOfStrings = decomposeString(end[i]); | ||
var stringObject = { | ||
length: arrayOfStrings.length, | ||
isString: true | ||
}; | ||
for (var ii = 0, len2 = arrayOfStrings.length; ii < len2; ii++) { | ||
stringObject[ii] = arrayOfStrings[ii]; | ||
} | ||
end[i] = stringObject; | ||
} | ||
if ((typeof start === 'number' && isNaN(start)) || | ||
start === null || | ||
end === null || | ||
start === false || | ||
end === false || | ||
start === undefined || | ||
end === undefined || | ||
start === end) { | ||
continue; | ||
} | ||
if (Array.isArray(end) && !Array.isArray(start)) { | ||
end.unshift(start); | ||
for (var i = 0, len = end.length; i < len; i++) { | ||
if (typeof end[i] === 'string') { | ||
var arrayOfStrings = decomposeString(end[i]); | ||
var stringObject = { length: arrayOfStrings.length, isString: true }; | ||
for (var ii = 0, len2 = arrayOfStrings.length; ii < len2; ii++) { | ||
stringObject[ii] = arrayOfStrings[ii]; | ||
} | ||
end[i] = stringObject; | ||
} | ||
} | ||
} | ||
_valuesStart[property] = start; | ||
if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { | ||
continue; | ||
} | ||
decompose(property, object, _valuesStart, _valuesEnd); | ||
} | ||
} | ||
if (Tween.Renderer && this.node && Tween.Renderer.init) { | ||
Tween.Renderer.init.call(this, object, _valuesStart, _valuesEnd); | ||
this.__render = true; | ||
_valuesStart[_property] = start; | ||
if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { | ||
continue; | ||
} | ||
return this; | ||
}; | ||
decompose(_property, object, _valuesStart, _valuesEnd); | ||
} | ||
if (Tween.Renderer && this.node && Tween.Renderer.init) { | ||
Tween.Renderer.init.call(this, object, _valuesStart, _valuesEnd); | ||
this.__render = true; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1369,15 +1765,15 @@ * Start the tweening | ||
*/ | ||
Tween.prototype.start = function (time) { | ||
this._startTime = | ||
time !== undefined | ||
? typeof time === 'string' ? now() + parseFloat(time) : time | ||
: now(); | ||
this._startTime += this._delayTime; | ||
this._initTime = this._prevTime = this._startTime; | ||
this._onStartCallbackFired = false; | ||
this._rendered = false; | ||
this._isPlaying = true; | ||
add(this); | ||
return this; | ||
}; | ||
}, { | ||
key: "start", | ||
value: function start(time) { | ||
this._startTime = time !== undefined ? typeof time === 'string' ? now() + parseFloat(time) : time : now(); | ||
this._startTime += this._delayTime; | ||
this._initTime = this._prevTime = this._startTime; | ||
this._onStartCallbackFired = false; | ||
this._rendered = false; | ||
this._isPlaying = true; | ||
add(this); | ||
return this; | ||
} | ||
/** | ||
@@ -1388,18 +1784,32 @@ * Stops the tween | ||
*/ | ||
Tween.prototype.stop = function () { | ||
var _a = this, _isPlaying = _a._isPlaying, _isFinite = _a._isFinite, object = _a.object, _startTime = _a._startTime, _delayTime = _a._delayTime, _duration = _a._duration, _r = _a._r, _yoyo = _a._yoyo, _reversed = _a._reversed; | ||
if (!_isPlaying) { | ||
return this; | ||
} | ||
var atStart = _isFinite ? (_r + 1) % 2 === 1 : !_reversed; | ||
this._reversed = false; | ||
if (_yoyo && atStart) { | ||
this.update(_startTime); | ||
} | ||
else { | ||
this.update(_startTime + _duration); | ||
} | ||
remove(this); | ||
return this.emit(EVENT_STOP, object); | ||
}; | ||
}, { | ||
key: "stop", | ||
value: function stop() { | ||
var _isPlaying = this._isPlaying, | ||
_isFinite = this._isFinite, | ||
object = this.object, | ||
_startTime = this._startTime, | ||
_delayTime = this._delayTime, | ||
_duration = this._duration, | ||
_r = this._r, | ||
_yoyo = this._yoyo, | ||
_reversed = this._reversed; | ||
if (!_isPlaying) { | ||
return this; | ||
} | ||
var atStart = _isFinite ? (_r + 1) % 2 === 1 : !_reversed; | ||
this._reversed = false; | ||
if (_yoyo && atStart) { | ||
this.update(_startTime); | ||
} else { | ||
this.update(_startTime + _duration); | ||
} | ||
remove(this); | ||
return this.emit(EVENT_STOP, object); | ||
} | ||
/** | ||
@@ -1411,7 +1821,9 @@ * Set delay of tween | ||
*/ | ||
Tween.prototype.delay = function (amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
}; | ||
}, { | ||
key: "delay", | ||
value: function delay(amount) { | ||
this._delayTime = typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
@@ -1423,12 +1835,18 @@ * Chained tweens | ||
*/ | ||
Tween.prototype.chainedTweens = function () { | ||
this._chainedTweensCount = arguments.length; | ||
if (!this._chainedTweensCount) { | ||
return this; | ||
} | ||
for (var i = 0, len = this._chainedTweensCount; i < len; i++) { | ||
this[CHAINED_TWEENS + i] = arguments[i]; | ||
} | ||
}, { | ||
key: "chainedTweens", | ||
value: function chainedTweens() { | ||
this._chainedTweensCount = arguments.length; | ||
if (!this._chainedTweensCount) { | ||
return this; | ||
}; | ||
} | ||
for (var i = 0, len = this._chainedTweensCount; i < len; i++) { | ||
this[CHAINED_TWEENS + i] = arguments[i]; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1440,10 +1858,11 @@ * Sets how times tween is repeating | ||
*/ | ||
Tween.prototype.repeat = function (amount) { | ||
this._repeat = !this._duration | ||
? 0 | ||
: typeof amount === 'function' ? amount(this._repeat) : amount; | ||
this._r = this._repeat; | ||
this._isFinite = isFinite(amount); | ||
return this; | ||
}; | ||
}, { | ||
key: "repeat", | ||
value: function repeat(amount) { | ||
this._repeat = !this._duration ? 0 : typeof amount === 'function' ? amount(this._repeat) : amount; | ||
this._r = this._repeat; | ||
this._isFinite = isFinite(amount); | ||
return this; | ||
} | ||
/** | ||
@@ -1455,7 +1874,9 @@ * Set delay of each repeat alternate of tween | ||
*/ | ||
Tween.prototype.reverseDelay = function (amount) { | ||
this._reverseDelayTime = | ||
typeof amount === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
}; | ||
}, { | ||
key: "reverseDelay", | ||
value: function reverseDelay(amount) { | ||
this._reverseDelayTime = typeof amount === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
@@ -1468,13 +1889,15 @@ * Set `yoyo` state (enables reverse in repeat) | ||
*/ | ||
Tween.prototype.yoyo = function (state, _easingReverse) { | ||
this._yoyo = | ||
typeof state === 'function' | ||
? state(this._yoyo) | ||
: state === null ? this._yoyo : state; | ||
if (!state) { | ||
this._reversed = false; | ||
} | ||
this._easingReverse = _easingReverse || null; | ||
return this; | ||
}; | ||
}, { | ||
key: "yoyo", | ||
value: function yoyo(state, _easingReverse) { | ||
this._yoyo = typeof state === 'function' ? state(this._yoyo) : state === null ? this._yoyo : state; | ||
if (!state) { | ||
this._reversed = false; | ||
} | ||
this._easingReverse = _easingReverse || null; | ||
return this; | ||
} | ||
/** | ||
@@ -1486,6 +1909,9 @@ * Set easing | ||
*/ | ||
Tween.prototype.easing = function (_easingFunction) { | ||
this._easingFunction = _easingFunction; | ||
return this; | ||
}; | ||
}, { | ||
key: "easing", | ||
value: function easing(_easingFunction) { | ||
this._easingFunction = _easingFunction; | ||
return this; | ||
} | ||
/** | ||
@@ -1497,8 +1923,12 @@ * Set interpolation | ||
*/ | ||
Tween.prototype.interpolation = function (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
}; | ||
}, { | ||
key: "interpolation", | ||
value: function interpolation(_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1509,15 +1939,22 @@ * Reassigns value for rare-case like Tween#restart or for Timeline | ||
*/ | ||
Tween.prototype.reassignValues = function (time) { | ||
var _a = this, _valuesStart = _a._valuesStart, object = _a.object, _delayTime = _a._delayTime; | ||
this._isPlaying = true; | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += _delayTime; | ||
this._reversed = false; | ||
add(this); | ||
for (var property in _valuesStart) { | ||
var start = _valuesStart[property]; | ||
object[property] = start; | ||
} | ||
return this; | ||
}; | ||
}, { | ||
key: "reassignValues", | ||
value: function reassignValues(time) { | ||
var _valuesStart = this._valuesStart, | ||
object = this.object, | ||
_delayTime = this._delayTime; | ||
this._isPlaying = true; | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += _delayTime; | ||
this._reversed = false; | ||
add(this); | ||
for (var property in _valuesStart) { | ||
var start = _valuesStart[property]; | ||
object[property] = start; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -1531,143 +1968,165 @@ * Updates initial object to target value by given `time` | ||
*/ | ||
Tween.prototype.update = function (time, preserve, forceTime) { | ||
var _a = this, _onStartCallbackFired = _a._onStartCallbackFired, _easingFunction = _a._easingFunction, _interpolationFunction = _a._interpolationFunction, _easingReverse = _a._easingReverse, _repeat = _a._repeat, _delayTime = _a._delayTime, _reverseDelayTime = _a._reverseDelayTime, _yoyo = _a._yoyo, _reversed = _a._reversed, _startTime = _a._startTime, _prevTime = _a._prevTime, _duration = _a._duration, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying, __render = _a.__render, _chainedTweensCount = _a._chainedTweensCount; | ||
var elapsed; | ||
var currentEasing; | ||
var property; | ||
var propCount = 0; | ||
if (!_duration) { | ||
elapsed = 1; | ||
_repeat = 0; | ||
}, { | ||
key: "update", | ||
value: function update$$1(time, preserve, forceTime) { | ||
var _onStartCallbackFired = this._onStartCallbackFired, | ||
_easingFunction = this._easingFunction, | ||
_interpolationFunction = this._interpolationFunction, | ||
_easingReverse = this._easingReverse, | ||
_repeat = this._repeat, | ||
_delayTime = this._delayTime, | ||
_reverseDelayTime = this._reverseDelayTime, | ||
_yoyo = this._yoyo, | ||
_reversed = this._reversed, | ||
_startTime = this._startTime, | ||
_prevTime = this._prevTime, | ||
_duration = this._duration, | ||
_valuesStart = this._valuesStart, | ||
_valuesEnd = this._valuesEnd, | ||
object = this.object, | ||
_isFinite = this._isFinite, | ||
_isPlaying = this._isPlaying, | ||
__render = this.__render, | ||
_chainedTweensCount = this._chainedTweensCount; | ||
var elapsed; | ||
var currentEasing; | ||
var property; | ||
var propCount = 0; | ||
if (!_duration) { | ||
elapsed = 1; | ||
_repeat = 0; | ||
} else { | ||
time = time !== undefined ? time : now(); | ||
var delta = time - _prevTime; | ||
this._prevTime = time; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
time -= delta - FRAME_MS; | ||
} | ||
else { | ||
time = time !== undefined ? time : now(); | ||
var delta = time - _prevTime; | ||
this._prevTime = time; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
time -= delta - FRAME_MS; | ||
} | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
return true; | ||
} | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
if (!_isPlaying || time < _startTime && !forceTime) { | ||
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; | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (!this._rendered) { | ||
this.render(); | ||
this._rendered = true; | ||
} | ||
currentEasing = _reversed | ||
? _easingReverse || _easingFunction | ||
: _easingFunction; | ||
if (!object) { | ||
return true; | ||
this.emit(EVENT_START, object); | ||
this._onStartCallbackFired = true; | ||
} | ||
currentEasing = _reversed ? _easingReverse || _easingFunction : _easingFunction; | ||
if (!object) { | ||
return true; | ||
} | ||
for (property in _valuesEnd) { | ||
var start = _valuesStart[property]; | ||
if ((start === undefined || start === null) && !(Plugins[property] && Plugins[property].update)) { | ||
continue; | ||
} | ||
for (property in _valuesEnd) { | ||
var start = _valuesStart[property]; | ||
if ((start === undefined || start === null) && | ||
!(Plugins[property] && Plugins[property].update)) { | ||
continue; | ||
} | ||
var end = _valuesEnd[property]; | ||
var value = currentEasing[property] | ||
? currentEasing[property](elapsed) | ||
: typeof currentEasing === 'function' | ||
? currentEasing(elapsed) | ||
: defaultEasing(elapsed); | ||
var _interpolationFunctionCall = _interpolationFunction[property] | ||
? _interpolationFunction[property] | ||
: typeof _interpolationFunction === 'function' | ||
? _interpolationFunction | ||
: Interpolation.Linear; | ||
if (typeof end === 'number') { | ||
object[property] = | ||
(((start + (end - start) * value) * DECIMAL) | 0) / DECIMAL; | ||
} | ||
else if (Array.isArray(end) && !Array.isArray(start)) { | ||
object[property] = _interpolationFunctionCall(end, value, object[property]); | ||
} | ||
else if (end && end.update) { | ||
end.update(value); | ||
} | ||
else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} | ||
else if (typeof end === 'string' && typeof start === 'number') { | ||
object[property] = start + parseFloat(end[0] + end.substr(2)) * value; | ||
} | ||
else { | ||
recompose(property, object, _valuesStart, _valuesEnd, value, elapsed); | ||
} | ||
if (Plugins[property] && Plugins[property].update) { | ||
Plugins[property].update.call(this, object[property], start, end, value, elapsed, property); | ||
} | ||
propCount++; | ||
var end = _valuesEnd[property]; | ||
var value = currentEasing[property] ? currentEasing[property](elapsed) : typeof currentEasing === 'function' ? currentEasing(elapsed) : defaultEasing(elapsed); | ||
var _interpolationFunctionCall = _interpolationFunction[property] ? _interpolationFunction[property] : typeof _interpolationFunction === 'function' ? _interpolationFunction : Interpolation.Linear; | ||
if (typeof end === 'number') { | ||
object[property] = ((start + (end - start) * value) * DECIMAL | 0) / DECIMAL; | ||
} else if (Array.isArray(end) && !Array.isArray(start)) { | ||
object[property] = _interpolationFunctionCall(end, value, object[property]); | ||
} else if (end && end.update) { | ||
end.update(value); | ||
} else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} else if (typeof end === 'string' && typeof start === 'number') { | ||
object[property] = start + parseFloat(end[0] + end.substr(2)) * value; | ||
} else { | ||
recompose(property, object, _valuesStart, _valuesEnd, value, elapsed); | ||
} | ||
if (!propCount) { | ||
remove(this); | ||
return false; | ||
if (Plugins[property] && Plugins[property].update) { | ||
Plugins[property].update.call(this, object[property], start, end, value, elapsed, property); | ||
} | ||
if (__render && Tween.Renderer && Tween.Renderer.update) { | ||
Tween.Renderer.update.call(this, object, elapsed); | ||
} | ||
this.emit(EVENT_UPDATE, object, elapsed, time); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat > 0 && _duration > 0) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
} | ||
else { | ||
for (property in _valuesEnd) { | ||
var end = _valuesEnd[property]; | ||
if (typeof end === 'string' && typeof _valuesStart[property] === 'number') { | ||
_valuesStart[property] += parseFloat(end[0] + end.substr(2)); | ||
} | ||
} | ||
} | ||
this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object); | ||
if (_reversed && _reverseDelayTime) { | ||
this._startTime = time - _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime = time + _delayTime; | ||
} | ||
return true; | ||
propCount++; | ||
} | ||
if (!propCount) { | ||
remove(this); | ||
return false; | ||
} | ||
if (__render && Tween.Renderer && Tween.Renderer.update) { | ||
Tween.Renderer.update.call(this, object, elapsed); | ||
} | ||
this.emit(EVENT_UPDATE, object, elapsed, time); | ||
if (elapsed === 1 || _reversed && elapsed === 0) { | ||
if (_repeat > 0 && _duration > 0) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
} else { | ||
for (property in _valuesEnd) { | ||
var _end = _valuesEnd[property]; | ||
if (typeof _end === 'string' && typeof _valuesStart[property] === 'number') { | ||
_valuesStart[property] += parseFloat(_end[0] + _end.substr(2)); | ||
} | ||
} | ||
else { | ||
if (!preserve) { | ||
this._isPlaying = false; | ||
remove(this); | ||
_id--; | ||
} | ||
this.emit(EVENT_COMPLETE, object); | ||
this._repeat = this._r; | ||
if (_chainedTweensCount) { | ||
for (var i = 0; i < _chainedTweensCount; i++) { | ||
this[CHAINED_TWEENS + i].start(time + _duration); | ||
} | ||
} | ||
return false; | ||
} | ||
this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object); | ||
if (_reversed && _reverseDelayTime) { | ||
this._startTime = time - _reverseDelayTime; | ||
} else { | ||
this._startTime = time + _delayTime; | ||
} | ||
return true; | ||
} else { | ||
if (!preserve) { | ||
this._isPlaying = false; | ||
remove(this); | ||
_id--; | ||
} | ||
this.emit(EVENT_COMPLETE, object); | ||
this._repeat = this._r; | ||
if (_chainedTweensCount) { | ||
for (var i = 0; i < _chainedTweensCount; i++) { | ||
this[CHAINED_TWEENS + i].start(time + _duration); | ||
} | ||
} | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return Tween; | ||
}()); | ||
} | ||
var __assign$2 = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
return true; | ||
} | ||
return t; | ||
}; | ||
}]); | ||
return Tween; | ||
}(); | ||
/** | ||
@@ -1681,50 +2140,54 @@ * Tween helper for plugins | ||
*/ | ||
var Interpolator = function (a, b) { | ||
var isArray = Array.isArray(a); | ||
var origin = typeof a === 'string' ? a : isArray ? a.slice() : __assign$2({}, a); | ||
if (isArray) { | ||
for (var i = 0, len = a.length; i < len; i++) { | ||
decompose(i, origin, a, b); | ||
} | ||
var Interpolator = function Interpolator(a, b) { | ||
var isArray = Array.isArray(a); | ||
var origin = typeof a === 'string' ? a : isArray ? a.slice() : _objectSpread({}, a); | ||
if (isArray) { | ||
for (var i = 0, len = a.length; i < len; i++) { | ||
decompose(i, origin, a, b); | ||
} | ||
else if (typeof a === 'object') { | ||
for (var i in a) { | ||
decompose(i, origin, a, b); | ||
} | ||
} else if (_typeof(a) === 'object') { | ||
for (var _i in a) { | ||
decompose(_i, origin, a, b); | ||
} | ||
else if (typeof a === 'string') { | ||
a = decomposeString(a); | ||
b = decomposeString(b); | ||
var i = 1; | ||
while (i < a.length) { | ||
if (a[i] === b[i] && typeof a[i - 1] === 'string') { | ||
a.splice(i - 1, 2, a[i - 1] + a[i]); | ||
b.splice(i - 1, 2, b[i - 1] + b[i]); | ||
} | ||
else { | ||
i++; | ||
} | ||
} | ||
var c = { isString: true, length: a.length }; | ||
while (i < c.length) { | ||
c[i] = a[i]; | ||
i++; | ||
} | ||
} else if (typeof a === 'string') { | ||
a = decomposeString(a); | ||
b = decomposeString(b); | ||
var _i2 = 1; | ||
while (_i2 < a.length) { | ||
if (a[_i2] === b[_i2] && typeof a[_i2 - 1] === 'string') { | ||
a.splice(_i2 - 1, 2, a[_i2 - 1] + a[_i2]); | ||
b.splice(_i2 - 1, 2, b[_i2 - 1] + b[_i2]); | ||
} else { | ||
_i2++; | ||
} | ||
} | ||
return function (t) { | ||
if (isArray) { | ||
for (var i = 0, len = a.length; i < len; i++) { | ||
recompose(i, origin, a, b, t); | ||
} | ||
} | ||
else if (typeof origin === 'object') { | ||
for (var i in a) { | ||
recompose(i, origin, a, b, t); | ||
} | ||
} | ||
else if (typeof origin === 'string') { | ||
origin = recompose(0, 0, a, b, t, t, true); | ||
} | ||
return origin; | ||
var c = { | ||
isString: true, | ||
length: a.length | ||
}; | ||
while (_i2 < c.length) { | ||
c[_i2] = a[_i2]; | ||
_i2++; | ||
} | ||
} | ||
return function (t) { | ||
if (isArray) { | ||
for (var _i3 = 0, _len = a.length; _i3 < _len; _i3++) { | ||
recompose(_i3, origin, a, b, t); | ||
} | ||
} else if (_typeof(origin) === 'object') { | ||
for (var _i4 in a) { | ||
recompose(_i4, origin, a, b, t); | ||
} | ||
} else if (typeof origin === 'string') { | ||
origin = recompose(0, 0, a, b, t, t, true); | ||
} | ||
return origin; | ||
}; | ||
}; | ||
@@ -1731,0 +2194,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN={})}(this,function(t){"use strict";var e,r="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,i=r.requestAnimationFrame||function(t){return r.setTimeout(t,16)},n=r.cancelAnimationFrame||function(t){return r.clearTimeout(t)},o=function(){if("undefined"==typeof process||void 0===process.hrtime||process.versions&&void 0!==process.versions.electron){if(void 0!==r.performance&&void 0!==r.performance.now)return r.performance.now.bind(r.performance);var t=r.performance&&r.performance.timing&&r.performance.timing.navigationStart?r.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}}(),s=[],u=!1,a=!1,f=i,h=n,c=0,l=function(t){var r=s.indexOf(t);r>-1&&s.splice(r,1),s.push(t),c=0,a&&!u&&(e=f(d),u=!0)},p=function(t){for(var e=0;e<s.length;e++)if(t===s[e])return s[e];return null},y=function(t){var e=s.indexOf(t);-1!==e&&s.splice(e,1)},d=function(t,r){if(t=void 0!==t?t:o(),a&&u&&(e=f(d)),s.length||c++,c>120)return h(e),u=!1,c=0,!1;for(var i=0;i<s.length;)s[i++].update(t,r);return!0},v={},_={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){return t*t*(2.70158*t-1.70158)},Out:function(t){return--t*t*(2.70158*t+1.70158)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-_.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*_.Bounce.In(2*t):.5*_.Bounce.Out(2*t-1)+.5}},Stepped:{steps:function(t){return function(e){return(e*t|0)/t}}}},m="_chainedTweens",g="Callback",b="STRING_PROP",T=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]=+)?([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]=?\d+)?/g;function j(t){if(t&&t.nodeType||void 0===t||"object"!=typeof t)return t;if(Array.isArray(t))return[].concat(t);if("object"==typeof t){var e={};for(var r in t)e[r]=j(t[r]);return e}return t}var w=function(t){return isNaN(+t)||("+"===t[0]||"-"===t[0])&&"="===t[1]||""===t||" "===t},O=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,A=function(t,e){var r,i,n;3===e.length&&(e=(r=e[0])+r+(i=e[1])+i+(n=e[2])+n);var o=parseInt(e,16);return"rgb("+(r=o>>16&255)+","+(i=o>>8&255)+","+(n=255&o)+")"};function I(t){return"string"!=typeof t?t:t.replace(O,A).match(T).map(function(t){return w(t)?t:+t})}function M(t,e,r,i,n){var o=r[t],s=i[t];if("string"==typeof o||"string"==typeof s){for(var u=Array.isArray(o)&&o[0]===b?o:I(o),a=Array.isArray(s)&&s[0]===b?s:I(s),f=1;f<u.length;)u[f]===a[f]&&"string"==typeof u[f-1]?(u.splice(f-1,2,u[f-1]+u[f]),a.splice(f-1,2,a[f-1]+a[f])):f++;f=0,u[0]===b&&u.shift(),a[0]===b&&a.shift();for(var h={isString:!0,length:u.length},c={isString:!0,length:a.length};f<h.length;)h[f]=u[f],c[f]=a[f],f++;return r[t]=h,i[t]=c,!0}if("object"==typeof o&&"object"==typeof s){if(Array.isArray(o))return o.map(function(r,i){return M(i,e[t],o,s)});for(var l in s)M(l,e[t],o,s);return!0}return!1}var R=Math.pow(10,4),P="rgba(",F=function(t,e,r){return void 0===r&&(r="rgb("),"number"==typeof t[e]&&(t[e-1]===r||t[e-3]===r||t[e-5]===r)};function S(t,e,r,i,n,o,s){var u=s?r:r[t],a=s?i:i[t];if(void 0===a)return u;if(void 0===u||"string"==typeof u||u===a)return a;if("object"==typeof u&&"object"==typeof a){if(!u||!a)return e[t];if("object"==typeof u&&u&&u.isString){for(var f="",h=0,c=u.length;h<c;h++){var l="number"==typeof u[h]&&"string"==typeof a[h]&&"="===a[h][1],p="number"!=typeof u[h]?u[h]:((l?u[h]+parseFloat(a[h][0]+a[h].substr(2))*n:u[h]+(a[h]-u[h])*n)*R|0)/R;(F(u,h)||F(u,h,P))&&(p|=0),f+=p,l&&1===o&&(u[h]=u[h]+parseFloat(a[h][0]+a[h].substr(2)))}return s||(e[t]=f),f}if(Array.isArray(u)&&u[0]!==b)for(h=0,c=u.length;h<c;h++)u[h]!==a[h]&&S(h,e[t],u,a,n,o);else if("object"==typeof u&&u&&!u.isString)for(var h in u)u[h]!==a[h]&&S(h,e[t],u,a,n,o)}else if("number"==typeof u){l="string"==typeof a;e[t]=((l?u+parseFloat(a[0]+a.substr(2))*n:u+(a-u)*n)*R|0)/R,l&&1===o&&(r[t]=e[t])}else"function"==typeof a&&(e[t]=a(n));return e[t]}var q,C=/([.\[])/g,k=/\]/g,x=function(t,e){var r=t[e],i=e.replace(k,"").split(C),n=i.length-1,o=Array.isArray(t),s="object"==typeof t&&!o;return s?(t[e]=null,delete t[e]):o&&t.splice(e,1),i.reduce(function(t,e,u){o&&"."!==e&&"["!==e&&(e*=1);var a="["===i[u+1];if("."===e||"["===e)return"."===e?(s=!0,o=!1):"["===e&&(s=!1,o=!0),t;if(void 0===t[e]){if(o||s)return t[e]=u===n?r:o||a?[]:s?{}:null,s=o=!1,t[e]}else if(void 0!==t[e])return u===n&&(t[e]=r),t[e];return t},t)},L=function(t){if("object"==typeof t&&t)for(var e in t)if(-1!==e.indexOf(".")||-1!==e.indexOf("["))x(t,e);else if("object"==typeof t[e]&&t[e]){var r=t[e];for(var i in r)if(-1!==i.indexOf(".")||-1!==i.indexOf("["))x(r,i);else if("object"==typeof r[i]&&r[i]){var n=r[i];for(var o in n)-1===o.indexOf(".")&&-1===o.indexOf("[")||x(n,o)}}return t},D={Linear:function(t,e,r){var i=t.length-1,n=i*e,o=Math.floor(n),s=D.Utils.Linear;return e<0?s(t[0],t[1],n,r):e>1?s(t[i],t[i-1],i-n,r):s(t[o],t[o+1>i?i:o+1],n-o,r)},Bezier:function(t,e,r){for(var i=D.Utils.Reset(r),n=t.length-1,o=Math.pow,s=D.Utils.Bernstein,u=Array.isArray(i),a=0;a<=n;a++)if("number"==typeof i)i+=o(1-e,n-a)*o(e,a)*t[a]*s(n,a);else if(u)for(var f=0,h=i.length;f<h;f++)"number"==typeof i[f]?i[f]+=o(1-e,n-a)*o(e,a)*t[a][f]*s(n,a):i[f]=t[a][f];else if("object"==typeof i)for(var f in i)"number"==typeof i[f]?i[f]+=o(1-e,n-a)*o(e,a)*t[a][f]*s(n,a):i[f]=t[a][f];else if("string"==typeof i){var c="",l=Math.round(n*e),p=t[l],y=1;for(h=p.length;y<h;y++)c+=p[y];return c}return i},CatmullRom:function(t,e,r){var i=t.length-1,n=i*e,o=Math.floor(n),s=D.Utils.CatmullRom;return t[0]===t[i]?(e<0&&(o=Math.floor(n=i*(1+e))),s(t[(o-1+i)%i],t[o],t[(o+1)%i],t[(o+2)%i],n-o,r)):e<0?s(t[1],t[1],t[0],t[0],-e,r):e>1?s(t[i-1],t[i-1],t[i],t[i],(0|e)-e,r):s(t[o?o-1:0],t[o],t[i<o+1?i:o+1],t[i<o+2?i:o+2],n-o,r)},Utils:{Linear:function(t,e,r,i){if("string"==typeof t)return e;if("number"==typeof t)return"function"==typeof t?t(r):t+(e-t)*r;if("object"==typeof t){if(void 0!==t.length){if(t[0]===b){for(var n="",o=1,s=t.length;o<s;o++){var u="number"==typeof t[o]?t[o]+(e[o]-t[o])*r:e[o];(F(t,o)||F(t,o,P))&&(u|=0),n+=u}return n}var a=0;for(s=i.length;a<s;a++)i[a]=D.Utils.Linear(t[a],e[a],r,i[a])}else for(var a in i)i[a]=D.Utils.Linear(t[a],e[a],r,i[a]);return i}},Reset:function(t){if(Array.isArray(t)){for(var e=0,r=t.length;e<r;e++)t[e]=D.Utils.Reset(t[e]);return t}if("object"==typeof t){for(var e in t)t[e]=D.Utils.Reset(t[e]);return t}return"number"==typeof t?0:t},Bernstein:function(t,e){var r=D.Utils.Factorial;return r(t)/r(e)/r(t-e)},Factorial:(q=[1],function(t){var e=1;if(q[t])return q[t];for(var r=t;r>1;r--)e*=r;return q[t]=e,e}),CatmullRom:function(t,e,r,i,n,o){if("string"==typeof t)return e;if("number"==typeof t){var s=.5*(r-t),u=.5*(i-e),a=n*n;return(2*e-2*r+s+u)*(n*a)+(-3*e+3*r-2*s-u)*a+s*n+e}if("object"==typeof t){if(void 0!==t.length){if(t[0]===b){for(var f="",h=1,c=t.length;h<c;h++){var l="number"==typeof t[h]?D.Utils.CatmullRom(t[h],e[h],r[h],i[h],n):i[h];(F(t,h)||F(t,h,P))&&(l|=0),f+=l}return f}var p=0;for(c=o.length;p<c;p++)o[p]=D.Utils.CatmullRom(t[p],e[p],r[p],i[p],n,o[p])}else for(var p in o)o[p]=D.Utils.CatmullRom(t[p],e[p],r[p],i[p],n,o[p]);return o}}}},U=this&&this.__assign||Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},N={},E=function(t,e,r){if(!t||!t.nodeType)return e;var i=t.queueID||"q_"+Date.now();t.queueID||(t.queueID=i);var n=N[i];if(n){if(n.object===e&&t===n.tween.node&&r._startTime===n.tween._startTime)y(n.tween);else if("object"==typeof e&&e&&n.object){for(var o in e)o in n.object&&(r._startTime===n.tween._startTime?delete n.object[o]:n.propNormaliseRequired=!0);n.object=U({},n.object,e)}return n.object}return"object"==typeof e&&e?(N[i]={tween:r,object:e,propNormaliseRequired:!1},N[i].object):e},B=function(t,e){return e?t?t===window||t===document?[t]:"string"==typeof t?!!document.querySelectorAll&&document.querySelectorAll(t):Array.isArray(t)?t:t.nodeType?[t]:[]:null:t?t===window||t===document?t:"string"==typeof t?!!document.querySelector&&document.querySelector(t):Array.isArray(t)?t[0]:t.nodeType?t:null:null},Q=0,V=_.Linear.None,z=function(){function t(t,e){return this._chainedTweensCount=0,this.id=Q++,!t||"object"!=typeof t||e||t.nodeType?t&&(t.nodeType||t.length||"string"==typeof t)&&(t=this.node=B(t),e=this.object=E(t,e,this)):(e=this.object=t,t=null),this._valuesEnd=null,this._valuesStart={},this._duration=1e3,this._easingFunction=V,this._easingReverse=V,this._interpolationFunction=D.Linear,this._startTime=0,this._initTime=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._maxListener=15,this._prevTime=null,this}return t.fromTo=function(e,r,i,n){void 0===n&&(n={}),n.quickRender=n.quickRender?n.quickRender:!i;var o=new t(e,r).to(i,n);return n.quickRender&&(o.render().update(o._startTime),o._rendered=!1,o._onStartCallbackFired=!1),o},t.to=function(e,r,i){return t.fromTo(e,null,r,i)},t.from=function(e,r,i){return t.fromTo(e,r,null,i)},t.prototype.setMaxListener=function(t){return void 0===t&&(t=15),this._maxListener=t,this},t.prototype.on=function(t,e){for(var r=this._maxListener,i=t+g,n=0;n<r;n++){var o=i+n;if(!this[o]){this[o]=e;break}}return this},t.prototype.once=function(t,e){return this},t.prototype.off=function(t,e){for(var r=this._maxListener,i=t+g,n=0;n<r;n++){var o=i+n;this[o]===e&&(this[o]=null)}return this},t.prototype.emit=function(t,e,r,i,n){var o=this._maxListener,s=t+g;if(!this[s+0])return this;for(var u=0;u<o;u++){var a=s+u;this[a]&&this[a](e,r,i,n)}return this},t.prototype.isPlaying=function(){return this._isPlaying},t.prototype.isStarted=function(){return this._onStartCallbackFired},t.prototype.reverse=function(t){var e=this._reversed;return this._reversed=void 0!==t?t:!e,this},t.prototype.reversed=function(){return this._reversed},t.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,y(this),this._pausedTime=o(),this.emit("pause",this.object)):this},t.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=o()-this._pausedTime,this._initTime=this._startTime,l(this),this._pausedTime=o(),this.emit("play",this.object))},t.prototype.restart=function(t){return this._repeat=this._r,this.reassignValues(),l(this),this.emit("restart",this.object)},t.prototype.seek=function(t,e){var r=this._duration,i=(this._repeat,this._initTime),n=this._startTime,o=(this._delayTime,this._reversed),s=i+t;return this._isPlaying=!0,s<n&&n>=i&&(this._startTime-=r,this._reversed=!o),this.update(t,!1),this.emit("seek",t,this.object),e?this:this.pause()},t.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},t.prototype.to=function(t,e,r){if(void 0===e&&(e=1e3),this._valuesEnd=t,"number"==typeof e||"function"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var i in e)if("function"==typeof this[i]){var n=Array.isArray(e[i])?e[i]:[e[i]],o=n[0],s=void 0===o?null:o,u=n[1],a=void 0===u?null:u,f=n[2],h=void 0===f?null:f,c=n[3],l=void 0===c?null:c;this[i](s,a,h,l)}return this},t.prototype.render=function(){if(this._rendered)return this;var e=this._valuesStart,r=this._valuesEnd,i=this.object,n=this.node,o=this.InitialValues;if(L(i),L(r),n&&n.queueID&&N[n.queueID]){var s=N[n.queueID];if(s.propNormaliseRequired&&s.tween!==this){for(var u in r);s.normalisedProp=!0,s.propNormaliseRequired=!1}}n&&o&&(i&&0!==Object.keys(i).length?r&&0!==Object.keys(r).length||(r=this._valuesEnd=o(n,i)):i=this.object=E(n,o(n,r),this));for(var u in r){var a=i&&i[u]&&j(i[u]),f=r[u];if(!(v[u]&&v[u].init&&(v[u].init.call(this,a,f,u,i),void 0===a&&e[u]&&(a=e[u]),v[u].skipProcess))&&!("number"==typeof a&&isNaN(a)||null===a||null===f||!1===a||!1===f||void 0===a||void 0===f||a===f)){if(Array.isArray(f)&&!Array.isArray(a)){f.unshift(a);for(var h=0,c=f.length;h<c;h++)if("string"==typeof f[h]){for(var l=I(f[h]),p={length:l.length,isString:!0},y=0,d=l.length;y<d;y++)p[y]=l[y];f[h]=p}}e[u]=a,"number"==typeof a&&"string"==typeof f&&"="===f[1]||M(u,i,e,r)}}return t.Renderer&&this.node&&t.Renderer.init&&(t.Renderer.init.call(this,i,e,r),this.__render=!0),this},t.prototype.start=function(t){return this._startTime=void 0!==t?"string"==typeof t?o()+parseFloat(t):t:o(),this._startTime+=this._delayTime,this._initTime=this._prevTime=this._startTime,this._onStartCallbackFired=!1,this._rendered=!1,this._isPlaying=!0,l(this),this},t.prototype.stop=function(){var t=this._isPlaying,e=this._isFinite,r=this.object,i=this._startTime,n=(this._delayTime,this._duration),o=this._r,s=this._yoyo,u=this._reversed;if(!t)return this;var a=e?(o+1)%2==1:!u;return this._reversed=!1,s&&a?this.update(i):this.update(i+n),y(this),this.emit("stop",r)},t.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},t.prototype.chainedTweens=function(){if(this._chainedTweensCount=arguments.length,!this._chainedTweensCount)return this;for(var t=0,e=this._chainedTweensCount;t<e;t++)this[m+t]=arguments[t];return this},t.prototype.repeat=function(t){return this._repeat=this._duration?"function"==typeof t?t(this._repeat):t:0,this._r=this._repeat,this._isFinite=isFinite(t),this},t.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},t.prototype.yoyo=function(t,e){return this._yoyo="function"==typeof t?t(this._yoyo):null===t?this._yoyo:t,t||(this._reversed=!1),this._easingReverse=e||null,this},t.prototype.easing=function(t){return this._easingFunction=t,this},t.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},t.prototype.reassignValues=function(t){var e=this._valuesStart,r=this.object,i=this._delayTime;this._isPlaying=!0,this._startTime=void 0!==t?t:o(),this._startTime+=i,this._reversed=!1,l(this);for(var n in e){var s=e[n];r[n]=s}return this},t.prototype.update=function(e,r,i){var n,s,u,a=this._onStartCallbackFired,f=this._easingFunction,h=this._interpolationFunction,c=this._easingReverse,l=this._repeat,p=this._delayTime,d=this._reverseDelayTime,_=this._yoyo,g=this._reversed,b=this._startTime,T=this._prevTime,j=this._duration,w=this._valuesStart,O=this._valuesEnd,A=this.object,I=this._isFinite,M=this._isPlaying,P=this.__render,F=this._chainedTweensCount,q=0;if(j){var C=(e=void 0!==e?e:o())-T;if(this._prevTime=e,C>250&&(e-=C-50/3),!M||e<b&&!i)return!0;n=(n=(e-b)/j)>1?1:n,n=g?1-n:n}else n=1,l=0;if(a||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",A),this._onStartCallbackFired=!0),s=g?c||f:f,!A)return!0;for(u in O){var k=w[u];if(void 0!==k&&null!==k||v[u]&&v[u].update){var x=O[u],L=s[u]?s[u](n):"function"==typeof s?s(n):V(n),U=h[u]?h[u]:"function"==typeof h?h:D.Linear;"number"==typeof x?A[u]=((k+(x-k)*L)*R|0)/R:Array.isArray(x)&&!Array.isArray(k)?A[u]=U(x,L,A[u]):x&&x.update?x.update(L):"function"==typeof x?A[u]=x(L):"string"==typeof x&&"number"==typeof k?A[u]=k+parseFloat(x[0]+x.substr(2))*L:S(u,A,w,O,L,n),v[u]&&v[u].update&&v[u].update.call(this,A[u],k,x,L,n,u),q++}}if(!q)return y(this),!1;if(P&&t.Renderer&&t.Renderer.update&&t.Renderer.update.call(this,A,n),this.emit("update",A,n,e),1===n||g&&0===n){if(l>0&&j>0){if(I&&this._repeat--,_)this._reversed=!g;else for(u in O){"string"==typeof(x=O[u])&&"number"==typeof w[u]&&(w[u]+=parseFloat(x[0]+x.substr(2)))}return this.emit(_&&!g?"reverse":"repeat",A),this._startTime=g&&d?e-d:e+p,!0}if(r||(this._isPlaying=!1,y(this),Q--),this.emit("complete",A),this._repeat=this._r,F)for(var N=0;N<F;N++)this[m+N].start(e+j);return!1}return!0},t}(),G=this&&this.__assign||Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t};t.Plugins=v,t.Selector=B,t.Interpolator=function(t,e){var r=Array.isArray(t),i="string"==typeof t?t:r?t.slice():G({},t);if(r)for(var n=0,o=t.length;n<o;n++)M(n,i,t,e);else if("object"==typeof t)for(var n in t)M(n,i,t,e);else if("string"==typeof t){for(t=I(t),e=I(e),n=1;n<t.length;)t[n]===e[n]&&"string"==typeof t[n-1]?(t.splice(n-1,2,t[n-1]+t[n]),e.splice(n-1,2,e[n-1]+e[n])):n++;for(var s={isString:!0,length:t.length};n<s.length;)s[n]=t[n],n++}return function(n){if(r)for(var o=0,s=t.length;o<s;o++)S(o,i,t,e,n);else if("object"==typeof i)for(var o in t)S(o,i,t,e,n);else"string"==typeof i&&(i=S(0,0,t,e,n,n,!0));return i}},t.onTick=function(t){return s.push({update:t})},t.has=function(t){return null!==p(t)},t.get=p,t.getAll=function(){return s},t.removeAll=function(){s.length=0},t.remove=y,t.add=l,t.now=o,t.update=d,t.autoPlay=function(t){a=t},t.isRunning=function(){return u},t.Tween=z,t.Easing=_,t.Interpolation=D,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN={})}(this,function(t){"use strict";function _(t){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function e(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}function f(i){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{},e=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(o).filter(function(t){return Object.getOwnPropertyDescriptor(o,t).enumerable}))),e.forEach(function(t){var e,r,n;e=i,n=o[r=t],r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n})}return i}function c(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,i=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(n=(u=s.next()).done)&&(r.push(u.value),!e||r.length!==e);n=!0);}catch(t){i=!0,o=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw o}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}"function"==typeof Symbol&&Symbol.asyncIterator&&Symbol.asyncIterator;var i,r="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,o=r.requestAnimationFrame||function(t){return r.setTimeout(t,16)},u=r.cancelAnimationFrame||function(t){return r.clearTimeout(t)},C=function(){if("undefined"==typeof process||void 0===process.hrtime||process.versions&&void 0!==process.versions.electron){if(void 0!==r.performance&&void 0!==r.performance.now)return r.performance.now.bind(r.performance);var t=r.performance&&r.performance.timing&&r.performance.timing.navigationStart?r.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}}(),s=[],a=!1,l=!1,h=o,y=u,v=0,p=function(t){var e=s.indexOf(t);-1<e&&s.splice(e,1),s.push(t),v=0,l&&!a&&(i=h(m),a=!0)},d=function(t){for(var e=0;e<s.length;e++)if(t===s[e])return s[e];return null},x=function(t){var e=s.indexOf(t);-1!==e&&s.splice(e,1)},m=function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:C(),r=1<arguments.length?arguments[1]:void 0;if(l&&a&&(i=h(t)),s.length||v++,120<v)return y(i),v=0,a=!1;for(var n=0;n<s.length;)s[n++].update(e,r);return!0},L={},g={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){return t*t*(2.70158*t-1.70158)},Out:function(t){return--t*t*(2.70158*t+1.70158)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-g.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*g.Bounce.In(2*t):.5*g.Bounce.Out(2*t-1)+.5}},Stepped:{steps:function(e){return function(t){return(t*e|0)/e}}}},D="_chainedTweens",b="Callback",T="STRING_PROP",j=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]=+)?([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]=?\d+)?/g;function k(t){if(t&&t.nodeType||void 0===t||"object"!==_(t))return t;if(Array.isArray(t))return[].concat(t);if("object"===_(t)){var e={};for(var r in t)e[r]=k(t[r]);return e}return t}var w=function(t){return isNaN(+t)||("+"===t[0]||"-"===t[0])&&"="===t[1]||""===t||" "===t},O=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,I=function(t,e){var r,n,i;3===e.length&&(e=(r=e[0])+r+(n=e[1])+n+(i=e[2])+i);var o=parseInt(e,16);return"rgb("+(r=o>>16&255)+","+(n=o>>8&255)+","+(i=255&o)+")"};function A(t){return"string"!=typeof t?t:t.replace(O,I).match(j).map(function(t){return w(t)?t:+t})}function S(r,n,t,e,i){var o=t[r],u=e[r];if("string"==typeof o||"string"==typeof u){for(var s=Array.isArray(o)&&o[0]===T?o:A(o),a=Array.isArray(u)&&u[0]===T?u:A(u),f=1;f<s.length;)s[f]===a[f]&&"string"==typeof s[f-1]?(s.splice(f-1,2,s[f-1]+s[f]),a.splice(f-1,2,a[f-1]+a[f])):f++;s[f=0]===T&&s.shift(),a[0]===T&&a.shift();for(var l={isString:!0,length:s.length},h={isString:!0,length:a.length};f<l.length;)l[f]=s[f],h[f]=a[f],f++;return t[r]=l,e[r]=h,!0}if("object"===_(o)&&"object"===_(u)){if(Array.isArray(o))return o.map(function(t,e){return S(e,n[r],o,u)});for(var c in u)S(c,n[r],o,u);return!0}return!1}var E=Math.pow(10,4),M="rgba(",P=function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"rgb(";return"number"==typeof t[e]&&(t[e-1]===r||t[e-3]===r||t[e-5]===r)};function U(t,e,r,n,i,o,u){var s=u?r:r[t],a=u?n:n[t];if(void 0===a)return s;if(void 0===s||"string"==typeof s||s===a)return a;if("object"===_(s)&&"object"===_(a)){if(!s||!a)return e[t];if("object"===_(s)&&s&&s.isString){for(var f="",l=0,h=s.length;l<h;l++){var c="number"==typeof s[l]&&"string"==typeof a[l]&&"="===a[l][1],y="number"!=typeof s[l]?s[l]:((c?s[l]+parseFloat(a[l][0]+a[l].substr(2))*i:s[l]+(a[l]-s[l])*i)*E|0)/E;(P(s,l)||P(s,l,M))&&(y|=0),f+=y,c&&1===o&&(s[l]=s[l]+parseFloat(a[l][0]+a[l].substr(2)))}return u||(e[t]=f),f}if(Array.isArray(s)&&s[0]!==T)for(var v=0,p=s.length;v<p;v++)s[v]!==a[v]&&U(v,e[t],s,a,i,o);else if("object"===_(s)&&s&&!s.isString)for(var d in s)s[d]!==a[d]&&U(d,e[t],s,a,i,o)}else if("number"==typeof s){var m="string"==typeof a;e[t]=((m?s+parseFloat(a[0]+a.substr(2))*i:s+(a-s)*i)*E|0)/E,m&&1===o&&(r[t]=e[t])}else"function"==typeof a&&(e[t]=a(i));return e[t]}var R,F=/([.\[])/g,q=/\]/g,N=function(t,e){var i=t[e],o=e.replace(q,"").split(F),u=o.length-1,s=Array.isArray(t),a="object"===_(t)&&!s;return a?(t[e]=null,delete t[e]):s&&t.splice(e,1),o.reduce(function(t,e,r){s&&"."!==e&&"["!==e&&(e*=1);var n="["===o[r+1];if("."===e||"["===e)return"."===e?s=!(a=!0):"["===e&&(s=!(a=!1)),t;if(void 0===t[e]){if(s||a)return t[e]=r===u?i:s||n?[]:a?{}:null,a=s=!1,t[e]}else if(void 0!==t[e])return r===u&&(t[e]=i),t[e];return t},t)},B=function(t){if("object"===_(t)&&t)for(var e in t)if(-1!==e.indexOf(".")||-1!==e.indexOf("["))N(t,e);else if("object"===_(t[e])&&t[e]){var r=t[e];for(var n in r)if(-1!==n.indexOf(".")||-1!==n.indexOf("["))N(r,n);else if("object"===_(r[n])&&r[n]){var i=r[n];for(var o in i)-1===o.indexOf(".")&&-1===o.indexOf("[")||N(i,o)}}return t},Q={Linear:function(t,e,r){var n=t.length-1,i=n*e,o=Math.floor(i),u=Q.Utils.Linear;return e<0?u(t[0],t[1],i,r):1<e?u(t[n],t[n-1],n-i,r):u(t[o],t[n<o+1?n:o+1],i-o,r)},Bezier:function(t,e,r){for(var n=Q.Utils.Reset(r),i=t.length-1,o=Math.pow,u=Q.Utils.Bernstein,s=Array.isArray(n),a=0;a<=i;a++)if("number"==typeof n)n+=o(1-e,i-a)*o(e,a)*t[a]*u(i,a);else if(s)for(var f=0,l=n.length;f<l;f++)"number"==typeof n[f]?n[f]+=o(1-e,i-a)*o(e,a)*t[a][f]*u(i,a):n[f]=t[a][f];else if("object"===_(n))for(var h in n)"number"==typeof n[h]?n[h]+=o(1-e,i-a)*o(e,a)*t[a][h]*u(i,a):n[h]=t[a][h];else if("string"==typeof n){for(var c="",y=Math.round(i*e),v=t[y],p=1,d=v.length;p<d;p++)c+=v[p];return c}return n},CatmullRom:function(t,e,r){var n=t.length-1,i=n*e,o=Math.floor(i),u=Q.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(o=Math.floor(i=n*(1+e))),u(t[(o-1+n)%n],t[o],t[(o+1)%n],t[(o+2)%n],i-o,r)):e<0?u(t[1],t[1],t[0],t[0],-e,r):1<e?u(t[n-1],t[n-1],t[n],t[n],(0|e)-e,r):u(t[o?o-1:0],t[o],t[n<o+1?n:o+1],t[n<o+2?n:o+2],i-o,r)},Utils:{Linear:function(t,e,r,n){if("string"==typeof t)return e;if("number"==typeof t)return"function"==typeof t?t(r):t+(e-t)*r;if("object"===_(t)){if(void 0!==t.length){if(t[0]===T){for(var i="",o=1,u=t.length;o<u;o++){var s="number"==typeof t[o]?t[o]+(e[o]-t[o])*r:e[o];(P(t,o)||P(t,o,M))&&(s|=0),i+=s}return i}for(var a=0,f=n.length;a<f;a++)n[a]=Q.Utils.Linear(t[a],e[a],r,n[a])}else for(var l in n)n[l]=Q.Utils.Linear(t[l],e[l],r,n[l]);return n}},Reset:function(t){if(Array.isArray(t)){for(var e=0,r=t.length;e<r;e++)t[e]=Q.Utils.Reset(t[e]);return t}if("object"===_(t)){for(var n in t)t[n]=Q.Utils.Reset(t[n]);return t}return"number"==typeof t?0:t},Bernstein:function(t,e){var r=Q.Utils.Factorial;return r(t)/r(e)/r(t-e)},Factorial:(R=[1],function(t){var e=1;if(R[t])return R[t];for(var r=t;1<r;r--)e*=r;return R[t]=e}),CatmullRom:function(t,e,r,n,i,o){if("string"==typeof t)return e;if("number"==typeof t){var u=.5*(r-t),s=.5*(n-e),a=i*i;return(2*e-2*r+u+s)*(i*a)+(-3*e+3*r-2*u-s)*a+u*i+e}if("object"===_(t)){if(void 0!==t.length){if(t[0]===T){for(var f="",l=1,h=t.length;l<h;l++){var c="number"==typeof t[l]?Q.Utils.CatmullRom(t[l],e[l],r[l],n[l],i):n[l];(P(t,l)||P(t,l,M))&&(c|=0),f+=c}return f}for(var y=0,v=o.length;y<v;y++)o[y]=Q.Utils.CatmullRom(t[y],e[y],r[y],n[y],i,o[y])}else for(var p in o)o[p]=Q.Utils.CatmullRom(t[p],e[p],r[p],n[p],i,o[p]);return o}}}},V={},z=function(t,e,r){if(!t||!t.nodeType)return e;var n=t.queueID||"q_"+Date.now();t.queueID||(t.queueID=n);var i=V[n];if(i){if(i.object===e&&t===i.tween.node&&r._startTime===i.tween._startTime)x(i.tween);else if("object"===_(e)&&e&&i.object){for(var o in e)o in i.object&&(r._startTime===i.tween._startTime?delete i.object[o]:i.propNormaliseRequired=!0);i.object=f({},i.object,e)}return i.object}return"object"===_(e)&&e?(V[n]={tween:r,object:e,propNormaliseRequired:!1},V[n].object):e},G=function(t,e){return e?t?t===window||t===document?[t]:"string"==typeof t?!!document.querySelectorAll&&document.querySelectorAll(t):Array.isArray(t)?t:t.nodeType?[t]:[]:null:t?t===window||t===document?t:"string"==typeof t?!!document.querySelector&&document.querySelector(t):Array.isArray(t)?t[0]:t.nodeType?t:null:null},W=0,Z=g.Linear.None,$=function(){function q(t,e){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,q),Object.defineProperty(this,"_chainedTweensCount",{configurable:!0,enumerable:!0,writable:!0,value:0}),this.id=W++,!t||"object"!==_(t)||e||t.nodeType?t&&(t.nodeType||t.length||"string"==typeof t)&&(t=this.node=G(t),e=this.object=z(t,e,this)):(e=this.object=t,t=null),this._valuesEnd=null,this._valuesStart={},this._duration=1e3,this._easingFunction=Z,this._easingReverse=Z,this._interpolationFunction=Q.Linear,this._startTime=0,this._initTime=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._maxListener=15,this._prevTime=null,this}return e(q,null,[{key:"fromTo",value:function(t,e,r){var n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{};n.quickRender=n.quickRender?n.quickRender:!r;var i=new q(t,e).to(r,n);return n.quickRender&&(i.render().update(i._startTime),i._rendered=!1,i._onStartCallbackFired=!1),i}},{key:"to",value:function(t,e,r){return q.fromTo(t,null,e,r)}},{key:"from",value:function(t,e,r){return q.fromTo(t,e,null,r)}}]),e(q,[{key:"setMaxListener",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:15;return this._maxListener=t,this}},{key:"on",value:function(t,e){for(var r=this._maxListener,n=t+b,i=0;i<r;i++){var o=n+i;if(!this[o]){this[o]=e;break}}return this}},{key:"once",value:function(t,e){return this}},{key:"off",value:function(t,e){for(var r=this._maxListener,n=t+b,i=0;i<r;i++){var o=n+i;this[o]===e&&(this[o]=null)}return this}},{key:"emit",value:function(t,e,r,n,i){var o=this._maxListener,u=t+b;if(!this[u+0])return this;for(var s=0;s<o;s++){var a=u+s;this[a]&&this[a](e,r,n,i)}return this}},{key:"isPlaying",value:function(){return this._isPlaying}},{key:"isStarted",value:function(){return this._onStartCallbackFired}},{key:"reverse",value:function(t){var e=this._reversed;return this._reversed=void 0!==t?t:!e,this}},{key:"reversed",value:function(){return this._reversed}},{key:"pause",value:function(){return this._isPlaying?(this._isPlaying=!1,x(this),this._pausedTime=C(),this.emit("pause",this.object)):this}},{key:"play",value:function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=C()-this._pausedTime,this._initTime=this._startTime,p(this),this._pausedTime=C(),this.emit("play",this.object))}},{key:"restart",value:function(t){return this._repeat=this._r,this.reassignValues(),p(this),this.emit("restart",this.object)}},{key:"seek",value:function(t,e){var r=this._duration,n=(this._repeat,this._initTime),i=this._startTime,o=(this._delayTime,this._reversed),u=n+t;return this._isPlaying=!0,u<i&&n<=i&&(this._startTime-=r,this._reversed=!o),this.update(t,!1),this.emit("seek",t,this.object),e?this:this.pause()}},{key:"duration",value:function(t){return this._duration="function"==typeof t?t(this._duration):t,this}},{key:"to",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1e3;if(this._valuesEnd=t,"number"==typeof e||"function"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"===_(e))for(var r in e)if("function"==typeof this[r]){var n=c(Array.isArray(e[r])?e[r]:[e[r]],4),i=n[0],o=void 0===i?null:i,u=n[1],s=void 0===u?null:u,a=n[2],f=void 0===a?null:a,l=n[3],h=void 0===l?null:l;this[r](o,s,f,h)}return this}},{key:"render",value:function(){if(this._rendered)return this;var t=this._valuesStart,e=this._valuesEnd,r=this.object,n=this.node,i=this.InitialValues;if(B(r),B(e),n&&n.queueID&&V[n.queueID]){var o=V[n.queueID];o.propNormaliseRequired&&o.tween!==this&&(o.normalisedProp=!0,o.propNormaliseRequired=!1)}for(var u in n&&i&&(r&&0!==Object.keys(r).length?e&&0!==Object.keys(e).length||(e=this._valuesEnd=i(n,r)):r=this.object=z(n,i(n,e),this)),e){var s=r&&r[u]&&k(r[u]),a=e[u];if(!(L[u]&&L[u].init&&(L[u].init.call(this,s,a,u,r),void 0===s&&t[u]&&(s=t[u]),L[u].skipProcess))&&!("number"==typeof s&&isNaN(s)||null===s||null===a||!1===s||!1===a||void 0===s||void 0===a||s===a)){if(Array.isArray(a)&&!Array.isArray(s)){a.unshift(s);for(var f=0,l=a.length;f<l;f++)if("string"==typeof a[f]){for(var h=A(a[f]),c={length:h.length,isString:!0},y=0,v=h.length;y<v;y++)c[y]=h[y];a[f]=c}}"number"==typeof(t[u]=s)&&"string"==typeof a&&"="===a[1]||S(u,r,t,e)}}return q.Renderer&&this.node&&q.Renderer.init&&(q.Renderer.init.call(this,r,t,e),this.__render=!0),this}},{key:"start",value:function(t){return this._startTime=void 0!==t?"string"==typeof t?C()+parseFloat(t):t:C(),this._startTime+=this._delayTime,this._initTime=this._prevTime=this._startTime,this._onStartCallbackFired=!1,this._rendered=!1,this._isPlaying=!0,p(this),this}},{key:"stop",value:function(){var t=this._isPlaying,e=this._isFinite,r=this.object,n=this._startTime,i=(this._delayTime,this._duration),o=this._r,u=this._yoyo,s=this._reversed;if(!t)return this;var a=e?(o+1)%2==1:!s;return this._reversed=!1,u&&a?this.update(n):this.update(n+i),x(this),this.emit("stop",r)}},{key:"delay",value:function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this}},{key:"chainedTweens",value:function(){if(this._chainedTweensCount=arguments.length,!this._chainedTweensCount)return this;for(var t=0,e=this._chainedTweensCount;t<e;t++)this[D+t]=arguments[t];return this}},{key:"repeat",value:function(t){return this._repeat=this._duration?"function"==typeof t?t(this._repeat):t:0,this._r=this._repeat,this._isFinite=isFinite(t),this}},{key:"reverseDelay",value:function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this}},{key:"yoyo",value:function(t,e){return this._yoyo="function"==typeof t?t(this._yoyo):null===t?this._yoyo:t,t||(this._reversed=!1),this._easingReverse=e||null,this}},{key:"easing",value:function(t){return this._easingFunction=t,this}},{key:"interpolation",value:function(t){return"function"==typeof t&&(this._interpolationFunction=t),this}},{key:"reassignValues",value:function(t){var e=this._valuesStart,r=this.object,n=this._delayTime;for(var i in this._isPlaying=!0,this._startTime=void 0!==t?t:C(),this._startTime+=n,this._reversed=!1,p(this),e){var o=e[i];r[i]=o}return this}},{key:"update",value:function(t,e,r){var n,i,o,u=this._onStartCallbackFired,s=this._easingFunction,a=this._interpolationFunction,f=this._easingReverse,l=this._repeat,h=this._delayTime,c=this._reverseDelayTime,y=this._yoyo,v=this._reversed,p=this._startTime,d=this._prevTime,m=this._duration,_=this._valuesStart,g=this._valuesEnd,b=this.object,T=this._isFinite,j=this._isPlaying,k=this.__render,w=this._chainedTweensCount,O=0;if(m){var I=(t=void 0!==t?t:C())-d;if(this._prevTime=t,250<I&&(t-=I-50/3),!j||t<p&&!r)return!0;n=1<(n=(t-p)/m)?1:n,n=v?1-n:n}else n=1,l=0;if(u||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",b),this._onStartCallbackFired=!0),i=v&&f||s,!b)return!0;for(o in g){var A=_[o];if(null!=A||L[o]&&L[o].update){var S=g[o],M=i[o]?i[o](n):"function"==typeof i?i(n):Z(n),P=a[o]?a[o]:"function"==typeof a?a:Q.Linear;"number"==typeof S?b[o]=((A+(S-A)*M)*E|0)/E:Array.isArray(S)&&!Array.isArray(A)?b[o]=P(S,M,b[o]):S&&S.update?S.update(M):"function"==typeof S?b[o]=S(M):"string"==typeof S&&"number"==typeof A?b[o]=A+parseFloat(S[0]+S.substr(2))*M:U(o,b,_,g,M,n),L[o]&&L[o].update&&L[o].update.call(this,b[o],A,S,M,n,o),O++}}if(!O)return x(this),!1;if(k&&q.Renderer&&q.Renderer.update&&q.Renderer.update.call(this,b,n),this.emit("update",b,n,t),1===n||v&&0===n){if(0<l&&0<m){if(T&&this._repeat--,y)this._reversed=!v;else for(o in g){var R=g[o];"string"==typeof R&&"number"==typeof _[o]&&(_[o]+=parseFloat(R[0]+R.substr(2)))}return this.emit(y&&!v?"reverse":"repeat",b),this._startTime=v&&c?t-c:t+h,!0}if(e||(this._isPlaying=!1,x(this),W--),this.emit("complete",b),this._repeat=this._r,w)for(var F=0;F<w;F++)this[D+F].start(t+m);return!1}return!0}}]),q}();t.Plugins=L,t.Selector=G,t.Interpolator=function(i,o){var u=Array.isArray(i),s="string"==typeof i?i:u?i.slice():f({},i);if(u)for(var t=0,e=i.length;t<e;t++)S(t,s,i,o);else if("object"===_(i))for(var r in i)S(r,s,i,o);else if("string"==typeof i){i=A(i),o=A(o);for(var n=1;n<i.length;)i[n]===o[n]&&"string"==typeof i[n-1]?(i.splice(n-1,2,i[n-1]+i[n]),o.splice(n-1,2,o[n-1]+o[n])):n++;for(var a={isString:!0,length:i.length};n<a.length;)a[n]=i[n],n++}return function(t){if(u)for(var e=0,r=i.length;e<r;e++)U(e,s,i,o,t);else if("object"===_(s))for(var n in i)U(n,s,i,o,t);else"string"==typeof s&&(s=U(0,0,i,o,t,t,!0));return s}},t.onTick=function(t){return s.push({update:t})},t.has=function(t){return null!==d(t)},t.get=d,t.getAll=function(){return s},t.removeAll=function(){s.length=0},t.remove=x,t.add=p,t.now=C,t.update=m,t.autoPlay=function(t){l=t},t.isRunning=function(){return a},t.Tween=$,t.Easing=g,t.Interpolation=Q,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct |
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "es6-tween", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -9,3 +9,2 @@ "browser": "bundled/Tween.min.js", | ||
"module": "src/index.js", | ||
"types": "src/index.d.ts", | ||
"directories": { | ||
@@ -15,10 +14,11 @@ "example": "examples" | ||
"scripts": { | ||
"source": "rollup -c", | ||
"minify": "uglifyjs bundled/Tween.js -c -m -o bundled/Tween.min.js --source-map \"filename='bundled/Tween.min.js.map'\"", | ||
"source": "npx rollup -c", | ||
"minify": "npx uglifyjs bundled/Tween.js -c -m -o bundled/Tween.min.js --source-map \"filename='bundled/Tween.min.js.map'\"", | ||
"build": "npm run source && npm run minify", | ||
"dev": "rollup -c -w", | ||
"test": "tsc && rollup -c && ava --verbose", | ||
"prepublishOnly": "tsc && npm run build && ava --verbose && npm run doc && npm run doc-md", | ||
"doc": "jsdoc --readme README.md --configure jsdoc.json --verbose", | ||
"doc-md": "jsdoc2md src/** > API.md" | ||
"dev": "npx rollup -c -w", | ||
"prepublishOnly": "npm run build && npx ava --verbose && npm run doc && npm run doc-md", | ||
"doc": "npx jsdoc --readme README.md --configure jsdoc.json --verbose", | ||
"doc-md": "npx jsdoc2md src/** > API.md", | ||
"test": "npx standard --verbose | npx snazzy && npx ava --verbose", | ||
"fix": "npx standard --fix" | ||
}, | ||
@@ -45,19 +45,17 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0-beta.44", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.44", | ||
"@babel/preset-env": "^7.0.0-beta.44", | ||
"ava": "^0.22.0", | ||
"docdash": "^0.4.0", | ||
"gulp": "^3.9.1", | ||
"gulp-buble": "^0.9.0", | ||
"gulp-concat": "^2.6.1", | ||
"gulp-typescript": "^4.0.0-alpha.1", | ||
"gulp-uglify": "^3.0.0", | ||
"jsdoc": "^3.5.5", | ||
"jsdoc-to-markdown": "next", | ||
"jsdoc-to-markdown": "^3.1.0-1", | ||
"rollup": "^0.50.1", | ||
"rollup-plugin-commonjs": "^8.2.6", | ||
"rollup-plugin-node-resolve": "^3.0.2", | ||
"rollup-watch": "^4.3.1", | ||
"typescript": "^2.6.2", | ||
"rollup-plugin-babel": "^4.0.0-beta.4", | ||
"uglify-js": "^3.3.5" | ||
}, | ||
"dependencies": {} | ||
"dependencies": {}, | ||
"standard": { | ||
"ignore": ["node_modules", "bundled", "examples", "performance"] | ||
} | ||
} |
@@ -27,3 +27,3 @@ # es6-tween | ||
Implementing tween in Javascript always has been hardly, especially in 2009-2012years, but there have been much of leaders, one of these GreenSock Animation Platform, shifty, CollieJS, CreateJS TweenJS and our tween.js. | ||
The @sole, @mrdoob and other contributors does the job amazing and worked hardly to make web better, interactive and live | ||
The @sole, @mrdoob and other contributors did the job amazing and worked hardly to make web better, interactive and live | ||
``` | ||
@@ -118,13 +118,2 @@ | ||
#### Using `grunt` | ||
PR are welcome... | ||
#### Using `gulp` | ||
After package installed, go-to directory and then run: | ||
- if you want build, then `$ gulp` | ||
- if you want watch, then `$ gulp watch` | ||
#### Using `import` | ||
@@ -150,3 +139,3 @@ | ||
#### Using `npm`, `yarn` or `bower` | ||
#### Using `npm` or `yarn` | ||
@@ -157,4 +146,2 @@ ```bash | ||
$ npm install es6-tween | ||
# or | ||
$ bower install es6-tween | ||
``` | ||
@@ -180,5 +167,5 @@ | ||
```bash | ||
$ npm run build # builds production files | ||
$ yarn build # builds production files | ||
# or | ||
$ npm run dev # builds and watchs development files | ||
$ yarn dev # builds and watchs development files | ||
``` | ||
@@ -185,0 +172,0 @@ |
@@ -1,2 +0,2 @@ | ||
var rollup = require('rollup') | ||
import babel from 'rollup-plugin-babel' | ||
@@ -6,8 +6,26 @@ export default { | ||
output: { | ||
format: 'umd', | ||
file: 'bundled/Tween.js' | ||
format: 'umd', | ||
file: 'bundled/Tween.js', | ||
name: 'TWEEN', | ||
sourcemap: true | ||
}, | ||
sourcemap: true, | ||
context: 'this', | ||
name: 'TWEEN' | ||
} | ||
plugins: [ | ||
babel({ | ||
babelrc: false, | ||
exclude: ['node_modules/**', 'bundles/**'], | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
shippedProposals: true | ||
} | ||
] | ||
], | ||
plugins: [ | ||
'@babel/plugin-proposal-class-properties' | ||
] | ||
}) | ||
] | ||
} |
// Frame lag-fix constants | ||
export var FRAME_MS = 50 / 3; | ||
export var TOO_LONG_FRAME_MS = 250; | ||
export var CHAINED_TWEENS = '_chainedTweens'; | ||
export const FRAME_MS = 50 / 3; | ||
export const TOO_LONG_FRAME_MS = 250; | ||
export const CHAINED_TWEENS = '_chainedTweens'; | ||
// Event System | ||
export var EVENT_CALLBACK = 'Callback'; | ||
export var EVENT_UPDATE = 'update'; | ||
export var EVENT_COMPLETE = 'complete'; | ||
export var EVENT_START = 'start'; | ||
export var EVENT_REPEAT = 'repeat'; | ||
export var EVENT_REVERSE = 'reverse'; | ||
export var EVENT_PAUSE = 'pause'; | ||
export var EVENT_PLAY = 'play'; | ||
export var EVENT_RESTART = 'restart'; | ||
export var EVENT_STOP = 'stop'; | ||
export var EVENT_SEEK = 'seek'; | ||
export const EVENT_CALLBACK = 'Callback'; | ||
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_RESTART = 'restart'; | ||
export const EVENT_STOP = 'stop'; | ||
export const EVENT_SEEK = 'seek'; | ||
// For String tweening stuffs | ||
export var STRING_PROP = 'STRING_PROP'; | ||
export const STRING_PROP = 'STRING_PROP'; | ||
// Also RegExp's for string tweening | ||
export var NUM_REGEX = /\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]=+)?([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]=?\d+)?/g; | ||
export var HEXC_REGEX = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i; | ||
export const NUM_REGEX = /\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]=+)?([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]=?\d+)?/g; | ||
export const HEXC_REGEX = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i; | ||
// Copies everything, duplicates, no shallow-copy | ||
export function deepCopy(source) { | ||
if ((source && source.nodeType) || source === undefined || typeof source !== 'object') { | ||
return source; | ||
if ((source && source.nodeType) || source === undefined || typeof source !== 'object') { | ||
return source; | ||
} else if (Array.isArray(source)) { | ||
return [].concat(source); | ||
} else if (typeof source === 'object') { | ||
let target = {}; | ||
for (let prop in source) { | ||
target[prop] = deepCopy(source[prop]); | ||
} | ||
else if (Array.isArray(source)) { | ||
return [].concat(source); | ||
} | ||
else if (typeof source === 'object') { | ||
var target = {}; | ||
for (var prop in source) { | ||
target[prop] = deepCopy(source[prop]); | ||
} | ||
return target; | ||
} | ||
return source; | ||
return target; | ||
} | ||
return source; | ||
} | ||
var isNaNForST = function (v) { | ||
return isNaN(+v) || ((v[0] === '+' || v[0] === '-') && v[1] === '=') || v === '' || v === ' '; | ||
const isNaNForST = v => | ||
isNaN(+v) || ((v[0] === '+' || v[0] === '-') && v[1] === '=') || v === '' || v === ' '; | ||
const hexColor = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i; | ||
const hex2rgb = (all, hex) => { | ||
let r; | ||
let g; | ||
let b; | ||
if (hex.length === 3) { | ||
r = hex[0]; | ||
g = hex[1]; | ||
b = hex[2]; | ||
hex = r + r + g + g + b + b; | ||
} | ||
let color = parseInt(hex, 16); | ||
r = color >> 16 & 255; | ||
g = color >> 8 & 255; | ||
b = color & 255; | ||
return "rgb(" + r + "," + g + "," + b + ")"; | ||
}; | ||
var hexColor = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i; | ||
var hex2rgb = function (all, hex) { | ||
var r; | ||
var g; | ||
var b; | ||
if (hex.length === 3) { | ||
r = hex[0]; | ||
g = hex[1]; | ||
b = hex[2]; | ||
hex = r + r + g + g + b + b; | ||
} | ||
var color = parseInt(hex, 16); | ||
r = color >> 16 & 255; | ||
g = color >> 8 & 255; | ||
b = color & 255; | ||
return "rgb(" + r + "," + g + "," + b + ")"; | ||
}; | ||
export function decomposeString(fromValue) { | ||
return typeof fromValue !== 'string' ? fromValue : fromValue.replace(hexColor, hex2rgb).match(NUM_REGEX).map(function (v) { return (isNaNForST(v) ? v : +v); }); | ||
return typeof fromValue !== 'string' ? fromValue : fromValue.replace(hexColor, hex2rgb).match(NUM_REGEX).map(v => (isNaNForST(v) ? v : +v)); | ||
} | ||
// Decompose value, now for only `string` that required | ||
export function decompose(prop, obj, from, to, stringBuffer) { | ||
var fromValue = from[prop]; | ||
var toValue = to[prop]; | ||
if (typeof fromValue === 'string' || typeof toValue === 'string') { | ||
var fromValue1 = Array.isArray(fromValue) && fromValue[0] === STRING_PROP ? fromValue : decomposeString(fromValue); | ||
var toValue1 = Array.isArray(toValue) && toValue[0] === STRING_PROP ? toValue : decomposeString(toValue); | ||
var i = 1; | ||
while (i < fromValue1.length) { | ||
if (fromValue1[i] === toValue1[i] && typeof fromValue1[i - 1] === 'string') { | ||
fromValue1.splice(i - 1, 2, fromValue1[i - 1] + fromValue1[i]); | ||
toValue1.splice(i - 1, 2, toValue1[i - 1] + toValue1[i]); | ||
} | ||
else { | ||
i++; | ||
} | ||
} | ||
i = 0; | ||
if (fromValue1[0] === STRING_PROP) { | ||
fromValue1.shift(); | ||
} | ||
if (toValue1[0] === STRING_PROP) { | ||
toValue1.shift(); | ||
} | ||
var fromValue2 = { isString: true, length: fromValue1.length }; | ||
var toValue2 = { isString: true, length: toValue1.length }; | ||
while (i < fromValue2.length) { | ||
fromValue2[i] = fromValue1[i]; | ||
toValue2[i] = toValue1[i]; | ||
i++; | ||
} | ||
from[prop] = fromValue2; | ||
to[prop] = toValue2; | ||
return true; | ||
const fromValue = from[prop]; | ||
const toValue = to[prop]; | ||
if (typeof fromValue === 'string' || typeof toValue === 'string') { | ||
let fromValue1 = Array.isArray(fromValue) && fromValue[0] === STRING_PROP ? fromValue : decomposeString(fromValue); | ||
let toValue1 = Array.isArray(toValue) && toValue[0] === STRING_PROP ? toValue : decomposeString(toValue); | ||
let i = 1; | ||
while (i < fromValue1.length) { | ||
if (fromValue1[i] === toValue1[i] && typeof fromValue1[i - 1] === 'string') { | ||
fromValue1.splice(i - 1, 2, fromValue1[i - 1] + fromValue1[i]) | ||
toValue1.splice(i - 1, 2, toValue1[i - 1] + toValue1[i]) | ||
} else { | ||
i++ | ||
} | ||
} | ||
i = 0; | ||
if (fromValue1[0] === STRING_PROP) { | ||
fromValue1.shift() | ||
} | ||
if (toValue1[0] === STRING_PROP) { | ||
toValue1.shift() | ||
} | ||
let fromValue2 = {isString:true,length:fromValue1.length} | ||
let toValue2 = {isString:true,length:toValue1.length} | ||
while (i < fromValue2.length) { | ||
fromValue2[i] = fromValue1[i] | ||
toValue2[i] = toValue1[i] | ||
i++ | ||
} | ||
from[prop] = fromValue2; | ||
to[prop] = toValue2; | ||
return true; | ||
} else if (typeof fromValue === 'object' && typeof toValue === 'object') { | ||
if (Array.isArray(fromValue)) { | ||
return fromValue.map((v, i) => | ||
decompose(i, obj[prop], fromValue, toValue) | ||
); | ||
} else { | ||
for (let prop2 in toValue) { | ||
decompose(prop2, obj[prop], fromValue, toValue); | ||
} | ||
} | ||
else if (typeof fromValue === 'object' && typeof toValue === 'object') { | ||
if (Array.isArray(fromValue)) { | ||
return fromValue.map(function (v, i) { | ||
return decompose(i, obj[prop], fromValue, toValue); | ||
}); | ||
} | ||
else { | ||
for (var prop2 in toValue) { | ||
decompose(prop2, obj[prop], fromValue, toValue); | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
return true; | ||
} | ||
return false; | ||
} | ||
// Recompose value | ||
export var DECIMAL = Math.pow(10, 4); | ||
export var RGB = 'rgb('; | ||
export var RGBA = 'rgba('; | ||
export var isRGBColor = function (v, i, r) { | ||
if (r === void 0) { r = RGB; } | ||
return typeof v[i] === 'number' && | ||
(v[i - 1] === r || v[i - 3] === r || v[i - 5] === r); | ||
}; | ||
export const DECIMAL = Math.pow(10, 4); | ||
export const RGB = 'rgb('; | ||
export const RGBA = 'rgba('; | ||
export const isRGBColor = (v, i, r = RGB) => | ||
typeof v[i] === 'number' && | ||
(v[i - 1] === r || v[i - 3] === r || v[i - 5] === r); | ||
export function recompose(prop, obj, from, to, t, originalT, stringBuffer) { | ||
var fromValue = stringBuffer ? from : from[prop]; | ||
var toValue = stringBuffer ? to : to[prop]; | ||
if (toValue === undefined) { | ||
return fromValue; | ||
const fromValue = stringBuffer ? from : from[prop]; | ||
const toValue = stringBuffer ? to : to[prop]; | ||
if (toValue === undefined) { | ||
return fromValue; | ||
} | ||
if ( | ||
fromValue === undefined || | ||
typeof fromValue === 'string' || | ||
fromValue === toValue | ||
) { | ||
return toValue; | ||
} else if (typeof fromValue === 'object' && typeof toValue === 'object') { | ||
if (!fromValue || !toValue) { | ||
return obj[prop]; | ||
} | ||
if (fromValue === undefined || | ||
typeof fromValue === 'string' || | ||
fromValue === toValue) { | ||
return toValue; | ||
} | ||
else if (typeof fromValue === 'object' && typeof toValue === 'object') { | ||
if (!fromValue || !toValue) { | ||
return obj[prop]; | ||
if (typeof fromValue === 'object' && !!fromValue && fromValue.isString) { | ||
let STRING_BUFFER = ''; | ||
for (let i = 0, len = fromValue.length; i < len; i++) { | ||
const isRelative = typeof fromValue[i] === 'number' && typeof toValue[i] === 'string' && toValue[i][1] === '='; | ||
let currentValue = | ||
typeof fromValue[i] !== 'number' | ||
? fromValue[i] | ||
: (((isRelative | ||
? fromValue[i] + | ||
parseFloat(toValue[i][0] + toValue[i].substr(2)) * t | ||
: fromValue[i] + (toValue[i] - fromValue[i]) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (isRGBColor(fromValue, i) || isRGBColor(fromValue, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
if (typeof fromValue === 'object' && !!fromValue && fromValue.isString) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 0, len = fromValue.length; i < len; i++) { | ||
var isRelative = typeof fromValue[i] === 'number' && typeof toValue[i] === 'string' && toValue[i][1] === '='; | ||
var currentValue = typeof fromValue[i] !== 'number' | ||
? fromValue[i] | ||
: (((isRelative | ||
? fromValue[i] + | ||
parseFloat(toValue[i][0] + toValue[i].substr(2)) * t | ||
: fromValue[i] + (toValue[i] - fromValue[i]) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (isRGBColor(fromValue, i) || isRGBColor(fromValue, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
if (isRelative && originalT === 1) { | ||
fromValue[i] = | ||
fromValue[i] + | ||
parseFloat(toValue[i][0] + toValue[i].substr(2)); | ||
} | ||
} | ||
if (!stringBuffer) { | ||
obj[prop] = STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
STRING_BUFFER += currentValue; | ||
if (isRelative && originalT === 1) { | ||
fromValue[i] = | ||
fromValue[i] + | ||
parseFloat(toValue[i][0] + toValue[i].substr(2)); | ||
} | ||
else if (Array.isArray(fromValue) && fromValue[0] !== STRING_PROP) { | ||
for (var i = 0, len = fromValue.length; i < len; i++) { | ||
if (fromValue[i] === toValue[i]) { | ||
continue; | ||
} | ||
recompose(i, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
} | ||
if (!stringBuffer) { | ||
obj[prop] = STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
} else if (Array.isArray(fromValue) && fromValue[0] !== STRING_PROP) { | ||
for (let i = 0, len = fromValue.length; i < len; i++) { | ||
if (fromValue[i] === toValue[i]) { | ||
continue; | ||
} | ||
else if (typeof fromValue === 'object' && !!fromValue && !fromValue.isString) { | ||
for (var i in fromValue) { | ||
if (fromValue[i] === toValue[i]) { | ||
continue; | ||
} | ||
recompose(i, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
recompose(i, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
} else if (typeof fromValue === 'object' && !!fromValue && !fromValue.isString) { | ||
for (let i in fromValue) { | ||
if (fromValue[i] === toValue[i]) { | ||
continue; | ||
} | ||
recompose(i, obj[prop], fromValue, toValue, t, originalT); | ||
} | ||
} | ||
else if (typeof fromValue === 'number') { | ||
var isRelative = typeof toValue === 'string'; | ||
obj[prop] = | ||
(((isRelative | ||
? fromValue + parseFloat(toValue[0] + toValue.substr(2)) * t | ||
: fromValue + (toValue - fromValue) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (isRelative && originalT === 1) { | ||
from[prop] = obj[prop]; | ||
} | ||
} else if (typeof fromValue === 'number') { | ||
const isRelative = typeof toValue === 'string'; | ||
obj[prop] = | ||
(((isRelative | ||
? fromValue + parseFloat(toValue[0] + toValue.substr(2)) * t | ||
: fromValue + (toValue - fromValue) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (isRelative && originalT === 1) { | ||
from[prop] = obj[prop]; | ||
} | ||
else if (typeof toValue === 'function') { | ||
obj[prop] = toValue(t); | ||
} | ||
return obj[prop]; | ||
} else if (typeof toValue === 'function') { | ||
obj[prop] = toValue(t); | ||
} | ||
return obj[prop]; | ||
} | ||
// Dot notation => Object structure converter | ||
@@ -203,80 +211,75 @@ // example | ||
// Only works for 3-level parsing, after 3-level, parsing dot-notation not works as it's not affects | ||
var propRegExp = /([.\[])/g; | ||
var replaceBrace = /\]/g; | ||
var propExtract = function (obj, property) { | ||
var value = obj[property]; | ||
var props = property.replace(replaceBrace, '').split(propRegExp); | ||
var propsLastIndex = props.length - 1; | ||
var lastArr = Array.isArray(obj); | ||
var lastObj = typeof obj === 'object' && !lastArr; | ||
if (lastObj) { | ||
obj[property] = null; | ||
delete obj[property]; | ||
const propRegExp = /([.\[])/g; | ||
const replaceBrace = /\]/g; | ||
const propExtract = function(obj, property) { | ||
const value = obj[property]; | ||
const props = property.replace(replaceBrace, '').split(propRegExp); | ||
const propsLastIndex = props.length - 1; | ||
let lastArr = Array.isArray(obj); | ||
let lastObj = typeof obj === 'object' && !lastArr; | ||
if (lastObj) { | ||
obj[property] = null; | ||
delete obj[property]; | ||
} else if (lastArr) { | ||
obj.splice(property, 1); | ||
} | ||
return props.reduce((nested, prop, index) => { | ||
if (lastArr) { | ||
if (prop !== '.' && prop !== '[') { | ||
prop *= 1; | ||
} | ||
} | ||
else if (lastArr) { | ||
obj.splice(property, 1); | ||
let nextProp = props[index + 1]; | ||
let nextIsArray = nextProp === '['; | ||
if (prop === '.' || prop === '[') { | ||
if (prop === '.') { | ||
lastObj = true; | ||
lastArr = false; | ||
} else if (prop === '[') { | ||
lastObj = false; | ||
lastArr = true; | ||
} | ||
return nested; | ||
} else if (nested[prop] === undefined) { | ||
if (lastArr || lastObj) { | ||
nested[prop] = | ||
index === propsLastIndex | ||
? value | ||
: lastArr || nextIsArray ? [] : lastObj ? {} : null; | ||
lastObj = lastArr = false; | ||
return nested[prop]; | ||
} | ||
} else if (nested[prop] !== undefined) { | ||
if (index === propsLastIndex) { | ||
nested[prop] = value; | ||
} | ||
return nested[prop]; | ||
} | ||
return props.reduce(function (nested, prop, index) { | ||
if (lastArr) { | ||
if (prop !== '.' && prop !== '[') { | ||
prop *= 1; | ||
} | ||
} | ||
var nextProp = props[index + 1]; | ||
var nextIsArray = nextProp === '['; | ||
if (prop === '.' || prop === '[') { | ||
if (prop === '.') { | ||
lastObj = true; | ||
lastArr = false; | ||
} | ||
else if (prop === '[') { | ||
lastObj = false; | ||
lastArr = true; | ||
} | ||
return nested; | ||
} | ||
else if (nested[prop] === undefined) { | ||
if (lastArr || lastObj) { | ||
nested[prop] = | ||
index === propsLastIndex | ||
? value | ||
: lastArr || nextIsArray ? [] : lastObj ? {} : null; | ||
lastObj = lastArr = false; | ||
return nested[prop]; | ||
} | ||
} | ||
else if (nested[prop] !== undefined) { | ||
if (index === propsLastIndex) { | ||
nested[prop] = value; | ||
} | ||
return nested[prop]; | ||
} | ||
return nested; | ||
}, obj); | ||
return nested; | ||
}, obj); | ||
}; | ||
export var SET_NESTED = function (nested) { | ||
if (typeof nested === 'object' && !!nested) { | ||
for (var prop in nested) { | ||
if (prop.indexOf('.') !== -1 || prop.indexOf('[') !== -1) { | ||
propExtract(nested, prop); | ||
export const SET_NESTED = function(nested) { | ||
if (typeof nested === 'object' && !!nested) { | ||
for (let prop in nested) { | ||
if (prop.indexOf('.') !== -1 || prop.indexOf('[') !== -1) { | ||
propExtract(nested, prop); | ||
} else if (typeof nested[prop] === 'object' && !!nested[prop]) { | ||
let nested2 = nested[prop]; | ||
for (let prop2 in nested2) { | ||
if (prop2.indexOf('.') !== -1 || prop2.indexOf('[') !== -1) { | ||
propExtract(nested2, prop2); | ||
} else if (typeof nested2[prop2] === 'object' && !!nested2[prop2]) { | ||
let nested3 = nested2[prop2]; | ||
for (let prop3 in nested3) { | ||
if (prop3.indexOf('.') !== -1 || prop3.indexOf('[') !== -1) { | ||
propExtract(nested3, prop3); | ||
} | ||
} | ||
else if (typeof nested[prop] === 'object' && !!nested[prop]) { | ||
var nested2 = nested[prop]; | ||
for (var prop2 in nested2) { | ||
if (prop2.indexOf('.') !== -1 || prop2.indexOf('[') !== -1) { | ||
propExtract(nested2, prop2); | ||
} | ||
else if (typeof nested2[prop2] === 'object' && !!nested2[prop2]) { | ||
var nested3 = nested2[prop2]; | ||
for (var prop3 in nested3) { | ||
if (prop3.indexOf('.') !== -1 || prop3.indexOf('[') !== -1) { | ||
propExtract(nested3, prop3); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return nested; | ||
} | ||
return nested; | ||
}; |
217
src/core.js
/* global process */ | ||
import { cancelAnimationFrame, requestAnimationFrame, root } from './shim'; | ||
/** | ||
@@ -10,29 +11,32 @@ * Get browser/Node.js current time-stamp | ||
*/ | ||
var now = (function () { | ||
if (typeof process !== 'undefined' && process.hrtime !== undefined && (!process.versions || process.versions.electron === 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. | ||
} | ||
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_1 = root.performance && | ||
root.performance.timing && | ||
root.performance.timing.navigationStart | ||
? root.performance.timing.navigationStart | ||
: Date.now(); | ||
return function () { | ||
return Date.now() - offset_1; | ||
}; | ||
} | ||
const now = (function() { | ||
if (typeof process !== 'undefined' && process.hrtime !== undefined && (!process.versions || process.versions.electron === undefined)) { | ||
return function() { | ||
const 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. | ||
} 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 { | ||
const offset = | ||
root.performance && | ||
root.performance.timing && | ||
root.performance.timing.navigationStart | ||
? root.performance.timing.navigationStart | ||
: Date.now(); | ||
return function() { | ||
return Date.now() - offset; | ||
}; | ||
} | ||
})(); | ||
/** | ||
@@ -47,10 +51,11 @@ * Lightweight, effecient and modular ES6 version of tween.js | ||
*/ | ||
var _tweens = []; | ||
var isStarted = false; | ||
var _autoPlay = false; | ||
var _tick; | ||
var _ticker = requestAnimationFrame; | ||
var _stopTicker = cancelAnimationFrame; | ||
var emptyFrame = 0; | ||
var powerModeThrottle = 120; | ||
const _tweens = []; | ||
let isStarted = false; | ||
let _autoPlay = false; | ||
let _tick; | ||
const _ticker = requestAnimationFrame; | ||
const _stopTicker = cancelAnimationFrame; | ||
let emptyFrame = 0; | ||
let powerModeThrottle = 120; | ||
/** | ||
@@ -65,14 +70,19 @@ * Adds tween to list | ||
*/ | ||
var add = function (tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i > -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
_tweens.push(tween); | ||
emptyFrame = 0; | ||
if (_autoPlay && !isStarted) { | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
const add = (tween) => { | ||
let i = _tweens.indexOf(tween); | ||
if (i > -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
_tweens.push(tween); | ||
emptyFrame = 0; | ||
if (_autoPlay && !isStarted) { | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
}; | ||
/** | ||
@@ -85,3 +95,4 @@ * Adds ticker like event | ||
*/ | ||
var onTick = function (fn) { return _tweens.push({ update: fn }); }; | ||
const onTick = (fn) => _tweens.push({ update: fn }); | ||
/** | ||
@@ -94,6 +105,6 @@ * Sets after how much frames empty updating should stop | ||
*/ | ||
var FrameThrottle = function (frameCount) { | ||
if (frameCount === void 0) { frameCount = 120; } | ||
powerModeThrottle = frameCount; | ||
const FrameThrottle = (frameCount = 120) => { | ||
powerModeThrottle = frameCount; | ||
}; | ||
/** | ||
@@ -104,3 +115,4 @@ * @returns {Array<Tween>} List of tweens in Array | ||
*/ | ||
var getAll = function () { return _tweens; }; | ||
const getAll = () => _tweens; | ||
/** | ||
@@ -112,5 +124,6 @@ * Runs update loop automaticlly | ||
*/ | ||
var autoPlay = function (state) { | ||
_autoPlay = state; | ||
const autoPlay = (state) => { | ||
_autoPlay = state; | ||
}; | ||
/** | ||
@@ -121,5 +134,6 @@ * Removes all tweens from list | ||
*/ | ||
var removeAll = function () { | ||
_tweens.length = 0; | ||
const removeAll = () => { | ||
_tweens.length = 0; | ||
}; | ||
/** | ||
@@ -132,10 +146,12 @@ * @param {Tween} tween Tween Instance to be matched | ||
*/ | ||
var get = function (tween) { | ||
for (var i = 0; i < _tweens.length; i++) { | ||
if (tween === _tweens[i]) { | ||
return _tweens[i]; | ||
} | ||
const get = (tween) => { | ||
for (let i = 0; i < _tweens.length; i++) { | ||
if (tween === _tweens[i]) { | ||
return _tweens[i]; | ||
} | ||
return null; | ||
} | ||
return null; | ||
}; | ||
/** | ||
@@ -148,4 +164,4 @@ * @param {Tween} tween Tween Instance to be matched | ||
*/ | ||
var has = function (tween) { | ||
return get(tween) !== null; | ||
const has = (tween) => { | ||
return get(tween) !== null; | ||
}; | ||
@@ -159,8 +175,9 @@ /** | ||
*/ | ||
var remove = function (tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i !== -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
const remove = (tween) => { | ||
const i = _tweens.indexOf(tween); | ||
if (i !== -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
}; | ||
/** | ||
@@ -174,23 +191,28 @@ * Updates global tweens by given time | ||
*/ | ||
var update = function (time, preserve) { | ||
time = time !== undefined ? time : now(); | ||
if (_autoPlay && isStarted) { | ||
_tick = _ticker(update); | ||
} | ||
if (!_tweens.length) { | ||
emptyFrame++; | ||
} | ||
if (emptyFrame > powerModeThrottle) { | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
emptyFrame = 0; | ||
return false; | ||
} | ||
var i = 0; | ||
var tween; | ||
while (i < _tweens.length) { | ||
_tweens[i++].update(time, preserve); | ||
} | ||
return true; | ||
const update = (time = now(), preserve) => { | ||
if (_autoPlay && isStarted) { | ||
_tick = _ticker(update); | ||
} | ||
if (!_tweens.length) { | ||
emptyFrame++; | ||
} | ||
if (emptyFrame > powerModeThrottle) { | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
emptyFrame = 0; | ||
return false; | ||
} | ||
let i = 0; | ||
let tween; | ||
while (i < _tweens.length) { | ||
_tweens[i++].update(time, preserve); | ||
} | ||
return true; | ||
}; | ||
/** | ||
@@ -202,3 +224,4 @@ * The state of ticker running | ||
*/ | ||
var isRunning = function () { return isStarted; }; | ||
const isRunning = () => isStarted; | ||
/** | ||
@@ -215,3 +238,17 @@ * The plugins store object | ||
*/ | ||
var Plugins = {}; | ||
export { Plugins, get, has, getAll, removeAll, remove, add, now, update, autoPlay, onTick, isRunning, }; | ||
const Plugins = {}; | ||
export { | ||
Plugins, | ||
get, | ||
has, | ||
getAll, | ||
removeAll, | ||
remove, | ||
add, | ||
now, | ||
update, | ||
autoPlay, | ||
onTick, | ||
isRunning, | ||
}; |
@@ -9,188 +9,242 @@ /** | ||
*/ | ||
var Easing = { | ||
Linear: { | ||
None: function (k) { | ||
return k; | ||
} | ||
const Easing = { | ||
Linear: { | ||
None(k) { | ||
return k; | ||
}, | ||
Quadratic: { | ||
In: function (k) { | ||
return k * k; | ||
}, | ||
Out: function (k) { | ||
return k * (2 - k); | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k; | ||
} | ||
return -0.5 * (--k * (k - 2) - 1); | ||
} | ||
}, | ||
Quadratic: { | ||
In(k) { | ||
return k * k; | ||
}, | ||
Cubic: { | ||
In: function (k) { | ||
return k * k * k; | ||
}, | ||
Out: function (k) { | ||
return --k * k * k + 1; | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k; | ||
} | ||
return 0.5 * ((k -= 2) * k * k + 2); | ||
} | ||
Out(k) { | ||
return k * (2 - k); | ||
}, | ||
Quartic: { | ||
In: function (k) { | ||
return k * k * k * k; | ||
}, | ||
Out: function (k) { | ||
return 1 - --k * k * k * k; | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k; | ||
} | ||
return -0.5 * ((k -= 2) * k * k * k - 2); | ||
} | ||
InOut(k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k; | ||
} | ||
return -0.5 * (--k * (k - 2) - 1); | ||
}, | ||
Quintic: { | ||
In: function (k) { | ||
return k * k * k * k * k; | ||
}, | ||
Out: function (k) { | ||
return --k * k * k * k * k + 1; | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k * k; | ||
} | ||
return 0.5 * ((k -= 2) * k * k * k * k + 2); | ||
} | ||
}, | ||
Cubic: { | ||
In(k) { | ||
return k * k * k; | ||
}, | ||
Sinusoidal: { | ||
In: function (k) { | ||
return 1 - Math.cos(k * Math.PI / 2); | ||
}, | ||
Out: function (k) { | ||
return Math.sin(k * Math.PI / 2); | ||
}, | ||
InOut: function (k) { | ||
return 0.5 * (1 - Math.cos(Math.PI * k)); | ||
} | ||
Out(k) { | ||
return --k * k * k + 1; | ||
}, | ||
Exponential: { | ||
In: function (k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1); | ||
}, | ||
Out: function (k) { | ||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k); | ||
}, | ||
InOut: function (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); | ||
} | ||
InOut(k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k; | ||
} | ||
return 0.5 * ((k -= 2) * k * k + 2); | ||
}, | ||
Circular: { | ||
In: function (k) { | ||
return 1 - Math.sqrt(1 - k * k); | ||
}, | ||
Out: function (k) { | ||
return Math.sqrt(1 - --k * k); | ||
}, | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
return -0.5 * (Math.sqrt(1 - k * k) - 1); | ||
} | ||
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1); | ||
} | ||
}, | ||
Quartic: { | ||
In(k) { | ||
return k * k * k * k; | ||
}, | ||
Elastic: { | ||
In: function (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 (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 (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(k) { | ||
return 1 - --k * k * k * k; | ||
}, | ||
Back: { | ||
In: function (k) { | ||
var s = 1.70158; | ||
return k * k * ((s + 1) * k - s); | ||
}, | ||
Out: function (k) { | ||
var s = 1.70158; | ||
return --k * k * ((s + 1) * k + s) + 1; | ||
}, | ||
InOut: function (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(k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k; | ||
} | ||
return -0.5 * ((k -= 2) * k * k * k - 2); | ||
}, | ||
Bounce: { | ||
In: function (k) { | ||
return 1 - Easing.Bounce.Out(1 - k); | ||
}, | ||
Out: function (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 (k) { | ||
if (k < 0.5) { | ||
return Easing.Bounce.In(k * 2) * 0.5; | ||
} | ||
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; | ||
} | ||
}, | ||
Quintic: { | ||
In(k) { | ||
return k * k * k * k * k; | ||
}, | ||
Stepped: { | ||
steps: function (steps) { return function (k) { return ((k * steps) | 0) / steps; }; } | ||
Out(k) { | ||
return --k * k * k * k * k + 1; | ||
}, | ||
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(k) { | ||
return 1 - Math.cos(k * Math.PI / 2); | ||
}, | ||
Out(k) { | ||
return Math.sin(k * Math.PI / 2); | ||
}, | ||
InOut(k) { | ||
return 0.5 * (1 - Math.cos(Math.PI * k)); | ||
}, | ||
}, | ||
Exponential: { | ||
In(k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1); | ||
}, | ||
Out(k) { | ||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k); | ||
}, | ||
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(k) { | ||
return 1 - Math.sqrt(1 - k * k); | ||
}, | ||
Out(k) { | ||
return Math.sqrt(1 - --k * k); | ||
}, | ||
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(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(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(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(k) { | ||
const s = 1.70158; | ||
return k * k * ((s + 1) * k - s); | ||
}, | ||
Out(k) { | ||
const s = 1.70158; | ||
return --k * k * ((s + 1) * k + s) + 1; | ||
}, | ||
InOut(k) { | ||
const 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(k) { | ||
return 1 - Easing.Bounce.Out(1 - k); | ||
}, | ||
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(k) { | ||
if (k < 0.5) { | ||
return Easing.Bounce.In(k * 2) * 0.5; | ||
} | ||
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; | ||
} | ||
}, | ||
Stepped: { | ||
steps: steps => k => ((k * steps) | 0) / steps, | ||
}, | ||
}; | ||
export default Easing; |
@@ -1,2 +0,15 @@ | ||
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update, } from './core'; | ||
import { | ||
add, | ||
onTick, | ||
autoPlay, | ||
get, | ||
getAll, | ||
has, | ||
isRunning, | ||
now, | ||
Plugins, | ||
remove, | ||
removeAll, | ||
update, | ||
} from './core'; | ||
import Easing from './Easing'; | ||
@@ -8,2 +21,20 @@ import Interpolation from './Interpolation'; | ||
import './shim'; | ||
export { Plugins, Selector, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Interpolation }; | ||
export { | ||
Plugins, | ||
Selector, | ||
Interpolator, | ||
onTick, | ||
has, | ||
get, | ||
getAll, | ||
removeAll, | ||
remove, | ||
add, | ||
now, | ||
update, | ||
autoPlay, | ||
isRunning, | ||
Tween, | ||
Easing, | ||
Interpolation | ||
}; |
@@ -1,2 +0,3 @@ | ||
import { isRGBColor, RGBA, STRING_PROP } from './constants'; | ||
import { isRGBColor, RGBA, recompose, STRING_PROP } from './constants'; | ||
/** | ||
@@ -12,189 +13,239 @@ * List of full Interpolation | ||
*/ | ||
var Interpolation = { | ||
Linear: function (v, k, value) { | ||
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, value); | ||
const Interpolation = { | ||
Linear(v, k, value) { | ||
const m = v.length - 1; | ||
const f = m * k; | ||
const i = Math.floor(f); | ||
const fn = Interpolation.Utils.Linear; | ||
if (k < 0) { | ||
return fn(v[0], v[1], f, value); | ||
} | ||
if (k > 1) { | ||
return fn(v[m], v[m - 1], m - f, value); | ||
} | ||
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i, value); | ||
}, | ||
Bezier(v, k, value) { | ||
let b = Interpolation.Utils.Reset(value); | ||
let n = v.length - 1; | ||
let pw = Math.pow; | ||
let fn = Interpolation.Utils.Bernstein; | ||
let isBArray = Array.isArray(b); | ||
for (let i = 0; i <= n; i++) { | ||
if (typeof b === 'number') { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * fn(n, i); | ||
} else if (isBArray) { | ||
for (let p = 0, len = b.length; p < len; p++) { | ||
if (typeof b[p] === 'number') { | ||
b[p] += pw(1 - k, n - i) * pw(k, i) * v[i][p] * fn(n, i); | ||
} else { | ||
b[p] = v[i][p]; | ||
} | ||
} | ||
if (k > 1) { | ||
return fn(v[m], v[m - 1], m - f, value); | ||
} else if (typeof b === 'object') { | ||
for (let p in b) { | ||
if (typeof b[p] === 'number') { | ||
b[p] += pw(1 - k, n - i) * pw(k, i) * v[i][p] * fn(n, i); | ||
} else { | ||
b[p] = v[i][p]; | ||
} | ||
} | ||
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i, value); | ||
}, | ||
Bezier: function (v, k, value) { | ||
var b = Interpolation.Utils.Reset(value); | ||
var n = v.length - 1; | ||
var pw = Math.pow; | ||
var fn = Interpolation.Utils.Bernstein; | ||
var isBArray = Array.isArray(b); | ||
for (var i = 0; i <= n; i++) { | ||
if (typeof b === 'number') { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * fn(n, i); | ||
} else if (typeof b === 'string') { | ||
let STRING_BUFFER = '', | ||
idx = Math.round(n * k), | ||
pidx = idx - 1 < 0 ? 0 : idx - 1, | ||
nidx = idx + 1 > n ? n : idx + 1, | ||
vCurr = v[idx], | ||
vPrev = v[pidx]; | ||
for (let ks = 1, len = vCurr.length; ks < len; ks++) { | ||
STRING_BUFFER += vCurr[ks]; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
} | ||
return b; | ||
}, | ||
CatmullRom(v, k, value) { | ||
const m = v.length - 1; | ||
let f = m * k; | ||
let i = Math.floor(f); | ||
const 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, | ||
value | ||
); | ||
} else { | ||
if (k < 0) { | ||
return fn(v[1], v[1], v[0], v[0], -k, value); | ||
} | ||
if (k > 1) { | ||
return fn(v[m - 1], v[m - 1], v[m], v[m], (k | 0) - k, value); | ||
} | ||
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, | ||
value | ||
); | ||
} | ||
}, | ||
Utils: { | ||
Linear(p0, p1, t, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} else if (typeof p0 === 'number') { | ||
return typeof p0 === 'function' ? p0(t) : p0 + (p1 - p0) * t; | ||
} else if (typeof p0 === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
let STRING_BUFFER = ''; | ||
for (let i = 1, len = p0.length; i < len; i++) { | ||
let currentValue = | ||
typeof p0[i] === 'number' ? p0[i] + (p1[i] - p0[i]) * t : p1[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
else if (isBArray) { | ||
for (var p = 0, len = b.length; p < len; p++) { | ||
if (typeof b[p] === 'number') { | ||
b[p] += pw(1 - k, n - i) * pw(k, i) * v[i][p] * fn(n, i); | ||
} | ||
else { | ||
b[p] = v[i][p]; | ||
} | ||
} | ||
} | ||
else if (typeof b === 'object') { | ||
for (var p in b) { | ||
if (typeof b[p] === 'number') { | ||
b[p] += pw(1 - k, n - i) * pw(k, i) * v[i][p] * fn(n, i); | ||
} | ||
else { | ||
b[p] = v[i][p]; | ||
} | ||
} | ||
} | ||
else if (typeof b === 'string') { | ||
var STRING_BUFFER = '', idx = Math.round(n * k), pidx = idx - 1 < 0 ? 0 : idx - 1, nidx = idx + 1 > n ? n : idx + 1, vCurr = v[idx], vPrev = v[pidx]; | ||
for (var ks = 1, len = vCurr.length; ks < len; ks++) { | ||
STRING_BUFFER += vCurr[ks]; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (let p = 0, len = v.length; p < len; p++) { | ||
v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
} | ||
} else { | ||
for (const p in v) { | ||
v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
} | ||
} | ||
return b; | ||
return v; | ||
} | ||
}, | ||
CatmullRom: function (v, k, value) { | ||
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, value); | ||
Reset(value) { | ||
if (Array.isArray(value)) { | ||
for (let i = 0, len = value.length; i < len; i++) { | ||
value[i] = Interpolation.Utils.Reset(value[i]); | ||
} | ||
else { | ||
if (k < 0) { | ||
return fn(v[1], v[1], v[0], v[0], -k, value); | ||
} | ||
if (k > 1) { | ||
return fn(v[m - 1], v[m - 1], v[m], v[m], (k | 0) - k, value); | ||
} | ||
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, value); | ||
return value; | ||
} else if (typeof value === 'object') { | ||
for (let i in value) { | ||
value[i] = Interpolation.Utils.Reset(value[i]); | ||
} | ||
return value; | ||
} else if (typeof value === 'number') { | ||
return 0; | ||
} | ||
return value; | ||
}, | ||
Utils: { | ||
Linear: function (p0, p1, t, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
Bernstein(n, i) { | ||
const fc = Interpolation.Utils.Factorial; | ||
return fc(n) / fc(i) / fc(n - i); | ||
}, | ||
Factorial: (function() { | ||
const a = [1]; | ||
return n => { | ||
let s = 1; | ||
if (a[n]) { | ||
return a[n]; | ||
} | ||
for (let i = n; i > 1; i--) { | ||
s *= i; | ||
} | ||
a[n] = s; | ||
return s; | ||
}; | ||
})(), | ||
CatmullRom(p0, p1, p2, p3, t, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} else if (typeof p0 === 'number') { | ||
const v0 = (p2 - p0) * 0.5; | ||
const v1 = (p3 - p1) * 0.5; | ||
const t2 = t * t; | ||
const t3 = t * t2; | ||
return ( | ||
(2 * p1 - 2 * p2 + v0 + v1) * t3 + | ||
(-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + | ||
v0 * t + | ||
p1 | ||
); | ||
} else if (typeof p0 === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
let STRING_BUFFER = ''; | ||
for (let i = 1, len = p0.length; i < len; i++) { | ||
let currentValue = | ||
typeof p0[i] === 'number' | ||
? Interpolation.Utils.CatmullRom( | ||
p0[i], | ||
p1[i], | ||
p2[i], | ||
p3[i], | ||
t | ||
) | ||
: p3[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
else if (typeof p0 === 'number') { | ||
return typeof p0 === 'function' ? p0(t) : p0 + (p1 - p0) * t; | ||
} | ||
else if (typeof p0 === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = p0.length; i < len; i++) { | ||
var currentValue = typeof p0[i] === 'number' ? p0[i] + (p1[i] - p0[i]) * t : p1[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (var p = 0, len = v.length; p < len; p++) { | ||
v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
} | ||
} | ||
else { | ||
for (var p in v) { | ||
v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
} | ||
} | ||
return v; | ||
} | ||
}, | ||
Reset: function (value) { | ||
if (Array.isArray(value)) { | ||
for (var i = 0, len = value.length; i < len; i++) { | ||
value[i] = Interpolation.Utils.Reset(value[i]); | ||
} | ||
return value; | ||
} | ||
else if (typeof value === 'object') { | ||
for (var i in value) { | ||
value[i] = Interpolation.Utils.Reset(value[i]); | ||
} | ||
return value; | ||
} | ||
else if (typeof value === 'number') { | ||
return 0; | ||
} | ||
return value; | ||
}, | ||
Bernstein: function (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 (p0, p1, p2, p3, t, v) { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} | ||
else if (typeof p0 === 'number') { | ||
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); | ||
} | ||
else if (typeof p0 === 'object') { | ||
if (p0.length !== undefined) { | ||
if (p0[0] === STRING_PROP) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = p0.length; i < len; i++) { | ||
var currentValue = typeof p0[i] === 'number' | ||
? Interpolation.Utils.CatmullRom(p0[i], p1[i], p2[i], p3[i], t) | ||
: p3[i]; | ||
if (isRGBColor(p0, i) || isRGBColor(p0, i, RGBA)) { | ||
currentValue |= 0; | ||
} | ||
STRING_BUFFER += currentValue; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (var p = 0, len = v.length; p < len; p++) { | ||
v[p] = Interpolation.Utils.CatmullRom(p0[p], p1[p], p2[p], p3[p], t, v[p]); | ||
} | ||
} | ||
else { | ||
for (var p in v) { | ||
v[p] = Interpolation.Utils.CatmullRom(p0[p], p1[p], p2[p], p3[p], t, v[p]); | ||
} | ||
} | ||
return v; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
for (let p = 0, len = v.length; p < len; p++) { | ||
v[p] = Interpolation.Utils.CatmullRom( | ||
p0[p], | ||
p1[p], | ||
p2[p], | ||
p3[p], | ||
t, | ||
v[p] | ||
); | ||
} | ||
} else { | ||
for (const p in v) { | ||
v[p] = Interpolation.Utils.CatmullRom( | ||
p0[p], | ||
p1[p], | ||
p2[p], | ||
p3[p], | ||
t, | ||
v[p] | ||
); | ||
} | ||
} | ||
} | ||
return v; | ||
} | ||
}, | ||
}, | ||
}; | ||
export default Interpolation; |
@@ -1,10 +0,3 @@ | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
import { decompose, recompose, decomposeString } from './constants'; | ||
import { decompose, recompose, decomposeString, STRING_PROP } from './constants' | ||
/** | ||
@@ -18,53 +11,52 @@ * Tween helper for plugins | ||
*/ | ||
var Interpolator = function (a, b) { | ||
var isArray = Array.isArray(a); | ||
var origin = typeof a === 'string' ? a : isArray ? a.slice() : __assign({}, a); | ||
if (isArray) { | ||
for (var i = 0, len = a.length; i < len; i++) { | ||
decompose(i, origin, a, b); | ||
} | ||
} | ||
else if (typeof a === 'object') { | ||
for (var i in a) { | ||
decompose(i, origin, a, b); | ||
} | ||
} | ||
else if (typeof a === 'string') { | ||
a = decomposeString(a); | ||
b = decomposeString(b); | ||
var i = 1; | ||
while (i < a.length) { | ||
if (a[i] === b[i] && typeof a[i - 1] === 'string') { | ||
a.splice(i - 1, 2, a[i - 1] + a[i]); | ||
b.splice(i - 1, 2, b[i - 1] + b[i]); | ||
} | ||
else { | ||
i++; | ||
} | ||
} | ||
var c = { isString: true, length: a.length }; | ||
var d = { isString: true, length: b.length }; | ||
while (i < c.length) { | ||
c[i] = a[i]; | ||
d[i] = b[i]; | ||
i++; | ||
} | ||
} | ||
return function (t) { | ||
if (isArray) { | ||
for (var i = 0, len = a.length; i < len; i++) { | ||
recompose(i, origin, a, b, t); | ||
} | ||
} | ||
else if (typeof origin === 'object') { | ||
for (var i in a) { | ||
recompose(i, origin, a, b, t); | ||
} | ||
} | ||
else if (typeof origin === 'string') { | ||
origin = recompose(0, 0, a, b, t, t, true); | ||
} | ||
return origin; | ||
}; | ||
}; | ||
export default Interpolator; | ||
const Interpolator = (a, b) => { | ||
let isArray = Array.isArray(a); | ||
let origin = typeof a === 'string' ? a : isArray ? a.slice() : {...a}; | ||
if (isArray) { | ||
for (let i = 0, len = a.length; i < len; i++) { | ||
decompose(i, origin, a, b) | ||
} | ||
} else if (typeof a === 'object') { | ||
for (let i in a) { | ||
decompose(i, origin, a, b) | ||
} | ||
} else if (typeof a === 'string') { | ||
a = decomposeString(a) | ||
b = decomposeString(b) | ||
let i = 1; | ||
while (i < a.length) { | ||
if (a[i] === b[i] && typeof a[i - 1] === 'string') { | ||
a.splice(i - 1, 2, a[i - 1] + a[i]) | ||
b.splice(i - 1, 2, b[i - 1] + b[i]) | ||
} else { | ||
i++ | ||
} | ||
} | ||
let c = {isString:true,length:a.length} | ||
let d = {isString:true,length:b.length} | ||
while (i < c.length) { | ||
c[i] = a[i] | ||
d[i] = b[i] | ||
i++ | ||
} | ||
} | ||
return function (t) { | ||
if (isArray) { | ||
for (let i = 0, len = a.length; i < len; i++) { | ||
recompose(i, origin, a, b, t) | ||
} | ||
} else if (typeof origin === 'object') { | ||
for (let i in a) { | ||
recompose(i, origin, a, b, t) | ||
} | ||
} else if (typeof origin === 'string') { | ||
origin = recompose(0, 0, a, b, t, t, true) | ||
} | ||
return origin; | ||
} | ||
} | ||
export default Interpolator |
@@ -1,46 +0,41 @@ | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
import { remove } from './core'; | ||
export var Store = {}; | ||
export default function (node, object, tween) { | ||
if (!node || !node.nodeType) { | ||
return object; | ||
} | ||
var ID = node.queueID || 'q_' + Date.now(); | ||
if (!node.queueID) { | ||
node.queueID = ID; | ||
} | ||
var storeID = Store[ID]; | ||
if (storeID) { | ||
if (storeID.object === object && | ||
node === storeID.tween.node && | ||
tween._startTime === storeID.tween._startTime) { | ||
remove(storeID.tween); | ||
export const Store = {}; | ||
export default function(node, object, tween) { | ||
if (!node || !node.nodeType) { | ||
return object; | ||
} | ||
const ID = node.queueID || 'q_' + Date.now(); | ||
if (!node.queueID) { | ||
node.queueID = ID; | ||
} | ||
const storeID = Store[ID]; | ||
if (storeID) { | ||
if ( | ||
storeID.object === object && | ||
node === storeID.tween.node && | ||
tween._startTime === storeID.tween._startTime | ||
) { | ||
remove(storeID.tween); | ||
} else if (typeof object === 'object' && !!object && !!storeID.object) { | ||
for (let prop in object) { | ||
if (prop in storeID.object) { | ||
if (tween._startTime === storeID.tween._startTime) { | ||
delete storeID.object[prop]; | ||
} else { | ||
storeID.propNormaliseRequired = true; | ||
} | ||
} | ||
else if (typeof object === 'object' && !!object && !!storeID.object) { | ||
for (var prop in object) { | ||
if (prop in storeID.object) { | ||
if (tween._startTime === storeID.tween._startTime) { | ||
delete storeID.object[prop]; | ||
} | ||
else { | ||
storeID.propNormaliseRequired = true; | ||
} | ||
} | ||
} | ||
storeID.object = __assign({}, storeID.object, object); | ||
} | ||
return storeID.object; | ||
} | ||
storeID.object = {...storeID.object, ...object} | ||
} | ||
if (typeof object === 'object' && !!object) { | ||
Store[ID] = { tween: tween, object: object, propNormaliseRequired: false }; | ||
return Store[ID].object; | ||
} | ||
return object; | ||
return storeID.object; | ||
} | ||
if (typeof object === 'object' && !!object) { | ||
Store[ID] = { tween, object, propNormaliseRequired: false }; | ||
return Store[ID].object; | ||
} | ||
return object; | ||
} |
@@ -1,69 +0,65 @@ | ||
var PlaybackPosition = /** @class */ (function () { | ||
function PlaybackPosition() { | ||
this.totalTime = 0; | ||
this.labels = []; | ||
this.offsets = []; | ||
export default class PlaybackPosition { | ||
constructor() { | ||
this.totalTime = 0; | ||
this.labels = []; | ||
this.offsets = []; | ||
} | ||
parseLabel(name, offset) { | ||
const { offsets, labels } = this; | ||
let i = labels.indexOf(name); | ||
if ( | ||
typeof name === 'string' && | ||
name.indexOf('=') !== -1 && | ||
!offset && | ||
i === -1 | ||
) { | ||
const rty = name.substr(name.indexOf('=') - 1, 2); | ||
const rt = name.split(rty); | ||
offset = rt.length === 2 ? rty + rt[1] : null; | ||
name = rt[0]; | ||
i = labels.indexOf(name); | ||
} | ||
PlaybackPosition.prototype.parseLabel = function (name, offset) { | ||
var _a = this, offsets = _a.offsets, labels = _a.labels; | ||
var i = labels.indexOf(name); | ||
if (typeof name === 'string' && | ||
name.indexOf('=') !== -1 && | ||
!offset && | ||
i === -1) { | ||
var rty = name.substr(name.indexOf('=') - 1, 2); | ||
var rt = name.split(rty); | ||
offset = rt.length === 2 ? rty + rt[1] : null; | ||
name = rt[0]; | ||
i = labels.indexOf(name); | ||
if (i !== -1 && name) { | ||
let currOffset = offsets[i] || 0; | ||
if (typeof offset === 'number') { | ||
currOffset = offset; | ||
} else if (typeof offset === 'string') { | ||
if (offset.indexOf('=') !== -1) { | ||
const type = offset.charAt(0); | ||
offset = Number(offset.substr(2)); | ||
if (type === '+' || type === '-') { | ||
currOffset += parseFloat(type + offset); | ||
} else if (type === '*') { | ||
currOffset *= offset; | ||
} else if (type === '/') { | ||
currOffset /= offset; | ||
} else if (type === '%') { | ||
currOffset *= offset / 100; | ||
} | ||
} | ||
if (i !== -1 && name) { | ||
var currOffset = offsets[i] || 0; | ||
if (typeof offset === 'number') { | ||
currOffset = offset; | ||
} | ||
else if (typeof offset === 'string') { | ||
if (offset.indexOf('=') !== -1) { | ||
var type = offset.charAt(0); | ||
offset = Number(offset.substr(2)); | ||
if (type === '+' || type === '-') { | ||
currOffset += parseFloat(type + offset); | ||
} | ||
else if (type === '*') { | ||
currOffset *= offset; | ||
} | ||
else if (type === '/') { | ||
currOffset /= offset; | ||
} | ||
else if (type === '%') { | ||
currOffset *= offset / 100; | ||
} | ||
} | ||
} | ||
return currOffset; | ||
} | ||
return typeof offset === 'number' ? offset : 0; | ||
}; | ||
PlaybackPosition.prototype.addLabel = function (name, offset) { | ||
this.labels.push(name); | ||
this.offsets.push(this.parseLabel(name, offset)); | ||
return this; | ||
}; | ||
PlaybackPosition.prototype.setLabel = function (name, offset) { | ||
var i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.offsets.splice(i, 1, this.parseLabel(name, offset)); | ||
} | ||
return this; | ||
}; | ||
PlaybackPosition.prototype.eraseLabel = function (name) { | ||
var i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.labels.splice(i, 1); | ||
this.offsets.splice(i, 1); | ||
} | ||
return this; | ||
}; | ||
return PlaybackPosition; | ||
}()); | ||
export default PlaybackPosition; | ||
} | ||
return currOffset; | ||
} | ||
return typeof offset === 'number' ? offset : 0; | ||
} | ||
addLabel(name, offset) { | ||
this.labels.push(name); | ||
this.offsets.push(this.parseLabel(name, offset)); | ||
return this; | ||
} | ||
setLabel(name, offset) { | ||
const i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.offsets.splice(i, 1, this.parseLabel(name, offset)); | ||
} | ||
return this; | ||
} | ||
eraseLabel(name) { | ||
const i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.labels.splice(i, 1); | ||
this.offsets.splice(i, 1); | ||
} | ||
return this; | ||
} | ||
} |
@@ -1,22 +0,22 @@ | ||
export default function (selector, collection) { | ||
if (collection) { | ||
return !selector | ||
? null | ||
: selector === window || selector === document | ||
? [selector] | ||
: typeof selector === 'string' | ||
? !!document.querySelectorAll && document.querySelectorAll(selector) | ||
: Array.isArray(selector) | ||
? selector | ||
: selector.nodeType ? [selector] : []; | ||
} | ||
export default function(selector, collection) { | ||
if (collection) { | ||
return !selector | ||
? null | ||
: selector === window || selector === document | ||
? null | ||
: selector === window || selector === document | ||
? [selector] | ||
: typeof selector === 'string' | ||
? !!document.querySelectorAll && document.querySelectorAll(selector) | ||
: Array.isArray(selector) | ||
? selector | ||
: typeof selector === 'string' | ||
? !!document.querySelector && document.querySelector(selector) | ||
: Array.isArray(selector) | ||
? selector[0] | ||
: selector.nodeType ? selector : null; | ||
: selector.nodeType ? [selector] : []; | ||
} | ||
return !selector | ||
? null | ||
: selector === window || selector === document | ||
? selector | ||
: typeof selector === 'string' | ||
? !!document.querySelector && document.querySelector(selector) | ||
: Array.isArray(selector) | ||
? selector[0] | ||
: selector.nodeType ? selector : null; | ||
} |
@@ -1,33 +0,22 @@ | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
/* global global */ | ||
export var assign = (function (source) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
export let assign = ((source, ...args) => { | ||
for (let i = 0, len = args.length; i < len; i++) { | ||
const arg = args[i]; | ||
for (const p in arg) { | ||
source[p] = arg[p]; | ||
} | ||
} | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
var arg = args[i]; | ||
for (var p in arg) { | ||
source[p] = arg[p]; | ||
} | ||
} | ||
return source; | ||
}); | ||
export var create = Object.create || (function (source) { | ||
if (source === void 0) { source = {}; } | ||
return (__assign({}, source)); | ||
}); | ||
export var root = typeof window !== 'undefined' | ||
}); | ||
export let create = | ||
Object.create || ((source = {}) => ({ ...source })); | ||
export let root = | ||
typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' ? global : this; | ||
export var requestAnimationFrame = root.requestAnimationFrame || | ||
(function (fn) { return root.setTimeout(fn, 16); }); | ||
export var 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)); |
1507
src/Tween.js
@@ -6,5 +6,29 @@ import { add, now, Plugins, remove } from './core'; | ||
import Selector from './selector'; | ||
import { decompose, decomposeString, recompose, deepCopy, SET_NESTED, EVENT_CALLBACK, CHAINED_TWEENS, EVENT_UPDATE, EVENT_COMPLETE, EVENT_START, EVENT_REPEAT, EVENT_REVERSE, EVENT_PAUSE, EVENT_PLAY, EVENT_RESTART, EVENT_STOP, EVENT_SEEK, FRAME_MS, TOO_LONG_FRAME_MS, DECIMAL, } from './constants'; | ||
var _id = 0; // Unique ID | ||
var defaultEasing = Easing.Linear.None; | ||
import { | ||
decompose, | ||
decomposeString, | ||
recompose, | ||
deepCopy, | ||
SET_NESTED, | ||
STRING_PROP, | ||
EVENT_CALLBACK, | ||
CHAINED_TWEENS, | ||
EVENT_UPDATE, | ||
EVENT_COMPLETE, | ||
EVENT_START, | ||
EVENT_REPEAT, | ||
EVENT_REVERSE, | ||
EVENT_PAUSE, | ||
EVENT_PLAY, | ||
EVENT_RESTART, | ||
EVENT_STOP, | ||
EVENT_SEEK, | ||
FRAME_MS, | ||
TOO_LONG_FRAME_MS, | ||
DECIMAL, | ||
} from './constants'; | ||
let _id = 0; // Unique ID | ||
const defaultEasing = Easing.Linear.None; | ||
/** | ||
@@ -19,680 +43,823 @@ * Tween main constructor | ||
*/ | ||
var Tween = /** @class */ (function () { | ||
function Tween(node, object) { | ||
this._chainedTweensCount = 0; | ||
this.id = _id++; | ||
if (!!node && typeof node === 'object' && !object && !node.nodeType) { | ||
object = this.object = node; | ||
node = null; | ||
class Tween { | ||
_chainedTweensCount = 0; | ||
/** | ||
* 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.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.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.Tween | ||
* @static | ||
*/ | ||
static from(node, from, params) { | ||
return Tween.fromTo(node, from, null, params); | ||
} | ||
constructor(node, object) { | ||
this.id = _id++; | ||
if (!!node && typeof node === 'object' && !object && !node.nodeType) { | ||
object = this.object = node; | ||
node = null; | ||
} else if ( | ||
!!node && | ||
(node.nodeType || node.length || typeof node === 'string') | ||
) { | ||
node = this.node = Selector(node); | ||
object = this.object = NodeCache(node, object, this); | ||
} | ||
this._valuesEnd = null; | ||
this._valuesStart = {}; | ||
this._duration = 1000; | ||
this._easingFunction = defaultEasing; | ||
this._easingReverse = defaultEasing; | ||
this._interpolationFunction = Interpolation.Linear; | ||
this._startTime = 0; | ||
this._initTime = 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._maxListener = 15; | ||
this._prevTime = null; | ||
return this; | ||
} | ||
/** | ||
* Sets max `event` listener's count to Events system | ||
* @param {number} count - Event listener's count | ||
* @memberof TWEEN.Tween | ||
*/ | ||
setMaxListener(count = 15) { | ||
this._maxListener = count; | ||
return this; | ||
} | ||
/** | ||
* Adds `event` to Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof TWEEN.Tween | ||
*/ | ||
on(event, callback) { | ||
const { _maxListener } = this; | ||
const callbackName = event + EVENT_CALLBACK; | ||
for (let i = 0; i < _maxListener; i++) { | ||
const callbackId = callbackName + i; | ||
if (!this[callbackId]) { | ||
this[callbackId] = callback; | ||
break; | ||
} | ||
} | ||
return this; | ||
} | ||
/** | ||
* Adds `event` to Events system. | ||
* Removes itself after fired once | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof TWEEN.Tween | ||
*/ | ||
once(event, callback) { | ||
const { _maxListener } = this; | ||
const callbackName = event + EVENT_CALLBACK; | ||
for (let i = 0; i < _maxListener; i++) { | ||
const callbackId = callbackName + i; | ||
if (!this[callbackId]) { | ||
this[callbackId] = (...args) => { | ||
callback.apply(this, args); | ||
this[callbackId] = null; | ||
}; | ||
break; | ||
} | ||
} | ||
return this; | ||
} | ||
/** | ||
* Removes `event` from Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof TWEEN.Tween | ||
*/ | ||
off(event, callback) { | ||
const { _maxListener } = this; | ||
const callbackName = event + EVENT_CALLBACK; | ||
for (let i = 0; i < _maxListener; i++) { | ||
const callbackId = callbackName + i; | ||
if (this[callbackId] === callback) { | ||
this[callbackId] = null; | ||
} | ||
} | ||
return this; | ||
} | ||
/** | ||
* Emits/Fired/Trigger `event` from Events system listeners | ||
* @param {string} event - Event listener name | ||
* @memberof TWEEN.Tween | ||
*/ | ||
emit(event, arg1, arg2, arg3, arg4) { | ||
const { _maxListener } = this; | ||
const callbackName = event + EVENT_CALLBACK; | ||
if (!this[callbackName + 0]) { | ||
return this; | ||
} | ||
for (let i = 0; i < _maxListener; i++) { | ||
const callbackId = callbackName + i; | ||
if (this[callbackId]) { | ||
this[callbackId](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
return this; | ||
} | ||
/** | ||
* @return {boolean} State of playing of tween | ||
* @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof TWEEN.Tween | ||
*/ | ||
isPlaying() { | ||
return this._isPlaying; | ||
} | ||
/** | ||
* @return {boolean} State of started of tween | ||
* @example tween.isStarted() // returns `true` if tween in started | ||
* @memberof TWEEN.Tween | ||
*/ | ||
isStarted() { | ||
return this._onStartCallbackFired; | ||
} | ||
/** | ||
* Reverses the tween state/direction | ||
* @example tween.reverse() | ||
* @param {boolean=} state Set state of current reverse | ||
* @memberof TWEEN.Tween | ||
*/ | ||
reverse(state){ | ||
const { _reversed } = this; | ||
this._reversed = state !== undefined ? state : !_reversed; | ||
return this; | ||
} | ||
/** | ||
* @return {boolean} State of reversed | ||
* @example tween.reversed() // returns `true` if tween in reversed state | ||
* @memberof TWEEN.Tween | ||
*/ | ||
reversed() { | ||
return this._reversed; | ||
} | ||
/** | ||
* Pauses tween | ||
* @example tween.pause() | ||
* @memberof TWEEN.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.Tween | ||
*/ | ||
play() { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
this._initTime = this._startTime; | ||
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.Tween | ||
*/ | ||
restart(noDelay){ | ||
this._repeat = this._r; | ||
this.reassignValues(); | ||
add(this); | ||
return this.emit(EVENT_RESTART, this.object); | ||
} | ||
/** | ||
* Seek tween value by `time`. Note: Not works as excepted. PR are welcome | ||
* @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.Tween | ||
* @deprecated Not works as excepted, so we deprecated this method | ||
*/ | ||
seek(time, keepPlaying){ | ||
const { | ||
_duration, | ||
_repeat, | ||
_initTime, | ||
_startTime, | ||
_delayTime, | ||
_reversed, | ||
} = this; | ||
let updateTime = _initTime + time; | ||
this._isPlaying = true; | ||
if (updateTime < _startTime && _startTime >= _initTime) { | ||
this._startTime -= _duration; | ||
this._reversed = !_reversed; | ||
} | ||
this.update(time, false); | ||
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.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.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); | ||
} | ||
else if (!!node && | ||
(node.nodeType || node.length || typeof node === 'string')) { | ||
node = this.node = Selector(node); | ||
object = this.object = NodeCache(node, object, this); | ||
} | ||
} | ||
return this; | ||
} | ||
/** | ||
* Renders and computes value at first render | ||
* @private | ||
* @memberof TWEEN.Tween | ||
*/ | ||
render() { | ||
if (this._rendered) { | ||
return this; | ||
} | ||
let { | ||
_valuesStart, | ||
_valuesEnd, | ||
object, | ||
node, | ||
InitialValues, | ||
_easingFunction, | ||
} = this; | ||
SET_NESTED(object); | ||
SET_NESTED(_valuesEnd); | ||
if (node && node.queueID && Store[node.queueID]) { | ||
const prevTweenByNode = Store[node.queueID]; | ||
if ( | ||
prevTweenByNode.propNormaliseRequired && | ||
prevTweenByNode.tween !== this | ||
) { | ||
for (const property in _valuesEnd) { | ||
if (prevTweenByNode.tween._valuesEnd[property] !== undefined) { | ||
//delete prevTweenByNode.tween._valuesEnd[property]; | ||
} | ||
} | ||
this._valuesEnd = null; | ||
this._valuesStart = {}; | ||
this._duration = 1000; | ||
this._easingFunction = defaultEasing; | ||
this._easingReverse = defaultEasing; | ||
this._interpolationFunction = Interpolation.Linear; | ||
this._startTime = 0; | ||
this._initTime = 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._maxListener = 15; | ||
this._prevTime = null; | ||
return this; | ||
prevTweenByNode.normalisedProp = true; | ||
prevTweenByNode.propNormaliseRequired = false; | ||
} | ||
} | ||
/** | ||
* 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.Tween | ||
* @static | ||
*/ | ||
Tween.fromTo = function (node, object, to, params) { | ||
if (params === void 0) { params = {}; } | ||
params.quickRender = params.quickRender ? params.quickRender : !to; | ||
var tween = new Tween(node, object).to(to, params); | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime); | ||
tween._rendered = false; | ||
tween._onStartCallbackFired = false; | ||
if (node && InitialValues) { | ||
if (!object || Object.keys(object).length === 0) { | ||
object = this.object = NodeCache( | ||
node, | ||
InitialValues(node, _valuesEnd), | ||
this | ||
); | ||
} else if (!_valuesEnd || Object.keys(_valuesEnd).length === 0) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
} | ||
} | ||
for (const property in _valuesEnd) { | ||
let start = object && object[property] && deepCopy(object[property]); | ||
let end = _valuesEnd[property]; | ||
if (Plugins[property] && Plugins[property].init) { | ||
Plugins[property].init.call(this, start, end, property, object); | ||
if (start === undefined && _valuesStart[property]) { | ||
start = _valuesStart[property]; | ||
} | ||
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.Tween | ||
* @static | ||
*/ | ||
Tween.to = function (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.Tween | ||
* @static | ||
*/ | ||
Tween.from = function (node, from, params) { | ||
return Tween.fromTo(node, from, null, params); | ||
}; | ||
/** | ||
* Sets max `event` listener's count to Events system | ||
* @param {number} count - Event listener's count | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.setMaxListener = function (count) { | ||
if (count === void 0) { count = 15; } | ||
this._maxListener = count; | ||
return this; | ||
}; | ||
/** | ||
* Adds `event` to Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.on = function (event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (!this[callbackId]) { | ||
this[callbackId] = callback; | ||
break; | ||
} | ||
if (Plugins[property].skipProcess) { | ||
continue; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Adds `event` to Events system. | ||
* Removes itself after fired once | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.once = function (event, callback) { | ||
var _this = this; | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
var _loop_1 = function (i) { | ||
var callbackId = callbackName + i; | ||
if (!this_1[callbackId]) { | ||
this_1[callbackId] = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
callback.apply(_this, args); | ||
_this[callbackId] = null; | ||
}; | ||
return "break"; | ||
} | ||
}; | ||
var this_1 = this; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var state_1 = _loop_1(i); | ||
if (state_1 === "break") | ||
break; | ||
} | ||
if ( | ||
(typeof start === 'number' && isNaN(start)) || | ||
start === null || | ||
end === null || | ||
start === false || | ||
end === false || | ||
start === undefined || | ||
end === undefined || | ||
start === end | ||
) { | ||
continue; | ||
} | ||
if (Array.isArray(end) && !Array.isArray(start)) { | ||
end.unshift(start); | ||
for (let i = 0, len = end.length; i < len; i++) { | ||
if (typeof end[i] === 'string') { | ||
let arrayOfStrings = decomposeString(end[i]); | ||
let stringObject = {length: arrayOfStrings.length, isString: true} | ||
for (let ii = 0, len2 = arrayOfStrings.length; ii < len2; ii++) { | ||
stringObject[ii] = arrayOfStrings[ii] | ||
} | ||
end[i] = stringObject | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Removes `event` from Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.off = function (event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId] === callback) { | ||
this[callbackId] = null; | ||
} | ||
} | ||
_valuesStart[property] = start; | ||
if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { | ||
continue | ||
} | ||
decompose(property, object, _valuesStart, _valuesEnd); | ||
} | ||
if (Tween.Renderer && this.node && Tween.Renderer.init) { | ||
Tween.Renderer.init.call(this, object, _valuesStart, _valuesEnd); | ||
this.__render = true; | ||
} | ||
return this; | ||
} | ||
/** | ||
* Start the tweening | ||
* @param {number|string} time setting manual time instead of Current browser timestamp or like `+1000` relative to current timestamp | ||
* @example tween.start() | ||
* @memberof TWEEN.Tween | ||
*/ | ||
start(time) { | ||
this._startTime = | ||
time !== undefined | ||
? typeof time === 'string' ? now() + parseFloat(time) : time | ||
: now(); | ||
this._startTime += this._delayTime; | ||
this._initTime = this._prevTime = this._startTime; | ||
this._onStartCallbackFired = false; | ||
this._rendered = false; | ||
this._isPlaying = true; | ||
add(this); | ||
return this; | ||
} | ||
/** | ||
* Stops the tween | ||
* @example tween.stop() | ||
* @memberof TWEEN.Tween | ||
*/ | ||
stop() { | ||
let { | ||
_isPlaying, | ||
_isFinite, | ||
object, | ||
_startTime, | ||
_delayTime, | ||
_duration, | ||
_r, | ||
_yoyo, | ||
_reversed, | ||
} = this; | ||
if (!_isPlaying) { | ||
return this; | ||
} | ||
let atStart = _isFinite ? (_r + 1) % 2 === 1 : !_reversed; | ||
this._reversed = false; | ||
if (_yoyo && atStart) { | ||
this.update(_startTime); | ||
} else { | ||
this.update(_startTime + _duration); | ||
} | ||
remove(this); | ||
return this.emit(EVENT_STOP, object); | ||
} | ||
/** | ||
* Set delay of tween | ||
* @param {number} amount Sets tween delay / wait duration | ||
* @example tween.delay(500) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
delay(amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
* Chained tweens | ||
* @param {any} arguments Arguments list | ||
* @example tween.chainedTweens(tween1, tween2) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
chainedTweens() { | ||
this._chainedTweensCount = arguments.length; | ||
if (!this._chainedTweensCount) { | ||
return this; | ||
} | ||
for (let i = 0, len = this._chainedTweensCount; i < len; i++) { | ||
this[CHAINED_TWEENS + i] = arguments[i]; | ||
} | ||
return this; | ||
} | ||
/** | ||
* Sets how times tween is repeating | ||
* @param {amount} amount the times of repeat | ||
* @example tween.repeat(5) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
repeat(amount) { | ||
this._repeat = !this._duration | ||
? 0 | ||
: typeof amount === 'function' ? amount(this._repeat) : amount; | ||
this._r = this._repeat; | ||
this._isFinite = isFinite(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.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.Tween | ||
*/ | ||
yoyo(state, _easingReverse){ | ||
this._yoyo = | ||
typeof state === 'function' | ||
? state(this._yoyo) | ||
: state === null ? this._yoyo : state; | ||
if (!state) { | ||
this._reversed = false; | ||
} | ||
this._easingReverse = _easingReverse || null; | ||
return this; | ||
} | ||
/** | ||
* Set easing | ||
* @param {Function} _easingFunction Easing function, applies in non-reverse direction if Tween#yoyo second argument is applied | ||
* @example tween.easing(Easing.Elastic.InOut) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
easing(_easingFunction) { | ||
this._easingFunction = _easingFunction; | ||
return this; | ||
} | ||
/** | ||
* Set interpolation | ||
* @param {Function} _interpolationFunction Interpolation function | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
interpolation(_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
} | ||
/** | ||
* Reassigns value for rare-case like Tween#restart or for Timeline | ||
* @private | ||
* @memberof TWEEN.Tween | ||
*/ | ||
reassignValues(time){ | ||
const { _valuesStart, object, _delayTime } = this; | ||
this._isPlaying = true; | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += _delayTime; | ||
this._reversed = false; | ||
add(this); | ||
for (const property in _valuesStart) { | ||
const start = _valuesStart[property]; | ||
object[property] = 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 | ||
* @param {boolean=} forceTime Forces to be frame rendered, even mismatching time | ||
* @example tween.update(100) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
update(time, preserve, forceTime){ | ||
let { | ||
_onStartCallbackFired, | ||
_easingFunction, | ||
_interpolationFunction, | ||
_easingReverse, | ||
_repeat, | ||
_delayTime, | ||
_reverseDelayTime, | ||
_yoyo, | ||
_reversed, | ||
_startTime, | ||
_prevTime, | ||
_duration, | ||
_valuesStart, | ||
_valuesEnd, | ||
object, | ||
_isFinite, | ||
_isPlaying, | ||
__render, | ||
_chainedTweensCount, | ||
} = this; | ||
let elapsed; | ||
let currentEasing; | ||
let property; | ||
let propCount = 0; | ||
if (!_duration) { | ||
elapsed = 1; | ||
_repeat = 0; | ||
} else { | ||
time = time !== undefined ? time : now(); | ||
let delta = time - _prevTime; | ||
this._prevTime = time; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
time -= delta - FRAME_MS; | ||
} | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
return true; | ||
} | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (!this._rendered) { | ||
this.render(); | ||
this._rendered = true; | ||
} | ||
this.emit(EVENT_START, object); | ||
this._onStartCallbackFired = true; | ||
} | ||
currentEasing = _reversed | ||
? _easingReverse || _easingFunction | ||
: _easingFunction; | ||
if (!object) { | ||
return true; | ||
} | ||
for (property in _valuesEnd) { | ||
const start = _valuesStart[property]; | ||
if ( | ||
(start === undefined || start === null) && | ||
!(Plugins[property] && Plugins[property].update) | ||
) { | ||
continue; | ||
} | ||
const end = _valuesEnd[property]; | ||
const value = currentEasing[property] | ||
? currentEasing[property](elapsed) | ||
: typeof currentEasing === 'function' | ||
? currentEasing(elapsed) | ||
: defaultEasing(elapsed); | ||
const _interpolationFunctionCall = _interpolationFunction[property] | ||
? _interpolationFunction[property] | ||
: typeof _interpolationFunction === 'function' | ||
? _interpolationFunction | ||
: Interpolation.Linear; | ||
if (typeof end === 'number') { | ||
object[property] = | ||
(((start + (end - start) * value) * DECIMAL) | 0) / DECIMAL; | ||
} else if (Array.isArray(end) && !Array.isArray(start)) { | ||
object[property] = _interpolationFunctionCall( | ||
end, | ||
value, | ||
object[property] | ||
); | ||
} else if (end && end.update) { | ||
end.update(value); | ||
} else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} else if (typeof end === 'string' && typeof start === 'number') { | ||
object[property] = start + parseFloat(end[0] + end.substr(2)) * value | ||
} else { | ||
recompose(property, object, _valuesStart, _valuesEnd, value, elapsed); | ||
} | ||
if (Plugins[property] && Plugins[property].update) { | ||
Plugins[property].update.call( | ||
this, | ||
object[property], | ||
start, | ||
end, | ||
value, | ||
elapsed, | ||
property | ||
); | ||
} | ||
propCount++; | ||
} | ||
if (!propCount) { | ||
remove(this); | ||
return false; | ||
} | ||
if (__render && Tween.Renderer && Tween.Renderer.update) { | ||
Tween.Renderer.update.call(this, object, elapsed); | ||
} | ||
this.emit(EVENT_UPDATE, object, elapsed, time); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat > 0 && _duration > 0) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Emits/Fired/Trigger `event` from Events system listeners | ||
* @param {string} event - Event listener name | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.emit = function (event, arg1, arg2, arg3, arg4) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
if (!this[callbackName + 0]) { | ||
return this; | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
} else { | ||
for (property in _valuesEnd) { | ||
let end = _valuesEnd[property] | ||
if (typeof end === 'string' && typeof _valuesStart[property] === 'number') { | ||
_valuesStart[property] += parseFloat(end[0] + end.substr(2)) | ||
} | ||
} | ||
} | ||
this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object); | ||
if (_reversed && _reverseDelayTime) { | ||
this._startTime = time - _reverseDelayTime; | ||
} else { | ||
this._startTime = time + _delayTime; | ||
} | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId]) { | ||
this[callbackId](arg1, arg2, arg3, arg4); | ||
} | ||
return true; | ||
} else { | ||
if (!preserve) { | ||
this._isPlaying = false; | ||
remove(this); | ||
_id--; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* @return {boolean} State of playing of tween | ||
* @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.isPlaying = function () { | ||
return this._isPlaying; | ||
}; | ||
/** | ||
* @return {boolean} State of started of tween | ||
* @example tween.isStarted() // returns `true` if tween in started | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.isStarted = function () { | ||
return this._onStartCallbackFired; | ||
}; | ||
/** | ||
* Reverses the tween state/direction | ||
* @example tween.reverse() | ||
* @param {boolean=} state Set state of current reverse | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.reverse = function (state) { | ||
var _reversed = this._reversed; | ||
this._reversed = state !== undefined ? state : !_reversed; | ||
return this; | ||
}; | ||
/** | ||
* @return {boolean} State of reversed | ||
* @example tween.reversed() // returns `true` if tween in reversed state | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.reversed = function () { | ||
return this._reversed; | ||
}; | ||
/** | ||
* Pauses tween | ||
* @example tween.pause() | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.pause = function () { | ||
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.Tween | ||
*/ | ||
Tween.prototype.play = function () { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
this._initTime = this._startTime; | ||
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.Tween | ||
*/ | ||
Tween.prototype.restart = function (noDelay) { | ||
this.emit(EVENT_COMPLETE, object); | ||
this._repeat = this._r; | ||
this.reassignValues(); | ||
add(this); | ||
return this.emit(EVENT_RESTART, this.object); | ||
}; | ||
/** | ||
* Seek tween value by `time`. Note: Not works as excepted. PR are welcome | ||
* @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.Tween | ||
* @deprecated Not works as excepted, so we deprecated this method | ||
*/ | ||
Tween.prototype.seek = function (time, keepPlaying) { | ||
var _a = this, _duration = _a._duration, _repeat = _a._repeat, _initTime = _a._initTime, _startTime = _a._startTime, _delayTime = _a._delayTime, _reversed = _a._reversed; | ||
var updateTime = _initTime + time; | ||
this._isPlaying = true; | ||
if (updateTime < _startTime && _startTime >= _initTime) { | ||
this._startTime -= _duration; | ||
this._reversed = !_reversed; | ||
if (_chainedTweensCount) { | ||
for (let i = 0; i < _chainedTweensCount; i++) { | ||
this[CHAINED_TWEENS + i].start(time + _duration); | ||
} | ||
} | ||
this.update(time, false); | ||
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.Tween | ||
*/ | ||
Tween.prototype.duration = function (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.Tween | ||
*/ | ||
Tween.prototype.to = function (properties, duration, maybeUsed) { | ||
if (duration === void 0) { duration = 1000; } | ||
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 (var prop in duration) { | ||
if (typeof this[prop] === 'function') { | ||
var _a = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]], _b = _a[0], arg1 = _b === void 0 ? null : _b, _c = _a[1], arg2 = _c === void 0 ? null : _c, _d = _a[2], arg3 = _d === void 0 ? null : _d, _e = _a[3], arg4 = _e === void 0 ? null : _e; | ||
this[prop](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Renders and computes value at first render | ||
* @private | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.render = function () { | ||
if (this._rendered) { | ||
return this; | ||
} | ||
var _a = this, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, node = _a.node, InitialValues = _a.InitialValues, _easingFunction = _a._easingFunction; | ||
SET_NESTED(object); | ||
SET_NESTED(_valuesEnd); | ||
if (node && node.queueID && Store[node.queueID]) { | ||
var prevTweenByNode = Store[node.queueID]; | ||
if (prevTweenByNode.propNormaliseRequired && | ||
prevTweenByNode.tween !== this) { | ||
for (var property in _valuesEnd) { | ||
if (prevTweenByNode.tween._valuesEnd[property] !== undefined) { | ||
//delete prevTweenByNode.tween._valuesEnd[property]; | ||
} | ||
} | ||
prevTweenByNode.normalisedProp = true; | ||
prevTweenByNode.propNormaliseRequired = false; | ||
} | ||
} | ||
if (node && InitialValues) { | ||
if (!object || Object.keys(object).length === 0) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd), this); | ||
} | ||
else if (!_valuesEnd || Object.keys(_valuesEnd).length === 0) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
} | ||
} | ||
for (var property in _valuesEnd) { | ||
var start = object && object[property] && deepCopy(object[property]); | ||
var end = _valuesEnd[property]; | ||
if (Plugins[property] && Plugins[property].init) { | ||
Plugins[property].init.call(this, start, end, property, object); | ||
if (start === undefined && _valuesStart[property]) { | ||
start = _valuesStart[property]; | ||
} | ||
if (Plugins[property].skipProcess) { | ||
continue; | ||
} | ||
} | ||
if ((typeof start === 'number' && isNaN(start)) || | ||
start === null || | ||
end === null || | ||
start === false || | ||
end === false || | ||
start === undefined || | ||
end === undefined || | ||
start === end) { | ||
continue; | ||
} | ||
if (Array.isArray(end) && !Array.isArray(start)) { | ||
end.unshift(start); | ||
for (var i = 0, len = end.length; i < len; i++) { | ||
if (typeof end[i] === 'string') { | ||
var arrayOfStrings = decomposeString(end[i]); | ||
var stringObject = { length: arrayOfStrings.length, isString: true }; | ||
for (var ii = 0, len2 = arrayOfStrings.length; ii < len2; ii++) { | ||
stringObject[ii] = arrayOfStrings[ii]; | ||
} | ||
end[i] = stringObject; | ||
} | ||
} | ||
} | ||
_valuesStart[property] = start; | ||
if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { | ||
continue; | ||
} | ||
decompose(property, object, _valuesStart, _valuesEnd); | ||
} | ||
if (Tween.Renderer && this.node && Tween.Renderer.init) { | ||
Tween.Renderer.init.call(this, object, _valuesStart, _valuesEnd); | ||
this.__render = true; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Start the tweening | ||
* @param {number|string} time setting manual time instead of Current browser timestamp or like `+1000` relative to current timestamp | ||
* @example tween.start() | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.start = function (time) { | ||
this._startTime = | ||
time !== undefined | ||
? typeof time === 'string' ? now() + parseFloat(time) : time | ||
: now(); | ||
this._startTime += this._delayTime; | ||
this._initTime = this._prevTime = this._startTime; | ||
this._onStartCallbackFired = false; | ||
this._rendered = false; | ||
this._isPlaying = true; | ||
add(this); | ||
return this; | ||
}; | ||
/** | ||
* Stops the tween | ||
* @example tween.stop() | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.stop = function () { | ||
var _a = this, _isPlaying = _a._isPlaying, _isFinite = _a._isFinite, object = _a.object, _startTime = _a._startTime, _delayTime = _a._delayTime, _duration = _a._duration, _r = _a._r, _yoyo = _a._yoyo, _reversed = _a._reversed; | ||
if (!_isPlaying) { | ||
return this; | ||
} | ||
var atStart = _isFinite ? (_r + 1) % 2 === 1 : !_reversed; | ||
this._reversed = false; | ||
if (_yoyo && atStart) { | ||
this.update(_startTime); | ||
} | ||
else { | ||
this.update(_startTime + _duration); | ||
} | ||
remove(this); | ||
return this.emit(EVENT_STOP, object); | ||
}; | ||
/** | ||
* Set delay of tween | ||
* @param {number} amount Sets tween delay / wait duration | ||
* @example tween.delay(500) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.delay = function (amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Chained tweens | ||
* @param {any} arguments Arguments list | ||
* @example tween.chainedTweens(tween1, tween2) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.chainedTweens = function () { | ||
this._chainedTweensCount = arguments.length; | ||
if (!this._chainedTweensCount) { | ||
return this; | ||
} | ||
for (var i = 0, len = this._chainedTweensCount; i < len; i++) { | ||
this[CHAINED_TWEENS + i] = arguments[i]; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Sets how times tween is repeating | ||
* @param {amount} amount the times of repeat | ||
* @example tween.repeat(5) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.repeat = function (amount) { | ||
this._repeat = !this._duration | ||
? 0 | ||
: typeof amount === 'function' ? amount(this._repeat) : amount; | ||
this._r = this._repeat; | ||
this._isFinite = isFinite(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.Tween | ||
*/ | ||
Tween.prototype.reverseDelay = function (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.Tween | ||
*/ | ||
Tween.prototype.yoyo = function (state, _easingReverse) { | ||
this._yoyo = | ||
typeof state === 'function' | ||
? state(this._yoyo) | ||
: state === null ? this._yoyo : state; | ||
if (!state) { | ||
this._reversed = false; | ||
} | ||
this._easingReverse = _easingReverse || null; | ||
return this; | ||
}; | ||
/** | ||
* Set easing | ||
* @param {Function} _easingFunction Easing function, applies in non-reverse direction if Tween#yoyo second argument is applied | ||
* @example tween.easing(Easing.Elastic.InOut) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.easing = function (_easingFunction) { | ||
this._easingFunction = _easingFunction; | ||
return this; | ||
}; | ||
/** | ||
* Set interpolation | ||
* @param {Function} _interpolationFunction Interpolation function | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.interpolation = function (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Reassigns value for rare-case like Tween#restart or for Timeline | ||
* @private | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.reassignValues = function (time) { | ||
var _a = this, _valuesStart = _a._valuesStart, object = _a.object, _delayTime = _a._delayTime; | ||
this._isPlaying = true; | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += _delayTime; | ||
this._reversed = false; | ||
add(this); | ||
for (var property in _valuesStart) { | ||
var start = _valuesStart[property]; | ||
object[property] = 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 | ||
* @param {boolean=} forceTime Forces to be frame rendered, even mismatching time | ||
* @example tween.update(100) | ||
* @memberof TWEEN.Tween | ||
*/ | ||
Tween.prototype.update = function (time, preserve, forceTime) { | ||
var _a = this, _onStartCallbackFired = _a._onStartCallbackFired, _easingFunction = _a._easingFunction, _interpolationFunction = _a._interpolationFunction, _easingReverse = _a._easingReverse, _repeat = _a._repeat, _delayTime = _a._delayTime, _reverseDelayTime = _a._reverseDelayTime, _yoyo = _a._yoyo, _reversed = _a._reversed, _startTime = _a._startTime, _prevTime = _a._prevTime, _duration = _a._duration, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying, __render = _a.__render, _chainedTweensCount = _a._chainedTweensCount; | ||
var elapsed; | ||
var currentEasing; | ||
var property; | ||
var propCount = 0; | ||
if (!_duration) { | ||
elapsed = 1; | ||
_repeat = 0; | ||
} | ||
else { | ||
time = time !== undefined ? time : now(); | ||
var delta = time - _prevTime; | ||
this._prevTime = time; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
time -= delta - FRAME_MS; | ||
} | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
return true; | ||
} | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (!this._rendered) { | ||
this.render(); | ||
this._rendered = true; | ||
} | ||
this.emit(EVENT_START, object); | ||
this._onStartCallbackFired = true; | ||
} | ||
currentEasing = _reversed | ||
? _easingReverse || _easingFunction | ||
: _easingFunction; | ||
if (!object) { | ||
return true; | ||
} | ||
for (property in _valuesEnd) { | ||
var start = _valuesStart[property]; | ||
if ((start === undefined || start === null) && | ||
!(Plugins[property] && Plugins[property].update)) { | ||
continue; | ||
} | ||
var end = _valuesEnd[property]; | ||
var value = currentEasing[property] | ||
? currentEasing[property](elapsed) | ||
: typeof currentEasing === 'function' | ||
? currentEasing(elapsed) | ||
: defaultEasing(elapsed); | ||
var _interpolationFunctionCall = _interpolationFunction[property] | ||
? _interpolationFunction[property] | ||
: typeof _interpolationFunction === 'function' | ||
? _interpolationFunction | ||
: Interpolation.Linear; | ||
if (typeof end === 'number') { | ||
object[property] = | ||
(((start + (end - start) * value) * DECIMAL) | 0) / DECIMAL; | ||
} | ||
else if (Array.isArray(end) && !Array.isArray(start)) { | ||
object[property] = _interpolationFunctionCall(end, value, object[property]); | ||
} | ||
else if (end && end.update) { | ||
end.update(value); | ||
} | ||
else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} | ||
else if (typeof end === 'string' && typeof start === 'number') { | ||
object[property] = start + parseFloat(end[0] + end.substr(2)) * value; | ||
} | ||
else { | ||
recompose(property, object, _valuesStart, _valuesEnd, value, elapsed); | ||
} | ||
if (Plugins[property] && Plugins[property].update) { | ||
Plugins[property].update.call(this, object[property], start, end, value, elapsed, property); | ||
} | ||
propCount++; | ||
} | ||
if (!propCount) { | ||
remove(this); | ||
return false; | ||
} | ||
if (__render && Tween.Renderer && Tween.Renderer.update) { | ||
Tween.Renderer.update.call(this, object, elapsed); | ||
} | ||
this.emit(EVENT_UPDATE, object, elapsed, time); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat > 0 && _duration > 0) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
} | ||
else { | ||
for (property in _valuesEnd) { | ||
var end = _valuesEnd[property]; | ||
if (typeof end === 'string' && typeof _valuesStart[property] === 'number') { | ||
_valuesStart[property] += parseFloat(end[0] + end.substr(2)); | ||
} | ||
} | ||
} | ||
this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object); | ||
if (_reversed && _reverseDelayTime) { | ||
this._startTime = time - _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime = time + _delayTime; | ||
} | ||
return true; | ||
} | ||
else { | ||
if (!preserve) { | ||
this._isPlaying = false; | ||
remove(this); | ||
_id--; | ||
} | ||
this.emit(EVENT_COMPLETE, object); | ||
this._repeat = this._r; | ||
if (_chainedTweensCount) { | ||
for (var i = 0; i < _chainedTweensCount; i++) { | ||
this[CHAINED_TWEENS + i].start(time + _duration); | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
return Tween; | ||
}()); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
export default Tween; |
227
test.js
@@ -5,167 +5,158 @@ import test from 'ava' | ||
test('Events', t => { | ||
let tween = new Tween({ x: 0 }) | ||
.to({ x: 100 }, 100) | ||
.repeat(2) | ||
.yoyo(true) | ||
.start(0) | ||
let tween = new Tween({ x: 0 }) | ||
.to({ x: 100 }, 100) | ||
.repeat(2) | ||
.yoyo(true) | ||
.start(0) | ||
t.plan(9) | ||
t.plan(9) | ||
tween.on('start', () => { | ||
t.log('Event [Start]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('start', () => { | ||
t.log('Event [Start]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('update', () => { | ||
t.log('Event [Update]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('update', () => { | ||
t.log('Event [Update]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('repeat', () => { | ||
t.log('Event [Repeat]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('repeat', () => { | ||
t.log('Event [Repeat]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('reverse', () => { | ||
t.log('Event [Reverse]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('reverse', () => { | ||
t.log('Event [Reverse]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('complete', () => { | ||
t.log('Event [Complete]: Was called successfully') | ||
t.pass() | ||
}) | ||
tween.on('complete', () => { | ||
t.log('Event [Complete]: Was called successfully') | ||
t.pass() | ||
}) | ||
update(0) | ||
update(50) | ||
update(100) | ||
update(200) | ||
update(300) | ||
update(0) | ||
update(50) | ||
update(100) | ||
update(200) | ||
update(300) | ||
}) | ||
test('Value Interpolation', t => { | ||
let obj = { a: 0, b: 'B value 1', c: { x: 2 }, d: [3], _e: 4, g: 5 } | ||
let obj = { a: 0, b: 'B value 1', c: { x: 2 }, d: [3], _e: 4, g: 5 } | ||
Object.defineProperty(obj, 'e', { | ||
get () { return obj._e }, | ||
set (x) { | ||
obj._e = x | ||
} | ||
}) | ||
Object.defineProperty(obj, 'e', { | ||
get: () => obj._e, | ||
set: x => obj._e = x | ||
}) | ||
new Tween(obj) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+=1' }, 100) | ||
.start(0) | ||
let tween = new Tween(obj) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+=1' }, 100) | ||
.start(0) | ||
update(0) | ||
update(0) | ||
t.is(obj.a, 0) | ||
t.is(obj.b, 'B value 1') | ||
t.is(obj.c.x, 2) | ||
t.is(obj.d[0], 3) | ||
t.is(obj.e, 4) | ||
t.is(obj.g, 5) | ||
t.is(obj.a, 0) | ||
t.is(obj.b, 'B value 1') | ||
t.is(obj.c.x, 2) | ||
t.is(obj.d[0], 3) | ||
t.is(obj.e, 4) | ||
t.is(obj.g, 5) | ||
update(50) | ||
update(50) | ||
t.is(obj.a, 0.5, 'Number interpolation not worked as excepted') | ||
t.log('Number interpolation worked as excepted') | ||
t.is(obj.a, 0.5, 'Number interpolation not worked as excepted') | ||
t.log('Number interpolation worked as excepted') | ||
t.is(obj.b, 'B value 1.5', 'String interpolation not worked as excepted') | ||
t.log('String interpolation worked as excepted') | ||
t.is(obj.b, 'B value 1.5', 'String interpolation not worked as excepted') | ||
t.log('String interpolation worked as excepted') | ||
t.is(obj.c.x, 2.5, 'Object interpolation not worked as excepted') | ||
t.log('Object interpolation worked as excepted') | ||
t.is(obj.c.x, 2.5, 'Object interpolation not worked as excepted') | ||
t.log('Object interpolation worked as excepted') | ||
t.is(obj.d[0], 3.5, 'Array interpolation not worked as excepted') | ||
t.log('Array interpolation worked as excepted') | ||
t.is(obj.d[0], 3.5, 'Array interpolation not worked as excepted') | ||
t.log('Array interpolation worked as excepted') | ||
t.is(obj.e, 4.5, 'Getter/Setter interpolation not worked as excepted') | ||
t.log('Getter/Setter interpolation worked as excepted') | ||
t.is(obj.e, 4.5, 'Getter/Setter interpolation not worked as excepted') | ||
t.log('Getter/Setter interpolation worked as excepted') | ||
t.is(obj.g, 5.5, 'Relative number interpolation not worked as excepted') | ||
t.log('Relative number interpolation worked as excepted') | ||
t.is(obj.g, 5.5, 'Relative number interpolation not worked as excepted') | ||
t.log('Relative number interpolation worked as excepted') | ||
update(100) | ||
update(100) | ||
t.is(obj.a, 1) | ||
t.is(obj.b, 'B value 2') | ||
t.is(obj.c.x, 3) | ||
t.is(obj.d[0], 4) | ||
t.is(obj.e, 5) | ||
t.is(obj.g, 6) | ||
t.is(obj.a, 1) | ||
t.is(obj.b, 'B value 2') | ||
t.is(obj.c.x, 3) | ||
t.is(obj.d[0], 4) | ||
t.is(obj.e, 5) | ||
t.is(obj.g, 6) | ||
}) | ||
test('Value Array-based Interpolation', t => { | ||
let obj = { x: 0 } | ||
new Tween(obj) | ||
.to({ x: [1, 3, 5] }, 100) | ||
.start(0) | ||
let obj = { x: 0 } | ||
let tween = new Tween(obj) | ||
.to({ x: [1, 3, 5] }, 100) | ||
.start(0) | ||
t.is(obj.x, 0) | ||
t.is(obj.x, 0) | ||
update(50) | ||
update(50) | ||
t.is(obj.x, 2, 'Interpolation failed') | ||
t.log('End-value interpolation was done') | ||
t.is(obj.x, 2, 'Interpolation failed') | ||
t.log('End-value interpolation was done') | ||
t.log('Start-value interpolation was done') | ||
t.log('Start-value interpolation was done') | ||
update(100) | ||
update(100) | ||
}) | ||
test('Tweens List Controlling', t => { | ||
let tween = new Tween({ x: 0 }) | ||
.to({ x: 100 }, 100) | ||
.repeat(2) | ||
.yoyo(true) | ||
.start(0) | ||
let tween = new Tween({ x: 0 }) | ||
.to({ x: 100 }, 100) | ||
.repeat(2) | ||
.yoyo(true) | ||
.start(0) | ||
t.is(getAll() | ||
.length, 1, 'Tween added in tweens list') | ||
t.log('Tweens adding was done') | ||
t.is(getAll() | ||
.length, 1, 'Tween added in tweens list') | ||
t.log('Tweens adding was done') | ||
tween.stop() | ||
tween.stop() | ||
t.is(getAll() | ||
.length, 0, 'Tween removed from tweens list') | ||
t.log('Tween removing was done') | ||
t.is(getAll() | ||
.length, 0, 'Tween removed from tweens list') | ||
t.log('Tween removing was done') | ||
tween.restart() | ||
tween.restart() | ||
t.is(getAll() | ||
.length, 1, 'Tween added in tweens list') | ||
t.log('Tweens restart and re-add to tweens list was done') | ||
t.is(getAll() | ||
.length, 1, 'Tween added in tweens list') | ||
t.log('Tweens restart and re-add to tweens list was done') | ||
removeAll() | ||
removeAll() | ||
t.is(getAll() | ||
.length, 0, 'All Tweens was removed from tweens list') | ||
t.log('Tween removeAll was worked fine') | ||
t.is(getAll() | ||
.length, 0, 'All Tweens was removed from tweens list') | ||
t.log('Tween removeAll was worked fine') | ||
}) | ||
test('Easing', t => { | ||
const { Quadratic, Elastic, Linear } = Easing | ||
const { Quadratic, Elastic, Linear } = Easing | ||
const { InOut: QuadraticInOut } = Quadratic | ||
const { InOut: ElasticInOut } = Elastic | ||
const { None } = Linear | ||
const { InOut: QuadraticInOut } = Quadratic | ||
const { InOut: ElasticInOut } = Elastic | ||
const { None } = Linear | ||
t.is(None(0.67), 0.67, 'Linear.None was not eased as excepted') | ||
t.log('Linear.None was eased as excepted') | ||
t.is(None(0.67), 0.67, 'Linear.None was not eased as excepted') | ||
t.log('Linear.None was eased as excepted') | ||
t.not(QuadraticInOut(0.77), 0.77, 'Quadratic.InOut was not eased as excepted') | ||
t.log('Quadratic.InOut was eased as excepted') | ||
t.not(QuadraticInOut(0.77), 0.77, 'Quadratic.InOut was not eased as excepted') | ||
t.log('Quadratic.InOut was eased as excepted') | ||
t.not(ElasticInOut(0.6), 0.6, 'Elastic.InOut was not eased as excepted') | ||
t.log('Elastic.InOut was eased as excepted') | ||
}) | ||
t.not(ElasticInOut(0.6), 0.6, 'Elastic.InOut was not eased as excepted') | ||
t.log('Elastic.InOut was eased as excepted') | ||
}) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
277007
22
3929
272