feat(embed): Support dark mode (wip)

This commit is contained in:
kakkokari-gtyih
2024-11-19 17:58:48 +09:00
committed by Samuel Newman
parent 48c5341644
commit 139683fab1
10 changed files with 139 additions and 49 deletions
+17
View File
@@ -0,0 +1,17 @@
export function applyTheme(theme: 'light' | 'dark') {
document.documentElement.classList.remove('light', 'dark')
document.documentElement.classList.add(theme)
}
export function initColorMode() {
applyTheme(
window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light',
)
window
.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', mql => {
applyTheme(mql.matches ? 'dark' : 'light')
})
}