feat: sync embedded analytics theme with parent app

This commit is contained in:
2026-04-02 20:11:33 +08:00
parent 1b5977a420
commit cc66034e59
8 changed files with 219 additions and 44 deletions

29
lib/theme-sync.ts Normal file
View File

@@ -0,0 +1,29 @@
import type { Theme } from "./theme";
export type ResolvedTheme = "light" | "dark";
export function resolveStoredTheme(
theme: Theme,
prefersDark: boolean,
): ResolvedTheme {
if (theme === "system") {
return prefersDark ? "dark" : "light";
}
return theme;
}
export function resolveIncomingThemeMode(
mode: unknown,
prefersDark: boolean,
): ResolvedTheme | null {
if (mode === "light" || mode === "dark") {
return mode;
}
if (mode === "auto" || mode === "system") {
return prefersDark ? "dark" : "light";
}
return null;
}