@litecanvas/utils 0.35.1 → 0.36.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/actor.js CHANGED
@@ -65,7 +65,7 @@
65
65
  var ANCHOR_BOT_LEFT = /* @__PURE__ */ vec(0, 1);
66
66
  var ANCHOR_BOT_RIGHT = /* @__PURE__ */ vec(1, 1);
67
67
  var Actor = class {
68
- /** @type {Image|HTMLCanvasElement|OffscreenCanvas} */
68
+ /** @type {CanvasImageSource} */
69
69
  sprite;
70
70
  /** @type {Vector} The actor position */
71
71
  pos;
package/dist/actor.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var c=Object.defineProperty;var p=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let e in globalThis.utils)e!=="global"&&(r||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var m={};p(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>y,ANCHOR_CENTER:()=>h,ANCHOR_TOP_LEFT:()=>l,ANCHOR_TOP_RIGHT:()=>f,Actor:()=>u});var x=2*Math.PI,n=class{x;y;constructor(e=0,t=e){this.x=e,this.y=t}toString(){return`Vector (${this.x}, ${this.y})`}},b=r=>r instanceof n,a=(r=0,e=r)=>(b(r)&&(e=r.y,r=r.x),new n(r,e));var h=a(.5,.5),l=a(0,0),f=a(1,0),d=a(0,1),y=a(1,1),u=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(e,t,s=l){this.sprite=e,this.pos=t||a(0),this._o=a(s),this._s=a(1,1)}set x(e){this.pos.x=e}get x(){return this.pos.x}set y(e){this.pos.y=e}get y(){return this.pos.y}set anchor(e){this._o.x=e.x,this._o.y=e.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(e,t=e){this._s.x=e,this._s.y=t}scaleBy(e,t=e){this._s.x*=e,this._s.y*=t}getBounds(e=!0){let t=this.sprite.width*(e?this._s.x:1),s=this.sprite.height*(e?this._s.y:1),i=this.pos.x-t*this.anchor.x,o=this.pos.y-s*this.anchor.y;return[i,o,t,s]}draw(e=globalThis,t=!0){this.hidden||this.opacity<=0||(t&&e.push(),this.transform(e),this.drawImage(e),t&&e.pop())}transform(e){e.translate(this.pos.x,this.pos.y),e.rotate(e.deg2rad(this.angle)),e.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(e,t=!0){let s=this.anchor,i=-this.sprite.width*(this.flipX?1-s.x:s.x),o=-this.sprite.height*(this.flipY?1-s.y:s.y);t&&e.alpha(this.opacity),e.image(i,o,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
1
+ (()=>{var x=Object.defineProperty;var u=(o,t)=>{for(var s in t)x(o,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let t in globalThis.utils)t!=="global"&&(o||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var p={};u(p,{ANCHOR_BOT_LEFT:()=>g,ANCHOR_BOT_RIGHT:()=>_,ANCHOR_CENTER:()=>a,ANCHOR_TOP_LEFT:()=>y,ANCHOR_TOP_RIGHT:()=>f,Actor:()=>h});var T=2*Math.PI,i=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},l=o=>o instanceof i,e=(o=0,t=o)=>(l(o)&&(t=o.y,o=o.x),new i(o,t));var a=e(.5,.5),y=e(0,0),f=e(1,0),g=e(0,1),_=e(1,1),h=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=y){this.sprite=t,this.pos=s||e(0),this._o=e(r),this._s=e(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),n=this.pos.x-s*this.anchor.x,c=this.pos.y-r*this.anchor.y;return[n,c,s,r]}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(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,n=-this.sprite.width*(this.flipX?1-r.x:r.x),c=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(n,c,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},p);})();
package/dist/all.js CHANGED
@@ -153,9 +153,9 @@
153
153
  start(clip = false) {
154
154
  this._engine.push();
155
155
  if (clip) {
156
- const region = path();
157
- region.rect(this.ox, this.oy, this.width, this.height);
158
- this._engine.clip(region);
156
+ this._engine.clip((ctx) => {
157
+ ctx.rect(this.ox, this.oy, this.width, this.height);
158
+ });
159
159
  }
160
160
  const centerX = this.ox + this.width / 2, centerY = this.oy + this.height / 2;
161
161
  this._engine.translate(centerX, centerY);
@@ -487,14 +487,14 @@
487
487
  * @param {Grid} grid
488
488
  * @returns {boolean?} returns `false` to stop/break the loop
489
489
  *
490
- * @param {GridForEachCallback} handler
490
+ * @param {GridForEachCallback} callback
491
491
  * @param {boolean} [reverse=false]
492
492
  */
493
- forEach(handler, reverse = false) {
493
+ forEach(callback, reverse = false) {
494
494
  let i = reverse ? this.length - 1 : 0, limit = reverse ? -1 : this.length, step = reverse ? -1 : 1;
495
495
  while (i !== limit) {
496
496
  const x = this.indexToPointX(i), y = this.indexToPointY(i), cellValue = this._c[i];
497
- if (false === handler(x, y, cellValue, this)) break;
497
+ if (false === callback(x, y, cellValue, this)) break;
498
498
  i += step;
499
499
  }
500
500
  }
@@ -754,7 +754,7 @@
754
754
  var ANCHOR_BOT_LEFT = /* @__PURE__ */ vec(0, 1);
755
755
  var ANCHOR_BOT_RIGHT = /* @__PURE__ */ vec(1, 1);
756
756
  var Actor = class {
757
- /** @type {Image|HTMLCanvasElement|OffscreenCanvas} */
757
+ /** @type {CanvasImageSource} */
758
758
  sprite;
759
759
  /** @type {Vector} The actor position */
760
760
  pos;
@@ -910,7 +910,7 @@
910
910
  var fract_default = (value) => value % 1 || 0;
911
911
 
912
912
  // src/math/advance.js
913
- var advance_default = advance = (position, velocity, acceleration, deltaTime = 1) => {
913
+ var advance_default = (position, velocity, acceleration, deltaTime = 1) => {
914
914
  if (acceleration) {
915
915
  velocity.x += acceleration.x * deltaTime;
916
916
  velocity.y += acceleration.y * deltaTime;
@@ -1367,17 +1367,17 @@
1367
1367
  const imageWidth = width + borderWidth * 2;
1368
1368
  const imageHeight = height + borderWidth * 2;
1369
1369
  return engine.paint(imageWidth, imageHeight, () => {
1370
+ const hasBorder = borderWidth > 0;
1371
+ if (hasBorder) {
1372
+ engine.cls(borderColor);
1373
+ }
1370
1374
  engine.rectfill(
1371
- borderWidth > 0 ? borderWidth : 0,
1372
- borderWidth > 0 ? borderWidth : 0,
1375
+ hasBorder ? borderWidth : 0,
1376
+ hasBorder ? borderWidth : 0,
1373
1377
  width,
1374
1378
  height,
1375
1379
  color
1376
1380
  );
1377
- if (borderWidth > 0) {
1378
- engine.linewidth(borderWidth);
1379
- engine.stroke(borderColor);
1380
- }
1381
1381
  });
1382
1382
  };
1383
1383
 
package/dist/all.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var Tt=Object.defineProperty;var kt=(e,t)=>{for(var s in t)Tt(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 X={};kt(X,{ANCHOR_BOT_LEFT:()=>Jt,ANCHOR_BOT_RIGHT:()=>te,ANCHOR_CENTER:()=>Kt,ANCHOR_TOP_LEFT:()=>J,ANCHOR_TOP_RIGHT:()=>Qt,Actor:()=>S,BACK_IN:()=>ie,BACK_IN_OUT:()=>ne,BACK_OUT:()=>oe,BOUNCE_IN:()=>ht,BOUNCE_IN_OUT:()=>me,BOUNCE_OUT:()=>z,Camera:()=>y,DOWN:()=>$t,EASE_IN:()=>se,EASE_IN_OUT:()=>ae,EASE_OUT:()=>re,ELASTIC_IN:()=>ue,ELASTIC_IN_OUT:()=>he,ELASTIC_OUT:()=>le,Grid:()=>k,LEFT:()=>Gt,LINEAR:()=>lt,Noise:()=>Y,ONE:()=>Vt,RIGHT:()=>Zt,TypedGrid:()=>C,UP:()=>Wt,Vector:()=>w,ZERO:()=>Q,advance:()=>st,choose:()=>yt,colcirc:()=>j,colrect:()=>U,diff:()=>tt,dist:()=>at,flipImage:()=>pt,fract:()=>et,head:()=>wt,intersection:()=>T,last:()=>Nt,lerpAngle:()=>ut,mag:()=>it,makeCircle:()=>dt,makeRectangle:()=>xt,mean:()=>ot,median:()=>nt,mod:()=>rt,range:()=>gt,resolverect:()=>B,scaleImage:()=>ft,shuffle:()=>_t,sum:()=>A,tail:()=>Mt,tintImage:()=>bt,tween:()=>ee,vec:()=>o,vecAbs:()=>Yt,vecAdd:()=>O,vecAngle:()=>vt,vecAngleBetween:()=>St,vecCeil:()=>Xt,vecClamp:()=>Ut,vecCross:()=>Rt,vecDist:()=>Ot,vecDist2:()=>Ft,vecDiv:()=>E,vecDot:()=>K,vecEq:()=>L,vecFloor:()=>Ht,vecIsZero:()=>qt,vecLerp:()=>zt,vecLimit:()=>Lt,vecMag:()=>$,vecMag2:()=>G,vecMove:()=>jt,vecMult:()=>N,vecNorm:()=>v,vecRand:()=>Dt,vecReflect:()=>Pt,vecRotate:()=>It,vecRound:()=>Bt,vecSet:()=>Z,vecSetMag:()=>Ct,vecSub:()=>F});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,a=null,i=null){this._engine=t||globalThis,this.ox=s,this.oy=r,this.resize(a||this._engine.W-s,i||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){if(this._engine.push(),t){let a=path();a.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(a)}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 a=Math.cos(-this.rotation),i=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=a*t-i*s+this.x,r.y=i*t+a*s+this.y,r}getCameraPoint(t,s,r={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=a*t-i*s,s=i*t+a*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 T=(e,t,s,r,a,i,n,u)=>{let h=Math.max(e,a),d=Math.min(e+s,a+n)-h,m=Math.max(t,i),x=Math.min(t+r,i+u)-m;return[h,m,d,x]};var B=(e,t,s,r,a,i,n,u)=>{let[h,d,m,x]=T(e,t,s,r,a,i,n,u),b="",_=e,l=t;return m<x?e<a?(b="right",_=a-s):(b="left",_=a+n):t<i?(b="bottom",l=i-r):(b="top",l=i+u),{direction:b,x:_,y:l}};var U=(e,t,s,r,a,i,n,u)=>e<a+n&&e+s>a&&t<i+u&&t+r>i;var j=(e,t,s,r,a,i)=>(r-e)*(r-e)+(a-t)*(a-t)<=(s+i)*(s+i);var k=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,a=s?-1:this.length,i=s?-1:1;for(;r!==a;){let n=this.indexToPointX(r),u=this.indexToPointY(r),h=this._c[r];if(t(n,u,h,this)===!1)break;r+=i}}fill(t){this.forEach((s,r)=>{this.set(s,r,t)})}clampX(t){return q(t,0,this._w-1)}clampY(t){return q(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((a,i,n)=>{r[i]=r[i]||"",r[i]+=n+t}),r.join(`
2
- `)}},C=class e extends k{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,a)=>{t.set(s,r,a)}),t}};function q(e,t,s){return e<t?t:e>s?s:e}var Et=Math.sqrt,V=Math.cos,W=Math.sin,At=2*Math.PI,w=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},g=e=>e instanceof w,o=(e=0,t=e)=>(g(e)&&(t=e.y,e=e.x),new w(e,t)),L=(e,t,s=t)=>g(t)?L(e,t.x,t.y):e.x===t&&e.y===s,Z=(e,t,s=t)=>(g(t)?Z(e,t.x,t.y):(e.x=t,e.y=s),e),O=(e,t,s=t)=>g(t)?O(e,t.x,t.y):(e.x+=t,e.y+=s,e),F=(e,t,s=t)=>g(t)?F(e,t.x,t.y):(e.x-=t,e.y-=s,e),N=(e,t,s=t)=>g(t)?N(e,t.x,t.y):(e.x*=t,e.y*=s,e),E=(e,t,s=t)=>g(t)?E(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),It=(e,t)=>{let s=V(t),r=W(t);return e.x=s*e.x-r*e.y,e.y=r*e.x+s*e.y,e},Pt=(e,t)=>{let s=v(o(t));return F(e,N(s,2*K(e,s)))},Ct=(e,t)=>(v(e),N(e,t),e),$=e=>Math.hypot(e.x,e.y),G=e=>e.x*e.x+e.y*e.y,v=e=>{let t=$(e);return t>0&&E(e,t),e},Lt=(e,t=1)=>{let s=G(e);return s>t*t&&(E(e,Et(s)),N(e,t)),e},Ot=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Ft=(e,t)=>{let s=e.x-t.x,r=e.y-t.y;return s*s+r*r},vt=e=>Math.atan2(e.y,e.x),St=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),K=(e,t)=>e.x*t.x+e.y*t.y,Rt=(e,t)=>e.x*t.y-e.y*t.x,zt=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Dt=(e=1,t=e,s=globalThis.rand||Math.random)=>{let r=s()*At,a=s()*(t-e)+e;return o(V(r)*a,W(r)*a)},Yt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Xt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Ht=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),Bt=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Ut=(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),jt=(e,t,s=1)=>O(e,t.x*s,t.y*s),qt=e=>L(e,Q),Q=o(0,0),Vt=o(1,1),Wt=o(0,-1),Zt=o(1,0),$t=o(0,1),Gt=o(-1,0);var Kt=o(.5,.5),J=o(0,0),Qt=o(1,0),Jt=o(0,1),te=o(1,1),S=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=J){this.sprite=t,this.pos=s||o(0),this._o=o(r),this._s=o(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),a=this.pos.x-s*this.anchor.x,i=this.pos.y-r*this.anchor.y;return[a,i,s,r]}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(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,a=-this.sprite.width*(this.flipX?1-r.x:r.x),i=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(a,i,this.sprite)}};var tt=(e,t)=>Math.abs(t-e)||0;var et=e=>e%1||0;var st=advance=(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 at=(e,t,s,r)=>Math.hypot(s-e,r-t);var it=(e,t)=>Math.hypot(e,t);var A=e=>{let t=0;for(let s=0;s<e.length;s++)t+=e[s];return t};var ot=e=>A(e)/e.length;var nt=(...e)=>{let t=e.sort((r,a)=>r-a),s=Math.floor(t.length/2);return t.length%2===0?(t[s-1]+t[s])/2:t[s]};var ut=(e,t,s)=>{let r=(t-e)%360;return r>180?r-=360:r<-180&&(r+=360),e+r*s};var I=Math.PI/2,ee=(e,t,s,r=1,a=lt)=>new R(e,t,s,r,a),lt=e=>e,se=e=>e*e,re=e=>-e*(e-2),ae=e=>e<.5?2*e*e:-2*e*e+4*e-1,ie=e=>e*e*e-e*Math.sin(e*Math.PI),oe=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},ne=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},ue=e=>Math.sin(13*I*e)*Math.pow(2,10*(e-1)),le=e=>Math.sin(-13*I*(e+1))*Math.pow(2,-10*e)+1,he=e=>{if(e<.5){let r=Math.sin(13*I*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*r*a}let t=Math.sin(-13*I*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},ht=e=>1-z(1-e),z=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,me=e=>e<.5?.5*ht(e*2):.5*z(e*2-1)+.5,R=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,r,a,i){this._o=t,this._p=s,this._x=r,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 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",a=>{if(this._t<=this._w){this._t+=a;return}let i=this._t-this._w;this._o[this._p]=this._lc.lerp(s,r,this._e(i/this._d)),this._t+=a,i>=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 mt=4,P=1<<mt,ct=8,ce=1<<ct,f=4095,D=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 a=Math.floor(t),i=Math.floor(s),n=Math.floor(r),u=t-a,h=s-i,d=r-n,m,x,b=0,_=.5,l,c,M;for(let H=0;H<this._po;H++){let p=a+(i<<mt)+(n<<ct);m=D(u),x=D(h),l=this._p[p&f],l+=m*(this._p[p+1&f]-l),c=this._p[p+P&f],c+=m*(this._p[p+P+1&f]-c),l+=x*(c-l),p+=ce,c=this._p[p&f],c+=m*(this._p[p+1&f]-c),M=this._p[p+P&f],M+=m*(this._p[p+P+1&f]-M),c+=x*(M-c),l+=D(d)*(c-l),b+=l*_,_*=this._pf,a<<=1,u*=2,i<<=1,h*=2,n<<=1,d*=2,u>=1&&(a++,u--),h>=1&&(i++,h--),d>=1&&(n++,d--)}return b}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<f+1;r++)this._p[r]=s()}};var pt=(e,t=!0,s=!1,r=globalThis)=>r.paint(e.width,e.height,a=>{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,a=>{r.push(),a.imageSmoothingEnabled=!s,r.scale(t),r.image(0,0,e),r.pop()});var bt=(e,t,s=1,r=globalThis)=>r.paint(e.width,e.height,a=>{r.push(),r.alpha(s),r.rectfill(0,0,e.width,e.height,t),a.globalCompositeOperation="destination-atop",r.alpha(1),r.image(0,0,e),r.pop()});var dt=(e,t,{borderWidth:s=0,borderColor:r=0,engine:a=globalThis}={})=>{let i=e*2+s;return a.paint(i,i,()=>{a.circfill(i/2,i/2,e,t),s>0&&(a.linewidth(s),a.stroke(r))})};var xt=(e,t,s,{borderWidth:r=0,borderColor:a=0,engine:i=globalThis}={})=>{let n=e+r*2,u=t+r*2;return i.paint(n,u,()=>{i.rectfill(r>0?r:0,r>0?r:0,e,t,s),r>0&&(i.linewidth(r),i.stroke(a))})};var gt=(e,t=0,s=1)=>[...new Array(e).keys()].map(r=>t+s*r);var _t=(e,t=globalThis.rand||Math.random)=>{e=[...e];for(let s=e.length-1;s>0;s--){let r=Math.floor(t()*(s+1)),a=e[s];e[s]=e[r],e[r]=a}return e};var yt=(e,t=globalThis.rand||Math.random)=>e[Math.floor(t()*e.length)];var wt=e=>e[0];var Nt=e=>e[e.length-1];var Mt=e=>e.slice(1);globalThis.utils=Object.assign(globalThis.utils||{},X);})();
1
+ (()=>{var It=Object.defineProperty;var Mt=(e,t)=>{for(var s in t)It(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={};Mt(Z,{ANCHOR_BOT_LEFT:()=>$t,ANCHOR_BOT_RIGHT:()=>Gt,ANCHOR_CENTER:()=>zt,ANCHOR_TOP_LEFT:()=>J,ANCHOR_TOP_RIGHT:()=>Kt,Actor:()=>O,BACK_IN:()=>ee,BACK_IN_OUT:()=>re,BACK_OUT:()=>se,BOUNCE_IN:()=>at,BOUNCE_IN_OUT:()=>ne,BOUNCE_OUT:()=>B,Camera:()=>y,DOWN:()=>jt,EASE_IN:()=>Qt,EASE_IN_OUT:()=>te,EASE_OUT:()=>vt,ELASTIC_IN:()=>ie,ELASTIC_IN_OUT:()=>he,ELASTIC_OUT:()=>oe,Grid:()=>b,LEFT:()=>qt,LINEAR:()=>nt,Noise:()=>Y,ONE:()=>Xt,RIGHT:()=>Vt,TypedGrid:()=>N,UP:()=>Dt,Vector:()=>I,ZERO:()=>G,advance:()=>tt,choose:()=>dt,colcirc:()=>X,colrect:()=>W,diff:()=>Q,dist:()=>st,flipImage:()=>lt,fract:()=>v,head:()=>mt,intersection:()=>w,last:()=>gt,lerpAngle:()=>ht,mag:()=>rt,makeCircle:()=>pt,makeRectangle:()=>ft,mean:()=>it,median:()=>ot,mod:()=>et,range:()=>_t,resolverect:()=>H,scaleImage:()=>ct,shuffle:()=>xt,sum:()=>R,tail:()=>yt,tintImage:()=>ut,tween:()=>Jt,vec:()=>h,vecAbs:()=>Bt,vecAdd:()=>L,vecAngle:()=>Lt,vecAngleBetween:()=>kt,vecCeil:()=>Ft,vecClamp:()=>Ut,vecCross:()=>St,vecDist:()=>Nt,vecDist2:()=>At,vecDiv:()=>P,vecDot:()=>$,vecEq:()=>A,vecFloor:()=>Yt,vecIsZero:()=>Wt,vecLerp:()=>Ot,vecLimit:()=>Tt,vecMag:()=>z,vecMag2:()=>K,vecMove:()=>Ht,vecMult:()=>M,vecNorm:()=>S,vecRand:()=>Ct,vecReflect:()=>Pt,vecRotate:()=>bt,vecRound:()=>Zt,vecSet:()=>q,vecSetMag:()=>Rt,vecSub:()=>k});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 w=(e,t,s,r,i,o,n,a)=>{let l=Math.max(e,i),x=Math.min(e+s,i+n)-l,u=Math.max(t,o),d=Math.min(t+r,o+a)-u;return[l,u,x,d]};var H=(e,t,s,r,i,o,n,a)=>{let[l,x,u,d]=w(e,t,s,r,i,o,n,a),_="",g=e,c=t;return u<d?e<i?(_="right",g=i-s):(_="left",g=i+n):t<o?(_="bottom",c=o-r):(_="top",c=o+a),{direction:_,x:g,y:c}};var W=(e,t,s,r,i,o,n,a)=>e<i+n&&e+s>i&&t<o+a&&t+r>o;var X=(e,t,s,r,i,o)=>(r-e)*(r-e)+(i-t)*(i-t)<=(s+o)*(s+o);var b=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 n=this.indexToPointX(r),a=this.indexToPointY(r),l=this._c[r];if(t(n,a,l,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,n)=>{r[o]=r[o]||"",r[o]+=n+t}),r.join(`
2
+ `)}},N=class e extends b{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 Et=Math.sqrt,V=Math.cos,j=Math.sin,wt=2*Math.PI,I=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}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)),A=(e,t,s=t)=>m(t)?A(e,t.x,t.y):e.x===t&&e.y===s,q=(e,t,s=t)=>(m(t)?q(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,e.y+=s,e),k=(e,t,s=t)=>m(t)?k(e,t.x,t.y):(e.x-=t,e.y-=s,e),M=(e,t,s=t)=>m(t)?M(e,t.x,t.y):(e.x*=t,e.y*=s,e),P=(e,t,s=t)=>m(t)?P(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),bt=(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},Pt=(e,t)=>{let s=S(h(t));return k(e,M(s,2*$(e,s)))},Rt=(e,t)=>(S(e),M(e,t),e),z=e=>Math.hypot(e.x,e.y),K=e=>e.x*e.x+e.y*e.y,S=e=>{let t=z(e);return t>0&&P(e,t),e},Tt=(e,t=1)=>{let s=K(e);return s>t*t&&(P(e,Et(s)),M(e,t)),e},Nt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),At=(e,t)=>{let s=e.x-t.x,r=e.y-t.y;return s*s+r*r},Lt=e=>Math.atan2(e.y,e.x),kt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),$=(e,t)=>e.x*t.x+e.y*t.y,St=(e,t)=>e.x*t.y-e.y*t.x,Ot=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Ct=(e=1,t=e,s=globalThis.rand||Math.random)=>{let r=s()*wt,i=s()*(t-e)+e;return h(V(r)*i,j(r)*i)},Bt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Ft=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Yt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),Zt=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Ut=(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),Ht=(e,t,s=1)=>L(e,t.x*s,t.y*s),Wt=e=>A(e,G),G=h(0,0),Xt=h(1,1),Dt=h(0,-1),Vt=h(1,0),jt=h(0,1),qt=h(-1,0);var zt=h(.5,.5),J=h(0,0),Kt=h(1,0),$t=h(0,1),Gt=h(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=J){this.sprite=t,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){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(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 Q=(e,t)=>Math.abs(t-e)||0;var v=e=>e%1||0;var tt=(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 et=(e,t)=>(t+e%t)%t;var st=(e,t,s,r)=>Math.hypot(s-e,r-t);var rt=(e,t)=>Math.hypot(e,t);var R=e=>{let t=0;for(let s=0;s<e.length;s++)t+=e[s];return t};var it=e=>R(e)/e.length;var ot=(...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 ht=(e,t,s)=>{let r=(t-e)%360;return r>180?r-=360:r<-180&&(r+=360),e+r*s};var T=Math.PI/2,Jt=(e,t,s,r=1,i=nt)=>new C(e,t,s,r,i),nt=e=>e,Qt=e=>e*e,vt=e=>-e*(e-2),te=e=>e<.5?2*e*e:-2*e*e+4*e-1,ee=e=>e*e*e-e*Math.sin(e*Math.PI),se=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},re=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},ie=e=>Math.sin(13*T*e)*Math.pow(2,10*(e-1)),oe=e=>Math.sin(-13*T*(e+1))*Math.pow(2,-10*e)+1,he=e=>{if(e<.5){let r=Math.sin(13*T*(2*e)),i=Math.pow(2,10*(2*e-1));return .5*r*i}let t=Math.sin(-13*T*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},at=e=>1-B(1-e),B=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,ne=e=>e<.5?.5*at(e*2):.5*B(e*2-1)+.5,C=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 F=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),n=Math.floor(r),a=t-i,l=s-o,x=r-n,u,d,_=0,g=.5,c,p,E;for(let U=0;U<this._po;U++){let f=i+(o<<4)+(n<<8);u=F(a),d=F(l),c=this._p[f&4095],c+=u*(this._p[f+1&4095]-c),p=this._p[f+16&4095],p+=u*(this._p[f+16+1&4095]-p),c+=d*(p-c),f+=256,p=this._p[f&4095],p+=u*(this._p[f+1&4095]-p),E=this._p[f+16&4095],E+=u*(this._p[f+16+1&4095]-E),p+=d*(E-p),c+=F(x)*(p-c),_+=c*g,g*=this._pf,i<<=1,a*=2,o<<=1,l*=2,n<<=1,x*=2,a>=1&&(i++,a--),l>=1&&(o++,l--),x>=1&&(n++,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 lt=(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 ct=(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 ut=(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 pt=(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 ft=(e,t,s,{borderWidth:r=0,borderColor:i=0,engine:o=globalThis}={})=>{let n=e+r*2,a=t+r*2;return o.paint(n,a,()=>{let l=r>0;l&&o.cls(i),o.rectfill(l?r:0,l?r:0,e,t,s)})};var _t=(e,t=0,s=1)=>[...new Array(e).keys()].map(r=>t+s*r);var xt=(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 dt=(e,t=globalThis.rand||Math.random)=>e[Math.floor(t()*e.length)];var mt=e=>e[0];var gt=e=>e[e.length-1];var yt=e=>e.slice(1);globalThis.utils=Object.assign(globalThis.utils||{},Z);})();
3
3
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/camera.js CHANGED
@@ -57,9 +57,9 @@
57
57
  start(clip = false) {
58
58
  this._engine.push();
59
59
  if (clip) {
60
- const region = path();
61
- region.rect(this.ox, this.oy, this.width, this.height);
62
- this._engine.clip(region);
60
+ this._engine.clip((ctx) => {
61
+ ctx.rect(this.ox, this.oy, this.width, this.height);
62
+ });
63
63
  }
64
64
  const centerX = this.ox + this.width / 2, centerY = this.oy + this.height / 2;
65
65
  this._engine.translate(centerX, centerY);
@@ -1 +1 @@
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;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.W-t,e||this._engine.H-s),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}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]}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});})();
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;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.W-t,e||this._engine.H-s),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}resize(i,t){this.width=i,this.height=t,this._engine.emit("camera-resized",this)}start(i=!1){this._engine.push(),i&&this._engine.clip(h=>{h.rect(this.ox,this.oy,this.width,this.height)});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]}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/grid.js CHANGED
@@ -161,14 +161,14 @@
161
161
  * @param {Grid} grid
