This commit is contained in:
2026-08-11 23:17:04 +07:00
parent bc37ab90f6
commit d7e0d81462
49 changed files with 9023 additions and 91 deletions
+31
View File
@@ -0,0 +1,31 @@
import { ref, watch } from 'vue'
const STORAGE_KEY = 'mws_theme'
const DARK_CLASS = 'app-dark'
const isDark = ref(loadInitial())
function loadInitial(): boolean {
const stored = localStorage.getItem(STORAGE_KEY)
if (stored === 'dark') return true
if (stored === 'light') return false
return window.matchMedia('(prefers-color-scheme: dark)').matches
}
function apply(value: boolean) {
document.documentElement.classList.toggle(DARK_CLASS, value)
}
apply(isDark.value)
watch(isDark, (value) => {
apply(value)
localStorage.setItem(STORAGE_KEY, value ? 'dark' : 'light')
})
export function useTheme() {
function toggle() {
isDark.value = !isDark.value
}
return { isDark, toggle }
}