litecanvas 0.86.0 → 0.87.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.dev.js +188 -123
- package/dist/dist.js +1 -1
- package/dist/dist.min.js +1 -1
- package/package.json +8 -5
- package/src/index.js +187 -123
package/dist/dist.js
CHANGED
|
@@ -1048,7 +1048,7 @@
|
|
|
1048
1048
|
}
|
|
1049
1049
|
if (settings.global) {
|
|
1050
1050
|
if (root.ENGINE) {
|
|
1051
|
-
throw new Error("
|
|
1051
|
+
throw new Error("only one global litecanvas is allowed");
|
|
1052
1052
|
}
|
|
1053
1053
|
Object.assign(root, instance);
|
|
1054
1054
|
root.ENGINE = instance;
|
package/dist/dist.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e=["#111","#6a7799","#aec2c2","#FFF1E8","#e83b3b","#fabc20","#155fd9","#3cbcfc","#327345","#63c64d","#6c2c1f","#ac7c00"];globalThis.litecanvas=function(t={}){let a=window,
|
|
1
|
+
(()=>{var e=["#111","#6a7799","#aec2c2","#FFF1E8","#e83b3b","#fabc20","#155fd9","#3cbcfc","#327345","#63c64d","#6c2c1f","#ac7c00"];globalThis.litecanvas=function(t={}){let a=window,n=Math,i=2*n.PI,l=requestAnimationFrame,o=[],r=(e,t,a)=>{e.addEventListener(t,a,!1),o.push(()=>e.removeEventListener(t,a,!1))},s=(e=>{let t=new AudioContext;return e.zzfxV=1,(a=1,n=.05,i=220,l=0,o=0,r=.1,s=0,f=1,c=0,d=0,p=0,u=0,h=0,g=0,m=0,v=0,w=0,b=1,x=0,y=0,k=0)=>{let E=Math,z=2*E.PI,P=c*=500*z/44100/44100,T=i*=(1-n+2*n*E.random(n=[]))*z/44100,C=0,I=0,A=0,L=1,S=0,X=0,Y=0,M=k<0?-1:1,D=z*M*k*2/44100,N=E.cos(D),F=E.sin,q=F(D)/4,B=1+q,H=-2*N/B,O=(1-q)/B,V=(1+M*N)/2/B,W=-(M+N)/B,R=0,G=0,$=0,j=0;for(l=44100*l+9,x*=44100,o*=44100,r*=44100,w*=44100,d*=500*z/85766121e6,m*=z/44100,p*=z/44100,u*=44100,h=44100*h|0,a*=.3*e.zzfxV,M=l+x+o+r+w|0;A<M;n[A++]=Y*a)++X%(100*v|0)||(Y=s?1<s?2<s?3<s?F(C*C):E.max(E.min(E.tan(C),1),-1):1-(2*C/z%2+2)%2:1-4*E.abs(E.round(C/z)-C/z):F(C),Y=(h?1-y+y*F(z*A/h):1)*(Y<0?-1:1)*E.abs(Y)**f*(A<l?A/l:A<l+x?1-(A-l)/x*(1-b):A<l+x+o?b:A<M-w?(M-A-w)/r*b:0),Y=w?Y/2+(w>A?0:(A<M-w?1:(M-A)/w)*n[A-w|0]/2/a):Y,k&&(Y=j=V*R+W*(R=G)+V*(G=Y)-O*$-H*($=j))),C+=(D=(i+=c+=d)*E.cos(m*I++))+D*g*F(A**5),L&&++L>u&&(i+=p,T+=p,L=0),!h||++S%h||(i=T,c=P,L=L||1);(a=t.createBuffer(1,M,44100)).getChannelData(0).set(n),(i=t.createBufferSource()).buffer=a,i.connect(t.destination),i.start()}})(a);t=Object.assign({width:null,height:null,autoscale:!0,pixelart:!1,antialias:!1,canvas:null,global:!0,loop:null,tapEvents:!0,keyboardEvents:!0,animate:!0},t);let f=!1,c=[],d,p=1,u,h=.5,g=1,m,v=1/60,w=0,b,x="sans-serif",y=20,k=Date.now(),E=e,z=[.5,0,1750,,,.3,1,,,,600,.1],P={},T={W:0,H:0,T:0,MX:-1,MY:-1,TWO_PI:i,HALF_PI:i/4,lerp:(e,t,a)=>a*(t-e)+e,deg2rad:e=>n.PI/180*e,rad2deg:e=>180/n.PI*e,round:(e,t=0)=>{if(!t)return n.round(e);let a=10**t;return n.round(e*a)/a},clamp:(e,t,a)=>e<t?t:e>a?a:e,wrap:(e,t,a)=>e-(a-t)*n.floor((e-t)/(a-t)),map(e,t,a,n,i,l){let o=(e-t)/(a-t)*(i-n)+n;return l?T.clamp(o,n,i):o},norm:(e,t,a)=>T.map(e,t,a,0,1),wave:(e,t,a,n=Math.sin)=>e+(n(a)+1)/2*(t-e),rand:(e=0,t=1)=>(k=(1664525*k+0x3c6ef35f)%0x100000000)/0x100000000*(t-e)+e,randi:(e=0,t=1)=>n.floor(T.rand(e,t+1)),rseed(e){k=~~e},cls(e){null==e?u.clearRect(0,0,u.canvas.width,u.canvas.height):T.rectfill(0,0,u.canvas.width,u.canvas.height,e)},rect(e,t,a,n,i,l){u.beginPath(),u[l?"roundRect":"rect"](~~e-h,~~t-h,~~a+2*h,~~n+2*h,l),T.stroke(i)},rectfill(e,t,a,n,i,l){u.beginPath(),u[l?"roundRect":"rect"](~~e,~~t,~~a,~~n,l),T.fill(i)},circ(e,t,a,n){u.beginPath(),u.arc(~~e,~~t,~~a,0,i),T.stroke(n)},circfill(e,t,a,n){u.beginPath(),u.arc(~~e,~~t,~~a,0,i),T.fill(n)},oval(e,t,a,n,l){u.beginPath(),u.ellipse(~~e,~~t,~~a,~~n,0,0,i),T.stroke(l)},ovalfill(e,t,a,n,l){u.beginPath(),u.ellipse(~~e,~~t,~~a,~~n,0,0,i),T.fill(l)},line(e,t,a,n,i){u.beginPath();let l=.5*(0!==h&&~~e==~~a),o=.5*(0!==h&&~~t==~~n);u.moveTo(~~e+l,~~t+o),u.lineTo(~~a+l,~~n+o),T.stroke(i)},linewidth(e){u.lineWidth=~~e,h=.5*(0!=~~e%2)},linedash(e,t=0){u.setLineDash(e),u.lineDashOffset=t},text(e,t,a,n=3,i="normal"){u.font=`${i} ${y}px ${x}`,u.fillStyle=E[~~n%E.length],u.fillText(a,~~e,~~t)},textfont(e){x=e},textsize(e){y=e},textalign(e,t){e&&(u.textAlign=e),t&&(u.textBaseline=t)},image(e,t,a){u.drawImage(a,~~e,~~t)},paint(e,t,a,n={}){let i=n.canvas||new OffscreenCanvas(1,1),l=n.scale||1,o=u;if(i.width=e*l,i.height=t*l,(u=i.getContext("2d")).scale(l,l),Array.isArray(a)){let e=0,t=0;for(let n of(u.imageSmoothingEnabled=!1,a)){for(let a of n)" "!==a&&"."!==a&&T.rectfill(e,t,1,1,parseInt(a,16)),e++;t++,e=0}}else a(u);return u=o,i.transferToImageBitmap()},ctx:e=>(e&&(u=e),u),push:()=>u.save(),pop:()=>u.restore(),translate:(e,t)=>u.translate(~~e,~~t),scale:(e,t)=>u.scale(e,t||e),rotate:e=>u.rotate(e),alpha(e){u.globalAlpha=T.clamp(e,0,1)},path:e=>new Path2D(e),fill(e,t){u.fillStyle=E[~~e%E.length],t?u.fill(t):u.fill()},stroke(e,t){u.strokeStyle=E[~~e%E.length],t?u.stroke(t):u.stroke()},clip(e){u.clip(e)},sfx:(e,t=0,n=1)=>!(a.zzfxV<=0)&&(!navigator.userActivation||!!navigator.userActivation.hasBeenActive)&&(e=e||z,(0!==t||1!==n)&&((e=e.slice())[0]=n*(e[0]||1),e[10]=~~e[10]+t),s.apply(0,e),e),volume(e){a.zzfxV=e},canvas:()=>d,use(e,t={}){f?S(e,t):c.push([e,t])},listen:(e,t)=>(P[e=e.toLowerCase()]=P[e]||new Set,P[e].add(t),()=>P&&P[e].delete(t)),emit(e,t,a,n,i){f&&(L("before:"+(e=e.toLowerCase()),t,a,n,i),L(e,t,a,n,i),L("after:"+e,t,a,n,i))},pal(t=e){E=t},def(e,n){T[e]=n,t.global&&(a[e]=n)},timescale(e){g=e},framerate(e){v=1/~~e},stat(e){let n={index:e,value:[t,f,b,p,P,E,z,g,a.zzfxV||1,k,y,x][e]};return T.emit("stat",n),n.value},quit(){for(let e of(cancelAnimationFrame(b),b=0,T.emit("quit"),P={},o))e();if(t.global){for(let e in T)delete a[e];delete a.ENGINE}f=!1}};for(let e of"PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,trunc,min,max,pow,sqrt,sign,exp".split(","))T[e]=n[e];function C(){let e=t.loop?t.loop:a;for(let t of"init,update,draw,tap,untap,tapping,tapped,resized".split(","))e[t]&&T.listen(t,e[t]);for(let[e,t]of c)S(e,t);if(t.autoscale&&r(a,"resize",A),t.tapEvents){let e=(e,t)=>[(e-d.offsetLeft)/p,(t-d.offsetTop)/p],t=new Map,n=(e,a,n)=>{let i={x:a,y:n,startX:a,startY:n,ts:performance.now()};return t.set(e,i),i},i=(e,a,i)=>{let l=t.get(e)||n(e);l.x=a,l.y=i},l=e=>e&&performance.now()-e.ts<=300,o=e=>e.preventDefault(),s=!1;r(d,"mousedown",t=>{if(0===t.button){o(t);let[a,i]=e(t.pageX,t.pageY);T.emit("tap",a,i,0),n(0,a,i),s=!0}}),r(d,"mouseup",a=>{if(0===a.button){o(a);let n=t.get(0),[i,r]=e(a.pageX,a.pageY);l(n)&&T.emit("tapped",n.startX,n.startY,0),T.emit("untap",i,r,0),t.delete(0),s=!1}}),r(d,"mousemove",t=>{o(t);let[a,n]=e(t.pageX,t.pageY);T.def("MX",a),T.def("MY",n),s&&(T.emit("tapping",a,n,0),i(0,a,n))}),r(d,"touchstart",t=>{for(let a of(o(t),t.changedTouches)){let[t,i]=e(a.pageX,a.pageY);T.emit("tap",t,i,a.identifier+1),n(a.identifier+1,t,i)}}),r(d,"touchmove",t=>{for(let a of(o(t),t.changedTouches)){let[t,n]=e(a.pageX,a.pageY);T.emit("tapping",t,n,a.identifier+1),i(a.identifier+1,t,n)}});let f=e=>{o(e);let a=[];if(e.targetTouches.length>0)for(let t of e.targetTouches)a.push(t.identifier+1);for(let[e,n]of t)a.includes(e)||(l(n)&&T.emit("tapped",n.startX,n.startY,e),T.emit("untap",n.x,n.y,e),t.delete(e))};r(d,"touchend",f),r(d,"touchcancel",f),r(a,"blur",()=>{for(let[e,a]of(s=!1,t))T.emit("untap",a.x,a.y,e),t.delete(e)})}if(t.keyboardEvents){let e=new Set,t=new Set,n=(e,t="")=>(t=t.toLowerCase())?e.has("space"===t?" ":t):e.size>0;r(a,"keydown",a=>{let n=a.key.toLowerCase();e.has(n)||(e.add(n),t.add(n))}),r(a,"keyup",t=>{e.delete(t.key.toLowerCase())}),r(a,"blur",()=>e.clear()),T.listen("after:update",()=>t.clear()),T.def("iskeydown",t=>n(e,t)),T.def("iskeypressed",e=>n(t,e))}f=!0,T.emit("init",T),m=performance.now(),b=l(I)}function I(e){let a=0;if(t.animate){for(w+=n.min(.1,(e-m)/1e3),m=e;w>=v;)a++,T.emit("update",v*g,a),T.def("T",T.T+v*g),w-=v;b&&(b=l(I))}else a=1;a&&(T.textalign("start","top"),T.emit("draw"))}function A(){let e=t.width||a.innerWidth,i=t.height||t.width||a.innerHeight;T.def("W",e),T.def("H",i),d.width=e,d.height=i,t.autoscale&&(d.style.display||(d.style.display="block",d.style.margin="auto"),p=n.min(a.innerWidth/e,a.innerHeight/i),p=(t.pixelart?~~p:p)||1,d.style.width=e*p+"px",d.style.height=i*p+"px"),(!t.antialias||t.pixelart)&&(u.imageSmoothingEnabled=!1,d.style.imageRendering="pixelated"),T.emit("resized",p),T.cls(0),t.animate||l(I)}function L(e,t,a,n,i){if(P[e])for(let l of P[e])l(t,a,n,i)}function S(e,t){let a=e(T,t);for(let e in a)T.def(e,a[e])}if(t.global){if(a.ENGINE)throw Error("only one global litecanvas is allowed");Object.assign(a,T),a.ENGINE=T}return u=(d=(d="string"==typeof t.canvas?document.querySelector(t.canvas):t.canvas)||document.createElement("canvas")).getContext("2d"),r(d,"click",()=>a.focus()),d.style="",A(),d.parentNode||document.body.appendChild(d),"loading"===document.readyState?r(a,"DOMContentLoaded",()=>l(C)):l(C),T}})();
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litecanvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and P5/Processing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Luiz Bills <luizbills@pm.me>",
|
|
7
7
|
"contributors": [],
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@litecanvas/jsdom-extras": "^
|
|
10
|
-
"@swc/core": "^1.12.
|
|
9
|
+
"@litecanvas/jsdom-extras": "^2.0.0",
|
|
10
|
+
"@swc/core": "^1.12.9",
|
|
11
11
|
"@types/jsdom": "^21.1.7",
|
|
12
12
|
"ava": "^6.4.0",
|
|
13
13
|
"esbuild": "^0.25.5",
|
|
14
|
+
"genversion": "^3.2.0",
|
|
14
15
|
"gzip-size": "^7.0.0",
|
|
15
16
|
"jsdom": "^26.1.0",
|
|
16
17
|
"prettier": "^3.6.2",
|
|
18
|
+
"sinon": "^21.0.0",
|
|
17
19
|
"tap-min": "^3.0.0"
|
|
18
20
|
},
|
|
19
21
|
"homepage": "https://litecanvas.github.io/about.html",
|
|
@@ -28,13 +30,14 @@
|
|
|
28
30
|
"main": "src/index.js",
|
|
29
31
|
"types": "types/index.d.ts",
|
|
30
32
|
"scripts": {
|
|
31
|
-
"test": "ava --tap | tap-min",
|
|
33
|
+
"test": "ava --timeout=1s --fast-fail --tap | tap-min",
|
|
32
34
|
"test:watch": "ava --watch",
|
|
33
35
|
"dev": "esbuild src/web.js --bundle --watch --outfile=dist/dist.dev.js --servedir=.",
|
|
34
|
-
"build": "node script/build.js",
|
|
36
|
+
"build": "npm run genversion && node script/build.js",
|
|
35
37
|
"gzip-size": "gzip -c dist/dist.min.js | wc -c | xargs printf \" Gzip size: %s bytes\n\"",
|
|
36
38
|
"format": "prettier -w src/* samples/* types/* script/* types/*",
|
|
37
39
|
"check-types": "npx ts types/*",
|
|
40
|
+
"genversion": "genversion --es6 --semi version.js",
|
|
38
41
|
"prepare": "npm run build",
|
|
39
42
|
"prepublishOnly": "npm test"
|
|
40
43
|
},
|