Files
Katia Bulatova 57ceb984af feat(webapp): new Dark theme is the default with a slight contrast bump
Missing or legacy preferences resolve to the pinned Dark theme (not
system-resolved, so nobody is surprised by light mode) and the default
contrast is 50. Classic remains the flag-off look.
2026-07-27 06:57:36 +00:00

26 lines
1.2 KiB
TypeScript

import { z } from "zod";
// Shared between server (dashboard preferences) and client (theme UI, system
// theme sync) - must stay free of server-only imports.
export const ThemePreference = z.enum(["classic", "system", "dark", "light"]);
export type ThemePreference = z.infer<typeof ThemePreference>;
/** Coerce any stored/legacy value into a valid preference. Missing or unknown
* values fall back to `dark` - the new dark theme is the default (pinned, not
* system-resolved, so nobody gets surprised by light mode). */
export function normalizeThemePreference(value: unknown): ThemePreference {
const result = ThemePreference.safeParse(value);
return result.success ? result.data : "dark";
}
/** The default dark theme ships with a slight contrast bump. */
export const DEFAULT_THEME_CONTRAST = 50;
/** Interface contrast for the System themes, 0 to 100. Missing or invalid
* values fall back to the default bump. */
export function normalizeThemeContrast(value: unknown): number {
const num = typeof value === "string" ? Number(value) : value;
if (typeof num !== "number" || !Number.isFinite(num)) return DEFAULT_THEME_CONTRAST;
return Math.min(100, Math.max(0, Math.round(num)));
}