(variant: ThemeVariant, isDark: boolean)
| 2 | import { blend, generateNeutralScale, generateScale, hexToOklch, hexToRgb, shift, withAlpha } from "./color" |
| 3 | |
| 4 | export function resolveThemeVariant(variant: ThemeVariant, isDark: boolean): ResolvedTheme { |
| 5 | const colors = getColors(variant) |
| 6 | const { overrides = {} } = variant |
| 7 | |
| 8 | const neutral = generateNeutralScale(colors.neutral, isDark, colors.ink) |
| 9 | const primary = generateScale(colors.primary, isDark) |
| 10 | const accent = generateScale(colors.accent, isDark) |
| 11 | const success = generateScale(colors.success, isDark) |
| 12 | const warning = generateScale(colors.warning, isDark) |
| 13 | const error = generateScale(colors.error, isDark) |
| 14 | const info = generateScale(colors.info, isDark) |
| 15 | const interactive = generateScale(colors.interactive, isDark) |
| 16 | const amber = generateScale( |
| 17 | shift(colors.warning, isDark ? { h: -16, l: -0.058, c: 1.14 } : { h: -22, l: -0.082, c: 0.94 }), |
| 18 | isDark, |
| 19 | ) |
| 20 | const blue = generateScale(shift(colors.interactive, { h: -12, l: 0.128, c: 1.12 }), isDark) |
| 21 | const diffAdd = generateScale( |
| 22 | colors.diffAdd ?? shift(colors.success, { c: isDark ? 0.7 : 0.55, l: isDark ? -0.18 : 0.14 }), |
| 23 | isDark, |
| 24 | ) |
| 25 | const diffDelete = generateScale( |
| 26 | colors.diffDelete ?? shift(colors.error, { c: isDark ? 0.82 : 0.7, l: isDark ? -0.08 : 0.08 }), |
| 27 | isDark, |
| 28 | ) |
| 29 | const ink = colors.ink ?? colors.neutral |
| 30 | const tint = colors.compact ? hexToOklch(ink) : undefined |
| 31 | const body = tint |
| 32 | ? shift(ink, { |
| 33 | l: isDark ? Math.max(0, 0.88 - tint.l) * 0.4 : -Math.max(0, tint.l - 0.18) * 0.24, |
| 34 | c: isDark ? 1.04 : 1.02, |
| 35 | }) |
| 36 | : undefined |
| 37 | const backgroundOverride = overrides["background-base"] |
| 38 | const backgroundHex = getHex(backgroundOverride) |
| 39 | const overlay = Boolean(backgroundOverride) && !backgroundHex |
| 40 | const content = (seed: HexColor, scale: HexColor[]) => { |
| 41 | const base = hexToOklch(seed) |
| 42 | const value = isDark ? (base.l > 0.84 ? shift(seed, { c: 1.18 }) : scale[10]) : scale[10] |
| 43 | return shift(value, { l: isDark ? 0.034 : -0.024, c: isDark ? 1.3 : 1.18 }) |
| 44 | } |
| 45 | const modified = () => { |
| 46 | if (!colors.compact) return isDark ? "#ffba92" : "#FF8C00" |
| 47 | const warningHue = hexToOklch(colors.warning).h |
| 48 | const deleteHue = hexToOklch(colors.diffDelete ?? colors.error).h |
| 49 | const delta = Math.abs(((((deleteHue - warningHue) % 360) + 540) % 360) - 180) |
| 50 | if (delta < 48) return isDark ? "#ffba92" : "#FF8C00" |
| 51 | return content(colors.warning, warning) |
| 52 | } |
| 53 | const surface = ( |
| 54 | seed: HexColor, |
| 55 | alpha: { base: number; weak: number; weaker: number; strong: number; stronger: number }, |
| 56 | ) => { |
| 57 | const base = alphaTone(seed, alpha.base) |
| 58 | return { |
| 59 | base, |
| 60 | weak: alphaTone(seed, alpha.weak), |
| 61 | weaker: alphaTone(seed, alpha.weaker), |
no test coverage detected