@litecanvas/utils 0.12.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/actor.js CHANGED
@@ -26,6 +26,7 @@
26
26
  });
27
27
 
28
28
  // src/vector/index.js
29
+ var PI2 = 2 * Math.PI;
29
30
  var Vector = class {
30
31
  /** @type {number} */
31
32
  x;
@@ -46,8 +47,17 @@
46
47
  return `Vector (${this.x}, ${this.y})`;
47
48
  }
48
49
  };
49
- var vec = (x = 0, y = x) => new Vector(x, y);
50
- var veccopy = (v) => vec(v.x, v.y);
50
+ var isVector = (v) => v instanceof Vector;
51
+ var vec = (x = 0, y = x) => {
52
+ if (isVector(x)) {
53
+ y = x.y;
54
+ x = x.x;
55
+ }
56
+ return new Vector(x, y);
57
+ };
58
+
59
+ // node_modules/litecanvas/src/zzfx.js
60
+ globalThis.zzfxV = 1;
51
61
 
52
62
  // src/actor/index.js
53
63
  var ANCHOR_CENTER = vec(0.5, 0.5);
@@ -78,7 +88,7 @@
78
88
  constructor(sprite, position, anchor = ANCHOR_TOP_LEFT) {
79
89
  this.sprite = sprite;
80
90
  this.pos = position || vec(0);
81
- this._o = veccopy(anchor);
91
+ this._o = vec(anchor);
82
92
  this._s = vec(1, 1);
83
93
  }
84
94
  /**
@@ -130,6 +140,12 @@
130
140
  get height() {
131
141
  return this.sprite.height * this._s.y;
132
142
  }
143
+ /**
144
+ * @retuns {Vector}
145
+ */
146
+ get scale() {
147
+ return this._s;
148
+ }
133
149
  /**
134
150
  * @returns {number[]}
135
151
  */
@@ -140,12 +156,6 @@
140
156
  const y = this.pos.y - h * this.anchor.y;
141
157
  return [x, y, w, h];
142
158
  }
