|
1 | 1 | import _ from 'lodash' |
| 2 | +import postcss from 'postcss' |
| 3 | +import applyClassPrefix from '../util/applyClassPrefix' |
2 | 4 | import backgroundColors from '../generators/backgroundColors' |
3 | 5 | import backgroundPositions from '../generators/backgroundPositions' |
4 | 6 | import backgroundSize from '../generators/backgroundSize' |
@@ -39,50 +41,61 @@ import zIndex from '../generators/zIndex' |
39 | 41 |
|
40 | 42 | export default function(config) { |
41 | 43 | return function(css) { |
42 | | - const options = config() |
| 44 | + const unwrappedConfig = config() |
43 | 45 |
|
44 | 46 | css.walkAtRules('tailwind', atRule => { |
45 | 47 | if (atRule.params === 'utilities') { |
46 | | - const utilities = _.flatten([ |
47 | | - lists(options), |
48 | | - forms(options), |
49 | | - textSizes(options), |
50 | | - textWeights(options), |
51 | | - textFonts(options), |
52 | | - textColors(options), |
53 | | - textLeading(options), |
54 | | - textTracking(options), |
55 | | - textAlign(options), |
56 | | - textWrap(options), |
57 | | - textStyle(options), |
58 | | - verticalAlign(options), |
59 | | - backgroundColors(options), |
60 | | - backgroundPositions(options), |
61 | | - backgroundSize(options), |
62 | | - borderStylesReset(options), |
63 | | - borderWidths(options), |
64 | | - borderColors(options), |
65 | | - borderStyles(options), |
66 | | - rounded(options), |
67 | | - display(options), |
68 | | - position(options), |
69 | | - overflow(options), |
70 | | - sizing(options), |
71 | | - spacing(options), |
72 | | - shadows(options), |
73 | | - flex(options), |
74 | | - floats(options), |
75 | | - visibility(options), |
76 | | - zIndex(options), |
77 | | - opacity(options), |
78 | | - userSelect(options), |
79 | | - pointerEvents(options), |
80 | | - resize(options), |
81 | | - cursor(options), |
82 | | - ]) |
| 48 | + const utilities = postcss.root({ |
| 49 | + nodes: _.flatten([ |
| 50 | + lists(unwrappedConfig), |
| 51 | + forms(unwrappedConfig), |
| 52 | + textSizes(unwrappedConfig), |
| 53 | + textWeights(unwrappedConfig), |
| 54 | + textFonts(unwrappedConfig), |
| 55 | + textColors(unwrappedConfig), |
| 56 | + textLeading(unwrappedConfig), |
| 57 | + textTracking(unwrappedConfig), |
| 58 | + textAlign(unwrappedConfig), |
| 59 | + textWrap(unwrappedConfig), |
| 60 | + textStyle(unwrappedConfig), |
| 61 | + verticalAlign(unwrappedConfig), |
| 62 | + backgroundColors(unwrappedConfig), |
| 63 | + backgroundPositions(unwrappedConfig), |
| 64 | + backgroundSize(unwrappedConfig), |
| 65 | + borderStylesReset(unwrappedConfig), |
| 66 | + borderWidths(unwrappedConfig), |
| 67 | + borderColors(unwrappedConfig), |
| 68 | + borderStyles(unwrappedConfig), |
| 69 | + rounded(unwrappedConfig), |
| 70 | + display(unwrappedConfig), |
| 71 | + position(unwrappedConfig), |
| 72 | + overflow(unwrappedConfig), |
| 73 | + sizing(unwrappedConfig), |
| 74 | + spacing(unwrappedConfig), |
| 75 | + shadows(unwrappedConfig), |
| 76 | + flex(unwrappedConfig), |
| 77 | + floats(unwrappedConfig), |
| 78 | + visibility(unwrappedConfig), |
| 79 | + zIndex(unwrappedConfig), |
| 80 | + opacity(unwrappedConfig), |
| 81 | + userSelect(unwrappedConfig), |
| 82 | + pointerEvents(unwrappedConfig), |
| 83 | + resize(unwrappedConfig), |
| 84 | + cursor(unwrappedConfig), |
| 85 | + ]), |
| 86 | + }) |
83 | 87 |
|
84 | | - atRule.before(container(options)) |
85 | | - atRule.before(responsive(utilities)) |
| 88 | + if (_.get(unwrappedConfig, 'options.important', false)) { |
| 89 | + utilities.walkDecls(decl => (decl.important = true)) |
| 90 | + } |
| 91 | + |
| 92 | + const tailwindClasses = postcss.root({ |
| 93 | + nodes: [...container(unwrappedConfig), responsive(utilities)], |
| 94 | + }) |
| 95 | + |
| 96 | + applyClassPrefix(tailwindClasses, _.get(unwrappedConfig, 'options.prefix', '')) |
| 97 | + |
| 98 | + atRule.before(tailwindClasses) |
86 | 99 | atRule.remove() |
87 | 100 | } |
88 | 101 | }) |
|
0 commit comments