@@ -10,6 +10,7 @@ import namedColors from 'color-name'
1010import { replaceCssVarsWithFallbacks } from './rewriting'
1111import { AstNode } from '../css'
1212import { walk , WalkAction } from './walk'
13+ import * as semver from 'semver'
1314
1415const COLOR_PROPS = [
1516 'accent-color' ,
@@ -201,19 +202,29 @@ let isNumericUtility =
201202 / ^ - ? ( ( m i n - | m a x - ) ? [ w h ] | z | s t a r t | o r d e r | o p a c i t y | r o u n d e d | r o w | c o l | s i z e | b a s i s | e n d | d u r a t i o n | e a s e | f o n t | t o p | l e f t | b o t t o m | r i g h t | i n s e t | l e a d i n g | c u r s o r | ( s p a c e | s c a l e | s k e w | r o t a t e ) - [ x y z ] | g a p ( - [ x y ] ) ? | ( s c r o l l - ) ? [ p m ] [ t r b l x y s e ] ? ) - /
202203let isMaskUtility = / ^ - ? m a s k - /
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
213224export 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