Skip to content
Merged

Patch #271

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 6 additions & 60 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "litecanvas",
"version": "0.103.4",
"version": "0.103.5",
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
"license": "MIT",
"author": "Luiz Bills <luizbills@pm.me>",
Expand Down Expand Up @@ -33,15 +33,15 @@
],
"devDependencies": {
"@happy-dom/global-registrator": "^20.8.3",
"@size-limit/preset-small-lib": "^12.0.0",
"@size-limit/preset-small-lib": "^12.0.1",
"@swc/core": "^1.15.18",
"ava": "^7.0.0",
"esbuild": "^0.27.3",
"genversion": "^3.2.0",
"gzip-size": "^7.0.0",
"prettier": "^3.8.1",
"sinon": "^21.0.2",
"size-limit": "^12.0.0",
"size-limit": "^12.0.1",
"tap-min": "^3.0.0"
},
"trustedDependencies": [
Expand Down
3 changes: 2 additions & 1 deletion samples/palette-dither-test/palette-dither-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ litecanvas({
})

function init() {
framerate(1)
combinations = []
for (let y = 0; y < cols; y++) {
for (let x = 0; x < cols; x++) {
Expand All @@ -35,6 +34,8 @@ function draw() {
}
}
}

pause()
}

function tapped() {
Expand Down
2 changes: 1 addition & 1 deletion samples/plugin-basics/plugin-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function pluginTest(engine, config) {
// the event callback
function () {
engine.cls(1)
engine.rectfill(0, 0, 100, 100, 4)
engine.rectfill(0, 0, 100, 100, 3)
}
)

Expand Down
2 changes: 1 addition & 1 deletion samples/snake/snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function draw() {
textfont('monospace')
textalign('center', 'middle')
textsize(28)
text(W / 2, H / 2, 'GAME OVER', 4, 'bold')
text(W / 2, H / 2, 'GAME OVER', 3, 'bold')
}
}

Expand Down
96 changes: 61 additions & 35 deletions script/build.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,75 @@
import fs from 'node:fs'
import fs from 'node:fs/promises'
import esbuild from 'esbuild'
import { minify } from '@swc/core'
import { gzipSizeSync } from 'gzip-size'
import * as prettier from 'prettier'

fs.rmSync('dist', { recursive: true, force: true })
await fs.rm('dist', { recursive: true, force: true })

// build the dist.dev.js (for development)
await esbuild.build({
entryPoints: ['src/web.js'],
outfile: 'dist/dist.dev.js',
bundle: true,
legalComments: 'eof',
drop: ['debugger'],
})
console.log(` 📄 dist/dist.dev.js (${filesize('dist/dist.dev.js')})`)
{
const filepath = 'dist/dist.dev.js'
await esbuild.build({
entryPoints: ['src/web.js'],
outfile: filepath,
bundle: true,
legalComments: 'eof',
minifyWhitespace: true,
drop: ['debugger'],
})
const formatted = await prettier.format(await fs.readFile(filepath, 'utf8'), {
parser: 'babel',
tabWidth: 2,
semi: false,
})
await fs.writeFile(filepath, formatted)

console.log(` 📄 ${filepath} (${await filesize(filepath)})`)
}

// build the dist.js
await esbuild.build({
entryPoints: ['src/web.js'],
outfile: 'dist/dist.js',
bundle: true,
legalComments: 'eof',
drop: ['console'],
dropLabels: ['DEV'],
})
{
{
const filepath = 'dist/dist.js'
await esbuild.build({
entryPoints: ['src/web.js'],
outfile: filepath,
bundle: true,
legalComments: 'eof',
minifyWhitespace: true,
drop: ['debugger', 'console'],
dropLabels: ['DEV'],
})
const formatted = await prettier.format(await fs.readFile(filepath, 'utf8'), {
parser: 'babel',
tabWidth: 2,
semi: false,
})
await fs.writeFile(filepath, formatted)

console.log(` 📄 dist/dist.js (${filesize('dist/dist.js')})`)
console.log(` 📄 ${filepath} (${await filesize(filepath)})`)
}
}

// build the dist.min.js
const minified = await minify(fs.readFileSync('dist/dist.js', { encoding: 'utf-8' }), {
format: {
comments: false,
},
compress: {
drop_console: true,
},
mangle: true,
})
fs.writeFileSync('dist/dist.min.js', minified.code)
console.log(
` 📄 dist/dist.min.js (${filesize('dist/dist.min.js')} ~= ${gzipsize(minified.code)} gzip)`
)

function filesize(filename) {
const stats = fs.statSync(filename)
{
const minified = await minify(await fs.readFile('dist/dist.js', { encoding: 'utf-8' }), {
format: {
comments: false,
},
compress: {
drop_console: true,
},
mangle: true,
})
await fs.writeFile('dist/dist.min.js', minified.code)
console.log(
` 📄 dist/dist.min.js (${await filesize('dist/dist.min.js')} ~= ${gzipsize(minified.code)} gzip)`
)
}

async function filesize(filename) {
const stats = await fs.stat(filename)
return (stats.size / 1000).toFixed(2) + 'kb'
}

Expand Down
2 changes: 1 addition & 1 deletion src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* @param {string} message
*/
export const assert = (condition, message = 'Assertion failed') => {
if (!condition) throw new Error(message)
if (!condition) throw new Error('[litecanvas] ' + message)
}
Loading