additween
Version:
Additive tweening library for smooth animations
3 lines (2 loc) • 2.27 kB
JavaScript
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).additween={})}(this,(function(n){"use strict";var e={clone:function(n){var e={};for(var t in n)e[t]=n[t];return e},reduce:function(n,e,t,i){for(var o in n)n[o]-=(e[o]-t[o])*i;return n}};function t(n,e){for(var t=0;t<e.length;t++){var i=e[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}function i(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function o(){}function r(n){return n}var a=function(){function n(t){var a=this;!function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),i(this,"tween",void 0),i(this,"isTweening",void 0),i(this,"finish",void 0),i(this,"cancel",void 0);var u=0,l=null,f=null,c=[],d=t.onRender||o,s=t.stateReducer||e,w=t.onFinish||o,h=t.onCancel||o;var v=function n(){if(null!==l){var e=a.now();f=function(n){for(var e,t,i=s.clone(l),o=c.length-1;o>=0;o--)(e=c[o]).end<n||(t=(e.end-n)/e.duration,i=s.reduce(i,e.toState,e.fromState,e.easing(t)));return i}(e),d(f),!function(n){for(var e=c.length-1;e>=0;e--)if(c[e].end>=n)return!0;return!1}(e)?a.finish():u=a.scheduleAnimationFrame(n)}};this.isTweening=function(){return!!l},this.finish=function(){null!==l&&(w(l),l=null,f=null)},this.cancel=function(){null!==l&&(window.cancelAnimationFrame&&(window.cancelAnimationFrame(u),u=0),h(),l=null,f=null)},this.tween=function(n,e,t,i){var o=this.now(),a={duration:t,end:o+t,fromState:null===l?n:l,toState:e,easing:i||r};!function(n){for(var e=[],t=c.length-1;t>=0;t--)c[t].end>n&&e.push(c[t]);c=e}(o),c.push(a),l=e,u=this.scheduleAnimationFrame(v)}}var a,u,l;return a=n,(u=[{key:"scheduleAnimationFrame",value:function(n){return window.requestAnimationFrame(n)}},{key:"now",value:function(){return window.performance&&window.performance.now?window.performance.now():Date.now?Date.now():(new Date).getTime()}}])&&t(a.prototype,u),l&&t(a,l),n}();n.AdditiveTweening=a,n.PlainObjectReducer=e,Object.defineProperty(n,"__esModule",{value:!0})}));
//# sourceMappingURL=additween.min.js.map