@litecanvas/utils 0.13.0 → 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 +3 -0
- package/dist/actor.min.js +1 -1
- package/dist/all.js +6 -0
- package/dist/all.min.js +3 -2
- package/dist/vector.js +2 -0
- package/dist/vector.min.js +1 -1
- package/package.json +1 -1
- package/src/_web.js +1 -0
- package/src/vector/index.js +9 -0
package/dist/actor.js
CHANGED
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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:()=>
|
|
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
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
vecAbs: () => vecAbs,
|
|
43
43
|
vecAdd: () => vecAdd,
|
|
44
44
|
vecAngle: () => vecAngle,
|
|
45
|
+
vecAngleBetween: () => vecAngleBetween,
|
|
45
46
|
vecCeil: () => vecCeil,
|
|
46
47
|
vecClamp: () => vecClamp,
|
|
47
48
|
vecCross: () => vecCross,
|
|
@@ -637,6 +638,7 @@
|
|
|
637
638
|
return dx * dx + dy * dy;
|
|
638
639
|
};
|
|
639
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);
|
|
640
642
|
var vecDot = (a, b) => a.x * b.x + a.y * b.y;
|
|
641
643
|
var vecCross = (a, b) => a.x * b.y - a.y * b.x;
|
|
642
644
|
var vecLerp = (a, b, t) => {
|
|
@@ -685,6 +687,9 @@
|
|
|
685
687
|
var DOWN = /* @__PURE__ */ vec(0, 1);
|
|
686
688
|
var LEFT = /* @__PURE__ */ vec(-1, 0);
|
|
687
689
|
|
|
690
|
+
// node_modules/litecanvas/src/zzfx.js
|
|
691
|
+
globalThis.zzfxV = 1;
|
|
692
|
+
|
|
688
693
|
// src/actor/index.js
|
|
689
694
|
var ANCHOR_CENTER = vec(0.5, 0.5);
|
|
690
695
|
var ANCHOR_TOP_LEFT = vec(0, 0);
|
|
@@ -828,3 +833,4 @@
|
|
|
828
833
|
// src/_web.js
|
|
829
834
|
globalThis.utils = Object.assign(globalThis.utils || {}, src_exports);
|
|
830
835
|
})();
|
|
836
|
+
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/all.min.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`)}},
|
|
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 */
|
package/dist/vector.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
vecAbs: () => vecAbs,
|
|
20
20
|
vecAdd: () => vecAdd,
|
|
21
21
|
vecAngle: () => vecAngle,
|
|
22
|
+
vecAngleBetween: () => vecAngleBetween,
|
|
22
23
|
vecCeil: () => vecCeil,
|
|
23
24
|
vecClamp: () => vecClamp,
|
|
24
25
|
vecCross: () => vecCross,
|
|
@@ -166,6 +167,7 @@
|
|
|
166
167
|
return dx * dx + dy * dy;
|
|
167
168
|
};
|
|
168
169
|
var vecAngle = (v) => Math.atan2(v.y, v.x);
|
|
170
|
+
var vecAngleBetween = (v1, v2) => Math.atan2(v2.y - v1.y, v2.x - v1.x);
|
|
169
171
|
var vecDot = (a, b) => a.x * b.x + a.y * b.y;
|
|
170
172
|
var vecCross = (a, b) => a.x * b.y - a.y * b.x;
|
|
171
173
|
var vecLerp = (a, b, t) => {
|
package/dist/vector.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var A=Object.defineProperty;var C=(t,e)=>{for(var o in e)A(t,o,{get:e[o],enumerable:!0})};var h={};C(h,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>q,vec:()=>c,vecAbs:()=>j,vecAdd:()=>i,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>B,vecClamp:()=>H,vecCross:()=>U,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>y,vecDot:()=>T,vecEq:()=>u,vecFloor:()=>F,vecIsZero:()=>W,vecLerp:()=>Z,vecLimit:()=>b,vecMag:()=>R,vecMag2:()=>D,vecMove:()=>V,vecMult:()=>x,vecNorm:()=>l,vecRand:()=>$,vecReflect:()=>O,vecRotate:()=>I,vecRound:()=>G,vecSet:()=>g,vecSetMag:()=>S,vecSub:()=>a});var p=Math.sqrt,f=Math.cos,d=Math.sin,E=2*Math.PI,s=class{x;y;constructor(e=0,o=e){this.x=e,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof s,c=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new s(t,e)),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):t.x===e&&t.y===o,g=(t,e,o=e)=>(n(e)?g(t,e.x,e.y):(t.x=e,t.y=o),t),i=(t,e,o=e)=>n(e)?i(t,e.x,e.y):(t.x+=e,t.y+=o,t),a=(t,e,o=e)=>n(e)?a(t,e.x,e.y):(t.x-=e,t.y-=o,t),x=(t,e,o=e)=>n(e)?x(t,e.x,e.y):(t.x*=e,t.y*=o,t),y=(t,e,o=e)=>n(e)?y(t,e.x,e.y):(t.x/=e,t.y/=o,t),I=(t,e)=>{let o=f(e),r=d(e);return t.x=o*t.x-r*t.y,t.y=r*t.x+o*t.y,t},O=(t,e)=>{let o=l(c(e));return a(t,x(o,2*T(t,o)))},S=(t,e)=>(l(t),x(t,e),t),R=t=>p(t.x*t.x+t.y*t.y),D=t=>t.x*t.x+t.y*t.y,l=t=>{let e=R(t);return e>0&&y(t,e),t},b=(t,e=1)=>{let o=D(t);return o>e*e&&(y(t,p(o)),x(t,e)),t},L=(t,e)=>{let o=t.x-e.x,r=t.y-e.y;return p(o*o+r*r)},N=(t,e)=>{let o=t.x-e.x,r=t.y-e.y;return o*o+r*r},P=t=>Math.atan2(t.y,t.x),w=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),T=(t,e)=>t.x*e.x+t.y*e.y,U=(t,e)=>t.x*e.y-t.y*e.x,Z=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),$=(t=1,e=t,o=globalThis.rand||Math.random)=>{let r=o()*E,M=o()*(e-t)+t;return c(f(r)*M,d(r)*M)},j=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),B=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),F=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),G=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),H=(t,e,o)=>(t.x<e.x&&(t.x=e.x),t.x>o.x&&(t.x=o.x),t.y<e.y&&(t.y=e.y),t.y>o.y&&(t.y=o.y),t),V=(t,e,o=1)=>i(t,e.x*o,e.y*o),W=t=>u(t,q),q=c(0,0),k=c(1,1),z=c(0,-1),J=c(1,0),K=c(0,1),Q=c(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},h);})();
|
package/package.json
CHANGED
package/src/_web.js
CHANGED
package/src/vector/index.js
CHANGED
|
@@ -278,6 +278,15 @@ export const vecDist2 = (a, b) => {
|
|
|
278
278
|
*/
|
|
279
279
|
export const vecAngle = (v) => Math.atan2(v.y, v.x)
|
|
280
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Calculates the angle between two vectors.
|
|
283
|
+
*
|
|
284
|
+
* @param {Vector} v1
|
|
285
|
+
* @param {Vector} v2
|
|
286
|
+
* @returns {number}
|
|
287
|
+
*/
|
|
288
|
+
export const vecAngleBetween = (v1, v2) => Math.atan2(v2.y - v1.y, v2.x - v1.x)
|
|
289
|
+
|
|
281
290
|
/**
|
|
282
291
|
* Calculates the dot product of two vectors.
|
|
283
292
|
*
|