litecanvas 0.58.0 → 0.58.2

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 CHANGED
@@ -860,6 +860,7 @@
860
860
  on(root, "keyup", (event) => {
861
861
  _keys.delete(event.key.toLowerCase());
862
862
  });
863
+ on(root, "blur", () => _keys.clear());
863
864
  }
864
865
  if (settings.pauseOnBlur) {
865
866
  on(root, "blur", () => {
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,d=0,g=0,h=0,m=0,v=0,T=1,b=0,x=0,y=0)=>{let E=Math,w=2*E.PI,H=c*=500*w/44100/44100,D=l*=(1-a+2*a*E.random(a=[]))*w/44100,I=0,A=0,P=0,S=1,C=0,k=0,z=0,L=y<0?-1:1,W=w*L*y*2/44100,X=E.cos(W),O=E.sin,_=O(W)/4,B=1+_,F=-2*X/B,Y=(1-_)/B,G=(1+L*X)/2/B,M=-(L+X)/B,R=0,N=0,j=0,V=0;for(n=44100*n+9,b*=44100,i*=44100,r*=44100,v*=44100,f*=500*w/85766121e6,h*=w/44100,p*=w/44100,u*=44100,d=44100*d|0,t*=.3*globalThis.zzfxV,L=n+b+i+r+v|0;P<L;a[P++]=z*t)++k%(100*m|0)||(z=o?1<o?2<o?3<o?O(I*I):E.max(E.min(E.tan(I),1),-1):1-(2*I/w%2+2)%2:1-4*E.abs(E.round(I/w)-I/w):O(I),z=(d?1-x+x*O(w*P/d):1)*(z<0?-1:1)*E.abs(z)**s*(P<n?P/n:P<n+b?1-(P-n)/b*(1-T):P<n+b+i?T:P<L-v?(L-P-v)/r*T:0),z=v?z/2+(v>P?0:(P<L-v?1:(L-P)/v)*a[P-v|0]/2/t):z,y&&(z=V=G*R+M*(R=N)+G*(N=z)-Y*j-F*(j=V))),I+=(W=(l+=c+=f)*E.cos(h*A++))+W*g*O(P**5),S&&++S>u&&(l+=p,D+=p,S=0),!d||++C%d||(l=D,c=H,S=S||1);(t=e.createBuffer(1,L,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,pauseOnBlur:!0,tapEvents:!0,keyboardEvents:!0},e);let o=!1,s=[],c=e.canvas||document.createElement("canvas"),f=e.fullscreen,p=e.autoscale,u=1,d,g,h,m=1,v,T=1/e.fps,b=1e3*T,x=0,y,E=0,w=0,H="sans-serif",D="",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=`${D||""} ${I}px ${H}`,h.fillStyle=C.getcolor(l),h.fillText(a,~~e,~~t)},textfont(e){H=e},textsize(e){I=e},textstyle(e){D=e},textalign(e,t){e&&(h.textAlign=e),t&&(h.textBaseline=t)},textmetrics(e,t){h.font=`${D||""} ${t||I}px ${H}`;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:()=>[d,g],timescale(e){m=e},use(e,t={}){e.__conf=t,o?X(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){W("before:"+e,t,a,l,n),W(e,t,a,l,n),W("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),L()}};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 k(){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)X(e);if(r(l,"resize",L),L(),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]=[d,g]=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)})}if(e.keyboardEvents){let e=/* @__PURE__ */new Set;C.setvar("iskeydown",t=>"any"===t?e.size>0:e.has(t.toLowerCase())),r(l,"keydown",t=>{e.add(t.key.toLowerCase())}),r(l,"keyup",t=>{e.delete(t.key.toLowerCase())})}e.pauseOnBlur&&(r(l,"blur",()=>{y=null}),r(l,"focus",()=>{y||(v=performance.now(),y=requestAnimationFrame(z))})),C.emit("init",C),v=performance.now(),y=requestAnimationFrame(z)}function z(e){let t=0,a=e-v;for(v=e,x+=a;x>=b;)C.emit("update",T*m),C.setvar("ELAPSED",C.ELAPSED+T*m),x-=b,t++;t&&(C.textalign("start","top"),C.emit("draw"),E++,(w+=b*t)+x>=1e3&&(C.setvar("FPS",E),E=0,w-=1e3)),y&&(y=requestAnimationFrame(z))}function L(){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 W(e,t,a,l,n){if(P[e])for(let i of P[e])i(t,a,l,n)}function X(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"global litecanvas already instantiated";Object.assign(l,C),l.__litecanvas=C}return"loading"===document.readyState?r(l,"DOMContentLoaded",k):k(),C}})();
1
+ (()=>{var e=/* @__PURE__ */new AudioContext;globalThis.zzfxV=1;var t=(t=1,a=.05,l=220,n=0,r=0,i=.1,o=0,s=1,c=0,f=0,p=0,u=0,d=0,g=0,h=0,m=0,v=0,b=1,T=0,x=0,y=0)=>{let E=Math,w=2*E.PI,H=c*=500*w/44100/44100,D=l*=(1-a+2*a*E.random(a=[]))*w/44100,I=0,A=0,P=0,S=1,C=0,k=0,z=0,L=y<0?-1:1,W=w*L*y*2/44100,X=E.cos(W),O=E.sin,_=O(W)/4,B=1+_,F=-2*X/B,Y=(1-_)/B,G=(1+L*X)/2/B,M=-(L+X)/B,R=0,N=0,j=0,V=0;for(n=44100*n+9,T*=44100,r*=44100,i*=44100,v*=44100,f*=500*w/85766121e6,h*=w/44100,p*=w/44100,u*=44100,d=44100*d|0,t*=.3*globalThis.zzfxV,L=n+T+r+i+v|0;P<L;a[P++]=z*t)++k%(100*m|0)||(z=o?1<o?2<o?3<o?O(I*I):E.max(E.min(E.tan(I),1),-1):1-(2*I/w%2+2)%2:1-4*E.abs(E.round(I/w)-I/w):O(I),z=(d?1-x+x*O(w*P/d):1)*(z<0?-1:1)*E.abs(z)**s*(P<n?P/n:P<n+T?1-(P-n)/T*(1-b):P<n+T+r?b:P<L-v?(L-P-v)/i*b:0),z=v?z/2+(v>P?0:(P<L-v?1:(L-P)/v)*a[P-v|0]/2/t):z,y&&(z=V=G*R+M*(R=N)+G*(N=z)-Y*j-F*(j=V))),I+=(W=(l+=c+=f)*E.cos(h*A++))+W*g*O(P**5),S&&++S>u&&(l+=p,D+=p,S=0),!d||++C%d||(l=D,c=H,S=S||1);(t=e.createBuffer(1,L,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,r=2*n,i=(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,pauseOnBlur:!0,tapEvents:!0,keyboardEvents:!0},e);let o=!1,s=[],c=e.canvas||document.createElement("canvas"),f=e.fullscreen,p=e.autoscale,u=1,d,g,h,m=1,v,b=1/e.fps,T=1e3*b,x=0,y,E=0,w=0,H="sans-serif",D="",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:r,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,r=!1){let i=(e-t)/(a-t)*(n-l)+l;return r?C.clamp(i,l,n):i},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,r=null){h.beginPath(),h[r?"roundRect":"rect"](~~e,~~t,a,l,r),C.stroke(n)},rectfill(e,t,a,l,n=0,r=null){h.beginPath(),h[r?"roundRect":"rect"](~~e,~~t,a,l,r),C.fill(n)},circ(e,t,a,l){h.beginPath(),h.arc(~~e,~~t,a,0,r),h.closePath(),C.stroke(l)},circfill(e,t,a,l){h.beginPath(),h.arc(~~e,~~t,a,0,r),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=`${D||""} ${I}px ${H}`,h.fillStyle=C.getcolor(l),h.fillText(a,~~e,~~t)},textfont(e){H=e},textsize(e){I=e},textstyle(e){D=e},textalign(e,t){e&&(h.textAlign=e),t&&(h.textBaseline=t)},textmetrics(e,t){h.font=`${D||""} ${t||I}px ${H}`;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),r=l.scale||1,i=h;if(n.width=e*r,n.height=t*r,(h=n.getContext("2d")).scale(r,r),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=i,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,r,i=!0)=>h[i?"setTransform":"transform"](e,t,a,l,n,r),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,r),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,r,i,o)=>e<n+i&&e+a>n&&t<r+o&&t+l>r,colcirc:(e,t,a,l,n,r)=>(l-e)**2+(n-t)**2<=(a+r)**2,mousepos:()=>[d,g],timescale(e){m=e},use(e,t={}){e.__conf=t,o?X(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){W("before:"+e,t,a,l,n),W(e,t,a,l,n),W("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),L()}};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 k(){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)X(e);if(i(l,"resize",L),L(),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 r=t.get(e)||a(e);r.x=l,r.y=n},r=e=>e&&performance.now()-e.ts<=200,o=!1;i(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}),i(c,"mousemove",t=>{t.preventDefault();let[a,l]=[d,g]=e(t.pageX,t.pageY);o&&(C.emit("tapping",a,l,0),n(0,a,l))}),i(c,"mouseup",a=>{a.preventDefault();let l=t.get(0),[n,i]=e(a.pageX,a.pageY);r(l)&&C.emit("tapped",l.startX,l.startY,0),C.emit("untap",n,i,0),t.delete(0),o=!1}),i(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)}}),i(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)||(r(l)&&C.emit("tapped",l.startX,l.startY,e),C.emit("untap",l.x,l.y,e),t.delete(e))};i(c,"touchend",s),i(c,"touchcancel",s),i(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)})}if(e.keyboardEvents){let e=/* @__PURE__ */new Set;C.setvar("iskeydown",t=>"any"===t?e.size>0:e.has(t.toLowerCase())),i(l,"keydown",t=>{e.add(t.key.toLowerCase())}),i(l,"keyup",t=>{e.delete(t.key.toLowerCase())}),i(l,"blur",()=>e.clear())}e.pauseOnBlur&&(i(l,"blur",()=>{y=null}),i(l,"focus",()=>{y||(v=performance.now(),y=requestAnimationFrame(z))})),C.emit("init",C),v=performance.now(),y=requestAnimationFrame(z)}function z(e){let t=0,a=e-v;for(v=e,x+=a;x>=T;)C.emit("update",b*m),C.setvar("ELAPSED",C.ELAPSED+b*m),x-=T,t++;t&&(C.textalign("start","top"),C.emit("draw"),E++,(w+=T*t)+x>=1e3&&(C.setvar("FPS",E),E=0,w-=1e3)),y&&(y=requestAnimationFrame(z))}function L(){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 W(e,t,a,l,n){if(P[e])for(let r of P[e])r(t,a,l,n)}function X(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"global litecanvas already instantiated";Object.assign(l,C),l.__litecanvas=C}return"loading"===document.readyState?i(l,"DOMContentLoaded",k):k(),C}})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litecanvas",
3
- "version": "0.58.0",
3
+ "version": "0.58.2",
4
4
  "description": "Lightweight HTML5 canvas engine suitable for small games and animations.",
5
5
  "license": "MIT",
6
6
  "author": "Luiz Bills <luizbills@pm.me>",
package/src/index.js CHANGED
@@ -1012,6 +1012,9 @@ export default function litecanvas(settings = {}) {
1012
1012
 
1013
1013
  /**
1014
1014
  * Checks if a key is currently pressed in your keyboard.
1015
+ * Notes:
1016
+ * - to check the space key use `iskeydown(" ")`.
1017
+ * - you can check if any key is pressed using `iskeydown("any")`.
1015
1018
  *
1016
1019
  * @param {string} key
1017
1020
  * @returns {boolean}
@@ -1028,6 +1031,8 @@ export default function litecanvas(settings = {}) {
1028
1031
  on(root, 'keyup', (/** @type {KeyboardEvent} */ event) => {
1029
1032
  _keys.delete(event.key.toLowerCase())
1030
1033
  })
1034
+
1035
+ on(root, 'blur', () => _keys.clear())
1031
1036
  }
1032
1037
 
1033
1038
  // listen browser focus/blur events and pause the update/draw loop
package/src/types.js CHANGED
@@ -8,10 +8,11 @@
8
8
  * @property {boolean} [pauseOnBlur=true]
9
9
  * @property {boolean} [autoscale=true]
10
10
  * @property {boolean} [pixelart=false]
11
- * @property {boolean} [antialias=true]
11
+ * @property {boolean} [antialias=false]
12
12
  * @property {string} [canvas]
13
13
  * @property {boolean} [global=true]
14
14
  * @property {boolean} [tapEvents=true]
15
+ * @property {boolean} [keyboardEvents=true]
15
16
  * @property {LitecanvasGameLoop} [loop]
16
17
  */
17
18
 
package/types/index.d.ts CHANGED
@@ -533,6 +533,9 @@ declare global {
533
533
  /** UTILS API */
534
534
  /**
535
535
  * Checks if a key is currently pressed in your keyboard.
536
+ * Notes:
537
+ * - to check the space key use `iskeydown(" ")`.
538
+ * - you can check if any key is pressed using `iskeydown("any")`.
536
539
  *
537
540
  * @param key
538
541
  * @returns `true` if the which key is down
package/types/types.d.ts CHANGED
@@ -517,6 +517,10 @@ type LitecanvasInstance = {
517
517
  /**
518
518
  * Checks if a key is currently pressed in your keyboard.
519
519
  *
520
+ * Notes:
521
+ * - to check the space key use `iskeydown(" ")`.
522
+ * - you can check if any key is pressed using `iskeydown("any")`.
523
+ *
520
524
  * @param key
521
525
  * @returns `true` if the which key is down
522
526
  */
@@ -655,7 +659,7 @@ type LitecanvasOptions = {
655
659
  */
656
660
  pixelart?: boolean
657
661
  /**
658
- * If `false`, disable the canvas antialias.
662
+ * If `false` (default), disable the canvas antialias.
659
663
  */
660
664
  antialias?: boolean
661
665
  /**
@@ -666,11 +670,6 @@ type LitecanvasOptions = {
666
670
  * If `true` (default), all methods and properties of the engine will be exposed to the global scope (window).
667
671
  */
668
672
  global?: boolean
669
- /**
670
- * if `false` disable the click/touch events handling.
671
- * Useful when you want to implement your own input handler.
672
- */
673
- tapEvents?: boolean
674
673
  /**
675
674
  * Specify your game loop callbacks.
676
675
  * By default use that global functions (if they exist):
@@ -684,6 +683,22 @@ type LitecanvasOptions = {
684
683
  * - `window.tapping(tapX: number, tapY: number, tapId: number): void`
685
684
  */
686
685
  loop?: LitecanvasGameLoop
686
+ /**
687
+ * default: `true`
688
+ *
689
+ * if `false` disable the click/touch events handling.
690
+ *
691
+ * Useful when you want to implement your own input handler.
692
+ */
693
+ tapEvents?: boolean
694
+ /**
695
+ * default: `true`
696
+ *
697
+ * if `false` disable the `iskeydown()` method.
698
+ *
699
+ * Useful when you want to implement your keyboard handler.
700
+ */
701
+ keyboardEvents?: boolean
687
702
  }
688
703
 
689
704
  type LitecanvasGameLoop = {