54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
// The themes a user can pick, apart from how they are applied. The palettes are
|
|
// in `../colors.css`, one `:root[data-theme="<id>"]` block per id here; a new
|
|
// theme is one entry here and one palette there. Each theme is light or dark.
|
|
// `auto` is not a theme: it leaves `data-theme` off, and the OS preference
|
|
// picks hyperhive light or hyperhive dark.
|
|
|
|
export type ThemeScheme = "light" | "dark";
|
|
|
|
export interface ThemeDef {
|
|
id: string;
|
|
label: string;
|
|
scheme: ThemeScheme;
|
|
}
|
|
|
|
export const THEMES: readonly ThemeDef[] = [
|
|
{ id: "hyperhive-light", label: "hyperhive light", scheme: "light" },
|
|
{ id: "hyperhive-dark", label: "hyperhive dark", scheme: "dark" },
|
|
{
|
|
id: "catppuccin-latte-mauve",
|
|
label: "catppuccin latte mauve",
|
|
scheme: "light",
|
|
},
|
|
{
|
|
id: "catppuccin-mocha-mauve",
|
|
label: "catppuccin mocha mauve",
|
|
scheme: "dark",
|
|
},
|
|
{
|
|
id: "catppuccin-mocha-mara",
|
|
label: "catppuccin mocha mara",
|
|
scheme: "dark",
|
|
},
|
|
];
|
|
|
|
/** The stored choice that follows the OS preference. */
|
|
export const AUTO_THEME = "auto";
|
|
|
|
/** What a page uses until the user has picked. */
|
|
export const DEFAULT_THEME = "hyperhive-dark";
|
|
|
|
/**
|
|
* The choice a stored value stands for. The values from before themes existed
|
|
* map to their successors (`system` to `auto`, `light` and `dark` to the
|
|
* hyperhive themes); anything unknown is `fallback`.
|
|
*/
|
|
export function themeChoice(
|
|
stored: unknown,
|
|
fallback: string = DEFAULT_THEME,
|
|
): string {
|
|
if (stored === AUTO_THEME || stored === "system") return AUTO_THEME;
|
|
if (stored === "light") return "hyperhive-light";
|
|
if (stored === "dark") return "hyperhive-dark";
|
|
return THEMES.some((t) => t.id === stored) ? (stored as string) : fallback;
|
|
}
|