@litecanvas/utils 0.5.1 → 0.7.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
@@ -5,6 +5,15 @@
5
5
  __defProp(target, name, { get: all[name], enumerable: true });
6
6
  };
7
7
 
8
+ // src/_global.js
9
+ globalThis.utils = globalThis.utils || {};
10
+ globalThis.utils.global = () => {
11
+ for (const key in globalThis.utils) {
12
+ if ("global" === key) continue;
13
+ globalThis[key] = globalThis.utils[key];
14
+ }
15
+ };
16
+
8
17
  // src/actor/index.js
9
18
  var actor_exports = {};
10
19
  __export(actor_exports, {
@@ -50,7 +59,7 @@
50
59
  /** @type {Image|HTMLCanvasElement|OffscreenCanvas} */
51
60
  sprite;
52
61
  /** @type {Vector} The actor position */
53
- _p;
62
+ pos;
54
63
  /** @type {Vector} The actor anchor (origin) */
55
64
  _o;
56
65
  /** @type {Vector} The actor scale */
@@ -67,7 +76,7 @@
67
76
  */
68
77
  constructor(sprite, position) {
69
78
  this.sprite = sprite;
70
- this._p = position || vec(0);
79
+ this.pos = position || vec(0);
71
80
  this._o = veccopy(ANCHOR_TOP_LEFT);
72
81
  this._s = vec(1, 1);
73
82
  }
@@ -75,25 +84,25 @@
75
84
  * @param {number}
76
85
  */
77
86
  set x(value) {
78
- this._p.x = value;
87
+ this.pos.x = value;
79
88
  }
80
89
  /**
81
90
  * @returns {number}
82
91
  */
83
92
  get x() {
84
- return this._p.x;
93
+ return this.pos.x;
85
94
  }
86
95
  /**
87
96
  * @param {number}
88
97
  */
89
98
  set y(value) {
90
- this._p.y = value;
99
+ this.pos.y = value;
91
100
  }
92
101
  /**
93
102
  * @returns {number}
94
103
  */
95
104
  get y() {
96
- return this._p.y;
105
+ return this.pos.y;
97
106
  }
98
107
  /**
99
108
  * @param {Vector}
@@ -144,7 +153,7 @@
144
153
  * @param {LitecanvasInstance} litecanvas
145
154
  */
146
155
  transform(litecanvas) {
147
- litecanvas.translate(this._p.x, this._p.y);
156
+ litecanvas.translate(this.pos.x, this.pos.y);
148
157
  litecanvas.rotate(this.angle);
149
158
  litecanvas.scale(this._s.x, this._s.y);
150
159
  litecanvas.alpha(this.opacity);
package/dist/actor.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var f=Object.defineProperty;var p=(e,t)=>{for(var r in t)f(e,r,{get:t[r],enumerable:!0})};var a={};p(a,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>x,ANCHOR_CENTER:()=>u,ANCHOR_TOP_LEFT:()=>c,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>n});var s=class{x;y;constructor(t=0,r=t){this.x=t,this.y=r}toString(){return`Vector (${this.x}, ${this.y})`}},o=(e=0,t=e)=>new s(e,t);var i=e=>o(e.x,e.y);var u=o(.5,.5),c=o(0,0),h=o(1,0),d=o(0,1),x=o(1,1),n=class{sprite;_p;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,r){this.sprite=t,this._p=r||o(0),this._o=i(c),this._s=o(1,1)}set x(t){this._p.x=t}get x(){return this._p.x}set y(t){this._p.y=t}get y(){return this._p.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.y}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}draw(t=globalThis){if(this.hidden||this.opacity<=0)return;t.push(),this.transform(t);let r=this.sprite.width*this.anchor.x,l=this.sprite.height*this.anchor.y;t.image(-r,-l,this.sprite),t.pop()}transform(t){t.translate(this._p.x,this._p.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y),t.alpha(this.opacity)}};globalThis.utils=Object.assign(globalThis.utils||{},a);})();
1
+ (()=>{var f=Object.defineProperty;var p=(e,t)=>{for(var s in t)f(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 i={};p(i,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>g,ANCHOR_CENTER:()=>u,ANCHOR_TOP_LEFT:()=>c,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>n});var r=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},o=(e=0,t=e)=>new r(e,t);var a=e=>o(e.x,e.y);var u=o(.5,.5),c=o(0,0),h=o(1,0),d=o(0,1),g=o(1,1),n=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,s){this.sprite=t,this.pos=s||o(0),this._o=a(c),this._s=o(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.y}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}draw(t=globalThis){if(this.hidden||this.opacity<=0)return;t.push(),this.transform(t);let s=this.sprite.width*this.anchor.x,l=this.sprite.height*this.anchor.y;t.image(-s,-l,this.sprite),t.pop()}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y),t.alpha(this.opacity)}};globalThis.utils=Object.assign(globalThis.utils||{},i);})();
package/dist/all.js CHANGED
@@ -5,6 +5,15 @@
5
5
  __defProp(target, name, { get: all[name], enumerable: true });
