@@ -39,7 +39,7 @@ import chokidar, { FSWatcher } from 'chokidar'
3939import findUp from 'find-up'
4040import minimatch from 'minimatch'
4141import resolveFrom , { setPnpApi } from './util/resolveFrom'
42- import { /*postcssFallback,*/ Result } from 'postcss'
42+ import { /*postcssFallback,*/ AtRule , Container , Node , Result } from 'postcss'
4343// import tailwindcssFallback from 'tailwindcss'
4444// import resolveConfigFallback from 'tailwindcss/resolveConfig'
4545import Module from 'module'
@@ -1096,6 +1096,10 @@ function runPlugin(
10961096 } catch ( _ ) { }
10971097}
10981098
1099+ function isAtRule ( node : Node ) : node is AtRule {
1100+ return node . type === 'atrule'
1101+ }
1102+
10991103function getVariants ( state : State ) : Record < string , string > {
11001104 if ( state . jit ) {
11011105 function escape ( className : string ) : string {
@@ -1153,18 +1157,36 @@ function getVariants(state: State): Record<string, string> {
11531157 let definitions = [ ]
11541158
11551159 for ( let fn of fns ) {
1160+ let definition : string
11561161 let container = root . clone ( )
1157- fn ( {
1162+ let returnValue = fn ( {
11581163 container,
11591164 separator : state . separator ,
11601165 modifySelectors,
1166+ format : ( def : string ) => {
1167+ definition = def . replace ( / : m e r g e \( ( [ ^ ) ] + ) \) / g, '$1' )
1168+ } ,
1169+ wrap : ( rule : Container ) => {
1170+ if ( isAtRule ( rule ) ) {
1171+ definition = `@${ rule . name } ${ rule . params } `
1172+ }
1173+ } ,
11611174 } )
11621175
1176+ if ( ! definition ) {
1177+ definition = returnValue
1178+ }
1179+
1180+ if ( definition ) {
1181+ definitions . push ( definition )
1182+ continue
1183+ }
1184+
11631185 container . walkDecls ( ( decl ) => {
11641186 decl . remove ( )
11651187 } )
11661188
1167- let definition = container
1189+ definition = container
11681190 . toString ( )
11691191 . replace ( `.${ escape ( `${ variantName } :${ placeholder } ` ) } ` , '&' )
11701192 . replace ( / (?< ! \\ ) [ { } ] / g, '' )
0 commit comments