From 143072f0a07e480fc37f9f871b26da3aec08d3a0 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Montoya Date: Tue, 6 Jan 2026 22:40:19 -0500 Subject: [PATCH] feat: enhance minification and mangling support by switching FONT_DATA to a Map and updating Vite configuration for ECMAScript 2020 compatibility --- src/core/PixelFont.ts | 103 +++++++++++++++++++++--------------------- vite.config.js | 42 +++++++++-------- 2 files changed, 74 insertions(+), 71 deletions(-) diff --git a/src/core/PixelFont.ts b/src/core/PixelFont.ts index ea0463a..d895c87 100644 --- a/src/core/PixelFont.ts +++ b/src/core/PixelFont.ts @@ -1,57 +1,58 @@ /** * Simple 5x7 Matrix Pixel Font data. * Each character is represented by an array of 7 integers, where each integer is a 5-bit mask. + * Using Map for better minification/mangling support. */ -const FONT_DATA: Record = { - A: [0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11], - B: [0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e], - C: [0x0e, 0x11, 0x11, 0x10, 0x11, 0x11, 0x0e], - D: [0x1e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1e], - E: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f], - F: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10], - G: [0x0f, 0x10, 0x10, 0x17, 0x11, 0x11, 0x0f], - H: [0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11], - I: [0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e], - J: [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c], - K: [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11], - L: [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f], - M: [0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11], - N: [0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11], - O: [0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e], - P: [0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10], - Q: [0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d], - R: [0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11], - S: [0x0e, 0x11, 0x10, 0x0e, 0x01, 0x11, 0x0e], - T: [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], - U: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e], - V: [0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04], - W: [0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11], - X: [0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11], - Y: [0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04], - Z: [0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f], - '0': [0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e], - '1': [0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e], - '2': [0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f], - '3': [0x1f, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0e], - '4': [0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02], - '5': [0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e], - '6': [0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e], - '7': [0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08], - '8': [0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e], - '9': [0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c], - ':': [0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00], - '.': [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00], - ',': [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08], - '!': [0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04], - '?': [0x0e, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04], - '+': [0x00, 0x04, 0x04, 0x1f, 0x04, 0x04, 0x00], - '-': [0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00], - '/': [0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10], - '(': [0x02, 0x04, 0x04, 0x04, 0x04, 0x04, 0x02], - ')': [0x08, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08], - ' ': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - '|': [0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], -}; +const FONT_DATA = new Map([ + ['A', [0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11]], + ['B', [0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e]], + ['C', [0x0e, 0x11, 0x11, 0x10, 0x11, 0x11, 0x0e]], + ['D', [0x1e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1e]], + ['E', [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f]], + ['F', [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10]], + ['G', [0x0f, 0x10, 0x10, 0x17, 0x11, 0x11, 0x0f]], + ['H', [0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11]], + ['I', [0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e]], + ['J', [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c]], + ['K', [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11]], + ['L', [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f]], + ['M', [0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11]], + ['N', [0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11]], + ['O', [0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e]], + ['P', [0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10]], + ['Q', [0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d]], + ['R', [0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11]], + ['S', [0x0e, 0x11, 0x10, 0x0e, 0x01, 0x11, 0x0e]], + ['T', [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04]], + ['U', [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e]], + ['V', [0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04]], + ['W', [0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11]], + ['X', [0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11]], + ['Y', [0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04]], + ['Z', [0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f]], + ['0', [0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e]], + ['1', [0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e]], + ['2', [0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f]], + ['3', [0x1f, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0e]], + ['4', [0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02]], + ['5', [0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e]], + ['6', [0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e]], + ['7', [0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08]], + ['8', [0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e]], + ['9', [0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c]], + [':', [0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00]], + ['.', [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00]], + [',', [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08]], + ['!', [0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04]], + ['?', [0x0e, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04]], + ['+', [0x00, 0x04, 0x04, 0x1f, 0x04, 0x04, 0x00]], + ['-', [0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00]], + ['/', [0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10]], + ['(', [0x02, 0x04, 0x04, 0x04, 0x04, 0x04, 0x02]], + [')', [0x08, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08]], + [' ', [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]], + ['|', [0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04]], +]); /** * Utility class for rendering text using a custom pixel font. @@ -80,7 +81,7 @@ export const PixelFont = { const chars = text.toUpperCase().split(''); chars.forEach((char) => { - const glyph = FONT_DATA[char] || FONT_DATA['?']; + const glyph = FONT_DATA.get(char) || FONT_DATA.get('?')!; for (let row = 0; row < 7; row++) { for (let col = 0; col < 5; col++) { if ((glyph[row] >> (4 - col)) & 1) { diff --git a/vite.config.js b/vite.config.js index 5f09b7e..3dfac46 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,25 +1,27 @@ import { defineConfig } from 'vite'; export default defineConfig({ - build: { - minify: 'terser', - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true, - }, - mangle: { - toplevel: true, - }, - format: { - comments: false, - }, - }, - rollupOptions: { - output: { - manualChunks: undefined, - }, - }, - sourcemap: false, + build: { + minify: 'terser', + terserOptions: { + ecma: 2020, + compress: { + drop_console: true, + drop_debugger: true, + }, + mangle: { + toplevel: true, + properties: true, + }, + format: { + comments: false, + }, }, + rollupOptions: { + output: { + manualChunks: undefined, + }, + }, + sourcemap: false, + }, });