6
6
  };
7
7
 
8
+ // src/_global.js
9
+ globalThis.utils = globalThis.utils || {};
10
+ globalThis.utils.global = () => {
11
+ for (const key in globalThis.utils) {
12
+ if ("global" === key) continue;
13
+ globalThis[key] = globalThis.utils[key];
14
+ }
15
+ };
16
+
8
17
  // src/index.js
9
18
  var src_exports = {};
10
19
  __export(src_exports, {
@@ -537,7 +546,7 @@
537
546
  /** @type {Image|HTMLCanvasElement|OffscreenCanvas} */
538
547
  sprite;
539
548
  /** @type {Vector} The actor position */
540
- _p;
549
+ pos;
541
550
  /** @type {Vector} The actor anchor (origin) */
542
551
  _o;
543
552
  /** @type {Vector} The actor scale */
@@ -554,7 +563,7 @@
554
563
  */
555
564
  constructor(sprite, position) {
556
565
  this.sprite = sprite;
557
- this._p = position || vec(0);
566
+ this.pos = position || vec(0);
558
567
  this._o = veccopy(ANCHOR_TOP_LEFT);
559
568
  this._s = vec(1, 1);
560
569
  }
@@ -562,25 +571,25 @@
562
571
  * @param {number}
563
572
  */
564
573
  set x(value) {
565
- this._p.x = value;
574
+ this.pos.x = value;
566
575
  }
567
576
  /**
568
577
  * @returns {number}
569
578
  */
570
579
  get x() {
571
- return this._p.x;
580
+ return this.pos.x;
572
581
  }
573
582
  /**
574
583
  * @param {number}
575
584
  */
576
585
  set y(value) {
577
- this._p.y = value;
586
+ this.pos.y = value;
578
587
  }
579
588
  /**
580
589
  * @returns {number}
581
590
  */
582
591
  get y() {
583
- return this._p.y;
592
+ return this.pos.y;
584
593
  }
585
594
  /**
586
595
  * @param {Vector}
@@ -631,7 +640,7 @@
631
640
  * @param {LitecanvasInstance} litecanvas
632
641
  */
633
642
  transform(litecanvas) {
634
- litecanvas.translate(this._p.x, this._p.y);
643
+ litecanvas.translate(this.pos.x, this.pos.y);
635
644
  litecanvas.rotate(this.angle);
636
645
  litecanvas.scale(this._s.x, this._s.y);
637
646
  litecanvas.alpha(this.opacity);
@@ -639,5 +648,5 @@
639
648
  };
640
649
 
641
650
  // src/_web.js
642
- globalThis.utils = src_exports;
651
+ globalThis.utils = Object.assign(globalThis.utils || {}, src_exports);
643
652
  })();
