es6-tween
Advanced tools
Comparing version 3.8.6 to 3.8.7
@@ -265,3 +265,3 @@ (function (global, factory) { | ||
if (sv[i] === undefined) { continue; } | ||
s[i] = ve.nodeType ? ve : ve.update ? ve : vs === ve ? null : isArray(ve) ? | ||
s[i] = ve && ve.nodeType ? ve : ve.update ? ve : vs === ve ? null : isArray(ve) ? | ||
isArray(vs) && ve.length === vs.length ? arrayTween(vs, ve, d) : parseInterpolatables(vs, ve) : isArray(vs) ? tweenThemTo(vs, ve) : typeof vs === 'object' ? | ||
@@ -367,2 +367,10 @@ objectTween(vs, ve, d) : typeof vs === 'string' ? | ||
/** | ||
* Adds ticker like event | ||
* @param {Function} fn callback | ||
* @memberof TWEEN | ||
* @example | ||
* TWEEN.onTick(time => console.log(time)) | ||
*/ | ||
var onTick = function (fn) { return _tweens.push(fn); }; | ||
/** | ||
* @returns {Array<Tween>} List of tweens in Array | ||
@@ -1247,3 +1255,3 @@ * @memberof TWEEN | ||
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state === null ? this._yoyo : state; | ||
this._easingReverse = _easingReverse || defaultEasing; | ||
this._easingReverse = _easingReverse || this._easingFunction; | ||
return this; | ||
@@ -1663,2 +1671,3 @@ }; | ||
exports.Interpolator = intertween$1; | ||
exports.onTick = onTick; | ||
exports.has = has; | ||
@@ -1665,0 +1674,0 @@ exports.get = get; |
@@ -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={})}(this,function(t){"use strict";var e,n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){!function(e,n){t.exports?t.exports=n():e.InterTween=n()}("undefined"!=typeof window?window:n,function(){function t(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}function e(t,e){var n,r,i;3===e.length&&(e=(n=e[0])+n+(r=e[1])+r+(i=e[2])+i);var o=parseInt(e,16);return n=o>>16&m,r=o>>8&m,i=o&m,"rgb("+n+","+r+","+i+")"}function n(t){return"string"==typeof t?t.replace(y,"").replace(_,","):t}function r(t,e){if("number"==typeof e)return e;var n=b[e.substr(0,2)],r=e.substr(2);if(1===n){var i=e[0]+r;return t+parseFloat(i)}return 2===n?t*+r:3===n?t/+r:4===n?t*(+r/100):e}function i(e){var n=T(e);return"string"==typeof n?n.match(d).map(t):e}function o(t,e,n){if(n=void 0!==n?n:1e4,!d.test(e))return e;var o=i(t),u=i(e),s=f(o,u,n);if(s)return s;s=null;for(var a=null,h=null,p=[],v=0,y=u.length;v<y;v++){var _=u[v],m=o[v];p[v]="string"==typeof _&&1===_.indexOf("=")?e:null,c.test(_)?(a=v+2,h=v+11):l.test(_)&&(a=v,h=v+9),u[v]=m===_?null:null!==p[v]?r(m,_):_}return function(t){var e="";for(v=0;v<y;v++){var i=o[v],s=u[v],f=p[v];e+="number"==typeof s?null!==a&&v>a&&v<h?i+(s-i)*t|0:((i+(s-i)*t)*n|0)/n:i,1===t&&null!==f&&(o[v]=s,u[v]=r(s,f))}return e}}function u(t,e){for(var n=[],r=0,i=t.length;r<i;r++){var u=t[r];n[r]=g(u)?a(u,e):"object"==typeof u?h(u,e):"string"==typeof u?o(u,e):u}return function(r){for(var i=0,o=n.length;i<o;i++)t[i]="function"==typeof n[i]?n[i](r):"number"==typeof n[i]?n[i]+(e-n[i])*r:n[i];return t}}function s(t,e){for(var n=[],r=0,i=e.length;r<i;r++){var o=e[r];n[r]=p(0===r?t:e[r-1],o)}var u=e[e.length-1];n.push(p(u,u));var s=n.length-1;return function(t){var e=t*s,r=Math.max(0,Math.floor(e)),i=e-r,o=n[r];return"function"==typeof o?o(i):o}}function a(t,e,n){n=void 0!==n?n:1e4;for(var i=t.slice(),f=[],p=Math.min(t.length,e.length),l=0;l<p;l++){var c=i[l],d=e[l];f[l]="string"==typeof d&&1===d.indexOf("=")?d:null,i[l]=d.nodeType||d.update?d.update:c===d?null:g(d)?g(c)&&d.length===c.length?a(c,d,n):s(c,d):g(c)?u(c,d):"object"==typeof c?h(c,d,n):"string"==typeof c?o(c,d,n):void 0!==c?c:d,e[l]=null!==f[l]?r(c,d):d}return function(o){for(var u=0;u<p;u++){var s=i[u],a=e[u],h=f[u];null!==s&&void 0!==s&&(t[u]="number"==typeof s?((s+(a-s)*o)*n|0)/n:"function"==typeof s?s(o):s.update?s.update(o):a&&a.update?a.update(o):a,h&&1===o&&(i[u]=a,e[u]=r(i[u],h)))}return t}}function f(t,e,n){if(n=void 0!==n?n:1e4,2===e.length&&2===t.length&&-1!==O.indexOf(e[1])){var i=+t[0],o=+e[0],u=e[1],s="string"==typeof e[0]&&1===e[0].indexOf("=")?e[0]:null;return s&&(o=r(i,o)),i===o&&e[0]===u?e:function(t){var e=((i+(o-i)*t)*n|0)/n+u;return s&&1===t&&(o=r(i=o,s)),e}}return!1}function h(t,e,n){n=void 0!==n?n:1e4;var i={},f={};for(var p in e){f[p]=t&&t[p];var l=f[p],c=e[p];i[p]="string"==typeof c&&1===c.indexOf("=")?c:null,void 0!==t[p]&&(f[p]=c.nodeType?c:c.update?c:l===c?null:g(c)?g(l)&&c.length===l.length?a(l,c,n):s(l,c):g(l)?u(l,c):"object"==typeof l?h(l,c,n):"string"==typeof l?o(l,c,n):void 0!==l?l:c,e[p]=null!==i[p]?r(l,c):c)}return function(o){for(var u in e){var s=f[u],a=e[u],h=i[u];null!==s&&void 0!==s&&(t[u]="number"==typeof s?((s+(a-s)*o)*n|0)/n:"function"==typeof s?s(o):s.update?s.update(o):a.update?a.update(o):a,h&&1===o&&(f[u]=a,e[u]=r(f[u],h)))}return t}}function p(t,e,n){n=void 0!==n?n:1e4;var i="string"==typeof e&&"number"==typeof t&&1===e.indexOf("=")?e:null;return i&&(e=r(t,i)),e.nodeType?e:t.nodeType?t:g(e)?g(t)&&t.length===e.length?a(t,e,n):s(t,e):g(t)?u(t,e):"object"==typeof e?h(t,e,n):"string"==typeof e?o(t,e,n):"function"==typeof e?e:function(o){var u="number"==typeof e?((t+(e-t)*o)*n|0)/n:t;return i&&1===o&&(e=r(t+=e,i)),u}}var l=/rgb/g,c=/argb/g,d=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,v=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,y=/\n|\r|\t/g,_=/, | ,| , /g,m=255,g=Array.isArray,b={"+=":1,"-=":1,"*=":2,"/=":3,"%=":4},T=function(t){return"string"!=typeof t?t:n(t).replace(v,e)},O=["px","pt","pc","deg","rad","turn","em","ex","cm","mm","dm","inch","in","rem","vw","vh","vmin","vmax","%"];return p})}),i=Object.create||function(t){return Object.assign({},t||{})},o=Object.assign||function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];for(var r=0,i=e.length;r<i;r++){var o=e[r];for(var u in o)t[u]=o[u]}return t},u="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,s=[],a=!1,f=!1,h=u.requestAnimationFrame||function(t){return u.setTimeout(t,16)},p=u.cancelAnimationFrame||function(t){return u.clearTimeout(t)},l=function(t){s.push(t),f&&!a&&(e=h(y),a=!0)},c=function(t){for(var e=0;e<s.length;e++)if(t===s[e])return s[e];return null},d=function(t){var e=s.indexOf(t);-1!==e&&s.splice(e,1)},v=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!==u.performance&&void 0!==u.performance.now)return u.performance.now.bind(u.performance);var t=u.performance&&u.performance.timing&&u.performance.timing.navigationStart?u.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),y=function(t,n){if(t=void 0!==t?t:v(),e=h(y),0===s.length)return p(e),a=!1,!1;for(var r=0;r<s.length;)s[r].update(t,n),r++;return!0},_={};if(u.document&&u.document.addEventListener){var m=0,g=0;u.document.addEventListener("visibilitychange",function(){if(document.hidden)g=v(),p(e),a=!1;else{m=v()-g;for(var t=0,n=s.length;t<n;t++)s[t]._startTime+=m;e=h(y),a=!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}}},T=function(){this.totalTime=0,this.labels=[],this.offsets=[]};T.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 u=t.substr(t.indexOf("=")-1,2),s=t.split(u);e=2===s.length?u+s[1]:null,t=s[0],o=i.indexOf(t)}if(-1!==o&&t){var a=r[o]||0;if("number"==typeof e)a=e;else if("string"==typeof e&&-1!==e.indexOf("=")){var f=e.charAt(0);e=Number(e.substr(2)),"+"===f||"-"===f?a+=parseFloat(f+e):"*"===f?a*=e:"/"===f?a/=e:"%"===f&&(a*=e/100)}return a}return"number"==typeof e?e:0},T.prototype.addLabel=function(t,e){return this.labels.push(t),this.offsets.push(this.parseLabel(t,e)),this},T.prototype.setLabel=function(t,e){var n=this.labels.indexOf(t);return-1!==n&&this.offsets.splice(n,1,this.parseLabel(t,e)),this},T.prototype.eraseLabel=function(t){var e=this.labels.indexOf(t);return-1!==e&&(this.labels.splice(e,1),this.offsets.splice(e,1)),this};var O=function(){this._events={}};O.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},O.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=[],u=arguments.length;u--;)o[u]=arguments[u];e.apply(n,o),r[t].splice(i,1)}),this},O.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},O.prototype.emit=function(t,e,n,r,i){var o=this._events[t];if(!o||!o.length)return this;for(var u=0,s=o.length;u<s;u++)o[u](e,n,r,i);return this};var w={},M=function(t,e){if(!t||!t.nodeType||!e)return e;var n=t.queueID||"queue_"+Math.round(1e3*Math.random()+Date.now());return t.queueID||(t.queueID=n),w[n]?(e&&(w[n]=o(w[n],e)),w[n]):(w[n]=e,w[n])};Object.create=i;var I=0,x=b.Linear.None,P=function(t){function e(e,n){t.call(this),this.id=I++,void 0===e||n||e.nodeType?void 0!==e&&(this.node=e,"object"==typeof n?n=this.object=M(e,n):this.object=n):(n=this.object=e,e=null);var r=this.isArr=Array.isArray(n);return this._valuesStart=r?[]:{},this._valuesEnd=null,this._valuesFunc={},this._duration=1e3,this._easingFunction=x,this._easingReverse=x,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._isFinite=!0,this._elapsed=0,this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.fromTo=function(t,n,r,i){void 0===i&&(i={}),i.quickRender=i.quickRender?i.quickRender:!r;var o=new e(t,n).to(r,i);return i.quickRender&&(o.render().update(o._startTime),o._rendered=!1,o._onStartCallbackFired=!1),o},e.to=function(t,n,r){return e.fromTo(t,null,n,r)},e.from=function(t,n,r){return e.fromTo(t,n,null,r)},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,d(this),this._pausedTime=v(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=v()-this._pausedTime,l(this),this._pausedTime=v(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this._startTime=v()+(t?0:this._delayTime),this._isPlaying||l(this),this.emit("restart",this.object)},e.prototype.seek=function(t,e){return this._startTime=v()+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,n){var r=this;if(void 0===e&&(e=1e3),this._valuesEnd=t,"number"==typeof e||"function"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var i in e)if("function"==typeof r[i]){var o=Array.isArray(e[i])?e[i]:[e[i]],u=o[0];void 0===u&&(u=null);var s=o[1];void 0===s&&(s=null);var a=o[2];void 0===a&&(a=null);var f=o[3];void 0===f&&(f=null),r[i](u,s,a,f)}return this},e.prototype.render=function(){var t=this;if(this._rendered)return this;var e=this,n=e._valuesEnd,i=e._valuesFunc,o=e._valuesStart,u=e.object,s=e.Renderer,a=e.node,f=e.InitialValues;a&&f&&(u?n||(n=this._valuesEnd=f(a,u)):u=this.object=M(a,f(a,n)));for(var h in n){var p=u&&u[h],l=n[h];if(_[h]){var c=_[h].prototype.update?new _[h](t,p,l,h,u):_[h](t,p,l,h,u);c&&(i[h]=c)}else u&&void 0!==u[h]&&("number"==typeof l&&"number"==typeof p?(o[h]=p,n[h]=l):i[h]=r(p,l))}return s&&this.node&&(this.__render=new s(this,u,n)),this},e.prototype.start=function(t){return this._startTime=void 0!==t?t:v(),this._startTime+=this._delayTime,l(this),this._isPlaying=!0,this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object,r=t._startTime,i=t._duration;return e?(this.update(r+i),d(this),this._isPlaying=!1,this.emit("stop",n)):this},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,e){return this._yoyo="function"==typeof t?t(this._yoyo):null===t?this._yoyo:t,this._easingReverse=e||x,this},e.prototype.easing=function(t){return this._easingFunction=t,this},e.prototype.reassignValues=function(){var t,e=this,n=e._valuesStart,r=e._valuesEnd,i=e.object,o=e.isArr;for(t in r){o&&(t=parseInt(t));var u=n[t],s=r[t];i[t]="function"==typeof s?s(0):u}return this},e.prototype.update=function(t,e){var n,r,i,o,u=this,s=u._onStartCallbackFired,a=u._easingFunction,f=u._easingReverse,h=u._repeat,p=u._repeatDelayTime,l=u._reverseDelayTime,c=u._yoyo,y=u._reversed,_=u._startTime,m=u._duration,g=u._valuesStart,b=u._valuesEnd,T=u._valuesFunc,O=u.object,w=u._isFinite,M=u._isPlaying,P=u.__render;if(t=void 0!==t?t:v(),!M||t<_)return!0;if(s||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",O),this._onStartCallbackFired=!0),n=(t-_)/m,n=n>1?1:n,n=y?1-n:n,o=y?f:a,!O)return!0;for(i in b){r=o[i]?o[i](n):"function"==typeof o?o(n):x(n);var j=g[i],F=b[i],L=T[i];L&&L.update?L.update(r,n):O[i]=L?L(r):"number"==typeof F?j+(F-j)*r:F}return P&&P.update(O,n),this.emit("update",O,n),!(1===n||y&&0===n)||(h?(w&&this._repeat--,c&&(this._reversed=!y),this.emit(c&&!y?"reverse":"repeat",O),this._startTime=!y&&p?t+p:y&&l?t+l:t,!0):(e||(this._isPlaying=!1,d(this),I--),this.emit("complete",O),this._repeat=this._r,!1))},e}(O),j=function(t){var e,n,r;for(r=t.length;r;r-=1)e=Math.floor(Math.random()*r),n=t[r-1],t[r-1]=t[e],t[e]=n;return t},F=0,L=function(t){function e(e){return t.call(this),this._duration=0,this._startTime=v(),this._tweens=[],this._elapsed=0,this._id=F++,this._defaultParams=e,this.position=new T,this.position.addLabel("afterLast",this._duration),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.mapTotal=function(t){return t.call(this,this._tweens),this},e.prototype.timingOrder=function(t){var e=t(this._tweens.map(function(t){return t._startTime}));return this._tweens.map(function(t,n){t._startTime=e[n]}),this},e.prototype.getTiming=function(t,e,n,r){if(void 0===r&&(r=0),"reverse"===t){var i=n.stagger,o=(i||0)*(e.length-1);return e.map(function(t,e){return o-(i||0)*e+r})}if("async"===t)return e.map(function(t){return r});if("sequence"===t||"delayed"===t){var u=n.stagger;return u||(u=(n.duration||1e3)/(e.length-1)),e.map(function(t,e){return u*e+r})}if("oneByOne"===t)return e.map(function(t){return n.duration});if("shuffle"===t){var s=n.stagger;return j(e.map(function(t,e){return(s||0)*e+r}))}var a=n.stagger;return e.map(function(t,e){return(a||0)*e+r})},e.prototype.fromTo=function(e,n,r,i){var o=this;if(Array.isArray(e)){this._defaultParams&&(i=Object.assign({},this._defaultParams,i));var u=i.label,s="number"==typeof u?u:this.position.parseLabel(void 0!==u?u:"afterLast",null),a=this.getTiming(i.mode,e,i,s);e.map(function(u,s){o.add(t.fromTo(u,"function"==typeof n?n(s,e.length):Object.assign({},n),"function"==typeof r?r(s,e.length):r,"function"==typeof i?i(s,e.length):i),a[s])})}return this.start()},e.prototype.from=function(t,e,n){return this.fromTo(t,e,null,n)},e.prototype.to=function(t,e,n){return this.fromTo(t,null,e,n)},e.prototype.addLabel=function(t,e){return this.position.addLabel(t,e),this},e.prototype.map=function(t){for(var e=this,n=0,r=this._tweens.length;n<r;n++){var i=e._tweens[n];t(i,n),e._duration=Math.max(e._duration,i._duration+i._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,u=i._duration;if(o)for(var s in o)"function"==typeof e[s]&&e[s](o[s]);var a="number"==typeof n?n:this.position.parseLabel(void 0!==n?n:"afterLast",null);return e._startTime=Math.max(this._startTime,e._delayTime),e._startTime+=a,e._isPlaying=!0,this._duration=Math.max(u,e._startTime+e._delayTime+e._duration),this._tweens.push(e),this.position.setLabel("afterLast",this._duration),this},e.prototype.restart=function(){return this._startTime+=v(),l(this),this.emit("restart")},e.prototype.easing=function(t){return this.map(function(e){return e.easing(t)})},e.prototype.interpolation=function(t){return this.map(function(e){return e.interpolation(t)})},e.prototype.update=function(t){var e=this,n=e._tweens,r=e._duration,i=e._repeatDelayTime,o=e._reverseDelayTime,u=e._startTime,s=e._reversed,a=e._yoyo,f=e._repeat,h=e._isFinite,p=e._elapsed;if(!e._isPlaying||t<u)return!0;var l=(t-u)/r;if(l=l>1?1:l,l=s?1-l:l,(l=(1e3*l|0)/1e3)===p)return!0;this._elapsed=l;for(var c=t-u,v=s?r-c:c,y=0;y<n.length;)n[y].update(v,!0),y++;if(this.emit("update",l,c),1===l||s&&0===l){if(f){for(h&&this._repeat--,this.emit(s?"reverse":"repeat"),a&&(this._reversed=!s,this.timingOrder(function(t){return t.reverse()})),this._startTime=!s&&i?t+i:s&&o?t+o:t;y<n.length;)n[y].reassignValues(),y++;return!0}return this.emit("complete"),this._repeat=this._r,d(this),this._isPlaying=!1,!1}return!0},e.prototype.elapsed=function(t){return void 0!==t?this.update(t*this._duration):this._elapsed},e}(P);t.Plugins=_,t.Interpolator=r,t.has=function(t){return null!==c(t)},t.get=c,t.getAll=function(){return s},t.removeAll=function(){s.length=0},t.remove=d,t.add=l,t.now=v,t.update=y,t.autoPlay=function(t){f=t},t.isRunning=function(){return a},t.Tween=P,t.Easing=b,t.Timeline=L,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN={})}(this,function(t){"use strict";var e,n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){!function(e,n){t.exports?t.exports=n():e.InterTween=n()}("undefined"!=typeof window?window:n,function(){function t(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}function e(t,e){var n,r,i;3===e.length&&(e=(n=e[0])+n+(r=e[1])+r+(i=e[2])+i);var o=parseInt(e,16);return n=o>>16&m,r=o>>8&m,i=o&m,"rgb("+n+","+r+","+i+")"}function n(t){return"string"==typeof t?t.replace(y,"").replace(_,","):t}function r(t,e){if("number"==typeof e)return e;var n=b[e.substr(0,2)],r=e.substr(2);if(1===n){var i=e[0]+r;return t+parseFloat(i)}return 2===n?t*+r:3===n?t/+r:4===n?t*(+r/100):e}function i(e){var n=T(e);return"string"==typeof n?n.match(d).map(t):e}function o(t,e,n){if(n=void 0!==n?n:1e4,!d.test(e))return e;var o=i(t),u=i(e),s=f(o,u,n);if(s)return s;s=null;for(var a=null,h=null,p=[],v=0,y=u.length;v<y;v++){var _=u[v],m=o[v];p[v]="string"==typeof _&&1===_.indexOf("=")?e:null,l.test(_)?(a=v+2,h=v+11):c.test(_)&&(a=v,h=v+9),u[v]=m===_?null:null!==p[v]?r(m,_):_}return function(t){var e="";for(v=0;v<y;v++){var i=o[v],s=u[v],f=p[v];e+="number"==typeof s?null!==a&&v>a&&v<h?i+(s-i)*t|0:((i+(s-i)*t)*n|0)/n:i,1===t&&null!==f&&(o[v]=s,u[v]=r(s,f))}return e}}function u(t,e){for(var n=[],r=0,i=t.length;r<i;r++){var u=t[r];n[r]=g(u)?a(u,e):"object"==typeof u?h(u,e):"string"==typeof u?o(u,e):u}return function(r){for(var i=0,o=n.length;i<o;i++)t[i]="function"==typeof n[i]?n[i](r):"number"==typeof n[i]?n[i]+(e-n[i])*r:n[i];return t}}function s(t,e){for(var n=[],r=0,i=e.length;r<i;r++){var o=e[r];n[r]=p(0===r?t:e[r-1],o)}var u=e[e.length-1];n.push(p(u,u));var s=n.length-1;return function(t){var e=t*s,r=Math.max(0,Math.floor(e)),i=e-r,o=n[r];return"function"==typeof o?o(i):o}}function a(t,e,n){n=void 0!==n?n:1e4;for(var i=t.slice(),f=[],p=Math.min(t.length,e.length),c=0;c<p;c++){var l=i[c],d=e[c];f[c]="string"==typeof d&&1===d.indexOf("=")?d:null,i[c]=d.nodeType||d.update?d.update:l===d?null:g(d)?g(l)&&d.length===l.length?a(l,d,n):s(l,d):g(l)?u(l,d):"object"==typeof l?h(l,d,n):"string"==typeof l?o(l,d,n):void 0!==l?l:d,e[c]=null!==f[c]?r(l,d):d}return function(o){for(var u=0;u<p;u++){var s=i[u],a=e[u],h=f[u];null!==s&&void 0!==s&&(t[u]="number"==typeof s?((s+(a-s)*o)*n|0)/n:"function"==typeof s?s(o):s.update?s.update(o):a&&a.update?a.update(o):a,h&&1===o&&(i[u]=a,e[u]=r(i[u],h)))}return t}}function f(t,e,n){if(n=void 0!==n?n:1e4,2===e.length&&2===t.length&&-1!==O.indexOf(e[1])){var i=+t[0],o=+e[0],u=e[1],s="string"==typeof e[0]&&1===e[0].indexOf("=")?e[0]:null;return s&&(o=r(i,o)),i===o&&e[0]===u?e:function(t){var e=((i+(o-i)*t)*n|0)/n+u;return s&&1===t&&(o=r(i=o,s)),e}}return!1}function h(t,e,n){n=void 0!==n?n:1e4;var i={},f={};for(var p in e){f[p]=t&&t[p];var c=f[p],l=e[p];i[p]="string"==typeof l&&1===l.indexOf("=")?l:null,void 0!==t[p]&&(f[p]=l&&l.nodeType?l:l.update?l:c===l?null:g(l)?g(c)&&l.length===c.length?a(c,l,n):s(c,l):g(c)?u(c,l):"object"==typeof c?h(c,l,n):"string"==typeof c?o(c,l,n):void 0!==c?c:l,e[p]=null!==i[p]?r(c,l):l)}return function(o){for(var u in e){var s=f[u],a=e[u],h=i[u];null!==s&&void 0!==s&&(t[u]="number"==typeof s?((s+(a-s)*o)*n|0)/n:"function"==typeof s?s(o):s.update?s.update(o):a.update?a.update(o):a,h&&1===o&&(f[u]=a,e[u]=r(f[u],h)))}return t}}function p(t,e,n){n=void 0!==n?n:1e4;var i="string"==typeof e&&"number"==typeof t&&1===e.indexOf("=")?e:null;return i&&(e=r(t,i)),e.nodeType?e:t.nodeType?t:g(e)?g(t)&&t.length===e.length?a(t,e,n):s(t,e):g(t)?u(t,e):"object"==typeof e?h(t,e,n):"string"==typeof e?o(t,e,n):"function"==typeof e?e:function(o){var u="number"==typeof e?((t+(e-t)*o)*n|0)/n:t;return i&&1===o&&(e=r(t+=e,i)),u}}var c=/rgb/g,l=/argb/g,d=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,v=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,y=/\n|\r|\t/g,_=/, | ,| , /g,m=255,g=Array.isArray,b={"+=":1,"-=":1,"*=":2,"/=":3,"%=":4},T=function(t){return"string"!=typeof t?t:n(t).replace(v,e)},O=["px","pt","pc","deg","rad","turn","em","ex","cm","mm","dm","inch","in","rem","vw","vh","vmin","vmax","%"];return p})}),i=Object.create||function(t){return Object.assign({},t||{})},o=Object.assign||function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];for(var r=0,i=e.length;r<i;r++){var o=e[r];for(var u in o)t[u]=o[u]}return t},u="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,s=[],a=!1,f=!1,h=u.requestAnimationFrame||function(t){return u.setTimeout(t,16)},p=u.cancelAnimationFrame||function(t){return u.clearTimeout(t)},c=function(t){s.push(t),f&&!a&&(e=h(y),a=!0)},l=function(t){for(var e=0;e<s.length;e++)if(t===s[e])return s[e];return null},d=function(t){var e=s.indexOf(t);-1!==e&&s.splice(e,1)},v=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!==u.performance&&void 0!==u.performance.now)return u.performance.now.bind(u.performance);var t=u.performance&&u.performance.timing&&u.performance.timing.navigationStart?u.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),y=function(t,n){if(t=void 0!==t?t:v(),e=h(y),0===s.length)return p(e),a=!1,!1;for(var r=0;r<s.length;)s[r].update(t,n),r++;return!0},_={};if(u.document&&u.document.addEventListener){var m=0,g=0;u.document.addEventListener("visibilitychange",function(){if(document.hidden)g=v(),p(e),a=!1;else{m=v()-g;for(var t=0,n=s.length;t<n;t++)s[t]._startTime+=m;e=h(y),a=!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}}},T=function(){this.totalTime=0,this.labels=[],this.offsets=[]};T.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 u=t.substr(t.indexOf("=")-1,2),s=t.split(u);e=2===s.length?u+s[1]:null,t=s[0],o=i.indexOf(t)}if(-1!==o&&t){var a=r[o]||0;if("number"==typeof e)a=e;else if("string"==typeof e&&-1!==e.indexOf("=")){var f=e.charAt(0);e=Number(e.substr(2)),"+"===f||"-"===f?a+=parseFloat(f+e):"*"===f?a*=e:"/"===f?a/=e:"%"===f&&(a*=e/100)}return a}return"number"==typeof e?e:0},T.prototype.addLabel=function(t,e){return this.labels.push(t),this.offsets.push(this.parseLabel(t,e)),this},T.prototype.setLabel=function(t,e){var n=this.labels.indexOf(t);return-1!==n&&this.offsets.splice(n,1,this.parseLabel(t,e)),this},T.prototype.eraseLabel=function(t){var e=this.labels.indexOf(t);return-1!==e&&(this.labels.splice(e,1),this.offsets.splice(e,1)),this};var O=function(){this._events={}};O.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},O.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=[],u=arguments.length;u--;)o[u]=arguments[u];e.apply(n,o),r[t].splice(i,1)}),this},O.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},O.prototype.emit=function(t,e,n,r,i){var o=this._events[t];if(!o||!o.length)return this;for(var u=0,s=o.length;u<s;u++)o[u](e,n,r,i);return this};var w={},M=function(t,e){if(!t||!t.nodeType||!e)return e;var n=t.queueID||"queue_"+Math.round(1e3*Math.random()+Date.now());return t.queueID||(t.queueID=n),w[n]?(e&&(w[n]=o(w[n],e)),w[n]):(w[n]=e,w[n])};Object.create=i;var I=0,x=b.Linear.None,P=function(t){function e(e,n){t.call(this),this.id=I++,void 0===e||n||e.nodeType?void 0!==e&&(this.node=e,"object"==typeof n?n=this.object=M(e,n):this.object=n):(n=this.object=e,e=null);var r=this.isArr=Array.isArray(n);return this._valuesStart=r?[]:{},this._valuesEnd=null,this._valuesFunc={},this._duration=1e3,this._easingFunction=x,this._easingReverse=x,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._isFinite=!0,this._elapsed=0,this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.fromTo=function(t,n,r,i){void 0===i&&(i={}),i.quickRender=i.quickRender?i.quickRender:!r;var o=new e(t,n).to(r,i);return i.quickRender&&(o.render().update(o._startTime),o._rendered=!1,o._onStartCallbackFired=!1),o},e.to=function(t,n,r){return e.fromTo(t,null,n,r)},e.from=function(t,n,r){return e.fromTo(t,n,null,r)},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,d(this),this._pausedTime=v(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=v()-this._pausedTime,c(this),this._pausedTime=v(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this._startTime=v()+(t?0:this._delayTime),this._isPlaying||c(this),this.emit("restart",this.object)},e.prototype.seek=function(t,e){return this._startTime=v()+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,n){var r=this;if(void 0===e&&(e=1e3),this._valuesEnd=t,"number"==typeof e||"function"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var i in e)if("function"==typeof r[i]){var o=Array.isArray(e[i])?e[i]:[e[i]],u=o[0];void 0===u&&(u=null);var s=o[1];void 0===s&&(s=null);var a=o[2];void 0===a&&(a=null);var f=o[3];void 0===f&&(f=null),r[i](u,s,a,f)}return this},e.prototype.render=function(){var t=this;if(this._rendered)return this;var e=this,n=e._valuesEnd,i=e._valuesFunc,o=e._valuesStart,u=e.object,s=e.Renderer,a=e.node,f=e.InitialValues;a&&f&&(u?n||(n=this._valuesEnd=f(a,u)):u=this.object=M(a,f(a,n)));for(var h in n){var p=u&&u[h],c=n[h];if(_[h]){var l=_[h].prototype.update?new _[h](t,p,c,h,u):_[h](t,p,c,h,u);l&&(i[h]=l)}else u&&void 0!==u[h]&&("number"==typeof c&&"number"==typeof p?(o[h]=p,n[h]=c):i[h]=r(p,c))}return s&&this.node&&(this.__render=new s(this,u,n)),this},e.prototype.start=function(t){return this._startTime=void 0!==t?t:v(),this._startTime+=this._delayTime,c(this),this._isPlaying=!0,this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object,r=t._startTime,i=t._duration;return e?(this.update(r+i),d(this),this._isPlaying=!1,this.emit("stop",n)):this},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,e){return this._yoyo="function"==typeof t?t(this._yoyo):null===t?this._yoyo:t,this._easingReverse=e||this._easingFunction,this},e.prototype.easing=function(t){return this._easingFunction=t,this},e.prototype.reassignValues=function(){var t,e=this,n=e._valuesStart,r=e._valuesEnd,i=e.object,o=e.isArr;for(t in r){o&&(t=parseInt(t));var u=n[t],s=r[t];i[t]="function"==typeof s?s(0):u}return this},e.prototype.update=function(t,e){var n,r,i,o,u=this,s=u._onStartCallbackFired,a=u._easingFunction,f=u._easingReverse,h=u._repeat,p=u._repeatDelayTime,c=u._reverseDelayTime,l=u._yoyo,y=u._reversed,_=u._startTime,m=u._duration,g=u._valuesStart,b=u._valuesEnd,T=u._valuesFunc,O=u.object,w=u._isFinite,M=u._isPlaying,P=u.__render;if(t=void 0!==t?t:v(),!M||t<_)return!0;if(s||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",O),this._onStartCallbackFired=!0),n=(t-_)/m,n=n>1?1:n,n=y?1-n:n,o=y?f:a,!O)return!0;for(i in b){r=o[i]?o[i](n):"function"==typeof o?o(n):x(n);var j=g[i],F=b[i],L=T[i];L&&L.update?L.update(r,n):O[i]=L?L(r):"number"==typeof F?j+(F-j)*r:F}return P&&P.update(O,n),this.emit("update",O,n),!(1===n||y&&0===n)||(h?(w&&this._repeat--,l&&(this._reversed=!y),this.emit(l&&!y?"reverse":"repeat",O),this._startTime=!y&&p?t+p:y&&c?t+c:t,!0):(e||(this._isPlaying=!1,d(this),I--),this.emit("complete",O),this._repeat=this._r,!1))},e}(O),j=function(t){var e,n,r;for(r=t.length;r;r-=1)e=Math.floor(Math.random()*r),n=t[r-1],t[r-1]=t[e],t[e]=n;return t},F=0,L=function(t){function e(e){return t.call(this),this._duration=0,this._startTime=v(),this._tweens=[],this._elapsed=0,this._id=F++,this._defaultParams=e,this.position=new T,this.position.addLabel("afterLast",this._duration),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.mapTotal=function(t){return t.call(this,this._tweens),this},e.prototype.timingOrder=function(t){var e=t(this._tweens.map(function(t){return t._startTime}));return this._tweens.map(function(t,n){t._startTime=e[n]}),this},e.prototype.getTiming=function(t,e,n,r){if(void 0===r&&(r=0),"reverse"===t){var i=n.stagger,o=(i||0)*(e.length-1);return e.map(function(t,e){return o-(i||0)*e+r})}if("async"===t)return e.map(function(t){return r});if("sequence"===t||"delayed"===t){var u=n.stagger;return u||(u=(n.duration||1e3)/(e.length-1)),e.map(function(t,e){return u*e+r})}if("oneByOne"===t)return e.map(function(t){return n.duration});if("shuffle"===t){var s=n.stagger;return j(e.map(function(t,e){return(s||0)*e+r}))}var a=n.stagger;return e.map(function(t,e){return(a||0)*e+r})},e.prototype.fromTo=function(e,n,r,i){var o=this;if(Array.isArray(e)){this._defaultParams&&(i=Object.assign({},this._defaultParams,i));var u=i.label,s="number"==typeof u?u:this.position.parseLabel(void 0!==u?u:"afterLast",null),a=this.getTiming(i.mode,e,i,s);e.map(function(u,s){o.add(t.fromTo(u,"function"==typeof n?n(s,e.length):Object.assign({},n),"function"==typeof r?r(s,e.length):r,"function"==typeof i?i(s,e.length):i),a[s])})}return this.start()},e.prototype.from=function(t,e,n){return this.fromTo(t,e,null,n)},e.prototype.to=function(t,e,n){return this.fromTo(t,null,e,n)},e.prototype.addLabel=function(t,e){return this.position.addLabel(t,e),this},e.prototype.map=function(t){for(var e=this,n=0,r=this._tweens.length;n<r;n++){var i=e._tweens[n];t(i,n),e._duration=Math.max(e._duration,i._duration+i._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,u=i._duration;if(o)for(var s in o)"function"==typeof e[s]&&e[s](o[s]);var a="number"==typeof n?n:this.position.parseLabel(void 0!==n?n:"afterLast",null);return e._startTime=Math.max(this._startTime,e._delayTime),e._startTime+=a,e._isPlaying=!0,this._duration=Math.max(u,e._startTime+e._delayTime+e._duration),this._tweens.push(e),this.position.setLabel("afterLast",this._duration),this},e.prototype.restart=function(){return this._startTime+=v(),c(this),this.emit("restart")},e.prototype.easing=function(t){return this.map(function(e){return e.easing(t)})},e.prototype.interpolation=function(t){return this.map(function(e){return e.interpolation(t)})},e.prototype.update=function(t){var e=this,n=e._tweens,r=e._duration,i=e._repeatDelayTime,o=e._reverseDelayTime,u=e._startTime,s=e._reversed,a=e._yoyo,f=e._repeat,h=e._isFinite,p=e._elapsed;if(!e._isPlaying||t<u)return!0;var c=(t-u)/r;if(c=c>1?1:c,c=s?1-c:c,(c=(1e3*c|0)/1e3)===p)return!0;this._elapsed=c;for(var l=t-u,v=s?r-l:l,y=0;y<n.length;)n[y].update(v,!0),y++;if(this.emit("update",c,l),1===c||s&&0===c){if(f){for(h&&this._repeat--,this.emit(s?"reverse":"repeat"),a&&(this._reversed=!s,this.timingOrder(function(t){return t.reverse()})),this._startTime=!s&&i?t+i:s&&o?t+o:t;y<n.length;)n[y].reassignValues(),y++;return!0}return this.emit("complete"),this._repeat=this._r,d(this),this._isPlaying=!1,!1}return!0},e.prototype.elapsed=function(t){return void 0!==t?this.update(t*this._duration):this._elapsed},e}(P);t.Plugins=_,t.Interpolator=r,t.onTick=function(t){return s.push(t)},t.has=function(t){return null!==l(t)},t.get=l,t.getAll=function(){return s},t.removeAll=function(){s.length=0},t.remove=d,t.add=c,t.now=v,t.update=y,t.autoPlay=function(t){f=t},t.isRunning=function(){return a},t.Tween=P,t.Easing=b,t.Timeline=L,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=full/Tween.min.js.map | ||
//# sourceMappingURL=Tween.min.js.map |
@@ -47,2 +47,10 @@ (function (global, factory) { | ||
/** | ||
* Adds ticker like event | ||
* @param {Function} fn callback | ||
* @memberof TWEEN | ||
* @example | ||
* TWEEN.onTick(time => console.log(time)) | ||
*/ | ||
var onTick = function (fn) { return _tweens.push(fn); }; | ||
/** | ||
* @returns {Array<Tween>} List of tweens in Array | ||
@@ -888,2 +896,3 @@ * @memberof TWEEN | ||
exports.Plugins = Plugins; | ||
exports.onTick = onTick; | ||
exports.has = has; | ||
@@ -890,0 +899,0 @@ exports.get = get; |
@@ -1,3 +0,3 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.TWEEN={})}(this,function(t){"use strict";var n,e="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,i=[],r=!1,o=!1,u=e.requestAnimationFrame||function(t){return e.setTimeout(t,16)},a=e.cancelAnimationFrame||function(t){return e.clearTimeout(t)},s=function(t){i.push(t),o&&!r&&(n=u(l),r=!0)},f=function(t){for(var n=0;n<i.length;n++)if(t===i[n])return i[n];return null},c=function(t){var n=i.indexOf(t);-1!==n&&i.splice(n,1)},h=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!==e.performance&&void 0!==e.performance.now)return e.performance.now.bind(e.performance);var t=e.performance&&e.performance.timing&&e.performance.timing.navigationStart?e.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),l=function(t,e){if(t=void 0!==t?t:h(),n=u(l),0===i.length)return a(n),r=!1,!1;for(var o=0;o<i.length;)i[o].update(t,e),o++;return!0},p={};if(e.document&&e.document.addEventListener){var _=0,y=0;e.document.addEventListener("visibilitychange",function(){if(document.hidden)y=h(),a(n),r=!1;else{_=h()-y;for(var t=0,e=i.length;t<e;t++)i[t]._startTime+=_;n=u(l),r=!0}return!0})}var d={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 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?t*t*((n+1)*t-n)*.5:.5*((t-=2)*t*((n+1)*t+n)+2)}},Bounce:{In:function(t){return 1-d.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*d.Bounce.In(2*t):.5*d.Bounce.Out(2*t-1)+.5}}},v={Linear:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.Linear;return n<0?o(t[0],t[1],i):n>1?o(t[e],t[e-1],e-i):o(t[r],t[r+1>e?e:r+1],i-r)},Bezier:function(t,n){for(var e=0,i=t.length-1,r=Math.pow,o=v.Utils.Bernstein,u=0;u<=i;u++)e+=r(1-n,i-u)*r(n,u)*t[u]*o(i,u);return e},CatmullRom:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.CatmullRom;return t[0]===t[e]?(n<0&&(r=Math.floor(i=e*(1+n))),o(t[(r-1+e)%e],t[r],t[(r+1)%e],t[(r+2)%e],i-r)):n<0?t[0]-(o(t[0],t[0],t[1],t[1],-i)-t[0]):n>1?t[e]-(o(t[e],t[e],t[e-1],t[e-1],i-e)-t[e]):o(t[r?r-1:0],t[r],t[e<r+1?e:r+1],t[e<r+2?e:r+2],i-r)},Utils:{Linear:function(t,n,e){return"function"==typeof t?t(e):(n-t)*e+t},Bernstein:function(t,n){var e=v.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;return(2*n-2*e+o+u)*(r*a)+(-3*n+3*e-2*o-u)*a+o*r+n}}},m=0,g=function(t){return this.id=m++,this.object=t,this._valuesStart={},this._valuesEnd=null,this._valuesStartRepeat={},this._duration=1e3,this._easingFunction=d.Linear.None,this._interpolationFunction=v.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._isFinite=!0,this._onStartCallback=null,this._onUpdateCallback=null,this._onCompleteCallback=null,this};g.prototype.onStart=function(t){return this._onStartCallback=t,this},g.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},g.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},g.prototype.isPlaying=function(){return this._isPlaying},g.prototype.isStarted=function(){return this._onStartCallbackFired},g.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,c(this),this._pausedTime=h(),this):this},g.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=h()-this._pausedTime,s(this),this._pausedTime=h(),this)},g.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},g.prototype.to=function(t,n){return void 0===n&&(n=1e3),this._valuesEnd=t,this._duration=n,this},g.prototype.start=function(t){this._startTime=void 0!==t?t:h(),this._startTime+=this._delayTime;var n=this,e=n._valuesEnd,i=n._valuesStartRepeat,r=n._valuesStart,o=n._interpolationFunction,u=n.object;for(var a in e)!function(t){var n=u[t],a=e[t];if(u&&void 0!==u[t]){var s=u[t];if("number"==typeof n){if("string"==typeof a)i[t]=a,a=n+parseFloat(a);else if(Array.isArray(a)){a.unshift(n);var f=a;a=function(t){return o(f,t)}}}else if("object"==typeof a)if(Array.isArray(a)){var c=a,h=n.map(function(t){return t}),l=void 0,p=a.length;a=function(t){for(l=0;l<p;l++)s[l]="number"==typeof h[l]?h[l]+(c[l]-h[l])*t:c[l];return s}}else{var _=a,y={};for(var d in n)y[d]=n[d];a=function(t){for(var n in a)s[n]="number"==typeof y[n]?y[n]+(_[n]-y[n])*t:_[n];return s}}r[t]=n,e[t]=a}}(a);return s(this),this._isPlaying=!0,this},g.prototype.stop=function(){var t=this,n=t._isPlaying,e=t._startTime,i=t._duration;return n?(this.update(e+i),c(this),this._isPlaying=!1,this):this},g.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},g.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},g.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},g.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},g.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},g.prototype.easing=function(t){return"function"==typeof t&&(this._easingFunction=t),this},g.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},g.prototype.reassignValues=function(){var t=this,n=t._valuesStart,e=t._valuesEnd,i=t.object;for(var r in e){var o=n[r];i[r]=o}return this},g.prototype.update=function(t,n){var e,i,r,o=this,u=o._onStartCallbackFired,a=o._easingFunction,s=o._repeat,f=o._repeatDelayTime,l=o._reverseDelayTime,p=o._yoyo,_=o._reversed,y=o._startTime,d=o._duration,v=o._valuesStart,g=o._valuesEnd,M=o._valuesStartRepeat,b=o.object,I=o._isFinite,T=o._isPlaying,O=o._onStartCallback,C=o._onUpdateCallback,P=o._onCompleteCallback;if(t=void 0!==t?t:h(),!T||t<y)return!0;u||(O&&O(b),this._onStartCallbackFired=!0),e=(e=(t-y)/d)>1?1:e,i=a(e=_?1-e:e);for(r in g){var F=v[r],w=g[r];void 0!==F&&("function"==typeof w?b[r]=w(i):"number"==typeof w&&(b[r]=F+(w-F)*i))}if(C&&C(b,e),1===e||_&&0===e){if(s){if(I&&this._repeat--,!_)for(r in M)v[r]=g[r],g[r]+=parseFloat(M[r]);return p&&(this._reversed=!_),this._startTime=!_&&f?t+f:_&&l?t+l:t,!0}return n||c(this),this._isPlaying=!1,P&&P(),this._repeat=this._r,m--,!1}return!0},t.Plugins=p,t.has=function(t){return null!==f(t)},t.get=f,t.getAll=function(){return i},t.removeAll=function(){i.length=0},t.remove=c,t.add=s,t.now=h,t.update=l,t.autoPlay=function(t){o=t},t.isRunning=function(){return r},t.Tween=g,t.Easing=d,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.TWEEN={})}(this,function(t){"use strict";var n,e="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,i=[],r=!1,o=!1,u=e.requestAnimationFrame||function(t){return e.setTimeout(t,16)},a=e.cancelAnimationFrame||function(t){return e.clearTimeout(t)},s=function(t){i.push(t),o&&!r&&(n=u(l),r=!0)},f=function(t){for(var n=0;n<i.length;n++)if(t===i[n])return i[n];return null},c=function(t){var n=i.indexOf(t);-1!==n&&i.splice(n,1)},h=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!==e.performance&&void 0!==e.performance.now)return e.performance.now.bind(e.performance);var t=e.performance&&e.performance.timing&&e.performance.timing.navigationStart?e.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),l=function(t,e){if(t=void 0!==t?t:h(),n=u(l),0===i.length)return a(n),r=!1,!1;for(var o=0;o<i.length;)i[o].update(t,e),o++;return!0},p={};if(e.document&&e.document.addEventListener){var _=0,y=0;e.document.addEventListener("visibilitychange",function(){if(document.hidden)y=h(),a(n),r=!1;else{_=h()-y;for(var t=0,e=i.length;t<e;t++)i[t]._startTime+=_;n=u(l),r=!0}return!0})}var d={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 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?t*t*((n+1)*t-n)*.5:.5*((t-=2)*t*((n+1)*t+n)+2)}},Bounce:{In:function(t){return 1-d.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*d.Bounce.In(2*t):.5*d.Bounce.Out(2*t-1)+.5}}},v={Linear:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.Linear;return n<0?o(t[0],t[1],i):n>1?o(t[e],t[e-1],e-i):o(t[r],t[r+1>e?e:r+1],i-r)},Bezier:function(t,n){for(var e=0,i=t.length-1,r=Math.pow,o=v.Utils.Bernstein,u=0;u<=i;u++)e+=r(1-n,i-u)*r(n,u)*t[u]*o(i,u);return e},CatmullRom:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=v.Utils.CatmullRom;return t[0]===t[e]?(n<0&&(r=Math.floor(i=e*(1+n))),o(t[(r-1+e)%e],t[r],t[(r+1)%e],t[(r+2)%e],i-r)):n<0?t[0]-(o(t[0],t[0],t[1],t[1],-i)-t[0]):n>1?t[e]-(o(t[e],t[e],t[e-1],t[e-1],i-e)-t[e]):o(t[r?r-1:0],t[r],t[e<r+1?e:r+1],t[e<r+2?e:r+2],i-r)},Utils:{Linear:function(t,n,e){return"function"==typeof t?t(e):(n-t)*e+t},Bernstein:function(t,n){var e=v.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;return(2*n-2*e+o+u)*(r*a)+(-3*n+3*e-2*o-u)*a+o*r+n}}},m=0,g=function(t){return this.id=m++,this.object=t,this._valuesStart={},this._valuesEnd=null,this._valuesStartRepeat={},this._duration=1e3,this._easingFunction=d.Linear.None,this._interpolationFunction=v.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._isFinite=!0,this._onStartCallback=null,this._onUpdateCallback=null,this._onCompleteCallback=null,this};g.prototype.onStart=function(t){return this._onStartCallback=t,this},g.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},g.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},g.prototype.isPlaying=function(){return this._isPlaying},g.prototype.isStarted=function(){return this._onStartCallbackFired},g.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,c(this),this._pausedTime=h(),this):this},g.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=h()-this._pausedTime,s(this),this._pausedTime=h(),this)},g.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},g.prototype.to=function(t,n){return void 0===n&&(n=1e3),this._valuesEnd=t,this._duration=n,this},g.prototype.start=function(t){this._startTime=void 0!==t?t:h(),this._startTime+=this._delayTime;var n=this,e=n._valuesEnd,i=n._valuesStartRepeat,r=n._valuesStart,o=n._interpolationFunction,u=n.object;for(var a in e)!function(t){var n=u[t],a=e[t];if(u&&void 0!==u[t]){var s=u[t];if("number"==typeof n){if("string"==typeof a)i[t]=a,a=n+parseFloat(a);else if(Array.isArray(a)){a.unshift(n);var f=a;a=function(t){return o(f,t)}}}else if("object"==typeof a)if(Array.isArray(a)){var c=a,h=n.map(function(t){return t}),l=void 0,p=a.length;a=function(t){for(l=0;l<p;l++)s[l]="number"==typeof h[l]?h[l]+(c[l]-h[l])*t:c[l];return s}}else{var _=a,y={};for(var d in n)y[d]=n[d];a=function(t){for(var n in a)s[n]="number"==typeof y[n]?y[n]+(_[n]-y[n])*t:_[n];return s}}r[t]=n,e[t]=a}}(a);return s(this),this._isPlaying=!0,this},g.prototype.stop=function(){var t=this,n=t._isPlaying,e=t._startTime,i=t._duration;return n?(this.update(e+i),c(this),this._isPlaying=!1,this):this},g.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},g.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},g.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},g.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},g.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},g.prototype.easing=function(t){return"function"==typeof t&&(this._easingFunction=t),this},g.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},g.prototype.reassignValues=function(){var t=this,n=t._valuesStart,e=t._valuesEnd,i=t.object;for(var r in e){var o=n[r];i[r]=o}return this},g.prototype.update=function(t,n){var e,i,r,o=this,u=o._onStartCallbackFired,a=o._easingFunction,s=o._repeat,f=o._repeatDelayTime,l=o._reverseDelayTime,p=o._yoyo,_=o._reversed,y=o._startTime,d=o._duration,v=o._valuesStart,g=o._valuesEnd,M=o._valuesStartRepeat,b=o.object,I=o._isFinite,T=o._isPlaying,O=o._onStartCallback,C=o._onUpdateCallback,P=o._onCompleteCallback;if(t=void 0!==t?t:h(),!T||t<y)return!0;u||(O&&O(b),this._onStartCallbackFired=!0),e=(e=(t-y)/d)>1?1:e,i=a(e=_?1-e:e);for(r in g){var F=v[r],w=g[r];void 0!==F&&("function"==typeof w?b[r]=w(i):"number"==typeof w&&(b[r]=F+(w-F)*i))}if(C&&C(b,e),1===e||_&&0===e){if(s){if(I&&this._repeat--,!_)for(r in M)v[r]=g[r],g[r]+=parseFloat(M[r]);return p&&(this._reversed=!_),this._startTime=!_&&f?t+f:_&&l?t+l:t,!0}return n||c(this),this._isPlaying=!1,P&&P(),this._repeat=this._r,m--,!1}return!0},t.Plugins=p,t.onTick=function(t){return i.push(t)},t.has=function(t){return null!==f(t)},t.get=f,t.getAll=function(){return i},t.removeAll=function(){i.length=0},t.remove=c,t.add=s,t.now=h,t.update=l,t.autoPlay=function(t){o=t},t.isRunning=function(){return r},t.Tween=g,t.Easing=d,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=lite/Tween.min.js.map | ||
//# sourceMappingURL=Tween.min.js.map |
{ | ||
"name": "es6-tween", | ||
"version": "3.8.6", | ||
"version": "3.8.7", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -25,5 +25,5 @@ "browser": "full/Tween.min.js", | ||
"test": "npm run lint && ava --verbose", | ||
"prepublish": "npm run prepare && npm run test && npm run doc-md", | ||
"doc": "node_modules/.bin/jsdoc --readme README.md --configure jsdoc.json --verbose", | ||
"doc-md": "jsdoc2md src/** > API.md" | ||
"prepublish": "npm run prepare && npm run test && npm run doc && npm run doc-md", | ||
"doc": "tsc && jsdoc --readme README.md --configure jsdoc.json --verbose", | ||
"doc-md": "tsc && jsdoc2md src/** > API.md" | ||
}, | ||
@@ -30,0 +30,0 @@ "repository": { |
@@ -7,3 +7,3 @@ # es6-tween | ||
[![gzipsize](http://img.badgesize.io/https://unpkg.com/es6-tween?compression=gzip&cache=false)](http://unpkg.com/es6-tween) | ||
[![size-lite](http://img.badgesize.io/https://unpkg.com/es6-tween/lite/Tween.min.js?label=lite%20size)](http://unpkg.com/es6-tween/lite/Tween.min.js) | ||
[![size-lite](http://img.badgesize.io/https://unpkg.com/es6-tween/lite/Tween.min.js?label=lite%20size&cache=false)](http://unpkg.com/es6-tween/lite/Tween.min.js) | ||
[![gzipsize-lite](http://img.badgesize.io/https://unpkg.com/es6-tween/lite/Tween.min.js?compression=gzip&cache=false&label=lite%20gzip%20size)](http://unpkg.com/es6-tween/lite/Tween.min.js) | ||
@@ -130,3 +130,3 @@ [![CDNJS](https://img.shields.io/cdnjs/v/es6-tween.svg)](https://cdnjs.com/libraries/es6-tween) | ||
// Lite | ||
import { Easing, Interpolation, Tween, autoPlay } from 'es6-tween/src/Tween.Lite' | ||
import { Easing, Interpolation, Tween, autoPlay } from 'es6-tween/src/index.lite' | ||
``` | ||
@@ -144,3 +144,3 @@ | ||
// Lite | ||
import { Easing, Interpolation, Tween, autoPlay } from 'es6-tween/src/Tween.Lite' | ||
import { Easing, Interpolation, Tween, autoPlay } from 'es6-tween/src/index.lite' | ||
@@ -147,0 +147,0 @@ |
@@ -12,2 +12,10 @@ /** | ||
/** | ||
* Adds ticker like event | ||
* @param {Function} fn callback | ||
* @memberof TWEEN | ||
* @example | ||
* TWEEN.onTick(time => console.log(time)) | ||
*/ | ||
declare const onTick: (fn: any) => number; | ||
/** | ||
* @returns {Array<Tween>} List of tweens in Array | ||
@@ -84,2 +92,2 @@ * @memberof TWEEN | ||
declare const Plugins: Object; | ||
export { Plugins, get, has, getAll, removeAll, remove, add, now, update, autoPlay, isRunning }; | ||
export { Plugins, get, has, getAll, removeAll, remove, add, now, update, autoPlay, onTick, isRunning }; |
177
src/core.js
/* global process */ | ||
import { cancelAnimationFrame, requestAnimationFrame, root } from './shim' | ||
import { cancelAnimationFrame, requestAnimationFrame, root } from './shim'; | ||
/** | ||
@@ -12,8 +12,8 @@ * Lightweight, effecient and modular ES6 version of tween.js | ||
*/ | ||
const _tweens = [] | ||
let isStarted = false | ||
let _autoPlay = false | ||
let _tick | ||
const _ticker = requestAnimationFrame | ||
const _stopTicker = cancelAnimationFrame | ||
const _tweens = []; | ||
let isStarted = false; | ||
let _autoPlay = false; | ||
let _tick; | ||
const _ticker = requestAnimationFrame; | ||
const _stopTicker = cancelAnimationFrame; | ||
/** | ||
@@ -29,9 +29,17 @@ * Adds tween to list | ||
const add = (tween) => { | ||
_tweens.push(tween) | ||
if (_autoPlay && !isStarted) { | ||
_tick = _ticker(update) | ||
isStarted = true | ||
} | ||
} | ||
_tweens.push(tween); | ||
if (_autoPlay && !isStarted) { | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
}; | ||
/** | ||
* Adds ticker like event | ||
* @param {Function} fn callback | ||
* @memberof TWEEN | ||
* @example | ||
* TWEEN.onTick(time => console.log(time)) | ||
*/ | ||
const onTick = fn => _tweens.push(fn); | ||
/** | ||
* @returns {Array<Tween>} List of tweens in Array | ||
@@ -41,3 +49,3 @@ * @memberof TWEEN | ||
*/ | ||
const getAll = () => _tweens | ||
const getAll = () => _tweens; | ||
/** | ||
@@ -50,4 +58,4 @@ * Runs update loop automaticlly | ||
const autoPlay = (state) => { | ||
_autoPlay = state | ||
} | ||
_autoPlay = state; | ||
}; | ||
/** | ||
@@ -59,4 +67,4 @@ * Removes all tweens from list | ||
const removeAll = () => { | ||
_tweens.length = 0 | ||
} | ||
_tweens.length = 0; | ||
}; | ||
/** | ||
@@ -70,9 +78,9 @@ * @param {Tween} tween Tween Instance to be matched | ||
const get = (tween) => { | ||
for (let i = 0; i < _tweens.length; i++) { | ||
if (tween === _tweens[i]) { | ||
return _tweens[i] | ||
for (let i = 0; i < _tweens.length; i++) { | ||
if (tween === _tweens[i]) { | ||
return _tweens[i]; | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
return null; | ||
}; | ||
/** | ||
@@ -86,4 +94,4 @@ * @param {Tween} tween Tween Instance to be matched | ||
const has = (tween) => { | ||
return get(tween) !== null | ||
} | ||
return get(tween) !== null; | ||
}; | ||
/** | ||
@@ -97,28 +105,30 @@ * Removes tween from list | ||
const remove = (tween) => { | ||
const i = _tweens.indexOf(tween) | ||
if (i !== -1) { | ||
_tweens.splice(i, 1) | ||
} | ||
} | ||
const i = _tweens.indexOf(tween); | ||
if (i !== -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
}; | ||
const now = (function () { | ||
if (typeof (process) !== 'undefined' && process.hrtime !== undefined) { | ||
return function () { | ||
const time = process.hrtime() | ||
// Convert [seconds, nanoseconds] to milliseconds. | ||
return time[0] * 1000 + time[1] / 1000000 | ||
if (typeof (process) !== 'undefined' && process.hrtime !== undefined) { | ||
return function () { | ||
const time = process.hrtime(); | ||
// Convert [seconds, nanoseconds] to milliseconds. | ||
return time[0] * 1000 + time[1] / 1000000; | ||
}; | ||
// In a browser, use window.performance.now if it is available. | ||
} | ||
// In a browser, use window.performance.now if it is available. | ||
} else if (root.performance !== undefined && | ||
else if (root.performance !== undefined && | ||
root.performance.now !== undefined) { | ||
// This must be bound, because directly assigning this function | ||
// leads to an invocation exception in Chrome. | ||
return root.performance.now.bind(root.performance) | ||
// Use Date.now if it is available. | ||
} else { | ||
const offset = root.performance && root.performance.timing && root.performance.timing.navigationStart ? root.performance.timing.navigationStart : Date.now() | ||
return function () { | ||
return Date.now() - offset | ||
// This must be bound, because directly assigning this function | ||
// leads to an invocation exception in Chrome. | ||
return root.performance.now.bind(root.performance); | ||
// Use Date.now if it is available. | ||
} | ||
} | ||
}()) | ||
else { | ||
const offset = root.performance && root.performance.timing && root.performance.timing.navigationStart ? root.performance.timing.navigationStart : Date.now(); | ||
return function () { | ||
return Date.now() - offset; | ||
}; | ||
} | ||
}()); | ||
/** | ||
@@ -133,16 +143,16 @@ * Updates global tweens by given time | ||
const update = (time, preserve) => { | ||
time = time !== undefined ? time : now() | ||
_tick = _ticker(update) | ||
if (_tweens.length === 0) { | ||
_stopTicker(_tick) | ||
isStarted = false | ||
return false | ||
} | ||
let i = 0 | ||
while (i < _tweens.length) { | ||
_tweens[i].update(time, preserve) | ||
i++ | ||
} | ||
return true | ||
} | ||
time = time !== undefined ? time : now(); | ||
_tick = _ticker(update); | ||
if (_tweens.length === 0) { | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
return false; | ||
} | ||
let i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i].update(time, preserve); | ||
i++; | ||
} | ||
return true; | ||
}; | ||
/** | ||
@@ -154,3 +164,3 @@ * The state of ticker running | ||
*/ | ||
const isRunning = () => isStarted | ||
const isRunning = () => isStarted; | ||
/** | ||
@@ -167,24 +177,25 @@ * The plugins store object | ||
*/ | ||
const Plugins = {} | ||
const Plugins = {}; | ||
// Normalise time when visiblity is changed (if available) ... | ||
if (root.document && root.document.addEventListener) { | ||
const doc = root.document | ||
let timeDiff = 0 | ||
let timePause = 0 | ||
doc.addEventListener('visibilitychange', () => { | ||
if (document.hidden) { | ||
timePause = now() | ||
_stopTicker(_tick) | ||
isStarted = false | ||
} else { | ||
timeDiff = now() - timePause | ||
for (let i = 0, length = _tweens.length; i < length; i++) { | ||
_tweens[i]._startTime += timeDiff | ||
} | ||
_tick = _ticker(update) | ||
isStarted = true | ||
} | ||
return true | ||
}) | ||
const doc = root.document; | ||
let timeDiff = 0; | ||
let timePause = 0; | ||
doc.addEventListener('visibilitychange', () => { | ||
if (document.hidden) { | ||
timePause = now(); | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
} | ||
else { | ||
timeDiff = now() - timePause; | ||
for (let i = 0, length = _tweens.length; i < length; i++) { | ||
_tweens[i]._startTime += timeDiff; | ||
} | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
return true; | ||
}); | ||
} | ||
export { Plugins, get, has, getAll, removeAll, remove, add, now, update, autoPlay, isRunning } | ||
export { Plugins, get, has, getAll, removeAll, remove, add, now, update, autoPlay, onTick, isRunning }; |
@@ -10,181 +10,184 @@ /** | ||
const Easing = { | ||
Linear: { | ||
None (k) { | ||
return k | ||
} | ||
}, | ||
Quadratic: { | ||
In (k) { | ||
return k * k | ||
Linear: { | ||
None(k) { | ||
return k; | ||
} | ||
}, | ||
Out (k) { | ||
return k * (2 - k) | ||
Quadratic: { | ||
In(k) { | ||
return k * k; | ||
}, | ||
Out(k) { | ||
return k * (2 - k); | ||
}, | ||
InOut(k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k; | ||
} | ||
return -0.5 * (--k * (k - 2) - 1); | ||
} | ||
}, | ||
InOut (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k | ||
} | ||
return -0.5 * (--k * (k - 2) - 1) | ||
} | ||
}, | ||
Cubic: { | ||
In (k) { | ||
return k * k * k | ||
Cubic: { | ||
In(k) { | ||
return k * k * k; | ||
}, | ||
Out(k) { | ||
return --k * k * k + 1; | ||
}, | ||
InOut(k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k; | ||
} | ||
return 0.5 * ((k -= 2) * k * k + 2); | ||
} | ||
}, | ||
Out (k) { | ||
return --k * k * k + 1 | ||
Quartic: { | ||
In(k) { | ||
return k * k * k * k; | ||
}, | ||
Out(k) { | ||
return 1 - (--k * k * k * k); | ||
}, | ||
InOut(k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k; | ||
} | ||
return -0.5 * ((k -= 2) * k * k * k - 2); | ||
} | ||
}, | ||
InOut (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k | ||
} | ||
return 0.5 * ((k -= 2) * k * k + 2) | ||
} | ||
}, | ||
Quartic: { | ||
In (k) { | ||
return k * k * k * k | ||
Quintic: { | ||
In(k) { | ||
return k * k * k * k * k; | ||
}, | ||
Out(k) { | ||
return --k * k * k * k * k + 1; | ||
}, | ||
InOut(k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k * k; | ||
} | ||
return 0.5 * ((k -= 2) * k * k * k * k + 2); | ||
} | ||
}, | ||
Out (k) { | ||
return 1 - (--k * k * k * k) | ||
Sinusoidal: { | ||
In(k) { | ||
return 1 - Math.cos(k * Math.PI / 2); | ||
}, | ||
Out(k) { | ||
return Math.sin(k * Math.PI / 2); | ||
}, | ||
InOut(k) { | ||
return 0.5 * (1 - Math.cos(Math.PI * k)); | ||
} | ||
}, | ||
InOut (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k | ||
} | ||
return -0.5 * ((k -= 2) * k * k * k - 2) | ||
} | ||
}, | ||
Quintic: { | ||
In (k) { | ||
return k * k * k * k * k | ||
Exponential: { | ||
In(k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1); | ||
}, | ||
Out(k) { | ||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k); | ||
}, | ||
InOut(k) { | ||
if (k === 0) { | ||
return 0; | ||
} | ||
if (k === 1) { | ||
return 1; | ||
} | ||
if ((k *= 2) < 1) { | ||
return 0.5 * Math.pow(1024, k - 1); | ||
} | ||
return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2); | ||
} | ||
}, | ||
Out (k) { | ||
return --k * k * k * k * k + 1 | ||
Circular: { | ||
In(k) { | ||
return 1 - Math.sqrt(1 - k * k); | ||
}, | ||
Out(k) { | ||
return Math.sqrt(1 - (--k * k)); | ||
}, | ||
InOut(k) { | ||
if ((k *= 2) < 1) { | ||
return -0.5 * (Math.sqrt(1 - k * k) - 1); | ||
} | ||
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1); | ||
} | ||
}, | ||
InOut (k) { | ||
if ((k *= 2) < 1) { | ||
return 0.5 * k * k * k * k * k | ||
} | ||
return 0.5 * ((k -= 2) * k * k * k * k + 2) | ||
} | ||
}, | ||
Sinusoidal: { | ||
In (k) { | ||
return 1 - Math.cos(k * Math.PI / 2) | ||
Elastic: { | ||
In(k) { | ||
if (k === 0) { | ||
return 0; | ||
} | ||
if (k === 1) { | ||
return 1; | ||
} | ||
return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); | ||
}, | ||
Out(k) { | ||
if (k === 0) { | ||
return 0; | ||
} | ||
if (k === 1) { | ||
return 1; | ||
} | ||
return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1; | ||
}, | ||
InOut(k) { | ||
if (k === 0) { | ||
return 0; | ||
} | ||
if (k === 1) { | ||
return 1; | ||
} | ||
k *= 2; | ||
if (k < 1) { | ||
return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); | ||
} | ||
return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1; | ||
} | ||
}, | ||
Out (k) { | ||
return Math.sin(k * Math.PI / 2) | ||
Back: { | ||
In(k) { | ||
const s = 1.70158; | ||
return k * k * ((s + 1) * k - s); | ||
}, | ||
Out(k) { | ||
const s = 1.70158; | ||
return --k * k * ((s + 1) * k + s) + 1; | ||
}, | ||
InOut(k) { | ||
const s = 1.70158 * 1.525; | ||
if ((k *= 2) < 1) { | ||
return 0.5 * (k * k * ((s + 1) * k - s)); | ||
} | ||
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2); | ||
} | ||
}, | ||
InOut (k) { | ||
return 0.5 * (1 - Math.cos(Math.PI * k)) | ||
Bounce: { | ||
In(k) { | ||
return 1 - Easing.Bounce.Out(1 - k); | ||
}, | ||
Out(k) { | ||
if (k < (1 / 2.75)) { | ||
return 7.5625 * k * k; | ||
} | ||
else if (k < (2 / 2.75)) { | ||
return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75; | ||
} | ||
else if (k < (2.5 / 2.75)) { | ||
return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375; | ||
} | ||
else { | ||
return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375; | ||
} | ||
}, | ||
InOut(k) { | ||
if (k < 0.5) { | ||
return Easing.Bounce.In(k * 2) * 0.5; | ||
} | ||
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; | ||
} | ||
} | ||
}, | ||
Exponential: { | ||
In (k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1) | ||
}, | ||
Out (k) { | ||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k) | ||
}, | ||
InOut (k) { | ||
if (k === 0) { | ||
return 0 | ||
} | ||
if (k === 1) { | ||
return 1 | ||
} | ||
if ((k *= 2) < 1) { | ||
return 0.5 * Math.pow(1024, k - 1) | ||
} | ||
return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2) | ||
} | ||
}, | ||
Circular: { | ||
In (k) { | ||
return 1 - Math.sqrt(1 - k * k) | ||
}, | ||
Out (k) { | ||
return Math.sqrt(1 - (--k * k)) | ||
}, | ||
InOut (k) { | ||
if ((k *= 2) < 1) { | ||
return -0.5 * (Math.sqrt(1 - k * k) - 1) | ||
} | ||
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1) | ||
} | ||
}, | ||
Elastic: { | ||
In (k) { | ||
if (k === 0) { | ||
return 0 | ||
} | ||
if (k === 1) { | ||
return 1 | ||
} | ||
return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) | ||
}, | ||
Out (k) { | ||
if (k === 0) { | ||
return 0 | ||
} | ||
if (k === 1) { | ||
return 1 | ||
} | ||
return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1 | ||
}, | ||
InOut (k) { | ||
if (k === 0) { | ||
return 0 | ||
} | ||
if (k === 1) { | ||
return 1 | ||
} | ||
k *= 2 | ||
if (k < 1) { | ||
return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) | ||
} | ||
return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1 | ||
} | ||
}, | ||
Back: { | ||
In (k) { | ||
const s = 1.70158 | ||
return k * k * ((s + 1) * k - s) | ||
}, | ||
Out (k) { | ||
const s = 1.70158 | ||
return --k * k * ((s + 1) * k + s) + 1 | ||
}, | ||
InOut (k) { | ||
const s = 1.70158 * 1.525 | ||
if ((k *= 2) < 1) { | ||
return 0.5 * (k * k * ((s + 1) * k - s)) | ||
} | ||
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2) | ||
} | ||
}, | ||
Bounce: { | ||
In (k) { | ||
return 1 - Easing.Bounce.Out(1 - k) | ||
}, | ||
Out (k) { | ||
if (k < (1 / 2.75)) { | ||
return 7.5625 * k * k | ||
} else if (k < (2 / 2.75)) { | ||
return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75 | ||
} else if (k < (2.5 / 2.75)) { | ||
return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375 | ||
} else { | ||
return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375 | ||
} | ||
}, | ||
InOut (k) { | ||
if (k < 0.5) { | ||
return Easing.Bounce.In(k * 2) * 0.5 | ||
} | ||
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5 | ||
} | ||
} | ||
} | ||
export default Easing | ||
}; | ||
export default Easing; |
@@ -11,6 +11,6 @@ /** | ||
class EventClass { | ||
constructor () { | ||
this._events = {} | ||
} | ||
/** | ||
constructor() { | ||
this._events = {}; | ||
} | ||
/** | ||
* Adds `event` to Events system | ||
@@ -21,10 +21,10 @@ * @param {string} event - Event listener name | ||
*/ | ||
on (event, callback) { | ||
if (!this._events[event]) { | ||
this._events[event] = [] | ||
on(event, callback) { | ||
if (!this._events[event]) { | ||
this._events[event] = []; | ||
} | ||
this._events[event].push(callback); | ||
return this; | ||
} | ||
this._events[event].push(callback) | ||
return this | ||
} | ||
/** | ||
/** | ||
* Adds `event` to Events system. | ||
@@ -36,15 +36,15 @@ * Removes itself after fired once | ||
*/ | ||
once (event, callback) { | ||
if (!this._events[event]) { | ||
this._events[event] = [] | ||
once(event, callback) { | ||
if (!this._events[event]) { | ||
this._events[event] = []; | ||
} | ||
const { _events } = this; | ||
const spliceIndex = _events[event].length; | ||
this._events[event].push((...args) => { | ||
callback.apply(this, args); | ||
_events[event].splice(spliceIndex, 1); | ||
}); | ||
return this; | ||
} | ||
const { _events } = this | ||
const spliceIndex = _events[event].length | ||
this._events[event].push((...args) => { | ||
callback.apply(this, args) | ||
_events[event].splice(spliceIndex, 1) | ||
}) | ||
return this | ||
} | ||
/** | ||
/** | ||
* Removes `event` from Events system | ||
@@ -55,15 +55,16 @@ * @param {string} event - Event listener name | ||
*/ | ||
off (event, callback) { | ||
const { _events } = this | ||
if (event === undefined || !_events[event]) { | ||
return this | ||
off(event, callback) { | ||
const { _events } = this; | ||
if (event === undefined || !_events[event]) { | ||
return this; | ||
} | ||
if (callback) { | ||
this._events[event] = this._events[event].filter((cb) => cb !== callback); | ||
} | ||
else { | ||
this._events[event].length = 0; | ||
} | ||
return this; | ||
} | ||
if (callback) { | ||
this._events[event] = this._events[event].filter((cb) => cb !== callback) | ||
} else { | ||
this._events[event].length = 0 | ||
} | ||
return this | ||
} | ||
/** | ||
/** | ||
* Emits/Fired/Trigger `event` from Events system listeners | ||
@@ -73,16 +74,16 @@ * @param {string} event - Event listener name | ||
*/ | ||
emit (event, arg1, arg2, arg3, arg4) { | ||
const { _events } = this | ||
const _event = _events[event] | ||
if (!_event || !_event.length) { | ||
return this | ||
emit(event, arg1, arg2, arg3, arg4) { | ||
const { _events } = this; | ||
const _event = _events[event]; | ||
if (!_event || !_event.length) { | ||
return this; | ||
} | ||
let i = 0; | ||
const len = _event.length; | ||
for (; i < len; i++) { | ||
_event[i](arg1, arg2, arg3, arg4); | ||
} | ||
return this; | ||
} | ||
let i = 0 | ||
const len = _event.length | ||
for (; i < len; i++) { | ||
_event[i](arg1, arg2, arg3, arg4) | ||
} | ||
return this | ||
} | ||
} | ||
export default EventClass | ||
export default EventClass; |
import Interpolator from 'intertween'; | ||
import { add, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
import Easing from './Easing'; | ||
@@ -7,2 +7,2 @@ import Timeline from './Timeline'; | ||
import './shim'; | ||
export { Plugins, Interpolator, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; | ||
export { Plugins, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; |
@@ -1,7 +0,7 @@ | ||
import Interpolator from 'intertween' | ||
import { add, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core' | ||
import Easing from './Easing' | ||
import Timeline from './Timeline' | ||
import Tween from './Tween' | ||
import './shim' | ||
export { Plugins, Interpolator, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline } | ||
import Interpolator from 'intertween'; | ||
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
import Easing from './Easing'; | ||
import Timeline from './Timeline'; | ||
import Tween from './Tween'; | ||
import './shim'; | ||
export { Plugins, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; |
@@ -1,4 +0,4 @@ | ||
import { add, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
import Easing from './Easing'; | ||
import Tween from './lite'; | ||
export { Plugins, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing }; | ||
export { Plugins, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing }; |
@@ -1,4 +0,4 @@ | ||
import { add, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core' | ||
import Easing from './Easing' | ||
import Tween from './lite' | ||
export { Plugins, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing } | ||
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
import Easing from './Easing'; | ||
import Tween from './lite'; | ||
export { Plugins, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing }; |
@@ -12,76 +12,77 @@ /** | ||
const Interpolation = { | ||
Linear (v, k) { | ||
const m = v.length - 1 | ||
const f = m * k | ||
const i = Math.floor(f) | ||
const fn = Interpolation.Utils.Linear | ||
if (k < 0) { | ||
return fn(v[0], v[1], f) | ||
} | ||
if (k > 1) { | ||
return fn(v[m], v[m - 1], m - f) | ||
} | ||
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i) | ||
}, | ||
Bezier (v, k) { | ||
let b = 0 | ||
const n = v.length - 1 | ||
const pw = Math.pow | ||
const bn = Interpolation.Utils.Bernstein | ||
for (let i = 0; i <= n; i++) { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i) | ||
} | ||
return b | ||
}, | ||
CatmullRom (v, k) { | ||
const m = v.length - 1 | ||
let f = m * k | ||
let i = Math.floor(f) | ||
const fn = Interpolation.Utils.CatmullRom | ||
if (v[0] === v[m]) { | ||
if (k < 0) { | ||
i = Math.floor(f = m * (1 + k)) | ||
} | ||
return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i) | ||
} else { | ||
if (k < 0) { | ||
return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]) | ||
} | ||
if (k > 1) { | ||
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]) | ||
} | ||
return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i) | ||
} | ||
}, | ||
Utils: { | ||
Linear (p0, p1, t) { | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0 | ||
Linear(v, k) { | ||
const m = v.length - 1; | ||
const f = m * k; | ||
const i = Math.floor(f); | ||
const fn = Interpolation.Utils.Linear; | ||
if (k < 0) { | ||
return fn(v[0], v[1], f); | ||
} | ||
if (k > 1) { | ||
return fn(v[m], v[m - 1], m - f); | ||
} | ||
return fn(v[i], v[i + 1 > m ? m : i + 1], f - i); | ||
}, | ||
Bernstein (n, i) { | ||
const fc = Interpolation.Utils.Factorial | ||
return fc(n) / fc(i) / fc(n - i) | ||
Bezier(v, k) { | ||
let b = 0; | ||
const n = v.length - 1; | ||
const pw = Math.pow; | ||
const bn = Interpolation.Utils.Bernstein; | ||
for (let i = 0; i <= n; i++) { | ||
b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i); | ||
} | ||
return b; | ||
}, | ||
Factorial: (function () { | ||
const a = [1] | ||
return (n) => { | ||
let s = 1 | ||
if (a[n]) { | ||
return a[n] | ||
CatmullRom(v, k) { | ||
const m = v.length - 1; | ||
let f = m * k; | ||
let i = Math.floor(f); | ||
const fn = Interpolation.Utils.CatmullRom; | ||
if (v[0] === v[m]) { | ||
if (k < 0) { | ||
i = Math.floor(f = m * (1 + k)); | ||
} | ||
return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i); | ||
} | ||
for (let i = n; i > 1; i--) { | ||
s *= i | ||
else { | ||
if (k < 0) { | ||
return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]); | ||
} | ||
if (k > 1) { | ||
return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]); | ||
} | ||
return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i); | ||
} | ||
a[n] = s | ||
return s | ||
} | ||
})(), | ||
CatmullRom (p0, p1, p2, p3, t) { | ||
const v0 = (p2 - p0) * 0.5 | ||
const v1 = (p3 - p1) * 0.5 | ||
const t2 = t * t | ||
const t3 = t * t2 | ||
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1 | ||
}, | ||
Utils: { | ||
Linear(p0, p1, t) { | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0; | ||
}, | ||
Bernstein(n, i) { | ||
const fc = Interpolation.Utils.Factorial; | ||
return fc(n) / fc(i) / fc(n - i); | ||
}, | ||
Factorial: (function () { | ||
const a = [1]; | ||
return (n) => { | ||
let s = 1; | ||
if (a[n]) { | ||
return a[n]; | ||
} | ||
for (let i = n; i > 1; i--) { | ||
s *= i; | ||
} | ||
a[n] = s; | ||
return s; | ||
}; | ||
})(), | ||
CatmullRom(p0, p1, p2, p3, t) { | ||
const v0 = (p2 - p0) * 0.5; | ||
const v1 = (p3 - p1) * 0.5; | ||
const t2 = t * t; | ||
const t3 = t * t2; | ||
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; | ||
} | ||
} | ||
} | ||
} | ||
export default Interpolation | ||
}; | ||
export default Interpolation; |
522
src/lite.js
@@ -1,5 +0,5 @@ | ||
import { add, now, remove } from './core' | ||
import Easing from './Easing' | ||
import Interpolation from './Interpolation' | ||
let _id = 0 // Unique ID | ||
import { add, now, remove } from './core'; | ||
import Easing from './Easing'; | ||
import Interpolation from './Interpolation'; | ||
let _id = 0; // Unique ID | ||
/** | ||
@@ -15,28 +15,28 @@ * Tween Lite main constructor | ||
class Lite { | ||
constructor (object) { | ||
this.id = _id++ | ||
this.object = object | ||
this._valuesStart = {} | ||
this._valuesEnd = null | ||
this._valuesStartRepeat = {} | ||
this._duration = 1000 | ||
this._easingFunction = Easing.Linear.None | ||
this._interpolationFunction = Interpolation.Linear | ||
this._startTime = 0 | ||
this._delayTime = 0 | ||
this._repeat = 0 | ||
this._r = 0 | ||
this._isPlaying = false | ||
this._yoyo = false | ||
this._reversed = false | ||
this._onStartCallbackFired = false | ||
this._pausedTime = null | ||
this._isFinite = true | ||
/* Callbacks */ | ||
this._onStartCallback = null | ||
this._onUpdateCallback = null | ||
this._onCompleteCallback = null | ||
return this | ||
} | ||
/** | ||
constructor(object) { | ||
this.id = _id++; | ||
this.object = object; | ||
this._valuesStart = {}; | ||
this._valuesEnd = null; | ||
this._valuesStartRepeat = {}; | ||
this._duration = 1000; | ||
this._easingFunction = Easing.Linear.None; | ||
this._interpolationFunction = Interpolation.Linear; | ||
this._startTime = 0; | ||
this._delayTime = 0; | ||
this._repeat = 0; | ||
this._r = 0; | ||
this._isPlaying = false; | ||
this._yoyo = false; | ||
this._reversed = false; | ||
this._onStartCallbackFired = false; | ||
this._pausedTime = null; | ||
this._isFinite = true; | ||
/* Callbacks */ | ||
this._onStartCallback = null; | ||
this._onUpdateCallback = null; | ||
this._onCompleteCallback = null; | ||
return this; | ||
} | ||
/** | ||
* onStart callback | ||
@@ -47,7 +47,7 @@ * @param {Function} callback Function should be fired after tween is started | ||
*/ | ||
onStart (callback) { | ||
this._onStartCallback = callback | ||
return this | ||
} | ||
/** | ||
onStart(callback) { | ||
this._onStartCallback = callback; | ||
return this; | ||
} | ||
/** | ||
* onUpdate callback | ||
@@ -58,7 +58,7 @@ * @param {Function} callback Function should be fired while tween is in progress | ||
*/ | ||
onUpdate (callback) { | ||
this._onUpdateCallback = callback | ||
return this | ||
} | ||
/** | ||
onUpdate(callback) { | ||
this._onUpdateCallback = callback; | ||
return this; | ||
} | ||
/** | ||
* onComplete callback | ||
@@ -69,7 +69,7 @@ * @param {Function} callback Function should be fired after tween is finished | ||
*/ | ||
onComplete (callback) { | ||
this._onCompleteCallback = callback | ||
return this | ||
} | ||
/** | ||
onComplete(callback) { | ||
this._onCompleteCallback = callback; | ||
return this; | ||
} | ||
/** | ||
* @return {boolean} State of playing of tween | ||
@@ -79,6 +79,6 @@ * @example tween.isPlaying() // returns `true` if tween in progress | ||
*/ | ||
isPlaying () { | ||
return this._isPlaying | ||
} | ||
/** | ||
isPlaying() { | ||
return this._isPlaying; | ||
} | ||
/** | ||
* @return {boolean} State of started of tween | ||
@@ -88,6 +88,6 @@ * @example tween.isStarted() // returns `true` if tween in started | ||
*/ | ||
isStarted () { | ||
return this._onStartCallbackFired | ||
} | ||
/** | ||
isStarted() { | ||
return this._onStartCallbackFired; | ||
} | ||
/** | ||
* Pauses tween | ||
@@ -97,12 +97,12 @@ * @example tween.pause() | ||
*/ | ||
pause () { | ||
if (!this._isPlaying) { | ||
return this | ||
pause() { | ||
if (!this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this; | ||
} | ||
this._isPlaying = false | ||
remove(this) | ||
this._pausedTime = now() | ||
return this | ||
} | ||
/** | ||
/** | ||
* Play/Resume the tween | ||
@@ -112,13 +112,13 @@ * @example tween.play() | ||
*/ | ||
play () { | ||
if (this._isPlaying) { | ||
return this | ||
play() { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this; | ||
} | ||
this._isPlaying = true | ||
this._startTime += now() - this._pausedTime | ||
add(this) | ||
this._pausedTime = now() | ||
return this | ||
} | ||
/** | ||
/** | ||
* Sets tween duration | ||
@@ -129,7 +129,7 @@ * @param {number} amount Duration is milliseconds | ||
*/ | ||
duration (amount) { | ||
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount | ||
return this | ||
} | ||
/** | ||
duration(amount) { | ||
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
} | ||
/** | ||
* Sets target value and duration | ||
@@ -141,8 +141,8 @@ * @param {object} properties Target value (to value) | ||
*/ | ||
to (properties, duration = 1000) { | ||
this._valuesEnd = properties | ||
this._duration = duration | ||
return this | ||
} | ||
/** | ||
to(properties, duration = 1000) { | ||
this._valuesEnd = properties; | ||
this._duration = duration; | ||
return this; | ||
} | ||
/** | ||
* Start the tweening | ||
@@ -153,59 +153,62 @@ * @param {number} time setting manual time instead of Current browser timestamp | ||
*/ | ||
start (time) { | ||
this._startTime = time !== undefined ? time : now() | ||
this._startTime += this._delayTime | ||
const { _valuesEnd, _valuesStartRepeat, _valuesStart, _interpolationFunction, object } = this | ||
for (const property in _valuesEnd) { | ||
const start = object[property] | ||
let end = _valuesEnd[property] | ||
if (!object || object[property] === undefined) { | ||
continue | ||
} | ||
const obj = object[property] | ||
if (typeof start === 'number') { | ||
if (typeof end === 'string') { | ||
_valuesStartRepeat[property] = end | ||
end = start + parseFloat(end) | ||
} else if (Array.isArray(end)) { | ||
end.unshift(start) | ||
const _endArr = end | ||
end = (t) => { | ||
return _interpolationFunction(_endArr, t) | ||
} | ||
} | ||
} else if (typeof end === 'object') { | ||
if (Array.isArray(end)) { | ||
const _endArr = end | ||
const _start = start.map((item) => item) | ||
let i | ||
const len = end.length | ||
end = (t) => { | ||
i = 0 | ||
for (; i < len; i++) { | ||
obj[i] = typeof _start[i] === 'number' ? _start[i] + (_endArr[i] - _start[i]) * t : _endArr[i] | ||
start(time) { | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += this._delayTime; | ||
const { _valuesEnd, _valuesStartRepeat, _valuesStart, _interpolationFunction, object } = this; | ||
for (const property in _valuesEnd) { | ||
const start = object[property]; | ||
let end = _valuesEnd[property]; | ||
if (!object || object[property] === undefined) { | ||
continue; | ||
} | ||
return obj | ||
} | ||
} else { | ||
const _endObj = end | ||
const _start = {} | ||
for (const p in start) { | ||
_start[p] = start[p] | ||
} | ||
end = (t) => { | ||
for (const i in end) { | ||
obj[i] = typeof _start[i] === 'number' ? _start[i] + (_endObj[i] - _start[i]) * t : _endObj[i] | ||
const obj = object[property]; | ||
if (typeof start === 'number') { | ||
if (typeof end === 'string') { | ||
_valuesStartRepeat[property] = end; | ||
end = start + parseFloat(end); | ||
} | ||
else if (Array.isArray(end)) { | ||
end.unshift(start); | ||
const _endArr = end; | ||
end = (t) => { | ||
return _interpolationFunction(_endArr, t); | ||
}; | ||
} | ||
} | ||
return obj | ||
} | ||
else if (typeof end === 'object') { | ||
if (Array.isArray(end)) { | ||
const _endArr = end; | ||
const _start = start.map((item) => item); | ||
let i; | ||
const len = end.length; | ||
end = (t) => { | ||
i = 0; | ||
for (; i < len; i++) { | ||
obj[i] = typeof _start[i] === 'number' ? _start[i] + (_endArr[i] - _start[i]) * t : _endArr[i]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
else { | ||
const _endObj = end; | ||
const _start = {}; | ||
for (const p in start) { | ||
_start[p] = start[p]; | ||
} | ||
end = (t) => { | ||
for (const i in end) { | ||
obj[i] = typeof _start[i] === 'number' ? _start[i] + (_endObj[i] - _start[i]) * t : _endObj[i]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
} | ||
_valuesStart[property] = start; | ||
_valuesEnd[property] = end; | ||
} | ||
} | ||
_valuesStart[property] = start | ||
_valuesEnd[property] = end | ||
add(this); | ||
this._isPlaying = true; | ||
return this; | ||
} | ||
add(this) | ||
this._isPlaying = true | ||
return this | ||
} | ||
/** | ||
/** | ||
* Stops the tween | ||
@@ -215,13 +218,13 @@ * @example tween.stop() | ||
*/ | ||
stop () { | ||
const { _isPlaying, _startTime, _duration } = this | ||
if (!_isPlaying) { | ||
return this | ||
stop() { | ||
const { _isPlaying, _startTime, _duration } = this; | ||
if (!_isPlaying) { | ||
return this; | ||
} | ||
this.update(_startTime + _duration); | ||
remove(this); | ||
this._isPlaying = false; | ||
return this; | ||
} | ||
this.update(_startTime + _duration) | ||
remove(this) | ||
this._isPlaying = false | ||
return this | ||
} | ||
/** | ||
/** | ||
* Set delay of tween | ||
@@ -232,7 +235,7 @@ * @param {number} amount Sets tween delay / wait duration | ||
*/ | ||
delay (amount) { | ||
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount | ||
return this | ||
} | ||
/** | ||
delay(amount) { | ||
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
* Sets how times tween is repeating | ||
@@ -243,9 +246,9 @@ * @param {amount} amount the times of repeat | ||
*/ | ||
repeat (amount) { | ||
this._repeat = typeof (amount) === 'function' ? amount(this._repeat) : amount | ||
this._r = this._repeat | ||
this._isFinite = isFinite(amount) | ||
return this | ||
} | ||
/** | ||
repeat(amount) { | ||
this._repeat = typeof (amount) === 'function' ? amount(this._repeat) : amount; | ||
this._r = this._repeat; | ||
this._isFinite = isFinite(amount); | ||
return this; | ||
} | ||
/** | ||
* Set delay of each repeat of tween | ||
@@ -256,7 +259,7 @@ * @param {number} amount Sets tween repeat delay / repeat wait duration | ||
*/ | ||
repeatDelay (amount) { | ||
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount | ||
return this | ||
} | ||
/** | ||
repeatDelay(amount) { | ||
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
* Set delay of each repeat alternate of tween | ||
@@ -267,7 +270,7 @@ * @param {number} amount Sets tween repeat alternate delay / repeat alternate wait duration | ||
*/ | ||
reverseDelay (amount) { | ||
this._reverseDelayTime = typeof (amount) === 'function' ? amount(this._reverseDelayTime) : amount | ||
return this | ||
} | ||
/** | ||
reverseDelay(amount) { | ||
this._reverseDelayTime = typeof (amount) === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
* Set `yoyo` state (enables reverse in repeat) | ||
@@ -278,7 +281,7 @@ * @param {boolean} state Enables alternate direction for repeat | ||
*/ | ||
yoyo (state) { | ||
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state | ||
return this | ||
} | ||
/** | ||
yoyo(state) { | ||
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state; | ||
return this; | ||
} | ||
/** | ||
* Set easing | ||
@@ -289,9 +292,9 @@ * @param {Function} _easingFunction Easing function | ||
*/ | ||
easing (fn) { | ||
if (typeof fn === 'function') { | ||
this._easingFunction = fn | ||
easing(fn) { | ||
if (typeof fn === 'function') { | ||
this._easingFunction = fn; | ||
} | ||
return this; | ||
} | ||
return this | ||
} | ||
/** | ||
/** | ||
* Set interpolation | ||
@@ -302,17 +305,17 @@ * @param {Function} _interpolationFunction Interpolation function | ||
*/ | ||
interpolation (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction | ||
interpolation(_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
} | ||
return this | ||
} | ||
reassignValues () { | ||
const { _valuesStart, _valuesEnd, object } = this | ||
for (const property in _valuesEnd) { | ||
const start = _valuesStart[property] | ||
object[property] = start | ||
reassignValues() { | ||
const { _valuesStart, _valuesEnd, object } = this; | ||
for (const property in _valuesEnd) { | ||
const start = _valuesStart[property]; | ||
object[property] = start; | ||
} | ||
return this; | ||
} | ||
return this | ||
} | ||
/** | ||
/** | ||
* Updates initial object to target value by given `time` | ||
@@ -324,73 +327,78 @@ * @param {Time} time Current time | ||
*/ | ||
update (time, preserve) { | ||
const { _onStartCallbackFired, _easingFunction, _repeat, _repeatDelayTime, _reverseDelayTime, _yoyo, _reversed, _startTime, _duration, _valuesStart, _valuesEnd, _valuesStartRepeat, object, _isFinite, _isPlaying, _onStartCallback, _onUpdateCallback, _onCompleteCallback } = this | ||
let elapsed | ||
let value | ||
let property | ||
time = time !== undefined ? time : now() | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (_onStartCallback) { | ||
_onStartCallback(object) | ||
} | ||
this._onStartCallbackFired = true | ||
} | ||
elapsed = (time - _startTime) / _duration | ||
elapsed = elapsed > 1 ? 1 : elapsed | ||
elapsed = _reversed ? 1 - elapsed : elapsed | ||
value = _easingFunction(elapsed) | ||
for (property in _valuesEnd) { | ||
const start = _valuesStart[property] | ||
const end = _valuesEnd[property] | ||
if (start === undefined) { | ||
continue | ||
} else if (typeof end === 'function') { | ||
object[property] = end(value) | ||
} else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value | ||
} | ||
} | ||
if (_onUpdateCallback) { | ||
_onUpdateCallback(object, elapsed) | ||
} | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat-- | ||
update(time, preserve) { | ||
const { _onStartCallbackFired, _easingFunction, _repeat, _repeatDelayTime, _reverseDelayTime, _yoyo, _reversed, _startTime, _duration, _valuesStart, _valuesEnd, _valuesStartRepeat, object, _isFinite, _isPlaying, _onStartCallback, _onUpdateCallback, _onCompleteCallback } = this; | ||
let elapsed; | ||
let value; | ||
let property; | ||
time = time !== undefined ? time : now(); | ||
if (!_isPlaying || time < _startTime) { | ||
return true; | ||
} | ||
if (!_reversed) { | ||
for (property in _valuesStartRepeat) { | ||
_valuesStart[property] = _valuesEnd[property] | ||
_valuesEnd[property] += parseFloat(_valuesStartRepeat[property]) | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (_onStartCallback) { | ||
_onStartCallback(object); | ||
} | ||
this._onStartCallbackFired = true; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
value = _easingFunction(elapsed); | ||
for (property in _valuesEnd) { | ||
const start = _valuesStart[property]; | ||
const end = _valuesEnd[property]; | ||
if (start === undefined) { | ||
continue; | ||
} | ||
else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} | ||
else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value; | ||
} | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime | ||
} else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime | ||
} else { | ||
this._startTime = time | ||
if (_onUpdateCallback) { | ||
_onUpdateCallback(object, elapsed); | ||
} | ||
return true | ||
} else { | ||
if (!preserve) { | ||
remove(this) | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
if (!_reversed) { | ||
for (property in _valuesStartRepeat) { | ||
_valuesStart[property] = _valuesEnd[property]; | ||
_valuesEnd[property] += parseFloat(_valuesStartRepeat[property]); | ||
} | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime; | ||
} | ||
else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime = time; | ||
} | ||
return true; | ||
} | ||
else { | ||
if (!preserve) { | ||
remove(this); | ||
} | ||
this._isPlaying = false; | ||
if (_onCompleteCallback) { | ||
_onCompleteCallback(); | ||
} | ||
this._repeat = this._r; | ||
_id--; | ||
return false; | ||
} | ||
} | ||
this._isPlaying = false | ||
if (_onCompleteCallback) { | ||
_onCompleteCallback() | ||
} | ||
this._repeat = this._r | ||
_id-- | ||
return false | ||
} | ||
return true; | ||
} | ||
return true | ||
} | ||
} | ||
export default Lite | ||
export default Lite; |
@@ -1,17 +0,18 @@ | ||
import { assign } from './shim' | ||
const Store = {} | ||
import { assign } from './shim'; | ||
const Store = {}; | ||
export default function (node, tween) { | ||
if (!node || !node.nodeType || !tween) { return tween } | ||
const ID = node.queueID || 'queue_' + Math.round(Math.random() * 1000 + Date.now()) | ||
if (!node.queueID) { | ||
node.queueID = ID | ||
} | ||
if (Store[ID]) { | ||
if (tween) { | ||
Store[ID] = assign(Store[ID], tween) | ||
if (!node || !node.nodeType || !tween) | ||
return tween; | ||
const ID = node.queueID || 'queue_' + Math.round(Math.random() * 1000 + Date.now()); | ||
if (!node.queueID) { | ||
node.queueID = ID; | ||
} | ||
return Store[ID] | ||
} | ||
Store[ID] = tween | ||
return Store[ID] | ||
if (Store[ID]) { | ||
if (tween) { | ||
Store[ID] = assign(Store[ID], tween); | ||
} | ||
return Store[ID]; | ||
} | ||
Store[ID] = tween; | ||
return Store[ID]; | ||
} |
export default class PlaybackPosition { | ||
constructor () { | ||
this.totalTime = 0 | ||
this.labels = [] | ||
this.offsets = [] | ||
} | ||
parseLabel (name, offset) { | ||
const { offsets, labels } = this | ||
let i = labels.indexOf(name) | ||
if (typeof name === 'string' && name.indexOf('=') !== -1 && !offset && i === -1) { | ||
const rty = name.substr(name.indexOf('=') - 1, 2) | ||
const rt = name.split(rty) | ||
offset = rt.length === 2 ? rty + rt[1] : null | ||
name = rt[0] | ||
i = labels.indexOf(name) | ||
constructor() { | ||
this.totalTime = 0; | ||
this.labels = []; | ||
this.offsets = []; | ||
} | ||
if (i !== -1 && name) { | ||
let currOffset = offsets[i] || 0 | ||
if (typeof offset === 'number') { | ||
currOffset = offset | ||
} else if (typeof offset === 'string') { | ||
if (offset.indexOf('=') !== -1) { | ||
const type = offset.charAt(0) | ||
offset = Number(offset.substr(2)) | ||
if (type === '+' || type === '-') { | ||
currOffset += parseFloat(type + offset) | ||
} else if (type === '*') { | ||
currOffset *= offset | ||
} else if (type === '/') { | ||
currOffset /= offset | ||
} else if (type === '%') { | ||
currOffset *= offset / 100 | ||
} | ||
parseLabel(name, offset) { | ||
const { offsets, labels } = this; | ||
let i = labels.indexOf(name); | ||
if (typeof name === 'string' && name.indexOf('=') !== -1 && !offset && i === -1) { | ||
const rty = name.substr(name.indexOf('=') - 1, 2); | ||
const rt = name.split(rty); | ||
offset = rt.length === 2 ? rty + rt[1] : null; | ||
name = rt[0]; | ||
i = labels.indexOf(name); | ||
} | ||
} | ||
return currOffset | ||
if (i !== -1 && name) { | ||
let currOffset = offsets[i] || 0; | ||
if (typeof offset === 'number') { | ||
currOffset = offset; | ||
} | ||
else if (typeof offset === 'string') { | ||
if (offset.indexOf('=') !== -1) { | ||
const type = offset.charAt(0); | ||
offset = Number(offset.substr(2)); | ||
if (type === '+' || type === '-') { | ||
currOffset += parseFloat(type + offset); | ||
} | ||
else if (type === '*') { | ||
currOffset *= offset; | ||
} | ||
else if (type === '/') { | ||
currOffset /= offset; | ||
} | ||
else if (type === '%') { | ||
currOffset *= offset / 100; | ||
} | ||
} | ||
} | ||
return currOffset; | ||
} | ||
return typeof offset === 'number' ? offset : 0; | ||
} | ||
return typeof offset === 'number' ? offset : 0 | ||
} | ||
addLabel (name, offset) { | ||
this.labels.push(name) | ||
this.offsets.push(this.parseLabel(name, offset)) | ||
return this | ||
} | ||
setLabel (name, offset) { | ||
const i = this.labels.indexOf(name) | ||
if (i !== -1) { | ||
this.offsets.splice(i, 1, this.parseLabel(name, offset)) | ||
addLabel(name, offset) { | ||
this.labels.push(name); | ||
this.offsets.push(this.parseLabel(name, offset)); | ||
return this; | ||
} | ||
return this | ||
} | ||
eraseLabel (name) { | ||
const i = this.labels.indexOf(name) | ||
if (i !== -1) { | ||
this.labels.splice(i, 1) | ||
this.offsets.splice(i, 1) | ||
setLabel(name, offset) { | ||
const i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.offsets.splice(i, 1, this.parseLabel(name, offset)); | ||
} | ||
return this; | ||
} | ||
return this | ||
} | ||
eraseLabel(name) { | ||
const i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.labels.splice(i, 1); | ||
this.offsets.splice(i, 1); | ||
} | ||
return this; | ||
} | ||
} |
/* global global */ | ||
export let create = Object.create || ((source) => { | ||
return Object.assign({}, source || {}) | ||
}) | ||
return Object.assign({}, source || {}); | ||
}); | ||
export let assign = Object.assign || ((source, ...args) => { | ||
for (let i = 0, len = args.length; i < len; i++) { | ||
const arg = args[i] | ||
for (const p in arg) { | ||
source[p] = arg[p] | ||
for (let i = 0, len = args.length; i < len; i++) { | ||
const arg = args[i]; | ||
for (const p in arg) { | ||
source[p] = arg[p]; | ||
} | ||
} | ||
} | ||
return source | ||
}) | ||
export let root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this | ||
export let requestAnimationFrame = root.requestAnimationFrame || (fn => root.setTimeout(fn, 16)) | ||
export let cancelAnimationFrame = root.cancelAnimationFrame || (id => root.clearTimeout(id)) | ||
return source; | ||
}); | ||
export let root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this; | ||
export let requestAnimationFrame = root.requestAnimationFrame || (fn => root.setTimeout(fn, 16)); | ||
export let cancelAnimationFrame = root.cancelAnimationFrame || (id => root.clearTimeout(id)); |
@@ -1,17 +0,17 @@ | ||
import { add, now, remove } from './core' | ||
import PlaybackPosition from './PlaybackPosition' | ||
import Tween, { EVENT_COMPLETE, EVENT_REPEAT, EVENT_REVERSE, EVENT_RS, EVENT_UPDATE } from './Tween' | ||
import { add, now, remove } from './core'; | ||
import PlaybackPosition from './PlaybackPosition'; | ||
import Tween, { EVENT_COMPLETE, EVENT_REPEAT, EVENT_REVERSE, EVENT_RS, EVENT_UPDATE } from './Tween'; | ||
export const shuffle = (a) => { | ||
let j | ||
let x | ||
let i | ||
for (i = a.length; i; i -= 1) { | ||
j = Math.floor(Math.random() * i) | ||
x = a[i - 1] | ||
a[i - 1] = a[j] | ||
a[j] = x | ||
} | ||
return a | ||
} | ||
let _id = 0 | ||
let j; | ||
let x; | ||
let i; | ||
for (i = a.length; i; i -= 1) { | ||
j = Math.floor(Math.random() * i); | ||
x = a[i - 1]; | ||
a[i - 1] = a[j]; | ||
a[j] = x; | ||
} | ||
return a; | ||
}; | ||
let _id = 0; | ||
/** | ||
@@ -27,48 +27,53 @@ * Timeline main constructor. | ||
class Timeline extends Tween { | ||
constructor (params) { | ||
super() | ||
this._duration = 0 | ||
this._startTime = now() | ||
this._tweens = [] | ||
this._elapsed = 0 | ||
this._id = _id++ | ||
this._defaultParams = params | ||
this.position = new PlaybackPosition() | ||
this.position.addLabel('afterLast', this._duration) | ||
this.position.addLabel('afterInit', this._startTime) | ||
return this | ||
} | ||
mapTotal (fn) { | ||
fn.call(this, this._tweens) | ||
return this | ||
} | ||
timingOrder (fn) { | ||
const timing = fn(this._tweens.map((t) => t._startTime)) | ||
this._tweens.map((tween, i) => { tween._startTime = timing[i] }) | ||
return this | ||
} | ||
getTiming (mode, nodes, params, offset = 0) { | ||
if (mode === 'reverse') { | ||
const { stagger } = params | ||
const totalStagger = (stagger || 0) * (nodes.length - 1) | ||
return nodes.map((node, i) => totalStagger - ((stagger || 0) * i) + offset) | ||
} else if (mode === 'async') { | ||
return nodes.map((node) => offset) | ||
} else if (mode === 'sequence' || mode === 'delayed') { | ||
let { stagger } = params | ||
if (!stagger) { | ||
stagger = (params.duration || 1000) / (nodes.length - 1) | ||
} | ||
return nodes.map((node, i) => (stagger * i) + offset) | ||
} else if (mode === 'oneByOne') { | ||
return nodes.map((node) => params.duration) | ||
} else if (mode === 'shuffle') { | ||
const { stagger } = params | ||
return shuffle(nodes.map((node, i) => ((stagger || 0) * i) + offset)) | ||
} else { | ||
const { stagger } = params | ||
return nodes.map((node, i) => ((stagger || 0) * i) + offset) | ||
constructor(params) { | ||
super(); | ||
this._duration = 0; | ||
this._startTime = now(); | ||
this._tweens = []; | ||
this._elapsed = 0; | ||
this._id = _id++; | ||
this._defaultParams = params; | ||
this.position = new PlaybackPosition(); | ||
this.position.addLabel('afterLast', this._duration); | ||
this.position.addLabel('afterInit', this._startTime); | ||
return this; | ||
} | ||
} | ||
/** | ||
mapTotal(fn) { | ||
fn.call(this, this._tweens); | ||
return this; | ||
} | ||
timingOrder(fn) { | ||
const timing = fn(this._tweens.map((t) => t._startTime)); | ||
this._tweens.map((tween, i) => { tween._startTime = timing[i]; }); | ||
return this; | ||
} | ||
getTiming(mode, nodes, params, offset = 0) { | ||
if (mode === 'reverse') { | ||
const { stagger } = params; | ||
const totalStagger = (stagger || 0) * (nodes.length - 1); | ||
return nodes.map((node, i) => totalStagger - ((stagger || 0) * i) + offset); | ||
} | ||
else if (mode === 'async') { | ||
return nodes.map((node) => offset); | ||
} | ||
else if (mode === 'sequence' || mode === 'delayed') { | ||
let { stagger } = params; | ||
if (!stagger) { | ||
stagger = (params.duration || 1000) / (nodes.length - 1); | ||
} | ||
return nodes.map((node, i) => (stagger * i) + offset); | ||
} | ||
else if (mode === 'oneByOne') { | ||
return nodes.map((node) => params.duration); | ||
} | ||
else if (mode === 'shuffle') { | ||
const { stagger } = params; | ||
return shuffle(nodes.map((node, i) => ((stagger || 0) * i) + offset)); | ||
} | ||
else { | ||
const { stagger } = params; | ||
return nodes.map((node, i) => ((stagger || 0) * i) + offset); | ||
} | ||
} | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
@@ -82,17 +87,17 @@ * @param {object} from - Initial value | ||
*/ | ||
fromTo (nodes, from, to, params) { | ||
if (Array.isArray(nodes)) { | ||
if (this._defaultParams) { | ||
params = Object.assign({}, this._defaultParams, params) | ||
} | ||
const position = params.label | ||
const offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null) | ||
const mode = this.getTiming(params.mode, nodes, params, offset) | ||
nodes.map((node, i) => { | ||
this.add(Tween.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : Object.assign({}, from), typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), mode[i]) | ||
}) | ||
fromTo(nodes, from, to, params) { | ||
if (Array.isArray(nodes)) { | ||
if (this._defaultParams) { | ||
params = Object.assign({}, this._defaultParams, params); | ||
} | ||
const position = params.label; | ||
const offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
const mode = this.getTiming(params.mode, nodes, params, offset); | ||
nodes.map((node, i) => { | ||
this.add(Tween.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : Object.assign({}, from), typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), mode[i]); | ||
}); | ||
} | ||
return this.start(); | ||
} | ||
return this.start() | ||
} | ||
/** | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
@@ -105,6 +110,6 @@ * @param {object} from - Initial value | ||
*/ | ||
from (nodes, from, params) { | ||
return this.fromTo(nodes, from, null, params) | ||
} | ||
/** | ||
from(nodes, from, params) { | ||
return this.fromTo(nodes, from, null, params); | ||
} | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
@@ -117,6 +122,6 @@ * @param {object} to - Target value | ||
*/ | ||
to (nodes, to, params) { | ||
return this.fromTo(nodes, null, to, params) | ||
} | ||
/** | ||
to(nodes, to, params) { | ||
return this.fromTo(nodes, null, to, params); | ||
} | ||
/** | ||
* Add label to Timeline | ||
@@ -128,15 +133,15 @@ * @param {string} name Label name | ||
*/ | ||
addLabel (name, offset) { | ||
this.position.addLabel(name, offset) | ||
return this | ||
} | ||
map (fn) { | ||
for (let i = 0, len = this._tweens.length; i < len; i++) { | ||
const _tween = this._tweens[i] | ||
fn(_tween, i) | ||
this._duration = Math.max(this._duration, _tween._duration + _tween._startTime) | ||
addLabel(name, offset) { | ||
this.position.addLabel(name, offset); | ||
return this; | ||
} | ||
return this | ||
} | ||
/** | ||
map(fn) { | ||
for (let i = 0, len = this._tweens.length; i < len; i++) { | ||
const _tween = this._tweens[i]; | ||
fn(_tween, i); | ||
this._duration = Math.max(this._duration, _tween._duration + _tween._startTime); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Add tween to Timeline | ||
@@ -148,96 +153,100 @@ * @param {Tween} tween Tween instance | ||
*/ | ||
add (tween, position) { | ||
if (Array.isArray(tween)) { | ||
tween.map((_tween) => { | ||
this.add(_tween, position) | ||
}) | ||
return this | ||
} else if (typeof tween === 'object' && !(tween instanceof Tween)) { | ||
tween = new Tween(tween.from).to(tween.to, tween) | ||
} | ||
const { _defaultParams, _duration } = this | ||
if (_defaultParams) { | ||
for (const method in _defaultParams) { | ||
if (typeof tween[method] === 'function') { | ||
tween[method](_defaultParams[method]) | ||
add(tween, position) { | ||
if (Array.isArray(tween)) { | ||
tween.map((_tween) => { | ||
this.add(_tween, position); | ||
}); | ||
return this; | ||
} | ||
} | ||
else if (typeof tween === 'object' && !(tween instanceof Tween)) { | ||
tween = new Tween(tween.from).to(tween.to, tween); | ||
} | ||
const { _defaultParams, _duration } = this; | ||
if (_defaultParams) { | ||
for (const method in _defaultParams) { | ||
if (typeof tween[method] === 'function') { | ||
tween[method](_defaultParams[method]); | ||
} | ||
} | ||
} | ||
const offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
tween._startTime = Math.max(this._startTime, tween._delayTime); | ||
tween._startTime += offset; | ||
tween._isPlaying = true; | ||
this._duration = Math.max(_duration, tween._startTime + tween._delayTime + tween._duration); | ||
this._tweens.push(tween); | ||
this.position.setLabel('afterLast', this._duration); | ||
return this; | ||
} | ||
const offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null) | ||
tween._startTime = Math.max(this._startTime, tween._delayTime) | ||
tween._startTime += offset | ||
tween._isPlaying = true | ||
this._duration = Math.max(_duration, tween._startTime + tween._delayTime + tween._duration) | ||
this._tweens.push(tween) | ||
this.position.setLabel('afterLast', this._duration) | ||
return this | ||
} | ||
restart () { | ||
this._startTime += now() | ||
add(this) | ||
return this.emit(EVENT_RS) | ||
} | ||
easing (easing) { | ||
return this.map((tween) => tween.easing(easing)) | ||
} | ||
interpolation (interpolation) { | ||
return this.map((tween) => tween.interpolation(interpolation)) | ||
} | ||
update (time) { | ||
const { _tweens, _duration, _repeatDelayTime, _reverseDelayTime, _startTime, _reversed, _yoyo, _repeat, _isFinite, _elapsed, _isPlaying } = this | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
restart() { | ||
this._startTime += now(); | ||
add(this); | ||
return this.emit(EVENT_RS); | ||
} | ||
let elapsed = (time - _startTime) / _duration | ||
elapsed = elapsed > 1 ? 1 : elapsed | ||
elapsed = _reversed ? 1 - elapsed : elapsed | ||
elapsed = ((elapsed * 1000) | 0) / 1000 | ||
if (elapsed === _elapsed) { | ||
return true | ||
easing(easing) { | ||
return this.map((tween) => tween.easing(easing)); | ||
} | ||
this._elapsed = elapsed | ||
const timing = time - _startTime | ||
const _timing = _reversed ? _duration - timing : timing | ||
let i = 0 | ||
while (i < _tweens.length) { | ||
_tweens[i].update(_timing, true) | ||
i++ | ||
interpolation(interpolation) { | ||
return this.map((tween) => tween.interpolation(interpolation)); | ||
} | ||
this.emit(EVENT_UPDATE, elapsed, timing) | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat-- | ||
update(time) { | ||
const { _tweens, _duration, _repeatDelayTime, _reverseDelayTime, _startTime, _reversed, _yoyo, _repeat, _isFinite, _elapsed, _isPlaying } = this; | ||
if (!_isPlaying || time < _startTime) { | ||
return true; | ||
} | ||
this.emit(_reversed ? EVENT_REVERSE : EVENT_REPEAT) | ||
if (_yoyo) { | ||
this._reversed = !_reversed | ||
this.timingOrder((timing) => timing.reverse()) | ||
let elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
elapsed = ((elapsed * 1000) | 0) / 1000; | ||
if (elapsed === _elapsed) { | ||
return true; | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime | ||
} else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime | ||
} else { | ||
this._startTime = time | ||
} | ||
this._elapsed = elapsed; | ||
const timing = time - _startTime; | ||
const _timing = _reversed ? _duration - timing : timing; | ||
let i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i].reassignValues() | ||
i++ | ||
_tweens[i].update(_timing, true); | ||
i++; | ||
} | ||
return true | ||
} else { | ||
this.emit(EVENT_COMPLETE) | ||
this._repeat = this._r | ||
remove(this) | ||
this._isPlaying = false | ||
return false | ||
} | ||
this.emit(EVENT_UPDATE, elapsed, timing); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
this.emit(_reversed ? EVENT_REVERSE : EVENT_REPEAT); | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
this.timingOrder((timing) => timing.reverse()); | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime; | ||
} | ||
else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime = time; | ||
} | ||
while (i < _tweens.length) { | ||
_tweens[i].reassignValues(); | ||
i++; | ||
} | ||
return true; | ||
} | ||
else { | ||
this.emit(EVENT_COMPLETE); | ||
this._repeat = this._r; | ||
remove(this); | ||
this._isPlaying = false; | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return true | ||
} | ||
elapsed (value) { | ||
return value !== undefined ? this.update(value * this._duration) : this._elapsed | ||
} | ||
elapsed(value) { | ||
return value !== undefined ? this.update(value * this._duration) : this._elapsed; | ||
} | ||
} | ||
export default Timeline | ||
export default Timeline; |
@@ -1,4 +0,4 @@ | ||
export default function toNumber (val) { | ||
const floatedVal = parseFloat(val) | ||
return typeof floatedVal === 'number' && !isNaN(floatedVal) ? floatedVal : val | ||
export default function toNumber(val) { | ||
const floatedVal = parseFloat(val); | ||
return typeof floatedVal === 'number' && !isNaN(floatedVal) ? floatedVal : val; | ||
} |
633
src/Tween.js
@@ -1,21 +0,21 @@ | ||
import InterTween from 'intertween' | ||
import { create } from './shim' | ||
import { add, now, Plugins, remove } from './core' | ||
import Easing from './Easing' | ||
import EventClass from './Event' | ||
import NodeCache from './NodeCache' | ||
Object.create = create | ||
import InterTween from 'intertween'; | ||
import { create } from './shim'; | ||
import { add, now, Plugins, remove } from './core'; | ||
import Easing from './Easing'; | ||
import EventClass from './Event'; | ||
import NodeCache from './NodeCache'; | ||
Object.create = create; | ||
// Events list | ||
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' | ||
let _id = 0 // Unique ID | ||
const defaultEasing = Easing.Linear.None | ||
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'; | ||
let _id = 0; // Unique ID | ||
const defaultEasing = Easing.Linear.None; | ||
/** | ||
@@ -30,3 +30,3 @@ * Tween main constructor | ||
class Tween extends EventClass { | ||
/** | ||
/** | ||
* Easier way to call the Tween | ||
@@ -41,13 +41,13 @@ * @param {Element} node DOM Element | ||
*/ | ||
static fromTo (node, object, to, params = {}) { | ||
params.quickRender = params.quickRender ? params.quickRender : !to | ||
const tween = new Tween(node, object).to(to, params) | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime) | ||
tween._rendered = false | ||
tween._onStartCallbackFired = false | ||
static fromTo(node, object, to, params = {}) { | ||
params.quickRender = params.quickRender ? params.quickRender : !to; | ||
const tween = new Tween(node, object).to(to, params); | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime); | ||
tween._rendered = false; | ||
tween._onStartCallbackFired = false; | ||
} | ||
return tween; | ||
} | ||
return tween | ||
} | ||
/** | ||
/** | ||
* Easier way calling constructor only applies the `to` value, useful for CSS Animation | ||
@@ -61,6 +61,6 @@ * @param {Element} node DOM Element | ||
*/ | ||
static to (node, to, params) { | ||
return Tween.fromTo(node, null, to, params) | ||
} | ||
/** | ||
static to(node, to, params) { | ||
return Tween.fromTo(node, null, to, params); | ||
} | ||
/** | ||
* Easier way calling constructor only applies the `from` value, useful for CSS Animation | ||
@@ -74,40 +74,42 @@ * @param {Element} node DOM Element | ||
*/ | ||
static from (node, from, params) { | ||
return Tween.fromTo(node, from, null, params) | ||
} | ||
constructor (node, object) { | ||
super() | ||
this.id = _id++ | ||
if (typeof node !== 'undefined' && !object && !node.nodeType) { | ||
object = this.object = node | ||
node = null | ||
} else if (typeof node !== 'undefined') { | ||
this.node = node | ||
if (typeof object === 'object') { | ||
object = this.object = NodeCache(node, object) | ||
} else { | ||
this.object = object | ||
} | ||
static from(node, from, params) { | ||
return Tween.fromTo(node, from, null, params); | ||
} | ||
const isArr = this.isArr = Array.isArray(object) | ||
this._valuesStart = isArr ? [] : {} | ||
this._valuesEnd = null | ||
this._valuesFunc = {} | ||
this._duration = 1000 | ||
this._easingFunction = defaultEasing | ||
this._easingReverse = defaultEasing | ||
this._startTime = 0 | ||
this._delayTime = 0 | ||
this._repeat = 0 | ||
this._r = 0 | ||
this._isPlaying = false | ||
this._yoyo = false | ||
this._reversed = false | ||
this._onStartCallbackFired = false | ||
this._pausedTime = null | ||
this._isFinite = true | ||
this._elapsed = 0 | ||
return this | ||
} | ||
/** | ||
constructor(node, object) { | ||
super(); | ||
this.id = _id++; | ||
if (typeof node !== 'undefined' && !object && !node.nodeType) { | ||
object = this.object = node; | ||
node = null; | ||
} | ||
else if (typeof node !== 'undefined') { | ||
this.node = node; | ||
if (typeof object === 'object') { | ||
object = this.object = NodeCache(node, object); | ||
} | ||
else { | ||
this.object = object; | ||
} | ||
} | ||
const isArr = this.isArr = Array.isArray(object); | ||
this._valuesStart = isArr ? [] : {}; | ||
this._valuesEnd = null; | ||
this._valuesFunc = {}; | ||
this._duration = 1000; | ||
this._easingFunction = defaultEasing; | ||
this._easingReverse = defaultEasing; | ||
this._startTime = 0; | ||
this._delayTime = 0; | ||
this._repeat = 0; | ||
this._r = 0; | ||
this._isPlaying = false; | ||
this._yoyo = false; | ||
this._reversed = false; | ||
this._onStartCallbackFired = false; | ||
this._pausedTime = null; | ||
this._isFinite = true; | ||
this._elapsed = 0; | ||
return this; | ||
} | ||
/** | ||
* @return {boolean} State of playing of tween | ||
@@ -117,6 +119,6 @@ * @example tween.isPlaying() // returns `true` if tween in progress | ||
*/ | ||
isPlaying () { | ||
return this._isPlaying | ||
} | ||
/** | ||
isPlaying() { | ||
return this._isPlaying; | ||
} | ||
/** | ||
* @return {boolean} State of started of tween | ||
@@ -126,6 +128,6 @@ * @example tween.isStarted() // returns `true` if tween in started | ||
*/ | ||
isStarted () { | ||
return this._onStartCallbackFired | ||
} | ||
/** | ||
isStarted() { | ||
return this._onStartCallbackFired; | ||
} | ||
/** | ||
* Reverses the tween state/direction | ||
@@ -135,8 +137,8 @@ * @example tween.reverse() | ||
*/ | ||
reverse () { | ||
const { _reversed } = this | ||
this._reversed = !_reversed | ||
return this | ||
} | ||
/** | ||
reverse() { | ||
const { _reversed } = this; | ||
this._reversed = !_reversed; | ||
return this; | ||
} | ||
/** | ||
* @return {boolean} State of reversed | ||
@@ -146,6 +148,6 @@ * @example tween.reversed() // returns `true` if tween in reversed state | ||
*/ | ||
reversed () { | ||
return this._reversed | ||
} | ||
/** | ||
reversed() { | ||
return this._reversed; | ||
} | ||
/** | ||
* Pauses tween | ||
@@ -155,12 +157,12 @@ * @example tween.pause() | ||
*/ | ||
pause () { | ||
if (!this._isPlaying) { | ||
return this | ||
pause() { | ||
if (!this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PAUSE, this.object); | ||
} | ||
this._isPlaying = false | ||
remove(this) | ||
this._pausedTime = now() | ||
return this.emit(EVENT_PAUSE, this.object) | ||
} | ||
/** | ||
/** | ||
* Play/Resume the tween | ||
@@ -170,13 +172,13 @@ * @example tween.play() | ||
*/ | ||
play () { | ||
if (this._isPlaying) { | ||
return this | ||
play() { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PLAY, this.object); | ||
} | ||
this._isPlaying = true | ||
this._startTime += now() - this._pausedTime | ||
add(this) | ||
this._pausedTime = now() | ||
return this.emit(EVENT_PLAY, this.object) | ||
} | ||
/** | ||
/** | ||
* Restarts tween from initial value | ||
@@ -187,11 +189,11 @@ * @param {boolean=} noDelay If this param is set to `true`, restarts tween without `delay` | ||
*/ | ||
restart (noDelay) { | ||
this._repeat = this._r | ||
this._startTime = now() + (noDelay ? 0 : this._delayTime) | ||
if (!this._isPlaying) { | ||
add(this) | ||
restart(noDelay) { | ||
this._repeat = this._r; | ||
this._startTime = now() + (noDelay ? 0 : this._delayTime); | ||
if (!this._isPlaying) { | ||
add(this); | ||
} | ||
return this.emit(EVENT_RS, this.object); | ||
} | ||
return this.emit(EVENT_RS, this.object) | ||
} | ||
/** | ||
/** | ||
* Seek tween value by `time` | ||
@@ -203,8 +205,8 @@ * @param {Time} time Tween update time | ||
*/ | ||
seek (time, keepPlaying) { | ||
this._startTime = now() + Math.max(0, Math.min(time, this._duration)) | ||
this.emit(EVENT_SEEK, time, this.object) | ||
return keepPlaying ? this : this.pause() | ||
} | ||
/** | ||
seek(time, keepPlaying) { | ||
this._startTime = now() + Math.max(0, Math.min(time, this._duration)); | ||
this.emit(EVENT_SEEK, time, this.object); | ||
return keepPlaying ? this : this.pause(); | ||
} | ||
/** | ||
* Sets tween duration | ||
@@ -215,7 +217,7 @@ * @param {number} amount Duration is milliseconds | ||
*/ | ||
duration (amount) { | ||
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount | ||
return this | ||
} | ||
/** | ||
duration(amount) { | ||
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
} | ||
/** | ||
* Sets target value and duration | ||
@@ -227,17 +229,18 @@ * @param {object} properties Target value (to value) | ||
*/ | ||
to (properties, duration = 1000, maybeUsed) { | ||
this._valuesEnd = properties | ||
if (typeof duration === 'number' || typeof (duration) === 'function') { | ||
this._duration = typeof (duration) === 'function' ? duration(this._duration) : duration | ||
} else if (typeof duration === 'object') { | ||
for (const prop in duration) { | ||
if (typeof this[prop] === 'function') { | ||
const [arg1 = null, arg2 = null, arg3 = null, arg4 = null] = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]] | ||
this[prop](arg1, arg2, arg3, arg4) | ||
to(properties, duration = 1000, maybeUsed) { | ||
this._valuesEnd = properties; | ||
if (typeof duration === 'number' || typeof (duration) === 'function') { | ||
this._duration = typeof (duration) === 'function' ? duration(this._duration) : duration; | ||
} | ||
} | ||
else if (typeof duration === 'object') { | ||
for (const prop in duration) { | ||
if (typeof this[prop] === 'function') { | ||
const [arg1 = null, arg2 = null, arg3 = null, arg4 = null] = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]]; | ||
this[prop](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
} | ||
return this; | ||
} | ||
return this | ||
} | ||
/** | ||
/** | ||
* Renders and computes value at first render | ||
@@ -247,40 +250,42 @@ * @private | ||
*/ | ||
render () { | ||
if (this._rendered) { | ||
return this | ||
} | ||
let { _valuesEnd, _valuesFunc, _valuesStart, object, Renderer, node, InitialValues } = this | ||
if (node && InitialValues) { | ||
if (!object) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd)) | ||
} else if (!_valuesEnd) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object) | ||
} | ||
} | ||
for (const property in _valuesEnd) { | ||
const start = object && object[property] | ||
const end = _valuesEnd[property] | ||
if (Plugins[property]) { | ||
const plugin = Plugins[property].prototype.update ? new Plugins[property](this, start, end, property, object) : Plugins[property](this, start, end, property, object) | ||
if (plugin) { | ||
_valuesFunc[property] = plugin | ||
render() { | ||
if (this._rendered) { | ||
return this; | ||
} | ||
continue | ||
} | ||
if (!object || object[property] === undefined) { | ||
continue | ||
} | ||
if (typeof end === 'number' && typeof start === 'number') { | ||
_valuesStart[property] = start | ||
_valuesEnd[property] = end | ||
} else { | ||
_valuesFunc[property] = InterTween(start, end) | ||
} | ||
let { _valuesEnd, _valuesFunc, _valuesStart, object, Renderer, node, InitialValues } = this; | ||
if (node && InitialValues) { | ||
if (!object) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd)); | ||
} | ||
else if (!_valuesEnd) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
} | ||
} | ||
for (const property in _valuesEnd) { | ||
const start = object && object[property]; | ||
const end = _valuesEnd[property]; | ||
if (Plugins[property]) { | ||
const plugin = Plugins[property].prototype.update ? new Plugins[property](this, start, end, property, object) : Plugins[property](this, start, end, property, object); | ||
if (plugin) { | ||
_valuesFunc[property] = plugin; | ||
} | ||
continue; | ||
} | ||
if (!object || object[property] === undefined) { | ||
continue; | ||
} | ||
if (typeof end === 'number' && typeof start === 'number') { | ||
_valuesStart[property] = start; | ||
_valuesEnd[property] = end; | ||
} | ||
else { | ||
_valuesFunc[property] = InterTween(start, end); | ||
} | ||
} | ||
if (Renderer && this.node) { | ||
this.__render = new Renderer(this, object, _valuesEnd); | ||
} | ||
return this; | ||
} | ||
if (Renderer && this.node) { | ||
this.__render = new Renderer(this, object, _valuesEnd) | ||
} | ||
return this | ||
} | ||
/** | ||
/** | ||
* Start the tweening | ||
@@ -291,10 +296,10 @@ * @param {number} time setting manual time instead of Current browser timestamp | ||
*/ | ||
start (time) { | ||
this._startTime = time !== undefined ? time : now() | ||
this._startTime += this._delayTime | ||
add(this) | ||
this._isPlaying = true | ||
return this | ||
} | ||
/** | ||
start(time) { | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += this._delayTime; | ||
add(this); | ||
this._isPlaying = true; | ||
return this; | ||
} | ||
/** | ||
* Stops the tween | ||
@@ -304,13 +309,13 @@ * @example tween.stop() | ||
*/ | ||
stop () { | ||
const { _isPlaying, object, _startTime, _duration } = this | ||
if (!_isPlaying) { | ||
return this | ||
stop() { | ||
const { _isPlaying, object, _startTime, _duration } = this; | ||
if (!_isPlaying) { | ||
return this; | ||
} | ||
this.update(_startTime + _duration); | ||
remove(this); | ||
this._isPlaying = false; | ||
return this.emit(EVENT_STOP, object); | ||
} | ||
this.update(_startTime + _duration) | ||
remove(this) | ||
this._isPlaying = false | ||
return this.emit(EVENT_STOP, object) | ||
} | ||
/** | ||
/** | ||
* Set delay of tween | ||
@@ -321,8 +326,8 @@ * @param {number} amount Sets tween delay / wait duration | ||
*/ | ||
delay (amount) { | ||
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount | ||
this._startTime += this._delayTime | ||
return this | ||
} | ||
/** | ||
delay(amount) { | ||
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount; | ||
this._startTime += this._delayTime; | ||
return this; | ||
} | ||
/** | ||
* Sets how times tween is repeating | ||
@@ -333,9 +338,9 @@ * @param {amount} amount the times of repeat | ||
*/ | ||
repeat (amount) { | ||
this._repeat = typeof (amount) === 'function' ? amount(this._repeat) : amount | ||
this._r = this._repeat | ||
this._isFinite = isFinite(amount) | ||
return this | ||
} | ||
/** | ||
repeat(amount) { | ||
this._repeat = typeof (amount) === 'function' ? amount(this._repeat) : amount; | ||
this._r = this._repeat; | ||
this._isFinite = isFinite(amount); | ||
return this; | ||
} | ||
/** | ||
* Set delay of each repeat of tween | ||
@@ -346,7 +351,7 @@ * @param {number} amount Sets tween repeat delay / repeat wait duration | ||
*/ | ||
repeatDelay (amount) { | ||
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount | ||
return this | ||
} | ||
/** | ||
repeatDelay(amount) { | ||
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
* Set delay of each repeat alternate of tween | ||
@@ -357,7 +362,7 @@ * @param {number} amount Sets tween repeat alternate delay / repeat alternate wait duration | ||
*/ | ||
reverseDelay (amount) { | ||
this._reverseDelayTime = typeof (amount) === 'function' ? amount(this._reverseDelayTime) : amount | ||
return this | ||
} | ||
/** | ||
reverseDelay(amount) { | ||
this._reverseDelayTime = typeof (amount) === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
} | ||
/** | ||
* Set `yoyo` state (enables reverse in repeat) | ||
@@ -369,8 +374,8 @@ * @param {boolean} state Enables alternate direction for repeat | ||
*/ | ||
yoyo (state, _easingReverse) { | ||
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state === null ? this._yoyo : state | ||
this._easingReverse = _easingReverse || defaultEasing | ||
return this | ||
} | ||
/** | ||
yoyo(state, _easingReverse) { | ||
this._yoyo = typeof (state) === 'function' ? state(this._yoyo) : state === null ? this._yoyo : state; | ||
this._easingReverse = _easingReverse || this._easingFunction; | ||
return this; | ||
} | ||
/** | ||
* Set easing | ||
@@ -381,7 +386,7 @@ * @param {Function} _easingFunction Easing function in non-reverse direction | ||
*/ | ||
easing (_easingFunction) { | ||
this._easingFunction = _easingFunction | ||
return this | ||
} | ||
/** | ||
easing(_easingFunction) { | ||
this._easingFunction = _easingFunction; | ||
return this; | ||
} | ||
/** | ||
* Reassigns value for rare-case like Tween#restart or for Timeline | ||
@@ -391,16 +396,16 @@ * @private | ||
*/ | ||
reassignValues () { | ||
const { _valuesStart, _valuesEnd, object, isArr } = this | ||
let property | ||
for (property in _valuesEnd) { | ||
if (isArr) { | ||
property = parseInt(property) | ||
} | ||
const start = _valuesStart[property] | ||
const end = _valuesEnd[property] | ||
object[property] = typeof end === 'function' ? end(0) : start | ||
reassignValues() { | ||
const { _valuesStart, _valuesEnd, object, isArr } = this; | ||
let property; | ||
for (property in _valuesEnd) { | ||
if (isArr) { | ||
property = parseInt(property); | ||
} | ||
const start = _valuesStart[property]; | ||
const end = _valuesEnd[property]; | ||
object[property] = typeof end === 'function' ? end(0) : start; | ||
} | ||
return this; | ||
} | ||
return this | ||
} | ||
/** | ||
/** | ||
* Updates initial object to target value by given `time` | ||
@@ -412,77 +417,83 @@ * @param {Time} time Current time | ||
*/ | ||
update (time, preserve) { | ||
const { _onStartCallbackFired, _easingFunction, _easingReverse, _repeat, _repeatDelayTime, _reverseDelayTime, _yoyo, _reversed, _startTime, _duration, _valuesStart, _valuesEnd, _valuesFunc, object, _isFinite, _isPlaying, __render } = this | ||
let elapsed | ||
let value | ||
let property | ||
let currentEasing | ||
time = time !== undefined ? time : now() | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (!this._rendered) { | ||
this.render() | ||
this._rendered = true | ||
} | ||
this.emit(EVENT_START, object) | ||
this._onStartCallbackFired = true | ||
} | ||
elapsed = (time - _startTime) / _duration | ||
elapsed = elapsed > 1 ? 1 : elapsed | ||
elapsed = _reversed ? 1 - elapsed : elapsed | ||
currentEasing = _reversed ? _easingReverse : _easingFunction | ||
if (!object) { | ||
return true | ||
} | ||
for (property in _valuesEnd) { | ||
value = currentEasing[property] ? currentEasing[property](elapsed) : typeof currentEasing === 'function' ? currentEasing(elapsed) : defaultEasing(elapsed) | ||
const start = _valuesStart[property] | ||
const end = _valuesEnd[property] | ||
const fnc = _valuesFunc[property] | ||
if (fnc && fnc.update) { | ||
fnc.update(value, elapsed) | ||
} else if (fnc) { | ||
object[property] = fnc(value) | ||
} else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value | ||
} else { | ||
object[property] = end | ||
} | ||
} | ||
if (__render) { | ||
__render.update(object, elapsed) | ||
} | ||
this.emit(EVENT_UPDATE, object, elapsed) | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat-- | ||
update(time, preserve) { | ||
const { _onStartCallbackFired, _easingFunction, _easingReverse, _repeat, _repeatDelayTime, _reverseDelayTime, _yoyo, _reversed, _startTime, _duration, _valuesStart, _valuesEnd, _valuesFunc, object, _isFinite, _isPlaying, __render } = this; | ||
let elapsed; | ||
let value; | ||
let property; | ||
let currentEasing; | ||
time = time !== undefined ? time : now(); | ||
if (!_isPlaying || time < _startTime) { | ||
return true; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed | ||
if (!_onStartCallbackFired) { | ||
if (!this._rendered) { | ||
this.render(); | ||
this._rendered = true; | ||
} | ||
this.emit(EVENT_START, object); | ||
this._onStartCallbackFired = true; | ||
} | ||
this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object) | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime | ||
} else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime | ||
} else { | ||
this._startTime = time | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
currentEasing = _reversed ? _easingReverse : _easingFunction; | ||
if (!object) { | ||
return true; | ||
} | ||
return true | ||
} else { | ||
if (!preserve) { | ||
this._isPlaying = false | ||
remove(this) | ||
_id-- | ||
for (property in _valuesEnd) { | ||
value = currentEasing[property] ? currentEasing[property](elapsed) : typeof currentEasing === 'function' ? currentEasing(elapsed) : defaultEasing(elapsed); | ||
const start = _valuesStart[property]; | ||
const end = _valuesEnd[property]; | ||
const fnc = _valuesFunc[property]; | ||
if (fnc && fnc.update) { | ||
fnc.update(value, elapsed); | ||
} | ||
else if (fnc) { | ||
object[property] = fnc(value); | ||
} | ||
else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value; | ||
} | ||
else { | ||
object[property] = end; | ||
} | ||
} | ||
this.emit(EVENT_COMPLETE, object) | ||
this._repeat = this._r | ||
return false | ||
} | ||
if (__render) { | ||
__render.update(object, elapsed); | ||
} | ||
this.emit(EVENT_UPDATE, object, elapsed); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
} | ||
this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object); | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime; | ||
} | ||
else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime = time; | ||
} | ||
return true; | ||
} | ||
else { | ||
if (!preserve) { | ||
this._isPlaying = false; | ||
remove(this); | ||
_id--; | ||
} | ||
this.emit(EVENT_COMPLETE, object); | ||
this._repeat = this._r; | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return true | ||
} | ||
} | ||
export default Tween | ||
export default Tween; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
800199
9354
0