Skip to content

Commit d48915b

Browse files
committed
Show colors for mask utilities
1 parent d219f08 commit d48915b

File tree

1 file changed

+14
-3
lines changed
  • packages/tailwindcss-language-service/src/util

1 file changed

+14
-3
lines changed

packages/tailwindcss-language-service/src/util/color.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import namedColors from 'color-name'
1010
import { replaceCssVarsWithFallbacks } from './rewriting'
1111
import { AstNode } from '../css'
1212
import { walk, WalkAction } from './walk'
13+
import * as semver from 'semver'
1314

1415
const COLOR_PROPS = [
1516
'accent-color',
@@ -179,19 +180,29 @@ let isNumericUtility =
179180
/^-?((min-|max-)?[wh]|z|start|indent|flex|columns|order|rounded|row|col|size|basis|end|delay|duration|ease|font|top|left|bottom|right|leading|cursor|(backdrop-)?(opacity|brightness|sepia|saturate|hue-rotate|grayscale|contrast|blur)|(space|scale|skew|rotate|translate|border-spacing|gap)(-[xyz])?|(scroll-)?[pm][trblxyse]?)-/
180181
let isMaskUtility = /^-?mask-/
181182

182-
function isLikelyColorless(className: string) {
183+
function isLikelyColorless(state: State, className: string) {
183184
if (isNegative.test(className)) return true
185+
if (isNumericUtility.test(className)) return true
186+
187+
// TODO: Update version number to v4.1.18 when it's released
188+
// v4.1.18 has an API that lets us access compiled candidate ASTs directly
189+
// significantly improving performance.
190+
//
191+
// While the additional compilation overhead from the mask utilities still
192+
// exists it is much smaller.
193+
if (semver.gte(state.version, '4.1.17')) return false
194+
184195
// TODO: This is **not** correct but is intentional because there are 5k mask utilities and a LOT of them are colors
185196
// This causes a massive slowdown when building the design system
186197
if (isMaskUtility.test(className)) return true
187-
if (isNumericUtility.test(className)) return true
198+
188199
return false
189200
}
190201

191202
export function getColor(state: State, className: string): ParsedColor | null {
192203
if (state.v4) {
193204
// FIXME: This is a performance optimization and not strictly correct
194-
if (isLikelyColorless(className)) return null
205+
if (isLikelyColorless(state, className)) return null
195206

196207
let css = state.designSystem.compile([className])[0]
197208
let color = getColorFromRoot(state, css)

0 commit comments

Comments
 (0)