litecanvas 0.95.1 → 0.96.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/README.md +7 -7
- package/dist/dist.dev.js +25 -18
- package/dist/dist.js +17 -13
- package/dist/dist.min.js +1 -1
- package/package.json +1 -1
- package/src/index.js +25 -18
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ function draw() {
|
|
|
91
91
|
}
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
[Play with this code in the playground](https://litecanvas.js.org?c=
|
|
94
|
+
[Play with this code in the playground](https://litecanvas.js.org?c=eJx9U8tu2zAQvOsrBsghcitYtnMz4HvvLdD2SJFriTVNEuSqthH430tSduQEQQUI0GNmdnZ22bb4ziIwhFWIxKMHDwSyvbZUtS0MiWBxdIG2GJh93Lat0UxS2L8iLv%2FEpQt9Kzo38nLgo3lKIqxtH6sZVb9WSJdxzm%2FxCm01Nxi9EkwNVBCnBiy8J4VrU10XVa7Lg47Yj1aydhZhtBHOSoLgYrCjZNCmOtUbJsvWC0y1uh47rFCECNIZF%2FC0Qt0ZIQ%2BLApk%2B7vDyAfWC%2BjQk7xMqCKXHmGA%2F0WI9K5bGcNKKh3a9KlDv4vkG3GScJMsU8At1kn1H2CzuhEsifPtA%2BP0p4fpJLIpSxAxptDzElt0oB4pzIlOo9bnB5Z5LrjII21Oc2tBBGspGdGbcIZ2IaRhZYZh%2Fwu3Le1J9bPf82MrlZtOP05h6caQ0917LNJ735meb0ybUih9MHsWBHh3uhTEx5b%2BC12dKjz4FFUk6q%2Bb6X3fYJMQXKP7MRyCrKKSd%2BY%2BXvI1vSyRNrLt%2BUULL56BIRRmIpqSyt702ps5RNMVDc1uYZtqmws2aELdOCpHpzPV61SDfzz%2BET8fvchoo0PMjI8Oq6z8yIyTy)
|
|
95
95
|
|
|
96
96
|
https://github.com/user-attachments/assets/854ac6bd-724f-4da8-bb3c-bc04dba5d8c8
|
|
97
97
|
|
|
@@ -99,13 +99,13 @@ https://github.com/user-attachments/assets/854ac6bd-724f-4da8-bb3c-bc04dba5d8c8
|
|
|
99
99
|
|
|
100
100
|
Try some demos in the playground:
|
|
101
101
|
|
|
102
|
-
- [Pong](https://litecanvas.js.org?c=
|
|
103
|
-
- [Bouncing Ball](https://litecanvas.js.org?c=
|
|
104
|
-
- [Scroller](https://litecanvas.js.org?c=
|
|
105
|
-
- [3D projection](https://litecanvas.js.org?c=
|
|
106
|
-
- [Rendering Benchmark](https://litecanvas.js.org?c=
|
|
102
|
+
- [Pong](https://litecanvas.js.org?c=eJy1VV1y00gQftcpmidJWJYl2U5IIKFMyiEPgKk4YMLW1paQxvYUiqSSxiT8hCtwgn3bQ3AeLsAV6J7RzyjEKV42rozdPT39%2B803CROQh%2FECDsAPPMcA%2FEP5hORxI74h0Wu3z1EeDSs5ZqUgA7JTmndhkmg%2Fz9ufc%2F6Jaa5JNUlXCelqb7yQ0RrpvJXKnLEYxaBOpYyyQjub8CUrURwqUbArQQErWxEWQh5fhknJDCPhgkVh%2BiEsrc%2FS4pLHYr0Pw7oPa8ZXa7EPoweouLYNYzCAo00psgt4%2B%2Bn4DZTZJo1LWGYFiDUvYRVeMLLJCyYEZ0Wfr1LMz4iytBTwZPbqxdEUw%2F%2FlgAM%2BG9KX6w1pCVDhQEAaB%2FZGXrVRf1zccXeU%2Fc7fD7fHmJ9NTs8ohOeOHewKjLFT8tgIl6EeZbzrVZHlUgXyRne5fzJ59uyf2fHx%2FOh0On1BcXx36MtyxhjAcz2KSnFw2ZXRpNTfc%2Fdw3aGVPp7r%2B%2FWvQJ6T60iuPlVoLDdpJHiWAk%2B5sGz43AIL4y4GQYsulE8GAfThBAYw6kyeTFHpB8a15lKEec5i68qBj7VjvgTrXoWQWtcFjSg2rFUvryzZa7tRYcM2RSrF6861%2BPrVusLk5CUbQGB3UtnkcSiYFYvbE1FOAQciuMBbUkYFY%2BnjxrIC%2FAHeAN2YgAjZB1Y8NqQpqi5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CzkfzJJKNhGhCheMW4G%2FXt7%2BuLu4ubvyYZjOGc0fwOQF42Wx%2BRv%2FIIpk102XXoGoVQcMJGjGC1H6DN3TV1RqcFbqs6OkzzuER7Uy1rmuAYyqHoR966CgcKPkIxsORU0FBEXyBTwcZxiA4PHTXpkH6WQCYY5hVFx2YjYqOjJg2bPJtG93D%2B4z68cJDcT6QrEuVPMoTxFGX3iCsvhRQJ%2FBQ6A68f4EOyl9lSvtUPvyMgEMONBQVKLYuuVFBswblb8vIO6PJg%2Fl%2F6vec8PyWMBKJlDv3%2FfWN%2B%2FnZqMCyMrjXJaQjqBQ4Mssh78XSG8Ha%2FKkTCvtumLLYLpgujeaMOX4qmxNa65zBSkNiQoolokmzzAnc7fbDCZ3u67%2BNbPxHg3Ezk1AGq9Rzf4GOoJP8eGHI8kKWvwJluiS4gwLT%2F8oHkNmQxQt00IXBKMVLRFhGCkf5bkf5Lkf5pqNtVofm8PfMGdpN9t0h%2B1gMO5%2FVY7g7tvcH9QMxT%2FGYyKg96dRb23Ru2aN%2FASaYns8%3D)
|
|
107
107
|
|
|
108
|
-
_See other demos in [samples](samples) folder_
|
|
108
|
+
> _See other demos in [samples](/samples) folder_
|
|
109
109
|
|
|
110
110
|
## Inspirations
|
|
111
111
|
|
package/dist/dist.dev.js
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
// src/version.js
|
|
35
|
-
var version = "0.
|
|
35
|
+
var version = "0.96.0";
|
|
36
36
|
|
|
37
37
|
// src/index.js
|
|
38
38
|
function litecanvas(settings = {}) {
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
round: (n, precision = 0) => {
|
|
130
130
|
DEV: assert(isNumber(n), "[litecanvas] round() 1st param must be a number");
|
|
131
131
|
DEV: assert(
|
|
132
|
-
|
|
132
|
+
isNumber(precision) && precision >= 0,
|
|
133
133
|
"[litecanvas] round() 2nd param must be a positive number or zero"
|
|
134
134
|
);
|
|
135
135
|
if (!precision) {
|
|
@@ -515,15 +515,15 @@
|
|
|
515
515
|
instance.stroke(color);
|
|
516
516
|
},
|
|
517
517
|
/**
|
|
518
|
-
* Sets the thickness of lines
|
|
518
|
+
* Sets the thickness of the lines
|
|
519
519
|
*
|
|
520
520
|
* @param {number} value
|
|
521
521
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
|
|
522
522
|
*/
|
|
523
523
|
linewidth(value) {
|
|
524
524
|
DEV: assert(
|
|
525
|
-
isNumber(value) &&
|
|
526
|
-
"[litecanvas] linewidth() 1st param must be a positive number"
|
|
525
|
+
isNumber(value) && value >= 0,
|
|
526
|
+
"[litecanvas] linewidth() 1st param must be a positive number or zero"
|
|
527
527
|
);
|
|
528
528
|
_ctx.lineWidth = ~~value;
|
|
529
529
|
_outline_fix = 0 === ~~value % 2 ? 0 : 0.5;
|
|
@@ -702,23 +702,27 @@
|
|
|
702
702
|
*
|
|
703
703
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
|
|
704
704
|
*/
|
|
705
|
-
push
|
|
705
|
+
push() {
|
|
706
|
+
_ctx.save();
|
|
707
|
+
},
|
|
706
708
|
/**
|
|
707
709
|
* restores the drawing style settings and transformations
|
|
708
710
|
*
|
|
709
711
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
|
|
710
712
|
*/
|
|
711
|
-
pop
|
|
713
|
+
pop() {
|
|
714
|
+
_ctx.restore();
|
|
715
|
+
},
|
|
712
716
|
/**
|
|
713
717
|
* Adds a translation to the transformation matrix.
|
|
714
718
|
*
|
|
715
719
|
* @param {number} x
|
|
716
720
|
* @param {number} y
|
|
717
721
|
*/
|
|
718
|
-
translate
|
|
722
|
+
translate(x, y) {
|
|
719
723
|
DEV: assert(isNumber(x), "[litecanvas] translate() 1st param must be a number");
|
|
720
724
|
DEV: assert(isNumber(y), "[litecanvas] translate() 2nd param must be a number");
|
|
721
|
-
|
|
725
|
+
_ctx.translate(~~x, ~~y);
|
|
722
726
|
},
|
|
723
727
|
/**
|
|
724
728
|
* Adds a scaling transformation to the canvas units horizontally and/or vertically.
|
|
@@ -726,19 +730,19 @@
|
|
|
726
730
|
* @param {number} x
|
|
727
731
|
* @param {number} [y]
|
|
728
732
|
*/
|
|
729
|
-
scale
|
|
733
|
+
scale(x, y) {
|
|
730
734
|
DEV: assert(isNumber(x), "[litecanvas] scale() 1st param must be a number");
|
|
731
735
|
DEV: assert(null == y || isNumber(y), "[litecanvas] scale() 2nd param must be a number");
|
|
732
|
-
|
|
736
|
+
_ctx.scale(x, y || x);
|
|
733
737
|
},
|
|
734
738
|
/**
|
|
735
739
|
* Adds a rotation to the transformation matrix.
|
|
736
740
|
*
|
|
737
741
|
* @param {number} radians
|
|
738
742
|
*/
|
|
739
|
-
rotate
|
|
743
|
+
rotate(radians) {
|
|
740
744
|
DEV: assert(isNumber(radians), "[litecanvas] rotate() 1st param must be a number");
|
|
741
|
-
|
|
745
|
+
_ctx.rotate(radians);
|
|
742
746
|
},
|
|
743
747
|
/**
|
|
744
748
|
* Sets the alpha (opacity) value to apply when drawing new shapes and images
|
|
@@ -963,12 +967,15 @@
|
|
|
963
967
|
/**
|
|
964
968
|
* Returns information about that engine instance.
|
|
965
969
|
*
|
|
966
|
-
* @param {number}
|
|
970
|
+
* @param {number|string} index
|
|
967
971
|
* @returns {any}
|
|
968
972
|
*/
|
|
969
|
-
stat(
|
|
970
|
-
DEV: assert(
|
|
971
|
-
|
|
973
|
+
stat(index) {
|
|
974
|
+
DEV: assert(
|
|
975
|
+
isNumber(index) || "string" === typeof index,
|
|
976
|
+
"[litecanvas] stat() 1st param must be a number or string"
|
|
977
|
+
);
|
|
978
|
+
const internals = [
|
|
972
979
|
// 0
|
|
973
980
|
settings,
|
|
974
981
|
// 1
|
|
@@ -994,7 +1001,7 @@
|
|
|
994
1001
|
// 11
|
|
995
1002
|
_fontFamily
|
|
996
1003
|
];
|
|
997
|
-
const data = { index
|
|
1004
|
+
const data = { index, value: internals[index] };
|
|
998
1005
|
instance.emit("stat", data);
|
|
999
1006
|
return data.value;
|
|
1000
1007
|
},
|
package/dist/dist.js
CHANGED
|
@@ -342,7 +342,7 @@
|
|
|
342
342
|
instance.stroke(color);
|
|
343
343
|
},
|
|
344
344
|
/**
|
|
345
|
-
* Sets the thickness of lines
|
|
345
|
+
* Sets the thickness of the lines
|
|
346
346
|
*
|
|
347
347
|
* @param {number} value
|
|
348
348
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
|
|
@@ -473,21 +473,25 @@
|
|
|
473
473
|
*
|
|
474
474
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
|
|
475
475
|
*/
|
|
476
|
-
push
|
|
476
|
+
push() {
|
|
477
|
+
_ctx.save();
|
|
478
|
+
},
|
|
477
479
|
/**
|
|
478
480
|
* restores the drawing style settings and transformations
|
|
479
481
|
*
|
|
480
482
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
|
|
481
483
|
*/
|
|
482
|
-
pop
|
|
484
|
+
pop() {
|
|
485
|
+
_ctx.restore();
|
|
486
|
+
},
|
|
483
487
|
/**
|
|
484
488
|
* Adds a translation to the transformation matrix.
|
|
485
489
|
*
|
|
486
490
|
* @param {number} x
|
|
487
491
|
* @param {number} y
|
|
488
492
|
*/
|
|
489
|
-
translate
|
|
490
|
-
|
|
493
|
+
translate(x, y) {
|
|
494
|
+
_ctx.translate(~~x, ~~y);
|
|
491
495
|
},
|
|
492
496
|
/**
|
|
493
497
|
* Adds a scaling transformation to the canvas units horizontally and/or vertically.
|
|
@@ -495,16 +499,16 @@
|
|
|
495
499
|
* @param {number} x
|
|
496
500
|
* @param {number} [y]
|
|
497
501
|
*/
|
|
498
|
-
scale
|
|
499
|
-
|
|
502
|
+
scale(x, y) {
|
|
503
|
+
_ctx.scale(x, y || x);
|
|
500
504
|
},
|
|
501
505
|
/**
|
|
502
506
|
* Adds a rotation to the transformation matrix.
|
|
503
507
|
*
|
|
504
508
|
* @param {number} radians
|
|
505
509
|
*/
|
|
506
|
-
rotate
|
|
507
|
-
|
|
510
|
+
rotate(radians) {
|
|
511
|
+
_ctx.rotate(radians);
|
|
508
512
|
},
|
|
509
513
|
/**
|
|
510
514
|
* Sets the alpha (opacity) value to apply when drawing new shapes and images
|
|
@@ -668,11 +672,11 @@
|
|
|
668
672
|
/**
|
|
669
673
|
* Returns information about that engine instance.
|
|
670
674
|
*
|
|
671
|
-
* @param {number}
|
|
675
|
+
* @param {number|string} index
|
|
672
676
|
* @returns {any}
|
|
673
677
|
*/
|
|
674
|
-
stat(
|
|
675
|
-
const
|
|
678
|
+
stat(index) {
|
|
679
|
+
const internals = [
|
|
676
680
|
// 0
|
|
677
681
|
settings,
|
|
678
682
|
// 1
|
|
@@ -698,7 +702,7 @@
|
|
|
698
702
|
// 11
|
|
699
703
|
_fontFamily
|
|
700
704
|
];
|
|
701
|
-
const data = { index
|
|
705
|
+
const data = { index, value: internals[index] };
|
|
702
706
|
instance.emit("stat", data);
|
|
703
707
|
return data.value;
|
|
704
708
|
},
|
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,l=Math,i=2*l.PI,n=requestAnimationFrame,o=[],r=(e,t,a)=>{e.addEventListener(t,a,!1),o.push(()=>e.removeEventListener(t,a,!1))},s=e=>e.preventDefault(),f=e=>e.beginPath(),c=(e=>{let t=new AudioContext;return e.zzfxV=1,(a=1,l=.05,i=220,n=0,o=0,r=.1,s=0,f=1,c=0,d=0,u=0,p=0,h=0,m=0,g=0,w=0,v=0,x=1,y=0,b=0,k=0)=>{let E=Math,z=2*E.PI,T=c*=500*z/44100/44100,C=i*=(1-l+2*l*E.random(l=[]))*z/44100,I=0,A=0,L=0,S=1,D=0,M=0,N=0,P=k<0?-1:1,F=z*P*k*2/44100,q=E.cos(F),B=E.sin,H=B(F)/4,O=1+H,V=-2*q/O,W=(1-H)/O,R=(1+P*q)/2/O,G=-(P+q)/O,X=0,Y=0,$=0,j=0;for(n=44100*n+9,y*=44100,o*=44100,r*=44100,v*=44100,d*=500*z/85766121e6,g*=z/44100,u*=z/44100,p*=44100,h=44100*h|0,a*=.3*e.zzfxV,P=n+y+o+r+v|0;L<P;l[L++]=N*a)++M%(100*w|0)||(N=s?1<s?2<s?3<s?B(I*I):E.max(E.min(E.tan(I),1),-1):1-(2*I/z%2+2)%2:1-4*E.abs(E.round(I/z)-I/z):B(I),N=(h?1-b+b*B(z*L/h):1)*(N<0?-1:1)*E.abs(N)**f*(L<n?L/n:L<n+y?1-(L-n)/y*(1-x):L<n+y+o?x:L<P-v?(P-L-v)/r*x:0),N=v?N/2+(v>L?0:(L<P-v?1:(P-L)/v)*l[L-v|0]/2/a):N,k&&(N=j=R*X+G*(X=Y)+R*(Y=N)-W*$-V*($=j))),I+=(F=(i+=c+=d)*E.cos(g*A++))+F*m*B(L**5),S&&++S>p&&(i+=u,C+=u,S=0),!h||++D%h||(i=C,c=T,S=S||1);(a=t.createBuffer(1,P,44100)).getChannelData(0).set(l),(i=t.createBufferSource()).buffer=a,i.connect(t.destination),i.start()}})(a);t=Object.assign({width:null,height:null,autoscale:!0,pixelart:!0,canvas:null,global:!0,loop:null,tapEvents:!0,keyboardEvents:!0,animate:!0},t);let d=!1,u=[],p,h=1,m,g=.5,w=1,v,x=1e3/60,y,b,k="sans-serif",E=20,z=Date.now(),T=e,C=[.5,0,1750,,,.3,1,,,,600,.1],I={},A={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=>l.PI/180*e,rad2deg:e=>180/l.PI*e,round:(e,t=0)=>{if(!t)return l.round(e);let a=10**t;return l.round(e*a)/a},clamp:(e,t,a)=>e<t?t:e>a?a:e,wrap:(e,t,a)=>e-(a-t)*l.floor((e-t)/(a-t)),map(e,t,a,l,i,n){let o=(e-t)/(a-t)*(i-l)+l;return n?A.clamp(o,l,i):o},norm:(e,t,a)=>A.map(e,t,a,0,1),wave:(e,t,a,l=Math.sin)=>e+(l(a)+1)/2*(t-e),rand:(e=0,t=1)=>(z=(1664525*z+0x3c6ef35f)%0x100000000)/0x100000000*(t-e)+e,randi:(e=0,t=1)=>l.floor(A.rand(e,t+1)),rseed(e){z=~~e},cls(e){null==e?m.clearRect(0,0,m.canvas.width,m.canvas.height):A.rectfill(0,0,m.canvas.width,m.canvas.height,e)},rect(e,t,a,l,i,n){f(m),m[n?"roundRect":"rect"](~~e-g,~~t-g,~~a+2*g,~~l+2*g,n),A.stroke(i)},rectfill(e,t,a,l,i,n){f(m),m[n?"roundRect":"rect"](~~e,~~t,~~a,~~l,n),A.fill(i)},circ(e,t,a,l){f(m),m.arc(~~e,~~t,~~a,0,i),A.stroke(l)},circfill(e,t,a,l){f(m),m.arc(~~e,~~t,~~a,0,i),A.fill(l)},oval(e,t,a,l,n){f(m),m.ellipse(~~e,~~t,~~a,~~l,0,0,i),A.stroke(n)},ovalfill(e,t,a,l,n){f(m),m.ellipse(~~e,~~t,~~a,~~l,0,0,i),A.fill(n)},line(e,t,a,l,i){f(m);let n=.5*(0!==g&&~~e==~~a),o=.5*(0!==g&&~~t==~~l);m.moveTo(~~e+n,~~t+o),m.lineTo(~~a+n,~~l+o),A.stroke(i)},linewidth(e){m.lineWidth=~~e,g=.5*(0!=~~e%2)},linedash(e,t=0){m.setLineDash(e),m.lineDashOffset=t},text(e,t,a,l=3,i="normal"){m.font=`${i} ${E}px ${k}`,m.fillStyle=T[~~l%T.length],m.fillText(a,~~e,~~t)},textfont(e){k=e},textsize(e){E=e},textalign(e,t){e&&(m.textAlign=e),t&&(m.textBaseline=t)},image(e,t,a){m.drawImage(a,~~e,~~t)},paint(e,t,a,l={}){let i=l.canvas||new OffscreenCanvas(1,1),n=l.scale||1,o=m;if(i.width=e*n,i.height=t*n,(m=i.getContext("2d")).scale(n,n),Array.isArray(a)){let e=0,t=0;for(let l of(m.imageSmoothingEnabled=!1,a)){for(let a of l)" "!==a&&"."!==a&&A.rectfill(e,t,1,1,parseInt(a,16)),e++;t++,e=0}}else a(m);return m=o,i.transferToImageBitmap()},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)},alpha(e){m.globalAlpha=A.clamp(e,0,1)},fill(e){m.fillStyle=T[~~e%T.length],m.fill()},stroke(e){m.strokeStyle=T[~~e%T.length],m.stroke()},clip(e){f(m),e(m),m.clip()},sfx:(e,t=0,l=1)=>!!a.zzfxV&&(!navigator.userActivation||!!navigator.userActivation.hasBeenActive)&&(e=e||C,(0!==t||1!==l)&&((e=e.slice())[0]=l*(e[0]||1),e[10]=~~e[10]+t),c.apply(0,e),e),volume(e){a.zzfxV=e},canvas:()=>p,use(e,t={}){d?N(e,t):u.push([e,t])},listen:(e,t)=>(I[e=e.toLowerCase()]=I[e]||new Set,I[e].add(t),()=>I&&I[e].delete(t)),emit(e,t,a,l,i){d&&(M("before:"+(e=e.toLowerCase()),t,a,l,i),M(e,t,a,l,i),M("after:"+e,t,a,l,i))},pal(t=e){T=t},def(e,l){A[e]=l,t.global&&(a[e]=l)},timescale(e){w=e},framerate(e){x=1e3/~~e},stat(e){let l={index:e,value:[t,d,x/1e3,h,I,T,C,w,a.zzfxV,z,E,k][e]};return A.emit("stat",l),l.value},quit(){for(let e of(A.pause(),A.emit("quit"),I={},o))e();if(t.global){for(let e in A)delete a[e];delete a.ENGINE}d=!1},pause(){cancelAnimationFrame(b),b=0},resume(){d&&!b&&(y=x,v=Date.now(),b=n(S))},paused:()=>!b};for(let e of"PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,trunc,min,max,pow,sqrt,sign,exp".split(","))A[e]=l[e];function L(){let e=t.loop?t.loop:a;for(let t of"init,update,draw,tap,untap,tapping,tapped,resized".split(","))e[t]&&A.listen(t,e[t]);for(let[e,t]of u)N(e,t);if(t.autoscale&&r(a,"resize",D),t.tapEvents){let e=e=>[(e.pageX-p.offsetLeft)/h,(e.pageY-p.offsetTop)/h],t=new Map,l=(e,a,l)=>{let i={x:a,y:l,xi:a,yi:l,t:Date.now()};return t.set(e,i),i},i=(e,a,i)=>{let n=t.get(e)||l(e);n.x=a,n.y=i},n=e=>e&&Date.now()-e.t<=300,o=!1;r(p,"mousedown",t=>{if(0===t.button){s(t);let[a,i]=e(t);A.emit("tap",a,i,0),l(0,a,i),o=!0}}),r(p,"mouseup",a=>{if(0===a.button){s(a);let l=t.get(0),[i,r]=e(a);n(l)&&A.emit("tapped",l.xi,l.yi,0),A.emit("untap",i,r,0),t.delete(0),o=!1}}),r(a,"mousemove",t=>{s(t);let[a,l]=e(t);A.def("MX",a),A.def("MY",l),o&&(A.emit("tapping",a,l,0),i(0,a,l))}),r(p,"touchstart",t=>{for(let a of(s(t),t.changedTouches)){let[t,i]=e(a);A.emit("tap",t,i,a.identifier+1),l(a.identifier+1,t,i)}}),r(p,"touchmove",t=>{for(let a of(s(t),t.changedTouches)){let[t,l]=e(a);A.emit("tapping",t,l,a.identifier+1),i(a.identifier+1,t,l)}});let f=e=>{s(e);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)||(n(l)&&A.emit("tapped",l.xi,l.yi,e),A.emit("untap",l.x,l.y,e),t.delete(e))};r(p,"touchend",f),r(p,"touchcancel",f),r(a,"blur",()=>{for(let[e,a]of(o=!1,t))A.emit("untap",a.x,a.y,e),t.delete(e)})}if(t.keyboardEvents){let e=new Set,t=new Set,l=(e,t="")=>(t=t.toLowerCase())?e.has("space"===t?" ":t):e.size>0,i="";r(a,"keydown",a=>{let l=a.key.toLowerCase();e.has(l)||(e.add(l),t.add(l),i=" "===l?"space":l)}),r(a,"keyup",t=>{e.delete(t.key.toLowerCase())}),r(a,"blur",()=>e.clear()),A.listen("after:update",()=>t.clear()),A.def("iskeydown",t=>l(e,t)),A.def("iskeypressed",e=>l(t,e)),A.def("lastkey",()=>i)}d=!0,A.emit("init",A),A.resume()}function S(){if(!t.animate)return A.emit("draw",m);let e=Date.now(),a=0,l=e-v;for(v=e,y+=l<100?l:x;y>=x;){a++,y-=x;let e=x/1e3*w;A.emit("update",e,a),A.def("T",A.T+e)}a&&(A.emit("draw",m),a>1&&(y=0)),b=n(S)}function D(){let e=t.width>0?t.width:innerWidth,a=t.width>0?t.height||t.width:innerHeight;if(A.def("W",e),A.def("H",a),p.width=e,p.height=a,t.autoscale){let i=+t.autoscale;p.style.display||(p.style.display="block",p.style.margin="auto"),h=l.min(innerWidth/e,innerHeight/a),h=i>1&&h>i?i:h,p.style.width=e*h+"px",p.style.height=a*h+"px"}t.pixelart&&(m.imageSmoothingEnabled=!1,p.style.imageRendering="pixelated"),A.textalign("start","top"),A.emit("resized",h),t.animate||n(S)}function M(e,t,a,l,i){if(I[e])for(let n of I[e])n(t,a,l,i)}function N(e,t){let a=e(A,t);for(let e in a)A.def(e,a[e])}if(t.global){if(a.ENGINE)throw Error("only one global litecanvas is allowed");Object.assign(a,A),a.ENGINE=A}return m=(p=(p="string"==typeof t.canvas?document.querySelector(t.canvas):t.canvas)||document.createElement("canvas")).getContext("2d"),r(p,"click",()=>focus()),p.style="",D(),p.parentNode||document.body.appendChild(p),p.oncontextmenu=()=>!1,"loading"===document.readyState?r(a,"DOMContentLoaded",()=>n(L)):n(L),A}})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litecanvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.96.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>",
|
package/src/index.js
CHANGED
|
@@ -178,7 +178,7 @@ export default function litecanvas(settings = {}) {
|
|
|
178
178
|
round: (n, precision = 0) => {
|
|
179
179
|
DEV: assert(isNumber(n), '[litecanvas] round() 1st param must be a number')
|
|
180
180
|
DEV: assert(
|
|
181
|
-
|
|
181
|
+
isNumber(precision) && precision >= 0,
|
|
182
182
|
'[litecanvas] round() 2nd param must be a positive number or zero'
|
|
183
183
|
)
|
|
184
184
|
if (!precision) {
|
|
@@ -602,15 +602,15 @@ export default function litecanvas(settings = {}) {
|
|
|
602
602
|
},
|
|
603
603
|
|
|
604
604
|
/**
|
|
605
|
-
* Sets the thickness of lines
|
|
605
|
+
* Sets the thickness of the lines
|
|
606
606
|
*
|
|
607
607
|
* @param {number} value
|
|
608
608
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
|
|
609
609
|
*/
|
|
610
610
|
linewidth(value) {
|
|
611
611
|
DEV: assert(
|
|
612
|
-
isNumber(value) &&
|
|
613
|
-
'[litecanvas] linewidth() 1st param must be a positive number'
|
|
612
|
+
isNumber(value) && value >= 0,
|
|
613
|
+
'[litecanvas] linewidth() 1st param must be a positive number or zero'
|
|
614
614
|
)
|
|
615
615
|
|
|
616
616
|
_ctx.lineWidth = ~~value
|
|
@@ -820,14 +820,18 @@ export default function litecanvas(settings = {}) {
|
|
|
820
820
|
*
|
|
821
821
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
|
|
822
822
|
*/
|
|
823
|
-
push
|
|
823
|
+
push() {
|
|
824
|
+
_ctx.save()
|
|
825
|
+
},
|
|
824
826
|
|
|
825
827
|
/**
|
|
826
828
|
* restores the drawing style settings and transformations
|
|
827
829
|
*
|
|
828
830
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
|
|
829
831
|
*/
|
|
830
|
-
pop
|
|
832
|
+
pop() {
|
|
833
|
+
_ctx.restore()
|
|
834
|
+
},
|
|
831
835
|
|
|
832
836
|
/**
|
|
833
837
|
* Adds a translation to the transformation matrix.
|
|
@@ -835,11 +839,11 @@ export default function litecanvas(settings = {}) {
|
|
|
835
839
|
* @param {number} x
|
|
836
840
|
* @param {number} y
|
|
837
841
|
*/
|
|
838
|
-
translate
|
|
842
|
+
translate(x, y) {
|
|
839
843
|
DEV: assert(isNumber(x), '[litecanvas] translate() 1st param must be a number')
|
|
840
844
|
DEV: assert(isNumber(y), '[litecanvas] translate() 2nd param must be a number')
|
|
841
845
|
|
|
842
|
-
|
|
846
|
+
_ctx.translate(~~x, ~~y)
|
|
843
847
|
},
|
|
844
848
|
|
|
845
849
|
/**
|
|
@@ -848,11 +852,11 @@ export default function litecanvas(settings = {}) {
|
|
|
848
852
|
* @param {number} x
|
|
849
853
|
* @param {number} [y]
|
|
850
854
|
*/
|
|
851
|
-
scale
|
|
855
|
+
scale(x, y) {
|
|
852
856
|
DEV: assert(isNumber(x), '[litecanvas] scale() 1st param must be a number')
|
|
853
857
|
DEV: assert(null == y || isNumber(y), '[litecanvas] scale() 2nd param must be a number')
|
|
854
858
|
|
|
855
|
-
|
|
859
|
+
_ctx.scale(x, y || x)
|
|
856
860
|
},
|
|
857
861
|
|
|
858
862
|
/**
|
|
@@ -860,10 +864,10 @@ export default function litecanvas(settings = {}) {
|
|
|
860
864
|
*
|
|
861
865
|
* @param {number} radians
|
|
862
866
|
*/
|
|
863
|
-
rotate
|
|
867
|
+
rotate(radians) {
|
|
864
868
|
DEV: assert(isNumber(radians), '[litecanvas] rotate() 1st param must be a number')
|
|
865
869
|
|
|
866
|
-
|
|
870
|
+
_ctx.rotate(radians)
|
|
867
871
|
},
|
|
868
872
|
|
|
869
873
|
/**
|
|
@@ -1128,13 +1132,16 @@ export default function litecanvas(settings = {}) {
|
|
|
1128
1132
|
/**
|
|
1129
1133
|
* Returns information about that engine instance.
|
|
1130
1134
|
*
|
|
1131
|
-
* @param {number}
|
|
1135
|
+
* @param {number|string} index
|
|
1132
1136
|
* @returns {any}
|
|
1133
1137
|
*/
|
|
1134
|
-
stat(
|
|
1135
|
-
DEV: assert(
|
|
1138
|
+
stat(index) {
|
|
1139
|
+
DEV: assert(
|
|
1140
|
+
isNumber(index) || 'string' === typeof index,
|
|
1141
|
+
'[litecanvas] stat() 1st param must be a number or string'
|
|
1142
|
+
)
|
|
1136
1143
|
|
|
1137
|
-
const
|
|
1144
|
+
const internals = [
|
|
1138
1145
|
// 0
|
|
1139
1146
|
settings,
|
|
1140
1147
|
// 1
|
|
@@ -1161,9 +1168,9 @@ export default function litecanvas(settings = {}) {
|
|
|
1161
1168
|
_fontFamily,
|
|
1162
1169
|
]
|
|
1163
1170
|
|
|
1164
|
-
const data = { index
|
|
1171
|
+
const data = { index, value: internals[index] }
|
|
1165
1172
|
|
|
1166
|
-
// plugins can modify or create
|
|
1173
|
+
// plugins can modify or create new stats
|
|
1167
1174
|
instance.emit('stat', data)
|
|
1168
1175
|
|
|
1169
1176
|
return data.value
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.96.0'
|