162
162
  * @returns {boolean?} returns `false` to stop/break the loop
163
163
  *
164
- * @param {GridForEachCallback} handler
164
+ * @param {GridForEachCallback} callback
165
165
  * @param {boolean} [reverse=false]
166
166
  */
167
- forEach(handler, reverse = false) {
167
+ forEach(callback, reverse = false) {
168
168
  let i = reverse ? this.length - 1 : 0, limit = reverse ? -1 : this.length, step = reverse ? -1 : 1;
169
169
  while (i !== limit) {
170
170
  const x = this.indexToPointX(i), y = this.indexToPointY(i), cellValue = this._c[i];
171
- if (false === handler(x, y, cellValue, this)) break;
171
+ if (false === callback(x, y, cellValue, this)) break;
172
172
  i += step;
173
173
  }
174
174
  }
package/dist/image.js CHANGED
@@ -77,17 +77,17 @@
77
77
  const imageWidth = width + borderWidth * 2;
78
78
  const imageHeight = height + borderWidth * 2;
79
79
  return engine.paint(imageWidth, imageHeight, () => {
80
+ const hasBorder = borderWidth > 0;
81
+ if (hasBorder) {
82
+ engine.cls(borderColor);
83
+ }
80
84
  engine.rectfill(
81
- borderWidth > 0 ? borderWidth : 0,
82
- borderWidth > 0 ? borderWidth : 0,
85
+ hasBorder ? borderWidth : 0,
86
+ hasBorder ? borderWidth : 0,
83
87
  width,
84
88
  height,
85
89
  color
86
90
  );
87
- if (borderWidth > 0) {
88
- engine.linewidth(borderWidth);
89
- engine.stroke(borderColor);
90
- }
91
91
  });
92
92
  };
