@@ -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' ,
@@ -179,19 +180,29 @@ let isNumericUtility =
179180 / ^ - ? ( ( m i n - | m a x - ) ? [ w h ] | z | s t a r t | i n d e n t | f l e x | c o l u m n s | o r d e r | 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 e l a y | 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 | l e a d i n g | c u r s o r | ( b a c k d r o p - ) ? ( o p a c i t y | b r i g h t n e s s | s e p i a | s a t u r a t e | h u e - r o t a t e | g r a y s c a l e | c o n t r a s t | b l u r ) | ( s p a c e | s c a l e | s k e w | r o t a t e | t r a n s l a t e | b o r d e r - s p a c i n g | g a p ) ( - [ x y z ] ) ? | ( s c r o l l - ) ? [ p m ] [ t r b l x y s e ] ? ) - /
180181let isMaskUtility = / ^ - ? m a s k - /
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
191202export 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