es6-tween
Advanced tools
Comparing version 3.8.24 to 4.0.0
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN={})}(this,function(t){"use strict";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(_,"").replace(v,","):t}function r(t,e){if("number"==typeof e)return e;var n=x[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=P(e);return"string"==typeof n?n.match(d).map(t):e}function o(t,e,n,o){if(n=null!==n&&void 0!==n?n:1e4,!d.test(e))return e;var u=i(t),s=i(e),a=f(u,s,n,o);if(a)return a;a=null;for(var p=null,l=null,y=[],_=0,v=s.length;_<v;_++){var m=s[_],g=u[_];y[_]="string"==typeof m&&1===m.indexOf("=")?e:null,h.test(m)?(p=_+2,l=_+11):c.test(m)&&(p=_,l=_+9),s[_]=g===m?null:null!==y[_]?r(g,m):m}return function(t,e,i){i||(i=o),e=void 0!==e?e:t;var a="";for(_=0;_<v;_++){var f=u[_],c=s[_],h=y[_],d="function"==typeof i?i(t):t;a+="number"==typeof c?null!==p&&_>p&&_<l?f+(c-f)*d|0:((f+(c-f)*d)*n|0)/n:f,1===e&&null!==h&&(u[_]=c,s[_]=r(c,h))}return a}}function u(t,e,n,r){for(var i=[],u=0,s=t.length;u<s;u++){var f=t[u];i[u]=g(f)?a(f,e,n,r&&r[u]||r):"object"==typeof f?p(f,e,n,r&&r[u]||r):"string"==typeof f?o(f,e,n,r&&r[u]||r):f}return function(n,o,u){o=void 0!==o?o:n,u||(u=r);for(var s=0,a=i.length;s<a;s++){var f=f="function"==typeof u?u:u&&"function"==typeof u[s]?u[s]:null,p=f(n);t[s]="function"==typeof i[s]?i[s](f?n:p,o,u):"number"==typeof i[s]?i[s]+(e-i[s])*p:i[s]}return t}}function s(t,e,n,r){for(var i=[],o=0,u=e.length;o<u;o++){var s=e[o];i[o]=l(0===o?t:e[o-1],s,n,r&&r[o]||r)}var a=e[e.length-1];i.push(l(a,a,n,r&&r[e.length-1]||r));var f=i.length-1;return function(t){var e=t*f,n=Math.max(0,Math.floor(e)),r=e-n,o=i[n];return"function"==typeof o?o(r):o}}function a(t,e,n,i){n=null!==n&&void 0!==n?n:1e4,w(e),w(t);for(var f=t.slice(),l=[],c=Math.min(t.length,e.length),h=0;h<c;h++){var d=f[h],y=e[h];void 0!==d&&null!==d?(l[h]="string"==typeof y&&1===y.indexOf("=")?y:null,f[h]=y.nodeType||y.update?y.update:d===y?null:g(y)?g(d)&&y.length===d.length?a(d,y,n,i&&i[h]||i):s(d,y,n,i&&i[h]||i):g(d)?u(d,y,n,i&&i[h]||i):"object"==typeof d?p(d,y,n,i&&i[h]||i):"string"==typeof d?o(d,y,n,i&&i[h]||i):void 0!==d?d:y,e[h]=null!==l[h]?r(d,y):y):("function"==typeof y||y&&y.update)&&(f[h]=y)}return function(o,u,s){s||(s=i);for(var a=0;a<c;a++){var p=f[a],h=e[a],d=l[a];if(null!==p&&void 0!==p){var y=y="function"==typeof s?s:s&&"function"==typeof s[a]?s[a]:null,_=y?y(o):o;t[a]="number"==typeof p?((p+(h-p)*_)*n|0)/n:"function"==typeof p?p(y?o:_,u,y):p.update?p.update(_,u,y):h&&h.update?h.update(_,u,y):h,d&&1===u&&(f[a]=h,e[a]=r(f[a],d))}}return t}}function f(t,e,n,i){if(n=null!==n&&void 0!==n?n:1e4,2===e.length&&2===t.length&&-1!==I.indexOf(e[1])){var o=+t[0],u=+e[0],s=e[1],a="string"==typeof e[0]&&1===e[0].indexOf("=")?e[0]:null;return a&&(u=r(o,u)),o===u&&e[0]===s?e:function(t,e,f){f||(f=i);var p="function"==typeof f?f(t):t,l=((o+(u-o)*p)*n|0)/n+s;return a&&1===e&&(u=r(o=u,a)),l}}return!1}function p(t,e,n,i){n=null!==n&&void 0!==n?n:1e4;var f,l={},c={};w(e),w(t),w(i);for(var h in e){c[h]=t&&t[h];var d=c[h],y=e[h];if(void 0!==d&&null!==d){var _=M(t,h);l[h]="string"==typeof y&&1===y.indexOf("=")?y:null,_&&!1===_.writable&&!_.set&&(f||(f={}),f[h]=!0),c[h]=y.nodeType?y:y.update?y:d===y?null:g(y)?g(d)&&y.length===d.length?a(d,y,n,i&&i[h]||i):s(d,y,n,i&&i[h]||i):g(d)?u(d,y,n,i&&i[h]||i):"object"==typeof d?p(d,y,n,i&&i[h]||i):"string"==typeof d?o(d,y,n,i&&i[h]||i):void 0!==d?d:y,e[h]=null!==l[h]?r(d,y):y}else("function"==typeof y||y&&y.update)&&(c[h]=y)}return function(o,u,s){s||(s=i),u=void 0!==u?u:o;for(var a in c){var p=c[a],h=e[a],d=l[a],y="function"==typeof s?s:s&&"function"==typeof s[a]?s[a]:null,_=y?y(o):o,v="number"==typeof p?((p+(h-p)*_)*n|0)/n:"function"==typeof p?p(y?o:_,u,y):p&&p.update?p.update(_,u,y):h&&h.update?h.update(_,u,y):h;f&&f[a]||(t[a]=v),d&&1===u&&(c[a]=h,e[a]=r(c[a],d))}return t}}function l(t,e,n,i){w(i),n=null!==n&&void 0!==n?n:1e4;var f="string"==typeof e&&"number"==typeof t&&1===e.indexOf("=")?e:null;return f&&(e=r(t,f)),e.nodeType?e:t.nodeType?t:g(e)?g(t)&&t.length===e.length?a(t,e,n,i):s(t,e,n,i):g(t)?u(t,e,n,i):"object"==typeof e?p(t,e,n,i):"string"==typeof e?o(t,e,n,i):"function"==typeof e?e:function(o,u,s){u=void 0!==u?u:o,s||(s=i);var a="function"==typeof s?s(o):o,p="number"==typeof e?((t+(e-t)*a)*n|0)/n:t;return f&&1===u&&(e=r(t+=e,f)),p}}var c=/rgb/g,h=/argb/g,d=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,y=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,_=/\n|\r|\t/g,v=/, | ,| , /g,m=255,g=Array.isArray||function(t){return t instanceof Array},b=/([.\[])/g,T=/\]/g,O=function(t,e){var n=t[e],r=e.replace(T,"").split(b),i=r.length-1,o=Array.isArray(t),u="object"==typeof t&&!o;return u?(t[e]=null,delete t[e]):o&&t.splice(e,1),r.reduce(function(t,e,s){o&&"."!==e&&"["!==e&&(e*=1);var a="["===r[s+1];if("."===e||"["===e)return"."===e?(u=!0,o=!1):"["===e&&(u=!1,o=!0),t;if(void 0===t[e]){if(o||u)return t[e]=s===i?n:o||a?[]:u?{}:null,u=o=!1,t[e]}else if(void 0!==t[e])return s===i&&(t[e]=n),t[e];return t},t)},w=function(t){if("object"==typeof t&&t)for(var e in t)if(-1!==e.indexOf(".")||-1!==e.indexOf("["))O(t,e);else if("object"==typeof t[e]&&t[e]){var n=t[e];for(var r in n)if(-1!==r.indexOf(".")||-1!==r.indexOf("["))O(n,r);else if("object"==typeof n[r]&&n[r]){var i=n[r];for(var o in i)-1===o.indexOf(".")&&-1===o.indexOf("[")||O(i,o)}}return t},x={"+=":1,"-=":1,"*=":2,"/=":3,"%=":4},P=function(t){return"string"!=typeof t?t:n(t).replace(y,e)},I=["px","pt","pc","deg","rad","turn","em","ex","cm","mm","dm","inch","in","rem","vw","vh","vmin","vmax","%"],j=Object.getOwnPropertyDescriptor,M=j||function(){};return l})}),i=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},o=Object.create||function(t){return void 0===t&&(t={}),i({},t)},u="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,s=u.requestAnimationFrame||function(t){return u.setTimeout(t,16)},a=u.cancelAnimationFrame||function(t){return u.clearTimeout(t)},f=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==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}}(),p=[],l=!1,c=!1,h=s,d=a,y=f(),_=0,v=0,m=function(t){var n=p.indexOf(t);n>-1&&p.splice(n,1),p.push(t),c&&!l&&(y=f(),e=h(T),l=!0)},g=function(t){for(var e=0;e<p.length;e++)if(t===p[e])return p[e];return null},b=function(t){var e=p.indexOf(t);-1!==e&&p.splice(e,1)},T=function(t,n){if(t=void 0!==t?t:f(),(_=t-y)>150&&(v=_-50/3),y=t,c&&l&&(e=h(T)),0===p.length)return d(e),l=!1,!1;for(var r,i=0;i<p.length;)r=p[i],v&&(r._startTime+=v),r.update(t,n),i++;return v&&(v=0),!0},O={},w={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-w.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*w.Bounce.In(2*t):.5*w.Bounce.Out(2*t-1)+.5}},Stepped:{steps:function(t){return function(e){return(e*t|0)/t}}}},x=function(){function t(){this.totalTime=0,this.labels=[],this.offsets=[]}return 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},t}(),P=function(){function t(){this._events={}}return t.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},t.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=0;u<arguments.length;u++)o[u]=arguments[u];e.apply(n,o),r[t].splice(i,1)}),this},t.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},t.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},t}(),I={},j=function(t,e){if(!t||!t.nodeType)return e;var n=t.queueID||"q_"+Date.now();return t.queueID||(t.queueID=n),I[n]?(e&&(I[n]=e),I[n]):(I[n]=e,I[n])},M=function(t,e){return e?t?t===window||t===document?[t]:"string"==typeof t?!!document.querySelectorAll&&document.querySelectorAll(t):Array.isArray(t)?t:t.nodeType?[t]:[]:null:t?t===window||t===document?t:"string"==typeof t?!!document.querySelector&&document.querySelector(t):Array.isArray(t)?t[0]:t.nodeType?t:null:null},F=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.create=o;var A=0,L=w.Linear.None,q=function(t){function e(e,n){var r=t.call(this)||this;return r.id=A++,!e||"object"!=typeof e||n||e.nodeType?e&&(e.nodeType||e.length||"string"==typeof e)&&(e=r.node=M(e),n=r.object=j(e,n)):(n=r.object=e,e=null),r._valuesEnd=null,r._valuesFunc=null,r._duration=1e3,r._easingFunction=L,r._easingReverse=L,r._startTime=0,r._initTime=0,r._delayTime=0,r._repeat=0,r._r=0,r._isPlaying=!1,r._yoyo=!1,r._reversed=!1,r._onStartCallbackFired=!1,r._pausedTime=null,r._isFinite=!0,r}return F(e,t),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(t){var e=this._reversed;return this._reversed=void 0!==t?t:!e,this},e.prototype.reversed=function(){return this._reversed},e.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,b(this),this._pausedTime=f(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=f()-this._pausedTime,this._initTime=this._startTime,m(this),this._pausedTime=f(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this.reassignValues(),m(this),this.emit("restart",this.object)},e.prototype.seek=function(t,e){var n=this,r=n._duration,i=(n._repeat,n._initTime),o=n._startTime,u=(n._delayTime,n._reversed),s=i+t;return this._isPlaying=!0,s<o&&o>=i&&(this._startTime-=r,this._reversed=!u),this.update(t,!1),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){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 r in e)if("function"==typeof this[r]){var i=Array.isArray(e[r])?e[r]:[e[r]],o=i[0],u=void 0===o?null:o,s=i[1],a=void 0===s?null:s,f=i[2],p=void 0===f?null:f,l=i[3],c=void 0===l?null:l;this[r](u,a,p,c)}return this},e.prototype.render=function(){if(this._rendered)return this;var t=this,e=t._valuesEnd,n=t.object,i=t.Renderer,o=t.node,u=t.InitialValues,s=t._easingFunction;o&&u&&(n?e||(e=this._valuesEnd=u(o,n)):n=this.object=j(o,u(o,e)));for(var a in e){var f=n&&n[a],p=e[a];if(O[a]){var l=O[a].prototype.update?new O[a](this,f,p,a,n):O[a](this,f,p,a,n);l&&(e[a]=l)}else;}return this._valuesFunc=r(n,e,null,s),i&&this.node&&(this.__render=new i(this,n,e)),this},e.prototype.start=function(t){return this._startTime=void 0!==t?"string"==typeof t?f()+parseFloat(t):t:f(),this._startTime+=this._delayTime,this._initTime=this._startTime,this._onStartCallbackFired=!1,this._rendered=!1,this._isPlaying=!0,m(this),this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t._isFinite,r=t.object,i=t._startTime,o=(t._delayTime,t._duration),u=t._r;if(!e||!n)return this;var s=(u+1)%2==1;return this._reversed=!1,s?this.update(i+o):this.update(i),b(this),this.emit("stop",r)},e.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,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.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,t||(this._reversed=!1),this._easingReverse=e||null,this},e.prototype.easing=function(t){return this._easingFunction=t,this},e.prototype.reassignValues=function(t){var e=this,n=e._valuesFunc,r=e.object,i=e._delayTime;this._isPlaying=!0,this._startTime=void 0!==t?t:f(),this._startTime+=i,this._reversed=!1,m(this);var o=n(0);for(var u in o){var s=o[u];r[u]=s}return this},e.prototype.update=function(t,e,n){var r,i,o=this,u=o._onStartCallbackFired,s=o._easingFunction,a=o._easingReverse,p=o._repeat,l=o._delayTime,c=o._reverseDelayTime,h=o._yoyo,d=o._reversed,y=o._startTime,_=o._duration,v=o._valuesFunc,m=o.object,g=o._isFinite,T=o._isPlaying,O=o.__render;return t=void 0!==t?t:f(),!T||t<y&&!n||(u||(this._rendered||(this.render(),this._rendered=!0,v=this._valuesFunc),this.emit("start",m),this._onStartCallbackFired=!0),r=(t-y)/_,r=r>1?1:r,r=d?1-r:r,i=d?a||s:s,!m||(v(r,r,i),O&&O.update(m,r),this.emit("update",m,r),!(1===r||d&&0===r)||(p?(g&&this._repeat--,h&&(this._reversed=!d),this.emit(h&&!d?"reverse":"repeat",m),this._startTime=d&&c?t-c:t+l,!0):(e||(this._isPlaying=!1,b(this),A--),this.emit("complete",m),this._repeat=this._r,!1))))},e}(P),S=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),k=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},D=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},E=0,R=function(t){function e(e){var n=t.call(this)||this;return n._duration=0,n._startTime=f(),n._tweens=[],n.elapsed=0,n._id=E++,n._defaultParams=e,n.position=new x,n.position.addLabel("afterLast",n._duration),n.position.addLabel("afterInit",n._startTime),n}return S(e,t),e.prototype.mapTotal=function(t){return t.call(this,this._tweens),this},e.prototype.timingOrder=function(t){var e=t(this._tweens.map(function(t){return t._startTime}));return this._tweens.map(function(t,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 D(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(t,e,n,r){if((t=M(t,!0))&&t.length){this._defaultParams&&(r=k({},this._defaultParams,r));for(var i=r.label,o="number"==typeof i?i:this.position.parseLabel(void 0!==i?i:"afterLast",null),u=this.getTiming(r.mode,t,r,o),s=0,a=void 0,f=t.length;s<f;s++)a=t[s],this.add(q.fromTo(a,"function"==typeof e?e(s,t.length):k({},e),"function"==typeof n?n(s,t.length):n,"function"==typeof r?r(s,t.length):r),u[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=0,n=this._tweens.length;e<n;e++){var r=this._tweens[e];t(r,e),this._duration=Math.max(this._duration,r._duration+r._startTime)}return this},e.prototype.add=function(t,e){var n=this;if(Array.isArray(t))return t.map(function(t){n.add(t,e)}),this;"object"!=typeof t||t instanceof q||(t=new q(t.from).to(t.to,t));var r=this,i=r._defaultParams,o=r._duration;if(i)for(var u in i)"function"==typeof t[u]&&t[u](i[u]);var s="number"==typeof e?e:this.position.parseLabel(void 0!==e?e:"afterLast",null);return t._startTime=Math.max(this._startTime,t._delayTime,s),t._delayTime=s,t._isPlaying=!0,this._duration=Math.max(o,t._startTime+t._delayTime+t._duration),this._tweens.push(t),this.position.setLabel("afterLast",this._duration),this},e.prototype.restart=function(){return this._startTime+=f(),m(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._reverseDelayTime,o=e._startTime,u=e._reversed,s=e._yoyo,a=e._repeat,f=e._isFinite;if(!e._isPlaying||t<o)return!0;var p=(t-o)/r;p=p>1?1:p,p=u?1-p:p,this.elapsed=p;for(var l=t-o,c=u?r-l:l,h=0;h<n.length;)n[h].update(c),h++;if(this.emit("update",p,l),1===p||u&&0===p){if(a){for(f&&this._repeat--,this.emit(u?"reverse":"repeat"),s&&(this._reversed=!u,this.timingOrder(function(t){return t.reverse()})),this._startTime=u&&i?t+i:t,h=0;h<n.length;)n[h].reassignValues(t),h++;return!0}return this.emit("complete"),this._repeat=this._r,b(this),this._isPlaying=!1,!1}return!0},e.prototype.progress=function(t){return void 0!==t?this.update(t*this._duration):this.elapsed},e}(q);t.Plugins=O,t.Selector=M,t.Interpolator=r,t.onTick=function(t){return p.push({update:t})},t.has=function(t){return null!==g(t)},t.get=g,t.getAll=function(){return p},t.removeAll=function(){p.length=0},t.remove=b,t.add=m,t.now=f,t.update=T,t.autoPlay=function(t){c=t},t.isRunning=function(){return l},t.Tween=q,t.Easing=w,t.Timeline=R,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN={})}(this,function(t){"use strict";function e(t){if(void 0===t||"object"!=typeof t)return t;if(Array.isArray(t))return[].concat(t);if("object"==typeof t){var n={};for(var r in t)n[r]=e(t[r]);return n}return t}function n(t,e,r,i){var o=r[t],s=i[t];if("string"==typeof o&&"string"==typeof s){var u=o.match(j).map(function(t){return P(t)?t:+t}),a=s.match(j).map(function(t,e){return P(t)?t:+t});return u.unshift(x),r[t]=u,i[t]=a,!0}if("object"==typeof o&&"object"==typeof s){if(Array.isArray(o))return o.map(function(r,i){return n(i,e[t],o,s)});for(var f in s)n(f,e[t],o,s);return!0}return!1}function r(t,e,n,i,o,s){var u=n[t],a=i[t];if(void 0===a)return u;if(void 0===u||"string"==typeof u||u===a)return a;if("object"==typeof u&&"object"==typeof a){if(!u||!a)return e[t];if(u[0]===x){for(var f="",h=1,p=u.length;h<p;h++){c="string"==typeof a[h-1];f+="number"!=typeof a[h-1]?u[h]:((c?u[h]+ +a[h-1]:u[h]+(a[h-1]-u[h])*o)*I|0)/I,1===s&&(u[h]=u[h]+ +a[h-1])}return e[t]=f,f}if(Array.isArray(u))for(var h=0,p=u.length;h<p;h++)u[h]!==a[h]&&r(h,e[t],u,a,o,s);else for(var h in u)u[h]!==a[h]&&r(h,e[t],u,a,o,s)}else if("number"==typeof u){var c="string"==typeof a;e[t]=((c?u+ +a*o:u+(a-u)*o)*I|0)/I,c&&1===s&&(n[t]=e[t])}else"function"==typeof a&&(e[t]=a(o));return e[t]}var i,o="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,s=o.requestAnimationFrame||function(t){return o.setTimeout(t,16)},u=o.cancelAnimationFrame||function(t){return o.clearTimeout(t)},a=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==o.performance&&void 0!==o.performance.now)return o.performance.now.bind(o.performance);var t=o.performance&&o.performance.timing&&o.performance.timing.navigationStart?o.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),f=[],h=!1,p=!1,c=s,l=u,d=function(t){var e=f.indexOf(t);if(e>-1&&f.splice(e,1),f.length>0){e=f.length-1;var n=f[e];t.prev=n,n.next=t}f.push(t),p&&!h&&(i=c(v),h=!0)},_=function(t){for(var e=0;e<f.length;e++)if(t===f[e])return f[e];return null},y=function(t){var e=f.indexOf(t);-1!==e&&f.splice(e,1)},v=function(t,e){if(t=void 0!==t?t:a(),p&&h&&(i=c(v)),!f.length)return l(i),h=!1,!1;for(var n=0;n<f.length;)f[n++].update(t,e);return!0},m={},g={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-g.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*g.Bounce.In(2*t):.5*g.Bounce.Out(2*t-1)+.5}},Stepped:{steps:function(t){return function(e){return(e*t|0)/t}}}},T=function(){function t(){this.totalTime=0,this.labels=[],this.offsets=[]}return 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 s=t.substr(t.indexOf("=")-1,2),u=t.split(s);e=2===u.length?s+u[1]:null,t=u[0],o=i.indexOf(t)}if(-1!==o&&t){var a=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},t}(),b={Linear:function(t,e){var n=t.length-1,r=n*e,i=Math.floor(r),o=b.Utils.Linear;return e<0?o(t[0],t[1],r):e>1?o(t[n],t[n-1],n-r):o(t[i],t[i+1>n?n:i+1],r-i)},Bezier:function(t,e){for(var n=0,r=t.length-1,i=Math.pow,o=b.Utils.Bernstein,s=0;s<=r;s++)n+=i(1-e,r-s)*i(e,s)*t[s]*o(r,s);return n},CatmullRom:function(t,e){var n=t.length-1,r=n*e,i=Math.floor(r),o=b.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(i=Math.floor(r=n*(1+e))),o(t[(i-1+n)%n],t[i],t[(i+1)%n],t[(i+2)%n],r-i)):e<0?t[0]-(o(t[0],t[0],t[1],t[1],-r)-t[0]):e>1?t[n]-(o(t[n],t[n],t[n-1],t[n-1],r-n)-t[n]):o(t[i?i-1:0],t[i],t[n<i+1?n:i+1],t[n<i+2?n:i+2],r-i)},Utils:{Linear:function(t,e,n){return"function"==typeof t?t(n):(e-t)*n+t},Bernstein:function(t,e){var n=b.Utils.Factorial;return n(t)/n(e)/n(t-e)},Factorial:function(){var t=[1];return function(e){var n=1;if(t[e])return t[e];for(var r=e;r>1;r--)n*=r;return t[e]=n,n}}(),CatmullRom:function(t,e,n,r,i){var o=.5*(n-t),s=.5*(r-e),u=i*i;return(2*e-2*n+o+s)*(i*u)+(-3*e+3*n-2*o-s)*u+o*i+e}}},w={},O=function(t,e,n){if(!t||!t.nodeType)return e;var r=t.queueID||"q_"+Date.now();t.queueID||(t.queueID=r);var i=w[r];if(i){if(i.object!==e||t!==i.tween.node){for(var o in e)o in i.object[o]&&n.startTime===i.tween.startTime&&delete i.object[o];return e}return y(i.tween),i.object}return w[r]={tween:n,object:e},w[r]},M=function(t,e){return e?t?t===window||t===document?[t]:"string"==typeof t?!!document.querySelectorAll&&document.querySelectorAll(t):Array.isArray(t)?t:t.nodeType?[t]:[]:null:t?t===window||t===document?t:"string"==typeof t?!!document.querySelector&&document.querySelector(t):Array.isArray(t)?t[0]:t.nodeType?t:null:null},x="STRING_PROP",j=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,P=function(t){return isNaN(+t)||"+"===t[0]||"-"===t[0]||""===t||" "===t},I=Math.pow(10,4),A={x:"MyVal 1"},L={x:A.x},F={x:"MyVal 2"};n("x",A,L,F),console.log(r("x",A,L,F,.5));var S=/([.\[])/g,C=/\]/g,k=function(t,e){var n=t[e],r=e.replace(C,"").split(S),i=r.length-1,o=Array.isArray(t),s="object"==typeof t&&!o;return s?(t[e]=null,delete t[e]):o&&t.splice(e,1),r.reduce(function(t,e,u){o&&"."!==e&&"["!==e&&(e*=1);var a="["===r[u+1];if("."===e||"["===e)return"."===e?(s=!0,o=!1):"["===e&&(s=!1,o=!0),t;if(void 0===t[e]){if(o||s)return t[e]=u===i?n:o||a?[]:s?{}:null,s=o=!1,t[e]}else if(void 0!==t[e])return u===i&&(t[e]=n),t[e];return t},t)},q=function(t){if("object"==typeof t&&t)for(var e in t)if(-1!==e.indexOf(".")||-1!==e.indexOf("["))k(t,e);else if("object"==typeof t[e]&&t[e]){var n=t[e];for(var r in n)if(-1!==r.indexOf(".")||-1!==r.indexOf("["))k(n,r);else if("object"==typeof n[r]&&n[r]){var i=n[r];for(var o in i)-1===o.indexOf(".")&&-1===o.indexOf("[")||k(i,o)}}return t},R=0,D=g.Linear.None,E=function(){function t(t,e){return this._chainedTweensCount=0,this.id=R++,!t||"object"!=typeof t||e||t.nodeType?t&&(t.nodeType||t.length||"string"==typeof t)&&(t=this.node=M(t),e=this.object=O(t,e,this)):(e=this.object=t,t=null),this._valuesEnd=null,this._valuesStart={},this._duration=1e3,this._easingFunction=D,this._easingReverse=D,this._interpolationFunction=b.Linear,this._startTime=0,this._initTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._pausedTime=null,this._isFinite=!0,this._maxListener=5,this._prevTime=null,this}return t.fromTo=function(e,n,r,i){void 0===i&&(i={}),i.quickRender=i.quickRender?i.quickRender:!r;var o=new t(e,n).to(r,i);return i.quickRender&&(o.render().update(o._startTime),o._rendered=!1,o._onStartCallbackFired=!1),o},t.to=function(e,n,r){return t.fromTo(e,null,n,r)},t.from=function(e,n,r){return t.fromTo(e,n,null,r)},t.prototype.setMaxListener=function(t){return void 0===t&&(t=5),this._maxListener=t,this},t.prototype.on=function(t,e){for(var n=this._maxListener,r=t+"Callback",i=0;i<n;i++){var o=r+i;this[o]||(this[o]=e);break}return this},t.prototype.once=function(t,e){return this},t.prototype.off=function(t,e){for(var n=this._maxListener,r=t+"Callback",i=0;i<n;i++){var o=r+i;this[o]===e&&(this[o]=null)}return this},t.prototype.emit=function(t,e,n,r,i){var o=this._maxListener,s=t+"Callback";if(!this[s+0])return this;for(var u=0;u<o;u++){var a=s+u;this[a]&&this[a](e,n,r,i)}return this},t.prototype.isPlaying=function(){return this._isPlaying},t.prototype.isStarted=function(){return this._onStartCallbackFired},t.prototype.reverse=function(t){var e=this._reversed;return this._reversed=void 0!==t?t:!e,this},t.prototype.reversed=function(){return this._reversed},t.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,y(this),this._pausedTime=a(),this.emit("pause",this.object)):this},t.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=a()-this._pausedTime,this._initTime=this._startTime,d(this),this._pausedTime=a(),this.emit("play",this.object))},t.prototype.restart=function(t){return this._repeat=this._r,this.reassignValues(),d(this),this.emit("restart",this.object)},t.prototype.seek=function(t,e){var n=this,r=n._duration,i=(n._repeat,n._initTime),o=n._startTime,s=(n._delayTime,n._reversed),u=i+t;return this._isPlaying=!0,u<o&&o>=i&&(this._startTime-=r,this._reversed=!s),this.update(t,!1),this.emit("seek",t,this.object),e?this:this.pause()},t.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},t.prototype.to=function(t,e,n){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 r in e)if("function"==typeof this[r]){var i=Array.isArray(e[r])?e[r]:[e[r]],o=i[0],s=void 0===o?null:o,u=i[1],a=void 0===u?null:u,f=i[2],h=void 0===f?null:f,p=i[3],c=void 0===p?null:p;this[r](s,a,h,c)}return this},t.prototype.render=function(){if(this._rendered)return this;var t=this,r=t._valuesStart,i=t._valuesEnd,o=t.object,s=t.Renderer,u=t.node,a=t.InitialValues;q(o),q(i),u&&a&&(o?i||(i=this._valuesEnd=a(u,o)):o=this.object=O(u,a(u,i),this));for(var f in i){var h=o&&o[f],p=i[f];if(m[f]){var c=m[f].prototype.update?new m[f](this,h,p,f,o):m[f](this,h,p,f,o);c&&(i[f]=c)}else"number"==typeof h&&isNaN(h)||null===h||null===p||void 0===h||void 0===p||h===p||(Array.isArray(p)&&"number"==typeof h&&p.unshift(h),r[f]=e(h),n(f,o,r,i))}return s&&this.node&&(this.__render=new s(this,o,i)),this},t.prototype.start=function(t){return this._startTime=void 0!==t?"string"==typeof t?a()+parseFloat(t):t:a(),this._startTime+=this._delayTime,this._initTime=this._prevTime=this._startTime,this._onStartCallbackFired=!1,this._rendered=!1,this._isPlaying=!0,d(this),this},t.prototype.stop=function(){var t=this,e=t._isPlaying,n=t._isFinite,r=t.object,i=t._startTime,o=(t._delayTime,t._duration),s=t._r,u=t._yoyo,a=t._reversed;if(!e)return this;var f=n?(s+1)%2==1&&u:a;return this._reversed=!1,f?this.update(i+o):this.update(i),y(this),this.emit("stop",r)},t.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},t.prototype.chainedTweens=function(){if(this._chainedTweensCount=arguments.length,!this._chainedTweensCount)return this;for(var t=0,e=this._chainedTweensCount;t<e;t++)this["_chainedTweens"+t]=arguments[t];return this},t.prototype.repeat=function(t){return this._repeat=this._duration?"function"==typeof t?t(this._repeat):t:0,this._r=this._repeat,this._isFinite=isFinite(t),this},t.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},t.prototype.yoyo=function(t,e){return this._yoyo="function"==typeof t?t(this._yoyo):null===t?this._yoyo:t,t||(this._reversed=!1),this._easingReverse=e||null,this},t.prototype.easing=function(t){return this._easingFunction=t,this},t.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},t.prototype.reassignValues=function(t){var e=this,n=e._valuesStart,r=e.object,i=e._delayTime;this._isPlaying=!0,this._startTime=void 0!==t?t:a(),this._startTime+=i,this._reversed=!1,d(this);for(var o in n){var s=n[o];r[o]=s}return this},t.prototype.update=function(t,e,n){var i,o,s,u=this,f=u._onStartCallbackFired,h=u._easingFunction,p=u._interpolationFunction,c=u._easingReverse,l=u._repeat,d=u._delayTime,_=u._reverseDelayTime,v=u._yoyo,m=u._reversed,g=u._startTime,T=u._prevTime,b=u._duration,w=u._valuesStart,O=u._valuesEnd,M=u.object,x=u._isFinite,j=u._isPlaying,P=u.__render,A=u._chainedTweensCount;if(b){t=void 0!==t?t:a();var L=g-T;if(L>250&&(g-=L-50/3,this._startTime=g),this._prevTime=t,!j||t<g&&!n)return!0;i=(i=(t-g)/b)>1?1:i,i=m?1-i:i}else i=1;if(f||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",M),this._onStartCallbackFired=!0),o=m?c||h:h,!M)return!0;for(s in O){var F=w[s];if(void 0!==F&&null!==F){var S=O[s],C=o[s]?o[s](i):"function"==typeof o?o(i):D(i);"number"==typeof S?M[s]=((F+(S-F)*C)*I|0)/I:Array.isArray(S)&&"number"==typeof F?M[s]=p(S,C):S&&S.update?S.update(C):"function"==typeof S?M[s]=S(C):r(s,M,w,O,C,i)}}if(P&&P.update(M,i),this.emit("update",M,i),1===i||m&&!i){if(l>0&&b>0)return x&&this._repeat--,v&&(this._reversed=!m),this.emit(v&&!m?"reverse":"repeat",M),this._startTime=m&&_?t-_:t+d,!0;if(e||(this._isPlaying=!1,y(this),R--),this.emit("complete",M),this._repeat=this._r,A)for(var k=0;k<A;k++)this["_chainedTweens"+k].start(t+b);return!1}return!0},t}(),B=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),N=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},V=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},U=0,Q=function(t){function e(e){var n=t.call(this)||this;return n._duration=0,n._startTime=a(),n._tweens=[],n.elapsed=0,n._id=U++,n._defaultParams=e,n.position=new T,n.position.addLabel("afterLast",n._duration),n.position.addLabel("afterInit",n._startTime),n}return B(e,t),e.prototype.mapTotal=function(t){return t.call(this,this._tweens),this},e.prototype.timingOrder=function(t){var e=t(this._tweens.map(function(t){return t._startTime}));return this._tweens.map(function(t,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 s=n.stagger;return s||(s=(n.duration||1e3)/(e.length-1)),e.map(function(t,e){return s*e+r})}if("oneByOne"===t)return e.map(function(t){return n.duration});if("shuffle"===t){var u=n.stagger;return V(e.map(function(t,e){return(u||0)*e+r}))}var a=n.stagger;return e.map(function(t,e){return(a||0)*e+r})},e.prototype.fromTo=function(t,e,n,r){if((t=M(t,!0))&&t.length){this._defaultParams&&(r=N({},this._defaultParams,r));for(var i=r.label,o="number"==typeof i?i:this.position.parseLabel(void 0!==i?i:"afterLast",null),s=this.getTiming(r.mode,t,r,o),u=0,a=void 0,f=t.length;u<f;u++)a=t[u],this.add(E.fromTo(a,"function"==typeof e?e(u,t.length):N({},e),"function"==typeof n?n(u,t.length):n,"function"==typeof r?r(u,t.length):r),s[u])}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=0,n=this._tweens.length;e<n;e++){var r=this._tweens[e];t(r,e),this._duration=Math.max(this._duration,r._duration+r._startTime)}return this},e.prototype.add=function(t,e){var n=this;if(Array.isArray(t))return t.map(function(t){n.add(t,e)}),this;"object"!=typeof t||t instanceof E||(t=new E(t.from).to(t.to,t));var r=this,i=r._defaultParams,o=r._duration;if(i)for(var s in i)"function"==typeof t[s]&&t[s](i[s]);var u="number"==typeof e?e:this.position.parseLabel(void 0!==e?e:"afterLast",null);return t._startTime=Math.max(this._startTime,t._delayTime,u),t._delayTime=u,t._isPlaying=!0,this._duration=Math.max(o,t._startTime+t._delayTime+t._duration),this._tweens.push(t),this.position.setLabel("afterLast",this._duration),this},e.prototype.restart=function(){return this._startTime+=a(),d(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._reverseDelayTime,o=e._startTime,s=e._reversed,u=e._yoyo,a=e._repeat,f=e._isFinite;if(!e._isPlaying||t<o)return!0;var h=(t-o)/r;h=h>1?1:h,h=s?1-h:h,this.elapsed=h;for(var p=t-o,c=s?r-p:p,l=0;l<n.length;)n[l].update(c),l++;if(this.emit("update",h,p),1===h||s&&0===h){if(a){for(f&&this._repeat--,this.emit(s?"reverse":"repeat"),u&&(this._reversed=!s,this.timingOrder(function(t){return t.reverse()})),this._startTime=s&&i?t+i:t,l=0;l<n.length;)n[l].reassignValues(t),l++;return!0}return this.emit("complete"),this._repeat=this._r,y(this),this._isPlaying=!1,!1}return!0},e.prototype.progress=function(t){return void 0!==t?this.update(t*this._duration):this.elapsed},e}(E);t.Plugins=m,t.Selector=M,t.onTick=function(t){return f.push({update:t})},t.has=function(t){return null!==_(t)},t.get=_,t.getAll=function(){return f},t.removeAll=function(){f.length=0},t.remove=y,t.add=d,t.now=a,t.update=v,t.autoPlay=function(t){p=t},t.isRunning=function(){return h},t.Tween=E,t.Easing=g,t.Timeline=Q,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "es6-tween", | ||
"version": "3.8.24", | ||
"version": "4.0.0", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -16,10 +16,5 @@ "browser": "full/Tween.min.js", | ||
"build": "npm run source && npm run minify", | ||
"source-lite": "rollup -c rollup.config.lite.js", | ||
"minify-lite": "uglifyjs lite/Tween.js -c -m -o lite/Tween.min.js --source-map \"filename='lite/Tween.min.js.map'\"", | ||
"build-lite": "npm run source-lite && npm run minify-lite", | ||
"buildAll": "tsc && npm run build && npm run build-lite", | ||
"dev": "rollup -c -w", | ||
"dev-lite": "rollup -c rollup.config.lite.js -w", | ||
"test": "tsc && rollup -c && ava --verbose", | ||
"prepublishOnly": "npm run buildAll && ava --verbose && npm run doc && npm run doc-md", | ||
"prepublishOnly": "tsc && npm run build && ava --verbose && npm run doc && npm run doc-md", | ||
"doc": "jsdoc --tutorials guide_notes --readme README.md --configure jsdoc.json --verbose", | ||
@@ -26,0 +21,0 @@ "doc-md": "jsdoc2md src/** > API.md" |
@@ -7,4 +7,2 @@ # es6-tween | ||
[![gzipsize](http://img.badgesize.io/http://unpkg.com/es6-tween?compression=gzip&cache=false)](http://unpkg.com/es6-tween) | ||
[![size-lite](http://img.badgesize.io/http://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/http://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) | ||
[![CDNJS](https://img.shields.io/cdnjs/v/es6-tween.svg)](https://cdnjs.com/libraries/es6-tween) | ||
@@ -33,29 +31,2 @@ [![jsdelivr](https://img.shields.io/badge/cdn-jsdelivr-brightgreen.svg)](https://cdn.jsdelivr.net/npm/es6-tween) [![unpkg](https://img.shields.io/badge/cdn-unpkg-brightgreen.svg)](https://unpkg.com/es6-tween) [![npmcdn](https://img.shields.io/badge/cdn-npmcdn-brightgreen.svg)](https://npmcdn.com/es6-tween) | ||
# Adversiting | ||
* Backers will be show there | ||
* The user @dalisoft is looking for job, you can contact to me via [e-mail](mailto:dalisoft@mail.ru), or at [Twitter](https://twitter.com/dalisoft) | ||
# `Lite` version | ||
You can use the `Lite` version of ES6 which lighter (~9Kb minified, ~3Kb min&gzip), faster (~10% faster execution speed), simpler (like the original one), memory effecient and better (can tween second-level Objects/Array). Optimized for runtime performance, no-lag anymore. | ||
When you want building mobile apps that loading files from server, use `Lite` for better performance. | ||
Differences when using `Lite`: | ||
* 2-times lighter size | ||
* No `Timeline` instance | ||
* No `String` tween support | ||
* No `Deep tween` support (does 2-level) | ||
* Uses original `Interpolation` instances for `Bezier` interpolation | ||
* Faster performance and execution speed | ||
* Memory effecient | ||
* No more shims required | ||
* No `Plugins` support | ||
* No `DOM Get/Set`, `Renderer` instance/plugin/add-on support | ||
* No full-Event system, just 3 event support (`onStart`, `onUpdate`, `onComplete`) | ||
* No `seek`, `reverse`, `restart` support | ||
* No event fire when `stop`, `pause`, `etc` | ||
* No `*`, `/`, `%` relatives support | ||
## Plugins | ||
@@ -85,28 +56,15 @@ | ||
* Now you can load from CDN both version `Full` and `Lite` | ||
* Now you can load from CDN | ||
```html | ||
<!-- jsDelivr --> | ||
<!-- Full --> | ||
<script src="https://cdn.jsdelivr.net/npm/es6-tween"></script> | ||
<!-- Lite --> | ||
<script src="https://cdn.jsdelivr.net/npm/es6-tween/lite/Tween.min.js"></script> | ||
<!-- unpkg --> | ||
<!-- Full --> | ||
<script src="https://unpkg.com/es6-tween"></script> | ||
<!-- Lite --> | ||
<script src="https://unpkg.com/es6-tween/lite/Tween.min.js"></script> | ||
<!-- npmcdn --> | ||
<!-- Full --> | ||
<script src="https://npmcdn.com/es6-tween"></script> | ||
<!-- Lite --> | ||
<script src="https://npmcdn.com/es6-tween/lite/Tween.min.js"></script> | ||
``` | ||
@@ -141,15 +99,7 @@ | ||
// ES6 | ||
// Full | ||
import { Easing, Tween, autoPlay } from 'es6-tween' | ||
// Lite | ||
import { Easing, Interpolation, Tween, autoPlay } from 'es6-tween/src/index.lite' | ||
// CommonJS | ||
// Full | ||
const { Tween, Easing, autoPlay } = require('es6-tween') | ||
// Lite | ||
const { Easing, Interpolation, Tween, autoPlay } = require('es6-tween/lite/Tween') | ||
</script> | ||
@@ -171,7 +121,3 @@ ``` | ||
```javascript | ||
// Full | ||
const { Tween, Easing, autoPlay } = require('es6-tween'); | ||
// Lite | ||
const { Tween, Interpolation, Easing, autoPlay } = require('es6-tween/lite/Tween'); | ||
``` | ||
@@ -178,0 +124,0 @@ |
var rollup = require('rollup') | ||
var commonjs = require('rollup-plugin-commonjs'); | ||
var nodeResolve = require('rollup-plugin-node-resolve'); | ||
var plugins = [ | ||
nodeResolve({ | ||
main: true, | ||
jsnext: true | ||
}), | ||
commonjs({ | ||
include: ['node_modules/intertween/index.js'] | ||
}) | ||
] | ||
export default { | ||
@@ -21,9 +9,5 @@ input: 'src/index.js', | ||
}, | ||
globals: { | ||
'intertween': 'InterTween' | ||
}, | ||
sourcemap: true, | ||
context: 'this', | ||
name: 'TWEEN', | ||
plugins: plugins | ||
name: 'TWEEN' | ||
} |
@@ -48,6 +48,2 @@ /* global process */ | ||
var _stopTicker = cancelAnimationFrame; | ||
var lastTime = now(); | ||
var delta = 0; | ||
var timeDiff = 0; | ||
var frameMs = 50 / 3; | ||
/** | ||
@@ -67,5 +63,10 @@ * Adds tween to list | ||
} | ||
if (_tweens.length > 0) { | ||
i = _tweens.length - 1; | ||
var tweenPrev = _tweens[i]; | ||
tween.prev = tweenPrev; | ||
tweenPrev.next = tween; | ||
} | ||
_tweens.push(tween); | ||
if (_autoPlay && !isStarted) { | ||
lastTime = now(); | ||
_tick = _ticker(update); | ||
@@ -154,11 +155,6 @@ isStarted = true; | ||
time = time !== undefined ? time : now(); | ||
delta = time - lastTime; | ||
if (delta > 150) { | ||
timeDiff = delta - frameMs; | ||
} | ||
lastTime = time; | ||
if (_autoPlay && isStarted) { | ||
_tick = _ticker(update); | ||
} | ||
if (_tweens.length === 0) { | ||
if (!_tweens.length) { | ||
_stopTicker(_tick); | ||
@@ -171,12 +167,4 @@ isStarted = false; | ||
while (i < _tweens.length) { | ||
tween = _tweens[i]; | ||
if (timeDiff) { | ||
tween._startTime += timeDiff; | ||
} | ||
tween.update(time, preserve); | ||
i++; | ||
_tweens[i++].update(time, preserve); | ||
} | ||
if (timeDiff) { | ||
timeDiff = 0; | ||
} | ||
return true; | ||
@@ -183,0 +171,0 @@ }; |
@@ -1,2 +0,1 @@ | ||
import Interpolator from 'intertween'; | ||
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
@@ -8,2 +7,2 @@ import Easing from './Easing'; | ||
import './shim'; | ||
export { Plugins, Selector, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; | ||
export { Plugins, Selector, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; |
@@ -1,2 +0,1 @@ | ||
import Interpolator from 'intertween'; | ||
import { add, onTick, autoPlay, get, getAll, has, isRunning, now, Plugins, remove, removeAll, update } from './core'; | ||
@@ -8,2 +7,2 @@ import Easing from './Easing'; | ||
import './shim'; | ||
export { Plugins, Selector, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; | ||
export { Plugins, Selector, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; |
@@ -1,1 +0,1 @@ | ||
export default function (node: any, tween: any): any; | ||
export default function (node: any, object: any, tween: any): any; |
@@ -0,5 +1,6 @@ | ||
import { remove } from './core'; | ||
var Store = {}; | ||
export default function (node, tween) { | ||
export default function (node, object, tween) { | ||
if (!node || !node.nodeType) { | ||
return tween; | ||
return object; | ||
} | ||
@@ -10,10 +11,21 @@ var ID = node.queueID || 'q_' + Date.now(); | ||
} | ||
if (Store[ID]) { | ||
if (tween) { | ||
Store[ID] = tween; //assign(Store[ID], tween) | ||
var storeID = Store[ID]; | ||
if (storeID) { | ||
if (storeID.object === object && node === storeID.tween.node) { | ||
remove(storeID.tween); | ||
} | ||
return Store[ID]; | ||
else { | ||
for (var prop in object) { | ||
if (prop in storeID.object[prop]) { | ||
if (tween.startTime === storeID.tween.startTime) { | ||
delete storeID.object[prop]; | ||
} | ||
} | ||
} | ||
return object; | ||
} | ||
return storeID.object; | ||
} | ||
Store[ID] = tween; | ||
Store[ID] = { tween: tween, object: object }; | ||
return Store[ID]; | ||
} |
@@ -21,3 +21,4 @@ var __extends = (this && this.__extends) || (function () { | ||
import PlaybackPosition from './PlaybackPosition'; | ||
import Tween, { EVENT_COMPLETE, EVENT_REPEAT, EVENT_REVERSE, EVENT_RS, EVENT_UPDATE, } from './Tween'; | ||
import Tween from './Tween'; | ||
import { EVENT_COMPLETE, EVENT_REPEAT, EVENT_REVERSE, EVENT_RESTART, EVENT_UPDATE, } from './constants'; | ||
import Selector from './selector'; | ||
@@ -211,3 +212,3 @@ export var shuffle = function (a) { | ||
add(this); | ||
return this.emit(EVENT_RS); | ||
return this.emit(EVENT_RESTART); | ||
}; | ||
@@ -214,0 +215,0 @@ Timeline.prototype.easing = function (easing) { |
@@ -1,12 +0,1 @@ | ||
import EventClass from './Event'; | ||
export declare const EVENT_UPDATE = "update"; | ||
export declare const EVENT_COMPLETE = "complete"; | ||
export declare const EVENT_START = "start"; | ||
export declare const EVENT_REPEAT = "repeat"; | ||
export declare const EVENT_REVERSE = "reverse"; | ||
export declare const EVENT_PAUSE = "pause"; | ||
export declare const EVENT_PLAY = "play"; | ||
export declare const EVENT_RS = "restart"; | ||
export declare const EVENT_STOP = "stop"; | ||
export declare const EVENT_SEEK = "seek"; | ||
export interface Params { | ||
@@ -23,3 +12,3 @@ quickRender?: boolean; | ||
* @namespace Tween | ||
* @extends EventClass | ||
* @extends Tween | ||
* @param {Object|Element} node Node Element or Tween initial object | ||
@@ -29,10 +18,11 @@ * @param {Object=} object If Node Element is using, second argument is used for Tween initial object | ||
*/ | ||
declare class Tween extends EventClass { | ||
declare class Tween { | ||
id: number; | ||
object: Object; | ||
_valuesStart: Object; | ||
_valuesEnd: Object; | ||
_valuesFunc: Function; | ||
_duration: number; | ||
_easingFunction: Function; | ||
_easingReverse: Function; | ||
_interpolationFunction: Function; | ||
_startTime: number; | ||
@@ -56,2 +46,5 @@ _initTime: number; | ||
private InitialValues; | ||
private _maxListener; | ||
private _chainedTweensCount; | ||
private _prevTime; | ||
/** | ||
@@ -90,2 +83,36 @@ * Easier way to call the Tween | ||
/** | ||
* Sets max `event` listener's count to Events system | ||
* @param {number} count - Event listener's count | ||
* @memberof Tween | ||
*/ | ||
setMaxListener(count?: number): this; | ||
/** | ||
* Adds `event` to Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
*/ | ||
on(event: string, callback: Function): this; | ||
/** | ||
* Adds `event` to Events system. | ||
* Removes itself after fired once | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
*/ | ||
once(event: string, callback: Function): this; | ||
/** | ||
* Removes `event` from Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
*/ | ||
off(event: string, callback: Function): this; | ||
/** | ||
* Emits/Fired/Trigger `event` from Events system listeners | ||
* @param {string} event - Event listener name | ||
* @memberof Tween | ||
*/ | ||
emit(event: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any): this; | ||
/** | ||
* @return {boolean} State of playing of tween | ||
@@ -140,3 +167,3 @@ * @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof Tween | ||
* @deprecated | ||
* @deprecated Not works as excepted, so we deprecated this method | ||
*/ | ||
@@ -186,2 +213,9 @@ seek(time: number, keepPlaying?: boolean): this; | ||
/** | ||
* Chained tweens | ||
* @param {any} arguments Arguments list | ||
* @example tween.chainedTweens(tween1, tween2) | ||
* @memberof Tween | ||
*/ | ||
chainedTweens(): this; | ||
/** | ||
* Sets how times tween is repeating | ||
@@ -216,2 +250,9 @@ * @param {amount} amount the times of repeat | ||
/** | ||
* Set interpolation | ||
* @param {Function} _interpolationFunction Interpolation function | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof Tween | ||
*/ | ||
interpolation(_interpolationFunction: Function): this; | ||
/** | ||
* Reassigns value for rare-case like Tween#restart or for Timeline | ||
@@ -218,0 +259,0 @@ * @private |
298
src/Tween.js
@@ -1,30 +0,7 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import InterTween from 'intertween'; | ||
import { create } from './shim'; | ||
import { add, now, Plugins, remove } from './core'; | ||
import Easing from './Easing'; | ||
import EventClass from './Event'; | ||
import Interpolation from './Interpolation'; | ||
import NodeCache from './NodeCache'; | ||
import Selector from './selector'; | ||
Object.create = create; | ||
// Events list | ||
export var EVENT_UPDATE = 'update'; | ||
export var EVENT_COMPLETE = 'complete'; | ||
export var EVENT_START = 'start'; | ||
export var EVENT_REPEAT = 'repeat'; | ||
export var EVENT_REVERSE = 'reverse'; | ||
export var EVENT_PAUSE = 'pause'; | ||
export var EVENT_PLAY = 'play'; | ||
export var EVENT_RS = 'restart'; | ||
export var EVENT_STOP = 'stop'; | ||
export var EVENT_SEEK = 'seek'; | ||
import { decompose, recompose, deepCopy, SET_NESTED, EVENT_CALLBACK, CHAINED_TWEENS, EVENT_UPDATE, EVENT_COMPLETE, EVENT_START, EVENT_REPEAT, EVENT_REVERSE, EVENT_PAUSE, EVENT_PLAY, EVENT_RESTART, EVENT_STOP, EVENT_SEEK, FRAME_MS, TOO_LONG_FRAME_MS, DECIMAL } from './constants'; | ||
var _id = 0; // Unique ID | ||
@@ -37,3 +14,3 @@ var defaultEasing = Easing.Linear.None; | ||
* @namespace Tween | ||
* @extends EventClass | ||
* @extends Tween | ||
* @param {Object|Element} node Node Element or Tween initial object | ||
@@ -43,9 +20,8 @@ * @param {Object=} object If Node Element is using, second argument is used for Tween initial object | ||
*/ | ||
var Tween = /** @class */ (function (_super) { | ||
__extends(Tween, _super); | ||
var Tween = /** @class */ (function () { | ||
function Tween(node, object) { | ||
var _this = _super.call(this) || this; | ||
_this.id = _id++; | ||
this._chainedTweensCount = 0; | ||
this.id = _id++; | ||
if (!!node && typeof node === 'object' && !object && !node.nodeType) { | ||
object = _this.object = node; | ||
object = this.object = node; | ||
node = null; | ||
@@ -55,22 +31,25 @@ } | ||
(node.nodeType || node.length || typeof node === 'string')) { | ||
node = _this.node = Selector(node); | ||
object = _this.object = NodeCache(node, object); | ||
node = this.node = Selector(node); | ||
object = this.object = NodeCache(node, object, this); | ||
} | ||
_this._valuesEnd = null; | ||
_this._valuesFunc = null; | ||
_this._duration = 1000; | ||
_this._easingFunction = defaultEasing; | ||
_this._easingReverse = defaultEasing; | ||
_this._startTime = 0; | ||
_this._initTime = 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; | ||
return _this; | ||
this._valuesEnd = null; | ||
this._valuesStart = {}; | ||
this._duration = 1000; | ||
this._easingFunction = defaultEasing; | ||
this._easingReverse = defaultEasing; | ||
this._interpolationFunction = Interpolation.Linear; | ||
this._startTime = 0; | ||
this._initTime = 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._maxListener = 5; | ||
this._prevTime = null; | ||
return this; | ||
} | ||
@@ -123,2 +102,99 @@ /** | ||
/** | ||
* Sets max `event` listener's count to Events system | ||
* @param {number} count - Event listener's count | ||
* @memberof Tween | ||
*/ | ||
Tween.prototype.setMaxListener = function (count) { | ||
if (count === void 0) { count = 5; } | ||
this._maxListener = count; | ||
return this; | ||
}; | ||
/** | ||
* Adds `event` to Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
*/ | ||
Tween.prototype.on = function (event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (!this[callbackId]) { | ||
this[callbackId] = callback; | ||
} | ||
break; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Adds `event` to Events system. | ||
* Removes itself after fired once | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
*/ | ||
Tween.prototype.once = function (event, callback) { | ||
var _this = this; | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
var _loop_1 = function (i) { | ||
var callbackId = callbackName + i; | ||
if (!this_1[callbackId]) { | ||
this_1[callbackId] = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
callback.apply(_this, args); | ||
_this[callbackId] = null; | ||
}; | ||
return "break"; | ||
} | ||
}; | ||
var this_1 = this; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var state_1 = _loop_1(i); | ||
if (state_1 === "break") | ||
break; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Removes `event` from Events system | ||
* @param {string} event - Event listener name | ||
* @param {Function} callback - Event listener callback | ||
* @memberof Tween | ||
*/ | ||
Tween.prototype.off = function (event, callback) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId] === callback) { | ||
this[callbackId] = null; | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Emits/Fired/Trigger `event` from Events system listeners | ||
* @param {string} event - Event listener name | ||
* @memberof Tween | ||
*/ | ||
Tween.prototype.emit = function (event, arg1, arg2, arg3, arg4) { | ||
var _maxListener = this._maxListener; | ||
var callbackName = event + EVENT_CALLBACK; | ||
if (!this[callbackName + 0]) { | ||
return this; | ||
} | ||
for (var i = 0; i < _maxListener; i++) { | ||
var callbackId = callbackName + i; | ||
if (this[callbackId]) { | ||
this[callbackId](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* @return {boolean} State of playing of tween | ||
@@ -198,3 +274,3 @@ * @example tween.isPlaying() // returns `true` if tween in progress | ||
add(this); | ||
return this.emit(EVENT_RS, this.object); | ||
return this.emit(EVENT_RESTART, this.object); | ||
}; | ||
@@ -207,3 +283,3 @@ /** | ||
* @memberof Tween | ||
* @deprecated | ||
* @deprecated Not works as excepted, so we deprecated this method | ||
*/ | ||
@@ -266,6 +342,8 @@ Tween.prototype.seek = function (time, keepPlaying) { | ||
} | ||
var _a = this, _valuesEnd = _a._valuesEnd, object = _a.object, Renderer = _a.Renderer, node = _a.node, InitialValues = _a.InitialValues, _easingFunction = _a._easingFunction; | ||
var _a = this, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, Renderer = _a.Renderer, node = _a.node, InitialValues = _a.InitialValues, _easingFunction = _a._easingFunction; | ||
SET_NESTED(object); | ||
SET_NESTED(_valuesEnd); | ||
if (node && InitialValues) { | ||
if (!object) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd)); | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd), this); | ||
} | ||
@@ -288,4 +366,11 @@ else if (!_valuesEnd) { | ||
} | ||
if ((typeof start === 'number' && isNaN(start)) || start === null || end === null || start === undefined || end === undefined || start === end) { | ||
continue; | ||
} | ||
if (Array.isArray(end) && typeof start === 'number') { | ||
end.unshift(start); | ||
} | ||
_valuesStart[property] = deepCopy(start); | ||
decompose(property, object, _valuesStart, _valuesEnd); | ||
} | ||
this._valuesFunc = InterTween(object, _valuesEnd, null, _easingFunction); | ||
if (Renderer && this.node) { | ||
@@ -308,3 +393,3 @@ this.__render = new Renderer(this, object, _valuesEnd); | ||
this._startTime += this._delayTime; | ||
this._initTime = this._startTime; | ||
this._initTime = this._prevTime = this._startTime; | ||
this._onStartCallbackFired = false; | ||
@@ -322,7 +407,7 @@ this._rendered = false; | ||
Tween.prototype.stop = function () { | ||
var _a = this, _isPlaying = _a._isPlaying, _isFinite = _a._isFinite, object = _a.object, _startTime = _a._startTime, _delayTime = _a._delayTime, _duration = _a._duration, _r = _a._r; | ||
if (!_isPlaying || !_isFinite) { | ||
var _a = this, _isPlaying = _a._isPlaying, _isFinite = _a._isFinite, object = _a.object, _startTime = _a._startTime, _delayTime = _a._delayTime, _duration = _a._duration, _r = _a._r, _yoyo = _a._yoyo, _reversed = _a._reversed; | ||
if (!_isPlaying) { | ||
return this; | ||
} | ||
var atEnd = (_r + 1) % 2 === 1; | ||
var atEnd = _isFinite ? ((_r + 1) % 2 === 1) && _yoyo : _reversed; | ||
this._reversed = false; | ||
@@ -350,2 +435,18 @@ if (atEnd) { | ||
/** | ||
* Chained tweens | ||
* @param {any} arguments Arguments list | ||
* @example tween.chainedTweens(tween1, tween2) | ||
* @memberof Tween | ||
*/ | ||
Tween.prototype.chainedTweens = function () { | ||
this._chainedTweensCount = arguments.length; | ||
if (!this._chainedTweensCount) { | ||
return this; | ||
} | ||
for (var i = 0, len = this._chainedTweensCount; i < len; i++) { | ||
this[CHAINED_TWEENS + i] = arguments[i]; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Sets how times tween is repeating | ||
@@ -357,3 +458,3 @@ * @param {amount} amount the times of repeat | ||
Tween.prototype.repeat = function (amount) { | ||
this._repeat = typeof amount === 'function' ? amount(this._repeat) : amount; | ||
this._repeat = !this._duration ? 0 : typeof amount === 'function' ? amount(this._repeat) : amount; | ||
this._r = this._repeat; | ||
@@ -403,2 +504,14 @@ this._isFinite = isFinite(amount); | ||
/** | ||
* Set interpolation | ||
* @param {Function} _interpolationFunction Interpolation function | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof Tween | ||
*/ | ||
Tween.prototype.interpolation = function (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Reassigns value for rare-case like Tween#restart or for Timeline | ||
@@ -409,3 +522,3 @@ * @private | ||
Tween.prototype.reassignValues = function (time) { | ||
var _a = this, _valuesFunc = _a._valuesFunc, object = _a.object, _delayTime = _a._delayTime; | ||
var _a = this, _valuesStart = _a._valuesStart, object = _a.object, _delayTime = _a._delayTime; | ||
this._isPlaying = true; | ||
@@ -416,3 +529,2 @@ this._startTime = time !== undefined ? time : now(); | ||
add(this); | ||
var _valuesStart = _valuesFunc(0); | ||
for (var property in _valuesStart) { | ||
@@ -433,9 +545,24 @@ var start = _valuesStart[property]; | ||
Tween.prototype.update = function (time, preserve, forceTime) { | ||
var _a = this, _onStartCallbackFired = _a._onStartCallbackFired, _easingFunction = _a._easingFunction, _easingReverse = _a._easingReverse, _repeat = _a._repeat, _delayTime = _a._delayTime, _reverseDelayTime = _a._reverseDelayTime, _yoyo = _a._yoyo, _reversed = _a._reversed, _startTime = _a._startTime, _duration = _a._duration, _valuesFunc = _a._valuesFunc, object = _a.object, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying, __render = _a.__render; | ||
var _a = this, _onStartCallbackFired = _a._onStartCallbackFired, _easingFunction = _a._easingFunction, _interpolationFunction = _a._interpolationFunction, _easingReverse = _a._easingReverse, _repeat = _a._repeat, _delayTime = _a._delayTime, _reverseDelayTime = _a._reverseDelayTime, _yoyo = _a._yoyo, _reversed = _a._reversed, _startTime = _a._startTime, _prevTime = _a._prevTime, _duration = _a._duration, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, object = _a.object, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying, __render = _a.__render, _chainedTweensCount = _a._chainedTweensCount; | ||
var elapsed; | ||
var currentEasing; | ||
time = time !== undefined ? time : now(); | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
return true; | ||
var property; | ||
if (!_duration) { | ||
elapsed = 1; | ||
} | ||
else { | ||
time = time !== undefined ? time : now(); | ||
var delta = _startTime - _prevTime; | ||
if (delta > TOO_LONG_FRAME_MS) { | ||
_startTime -= delta - FRAME_MS; | ||
this._startTime = _startTime; | ||
} | ||
this._prevTime = time; | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
return true; | ||
} | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
} | ||
if (!_onStartCallbackFired) { | ||
@@ -445,3 +572,2 @@ if (!this._rendered) { | ||
this._rendered = true; | ||
_valuesFunc = this._valuesFunc; | ||
} | ||
@@ -451,5 +577,2 @@ this.emit(EVENT_START, object); | ||
} | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
currentEasing = _reversed | ||
@@ -461,3 +584,25 @@ ? _easingReverse || _easingFunction | ||
} | ||
_valuesFunc(elapsed, elapsed, currentEasing); | ||
for (property in _valuesEnd) { | ||
var start = _valuesStart[property]; | ||
if (start === undefined || start === null) { | ||
continue; | ||
} | ||
var end = _valuesEnd[property]; | ||
var value = currentEasing[property] ? currentEasing[property](elapsed) : typeof currentEasing === 'function' ? currentEasing(elapsed) : defaultEasing(elapsed); | ||
if (typeof end === 'number') { | ||
object[property] = (((start + (end - start) * value) * DECIMAL) | 0) / DECIMAL; | ||
} | ||
else if (Array.isArray(end) && typeof start === 'number') { | ||
object[property] = _interpolationFunction(end, value); | ||
} | ||
else if (end && end.update) { | ||
end.update(value); | ||
} | ||
else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} | ||
else { | ||
recompose(property, object, _valuesStart, _valuesEnd, value, elapsed); | ||
} | ||
} | ||
if (__render) { | ||
@@ -467,4 +612,4 @@ __render.update(object, elapsed); | ||
this.emit(EVENT_UPDATE, object, elapsed); | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (elapsed === 1 || (_reversed && !elapsed)) { | ||
if (_repeat > 0 && _duration > 0) { | ||
if (_isFinite) { | ||
@@ -493,2 +638,7 @@ this._repeat--; | ||
this._repeat = this._r; | ||
if (_chainedTweensCount) { | ||
for (var i = 0; i < _chainedTweensCount; i++) { | ||
this[CHAINED_TWEENS + i].start(time + _duration); | ||
} | ||
} | ||
return false; | ||
@@ -500,3 +650,3 @@ } | ||
return Tween; | ||
}(EventClass)); | ||
}()); | ||
export default Tween; |
@@ -57,3 +57,3 @@ import test from 'ava' | ||
let tween = new Tween(obj) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+=1' }, 100) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+1' }, 100) | ||
.start(0) | ||
@@ -104,5 +104,5 @@ | ||
let obj = { x: 0, y: [2, 4, 6] } | ||
let obj = { x: 0 } | ||
let tween = new Tween(obj) | ||
.to({ x: [1, 3, 5], y: 10 }, 100) | ||
.to({ x: [1, 3, 5] }, 100) | ||
.start(0) | ||
@@ -117,3 +117,2 @@ | ||
t.deepEqual(obj.y, [6, 7, 8], 'Tween-them failed') | ||
t.log('Start-value interpolation was done') | ||
@@ -120,0 +119,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
446545
36
4136
241