@litecanvas/utils 0.26.0 → 0.28.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 +1 -0
- package/dist/actor.js +7 -5
- package/dist/actor.min.js +1 -1
- package/dist/all.js +31 -9
- package/dist/all.min.js +2 -2
- package/dist/camera.js +4 -2
- package/dist/camera.min.js +1 -1
- package/dist/collision.js +4 -2
- package/dist/collision.min.js +1 -1
- package/dist/grid.js +7 -5
- package/dist/grid.min.js +1 -1
- package/dist/image.js +4 -2
- package/dist/image.min.js +1 -1
- package/dist/math.js +29 -5
- package/dist/math.min.js +1 -1
- package/dist/noise.js +7 -5
- package/dist/noise.min.js +1 -1
- package/dist/tween.js +7 -5
- package/dist/tween.min.js +1 -1
- package/dist/vector.js +5 -7
- package/dist/vector.min.js +1 -1
- package/package.json +4 -4
- package/src/_global.js +4 -2
- package/src/actor/README.md +9 -9
- package/src/camera/README.md +7 -3
- package/src/math/dist.js +12 -0
- package/src/math/index.js +3 -0
- package/src/math/mag.js +10 -0
- package/src/math/roundd.js +14 -0
- package/src/vector/index.js +2 -4
package/README.md
CHANGED
|
@@ -50,4 +50,5 @@ const pos = vec(0, 0)
|
|
|
50
50
|
- **Grid**: class to handle retangular grid areas. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/grid)
|
|
51
51
|
- **Collision** utilities. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/collision)
|
|
52
52
|
- **Tween** to create animations. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/tween)
|
|
53
|
+
- **Image** to manipulate images. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/image)
|
|
53
54
|
- And some [math utilities](https://github.com/litecanvas/utils/tree/main/src/math)...
|
package/dist/actor.js
CHANGED
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
// src/_global.js
|
|
9
9
|
globalThis.utils = globalThis.utils || {};
|
|
10
|
-
globalThis.utils.global = () => {
|
|
10
|
+
globalThis.utils.global = (overrides = true) => {
|
|
11
11
|
for (const key in globalThis.utils) {
|
|
12
12
|
if ("global" === key) continue;
|
|
13
|
-
globalThis[key]
|
|
13
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
14
|
+
globalThis[key] = globalThis.utils[key];
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
// src/actor/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
20
22
|
ANCHOR_BOT_LEFT: () => ANCHOR_BOT_LEFT,
|
|
21
23
|
ANCHOR_BOT_RIGHT: () => ANCHOR_BOT_RIGHT,
|
|
22
24
|
ANCHOR_CENTER: () => ANCHOR_CENTER,
|
|
@@ -213,5 +215,5 @@
|
|
|
213
215
|
};
|
|
214
216
|
|
|
215
217
|
// src/actor/_web.js
|
|
216
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
218
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
217
219
|
})();
|
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
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);})();
|
package/dist/all.js
CHANGED
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
// src/_global.js
|
|
9
9
|
globalThis.utils = globalThis.utils || {};
|
|
10
|
-
globalThis.utils.global = () => {
|
|
10
|
+
globalThis.utils.global = (overrides = true) => {
|
|
11
11
|
for (const key in globalThis.utils) {
|
|
12
12
|
if ("global" === key) continue;
|
|
13
|
-
globalThis[key]
|
|
13
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
14
|
+
globalThis[key] = globalThis.utils[key];
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
// src/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
20
22
|
ANCHOR_BOT_LEFT: () => ANCHOR_BOT_LEFT,
|
|
21
23
|
ANCHOR_BOT_RIGHT: () => ANCHOR_BOT_RIGHT,
|
|
22
24
|
ANCHOR_CENTER: () => ANCHOR_CENTER,
|
|
@@ -49,12 +51,15 @@
|
|
|
49
51
|
ZERO: () => ZERO,
|
|
50
52
|
advance: () => advance_default,
|
|
51
53
|
diff: () => diff_default,
|
|
54
|
+
dist: () => dist_default,
|
|
52
55
|
flipImage: () => flip_default,
|
|
53
56
|
fract: () => fract_default,
|
|
54
57
|
intersection: () => intersection_default,
|
|
58
|
+
mag: () => mag_default,
|
|
55
59
|
mod: () => mod_default,
|
|
56
60
|
range: () => range_default,
|
|
57
61
|
resolve: () => resolve_default,
|
|
62
|
+
roundd: () => roundd_default,
|
|
58
63
|
scaleImage: () => scale_default,
|
|
59
64
|
tint: () => tint_default,
|
|
60
65
|
tween: () => tween,
|
|
@@ -655,7 +660,7 @@
|
|
|
655
660
|
vecMult(v, value);
|
|
656
661
|
return v;
|
|
657
662
|
};
|
|
658
|
-
var vecMag = (v) =>
|
|
663
|
+
var vecMag = (v) => Math.hypot(v.x, v.y);
|
|
659
664
|
var vecMag2 = (v) => v.x * v.x + v.y * v.y;
|
|
660
665
|
var vecNorm = (v) => {
|
|
661
666
|
const length = vecMag(v);
|
|
@@ -673,9 +678,7 @@
|
|
|
673
678
|
return v;
|
|
674
679
|
};
|
|
675
680
|
var vecDist = (a, b) => {
|
|
676
|
-
|
|
677
|
-
const dy = a.y - b.y;
|
|
678
|
-
return sqrt(dx * dx + dy * dy);
|
|
681
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
679
682
|
};
|
|
680
683
|
var vecDist2 = (a, b) => {
|
|
681
684
|
const dx = a.x - b.x;
|
|
@@ -913,6 +916,25 @@
|
|
|
913
916
|
// src/math/mod.js
|
|
914
917
|
var mod_default = (a, b) => (b + a % b) % b;
|
|
915
918
|
|
|
919
|
+
// src/math/roundd.js
|
|
920
|
+
var roundd_default = (n, precision = 0) => {
|
|
921
|
+
if (!precision) {
|
|
922
|
+
return Math.round(n);
|
|
923
|
+
}
|
|
924
|
+
const multiplier = Math.pow(10, precision);
|
|
925
|
+
return Math.round(n * multiplier) / multiplier;
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
// src/math/dist.js
|
|
929
|
+
var dist_default = (x1, y1, x2, y2) => {
|
|
930
|
+
return Math.hypot(x2 - x1, y2 - y1);
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
// src/math/mag.js
|
|
934
|
+
var mag_default = (x, y) => {
|
|
935
|
+
return Math.hypot(x, y);
|
|
936
|
+
};
|
|
937
|
+
|
|
916
938
|
// src/tween/index.js
|
|
917
939
|
var HALF_PI = Math.PI / 2;
|
|
918
940
|
var tween = (object, prop, toValue, duration = 1, easing = LINEAR) => {
|
|
@@ -1296,6 +1318,6 @@
|
|
|
1296
1318
|
};
|
|
1297
1319
|
|
|
1298
1320
|
// src/_web.js
|
|
1299
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
1321
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
1300
1322
|
})();
|
|
1301
1323
|
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/all.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`)}},
|
|
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);})();
|
|
3
3
|
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/camera.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
// src/_global.js
|
|
3
3
|
globalThis.utils = globalThis.utils || {};
|
|
4
|
-
globalThis.utils.global = () => {
|
|
4
|
+
globalThis.utils.global = (overrides = true) => {
|
|
5
5
|
for (const key in globalThis.utils) {
|
|
6
6
|
if ("global" === key) continue;
|
|
7
|
-
globalThis[key]
|
|
7
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
8
|
+
globalThis[key] = globalThis.utils[key];
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
11
|
};
|
|
10
12
|
|
package/dist/camera.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let
|
|
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});})();
|
package/dist/collision.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
// src/_global.js
|
|
3
3
|
globalThis.utils = globalThis.utils || {};
|
|
4
|
-
globalThis.utils.global = () => {
|
|
4
|
+
globalThis.utils.global = (overrides = true) => {
|
|
5
5
|
for (const key in globalThis.utils) {
|
|
6
6
|
if ("global" === key) continue;
|
|
7
|
-
globalThis[key]
|
|
7
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
8
|
+
globalThis[key] = globalThis.utils[key];
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
11
|
};
|
|
10
12
|
|
package/dist/collision.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var
|
|
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
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
// src/_global.js
|
|
9
9
|
globalThis.utils = globalThis.utils || {};
|
|
10
|
-
globalThis.utils.global = () => {
|
|
10
|
+
globalThis.utils.global = (overrides = true) => {
|
|
11
11
|
for (const key in globalThis.utils) {
|
|
12
12
|
if ("global" === key) continue;
|
|
13
|
-
globalThis[key]
|
|
13
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
14
|
+
globalThis[key] = globalThis.utils[key];
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
// src/grid/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
20
22
|
Grid: () => Grid,
|
|
21
23
|
TypedGrid: () => TypedGrid
|
|
22
24
|
});
|
|
@@ -250,5 +252,5 @@
|
|
|
250
252
|
}
|
|
251
253
|
|
|
252
254
|
// src/grid/_web.js
|
|
253
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
255
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
254
256
|
})();
|
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=()=>{for(let
|
|
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,10 +1,12 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
// src/_global.js
|
|
3
3
|
globalThis.utils = globalThis.utils || {};
|
|
4
|
-
globalThis.utils.global = () => {
|
|
4
|
+
globalThis.utils.global = (overrides = true) => {
|
|
5
5
|
for (const key in globalThis.utils) {
|
|
6
6
|
if ("global" === key) continue;
|
|
7
|
-
globalThis[key]
|
|
7
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
8
|
+
globalThis[key] = globalThis.utils[key];
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
11
|
};
|
|
10
12
|
|
package/dist/image.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let
|
|
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});})();
|
package/dist/math.js
CHANGED
|
@@ -7,21 +7,26 @@
|
|
|
7
7
|
|
|
8
8
|
// src/_global.js
|
|
9
9
|
globalThis.utils = globalThis.utils || {};
|
|
10
|
-
globalThis.utils.global = () => {
|
|
10
|
+
globalThis.utils.global = (overrides = true) => {
|
|
11
11
|
for (const key in globalThis.utils) {
|
|
12
12
|
if ("global" === key) continue;
|
|
13
|
-
globalThis[key]
|
|
13
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
14
|
+
globalThis[key] = globalThis.utils[key];
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
// src/math/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
20
22
|
advance: () => advance_default,
|
|
21
23
|
diff: () => diff_default,
|
|
24
|
+
dist: () => dist_default,
|
|
22
25
|
fract: () => fract_default,
|
|
26
|
+
mag: () => mag_default,
|
|
23
27
|
mod: () => mod_default,
|
|
24
28
|
range: () => range_default,
|
|
29
|
+
roundd: () => roundd_default,
|
|
25
30
|
wave: () => wave_default
|
|
26
31
|
});
|
|
27
32
|
|
|
@@ -53,6 +58,25 @@
|
|
|
53
58
|
// src/math/mod.js
|
|
54
59
|
var mod_default = (a, b) => (b + a % b) % b;
|
|
55
60
|
|
|
61
|
+
// src/math/roundd.js
|
|
62
|
+
var roundd_default = (n, precision = 0) => {
|
|
63
|
+
if (!precision) {
|
|
64
|
+
return Math.round(n);
|
|
65
|
+
}
|
|
66
|
+
const multiplier = Math.pow(10, precision);
|
|
67
|
+
return Math.round(n * multiplier) / multiplier;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/math/dist.js
|
|
71
|
+
var dist_default = (x1, y1, x2, y2) => {
|
|
72
|
+
return Math.hypot(x2 - x1, y2 - y1);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/math/mag.js
|
|
76
|
+
var mag_default = (x, y) => {
|
|
77
|
+
return Math.hypot(x, y);
|
|
78
|
+
};
|
|
79
|
+
|
|
56
80
|
// src/math/_web.js
|
|
57
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
81
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
58
82
|
})();
|
package/dist/math.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
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);})();
|
package/dist/noise.js
CHANGED
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
// src/_global.js
|
|
9
9
|
globalThis.utils = globalThis.utils || {};
|
|
10
|
-
globalThis.utils.global = () => {
|
|
10
|
+
globalThis.utils.global = (overrides = true) => {
|
|
11
11
|
for (const key in globalThis.utils) {
|
|
12
12
|
if ("global" === key) continue;
|
|
13
|
-
globalThis[key]
|
|
13
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
14
|
+
globalThis[key] = globalThis.utils[key];
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
// src/noise/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
20
22
|
Noise: () => Noise
|
|
21
23
|
});
|
|
22
24
|
var PERLIN_YWRAPB = 4;
|
|
@@ -149,5 +151,5 @@
|
|
|
149
151
|
};
|
|
150
152
|
|
|
151
153
|
// src/noise/_web.js
|
|
152
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
154
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
153
155
|
})();
|
package/dist/noise.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
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);})();
|
package/dist/tween.js
CHANGED
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
// src/_global.js
|
|
9
9
|
globalThis.utils = globalThis.utils || {};
|
|
10
|
-
globalThis.utils.global = () => {
|
|
10
|
+
globalThis.utils.global = (overrides = true) => {
|
|
11
11
|
for (const key in globalThis.utils) {
|
|
12
12
|
if ("global" === key) continue;
|
|
13
|
-
globalThis[key]
|
|
13
|
+
if (overrides || globalThis[key] !== void 0) {
|
|
14
|
+
globalThis[key] = globalThis.utils[key];
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
// src/tween/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
20
22
|
BACK_IN: () => BACK_IN,
|
|
21
23
|
BACK_IN_OUT: () => BACK_IN_OUT,
|
|
22
24
|
BACK_OUT: () => BACK_OUT,
|
|
@@ -250,5 +252,5 @@
|
|
|
250
252
|
};
|
|
251
253
|
|
|
252
254
|
// src/tween/_web.js
|
|
253
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
255
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
254
256
|
})();
|
package/dist/tween.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
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);})();
|
package/dist/vector.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/vector/index.js
|
|
9
|
-
var
|
|
10
|
-
__export(
|
|
9
|
+
var index_exports = {};
|
|
10
|
+
__export(index_exports, {
|
|
11
11
|
DOWN: () => DOWN,
|
|
12
12
|
LEFT: () => LEFT,
|
|
13
13
|
ONE: () => ONE,
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
vecMult(v, value);
|
|
140
140
|
return v;
|
|
141
141
|
};
|
|
142
|
-
var vecMag = (v) =>
|
|
142
|
+
var vecMag = (v) => Math.hypot(v.x, v.y);
|
|
143
143
|
var vecMag2 = (v) => v.x * v.x + v.y * v.y;
|
|
144
144
|
var vecNorm = (v) => {
|
|
145
145
|
const length = vecMag(v);
|
|
@@ -157,9 +157,7 @@
|
|
|
157
157
|
return v;
|
|
158
158
|
};
|
|
159
159
|
var vecDist = (a, b) => {
|
|
160
|
-
|
|
161
|
-
const dy = a.y - b.y;
|
|
162
|
-
return sqrt(dx * dx + dy * dy);
|
|
160
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
163
161
|
};
|
|
164
162
|
var vecDist2 = (a, b) => {
|
|
165
163
|
const dx = a.x - b.x;
|
|
@@ -217,5 +215,5 @@
|
|
|
217
215
|
var LEFT = /* @__PURE__ */ vec(-1, 0);
|
|
218
216
|
|
|
219
217
|
// src/vector/_web.js
|
|
220
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
218
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
221
219
|
})();
|
package/dist/vector.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var q=Object.defineProperty;var A=(t,e)=>{for(var o in e)q(t,o,{get:e[o],enumerable:!0})};var a={};A(a,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>T,vec:()=>r,vecAbs:()=>j,vecAdd:()=>u,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>B,vecClamp:()=>H,vecCross:()=>U,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>x,vecDot:()=>D,vecEq:()=>p,vecFloor:()=>F,vecIsZero:()=>W,vecLerp:()=>Z,vecLimit:()=>b,vecMag:()=>d,vecMag2:()=>R,vecMove:()=>V,vecMult:()=>y,vecNorm:()=>h,vecRand:()=>$,vecReflect:()=>O,vecRotate:()=>I,vecRound:()=>G,vecSet:()=>g,vecSetMag:()=>S,vecSub:()=>i});var C=Math.sqrt,M=Math.cos,f=Math.sin,E=2*Math.PI,s=class{x;y;constructor(e=0,o=e){this.x=e,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof s,r=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new s(t,e)),p=(t,e,o=e)=>n(e)?p(t,e.x,e.y):t.x===e&&t.y===o,g=(t,e,o=e)=>(n(e)?g(t,e.x,e.y):(t.x=e,t.y=o),t),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):(t.x+=e,t.y+=o,t),i=(t,e,o=e)=>n(e)?i(t,e.x,e.y):(t.x-=e,t.y-=o,t),y=(t,e,o=e)=>n(e)?y(t,e.x,e.y):(t.x*=e,t.y*=o,t),x=(t,e,o=e)=>n(e)?x(t,e.x,e.y):(t.x/=e||1,t.y/=o||1,t),I=(t,e)=>{let o=M(e),c=f(e);return t.x=o*t.x-c*t.y,t.y=c*t.x+o*t.y,t},O=(t,e)=>{let o=h(r(e));return i(t,y(o,2*D(t,o)))},S=(t,e)=>(h(t),y(t,e),t),d=t=>Math.hypot(t.x,t.y),R=t=>t.x*t.x+t.y*t.y,h=t=>{let e=d(t);return e>0&&x(t,e),t},b=(t,e=1)=>{let o=R(t);return o>e*e&&(x(t,C(o)),y(t,e)),t},L=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),N=(t,e)=>{let o=t.x-e.x,c=t.y-e.y;return o*o+c*c},P=t=>Math.atan2(t.y,t.x),w=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),D=(t,e)=>t.x*e.x+t.y*e.y,U=(t,e)=>t.x*e.y-t.y*e.x,Z=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),$=(t=1,e=t,o=globalThis.rand||Math.random)=>{let c=o()*E,l=o()*(e-t)+t;return r(M(c)*l,f(c)*l)},j=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),B=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),F=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),G=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),H=(t,e,o)=>(t.x<e.x&&(t.x=e.x),t.x>o.x&&(t.x=o.x),t.y<e.y&&(t.y=e.y),t.y>o.y&&(t.y=o.y),t),V=(t,e,o=1)=>u(t,e.x*o,e.y*o),W=t=>p(t,T),T=r(0,0),k=r(1,1),z=r(0,-1),J=r(1,0),K=r(0,1),Q=r(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},a);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litecanvas/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Utilities to help build litecanvas games",
|
|
5
5
|
"author": "Luiz Bills <luizbills@pm.me>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"litecanvas": "
|
|
37
|
+
"litecanvas": "latest"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"esbuild": "^0.
|
|
40
|
+
"esbuild": "^0.25.0",
|
|
41
41
|
"gzip-size": "^7.0.0",
|
|
42
|
-
"prettier": "^3.
|
|
42
|
+
"prettier": "^3.5.2"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/_global.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
globalThis.utils = globalThis.utils || {}
|
|
2
2
|
|
|
3
|
-
globalThis.utils.global = () => {
|
|
3
|
+
globalThis.utils.global = (overrides = true) => {
|
|
4
4
|
for (const key in globalThis.utils) {
|
|
5
5
|
if ("global" === key) continue
|
|
6
|
-
globalThis[key]
|
|
6
|
+
if (overrides || globalThis[key] !== undefined) {
|
|
7
|
+
globalThis[key] = globalThis.utils[key]
|
|
8
|
+
}
|
|
7
9
|
}
|
|
8
10
|
}
|
package/src/actor/README.md
CHANGED
|
@@ -14,11 +14,11 @@ litecanvas({
|
|
|
14
14
|
loop: { init, tapped, draw },
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
// create a
|
|
17
|
+
// lets create a image to our actor
|
|
18
18
|
mySprite = paint(3, 3, ["303", "030", "303"], { scale: 10 })
|
|
19
19
|
|
|
20
20
|
function init() {
|
|
21
|
-
// create a actor
|
|
21
|
+
// create a actor and pass its image
|
|
22
22
|
player = new Actor(mySprite)
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -42,9 +42,12 @@ Set or get the actor position vector
|
|
|
42
42
|
|
|
43
43
|
```js
|
|
44
44
|
player.pos.x = 100
|
|
45
|
-
player.pos.
|
|
45
|
+
player.pos.y = 200
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
> Note:
|
|
49
|
+
> The `player.pos` is a [Vector](https://github.com/litecanvas/utils/blob/main/src/vector/README.md) instance.
|
|
50
|
+
|
|
48
51
|
## Actor#x / Actor#y
|
|
49
52
|
|
|
50
53
|
Set or get the actor position X or Y
|
|
@@ -99,15 +102,12 @@ If `true` the actor sprite is flipped vertically. Default is `false`.
|
|
|
99
102
|
Set or get the actor anchor (origin). By default, the anchor is a vector `(0, 0)` (meaning anchor Top Left).
|
|
100
103
|
|
|
101
104
|
```js
|
|
102
|
-
//
|
|
105
|
+
// example: actor position based on their center
|
|
103
106
|
player.anchor.x = 0.5
|
|
104
107
|
player.anchor.y = 0.5
|
|
105
|
-
```
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
// alternatively
|
|
109
|
+
// or...
|
|
109
110
|
import { ANCHOR_CENTER } from "@litecanvas/utils"
|
|
110
|
-
|
|
111
111
|
player.anchor = ANCHOR_CENTER
|
|
112
112
|
```
|
|
113
113
|
|
|
@@ -173,4 +173,4 @@ player.sprite = anotherSprite
|
|
|
173
173
|
|
|
174
174
|
> The actor sprite must be a `Image`, `HTMLCanvas` or `OffscreenCanvas`.
|
|
175
175
|
>
|
|
176
|
-
> Remember, you can create a image using the litecanvas' `paint()` built-in helper or [load a image](https://github.com/litecanvas/plugin-asset-loader?tab=readme-ov-file#loading-images)
|
|
176
|
+
> Remember, you can create a image using the litecanvas' `paint()` built-in helper or [load a image](https://github.com/litecanvas/plugin-asset-loader?tab=readme-ov-file#loading-images).
|
package/src/camera/README.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
import { litecanvas } from "litecanvas"
|
|
9
9
|
import { Camera } from "@litecanvas/utils"
|
|
10
10
|
|
|
11
|
+
litecanvas({
|
|
12
|
+
loop: { init, draw }
|
|
13
|
+
})
|
|
14
|
+
|
|
11
15
|
function init() {
|
|
12
16
|
camera = new Camera()
|
|
13
17
|
}
|
|
@@ -17,11 +21,11 @@ function draw() {
|
|
|
17
21
|
|
|
18
22
|
camera.start()
|
|
19
23
|
|
|
20
|
-
// draw your game objects here
|
|
24
|
+
// draw your dynamic game objects here (player, enemies, tilemap, etc)
|
|
21
25
|
|
|
22
26
|
camera.end()
|
|
23
27
|
|
|
24
|
-
// draw your UI here
|
|
28
|
+
// draw your UI here (score, lifes, etc)
|
|
25
29
|
}
|
|
26
30
|
```
|
|
27
31
|
|
|
@@ -43,7 +47,7 @@ function draw() {
|
|
|
43
47
|
|
|
44
48
|
Apply the camera transformations (move, zoom and rotate). You must call this method before draw anything inside of the camera.
|
|
45
49
|
|
|
46
|
-
###
|
|
50
|
+
### end()
|
|
47
51
|
|
|
48
52
|
Stop looking through the camera. You must call this method after draw anything inside of the camera.
|
|
49
53
|
|
package/src/math/dist.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the distance between a point (x1, y1) to another (x2, y2).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} x1
|
|
5
|
+
* @param {number} y1
|
|
6
|
+
* @param {number} x2
|
|
7
|
+
* @param {number} y2
|
|
8
|
+
* @returns {number}
|
|
9
|
+
*/
|
|
10
|
+
export default (x1, y1, x2, y2) => {
|
|
11
|
+
return Math.hypot(x2 - x1, y2 - y1)
|
|
12
|
+
}
|
package/src/math/index.js
CHANGED
|
@@ -4,3 +4,6 @@ export { default as fract } from "./fract.js"
|
|
|
4
4
|
export { default as range } from "./range.js"
|
|
5
5
|
export { default as advance } from "./advance.js"
|
|
6
6
|
export { default as mod } from "./mod.js"
|
|
7
|
+
export { default as roundd } from "./roundd.js"
|
|
8
|
+
export { default as dist } from "./dist.js"
|
|
9
|
+
export { default as mag } from "./mag.js"
|
package/src/math/mag.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the integer closest to a number and optional precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} n number to round.
|
|
5
|
+
* @param {number} [precision] number of decimal digits to round to, default is 0.
|
|
6
|
+
* @returns {number} rounded number.
|
|
7
|
+
*/
|
|
8
|
+
export default (n, precision = 0) => {
|
|
9
|
+
if (!precision) {
|
|
10
|
+
return Math.round(n)
|
|
11
|
+
}
|
|
12
|
+
const multiplier = Math.pow(10, precision)
|
|
13
|
+
return Math.round(n * multiplier) / multiplier
|
|
14
|
+
}
|
package/src/vector/index.js
CHANGED
|
@@ -205,7 +205,7 @@ export const vecSetMag = (v, value) => {
|
|
|
205
205
|
* @param {Vector} v
|
|
206
206
|
* @returns {number}
|
|
207
207
|
*/
|
|
208
|
-
export const vecMag = (v) =>
|
|
208
|
+
export const vecMag = (v) => Math.hypot(v.x, v.y)
|
|
209
209
|
|
|
210
210
|
/**
|
|
211
211
|
* Calculates the magnitude (length) of the vector squared.
|
|
@@ -253,9 +253,7 @@ export const vecLimit = (v, max = 1) => {
|
|
|
253
253
|
* @returns {number}
|
|
254
254
|
*/
|
|
255
255
|
export const vecDist = (a, b) => {
|
|
256
|
-
|
|
257
|
-
const dy = a.y - b.y
|
|
258
|
-
return sqrt(dx * dx + dy * dy)
|
|
256
|
+
return Math.hypot(b.x - a.x, b.y - a.y)
|
|
259
257
|
}
|
|
260
258
|
|
|
261
259
|
/**
|