30 lines
709 B
TypeScript
30 lines
709 B
TypeScript
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";
|
|
}
|