93
93
 
package/dist/image.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var f=Object.defineProperty;var d=(t,a)=>{for(var r in a)f(t,r,{get:a[r],enumerable:!0})};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 n={};d(n,{flipImage:()=>u,makeCircle:()=>l,makeRectangle:()=>p,scaleImage:()=>o,tintImage:()=>m});var u=(t,a=!0,r=!1,e=globalThis)=>e.paint(t.width,t.height,s=>{e.push(),e.scale(a?-1:1,r?-1:1),e.image(a?-t.width:0,r?-t.height:0,t),e.pop()});var o=(t,a,r=!0,e=globalThis)=>e.paint(t.width*a,t.height*a,s=>{e.push(),s.imageSmoothingEnabled=!r,e.scale(a),e.image(0,0,t),e.pop()});var m=(t,a,r=1,e=globalThis)=>e.paint(t.width,t.height,s=>{e.push(),e.alpha(r),e.rectfill(0,0,t.width,t.height,a),s.globalCompositeOperation="destination-atop",e.alpha(1),e.image(0,0,t),e.pop()});var l=(t,a,{borderWidth:r=0,borderColor:e=0,engine:s=globalThis}={})=>{let i=t*2+r;return s.paint(i,i,()=>{s.circfill(i/2,i/2,t,a),r>0&&(s.linewidth(r),s.stroke(e))})};var p=(t,a,r,{borderWidth:e=0,borderColor:s=0,engine:i=globalThis}={})=>{let b=t+e*2,c=a+e*2;return i.paint(b,c,()=>{i.rectfill(e>0?e:0,e>0?e:0,t,a,r),e>0&&(i.linewidth(e),i.stroke(s))})};globalThis.utils=Object.assign(globalThis.utils||{},n);})();
1
+ (()=>{var m=Object.defineProperty;var x=(t,a)=>{for(var s in a)m(t,s,{get:a[s],enumerable:!0})};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 h={};x(h,{flipImage:()=>u,makeCircle:()=>r,makeRectangle:()=>c,scaleImage:()=>f,tintImage:()=>e});var u=(t,a=!0,s=!1,l=globalThis)=>l.paint(t.width,t.height,o=>{l.push(),l.scale(a?-1:1,s?-1:1),l.image(a?-t.width:0,s?-t.height:0,t),l.pop()});var f=(t,a,s=!0,l=globalThis)=>l.paint(t.width*a,t.height*a,o=>{l.push(),o.imageSmoothingEnabled=!s,l.scale(a),l.image(0,0,t),l.pop()});var e=(t,a,s=1,l=globalThis)=>l.paint(t.width,t.height,o=>{l.push(),l.alpha(s),l.rectfill(0,0,t.width,t.height,a),o.globalCompositeOperation="destination-atop",l.alpha(1),l.image(0,0,t),l.pop()});var r=(t,a,{borderWidth:s=0,borderColor:l=0,engine:o=globalThis}={})=>{let i=t*2+s;return o.paint(i,i,()=>{o.circfill(i/2,i/2,t,a),s>0&&(o.linewidth(s),o.stroke(l))})};var c=(t,a,s,{borderWidth:l=0,borderColor:o=0,engine:i=globalThis}={})=>{let T=t+l*2,b=a+l*2;return i.paint(T,b,()=>{let p=l>0;p&&i.cls(o),i.rectfill(p?l:0,p?l:0,t,a,s)})};globalThis.utils=Object.assign(globalThis.utils||{},h);})();
package/dist/math.js CHANGED
@@ -41,7 +41,7 @@
41
41
  var PI2 = 2 * Math.PI;
