| 51 | type CSSVariables = Record<YaakColorKey, string | undefined>; |
| 52 | |
| 53 | function themeVariables( |
| 54 | theme: Theme, |
| 55 | component?: ComponentName, |
| 56 | base?: CSSVariables, |
| 57 | ): CSSVariables | null { |
| 58 | const cmp = |
| 59 | component == null |
| 60 | ? theme.base |
| 61 | : (theme.components?.[component] ?? ({} as ThemeComponentColors)); |
| 62 | const color = (value: string | undefined) => yc(theme, value); |
| 63 | const vars: CSSVariables = { |
| 64 | surface: cmp.surface, |
| 65 | surfaceHighlight: cmp.surfaceHighlight ?? color(cmp.surface)?.lift(0.06).css(), |
| 66 | surfaceActive: cmp.surfaceActive ?? color(cmp.primary)?.lower(0.2).translucify(0.8).css(), |
| 67 | backdrop: cmp.backdrop ?? color(cmp.surface)?.lower(0.2).translucify(0.2).css(), |
| 68 | selection: cmp.selection ?? color(cmp.primary)?.lower(0.1).translucify(0.7).css(), |
| 69 | border: cmp.border ?? color(cmp.surface)?.lift(0.11)?.css(), |
| 70 | borderSubtle: cmp.borderSubtle ?? color(cmp.border)?.lower(0.06)?.css(), |
| 71 | borderFocus: color(cmp.info)?.translucify(0.5)?.css(), |
| 72 | text: cmp.text, |
| 73 | textSubtle: cmp.textSubtle ?? color(cmp.text)?.lower(0.2)?.css(), |
| 74 | textSubtlest: cmp.textSubtlest ?? color(cmp.text)?.lower(0.3)?.css(), |
| 75 | shadow: |
| 76 | cmp.shadow ?? |
| 77 | YaakColor.black() |
| 78 | .translucify(theme.dark ? 0.7 : 0.93) |
| 79 | .css(), |
| 80 | primary: cmp.primary, |
| 81 | secondary: cmp.secondary, |
| 82 | info: cmp.info, |
| 83 | success: cmp.success, |
| 84 | notice: cmp.notice, |
| 85 | warning: cmp.warning, |
| 86 | danger: cmp.danger, |
| 87 | }; |
| 88 | |
| 89 | for (const [key, value] of Object.entries(vars)) { |
| 90 | if (!value && base?.[key as YaakColorKey]) { |
| 91 | vars[key as YaakColorKey] = base[key as YaakColorKey]; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return vars; |
| 96 | } |
| 97 | |
| 98 | function templateTagColorVariables(color: YaakColor | null): Partial<CSSVariables> { |
| 99 | if (color == null) return {}; |