litecanvas 0.302.0 → 0.303.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 +2 -2
- package/dist/dist.js +1 -1
- package/dist/dist.min.js +1 -1
- package/package.json +8 -8
- package/src/index.js +1 -1
- package/src/version.js +1 -1
- package/types/global.d.ts +0 -8
- package/types/types.d.ts +0 -8
package/dist/dist.dev.js
CHANGED
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
var assert = (condition, message = "Assertion failed") => {
|
|
116
116
|
if (!condition) throw new Error("[Litecanvas] " + message);
|
|
117
117
|
};
|
|
118
|
-
var version = "0.
|
|
118
|
+
var version = "0.303.0";
|
|
119
119
|
function litecanvas(settings = {}) {
|
|
120
120
|
const root = window,
|
|
121
121
|
math = Math,
|
|
@@ -935,7 +935,7 @@
|
|
|
935
935
|
},
|
|
936
936
|
};
|
|
937
937
|
const mathProps =
|
|
938
|
-
"PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,
|
|
938
|
+
"PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,min,max,pow,sqrt,sign";
|
|
939
939
|
for (const k of mathProps.split(",")) {
|
|
940
940
|
instance[k] = math[k];
|
|
941
941
|
}
|
package/dist/dist.js
CHANGED
|
@@ -531,7 +531,7 @@
|
|
|
531
531
|
},
|
|
532
532
|
};
|
|
533
533
|
const mathProps =
|
|
534
|
-
"PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,
|
|
534
|
+
"PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,min,max,pow,sqrt,sign";
|
|
535
535
|
for (const k of mathProps.split(",")) {
|
|
536
536
|
instance[k] = math[k];
|
|
537
537
|
}
|
package/dist/dist.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e=["#211e20","#555568","#a0a08b","#e9efec"];window.litecanvas=function(t={}){let a,l=window,n=Math,i=performance,o=2*n.PI,r=requestAnimationFrame,s=[],f=(e,t,a)=>{e.addEventListener(t,a,!1),s.push(()=>e.removeEventListener(t,a,!1))},
|
|
1
|
+
(()=>{var e=["#211e20","#555568","#a0a08b","#e9efec"];window.litecanvas=function(t={}){let a,l=window,n=Math,i=performance,o=2*n.PI,r=requestAnimationFrame,s=[],f=(e,t,a)=>{e.addEventListener(t,a,!1),s.push(()=>e.removeEventListener(t,a,!1))},d=(l.zzfxX=new AudioContext,l.zzfxV=1,(e=1,t=.05,a=220,l=0,n=0,i=.1,o=0,r=1,s=0,f=0,d=0,c=0,u=0,p=0,h=0,m=0,g=0,w=1,v=0,x=0,y=0)=>{let b=Math,z=2*b.PI,k=s*=500*z/44100/44100,E=a*=(1-t+2*t*b.random(t=[]))*z/44100,T=0,C=0,P=0,I=1,D=0,L=0,S=0,A=y<0?-1:1,M=z*A*y*2/44100,N=b.cos(M),W=b.sin,X=W(M)/4,H=1+X,q=-2*N/H,B=(1-X)/H,V=(1+A*N)/2/H,O=-(A+N)/H,G=0,R=0,Y=0,$=0;for(l=44100*l+9,v*=44100,n*=44100,i*=44100,g*=44100,f*=500*z/85766121e6,h*=z/44100,d*=z/44100,c*=44100,u=44100*u|0,e*=.3*zzfxV,A=l+v+n+i+g|0;P<A;t[P++]=S*e)++L%(100*m|0)||(S=o?1<o?2<o?3<o?W(T*T):b.max(b.min(b.tan(T),1),-1):1-(2*T/z%2+2)%2:1-4*b.abs(b.round(T/z)-T/z):W(T),S=(u?1-x+x*W(z*P/u):1)*(S<0?-1:1)*b.abs(S)**r*(P<l?P/l:P<l+v?1-(P-l)/v*(1-w):P<l+v+n?w:P<A-g?(A-P-g)/i*w:0),S=g?S/2+(g>P?0:(P<A-g?1:(A-P)/g)*t[P-g|0]/2/e):S,y&&(S=$=V*G+O*(G=R)+V*(R=S)-B*Y-q*(Y=$))),T+=(M=(a+=s+=f)*b.cos(h*C++))+M*p*W(P**5),I&&++I>c&&(a+=d,E+=d,I=0),!u||++D%u||(a=E,s=k,I=I||1);(e=zzfxX.createBuffer(1,A,44100)).getChannelData(0).set(t),(a=zzfxX.createBufferSource()).buffer=e,a.connect(zzfxX.destination),a.start()}),c=(t=Object.assign({width:null,height:null,autoscale:!0,canvas:null,global:!0,loop:null,tapEvents:!0,keyboardEvents:!0},t)).loop,u,p,h,m=1,g,w=.5,v=1,x,y=1e3/60,b,z=0,k=3,E="sans-serif",T=20,C=1.2,P=Date.now(),I=e,D=e,L=[],S=[.5,0,1750,,,.3,1,,,,600,.1],A={},M={W:0,H:0,T:0,MX:-1,MY:-1,TAU:o,lerp:(e,t,a)=>e+a*(t-e),deg2rad:e=>n.PI/180*e,rad2deg:e=>180/n.PI*e,mod:(e,t)=>(e%t+t)%t||0,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,dist:(e,t,a,l)=>n.hypot(a-e,l-t),wrap:(e,t,a)=>e-(a-t)*n.floor((e-t)/(a-t)),map(e,t,a,l,n,i){let o=(e-t)/(a-t)*(n-l)+l;return i?M.clamp(o,l,n):o},norm:(e,t,a)=>M.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)=>~~M.rand(e,t+1),rseed(e){P=~~e},cls(e){null==e?g.clearRect(0,0,M.W,M.H):M.rectfill(0,0,M.W,M.H,e)},rect(e,t,a,l,n,i){g.beginPath(),g[i?"roundRect":"rect"](~~e-w,~~t-w,~~a+2*w,~~l+2*w,i),M.stroke(n)},rectfill(e,t,a,l,n,i){g.beginPath(),g[i?"roundRect":"rect"](~~e,~~t,~~a,~~l,i),M.fill(n)},oval(e,t,a,l,n){g.beginPath(),g.ellipse(~~e,~~t,~~a,~~l,0,0,o),M.stroke(n)},ovalfill(e,t,a,l,n){g.beginPath(),g.ellipse(~~e,~~t,~~a,~~l,0,0,o),M.fill(n)},circ(e,t,a,l){M.oval(e,t,a,a,l)},circfill(e,t,a,l){M.ovalfill(e,t,a,a,l)},shape(e){g.beginPath();for(let t=0;t<e.length;t+=2)t?g.lineTo(~~e[t],~~e[t+1]):g.moveTo(~~e[t],~~e[t+1]);g.lineTo(~~e[0],~~e[1])},line(e,t,a,l,n){g.beginPath();let i=w&&~~e==~~a?.5:0,o=w&&~~t==~~l?.5:0;g.moveTo(~~e+i,~~t+o),g.lineTo(~~a+i,~~l+o),M.stroke(n)},linewidth(e){g.lineWidth=~~e,w=~~e%2?.5:0},linedash(e,t=0){g.setLineDash(e),g.lineDashOffset=t},text(e,t,a,l=k,n="normal"){g.font=`${n} ${T}px ${E}`,g.fillStyle=q(l);let i=(""+a).split("\n");for(let a=0;a<i.length;a++)g.fillText(i[a],~~e,~~t+T*C*a)},textgap(e){C=e},textfont(e){E=e},textsize(e){T=e},textalign(e,t){e&&(g.textAlign=e),t&&(g.textBaseline=t)},image(e,t,a){g.drawImage(a,~~e,~~t)},spr(e,t,a){let l=a.replace(/[^\w.\n]/g,"").split("\n").filter(e=>e);for(let a=0;a<l.length;a++)for(let n=0;n<l[a].length;n++)"."!==l[a][n]&&M.rectfill(e+n,t+a,1,1,parseInt(l[a][n],36)||0)},paint(e,t,a,l={}){let n=l.canvas||new OffscreenCanvas(1,1),i=l.scale||1,o=g;return n.width=e*i,n.height=t*i,(g=n.getContext("2d")).scale(i,i),a(g),g=o,n.transferToImageBitmap()},ctx:e=>(e&&(g=e),g),push(e=0,t=e,a=0,l=1,n=l){g.save(),M.translate(e,t),M.rotate(a),M.scale(l,n)},pop(){g.restore()},translate(e,t){g.translate(~~e,~~t)},scale(e,t=e){g.scale(e,t)},rotate(e){g.rotate(e)},alpha(e){g.globalAlpha=M.clamp(e,0,1)},fill(e){g.fillStyle=q(e),g.fill()},stroke(e){g.strokeStyle=q(e),g.stroke()},clip(e){g.beginPath(),e(g),g.clip()},sfx:(e,t,a)=>!!l.zzfxV&&(!navigator.userActivation||!!navigator.userActivation.hasBeenActive)&&(e||=S,(t||a>=0)&&((e=e.slice())[0]=a*(e[0]||1),e[10]=~~e[10]+t),d.apply(0,e),e),volume(e){l.zzfxV=e},canvas:()=>h,use(e,t={}){var a=e,l=t;let n=a(M,l);for(let e in n)M.def(e,n[e])},resize(e,a=e,l){t.width=e,t.height=a,t.autoscale=null==l?t.autoscale:l,X()},listen:(e,t)=>{A[e=e.toLowerCase()]=A[e]||new Set,A[e].add(t)},unlisten:(e,t)=>{A[e=e.toLowerCase()]&&A[e].delete(t)},emit:(e,t,a,n,i)=>(u&&(H("before:"+(e=e.toLowerCase()),t,a,n,i),c||l[e]===M[e]||"function"!=typeof l[e]||l[e](t,a,n,i),H(e,t,a,n,i),H("after:"+e,t,a,n,i)),t),pal(e,t=3){null==e?I=D:(D=I,I=e),L=[],k=t,M.emit("pal",I,k)},palc(e,t){null==e?L=[]:L[e]=t},def(e,a){M[e]=a,t.global&&(l[e]=a)},timescale(e){v=e},framerate(e){y=1e3/~~e},stat:e=>[t,u,y/1e3,m,A,I,S,v,l.zzfxV,P,T,E,L,C][e],ispaused:()=>p,pause(){p||(p=!0,z=~~cancelAnimationFrame(z),M.emit("paused"))},resume(){u&&p&&(N(),p=!1,M.emit("resumed"))},quit(){for(let e of(M.emit("quit"),M.pause(),u=!1,A={},s))e();if(t.global){for(let e in M)delete l[e];delete l.ENGINE}}};for(let e of"PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,min,max,pow,sqrt,sign".split(","))M[e]=n[e];function N(){z||(b=0,x=i.now(),z=r(W))}function W(){z=r(W);let e=i.now(),t=0,a=e-x;for(x=e,b+=a<100?a:y;b>=y;){t++,b-=y;let e=y/1e3*v;M.emit("update",e,t),M.def("T",M.T+e)}t&&(M.emit("draw",g),t>1&&(b=0))}function X(){let e=t.width>0?t.width:innerWidth,a=t.width>0?t.height||t.width:innerHeight;if(M.def("W",e),M.def("H",a),h.width=e,h.height=a,h.style="image-rendering:pixelated",t.autoscale){let l=+t.autoscale;h.style.display||(h.style.display="block",h.style.margin="auto"),m=n.min(innerWidth/e,innerHeight/a),m=l>1&&m>l?l:m,h.style.width=e*m+"px",h.style.height=a*m+"px"}g.imageSmoothingEnabled=!1,M.textalign("start","top"),M.emit("resized",m)}function H(e,t,a,l,n){if(A[e])for(let i of A[e])i(t,a,l,n)}function q(e){return I[~~(L[e]??e)%I.length]}if(t.global){if(l.ENGINE)throw Error("only one global litecanvas is allowed");Object.assign(l,M),l.ENGINE=M}if(a=document,g=(h=(h="string"==typeof t.canvas?a.querySelector(t.canvas):t.canvas)||a.createElement("canvas")).getContext("2d"),f(h,"click",()=>focus()),h.parentNode||a.body.appendChild(h),h.oncontextmenu=()=>!1,X(),c)for(let e in c)c[e]&&M.listen(e,c[e]);return r(function(){if(t.autoscale&&f(l,"resize",X),t.tapEvents){let e=e=>[(e.pageX-h.offsetLeft)/m,(e.pageY-h.offsetTop)/m],t=new Map,a=(e,a,l)=>{let n={x:a,y:l,xi:a,yi:l,t:i.now()};return t.set(e,n),n},n=(e,l,n)=>{let i=t.get(e)||a(e);i.x=l,i.y=n},o=e=>e&&i.now()-e.t<=300,r=!1;f(h,"mousedown",t=>{if(!t.button){t.preventDefault();let[l,n]=e(t);M.emit("tap",l,n,0),a(0,l,n),r=!0}}),f(h,"mouseup",a=>{if(!a.button){a.preventDefault();let l=t.get(0),[n,i]=e(a);o(l)&&M.emit("tapped",l.xi,l.yi,0),M.emit("untap",n,i,0),t.delete(0),r=!1}}),f(l,"mousemove",t=>{t.preventDefault();let[a,l]=e(t);M.def("MX",a),M.def("MY",l),r&&(M.emit("tapping",a,l,0),n(0,a,l))}),f(h,"touchstart",t=>{for(let l of(t.preventDefault(),t.changedTouches)){let[t,n]=e(l);M.emit("tap",t,n,l.identifier+1),a(l.identifier+1,t,n)}}),f(h,"touchmove",t=>{for(let a of(t.preventDefault(),t.changedTouches)){let[t,l]=e(a);M.emit("tapping",t,l,a.identifier+1),n(a.identifier+1,t,l)}});let s=e=>{e.preventDefault();let a=[];for(let t of e.targetTouches)a.push(t.identifier+1);for(let[e,l]of t)a.includes(e)||(o(l)&&M.emit("tapped",l.xi,l.yi,e),M.emit("untap",l.x,l.y,e),t.delete(e))};f(h,"touchend",s),f(h,"touchcancel",s),f(l,"blur",()=>{for(let[e,a]of(r=!1,t))M.emit("untap",a.x,a.y,e),t.delete(e)})}if(t.keyboardEvents){let e=new Set,t=new Set,a=(e,t="")=>(t=t.toLowerCase())?e.has("space"===t?" ":t):e.size>0,n="";f(l,"keydown",a=>{let l=a.key.toLowerCase();e.has(l)||(e.add(l),t.add(l),n=" "===l?"space":l)}),f(l,"keyup",t=>{e.delete(t.key.toLowerCase())}),f(l,"blur",()=>e.clear()),M.listen("after:update",()=>t.clear()),M.def("iskeydown",t=>a(e,t)),M.def("iskeypressed",e=>a(t,e)),M.def("lastkey",()=>n)}u=!0,M.emit("init",M),p||N()}),M}})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litecanvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.303.0",
|
|
4
4
|
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Luiz Bills <luizbills@pm.me>",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"creative coding"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@happy-dom/global-registrator": "^
|
|
36
|
-
"@size-limit/preset-small-lib": "^
|
|
37
|
-
"@swc/core": "^1.
|
|
35
|
+
"@happy-dom/global-registrator": "^21.0.1",
|
|
36
|
+
"@size-limit/preset-small-lib": "^14.2.0",
|
|
37
|
+
"@swc/core": "^1.16.18",
|
|
38
38
|
"ava": "^8.0.1",
|
|
39
|
-
"esbuild": "^0.28.
|
|
39
|
+
"esbuild": "^0.28.2",
|
|
40
40
|
"genversion": "^3.2.0",
|
|
41
41
|
"gzip-size": "^7.0.0",
|
|
42
|
-
"prettier": "^3.
|
|
43
|
-
"sinon": "^22.
|
|
44
|
-
"size-limit": "^
|
|
42
|
+
"prettier": "^3.9.10",
|
|
43
|
+
"sinon": "^22.1.0",
|
|
44
|
+
"size-limit": "^14.2.0",
|
|
45
45
|
"tap-min": "^3.0.0"
|
|
46
46
|
},
|
|
47
47
|
"trustedDependencies": [
|
package/src/index.js
CHANGED
|
@@ -1427,7 +1427,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1427
1427
|
}
|
|
1428
1428
|
|
|
1429
1429
|
// prettier-ignore
|
|
1430
|
-
const mathProps = 'PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,
|
|
1430
|
+
const mathProps = 'PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,min,max,pow,sqrt,sign'
|
|
1431
1431
|
for (const k of mathProps.split(',')) {
|
|
1432
1432
|
// import native Math functions
|
|
1433
1433
|
instance[k] = math[k]
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.303.0'
|
package/types/global.d.ts
CHANGED
|
@@ -162,10 +162,6 @@ declare global {
|
|
|
162
162
|
* Always rounds down and returns the largest integer less than or equal to a given number.
|
|
163
163
|
*/
|
|
164
164
|
function floor(n: number): number
|
|
165
|
-
/**
|
|
166
|
-
* Returns the integer part of a number by removing any fractional digits.
|
|
167
|
-
*/
|
|
168
|
-
function trunc(n: number): number
|
|
169
165
|
/**
|
|
170
166
|
* Returns the smallest of the numbers given as input parameters, or `Infinity` if there are no parameters.
|
|
171
167
|
*/
|
|
@@ -187,10 +183,6 @@ declare global {
|
|
|
187
183
|
* If the input is 0 or -0, it will be returned as-is.
|
|
188
184
|
*/
|
|
189
185
|
function sign(n: number): number
|
|
190
|
-
/**
|
|
191
|
-
* Returns the Euler's number raised to the power of a number.
|
|
192
|
-
*/
|
|
193
|
-
function exp(exponent: number): number
|
|
194
186
|
|
|
195
187
|
/** RNG API */
|
|
196
188
|
/**
|
package/types/types.d.ts
CHANGED
|
@@ -156,10 +156,6 @@ type LitecanvasInstance = {
|
|
|
156
156
|
* Always rounds down and returns the largest integer less than or equal to a given number.
|
|
157
157
|
*/
|
|
158
158
|
floor?(n: number): number
|
|
159
|
-
/**
|
|
160
|
-
* Returns the integer part of a number by removing any fractional digits.
|
|
161
|
-
*/
|
|
162
|
-
trunc?(n: number): number
|
|
163
159
|
/**
|
|
164
160
|
* Returns the smallest of the numbers given as input parameters, or `Infinity` if there are no parameters.
|
|
165
161
|
*/
|
|
@@ -181,10 +177,6 @@ type LitecanvasInstance = {
|
|
|
181
177
|
* If the input is 0 or -0, it will be returned as-is.
|
|
182
178
|
*/
|
|
183
179
|
sign?(n: number): number
|
|
184
|
-
/**
|
|
185
|
-
* Returns the Euler's number raised to the power of a number.
|
|
186
|
-
*/
|
|
187
|
-
exp?(exponent: number): number
|
|
188
180
|
|
|
189
181
|
/** RNG API */
|
|
190
182
|
/**
|