Files
radicle-explorer/src/lib/appearance.ts
T
Brandon Oxendine 2fd961c6c3 Add monospace fallback to JetBrains Mono fonts
When users block web fonts, code was rendered in the browser's default
sans-serif font because the JetBrains Mono code font tokens had no
generic fallback. Add `monospace` as a fallback so code stays
monospaced.

Fixes: 8942cea33a
2026-10-20 12:27:29 +02:00

48 lines
1.1 KiB
TypeScript

import storedWritable from "@app/lib/localStore";
import { boolean, literal, union, z } from "zod";
const themeSchema = union([literal("dark"), literal("light")]);
type Theme = z.infer<typeof themeSchema>;
export const followSystemTheme = storedWritable<boolean | undefined>(
"followSystemTheme",
boolean(),
!localStorage?.getItem("theme"),
!window.localStorage,
);
export const theme = storedWritable<Theme>(
"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<typeof codeFontSchema>;
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" },
];