3ef8caa319
- 新增 Go + SQLite 后端,支持登录、域名、邮箱、别名、联系人、规则、统计与邮件收发。 - 新增 Webmail 前端,支持多邮箱切换、邮件列表/阅读/写信、附件、搜索、主题切换与个人中心。 - 新增 Docker Compose 部署骨架,补充 Postfix、Dovecot、OpenDKIM、Nginx 配置与部署说明。
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
const THEME_TRANSITION_MS = 180
|
|
let themeTimer: number | undefined
|
|
|
|
export function getInitialTheme() {
|
|
return localStorage.getItem("lanqin:theme") === "dark" || document.documentElement.classList.contains("dark")
|
|
}
|
|
|
|
export function applyTheme(dark: boolean, animated = false) {
|
|
const root = document.documentElement
|
|
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
const updateTheme = () => {
|
|
root.classList.toggle("dark", dark)
|
|
root.style.colorScheme = dark ? "dark" : "light"
|
|
localStorage.setItem("lanqin:theme", dark ? "dark" : "light")
|
|
}
|
|
|
|
if (!animated || reduceMotion) {
|
|
root.classList.remove("theme-transition")
|
|
root.style.removeProperty("--theme-fade-bg")
|
|
updateTheme()
|
|
return
|
|
}
|
|
|
|
if (themeTimer) window.clearTimeout(themeTimer)
|
|
root.style.setProperty("--theme-fade-bg", getComputedStyle(document.body).backgroundColor)
|
|
root.classList.add("theme-transition")
|
|
requestAnimationFrame(() => {
|
|
updateTheme()
|
|
themeTimer = window.setTimeout(() => {
|
|
root.classList.remove("theme-transition")
|
|
root.style.removeProperty("--theme-fade-bg")
|
|
themeTimer = undefined
|
|
}, THEME_TRANSITION_MS)
|
|
})
|
|
}
|