143
- /**
144
- * @retuns {Vector}
145
- */
146
- get scale() {
147
- return this._s;
148
- }
149
159
  /**
150
160
  * Update the transformation matrix, sets the opacity and draw the actor sprite image.
151
161
  *
package/dist/actor.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var h=Object.defineProperty;var u=(e,t)=>{for(var o in t)h(e,o,{get:t[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var a={};u(a,{ANCHOR_BOT_LEFT:()=>g,ANCHOR_BOT_RIGHT:()=>y,ANCHOR_CENTER:()=>d,ANCHOR_TOP_LEFT:()=>l,ANCHOR_TOP_RIGHT:()=>x,Actor:()=>i});var n=class{x;y;constructor(t=0,o=t){this.x=t,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},s=(e=0,t=e)=>new n(e,t);var c=e=>s(e.x,e.y);var d=s(.5,.5),l=s(0,0),x=s(1,0),g=s(0,1),y=s(1,1),i=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,o,r=l){this.sprite=t,this.pos=o||s(0),this._o=c(r),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}getBounds(t=!0){let o=this.sprite.width*(t?this._s.x:1),r=this.sprite.height*(t?this._s.y:1),f=this.pos.x-o*this.anchor.x,p=this.pos.y-r*this.anchor.y;return[f,p,o,r]}get scale(){return this._s}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let o=this.sprite.width*this.anchor.x,r=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-o,-r,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},a);})();
1
+ (()=>{var p=Object.defineProperty;var u=(e,t)=>{for(var o in t)p(e,o,{get:t[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var a={};u(a,{ANCHOR_BOT_LEFT:()=>x,ANCHOR_BOT_RIGHT:()=>g,ANCHOR_CENTER:()=>d,ANCHOR_TOP_LEFT:()=>c,ANCHOR_TOP_RIGHT:()=>y,Actor:()=>i});var _=2*Math.PI,n=class{x;y;constructor(t=0,o=t){this.x=t,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},h=e=>e instanceof n,r=(e=0,t=e)=>(h(e)&&(t=e.y,e=e.x),new n(e,t));globalThis.zzfxV=1;var d=r(.5,.5),c=r(0,0),y=r(1,0),x=r(0,1),g=r(1,1),i=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,o,s=c){this.sprite=t,this.pos=o||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}getBounds(t=!0){let o=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),l=this.pos.x-o*this.anchor.x,f=this.pos.y-s*this.anchor.y;return[l,f,o,s]}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let o=this.sprite.width*this.anchor.x,s=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-o,-s,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},a);})();
package/dist/all.js CHANGED
@@ -36,30 +36,37 @@
36
36
  diff: () => diff_default,
37
37
  fract: () => fract_default,
38
38
  intersection: () => intersection_default,
39
- isvector: () => isvector,
40
39
  range: () => range_default,
41
40
  resolve: () => resolve_default,
42
41
  vec: () => vec,
43
- vecadd: () => vecadd,
44
- vecconfig: () => vecconfig,
45
- veccopy: () => veccopy,
46
- veccross: () => veccross,
47
- vecdir: () => vecdir,
48
- vecdist: () => vecdist,
49
- vecdist2: () => vecdist2,
50
- vecdiv: () => vecdiv,
51
- vecdot: () => vecdot,
52
- veceq: () => veceq,
53
- veclerp: () => veclerp,
54
- veclimit: () => veclimit,
55
- vecmag: () => vecmag,
56
- vecmag2: () => vecmag2,
57
- vecmult: () => vecmult,
58
- vecnorm: () => vecnorm,
59
- vecrand: () => vecrand,
60
- vecrot: () => vecrot,
61
- vecset: () => vecset,
62
- vecsub: () => vecsub,
42
+ vecAbs: () => vecAbs,
43
+ vecAdd: () => vecAdd,
44
+ vecAngle: () => vecAngle,
45
+ vecAngleBetween: () => vecAngleBetween,
46
+ vecCeil: () => vecCeil,
47
+ vecClamp: () => vecClamp,
48
+ vecCross: () => vecCross,
49
+ vecDist: () => vecDist,
50
+ vecDist2: () => vecDist2,
51
+ vecDiv: () => vecDiv,
52
+ vecDot: () => vecDot,
53
+ vecEq: () => vecEq,
54
+ vecFloor: () => vecFloor,
55
+ vecIsZero: () => vecIsZero,
56
+ vecLerp: () => vecLerp,
57
+ vecLimit: () => vecLimit,
58
+ vecMag: () => vecMag,
59
+ vecMag2: () => vecMag2,
60
+ vecMove: () => vecMove,
61
+ vecMult: () => vecMult,
62
+ vecNorm: () => vecNorm,
63
+ vecRand: () => vecRand,
64
+ vecReflect: () => vecReflect,
65
+ vecRotate: () => vecRotate,
66
+ vecRound: () => vecRound,
67
+ vecSet: () => vecSet,
68
+ vecSetMag: () => vecSetMag,
69
+ vecSub: () => vecSub,
63
70
  wave: () => wave_default
64
71
  });
65
72
 
@@ -509,6 +516,10 @@
509
516
  }
510
517
 
511
518
  // src/vector/index.js
519
+ var sqrt = Math.sqrt;
520
+ var cos = Math.cos;
521
+ var sin = Math.sin;
522
+ var PI2 = 2 * Math.PI;
512
523
  var Vector = class {
513
524
  /** @type {number} */
514
525
  x;
@@ -529,102 +540,146 @@
529
540
  return `Vector (${this.x}, ${this.y})`;
530
541
  }
531
542
  };