42
42
 
43
43
  // src/math/advance.js
44
- var advance_default = advance = (position, velocity, acceleration, deltaTime = 1) => {
44
+ var advance_default = (position, velocity, acceleration, deltaTime = 1) => {
45
45
  if (acceleration) {
46
46
  velocity.x += acceleration.x * deltaTime;
47
47
  velocity.y += acceleration.y * deltaTime;
package/dist/math.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var d=Object.defineProperty;var M=(e,t)=>{for(var r in t)d(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:()=>u,diff:()=>c,dist:()=>l,fract:()=>x,lerpAngle:()=>i,mag:()=>p,mean:()=>f,median:()=>y,mod:()=>a,sum:()=>s});var c=(e,t)=>Math.abs(t-e)||0;var x=e=>e%1||0;var T=2*Math.PI;var u=advance=(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 a=(e,t)=>(t+e%t)%t;var l=(e,t,r,o)=>Math.hypot(r-e,o-t);var p=(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,h)=>o-h),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};globalThis.utils=Object.assign(globalThis.utils||{},n);})();
1
+ (()=>{var d=Object.defineProperty;var M=(e,t)=>{for(var r in t)d(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:()=>u,diff:()=>c,dist:()=>p,fract:()=>x,lerpAngle:()=>i,mag:()=>a,mean:()=>f,median:()=>y,mod:()=>l,sum:()=>s});var c=(e,t)=>Math.abs(t-e)||0;var x=e=>e%1||0;var T=2*Math.PI;var u=(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 l=(e,t)=>(t+e%t)%t;var p=(e,t,r,o)=>Math.hypot(r-e,o-t);var a=(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,h)=>o-h),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};globalThis.utils=Object.assign(globalThis.utils||{},n);})();
package/dist/noise.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var E=Object.defineProperty;var T=(o,e)=>{for(var t in e)E(o,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let e in globalThis.utils)e!=="global"&&(o||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var v={};T(v,{Noise:()=>N});var k=4,h=1<<k,A=8,P=1<<A,n=4095,y=o=>.5*(1-Math.cos(o*Math.PI)),N=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,s=0){e<0&&(e=-e),t<0&&(t=-t),s<0&&(s=-s);let m=Math.floor(e),l=Math.floor(t),p=Math.floor(s),b=e-m,c=t-l,f=s-p,u,g,w=0,x=.5,i,a,d;for(let _=0;_<this._po;_++){let r=m+(l<<k)+(p<<A);u=y(b),g=y(c),i=this._p[r&n],i+=u*(this._p[r+1&n]-i),a=this._p[r+h&n],a+=u*(this._p[r+h+1&n]-a),i+=g*(a-i),r+=P,a=this._p[r&n],a+=u*(this._p[r+1&n]-a),d=this._p[r+h&n],d+=u*(this._p[r+h+1&n]-d),a+=g*(d-a),i+=y(f)*(a-i),w+=i*x,x*=this._pf,m<<=1,b*=2,l<<=1,c*=2,p<<=1,f*=2,b>=1&&(m++,b--),c>=1&&(l++,c--),f>=1&&(p++,f--)}return w}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.rseed(e);let t=this._e.rand||Math.random;for(let s=0;s<n+1;s++)this._p[s]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},v);})();
1
+ (()=>{var b=Object.defineProperty;var g=(P,i)=>{for(var t in i)b(P,t,{get:i[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(P=!0)=>{for(let i in globalThis.utils)i!=="global"&&(P||globalThis[i]===void 0)&&(globalThis[i]=globalThis.utils[i])};var p={};g(p,{Noise:()=>N});var r=P=>.5*(1-Math.cos(P*Math.PI)),N=class{_p=[];_po=4;_pf=.5;_e=null;constructor(i){this._e=i||globalThis,this.noiseSeed()}noise(i,t=0,l=0){i<0&&(i=-i),t<0&&(t=-t),l<0&&(l=-l);let e=Math.floor(i),I=Math.floor(t),h=Math.floor(l),E=i-e,n=t-I,a=l-h,R,L,c=0,Z=.5,_,s,f;for(let u=0;u<this._po;u++){let o=e+(I<<4)+(h<<8);R=r(E),L=r(n),_=this._p[o&4095],_+=R*(this._p[o+1&4095]-_),s=this._p[o+16&4095],s+=R*(this._p[o+16+1&4095]-s),_+=L*(s-_),o+=256,s=this._p[o&4095],s+=R*(this._p[o+1&4095]-s),f=this._p[o+16&4095],f+=R*(this._p[o+16+1&4095]-f),s+=L*(f-s),_+=r(a)*(s-_),c+=_*Z,Z*=this._pf,e<<=1,E*=2,I<<=1,n*=2,h<<=1,a*=2,E>=1&&(e++,E--),n>=1&&(I++,n--),a>=1&&(h++,a--)}return c}noiseDetail(i,t){i>0&&(this._po=i),t>0&&(this._pf=t)}noiseSeed(i=null){i!=null&&this._e.rseed(i);let t=this._e.rand||Math.random;for(let l=0;l<4096;l++)this._p[l]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},p);})();
package/dist/tween.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var b=Object.defineProperty;var c=(e,t)=>{for(var s in t)b(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 m={};c(m,{BACK_IN:()=>_,BACK_IN_OUT:()=>y,BACK_OUT:()=>N,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>T,BOUNCE_OUT:()=>o,EASE_IN:()=>f,EASE_IN_OUT:()=>g,EASE_OUT:()=>d,ELASTIC_IN:()=>w,ELASTIC_IN_OUT:()=>v,ELASTIC_OUT:()=>x,LINEAR:()=>l,tween:()=>h});var n=Math.PI/2,h=(e,t,s,r=1,a=l)=>new u(e,t,s,r,a),l=e=>e,f=e=>e*e,d=e=>-e*(e-2),g=e=>e<.5?2*e*e:-2*e*e+4*e-1,_=e=>e*e*e-e*Math.sin(e*Math.PI),N=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},y=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},w=e=>Math.sin(13*n*e)*Math.pow(2,10*(e-1)),x=e=>Math.sin(-13*n*(e+1))*Math.pow(2,-10*e)+1,v=e=>{if(e<.5){let r=Math.sin(13*n*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*r*a}let t=Math.sin(-13*n*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},p=e=>1-o(1-e),o=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,T=e=>e<.5?.5*p(e*2):.5*o(e*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(t,s,r,a,i){this._o=t,this._p=s,this._x=r,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 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",a=>{if(this._t<=this._w){this._t+=a;return}let i=this._t-this._w;this._o[this._p]=this._lc.lerp(s,r,this._e(i/this._d)),this._t+=a,i>=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}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
1
+ (()=>{var c=Object.defineProperty;var p=(t,s)=>{for(var i in s)c(t,i,{get:s[i],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let s in globalThis.utils)s!=="global"&&(t||globalThis[s]===void 0)&&(globalThis[s]=globalThis.utils[s])};var u={};p(u,{BACK_IN:()=>x,BACK_IN_OUT:()=>M,BACK_OUT:()=>I,BOUNCE_IN:()=>a,BOUNCE_IN_OUT:()=>O,BOUNCE_OUT:()=>l,EASE_IN:()=>g,EASE_IN_OUT:()=>T,EASE_OUT:()=>b,ELASTIC_IN:()=>E,ELASTIC_IN_OUT:()=>N,ELASTIC_OUT:()=>w,LINEAR:()=>n,tween:()=>f});var _=Math.PI/2,f=(t,s,i,r=1,h=n)=>new o(t,s,i,r,h),n=t=>t,g=t=>t*t,b=t=>-t*(t-2),T=t=>t<.5?2*t*t:-2*t*t+4*t-1,x=t=>t*t*t-t*Math.sin(t*Math.PI),I=t=>{let s=1-t;return 1-(s*s*s-s*Math.sin(s*Math.PI))},M=t=>{if(t<.5){let i=2*t;return .5*(i*i*i-i*Math.sin(i*Math.PI))}let s=1-(2*t-1);return .5*(1-(s*s*s-s*Math.sin(t*Math.PI)))+.5},E=t=>Math.sin(13*_*t)*Math.pow(2,10*(t-1)),w=t=>Math.sin(-13*_*(t+1))*Math.pow(2,-10*t)+1,N=t=>{if(t<.5){let r=Math.sin(13*_*(2*t)),h=Math.pow(2,10*(2*t-1));return .5*r*h}let s=Math.sin(-13*_*(2*t-1+1)),i=Math.pow(2,-10*(2*t-1));return .5*(s*i+2)},a=t=>1-l(1-t),l=t=>t<4/11?121*t*t/16:t<8/11?363/40*t*t-99/10*t+17/5:t<9/10?4356/361*t*t-35442/1805*t+16061/1805:54/5*t*t-513/25*t+268/25,O=t=>t<.5?.5*a(t*2):.5*l(t*2-1)+.5,o=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(s,i,r,h,e){this._o=s,this._p=i,this._x=r,this._d=h,this._e=e,this._w=0}start(s){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let i=this._o[this._p]||0,r=this._rel?i+this._x:this._x;return this._lc=this._lc||s||globalThis,this._u=this._lc.listen("update",h=>{if(this._t<=this._w){this._t+=h;return}let e=this._t-this._w;this._o[this._p]=this._lc.lerp(i,r,this._e(e/this._d)),this._t+=h,e>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(s=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,s)for(let i of this._cb)i(this._o);return this}restart(s=null,i=!1){return this.stop(i).restart(s)}onEnd(s){return this._cb.push(s),this}chain(s){return this._ch.onEnd(()=>{this._cu=s.start(this._lc)}),this._ch=s,this}reset(){return this._cb.length=0,this.stop()}relative(s=!0){return this._rel=s,this}delay(s){return this._w=s,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};globalThis.utils=Object.assign(globalThis.utils||{},u);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.35.1",
3
+ "version": "0.36.0",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "grid"
24
24
  ],
25
25
  "scripts": {
26
- "dev": "esbuild src/_web.js --bundle --watch --outfile=dist/all.js --servedir=.",
26
+ "dev": "esbuild src/_web.js --bundle --watch --outfile=samples/dist/all.js --servedir=samples",
27
27
  "build": "node scripts/build.js",
28
28
  "prepare": "npm run build",
29
29
  "prepublishOnly": "npm run build",
@@ -37,8 +37,8 @@
37
37
  "litecanvas": "latest"
38
38
  },
39
39
  "devDependencies": {
40
- "esbuild": "^0.25.5",
40
+ "esbuild": "^0.25.6",
41
41
  "gzip-size": "^7.0.0",
42
- "prettier": "^3.5.3"
42
+ "prettier": "^3.6.2"
43
43
  }
44
44
  }
@@ -1,5 +1,4 @@
1
1
  import { Vector, vec } from "../vector/index.js"
2
- import "litecanvas"
3
2
 
4
3
  export const ANCHOR_CENTER = /** @__PURE__ */ vec(0.5, 0.5)
5
4
  export const ANCHOR_TOP_LEFT = /** @__PURE__ */ vec(0, 0)
@@ -8,7 +7,7 @@ export const ANCHOR_BOT_LEFT = /** @__PURE__ */ vec(0, 1)
8
7
  export const ANCHOR_BOT_RIGHT = /** @__PURE__ */ vec(1, 1)
9
8
 
10
9
  export class Actor {
11
- /** @type {Image|HTMLCanvasElement|OffscreenCanvas} */
10
+ /** @type {CanvasImageSource} */
12
11
  sprite
13
12
 
14
13
  /** @type {Vector} The actor position */
@@ -57,9 +57,9 @@ export default class Camera {
57
57
  this._engine.push()
58
58
 
59
59
  if (clip) {
60
- const region = path()
61
- region.rect(this.ox, this.oy, this.width, this.height)
62
- this._engine.clip(region)
60
+ this._engine.clip((ctx) => {
61
+ ctx.rect(this.ox, this.oy, this.width, this.height)
62
+ })
63
63
  }
64
64
 
65
65
  const centerX = this.ox + this.width / 2,
package/src/grid/index.js CHANGED
@@ -154,10 +154,10 @@ export class Grid {
154
154
  * @param {Grid} grid
155
155
  * @returns {boolean?} returns `false` to stop/break the loop
156
156
  *
157
- * @param {GridForEachCallback} handler
157
+ * @param {GridForEachCallback} callback
158
158
  * @param {boolean} [reverse=false]
159
159
  */
160
- forEach(handler, reverse = false) {
160
+ forEach(callback, reverse = false) {
161
161
  let i = reverse ? this.length - 1 : 0,
162
162
  limit = reverse ? -1 : this.length,
163
163
  step = reverse ? -1 : 1
@@ -167,7 +167,7 @@ export class Grid {
167
167
  y = this.indexToPointY(i),
168
168
  cellValue = this._c[i]
169
169
 
170
- if (false === handler(x, y, cellValue, this)) break
170
+ if (false === callback(x, y, cellValue, this)) break
171
171
 
172
172
  i += step
173
173
  }
package/src/image/flip.js CHANGED
@@ -1,9 +1,7 @@
1
- import "litecanvas"
2
-
3
1
  /**
4
2
  * Flip a image with a color and optional opacity.
5
3
  *
6
- * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} img
4
+ * @param {CanvasImageSource} img
7
5
  * @param {boolean} [horizontal=true]
8
6
  * @param {boolean} [vertically=false]
9
7
  * @param {LitecanvasInstance} [engine]
@@ -1,5 +1,3 @@
1
- import "litecanvas"
2
-
3
1
  /**
4
2
  * Creates an image with the geometric shape of a circle with an optional border.
5
3
  *
@@ -1,5 +1,3 @@
1
- import "litecanvas"
2
-
3
1
  /**
4
2
  * Creates an image with the geometric shape of a rectangle with an optional border.
5
3
  *
@@ -22,16 +20,17 @@ export default (
22
20
  const imageHeight = height + borderWidth * 2
23
21
 
24
22
  return engine.paint(imageWidth, imageHeight, () => {
23
+ const hasBorder = borderWidth > 0
24
+ if (hasBorder) {
25
+ engine.cls(borderColor)
26
+ }
27
+
25
28
  engine.rectfill(
26
- borderWidth > 0 ? borderWidth : 0,
27
- borderWidth > 0 ? borderWidth : 0,
29
+ hasBorder ? borderWidth : 0,
30
+ hasBorder ? borderWidth : 0,
28
31
  width,
29
32
  height,
30
33
  color
31
34
  )
32
- if (borderWidth > 0) {
33
- engine.linewidth(borderWidth)
34
- engine.stroke(borderColor)
35
- }
36
35
  })
37
36
  }
@@ -1,9 +1,7 @@
1
- import "litecanvas"
2
-
3
1
  /**
4
2
  * Increases or decreases a image size.
5
3
  *
6
- * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} img
4
+ * @param {CanvasImageSource} img
7
5
  * @param {number} factor
8
6
  * @param {LitecanvasInstance} [engine]
9
7
  */
package/src/image/tint.js CHANGED
@@ -1,9 +1,7 @@
1
- import "litecanvas"
2
-
3
1
  /**
4
2
  * Tint a image with a color and optional opacity.
5
3
  *
6
- * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} img
4
+ * @param {CanvasImageSource} img
7
5
  * @param {number} color
8
6
  * @param {number} [opacity=1]
9
7
  * @param {LitecanvasInstance} [engine]
@@ -9,7 +9,7 @@ import { Vector } from "../vector/index.js"
9
9
  * @param {Vector?} [acceleration]
10
10
  * @param {number?} [deltaTime]
11
11
  */
12
- export default advance = (position, velocity, acceleration, deltaTime = 1) => {
12
+ export default (position, velocity, acceleration, deltaTime = 1) => {
13
13
  if (acceleration) {
14
14
  velocity.x += acceleration.x * deltaTime
15
15
  velocity.y += acceleration.y * deltaTime
@@ -3,12 +3,7 @@
3
3
  * https://github.com/processing/p5.js/blob/v1.11.1/src/math/noise.js
4
4
  */
5
5
 
6
- // import litecanvas types
7
- import "litecanvas"
8
-
9
- /**
10
- * Constants for Perlin noise calculations.
11
- */
6
+ // Constants for Perlin noise calculations.
12
7
  const PERLIN_YWRAPB = 4
13
8
  const PERLIN_YWRAP = 1 << PERLIN_YWRAPB
14
9
  const PERLIN_ZWRAPB = 8
@@ -1,5 +1,3 @@
1
- import "litecanvas"
2
-
3
1
  const HALF_PI = Math.PI / 2
4
2
 
5
3
  /**