@litecanvas/utils 0.27.0 → 0.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/actor.js CHANGED
@@ -7,10 +7,12 @@
7
7
 
8
8
  // src/_global.js
9
9
  globalThis.utils = globalThis.utils || {};
10
- globalThis.utils.global = () => {
10
+ globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- globalThis[key] = globalThis.utils[key];
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
14
16
  }
15
17
  };
16
18
 
package/dist/actor.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var c=Object.defineProperty;var l=(r,t)=>{for(var e in t)c(r,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let r in globalThis.utils)r!=="global"&&(globalThis[r]=globalThis.utils[r])};var m={};l(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>D,ANCHOR_CENTER:()=>b,ANCHOR_TOP_LEFT:()=>p,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>u});var _=2*Math.PI,n=class{x;y;constructor(t=0,e=t){this.x=t,this.y=e}toString(){return`Vector (${this.x}, ${this.y})`}},f=r=>r instanceof n,s=(r=0,t=r)=>(f(r)&&(t=r.y,r=r.x),new n(r,t));var b=s(.5,.5),p=s(0,0),h=s(1,0),d=s(0,1),D=s(1,1),u=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,a=p){this.sprite=t,this.pos=e||s(0),this._o=s(a),this._s=s(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,e=t){this._s.x=t,this._s.y=e}scaleBy(t,e=t){this._s.x*=t,this._s.y*=e}getBounds(t=!0){let e=this.sprite.width*(t?this._s.x:1),a=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,o=this.pos.y-a*this.anchor.y;return[i,o,e,a]}draw(t=globalThis,e=!0){this.hidden||this.opacity<=0||(e&&t.push(),this.transform(t),this.drawImage(t),e&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,e=!0){let a=this.anchor,i=-this.sprite.width*(this.flipX?1-a.x:a.x),o=-this.sprite.height*(this.flipY?1-a.y:a.y);e&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
1
+ (()=>{var c=Object.defineProperty;var l=(r,t)=>{for(var e in t)c(r,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let t in globalThis.utils)t!=="global"&&(r||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var m={};l(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>D,ANCHOR_CENTER:()=>b,ANCHOR_TOP_LEFT:()=>p,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>u});var _=2*Math.PI,n=class{x;y;constructor(t=0,e=t){this.x=t,this.y=e}toString(){return`Vector (${this.x}, ${this.y})`}},f=r=>r instanceof n,s=(r=0,t=r)=>(f(r)&&(t=r.y,r=r.x),new n(r,t));var b=s(.5,.5),p=s(0,0),h=s(1,0),d=s(0,1),D=s(1,1),u=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,a=p){this.sprite=t,this.pos=e||s(0),this._o=s(a),this._s=s(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,e=t){this._s.x=t,this._s.y=e}scaleBy(t,e=t){this._s.x*=t,this._s.y*=e}getBounds(t=!0){let e=this.sprite.width*(t?this._s.x:1),a=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,o=this.pos.y-a*this.anchor.y;return[i,o,e,a]}draw(t=globalThis,e=!0){this.hidden||this.opacity<=0||(e&&t.push(),this.transform(t),this.drawImage(t),e&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,e=!0){let a=this.anchor,i=-this.sprite.width*(this.flipX?1-a.x:a.x),o=-this.sprite.height*(this.flipY?1-a.y:a.y);e&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
package/dist/all.js CHANGED
@@ -7,10 +7,12 @@
7
7
 
8
8
  // src/_global.js
9
9
  globalThis.utils = globalThis.utils || {};
10
- globalThis.utils.global = () => {
10
+ globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- globalThis[key] = globalThis.utils[key];
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
14
16
  }
15
17
  };
16
18
 
@@ -57,7 +59,7 @@
57
59
  mod: () => mod_default,
58
60
  range: () => range_default,
59
61
  resolve: () => resolve_default,
60
- round: () => round_default,
62
+ roundd: () => roundd_default,
61
63
  scaleImage: () => scale_default,
62
64
  tint: () => tint_default,
63
65
  tween: () => tween,
@@ -914,12 +916,12 @@
914
916
  // src/math/mod.js
915
917
  var mod_default = (a, b) => (b + a % b) % b;
916
918
 
917
- // src/math/round.js
918
- var round_default = (n, decimals) => {
919
- if (!decimals) {
919
+ // src/math/roundd.js
920
+ var roundd_default = (n, precision = 0) => {
921
+ if (!precision) {
920
922
  return Math.round(n);
921
923
  }
922
- const multiplier = Math.pow(10, decimals);
924
+ const multiplier = Math.pow(10, precision);
923
925
  return Math.round(n * multiplier) / multiplier;
924
926
  };
925
927
 
package/dist/all.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var mt=Object.defineProperty;var ft=(e,t)=>{for(var r in t)mt(e,r,{get:t[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var X={};ft(X,{ANCHOR_BOT_LEFT:()=>Wt,ANCHOR_BOT_RIGHT:()=>zt,ANCHOR_CENTER:()=>Yt,ANCHOR_TOP_LEFT:()=>K,ANCHOR_TOP_RIGHT:()=>Nt,Actor:()=>O,BACK_IN:()=>$t,BACK_IN_OUT:()=>Kt,BACK_OUT:()=>Zt,BOUNCE_IN:()=>ot,BOUNCE_IN_OUT:()=>te,BOUNCE_OUT:()=>C,Camera:()=>D,DOWN:()=>Rt,EASE_IN:()=>jt,EASE_IN_OUT:()=>qt,EASE_OUT:()=>Gt,ELASTIC_IN:()=>Jt,ELASTIC_IN_OUT:()=>vt,ELASTIC_OUT:()=>Qt,Grid:()=>T,LEFT:()=>Xt,LINEAR:()=>nt,Noise:()=>R,ONE:()=>kt,RIGHT:()=>St,TypedGrid:()=>B,UP:()=>Ct,Vector:()=>y,ZERO:()=>Z,advance:()=>et,diff:()=>J,dist:()=>at,flipImage:()=>pt,fract:()=>v,intersection:()=>w,mag:()=>it,mod:()=>rt,range:()=>tt,resolve:()=>N,round:()=>st,scaleImage:()=>ct,tint:()=>lt,tween:()=>Ft,vec:()=>n,vecAbs:()=>Ut,vecAdd:()=>A,vecAngle:()=>It,vecAngleBetween:()=>wt,vecCeil:()=>Bt,vecClamp:()=>Pt,vecCross:()=>Tt,vecDist:()=>yt,vecDist2:()=>Et,vecDiv:()=>L,vecDot:()=>$,vecEq:()=>V,vecFloor:()=>Vt,vecIsZero:()=>Ot,vecLerp:()=>Lt,vecLimit:()=>Dt,vecMag:()=>G,vecMag2:()=>q,vecMove:()=>Ht,vecMult:()=>E,vecNorm:()=>H,vecRand:()=>Mt,vecReflect:()=>xt,vecRotate:()=>dt,vecRound:()=>At,vecSet:()=>j,vecSetMag:()=>gt,vecSub:()=>P,wave:()=>Q});var w=(e,t,r,s,a,i,o,h)=>{let u=Math.max(e,a),b=Math.min(e+r,a+o)-u,c=Math.max(t,i),d=Math.min(t+s,i+h)-c;return[u,c,b,d]};var N=(e,t,r,s,a,i,o,h)=>{let[u,b,c,d]=w(e,t,r,s,a,i,o,h),_="",g=e,l=t;return c<d?e<a?(_="right",g=a-r):(_="left",g=a+o):t<i?(_="bottom",l=i-s):(_="top",l=i+h),{direction:_,x:g,y:l}};var D=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,r=0,s=0,a=null,i=null){this._engine=t||globalThis,this.ox=r,this.oy=s,this.resize(a||this._engine.WIDTH-r,i||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(t,r){this.width=t,this.height=r,this._engine.emit("camera-resized",this)}start(t=!1){if(this._engine.push(),t){let a=path();a.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(a)}let r=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(r,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,r){this.x=t,this.y=r}move(t,r){this.x+=t,this.y+=r}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,r=(r-this.height/2-this.oy)/this.scale,s.x=a*t-i*r+this.x,s.y=i*t+a*r+this.y,s}getCameraPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=t-this.x,r=r-this.y,t=a*t-i*r,r=i*t+a*r,s.x=t*this.scale+this.width/2+this.ox,s.y=r*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,r,s,a){let i=this.width/2-this.x,o=this.height/2-this.y,h=this.width/this.scale,u=this.height/this.scale;return this._engine.colrect(t,r,s,a,i,o,h,u)}shake(t=1,r=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),r-=s,r<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var T=class e{_w;_h;_c;constructor(t,r,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~r),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new e(this._w,this._h,this._c)}clear(){this.forEach((t,r)=>this.set(t,r,void 0))}get width(){return this._w}get height(){return this._h}set(t,r,s){this._c[this.pointToIndex(t,r)]=s}get(t,r){return this._c[this.pointToIndex(t,r)]}has(t,r){return this.get(t,r)!=null}check(t,r){return t>=0&&t<this._w&&r>=0&&r<this._h}get length(){return this._w*this._h}pointToIndex(t,r){return this.clampX(~~t)+this.clampY(~~r)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,r=!1){let s=r?this.length-1:0,a=r?-1:this.length,i=r?-1:1;for(;s!==a;){let o=this.indexToPointX(s),h=this.indexToPointY(s),u=this._c[s];if(t(o,h,u,this)===!1)break;s+=i}}fill(t){this.forEach((r,s)=>{this.set(r,s,t)})}clampX(t){return W(t,0,this._w-1)}clampY(t){return W(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",r=!0){if(!r)return this._c.join(t);let s=[];return this.forEach((a,i,o)=>{s[i]=s[i]||"",s[i]+=o+t}),s.join(`
2
- `)}},B=class e extends T{constructor(t,r,s=Uint8Array){super(t,r,null),this._c=new s(this._w*this._h)}has(t,r){return this.get(t,r)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((r,s,a)=>{t.set(r,s,a)}),t}};function W(e,t,r){return e<t?t:e>r?r:e}var _t=Math.sqrt,z=Math.cos,F=Math.sin,bt=2*Math.PI,y=class{x;y;constructor(t=0,r=t){this.x=t,this.y=r}toString(){return`Vector (${this.x}, ${this.y})`}},x=e=>e instanceof y,n=(e=0,t=e)=>(x(e)&&(t=e.y,e=e.x),new y(e,t)),V=(e,t,r=t)=>x(t)?V(e,t.x,t.y):e.x===t&&e.y===r,j=(e,t,r=t)=>(x(t)?j(e,t.x,t.y):(e.x=t,e.y=r),e),A=(e,t,r=t)=>x(t)?A(e,t.x,t.y):(e.x+=t,e.y+=r,e),P=(e,t,r=t)=>x(t)?P(e,t.x,t.y):(e.x-=t,e.y-=r,e),E=(e,t,r=t)=>x(t)?E(e,t.x,t.y):(e.x*=t,e.y*=r,e),L=(e,t,r=t)=>x(t)?L(e,t.x,t.y):(e.x/=t||1,e.y/=r||1,e),dt=(e,t)=>{let r=z(t),s=F(t);return e.x=r*e.x-s*e.y,e.y=s*e.x+r*e.y,e},xt=(e,t)=>{let r=H(n(t));return P(e,E(r,2*$(e,r)))},gt=(e,t)=>(H(e),E(e,t),e),G=e=>Math.hypot(e.x,e.y),q=e=>e.x*e.x+e.y*e.y,H=e=>{let t=G(e);return t>0&&L(e,t),e},Dt=(e,t=1)=>{let r=q(e);return r>t*t&&(L(e,_t(r)),E(e,t)),e},yt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Et=(e,t)=>{let r=e.x-t.x,s=e.y-t.y;return r*r+s*s},It=e=>Math.atan2(e.y,e.x),wt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),$=(e,t)=>e.x*t.x+e.y*t.y,Tt=(e,t)=>e.x*t.y-e.y*t.x,Lt=(e,t,r)=>(e.x+=(t.x-e.x)*r||0,e.y+=(t.y-e.y)*r||0,e),Mt=(e=1,t=e,r=globalThis.rand||Math.random)=>{let s=r()*bt,a=r()*(t-e)+e;return n(z(s)*a,F(s)*a)},Ut=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Bt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Vt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),At=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Pt=(e,t,r)=>(e.x<t.x&&(e.x=t.x),e.x>r.x&&(e.x=r.x),e.y<t.y&&(e.y=t.y),e.y>r.y&&(e.y=r.y),e),Ht=(e,t,r=1)=>A(e,t.x*r,t.y*r),Ot=e=>V(e,Z),Z=n(0,0),kt=n(1,1),Ct=n(0,-1),St=n(1,0),Rt=n(0,1),Xt=n(-1,0);var Yt=n(.5,.5),K=n(0,0),Nt=n(1,0),Wt=n(0,1),zt=n(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,r,s=K){this.sprite=t,this.pos=r||n(0),this._o=n(s),this._s=n(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,r=t){this._s.x=t,this._s.y=r}scaleBy(t,r=t){this._s.x*=t,this._s.y*=r}getBounds(t=!0){let r=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),a=this.pos.x-r*this.anchor.x,i=this.pos.y-s*this.anchor.y;return[a,i,r,s]}draw(t=globalThis,r=!0){this.hidden||this.opacity<=0||(r&&t.push(),this.transform(t),this.drawImage(t),r&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,r=!0){let s=this.anchor,a=-this.sprite.width*(this.flipX?1-s.x:s.x),i=-this.sprite.height*(this.flipY?1-s.y:s.y);r&&t.alpha(this.opacity),t.image(a,i,this.sprite)}};var J=(e,t)=>Math.abs(t-e)||0;var Q=(e,t,r,s=Math.sin)=>e+(s(r)+1)/2*(t-e);var v=e=>e%1||0;var tt=e=>Array.from(Array(e).keys());var et=advance=(e,t,r,s=1)=>{r&&(t.x+=r.x*s,t.y+=r.y*s),e.x+=t.x*s,e.y+=t.y*s};var rt=(e,t)=>(t+e%t)%t;var st=(e,t)=>{if(!t)return Math.round(e);let r=Math.pow(10,t);return Math.round(e*r)/r};var at=(e,t,r,s)=>Math.hypot(r-e,s-t);var it=(e,t)=>Math.hypot(e,t);var M=Math.PI/2,Ft=(e,t,r,s=1,a=nt)=>new k(e,t,r,s,a),nt=e=>e,jt=e=>e*e,Gt=e=>-e*(e-2),qt=e=>e<.5?2*e*e:-2*e*e+4*e-1,$t=e=>e*e*e-e*Math.sin(e*Math.PI),Zt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},Kt=e=>{if(e<.5){let r=2*e;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},Jt=e=>Math.sin(13*M*e)*Math.pow(2,10*(e-1)),Qt=e=>Math.sin(-13*M*(e+1))*Math.pow(2,-10*e)+1,vt=e=>{if(e<.5){let s=Math.sin(13*M*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*s*a}let t=Math.sin(-13*M*(2*e-1+1)),r=Math.pow(2,-10*(2*e-1));return .5*(t*r+2)},ot=e=>1-C(1-e),C=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,te=e=>e<.5?.5*ot(e*2):.5*C(e*2-1)+.5,k=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,r,s,a,i){this._o=t,this._p=r,this._x=s,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 r=this._o[this._p]||0,s=this._rel?r+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(r,s,this._e(i/this._d)),this._t+=a,i>=this._d&&(this._o[this._p]=s,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let r of this._cb)r(this._o);return this}restart(t=null,r=!1){return this.stop(r).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}};var ht=4,U=1<<ht,ut=8,ee=1<<ut,f=4095,S=e=>.5*(1-Math.cos(e*Math.PI)),R=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,r=0,s=0){t<0&&(t=-t),r<0&&(r=-r),s<0&&(s=-s);let a=Math.floor(t),i=Math.floor(r),o=Math.floor(s),h=t-a,u=r-i,b=s-o,c,d,_=0,g=.5,l,p,I;for(let Y=0;Y<this._po;Y++){let m=a+(i<<ht)+(o<<ut);c=S(h),d=S(u),l=this._p[m&f],l+=c*(this._p[m+1&f]-l),p=this._p[m+U&f],p+=c*(this._p[m+U+1&f]-p),l+=d*(p-l),m+=ee,p=this._p[m&f],p+=c*(this._p[m+1&f]-p),I=this._p[m+U&f],I+=c*(this._p[m+U+1&f]-I),p+=d*(I-p),l+=S(b)*(p-l),_+=l*g,g*=this._pf,a<<=1,h*=2,i<<=1,u*=2,o<<=1,b*=2,h>=1&&(a++,h--),u>=1&&(i++,u--),b>=1&&(o++,b--)}return _}noiseDetail(t,r){t>0&&(this._po=t),r>0&&(this._pf=r)}noiseSeed(t=null){t!=null&&this._e.seed(t);let r=this._e.rand||Math.random;for(let s=0;s<f+1;s++)this._p[s]=r()}};var lt=(e,t,r=1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.alpha(r),s.rectfill(0,0,e.width,e.height,t),a.globalCompositeOperation="destination-atop",s.alpha(1),s.image(0,0,e),s.pop()});var ct=(e,t,r=!0,s=globalThis)=>s.paint(e.width*t,e.height*t,a=>{s.push(),a.imageSmoothingEnabled=!r,s.scale(t),s.image(0,0,e),s.pop()});var pt=(e,t=!0,r=!1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.scale(t?-1:1,r?-1:1),s.image(t?-e.width:0,r?-e.height:0,e),s.pop()});globalThis.utils=Object.assign(globalThis.utils||{},X);})();
1
+ (()=>{var mt=Object.defineProperty;var ft=(e,t)=>{for(var r in t)mt(e,r,{get:t[r],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 X={};ft(X,{ANCHOR_BOT_LEFT:()=>Wt,ANCHOR_BOT_RIGHT:()=>zt,ANCHOR_CENTER:()=>Yt,ANCHOR_TOP_LEFT:()=>K,ANCHOR_TOP_RIGHT:()=>Nt,Actor:()=>O,BACK_IN:()=>$t,BACK_IN_OUT:()=>Kt,BACK_OUT:()=>Zt,BOUNCE_IN:()=>ot,BOUNCE_IN_OUT:()=>te,BOUNCE_OUT:()=>C,Camera:()=>D,DOWN:()=>Rt,EASE_IN:()=>jt,EASE_IN_OUT:()=>qt,EASE_OUT:()=>Gt,ELASTIC_IN:()=>Jt,ELASTIC_IN_OUT:()=>vt,ELASTIC_OUT:()=>Qt,Grid:()=>w,LEFT:()=>Xt,LINEAR:()=>nt,Noise:()=>R,ONE:()=>kt,RIGHT:()=>St,TypedGrid:()=>B,UP:()=>Ct,Vector:()=>y,ZERO:()=>Z,advance:()=>et,diff:()=>J,dist:()=>at,flipImage:()=>pt,fract:()=>v,intersection:()=>T,mag:()=>it,mod:()=>rt,range:()=>tt,resolve:()=>N,roundd:()=>st,scaleImage:()=>ct,tint:()=>lt,tween:()=>Ft,vec:()=>n,vecAbs:()=>Ut,vecAdd:()=>A,vecAngle:()=>It,vecAngleBetween:()=>Tt,vecCeil:()=>Bt,vecClamp:()=>Pt,vecCross:()=>wt,vecDist:()=>yt,vecDist2:()=>Et,vecDiv:()=>L,vecDot:()=>$,vecEq:()=>V,vecFloor:()=>Vt,vecIsZero:()=>Ot,vecLerp:()=>Lt,vecLimit:()=>Dt,vecMag:()=>G,vecMag2:()=>q,vecMove:()=>Ht,vecMult:()=>E,vecNorm:()=>H,vecRand:()=>Mt,vecReflect:()=>xt,vecRotate:()=>dt,vecRound:()=>At,vecSet:()=>j,vecSetMag:()=>gt,vecSub:()=>P,wave:()=>Q});var T=(e,t,r,s,a,i,o,h)=>{let u=Math.max(e,a),b=Math.min(e+r,a+o)-u,c=Math.max(t,i),d=Math.min(t+s,i+h)-c;return[u,c,b,d]};var N=(e,t,r,s,a,i,o,h)=>{let[u,b,c,d]=T(e,t,r,s,a,i,o,h),_="",g=e,l=t;return c<d?e<a?(_="right",g=a-r):(_="left",g=a+o):t<i?(_="bottom",l=i-s):(_="top",l=i+h),{direction:_,x:g,y:l}};var D=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,r=0,s=0,a=null,i=null){this._engine=t||globalThis,this.ox=r,this.oy=s,this.resize(a||this._engine.WIDTH-r,i||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(t,r){this.width=t,this.height=r,this._engine.emit("camera-resized",this)}start(t=!1){if(this._engine.push(),t){let a=path();a.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(a)}let r=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(r,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,r){this.x=t,this.y=r}move(t,r){this.x+=t,this.y+=r}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,r=(r-this.height/2-this.oy)/this.scale,s.x=a*t-i*r+this.x,s.y=i*t+a*r+this.y,s}getCameraPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=t-this.x,r=r-this.y,t=a*t-i*r,r=i*t+a*r,s.x=t*this.scale+this.width/2+this.ox,s.y=r*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,r,s,a){let i=this.width/2-this.x,o=this.height/2-this.y,h=this.width/this.scale,u=this.height/this.scale;return this._engine.colrect(t,r,s,a,i,o,h,u)}shake(t=1,r=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),r-=s,r<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var w=class e{_w;_h;_c;constructor(t,r,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~r),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new e(this._w,this._h,this._c)}clear(){this.forEach((t,r)=>this.set(t,r,void 0))}get width(){return this._w}get height(){return this._h}set(t,r,s){this._c[this.pointToIndex(t,r)]=s}get(t,r){return this._c[this.pointToIndex(t,r)]}has(t,r){return this.get(t,r)!=null}check(t,r){return t>=0&&t<this._w&&r>=0&&r<this._h}get length(){return this._w*this._h}pointToIndex(t,r){return this.clampX(~~t)+this.clampY(~~r)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,r=!1){let s=r?this.length-1:0,a=r?-1:this.length,i=r?-1:1;for(;s!==a;){let o=this.indexToPointX(s),h=this.indexToPointY(s),u=this._c[s];if(t(o,h,u,this)===!1)break;s+=i}}fill(t){this.forEach((r,s)=>{this.set(r,s,t)})}clampX(t){return W(t,0,this._w-1)}clampY(t){return W(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",r=!0){if(!r)return this._c.join(t);let s=[];return this.forEach((a,i,o)=>{s[i]=s[i]||"",s[i]+=o+t}),s.join(`
2
+ `)}},B=class e extends w{constructor(t,r,s=Uint8Array){super(t,r,null),this._c=new s(this._w*this._h)}has(t,r){return this.get(t,r)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((r,s,a)=>{t.set(r,s,a)}),t}};function W(e,t,r){return e<t?t:e>r?r:e}var _t=Math.sqrt,z=Math.cos,F=Math.sin,bt=2*Math.PI,y=class{x;y;constructor(t=0,r=t){this.x=t,this.y=r}toString(){return`Vector (${this.x}, ${this.y})`}},x=e=>e instanceof y,n=(e=0,t=e)=>(x(e)&&(t=e.y,e=e.x),new y(e,t)),V=(e,t,r=t)=>x(t)?V(e,t.x,t.y):e.x===t&&e.y===r,j=(e,t,r=t)=>(x(t)?j(e,t.x,t.y):(e.x=t,e.y=r),e),A=(e,t,r=t)=>x(t)?A(e,t.x,t.y):(e.x+=t,e.y+=r,e),P=(e,t,r=t)=>x(t)?P(e,t.x,t.y):(e.x-=t,e.y-=r,e),E=(e,t,r=t)=>x(t)?E(e,t.x,t.y):(e.x*=t,e.y*=r,e),L=(e,t,r=t)=>x(t)?L(e,t.x,t.y):(e.x/=t||1,e.y/=r||1,e),dt=(e,t)=>{let r=z(t),s=F(t);return e.x=r*e.x-s*e.y,e.y=s*e.x+r*e.y,e},xt=(e,t)=>{let r=H(n(t));return P(e,E(r,2*$(e,r)))},gt=(e,t)=>(H(e),E(e,t),e),G=e=>Math.hypot(e.x,e.y),q=e=>e.x*e.x+e.y*e.y,H=e=>{let t=G(e);return t>0&&L(e,t),e},Dt=(e,t=1)=>{let r=q(e);return r>t*t&&(L(e,_t(r)),E(e,t)),e},yt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Et=(e,t)=>{let r=e.x-t.x,s=e.y-t.y;return r*r+s*s},It=e=>Math.atan2(e.y,e.x),Tt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),$=(e,t)=>e.x*t.x+e.y*t.y,wt=(e,t)=>e.x*t.y-e.y*t.x,Lt=(e,t,r)=>(e.x+=(t.x-e.x)*r||0,e.y+=(t.y-e.y)*r||0,e),Mt=(e=1,t=e,r=globalThis.rand||Math.random)=>{let s=r()*bt,a=r()*(t-e)+e;return n(z(s)*a,F(s)*a)},Ut=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Bt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Vt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),At=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Pt=(e,t,r)=>(e.x<t.x&&(e.x=t.x),e.x>r.x&&(e.x=r.x),e.y<t.y&&(e.y=t.y),e.y>r.y&&(e.y=r.y),e),Ht=(e,t,r=1)=>A(e,t.x*r,t.y*r),Ot=e=>V(e,Z),Z=n(0,0),kt=n(1,1),Ct=n(0,-1),St=n(1,0),Rt=n(0,1),Xt=n(-1,0);var Yt=n(.5,.5),K=n(0,0),Nt=n(1,0),Wt=n(0,1),zt=n(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,r,s=K){this.sprite=t,this.pos=r||n(0),this._o=n(s),this._s=n(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,r=t){this._s.x=t,this._s.y=r}scaleBy(t,r=t){this._s.x*=t,this._s.y*=r}getBounds(t=!0){let r=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),a=this.pos.x-r*this.anchor.x,i=this.pos.y-s*this.anchor.y;return[a,i,r,s]}draw(t=globalThis,r=!0){this.hidden||this.opacity<=0||(r&&t.push(),this.transform(t),this.drawImage(t),r&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,r=!0){let s=this.anchor,a=-this.sprite.width*(this.flipX?1-s.x:s.x),i=-this.sprite.height*(this.flipY?1-s.y:s.y);r&&t.alpha(this.opacity),t.image(a,i,this.sprite)}};var J=(e,t)=>Math.abs(t-e)||0;var Q=(e,t,r,s=Math.sin)=>e+(s(r)+1)/2*(t-e);var v=e=>e%1||0;var tt=e=>Array.from(Array(e).keys());var et=advance=(e,t,r,s=1)=>{r&&(t.x+=r.x*s,t.y+=r.y*s),e.x+=t.x*s,e.y+=t.y*s};var rt=(e,t)=>(t+e%t)%t;var st=(e,t=0)=>{if(!t)return Math.round(e);let r=Math.pow(10,t);return Math.round(e*r)/r};var at=(e,t,r,s)=>Math.hypot(r-e,s-t);var it=(e,t)=>Math.hypot(e,t);var M=Math.PI/2,Ft=(e,t,r,s=1,a=nt)=>new k(e,t,r,s,a),nt=e=>e,jt=e=>e*e,Gt=e=>-e*(e-2),qt=e=>e<.5?2*e*e:-2*e*e+4*e-1,$t=e=>e*e*e-e*Math.sin(e*Math.PI),Zt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},Kt=e=>{if(e<.5){let r=2*e;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},Jt=e=>Math.sin(13*M*e)*Math.pow(2,10*(e-1)),Qt=e=>Math.sin(-13*M*(e+1))*Math.pow(2,-10*e)+1,vt=e=>{if(e<.5){let s=Math.sin(13*M*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*s*a}let t=Math.sin(-13*M*(2*e-1+1)),r=Math.pow(2,-10*(2*e-1));return .5*(t*r+2)},ot=e=>1-C(1-e),C=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,te=e=>e<.5?.5*ot(e*2):.5*C(e*2-1)+.5,k=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,r,s,a,i){this._o=t,this._p=r,this._x=s,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 r=this._o[this._p]||0,s=this._rel?r+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(r,s,this._e(i/this._d)),this._t+=a,i>=this._d&&(this._o[this._p]=s,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let r of this._cb)r(this._o);return this}restart(t=null,r=!1){return this.stop(r).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}};var ht=4,U=1<<ht,ut=8,ee=1<<ut,f=4095,S=e=>.5*(1-Math.cos(e*Math.PI)),R=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,r=0,s=0){t<0&&(t=-t),r<0&&(r=-r),s<0&&(s=-s);let a=Math.floor(t),i=Math.floor(r),o=Math.floor(s),h=t-a,u=r-i,b=s-o,c,d,_=0,g=.5,l,p,I;for(let Y=0;Y<this._po;Y++){let m=a+(i<<ht)+(o<<ut);c=S(h),d=S(u),l=this._p[m&f],l+=c*(this._p[m+1&f]-l),p=this._p[m+U&f],p+=c*(this._p[m+U+1&f]-p),l+=d*(p-l),m+=ee,p=this._p[m&f],p+=c*(this._p[m+1&f]-p),I=this._p[m+U&f],I+=c*(this._p[m+U+1&f]-I),p+=d*(I-p),l+=S(b)*(p-l),_+=l*g,g*=this._pf,a<<=1,h*=2,i<<=1,u*=2,o<<=1,b*=2,h>=1&&(a++,h--),u>=1&&(i++,u--),b>=1&&(o++,b--)}return _}noiseDetail(t,r){t>0&&(this._po=t),r>0&&(this._pf=r)}noiseSeed(t=null){t!=null&&this._e.seed(t);let r=this._e.rand||Math.random;for(let s=0;s<f+1;s++)this._p[s]=r()}};var lt=(e,t,r=1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.alpha(r),s.rectfill(0,0,e.width,e.height,t),a.globalCompositeOperation="destination-atop",s.alpha(1),s.image(0,0,e),s.pop()});var ct=(e,t,r=!0,s=globalThis)=>s.paint(e.width*t,e.height*t,a=>{s.push(),a.imageSmoothingEnabled=!r,s.scale(t),s.image(0,0,e),s.pop()});var pt=(e,t=!0,r=!1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.scale(t?-1:1,r?-1:1),s.image(t?-e.width:0,r?-e.height:0,e),s.pop()});globalThis.utils=Object.assign(globalThis.utils||{},X);})();
3
3
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/camera.js CHANGED
@@ -1,10 +1,12 @@
1
1
  (() => {
2
2
  // src/_global.js
3
3
  globalThis.utils = globalThis.utils || {};
4
- globalThis.utils.global = () => {
4
+ globalThis.utils.global = (overrides = true) => {
5
5
  for (const key in globalThis.utils) {
6
6
  if ("global" === key) continue;
7
- globalThis[key] = globalThis.utils[key];
7
+ if (overrides || globalThis[key] === void 0) {
8
+ globalThis[key] = globalThis.utils[key];
9
+ }
8
10
  }
9
11
  };
10
12
 
@@ -1 +1 @@
1
- (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let o in globalThis.utils)o!=="global"&&(globalThis[o]=globalThis.utils[o])};var n=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,i=0,s=0,h=null,e=null){this._engine=t||globalThis,this.ox=i,this.oy=s,this.resize(h||this._engine.WIDTH-i,e||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(t,i){this.width=t,this.height=i,this._engine.emit("camera-resized",this)}start(t=!1){if(this._engine.push(),t){let h=path();h.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(h)}let i=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(i,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,i){this.x=t,this.y=i}move(t,i){this.x+=t,this.y+=i}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,i,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,i=(i-this.height/2-this.oy)/this.scale,s.x=h*t-e*i+this.x,s.y=e*t+h*i+this.y,s}getCameraPoint(t,i,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return t=t-this.x,i=i-this.y,t=h*t-e*i,i=e*t+h*i,s.x=t*this.scale+this.width/2+this.ox,s.y=i*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,i,s,h){let e=this.width/2-this.x,a=this.height/2-this.y,l=this.width/this.scale,r=this.height/this.scale;return this._engine.colrect(t,i,s,h,e,a,l,r)}shake(t=1,i=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),i-=s,i<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};globalThis.utils=Object.assign(globalThis.utils||{},{Camera:n});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let i in globalThis.utils)i!=="global"&&(o||globalThis[i]===void 0)&&(globalThis[i]=globalThis.utils[i])};var n=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(i=null,t=0,s=0,h=null,e=null){this._engine=i||globalThis,this.ox=t,this.oy=s,this.resize(h||this._engine.WIDTH-t,e||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(i,t){this.width=i,this.height=t,this._engine.emit("camera-resized",this)}start(i=!1){if(this._engine.push(),i){let h=path();h.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(h)}let t=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(t,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(i,t){this.x=i,this.y=t}move(i,t){this.x+=i,this.y+=t}zoom(i){this.scale*=i}zoomTo(i){this.scale=i}rotate(i){this.rotation+=i}rotateTo(i){this.rotation=i}getWorldPoint(i,t,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return i=(i-this.width/2-this.ox)/this.scale,t=(t-this.height/2-this.oy)/this.scale,s.x=h*i-e*t+this.x,s.y=e*i+h*t+this.y,s}getCameraPoint(i,t,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return i=i-this.x,t=t-this.y,i=h*i-e*t,t=e*i+h*t,s.x=i*this.scale+this.width/2+this.ox,s.y=t*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(i,t,s,h){let e=this.width/2-this.x,a=this.height/2-this.y,l=this.width/this.scale,r=this.height/this.scale;return this._engine.colrect(i,t,s,h,e,a,l,r)}shake(i=1,t=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-i,i),this._shake.y=this._engine.randi(-i,i),t-=s,t<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};globalThis.utils=Object.assign(globalThis.utils||{},{Camera:n});})();
package/dist/collision.js CHANGED
@@ -1,10 +1,12 @@
1
1
  (() => {
2
2
  // src/_global.js
3
3
  globalThis.utils = globalThis.utils || {};
4
- globalThis.utils.global = () => {
4
+ globalThis.utils.global = (overrides = true) => {
5
5
  for (const key in globalThis.utils) {
6
6
  if ("global" === key) continue;
7
- globalThis[key] = globalThis.utils[key];
7
+ if (overrides || globalThis[key] === void 0) {
8
+ globalThis[key] = globalThis.utils[key];
9
+ }
8
10
  }
9
11
  };
10
12
 
@@ -1 +1 @@
1
- (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var g=(t,o,s,r,l,i,a,n)=>{let f=Math.max(t,l),c=Math.min(t+s,l+a)-f,h=Math.max(o,i),b=Math.min(o+r,i+n)-h;return[f,h,c,b]};var p=(t,o,s,r,l,i,a,n)=>{let[f,c,h,b]=g(t,o,s,r,l,i,a,n),e="",m=t,u=o;return h<b?t<l?(e="right",m=l-s):(e="left",m=l+a):o<i?(e="bottom",u=i-r):(e="top",u=i+n),{direction:e,x:m,y:u}};globalThis.utils=Object.assign(globalThis.utils||{},{resolve:p,intersection:g});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=(l=!0)=>{for(let t in globalThis.utils)t!=="global"&&(l||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var f=(l,t,s,r,i,o,n,a)=>{let g=Math.max(l,i),c=Math.min(l+s,i+n)-g,h=Math.max(t,o),u=Math.min(t+r,o+a)-h;return[g,h,c,u]};var p=(l,t,s,r,i,o,n,a)=>{let[g,c,h,u]=f(l,t,s,r,i,o,n,a),e="",b=l,m=t;return h<u?l<i?(e="right",b=i-s):(e="left",b=i+n):t<o?(e="bottom",m=o-r):(e="top",m=o+a),{direction:e,x:b,y:m}};globalThis.utils=Object.assign(globalThis.utils||{},{resolve:p,intersection:f});})();
package/dist/grid.js CHANGED
@@ -7,10 +7,12 @@
7
7
 
8
8
  // src/_global.js
9
9
  globalThis.utils = globalThis.utils || {};
10
- globalThis.utils.global = () => {
10
+ globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- globalThis[key] = globalThis.utils[key];
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
14
16
  }
15
17
  };
16
18
 
package/dist/grid.min.js CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{var g=Object.defineProperty;var f=(h,t)=>{for(var i in t)g(h,i,{get:t[i],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let h in globalThis.utils)h!=="global"&&(globalThis[h]=globalThis.utils[h])};var c={};f(c,{Grid:()=>r,TypedGrid:()=>l});var r=class h{_w;_h;_c;constructor(t,i,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~i),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new h(this._w,this._h,this._c)}clear(){this.forEach((t,i)=>this.set(t,i,void 0))}get width(){return this._w}get height(){return this._h}set(t,i,s){this._c[this.pointToIndex(t,i)]=s}get(t,i){return this._c[this.pointToIndex(t,i)]}has(t,i){return this.get(t,i)!=null}check(t,i){return t>=0&&t<this._w&&i>=0&&i<this._h}get length(){return this._w*this._h}pointToIndex(t,i){return this.clampX(~~t)+this.clampY(~~i)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,i=!1){let s=i?this.length-1:0,e=i?-1:this.length,n=i?-1:1;for(;s!==e;){let o=this.indexToPointX(s),a=this.indexToPointY(s),_=this._c[s];if(t(o,a,_,this)===!1)break;s+=n}}fill(t){this.forEach((i,s)=>{this.set(i,s,t)})}clampX(t){return u(t,0,this._w-1)}clampY(t){return u(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",i=!0){if(!i)return this._c.join(t);let s=[];return this.forEach((e,n,o)=>{s[n]=s[n]||"",s[n]+=o+t}),s.join(`
1
+ (()=>{var g=Object.defineProperty;var f=(h,t)=>{for(var i in t)g(h,i,{get:t[i],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(h=!0)=>{for(let t in globalThis.utils)t!=="global"&&(h||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var c={};f(c,{Grid:()=>r,TypedGrid:()=>l});var r=class h{_w;_h;_c;constructor(t,i,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~i),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new h(this._w,this._h,this._c)}clear(){this.forEach((t,i)=>this.set(t,i,void 0))}get width(){return this._w}get height(){return this._h}set(t,i,s){this._c[this.pointToIndex(t,i)]=s}get(t,i){return this._c[this.pointToIndex(t,i)]}has(t,i){return this.get(t,i)!=null}check(t,i){return t>=0&&t<this._w&&i>=0&&i<this._h}get length(){return this._w*this._h}pointToIndex(t,i){return this.clampX(~~t)+this.clampY(~~i)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,i=!1){let s=i?this.length-1:0,e=i?-1:this.length,n=i?-1:1;for(;s!==e;){let o=this.indexToPointX(s),a=this.indexToPointY(s),_=this._c[s];if(t(o,a,_,this)===!1)break;s+=n}}fill(t){this.forEach((i,s)=>{this.set(i,s,t)})}clampX(t){return u(t,0,this._w-1)}clampY(t){return u(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",i=!0){if(!i)return this._c.join(t);let s=[];return this.forEach((e,n,o)=>{s[n]=s[n]||"",s[n]+=o+t}),s.join(`
2
2
  `)}},l=class h extends r{constructor(t,i,s=Uint8Array){super(t,i,null),this._c=new s(this._w*this._h)}has(t,i){return this.get(t,i)!==0}clone(){let t=new h(this._w,this._h,this._c.constructor);return this.forEach((i,s,e)=>{t.set(i,s,e)}),t}};function u(h,t,i){return h<t?t:h>i?i:h}globalThis.utils=Object.assign(globalThis.utils||{},c);})();
package/dist/image.js CHANGED
@@ -1,10 +1,12 @@
1
1
  (() => {
2
2
  // src/_global.js
3
3
  globalThis.utils = globalThis.utils || {};
4
- globalThis.utils.global = () => {
4
+ globalThis.utils.global = (overrides = true) => {
5
5
  for (const key in globalThis.utils) {
6
6
  if ("global" === key) continue;
7
- globalThis[key] = globalThis.utils[key];
7
+ if (overrides || globalThis[key] === void 0) {
8
+ globalThis[key] = globalThis.utils[key];
9
+ }
8
10
  }
9
11
  };
10
12
 
package/dist/image.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var s=(e,a,r=1,t=globalThis)=>t.paint(e.width,e.height,n=>{t.push(),t.alpha(r),t.rectfill(0,0,e.width,e.height,a),n.globalCompositeOperation="destination-atop",t.alpha(1),t.image(0,0,e),t.pop()});var i=(e,a,r=!0,t=globalThis)=>t.paint(e.width*a,e.height*a,n=>{t.push(),n.imageSmoothingEnabled=!r,t.scale(a),t.image(0,0,e),t.pop()});var u=(e,a=!0,r=!1,t=globalThis)=>t.paint(e.width,e.height,n=>{t.push(),t.scale(a?-1:1,r?-1:1),t.image(a?-e.width:0,r?-e.height:0,e),t.pop()});globalThis.utils=Object.assign(globalThis.utils||{},{tint:s,scaleImage:i,flipImage:u});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let a in globalThis.utils)a!=="global"&&(t||globalThis[a]===void 0)&&(globalThis[a]=globalThis.utils[a])};var s=(t,a,r=1,e=globalThis)=>e.paint(t.width,t.height,n=>{e.push(),e.alpha(r),e.rectfill(0,0,t.width,t.height,a),n.globalCompositeOperation="destination-atop",e.alpha(1),e.image(0,0,t),e.pop()});var i=(t,a,r=!0,e=globalThis)=>e.paint(t.width*a,t.height*a,n=>{e.push(),n.imageSmoothingEnabled=!r,e.scale(a),e.image(0,0,t),e.pop()});var u=(t,a=!0,r=!1,e=globalThis)=>e.paint(t.width,t.height,n=>{e.push(),e.scale(a?-1:1,r?-1:1),e.image(a?-t.width:0,r?-t.height:0,t),e.pop()});globalThis.utils=Object.assign(globalThis.utils||{},{tint:s,scaleImage:i,flipImage:u});})();
package/dist/math.js CHANGED
@@ -7,10 +7,12 @@
7
7
 
8
8
  // src/_global.js
9
9
  globalThis.utils = globalThis.utils || {};
10
- globalThis.utils.global = () => {
10
+ globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- globalThis[key] = globalThis.utils[key];
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
14
16
  }
15
17
  };
16
18
 
@@ -24,7 +26,7 @@
24
26
  mag: () => mag_default,
25
27
  mod: () => mod_default,
26
28
  range: () => range_default,
27
- round: () => round_default,
29
+ roundd: () => roundd_default,
28
30
  wave: () => wave_default
29
31
  });
30
32
 
@@ -56,12 +58,12 @@
56
58
  // src/math/mod.js
57
59
  var mod_default = (a, b) => (b + a % b) % b;
58
60
 
59
- // src/math/round.js
60
- var round_default = (n, decimals) => {
61
- if (!decimals) {
61
+ // src/math/roundd.js
62
+ var roundd_default = (n, precision = 0) => {
63
+ if (!precision) {
62
64
  return Math.round(n);
63
65
  }
64
- const multiplier = Math.pow(10, decimals);
66
+ const multiplier = Math.pow(10, precision);
65
67
  return Math.round(n * multiplier) / multiplier;
66
68
  };
67
69
 
package/dist/math.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var i=Object.defineProperty;var h=(t,r)=>{for(var o in r)i(t,o,{get:r[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var s={};h(s,{advance:()=>u,diff:()=>n,dist:()=>f,fract:()=>x,mag:()=>l,mod:()=>p,range:()=>a,round:()=>y,wave:()=>c});var n=(t,r)=>Math.abs(r-t)||0;var c=(t,r,o,e=Math.sin)=>t+(e(o)+1)/2*(r-t);var x=t=>t%1||0;var a=t=>Array.from(Array(t).keys());var T=2*Math.PI;var u=advance=(t,r,o,e=1)=>{o&&(r.x+=o.x*e,r.y+=o.y*e),t.x+=r.x*e,t.y+=r.y*e};var p=(t,r)=>(r+t%r)%r;var y=(t,r)=>{if(!r)return Math.round(t);let o=Math.pow(10,r);return Math.round(t*o)/o};var f=(t,r,o,e)=>Math.hypot(o-t,e-r);var l=(t,r)=>Math.hypot(t,r);globalThis.utils=Object.assign(globalThis.utils||{},s);})();
1
+ (()=>{var i=Object.defineProperty;var h=(r,t)=>{for(var o in t)i(r,o,{get:t[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let t in globalThis.utils)t!=="global"&&(r||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var s={};h(s,{advance:()=>u,diff:()=>n,dist:()=>f,fract:()=>x,mag:()=>l,mod:()=>p,range:()=>a,roundd:()=>y,wave:()=>c});var n=(r,t)=>Math.abs(t-r)||0;var c=(r,t,o,e=Math.sin)=>r+(e(o)+1)/2*(t-r);var x=r=>r%1||0;var a=r=>Array.from(Array(r).keys());var T=2*Math.PI;var u=advance=(r,t,o,e=1)=>{o&&(t.x+=o.x*e,t.y+=o.y*e),r.x+=t.x*e,r.y+=t.y*e};var p=(r,t)=>(t+r%t)%t;var y=(r,t=0)=>{if(!t)return Math.round(r);let o=Math.pow(10,t);return Math.round(r*o)/o};var f=(r,t,o,e)=>Math.hypot(o-r,e-t);var l=(r,t)=>Math.hypot(r,t);globalThis.utils=Object.assign(globalThis.utils||{},s);})();
package/dist/noise.js CHANGED
@@ -7,10 +7,12 @@
7
7
 
8
8
  // src/_global.js
9
9
  globalThis.utils = globalThis.utils || {};
10
- globalThis.utils.global = () => {
10
+ globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- globalThis[key] = globalThis.utils[key];
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
14
16
  }
15
17
  };
16
18
 
package/dist/noise.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var T=Object.defineProperty;var y=(i,e)=>{for(var t in e)T(i,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let i in globalThis.utils)i!=="global"&&(globalThis[i]=globalThis.utils[i])};var g={};y(g,{Noise:()=>E});var B=4,h=1<<B,V=8,v=1<<V,s=4095,_=i=>.5*(1-Math.cos(i*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,r=0){e<0&&(e=-e),t<0&&(t=-t),r<0&&(r=-r);let o=Math.floor(e),l=Math.floor(t),p=Math.floor(r),f=e-o,b=t-l,c=r-p,m,D,I=0,L=.5,u,a,d;for(let U=0;U<this._po;U++){let n=o+(l<<B)+(p<<V);m=_(f),D=_(b),u=this._p[n&s],u+=m*(this._p[n+1&s]-u),a=this._p[n+h&s],a+=m*(this._p[n+h+1&s]-a),u+=D*(a-u),n+=v,a=this._p[n&s],a+=m*(this._p[n+1&s]-a),d=this._p[n+h&s],d+=m*(this._p[n+h+1&s]-d),a+=D*(d-a),u+=_(c)*(a-u),I+=u*L,L*=this._pf,o<<=1,f*=2,l<<=1,b*=2,p<<=1,c*=2,f>=1&&(o++,f--),b>=1&&(l++,b--),c>=1&&(p++,c--)}return I}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.seed(e);let t=this._e.rand||Math.random;for(let r=0;r<s+1;r++)this._p[r]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},g);})();
1
+ (()=>{var T=Object.defineProperty;var y=(u,e)=>{for(var t in e)T(u,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(u=!0)=>{for(let e in globalThis.utils)e!=="global"&&(u||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var g={};y(g,{Noise:()=>E});var B=4,h=1<<B,V=8,v=1<<V,s=4095,_=u=>.5*(1-Math.cos(u*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,r=0){e<0&&(e=-e),t<0&&(t=-t),r<0&&(r=-r);let o=Math.floor(e),l=Math.floor(t),p=Math.floor(r),f=e-o,b=t-l,c=r-p,m,D,I=0,L=.5,i,a,d;for(let U=0;U<this._po;U++){let n=o+(l<<B)+(p<<V);m=_(f),D=_(b),i=this._p[n&s],i+=m*(this._p[n+1&s]-i),a=this._p[n+h&s],a+=m*(this._p[n+h+1&s]-a),i+=D*(a-i),n+=v,a=this._p[n&s],a+=m*(this._p[n+1&s]-a),d=this._p[n+h&s],d+=m*(this._p[n+h+1&s]-d),a+=D*(d-a),i+=_(c)*(a-i),I+=i*L,L*=this._pf,o<<=1,f*=2,l<<=1,b*=2,p<<=1,c*=2,f>=1&&(o++,f--),b>=1&&(l++,b--),c>=1&&(p++,c--)}return I}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.seed(e);let t=this._e.rand||Math.random;for(let r=0;r<s+1;r++)this._p[r]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},g);})();
package/dist/tween.js CHANGED
@@ -7,10 +7,12 @@
7
7
 
8
8
  // src/_global.js
9
9
  globalThis.utils = globalThis.utils || {};
10
- globalThis.utils.global = () => {
10
+ globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- globalThis[key] = globalThis.utils[key];
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
14
16
  }
15
17
  };
16
18
 
package/dist/tween.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var c=Object.defineProperty;var f=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var o={};f(o,{BACK_IN:()=>D,BACK_IN_OUT:()=>g,BACK_OUT:()=>E,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>T,BOUNCE_OUT:()=>m,EASE_IN:()=>h,EASE_IN_OUT:()=>d,EASE_OUT:()=>_,ELASTIC_IN:()=>I,ELASTIC_IN_OUT:()=>U,ELASTIC_OUT:()=>L,LINEAR:()=>l,tween:()=>b});var i=Math.PI/2,b=(t,e,r,a=1,s=l)=>new u(t,e,r,a,s),l=t=>t,h=t=>t*t,_=t=>-t*(t-2),d=t=>t<.5?2*t*t:-2*t*t+4*t-1,D=t=>t*t*t-t*Math.sin(t*Math.PI),E=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},g=t=>{if(t<.5){let r=2*t;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},I=t=>Math.sin(13*i*t)*Math.pow(2,10*(t-1)),L=t=>Math.sin(-13*i*(t+1))*Math.pow(2,-10*t)+1,U=t=>{if(t<.5){let a=Math.sin(13*i*(2*t)),s=Math.pow(2,10*(2*t-1));return .5*a*s}let e=Math.sin(-13*i*(2*t-1+1)),r=Math.pow(2,-10*(2*t-1));return .5*(e*r+2)},p=t=>1-m(1-t),m=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*p(t*2):.5*m(t*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(e,r,a,s,n){this._o=e,this._p=r,this._x=a,this._d=s,this._e=n,this._w=0}start(e){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,a=this._rel?r+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",s=>{if(this._t<=this._w){this._t+=s;return}let n=this._t-this._w;this._o[this._p]=this._lc.lerp(r,a,this._e(n/this._d)),this._t+=s,n>=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 r of this._cb)r(this._o);return this}restart(e=null,r=!1){return this.stop(r).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||{},o);})();
1
+ (()=>{var c=Object.defineProperty;var f=(t,e)=>{for(var r in e)c(t,r,{get:e[r],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 o={};f(o,{BACK_IN:()=>D,BACK_IN_OUT:()=>g,BACK_OUT:()=>E,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>T,BOUNCE_OUT:()=>m,EASE_IN:()=>h,EASE_IN_OUT:()=>d,EASE_OUT:()=>_,ELASTIC_IN:()=>I,ELASTIC_IN_OUT:()=>U,ELASTIC_OUT:()=>L,LINEAR:()=>l,tween:()=>b});var i=Math.PI/2,b=(t,e,r,a=1,s=l)=>new u(t,e,r,a,s),l=t=>t,h=t=>t*t,_=t=>-t*(t-2),d=t=>t<.5?2*t*t:-2*t*t+4*t-1,D=t=>t*t*t-t*Math.sin(t*Math.PI),E=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},g=t=>{if(t<.5){let r=2*t;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},I=t=>Math.sin(13*i*t)*Math.pow(2,10*(t-1)),L=t=>Math.sin(-13*i*(t+1))*Math.pow(2,-10*t)+1,U=t=>{if(t<.5){let a=Math.sin(13*i*(2*t)),s=Math.pow(2,10*(2*t-1));return .5*a*s}let e=Math.sin(-13*i*(2*t-1+1)),r=Math.pow(2,-10*(2*t-1));return .5*(e*r+2)},p=t=>1-m(1-t),m=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*p(t*2):.5*m(t*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(e,r,a,s,n){this._o=e,this._p=r,this._x=a,this._d=s,this._e=n,this._w=0}start(e){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,a=this._rel?r+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",s=>{if(this._t<=this._w){this._t+=s;return}let n=this._t-this._w;this._o[this._p]=this._lc.lerp(r,a,this._e(n/this._d)),this._t+=s,n>=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 r of this._cb)r(this._o);return this}restart(e=null,r=!1){return this.stop(r).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||{},o);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.27.0",
3
+ "version": "0.28.1",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
package/src/_global.js CHANGED
@@ -1,8 +1,10 @@
1
1
  globalThis.utils = globalThis.utils || {}
2
2
 
3
- globalThis.utils.global = () => {
3
+ globalThis.utils.global = (overrides = true) => {
4
4
  for (const key in globalThis.utils) {
5
5
  if ("global" === key) continue
6
- globalThis[key] = globalThis.utils[key]
6
+ if (overrides || globalThis[key] === undefined) {
7
+ globalThis[key] = globalThis.utils[key]
8
+ }
7
9
  }
8
10
  }
package/src/math/index.js CHANGED
@@ -4,6 +4,6 @@ export { default as fract } from "./fract.js"
4
4
  export { default as range } from "./range.js"
5
5
  export { default as advance } from "./advance.js"
6
6
  export { default as mod } from "./mod.js"
7
- export { default as round } from "./round.js"
7
+ export { default as roundd } from "./roundd.js"
8
8
  export { default as dist } from "./dist.js"
9
9
  export { default as mag } from "./mag.js"
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Calculates the integer closest to a number and optional precision.
3
+ *
4
+ * @param {number} n number to round.
5
+ * @param {number} [precision] number of decimal digits to round to, default is 0.
6
+ * @returns {number} rounded number.
7
+ */
8
+ export default (n, precision = 0) => {
9
+ if (!precision) {
10
+ return Math.round(n)
11
+ }
12
+ const multiplier = Math.pow(10, precision)
13
+ return Math.round(n * multiplier) / multiplier
14
+ }
package/src/math/round.js DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * Calculates the integer closest to a number.
3
- *
4
- * @param {number} n number to round.
5
- * @param {number} [decimals] number of decimal places to round to, default is 0.
6
- * @returns {number} rounded number.
7
- */
8
- export default (n, decimals) => {
9
- if (!decimals) {
10
- return Math.round(n)
11
- }
12
- const multiplier = Math.pow(10, decimals)
13
- return Math.round(n * multiplier) / multiplier
14
- }