litecanvas 0.54.0 → 0.54.1
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 +7 -6
- package/dist/dist.min.js +1 -1
- package/package.json +1 -1
- package/src/index.js +7 -7
- package/src/zzfx.js +4 -1
- package/types/index.d.ts +3 -3
- package/types/types.d.ts +3 -3
package/dist/dist.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
// src/zzfx.js
|
|
3
3
|
var zzfxX = /* @__PURE__ */ new AudioContext();
|
|
4
|
+
globalThis.zzfxV = 1;
|
|
4
5
|
var zzfx = (p = 1, k = 0.05, b = 220, e = 0, r = 0, t = 0.1, q = 0, D = 1, u = 0, y = 0, v = 0, z = 0, l = 0, E = 0, A = 0, F = 0, c = 0, w = 1, m = 0, B = 0, N = 0) => {
|
|
5
6
|
let M = Math, d = 2 * M.PI, R = 44100, G = u *= 500 * d / R / R, C = b *= (1 - k + 2 * k * M.random(k = [])) * d / R, g = 0, H = 0, a = 0, n = 1, I = 0, J = 0, f = 0, h = N < 0 ? -1 : 1, x = d * h * N * 2 / R, L = M.cos(x), Z = M.sin, K = Z(x) / 4, O = 1 + K, X = -2 * L / O, Y = (1 - K) / O, P = (1 + h * L) / 2 / O, Q = -(h + L) / O, S = P, T = 0, U = 0, V = 0, W = 0;
|
|
6
7
|
e = R * e + 9;
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
v *= d / R;
|
|
14
15
|
z *= R;
|
|
15
16
|
l = R * l | 0;
|
|
16
|
-
p *= globalThis.zzfxV
|
|
17
|
+
p *= globalThis.zzfxV * 0.3;
|
|
17
18
|
for (h = e + m + r + t + c | 0; a < h; k[a++] = f * p)
|
|
18
19
|
++J % (100 * F | 0) || (f = q ? 1 < q ? 2 < q ? 3 < q ? Z(g * g) : M.max(M.min(M.tan(g), 1), -1) : 1 - (2 * g / d % 2 + 2) % 2 : 1 - 4 * M.abs(M.round(g / d) - g / d) : Z(g), f = (l ? 1 - B + B * Z(d * a / l) : 1) * (f < 0 ? -1 : 1) * M.abs(f) ** D * (a < e ? a / e : a < e + m ? 1 - (a - e) / m * (1 - w) : a < e + m + r ? w : a < h - c ? (h - a - c) / t * w : 0), f = c ? f / 2 + (c > a ? 0 : (a < h - c ? 1 : (h - a) / c) * k[a - c | 0] / 2 / p) : f, N ? f = W = S * T + Q * (T = U) + P * (U = f) - Y * V - X * (V = W) : 0), x = (b += u += y) * M.cos(A * H++), g += x + x * E * Z(a ** 5), n && ++n > z && (b += v, C += v, n = 0), !l || ++I % l || (b = C, u = G, n = n || 1);
|
|
19
20
|
p = zzfxX.createBuffer(1, h, R);
|
|
@@ -576,7 +577,7 @@
|
|
|
576
577
|
},
|
|
577
578
|
/** SOUND API */
|
|
578
579
|
/**
|
|
579
|
-
* Play a sound
|
|
580
|
+
* Play a sound effects using ZzFX library.
|
|
580
581
|
* If the first argument is omitted, plays an default sound.
|
|
581
582
|
*
|
|
582
583
|
* @param {number|number[]} [sound] a ZzFX array of params
|
|
@@ -587,7 +588,7 @@
|
|
|
587
588
|
* @see https://github.com/KilledByAPixel/ZzFX
|
|
588
589
|
*/
|
|
589
590
|
sfx(zzfxParams, volume, pitch, randomness) {
|
|
590
|
-
if (navigator.userActivation && !navigator.userActivation.hasBeenActive) {
|
|
591
|
+
if (root.zzfxV <= 0 || navigator.userActivation && !navigator.userActivation.hasBeenActive) {
|
|
591
592
|
return;
|
|
592
593
|
}
|
|
593
594
|
zzfxParams = zzfxParams || DEFAULT_SFX_SOUND;
|
|
@@ -600,13 +601,13 @@
|
|
|
600
601
|
zzfx.apply(0, zzfxParams);
|
|
601
602
|
},
|
|
602
603
|
/**
|
|
603
|
-
* Set the ZzFX's global volume.
|
|
604
|
-
*
|
|
604
|
+
* Set the ZzFX's global volume factor.
|
|
605
|
+
* Note: use 0 to mute all sound effects.
|
|
605
606
|
*
|
|
606
607
|
* @param {number} value
|
|
607
608
|
*/
|
|
608
609
|
volume(value) {
|
|
609
|
-
root.zzfxV = +value
|
|
610
|
+
root.zzfxV = +value;
|
|
610
611
|
},
|
|
611
612
|
/** UTILS API */
|
|
612
613
|
/**
|
package/dist/dist.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e=/* @__PURE__ */new AudioContext
|
|
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,x=1,T=0,b=0,H=0)=>{let E=Math,y=2*E.PI,D=c*=500*y/44100/44100,w=l*=(1-a+2*a*E.random(a=[]))*y/44100,I=0,A=0,P=0,C=1,S=0,z=0,W=0,O=H<0?-1:1,B=y*O*H*2/44100,X=E.cos(B),Y=E.sin,k=Y(B)/4,G=1+k,_=-2*X/G,L=(1-k)/G,M=(1+O*X)/2/G,R=-(O+X)/G,N=0,j=0,F=0,V=0;for(n=44100*n+9,T*=44100,i*=44100,r*=44100,v*=44100,f*=500*y/85766121e6,h*=y/44100,p*=y/44100,u*=44100,g=44100*g|0,t*=.3*globalThis.zzfxV,O=n+T+i+r+v|0;P<O;a[P++]=W*t)++z%(100*m|0)||(W=o?1<o?2<o?3<o?Y(I*I):E.max(E.min(E.tan(I),1),-1):1-(2*I/y%2+2)%2:1-4*E.abs(E.round(I/y)-I/y):Y(I),W=(g?1-b+b*Y(y*P/g):1)*(W<0?-1:1)*E.abs(W)**s*(P<n?P/n:P<n+T?1-(P-n)/T*(1-x):P<n+T+i?x:P<O-v?(O-P-v)/r*x:0),W=v?W/2+(v>P?0:(P<O-v?1:(O-P)/v)*a[P-v|0]/2/t):W,H&&(W=V=M*N+R*(N=j)+M*(j=W)-L*F-_*(F=V))),I+=(B=(l+=c+=f)*E.cos(h*A++))+B*d*Y(P**5),C&&++C>u&&(l+=p,w+=p,C=0),!g||++S%g||(l=w,c=D,C=C||1);(t=e.createBuffer(1,O,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=[.5,,1675,,.06,.2,1,1.8,,,637,.06],o=(e,t,a)=>e.addEventListener(t,a);e=Object.assign({fps:60,fullscreen:!0,width:null,height:null,autoscale:!0,pixelart:!1,antialias:!0,canvas:null,global:!0,loop:null,tapEvents:!0,pauseOnBlur:!0},e);let s=!1,c=[],f=e.canvas||document.createElement("canvas"),p=e.fullscreen,u=e.autoscale,g=1,d,h,m,v=1,x,T=1/e.fps,b=1e3*T,H=0,E,y=0,D=0,w="sans-serif",I="",A=32,P=Date.now(),C={init:!1,update:!1,draw:!1,resized:!1,tap:!1,untap:!1,tapping:!1,tapped:!1},S={settings:Object.assign({},e),colors:a},z={WIDTH:e.width,HEIGHT:e.height||e.width,CANVAS:null,ELAPSED:0,FPS:e.fps,CENTERX:null,CENTERY:null,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?z.clamp(r,l,n):r},norm:(e,t,a)=>z.map(e,t,a,0,1),rand:(e=0,t=1)=>(P=(1664525*P+0x3c6ef35f)%0x100000000)/0x100000000*(t-e)+e,randi:(e=0,t=1)=>z.floor(z.rand()*(t-e+1)+e),seed:e=>null==e?P:P=~~e,cls(e){null==e?m.clearRect(0,0,z.WIDTH,z.HEIGHT):z.rectfill(0,0,z.WIDTH,z.HEIGHT,e)},rect(e,t,a,l,n=0,i=null){m.beginPath(),m[i?"roundRect":"rect"](~~e,~~t,a,l,i),z.stroke(n)},rectfill(e,t,a,l,n=0,i=null){m.beginPath(),m[i?"roundRect":"rect"](~~e,~~t,a,l,i),z.fill(n)},circ(e,t,a,l){m.beginPath(),m.arc(~~e,~~t,a,0,i),m.closePath(),z.stroke(l)},circfill(e,t,a,l){m.beginPath(),m.arc(~~e,~~t,a,0,i),m.closePath(),z.fill(l)},line(e,t,a,l,n){m.beginPath(),m.moveTo(~~e,~~t),m.lineTo(~~a,~~l),z.stroke(n)},linewidth(e){m.lineWidth=e},linedash(e,t=0){m.setLineDash(Array.isArray(e)?e:[e]),m.lineDashOffset=t},text(e,t,a,l=3){m.font=`${I||""} ${A}px ${w}`,m.fillStyle=z.getcolor(l),m.fillText(a,~~e,~~t)},textfont(e){w=e},textsize(e){A=e},textstyle(e){I=e},textalign(e,t){e&&(m.textAlign=e),t&&(m.textBaseline=t)},textmetrics(e,t){m.font=`${I||""} ${t||A}px ${w}`;let a=m.measureText(e);return a.height=a.actualBoundingBoxAscent+a.actualBoundingBoxDescent,a},image(e,t,a){m.drawImage(a,~~e,~~t)},paint(e,t,a,l={}){let n=new OffscreenCanvas(e,t),i=m,r=l.scale||1;if(n.width=e*r,n.height=t*r,(m=n.getContext("2d")).scale(r,r),Array.isArray(a)){let e=0,t=0;for(let l of(m.imageSmoothingEnabled=!1,a)){for(let a of l)" "!==a&&"."!==a&&z.rectfill(e,t,1,1,parseInt(a,16)),e++;t++,e=0}}else a(n,m);return m=i,n},ctx:e=>(e&&(m=e),m),push:()=>m.save(),pop:()=>m.restore(),translate:(e,t)=>m.translate(~~e,~~t),scale:(e,t)=>m.scale(e,t||e),rotate:e=>m.rotate(e),transform:(e,t,a,l,n,i,r=!0)=>m[r?"setTransform":"transform"](e,t,a,l,n,i),alpha(e){m.globalAlpha=z.clamp(e,0,1)},path:e=>new Path2D(e),fill(e,t){m.fillStyle=z.getcolor(e),m.fill(t)},stroke(e,t){m.strokeStyle=z.getcolor(e),t?m.stroke(t):m.stroke()},cliprect(e,t,a,l){m.beginPath(),m.rect(e,t,a,l),m.clip()},clipcirc(e,t,a){m.beginPath(),m.arc(e,t,a,0,i),m.clip()},blendmode(e){m.globalCompositeOperation=e},sfx(e,a,n,i){l.zzfxV<=0||navigator.userActivation&&!navigator.userActivation.hasBeenActive||(e=e||r,(a||n||i)&&((e=e.slice())[0]=(a||1)*(e[0]||1),e[1]=+i?i:e[1],e[10]=~~e[10]+~~n),t.apply(0,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:()=>[d,h],timescale(e){v=e},use(e,t={}){e.__conf=t,s?Y(e):c.push(e)},listen:(e,t)=>(C[e]=C[e]||[],C[e].push(t),()=>{C[e]=C[e].filter(e=>t!==e)}),emit(e,t,a,l,n){X("before:"+e,t,a,l,n),X(e,t,a,l,n),X("after:"+e,t,a,l,n)},getcolor:e=>a[~~e%a.length],setvar(t,a){z[t]=a,e.global&&(l[t]=a)},resize(e,t){z.setvar("WIDTH",f.width=e),z.setvar("HEIGHT",f.height=t||e),B()}};for(let e of["sin","cos","atan2","hypot","tan","abs","ceil","round","floor","trunc","min","max","pow","sqrt","sign","exp"])z[e]=Math[e];function W(){s=!0,f="string"==typeof f?document.querySelector(f):f,z.setvar("CANVAS",f),m=f.getContext("2d"),z.WIDTH>0&&(p=!1),f.width=z.WIDTH,f.height=z.HEIGHT||z.WIDTH,f.parentNode||document.body.appendChild(f),f.style.display="block",p?(f.style.position="absolute",f.style.inset=0):u&&(f.style.margin="auto");let t=e.loop?e.loop:l;for(let e of Object.keys(C))t[e]&&z.listen(e,t[e]);for(let e of c)Y(e);if(o(l,"resize",B),B(),e.tapEvents){let e=(e,t)=>[(e-f.offsetLeft)/g,(t-f.offsetTop)/g],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,r=!1;o(f,"mousedown",t=>{t.preventDefault();let[l,n]=e(t.pageX,t.pageY);z.emit("tap",l,n,0),a(0,l,n),r=!0}),o(f,"mousemove",t=>{t.preventDefault();let[a,l]=[d,h]=e(t.pageX,t.pageY);r&&(z.emit("tapping",a,l,0),n(0,a,l))}),o(f,"mouseup",a=>{a.preventDefault();let l=t.get(0),[n,o]=e(a.pageX,a.pageY);i(l)&&z.emit("tapped",l.startX,l.startY,0),z.emit("untap",n,o,0),t.delete(0),r=!1}),o(f,"touchstart",t=>{for(let l of(t.preventDefault(),t.changedTouches)){let[t,n]=e(l.pageX,l.pageY);z.emit("tap",t,n,l.identifier+1),a(l.identifier+1,t,n)}}),o(f,"touchmove",t=>{for(let a of(t.preventDefault(),t.changedTouches)){let[t,l]=e(a.pageX,a.pageY);z.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)&&z.emit("tapped",l.startX,l.startY,e),z.emit("untap",l.x,l.y,e),t.delete(e))};o(f,"touchend",s),o(f,"touchcancel",s),o(l,"blur",()=>{if(r=!1,0!==t.size)for(let[e,a]of t)z.emit("untap",a.x,a.y,e),t.delete(e)})}e.pauseOnBlur&&(o(l,"blur",()=>{E=null}),o(l,"focus",()=>{E||(x=performance.now(),E=requestAnimationFrame(O))})),z.emit("init"),x=performance.now(),E=requestAnimationFrame(O)}function O(e){let t=0,a=e-x;for(x=e,H+=a;H>=b;)z.emit("update",T*v),z.setvar("ELAPSED",z.ELAPSED+T*v),H-=b,t++;t&&(z.textalign("start","top"),z.emit("draw"),y++,(D+=b*t)+H>=1e3&&(z.setvar("FPS",y),y=0,D-=1e3)),E&&(E=requestAnimationFrame(O))}function B(){let t=l.innerWidth,a=l.innerHeight;p?(z.setvar("WIDTH",f.width=t),z.setvar("HEIGHT",f.height=a)):u&&(g=Math.min(t/z.WIDTH,a/z.HEIGHT),g=e.pixelart?Math.floor(g):g,f.style.width=z.WIDTH*g+"px",f.style.height=z.HEIGHT*g+"px"),z.setvar("CENTERX",z.WIDTH/2),z.setvar("CENTERY",z.HEIGHT/2),(!e.antialias||e.pixelart)&&(m.imageSmoothingEnabled=!1,f.style.imageRendering="pixelated"),z.emit("resized",g)}function X(e,t,a,l,n){if(C[e])for(let i of C[e])i(t,a,l,n)}function Y(e){let t=e(z,S,e.__conf);if("object"==typeof t)for(let[e,a]of Object.entries(t))z.setvar(e,a)}if(e.global){if(l.__litecanvas)throw"Cannot instantiate litecanvas globally twice";Object.assign(l,z),l.__litecanvas=z}return"loading"===document.readyState?o(l,"DOMContentLoaded",W):W(),z}})();
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -671,7 +671,7 @@ export default function litecanvas(settings = {}) {
|
|
|
671
671
|
|
|
672
672
|
/** SOUND API */
|
|
673
673
|
/**
|
|
674
|
-
* Play a sound
|
|
674
|
+
* Play a sound effects using ZzFX library.
|
|
675
675
|
* If the first argument is omitted, plays an default sound.
|
|
676
676
|
*
|
|
677
677
|
* @param {number|number[]} [sound] a ZzFX array of params
|
|
@@ -683,13 +683,13 @@ export default function litecanvas(settings = {}) {
|
|
|
683
683
|
*/
|
|
684
684
|
sfx(zzfxParams, volume, pitch, randomness) {
|
|
685
685
|
if (
|
|
686
|
-
|
|
687
|
-
|
|
686
|
+
root.zzfxV <= 0 ||
|
|
687
|
+
(navigator.userActivation &&
|
|
688
|
+
!navigator.userActivation.hasBeenActive)
|
|
688
689
|
) {
|
|
689
690
|
return
|
|
690
691
|
}
|
|
691
692
|
|
|
692
|
-
// prettier-ignore
|
|
693
693
|
zzfxParams = zzfxParams || DEFAULT_SFX_SOUND
|
|
694
694
|
|
|
695
695
|
// if has other arguments, copy the sound to not change the original
|
|
@@ -704,13 +704,13 @@ export default function litecanvas(settings = {}) {
|
|
|
704
704
|
},
|
|
705
705
|
|
|
706
706
|
/**
|
|
707
|
-
* Set the ZzFX's global volume.
|
|
708
|
-
*
|
|
707
|
+
* Set the ZzFX's global volume factor.
|
|
708
|
+
* Note: use 0 to mute all sound effects.
|
|
709
709
|
*
|
|
710
710
|
* @param {number} value
|
|
711
711
|
*/
|
|
712
712
|
volume(value) {
|
|
713
|
-
root.zzfxV = +value
|
|
713
|
+
root.zzfxV = +value
|
|
714
714
|
},
|
|
715
715
|
|
|
716
716
|
/** UTILS API */
|
package/src/zzfx.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.3.0 by Frank Force | https://github.com/KilledByAPixel/ZzFX
|
|
2
2
|
const zzfxX = /** @__PURE__ */ new AudioContext()
|
|
3
|
+
|
|
4
|
+
globalThis.zzfxV = 1
|
|
5
|
+
|
|
3
6
|
export const zzfx = (
|
|
4
7
|
p = 1,
|
|
5
8
|
k = 0.05,
|
|
@@ -60,7 +63,7 @@ export const zzfx = (
|
|
|
60
63
|
v *= d / R
|
|
61
64
|
z *= R
|
|
62
65
|
l = (R * l) | 0
|
|
63
|
-
p *= globalThis.zzfxV
|
|
66
|
+
p *= globalThis.zzfxV * 0.3
|
|
64
67
|
for (h = (e + m + r + t + c) | 0; a < h; k[a++] = f * p)
|
|
65
68
|
++J % ((100 * F) | 0) ||
|
|
66
69
|
((f = q
|
package/types/index.d.ts
CHANGED
|
@@ -505,7 +505,7 @@ declare global {
|
|
|
505
505
|
|
|
506
506
|
/** SOUND API */
|
|
507
507
|
/**
|
|
508
|
-
* Play a sound
|
|
508
|
+
* Play a sound effects using ZzFX library.
|
|
509
509
|
* If the first argument is omitted, plays an default sound.
|
|
510
510
|
*
|
|
511
511
|
* @param {number|number[]} [sound] a ZzFX array of params
|
|
@@ -522,8 +522,8 @@ declare global {
|
|
|
522
522
|
randomness?: number
|
|
523
523
|
): void
|
|
524
524
|
/**
|
|
525
|
-
* Set the ZzFX's global volume.
|
|
526
|
-
*
|
|
525
|
+
* Set the ZzFX's global volume factor.
|
|
526
|
+
* Note: use 0 to mute all sound effects.
|
|
527
527
|
*
|
|
528
528
|
* @param {number} value
|
|
529
529
|
*/
|
package/types/types.d.ts
CHANGED
|
@@ -488,7 +488,7 @@ type LitecanvasInstance = {
|
|
|
488
488
|
|
|
489
489
|
/** SOUND API */
|
|
490
490
|
/**
|
|
491
|
-
* Play a sound
|
|
491
|
+
* Play a sound effects using ZzFX library.
|
|
492
492
|
* If the first argument is omitted, plays an default sound.
|
|
493
493
|
*
|
|
494
494
|
* @param {number|number[]} [sound] a ZzFX array of params
|
|
@@ -505,8 +505,8 @@ type LitecanvasInstance = {
|
|
|
505
505
|
randomness?: number
|
|
506
506
|
): void
|
|
507
507
|
/**
|
|
508
|
-
* Set the ZzFX's global volume.
|
|
509
|
-
*
|
|
508
|
+
* Set the ZzFX's global volume factor.
|
|
509
|
+
* Note: use 0 to mute all sound effects.
|
|
510
510
|
*
|
|
511
511
|
* @param {number} value
|
|
512
512
|
*/
|