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
|
@@ -4,75 +4,70 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
exports.default = normalizeTailwindDirectives;
|
|
6
6
|
var _log = _interopRequireDefault(require("../util/log"));
|
|
7
|
-
function _interopRequireDefault(obj) {
|
|
8
|
-
return obj && obj.__esModule ? obj : {
|
|
9
|
-
default: obj
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
7
|
function normalizeTailwindDirectives(root) {
|
|
13
8
|
let tailwindDirectives = new Set();
|
|
14
9
|
let layerDirectives = new Set();
|
|
15
10
|
let applyDirectives = new Set();
|
|
16
11
|
root.walkAtRules((atRule)=>{
|
|
17
|
-
if (atRule.name ===
|
|
12
|
+
if (atRule.name === "apply") {
|
|
18
13
|
applyDirectives.add(atRule);
|
|
19
14
|
}
|
|
20
|
-
if (atRule.name ===
|
|
15
|
+
if (atRule.name === "import") {
|
|
21
16
|
if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
|
|
22
|
-
atRule.name =
|
|
23
|
-
atRule.params =
|
|
17
|
+
atRule.name = "tailwind";
|
|
18
|
+
atRule.params = "base";
|
|
24
19
|
} else if (atRule.params === '"tailwindcss/components"' || atRule.params === "'tailwindcss/components'") {
|
|
25
|
-
atRule.name =
|
|
26
|
-
atRule.params =
|
|
20
|
+
atRule.name = "tailwind";
|
|
21
|
+
atRule.params = "components";
|
|
27
22
|
} else if (atRule.params === '"tailwindcss/utilities"' || atRule.params === "'tailwindcss/utilities'") {
|
|
28
|
-
atRule.name =
|
|
29
|
-
atRule.params =
|
|
23
|
+
atRule.name = "tailwind";
|
|
24
|
+
atRule.params = "utilities";
|
|
30
25
|
} else if (atRule.params === '"tailwindcss/screens"' || atRule.params === "'tailwindcss/screens'" || atRule.params === '"tailwindcss/variants"' || atRule.params === "'tailwindcss/variants'") {
|
|
31
|
-
atRule.name =
|
|
32
|
-
atRule.params =
|
|
26
|
+
atRule.name = "tailwind";
|
|
27
|
+
atRule.params = "variants";
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
|
-
if (atRule.name ===
|
|
36
|
-
if (atRule.params ===
|
|
37
|
-
atRule.params =
|
|
30
|
+
if (atRule.name === "tailwind") {
|
|
31
|
+
if (atRule.params === "screens") {
|
|
32
|
+
atRule.params = "variants";
|
|
38
33
|
}
|
|
39
34
|
tailwindDirectives.add(atRule.params);
|
|
40
35
|
}
|
|
41
36
|
if ([
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
"layer",
|
|
38
|
+
"responsive",
|
|
39
|
+
"variants"
|
|
45
40
|
].includes(atRule.name)) {
|
|
46
41
|
if ([
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
"responsive",
|
|
43
|
+
"variants"
|
|
49
44
|
].includes(atRule.name)) {
|
|
50
45
|
_log.default.warn(`${atRule.name}-at-rule-deprecated`, [
|
|
51
46
|
`The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
|
|
52
47
|
`Use \`@layer utilities\` or \`@layer components\` instead.`,
|
|
53
|
-
|
|
48
|
+
"https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer",
|
|
54
49
|
]);
|
|
55
50
|
}
|
|
56
51
|
layerDirectives.add(atRule);
|
|
57
52
|
}
|
|
58
53
|
});
|
|
59
|
-
if (!tailwindDirectives.has(
|
|
54
|
+
if (!tailwindDirectives.has("base") || !tailwindDirectives.has("components") || !tailwindDirectives.has("utilities")) {
|
|
60
55
|
for (let rule of layerDirectives){
|
|
61
|
-
if (rule.name ===
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
if (rule.name === "layer" && [
|
|
57
|
+
"base",
|
|
58
|
+
"components",
|
|
59
|
+
"utilities"
|
|
65
60
|
].includes(rule.params)) {
|
|
66
61
|
if (!tailwindDirectives.has(rule.params)) {
|
|
67
62
|
throw rule.error(`\`@layer ${rule.params}\` is used but no matching \`@tailwind ${rule.params}\` directive is present.`);
|
|
68
63
|
}
|
|
69
|
-
} else if (rule.name ===
|
|
70
|
-
if (!tailwindDirectives.has(
|
|
71
|
-
throw rule.error(
|
|
64
|
+
} else if (rule.name === "responsive") {
|
|
65
|
+
if (!tailwindDirectives.has("utilities")) {
|
|
66
|
+
throw rule.error("`@responsive` is used but `@tailwind utilities` is missing.");
|
|
72
67
|
}
|
|
73
|
-
} else if (rule.name ===
|
|
74
|
-
if (!tailwindDirectives.has(
|
|
75
|
-
throw rule.error(
|
|
68
|
+
} else if (rule.name === "variants") {
|
|
69
|
+
if (!tailwindDirectives.has("utilities")) {
|
|
70
|
+
throw rule.error("`@variants` is used but `@tailwind utilities` is missing.");
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
}
|
|
@@ -82,3 +77,8 @@ function normalizeTailwindDirectives(root) {
|
|
|
82
77
|
applyDirectives
|
|
83
78
|
};
|
|
84
79
|
}
|
|
80
|
+
function _interopRequireDefault(obj) {
|
|
81
|
+
return obj && obj.__esModule ? obj : {
|
|
82
|
+
default: obj
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -3,10 +3,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = expandApplyAtRules;
|
|
6
|
+
function expandApplyAtRules() {
|
|
7
|
+
return (root)=>{
|
|
8
|
+
partitionRules(root);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
function partitionRules(root) {
|
|
7
12
|
if (!root.walkAtRules) return;
|
|
8
13
|
let applyParents = new Set();
|
|
9
|
-
root.walkAtRules(
|
|
14
|
+
root.walkAtRules("apply", (rule)=>{
|
|
10
15
|
applyParents.add(rule.parent);
|
|
11
16
|
});
|
|
12
17
|
if (applyParents.size === 0) {
|
|
@@ -16,7 +21,7 @@ function partitionRules(root) {
|
|
|
16
21
|
let nodeGroups = [];
|
|
17
22
|
let lastGroup = [];
|
|
18
23
|
for (let node of rule1.nodes){
|
|
19
|
-
if (node.type ===
|
|
24
|
+
if (node.type === "atrule" && node.name === "apply") {
|
|
20
25
|
if (lastGroup.length > 0) {
|
|
21
26
|
nodeGroups.push(lastGroup);
|
|
22
27
|
lastGroup = [];
|
|
@@ -46,8 +51,3 @@ function partitionRules(root) {
|
|
|
46
51
|
rule1.remove();
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
|
-
function expandApplyAtRules() {
|
|
50
|
-
return (root)=>{
|
|
51
|
-
partitionRules(root);
|
|
52
|
-
};
|
|
53
|
-
}
|
package/lib/lib/regex.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.pattern = pattern;
|
|
6
|
+
exports.withoutCapturing = withoutCapturing;
|
|
7
|
+
exports.any = any;
|
|
8
|
+
exports.optional = optional;
|
|
9
|
+
exports.zeroOrMore = zeroOrMore;
|
|
10
|
+
exports.nestedBrackets = nestedBrackets;
|
|
11
|
+
exports.escape = escape;
|
|
12
|
+
const REGEX_SPECIAL = /[\\^$.*+?()[\]{}|]/g;
|
|
13
|
+
const REGEX_HAS_SPECIAL = RegExp(REGEX_SPECIAL.source);
|
|
14
|
+
/**
|
|
15
|
+
* @param {string|RegExp|Array<string|RegExp>} source
|
|
16
|
+
*/ function toSource(source) {
|
|
17
|
+
source = Array.isArray(source) ? source : [
|
|
18
|
+
source
|
|
19
|
+
];
|
|
20
|
+
source = source.map((item)=>item instanceof RegExp ? item.source : item);
|
|
21
|
+
return source.join("");
|
|
22
|
+
}
|
|
23
|
+
function pattern(source) {
|
|
24
|
+
return new RegExp(toSource(source), "g");
|
|
25
|
+
}
|
|
26
|
+
function withoutCapturing(source) {
|
|
27
|
+
return new RegExp(`(?:${toSource(source)})`, "g");
|
|
28
|
+
}
|
|
29
|
+
function any(sources) {
|
|
30
|
+
return `(?:${sources.map(toSource).join("|")})`;
|
|
31
|
+
}
|
|
32
|
+
function optional(source) {
|
|
33
|
+
return `(?:${toSource(source)})?`;
|
|
34
|
+
}
|
|
35
|
+
function zeroOrMore(source) {
|
|
36
|
+
return `(?:${toSource(source)})*`;
|
|
37
|
+
}
|
|
38
|
+
function nestedBrackets(open, close, depth = 1) {
|
|
39
|
+
return withoutCapturing([
|
|
40
|
+
escape(open),
|
|
41
|
+
/[^\s]*/,
|
|
42
|
+
depth === 1 ? `[^${escape(open)}${escape(close)}\s]*` : any([
|
|
43
|
+
`[^${escape(open)}${escape(close)}\s]*`,
|
|
44
|
+
nestedBrackets(open, close, depth - 1)
|
|
45
|
+
]),
|
|
46
|
+
/[^\s]*/,
|
|
47
|
+
escape(close),
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
function escape(string) {
|
|
51
|
+
return string && REGEX_HAS_SPECIAL.test(string) ? string.replace(REGEX_SPECIAL, "\\$&") : string || "";
|
|
52
|
+
}
|
|
@@ -7,6 +7,85 @@ exports.elementSelectorParser = void 0;
|
|
|
7
7
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
8
8
|
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
9
9
|
var _featureFlags = require("../featureFlags");
|
|
10
|
+
function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
11
|
+
return (root)=>{
|
|
12
|
+
let variableNodeMap = new Map();
|
|
13
|
+
/** @type {Set<import('postcss').AtRule>} */ let universals = new Set();
|
|
14
|
+
root.walkAtRules("defaults", (rule)=>{
|
|
15
|
+
if (rule.nodes && rule.nodes.length > 0) {
|
|
16
|
+
universals.add(rule);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let variable = rule.params;
|
|
20
|
+
if (!variableNodeMap.has(variable)) {
|
|
21
|
+
variableNodeMap.set(variable, new Set());
|
|
22
|
+
}
|
|
23
|
+
variableNodeMap.get(variable).add(rule.parent);
|
|
24
|
+
rule.remove();
|
|
25
|
+
});
|
|
26
|
+
if ((0, _featureFlags).flagEnabled(tailwindConfig, "optimizeUniversalDefaults")) {
|
|
27
|
+
for (let universal of universals){
|
|
28
|
+
/** @type {Map<string, Set<string>>} */ let selectorGroups = new Map();
|
|
29
|
+
var ref;
|
|
30
|
+
let rules = (ref = variableNodeMap.get(universal.params)) !== null && ref !== void 0 ? ref : [];
|
|
31
|
+
for (let rule of rules){
|
|
32
|
+
for (let selector of extractElementSelector(rule.selector)){
|
|
33
|
+
// If selector contains a vendor prefix after a pseudo element or class,
|
|
34
|
+
// we consider them separately because merging the declarations into
|
|
35
|
+
// a single rule will cause browsers that do not understand the
|
|
36
|
+
// vendor prefix to throw out the whole rule
|
|
37
|
+
let selectorGroupName = selector.includes(":-") || selector.includes("::-") ? selector : "__DEFAULT__";
|
|
38
|
+
var ref1;
|
|
39
|
+
let selectors = (ref1 = selectorGroups.get(selectorGroupName)) !== null && ref1 !== void 0 ? ref1 : new Set();
|
|
40
|
+
selectorGroups.set(selectorGroupName, selectors);
|
|
41
|
+
selectors.add(selector);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if ((0, _featureFlags).flagEnabled(tailwindConfig, "optimizeUniversalDefaults")) {
|
|
45
|
+
if (selectorGroups.size === 0) {
|
|
46
|
+
universal.remove();
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
for (let [, selectors] of selectorGroups){
|
|
50
|
+
let universalRule = _postcss.default.rule({
|
|
51
|
+
source: universal.source
|
|
52
|
+
});
|
|
53
|
+
universalRule.selectors = [
|
|
54
|
+
...selectors
|
|
55
|
+
];
|
|
56
|
+
universalRule.append(universal.nodes.map((node)=>node.clone()));
|
|
57
|
+
universal.before(universalRule);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
universal.remove();
|
|
61
|
+
}
|
|
62
|
+
} else if (universals.size) {
|
|
63
|
+
let universalRule = _postcss.default.rule({
|
|
64
|
+
selectors: [
|
|
65
|
+
"*",
|
|
66
|
+
"::before",
|
|
67
|
+
"::after"
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
for (let universal of universals){
|
|
71
|
+
universalRule.append(universal.nodes);
|
|
72
|
+
if (!universalRule.parent) {
|
|
73
|
+
universal.before(universalRule);
|
|
74
|
+
}
|
|
75
|
+
if (!universalRule.source) {
|
|
76
|
+
universalRule.source = universal.source;
|
|
77
|
+
}
|
|
78
|
+
universal.remove();
|
|
79
|
+
}
|
|
80
|
+
let backdropRule = universalRule.clone({
|
|
81
|
+
selectors: [
|
|
82
|
+
"::backdrop"
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
universalRule.after(backdropRule);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
10
89
|
function _interopRequireDefault(obj) {
|
|
11
90
|
return obj && obj.__esModule ? obj : {
|
|
12
91
|
default: obj
|
|
@@ -15,8 +94,8 @@ function _interopRequireDefault(obj) {
|
|
|
15
94
|
let getNode = {
|
|
16
95
|
id (node) {
|
|
17
96
|
return _postcssSelectorParser.default.attribute({
|
|
18
|
-
attribute:
|
|
19
|
-
operator:
|
|
97
|
+
attribute: "id",
|
|
98
|
+
operator: "=",
|
|
20
99
|
value: node.value,
|
|
21
100
|
quoteMark: '"'
|
|
22
101
|
});
|
|
@@ -25,33 +104,31 @@ let getNode = {
|
|
|
25
104
|
function minimumImpactSelector(nodes) {
|
|
26
105
|
let rest = nodes.filter((node)=>{
|
|
27
106
|
// Keep non-pseudo nodes
|
|
28
|
-
if (node.type !==
|
|
107
|
+
if (node.type !== "pseudo") return true;
|
|
29
108
|
// Keep pseudo nodes that have subnodes
|
|
30
109
|
// E.g.: `:not()` contains subnodes inside the parentheses
|
|
31
110
|
if (node.nodes.length > 0) return true;
|
|
32
111
|
// Keep pseudo `elements`
|
|
33
112
|
// This implicitly means that we ignore pseudo `classes`
|
|
34
|
-
return node.value.startsWith(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
113
|
+
return node.value.startsWith("::") || [
|
|
114
|
+
":before",
|
|
115
|
+
":after",
|
|
116
|
+
":first-line",
|
|
117
|
+
":first-letter"
|
|
39
118
|
].includes(node.value);
|
|
40
119
|
}).reverse();
|
|
41
120
|
let searchFor = new Set([
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
121
|
+
"tag",
|
|
122
|
+
"class",
|
|
123
|
+
"id",
|
|
124
|
+
"attribute"
|
|
46
125
|
]);
|
|
47
|
-
let splitPointIdx = rest.findIndex((n)=>searchFor.has(n.type)
|
|
48
|
-
);
|
|
49
|
-
if (splitPointIdx === -1) return rest.reverse().join('').trim();
|
|
126
|
+
let splitPointIdx = rest.findIndex((n)=>searchFor.has(n.type));
|
|
127
|
+
if (splitPointIdx === -1) return rest.reverse().join("").trim();
|
|
50
128
|
let node1 = rest[splitPointIdx];
|
|
51
129
|
let bestNode = getNode[node1.type] ? getNode[node1.type](node1) : node1;
|
|
52
130
|
rest = rest.slice(0, splitPointIdx);
|
|
53
|
-
let combinatorIdx = rest.findIndex((n)=>n.type ===
|
|
54
|
-
);
|
|
131
|
+
let combinatorIdx = rest.findIndex((n)=>n.type === "combinator" && n.value === ">");
|
|
55
132
|
if (combinatorIdx !== -1) {
|
|
56
133
|
rest.splice(0, combinatorIdx);
|
|
57
134
|
rest.unshift(_postcssSelectorParser.default.universal());
|
|
@@ -59,12 +136,11 @@ function minimumImpactSelector(nodes) {
|
|
|
59
136
|
return [
|
|
60
137
|
bestNode,
|
|
61
138
|
...rest.reverse()
|
|
62
|
-
].join(
|
|
139
|
+
].join("").trim();
|
|
63
140
|
}
|
|
64
141
|
let elementSelectorParser = (0, _postcssSelectorParser).default((selectors)=>{
|
|
65
142
|
return selectors.map((s)=>{
|
|
66
|
-
let nodes = s.split((n)=>n.type ===
|
|
67
|
-
).pop();
|
|
143
|
+
let nodes = s.split((n)=>n.type === "combinator" && n.value === " ").pop();
|
|
68
144
|
return minimumImpactSelector(nodes);
|
|
69
145
|
});
|
|
70
146
|
});
|
|
@@ -76,64 +152,3 @@ function extractElementSelector(selector) {
|
|
|
76
152
|
}
|
|
77
153
|
return cache.get(selector);
|
|
78
154
|
}
|
|
79
|
-
function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
80
|
-
return (root)=>{
|
|
81
|
-
let variableNodeMap = new Map();
|
|
82
|
-
/** @type {Set<import('postcss').AtRule>} */ let universals = new Set();
|
|
83
|
-
root.walkAtRules('defaults', (rule)=>{
|
|
84
|
-
if (rule.nodes && rule.nodes.length > 0) {
|
|
85
|
-
universals.add(rule);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
let variable = rule.params;
|
|
89
|
-
if (!variableNodeMap.has(variable)) {
|
|
90
|
-
variableNodeMap.set(variable, new Set());
|
|
91
|
-
}
|
|
92
|
-
variableNodeMap.get(variable).add(rule.parent);
|
|
93
|
-
rule.remove();
|
|
94
|
-
});
|
|
95
|
-
for (let universal of universals){
|
|
96
|
-
/** @type {Map<string, Set<string>>} */ let selectorGroups = new Map();
|
|
97
|
-
var ref;
|
|
98
|
-
let rules = (ref = variableNodeMap.get(universal.params)) !== null && ref !== void 0 ? ref : [];
|
|
99
|
-
for (let rule of rules){
|
|
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);
|
|
109
|
-
selectors.add(selector);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if ((0, _featureFlags).flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
|
|
113
|
-
if (selectorGroups.size === 0) {
|
|
114
|
-
universal.remove();
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
for (let [, selectors] of selectorGroups){
|
|
118
|
-
let universalRule = _postcss.default.rule();
|
|
119
|
-
universalRule.selectors = [
|
|
120
|
-
...selectors
|
|
121
|
-
];
|
|
122
|
-
universalRule.append(universal.nodes.map((node)=>node.clone()
|
|
123
|
-
));
|
|
124
|
-
universal.before(universalRule);
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
let universalRule = _postcss.default.rule();
|
|
128
|
-
universalRule.selectors = [
|
|
129
|
-
'*',
|
|
130
|
-
'::before',
|
|
131
|
-
'::after'
|
|
132
|
-
];
|
|
133
|
-
universalRule.append(universal.nodes);
|
|
134
|
-
universal.before(universalRule);
|
|
135
|
-
}
|
|
136
|
-
universal.remove();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|