// Debug-HUD toggle (#20). Off by default; persisted in localStorage so it // survives reloads, flipped by a keybind (Ctrl+Shift+D), and force-enabled by // `?hud` in dev. A `maestro-hud-toggle` event lets the HUD re-render on change. const STORAGE_KEY = "maestro:hud"; export const HUD_TOGGLE_EVENT = "maestro-hud-toggle"; /** Whether the debug HUD should be shown. */ export function isHudEnabled(): boolean { if (import.meta.env.DEV && location.search.includes("hud")) return true; try { return localStorage.getItem(STORAGE_KEY) === "1"; } catch { // Private-mode / storage-disabled: HUD just stays off. return false; } } /** Persist the HUD on/off state and notify listeners. */ export function setHudEnabled(on: boolean): void { try { if (on) localStorage.setItem(STORAGE_KEY, "1"); else localStorage.removeItem(STORAGE_KEY); } catch { // ignore storage failures — the event still drives the in-memory HUD } window.dispatchEvent(new CustomEvent(HUD_TOGGLE_EVENT)); } export function toggleHud(): void { setHudEnabled(!isHudEnabled()); } /** Global keybind: Ctrl+Shift+D toggles the debug HUD. */ export function installHudKeybind(): void { window.addEventListener("keydown", (e) => { if (e.ctrlKey && e.shiftKey && (e.key === "D" || e.key === "d")) { e.preventDefault(); toggleHud(); } }); }