tailwindcss 3.0.23 → 3.1.1
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 +92 -2
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +3 -0
- package/lib/cli-peer-dependencies.js +10 -5
- package/lib/cli.js +266 -203
- package/lib/constants.js +8 -8
- package/lib/corePluginList.js +1 -0
- package/lib/corePlugins.js +1640 -1562
- package/lib/css/preflight.css +1 -8
- package/lib/featureFlags.js +14 -12
- package/lib/index.js +16 -6
- package/lib/lib/cacheInvalidation.js +87 -0
- package/lib/lib/collapseAdjacentRules.js +30 -15
- package/lib/lib/collapseDuplicateDeclarations.js +1 -1
- package/lib/lib/defaultExtractor.js +191 -32
- package/lib/lib/detectNesting.js +9 -9
- package/lib/lib/evaluateTailwindFunctions.js +37 -28
- package/lib/lib/expandApplyAtRules.js +379 -189
- package/lib/lib/expandTailwindAtRules.js +168 -144
- package/lib/lib/generateRules.js +177 -95
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +35 -35
- package/lib/lib/partitionApplyAtRules.js +7 -7
- package/lib/lib/regex.js +52 -0
- package/lib/lib/resolveDefaultsAtRules.js +96 -81
- package/lib/lib/setupContextUtils.js +202 -159
- package/lib/lib/setupTrackingContext.js +61 -63
- package/lib/lib/sharedState.js +10 -9
- package/lib/lib/substituteScreenAtRules.js +3 -4
- package/lib/postcss-plugins/nesting/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +1 -1
- package/lib/postcss-plugins/nesting/plugin.js +40 -9
- package/lib/processTailwindFeatures.js +7 -7
- package/lib/public/colors.js +241 -241
- package/lib/public/resolve-config.js +5 -5
- package/lib/util/buildMediaQuery.js +2 -3
- package/lib/util/cloneDeep.js +3 -5
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +42 -51
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +6 -7
- package/lib/util/dataTypes.js +85 -81
- package/lib/util/escapeClassName.js +5 -5
- package/lib/util/escapeCommas.js +1 -1
- package/lib/util/flattenColorPalette.js +4 -7
- package/lib/util/formatVariantSelector.js +82 -75
- package/lib/util/getAllConfigs.js +15 -10
- package/lib/util/hashConfig.js +5 -5
- package/lib/util/isKeyframeRule.js +1 -1
- package/lib/util/isPlainObject.js +1 -1
- package/lib/util/isValidArbitraryValue.js +26 -27
- package/lib/util/log.js +9 -10
- package/lib/util/nameClass.js +7 -7
- package/lib/util/negateValue.js +4 -5
- package/lib/util/normalizeConfig.js +68 -58
- package/lib/util/normalizeScreens.js +5 -6
- package/lib/util/parseAnimationValue.js +56 -57
- package/lib/util/parseBoxShadowValue.js +19 -20
- package/lib/util/parseDependency.js +32 -32
- package/lib/util/parseObjectStyles.js +6 -6
- package/lib/util/pluginUtils.js +20 -12
- package/lib/util/prefixSelector.js +1 -1
- package/lib/util/resolveConfig.js +81 -58
- package/lib/util/resolveConfigPath.js +16 -16
- package/lib/util/responsive.js +6 -6
- package/lib/util/splitAtTopLevelOnly.js +90 -0
- package/lib/util/toColorValue.js +1 -1
- package/lib/util/toPath.js +2 -2
- package/lib/util/transformThemeValue.js +30 -28
- package/lib/util/validateConfig.js +21 -0
- package/lib/util/withAlphaVariable.js +23 -23
- package/package.json +33 -27
- package/peers/index.js +7702 -5822
- package/plugin.d.ts +11 -0
- package/scripts/generate-types.js +52 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +118 -24
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +109 -30
- package/src/css/preflight.css +1 -8
- package/src/featureFlags.js +4 -4
- package/src/index.js +15 -1
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/defaultExtractor.js +177 -35
- package/src/lib/evaluateTailwindFunctions.js +20 -4
- package/src/lib/expandApplyAtRules.js +418 -186
- package/src/lib/expandTailwindAtRules.js +29 -9
- package/src/lib/generateRules.js +137 -51
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -32
- package/src/lib/setupContextUtils.js +128 -65
- package/src/lib/setupTrackingContext.js +7 -3
- package/src/lib/sharedState.js +1 -0
- package/src/postcss-plugins/nesting/README.md +2 -2
- package/src/postcss-plugins/nesting/plugin.js +36 -0
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +25 -21
- package/src/util/dataTypes.js +14 -6
- package/src/util/formatVariantSelector.js +79 -62
- package/src/util/getAllConfigs.js +7 -0
- package/src/util/log.js +8 -8
- package/src/util/normalizeConfig.js +0 -8
- package/src/util/parseBoxShadowValue.js +3 -2
- package/src/util/pluginUtils.js +13 -1
- package/src/util/resolveConfig.js +66 -22
- package/src/util/splitAtTopLevelOnly.js +71 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +4 -2
- package/src/util/validateConfig.js +13 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/stubs/defaultConfig.stub.js +5 -1
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +325 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/index.d.ts +7 -0
package/lib/lib/generateRules.js
CHANGED
|
@@ -14,36 +14,56 @@ var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
|
14
14
|
var _formatVariantSelector = require("../util/formatVariantSelector");
|
|
15
15
|
var _nameClass = require("../util/nameClass");
|
|
16
16
|
var _dataTypes = require("../util/dataTypes");
|
|
17
|
+
var _setupContextUtils = require("./setupContextUtils");
|
|
17
18
|
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
19
|
+
var _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
|
|
20
|
+
var _featureFlags = require("../featureFlags");
|
|
18
21
|
function _interopRequireDefault(obj) {
|
|
19
22
|
return obj && obj.__esModule ? obj : {
|
|
20
23
|
default: obj
|
|
21
24
|
};
|
|
22
25
|
}
|
|
26
|
+
function _getRequireWildcardCache() {
|
|
27
|
+
if (typeof WeakMap !== "function") return null;
|
|
28
|
+
var cache = new WeakMap();
|
|
29
|
+
_getRequireWildcardCache = function() {
|
|
30
|
+
return cache;
|
|
31
|
+
};
|
|
32
|
+
return cache;
|
|
33
|
+
}
|
|
23
34
|
function _interopRequireWildcard(obj) {
|
|
24
35
|
if (obj && obj.__esModule) {
|
|
25
36
|
return obj;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
}
|
|
38
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
39
|
+
return {
|
|
40
|
+
default: obj
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var cache = _getRequireWildcardCache();
|
|
44
|
+
if (cache && cache.has(obj)) {
|
|
45
|
+
return cache.get(obj);
|
|
46
|
+
}
|
|
47
|
+
var newObj = {};
|
|
48
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
49
|
+
for(var key in obj){
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
51
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
52
|
+
if (desc && (desc.get || desc.set)) {
|
|
53
|
+
Object.defineProperty(newObj, key, desc);
|
|
54
|
+
} else {
|
|
55
|
+
newObj[key] = obj[key];
|
|
38
56
|
}
|
|
39
57
|
}
|
|
40
|
-
newObj.default = obj;
|
|
41
|
-
return newObj;
|
|
42
58
|
}
|
|
59
|
+
newObj.default = obj;
|
|
60
|
+
if (cache) {
|
|
61
|
+
cache.set(obj, newObj);
|
|
62
|
+
}
|
|
63
|
+
return newObj;
|
|
43
64
|
}
|
|
44
65
|
let classNameParser = (0, _postcssSelectorParser).default((selectors)=>{
|
|
45
|
-
return selectors.first.filter(({ type })=>type ===
|
|
46
|
-
).pop().value;
|
|
66
|
+
return selectors.first.filter(({ type })=>type === "class").pop().value;
|
|
47
67
|
});
|
|
48
68
|
function getClassNameFromSelector(selector) {
|
|
49
69
|
return classNameParser.transformSync(selector);
|
|
@@ -59,16 +79,16 @@ function* candidatePermutations(candidate) {
|
|
|
59
79
|
let lastIndex = Infinity;
|
|
60
80
|
while(lastIndex >= 0){
|
|
61
81
|
let dashIdx;
|
|
62
|
-
if (lastIndex === Infinity && candidate.endsWith(
|
|
63
|
-
let bracketIdx = candidate.indexOf(
|
|
82
|
+
if (lastIndex === Infinity && candidate.endsWith("]")) {
|
|
83
|
+
let bracketIdx = candidate.indexOf("[");
|
|
64
84
|
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
65
85
|
// eg. string[]
|
|
66
86
|
dashIdx = [
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
"-",
|
|
88
|
+
"/"
|
|
69
89
|
].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
|
|
70
90
|
} else {
|
|
71
|
-
dashIdx = candidate.lastIndexOf(
|
|
91
|
+
dashIdx = candidate.lastIndexOf("-", lastIndex);
|
|
72
92
|
}
|
|
73
93
|
if (dashIdx < 0) {
|
|
74
94
|
break;
|
|
@@ -83,7 +103,7 @@ function* candidatePermutations(candidate) {
|
|
|
83
103
|
}
|
|
84
104
|
}
|
|
85
105
|
function applyPrefix(matches, context) {
|
|
86
|
-
if (matches.length === 0 || context.tailwindConfig.prefix ===
|
|
106
|
+
if (matches.length === 0 || context.tailwindConfig.prefix === "") {
|
|
87
107
|
return matches;
|
|
88
108
|
}
|
|
89
109
|
for (let match of matches){
|
|
@@ -100,7 +120,7 @@ function applyPrefix(matches, context) {
|
|
|
100
120
|
// have to ensure that the generated selector matches the candidate
|
|
101
121
|
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
102
122
|
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
103
|
-
let shouldPrependNegative = classCandidate.startsWith(
|
|
123
|
+
let shouldPrependNegative = classCandidate.startsWith("-");
|
|
104
124
|
r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
|
|
105
125
|
});
|
|
106
126
|
match[1] = container.nodes[0];
|
|
@@ -108,7 +128,7 @@ function applyPrefix(matches, context) {
|
|
|
108
128
|
}
|
|
109
129
|
return matches;
|
|
110
130
|
}
|
|
111
|
-
function applyImportant(matches) {
|
|
131
|
+
function applyImportant(matches, classCandidate) {
|
|
112
132
|
if (matches.length === 0) {
|
|
113
133
|
return matches;
|
|
114
134
|
}
|
|
@@ -121,10 +141,12 @@ function applyImportant(matches) {
|
|
|
121
141
|
});
|
|
122
142
|
container.walkRules((r)=>{
|
|
123
143
|
r.selector = (0, _pluginUtils).updateAllClasses(r.selector, (className)=>{
|
|
124
|
-
|
|
144
|
+
if (className === classCandidate) {
|
|
145
|
+
return `!${className}`;
|
|
146
|
+
}
|
|
147
|
+
return className;
|
|
125
148
|
});
|
|
126
|
-
r.walkDecls((d)=>d.important = true
|
|
127
|
-
);
|
|
149
|
+
r.walkDecls((d)=>d.important = true);
|
|
128
150
|
});
|
|
129
151
|
result.push([
|
|
130
152
|
{
|
|
@@ -148,12 +170,34 @@ function applyVariant(variant, matches, context) {
|
|
|
148
170
|
if (matches.length === 0) {
|
|
149
171
|
return matches;
|
|
150
172
|
}
|
|
173
|
+
let args;
|
|
174
|
+
// Find partial arbitrary variants
|
|
175
|
+
if (variant.endsWith("]") && !variant.startsWith("[")) {
|
|
176
|
+
args = variant.slice(variant.lastIndexOf("[") + 1, -1);
|
|
177
|
+
variant = variant.slice(0, variant.indexOf(args) - 1 /* - */ - 1 /* [ */ );
|
|
178
|
+
}
|
|
179
|
+
// Register arbitrary variants
|
|
180
|
+
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
|
|
181
|
+
let selector = (0, _dataTypes).normalize(variant.slice(1, -1));
|
|
182
|
+
if (!(0, _setupContextUtils).isValidVariantFormatString(selector)) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
let fn = (0, _setupContextUtils).parseVariant(selector);
|
|
186
|
+
let sort = Array.from(context.variantOrder.values()).pop() << 1n;
|
|
187
|
+
context.variantMap.set(variant, [
|
|
188
|
+
[
|
|
189
|
+
sort,
|
|
190
|
+
fn
|
|
191
|
+
]
|
|
192
|
+
]);
|
|
193
|
+
context.variantOrder.set(variant, sort);
|
|
194
|
+
}
|
|
151
195
|
if (context.variantMap.has(variant)) {
|
|
152
|
-
let variantFunctionTuples = context.variantMap.get(variant);
|
|
196
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice();
|
|
153
197
|
let result = [];
|
|
154
198
|
for (let [meta, rule1] of matches){
|
|
155
199
|
// Don't generate variants for user css
|
|
156
|
-
if (meta.layer ===
|
|
200
|
+
if (meta.layer === "user") {
|
|
157
201
|
continue;
|
|
158
202
|
}
|
|
159
203
|
let container = _postcss.default.root({
|
|
@@ -167,13 +211,12 @@ function applyVariant(variant, matches, context) {
|
|
|
167
211
|
let originals = new Map();
|
|
168
212
|
function prepareBackup() {
|
|
169
213
|
if (originals.size > 0) return; // Already prepared, chicken out
|
|
170
|
-
clone.walkRules((rule)=>originals.set(rule, rule.selector)
|
|
171
|
-
);
|
|
214
|
+
clone.walkRules((rule)=>originals.set(rule, rule.selector));
|
|
172
215
|
}
|
|
173
216
|
function modifySelectors(modifierFunction) {
|
|
174
217
|
prepareBackup();
|
|
175
218
|
clone.each((rule)=>{
|
|
176
|
-
if (rule.type !==
|
|
219
|
+
if (rule.type !== "rule") {
|
|
177
220
|
return;
|
|
178
221
|
}
|
|
179
222
|
rule.selectors = rule.selectors.map((selector)=>{
|
|
@@ -204,9 +247,29 @@ function applyVariant(variant, matches, context) {
|
|
|
204
247
|
},
|
|
205
248
|
format (selectorFormat) {
|
|
206
249
|
collectedFormats.push(selectorFormat);
|
|
207
|
-
}
|
|
250
|
+
},
|
|
251
|
+
args
|
|
208
252
|
});
|
|
209
|
-
|
|
253
|
+
// It can happen that a list of format strings is returned from within the function. In that
|
|
254
|
+
// case, we have to process them as well. We can use the existing `variantSort`.
|
|
255
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
256
|
+
for (let [idx, variantFunction] of ruleWithVariant.entries()){
|
|
257
|
+
// This is a little bit scary since we are pushing to an array of items that we are
|
|
258
|
+
// currently looping over. However, you can also think of it like a processing queue
|
|
259
|
+
// where you keep handling jobs until everything is done and each job can queue more
|
|
260
|
+
// jobs if needed.
|
|
261
|
+
variantFunctionTuples.push([
|
|
262
|
+
// TODO: This could have potential bugs if we shift the sort order from variant A far
|
|
263
|
+
// enough into the sort space of variant B. The chances are low, but if this happens
|
|
264
|
+
// then this might be the place too look at. One potential solution to this problem is
|
|
265
|
+
// reserving additional X places for these 'unknown' variants in between.
|
|
266
|
+
variantSort | BigInt(idx << ruleWithVariant.length),
|
|
267
|
+
variantFunction,
|
|
268
|
+
]);
|
|
269
|
+
}
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (typeof ruleWithVariant === "string") {
|
|
210
273
|
collectedFormats.push(ruleWithVariant);
|
|
211
274
|
}
|
|
212
275
|
if (ruleWithVariant === null) {
|
|
@@ -241,7 +304,7 @@ function applyVariant(variant, matches, context) {
|
|
|
241
304
|
// modified (by plugin): .foo .foo\\:markdown > p
|
|
242
305
|
// rebuiltBase (internal): .foo\\:markdown > p
|
|
243
306
|
// format: .foo &
|
|
244
|
-
collectedFormats.push(modified.replace(rebuiltBase,
|
|
307
|
+
collectedFormats.push(modified.replace(rebuiltBase, "&"));
|
|
245
308
|
rule.selector = before;
|
|
246
309
|
});
|
|
247
310
|
}
|
|
@@ -302,17 +365,27 @@ function isValidPropName(name) {
|
|
|
302
365
|
*/ function looksLikeUri(declaration) {
|
|
303
366
|
// Quick bailout for obvious non-urls
|
|
304
367
|
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
305
|
-
if (!declaration.includes(
|
|
368
|
+
if (!declaration.includes("://")) {
|
|
306
369
|
return false;
|
|
307
370
|
}
|
|
308
371
|
try {
|
|
309
372
|
const url = new URL(declaration);
|
|
310
|
-
return url.scheme !==
|
|
373
|
+
return url.scheme !== "" && url.host !== "";
|
|
311
374
|
} catch (err) {
|
|
312
375
|
// Definitely not a valid url
|
|
313
376
|
return false;
|
|
314
377
|
}
|
|
315
378
|
}
|
|
379
|
+
function isParsableNode(node) {
|
|
380
|
+
let isParsable = true;
|
|
381
|
+
node.walkDecls((decl)=>{
|
|
382
|
+
if (!isParsableCssValue(decl.name, decl.value)) {
|
|
383
|
+
isParsable = false;
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
return isParsable;
|
|
388
|
+
}
|
|
316
389
|
function isParsableCssValue(property, value) {
|
|
317
390
|
// We don't want to to treat [https://example.com] as a custom property
|
|
318
391
|
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
@@ -347,14 +420,13 @@ function extractArbitraryProperty(classCandidate, context) {
|
|
|
347
420
|
[
|
|
348
421
|
{
|
|
349
422
|
sort: context.arbitraryPropertiesSort,
|
|
350
|
-
layer:
|
|
423
|
+
layer: "utilities"
|
|
351
424
|
},
|
|
352
425
|
()=>({
|
|
353
426
|
[(0, _nameClass).asClass(classCandidate)]: {
|
|
354
427
|
[property]: normalized
|
|
355
428
|
}
|
|
356
|
-
})
|
|
357
|
-
,
|
|
429
|
+
}),
|
|
358
430
|
],
|
|
359
431
|
];
|
|
360
432
|
}
|
|
@@ -362,29 +434,30 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
362
434
|
if (context.candidateRuleMap.has(classCandidate)) {
|
|
363
435
|
yield [
|
|
364
436
|
context.candidateRuleMap.get(classCandidate),
|
|
365
|
-
|
|
437
|
+
"DEFAULT"
|
|
366
438
|
];
|
|
367
439
|
}
|
|
368
|
-
yield*
|
|
440
|
+
yield* function*(arbitraryPropertyRule) {
|
|
369
441
|
if (arbitraryPropertyRule !== null) {
|
|
370
442
|
yield [
|
|
371
443
|
arbitraryPropertyRule,
|
|
372
|
-
|
|
444
|
+
"DEFAULT"
|
|
373
445
|
];
|
|
374
446
|
}
|
|
375
|
-
}
|
|
447
|
+
}(extractArbitraryProperty(classCandidate, context));
|
|
376
448
|
let candidatePrefix = classCandidate;
|
|
377
449
|
let negative = false;
|
|
378
450
|
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
379
451
|
const twConfigPrefixLen = twConfigPrefix.length;
|
|
380
|
-
|
|
452
|
+
const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
|
|
453
|
+
if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
|
|
381
454
|
negative = true;
|
|
382
455
|
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
383
456
|
}
|
|
384
457
|
if (negative && context.candidateRuleMap.has(candidatePrefix)) {
|
|
385
458
|
yield [
|
|
386
459
|
context.candidateRuleMap.get(candidatePrefix),
|
|
387
|
-
|
|
460
|
+
"-DEFAULT"
|
|
388
461
|
];
|
|
389
462
|
}
|
|
390
463
|
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
|
|
@@ -402,7 +475,7 @@ function splitWithSeparator(input, separator) {
|
|
|
402
475
|
sharedState.NOT_ON_DEMAND
|
|
403
476
|
];
|
|
404
477
|
}
|
|
405
|
-
return
|
|
478
|
+
return Array.from((0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(input, separator));
|
|
406
479
|
}
|
|
407
480
|
function* recordCandidates(matches, classCandidate) {
|
|
408
481
|
for (const match of matches){
|
|
@@ -413,14 +486,22 @@ function* recordCandidates(matches, classCandidate) {
|
|
|
413
486
|
yield match;
|
|
414
487
|
}
|
|
415
488
|
}
|
|
416
|
-
function* resolveMatches(candidate, context) {
|
|
489
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
417
490
|
let separator = context.tailwindConfig.separator;
|
|
418
491
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
419
492
|
let important = false;
|
|
420
|
-
if (classCandidate.startsWith(
|
|
493
|
+
if (classCandidate.startsWith("!")) {
|
|
421
494
|
important = true;
|
|
422
495
|
classCandidate = classCandidate.slice(1);
|
|
423
496
|
}
|
|
497
|
+
if ((0, _featureFlags).flagEnabled(context.tailwindConfig, "variantGrouping")) {
|
|
498
|
+
if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
|
|
499
|
+
let base = variants.slice().reverse().join(separator);
|
|
500
|
+
for (let part of (0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(classCandidate.slice(1, -1), ",")){
|
|
501
|
+
yield* resolveMatches(base + separator + part, context, original);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
424
505
|
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
425
506
|
// function sortAgainst(toSort, against) {
|
|
426
507
|
// return toSort.slice().sort((a, z) => {
|
|
@@ -439,7 +520,7 @@ function* resolveMatches(candidate, context) {
|
|
|
439
520
|
let isOnlyPlugin = plugins.length === 1;
|
|
440
521
|
for (let [sort, plugin] of plugins){
|
|
441
522
|
let matchesPerPlugin = [];
|
|
442
|
-
if (typeof plugin ===
|
|
523
|
+
if (typeof plugin === "function") {
|
|
443
524
|
for (let ruleSet of [].concat(plugin(modifier, {
|
|
444
525
|
isOnlyPlugin
|
|
445
526
|
}))){
|
|
@@ -457,7 +538,7 @@ function* resolveMatches(candidate, context) {
|
|
|
457
538
|
]);
|
|
458
539
|
}
|
|
459
540
|
}
|
|
460
|
-
} else if (modifier ===
|
|
541
|
+
} else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
|
|
461
542
|
let ruleSet = plugin;
|
|
462
543
|
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
463
544
|
for (let rule of rules){
|
|
@@ -479,54 +560,52 @@ function* resolveMatches(candidate, context) {
|
|
|
479
560
|
matches.push(matchesPerPlugin);
|
|
480
561
|
}
|
|
481
562
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
563
|
+
if (isArbitraryValue(modifier)) {
|
|
564
|
+
// When generated arbitrary values are ambiguous, we can't know
|
|
565
|
+
// which to pick so don't generate any utilities for them
|
|
566
|
+
if (matches.length > 1) {
|
|
567
|
+
var ref1;
|
|
568
|
+
let typesPerPlugin = matches.map((match)=>new Set([
|
|
569
|
+
...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
|
|
570
|
+
]));
|
|
571
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
572
|
+
for (let pluginTypes of typesPerPlugin){
|
|
573
|
+
for (let type of pluginTypes){
|
|
574
|
+
let removeFromOwnGroup = false;
|
|
575
|
+
for (let otherGroup of typesPerPlugin){
|
|
576
|
+
if (pluginTypes === otherGroup) continue;
|
|
577
|
+
if (otherGroup.has(type)) {
|
|
578
|
+
otherGroup.delete(type);
|
|
579
|
+
removeFromOwnGroup = true;
|
|
580
|
+
}
|
|
499
581
|
}
|
|
582
|
+
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
500
583
|
}
|
|
501
|
-
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
502
584
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
.join('\n')
|
|
513
|
-
).join('\n\n');
|
|
514
|
-
messages.push(` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
515
|
-
break;
|
|
585
|
+
let messages = [];
|
|
586
|
+
for (let [idx, group] of typesPerPlugin.entries()){
|
|
587
|
+
for (let type of group){
|
|
588
|
+
let rules = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
|
|
589
|
+
.map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
|
|
590
|
+
.join("\n")).join("\n\n");
|
|
591
|
+
messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
516
594
|
}
|
|
595
|
+
_log.default.warn([
|
|
596
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
597
|
+
...messages,
|
|
598
|
+
`If this is content and not a class, replace it with \`${candidate.replace("[", "[").replace("]", "]")}\` to silence this warning.`,
|
|
599
|
+
]);
|
|
600
|
+
continue;
|
|
517
601
|
}
|
|
518
|
-
|
|
519
|
-
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
520
|
-
...messages,
|
|
521
|
-
`If this is content and not a class, replace it with \`${candidate.replace('[', '[').replace(']', ']')}\` to silence this warning.`,
|
|
522
|
-
]);
|
|
523
|
-
continue;
|
|
602
|
+
matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
|
|
524
603
|
}
|
|
525
604
|
matches = matches.flat();
|
|
526
605
|
matches = Array.from(recordCandidates(matches, classCandidate));
|
|
527
606
|
matches = applyPrefix(matches, context);
|
|
528
607
|
if (important) {
|
|
529
|
-
matches = applyImportant(matches,
|
|
608
|
+
matches = applyImportant(matches, classCandidate);
|
|
530
609
|
}
|
|
531
610
|
for (let variant of variants){
|
|
532
611
|
matches = applyVariant(variant, matches, context);
|
|
@@ -538,17 +617,20 @@ function* resolveMatches(candidate, context) {
|
|
|
538
617
|
};
|
|
539
618
|
// Apply final format selector
|
|
540
619
|
if (match1[0].collectedFormats) {
|
|
541
|
-
let finalFormat = (0, _formatVariantSelector).formatVariantSelector(
|
|
620
|
+
let finalFormat = (0, _formatVariantSelector).formatVariantSelector("&", ...match1[0].collectedFormats);
|
|
542
621
|
let container = _postcss.default.root({
|
|
543
622
|
nodes: [
|
|
544
623
|
match1[1].clone()
|
|
545
624
|
]
|
|
546
625
|
});
|
|
547
626
|
container.walkRules((rule)=>{
|
|
627
|
+
var ref;
|
|
548
628
|
if (inKeyframes(rule)) return;
|
|
629
|
+
var ref2;
|
|
549
630
|
rule.selector = (0, _formatVariantSelector).finalizeSelector(finalFormat, {
|
|
550
631
|
selector: rule.selector,
|
|
551
|
-
candidate,
|
|
632
|
+
candidate: original,
|
|
633
|
+
base: candidate.split(new RegExp(`\\${(ref2 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref2 !== void 0 ? ref2 : ":"}(?![^[]*\\])`)).pop(),
|
|
552
634
|
context
|
|
553
635
|
});
|
|
554
636
|
});
|
|
@@ -559,7 +641,7 @@ function* resolveMatches(candidate, context) {
|
|
|
559
641
|
}
|
|
560
642
|
}
|
|
561
643
|
function inKeyframes(rule) {
|
|
562
|
-
return rule.parent && rule.parent.type ===
|
|
644
|
+
return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
|
|
563
645
|
}
|
|
564
646
|
function generateRules(candidates, context) {
|
|
565
647
|
let allRules = [];
|
|
@@ -584,13 +666,13 @@ function generateRules(candidates, context) {
|
|
|
584
666
|
if (important === true) {
|
|
585
667
|
return (rule)=>{
|
|
586
668
|
rule.walkDecls((d)=>{
|
|
587
|
-
if (d.parent.type ===
|
|
669
|
+
if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
|
|
588
670
|
d.important = true;
|
|
589
671
|
}
|
|
590
672
|
});
|
|
591
673
|
};
|
|
592
674
|
}
|
|
593
|
-
if (typeof important ===
|
|
675
|
+
if (typeof important === "string") {
|
|
594
676
|
return (rule)=>{
|
|
595
677
|
rule.selectors = rule.selectors.map((selector)=>{
|
|
596
678
|
return `${important} ${selector}`;
|
|
@@ -622,7 +704,7 @@ function generateRules(candidates, context) {
|
|
|
622
704
|
});
|
|
623
705
|
}
|
|
624
706
|
function isArbitraryValue(input) {
|
|
625
|
-
return input.startsWith(
|
|
707
|
+
return input.startsWith("[") && input.endsWith("]");
|
|
626
708
|
}
|
|
627
709
|
exports.resolveMatches = resolveMatches;
|
|
628
710
|
exports.generateRules = generateRules;
|
|
@@ -7,19 +7,6 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
var _resolve = _interopRequireDefault(require("resolve"));
|
|
9
9
|
var _detective = _interopRequireDefault(require("detective"));
|
|
10
|
-
function _interopRequireDefault(obj) {
|
|
11
|
-
return obj && obj.__esModule ? obj : {
|
|
12
|
-
default: obj
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function createModule(file) {
|
|
16
|
-
const source = _fs.default.readFileSync(file, 'utf-8');
|
|
17
|
-
const requires = (0, _detective).default(source);
|
|
18
|
-
return {
|
|
19
|
-
file,
|
|
20
|
-
requires
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
10
|
function getModuleDependencies(entryFile) {
|
|
24
11
|
const rootModule = createModule(entryFile);
|
|
25
12
|
const modules = [
|
|
@@ -30,7 +17,7 @@ function getModuleDependencies(entryFile) {
|
|
|
30
17
|
for (const mdl of modules){
|
|
31
18
|
mdl.requires.filter((dep)=>{
|
|
32
19
|
// Only track local modules, not node_modules
|
|
33
|
-
return dep.startsWith(
|
|
20
|
+
return dep.startsWith("./") || dep.startsWith("../");
|
|
34
21
|
}).forEach((dep)=>{
|
|
35
22
|
try {
|
|
36
23
|
const basedir = _path.default.dirname(mdl.file);
|
|
@@ -46,3 +33,16 @@ function getModuleDependencies(entryFile) {
|
|
|
46
33
|
}
|
|
47
34
|
return modules;
|
|
48
35
|
}
|
|
36
|
+
function _interopRequireDefault(obj) {
|
|
37
|
+
return obj && obj.__esModule ? obj : {
|
|
38
|
+
default: obj
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createModule(file) {
|
|
42
|
+
const source = _fs.default.readFileSync(file, "utf-8");
|
|
43
|
+
const requires = (0, _detective).default(source);
|
|
44
|
+
return {
|
|
45
|
+
file,
|
|
46
|
+
requires
|
|
47
|
+
};
|
|
48
|
+
}
|