MCPcopy
hub / github.com/tailwindlabs/tailwindcss / asColor

Function asColor

packages/tailwindcss/src/utilities.ts:213–237  ·  view source on GitHub ↗
(
  value: string,
  modifier: CandidateModifier | null,
  theme: Theme,
)

Source from the content-addressed store, hash-verified

211 * Resolve a color value + optional opacity modifier to a final color.
212 */
213export 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

Callers 7

compileBaseUtilityFunction · 0.90
resolveThemeColorFunction · 0.85
colorUtilityFunction · 0.85
borderSideUtilityFunction · 0.85
createUtilitiesFunction · 0.85
gradientStopUtilityFunction · 0.85
maskStopUtilityFunction · 0.85

Calls 3

isValidOpacityValueFunction · 0.90
withAlphaFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected