diff --git a/assets/web-showcase-template/app.js b/assets/web-showcase-template/app.js index 598860f..5d64033 100644 --- a/assets/web-showcase-template/app.js +++ b/assets/web-showcase-template/app.js @@ -855,6 +855,21 @@ function renderBookmarkList() { } // ───────────────────────── URL Hash State ───────────────────────── +function encodeHashState(value) { + const bytes = new TextEncoder().encode(value); + let binary = ""; + for (let index = 0; index < bytes.length; index += 0x8000) { + binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000)); + } + return btoa(binary).replace(/=/g, ""); +} + +function decodeHashState(value) { + const padded = value + "=".repeat((4 - (value.length % 4)) % 4); + const binary = atob(padded); + return new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0))); +} + function serializeStateToHash() { const hash = { f: Object.entries(state.floors).filter(([, v]) => !v).map(([k]) => k), // only store disabled @@ -867,7 +882,7 @@ function serializeStateToHash() { }, b: bookmarks, }; - const encoded = btoa(JSON.stringify(hash)).replace(/=/g, ""); + const encoded = encodeHashState(JSON.stringify(hash)); history.replaceState(null, "", `#${encoded}`); } @@ -875,7 +890,7 @@ function restoreStateFromHash() { try { const raw = window.location.hash.slice(1); if (!raw) return; - const hash = JSON.parse(atob(raw)); + const hash = JSON.parse(decodeHashState(raw)); if (hash.f) for (const fk of hash.f) { if (fk in state.floors) state.floors[fk] = false; } if (hash.c) for (const ck of hash.c) { if (ck in state.categories) state.categories[ck] = false; } if (hash.s) { sectionInput.value = hash.s; applySection(Number(hash.s)); } diff --git a/scripts/web_smoke_test.mjs b/scripts/web_smoke_test.mjs index 7845d81..6061d1e 100644 --- a/scripts/web_smoke_test.mjs +++ b/scripts/web_smoke_test.mjs @@ -58,6 +58,24 @@ async function inspect(viewport, name) { await page.waitForTimeout(1500); const after = await page.evaluate(() => window.__renders || 0); checks.push({ name: `${name}:idle-render`, status: after === before ? "PASS" : "FAIL", detail: `${before}->${after}` }); + if (name === "desktop") { + const buttons = page.locator("#floor-controls button"); + const labels = await buttons.allTextContents(); + const unicodeIndex = labels.findIndex((label) => /[^\x00-\x7F]/.test(label)); + if (unicodeIndex >= 0) { + const button = buttons.nth(unicodeIndex); + await button.click(); + await page.waitForTimeout(150); + const hashWritten = await page.evaluate(() => window.location.hash.length > 1); + await button.click(); + await page.waitForTimeout(150); + checks.push({ + name: "desktop:unicode-floor-state", + status: hashWritten ? "PASS" : "FAIL", + detail: hashWritten ? "UTF-8 floor label serialized to URL hash" : "URL hash was not written", + }); + } + } if (name === "desktop" && thumbnailOut) { // Export the renderer itself. Cropping a page screenshot retains UI panels // and makes Agents guess at a dark-background crop; the canvas is already