Skip to content

Commit bf0ad36

Browse files
committed
Show colors for mask utilities
1 parent e96eea6 commit bf0ad36

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',
@@ -201,19 +202,29 @@ let isNumericUtility =
201202
/^-?((min-|max-)?[wh]|z|start|order|opacity|rounded|row|col|size|basis|end|duration|ease|font|top|left|bottom|right|inset|leading|cursor|(space|scale|skew|rotate)-[xyz]|gap(-[xy])?|(scroll-)?[pm][trblxyse]?)-/
202203
let isMaskUtility = /^-?mask-/
203204

204-
function isLikelyColorless(className: string) {
205+
function isLikelyColorless(state: State, className: string) {
205206
if (isNegative.test(className)) return true
207+
if (isNumericUtility.test(className)) return true
208+
209+
// TODO: Update version number to v4.1.18 when it's released
210+
// v4.1.18 has an API that lets us access compiled candidate ASTs directly
211+
// significantly improving performance.
212+
//
213+
// While the additional compilation overhead from the mask utilities still
214+
// exists it is much smaller.
215+
if (semver.gte(state.version, '4.1.17')) return false
216+
206217
// TODO: This is **not** correct but is intentional because there are 5k mask utilities and a LOT of them are colors
207218
// This causes a massive slowdown when building the design system
208219
if (isMaskUtility.test(className)) return true
209-
if (isNumericUtility.test(className)) return true
220+
210221
return false
211222
}
212223

213224
export function getColor(state: State, className: string): culori.Color | KeywordColor | null {
214225
if (state.v4) {
215226
// FIXME: This is a performance optimization and not strictly correct
216-
if (isLikelyColorless(className)) return null
227+
if (isLikelyColorless(state, className)) return null
217228

218229
let css = state.designSystem.compile([className])[0]
219230

0 commit comments

Comments
 (0)