diff --git a/bun.lock b/bun.lock index 1e8d826..8ab5752 100644 --- a/bun.lock +++ b/bun.lock @@ -92,7 +92,7 @@ "@isaacs/fs-minipass": ["@isaacs/fs-minipass@4.0.1", "", { "dependencies": { "minipass": "^7.0.4" } }, ""], - "@litecanvas/jsdom-extras": ["@litecanvas/jsdom-extras@2.0.0", "", { "dependencies": { "jsdom": "^26.1.0" }, "peerDependencies": { "litecanvas": "latest" } }, "sha512-RnTOzQkNuFCOCbOiiD5HgfsL/QiL4xdseb7zQNCgBxtzLGTLU3jYx8svWTI3OyJsxgo/eAzSMkfoCLjRb4yJuw=="], + "@litecanvas/jsdom-extras": ["@litecanvas/jsdom-extras@2.0.1", "", { "dependencies": { "jsdom": "^26.1.0" }, "peerDependencies": { "litecanvas": "latest" } }, "sha512-ABtufYkaYXhFbsZrXlmfcemsrrkww096kL5NpDOuIITCvgKMTGnR3oLmfONfHysOnkiUl1oB2a7sMpbfjBPk+A=="], "@mapbox/node-pre-gyp": ["@mapbox/node-pre-gyp@2.0.0", "", { "dependencies": { "consola": "^3.2.3", "detect-libc": "^2.0.0", "https-proxy-agent": "^7.0.5", "node-fetch": "^2.6.7", "nopt": "^8.0.0", "semver": "^7.5.3", "tar": "^7.4.0" }, "bin": { "node-pre-gyp": "bin/node-pre-gyp" } }, ""], @@ -120,27 +120,27 @@ "@size-limit/preset-small-lib": ["@size-limit/preset-small-lib@11.2.0", "", { "dependencies": { "@size-limit/esbuild": "11.2.0", "@size-limit/file": "11.2.0", "size-limit": "11.2.0" } }, "sha512-RFbbIVfv8/QDgTPyXzjo5NKO6CYyK5Uq5xtNLHLbw5RgSKrgo8WpiB/fNivZuNd/5Wk0s91PtaJ9ThNcnFuI3g=="], - "@swc/core": ["@swc/core@1.12.11", "", { "dependencies": { "@swc/counter": "^0.1.3", "@swc/types": "^0.1.23" }, "optionalDependencies": { "@swc/core-darwin-arm64": "1.12.11", "@swc/core-darwin-x64": "1.12.11", "@swc/core-linux-arm-gnueabihf": "1.12.11", "@swc/core-linux-arm64-gnu": "1.12.11", "@swc/core-linux-arm64-musl": "1.12.11", "@swc/core-linux-x64-gnu": "1.12.11", "@swc/core-linux-x64-musl": "1.12.11", "@swc/core-win32-arm64-msvc": "1.12.11", "@swc/core-win32-ia32-msvc": "1.12.11", "@swc/core-win32-x64-msvc": "1.12.11" }, "peerDependencies": { "@swc/helpers": ">=0.5.17" }, "optionalPeers": ["@swc/helpers"] }, "sha512-P3GM+0lqjFctcp5HhR9mOcvLSX3SptI9L1aux0Fuvgt8oH4f92rCUrkodAa0U2ktmdjcyIiG37xg2mb/dSCYSA=="], + "@swc/core": ["@swc/core@1.13.0", "", { "dependencies": { "@swc/counter": "^0.1.3", "@swc/types": "^0.1.23" }, "optionalDependencies": { "@swc/core-darwin-arm64": "1.13.0", "@swc/core-darwin-x64": "1.13.0", "@swc/core-linux-arm-gnueabihf": "1.13.0", "@swc/core-linux-arm64-gnu": "1.13.0", "@swc/core-linux-arm64-musl": "1.13.0", "@swc/core-linux-x64-gnu": "1.13.0", "@swc/core-linux-x64-musl": "1.13.0", "@swc/core-win32-arm64-msvc": "1.13.0", "@swc/core-win32-ia32-msvc": "1.13.0", "@swc/core-win32-x64-msvc": "1.13.0" }, "peerDependencies": { "@swc/helpers": ">=0.5.17" }, "optionalPeers": ["@swc/helpers"] }, "sha512-7Fh16ZH/Rj3Di720if+sw9BictD4N5kbTpsyDC+URXhvsZ7qRt1lH7PaeIQYyJJQHwFhoKpwwGxfGU9SHgPLdw=="], - "@swc/core-darwin-arm64": ["@swc/core-darwin-arm64@1.12.11", "", { "os": "darwin", "cpu": "arm64" }, "sha512-J19Jj9Y5x/N0loExH7W0OI9OwwoVyxutDdkyq1o/kgXyBqmmzV7Y/Q9QekI2Fm/qc5mNeAdP7aj4boY4AY/JPw=="], + "@swc/core-darwin-arm64": ["@swc/core-darwin-arm64@1.13.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-SkmR9u7MHDu2X8hf7SjZTmsAfQTmel0mi+TJ7AGtufLwGySv6pwQfJ/CIJpcPxYENVqDJAFnDrHaKV8mgA6kxQ=="], - "@swc/core-darwin-x64": ["@swc/core-darwin-x64@1.12.11", "", { "os": "darwin", "cpu": "x64" }, "sha512-PTuUQrfStQ6cjW+uprGO2lpQHy84/l0v+GqRqq8s/jdK55rFRjMfCeyf6FAR0l6saO5oNOQl+zWR1aNpj8pMQw=="], + "@swc/core-darwin-x64": ["@swc/core-darwin-x64@1.13.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-15/SyDjXRtFJ09fYHBXUXrj4tpiSpCkjgsF1z3/sSpHH1POWpQUQzxmFyomPQVZ/SsDqP18WGH09Vph4Qriuiw=="], - "@swc/core-linux-arm-gnueabihf": ["@swc/core-linux-arm-gnueabihf@1.12.11", "", { "os": "linux", "cpu": "arm" }, "sha512-poxBq152HsupOtnZilenvHmxZ9a8SRj4LtfxUnkMDNOGrZR9oxbQNwEzNKfi3RXEcXz+P8c0Rai1ubBazXv8oQ=="], + "@swc/core-linux-arm-gnueabihf": ["@swc/core-linux-arm-gnueabihf@1.13.0", "", { "os": "linux", "cpu": "arm" }, "sha512-AHauVHZQEJI/dCZQg6VYNNQ6HROz8dSOnCSheXzzBw1DGWo77BlcxRP0fF0jaAXM9WNqtCUOY1HiJ9ohkAE61Q=="], - "@swc/core-linux-arm64-gnu": ["@swc/core-linux-arm64-gnu@1.12.11", "", { "os": "linux", "cpu": "arm64" }, "sha512-y1HNamR/D0Hc8xIE910ysyLe269UYiGaQPoLjQS0phzWFfWdMj9bHM++oydVXZ4RSWycO7KyJ3uvw4NilvyMKQ=="], + "@swc/core-linux-arm64-gnu": ["@swc/core-linux-arm64-gnu@1.13.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-qyZmBZF7asF6954/x7yn6R7Bzd45KRG05rK2atIF9J3MTa8az7vubP1Q3BWmmss1j8699DELpbuoJucGuhsNXw=="], - "@swc/core-linux-arm64-musl": ["@swc/core-linux-arm64-musl@1.12.11", "", { "os": "linux", "cpu": "arm64" }, "sha512-LlBxPh/32pyQsu2emMEOFRm7poEFLsw12Y1mPY7FWZiZeptomKSOSHRzKDz9EolMiV4qhK1caP1lvW4vminYgQ=="], + "@swc/core-linux-arm64-musl": ["@swc/core-linux-arm64-musl@1.13.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-whskQCOUlLQT7MjnronpHmyHegBka5ig9JkQvecbqhWzRfdwN+c2xTJs3kQsWy2Vc2f1hcL3D8hGIwY5TwPxMQ=="], - "@swc/core-linux-x64-gnu": ["@swc/core-linux-x64-gnu@1.12.11", "", { "os": "linux", "cpu": "x64" }, "sha512-bOjiZB8O/1AzHkzjge1jqX62HGRIpOHqFUrGPfAln/NC6NR+Z2A78u3ixV7k5KesWZFhCV0YVGJL+qToL27myA=="], + "@swc/core-linux-x64-gnu": ["@swc/core-linux-x64-gnu@1.13.0", "", { "os": "linux", "cpu": "x64" }, "sha512-51n4P4nv6rblXyH3zCEktvmR9uSAZ7+zbfeby0sxbj8LS/IKuVd7iCwD5dwMj4CxG9Fs+HgjN73dLQF/OerHhg=="], - "@swc/core-linux-x64-musl": ["@swc/core-linux-x64-musl@1.12.11", "", { "os": "linux", "cpu": "x64" }, "sha512-4dzAtbT/m3/UjF045+33gLiHd8aSXJDoqof7gTtu4q0ZyAf7XJ3HHspz+/AvOJLVo4FHHdFcdXhmo/zi1nFn8A=="], + "@swc/core-linux-x64-musl": ["@swc/core-linux-x64-musl@1.13.0", "", { "os": "linux", "cpu": "x64" }, "sha512-VMqelgvnXs27eQyhDf1S2O2MxSdchIH7c1tkxODRtu9eotcAeniNNgqqLjZ5ML0MGeRk/WpbsAY/GWi7eSpiHw=="], - "@swc/core-win32-arm64-msvc": ["@swc/core-win32-arm64-msvc@1.12.11", "", { "os": "win32", "cpu": "arm64" }, "sha512-h8HiwBZErKvCAmjW92JvQp0iOqm6bncU4ac5jxBGkRApabpUenNJcj3h2g5O6GL5K6T9/WhnXE5gyq/s1fhPQg=="], + "@swc/core-win32-arm64-msvc": ["@swc/core-win32-arm64-msvc@1.13.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-NLJmseWJngWeENgat+O/WB4ptNxtx2X4OfPnSG5a/A4sxcn2E4jq91OPvbeUQwDkH+ZQWKXmbXFzt7Nn661QYA=="], - "@swc/core-win32-ia32-msvc": ["@swc/core-win32-ia32-msvc@1.12.11", "", { "os": "win32", "cpu": "ia32" }, "sha512-1pwr325mXRNUhxTtXmx1IokV5SiRL+6iDvnt3FRXj+X5UvXXKtg2zeyftk+03u8v8v8WUr5I32hIypVJPTNxNg=="], + "@swc/core-win32-ia32-msvc": ["@swc/core-win32-ia32-msvc@1.13.0", "", { "os": "win32", "cpu": "ia32" }, "sha512-UBfwrp0xW37KQGTA08mwrCLIm1ZKy6pXK8IVwou7BvhMgrItRNweTGyUrCnvDLUfyYFuJCmzcEaJ3NudtctD6g=="], - "@swc/core-win32-x64-msvc": ["@swc/core-win32-x64-msvc@1.12.11", "", { "os": "win32", "cpu": "x64" }, "sha512-5gggWo690Gvs7XiPxAmb5tHwzB9RTVXUV7AWoGb6bmyUd1OXYaebQF0HAOtade5jIoNhfQMQJ7QReRgt/d2jAA=="], + "@swc/core-win32-x64-msvc": ["@swc/core-win32-x64-msvc@1.13.0", "", { "os": "win32", "cpu": "x64" }, "sha512-BAB1P7Z/y2EENsfsPytPnjIyBVRZN2WULY+s3ozW4QkGmYHde6XXG28n0ABTHhcIOmmR2VzM+uaW1x48laSimw=="], "@swc/counter": ["@swc/counter@0.1.3", "", {}, "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ=="], @@ -372,7 +372,7 @@ "lilconfig": ["lilconfig@3.1.3", "", {}, "sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw=="], - "litecanvas": ["litecanvas@0.86.0", "", {}, "sha512-gn5iWcSsFvpAtKxBZ/flZxW/OIvqkff7T4u8SWGgRverbaPF5QWEFBFGmlU0oXd/KpzdpV0hwkZvDdA5lykxgQ=="], + "litecanvas": ["litecanvas@0.92.3", "", {}, "sha512-O1m/A9cD4fAdJcJleO/S+3Dvz5a4md4vqeTG8no8BkeM8vhSTPASgY8a46oetOzNvs3tQSfOU02jJwHpDaZ+Jg=="], "load-json-file": ["load-json-file@7.0.1", "", {}, ""], diff --git a/package.json b/package.json index bf1cf60..acc9893 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,9 @@ "creative coding" ], "devDependencies": { - "@litecanvas/jsdom-extras": "^2.0.0", + "@litecanvas/jsdom-extras": "^2.0.1", "@size-limit/preset-small-lib": "^11.2.0", - "@swc/core": "^1.12.11", + "@swc/core": "^1.13.0", "@types/jsdom": "^21.1.7", "ava": "^6.4.1", "esbuild": "^0.25.6", diff --git a/src/index.js b/src/index.js index a3f49c1..0315586 100644 --- a/src/index.js +++ b/src/index.js @@ -33,7 +33,6 @@ export default function litecanvas(settings = {}) { height: null, autoscale: true, pixelart: false, - antialias: false, canvas: null, global: true, loop: null, @@ -945,7 +944,7 @@ export default function litecanvas(settings = {}) { DEV: assert(isNumber(volumeFactor), '[litecanvas] sfx() 3rd param must be a number') if ( - root.zzfxV <= 0 || + !root.zzfxV || (navigator.userActivation && !navigator.userActivation.hasBeenActive) ) { return false @@ -972,7 +971,10 @@ export default function litecanvas(settings = {}) { * @param {number} value */ volume(value) { - DEV: assert(isNumber(value), '[litecanvas] volume() 1st param must be a number') + DEV: assert( + isNumber(value) && value >= 0, + '[litecanvas] volume() 1st param must be a positive number or zero' + ) root.zzfxV = value }, @@ -1564,7 +1566,7 @@ export default function litecanvas(settings = {}) { _ctx = _canvas.getContext('2d') - on(_canvas, 'click', () => root.focus()) + on(_canvas, 'click', () => focus()) /** @ts-ignore */ _canvas.style = '' @@ -1592,8 +1594,8 @@ export default function litecanvas(settings = {}) { '[litecanvas] litecanvas() option "width" is required when the option "height" is defined' ) - const width = settings.width || root.innerWidth, - height = settings.height || settings.width || root.innerHeight + const width = settings.width > 0 ? settings.width : innerWidth, + height = settings.width > 0 ? settings.height || settings.width : innerHeight instance.def('W', width) instance.def('H', height) @@ -1608,29 +1610,30 @@ export default function litecanvas(settings = {}) { _canvas.style.margin = 'auto' } - _scale = math.min(root.innerWidth / width, root.innerHeight / height) + _scale = math.min(innerWidth / width, innerHeight / height) _scale = maxScale > 1 && _scale > maxScale ? maxScale : _scale - _scale = (settings.pixelart ? ~~_scale : _scale) || 1 _canvas.style.width = width * _scale + 'px' _canvas.style.height = height * _scale + 'px' } - // restore canvas image rendering properties - if (!settings.antialias || settings.pixelart) { + // set canvas image rendering properties + if (settings.pixelart) { _ctx.imageSmoothingEnabled = false _canvas.style.imageRendering = 'pixelated' } - // reset the default text align and baseline + // set the default text align and baseline instance.textalign('start', 'top') // trigger "resized" event + // note: not triggered before the "init" event instance.emit('resized', _scale) + // paint a temporary background instance.cls(0) - // force redraw + // force redraw when the canvas is not animated if (!settings.animate) { raf(drawFrame) } diff --git a/types/types.d.ts b/types/types.d.ts index 0d39db7..d7d2e8e 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -594,19 +594,18 @@ type LitecanvasOptions = { canvas?: HTMLCanvasElement | string /** * If `true` (default) scales the canvas to fill the screen, but preserving the aspect ratio. - * Instead of `true`, you can pass a number to limit the maximum scale factor of the canvas. + * Instead of `true`, you can pass a number to determine the maximum scale. * * Note: Only works if the option "width" was specified. */ autoscale?: boolean | number /** * If `true`, the pixel art images won't look blurry. + * Also, disables canvas built-in antialias. + * + * Default: `false` */ pixelart?: boolean - /** - * If `false` (default), disable the canvas antialias. - */ - antialias?: boolean /** * If `true` (default), all methods and properties of the engine will be exposed to the global scope (window). */