Added more things
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 34s

This commit is contained in:
2026-03-20 00:07:23 +01:00
parent b1c5535420
commit 2def9a207c
9 changed files with 425 additions and 27 deletions

View File

@@ -0,0 +1,47 @@
import { ref, onMounted, watch } from 'vue'
type Theme = 'light' | 'dark'
type Accent = 'alfdir'
const theme = ref<Theme>('light')
const accent = ref<Accent>('alfdir')
const applyTheme = () => {
document.documentElement.setAttribute('data-theme', theme.value)
document.documentElement.setAttribute('data-accent', accent.value)
}
const setTheme = (value: Theme) => {
theme.value = value
localStorage.setItem('theme', value)
applyTheme();
}
const setAccent = (value: Accent) => {
accent.value = value
localStorage.setItem('accent', value)
applyTheme();
}
const setupTheme = () => {
const savedTheme = localStorage.getItem('theme') as Theme | null
const savedAccent = localStorage.getItem('accent') as Accent | null
const media = window.matchMedia('(prefers-color-scheme: dark)')
theme.value = savedTheme || (media.matches ? 'dark' : 'light')
accent.value = savedAccent || 'alfdir'
applyTheme()
media.addEventListener('change', (e) => {
if (!localStorage.getItem('theme')) {
theme.value = e.matches ? 'dark' : 'light'
applyTheme()
}
})
};
watch([theme, accent], applyTheme)
export { theme, accent, setTheme, setAccent, setupTheme}