@@ -12,7 +12,7 @@ import escapeClassName from '../util/escapeClassName'
1212import nameClass , { formatClass } from '../util/nameClass'
1313import { coerceValue } from '../util/pluginUtils'
1414import bigSign from '../util/bigSign'
15- import corePlugins from '../corePlugins'
15+ import { variantPlugins , corePlugins } from '../corePlugins'
1616import * as sharedState from './sharedState'
1717import { env } from './sharedState'
1818import { toPath } from '../util/toPath'
@@ -237,17 +237,11 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
237237 } ,
238238 addComponents ( components , options ) {
239239 let defaultOptions = {
240- variants : [ ] ,
241240 respectPrefix : true ,
242241 respectImportant : false ,
243- respectVariants : true ,
244242 }
245243
246- options = Object . assign (
247- { } ,
248- defaultOptions ,
249- Array . isArray ( options ) ? { variants : options } : options
250- )
244+ options = Object . assign ( { } , defaultOptions , Array . isArray ( options ) ? { } : options )
251245
252246 for ( let [ identifier , rule ] of withIdentifiers ( components ) ) {
253247 let prefixedIdentifier = prefixIdentifier ( identifier , options )
@@ -266,17 +260,11 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
266260 } ,
267261 addUtilities ( utilities , options ) {
268262 let defaultOptions = {
269- variants : [ ] ,
270263 respectPrefix : true ,
271264 respectImportant : true ,
272- respectVariants : true ,
273265 }
274266
275- options = Object . assign (
276- { } ,
277- defaultOptions ,
278- Array . isArray ( options ) ? { variants : options } : options
279- )
267+ options = Object . assign ( { } , defaultOptions , Array . isArray ( options ) ? { } : options )
280268
281269 for ( let [ identifier , rule ] of withIdentifiers ( utilities ) ) {
282270 let prefixedIdentifier = prefixIdentifier ( identifier , options )
@@ -295,10 +283,8 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
295283 } ,
296284 matchUtilities : function ( utilities , options ) {
297285 let defaultOptions = {
298- variants : [ ] ,
299286 respectPrefix : true ,
300287 respectImportant : true ,
301- respectVariants : true ,
302288 }
303289
304290 options = { ...defaultOptions , ...options }
@@ -338,21 +324,14 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
338324 return [ ]
339325 }
340326
341- let includedRules = [ ]
342327 let ruleSets = [ ]
343- . concat (
344- rule ( value , {
345- includeRules ( rules ) {
346- includedRules . push ( ...rules )
347- } ,
348- } )
349- )
328+ . concat ( rule ( value ) )
350329 . filter ( Boolean )
351330 . map ( ( declaration ) => ( {
352331 [ nameClass ( identifier , modifier ) ] : declaration ,
353332 } ) )
354333
355- return [ ... includedRules , ... ruleSets ]
334+ return ruleSets
356335 }
357336
358337 let withOffsets = [ { sort : offset , layer : 'utilities' , options } , wrapped ]
@@ -361,6 +340,68 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
361340 context . candidateRuleMap . set ( prefixedIdentifier , [ ] )
362341 }
363342
343+ context . candidateRuleMap . get ( prefixedIdentifier ) . push ( withOffsets )
344+ }
345+ } ,
346+ matchComponents : function ( components , options ) {
347+ let defaultOptions = {
348+ respectPrefix : true ,
349+ respectImportant : false ,
350+ }
351+
352+ options = { ...defaultOptions , ...options }
353+
354+ let offset = offsets . components ++
355+
356+ for ( let identifier in components ) {
357+ let prefixedIdentifier = prefixIdentifier ( identifier , options )
358+ let rule = components [ identifier ]
359+
360+ classList . add ( [ prefixedIdentifier , options ] )
361+
362+ function wrapped ( modifier , { isOnlyPlugin } ) {
363+ let { type = 'any' } = options
364+ type = [ ] . concat ( type )
365+ let [ value , coercedType ] = coerceValue ( type , modifier , options . values , tailwindConfig )
366+
367+ if ( value === undefined ) {
368+ return [ ]
369+ }
370+
371+ if ( ! type . includes ( coercedType ) ) {
372+ if ( isOnlyPlugin ) {
373+ log . warn ( [
374+ `Unnecessary typehint \`${ coercedType } \` in \`${ identifier } -${ modifier } \`.` ,
375+ `You can safely update it to \`${ identifier } -${ modifier . replace (
376+ coercedType + ':' ,
377+ ''
378+ ) } \`.`,
379+ ] )
380+ } else {
381+ return [ ]
382+ }
383+ }
384+
385+ if ( ! isValidArbitraryValue ( value ) ) {
386+ return [ ]
387+ }
388+
389+ let ruleSets = [ ]
390+ . concat ( rule ( value ) )
391+ . filter ( Boolean )
392+ . map ( ( declaration ) => ( {
393+ [ nameClass ( identifier , modifier ) ] : declaration ,
394+ } ) )
395+
396+ return ruleSets
397+ }
398+
399+ let withOffsets = [ { sort : offset , layer : 'components' , options } , wrapped ]
400+
401+ if ( ! context . candidateRuleMap . has ( prefixedIdentifier ) ) {
402+ context . candidateRuleMap . set ( prefixedIdentifier , [ ] )
403+ }
404+
364405 context . candidateRuleMap . get ( prefixedIdentifier ) . push ( withOffsets )
365406 }
366407 } ,
@@ -457,7 +498,7 @@ function collectLayerPlugins(root) {
457498}
458499
459500function resolvePlugins ( context , root ) {
460- let corePluginList = Object . entries ( corePlugins )
501+ let corePluginList = Object . entries ( { ... variantPlugins , ... corePlugins } )
461502 . map ( ( [ name , plugin ] ) => {
462503 if ( ! context . tailwindConfig . corePlugins . includes ( name ) ) {
463504 return null
@@ -479,12 +520,15 @@ function resolvePlugins(context, root) {
479520
480521 // TODO: This is a workaround for backwards compatibility, since custom variants
481522 // were historically sorted before screen/stackable variants.
482- let beforeVariants = [ corePlugins [ 'pseudoElementVariants' ] , corePlugins [ 'pseudoClassVariants' ] ]
523+ let beforeVariants = [
524+ variantPlugins [ 'pseudoElementVariants' ] ,
525+ variantPlugins [ 'pseudoClassVariants' ] ,
526+ ]
483527 let afterVariants = [
484- corePlugins [ 'directionVariants' ] ,
485- corePlugins [ 'reducedMotionVariants' ] ,
486- corePlugins [ 'darkVariants' ] ,
487- corePlugins [ 'screenVariants' ] ,
528+ variantPlugins [ 'directionVariants' ] ,
529+ variantPlugins [ 'reducedMotionVariants' ] ,
530+ variantPlugins [ 'darkVariants' ] ,
531+ variantPlugins [ 'screenVariants' ] ,
488532 ]
489533
490534 return [ ...corePluginList , ...beforeVariants , ...userPlugins , ...afterVariants , ...layerPlugins ]
0 commit comments