es6-tween
Advanced tools
Comparing version 4.1.0 to 5.0.1
1106
full/Tween.js
@@ -84,8 +84,2 @@ (function (global, factory) { | ||
} | ||
if (_tweens.length > 0) { | ||
i = _tweens.length - 1; | ||
var tweenPrev = _tweens[i]; | ||
tween.prev = tweenPrev; | ||
tweenPrev.next = tween; | ||
} | ||
_tweens.push(tween); | ||
@@ -410,252 +404,2 @@ emptyFrame = 0; | ||
/** | ||
* List of full Interpolation | ||
* @namespace TWEEN.Interpolation | ||
* @example | ||
* import {Interpolation, Tween} from 'es6-tween' | ||
* | ||
* let bezier = Interpolation.Bezier | ||
* new Tween({x:0}).to({x:[0, 4, 8, 12, 15, 20, 30, 40, 20, 40, 10, 50]}, 1000).interpolation(bezier).start() | ||
* @memberof TWEEN | ||
*/ | ||
var Interpolation = { | ||
Linear: function (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 (v, k, value) { | ||
var b = 0; | ||
var n = v.length - 1; | ||
var pw = Math.pow; | ||
var bn = Interpolation.Utils.Bernstein; | ||
for (var i = 0; i <= n; i++) { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i); | ||
} | ||
return b; | ||
}, | ||
CatmullRom: function (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 v[0] - (fn(v[0], v[0], v[1], v[1], -f, value) - v[0]); | ||
} | ||
if (k > 1) { | ||
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m, value) - v[m]); | ||
} | ||
return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i, value); | ||
} | ||
}, | ||
Utils: { | ||
Linear: function (p0, p1, t, v) { | ||
if (typeof v === 'string') { | ||
return p1; | ||
} | ||
else if (typeof v === 'number') { | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0; | ||
} | ||
else if (typeof v === 'object') { | ||
if (v.length !== undefined) { | ||
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; | ||
} | ||
}, | ||
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 v === 'string') { | ||
return p1; | ||
} | ||
else if (typeof v === '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 v === 'object') { | ||
if (v.length !== undefined) { | ||
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; | ||
} | ||
} | ||
} | ||
}; | ||
var PlaybackPosition = /** @class */ (function () { | ||
function PlaybackPosition() { | ||
this.totalTime = 0; | ||
this.labels = []; | ||
this.offsets = []; | ||
} | ||
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) { | ||
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; | ||
}()); | ||
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); | ||
} | ||
else { | ||
for (var prop in object) { | ||
if (prop in storeID.object) { | ||
if (tween._startTime === storeID.tween._startTime) { | ||
delete storeID.object[prop]; | ||
} | ||
else { | ||
storeID.propNormaliseRequired = true; | ||
} | ||
} | ||
} | ||
return object; | ||
} | ||
return storeID.object; | ||
} | ||
Store[ID] = { tween: tween, object: object, propNormaliseRequired: false }; | ||
return Store[ID].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; | ||
}; | ||
// Frame lag-fix constants | ||
@@ -680,7 +424,7 @@ var FRAME_MS = 50 / 3; | ||
// Also RegExp's for string tweening | ||
var NUM_REGEX = /\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g; | ||
var NUM_REGEX = /\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]=+)?([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]=?\d+)?/g; | ||
// Copies everything, duplicates, no shallow-copy | ||
function deepCopy(source) { | ||
if (source === undefined || typeof source !== 'object') { | ||
if ((source && source.nodeType) || source === undefined || typeof source !== 'object') { | ||
return source; | ||
@@ -701,18 +445,57 @@ } | ||
var isNaNForST = function (v) { | ||
return isNaN(+v) || v[0] === '+' || v[0] === '-' || v === '' || 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 + ")"; | ||
}; | ||
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 | ||
function decompose(prop, obj, from, to) { | ||
function decompose(prop, obj, from, to, stringBuffer) { | ||
var fromValue = from[prop]; | ||
var toValue = to[prop]; | ||
if (typeof fromValue === 'string' && typeof toValue === 'string') { | ||
var fromValue1 = fromValue | ||
.match(NUM_REGEX) | ||
.map(function (v) { return (isNaNForST(v) ? v : +v); }); | ||
var toValue1 = toValue | ||
.match(NUM_REGEX) | ||
.map(function (v, i) { return (isNaNForST(v) ? v : +v); }); | ||
fromValue1.unshift(STRING_PROP); | ||
from[prop] = fromValue1; | ||
to[prop] = toValue1; | ||
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; | ||
@@ -737,5 +520,12 @@ } | ||
var DECIMAL = Math.pow(10, 4); | ||
function recompose(prop, obj, from, to, t, originalT) { | ||
var fromValue = from[prop]; | ||
var toValue = to[prop]; | ||
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); | ||
}; | ||
function recompose(prop, obj, from, to, t, originalT, stringBuffer) { | ||
var fromValue = stringBuffer ? from : from[prop]; | ||
var toValue = stringBuffer ? to : to[prop]; | ||
if (toValue === undefined) { | ||
@@ -753,23 +543,31 @@ return fromValue; | ||
} | ||
if (fromValue[0] === STRING_PROP) { | ||
if (typeof fromValue === 'object' && !!fromValue && fromValue.isString) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = fromValue.length; i < len; i++) { | ||
var isRelative = typeof toValue[i - 1] === 'string'; | ||
STRING_BUFFER += | ||
typeof toValue[i - 1] !== 'number' | ||
? fromValue[i] | ||
: (((isRelative | ||
? fromValue[i] + +toValue[i - 1] | ||
: fromValue[i] + (toValue[i - 1] - fromValue[i]) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (originalT === 1) { | ||
fromValue[i] = fromValue[i] + +toValue[i - 1]; | ||
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)); | ||
} | ||
} | ||
obj[prop] = STRING_BUFFER; | ||
if (!stringBuffer) { | ||
obj[prop] = STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
else if (Array.isArray(fromValue)) { | ||
else if (Array.isArray(fromValue) && fromValue[0] !== STRING_PROP) { | ||
for (var i = 0, len = fromValue.length; i < len; i++) { | ||
@@ -782,3 +580,3 @@ if (fromValue[i] === toValue[i]) { | ||
} | ||
else { | ||
else if (typeof fromValue === 'object' && !!fromValue && !fromValue.isString) { | ||
for (var i in fromValue) { | ||
@@ -796,3 +594,3 @@ if (fromValue[i] === toValue[i]) { | ||
(((isRelative | ||
? fromValue + +toValue * t | ||
? fromValue + parseFloat(toValue[0] + toValue.substr(2)) * t | ||
: fromValue + (toValue - fromValue) * t) * | ||
@@ -895,3 +693,270 @@ DECIMAL) | | ||
var _id$1 = 0; // Unique ID | ||
/** | ||
* List of full Interpolation | ||
* @namespace TWEEN.Interpolation | ||
* @example | ||
* import {Interpolation, Tween} from 'es6-tween' | ||
* | ||
* let bezier = Interpolation.Bezier | ||
* new Tween({x:0}).to({x:[0, 4, 8, 12, 15, 20, 30, 40, 20, 40, 10, 50]}, 1000).interpolation(bezier).start() | ||
* @memberof TWEEN | ||
*/ | ||
var Interpolation = { | ||
Linear: function (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 (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]; | ||
} | ||
} | ||
} | ||
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 b; | ||
}, | ||
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); | ||
} | ||
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 (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; | ||
} | ||
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; | ||
} | ||
} | ||
} | ||
}; | ||
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); | ||
} | ||
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; | ||
} | ||
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; | ||
}; | ||
var _id = 0; // Unique ID | ||
var defaultEasing = Easing.Linear.None; | ||
@@ -902,4 +967,3 @@ /** | ||
* @class | ||
* @namespace Tween | ||
* @extends Tween | ||
* @namespace TWEEN.Tween | ||
* @param {Object|Element} node Node Element or Tween initial object | ||
@@ -912,3 +976,3 @@ * @param {Object=} object If Node Element is using, second argument is used for Tween initial object | ||
this._chainedTweensCount = 0; | ||
this.id = _id$1++; | ||
this.id = _id++; | ||
if (!!node && typeof node === 'object' && !object && !node.nodeType) { | ||
@@ -951,3 +1015,3 @@ object = this.object = node; | ||
* @example Tween.fromTo(node, {x:0}, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -972,3 +1036,3 @@ */ | ||
* @example Tween.to(node, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -985,3 +1049,3 @@ */ | ||
* @example Tween.from(node, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -995,3 +1059,3 @@ */ | ||
* @param {number} count - Event listener's count | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1007,3 +1071,3 @@ Tween.prototype.setMaxListener = function (count) { | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1027,3 +1091,3 @@ Tween.prototype.on = function (event, callback) { | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1037,3 +1101,3 @@ Tween.prototype.once = function (event, callback) { | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1054,3 +1118,3 @@ Tween.prototype.off = function (event, callback) { | ||
* @param {string} event - Event listener name | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1074,3 +1138,3 @@ Tween.prototype.emit = function (event, arg1, arg2, arg3, arg4) { | ||
* @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1083,3 +1147,3 @@ Tween.prototype.isPlaying = function () { | ||
* @example tween.isStarted() // returns `true` if tween in started | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1093,3 +1157,3 @@ Tween.prototype.isStarted = function () { | ||
* @param {boolean=} state Set state of current reverse | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1104,3 +1168,3 @@ Tween.prototype.reverse = function (state) { | ||
* @example tween.reversed() // returns `true` if tween in reversed state | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1113,3 +1177,3 @@ Tween.prototype.reversed = function () { | ||
* @example tween.pause() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1128,3 +1192,3 @@ Tween.prototype.pause = function () { | ||
* @example tween.play() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1146,3 +1210,3 @@ Tween.prototype.play = function () { | ||
* @example tween.restart() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1160,3 +1224,3 @@ Tween.prototype.restart = function (noDelay) { | ||
* @example tween.seek(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @deprecated Not works as excepted, so we deprecated this method | ||
@@ -1180,3 +1244,3 @@ */ | ||
* @example tween.duration(2000) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1193,3 +1257,3 @@ Tween.prototype.duration = function (amount) { | ||
* @example let tween = new Tween({x:0}).to({x:100}, 2000) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1216,3 +1280,3 @@ Tween.prototype.to = function (properties, duration, maybeUsed) { | ||
* @private | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1223,3 +1287,5 @@ Tween.prototype.render = function () { | ||
} | ||
var _a = this, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, Renderer = _a.Renderer, node = _a.node, InitialValues = _a.InitialValues; | ||
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]) { | ||
@@ -1230,5 +1296,3 @@ var prevTweenByNode = Store[node.queueID]; | ||
for (var property in _valuesEnd) { | ||
if (prevTweenByNode.tween._valuesEnd[property] !== undefined) { | ||
delete prevTweenByNode.tween._valuesEnd[property]; | ||
} | ||
} | ||
@@ -1239,9 +1303,7 @@ prevTweenByNode.normalisedProp = true; | ||
} | ||
SET_NESTED(object); | ||
SET_NESTED(_valuesEnd); | ||
if (node && InitialValues) { | ||
if (!object) { | ||
if (!object || Object.keys(object).length === 0) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd), this); | ||
} | ||
else if (!_valuesEnd) { | ||
else if (!_valuesEnd || Object.keys(_valuesEnd).length === 0) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
@@ -1251,12 +1313,12 @@ } | ||
for (var property in _valuesEnd) { | ||
var start = object && object[property]; | ||
var start = object && object[property] && deepCopy(object[property]); | ||
var end = _valuesEnd[property]; | ||
if (Plugins[property]) { | ||
var plugin = Plugins[property].prototype.update | ||
? new Plugins[property](this, start, end, property, object) | ||
: Plugins[property](this, start, end, property, object); | ||
if (plugin) { | ||
_valuesEnd[property] = plugin; | ||
if (Plugins[property] && Plugins[property].init) { | ||
Plugins[property].init.call(this, start, end, property, object); | ||
if (start === undefined && _valuesStart[property]) { | ||
start = _valuesStart[property]; | ||
} | ||
continue; | ||
if (Plugins[property].skipProcess) { | ||
continue; | ||
} | ||
} | ||
@@ -1266,2 +1328,4 @@ if ((typeof start === 'number' && isNaN(start)) || | ||
end === null || | ||
start === false || | ||
end === false || | ||
start === undefined || | ||
@@ -1274,8 +1338,22 @@ end === undefined || | ||
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] = deepCopy(start); | ||
_valuesStart[property] = start; | ||
if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { | ||
continue; | ||
} | ||
decompose(property, object, _valuesStart, _valuesEnd); | ||
} | ||
if (Renderer && this.node) { | ||
this.__render = new Renderer(this, object, _valuesEnd); | ||
if (Tween.Renderer && this.node && Tween.Renderer.init) { | ||
Tween.Renderer.init.call(this, object, _valuesStart, _valuesEnd); | ||
this.__render = true; | ||
} | ||
@@ -1288,3 +1366,3 @@ return this; | ||
* @example tween.start() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1307,3 +1385,3 @@ Tween.prototype.start = function (time) { | ||
* @example tween.stop() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1330,3 +1408,3 @@ Tween.prototype.stop = function () { | ||
* @example tween.delay(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1342,3 +1420,3 @@ Tween.prototype.delay = function (amount) { | ||
* @example tween.chainedTweens(tween1, tween2) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1359,3 +1437,3 @@ Tween.prototype.chainedTweens = function () { | ||
* @example tween.repeat(5) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1374,3 +1452,3 @@ Tween.prototype.repeat = function (amount) { | ||
* @example tween.reverseDelay(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1387,3 +1465,3 @@ Tween.prototype.reverseDelay = function (amount) { | ||
* @example tween.yoyo(true) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1405,3 +1483,3 @@ Tween.prototype.yoyo = function (state, _easingReverse) { | ||
* @example tween.easing(Easing.Elastic.InOut) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1416,3 +1494,3 @@ Tween.prototype.easing = function (_easingFunction) { | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1428,3 +1506,3 @@ Tween.prototype.interpolation = function (_interpolationFunction) { | ||
* @private | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1450,3 +1528,3 @@ Tween.prototype.reassignValues = function (time) { | ||
* @example tween.update(100) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -1461,2 +1539,3 @@ Tween.prototype.update = function (time, preserve, forceTime) { | ||
elapsed = 1; | ||
_repeat = 0; | ||
} | ||
@@ -1466,6 +1545,6 @@ else { | ||
var delta = time - _prevTime; | ||
this._prevTime = time; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
time += delta - FRAME_MS; | ||
time -= delta - FRAME_MS; | ||
} | ||
this._prevTime = time; | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
@@ -1494,3 +1573,4 @@ return true; | ||
var start = _valuesStart[property]; | ||
if (start === undefined || start === null) { | ||
if ((start === undefined || start === null) && | ||
!(Plugins[property] && Plugins[property].update)) { | ||
continue; | ||
@@ -1504,2 +1584,7 @@ } | ||
: defaultEasing(elapsed); | ||
var _interpolationFunctionCall = _interpolationFunction[property] | ||
? _interpolationFunction[property] | ||
: typeof _interpolationFunction === 'function' | ||
? _interpolationFunction | ||
: Interpolation.Linear; | ||
if (typeof end === 'number') { | ||
@@ -1510,3 +1595,3 @@ object[property] = | ||
else if (Array.isArray(end) && !Array.isArray(start)) { | ||
object[property] = _interpolationFunction(end, value, object[property]); | ||
object[property] = _interpolationFunctionCall(end, value, object[property]); | ||
} | ||
@@ -1519,5 +1604,11 @@ else if (end && end.update) { | ||
} | ||
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); | ||
} | ||
propCount++; | ||
@@ -1529,7 +1620,7 @@ } | ||
} | ||
if (__render) { | ||
__render.update(object, elapsed); | ||
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)) { | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat > 0 && _duration > 0) { | ||
@@ -1542,2 +1633,10 @@ if (_isFinite) { | ||
} | ||
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); | ||
@@ -1556,3 +1655,3 @@ if (_reversed && _reverseDelayTime) { | ||
remove(this); | ||
_id$1--; | ||
_id--; | ||
} | ||
@@ -1574,275 +1673,63 @@ this.emit(EVENT_COMPLETE, object); | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
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 shuffle = function (a) { | ||
var j; | ||
var x; | ||
var i; | ||
for (i = a.length; i; i -= 1) { | ||
j = Math.floor(Math.random() * i); | ||
x = a[i - 1]; | ||
a[i - 1] = a[j]; | ||
a[j] = x; | ||
} | ||
return a; | ||
}; | ||
var _id = 0; | ||
/** | ||
* Timeline main constructor. | ||
* | ||
* It works same as `Tween` instance, using `.repeat`, `.restart` or `etc` works like a `Tween`, so please see `Tween` class for methods | ||
* @constructor | ||
* @class | ||
* @namespace Timeline | ||
* @param {Object=} params Default params for new tweens | ||
* @example let tl = new Timeline({delay:200}) | ||
* @extends Tween | ||
* Tween helper for plugins | ||
* @namespace TWEEN.Interpolator | ||
* @memberof TWEEN | ||
* @param {any} a - Initial position | ||
* @param {any} b - End position | ||
* @return {Function} Returns function that accepts number between `0-1` | ||
*/ | ||
var Timeline = /** @class */ (function (_super) { | ||
__extends(Timeline, _super); | ||
function Timeline(params) { | ||
var _this = _super.call(this) || this; | ||
_this._duration = 0; | ||
_this._startTime = now(); | ||
_this._tweens = []; | ||
_this.elapsed = 0; | ||
_this._id = _id++; | ||
_this._defaultParams = params; | ||
_this.position = new PlaybackPosition(); | ||
_this.position.addLabel('afterLast', _this._duration); | ||
_this.position.addLabel('afterInit', _this._startTime); | ||
return _this; | ||
var Interpolator = function (a, b) { | ||
var isArray = Array.isArray(a); | ||
var origin = typeof a === 'string' ? a : isArray ? a.slice() : Object.assign({}, a); | ||
if (isArray) { | ||
for (var i = 0, len = a.length; i < len; i++) { | ||
decompose(i, origin, a, b); | ||
} | ||
} | ||
Timeline.prototype.mapTotal = function (fn) { | ||
fn.call(this, this._tweens); | ||
return this; | ||
}; | ||
Timeline.prototype.timingOrder = function (fn) { | ||
var timing = fn(this._tweens.map(function (t) { return t._startTime; })); | ||
this._tweens.map(function (tween, i) { | ||
tween._startTime = timing[i]; | ||
}); | ||
return this; | ||
}; | ||
Timeline.prototype.getTiming = function (mode, nodes, params, offset) { | ||
if (offset === void 0) { offset = 0; } | ||
if (mode === 'reverse') { | ||
var stagger_1 = params.stagger; | ||
var totalStagger_1 = (stagger_1 || 0) * (nodes.length - 1); | ||
return nodes.map(function (node, i) { return totalStagger_1 - (stagger_1 || 0) * i + offset; }); | ||
else if (typeof a === 'object') { | ||
for (var i in a) { | ||
decompose(i, origin, a, b); | ||
} | ||
else if (mode === 'async') { | ||
return nodes.map(function (node) { return offset; }); | ||
} | ||
else if (mode === 'sequence' || mode === 'delayed') { | ||
var stagger_2 = params.stagger; | ||
if (!stagger_2) { | ||
stagger_2 = (params.duration || 1000) / (nodes.length - 1); | ||
} | ||
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]); | ||
} | ||
return nodes.map(function (node, i) { return stagger_2 * i + offset; }); | ||
else { | ||
i++; | ||
} | ||
} | ||
else if (mode === 'oneByOne') { | ||
return nodes.map(function (node) { return params.duration; }); | ||
var c = { isString: true, length: a.length }; | ||
while (i < c.length) { | ||
c[i] = a[i]; | ||
i++; | ||
} | ||
else if (mode === 'shuffle') { | ||
var stagger_3 = params.stagger; | ||
return shuffle(nodes.map(function (node, i) { return (stagger_3 || 0) * i + offset; })); | ||
} | ||
else { | ||
var stagger_4 = params.stagger; | ||
return nodes.map(function (node, i) { return (stagger_4 || 0) * i + offset; }); | ||
} | ||
}; | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
* @param {object} from - Initial value | ||
* @param {object} to - Target value | ||
* @param {object} params - Options of tweens | ||
* @example tl.fromTo(nodes, {x:0}, {x:200}, {duration:1000, stagger:200}) | ||
* @memberof Timeline | ||
* @static | ||
*/ | ||
Timeline.prototype.fromTo = function (nodes, from, to, params) { | ||
nodes = Selector(nodes, true); | ||
if (nodes && nodes.length) { | ||
if (this._defaultParams) { | ||
params = __assign$1({}, this._defaultParams, params); | ||
} | ||
return function (t) { | ||
if (isArray) { | ||
for (var i = 0, len = a.length; i < len; i++) { | ||
recompose(i, origin, a, b, t); | ||
} | ||
var position = params.label; | ||
var offset = typeof position === 'number' | ||
? position | ||
: this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
var mode = this.getTiming(params.mode, nodes, params, offset); | ||
for (var i = 0, node = void 0, len = nodes.length; i < len; i++) { | ||
node = nodes[i]; | ||
this.add(Tween.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : __assign$1({}, from), typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), mode[i]); | ||
} | ||
} | ||
return this.start(); | ||
}; | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
* @param {object} from - Initial value | ||
* @param {object} params - Options of tweens | ||
* @example tl.from(nodes, {x:200}, {duration:1000, stagger:200}) | ||
* @memberof Timeline | ||
* @static | ||
*/ | ||
Timeline.prototype.from = function (nodes, from, params) { | ||
return this.fromTo(nodes, from, null, params); | ||
}; | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
* @param {object} to - Target value | ||
* @param {object} params - Options of tweens | ||
* @example tl.to(nodes, {x:200}, {duration:1000, stagger:200}) | ||
* @memberof Timeline | ||
* @static | ||
*/ | ||
Timeline.prototype.to = function (nodes, to, params) { | ||
return this.fromTo(nodes, null, to, params); | ||
}; | ||
/** | ||
* Add label to Timeline | ||
* @param {string} name Label name | ||
* @param {any} offset Label value, can be `number` and/or `string` | ||
* @example tl.add('label1', 200) | ||
* @memberof Timeline | ||
*/ | ||
Timeline.prototype.addLabel = function (name, offset) { | ||
this.position.addLabel(name, offset); | ||
return this; | ||
}; | ||
Timeline.prototype.map = function (fn) { | ||
for (var i = 0, len = this._tweens.length; i < len; i++) { | ||
var _tween = this._tweens[i]; | ||
fn(_tween, i); | ||
this._duration = Math.max(this._duration, _tween._duration + _tween._startTime); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Add tween to Timeline | ||
* @param {Tween} tween Tween instance | ||
* @param {position} position Can be label name, number or relative number to label | ||
* @example tl.add(new Tween(node, {x:0}).to({x:200}, 200)) | ||
* @memberof Timeline | ||
*/ | ||
Timeline.prototype.add = function (tween, position) { | ||
var _this = this; | ||
if (Array.isArray(tween)) { | ||
tween.map(function (_tween) { | ||
_this.add(_tween, position); | ||
}); | ||
return this; | ||
} | ||
else if (typeof tween === 'object' && !(tween instanceof Tween)) { | ||
tween = new Tween(tween.from).to(tween.to, tween); | ||
} | ||
var _a = this, _defaultParams = _a._defaultParams, _duration = _a._duration; | ||
if (_defaultParams) { | ||
for (var method in _defaultParams) { | ||
if (typeof tween[method] === 'function') { | ||
tween[method](_defaultParams[method]); | ||
} | ||
else if (typeof origin === 'object') { | ||
for (var i in a) { | ||
recompose(i, origin, a, b, t); | ||
} | ||
} | ||
var offset = typeof position === 'number' | ||
? position | ||
: this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
tween._startTime = Math.max(this._startTime, tween._delayTime, offset); | ||
tween._delayTime = offset; | ||
tween._isPlaying = true; | ||
this._duration = Math.max(_duration, tween._startTime + tween._delayTime + tween._duration); | ||
this._tweens.push(tween); | ||
this.position.setLabel('afterLast', this._duration); | ||
return this; | ||
}; | ||
Timeline.prototype.restart = function () { | ||
this._startTime += now(); | ||
add(this); | ||
return this.emit(EVENT_RESTART); | ||
}; | ||
Timeline.prototype.easing = function (easing) { | ||
return this.map(function (tween) { return tween.easing(easing); }); | ||
}; | ||
Timeline.prototype.interpolation = function (interpolation) { | ||
return this.map(function (tween) { return tween.interpolation(interpolation); }); | ||
}; | ||
Timeline.prototype.update = function (time) { | ||
var _a = this, _tweens = _a._tweens, _duration = _a._duration, _reverseDelayTime = _a._reverseDelayTime, _startTime = _a._startTime, _reversed = _a._reversed, _yoyo = _a._yoyo, _repeat = _a._repeat, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying; | ||
if (!_isPlaying || time < _startTime) { | ||
return true; | ||
else if (typeof origin === 'string') { | ||
origin = recompose(0, 0, a, b, t, t, true); | ||
} | ||
var elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
this.elapsed = elapsed; | ||
var timing = time - _startTime; | ||
var _timing = _reversed ? _duration - timing : timing; | ||
var i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i].update(_timing); | ||
i++; | ||
} | ||
this.emit(EVENT_UPDATE, elapsed, timing); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
this.emit(_reversed ? EVENT_REVERSE : EVENT_REPEAT); | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
this.timingOrder(function (timing) { return timing.reverse(); }); | ||
} | ||
if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime = time; | ||
} | ||
i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i].reassignValues(time); | ||
i++; | ||
} | ||
return true; | ||
} | ||
else { | ||
this.emit(EVENT_COMPLETE); | ||
this._repeat = this._r; | ||
remove(this); | ||
this._isPlaying = false; | ||
return false; | ||
} | ||
} | ||
return true; | ||
return origin; | ||
}; | ||
Timeline.prototype.progress = function (value) { | ||
return value !== undefined | ||
? this.update(value * this._duration) | ||
: this.elapsed; | ||
}; | ||
return Timeline; | ||
}(Tween)); | ||
}; | ||
exports.Plugins = Plugins; | ||
exports.Selector = Selector; | ||
exports.Interpolator = Interpolator; | ||
exports.onTick = onTick; | ||
@@ -1862,3 +1749,2 @@ exports.has = has; | ||
exports.Interpolation = Interpolation; | ||
exports.Timeline = Timeline; | ||
@@ -1865,0 +1751,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -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";function e(t){if(void 0===t||"object"!=typeof t)return t;if(Array.isArray(t))return[].concat(t);if("object"==typeof t){var r={};for(var n in t)r[n]=e(t[n]);return r}return t}function r(t,e,n,i){var o=n[t],s=i[t];if("string"==typeof o&&"string"==typeof s){var u=o.match(P).map(function(t){return A(t)?t:+t}),a=s.match(P).map(function(t,e){return A(t)?t:+t});return u.unshift(M),n[t]=u,i[t]=a,!0}if("object"==typeof o&&"object"==typeof s){if(Array.isArray(o))return o.map(function(n,i){return r(i,e[t],o,s)});for(var f in s)r(f,e[t],o,s);return!0}return!1}function n(t,e,r,i,o,s){var u=r[t],a=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(u[0]===M){for(var f="",h=1,p=u.length;h<p;h++){l="string"==typeof a[h-1];f+="number"!=typeof a[h-1]?u[h]:((l?u[h]+ +a[h-1]:u[h]+(a[h-1]-u[h])*o)*L|0)/L,1===s&&(u[h]=u[h]+ +a[h-1])}return e[t]=f,f}if(Array.isArray(u))for(var h=0,p=u.length;h<p;h++)u[h]!==a[h]&&n(h,e[t],u,a,o,s);else for(var h in u)u[h]!==a[h]&&n(h,e[t],u,a,o,s)}else if("number"==typeof u){var l="string"==typeof a;e[t]=((l?u+ +a*o:u+(a-u)*o)*L|0)/L,l&&1===s&&(r[t]=e[t])}else"function"==typeof a&&(e[t]=a(o));return e[t]}var i,o="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,s=o.requestAnimationFrame||function(t){return o.setTimeout(t,16)},u=o.cancelAnimationFrame||function(t){return o.clearTimeout(t)},a=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==o.performance&&void 0!==o.performance.now)return o.performance.now.bind(o.performance);var t=o.performance&&o.performance.timing&&o.performance.timing.navigationStart?o.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),f=[],h=!1,p=!1,l=s,c=u,d=0,_=function(t){var e=f.indexOf(t);if(e>-1&&f.splice(e,1),f.length>0){e=f.length-1;var r=f[e];t.prev=r,r.next=t}f.push(t),d=0,p&&!h&&(i=l(m),h=!0)},y=function(t){for(var e=0;e<f.length;e++)if(t===f[e])return f[e];return null},v=function(t){var e=f.indexOf(t);-1!==e&&f.splice(e,1)},m=function(t,e){if(t=void 0!==t?t:a(),p&&h&&(i=l(m)),f.length||d++,d>120)return c(i),h=!1,d=0,!1;for(var r=0;r<f.length;)f[r++].update(t,e);return!0},g={},T={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+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-T.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*T.Bounce.In(2*t):.5*T.Bounce.Out(2*t-1)+.5}},Stepped:{steps:function(t){return function(e){return(e*t|0)/t}}}},b={Linear:function(t,e,r){var n=t.length-1,i=n*e,o=Math.floor(i),s=b.Utils.Linear;return e<0?s(t[0],t[1],i,r):e>1?s(t[n],t[n-1],n-i,r):s(t[o],t[o+1>n?n:o+1],i-o,r)},Bezier:function(t,e,r){for(var n=0,i=t.length-1,o=Math.pow,s=b.Utils.Bernstein,u=0;u<=i;u++)n+=o(1-e,i-u)*o(e,u)*t[u]*s(i,u);return n},CatmullRom:function(t,e,r){var n=t.length-1,i=n*e,o=Math.floor(i),s=b.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(o=Math.floor(i=n*(1+e))),s(t[(o-1+n)%n],t[o],t[(o+1)%n],t[(o+2)%n],i-o,r)):e<0?t[0]-(s(t[0],t[0],t[1],t[1],-i,r)-t[0]):e>1?t[n]-(s(t[n],t[n],t[n-1],t[n-1],i-n,r)-t[n]):s(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 n)return e;if("number"==typeof n)return"function"==typeof t?t(r):(e-t)*r+t;if("object"==typeof n){if(void 0!==n.length)for(var i=0,o=n.length;i<o;i++)n[i]=b.Utils.Linear(t[i],e[i],r,n[i]);else for(var i in n)n[i]=b.Utils.Linear(t[i],e[i],r,n[i]);return n}},Bernstein:function(t,e){var r=b.Utils.Factorial;return r(t)/r(e)/r(t-e)},Factorial:function(){var t=[1];return function(e){var r=1;if(t[e])return t[e];for(var n=e;n>1;n--)r*=n;return t[e]=r,r}}(),CatmullRom:function(t,e,r,n,i,o){if("string"==typeof o)return e;if("number"==typeof o){var s=.5*(r-t),u=.5*(n-e),a=i*i;return(2*e-2*r+s+u)*(i*a)+(-3*e+3*r-2*s-u)*a+s*i+e}if("object"==typeof o){if(void 0!==o.length)for(var f=0,h=o.length;f<h;f++)o[f]=b.Utils.CatmullRom(t[f],e[f],r[f],n[f],i,o[f]);else for(var f in o)o[f]=b.Utils.CatmullRom(t[f],e[f],r[f],n[f],i,o[f]);return o}}}},w=function(){function t(){this.totalTime=0,this.labels=[],this.offsets=[]}return t.prototype.parseLabel=function(t,e){var r=this,n=r.offsets,i=r.labels,o=i.indexOf(t);if("string"==typeof t&&-1!==t.indexOf("=")&&!e&&-1===o){var s=t.substr(t.indexOf("=")-1,2),u=t.split(s);e=2===u.length?s+u[1]:null,t=u[0],o=i.indexOf(t)}if(-1!==o&&t){var a=n[o]||0;if("number"==typeof e)a=e;else if("string"==typeof e&&-1!==e.indexOf("=")){var f=e.charAt(0);e=Number(e.substr(2)),"+"===f||"-"===f?a+=parseFloat(f+e):"*"===f?a*=e:"/"===f?a/=e:"%"===f&&(a*=e/100)}return a}return"number"==typeof e?e:0},t.prototype.addLabel=function(t,e){return this.labels.push(t),this.offsets.push(this.parseLabel(t,e)),this},t.prototype.setLabel=function(t,e){var r=this.labels.indexOf(t);return-1!==r&&this.offsets.splice(r,1,this.parseLabel(t,e)),this},t.prototype.eraseLabel=function(t){var e=this.labels.indexOf(t);return-1!==e&&(this.labels.splice(e,1),this.offsets.splice(e,1)),this},t}(),O={},j=function(t,e,r){if(!t||!t.nodeType)return e;var n=t.queueID||"q_"+Date.now();t.queueID||(t.queueID=n);var i=O[n];if(i){if(i.object!==e||t!==i.tween.node||r._startTime!==i.tween._startTime){for(var o in e)o in i.object&&(r._startTime===i.tween._startTime?delete i.object[o]:i.propNormaliseRequired=!0);return e}return v(i.tween),i.object}return O[n]={tween:r,object:e,propNormaliseRequired:!1},O[n].object},I=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},M="STRING_PROP",P=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,A=function(t){return isNaN(+t)||"+"===t[0]||"-"===t[0]||""===t||" "===t},L=Math.pow(10,4),x=/([.\[])/g,q=/\]/g,F=function(t,e){var r=t[e],n=e.replace(q,"").split(x),i=n.length-1,o=Array.isArray(t),s="object"==typeof t&&!o;return s?(t[e]=null,delete t[e]):o&&t.splice(e,1),n.reduce(function(t,e,u){o&&"."!==e&&"["!==e&&(e*=1);var a="["===n[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===i?r:o||a?[]:s?{}:null,s=o=!1,t[e]}else if(void 0!==t[e])return u===i&&(t[e]=r),t[e];return t},t)},C=function(t){if("object"==typeof t&&t)for(var e in t)if(-1!==e.indexOf(".")||-1!==e.indexOf("["))F(t,e);else if("object"==typeof t[e]&&t[e]){var r=t[e];for(var n in r)if(-1!==n.indexOf(".")||-1!==n.indexOf("["))F(r,n);else if("object"==typeof r[n]&&r[n]){var i=r[n];for(var o in i)-1===o.indexOf(".")&&-1===o.indexOf("[")||F(i,o)}}return t},S=0,R=T.Linear.None,k=function(){function t(t,e){return this._chainedTweensCount=0,this.id=S++,!t||"object"!=typeof t||e||t.nodeType?t&&(t.nodeType||t.length||"string"==typeof t)&&(t=this.node=I(t),e=this.object=j(t,e,this)):(e=this.object=t,t=null),this._valuesEnd=null,this._valuesStart={},this._duration=1e3,this._easingFunction=R,this._easingReverse=R,this._interpolationFunction=b.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,n,i){void 0===i&&(i={}),i.quickRender=i.quickRender?i.quickRender:!n;var o=new t(e,r).to(n,i);return i.quickRender&&(o.render().update(o._startTime),o._rendered=!1,o._onStartCallbackFired=!1),o},t.to=function(e,r,n){return t.fromTo(e,null,r,n)},t.from=function(e,r,n){return t.fromTo(e,r,null,n)},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,n=t+"Callback",i=0;i<r;i++){var o=n+i;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,n=t+"Callback",i=0;i<r;i++){var o=n+i;this[o]===e&&(this[o]=null)}return this},t.prototype.emit=function(t,e,r,n,i){var o=this._maxListener,s=t+"Callback";if(!this[s+0])return this;for(var u=0;u<o;u++){var a=s+u;this[a]&&this[a](e,r,n,i)}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,v(this),this._pausedTime=a(),this.emit("pause",this.object)):this},t.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=a()-this._pausedTime,this._initTime=this._startTime,_(this),this._pausedTime=a(),this.emit("play",this.object))},t.prototype.restart=function(t){return this._repeat=this._r,this.reassignValues(),_(this),this.emit("restart",this.object)},t.prototype.seek=function(t,e){var r=this,n=r._duration,i=(r._repeat,r._initTime),o=r._startTime,s=(r._delayTime,r._reversed),u=i+t;return this._isPlaying=!0,u<o&&o>=i&&(this._startTime-=n,this._reversed=!s),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 n in e)if("function"==typeof this[n]){var i=Array.isArray(e[n])?e[n]:[e[n]],o=i[0],s=void 0===o?null:o,u=i[1],a=void 0===u?null:u,f=i[2],h=void 0===f?null:f,p=i[3],l=void 0===p?null:p;this[n](s,a,h,l)}return this},t.prototype.render=function(){if(this._rendered)return this;var t=this,n=t._valuesStart,i=t._valuesEnd,o=t.object,s=t.Renderer,u=t.node,a=t.InitialValues;if(u&&u.queueID&&O[u.queueID]){var f=O[u.queueID];if(f.propNormaliseRequired&&f.tween!==this){for(var h in i)void 0!==f.tween._valuesEnd[h]&&delete f.tween._valuesEnd[h];f.normalisedProp=!0,f.propNormaliseRequired=!1}}C(o),C(i),u&&a&&(o?i||(i=this._valuesEnd=a(u,o)):o=this.object=j(u,a(u,i),this));for(var h in i){var p=o&&o[h],l=i[h];if(g[h]){var c=g[h].prototype.update?new g[h](this,p,l,h,o):g[h](this,p,l,h,o);c&&(i[h]=c)}else"number"==typeof p&&isNaN(p)||null===p||null===l||void 0===p||void 0===l||p===l||(Array.isArray(l)&&!Array.isArray(p)&&l.unshift(p),n[h]=e(p),r(h,o,n,i))}return s&&this.node&&(this.__render=new s(this,o,i)),this},t.prototype.start=function(t){return this._startTime=void 0!==t?"string"==typeof t?a()+parseFloat(t):t:a(),this._startTime+=this._delayTime,this._initTime=this._prevTime=this._startTime,this._onStartCallbackFired=!1,this._rendered=!1,this._isPlaying=!0,_(this),this},t.prototype.stop=function(){var t=this,e=t._isPlaying,r=t._isFinite,n=t.object,i=t._startTime,o=(t._delayTime,t._duration),s=t._r,u=t._yoyo,a=t._reversed;if(!e)return this;var f=r?(s+1)%2==1:!a;return this._reversed=!1,u&&f?this.update(i):this.update(i+o),v(this),this.emit("stop",n)},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["_chainedTweens"+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,r=e._valuesStart,n=e.object,i=e._delayTime;this._isPlaying=!0,this._startTime=void 0!==t?t:a(),this._startTime+=i,this._reversed=!1,_(this);for(var o in r){var s=r[o];n[o]=s}return this},t.prototype.update=function(t,e,r){var i,o,s,u=this,f=u._onStartCallbackFired,h=u._easingFunction,p=u._interpolationFunction,l=u._easingReverse,c=u._repeat,d=u._delayTime,_=u._reverseDelayTime,y=u._yoyo,m=u._reversed,g=u._startTime,T=u._prevTime,b=u._duration,w=u._valuesStart,O=u._valuesEnd,j=u.object,I=u._isFinite,M=u._isPlaying,P=u.__render,A=u._chainedTweensCount,x=0;if(b){var q=(t=void 0!==t?t:a())-T;if(q>250&&(t+=q-50/3),this._prevTime=t,!M||t<g&&!r)return!0;i=(i=(t-g)/b)>1?1:i,i=m?1-i:i}else i=1;if(f||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",j),this._onStartCallbackFired=!0),o=m?l||h:h,!j)return!0;for(s in O){var F=w[s];if(void 0!==F&&null!==F){var C=O[s],k=o[s]?o[s](i):"function"==typeof o?o(i):R(i);"number"==typeof C?j[s]=((F+(C-F)*k)*L|0)/L:Array.isArray(C)&&!Array.isArray(F)?j[s]=p(C,k,j[s]):C&&C.update?C.update(k):"function"==typeof C?j[s]=C(k):n(s,j,w,O,k,i),x++}}if(!x)return v(this),!1;if(P&&P.update(j,i),this.emit("update",j,i,t),1===i||m&&!i){if(c>0&&b>0)return I&&this._repeat--,y&&(this._reversed=!m),this.emit(y&&!m?"reverse":"repeat",j),this._startTime=m&&_?t-_:t+d,!0;if(e||(this._isPlaying=!1,v(this),S--),this.emit("complete",j),this._repeat=this._r,A)for(var D=0;D<A;D++)this["_chainedTweens"+D].start(t+b);return!1}return!0},t}(),D=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),E=this&&this.__assign||Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},N=function(t){var e,r,n;for(n=t.length;n;n-=1)e=Math.floor(Math.random()*n),r=t[n-1],t[n-1]=t[e],t[e]=r;return t},B=0,U=function(t){function e(e){var r=t.call(this)||this;return r._duration=0,r._startTime=a(),r._tweens=[],r.elapsed=0,r._id=B++,r._defaultParams=e,r.position=new w,r.position.addLabel("afterLast",r._duration),r.position.addLabel("afterInit",r._startTime),r}return D(e,t),e.prototype.mapTotal=function(t){return t.call(this,this._tweens),this},e.prototype.timingOrder=function(t){var e=t(this._tweens.map(function(t){return t._startTime}));return this._tweens.map(function(t,r){t._startTime=e[r]}),this},e.prototype.getTiming=function(t,e,r,n){if(void 0===n&&(n=0),"reverse"===t){var i=r.stagger,o=(i||0)*(e.length-1);return e.map(function(t,e){return o-(i||0)*e+n})}if("async"===t)return e.map(function(t){return n});if("sequence"===t||"delayed"===t){var s=r.stagger;return s||(s=(r.duration||1e3)/(e.length-1)),e.map(function(t,e){return s*e+n})}if("oneByOne"===t)return e.map(function(t){return r.duration});if("shuffle"===t){var u=r.stagger;return N(e.map(function(t,e){return(u||0)*e+n}))}var a=r.stagger;return e.map(function(t,e){return(a||0)*e+n})},e.prototype.fromTo=function(t,e,r,n){if((t=I(t,!0))&&t.length){this._defaultParams&&(n=E({},this._defaultParams,n));for(var i=n.label,o="number"==typeof i?i:this.position.parseLabel(void 0!==i?i:"afterLast",null),s=this.getTiming(n.mode,t,n,o),u=0,a=void 0,f=t.length;u<f;u++)a=t[u],this.add(k.fromTo(a,"function"==typeof e?e(u,t.length):E({},e),"function"==typeof r?r(u,t.length):r,"function"==typeof n?n(u,t.length):n),s[u])}return this.start()},e.prototype.from=function(t,e,r){return this.fromTo(t,e,null,r)},e.prototype.to=function(t,e,r){return this.fromTo(t,null,e,r)},e.prototype.addLabel=function(t,e){return this.position.addLabel(t,e),this},e.prototype.map=function(t){for(var e=0,r=this._tweens.length;e<r;e++){var n=this._tweens[e];t(n,e),this._duration=Math.max(this._duration,n._duration+n._startTime)}return this},e.prototype.add=function(t,e){var r=this;if(Array.isArray(t))return t.map(function(t){r.add(t,e)}),this;"object"!=typeof t||t instanceof k||(t=new k(t.from).to(t.to,t));var n=this,i=n._defaultParams,o=n._duration;if(i)for(var s in i)"function"==typeof t[s]&&t[s](i[s]);var u="number"==typeof e?e:this.position.parseLabel(void 0!==e?e:"afterLast",null);return t._startTime=Math.max(this._startTime,t._delayTime,u),t._delayTime=u,t._isPlaying=!0,this._duration=Math.max(o,t._startTime+t._delayTime+t._duration),this._tweens.push(t),this.position.setLabel("afterLast",this._duration),this},e.prototype.restart=function(){return this._startTime+=a(),_(this),this.emit("restart")},e.prototype.easing=function(t){return this.map(function(e){return e.easing(t)})},e.prototype.interpolation=function(t){return this.map(function(e){return e.interpolation(t)})},e.prototype.update=function(t){var e=this,r=e._tweens,n=e._duration,i=e._reverseDelayTime,o=e._startTime,s=e._reversed,u=e._yoyo,a=e._repeat,f=e._isFinite;if(!e._isPlaying||t<o)return!0;var h=(t-o)/n;h=h>1?1:h,h=s?1-h:h,this.elapsed=h;for(var p=t-o,l=s?n-p:p,c=0;c<r.length;)r[c].update(l),c++;if(this.emit("update",h,p),1===h||s&&0===h){if(a){for(f&&this._repeat--,this.emit(s?"reverse":"repeat"),u&&(this._reversed=!s,this.timingOrder(function(t){return t.reverse()})),this._startTime=s&&i?t+i:t,c=0;c<r.length;)r[c].reassignValues(t),c++;return!0}return this.emit("complete"),this._repeat=this._r,v(this),this._isPlaying=!1,!1}return!0},e.prototype.progress=function(t){return void 0!==t?this.update(t*this._duration):this.elapsed},e}(k);t.Plugins=g,t.Selector=I,t.onTick=function(t){return f.push({update:t})},t.has=function(t){return null!==y(t)},t.get=y,t.getAll=function(){return f},t.removeAll=function(){f.length=0},t.remove=v,t.add=_,t.now=a,t.update=m,t.autoPlay=function(t){p=t},t.isRunning=function(){return h},t.Tween=k,t.Easing=T,t.Interpolation=b,t.Timeline=U,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 e(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 r={};for(var n in t)r[n]=e(t[n]);return r}return t}function r(t){return"string"!=typeof t?t:t.replace(I,O).match(w).map(function(t){return A(t)?t:+t})}function n(t,e,i,o,s){var u=i[t],a=o[t];if("string"==typeof u||"string"==typeof a){for(var f=Array.isArray(u)&&u[0]===j?u:r(u),h=Array.isArray(a)&&a[0]===j?a:r(a),l=1;l<f.length;)f[l]===h[l]&&"string"==typeof f[l-1]?(f.splice(l-1,2,f[l-1]+f[l]),h.splice(l-1,2,h[l-1]+h[l])):l++;l=0,f[0]===j&&f.shift(),h[0]===j&&h.shift();for(var c={isString:!0,length:f.length},p={isString:!0,length:h.length};l<c.length;)c[l]=f[l],p[l]=h[l],l++;return i[t]=c,o[t]=p,!0}if("object"==typeof u&&"object"==typeof a){if(Array.isArray(u))return u.map(function(r,i){return n(i,e[t],u,a)});for(var y in a)n(y,e[t],u,a);return!0}return!1}function i(t,e,r,n,o,s,u){var a=u?r:r[t],f=u?n:n[t];if(void 0===f)return a;if(void 0===a||"string"==typeof a||a===f)return f;if("object"==typeof a&&"object"==typeof f){if(!a||!f)return e[t];if("object"==typeof a&&a&&a.isString){for(var h="",l=0,c=a.length;l<c;l++){var p="number"==typeof a[l]&&"string"==typeof f[l]&&"="===f[l][1],y="number"!=typeof a[l]?a[l]:((p?a[l]+parseFloat(f[l][0]+f[l].substr(2))*o:a[l]+(f[l]-a[l])*o)*M|0)/M;(P(a,l)||P(a,l,R))&&(y|=0),h+=y,p&&1===s&&(a[l]=a[l]+parseFloat(f[l][0]+f[l].substr(2)))}return u||(e[t]=h),h}if(Array.isArray(a)&&a[0]!==j)for(var l=0,c=a.length;l<c;l++)a[l]!==f[l]&&i(l,e[t],a,f,o,s);else if("object"==typeof a&&a&&!a.isString)for(var l in a)a[l]!==f[l]&&i(l,e[t],a,f,o,s)}else if("number"==typeof a){p="string"==typeof f;e[t]=((p?a+parseFloat(f[0]+f.substr(2))*o:a+(f-a)*o)*M|0)/M,p&&1===s&&(r[t]=e[t])}else"function"==typeof f&&(e[t]=f(o));return e[t]}var o,s="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,u=s.requestAnimationFrame||function(t){return s.setTimeout(t,16)},a=s.cancelAnimationFrame||function(t){return s.clearTimeout(t)},f=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==s.performance&&void 0!==s.performance.now)return s.performance.now.bind(s.performance);var t=s.performance&&s.performance.timing&&s.performance.timing.navigationStart?s.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),h=[],l=!1,c=!1,p=u,y=a,d=0,v=function(t){var e=h.indexOf(t);e>-1&&h.splice(e,1),h.push(t),d=0,c&&!l&&(o=p(g),l=!0)},_=function(t){for(var e=0;e<h.length;e++)if(t===h[e])return h[e];return null},m=function(t){var e=h.indexOf(t);-1!==e&&h.splice(e,1)},g=function(t,e){if(t=void 0!==t?t:f(),c&&l&&(o=p(g)),h.length||d++,d>120)return y(o),l=!1,d=0,!1;for(var r=0;r<h.length;)h[r++].update(t,e);return!0},b={},T={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+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-T.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*T.Bounce.In(2*t):.5*T.Bounce.Out(2*t-1)+.5}},Stepped:{steps:function(t){return function(e){return(e*t|0)/t}}}},j="STRING_PROP",w=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]=+)?([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]=?\d+)?/g,A=function(t){return isNaN(+t)||("+"===t[0]||"-"===t[0])&&"="===t[1]||""===t||" "===t},I=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,O=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 r=o>>16&255,n=o>>8&255,i=255&o,"rgb("+r+","+n+","+i+")"},M=Math.pow(10,4),R="rgba(",P=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)},F=/([.\[])/g,S=/\]/g,q=function(t,e){var r=t[e],n=e.replace(S,"").split(F),i=n.length-1,o=Array.isArray(t),s="object"==typeof t&&!o;return s?(t[e]=null,delete t[e]):o&&t.splice(e,1),n.reduce(function(t,e,u){o&&"."!==e&&"["!==e&&(e*=1);var a="["===n[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===i?r:o||a?[]:s?{}:null,s=o=!1,t[e]}else if(void 0!==t[e])return u===i&&(t[e]=r),t[e];return t},t)},C=function(t){if("object"==typeof t&&t)for(var e in t)if(-1!==e.indexOf(".")||-1!==e.indexOf("["))q(t,e);else if("object"==typeof t[e]&&t[e]){var r=t[e];for(var n in r)if(-1!==n.indexOf(".")||-1!==n.indexOf("["))q(r,n);else if("object"==typeof r[n]&&r[n]){var i=r[n];for(var o in i)-1===o.indexOf(".")&&-1===o.indexOf("[")||q(i,o)}}return t},k={Linear:function(t,e,r){var n=t.length-1,i=n*e,o=Math.floor(i),s=k.Utils.Linear;return e<0?s(t[0],t[1],i,r):e>1?s(t[n],t[n-1],n-i,r):s(t[o],t[o+1>n?n:o+1],i-o,r)},Bezier:function(t,e,r){for(var n=k.Utils.Reset(r),i=t.length-1,o=Math.pow,s=k.Utils.Bernstein,u=Array.isArray(n),a=0;a<=i;a++)if("number"==typeof n)n+=o(1-e,i-a)*o(e,a)*t[a]*s(i,a);else if(u)for(var f=0,h=n.length;f<h;f++)"number"==typeof n[f]?n[f]+=o(1-e,i-a)*o(e,a)*t[a][f]*s(i,a):n[f]=t[a][f];else if("object"==typeof n)for(var f in n)"number"==typeof n[f]?n[f]+=o(1-e,i-a)*o(e,a)*t[a][f]*s(i,a):n[f]=t[a][f];else if("string"==typeof n){for(var l="",c=Math.round(i*e),p=t[c],y=1,h=p.length;y<h;y++)l+=p[y];return l}return n},CatmullRom:function(t,e,r){var n=t.length-1,i=n*e,o=Math.floor(i),s=k.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(o=Math.floor(i=n*(1+e))),s(t[(o-1+n)%n],t[o],t[(o+1)%n],t[(o+2)%n],i-o,r)):e<0?s(t[1],t[1],t[0],t[0],-e,r):e>1?s(t[n-1],t[n-1],t[n],t[n],(0|e)-e,r):s(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"==typeof t){if(void 0!==t.length){if(t[0]===j){for(var i="",o=1,s=t.length;o<s;o++){var u="number"==typeof t[o]?t[o]+(e[o]-t[o])*r:e[o];(P(t,o)||P(t,o,R))&&(u|=0),i+=u}return i}for(var a=0,s=n.length;a<s;a++)n[a]=k.Utils.Linear(t[a],e[a],r,n[a])}else for(var a in n)n[a]=k.Utils.Linear(t[a],e[a],r,n[a]);return n}},Reset:function(t){if(Array.isArray(t)){for(var e=0,r=t.length;e<r;e++)t[e]=k.Utils.Reset(t[e]);return t}if("object"==typeof t){for(var e in t)t[e]=k.Utils.Reset(t[e]);return t}return"number"==typeof t?0:t},Bernstein:function(t,e){var r=k.Utils.Factorial;return r(t)/r(e)/r(t-e)},Factorial:function(){var t=[1];return function(e){var r=1;if(t[e])return t[e];for(var n=e;n>1;n--)r*=n;return t[e]=r,r}}(),CatmullRom:function(t,e,r,n,i,o){if("string"==typeof t)return e;if("number"==typeof t){var s=.5*(r-t),u=.5*(n-e),a=i*i;return(2*e-2*r+s+u)*(i*a)+(-3*e+3*r-2*s-u)*a+s*i+e}if("object"==typeof t){if(void 0!==t.length){if(t[0]===j){for(var f="",h=1,l=t.length;h<l;h++){var c="number"==typeof t[h]?k.Utils.CatmullRom(t[h],e[h],r[h],n[h],i):n[h];(P(t,h)||P(t,h,R))&&(c|=0),f+=c}return f}for(var p=0,l=o.length;p<l;p++)o[p]=k.Utils.CatmullRom(t[p],e[p],r[p],n[p],i,o[p])}else for(var p in o)o[p]=k.Utils.CatmullRom(t[p],e[p],r[p],n[p],i,o[p]);return o}}}},x=this&&this.__assign||Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},L={},D=function(t,e,r){if(!t||!t.nodeType)return e;var n=t.queueID||"q_"+Date.now();t.queueID||(t.queueID=n);var i=L[n];if(i){if(i.object===e&&t===i.tween.node&&r._startTime===i.tween._startTime)m(i.tween);else if("object"==typeof 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=x({},i.object,e)}return i.object}return"object"==typeof e&&e?(L[n]={tween:r,object:e,propNormaliseRequired:!1},L[n].object):e},U=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},N=0,E=T.Linear.None,B=function(){function t(t,e){return this._chainedTweensCount=0,this.id=N++,!t||"object"!=typeof t||e||t.nodeType?t&&(t.nodeType||t.length||"string"==typeof t)&&(t=this.node=U(t),e=this.object=D(t,e,this)):(e=this.object=t,t=null),this._valuesEnd=null,this._valuesStart={},this._duration=1e3,this._easingFunction=E,this._easingReverse=E,this._interpolationFunction=k.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,n,i){void 0===i&&(i={}),i.quickRender=i.quickRender?i.quickRender:!n;var o=new t(e,r).to(n,i);return i.quickRender&&(o.render().update(o._startTime),o._rendered=!1,o._onStartCallbackFired=!1),o},t.to=function(e,r,n){return t.fromTo(e,null,r,n)},t.from=function(e,r,n){return t.fromTo(e,r,null,n)},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,n=t+"Callback",i=0;i<r;i++){var o=n+i;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,n=t+"Callback",i=0;i<r;i++){var o=n+i;this[o]===e&&(this[o]=null)}return this},t.prototype.emit=function(t,e,r,n,i){var o=this._maxListener,s=t+"Callback";if(!this[s+0])return this;for(var u=0;u<o;u++){var a=s+u;this[a]&&this[a](e,r,n,i)}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,m(this),this._pausedTime=f(),this.emit("pause",this.object)):this},t.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=f()-this._pausedTime,this._initTime=this._startTime,v(this),this._pausedTime=f(),this.emit("play",this.object))},t.prototype.restart=function(t){return this._repeat=this._r,this.reassignValues(),v(this),this.emit("restart",this.object)},t.prototype.seek=function(t,e){var r=this,n=r._duration,i=(r._repeat,r._initTime),o=r._startTime,s=(r._delayTime,r._reversed),u=i+t;return this._isPlaying=!0,u<o&&o>=i&&(this._startTime-=n,this._reversed=!s),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 n in e)if("function"==typeof this[n]){var i=Array.isArray(e[n])?e[n]:[e[n]],o=i[0],s=void 0===o?null:o,u=i[1],a=void 0===u?null:u,f=i[2],h=void 0===f?null:f,l=i[3],c=void 0===l?null:l;this[n](s,a,h,c)}return this},t.prototype.render=function(){if(this._rendered)return this;var i=this,o=i._valuesStart,s=i._valuesEnd,u=i.object,a=i.node,f=i.InitialValues;if(C(u),C(s),a&&a.queueID&&L[a.queueID]){var h=L[a.queueID];if(h.propNormaliseRequired&&h.tween!==this){for(var l in s);h.normalisedProp=!0,h.propNormaliseRequired=!1}}a&&f&&(u&&0!==Object.keys(u).length?s&&0!==Object.keys(s).length||(s=this._valuesEnd=f(a,u)):u=this.object=D(a,f(a,s),this));for(var l in s){var c=u&&u[l]&&e(u[l]),p=s[l];if(!(b[l]&&b[l].init&&(b[l].init.call(this,c,p,l,u),void 0===c&&o[l]&&(c=o[l]),b[l].skipProcess))&&!("number"==typeof c&&isNaN(c)||null===c||null===p||!1===c||!1===p||void 0===c||void 0===p||c===p)){if(Array.isArray(p)&&!Array.isArray(c)){p.unshift(c);for(var y=0,d=p.length;y<d;y++)if("string"==typeof p[y]){for(var v=r(p[y]),_={length:v.length,isString:!0},m=0,g=v.length;m<g;m++)_[m]=v[m];p[y]=_}}o[l]=c,"number"==typeof c&&"string"==typeof p&&"="===p[1]||n(l,u,o,s)}}return t.Renderer&&this.node&&t.Renderer.init&&(t.Renderer.init.call(this,u,o,s),this.__render=!0),this},t.prototype.start=function(t){return this._startTime=void 0!==t?"string"==typeof t?f()+parseFloat(t):t:f(),this._startTime+=this._delayTime,this._initTime=this._prevTime=this._startTime,this._onStartCallbackFired=!1,this._rendered=!1,this._isPlaying=!0,v(this),this},t.prototype.stop=function(){var t=this,e=t._isPlaying,r=t._isFinite,n=t.object,i=t._startTime,o=(t._delayTime,t._duration),s=t._r,u=t._yoyo,a=t._reversed;if(!e)return this;var f=r?(s+1)%2==1:!a;return this._reversed=!1,u&&f?this.update(i):this.update(i+o),m(this),this.emit("stop",n)},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["_chainedTweens"+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,r=e._valuesStart,n=e.object,i=e._delayTime;this._isPlaying=!0,this._startTime=void 0!==t?t:f(),this._startTime+=i,this._reversed=!1,v(this);for(var o in r){var s=r[o];n[o]=s}return this},t.prototype.update=function(e,r,n){var o,s,u,a=this,h=a._onStartCallbackFired,l=a._easingFunction,c=a._interpolationFunction,p=a._easingReverse,y=a._repeat,d=a._delayTime,v=a._reverseDelayTime,_=a._yoyo,g=a._reversed,T=a._startTime,j=a._prevTime,w=a._duration,A=a._valuesStart,I=a._valuesEnd,O=a.object,R=a._isFinite,P=a._isPlaying,F=a.__render,S=a._chainedTweensCount,q=0;if(w){var C=(e=void 0!==e?e:f())-j;if(this._prevTime=e,C>250&&(e-=C-50/3),!P||e<T&&!n)return!0;o=(o=(e-T)/w)>1?1:o,o=g?1-o:o}else o=1,y=0;if(h||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",O),this._onStartCallbackFired=!0),s=g?p||l:l,!O)return!0;for(u in I){var x=A[u];if(void 0!==x&&null!==x||b[u]&&b[u].update){var L=I[u],D=s[u]?s[u](o):"function"==typeof s?s(o):E(o),U=c[u]?c[u]:"function"==typeof c?c:k.Linear;"number"==typeof L?O[u]=((x+(L-x)*D)*M|0)/M:Array.isArray(L)&&!Array.isArray(x)?O[u]=U(L,D,O[u]):L&&L.update?L.update(D):"function"==typeof L?O[u]=L(D):"string"==typeof L&&"number"==typeof x?O[u]=x+parseFloat(L[0]+L.substr(2))*D:i(u,O,A,I,D,o),b[u]&&b[u].update&&b[u].update.call(this,O[u],x,L,D,o),q++}}if(!q)return m(this),!1;if(F&&t.Renderer&&t.Renderer.update&&t.Renderer.update.call(this,O,o),this.emit("update",O,o,e),1===o||g&&0===o){if(y>0&&w>0){if(R&&this._repeat--,_)this._reversed=!g;else for(u in I)"string"==typeof(L=I[u])&&"number"==typeof A[u]&&(A[u]+=parseFloat(L[0]+L.substr(2)));return this.emit(_&&!g?"reverse":"repeat",O),this._startTime=g&&v?e-v:e+d,!0}if(r||(this._isPlaying=!1,m(this),N--),this.emit("complete",O),this._repeat=this._r,S)for(var B=0;B<S;B++)this["_chainedTweens"+B].start(e+w);return!1}return!0},t}();t.Plugins=b,t.Selector=U,t.Interpolator=function(t,e){var o=Array.isArray(t),s="string"==typeof t?t:o?t.slice():Object.assign({},t);if(o)for(var u=0,a=t.length;u<a;u++)n(u,s,t,e);else if("object"==typeof t)for(var u in t)n(u,s,t,e);else if("string"==typeof t){for(t=r(t),e=r(e),u=1;u<t.length;)t[u]===e[u]&&"string"==typeof t[u-1]?(t.splice(u-1,2,t[u-1]+t[u]),e.splice(u-1,2,e[u-1]+e[u])):u++;for(var f={isString:!0,length:t.length};u<f.length;)f[u]=t[u],u++}return function(r){if(o)for(var n=0,u=t.length;n<u;n++)i(n,s,t,e,r);else if("object"==typeof s)for(var n in t)i(n,s,t,e,r);else"string"==typeof s&&(s=i(0,0,t,e,r,r,!0));return s}},t.onTick=function(t){return h.push({update:t})},t.has=function(t){return null!==_(t)},t.get=_,t.getAll=function(){return h},t.removeAll=function(){h.length=0},t.remove=m,t.add=v,t.now=f,t.update=g,t.autoPlay=function(t){c=t},t.isRunning=function(){return l},t.Tween=B,t.Easing=T,t.Interpolation=k,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "es6-tween", | ||
"version": "4.1.0", | ||
"version": "5.0.1", | ||
"description": "ES6 implementation of amazing tween.js", | ||
"browser": "full/Tween.min.js", | ||
"cdn": "full/Tween.min.js", | ||
"main": "full/Tween.js", | ||
"browser": "bundled/Tween.min.js", | ||
"cdn": "bundled/Tween.min.js", | ||
"main": "bundled/Tween.js", | ||
"module": "src/index.js", | ||
"types": "src/index.d.ts", | ||
"directories": { | ||
@@ -14,3 +15,3 @@ "example": "examples" | ||
"source": "rollup -c", | ||
"minify": "uglifyjs full/Tween.js -c -m -o full/Tween.min.js --source-map \"filename='full/Tween.min.js.map'\"", | ||
"minify": "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", | ||
@@ -17,0 +18,0 @@ "dev": "rollup -c -w", |
@@ -7,3 +7,3 @@ var rollup = require('rollup') | ||
format: 'umd', | ||
file: 'full/Tween.js' | ||
file: 'bundled/Tween.js' | ||
}, | ||
@@ -10,0 +10,0 @@ sourcemap: true, |
@@ -19,5 +19,9 @@ export declare const FRAME_MS: number; | ||
export declare function deepCopy(source: any): any; | ||
export declare function decompose(prop: any, obj: any, from: any, to: any): any; | ||
export declare function decomposeString(fromValue: string): any[]; | ||
export declare function decompose(prop: any, obj: any, from: any, to: any, stringBuffer?: any): any; | ||
export declare const DECIMAL: number; | ||
export declare function recompose(prop: any, obj: any, from: any, to: any, t: any, originalT?: any): any; | ||
export declare const RGB = "rgb("; | ||
export declare const RGBA = "rgba("; | ||
export declare const isRGBColor: (v: any, i: any, r?: string) => boolean; | ||
export declare function recompose(prop: any, obj: any, from: any, to: any, t: any, originalT?: any, stringBuffer?: any): any; | ||
export declare const SET_NESTED: (nested: any) => any; |
@@ -20,7 +20,7 @@ // Frame lag-fix constants | ||
// Also RegExp's for string tweening | ||
export var NUM_REGEX = /\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g; | ||
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; | ||
// Copies everything, duplicates, no shallow-copy | ||
export function deepCopy(source) { | ||
if (source === undefined || typeof source !== 'object') { | ||
if ((source && source.nodeType) || source === undefined || typeof source !== 'object') { | ||
return source; | ||
@@ -41,18 +41,57 @@ } | ||
var isNaNForST = function (v) { | ||
return isNaN(+v) || v[0] === '+' || v[0] === '-' || v === '' || 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 + ")"; | ||
}; | ||
export 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 | ||
export function decompose(prop, obj, from, to) { | ||
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 = fromValue | ||
.match(NUM_REGEX) | ||
.map(function (v) { return (isNaNForST(v) ? v : +v); }); | ||
var toValue1 = toValue | ||
.match(NUM_REGEX) | ||
.map(function (v, i) { return (isNaNForST(v) ? v : +v); }); | ||
fromValue1.unshift(STRING_PROP); | ||
from[prop] = fromValue1; | ||
to[prop] = toValue1; | ||
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; | ||
@@ -77,5 +116,12 @@ } | ||
export var DECIMAL = Math.pow(10, 4); | ||
export function recompose(prop, obj, from, to, t, originalT) { | ||
var fromValue = from[prop]; | ||
var toValue = to[prop]; | ||
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 function recompose(prop, obj, from, to, t, originalT, stringBuffer) { | ||
var fromValue = stringBuffer ? from : from[prop]; | ||
var toValue = stringBuffer ? to : to[prop]; | ||
if (toValue === undefined) { | ||
@@ -93,23 +139,31 @@ return fromValue; | ||
} | ||
if (fromValue[0] === STRING_PROP) { | ||
if (typeof fromValue === 'object' && !!fromValue && fromValue.isString) { | ||
var STRING_BUFFER = ''; | ||
for (var i = 1, len = fromValue.length; i < len; i++) { | ||
var isRelative = typeof toValue[i - 1] === 'string'; | ||
STRING_BUFFER += | ||
typeof toValue[i - 1] !== 'number' | ||
? fromValue[i] | ||
: (((isRelative | ||
? fromValue[i] + +toValue[i - 1] | ||
: fromValue[i] + (toValue[i - 1] - fromValue[i]) * t) * | ||
DECIMAL) | | ||
0) / | ||
DECIMAL; | ||
if (originalT === 1) { | ||
fromValue[i] = fromValue[i] + +toValue[i - 1]; | ||
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)); | ||
} | ||
} | ||
obj[prop] = STRING_BUFFER; | ||
if (!stringBuffer) { | ||
obj[prop] = STRING_BUFFER; | ||
} | ||
return STRING_BUFFER; | ||
} | ||
else if (Array.isArray(fromValue)) { | ||
else if (Array.isArray(fromValue) && fromValue[0] !== STRING_PROP) { | ||
for (var i = 0, len = fromValue.length; i < len; i++) { | ||
@@ -122,3 +176,3 @@ if (fromValue[i] === toValue[i]) { | ||
} | ||
else { | ||
else if (typeof fromValue === 'object' && !!fromValue && !fromValue.isString) { | ||
for (var i in fromValue) { | ||
@@ -136,3 +190,3 @@ if (fromValue[i] === toValue[i]) { | ||
(((isRelative | ||
? fromValue + +toValue * t | ||
? fromValue + parseFloat(toValue[0] + toValue.substr(2)) * t | ||
: fromValue + (toValue - fromValue) * t) * | ||
@@ -139,0 +193,0 @@ DECIMAL) | |
@@ -72,3 +72,3 @@ /** | ||
* Updates global tweens by given time | ||
* @param {number|Time} time Timestamp | ||
* @param {number=} time Timestamp | ||
* @param {Boolean=} preserve Prevents tween to be removed after finish | ||
@@ -79,3 +79,3 @@ * @memberof TWEEN | ||
*/ | ||
declare const update: (time: number, preserve?: boolean) => boolean; | ||
declare const update: (time?: number, preserve?: boolean) => boolean; | ||
/** | ||
@@ -82,0 +82,0 @@ * The state of ticker running |
@@ -11,3 +11,3 @@ /* global process */ | ||
var now = (function () { | ||
if (typeof process !== 'undefined' && process.hrtime !== undefined) { | ||
if (typeof process !== 'undefined' && process.hrtime !== undefined && (!process.versions || process.versions.electron === undefined)) { | ||
return function () { | ||
@@ -69,8 +69,2 @@ var time = process.hrtime(); | ||
} | ||
if (_tweens.length > 0) { | ||
i = _tweens.length - 1; | ||
var tweenPrev = _tweens[i]; | ||
tween.prev = tweenPrev; | ||
tweenPrev.next = tween; | ||
} | ||
_tweens.push(tween); | ||
@@ -165,3 +159,3 @@ emptyFrame = 0; | ||
* Updates global tweens by given time | ||
* @param {number|Time} time Timestamp | ||
* @param {number=} time Timestamp | ||
* @param {Boolean=} preserve Prevents tween to be removed after finish | ||
@@ -168,0 +162,0 @@ * @memberof TWEEN |
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
import Easing from './Easing'; | ||
import Interpolation from './Interpolation'; | ||
import Timeline from './Timeline'; | ||
import Tween from './Tween'; | ||
import Selector from './selector'; | ||
import Interpolator from './Interpolator'; | ||
import './shim'; | ||
export { Plugins, Selector, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Interpolation, Timeline }; | ||
export { Plugins, Selector, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Interpolation }; |
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update, } from './core'; | ||
import Easing from './Easing'; | ||
import Interpolation from './Interpolation'; | ||
import Timeline from './Timeline'; | ||
import Tween from './Tween'; | ||
import Selector from './selector'; | ||
import Interpolator from './Interpolator'; | ||
import './shim'; | ||
export { Plugins, Selector, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Interpolation, Timeline, }; | ||
export { Plugins, Selector, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Interpolation }; |
@@ -13,11 +13,12 @@ /** | ||
Linear(v: any, k: any, value: any): any; | ||
Bezier(v: any, k: any, value: any): number; | ||
Bezier(v: any, k: any, value: any): any; | ||
CatmullRom(v: any, k: any, value: any): any; | ||
Utils: { | ||
Linear(p0: any, p1: any, t: any, v: any): any; | ||
Reset(value: any): any; | ||
Bernstein(n: any, i: any): number; | ||
Factorial: (n: any) => number; | ||
CatmullRom(p0: any, p1: any, p2: any, p3: any, t: any, v: any): any; | ||
CatmullRom(p0: any, p1: any, p2: any, p3: any, t: any, v?: any): any; | ||
}; | ||
}; | ||
export default Interpolation; |
@@ -0,1 +1,2 @@ | ||
import { isRGBColor, RGBA, STRING_PROP } from './constants'; | ||
/** | ||
@@ -26,8 +27,38 @@ * List of full Interpolation | ||
Bezier: function (v, k, value) { | ||
var b = 0; | ||
var b = Interpolation.Utils.Reset(value); | ||
var n = v.length - 1; | ||
var pw = Math.pow; | ||
var bn = Interpolation.Utils.Bernstein; | ||
var fn = Interpolation.Utils.Bernstein; | ||
var isBArray = Array.isArray(b); | ||
for (var i = 0; i <= n; i++) { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(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]; | ||
} | ||
} | ||
} | ||
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; | ||
} | ||
} | ||
@@ -43,3 +74,3 @@ return b; | ||
if (k < 0) { | ||
i = Math.floor(f = m * (1 + k)); | ||
i = Math.floor((f = m * (1 + k))); | ||
} | ||
@@ -50,6 +81,6 @@ return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i, value); | ||
if (k < 0) { | ||
return v[0] - (fn(v[0], v[0], v[1], v[1], -f, value) - v[0]); | ||
return fn(v[1], v[1], v[0], v[0], -k, value); | ||
} | ||
if (k > 1) { | ||
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m, value) - v[m]); | ||
return fn(v[m - 1], v[m - 1], v[m], v[m], (k | 0) - k, value); | ||
} | ||
@@ -61,10 +92,21 @@ 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); | ||
Linear: function (p0, p1, t, v) { | ||
if (typeof v === 'string') { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} | ||
else if (typeof v === 'number') { | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0; | ||
else if (typeof p0 === 'number') { | ||
return typeof p0 === 'function' ? p0(t) : p0 + (p1 - p0) * t; | ||
} | ||
else if (typeof v === 'object') { | ||
if (v.length !== undefined) { | ||
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++) { | ||
@@ -82,2 +124,20 @@ v[p] = Interpolation.Utils.Linear(p0[p], p1[p], t, v[p]); | ||
}, | ||
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) { | ||
@@ -102,6 +162,6 @@ var fc = Interpolation.Utils.Factorial; | ||
CatmullRom: function (p0, p1, p2, p3, t, v) { | ||
if (typeof v === 'string') { | ||
if (typeof p0 === 'string') { | ||
return p1; | ||
} | ||
else if (typeof v === 'number') { | ||
else if (typeof p0 === 'number') { | ||
var v0 = (p2 - p0) * 0.5; | ||
@@ -111,6 +171,22 @@ var v1 = (p3 - p1) * 0.5; | ||
var t3 = t * t2; | ||
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; | ||
return ((2 * p1 - 2 * p2 + v0 + v1) * t3 + | ||
(-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + | ||
v0 * t + | ||
p1); | ||
} | ||
else if (typeof v === 'object') { | ||
if (v.length !== undefined) { | ||
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++) { | ||
@@ -117,0 +193,0 @@ v[p] = Interpolation.Utils.CatmullRom(p0[p], p1[p], p2[p], p3[p], t, v[p]); |
@@ -0,1 +1,9 @@ | ||
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'; | ||
@@ -18,3 +26,3 @@ export var Store = {}; | ||
} | ||
else { | ||
else if (typeof object === 'object' && !!object && !!storeID.object) { | ||
for (var prop in object) { | ||
@@ -30,8 +38,11 @@ if (prop in storeID.object) { | ||
} | ||
return object; | ||
storeID.object = __assign({}, storeID.object, object); | ||
} | ||
return storeID.object; | ||
} | ||
Store[ID] = { tween: tween, object: object, propNormaliseRequired: false }; | ||
return Store[ID].object; | ||
if (typeof object === 'object' && !!object) { | ||
Store[ID] = { tween: tween, object: object, propNormaliseRequired: false }; | ||
return Store[ID].object; | ||
} | ||
return object; | ||
} |
@@ -9,6 +9,7 @@ import Tween from './Tween'; | ||
* @class | ||
* @namespace Timeline | ||
* @namespace TWEEN.Timeline | ||
* @param {Object=} params Default params for new tweens | ||
* @example let tl = new Timeline({delay:200}) | ||
* @extends Tween | ||
* @deprecated | ||
*/ | ||
@@ -15,0 +16,0 @@ declare class Timeline extends Tween { |
@@ -22,3 +22,3 @@ var __extends = (this && this.__extends) || (function () { | ||
import Tween from './Tween'; | ||
import { EVENT_COMPLETE, EVENT_REPEAT, EVENT_REVERSE, EVENT_RESTART, EVENT_UPDATE, } from './constants'; | ||
import { EVENT_COMPLETE, EVENT_REPEAT, EVENT_REVERSE, EVENT_RESTART, EVENT_UPDATE, FRAME_MS, TOO_LONG_FRAME_MS } from './constants'; | ||
import Selector from './selector'; | ||
@@ -44,6 +44,7 @@ export var shuffle = function (a) { | ||
* @class | ||
* @namespace Timeline | ||
* @namespace TWEEN.Timeline | ||
* @param {Object=} params Default params for new tweens | ||
* @example let tl = new Timeline({delay:200}) | ||
* @extends Tween | ||
* @deprecated | ||
*/ | ||
@@ -127,3 +128,3 @@ var Timeline = /** @class */ (function (_super) { | ||
node = nodes[i]; | ||
this.add(Tween.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : __assign({}, from), typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), mode[i]); | ||
this.add(Tween.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : typeof from === 'object' && !!from ? __assign({}, from) : null, typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), mode[i]); | ||
} | ||
@@ -223,3 +224,8 @@ } | ||
Timeline.prototype.update = function (time) { | ||
var _a = this, _tweens = _a._tweens, _duration = _a._duration, _reverseDelayTime = _a._reverseDelayTime, _startTime = _a._startTime, _reversed = _a._reversed, _yoyo = _a._yoyo, _repeat = _a._repeat, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying; | ||
var _a = this, _tweens = _a._tweens, _duration = _a._duration, _reverseDelayTime = _a._reverseDelayTime, _startTime = _a._startTime, _reversed = _a._reversed, _yoyo = _a._yoyo, _repeat = _a._repeat, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying, _prevTime = _a._prevTime; | ||
var delta = time - _prevTime; | ||
this._prevTime = time; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
time -= delta - FRAME_MS; | ||
} | ||
if (!_isPlaying || time < _startTime) { | ||
@@ -226,0 +232,0 @@ return true; |
export interface Params { | ||
quickRender?: boolean; | ||
} | ||
export interface RenderType { | ||
update?: Function; | ||
} | ||
/** | ||
@@ -11,4 +8,3 @@ * Tween main constructor | ||
* @class | ||
* @namespace Tween | ||
* @extends Tween | ||
* @namespace TWEEN.Tween | ||
* @param {Object|Element} node Node Element or Tween initial object | ||
@@ -35,3 +31,2 @@ * @param {Object=} object If Node Element is using, second argument is used for Tween initial object | ||
node: any; | ||
Renderer: any; | ||
_r: number; | ||
@@ -42,9 +37,10 @@ _reversed: boolean; | ||
elapsed: number; | ||
_prevTime: number; | ||
private _onStartCallbackFired; | ||
private _rendered; | ||
private __render; | ||
static Renderer: any; | ||
private InitialValues; | ||
private _maxListener; | ||
private _chainedTweensCount; | ||
private _prevTime; | ||
/** | ||
@@ -57,3 +53,3 @@ * Easier way to call the Tween | ||
* @example Tween.fromTo(node, {x:0}, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -68,3 +64,3 @@ */ | ||
* @example Tween.to(node, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -79,3 +75,3 @@ */ | ||
* @example Tween.from(node, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -88,3 +84,3 @@ */ | ||
* @param {number} count - Event listener's count | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -96,3 +92,3 @@ setMaxListener(count?: number): this; | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -105,3 +101,3 @@ on(event: string, callback: Function): this; | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -113,3 +109,3 @@ once(event: string, callback: Function): this; | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -120,3 +116,3 @@ off(event: string, callback: Function): this; | ||
* @param {string} event - Event listener name | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -127,3 +123,3 @@ emit(event: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any): this; | ||
* @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -134,3 +130,3 @@ isPlaying(): boolean; | ||
* @example tween.isStarted() // returns `true` if tween in started | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -142,3 +138,3 @@ isStarted(): boolean; | ||
* @param {boolean=} state Set state of current reverse | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -149,3 +145,3 @@ reverse(state?: boolean): this; | ||
* @example tween.reversed() // returns `true` if tween in reversed state | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -156,3 +152,3 @@ reversed(): boolean; | ||
* @example tween.pause() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -163,3 +159,3 @@ pause(): this; | ||
* @example tween.play() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -171,3 +167,3 @@ play(): this; | ||
* @example tween.restart() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -180,3 +176,3 @@ restart(noDelay?: boolean): this; | ||
* @example tween.seek(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @deprecated Not works as excepted, so we deprecated this method | ||
@@ -189,3 +185,3 @@ */ | ||
* @example tween.duration(2000) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -198,3 +194,3 @@ duration(amount: number): this; | ||
* @example let tween = new Tween({x:0}).to({x:100}, 2000) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -205,3 +201,3 @@ to(properties: Object, duration?: any, maybeUsed?: any): this; | ||
* @private | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -213,3 +209,3 @@ render(): this; | ||
* @example tween.start() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -220,3 +216,3 @@ start(time?: number | string): this; | ||
* @example tween.stop() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -228,3 +224,3 @@ stop(): this; | ||
* @example tween.delay(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -236,3 +232,3 @@ delay(amount: number): this; | ||
* @example tween.chainedTweens(tween1, tween2) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -244,3 +240,3 @@ chainedTweens(): this; | ||
* @example tween.repeat(5) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -252,3 +248,3 @@ repeat(amount: number): this; | ||
* @example tween.reverseDelay(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -261,3 +257,3 @@ reverseDelay(amount: number): this; | ||
* @example tween.yoyo(true) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -269,3 +265,3 @@ yoyo(state: boolean, _easingReverse?: Function): this; | ||
* @example tween.easing(Easing.Elastic.InOut) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -277,3 +273,3 @@ easing(_easingFunction: Function): this; | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -284,3 +280,3 @@ interpolation(_interpolationFunction: Function): this; | ||
* @private | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -294,3 +290,3 @@ reassignValues(time?: number): this; | ||
* @example tween.update(100) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -297,0 +293,0 @@ update(time?: number, preserve?: boolean, forceTime?: boolean): boolean; |
150
src/Tween.js
@@ -6,3 +6,3 @@ import { add, now, Plugins, remove } from './core'; | ||
import Selector from './selector'; | ||
import { decompose, 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'; | ||
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 | ||
@@ -14,4 +14,3 @@ var defaultEasing = Easing.Linear.None; | ||
* @class | ||
* @namespace Tween | ||
* @extends Tween | ||
* @namespace TWEEN.Tween | ||
* @param {Object|Element} node Node Element or Tween initial object | ||
@@ -62,3 +61,3 @@ * @param {Object=} object If Node Element is using, second argument is used for Tween initial object | ||
* @example Tween.fromTo(node, {x:0}, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -83,3 +82,3 @@ */ | ||
* @example Tween.to(node, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -96,3 +95,3 @@ */ | ||
* @example Tween.from(node, {x:200}, {duration:1000}) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @static | ||
@@ -106,3 +105,3 @@ */ | ||
* @param {number} count - Event listener's count | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -118,3 +117,3 @@ Tween.prototype.setMaxListener = function (count) { | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -138,3 +137,3 @@ Tween.prototype.on = function (event, callback) { | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -171,3 +170,3 @@ Tween.prototype.once = function (event, callback) { | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -188,3 +187,3 @@ Tween.prototype.off = function (event, callback) { | ||
* @param {string} event - Event listener name | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -208,3 +207,3 @@ Tween.prototype.emit = function (event, arg1, arg2, arg3, arg4) { | ||
* @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -217,3 +216,3 @@ Tween.prototype.isPlaying = function () { | ||
* @example tween.isStarted() // returns `true` if tween in started | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -227,3 +226,3 @@ Tween.prototype.isStarted = function () { | ||
* @param {boolean=} state Set state of current reverse | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -238,3 +237,3 @@ Tween.prototype.reverse = function (state) { | ||
* @example tween.reversed() // returns `true` if tween in reversed state | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -247,3 +246,3 @@ Tween.prototype.reversed = function () { | ||
* @example tween.pause() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -262,3 +261,3 @@ Tween.prototype.pause = function () { | ||
* @example tween.play() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -280,3 +279,3 @@ Tween.prototype.play = function () { | ||
* @example tween.restart() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -294,3 +293,3 @@ Tween.prototype.restart = function (noDelay) { | ||
* @example tween.seek(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
* @deprecated Not works as excepted, so we deprecated this method | ||
@@ -314,3 +313,3 @@ */ | ||
* @example tween.duration(2000) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -327,3 +326,3 @@ Tween.prototype.duration = function (amount) { | ||
* @example let tween = new Tween({x:0}).to({x:100}, 2000) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -350,3 +349,3 @@ Tween.prototype.to = function (properties, duration, maybeUsed) { | ||
* @private | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -357,3 +356,5 @@ Tween.prototype.render = function () { | ||
} | ||
var _a = this, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, Renderer = _a.Renderer, node = _a.node, InitialValues = _a.InitialValues, _easingFunction = _a._easingFunction; | ||
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]) { | ||
@@ -365,3 +366,3 @@ var prevTweenByNode = Store[node.queueID]; | ||
if (prevTweenByNode.tween._valuesEnd[property] !== undefined) { | ||
delete prevTweenByNode.tween._valuesEnd[property]; | ||
//delete prevTweenByNode.tween._valuesEnd[property]; | ||
} | ||
@@ -373,9 +374,7 @@ } | ||
} | ||
SET_NESTED(object); | ||
SET_NESTED(_valuesEnd); | ||
if (node && InitialValues) { | ||
if (!object) { | ||
if (!object || Object.keys(object).length === 0) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd), this); | ||
} | ||
else if (!_valuesEnd) { | ||
else if (!_valuesEnd || Object.keys(_valuesEnd).length === 0) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
@@ -385,12 +384,12 @@ } | ||
for (var property in _valuesEnd) { | ||
var start = object && object[property]; | ||
var start = object && object[property] && deepCopy(object[property]); | ||
var end = _valuesEnd[property]; | ||
if (Plugins[property]) { | ||
var plugin = Plugins[property].prototype.update | ||
? new Plugins[property](this, start, end, property, object) | ||
: Plugins[property](this, start, end, property, object); | ||
if (plugin) { | ||
_valuesEnd[property] = plugin; | ||
if (Plugins[property] && Plugins[property].init) { | ||
Plugins[property].init.call(this, start, end, property, object); | ||
if (start === undefined && _valuesStart[property]) { | ||
start = _valuesStart[property]; | ||
} | ||
continue; | ||
if (Plugins[property].skipProcess) { | ||
continue; | ||
} | ||
} | ||
@@ -400,2 +399,4 @@ if ((typeof start === 'number' && isNaN(start)) || | ||
end === null || | ||
start === false || | ||
end === false || | ||
start === undefined || | ||
@@ -408,8 +409,22 @@ end === undefined || | ||
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] = deepCopy(start); | ||
_valuesStart[property] = start; | ||
if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { | ||
continue; | ||
} | ||
decompose(property, object, _valuesStart, _valuesEnd); | ||
} | ||
if (Renderer && this.node) { | ||
this.__render = new Renderer(this, object, _valuesEnd); | ||
if (Tween.Renderer && this.node && Tween.Renderer.init) { | ||
Tween.Renderer.init.call(this, object, _valuesStart, _valuesEnd); | ||
this.__render = true; | ||
} | ||
@@ -422,3 +437,3 @@ return this; | ||
* @example tween.start() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -441,3 +456,3 @@ Tween.prototype.start = function (time) { | ||
* @example tween.stop() | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -464,3 +479,3 @@ Tween.prototype.stop = function () { | ||
* @example tween.delay(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -476,3 +491,3 @@ Tween.prototype.delay = function (amount) { | ||
* @example tween.chainedTweens(tween1, tween2) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -493,3 +508,3 @@ Tween.prototype.chainedTweens = function () { | ||
* @example tween.repeat(5) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -508,3 +523,3 @@ Tween.prototype.repeat = function (amount) { | ||
* @example tween.reverseDelay(500) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -521,3 +536,3 @@ Tween.prototype.reverseDelay = function (amount) { | ||
* @example tween.yoyo(true) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -539,3 +554,3 @@ Tween.prototype.yoyo = function (state, _easingReverse) { | ||
* @example tween.easing(Easing.Elastic.InOut) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -550,3 +565,3 @@ Tween.prototype.easing = function (_easingFunction) { | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -562,3 +577,3 @@ Tween.prototype.interpolation = function (_interpolationFunction) { | ||
* @private | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -584,3 +599,3 @@ Tween.prototype.reassignValues = function (time) { | ||
* @example tween.update(100) | ||
* @memberof Tween | ||
* @memberof TWEEN.Tween | ||
*/ | ||
@@ -595,2 +610,3 @@ Tween.prototype.update = function (time, preserve, forceTime) { | ||
elapsed = 1; | ||
_repeat = 0; | ||
} | ||
@@ -600,6 +616,6 @@ else { | ||
var delta = time - _prevTime; | ||
this._prevTime = time; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
time += delta - FRAME_MS; | ||
time -= delta - FRAME_MS; | ||
} | ||
this._prevTime = time; | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
@@ -628,3 +644,4 @@ return true; | ||
var start = _valuesStart[property]; | ||
if (start === undefined || start === null) { | ||
if ((start === undefined || start === null) && | ||
!(Plugins[property] && Plugins[property].update)) { | ||
continue; | ||
@@ -638,2 +655,7 @@ } | ||
: defaultEasing(elapsed); | ||
var _interpolationFunctionCall = _interpolationFunction[property] | ||
? _interpolationFunction[property] | ||
: typeof _interpolationFunction === 'function' | ||
? _interpolationFunction | ||
: Interpolation.Linear; | ||
if (typeof end === 'number') { | ||
@@ -644,3 +666,3 @@ object[property] = | ||
else if (Array.isArray(end) && !Array.isArray(start)) { | ||
object[property] = _interpolationFunction(end, value, object[property]); | ||
object[property] = _interpolationFunctionCall(end, value, object[property]); | ||
} | ||
@@ -653,5 +675,11 @@ else if (end && end.update) { | ||
} | ||
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); | ||
} | ||
propCount++; | ||
@@ -663,7 +691,7 @@ } | ||
} | ||
if (__render) { | ||
__render.update(object, elapsed); | ||
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)) { | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat > 0 && _duration > 0) { | ||
@@ -676,2 +704,10 @@ if (_isFinite) { | ||
} | ||
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); | ||
@@ -678,0 +714,0 @@ if (_reversed && _reverseDelayTime) { |
@@ -57,3 +57,3 @@ import test from 'ava' | ||
let tween = new Tween(obj) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+1' }, 100) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+=1' }, 100) | ||
.start(0) | ||
@@ -118,3 +118,3 @@ | ||
tween.update(100) | ||
update(100) | ||
@@ -121,0 +121,0 @@ }) |
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
687875
41
6207