es6-tween
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -617,6 +617,8 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
this._startTime = null; | ||
this._startTime = 0; | ||
this._delayTime = 0; | ||
this._repeat = 0; | ||
this._r = 0; | ||
this._repeatDelayTime = 0; | ||
this._reverseDelayTime = 0; | ||
this._isPlaying = false; | ||
@@ -627,3 +629,3 @@ this._yoyo = false; | ||
this._onStartCallbackFired = false; | ||
this._events = new Map(); | ||
this._events = {}; | ||
this._pausedTime = 0; | ||
@@ -635,10 +637,100 @@ | ||
_createClass(Tween, [{ | ||
key: 'isPlaying', | ||
value: function isPlaying() { | ||
return this._isPlaying; | ||
} | ||
}, { | ||
key: 'isStarted', | ||
value: function isStarted() { | ||
return this._onStartCallbackFired; | ||
} | ||
}, { | ||
key: 'reverse', | ||
value: function reverse() { | ||
var _valuesStartRepeat = this._valuesStartRepeat, | ||
_yoyo = this._yoyo, | ||
_valuesEnd = this._valuesEnd, | ||
_valuesStart = this._valuesStart; | ||
// Reassign starting values, restart by making startTime = now | ||
for (var property in _valuesStartRepeat) { | ||
if (typeof _valuesEnd[property] === 'string') { | ||
_valuesStartRepeat[property] = _valuesStartRepeat[property] + parseFloat(_valuesEnd[property]); | ||
} | ||
if (_yoyo) { | ||
var tmp = _valuesStartRepeat[property]; | ||
_valuesStartRepeat[property] = _valuesEnd[property]; | ||
_valuesEnd[property] = tmp; | ||
} | ||
_valuesStart[property] = _valuesStartRepeat[property]; | ||
} | ||
this._reversed = !this._reversed; | ||
return this; | ||
} | ||
}, { | ||
key: 'off', | ||
value: function off(name, fn) { | ||
if (this._events[name] === undefined) { | ||
return this; | ||
} | ||
if (name !== undefined && fn !== undefined) { | ||
this._events[name].filter(function (event) { | ||
if (event === fn) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
} else if (name !== undefined && fn === undefined) { | ||
this._events[name] = []; | ||
} | ||
return this; | ||
} | ||
}, { | ||
key: 'on', | ||
value: function on(name, fn) { | ||
if (this._events[name] === undefined) { | ||
this._events[name] = []; | ||
} | ||
this._events[name].push(fn); | ||
return this; | ||
} | ||
}, { | ||
key: 'once', | ||
value: function once(name, fn) { | ||
var _this = this; | ||
if (this._events[name] === undefined) { | ||
this._events[name] = []; | ||
} | ||
return this.on(name, function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
fn.call.apply(fn, [_this].concat(args)); | ||
_this.off(name); | ||
}); | ||
} | ||
}, { | ||
key: 'emit', | ||
value: function emit(name, fn, a2, a3, a4) { | ||
value: function emit(name) { | ||
var _this2 = this; | ||
if (name !== undefined && typeof fn === "function") { | ||
this._events.set(name, fn); | ||
} else if (typeof fn !== "function" && this._events.get(name) !== undefined) { | ||
this._events.get(name).call(this, fn, a2, a3, a4); | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
if (this._events[name] === undefined) { | ||
return this; | ||
} | ||
this._events[name].map(function (event) { | ||
event.call.apply(event, [_this2].concat(args)); | ||
}); | ||
return this; | ||
@@ -678,2 +770,24 @@ } | ||
}, { | ||
key: 'restart', | ||
value: function restart(noDelay) { | ||
this._startTime = TWEEN.now() + (noDelay ? 0 : this._delayTime); | ||
if (!this._isPlaying) { | ||
TWEEN.add(this); | ||
} | ||
return this.emit('restart', this._object); | ||
} | ||
}, { | ||
key: 'seek', | ||
value: function seek(time, keepPlaying) { | ||
this._startTime = TWEEN.now() + Math.max(0, Math.min(time, this._duration)); | ||
this.emit('seek', time, this._object); | ||
return keepPlaying ? this : this.pause(); | ||
} | ||
}, { | ||
key: 'duration', | ||
@@ -768,2 +882,3 @@ value: function duration(amount) { | ||
this._repeat = times; | ||
this._r = times; | ||
@@ -781,2 +896,10 @@ return this; | ||
}, { | ||
key: 'reverseDelay', | ||
value: function reverseDelay(amount) { | ||
this._reverseDelayTime = amount; | ||
return this; | ||
} | ||
}, { | ||
key: 'yoyo', | ||
@@ -808,4 +931,4 @@ value: function yoyo(state) { | ||
value: function chain() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
@@ -820,6 +943,3 @@ | ||
value: function update(time) { | ||
var _onUpdateCallback = this._onUpdateCallback, | ||
_onStartCallback = this._onStartCallback, | ||
_onStartCallbackFired = this._onStartCallbackFired, | ||
_onCompleteCallback = this._onCompleteCallback, | ||
var _onStartCallbackFired = this._onStartCallbackFired, | ||
_chainedTweens = this._chainedTweens, | ||
@@ -830,2 +950,3 @@ _easingFunction = this._easingFunction, | ||
_repeatDelayTime = this._repeatDelayTime, | ||
_reverseDelayTime = this._reverseDelayTime, | ||
_delayTime = this._delayTime, | ||
@@ -916,3 +1037,3 @@ _yoyo = this._yoyo, | ||
this.emit('repeat', object, _reversed); | ||
this.emit(_reversed ? 'repeat' : 'reverse', object); | ||
@@ -923,4 +1044,6 @@ if (_yoyo) { | ||
if (_repeatDelayTime) { | ||
if (_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime; | ||
} else if (!_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime; | ||
} else { | ||
@@ -939,2 +1062,4 @@ this._startTime = time + _delayTime; | ||
this._repeat = this._r; | ||
return false; | ||
@@ -1016,3 +1141,3 @@ } | ||
if (ROOT.cancelAnimationFrame === undefined) { | ||
if (ROOT.cancelAnimationFrame === undefined && (ROOT.cancelAnimationFrame = ROOT.cancelRequestAnimationFrame) === undefined) { | ||
var _caf = void 0; | ||
@@ -1019,0 +1144,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.TWEEN=n():t.TWEEN=n()}(this,function(){return function(t){function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}var e={};return n.m=t,n.c=e,n.i=function(t){return t},n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="",n(n.s=8)}([function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var i={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(-10*t,2)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(-Math.pow(-10*(t-1),2)+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(10*(t-1),2)*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(-10*t,2)*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(10*(t-1),2)*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(-10*(t-1),2)*Math.sin(5*(t-1.1)*Math.PI)+1)}},Back:{In:function(t){var n=1.70158;return t*t*((n+1)*t-n)},Out:function(t){var n=1.70158;return--t*t*((n+1)*t+n)+1},InOut:function(t){var n=2.5949095;return(t*=2)<1?.5*(t*t*((n+1)*t-n)):.5*((t-=2)*t*((n+1)*t+n)+2)}},Bounce:{In:function(t){return 1-i.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*i.Bounce.In(2*t):.5*i.Bounce.Out(2*t-1)+.5}}};n.default=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var i={Linear:function(t,n){var e=t.length-1,r=e*n,o=Math.floor(r),u=i.Utils.Linear;return n<0?u(t[0],t[1],r):n>1?u(t[e],t[e-1],e-r):u(t[o],t[o+1>e?e:o+1],r-o)},Bezier:function(t,n){for(var e=0,r=t.length-1,o=Math.pow,u=i.Utils.Bernstein,a=0;a<=r;a++)e+=o(1-n,r-a)*o(n,a)*t[a]*u(r,a);return e},CatmullRom:function(t,n){var e=t.length-1,r=e*n,o=Math.floor(r),u=i.Utils.CatmullRom;return t[0]===t[e]?(n<0&&(o=Math.floor(r=e*(1+n))),u(t[(o-1+e)%e],t[o],t[(o+1)%e],t[(o+2)%e],r-o)):n<0?t[0]-(u(t[0],t[0],t[1],t[1],-r)-t[0]):n>1?t[e]-(u(t[e],t[e],t[e-1],t[e-1],r-e)-t[e]):u(t[o?o-1:0],t[o],t[e<o+1?e:o+1],t[e<o+2?e:o+2],r-o)},Utils:{Linear:function(t,n,e){return(n-t)*e+t},Bernstein:function(t,n){var e=i.Utils.Factorial;return e(t)/e(n)/e(t-n)},Factorial:function(){var t=[1];return function(n){var e=1;if(t[n])return t[n];for(var i=n;i>1;i--)e*=i;return t[n]=e,e}}(),CatmullRom:function(t,n,e,i,r){var o=.5*(e-t),u=.5*(i-n),a=r*r,s=r*a;return(2*n-2*e+o+u)*s+(-3*n+3*e-2*o-u)*a+o*r+n}}};n.default=i},function(t,n,e){"use strict";function i(t){p(o)?(o=t,s=requestAnimationFrame(i)):(u=!1,cancelAnimationFrame(s))}Object.defineProperty(n,"__esModule",{value:!0});var r=[],o=0,u=!1,a=!1,s=void 0,c=function(){return r},f=function(t){a=t},l=function(){r=[]},h=function(t){r.push(t),a&&!u&&(i(v()),u=!0)},d=function(t){r.filter(function(n){return n!==t})},v=function(){return o},p=function(t,n){if(t=void 0!==t?t:v(),o=t,0===r.length)return!1;for(var e=0;e<r.length;)r[e].update(t)||n?e++:r.splice(e,1);return!0};n.getAll=c,n.removeAll=l,n.remove=d,n.add=h,n.now=v,n.update=p,n.autoPlay=f},function(t,n,e){"use strict";var i,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(t){"object"===("undefined"==typeof window?"undefined":r(window))&&(i=window)}t.exports=i},function(t,n,e){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}function r(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}(),u=(e(2),e(0)),a=i(u),s=e(1),c=i(s),f=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return r(this,t),this.object=n,this._valuesStart=Object.assign({},n),this._valuesStartRepeat=Object.assign({},n),this._valuesEnd={},this._chainedTweens=[],this._duration=1e3,this._easingFunction=a.default.Linear.None,this._interpolationFunction=c.default.None,this._startTime=null,this._delayTime=0,this._repeat=0,this._repeatDelayTime=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._events=new Map,this._pausedTime=0,this}return o(t,[{key:"emit",value:function(t,n,e,i,r){return void 0!==t&&"function"==typeof n?this._events.set(t,n):"function"!=typeof n&&void 0!==this._events.get(t)&&this._events.get(t).call(this,n,e,i,r),this}},{key:"pause",value:function(){return this._isPlaying?(this._isPlaying=!1,TWEEN.remove(this),this._pausedTime=TWEEN.now(),this.emit("pause",this.object)):this}},{key:"play",value:function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=TWEEN.now()-this._pausedTime,TWEEN.add(this),this._pausedTime=TWEEN.now(),this.emit("play",this.object))}},{key:"duration",value:function(t){return this._duration=t,this}},{key:"to",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;return this._valuesEnd=t,this._duration=n,this}},{key:"start",value:function(t){var n=this._startTime,e=this._delayTime;return n=void 0!==t?t:TWEEN.now(),n+=e,this._startTime=n,TWEEN.add(this),this._isPlaying=!0,this}},{key:"stop",value:function(){var t=this._isPlaying,n=(this._onStopCallback,this.object);return t?(TWEEN.remove(this),this._isPlaying=!1,this.stopChainedTweens(),this.emit("stop",n)):this}},{key:"end",value:function(){var t=this._startTime,n=this._duration;return this.update(t+n)}},{key:"stopChainedTweens",value:function(){var t=this._chainedTweens;return t.map(function(t){return t.stop()}),this}},{key:"delay",value:function(t){return this._delayTime=t,this}},{key:"repeat",value:function(t){return this._repeat=t,this}},{key:"repeatDelay",value:function(t){return this._repeatDelayTime=t,this}},{key:"yoyo",value:function(t){return this._yoyo=t,this}},{key:"easing",value:function(t){return this._easingFunction=t,this}},{key:"interpolation",value:function(t){return this._interpolationFunction=t,this}},{key:"chain",value:function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return this._chainedTweens=n,this}},{key:"update",value:function(t){var n=(this._onUpdateCallback,this._onStartCallback,this._onStartCallbackFired),e=(this._onCompleteCallback,this._chainedTweens),i=this._easingFunction,r=this._interpolationFunction,o=this._repeat,u=this._repeatDelayTime,a=this._delayTime,s=this._yoyo,c=this._reversed,f=this._startTime,l=this._duration,h=this._valuesStart,d=this._valuesStartRepeat,v=this._valuesEnd,p=this.object,y=void 0,_=void 0,m=void 0;if(t<f)return!0;n===!1&&(this.emit("start",p),this._onStartCallbackFired=!0),_=(t-f)/l,_=_>1?1:_,m=i(_);for(y in v){var w=h[y],b=v[y];b instanceof Array?p[y]=r(b,m):("string"==typeof b&&(b="+"===b.charAt(0)||"-"===b.charAt(0)?w+parseFloat(b):parseFloat(b)),"number"==typeof b&&(p[y]=w+(b-w)*m))}if(this.emit("update",p,_),1===_){if(o>0){isFinite(o)&&o--;for(y in d){if("string"==typeof v[y]&&(d[y]=d[y]+parseFloat(v[y])),s){var g=d[y];d[y]=v[y],v[y]=g}h[y]=d[y]}return this.emit("repeat",p,c),s&&(this._reversed=!c),u?this._startTime=t+u:this._startTime=t+a,!0}return this.emit("complete",p),e.map(function(t){return t.start(f+l)}),!1}return!0}}]),t}();n.default=f},function(t,n,e){"use strict";void 0===Object.assign&&(Object.assign=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];var i=n.shift();return n.map(function(t){for(var n in t)i[n]=t[n]}),i})},function(t,n,e){"use strict";(function(t){var n="undefined"!=typeof window?window:"undefined"!=typeof t?t:void 0,e=["webkit","moz","ms","o"],i="AnimationFrame",r="Request"+i,o="Cancel"+i,u="CancelRequest"+i,a=setTimeout,s=clearTimeout;if(void 0===n.requestAnimationFrame){var c=void 0,f=void 0,l=Date.now(),h=50/3,d=h;e.map(function(t){void 0===(c=n[t+r])&&(c=function(t){return a(function(){f=Date.now(),t(f-l),d=h+(Date.now()-f)},d)})}),void 0!==c&&(n.requestAnimationFrame=c)}if(void 0===n.cancelAnimationFrame){var v=void 0;e.map(function(t){void 0===(v=n[t+o])&&void 0===(v=n[t+u])&&(v=function(t){return s(t)})}),void 0!==v&&(n.cancelAnimationFrame=v)}}).call(n,e(3))},function(t,n,e){"use strict";(function(t){function n(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var e="undefined"!=typeof window?window:"undefined"!=typeof t?t:void 0;void 0===e.Map&&(e.Map=function t(){n(this,t);var e={};return this.set=function(t,n){return e[t]=n,this},this.get=function(t){return e[t]},this.has=function(t){return void 0!==this.get(t)},this})}).call(n,e(3))},function(t,n,e){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(n,"__esModule",{value:!0}),n.Interpolation=n.Easing=n.Tween=n.now=n.autoPlay=n.update=n.remove=n.removeAll=n.add=n.getAll=void 0,e(5),e(6),e(7);var r=e(2),o=e(0),u=i(o),a=e(4),s=i(a),c=e(1),f=i(c);n.getAll=r.getAll,n.add=r.add,n.removeAll=r.removeAll,n.remove=r.remove,n.update=r.update,n.autoPlay=r.autoPlay,n.now=r.now,n.Tween=s.default,n.Easing=u.default,n.Interpolation=f.default}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TWEEN=e():t.TWEEN=e()}(this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=8)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i={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(-10*t,2)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(-Math.pow(-10*(t-1),2)+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(10*(t-1),2)*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(-10*t,2)*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(10*(t-1),2)*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(-10*(t-1),2)*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-i.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*i.Bounce.In(2*t):.5*i.Bounce.Out(2*t-1)+.5}}};e.default=i},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i={Linear:function(t,e){var n=t.length-1,r=n*e,o=Math.floor(r),u=i.Utils.Linear;return e<0?u(t[0],t[1],r):e>1?u(t[n],t[n-1],n-r):u(t[o],t[o+1>n?n:o+1],r-o)},Bezier:function(t,e){for(var n=0,r=t.length-1,o=Math.pow,u=i.Utils.Bernstein,a=0;a<=r;a++)n+=o(1-e,r-a)*o(e,a)*t[a]*u(r,a);return n},CatmullRom:function(t,e){var n=t.length-1,r=n*e,o=Math.floor(r),u=i.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(o=Math.floor(r=n*(1+e))),u(t[(o-1+n)%n],t[o],t[(o+1)%n],t[(o+2)%n],r-o)):e<0?t[0]-(u(t[0],t[0],t[1],t[1],-r)-t[0]):e>1?t[n]-(u(t[n],t[n],t[n-1],t[n-1],r-n)-t[n]):u(t[o?o-1:0],t[o],t[n<o+1?n:o+1],t[n<o+2?n:o+2],r-o)},Utils:{Linear:function(t,e,n){return(e-t)*n+t},Bernstein:function(t,e){var n=i.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),u=.5*(i-e),a=r*r,s=r*a;return(2*e-2*n+o+u)*s+(-3*e+3*n-2*o-u)*a+o*r+e}}};e.default=i},function(t,e,n){"use strict";function i(t){p(o)?(o=t,s=requestAnimationFrame(i)):(u=!1,cancelAnimationFrame(s))}Object.defineProperty(e,"__esModule",{value:!0});var r=[],o=0,u=!1,a=!1,s=void 0,c=function(){return r},h=function(t){a=t},f=function(){r=[]},l=function(t){r.push(t),a&&!u&&(i(d()),u=!0)},v=function(t){r.filter(function(e){return e!==t})},d=function(){return o},p=function(t,e){if(t=void 0!==t?t:d(),o=t,0===r.length)return!1;for(var n=0;n<r.length;)r[n].update(t)||e?n++:r.splice(n,1);return!0};e.getAll=c,e.removeAll=f,e.remove=v,e.add=l,e.now=d,e.update=p,e.autoPlay=h},function(t,e,n){"use strict";var i,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(t){"object"===("undefined"==typeof window?"undefined":r(window))&&(i=window)}t.exports=i},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),u=(n(2),n(0)),a=i(u),s=n(1),c=i(s),h=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return r(this,t),this.object=e,this._valuesStart=Object.assign({},e),this._valuesStartRepeat=Object.assign({},e),this._valuesEnd={},this._chainedTweens=[],this._duration=1e3,this._easingFunction=a.default.Linear.None,this._interpolationFunction=c.default.None,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._repeatDelayTime=0,this._reverseDelayTime=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._events={},this._pausedTime=0,this}return o(t,[{key:"isPlaying",value:function(){return this._isPlaying}},{key:"isStarted",value:function(){return this._onStartCallbackFired}},{key:"reverse",value:function(){var t=this._valuesStartRepeat,e=this._yoyo,n=this._valuesEnd,i=this._valuesStart;for(var r in t){if("string"==typeof n[r]&&(t[r]=t[r]+parseFloat(n[r])),e){var o=t[r];t[r]=n[r],n[r]=o}i[r]=t[r]}return this._reversed=!this._reversed,this}},{key:"off",value:function(t,e){return void 0===this._events[t]?this:(void 0!==t&&void 0!==e?this._events[t].filter(function(t){return t!==e}):void 0!==t&&void 0===e&&(this._events[t]=[]),this)}},{key:"on",value:function(t,e){return void 0===this._events[t]&&(this._events[t]=[]),this._events[t].push(e),this}},{key:"once",value:function(t,e){var n=this;return void 0===this._events[t]&&(this._events[t]=[]),this.on(t,function(){for(var i=arguments.length,r=Array(i),o=0;o<i;o++)r[o]=arguments[o];e.call.apply(e,[n].concat(r)),n.off(t)})}},{key:"emit",value:function(t){for(var e=this,n=arguments.length,i=Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return void 0===this._events[t]?this:(this._events[t].map(function(t){t.call.apply(t,[e].concat(i))}),this)}},{key:"pause",value:function(){return this._isPlaying?(this._isPlaying=!1,TWEEN.remove(this),this._pausedTime=TWEEN.now(),this.emit("pause",this.object)):this}},{key:"play",value:function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=TWEEN.now()-this._pausedTime,TWEEN.add(this),this._pausedTime=TWEEN.now(),this.emit("play",this.object))}},{key:"restart",value:function(t){return this._startTime=TWEEN.now()+(t?0:this._delayTime),this._isPlaying||TWEEN.add(this),this.emit("restart",this._object)}},{key:"seek",value:function(t,e){return this._startTime=TWEEN.now()+Math.max(0,Math.min(t,this._duration)),this.emit("seek",t,this._object),e?this:this.pause()}},{key:"duration",value:function(t){return this._duration=t,this}},{key:"to",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;return this._valuesEnd=t,this._duration=e,this}},{key:"start",value:function(t){var e=this._startTime,n=this._delayTime;return e=void 0!==t?t:TWEEN.now(),e+=n,this._startTime=e,TWEEN.add(this),this._isPlaying=!0,this}},{key:"stop",value:function(){var t=this._isPlaying,e=(this._onStopCallback,this.object);return t?(TWEEN.remove(this),this._isPlaying=!1,this.stopChainedTweens(),this.emit("stop",e)):this}},{key:"end",value:function(){var t=this._startTime,e=this._duration;return this.update(t+e)}},{key:"stopChainedTweens",value:function(){var t=this._chainedTweens;return t.map(function(t){return t.stop()}),this}},{key:"delay",value:function(t){return this._delayTime=t,this}},{key:"repeat",value:function(t){return this._repeat=t,this._r=t,this}},{key:"repeatDelay",value:function(t){return this._repeatDelayTime=t,this}},{key:"reverseDelay",value:function(t){return this._reverseDelayTime=t,this}},{key:"yoyo",value:function(t){return this._yoyo=t,this}},{key:"easing",value:function(t){return this._easingFunction=t,this}},{key:"interpolation",value:function(t){return this._interpolationFunction=t,this}},{key:"chain",value:function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return this._chainedTweens=e,this}},{key:"update",value:function(t){var e=this._onStartCallbackFired,n=this._chainedTweens,i=this._easingFunction,r=this._interpolationFunction,o=this._repeat,u=this._repeatDelayTime,a=this._reverseDelayTime,s=this._delayTime,c=this._yoyo,h=this._reversed,f=this._startTime,l=this._duration,v=this._valuesStart,d=this._valuesStartRepeat,p=this._valuesEnd,y=this.object,_=void 0,m=void 0,w=void 0;if(t<f)return!0;e===!1&&(this.emit("start",y),this._onStartCallbackFired=!0),m=(t-f)/l,m=m>1?1:m,w=i(m);for(_ in p){var T=v[_],g=p[_];g instanceof Array?y[_]=r(g,w):("string"==typeof g&&(g="+"===g.charAt(0)||"-"===g.charAt(0)?T+parseFloat(g):parseFloat(g)),"number"==typeof g&&(y[_]=T+(g-T)*w))}if(this.emit("update",y,m),1===m){if(o>0){isFinite(o)&&o--;for(_ in d){if("string"==typeof p[_]&&(d[_]=d[_]+parseFloat(p[_])),c){var b=d[_];d[_]=p[_],p[_]=b}v[_]=d[_]}return this.emit(h?"repeat":"reverse",y),c&&(this._reversed=!h),h&&u?this._startTime=t+u:!h&&a?this._startTime=t+a:this._startTime=t+s,!0}return this.emit("complete",y),n.map(function(t){return t.start(f+l)}),this._repeat=this._r,!1}return!0}}]),t}();e.default=h},function(t,e,n){"use strict";void 0===Object.assign&&(Object.assign=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];var i=e.shift();return e.map(function(t){for(var e in t)i[e]=t[e]}),i})},function(t,e,n){"use strict";(function(t){var e="undefined"!=typeof window?window:"undefined"!=typeof t?t:void 0,n=["webkit","moz","ms","o"],i="AnimationFrame",r="Request"+i,o="Cancel"+i,u="CancelRequest"+i,a=setTimeout,s=clearTimeout;if(void 0===e.requestAnimationFrame){var c=void 0,h=void 0,f=Date.now(),l=50/3,v=l;n.map(function(t){void 0===(c=e[t+r])&&(c=function(t){return a(function(){h=Date.now(),t(h-f),v=l+(Date.now()-h)},v)})}),void 0!==c&&(e.requestAnimationFrame=c)}if(void 0===e.cancelAnimationFrame&&void 0===(e.cancelAnimationFrame=e.cancelRequestAnimationFrame)){var d=void 0;n.map(function(t){void 0===(d=e[t+o])&&void 0===(d=e[t+u])&&(d=function(t){return s(t)})}),void 0!==d&&(e.cancelAnimationFrame=d)}}).call(e,n(3))},function(t,e,n){"use strict";(function(t){function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var n="undefined"!=typeof window?window:"undefined"!=typeof t?t:void 0;void 0===n.Map&&(n.Map=function t(){e(this,t);var n={};return this.set=function(t,e){return n[t]=e,this},this.get=function(t){return n[t]},this.has=function(t){return void 0!==this.get(t)},this})}).call(e,n(3))},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.Interpolation=e.Easing=e.Tween=e.now=e.autoPlay=e.update=e.remove=e.removeAll=e.add=e.getAll=void 0,n(5),n(6),n(7);var r=n(2),o=n(0),u=i(o),a=n(4),s=i(a),c=n(1),h=i(c);e.getAll=r.getAll,e.add=r.add,e.removeAll=r.removeAll,e.remove=r.remove,e.update=r.update,e.autoPlay=r.autoPlay,e.now=r.now,e.Tween=s.default,e.Easing=u.default,e.Interpolation=h.default}])}); |
{ | ||
"name": "es6-tween", | ||
"version": "0.1.09", | ||
"version": "0.1.10", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/Tween.js", |
@@ -1,2 +0,7 @@ | ||
import { add, remove, now } from './core'; | ||
import { | ||
add | ||
, remove | ||
, now | ||
} | ||
from './core'; | ||
import Easing from './Easing'; | ||
@@ -18,6 +23,8 @@ import Interpolation from './Interpolation'; | ||
this._startTime = null; | ||
this._startTime = 0; | ||
this._delayTime = 0; | ||
this._repeat = 0; | ||
this._r = 0; | ||
this._repeatDelayTime = 0; | ||
this._reverseDelayTime = 0; | ||
this._isPlaying = false; | ||
@@ -28,3 +35,3 @@ this._yoyo = false; | ||
this._onStartCallbackFired = false; | ||
this._events = new Map(); | ||
this._events = {}; | ||
this._pausedTime = 0; | ||
@@ -35,15 +42,85 @@ | ||
} | ||
emit(name, fn, a2, a3, a4) { | ||
isPlaying() { | ||
return this._isPlaying; | ||
} | ||
isStarted() { | ||
return this._onStartCallbackFired; | ||
} | ||
reverse() { | ||
if (name !== undefined && typeof(fn) === "function") { | ||
this._events.set(name, fn); | ||
} else if (typeof(fn) !== "function" && this._events.get(name) !== undefined) { | ||
this._events.get(name).call(this, fn, a2, a3, a4); | ||
let { | ||
_valuesStartRepeat | ||
, _yoyo | ||
, _valuesEnd | ||
, _valuesStart | ||
} = this; | ||
// Reassign starting values, restart by making startTime = now | ||
for ( let property in _valuesStartRepeat ) { | ||
if ( typeof( _valuesEnd[ property ] ) === 'string' ) { | ||
_valuesStartRepeat[ property ] = _valuesStartRepeat[ property ] + parseFloat( _valuesEnd[ property ] ); | ||
} | ||
if ( _yoyo ) { | ||
let tmp = _valuesStartRepeat[ property ]; | ||
_valuesStartRepeat[ property ] = _valuesEnd[ property ]; | ||
_valuesEnd[ property ] = tmp; | ||
} | ||
_valuesStart[ property ] = _valuesStartRepeat[ property ]; | ||
} | ||
this._reversed = !this._reversed; | ||
return this; | ||
} | ||
off( name, fn ) { | ||
if ( this._events[ name ] === undefined ) { | ||
return this; | ||
} | ||
if ( name !== undefined && fn !== undefined ) { | ||
this._events[ name ].filter( event => { | ||
if ( event === fn ) { | ||
return false; | ||
} | ||
return true; | ||
} ); | ||
} else if ( name !== undefined && fn === undefined ) { | ||
this._events[ name ] = []; | ||
} | ||
return this; | ||
} | ||
on( name, fn ) { | ||
if ( this._events[ name ] === undefined ) { | ||
this._events[ name ] = []; | ||
} | ||
this._events[ name ].push( fn ); | ||
return this; | ||
} | ||
once( name, fn ) { | ||
if ( this._events[ name ] === undefined ) { | ||
this._events[ name ] = []; | ||
} | ||
return this.on( name, ( ...args ) => { | ||
fn.call( this, ...args ); | ||
this.off( name ); | ||
} ); | ||
} | ||
emit( name, ...args ) { | ||
if ( this._events[ name ] === undefined ) { | ||
return this; | ||
} | ||
this._events[ name ].map( event => { | ||
event.call( this, ...args ); | ||
} ); | ||
return this; | ||
} | ||
pause () { | ||
pause() { | ||
if (!this._isPlaying) { | ||
if ( !this._isPlaying ) { | ||
return this; | ||
@@ -54,10 +131,10 @@ } | ||
TWEEN.remove(this); | ||
TWEEN.remove( this ); | ||
this._pausedTime = TWEEN.now(); | ||
return this.emit('pause', this.object); | ||
return this.emit( 'pause', this.object ); | ||
} | ||
play () { | ||
play() { | ||
if (this._isPlaying) { | ||
if ( this._isPlaying ) { | ||
return this; | ||
@@ -69,9 +146,30 @@ } | ||
this._startTime += TWEEN.now() - this._pausedTime; | ||
TWEEN.add(this); | ||
TWEEN.add( this ); | ||
this._pausedTime = TWEEN.now(); | ||
return this.emit('play', this.object); | ||
return this.emit( 'play', this.object ); | ||
} | ||
duration ( amount ) { | ||
restart( noDelay ) { | ||
this._startTime = TWEEN.now() + ( noDelay ? 0 : this._delayTime ); | ||
if ( !this._isPlaying ) { | ||
TWEEN.add( this ); | ||
} | ||
return this.emit( 'restart', this._object ); | ||
} | ||
seek( time, keepPlaying ) { | ||
this._startTime = TWEEN.now() + Math.max( 0, Math.min( | ||
time, this._duration ) ); | ||
this.emit( 'seek', time, this._object ); | ||
return keepPlaying ? this : this.pause(); | ||
} | ||
duration( amount ) { | ||
this._duration = amount; | ||
@@ -91,3 +189,6 @@ | ||
let { _startTime, _delayTime } = this; | ||
let { | ||
_startTime | ||
, _delayTime | ||
} = this; | ||
@@ -108,3 +209,7 @@ _startTime = time !== undefined ? time : TWEEN.now(); | ||
let { _isPlaying, _onStopCallback, object } = this; | ||
let { | ||
_isPlaying | ||
, _onStopCallback | ||
, object | ||
} = this; | ||
@@ -119,3 +224,3 @@ if ( !_isPlaying ) { | ||
this.stopChainedTweens(); | ||
return this.emit('stop', object); | ||
return this.emit( 'stop', object ); | ||
@@ -125,3 +230,6 @@ } | ||
const { _startTime, _duration } = this; | ||
const { | ||
_startTime | ||
, _duration | ||
} = this; | ||
@@ -133,3 +241,5 @@ return this.update( _startTime + _duration ); | ||
let { _chainedTweens } = this; | ||
let { | ||
_chainedTweens | ||
} = this; | ||
@@ -151,2 +261,3 @@ _chainedTweens.map( item => item.stop() ); | ||
this._repeat = times; | ||
this._r = times; | ||
@@ -163,2 +274,9 @@ return this; | ||
} | ||
reverseDelay( amount ) { | ||
this._reverseDelayTime = amount; | ||
return this; | ||
} | ||
yoyo( state ) { | ||
@@ -195,6 +313,3 @@ | ||
let { | ||
_onUpdateCallback | ||
, _onStartCallback | ||
, _onStartCallbackFired | ||
, _onCompleteCallback | ||
_onStartCallbackFired | ||
, _chainedTweens | ||
@@ -205,2 +320,3 @@ , _easingFunction | ||
, _repeatDelayTime | ||
, _reverseDelayTime | ||
, _delayTime | ||
@@ -227,3 +343,3 @@ , _yoyo | ||
this.emit('start', object); | ||
this.emit( 'start', object ); | ||
@@ -268,3 +384,3 @@ this._onStartCallbackFired = true; | ||
this.emit('update', object, elapsed); | ||
this.emit( 'update', object, elapsed ); | ||
@@ -297,3 +413,3 @@ if ( elapsed === 1 ) { | ||
this.emit('repeat', object, _reversed); | ||
this.emit( _reversed ? 'repeat' : 'reverse', object ); | ||
@@ -304,4 +420,6 @@ if ( _yoyo ) { | ||
if ( _repeatDelayTime ) { | ||
if ( _reversed && _repeatDelayTime ) { | ||
this._startTime = time + _repeatDelayTime; | ||
} else if ( !_reversed && _reverseDelayTime ) { | ||
this._startTime = time + _reverseDelayTime; | ||
} else { | ||
@@ -315,6 +433,8 @@ this._startTime = time + _delayTime; | ||
this.emit('complete', object); | ||
this.emit( 'complete', object ); | ||
_chainedTweens.map(tween => tween.start( _startTime + _duration)); | ||
_chainedTweens.map( tween => tween.start( _startTime + _duration ) ); | ||
this._repeat = this._r; | ||
return false; | ||
@@ -321,0 +441,0 @@ |
@@ -31,3 +31,3 @@ let ROOT = typeof(window) !== "undefined" ? window : typeof(global) !== "undefined" ? global : this; | ||
if ( ROOT.cancelAnimationFrame === undefined ) { | ||
if ( ROOT.cancelAnimationFrame === undefined && (ROOT.cancelAnimationFrame = ROOT.cancelRequestAnimationFrame) === undefined ) { | ||
let _caf; | ||
@@ -34,0 +34,0 @@ |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
330342
1660
0