@litecanvas/utils 0.24.1 → 0.25.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 +2 -2
- package/dist/actor.min.js +1 -1
- package/dist/all.js +29 -3
- package/dist/all.min.js +2 -2
- package/dist/image.js +40 -0
- package/dist/image.min.js +1 -0
- package/dist/noise.min.js +1 -1
- package/dist/tween.min.js +1 -1
- package/dist/vector.js +3 -3
- package/package.json +1 -1
- package/src/image/_web.js +8 -0
- package/src/image/scale-image.js +18 -0
- package/src/image/tint.js +21 -0
- package/src/index.js +2 -0
- package/src/math/advance.js +2 -2
- package/src/vector/index.js +6 -6
package/dist/actor.js
CHANGED
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var u=Object.defineProperty;var p=(o,t)=>{for(var e in t)u(o,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let o in globalThis.utils)o!=="global"&&(globalThis[o]=globalThis.utils[o])};var l={};p(l,{ANCHOR_BOT_LEFT:()=>x,ANCHOR_BOT_RIGHT:()=>g,ANCHOR_CENTER:()=>d,ANCHOR_TOP_LEFT:()=>f,ANCHOR_TOP_RIGHT:()=>y,Actor:()=>c});var T=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})`}},h=o=>o instanceof n,r=(o=0,t=o)=>(h(o)&&(t=o.y,o=o.x),new n(o,t));var d=r(.5,.5),f=r(0,0),y=r(1,0),x=r(0,1),g=r(1,1),c=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,s=f){this.sprite=t,this.pos=e||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}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),s=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,a=this.pos.y-s*this.anchor.y;return[i,a,e,s]}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 s=this.anchor,i=-this.sprite.width*(this.flipX?1-s.x:s.x),a=-this.sprite.height*(this.flipY?1-s.y:s.y);e&&t.alpha(this.opacity),t.image(i,a,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},l);})();
|
package/dist/all.js
CHANGED
|
@@ -54,6 +54,8 @@
|
|
|
54
54
|
mod: () => mod_default,
|
|
55
55
|
range: () => range_default,
|
|
56
56
|
resolve: () => resolve_default,
|
|
57
|
+
scaleImage: () => scale_image_default,
|
|
58
|
+
tint: () => tint_default,
|
|
57
59
|
tween: () => tween,
|
|
58
60
|
vec: () => vec,
|
|
59
61
|
vecAbs: () => vecAbs,
|
|
@@ -568,8 +570,8 @@
|
|
|
568
570
|
/** @type {number} */
|
|
569
571
|
y;
|
|
570
572
|
/**
|
|
571
|
-
* @param {number} x
|
|
572
|
-
* @param {number} y
|
|
573
|
+
* @param {number} [x=0]
|
|
574
|
+
* @param {number} [y]
|
|
573
575
|
*/
|
|
574
576
|
constructor(x = 0, y = x) {
|
|
575
577
|
this.x = x;
|
|
@@ -720,7 +722,7 @@
|
|
|
720
722
|
if (v.y > max.y) v.y = max.y;
|
|
721
723
|
return v;
|
|
722
724
|
};
|
|
723
|
-
var vecMove = (
|
|
725
|
+
var vecMove = (from, to, delta = 1) => vecAdd(from, to.x * delta, to.y * delta);
|
|
724
726
|
var vecIsZero = (v) => vecEq(v, ZERO);
|
|
725
727
|
var ZERO = /* @__PURE__ */ vec(0, 0);
|
|
726
728
|
var ONE = /* @__PURE__ */ vec(1, 1);
|
|
@@ -1258,6 +1260,30 @@
|
|
|
1258
1260
|
}
|
|
1259
1261
|
};
|
|
1260
1262
|
|
|
1263
|
+
// src/image/tint.js
|
|
1264
|
+
var tint_default = (img, color, opacity = 1, engine = globalThis) => {
|
|
1265
|
+
return engine.paint(img.width, img.height, (ctx) => {
|
|
1266
|
+
engine.push();
|
|
1267
|
+
engine.alpha(opacity);
|
|
1268
|
+
engine.rectfill(0, 0, img.width, img.height, color);
|
|
1269
|
+
ctx.globalCompositeOperation = "destination-atop";
|
|
1270
|
+
engine.alpha(1);
|
|
1271
|
+
engine.image(0, 0, img);
|
|
1272
|
+
engine.pop();
|
|
1273
|
+
});
|
|
1274
|
+
};
|
|
1275
|
+
|
|
1276
|
+
// src/image/scale-image.js
|
|
1277
|
+
var scale_image_default = (img, factor, pixelart = true, engine = globalThis) => {
|
|
1278
|
+
return engine.paint(img.width * factor, img.height * factor, (ctx) => {
|
|
1279
|
+
engine.push();
|
|
1280
|
+
ctx.imageSmoothingEnabled = !pixelart;
|
|
1281
|
+
engine.scale(factor);
|
|
1282
|
+
engine.image(0, 0, img);
|
|
1283
|
+
engine.pop();
|
|
1284
|
+
});
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1261
1287
|
// src/_web.js
|
|
1262
1288
|
globalThis.utils = Object.assign(globalThis.utils || {}, src_exports);
|
|
1263
1289
|
})();
|
package/dist/all.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`)}},S=class e extends b{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,r)=>{t.set(s,i,r)}),t}};function
|
|
1
|
+
(()=>{var lt=Object.defineProperty;var ut=(e,t)=>{for(var s in t)lt(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 W={};ut(W,{ANCHOR_BOT_LEFT:()=>Nt,ANCHOR_BOT_RIGHT:()=>Bt,ANCHOR_CENTER:()=>Xt,ANCHOR_TOP_LEFT:()=>J,ANCHOR_TOP_RIGHT:()=>Yt,Actor:()=>R,BACK_IN:()=>Gt,BACK_IN_OUT:()=>$t,BACK_OUT:()=>jt,BOUNCE_IN:()=>ot,BOUNCE_IN_OUT:()=>Kt,BOUNCE_OUT:()=>Y,Camera:()=>w,DOWN:()=>Dt,EASE_IN:()=>Ut,EASE_IN_OUT:()=>Vt,EASE_OUT:()=>Ft,ELASTIC_IN:()=>qt,ELASTIC_IN_OUT:()=>zt,ELASTIC_OUT:()=>Zt,Grid:()=>b,LEFT:()=>Rt,LINEAR:()=>rt,Noise:()=>B,ONE:()=>Ct,RIGHT:()=>Pt,TypedGrid:()=>S,UP:()=>Lt,Vector:()=>T,ZERO:()=>K,advance:()=>st,diff:()=>Q,fract:()=>tt,intersection:()=>I,mod:()=>it,range:()=>et,resolve:()=>F,scaleImage:()=>ct,tint:()=>at,tween:()=>Wt,vec:()=>n,vecAbs:()=>It,vecAdd:()=>L,vecAngle:()=>mt,vecAngleBetween:()=>wt,vecCeil:()=>bt,vecClamp:()=>Ot,vecCross:()=>Tt,vecDist:()=>gt,vecDist2:()=>yt,vecDiv:()=>A,vecDot:()=>z,vecEq:()=>C,vecFloor:()=>At,vecIsZero:()=>kt,vecLerp:()=>Et,vecLimit:()=>xt,vecMag:()=>q,vecMag2:()=>Z,vecMove:()=>St,vecMult:()=>E,vecNorm:()=>D,vecRand:()=>Mt,vecReflect:()=>_t,vecRotate:()=>pt,vecRound:()=>Ht,vecSet:()=>$,vecSetMag:()=>dt,vecSub:()=>P,wave:()=>v});var I=(e,t,s,i,r,o,h,a)=>{let c=Math.max(e,r),x=Math.min(e+s,r+h)-c,u=Math.max(t,o),g=Math.min(t+i,o+a)-u;return[c,u,x,g]};var F=(e,t,s,i,r,o,h,a)=>{let[c,x,u,g]=I(e,t,s,i,r,o,h,a),d="",m=e,l=t;return u<g?e<r?(d="right",m=r-s):(d="left",m=r+h):t<o?(d="bottom",l=o-i):(d="top",l=o+a),{direction:d,x:m,y:l}};var w=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,r=null,o=null){this._engine=t||globalThis,this.ox=s,this.oy=i,this.resize(r||this._engine.WIDTH-s,o||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){if(this._engine.push(),t){let r=path();r.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(r)}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 r=Math.cos(-this.rotation),o=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=r*t-o*s+this.x,i.y=o*t+r*s+this.y,i}getCameraPoint(t,s,i={}){let r=Math.cos(-this.rotation),o=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=r*t-o*s,s=o*t+r*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,r){let o=this.width/2-this.x,h=this.height/2-this.y,a=this.width/this.scale,c=this.height/this.scale;return this._engine.colrect(t,s,i,r,o,h,a,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 b=class e{_w;_h;_c;constructor(t,s,i=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=i}[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,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}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 i=s?this.length-1:0,r=s?-1:this.length,o=s?-1:1;for(;i!==r;){let h=this.indexToPointX(i),a=this.indexToPointY(i),c=this._c[i];if(t(h,a,c,this)===!1)break;i+=o}}fill(t){this.forEach((s,i)=>{this.set(s,i,t)})}clampX(t){return V(t,0,this._w-1)}clampY(t){return V(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((r,o,h)=>{i[o]=i[o]||"",i[o]+=h+t}),i.join(`
|
|
2
|
+
`)}},S=class e extends b{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,r)=>{t.set(s,i,r)}),t}};function V(e,t,s){return e<t?t:e>s?s:e}var k=Math.sqrt,G=Math.cos,j=Math.sin,ft=2*Math.PI,T=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},y=e=>e instanceof T,n=(e=0,t=e)=>(y(e)&&(t=e.y,e=e.x),new T(e,t)),C=(e,t,s=t)=>y(t)?C(e,t.x,t.y):e.x===t&&e.y===s,$=(e,t,s=t)=>(y(t)?$(e,t.x,t.y):(e.x=t,e.y=s),e),L=(e,t,s=t)=>y(t)?L(e,t.x,t.y):(e.x+=t,e.y+=s,e),P=(e,t,s=t)=>y(t)?P(e,t.x,t.y):(e.x-=t,e.y-=s,e),E=(e,t,s=t)=>y(t)?E(e,t.x,t.y):(e.x*=t,e.y*=s,e),A=(e,t,s=t)=>y(t)?A(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),pt=(e,t)=>{let s=G(t),i=j(t);return e.x=s*e.x-i*e.y,e.y=i*e.x+s*e.y,e},_t=(e,t)=>{let s=D(n(t));return P(e,E(s,2*z(e,s)))},dt=(e,t)=>(D(e),E(e,t),e),q=e=>k(e.x*e.x+e.y*e.y),Z=e=>e.x*e.x+e.y*e.y,D=e=>{let t=q(e);return t>0&&A(e,t),e},xt=(e,t=1)=>{let s=Z(e);return s>t*t&&(A(e,k(s)),E(e,t)),e},gt=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return k(s*s+i*i)},yt=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return s*s+i*i},mt=e=>Math.atan2(e.y,e.x),wt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),z=(e,t)=>e.x*t.x+e.y*t.y,Tt=(e,t)=>e.x*t.y-e.y*t.x,Et=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),Mt=(e=1,t=e,s=globalThis.rand||Math.random)=>{let i=s()*ft,r=s()*(t-e)+e;return n(G(i)*r,j(i)*r)},It=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),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),Ot=(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),St=(e,t,s=1)=>L(e,t.x*s,t.y*s),kt=e=>C(e,K),K=n(0,0),Ct=n(1,1),Lt=n(0,-1),Pt=n(1,0),Dt=n(0,1),Rt=n(-1,0);var Xt=n(.5,.5),J=n(0,0),Yt=n(1,0),Nt=n(0,1),Bt=n(1,1),R=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,i=J){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}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),i=this.sprite.height*(t?this._s.y:1),r=this.pos.x-s*this.anchor.x,o=this.pos.y-i*this.anchor.y;return[r,o,s,i]}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 i=this.anchor,r=-this.sprite.width*(this.flipX?1-i.x:i.x),o=-this.sprite.height*(this.flipY?1-i.y:i.y);s&&t.alpha(this.opacity),t.image(r,o,this.sprite)}};var Q=(e,t)=>Math.abs(t-e)||0;var v=(e,t,s,i=Math.sin)=>e+(i(s)+1)/2*(t-e);var tt=e=>e%1||0;var et=e=>Array.from(Array(e).keys());var st=advance=(e,t,s,i=1)=>{s&&(t.x+=s.x*i,t.y+=s.y*i),e.x+=t.x*i,e.y+=t.y*i};var it=(e,t)=>(t+e%t)%t;var H=Math.PI/2,Wt=(e,t,s,i=1,r=rt)=>new X(e,t,s,i,r),rt=e=>e,Ut=e=>e*e,Ft=e=>-e*(e-2),Vt=e=>e<.5?2*e*e:-2*e*e+4*e-1,Gt=e=>e*e*e-e*Math.sin(e*Math.PI),jt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},$t=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},qt=e=>Math.sin(13*H*e)*Math.pow(2,10*(e-1)),Zt=e=>Math.sin(-13*H*(e+1))*Math.pow(2,-10*e)+1,zt=e=>{if(e<.5){let i=Math.sin(13*H*(2*e)),r=Math.pow(2,10*(2*e-1));return .5*i*r}let t=Math.sin(-13*H*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},ot=e=>1-Y(1-e),Y=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,Kt=e=>e<.5?.5*ot(e*2):.5*Y(e*2-1)+.5,X=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,i,r,o){this._o=t,this._p=s,this._x=i,this._d=r,this._e=o,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,i=this._rel?s+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",r=>{if(this._t<=this._w){this._t+=r;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,i,this._e(o/this._d)),this._t+=r,o>=this._d&&(this._o[this._p]=i,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 nt=4,O=1<<nt,ht=8,Jt=1<<ht,_=4095,N=e=>.5*(1-Math.cos(e*Math.PI)),B=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,s=0,i=0){t<0&&(t=-t),s<0&&(s=-s),i<0&&(i=-i);let r=Math.floor(t),o=Math.floor(s),h=Math.floor(i),a=t-r,c=s-o,x=i-h,u,g,d=0,m=.5,l,f,M;for(let U=0;U<this._po;U++){let p=r+(o<<nt)+(h<<ht);u=N(a),g=N(c),l=this._p[p&_],l+=u*(this._p[p+1&_]-l),f=this._p[p+O&_],f+=u*(this._p[p+O+1&_]-f),l+=g*(f-l),p+=Jt,f=this._p[p&_],f+=u*(this._p[p+1&_]-f),M=this._p[p+O&_],M+=u*(this._p[p+O+1&_]-M),f+=g*(M-f),l+=N(x)*(f-l),d+=l*m,m*=this._pf,r<<=1,a*=2,o<<=1,c*=2,h<<=1,x*=2,a>=1&&(r++,a--),c>=1&&(o++,c--),x>=1&&(h++,x--)}return d}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 i=0;i<_+1;i++)this._p[i]=s()}};var at=(e,t,s=1,i=globalThis)=>i.paint(e.width,e.height,r=>{i.push(),i.alpha(s),i.rectfill(0,0,e.width,e.height,t),r.globalCompositeOperation="destination-atop",i.alpha(1),i.image(0,0,e),i.pop()});var ct=(e,t,s=!0,i=globalThis)=>i.paint(e.width*t,e.height*t,r=>{i.push(),r.imageSmoothingEnabled=!s,i.scale(t),i.image(0,0,e),i.pop()});globalThis.utils=Object.assign(globalThis.utils||{},W);})();
|
|
3
3
|
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/image.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
// src/_global.js
|
|
3
|
+
globalThis.utils = globalThis.utils || {};
|
|
4
|
+
globalThis.utils.global = () => {
|
|
5
|
+
for (const key in globalThis.utils) {
|
|
6
|
+
if ("global" === key) continue;
|
|
7
|
+
globalThis[key] = globalThis.utils[key];
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/image/tint.js
|
|
12
|
+
var tint_default = (img, color, opacity = 1, engine = globalThis) => {
|
|
13
|
+
return engine.paint(img.width, img.height, (ctx) => {
|
|
14
|
+
engine.push();
|
|
15
|
+
engine.alpha(opacity);
|
|
16
|
+
engine.rectfill(0, 0, img.width, img.height, color);
|
|
17
|
+
ctx.globalCompositeOperation = "destination-atop";
|
|
18
|
+
engine.alpha(1);
|
|
19
|
+
engine.image(0, 0, img);
|
|
20
|
+
engine.pop();
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/image/scale-image.js
|
|
25
|
+
var scale_image_default = (img, factor, pixelart = true, engine = globalThis) => {
|
|
26
|
+
return engine.paint(img.width * factor, img.height * factor, (ctx) => {
|
|
27
|
+
engine.push();
|
|
28
|
+
ctx.imageSmoothingEnabled = !pixelart;
|
|
29
|
+
engine.scale(factor);
|
|
30
|
+
engine.image(0, 0, img);
|
|
31
|
+
engine.pop();
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/image/_web.js
|
|
36
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, {
|
|
37
|
+
tint: tint_default,
|
|
38
|
+
scaleImage: scale_image_default
|
|
39
|
+
});
|
|
40
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var n=(t,a,o=1,e=globalThis)=>e.paint(t.width,t.height,l=>{e.push(),e.alpha(o),e.rectfill(0,0,t.width,t.height,a),l.globalCompositeOperation="destination-atop",e.alpha(1),e.image(0,0,t),e.pop()});var i=(t,a,o=!0,e=globalThis)=>e.paint(t.width*a,t.height*a,l=>{e.push(),l.imageSmoothingEnabled=!o,e.scale(a),e.image(0,0,t),e.pop()});globalThis.utils=Object.assign(globalThis.utils||{},{tint:n,scaleImage:i});})();
|
package/dist/noise.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var D=Object.defineProperty;var H=(s,e)=>{for(var t in e)D(s,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let s in globalThis.utils)s!=="global"&&(globalThis[s]=globalThis.utils[s])};var b={};H(b,{Noise:()=>E});var I=4,_=1<<I,v=8,S=1<<v,a=4095,T=s=>.5*(1-Math.cos(s*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,n=0){e<0&&(e=-e),t<0&&(t=-t),n<0&&(n=-n);let c=Math.floor(e),f=Math.floor(t),u=Math.floor(n),p=e-c,h=t-f,d=n-u,r,m,y=0,x=.5,l,o,g;for(let w=0;w<this._po;w++){let i=c+(f<<I)+(u<<v);r=T(p),m=T(h),l=this._p[i&a],l+=r*(this._p[i+1&a]-l),o=this._p[i+_&a],o+=r*(this._p[i+_+1&a]-o),l+=m*(o-l),i+=S,o=this._p[i&a],o+=r*(this._p[i+1&a]-o),g=this._p[i+_&a],g+=r*(this._p[i+_+1&a]-g),o+=m*(g-o),l+=T(d)*(o-l),y+=l*x,x*=this._pf,c<<=1,p*=2,f<<=1,h*=2,u<<=1,d*=2,p>=1&&(c++,p--),h>=1&&(f++,h--),d>=1&&(u++,d--)}return y}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 n=0;n<a+1;n++)this._p[n]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},b);})();
|
package/dist/tween.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var f=Object.defineProperty;var p=(t,e)=>{for(var s in e)f(t,s,{get:e[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var c={};p(c,{BACK_IN:()=>E,BACK_IN_OUT:()=>m,BACK_OUT:()=>x,BOUNCE_IN:()=>h,BOUNCE_IN_OUT:()=>y,BOUNCE_OUT:()=>l,EASE_IN:()=>d,EASE_IN_OUT:()=>T,EASE_OUT:()=>g,ELASTIC_IN:()=>b,ELASTIC_IN_OUT:()=>I,ELASTIC_OUT:()=>w,LINEAR:()=>u,tween:()=>_});var n=Math.PI/2,_=(t,e,s,i=1,r=u)=>new a(t,e,s,i,r),u=t=>t,d=t=>t*t,g=t=>-t*(t-2),T=t=>t<.5?2*t*t:-2*t*t+4*t-1,E=t=>t*t*t-t*Math.sin(t*Math.PI),x=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},m=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},b=t=>Math.sin(13*n*t)*Math.pow(2,10*(t-1)),w=t=>Math.sin(-13*n*(t+1))*Math.pow(2,-10*t)+1,I=t=>{if(t<.5){let i=Math.sin(13*n*(2*t)),r=Math.pow(2,10*(2*t-1));return .5*i*r}let e=Math.sin(-13*n*(2*t-1+1)),s=Math.pow(2,-10*(2*t-1));return .5*(e*s+2)},h=t=>1-l(1-t),l=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,y=t=>t<.5?.5*h(t*2):.5*l(t*2-1)+.5,a=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(e,s,i,r,o){this._o=e,this._p=s,this._x=i,this._d=r,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,i=this._rel?s+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",r=>{if(this._t<=this._w){this._t+=r;return}let o=this._t-this._w;this._o[this._p]=this._lc.lerp(s,i,this._e(o/this._d)),this._t+=r,o>=this._d&&(this._o[this._p]=i,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}};globalThis.utils=Object.assign(globalThis.utils||{},c);})();
|
package/dist/vector.js
CHANGED
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
/** @type {number} */
|
|
56
56
|
y;
|
|
57
57
|
/**
|
|
58
|
-
* @param {number} x
|
|
59
|
-
* @param {number} y
|
|
58
|
+
* @param {number} [x=0]
|
|
59
|
+
* @param {number} [y]
|
|
60
60
|
*/
|
|
61
61
|
constructor(x = 0, y = x) {
|
|
62
62
|
this.x = x;
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
if (v.y > max.y) v.y = max.y;
|
|
208
208
|
return v;
|
|
209
209
|
};
|
|
210
|
-
var vecMove = (
|
|
210
|
+
var vecMove = (from, to, delta = 1) => vecAdd(from, to.x * delta, to.y * delta);
|
|
211
211
|
var vecIsZero = (v) => vecEq(v, ZERO);
|
|
212
212
|
var ZERO = /* @__PURE__ */ vec(0, 0);
|
|
213
213
|
var ONE = /* @__PURE__ */ vec(1, 1);
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "litecanvas"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Increases or decreases a image size.
|
|
5
|
+
*
|
|
6
|
+
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} img
|
|
7
|
+
* @param {number} factor
|
|
8
|
+
* @param {LitecanvasInstance} [engine]
|
|
9
|
+
*/
|
|
10
|
+
export default (img, factor, pixelart = true, engine = globalThis) => {
|
|
11
|
+
return engine.paint(img.width * factor, img.height * factor, (ctx) => {
|
|
12
|
+
engine.push()
|
|
13
|
+
ctx.imageSmoothingEnabled = !pixelart
|
|
14
|
+
engine.scale(factor)
|
|
15
|
+
engine.image(0, 0, img)
|
|
16
|
+
engine.pop()
|
|
17
|
+
})
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "litecanvas"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tint a image with a color and optional opacity.
|
|
5
|
+
*
|
|
6
|
+
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} img
|
|
7
|
+
* @param {number} color
|
|
8
|
+
* @param {number} [opacity=1]
|
|
9
|
+
* @param {LitecanvasInstance} [engine]
|
|
10
|
+
*/
|
|
11
|
+
export default (img, color, opacity = 1, engine = globalThis) => {
|
|
12
|
+
return engine.paint(img.width, img.height, (ctx) => {
|
|
13
|
+
engine.push()
|
|
14
|
+
engine.alpha(opacity)
|
|
15
|
+
engine.rectfill(0, 0, img.width, img.height, color)
|
|
16
|
+
ctx.globalCompositeOperation = "destination-atop"
|
|
17
|
+
engine.alpha(1)
|
|
18
|
+
engine.image(0, 0, img)
|
|
19
|
+
engine.pop()
|
|
20
|
+
})
|
|
21
|
+
}
|
package/src/index.js
CHANGED
package/src/math/advance.js
CHANGED
|
@@ -6,8 +6,8 @@ import { Vector } from "../vector"
|
|
|
6
6
|
*
|
|
7
7
|
* @param {Vector} position
|
|
8
8
|
* @param {Vector} velocity
|
|
9
|
-
* @param {Vector?} acceleration
|
|
10
|
-
* @param {number?} deltaTime
|
|
9
|
+
* @param {Vector?} [acceleration]
|
|
10
|
+
* @param {number?} [deltaTime]
|
|
11
11
|
*/
|
|
12
12
|
export default advance = (position, velocity, acceleration, deltaTime = 1) => {
|
|
13
13
|
if (acceleration) {
|
package/src/vector/index.js
CHANGED
|
@@ -10,8 +10,8 @@ export class Vector {
|
|
|
10
10
|
y
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @param {number} x
|
|
14
|
-
* @param {number} y
|
|
13
|
+
* @param {number} [x=0]
|
|
14
|
+
* @param {number} [y]
|
|
15
15
|
*/
|
|
16
16
|
constructor(x = 0, y = x) {
|
|
17
17
|
this.x = x
|
|
@@ -417,13 +417,13 @@ export const vecClamp = (v, min, max) => {
|
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
/**
|
|
420
|
-
* @param {Vector}
|
|
420
|
+
* @param {Vector} from
|
|
421
421
|
* @param {Vector} to
|
|
422
|
-
* @param {number} delta
|
|
422
|
+
* @param {number} [delta=1]
|
|
423
423
|
* @returns {Vector}
|
|
424
424
|
*/
|
|
425
|
-
export const vecMove = (
|
|
426
|
-
vecAdd(
|
|
425
|
+
export const vecMove = (from, to, delta = 1) =>
|
|
426
|
+
vecAdd(from, to.x * delta, to.y * delta)
|
|
427
427
|
|
|
428
428
|
export const vecIsZero = (v) => vecEq(v, ZERO)
|
|
429
429
|
|