@litecanvas/utils 0.24.2 → 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 +12 -978
- package/dist/actor.min.js +1 -1
- package/dist/all.js +38 -978
- package/dist/all.min.js +2 -2
- package/dist/image.js +40 -0
- package/dist/image.min.js +1 -0
- package/dist/noise.js +0 -968
- package/dist/noise.min.js +1 -1
- package/dist/tween.js +0 -968
- package/dist/tween.min.js +1 -1
- 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/dist/all.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`)}},ht=class e extends st{constructor(t,s,o=Uint8Array){super(t,s,null),this._c=new o(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,o,c)=>{t.set(s,o,c)}),t}};function wt(e,t,s){return e<t?t:e>s?s:e}var at=Math.sqrt,Et=Math.cos,Mt=Math.sin,Vt=2*Math.PI,Q=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},$=e=>e instanceof Q,H=(e=0,t=e)=>($(e)&&(t=e.y,e=e.x),new Q(e,t)),ct=(e,t,s=t)=>$(t)?ct(e,t.x,t.y):e.x===t&&e.y===s,It=(e,t,s=t)=>($(t)?It(e,t.x,t.y):(e.x=t,e.y=s),e),lt=(e,t,s=t)=>$(t)?lt(e,t.x,t.y):(e.x+=t,e.y+=s,e),ut=(e,t,s=t)=>$(t)?ut(e,t.x,t.y):(e.x-=t,e.y-=s,e),v=(e,t,s=t)=>$(t)?v(e,t.x,t.y):(e.x*=t,e.y*=s,e),it=(e,t,s=t)=>$(t)?it(e,t.x,t.y):(e.x/=t||1,e.y/=s||1,e),jt=(e,t)=>{let s=Et(t),o=Mt(t);return e.x=s*e.x-o*e.y,e.y=o*e.x+s*e.y,e},$t=(e,t)=>{let s=ft(H(t));return ut(e,v(s,2*At(e,s)))},qt=(e,t)=>(ft(e),v(e,t),e),bt=e=>at(e.x*e.x+e.y*e.y),Ht=e=>e.x*e.x+e.y*e.y,ft=e=>{let t=bt(e);return t>0&&it(e,t),e},Zt=(e,t=1)=>{let s=Ht(e);return s>t*t&&(it(e,at(s)),v(e,t)),e},zt=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return at(s*s+o*o)},Kt=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return s*s+o*o},Jt=e=>Math.atan2(e.y,e.x),Qt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),At=(e,t)=>e.x*t.x+e.y*t.y,vt=(e,t)=>e.x*t.y-e.y*t.x,te=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),ee=(e=1,t=e,s=globalThis.rand||Math.random)=>{let o=s()*Vt,c=s()*(t-e)+e;return H(Et(o)*c,Mt(o)*c)},se=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),ie=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),re=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),oe=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),ne=(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),he=(e,t,s=1)=>lt(e,t.x*s,t.y*s),ae=e=>ct(e,Ot),Ot=H(0,0),ce=H(1,1),le=H(0,-1),ue=H(1,0),fe=H(0,1),pe=H(-1,0);var pt=new AudioContext,St=(e=1,t=.05,s=220,o=0,c=0,u=.1,_=0,O=1,E=0,P=0,f=0,D=0,I=0,R=0,m=0,a=0,b=0,N=1,w=0,j=0,G=0)=>{let S=Math,L=2*S.PI,M=44100,z=E*=500*L/M/M,V=s*=(1-t+2*t*S.random(t=[]))*L/M,X=0,W=0,A=0,h=1,tt=0,q=0,Y=0,C=G<0?-1:1,U=L*C*G*2/M,Z=S.cos(U),i=S.sin,r=i(U)/4,n=1+r,l=-2*Z/n,x=(1-r)/n,y=(1+C*Z)/2/n,k=-(C+Z)/n,B=y,p=0,g=0,d=0,T=0;for(o=M*o+9,w*=M,c*=M,u*=M,b*=M,P*=500*L/M**3,m*=L/M,f*=L/M,D*=M,I=M*I|0,e*=.3*(globalThis.zzfxV||1),C=o+w+c+u+b|0;A<C;t[A++]=Y*e)++q%(100*a|0)||(Y=_?1<_?2<_?3<_?i(X*X):S.max(S.min(S.tan(X),1),-1):1-(2*X/L%2+2)%2:1-4*S.abs(S.round(X/L)-X/L):i(X),Y=(I?1-j+j*i(L*A/I):1)*(Y<0?-1:1)*S.abs(Y)**O*(A<o?A/o:A<o+w?1-(A-o)/w*(1-N):A<o+w+c?N:A<C-b?(C-A-b)/u*N:0),Y=b?Y/2+(b>A?0:(A<C-b?1:(C-A)/b)*t[A-b|0]/2/e):Y,G&&(Y=T=B*p+k*(p=g)+y*(g=Y)-x*d-l*(d=T))),U=(s+=E+=P)*S.cos(m*W++),X+=U+U*R*i(A**5),h&&++h>D&&(s+=f,V+=f,h=0),!I||++tt%I||(s=V,E=z,h=h||1);e=pt.createBuffer(1,C,M),e.getChannelData(0).set(t),s=pt.createBufferSource(),s.buffer=e,s.connect(pt.destination),s.start()};var rt=["#111","#6a7799","#aec2c2","#FFF1E8","#e83b3b","#fabc20","#155fd9","#3cbcfc","#327345","#63c64d","#6c2c1f","#ac7c00"];globalThis.litecanvas=kt;function kt(e={}){let t=globalThis,s=Math.PI,o=s*2,c=requestAnimationFrame,u=[],_=(i,r,n)=>{i.addEventListener(r,n,!1),u.push(()=>i.removeEventListener(r,n,!1))};e=Object.assign({fps:60,fullscreen:!0,width:null,height:null,autoscale:!0,pixelart:!1,antialias:!1,canvas:null,global:!0,loop:null,pauseOnBlur:!0,tapEvents:!0,keyboardEvents:!0,animate:!0},e);let E=!1,P=[],f=e.canvas||document.createElement("canvas"),D=e.fullscreen,I=e.autoscale,R=e.animate,m=1,a,b=1,N,w,j,G=0,S=!0,L="sans-serif",M="",z=32,V=Date.now(),X=e.global,W={init:null,update:null,draw:null,resized:null,tap:null,untap:null,tapping:null,tapped:null},A={settings:Object.assign({},e),colors:rt},h={WIDTH:e.width,HEIGHT:e.height||e.width,CANVAS:null,ELAPSED:0,CENTERX:0,CENTERY:0,MOUSEX:-1,MOUSEY:-1,DEFAULT_SFX:[.5,,1675,,.06,.2,1,1.8,,,637,.06],PI:s,TWO_PI:o,HALF_PI:s*.5,lerp:(i,r,n)=>i+n*(r-i),deg2rad:i=>s/180*i,rad2deg:i=>180/s*i,clamp:(i,r,n)=>i<r?r:i>n?n:i,wrap:(i,r,n)=>i-(n-r)*Math.floor((i-r)/(n-r)),map(i,r,n,l,x,y){let k=(i-r)/(n-r)*(x-l)+l;return y?h.clamp(k,l,x):k},norm:(i,r,n)=>h.map(i,r,n,0,1),rand:(i=0,r=1)=>(V=(1664525*V+1013904223)%4294967296,V/4294967296*(r-i)+i),randi:(i=0,r=1)=>Math.floor(h.rand(i,r+1)),seed:i=>i==null?V:V=~~i,cls(i){i==null?a.clearRect(0,0,h.WIDTH,h.HEIGHT):h.rectfill(0,0,h.WIDTH,h.HEIGHT,i)},rect(i,r,n,l,x=0,y=null){a.beginPath(),a[y?"roundRect":"rect"](~~i,~~r,n,l,y),h.stroke(x)},rectfill(i,r,n,l,x=0,y=null){a.beginPath(),a[y?"roundRect":"rect"](~~i,~~r,n,l,y),h.fill(x)},circ(i,r,n,l){a.beginPath(),a.arc(~~i,~~r,n,0,o),h.stroke(l)},circfill(i,r,n,l){a.beginPath(),a.arc(~~i,~~r,n,0,o),h.fill(l)},line(i,r,n,l,x){a.beginPath(),a.moveTo(~~i,~~r),a.lineTo(~~n,~~l),h.stroke(x)},linewidth(i){a.lineWidth=i},linedash(i,r=0){a.setLineDash(i),a.lineDashOffset=r},text(i,r,n,l=3){a.font=`${M} ${z}px ${L}`,a.fillStyle=h.getcolor(l),a.fillText(n,~~i,~~r)},textfont(i){L=i},textsize(i){z=i},textstyle(i){M=i||""},textalign(i,r){i&&(a.textAlign=i),r&&(a.textBaseline=r)},textmetrics(i,r=z){a.font=`${M} ${r}px ${L}`;let n=a.measureText(i);return n.height=n.actualBoundingBoxAscent+n.actualBoundingBoxDescent,n},image(i,r,n){a.drawImage(n,~~i,~~r)},paint(i,r,n,l={}){let x=l.canvas||new OffscreenCanvas(1,1),y=l.scale||1,k=a;if(x.width=i*y,x.height=r*y,a=x.getContext("2d"),a.scale(y,y),n.push){let B=0,p=0;a.imageSmoothingEnabled=!1;for(let g of n){for(let d of g)d!==" "&&d!=="."&&h.rectfill(B,p,1,1,parseInt(d,16)),B++;p++,B=0}}else n(a);return a=k,x},ctx(i){return i&&(a=i),a},push:()=>a.save(),pop:()=>a.restore(),translate:(i,r)=>a.translate(~~i,~~r),scale:(i,r)=>a.scale(i,r||i),rotate:i=>a.rotate(i),transform:(i,r,n,l,x,y,k=!0)=>a[k?"setTransform":"transform"](i,r,n,l,x,y),alpha(i){a.globalAlpha=h.clamp(i,0,1)},path:i=>new Path2D(i),fill(i,r){a.fillStyle=h.getcolor(i),r?a.fill(r):a.fill()},stroke(i,r){a.strokeStyle=h.getcolor(i),r?a.stroke(r):a.stroke()},clip(i){a.clip(i)},sfx(i,r=0,n=1){return t.zzfxV<=0||navigator.userActivation&&!navigator.userActivation.hasBeenActive?!1:(i=i||h.DEFAULT_SFX,(r>0||n!==1)&&(i=i.slice(),i[0]=n*(i[0]||1),i[10]=~~i[10]+r),St.apply(0,i),i)},volume(i){t.zzfxV=+i},colrect:(i,r,n,l,x,y,k,B)=>i<x+k&&i+n>x&&r<y+B&&r+l>y,colcirc:(i,r,n,l,x,y)=>(l-i)**2+(x-r)**2<=(n+y)**2,use(i,r={}){E?Z(i,r):P.push([i,r])},listen(i,r){return W[i]=W[i]||new Set,W[i].add(r),()=>W[i].delete(r)},emit(i,r,n,l,x){U("before:"+i,r,n,l,x),U(i,r,n,l,x),U("after:"+i,r,n,l,x)},getcolor:i=>rt[~~i%rt.length],setvar(i,r){h[i]=r,X&&(t[i]=r)},resize(i,r){h.setvar("WIDTH",f.width=i),h.setvar("HEIGHT",f.height=r||i),C()},timescale(i){b=i},setfps(i){w=1/i,j=w*1e3,G=0},quit(){h.emit("quit");for(let i of u)i();if(S=W=!1,X){for(let i in h)delete t[i];delete t.__litecanvas}}};for(let i of["sin","cos","atan2","hypot","tan","abs","ceil","round","floor","trunc","min","max","pow","sqrt","sign","exp"])h[i]=Math[i];function tt(){E=!0;let i=e.loop?e.loop:t;for(let r in W)i[r]&&h.listen(r,i[r]);for(let[r,n]of P)Z(r,n);if((D||I)&&_(t,"resize",C),C(),e.tapEvents){let r=(p,g)=>[(p-f.offsetLeft)/m,(g-f.offsetTop)/m],n=new Map,l=(p,g,d)=>{let T={x:g,y:d,startX:g,startY:d,ts:performance.now()};return n.set(p,T),T},x=(p,g,d)=>{let T=n.get(p)||l(p);T.x=g,T.y=d},y=p=>p&&performance.now()-p.ts<=200,k=!1;_(f,"mousedown",p=>{p.preventDefault();let[g,d]=r(p.pageX,p.pageY);h.emit("tap",g,d,0),l(0,g,d),k=!0}),_(f,"mousemove",p=>{p.preventDefault();let[g,d]=r(p.pageX,p.pageY);h.setvar("MOUSEX",g),h.setvar("MOUSEY",d),k&&(h.emit("tapping",g,d,0),x(0,g,d))}),_(f,"mouseup",p=>{p.preventDefault();let g=n.get(0),[d,T]=r(p.pageX,p.pageY);y(g)&&h.emit("tapped",g.startX,g.startY,0),h.emit("untap",d,T,0),n.delete(0),k=!1}),_(f,"touchstart",p=>{p.preventDefault();let g=p.changedTouches;for(let d of g){let[T,K]=r(d.pageX,d.pageY);h.emit("tap",T,K,d.identifier+1),l(d.identifier+1,T,K)}}),_(f,"touchmove",p=>{p.preventDefault();let g=p.changedTouches;for(let d of g){let[T,K]=r(d.pageX,d.pageY);h.emit("tapping",T,K,d.identifier+1),x(d.identifier+1,T,K)}});let B=p=>{p.preventDefault();let g=[];if(p.targetTouches.length>0)for(let d of p.targetTouches)g.push(d.identifier+1);for(let[d,T]of n)g.includes(d)||(y(T)&&h.emit("tapped",T.startX,T.startY,d),h.emit("untap",T.x,T.y,d),n.delete(d))};_(f,"touchend",B),_(f,"touchcancel",B),_(t,"blur",()=>{k=!1;for(let[p,g]of n)h.emit("untap",g.x,g.y,p),n.delete(p)})}if(e.keyboardEvents){let r=new Set,n=l=>l==="any"?r.size>0:r.has(l.toLowerCase());h.setvar("iskeydown",n),_(t,"keydown",l=>{r.add(l.key.toLowerCase())}),_(t,"keyup",l=>{r.delete(l.key.toLowerCase())}),_(t,"blur",()=>r.clear())}e.pauseOnBlur&&(_(t,"blur",()=>{S=!1}),_(t,"focus",()=>{S=!0,c(q)})),h.setfps(e.fps),h.emit("init",h),N=performance.now(),c(q)}function q(i){let r=!R,n=i-N;for(G+=n>100?j:n,N=i;G>=j;)h.emit("update",w*b),h.setvar("ELAPSED",h.ELAPSED+w*b),G-=j,r=!0;r&&(h.textalign("start","top"),h.emit("draw")),S&&R&&c(q)}function Y(){f=typeof f=="string"?document.querySelector(f):f,h.setvar("CANVAS",f),a=f.getContext("2d"),_(f,"click",()=>t.focus()),h.WIDTH>0&&(D=!1),f.style="",f.width=h.WIDTH,f.height=h.HEIGHT||h.WIDTH,f.parentNode||document.body.appendChild(f)}function C(){let i=t.innerWidth,r=t.innerHeight,n=f.style;n.display="block",D?(n.position="absolute",n.inset=0,h.setvar("WIDTH",f.width=i),h.setvar("HEIGHT",f.height=r)):I&&(n.margin="auto",m=Math.min(i/h.WIDTH,r/h.HEIGHT),m=(e.pixelart?~~m:m)||1,n.width=h.WIDTH*m+"px",n.height=h.HEIGHT*m+"px"),h.setvar("CENTERX",h.WIDTH/2),h.setvar("CENTERY",h.HEIGHT/2),(!e.antialias||e.pixelart)&&(a.imageSmoothingEnabled=!1,f.style.imageRendering="pixelated"),h.emit("resized",m),R||c(q)}function U(i,r,n,l,x){if(W[i])for(let y of W[i])y(r,n,l,x)}function Z(i,r){let n=i(h,A,r);if(typeof n=="object")for(let l of Object.keys(n))h.setvar(l,n[l])}if(X){if(t.__litecanvas)throw"global litecanvas already instantiated";Object.assign(t,h),t.__litecanvas=h}return Y(),document.readyState==="loading"?_(t,"DOMContentLoaded",()=>c(tt)):c(tt),h}var _e=H(.5,.5),Dt=H(0,0),de=H(1,0),xe=H(0,1),ge=H(1,1),_t=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,s,o=Dt){this.sprite=t,this.pos=s||H(0),this._o=H(o),this._s=H(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),o=this.sprite.height*(t?this._s.y:1),c=this.pos.x-s*this.anchor.x,u=this.pos.y-o*this.anchor.y;return[c,u,s,o]}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 o=this.anchor,c=-this.sprite.width*(this.flipX?1-o.x:o.x),u=-this.sprite.height*(this.flipY?1-o.y:o.y);s&&t.alpha(this.opacity),t.image(c,u,this.sprite)}};var Lt=(e,t)=>Math.abs(t-e)||0;var Ct=(e,t,s,o=Math.sin)=>e+(o(s)+1)/2*(t-e);var Pt=e=>e%1||0;var Rt=e=>Array.from(Array(e).keys());var Xt=advance=(e,t,s,o=1)=>{s&&(t.x+=s.x*o,t.y+=s.y*o),e.x+=t.x*o,e.y+=t.y*o};var Yt=(e,t)=>(t+e%t)%t;var ot=Math.PI/2,ye=(e,t,s,o=1,c=Nt)=>new dt(e,t,s,o,c),Nt=e=>e,me=e=>e*e,Te=e=>-e*(e-2),we=e=>e<.5?2*e*e:-2*e*e+4*e-1,Ee=e=>e*e*e-e*Math.sin(e*Math.PI),Me=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},Ie=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},be=e=>Math.sin(13*ot*e)*Math.pow(2,10*(e-1)),He=e=>Math.sin(-13*ot*(e+1))*Math.pow(2,-10*e)+1,Ae=e=>{if(e<.5){let o=Math.sin(13*ot*(2*e)),c=Math.pow(2,10*(2*e-1));return .5*o*c}let t=Math.sin(-13*ot*(2*e-1+1)),s=Math.pow(2,-10*(2*e-1));return .5*(t*s+2)},Wt=e=>1-xt(1-e),xt=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,Oe=e=>e<.5?.5*Wt(e*2):.5*xt(e*2-1)+.5,dt=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,s,o,c,u){this._o=t,this._p=s,this._x=o,this._d=c,this._e=u,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,o=this._rel?s+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",c=>{if(this._t<=this._w){this._t+=c;return}let u=this._t-this._w;this._o[this._p]=this._lc.lerp(s,o,this._e(u/this._d)),this._t+=c,u>=this._d&&(this._o[this._p]=o,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 Bt=4,nt=1<<Bt,Ut=8,Se=1<<Ut,F=4095,gt=e=>.5*(1-Math.cos(e*Math.PI)),yt=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,s=0,o=0){t<0&&(t=-t),s<0&&(s=-s),o<0&&(o=-o);let c=Math.floor(t),u=Math.floor(s),_=Math.floor(o),O=t-c,E=s-u,P=o-_,f,D,I=0,R=.5,m,a,b;for(let N=0;N<this._po;N++){let w=c+(u<<Bt)+(_<<Ut);f=gt(O),D=gt(E),m=this._p[w&F],m+=f*(this._p[w+1&F]-m),a=this._p[w+nt&F],a+=f*(this._p[w+nt+1&F]-a),m+=D*(a-m),w+=Se,a=this._p[w&F],a+=f*(this._p[w+1&F]-a),b=this._p[w+nt&F],b+=f*(this._p[w+nt+1&F]-b),a+=D*(b-a),m+=gt(P)*(a-m),I+=m*R,R*=this._pf,c<<=1,O*=2,u<<=1,E*=2,_<<=1,P*=2,O>=1&&(c++,O--),E>=1&&(u++,E--),P>=1&&(_++,P--)}return I}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 o=0;o<F+1;o++)this._p[o]=s()}};globalThis.utils=Object.assign(globalThis.utils||{},mt);})();
|
|
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});})();
|