package/dist/all.min.js CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{var L=Object.defineProperty;var v=(e,t)=>{for(var s in t)L(e,s,{get:t[s],enumerable:!0})};var A={};v(A,{ANCHOR_BOT_LEFT:()=>it,ANCHOR_BOT_RIGHT:()=>nt,ANCHOR_CENTER:()=>ot,ANCHOR_TOP_LEFT:()=>W,ANCHOR_TOP_RIGHT:()=>rt,Actor:()=>I,Camera:()=>p,DOWN:()=>et,Grid:()=>u,LEFT:()=>st,ONE:()=>K,RIGHT:()=>tt,UP:()=>Q,Vector:()=>d,ZERO:()=>J,diff:()=>M,fract:()=>P,intersection:()=>g,isvector:()=>c,resolve:()=>O,vec:()=>i,vecadd:()=>S,vecconfig:()=>w,veccopy:()=>H,veccross:()=>V,vecdir:()=>$,vecdist:()=>B,vecdist2:()=>j,vecdiv:()=>_,vecdot:()=>q,veceq:()=>k,veclerp:()=>U,veclimit:()=>F,vecmag:()=>R,vecmag2:()=>Y,vecmult:()=>E,vecnorm:()=>N,vecrand:()=>Z,vecrot:()=>G,vecset:()=>z,vecsub:()=>X,wave:()=>b});var M=(e,t)=>Math.abs(t-e)||0;var P=e=>e%1||0;var b=(e,t,s,o=Math.sin)=>e+(o(s)+1)/2*(t-e);var g=(e,t,s,o,n,r,a,h)=>{let l=Math.max(e,n),D=Math.min(e+s,n+a)-l,x=Math.max(t,r),m=Math.min(t+o,r+h)-x;return[l,x,D,m]};var O=(e,t,s,o,n,r,a,h)=>{let[l,D,x,m]=g(e,t,s,o,n,r,a,h),f="",y=e,T=t;return x<m?e<n?(f="right",y=n-s):(f="left",y=n+a):t<r?(f="bottom",T=r-o):(f="top",T=r+h),{direction:f,x:y,y:T}};var p=class{_engine=null;x=0;y=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null){t=t||globalThis,this._engine=t,this.size(t.WIDTH||0,t.HEIGHT||0),this.x=this.width/2,this.y=this.height/2}size(t,s){this.width=t,this.height=s}start(t=!1){let s=this.width/2,o=this.height/2;this._engine.push(),this._engine.translate(s,o),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y),t&&this._engine.cliprect(this.x,this.y,this.width,this.height)}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}shake(t=.3,s=1){this.shaking()||(this._shake.removeListener=this._engine.listen("update",o=>{this._shake.x=this._engine.randi(-s,s),this._shake.y=this._engine.randi(-s,s),t-=o,t<=0&&this.unshake()}))}unshake(){this.shaking()&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}shaking(){return this._shake.removeListener!==null}};var u=class e{_w;_h;_c;static fromArray(t,s,o){let n=new e(t,s);for(let r=0;r<o.length;r++)n._c[r]=o[r];return n}constructor(t,s){this.width=t,this.height=s,this.clear()}clear(){this._c=Array(this._w*this._h)}set width(t){this._w=Math.max(1,~~t)}get width(){return this._w}set height(t){this._h=Math.max(1,~~t)}get height(){return this._h}set(t,s,o){this._c[this.pointToIndex(t,s)]=o}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 o=s?this.length-1:0,n=s?-1:this.length,r=s?-1:1;for(;o!==n;){let a=this.indexToPointX(o),h=this.indexToPointY(o),l=this._c[o];if(t(a,h,l,this)===!1)break;o+=r}}fill(t){this.forEach((s,o)=>{this.set(s,o,t)})}clone(){return e.fromArray(this._w,this._h,this._c)}clampX(t){return C(t,0,this._w-1)}clampY(t){return C(t,0,this._h-1)}toArray(){return this._c.slice(0)}toString(t=" ",s=!0){if(!s)return this._c.join(t);let o=[];return this.forEach((n,r,a)=>{o[r]=o[r]||"",o[r]+=a+t}),o.join(`
2
- `)}};function C(e,t,s){return e<t?t:e>s?s:e}var d=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},i=(e=0,t=e)=>new d(e,t),k=(e,t,s=t)=>c(t)?k(e,t.x,t.y):e.x===t&&e.y===s,H=e=>i(e.x,e.y),z=(e,t,s=t)=>{c(t)?z(e,t.x,t.y):(e.x=t,e.y=s)},S=(e,t,s=t)=>{c(t)?S(e,t.x,t.y):(e.x+=t,e.y+=s)},X=(e,t,s=t)=>{c(t)?X(e,t.x,t.y):(e.x-=t,e.y-=s)},E=(e,t,s=t)=>{c(t)?E(e,t.x,t.y):(e.x*=t,e.y*=s)},_=(e,t,s=t)=>{c(t)?_(e,t.x,t.y):(e.x/=t,e.y/=s)},G=(e,t)=>{let s=Math.cos(t),o=Math.sin(t);e.x=s*e.x-o*e.y,e.y=o*e.x+s*e.y},R=e=>Math.sqrt(e.x*e.x+e.y*e.y),Y=e=>e.x*e.x+e.y*e.y,N=e=>{let t=R(e);t>0&&_(e,t)},F=(e,t)=>{let s=Y(e);s>t*t&&(_(e,Math.sqrt(s)),E(e,t))},B=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return Math.sqrt(s*s+o*o)},j=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return s*s+o*o},$=e=>Math.atan2(e.y,e.x),q=(e,t)=>e.x*t.x+e.y*t.y,V=(e,t)=>e.x*t.y-e.y*t.x,U=(e,t,s)=>{e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0},Z=(e=1,t=e)=>{let s=w.random()*2*Math.PI,o=w.random()*(t-e)+e;return i(Math.cos(s)*o,Math.sin(s)*o)},c=e=>e instanceof d,w={random:()=>globalThis.rand?rand():Math.random()},J=i(0,0),K=i(1,1),Q=i(0,-1),tt=i(1,0),et=i(0,1),st=i(-1,0);var ot=i(.5,.5),W=i(0,0),rt=i(1,0),it=i(0,1),nt=i(1,1),I=class{sprite;_p;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,s){this.sprite=t,this._p=s||i(0),this._o=H(W),this._s=i(1,1)}set x(t){this._p.x=t}get x(){return this._p.x}set y(t){this._p.y=t}get y(){return this._p.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.y}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}draw(t=globalThis){if(this.hidden||this.opacity<=0)return;t.push(),this.transform(t);let s=this.sprite.width*this.anchor.x,o=this.sprite.height*this.anchor.y;t.image(-s,-o,this.sprite),t.pop()}transform(t){t.translate(this._p.x,this._p.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y),t.alpha(this.opacity)}};globalThis.utils=A;})();
1
+ (()=>{var L=Object.defineProperty;var G=(e,t)=>{for(var s in t)L(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 I={};G(I,{ANCHOR_BOT_LEFT:()=>rt,ANCHOR_BOT_RIGHT:()=>nt,ANCHOR_CENTER:()=>ot,ANCHOR_TOP_LEFT:()=>W,ANCHOR_TOP_RIGHT:()=>it,Actor:()=>b,Camera:()=>p,DOWN:()=>et,Grid:()=>u,LEFT:()=>st,ONE:()=>K,RIGHT:()=>tt,UP:()=>Q,Vector:()=>d,ZERO:()=>J,diff:()=>D,fract:()=>M,intersection:()=>x,isvector:()=>l,resolve:()=>O,vec:()=>r,vecadd:()=>S,vecconfig:()=>w,veccopy:()=>H,veccross:()=>V,vecdir:()=>q,vecdist:()=>j,vecdist2:()=>$,vecdiv:()=>_,vecdot:()=>N,veceq:()=>k,veclerp:()=>U,veclimit:()=>B,vecmag:()=>R,vecmag2:()=>Y,vecmult:()=>E,vecnorm:()=>F,vecrand:()=>Z,vecrot:()=>v,vecset:()=>z,vecsub:()=>X,wave:()=>P});var D=(e,t)=>Math.abs(t-e)||0;var M=e=>e%1||0;var P=(e,t,s,o=Math.sin)=>e+(o(s)+1)/2*(t-e);var x=(e,t,s,o,n,i,a,c)=>{let h=Math.max(e,n),A=Math.min(e+s,n+a)-h,g=Math.max(t,i),m=Math.min(t+o,i+c)-g;return[h,g,A,m]};var O=(e,t,s,o,n,i,a,c)=>{let[h,A,g,m]=x(e,t,s,o,n,i,a,c),f="",y=e,T=t;return g<m?e<n?(f="right",y=n-s):(f="left",y=n+a):t<i?(f="bottom",T=i-o):(f="top",T=i+c),{direction:f,x:y,y:T}};var p=class{_engine=null;x=0;y=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null){t=t||globalThis,this._engine=t,this.size(t.WIDTH||0,t.HEIGHT||0),this.x=this.width/2,this.y=this.height/2}size(t,s){this.width=t,this.height=s}start(t=!1){let s=this.width/2,o=this.height/2;this._engine.push(),this._engine.translate(s,o),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y),t&&this._engine.cliprect(this.x,this.y,this.width,this.height)}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}shake(t=.3,s=1){this.shaking()||(this._shake.removeListener=this._engine.listen("update",o=>{this._shake.x=this._engine.randi(-s,s),this._shake.y=this._engine.randi(-s,s),t-=o,t<=0&&this.unshake()}))}unshake(){this.shaking()&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}shaking(){return this._shake.removeListener!==null}};var u=class e{_w;_h;_c;static fromArray(t,s,o){let n=new e(t,s);for(let i=0;i<o.length;i++)n._c[i]=o[i];return n}constructor(t,s){this.width=t,this.height=s,this.clear()}clear(){this._c=Array(this._w*this._h)}set width(t){this._w=Math.max(1,~~t)}get width(){return this._w}set height(t){this._h=Math.max(1,~~t)}get height(){return this._h}set(t,s,o){this._c[this.pointToIndex(t,s)]=o}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 o=s?this.length-1:0,n=s?-1:this.length,i=s?-1:1;for(;o!==n;){let a=this.indexToPointX(o),c=this.indexToPointY(o),h=this._c[o];if(t(a,c,h,this)===!1)break;o+=i}}fill(t){this.forEach((s,o)=>{this.set(s,o,t)})}clone(){return e.fromArray(this._w,this._h,this._c)}clampX(t){return C(t,0,this._w-1)}clampY(t){return C(t,0,this._h-1)}toArray(){return this._c.slice(0)}toString(t=" ",s=!0){if(!s)return this._c.join(t);let o=[];return this.forEach((n,i,a)=>{o[i]=o[i]||"",o[i]+=a+t}),o.join(`
2
+ `)}};function C(e,t,s){return e<t?t:e>s?s:e}var d=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},r=(e=0,t=e)=>new d(e,t),k=(e,t,s=t)=>l(t)?k(e,t.x,t.y):e.x===t&&e.y===s,H=e=>r(e.x,e.y),z=(e,t,s=t)=>{l(t)?z(e,t.x,t.y):(e.x=t,e.y=s)},S=(e,t,s=t)=>{l(t)?S(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)},E=(e,t,s=t)=>{l(t)?E(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)},v=(e,t)=>{let s=Math.cos(t),o=Math.sin(t);e.x=s*e.x-o*e.y,e.y=o*e.x+s*e.y},R=e=>Math.sqrt(e.x*e.x+e.y*e.y),Y=e=>e.x*e.x+e.y*e.y,F=e=>{let t=R(e);t>0&&_(e,t)},B=(e,t)=>{let s=Y(e);s>t*t&&(_(e,Math.sqrt(s)),E(e,t))},j=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return Math.sqrt(s*s+o*o)},$=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return s*s+o*o},q=e=>Math.atan2(e.y,e.x),N=(e,t)=>e.x*t.x+e.y*t.y,V=(e,t)=>e.x*t.y-e.y*t.x,U=(e,t,s)=>{e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0},Z=(e=1,t=e)=>{let s=w.random()*2*Math.PI,o=w.random()*(t-e)+e;return r(Math.cos(s)*o,Math.sin(s)*o)},l=e=>e instanceof d,w={random:()=>globalThis.rand?rand():Math.random()},J=r(0,0),K=r(1,1),Q=r(0,-1),tt=r(1,0),et=r(0,1),st=r(-1,0);var ot=r(.5,.5),W=r(0,0),it=r(1,0),rt=r(0,1),nt=r(1,1),b=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,s){this.sprite=t,this.pos=s||r(0),this._o=H(W),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.y}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}draw(t=globalThis){if(this.hidden||this.opacity<=0)return;t.push(),this.transform(t);let s=this.sprite.width*this.anchor.x,o=this.sprite.height*this.anchor.y;t.image(-s,-o,this.sprite),t.pop()}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y),t.alpha(this.opacity)}};globalThis.utils=Object.assign(globalThis.utils||{},I);})();
package/dist/camera.js CHANGED
@@ -1,4 +1,13 @@
1
1
  (() => {
2
+ // src/_global.js
3
+ globalThis.utils = globalThis.utils || {};
4
+ globalThis.utils.global = () => {
5
+ for (const key in globalThis.utils) {
6
+ if ("global" === key) continue;
7
+ globalThis[key] = globalThis.utils[key];
8
+ }
9
+ };
10
+
2
11
  // src/camera/index.js
3
12
  var Camera = class {
4
13
  /** @type {LitecanvasInstance} */
@@ -1 +1 @@
1
- (()=>{var i=class{_engine=null;x=0;y=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null){t=t||globalThis,this._engine=t,this.size(t.WIDTH||0,t.HEIGHT||0),this.x=this.width/2,this.y=this.height/2}size(t,s){this.width=t,this.height=s}start(t=!1){let s=this.width/2,h=this.height/2;this._engine.push(),this._engine.translate(s,h),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y),t&&this._engine.cliprect(this.x,this.y,this.width,this.height)}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}shake(t=.3,s=1){this.shaking()||(this._shake.removeListener=this._engine.listen("update",h=>{this._shake.x=this._engine.randi(-s,s),this._shake.y=this._engine.randi(-s,s),t-=h,t<=0&&this.unshake()}))}unshake(){this.shaking()&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}shaking(){return this._shake.removeListener!==null}};globalThis.utils=Object.assign(globalThis.utils||{},{Camera:i});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let h in globalThis.utils)h!=="global"&&(globalThis[h]=globalThis.utils[h])};var t=class{_engine=null;x=0;y=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(i=null){i=i||globalThis,this._engine=i,this.size(i.WIDTH||0,i.HEIGHT||0),this.x=this.width/2,this.y=this.height/2}size(i,s){this.width=i,this.height=s}start(i=!1){let s=this.width/2,e=this.height/2;this._engine.push(),this._engine.translate(s,e),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y),i&&this._engine.cliprect(this.x,this.y,this.width,this.height)}end(){this._engine.pop()}lookAt(i,s){this.x=i,this.y=s}move(i,s){this.x+=i,this.y+=s}zoom(i){this.scale*=i}zoomTo(i){this.scale=i}rotate(i){this.rotation+=i}rotateTo(i){this.rotation=i}shake(i=.3,s=1){this.shaking()||(this._shake.removeListener=this._engine.listen("update",e=>{this._shake.x=this._engine.randi(-s,s),this._shake.y=this._engine.randi(-s,s),i-=e,i<=0&&this.unshake()}))}unshake(){this.shaking()&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}shaking(){return this._shake.removeListener!==null}};globalThis.utils=Object.assign(globalThis.utils||{},{Camera:t});})();
package/dist/collision.js CHANGED
@@ -1,4 +1,13 @@
1
1
  (() => {
2
+ // src/_global.js
3
+ globalThis.utils = globalThis.utils || {};
4
+ globalThis.utils.global = () => {
5
+ for (const key in globalThis.utils) {
6
+ if ("global" === key) continue;
7
+ globalThis[key] = globalThis.utils[key];
8
+ }
9
+ };
10
+
2
11
  // src/collision/intersection.js
3
12
  var intersection_default = (x1, y1, w1, h1, x2, y2, w2, h2) => {
4
13
  const left = Math.max(x1, x2);
@@ -1 +1 @@
1
- (()=>{var h=(o,i,r,s,t,e,n,a)=>{let m=Math.max(o,t),u=Math.min(o+r,t+n)-m,f=Math.max(i,e),c=Math.min(i+s,e+a)-f;return[m,f,u,c]};var d=(o,i,r,s,t,e,n,a)=>{let[m,u,f,c]=h(o,i,r,s,t,e,n,a),l="",p=o,g=i;return f<c?o<t?(l="right",p=t-r):(l="left",p=t+n):i<e?(l="bottom",g=e-s):(l="top",g=e+a),{direction:l,x:p,y:g}};globalThis.utils=Object.assign(globalThis.utils||{},{resolve:d,intersection:h});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var g=(t,o,s,r,l,i,a,n)=>{let f=Math.max(t,l),c=Math.min(t+s,l+a)-f,h=Math.max(o,i),b=Math.min(o+r,i+n)-h;return[f,h,c,b]};var p=(t,o,s,r,l,i,a,n)=>{let[f,c,h,b]=g(t,o,s,r,l,i,a,n),e="",m=t,u=o;return h<b?t<l?(e="right",m=l-s):(e="left",m=l+a):o<i?(e="bottom",u=i-r):(e="top",u=i+n),{direction:e,x:m,y:u}};globalThis.utils=Object.assign(globalThis.utils||{},{resolve:p,intersection:g});})();
package/dist/grid.js CHANGED
@@ -1,4 +1,13 @@
1
1
  (() => {
2
+ // src/_global.js
3
+ globalThis.utils = globalThis.utils || {};
4
+ globalThis.utils.global = () => {
5
+ for (const key in globalThis.utils) {
6
+ if ("global" === key) continue;
7
+ globalThis[key] = globalThis.utils[key];
8
+ }
9
+ };
10
+
2
11
  // src/grid/index.js
3
12
  var Grid = class _Grid {
4
13
  /** @type {number} The grid width */
package/dist/grid.min.js CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{var e=class s{_w;_h;_c;static fromArray(t,i,h){let n=new s(t,i);for(let r=0;r<h.length;r++)n._c[r]=h[r];return n}constructor(t,i){this.width=t,this.height=i,this.clear()}clear(){this._c=Array(this._w*this._h)}set width(t){this._w=Math.max(1,~~t)}get width(){return this._w}set height(t){this._h=Math.max(1,~~t)}get height(){return this._h}set(t,i,h){this._c[this.pointToIndex(t,i)]=h}get(t,i){return this._c[this.pointToIndex(t,i)]}has(t,i){return this.get(t,i)!=null}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 h=i?this.length-1:0,n=i?-1:this.length,r=i?-1:1;for(;h!==n;){let o=this.indexToPointX(h),c=this.indexToPointY(h),_=this._c[h];if(t(o,c,_,this)===!1)break;h+=r}}fill(t){this.forEach((i,h)=>{this.set(i,h,t)})}clone(){return s.fromArray(this._w,this._h,this._c)}clampX(t){return l(t,0,this._w-1)}clampY(t){return l(t,0,this._h-1)}toArray(){return this._c.slice(0)}toString(t=" ",i=!0){if(!i)return this._c.join(t);let h=[];return this.forEach((n,r,o)=>{h[r]=h[r]||"",h[r]+=o+t}),h.join(`
2
- `)}};function l(s,t,i){return s<t?t:s>i?i:s}globalThis.utils=Object.assign(globalThis.utils||{},{Grid:e});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let s in globalThis.utils)s!=="global"&&(globalThis[s]=globalThis.utils[s])};var n=class s{_w;_h;_c;static fromArray(t,i,h){let l=new s(t,i);for(let r=0;r<h.length;r++)l._c[r]=h[r];return l}constructor(t,i){this.width=t,this.height=i,this.clear()}clear(){this._c=Array(this._w*this._h)}set width(t){this._w=Math.max(1,~~t)}get width(){return this._w}set height(t){this._h=Math.max(1,~~t)}get height(){return this._h}set(t,i,h){this._c[this.pointToIndex(t,i)]=h}get(t,i){return this._c[this.pointToIndex(t,i)]}has(t,i){return this.get(t,i)!=null}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 h=i?this.length-1:0,l=i?-1:this.length,r=i?-1:1;for(;h!==l;){let e=this.indexToPointX(h),c=this.indexToPointY(h),a=this._c[h];if(t(e,c,a,this)===!1)break;h+=r}}fill(t){this.forEach((i,h)=>{this.set(i,h,t)})}clone(){return s.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(0)}toString(t=" ",i=!0){if(!i)return this._c.join(t);let h=[];return this.forEach((l,r,e)=>{h[r]=h[r]||"",h[r]+=e+t}),h.join(`
2
+ `)}};function o(s,t,i){return s<t?t:s>i?i:s}globalThis.utils=Object.assign(globalThis.utils||{},{Grid:n});})();
package/dist/math.js CHANGED
@@ -1,4 +1,13 @@
1
1
  (() => {
2
+ // src/_global.js
3
+ globalThis.utils = globalThis.utils || {};
4
+ globalThis.utils.global = () => {
5
+ for (const key in globalThis.utils) {
6
+ if ("global" === key) continue;
7
+ globalThis[key] = globalThis.utils[key];
8
+ }
9
+ };
10
+
2
11
  // src/math/diff.js
3
12
  var diff_default = (a, b) => Math.abs(b - a) || 0;
4
13
 
package/dist/math.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var i=(t,a)=>Math.abs(a-t)||0;var o=(t,a,r,l=Math.sin)=>t+(l(r)+1)/2*(a-t);var f=t=>t%1||0;globalThis.utils=Object.assign(globalThis.utils||{},{diff:i,wave:o,fract:f});})();
1
+ (()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let l in globalThis.utils)l!=="global"&&(globalThis[l]=globalThis.utils[l])};var t=(l,i)=>Math.abs(i-l)||0;var o=(l,i,a,b=Math.sin)=>l+(b(a)+1)/2*(i-l);var s=l=>l%1||0;globalThis.utils=Object.assign(globalThis.utils||{},{diff:t,wave:o,fract:s});})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litecanvas/utils",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "description": "Utilities to help build litecanvas games",
5
5
  "author": "Luiz Bills <luizbills@pm.me>",
