From 464cfa50b05ba455b36a79c1b5b1c27c166f8cee Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 2 May 2026 16:12:23 -0500 Subject: [PATCH] feat(micron): inject CSS styles for ForceMonospace mode in WASM --- meshchatx/src/frontend/js/MicronWasmLoader.js | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/meshchatx/src/frontend/js/MicronWasmLoader.js b/meshchatx/src/frontend/js/MicronWasmLoader.js index 627722f..5655d4b 100644 --- a/meshchatx/src/frontend/js/MicronWasmLoader.js +++ b/meshchatx/src/frontend/js/MicronWasmLoader.js @@ -6,6 +6,33 @@ let resolvedPromise = null; +/** Injects CSS required for ForceMonospace mode when using WASM. Safe to call multiple times. */ +function injectMicronWasmStyles() { + if (document.getElementById("micron-wasm-monospace-styles")) { + return; + } + const styleEl = document.createElement("style"); + styleEl.id = "micron-wasm-monospace-styles"; + styleEl.textContent = ` + .Mu-nl { + cursor: pointer; + } + .Mu-mnt { + display: inline-block; + min-width: 1ch; + text-align: center; + white-space: pre; + text-decoration: inherit; + font-variant-numeric: tabular-nums; + } + .Mu-mws { + text-decoration: inherit; + display: inline; + } + `; + document.head.appendChild(styleEl); +} + /** True when WASM artifacts were present at Vite build time (not runtime probing). */ export function isMicronWasmBundled() { if (typeof globalThis !== "undefined" && typeof globalThis.__MESHCHATX_TEST_MICRON_WASM_BUNDLED__ === "boolean") { @@ -76,13 +103,16 @@ export function preloadNomadMicronWasm() { return Promise.resolve(false); } if (typeof globalThis.micronConvert === "function") { + injectMicronWasmStyles(); return Promise.resolve(true); } if (resolvedPromise === null) { resolvedPromise = (async () => { try { await instantiateOnce(); - return typeof globalThis.micronConvert === "function"; + const ok = typeof globalThis.micronConvert === "function"; + if (ok) injectMicronWasmStyles(); + return ok; } catch (e) { console.warn(e); resolvedPromise = null;