es6-tween
Advanced tools
Comparing version 3.8.19 to 3.8.22
@@ -1,3 +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(v,"").replace(_,","):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=M(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,h=null,y=[],v=0,_=s.length;v<_;v++){var m=s[v],g=u[v];y[v]="string"==typeof m&&1===m.indexOf("=")?m:null,c.test(m)?(p=v+2,h=v+11):l.test(m)&&(p=v,h=v+9),s[v]=g===m?null:null!==y[v]?r(g,m):m}return function(t,e,i){i||(i=o),e=void 0!==e?e:t;var a="";for(v=0;v<_;v++){var f=u[v],l=s[v],c=y[v],d="function"==typeof i?i(t):t;a+="number"==typeof l?null!==p&&v>p&&v<h?f+(l-f)*d|0:((f+(l-f)*d)*n|0)/n:f,1===e&&null!==c&&(u[v]=l,s[v]=r(l,c))}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]=h(0===o?t:e[o-1],s,n,r&&r[o]||r)}var a=e[e.length-1];i.push(h(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(),h=[],l=Math.min(t.length,e.length),c=0;c<l;c++){var d=f[c],y=e[c];void 0!==d&&null!==d?(h[c]="string"==typeof y&&1===y.indexOf("=")?y:null,f[c]=y.nodeType||y.update?y.update:d===y?null:g(y)?g(d)&&y.length===d.length?a(d,y,n,i&&i[c]||i):s(d,y,n,i&&i[c]||i):g(d)?u(d,y,n,i&&i[c]||i):"object"==typeof d?p(d,y,n,i&&i[c]||i):"string"==typeof d?o(d,y,n,i&&i[c]||i):void 0!==d?d:y,e[c]=null!==h[c]?r(d,y):y):("function"==typeof y||y&&y.update)&&(f[c]=y)}return function(o,u,s){s||(s=i);for(var a=0;a<l;a++){var p=f[a],c=e[a],d=h[a];if(null!==p&&void 0!==p){var y=y="function"==typeof s?s:s&&"function"==typeof s[a]?s[a]:null,v=y?y(o):o;t[a]="number"==typeof p?((p+(c-p)*v)*n|0)/n:"function"==typeof p?p(y?o:v,u,y):p.update?p.update(v,u,y):c&&c.update?c.update(v,u,y):c,d&&1===u&&(f[a]=c,e[a]=r(f[a],d))}}return 1===u?e: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,h=((o+(u-o)*p)*n|0)/n+s;return a&&1===e&&(u=r(o=u,a)),h}}return!1}function p(t,e,n,i){n=null!==n&&void 0!==n?n:1e4;var f,h={},l={};w(e),w(t),w(i);for(var c in e){var d=t[c],y=e[c];if(void 0!==d&&null!==d){var v=P(t,c);h[c]="string"==typeof y&&1===y.indexOf("=")?y:null,v&&!1===v.writable&&!v.set&&(f||(f={}),f[c]=!0),l[c]=y.nodeType?y:y.update?y:d===y?null:g(y)?g(d)&&y.length===d.length?a(d,y,n,i&&i[c]||i):s(d,y,n,i&&i[c]||i):g(d)?u(d,y,n,i&&i[c]||i):"object"==typeof d?p(d,y,n,i&&i[c]||i):"string"==typeof d?o(d,y,n,i&&i[c]||i):void 0!==d?d:y,e[c]=null!==h[c]?r(d,y):y}else("function"==typeof y||y&&y.update)&&(l[c]=y)}return function(o,u,s){s||(s=i),u=void 0!==u?u:o;for(var a in l){var p=l[a],c=e[a],d=h[a],y="function"==typeof s?s:s&&"function"==typeof s[a]?s[a]:null,v=y?y(o):o,_="number"==typeof p?((p+(c-p)*v)*n|0)/n:"function"==typeof p?p(y?o:v,u,y):p&&p.update?p.update(v,u,y):c&&c.update?c.update(v,u,y):c;f&&f[a]||(t[a]=_),1===u&&d&&(l[a]=c,e[a]=r(l[a],d))}return 1===u?e:t}}function h(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 l=/rgb/g,c=/argb/g,d=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,y=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,v=/\n|\r|\t/g,_=/, | ,| , /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},M=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,P=j||function(){};return h})}),i=Object.create||function(t){return Object.assign({},t||{})},o="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,u=o.requestAnimationFrame||function(t){return o.setTimeout(t,16)},s=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=[],p=!1,h=!1,l=u,c=s,d=a(),y=0,v=0,_=function(t){var n=f.indexOf(t);n>-1&&f.splice(n,1),f.push(t),h&&!p&&(d=a(),e=l(b),p=!0)},m=function(t){for(var e=0;e<f.length;e++)if(t===f[e])return f[e];return null},g=function(t){var e=f.indexOf(t);-1!==e&&f.splice(e,1)},b=function(t,n){if(t=void 0!==t?t:a(),(y=t-d)>150&&(v=y-50/3),d=t,h&&p&&(e=l(b)),0===f.length)return c(e),p=!1,!1;for(var r,i=0;i<f.length;)r=f[i],v&&(r._startTime+=v),r.update(t,n),i++;return v&&(v=0),!0},T={},O={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-O.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*O.Bounce.In(2*t):.5*O.Bounce.Out(2*t-1)+.5}}},w=function(){this.totalTime=0,this.labels=[],this.offsets=[]};w.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},w.prototype.addLabel=function(t,e){return this.labels.push(t),this.offsets.push(this.parseLabel(t,e)),this},w.prototype.setLabel=function(t,e){var n=this.labels.indexOf(t);return-1!==n&&this.offsets.splice(n,1,this.parseLabel(t,e)),this},w.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 x=function(){this._events={}};x.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},x.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},x.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},x.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 M={},I=function(t,e){if(!t||!t.nodeType)return e;var n=t.queueID||"q_"+Date.now();return t.queueID||(t.queueID=n),M[n]?(e&&(M[n]=e),M[n]):(M[n]=e,M[n])},j=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};Object.create=i;var P=0,F=O.Linear.None,A=function(t){function e(e,n){return t.call(this),this.id=P++,!e||"object"!=typeof e||n||e.nodeType?e&&(e.nodeType||e.length||"string"==typeof e)&&(e=this.node=j(e),n=this.object=I(e,n)):(n=this.object=e,e=null),this._valuesEnd=null,this._valuesFunc=null,this._duration=1e3,this._easingFunction=F,this._easingReverse=F,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,g(this),this._pausedTime=a(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=a()-this._pausedTime,_(this),this._pausedTime=a(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this.reassignValues(),_(this),this.emit("restart",this.object)},e.prototype.seek=function(t,e){return this._startTime=a()+Math.max(0,Math.min(t,this._duration)),this._isPlaying=!0,_(this),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.object,o=e.Renderer,u=e.node,s=e.InitialValues,a=e._easingFunction;u&&s&&(i?n||(n=this._valuesEnd=s(u,i)):i=this.object=I(u,s(u,n)));for(var f in n){var p=i&&i[f],h=n[f];if(T[f]){var l=T[f].prototype.update?new T[f](t,p,h,f,i):T[f](t,p,h,f,i);l&&(n[f]=l)}else;}return this._valuesFunc=r(i,n,null,a),o&&this.node&&(this.__render=new o(this,i,n)),this},e.prototype.start=function(t){return this._startTime=void 0!==t?t:a(),this._startTime+=this._delayTime,this._onStartCallbackFired=!1,this._rendered=!1,this._isPlaying=!0,_(this),this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t._isFinite,r=t.object,i=t._startTime,o=t._delayTime,u=t._duration;return e&&n?(this._startTime=i=i+o+u,this.update(i),g(this),this.emit("stop",r)):this},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.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(t){var e=this,n=e._valuesFunc,r=e.object,i=e._delayTime;this._isPlaying=!0,this._startTime=void 0!==t?t:a(),this._startTime+=i,this._reversed=!1,_(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){var n,r,i=this,o=i._onStartCallbackFired,u=i._easingFunction,s=i._easingReverse,f=i._repeat,p=i._repeatDelayTime,h=i._reverseDelayTime,l=i._yoyo,c=i._reversed,d=i._startTime,y=i._duration,v=i._valuesFunc,_=i.object,m=i._isFinite,b=i._isPlaying,T=i.__render;return t=void 0!==t?t:a(),!b||t<d||(o||(this._rendered||(this.render(),this._rendered=!0,v=this._valuesFunc),this.emit("start",_),this._onStartCallbackFired=!0),n=(t-d)/y,n=n>1?1:n,n=c?1-n:n,r=c?s:u,!_||(v(n,n,r),T&&T.update(_,n),this.emit("update",_,n),!(1===n||c&&0===n)||(f?(m&&this._repeat--,l&&(this._reversed=!c),this.emit(l&&!c?"reverse":"repeat",_),this._startTime=!c&&p?t+p:c&&h?t+h:t,!0):(e||(this._isPlaying=!1,g(this),P--),this.emit("complete",_),this._repeat=this._r,!1))))},e}(x),L=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},q=0,D=function(t){function e(e){return t.call(this),this._duration=0,this._startTime=a(),this._tweens=[],this._elapsed=0,this._id=q++,this._defaultParams=e,this.position=new w,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 L(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((e=j(e,!0))&&e.length){this._defaultParams&&(i=Object.assign({},this._defaultParams,i));for(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),f=0,p=void 0,h=e.length;f<h;f++)p=e[f],o.add(t.fromTo(p,"function"==typeof n?n(f,e.length):Object.assign({},n),"function"==typeof r?r(f,e.length):r,"function"==typeof i?i(f,e.length):i),a[f])}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,a),e._delayTime=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+=a(),_(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,p=e._isFinite;if(!e._isPlaying||t<u)return!0;var h=(t-u)/r;h=h>1?1:h,h=s?1-h:h;for(var l=t-u,c=s?r-l:l,d=0;d<n.length;)n[d].update(c),d++;if(this.emit("update",h,l),1===h||s&&0===h){if(f){for(p&&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,d=0;d<n.length;)n[d].reassignValues(t),d++;return!0}return this.emit("complete"),this._repeat=this._r,g(this),this._isPlaying=!1,!1}return!0},e.prototype.elapsed=function(t){return void 0!==t?this.update(t*this._duration):this._elapsed},e}(A);t.Plugins=T,t.Selector=j,t.Interpolator=r,t.onTick=function(t){return f.push({update:t})},t.has=function(t){return null!==m(t)},t.get=m,t.getAll=function(){return f},t.removeAll=function(){f.length=0},t.remove=g,t.add=_,t.now=a,t.update=b,t.autoPlay=function(t){h=t},t.isRunning=function(){return p},t.Tween=A,t.Easing=O,t.Timeline=D,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=full/Tween.min.js.map | ||
//# sourceMappingURL=Tween.min.js.map | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN=t.TWEEN||{})}(this,function(t){"use strict";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,n._repeat,n._initTime+t);return this._isPlaying=!0,e&&m(this),this.update(r,!1,!0),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;return e&&n?((u+1)%2==1?this.update(i+o):this.update(i),b(this),this.emit("stop",r)):this},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.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,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._repeatDelayTime,o._reverseDelayTime),c=o._yoyo,h=o._reversed,d=o._startTime,y=o._duration,_=o._valuesFunc,v=o.object,m=o._isFinite,g=o._isPlaying,T=o.__render;return t=void 0!==t?t:f(),!g||t<d&&!n||(u||(this._rendered||(this.render(),this._rendered=!0,_=this._valuesFunc),this.emit("start",v),this._onStartCallbackFired=!0),r=(t-d)/y,r=r>1?1:r,r=h?1-r:r,i=h?a||s:s,!v||(_(r,r,i),T&&T.update(v,r),this.emit("update",v,r),!(1===r||h&&0===r)||(p?(m&&this._repeat--,c&&(this._reversed=!h),this.emit(c&&!h?"reverse":"repeat",v),this._startTime+=h&&l?y-l:y,!0):(e||(this._isPlaying=!1,b(this),A--),this.emit("complete",v),this._repeat=this._r,!1))))},e}(P),D=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)}}(),S=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},k=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 D(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 k(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=S({},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):S({},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._repeatDelayTime,o=e._reverseDelayTime,u=e._startTime,s=e._reversed,a=e._yoyo,f=e._repeat,p=e._isFinite;if(!e._isPlaying||t<u)return!0;var l=(t-u)/r;l=l>1?1:l,l=s?1-l:l,this.elapsed=l;for(var c=t-u,h=s?r-c:c,d=0;d<n.length;)n[d].update(h),d++;if(this.emit("update",l,c),1===l||s&&0===l){if(f){for(p&&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,d=0;d<n.length;)n[d].reassignValues(t),d++;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 (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.TWEEN = {}))); | ||
(factory((global.TWEEN = global.TWEEN || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -39,5 +39,5 @@ | ||
else { | ||
var offset = root.performance && root.performance.timing && root.performance.timing.navigationStart ? root.performance.timing.navigationStart : Date.now(); | ||
var offset_1 = root.performance && root.performance.timing && root.performance.timing.navigationStart ? root.performance.timing.navigationStart : Date.now(); | ||
return function () { | ||
return Date.now() - offset; | ||
return Date.now() - offset_1; | ||
}; | ||
@@ -223,3 +223,3 @@ } | ||
Linear: { | ||
None: function None(k) { | ||
None: function (k) { | ||
return k; | ||
@@ -229,9 +229,9 @@ } | ||
Quadratic: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return k * k; | ||
}, | ||
Out: function Out(k) { | ||
Out: function (k) { | ||
return k * (2 - k); | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
@@ -244,9 +244,9 @@ return 0.5 * k * k; | ||
Cubic: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return k * k * k; | ||
}, | ||
Out: function Out(k) { | ||
Out: function (k) { | ||
return --k * k * k + 1; | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
@@ -259,9 +259,9 @@ return 0.5 * k * k * k; | ||
Quartic: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return k * k * k * k; | ||
}, | ||
Out: function Out(k) { | ||
return 1 - (--k * k * k * k); | ||
Out: function (k) { | ||
return 1 - --k * k * k * k; | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
@@ -274,9 +274,9 @@ return 0.5 * k * k * k * k; | ||
Quintic: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return k * k * k * k * k; | ||
}, | ||
Out: function Out(k) { | ||
Out: function (k) { | ||
return --k * k * k * k * k + 1; | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
@@ -289,9 +289,9 @@ return 0.5 * k * k * k * k * k; | ||
Sinusoidal: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return 1 - Math.cos(k * Math.PI / 2); | ||
}, | ||
Out: function Out(k) { | ||
Out: function (k) { | ||
return Math.sin(k * Math.PI / 2); | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
return 0.5 * (1 - Math.cos(Math.PI * k)); | ||
@@ -301,9 +301,9 @@ } | ||
Exponential: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1); | ||
}, | ||
Out: function Out(k) { | ||
Out: function (k) { | ||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k); | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if (k === 0) { | ||
@@ -322,9 +322,9 @@ return 0; | ||
Circular: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return 1 - Math.sqrt(1 - k * k); | ||
}, | ||
Out: function Out(k) { | ||
return Math.sqrt(1 - (--k * k)); | ||
Out: function (k) { | ||
return Math.sqrt(1 - --k * k); | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if ((k *= 2) < 1) { | ||
@@ -337,3 +337,3 @@ return -0.5 * (Math.sqrt(1 - k * k) - 1); | ||
Elastic: { | ||
In: function In(k) { | ||
In: function (k) { | ||
if (k === 0) { | ||
@@ -347,3 +347,3 @@ return 0; | ||
}, | ||
Out: function Out(k) { | ||
Out: function (k) { | ||
if (k === 0) { | ||
@@ -357,3 +357,3 @@ return 0; | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if (k === 0) { | ||
@@ -367,17 +367,17 @@ return 0; | ||
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)); | ||
} | ||
return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1; | ||
return (0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1); | ||
} | ||
}, | ||
Back: { | ||
In: function In(k) { | ||
In: function (k) { | ||
var s = 1.70158; | ||
return k * k * ((s + 1) * k - s); | ||
}, | ||
Out: function Out(k) { | ||
Out: function (k) { | ||
var s = 1.70158; | ||
return --k * k * ((s + 1) * k + s) + 1; | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
var s = 1.70158 * 1.525; | ||
@@ -391,20 +391,20 @@ if ((k *= 2) < 1) { | ||
Bounce: { | ||
In: function In(k) { | ||
In: function (k) { | ||
return 1 - Easing.Bounce.Out(1 - k); | ||
}, | ||
Out: function Out(k) { | ||
if (k < (1 / 2.75)) { | ||
Out: function (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 / 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 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; | ||
return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375; | ||
} | ||
}, | ||
InOut: function InOut(k) { | ||
InOut: function (k) { | ||
if (k < 0.5) { | ||
@@ -415,2 +415,5 @@ return Easing.Bounce.In(k * 2) * 0.5; | ||
} | ||
}, | ||
Stepped: { | ||
steps: function (steps) { return function (k) { return ((k * steps) | 0) / steps; }; } | ||
} | ||
@@ -430,3 +433,3 @@ }; | ||
var Interpolation = { | ||
Linear: function Linear(v, k) { | ||
Linear: function (v, k) { | ||
var m = v.length - 1; | ||
@@ -444,3 +447,3 @@ var f = m * k; | ||
}, | ||
Bezier: function Bezier(v, k) { | ||
Bezier: function (v, k) { | ||
var b = 0; | ||
@@ -455,3 +458,3 @@ var n = v.length - 1; | ||
}, | ||
CatmullRom: function CatmullRom(v, k) { | ||
CatmullRom: function (v, k) { | ||
var m = v.length - 1; | ||
@@ -478,6 +481,6 @@ var f = m * k; | ||
Utils: { | ||
Linear: function Linear(p0, p1, t) { | ||
Linear: function (p0, p1, t) { | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0; | ||
}, | ||
Bernstein: function Bernstein(n, i) { | ||
Bernstein: function (n, i) { | ||
var fc = Interpolation.Utils.Factorial; | ||
@@ -500,3 +503,3 @@ return fc(n) / fc(i) / fc(n - i); | ||
})(), | ||
CatmullRom: function CatmullRom(p0, p1, p2, p3, t) { | ||
CatmullRom: function (p0, p1, p2, p3, t) { | ||
var v0 = (p2 - p0) * 0.5; | ||
@@ -523,406 +526,389 @@ var v1 = (p3 - p1) * 0.5; | ||
*/ | ||
var Lite = function Lite(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 | ||
* @param {Function} callback Function should be fired after tween is started | ||
* @example tween.onStart(object => console.log(object)) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.onStart = function onStart (callback) { | ||
this._onStartCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* onUpdate callback | ||
* @param {Function} callback Function should be fired while tween is in progress | ||
* @example tween.onUpdate(object => console.log(object)) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.onUpdate = function onUpdate (callback) { | ||
this._onUpdateCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* onComplete callback | ||
* @param {Function} callback Function should be fired after tween is finished | ||
* @example tween.onComplete(object => console.log(object)) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.onComplete = function onComplete (callback) { | ||
this._onCompleteCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* @return {boolean} State of playing of tween | ||
* @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.isPlaying = function isPlaying () { | ||
return this._isPlaying; | ||
}; | ||
/** | ||
* @return {boolean} State of started of tween | ||
* @example tween.isStarted() // returns `true` if tween in started | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.isStarted = function isStarted () { | ||
return this._onStartCallbackFired; | ||
}; | ||
/** | ||
* Pauses tween | ||
* @example tween.pause() | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.pause = function pause () { | ||
if (!this._isPlaying) { | ||
var Lite = /** @class */ (function () { | ||
function Lite(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; | ||
} | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this; | ||
}; | ||
/** | ||
* Play/Resume the tween | ||
* @example tween.play() | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.play = function play () { | ||
if (this._isPlaying) { | ||
/** | ||
* onStart callback | ||
* @param {Function} callback Function should be fired after tween is started | ||
* @example tween.onStart(object => console.log(object)) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.onStart = function (callback) { | ||
this._onStartCallback = callback; | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this; | ||
}; | ||
/** | ||
* Sets tween duration | ||
* @param {number} amount Duration is milliseconds | ||
* @example tween.duration(2000) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.duration = function duration (amount) { | ||
this._duration = | ||
typeof amount === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets target value and duration | ||
* @param {object} properties Target value (to value) | ||
* @param {number} [duration=1000] Duration of tween | ||
* @example new Tween({x:0}).to({x:200}, 2000) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.to = function to (properties, duration) { | ||
if ( duration === void 0 ) duration = 1000; | ||
this._valuesEnd = properties; | ||
this._duration = duration; | ||
return this; | ||
}; | ||
/** | ||
* Start the tweening | ||
* @param {number} time setting manual time instead of Current browser timestamp | ||
* @example tween.start() | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.start = function start (time) { | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += this._delayTime; | ||
var ref = this; | ||
var _valuesEnd = ref._valuesEnd; | ||
var _valuesStartRepeat = ref._valuesStartRepeat; | ||
var _valuesStart = ref._valuesStart; | ||
var _interpolationFunction = ref._interpolationFunction; | ||
var object = ref.object; | ||
var loop = function ( property ) { | ||
var start = object[property]; | ||
var end = _valuesEnd[property]; | ||
if (!object || object[property] === undefined) { | ||
return; | ||
}; | ||
/** | ||
* onUpdate callback | ||
* @param {Function} callback Function should be fired while tween is in progress | ||
* @example tween.onUpdate(object => console.log(object)) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.onUpdate = function (callback) { | ||
this._onUpdateCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* onComplete callback | ||
* @param {Function} callback Function should be fired after tween is finished | ||
* @example tween.onComplete(object => console.log(object)) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.onComplete = function (callback) { | ||
this._onCompleteCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* @return {boolean} State of playing of tween | ||
* @example tween.isPlaying() // returns `true` if tween in progress | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.isPlaying = function () { | ||
return this._isPlaying; | ||
}; | ||
/** | ||
* @return {boolean} State of started of tween | ||
* @example tween.isStarted() // returns `true` if tween in started | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.isStarted = function () { | ||
return this._onStartCallbackFired; | ||
}; | ||
/** | ||
* Pauses tween | ||
* @example tween.pause() | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.pause = function () { | ||
if (!this._isPlaying) { | ||
return this; | ||
} | ||
var obj = object[property]; | ||
if (typeof start === 'number') { | ||
if (typeof end === 'string') { | ||
_valuesStartRepeat[property] = end; | ||
end = start + parseFloat(end); | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this; | ||
}; | ||
/** | ||
* Play/Resume the tween | ||
* @example tween.play() | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.play = function () { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this; | ||
}; | ||
/** | ||
* Sets tween duration | ||
* @param {number} amount Duration is milliseconds | ||
* @example tween.duration(2000) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.duration = function (amount) { | ||
this._duration = | ||
typeof amount === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets target value and duration | ||
* @param {object} properties Target value (to value) | ||
* @param {number} [duration=1000] Duration of tween | ||
* @example new Tween({x:0}).to({x:200}, 2000) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.to = function (properties, duration) { | ||
if (duration === void 0) { duration = 1000; } | ||
this._valuesEnd = properties; | ||
this._duration = duration; | ||
return this; | ||
}; | ||
/** | ||
* Start the tweening | ||
* @param {number} time setting manual time instead of Current browser timestamp | ||
* @example tween.start() | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.start = function (time) { | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += this._delayTime; | ||
var _a = this, _valuesEnd = _a._valuesEnd, _valuesStartRepeat = _a._valuesStartRepeat, _valuesStart = _a._valuesStart, _interpolationFunction = _a._interpolationFunction, object = _a.object; | ||
var _loop_1 = function (property) { | ||
var start = object[property]; | ||
var end = _valuesEnd[property]; | ||
if (!object || object[property] === undefined) { | ||
return "continue"; | ||
} | ||
else if (Array.isArray(end)) { | ||
end.unshift(start); | ||
var _endArr = end; | ||
end = function (t) { | ||
return _interpolationFunction(_endArr, t); | ||
}; | ||
var 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); | ||
var _endArr_1 = end; | ||
end = function (t) { | ||
return _interpolationFunction(_endArr_1, t); | ||
}; | ||
} | ||
} | ||
} | ||
else if (typeof end === 'object') { | ||
if (Array.isArray(end)) { | ||
var _endArr$1 = end; | ||
var _start = start.map(function (item) { return item; }); | ||
var i = (void 0); | ||
var len = end.length; | ||
end = function (t) { | ||
i = 0; | ||
for (; i < len; i++) { | ||
obj[i] = | ||
typeof _start[i] === 'number' | ||
? _start[i] + (_endArr$1[i] - _start[i]) * t | ||
: _endArr$1[i]; | ||
else if (typeof end === 'object') { | ||
if (Array.isArray(end)) { | ||
var _endArr_2 = end; | ||
var _start_1 = start.map(function (item) { return item; }); | ||
var i_1; | ||
var len_1 = end.length; | ||
end = function (t) { | ||
i_1 = 0; | ||
for (; i_1 < len_1; i_1++) { | ||
obj[i_1] = | ||
typeof _start_1[i_1] === 'number' | ||
? _start_1[i_1] + (_endArr_2[i_1] - _start_1[i_1]) * t | ||
: _endArr_2[i_1]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
else { | ||
var _endObj_1 = end; | ||
var _start_2 = {}; | ||
for (var p in start) { | ||
_start_2[p] = start[p]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
else { | ||
var _endObj = end; | ||
var _start$1 = {}; | ||
for (var p in start) { | ||
_start$1[p] = start[p]; | ||
end = function (t) { | ||
for (var i in end) { | ||
obj[i] = | ||
typeof _start_2[i] === 'number' | ||
? _start_2[i] + (_endObj_1[i] - _start_2[i]) * t | ||
: _endObj_1[i]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
end = function (t) { | ||
for (var i in end) { | ||
obj[i] = | ||
typeof _start$1[i] === 'number' | ||
? _start$1[i] + (_endObj[i] - _start$1[i]) * t | ||
: _endObj[i]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
_valuesStart[property] = start; | ||
_valuesEnd[property] = end; | ||
}; | ||
for (var property in _valuesEnd) { | ||
_loop_1(property); | ||
} | ||
_valuesStart[property] = start; | ||
_valuesEnd[property] = end; | ||
this._isPlaying = true; | ||
this._reversed = false; | ||
this._onStartCallbackFired = false; | ||
add(this); | ||
return this; | ||
}; | ||
for (var property in _valuesEnd) loop( property ); | ||
this._isPlaying = true; | ||
this._reversed = false; | ||
this._onStartCallbackFired = false; | ||
add(this); | ||
return this; | ||
}; | ||
/** | ||
* Stops the tween | ||
* @example tween.stop() | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.stop = function stop () { | ||
var ref = this; | ||
var _isPlaying = ref._isPlaying; | ||
var _isFinite = ref._isFinite; | ||
var _startTime = ref._startTime; | ||
var _delayTime = ref._delayTime; | ||
var _duration = ref._duration; | ||
if (!_isPlaying || !_isFinite) { | ||
/** | ||
* Stops the tween | ||
* @example tween.stop() | ||
* @memberof Lite | ||
*/ | ||
Lite.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) { | ||
return this; | ||
} | ||
var atEnd = (_r + 1) % 2 === 1; | ||
if (atEnd) { | ||
this.update(_startTime + _duration); | ||
} | ||
else { | ||
this.update(_startTime); | ||
} | ||
remove(this); | ||
return this; | ||
} | ||
this._startTime = _startTime = _startTime + _delayTime + _duration; | ||
this.update(_startTime); | ||
remove(this); | ||
return this; | ||
}; | ||
/** | ||
* Set delay of tween | ||
* @param {number} amount Sets tween delay / wait duration | ||
* @example tween.delay(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.delay = function delay (amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets how times tween is repeating | ||
* @param {amount} amount the times of repeat | ||
* @example tween.repeat(2) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.repeat = function 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 | ||
* @param {number} amount Sets tween repeat delay / repeat wait duration | ||
* @example tween.repeatDelay(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.repeatDelay = function repeatDelay (amount) { | ||
this._repeatDelayTime = | ||
typeof amount === 'function' ? amount(this._repeatDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set delay of each repeat alternate of tween | ||
* @param {number} amount Sets tween repeat alternate delay / repeat alternate wait duration | ||
* @example tween.reverseDelay(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.reverseDelay = function reverseDelay (amount) { | ||
this._reverseDelayTime = | ||
typeof amount === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set `yoyo` state (enables reverse in repeat) | ||
* @param {boolean} state Enables alternate direction for repeat | ||
* @example tween.yoyo(true) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.yoyo = function yoyo (state) { | ||
this._yoyo = typeof state === 'function' ? state(this._yoyo) : state; | ||
return this; | ||
}; | ||
/** | ||
* Set easing | ||
* @param {Function} _easingFunction Easing function | ||
* @example tween.easing(Easing.Quadratic.InOut) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.easing = function easing (fn) { | ||
if (typeof fn === 'function') { | ||
this._easingFunction = fn; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Set interpolation | ||
* @param {Function} _interpolationFunction Interpolation function | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.interpolation = function interpolation (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Updates initial object to target value by given `time` | ||
* @param {Time} time Current time | ||
* @param {boolean=} preserve Prevents from removing tween from store | ||
* @example tween.update(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.update = function update$$1 (time, preserve) { | ||
var ref = this; | ||
var _onStartCallbackFired = ref._onStartCallbackFired; | ||
var _easingFunction = ref._easingFunction; | ||
var _repeat = ref._repeat; | ||
var _repeatDelayTime = ref._repeatDelayTime; | ||
var _reverseDelayTime = ref._reverseDelayTime; | ||
var _yoyo = ref._yoyo; | ||
var _reversed = ref._reversed; | ||
var _startTime = ref._startTime; | ||
var _duration = ref._duration; | ||
var _valuesStart = ref._valuesStart; | ||
var _valuesEnd = ref._valuesEnd; | ||
var _valuesStartRepeat = ref._valuesStartRepeat; | ||
var object = ref.object; | ||
var _isFinite = ref._isFinite; | ||
var _isPlaying = ref._isPlaying; | ||
var _onStartCallback = ref._onStartCallback; | ||
var _onUpdateCallback = ref._onUpdateCallback; | ||
var _onCompleteCallback = ref._onCompleteCallback; | ||
var elapsed; | ||
var value; | ||
var property; | ||
time = time !== undefined ? time : now(); | ||
if (!_isPlaying || time < _startTime) { | ||
return true; | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (_onStartCallback) { | ||
_onStartCallback(object); | ||
}; | ||
/** | ||
* Set delay of tween | ||
* @param {number} amount Sets tween delay / wait duration | ||
* @example tween.delay(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.delay = function (amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets how times tween is repeating | ||
* @param {amount} amount the times of repeat | ||
* @example tween.repeat(2) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.repeat = function (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 | ||
* @param {number} amount Sets tween repeat delay / repeat wait duration | ||
* @example tween.repeatDelay(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.repeatDelay = function (amount) { | ||
this._repeatDelayTime = | ||
typeof amount === 'function' ? amount(this._repeatDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set delay of each repeat alternate of tween | ||
* @param {number} amount Sets tween repeat alternate delay / repeat alternate wait duration | ||
* @example tween.reverseDelay(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.reverseDelay = function (amount) { | ||
this._reverseDelayTime = | ||
typeof amount === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set `yoyo` state (enables reverse in repeat) | ||
* @param {boolean} state Enables alternate direction for repeat | ||
* @example tween.yoyo(true) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.yoyo = function (state) { | ||
this._yoyo = typeof state === 'function' ? state(this._yoyo) : state; | ||
if (!state) { | ||
this._reversed = false; | ||
} | ||
this._onStartCallbackFired = true; | ||
} | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
value = _easingFunction(elapsed); | ||
for (property in _valuesEnd) { | ||
var start = _valuesStart[property]; | ||
var end = _valuesEnd[property]; | ||
if (start === undefined) { | ||
continue; | ||
return this; | ||
}; | ||
/** | ||
* Set easing | ||
* @param {Function} _easingFunction Easing function | ||
* @example tween.easing(Easing.Quadratic.InOut) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.easing = function (fn) { | ||
if (typeof fn === 'function') { | ||
this._easingFunction = fn; | ||
} | ||
else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
return this; | ||
}; | ||
/** | ||
* Set interpolation | ||
* @param {Function} _interpolationFunction Interpolation function | ||
* @example tween.interpolation(Interpolation.Bezier) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.interpolation = function (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value; | ||
return this; | ||
}; | ||
/** | ||
* Updates initial object to target value by given `time` | ||
* @param {Time} time Current time | ||
* @param {boolean=} preserve Prevents from removing tween from store | ||
* @example tween.update(500) | ||
* @memberof Lite | ||
*/ | ||
Lite.prototype.update = function (time, preserve) { | ||
var _a = this, _onStartCallbackFired = _a._onStartCallbackFired, _easingFunction = _a._easingFunction, _repeat = _a._repeat, _repeatDelayTime = _a._repeatDelayTime, _reverseDelayTime = _a._reverseDelayTime, _yoyo = _a._yoyo, _reversed = _a._reversed, _startTime = _a._startTime, _duration = _a._duration, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, _valuesStartRepeat = _a._valuesStartRepeat, object = _a.object, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying, _onStartCallback = _a._onStartCallback, _onUpdateCallback = _a._onUpdateCallback, _onCompleteCallback = _a._onCompleteCallback; | ||
var elapsed; | ||
var value; | ||
var property; | ||
time = time !== undefined ? time : now(); | ||
if (!_isPlaying || time < _startTime) { | ||
return true; | ||
} | ||
} | ||
if (_onUpdateCallback) { | ||
_onUpdateCallback(object, elapsed); | ||
} | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat--; | ||
if (!_onStartCallbackFired) { | ||
if (_onStartCallback) { | ||
_onStartCallback(object); | ||
} | ||
if (!_reversed) { | ||
for (property in _valuesStartRepeat) { | ||
_valuesStart[property] = _valuesEnd[property]; | ||
_valuesEnd[property] += parseFloat(_valuesStartRepeat[property]); | ||
} | ||
this._onStartCallbackFired = true; | ||
} | ||
elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
value = _easingFunction(elapsed); | ||
for (property in _valuesEnd) { | ||
var start = _valuesStart[property]; | ||
var end = _valuesEnd[property]; | ||
if (start === undefined) { | ||
continue; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed; | ||
else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime; | ||
else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value; | ||
} | ||
else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime; | ||
} | ||
if (_onUpdateCallback) { | ||
_onUpdateCallback(object, elapsed); | ||
} | ||
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 { | ||
this._startTime = time; | ||
if (!preserve) { | ||
this._isPlaying = false; | ||
remove(this); | ||
} | ||
if (_onCompleteCallback) { | ||
_onCompleteCallback(); | ||
} | ||
this._repeat = this._r; | ||
_id--; | ||
return false; | ||
} | ||
return true; | ||
} | ||
else { | ||
if (!preserve) { | ||
this._isPlaying = false; | ||
remove(this); | ||
} | ||
if (_onCompleteCallback) { | ||
_onCompleteCallback(); | ||
} | ||
this._repeat = this._r; | ||
_id--; | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
return true; | ||
}; | ||
return Lite; | ||
}()); | ||
@@ -929,0 +915,0 @@ exports.Plugins = Plugins; |
@@ -1,3 +0,1 @@ | ||
!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,i="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,e=i.requestAnimationFrame||function(t){return i.setTimeout(t,16)},r=i.cancelAnimationFrame||function(t){return i.clearTimeout(t)},o=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!==i.performance&&void 0!==i.performance.now)return i.performance.now.bind(i.performance);var t=i.performance&&i.performance.timing&&i.performance.timing.navigationStart?i.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),u=[],a=!1,s=!1,f=e,c=r,h=o(),l=0,p=0,_=function(t){var i=u.indexOf(t);i>-1&&u.splice(i,1),u.push(t),s&&!a&&(h=o(),n=f(v),a=!0)},y=function(t){for(var n=0;n<u.length;n++)if(t===u[n])return u[n];return null},d=function(t){var n=u.indexOf(t);-1!==n&&u.splice(n,1)},v=function(t,i){if(t=void 0!==t?t:o(),(l=t-h)>150&&(p=l-50/3),h=t,s&&a&&(n=f(v)),0===u.length)return c(n),a=!1,!1;for(var e,r=0;r<u.length;)e=u[r],p&&(e._startTime+=p),e.update(t,i),r++;return p&&(p=0),!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 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-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}}},M={Linear:function(t,n){var i=t.length-1,e=i*n,r=Math.floor(e),o=M.Utils.Linear;return n<0?o(t[0],t[1],e):n>1?o(t[i],t[i-1],i-e):o(t[r],t[r+1>i?i:r+1],e-r)},Bezier:function(t,n){for(var i=0,e=t.length-1,r=Math.pow,o=M.Utils.Bernstein,u=0;u<=e;u++)i+=r(1-n,e-u)*r(n,u)*t[u]*o(e,u);return i},CatmullRom:function(t,n){var i=t.length-1,e=i*n,r=Math.floor(e),o=M.Utils.CatmullRom;return t[0]===t[i]?(n<0&&(r=Math.floor(e=i*(1+n))),o(t[(r-1+i)%i],t[r],t[(r+1)%i],t[(r+2)%i],e-r)):n<0?t[0]-(o(t[0],t[0],t[1],t[1],-e)-t[0]):n>1?t[i]-(o(t[i],t[i],t[i-1],t[i-1],e-i)-t[i]):o(t[r?r-1:0],t[r],t[i<r+1?i:r+1],t[i<r+2?i:r+2],e-r)},Utils:{Linear:function(t,n,i){return"function"==typeof t?t(i):(n-t)*i+t},Bernstein:function(t,n){var i=M.Utils.Factorial;return i(t)/i(n)/i(t-n)},Factorial:function(){var t=[1];return function(n){var i=1;if(t[n])return t[n];for(var e=n;e>1;e--)i*=e;return t[n]=i,i}}(),CatmullRom:function(t,n,i,e,r){var o=.5*(i-t),u=.5*(e-n),a=r*r;return(2*n-2*i+o+u)*(r*a)+(-3*n+3*i-2*o-u)*a+o*r+n}}},T=0,b=function(t){return this.id=T++,this.object=t,this._valuesStart={},this._valuesEnd=null,this._valuesStartRepeat={},this._duration=1e3,this._easingFunction=g.Linear.None,this._interpolationFunction=M.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};b.prototype.onStart=function(t){return this._onStartCallback=t,this},b.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},b.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},b.prototype.isPlaying=function(){return this._isPlaying},b.prototype.isStarted=function(){return this._onStartCallbackFired},b.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,d(this),this._pausedTime=o(),this):this},b.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=o()-this._pausedTime,_(this),this._pausedTime=o(),this)},b.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},b.prototype.to=function(t,n){return void 0===n&&(n=1e3),this._valuesEnd=t,this._duration=n,this},b.prototype.start=function(t){this._startTime=void 0!==t?t:o(),this._startTime+=this._delayTime;var n=this,i=n._valuesEnd,e=n._valuesStartRepeat,r=n._valuesStart,u=n._interpolationFunction,a=n.object;for(var s in i)!function(t){var n=a[t],o=i[t];if(a&&void 0!==a[t]){var s=a[t];if("number"==typeof n){if("string"==typeof o)e[t]=o,o=n+parseFloat(o);else if(Array.isArray(o)){o.unshift(n);var f=o;o=function(t){return u(f,t)}}}else if("object"==typeof o)if(Array.isArray(o)){var c=o,h=n.map(function(t){return t}),l=void 0,p=o.length;o=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 _=o,y={};for(var d in n)y[d]=n[d];o=function(t){for(var n in o)s[n]="number"==typeof y[n]?y[n]+(_[n]-y[n])*t:_[n];return s}}r[t]=n,i[t]=o}}(s);return this._isPlaying=!0,this._reversed=!1,this._onStartCallbackFired=!1,_(this),this},b.prototype.stop=function(){var t=this,n=t._isPlaying,i=t._isFinite,e=t._startTime,r=t._delayTime,o=t._duration;return n&&i?(this._startTime=e=e+r+o,this.update(e),d(this),this):this},b.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},b.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},b.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},b.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},b.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},b.prototype.easing=function(t){return"function"==typeof t&&(this._easingFunction=t),this},b.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},b.prototype.update=function(t,n){var i,e,r,u=this,a=u._onStartCallbackFired,s=u._easingFunction,f=u._repeat,c=u._repeatDelayTime,h=u._reverseDelayTime,l=u._yoyo,p=u._reversed,_=u._startTime,y=u._duration,v=u._valuesStart,m=u._valuesEnd,g=u._valuesStartRepeat,M=u.object,b=u._isFinite,I=u._isPlaying,O=u._onStartCallback,C=u._onUpdateCallback,F=u._onCompleteCallback;if(t=void 0!==t?t:o(),!I||t<_)return!0;a||(O&&O(M),this._onStartCallbackFired=!0),i=(i=(t-_)/y)>1?1:i,e=s(i=p?1-i:i);for(r in m){var P=v[r],w=m[r];void 0!==P&&("function"==typeof w?M[r]=w(e):"number"==typeof w&&(M[r]=P+(w-P)*e))}if(C&&C(M,i),1===i||p&&0===i){if(f){if(b&&this._repeat--,!p)for(r in g)v[r]=m[r],m[r]+=parseFloat(g[r]);return l&&(this._reversed=!p),this._startTime=!p&&c?t+c:p&&h?t+h:t,!0}return n||(this._isPlaying=!1,d(this)),F&&F(),this._repeat=this._r,T--,!1}return!0},t.Plugins=m,t.onTick=function(t){return u.push({update:t})},t.has=function(t){return null!==y(t)},t.get=y,t.getAll=function(){return u},t.removeAll=function(){u.length=0},t.remove=d,t.add=_,t.now=o,t.update=v,t.autoPlay=function(t){s=t},t.isRunning=function(){return a},t.Tween=b,t.Easing=g,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=lite/Tween.min.js.map | ||
//# sourceMappingURL=Tween.min.js.map | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.TWEEN=t.TWEEN||{})}(this,function(t){"use strict";var n,e="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,i=e.requestAnimationFrame||function(t){return e.setTimeout(t,16)},r=e.cancelAnimationFrame||function(t){return e.clearTimeout(t)},o=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}}(),u=[],a=!1,s=!1,f=i,c=r,h=o(),l=0,p=0,_=function(t){var e=u.indexOf(t);e>-1&&u.splice(e,1),u.push(t),s&&!a&&(h=o(),n=f(v),a=!0)},y=function(t){for(var n=0;n<u.length;n++)if(t===u[n])return u[n];return null},d=function(t){var n=u.indexOf(t);-1!==n&&u.splice(n,1)},v=function(t,e){if(t=void 0!==t?t:o(),(l=t-h)>150&&(p=l-50/3),h=t,s&&a&&(n=f(v)),0===u.length)return c(n),a=!1,!1;for(var i,r=0;r<u.length;)i=u[r],p&&(i._startTime+=p),i.update(t,e),r++;return p&&(p=0),!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 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-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(n){return(n*t|0)/t}}}},M={Linear:function(t,n){var e=t.length-1,i=e*n,r=Math.floor(i),o=M.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=M.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=M.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=M.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}}},b=0,T=function(){function t(t){return this.id=b++,this.object=t,this._valuesStart={},this._valuesEnd=null,this._valuesStartRepeat={},this._duration=1e3,this._easingFunction=g.Linear.None,this._interpolationFunction=M.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}return t.prototype.onStart=function(t){return this._onStartCallback=t,this},t.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},t.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},t.prototype.isPlaying=function(){return this._isPlaying},t.prototype.isStarted=function(){return this._onStartCallbackFired},t.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,d(this),this._pausedTime=o(),this):this},t.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=o()-this._pausedTime,_(this),this._pausedTime=o(),this)},t.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},t.prototype.to=function(t,n){return void 0===n&&(n=1e3),this._valuesEnd=t,this._duration=n,this},t.prototype.start=function(t){this._startTime=void 0!==t?t:o(),this._startTime+=this._delayTime;var n=this,e=n._valuesEnd,i=n._valuesStartRepeat,r=n._valuesStart,u=n._interpolationFunction,a=n.object;for(var s in e)!function(t){var n=a[t],o=e[t];if(!a||void 0===a[t])return"continue";var s=a[t];if("number"==typeof n){if("string"==typeof o)i[t]=o,o=n+parseFloat(o);else if(Array.isArray(o)){o.unshift(n);var f=o;o=function(t){return u(f,t)}}}else if("object"==typeof o)if(Array.isArray(o)){var c,h=o,l=n.map(function(t){return t}),p=o.length;o=function(t){for(c=0;c<p;c++)s[c]="number"==typeof l[c]?l[c]+(h[c]-l[c])*t:h[c];return s}}else{var _=o,y={};for(var d in n)y[d]=n[d];o=function(t){for(var n in o)s[n]="number"==typeof y[n]?y[n]+(_[n]-y[n])*t:_[n];return s}}r[t]=n,e[t]=o}(s);return this._isPlaying=!0,this._reversed=!1,this._onStartCallbackFired=!1,_(this),this},t.prototype.stop=function(){var t=this,n=t._isPlaying,e=t._isFinite,i=(t.object,t._startTime),r=(t._delayTime,t._duration),o=t._r;return n&&e?((o+1)%2==1?this.update(i+r):this.update(i),d(this),this):this},t.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this},t.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},t.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},t.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},t.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,t||(this._reversed=!1),this},t.prototype.easing=function(t){return"function"==typeof t&&(this._easingFunction=t),this},t.prototype.interpolation=function(t){return"function"==typeof t&&(this._interpolationFunction=t),this},t.prototype.update=function(t,n){var e,i,r,u=this,a=u._onStartCallbackFired,s=u._easingFunction,f=u._repeat,c=u._repeatDelayTime,h=u._reverseDelayTime,l=u._yoyo,p=u._reversed,_=u._startTime,y=u._duration,v=u._valuesStart,m=u._valuesEnd,g=u._valuesStartRepeat,M=u.object,T=u._isFinite,I=u._isPlaying,O=u._onStartCallback,C=u._onUpdateCallback,F=u._onCompleteCallback;if(t=void 0!==t?t:o(),!I||t<_)return!0;a||(O&&O(M),this._onStartCallbackFired=!0),e=(e=(t-_)/y)>1?1:e,i=s(e=p?1-e:e);for(r in m){var P=v[r],S=m[r];void 0!==P&&("function"==typeof S?M[r]=S(i):"number"==typeof S&&(M[r]=P+(S-P)*i))}if(C&&C(M,e),1===e||p&&0===e){if(f){if(T&&this._repeat--,!p)for(r in g)v[r]=m[r],m[r]+=parseFloat(g[r]);return l&&(this._reversed=!p),this._startTime=!p&&c?t+c:p&&h?t+h:t,!0}return n||(this._isPlaying=!1,d(this)),F&&F(),this._repeat=this._r,b--,!1}return!0},t}();t.Plugins=m,t.onTick=function(t){return u.push({update:t})},t.has=function(t){return null!==y(t)},t.get=y,t.getAll=function(){return u},t.removeAll=function(){u.length=0},t.remove=d,t.add=_,t.now=o,t.update=v,t.autoPlay=function(t){s=t},t.isRunning=function(){return a},t.Tween=T,t.Easing=g,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "es6-tween", | ||
"version": "3.8.19", | ||
"version": "3.8.22", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -14,7 +14,7 @@ "browser": "full/Tween.min.js", | ||
"scripts": { | ||
"source": "rollup -c --environment min:false", | ||
"minify": "rollup -c --environment min:true", | ||
"source": "rollup -c", | ||
"minify": "uglifyjs full/Tween.js -c -m -o full/Tween.min.js --source-map \"filename='full/Tween.min.js.map'\"", | ||
"build": "npm run source && npm run minify", | ||
"source-lite": "rollup -c rollup.config.lite.js --environment min:false", | ||
"minify-lite": "rollup -c rollup.config.lite.js --environment min:true", | ||
"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", | ||
@@ -24,5 +24,4 @@ "prepare": "tsc && npm run build && npm run build-lite", | ||
"dev-lite": "rollup -c rollup.config.lite.js -w", | ||
"lint": "eslint --fix src", | ||
"test": "npm run lint && ava --verbose", | ||
"prepublishOnly": "npm run prepare && npm run test && npm run doc && npm run doc-md", | ||
"test": "ava --verbose", | ||
"prepublishOnly": "npm run prepare && ava --verbose && npm run doc && npm run doc-md", | ||
"doc": "jsdoc --tutorials guide_notes --readme README.md --configure jsdoc.json --verbose", | ||
@@ -53,14 +52,10 @@ "doc-md": "jsdoc2md src/** > API.md" | ||
"docdash": "^0.4.0", | ||
"eslint": "latest", | ||
"eslint-plugin-import": "latest", | ||
"jsdoc": "^3.5.5", | ||
"jsdoc-to-markdown": "next", | ||
"rollup": "^0.50.0", | ||
"rollup-plugin-buble": "latest", | ||
"rollup-plugin-commonjs": "latest", | ||
"rollup-plugin-node-resolve": "latest", | ||
"rollup-plugin-uglify": "latest", | ||
"rollup-watch": "latest", | ||
"rollup-plugin-commonjs": "^8.2.1", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-watch": "^4.3.1", | ||
"typescript": "^2.5.2", | ||
"uglify-es": "latest" | ||
"uglify-js": "^3.1.1" | ||
}, | ||
@@ -67,0 +62,0 @@ "dependencies": { |
@@ -1,5 +0,6 @@ | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
var rollup = require('rollup') | ||
var commonjs = require('rollup-plugin-commonjs'); | ||
var nodeResolve = require('rollup-plugin-node-resolve'); | ||
const plugins = [ | ||
var plugins = [ | ||
nodeResolve({ | ||
@@ -15,11 +16,12 @@ main: true, | ||
export default { | ||
input: 'src/index.js', | ||
output: { | ||
entry: 'src/index.js', | ||
format: 'umd', | ||
file: `full/Tween${minSuffix}.js` | ||
dest: 'full/Tween.js', | ||
globals: { | ||
'intertween': 'InterTween' | ||
}, | ||
sourcemap: true, | ||
sourceMap: true, | ||
context: 'this', | ||
name: 'TWEEN', | ||
moduleName: 'TWEEN', | ||
plugins: plugins | ||
} | ||
} |
@@ -1,46 +0,8 @@ | ||
import buble from 'rollup-plugin-buble' | ||
import uglify from 'rollup-plugin-uglify' | ||
import { minify } from 'uglify-es' | ||
const { min } = process.env | ||
const isMinify = min === 'true' | ||
const minSuffix = isMinify ? '.min' : '' | ||
let mode = (isMinify ? '' : 'un') + 'compressed' | ||
const plugins = [ | ||
// ES6->ES5 syntax/code transpiler | ||
buble({ | ||
// Spread to Object merge/assign | ||
objectAssign: `Object.assign`, | ||
// Features | ||
transforms: { | ||
// For of feature | ||
dangerousForOf: true | ||
} | ||
}) | ||
] | ||
if ( isMinify ) { | ||
plugins.push( | ||
// Minify | ||
uglify({ | ||
sourceMap: { | ||
filename: `src/index.lite.js`, | ||
url: `lite/Tween${minSuffix}.js.map` | ||
} | ||
}, minify) | ||
); | ||
} | ||
export default { | ||
input: 'src/index.lite.js', | ||
output: { | ||
entry: 'src/index.lite.js', | ||
dest: 'lite/Tween.js', | ||
format: 'umd', | ||
file: `lite/Tween${minSuffix}.js` | ||
}, | ||
sourcemap: true, | ||
sourceMap: true, | ||
context: 'this', | ||
name: 'TWEEN', | ||
plugins: plugins | ||
} | ||
moduleName: 'TWEEN' | ||
} |
194
src/core.js
/* global process */ | ||
import { cancelAnimationFrame, requestAnimationFrame, root } from './shim' | ||
import { cancelAnimationFrame, requestAnimationFrame, root } from './shim'; | ||
/** | ||
@@ -10,23 +10,25 @@ * Get browser/Node.js current time-stamp | ||
*/ | ||
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 | ||
var now = (function () { | ||
if (typeof (process) !== 'undefined' && process.hrtime !== undefined) { | ||
return function () { | ||
var 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 { | ||
var offset_1 = root.performance && root.performance.timing && root.performance.timing.navigationStart ? root.performance.timing.navigationStart : Date.now(); | ||
return function () { | ||
return Date.now() - offset_1; | ||
}; | ||
} | ||
}()); | ||
/** | ||
@@ -41,12 +43,12 @@ * 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 | ||
let lastTime = now() | ||
let delta = 0 | ||
let timeDiff = 0 | ||
let frameMs = 50 / 3 | ||
var _tweens = []; | ||
var isStarted = false; | ||
var _autoPlay = false; | ||
var _tick; | ||
var _ticker = requestAnimationFrame; | ||
var _stopTicker = cancelAnimationFrame; | ||
var lastTime = now(); | ||
var delta = 0; | ||
var timeDiff = 0; | ||
var frameMs = 50 / 3; | ||
/** | ||
@@ -61,14 +63,14 @@ * Adds tween to list | ||
*/ | ||
const add = (tween) => { | ||
let i = _tweens.indexOf(tween) | ||
if (i > -1) { | ||
_tweens.splice(i, 1) | ||
} | ||
_tweens.push(tween) | ||
if (_autoPlay && !isStarted) { | ||
lastTime = now() | ||
_tick = _ticker(update) | ||
isStarted = true | ||
} | ||
} | ||
var add = function (tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i > -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
_tweens.push(tween); | ||
if (_autoPlay && !isStarted) { | ||
lastTime = now(); | ||
_tick = _ticker(update); | ||
isStarted = true; | ||
} | ||
}; | ||
/** | ||
@@ -81,3 +83,3 @@ * Adds ticker like event | ||
*/ | ||
const onTick = (fn) => _tweens.push({ update: fn }) | ||
var onTick = function (fn) { return _tweens.push({ update: fn }); }; | ||
/** | ||
@@ -88,3 +90,3 @@ * @returns {Array<Tween>} List of tweens in Array | ||
*/ | ||
const getAll = () => _tweens | ||
var getAll = function () { return _tweens; }; | ||
/** | ||
@@ -96,5 +98,5 @@ * Runs update loop automaticlly | ||
*/ | ||
const autoPlay = (state) => { | ||
_autoPlay = state | ||
} | ||
var autoPlay = function (state) { | ||
_autoPlay = state; | ||
}; | ||
/** | ||
@@ -105,5 +107,5 @@ * Removes all tweens from list | ||
*/ | ||
const removeAll = () => { | ||
_tweens.length = 0 | ||
} | ||
var removeAll = function () { | ||
_tweens.length = 0; | ||
}; | ||
/** | ||
@@ -116,10 +118,10 @@ * @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] | ||
var get = function (tween) { | ||
for (var i = 0; i < _tweens.length; i++) { | ||
if (tween === _tweens[i]) { | ||
return _tweens[i]; | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
return null; | ||
}; | ||
/** | ||
@@ -132,5 +134,5 @@ * @param {Tween} tween Tween Instance to be matched | ||
*/ | ||
const has = (tween) => { | ||
return get(tween) !== null | ||
} | ||
var has = function (tween) { | ||
return get(tween) !== null; | ||
}; | ||
/** | ||
@@ -143,8 +145,8 @@ * Removes tween from list | ||
*/ | ||
const remove = (tween) => { | ||
const i = _tweens.indexOf(tween) | ||
if (i !== -1) { | ||
_tweens.splice(i, 1) | ||
} | ||
} | ||
var remove = function (tween) { | ||
var i = _tweens.indexOf(tween); | ||
if (i !== -1) { | ||
_tweens.splice(i, 1); | ||
} | ||
}; | ||
/** | ||
@@ -158,32 +160,32 @@ * Updates global tweens by given time | ||
*/ | ||
const update = (time, preserve) => { | ||
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) { | ||
_stopTicker(_tick) | ||
isStarted = false | ||
return false | ||
} | ||
let i = 0 | ||
let tween | ||
while (i < _tweens.length) { | ||
tween = _tweens[i] | ||
var update = function (time, preserve) { | ||
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) { | ||
_stopTicker(_tick); | ||
isStarted = false; | ||
return false; | ||
} | ||
var i = 0; | ||
var tween; | ||
while (i < _tweens.length) { | ||
tween = _tweens[i]; | ||
if (timeDiff) { | ||
tween._startTime += timeDiff; | ||
} | ||
tween.update(time, preserve); | ||
i++; | ||
} | ||
if (timeDiff) { | ||
tween._startTime += timeDiff | ||
timeDiff = 0; | ||
} | ||
tween.update(time, preserve) | ||
i++ | ||
} | ||
if (timeDiff) { | ||
timeDiff = 0 | ||
} | ||
return true | ||
} | ||
return true; | ||
}; | ||
/** | ||
@@ -195,3 +197,3 @@ * The state of ticker running | ||
*/ | ||
const isRunning = () => isStarted | ||
var isRunning = function () { return isStarted; }; | ||
/** | ||
@@ -208,3 +210,3 @@ * The plugins store object | ||
*/ | ||
const Plugins = {} | ||
export { Plugins, get, has, getAll, removeAll, remove, add, now, update, autoPlay, onTick, isRunning } | ||
var Plugins = {}; | ||
export { Plugins, get, has, getAll, removeAll, remove, add, now, update, autoPlay, onTick, isRunning }; |
@@ -63,3 +63,6 @@ /** | ||
}; | ||
Stepped: { | ||
steps: (steps: any) => (k: any) => number; | ||
}; | ||
}; | ||
export default Easing; |
@@ -9,182 +9,188 @@ /** | ||
*/ | ||
const Easing = { | ||
Linear: { | ||
None (k) { | ||
return k | ||
} | ||
}, | ||
Quadratic: { | ||
In (k) { | ||
return k * k | ||
var Easing = { | ||
Linear: { | ||
None: function (k) { | ||
return k; | ||
} | ||
}, | ||
Out (k) { | ||
return k * (2 - k) | ||
Quadratic: { | ||
In: function (k) { | ||
return k * k; | ||
}, | ||
Out: function (k) { | ||
return k * (2 - k); | ||
}, | ||
InOut: function (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: function (k) { | ||
return k * k * k; | ||
}, | ||
Out: function (k) { | ||
return --k * k * k + 1; | ||
}, | ||
InOut: function (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: function (k) { | ||
return k * k * k * k; | ||
}, | ||
Out: function (k) { | ||
return 1 - --k * k * k * k; | ||
}, | ||
InOut: function (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: function (k) { | ||
return k * k * k * k * k; | ||
}, | ||
Out: function (k) { | ||
return --k * k * k * k * k + 1; | ||
}, | ||
InOut: function (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: function (k) { | ||
return 1 - Math.cos(k * Math.PI / 2); | ||
}, | ||
Out: function (k) { | ||
return Math.sin(k * Math.PI / 2); | ||
}, | ||
InOut: function (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: function (k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1); | ||
}, | ||
Out: function (k) { | ||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k); | ||
}, | ||
InOut: function (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: function (k) { | ||
return 1 - Math.sqrt(1 - k * k); | ||
}, | ||
Out: function (k) { | ||
return Math.sqrt(1 - --k * k); | ||
}, | ||
InOut: function (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: function (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: function (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: function (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: function (k) { | ||
var s = 1.70158; | ||
return k * k * ((s + 1) * k - s); | ||
}, | ||
Out: function (k) { | ||
var s = 1.70158; | ||
return --k * k * ((s + 1) * k + s) + 1; | ||
}, | ||
InOut: function (k) { | ||
var 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)) | ||
} | ||
}, | ||
Exponential: { | ||
In (k) { | ||
return k === 0 ? 0 : Math.pow(1024, k - 1) | ||
Bounce: { | ||
In: function (k) { | ||
return 1 - Easing.Bounce.Out(1 - k); | ||
}, | ||
Out: function (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: function (k) { | ||
if (k < 0.5) { | ||
return Easing.Bounce.In(k * 2) * 0.5; | ||
} | ||
return Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; | ||
} | ||
}, | ||
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) | ||
Stepped: { | ||
steps: function (steps) { return function (k) { return ((k * steps) | 0) / steps; }; } | ||
} | ||
}, | ||
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; |
115
src/Event.js
@@ -11,7 +11,7 @@ /** | ||
*/ | ||
class EventClass { | ||
constructor () { | ||
this._events = {} | ||
} | ||
/** | ||
var EventClass = /** @class */ (function () { | ||
function EventClass() { | ||
this._events = {}; | ||
} | ||
/** | ||
* Adds `event` to Events system | ||
@@ -22,10 +22,10 @@ * @param {string} event - Event listener name | ||
*/ | ||
on (event, callback) { | ||
if (!this._events[event]) { | ||
this._events[event] = [] | ||
} | ||
this._events[event].push(callback) | ||
return this | ||
} | ||
/** | ||
EventClass.prototype.on = function (event, callback) { | ||
if (!this._events[event]) { | ||
this._events[event] = []; | ||
} | ||
this._events[event].push(callback); | ||
return this; | ||
}; | ||
/** | ||
* Adds `event` to Events system. | ||
@@ -37,15 +37,20 @@ * Removes itself after fired once | ||
*/ | ||
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 | ||
} | ||
/** | ||
EventClass.prototype.once = function (event, callback) { | ||
var _this = this; | ||
if (!this._events[event]) { | ||
this._events[event] = []; | ||
} | ||
var _events = this._events; | ||
var spliceIndex = _events[event].length; | ||
this._events[event].push(function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
callback.apply(_this, args); | ||
_events[event].splice(spliceIndex, 1); | ||
}); | ||
return this; | ||
}; | ||
/** | ||
* Removes `event` from Events system | ||
@@ -56,15 +61,16 @@ * @param {string} event - Event listener name | ||
*/ | ||
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 | ||
} | ||
/** | ||
EventClass.prototype.off = function (event, callback) { | ||
var _events = this._events; | ||
if (event === undefined || !_events[event]) { | ||
return this; | ||
} | ||
if (callback) { | ||
this._events[event] = this._events[event].filter(function (cb) { return cb !== callback; }); | ||
} | ||
else { | ||
this._events[event].length = 0; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Emits/Fired/Trigger `event` from Events system listeners | ||
@@ -74,16 +80,17 @@ * @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 | ||
} | ||
let i = 0 | ||
const len = _event.length | ||
for (; i < len; i++) { | ||
_event[i](arg1, arg2, arg3, arg4) | ||
} | ||
return this | ||
} | ||
} | ||
export default EventClass | ||
EventClass.prototype.emit = function (event, arg1, arg2, arg3, arg4) { | ||
var _events = this._events; | ||
var _event = _events[event]; | ||
if (!_event || !_event.length) { | ||
return this; | ||
} | ||
var i = 0; | ||
var len = _event.length; | ||
for (; i < len; i++) { | ||
_event[i](arg1, arg2, arg3, arg4); | ||
} | ||
return this; | ||
}; | ||
return EventClass; | ||
}()); | ||
export default EventClass; |
@@ -1,8 +0,8 @@ | ||
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 Selector from './selector' | ||
import './shim' | ||
export { Plugins, Selector, Interpolator, onTick, 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 Selector from './selector'; | ||
import './shim'; | ||
export { Plugins, Selector, Interpolator, onTick, has, get, getAll, removeAll, remove, add, now, update, autoPlay, isRunning, Tween, Easing, Timeline }; |
@@ -1,4 +0,4 @@ | ||
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 } | ||
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 }; |
@@ -11,77 +11,78 @@ /** | ||
*/ | ||
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 | ||
var Interpolation = { | ||
Linear: function (v, k) { | ||
var m = v.length - 1; | ||
var f = m * k; | ||
var i = Math.floor(f); | ||
var 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: function (v, k) { | ||
var b = 0; | ||
var n = v.length - 1; | ||
var pw = Math.pow; | ||
var bn = Interpolation.Utils.Bernstein; | ||
for (var 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: function (v, k) { | ||
var m = v.length - 1; | ||
var f = m * k; | ||
var i = Math.floor(f); | ||
var 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: function (p0, p1, t) { | ||
return typeof p0 === 'function' ? p0(t) : (p1 - p0) * t + p0; | ||
}, | ||
Bernstein: function (n, i) { | ||
var fc = Interpolation.Utils.Factorial; | ||
return fc(n) / fc(i) / fc(n - i); | ||
}, | ||
Factorial: (function () { | ||
var a = [1]; | ||
return function (n) { | ||
var s = 1; | ||
if (a[n]) { | ||
return a[n]; | ||
} | ||
for (var i = n; i > 1; i--) { | ||
s *= i; | ||
} | ||
a[n] = s; | ||
return s; | ||
}; | ||
})(), | ||
CatmullRom: function (p0, p1, p2, p3, t) { | ||
var v0 = (p2 - p0) * 0.5; | ||
var v1 = (p3 - p1) * 0.5; | ||
var t2 = t * t; | ||
var 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; |
563
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'; | ||
var _id = 0; // Unique ID | ||
/** | ||
@@ -16,29 +16,29 @@ * 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 | ||
} | ||
/** | ||
var Lite = /** @class */ (function () { | ||
function Lite(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 | ||
@@ -49,7 +49,7 @@ * @param {Function} callback Function should be fired after tween is started | ||
*/ | ||
onStart (callback) { | ||
this._onStartCallback = callback | ||
return this | ||
} | ||
/** | ||
Lite.prototype.onStart = function (callback) { | ||
this._onStartCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* onUpdate callback | ||
@@ -60,7 +60,7 @@ * @param {Function} callback Function should be fired while tween is in progress | ||
*/ | ||
onUpdate (callback) { | ||
this._onUpdateCallback = callback | ||
return this | ||
} | ||
/** | ||
Lite.prototype.onUpdate = function (callback) { | ||
this._onUpdateCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* onComplete callback | ||
@@ -71,7 +71,7 @@ * @param {Function} callback Function should be fired after tween is finished | ||
*/ | ||
onComplete (callback) { | ||
this._onCompleteCallback = callback | ||
return this | ||
} | ||
/** | ||
Lite.prototype.onComplete = function (callback) { | ||
this._onCompleteCallback = callback; | ||
return this; | ||
}; | ||
/** | ||
* @return {boolean} State of playing of tween | ||
@@ -81,6 +81,6 @@ * @example tween.isPlaying() // returns `true` if tween in progress | ||
*/ | ||
isPlaying () { | ||
return this._isPlaying | ||
} | ||
/** | ||
Lite.prototype.isPlaying = function () { | ||
return this._isPlaying; | ||
}; | ||
/** | ||
* @return {boolean} State of started of tween | ||
@@ -90,6 +90,6 @@ * @example tween.isStarted() // returns `true` if tween in started | ||
*/ | ||
isStarted () { | ||
return this._onStartCallbackFired | ||
} | ||
/** | ||
Lite.prototype.isStarted = function () { | ||
return this._onStartCallbackFired; | ||
}; | ||
/** | ||
* Pauses tween | ||
@@ -99,12 +99,12 @@ * @example tween.pause() | ||
*/ | ||
pause () { | ||
if (!this._isPlaying) { | ||
return this | ||
} | ||
this._isPlaying = false | ||
remove(this) | ||
this._pausedTime = now() | ||
return this | ||
} | ||
/** | ||
Lite.prototype.pause = function () { | ||
if (!this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this; | ||
}; | ||
/** | ||
* Play/Resume the tween | ||
@@ -114,13 +114,13 @@ * @example tween.play() | ||
*/ | ||
play () { | ||
if (this._isPlaying) { | ||
return this | ||
} | ||
this._isPlaying = true | ||
this._startTime += now() - this._pausedTime | ||
add(this) | ||
this._pausedTime = now() | ||
return this | ||
} | ||
/** | ||
Lite.prototype.play = function () { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this; | ||
}; | ||
/** | ||
* Sets tween duration | ||
@@ -131,8 +131,8 @@ * @param {number} amount Duration is milliseconds | ||
*/ | ||
duration (amount) { | ||
this._duration = | ||
typeof amount === 'function' ? amount(this._duration) : amount | ||
return this | ||
} | ||
/** | ||
Lite.prototype.duration = function (amount) { | ||
this._duration = | ||
typeof amount === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets target value and duration | ||
@@ -144,8 +144,9 @@ * @param {object} properties Target value (to value) | ||
*/ | ||
to (properties, duration = 1000) { | ||
this._valuesEnd = properties | ||
this._duration = duration | ||
return this | ||
} | ||
/** | ||
Lite.prototype.to = function (properties, duration) { | ||
if (duration === void 0) { duration = 1000; } | ||
this._valuesEnd = properties; | ||
this._duration = duration; | ||
return this; | ||
}; | ||
/** | ||
* Start the tweening | ||
@@ -156,67 +157,73 @@ * @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] | ||
Lite.prototype.start = function (time) { | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += this._delayTime; | ||
var _a = this, _valuesEnd = _a._valuesEnd, _valuesStartRepeat = _a._valuesStartRepeat, _valuesStart = _a._valuesStart, _interpolationFunction = _a._interpolationFunction, object = _a.object; | ||
var _loop_1 = function (property) { | ||
var start = object[property]; | ||
var end = _valuesEnd[property]; | ||
if (!object || object[property] === undefined) { | ||
return "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] | ||
var 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); | ||
var _endArr_1 = end; | ||
end = function (t) { | ||
return _interpolationFunction(_endArr_1, t); | ||
}; | ||
} | ||
} | ||
return obj | ||
} | ||
else if (typeof end === 'object') { | ||
if (Array.isArray(end)) { | ||
var _endArr_2 = end; | ||
var _start_1 = start.map(function (item) { return item; }); | ||
var i_1; | ||
var len_1 = end.length; | ||
end = function (t) { | ||
i_1 = 0; | ||
for (; i_1 < len_1; i_1++) { | ||
obj[i_1] = | ||
typeof _start_1[i_1] === 'number' | ||
? _start_1[i_1] + (_endArr_2[i_1] - _start_1[i_1]) * t | ||
: _endArr_2[i_1]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
else { | ||
var _endObj_1 = end; | ||
var _start_2 = {}; | ||
for (var p in start) { | ||
_start_2[p] = start[p]; | ||
} | ||
end = function (t) { | ||
for (var i in end) { | ||
obj[i] = | ||
typeof _start_2[i] === 'number' | ||
? _start_2[i] + (_endObj_1[i] - _start_2[i]) * t | ||
: _endObj_1[i]; | ||
} | ||
return obj; | ||
}; | ||
} | ||
} | ||
_valuesStart[property] = start; | ||
_valuesEnd[property] = end; | ||
}; | ||
for (var property in _valuesEnd) { | ||
_loop_1(property); | ||
} | ||
} | ||
_valuesStart[property] = start | ||
_valuesEnd[property] = end | ||
} | ||
this._isPlaying = true | ||
this._reversed = false | ||
this._onStartCallbackFired = false | ||
add(this) | ||
return this | ||
} | ||
/** | ||
this._isPlaying = true; | ||
this._reversed = false; | ||
this._onStartCallbackFired = false; | ||
add(this); | ||
return this; | ||
}; | ||
/** | ||
* Stops the tween | ||
@@ -226,13 +233,18 @@ * @example tween.stop() | ||
*/ | ||
stop () { | ||
let { _isPlaying, _isFinite, _startTime, _delayTime, _duration } = this | ||
if (!_isPlaying || !_isFinite) { | ||
return this | ||
} | ||
this._startTime = _startTime = _startTime + _delayTime + _duration | ||
this.update(_startTime) | ||
remove(this) | ||
return this | ||
} | ||
/** | ||
Lite.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) { | ||
return this; | ||
} | ||
var atEnd = (_r + 1) % 2 === 1; | ||
if (atEnd) { | ||
this.update(_startTime + _duration); | ||
} | ||
else { | ||
this.update(_startTime); | ||
} | ||
remove(this); | ||
return this; | ||
}; | ||
/** | ||
* Set delay of tween | ||
@@ -243,8 +255,8 @@ * @param {number} amount Sets tween delay / wait duration | ||
*/ | ||
delay (amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount | ||
return this | ||
} | ||
/** | ||
Lite.prototype.delay = function (amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets how times tween is repeating | ||
@@ -255,9 +267,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 | ||
} | ||
/** | ||
Lite.prototype.repeat = function (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 | ||
@@ -268,8 +280,8 @@ * @param {number} amount Sets tween repeat delay / repeat wait duration | ||
*/ | ||
repeatDelay (amount) { | ||
this._repeatDelayTime = | ||
typeof amount === 'function' ? amount(this._repeatDelayTime) : amount | ||
return this | ||
} | ||
/** | ||
Lite.prototype.repeatDelay = function (amount) { | ||
this._repeatDelayTime = | ||
typeof amount === 'function' ? amount(this._repeatDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set delay of each repeat alternate of tween | ||
@@ -280,8 +292,8 @@ * @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 | ||
} | ||
/** | ||
Lite.prototype.reverseDelay = function (amount) { | ||
this._reverseDelayTime = | ||
typeof amount === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set `yoyo` state (enables reverse in repeat) | ||
@@ -292,7 +304,10 @@ * @param {boolean} state Enables alternate direction for repeat | ||
*/ | ||
yoyo (state) { | ||
this._yoyo = typeof state === 'function' ? state(this._yoyo) : state | ||
return this | ||
} | ||
/** | ||
Lite.prototype.yoyo = function (state) { | ||
this._yoyo = typeof state === 'function' ? state(this._yoyo) : state; | ||
if (!state) { | ||
this._reversed = false; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Set easing | ||
@@ -303,9 +318,9 @@ * @param {Function} _easingFunction Easing function | ||
*/ | ||
easing (fn) { | ||
if (typeof fn === 'function') { | ||
this._easingFunction = fn | ||
} | ||
return this | ||
} | ||
/** | ||
Lite.prototype.easing = function (fn) { | ||
if (typeof fn === 'function') { | ||
this._easingFunction = fn; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Set interpolation | ||
@@ -316,9 +331,9 @@ * @param {Function} _interpolationFunction Interpolation function | ||
*/ | ||
interpolation (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction | ||
} | ||
return this | ||
} | ||
/** | ||
Lite.prototype.interpolation = function (_interpolationFunction) { | ||
if (typeof _interpolationFunction === 'function') { | ||
this._interpolationFunction = _interpolationFunction; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Updates initial object to target value by given `time` | ||
@@ -330,73 +345,79 @@ * @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-- | ||
Lite.prototype.update = function (time, preserve) { | ||
var _a = this, _onStartCallbackFired = _a._onStartCallbackFired, _easingFunction = _a._easingFunction, _repeat = _a._repeat, _repeatDelayTime = _a._repeatDelayTime, _reverseDelayTime = _a._reverseDelayTime, _yoyo = _a._yoyo, _reversed = _a._reversed, _startTime = _a._startTime, _duration = _a._duration, _valuesStart = _a._valuesStart, _valuesEnd = _a._valuesEnd, _valuesStartRepeat = _a._valuesStartRepeat, object = _a.object, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying, _onStartCallback = _a._onStartCallback, _onUpdateCallback = _a._onUpdateCallback, _onCompleteCallback = _a._onCompleteCallback; | ||
var elapsed; | ||
var value; | ||
var 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) { | ||
var start = _valuesStart[property]; | ||
var 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) { | ||
this._isPlaying = false | ||
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) { | ||
this._isPlaying = false; | ||
remove(this); | ||
} | ||
if (_onCompleteCallback) { | ||
_onCompleteCallback(); | ||
} | ||
this._repeat = this._r; | ||
_id--; | ||
return false; | ||
} | ||
} | ||
if (_onCompleteCallback) { | ||
_onCompleteCallback() | ||
} | ||
this._repeat = this._r | ||
_id-- | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
} | ||
export default Lite | ||
return true; | ||
}; | ||
return Lite; | ||
}()); | ||
export default Lite; |
@@ -1,18 +0,18 @@ | ||
const Store = {} | ||
var Store = {}; | ||
export default function (node, tween) { | ||
if (!node || !node.nodeType) { | ||
return tween | ||
} | ||
const ID = node.queueID || 'q_' + Date.now() | ||
if (!node.queueID) { | ||
node.queueID = ID | ||
} | ||
if (Store[ID]) { | ||
if (tween) { | ||
Store[ID] = tween // assign(Store[ID], tween) | ||
if (!node || !node.nodeType) { | ||
return tween; | ||
} | ||
return Store[ID] | ||
} | ||
Store[ID] = tween | ||
return Store[ID] | ||
var ID = node.queueID || 'q_' + Date.now(); | ||
if (!node.queueID) { | ||
node.queueID = ID; | ||
} | ||
if (Store[ID]) { | ||
if (tween) { | ||
Store[ID] = tween; //assign(Store[ID], tween) | ||
} | ||
return Store[ID]; | ||
} | ||
Store[ID] = tween; | ||
return Store[ID]; | ||
} |
@@ -1,60 +0,66 @@ | ||
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) | ||
var PlaybackPosition = /** @class */ (function () { | ||
function PlaybackPosition() { | ||
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 | ||
} | ||
PlaybackPosition.prototype.parseLabel = function (name, offset) { | ||
var _a = this, offsets = _a.offsets, labels = _a.labels; | ||
var i = labels.indexOf(name); | ||
if (typeof name === 'string' && name.indexOf('=') !== -1 && !offset && i === -1) { | ||
var rty = name.substr(name.indexOf('=') - 1, 2); | ||
var rt = name.split(rty); | ||
offset = rt.length === 2 ? rty + rt[1] : null; | ||
name = rt[0]; | ||
i = labels.indexOf(name); | ||
} | ||
} | ||
return currOffset | ||
} | ||
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)) | ||
} | ||
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 | ||
} | ||
} | ||
if (i !== -1 && name) { | ||
var currOffset = offsets[i] || 0; | ||
if (typeof offset === 'number') { | ||
currOffset = offset; | ||
} | ||
else if (typeof offset === 'string') { | ||
if (offset.indexOf('=') !== -1) { | ||
var type = offset.charAt(0); | ||
offset = Number(offset.substr(2)); | ||
if (type === '+' || type === '-') { | ||
currOffset += parseFloat(type + offset); | ||
} | ||
else if (type === '*') { | ||
currOffset *= offset; | ||
} | ||
else if (type === '/') { | ||
currOffset /= offset; | ||
} | ||
else if (type === '%') { | ||
currOffset *= offset / 100; | ||
} | ||
} | ||
} | ||
return currOffset; | ||
} | ||
return typeof offset === 'number' ? offset : 0; | ||
}; | ||
PlaybackPosition.prototype.addLabel = function (name, offset) { | ||
this.labels.push(name); | ||
this.offsets.push(this.parseLabel(name, offset)); | ||
return this; | ||
}; | ||
PlaybackPosition.prototype.setLabel = function (name, offset) { | ||
var i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.offsets.splice(i, 1, this.parseLabel(name, offset)); | ||
} | ||
return this; | ||
}; | ||
PlaybackPosition.prototype.eraseLabel = function (name) { | ||
var i = this.labels.indexOf(name); | ||
if (i !== -1) { | ||
this.labels.splice(i, 1); | ||
this.offsets.splice(i, 1); | ||
} | ||
return this; | ||
}; | ||
return PlaybackPosition; | ||
}()); | ||
export default PlaybackPosition; |
export default function (selector, collection) { | ||
if (collection) { | ||
return !selector ? null : selector === window || selector === document ? [selector] : typeof selector === 'string' ? !!document.querySelectorAll && document.querySelectorAll(selector) : Array.isArray(selector) ? selector : selector.nodeType ? [selector] : [] | ||
} | ||
return !selector ? null : selector === window || selector === document ? selector : typeof selector === 'string' ? !!document.querySelector && document.querySelector(selector) : Array.isArray(selector) ? selector[0] : selector.nodeType ? selector : null | ||
if (collection) { | ||
return !selector ? null : selector === window || selector === document ? [selector] : typeof selector === 'string' ? !!document.querySelectorAll && document.querySelectorAll(selector) : Array.isArray(selector) ? selector : selector.nodeType ? [selector] : []; | ||
} | ||
return !selector ? null : selector === window || selector === document ? selector : typeof selector === 'string' ? !!document.querySelector && document.querySelector(selector) : Array.isArray(selector) ? selector[0] : selector.nodeType ? selector : null; | ||
} |
@@ -1,5 +0,1 @@ | ||
export declare let create: { | ||
(o: object): any; | ||
(o: object, properties: PropertyDescriptorMap & ThisType<any>): any; | ||
}; | ||
export declare let assign: { | ||
@@ -11,4 +7,8 @@ <T, U>(target: T, source: U): T & U; | ||
}; | ||
export declare let create: { | ||
(o: object): any; | ||
(o: object, properties: PropertyDescriptorMap & ThisType<any>): any; | ||
}; | ||
export declare let root: any; | ||
export declare let requestAnimationFrame: Function; | ||
export declare let cancelAnimationFrame: Function; |
@@ -0,16 +1,29 @@ | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
/* global global */ | ||
export let create = Object.create || ((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] | ||
export var assign = Object.assign || (function (source) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
} | ||
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)) | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
var arg = args[i]; | ||
for (var p in arg) { | ||
source[p] = arg[p]; | ||
} | ||
} | ||
return source; | ||
}); | ||
export var create = Object.create || (function (source) { | ||
if (source === void 0) { source = {}; } | ||
return (__assign({}, source)); | ||
}); | ||
export var root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this; | ||
export var requestAnimationFrame = root.requestAnimationFrame || (function (fn) { return root.setTimeout(fn, 16); }); | ||
export var cancelAnimationFrame = root.cancelAnimationFrame || (function (id) { return root.clearTimeout(id); }); |
@@ -19,3 +19,2 @@ import Tween from './Tween'; | ||
_reversed: boolean; | ||
_elapsed: number; | ||
_id: number; | ||
@@ -78,4 +77,4 @@ private _defaultParams; | ||
update(time: any): boolean; | ||
elapsed(value: any): number | boolean; | ||
progress(value: any): number | boolean; | ||
} | ||
export default Timeline; |
@@ -1,18 +0,36 @@ | ||
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 Selector from './selector' | ||
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 | ||
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 __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
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 Selector from './selector'; | ||
export var shuffle = function (a) { | ||
var j; | ||
var x; | ||
var 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; | ||
}; | ||
var _id = 0; | ||
/** | ||
@@ -29,49 +47,58 @@ * 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) | ||
var Timeline = /** @class */ (function (_super) { | ||
__extends(Timeline, _super); | ||
function Timeline(params) { | ||
var _this = _super.call(this) || this; | ||
_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; | ||
} | ||
} | ||
/** | ||
Timeline.prototype.mapTotal = function (fn) { | ||
fn.call(this, this._tweens); | ||
return this; | ||
}; | ||
Timeline.prototype.timingOrder = function (fn) { | ||
var timing = fn(this._tweens.map(function (t) { return t._startTime; })); | ||
this._tweens.map(function (tween, i) { | ||
tween._startTime = timing[i]; | ||
}); | ||
return this; | ||
}; | ||
Timeline.prototype.getTiming = function (mode, nodes, params, offset) { | ||
if (offset === void 0) { offset = 0; } | ||
if (mode === 'reverse') { | ||
var stagger_1 = params.stagger; | ||
var totalStagger_1 = (stagger_1 || 0) * (nodes.length - 1); | ||
return nodes.map(function (node, i) { return totalStagger_1 - (stagger_1 || 0) * i + offset; }); | ||
} | ||
else if (mode === 'async') { | ||
return nodes.map(function (node) { return offset; }); | ||
} | ||
else if (mode === 'sequence' || mode === 'delayed') { | ||
var stagger_2 = params.stagger; | ||
if (!stagger_2) { | ||
stagger_2 = (params.duration || 1000) / (nodes.length - 1); | ||
} | ||
return nodes.map(function (node, i) { return stagger_2 * i + offset; }); | ||
} | ||
else if (mode === 'oneByOne') { | ||
return nodes.map(function (node) { return params.duration; }); | ||
} | ||
else if (mode === 'shuffle') { | ||
var stagger_3 = params.stagger; | ||
return shuffle(nodes.map(function (node, i) { return (stagger_3 || 0) * i + offset; })); | ||
} | ||
else { | ||
var stagger_4 = params.stagger; | ||
return nodes.map(function (node, i) { return (stagger_4 || 0) * i + offset; }); | ||
} | ||
}; | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
@@ -85,19 +112,21 @@ * @param {object} from - Initial value | ||
*/ | ||
fromTo (nodes, from, to, params) { | ||
nodes = Selector(nodes, true) | ||
if (nodes && nodes.length) { | ||
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) | ||
for (let i = 0, node, len = nodes.length; i < len; i++) { | ||
node = nodes[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() | ||
} | ||
/** | ||
Timeline.prototype.fromTo = function (nodes, from, to, params) { | ||
nodes = Selector(nodes, true); | ||
if (nodes && nodes.length) { | ||
if (this._defaultParams) { | ||
params = __assign({}, this._defaultParams, params); | ||
} | ||
var position = params.label; | ||
var offset = typeof position === 'number' | ||
? position | ||
: this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
var mode = this.getTiming(params.mode, nodes, params, offset); | ||
for (var i = 0, node = void 0, len = nodes.length; i < len; i++) { | ||
node = nodes[i]; | ||
this.add(Tween.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : __assign({}, from), typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), mode[i]); | ||
} | ||
} | ||
return this.start(); | ||
}; | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
@@ -110,6 +139,6 @@ * @param {object} from - Initial value | ||
*/ | ||
from (nodes, from, params) { | ||
return this.fromTo(nodes, from, null, params) | ||
} | ||
/** | ||
Timeline.prototype.from = function (nodes, from, params) { | ||
return this.fromTo(nodes, from, null, params); | ||
}; | ||
/** | ||
* @param {Array<Element>} nodes DOM Elements Collection (converted to Array) | ||
@@ -122,6 +151,6 @@ * @param {object} to - Target value | ||
*/ | ||
to (nodes, to, params) { | ||
return this.fromTo(nodes, null, to, params) | ||
} | ||
/** | ||
Timeline.prototype.to = function (nodes, to, params) { | ||
return this.fromTo(nodes, null, to, params); | ||
}; | ||
/** | ||
* Add label to Timeline | ||
@@ -133,15 +162,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) | ||
} | ||
return this | ||
} | ||
/** | ||
Timeline.prototype.addLabel = function (name, offset) { | ||
this.position.addLabel(name, offset); | ||
return this; | ||
}; | ||
Timeline.prototype.map = function (fn) { | ||
for (var i = 0, len = this._tweens.length; i < len; i++) { | ||
var _tween = this._tweens[i]; | ||
fn(_tween, i); | ||
this._duration = Math.max(this._duration, _tween._duration + _tween._startTime); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Add tween to Timeline | ||
@@ -153,92 +182,103 @@ * @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]) | ||
Timeline.prototype.add = function (tween, position) { | ||
var _this = this; | ||
if (Array.isArray(tween)) { | ||
tween.map(function (_tween) { | ||
_this.add(_tween, position); | ||
}); | ||
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, offset) | ||
tween._delayTime = 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, _isPlaying } = this | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
} | ||
let elapsed = (time - _startTime) / _duration | ||
elapsed = elapsed > 1 ? 1 : elapsed | ||
elapsed = _reversed ? 1 - elapsed : elapsed | ||
const timing = time - _startTime | ||
const _timing = _reversed ? _duration - timing : timing | ||
let i = 0 | ||
while (i < _tweens.length) { | ||
_tweens[i].update(_timing) | ||
i++ | ||
} | ||
this.emit(EVENT_UPDATE, elapsed, timing) | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat-- | ||
else if (typeof tween === 'object' && !(tween instanceof Tween)) { | ||
tween = new Tween(tween.from).to(tween.to, tween); | ||
} | ||
this.emit(_reversed ? EVENT_REVERSE : EVENT_REPEAT) | ||
if (_yoyo) { | ||
this._reversed = !_reversed | ||
this.timingOrder((timing) => timing.reverse()) | ||
var _a = this, _defaultParams = _a._defaultParams, _duration = _a._duration; | ||
if (_defaultParams) { | ||
for (var method in _defaultParams) { | ||
if (typeof tween[method] === 'function') { | ||
tween[method](_defaultParams[method]); | ||
} | ||
} | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime | ||
} else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime | ||
} else { | ||
this._startTime = time | ||
var offset = typeof position === 'number' | ||
? position | ||
: this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
tween._startTime = Math.max(this._startTime, tween._delayTime, offset); | ||
tween._delayTime = 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; | ||
}; | ||
Timeline.prototype.restart = function () { | ||
this._startTime += now(); | ||
add(this); | ||
return this.emit(EVENT_RS); | ||
}; | ||
Timeline.prototype.easing = function (easing) { | ||
return this.map(function (tween) { return tween.easing(easing); }); | ||
}; | ||
Timeline.prototype.interpolation = function (interpolation) { | ||
return this.map(function (tween) { return tween.interpolation(interpolation); }); | ||
}; | ||
Timeline.prototype.update = function (time) { | ||
var _a = this, _tweens = _a._tweens, _duration = _a._duration, _repeatDelayTime = _a._repeatDelayTime, _reverseDelayTime = _a._reverseDelayTime, _startTime = _a._startTime, _reversed = _a._reversed, _yoyo = _a._yoyo, _repeat = _a._repeat, _isFinite = _a._isFinite, _isPlaying = _a._isPlaying; | ||
if (!_isPlaying || time < _startTime) { | ||
return true; | ||
} | ||
i = 0 | ||
var elapsed = (time - _startTime) / _duration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
this.elapsed = elapsed; | ||
var timing = time - _startTime; | ||
var _timing = _reversed ? _duration - timing : timing; | ||
var i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i].reassignValues(time) | ||
i++ | ||
_tweens[i].update(_timing); | ||
i++; | ||
} | ||
return true | ||
} else { | ||
this.emit(EVENT_COMPLETE) | ||
this._repeat = this._r | ||
remove(this) | ||
this._isPlaying = false | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
elapsed (value) { | ||
return value !== undefined ? this.update(value * this._duration) : this._elapsed | ||
} | ||
} | ||
export default Timeline | ||
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(function (timing) { return timing.reverse(); }); | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime = time + _repeatDelayTime; | ||
} | ||
else if (_reversed && _reverseDelayTime) { | ||
this._startTime = time + _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime = time; | ||
} | ||
i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i].reassignValues(time); | ||
i++; | ||
} | ||
return true; | ||
} | ||
else { | ||
this.emit(EVENT_COMPLETE); | ||
this._repeat = this._r; | ||
remove(this); | ||
this._isPlaying = false; | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
Timeline.prototype.progress = function (value) { | ||
return value !== undefined | ||
? this.update(value * this._duration) | ||
: this.elapsed; | ||
}; | ||
return Timeline; | ||
}(Tween)); | ||
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) { | ||
var floatedVal = parseFloat(val); | ||
return typeof floatedVal === 'number' && !isNaN(floatedVal) ? floatedVal : val; | ||
} |
@@ -37,2 +37,3 @@ import EventClass from './Event'; | ||
_startTime: number; | ||
_initTime: number; | ||
_delayTime: number; | ||
@@ -50,3 +51,3 @@ _repeatDelayTime: number; | ||
_isPlaying: boolean; | ||
_elapsed: number; | ||
elapsed: number; | ||
private _onStartCallbackFired; | ||
@@ -103,5 +104,6 @@ private _rendered; | ||
* @example tween.reverse() | ||
* @param {boolean=} state Set state of current reverse | ||
* @memberof Tween | ||
*/ | ||
reverse(): this; | ||
reverse(state?: boolean): this; | ||
/** | ||
@@ -163,7 +165,7 @@ * @return {boolean} State of reversed | ||
* Start the tweening | ||
* @param {number} time setting manual time instead of Current browser timestamp | ||
* @param {number|string} time setting manual time instead of Current browser timestamp or like `+1000` relative to current timestamp | ||
* @example tween.start() | ||
* @memberof Tween | ||
*/ | ||
start(time?: number): this; | ||
start(time?: number | string): this; | ||
/** | ||
@@ -228,7 +230,8 @@ * Stops the tween | ||
* @param {boolean=} preserve Prevents from removing tween from store | ||
* @param {boolean=} forceTime Forces to be frame rendered, even mismatching time | ||
* @example tween.update(100) | ||
* @memberof Tween | ||
*/ | ||
update(time: number, preserve?: boolean): boolean; | ||
update(time?: number, preserve?: boolean, forceTime?: boolean): boolean; | ||
} | ||
export default Tween; |
645
src/Tween.js
@@ -1,22 +0,32 @@ | ||
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' | ||
import Selector from './selector' | ||
Object.create = create | ||
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 NodeCache from './NodeCache'; | ||
import Selector from './selector'; | ||
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 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'; | ||
var _id = 0; // Unique ID | ||
var defaultEasing = Easing.Linear.None; | ||
/** | ||
@@ -32,4 +42,35 @@ * Tween main constructor | ||
*/ | ||
class Tween extends EventClass { | ||
/** | ||
var Tween = /** @class */ (function (_super) { | ||
__extends(Tween, _super); | ||
function Tween(node, object) { | ||
var _this = _super.call(this) || this; | ||
_this.id = _id++; | ||
if (!!node && typeof node === 'object' && !object && !node.nodeType) { | ||
object = _this.object = node; | ||
node = null; | ||
} | ||
else if (!!node && | ||
(node.nodeType || node.length || typeof node === 'string')) { | ||
node = _this.node = Selector(node); | ||
object = _this.object = NodeCache(node, object); | ||
} | ||
_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; | ||
} | ||
/** | ||
* Easier way to call the Tween | ||
@@ -44,13 +85,14 @@ * @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 | ||
} | ||
return tween | ||
} | ||
/** | ||
Tween.fromTo = function (node, object, to, params) { | ||
if (params === void 0) { params = {}; } | ||
params.quickRender = params.quickRender ? params.quickRender : !to; | ||
var tween = new Tween(node, object).to(to, params); | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime); | ||
tween._rendered = false; | ||
tween._onStartCallbackFired = false; | ||
} | ||
return tween; | ||
}; | ||
/** | ||
* Easier way calling constructor only applies the `to` value, useful for CSS Animation | ||
@@ -64,6 +106,6 @@ * @param {Element} node DOM Element | ||
*/ | ||
static to (node, to, params) { | ||
return Tween.fromTo(node, null, to, params) | ||
} | ||
/** | ||
Tween.to = function (node, to, params) { | ||
return Tween.fromTo(node, null, to, params); | ||
}; | ||
/** | ||
* Easier way calling constructor only applies the `from` value, useful for CSS Animation | ||
@@ -77,34 +119,6 @@ * @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 (!!node && typeof node === 'object' && !object && !node.nodeType) { | ||
object = this.object = node | ||
node = null | ||
} else if (!!node && (node.nodeType || node.length || typeof node === 'string')) { | ||
node = this.node = Selector(node) | ||
object = this.object = NodeCache(node, object) | ||
} | ||
this._valuesEnd = null | ||
this._valuesFunc = null | ||
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 | ||
} | ||
/** | ||
Tween.from = function (node, from, params) { | ||
return Tween.fromTo(node, from, null, params); | ||
}; | ||
/** | ||
* @return {boolean} State of playing of tween | ||
@@ -114,6 +128,6 @@ * @example tween.isPlaying() // returns `true` if tween in progress | ||
*/ | ||
isPlaying () { | ||
return this._isPlaying | ||
} | ||
/** | ||
Tween.prototype.isPlaying = function () { | ||
return this._isPlaying; | ||
}; | ||
/** | ||
* @return {boolean} State of started of tween | ||
@@ -123,16 +137,17 @@ * @example tween.isStarted() // returns `true` if tween in started | ||
*/ | ||
isStarted () { | ||
return this._onStartCallbackFired | ||
} | ||
/** | ||
Tween.prototype.isStarted = function () { | ||
return this._onStartCallbackFired; | ||
}; | ||
/** | ||
* Reverses the tween state/direction | ||
* @example tween.reverse() | ||
* @param {boolean=} state Set state of current reverse | ||
* @memberof Tween | ||
*/ | ||
reverse () { | ||
const { _reversed } = this | ||
this._reversed = !_reversed | ||
return this | ||
} | ||
/** | ||
Tween.prototype.reverse = function (state) { | ||
var _reversed = this._reversed; | ||
this._reversed = state !== undefined ? state : !_reversed; | ||
return this; | ||
}; | ||
/** | ||
* @return {boolean} State of reversed | ||
@@ -142,6 +157,6 @@ * @example tween.reversed() // returns `true` if tween in reversed state | ||
*/ | ||
reversed () { | ||
return this._reversed | ||
} | ||
/** | ||
Tween.prototype.reversed = function () { | ||
return this._reversed; | ||
}; | ||
/** | ||
* Pauses tween | ||
@@ -151,12 +166,12 @@ * @example tween.pause() | ||
*/ | ||
pause () { | ||
if (!this._isPlaying) { | ||
return this | ||
} | ||
this._isPlaying = false | ||
remove(this) | ||
this._pausedTime = now() | ||
return this.emit(EVENT_PAUSE, this.object) | ||
} | ||
/** | ||
Tween.prototype.pause = function () { | ||
if (!this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = false; | ||
remove(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PAUSE, this.object); | ||
}; | ||
/** | ||
* Play/Resume the tween | ||
@@ -166,13 +181,14 @@ * @example tween.play() | ||
*/ | ||
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) | ||
} | ||
/** | ||
Tween.prototype.play = function () { | ||
if (this._isPlaying) { | ||
return this; | ||
} | ||
this._isPlaying = true; | ||
this._startTime += now() - this._pausedTime; | ||
this._initTime = this._startTime; | ||
add(this); | ||
this._pausedTime = now(); | ||
return this.emit(EVENT_PLAY, this.object); | ||
}; | ||
/** | ||
* Restarts tween from initial value | ||
@@ -183,9 +199,9 @@ * @param {boolean=} noDelay If this param is set to `true`, restarts tween without `delay` | ||
*/ | ||
restart (noDelay) { | ||
this._repeat = this._r | ||
this.reassignValues() | ||
add(this) | ||
return this.emit(EVENT_RS, this.object) | ||
} | ||
/** | ||
Tween.prototype.restart = function (noDelay) { | ||
this._repeat = this._r; | ||
this.reassignValues(); | ||
add(this); | ||
return this.emit(EVENT_RS, this.object); | ||
}; | ||
/** | ||
* Seek tween value by `time` | ||
@@ -197,10 +213,14 @@ * @param {Time} time Tween update time | ||
*/ | ||
seek (time, keepPlaying) { | ||
this._startTime = now() + Math.max(0, Math.min(time, this._duration)) | ||
this._isPlaying = true | ||
add(this) | ||
this.emit(EVENT_SEEK, time, this.object) | ||
return keepPlaying ? this : this.pause() | ||
} | ||
/** | ||
Tween.prototype.seek = function (time, keepPlaying) { | ||
var _a = this, _duration = _a._duration, _repeat = _a._repeat, _initTime = _a._initTime; | ||
var updateTime = _initTime + time; | ||
this._isPlaying = true; | ||
if (keepPlaying) { | ||
add(this); | ||
} | ||
this.update(updateTime, false, true); | ||
this.emit(EVENT_SEEK, time, this.object); | ||
return keepPlaying ? this : this.pause(); | ||
}; | ||
/** | ||
* Sets tween duration | ||
@@ -211,7 +231,8 @@ * @param {number} amount Duration is milliseconds | ||
*/ | ||
duration (amount) { | ||
this._duration = typeof (amount) === 'function' ? amount(this._duration) : amount | ||
return this | ||
} | ||
/** | ||
Tween.prototype.duration = function (amount) { | ||
this._duration = | ||
typeof amount === 'function' ? amount(this._duration) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets target value and duration | ||
@@ -223,17 +244,20 @@ * @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) | ||
Tween.prototype.to = function (properties, duration, maybeUsed) { | ||
if (duration === void 0) { duration = 1000; } | ||
this._valuesEnd = properties; | ||
if (typeof duration === 'number' || typeof duration === 'function') { | ||
this._duration = | ||
typeof duration === 'function' ? duration(this._duration) : duration; | ||
} | ||
} | ||
} | ||
return this | ||
} | ||
/** | ||
else if (typeof duration === 'object') { | ||
for (var prop in duration) { | ||
if (typeof this[prop] === 'function') { | ||
var _a = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]], _b = _a[0], arg1 = _b === void 0 ? null : _b, _c = _a[1], arg2 = _c === void 0 ? null : _c, _d = _a[2], arg3 = _d === void 0 ? null : _d, _e = _a[3], arg4 = _e === void 0 ? null : _e; | ||
this[prop](arg1, arg2, arg3, arg4); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Renders and computes value at first render | ||
@@ -243,47 +267,54 @@ * @private | ||
*/ | ||
render () { | ||
if (this._rendered) { | ||
return this | ||
} | ||
let { _valuesEnd, object, Renderer, node, InitialValues, _easingFunction } = 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) { | ||
_valuesEnd[property] = plugin | ||
Tween.prototype.render = function () { | ||
if (this._rendered) { | ||
return this; | ||
} | ||
continue | ||
} | ||
} | ||
this._valuesFunc = InterTween(object, _valuesEnd, null, _easingFunction) | ||
if (Renderer && this.node) { | ||
this.__render = new Renderer(this, object, _valuesEnd) | ||
} | ||
return this | ||
} | ||
/** | ||
var _a = this, _valuesEnd = _a._valuesEnd, object = _a.object, Renderer = _a.Renderer, node = _a.node, InitialValues = _a.InitialValues, _easingFunction = _a._easingFunction; | ||
if (node && InitialValues) { | ||
if (!object) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd)); | ||
} | ||
else if (!_valuesEnd) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
} | ||
} | ||
for (var property in _valuesEnd) { | ||
var start = object && object[property]; | ||
var end = _valuesEnd[property]; | ||
if (Plugins[property]) { | ||
var plugin = Plugins[property].prototype.update | ||
? new Plugins[property](this, start, end, property, object) | ||
: Plugins[property](this, start, end, property, object); | ||
if (plugin) { | ||
_valuesEnd[property] = plugin; | ||
} | ||
continue; | ||
} | ||
} | ||
this._valuesFunc = InterTween(object, _valuesEnd, null, _easingFunction); | ||
if (Renderer && this.node) { | ||
this.__render = new Renderer(this, object, _valuesEnd); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Start the tweening | ||
* @param {number} time setting manual time instead of Current browser timestamp | ||
* @param {number|string} time setting manual time instead of Current browser timestamp or like `+1000` relative to current timestamp | ||
* @example tween.start() | ||
* @memberof Tween | ||
*/ | ||
start (time) { | ||
this._startTime = time !== undefined ? time : now() | ||
this._startTime += this._delayTime | ||
this._onStartCallbackFired = false | ||
this._rendered = false | ||
this._isPlaying = true | ||
add(this) | ||
return this | ||
} | ||
/** | ||
Tween.prototype.start = function (time) { | ||
this._startTime = | ||
time !== undefined | ||
? typeof time === 'string' ? now() + parseFloat(time) : time | ||
: now(); | ||
this._startTime += this._delayTime; | ||
this._initTime = this._startTime; | ||
this._onStartCallbackFired = false; | ||
this._rendered = false; | ||
this._isPlaying = true; | ||
add(this); | ||
return this; | ||
}; | ||
/** | ||
* Stops the tween | ||
@@ -293,13 +324,18 @@ * @example tween.stop() | ||
*/ | ||
stop () { | ||
let { _isPlaying, _isFinite, object, _startTime, _delayTime, _duration } = this | ||
if (!_isPlaying || !_isFinite) { | ||
return this | ||
} | ||
this._startTime = _startTime = _startTime + _delayTime + _duration | ||
this.update(_startTime) | ||
remove(this) | ||
return this.emit(EVENT_STOP, object) | ||
} | ||
/** | ||
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) { | ||
return this; | ||
} | ||
var atEnd = (_r + 1) % 2 === 1; | ||
if (atEnd) { | ||
this.update(_startTime + _duration); | ||
} | ||
else { | ||
this.update(_startTime); | ||
} | ||
remove(this); | ||
return this.emit(EVENT_STOP, object); | ||
}; | ||
/** | ||
* Set delay of tween | ||
@@ -310,7 +346,8 @@ * @param {number} amount Sets tween delay / wait duration | ||
*/ | ||
delay (amount) { | ||
this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount | ||
return this | ||
} | ||
/** | ||
Tween.prototype.delay = function (amount) { | ||
this._delayTime = | ||
typeof amount === 'function' ? amount(this._delayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Sets how times tween is repeating | ||
@@ -321,9 +358,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 | ||
} | ||
/** | ||
Tween.prototype.repeat = function (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 | ||
@@ -334,7 +371,8 @@ * @param {number} amount Sets tween repeat delay / repeat wait duration | ||
*/ | ||
repeatDelay (amount) { | ||
this._repeatDelayTime = typeof (amount) === 'function' ? amount(this._repeatDelayTime) : amount | ||
return this | ||
} | ||
/** | ||
Tween.prototype.repeatDelay = function (amount) { | ||
this._repeatDelayTime = | ||
typeof amount === 'function' ? amount(this._repeatDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set delay of each repeat alternate of tween | ||
@@ -345,7 +383,8 @@ * @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 | ||
} | ||
/** | ||
Tween.prototype.reverseDelay = function (amount) { | ||
this._reverseDelayTime = | ||
typeof amount === 'function' ? amount(this._reverseDelayTime) : amount; | ||
return this; | ||
}; | ||
/** | ||
* Set `yoyo` state (enables reverse in repeat) | ||
@@ -357,8 +396,14 @@ * @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 || this._easingFunction | ||
return this | ||
} | ||
/** | ||
Tween.prototype.yoyo = function (state, _easingReverse) { | ||
this._yoyo = | ||
typeof state === 'function' | ||
? state(this._yoyo) | ||
: state === null ? this._yoyo : state; | ||
if (!state) { | ||
this._reversed = false; | ||
} | ||
this._easingReverse = _easingReverse || null; | ||
return this; | ||
}; | ||
/** | ||
* Set easing | ||
@@ -369,7 +414,7 @@ * @param {Function} _easingFunction Easing function, applies in non-reverse direction if Tween#yoyo second argument is applied | ||
*/ | ||
easing (_easingFunction) { | ||
this._easingFunction = _easingFunction | ||
return this | ||
} | ||
/** | ||
Tween.prototype.easing = function (_easingFunction) { | ||
this._easingFunction = _easingFunction; | ||
return this; | ||
}; | ||
/** | ||
* Reassigns value for rare-case like Tween#restart or for Timeline | ||
@@ -379,83 +424,87 @@ * @private | ||
*/ | ||
reassignValues (time) { | ||
const { _valuesFunc, object, _delayTime } = this | ||
this._isPlaying = true | ||
this._startTime = time !== undefined ? time : now() | ||
this._startTime += _delayTime | ||
this._reversed = false | ||
add(this) | ||
const _valuesStart = _valuesFunc(0) | ||
for (const property in _valuesStart) { | ||
const start = _valuesStart[property] | ||
object[property] = start | ||
} | ||
return this | ||
} | ||
/** | ||
Tween.prototype.reassignValues = function (time) { | ||
var _a = this, _valuesFunc = _a._valuesFunc, object = _a.object, _delayTime = _a._delayTime; | ||
this._isPlaying = true; | ||
this._startTime = time !== undefined ? time : now(); | ||
this._startTime += _delayTime; | ||
this._reversed = false; | ||
add(this); | ||
var _valuesStart = _valuesFunc(0); | ||
for (var property in _valuesStart) { | ||
var start = _valuesStart[property]; | ||
object[property] = start; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Updates initial object to target value by given `time` | ||
* @param {Time} time Current time | ||
* @param {boolean=} preserve Prevents from removing tween from store | ||
* @param {boolean=} forceTime Forces to be frame rendered, even mismatching time | ||
* @example tween.update(100) | ||
* @memberof Tween | ||
*/ | ||
update (time, preserve) { | ||
let { _onStartCallbackFired, _easingFunction, _easingReverse, _repeat, _repeatDelayTime, _reverseDelayTime, _yoyo, _reversed, _startTime, _duration, _valuesFunc, object, _isFinite, _isPlaying, __render } = this | ||
let elapsed | ||
let currentEasing | ||
time = time !== undefined ? time : now() | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
} | ||
if (!_onStartCallbackFired) { | ||
if (!this._rendered) { | ||
this.render() | ||
this._rendered = true | ||
_valuesFunc = this._valuesFunc | ||
} | ||
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 | ||
} | ||
_valuesFunc(elapsed, elapsed, currentEasing) | ||
if (__render) { | ||
__render.update(object, elapsed) | ||
} | ||
this.emit(EVENT_UPDATE, object, elapsed) | ||
if (elapsed === 1 || (_reversed && elapsed === 0)) { | ||
if (_repeat) { | ||
if (_isFinite) { | ||
this._repeat-- | ||
Tween.prototype.update = function (time, preserve, forceTime) { | ||
var _a = this, _onStartCallbackFired = _a._onStartCallbackFired, _easingFunction = _a._easingFunction, _easingReverse = _a._easingReverse, _repeat = _a._repeat, _repeatDelayTime = _a._repeatDelayTime, _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 elapsed; | ||
var currentEasing; | ||
time = time !== undefined ? time : now(); | ||
if (!_isPlaying || (time < _startTime && !forceTime)) { | ||
return true; | ||
} | ||
if (_yoyo) { | ||
this._reversed = !_reversed | ||
if (!_onStartCallbackFired) { | ||
if (!this._rendered) { | ||
this.render(); | ||
this._rendered = true; | ||
_valuesFunc = this._valuesFunc; | ||
} | ||
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 | ||
: _easingFunction; | ||
if (!object) { | ||
return true; | ||
} | ||
return true | ||
} else { | ||
if (!preserve) { | ||
this._isPlaying = false | ||
remove(this) | ||
_id-- | ||
_valuesFunc(elapsed, elapsed, currentEasing); | ||
if (__render) { | ||
__render.update(object, elapsed); | ||
} | ||
this.emit(EVENT_COMPLETE, object) | ||
this._repeat = this._r | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
} | ||
export default Tween | ||
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 && _reverseDelayTime) { | ||
this._startTime += _duration - _reverseDelayTime; | ||
} | ||
else { | ||
this._startTime += _duration; | ||
} | ||
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 Tween; | ||
}(EventClass)); | ||
export default Tween; |
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
10
5501
0
638245