@litecanvas/utils 0.17.0 → 0.17.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/all.js CHANGED
@@ -344,7 +344,7 @@
344
344
  next: () => {
345
345
  return {
346
346
  value: [this.indexToPointX(i), this.indexToPointY(i), this._c[i++]],
347
- done: i === this._c.length
347
+ done: i > this._c.length
348
348
  };
349
349
  }
350
350
  };
package/dist/all.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var J=Object.defineProperty;var Q=(e,t)=>{for(var s in t)J(e,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var D={};Q(D,{ANCHOR_BOT_LEFT:()=>bt,ANCHOR_BOT_RIGHT:()=>At,ANCHOR_CENTER:()=>Mt,ANCHOR_TOP_LEFT:()=>G,ANCHOR_TOP_RIGHT:()=>It,Actor:()=>C,BACK_IN:()=>kt,BACK_IN_OUT:()=>Pt,BACK_OUT:()=>Dt,BOUNCE_IN:()=>Z,BOUNCE_IN_OUT:()=>Yt,BOUNCE_OUT:()=>k,Camera:()=>u,DOWN:()=>wt,EASE_IN:()=>Ot,EASE_IN_OUT:()=>St,EASE_OUT:()=>Ct,ELASTIC_IN:()=>Lt,ELASTIC_IN_OUT:()=>Rt,ELASTIC_OUT:()=>Xt,Grid:()=>g,LEFT:()=>Et,LINEAR:()=>K,ONE:()=>yt,RIGHT:()=>Tt,TypedGrid:()=>M,UP:()=>mt,Vector:()=>p,ZERO:()=>F,advance:()=>q,diff:()=>V,fract:()=>z,intersection:()=>d,range:()=>$,resolve:()=>L,tween:()=>Ht,vec:()=>n,vecAbs:()=>ft,vecAdd:()=>A,vecAngle:()=>nt,vecAngleBetween:()=>ht,vecCeil:()=>ut,vecClamp:()=>xt,vecCross:()=>at,vecDist:()=>rt,vecDist2:()=>ot,vecDiv:()=>y,vecDot:()=>N,vecEq:()=>b,vecFloor:()=>pt,vecIsZero:()=>gt,vecLerp:()=>ct,vecLimit:()=>it,vecMag:()=>U,vecMag2:()=>W,vecMove:()=>dt,vecMult:()=>_,vecNorm:()=>O,vecRand:()=>lt,vecReflect:()=>et,vecRotate:()=>tt,vecRound:()=>_t,vecSet:()=>B,vecSetMag:()=>st,vecSub:()=>H,wave:()=>j});var d=(e,t,s,i,r,o,h,a)=>{let c=Math.max(e,r),P=Math.min(e+s,r+h)-c,x=Math.max(t,o),T=Math.min(t+i,o+a)-x;return[c,x,P,T]};var L=(e,t,s,i,r,o,h,a)=>{let[c,P,x,T]=d(e,t,s,i,r,o,h,a),f="",w=e,E=t;return x<T?e<r?(f="right",w=r-s):(f="left",w=r+h):t<o?(f="bottom",E=o-i):(f="top",E=o+a),{direction:f,x:w,y:E}};var u=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,s=0,i=0,r=null,o=null){this._engine=t||globalThis,this.ox=s,this.oy=i,this.resize(r||this._engine.WIDTH-s,o||this._engine.HEIGHT-i),this.x=this.width/2,this.y=this.height/2}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.cliprect(this.ox,this.oy,this.width,this.height);let s=this.ox+this.width/2,i=this.oy+this.height/2;this._engine.translate(s,i),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,i={}){let r=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,i.x=r*t-o*s+this.x,i.y=o*t+r*s+this.y,i}getCameraPoint(t,s,i={}){let r=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=r*t-o*s,s=o*t+r*s,i.x=t*this.scale+this.width/2+this.ox,i.y=s*this.scale+this.height/2+this.oy,i}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,s,i,r){let o=this.width/2-this.x,h=this.height/2-this.y,a=this.width/this.scale,c=this.height/this.scale;return this._engine.colrect(t,s,i,r,o,h,a,c)}shake(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",i=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),s-=i,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 g=class e{_w;_h;_c;constructor(t,s,i=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=i}[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,i){this._c[this.pointToIndex(t,s)]=i}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 i=s?this.length-1:0,r=s?-1:this.length,o=s?-1:1;for(;i!==r;){let h=this.indexToPointX(i),a=this.indexToPointY(i),c=this._c[i];if(t(h,a,c,this)===!1)break;i+=o}}fill(t){this.forEach((s,i)=>{this.set(s,i,t)})}clampX(t){return X(t,0,this._w-1)}clampY(t){return X(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let i=[];return this.forEach((r,o,h)=>{i[o]=i[o]||"",i[o]+=h+t}),i.join(`
1
+ (()=>{var J=Object.defineProperty;var Q=(e,t)=>{for(var s in t)J(e,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var D={};Q(D,{ANCHOR_BOT_LEFT:()=>bt,ANCHOR_BOT_RIGHT:()=>At,ANCHOR_CENTER:()=>Mt,ANCHOR_TOP_LEFT:()=>G,ANCHOR_TOP_RIGHT:()=>It,Actor:()=>C,BACK_IN:()=>kt,BACK_IN_OUT:()=>Pt,BACK_OUT:()=>Dt,BOUNCE_IN:()=>Z,BOUNCE_IN_OUT:()=>Yt,BOUNCE_OUT:()=>k,Camera:()=>u,DOWN:()=>wt,EASE_IN:()=>Ot,EASE_IN_OUT:()=>St,EASE_OUT:()=>Ct,ELASTIC_IN:()=>Lt,ELASTIC_IN_OUT:()=>Rt,ELASTIC_OUT:()=>Xt,Grid:()=>g,LEFT:()=>Et,LINEAR:()=>K,ONE:()=>yt,RIGHT:()=>Tt,TypedGrid:()=>M,UP:()=>mt,Vector:()=>p,ZERO:()=>F,advance:()=>q,diff:()=>V,fract:()=>z,intersection:()=>d,range:()=>$,resolve:()=>L,tween:()=>Ht,vec:()=>n,vecAbs:()=>ft,vecAdd:()=>A,vecAngle:()=>nt,vecAngleBetween:()=>ht,vecCeil:()=>ut,vecClamp:()=>xt,vecCross:()=>at,vecDist:()=>rt,vecDist2:()=>ot,vecDiv:()=>y,vecDot:()=>N,vecEq:()=>b,vecFloor:()=>pt,vecIsZero:()=>gt,vecLerp:()=>ct,vecLimit:()=>it,vecMag:()=>U,vecMag2:()=>W,vecMove:()=>dt,vecMult:()=>_,vecNorm:()=>O,vecRand:()=>lt,vecReflect:()=>et,vecRotate:()=>tt,vecRound:()=>_t,vecSet:()=>B,vecSetMag:()=>st,vecSub:()=>H,wave:()=>j});var d=(e,t,s,i,r,o,h,a)=>{let c=Math.max(e,r),P=Math.min(e+s,r+h)-c,x=Math.max(t,o),T=Math.min(t+i,o+a)-x;return[c,x,P,T]};var L=(e,t,s,i,r,o,h,a)=>{let[c,P,x,T]=d(e,t,s,i,r,o,h,a),f="",w=e,E=t;return x<T?e<r?(f="right",w=r-s):(f="left",w=r+h):t<o?(f="bottom",E=o-i):(f="top",E=o+a),{direction:f,x:w,y:E}};var u=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,s=0,i=0,r=null,o=null){this._engine=t||globalThis,this.ox=s,this.oy=i,this.resize(r||this._engine.WIDTH-s,o||this._engine.HEIGHT-i),this.x=this.width/2,this.y=this.height/2}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.cliprect(this.ox,this.oy,this.width,this.height);let s=this.ox+this.width/2,i=this.oy+this.height/2;this._engine.translate(s,i),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,i={}){let r=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,i.x=r*t-o*s+this.x,i.y=o*t+r*s+this.y,i}getCameraPoint(t,s,i={}){let r=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=r*t-o*s,s=o*t+r*s,i.x=t*this.scale+this.width/2+this.ox,i.y=s*this.scale+this.height/2+this.oy,i}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,s,i,r){let o=this.width/2-this.x,h=this.height/2-this.y,a=this.width/this.scale,c=this.height/this.scale;return this._engine.colrect(t,s,i,r,o,h,a,c)}shake(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",i=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),s-=i,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 g=class e{_w;_h;_c;constructor(t,s,i=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=i}[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,i){this._c[this.pointToIndex(t,s)]=i}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 i=s?this.length-1:0,r=s?-1:this.length,o=s?-1:1;for(;i!==r;){let h=this.indexToPointX(i),a=this.indexToPointY(i),c=this._c[i];if(t(h,a,c,this)===!1)break;i+=o}}fill(t){this.forEach((s,i)=>{this.set(s,i,t)})}clampX(t){return X(t,0,this._w-1)}clampY(t){return X(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let i=[];return this.forEach((r,o,h)=>{i[o]=i[o]||"",i[o]+=h+t}),i.join(`
2
2
  `)}},M=class e extends g{constructor(t,s,i=Uint8Array){super(t,s,null),this._c=new i(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,i,r)=>{t.set(s,i,r)}),t}};function X(e,t,s){return e<t?t:e>s?s:e}var I=Math.sqrt,R=Math.cos,Y=Math.sin,v=2*Math.PI,p=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},l=e=>e instanceof p,n=(e=0,t=e)=>(l(e)&&(t=e.y,e=e.x),new p(e,t)),b=(e,t,s=t)=>l(t)?b(e,t.x,t.y):e.x===t&&e.y===s,B=(e,t,s=t)=>(l(t)?B(e,t.x,t.y):(e.x=t,e.y=s),e),A=(e,t,s=t)=>l(t)?A(e,t.x,t.y):(e.x+=t,e.y+=s,e),H=(e,t,s=t)=>l(t)?H(e,t.x,t.y):(e.x-=t,e.y-=s,e),_=(e,t,s=t)=>l(t)?_(e,t.x,t.y):(e.x*=t,e.y*=s,e),y=(e,t,s=t)=>l(t)?y(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),tt=(e,t)=>{let s=R(t),i=Y(t);return e.x=s*e.x-i*e.y,e.y=i*e.x+s*e.y,e},et=(e,t)=>{let s=O(n(t));return H(e,_(s,2*N(e,s)))},st=(e,t)=>(O(e),_(e,t),e),U=e=>I(e.x*e.x+e.y*e.y),W=e=>e.x*e.x+e.y*e.y,O=e=>{let t=U(e);return t>0&&y(e,t),e},it=(e,t=1)=>{let s=W(e);return s>t*t&&(y(e,I(s)),_(e,t)),e},rt=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return I(s*s+i*i)},ot=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return s*s+i*i},nt=e=>Math.atan2(e.y,e.x),ht=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),N=(e,t)=>e.x*t.x+e.y*t.y,at=(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),lt=(e=1,t=e,s=globalThis.rand||Math.random)=>{let i=s()*v,r=s()*(t-e)+e;return n(R(i)*r,Y(i)*r)},ft=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),ut=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),pt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),_t=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),xt=(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),dt=(e,t,s=1)=>A(e,t.x*s,t.y*s),gt=e=>b(e,F),F=n(0,0),yt=n(1,1),mt=n(0,-1),Tt=n(1,0),wt=n(0,1),Et=n(-1,0);globalThis.zzfxV=1;var Mt=n(.5,.5),G=n(0,0),It=n(1,0),bt=n(0,1),At=n(1,1),C=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,i=G){this.sprite=t,this.pos=s||n(0),this._o=n(i),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,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),i=this.sprite.height*(t?this._s.y:1),r=this.pos.x-s*this.anchor.x,o=this.pos.y-i*this.anchor.y;return[r,o,s,i]}draw(t=globalThis,s=!0){this.hidden||this.opacity<=0||(s&&t.push(),this.transform(t),this.drawImage(t),s&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,s=!0){let i=this.anchor,r=-this.sprite.width*(this.flipX?1-i.x:i.x),o=-this.sprite.height*(this.flipY?1-i.y:i.y);s&&t.alpha(this.opacity),t.image(r,o,this.sprite)}};var V=(e,t)=>Math.abs(t-e)||0;var j=(e,t,s,i=Math.sin)=>e+(i(s)+1)/2*(t-e);var z=e=>e%1||0;var $=e=>Array.from(Array(e).keys());var q=advance=(e,t,s,i=1)=>{s&&(t.x+=s.x*i,t.y+=s.y*i),e.x+=t.x*i,e.y+=t.y*i};var m=Math.PI/2,Ht=(e,t,s,i=1,r=K)=>new S(e,t,s,i,r),K=e=>e,Ot=e=>e*e,Ct=e=>-e*(e-2),St=e=>e<.5?2*e*e:-2*e*e+4*e-1,kt=e=>e*e*e-e*Math.sin(e*Math.PI),Dt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},Pt=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},Lt=e=>Math.sin(13*m*e)*Math.pow(2,10*(e-1)),Xt=e=>Math.sin(-13*m*(e+1))*Math.pow(2,-10*e)+1,Rt=e=>{if(e<.5){let i=Math.sin(13*m*(2*e)),r=Math.pow(2,10*(2*e-1));return .5*i*r}let t=Math.sin(-13*m*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},Z=e=>1-k(1-e),k=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,Yt=e=>e<.5?.5*Z(e*2):.5*k(e*2-1)+.5,S=class{running=!1;_o;_p;_x;_d;_e;_cb=[];_t=0;_u=0;_lc;constructor(t,s,i,r,o){this._o=t,this._p=s,this._x=i,this._d=r,this._e=o}start(t=globalThis){this.running||this.stop();let s=this._o[this._p]||0;return this._lc=t,this._u=t.listen("update",i=>{this._o[this._p]=t.lerp(s,this._x,this._e(this._t/this._d)),this._t+=i,this._t>=this._d&&(this._o[this._p]=this._x,this.stop())}),this.running=!0,this}onEnd(t){this._cb.push(t)}stop(t=!0){if(!(!this.running||!this._u)&&(this.running=!1,this._u(),t))for(let s of this._cb)s(this._o)}reset(){this._cb.length=0,this.stop()}get progress(){return this.running?this._t/this._d:0}};globalThis.utils=Object.assign(globalThis.utils||{},D);})();
3
3
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/grid.js CHANGED
@@ -42,7 +42,7 @@
42
42
  next: () => {
43
43
  return {
44
44
  value: [this.indexToPointX(i), this.indexToPointY(i), this._c[i++]],
45
- done: i === this._c.length
45
+ done: i > this._c.length
46
46
  };
47
47
  }
48
48
  };
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=()=>{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(`
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
package/src/grid/index.js CHANGED
@@ -24,7 +24,7 @@ export class Grid {
24
24
  next: () => {
25
25
  return {
26
26
  value: [this.indexToPointX(i), this.indexToPointY(i), this._c[i++]],
27
- done: i === this._c.length,
27
+ done: i > this._c.length,
28
28
  }
29
29
  },
30
30
  }