mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-28 17:50:28 +08:00
Also moving the svelte-stored-writable package into the repo. So we have it closer for maintenance, we can eventually rewrite it in svelte 5 runes later. Reference: https://github.com/efstajas/svelte-stored-writable/pull/5
48 lines
1.1 KiB
TypeScript
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",
|
|
displayName: "JetBrains Mono",
|
|
},
|
|
{ storedName: "system", fontFamily: "monospace", displayName: "System" },
|
|
];
|