@litecanvas/utils 0.47.2 → 0.48.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.min.js +1 -1
- package/dist/all.js +15 -1
- package/dist/all.min.js +2 -2
- package/dist/math.min.js +1 -1
- package/dist/vector.js +15 -1
- package/dist/vector.min.js +1 -1
- package/package.json +1 -2
- package/src/vector/index.js +20 -3
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var d=Object.defineProperty;var f=(e,t)=>{for(var s in t)d(e,s,{get:t[s],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 a={};f(a,{ANCHOR_BOT_LEFT:()=>M,ANCHOR_BOT_RIGHT:()=>_,ANCHOR_CENTER:()=>b,ANCHOR_TOP_LEFT:()=>u,ANCHOR_TOP_RIGHT:()=>m,Actor:()=>h});var w=2*Math.PI,n=class{constructor(t=0,s=t){this.x=parseFloat(t)||0,this.y=parseFloat(s)||0}toString(){return`Vector (${this.x}, ${this.y})`}},g=e=>e instanceof n,o=(e=0,t=e)=>(g(e)&&(t=e.y,e=e.x),new n(e,t));var l=(e,t,s,r,i,c,p)=>{let x=i-Math.max(e,Math.min(i,e+s)),y=c-Math.max(t,Math.min(c,t+r));return x*x+y*y<=p*p};var b=o(.5,.5),u=o(0,0),m=o(1,0),M=o(0,1),_=o(1,1),h=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=u){this.sprite=t||{width:0,height:0},this.pos=s||o(0),this._o=o(r),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.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,s=t){this._s.x=t,this._s.y=s}scaleBy(t,s=t){this._s.x*=t,this._s.y*=s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),r=this.sprite.height*(t?this._s.y:1),i=this.pos.x-s*this.anchor.x,c=this.pos.y-r*this.anchor.y;return[i,c,s,r]}in(t,s,r=1){return l(...this.getBounds(),t,s,r)}col(t){return colrect(...this.getBounds(),...t.getBounds())}draw(t=globalThis,s=!0){s&&t.push(),this.transform(t),this.sprite.width&&this.sprite.height&&!this.hidden&&this.opacity>0&&this.drawImage(t),s&&t.pop()}transform(t=globalThis){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=globalThis,s=!0){let r=this.anchor,i=-this.sprite.width*(this.flipX?1-r.x:r.x),c=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(i,c,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},a);})();
|
package/dist/all.js
CHANGED
|
@@ -754,7 +754,21 @@
|
|
|
754
754
|
v.y %= value;
|
|
755
755
|
return v;
|
|
756
756
|
};
|
|
757
|
-
var vecMove = (from, to,
|
|
757
|
+
var vecMove = (from, to, step = 1) => {
|
|
758
|
+
const dx = to.x - from.x;
|
|
759
|
+
const dy = to.y - from.y;
|
|
760
|
+
const distance = Math.hypot(dx, dy);
|
|
761
|
+
step = Math.abs(step);
|
|
762
|
+
if (distance <= step || distance === 0) {
|
|
763
|
+
from.x = to.x;
|
|
764
|
+
from.y = to.y;
|
|
765
|
+
} else {
|
|
766
|
+
const ratio = step / distance;
|
|
767
|
+
from.x = from.x + dx * ratio;
|
|
768
|
+
from.y = from.y + dy * ratio;
|
|
769
|
+
}
|
|
770
|
+
return from;
|
|
771
|
+
};
|
|
758
772
|
var vecEq = (v, x, y = x) => {
|
|
759
773
|
if (isVector(x)) {
|
|
760
774
|
return vecEq(v, x.x, x.y);
|
package/dist/all.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var St=Object.defineProperty;var kt=(e
|
|
2
|
-
`)}},N=class
|
|
1
|
+
(()=>{var St=Object.defineProperty;var kt=(t,e)=>{for(var s in e)St(t,s,{get:e[s],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 U={};kt(U,{ANCHOR_BOT_LEFT:()=>he,ANCHOR_BOT_RIGHT:()=>ne,ANCHOR_CENTER:()=>oe,ANCHOR_TOP_LEFT:()=>st,ANCHOR_TOP_RIGHT:()=>ae,Actor:()=>O,BACK_IN:()=>fe,BACK_IN_OUT:()=>me,BACK_OUT:()=>xe,BOUNCE_IN:()=>_t,BOUNCE_IN_OUT:()=>be,BOUNCE_OUT:()=>C,Camera:()=>b,DOWN:()=>re,EASE_IN:()=>ce,EASE_IN_OUT:()=>pe,EASE_OUT:()=>ue,ELASTIC_IN:()=>_e,ELASTIC_IN_OUT:()=>ye,ELASTIC_OUT:()=>de,Grid:()=>E,LEFT:()=>ie,LINEAR:()=>mt,Noise:()=>Z,ONE:()=>te,RIGHT:()=>se,TypedGrid:()=>N,UP:()=>ee,Vector:()=>g,ZERO:()=>et,advance:()=>ot,assert:()=>X,choose:()=>Et,colcirc:()=>V,colrect:()=>D,colrectcirc:()=>w,dd:()=>Ft,diff:()=>rt,dist:()=>ht,flipImage:()=>dt,formatTime:()=>At,fract:()=>it,head:()=>Pt,intersection:()=>I,is:()=>R,last:()=>Tt,lerpAngle:()=>ut,lpad:()=>Lt,mag:()=>nt,makeCircle:()=>gt,makeRectangle:()=>Mt,mean:()=>lt,median:()=>ct,mod:()=>at,move:()=>xt,percent:()=>pt,range:()=>It,resolverect:()=>W,rpad:()=>Nt,scaleImage:()=>yt,shuffle:()=>wt,sum:()=>T,tail:()=>Rt,tintImage:()=>bt,tween:()=>le,vec:()=>n,vecAbs:()=>Vt,vecAdd:()=>$,vecAngle:()=>Ht,vecAngleBetween:()=>Wt,vecCeil:()=>jt,vecClamp:()=>Kt,vecCross:()=>Xt,vecDist:()=>Zt,vecDist2:()=>Ut,vecDiv:()=>F,vecDot:()=>tt,vecEq:()=>k,vecFloor:()=>qt,vecHeading:()=>v,vecIsZero:()=>Jt,vecLerp:()=>Dt,vecLimit:()=>Yt,vecMag:()=>J,vecMag2:()=>Q,vecMove:()=>Gt,vecMult:()=>P,vecNorm:()=>S,vecRand:()=>vt,vecReflect:()=>Ct,vecRem:()=>$t,vecRotate:()=>Bt,vecRound:()=>zt,vecSet:()=>K,vecSetMag:()=>G,vecSub:()=>L,vecToArray:()=>Qt,wave:()=>ft});var b=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;constructor(e=null,s=0,r=0,i=null,o=null){this._engine=e||globalThis,this.ox=s,this.oy=r,this.resize(i||this._engine.W-s,o||this._engine.H-r),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}resize(e,s){this.width=e,this.height=s,this._engine.emit("camera-resized",this)}start(e=!1){this._engine.push(),e&&this._engine.clip(i=>{i.rect(this.ox,this.oy,this.width,this.height)});let s=this.ox+this.width/2,r=this.oy+this.height/2;this._engine.translate(s,r),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(e,s){this.x=e,this.y=s}move(e,s){this.x+=e,this.y+=s}zoom(e){this.scale*=e}zoomTo(e){this.scale=e}rotate(e){this.rotation+=e}rotateTo(e){this.rotation=e}getWorldPoint(e,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return e=(e-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,r.x=i*e-o*s+this.x,r.y=o*e+i*s+this.y,r}getCameraPoint(e,s,r={}){let i=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return e=e-this.x,s=s-this.y,e=i*e-o*s,s=o*e+i*s,r.x=e*this.scale+this.width/2+this.ox,r.y=s*this.scale+this.height/2+this.oy,r}getBounds(){return[this.ox,this.oy,this.width,this.height]}shake(e=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",r=>{this._shake.x=this._engine.randi(-e,e),this._shake.y=this._engine.randi(-e,e),s-=r,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 I=(t,e,s,r,i,o,a,h)=>{let l=Math.max(t,i),m=Math.min(t+s,i+a)-l,u=Math.max(e,o),_=Math.min(e+r,o+h)-u;return[l,u,m,_]};var W=(t,e,s,r,i,o,a,h)=>{let[l,m,u,_]=I(t,e,s,r,i,o,a,h),x="",y=t,c=e;return u<_?t<i?(x="right",y=i-s):(x="left",y=i+a):e<o?(x="bottom",c=o-r):(x="top",c=o+h),{dir:x,x:y,y:c}};var X=(t,e="Assertion failed")=>{if(!t)throw new Error(e)};var D=(t,e,s,r,i,o,a,h)=>t<i+a&&t+s>i&&e<o+h&&e+r>o;var V=(t,e,s,r,i,o)=>(r-t)*(r-t)+(i-e)*(i-e)<=(s+o)*(s+o);var w=(t,e,s,r,i,o,a)=>{let h=i-Math.max(t,Math.min(i,t+s)),l=o-Math.max(e,Math.min(o,e+r));return h*h+l*l<=a*a};var E=class t{_w;_h;_c;constructor(e,s,r=[]){this._w=Math.max(1,~~e),this._h=Math.max(1,~~s),this._c=r}[Symbol.iterator](){let e=0;return{next:()=>({value:[this.indexToPointX(e),this.indexToPointY(e),this._c[e++]],done:e>this._c.length})}}clone(){return new t(this._w,this._h,this._c)}clear(){this.forEach((e,s)=>this.set(e,s,void 0))}get width(){return this._w}get height(){return this._h}set(e,s,r){this._c[this.pointToIndex(e,s)]=r}get(e,s){return this._c[this.pointToIndex(e,s)]}has(e,s){return this.get(e,s)!=null}check(e,s){return e>=0&&e<this._w&&s>=0&&s<this._h}get length(){return this._w*this._h}pointToIndex(e,s){return this.clampX(~~e)+this.clampY(~~s)*this._w}indexToPointX(e){return e%this._w}indexToPointY(e){return Math.floor(e/this._w)}forEach(e,s=!1){let r=s?this.length-1:0,i=s?-1:this.length,o=s?-1:1;for(;r!==i;){let a=this.indexToPointX(r),h=this.indexToPointY(r),l=this._c[r];if(e(a,h,l,this)===!1)break;r+=o}}fill(e){this.forEach((s,r)=>{this.set(s,r,e)})}clampX(e){return j(e,0,this._w-1)}clampY(e){return j(e,0,this._h-1)}toArray(){return this._c.slice()}toString(e=" ",s=!0){if(!s)return this._c.join(e);let r=[];return this.forEach((i,o,a)=>{r[o]=r[o]||"",r[o]+=a+e}),r.join(`
|
|
2
|
+
`)}},N=class t extends E{constructor(e,s,r=Uint8Array){super(e,s,null),this._c=new r(this._w*this._h)}has(e,s){return this.get(e,s)!==0}clone(){let e=new t(this._w,this._h,this._c.constructor);return this.forEach((s,r,i)=>{e.set(s,r,i)}),e}};function j(t,e,s){return t<e?e:t>s?s:t}var q=Math.cos,z=Math.sin,Ot=2*Math.PI,g=class{constructor(e=0,s=e){this.x=parseFloat(e)||0,this.y=parseFloat(s)||0}toString(){return`Vector (${this.x}, ${this.y})`}},d=t=>t instanceof g,n=(t=0,e=t)=>(d(t)&&(e=t.y,t=t.x),new g(t,e)),K=(t,e,s=e)=>(d(e)?K(t,e.x,e.y):(t.x=e,t.y=s),t),$=(t,e,s=e)=>d(e)?$(t,e.x,e.y):(t.x+=e,t.y+=s,t),L=(t,e,s=e)=>d(e)?L(t,e.x,e.y):(t.x-=e,t.y-=s,t),P=(t,e,s=e)=>d(e)?P(t,e.x,e.y):(t.x*=e,t.y*=s,t),F=(t,e,s=e)=>d(e)?F(t,e.x,e.y):(t.x/=e||1,t.y/=s||1,t),Bt=(t,e)=>{let s=q(e),r=z(e);return t.x=s*t.x-r*t.y,t.y=r*t.x+s*t.y,t},Ct=(t,e)=>{let s=S(n(e));return L(t,P(s,2*tt(t,s)))},G=(t,e)=>(S(t),P(t,e),t),J=t=>Math.hypot(t.x,t.y),Q=t=>t.x*t.x+t.y*t.y,S=t=>{let e=J(t);return e>0&&F(t,e),t},Yt=(t,e=1)=>(Q(t)>e*e&&G(t,e),t),Zt=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),Ut=(t,e)=>{let s=t.x-e.x,r=t.y-e.y;return s*s+r*r},v=t=>Math.atan2(t.y,t.x),Ht=t=>v(t),Wt=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),tt=(t,e)=>t.x*e.x+t.y*e.y,Xt=(t,e)=>t.x*e.y-t.y*e.x,Dt=(t,e,s)=>(t.x+=(e.x-t.x)*s||0,t.y+=(e.y-t.y)*s||0,t),Vt=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),jt=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),qt=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),zt=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),Kt=(t,e,s)=>(t.x<e.x&&(t.x=e.x),t.x>s.x&&(t.x=s.x),t.y<e.y&&(t.y=e.y),t.y>s.y&&(t.y=s.y),t),$t=(t,e)=>(t.x%=e,t.y%=e,t),Gt=(t,e,s=1)=>{let r=e.x-t.x,i=e.y-t.y,o=Math.hypot(r,i);if(s=Math.abs(s),o<=s||o===0)t.x=e.x,t.y=e.y;else{let a=s/o;t.x=t.x+r*a,t.y=t.y+i*a}return t},k=(t,e,s=e)=>d(e)?k(t,e.x,e.y):t.x===e&&t.y===s,Jt=t=>k(t,et),Qt=t=>[t.x,t.y],vt=(t=1,e=t,s=globalThis.rand||Math.random)=>{let r=s()*Ot,i=s()*(e-t)+t;return n(q(r)*i,z(r)*i)},et=n(0,0),te=n(1,1),ee=n(0,-1),se=n(1,0),re=n(0,1),ie=n(-1,0);var oe=n(.5,.5),st=n(0,0),ae=n(1,0),he=n(0,1),ne=n(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(e,s,r=st){this.sprite=e||{width:0,height:0},this.pos=s||n(0),this._o=n(r),this._s=n(1,1)}set x(e){this.pos.x=e}get x(){return this.pos.x}set y(e){this.pos.y=e}get y(){return this.pos.y}set anchor(e){this._o.x=e.x,this._o.y=e.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(e,s=e){this._s.x=e,this._s.y=s}scaleBy(e,s=e){this._s.x*=e,this._s.y*=s}getBounds(e=!0){let s=this.sprite.width*(e?this._s.x:1),r=this.sprite.height*(e?this._s.y:1),i=this.pos.x-s*this.anchor.x,o=this.pos.y-r*this.anchor.y;return[i,o,s,r]}in(e,s,r=1){return w(...this.getBounds(),e,s,r)}col(e){return colrect(...this.getBounds(),...e.getBounds())}draw(e=globalThis,s=!0){s&&e.push(),this.transform(e),this.sprite.width&&this.sprite.height&&!this.hidden&&this.opacity>0&&this.drawImage(e),s&&e.pop()}transform(e=globalThis){e.translate(this.pos.x,this.pos.y),e.rotate(e.deg2rad(this.angle)),e.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(e=globalThis,s=!0){let r=this.anchor,i=-this.sprite.width*(this.flipX?1-r.x:r.x),o=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&e.alpha(this.opacity),e.image(i,o,this.sprite)}};var rt=(t,e)=>Math.abs(e-t)||0;var it=t=>t%1||0;var ot=(t,e,s,r=1)=>{s&&(e.x+=s.x*r,e.y+=s.y*r),t.x+=e.x*r,t.y+=e.y*r};var at=(t,e)=>(e+t%e)%e;var ht=(t,e,s,r)=>Math.hypot(s-t,r-e);var nt=(t,e)=>Math.hypot(t,e);var T=t=>{let e=0;for(let s=0;s<t.length;s++)e+=t[s];return e};var lt=t=>T(t)/t.length;var ct=t=>{let e=t.sort((r,i)=>r-i),s=Math.floor(e.length/2);return e.length%2===0?(e[s-1]+e[s])/2:e[s]};var ut=(t,e,s)=>{let r=(e-t)%360;return r>180?r-=360:r<-180&&(r+=360),t+r*s};var pt=(t,e=0,s=1)=>s-e?(t-e)/(s-e):0;var R=(t,e)=>typeof e=="function"?t instanceof e:typeof t===e;var ft=(t,e,s,r=Math.sin)=>t+(r(s)+1)/2*(e-t);var xt=(t,e,s)=>Math.abs(e-t)<=s?e:t+Math.sign(e-t)*s;var A=Math.PI/2,le=(t,e,s,r=1,i=mt)=>new B(t,e,s,r,i),mt=t=>t,ce=t=>t*t,ue=t=>-t*(t-2),pe=t=>t<.5?2*t*t:-2*t*t+4*t-1,fe=t=>t*t*t-t*Math.sin(t*Math.PI),xe=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},me=t=>{if(t<.5){let s=2*t;return .5*(s*s*s-s*Math.sin(s*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},_e=t=>Math.sin(13*A*t)*Math.pow(2,10*(t-1)),de=t=>Math.sin(-13*A*(t+1))*Math.pow(2,-10*t)+1,ye=t=>{if(t<.5){let r=Math.sin(13*A*(2*t)),i=Math.pow(2,10*(2*t-1));return .5*r*i}let e=Math.sin(-13*A*(2*t-1+1)),s=Math.pow(2,-10*(2*t-1));return .5*(e*s+2)},_t=t=>1-C(1-t),C=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,be=t=>t<.5?.5*_t(t*2):.5*C(t*2-1)+.5,B=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(e,s,r,i,o){this._o=e,this._p=s,this._x=r,this._d=i,this._e=o,this._w=0}start(e){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let s=this._o[this._p]||0,r=this._rel?s+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",i=>{if(this._t<=this._w){this._t+=i;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,r,this._e(o/this._d)),this._t+=i,o>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(e=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,e)for(let s of this._cb)s(this._o);return this}restart(e=null,s=!1){return this.stop(s).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}};var Y=t=>.5*(1-Math.cos(t*Math.PI)),Z=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,s=0,r=0){e<0&&(e=-e),s<0&&(s=-s),r<0&&(r=-r);let i=Math.floor(e),o=Math.floor(s),a=Math.floor(r),h=e-i,l=s-o,m=r-a,u,_,x=0,y=.5,c,p,M;for(let H=0;H<this._po;H++){let f=i+(o<<4)+(a<<8);u=Y(h),_=Y(l),c=this._p[f&4095],c+=u*(this._p[f+1&4095]-c),p=this._p[f+16&4095],p+=u*(this._p[f+16+1&4095]-p),c+=_*(p-c),f+=256,p=this._p[f&4095],p+=u*(this._p[f+1&4095]-p),M=this._p[f+16&4095],M+=u*(this._p[f+16+1&4095]-M),p+=_*(M-p),c+=Y(m)*(p-c),x+=c*y,y*=this._pf,i<<=1,h*=2,o<<=1,l*=2,a<<=1,m*=2,h>=1&&(i++,h--),l>=1&&(o++,l--),m>=1&&(a++,m--)}return x}noiseDetail(e,s){e>0&&(this._po=e),s>0&&(this._pf=s)}noiseSeed(e=null){e!=null&&this._e.rseed(e);let s=this._e.rand||Math.random;for(let r=0;r<4096;r++)this._p[r]=s()}};var dt=(t,e=!0,s=!1,r=globalThis)=>r.paint(t.width,t.height,i=>{r.push(),r.scale(e?-1:1,s?-1:1),r.image(e?-t.width:0,s?-t.height:0,t),r.pop()});var yt=(t,e,s=!0,r=globalThis)=>r.paint(t.width*e,t.height*e,i=>{r.push(),i.imageSmoothingEnabled=!s,r.scale(e),r.image(0,0,t),r.pop()});var bt=(t,e,s=1,r=globalThis)=>r.paint(t.width,t.height,i=>{r.push(),r.alpha(s),r.rectfill(0,0,t.width,t.height,e),i.globalCompositeOperation="destination-atop",r.alpha(1),r.image(0,0,t),r.pop()});var gt=(t,e,{borderWidth:s=0,borderColor:r=0,engine:i=globalThis}={})=>{let o=t*2+s;return i.paint(o,o,()=>{i.circfill(o/2,o/2,t,e),s>0&&(i.linewidth(s),i.stroke(r))})};var Mt=(t,e,s,{borderWidth:r=0,borderColor:i=0,engine:o=globalThis}={})=>{let a=t+r*2,h=e+r*2;return o.paint(a,h,()=>{let l=r>0;l&&o.cls(i),o.rectfill(l?r:0,l?r:0,t,e,s)})};var It=(t,e=0,s=1)=>[...Array(t|0).keys()].map(r=>e+s*r);var wt=(t,e=globalThis.rand||Math.random)=>{t=[...t];for(let s=t.length-1;s>0;s--){let r=Math.floor(e()*(s+1)),i=t[s];t[s]=t[r],t[r]=i}return t};var Et=(t,e=globalThis.rand||Math.random)=>t[Math.floor(e()*t.length)];var Pt=t=>t[0];var Tt=t=>t[t.length-1];var Rt=t=>t.slice(1);var At=t=>~~(t/60)+":"+(t%60<10?"0":"")+~~(t%60);var Nt=(t,e,s="0")=>(t+"").padEnd(e,s);var Lt=(t,e,s="0")=>(t+"").padStart(e,s);var Ft=(t,e,s=globalThis)=>{s.pal(["blue","#fff"]),s.cls(0),s.ctx().resetTransform(),s.textfont("monospace"),s.textsize(16),s.textalign("start","top"),s.text(16,16,`${e??"dd() output"}: `+(R(t,"object")?JSON.stringify(t,null,4):t)),s.quit()};globalThis.utils=Object.assign(globalThis.utils||{},U);})();
|
|
3
3
|
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/math.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var M=Object.defineProperty;var g=(r,t)=>{for(var e in t)M(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 a={};g(a,{advance:()=>c,diff:()=>n,dist:()=>
|
|
1
|
+
(()=>{var M=Object.defineProperty;var g=(r,t)=>{for(var e in t)M(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 a={};g(a,{advance:()=>c,diff:()=>n,dist:()=>x,fract:()=>u,lerpAngle:()=>y,mag:()=>i,mean:()=>l,median:()=>f,mod:()=>p,move:()=>h,percent:()=>m,sum:()=>s,wave:()=>d});var n=(r,t)=>Math.abs(t-r)||0;var u=r=>r%1||0;var R=2*Math.PI;var c=(r,t,e,o=1)=>{e&&(t.x+=e.x*o,t.y+=e.y*o),r.x+=t.x*o,r.y+=t.y*o};var p=(r,t)=>(t+r%t)%t;var x=(r,t,e,o)=>Math.hypot(e-r,o-t);var i=(r,t)=>Math.hypot(r,t);var s=r=>{let t=0;for(let e=0;e<r.length;e++)t+=r[e];return t};var l=r=>s(r)/r.length;var f=r=>{let t=r.sort((o,b)=>o-b),e=Math.floor(t.length/2);return t.length%2===0?(t[e-1]+t[e])/2:t[e]};var y=(r,t,e)=>{let o=(t-r)%360;return o>180?o-=360:o<-180&&(o+=360),r+o*e};var m=(r,t=0,e=1)=>e-t?(r-t)/(e-t):0;var d=(r,t,e,o=Math.sin)=>r+(o(e)+1)/2*(t-r);var h=(r,t,e)=>Math.abs(t-r)<=e?t:r+Math.sign(t-r)*e;globalThis.utils=Object.assign(globalThis.utils||{},a);})();
|
package/dist/vector.js
CHANGED
|
@@ -197,7 +197,21 @@
|
|
|
197
197
|
v.y %= value;
|
|
198
198
|
return v;
|
|
199
199
|
};
|
|
200
|
-
var vecMove = (from, to,
|
|
200
|
+
var vecMove = (from, to, step = 1) => {
|
|
201
|
+
const dx = to.x - from.x;
|
|
202
|
+
const dy = to.y - from.y;
|
|
203
|
+
const distance = Math.hypot(dx, dy);
|
|
204
|
+
step = Math.abs(step);
|
|
205
|
+
if (distance <= step || distance === 0) {
|
|
206
|
+
from.x = to.x;
|
|
207
|
+
from.y = to.y;
|
|
208
|
+
} else {
|
|
209
|
+
const ratio = step / distance;
|
|
210
|
+
from.x = from.x + dx * ratio;
|
|
211
|
+
from.y = from.y + dy * ratio;
|
|
212
|
+
}
|
|
213
|
+
return from;
|
|
214
|
+
};
|
|
201
215
|
var vecEq = (v, x, y = x) => {
|
|
202
216
|
if (isVector(x)) {
|
|
203
217
|
return vecEq(v, x.x, x.y);
|
package/dist/vector.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var F=Object.defineProperty;var I=(t,e)=>{for(var o in e)F(t,o,{get:e[o],enumerable:!0})};var l={};I(l,{DOWN:()=>_,LEFT:()=>m,ONE:()=>Q,RIGHT:()=>Y,UP:()=>X,Vector:()=>x,ZERO:()=>E,vec:()=>c,vecAbs:()=>$,vecAdd:()=>R,vecAngle:()=>w,vecAngleBetween:()=>H,vecCeil:()=>j,vecClamp:()=>V,vecCross:()=>U,vecDist:()=>N,vecDist2:()=>P,vecDiv:()=>u,vecDot:()=>C,vecEq:()=>h,vecFloor:()=>B,vecHeading:()=>b,vecIsZero:()=>z,vecLerp:()=>Z,vecLimit:()=>L,vecMag:()=>A,vecMag2:()=>D,vecMove:()=>k,vecMult:()=>y,vecNorm:()=>a,vecRand:()=>K,vecReflect:()=>q,vecRem:()=>W,vecRotate:()=>S,vecRound:()=>G,vecSet:()=>g,vecSetMag:()=>T,vecSub:()=>i,vecToArray:()=>J});var d=Math.cos,f=Math.sin,O=2*Math.PI,x=class{constructor(e=0,o=e){this.x=parseFloat(e)||0,this.y=parseFloat(o)||0}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof x,c=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new x(t,e)),g=(t,e,o=e)=>(n(e)?g(t,e.x,e.y):(t.x=e,t.y=o),t),R=(t,e,o=e)=>n(e)?R(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),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):(t.x/=e||1,t.y/=o||1,t),S=(t,e)=>{let o=d(e),r=f(e);return t.x=o*t.x-r*t.y,t.y=r*t.x+o*t.y,t},q=(t,e)=>{let o=a(c(e));return i(t,y(o,2*C(t,o)))},T=(t,e)=>(a(t),y(t,e),t),A=t=>Math.hypot(t.x,t.y),D=t=>t.x*t.x+t.y*t.y,a=t=>{let e=A(t);return e>0&&u(t,e),t},L=(t,e=1)=>(D(t)>e*e&&T(t,e),t),N=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),P=(t,e)=>{let o=t.x-e.x,r=t.y-e.y;return o*o+r*r},b=t=>Math.atan2(t.y,t.x),w=t=>b(t),H=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),C=(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=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),j=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),B=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),G=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),V=(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),W=(t,e)=>(t.x%=e,t.y%=e,t),k=(t,e,o=1)=>{let r=e.x-t.x,s=e.y-t.y,p=Math.hypot(r,s);if(o=Math.abs(o),p<=o||p===0)t.x=e.x,t.y=e.y;else{let M=o/p;t.x=t.x+r*M,t.y=t.y+s*M}return t},h=(t,e,o=e)=>n(e)?h(t,e.x,e.y):t.x===e&&t.y===o,z=t=>h(t,E),J=t=>[t.x,t.y],K=(t=1,e=t,o=globalThis.rand||Math.random)=>{let r=o()*O,s=o()*(e-t)+t;return c(d(r)*s,f(r)*s)},E=c(0,0),Q=c(1,1),X=c(0,-1),Y=c(1,0),_=c(0,1),m=c(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},l);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litecanvas/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "Utilities to help build litecanvas games",
|
|
5
5
|
"author": "Luiz Bills <luizbills@pm.me>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"main": "src/index.js",
|
|
17
17
|
"unpkg": "./dist/all.js",
|
|
18
18
|
"jsdelivr": "./dist/all.js",
|
|
19
|
-
"browser": "./dist/all.js",
|
|
20
19
|
"keywords": [
|
|
21
20
|
"litecanvas",
|
|
22
21
|
"utilities",
|
package/src/vector/index.js
CHANGED
|
@@ -395,11 +395,28 @@ export const vecRem = (v, value) => {
|
|
|
395
395
|
/**
|
|
396
396
|
* @param {Vector} from
|
|
397
397
|
* @param {Vector} to
|
|
398
|
-
* @param {number} [
|
|
398
|
+
* @param {number} [step=1]
|
|
399
399
|
* @returns {Vector}
|
|
400
400
|
*/
|
|
401
|
-
export const vecMove = (from, to,
|
|
402
|
-
|
|
401
|
+
export const vecMove = (from, to, step = 1) => {
|
|
402
|
+
const dx = to.x - from.x
|
|
403
|
+
const dy = to.y - from.y
|
|
404
|
+
const distance = Math.hypot(dx, dy)
|
|
405
|
+
|
|
406
|
+
step = Math.abs(step)
|
|
407
|
+
|
|
408
|
+
if (distance <= step || distance === 0) {
|
|
409
|
+
from.x = to.x
|
|
410
|
+
from.y = to.y
|
|
411
|
+
} else {
|
|
412
|
+
const ratio = step / distance
|
|
413
|
+
|
|
414
|
+
from.x = from.x + dx * ratio
|
|
415
|
+
from.y = from.y + dy * ratio
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return from
|
|
419
|
+
}
|
|
403
420
|
|
|
404
421
|
/**
|
|
405
422
|
* Checks whether two vectors are equal.
|