This commit is contained in:
eric
2026-05-20 18:45:21 -05:00
parent 6809f833f8
commit fdd456864b
11 changed files with 405 additions and 261 deletions

29
lib/theme.ts Normal file
View File

@@ -0,0 +1,29 @@
export type Theme = "light" | "dark";
export const THEME_STORAGE_KEY = "theme";
declare global {
interface Window {
NomadRoamTheme?: {
apply: (theme: Theme) => void;
toggle: () => void;
read: () => Theme;
};
}
}
export function applyTheme(theme: Theme) {
if (typeof window !== "undefined" && window.NomadRoamTheme) {
window.NomadRoamTheme.apply(theme);
}
}
export function readThemeFromDom(): Theme {
if (typeof window !== "undefined" && window.NomadRoamTheme) {
return window.NomadRoamTheme.read();
}
if (typeof document === "undefined") return "light";
return document.documentElement.getAttribute("data-theme") === "dark"
? "dark"
: "light";
}