@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/noise.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var se=Object.defineProperty;var le=(f,s)=>{for(var h in s)se(f,h,{get:s[h],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let f in globalThis.utils)f!=="global"&&(globalThis[f]=globalThis.utils[f])};var te={};le(te,{Noise:()=>ee});var Q=new AudioContext,oe=(f=1,s=.05,h=220,_=0,H=0,M=.1,g=0,U=1,R=0,W=0,r=0,C=0,S=0,B=0,T=0,i=0,y=0,O=1,E=0,j=0,F=0)=>{let x=Math,v=2*x.PI,b=44100,Z=R*=500*v/b/b,G=h*=(1-s+2*s*x.random(s=[]))*v/b,L=0,P=0,I=0,n=1,q=0,V=0,A=0,w=F<0?-1:1,k=v*w*F*2/b,$=x.cos(k),e=x.sin,t=e(k)/4,o=1+t,a=-2*$/o,u=(1-t)/o,d=(1+w*$)/2/o,D=-(w+$)/o,X=d,l=0,p=0,c=0,m=0;for(_=b*_+9,E*=b,H*=b,M*=b,y*=b,W*=500*v/b**3,T*=v/b,r*=v/b,C*=b,S=b*S|0,f*=.3*(globalThis.zzfxV||1),w=_+E+H+M+y|0;I<w;s[I++]=A*f)++V%(100*i|0)||(A=g?1<g?2<g?3<g?e(L*L):x.max(x.min(x.tan(L),1),-1):1-(2*L/v%2+2)%2:1-4*x.abs(x.round(L/v)-L/v):e(L),A=(S?1-j+j*e(v*I/S):1)*(A<0?-1:1)*x.abs(A)**U*(I<_?I/_:I<_+E?1-(I-_)/E*(1-O):I<_+E+H?O:I<w-y?(w-I-y)/M*O:0),A=y?A/2+(y>I?0:(I<w-y?1:(w-I)/y)*s[I-y|0]/2/f):A,F&&(A=m=X*l+D*(l=p)+d*(p=A)-u*c-a*(c=m))),k=(h+=R+=W)*x.cos(T*P++),L+=k+k*B*e(I**5),n&&++n>C&&(h+=r,G+=r,n=0),!S||++q%S||(h=G,R=Z,n=n||1);f=Q.createBuffer(1,w,b),f.getChannelData(0).set(s),h=Q.createBufferSource(),h.buffer=f,h.connect(Q.destination),h.start()};var J=["#111","#6a7799","#aec2c2","#FFF1E8","#e83b3b","#fabc20","#155fd9","#3cbcfc","#327345","#63c64d","#6c2c1f","#ac7c00"];globalThis.litecanvas=ne;function ne(f={}){let s=globalThis,h=Math.PI,_=h*2,H=requestAnimationFrame,M=[],g=(e,t,o)=>{e.addEventListener(t,o,!1),M.push(()=>e.removeEventListener(t,o,!1))};f=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},f);let R=!1,W=[],r=f.canvas||document.createElement("canvas"),C=f.fullscreen,S=f.autoscale,B=f.animate,T=1,i,y=1,O,E,j,F=0,x=!0,v="sans-serif",b="",Z=32,G=Date.now(),L=f.global,P={init:null,update:null,draw:null,resized:null,tap:null,untap:null,tapping:null,tapped:null},I={settings:Object.assign({},f),colors:J},n={WIDTH:f.width,HEIGHT:f.height||f.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:h,TWO_PI:_,HALF_PI:h*.5,lerp:(e,t,o)=>e+o*(t-e),deg2rad:e=>h/180*e,rad2deg:e=>180/h*e,clamp:(e,t,o)=>e<t?t:e>o?o:e,wrap:(e,t,o)=>e-(o-t)*Math.floor((e-t)/(o-t)),map(e,t,o,a,u,d){let D=(e-t)/(o-t)*(u-a)+a;return d?n.clamp(D,a,u):D},norm:(e,t,o)=>n.map(e,t,o,0,1),rand:(e=0,t=1)=>(G=(1664525*G+1013904223)%4294967296,G/4294967296*(t-e)+e),randi:(e=0,t=1)=>Math.floor(n.rand(e,t+1)),seed:e=>e==null?G:G=~~e,cls(e){e==null?i.clearRect(0,0,n.WIDTH,n.HEIGHT):n.rectfill(0,0,n.WIDTH,n.HEIGHT,e)},rect(e,t,o,a,u=0,d=null){i.beginPath(),i[d?"roundRect":"rect"](~~e,~~t,o,a,d),n.stroke(u)},rectfill(e,t,o,a,u=0,d=null){i.beginPath(),i[d?"roundRect":"rect"](~~e,~~t,o,a,d),n.fill(u)},circ(e,t,o,a){i.beginPath(),i.arc(~~e,~~t,o,0,_),n.stroke(a)},circfill(e,t,o,a){i.beginPath(),i.arc(~~e,~~t,o,0,_),n.fill(a)},line(e,t,o,a,u){i.beginPath(),i.moveTo(~~e,~~t),i.lineTo(~~o,~~a),n.stroke(u)},linewidth(e){i.lineWidth=e},linedash(e,t=0){i.setLineDash(e),i.lineDashOffset=t},text(e,t,o,a=3){i.font=`${b} ${Z}px ${v}`,i.fillStyle=n.getcolor(a),i.fillText(o,~~e,~~t)},textfont(e){v=e},textsize(e){Z=e},textstyle(e){b=e||""},textalign(e,t){e&&(i.textAlign=e),t&&(i.textBaseline=t)},textmetrics(e,t=Z){i.font=`${b} ${t}px ${v}`;let o=i.measureText(e);return o.height=o.actualBoundingBoxAscent+o.actualBoundingBoxDescent,o},image(e,t,o){i.drawImage(o,~~e,~~t)},paint(e,t,o,a={}){let u=a.canvas||new OffscreenCanvas(1,1),d=a.scale||1,D=i;if(u.width=e*d,u.height=t*d,i=u.getContext("2d"),i.scale(d,d),o.push){let X=0,l=0;i.imageSmoothingEnabled=!1;for(let p of o){for(let c of p)c!==" "&&c!=="."&&n.rectfill(X,l,1,1,parseInt(c,16)),X++;l++,X=0}}else o(i);return i=D,u},ctx(e){return e&&(i=e),i},push:()=>i.save(),pop:()=>i.restore(),translate:(e,t)=>i.translate(~~e,~~t),scale:(e,t)=>i.scale(e,t||e),rotate:e=>i.rotate(e),transform:(e,t,o,a,u,d,D=!0)=>i[D?"setTransform":"transform"](e,t,o,a,u,d),alpha(e){i.globalAlpha=n.clamp(e,0,1)},path:e=>new Path2D(e),fill(e,t){i.fillStyle=n.getcolor(e),t?i.fill(t):i.fill()},stroke(e,t){i.strokeStyle=n.getcolor(e),t?i.stroke(t):i.stroke()},clip(e){i.clip(e)},sfx(e,t=0,o=1){return s.zzfxV<=0||navigator.userActivation&&!navigator.userActivation.hasBeenActive?!1:(e=e||n.DEFAULT_SFX,(t>0||o!==1)&&(e=e.slice(),e[0]=o*(e[0]||1),e[10]=~~e[10]+t),oe.apply(0,e),e)},volume(e){s.zzfxV=+e},colrect:(e,t,o,a,u,d,D,X)=>e<u+D&&e+o>u&&t<d+X&&t+a>d,colcirc:(e,t,o,a,u,d)=>(a-e)**2+(u-t)**2<=(o+d)**2,use(e,t={}){R?$(e,t):W.push([e,t])},listen(e,t){return P[e]=P[e]||new Set,P[e].add(t),()=>P[e].delete(t)},emit(e,t,o,a,u){k("before:"+e,t,o,a,u),k(e,t,o,a,u),k("after:"+e,t,o,a,u)},getcolor:e=>J[~~e%J.length],setvar(e,t){n[e]=t,L&&(s[e]=t)},resize(e,t){n.setvar("WIDTH",r.width=e),n.setvar("HEIGHT",r.height=t||e),w()},timescale(e){y=e},setfps(e){E=1/e,j=E*1e3,F=0},quit(){n.emit("quit");for(let e of M)e();if(x=P=!1,L){for(let e in n)delete s[e];delete s.__litecanvas}}};for(let e of["sin","cos","atan2","hypot","tan","abs","ceil","round","floor","trunc","min","max","pow","sqrt","sign","exp"])n[e]=Math[e];function q(){R=!0;let e=f.loop?f.loop:s;for(let t in P)e[t]&&n.listen(t,e[t]);for(let[t,o]of W)$(t,o);if((C||S)&&g(s,"resize",w),w(),f.tapEvents){let t=(l,p)=>[(l-r.offsetLeft)/T,(p-r.offsetTop)/T],o=new Map,a=(l,p,c)=>{let m={x:p,y:c,startX:p,startY:c,ts:performance.now()};return o.set(l,m),m},u=(l,p,c)=>{let m=o.get(l)||a(l);m.x=p,m.y=c},d=l=>l&&performance.now()-l.ts<=200,D=!1;g(r,"mousedown",l=>{l.preventDefault();let[p,c]=t(l.pageX,l.pageY);n.emit("tap",p,c,0),a(0,p,c),D=!0}),g(r,"mousemove",l=>{l.preventDefault();let[p,c]=t(l.pageX,l.pageY);n.setvar("MOUSEX",p),n.setvar("MOUSEY",c),D&&(n.emit("tapping",p,c,0),u(0,p,c))}),g(r,"mouseup",l=>{l.preventDefault();let p=o.get(0),[c,m]=t(l.pageX,l.pageY);d(p)&&n.emit("tapped",p.startX,p.startY,0),n.emit("untap",c,m,0),o.delete(0),D=!1}),g(r,"touchstart",l=>{l.preventDefault();let p=l.changedTouches;for(let c of p){let[m,N]=t(c.pageX,c.pageY);n.emit("tap",m,N,c.identifier+1),a(c.identifier+1,m,N)}}),g(r,"touchmove",l=>{l.preventDefault();let p=l.changedTouches;for(let c of p){let[m,N]=t(c.pageX,c.pageY);n.emit("tapping",m,N,c.identifier+1),u(c.identifier+1,m,N)}});let X=l=>{l.preventDefault();let p=[];if(l.targetTouches.length>0)for(let c of l.targetTouches)p.push(c.identifier+1);for(let[c,m]of o)p.includes(c)||(d(m)&&n.emit("tapped",m.startX,m.startY,c),n.emit("untap",m.x,m.y,c),o.delete(c))};g(r,"touchend",X),g(r,"touchcancel",X),g(s,"blur",()=>{D=!1;for(let[l,p]of o)n.emit("untap",p.x,p.y,l),o.delete(l)})}if(f.keyboardEvents){let t=new Set,o=a=>a==="any"?t.size>0:t.has(a.toLowerCase());n.setvar("iskeydown",o),g(s,"keydown",a=>{t.add(a.key.toLowerCase())}),g(s,"keyup",a=>{t.delete(a.key.toLowerCase())}),g(s,"blur",()=>t.clear())}f.pauseOnBlur&&(g(s,"blur",()=>{x=!1}),g(s,"focus",()=>{x=!0,H(V)})),n.setfps(f.fps),n.emit("init",n),O=performance.now(),H(V)}function V(e){let t=!B,o=e-O;for(F+=o>100?j:o,O=e;F>=j;)n.emit("update",E*y),n.setvar("ELAPSED",n.ELAPSED+E*y),F-=j,t=!0;t&&(n.textalign("start","top"),n.emit("draw")),x&&B&&H(V)}function A(){r=typeof r=="string"?document.querySelector(r):r,n.setvar("CANVAS",r),i=r.getContext("2d"),g(r,"click",()=>s.focus()),n.WIDTH>0&&(C=!1),r.style="",r.width=n.WIDTH,r.height=n.HEIGHT||n.WIDTH,r.parentNode||document.body.appendChild(r)}function w(){let e=s.innerWidth,t=s.innerHeight,o=r.style;o.display="block",C?(o.position="absolute",o.inset=0,n.setvar("WIDTH",r.width=e),n.setvar("HEIGHT",r.height=t)):S&&(o.margin="auto",T=Math.min(e/n.WIDTH,t/n.HEIGHT),T=(f.pixelart?~~T:T)||1,o.width=n.WIDTH*T+"px",o.height=n.HEIGHT*T+"px"),n.setvar("CENTERX",n.WIDTH/2),n.setvar("CENTERY",n.HEIGHT/2),(!f.antialias||f.pixelart)&&(i.imageSmoothingEnabled=!1,r.style.imageRendering="pixelated"),n.emit("resized",T),B||H(V)}function k(e,t,o,a,u){if(P[e])for(let d of P[e])d(t,o,a,u)}function $(e,t){let o=e(n,I,t);if(typeof o=="object")for(let a of Object.keys(o))n.setvar(a,o[a])}if(L){if(s.__litecanvas)throw"global litecanvas already instantiated";Object.assign(s,n),s.__litecanvas=n}return A(),document.readyState==="loading"?g(s,"DOMContentLoaded",()=>H(q)):H(q),n}var ie=4,K=1<<ie,ae=8,re=1<<ae,Y=4095,z=f=>.5*(1-Math.cos(f*Math.PI)),ee=class{_p=[];_po=4;_pf=.5;_e=null;constructor(s){this._e=s||globalThis,this.noiseSeed()}noise(s,h=0,_=0){s<0&&(s=-s),h<0&&(h=-h),_<0&&(_=-_);let H=Math.floor(s),M=Math.floor(h),g=Math.floor(_),U=s-H,R=h-M,W=_-g,r,C,S=0,B=.5,T,i,y;for(let O=0;O<this._po;O++){let E=H+(M<<ie)+(g<<ae);r=z(U),C=z(R),T=this._p[E&Y],T+=r*(this._p[E+1&Y]-T),i=this._p[E+K&Y],i+=r*(this._p[E+K+1&Y]-i),T+=C*(i-T),E+=re,i=this._p[E&Y],i+=r*(this._p[E+1&Y]-i),y=this._p[E+K&Y],y+=r*(this._p[E+K+1&Y]-y),i+=C*(y-i),T+=z(W)*(i-T),S+=T*B,B*=this._pf,H<<=1,U*=2,M<<=1,R*=2,g<<=1,W*=2,U>=1&&(H++,U--),R>=1&&(M++,R--),W>=1&&(g++,W--)}return S}noiseDetail(s,h){s>0&&(this._po=s),h>0&&(this._pf=h)}noiseSeed(s=null){s!=null&&this._e.seed(s);let h=this._e.rand||Math.random;for(let _=0;_<Y+1;_++)this._p[_]=h()}};globalThis.utils=Object.assign(globalThis.utils||{},te);})();
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);})();