532
- var vec = (x = 0, y = x) => new Vector(x, y);
533
- var veceq = (v, x, y = x) => {
534
- if (isvector(x)) {
535
- return veceq(v, x.x, x.y);
543
+ var isVector = (v) => v instanceof Vector;
544
+ var vec = (x = 0, y = x) => {
545
+ if (isVector(x)) {
546
+ y = x.y;
547
+ x = x.x;
548
+ }
549
+ return new Vector(x, y);
550
+ };
551
+ var vecEq = (v, x, y = x) => {
552
+ if (isVector(x)) {
553
+ return vecEq(v, x.x, x.y);
536
554
  }
537
555
  return v.x === x && v.y === y;
538
556
  };
539
- var veccopy = (v) => vec(v.x, v.y);
540
- var vecset = (v, x, y = x) => {
541
- if (isvector(x)) {
542
- vecset(v, x.x, x.y);
557
+ var vecSet = (v, x, y = x) => {
558
+ if (isVector(x)) {
559
+ vecSet(v, x.x, x.y);
543
560
  } else {
544
561
  v.x = x;
545
562
  v.y = y;
546
563
  }
564
+ return v;
547
565
  };
548
- var vecadd = (v, x, y = x) => {
549
- if (isvector(x)) {
550
- vecadd(v, x.x, x.y);
551
- } else {
552
- v.x += x;
553
- v.y += y;
566
+ var vecAdd = (v, x, y = x) => {
567
+ if (isVector(x)) {
568
+ return vecAdd(v, x.x, x.y);
554
569
  }
570
+ v.x += x;
571
+ v.y += y;
572
+ return v;
555
573
  };
556
- var vecsub = (v, x, y = x) => {
557
- if (isvector(x)) {
558
- vecsub(v, x.x, x.y);
559
- } else {
560
- v.x -= x;
561
- v.y -= y;
574
+ var vecSub = (v, x, y = x) => {
575
+ if (isVector(x)) {
576
+ return vecSub(v, x.x, x.y);
562
577
  }
578
+ v.x -= x;
579
+ v.y -= y;
580
+ return v;
563
581
  };
564
- var vecmult = (v, x, y = x) => {
565
- if (isvector(x)) {
566
- vecmult(v, x.x, x.y);
567
- } else {
568
- v.x *= x;
569
- v.y *= y;
582
+ var vecMult = (v, x, y = x) => {
583
+ if (isVector(x)) {
584
+ return vecMult(v, x.x, x.y);
570
585
  }
586
+ v.x *= x;
587
+ v.y *= y;
588
+ return v;
571
589
  };
572
- var vecdiv = (v, x, y = x) => {
573
- if (isvector(x)) {
574
- vecdiv(v, x.x, x.y);
575
- } else {
576
- v.x /= x;
577
- v.y /= y;
590
+ var vecDiv = (v, x, y = x) => {
591
+ if (isVector(x)) {
592
+ return vecDiv(v, x.x, x.y);
578
593
  }
594
+ v.x /= x;
595
+ v.y /= y;
596
+ return v;
597
+ };
598
+ var vecRotate = (v, radians) => {
599
+ const c = cos(radians), s = sin(radians);
600
+ v.x = c * v.x - s * v.y;
601
+ v.y = s * v.x + c * v.y;
602
+ return v;
579
603
  };
580
- var vecrot = (v, radians) => {
581
- const cos = Math.cos(radians), sin = Math.sin(radians);
582
- v.x = cos * v.x - sin * v.y;
583
- v.y = sin * v.x + cos * v.y;
604
+ var vecReflect = (v, normal) => {
605
+ const normalCopy = vecNorm(vec(normal));
606
+ return vecSub(v, vecMult(normalCopy, 2 * vecDot(v, normalCopy)));
584
607
  };
585
- var vecmag = (v) => Math.sqrt(v.x * v.x + v.y * v.y);
586
- var vecmag2 = (v) => v.x * v.x + v.y * v.y;
587
- var vecnorm = (v) => {
588
- const length = vecmag(v);
608
+ var vecSetMag = (v, value) => {
609
+ vecNorm(v);
610
+ vecMult(v, value);
611
+ return v;
612
+ };
613
+ var vecMag = (v) => sqrt(v.x * v.x + v.y * v.y);
614
+ var vecMag2 = (v) => v.x * v.x + v.y * v.y;
615
+ var vecNorm = (v) => {
616
+ const length = vecMag(v);
589
617
  if (length > 0) {
590
- vecdiv(v, length);
618
+ vecDiv(v, length);
591
619
  }
620
+ return v;
592
621
  };
593
- var veclimit = (v, max) => {
594
- const sq = vecmag2(v);
622
+ var vecLimit = (v, max = 1) => {
623
+ const sq = vecMag2(v);
595
624
  if (sq > max * max) {
596
- vecdiv(v, Math.sqrt(sq));
597
- vecmult(v, max);
625
+ vecDiv(v, sqrt(sq));
626
+ vecMult(v, max);
598
627
  }
628
+ return v;
599
629
  };
600
- var vecdist = (a, b) => {
630
+ var vecDist = (a, b) => {
601
631
  const dx = a.x - b.x;
602
632
  const dy = a.y - b.y;
603
- return Math.sqrt(dx * dx + dy * dy);
633
+ return sqrt(dx * dx + dy * dy);
604
634
  };
605
- var vecdist2 = (a, b) => {
635
+ var vecDist2 = (a, b) => {
606
636
  const dx = a.x - b.x;
607
637
  const dy = a.y - b.y;
608
638
  return dx * dx + dy * dy;
609
639
  };
610
- var vecdir = (v) => Math.atan2(v.y, v.x);
611
- var vecdot = (a, b) => a.x * b.x + a.y * b.y;
612
- var veccross = (a, b) => a.x * b.y - a.y * b.x;
613
- var veclerp = (a, b, t) => {
640
+ var vecAngle = (v) => Math.atan2(v.y, v.x);
641
+ var vecAngleBetween = (v1, v2) => Math.atan2(v2.y - v1.y, v2.x - v1.x);
642
+ var vecDot = (a, b) => a.x * b.x + a.y * b.y;
643
+ var vecCross = (a, b) => a.x * b.y - a.y * b.x;
644
+ var vecLerp = (a, b, t) => {
614
645
  a.x += (b.x - a.x) * t || 0;
615
646
  a.y += (b.y - a.y) * t || 0;
647
+ return a;
616
648
  };
617
- var vecrand = (minlength = 1, maxlength = minlength) => {
618
- const angle = vecconfig.random() * 2 * Math.PI;
619
- const radius = vecconfig.random() * (maxlength - minlength) + minlength;
620
- return vec(Math.cos(angle) * radius, Math.sin(angle) * radius);
649
+ var vecRand = (minlength = 1, maxlength = minlength, randomFn = globalThis.rand || Math.random) => {
650
+ const angle = randomFn() * PI2;
651
+ const radius = randomFn() * (maxlength - minlength) + minlength;
652
+ return vec(cos(angle) * radius, sin(angle) * radius);
621
653
  };
622
- var isvector = (v) => v instanceof Vector;
623
- var vecconfig = {
624
- random: () => {
625
- return globalThis.rand ? rand() : Math.random();
626
- }
654
+ var vecAbs = (v) => {
655
+ v.x = Math.abs(v.x);
656
+ v.y = Math.abs(v.y);
657
+ return v;
658
+ };
659
+ var vecCeil = (v) => {
660
+ v.x = Math.ceil(v.x);
661
+ v.y = Math.ceil(v.y);
662
+ return v;
663
+ };
664
+ var vecFloor = (v) => {
665
+ v.x = Math.floor(v.x);
666
+ v.y = Math.floor(v.y);
667
+ return v;
668
+ };
669
+ var vecRound = (v) => {
670
+ v.x = Math.round(v.x);
671
+ v.y = Math.round(v.y);
672
+ return v;
673
+ };
674
+ var vecClamp = (v, min, max) => {
675
+ if (v.x < min.x) v.x = min.x;
676
+ if (v.x > max.x) v.x = max.x;
677
+ if (v.y < min.y) v.y = min.y;
678
+ if (v.y > max.y) v.y = max.y;
679
+ return v;
627
680
  };
681
+ var vecMove = (v, to, delta = 1) => vecAdd(v, to.x * delta, to.y * delta);
682
+ var vecIsZero = (v) => vecEq(v, ZERO);
628
683
  var ZERO = /* @__PURE__ */ vec(0, 0);
629
684
  var ONE = /* @__PURE__ */ vec(1, 1);
630
685
  var UP = /* @__PURE__ */ vec(0, -1);
@@ -632,6 +687,9 @@
632
687
  var DOWN = /* @__PURE__ */ vec(0, 1);
633
688
  var LEFT = /* @__PURE__ */ vec(-1, 0);
634
689
 
690
+ // node_modules/litecanvas/src/zzfx.js
691
+ globalThis.zzfxV = 1;
692
+
635
693
  // src/actor/index.js
636
694
  var ANCHOR_CENTER = vec(0.5, 0.5);
637
695
  var ANCHOR_TOP_LEFT = vec(0, 0);
@@ -661,7 +719,7 @@
661
719
  constructor(sprite, position, anchor = ANCHOR_TOP_LEFT) {
662
720
  this.sprite = sprite;
663
721
  this.pos = position || vec(0);
664
- this._o = veccopy(anchor);
722
+ this._o = vec(anchor);
665
723
  this._s = vec(1, 1);
666
724
  }
667
725
  /**
@@ -713,6 +771,12 @@
713
771
  get height() {
714
772
  return this.sprite.height * this._s.y;
715
773
  }
774
+ /**
775
+ * @retuns {Vector}
776
+ */
777
+ get scale() {
778
+ return this._s;
779
+ }
716
780
  /**
717
781
  * @returns {number[]}
718
782
  */
@@ -723,12 +787,6 @@
723
787
  const y = this.pos.y - h * this.anchor.y;
724
788
  return [x, y, w, h];
725
789
  }
726
- /**
727
- * @retuns {Vector}
728
- */
729
- get scale() {
730
- return this._s;
731
- }
732
790
  /**
733
791
  * Update the transformation matrix, sets the opacity and draw the actor sprite image.
734
792
  *
@@ -775,3 +833,4 @@
775
833
  // src/_web.js
776
834
  globalThis.utils = Object.assign(globalThis.utils || {}, src_exports);
777
835
  })();
836
+ /*! @litecanvas/utils by Luiz Bills | MIT Licensed */
package/dist/all.min.js CHANGED
@@ -1,2 +1,3 @@
1
- (()=>{var B=Object.defineProperty;var F=(e,t)=>{for(var s in t)B(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 M={};F(M,{ANCHOR_BOT_LEFT:()=>at,ANCHOR_BOT_RIGHT:()=>ht,ANCHOR_CENTER:()=>rt,ANCHOR_TOP_LEFT:()=>Y,ANCHOR_TOP_RIGHT:()=>nt,Actor:()=>b,Camera:()=>p,DOWN:()=>it,Grid:()=>x,LEFT:()=>ot,ONE:()=>tt,RIGHT:()=>st,TypedGrid:()=>w,UP:()=>et,Vector:()=>u,ZERO:()=>Q,diff:()=>R,fract:()=>L,intersection:()=>g,isvector:()=>l,range:()=>v,resolve:()=>P,vec:()=>n,vecadd:()=>k,vecconfig:()=>H,veccopy:()=>E,veccross:()=>Z,vecdir:()=>V,vecdist:()=>q,vecdist2:()=>N,vecdiv:()=>_,vecdot:()=>U,veceq:()=>O,veclerp:()=>J,veclimit:()=>$,vecmag:()=>z,vecmag2:()=>S,vecmult:()=>I,vecnorm:()=>j,vecrand:()=>K,vecrot:()=>G,vecset:()=>C,vecsub:()=>X,wave:()=>W});var g=(e,t,s,i,r,o,a,h)=>{let c=Math.max(e,r),A=Math.min(e+s,r+a)-c,d=Math.max(t,o),m=Math.min(t+i,o+h)-d;return[c,d,A,m]};var P=(e,t,s,i,r,o,a,h)=>{let[c,A,d,m]=g(e,t,s,i,r,o,a,h),f="",y=e,T=t;return d<m?e<r?(f="right",y=r-s):(f="left",y=r+a):t<o?(f="bottom",T=o-i):(f="top",T=o+h),{direction:f,x:y,y:T}};var p=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,s=0,i=0,r=null,o=null){this._engine=t||globalThis,this.ox=s,this.oy=i,this.resize(r||this._engine.WIDTH-s,o||this._engine.HEIGHT-i),this.x=this.width/2,this.y=this.height/2}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.cliprect(this.ox,this.oy,this.width,this.height);let s=this.ox+this.width/2,i=this.oy+this.height/2;this._engine.translate(s,i),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,s,i={}){let r=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,i.x=r*t-o*s+this.x,i.y=o*t+r*s+this.y,i}getCameraPoint(t,s,i={}){let r=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=r*t-o*s,s=o*t+r*s,i.x=t*this.scale+this.width/2+this.ox,i.y=s*this.scale+this.height/2+this.oy,i}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,s,i,r){let o=this.width/2-this.x,a=this.height/2-this.y,h=this.width/this.scale,c=this.height/this.scale;return this._engine.colrect(t,s,i,r,o,a,h,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 x=class e{_w;_h;_c;constructor(t,s,i=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=i}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}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 a=this.indexToPointX(i),h=this.indexToPointY(i),c=this._c[i];if(t(a,h,c,this)===!1)break;i+=o}}fill(t){this.forEach((s,i)=>{this.set(s,i,t)})}clone(){return e.fromArray(this._w,this._h,this._c)}clampX(t){return D(t,0,this._w-1)}clampY(t){return D(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let i=[];return this.forEach((r,o,a)=>{i[o]=i[o]||"",i[o]+=a+t}),i.join(`
2
- `)}},w=class e extends x{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 D(e,t,s){return e<t?t:e>s?s:e}var u=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},n=(e=0,t=e)=>new u(e,t),O=(e,t,s=t)=>l(t)?O(e,t.x,t.y):e.x===t&&e.y===s,E=e=>n(e.x,e.y),C=(e,t,s=t)=>{l(t)?C(e,t.x,t.y):(e.x=t,e.y=s)},k=(e,t,s=t)=>{l(t)?k(e,t.x,t.y):(e.x+=t,e.y+=s)},X=(e,t,s=t)=>{l(t)?X(e,t.x,t.y):(e.x-=t,e.y-=s)},I=(e,t,s=t)=>{l(t)?I(e,t.x,t.y):(e.x*=t,e.y*=s)},_=(e,t,s=t)=>{l(t)?_(e,t.x,t.y):(e.x/=t,e.y/=s)},G=(e,t)=>{let s=Math.cos(t),i=Math.sin(t);e.x=s*e.x-i*e.y,e.y=i*e.x+s*e.y},z=e=>Math.sqrt(e.x*e.x+e.y*e.y),S=e=>e.x*e.x+e.y*e.y,j=e=>{let t=z(e);t>0&&_(e,t)},$=(e,t)=>{let s=S(e);s>t*t&&(_(e,Math.sqrt(s)),I(e,t))},q=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return Math.sqrt(s*s+i*i)},N=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return s*s+i*i},V=e=>Math.atan2(e.y,e.x),U=(e,t)=>e.x*t.x+e.y*t.y,Z=(e,t)=>e.x*t.y-e.y*t.x,J=(e,t,s)=>{e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0},K=(e=1,t=e)=>{let s=H.random()*2*Math.PI,i=H.random()*(t-e)+e;return n(Math.cos(s)*i,Math.sin(s)*i)},l=e=>e instanceof u,H={random:()=>globalThis.rand?rand():Math.random()},Q=n(0,0),tt=n(1,1),et=n(0,-1),st=n(1,0),it=n(0,1),ot=n(-1,0);var rt=n(.5,.5),Y=n(0,0),nt=n(1,0),at=n(0,1),ht=n(1,1),b=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,s,i=Y){this.sprite=t,this.pos=s||n(0),this._o=E(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}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]}get scale(){return this._s}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let s=this.sprite.width*this.anchor.x,i=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-s,-i,this.sprite)}};var R=(e,t)=>Math.abs(t-e)||0;var W=(e,t,s,i=Math.sin)=>e+(i(s)+1)/2*(t-e);var L=e=>e%1||0;var v=e=>Array.from(Array(e).keys());globalThis.utils=Object.assign(globalThis.utils||{},M);})();
1
+ (()=>{var U=Object.defineProperty;var $=(e,t)=>{for(var s in t)U(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 k={};$(k,{ANCHOR_BOT_LEFT:()=>mt,ANCHOR_BOT_RIGHT:()=>Tt,ANCHOR_CENTER:()=>yt,ANCHOR_TOP_LEFT:()=>F,ANCHOR_TOP_RIGHT:()=>_t,Actor:()=>D,Camera:()=>u,DOWN:()=>xt,Grid:()=>y,LEFT:()=>gt,ONE:()=>ut,RIGHT:()=>dt,TypedGrid:()=>E,UP:()=>pt,Vector:()=>p,ZERO:()=>B,diff:()=>G,fract:()=>j,intersection:()=>g,range:()=>z,resolve:()=>S,vec:()=>n,vecAbs:()=>rt,vecAdd:()=>b,vecAngle:()=>tt,vecAngleBetween:()=>et,vecCeil:()=>nt,vecClamp:()=>ct,vecCross:()=>st,vecDist:()=>Q,vecDist2:()=>v,vecDiv:()=>_,vecDot:()=>W,vecEq:()=>H,vecFloor:()=>at,vecIsZero:()=>ft,vecLerp:()=>it,vecLimit:()=>K,vecMag:()=>R,vecMag2:()=>Y,vecMove:()=>lt,vecMult:()=>d,vecNorm:()=>A,vecRand:()=>ot,vecReflect:()=>Z,vecRotate:()=>q,vecRound:()=>ht,vecSet:()=>P,vecSetMag:()=>J,vecSub:()=>I,wave:()=>V});var g=(e,t,s,i,o,r,a,h)=>{let c=Math.max(e,o),C=Math.min(e+s,o+a)-c,x=Math.max(t,r),m=Math.min(t+i,r+h)-x;return[c,x,C,m]};var S=(e,t,s,i,o,r,a,h)=>{let[c,C,x,m]=g(e,t,s,i,o,r,a,h),f="",T=e,w=t;return x<m?e<o?(f="right",T=o-s):(f="left",T=o+a):t<r?(f="bottom",w=r-i):(f="top",w=r+h),{direction:f,x:T,y:w}};var u=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,s=0,i=0,o=null,r=null){this._engine=t||globalThis,this.ox=s,this.oy=i,this.resize(o||this._engine.WIDTH-s,r||this._engine.HEIGHT-i),this.x=this.width/2,this.y=this.height/2}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.cliprect(this.ox,this.oy,this.width,this.height);let s=this.ox+this.width/2,i=this.oy+this.height/2;this._engine.translate(s,i),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,s,i={}){let o=Math.cos(-this.rotation),r=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=o*t-r*s+this.x,i.y=r*t+o*s+this.y,i}getCameraPoint(t,s,i={}){let o=Math.cos(-this.rotation),r=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=o*t-r*s,s=r*t+o*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,o){let r=this.width/2-this.x,a=this.height/2-this.y,h=this.width/this.scale,c=this.height/this.scale;return this._engine.colrect(t,s,i,o,r,a,h,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 y=class e{_w;_h;_c;constructor(t,s,i=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=i}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}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,o=s?-1:this.length,r=s?-1:1;for(;i!==o;){let a=this.indexToPointX(i),h=this.indexToPointY(i),c=this._c[i];if(t(a,h,c,this)===!1)break;i+=r}}fill(t){this.forEach((s,i)=>{this.set(s,i,t)})}clone(){return e.fromArray(this._w,this._h,this._c)}clampX(t){return O(t,0,this._w-1)}clampY(t){return O(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((o,r,a)=>{i[r]=i[r]||"",i[r]+=a+t}),i.join(`
2
+ `)}},E=class e extends y{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,o)=>{t.set(s,i,o)}),t}};function O(e,t,s){return e<t?t:e>s?s:e}var M=Math.sqrt,X=Math.cos,L=Math.sin,N=2*Math.PI,p=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},l=e=>e instanceof p,n=(e=0,t=e)=>(l(e)&&(t=e.y,e=e.x),new p(e,t)),H=(e,t,s=t)=>l(t)?H(e,t.x,t.y):e.x===t&&e.y===s,P=(e,t,s=t)=>(l(t)?P(e,t.x,t.y):(e.x=t,e.y=s),e),b=(e,t,s=t)=>l(t)?b(e,t.x,t.y):(e.x+=t,e.y+=s,e),I=(e,t,s=t)=>l(t)?I(e,t.x,t.y):(e.x-=t,e.y-=s,e),d=(e,t,s=t)=>l(t)?d(e,t.x,t.y):(e.x*=t,e.y*=s,e),_=(e,t,s=t)=>l(t)?_(e,t.x,t.y):(e.x/=t,e.y/=s,e),q=(e,t)=>{let s=X(t),i=L(t);return e.x=s*e.x-i*e.y,e.y=i*e.x+s*e.y,e},Z=(e,t)=>{let s=A(n(t));return I(e,d(s,2*W(e,s)))},J=(e,t)=>(A(e),d(e,t),e),R=e=>M(e.x*e.x+e.y*e.y),Y=e=>e.x*e.x+e.y*e.y,A=e=>{let t=R(e);return t>0&&_(e,t),e},K=(e,t=1)=>{let s=Y(e);return s>t*t&&(_(e,M(s)),d(e,t)),e},Q=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return M(s*s+i*i)},v=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return s*s+i*i},tt=e=>Math.atan2(e.y,e.x),et=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),W=(e,t)=>e.x*t.x+e.y*t.y,st=(e,t)=>e.x*t.y-e.y*t.x,it=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),ot=(e=1,t=e,s=globalThis.rand||Math.random)=>{let i=s()*N,o=s()*(t-e)+e;return n(X(i)*o,L(i)*o)},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),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),ct=(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),lt=(e,t,s=1)=>b(e,t.x*s,t.y*s),ft=e=>H(e,B),B=n(0,0),ut=n(1,1),pt=n(0,-1),dt=n(1,0),xt=n(0,1),gt=n(-1,0);globalThis.zzfxV=1;var yt=n(.5,.5),F=n(0,0),_t=n(1,0),mt=n(0,1),Tt=n(1,1),D=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,s,i=F){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}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),i=this.sprite.height*(t?this._s.y:1),o=this.pos.x-s*this.anchor.x,r=this.pos.y-i*this.anchor.y;return[o,r,s,i]}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let s=this.sprite.width*this.anchor.x,i=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-s,-i,this.sprite)}};var G=(e,t)=>Math.abs(t-e)||0;var V=(e,t,s,i=Math.sin)=>e+(i(s)+1)/2*(t-e);var j=e=>e%1||0;var z=e=>Array.from(Array(e).keys());globalThis.utils=Object.assign(globalThis.utils||{},k);})();
3
+ /*! @litecanvas/utils by Luiz Bills | MIT Licensed */