1// The two values per theme, and nothing else.2//3// The stylesheet has to declare *some* default, and the app cannot run before4// first paint, so a saved dark theme would show a full frame of white before the5// palette reached it. Survivable on a tinted paper; on the black theme it is a6// flashbulb, which is the one thing a black theme exists to avoid.7//8// This is the smallest thing that can run early enough. Kept in step with9// theme.gleam by hand — it is four pairs, and the alternative is blocking paint10// on a module graph.1112(function () {13 // The picture covers the whole safe area, which it can only do once the page14 // is told to lay out under the hardware's cutouts — and the board owns every15 // gesture, so the browser must not be offered a pinch. Written here rather16 // than in the generated head because the generator owns that tag.17 var viewport = document.querySelector('meta[name="viewport"]');18 if (viewport) {19 viewport.setAttribute(20 "content",21 "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover",22 );23 }2425 var INK = {26 macintosh: "#2B2B22",27 paper: "#2E3037",28 night: "#DCE4E2",29 amoled: "#DCF2FF",30 };31 var PAPER = {32 macintosh: "#E8F4F2",33 paper: "#EBE5CE",34 night: "#1C2028",35 amoled: "#000000",36 };37 try {38 var raw = JSON.parse(localStorage.getItem("klotski.save"));39 var id = raw && raw.payload && raw.payload.palette;40 // AUTO is stored as AUTO and resolved against the system, which is a41 // question this can ask without loading anything.42 if (id === "auto") {43 id = window.matchMedia("(prefers-color-scheme: dark)").matches44 ? "night"45 : "macintosh";46 }47 if (!PAPER[id]) return;48 var style = document.documentElement.style;49 style.setProperty("--ink", INK[id]);50 style.setProperty("--paper", PAPER[id]);51 style.setProperty("--ground", PAPER[id]);52 var meta = document.querySelector('meta[name="theme-color"]');53 if (meta) meta.setAttribute("content", PAPER[id]);54 } catch (e) {55 // Private mode, or nothing saved yet: the default stands.56 }57})();