6
6
  "license": "MIT",
package/src/_global.js ADDED
@@ -0,0 +1,8 @@
1
+ globalThis.utils = globalThis.utils || {}
2
+
3
+ globalThis.utils.global = () => {
4
+ for (const key in globalThis.utils) {
5
+ if ("global" === key) continue
6
+ globalThis[key] = globalThis.utils[key]
7
+ }
8
+ }
package/src/_web.js CHANGED
@@ -1,3 +1,4 @@
1
+ import "./_global.js"
1
2
  import * as utils from "./index.js"
2
3
 
3
- globalThis.utils = utils
4
+ globalThis.utils = Object.assign(globalThis.utils || {}, utils)
@@ -36,9 +36,18 @@ function draw() {
36
36
  }
37
37
  ```
38
38
 
39
+ ## Actor#pos
40
+
41
+ Set or get the actor position vector
42
+
43
+ ```js
44
+ player.pos.x = 100
45
+ player.pos.x = 200
46
+ ```
47
+
39
48
  ## Actor#x / Actor#y
40
49
 
41
- Set or get the actor position
50
+ Set or get the actor position X or Y
42
51
 
43
52
  ```js
44
53
  player.x = 100
@@ -122,7 +131,7 @@ Get (not set) the actor current height.
122
131
  ```js
123
132
  console.log(player.height) // => 30
124
133
 
125
- player.scale.x = 2
134
+ player.scale.y = 2
126
135
 
127
136
  console.log(player.height) // => 60
128
137
  ```
