@@ -25,6 +25,7 @@ import {
25
25
isValidOpacityValue ,
26
26
isValidSpacingMultiplier ,
27
27
} from '../../../../tailwindcss/src/utils/infer-data-type'
28
+ import * as ValueParser from '../../../../tailwindcss/src/value-parser'
28
29
import { findStaticPlugins , type StaticPluginOptions } from '../../utils/extract-static-plugins'
29
30
import { highlight , info , relative } from '../../utils/renderer'
30
31
@@ -165,6 +166,35 @@ async function migrateTheme(
165
166
}
166
167
delete resolvedConfig . theme . data
167
168
}
169
+
170
+ if ( 'supports' in resolvedConfig . theme ) {
171
+ for ( let [ key , value ] of Object . entries ( resolvedConfig . theme . supports ?? { } ) ) {
172
+ // Will be handled by bare values if the value of the declaration is a
173
+ // CSS variable.
174
+ let parsed = ValueParser . parse ( `${ value } ` )
175
+
176
+ // Unwrap the parens, e.g.: `(foo: var(--bar))` → `foo: var(--bar)`
177
+ if ( parsed . length === 1 && parsed [ 0 ] . kind === 'function' && parsed [ 0 ] . value === '' ) {
178
+ parsed = parsed [ 0 ] . nodes
179
+ }
180
+
181
+ // Verify structure: `foo: var(--bar)`
182
+ // ^^^ ← must match the `key`
183
+ if (
184
+ parsed . length === 3 &&
185
+ parsed [ 0 ] . kind === 'word' &&
186
+ parsed [ 0 ] . value === key &&
187
+ parsed [ 2 ] . kind === 'function' &&
188
+ parsed [ 2 ] . value === 'var'
189
+ ) {
190
+ continue
191
+ }
192
+
193
+ // Create custom variant
194
+ variants . set ( `supports-${ key } ` , `{@supports(${ value } ){@slot;}}` )
195
+ }
196
+ delete resolvedConfig . theme . supports
197
+ }
168
198
}
169
199
170
200
// Convert theme values to CSS custom properties
@@ -253,7 +283,11 @@ async function migrateTheme(
253
283
if ( previousRoot !== root ) css += '\n'
254
284
previousRoot = root
255
285
256
- css += `@custom-variant ${ name } (${ selector } );\n`
286
+ if ( selector . startsWith ( '{' ) ) {
287
+ css += `@custom-variant ${ name } ${ selector } \n`
288
+ } else {
289
+ css += `@custom-variant ${ name } (${ selector } );\n`
290
+ }
257
291
}
258
292
css += '}\n'
259
293
}
@@ -418,15 +452,11 @@ const ALLOWED_THEME_KEYS = [
418
452
// Used by @tailwindcss /container-queries
419
453
'containers' ,
420
454
]
421
- const BLOCKED_THEME_KEYS = [ 'supports' ]
422
455
function onlyAllowedThemeValues ( theme : ThemeConfig ) : boolean {
423
456
for ( let key of Object . keys ( theme ) ) {
424
457
if ( ! ALLOWED_THEME_KEYS . includes ( key ) ) {
425
458
return false
426
459
}
427
- if ( BLOCKED_THEME_KEYS . includes ( key ) ) {
428
- return false
429
- }
430
460
}
431
461
432
462
if ( 'screens' in theme && typeof theme . screens === 'object' && theme . screens !== null ) {
0 commit comments