@@ -70,6 +70,28 @@ function needsArbitraryBrackets(value: string): boolean {
7070 return SPECIAL_CHARS_REGEX . test ( value ) || CSS_UNITS_REGEX . test ( value )
7171}
7272
73+ /**
74+ * Convert underscores to spaces in arbitrary values (Tailwind convention).
75+ * e.g. grid-cols-[120px_1fr_200px] → "120px 1fr 200px"
76+ * Preserves underscores inside url(), var(), and other CSS functions.
77+ */
78+ function convertArbitraryUnderscores ( value : string ) : string {
79+ if ( ! value . includes ( '_' ) ) return value
80+ // If the value contains CSS functions, only replace underscores outside them
81+ if ( value . includes ( '(' ) ) {
82+ let result = ''
83+ let depth = 0
84+ for ( let i = 0 ; i < value . length ; i ++ ) {
85+ const ch = value [ i ]
86+ if ( ch === '(' ) depth ++
87+ else if ( ch === ')' ) depth --
88+ result += ( ch === '_' && depth === 0 ) ? ' ' : ch
89+ }
90+ return result
91+ }
92+ return value . replace ( / _ / g, ' ' )
93+ }
94+
7395/**
7496 * Handle min/max prefix patterns for sizing utilities
7597 * w[min 200px] -> min-w-[200px], h[max screen] -> max-h-screen
@@ -997,7 +1019,7 @@ function parseClassImpl(className: string): ParsedClass {
9971019 if ( preArbitraryMatch ) {
9981020 const variantPart = preArbitraryMatch [ 1 ]
9991021 const variants = variantPart ? variantPart . split ( ':' ) . filter ( Boolean ) : [ ]
1000- let value = preArbitraryMatch [ 3 ]
1022+ let value = convertArbitraryUnderscores ( preArbitraryMatch [ 3 ] )
10011023 let typeHint : string | undefined
10021024
10031025 // Check for type hint in arbitrary value: text-[color:var(--muted)]
@@ -1059,7 +1081,7 @@ function parseClassImpl(className: string): ParsedClass {
10591081 // Check for arbitrary values: w-[100px] or bg-[#ff0000] or text-[color:var(--muted)]
10601082 const arbitraryMatch = utility . match ( / ^ ( [ a - z - ] + ?) - \[ ( .+ ?) \] $ / )
10611083 if ( arbitraryMatch ) {
1062- let value = arbitraryMatch [ 2 ]
1084+ let value = convertArbitraryUnderscores ( arbitraryMatch [ 2 ] )
10631085 let typeHint : string | undefined
10641086
10651087 // Check for type hint in arbitrary value: text-[color:var(--muted)]
0 commit comments