전 저장소 리팩터링과 SSOT 정비
This commit is contained in:
parent
14ecbd4e7d
commit
3dfddcac6f
173 changed files with 19679 additions and 6952 deletions
|
|
@ -1,6 +1,7 @@
|
|||
export type AppTheme = "light" | "dark";
|
||||
|
||||
export const THEME_KEY = "vignette.theme";
|
||||
const themeListeners = new Set<() => void>();
|
||||
|
||||
export function readInitialTheme(): AppTheme {
|
||||
try {
|
||||
|
|
@ -14,12 +15,26 @@ export function readInitialTheme(): AppTheme {
|
|||
}
|
||||
|
||||
export function applyTheme(theme: AppTheme) {
|
||||
const changed = document.documentElement.getAttribute("data-theme") !== theme;
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
try {
|
||||
localStorage.setItem(THEME_KEY, theme);
|
||||
} catch {
|
||||
/* 저장 실패는 렌더링을 막지 않는다. */
|
||||
}
|
||||
if (changed) themeListeners.forEach((listener) => listener());
|
||||
}
|
||||
|
||||
/** React와 비 React 진입점이 함께 쓰는 현재 적용 테마 snapshot. */
|
||||
export function readAppliedTheme(): AppTheme {
|
||||
const applied = document.documentElement.getAttribute("data-theme");
|
||||
return applied === "light" || applied === "dark" ? applied : readInitialTheme();
|
||||
}
|
||||
|
||||
/** 앱 전역 테마 store 구독. 테마 상태의 유일한 알림 경로다. */
|
||||
export function subscribeTheme(listener: () => void) {
|
||||
themeListeners.add(listener);
|
||||
return () => themeListeners.delete(listener);
|
||||
}
|
||||
|
||||
export function initTheme() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue