import type { themes } from "./themes.ts"; export const USER_THEMES = ["light", "dark", "system"] as const; export type UserTheme = (typeof USER_THEMES)[number]; // "reader" = fall through to the visitor's theme; "enforce" = override with the wiki's theme. export type WikiThemeMode = "reader" | "enforce"; export type ThemeName = keyof typeof themes; export function resolveUserTheme( cookieHeader: string | null | undefined, ): UserTheme { if (!cookieHeader) return "system"; const match = cookieHeader.match(/(?:^|;\s*)theme=([^;]+)/); if (!match?.[1]) return "system"; const val = match[1].trim(); if ((USER_THEMES as readonly string[]).includes(val)) { return val as UserTheme; } return "system"; }