UNPKG

@litecanvas/utils

Version:

Utilities to help build litecanvas games

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