package/src/actor/_web.js CHANGED
@@ -1,3 +1,4 @@
1
+ import "../_global.js"
1
2
  import * as actorUtils from "./index.js"
2
3
 
3
4
  globalThis.utils = Object.assign(globalThis.utils || {}, actorUtils)
@@ -12,7 +12,7 @@ export class Actor {
12
12
  sprite
13
13
 
14
14
  /** @type {Vector} The actor position */
15
- _p
15
+ pos
16
16
 
17
17
  /** @type {Vector} The actor anchor (origin) */
18
18
  _o
@@ -35,7 +35,7 @@ export class Actor {
35
35
  */
36
36
  constructor(sprite, position) {
37
37
  this.sprite = sprite
38
- this._p = position || vec(0)
38
+ this.pos = position || vec(0)
39
39
  this._o = veccopy(ANCHOR_TOP_LEFT)
40
40
  this._s = vec(1, 1)
41
41
  }
@@ -44,28 +44,28 @@ export class Actor {
44
44
  * @param {number}
45
45
  */
46
46
  set x(value) {
47
- this._p.x = value
47
+ this.pos.x = value
48
48
  }
49
49
 
50
50
  /**
51
51
  * @returns {number}
52
52
  */
53
53
  get x() {
54
- return this._p.x
54
+ return this.pos.x
55
55
  }
56
56
 
57
57
  /**
58
58
  * @param {number}
59
59
  */
60
60
  set y(value) {
61
- this._p.y = value
61
+ this.pos.y = value
62
62
  }
63
63
 
64
64
  /**
65
65
  * @returns {number}
66
66
  */
67
67
  get y() {
68
- return this._p.y
68
+ return this.pos.y
69
69
  }
70
70
 
71
71
  /**
@@ -127,7 +127,7 @@ export class Actor {
127
127
  * @param {LitecanvasInstance} litecanvas
128
128
  */
129
129
  transform(litecanvas) {
130
- litecanvas.translate(this._p.x, this._p.y)
130
+ litecanvas.translate(this.pos.x, this.pos.y)
131
131
  litecanvas.rotate(this.angle)
132
132
  litecanvas.scale(this._s.x, this._s.y)
133
133
  litecanvas.alpha(this.opacity)
@@ -1,3 +1,4 @@
1
+ import "../_global.js"
1
2
  import Camera from "./index.js"
2
3
 
3
4
  globalThis.utils = Object.assign(globalThis.utils || {}, { Camera })
@@ -1,3 +1,4 @@
1
+ import "../_global.js"
1
2
  import resolve from "./resolve.js"
2
3
  import intersection from "./intersection.js"
3
4
 
package/src/grid/_web.js CHANGED
@@ -1,3 +1,4 @@
1
+ import "../_global.js"
1
2
  import Grid from "./index.js"
2
3
 
3
4
  globalThis.utils = Object.assign(globalThis.utils || {}, { Grid })
package/src/math/_web.js CHANGED
@@ -1,3 +1,4 @@
1
+ import "../_global.js"
1
2
  import diff from "./diff.js"
2
3
  import wave from "./wave.js"
3
4
  import fract from "./fract.js"