Add built-in white and black themes

This commit is contained in:
eezd committed 2026-10-20 10:26:49 +08:00
1 parent 7f65162115
commit 9fd7e2a948
6 files changed
+103 -5

No files matched your search

+6 -1
View File
@@ -13,6 +13,11 @@ export interface Appearance {
export const appearancePaused = new URLSearchParams(location.search).has('reset-appearance')
export function fixedThemeMode(theme: string): 'light' | 'dark' | undefined {
if (theme === 'white') return 'light'
if (theme === 'black') return 'dark'
}
export function sanitizeAppearance(raw: Record<string, unknown>): Appearance {
return {
colorMode: raw.colorMode === 'light' || raw.colorMode === 'dark' ? raw.colorMode : 'system',
@@ -40,7 +45,7 @@ function style(id: string, css: string) {
}
function render() {
const mode = appearancePaused ? 'system' : current.colorMode
const mode = appearancePaused ? 'system' : fixedThemeMode(current.theme) ?? current.colorMode
const dark = mode === 'system' ? darkMode.matches : mode === 'dark'
const signature = JSON.stringify([dark, appearancePaused ? '' : [current.theme, themeCSS, current.cssSnippets]])
if (signature === rendered) return