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

Function gradientStopUtility

packages/tailwindcss/src/utilities.ts:2993–3053  ·  view source on GitHub ↗
(classRoot: string, desc: GradientStopDescription)

Source from the content-addressed store, hash-verified

2991 }
2992
2993 function gradientStopUtility(classRoot: string, desc: GradientStopDescription) {
2994 utilities.functional(classRoot, (candidate) => {
2995 if (!candidate.value) return
2996
2997 // Arbitrary values
2998 if (candidate.value.kind === 'arbitrary') {
2999 let value: string | null = candidate.value.value
3000 let type =
3001 candidate.value.dataType ?? inferDataType(value, ['color', 'length', 'percentage'])
3002
3003 switch (type) {
3004 case 'length':
3005 case 'percentage': {
3006 if (candidate.modifier) return
3007 return desc.position(value)
3008 }
3009 default: {
3010 value = asColor(value, candidate.modifier, theme)
3011 if (value === null) return
3012
3013 return desc.color(value)
3014 }
3015 }
3016 }
3017
3018 // Known values: Color Stops
3019 {
3020 let value = resolveThemeColor(candidate, theme, ['--background-color', '--color'])
3021 if (value) {
3022 return desc.color(value)
3023 }
3024 }
3025
3026 // Known values: Positions
3027 {
3028 if (candidate.modifier) return
3029 let value = theme.resolve(candidate.value.value, ['--gradient-color-stop-positions'])
3030 if (value) {
3031 return desc.position(value)
3032 } else if (
3033 candidate.value.value[candidate.value.value.length - 1] === '%' &&
3034 isPositiveInteger(candidate.value.value.slice(0, -1))
3035 ) {
3036 return desc.position(candidate.value.value)
3037 }
3038 }
3039 })
3040
3041 suggest(classRoot, () => [
3042 {
3043 values: ['current', 'inherit', 'transparent'],
3044 valueThemeKeys: ['--background-color', '--color'],
3045 modifierThemeKeys: ['--opacity'],
3046 modifiers: Array.from({ length: 21 }, (_, index) => `${index * 5}`),
3047 },
3048 {
3049 values: Array.from({ length: 21 }, (_, index) => `${index * 5}%`),
3050 valueThemeKeys: ['--gradient-color-stop-positions'],

Callers 1

createUtilitiesFunction · 0.85

Calls 7

inferDataTypeFunction · 0.90
isPositiveIntegerFunction · 0.90
asColorFunction · 0.85
resolveThemeColorFunction · 0.85
suggestFunction · 0.85
resolveMethod · 0.80
functionalMethod · 0.45

Tested by

no test coverage detected