@litecanvas/utils 0.28.0 → 0.29.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
@@ -51,4 +51,5 @@ const pos = vec(0, 0)
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
53
  - **Image** to manipulate images. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/image)
54
+ - **Collection** to manipulate lists (arrays). [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/collection)
54
55
  - And some [math utilities](https://github.com/litecanvas/utils/tree/main/src/math)...
package/dist/actor.js CHANGED
@@ -10,7 +10,7 @@
10
10
  globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- if (overrides || globalThis[key] !== void 0) {
13
+ if (overrides || globalThis[key] === void 0) {
14
14
  globalThis[key] = globalThis.utils[key];
15
15
  }
16
16
  }
package/dist/actor.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var c=Object.defineProperty;var l=(r,t)=>{for(var e in t)c(r,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let t in globalThis.utils)t!=="global"&&(r||globalThis[t]!==void 0)&&(globalThis[t]=globalThis.utils[t])};var m={};l(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>D,ANCHOR_CENTER:()=>b,ANCHOR_TOP_LEFT:()=>p,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>u});var _=2*Math.PI,n=class{x;y;constructor(t=0,e=t){this.x=t,this.y=e}toString(){return`Vector (${this.x}, ${this.y})`}},f=r=>r instanceof n,s=(r=0,t=r)=>(f(r)&&(t=r.y,r=r.x),new n(r,t));var b=s(.5,.5),p=s(0,0),h=s(1,0),d=s(0,1),D=s(1,1),u=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,a=p){this.sprite=t,this.pos=e||s(0),this._o=s(a),this._s=s(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,e=t){this._s.x=t,this._s.y=e}scaleBy(t,e=t){this._s.x*=t,this._s.y*=e}getBounds(t=!0){let e=this.sprite.width*(t?this._s.x:1),a=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,o=this.pos.y-a*this.anchor.y;return[i,o,e,a]}draw(t=globalThis,e=!0){this.hidden||this.opacity<=0||(e&&t.push(),this.transform(t),this.drawImage(t),e&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,e=!0){let a=this.anchor,i=-this.sprite.width*(this.flipX?1-a.x:a.x),o=-this.sprite.height*(this.flipY?1-a.y:a.y);e&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
1
+ (()=>{var l=Object.defineProperty;var c=(r,t)=>{for(var e in t)l(r,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let t in globalThis.utils)t!=="global"&&(r||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var m={};c(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>y,ANCHOR_CENTER:()=>f,ANCHOR_TOP_LEFT:()=>p,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>u});var x=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})`}},b=r=>r instanceof n,s=(r=0,t=r)=>(b(r)&&(t=r.y,r=r.x),new n(r,t));var f=s(.5,.5),p=s(0,0),h=s(1,0),d=s(0,1),y=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),o=this.pos.x-e*this.anchor.x,i=this.pos.y-a*this.anchor.y;return[o,i,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,o=-this.sprite.width*(this.flipX?1-a.x:a.x),i=-this.sprite.height*(this.flipY?1-a.y:a.y);e&&t.alpha(this.opacity),t.image(o,i,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
package/dist/all.js CHANGED
@@ -10,7 +10,7 @@
10
10
  globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- if (overrides || globalThis[key] !== void 0) {
13
+ if (overrides || globalThis[key] === void 0) {
14
14
  globalThis[key] = globalThis.utils[key];
15
15
  }
16
16
  }
@@ -54,14 +54,21 @@
54
54
  dist: () => dist_default,
55
55
  flipImage: () => flip_default,
56
56
  fract: () => fract_default,
57
+ head: () => head_default,
57
58
  intersection: () => intersection_default,
59
+ last: () => last_default,
58
60
  mag: () => mag_default,
61
+ mean: () => mean_default,
59
62
  mod: () => mod_default,
60
63
  range: () => range_default,
61
64
  resolve: () => resolve_default,
62
65
  roundd: () => roundd_default,
66
+ sample: () => sample_default,
63
67
  scaleImage: () => scale_default,
64
- tint: () => tint_default,
68
+ shuffle: () => shuffle_default,
69
+ sum: () => sum_default,
70
+ tail: () => tail_default,
71
+ tintImage: () => tint_default,
65
72
  tween: () => tween,
66
73
  vec: () => vec,
67
74
  vecAbs: () => vecAbs,
@@ -694,9 +701,9 @@
694
701
  a.y += (b.y - a.y) * t || 0;
695
702
  return a;
696
703
  };
697
- var vecRand = (minlength = 1, maxlength = minlength, randomFn = globalThis.rand || Math.random) => {
698
- const angle = randomFn() * PI2;
699
- const radius = randomFn() * (maxlength - minlength) + minlength;
704
+ var vecRand = (minlength = 1, maxlength = minlength, rng = globalThis.rand || Math.random) => {
705
+ const angle = rng() * PI2;
706
+ const radius = rng() * (maxlength - minlength) + minlength;
700
707
  return vec(cos(angle) * radius, sin(angle) * radius);
701
708
  };
702
709
  var vecAbs = (v) => {
@@ -900,9 +907,6 @@
900
907
  // src/math/fract.js
901
908
  var fract_default = (value) => value % 1 || 0;
902
909
 
903
- // src/math/range.js
904
- var range_default = (size) => Array.from(Array(size).keys());
905
-
906
910
  // src/math/advance.js
907
911
  var advance_default = advance = (position, velocity, acceleration, deltaTime = 1) => {
908
912
  if (acceleration) {
@@ -935,6 +939,20 @@
935
939
  return Math.hypot(x, y);
936
940
  };
937
941
 
942
+ // src/math/sum.js
943
+ var sum_default = (values) => {
944
+ let result = 0;
945
+ for (let i = 0; i < values.length; i++) {
946
+ result += values[i];
947
+ }
948
+ return result;
949
+ };
950
+
951
+ // src/math/mean.js
952
+ var mean_default = (values) => {
953
+ return sum_default(values) / values.length;
954
+ };
955
+
938
956
  // src/tween/index.js
939
957
  var HALF_PI = Math.PI / 2;
940
958
  var tween = (object, prop, toValue, duration = 1, easing = LINEAR) => {
@@ -1283,15 +1301,12 @@
1283
1301
  }
1284
1302
  };
1285
1303
 
1286
- // src/image/tint.js
1287
- var tint_default = (img, color, opacity = 1, engine = globalThis) => {
1304
+ // src/image/flip.js
1305
+ var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => {
1288
1306
  return engine.paint(img.width, img.height, (ctx) => {
1289
1307
  engine.push();
1290
- engine.alpha(opacity);
1291
- engine.rectfill(0, 0, img.width, img.height, color);
1292
- ctx.globalCompositeOperation = "destination-atop";
1293
- engine.alpha(1);
1294
- engine.image(0, 0, img);
1308
+ engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1);
1309
+ engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img);
1295
1310
  engine.pop();
1296
1311
  });
1297
1312
  };
@@ -1307,16 +1322,52 @@
1307
1322
  });
1308
1323
  };
1309
1324
 
1310
- // src/image/flip.js
1311
- var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => {
1325
+ // src/image/tint.js
1326
+ var tint_default = (img, color, opacity = 1, engine = globalThis) => {
1312
1327
  return engine.paint(img.width, img.height, (ctx) => {
1313
1328
  engine.push();
1314
- engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1);
1315
- engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img);
1329
+ engine.alpha(opacity);
1330
+ engine.rectfill(0, 0, img.width, img.height, color);
1331
+ ctx.globalCompositeOperation = "destination-atop";
1332
+ engine.alpha(1);
1333
+ engine.image(0, 0, img);
1316
1334
  engine.pop();
1317
1335
  });
1318
1336
  };
1319
1337
 
1338
+ // src/collection/range.js
1339
+ var range_default = (size, from = 0, step = 1) => Array.from(
1340
+ Array(size).keys().map((i) => {
1341
+ return from + step * i;
1342
+ })
1343
+ );
1344
+
1345
+ // src/collection/shuffle.js
1346
+ var shuffle_default = (values, rng = globalThis.rand || Math.random) => {
1347
+ values = Array.from(values);
1348
+ for (let i = values.length - 1; i > 0; i--) {
1349
+ let j = Math.floor(rng() * (i + 1));
1350
+ let temp = values[i];
1351
+ values[i] = values[j];
1352
+ values[j] = temp;
1353
+ }
1354
+ return values;
1355
+ };
1356
+
1357
+ // src/collection/sample.js
1358
+ var sample_default = (values, rng = globalThis.rand || Math.random) => {
1359
+ return values[Math.floor(rng() * values.length)];
1360
+ };
1361
+
1362
+ // src/collection/head.js
1363
+ var head_default = (values) => values[0];
1364
+
1365
+ // src/collection/last.js
1366
+ var last_default = (values) => values[values.length - 1];
1367
+
1368
+ // src/collection/tail.js
1369
+ var tail_default = (values) => values.slice(1);
1370
+
1320
1371
  // src/_web.js
1321
1372
  globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
1322
1373
  })();
package/dist/all.min.js CHANGED
@@ -1,3 +1,3 @@
1
- (()=>{var mt=Object.defineProperty;var ft=(e,t)=>{for(var r in t)mt(e,r,{get:t[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let t in globalThis.utils)t!=="global"&&(e||globalThis[t]!==void 0)&&(globalThis[t]=globalThis.utils[t])};var X={};ft(X,{ANCHOR_BOT_LEFT:()=>Wt,ANCHOR_BOT_RIGHT:()=>zt,ANCHOR_CENTER:()=>Yt,ANCHOR_TOP_LEFT:()=>K,ANCHOR_TOP_RIGHT:()=>Nt,Actor:()=>O,BACK_IN:()=>$t,BACK_IN_OUT:()=>Kt,BACK_OUT:()=>Zt,BOUNCE_IN:()=>ot,BOUNCE_IN_OUT:()=>te,BOUNCE_OUT:()=>C,Camera:()=>D,DOWN:()=>Rt,EASE_IN:()=>jt,EASE_IN_OUT:()=>qt,EASE_OUT:()=>Gt,ELASTIC_IN:()=>Jt,ELASTIC_IN_OUT:()=>vt,ELASTIC_OUT:()=>Qt,Grid:()=>w,LEFT:()=>Xt,LINEAR:()=>nt,Noise:()=>R,ONE:()=>kt,RIGHT:()=>St,TypedGrid:()=>B,UP:()=>Ct,Vector:()=>y,ZERO:()=>Z,advance:()=>et,diff:()=>J,dist:()=>at,flipImage:()=>pt,fract:()=>v,intersection:()=>T,mag:()=>it,mod:()=>rt,range:()=>tt,resolve:()=>N,roundd:()=>st,scaleImage:()=>ct,tint:()=>lt,tween:()=>Ft,vec:()=>n,vecAbs:()=>Ut,vecAdd:()=>A,vecAngle:()=>It,vecAngleBetween:()=>Tt,vecCeil:()=>Bt,vecClamp:()=>Pt,vecCross:()=>wt,vecDist:()=>yt,vecDist2:()=>Et,vecDiv:()=>L,vecDot:()=>$,vecEq:()=>V,vecFloor:()=>Vt,vecIsZero:()=>Ot,vecLerp:()=>Lt,vecLimit:()=>Dt,vecMag:()=>G,vecMag2:()=>q,vecMove:()=>Ht,vecMult:()=>E,vecNorm:()=>H,vecRand:()=>Mt,vecReflect:()=>xt,vecRotate:()=>dt,vecRound:()=>At,vecSet:()=>j,vecSetMag:()=>gt,vecSub:()=>P,wave:()=>Q});var T=(e,t,r,s,a,i,o,h)=>{let u=Math.max(e,a),b=Math.min(e+r,a+o)-u,c=Math.max(t,i),d=Math.min(t+s,i+h)-c;return[u,c,b,d]};var N=(e,t,r,s,a,i,o,h)=>{let[u,b,c,d]=T(e,t,r,s,a,i,o,h),_="",g=e,l=t;return c<d?e<a?(_="right",g=a-r):(_="left",g=a+o):t<i?(_="bottom",l=i-s):(_="top",l=i+h),{direction:_,x:g,y:l}};var D=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,r=0,s=0,a=null,i=null){this._engine=t||globalThis,this.ox=r,this.oy=s,this.resize(a||this._engine.WIDTH-r,i||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(t,r){this.width=t,this.height=r,this._engine.emit("camera-resized",this)}start(t=!1){if(this._engine.push(),t){let a=path();a.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(a)}let r=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(r,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,r){this.x=t,this.y=r}move(t,r){this.x+=t,this.y+=r}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,r=(r-this.height/2-this.oy)/this.scale,s.x=a*t-i*r+this.x,s.y=i*t+a*r+this.y,s}getCameraPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=t-this.x,r=r-this.y,t=a*t-i*r,r=i*t+a*r,s.x=t*this.scale+this.width/2+this.ox,s.y=r*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,r,s,a){let i=this.width/2-this.x,o=this.height/2-this.y,h=this.width/this.scale,u=this.height/this.scale;return this._engine.colrect(t,r,s,a,i,o,h,u)}shake(t=1,r=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),r-=s,r<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var w=class e{_w;_h;_c;constructor(t,r,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~r),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new e(this._w,this._h,this._c)}clear(){this.forEach((t,r)=>this.set(t,r,void 0))}get width(){return this._w}get height(){return this._h}set(t,r,s){this._c[this.pointToIndex(t,r)]=s}get(t,r){return this._c[this.pointToIndex(t,r)]}has(t,r){return this.get(t,r)!=null}check(t,r){return t>=0&&t<this._w&&r>=0&&r<this._h}get length(){return this._w*this._h}pointToIndex(t,r){return this.clampX(~~t)+this.clampY(~~r)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,r=!1){let s=r?this.length-1:0,a=r?-1:this.length,i=r?-1:1;for(;s!==a;){let o=this.indexToPointX(s),h=this.indexToPointY(s),u=this._c[s];if(t(o,h,u,this)===!1)break;s+=i}}fill(t){this.forEach((r,s)=>{this.set(r,s,t)})}clampX(t){return W(t,0,this._w-1)}clampY(t){return W(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",r=!0){if(!r)return this._c.join(t);let s=[];return this.forEach((a,i,o)=>{s[i]=s[i]||"",s[i]+=o+t}),s.join(`
2
- `)}},B=class e extends w{constructor(t,r,s=Uint8Array){super(t,r,null),this._c=new s(this._w*this._h)}has(t,r){return this.get(t,r)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((r,s,a)=>{t.set(r,s,a)}),t}};function W(e,t,r){return e<t?t:e>r?r:e}var _t=Math.sqrt,z=Math.cos,F=Math.sin,bt=2*Math.PI,y=class{x;y;constructor(t=0,r=t){this.x=t,this.y=r}toString(){return`Vector (${this.x}, ${this.y})`}},x=e=>e instanceof y,n=(e=0,t=e)=>(x(e)&&(t=e.y,e=e.x),new y(e,t)),V=(e,t,r=t)=>x(t)?V(e,t.x,t.y):e.x===t&&e.y===r,j=(e,t,r=t)=>(x(t)?j(e,t.x,t.y):(e.x=t,e.y=r),e),A=(e,t,r=t)=>x(t)?A(e,t.x,t.y):(e.x+=t,e.y+=r,e),P=(e,t,r=t)=>x(t)?P(e,t.x,t.y):(e.x-=t,e.y-=r,e),E=(e,t,r=t)=>x(t)?E(e,t.x,t.y):(e.x*=t,e.y*=r,e),L=(e,t,r=t)=>x(t)?L(e,t.x,t.y):(e.x/=t||1,e.y/=r||1,e),dt=(e,t)=>{let r=z(t),s=F(t);return e.x=r*e.x-s*e.y,e.y=s*e.x+r*e.y,e},xt=(e,t)=>{let r=H(n(t));return P(e,E(r,2*$(e,r)))},gt=(e,t)=>(H(e),E(e,t),e),G=e=>Math.hypot(e.x,e.y),q=e=>e.x*e.x+e.y*e.y,H=e=>{let t=G(e);return t>0&&L(e,t),e},Dt=(e,t=1)=>{let r=q(e);return r>t*t&&(L(e,_t(r)),E(e,t)),e},yt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Et=(e,t)=>{let r=e.x-t.x,s=e.y-t.y;return r*r+s*s},It=e=>Math.atan2(e.y,e.x),Tt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),$=(e,t)=>e.x*t.x+e.y*t.y,wt=(e,t)=>e.x*t.y-e.y*t.x,Lt=(e,t,r)=>(e.x+=(t.x-e.x)*r||0,e.y+=(t.y-e.y)*r||0,e),Mt=(e=1,t=e,r=globalThis.rand||Math.random)=>{let s=r()*bt,a=r()*(t-e)+e;return n(z(s)*a,F(s)*a)},Ut=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Bt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Vt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),At=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Pt=(e,t,r)=>(e.x<t.x&&(e.x=t.x),e.x>r.x&&(e.x=r.x),e.y<t.y&&(e.y=t.y),e.y>r.y&&(e.y=r.y),e),Ht=(e,t,r=1)=>A(e,t.x*r,t.y*r),Ot=e=>V(e,Z),Z=n(0,0),kt=n(1,1),Ct=n(0,-1),St=n(1,0),Rt=n(0,1),Xt=n(-1,0);var Yt=n(.5,.5),K=n(0,0),Nt=n(1,0),Wt=n(0,1),zt=n(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,r,s=K){this.sprite=t,this.pos=r||n(0),this._o=n(s),this._s=n(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,r=t){this._s.x=t,this._s.y=r}scaleBy(t,r=t){this._s.x*=t,this._s.y*=r}getBounds(t=!0){let r=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),a=this.pos.x-r*this.anchor.x,i=this.pos.y-s*this.anchor.y;return[a,i,r,s]}draw(t=globalThis,r=!0){this.hidden||this.opacity<=0||(r&&t.push(),this.transform(t),this.drawImage(t),r&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,r=!0){let s=this.anchor,a=-this.sprite.width*(this.flipX?1-s.x:s.x),i=-this.sprite.height*(this.flipY?1-s.y:s.y);r&&t.alpha(this.opacity),t.image(a,i,this.sprite)}};var J=(e,t)=>Math.abs(t-e)||0;var Q=(e,t,r,s=Math.sin)=>e+(s(r)+1)/2*(t-e);var v=e=>e%1||0;var tt=e=>Array.from(Array(e).keys());var et=advance=(e,t,r,s=1)=>{r&&(t.x+=r.x*s,t.y+=r.y*s),e.x+=t.x*s,e.y+=t.y*s};var rt=(e,t)=>(t+e%t)%t;var st=(e,t=0)=>{if(!t)return Math.round(e);let r=Math.pow(10,t);return Math.round(e*r)/r};var at=(e,t,r,s)=>Math.hypot(r-e,s-t);var it=(e,t)=>Math.hypot(e,t);var M=Math.PI/2,Ft=(e,t,r,s=1,a=nt)=>new k(e,t,r,s,a),nt=e=>e,jt=e=>e*e,Gt=e=>-e*(e-2),qt=e=>e<.5?2*e*e:-2*e*e+4*e-1,$t=e=>e*e*e-e*Math.sin(e*Math.PI),Zt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},Kt=e=>{if(e<.5){let r=2*e;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},Jt=e=>Math.sin(13*M*e)*Math.pow(2,10*(e-1)),Qt=e=>Math.sin(-13*M*(e+1))*Math.pow(2,-10*e)+1,vt=e=>{if(e<.5){let s=Math.sin(13*M*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*s*a}let t=Math.sin(-13*M*(2*e-1+1)),r=Math.pow(2,-10*(2*e-1));return .5*(t*r+2)},ot=e=>1-C(1-e),C=e=>e<4/11?121*e*e/16:e<8/11?363/40*e*e-99/10*e+17/5:e<9/10?4356/361*e*e-35442/1805*e+16061/1805:54/5*e*e-513/25*e+268/25,te=e=>e<.5?.5*ot(e*2):.5*C(e*2-1)+.5,k=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,r,s,a,i){this._o=t,this._p=r,this._x=s,this._d=a,this._e=i,this._w=0}start(t){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,s=this._rel?r+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",a=>{if(this._t<=this._w){this._t+=a;return}let i=this._t-this._w;this._o[this._p]=this._lc.lerp(r,s,this._e(i/this._d)),this._t+=a,i>=this._d&&(this._o[this._p]=s,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let r of this._cb)r(this._o);return this}restart(t=null,r=!1){return this.stop(r).restart(t)}onEnd(t){return this._cb.push(t),this}chain(t){return this._ch.onEnd(()=>{this._cu=t.start(this._lc)}),this._ch=t,this}reset(){return this._cb.length=0,this.stop()}relative(t=!0){return this._rel=t,this}delay(t){return this._w=t,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};var ht=4,U=1<<ht,ut=8,ee=1<<ut,f=4095,S=e=>.5*(1-Math.cos(e*Math.PI)),R=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,r=0,s=0){t<0&&(t=-t),r<0&&(r=-r),s<0&&(s=-s);let a=Math.floor(t),i=Math.floor(r),o=Math.floor(s),h=t-a,u=r-i,b=s-o,c,d,_=0,g=.5,l,p,I;for(let Y=0;Y<this._po;Y++){let m=a+(i<<ht)+(o<<ut);c=S(h),d=S(u),l=this._p[m&f],l+=c*(this._p[m+1&f]-l),p=this._p[m+U&f],p+=c*(this._p[m+U+1&f]-p),l+=d*(p-l),m+=ee,p=this._p[m&f],p+=c*(this._p[m+1&f]-p),I=this._p[m+U&f],I+=c*(this._p[m+U+1&f]-I),p+=d*(I-p),l+=S(b)*(p-l),_+=l*g,g*=this._pf,a<<=1,h*=2,i<<=1,u*=2,o<<=1,b*=2,h>=1&&(a++,h--),u>=1&&(i++,u--),b>=1&&(o++,b--)}return _}noiseDetail(t,r){t>0&&(this._po=t),r>0&&(this._pf=r)}noiseSeed(t=null){t!=null&&this._e.seed(t);let r=this._e.rand||Math.random;for(let s=0;s<f+1;s++)this._p[s]=r()}};var lt=(e,t,r=1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.alpha(r),s.rectfill(0,0,e.width,e.height,t),a.globalCompositeOperation="destination-atop",s.alpha(1),s.image(0,0,e),s.pop()});var ct=(e,t,r=!0,s=globalThis)=>s.paint(e.width*t,e.height*t,a=>{s.push(),a.imageSmoothingEnabled=!r,s.scale(t),s.image(0,0,e),s.pop()});var pt=(e,t=!0,r=!1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.scale(t?-1:1,r?-1:1),s.image(t?-e.width:0,r?-e.height:0,e),s.pop()});globalThis.utils=Object.assign(globalThis.utils||{},X);})();
1
+ (()=>{var yt=Object.defineProperty;var wt=(e,t)=>{for(var r in t)yt(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 F={};wt(F,{ANCHOR_BOT_LEFT:()=>Zt,ANCHOR_BOT_RIGHT:()=>Kt,ANCHOR_CENTER:()=>Vt,ANCHOR_TOP_LEFT:()=>Q,ANCHOR_TOP_RIGHT:()=>$t,Actor:()=>R,BACK_IN:()=>ee,BACK_IN_OUT:()=>se,BACK_OUT:()=>re,BOUNCE_IN:()=>ht,BOUNCE_IN_OUT:()=>oe,BOUNCE_OUT:()=>Y,Camera:()=>y,DOWN:()=>jt,EASE_IN:()=>Jt,EASE_IN_OUT:()=>te,EASE_OUT:()=>vt,ELASTIC_IN:()=>ae,ELASTIC_IN_OUT:()=>ie,ELASTIC_OUT:()=>ne,Grid:()=>I,LEFT:()=>qt,LINEAR:()=>ot,Noise:()=>X,ONE:()=>Bt,RIGHT:()=>Gt,TypedGrid:()=>P,UP:()=>zt,Vector:()=>w,ZERO:()=>K,advance:()=>et,diff:()=>J,dist:()=>at,flipImage:()=>pt,fract:()=>tt,head:()=>_t,intersection:()=>E,last:()=>xt,mag:()=>nt,mean:()=>it,mod:()=>rt,range:()=>ft,resolve:()=>B,roundd:()=>st,sample:()=>dt,scaleImage:()=>ct,shuffle:()=>bt,sum:()=>H,tail:()=>gt,tintImage:()=>mt,tween:()=>Qt,vec:()=>i,vecAbs:()=>Rt,vecAdd:()=>D,vecAngle:()=>Pt,vecAngleBetween:()=>Ct,vecCeil:()=>Nt,vecClamp:()=>Xt,vecCross:()=>Dt,vecDist:()=>kt,vecDist2:()=>Ot,vecDiv:()=>A,vecDot:()=>Z,vecEq:()=>C,vecFloor:()=>Yt,vecIsZero:()=>Ut,vecLerp:()=>Lt,vecLimit:()=>Ht,vecMag:()=>V,vecMag2:()=>$,vecMove:()=>Ft,vecMult:()=>T,vecNorm:()=>S,vecRand:()=>St,vecReflect:()=>It,vecRotate:()=>Et,vecRound:()=>Wt,vecSet:()=>q,vecSetMag:()=>At,vecSub:()=>L,wave:()=>v});var E=(e,t,r,s,a,n,o,h)=>{let u=Math.max(e,a),d=Math.min(e+r,a+o)-u,p=Math.max(t,n),_=Math.min(t+s,n+h)-p;return[u,p,d,_]};var B=(e,t,r,s,a,n,o,h)=>{let[u,d,p,_]=E(e,t,r,s,a,n,o,h),b="",g=e,l=t;return p<_?e<a?(b="right",g=a-r):(b="left",g=a+o):t<n?(b="bottom",l=n-s):(b="top",l=n+h),{direction:b,x:g,y:l}};var y=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,n=null){this._engine=t||globalThis,this.ox=r,this.oy=s,this.resize(a||this._engine.WIDTH-r,n||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),n=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-n*r+this.x,s.y=n*t+a*r+this.y,s}getCameraPoint(t,r,s={}){let a=Math.cos(-this.rotation),n=Math.sin(-this.rotation);return t=t-this.x,r=r-this.y,t=a*t-n*r,r=n*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 n=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,n,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 I=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,n=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+=n}}fill(t){this.forEach((r,s)=>{this.set(r,s,t)})}clampX(t){return z(t,0,this._w-1)}clampY(t){return z(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,n,o)=>{s[n]=s[n]||"",s[n]+=o+t}),s.join(`
2
+ `)}},P=class e extends I{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 z(e,t,r){return e<t?t:e>r?r:e}var Tt=Math.sqrt,G=Math.cos,j=Math.sin,Mt=2*Math.PI,w=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 w,i=(e=0,t=e)=>(x(e)&&(t=e.y,e=e.x),new w(e,t)),C=(e,t,r=t)=>x(t)?C(e,t.x,t.y):e.x===t&&e.y===r,q=(e,t,r=t)=>(x(t)?q(e,t.x,t.y):(e.x=t,e.y=r),e),D=(e,t,r=t)=>x(t)?D(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,e.y-=r,e),T=(e,t,r=t)=>x(t)?T(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||1,e.y/=r||1,e),Et=(e,t)=>{let r=G(t),s=j(t);return e.x=r*e.x-s*e.y,e.y=s*e.x+r*e.y,e},It=(e,t)=>{let r=S(i(t));return L(e,T(r,2*Z(e,r)))},At=(e,t)=>(S(e),T(e,t),e),V=e=>Math.hypot(e.x,e.y),$=e=>e.x*e.x+e.y*e.y,S=e=>{let t=V(e);return t>0&&A(e,t),e},Ht=(e,t=1)=>{let r=$(e);return r>t*t&&(A(e,Tt(r)),T(e,t)),e},kt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Ot=(e,t)=>{let r=e.x-t.x,s=e.y-t.y;return r*r+s*s},Pt=e=>Math.atan2(e.y,e.x),Ct=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),Z=(e,t)=>e.x*t.x+e.y*t.y,Dt=(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),St=(e=1,t=e,r=globalThis.rand||Math.random)=>{let s=r()*Mt,a=r()*(t-e)+e;return i(G(s)*a,j(s)*a)},Rt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Nt=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),Wt=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Xt=(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),Ft=(e,t,r=1)=>D(e,t.x*r,t.y*r),Ut=e=>C(e,K),K=i(0,0),Bt=i(1,1),zt=i(0,-1),Gt=i(1,0),jt=i(0,1),qt=i(-1,0);var Vt=i(.5,.5),Q=i(0,0),$t=i(1,0),Zt=i(0,1),Kt=i(1,1),R=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,r,s=Q){this.sprite=t,this.pos=r||i(0),this._o=i(s),this._s=i(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,n=this.pos.y-s*this.anchor.y;return[a,n,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),n=-this.sprite.height*(this.flipY?1-s.y:s.y);r&&t.alpha(this.opacity),t.image(a,n,this.sprite)}};var J=(e,t)=>Math.abs(t-e)||0;var v=(e,t,r,s=Math.sin)=>e+(s(r)+1)/2*(t-e);var tt=e=>e%1||0;var et=advance=(e,t,r,s=1)=>{r&&(t.x+=r.x*s,t.y+=r.y*s),e.x+=t.x*s,e.y+=t.y*s};var rt=(e,t)=>(t+e%t)%t;var st=(e,t=0)=>{if(!t)return Math.round(e);let r=Math.pow(10,t);return Math.round(e*r)/r};var at=(e,t,r,s)=>Math.hypot(r-e,s-t);var nt=(e,t)=>Math.hypot(e,t);var H=e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t};var it=e=>H(e)/e.length;var k=Math.PI/2,Qt=(e,t,r,s=1,a=ot)=>new N(e,t,r,s,a),ot=e=>e,Jt=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),re=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},se=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},ae=e=>Math.sin(13*k*e)*Math.pow(2,10*(e-1)),ne=e=>Math.sin(-13*k*(e+1))*Math.pow(2,-10*e)+1,ie=e=>{if(e<.5){let s=Math.sin(13*k*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*s*a}let t=Math.sin(-13*k*(2*e-1+1)),r=Math.pow(2,-10*(2*e-1));return .5*(t*r+2)},ht=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,oe=e=>e<.5?.5*ht(e*2):.5*Y(e*2-1)+.5,N=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,n){this._o=t,this._p=r,this._x=s,this._d=a,this._e=n,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 n=this._t-this._w;this._o[this._p]=this._lc.lerp(r,s,this._e(n/this._d)),this._t+=a,n>=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 ut=4,O=1<<ut,lt=8,he=1<<lt,f=4095,W=e=>.5*(1-Math.cos(e*Math.PI)),X=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),n=Math.floor(r),o=Math.floor(s),h=t-a,u=r-n,d=s-o,p,_,b=0,g=.5,l,c,M;for(let U=0;U<this._po;U++){let m=a+(n<<ut)+(o<<lt);p=W(h),_=W(u),l=this._p[m&f],l+=p*(this._p[m+1&f]-l),c=this._p[m+O&f],c+=p*(this._p[m+O+1&f]-c),l+=_*(c-l),m+=he,c=this._p[m&f],c+=p*(this._p[m+1&f]-c),M=this._p[m+O&f],M+=p*(this._p[m+O+1&f]-M),c+=_*(M-c),l+=W(d)*(c-l),b+=l*g,g*=this._pf,a<<=1,h*=2,n<<=1,u*=2,o<<=1,d*=2,h>=1&&(a++,h--),u>=1&&(n++,u--),d>=1&&(o++,d--)}return b}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 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()});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 mt=(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 ft=(e,t=0,r=1)=>Array.from(Array(e).keys().map(s=>t+r*s));var bt=(e,t=globalThis.rand||Math.random)=>{e=Array.from(e);for(let r=e.length-1;r>0;r--){let s=Math.floor(t()*(r+1)),a=e[r];e[r]=e[s],e[s]=a}return e};var dt=(e,t=globalThis.rand||Math.random)=>e[Math.floor(t()*e.length)];var _t=e=>e[0];var xt=e=>e[e.length-1];var gt=e=>e.slice(1);globalThis.utils=Object.assign(globalThis.utils||{},F);})();
3
3
  /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/camera.js CHANGED
@@ -4,7 +4,7 @@
4
4
  globalThis.utils.global = (overrides = true) => {
5
5
  for (const key in globalThis.utils) {
6
6
  if ("global" === key) continue;
7
- if (overrides || globalThis[key] !== void 0) {
7
+ if (overrides || globalThis[key] === void 0) {
8
8
  globalThis[key] = globalThis.utils[key];
9
9
  }
10
10
  }
@@ -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;_shake={x:0,y:0,removeListener:null};constructor(i=null,t=0,s=0,h=null,e=null){this._engine=i||globalThis,this.ox=t,this.oy=s,this.resize(h||this._engine.WIDTH-t,e||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(i,t){this.width=i,this.height=t,this._engine.emit("camera-resized",this)}start(i=!1){if(this._engine.push(),i){let h=path();h.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(h)}let t=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(t,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(i,t){this.x=i,this.y=t}move(i,t){this.x+=i,this.y+=t}zoom(i){this.scale*=i}zoomTo(i){this.scale=i}rotate(i){this.rotation+=i}rotateTo(i){this.rotation=i}getWorldPoint(i,t,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return i=(i-this.width/2-this.ox)/this.scale,t=(t-this.height/2-this.oy)/this.scale,s.x=h*i-e*t+this.x,s.y=e*i+h*t+this.y,s}getCameraPoint(i,t,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return i=i-this.x,t=t-this.y,i=h*i-e*t,t=e*i+h*t,s.x=i*this.scale+this.width/2+this.ox,s.y=t*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(i,t,s,h){let e=this.width/2-this.x,a=this.height/2-this.y,l=this.width/this.scale,r=this.height/this.scale;return this._engine.colrect(i,t,s,h,e,a,l,r)}shake(i=1,t=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-i,i),this._shake.y=this._engine.randi(-i,i),t-=s,t<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};globalThis.utils=Object.assign(globalThis.utils||{},{Camera:n});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let i in globalThis.utils)i!=="global"&&(o||globalThis[i]===void 0)&&(globalThis[i]=globalThis.utils[i])};var n=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(i=null,t=0,s=0,h=null,e=null){this._engine=i||globalThis,this.ox=t,this.oy=s,this.resize(h||this._engine.WIDTH-t,e||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(i,t){this.width=i,this.height=t,this._engine.emit("camera-resized",this)}start(i=!1){if(this._engine.push(),i){let h=path();h.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(h)}let t=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(t,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(i,t){this.x=i,this.y=t}move(i,t){this.x+=i,this.y+=t}zoom(i){this.scale*=i}zoomTo(i){this.scale=i}rotate(i){this.rotation+=i}rotateTo(i){this.rotation=i}getWorldPoint(i,t,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return i=(i-this.width/2-this.ox)/this.scale,t=(t-this.height/2-this.oy)/this.scale,s.x=h*i-e*t+this.x,s.y=e*i+h*t+this.y,s}getCameraPoint(i,t,s={}){let h=Math.cos(-this.rotation),e=Math.sin(-this.rotation);return i=i-this.x,t=t-this.y,i=h*i-e*t,t=e*i+h*t,s.x=i*this.scale+this.width/2+this.ox,s.y=t*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(i,t,s,h){let e=this.width/2-this.x,a=this.height/2-this.y,l=this.width/this.scale,r=this.height/this.scale;return this._engine.colrect(i,t,s,h,e,a,l,r)}shake(i=1,t=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-i,i),this._shake.y=this._engine.randi(-i,i),t-=s,t<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};globalThis.utils=Object.assign(globalThis.utils||{},{Camera:n});})();
@@ -0,0 +1,65 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+
8
+ // src/_global.js
9
+ globalThis.utils = globalThis.utils || {};
10
+ globalThis.utils.global = (overrides = true) => {
11
+ for (const key in globalThis.utils) {
12
+ if ("global" === key) continue;
13
+ if (overrides || globalThis[key] === void 0) {
14
+ globalThis[key] = globalThis.utils[key];
15
+ }
16
+ }
17
+ };
18
+
19
+ // src/collection/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ head: () => head_default,
23
+ last: () => last_default,
24
+ range: () => range_default,
25
+ sample: () => sample_default,
26
+ shuffle: () => shuffle_default,
27
+ tail: () => tail_default
28
+ });
29
+
30
+ // src/collection/range.js
31
+ var range_default = (size, from = 0, step = 1) => Array.from(
32
+ Array(size).keys().map((i) => {
33
+ return from + step * i;
34
+ })
35
+ );
36
+
37
+ // src/collection/shuffle.js
38
+ var shuffle_default = (values, rng = globalThis.rand || Math.random) => {
39
+ values = Array.from(values);
40
+ for (let i = values.length - 1; i > 0; i--) {
41
+ let j = Math.floor(rng() * (i + 1));
42
+ let temp = values[i];
43
+ values[i] = values[j];
44
+ values[j] = temp;
45
+ }
46
+ return values;
47
+ };
48
+
49
+ // src/collection/sample.js
50
+ var sample_default = (values, rng = globalThis.rand || Math.random) => {
51
+ return values[Math.floor(rng() * values.length)];
52
+ };
53
+
54
+ // src/collection/head.js
55
+ var head_default = (values) => values[0];
56
+
57
+ // src/collection/last.js
58
+ var last_default = (values) => values[values.length - 1];
59
+
60
+ // src/collection/tail.js
61
+ var tail_default = (values) => values.slice(1);
62
+
63
+ // src/collection/_web.js
64
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
65
+ })();
@@ -0,0 +1 @@
1
+ (()=>{var g=Object.defineProperty;var p=(t,l)=>{for(var o in l)g(t,o,{get:l[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let l in globalThis.utils)l!=="global"&&(t||globalThis[l]===void 0)&&(globalThis[l]=globalThis.utils[l])};var a={};p(a,{head:()=>s,last:()=>h,range:()=>e,sample:()=>f,shuffle:()=>i,tail:()=>d});var e=(t,l=0,o=1)=>Array.from(Array(t).keys().map(r=>l+o*r));var i=(t,l=globalThis.rand||Math.random)=>{t=Array.from(t);for(let o=t.length-1;o>0;o--){let r=Math.floor(l()*(o+1)),n=t[o];t[o]=t[r],t[r]=n}return t};var f=(t,l=globalThis.rand||Math.random)=>t[Math.floor(l()*t.length)];var s=t=>t[0];var h=t=>t[t.length-1];var d=t=>t.slice(1);globalThis.utils=Object.assign(globalThis.utils||{},a);})();
package/dist/collision.js CHANGED
@@ -4,7 +4,7 @@
4
4
  globalThis.utils.global = (overrides = true) => {
5
5
  for (const key in globalThis.utils) {
6
6
  if ("global" === key) continue;
7
- if (overrides || globalThis[key] !== void 0) {
7
+ if (overrides || globalThis[key] === void 0) {
8
8
  globalThis[key] = globalThis.utils[key];
9
9
  }
10
10
  }
@@ -1 +1 @@
1
- (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=(l=!0)=>{for(let t in globalThis.utils)t!=="global"&&(l||globalThis[t]!==void 0)&&(globalThis[t]=globalThis.utils[t])};var f=(l,t,s,r,i,o,n,a)=>{let g=Math.max(l,i),c=Math.min(l+s,i+n)-g,h=Math.max(t,o),u=Math.min(t+r,o+a)-h;return[g,h,c,u]};var p=(l,t,s,r,i,o,n,a)=>{let[g,c,h,u]=f(l,t,s,r,i,o,n,a),e="",b=l,m=t;return h<u?l<i?(e="right",b=i-s):(e="left",b=i+n):t<o?(e="bottom",m=o-r):(e="top",m=o+a),{direction:e,x:b,y:m}};globalThis.utils=Object.assign(globalThis.utils||{},{resolve:p,intersection:f});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=(l=!0)=>{for(let t in globalThis.utils)t!=="global"&&(l||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var f=(l,t,s,r,i,o,n,a)=>{let g=Math.max(l,i),c=Math.min(l+s,i+n)-g,h=Math.max(t,o),u=Math.min(t+r,o+a)-h;return[g,h,c,u]};var p=(l,t,s,r,i,o,n,a)=>{let[g,c,h,u]=f(l,t,s,r,i,o,n,a),e="",b=l,m=t;return h<u?l<i?(e="right",b=i-s):(e="left",b=i+n):t<o?(e="bottom",m=o-r):(e="top",m=o+a),{direction:e,x:b,y:m}};globalThis.utils=Object.assign(globalThis.utils||{},{resolve:p,intersection:f});})();
package/dist/grid.js CHANGED
@@ -10,7 +10,7 @@
10
10
  globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- if (overrides || globalThis[key] !== void 0) {
13
+ if (overrides || globalThis[key] === void 0) {
14
14
  globalThis[key] = globalThis.utils[key];
15
15
  }
16
16
  }
package/dist/grid.min.js CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{var g=Object.defineProperty;var f=(h,t)=>{for(var i in t)g(h,i,{get:t[i],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(h=!0)=>{for(let t in globalThis.utils)t!=="global"&&(h||globalThis[t]!==void 0)&&(globalThis[t]=globalThis.utils[t])};var c={};f(c,{Grid:()=>r,TypedGrid:()=>l});var r=class h{_w;_h;_c;constructor(t,i,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~i),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new h(this._w,this._h,this._c)}clear(){this.forEach((t,i)=>this.set(t,i,void 0))}get width(){return this._w}get height(){return this._h}set(t,i,s){this._c[this.pointToIndex(t,i)]=s}get(t,i){return this._c[this.pointToIndex(t,i)]}has(t,i){return this.get(t,i)!=null}check(t,i){return t>=0&&t<this._w&&i>=0&&i<this._h}get length(){return this._w*this._h}pointToIndex(t,i){return this.clampX(~~t)+this.clampY(~~i)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,i=!1){let s=i?this.length-1:0,e=i?-1:this.length,n=i?-1:1;for(;s!==e;){let o=this.indexToPointX(s),a=this.indexToPointY(s),_=this._c[s];if(t(o,a,_,this)===!1)break;s+=n}}fill(t){this.forEach((i,s)=>{this.set(i,s,t)})}clampX(t){return u(t,0,this._w-1)}clampY(t){return u(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",i=!0){if(!i)return this._c.join(t);let s=[];return this.forEach((e,n,o)=>{s[n]=s[n]||"",s[n]+=o+t}),s.join(`
1
+ (()=>{var g=Object.defineProperty;var f=(h,t)=>{for(var i in t)g(h,i,{get:t[i],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(h=!0)=>{for(let t in globalThis.utils)t!=="global"&&(h||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var c={};f(c,{Grid:()=>r,TypedGrid:()=>l});var r=class h{_w;_h;_c;constructor(t,i,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~i),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new h(this._w,this._h,this._c)}clear(){this.forEach((t,i)=>this.set(t,i,void 0))}get width(){return this._w}get height(){return this._h}set(t,i,s){this._c[this.pointToIndex(t,i)]=s}get(t,i){return this._c[this.pointToIndex(t,i)]}has(t,i){return this.get(t,i)!=null}check(t,i){return t>=0&&t<this._w&&i>=0&&i<this._h}get length(){return this._w*this._h}pointToIndex(t,i){return this.clampX(~~t)+this.clampY(~~i)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,i=!1){let s=i?this.length-1:0,e=i?-1:this.length,n=i?-1:1;for(;s!==e;){let o=this.indexToPointX(s),a=this.indexToPointY(s),_=this._c[s];if(t(o,a,_,this)===!1)break;s+=n}}fill(t){this.forEach((i,s)=>{this.set(i,s,t)})}clampX(t){return u(t,0,this._w-1)}clampY(t){return u(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",i=!0){if(!i)return this._c.join(t);let s=[];return this.forEach((e,n,o)=>{s[n]=s[n]||"",s[n]+=o+t}),s.join(`
2
2
  `)}},l=class h extends r{constructor(t,i,s=Uint8Array){super(t,i,null),this._c=new s(this._w*this._h)}has(t,i){return this.get(t,i)!==0}clone(){let t=new h(this._w,this._h,this._c.constructor);return this.forEach((i,s,e)=>{t.set(i,s,e)}),t}};function u(h,t,i){return h<t?t:h>i?i:h}globalThis.utils=Object.assign(globalThis.utils||{},c);})();
package/dist/image.js CHANGED
@@ -1,24 +1,35 @@
1
1
  (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+
2
8
  // src/_global.js
3
9
  globalThis.utils = globalThis.utils || {};
4
10
  globalThis.utils.global = (overrides = true) => {
5
11
  for (const key in globalThis.utils) {
6
12
  if ("global" === key) continue;
7
- if (overrides || globalThis[key] !== void 0) {
13
+ if (overrides || globalThis[key] === void 0) {
8
14
  globalThis[key] = globalThis.utils[key];
9
15
  }
10
16
  }
11
17
  };
12
18
 
13
- // src/image/tint.js
14
- var tint_default = (img, color, opacity = 1, engine = globalThis) => {
19
+ // src/image/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ flipImage: () => flip_default,
23
+ scaleImage: () => scale_default,
24
+ tintImage: () => tint_default
25
+ });
26
+
27
+ // src/image/flip.js
28
+ var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => {
15
29
  return engine.paint(img.width, img.height, (ctx) => {
16
30
  engine.push();
17
- engine.alpha(opacity);
18
- engine.rectfill(0, 0, img.width, img.height, color);
19
- ctx.globalCompositeOperation = "destination-atop";
20
- engine.alpha(1);
21
- engine.image(0, 0, img);
31
+ engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1);
32
+ engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img);
22
33
  engine.pop();
23
34
  });
24
35
  };
@@ -34,20 +45,19 @@
34
45
  });
35
46
  };
36
47
 
37
- // src/image/flip.js
38
- var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => {
48
+ // src/image/tint.js
49
+ var tint_default = (img, color, opacity = 1, engine = globalThis) => {
39
50
  return engine.paint(img.width, img.height, (ctx) => {
40
51
  engine.push();
41
- engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1);
42
- engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img);
52
+ engine.alpha(opacity);
53
+ engine.rectfill(0, 0, img.width, img.height, color);
54
+ ctx.globalCompositeOperation = "destination-atop";
55
+ engine.alpha(1);
56
+ engine.image(0, 0, img);
43
57
  engine.pop();
44
58
  });
45
59
  };
46
60
 
47
61
  // src/image/_web.js
48
- globalThis.utils = Object.assign(globalThis.utils || {}, {
49
- tint: tint_default,
50
- scaleImage: scale_default,
51
- flipImage: flip_default
52
- });
62
+ globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
53
63
  })();
package/dist/image.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let a in globalThis.utils)a!=="global"&&(t||globalThis[a]!==void 0)&&(globalThis[a]=globalThis.utils[a])};var s=(t,a,r=1,e=globalThis)=>e.paint(t.width,t.height,n=>{e.push(),e.alpha(r),e.rectfill(0,0,t.width,t.height,a),n.globalCompositeOperation="destination-atop",e.alpha(1),e.image(0,0,t),e.pop()});var i=(t,a,r=!0,e=globalThis)=>e.paint(t.width*a,t.height*a,n=>{e.push(),n.imageSmoothingEnabled=!r,e.scale(a),e.image(0,0,t),e.pop()});var u=(t,a=!0,r=!1,e=globalThis)=>e.paint(t.width,t.height,n=>{e.push(),e.scale(a?-1:1,r?-1:1),e.image(a?-t.width:0,r?-t.height:0,t),e.pop()});globalThis.utils=Object.assign(globalThis.utils||{},{tint:s,scaleImage:i,flipImage:u});})();
1
+ (()=>{var o=Object.defineProperty;var l=(e,a)=>{for(var r in a)o(e,r,{get:a[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let a in globalThis.utils)a!=="global"&&(e||globalThis[a]===void 0)&&(globalThis[a]=globalThis.utils[a])};var s={};l(s,{flipImage:()=>u,scaleImage:()=>m,tintImage:()=>i});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()});var m=(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 i=(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()});globalThis.utils=Object.assign(globalThis.utils||{},s);})();
package/dist/math.js CHANGED
@@ -10,7 +10,7 @@
10
10
  globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- if (overrides || globalThis[key] !== void 0) {
13
+ if (overrides || globalThis[key] === void 0) {
14
14
  globalThis[key] = globalThis.utils[key];
15
15
  }
16
16
  }
@@ -24,9 +24,10 @@
24
24
  dist: () => dist_default,
25
25
  fract: () => fract_default,
26
26
  mag: () => mag_default,
27
+ mean: () => mean_default,
27
28
  mod: () => mod_default,
28
- range: () => range_default,
29
29
  roundd: () => roundd_default,
30
+ sum: () => sum_default,
30
31
  wave: () => wave_default
31
32
  });
32
33
 
@@ -39,9 +40,6 @@
39
40
  // src/math/fract.js
40
41
  var fract_default = (value) => value % 1 || 0;
41
42
 
42
- // src/math/range.js
43
- var range_default = (size) => Array.from(Array(size).keys());
44
-
45
43
  // src/vector/index.js
46
44
  var PI2 = 2 * Math.PI;
47
45
 
@@ -77,6 +75,20 @@
77
75
  return Math.hypot(x, y);
78
76
  };
79
77
 
78
+ // src/math/sum.js
79
+ var sum_default = (values) => {
80
+ let result = 0;
81
+ for (let i = 0; i < values.length; i++) {
82
+ result += values[i];
83
+ }
84
+ return result;
85
+ };
86
+
87
+ // src/math/mean.js
88
+ var mean_default = (values) => {
89
+ return sum_default(values) / values.length;
90
+ };
91
+
80
92
  // src/math/_web.js
81
93
  globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
82
94
  })();
package/dist/math.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var i=Object.defineProperty;var h=(r,t)=>{for(var o in t)i(r,o,{get:t[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let t in globalThis.utils)t!=="global"&&(r||globalThis[t]!==void 0)&&(globalThis[t]=globalThis.utils[t])};var s={};h(s,{advance:()=>u,diff:()=>n,dist:()=>f,fract:()=>x,mag:()=>l,mod:()=>p,range:()=>a,roundd:()=>y,wave:()=>c});var n=(r,t)=>Math.abs(t-r)||0;var c=(r,t,o,e=Math.sin)=>r+(e(o)+1)/2*(t-r);var x=r=>r%1||0;var a=r=>Array.from(Array(r).keys());var T=2*Math.PI;var u=advance=(r,t,o,e=1)=>{o&&(t.x+=o.x*e,t.y+=o.y*e),r.x+=t.x*e,r.y+=t.y*e};var p=(r,t)=>(t+r%t)%t;var y=(r,t=0)=>{if(!t)return Math.round(r);let o=Math.pow(10,t);return Math.round(r*o)/o};var f=(r,t,o,e)=>Math.hypot(o-r,e-t);var l=(r,t)=>Math.hypot(r,t);globalThis.utils=Object.assign(globalThis.utils||{},s);})();
1
+ (()=>{var h=Object.defineProperty;var d=(r,t)=>{for(var o in t)h(r,o,{get:t[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let t in globalThis.utils)t!=="global"&&(r||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var n={};d(n,{advance:()=>a,diff:()=>c,dist:()=>f,fract:()=>u,mag:()=>y,mean:()=>i,mod:()=>p,roundd:()=>l,sum:()=>s,wave:()=>x});var c=(r,t)=>Math.abs(t-r)||0;var x=(r,t,o,e=Math.sin)=>r+(e(o)+1)/2*(t-r);var u=r=>r%1||0;var T=2*Math.PI;var a=advance=(r,t,o,e=1)=>{o&&(t.x+=o.x*e,t.y+=o.y*e),r.x+=t.x*e,r.y+=t.y*e};var p=(r,t)=>(t+r%t)%t;var l=(r,t=0)=>{if(!t)return Math.round(r);let o=Math.pow(10,t);return Math.round(r*o)/o};var f=(r,t,o,e)=>Math.hypot(o-r,e-t);var y=(r,t)=>Math.hypot(r,t);var s=r=>{let t=0;for(let o=0;o<r.length;o++)t+=r[o];return t};var i=r=>s(r)/r.length;globalThis.utils=Object.assign(globalThis.utils||{},n);})();
package/dist/noise.js CHANGED
@@ -10,7 +10,7 @@
10
10
  globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- if (overrides || globalThis[key] !== void 0) {
13
+ if (overrides || globalThis[key] === void 0) {
14
14
  globalThis[key] = globalThis.utils[key];
15
15
  }
16
16
  }
package/dist/noise.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var T=Object.defineProperty;var y=(u,e)=>{for(var t in e)T(u,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(u=!0)=>{for(let e in globalThis.utils)e!=="global"&&(u||globalThis[e]!==void 0)&&(globalThis[e]=globalThis.utils[e])};var g={};y(g,{Noise:()=>E});var B=4,h=1<<B,V=8,v=1<<V,s=4095,_=u=>.5*(1-Math.cos(u*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,r=0){e<0&&(e=-e),t<0&&(t=-t),r<0&&(r=-r);let o=Math.floor(e),l=Math.floor(t),p=Math.floor(r),f=e-o,b=t-l,c=r-p,m,D,I=0,L=.5,i,a,d;for(let U=0;U<this._po;U++){let n=o+(l<<B)+(p<<V);m=_(f),D=_(b),i=this._p[n&s],i+=m*(this._p[n+1&s]-i),a=this._p[n+h&s],a+=m*(this._p[n+h+1&s]-a),i+=D*(a-i),n+=v,a=this._p[n&s],a+=m*(this._p[n+1&s]-a),d=this._p[n+h&s],d+=m*(this._p[n+h+1&s]-d),a+=D*(d-a),i+=_(c)*(a-i),I+=i*L,L*=this._pf,o<<=1,f*=2,l<<=1,b*=2,p<<=1,c*=2,f>=1&&(o++,f--),b>=1&&(l++,b--),c>=1&&(p++,c--)}return I}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.seed(e);let t=this._e.rand||Math.random;for(let r=0;r<s+1;r++)this._p[r]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},g);})();
1
+ (()=>{var D=Object.defineProperty;var H=(u,e)=>{for(var t in e)D(u,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(u=!0)=>{for(let e in globalThis.utils)e!=="global"&&(u||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var E={};H(E,{Noise:()=>T});var w=4,h=1<<w,I=8,L=1<<I,s=4095,_=u=>.5*(1-Math.cos(u*Math.PI)),T=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),c=e-o,b=t-l,f=r-p,m,g,v=0,y=.5,i,a,d;for(let A=0;A<this._po;A++){let n=o+(l<<w)+(p<<I);m=_(c),g=_(b),i=this._p[n&s],i+=m*(this._p[n+1&s]-i),a=this._p[n+h&s],a+=m*(this._p[n+h+1&s]-a),i+=g*(a-i),n+=L,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+=g*(d-a),i+=_(f)*(a-i),v+=i*y,y*=this._pf,o<<=1,c*=2,l<<=1,b*=2,p<<=1,f*=2,c>=1&&(o++,c--),b>=1&&(l++,b--),f>=1&&(p++,f--)}return v}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||{},E);})();
package/dist/tween.js CHANGED
@@ -10,7 +10,7 @@
10
10
  globalThis.utils.global = (overrides = true) => {
11
11
  for (const key in globalThis.utils) {
12
12
  if ("global" === key) continue;
13
- if (overrides || globalThis[key] !== void 0) {
13
+ if (overrides || globalThis[key] === void 0) {
14
14
  globalThis[key] = globalThis.utils[key];
15
15
  }
16
16
  }
package/dist/tween.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var c=Object.defineProperty;var f=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let e in globalThis.utils)e!=="global"&&(t||globalThis[e]!==void 0)&&(globalThis[e]=globalThis.utils[e])};var o={};f(o,{BACK_IN:()=>D,BACK_IN_OUT:()=>g,BACK_OUT:()=>E,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>T,BOUNCE_OUT:()=>m,EASE_IN:()=>h,EASE_IN_OUT:()=>d,EASE_OUT:()=>_,ELASTIC_IN:()=>I,ELASTIC_IN_OUT:()=>U,ELASTIC_OUT:()=>L,LINEAR:()=>l,tween:()=>b});var i=Math.PI/2,b=(t,e,r,a=1,s=l)=>new u(t,e,r,a,s),l=t=>t,h=t=>t*t,_=t=>-t*(t-2),d=t=>t<.5?2*t*t:-2*t*t+4*t-1,D=t=>t*t*t-t*Math.sin(t*Math.PI),E=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},g=t=>{if(t<.5){let r=2*t;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},I=t=>Math.sin(13*i*t)*Math.pow(2,10*(t-1)),L=t=>Math.sin(-13*i*(t+1))*Math.pow(2,-10*t)+1,U=t=>{if(t<.5){let a=Math.sin(13*i*(2*t)),s=Math.pow(2,10*(2*t-1));return .5*a*s}let e=Math.sin(-13*i*(2*t-1+1)),r=Math.pow(2,-10*(2*t-1));return .5*(e*r+2)},p=t=>1-m(1-t),m=t=>t<4/11?121*t*t/16:t<8/11?363/40*t*t-99/10*t+17/5:t<9/10?4356/361*t*t-35442/1805*t+16061/1805:54/5*t*t-513/25*t+268/25,T=t=>t<.5?.5*p(t*2):.5*m(t*2-1)+.5,u=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(e,r,a,s,n){this._o=e,this._p=r,this._x=a,this._d=s,this._e=n,this._w=0}start(e){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,a=this._rel?r+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",s=>{if(this._t<=this._w){this._t+=s;return}let n=this._t-this._w;this._o[this._p]=this._lc.lerp(r,a,this._e(n/this._d)),this._t+=s,n>=this._d&&(this._o[this._p]=a,this.stop())}),this}stop(e=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,e)for(let r of this._cb)r(this._o);return this}restart(e=null,r=!1){return this.stop(r).restart(e)}onEnd(e){return this._cb.push(e),this}chain(e){return this._ch.onEnd(()=>{this._cu=e.start(this._lc)}),this._ch=e,this}reset(){return this._cb.length=0,this.stop()}relative(e=!0){return this._rel=e,this}delay(e){return this._w=e,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};globalThis.utils=Object.assign(globalThis.utils||{},o);})();
1
+ (()=>{var c=Object.defineProperty;var b=(t,e)=>{for(var a in e)c(t,a,{get:e[a],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(t=!0)=>{for(let e in globalThis.utils)e!=="global"&&(t||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var m={};b(m,{BACK_IN:()=>g,BACK_IN_OUT:()=>E,BACK_OUT:()=>T,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>v,BOUNCE_OUT:()=>o,EASE_IN:()=>h,EASE_IN_OUT:()=>_,EASE_OUT:()=>d,ELASTIC_IN:()=>w,ELASTIC_IN_OUT:()=>I,ELASTIC_OUT:()=>A,LINEAR:()=>l,tween:()=>f});var i=Math.PI/2,f=(t,e,a,r=1,s=l)=>new u(t,e,a,r,s),l=t=>t,h=t=>t*t,d=t=>-t*(t-2),_=t=>t<.5?2*t*t:-2*t*t+4*t-1,g=t=>t*t*t-t*Math.sin(t*Math.PI),T=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},E=t=>{if(t<.5){let a=2*t;return .5*(a*a*a-a*Math.sin(a*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},w=t=>Math.sin(13*i*t)*Math.pow(2,10*(t-1)),A=t=>Math.sin(-13*i*(t+1))*Math.pow(2,-10*t)+1,I=t=>{if(t<.5){let r=Math.sin(13*i*(2*t)),s=Math.pow(2,10*(2*t-1));return .5*r*s}let e=Math.sin(-13*i*(2*t-1+1)),a=Math.pow(2,-10*(2*t-1));return .5*(e*a+2)},p=t=>1-o(1-t),o=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,v=t=>t<.5?.5*p(t*2):.5*o(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,a,r,s,n){this._o=e,this._p=a,this._x=r,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 a=this._o[this._p]||0,r=this._rel?a+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(a,r,this._e(n/this._d)),this._t+=s,n>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(e=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,e)for(let a of this._cb)a(this._o);return this}restart(e=null,a=!1){return this.stop(a).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||{},m);})();
package/dist/vector.js CHANGED
@@ -173,9 +173,9 @@
173
173
  a.y += (b.y - a.y) * t || 0;
174
174
  return a;
175
175
  };
176
- var vecRand = (minlength = 1, maxlength = minlength, randomFn = globalThis.rand || Math.random) => {
177
- const angle = randomFn() * PI2;
178
- const radius = randomFn() * (maxlength - minlength) + minlength;
176
+ var vecRand = (minlength = 1, maxlength = minlength, rng = globalThis.rand || Math.random) => {
177
+ const angle = rng() * PI2;
178
+ const radius = rng() * (maxlength - minlength) + minlength;
179
179
  return vec(cos(angle) * radius, sin(angle) * radius);
180
180
  };
181
181
  var vecAbs = (v) => {
@@ -1 +1 @@
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);})();
1
+ (()=>{var q=Object.defineProperty;var A=(t,e)=>{for(var o in e)q(t,o,{get:e[o],enumerable:!0})};var h={};A(h,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>T,vec:()=>r,vecAbs:()=>$,vecAdd:()=>u,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>j,vecClamp:()=>H,vecCross:()=>F,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>x,vecDot:()=>D,vecEq:()=>p,vecFloor:()=>B,vecIsZero:()=>W,vecLerp:()=>U,vecLimit:()=>b,vecMag:()=>g,vecMag2:()=>R,vecMove:()=>V,vecMult:()=>y,vecNorm:()=>a,vecRand:()=>Z,vecReflect:()=>O,vecRotate:()=>I,vecRound:()=>G,vecSet:()=>d,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,d=(t,e,o=e)=>(n(e)?d(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=a(r(e));return i(t,y(o,2*D(t,o)))},S=(t,e)=>(a(t),y(t,e),t),g=t=>Math.hypot(t.x,t.y),R=t=>t.x*t.x+t.y*t.y,a=t=>{let e=g(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,F=(t,e)=>t.x*e.y-t.y*e.x,U=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),Z=(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)},$=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),j=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),B=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||{},h);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
@@ -39,6 +39,6 @@
39
39
  "devDependencies": {
40
40
  "esbuild": "^0.25.0",
41
41
  "gzip-size": "^7.0.0",
42
- "prettier": "^3.5.2"
42
+ "prettier": "^3.5.3"
43
43
  }
44
44
  }
package/src/_global.js CHANGED
@@ -3,7 +3,7 @@ globalThis.utils = globalThis.utils || {}
3
3
  globalThis.utils.global = (overrides = true) => {
4
4
  for (const key in globalThis.utils) {
5
5
  if ("global" === key) continue
6
- if (overrides || globalThis[key] !== undefined) {
6
+ if (overrides || globalThis[key] === undefined) {
7
7
  globalThis[key] = globalThis.utils[key]
8
8
  }
9
9
  }
@@ -0,0 +1,92 @@
1
+ # Collection utilities
2
+
3
+ **CDN**: https://unpkg.com/@litecanvas/utils/dist/collection.js
4
+
5
+ ## head
6
+
7
+ Returns the first element of an array.
8
+
9
+ Syntax: `head(any[]): any`
10
+
11
+ ```js
12
+ import { head } from "@litecanvas/utils"
13
+
14
+ head([1, 2, 3]) // => 1
15
+ ```
16
+
17
+ ## last
18
+
19
+ Returns the last element of an array.
20
+
21
+ Syntax: `last(any[]): any`
22
+
23
+ ```js
24
+ import { last } from "@litecanvas/utils"
25
+
26
+ last([1, 2, 3]) // => 3
27
+ ```
28
+
29
+ ## tail
30
+
31
+ Returns all but the first element of an array.
32
+
33
+ Syntax: `tail(any[]): any[]`
34
+
35
+ ```js
36
+ import { tail } from "@litecanvas/utils"
37
+
38
+ tail([1, 2, 3]) // => [2, 3]
39
+ ```
40
+
41
+ ## range
42
+
43
+ Returns a sequence of numbers.
44
+
45
+ Syntax: `range(size: number, first?: number, step?: number): number[]`
46
+
47
+ ```js
48
+ import { range } from "@litecanvas/utils"
49
+
50
+ // prints 0 1 2 3 4
51
+ for (let i of range(5)) {
52
+ console.log(i)
53
+ }
54
+
55
+ // prints -5 -4 -3 -2 -1
56
+ for (let i of range(5, -5)) {
57
+ console.log(i)
58
+ }
59
+
60
+ // prints 10 20 30 40 50 60 70 80 90 100
61
+ for (let i of range(10, 10, 10)) {
62
+ console.log(i)
63
+ }
64
+ ```
65
+
66
+ ## sample
67
+
68
+ Return a random value of an array.
69
+
70
+ Syntax: `sample(values: any[], rng = Math.random): any`
71
+
72
+ ```js
73
+ import { sample } from "@litecanvas/utils"
74
+
75
+ const values = [0, 1, 2]
76
+
77
+ sample(values) // returns a value of this array
78
+ ```
79
+
80
+ ## shuffle
81
+
82
+ Creates an new array of shuffled values.
83
+
84
+ Syntax: `sample(values: any[], rng = Math.random): any`
85
+
86
+ ```js
87
+ import { shuffle } from "@litecanvas/utils"
88
+
89
+ const values = [0, 1, 2, 3]
90
+
91
+ shuffle(values) // => [2, 0, 3, 1] (just a example of shuffled)
92
+ ```
@@ -0,0 +1,4 @@
1
+ import "../_global.js"
2
+ import * as collectionUtils from "./index.js"
3
+
4
+ globalThis.utils = Object.assign(globalThis.utils || {}, collectionUtils)
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the first value of an array
3
+ *
4
+ * @param {T[]} values
5
+ * @returns {T}
6
+ */
7
+ export default (values) => values[0]
@@ -0,0 +1,6 @@
1
+ export { default as range } from "./range.js"
2
+ export { default as shuffle } from "./shuffle.js"
3
+ export { default as sample } from "./sample.js"
4
+ export { default as head } from "./head.js"
5
+ export { default as last } from "./last.js"
6
+ export { default as tail } from "./tail.js"
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the last value of an array
3
+ *
4
+ * @param {T[]} values
5
+ * @returns {T}
6
+ */
7
+ export default (values) => values[values.length - 1]
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returns a sequence of numbers.
3
+ *
4
+ * @param {number} size the amount of numbers
5
+ * @param {number} [from] the first value (default = 0)
6
+ * @param {number} [step] the value that should be incremented (default = 1)
7
+ * @returns {number[]}
8
+ *
9
+ * @example
10
+ * // print 0 1 2 3 4
11
+ * for(let i of range(5)) {
12
+ * console.log(i)
13
+ * }
14
+ *
15
+ * // print 10 15 20 25 30
16
+ * for(let i of range(5, 10, 5)) {
17
+ * console.log(i)
18
+ * }
19
+ */
20
+ export default (size, from = 0, step = 1) =>
21
+ Array.from(
22
+ Array(size)
23
+ .keys()
24
+ .map((i) => {
25
+ return from + step * i
26
+ })
27
+ )
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Return a random value of an array.
3
+ *
4
+ * @param {number[]} values
5
+ * @param {()=>number} [rng]
6
+ * @returns {number}
7
+ */
8
+ export default (values, rng = globalThis.rand || Math.random) => {
9
+ return values[Math.floor(rng() * values.length)]
10
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Creates an new array of shuffled values
3
+ *
4
+ * @param {number[]} values
5
+ * @param {()=>number} [rng]
6
+ * @returns {number[]} the same array but shuffled
7
+ */
8
+ export default (values, rng = globalThis.rand || Math.random) => {
9
+ values = Array.from(values)
10
+ for (let i = values.length - 1; i > 0; i--) {
11
+ let j = Math.floor(rng() * (i + 1))
12
+ let temp = values[i]
13
+ values[i] = values[j]
14
+ values[j] = temp
15
+ }
16
+ return values
17
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets all but the first element of an array
3
+ *
4
+ * @param {T[]} values
5
+ * @returns {T}
6
+ */
7
+ export default (values) => values.slice(1)
package/src/image/_web.js CHANGED
@@ -1,10 +1,4 @@
1
1
  import "../_global.js"
2
- import tint from "./tint.js"
3
- import scaleImage from "./scale.js"
4
- import flipImage from "./flip.js"
2
+ import * as imageUtils from "./index.js"
5
3
 
6
- globalThis.utils = Object.assign(globalThis.utils || {}, {
7
- tint,
8
- scaleImage,
9
- flipImage,
10
- })
4
+ globalThis.utils = Object.assign(globalThis.utils || {}, imageUtils)
@@ -0,0 +1,3 @@
1
+ export { default as flipImage } from "./flip.js"
2
+ export { default as scaleImage } from "./scale.js"
3
+ export { default as tintImage } from "./tint.js"
package/src/index.js CHANGED
@@ -7,6 +7,5 @@ export * from "./actor/index.js"
7
7
  export * from "./math/index.js"
8
8
  export * from "./tween/index.js"
9
9
  export * from "./noise/index.js"
10
- export { default as tint } from "./image/tint.js"
11
- export { default as scaleImage } from "./image/scale.js"
12
- export { default as flipImage } from "./image/flip.js"
10
+ export * from "./image/index.js"
11
+ export * from "./collection/index.js"
@@ -99,28 +99,33 @@ function draw() {
99
99
 
100
100
  [See in playground](https://litecanvas.js.org?c=eJxVjjELwjAQhff%2BihtTCKWCg0tdtKCLgxTEMV5SCYS0NGlUpP%2FdS1NQhxvue7yPN3ptXHE33U0YlmdGe4XCBuHoydrRotedBW21Zzm8M4C%2Bc1BBUMhKDrv61NTna048KPPlZSQCcSGrMrHpRzn2UnjFpE9aIYOwqBjpeXTxWOdAMYW6hRgUT9jC5bhvDqkzjyFYQUnf9KeXg3gsi9E4Ng9CPWDy8Ln54rDe0NGwDwbOS1Q%3D)
101
101
 
102
- ## range
102
+ ## mod
103
+
104
+ Math modulus (always returns a positive number).
105
+
106
+ ```js
107
+ import { mod } from "@litecanvas/utils"
108
+
109
+ mod(17, 5) // => 2
110
+ mod(-17, 5) // => 3
111
+ ```
103
112
 
104
- Returns a sequence of numbers from `0` to `size - 1`.
113
+ ## mean
105
114
 
106
- Syntax: `range(size: number): number[]`
115
+ Computes the mean of the values in a array.
107
116
 
108
117
  ```js
109
- import { range } from "@litecanvas/utils"
118
+ import { mean } from "@litecanvas/utils"
110
119
 
111
- // prints 0 1 2 3 4
112
- for (let i of range(5)) {
113
- console.log(i)
114
- }
120
+ mean(10, 5, 3) // => 6 or (10 + 5 + 3) / 3
115
121
  ```
116
122
 
117
- ## mod
123
+ ## sum
118
124
 
119
- Math modulus (always returns a positive number).
125
+ Computes the sum of the values in a array.
120
126
 
121
127
  ```js
122
- import { mod } from "@litecanvas/utils"
128
+ import { sum } from "@litecanvas/utils"
123
129
 
124
- mod(17, 5) // => 2
125
- mod(-17, 5) // => 3
130
+ sum(10, 5, 3) // => 18 or (10 + 5 + 3)
126
131
  ```
package/src/math/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  export { default as diff } from "./diff.js"
2
2
  export { default as wave } from "./wave.js"
3
3
  export { default as fract } from "./fract.js"
4
- export { default as range } from "./range.js"
5
4
  export { default as advance } from "./advance.js"
6
5
  export { default as mod } from "./mod.js"
7
6
  export { default as roundd } from "./roundd.js"
8
7
  export { default as dist } from "./dist.js"
9
8
  export { default as mag } from "./mag.js"
9
+ export { default as mean } from "./mean.js"
10
+ export { default as sum } from "./sum.js"
@@ -0,0 +1,11 @@
1
+ import sum from "./sum"
2
+
3
+ /**
4
+ * Computes the mean of the values in a array.
5
+ *
6
+ * @param {number[]} values list of numbers
7
+ * @returns {number}
8
+ */
9
+ export default (values) => {
10
+ return sum(values) / values.length
11
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Computes the sum of the values in a array.
3
+ *
4
+ * @param {number[]} values list of numbers
5
+ * @returns {number}
6
+ */
7
+ export default (values) => {
8
+ let result = 0
9
+ for (let i = 0; i < values.length; i++) {
10
+ result += values[i]
11
+ }
12
+ return result
13
+ }
@@ -345,10 +345,10 @@ export const vecLerp = (a, b, t) => {
345
345
  export const vecRand = (
346
346
  minlength = 1,
347
347
  maxlength = minlength,
348
- randomFn = globalThis.rand || Math.random
348
+ rng = globalThis.rand || Math.random
349
349
  ) => {
350
- const angle = randomFn() * PI2
351
- const radius = randomFn() * (maxlength - minlength) + minlength
350
+ const angle = rng() * PI2
351
+ const radius = rng() * (maxlength - minlength) + minlength
352
352
  return vec(cos(angle) * radius, sin(angle) * radius)
353
353
  }
354
354
 
package/src/math/range.js DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Returns a sequence of numbers from `0` to `size - 1`.
3
- *
4
- * @param {number} size the amount of numbers
5
- * @returns {number[]}
6
- * @example
7
- * // print 0 1 2 3 4
8
- * for(let i of range(5)) console.log(i)
9
- */
10
- export default (size) => Array.from(Array(size).keys())