@litecanvas/utils
Version:
Utilities to help build litecanvas games
2 lines (1 loc) • 2.42 kB
JavaScript
(()=>{var c=Object.defineProperty;var p=(t,s)=>{for(var i in s)c(t,i,{get:s[i],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let s in globalThis.utils)s!=="global"&&(t||globalThis[s]===void 0)&&(globalThis[s]=globalThis.utils[s])};var u={};p(u,{BACK_IN:()=>x,BACK_IN_OUT:()=>M,BACK_OUT:()=>I,BOUNCE_IN:()=>a,BOUNCE_IN_OUT:()=>O,BOUNCE_OUT:()=>l,EASE_IN:()=>g,EASE_IN_OUT:()=>T,EASE_OUT:()=>b,ELASTIC_IN:()=>E,ELASTIC_IN_OUT:()=>N,ELASTIC_OUT:()=>w,LINEAR:()=>n,tween:()=>f});var _=Math.PI/2,f=(t,s,i,r=1,h=n)=>new o(t,s,i,r,h),n=t=>t,g=t=>t*t,b=t=>-t*(t-2),T=t=>t<.5?2*t*t:-2*t*t+4*t-1,x=t=>t*t*t-t*Math.sin(t*Math.PI),I=t=>{let s=1-t;return 1-(s*s*s-s*Math.sin(s*Math.PI))},M=t=>{if(t<.5){let i=2*t;return .5*(i*i*i-i*Math.sin(i*Math.PI))}let s=1-(2*t-1);return .5*(1-(s*s*s-s*Math.sin(t*Math.PI)))+.5},E=t=>Math.sin(13*_*t)*Math.pow(2,10*(t-1)),w=t=>Math.sin(-13*_*(t+1))*Math.pow(2,-10*t)+1,N=t=>{if(t<.5){let r=Math.sin(13*_*(2*t)),h=Math.pow(2,10*(2*t-1));return .5*r*h}let s=Math.sin(-13*_*(2*t-1+1)),i=Math.pow(2,-10*(2*t-1));return .5*(s*i+2)},a=t=>1-l(1-t),l=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,O=t=>t<.5?.5*a(t*2):.5*l(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(s,i,r,h,e){this._o=s,this._p=i,this._x=r,this._d=h,this._e=e,this._w=0}start(s){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let i=this._o[this._p]||0,r=this._rel?i+this._x:this._x;return this._lc=this._lc||s||globalThis,this._u=this._lc.listen("update",h=>{if(this._t<=this._w){this._t+=h;return}let e=this._t-this._w;this._o[this._p]=this._lc.lerp(i,r,this._e(e/this._d)),this._t+=h,e>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(s=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,s)for(let i of this._cb)i(this._o);return this}restart(s=null,i=!1){return this.stop(i).restart(s)}onEnd(s){return this._cb.push(s),this}chain(s){return this._ch.onEnd(()=>{this._cu=s.start(this._lc)}),this._ch=s,this}reset(){return this._cb.length=0,this.stop()}relative(s=!0){return this._rel=s,this}delay(s){return this._w=s,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||{},u);})();