@litecanvas/utils 0.25.0 → 0.27.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/README.md CHANGED
@@ -50,4 +50,5 @@ const pos = vec(0, 0)
50
50
  - **Grid**: class to handle retangular grid areas. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/grid)
51
51
  - **Collision** utilities. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/collision)
52
52
  - **Tween** to create animations. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/tween)
53
+ - **Image** to manipulate images. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/image)
53
54
  - And some [math utilities](https://github.com/litecanvas/utils/tree/main/src/math)...
package/dist/actor.js CHANGED
@@ -15,8 +15,8 @@
15
15
  };
16
16
 
17
17
  // src/actor/index.js
18
- var actor_exports = {};
19
- __export(actor_exports, {
18
+ var index_exports = {};
19
+ __export(index_exports, {
20
20
  ANCHOR_BOT_LEFT: () => ANCHOR_BOT_LEFT,
21
21
  ANCHOR_BOT_RIGHT: () => ANCHOR_BOT_RIGHT,
22
22
  ANCHOR_CENTER: () => ANCHOR_CENTER,
@@ -213,5 +213,5 @@
213
213
  };
214
214
 
215
215
  // src/actor/_web.js
216
- globalThis.utils = Object.assign(globalThis.utils || {}, actor_exports);
216
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
217
217
  })();
package/dist/actor.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var u=Object.defineProperty;var p=(o,t)=>{for(var e in t)u(o,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let o in globalThis.utils)o!=="global"&&(globalThis[o]=globalThis.utils[o])};var l={};p(l,{ANCHOR_BOT_LEFT:()=>x,ANCHOR_BOT_RIGHT:()=>g,ANCHOR_CENTER:()=>d,ANCHOR_TOP_LEFT:()=>f,ANCHOR_TOP_RIGHT:()=>y,Actor:()=>c});var T=2*Math.PI,n=class{x;y;constructor(t=0,e=t){this.x=t,this.y=e}toString(){return`Vector (${this.x}, ${this.y})`}},h=o=>o instanceof n,r=(o=0,t=o)=>(h(o)&&(t=o.y,o=o.x),new n(o,t));var d=r(.5,.5),f=r(0,0),y=r(1,0),x=r(0,1),g=r(1,1),c=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,s=f){this.sprite=t,this.pos=e||r(0),this._o=r(s),this._s=r(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),s=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,a=this.pos.y-s*this.anchor.y;return[i,a,e,s]}draw(t=globalThis,e=!0){this.hidden||this.opacity<=0||(e&&t.push(),this.transform(t),this.drawImage(t),e&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,e=!0){let s=this.anchor,i=-this.sprite.width*(this.flipX?1-s.x:s.x),a=-this.sprite.height*(this.flipY?1-s.y:s.y);e&&t.alpha(this.opacity),t.image(i,a,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},l);})();
1
+ (()=>{var c=Object.defineProperty;var l=(r,t)=>{for(var e in t)c(r,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let r in globalThis.utils)r!=="global"&&(globalThis[r]=globalThis.utils[r])};var m={};l(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>D,ANCHOR_CENTER:()=>b,ANCHOR_TOP_LEFT:()=>p,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>u});var _=2*Math.PI,n=class{x;y;constructor(t=0,e=t){this.x=t,this.y=e}toString(){return`Vector (${this.x}, ${this.y})`}},f=r=>r instanceof n,s=(r=0,t=r)=>(f(r)&&(t=r.y,r=r.x),new n(r,t));var b=s(.5,.5),p=s(0,0),h=s(1,0),d=s(0,1),D=s(1,1),u=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,a=p){this.sprite=t,this.pos=e||s(0),this._o=s(a),this._s=s(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,e=t){this._s.x=t,this._s.y=e}scaleBy(t,e=t){this._s.x*=t,this._s.y*=e}getBounds(t=!0){let e=this.sprite.width*(t?this._s.x:1),a=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,o=this.pos.y-a*this.anchor.y;return[i,o,e,a]}draw(t=globalThis,e=!0){this.hidden||this.opacity<=0||(e&&t.push(),this.transform(t),this.drawImage(t),e&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,e=!0){let a=this.anchor,i=-this.sprite.width*(this.flipX?1-a.x:a.x),o=-this.sprite.height*(this.flipY?1-a.y:a.y);e&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
package/dist/all.js CHANGED
@@ -15,8 +15,8 @@
15
15
  };
16
16
 
17
17
  // src/index.js
18
- var src_exports = {};
19
- __export(src_exports, {
18
+ var index_exports = {};
19
+ __export(index_exports, {
20
20
  ANCHOR_BOT_LEFT: () => ANCHOR_BOT_LEFT,
21
21
  ANCHOR_BOT_RIGHT: () => ANCHOR_BOT_RIGHT,
22
22
  ANCHOR_CENTER: () => ANCHOR_CENTER,
@@ -49,12 +49,16 @@
49
49
  ZERO: () => ZERO,
50
50
  advance: () => advance_default,
51
51
  diff: () => diff_default,
52
+ dist: () => dist_default,
53
+ flipImage: () => flip_default,
52
54
  fract: () => fract_default,
53
55
  intersection: () => intersection_default,
56
+ mag: () => mag_default,
54
57
  mod: () => mod_default,
55
58
  range: () => range_default,
56
59
  resolve: () => resolve_default,
57
- scaleImage: () => scale_image_default,
60
+ round: () => round_default,
61
+ scaleImage: () => scale_default,
58
62
  tint: () => tint_default,
59
63
  tween: () => tween,
60
64
  vec: () => vec,
@@ -654,7 +658,7 @@
654
658
  vecMult(v, value);
655
659
  return v;
656
660
  };
657
- var vecMag = (v) => sqrt(v.x * v.x + v.y * v.y);
661
+ var vecMag = (v) => Math.hypot(v.x, v.y);
658
662
  var vecMag2 = (v) => v.x * v.x + v.y * v.y;
659
663
  var vecNorm = (v) => {
660
664
  const length = vecMag(v);
@@ -672,9 +676,7 @@
672
676
  return v;
673
677
  };
674
678
  var vecDist = (a, b) => {
675
- const dx = a.x - b.x;
676
- const dy = a.y - b.y;
677
- return sqrt(dx * dx + dy * dy);
679
+ return Math.hypot(b.x - a.x, b.y - a.y);
678
680
  };
679
681
  var vecDist2 = (a, b) => {
680
682
  const dx = a.x - b.x;
@@ -912,6 +914,25 @@
912
914
  // src/math/mod.js
913
915
  var mod_default = (a, b) => (b + a % b) % b;
914
916
 
917
+ // src/math/round.js
918
+ var round_default = (n, decimals) => {
919
+ if (!decimals) {
920
+ return Math.round(n);
921
+ }
922
+ const multiplier = Math.pow(10, decimals);
923
+ return Math.round(n * multiplier) / multiplier;
924
+ };
925
+
926
+ // src/math/dist.js
927
+ var dist_default = (x1, y1, x2, y2) => {
928
+ return Math.hypot(x2 - x1, y2 - y1);
929
+ };
930
+
931
+ // src/math/mag.js
932
+ var mag_default = (x, y) => {
933
+ return Math.hypot(x, y);
934
+ };
935
+
915
936
  // src/tween/index.js
916
937
  var HALF_PI = Math.PI / 2;
917
938
  var tween = (object, prop, toValue, duration = 1, easing = LINEAR) => {
@@ -1273,8 +1294,8 @@
1273
1294
  });
1274
1295
  };
1275
1296
 
1276
- // src/image/scale-image.js
1277
- var scale_image_default = (img, factor, pixelart = true, engine = globalThis) => {
1297
+ // src/image/scale.js
1298
+ var scale_default = (img, factor, pixelart = true, engine = globalThis) => {
1278
1299
  return engine.paint(img.width * factor, img.height * factor, (ctx) => {
1279
1300
  engine.push();
1280
1301
  ctx.imageSmoothingEnabled = !pixelart;
@@ -1284,7 +1305,17 @@
1284
1305
  });
1285
1306
  };
1286
1307
 
1308
+ // src/image/flip.js
1309
+ var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => {
1310
+ return engine.paint(img.width, img.height, (ctx) => {
1311
+ engine.push();
1312
+ engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1);
1313
+ engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img);
1314
+ engine.pop();
1315
+ });
1316
+ };
1317
+
1287
1318
  // src/_web.js
1288
- globalThis.utils = Object.assign(globalThis.utils || {}, src_exports);
1319
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
1289
1320
  })();
1290
1321
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/all.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var lt=Object.defineProperty;var ut=(e,t)=>{for(var s in t)lt(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 W={};ut(W,{ANCHOR_BOT_LEFT:()=>Nt,ANCHOR_BOT_RIGHT:()=>Bt,ANCHOR_CENTER:()=>Xt,ANCHOR_TOP_LEFT:()=>J,ANCHOR_TOP_RIGHT:()=>Yt,Actor:()=>R,BACK_IN:()=>Gt,BACK_IN_OUT:()=>$t,BACK_OUT:()=>jt,BOUNCE_IN:()=>ot,BOUNCE_IN_OUT:()=>Kt,BOUNCE_OUT:()=>Y,Camera:()=>w,DOWN:()=>Dt,EASE_IN:()=>Ut,EASE_IN_OUT:()=>Vt,EASE_OUT:()=>Ft,ELASTIC_IN:()=>qt,ELASTIC_IN_OUT:()=>zt,ELASTIC_OUT:()=>Zt,Grid:()=>b,LEFT:()=>Rt,LINEAR:()=>rt,Noise:()=>B,ONE:()=>Ct,RIGHT:()=>Pt,TypedGrid:()=>S,UP:()=>Lt,Vector:()=>T,ZERO:()=>K,advance:()=>st,diff:()=>Q,fract:()=>tt,intersection:()=>I,mod:()=>it,range:()=>et,resolve:()=>F,scaleImage:()=>ct,tint:()=>at,tween:()=>Wt,vec:()=>n,vecAbs:()=>It,vecAdd:()=>L,vecAngle:()=>mt,vecAngleBetween:()=>wt,vecCeil:()=>bt,vecClamp:()=>Ot,vecCross:()=>Tt,vecDist:()=>gt,vecDist2:()=>yt,vecDiv:()=>A,vecDot:()=>z,vecEq:()=>C,vecFloor:()=>At,vecIsZero:()=>kt,vecLerp:()=>Et,vecLimit:()=>xt,vecMag:()=>q,vecMag2:()=>Z,vecMove:()=>St,vecMult:()=>E,vecNorm:()=>D,vecRand:()=>Mt,vecReflect:()=>_t,vecRotate:()=>pt,vecRound:()=>Ht,vecSet:()=>$,vecSetMag:()=>dt,vecSub:()=>P,wave:()=>v});var I=(e,t,s,i,r,o,h,a)=>{let c=Math.max(e,r),x=Math.min(e+s,r+h)-c,u=Math.max(t,o),g=Math.min(t+i,o+a)-u;return[c,u,x,g]};var F=(e,t,s,i,r,o,h,a)=>{let[c,x,u,g]=I(e,t,s,i,r,o,h,a),d="",m=e,l=t;return u<g?e<r?(d="right",m=r-s):(d="left",m=r+h):t<o?(d="bottom",l=o-i):(d="top",l=o+a),{direction:d,x:m,y:l}};var w=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){if(this._engine.push(),t){let r=path();r.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(r)}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 b=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 V(t,0,this._w-1)}clampY(t){return V(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
- `)}},S=class e extends b{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 V(e,t,s){return e<t?t:e>s?s:e}var k=Math.sqrt,G=Math.cos,j=Math.sin,ft=2*Math.PI,T=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},y=e=>e instanceof T,n=(e=0,t=e)=>(y(e)&&(t=e.y,e=e.x),new T(e,t)),C=(e,t,s=t)=>y(t)?C(e,t.x,t.y):e.x===t&&e.y===s,$=(e,t,s=t)=>(y(t)?$(e,t.x,t.y):(e.x=t,e.y=s),e),L=(e,t,s=t)=>y(t)?L(e,t.x,t.y):(e.x+=t,e.y+=s,e),P=(e,t,s=t)=>y(t)?P(e,t.x,t.y):(e.x-=t,e.y-=s,e),E=(e,t,s=t)=>y(t)?E(e,t.x,t.y):(e.x*=t,e.y*=s,e),A=(e,t,s=t)=>y(t)?A(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),pt=(e,t)=>{let s=G(t),i=j(t);return e.x=s*e.x-i*e.y,e.y=i*e.x+s*e.y,e},_t=(e,t)=>{let s=D(n(t));return P(e,E(s,2*z(e,s)))},dt=(e,t)=>(D(e),E(e,t),e),q=e=>k(e.x*e.x+e.y*e.y),Z=e=>e.x*e.x+e.y*e.y,D=e=>{let t=q(e);return t>0&&A(e,t),e},xt=(e,t=1)=>{let s=Z(e);return s>t*t&&(A(e,k(s)),E(e,t)),e},gt=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return k(s*s+i*i)},yt=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return s*s+i*i},mt=e=>Math.atan2(e.y,e.x),wt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),z=(e,t)=>e.x*t.x+e.y*t.y,Tt=(e,t)=>e.x*t.y-e.y*t.x,Et=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Mt=(e=1,t=e,s=globalThis.rand||Math.random)=>{let i=s()*ft,r=s()*(t-e)+e;return n(G(i)*r,j(i)*r)},It=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),bt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),At=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),Ht=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Ot=(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),St=(e,t,s=1)=>L(e,t.x*s,t.y*s),kt=e=>C(e,K),K=n(0,0),Ct=n(1,1),Lt=n(0,-1),Pt=n(1,0),Dt=n(0,1),Rt=n(-1,0);var Xt=n(.5,.5),J=n(0,0),Yt=n(1,0),Nt=n(0,1),Bt=n(1,1),R=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,i=J){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(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 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 Q=(e,t)=>Math.abs(t-e)||0;var v=(e,t,s,i=Math.sin)=>e+(i(s)+1)/2*(t-e);var tt=e=>e%1||0;var et=e=>Array.from(Array(e).keys());var st=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 it=(e,t)=>(t+e%t)%t;var H=Math.PI/2,Wt=(e,t,s,i=1,r=rt)=>new X(e,t,s,i,r),rt=e=>e,Ut=e=>e*e,Ft=e=>-e*(e-2),Vt=e=>e<.5?2*e*e:-2*e*e+4*e-1,Gt=e=>e*e*e-e*Math.sin(e*Math.PI),jt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},$t=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},qt=e=>Math.sin(13*H*e)*Math.pow(2,10*(e-1)),Zt=e=>Math.sin(-13*H*(e+1))*Math.pow(2,-10*e)+1,zt=e=>{if(e<.5){let i=Math.sin(13*H*(2*e)),r=Math.pow(2,10*(2*e-1));return .5*i*r}let t=Math.sin(-13*H*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},ot=e=>1-Y(1-e),Y=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,Kt=e=>e<.5?.5*ot(e*2):.5*Y(e*2-1)+.5,X=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,i,r,o){this._o=t,this._p=s,this._x=i,this._d=r,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,i=this._rel?s+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",r=>{if(this._t<=this._w){this._t+=r;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,i,this._e(o/this._d)),this._t+=r,o>=this._d&&(this._o[this._p]=i,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 nt=4,O=1<<nt,ht=8,Jt=1<<ht,_=4095,N=e=>.5*(1-Math.cos(e*Math.PI)),B=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,s=0,i=0){t<0&&(t=-t),s<0&&(s=-s),i<0&&(i=-i);let r=Math.floor(t),o=Math.floor(s),h=Math.floor(i),a=t-r,c=s-o,x=i-h,u,g,d=0,m=.5,l,f,M;for(let U=0;U<this._po;U++){let p=r+(o<<nt)+(h<<ht);u=N(a),g=N(c),l=this._p[p&_],l+=u*(this._p[p+1&_]-l),f=this._p[p+O&_],f+=u*(this._p[p+O+1&_]-f),l+=g*(f-l),p+=Jt,f=this._p[p&_],f+=u*(this._p[p+1&_]-f),M=this._p[p+O&_],M+=u*(this._p[p+O+1&_]-M),f+=g*(M-f),l+=N(x)*(f-l),d+=l*m,m*=this._pf,r<<=1,a*=2,o<<=1,c*=2,h<<=1,x*=2,a>=1&&(r++,a--),c>=1&&(o++,c--),x>=1&&(h++,x--)}return d}noiseDetail(t,s){t>0&&(this._po=t),s>0&&(this._pf=s)}noiseSeed(t=null){t!=null&&this._e.seed(t);let s=this._e.rand||Math.random;for(let i=0;i<_+1;i++)this._p[i]=s()}};var at=(e,t,s=1,i=globalThis)=>i.paint(e.width,e.height,r=>{i.push(),i.alpha(s),i.rectfill(0,0,e.width,e.height,t),r.globalCompositeOperation="destination-atop",i.alpha(1),i.image(0,0,e),i.pop()});var ct=(e,t,s=!0,i=globalThis)=>i.paint(e.width*t,e.height*t,r=>{i.push(),r.imageSmoothingEnabled=!s,i.scale(t),i.image(0,0,e),i.pop()});globalThis.utils=Object.assign(globalThis.utils||{},W);})();
1
+ (()=>{var mt=Object.defineProperty;var ft=(e,t)=>{for(var r in t)mt(e,r,{get:t[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var X={};ft(X,{ANCHOR_BOT_LEFT:()=>Wt,ANCHOR_BOT_RIGHT:()=>zt,ANCHOR_CENTER:()=>Yt,ANCHOR_TOP_LEFT:()=>K,ANCHOR_TOP_RIGHT:()=>Nt,Actor:()=>O,BACK_IN:()=>$t,BACK_IN_OUT:()=>Kt,BACK_OUT:()=>Zt,BOUNCE_IN:()=>ot,BOUNCE_IN_OUT:()=>te,BOUNCE_OUT:()=>C,Camera:()=>D,DOWN:()=>Rt,EASE_IN:()=>jt,EASE_IN_OUT:()=>qt,EASE_OUT:()=>Gt,ELASTIC_IN:()=>Jt,ELASTIC_IN_OUT:()=>vt,ELASTIC_OUT:()=>Qt,Grid:()=>T,LEFT:()=>Xt,LINEAR:()=>nt,Noise:()=>R,ONE:()=>kt,RIGHT:()=>St,TypedGrid:()=>B,UP:()=>Ct,Vector:()=>y,ZERO:()=>Z,advance:()=>et,diff:()=>J,dist:()=>at,flipImage:()=>pt,fract:()=>v,intersection:()=>w,mag:()=>it,mod:()=>rt,range:()=>tt,resolve:()=>N,round:()=>st,scaleImage:()=>ct,tint:()=>lt,tween:()=>Ft,vec:()=>n,vecAbs:()=>Ut,vecAdd:()=>A,vecAngle:()=>It,vecAngleBetween:()=>wt,vecCeil:()=>Bt,vecClamp:()=>Pt,vecCross:()=>Tt,vecDist:()=>yt,vecDist2:()=>Et,vecDiv:()=>L,vecDot:()=>$,vecEq:()=>V,vecFloor:()=>Vt,vecIsZero:()=>Ot,vecLerp:()=>Lt,vecLimit:()=>Dt,vecMag:()=>G,vecMag2:()=>q,vecMove:()=>Ht,vecMult:()=>E,vecNorm:()=>H,vecRand:()=>Mt,vecReflect:()=>xt,vecRotate:()=>dt,vecRound:()=>At,vecSet:()=>j,vecSetMag:()=>gt,vecSub:()=>P,wave:()=>Q});var w=(e,t,r,s,a,i,o,h)=>{let u=Math.max(e,a),b=Math.min(e+r,a+o)-u,c=Math.max(t,i),d=Math.min(t+s,i+h)-c;return[u,c,b,d]};var N=(e,t,r,s,a,i,o,h)=>{let[u,b,c,d]=w(e,t,r,s,a,i,o,h),_="",g=e,l=t;return c<d?e<a?(_="right",g=a-r):(_="left",g=a+o):t<i?(_="bottom",l=i-s):(_="top",l=i+h),{direction:_,x:g,y:l}};var D=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,r=0,s=0,a=null,i=null){this._engine=t||globalThis,this.ox=r,this.oy=s,this.resize(a||this._engine.WIDTH-r,i||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(t,r){this.width=t,this.height=r,this._engine.emit("camera-resized",this)}start(t=!1){if(this._engine.push(),t){let a=path();a.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(a)}let r=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(r,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,r){this.x=t,this.y=r}move(t,r){this.x+=t,this.y+=r}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,r=(r-this.height/2-this.oy)/this.scale,s.x=a*t-i*r+this.x,s.y=i*t+a*r+this.y,s}getCameraPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=t-this.x,r=r-this.y,t=a*t-i*r,r=i*t+a*r,s.x=t*this.scale+this.width/2+this.ox,s.y=r*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,r,s,a){let i=this.width/2-this.x,o=this.height/2-this.y,h=this.width/this.scale,u=this.height/this.scale;return this._engine.colrect(t,r,s,a,i,o,h,u)}shake(t=1,r=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),r-=s,r<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var T=class e{_w;_h;_c;constructor(t,r,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~r),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new e(this._w,this._h,this._c)}clear(){this.forEach((t,r)=>this.set(t,r,void 0))}get width(){return this._w}get height(){return this._h}set(t,r,s){this._c[this.pointToIndex(t,r)]=s}get(t,r){return this._c[this.pointToIndex(t,r)]}has(t,r){return this.get(t,r)!=null}check(t,r){return t>=0&&t<this._w&&r>=0&&r<this._h}get length(){return this._w*this._h}pointToIndex(t,r){return this.clampX(~~t)+this.clampY(~~r)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,r=!1){let s=r?this.length-1:0,a=r?-1:this.length,i=r?-1:1;for(;s!==a;){let o=this.indexToPointX(s),h=this.indexToPointY(s),u=this._c[s];if(t(o,h,u,this)===!1)break;s+=i}}fill(t){this.forEach((r,s)=>{this.set(r,s,t)})}clampX(t){return W(t,0,this._w-1)}clampY(t){return W(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",r=!0){if(!r)return this._c.join(t);let s=[];return this.forEach((a,i,o)=>{s[i]=s[i]||"",s[i]+=o+t}),s.join(`
2
+ `)}},B=class e extends T{constructor(t,r,s=Uint8Array){super(t,r,null),this._c=new s(this._w*this._h)}has(t,r){return this.get(t,r)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((r,s,a)=>{t.set(r,s,a)}),t}};function W(e,t,r){return e<t?t:e>r?r:e}var _t=Math.sqrt,z=Math.cos,F=Math.sin,bt=2*Math.PI,y=class{x;y;constructor(t=0,r=t){this.x=t,this.y=r}toString(){return`Vector (${this.x}, ${this.y})`}},x=e=>e instanceof y,n=(e=0,t=e)=>(x(e)&&(t=e.y,e=e.x),new y(e,t)),V=(e,t,r=t)=>x(t)?V(e,t.x,t.y):e.x===t&&e.y===r,j=(e,t,r=t)=>(x(t)?j(e,t.x,t.y):(e.x=t,e.y=r),e),A=(e,t,r=t)=>x(t)?A(e,t.x,t.y):(e.x+=t,e.y+=r,e),P=(e,t,r=t)=>x(t)?P(e,t.x,t.y):(e.x-=t,e.y-=r,e),E=(e,t,r=t)=>x(t)?E(e,t.x,t.y):(e.x*=t,e.y*=r,e),L=(e,t,r=t)=>x(t)?L(e,t.x,t.y):(e.x/=t||1,e.y/=r||1,e),dt=(e,t)=>{let r=z(t),s=F(t);return e.x=r*e.x-s*e.y,e.y=s*e.x+r*e.y,e},xt=(e,t)=>{let r=H(n(t));return P(e,E(r,2*$(e,r)))},gt=(e,t)=>(H(e),E(e,t),e),G=e=>Math.hypot(e.x,e.y),q=e=>e.x*e.x+e.y*e.y,H=e=>{let t=G(e);return t>0&&L(e,t),e},Dt=(e,t=1)=>{let r=q(e);return r>t*t&&(L(e,_t(r)),E(e,t)),e},yt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Et=(e,t)=>{let r=e.x-t.x,s=e.y-t.y;return r*r+s*s},It=e=>Math.atan2(e.y,e.x),wt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),$=(e,t)=>e.x*t.x+e.y*t.y,Tt=(e,t)=>e.x*t.y-e.y*t.x,Lt=(e,t,r)=>(e.x+=(t.x-e.x)*r||0,e.y+=(t.y-e.y)*r||0,e),Mt=(e=1,t=e,r=globalThis.rand||Math.random)=>{let s=r()*bt,a=r()*(t-e)+e;return n(z(s)*a,F(s)*a)},Ut=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Bt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Vt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),At=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Pt=(e,t,r)=>(e.x<t.x&&(e.x=t.x),e.x>r.x&&(e.x=r.x),e.y<t.y&&(e.y=t.y),e.y>r.y&&(e.y=r.y),e),Ht=(e,t,r=1)=>A(e,t.x*r,t.y*r),Ot=e=>V(e,Z),Z=n(0,0),kt=n(1,1),Ct=n(0,-1),St=n(1,0),Rt=n(0,1),Xt=n(-1,0);var Yt=n(.5,.5),K=n(0,0),Nt=n(1,0),Wt=n(0,1),zt=n(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,r,s=K){this.sprite=t,this.pos=r||n(0),this._o=n(s),this._s=n(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,r=t){this._s.x=t,this._s.y=r}scaleBy(t,r=t){this._s.x*=t,this._s.y*=r}getBounds(t=!0){let r=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),a=this.pos.x-r*this.anchor.x,i=this.pos.y-s*this.anchor.y;return[a,i,r,s]}draw(t=globalThis,r=!0){this.hidden||this.opacity<=0||(r&&t.push(),this.transform(t),this.drawImage(t),r&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,r=!0){let s=this.anchor,a=-this.sprite.width*(this.flipX?1-s.x:s.x),i=-this.sprite.height*(this.flipY?1-s.y:s.y);r&&t.alpha(this.opacity),t.image(a,i,this.sprite)}};var J=(e,t)=>Math.abs(t-e)||0;var Q=(e,t,r,s=Math.sin)=>e+(s(r)+1)/2*(t-e);var v=e=>e%1||0;var tt=e=>Array.from(Array(e).keys());var et=advance=(e,t,r,s=1)=>{r&&(t.x+=r.x*s,t.y+=r.y*s),e.x+=t.x*s,e.y+=t.y*s};var rt=(e,t)=>(t+e%t)%t;var st=(e,t)=>{if(!t)return Math.round(e);let r=Math.pow(10,t);return Math.round(e*r)/r};var at=(e,t,r,s)=>Math.hypot(r-e,s-t);var it=(e,t)=>Math.hypot(e,t);var M=Math.PI/2,Ft=(e,t,r,s=1,a=nt)=>new k(e,t,r,s,a),nt=e=>e,jt=e=>e*e,Gt=e=>-e*(e-2),qt=e=>e<.5?2*e*e:-2*e*e+4*e-1,$t=e=>e*e*e-e*Math.sin(e*Math.PI),Zt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},Kt=e=>{if(e<.5){let r=2*e;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},Jt=e=>Math.sin(13*M*e)*Math.pow(2,10*(e-1)),Qt=e=>Math.sin(-13*M*(e+1))*Math.pow(2,-10*e)+1,vt=e=>{if(e<.5){let s=Math.sin(13*M*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*s*a}let t=Math.sin(-13*M*(2*e-1+1)),r=Math.pow(2,-10*(2*e-1));return .5*(t*r+2)},ot=e=>1-C(1-e),C=e=>e<4/11?121*e*e/16:e<8/11?363/40*e*e-99/10*e+17/5:e<9/10?4356/361*e*e-35442/1805*e+16061/1805:54/5*e*e-513/25*e+268/25,te=e=>e<.5?.5*ot(e*2):.5*C(e*2-1)+.5,k=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,r,s,a,i){this._o=t,this._p=r,this._x=s,this._d=a,this._e=i,this._w=0}start(t){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,s=this._rel?r+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",a=>{if(this._t<=this._w){this._t+=a;return}let i=this._t-this._w;this._o[this._p]=this._lc.lerp(r,s,this._e(i/this._d)),this._t+=a,i>=this._d&&(this._o[this._p]=s,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let r of this._cb)r(this._o);return this}restart(t=null,r=!1){return this.stop(r).restart(t)}onEnd(t){return this._cb.push(t),this}chain(t){return this._ch.onEnd(()=>{this._cu=t.start(this._lc)}),this._ch=t,this}reset(){return this._cb.length=0,this.stop()}relative(t=!0){return this._rel=t,this}delay(t){return this._w=t,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};var ht=4,U=1<<ht,ut=8,ee=1<<ut,f=4095,S=e=>.5*(1-Math.cos(e*Math.PI)),R=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,r=0,s=0){t<0&&(t=-t),r<0&&(r=-r),s<0&&(s=-s);let a=Math.floor(t),i=Math.floor(r),o=Math.floor(s),h=t-a,u=r-i,b=s-o,c,d,_=0,g=.5,l,p,I;for(let Y=0;Y<this._po;Y++){let m=a+(i<<ht)+(o<<ut);c=S(h),d=S(u),l=this._p[m&f],l+=c*(this._p[m+1&f]-l),p=this._p[m+U&f],p+=c*(this._p[m+U+1&f]-p),l+=d*(p-l),m+=ee,p=this._p[m&f],p+=c*(this._p[m+1&f]-p),I=this._p[m+U&f],I+=c*(this._p[m+U+1&f]-I),p+=d*(I-p),l+=S(b)*(p-l),_+=l*g,g*=this._pf,a<<=1,h*=2,i<<=1,u*=2,o<<=1,b*=2,h>=1&&(a++,h--),u>=1&&(i++,u--),b>=1&&(o++,b--)}return _}noiseDetail(t,r){t>0&&(this._po=t),r>0&&(this._pf=r)}noiseSeed(t=null){t!=null&&this._e.seed(t);let r=this._e.rand||Math.random;for(let s=0;s<f+1;s++)this._p[s]=r()}};var lt=(e,t,r=1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.alpha(r),s.rectfill(0,0,e.width,e.height,t),a.globalCompositeOperation="destination-atop",s.alpha(1),s.image(0,0,e),s.pop()});var ct=(e,t,r=!0,s=globalThis)=>s.paint(e.width*t,e.height*t,a=>{s.push(),a.imageSmoothingEnabled=!r,s.scale(t),s.image(0,0,e),s.pop()});var pt=(e,t=!0,r=!1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.scale(t?-1:1,r?-1:1),s.image(t?-e.width:0,r?-e.height:0,e),s.pop()});globalThis.utils=Object.assign(globalThis.utils||{},X);})();
3
3
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/grid.js CHANGED
@@ -15,8 +15,8 @@
15
15
  };
16
16
 
17
17
  // src/grid/index.js
18
- var grid_exports = {};
19
- __export(grid_exports, {
18
+ var index_exports = {};
19
+ __export(index_exports, {
20
20
  Grid: () => Grid,
21
21
  TypedGrid: () => TypedGrid
22
22
  });
@@ -250,5 +250,5 @@
250
250
  }
251
251
 
252
252
  // src/grid/_web.js
253
- globalThis.utils = Object.assign(globalThis.utils || {}, grid_exports);
253
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
254
254
  })();
package/dist/image.js CHANGED
@@ -21,8 +21,8 @@
21
21
  });
22
22
  };
23
23
 
24
- // src/image/scale-image.js
25
- var scale_image_default = (img, factor, pixelart = true, engine = globalThis) => {
24
+ // src/image/scale.js
25
+ var scale_default = (img, factor, pixelart = true, engine = globalThis) => {
26
26
  return engine.paint(img.width * factor, img.height * factor, (ctx) => {
27
27
  engine.push();
28
28
  ctx.imageSmoothingEnabled = !pixelart;
@@ -32,9 +32,20 @@
32
32
  });
33
33
  };
34
34
 
35
+ // src/image/flip.js
36
+ var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => {
37
+ return engine.paint(img.width, img.height, (ctx) => {
38
+ engine.push();
39
+ engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1);
40
+ engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img);
41
+ engine.pop();
42
+ });
43
+ };
44
+
35
45
  // src/image/_web.js
36
46
  globalThis.utils = Object.assign(globalThis.utils || {}, {
37
47
  tint: tint_default,
38
- scaleImage: scale_image_default
48
+ scaleImage: scale_default,
49
+ flipImage: flip_default
39
50
  });
40
51
  })();
package/dist/image.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var n=(t,a,o=1,e=globalThis)=>e.paint(t.width,t.height,l=>{e.push(),e.alpha(o),e.rectfill(0,0,t.width,t.height,a),l.globalCompositeOperation="destination-atop",e.alpha(1),e.image(0,0,t),e.pop()});var i=(t,a,o=!0,e=globalThis)=>e.paint(t.width*a,t.height*a,l=>{e.push(),l.imageSmoothingEnabled=!o,e.scale(a),e.image(0,0,t),e.pop()});globalThis.utils=Object.assign(globalThis.utils||{},{tint:n,scaleImage:i});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var s=(e,a,r=1,t=globalThis)=>t.paint(e.width,e.height,n=>{t.push(),t.alpha(r),t.rectfill(0,0,e.width,e.height,a),n.globalCompositeOperation="destination-atop",t.alpha(1),t.image(0,0,e),t.pop()});var i=(e,a,r=!0,t=globalThis)=>t.paint(e.width*a,e.height*a,n=>{t.push(),n.imageSmoothingEnabled=!r,t.scale(a),t.image(0,0,e),t.pop()});var u=(e,a=!0,r=!1,t=globalThis)=>t.paint(e.width,e.height,n=>{t.push(),t.scale(a?-1:1,r?-1:1),t.image(a?-e.width:0,r?-e.height:0,e),t.pop()});globalThis.utils=Object.assign(globalThis.utils||{},{tint:s,scaleImage:i,flipImage:u});})();
package/dist/math.js CHANGED
@@ -15,13 +15,16 @@
15
15
  };
16
16
 
17
17
  // src/math/index.js
18
- var math_exports = {};
19
- __export(math_exports, {
18
+ var index_exports = {};
19
+ __export(index_exports, {
20
20
  advance: () => advance_default,
21
21
  diff: () => diff_default,
22
+ dist: () => dist_default,
22
23
  fract: () => fract_default,
24
+ mag: () => mag_default,
23
25
  mod: () => mod_default,
24
26
  range: () => range_default,
27
+ round: () => round_default,
25
28
  wave: () => wave_default
26
29
  });
27
30
 
@@ -53,6 +56,25 @@
53
56
  // src/math/mod.js
54
57
  var mod_default = (a, b) => (b + a % b) % b;
55
58
 
59
+ // src/math/round.js
60
+ var round_default = (n, decimals) => {
61
+ if (!decimals) {
62
+ return Math.round(n);
63
+ }
64
+ const multiplier = Math.pow(10, decimals);
65
+ return Math.round(n * multiplier) / multiplier;
66
+ };
67
+
68
+ // src/math/dist.js
69
+ var dist_default = (x1, y1, x2, y2) => {
70
+ return Math.hypot(x2 - x1, y2 - y1);
71
+ };
72
+
73
+ // src/math/mag.js
74
+ var mag_default = (x, y) => {
75
+ return Math.hypot(x, y);
76
+ };
77
+
56
78
  // src/math/_web.js
57
- globalThis.utils = Object.assign(globalThis.utils || {}, math_exports);
79
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
58
80
  })();
package/dist/math.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var p=Object.defineProperty;var l=(t,o)=>{for(var r in o)p(t,r,{get:o[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var s={};l(s,{advance:()=>a,diff:()=>n,fract:()=>x,mod:()=>u,range:()=>y,wave:()=>c});var n=(t,o)=>Math.abs(o-t)||0;var c=(t,o,r,e=Math.sin)=>t+(e(r)+1)/2*(o-t);var x=t=>t%1||0;var y=t=>Array.from(Array(t).keys());var g=2*Math.PI;var a=advance=(t,o,r,e=1)=>{r&&(o.x+=r.x*e,o.y+=r.y*e),t.x+=o.x*e,t.y+=o.y*e};var u=(t,o)=>(o+t%o)%o;globalThis.utils=Object.assign(globalThis.utils||{},s);})();
1
+ (()=>{var i=Object.defineProperty;var h=(t,r)=>{for(var o in r)i(t,o,{get:r[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var s={};h(s,{advance:()=>u,diff:()=>n,dist:()=>f,fract:()=>x,mag:()=>l,mod:()=>p,range:()=>a,round:()=>y,wave:()=>c});var n=(t,r)=>Math.abs(r-t)||0;var c=(t,r,o,e=Math.sin)=>t+(e(o)+1)/2*(r-t);var x=t=>t%1||0;var a=t=>Array.from(Array(t).keys());var T=2*Math.PI;var u=advance=(t,r,o,e=1)=>{o&&(r.x+=o.x*e,r.y+=o.y*e),t.x+=r.x*e,t.y+=r.y*e};var p=(t,r)=>(r+t%r)%r;var y=(t,r)=>{if(!r)return Math.round(t);let o=Math.pow(10,r);return Math.round(t*o)/o};var f=(t,r,o,e)=>Math.hypot(o-t,e-r);var l=(t,r)=>Math.hypot(t,r);globalThis.utils=Object.assign(globalThis.utils||{},s);})();
package/dist/noise.js CHANGED
@@ -15,8 +15,8 @@
15
15
  };
16
16
 
17
17
  // src/noise/index.js
18
- var noise_exports = {};
19
- __export(noise_exports, {
18
+ var index_exports = {};
19
+ __export(index_exports, {
20
20
  Noise: () => Noise
21
21
  });
22
22
  var PERLIN_YWRAPB = 4;
@@ -149,5 +149,5 @@
149
149
  };
150
150
 
151
151
  // src/noise/_web.js
152
- globalThis.utils = Object.assign(globalThis.utils || {}, noise_exports);
152
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
153
153
  })();
package/dist/noise.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var D=Object.defineProperty;var H=(s,e)=>{for(var t in e)D(s,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let s in globalThis.utils)s!=="global"&&(globalThis[s]=globalThis.utils[s])};var b={};H(b,{Noise:()=>E});var I=4,_=1<<I,v=8,S=1<<v,a=4095,T=s=>.5*(1-Math.cos(s*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,n=0){e<0&&(e=-e),t<0&&(t=-t),n<0&&(n=-n);let c=Math.floor(e),f=Math.floor(t),u=Math.floor(n),p=e-c,h=t-f,d=n-u,r,m,y=0,x=.5,l,o,g;for(let w=0;w<this._po;w++){let i=c+(f<<I)+(u<<v);r=T(p),m=T(h),l=this._p[i&a],l+=r*(this._p[i+1&a]-l),o=this._p[i+_&a],o+=r*(this._p[i+_+1&a]-o),l+=m*(o-l),i+=S,o=this._p[i&a],o+=r*(this._p[i+1&a]-o),g=this._p[i+_&a],g+=r*(this._p[i+_+1&a]-g),o+=m*(g-o),l+=T(d)*(o-l),y+=l*x,x*=this._pf,c<<=1,p*=2,f<<=1,h*=2,u<<=1,d*=2,p>=1&&(c++,p--),h>=1&&(f++,h--),d>=1&&(u++,d--)}return y}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.seed(e);let t=this._e.rand||Math.random;for(let n=0;n<a+1;n++)this._p[n]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},b);})();
1
+ (()=>{var T=Object.defineProperty;var y=(i,e)=>{for(var t in e)T(i,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let i in globalThis.utils)i!=="global"&&(globalThis[i]=globalThis.utils[i])};var g={};y(g,{Noise:()=>E});var B=4,h=1<<B,V=8,v=1<<V,s=4095,_=i=>.5*(1-Math.cos(i*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,r=0){e<0&&(e=-e),t<0&&(t=-t),r<0&&(r=-r);let o=Math.floor(e),l=Math.floor(t),p=Math.floor(r),f=e-o,b=t-l,c=r-p,m,D,I=0,L=.5,u,a,d;for(let U=0;U<this._po;U++){let n=o+(l<<B)+(p<<V);m=_(f),D=_(b),u=this._p[n&s],u+=m*(this._p[n+1&s]-u),a=this._p[n+h&s],a+=m*(this._p[n+h+1&s]-a),u+=D*(a-u),n+=v,a=this._p[n&s],a+=m*(this._p[n+1&s]-a),d=this._p[n+h&s],d+=m*(this._p[n+h+1&s]-d),a+=D*(d-a),u+=_(c)*(a-u),I+=u*L,L*=this._pf,o<<=1,f*=2,l<<=1,b*=2,p<<=1,c*=2,f>=1&&(o++,f--),b>=1&&(l++,b--),c>=1&&(p++,c--)}return I}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.seed(e);let t=this._e.rand||Math.random;for(let r=0;r<s+1;r++)this._p[r]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},g);})();
package/dist/tween.js CHANGED
@@ -15,8 +15,8 @@
15
15
  };
16
16
 
17
17
  // src/tween/index.js
18
- var tween_exports = {};
19
- __export(tween_exports, {
18
+ var index_exports = {};
19
+ __export(index_exports, {
20
20
  BACK_IN: () => BACK_IN,
21
21
  BACK_IN_OUT: () => BACK_IN_OUT,
22
22
  BACK_OUT: () => BACK_OUT,
@@ -250,5 +250,5 @@
250
250
  };
251
251
 
252
252
  // src/tween/_web.js
253
- globalThis.utils = Object.assign(globalThis.utils || {}, tween_exports);
253
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
254
254
  })();
package/dist/tween.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var f=Object.defineProperty;var p=(t,e)=>{for(var s in e)f(t,s,{get:e[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var c={};p(c,{BACK_IN:()=>E,BACK_IN_OUT:()=>m,BACK_OUT:()=>x,BOUNCE_IN:()=>h,BOUNCE_IN_OUT:()=>y,BOUNCE_OUT:()=>l,EASE_IN:()=>d,EASE_IN_OUT:()=>T,EASE_OUT:()=>g,ELASTIC_IN:()=>b,ELASTIC_IN_OUT:()=>I,ELASTIC_OUT:()=>w,LINEAR:()=>u,tween:()=>_});var n=Math.PI/2,_=(t,e,s,i=1,r=u)=>new a(t,e,s,i,r),u=t=>t,d=t=>t*t,g=t=>-t*(t-2),T=t=>t<.5?2*t*t:-2*t*t+4*t-1,E=t=>t*t*t-t*Math.sin(t*Math.PI),x=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},m=t=>{if(t<.5){let s=2*t;return .5*(s*s*s-s*Math.sin(s*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},b=t=>Math.sin(13*n*t)*Math.pow(2,10*(t-1)),w=t=>Math.sin(-13*n*(t+1))*Math.pow(2,-10*t)+1,I=t=>{if(t<.5){let i=Math.sin(13*n*(2*t)),r=Math.pow(2,10*(2*t-1));return .5*i*r}let e=Math.sin(-13*n*(2*t-1+1)),s=Math.pow(2,-10*(2*t-1));return .5*(e*s+2)},h=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,y=t=>t<.5?.5*h(t*2):.5*l(t*2-1)+.5,a=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(e,s,i,r,o){this._o=e,this._p=s,this._x=i,this._d=r,this._e=o,this._w=0}start(e){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let s=this._o[this._p]||0,i=this._rel?s+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",r=>{if(this._t<=this._w){this._t+=r;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,i,this._e(o/this._d)),this._t+=r,o>=this._d&&(this._o[this._p]=i,this.stop())}),this}stop(e=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,e)for(let s of this._cb)s(this._o);return this}restart(e=null,s=!1){return this.stop(s).restart(e)}onEnd(e){return this._cb.push(e),this}chain(e){return this._ch.onEnd(()=>{this._cu=e.start(this._lc)}),this._ch=e,this}reset(){return this._cb.length=0,this.stop()}relative(e=!0){return this._rel=e,this}delay(e){return this._w=e,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};globalThis.utils=Object.assign(globalThis.utils||{},c);})();
1
+ (()=>{var c=Object.defineProperty;var f=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var o={};f(o,{BACK_IN:()=>D,BACK_IN_OUT:()=>g,BACK_OUT:()=>E,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>T,BOUNCE_OUT:()=>m,EASE_IN:()=>h,EASE_IN_OUT:()=>d,EASE_OUT:()=>_,ELASTIC_IN:()=>I,ELASTIC_IN_OUT:()=>U,ELASTIC_OUT:()=>L,LINEAR:()=>l,tween:()=>b});var i=Math.PI/2,b=(t,e,r,a=1,s=l)=>new u(t,e,r,a,s),l=t=>t,h=t=>t*t,_=t=>-t*(t-2),d=t=>t<.5?2*t*t:-2*t*t+4*t-1,D=t=>t*t*t-t*Math.sin(t*Math.PI),E=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},g=t=>{if(t<.5){let r=2*t;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},I=t=>Math.sin(13*i*t)*Math.pow(2,10*(t-1)),L=t=>Math.sin(-13*i*(t+1))*Math.pow(2,-10*t)+1,U=t=>{if(t<.5){let a=Math.sin(13*i*(2*t)),s=Math.pow(2,10*(2*t-1));return .5*a*s}let e=Math.sin(-13*i*(2*t-1+1)),r=Math.pow(2,-10*(2*t-1));return .5*(e*r+2)},p=t=>1-m(1-t),m=t=>t<4/11?121*t*t/16:t<8/11?363/40*t*t-99/10*t+17/5:t<9/10?4356/361*t*t-35442/1805*t+16061/1805:54/5*t*t-513/25*t+268/25,T=t=>t<.5?.5*p(t*2):.5*m(t*2-1)+.5,u=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(e,r,a,s,n){this._o=e,this._p=r,this._x=a,this._d=s,this._e=n,this._w=0}start(e){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,a=this._rel?r+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",s=>{if(this._t<=this._w){this._t+=s;return}let n=this._t-this._w;this._o[this._p]=this._lc.lerp(r,a,this._e(n/this._d)),this._t+=s,n>=this._d&&(this._o[this._p]=a,this.stop())}),this}stop(e=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,e)for(let r of this._cb)r(this._o);return this}restart(e=null,r=!1){return this.stop(r).restart(e)}onEnd(e){return this._cb.push(e),this}chain(e){return this._ch.onEnd(()=>{this._cu=e.start(this._lc)}),this._ch=e,this}reset(){return this._cb.length=0,this.stop()}relative(e=!0){return this._rel=e,this}delay(e){return this._w=e,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};globalThis.utils=Object.assign(globalThis.utils||{},o);})();
package/dist/vector.js CHANGED
@@ -6,8 +6,8 @@
6
6
  };
7
7
 
8
8
  // src/vector/index.js
9
- var vector_exports = {};
10
- __export(vector_exports, {
9
+ var index_exports = {};
10
+ __export(index_exports, {
11
11
  DOWN: () => DOWN,
12
12
  LEFT: () => LEFT,
13
13
  ONE: () => ONE,
@@ -139,7 +139,7 @@
139
139
  vecMult(v, value);
140
140
  return v;
141
141
  };
142
- var vecMag = (v) => sqrt(v.x * v.x + v.y * v.y);
142
+ var vecMag = (v) => Math.hypot(v.x, v.y);
143
143
  var vecMag2 = (v) => v.x * v.x + v.y * v.y;
144
144
  var vecNorm = (v) => {
145
145
  const length = vecMag(v);
@@ -157,9 +157,7 @@
157
157
  return v;
158
158
  };
159
159
  var vecDist = (a, b) => {
160
- const dx = a.x - b.x;
161
- const dy = a.y - b.y;
162
- return sqrt(dx * dx + dy * dy);
160
+ return Math.hypot(b.x - a.x, b.y - a.y);
163
161
  };
164
162
  var vecDist2 = (a, b) => {
165
163
  const dx = a.x - b.x;
@@ -217,5 +215,5 @@
217
215
  var LEFT = /* @__PURE__ */ vec(-1, 0);
218
216
 
219
217
  // src/vector/_web.js
220
- globalThis.utils = Object.assign(globalThis.utils || {}, vector_exports);
218
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
221
219
  })();
@@ -1 +1 @@
1
- (()=>{var A=Object.defineProperty;var C=(t,e)=>{for(var o in e)A(t,o,{get:e[o],enumerable:!0})};var h={};C(h,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>q,vec:()=>c,vecAbs:()=>j,vecAdd:()=>i,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>B,vecClamp:()=>H,vecCross:()=>U,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>y,vecDot:()=>T,vecEq:()=>u,vecFloor:()=>F,vecIsZero:()=>W,vecLerp:()=>Z,vecLimit:()=>b,vecMag:()=>R,vecMag2:()=>D,vecMove:()=>V,vecMult:()=>x,vecNorm:()=>l,vecRand:()=>$,vecReflect:()=>O,vecRotate:()=>I,vecRound:()=>G,vecSet:()=>g,vecSetMag:()=>S,vecSub:()=>a});var p=Math.sqrt,f=Math.cos,d=Math.sin,E=2*Math.PI,s=class{x;y;constructor(e=0,o=e){this.x=e,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof s,c=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new s(t,e)),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):t.x===e&&t.y===o,g=(t,e,o=e)=>(n(e)?g(t,e.x,e.y):(t.x=e,t.y=o),t),i=(t,e,o=e)=>n(e)?i(t,e.x,e.y):(t.x+=e,t.y+=o,t),a=(t,e,o=e)=>n(e)?a(t,e.x,e.y):(t.x-=e,t.y-=o,t),x=(t,e,o=e)=>n(e)?x(t,e.x,e.y):(t.x*=e,t.y*=o,t),y=(t,e,o=e)=>n(e)?y(t,e.x,e.y):(t.x/=e||1,t.y/=o||1,t),I=(t,e)=>{let o=f(e),r=d(e);return t.x=o*t.x-r*t.y,t.y=r*t.x+o*t.y,t},O=(t,e)=>{let o=l(c(e));return a(t,x(o,2*T(t,o)))},S=(t,e)=>(l(t),x(t,e),t),R=t=>p(t.x*t.x+t.y*t.y),D=t=>t.x*t.x+t.y*t.y,l=t=>{let e=R(t);return e>0&&y(t,e),t},b=(t,e=1)=>{let o=D(t);return o>e*e&&(y(t,p(o)),x(t,e)),t},L=(t,e)=>{let o=t.x-e.x,r=t.y-e.y;return p(o*o+r*r)},N=(t,e)=>{let o=t.x-e.x,r=t.y-e.y;return o*o+r*r},P=t=>Math.atan2(t.y,t.x),w=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),T=(t,e)=>t.x*e.x+t.y*e.y,U=(t,e)=>t.x*e.y-t.y*e.x,Z=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),$=(t=1,e=t,o=globalThis.rand||Math.random)=>{let r=o()*E,M=o()*(e-t)+t;return c(f(r)*M,d(r)*M)},j=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),B=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),F=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),G=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),H=(t,e,o)=>(t.x<e.x&&(t.x=e.x),t.x>o.x&&(t.x=o.x),t.y<e.y&&(t.y=e.y),t.y>o.y&&(t.y=o.y),t),V=(t,e,o=1)=>i(t,e.x*o,e.y*o),W=t=>u(t,q),q=c(0,0),k=c(1,1),z=c(0,-1),J=c(1,0),K=c(0,1),Q=c(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},h);})();
1
+ (()=>{var q=Object.defineProperty;var A=(t,e)=>{for(var o in e)q(t,o,{get:e[o],enumerable:!0})};var a={};A(a,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>T,vec:()=>r,vecAbs:()=>j,vecAdd:()=>u,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>B,vecClamp:()=>H,vecCross:()=>U,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>x,vecDot:()=>D,vecEq:()=>p,vecFloor:()=>F,vecIsZero:()=>W,vecLerp:()=>Z,vecLimit:()=>b,vecMag:()=>d,vecMag2:()=>R,vecMove:()=>V,vecMult:()=>y,vecNorm:()=>h,vecRand:()=>$,vecReflect:()=>O,vecRotate:()=>I,vecRound:()=>G,vecSet:()=>g,vecSetMag:()=>S,vecSub:()=>i});var C=Math.sqrt,M=Math.cos,f=Math.sin,E=2*Math.PI,s=class{x;y;constructor(e=0,o=e){this.x=e,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof s,r=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new s(t,e)),p=(t,e,o=e)=>n(e)?p(t,e.x,e.y):t.x===e&&t.y===o,g=(t,e,o=e)=>(n(e)?g(t,e.x,e.y):(t.x=e,t.y=o),t),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):(t.x+=e,t.y+=o,t),i=(t,e,o=e)=>n(e)?i(t,e.x,e.y):(t.x-=e,t.y-=o,t),y=(t,e,o=e)=>n(e)?y(t,e.x,e.y):(t.x*=e,t.y*=o,t),x=(t,e,o=e)=>n(e)?x(t,e.x,e.y):(t.x/=e||1,t.y/=o||1,t),I=(t,e)=>{let o=M(e),c=f(e);return t.x=o*t.x-c*t.y,t.y=c*t.x+o*t.y,t},O=(t,e)=>{let o=h(r(e));return i(t,y(o,2*D(t,o)))},S=(t,e)=>(h(t),y(t,e),t),d=t=>Math.hypot(t.x,t.y),R=t=>t.x*t.x+t.y*t.y,h=t=>{let e=d(t);return e>0&&x(t,e),t},b=(t,e=1)=>{let o=R(t);return o>e*e&&(x(t,C(o)),y(t,e)),t},L=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),N=(t,e)=>{let o=t.x-e.x,c=t.y-e.y;return o*o+c*c},P=t=>Math.atan2(t.y,t.x),w=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),D=(t,e)=>t.x*e.x+t.y*e.y,U=(t,e)=>t.x*e.y-t.y*e.x,Z=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),$=(t=1,e=t,o=globalThis.rand||Math.random)=>{let c=o()*E,l=o()*(e-t)+t;return r(M(c)*l,f(c)*l)},j=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),B=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),F=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),G=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),H=(t,e,o)=>(t.x<e.x&&(t.x=e.x),t.x>o.x&&(t.x=o.x),t.y<e.y&&(t.y=e.y),t.y>o.y&&(t.y=o.y),t),V=(t,e,o=1)=>u(t,e.x*o,e.y*o),W=t=>p(t,T),T=r(0,0),k=r(1,1),z=r(0,-1),J=r(1,0),K=r(0,1),Q=r(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},a);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
@@ -34,11 +34,11 @@
34
34
  "dist"
35
35
  ],
36
36
  "peerDependencies": {
37
- "litecanvas": "*"
37
+ "litecanvas": "latest"
38
38
  },
39
39
  "devDependencies": {
40
- "esbuild": "^0.23.1",
40
+ "esbuild": "^0.25.0",
41
41
  "gzip-size": "^7.0.0",
42
- "prettier": "^3.3.3"
42
+ "prettier": "^3.5.2"
43
43
  }
44
44
  }
@@ -14,11 +14,11 @@ litecanvas({
14
14
  loop: { init, tapped, draw },
15
15
  })
16
16
 
17
- // create a sprite image
17
+ // lets create a image to our actor
18
18
  mySprite = paint(3, 3, ["303", "030", "303"], { scale: 10 })
19
19
 
20
20
  function init() {
21
- // create a actor
21
+ // create a actor and pass its image
22
22
  player = new Actor(mySprite)
23
23
  }
24
24
 
@@ -42,9 +42,12 @@ Set or get the actor position vector
42
42
 
43
43
  ```js
44
44
  player.pos.x = 100
45
- player.pos.x = 200
45
+ player.pos.y = 200
46
46
  ```
47
47
 
48
+ > Note:
49
+ > The `player.pos` is a [Vector](https://github.com/litecanvas/utils/blob/main/src/vector/README.md) instance.
50
+
48
51
  ## Actor#x / Actor#y
49
52
 
50
53
  Set or get the actor position X or Y
@@ -99,15 +102,12 @@ If `true` the actor sprite is flipped vertically. Default is `false`.
99
102
  Set or get the actor anchor (origin). By default, the anchor is a vector `(0, 0)` (meaning anchor Top Left).
100
103
 
101
104
  ```js
102
- // position the sprite based on their center
105
+ // example: actor position based on their center
103
106
  player.anchor.x = 0.5
104
107
  player.anchor.y = 0.5
105
- ```
106
108
 
107
- ```js
108
- // alternatively
109
+ // or...
109
110
  import { ANCHOR_CENTER } from "@litecanvas/utils"
110
-
111
111
  player.anchor = ANCHOR_CENTER
112
112
  ```
113
113
 
@@ -173,4 +173,4 @@ player.sprite = anotherSprite
173
173
 
174
174
  > The actor sprite must be a `Image`, `HTMLCanvas` or `OffscreenCanvas`.
175
175
  >
176
- > Remember, you can create a image using the litecanvas' `paint()` built-in helper or [load a image](https://github.com/litecanvas/plugin-asset-loader?tab=readme-ov-file#loading-images) with plugins.
176
+ > Remember, you can create a image using the litecanvas' `paint()` built-in helper or [load a image](https://github.com/litecanvas/plugin-asset-loader?tab=readme-ov-file#loading-images).
@@ -8,6 +8,10 @@
8
8
  import { litecanvas } from "litecanvas"
9
9
  import { Camera } from "@litecanvas/utils"
10
10
 
11
+ litecanvas({
12
+ loop: { init, draw }
13
+ })
14
+
11
15
  function init() {
12
16
  camera = new Camera()
13
17
  }
@@ -17,11 +21,11 @@ function draw() {
17
21
 
18
22
  camera.start()
19
23
 
20
- // draw your game objects here
24
+ // draw your dynamic game objects here (player, enemies, tilemap, etc)
21
25
 
22
26
  camera.end()
23
27
 
24
- // draw your UI here
28
+ // draw your UI here (score, lifes, etc)
25
29
  }
26
30
  ```
27
31
 
@@ -43,7 +47,7 @@ function draw() {
43
47
 
44
48
  Apply the camera transformations (move, zoom and rotate). You must call this method before draw anything inside of the camera.
45
49
 
46
- ### stop()
50
+ ### end()
47
51
 
48
52
  Stop looking through the camera. You must call this method after draw anything inside of the camera.
49
53
 
package/src/image/_web.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import "../_global.js"
2
2
  import tint from "./tint.js"
3
- import scaleImage from "./scale-image.js"
3
+ import scaleImage from "./scale.js"
4
+ import flipImage from "./flip.js"
4
5
 
5
6
  globalThis.utils = Object.assign(globalThis.utils || {}, {
6
7
  tint,
7
8
  scaleImage,
9
+ flipImage,
8
10
  })
@@ -0,0 +1,23 @@
1
+ import "litecanvas"
2
+
3
+ /**
4
+ * Flip a image with a color and optional opacity.
5
+ *
6
+ * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} img
7
+ * @param {boolean} [horizontal=true]
8
+ * @param {boolean} [vertically=false]
9
+ * @param {LitecanvasInstance} [engine]
10
+ */
11
+ export default (
12
+ img,
13
+ horizontal = true,
14
+ vertically = false,
15
+ engine = globalThis
16
+ ) => {
17
+ return engine.paint(img.width, img.height, (ctx) => {
18
+ engine.push()
19
+ engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1)
20
+ engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img)
21
+ engine.pop()
22
+ })
23
+ }
package/src/index.js CHANGED
@@ -8,4 +8,5 @@ export * from "./math/index.js"
8
8
  export * from "./tween/index.js"
9
9
  export * from "./noise/index.js"
10
10
  export { default as tint } from "./image/tint.js"
11
- export { default as scaleImage } from "./image/scale-image.js"
11
+ export { default as scaleImage } from "./image/scale.js"
12
+ export { default as flipImage } from "./image/flip.js"
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Calculates the distance between a point (x1, y1) to another (x2, y2).
3
+ *
4
+ * @param {number} x1
5
+ * @param {number} y1
6
+ * @param {number} x2
7
+ * @param {number} y2
8
+ * @returns {number}
9
+ */
10
+ export default (x1, y1, x2, y2) => {
11
+ return Math.hypot(x2 - x1, y2 - y1)
12
+ }
package/src/math/index.js CHANGED
@@ -4,3 +4,6 @@ export { default as fract } from "./fract.js"
4
4
  export { default as range } from "./range.js"
5
5
  export { default as advance } from "./advance.js"
6
6
  export { default as mod } from "./mod.js"
7
+ export { default as round } from "./round.js"
8
+ export { default as dist } from "./dist.js"
9
+ export { default as mag } from "./mag.js"
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Calculates the magnitude (length) of a vector (x, y).
3
+ *
4
+ * @param {number} x
5
+ * @param {number} y
6
+ * @returns {number} magnitude of vector.
7
+ */
8
+ export default (x, y) => {
9
+ return Math.hypot(x, y)
10
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Calculates the integer closest to a number.
3
+ *
4
+ * @param {number} n number to round.
5
+ * @param {number} [decimals] number of decimal places to round to, default is 0.
6
+ * @returns {number} rounded number.
7
+ */
8
+ export default (n, decimals) => {
9
+ if (!decimals) {
10
+ return Math.round(n)
11
+ }
12
+ const multiplier = Math.pow(10, decimals)
13
+ return Math.round(n * multiplier) / multiplier
14
+ }
@@ -205,7 +205,7 @@ export const vecSetMag = (v, value) => {
205
205
  * @param {Vector} v
206
206
  * @returns {number}
207
207
  */
208
- export const vecMag = (v) => sqrt(v.x * v.x + v.y * v.y)
208
+ export const vecMag = (v) => Math.hypot(v.x, v.y)
209
209
 
210
210
  /**
211
211
  * Calculates the magnitude (length) of the vector squared.
@@ -253,9 +253,7 @@ export const vecLimit = (v, max = 1) => {
253
253
  * @returns {number}
254
254
  */
255
255
  export const vecDist = (a, b) => {
256
- const dx = a.x - b.x
257
- const dy = a.y - b.y
258
- return sqrt(dx * dx + dy * dy)
256
+ return Math.hypot(b.x - a.x, b.y - a.y)
259
257
  }
260
258
 
261
259
  /**
File without changes