@@ -41,6 +41,33 @@ export default function (plugins, config) {
4141 return prefixSelector ( config . prefix , selector )
4242 }
4343
44+ function addUtilities ( utilities , options ) {
45+ const defaultOptions = { variants : [ ] , respectPrefix : true , respectImportant : true }
46+
47+ options = Array . isArray ( options )
48+ ? Object . assign ( { } , defaultOptions , { variants : options } )
49+ : _ . defaults ( options , defaultOptions )
50+
51+ const styles = postcss . root ( { nodes : parseStyles ( utilities ) } )
52+
53+ styles . walkRules ( ( rule ) => {
54+ if ( options . respectPrefix && ! isKeyframeRule ( rule ) ) {
55+ rule . selector = applyConfiguredPrefix ( rule . selector )
56+ }
57+
58+ if ( options . respectImportant && config . important ) {
59+ rule . __tailwind = {
60+ ...rule . __tailwind ,
61+ important : config . important ,
62+ }
63+ }
64+ } )
65+
66+ pluginUtilities . push (
67+ wrapWithLayer ( wrapWithVariants ( styles . nodes , options . variants ) , 'utilities' )
68+ )
69+ }
70+
4471 const getConfigValue = ( path , defaultValue ) => ( path ? _ . get ( config , path , defaultValue ) : config )
4572
4673 plugins . forEach ( ( plugin ) => {
@@ -75,31 +102,17 @@ export default function (plugins, config) {
75102 } ,
76103 e : escapeClassName ,
77104 prefix : applyConfiguredPrefix ,
78- addUtilities : ( utilities , options ) => {
79- const defaultOptions = { variants : [ ] , respectPrefix : true , respectImportant : true }
80-
81- options = Array . isArray ( options )
82- ? Object . assign ( { } , defaultOptions , { variants : options } )
83- : _ . defaults ( options , defaultOptions )
84-
85- const styles = postcss . root ( { nodes : parseStyles ( utilities ) } )
86-
87- styles . walkRules ( ( rule ) => {
88- if ( options . respectPrefix && ! isKeyframeRule ( rule ) ) {
89- rule . selector = applyConfiguredPrefix ( rule . selector )
90- }
91-
92- if ( options . respectImportant && config . important ) {
93- rule . __tailwind = {
94- ...rule . __tailwind ,
95- important : config . important ,
96- }
97- }
105+ addUtilities,
106+ matchUtilities : ( matches , { values, variants, respectPrefix, respectImportant } ) => {
107+ let modifierValues = Object . entries ( values )
108+
109+ let result = Object . values ( matches ) . flatMap ( ( utilityFunction ) => {
110+ return modifierValues . map ( ( [ modifier , value ] ) => {
111+ return utilityFunction ( modifier , { value } )
112+ } )
98113 } )
99114
100- pluginUtilities . push (
101- wrapWithLayer ( wrapWithVariants ( styles . nodes , options . variants ) , 'utilities' )
102- )
115+ addUtilities ( result , { variants, respectPrefix, respectImportant } )
103116 } ,
104117 addComponents : ( components , options ) => {
105118 const defaultOptions = { variants : [ ] , respectPrefix : true }
0 commit comments