import storedWritable from "@app/lib/localStore"; import { boolean, literal, union, z } from "zod"; const themeSchema = union([literal("dark"), literal("light")]); type Theme = z.infer; export const followSystemTheme = storedWritable( "followSystemTheme", boolean(), !localStorage?.getItem("theme"), !window.localStorage, ); export const theme = storedWritable( "theme", themeSchema, loadTheme(), !window.localStorage, ); export function loadTheme(): Theme { const { matches } = window.matchMedia("(prefers-color-scheme: dark)"); return matches ? "dark" : "light"; } const codeFontSchema = union([literal("jetbrains"), literal("system")]); type CodeFont = z.infer; export const codeFont = storedWritable( "codefont", codeFontSchema, "jetbrains", !window.localStorage, ); export const codeFonts: { storedName: CodeFont; fontFamily: string; displayName: string; }[] = [ { storedName: "jetbrains", fontFamily: "JetBrains Mono, monospace", displayName: "JetBrains Mono", }, { storedName: "system", fontFamily: "monospace", displayName: "System" }, ];