tailwindcss 0.0.0-insiders.df011dc → 0.0.0-insiders.e2d5f21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -1
- package/README.md +1 -1
- package/colors.js +1 -304
- package/defaultConfig.js +1 -4
- package/defaultTheme.js +1 -4
- package/lib/cli-peer-dependencies.js +4 -9
- package/lib/cli.js +646 -705
- package/lib/constants.js +15 -15
- package/lib/corePluginList.js +174 -4
- package/lib/corePlugins.js +3637 -2934
- package/lib/css/preflight.css +14 -1
- package/lib/featureFlags.js +44 -44
- package/lib/index.js +25 -24
- package/lib/lib/collapseAdjacentRules.js +33 -35
- package/lib/lib/collapseDuplicateDeclarations.js +29 -0
- package/lib/lib/detectNesting.js +34 -0
- package/lib/lib/evaluateTailwindFunctions.js +134 -155
- package/lib/lib/expandApplyAtRules.js +183 -200
- package/lib/lib/expandTailwindAtRules.js +219 -232
- package/lib/lib/generateRules.js +478 -311
- package/lib/lib/getModuleDependencies.js +36 -41
- package/lib/lib/normalizeTailwindDirectives.js +66 -58
- package/lib/lib/resolveDefaultsAtRules.js +110 -90
- package/lib/lib/setupContextUtils.js +740 -580
- package/lib/lib/setupTrackingContext.js +142 -162
- package/lib/lib/setupWatchingContext.js +235 -278
- package/lib/lib/sharedState.js +7 -17
- package/lib/lib/substituteScreenAtRules.js +22 -26
- package/lib/processTailwindFeatures.js +38 -44
- package/lib/public/colors.js +329 -0
- package/lib/public/create-plugin.js +13 -0
- package/lib/public/default-config.js +14 -0
- package/lib/public/default-theme.js +14 -0
- package/lib/public/resolve-config.js +19 -0
- package/lib/util/bigSign.js +3 -5
- package/lib/util/buildMediaQuery.js +15 -31
- package/lib/util/cloneDeep.js +14 -13
- package/lib/util/cloneNodes.js +9 -13
- package/lib/util/color.js +69 -59
- package/lib/util/configurePlugins.js +13 -14
- package/lib/util/createPlugin.js +21 -24
- package/lib/util/createUtilityPlugin.js +47 -45
- package/lib/util/dataTypes.js +231 -0
- package/lib/util/defaults.js +10 -14
- package/lib/util/escapeClassName.js +12 -14
- package/lib/util/escapeCommas.js +3 -5
- package/lib/util/flattenColorPalette.js +14 -10
- package/lib/util/formatVariantSelector.js +186 -0
- package/lib/util/getAllConfigs.js +23 -16
- package/lib/util/hashConfig.js +10 -10
- package/lib/util/isKeyframeRule.js +3 -5
- package/lib/util/isPlainObject.js +7 -10
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +39 -30
- package/lib/util/nameClass.js +23 -23
- package/lib/util/negateValue.js +14 -15
- package/lib/util/normalizeConfig.js +208 -0
- package/lib/util/normalizeScreens.js +58 -0
- package/lib/util/parseAnimationValue.js +82 -53
- package/lib/util/parseBoxShadowValue.js +77 -0
- package/lib/util/parseDependency.js +49 -60
- package/lib/util/parseObjectStyles.js +23 -20
- package/lib/util/pluginUtils.js +153 -285
- package/lib/util/prefixSelector.js +14 -16
- package/lib/util/resolveConfig.js +194 -249
- package/lib/util/resolveConfigPath.js +38 -45
- package/lib/util/responsive.js +12 -11
- package/lib/util/tap.js +4 -6
- package/lib/util/toColorValue.js +4 -5
- package/lib/util/toPath.js +4 -6
- package/lib/util/transformThemeValue.js +57 -26
- package/lib/util/withAlphaVariable.js +56 -54
- package/package.json +27 -37
- package/peers/index.js +73099 -84294
- package/plugin.js +1 -3
- package/resolveConfig.js +1 -7
- package/scripts/create-plugin-list.js +2 -2
- package/src/cli.js +27 -18
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +2124 -1968
- package/src/css/preflight.css +14 -1
- package/src/featureFlags.js +12 -6
- package/src/lib/collapseDuplicateDeclarations.js +28 -0
- package/src/lib/detectNesting.js +39 -0
- package/src/lib/evaluateTailwindFunctions.js +5 -2
- package/src/lib/expandTailwindAtRules.js +24 -32
- package/src/lib/generateRules.js +230 -20
- package/src/lib/normalizeTailwindDirectives.js +3 -2
- package/src/lib/resolveDefaultsAtRules.js +46 -30
- package/src/lib/setupContextUtils.js +275 -113
- package/src/lib/setupTrackingContext.js +9 -8
- package/src/lib/setupWatchingContext.js +12 -7
- package/src/lib/sharedState.js +1 -4
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/processTailwindFeatures.js +8 -1
- package/src/public/colors.js +300 -0
- package/src/public/create-plugin.js +2 -0
- package/src/public/default-config.js +4 -0
- package/src/public/default-theme.js +4 -0
- package/src/public/resolve-config.js +7 -0
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/createUtilityPlugin.js +2 -11
- package/src/util/dataTypes.js +246 -0
- package/src/util/formatVariantSelector.js +196 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +18 -21
- package/src/util/nameClass.js +10 -6
- package/src/util/negateValue.js +4 -2
- package/src/util/normalizeConfig.js +249 -0
- package/src/util/normalizeScreens.js +42 -0
- package/src/util/parseAnimationValue.js +7 -1
- package/src/util/parseBoxShadowValue.js +71 -0
- package/src/util/parseDependency.js +4 -0
- package/src/util/pluginUtils.js +101 -204
- package/src/util/prefixSelector.js +1 -4
- package/src/util/resolveConfig.js +12 -65
- package/src/util/transformThemeValue.js +22 -7
- package/src/util/withAlphaVariable.js +13 -8
- package/stubs/defaultConfig.stub.js +163 -97
- package/stubs/simpleConfig.stub.js +0 -1
package/lib/lib/generateRules.js
CHANGED
|
@@ -1,116 +1,114 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports.resolveMatches =
|
|
7
|
-
exports.generateRules = generateRules;
|
|
8
|
-
|
|
5
|
+
exports.generateRules = exports.resolveMatches = void 0;
|
|
9
6
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
10
|
-
|
|
11
7
|
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
12
|
-
|
|
13
8
|
var _parseObjectStyles = _interopRequireDefault(require("../util/parseObjectStyles"));
|
|
14
|
-
|
|
15
9
|
var _isPlainObject = _interopRequireDefault(require("../util/isPlainObject"));
|
|
16
|
-
|
|
17
10
|
var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
|
|
18
|
-
|
|
19
11
|
var _pluginUtils = require("../util/pluginUtils");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
var _log = _interopRequireDefault(require("../util/log"));
|
|
13
|
+
var _formatVariantSelector = require("../util/formatVariantSelector");
|
|
14
|
+
var _nameClass = require("../util/nameClass");
|
|
15
|
+
var _dataTypes = require("../util/dataTypes");
|
|
16
|
+
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
17
|
+
function _interopRequireDefault(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
let classNameParser = (0, _postcssSelectorParser).default((selectors)=>{
|
|
23
|
+
return selectors.first.filter(({ type })=>type === 'class'
|
|
24
|
+
).pop().value;
|
|
27
25
|
});
|
|
28
|
-
|
|
29
26
|
function getClassNameFromSelector(selector) {
|
|
30
|
-
|
|
31
|
-
}
|
|
27
|
+
return classNameParser.transformSync(selector);
|
|
28
|
+
}
|
|
29
|
+
// Generate match permutations for a class candidate, like:
|
|
32
30
|
// ['ring-offset-blue', '100']
|
|
33
31
|
// ['ring-offset', 'blue-100']
|
|
34
32
|
// ['ring', 'offset-blue-100']
|
|
35
33
|
// Example with dynamic classes:
|
|
36
34
|
// ['grid-cols', '[[linename],1fr,auto]']
|
|
37
35
|
// ['grid', 'cols-[[linename],1fr,auto]']
|
|
38
|
-
|
|
39
|
-
|
|
40
36
|
function* candidatePermutations(candidate, lastIndex = Infinity) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
37
|
+
if (lastIndex < 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let dashIdx;
|
|
41
|
+
if (lastIndex === Infinity && candidate.endsWith(']')) {
|
|
42
|
+
let bracketIdx = candidate.indexOf('[');
|
|
43
|
+
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
44
|
+
// eg. string[]
|
|
45
|
+
dashIdx = [
|
|
46
|
+
'-',
|
|
47
|
+
'/'
|
|
48
|
+
].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
|
|
49
|
+
} else {
|
|
50
|
+
dashIdx = candidate.lastIndexOf('-', lastIndex);
|
|
51
|
+
}
|
|
52
|
+
if (dashIdx < 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let prefix = candidate.slice(0, dashIdx);
|
|
56
|
+
let modifier = candidate.slice(dashIdx + 1);
|
|
57
|
+
yield [
|
|
58
|
+
prefix,
|
|
59
|
+
modifier
|
|
60
|
+
];
|
|
61
|
+
yield* candidatePermutations(candidate, dashIdx - 1);
|
|
64
62
|
}
|
|
65
|
-
|
|
66
63
|
function applyPrefix(matches, context) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
if (matches.length === 0 || context.tailwindConfig.prefix === '') {
|
|
65
|
+
return matches;
|
|
66
|
+
}
|
|
67
|
+
for (let match of matches){
|
|
68
|
+
let [meta] = match;
|
|
69
|
+
if (meta.options.respectPrefix) {
|
|
70
|
+
let container = _postcss.default.root({
|
|
71
|
+
nodes: [
|
|
72
|
+
match[1].clone()
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
container.walkRules((r)=>{
|
|
76
|
+
r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector);
|
|
77
|
+
});
|
|
78
|
+
match[1] = container.nodes[0];
|
|
79
|
+
}
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return matches;
|
|
81
|
+
return matches;
|
|
87
82
|
}
|
|
88
|
-
|
|
89
83
|
function applyImportant(matches) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
84
|
+
if (matches.length === 0) {
|
|
85
|
+
return matches;
|
|
86
|
+
}
|
|
87
|
+
let result = [];
|
|
88
|
+
for (let [meta, rule] of matches){
|
|
89
|
+
let container = _postcss.default.root({
|
|
90
|
+
nodes: [
|
|
91
|
+
rule.clone()
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
container.walkRules((r)=>{
|
|
95
|
+
r.selector = (0, _pluginUtils).updateAllClasses(r.selector, (className)=>{
|
|
96
|
+
return `!${className}`;
|
|
97
|
+
});
|
|
98
|
+
r.walkDecls((d)=>d.important = true
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
result.push([
|
|
102
|
+
{
|
|
103
|
+
...meta,
|
|
104
|
+
important: true
|
|
105
|
+
},
|
|
106
|
+
container.nodes[0]
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
// Takes a list of rule tuples and applies a variant like `hover`, sm`,
|
|
114
112
|
// whatever to it. We used to do some extra caching here to avoid generating
|
|
115
113
|
// a variant of the same rule more than once, but this was never hit because
|
|
116
114
|
// we cache at the entire selector level further up the tree.
|
|
@@ -118,245 +116,414 @@ function applyImportant(matches) {
|
|
|
118
116
|
// Technically you can get a cache hit if you have `hover:focus:text-center`
|
|
119
117
|
// and `focus:hover:text-center` in the same project, but it doesn't feel
|
|
120
118
|
// worth the complexity for that case.
|
|
121
|
-
|
|
122
|
-
|
|
123
119
|
function applyVariant(variant, matches, context) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
let container = _postcss.default.root({
|
|
139
|
-
nodes: [rule.clone()]
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
for (let [variantSort, variantFunction] of variantFunctionTuples) {
|
|
143
|
-
let clone = container.clone();
|
|
144
|
-
|
|
145
|
-
function modifySelectors(modifierFunction) {
|
|
146
|
-
clone.each(rule => {
|
|
147
|
-
if (rule.type !== 'rule') {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
rule.selectors = rule.selectors.map(selector => {
|
|
152
|
-
return modifierFunction({
|
|
153
|
-
get className() {
|
|
154
|
-
return getClassNameFromSelector(selector);
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
selector
|
|
158
|
-
});
|
|
120
|
+
if (matches.length === 0) {
|
|
121
|
+
return matches;
|
|
122
|
+
}
|
|
123
|
+
if (context.variantMap.has(variant)) {
|
|
124
|
+
let variantFunctionTuples = context.variantMap.get(variant);
|
|
125
|
+
let result = [];
|
|
126
|
+
for (let [meta, rule1] of matches){
|
|
127
|
+
let container = _postcss.default.root({
|
|
128
|
+
nodes: [
|
|
129
|
+
rule1.clone()
|
|
130
|
+
]
|
|
159
131
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
132
|
+
for (let [variantSort, variantFunction] of variantFunctionTuples){
|
|
133
|
+
let clone = container.clone();
|
|
134
|
+
let collectedFormats = [];
|
|
135
|
+
let originals = new Map();
|
|
136
|
+
function prepareBackup() {
|
|
137
|
+
if (originals.size > 0) return; // Already prepared, chicken out
|
|
138
|
+
clone.walkRules((rule)=>originals.set(rule, rule.selector)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function modifySelectors(modifierFunction) {
|
|
142
|
+
prepareBackup();
|
|
143
|
+
clone.each((rule)=>{
|
|
144
|
+
if (rule.type !== 'rule') {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
148
|
+
return modifierFunction({
|
|
149
|
+
get className () {
|
|
150
|
+
return getClassNameFromSelector(selector);
|
|
151
|
+
},
|
|
152
|
+
selector
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
return clone;
|
|
157
|
+
}
|
|
158
|
+
let ruleWithVariant = variantFunction({
|
|
159
|
+
// Public API
|
|
160
|
+
get container () {
|
|
161
|
+
prepareBackup();
|
|
162
|
+
return clone;
|
|
163
|
+
},
|
|
164
|
+
separator: context.tailwindConfig.separator,
|
|
165
|
+
modifySelectors,
|
|
166
|
+
// Private API for now
|
|
167
|
+
wrap (wrapper) {
|
|
168
|
+
let nodes = clone.nodes;
|
|
169
|
+
clone.removeAll();
|
|
170
|
+
wrapper.append(nodes);
|
|
171
|
+
clone.append(wrapper);
|
|
172
|
+
},
|
|
173
|
+
format (selectorFormat) {
|
|
174
|
+
collectedFormats.push(selectorFormat);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (typeof ruleWithVariant === 'string') {
|
|
178
|
+
collectedFormats.push(ruleWithVariant);
|
|
179
|
+
}
|
|
180
|
+
if (ruleWithVariant === null) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
// We filled the `originals`, therefore we assume that somebody touched
|
|
184
|
+
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
185
|
+
// can restore the selectors, and collect the format strings.
|
|
186
|
+
if (originals.size > 0) {
|
|
187
|
+
clone.walkRules((rule)=>{
|
|
188
|
+
if (!originals.has(rule)) return;
|
|
189
|
+
let before = originals.get(rule);
|
|
190
|
+
if (before === rule.selector) return; // No mutation happened
|
|
191
|
+
let modified = rule.selector;
|
|
192
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
193
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
194
|
+
// However, plugin authors probably also prepend or append certain
|
|
195
|
+
// classes, pseudos, ids, ...
|
|
196
|
+
let rebuiltBase = (0, _postcssSelectorParser).default((selectors)=>{
|
|
197
|
+
selectors.walkClasses((classNode)=>{
|
|
198
|
+
classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
|
|
199
|
+
});
|
|
200
|
+
}).processSync(before);
|
|
201
|
+
// Now that we know the original selector, the new selector, and
|
|
202
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
203
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
204
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
205
|
+
//
|
|
206
|
+
// E.g.:
|
|
207
|
+
// variant: foo
|
|
208
|
+
// selector: .markdown > p
|
|
209
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
210
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
211
|
+
// format: .foo &
|
|
212
|
+
collectedFormats.push(modified.replace(rebuiltBase, '&'));
|
|
213
|
+
rule.selector = before;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
var _collectedFormats;
|
|
217
|
+
let withOffset = [
|
|
218
|
+
{
|
|
219
|
+
...meta,
|
|
220
|
+
sort: variantSort | meta.sort,
|
|
221
|
+
collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats)
|
|
222
|
+
},
|
|
223
|
+
clone.nodes[0],
|
|
224
|
+
];
|
|
225
|
+
result.push(withOffset);
|
|
226
|
+
}
|
|
172
227
|
}
|
|
173
|
-
|
|
174
|
-
let withOffset = [{ ...meta,
|
|
175
|
-
sort: variantSort | meta.sort
|
|
176
|
-
}, clone.nodes[0]];
|
|
177
|
-
result.push(withOffset);
|
|
178
|
-
}
|
|
228
|
+
return result;
|
|
179
229
|
}
|
|
180
|
-
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return [];
|
|
230
|
+
return [];
|
|
185
231
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
232
|
+
function parseRules(rule, cache, options = {
|
|
233
|
+
}) {
|
|
234
|
+
// PostCSS node
|
|
235
|
+
if (!(0, _isPlainObject).default(rule) && !Array.isArray(rule)) {
|
|
236
|
+
return [
|
|
237
|
+
[
|
|
238
|
+
rule
|
|
239
|
+
],
|
|
240
|
+
options
|
|
241
|
+
];
|
|
242
|
+
}
|
|
243
|
+
// Tuple
|
|
244
|
+
if (Array.isArray(rule)) {
|
|
245
|
+
return parseRules(rule[0], cache, rule[1]);
|
|
246
|
+
}
|
|
247
|
+
// Simple object
|
|
248
|
+
if (!cache.has(rule)) {
|
|
249
|
+
cache.set(rule, (0, _parseObjectStyles).default(rule));
|
|
250
|
+
}
|
|
251
|
+
return [
|
|
252
|
+
cache.get(rule),
|
|
253
|
+
options
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
function extractArbitraryProperty(classCandidate, context) {
|
|
257
|
+
var ref;
|
|
258
|
+
let [, property, value] = (ref = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && ref !== void 0 ? ref : [];
|
|
259
|
+
if (value === undefined) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
let normalized = (0, _dataTypes).normalize(value);
|
|
263
|
+
if (!(0, _isValidArbitraryValue).default(normalized)) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return [
|
|
267
|
+
[
|
|
268
|
+
{
|
|
269
|
+
sort: context.arbitraryPropertiesSort,
|
|
270
|
+
layer: 'utilities'
|
|
271
|
+
},
|
|
272
|
+
()=>({
|
|
273
|
+
[(0, _nameClass).asClass(classCandidate)]: {
|
|
274
|
+
[property]: normalized
|
|
275
|
+
}
|
|
276
|
+
})
|
|
277
|
+
,
|
|
278
|
+
],
|
|
279
|
+
];
|
|
204
280
|
}
|
|
205
|
-
|
|
206
281
|
function* resolveMatchedPlugins(classCandidate, context) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
282
|
+
if (context.candidateRuleMap.has(classCandidate)) {
|
|
283
|
+
yield [
|
|
284
|
+
context.candidateRuleMap.get(classCandidate),
|
|
285
|
+
'DEFAULT'
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
yield* (function*(arbitraryPropertyRule) {
|
|
289
|
+
if (arbitraryPropertyRule !== null) {
|
|
290
|
+
yield [
|
|
291
|
+
arbitraryPropertyRule,
|
|
292
|
+
'DEFAULT'
|
|
293
|
+
];
|
|
294
|
+
}
|
|
295
|
+
})(extractArbitraryProperty(classCandidate, context));
|
|
296
|
+
let candidatePrefix = classCandidate;
|
|
297
|
+
let negative = false;
|
|
298
|
+
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
299
|
+
const twConfigPrefixLen = twConfigPrefix.length;
|
|
300
|
+
if (candidatePrefix[twConfigPrefixLen] === '-') {
|
|
301
|
+
negative = true;
|
|
302
|
+
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
303
|
+
}
|
|
304
|
+
if (negative && context.candidateRuleMap.has(candidatePrefix)) {
|
|
305
|
+
yield [
|
|
306
|
+
context.candidateRuleMap.get(candidatePrefix),
|
|
307
|
+
'-DEFAULT'
|
|
308
|
+
];
|
|
309
|
+
}
|
|
310
|
+
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
|
|
311
|
+
if (context.candidateRuleMap.has(prefix)) {
|
|
312
|
+
yield [
|
|
313
|
+
context.candidateRuleMap.get(prefix),
|
|
314
|
+
negative ? `-${modifier}` : modifier
|
|
315
|
+
];
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
225
318
|
}
|
|
226
|
-
}
|
|
227
319
|
}
|
|
228
|
-
|
|
229
320
|
function splitWithSeparator(input, separator) {
|
|
230
|
-
|
|
321
|
+
return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'));
|
|
231
322
|
}
|
|
232
|
-
|
|
233
323
|
function* resolveMatches(candidate, context) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
324
|
+
let separator = context.tailwindConfig.separator;
|
|
325
|
+
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
326
|
+
let important = false;
|
|
327
|
+
if (classCandidate.startsWith('!')) {
|
|
328
|
+
important = true;
|
|
329
|
+
classCandidate = classCandidate.slice(1);
|
|
330
|
+
}
|
|
331
|
+
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
332
|
+
// function sortAgainst(toSort, against) {
|
|
333
|
+
// return toSort.slice().sort((a, z) => {
|
|
334
|
+
// return bigSign(against.get(a)[0] - against.get(z)[0])
|
|
335
|
+
// })
|
|
336
|
+
// }
|
|
337
|
+
// let sorted = sortAgainst(variants, context.variantMap)
|
|
338
|
+
// if (sorted.toString() !== variants.toString()) {
|
|
339
|
+
// let corrected = sorted.reverse().concat(classCandidate).join(':')
|
|
340
|
+
// throw new Error(`Class ${candidate} should be written as ${corrected}`)
|
|
341
|
+
// }
|
|
342
|
+
for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)){
|
|
343
|
+
let matches = [];
|
|
344
|
+
let typesByMatches = new Map();
|
|
345
|
+
let [plugins, modifier] = matchedPlugins;
|
|
346
|
+
let isOnlyPlugin = plugins.length === 1;
|
|
347
|
+
for (let [sort, plugin] of plugins){
|
|
348
|
+
let matchesPerPlugin = [];
|
|
349
|
+
if (typeof plugin === 'function') {
|
|
350
|
+
for (let ruleSet of [].concat(plugin(modifier, {
|
|
351
|
+
isOnlyPlugin
|
|
352
|
+
}))){
|
|
353
|
+
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
354
|
+
for (let rule of rules){
|
|
355
|
+
matchesPerPlugin.push([
|
|
356
|
+
{
|
|
357
|
+
...sort,
|
|
358
|
+
options: {
|
|
359
|
+
...sort.options,
|
|
360
|
+
...options
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
rule
|
|
364
|
+
]);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
} else if (modifier === 'DEFAULT' || modifier === '-DEFAULT') {
|
|
368
|
+
let ruleSet = plugin;
|
|
369
|
+
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
370
|
+
for (let rule of rules){
|
|
371
|
+
matchesPerPlugin.push([
|
|
372
|
+
{
|
|
373
|
+
...sort,
|
|
374
|
+
options: {
|
|
375
|
+
...sort.options,
|
|
376
|
+
...options
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
rule
|
|
380
|
+
]);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (matchesPerPlugin.length > 0) {
|
|
384
|
+
var ref;
|
|
385
|
+
typesByMatches.set(matchesPerPlugin, (ref = sort.options) === null || ref === void 0 ? void 0 : ref.type);
|
|
386
|
+
matches.push(matchesPerPlugin);
|
|
387
|
+
}
|
|
270
388
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
389
|
+
// Only keep the result of the very first plugin if we are dealing with
|
|
390
|
+
// arbitrary values, to protect against ambiguity.
|
|
391
|
+
if (isArbitraryValue(modifier) && matches.length > 1) {
|
|
392
|
+
var ref1;
|
|
393
|
+
let typesPerPlugin = matches.map((match)=>new Set([
|
|
394
|
+
...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
|
|
395
|
+
])
|
|
396
|
+
);
|
|
397
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
398
|
+
for (let pluginTypes of typesPerPlugin){
|
|
399
|
+
for (let type of pluginTypes){
|
|
400
|
+
let removeFromOwnGroup = false;
|
|
401
|
+
for (let otherGroup of typesPerPlugin){
|
|
402
|
+
if (pluginTypes === otherGroup) continue;
|
|
403
|
+
if (otherGroup.has(type)) {
|
|
404
|
+
otherGroup.delete(type);
|
|
405
|
+
removeFromOwnGroup = true;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
409
|
+
}
|
|
280
410
|
}
|
|
281
|
-
|
|
411
|
+
let messages = [];
|
|
412
|
+
for (let [idx, group] of typesPerPlugin.entries()){
|
|
413
|
+
for (let type of group){
|
|
414
|
+
let rules = matches[idx].map(([, rule])=>rule
|
|
415
|
+
).flat().map((rule)=>rule.toString().split('\n').slice(1, -1) // Remove selector and closing '}'
|
|
416
|
+
.map((line)=>line.trim()
|
|
417
|
+
).map((x)=>` ${x}`
|
|
418
|
+
) // Re-indent
|
|
419
|
+
.join('\n')
|
|
420
|
+
).join('\n\n');
|
|
421
|
+
messages.push(` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
_log.default.warn([
|
|
426
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
427
|
+
...messages,
|
|
428
|
+
`If this is content and not a class, replace it with \`${candidate.replace('[', '[').replace(']', ']')}\` to silence this warning.`,
|
|
429
|
+
]);
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
matches = applyPrefix(matches.flat(), context);
|
|
433
|
+
if (important) {
|
|
434
|
+
matches = applyImportant(matches, context);
|
|
435
|
+
}
|
|
436
|
+
for (let variant of variants){
|
|
437
|
+
matches = applyVariant(variant, matches, context);
|
|
438
|
+
}
|
|
439
|
+
for (let match1 of matches){
|
|
440
|
+
// Apply final format selector
|
|
441
|
+
if (match1[0].collectedFormats) {
|
|
442
|
+
let finalFormat = (0, _formatVariantSelector).formatVariantSelector('&', ...match1[0].collectedFormats);
|
|
443
|
+
let container = _postcss.default.root({
|
|
444
|
+
nodes: [
|
|
445
|
+
match1[1].clone()
|
|
446
|
+
]
|
|
447
|
+
});
|
|
448
|
+
container.walkRules((rule)=>{
|
|
449
|
+
if (inKeyframes(rule)) return;
|
|
450
|
+
rule.selector = (0, _formatVariantSelector).finalizeSelector(finalFormat, {
|
|
451
|
+
selector: rule.selector,
|
|
452
|
+
candidate,
|
|
453
|
+
context
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
match1[1] = container.nodes[0];
|
|
457
|
+
}
|
|
458
|
+
yield match1;
|
|
282
459
|
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
matches = applyPrefix(matches, context);
|
|
287
|
-
|
|
288
|
-
if (important) {
|
|
289
|
-
matches = applyImportant(matches, context);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
for (let variant of variants) {
|
|
293
|
-
matches = applyVariant(variant, matches, context);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
for (let match of matches) {
|
|
297
|
-
yield match;
|
|
298
460
|
}
|
|
299
|
-
}
|
|
300
461
|
}
|
|
301
|
-
|
|
302
462
|
function inKeyframes(rule) {
|
|
303
|
-
|
|
463
|
+
return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes';
|
|
304
464
|
}
|
|
305
|
-
|
|
306
465
|
function generateRules(candidates, context) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
context.classCache.set(candidate, matches);
|
|
327
|
-
allRules.push(matches);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
return allRules.flat(1).map(([{
|
|
331
|
-
sort,
|
|
332
|
-
layer,
|
|
333
|
-
options
|
|
334
|
-
}, rule]) => {
|
|
335
|
-
if (options.respectImportant) {
|
|
336
|
-
if (context.tailwindConfig.important === true) {
|
|
337
|
-
rule.walkDecls(d => {
|
|
338
|
-
if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
|
|
339
|
-
d.important = true;
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
} else if (typeof context.tailwindConfig.important === 'string') {
|
|
343
|
-
let container = _postcss.default.root({
|
|
344
|
-
nodes: [rule.clone()]
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
container.walkRules(r => {
|
|
348
|
-
if (inKeyframes(r)) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
r.selectors = r.selectors.map(selector => {
|
|
353
|
-
return `${context.tailwindConfig.important} ${selector}`;
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
rule = container.nodes[0];
|
|
357
|
-
}
|
|
466
|
+
let allRules = [];
|
|
467
|
+
for (let candidate of candidates){
|
|
468
|
+
if (context.notClassCache.has(candidate)) {
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
if (context.classCache.has(candidate)) {
|
|
472
|
+
allRules.push(context.classCache.get(candidate));
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
let matches = Array.from(resolveMatches(candidate, context));
|
|
476
|
+
if (matches.length === 0) {
|
|
477
|
+
context.notClassCache.add(candidate);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
context.classCache.set(candidate, matches);
|
|
481
|
+
allRules.push(matches);
|
|
358
482
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
483
|
+
// Strategy based on `tailwindConfig.important`
|
|
484
|
+
let strategy = ((important)=>{
|
|
485
|
+
if (important === true) {
|
|
486
|
+
return (rule)=>{
|
|
487
|
+
rule.walkDecls((d)=>{
|
|
488
|
+
if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
|
|
489
|
+
d.important = true;
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
if (typeof important === 'string') {
|
|
495
|
+
return (rule)=>{
|
|
496
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
497
|
+
return `${important} ${selector}`;
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
})(context.tailwindConfig.important);
|
|
502
|
+
return allRules.flat(1).map(([{ sort , layer , options }, rule])=>{
|
|
503
|
+
if (options.respectImportant) {
|
|
504
|
+
if (strategy) {
|
|
505
|
+
let container = _postcss.default.root({
|
|
506
|
+
nodes: [
|
|
507
|
+
rule.clone()
|
|
508
|
+
]
|
|
509
|
+
});
|
|
510
|
+
container.walkRules((r)=>{
|
|
511
|
+
if (inKeyframes(r)) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
strategy(r);
|
|
515
|
+
});
|
|
516
|
+
rule = container.nodes[0];
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return [
|
|
520
|
+
sort | context.layerOrder[layer],
|
|
521
|
+
rule
|
|
522
|
+
];
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
function isArbitraryValue(input) {
|
|
526
|
+
return input.startsWith('[') && input.endsWith(']');
|
|
527
|
+
}
|
|
528
|
+
exports.resolveMatches = resolveMatches;
|
|
529
|
+
exports.generateRules = generateRules;
|