@@ -170,6 +170,28 @@ function withIdentifiers(styles) {
170
170
} )
171
171
}
172
172
173
+ export function parseVariant ( variant ) {
174
+ variant = variant
175
+ . replace ( / \n + / g, '' )
176
+ . replace ( / \s { 1 , } / g, ' ' )
177
+ . trim ( )
178
+
179
+ let fns = parseVariantFormatString ( variant ) . map ( ( str ) => {
180
+ if ( ! str . startsWith ( '@' ) ) {
181
+ return ( { format } ) => format ( str )
182
+ }
183
+
184
+ let [ , name , params ] = / @ ( .* ?) ( .* ) / g. exec ( str )
185
+ return ( { wrap } ) => wrap ( postcss . atRule ( { name, params } ) )
186
+ } ) . reverse ( )
187
+
188
+ return ( api ) => {
189
+ for ( let fn of fns ) {
190
+ fn ( api )
191
+ }
192
+ }
193
+ }
194
+
173
195
function buildPluginApi ( tailwindConfig , context , { variantList, variantMap, offsets, classList } ) {
174
196
function getConfigValue ( path , defaultValue ) {
175
197
return path ? dlv ( tailwindConfig , path , defaultValue ) : tailwindConfig
@@ -201,27 +223,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
201
223
}
202
224
}
203
225
204
- variantFunction = variantFunction
205
- . replace ( / \n + / g, '' )
206
- . replace ( / \s { 1 , } / g, ' ' )
207
- . trim ( )
208
-
209
- let fns = parseVariantFormatString ( variantFunction )
210
- . map ( ( str ) => {
211
- if ( ! str . startsWith ( '@' ) ) {
212
- return ( { format } ) => format ( str )
213
- }
214
-
215
- let [ , name , params ] = / @ ( .* ?) ( .* ) / g. exec ( str )
216
- return ( { wrap } ) => wrap ( postcss . atRule ( { name, params } ) )
217
- } )
218
- . reverse ( )
219
-
220
- return ( api ) => {
221
- for ( let fn of fns ) {
222
- fn ( api )
223
- }
224
- }
226
+ return parseVariant ( variantFunction )
225
227
} )
226
228
227
229
insertInto ( variantList , variantName , options )
@@ -674,29 +676,29 @@ function registerPlugins(plugins, context) {
674
676
for ( let util of classList ) {
675
677
let utils = Array . isArray ( util )
676
678
? ( ( ) => {
677
- let [ utilName , options ] = util
678
- let values = Object . keys ( options ?. values ?? { } )
679
- let classes = values . map ( ( value ) => formatClass ( utilName , value ) )
680
-
681
- if ( options ?. supportsNegativeValues ) {
682
- // This is the normal negated version
683
- // e.g. `-inset-1` or `-tw-inset-1`
684
- classes = [ ...classes , ...classes . map ( ( cls ) => '-' + cls ) ]
685
-
686
- // This is the negated version *after* the prefix
687
- // e.g. `tw--inset-1`
688
- // The prefix is already attached to util name
689
- // So we add the negative after the prefix
690
- classes = [
691
- ...classes ,
692
- ...classes . map (
693
- ( cls ) => cls . slice ( 0 , prefixLength ) + '-' + cls . slice ( prefixLength )
694
- ) ,
695
- ]
696
- }
697
-
698
- return classes
699
- } ) ( )
679
+ let [ utilName , options ] = util
680
+ let values = Object . keys ( options ?. values ?? { } )
681
+ let classes = values . map ( ( value ) => formatClass ( utilName , value ) )
682
+
683
+ if ( options ?. supportsNegativeValues ) {
684
+ // This is the normal negated version
685
+ // e.g. `-inset-1` or `-tw-inset-1`
686
+ classes = [ ...classes , ...classes . map ( ( cls ) => '-' + cls ) ]
687
+
688
+ // This is the negated version *after* the prefix
689
+ // e.g. `tw--inset-1`
690
+ // The prefix is already attached to util name
691
+ // So we add the negative after the prefix
692
+ classes = [
693
+ ...classes ,
694
+ ...classes . map (
695
+ ( cls ) => cls . slice ( 0 , prefixLength ) + '-' + cls . slice ( prefixLength )
696
+ ) ,
697
+ ]
698
+ }
699
+
700
+ return classes
701
+ } ) ( )
700
702
: [ util ]
701
703
702
704
for ( let util of utils ) {
0 commit comments