( value: string, modifier: CandidateModifier | null, theme: Theme, )
| 211 | * Resolve a color value + optional opacity modifier to a final color. |
| 212 | */ |
| 213 | export function asColor( |
| 214 | value: string, |
| 215 | modifier: CandidateModifier | null, |
| 216 | theme: Theme, |
| 217 | ): string | null { |
| 218 | if (!modifier) return value |
| 219 | |
| 220 | if (modifier.kind === 'arbitrary') { |
| 221 | return withAlpha(value, modifier.value) |
| 222 | } |
| 223 | |
| 224 | // Check if the modifier exists in the `opacity` theme configuration and use |
| 225 | // that value if so. |
| 226 | let alpha = theme.resolve(modifier.value, ['--opacity']) |
| 227 | if (alpha) { |
| 228 | return withAlpha(value, alpha) |
| 229 | } |
| 230 | |
| 231 | if (!isValidOpacityValue(modifier.value)) { |
| 232 | return null |
| 233 | } |
| 234 | |
| 235 | // The modifier is a bare value like `50`, so convert that to `50%`. |
| 236 | return withAlpha(value, `${modifier.value}%`) |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Finds a color in the theme under one of the given theme keys that matches |
no test coverage detected