Skip to content

Commit 385d290

Browse files
authored
Merge pull request #203 from litecanvas/patch
Patch
2 parents b12cbb3 + c17c216 commit 385d290

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

bun.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"creative coding"
3232
],
3333
"devDependencies": {
34-
"@litecanvas/jsdom-extras": "^2.0.0",
34+
"@litecanvas/jsdom-extras": "^2.0.1",
3535
"@size-limit/preset-small-lib": "^11.2.0",
36-
"@swc/core": "^1.12.11",
36+
"@swc/core": "^1.13.0",
3737
"@types/jsdom": "^21.1.7",
3838
"ava": "^6.4.1",
3939
"esbuild": "^0.25.6",

src/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export default function litecanvas(settings = {}) {
3333
height: null,
3434
autoscale: true,
3535
pixelart: false,
36-
antialias: false,
3736
canvas: null,
3837
global: true,
3938
loop: null,
@@ -945,7 +944,7 @@ export default function litecanvas(settings = {}) {
945944
DEV: assert(isNumber(volumeFactor), '[litecanvas] sfx() 3rd param must be a number')
946945

947946
if (
948-
root.zzfxV <= 0 ||
947+
!root.zzfxV ||
949948
(navigator.userActivation && !navigator.userActivation.hasBeenActive)
950949
) {
951950
return false
@@ -972,7 +971,10 @@ export default function litecanvas(settings = {}) {
972971
* @param {number} value
973972
*/
974973
volume(value) {
975-
DEV: assert(isNumber(value), '[litecanvas] volume() 1st param must be a number')
974+
DEV: assert(
975+
isNumber(value) && value >= 0,
976+
'[litecanvas] volume() 1st param must be a positive number or zero'
977+
)
976978

977979
root.zzfxV = value
978980
},
@@ -1564,7 +1566,7 @@ export default function litecanvas(settings = {}) {
15641566

15651567
_ctx = _canvas.getContext('2d')
15661568

1567-
on(_canvas, 'click', () => root.focus())
1569+
on(_canvas, 'click', () => focus())
15681570

15691571
/** @ts-ignore */
15701572
_canvas.style = ''
@@ -1592,8 +1594,8 @@ export default function litecanvas(settings = {}) {
15921594
'[litecanvas] litecanvas() option "width" is required when the option "height" is defined'
15931595
)
15941596

1595-
const width = settings.width || root.innerWidth,
1596-
height = settings.height || settings.width || root.innerHeight
1597+
const width = settings.width > 0 ? settings.width : innerWidth,
1598+
height = settings.width > 0 ? settings.height || settings.width : innerHeight
15971599

15981600
instance.def('W', width)
15991601
instance.def('H', height)
@@ -1608,29 +1610,30 @@ export default function litecanvas(settings = {}) {
16081610
_canvas.style.margin = 'auto'
16091611
}
16101612

1611-
_scale = math.min(root.innerWidth / width, root.innerHeight / height)
1613+
_scale = math.min(innerWidth / width, innerHeight / height)
16121614
_scale = maxScale > 1 && _scale > maxScale ? maxScale : _scale
1613-
_scale = (settings.pixelart ? ~~_scale : _scale) || 1
16141615

16151616
_canvas.style.width = width * _scale + 'px'
16161617
_canvas.style.height = height * _scale + 'px'
16171618
}
16181619

1619-
// restore canvas image rendering properties
1620-
if (!settings.antialias || settings.pixelart) {
1620+
// set canvas image rendering properties
1621+
if (settings.pixelart) {
16211622
_ctx.imageSmoothingEnabled = false
16221623
_canvas.style.imageRendering = 'pixelated'
16231624
}
16241625

1625-
// reset the default text align and baseline
1626+
// set the default text align and baseline
16261627
instance.textalign('start', 'top')
16271628

16281629
// trigger "resized" event
1630+
// note: not triggered before the "init" event
16291631
instance.emit('resized', _scale)
16301632

1633+
// paint a temporary background
16311634
instance.cls(0)
16321635

1633-
// force redraw
1636+
// force redraw when the canvas is not animated
16341637
if (!settings.animate) {
16351638
raf(drawFrame)
16361639
}

types/types.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,19 +594,18 @@ type LitecanvasOptions = {
594594
canvas?: HTMLCanvasElement | string
595595
/**
596596
* If `true` (default) scales the canvas to fill the screen, but preserving the aspect ratio.
597-
* Instead of `true`, you can pass a number to limit the maximum scale factor of the canvas.
597+
* Instead of `true`, you can pass a number to determine the maximum scale.
598598
*
599599
* Note: Only works if the option "width" was specified.
600600
*/
601601
autoscale?: boolean | number
602602
/**
603603
* If `true`, the pixel art images won't look blurry.
604+
* Also, disables canvas built-in antialias.
605+
*
606+
* Default: `false`
604607
*/
605608
pixelart?: boolean
606-
/**
607-
* If `false` (default), disable the canvas antialias.
608-
*/
609-
antialias?: boolean
610609
/**
611610
* If `true` (default), all methods and properties of the engine will be exposed to the global scope (window).
612611
*/

0 commit comments

Comments
 (0)