// packages/ui/src/theme-vars.ts // 팝업 윈도우용 CSS 변수 맵. // main process (WindowManager)에서 insertCSS로 팝업에 테마를 주입할 때 사용. // 값은 theme-raw.ts(렌더러와 같은 원시값)에서 파생한다 — 손으로 복제하지 않는다. // Node.js/Electron main 환경에서 import 가능 (MUI·DOM 의존 없음). import { RAW, STATUS, buildCssVars, isThemeKey, type ThemeKey } from './theme-raw' export type PopupThemeKey = ThemeKey /** * 팝업 CSS 가 쓰는 전용 별칭. 렌더러 공통 변수(buildCssVars) 위에 얹는다. * v4: 팝업도 평면 — 반투명 배경·다색 파형을 쓰지 않는다. */ function popupAliases(key: ThemeKey): Record { const r = RAW[key] const st = STATUS[key] const wave: Record = {} for (let i = 1; i <= 9; i++) wave[`--d3-wave-${i}`] = r.accent.main return { '--d3-bg-tip': r.bg.card, '--d3-shadow-popup': r.shadow.overlay, '--d3-bg-result': r.bg.card, '--d3-border-result': r.border.default, '--d3-text-result': r.text.primary, '--d3-action-btn': r.text.secondary, '--d3-action-btn-hover-bg': 'var(--d3-overlay-soft)', '--d3-action-btn-hover': r.text.primary, '--d3-accent-glow-dim': r.accent.dim, '--d3-status-error': st.danger, ...wave, } } /** ThemeMode('system' | 'auto' | 테마 키)를 팝업 테마 키로. 시스템 모드는 호출자가 prefersDark 를 넘긴다. */ export function resolvePopupThemeKey(themeKey: string, prefersDark = true): PopupThemeKey { if (isThemeKey(themeKey)) return themeKey if (themeKey === 'system' || themeKey === 'auto') return prefersDark ? 'dark' : 'light' return 'dark' } /** 팝업용 CSS 변수 맵 조회. 알 수 없는 값은 'dark'. */ export function getPopupThemeVars(themeKey: string, prefersDark = true): Record { const key = resolvePopupThemeKey(themeKey, prefersDark) return { ...buildCssVars(key), ...popupAliases(key) } } /** * 팝업 BrowserWindow에 insertCSS로 주입할 CSS 문자열 반환. * `:root { --d3-bg-card: #111a30; ... }` */ export function buildPopupThemeCss(themeKey: string, prefersDark = true): string { const vars = getPopupThemeVars(themeKey, prefersDark) const declarations = Object.entries(vars) .map(([prop, value]) => ` ${prop}: ${value};`) .join('\n') return `:root {\n${declarations}\n}` }