33 lines
1.4 KiB
JavaScript
33 lines
1.4 KiB
JavaScript
// Sets the stored theme and motion overrides on <html> before the first paint.
|
|
// The app applies them again once it mounts (`useApplyThemeOverride`,
|
|
// `useApplyMotionOverride`), but that is after the page has painted, so a light
|
|
// OS showed a light flash before the dark default took over. This runs from a
|
|
// blocking script in the head, as the page's policy allows no inline script. The
|
|
// keys and the fallbacks (hyperhive dark for the theme, "system" for motion) are
|
|
// those of `shell/Shell.tsx`, and the theme ids and the values from before
|
|
// themes existed are those of `@hive/shared`'s `settings/themes.ts`;
|
|
// `test/theme-boot.test.mjs` keeps them in step.
|
|
(function () {
|
|
function read(key, fallback) {
|
|
try {
|
|
var raw = localStorage.getItem(key);
|
|
return raw === null ? fallback : JSON.parse(raw);
|
|
} catch (e) {
|
|
return fallback;
|
|
}
|
|
}
|
|
var root = document.documentElement;
|
|
var themes = [
|
|
"hyperhive-light",
|
|
"hyperhive-dark",
|
|
"catppuccin-latte-mauve",
|
|
"catppuccin-mocha-mauve",
|
|
"catppuccin-mocha-mara",
|
|
];
|
|
var theme = read("swarm-ui:theme-override", "hyperhive-dark");
|
|
if (theme === "light") theme = "hyperhive-light";
|
|
if (theme === "dark") theme = "hyperhive-dark";
|
|
if (themes.indexOf(theme) >= 0) root.dataset.theme = theme;
|
|
var motion = read("swarm-ui:motion-override", "system");
|
|
if (motion === "reduce" || motion === "allow") root.dataset.motion = motion;
|
|
})();
|