@@ -24,6 +24,7 @@ import {
2424 isValidOpacityValue ,
2525 isValidSpacingMultiplier ,
2626} from '../../../../tailwindcss/src/utils/infer-data-type'
27+ import * as ValueParser from '../../../../tailwindcss/src/value-parser'
2728import { findStaticPlugins , type StaticPluginOptions } from '../../utils/extract-static-plugins'
2829import { highlight , info , relative } from '../../utils/renderer'
2930
@@ -164,6 +165,35 @@ async function migrateTheme(
164165 }
165166 delete resolvedConfig . theme . data
166167 }
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+ }
167197 }
168198
169199 // Convert theme values to CSS custom properties
@@ -242,7 +272,11 @@ async function migrateTheme(
242272 if ( previousRoot !== root ) css += '\n'
243273 previousRoot = root
244274
245- css += `@custom-variant ${ name } (${ selector } );\n`
275+ if ( selector . startsWith ( '{' ) ) {
276+ css += `@custom-variant ${ name } ${ selector } \n`
277+ } else {
278+ css += `@custom-variant ${ name } (${ selector } );\n`
279+ }
246280 }
247281 css += '}\n'
248282 }
@@ -407,15 +441,11 @@ const ALLOWED_THEME_KEYS = [
407441 // Used by @tailwindcss /container-queries
408442 'containers' ,
409443]
410- const BLOCKED_THEME_KEYS = [ 'supports' ]
411444function onlyAllowedThemeValues ( theme : ThemeConfig ) : boolean {
412445 for ( let key of Object . keys ( theme ) ) {
413446 if ( ! ALLOWED_THEME_KEYS . includes ( key ) ) {
414447 return false
415448 }
416- if ( BLOCKED_THEME_KEYS . includes ( key ) ) {
417- return false
418- }
419449 }
420450
421451 if ( 'screens' in theme && typeof theme . screens === 'object' && theme . screens !== null ) {
0 commit comments