@@ -24,6 +24,7 @@ import {
24
24
isValidOpacityValue ,
25
25
isValidSpacingMultiplier ,
26
26
} from '../../../../tailwindcss/src/utils/infer-data-type'
27
+ import * as ValueParser from '../../../../tailwindcss/src/value-parser'
27
28
import { findStaticPlugins , type StaticPluginOptions } from '../../utils/extract-static-plugins'
28
29
import { highlight , info , relative } from '../../utils/renderer'
29
30
@@ -164,6 +165,35 @@ async function migrateTheme(
164
165
}
165
166
delete resolvedConfig . theme . data
166
167
}
168
+
169
+ if ( 'supports' in resolvedConfig . theme ) {
170
+ for ( let [ key , value ] of Object . entries ( resolvedConfig . theme . supports ?? { } ) ) {
171
+ // Will be handled by bare values if the value of the declaration is a
172
+ // CSS variable.
173
+ let parsed = ValueParser . parse ( `${ value } ` )
174
+
175
+ // Unwrap the parens, e.g.: `(foo: var(--bar))` → `foo: var(--bar)`
176
+ if ( parsed . length === 1 && parsed [ 0 ] . kind === 'function' && parsed [ 0 ] . value === '' ) {
177
+ parsed = parsed [ 0 ] . nodes
178
+ }
179
+
180
+ // Verify structure: `foo: var(--bar)`
181
+ // ^^^ ← must match the `key`
182
+ if (
183
+ parsed . length === 3 &&
184
+ parsed [ 0 ] . kind === 'word' &&
185
+ parsed [ 0 ] . value === key &&
186
+ parsed [ 2 ] . kind === 'function' &&
187
+ parsed [ 2 ] . value === 'var'
188
+ ) {
189
+ continue
190
+ }
191
+
192
+ // Create custom variant
193
+ variants . set ( `supports-${ key } ` , `{@supports(${ value } ){@slot;}}` )
194
+ }
195
+ delete resolvedConfig . theme . supports
196
+ }
167
197
}
168
198
169
199
// Convert theme values to CSS custom properties
@@ -241,7 +271,11 @@ async function migrateTheme(
241
271
if ( previousRoot !== root ) css += '\n'
242
272
previousRoot = root
243
273
244
- css += `@custom-variant ${ name } (${ selector } );\n`
274
+ if ( selector . startsWith ( '{' ) ) {
275
+ css += `@custom-variant ${ name } ${ selector } \n`
276
+ } else {
277
+ css += `@custom-variant ${ name } (${ selector } );\n`
278
+ }
245
279
}
246
280
css += '}\n'
247
281
}
@@ -406,15 +440,11 @@ const ALLOWED_THEME_KEYS = [
406
440
// Used by @tailwindcss /container-queries
407
441
'containers' ,
408
442
]
409
- const BLOCKED_THEME_KEYS = [ 'supports' ]
410
443
function onlyAllowedThemeValues ( theme : ThemeConfig ) : boolean {
411
444
for ( let key of Object . keys ( theme ) ) {
412
445
if ( ! ALLOWED_THEME_KEYS . includes ( key ) ) {
413
446
return false
414
447
}
415
- if ( BLOCKED_THEME_KEYS . includes ( key ) ) {
416
- return false
417
- }
418
448
}
419
449
420
450
if ( 'screens' in theme && typeof theme . screens === 'object' && theme . screens !== null ) {
0 commit comments