es6-tween
Advanced tools
Comparing version 3.1.0 to 3.3.0
@@ -28,3 +28,3 @@ (function (global, factory) { | ||
if (_autoPlay && !isStarted) { | ||
update(); | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
@@ -50,6 +50,7 @@ } | ||
for (var id in _tweens) { | ||
_tweens[+id] = null; | ||
delete _tweens[+id]; | ||
_tweens[id] = null; | ||
delete _tweens[id]; | ||
} | ||
_tweens.length = 0; | ||
_stopTicker(_tick); | ||
}; | ||
@@ -60,3 +61,3 @@ | ||
if (tween.id === +searchTween) { | ||
return _tweens[+searchTween] | ||
return _tweens[searchTween] | ||
} | ||
@@ -75,6 +76,9 @@ } | ||
if (tween.id === +searchTween) { | ||
delete _tweens[+searchTween]; | ||
delete _tweens[searchTween]; | ||
_tweens.length--; | ||
} | ||
} | ||
if (_tweens.length === 0) { | ||
_stopTicker(_tick); | ||
} | ||
}; | ||
@@ -108,7 +112,7 @@ | ||
if (_autoPlay) { | ||
_tick = _ticker(update); | ||
} | ||
_tick = _ticker(update); | ||
if (_tweens.length === 0) { | ||
var i; | ||
var length = _tweens.length; | ||
if (!length) { | ||
isStarted = false; | ||
@@ -119,9 +123,4 @@ _stopTicker(_tick); | ||
for (var i in _tweens) { | ||
if (_tweens[i].update(time) || preserve) { | ||
i++; | ||
} else { | ||
delete _tweens[+i]; | ||
_tweens.length--; | ||
} | ||
for (i in _tweens) { | ||
_tweens[i].update(time, preserve); | ||
} | ||
@@ -132,2 +131,4 @@ | ||
var isRunning = function () { return isStarted; }; | ||
var Plugins = {}; | ||
@@ -141,8 +142,6 @@ | ||
doc.addEventListener('visibilitychange', function () { | ||
if (_tweens.length === 0) { | ||
return false | ||
} | ||
if (document.hidden) { | ||
timePause = now(); | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
} else { | ||
@@ -154,2 +153,4 @@ timeDiff = now() - timePause; | ||
} | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
@@ -477,3 +478,3 @@ | ||
Linear: function Linear (p0, p1, t) { | ||
return typeof p1 === 'function' ? p1(t) : (p1 - p0) * t + p0 | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0 | ||
}, | ||
@@ -632,4 +633,2 @@ | ||
} else if (!Array.isArray(start) && Array.isArray(end)) { | ||
end.unshift(start); | ||
end.push(end[end.length - 1]); | ||
return end.map(function (v, i) { return SubTween(i === 0 ? start : end[i - 1], v); }) | ||
@@ -646,3 +645,3 @@ } else { | ||
if (tween) { | ||
return tween | ||
return Object.assign(Store[node], tween) | ||
} | ||
@@ -660,7 +659,2 @@ return Store[node] | ||
EventClass.prototype.bind = function bind (scope) { | ||
this._bind = scope; | ||
return this | ||
}; | ||
EventClass.prototype.on = function on (event, callback) { | ||
@@ -676,2 +670,4 @@ if (!this._events[event]) { | ||
EventClass.prototype.once = function once (event, callback) { | ||
var this$1 = this; | ||
if (!this._events[event]) { | ||
@@ -683,3 +679,2 @@ this._events[event] = []; | ||
var _events = ref._events; | ||
var _bind = ref._bind; | ||
var spliceIndex = _events[event].length; | ||
@@ -690,3 +685,3 @@ this._events[event].push(function () { | ||
callback.apply(_bind, args); | ||
callback.apply(this$1, args); | ||
_events[event].splice(spliceIndex, 1); | ||
@@ -717,3 +712,2 @@ }); | ||
var _events = ref._events; | ||
var _bind = ref._bind; | ||
@@ -727,3 +721,3 @@ if (event === undefined || !_events[event]) { | ||
for (var i = 0, length = _event.length; i < length; i++) { | ||
_event[i].call(_bind, arg1, arg2, arg3, arg4); | ||
_event[i](arg1, arg2, arg3, arg4); | ||
} | ||
@@ -747,12 +741,14 @@ }; | ||
var Tween = (function (EventClass$$1) { | ||
function Tween (object, instate) { | ||
if ( object === void 0 ) object = {}; | ||
function Tween (node, object) { | ||
EventClass$$1.call(this); | ||
if (object.node) { | ||
this.node = object.node; | ||
delete object.node; | ||
this.id = nextId(); | ||
if (typeof node === 'object' && !object && !node.nodeType) { | ||
object = this.object = node; | ||
node = null; | ||
} else if (typeof node !== 'undefined') { | ||
this.node = node; | ||
object = this.object = NodeCache(node, object); | ||
this.object.node = node; | ||
} | ||
this.object = NodeCache(this.node, object); | ||
this._valuesStart = Tween.createEmptyConst(object); | ||
@@ -775,10 +771,5 @@ this._valuesEnd = Tween.createEmptyConst(object); | ||
this._pausedTime = null; | ||
this.id = nextId(); | ||
this._plugins = {}; | ||
this._isFinite = true; | ||
if (instate && instate.to) { | ||
return new Tween(object) | ||
.to(instate.to, instate) | ||
} | ||
return this | ||
@@ -791,5 +782,8 @@ } | ||
Tween.fromTo = function fromTo (from, instance) { | ||
return new Tween(from, instance) | ||
Tween.prototype.timeout = function timeout (fn, delay) { | ||
return new Tween({x: 0}).to({x: 1}, delay).on('complete', fn) | ||
}; | ||
Tween.prototype.interval = function interval (fn, delay) { | ||
return new Tween({x: 0}).to({x: 1}, delay).repeat(Infinity).on('repeat', fn) | ||
}; | ||
@@ -910,4 +904,6 @@ Tween.createEmptyConst = function createEmptyConst (oldObject) { | ||
var ref = this; | ||
var _valuesStart = ref._valuesStart; | ||
var _valuesEnd = ref._valuesEnd; | ||
var object = ref.object; | ||
var _plugins = ref._plugins; | ||
@@ -917,14 +913,14 @@ for (var property in _valuesEnd) { | ||
if (isPluginProp) { | ||
isPluginProp = this$1._plugins[property] = new Plugins[property](this$1, object[property], _valuesEnd[property]); | ||
isPluginProp = _plugins[property] = new Plugins[property](this$1, object[property], _valuesEnd[property]); | ||
isPluginProp.preprocess && isPluginProp.preprocess(object[property], _valuesEnd[property]); | ||
} | ||
if (typeof _valuesEnd[property] === 'object' && _valuesEnd[property]) { | ||
this$1._valuesEnd[property] = SubTween(object[property], _valuesEnd[property]); | ||
if (typeof this$1._valuesEnd[property] === 'function') { | ||
this$1.object[property] = this$1._valuesEnd[property](0); | ||
if (typeof _valuesEnd[property] === 'object' && _valuesEnd[property] && typeof object[property] === 'object') { | ||
_valuesEnd[property] = SubTween(object[property], _valuesEnd[property]); | ||
if (typeof _valuesEnd[property] === 'function') { | ||
object[property] = _valuesEnd[property](0); | ||
} | ||
} else if (typeof _valuesEnd[property] === 'string' && typeof object[property] === 'string') { | ||
this$1._valuesEnd[property] = SubTween(object[property], _valuesEnd[property]); | ||
if (typeof this$1._valuesEnd[property] === 'function') { | ||
this$1.object[property] = this$1._valuesEnd[property](0); | ||
_valuesEnd[property] = SubTween(object[property], _valuesEnd[property]); | ||
if (typeof _valuesEnd[property] === 'function') { | ||
object[property] = _valuesEnd[property](0); | ||
} | ||
@@ -939,6 +935,6 @@ } | ||
this$1._valuesStart[property] = object[property]; | ||
_valuesStart[property] = object[property]; | ||
if (isPluginProp) { | ||
isPluginProp.postprocess && isPluginProp.postprocess(this$1.object[property], this$1._valuesEnd[property]); | ||
isPluginProp.postprocess && isPluginProp.postprocess(object[property], _valuesEnd[property]); | ||
} | ||
@@ -999,2 +995,3 @@ } | ||
this._r = this._repeat; | ||
this._isFinite = isFinite(amount); | ||
@@ -1034,2 +1031,20 @@ return this | ||
Tween.prototype.reassignValues = function reassignValues () { | ||
var ref = this; | ||
var _valuesStart = ref._valuesStart; | ||
var _valuesEnd = ref._valuesEnd; | ||
var object = ref.object; | ||
for (var property in _valuesEnd) { | ||
var end = _valuesEnd[property]; | ||
var start = _valuesStart[property]; | ||
if (typeof end === 'number' || typeof end === 'string') { | ||
object[property] = start; | ||
} | ||
} | ||
return this | ||
}; | ||
Tween.prototype.get = function get$$1 (time) { | ||
@@ -1040,5 +1055,3 @@ this.update(time); | ||
Tween.prototype.update = function update$$1 (time) { | ||
var this$1 = this; | ||
Tween.prototype.update = function update$$1 (time, preserve) { | ||
var ref = this; | ||
@@ -1059,2 +1072,3 @@ var _onStartCallbackFired = ref._onStartCallbackFired; | ||
var object = ref.object; | ||
var _isFinite = ref._isFinite; | ||
@@ -1121,7 +1135,5 @@ var property; | ||
this.object = object; | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (isFinite(_repeat)) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
@@ -1132,3 +1144,3 @@ } | ||
if (typeof (_valuesEnd[property]) === 'string' && typeof (_valuesStart[property]) === 'number') { | ||
this$1._valuesStart[property] = _valuesStart[property] + parseFloat(_valuesEnd[property]); | ||
_valuesStart[property] = _valuesStart[property] + parseFloat(_valuesEnd[property]); | ||
} | ||
@@ -1141,3 +1153,3 @@ } | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
this.reverse(); | ||
} | ||
@@ -1155,2 +1167,5 @@ | ||
} else { | ||
if (!preserve) { | ||
remove(this); | ||
} | ||
this.emit(EVENT_COMPLETE, object); | ||
@@ -1169,2 +1184,64 @@ this._repeat = this._r; | ||
var PlaybackPosition = function PlaybackPosition () { | ||
this.totalTime = 0; | ||
this.labels = []; | ||
this.offsets = []; | ||
}; | ||
PlaybackPosition.prototype.parseLabel = function parseLabel (name, offset) { | ||
var ref = this; | ||
var offsets = ref.offsets; | ||
var labels = ref.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 addLabel (name, offset) { | ||
this.labels.push(name); | ||
this.offsets.push(this.parseLabel(name, offset)); | ||
return this | ||
}; | ||
PlaybackPosition.prototype.setLabel = function setLabel (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 eraseLabel (name) { | ||
var i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.labels.splice(i, 1); | ||
this.offsets.splice(i, 1); | ||
} | ||
return this | ||
}; | ||
var _id = 0; | ||
var Timeline = (function (Tween$$1) { | ||
@@ -1176,7 +1253,8 @@ function Timeline (params) { | ||
this._tweens = {}; | ||
this._timing = []; | ||
this._elapsed = 0; | ||
this._id = nextId(); | ||
this._labels = {}; | ||
this._id = _id++; | ||
this._defaultParams = params; | ||
this.position = new PlaybackPosition(); | ||
this.position.addLabel('afterLast', this._totalDuration); | ||
this.position.addLabel('afterInit', this._startTime); | ||
@@ -1190,34 +1268,7 @@ return this | ||
Timeline.prototype.setLabel = function setLabel (name, value) { | ||
this._labels[name] = this.parsePosition(0, value, 0); | ||
Timeline.prototype.addLabel = function addLabel (name, offset) { | ||
this.position.addLabel(name, offset); | ||
return this | ||
}; | ||
Timeline.prototype.parsePosition = function parsePosition (startTime, input, total) { | ||
var this$1 = this; | ||
var position = startTime + total; | ||
if (typeof input === 'string') { | ||
for (var label in this$1._labels) { | ||
if (input.indexOf(label) === 0) { | ||
var inp = input.split(label)[1]; | ||
if (inp.length === 0 || (inp[0] === '+' || inp[0] === '-')) { | ||
position = this$1._labels[label] + startTime; | ||
input = input.replace(label, ''); | ||
} | ||
} | ||
} | ||
if (input.indexOf('+') === 0 || input.indexOf('-') === 0) { | ||
position += parseFloat(input); | ||
} | ||
} else if (typeof input === 'number') { | ||
position += input; | ||
} | ||
return Math.max(0, position) | ||
}; | ||
Timeline.prototype.map = function map (fn) { | ||
@@ -1243,3 +1294,3 @@ var this$1 = this; | ||
} else if (typeof tween === 'object' && !(tween instanceof Tween$$1)) { | ||
tween = new Tween$$1(tween.from, tween); | ||
tween = new Tween$$1(tween.from).to(tween.to, tween); | ||
} | ||
@@ -1257,6 +1308,8 @@ | ||
tween._startTime = this.parsePosition(now() + tween._delayTime, position, _totalDuration); | ||
this._timing[tween.id] = tween._startTime; | ||
this._totalDuration = Math.max(_totalDuration, tween._duration + tween._startTime + tween._delayTime); | ||
var offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
tween._startTime = this._startTime; | ||
tween._startTime += offset; | ||
this._totalDuration = Math.max(_totalDuration, tween._startTime + tween._delayTime + tween._duration); | ||
this._tweens[tween.id] = tween; | ||
this.position.setLabel('afterLast', this._totalDuration); | ||
return this | ||
@@ -1270,3 +1323,3 @@ }; | ||
return this.emit('restart') | ||
return this.emit(EVENT_RS) | ||
}; | ||
@@ -1283,10 +1336,4 @@ | ||
Timeline.prototype.reverse = function reverse () { | ||
var this$1 = this; | ||
this._reversed = !this._reversed; | ||
this._timing = this._timing.reverse(); | ||
for (var tween in this$1._tweens) { | ||
this$1._tweens[tween]._startTime = this$1._timing[+tween]; | ||
} | ||
return this | ||
return this.emit(EVENT_REVERSE) | ||
}; | ||
@@ -1304,2 +1351,3 @@ | ||
var _repeat = ref._repeat; | ||
var _isFinite = ref._isFinite; | ||
@@ -1328,11 +1376,11 @@ if (time < _startTime) { | ||
this.emit('update', elapsed, timing); | ||
this.emit(EVENT_UPDATE, elapsed, timing); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (isFinite(_repeat)) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
this.emit(_reversed ? 'reverse' : 'repeat'); | ||
this.emit(_reversed ? EVENT_REVERSE : EVENT_REPEAT); | ||
@@ -1356,2 +1404,3 @@ if (_yoyo) { | ||
} | ||
_tween$1.reassignValues(); | ||
} | ||
@@ -1361,3 +1410,3 @@ | ||
} else { | ||
this.emit('complete'); | ||
this.emit(EVENT_COMPLETE); | ||
this._repeat = this._r; | ||
@@ -1402,2 +1451,3 @@ | ||
exports.autoPlay = autoPlay; | ||
exports.isRunning = isRunning; | ||
exports.Tween = Tween; | ||
@@ -1404,0 +1454,0 @@ exports.Easing = Easing; |
@@ -1,3 +0,3 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN=t.TWEEN||{})}(this,function(t){"use strict";function e(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}var n,r={},i=!1,o=!1,s="undefined"!=typeof window?window:"undefined"!=typeof global?global:{},a=0,u=function(t){return"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(t):setTimeout(t,16.6)},p=function(t){return"undefined"!=typeof cancelAnimationFrame?cancelAnimationFrame(t):clearTimeout(t)};!function(t,e,n){Object.defineProperty(t,e,n)}(r,"length",{enumerable:!1,writable:!0,value:0});var f=function(t){var e=t.id;r[e]=t,r.length++,o&&!i&&(y(),i=!0)},h=function(){var t=a;return a++,t},c=function(t){for(var e in r)if(t.id===+e)return r[+e];return null},l=function(t){for(var e in r)t.id===+e&&(delete r[+e],r.length--)},_=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}}(),y=function(t,e){if(t=void 0!==t?t:_(),o&&(n=u(y)),0===r.length)return i=!1,p(n),!1;for(var s in r)r[s].update(t)||e?s++:(delete r[+s],r.length--);return!0},d={};if(s.document){var v=0,m=0;s.document.addEventListener("visibilitychange",function(){if(0===r.length)return!1;if(document.hidden)m=_();else{v=_()-m;for(var t in r)r[t]._startTime+=v}return!0})}var g={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){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-g.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*g.Bounce.In(2*t):.5*g.Bounce.Out(2*t-1)+.5}}},b={Linear:function(t,e){var n=t.length-1,r=n*e,i=Math.floor(r),o=b.Utils.Linear;return e<0?o(t[0],t[1],r):e>1?o(t[n],t[n-1],n-r):o(t[i],t[i+1>n?n:i+1],r-i)},Bezier:function(t,e){for(var n=0,r=t.length-1,i=Math.pow,o=b.Utils.Bernstein,s=0;s<=r;s++)n+=i(1-e,r-s)*i(e,s)*t[s]*o(r,s);return n},CatmullRom:function(t,e){var n=t.length-1,r=n*e,i=Math.floor(r),o=b.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(i=Math.floor(r=n*(1+e))),o(t[(i-1+n)%n],t[i],t[(i+1)%n],t[(i+2)%n],r-i)):e<0?t[0]-(o(t[0],t[0],t[1],t[1],-r)-t[0]):e>1?t[n]-(o(t[n],t[n],t[n-1],t[n-1],r-n)-t[n]):o(t[i?i-1:0],t[i],t[n<i+1?n:i+1],t[n<i+2?n:i+2],r-i)},Utils:{Linear:function(t,e,n){return"function"==typeof e?e(n):(e-t)*n+t},Bernstein:function(t,e){var n=b.Utils.Factorial;return n(t)/n(e)/n(t-e)},Factorial:function(){var t=[1];return function(e){var n=1;if(t[e])return t[e];for(var r=e;r>1;r--)n*=r;return t[e]=n,n}}(),CatmullRom:function(t,e,n,r,i){var o=.5*(n-t),s=.5*(r-e),a=i*i;return(2*e-2*n+o+s)*(i*a)+(-3*e+3*n-2*o-s)*a+o*i+e}}},T=/rgb|hsl|hsv/g,M=/ahsv|ahsl|argb/g,I=/\s+|([A-Za-z?().,{}:""[\]#]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,w=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,O=/\n|\r|\t/g,j=function(t,e){var n,r,i;return 3===e.length?(n=parseInt(e[0]+e[0],16),r=parseInt(e[1]+e[1],16),i=parseInt(e[2]+e[2],16)):6===e.length&&(n=parseInt(e.substr(0,2),16),r=parseInt(e.substr(2,2),16),i=parseInt(e.substr(4,6),16)),"rgb("+n+","+r+","+i+")"},P=function(t){return"string"==typeof t?t.replace(O,""):t},A=function(t,n,r){if(void 0===r&&(r=1e4),"function"==typeof n||n&&n.nodeType)return n;if(t&&t.nodeType)return t;if(Array.isArray(t)){var i=null,o=null;n=n.map(function(e,n){return"string"==typeof e&&T.test(e)?(i=e,o=n,null):e===t[n]?null:"number"==typeof e?e-t[n]:"string"==typeof e&&I.test(e)?A(P(t[n]),P(e)):A(t[n],e)});var s=null!==o?o+6:null;i&&M.test(i)&&(o++,s++);var a=[].concat(t);return function(e){for(var i=0,u=void 0,p=n.length;i<p;i++)"function"==typeof(u=n[i])?a[i]=u(e):"number"==typeof u&&(a[i]=((t[i]+u*e)*r|0)/r,null!==o&&i>o&&i<s&&(a[i]=0|a[i]));return a}}if("object"==typeof t){for(var u in n)n[u]===t[u]?n[u]=null:"number"==typeof t[u]?n[u]-=t[u]:("object"==typeof n[u]||"string"==typeof n[u]&&I.test(n[u]))&&(n[u]=A(t[u],n[u]));var p=Object.assign({},t);return function(e){for(var i in n){var o=n[i];"function"==typeof o?p[i]=o(e):"number"==typeof o&&(p[i]=((t[i]+o*e)*r|0)/r)}return p}}if("number"==typeof t){var f=t===(n-=t);return function(e){return f?n:((t+n*e)*r|0)/r}}if("string"==typeof t&&"string"==typeof n&&I.test(t)&&I.test(n)||"string"==typeof n&&t&&(w.test(t)||w.test(n))){var h=P(t).replace(w,j).match(I).map(e),c=P(n).replace(w,j).match(I).map(e),l=A(h,c);return function(t){for(var e=l(t),n=0,r="";n<e.length;)r+=e[n],n++;return r}}return!Array.isArray(t)&&Array.isArray(n)?(n.unshift(t),n.push(n[n.length-1]),n.map(function(e,r){return A(0===r?t:n[r-1],e)})):n},E={},F=function(t,e){return t?E[t]?e||E[t]:(E[t]=e,E[t]):e},D=function(){this._events={}};D.prototype.bind=function(t){return this._bind=t,this},D.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},D.prototype.once=function(t,e){this._events[t]||(this._events[t]=[]);var n=this,r=n._events,i=n._bind,o=r[t].length;return this._events[t].push(function(){for(var n=[],s=arguments.length;s--;)n[s]=arguments[s];e.apply(i,n),r[t].splice(o,1)}),this},D.prototype.off=function(t,e){var n=this._events;return void 0!==t&&n[t]?(e?this._events[t]=this._events[t].filter(function(t){return t!==e}):this._events[t].length=0,this):this},D.prototype.emit=function(t,e,n,r,i){var o=this,s=o._events,a=o._bind;if(void 0===t||!s[t])return this;for(var u=s[t],p=0,f=u.length;p<f;p++)u[p].call(a,e,n,r,i)};var k=g.Linear.None,x=function(t){function e(n,r){return void 0===n&&(n={}),t.call(this),n.node&&(this.node=n.node,delete n.node),this.object=F(this.node,n),this._valuesStart=e.createEmptyConst(n),this._valuesEnd=e.createEmptyConst(n),this._duration=1e3,this._easingFunction=k,this._interpolationFunction=b.Linear,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._pausedTime=null,this.id=h(),this._plugins={},r&&r.to?new e(n).to(r.to,r):this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.fromTo=function(t,n){return new e(t,n)},e.createEmptyConst=function(t){return"number"==typeof t?0:Array.isArray(t)?[]:"object"==typeof t?{}:""},e.checkValidness=function(t){return void 0!==t&&null!==t&&""!==t&&("number"==typeof t&&!isNaN(t)||"number"!=typeof t)&&t!==1/0},e.prototype.isPlaying=function(){return this._isPlaying},e.prototype.isStarted=function(){return this._onStartCallbackFired},e.prototype.reverse=function(){var t=this._reversed;return this._reversed=!t,this},e.prototype.reversed=function(){return this._reversed},e.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,l(this),this._pausedTime=_(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=_()-this._pausedTime,f(this),this._pausedTime=_(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this._startTime=_()+(t?0:this._delayTime),this._isPlaying||f(this),this.emit("restart",this._object)},e.prototype.seek=function(t,e){return this._startTime=_()+Math.max(0,Math.min(t,this._duration)),this.emit("seek",t,this._object),e?this:this.pause()},e.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},e.prototype.to=function(t,e){var n=this;if(void 0===t&&(t={}),void 0===e&&(e=1e3),"object"==typeof t&&(this._valuesEnd=t),"number"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var r in e)n[r]&&(i=n)[r].apply(i,Array.isArray(e)?e:[e]);return this;var i},e.prototype.render=function(){var t=this;if(this._rendered)return this;var n=this,r=n._valuesEnd,i=n.object;for(var o in r){var s=d[o];s&&(s=t._plugins[o]=new d[o](t,i[o],r[o])).preprocess&&s.preprocess(i[o],r[o]),"object"==typeof r[o]&&r[o]?(t._valuesEnd[o]=A(i[o],r[o]),"function"==typeof t._valuesEnd[o]&&(t.object[o]=t._valuesEnd[o](0))):"string"==typeof r[o]&&"string"==typeof i[o]&&(t._valuesEnd[o]=A(i[o],r[o]),"function"==typeof t._valuesEnd[o]&&(t.object[o]=t._valuesEnd[o](0))),!1!==e.checkValidness(i[o])&&(t._valuesStart[o]=i[o],s&&s.postprocess&&s.postprocess(t.object[o],t._valuesEnd[o]))}return this},e.prototype.start=function(t){return this._startTime=void 0!==t?t:_(),this._startTime+=this._delayTime,this.render(),this._rendered=!0,f(this),this.emit("start",this.object),this._isPlaying=!0,this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object;return e?(l(this),this._isPlaying=!1,this.emit("stop",n)):this},e.prototype.end=function(){var t=this,e=t._startTime,n=t._duration;return this.update(e+n)},e.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this._startTime+=this._delayTime,this},e.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this},e.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},e.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},e.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},e.prototype.easing=function(t){return this._easingFunction=t,this},e.prototype.interpolation=function(t){return this._interpolationFunction=t,this},e.prototype.get=function(t){return this.update(t),this.object},e.prototype.update=function(t){var e,n,r,i=this,o=this,s=o._onStartCallbackFired,a=o._easingFunction,u=o._interpolationFunction,p=o._repeat,f=o._repeatDelayTime,h=o._reverseDelayTime,c=o._yoyo,l=o._reversed,y=o._startTime,d=o._duration,v=o._valuesStart,m=o._valuesEnd,g=o._plugins,b=o.object;if((t=void 0!==t?t:_())<y)return!0;s||(this._rendered||(this.render(),this.emit("start",b),this._rendered=!0),this._onStartCallbackFired=!0),n=(n=(t-y)/d)>1?1:n,n=l?1-n:n,r="function"==typeof a?a(n):k(n);for(e in m){var T=v[e],M=m[e],I=g[e];if(r=a[e]?a[e](n):r,I&&I.update)I.update(r,n,l);else{if(null===T||void 0===T)continue;"function"==typeof M?b[e]=M(r):Array.isArray(M)?b[e]=u(M,r):"number"==typeof M?b[e]=T+(M-T)*r:"string"==typeof M&&"number"==typeof(M="+"===M.charAt(0)||"-"===M.charAt(0)?T+parseFloat(M):parseFloat(M))&&(b[e]=T+(M-T)*r)}}if(this.emit("update",b,r,n),this.object=b,1===n||l&&0===n){if(p){isFinite(p)&&this._repeat--;for(e in m)"string"==typeof m[e]&&"number"==typeof v[e]&&(i._valuesStart[e]=v[e]+parseFloat(m[e]));return this.emit(l?"reverse":"repeat",b),c&&(this._reversed=!l),this._startTime+=!l&&f?d+f:l&&h?d+h:d,!0}return this.emit("complete",b),this._repeat=this._r,!1}return!0},e}(D),C=function(t){function e(e){return t.call(this),this._totalDuration=0,this._startTime=_(),this._tweens={},this._timing=[],this._elapsed=0,this._id=h(),this._labels={},this._defaultParams=e,this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setLabel=function(t,e){return this._labels[t]=this.parsePosition(0,e,0),this},e.prototype.parsePosition=function(t,e,n){var r=this,i=t+n;if("string"==typeof e){for(var o in r._labels)if(0===e.indexOf(o)){var s=e.split(o)[1];0!==s.length&&"+"!==s[0]&&"-"!==s[0]||(i=r._labels[o]+t,e=e.replace(o,""))}0!==e.indexOf("+")&&0!==e.indexOf("-")||(i+=parseFloat(e))}else"number"==typeof e&&(i+=e);return Math.max(0,i)},e.prototype.map=function(t){var e=this;for(var n in e._tweens){var r=e._tweens[n];t(r,+n),e._totalDuration=Math.max(e._totalDuration,r._duration+r._startTime)}return this},e.prototype.add=function(e,n){var r=this;if(Array.isArray(e))return e.map(function(t){r.add(t,n)}),this;"object"!=typeof e||e instanceof t||(e=new t(e.from,e));var i=this,o=i._defaultParams,s=i._totalDuration;if(o)for(var a in o)e[a](o[a]);return e._startTime=this.parsePosition(_()+e._delayTime,n,s),this._timing[e.id]=e._startTime,this._totalDuration=Math.max(s,e._duration+e._startTime+e._delayTime),this._tweens[e.id]=e,this},e.prototype.restart=function(){return this._startTime+=_(),f(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.reverse=function(){var t=this;this._reversed=!this._reversed,this._timing=this._timing.reverse();for(var e in t._tweens)t._tweens[e]._startTime=t._timing[+e];return this},e.prototype.update=function(t){var e=this,n=e._tweens,r=e._totalDuration,i=e._repeatDelayTime,o=e._reverseDelayTime,s=e._startTime,a=e._reversed,u=e._yoyo,p=e._repeat;if(t<s)return!0;var f=Math.min(1,Math.max(0,(t-s)/r));f=a?1-f:f,this._elapsed=f;var h=t-s,c=a?r-h:h;for(var l in n){var _=n[l];if(_.skip)_.skip=!1;else{if(_.update(c))continue;_.skip=!0}}if(this.emit("update",f,h),1===f||a&&0===f){if(p){isFinite(p)&&this._repeat--,this.emit(a?"reverse":"repeat"),u&&this.reverse(),this._startTime+=!a&&i?r+i:a&&o?r+o:r;for(var y in n){var d=n[y];d.skip&&(d.skip=!1)}return!0}this.emit("complete"),this._repeat=this._r;for(var v in n){var m=n[v];m.skip&&(m.skip=!1)}return!1}return!0},e.prototype.elapsed=function(t){return void 0!==t?this.update(t*this._totalDuration):this._elapsed},e.prototype.seek=function(t){return this.update(t<1.1?t*this._totalDuration:t)},e}(x);t.Plugins=d,t.Interpolator=A,t.nextId=h,t.has=function(t){return null!==c(t)},t.get=c,t.getAll=function(){return r},t.removeAll=function(){for(var t in r)r[+t]=null,delete r[+t];r.length=0},t.remove=l,t.add=f,t.now=_,t.update=y,t.autoPlay=function(t){o=t},t.Tween=x,t.Easing=g,t.Interpolation=b,t.Timeline=C,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=t.TWEEN||{})}(this,function(t){"use strict";function e(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}var n,r={},i=!1,o=!1,s="undefined"!=typeof window?window:"undefined"!=typeof global?global:{},a=0,u=function(t){return"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(t):setTimeout(t,16.6)},p=function(t){return"undefined"!=typeof cancelAnimationFrame?cancelAnimationFrame(t):clearTimeout(t)};!function(t,e,n){Object.defineProperty(t,e,n)}(r,"length",{enumerable:!1,writable:!0,value:0});var f=function(t){var e=t.id;r[e]=t,r.length++,o&&!i&&(n=u(d),i=!0)},h=function(){var t=a;return a++,t},c=function(t){for(var e in r)if(t.id===+e)return r[e];return null},l=function(t){for(var e in r)t.id===+e&&(delete r[e],r.length--);0===r.length&&p(n)},y=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}}(),d=function(t,e){t=void 0!==t?t:y(),n=u(d);var o;if(!r.length)return i=!1,p(n),!1;for(o in r)r[o].update(t,e);return!0},_={};if(s.document){var v=0,m=0;s.document.addEventListener("visibilitychange",function(){if(document.hidden)m=y(),p(n),i=!1;else{v=y()-m;for(var t in r)r[t]._startTime+=v;n=u(d),i=!0}return!0})}var b={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-b.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*b.Bounce.In(2*t):.5*b.Bounce.Out(2*t-1)+.5}}},g={Linear:function(t,e){var n=t.length-1,r=n*e,i=Math.floor(r),o=g.Utils.Linear;return e<0?o(t[0],t[1],r):e>1?o(t[n],t[n-1],n-r):o(t[i],t[i+1>n?n:i+1],r-i)},Bezier:function(t,e){for(var n=0,r=t.length-1,i=Math.pow,o=g.Utils.Bernstein,s=0;s<=r;s++)n+=i(1-e,r-s)*i(e,s)*t[s]*o(r,s);return n},CatmullRom:function(t,e){var n=t.length-1,r=n*e,i=Math.floor(r),o=g.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(i=Math.floor(r=n*(1+e))),o(t[(i-1+n)%n],t[i],t[(i+1)%n],t[(i+2)%n],r-i)):e<0?t[0]-(o(t[0],t[0],t[1],t[1],-r)-t[0]):e>1?t[n]-(o(t[n],t[n],t[n-1],t[n-1],r-n)-t[n]):o(t[i?i-1:0],t[i],t[n<i+1?n:i+1],t[n<i+2?n:i+2],r-i)},Utils:{Linear:function(t,e,n){return"function"==typeof t?t(n):(e-t)*n+t},Bernstein:function(t,e){var n=g.Utils.Factorial;return n(t)/n(e)/n(t-e)},Factorial:function(){var t=[1];return function(e){var n=1;if(t[e])return t[e];for(var r=e;r>1;r--)n*=r;return t[e]=n,n}}(),CatmullRom:function(t,e,n,r,i){var o=.5*(n-t),s=.5*(r-e),a=i*i;return(2*e-2*n+o+s)*(i*a)+(-3*e+3*n-2*o-s)*a+o*i+e}}},T=/rgb|hsl|hsv/g,I=/ahsv|ahsl|argb/g,M=/\s+|([A-Za-z?().,{}:""[\]#]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,O=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,w=/\n|\r|\t/g,j=function(t,e){var n,r,i;return 3===e.length?(n=parseInt(e[0]+e[0],16),r=parseInt(e[1]+e[1],16),i=parseInt(e[2]+e[2],16)):6===e.length&&(n=parseInt(e.substr(0,2),16),r=parseInt(e.substr(2,2),16),i=parseInt(e.substr(4,6),16)),"rgb("+n+","+r+","+i+")"},F=function(t){return"string"==typeof t?t.replace(w,""):t},A=function(t,n,r){if(void 0===r&&(r=1e4),"function"==typeof n||n&&n.nodeType)return n;if(t&&t.nodeType)return t;if(Array.isArray(t)){var i=null,o=null;n=n.map(function(e,n){return"string"==typeof e&&T.test(e)?(i=e,o=n,null):e===t[n]?null:"number"==typeof e?e-t[n]:"string"==typeof e&&M.test(e)?A(F(t[n]),F(e)):A(t[n],e)});var s=null!==o?o+6:null;i&&I.test(i)&&(o++,s++);var a=[].concat(t);return function(e){for(var i=0,u=void 0,p=n.length;i<p;i++)"function"==typeof(u=n[i])?a[i]=u(e):"number"==typeof u&&(a[i]=((t[i]+u*e)*r|0)/r,null!==o&&i>o&&i<s&&(a[i]=0|a[i]));return a}}if("object"==typeof t){for(var u in n)n[u]===t[u]?n[u]=null:"number"==typeof t[u]?n[u]-=t[u]:("object"==typeof n[u]||"string"==typeof n[u]&&M.test(n[u]))&&(n[u]=A(t[u],n[u]));var p=Object.assign({},t);return function(e){for(var i in n){var o=n[i];"function"==typeof o?p[i]=o(e):"number"==typeof o&&(p[i]=((t[i]+o*e)*r|0)/r)}return p}}if("number"==typeof t){var f=t===(n-=t);return function(e){return f?n:((t+n*e)*r|0)/r}}if("string"==typeof t&&"string"==typeof n&&M.test(t)&&M.test(n)||"string"==typeof n&&t&&(O.test(t)||O.test(n))){var h=F(t).replace(O,j).match(M).map(e),c=F(n).replace(O,j).match(M).map(e),l=A(h,c);return function(t){for(var e=l(t),n=0,r="";n<e.length;)r+=e[n],n++;return r}}return!Array.isArray(t)&&Array.isArray(n)?n.map(function(e,r){return A(0===r?t:n[r-1],e)}):n},P={},D=function(t,e){return t?P[t]?e?Object.assign(P[t],e):P[t]:(P[t]=e,P[t]):e},L=function(){this._events={}};L.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},L.prototype.once=function(t,e){var n=this;this._events[t]||(this._events[t]=[]);var r=this._events,i=r[t].length;return this._events[t].push(function(){for(var o=[],s=arguments.length;s--;)o[s]=arguments[s];e.apply(n,o),r[t].splice(i,1)}),this},L.prototype.off=function(t,e){var n=this._events;return void 0!==t&&n[t]?(e?this._events[t]=this._events[t].filter(function(t){return t!==e}):this._events[t].length=0,this):this},L.prototype.emit=function(t,e,n,r,i){var o=this._events;if(void 0===t||!o[t])return this;for(var s=o[t],a=0,u=s.length;a<u;a++)s[a](e,n,r,i)};var x=b.Linear.None,k=function(t){function e(n,r){return t.call(this),this.id=h(),"object"!=typeof n||r||n.nodeType?void 0!==n&&(this.node=n,r=this.object=D(n,r),this.object.node=n):(r=this.object=n,n=null),this._valuesStart=e.createEmptyConst(r),this._valuesEnd=e.createEmptyConst(r),this._duration=1e3,this._easingFunction=x,this._interpolationFunction=g.Linear,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._pausedTime=null,this._plugins={},this._isFinite=!0,this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.timeout=function(t,n){return new e({x:0}).to({x:1},n).on("complete",t)},e.prototype.interval=function(t,n){return new e({x:0}).to({x:1},n).repeat(1/0).on("repeat",t)},e.createEmptyConst=function(t){return"number"==typeof t?0:Array.isArray(t)?[]:"object"==typeof t?{}:""},e.checkValidness=function(t){return void 0!==t&&null!==t&&""!==t&&("number"==typeof t&&!isNaN(t)||"number"!=typeof t)&&t!==1/0},e.prototype.isPlaying=function(){return this._isPlaying},e.prototype.isStarted=function(){return this._onStartCallbackFired},e.prototype.reverse=function(){var t=this._reversed;return this._reversed=!t,this},e.prototype.reversed=function(){return this._reversed},e.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,l(this),this._pausedTime=y(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=y()-this._pausedTime,f(this),this._pausedTime=y(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this._startTime=y()+(t?0:this._delayTime),this._isPlaying||f(this),this.emit("restart",this._object)},e.prototype.seek=function(t,e){return this._startTime=y()+Math.max(0,Math.min(t,this._duration)),this.emit("seek",t,this._object),e?this:this.pause()},e.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},e.prototype.to=function(t,e){var n=this;if(void 0===t&&(t={}),void 0===e&&(e=1e3),"object"==typeof t&&(this._valuesEnd=t),"number"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var r in e)n[r]&&(i=n)[r].apply(i,Array.isArray(e)?e:[e]);return this;var i},e.prototype.render=function(){var t=this;if(this._rendered)return this;var n=this,r=n._valuesStart,i=n._valuesEnd,o=n.object,s=n._plugins;for(var a in i){var u=_[a];u&&(u=s[a]=new _[a](t,o[a],i[a])).preprocess&&u.preprocess(o[a],i[a]),"object"==typeof i[a]&&i[a]&&"object"==typeof o[a]?(i[a]=A(o[a],i[a]),"function"==typeof i[a]&&(o[a]=i[a](0))):"string"==typeof i[a]&&"string"==typeof o[a]&&(i[a]=A(o[a],i[a]),"function"==typeof i[a]&&(o[a]=i[a](0))),!1!==e.checkValidness(o[a])&&(r[a]=o[a],u&&u.postprocess&&u.postprocess(o[a],i[a]))}return this},e.prototype.start=function(t){return this._startTime=void 0!==t?t:y(),this._startTime+=this._delayTime,this.render(),this._rendered=!0,f(this),this.emit("start",this.object),this._isPlaying=!0,this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object;return e?(l(this),this._isPlaying=!1,this.emit("stop",n)):this},e.prototype.end=function(){var t=this,e=t._startTime,n=t._duration;return this.update(e+n)},e.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this._startTime+=this._delayTime,this},e.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},e.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},e.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},e.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},e.prototype.easing=function(t){return this._easingFunction=t,this},e.prototype.interpolation=function(t){return this._interpolationFunction=t,this},e.prototype.reassignValues=function(){var t=this,e=t._valuesStart,n=t._valuesEnd,r=t.object;for(var i in n){var o=n[i],s=e[i];"number"!=typeof o&&"string"!=typeof o||(r[i]=s)}return this},e.prototype.get=function(t){return this.update(t),this.object},e.prototype.update=function(t,e){var n,r,i,o=this,s=o._onStartCallbackFired,a=o._easingFunction,u=o._interpolationFunction,p=o._repeat,f=o._repeatDelayTime,h=o._reverseDelayTime,c=o._yoyo,d=o._reversed,_=o._startTime,v=o._duration,m=o._valuesStart,b=o._valuesEnd,g=o._plugins,T=o.object,I=o._isFinite;if((t=void 0!==t?t:y())<_)return!0;s||(this._rendered||(this.render(),this.emit("start",T),this._rendered=!0),this._onStartCallbackFired=!0),r=(r=(t-_)/v)>1?1:r,r=d?1-r:r,i="function"==typeof a?a(r):x(r);for(n in b){var M=m[n],O=b[n],w=g[n];if(i=a[n]?a[n](r):i,w&&w.update)w.update(i,r,d);else{if(null===M||void 0===M)continue;"function"==typeof O?T[n]=O(i):Array.isArray(O)?T[n]=u(O,i):"number"==typeof O?T[n]=M+(O-M)*i:"string"==typeof O&&"number"==typeof(O="+"===O.charAt(0)||"-"===O.charAt(0)?M+parseFloat(O):parseFloat(O))&&(T[n]=M+(O-M)*i)}}if(this.emit("update",T,i,r),1===r||d&&0===r){if(p){I&&this._repeat--;for(n in b)"string"==typeof b[n]&&"number"==typeof m[n]&&(m[n]=m[n]+parseFloat(b[n]));return this.emit(d?"reverse":"repeat",T),c&&this.reverse(),this._startTime+=!d&&f?v+f:d&&h?v+h:v,!0}return e||l(this),this.emit("complete",T),this._repeat=this._r,!1}return!0},e}(L),E=function(){this.totalTime=0,this.labels=[],this.offsets=[]};E.prototype.parseLabel=function(t,e){var n=this,r=n.offsets,i=n.labels,o=i.indexOf(t);if("string"==typeof t&&-1!==t.indexOf("=")&&!e&&-1===o){var s=t.substr(t.indexOf("=")-1,2),a=t.split(s);e=2===a.length?s+a[1]:null,t=a[0],o=i.indexOf(t)}if(-1!==o&&t){var u=r[o]||0;if("number"==typeof e)u=e;else if("string"==typeof e&&-1!==e.indexOf("=")){var p=e.charAt(0);e=Number(e.substr(2)),"+"===p||"-"===p?u+=parseFloat(p+e):"*"===p?u*=e:"/"===p?u/=e:"%"===p&&(u*=e/100)}return u}return"number"==typeof e?e:0},E.prototype.addLabel=function(t,e){return this.labels.push(t),this.offsets.push(this.parseLabel(t,e)),this},E.prototype.setLabel=function(t,e){var n=this.labels.indexOf(t);return-1!==n&&this.offsets.splice(n,1,this.parseLabel(t,e)),this},E.prototype.eraseLabel=function(t){var e=this.labels.indexOf(t);return-1!==e&&(this.labels.splice(e,1),this.offsets.splice(e,1)),this};var C=0,S=function(t){function e(e){return t.call(this),this._totalDuration=0,this._startTime=y(),this._tweens={},this._elapsed=0,this._id=C++,this._defaultParams=e,this.position=new E,this.position.addLabel("afterLast",this._totalDuration),this.position.addLabel("afterInit",this._startTime),this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.addLabel=function(t,e){return this.position.addLabel(t,e),this},e.prototype.map=function(t){var e=this;for(var n in e._tweens){var r=e._tweens[n];t(r,+n),e._totalDuration=Math.max(e._totalDuration,r._duration+r._startTime)}return this},e.prototype.add=function(e,n){var r=this;if(Array.isArray(e))return e.map(function(t){r.add(t,n)}),this;"object"!=typeof e||e instanceof t||(e=new t(e.from).to(e.to,e));var i=this,o=i._defaultParams,s=i._totalDuration;if(o)for(var a in o)e[a](o[a]);var u="number"==typeof n?n:this.position.parseLabel(void 0!==n?n:"afterLast",null);return e._startTime=this._startTime,e._startTime+=u,this._totalDuration=Math.max(s,e._startTime+e._delayTime+e._duration),this._tweens[e.id]=e,this.position.setLabel("afterLast",this._totalDuration),this},e.prototype.restart=function(){return this._startTime+=y(),f(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.reverse=function(){return this._reversed=!this._reversed,this.emit("reverse")},e.prototype.update=function(t){var e=this,n=e._tweens,r=e._totalDuration,i=e._repeatDelayTime,o=e._reverseDelayTime,s=e._startTime,a=e._reversed,u=e._yoyo,p=e._repeat,f=e._isFinite;if(t<s)return!0;var h=Math.min(1,Math.max(0,(t-s)/r));h=a?1-h:h,this._elapsed=h;var c=t-s,l=a?r-c:c;for(var y in n){var d=n[y];if(d.skip)d.skip=!1;else{if(d.update(l))continue;d.skip=!0}}if(this.emit("update",h,c),1===h||a&&0===h){if(p){f&&this._repeat--,this.emit(a?"reverse":"repeat"),u&&this.reverse(),this._startTime+=!a&&i?r+i:a&&o?r+o:r;for(var _ in n){var v=n[_];v.skip&&(v.skip=!1),v.reassignValues()}return!0}this.emit("complete"),this._repeat=this._r;for(var m in n){var b=n[m];b.skip&&(b.skip=!1)}return!1}return!0},e.prototype.elapsed=function(t){return void 0!==t?this.update(t*this._totalDuration):this._elapsed},e.prototype.seek=function(t){return this.update(t<1.1?t*this._totalDuration:t)},e}(k);t.Plugins=_,t.Interpolator=A,t.nextId=h,t.has=function(t){return null!==c(t)},t.get=c,t.getAll=function(){return r},t.removeAll=function(){for(var t in r)r[t]=null,delete r[t];r.length=0,p(n)},t.remove=l,t.add=f,t.now=y,t.update=d,t.autoPlay=function(t){o=t},t.isRunning=function(){return i},t.Tween=k,t.Easing=b,t.Interpolation=g,t.Timeline=S,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=dist/Tween.min.js.map | ||
//# sourceMappingURL=Tween.min.js.map |
{ | ||
"name": "es6-tween", | ||
"version": "3.1.0", | ||
"version": "3.3.0", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -5,0 +5,0 @@ "browser": "dist/Tween.min.js", |
@@ -39,2 +39,3 @@ # es6-tween | ||
* Demo #2 [Morphing SVG Shape](https://codepen.io/dalisoft/pen/BdLydv) | ||
* Demo #3 [Timeline](https://codepen.io/dalisoft/pen/mMRWdr) | ||
@@ -41,0 +42,0 @@ ## Installation |
@@ -22,3 +22,3 @@ /* global global, window, Object, document, process, requestAnimationFrame, cancelAnimationFrame, setTimeout, clearTimeout */ | ||
if (_autoPlay && !isStarted) { | ||
update() | ||
_tick = _ticker(update) | ||
isStarted = true | ||
@@ -44,6 +44,7 @@ } | ||
for (let id in _tweens) { | ||
_tweens[+id] = null | ||
delete _tweens[+id] | ||
_tweens[id] = null | ||
delete _tweens[id] | ||
} | ||
_tweens.length = 0 | ||
_stopTicker(_tick) | ||
} | ||
@@ -54,3 +55,3 @@ | ||
if (tween.id === +searchTween) { | ||
return _tweens[+searchTween] | ||
return _tweens[searchTween] | ||
} | ||
@@ -69,6 +70,9 @@ } | ||
if (tween.id === +searchTween) { | ||
delete _tweens[+searchTween] | ||
delete _tweens[searchTween] | ||
_tweens.length-- | ||
} | ||
} | ||
if (_tweens.length === 0) { | ||
_stopTicker(_tick) | ||
} | ||
} | ||
@@ -102,7 +106,7 @@ | ||
if (_autoPlay) { | ||
_tick = _ticker(update) | ||
} | ||
_tick = _ticker(update) | ||
if (_tweens.length === 0) { | ||
let i | ||
let length = _tweens.length | ||
if (!length) { | ||
isStarted = false | ||
@@ -113,9 +117,4 @@ _stopTicker(_tick) | ||
for (let i in _tweens) { | ||
if (_tweens[i].update(time) || preserve) { | ||
i++ | ||
} else { | ||
delete _tweens[+i] | ||
_tweens.length-- | ||
} | ||
for (i in _tweens) { | ||
_tweens[i].update(time, preserve) | ||
} | ||
@@ -126,2 +125,4 @@ | ||
const isRunning = () => isStarted | ||
const Plugins = {} | ||
@@ -135,8 +136,6 @@ | ||
doc.addEventListener('visibilitychange', () => { | ||
if (_tweens.length === 0) { | ||
return false | ||
} | ||
if (document.hidden) { | ||
timePause = now() | ||
_stopTicker(_tick) | ||
isStarted = false | ||
} else { | ||
@@ -148,2 +147,4 @@ timeDiff = now() - timePause | ||
} | ||
_tick = _ticker(update) | ||
isStarted = true | ||
} | ||
@@ -155,2 +156,2 @@ | ||
export { Plugins, get, has, nextId, getAll, removeAll, remove, add, now, update, autoPlay } | ||
export { Plugins, get, has, nextId, getAll, removeAll, remove, add, now, update, autoPlay, isRunning } |
@@ -6,7 +6,2 @@ export default class EventClass { | ||
bind (scope) { | ||
this._bind = scope | ||
return this | ||
} | ||
on (event, callback) { | ||
@@ -26,6 +21,6 @@ if (!this._events[event]) { | ||
let {_events, _bind} = this | ||
let {_events} = this | ||
let spliceIndex = _events[event].length | ||
this._events[event].push((...args) => { | ||
callback.apply(_bind, args) | ||
callback.apply(this, args) | ||
_events[event].splice(spliceIndex, 1) | ||
@@ -53,3 +48,3 @@ }) | ||
emit (event, arg1, arg2, arg3, arg4) { | ||
let {_events, _bind} = this | ||
let {_events} = this | ||
@@ -63,5 +58,5 @@ if (event === undefined || !_events[event]) { | ||
for (let i = 0, length = _event.length; i < length; i++) { | ||
_event[i].call(_bind, arg1, arg2, arg3, arg4) | ||
_event[i](arg1, arg2, arg3, arg4) | ||
} | ||
} | ||
} |
@@ -61,3 +61,3 @@ const Interpolation = { | ||
Linear (p0, p1, t) { | ||
return typeof p1 === 'function' ? p1(t) : (p1 - p0) * t + p0 | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0 | ||
}, | ||
@@ -64,0 +64,0 @@ |
@@ -6,3 +6,3 @@ let Store = {} | ||
if (tween) { | ||
return tween | ||
return Object.assign(Store[node], tween) | ||
} | ||
@@ -9,0 +9,0 @@ return Store[node] |
@@ -109,4 +109,2 @@ import toNumber from './toNumber' | ||
} else if (!Array.isArray(start) && Array.isArray(end)) { | ||
end.unshift(start) | ||
end.push(end[end.length - 1]) | ||
return end.map((v, i) => SubTween(i === 0 ? start : end[i - 1], v)) | ||
@@ -113,0 +111,0 @@ } else { |
@@ -1,4 +0,6 @@ | ||
import Tween from './Tween' | ||
import { add, now, nextId } from './core' | ||
import Tween, { EVENT_UPDATE, EVENT_RS, EVENT_REPEAT, EVENT_REVERSE, EVENT_COMPLETE } from './Tween' | ||
import { add, now } from './core' | ||
import PlaybackPosition from './PlaybackPosition' | ||
let _id = 0 | ||
class Timeline extends Tween { | ||
@@ -10,7 +12,8 @@ constructor (params) { | ||
this._tweens = {} | ||
this._timing = [] | ||
this._elapsed = 0 | ||
this._id = nextId() | ||
this._labels = {} | ||
this._id = _id++ | ||
this._defaultParams = params | ||
this.position = new PlaybackPosition() | ||
this.position.addLabel('afterLast', this._totalDuration) | ||
this.position.addLabel('afterInit', this._startTime) | ||
@@ -20,32 +23,7 @@ return this | ||
setLabel (name, value) { | ||
this._labels[name] = this.parsePosition(0, value, 0) | ||
addLabel (name, offset) { | ||
this.position.addLabel(name, offset) | ||
return this | ||
} | ||
parsePosition (startTime, input, total) { | ||
let position = startTime + total | ||
if (typeof input === 'string') { | ||
for (let label in this._labels) { | ||
if (input.indexOf(label) === 0) { | ||
let inp = input.split(label)[1] | ||
if (inp.length === 0 || (inp[0] === '+' || inp[0] === '-')) { | ||
position = this._labels[label] + startTime | ||
input = input.replace(label, '') | ||
} | ||
} | ||
} | ||
if (input.indexOf('+') === 0 || input.indexOf('-') === 0) { | ||
position += parseFloat(input) | ||
} | ||
} else if (typeof input === 'number') { | ||
position += input | ||
} | ||
return Math.max(0, position) | ||
} | ||
map (fn) { | ||
@@ -67,3 +45,3 @@ for (let tween in this._tweens) { | ||
} else if (typeof tween === 'object' && !(tween instanceof Tween)) { | ||
tween = new Tween(tween.from, tween) | ||
tween = new Tween(tween.from).to(tween.to, tween) | ||
} | ||
@@ -82,6 +60,8 @@ | ||
tween._startTime = this.parsePosition(now() + tween._delayTime, position, _totalDuration) | ||
this._timing[tween.id] = tween._startTime | ||
this._totalDuration = Math.max(_totalDuration, tween._duration + tween._startTime + tween._delayTime) | ||
const offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null) | ||
tween._startTime = this._startTime | ||
tween._startTime += offset | ||
this._totalDuration = Math.max(_totalDuration, tween._startTime + tween._delayTime + tween._duration) | ||
this._tweens[tween.id] = tween | ||
this.position.setLabel('afterLast', this._totalDuration) | ||
return this | ||
@@ -95,3 +75,3 @@ } | ||
return this.emit('restart') | ||
return this.emit(EVENT_RS) | ||
} | ||
@@ -109,7 +89,3 @@ | ||
this._reversed = !this._reversed | ||
this._timing = this._timing.reverse() | ||
for (let tween in this._tweens) { | ||
this._tweens[tween]._startTime = this._timing[+tween] | ||
} | ||
return this | ||
return this.emit(EVENT_REVERSE) | ||
} | ||
@@ -126,3 +102,4 @@ | ||
_yoyo, | ||
_repeat | ||
_repeat, | ||
_isFinite | ||
} = this | ||
@@ -152,11 +129,11 @@ | ||
this.emit('update', elapsed, timing) | ||
this.emit(EVENT_UPDATE, elapsed, timing) | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (isFinite(_repeat)) { | ||
if (_isFinite) { | ||
this._repeat-- | ||
} | ||
this.emit(_reversed ? 'reverse' : 'repeat') | ||
this.emit(_reversed ? EVENT_REVERSE : EVENT_REPEAT) | ||
@@ -180,2 +157,3 @@ if (_yoyo) { | ||
} | ||
_tween.reassignValues() | ||
} | ||
@@ -185,3 +163,3 @@ | ||
} else { | ||
this.emit('complete') | ||
this.emit(EVENT_COMPLETE) | ||
this._repeat = this._r | ||
@@ -188,0 +166,0 @@ |
@@ -18,25 +18,32 @@ import { | ||
// Events list | ||
const EVENT_UPDATE = 'update' | ||
const EVENT_COMPLETE = 'complete' | ||
const EVENT_START = 'start' | ||
const EVENT_REPEAT = 'repeat' | ||
const EVENT_REVERSE = 'reverse' | ||
const EVENT_PAUSE = 'pause' | ||
const EVENT_PLAY = 'play' | ||
const EVENT_RS = 'restart' | ||
const EVENT_STOP = 'stop' | ||
const EVENT_SEEK = 'seek' | ||
export const EVENT_UPDATE = 'update' | ||
export const EVENT_COMPLETE = 'complete' | ||
export const EVENT_START = 'start' | ||
export const EVENT_REPEAT = 'repeat' | ||
export const EVENT_REVERSE = 'reverse' | ||
export const EVENT_PAUSE = 'pause' | ||
export const EVENT_PLAY = 'play' | ||
export const EVENT_RS = 'restart' | ||
export const EVENT_STOP = 'stop' | ||
export const EVENT_SEEK = 'seek' | ||
class Tween extends EventClass { | ||
static fromTo (from, instance) { | ||
return new Tween(from, instance) | ||
timeout (fn, delay) { | ||
return new Tween({x: 0}).to({x: 1}, delay).on('complete', fn) | ||
} | ||
constructor (object = {}, instate) { | ||
interval (fn, delay) { | ||
return new Tween({x: 0}).to({x: 1}, delay).repeat(Infinity).on('repeat', fn) | ||
} | ||
constructor (node, object) { | ||
super() | ||
if (object.node) { | ||
this.node = object.node | ||
delete object.node | ||
this.id = nextId() | ||
if (typeof node === 'object' && !object && !node.nodeType) { | ||
object = this.object = node | ||
node = null | ||
} else if (typeof node !== 'undefined') { | ||
this.node = node | ||
object = this.object = NodeCache(node, object) | ||
this.object.node = node | ||
} | ||
this.object = NodeCache(this.node, object) | ||
this._valuesStart = Tween.createEmptyConst(object) | ||
@@ -59,10 +66,5 @@ this._valuesEnd = Tween.createEmptyConst(object) | ||
this._pausedTime = null | ||
this.id = nextId() | ||
this._plugins = {} | ||
this._isFinite = true | ||
if (instate && instate.to) { | ||
return new Tween(object) | ||
.to(instate.to, instate) | ||
} | ||
return this | ||
@@ -179,4 +181,6 @@ } | ||
let { | ||
_valuesStart, | ||
_valuesEnd, | ||
object | ||
object, | ||
_plugins | ||
} = this | ||
@@ -187,14 +191,14 @@ | ||
if (isPluginProp) { | ||
isPluginProp = this._plugins[property] = new Plugins[property](this, object[property], _valuesEnd[property]) | ||
isPluginProp = _plugins[property] = new Plugins[property](this, object[property], _valuesEnd[property]) | ||
isPluginProp.preprocess && isPluginProp.preprocess(object[property], _valuesEnd[property]) | ||
} | ||
if (typeof _valuesEnd[property] === 'object' && _valuesEnd[property]) { | ||
this._valuesEnd[property] = SubTween(object[property], _valuesEnd[property]) | ||
if (typeof this._valuesEnd[property] === 'function') { | ||
this.object[property] = this._valuesEnd[property](0) | ||
if (typeof _valuesEnd[property] === 'object' && _valuesEnd[property] && typeof object[property] === 'object') { | ||
_valuesEnd[property] = SubTween(object[property], _valuesEnd[property]) | ||
if (typeof _valuesEnd[property] === 'function') { | ||
object[property] = _valuesEnd[property](0) | ||
} | ||
} else if (typeof _valuesEnd[property] === 'string' && typeof object[property] === 'string') { | ||
this._valuesEnd[property] = SubTween(object[property], _valuesEnd[property]) | ||
if (typeof this._valuesEnd[property] === 'function') { | ||
this.object[property] = this._valuesEnd[property](0) | ||
_valuesEnd[property] = SubTween(object[property], _valuesEnd[property]) | ||
if (typeof _valuesEnd[property] === 'function') { | ||
object[property] = _valuesEnd[property](0) | ||
} | ||
@@ -209,6 +213,6 @@ } | ||
this._valuesStart[property] = object[property] | ||
_valuesStart[property] = object[property] | ||
if (isPluginProp) { | ||
isPluginProp.postprocess && isPluginProp.postprocess(this.object[property], this._valuesEnd[property]) | ||
isPluginProp.postprocess && isPluginProp.postprocess(object[property], _valuesEnd[property]) | ||
} | ||
@@ -271,2 +275,3 @@ } | ||
this._r = this._repeat | ||
this._isFinite = isFinite(amount) | ||
@@ -306,2 +311,21 @@ return this | ||
reassignValues () { | ||
const { | ||
_valuesStart, | ||
_valuesEnd, | ||
object | ||
} = this | ||
for (let property in _valuesEnd) { | ||
let end = _valuesEnd[property] | ||
let start = _valuesStart[property] | ||
if (typeof end === 'number' || typeof end === 'string') { | ||
object[property] = start | ||
} | ||
} | ||
return this | ||
} | ||
get (time) { | ||
@@ -312,3 +336,3 @@ this.update(time) | ||
update (time) { | ||
update (time, preserve) { | ||
let { | ||
@@ -328,3 +352,4 @@ _onStartCallbackFired, | ||
_plugins, | ||
object | ||
object, | ||
_isFinite | ||
} = this | ||
@@ -392,7 +417,5 @@ | ||
this.object = object | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (isFinite(_repeat)) { | ||
if (_isFinite) { | ||
this._repeat-- | ||
@@ -403,3 +426,3 @@ } | ||
if (typeof (_valuesEnd[property]) === 'string' && typeof (_valuesStart[property]) === 'number') { | ||
this._valuesStart[property] = _valuesStart[property] + parseFloat(_valuesEnd[property]) | ||
_valuesStart[property] = _valuesStart[property] + parseFloat(_valuesEnd[property]) | ||
} | ||
@@ -412,3 +435,3 @@ } | ||
if (_yoyo) { | ||
this._reversed = !_reversed | ||
this.reverse() | ||
} | ||
@@ -426,2 +449,5 @@ | ||
} else { | ||
if (!preserve) { | ||
remove(this) | ||
} | ||
this.emit(EVENT_COMPLETE, object) | ||
@@ -428,0 +454,0 @@ this._repeat = this._r |
@@ -1,2 +0,2 @@ | ||
import { nextId, has, get, getAll, removeAll, remove, add, now, update, autoPlay, Plugins } from './dist/core' | ||
import { nextId, has, get, getAll, removeAll, remove, add, now, update, autoPlay, Plugins, isRunning } from './dist/core' | ||
import Easing from './dist/Easing' | ||
@@ -7,2 +7,2 @@ import Tween from './dist/Tween' | ||
import SubTween from './dist/SubTween' | ||
export { Plugins, SubTween as Interpolator, nextId, has, get, getAll, removeAll, remove, add, now, update, autoPlay, Tween, Easing, Interpolation, Timeline } | ||
export { Plugins, SubTween as Interpolator, nextId, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Interpolation, Timeline } |
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
418826
28
2916
204