d3ro-voice/packages/ui/src/theme.ts
Yun Chan 2428ede03d feat(ui): flat "quiet instrument" token v4 with a single raw-value SSOT
- Add theme-raw.ts (no MUI/DOM deps) as the one source of theme values.
  Each theme declares only surfaces, 3-tier text, borders, accent and
  overlay shadow; legacy glass/gradient/glow/crt keys are derived as
  flat values so existing call sites lose effects without edits.
- Tertiary text now clears 4.5:1 on every surface in all six themes
  (label/inactive/dimLabel/muted alias it). Filled buttons use
  accent.solid + accent.ink (5.17:1 on dark/light, was 3.68:1).
- theme-vars.ts derives popup CSS from the same raw values instead of a
  hand copy, and defines the previously undefined --d3-overlay-strong
  and --d3-accent-glow-dim.
- MUI: no ripple, global focus-visible ring and reduced-motion rule,
  flat Card, status colors per theme, shape radius 16 -> 6.
- DS: flatten MetalCard/DoubleBezelCard/ScreenPanel/TiltCard, tone-based
  PhysicalButton (500 weight, no lift), TactileBadge with zero tracking
  and keyboard support, glow-free Led/StatRing, idle wave amplitude 0.
- PhosphorText drops mono/uppercase variants: mono has no Hangul glyphs,
  which spaced out Korean labels.
- design.md: record the 2026-09-28 redesign brief, audit, IA and tokens.
2026-09-28 18:26:03 +09:00

485 lines
19 KiB
TypeScript

