@litecanvas/utils 0.32.0 → 0.33.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 +5 -30
- package/dist/all.min.js +2 -2
- package/dist/camera.js +5 -30
- package/dist/camera.min.js +1 -1
- package/dist/image.min.js +1 -1
- package/dist/noise.min.js +1 -1
- package/dist/tween.min.js +1 -1
- package/package.json +2 -2
- package/src/camera/index.js +6 -33
- package/src/collision/intersection.js +1 -1
- package/src/collision/resolverect.js +1 -1
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var c=Object.defineProperty;var p=(
|
|
1
|
+
(()=>{var c=Object.defineProperty;var p=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(r=!0)=>{for(let e in globalThis.utils)e!=="global"&&(r||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var m={};p(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>g,ANCHOR_CENTER:()=>h,ANCHOR_TOP_LEFT:()=>l,ANCHOR_TOP_RIGHT:()=>f,Actor:()=>u});var x=2*Math.PI,n=class{x;y;constructor(e=0,t=e){this.x=e,this.y=t}toString(){return`Vector (${this.x}, ${this.y})`}},b=r=>r instanceof n,a=(r=0,e=r)=>(b(r)&&(e=r.y,r=r.x),new n(r,e));var h=a(.5,.5),l=a(0,0),f=a(1,0),d=a(0,1),g=a(1,1),u=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(e,t,s=l){this.sprite=e,this.pos=t||a(0),this._o=a(s),this._s=a(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,t=e){this._s.x=e,this._s.y=t}scaleBy(e,t=e){this._s.x*=e,this._s.y*=t}getBounds(e=!0){let t=this.sprite.width*(e?this._s.x:1),s=this.sprite.height*(e?this._s.y:1),i=this.pos.x-t*this.anchor.x,o=this.pos.y-s*this.anchor.y;return[i,o,t,s]}draw(e=globalThis,t=!0){this.hidden||this.opacity<=0||(t&&e.push(),this.transform(e),this.drawImage(e),t&&e.pop())}transform(e){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,t=!0){let s=this.anchor,i=-this.sprite.width*(this.flipX?1-s.x:s.x),o=-this.sprite.height*(this.flipY?1-s.y:s.y);t&&e.alpha(this.opacity),e.image(i,o,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
|
package/dist/all.js
CHANGED
|
@@ -127,11 +127,6 @@
|
|
|
127
127
|
rotation = 0;
|
|
128
128
|
/** @type {number} */
|
|
129
129
|
scale = 1;
|
|
130
|
-
_shake = {
|
|
131
|
-
x: 0,
|
|
132
|
-
y: 0,
|
|
133
|
-
removeListener: null
|
|
134
|
-
};
|
|
135
130
|
/**
|
|
136
131
|
* @param {LitecanvasInstance} engine
|
|
137
132
|
*/
|
|
@@ -145,6 +140,11 @@
|
|
|
145
140
|
);
|
|
146
141
|
this.x = this.width / 2;
|
|
147
142
|
this.y = this.height / 2;
|
|
143
|
+
this._shake = {
|
|
144
|
+
x: 0,
|
|
145
|
+
y: 0,
|
|
146
|
+
removeListener: null
|
|
147
|
+
};
|
|
148
148
|
}
|
|
149
149
|
resize(width, height) {
|
|
150
150
|
this.width = width;
|
|
@@ -246,31 +246,6 @@
|
|
|
246
246
|
getBounds() {
|
|
247
247
|
return [this.ox, this.oy, this.width, this.height];
|
|
248
248
|
}
|
|
249
|
-
/**
|
|
250
|
-
* Check if a rect is inside of the camera.
|
|
251
|
-
*
|
|
252
|
-
* @param {number} x
|
|
253
|
-
* @param {number} y
|
|
254
|
-
* @param {number} width
|
|
255
|
-
* @param {number} height
|
|
256
|
-
* @returns {boolean}
|
|
257
|
-
*/
|
|
258
|
-
viewing(x, y, width, height) {
|
|
259
|
-
const cameraX = this.width / 2 - this.x;
|
|
260
|
-
const cameraY = this.height / 2 - this.y;
|
|
261
|
-
const cameraWidth = this.width / this.scale;
|
|
262
|
-
const cameraHeight = this.height / this.scale;
|
|
263
|
-
return this._engine.colrect(
|
|
264
|
-
x,
|
|
265
|
-
y,
|
|
266
|
-
width,
|
|
267
|
-
height,
|
|
268
|
-
cameraX,
|
|
269
|
-
cameraY,
|
|
270
|
-
cameraWidth,
|
|
271
|
-
cameraHeight
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
249
|
/**
|
|
275
250
|
* Shake the camera
|
|
276
251
|
*
|
package/dist/all.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var Mt=Object.defineProperty;var It=(e,t)=>{for(var s in t)Mt(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 z={};It(z,{ANCHOR_BOT_LEFT:()=>te,ANCHOR_BOT_RIGHT:()=>ee,ANCHOR_CENTER:()=>Qt,ANCHOR_TOP_LEFT:()=>J,ANCHOR_TOP_RIGHT:()=>Jt,Actor:()=>
|
|
2
|
-
`)}},
|
|
1
|
+
(()=>{var Mt=Object.defineProperty;var It=(e,t)=>{for(var s in t)Mt(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 z={};It(z,{ANCHOR_BOT_LEFT:()=>te,ANCHOR_BOT_RIGHT:()=>ee,ANCHOR_CENTER:()=>Qt,ANCHOR_TOP_LEFT:()=>J,ANCHOR_TOP_RIGHT:()=>Jt,Actor:()=>F,BACK_IN:()=>oe,BACK_IN_OUT:()=>ue,BACK_OUT:()=>ne,BOUNCE_IN:()=>mt,BOUNCE_IN_OUT:()=>ce,BOUNCE_OUT:()=>H,Camera:()=>y,DOWN:()=>Zt,EASE_IN:()=>re,EASE_IN_OUT:()=>ie,EASE_OUT:()=>ae,ELASTIC_IN:()=>le,ELASTIC_IN_OUT:()=>me,ELASTIC_OUT:()=>he,Grid:()=>M,LEFT:()=>Kt,LINEAR:()=>ht,Noise:()=>Y,ONE:()=>Vt,RIGHT:()=>$t,TypedGrid:()=>C,UP:()=>Wt,Vector:()=>w,ZERO:()=>Q,advance:()=>rt,choose:()=>wt,colcirc:()=>j,colrect:()=>B,diff:()=>tt,dist:()=>it,flipImage:()=>ft,fract:()=>st,head:()=>Nt,intersection:()=>E,last:()=>Tt,lerpAngle:()=>lt,mag:()=>ot,makeCircle:()=>xt,makeRectangle:()=>gt,mean:()=>nt,median:()=>ut,mod:()=>at,range:()=>_t,resolverect:()=>U,scaleImage:()=>bt,shuffle:()=>yt,sum:()=>A,tail:()=>Et,tintImage:()=>dt,tween:()=>se,vec:()=>o,vecAbs:()=>zt,vecAdd:()=>S,vecAngle:()=>Ft,vecAngleBetween:()=>Rt,vecCeil:()=>Xt,vecClamp:()=>jt,vecCross:()=>Ht,vecDist:()=>Lt,vecDist2:()=>Dt,vecDiv:()=>I,vecDot:()=>K,vecEq:()=>O,vecFloor:()=>Ut,vecIsZero:()=>Gt,vecLerp:()=>vt,vecLimit:()=>St,vecMag:()=>$,vecMag2:()=>Z,vecMove:()=>qt,vecMult:()=>N,vecNorm:()=>D,vecRand:()=>Yt,vecReflect:()=>Ct,vecRotate:()=>Pt,vecRound:()=>Bt,vecSet:()=>W,vecSetMag:()=>Ot,vecSub:()=>L,wave:()=>et});var y=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;constructor(t=null,s=0,r=0,a=null,i=null){this._engine=t||globalThis,this.ox=s,this.oy=r,this.resize(a||this._engine.WIDTH-s,i||this._engine.HEIGHT-r),this.x=this.width/2,this.y=this.height/2,this._shake={x:0,y:0,removeListener:null}}resize(t,s){this.width=t,this.height=s,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 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(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,r={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,r.x=a*t-i*s+this.x,r.y=i*t+a*s+this.y,r}getCameraPoint(t,s,r={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=a*t-i*s,s=i*t+a*s,r.x=t*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(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",r=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),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 E=(e,t,s,r,a,i,n,u)=>{let h=Math.max(e,a),d=Math.min(e+s,a+n)-h,m=Math.max(t,i),x=Math.min(t+r,i+u)-m;return[h,m,d,x]};var U=(e,t,s,r,a,i,n,u)=>{let[h,d,m,x]=E(e,t,s,r,a,i,n,u),b="",_=e,l=t;return m<x?e<a?(b="right",_=a-s):(b="left",_=a+n):t<i?(b="bottom",l=i-r):(b="top",l=i+u),{direction:b,x:_,y:l}};var B=(e,t,s,r,a,i,n,u)=>e<a+n&&e+s>a&&t<i+u&&t+r>i;var j=(e,t,s,r,a,i)=>(r-e)*(r-e)+(a-t)*(a-t)<=(s+i)*(s+i);var M=class e{_w;_h;_c;constructor(t,s,r=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=r}[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,s)=>this.set(t,s,void 0))}get width(){return this._w}get height(){return this._h}set(t,s,r){this._c[this.pointToIndex(t,s)]=r}get(t,s){return this._c[this.pointToIndex(t,s)]}has(t,s){return this.get(t,s)!=null}check(t,s){return t>=0&&t<this._w&&s>=0&&s<this._h}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 r=s?this.length-1:0,a=s?-1:this.length,i=s?-1:1;for(;r!==a;){let n=this.indexToPointX(r),u=this.indexToPointY(r),h=this._c[r];if(t(n,u,h,this)===!1)break;r+=i}}fill(t){this.forEach((s,r)=>{this.set(s,r,t)})}clampX(t){return q(t,0,this._w-1)}clampY(t){return q(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let r=[];return this.forEach((a,i,n)=>{r[i]=r[i]||"",r[i]+=n+t}),r.join(`
|
|
2
|
+
`)}},C=class e extends M{constructor(t,s,r=Uint8Array){super(t,s,null),this._c=new r(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,r,a)=>{t.set(s,r,a)}),t}};function q(e,t,s){return e<t?t:e>s?s:e}var At=Math.sqrt,G=Math.cos,V=Math.sin,kt=2*Math.PI,w=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},g=e=>e instanceof w,o=(e=0,t=e)=>(g(e)&&(t=e.y,e=e.x),new w(e,t)),O=(e,t,s=t)=>g(t)?O(e,t.x,t.y):e.x===t&&e.y===s,W=(e,t,s=t)=>(g(t)?W(e,t.x,t.y):(e.x=t,e.y=s),e),S=(e,t,s=t)=>g(t)?S(e,t.x,t.y):(e.x+=t,e.y+=s,e),L=(e,t,s=t)=>g(t)?L(e,t.x,t.y):(e.x-=t,e.y-=s,e),N=(e,t,s=t)=>g(t)?N(e,t.x,t.y):(e.x*=t,e.y*=s,e),I=(e,t,s=t)=>g(t)?I(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),Pt=(e,t)=>{let s=G(t),r=V(t);return e.x=s*e.x-r*e.y,e.y=r*e.x+s*e.y,e},Ct=(e,t)=>{let s=D(o(t));return L(e,N(s,2*K(e,s)))},Ot=(e,t)=>(D(e),N(e,t),e),$=e=>Math.hypot(e.x,e.y),Z=e=>e.x*e.x+e.y*e.y,D=e=>{let t=$(e);return t>0&&I(e,t),e},St=(e,t=1)=>{let s=Z(e);return s>t*t&&(I(e,At(s)),N(e,t)),e},Lt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Dt=(e,t)=>{let s=e.x-t.x,r=e.y-t.y;return s*s+r*r},Ft=e=>Math.atan2(e.y,e.x),Rt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),K=(e,t)=>e.x*t.x+e.y*t.y,Ht=(e,t)=>e.x*t.y-e.y*t.x,vt=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Yt=(e=1,t=e,s=globalThis.rand||Math.random)=>{let r=s()*kt,a=s()*(t-e)+e;return o(G(r)*a,V(r)*a)},zt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Xt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Ut=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),Bt=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),jt=(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),qt=(e,t,s=1)=>S(e,t.x*s,t.y*s),Gt=e=>O(e,Q),Q=o(0,0),Vt=o(1,1),Wt=o(0,-1),$t=o(1,0),Zt=o(0,1),Kt=o(-1,0);var Qt=o(.5,.5),J=o(0,0),Jt=o(1,0),te=o(0,1),ee=o(1,1),F=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,r=J){this.sprite=t,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),a=this.pos.x-s*this.anchor.x,i=this.pos.y-r*this.anchor.y;return[a,i,s,r]}draw(t=globalThis,s=!0){this.hidden||this.opacity<=0||(s&&t.push(),this.transform(t),this.drawImage(t),s&&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,s=!0){let r=this.anchor,a=-this.sprite.width*(this.flipX?1-r.x:r.x),i=-this.sprite.height*(this.flipY?1-r.y:r.y);s&&t.alpha(this.opacity),t.image(a,i,this.sprite)}};var tt=(e,t)=>Math.abs(t-e)||0;var et=(e,t,s,r=Math.sin)=>e+(r(s)+1)/2*(t-e);var st=e=>e%1||0;var rt=advance=(e,t,s,r=1)=>{s&&(t.x+=s.x*r,t.y+=s.y*r),e.x+=t.x*r,e.y+=t.y*r};var at=(e,t)=>(t+e%t)%t;var it=(e,t,s,r)=>Math.hypot(s-e,r-t);var ot=(e,t)=>Math.hypot(e,t);var A=e=>{let t=0;for(let s=0;s<e.length;s++)t+=e[s];return t};var nt=e=>A(e)/e.length;var ut=(...e)=>{let t=e.sort((r,a)=>r-a),s=Math.floor(t.length/2);return t.length%2===0?(t[s-1]+t[s])/2:t[s]};var lt=(e,t,s)=>{let r=(t-e)%360;return r>180?r-=360:r<-180&&(r+=360),e+r*s};var k=Math.PI/2,se=(e,t,s,r=1,a=ht)=>new R(e,t,s,r,a),ht=e=>e,re=e=>e*e,ae=e=>-e*(e-2),ie=e=>e<.5?2*e*e:-2*e*e+4*e-1,oe=e=>e*e*e-e*Math.sin(e*Math.PI),ne=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},ue=e=>{if(e<.5){let s=2*e;return .5*(s*s*s-s*Math.sin(s*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},le=e=>Math.sin(13*k*e)*Math.pow(2,10*(e-1)),he=e=>Math.sin(-13*k*(e+1))*Math.pow(2,-10*e)+1,me=e=>{if(e<.5){let r=Math.sin(13*k*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*r*a}let t=Math.sin(-13*k*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},mt=e=>1-H(1-e),H=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,ce=e=>e<.5?.5*mt(e*2):.5*H(e*2-1)+.5,R=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,r,a,i){this._o=t,this._p=s,this._x=r,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 s=this._o[this._p]||0,r=this._rel?s+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(s,r,this._e(i/this._d)),this._t+=a,i>=this._d&&(this._o[this._p]=r,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let s of this._cb)s(this._o);return this}restart(t=null,s=!1){return this.stop(s).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 ct=4,P=1<<ct,pt=8,pe=1<<pt,f=4095,v=e=>.5*(1-Math.cos(e*Math.PI)),Y=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,s=0,r=0){t<0&&(t=-t),s<0&&(s=-s),r<0&&(r=-r);let a=Math.floor(t),i=Math.floor(s),n=Math.floor(r),u=t-a,h=s-i,d=r-n,m,x,b=0,_=.5,l,c,T;for(let X=0;X<this._po;X++){let p=a+(i<<ct)+(n<<pt);m=v(u),x=v(h),l=this._p[p&f],l+=m*(this._p[p+1&f]-l),c=this._p[p+P&f],c+=m*(this._p[p+P+1&f]-c),l+=x*(c-l),p+=pe,c=this._p[p&f],c+=m*(this._p[p+1&f]-c),T=this._p[p+P&f],T+=m*(this._p[p+P+1&f]-T),c+=x*(T-c),l+=v(d)*(c-l),b+=l*_,_*=this._pf,a<<=1,u*=2,i<<=1,h*=2,n<<=1,d*=2,u>=1&&(a++,u--),h>=1&&(i++,h--),d>=1&&(n++,d--)}return b}noiseDetail(t,s){t>0&&(this._po=t),s>0&&(this._pf=s)}noiseSeed(t=null){t!=null&&this._e.seed(t);let s=this._e.rand||Math.random;for(let r=0;r<f+1;r++)this._p[r]=s()}};var ft=(e,t=!0,s=!1,r=globalThis)=>r.paint(e.width,e.height,a=>{r.push(),r.scale(t?-1:1,s?-1:1),r.image(t?-e.width:0,s?-e.height:0,e),r.pop()});var bt=(e,t,s=!0,r=globalThis)=>r.paint(e.width*t,e.height*t,a=>{r.push(),a.imageSmoothingEnabled=!s,r.scale(t),r.image(0,0,e),r.pop()});var dt=(e,t,s=1,r=globalThis)=>r.paint(e.width,e.height,a=>{r.push(),r.alpha(s),r.rectfill(0,0,e.width,e.height,t),a.globalCompositeOperation="destination-atop",r.alpha(1),r.image(0,0,e),r.pop()});var xt=(e,t,{borderWidth:s=0,borderColor:r=0,engine:a=globalThis}={})=>{let i=e*2+s;return a.paint(i,i,()=>{a.circfill(i/2,i/2,e,t),s>0&&(a.linewidth(s),a.stroke(r))})};var gt=(e,t,s,{borderWidth:r=0,borderColor:a=0,engine:i=globalThis}={})=>{let n=e+r*2,u=t+r*2;return i.paint(n,u,()=>{i.rectfill(r>0?r:0,r>0?r:0,e,t,s),r>0&&(i.linewidth(r),i.stroke(a))})};var _t=(e,t=0,s=1)=>[...new Array(e).keys()].map(r=>t+s*r);var yt=(e,t=globalThis.rand||Math.random)=>{e=[...e];for(let s=e.length-1;s>0;s--){let r=Math.floor(t()*(s+1)),a=e[s];e[s]=e[r],e[r]=a}return e};var wt=(e,t=globalThis.rand||Math.random)=>e[Math.floor(t()*e.length)];var Nt=e=>e[0];var Tt=e=>e[e.length-1];var Et=e=>e.slice(1);globalThis.utils=Object.assign(globalThis.utils||{},z);})();
|
|
3
3
|
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/camera.js
CHANGED
|
@@ -30,11 +30,6 @@
|
|
|
30
30
|
rotation = 0;
|
|
31
31
|
/** @type {number} */
|
|
32
32
|
scale = 1;
|
|
33
|
-
_shake = {
|
|
34
|
-
x: 0,
|
|
35
|
-
y: 0,
|
|
36
|
-
removeListener: null
|
|
37
|
-
};
|
|
38
33
|
/**
|
|
39
34
|
* @param {LitecanvasInstance} engine
|
|
40
35
|
*/
|
|
@@ -48,6 +43,11 @@
|
|
|
48
43
|
);
|
|
49
44
|
this.x = this.width / 2;
|
|
50
45
|
this.y = this.height / 2;
|
|
46
|
+
this._shake = {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
removeListener: null
|
|
50
|
+
};
|
|
51
51
|
}
|
|
52
52
|
resize(width, height) {
|
|
53
53
|
this.width = width;
|
|
@@ -149,31 +149,6 @@
|
|
|
149
149
|
getBounds() {
|
|
150
150
|
return [this.ox, this.oy, this.width, this.height];
|
|
151
151
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Check if a rect is inside of the camera.
|
|
154
|
-
*
|
|
155
|
-
* @param {number} x
|
|
156
|
-
* @param {number} y
|
|
157
|
-
* @param {number} width
|
|
158
|
-
* @param {number} height
|
|
159
|
-
* @returns {boolean}
|
|
160
|
-
*/
|
|
161
|
-
viewing(x, y, width, height) {
|
|
162
|
-
const cameraX = this.width / 2 - this.x;
|
|
163
|
-
const cameraY = this.height / 2 - this.y;
|
|
164
|
-
const cameraWidth = this.width / this.scale;
|
|
165
|
-
const cameraHeight = this.height / this.scale;
|
|
166
|
-
return this._engine.colrect(
|
|
167
|
-
x,
|
|
168
|
-
y,
|
|
169
|
-
width,
|
|
170
|
-
height,
|
|
171
|
-
cameraX,
|
|
172
|
-
cameraY,
|
|
173
|
-
cameraWidth,
|
|
174
|
-
cameraHeight
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
152
|
/**
|
|
178
153
|
* Shake the camera
|
|
179
154
|
*
|
package/dist/camera.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;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,this._shake={x:0,y:0,removeListener:null}}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]}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/image.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var f=Object.defineProperty;var d=(t,a)=>{for(var
|
|
1
|
+
(()=>{var f=Object.defineProperty;var d=(t,a)=>{for(var r in a)f(t,r,{get:a[r],enumerable:!0})};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 n={};d(n,{flipImage:()=>o,makeCircle:()=>l,makeRectangle:()=>p,scaleImage:()=>u,tintImage:()=>m});var o=(t,a=!0,r=!1,e=globalThis)=>e.paint(t.width,t.height,s=>{e.push(),e.scale(a?-1:1,r?-1:1),e.image(a?-t.width:0,r?-t.height:0,t),e.pop()});var u=(t,a,r=!0,e=globalThis)=>e.paint(t.width*a,t.height*a,s=>{e.push(),s.imageSmoothingEnabled=!r,e.scale(a),e.image(0,0,t),e.pop()});var m=(t,a,r=1,e=globalThis)=>e.paint(t.width,t.height,s=>{e.push(),e.alpha(r),e.rectfill(0,0,t.width,t.height,a),s.globalCompositeOperation="destination-atop",e.alpha(1),e.image(0,0,t),e.pop()});var l=(t,a,{borderWidth:r=0,borderColor:e=0,engine:s=globalThis}={})=>{let i=t*2+r;return s.paint(i,i,()=>{s.circfill(i/2,i/2,t,a),r>0&&(s.linewidth(r),s.stroke(e))})};var p=(t,a,r,{borderWidth:e=0,borderColor:s=0,engine:i=globalThis}={})=>{let b=t+e*2,c=a+e*2;return i.paint(b,c,()=>{i.rectfill(e>0?e:0,e>0?e:0,t,a,r),e>0&&(i.linewidth(e),i.stroke(s))})};globalThis.utils=Object.assign(globalThis.utils||{},n);})();
|
package/dist/noise.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var A=Object.defineProperty;var
|
|
1
|
+
(()=>{var A=Object.defineProperty;var k=(o,e)=>{for(var t in e)A(o,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(o=!0)=>{for(let e in globalThis.utils)e!=="global"&&(o||globalThis[e]===void 0)&&(globalThis[e]=globalThis.utils[e])};var v={};k(v,{Noise:()=>y});var E=4,h=1<<E,T=8,D=1<<T,i=4095,N=o=>.5*(1-Math.cos(o*Math.PI)),y=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 u=Math.floor(e),l=Math.floor(t),p=Math.floor(r),b=e-u,c=t-l,f=r-p,m,g,x=0,w=.5,n,a,d;for(let _=0;_<this._po;_++){let s=u+(l<<E)+(p<<T);m=N(b),g=N(c),n=this._p[s&i],n+=m*(this._p[s+1&i]-n),a=this._p[s+h&i],a+=m*(this._p[s+h+1&i]-a),n+=g*(a-n),s+=D,a=this._p[s&i],a+=m*(this._p[s+1&i]-a),d=this._p[s+h&i],d+=m*(this._p[s+h+1&i]-d),a+=g*(d-a),n+=N(f)*(a-n),x+=n*w,w*=this._pf,u<<=1,b*=2,l<<=1,c*=2,p<<=1,f*=2,b>=1&&(u++,b--),c>=1&&(l++,c--),f>=1&&(p++,f--)}return x}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<i+1;r++)this._p[r]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},v);})();
|
package/dist/tween.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var c=Object.defineProperty;var b=(e,t)=>{for(var r in t)c(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 m={};b(m,{BACK_IN:()=>_,BACK_IN_OUT:()=>y,BACK_OUT:()=>N,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>E,BOUNCE_OUT:()=>u,EASE_IN:()=>f,EASE_IN_OUT:()=>g,EASE_OUT:()=>d,ELASTIC_IN:()=>x,ELASTIC_IN_OUT:()=>v,ELASTIC_OUT:()=>w,LINEAR:()=>l,tween:()=>h});var n=Math.PI/2,h=(e,t,r,s=1,a=l)=>new o(e,t,r,s,a),l=e=>e,f=e=>e*e,d=e=>-e*(e-2),g=e=>e<.5?2*e*e:-2*e*e+4*e-1,_=e=>e*e*e-e*Math.sin(e*Math.PI),N=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},y=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},x=e=>Math.sin(13*n*e)*Math.pow(2,10*(e-1)),w=e=>Math.sin(-13*n*(e+1))*Math.pow(2,-10*e)+1,v=e=>{if(e<.5){let s=Math.sin(13*n*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*s*a}let t=Math.sin(-13*n*(2*e-1+1)),r=Math.pow(2,-10*(2*e-1));return .5*(t*r+2)},p=e=>1-u(1-e),u=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,E=e=>e<.5?.5*p(e*2):.5*u(e*2-1)+.5,o=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}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litecanvas/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "Utilities to help build litecanvas games",
|
|
5
5
|
"author": "Luiz Bills <luizbills@pm.me>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"litecanvas": "latest"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"esbuild": "^0.25.
|
|
40
|
+
"esbuild": "^0.25.2",
|
|
41
41
|
"gzip-size": "^7.0.0",
|
|
42
42
|
"prettier": "^3.5.3"
|
|
43
43
|
}
|
package/src/camera/index.js
CHANGED
|
@@ -23,12 +23,6 @@ export default class Camera {
|
|
|
23
23
|
/** @type {number} */
|
|
24
24
|
scale = 1
|
|
25
25
|
|
|
26
|
-
_shake = {
|
|
27
|
-
x: 0,
|
|
28
|
-
y: 0,
|
|
29
|
-
removeListener: null,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
26
|
/**
|
|
33
27
|
* @param {LitecanvasInstance} engine
|
|
34
28
|
*/
|
|
@@ -45,6 +39,12 @@ export default class Camera {
|
|
|
45
39
|
|
|
46
40
|
this.x = this.width / 2
|
|
47
41
|
this.y = this.height / 2
|
|
42
|
+
|
|
43
|
+
this._shake = {
|
|
44
|
+
x: 0,
|
|
45
|
+
y: 0,
|
|
46
|
+
removeListener: null,
|
|
47
|
+
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
resize(width, height) {
|
|
@@ -171,33 +171,6 @@ export default class Camera {
|
|
|
171
171
|
return [this.ox, this.oy, this.width, this.height]
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
/**
|
|
175
|
-
* Check if a rect is inside of the camera.
|
|
176
|
-
*
|
|
177
|
-
* @param {number} x
|
|
178
|
-
* @param {number} y
|
|
179
|
-
* @param {number} width
|
|
180
|
-
* @param {number} height
|
|
181
|
-
* @returns {boolean}
|
|
182
|
-
*/
|
|
183
|
-
viewing(x, y, width, height) {
|
|
184
|
-
const cameraX = this.width / 2 - this.x
|
|
185
|
-
const cameraY = this.height / 2 - this.y
|
|
186
|
-
const cameraWidth = this.width / this.scale
|
|
187
|
-
const cameraHeight = this.height / this.scale
|
|
188
|
-
|
|
189
|
-
return this._engine.colrect(
|
|
190
|
-
x,
|
|
191
|
-
y,
|
|
192
|
-
width,
|
|
193
|
-
height,
|
|
194
|
-
cameraX,
|
|
195
|
-
cameraY,
|
|
196
|
-
cameraWidth,
|
|
197
|
-
cameraHeight
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
174
|
/**
|
|
202
175
|
* Shake the camera
|
|
203
176
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the resulting rectangle of the intersection between two rectangles.
|
|
3
|
-
* Note: this function should be called with or after `
|
|
3
|
+
* Note: this function should be called with or after `colrect`.
|
|
4
4
|
*
|
|
5
5
|
* @param {number} x1
|
|
6
6
|
* @param {number} y1
|
|
@@ -2,7 +2,7 @@ import intersection from "./intersection"
|
|
|
2
2
|
/**
|
|
3
3
|
* Determines the direction of the collision between two rectangles and
|
|
4
4
|
* the new position of the first rectangle to be adjusted.
|
|
5
|
-
* Note: this function should be called with or after `
|
|
5
|
+
* Note: this function should be called with or after `colrect`.
|
|
6
6
|
*
|
|
7
7
|
* @param {number} x1
|
|
8
8
|
* @param {number} y1
|