tailwindcss 0.0.0-insiders.e2d5f21 → 0.0.0-insiders.e302ef1
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 +244 -3
- package/LICENSE +1 -2
- package/README.md +8 -4
- package/colors.js +2 -1
- package/defaultConfig.js +2 -1
- package/defaultTheme.js +2 -1
- package/lib/cli.js +123 -88
- package/lib/corePlugins.js +288 -360
- package/lib/css/preflight.css +4 -4
- package/lib/featureFlags.js +4 -5
- package/lib/index.js +12 -3
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +14 -1
- package/lib/lib/collapseDuplicateDeclarations.js +52 -1
- package/lib/lib/defaultExtractor.js +44 -0
- package/lib/lib/evaluateTailwindFunctions.js +1 -1
- package/lib/lib/expandApplyAtRules.js +265 -60
- package/lib/lib/expandTailwindAtRules.js +63 -48
- package/lib/lib/generateRules.js +136 -34
- package/lib/lib/normalizeTailwindDirectives.js +10 -2
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +30 -12
- package/lib/lib/setupContextUtils.js +137 -81
- package/lib/lib/setupTrackingContext.js +8 -7
- package/lib/lib/sharedState.js +38 -5
- package/{nesting → lib/postcss-plugins/nesting}/README.md +0 -0
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +10 -2
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +23 -8
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +4 -8
- package/lib/util/dataTypes.js +4 -2
- package/lib/util/defaults.js +6 -0
- package/lib/util/flattenColorPalette.js +1 -3
- package/lib/util/log.js +10 -6
- package/lib/util/normalizeConfig.js +47 -15
- package/lib/util/normalizeScreens.js +6 -5
- package/lib/util/parseBoxShadowValue.js +44 -4
- package/lib/util/pluginUtils.js +6 -13
- package/lib/util/prefixSelector.js +4 -5
- package/lib/util/resolveConfig.js +48 -27
- package/lib/util/resolveConfigPath.js +1 -2
- package/lib/util/toColorValue.js +1 -2
- package/lib/util/toPath.js +6 -1
- package/lib/util/transformThemeValue.js +4 -8
- package/nesting/index.js +2 -12
- package/package.json +28 -33
- package/peers/index.js +3209 -4239
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/src/cli.js +62 -15
- package/src/corePlugins.js +212 -217
- package/src/css/preflight.css +4 -4
- package/src/featureFlags.js +3 -3
- package/src/index.js +14 -6
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +16 -1
- package/src/lib/collapseDuplicateDeclarations.js +66 -1
- package/src/lib/defaultExtractor.js +50 -0
- package/src/lib/evaluateTailwindFunctions.js +1 -1
- package/src/lib/expandApplyAtRules.js +285 -56
- package/src/lib/expandTailwindAtRules.js +75 -37
- package/src/lib/generateRules.js +121 -27
- package/src/lib/normalizeTailwindDirectives.js +7 -1
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/resolveDefaultsAtRules.js +35 -10
- package/src/lib/setupContextUtils.js +127 -45
- package/src/lib/setupTrackingContext.js +8 -7
- package/src/lib/sharedState.js +42 -4
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +12 -2
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +20 -7
- package/src/util/dataTypes.js +7 -5
- package/src/util/defaults.js +6 -0
- package/src/util/log.js +10 -6
- package/src/util/normalizeConfig.js +24 -3
- package/src/util/normalizeScreens.js +6 -3
- package/src/util/parseBoxShadowValue.js +51 -3
- package/src/util/pluginUtils.js +1 -1
- package/src/util/prefixSelector.js +7 -5
- package/src/util/resolveConfig.js +41 -1
- package/src/util/toPath.js +23 -1
- package/stubs/defaultConfig.stub.js +2 -2
- package/lib/lib/setupWatchingContext.js +0 -288
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -311
package/lib/lib/generateRules.js
CHANGED
|
@@ -10,6 +10,7 @@ var _isPlainObject = _interopRequireDefault(require("../util/isPlainObject"));
|
|
|
10
10
|
var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
|
|
11
11
|
var _pluginUtils = require("../util/pluginUtils");
|
|
12
12
|
var _log = _interopRequireDefault(require("../util/log"));
|
|
13
|
+
var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
13
14
|
var _formatVariantSelector = require("../util/formatVariantSelector");
|
|
14
15
|
var _nameClass = require("../util/nameClass");
|
|
15
16
|
var _dataTypes = require("../util/dataTypes");
|
|
@@ -19,6 +20,27 @@ function _interopRequireDefault(obj) {
|
|
|
19
20
|
default: obj
|
|
20
21
|
};
|
|
21
22
|
}
|
|
23
|
+
function _interopRequireWildcard(obj) {
|
|
24
|
+
if (obj && obj.__esModule) {
|
|
25
|
+
return obj;
|
|
26
|
+
} else {
|
|
27
|
+
var newObj = {};
|
|
28
|
+
if (obj != null) {
|
|
29
|
+
for(var key in obj){
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
31
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
32
|
+
if (desc.get || desc.set) {
|
|
33
|
+
Object.defineProperty(newObj, key, desc);
|
|
34
|
+
} else {
|
|
35
|
+
newObj[key] = obj[key];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
newObj.default = obj;
|
|
41
|
+
return newObj;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
22
44
|
let classNameParser = (0, _postcssSelectorParser).default((selectors)=>{
|
|
23
45
|
return selectors.first.filter(({ type })=>type === 'class'
|
|
24
46
|
).pop().value;
|
|
@@ -33,32 +55,32 @@ function getClassNameFromSelector(selector) {
|
|
|
33
55
|
// Example with dynamic classes:
|
|
34
56
|
// ['grid-cols', '[[linename],1fr,auto]']
|
|
35
57
|
// ['grid', 'cols-[[linename],1fr,auto]']
|
|
36
|
-
function* candidatePermutations(candidate
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
function* candidatePermutations(candidate) {
|
|
59
|
+
let lastIndex = Infinity;
|
|
60
|
+
while(lastIndex >= 0){
|
|
61
|
+
let dashIdx;
|
|
62
|
+
if (lastIndex === Infinity && candidate.endsWith(']')) {
|
|
63
|
+
let bracketIdx = candidate.indexOf('[');
|
|
64
|
+
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
65
|
+
// eg. string[]
|
|
66
|
+
dashIdx = [
|
|
67
|
+
'-',
|
|
68
|
+
'/'
|
|
69
|
+
].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
|
|
70
|
+
} else {
|
|
71
|
+
dashIdx = candidate.lastIndexOf('-', lastIndex);
|
|
72
|
+
}
|
|
73
|
+
if (dashIdx < 0) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
let prefix = candidate.slice(0, dashIdx);
|
|
77
|
+
let modifier = candidate.slice(dashIdx + 1);
|
|
78
|
+
yield [
|
|
79
|
+
prefix,
|
|
80
|
+
modifier
|
|
81
|
+
];
|
|
82
|
+
lastIndex = dashIdx - 1;
|
|
54
83
|
}
|
|
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);
|
|
62
84
|
}
|
|
63
85
|
function applyPrefix(matches, context) {
|
|
64
86
|
if (matches.length === 0 || context.tailwindConfig.prefix === '') {
|
|
@@ -72,15 +94,21 @@ function applyPrefix(matches, context) {
|
|
|
72
94
|
match[1].clone()
|
|
73
95
|
]
|
|
74
96
|
});
|
|
97
|
+
let classCandidate = match[1].raws.tailwind.classCandidate;
|
|
75
98
|
container.walkRules((r)=>{
|
|
76
|
-
|
|
99
|
+
// If this is a negative utility with a dash *before* the prefix we
|
|
100
|
+
// have to ensure that the generated selector matches the candidate
|
|
101
|
+
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
102
|
+
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
103
|
+
let shouldPrependNegative = classCandidate.startsWith('-');
|
|
104
|
+
r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
|
|
77
105
|
});
|
|
78
106
|
match[1] = container.nodes[0];
|
|
79
107
|
}
|
|
80
108
|
}
|
|
81
109
|
return matches;
|
|
82
110
|
}
|
|
83
|
-
function applyImportant(matches) {
|
|
111
|
+
function applyImportant(matches, classCandidate) {
|
|
84
112
|
if (matches.length === 0) {
|
|
85
113
|
return matches;
|
|
86
114
|
}
|
|
@@ -93,7 +121,10 @@ function applyImportant(matches) {
|
|
|
93
121
|
});
|
|
94
122
|
container.walkRules((r)=>{
|
|
95
123
|
r.selector = (0, _pluginUtils).updateAllClasses(r.selector, (className)=>{
|
|
96
|
-
|
|
124
|
+
if (className === classCandidate) {
|
|
125
|
+
return `!${className}`;
|
|
126
|
+
}
|
|
127
|
+
return className;
|
|
97
128
|
});
|
|
98
129
|
r.walkDecls((d)=>d.important = true
|
|
99
130
|
);
|
|
@@ -124,6 +155,10 @@ function applyVariant(variant, matches, context) {
|
|
|
124
155
|
let variantFunctionTuples = context.variantMap.get(variant);
|
|
125
156
|
let result = [];
|
|
126
157
|
for (let [meta, rule1] of matches){
|
|
158
|
+
// Don't generate variants for user css
|
|
159
|
+
if (meta.layer === 'user') {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
127
162
|
let container = _postcss.default.root({
|
|
128
163
|
nodes: [
|
|
129
164
|
rule1.clone()
|
|
@@ -213,6 +248,14 @@ function applyVariant(variant, matches, context) {
|
|
|
213
248
|
rule.selector = before;
|
|
214
249
|
});
|
|
215
250
|
}
|
|
251
|
+
// This tracks the originating layer for the variant
|
|
252
|
+
// For example:
|
|
253
|
+
// .sm:underline {} is a variant of something in the utilities layer
|
|
254
|
+
// .sm:container {} is a variant of the container component
|
|
255
|
+
clone.nodes[0].raws.tailwind = {
|
|
256
|
+
...clone.nodes[0].raws.tailwind,
|
|
257
|
+
parentLayer: meta.layer
|
|
258
|
+
};
|
|
216
259
|
var _collectedFormats;
|
|
217
260
|
let withOffset = [
|
|
218
261
|
{
|
|
@@ -229,8 +272,7 @@ function applyVariant(variant, matches, context) {
|
|
|
229
272
|
}
|
|
230
273
|
return [];
|
|
231
274
|
}
|
|
232
|
-
function parseRules(rule, cache, options = {
|
|
233
|
-
}) {
|
|
275
|
+
function parseRules(rule, cache, options = {}) {
|
|
234
276
|
// PostCSS node
|
|
235
277
|
if (!(0, _isPlainObject).default(rule) && !Array.isArray(rule)) {
|
|
236
278
|
return [
|
|
@@ -253,14 +295,55 @@ function parseRules(rule, cache, options = {
|
|
|
253
295
|
options
|
|
254
296
|
];
|
|
255
297
|
}
|
|
298
|
+
const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
|
|
299
|
+
function isValidPropName(name) {
|
|
300
|
+
return IS_VALID_PROPERTY_NAME.test(name);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @param {string} declaration
|
|
304
|
+
* @returns {boolean}
|
|
305
|
+
*/ function looksLikeUri(declaration) {
|
|
306
|
+
// Quick bailout for obvious non-urls
|
|
307
|
+
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
308
|
+
if (!declaration.includes('://')) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
const url = new URL(declaration);
|
|
313
|
+
return url.scheme !== '' && url.host !== '';
|
|
314
|
+
} catch (err) {
|
|
315
|
+
// Definitely not a valid url
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function isParsableCssValue(property, value) {
|
|
320
|
+
// We don't want to to treat [https://example.com] as a custom property
|
|
321
|
+
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
322
|
+
// So we short-circuit here by checking if the custom property looks like a url
|
|
323
|
+
if (looksLikeUri(`${property}:${value}`)) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
_postcss.default.parse(`a{${property}:${value}}`).toResult();
|
|
328
|
+
return true;
|
|
329
|
+
} catch (err) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
256
333
|
function extractArbitraryProperty(classCandidate, context) {
|
|
257
334
|
var ref;
|
|
258
335
|
let [, property, value] = (ref = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && ref !== void 0 ? ref : [];
|
|
259
336
|
if (value === undefined) {
|
|
260
337
|
return null;
|
|
261
338
|
}
|
|
339
|
+
if (!isValidPropName(property)) {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
262
345
|
let normalized = (0, _dataTypes).normalize(value);
|
|
263
|
-
if (!(
|
|
346
|
+
if (!isParsableCssValue(property, normalized)) {
|
|
264
347
|
return null;
|
|
265
348
|
}
|
|
266
349
|
return [
|
|
@@ -313,13 +396,26 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
313
396
|
context.candidateRuleMap.get(prefix),
|
|
314
397
|
negative ? `-${modifier}` : modifier
|
|
315
398
|
];
|
|
316
|
-
return;
|
|
317
399
|
}
|
|
318
400
|
}
|
|
319
401
|
}
|
|
320
402
|
function splitWithSeparator(input, separator) {
|
|
403
|
+
if (input === sharedState.NOT_ON_DEMAND) {
|
|
404
|
+
return [
|
|
405
|
+
sharedState.NOT_ON_DEMAND
|
|
406
|
+
];
|
|
407
|
+
}
|
|
321
408
|
return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'));
|
|
322
409
|
}
|
|
410
|
+
function* recordCandidates(matches, classCandidate) {
|
|
411
|
+
for (const match of matches){
|
|
412
|
+
match[1].raws.tailwind = {
|
|
413
|
+
...match[1].raws.tailwind,
|
|
414
|
+
classCandidate
|
|
415
|
+
};
|
|
416
|
+
yield match;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
323
419
|
function* resolveMatches(candidate, context) {
|
|
324
420
|
let separator = context.tailwindConfig.separator;
|
|
325
421
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
@@ -429,14 +525,20 @@ function* resolveMatches(candidate, context) {
|
|
|
429
525
|
]);
|
|
430
526
|
continue;
|
|
431
527
|
}
|
|
432
|
-
matches =
|
|
528
|
+
matches = matches.flat();
|
|
529
|
+
matches = Array.from(recordCandidates(matches, classCandidate));
|
|
530
|
+
matches = applyPrefix(matches, context);
|
|
433
531
|
if (important) {
|
|
434
|
-
matches = applyImportant(matches,
|
|
532
|
+
matches = applyImportant(matches, classCandidate);
|
|
435
533
|
}
|
|
436
534
|
for (let variant of variants){
|
|
437
535
|
matches = applyVariant(variant, matches, context);
|
|
438
536
|
}
|
|
439
537
|
for (let match1 of matches){
|
|
538
|
+
match1[1].raws.tailwind = {
|
|
539
|
+
...match1[1].raws.tailwind,
|
|
540
|
+
candidate
|
|
541
|
+
};
|
|
440
542
|
// Apply final format selector
|
|
441
543
|
if (match1[0].collectedFormats) {
|
|
442
544
|
let finalFormat = (0, _formatVariantSelector).formatVariantSelector('&', ...match1[0].collectedFormats);
|
|
@@ -12,7 +12,11 @@ function _interopRequireDefault(obj) {
|
|
|
12
12
|
function normalizeTailwindDirectives(root) {
|
|
13
13
|
let tailwindDirectives = new Set();
|
|
14
14
|
let layerDirectives = new Set();
|
|
15
|
+
let applyDirectives = new Set();
|
|
15
16
|
root.walkAtRules((atRule)=>{
|
|
17
|
+
if (atRule.name === 'apply') {
|
|
18
|
+
applyDirectives.add(atRule);
|
|
19
|
+
}
|
|
16
20
|
if (atRule.name === 'import') {
|
|
17
21
|
if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
|
|
18
22
|
atRule.name = 'tailwind';
|
|
@@ -45,7 +49,8 @@ function normalizeTailwindDirectives(root) {
|
|
|
45
49
|
].includes(atRule.name)) {
|
|
46
50
|
_log.default.warn(`${atRule.name}-at-rule-deprecated`, [
|
|
47
51
|
`The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
|
|
48
|
-
`Use \`@layer utilities\` or \`@layer components\` instead.`,
|
|
52
|
+
`Use \`@layer utilities\` or \`@layer components\` instead.`,
|
|
53
|
+
'https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer',
|
|
49
54
|
]);
|
|
50
55
|
}
|
|
51
56
|
layerDirectives.add(atRule);
|
|
@@ -72,5 +77,8 @@ function normalizeTailwindDirectives(root) {
|
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
|
-
return
|
|
80
|
+
return {
|
|
81
|
+
tailwindDirectives,
|
|
82
|
+
applyDirectives
|
|
83
|
+
};
|
|
76
84
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = expandApplyAtRules;
|
|
6
|
+
function partitionRules(root) {
|
|
7
|
+
if (!root.walkAtRules) return;
|
|
8
|
+
let applyParents = new Set();
|
|
9
|
+
root.walkAtRules('apply', (rule)=>{
|
|
10
|
+
applyParents.add(rule.parent);
|
|
11
|
+
});
|
|
12
|
+
if (applyParents.size === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
for (let rule1 of applyParents){
|
|
16
|
+
let nodeGroups = [];
|
|
17
|
+
let lastGroup = [];
|
|
18
|
+
for (let node of rule1.nodes){
|
|
19
|
+
if (node.type === 'atrule' && node.name === 'apply') {
|
|
20
|
+
if (lastGroup.length > 0) {
|
|
21
|
+
nodeGroups.push(lastGroup);
|
|
22
|
+
lastGroup = [];
|
|
23
|
+
}
|
|
24
|
+
nodeGroups.push([
|
|
25
|
+
node
|
|
26
|
+
]);
|
|
27
|
+
} else {
|
|
28
|
+
lastGroup.push(node);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (lastGroup.length > 0) {
|
|
32
|
+
nodeGroups.push(lastGroup);
|
|
33
|
+
}
|
|
34
|
+
if (nodeGroups.length === 1) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
for (let group of [
|
|
38
|
+
...nodeGroups
|
|
39
|
+
].reverse()){
|
|
40
|
+
let clone = rule1.clone({
|
|
41
|
+
nodes: []
|
|
42
|
+
});
|
|
43
|
+
clone.append(group);
|
|
44
|
+
rule1.after(clone);
|
|
45
|
+
}
|
|
46
|
+
rule1.remove();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function expandApplyAtRules() {
|
|
50
|
+
return (root)=>{
|
|
51
|
+
partitionRules(root);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -79,7 +79,7 @@ function extractElementSelector(selector) {
|
|
|
79
79
|
function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
80
80
|
return (root)=>{
|
|
81
81
|
let variableNodeMap = new Map();
|
|
82
|
-
let universals = new Set();
|
|
82
|
+
/** @type {Set<import('postcss').AtRule>} */ let universals = new Set();
|
|
83
83
|
root.walkAtRules('defaults', (rule)=>{
|
|
84
84
|
if (rule.nodes && rule.nodes.length > 0) {
|
|
85
85
|
universals.add(rule);
|
|
@@ -93,32 +93,50 @@ function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
|
93
93
|
rule.remove();
|
|
94
94
|
});
|
|
95
95
|
for (let universal of universals){
|
|
96
|
-
let
|
|
96
|
+
/** @type {Map<string, Set<string>>} */ let selectorGroups = new Map();
|
|
97
97
|
var ref;
|
|
98
98
|
let rules = (ref = variableNodeMap.get(universal.params)) !== null && ref !== void 0 ? ref : [];
|
|
99
99
|
for (let rule of rules){
|
|
100
100
|
for (let selector of extractElementSelector(rule.selector)){
|
|
101
|
+
// If selector contains a vendor prefix after a pseudo element or class,
|
|
102
|
+
// we consider them separately because merging the declarations into
|
|
103
|
+
// a single rule will cause browsers that do not understand the
|
|
104
|
+
// vendor prefix to throw out the whole rule
|
|
105
|
+
let selectorGroupName = selector.includes(':-') || selector.includes('::-') ? selector : '__DEFAULT__';
|
|
106
|
+
var ref1;
|
|
107
|
+
let selectors = (ref1 = selectorGroups.get(selectorGroupName)) !== null && ref1 !== void 0 ? ref1 : new Set();
|
|
108
|
+
selectorGroups.set(selectorGroupName, selectors);
|
|
101
109
|
selectors.add(selector);
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
|
-
if (selectors.size === 0) {
|
|
105
|
-
universal.remove();
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
let universalRule = _postcss.default.rule();
|
|
109
112
|
if ((0, _featureFlags).flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
if (selectorGroups.size === 0) {
|
|
114
|
+
universal.remove();
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
for (let [, selectors] of selectorGroups){
|
|
118
|
+
let universalRule = _postcss.default.rule({
|
|
119
|
+
source: universal.source
|
|
120
|
+
});
|
|
121
|
+
universalRule.selectors = [
|
|
122
|
+
...selectors
|
|
123
|
+
];
|
|
124
|
+
universalRule.append(universal.nodes.map((node)=>node.clone()
|
|
125
|
+
));
|
|
126
|
+
universal.before(universalRule);
|
|
127
|
+
}
|
|
113
128
|
} else {
|
|
129
|
+
let universalRule = _postcss.default.rule({
|
|
130
|
+
source: universal.source
|
|
131
|
+
});
|
|
114
132
|
universalRule.selectors = [
|
|
115
133
|
'*',
|
|
116
134
|
'::before',
|
|
117
135
|
'::after'
|
|
118
136
|
];
|
|
137
|
+
universalRule.append(universal.nodes);
|
|
138
|
+
universal.before(universalRule);
|
|
119
139
|
}
|
|
120
|
-
universalRule.append(universal.nodes);
|
|
121
|
-
universal.before(universalRule);
|
|
122
140
|
universal.remove();
|
|
123
141
|
}
|
|
124
142
|
};
|