// Light or dark, chosen by hand (D14, ยง6.9 of DESIGN_M1.md). The page follows // the system unless light or dark is kept in the browser's storage. // // Storage is passed as a function returning it, because merely reaching for // localStorage throws where the page may not use it. // The inline line in index.html reads the same key before the page paints. const key = "theme"; // What is kept and read back. "system" is never kept: it is the absence of a // choice. const kept = ["light", "dark"]; export function stored(storage) { try { const value = storage().getItem(key); return kept.includes(value) ? value : "system"; } catch { return "system"; } } // Without storage, a choice lasts until the page is reloaded. export function store(storage, choice) { try { if (kept.includes(choice)) storage().setItem(key, choice); else storage().removeItem(key); } catch { // Nothing to keep it in, and nothing else to do. } }