( value: ColorValue, defs: Record<string, string>, theme: ThemeJson["theme"], mode: "dark" | "light", )
| 20 | type ColorValue = string | { dark: string; light: string } |
| 21 | |
| 22 | function resolveColor( |
| 23 | value: ColorValue, |
| 24 | defs: Record<string, string>, |
| 25 | theme: ThemeJson["theme"], |
| 26 | mode: "dark" | "light", |
| 27 | ): string { |
| 28 | if (typeof value === "object" && "dark" in value) { |
| 29 | value = value[mode] |
| 30 | } |
| 31 | if (typeof value === "string") { |
| 32 | if (value === "transparent" || value === "none") return "transparent" |
| 33 | if (value.startsWith("#") || value.startsWith("rgba(")) return value |
| 34 | if (defs[value]) return resolveColor(defs[value], defs, theme, mode) |
| 35 | const themeValue = theme[value as keyof typeof theme] |
| 36 | if (themeValue) return resolveColor(themeValue as ColorValue, defs, theme, mode) |
| 37 | } |
| 38 | return value as string |
| 39 | } |
| 40 | |
| 41 | function resolveThemeColors(themeJson: ThemeJson, mode: "dark" | "light"): Record<string, string> { |
| 42 | const defs = themeJson.defs ?? {} |
no outgoing calls
no test coverage detected