@litecanvas/utils 0.39.0 → 0.40.0

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/all.js CHANGED
@@ -320,7 +320,7 @@
320
320
  resolveY = y2 + h2;
321
321
  }
322
322
  }
323
- return { direction, x: resolveX, y: resolveY };
323
+ return { dir: direction, x: resolveX, y: resolveY };
324
324
  };
325
325
 
326
326
  // src/debug/assert.js
@@ -490,7 +490,7 @@
490
490
  * @param {number} y
491
491
  * @param {any} value
492
492
  * @param {Grid} grid
493
- * @returns {boolean?} returns `false` to stop/break the loop
493
+ * @returns {false|void} returns `false` to stop/break the loop
494
494
  *
495
495
  * @param {GridForEachCallback} callback
496
496
  * @param {boolean} [reverse=false]
@@ -941,6 +941,7 @@
941
941
 
942
942
  // src/math/sum.js
943
943
  var sum_default = (values) => {
944
+ DEV: assert_default(Array.isArray(values), "1st param must be an array");
944
945
  let result = 0;
945
946
  for (let i = 0; i < values.length; i++) {
946
947
  result += values[i];
@@ -950,11 +951,13 @@
950
951
 
951
952
  // src/math/mean.js
952
953
  var mean_default = (values) => {
954
+ DEV: assert_default(Array.isArray(values), "1st param must be an array");
953
955
  return sum_default(values) / values.length;
954
956
  };
955
957
 
956
958
  // src/math/median.js
957
- var median_default = (...values) => {
959
+ var median_default = (values) => {
960
+ DEV: assert_default(Array.isArray(values), "1st param must be an array");
958
961
  const sorted = values.sort((a, b) => a - b);
959
962
  const middle = Math.floor(sorted.length / 2);
960
963
  if (sorted.length % 2 === 0) {
package/dist/all.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var bt=Object.defineProperty;var Pt=(e,t)=>{for(var s in t)bt(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 Z={};Pt(Z,{ANCHOR_BOT_LEFT:()=>vt,ANCHOR_BOT_RIGHT:()=>te,ANCHOR_CENTER:()=>Jt,ANCHOR_TOP_LEFT:()=>v,ANCHOR_TOP_RIGHT:()=>Qt,Actor:()=>O,BACK_IN:()=>oe,BACK_IN_OUT:()=>ae,BACK_OUT:()=>he,BOUNCE_IN:()=>pt,BOUNCE_IN_OUT:()=>pe,BOUNCE_OUT:()=>C,Camera:()=>y,DOWN:()=>$t,EASE_IN:()=>se,EASE_IN_OUT:()=>ie,EASE_OUT:()=>re,ELASTIC_IN:()=>ne,ELASTIC_IN_OUT:()=>le,ELASTIC_OUT:()=>ce,Grid:()=>w,LEFT:()=>Gt,LINEAR:()=>lt,Noise:()=>Y,ONE:()=>qt,RIGHT:()=>Kt,TypedGrid:()=>T,UP:()=>zt,Vector:()=>I,ZERO:()=>Q,advance:()=>st,choose:()=>yt,colcirc:()=>X,colrect:()=>W,diff:()=>tt,dist:()=>it,flipImage:()=>ut,formatTime:()=>wt,fract:()=>et,head:()=>It,intersection:()=>M,last:()=>Et,lerpAngle:()=>nt,mag:()=>ot,makeCircle:()=>xt,makeRectangle:()=>dt,mean:()=>ht,median:()=>at,mod:()=>rt,percent:()=>ct,range:()=>mt,resolverect:()=>H,scaleImage:()=>ft,shuffle:()=>gt,sum:()=>P,tail:()=>Mt,tintImage:()=>_t,tween:()=>ee,vec:()=>h,vecAbs:()=>Bt,vecAdd:()=>N,vecAngle:()=>St,vecAngleBetween:()=>Ot,vecCeil:()=>Yt,vecClamp:()=>Ht,vecCross:()=>Ft,vecDist:()=>Lt,vecDist2:()=>kt,vecDiv:()=>L,vecDot:()=>J,vecEq:()=>S,vecFloor:()=>Zt,vecHeading:()=>G,vecIsZero:()=>Dt,vecLerp:()=>Ct,vecLimit:()=>At,vecMag:()=>K,vecMag2:()=>$,vecMove:()=>Xt,vecMult:()=>b,vecNorm:()=>k,vecRand:()=>jt,vecReflect:()=>Nt,vecRem:()=>Wt,vecRotate:()=>Tt,vecRound:()=>Ut,vecSet:()=>q,vecSetMag:()=>z,vecSub:()=>A,vecToArray:()=>Vt});var y=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;constructor(t=null,s=0,r=0,i=null,o=null){this._engine=t||globalThis,this.ox=s,this.oy=r,this.resize(i||this._engine.W-s,o||this._engine.H-r),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.clip(i=>{i.rect(this.ox,this.oy,this.width,this.height)});let s=this.ox+this.width/2,r=this.oy+this.height/2;this._engine.translate(s,r),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,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,r.x=i*t-o*s+this.x,r.y=o*t+i*s+this.y,r}getCameraPoint(t,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=i*t-o*s,s=o*t+i*s,r.x=t*this.scale+this.width/2+this.ox,r.y=s*this.scale+this.height/2+this.oy,r}getBounds(){return[this.ox,this.oy,this.width,this.height]}shake(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",r=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),s-=r,s<=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 M=(e,t,s,r,i,o,a,n)=>{let c=Math.max(e,i),x=Math.min(e+s,i+a)-c,p=Math.max(t,o),d=Math.min(t+r,o+n)-p;return[c,p,x,d]};var H=(e,t,s,r,i,o,a,n)=>{let[c,x,p,d]=M(e,t,s,r,i,o,a,n),_="",g=e,l=t;return p<d?e<i?(_="right",g=i-s):(_="left",g=i+a):t<o?(_="bottom",l=o-r):(_="top",l=o+n),{direction:_,x:g,y:l}};var W=(e,t,s,r,i,o,a,n)=>e<i+a&&e+s>i&&t<o+n&&t+r>o;var X=(e,t,s,r,i,o)=>(r-e)*(r-e)+(i-t)*(i-t)<=(s+o)*(s+o);var w=class e{_w;_h;_c;constructor(t,s,r=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=r}[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,s)=>this.set(t,s,void 0))}get width(){return this._w}get height(){return this._h}set(t,s,r){this._c[this.pointToIndex(t,s)]=r}get(t,s){return this._c[this.pointToIndex(t,s)]}has(t,s){return this.get(t,s)!=null}check(t,s){return t>=0&&t<this._w&&s>=0&&s<this._h}get length(){return this._w*this._h}pointToIndex(t,s){return this.clampX(~~t)+this.clampY(~~s)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,s=!1){let r=s?this.length-1:0,i=s?-1:this.length,o=s?-1:1;for(;r!==i;){let a=this.indexToPointX(r),n=this.indexToPointY(r),c=this._c[r];if(t(a,n,c,this)===!1)break;r+=o}}fill(t){this.forEach((s,r)=>{this.set(s,r,t)})}clampX(t){return D(t,0,this._w-1)}clampY(t){return D(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let r=[];return this.forEach((i,o,a)=>{r[o]=r[o]||"",r[o]+=a+t}),r.join(`
2
- `)}},T=class e extends w{constructor(t,s,r=Uint8Array){super(t,s,null),this._c=new r(this._w*this._h)}has(t,s){return this.get(t,s)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((s,r,i)=>{t.set(s,r,i)}),t}};function D(e,t,s){return e<t?t:e>s?s:e}var V=Math.cos,j=Math.sin,Rt=2*Math.PI,I=class{constructor(t=0,s=t){this.x=parseFloat(t)||0,this.y=parseFloat(s)||0}toString(){return`Vector (${this.x}, ${this.y})`}},m=e=>e instanceof I,h=(e=0,t=e)=>(m(e)&&(t=e.y,e=e.x),new I(e,t)),q=(e,t,s=t)=>(m(t)?q(e,t.x,t.y):(e.x=t,e.y=s),e),N=(e,t,s=t)=>m(t)?N(e,t.x,t.y):(e.x+=t,e.y+=s,e),A=(e,t,s=t)=>m(t)?A(e,t.x,t.y):(e.x-=t,e.y-=s,e),b=(e,t,s=t)=>m(t)?b(e,t.x,t.y):(e.x*=t,e.y*=s,e),L=(e,t,s=t)=>m(t)?L(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),Tt=(e,t)=>{let s=V(t),r=j(t);return e.x=s*e.x-r*e.y,e.y=r*e.x+s*e.y,e},Nt=(e,t)=>{let s=k(h(t));return A(e,b(s,2*J(e,s)))},z=(e,t)=>(k(e),b(e,t),e),K=e=>Math.hypot(e.x,e.y),$=e=>e.x*e.x+e.y*e.y,k=e=>{let t=K(e);return t>0&&L(e,t),e},At=(e,t=1)=>($(e)>t*t&&z(e,t),e),Lt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),kt=(e,t)=>{let s=e.x-t.x,r=e.y-t.y;return s*s+r*r},G=e=>Math.atan2(e.y,e.x),St=e=>G(e),Ot=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),J=(e,t)=>e.x*t.x+e.y*t.y,Ft=(e,t)=>e.x*t.y-e.y*t.x,Ct=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Bt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Yt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Zt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),Ut=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Ht=(e,t,s)=>(e.x<t.x&&(e.x=t.x),e.x>s.x&&(e.x=s.x),e.y<t.y&&(e.y=t.y),e.y>s.y&&(e.y=s.y),e),Wt=(e,t)=>(e.x%=t,e.y%=t,e),Xt=(e,t,s=1)=>N(e,t.x*s,t.y*s),S=(e,t,s=t)=>m(t)?S(e,t.x,t.y):e.x===t&&e.y===s,Dt=e=>S(e,Q),Vt=e=>[e.x,e.y],jt=(e=1,t=e,s=globalThis.rand||Math.random)=>{let r=s()*Rt,i=s()*(t-e)+e;return h(V(r)*i,j(r)*i)},Q=h(0,0),qt=h(1,1),zt=h(0,-1),Kt=h(1,0),$t=h(0,1),Gt=h(-1,0);var Jt=h(.5,.5),v=h(0,0),Qt=h(1,0),vt=h(0,1),te=h(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=v){this.sprite=t||{width:0,height:0},this.pos=s||h(0),this._o=h(r),this._s=h(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,s=t){this._s.x=t,this._s.y=s}scaleBy(t,s=t){this._s.x*=t,this._s.y*=s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),r=this.sprite.height*(t?this._s.y:1),i=this.pos.x-s*this.anchor.x,o=this.pos.y-r*this.anchor.y;return[i,o,s,r]}draw(t=globalThis,s=!0){s&&t.push(),this.transform(t),this.sprite.width&&this.sprite.height&&!this.hidden&&this.opacity>0&&this.drawImage(t),s&&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,s=!0){let r=this.anchor,i=-this.sprite.width*(this.flipX?1-r.x:r.x),o=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};var tt=(e,t)=>Math.abs(t-e)||0;var et=e=>e%1||0;var st=(e,t,s,r=1)=>{s&&(t.x+=s.x*r,t.y+=s.y*r),e.x+=t.x*r,e.y+=t.y*r};var rt=(e,t)=>(t+e%t)%t;var it=(e,t,s,r)=>Math.hypot(s-e,r-t);var ot=(e,t)=>Math.hypot(e,t);var P=e=>{let t=0;for(let s=0;s<e.length;s++)t+=e[s];return t};var ht=e=>P(e)/e.length;var at=(...e)=>{let t=e.sort((r,i)=>r-i),s=Math.floor(t.length/2);return t.length%2===0?(t[s-1]+t[s])/2:t[s]};var nt=(e,t,s)=>{let r=(t-e)%360;return r>180?r-=360:r<-180&&(r+=360),e+r*s};var ct=(e,t=0,s=1)=>s-t?(e-t)/(s-t):0;var R=Math.PI/2,ee=(e,t,s,r=1,i=lt)=>new F(e,t,s,r,i),lt=e=>e,se=e=>e*e,re=e=>-e*(e-2),ie=e=>e<.5?2*e*e:-2*e*e+4*e-1,oe=e=>e*e*e-e*Math.sin(e*Math.PI),he=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},ae=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},ne=e=>Math.sin(13*R*e)*Math.pow(2,10*(e-1)),ce=e=>Math.sin(-13*R*(e+1))*Math.pow(2,-10*e)+1,le=e=>{if(e<.5){let r=Math.sin(13*R*(2*e)),i=Math.pow(2,10*(2*e-1));return .5*r*i}let t=Math.sin(-13*R*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},pt=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,pe=e=>e<.5?.5*pt(e*2):.5*C(e*2-1)+.5,F=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,r,i,o){this._o=t,this._p=s,this._x=r,this._d=i,this._e=o,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",i=>{if(this._t<=this._w){this._t+=i;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,r,this._e(o/this._d)),this._t+=i,o>=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}};var B=e=>.5*(1-Math.cos(e*Math.PI)),Y=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,s=0,r=0){t<0&&(t=-t),s<0&&(s=-s),r<0&&(r=-r);let i=Math.floor(t),o=Math.floor(s),a=Math.floor(r),n=t-i,c=s-o,x=r-a,p,d,_=0,g=.5,l,u,E;for(let U=0;U<this._po;U++){let f=i+(o<<4)+(a<<8);p=B(n),d=B(c),l=this._p[f&4095],l+=p*(this._p[f+1&4095]-l),u=this._p[f+16&4095],u+=p*(this._p[f+16+1&4095]-u),l+=d*(u-l),f+=256,u=this._p[f&4095],u+=p*(this._p[f+1&4095]-u),E=this._p[f+16&4095],E+=p*(this._p[f+16+1&4095]-E),u+=d*(E-u),l+=B(x)*(u-l),_+=l*g,g*=this._pf,i<<=1,n*=2,o<<=1,c*=2,a<<=1,x*=2,n>=1&&(i++,n--),c>=1&&(o++,c--),x>=1&&(a++,x--)}return _}noiseDetail(t,s){t>0&&(this._po=t),s>0&&(this._pf=s)}noiseSeed(t=null){t!=null&&this._e.rseed(t);let s=this._e.rand||Math.random;for(let r=0;r<4096;r++)this._p[r]=s()}};var ut=(e,t=!0,s=!1,r=globalThis)=>r.paint(e.width,e.height,i=>{r.push(),r.scale(t?-1:1,s?-1:1),r.image(t?-e.width:0,s?-e.height:0,e),r.pop()});var ft=(e,t,s=!0,r=globalThis)=>r.paint(e.width*t,e.height*t,i=>{r.push(),i.imageSmoothingEnabled=!s,r.scale(t),r.image(0,0,e),r.pop()});var _t=(e,t,s=1,r=globalThis)=>r.paint(e.width,e.height,i=>{r.push(),r.alpha(s),r.rectfill(0,0,e.width,e.height,t),i.globalCompositeOperation="destination-atop",r.alpha(1),r.image(0,0,e),r.pop()});var xt=(e,t,{borderWidth:s=0,borderColor:r=0,engine:i=globalThis}={})=>{let o=e*2+s;return i.paint(o,o,()=>{i.circfill(o/2,o/2,e,t),s>0&&(i.linewidth(s),i.stroke(r))})};var dt=(e,t,s,{borderWidth:r=0,borderColor:i=0,engine:o=globalThis}={})=>{let a=e+r*2,n=t+r*2;return o.paint(a,n,()=>{let c=r>0;c&&o.cls(i),o.rectfill(c?r:0,c?r:0,e,t,s)})};var mt=(e,t=0,s=1)=>[...new Array(e).keys()].map(r=>t+s*r);var gt=(e,t=globalThis.rand||Math.random)=>{e=[...e];for(let s=e.length-1;s>0;s--){let r=Math.floor(t()*(s+1)),i=e[s];e[s]=e[r],e[r]=i}return e};var yt=(e,t=globalThis.rand||Math.random)=>e[Math.floor(t()*e.length)];var It=e=>e[0];var Et=e=>e[e.length-1];var Mt=e=>e.slice(1);var wt=e=>~~(e/60)+":"+(e%60<10?"0":"")+~~(e%60);globalThis.utils=Object.assign(globalThis.utils||{},Z);})();
1
+ (()=>{var bt=Object.defineProperty;var Pt=(s,t)=>{for(var e in t)bt(s,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(s=!0)=>{for(let t in globalThis.utils)t!=="global"&&(s||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var Z={};Pt(Z,{ANCHOR_BOT_LEFT:()=>vt,ANCHOR_BOT_RIGHT:()=>ts,ANCHOR_CENTER:()=>Jt,ANCHOR_TOP_LEFT:()=>v,ANCHOR_TOP_RIGHT:()=>Qt,Actor:()=>O,BACK_IN:()=>os,BACK_IN_OUT:()=>as,BACK_OUT:()=>hs,BOUNCE_IN:()=>pt,BOUNCE_IN_OUT:()=>ps,BOUNCE_OUT:()=>C,Camera:()=>g,DOWN:()=>$t,EASE_IN:()=>es,EASE_IN_OUT:()=>is,EASE_OUT:()=>rs,ELASTIC_IN:()=>ns,ELASTIC_IN_OUT:()=>cs,ELASTIC_OUT:()=>ls,Grid:()=>w,LEFT:()=>Gt,LINEAR:()=>ct,Noise:()=>Y,ONE:()=>qt,RIGHT:()=>Kt,TypedGrid:()=>T,UP:()=>zt,Vector:()=>I,ZERO:()=>Q,advance:()=>et,choose:()=>gt,colcirc:()=>X,colrect:()=>W,diff:()=>tt,dist:()=>it,flipImage:()=>ut,formatTime:()=>wt,fract:()=>st,head:()=>It,intersection:()=>M,last:()=>Et,lerpAngle:()=>nt,mag:()=>ot,makeCircle:()=>xt,makeRectangle:()=>mt,mean:()=>ht,median:()=>at,mod:()=>rt,percent:()=>lt,range:()=>dt,resolverect:()=>H,scaleImage:()=>ft,shuffle:()=>yt,sum:()=>P,tail:()=>Mt,tintImage:()=>_t,tween:()=>ss,vec:()=>h,vecAbs:()=>Bt,vecAdd:()=>A,vecAngle:()=>St,vecAngleBetween:()=>Ot,vecCeil:()=>Yt,vecClamp:()=>Ht,vecCross:()=>Ft,vecDist:()=>Lt,vecDist2:()=>kt,vecDiv:()=>L,vecDot:()=>J,vecEq:()=>S,vecFloor:()=>Zt,vecHeading:()=>G,vecIsZero:()=>Dt,vecLerp:()=>Ct,vecLimit:()=>Nt,vecMag:()=>K,vecMag2:()=>$,vecMove:()=>Xt,vecMult:()=>b,vecNorm:()=>k,vecRand:()=>jt,vecReflect:()=>At,vecRem:()=>Wt,vecRotate:()=>Tt,vecRound:()=>Ut,vecSet:()=>q,vecSetMag:()=>z,vecSub:()=>N,vecToArray:()=>Vt});var g=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;constructor(t=null,e=0,r=0,i=null,o=null){this._engine=t||globalThis,this.ox=e,this.oy=r,this.resize(i||this._engine.W-e,o||this._engine.H-r),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}resize(t,e){this.width=t,this.height=e,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.clip(i=>{i.rect(this.ox,this.oy,this.width,this.height)});let e=this.ox+this.width/2,r=this.oy+this.height/2;this._engine.translate(e,r),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,e){this.x=t,this.y=e}move(t,e){this.x+=t,this.y+=e}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,e,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,e=(e-this.height/2-this.oy)/this.scale,r.x=i*t-o*e+this.x,r.y=o*t+i*e+this.y,r}getCameraPoint(t,e,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,e=e-this.y,t=i*t-o*e,e=o*t+i*e,r.x=t*this.scale+this.width/2+this.ox,r.y=e*this.scale+this.height/2+this.oy,r}getBounds(){return[this.ox,this.oy,this.width,this.height]}shake(t=1,e=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",r=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),e-=r,e<=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 M=(s,t,e,r,i,o,a,n)=>{let l=Math.max(s,i),x=Math.min(s+e,i+a)-l,p=Math.max(t,o),m=Math.min(t+r,o+n)-p;return[l,p,x,m]};var H=(s,t,e,r,i,o,a,n)=>{let[l,x,p,m]=M(s,t,e,r,i,o,a,n),_="",y=s,c=t;return p<m?s<i?(_="right",y=i-e):(_="left",y=i+a):t<o?(_="bottom",c=o-r):(_="top",c=o+n),{dir:_,x:y,y:c}};var W=(s,t,e,r,i,o,a,n)=>s<i+a&&s+e>i&&t<o+n&&t+r>o;var X=(s,t,e,r,i,o)=>(r-s)*(r-s)+(i-t)*(i-t)<=(e+o)*(e+o);var w=class s{_w;_h;_c;constructor(t,e,r=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~e),this._c=r}[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 s(this._w,this._h,this._c)}clear(){this.forEach((t,e)=>this.set(t,e,void 0))}get width(){return this._w}get height(){return this._h}set(t,e,r){this._c[this.pointToIndex(t,e)]=r}get(t,e){return this._c[this.pointToIndex(t,e)]}has(t,e){return this.get(t,e)!=null}check(t,e){return t>=0&&t<this._w&&e>=0&&e<this._h}get length(){return this._w*this._h}pointToIndex(t,e){return this.clampX(~~t)+this.clampY(~~e)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,e=!1){let r=e?this.length-1:0,i=e?-1:this.length,o=e?-1:1;for(;r!==i;){let a=this.indexToPointX(r),n=this.indexToPointY(r),l=this._c[r];if(t(a,n,l,this)===!1)break;r+=o}}fill(t){this.forEach((e,r)=>{this.set(e,r,t)})}clampX(t){return D(t,0,this._w-1)}clampY(t){return D(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",e=!0){if(!e)return this._c.join(t);let r=[];return this.forEach((i,o,a)=>{r[o]=r[o]||"",r[o]+=a+t}),r.join(`
2
+ `)}},T=class s extends w{constructor(t,e,r=Uint8Array){super(t,e,null),this._c=new r(this._w*this._h)}has(t,e){return this.get(t,e)!==0}clone(){let t=new s(this._w,this._h,this._c.constructor);return this.forEach((e,r,i)=>{t.set(e,r,i)}),t}};function D(s,t,e){return s<t?t:s>e?e:s}var V=Math.cos,j=Math.sin,Rt=2*Math.PI,I=class{constructor(t=0,e=t){this.x=parseFloat(t)||0,this.y=parseFloat(e)||0}toString(){return`Vector (${this.x}, ${this.y})`}},d=s=>s instanceof I,h=(s=0,t=s)=>(d(s)&&(t=s.y,s=s.x),new I(s,t)),q=(s,t,e=t)=>(d(t)?q(s,t.x,t.y):(s.x=t,s.y=e),s),A=(s,t,e=t)=>d(t)?A(s,t.x,t.y):(s.x+=t,s.y+=e,s),N=(s,t,e=t)=>d(t)?N(s,t.x,t.y):(s.x-=t,s.y-=e,s),b=(s,t,e=t)=>d(t)?b(s,t.x,t.y):(s.x*=t,s.y*=e,s),L=(s,t,e=t)=>d(t)?L(s,t.x,t.y):(s.x/=t||1,s.y/=e||1,s),Tt=(s,t)=>{let e=V(t),r=j(t);return s.x=e*s.x-r*s.y,s.y=r*s.x+e*s.y,s},At=(s,t)=>{let e=k(h(t));return N(s,b(e,2*J(s,e)))},z=(s,t)=>(k(s),b(s,t),s),K=s=>Math.hypot(s.x,s.y),$=s=>s.x*s.x+s.y*s.y,k=s=>{let t=K(s);return t>0&&L(s,t),s},Nt=(s,t=1)=>($(s)>t*t&&z(s,t),s),Lt=(s,t)=>Math.hypot(t.x-s.x,t.y-s.y),kt=(s,t)=>{let e=s.x-t.x,r=s.y-t.y;return e*e+r*r},G=s=>Math.atan2(s.y,s.x),St=s=>G(s),Ot=(s,t)=>Math.atan2(t.y-s.y,t.x-s.x),J=(s,t)=>s.x*t.x+s.y*t.y,Ft=(s,t)=>s.x*t.y-s.y*t.x,Ct=(s,t,e)=>(s.x+=(t.x-s.x)*e||0,s.y+=(t.y-s.y)*e||0,s),Bt=s=>(s.x=Math.abs(s.x),s.y=Math.abs(s.y),s),Yt=s=>(s.x=Math.ceil(s.x),s.y=Math.ceil(s.y),s),Zt=s=>(s.x=Math.floor(s.x),s.y=Math.floor(s.y),s),Ut=s=>(s.x=Math.round(s.x),s.y=Math.round(s.y),s),Ht=(s,t,e)=>(s.x<t.x&&(s.x=t.x),s.x>e.x&&(s.x=e.x),s.y<t.y&&(s.y=t.y),s.y>e.y&&(s.y=e.y),s),Wt=(s,t)=>(s.x%=t,s.y%=t,s),Xt=(s,t,e=1)=>A(s,t.x*e,t.y*e),S=(s,t,e=t)=>d(t)?S(s,t.x,t.y):s.x===t&&s.y===e,Dt=s=>S(s,Q),Vt=s=>[s.x,s.y],jt=(s=1,t=s,e=globalThis.rand||Math.random)=>{let r=e()*Rt,i=e()*(t-s)+s;return h(V(r)*i,j(r)*i)},Q=h(0,0),qt=h(1,1),zt=h(0,-1),Kt=h(1,0),$t=h(0,1),Gt=h(-1,0);var Jt=h(.5,.5),v=h(0,0),Qt=h(1,0),vt=h(0,1),ts=h(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,r=v){this.sprite=t||{width:0,height:0},this.pos=e||h(0),this._o=h(r),this._s=h(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),r=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,o=this.pos.y-r*this.anchor.y;return[i,o,e,r]}draw(t=globalThis,e=!0){e&&t.push(),this.transform(t),this.sprite.width&&this.sprite.height&&!this.hidden&&this.opacity>0&&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 r=this.anchor,i=-this.sprite.width*(this.flipX?1-r.x:r.x),o=-this.sprite.height*(this.flipY?1-r.y:r.y);e&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};var tt=(s,t)=>Math.abs(t-s)||0;var st=s=>s%1||0;var et=(s,t,e,r=1)=>{e&&(t.x+=e.x*r,t.y+=e.y*r),s.x+=t.x*r,s.y+=t.y*r};var rt=(s,t)=>(t+s%t)%t;var it=(s,t,e,r)=>Math.hypot(e-s,r-t);var ot=(s,t)=>Math.hypot(s,t);var P=s=>{let t=0;for(let e=0;e<s.length;e++)t+=s[e];return t};var ht=s=>P(s)/s.length;var at=s=>{let t=s.sort((r,i)=>r-i),e=Math.floor(t.length/2);return t.length%2===0?(t[e-1]+t[e])/2:t[e]};var nt=(s,t,e)=>{let r=(t-s)%360;return r>180?r-=360:r<-180&&(r+=360),s+r*e};var lt=(s,t=0,e=1)=>e-t?(s-t)/(e-t):0;var R=Math.PI/2,ss=(s,t,e,r=1,i=ct)=>new F(s,t,e,r,i),ct=s=>s,es=s=>s*s,rs=s=>-s*(s-2),is=s=>s<.5?2*s*s:-2*s*s+4*s-1,os=s=>s*s*s-s*Math.sin(s*Math.PI),hs=s=>{let t=1-s;return 1-(t*t*t-t*Math.sin(t*Math.PI))},as=s=>{if(s<.5){let e=2*s;return .5*(e*e*e-e*Math.sin(e*Math.PI))}let t=1-(2*s-1);return .5*(1-(t*t*t-t*Math.sin(s*Math.PI)))+.5},ns=s=>Math.sin(13*R*s)*Math.pow(2,10*(s-1)),ls=s=>Math.sin(-13*R*(s+1))*Math.pow(2,-10*s)+1,cs=s=>{if(s<.5){let r=Math.sin(13*R*(2*s)),i=Math.pow(2,10*(2*s-1));return .5*r*i}let t=Math.sin(-13*R*(2*s-1+1)),e=Math.pow(2,-10*(2*s-1));return .5*(t*e+2)},pt=s=>1-C(1-s),C=s=>s<4/11?121*s*s/16:s<8/11?363/40*s*s-99/10*s+17/5:s<9/10?4356/361*s*s-35442/1805*s+16061/1805:54/5*s*s-513/25*s+268/25,ps=s=>s<.5?.5*pt(s*2):.5*C(s*2-1)+.5,F=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,e,r,i,o){this._o=t,this._p=e,this._x=r,this._d=i,this._e=o,this._w=0}start(t){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let e=this._o[this._p]||0,r=this._rel?e+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",i=>{if(this._t<=this._w){this._t+=i;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(e,r,this._e(o/this._d)),this._t+=i,o>=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 e of this._cb)e(this._o);return this}restart(t=null,e=!1){return this.stop(e).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 B=s=>.5*(1-Math.cos(s*Math.PI)),Y=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,e=0,r=0){t<0&&(t=-t),e<0&&(e=-e),r<0&&(r=-r);let i=Math.floor(t),o=Math.floor(e),a=Math.floor(r),n=t-i,l=e-o,x=r-a,p,m,_=0,y=.5,c,u,E;for(let U=0;U<this._po;U++){let f=i+(o<<4)+(a<<8);p=B(n),m=B(l),c=this._p[f&4095],c+=p*(this._p[f+1&4095]-c),u=this._p[f+16&4095],u+=p*(this._p[f+16+1&4095]-u),c+=m*(u-c),f+=256,u=this._p[f&4095],u+=p*(this._p[f+1&4095]-u),E=this._p[f+16&4095],E+=p*(this._p[f+16+1&4095]-E),u+=m*(E-u),c+=B(x)*(u-c),_+=c*y,y*=this._pf,i<<=1,n*=2,o<<=1,l*=2,a<<=1,x*=2,n>=1&&(i++,n--),l>=1&&(o++,l--),x>=1&&(a++,x--)}return _}noiseDetail(t,e){t>0&&(this._po=t),e>0&&(this._pf=e)}noiseSeed(t=null){t!=null&&this._e.rseed(t);let e=this._e.rand||Math.random;for(let r=0;r<4096;r++)this._p[r]=e()}};var ut=(s,t=!0,e=!1,r=globalThis)=>r.paint(s.width,s.height,i=>{r.push(),r.scale(t?-1:1,e?-1:1),r.image(t?-s.width:0,e?-s.height:0,s),r.pop()});var ft=(s,t,e=!0,r=globalThis)=>r.paint(s.width*t,s.height*t,i=>{r.push(),i.imageSmoothingEnabled=!e,r.scale(t),r.image(0,0,s),r.pop()});var _t=(s,t,e=1,r=globalThis)=>r.paint(s.width,s.height,i=>{r.push(),r.alpha(e),r.rectfill(0,0,s.width,s.height,t),i.globalCompositeOperation="destination-atop",r.alpha(1),r.image(0,0,s),r.pop()});var xt=(s,t,{borderWidth:e=0,borderColor:r=0,engine:i=globalThis}={})=>{let o=s*2+e;return i.paint(o,o,()=>{i.circfill(o/2,o/2,s,t),e>0&&(i.linewidth(e),i.stroke(r))})};var mt=(s,t,e,{borderWidth:r=0,borderColor:i=0,engine:o=globalThis}={})=>{let a=s+r*2,n=t+r*2;return o.paint(a,n,()=>{let l=r>0;l&&o.cls(i),o.rectfill(l?r:0,l?r:0,s,t,e)})};var dt=(s,t=0,e=1)=>[...new Array(s).keys()].map(r=>t+e*r);var yt=(s,t=globalThis.rand||Math.random)=>{s=[...s];for(let e=s.length-1;e>0;e--){let r=Math.floor(t()*(e+1)),i=s[e];s[e]=s[r],s[r]=i}return s};var gt=(s,t=globalThis.rand||Math.random)=>s[Math.floor(t()*s.length)];var It=s=>s[0];var Et=s=>s[s.length-1];var Mt=s=>s.slice(1);var wt=s=>~~(s/60)+":"+(s%60<10?"0":"")+~~(s%60);globalThis.utils=Object.assign(globalThis.utils||{},Z);})();
3
3
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/collision.js CHANGED
@@ -66,7 +66,7 @@
66
66
  resolveY = y2 + h2;
67
67
  }
68
68
  }
69
- return { direction, x: resolveX, y: resolveY };
69
+ return { dir: direction, x: resolveX, y: resolveY };
70
70
  };
71
71
 
72
72
  // src/debug/assert.js
@@ -1 +1 @@
1
- (()=>{var x=Object.defineProperty;var w=(e,t)=>{for(var i in t)x(e,i,{get:t[i],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 h={};w(h,{colcirc:()=>T,colrect:()=>F,intersection:()=>c,resolverect:()=>g});var c=(e,t,i,a,r,s,o,l)=>{let u=Math.max(e,r),d=Math.min(e+i,r+o)-u,n=Math.max(t,s),b=Math.min(t+a,s+l)-n;return[u,n,d,b]};var g=(e,t,i,a,r,s,o,l)=>{let[u,d,n,b]=c(e,t,i,a,r,s,o,l),m="",p=e,f=t;return n<b?e<r?(m="right",p=r-i):(m="left",p=r+o):t<s?(m="bottom",f=s-a):(m="top",f=s+l),{direction:m,x:p,y:f}};var F=(e,t,i,a,r,s,o,l)=>e<r+o&&e+i>r&&t<s+l&&t+a>s;var T=(e,t,i,a,r,s)=>(a-e)*(a-e)+(r-t)*(r-t)<=(i+s)*(i+s);globalThis.utils=Object.assign(globalThis.utils||{},h);})();
1
+ (()=>{var x=Object.defineProperty;var w=(e,t)=>{for(var i in t)x(e,i,{get:t[i],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 h={};w(h,{colcirc:()=>T,colrect:()=>F,intersection:()=>c,resolverect:()=>g});var c=(e,t,i,a,r,s,o,l)=>{let u=Math.max(e,r),d=Math.min(e+i,r+o)-u,n=Math.max(t,s),b=Math.min(t+a,s+l)-n;return[u,n,d,b]};var g=(e,t,i,a,r,s,o,l)=>{let[u,d,n,b]=c(e,t,i,a,r,s,o,l),m="",p=e,f=t;return n<b?e<r?(m="right",p=r-i):(m="left",p=r+o):t<s?(m="bottom",f=s-a):(m="top",f=s+l),{dir:m,x:p,y:f}};var F=(e,t,i,a,r,s,o,l)=>e<r+o&&e+i>r&&t<s+l&&t+a>s;var T=(e,t,i,a,r,s)=>(a-e)*(a-e)+(r-t)*(r-t)<=(i+s)*(i+s);globalThis.utils=Object.assign(globalThis.utils||{},h);})();
package/dist/grid.js CHANGED
@@ -159,7 +159,7 @@
159
159
  * @param {number} y
160
160
  * @param {any} value
161
161
  * @param {Grid} grid
162
- * @returns {boolean?} returns `false` to stop/break the loop
162
+ * @returns {false|void} returns `false` to stop/break the loop
163
163
  *
164
164
  * @param {GridForEachCallback} callback
165
165
  * @param {boolean} [reverse=false]
package/dist/math.js CHANGED
@@ -64,8 +64,14 @@
64
64
  return Math.hypot(x, y);
65
65
  };
66
66
 
67
+ // src/debug/assert.js
68
+ var assert_default = (condition, message = "Assertion failed") => {
69
+ if (!condition) throw new Error(message);
70
+ };
71
+
67
72
  // src/math/sum.js
68
73
  var sum_default = (values) => {
74
+ DEV: assert_default(Array.isArray(values), "1st param must be an array");
69
75
  let result = 0;
70
76
  for (let i = 0; i < values.length; i++) {
71
77
  result += values[i];
@@ -75,11 +81,13 @@
75
81
 
76
82
  // src/math/mean.js
77
83
  var mean_default = (values) => {
84
+ DEV: assert_default(Array.isArray(values), "1st param must be an array");
78
85
  return sum_default(values) / values.length;
79
86
  };
80
87
 
81
88
  // src/math/median.js
82
- var median_default = (...values) => {
89
+ var median_default = (values) => {
90
+ DEV: assert_default(Array.isArray(values), "1st param must be an array");
83
91
  const sorted = values.sort((a, b) => a - b);
84
92
  const middle = Math.floor(sorted.length / 2);
85
93
  if (sorted.length % 2 === 0) {
package/dist/math.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var g=Object.defineProperty;var M=(e,t)=>{for(var r in t)g(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 n={};M(n,{advance:()=>p,diff:()=>c,dist:()=>a,fract:()=>x,lerpAngle:()=>i,mag:()=>l,mean:()=>f,median:()=>y,mod:()=>u,percent:()=>h,sum:()=>s});var c=(e,t)=>Math.abs(t-e)||0;var x=e=>e%1||0;var R=2*Math.PI;var p=(e,t,r,o=1)=>{r&&(t.x+=r.x*o,t.y+=r.y*o),e.x+=t.x*o,e.y+=t.y*o};var u=(e,t)=>(t+e%t)%t;var a=(e,t,r,o)=>Math.hypot(r-e,o-t);var l=(e,t)=>Math.hypot(e,t);var s=e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t};var f=e=>s(e)/e.length;var y=(...e)=>{let t=e.sort((o,d)=>o-d),r=Math.floor(t.length/2);return t.length%2===0?(t[r-1]+t[r])/2:t[r]};var i=(e,t,r)=>{let o=(t-e)%360;return o>180?o-=360:o<-180&&(o+=360),e+o*r};var h=(e,t=0,r=1)=>r-t?(e-t)/(r-t):0;globalThis.utils=Object.assign(globalThis.utils||{},n);})();
1
+ (()=>{var m=Object.defineProperty;var g=(r,t)=>{for(var e in t)m(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 n={};g(n,{advance:()=>x,diff:()=>a,dist:()=>u,fract:()=>c,lerpAngle:()=>i,mag:()=>l,mean:()=>f,median:()=>y,mod:()=>p,percent:()=>h,sum:()=>s});var a=(r,t)=>Math.abs(t-r)||0;var c=r=>r%1||0;var T=2*Math.PI;var x=(r,t,e,o=1)=>{e&&(t.x+=e.x*o,t.y+=e.y*o),r.x+=t.x*o,r.y+=t.y*o};var p=(r,t)=>(t+r%t)%t;var u=(r,t,e,o)=>Math.hypot(e-r,o-t);var l=(r,t)=>Math.hypot(r,t);var s=r=>{let t=0;for(let e=0;e<r.length;e++)t+=r[e];return t};var f=r=>s(r)/r.length;var y=r=>{let t=r.sort((o,d)=>o-d),e=Math.floor(t.length/2);return t.length%2===0?(t[e-1]+t[e])/2:t[e]};var i=(r,t,e)=>{let o=(t-r)%360;return o>180?o-=360:o<-180&&(o+=360),r+o*e};var h=(r,t=0,e=1)=>e-t?(r-t)/(e-t):0;globalThis.utils=Object.assign(globalThis.utils||{},n);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.39.0",
3
+ "version": "0.40.0",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "litecanvas": "latest"
38
38
  },
39
39
  "devDependencies": {
40
- "esbuild": "^0.25.8",
40
+ "esbuild": "^0.25.9",
41
41
  "gzip-size": "^7.0.0",
42
42
  "prettier": "^3.6.2"
43
43
  }
@@ -12,7 +12,7 @@ import intersection from "./intersection.js"
12
12
  * @param {number} y2
13
13
  * @param {number} w2
14
14
  * @param {number} h2
15
- * @returns {{direction: string, x: number, y: number}} An object containing the direction of the collision and the new position (X and Y) of the first rectangle.
15
+ * @returns {{dir: string, x: number, y: number}} An object containing the direction of the collision and the new position (X and Y) of the first rectangle.
16
16
  */
17
17
  export default (x1, y1, w1, h1, x2, y2, w2, h2) => {
18
18
  // get the intersection area
@@ -49,5 +49,5 @@ export default (x1, y1, w1, h1, x2, y2, w2, h2) => {
49
49
  }
50
50
  }
51
51
 
52
- return { direction, x: resolveX, y: resolveY }
52
+ return { dir: direction, x: resolveX, y: resolveY }
53
53
  }
package/src/grid/index.js CHANGED
@@ -152,7 +152,7 @@ export class Grid {
152
152
  * @param {number} y
153
153
  * @param {any} value
154
154
  * @param {Grid} grid
155
- * @returns {boolean?} returns `false` to stop/break the loop
155
+ * @returns {false|void} returns `false` to stop/break the loop
156
156
  *
157
157
  * @param {GridForEachCallback} callback
158
158
  * @param {boolean} [reverse=false]
@@ -6,8 +6,8 @@ import { Vector } from "../vector/index.js"
6
6
  *
7
7
  * @param {Vector} position
8
8
  * @param {Vector} velocity
9
- * @param {Vector?} [acceleration]
10
- * @param {number?} [deltaTime]
9
+ * @param {Vector} [acceleration]
10
+ * @param {number} [deltaTime]
11
11
  */
12
12
  export default (position, velocity, acceleration, deltaTime = 1) => {
13
13
  if (acceleration) {
package/src/math/mean.js CHANGED
@@ -1,3 +1,4 @@
1
+ import assert from "../debug/assert.js"
1
2
  import sum from "./sum.js"
2
3
 
3
4
  /**
@@ -7,5 +8,6 @@ import sum from "./sum.js"
7
8
  * @returns {number}
8
9
  */
9
10
  export default (values) => {
11
+ DEV: assert(Array.isArray(values), "1st param must be an array")
10
12
  return sum(values) / values.length
11
13
  }
@@ -1,3 +1,5 @@
1
+ import assert from "../debug/assert"
2
+
1
3
  /**
2
4
  * Compute the median of the values. The values are sorted and the middle value is returned.
3
5
  * In case of an even number of values, the average of the two middle values is returned
@@ -5,7 +7,8 @@
5
7
  * @param {number[]} values
6
8
  * @returns {number}
7
9
  */
8
- export default (...values) => {
10
+ export default (values) => {
11
+ DEV: assert(Array.isArray(values), "1st param must be an array")
9
12
  const sorted = values.sort((a, b) => a - b)
10
13
  const middle = Math.floor(sorted.length / 2)
11
14
 
package/src/math/sum.js CHANGED
@@ -1,10 +1,15 @@
1
+ import assert from "../debug/assert"
2
+
1
3
  /**
2
4
  * Computes the sum of the values in a array.
3
5
  *
6
+ * usage: `sum([2,3,5]) // returns 10`
7
+ *
4
8
  * @param {number[]} values list of numbers
5
9
  * @returns {number}
6
10
  */
7
11
  export default (values) => {
12
+ DEV: assert(Array.isArray(values), "1st param must be an array")
8
13
  let result = 0
9
14
  for (let i = 0; i < values.length; i++) {
10
15
  result += values[i]