@litecanvas/utils
Version:
Utilities to help build litecanvas games
2 lines (1 loc) • 2.42 kB
JavaScript
(()=>{var b=Object.defineProperty;var c=(e,t)=>{for(var s in t)b(e,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let t in globalThis.utils)t!=="global"&&(e||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var m={};c(m,{BACK_IN:()=>_,BACK_IN_OUT:()=>y,BACK_OUT:()=>N,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>T,BOUNCE_OUT:()=>o,EASE_IN:()=>f,EASE_IN_OUT:()=>g,EASE_OUT:()=>d,ELASTIC_IN:()=>w,ELASTIC_IN_OUT:()=>v,ELASTIC_OUT:()=>x,LINEAR:()=>l,tween:()=>h});var n=Math.PI/2,h=(e,t,s,r=1,a=l)=>new u(e,t,s,r,a),l=e=>e,f=e=>e*e,d=e=>-e*(e-2),g=e=>e<.5?2*e*e:-2*e*e+4*e-1,_=e=>e*e*e-e*Math.sin(e*Math.PI),N=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},y=e=>{if(e<.5){let s=2*e;return .5*(s*s*s-s*Math.sin(s*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},w=e=>Math.sin(13*n*e)*Math.pow(2,10*(e-1)),x=e=>Math.sin(-13*n*(e+1))*Math.pow(2,-10*e)+1,v=e=>{if(e<.5){let r=Math.sin(13*n*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*r*a}let t=Math.sin(-13*n*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},p=e=>1-o(1-e),o=e=>e<4/11?121*e*e/16:e<8/11?363/40*e*e-99/10*e+17/5:e<9/10?4356/361*e*e-35442/1805*e+16061/1805:54/5*e*e-513/25*e+268/25,T=e=>e<.5?.5*p(e*2):.5*o(e*2-1)+.5,u=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,r,a,i){this._o=t,this._p=s,this._x=r,this._d=a,this._e=i,this._w=0}start(t){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let s=this._o[this._p]||0,r=this._rel?s+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",a=>{if(this._t<=this._w){this._t+=a;return}let i=this._t-this._w;this._o[this._p]=this._lc.lerp(s,r,this._e(i/this._d)),this._t+=a,i>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let s of this._cb)s(this._o);return this}restart(t=null,s=!1){return this.stop(s).restart(t)}onEnd(t){return this._cb.push(t),this}chain(t){return this._ch.onEnd(()=>{this._cu=t.start(this._lc)}),this._ch=t,this}reset(){return this._cb.length=0,this.stop()}relative(t=!0){return this._rel=t,this}delay(t){return this._w=t,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();