litecanvas 0.55.0 → 0.56.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/dist.js +1 -1
- package/dist/dist.min.js +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/types/index.d.ts +4 -4
- package/types/types.d.ts +2 -2
package/dist/dist.js
CHANGED
package/dist/dist.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e=/* @__PURE__ */new AudioContext;globalThis.zzfxV=1;var t=(t=1,a=.05,l=220,n=0,i=0,r=.1,o=0,s=1,c=0,f=0,p=0,u=0,g=0,d=0,h=0,m=0,v=0,T=1,x=0,b=0,E=0)=>{let H=Math,D=2*H.PI,y=c*=500*D/44100/44100,w=l*=(1-a+2*a*H.random(a=[]))*D/44100,I=0,A=0,P=0,S=1,C=0,z=0,W=0,X=E<0?-1:1,O=D*X*E*2/44100,_=H.cos(O),B=H.sin,F=B(O)/4,L=1+F,Y=-2*_/L,k=(1-F)/L,G=(1+X*_)/2/L,M=-(X+_)/L,R=0,N=0,j=0,V=0;for(n=44100*n+9,x*=44100,i*=44100,r*=44100,v*=44100,f*=500*D/85766121e6,h*=D/44100,p*=D/44100,u*=44100,g=44100*g|0,t*=.3*globalThis.zzfxV,X=n+x+i+r+v|0;P<X;a[P++]=W*t)++z%(100*m|0)||(W=o?1<o?2<o?3<o?B(I*I):H.max(H.min(H.tan(I),1),-1):1-(2*I/D%2+2)%2:1-4*H.abs(H.round(I/D)-I/D):B(I),W=(g?1-b+b*B(D*P/g):1)*(W<0?-1:1)*H.abs(W)**s*(P<n?P/n:P<n+x?1-(P-n)/x*(1-T):P<n+x+i?T:P<X-v?(X-P-v)/r*T:0),W=v?W/2+(v>P?0:(P<X-v?1:(X-P)/v)*a[P-v|0]/2/t):W,E&&(W=V=G*R+M*(R=N)+G*(N=W)-k*j-Y*(j=V))),I+=(O=(l+=c+=f)*H.cos(h*A++))+O*d*B(P**5),S&&++S>u&&(l+=p,w+=p,S=0),!g||++C%g||(l=w,c=y,S=S||1);(t=e.createBuffer(1,X,44100)).getChannelData(0).set(a),(l=e.createBufferSource()).buffer=t,l.connect(e.destination),l.start()},a=["#18161c","#6a7799","#aec2c2","#f3eade","#f04f78","#fcf660","#2f328f","#4b80ca","#327345","#63c64d","#703075","#a56243"];globalThis.litecanvas=function(e={}){let l=globalThis,n=Math.PI,i=2*n,r=(e,t,a)=>e.addEventListener(t,a);e=Object.assign({fps:60,fullscreen:!0,width:null,height:null,autoscale:!0,pixelart:!1,antialias:!
|
|
1
|
+
(()=>{var e=/* @__PURE__ */new AudioContext;globalThis.zzfxV=1;var t=(t=1,a=.05,l=220,n=0,i=0,r=.1,o=0,s=1,c=0,f=0,p=0,u=0,g=0,d=0,h=0,m=0,v=0,T=1,x=0,b=0,E=0)=>{let H=Math,D=2*H.PI,y=c*=500*D/44100/44100,w=l*=(1-a+2*a*H.random(a=[]))*D/44100,I=0,A=0,P=0,S=1,C=0,z=0,W=0,X=E<0?-1:1,O=D*X*E*2/44100,_=H.cos(O),B=H.sin,F=B(O)/4,L=1+F,Y=-2*_/L,k=(1-F)/L,G=(1+X*_)/2/L,M=-(X+_)/L,R=0,N=0,j=0,V=0;for(n=44100*n+9,x*=44100,i*=44100,r*=44100,v*=44100,f*=500*D/85766121e6,h*=D/44100,p*=D/44100,u*=44100,g=44100*g|0,t*=.3*globalThis.zzfxV,X=n+x+i+r+v|0;P<X;a[P++]=W*t)++z%(100*m|0)||(W=o?1<o?2<o?3<o?B(I*I):H.max(H.min(H.tan(I),1),-1):1-(2*I/D%2+2)%2:1-4*H.abs(H.round(I/D)-I/D):B(I),W=(g?1-b+b*B(D*P/g):1)*(W<0?-1:1)*H.abs(W)**s*(P<n?P/n:P<n+x?1-(P-n)/x*(1-T):P<n+x+i?T:P<X-v?(X-P-v)/r*T:0),W=v?W/2+(v>P?0:(P<X-v?1:(X-P)/v)*a[P-v|0]/2/t):W,E&&(W=V=G*R+M*(R=N)+G*(N=W)-k*j-Y*(j=V))),I+=(O=(l+=c+=f)*H.cos(h*A++))+O*d*B(P**5),S&&++S>u&&(l+=p,w+=p,S=0),!g||++C%g||(l=w,c=y,S=S||1);(t=e.createBuffer(1,X,44100)).getChannelData(0).set(a),(l=e.createBufferSource()).buffer=t,l.connect(e.destination),l.start()},a=["#18161c","#6a7799","#aec2c2","#f3eade","#f04f78","#fcf660","#2f328f","#4b80ca","#327345","#63c64d","#703075","#a56243"];globalThis.litecanvas=function(e={}){let l=globalThis,n=Math.PI,i=2*n,r=(e,t,a)=>e.addEventListener(t,a);e=Object.assign({fps:60,fullscreen:!0,width:null,height:null,autoscale:!0,pixelart:!1,antialias:!1,canvas:null,global:!0,loop:null,tapEvents:!0,pauseOnBlur:!0},e);let o=!1,s=[],c=e.canvas||document.createElement("canvas"),f=e.fullscreen,p=e.autoscale,u=1,g,d,h,m=1,v,T=1/e.fps,x=1e3*T,b=0,E,H=0,D=0,y="sans-serif",w="",I=32,A=Date.now(),P={init:!1,update:!1,draw:!1,resized:!1,tap:!1,untap:!1,tapping:!1,tapped:!1},S={settings:Object.assign({},e),colors:a},C={WIDTH:e.width,HEIGHT:e.height||e.width,CANVAS:null,ELAPSED:0,FPS:e.fps,CENTERX:null,CENTERY:null,DEFAULT_SFX:[.5,,1675,,.06,.2,1,1.8,,,637,.06],PI:n,TWO_PI:i,HALF_PI:.5*n,lerp:(e,t,a)=>e+a*(t-e),deg2rad:e=>n/180*e,rad2deg:e=>180/n*e,clamp:(e,t,a)=>e<t?t:e>a?a:e,wrap:(e,t,a)=>e-(a-t)*Math.floor((e-t)/(a-t)),map(e,t,a,l,n,i=!1){let r=(e-t)/(a-t)*(n-l)+l;return i?C.clamp(r,l,n):r},norm:(e,t,a)=>C.map(e,t,a,0,1),rand:(e=0,t=1)=>(A=(1664525*A+0x3c6ef35f)%0x100000000)/0x100000000*(t-e)+e,randi:(e=0,t=1)=>C.floor(C.rand()*(t-e+1)+e),seed:e=>null==e?A:A=~~e,cls(e){null==e?h.clearRect(0,0,C.WIDTH,C.HEIGHT):C.rectfill(0,0,C.WIDTH,C.HEIGHT,e)},rect(e,t,a,l,n=0,i=null){h.beginPath(),h[i?"roundRect":"rect"](~~e,~~t,a,l,i),C.stroke(n)},rectfill(e,t,a,l,n=0,i=null){h.beginPath(),h[i?"roundRect":"rect"](~~e,~~t,a,l,i),C.fill(n)},circ(e,t,a,l){h.beginPath(),h.arc(~~e,~~t,a,0,i),h.closePath(),C.stroke(l)},circfill(e,t,a,l){h.beginPath(),h.arc(~~e,~~t,a,0,i),h.closePath(),C.fill(l)},line(e,t,a,l,n){h.beginPath(),h.moveTo(~~e,~~t),h.lineTo(~~a,~~l),C.stroke(n)},linewidth(e){h.lineWidth=e},linedash(e,t=0){h.setLineDash(Array.isArray(e)?e:[e]),h.lineDashOffset=t},text(e,t,a,l=3){h.font=`${w||""} ${I}px ${y}`,h.fillStyle=C.getcolor(l),h.fillText(a,~~e,~~t)},textfont(e){y=e},textsize(e){I=e},textstyle(e){w=e},textalign(e,t){e&&(h.textAlign=e),t&&(h.textBaseline=t)},textmetrics(e,t){h.font=`${w||""} ${t||I}px ${y}`;let a=h.measureText(e);return a.height=a.actualBoundingBoxAscent+a.actualBoundingBoxDescent,a},image(e,t,a){h.drawImage(a,~~e,~~t)},paint(e,t,a,l={}){let n=l.canvas||new OffscreenCanvas(0,0),i=l.scale||1,r=h;if(n.width=e*i,n.height=t*i,(h=n.getContext("2d")).scale(i,i),Array.isArray(a)){let e=0,t=0;for(let l of(h.imageSmoothingEnabled=!1,a)){for(let a of l)" "!==a&&"."!==a&&C.rectfill(e,t,1,1,parseInt(a,16)),e++;t++,e=0}}else a(n,h);return h=r,n},ctx:e=>(e&&(h=e),h),push:()=>h.save(),pop:()=>h.restore(),translate:(e,t)=>h.translate(~~e,~~t),scale:(e,t)=>h.scale(e,t||e),rotate:e=>h.rotate(e),transform:(e,t,a,l,n,i,r=!0)=>h[r?"setTransform":"transform"](e,t,a,l,n,i),alpha(e){h.globalAlpha=C.clamp(e,0,1)},path:e=>new Path2D(e),fill(e,t){h.fillStyle=C.getcolor(e),h.fill(t)},stroke(e,t){h.strokeStyle=C.getcolor(e),t?h.stroke(t):h.stroke()},cliprect(e,t,a,l){h.beginPath(),h.rect(e,t,a,l),h.clip()},clipcirc(e,t,a){h.beginPath(),h.arc(e,t,a,0,i),h.clip()},blendmode(e){h.globalCompositeOperation=e},sfx:(e,a=0,n=1)=>!(l.zzfxV<=0)&&(!navigator.userActivation||!!navigator.userActivation.hasBeenActive)&&(e=e||C.DEFAULT_SFX,(a>0||1!==n)&&((e=e.slice())[0]=n*(e[0]||1),e[10]=~~e[10]+a),t.apply(0,e),e),volume(e){l.zzfxV=+e},colrect:(e,t,a,l,n,i,r,o)=>e<n+r&&e+a>n&&t<i+o&&t+l>i,colcirc:(e,t,a,l,n,i)=>(l-e)**2+(n-t)**2<=(a+i)**2,mousepos:()=>[g,d],timescale(e){m=e},use(e,t={}){e.__conf=t,o?_(e):s.push(e)},listen:(e,t)=>(P[e]=P[e]||[],P[e].push(t),()=>{P[e]=P[e].filter(e=>t!==e)}),emit(e,t,a,l,n){O("before:"+e,t,a,l,n),O(e,t,a,l,n),O("after:"+e,t,a,l,n)},getcolor:e=>a[~~e%a.length],setvar(t,a){C[t]=a,e.global&&(l[t]=a)},resize(e,t){C.setvar("WIDTH",c.width=e),C.setvar("HEIGHT",c.height=t||e),X()}};for(let e of["sin","cos","atan2","hypot","tan","abs","ceil","round","floor","trunc","min","max","pow","sqrt","sign","exp"])C[e]=Math[e];function z(){o=!0,c="string"==typeof c?document.querySelector(c):c,C.setvar("CANVAS",c),h=c.getContext("2d"),C.WIDTH>0&&(f=!1),c.width=C.WIDTH,c.height=C.HEIGHT||C.WIDTH,c.parentNode||document.body.appendChild(c),c.style.display="block",f?(c.style.position="absolute",c.style.inset=0):p&&(c.style.margin="auto");let t=e.loop?e.loop:l;for(let e of Object.keys(P))t[e]&&C.listen(e,t[e]);for(let e of s)_(e);if(r(l,"resize",X),X(),e.tapEvents){let e=(e,t)=>[(e-c.offsetLeft)/u,(t-c.offsetTop)/u],t=/* @__PURE__ */new Map,a=(e,a,l)=>{let n={x:a,y:l,startX:a,startY:l,ts:performance.now()};return t.set(e,n),n},n=(e,l,n)=>{let i=t.get(e)||a(e);i.x=l,i.y=n},i=e=>e&&performance.now()-e.ts<=200,o=!1;r(c,"mousedown",t=>{t.preventDefault();let[l,n]=e(t.pageX,t.pageY);C.emit("tap",l,n,0),a(0,l,n),o=!0}),r(c,"mousemove",t=>{t.preventDefault();let[a,l]=[g,d]=e(t.pageX,t.pageY);o&&(C.emit("tapping",a,l,0),n(0,a,l))}),r(c,"mouseup",a=>{a.preventDefault();let l=t.get(0),[n,r]=e(a.pageX,a.pageY);i(l)&&C.emit("tapped",l.startX,l.startY,0),C.emit("untap",n,r,0),t.delete(0),o=!1}),r(c,"touchstart",t=>{for(let l of(t.preventDefault(),t.changedTouches)){let[t,n]=e(l.pageX,l.pageY);C.emit("tap",t,n,l.identifier+1),a(l.identifier+1,t,n)}}),r(c,"touchmove",t=>{for(let a of(t.preventDefault(),t.changedTouches)){let[t,l]=e(a.pageX,a.pageY);C.emit("tapping",t,l,a.identifier+1),n(a.identifier+1,t,l)}});let s=e=>{e.preventDefault();let a=[];if(e.targetTouches.length>0)for(let t of e.targetTouches)a.push(t.identifier+1);for(let[e,l]of t)a.includes(e)||(i(l)&&C.emit("tapped",l.startX,l.startY,e),C.emit("untap",l.x,l.y,e),t.delete(e))};r(c,"touchend",s),r(c,"touchcancel",s),r(l,"blur",()=>{if(o=!1,0!==t.size)for(let[e,a]of t)C.emit("untap",a.x,a.y,e),t.delete(e)})}e.pauseOnBlur&&(r(l,"blur",()=>{E=null}),r(l,"focus",()=>{E||(v=performance.now(),E=requestAnimationFrame(W))})),C.emit("init"),v=performance.now(),E=requestAnimationFrame(W)}function W(e){let t=0,a=e-v;for(v=e,b+=a;b>=x;)C.emit("update",T*m),C.setvar("ELAPSED",C.ELAPSED+T*m),b-=x,t++;t&&(C.textalign("start","top"),C.emit("draw"),H++,(D+=x*t)+b>=1e3&&(C.setvar("FPS",H),H=0,D-=1e3)),E&&(E=requestAnimationFrame(W))}function X(){let t=l.innerWidth,a=l.innerHeight;f?(C.setvar("WIDTH",c.width=t),C.setvar("HEIGHT",c.height=a)):p&&(u=Math.min(t/C.WIDTH,a/C.HEIGHT),u=e.pixelart?Math.floor(u):u,c.style.width=C.WIDTH*u+"px",c.style.height=C.HEIGHT*u+"px"),C.setvar("CENTERX",C.WIDTH/2),C.setvar("CENTERY",C.HEIGHT/2),(!e.antialias||e.pixelart)&&(h.imageSmoothingEnabled=!1,c.style.imageRendering="pixelated"),C.emit("resized",u)}function O(e,t,a,l,n){if(P[e])for(let i of P[e])i(t,a,l,n)}function _(e){let t=e(C,S,e.__conf);if("object"==typeof t)for(let[e,a]of Object.entries(t))C.setvar(e,a)}if(e.global){if(l.__litecanvas)throw"Cannot instantiate litecanvas globally twice";Object.assign(l,C),l.__litecanvas=C}return"loading"===document.readyState?r(l,"DOMContentLoaded",z):z(),C}})();
|
package/package.json
CHANGED
package/src/index.js
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -511,16 +511,16 @@ declare global {
|
|
|
511
511
|
* If the first argument is omitted, plays an default sound.
|
|
512
512
|
*
|
|
513
513
|
* @param {number|number[]} [zzfxParams] a ZzFX array of params
|
|
514
|
-
* @param {number} [pitchSlide] a value to increment/decrement the pitch
|
|
515
|
-
* @param {number} [volumeFactor] the volume factor
|
|
514
|
+
* @param {number} [pitchSlide=0] a value to increment/decrement the pitch
|
|
515
|
+
* @param {number} [volumeFactor=1] the volume factor
|
|
516
516
|
* @returns The sound that was played or `false`
|
|
517
517
|
*
|
|
518
518
|
* @see https://github.com/KilledByAPixel/ZzFX
|
|
519
519
|
*/
|
|
520
520
|
function sfx(
|
|
521
521
|
zzfxParams?: number[],
|
|
522
|
-
pitchSlide?: number
|
|
523
|
-
volumeFactor?: number
|
|
522
|
+
pitchSlide?: number,
|
|
523
|
+
volumeFactor?: number
|
|
524
524
|
): number[] | boolean
|
|
525
525
|
/**
|
|
526
526
|
* Set the ZzFX's global volume factor.
|
package/types/types.d.ts
CHANGED
|
@@ -502,8 +502,8 @@ type LitecanvasInstance = {
|
|
|
502
502
|
*/
|
|
503
503
|
sfx(
|
|
504
504
|
zzfxParams?: number[],
|
|
505
|
-
pitchSlide?: number
|
|
506
|
-
volumeFactor?: number
|
|
505
|
+
pitchSlide?: number,
|
|
506
|
+
volumeFactor?: number
|
|
507
507
|
): number[] | boolean
|
|
508
508
|
/**
|
|
509
509
|
* Set the ZzFX's global volume factor.
|