es6-tween
Advanced tools
Comparing version 2.2.6 to 2.2.7
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.Tween = global.Tween || {}))); | ||
(factory((global.TWEEN = global.TWEEN || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -76,3 +76,3 @@ | ||
var _tweens = []; | ||
var _tweens = {}; | ||
var isStarted = false; | ||
@@ -83,15 +83,10 @@ var _autoPlay = false; | ||
var root = typeof (window) !== "undefined" ? window : typeof (global) !== "undefined" ? global : {}; | ||
var _nextId = 0; | ||
var getAll = function () { | ||
return _tweens; | ||
}; | ||
Object.defineProperty(_tweens, "length", { | ||
enumerable: false, | ||
writable: true, | ||
value: 0 | ||
}); | ||
var autoPlay = function (state) { | ||
_autoPlay = state; | ||
}; | ||
var removeAll = function () { | ||
_tweens = []; | ||
}; | ||
var emit = function(name, a, b, c, d, e) { | ||
@@ -110,2 +105,22 @@ var this$1 = this; | ||
var on = function (ev, fn) { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
_events[ev].push(fn); | ||
}; | ||
var once = function (ev, fn) { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
on(ev, function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
fn.apply(void 0, args); | ||
off(ev); | ||
}); | ||
}; | ||
var off = function (ev, fn) { | ||
@@ -130,3 +145,5 @@ if (ev === undefined || _events[ev] === undefined) { | ||
var add = function (tween) { | ||
_tweens.push(tween); | ||
var id = tween.id; | ||
_tweens[id] = tween; | ||
_tweens.length++; | ||
@@ -142,33 +159,54 @@ if (_autoPlay && !isStarted) { | ||
var on = function (ev, fn) { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
_events[ev].push(fn); | ||
var nextId = function () { | ||
var id = _nextId; | ||
_nextId++; | ||
return id; | ||
}; | ||
var once = function (ev, fn) { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
on(ev, function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var getAll = function () { | ||
return _tweens; | ||
}; | ||
fn.apply(void 0, args); | ||
off(ev); | ||
var autoPlay = function (state) { | ||
_autoPlay = state; | ||
}; | ||
var removeAll = function () { | ||
_tweens = {}; | ||
Object.defineProperty(_tweens, "length", { | ||
enumerable: false, | ||
writable: true, | ||
value: 0 | ||
}); | ||
}; | ||
var get = function (tween) { | ||
for ( var searchTween in _tweens ) { | ||
if (tween.id === +searchTween) { | ||
return _tweens[+searchTween]; | ||
} | ||
} | ||
return null; | ||
}; | ||
var has = function (tween) { | ||
return get(tween) !== null; | ||
}; | ||
var remove = function (tween) { | ||
_tweens.filter(function (tweens) { return tweens !== tween; }); | ||
var i = 0 | ||
, tweenFind; | ||
while (i < _tweens.length) { | ||
tweenFind = _tweens[i]; | ||
if (tweenFind === tween) { | ||
emit('remove', tween, _tweens); | ||
_tweens.splice(i, 1); | ||
for ( var searchTween in _tweens ) { | ||
if (tween.id === +searchTween) { | ||
delete _tweens[+searchTween]; | ||
_tweens.length--; | ||
} | ||
i++; | ||
} | ||
@@ -221,4 +259,3 @@ }; | ||
var i = 0; | ||
while (i < _tweens.length) { | ||
for ( var i in _tweens ) { | ||
@@ -228,3 +265,4 @@ if (_tweens[i].update(time) || preserve) { | ||
} else { | ||
_tweens.splice(i, 1); | ||
delete _tweens[+i]; | ||
_tweens.length--; | ||
} | ||
@@ -237,3 +275,3 @@ | ||
// Normalise time when visiblity is changed ... | ||
// Normalise time when visiblity is changed (if available) ... | ||
if (root.document) { | ||
@@ -249,4 +287,9 @@ var doc = root.document, timeDiff = 0, timePause = 0; | ||
timeDiff = now$1() - timePause; | ||
_tweens.map(function (tween) { return tween._startTime += timeDiff; }); | ||
for ( var tween in _tweens ) { | ||
tween._startTime += timeDiff; | ||
} | ||
} | ||
@@ -752,2 +795,3 @@ return true; | ||
this._pausedTime = null; | ||
this.id = nextId(); | ||
@@ -1051,3 +1095,2 @@ if (instate && instate.to) { | ||
this.stopChainedTweens(); | ||
return this.emit('stop', object); | ||
@@ -1065,12 +1108,2 @@ | ||
}; | ||
Tween.prototype.stopChainedTweens = function stopChainedTweens () { | ||
var ref = this; | ||
var _chainedTweens = ref._chainedTweens; if ( _chainedTweens === void 0 ) _chainedTweens = []; | ||
_chainedTweens.map(function (item) { return item.stop(); }); | ||
return this; | ||
}; | ||
Tween.prototype.delay = function delay (amount) { | ||
@@ -1126,13 +1159,3 @@ | ||
}; | ||
Tween.prototype.chain = function chain () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
this._chainedTweens = args; | ||
return this; | ||
}; | ||
Tween.prototype.get = function get (time) { | ||
Tween.prototype.get = function get$$1 (time) { | ||
this.update(time); | ||
@@ -1147,3 +1170,2 @@ return this.object; | ||
var _onStartCallbackFired = ref._onStartCallbackFired; | ||
var _chainedTweens = ref._chainedTweens; | ||
var _easingFunction = ref._easingFunction; | ||
@@ -1271,6 +1293,2 @@ var _interpolationFunction = ref._interpolationFunction; | ||
if (_chainedTweens) { | ||
_chainedTweens.map(function (tween) { return tween.start(_startTime + _duration); }); | ||
} | ||
return false; | ||
@@ -1506,2 +1524,4 @@ | ||
exports.TweenInit = TweenInit; | ||
exports.has = has; | ||
exports.get = get; | ||
exports.getAll = getAll; | ||
@@ -1508,0 +1528,0 @@ exports.removeAll = removeAll; |
@@ -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=t.Tween||{})}(this,function(t){"use strict";function e(t,e,n){void 0===t&&(t={}),void 0===e&&(e={}),void 0===n&&(n=U);var i=new n;for(var r in t)void 0!==e[r]?i[r]=e[r]:i[r]=t[r];return i}function n(t){for(var e="",n=0,i=t.length;n<i;n++)e+=t[n];return e}function i(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}function r(t){var e=t.from,n=t.to,i=t.duration;void 0===i&&(i=1e3);var r=t.easing;void 0===r&&(r=G);var o=t.events,a=t.instance,s=new U(e,a).to(n,i).easing(G);o&&(s._events=o),t.start=s.start.bind(s)}void 0===Object.assign&&(Object.assign=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return e.map(function(e){for(var n in e)t[n]=e[n]}),t});var o="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof t?t:{},a=["webkit","moz","ms","o"],s="AnimationFrame",u="Request"+s,f="Cancel"+s,c="CancelRequest"+s,h=o.setTimeout,p=o.clearTimeout;if(h&&void 0===o.requestAnimationFrame){var l,v,d=Date.now(),y=50/3,m=y;a.map(function(t){void 0===(l=o[t+u])&&(l=function(t){return h(function(){v=Date.now(),t(v-d),m=y+(Date.now()-v)},m)})}),void 0!==l&&(o.requestAnimationFrame=l)}if(p&&void 0===o.cancelAnimationFrame&&void 0===(o.cancelAnimationFrame=o.cancelRequestAnimationFrame)){var _;a.map(function(t){void 0===(_=o[t+f])&&void 0===(_=o[t+c])&&(_=function(t){return p(t)})}),void 0!==_&&(o.cancelAnimationFrame=_)}void 0===Array.isArray&&(Array.isArray=function(t){return void 0!==t&&"object"==typeof t&&t.length&&void 0!==t.push&&void 0!==t.splice});var g,b=[],w=!1,T=!1,M={},j="undefined"!=typeof window?window:"undefined"!=typeof global?global:{},I=function(){return b},F=function(t){T=t},O=function(){b=[]},A=function(t,e,n,i,r,o){var a=this,s=M[t];if(s)for(var u=s.length;u--;)s[u].call(a,e,n,i,r,o)},P=function(t,e){if(void 0!==t&&void 0!==M[t])if(void 0!==e)for(var n=M[name],i=0;i<n.length;)n[i]===e&&n.splice(i,1),i++;else M[name]=[]},E=function(t){b.push(t),T&&!w&&(N(),w=!0,A("start")),A("add",t,b)},C=function(t,e){void 0===M[t]&&(M[t]=[]),M[t].push(e)},S=function(t,e){void 0===M[t]&&(M[t]=[]),C(t,function(){for(var n=[],i=arguments.length;i--;)n[i]=arguments[i];e.apply(void 0,n),P(t)})},k=function(t){b.filter(function(e){return e!==t});for(var e,n=0;n<b.length;)e=b[n],e===t&&(A("remove",t,b),b.splice(n,1)),n++},D=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!==j.performance&&void 0!==j.performance.now)return j.performance.now.bind(j.performance);var t=j.performance&&j.performance.timing&&j.performance.timing.navigationStart?j.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),N=function(t,e){if(t=void 0!==t?t:D(),T&&(g=requestAnimationFrame(N)),A("update",t,b),0===b.length)return w=!1,cancelAnimationFrame(g),A("stop",t),!1;for(var n=0;n<b.length;)b[n].update(t)||e?n++:b.splice(n,1);return!0};if(j.document){var x=j.document,q=0,B=0;x.addEventListener("visibilitychange",function(t){return 0!==b.length&&(document.hidden?B=D():(q=D()-B,b.map(function(t){return t._startTime+=q})),!0)})}var L={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*(-Math.pow(2,-10*(t-1))+2)}},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,t<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?.5*(t*t*((e+1)*t-e)):.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-L.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*L.Bounce.In(2*t):.5*L.Bounce.Out(2*t-1)+.5}}},R={Linear:function(t,e){var n=t.length-1,i=n*e,r=Math.floor(i),o=R.Utils.Linear;return e<0?o(t[0],t[1],i):e>1?o(t[n],t[n-1],n-i):o(t[r],t[r+1>n?n:r+1],i-r)},Bezier:function(t,e){for(var n=0,i=t.length-1,r=Math.pow,o=R.Utils.Bernstein,a=0;a<=i;a++)n+=r(1-e,i-a)*r(e,a)*t[a]*o(i,a);return n},CatmullRom:function(t,e){var n=t.length-1,i=n*e,r=Math.floor(i),o=R.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(r=Math.floor(i=n*(1+e))),o(t[(r-1+n)%n],t[r],t[(r+1)%n],t[(r+2)%n],i-r)):e<0?t[0]-(o(t[0],t[0],t[1],t[1],-i)-t[0]):e>1?t[n]-(o(t[n],t[n],t[n-1],t[n-1],i-n)-t[n]):o(t[r?r-1:0],t[r],t[n<r+1?n:r+1],t[n<r+2?n:r+2],i-r)},Utils:{Linear:function(t,e,n){return(e-t)*n+t},Bernstein:function(t,e){var n=R.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 i=e;i>1;i--)n*=i;return t[e]=n,n}}(),CatmullRom:function(t,e,n,i,r){var o=.5*(n-t),a=.5*(i-e),s=r*r,u=r*s;return(2*e-2*n+o+a)*u+(-3*e+3*n-2*o-a)*s+o*r+e}}},z=/\s+|([A-Za-z?().,{}:""\[\]#]+)|([-+\/*%]+=)?([-+*\/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/gi,U=function t(e,n){return void 0===e&&(e={}),this.object=e,this._valuesStart=t.createEmptyConst(e),this._valuesEnd=t.createEmptyConst(e),this._duration=1e3,this._easingFunction=L.Linear.None,this._interpolationFunction=R.None,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=null,this._isPlaying=!1,this._yoyo=!1,this._reversed=null,this._onStartCallbackFired=!1,this._pausedTime=null,n&&n.to?new t(e).to(n.to,n):this};U.createEmptyConst=function(t){return"number"==typeof t?0:Array.isArray(t)?[]:"object"==typeof t?{}:""},U.checkValidness=function(t){return void 0!==t&&null!==t&&""!==t&&NaN!==t&&t!==1/0},U.prototype.isPlaying=function(){return this._isPlaying},U.prototype.isStarted=function(){return this._onStartCallbackFired},U.prototype.reverse=function(){var t=this,e=t._reversed;return this._reversed=!e,this},U.prototype.reversed=function(){return this._reversed},U.prototype.off=function(t,e){if(!this._events||void 0===this._events[t])return this;if(void 0!==t&&void 0!==e)for(var n=this._events[t],i=0;i<n.length;)n[i]===e&&n.splice(i,1),i++;else void 0!==t&&void 0===e&&(this._events[t]=[]);return this},U.prototype.on=function(t,e){return this._events&&void 0!==this._events[t]||(this._events||(this._events={}),this._events[t]=[]),this._events[t].push(e),this},U.prototype.once=function(t,e){var n=this;return this._events&&void 0!==this._events[t]||(this._events||(this._events={}),this._events[t]=[]),this.on(t,function(){for(var i=[],r=arguments.length;r--;)i[r]=arguments[r];e.call.apply(e,[n].concat(i)),n.off(t)})},U.prototype.emit=function(t,e,n,i,r,o){var a=this,s=this,u=s._events;if(!u)return this;var f=u[t];if(!f)return this;for(var c=f.length;c--;)f[c].call(a,e,n,i,r,o);return this},U.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,k(this),this._pausedTime=D(),this.emit("pause",this.object)):this},U.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=D()-this._pausedTime,E(this),this._pausedTime=D(),this.emit("play",this.object))},U.prototype.restart=function(t){return this._repeat=this._r,this._startTime=D()+(t?0:this._delayTime),this._isPlaying||E(this),this.emit("restart",this._object)},U.prototype.seek=function(t,e){return this._startTime=D()+Math.max(0,Math.min(t,this._duration)),this.emit("seek",t,this._object),e?this:this.pause()},U.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},U.prototype.to=function(t,e){var n=this;if(void 0===t&&(t={}),void 0===e&&(e=1e3),"number"==typeof t){var i={Number:t};this._valuesEnd=i}else this._valuesEnd=t;if("number"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var r in e)n[r]&&n[r]("function"==typeof e[r]?e[r](n._duration):e);return this},U.prototype.start=function(t){var n=this,r=this,o=r._startTime,a=r._delayTime,s=r._valuesEnd,u=(r._valuesStart,r.object);o=void 0!==t?t:D(),o+=a,this._startTime=o;for(var f in s){if("object"==typeof s[f])if(Array.isArray(s[f]))if("number"==typeof u[f])n._valuesEnd[f]=[u[f]].concat(s[f]);else{var c=e(n,{object:u[f],_valuesEnd:s[f],_events:void 0}).start().stop();n._valuesEnd[f]=c}else{var h=e(n,{object:u[f],_valuesEnd:s[f],_events:void 0}).start().stop();n._valuesStart[f]=1,n._valuesEnd[f]=h}else if("string"==typeof s[f]&&"string"==typeof u[f]&&z.test(u[f])&&z.test(s[f])){var p=u[f].match(z);p=p.map(i);var l=s[f].match(z);l=l.map(i);var v=e(n,{object:p,_valuesEnd:l,_events:{}}).start().stop();v.join=!0,n._valuesStart[f]=1,n._valuesEnd[f]=v}"function"==typeof u[f]&&(u[f]=n.object[f]=u[f](n)),"function"==typeof s[f]&&(n._valuesEnd[f]=s[f](n)),U.checkValidness(u[f])!==!1&&u[f]!==s[f]&&(n._valuesStart[f]=u[f])}return E(this),this._isPlaying=!0,this},U.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object;return e?(k(this),this._isPlaying=!1,this.stopChainedTweens(),this.emit("stop",n)):this},U.prototype.end=function(){var t=this,e=t._startTime,n=t._duration;return this.update(e+n)},U.prototype.stopChainedTweens=function(){var t=this,e=t._chainedTweens;return void 0===e&&(e=[]),e.map(function(t){return t.stop()}),this},U.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},U.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this},U.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},U.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},U.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},U.prototype.easing=function(t){return this._easingFunction=t,this},U.prototype.interpolation=function(t){return this._interpolationFunction=t,this},U.prototype.chain=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return this._chainedTweens=t,this},U.prototype.get=function(t){return this.update(t),this.object},U.prototype.update=function(t){var e,i,r,o=this,a=this,s=a._onStartCallbackFired,u=a._chainedTweens,f=a._easingFunction,c=a._interpolationFunction,h=a._repeat,p=a._repeatDelayTime,l=a._reverseDelayTime,v=(a._delayTime,a._yoyo),d=a._reversed,y=a._startTime,m=a._duration,_=a._valuesStart,g=a._valuesEnd,b=a.object;if(t=void 0!==t?t:D(),t<y)return!0;s||(this.emit("start",b),this._onStartCallbackFired=!0),i=(t-y)/m,i=i>1?1:i,i=d?1-i:i,r=f(i);for(e in g)if(void 0!==_[e]){var w=_[e],T=g[e];if(T instanceof U){var M=T.get(t);T.join?b[e]=n(M):b[e]=M}else Array.isArray(T)?b[e]=c(T,r):"string"==typeof T?(T="+"===T.charAt(0)||"-"===T.charAt(0)?w+parseFloat(T):parseFloat(T),"number"==typeof T&&(b[e]=w+(T-w)*r)):"number"==typeof T&&(b[e]=w+(T-w)*r)}if(this.emit("update",b,r,i),1===i||d&&0===i){if(h){isFinite(h)&&this._repeat--;for(e in g)"string"==typeof g[e]&&"number"==typeof _[e]&&(o._valuesStart[e]=_[e]+parseFloat(g[e]));return this.emit(d?"reverse":"repeat",b),v&&(this._reversed=!d),!d&&p?this._startTime+=m+p:d&&l?this._startTime+=m+l:this._startTime+=m,!0}return this.emit("complete",b),u&&u.map(function(t){return t.start(y+m)}),!1}return!0};var X={filter:{grayscale:1,brightness:1,sepia:1,invert:1,saturate:1,contrast:1,blur:1,hueRotate:1,dropShadow:1},transform:{translate:1,translateX:1,translateY:1,translateZ:1,rotate:1,rotateX:1,rotateY:1,rotateZ:1,scale:1,scaleX:1,scaleY:1,scaleZ:1,skew:1,skewX:1,skewY:1}},Y=function(){};Y.DOM=function(t){var e=t.domNode,n=e.style;return{update:function(t,e){for(var i in e)n[i]=e[i]}}},Y.Transform=function(t){var e=t.domNode,n=e.style;return{update:function(t,e){var i="";for(var r in e)"x"===r||"y"===r||"z"===r?i+=" translate3d( "+(e.x||"0px")+", "+(e.y||"0px")+", "+(e.z||"0px")+")":X.transform[r]&&(i+=" "+r+"( "+e[r]+")");i&&(n.transform=i)}}},Y.Filter=function(t){var e=t.domNode,n=e.style;return{update:function(t,e){var i="";for(var r in e)X.filter[r]&&(i+=" "+r+"( "+e[r]+")");i&&(n.webkitFilter=n.filter=i)}}},Y.Scroll=function(t){var e=t.domNode;return{update:function(t,n){for(var i in n)e[i]=n[i]}}};var Z=function(t){this.domNode=t,this.plugins={};var e=this.plugins;return this.render=function(t){var n=this;for(var i in e)e[i]&&e[i].update&&e[i].update(n,t);return this},this.fetch=function(){var t=this;if(Object.keys(this.object).length)return this;for(var n in e)e[n]&&e[n].fetch&&e[n].fetch(t);return this},this.init=function(t){var n=this;for(var i in e)e[i]&&e[i].init&&e[i].init(n,t);return this},this},Q={object:{}};Z.prototype.applyPlugin=function(t){return void 0!==Y[t]&&(this.plugins[t]=Y[t](this)),this},Q.object.set=function(t){return this.render(t)},Z.prototype.cloneLayer=function(){return e(this,{},Z)},Z.prototype.appendTo=function(t){return t.appendChild(this.domNode),this},Object.defineProperties(Z.prototype,Q);var V=function(){return this._private={tweens:[],fullTime:0},this};V.prototype.add=function(t){var e=this;if(t instanceof U)this._private.tweens.push(t);else if(Array.isArray(t)||"object"!=typeof t)"object"==typeof t&&t.map(function(t){e.add(t)});else{var n=new U({x:0});for(var i in t)n[i](t[i]);this.add(n)}return this},V.prototype.start=function(){var t=this;return this._private.tweens.map(function(e){e.start(t._private.fullTime)}),this._private.fullTime=Math.max.apply(0,this._private.tweens.reduce(function(t,e){return e._duration>t?e._duration:t},0)),this};var G=function(t){return t};t.TweenInit=r,t.getAll=I,t.removeAll=O,t.remove=k,t.add=E,t.now=D,t.update=N,t.autoPlay=F,t.on=C,t.once=S,t.off=P,t.emit=A,t.Tween=U,t.Easing=L,t.Interpolation=R,t.Composite=Z,t.Timeline=V,t.Plugins=Y,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,e,n){void 0===t&&(t={}),void 0===e&&(e={}),void 0===n&&(n=Q);var i=new n;for(var r in t)void 0!==e[r]?i[r]=e[r]:i[r]=t[r];return i}function n(t){for(var e="",n=0,i=t.length;n<i;n++)e+=t[n];return e}function i(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}function r(t){var e=t.from,n=t.to,i=t.duration;void 0===i&&(i=1e3);var r=t.easing;void 0===r&&(r=K);var o=t.events,a=t.instance,s=new Q(e,a).to(n,i).easing(K);o&&(s._events=o),t.start=s.start.bind(s)}void 0===Object.assign&&(Object.assign=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return e.map(function(e){for(var n in e)t[n]=e[n]}),t});var o="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof t?t:{},a=["webkit","moz","ms","o"],s="AnimationFrame",u="Request"+s,f="Cancel"+s,c="CancelRequest"+s,h=o.setTimeout,p=o.clearTimeout;if(h&&void 0===o.requestAnimationFrame){var l,v,d=Date.now(),y=50/3,m=y;a.map(function(t){void 0===(l=o[t+u])&&(l=function(t){return h(function(){v=Date.now(),t(v-d),m=y+(Date.now()-v)},m)})}),void 0!==l&&(o.requestAnimationFrame=l)}if(p&&void 0===o.cancelAnimationFrame&&void 0===(o.cancelAnimationFrame=o.cancelRequestAnimationFrame)){var _;a.map(function(t){void 0===(_=o[t+f])&&void 0===(_=o[t+c])&&(_=function(t){return p(t)})}),void 0!==_&&(o.cancelAnimationFrame=_)}void 0===Array.isArray&&(Array.isArray=function(t){return void 0!==t&&"object"==typeof t&&t.length&&void 0!==t.push&&void 0!==t.splice});var g,b={},w=!1,T=!1,M={},j="undefined"!=typeof window?window:"undefined"!=typeof global?global:{},I=0;Object.defineProperty(b,"length",{enumerable:!1,writable:!0,value:0});var O=function(t,e,n,i,r,o){var a=this,s=M[t];if(s)for(var u=s.length;u--;)s[u].call(a,e,n,i,r,o)},F=function(t,e){void 0===M[t]&&(M[t]=[]),M[t].push(e)},A=function(t,e){void 0===M[t]&&(M[t]=[]),F(t,function(){for(var n=[],i=arguments.length;i--;)n[i]=arguments[i];e.apply(void 0,n),E(t)})},E=function(t,e){if(void 0!==t&&void 0!==M[t])if(void 0!==e)for(var n=M[name],i=0;i<n.length;)n[i]===e&&n.splice(i,1),i++;else M[name]=[]},P=function(t){var e=t.id;b[e]=t,b.length++,T&&!w&&(L(),w=!0,O("start")),O("add",t,b)},S=function(){var t=I;return I++,t},C=function(){return b},N=function(t){T=t},k=function(){b={},Object.defineProperty(b,"length",{enumerable:!1,writable:!0,value:0})},D=function(t){for(var e in b)if(t.id===+e)return b[+e];return null},x=function(t){return null!==D(t)},q=function(t){for(var e in b)t.id===+e&&(delete b[+e],b.length--)},B=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!==j.performance&&void 0!==j.performance.now)return j.performance.now.bind(j.performance);var t=j.performance&&j.performance.timing&&j.performance.timing.navigationStart?j.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),L=function(t,e){if(t=void 0!==t?t:B(),T&&(g=requestAnimationFrame(L)),O("update",t,b),0===b.length)return w=!1,cancelAnimationFrame(g),O("stop",t),!1;for(var n in b)b[n].update(t)||e?n++:(delete b[+n],b.length--);return!0};if(j.document){var R=j.document,z=0,U=0;R.addEventListener("visibilitychange",function(t){if(0===b.length)return!1;if(document.hidden)U=B();else{z=B()-U;for(var e in b)e._startTime+=z}return!0})}var X={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*(-Math.pow(2,-10*(t-1))+2)}},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,t<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?.5*(t*t*((e+1)*t-e)):.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-X.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*X.Bounce.In(2*t):.5*X.Bounce.Out(2*t-1)+.5}}},Y={Linear:function(t,e){var n=t.length-1,i=n*e,r=Math.floor(i),o=Y.Utils.Linear;return e<0?o(t[0],t[1],i):e>1?o(t[n],t[n-1],n-i):o(t[r],t[r+1>n?n:r+1],i-r)},Bezier:function(t,e){for(var n=0,i=t.length-1,r=Math.pow,o=Y.Utils.Bernstein,a=0;a<=i;a++)n+=r(1-e,i-a)*r(e,a)*t[a]*o(i,a);return n},CatmullRom:function(t,e){var n=t.length-1,i=n*e,r=Math.floor(i),o=Y.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(r=Math.floor(i=n*(1+e))),o(t[(r-1+n)%n],t[r],t[(r+1)%n],t[(r+2)%n],i-r)):e<0?t[0]-(o(t[0],t[0],t[1],t[1],-i)-t[0]):e>1?t[n]-(o(t[n],t[n],t[n-1],t[n-1],i-n)-t[n]):o(t[r?r-1:0],t[r],t[n<r+1?n:r+1],t[n<r+2?n:r+2],i-r)},Utils:{Linear:function(t,e,n){return(e-t)*n+t},Bernstein:function(t,e){var n=Y.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 i=e;i>1;i--)n*=i;return t[e]=n,n}}(),CatmullRom:function(t,e,n,i,r){var o=.5*(n-t),a=.5*(i-e),s=r*r,u=r*s;return(2*e-2*n+o+a)*u+(-3*e+3*n-2*o-a)*s+o*r+e}}},Z=/\s+|([A-Za-z?().,{}:""\[\]#]+)|([-+\/*%]+=)?([-+*\/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/gi,Q=function t(e,n){return void 0===e&&(e={}),this.object=e,this._valuesStart=t.createEmptyConst(e),this._valuesEnd=t.createEmptyConst(e),this._duration=1e3,this._easingFunction=X.Linear.None,this._interpolationFunction=Y.None,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=null,this._isPlaying=!1,this._yoyo=!1,this._reversed=null,this._onStartCallbackFired=!1,this._pausedTime=null,this.id=S(),n&&n.to?new t(e).to(n.to,n):this};Q.createEmptyConst=function(t){return"number"==typeof t?0:Array.isArray(t)?[]:"object"==typeof t?{}:""},Q.checkValidness=function(t){return void 0!==t&&null!==t&&""!==t&&NaN!==t&&t!==1/0},Q.prototype.isPlaying=function(){return this._isPlaying},Q.prototype.isStarted=function(){return this._onStartCallbackFired},Q.prototype.reverse=function(){var t=this,e=t._reversed;return this._reversed=!e,this},Q.prototype.reversed=function(){return this._reversed},Q.prototype.off=function(t,e){if(!this._events||void 0===this._events[t])return this;if(void 0!==t&&void 0!==e)for(var n=this._events[t],i=0;i<n.length;)n[i]===e&&n.splice(i,1),i++;else void 0!==t&&void 0===e&&(this._events[t]=[]);return this},Q.prototype.on=function(t,e){return this._events&&void 0!==this._events[t]||(this._events||(this._events={}),this._events[t]=[]),this._events[t].push(e),this},Q.prototype.once=function(t,e){var n=this;return this._events&&void 0!==this._events[t]||(this._events||(this._events={}),this._events[t]=[]),this.on(t,function(){for(var i=[],r=arguments.length;r--;)i[r]=arguments[r];e.call.apply(e,[n].concat(i)),n.off(t)})},Q.prototype.emit=function(t,e,n,i,r,o){var a=this,s=this,u=s._events;if(!u)return this;var f=u[t];if(!f)return this;for(var c=f.length;c--;)f[c].call(a,e,n,i,r,o);return this},Q.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,q(this),this._pausedTime=B(),this.emit("pause",this.object)):this},Q.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=B()-this._pausedTime,P(this),this._pausedTime=B(),this.emit("play",this.object))},Q.prototype.restart=function(t){return this._repeat=this._r,this._startTime=B()+(t?0:this._delayTime),this._isPlaying||P(this),this.emit("restart",this._object)},Q.prototype.seek=function(t,e){return this._startTime=B()+Math.max(0,Math.min(t,this._duration)),this.emit("seek",t,this._object),e?this:this.pause()},Q.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},Q.prototype.to=function(t,e){var n=this;if(void 0===t&&(t={}),void 0===e&&(e=1e3),"number"==typeof t){var i={Number:t};this._valuesEnd=i}else this._valuesEnd=t;if("number"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var r in e)n[r]&&n[r]("function"==typeof e[r]?e[r](n._duration):e);return this},Q.prototype.start=function(t){var n=this,r=this,o=r._startTime,a=r._delayTime,s=r._valuesEnd,u=(r._valuesStart,r.object);o=void 0!==t?t:B(),o+=a,this._startTime=o;for(var f in s){if("object"==typeof s[f])if(Array.isArray(s[f]))if("number"==typeof u[f])n._valuesEnd[f]=[u[f]].concat(s[f]);else{var c=e(n,{object:u[f],_valuesEnd:s[f],_events:void 0}).start().stop();n._valuesEnd[f]=c}else{var h=e(n,{object:u[f],_valuesEnd:s[f],_events:void 0}).start().stop();n._valuesStart[f]=1,n._valuesEnd[f]=h}else if("string"==typeof s[f]&&"string"==typeof u[f]&&Z.test(u[f])&&Z.test(s[f])){var p=u[f].match(Z);p=p.map(i);var l=s[f].match(Z);l=l.map(i);var v=e(n,{object:p,_valuesEnd:l,_events:{}}).start().stop();v.join=!0,n._valuesStart[f]=1,n._valuesEnd[f]=v}"function"==typeof u[f]&&(u[f]=n.object[f]=u[f](n)),"function"==typeof s[f]&&(n._valuesEnd[f]=s[f](n)),Q.checkValidness(u[f])!==!1&&u[f]!==s[f]&&(n._valuesStart[f]=u[f])}return P(this),this._isPlaying=!0,this},Q.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object;return e?(q(this),this._isPlaying=!1,this.emit("stop",n)):this},Q.prototype.end=function(){var t=this,e=t._startTime,n=t._duration;return this.update(e+n)},Q.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},Q.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this},Q.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},Q.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},Q.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},Q.prototype.easing=function(t){return this._easingFunction=t,this},Q.prototype.interpolation=function(t){return this._interpolationFunction=t,this},Q.prototype.get=function(t){return this.update(t),this.object},Q.prototype.update=function(t){var e,i,r,o=this,a=this,s=a._onStartCallbackFired,u=a._easingFunction,f=a._interpolationFunction,c=a._repeat,h=a._repeatDelayTime,p=a._reverseDelayTime,l=(a._delayTime,a._yoyo),v=a._reversed,d=a._startTime,y=a._duration,m=a._valuesStart,_=a._valuesEnd,g=a.object;if(t=void 0!==t?t:B(),t<d)return!0;s||(this.emit("start",g),this._onStartCallbackFired=!0),i=(t-d)/y,i=i>1?1:i,i=v?1-i:i,r=u(i);for(e in _)if(void 0!==m[e]){var b=m[e],w=_[e];if(w instanceof Q){var T=w.get(t);w.join?g[e]=n(T):g[e]=T}else Array.isArray(w)?g[e]=f(w,r):"string"==typeof w?(w="+"===w.charAt(0)||"-"===w.charAt(0)?b+parseFloat(w):parseFloat(w),"number"==typeof w&&(g[e]=b+(w-b)*r)):"number"==typeof w&&(g[e]=b+(w-b)*r)}if(this.emit("update",g,r,i),1===i||v&&0===i){if(c){isFinite(c)&&this._repeat--;for(e in _)"string"==typeof _[e]&&"number"==typeof m[e]&&(o._valuesStart[e]=m[e]+parseFloat(_[e]));return this.emit(v?"reverse":"repeat",g),l&&(this._reversed=!v),!v&&h?this._startTime+=y+h:v&&p?this._startTime+=y+p:this._startTime+=y,!0}return this.emit("complete",g),!1}return!0};var V={filter:{grayscale:1,brightness:1,sepia:1,invert:1,saturate:1,contrast:1,blur:1,hueRotate:1,dropShadow:1},transform:{translate:1,translateX:1,translateY:1,translateZ:1,rotate:1,rotateX:1,rotateY:1,rotateZ:1,scale:1,scaleX:1,scaleY:1,scaleZ:1,skew:1,skewX:1,skewY:1}},W=function(){};W.DOM=function(t){var e=t.domNode,n=e.style;return{update:function(t,e){for(var i in e)n[i]=e[i]}}},W.Transform=function(t){var e=t.domNode,n=e.style;return{update:function(t,e){var i="";for(var r in e)"x"===r||"y"===r||"z"===r?i+=" translate3d( "+(e.x||"0px")+", "+(e.y||"0px")+", "+(e.z||"0px")+")":V.transform[r]&&(i+=" "+r+"( "+e[r]+")");i&&(n.transform=i)}}},W.Filter=function(t){var e=t.domNode,n=e.style;return{update:function(t,e){var i="";for(var r in e)V.filter[r]&&(i+=" "+r+"( "+e[r]+")");i&&(n.webkitFilter=n.filter=i)}}},W.Scroll=function(t){var e=t.domNode;return{update:function(t,n){for(var i in n)e[i]=n[i]}}};var G=function(t){this.domNode=t,this.plugins={};var e=this.plugins;return this.render=function(t){var n=this;for(var i in e)e[i]&&e[i].update&&e[i].update(n,t);return this},this.fetch=function(){var t=this;if(Object.keys(this.object).length)return this;for(var n in e)e[n]&&e[n].fetch&&e[n].fetch(t);return this},this.init=function(t){var n=this;for(var i in e)e[i]&&e[i].init&&e[i].init(n,t);return this},this},H={object:{}};G.prototype.applyPlugin=function(t){return void 0!==W[t]&&(this.plugins[t]=W[t](this)),this},H.object.set=function(t){return this.render(t)},G.prototype.cloneLayer=function(){return e(this,{},G)},G.prototype.appendTo=function(t){return t.appendChild(this.domNode),this},Object.defineProperties(G.prototype,H);var J=function(){return this._private={tweens:[],fullTime:0},this};J.prototype.add=function(t){var e=this;if(t instanceof Q)this._private.tweens.push(t);else if(Array.isArray(t)||"object"!=typeof t)"object"==typeof t&&t.map(function(t){e.add(t)});else{var n=new Q({x:0});for(var i in t)n[i](t[i]);this.add(n)}return this},J.prototype.start=function(){var t=this;return this._private.tweens.map(function(e){e.start(t._private.fullTime)}),this._private.fullTime=Math.max.apply(0,this._private.tweens.reduce(function(t,e){return e._duration>t?e._duration:t},0)),this};var K=function(t){return t};t.TweenInit=r,t.has=x,t.get=D,t.getAll=C,t.removeAll=k,t.remove=q,t.add=P,t.now=B,t.update=L,t.autoPlay=N,t.on=F,t.once=A,t.off=E,t.emit=O,t.Tween=Q,t.Easing=X,t.Interpolation=Y,t.Composite=G,t.Timeline=J,t.Plugins=W,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"standard": { | ||
"ignore": [ | ||
"/dist/", | ||
"/test/" | ||
"dist/", | ||
"test/" | ||
] | ||
}, | ||
"name": "es6-tween", | ||
"version": "2.2.6", | ||
"version": "2.2.7", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -22,4 +22,4 @@ "browser": "dist/Tween.min.js", | ||
"dev": "rollup -c -w --sourcemap", | ||
"test": "npm run test-unit && npm run lint", | ||
"test-unit": "nodeunit test/unit/nodeunitheadless.js", | ||
"test": "npm run test-unit && npm run fix && npm run lint", | ||
"fix": "standard --fix", | ||
@@ -26,0 +26,0 @@ "lint": "standard --verbose | snazzy", |
@@ -23,4 +23,4 @@ import buble from 'rollup-plugin-buble' | ||
dest: destFile, // equivalent to --output | ||
moduleName: 'Tween', | ||
moduleName: 'TWEEN', | ||
plugins: plugins | ||
} |
let _tweens = []; | ||
let _tweens = {}; | ||
let isStarted = false; | ||
@@ -9,15 +9,10 @@ let _autoPlay = false; | ||
let root = typeof (window) !== "undefined" ? window : typeof (global) !== "undefined" ? global : {}; | ||
let _nextId = 0; | ||
const getAll = () => { | ||
return _tweens; | ||
} | ||
Object.defineProperty(_tweens, "length", { | ||
enumerable: false, | ||
writable: true, | ||
value: 0 | ||
}); | ||
const autoPlay = (state) => { | ||
_autoPlay = state; | ||
} | ||
const removeAll = () => { | ||
_tweens = [] | ||
} | ||
const emit = function(name, a, b, c, d, e) { | ||
@@ -34,2 +29,19 @@ let eventFn = _events[name]; | ||
const on = (ev, fn) => { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
_events[ev].push(fn); | ||
} | ||
const once = (ev, fn) => { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
on(ev, (...args) => { | ||
fn(...args); | ||
off(ev); | ||
}); | ||
} | ||
const off = (ev, fn) => { | ||
@@ -53,4 +65,6 @@ if (ev === undefined || _events[ev] === undefined) { | ||
const add = (tween) => { | ||
_tweens.push(tween); | ||
const add = tween => { | ||
let { id } = tween; | ||
_tweens[id] = tween; | ||
_tweens.length++; | ||
@@ -66,30 +80,54 @@ if (_autoPlay && !isStarted) { | ||
const on = (ev, fn) => { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
_events[ev].push(fn); | ||
const nextId = () => { | ||
let id = _nextId; | ||
_nextId++; | ||
return id; | ||
} | ||
const once = (ev, fn) => { | ||
if (_events[ev] === undefined) { | ||
_events[ev] = []; | ||
} | ||
on(ev, (...args) => { | ||
fn(...args); | ||
off(ev); | ||
const getAll = () => { | ||
return _tweens; | ||
} | ||
const autoPlay = (state) => { | ||
_autoPlay = state; | ||
} | ||
const removeAll = () => { | ||
_tweens = {} | ||
Object.defineProperty(_tweens, "length", { | ||
enumerable: false, | ||
writable: true, | ||
value: 0 | ||
}); | ||
} | ||
const remove = (tween) => { | ||
_tweens.filter(tweens => tweens !== tween); | ||
let i = 0 | ||
, tweenFind; | ||
while (i < _tweens.length) { | ||
tweenFind = _tweens[i]; | ||
if (tweenFind === tween) { | ||
emit('remove', tween, _tweens); | ||
_tweens.splice(i, 1); | ||
const get = tween => { | ||
for ( let searchTween in _tweens ) { | ||
if (tween.id === +searchTween) { | ||
return _tweens[+searchTween]; | ||
} | ||
} | ||
return null; | ||
} | ||
const has = tween => { | ||
return get(tween) !== null; | ||
} | ||
const remove = tween => { | ||
for ( let searchTween in _tweens ) { | ||
if (tween.id === +searchTween) { | ||
delete _tweens[+searchTween]; | ||
_tweens.length--; | ||
} | ||
i++ | ||
} | ||
@@ -142,4 +180,3 @@ } | ||
let i = 0; | ||
while (i < _tweens.length) { | ||
for ( let i in _tweens ) { | ||
@@ -149,3 +186,4 @@ if (_tweens[i].update(time) || preserve) { | ||
} else { | ||
_tweens.splice(i, 1); | ||
delete _tweens[+i]; | ||
_tweens.length--; | ||
} | ||
@@ -158,3 +196,3 @@ | ||
// Normalise time when visiblity is changed ... | ||
// Normalise time when visiblity is changed (if available) ... | ||
if (root.document) { | ||
@@ -170,4 +208,9 @@ let doc = root.document, timeDiff = 0, timePause = 0; | ||
timeDiff = now() - timePause; | ||
_tweens.map(tween => tween._startTime += timeDiff) | ||
for ( let tween in _tweens ) { | ||
tween._startTime += timeDiff | ||
} | ||
} | ||
@@ -178,2 +221,2 @@ return true; | ||
export { getAll, removeAll, remove, add, now, update, autoPlay, on, once, off, emit }; | ||
export { get, has, nextId, getAll, removeAll, remove, add, now, update, autoPlay, on, once, off, emit }; |
import { | ||
add, | ||
remove, | ||
now | ||
now, | ||
nextId | ||
} | ||
@@ -39,2 +40,3 @@ from './core'; | ||
this._pausedTime = null; | ||
this.id = nextId(); | ||
@@ -329,3 +331,2 @@ if (instate && instate.to) { | ||
this.stopChainedTweens(); | ||
return this.emit('stop', object); | ||
@@ -344,13 +345,2 @@ | ||
} | ||
stopChainedTweens() { | ||
let { | ||
_chainedTweens = [] | ||
} = this; | ||
_chainedTweens.map(item => item.stop()); | ||
return this; | ||
} | ||
delay(amount) { | ||
@@ -406,9 +396,2 @@ | ||
} | ||
chain(...args) { | ||
this._chainedTweens = args; | ||
return this; | ||
} | ||
get(time) { | ||
@@ -422,3 +405,2 @@ this.update(time); | ||
_onStartCallbackFired, | ||
_chainedTweens, | ||
_easingFunction, | ||
@@ -547,6 +529,2 @@ _interpolationFunction, | ||
if (_chainedTweens) { | ||
_chainedTweens.map(tween => tween.start(_startTime + _duration)); | ||
} | ||
return false; | ||
@@ -553,0 +531,0 @@ |
@@ -9,3 +9,3 @@ /* Shims will be deprecated in next update, please update browser */ | ||
import { getAll, removeAll, remove, add, now, update, autoPlay, on, once, off, emit } from './dist/core' | ||
import { has, get, getAll, removeAll, remove, add, now, update, autoPlay, on, once, off, emit } from './dist/core' | ||
@@ -26,2 +26,2 @@ import Easing from './dist/Easing' | ||
export { TweenInit, getAll, removeAll, remove, add, now, update, autoPlay, on, once, off, emit, Tween, Easing, Interpolation, Composite, Timeline, Plugins } | ||
export { TweenInit, has, get, getAll, removeAll, remove, add, now, update, autoPlay, on, once, off, emit, Tween, Easing, Interpolation, Composite, Timeline, Plugins } |
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
2284
273478