// packages/ui/src/theme.ts
// D3RO 디자인 시스템 SSOT — v4 "조용한 계기" (2026-09-28).
// 원시값은 theme-raw.ts 한 곳에 있다. 이 파일은 그 값을 CSS 변수 참조(d3roPalette)와 MUI 테마로 노출한다.
// d3roPalette 가 var() 를 쓰므로 테마를 바꾸면 컴포넌트가 자동으로 따라간다.
//
// v4 디자인 언어 (루트 design.md "2026-09-28 전면 개편"):
// - 평평한 표면 + 1px 선. 글래스·글로우·그라디언트는 쓰지 않는다(키는 호환용으로 남고 평면 값이 들어 있다).
// - 텍스트 3단(primary/secondary/tertiary). label/inactive/dimLabel/muted 는 tertiary 의 별칭.
// - 강조색은 주 행동·현재 위치·포커스·녹음 상태에만.
import { createTheme, type Theme } from '@mui/material/styles'
import type { ThemeMode } from '@d3ro/core/types'
import {
RAW,
STATUS,
TAG,
SPACE,
CONTROL,
WEIGHT,
MOTION,
RADIUS,
FONT_SANS,
FONT_MONO,
buildCssVars,
type ThemeKey,
type RawTheme,
} from './theme-raw'
export type { ThemeKey, RawTheme } from './theme-raw'
// ── SSOT: d3roPalette — CSS Custom Properties로 테마 반응형 ──
// 컴포넌트에서 이 객체만 import하면 테마 자동 전환.
export const d3roPalette = {
bg: {
app: 'var(--d3-bg-app)',
card: 'var(--d3-bg-card)',
cardHover: 'var(--d3-bg-cardHover)',
elevated: 'var(--d3-bg-elevated)',
input: 'var(--d3-bg-input)',
sidebar: 'var(--d3-bg-sidebar)',
inset: 'var(--d3-bg-inset)',
/** @deprecated v4: bg.card 와 같다 */
chassis: 'var(--d3-bg-chassis)',
/** @deprecated v4: bg.inset 와 같다 */
crtBezel: 'var(--d3-bg-crtBezel)',
/** @deprecated v4: bg.inset 와 같다 */
crtGlass: 'var(--d3-bg-crtGlass)',
},
accent: {
main: 'var(--d3-accent-main)',
/** 표면 위 강조 글자·아이콘 (모든 테마에서 4.5:1 이상) */
light: 'var(--d3-accent-light)',
dark: 'var(--d3-accent-dark)',
dim: 'var(--d3-accent-dim)',
glow: 'var(--d3-accent-glow)',
/** 채운 버튼 배경 */
solid: 'var(--d3-accent-solid)',
solidHover: 'var(--d3-accent-solidHover)',
/** accent.solid 위 글자색 */
ink: 'var(--d3-accent-ink)',
},
/** @deprecated v4: 평면 값이 들어 있다. 새 코드는 bg/border 를 쓴다 */
glass: {
surface: 'var(--d3-glass-surface)',
raised: 'var(--d3-glass-raised)',
hairline: 'var(--d3-glass-hairline)',
hairlineStrong: 'var(--d3-glass-hairlineStrong)',
sheen: 'var(--d3-glass-sheen)',
borderGradient: 'var(--d3-glass-borderGradient)',
blur: 'var(--d3-glass-blur)',
specular: 'var(--d3-glass-specular)',
},
/** @deprecated v4: 단색으로 파생된다. 새 코드는 accent 를 쓴다 */
gradient: {
accent: 'var(--d3-gradient-accent)',
logo: 'var(--d3-gradient-logo)',
bar: 'var(--d3-gradient-bar)',
barAlt: 'var(--d3-gradient-barAlt)',
wave1: 'var(--d3-gradient-wave1)',
wave2: 'var(--d3-gradient-wave2)',
wave3: 'var(--d3-gradient-wave3)',
wave4: 'var(--d3-gradient-wave4)',
},
/** @deprecated v4: 전부 none */
glow: {
accent: 'var(--d3-glow-accent)',
soft: 'var(--d3-glow-soft)',
card: 'var(--d3-glow-card)',
cardHover: 'var(--d3-glow-cardHover)',
},
/** 시맨틱 상태 역할 (테마 반응, 텍스트로 써도 대비 유지) */
status: {
success: 'var(--d3-status-success)',
successBg: 'var(--d3-status-successBg)',
warning: 'var(--d3-status-warning)',
warningBg: 'var(--d3-status-warningBg)',
danger: 'var(--d3-status-danger)',
dangerBg: 'var(--d3-status-dangerBg)',
info: 'var(--d3-status-info)',
infoBg: 'var(--d3-status-infoBg)',
},
/** 반투명 표면·오버레이·스크림 역할 */
surface: {
insetSoft: 'var(--d3-bg-inset-soft)',
cardSoft: 'var(--d3-bg-card-soft)',
raisedSoft: 'var(--d3-bg-raised-soft)',
scrim: 'var(--d3-scrim)',
overlaySoft: 'var(--d3-overlay-soft)',
overlayStrong: 'var(--d3-overlay-strong)',
},
/** 테마 불변 카테고리색 — 글자가 아닌 점·아이콘·범례용. 상태 글자는 status 를 쓴다 */
tag: TAG,
text: {
primary: 'var(--d3-text-primary)',
secondary: 'var(--d3-text-secondary)',
/** 3차 텍스트 — 메타·라벨·힌트 (모든 표면에서 4.5:1 이상) */
tertiary: 'var(--d3-text-tertiary)',
inverse: 'var(--d3-text-inverse, #ffffff)',
/** @deprecated v4: tertiary 별칭 */
label: 'var(--d3-text-label)',
disabled: 'var(--d3-text-disabled)',
/** @deprecated v4 */
engraving: 'var(--d3-text-engraving)',
/** @deprecated v4: tertiary 별칭 */
inactive: 'var(--d3-text-inactive)',
/** @deprecated v4: tertiary 별칭 */
dimLabel: 'var(--d3-text-dimLabel)',
/** @deprecated v4: tertiary 별칭 */
muted: 'var(--d3-text-muted)',
hover: 'var(--d3-text-hover)',
},
border: {
subtle: 'var(--d3-border-subtle)',
default: 'var(--d3-border-default)',
strong: 'var(--d3-border-strong)',
},
/** @deprecated v4 */
crt: {
phosphor: 'var(--d3-accent-crtPhosphor)',
phosphorDim: 'var(--d3-accent-crtPhosphorDim)',
scanline: 'transparent',
bg: 'var(--d3-bg-chassis)',
},
led: {
off: 'var(--d3-border-strong)',
},
} as const
export const d3roFontSans = FONT_SANS
/** 숫자·코드·키 이름(라틴) 전용. 한글이 섞일 수 있는 문자열에는 쓰지 않는다. */
export const d3roFontMono = FONT_MONO
// ── SSOT: 타이포그래피 토큰 ─────────────────────────────
// v3 "타이포그래피 퍼스트" 유지 + v4 보정:
// - 볼드(700+) 없음. 헤드라인 500, 몸통 400, 라벨 500.
// - 한글 행간 1.5~1.7, 헤드라인도 1.2 이상. 한글 자간 0 — 라벨의 양수 트래킹을 걷어냈다(v4).
// - 한글 최소 11px. engrave/micro 는 한글 라벨로 쓰이므로 11px 로 올렸다(v4). nano(10px)는 라틴 수치 전용.
export const d3roTypo = {
hero: { size: '28px', weight: 500, spacing: '-0.015em', line: 1.3 },
title: { size: '22px', weight: 500, spacing: '-0.01em', line: 1.35 },
value: { size: '20px', weight: 500, spacing: '0', line: 1.2 },
heading: { size: '16px', weight: 500, spacing: '0', line: 1.5 },
body: { size: '14px', weight: 400, spacing: '0', line: 1.6 },
compact: { size: '13px', weight: 400, spacing: '0', line: 1.55 },
small: { size: '12px', weight: 400, spacing: '0', line: 1.5 },
meta: { size: '12px', weight: 400, spacing: '0', line: 1.45 },
label: { size: '11px', weight: 500, spacing: '0', line: 1.4 },
engrave: { size: '11px', weight: 500, spacing: '0', line: 1.4 },
micro: { size: '11px', weight: 500, spacing: '0', line: 1.4 },
nano: { size: '10px', weight: 500, spacing: '0.02em', line: 1.2 },
} as const
/**
* d3roTypo의 `{ size, weight, spacing, line }` 포맷을 MUI `sx` 호환
* `{ fontSize, fontWeight, letterSpacing, lineHeight }`로 변환하는 헬퍼.
*/
export function typoSx(key: keyof typeof d3roTypo): {
fontSize: string
fontWeight: number
letterSpacing: string
lineHeight: number
} {
const v = d3roTypo[key]
return {
fontSize: v.size,
fontWeight: v.weight,
letterSpacing: v.spacing,
lineHeight: v.line,
}
}
// ── SSOT: 그림자 토큰 ───────────────────────────────────
// v4: 표면에는 그림자가 없다. 그림자는 떠 있는 층(메뉴·다이얼로그·툴팁·플로팅 버튼)에만 — overlay/tooltip.
export const d3roShadow = {
/** 떠 있는 층: 다이얼로그·메뉴·팝오버·플로팅 버튼 */
overlay: 'var(--d3-shadow-overlay)',
tooltip: 'var(--d3-shadow-tooltip)',
/** @deprecated v4: none */
chassis: 'var(--d3-shadow-chassis)',
/** @deprecated v4: none — 카드는 1px 선으로 구분한다 */
card: 'var(--d3-shadow-card)',
/** @deprecated v4: none */
inset: 'var(--d3-shadow-inset)',
/** @deprecated v4: none */
insetDeep: 'var(--d3-shadow-insetDeep)',
/** @deprecated v4: none */
buttonRaised: 'var(--d3-shadow-buttonRaised)',
/** @deprecated v4: none */
buttonPressed: 'var(--d3-shadow-buttonPressed)',
/** @deprecated v4: none */
buttonActive: 'var(--d3-shadow-buttonPressed)',
dialog: 'var(--d3-shadow-overlay)',
/** @deprecated v4: none */
screenGlow: 'var(--d3-shadow-screenGlow)',
/** @deprecated v4: none */
glowAccent: 'var(--d3-glow-accent)',
/** @deprecated v4: none */
glowSoft: 'var(--d3-glow-soft)',
/** @deprecated v4: none */
glowCard: 'var(--d3-glow-card)',
/** @deprecated v4: none */
glowCardHover: 'var(--d3-glow-cardHover)',
islandFloat: 'var(--d3-shadow-overlay)',
} as const
// ── SSOT: 반경 · 간격 · 컨트롤 · 웨이트 · 모션 ─────────────────
export const d3roRadius = RADIUS
export const d3roSpace = SPACE
export const d3roControl = CONTROL
export const d3roWeight = WEIGHT
export const d3roMotion = MOTION
/** 상태 변화 트랜지션 한 줄 — 컴포넌트마다 duration/easing 을 새로 적지 않는다. */
export function d3roTransition(...props: string[]): string {
return props.map((p) => `${p} ${MOTION.quick} ${MOTION.easeOut}`).join(', ')
}
/** 숫자 정렬 계약 — 수치가 흔들리면 계기판이 아니다. */
export const d3roNumeralSx = {
fontVariantNumeric: 'tabular-nums' as const,
} as const
/** 키보드 포커스 링 — 모든 상호작용 요소에 같은 모양. */
export const d3roFocusRing = {
outline: `2px solid ${d3roPalette.accent.main}`,
outlineOffset: '2px',
} as const
// ── 테마 팩토리 ───────────────────────────────────────────
function createD3ROTheme(key: ThemeKey): Theme {
// MUI palette.mode는 'dark' | 'light'만 허용. light 외 모두 dark 기반.
const muiMode: 'dark' | 'light' = key === 'light' ? 'light' : 'dark'
const r = RAW[key]
const st = STATUS[key]
const cssVars = buildCssVars(key)
const quick = `${MOTION.quick} ${MOTION.easeOut}`
return createTheme({
palette: {
mode: muiMode,
primary: { main: r.accent.solid, light: r.accent.light, dark: r.accent.solidHover, contrastText: r.accent.ink },
secondary: { main: r.text.secondary, contrastText: r.bg.app },
error: { main: st.danger },
warning: { main: st.warning },
success: { main: st.success },
info: { main: st.info },
background: { default: r.bg.app, paper: r.bg.card },
text: { primary: r.text.primary, secondary: r.text.secondary, disabled: r.text.disabled },
divider: r.border.default,
action: { hover: 'var(--d3-overlay-soft)', selected: r.accent.dim },
},
typography: {
fontFamily: FONT_SANS,
h4: { fontWeight: 500, fontSize: '22px', lineHeight: 1.35 },
h5: { fontWeight: 500, fontSize: '18px', lineHeight: 1.45 },
h6: { fontWeight: 500, fontSize: '16px', lineHeight: 1.5 },
subtitle1: { fontWeight: 500, fontSize: '16px', lineHeight: 1.5 },
body1: { fontSize: '14px', lineHeight: 1.6 },
body2: { fontSize: '13px', lineHeight: 1.55 },
button: { textTransform: 'none' as const, fontWeight: 500, fontSize: '13px' },
caption: { fontSize: '12px', fontWeight: 400, letterSpacing: 0, color: r.text.tertiary },
overline: { fontSize: '11px', fontWeight: 500, letterSpacing: 0, textTransform: 'none' as const, lineHeight: 1.4 },
},
// sx 의 borderRadius 숫자 배수 기준. 1 = 6px.
shape: { borderRadius: 6 },
components: {
MuiCssBaseline: {
styleOverrides: {
':root': cssVars,
body: { backgroundColor: r.bg.app, color: r.text.primary },
// 네이티브 스크롤바 제거 (레이아웃 폭 불변). 시각적 인디케이터는 OverlayScrollbars 가 담당.
'*::-webkit-scrollbar': { width: 0, height: 0, background: 'transparent' },
':focus-visible': { outline: `2px solid ${r.accent.main}`, outlineOffset: '2px' },
'@media (prefers-reduced-motion: reduce)': {
'*, *::before, *::after': {
animationDuration: '0.01ms !important',
animationIterationCount: '1 !important',
transitionDuration: '0.01ms !important',
scrollBehavior: 'auto !important',
},
},
},
},
MuiButtonBase: { defaultProps: { disableRipple: true } },
MuiButton: {
defaultProps: { disableElevation: true },
styleOverrides: {
root: {
textTransform: 'none', fontWeight: 500, borderRadius: RADIUS.button,
minHeight: CONTROL.h, padding: `0 ${CONTROL.padX}`,
transition: `background-color ${quick}, border-color ${quick}, color ${quick}`,
},
sizeSmall: { minHeight: CONTROL.hSm, padding: `0 ${CONTROL.padXSm}` },
containedPrimary: {
color: r.accent.ink,
backgroundColor: r.accent.solid,
'&:hover': { backgroundColor: r.accent.solidHover },
},
outlined: {
borderColor: r.border.strong,
backgroundColor: 'transparent',
color: r.text.primary,
'&:hover': { borderColor: r.border.strong, backgroundColor: 'var(--d3-overlay-soft)' },
},
text: {
color: r.text.secondary,
'&:hover': { color: r.text.primary, backgroundColor: 'var(--d3-overlay-soft)' },
},
containedSecondary: {
backgroundColor: r.bg.elevated,
color: r.text.primary,
border: `1px solid ${r.border.default}`,
'&:hover': { backgroundColor: r.bg.cardHover },
},
},
},
MuiIconButton: {
styleOverrides: {
root: {
borderRadius: RADIUS.button,
color: r.text.secondary,
'&:hover': { color: r.text.primary, backgroundColor: 'var(--d3-overlay-soft)' },
},
},
},
MuiCard: {
defaultProps: { elevation: 0 },
styleOverrides: {
root: {
backgroundColor: r.bg.card,
border: `1px solid ${r.border.default}`,
borderRadius: RADIUS.card,
boxShadow: 'none',
},
},
},
MuiChip: {
styleOverrides: {
root: { borderRadius: RADIUS.small, fontWeight: 500, fontSize: '12px', letterSpacing: 0, height: 24 },
colorPrimary: { backgroundColor: r.accent.dim, color: r.accent.light },
colorSecondary: { backgroundColor: 'var(--d3-overlay-soft)', color: r.text.secondary },
colorSuccess: { backgroundColor: st.successBg, color: st.success },
colorError: { backgroundColor: st.dangerBg, color: st.danger },
colorWarning: { backgroundColor: st.warningBg, color: st.warning },
colorInfo: { backgroundColor: st.infoBg, color: st.info },
},
},
MuiDrawer: { styleOverrides: { paper: { width: 240, backgroundColor: r.bg.sidebar, borderRight: `1px solid ${r.border.default}` } } },
MuiListItemButton: {
styleOverrides: {
root: {
borderRadius: RADIUS.button, marginLeft: 8, marginRight: 8,
'&.Mui-selected': { backgroundColor: r.accent.dim, color: r.accent.light, fontWeight: 500, '&:hover': { backgroundColor: r.accent.dim } },
},
},
},
MuiDialog: {
styleOverrides: {
paper: {
backgroundColor: r.bg.card, borderRadius: RADIUS.outer,
backgroundImage: 'none',
border: `1px solid ${r.border.default}`,
boxShadow: r.shadow.overlay,
},
},
},
MuiBackdrop: {
styleOverrides: {
root: {
backgroundColor: muiMode === 'dark' ? 'rgba(4,8,20,0.6)' : 'rgba(17,24,39,0.32)',
'&.MuiBackdrop-invisible': { backgroundColor: 'transparent' },
},
},
},
MuiPopover: { styleOverrides: { paper: { border: `1px solid ${r.border.default}`, boxShadow: r.shadow.overlay, borderRadius: RADIUS.inner } } },
MuiMenu: { styleOverrides: { paper: { border: `1px solid ${r.border.default}`, boxShadow: r.shadow.overlay, borderRadius: RADIUS.inner } } },
MuiTextField: {
defaultProps: { size: 'small', variant: 'outlined' },
styleOverrides: {
root: {
'& .MuiOutlinedInput-root': {
backgroundColor: r.bg.input, borderRadius: RADIUS.button,
color: r.text.primary,
'& fieldset': { borderColor: r.border.default },
'&:hover fieldset': { borderColor: r.border.strong },
'&.Mui-focused fieldset': { borderColor: r.accent.main, borderWidth: 1 },
},
},
},
},
MuiSelect: {
styleOverrides: {
select: { color: r.text.primary },
icon: { color: r.text.secondary },
},
},
MuiInputLabel: {
styleOverrides: {
root: { color: r.text.secondary, '&.Mui-focused': { color: r.accent.light } },
},
},
MuiFormControlLabel: {
styleOverrides: {
label: { color: r.text.primary, fontSize: '14px' },
},
},
MuiSwitch: {
styleOverrides: {
switchBase: {
'&.Mui-checked': { color: r.accent.ink },
'&.Mui-checked + .MuiSwitch-track': { backgroundColor: r.accent.solid, opacity: 1 },
},
track: { backgroundColor: r.text.tertiary },
},
},
MuiMenuItem: {
styleOverrides: {
root: {
color: r.text.primary,
fontSize: '13px',
'&.Mui-selected': { backgroundColor: r.accent.dim },
},
},
},
MuiTooltip: {
defaultProps: { arrow: false, enterDelay: 400 },
styleOverrides: {
tooltip: { backgroundColor: r.bg.elevated, color: r.text.primary, fontSize: '12px', fontWeight: 400, borderRadius: RADIUS.small, border: `1px solid ${r.border.default}`, boxShadow: r.shadow.tooltip },
},
},
MuiTabs: { styleOverrides: { indicator: { backgroundColor: r.accent.main, height: 2, borderRadius: 0 } } },
MuiTab: { styleOverrides: { root: { textTransform: 'none', fontWeight: 400, fontSize: '13px', minHeight: 40, color: r.text.secondary, '&.Mui-selected': { color: r.text.primary, fontWeight: 500 } } } },
MuiAlert: { styleOverrides: { root: { borderRadius: RADIUS.inner, fontSize: '13px' } } },
MuiPaper: {
styleOverrides: {
root: { backgroundImage: 'none' },
},
},
},
})
}
// ── Export ─────────────────────────────────────────────────
export const themes: Record<ThemeKey, Theme> = {
dark: createD3ROTheme('dark'),
light: createD3ROTheme('light'),
nord: createD3ROTheme('nord'),
solarized: createD3ROTheme('solarized'),
catppuccin: createD3ROTheme('catppuccin'),
dracula: createD3ROTheme('dracula'),
}
// 하위 호환 export
export const darkTheme = themes.dark
export const lightTheme = themes.light
export function getTheme(mode: ThemeMode, prefersDark = true): Theme {
if (mode === 'auto') return prefersDark ? themes.dark : themes.light
return themes[mode as ThemeKey] ?? themes.dark
}
export function getModePalette(mode: ThemeMode): RawTheme {
return RAW[mode as ThemeKey] ?? RAW.dark
}