feat: enhance minification and mangling support by switching FONT_DATA to a Map and updating Vite configuration for ECMAScript 2020 compatibility

This commit is contained in:
Juan Sebastián Montoya 2026-01-06 22:40:19 -05:00
parent 9e640aa7be
commit 143072f0a0
2 changed files with 74 additions and 71 deletions

View file

@ -1,57 +1,58 @@
/** /**
* Simple 5x7 Matrix Pixel Font data. * Simple 5x7 Matrix Pixel Font data.
* Each character is represented by an array of 7 integers, where each integer is a 5-bit mask. * 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<string, number[]> = { const FONT_DATA = new Map<string, readonly number[]>([
A: [0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11], ['A', [0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11]],
B: [0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e], ['B', [0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e]],
C: [0x0e, 0x11, 0x11, 0x10, 0x11, 0x11, 0x0e], ['C', [0x0e, 0x11, 0x11, 0x10, 0x11, 0x11, 0x0e]],
D: [0x1e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1e], ['D', [0x1e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1e]],
E: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f], ['E', [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f]],
F: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10], ['F', [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10]],
G: [0x0f, 0x10, 0x10, 0x17, 0x11, 0x11, 0x0f], ['G', [0x0f, 0x10, 0x10, 0x17, 0x11, 0x11, 0x0f]],
H: [0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11], ['H', [0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11]],
I: [0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e], ['I', [0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e]],
J: [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c], ['J', [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c]],
K: [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11], ['K', [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11]],
L: [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f], ['L', [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f]],
M: [0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11], ['M', [0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11]],
N: [0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11], ['N', [0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11]],
O: [0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e], ['O', [0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e]],
P: [0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10], ['P', [0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10]],
Q: [0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d], ['Q', [0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d]],
R: [0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11], ['R', [0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11]],
S: [0x0e, 0x11, 0x10, 0x0e, 0x01, 0x11, 0x0e], ['S', [0x0e, 0x11, 0x10, 0x0e, 0x01, 0x11, 0x0e]],
T: [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], ['T', [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04]],
U: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e], ['U', [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e]],
V: [0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04], ['V', [0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04]],
W: [0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11], ['W', [0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11]],
X: [0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11], ['X', [0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11]],
Y: [0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04], ['Y', [0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04]],
Z: [0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f], ['Z', [0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f]],
'0': [0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e], ['0', [0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e]],
'1': [0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e], ['1', [0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e]],
'2': [0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f], ['2', [0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f]],
'3': [0x1f, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0e], ['3', [0x1f, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0e]],
'4': [0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02], ['4', [0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02]],
'5': [0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e], ['5', [0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e]],
'6': [0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e], ['6', [0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e]],
'7': [0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08], ['7', [0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08]],
'8': [0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e], ['8', [0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e]],
'9': [0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c], ['9', [0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c]],
':': [0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00], [':', [0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00]],
'.': [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00], ['.', [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00]],
',': [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08], [',', [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08]],
'!': [0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04], ['!', [0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04]],
'?': [0x0e, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04], ['?', [0x0e, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04]],
'+': [0x00, 0x04, 0x04, 0x1f, 0x04, 0x04, 0x00], ['+', [0x00, 0x04, 0x04, 0x1f, 0x04, 0x04, 0x00]],
'-': [0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00], ['-', [0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00]],
'/': [0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10], ['/', [0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10]],
'(': [0x02, 0x04, 0x04, 0x04, 0x04, 0x04, 0x02], ['(', [0x02, 0x04, 0x04, 0x04, 0x04, 0x04, 0x02]],
')': [0x08, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08], [')', [0x08, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08]],
' ': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], [' ', [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]],
'|': [0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], ['|', [0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04]],
}; ]);
/** /**
* Utility class for rendering text using a custom pixel font. * Utility class for rendering text using a custom pixel font.
@ -80,7 +81,7 @@ export const PixelFont = {
const chars = text.toUpperCase().split(''); const chars = text.toUpperCase().split('');
chars.forEach((char) => { 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 row = 0; row < 7; row++) {
for (let col = 0; col < 5; col++) { for (let col = 0; col < 5; col++) {
if ((glyph[row] >> (4 - col)) & 1) { if ((glyph[row] >> (4 - col)) & 1) {

View file

@ -4,12 +4,14 @@ export default defineConfig({
build: { build: {
minify: 'terser', minify: 'terser',
terserOptions: { terserOptions: {
ecma: 2020,
compress: { compress: {
drop_console: true, drop_console: true,
drop_debugger: true, drop_debugger: true,
}, },
mangle: { mangle: {
toplevel: true, toplevel: true,
properties: true,
}, },
format: { format: {
comments: false, comments: false,