@@ -21,6 +21,7 @@ import isValidArbitraryValue from '../util/isValidArbitraryValue'
21
21
import { generateRules } from './generateRules'
22
22
import { hasContentChanged } from './cacheInvalidation.js'
23
23
import { Offsets } from './offsets.js'
24
+ import { flagEnabled } from '../featureFlags.js'
24
25
25
26
let MATCH_VARIANT = Symbol ( )
26
27
@@ -358,6 +359,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
358
359
let defaultOptions = {
359
360
respectPrefix : true ,
360
361
respectImportant : true ,
362
+ modifiers : false ,
361
363
}
362
364
363
365
options = normalizeOptionTypes ( { ...defaultOptions , ...options } )
@@ -371,7 +373,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
371
373
classList . add ( [ prefixedIdentifier , options ] )
372
374
373
375
function wrapped ( modifier , { isOnlyPlugin } ) {
374
- let [ value , coercedType ] = coerceValue ( options . types , modifier , options , tailwindConfig )
376
+ let [ value , coercedType , utilityModifier ] = coerceValue (
377
+ options . types ,
378
+ modifier ,
379
+ options ,
380
+ tailwindConfig
381
+ )
375
382
376
383
if ( value === undefined ) {
377
384
return [ ]
@@ -395,8 +402,22 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
395
402
return [ ]
396
403
}
397
404
405
+ let extras = {
406
+ get modifier ( ) {
407
+ if ( ! options . modifiers ) {
408
+ log . warn ( `modifier-used-without-options-for-${ identifier } ` , [
409
+ 'Your plugin must set `modifiers: true` in its options to support modifiers.' ,
410
+ ] )
411
+ }
412
+
413
+ return utilityModifier
414
+ } ,
415
+ }
416
+
417
+ let modifiersEnabled = flagEnabled ( tailwindConfig , 'generalizedModifiers' )
418
+
398
419
let ruleSets = [ ]
399
- . concat ( rule ( value ) )
420
+ . concat ( modifiersEnabled ? rule ( value , extras ) : rule ( value ) )
400
421
. filter ( Boolean )
401
422
. map ( ( declaration ) => ( {
402
423
[ nameClass ( identifier , modifier ) ] : declaration ,
@@ -418,6 +439,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
418
439
let defaultOptions = {
419
440
respectPrefix : true ,
420
441
respectImportant : false ,
442
+ modifiers : false ,
421
443
}
422
444
423
445
options = normalizeOptionTypes ( { ...defaultOptions , ...options } )
@@ -431,7 +453,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
431
453
classList . add ( [ prefixedIdentifier , options ] )
432
454
433
455
function wrapped ( modifier , { isOnlyPlugin } ) {
434
- let [ value , coercedType ] = coerceValue ( options . types , modifier , options , tailwindConfig )
456
+ let [ value , coercedType , utilityModifier ] = coerceValue (
457
+ options . types ,
458
+ modifier ,
459
+ options ,
460
+ tailwindConfig
461
+ )
435
462
436
463
if ( value === undefined ) {
437
464
return [ ]
@@ -455,8 +482,22 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
455
482
return [ ]
456
483
}
457
484
485
+ let extras = {
486
+ get modifier ( ) {
487
+ if ( ! options . modifiers ) {
488
+ log . warn ( `modifier-used-without-options-for-${ identifier } ` , [
489
+ 'Your plugin must set `modifiers: true` in its options to support modifiers.' ,
490
+ ] )
491
+ }
492
+
493
+ return utilityModifier
494
+ } ,
495
+ }
496
+
497
+ let modifiersEnabled = flagEnabled ( tailwindConfig , 'generalizedModifiers' )
498
+
458
499
let ruleSets = [ ]
459
- . concat ( rule ( value ) )
500
+ . concat ( modifiersEnabled ? rule ( value , extras ) : rule ( value ) )
460
501
. filter ( Boolean )
461
502
. map ( ( declaration ) => ( {
462
503
[ nameClass ( identifier , modifier ) ] : declaration ,
@@ -522,21 +563,37 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
522
563
let id = ++ variantIdentifier // A unique identifier that "groups" these variables together.
523
564
let isSpecial = variant === '@'
524
565
566
+ let modifiersEnabled = flagEnabled ( tailwindConfig , 'generalizedModifiers' )
567
+
525
568
for ( let [ key , value ] of Object . entries ( options ?. values ?? { } ) ) {
526
569
api . addVariant (
527
570
isSpecial ? `${ variant } ${ key } ` : `${ variant } -${ key } ` ,
528
- Object . assign ( ( { args, container } ) => variantFn ( { ...args , container, value } ) , {
529
- [ MATCH_VARIANT ] : true ,
530
- } ) ,
571
+ Object . assign (
572
+ ( { args, container } ) =>
573
+ variantFn (
574
+ value ,
575
+ modifiersEnabled ? { modifier : args . modifier , container } : { container }
576
+ ) ,
577
+ {
578
+ [ MATCH_VARIANT ] : true ,
579
+ }
580
+ ) ,
531
581
{ ...options , value, id }
532
582
)
533
583
}
534
584
535
585
api . addVariant (
536
586
variant ,
537
- Object . assign ( ( { args, container } ) => variantFn ( { ...args , container } ) , {
538
- [ MATCH_VARIANT ] : true ,
539
- } ) ,
587
+ Object . assign (
588
+ ( { args, container } ) =>
589
+ variantFn (
590
+ args . value ,
591
+ modifiersEnabled ? { modifier : args . modifier , container } : { container }
592
+ ) ,
593
+ {
594
+ [ MATCH_VARIANT ] : true ,
595
+ }
596
+ ) ,
540
597
{ ...options , id }
541
598
)
542
599
} ,
0 commit comments