tailwindcss 0.0.0-insiders.ea80db2 → 0.0.0-insiders.eae2b7a
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/README.md +13 -9
- package/defaultTheme.d.ts +2 -1
- package/index.css +5 -0
- package/lib/cli/build/index.js +57 -0
- package/lib/cli/build/plugin.js +427 -0
- package/lib/cli/build/utils.js +88 -0
- package/lib/cli/build/watching.js +182 -0
- package/lib/cli/help/index.js +73 -0
- package/lib/cli/index.js +231 -0
- package/lib/cli/init/index.js +63 -0
- package/lib/cli.js +1 -759
- package/lib/corePluginList.js +12 -3
- package/lib/corePlugins.js +2308 -1739
- package/lib/css/preflight.css +13 -5
- package/lib/featureFlags.js +50 -25
- package/lib/index.js +1 -40
- package/lib/lib/cacheInvalidation.js +48 -25
- package/lib/lib/collapseAdjacentRules.js +17 -10
- package/lib/lib/collapseDuplicateDeclarations.js +13 -8
- package/lib/lib/content.js +207 -0
- package/lib/lib/defaultExtractor.js +232 -33
- package/lib/lib/detectNesting.js +21 -10
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +316 -215
- package/lib/lib/expandTailwindAtRules.js +167 -115
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +444 -211
- package/lib/lib/getModuleDependencies.js +88 -37
- package/lib/lib/handleImportAtRules.js +50 -0
- package/lib/lib/load-config.js +42 -0
- package/lib/lib/normalizeTailwindDirectives.js +29 -39
- package/lib/lib/offsets.js +306 -0
- package/lib/lib/partitionApplyAtRules.js +13 -8
- package/lib/lib/regex.js +74 -0
- package/lib/lib/remap-bitfield.js +89 -0
- package/lib/lib/resolveDefaultsAtRules.js +96 -74
- package/lib/lib/setupContextUtils.js +672 -300
- package/lib/lib/setupTrackingContext.js +63 -68
- package/lib/lib/sharedState.js +44 -17
- package/lib/lib/substituteScreenAtRules.js +14 -10
- package/lib/plugin.js +160 -0
- package/lib/postcss-plugins/nesting/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +10 -6
- package/lib/postcss-plugins/nesting/plugin.js +24 -20
- package/lib/processTailwindFeatures.js +34 -29
- package/lib/public/colors.js +272 -246
- package/lib/public/create-plugin.js +9 -5
- package/lib/public/default-config.js +10 -6
- package/lib/public/default-theme.js +10 -6
- package/lib/public/load-config.js +12 -0
- package/lib/public/resolve-config.js +11 -6
- package/lib/util/applyImportantSelector.js +36 -0
- package/lib/util/bigSign.js +6 -1
- package/lib/util/buildMediaQuery.js +13 -6
- package/lib/util/cloneDeep.js +9 -6
- package/lib/util/cloneNodes.js +12 -3
- package/lib/util/color.js +66 -50
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +7 -2
- package/lib/util/createPlugin.js +8 -5
- package/lib/util/createUtilityPlugin.js +13 -9
- package/lib/util/dataTypes.js +182 -111
- package/lib/util/defaults.js +12 -7
- package/lib/util/escapeClassName.js +13 -8
- package/lib/util/escapeCommas.js +7 -2
- package/lib/util/flattenColorPalette.js +11 -10
- package/lib/util/formatVariantSelector.js +228 -151
- package/lib/util/getAllConfigs.js +33 -12
- package/lib/util/hashConfig.js +9 -4
- package/lib/util/isKeyframeRule.js +7 -2
- package/lib/util/isPlainObject.js +7 -2
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
- package/lib/util/log.js +40 -13
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +155 -87
- package/lib/util/normalizeScreens.js +127 -8
- package/lib/util/parseAnimationValue.js +44 -40
- package/lib/util/parseBoxShadowValue.js +33 -62
- package/lib/util/parseDependency.js +39 -55
- package/lib/util/parseGlob.js +36 -0
- package/lib/util/parseObjectStyles.js +15 -10
- package/lib/util/pluginUtils.js +154 -59
- package/lib/util/prefixSelector.js +29 -10
- package/lib/util/pseudoElements.js +209 -0
- package/lib/util/removeAlphaVariables.js +31 -0
- package/lib/util/resolveConfig.js +96 -95
- package/lib/util/resolveConfigPath.js +29 -10
- package/lib/util/responsive.js +11 -6
- package/lib/util/splitAtTopLevelOnly.js +51 -0
- package/lib/util/tap.js +6 -1
- package/lib/util/toColorValue.js +7 -2
- package/lib/util/toPath.js +22 -4
- package/lib/util/transformThemeValue.js +40 -26
- package/lib/util/validateConfig.js +48 -0
- package/lib/util/validateFormalSyntax.js +26 -0
- package/lib/util/withAlphaVariable.js +27 -15
- package/lib/value-parser/LICENSE +22 -0
- package/lib/value-parser/README.md +3 -0
- package/lib/value-parser/index.d.js +2 -0
- package/lib/value-parser/index.js +22 -0
- package/lib/value-parser/parse.js +259 -0
- package/lib/value-parser/stringify.js +38 -0
- package/lib/value-parser/unit.js +86 -0
- package/lib/value-parser/walk.js +16 -0
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/package.json +54 -52
- package/plugin.d.ts +10 -5
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +53 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/index.js +53 -0
- package/src/cli/build/plugin.js +465 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +229 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +217 -0
- package/src/cli/init/index.js +79 -0
- package/src/cli.js +1 -836
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +576 -106
- package/src/css/preflight.css +13 -5
- package/src/featureFlags.js +17 -3
- package/src/index.js +1 -42
- package/src/lib/collapseAdjacentRules.js +5 -1
- package/src/lib/content.js +240 -0
- package/src/lib/defaultExtractor.js +202 -35
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +82 -8
- package/src/lib/expandApplyAtRules.js +322 -189
- package/src/lib/expandTailwindAtRules.js +82 -59
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +413 -132
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/handleImportAtRules.js +34 -0
- package/src/lib/load-config.ts +31 -0
- package/src/lib/normalizeTailwindDirectives.js +0 -27
- package/src/lib/offsets.js +373 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -36
- package/src/lib/setupContextUtils.js +570 -151
- package/src/lib/setupTrackingContext.js +44 -58
- package/src/lib/sharedState.js +13 -4
- package/src/plugin.js +128 -0
- package/src/postcss-plugins/nesting/README.md +2 -2
- package/src/public/colors.js +22 -0
- package/src/public/default-config.js +1 -1
- package/src/public/default-theme.js +2 -2
- package/src/public/load-config.js +2 -0
- package/src/util/applyImportantSelector.js +27 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +5 -1
- package/src/util/color.js +34 -17
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +67 -23
- package/src/util/formatVariantSelector.js +264 -144
- package/src/util/getAllConfigs.js +21 -2
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +25 -1
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +78 -20
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +118 -23
- package/src/util/prefixSelector.js +28 -10
- package/src/util/pseudoElements.js +167 -0
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -62
- package/src/util/resolveConfigPath.js +12 -1
- package/src/util/splitAtTopLevelOnly.js +52 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +36 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/src/value-parser/LICENSE +22 -0
- package/src/value-parser/README.md +3 -0
- package/src/value-parser/index.d.ts +177 -0
- package/src/value-parser/index.js +28 -0
- package/src/value-parser/parse.js +303 -0
- package/src/value-parser/stringify.js +41 -0
- package/src/value-parser/unit.js +118 -0
- package/src/value-parser/walk.js +18 -0
- package/stubs/.gitignore +1 -0
- package/stubs/.prettierrc.json +6 -0
- package/stubs/{defaultConfig.stub.js → config.full.js} +215 -165
- package/stubs/{simpleConfig.stub.js → config.simple.js} +1 -1
- package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -1
- package/stubs/postcss.config.js +5 -0
- package/stubs/tailwind.config.cjs +2 -0
- package/stubs/tailwind.config.js +2 -0
- package/stubs/tailwind.config.ts +3 -0
- package/types/config.d.ts +102 -56
- package/types/generated/colors.d.ts +22 -0
- package/types/generated/corePluginList.d.ts +1 -1
- package/types/generated/default-theme.d.ts +372 -0
- package/types/index.d.ts +7 -1
- package/CHANGELOG.md +0 -2099
- package/lib/cli-peer-dependencies.js +0 -15
- package/lib/constants.js +0 -37
- package/peers/index.js +0 -75156
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/cli-peer-dependencies.js +0 -9
- package/src/constants.js +0 -17
- package/types.d.ts +0 -1
package/lib/lib/generateRules.js
CHANGED
|
@@ -2,48 +2,85 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getClassNameFromSelector: function() {
|
|
13
|
+
return getClassNameFromSelector;
|
|
14
|
+
},
|
|
15
|
+
resolveMatches: function() {
|
|
16
|
+
return resolveMatches;
|
|
17
|
+
},
|
|
18
|
+
generateRules: function() {
|
|
19
|
+
return generateRules;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
|
|
23
|
+
const _postcssselectorparser = /*#__PURE__*/ _interop_require_default(require("postcss-selector-parser"));
|
|
24
|
+
const _parseObjectStyles = /*#__PURE__*/ _interop_require_default(require("../util/parseObjectStyles"));
|
|
25
|
+
const _isPlainObject = /*#__PURE__*/ _interop_require_default(require("../util/isPlainObject"));
|
|
26
|
+
const _prefixSelector = /*#__PURE__*/ _interop_require_default(require("../util/prefixSelector"));
|
|
27
|
+
const _pluginUtils = require("../util/pluginUtils");
|
|
28
|
+
const _log = /*#__PURE__*/ _interop_require_default(require("../util/log"));
|
|
29
|
+
const _sharedState = /*#__PURE__*/ _interop_require_wildcard(require("./sharedState"));
|
|
30
|
+
const _formatVariantSelector = require("../util/formatVariantSelector");
|
|
31
|
+
const _nameClass = require("../util/nameClass");
|
|
32
|
+
const _dataTypes = require("../util/dataTypes");
|
|
33
|
+
const _setupContextUtils = require("./setupContextUtils");
|
|
34
|
+
const _isSyntacticallyValidPropertyValue = /*#__PURE__*/ _interop_require_default(require("../util/isSyntacticallyValidPropertyValue"));
|
|
35
|
+
const _splitAtTopLevelOnly = require("../util/splitAtTopLevelOnly.js");
|
|
36
|
+
const _featureFlags = require("../featureFlags");
|
|
37
|
+
const _applyImportantSelector = require("../util/applyImportantSelector");
|
|
38
|
+
function _interop_require_default(obj) {
|
|
19
39
|
return obj && obj.__esModule ? obj : {
|
|
20
40
|
default: obj
|
|
21
41
|
};
|
|
22
42
|
}
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
43
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
44
|
+
if (typeof WeakMap !== "function") return null;
|
|
45
|
+
var cacheBabelInterop = new WeakMap();
|
|
46
|
+
var cacheNodeInterop = new WeakMap();
|
|
47
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
48
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
49
|
+
})(nodeInterop);
|
|
50
|
+
}
|
|
51
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
52
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
53
|
return obj;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
}
|
|
55
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
56
|
+
return {
|
|
57
|
+
default: obj
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
61
|
+
if (cache && cache.has(obj)) {
|
|
62
|
+
return cache.get(obj);
|
|
63
|
+
}
|
|
64
|
+
var newObj = {};
|
|
65
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
66
|
+
for(var key in obj){
|
|
67
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
68
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
69
|
+
if (desc && (desc.get || desc.set)) {
|
|
70
|
+
Object.defineProperty(newObj, key, desc);
|
|
71
|
+
} else {
|
|
72
|
+
newObj[key] = obj[key];
|
|
38
73
|
}
|
|
39
74
|
}
|
|
40
|
-
newObj.default = obj;
|
|
41
|
-
return newObj;
|
|
42
75
|
}
|
|
76
|
+
newObj.default = obj;
|
|
77
|
+
if (cache) {
|
|
78
|
+
cache.set(obj, newObj);
|
|
79
|
+
}
|
|
80
|
+
return newObj;
|
|
43
81
|
}
|
|
44
|
-
let classNameParser = (0,
|
|
45
|
-
return selectors.first.filter(({ type })=>type ===
|
|
46
|
-
).pop().value;
|
|
82
|
+
let classNameParser = (0, _postcssselectorparser.default)((selectors)=>{
|
|
83
|
+
return selectors.first.filter(({ type })=>type === "class").pop().value;
|
|
47
84
|
});
|
|
48
85
|
function getClassNameFromSelector(selector) {
|
|
49
86
|
return classNameParser.transformSync(selector);
|
|
@@ -59,31 +96,43 @@ function* candidatePermutations(candidate) {
|
|
|
59
96
|
let lastIndex = Infinity;
|
|
60
97
|
while(lastIndex >= 0){
|
|
61
98
|
let dashIdx;
|
|
62
|
-
|
|
63
|
-
|
|
99
|
+
let wasSlash = false;
|
|
100
|
+
if (lastIndex === Infinity && candidate.endsWith("]")) {
|
|
101
|
+
let bracketIdx = candidate.indexOf("[");
|
|
64
102
|
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
103
|
+
// e.g. string[]
|
|
104
|
+
if (candidate[bracketIdx - 1] === "-") {
|
|
105
|
+
dashIdx = bracketIdx - 1;
|
|
106
|
+
} else if (candidate[bracketIdx - 1] === "/") {
|
|
107
|
+
dashIdx = bracketIdx - 1;
|
|
108
|
+
wasSlash = true;
|
|
109
|
+
} else {
|
|
110
|
+
dashIdx = -1;
|
|
111
|
+
}
|
|
112
|
+
} else if (lastIndex === Infinity && candidate.includes("/")) {
|
|
113
|
+
dashIdx = candidate.lastIndexOf("/");
|
|
114
|
+
wasSlash = true;
|
|
70
115
|
} else {
|
|
71
|
-
dashIdx = candidate.lastIndexOf(
|
|
116
|
+
dashIdx = candidate.lastIndexOf("-", lastIndex);
|
|
72
117
|
}
|
|
73
118
|
if (dashIdx < 0) {
|
|
74
119
|
break;
|
|
75
120
|
}
|
|
76
121
|
let prefix = candidate.slice(0, dashIdx);
|
|
77
|
-
let modifier = candidate.slice(dashIdx + 1);
|
|
122
|
+
let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1);
|
|
123
|
+
lastIndex = dashIdx - 1;
|
|
124
|
+
// TODO: This feels a bit hacky
|
|
125
|
+
if (prefix === "" || modifier === "/") {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
78
128
|
yield [
|
|
79
129
|
prefix,
|
|
80
130
|
modifier
|
|
81
131
|
];
|
|
82
|
-
lastIndex = dashIdx - 1;
|
|
83
132
|
}
|
|
84
133
|
}
|
|
85
134
|
function applyPrefix(matches, context) {
|
|
86
|
-
if (matches.length === 0 || context.tailwindConfig.prefix ===
|
|
135
|
+
if (matches.length === 0 || context.tailwindConfig.prefix === "") {
|
|
87
136
|
return matches;
|
|
88
137
|
}
|
|
89
138
|
for (let match of matches){
|
|
@@ -100,8 +149,8 @@ function applyPrefix(matches, context) {
|
|
|
100
149
|
// have to ensure that the generated selector matches the candidate
|
|
101
150
|
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
102
151
|
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
103
|
-
let shouldPrependNegative = classCandidate.startsWith(
|
|
104
|
-
r.selector = (0, _prefixSelector
|
|
152
|
+
let shouldPrependNegative = classCandidate.startsWith("-");
|
|
153
|
+
r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
|
|
105
154
|
});
|
|
106
155
|
match[1] = container.nodes[0];
|
|
107
156
|
}
|
|
@@ -120,14 +169,13 @@ function applyImportant(matches, classCandidate) {
|
|
|
120
169
|
]
|
|
121
170
|
});
|
|
122
171
|
container.walkRules((r)=>{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
r.walkDecls((d)=>d.important = true
|
|
130
|
-
);
|
|
172
|
+
let ast = (0, _postcssselectorparser.default)().astSync(r.selector);
|
|
173
|
+
// Remove extraneous selectors that do not include the base candidate
|
|
174
|
+
ast.each((sel)=>(0, _formatVariantSelector.eliminateIrrelevantSelectors)(sel, classCandidate));
|
|
175
|
+
// Update all instances of the base candidate to include the important marker
|
|
176
|
+
(0, _pluginUtils.updateAllClasses)(ast, (className)=>className === classCandidate ? `!${className}` : className);
|
|
177
|
+
r.selector = ast.toString();
|
|
178
|
+
r.walkDecls((d)=>d.important = true);
|
|
131
179
|
});
|
|
132
180
|
result.push([
|
|
133
181
|
{
|
|
@@ -151,32 +199,91 @@ function applyVariant(variant, matches, context) {
|
|
|
151
199
|
if (matches.length === 0) {
|
|
152
200
|
return matches;
|
|
153
201
|
}
|
|
202
|
+
/** @type {{modifier: string | null, value: string | null}} */ let args = {
|
|
203
|
+
modifier: null,
|
|
204
|
+
value: _sharedState.NONE
|
|
205
|
+
};
|
|
206
|
+
// Retrieve "modifier"
|
|
207
|
+
{
|
|
208
|
+
let [baseVariant, ...modifiers] = (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(variant, "/");
|
|
209
|
+
// This is a hack to support variants with `/` in them, like `ar-1/10/20:text-red-500`
|
|
210
|
+
// In this case 1/10 is a value but /20 is a modifier
|
|
211
|
+
if (modifiers.length > 1) {
|
|
212
|
+
baseVariant = baseVariant + "/" + modifiers.slice(0, -1).join("/");
|
|
213
|
+
modifiers = modifiers.slice(-1);
|
|
214
|
+
}
|
|
215
|
+
if (modifiers.length && !context.variantMap.has(variant)) {
|
|
216
|
+
variant = baseVariant;
|
|
217
|
+
args.modifier = modifiers[0];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Retrieve "arbitrary value"
|
|
221
|
+
if (variant.endsWith("]") && !variant.startsWith("[")) {
|
|
222
|
+
// We either have:
|
|
223
|
+
// @[200px]
|
|
224
|
+
// group-[:hover]
|
|
225
|
+
//
|
|
226
|
+
// But we don't want:
|
|
227
|
+
// @-[200px] (`-` is incorrect)
|
|
228
|
+
// group[:hover] (`-` is missing)
|
|
229
|
+
let match = /(.)(-?)\[(.*)\]/g.exec(variant);
|
|
230
|
+
if (match) {
|
|
231
|
+
let [, char, separator, value] = match;
|
|
232
|
+
// @-[200px] case
|
|
233
|
+
if (char === "@" && separator === "-") return [];
|
|
234
|
+
// group[:hover] case
|
|
235
|
+
if (char !== "@" && separator === "") return [];
|
|
236
|
+
variant = variant.replace(`${separator}[${value}]`, "");
|
|
237
|
+
args.value = value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Register arbitrary variants
|
|
241
|
+
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
|
|
242
|
+
let sort = context.offsets.recordVariant(variant);
|
|
243
|
+
let selector = (0, _dataTypes.normalize)(variant.slice(1, -1));
|
|
244
|
+
let selectors = (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(selector, ",");
|
|
245
|
+
// We do not support multiple selectors for arbitrary variants
|
|
246
|
+
if (selectors.length > 1) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
if (!selectors.every(_setupContextUtils.isValidVariantFormatString)) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
let records = selectors.map((sel, idx)=>[
|
|
253
|
+
context.offsets.applyParallelOffset(sort, idx),
|
|
254
|
+
(0, _setupContextUtils.parseVariant)(sel.trim())
|
|
255
|
+
]);
|
|
256
|
+
context.variantMap.set(variant, records);
|
|
257
|
+
}
|
|
154
258
|
if (context.variantMap.has(variant)) {
|
|
155
|
-
let
|
|
259
|
+
let isArbitraryVariant = isArbitraryValue(variant);
|
|
260
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice();
|
|
156
261
|
let result = [];
|
|
157
|
-
for (let [meta,
|
|
262
|
+
for (let [meta, rule] of matches){
|
|
158
263
|
// Don't generate variants for user css
|
|
159
|
-
if (meta.layer ===
|
|
264
|
+
if (meta.layer === "user") {
|
|
160
265
|
continue;
|
|
161
266
|
}
|
|
162
267
|
let container = _postcss.default.root({
|
|
163
268
|
nodes: [
|
|
164
|
-
|
|
269
|
+
rule.clone()
|
|
165
270
|
]
|
|
166
271
|
});
|
|
167
|
-
for (let [variantSort, variantFunction] of variantFunctionTuples){
|
|
168
|
-
let clone = container.clone();
|
|
272
|
+
for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples){
|
|
273
|
+
let clone = (containerFromArray !== null && containerFromArray !== void 0 ? containerFromArray : container).clone();
|
|
169
274
|
let collectedFormats = [];
|
|
170
|
-
let originals = new Map();
|
|
171
275
|
function prepareBackup() {
|
|
172
|
-
|
|
173
|
-
clone.
|
|
174
|
-
|
|
276
|
+
// Already prepared, chicken out
|
|
277
|
+
if (clone.raws.neededBackup) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
clone.raws.neededBackup = true;
|
|
281
|
+
clone.walkRules((rule)=>rule.raws.originalSelector = rule.selector);
|
|
175
282
|
}
|
|
176
283
|
function modifySelectors(modifierFunction) {
|
|
177
284
|
prepareBackup();
|
|
178
285
|
clone.each((rule)=>{
|
|
179
|
-
if (rule.type !==
|
|
286
|
+
if (rule.type !== "rule") {
|
|
180
287
|
return;
|
|
181
288
|
}
|
|
182
289
|
rule.selectors = rule.selectors.map((selector)=>{
|
|
@@ -206,29 +313,56 @@ function applyVariant(variant, matches, context) {
|
|
|
206
313
|
clone.append(wrapper);
|
|
207
314
|
},
|
|
208
315
|
format (selectorFormat) {
|
|
209
|
-
collectedFormats.push(
|
|
210
|
-
|
|
316
|
+
collectedFormats.push({
|
|
317
|
+
format: selectorFormat,
|
|
318
|
+
isArbitraryVariant
|
|
319
|
+
});
|
|
320
|
+
},
|
|
321
|
+
args
|
|
211
322
|
});
|
|
212
|
-
|
|
213
|
-
|
|
323
|
+
// It can happen that a list of format strings is returned from within the function. In that
|
|
324
|
+
// case, we have to process them as well. We can use the existing `variantSort`.
|
|
325
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
326
|
+
for (let [idx, variantFunction] of ruleWithVariant.entries()){
|
|
327
|
+
// This is a little bit scary since we are pushing to an array of items that we are
|
|
328
|
+
// currently looping over. However, you can also think of it like a processing queue
|
|
329
|
+
// where you keep handling jobs until everything is done and each job can queue more
|
|
330
|
+
// jobs if needed.
|
|
331
|
+
variantFunctionTuples.push([
|
|
332
|
+
context.offsets.applyParallelOffset(variantSort, idx),
|
|
333
|
+
variantFunction,
|
|
334
|
+
// If the clone has been modified we have to pass that back
|
|
335
|
+
// though so each rule can use the modified container
|
|
336
|
+
clone.clone()
|
|
337
|
+
]);
|
|
338
|
+
}
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (typeof ruleWithVariant === "string") {
|
|
342
|
+
collectedFormats.push({
|
|
343
|
+
format: ruleWithVariant,
|
|
344
|
+
isArbitraryVariant
|
|
345
|
+
});
|
|
214
346
|
}
|
|
215
347
|
if (ruleWithVariant === null) {
|
|
216
348
|
continue;
|
|
217
349
|
}
|
|
218
|
-
// We
|
|
350
|
+
// We had to backup selectors, therefore we assume that somebody touched
|
|
219
351
|
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
220
352
|
// can restore the selectors, and collect the format strings.
|
|
221
|
-
if (
|
|
353
|
+
if (clone.raws.neededBackup) {
|
|
354
|
+
delete clone.raws.neededBackup;
|
|
222
355
|
clone.walkRules((rule)=>{
|
|
223
|
-
|
|
224
|
-
|
|
356
|
+
let before = rule.raws.originalSelector;
|
|
357
|
+
if (!before) return;
|
|
358
|
+
delete rule.raws.originalSelector;
|
|
225
359
|
if (before === rule.selector) return; // No mutation happened
|
|
226
360
|
let modified = rule.selector;
|
|
227
361
|
// Rebuild the base selector, this is what plugin authors would do
|
|
228
362
|
// as well. E.g.: `${variant}${separator}${className}`.
|
|
229
363
|
// However, plugin authors probably also prepend or append certain
|
|
230
364
|
// classes, pseudos, ids, ...
|
|
231
|
-
let rebuiltBase = (0,
|
|
365
|
+
let rebuiltBase = (0, _postcssselectorparser.default)((selectors)=>{
|
|
232
366
|
selectors.walkClasses((classNode)=>{
|
|
233
367
|
classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
|
|
234
368
|
});
|
|
@@ -244,7 +378,10 @@ function applyVariant(variant, matches, context) {
|
|
|
244
378
|
// modified (by plugin): .foo .foo\\:markdown > p
|
|
245
379
|
// rebuiltBase (internal): .foo\\:markdown > p
|
|
246
380
|
// format: .foo &
|
|
247
|
-
collectedFormats.push(
|
|
381
|
+
collectedFormats.push({
|
|
382
|
+
format: modified.replace(rebuiltBase, "&"),
|
|
383
|
+
isArbitraryVariant
|
|
384
|
+
});
|
|
248
385
|
rule.selector = before;
|
|
249
386
|
});
|
|
250
387
|
}
|
|
@@ -256,14 +393,14 @@ function applyVariant(variant, matches, context) {
|
|
|
256
393
|
...clone.nodes[0].raws.tailwind,
|
|
257
394
|
parentLayer: meta.layer
|
|
258
395
|
};
|
|
259
|
-
var
|
|
396
|
+
var _meta_collectedFormats;
|
|
260
397
|
let withOffset = [
|
|
261
398
|
{
|
|
262
399
|
...meta,
|
|
263
|
-
sort: variantSort
|
|
264
|
-
collectedFormats: ((
|
|
400
|
+
sort: context.offsets.applyVariantOffset(meta.sort, variantSort, Object.assign(args, context.variantOptions.get(variant))),
|
|
401
|
+
collectedFormats: ((_meta_collectedFormats = meta.collectedFormats) !== null && _meta_collectedFormats !== void 0 ? _meta_collectedFormats : []).concat(collectedFormats)
|
|
265
402
|
},
|
|
266
|
-
clone.nodes[0]
|
|
403
|
+
clone.nodes[0]
|
|
267
404
|
];
|
|
268
405
|
result.push(withOffset);
|
|
269
406
|
}
|
|
@@ -274,7 +411,7 @@ function applyVariant(variant, matches, context) {
|
|
|
274
411
|
}
|
|
275
412
|
function parseRules(rule, cache, options = {}) {
|
|
276
413
|
// PostCSS node
|
|
277
|
-
if (!(0, _isPlainObject
|
|
414
|
+
if (!(0, _isPlainObject.default)(rule) && !Array.isArray(rule)) {
|
|
278
415
|
return [
|
|
279
416
|
[
|
|
280
417
|
rule
|
|
@@ -288,7 +425,7 @@ function parseRules(rule, cache, options = {}) {
|
|
|
288
425
|
}
|
|
289
426
|
// Simple object
|
|
290
427
|
if (!cache.has(rule)) {
|
|
291
|
-
cache.set(rule, (0, _parseObjectStyles
|
|
428
|
+
cache.set(rule, (0, _parseObjectStyles.default)(rule));
|
|
292
429
|
}
|
|
293
430
|
return [
|
|
294
431
|
cache.get(rule),
|
|
@@ -305,12 +442,12 @@ function isValidPropName(name) {
|
|
|
305
442
|
*/ function looksLikeUri(declaration) {
|
|
306
443
|
// Quick bailout for obvious non-urls
|
|
307
444
|
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
308
|
-
if (!declaration.includes(
|
|
445
|
+
if (!declaration.includes("://")) {
|
|
309
446
|
return false;
|
|
310
447
|
}
|
|
311
448
|
try {
|
|
312
449
|
const url = new URL(declaration);
|
|
313
|
-
return url.scheme !==
|
|
450
|
+
return url.scheme !== "" && url.host !== "";
|
|
314
451
|
} catch (err) {
|
|
315
452
|
// Definitely not a valid url
|
|
316
453
|
return false;
|
|
@@ -319,7 +456,7 @@ function isValidPropName(name) {
|
|
|
319
456
|
function isParsableNode(node) {
|
|
320
457
|
let isParsable = true;
|
|
321
458
|
node.walkDecls((decl)=>{
|
|
322
|
-
if (!isParsableCssValue(decl.
|
|
459
|
+
if (!isParsableCssValue(decl.prop, decl.value)) {
|
|
323
460
|
isParsable = false;
|
|
324
461
|
return false;
|
|
325
462
|
}
|
|
@@ -327,9 +464,9 @@ function isParsableNode(node) {
|
|
|
327
464
|
return isParsable;
|
|
328
465
|
}
|
|
329
466
|
function isParsableCssValue(property, value) {
|
|
330
|
-
// We don't want to
|
|
467
|
+
// We don't want to treat [https://example.com] as a custom property
|
|
331
468
|
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
332
|
-
// So we short-circuit here by checking if the custom property looks like a
|
|
469
|
+
// So we short-circuit here by checking if the custom property looks like a URL
|
|
333
470
|
if (looksLikeUri(`${property}:${value}`)) {
|
|
334
471
|
return false;
|
|
335
472
|
}
|
|
@@ -341,63 +478,64 @@ function isParsableCssValue(property, value) {
|
|
|
341
478
|
}
|
|
342
479
|
}
|
|
343
480
|
function extractArbitraryProperty(classCandidate, context) {
|
|
344
|
-
var
|
|
345
|
-
let [, property, value] = (
|
|
481
|
+
var _classCandidate_match;
|
|
482
|
+
let [, property, value] = (_classCandidate_match = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && _classCandidate_match !== void 0 ? _classCandidate_match : [];
|
|
346
483
|
if (value === undefined) {
|
|
347
484
|
return null;
|
|
348
485
|
}
|
|
349
486
|
if (!isValidPropName(property)) {
|
|
350
487
|
return null;
|
|
351
488
|
}
|
|
352
|
-
if (!(0,
|
|
489
|
+
if (!(0, _isSyntacticallyValidPropertyValue.default)(value)) {
|
|
353
490
|
return null;
|
|
354
491
|
}
|
|
355
|
-
let normalized = (0, _dataTypes
|
|
492
|
+
let normalized = (0, _dataTypes.normalize)(value);
|
|
356
493
|
if (!isParsableCssValue(property, normalized)) {
|
|
357
494
|
return null;
|
|
358
495
|
}
|
|
496
|
+
let sort = context.offsets.arbitraryProperty();
|
|
359
497
|
return [
|
|
360
498
|
[
|
|
361
499
|
{
|
|
362
|
-
sort
|
|
363
|
-
layer:
|
|
500
|
+
sort,
|
|
501
|
+
layer: "utilities"
|
|
364
502
|
},
|
|
365
503
|
()=>({
|
|
366
|
-
[(0, _nameClass
|
|
504
|
+
[(0, _nameClass.asClass)(classCandidate)]: {
|
|
367
505
|
[property]: normalized
|
|
368
506
|
}
|
|
369
507
|
})
|
|
370
|
-
|
|
371
|
-
],
|
|
508
|
+
]
|
|
372
509
|
];
|
|
373
510
|
}
|
|
374
511
|
function* resolveMatchedPlugins(classCandidate, context) {
|
|
375
512
|
if (context.candidateRuleMap.has(classCandidate)) {
|
|
376
513
|
yield [
|
|
377
514
|
context.candidateRuleMap.get(classCandidate),
|
|
378
|
-
|
|
515
|
+
"DEFAULT"
|
|
379
516
|
];
|
|
380
517
|
}
|
|
381
|
-
yield*
|
|
518
|
+
yield* function*(arbitraryPropertyRule) {
|
|
382
519
|
if (arbitraryPropertyRule !== null) {
|
|
383
520
|
yield [
|
|
384
521
|
arbitraryPropertyRule,
|
|
385
|
-
|
|
522
|
+
"DEFAULT"
|
|
386
523
|
];
|
|
387
524
|
}
|
|
388
|
-
}
|
|
525
|
+
}(extractArbitraryProperty(classCandidate, context));
|
|
389
526
|
let candidatePrefix = classCandidate;
|
|
390
527
|
let negative = false;
|
|
391
528
|
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
392
529
|
const twConfigPrefixLen = twConfigPrefix.length;
|
|
393
|
-
|
|
530
|
+
const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
|
|
531
|
+
if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
|
|
394
532
|
negative = true;
|
|
395
533
|
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
396
534
|
}
|
|
397
535
|
if (negative && context.candidateRuleMap.has(candidatePrefix)) {
|
|
398
536
|
yield [
|
|
399
537
|
context.candidateRuleMap.get(candidatePrefix),
|
|
400
|
-
|
|
538
|
+
"-DEFAULT"
|
|
401
539
|
];
|
|
402
540
|
}
|
|
403
541
|
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
|
|
@@ -410,30 +548,41 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
410
548
|
}
|
|
411
549
|
}
|
|
412
550
|
function splitWithSeparator(input, separator) {
|
|
413
|
-
if (input ===
|
|
551
|
+
if (input === _sharedState.NOT_ON_DEMAND) {
|
|
414
552
|
return [
|
|
415
|
-
|
|
553
|
+
_sharedState.NOT_ON_DEMAND
|
|
416
554
|
];
|
|
417
555
|
}
|
|
418
|
-
return
|
|
556
|
+
return (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(input, separator);
|
|
419
557
|
}
|
|
420
558
|
function* recordCandidates(matches, classCandidate) {
|
|
421
559
|
for (const match of matches){
|
|
560
|
+
var _match__options;
|
|
561
|
+
var _match__options_preserveSource;
|
|
422
562
|
match[1].raws.tailwind = {
|
|
423
563
|
...match[1].raws.tailwind,
|
|
424
|
-
classCandidate
|
|
564
|
+
classCandidate,
|
|
565
|
+
preserveSource: (_match__options_preserveSource = (_match__options = match[0].options) === null || _match__options === void 0 ? void 0 : _match__options.preserveSource) !== null && _match__options_preserveSource !== void 0 ? _match__options_preserveSource : false
|
|
425
566
|
};
|
|
426
567
|
yield match;
|
|
427
568
|
}
|
|
428
569
|
}
|
|
429
|
-
function* resolveMatches(candidate, context) {
|
|
570
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
430
571
|
let separator = context.tailwindConfig.separator;
|
|
431
572
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
432
573
|
let important = false;
|
|
433
|
-
if (classCandidate.startsWith(
|
|
574
|
+
if (classCandidate.startsWith("!")) {
|
|
434
575
|
important = true;
|
|
435
576
|
classCandidate = classCandidate.slice(1);
|
|
436
577
|
}
|
|
578
|
+
if ((0, _featureFlags.flagEnabled)(context.tailwindConfig, "variantGrouping")) {
|
|
579
|
+
if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
|
|
580
|
+
let base = variants.slice().reverse().join(separator);
|
|
581
|
+
for (let part of (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(classCandidate.slice(1, -1), ",")){
|
|
582
|
+
yield* resolveMatches(base + separator + part, context, original);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
437
586
|
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
438
587
|
// function sortAgainst(toSort, against) {
|
|
439
588
|
// return toSort.slice().sort((a, z) => {
|
|
@@ -452,7 +601,7 @@ function* resolveMatches(candidate, context) {
|
|
|
452
601
|
let isOnlyPlugin = plugins.length === 1;
|
|
453
602
|
for (let [sort, plugin] of plugins){
|
|
454
603
|
let matchesPerPlugin = [];
|
|
455
|
-
if (typeof plugin ===
|
|
604
|
+
if (typeof plugin === "function") {
|
|
456
605
|
for (let ruleSet of [].concat(plugin(modifier, {
|
|
457
606
|
isOnlyPlugin
|
|
458
607
|
}))){
|
|
@@ -470,7 +619,7 @@ function* resolveMatches(candidate, context) {
|
|
|
470
619
|
]);
|
|
471
620
|
}
|
|
472
621
|
}
|
|
473
|
-
} else if (modifier ===
|
|
622
|
+
} else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
|
|
474
623
|
let ruleSet = plugin;
|
|
475
624
|
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
476
625
|
for (let rule of rules){
|
|
@@ -487,58 +636,94 @@ function* resolveMatches(candidate, context) {
|
|
|
487
636
|
}
|
|
488
637
|
}
|
|
489
638
|
if (matchesPerPlugin.length > 0) {
|
|
490
|
-
var
|
|
491
|
-
|
|
639
|
+
var _sort_options;
|
|
640
|
+
var _sort_options_types, _sort_options1;
|
|
641
|
+
let matchingTypes = Array.from((0, _pluginUtils.getMatchingTypes)((_sort_options_types = (_sort_options = sort.options) === null || _sort_options === void 0 ? void 0 : _sort_options.types) !== null && _sort_options_types !== void 0 ? _sort_options_types : [], modifier, (_sort_options1 = sort.options) !== null && _sort_options1 !== void 0 ? _sort_options1 : {}, context.tailwindConfig)).map(([_, type])=>type);
|
|
642
|
+
if (matchingTypes.length > 0) {
|
|
643
|
+
typesByMatches.set(matchesPerPlugin, matchingTypes);
|
|
644
|
+
}
|
|
492
645
|
matches.push(matchesPerPlugin);
|
|
493
646
|
}
|
|
494
647
|
}
|
|
495
648
|
if (isArbitraryValue(modifier)) {
|
|
496
|
-
// When generated arbitrary values are ambiguous, we can't know
|
|
497
|
-
// which to pick so don't generate any utilities for them
|
|
498
649
|
if (matches.length > 1) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
])
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
650
|
+
// Partition plugins in 2 categories so that we can start searching in the plugins that
|
|
651
|
+
// don't have `any` as a type first.
|
|
652
|
+
let [withAny, withoutAny] = matches.reduce((group, plugin)=>{
|
|
653
|
+
let hasAnyType = plugin.some(([{ options }])=>options.types.some(({ type })=>type === "any"));
|
|
654
|
+
if (hasAnyType) {
|
|
655
|
+
group[0].push(plugin);
|
|
656
|
+
} else {
|
|
657
|
+
group[1].push(plugin);
|
|
658
|
+
}
|
|
659
|
+
return group;
|
|
660
|
+
}, [
|
|
661
|
+
[],
|
|
662
|
+
[]
|
|
663
|
+
]);
|
|
664
|
+
function findFallback(matches) {
|
|
665
|
+
// If only a single plugin matches, let's take that one
|
|
666
|
+
if (matches.length === 1) {
|
|
667
|
+
return matches[0];
|
|
668
|
+
}
|
|
669
|
+
// Otherwise, find the plugin that creates a valid rule given the arbitrary value, and
|
|
670
|
+
// also has the correct type which preferOnConflicts the plugin in case of clashes.
|
|
671
|
+
return matches.find((rules)=>{
|
|
672
|
+
let matchingTypes = typesByMatches.get(rules);
|
|
673
|
+
return rules.some(([{ options }, rule])=>{
|
|
674
|
+
if (!isParsableNode(rule)) {
|
|
675
|
+
return false;
|
|
513
676
|
}
|
|
677
|
+
return options.types.some(({ type , preferOnConflict })=>matchingTypes.includes(type) && preferOnConflict);
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
var _findFallback;
|
|
682
|
+
// Try to find a fallback plugin, because we already know that multiple plugins matched for
|
|
683
|
+
// the given arbitrary value.
|
|
684
|
+
let fallback = (_findFallback = findFallback(withoutAny)) !== null && _findFallback !== void 0 ? _findFallback : findFallback(withAny);
|
|
685
|
+
if (fallback) {
|
|
686
|
+
matches = [
|
|
687
|
+
fallback
|
|
688
|
+
];
|
|
689
|
+
} else {
|
|
690
|
+
var _typesByMatches_get;
|
|
691
|
+
let typesPerPlugin = matches.map((match)=>new Set([
|
|
692
|
+
...(_typesByMatches_get = typesByMatches.get(match)) !== null && _typesByMatches_get !== void 0 ? _typesByMatches_get : []
|
|
693
|
+
]));
|
|
694
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
695
|
+
for (let pluginTypes of typesPerPlugin){
|
|
696
|
+
for (let type of pluginTypes){
|
|
697
|
+
let removeFromOwnGroup = false;
|
|
698
|
+
for (let otherGroup of typesPerPlugin){
|
|
699
|
+
if (pluginTypes === otherGroup) continue;
|
|
700
|
+
if (otherGroup.has(type)) {
|
|
701
|
+
otherGroup.delete(type);
|
|
702
|
+
removeFromOwnGroup = true;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
514
706
|
}
|
|
515
|
-
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
516
707
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
.join('\n')
|
|
527
|
-
).join('\n\n');
|
|
528
|
-
messages.push(` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
529
|
-
break;
|
|
708
|
+
let messages = [];
|
|
709
|
+
for (let [idx, group] of typesPerPlugin.entries()){
|
|
710
|
+
for (let type of group){
|
|
711
|
+
let rules = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
|
|
712
|
+
.map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
|
|
713
|
+
.join("\n")).join("\n\n");
|
|
714
|
+
messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
530
717
|
}
|
|
718
|
+
_log.default.warn([
|
|
719
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
720
|
+
...messages,
|
|
721
|
+
`If this is content and not a class, replace it with \`${candidate.replace("[", "[").replace("]", "]")}\` to silence this warning.`
|
|
722
|
+
]);
|
|
723
|
+
continue;
|
|
531
724
|
}
|
|
532
|
-
_log.default.warn([
|
|
533
|
-
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
534
|
-
...messages,
|
|
535
|
-
`If this is content and not a class, replace it with \`${candidate.replace('[', '[').replace(']', ']')}\` to silence this warning.`,
|
|
536
|
-
]);
|
|
537
|
-
continue;
|
|
538
725
|
}
|
|
539
|
-
matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])
|
|
540
|
-
)
|
|
541
|
-
);
|
|
726
|
+
matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
|
|
542
727
|
}
|
|
543
728
|
matches = matches.flat();
|
|
544
729
|
matches = Array.from(recordCandidates(matches, classCandidate));
|
|
@@ -549,44 +734,113 @@ function* resolveMatches(candidate, context) {
|
|
|
549
734
|
for (let variant of variants){
|
|
550
735
|
matches = applyVariant(variant, matches, context);
|
|
551
736
|
}
|
|
552
|
-
for (let
|
|
553
|
-
|
|
554
|
-
...
|
|
737
|
+
for (let match of matches){
|
|
738
|
+
match[1].raws.tailwind = {
|
|
739
|
+
...match[1].raws.tailwind,
|
|
555
740
|
candidate
|
|
556
741
|
};
|
|
557
742
|
// Apply final format selector
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
selector: rule.selector,
|
|
569
|
-
candidate,
|
|
570
|
-
context
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
match1[1] = container.nodes[0];
|
|
743
|
+
match = applyFinalFormat(match, {
|
|
744
|
+
context,
|
|
745
|
+
candidate,
|
|
746
|
+
original
|
|
747
|
+
});
|
|
748
|
+
// Skip rules with invalid selectors
|
|
749
|
+
// This will cause the candidate to be added to the "not class"
|
|
750
|
+
// cache skipping it entirely for future builds
|
|
751
|
+
if (match === null) {
|
|
752
|
+
continue;
|
|
574
753
|
}
|
|
575
|
-
yield
|
|
754
|
+
yield match;
|
|
576
755
|
}
|
|
577
756
|
}
|
|
578
757
|
}
|
|
758
|
+
function applyFinalFormat(match, { context , candidate , original }) {
|
|
759
|
+
if (!match[0].collectedFormats) {
|
|
760
|
+
return match;
|
|
761
|
+
}
|
|
762
|
+
let isValid = true;
|
|
763
|
+
let finalFormat;
|
|
764
|
+
try {
|
|
765
|
+
finalFormat = (0, _formatVariantSelector.formatVariantSelector)(match[0].collectedFormats, {
|
|
766
|
+
context,
|
|
767
|
+
candidate
|
|
768
|
+
});
|
|
769
|
+
} catch {
|
|
770
|
+
// The format selector we produced is invalid
|
|
771
|
+
// This could be because:
|
|
772
|
+
// - A bug exists
|
|
773
|
+
// - A plugin introduced an invalid variant selector (ex: `addVariant('foo', '&;foo')`)
|
|
774
|
+
// - The user used an invalid arbitrary variant (ex: `[&;foo]:underline`)
|
|
775
|
+
// Either way the build will fail because of this
|
|
776
|
+
// We would rather that the build pass "silently" given that this could
|
|
777
|
+
// happen because of picking up invalid things when scanning content
|
|
778
|
+
// So we'll throw out the candidate instead
|
|
779
|
+
return null;
|
|
780
|
+
}
|
|
781
|
+
let container = _postcss.default.root({
|
|
782
|
+
nodes: [
|
|
783
|
+
match[1].clone()
|
|
784
|
+
]
|
|
785
|
+
});
|
|
786
|
+
container.walkRules((rule)=>{
|
|
787
|
+
if (inKeyframes(rule)) {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
try {
|
|
791
|
+
rule.selector = (0, _formatVariantSelector.finalizeSelector)(rule.selector, finalFormat, {
|
|
792
|
+
candidate: original,
|
|
793
|
+
context
|
|
794
|
+
});
|
|
795
|
+
} catch {
|
|
796
|
+
// If this selector is invalid we also want to skip it
|
|
797
|
+
// But it's likely that being invalid here means there's a bug in a plugin rather than too loosely matching content
|
|
798
|
+
isValid = false;
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
if (!isValid) {
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
match[1] = container.nodes[0];
|
|
806
|
+
return match;
|
|
807
|
+
}
|
|
579
808
|
function inKeyframes(rule) {
|
|
580
|
-
return rule.parent && rule.parent.type ===
|
|
809
|
+
return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
|
|
810
|
+
}
|
|
811
|
+
function getImportantStrategy(important) {
|
|
812
|
+
if (important === true) {
|
|
813
|
+
return (rule)=>{
|
|
814
|
+
if (inKeyframes(rule)) {
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
rule.walkDecls((d)=>{
|
|
818
|
+
if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
|
|
819
|
+
d.important = true;
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
if (typeof important === "string") {
|
|
825
|
+
return (rule)=>{
|
|
826
|
+
if (inKeyframes(rule)) {
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
830
|
+
return (0, _applyImportantSelector.applyImportantSelector)(selector, important);
|
|
831
|
+
});
|
|
832
|
+
};
|
|
833
|
+
}
|
|
581
834
|
}
|
|
582
835
|
function generateRules(candidates, context) {
|
|
583
836
|
let allRules = [];
|
|
837
|
+
let strategy = getImportantStrategy(context.tailwindConfig.important);
|
|
584
838
|
for (let candidate of candidates){
|
|
585
839
|
if (context.notClassCache.has(candidate)) {
|
|
586
840
|
continue;
|
|
587
841
|
}
|
|
588
|
-
if (context.
|
|
589
|
-
allRules.
|
|
842
|
+
if (context.candidateRuleCache.has(candidate)) {
|
|
843
|
+
allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)));
|
|
590
844
|
continue;
|
|
591
845
|
}
|
|
592
846
|
let matches = Array.from(resolveMatches(candidate, context));
|
|
@@ -595,52 +849,31 @@ function generateRules(candidates, context) {
|
|
|
595
849
|
continue;
|
|
596
850
|
}
|
|
597
851
|
context.classCache.set(candidate, matches);
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
rule.walkDecls((d)=>{
|
|
605
|
-
if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
|
|
606
|
-
d.important = true;
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
if (typeof important === 'string') {
|
|
612
|
-
return (rule)=>{
|
|
613
|
-
rule.selectors = rule.selectors.map((selector)=>{
|
|
614
|
-
return `${important} ${selector}`;
|
|
615
|
-
});
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
})(context.tailwindConfig.important);
|
|
619
|
-
return allRules.flat(1).map(([{ sort , layer , options }, rule])=>{
|
|
620
|
-
if (options.respectImportant) {
|
|
621
|
-
if (strategy) {
|
|
852
|
+
var _context_candidateRuleCache_get;
|
|
853
|
+
let rules = (_context_candidateRuleCache_get = context.candidateRuleCache.get(candidate)) !== null && _context_candidateRuleCache_get !== void 0 ? _context_candidateRuleCache_get : new Set();
|
|
854
|
+
context.candidateRuleCache.set(candidate, rules);
|
|
855
|
+
for (const match of matches){
|
|
856
|
+
let [{ sort , options }, rule] = match;
|
|
857
|
+
if (options.respectImportant && strategy) {
|
|
622
858
|
let container = _postcss.default.root({
|
|
623
859
|
nodes: [
|
|
624
860
|
rule.clone()
|
|
625
861
|
]
|
|
626
862
|
});
|
|
627
|
-
container.walkRules(
|
|
628
|
-
if (inKeyframes(r)) {
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
strategy(r);
|
|
632
|
-
});
|
|
863
|
+
container.walkRules(strategy);
|
|
633
864
|
rule = container.nodes[0];
|
|
634
865
|
}
|
|
866
|
+
let newEntry = [
|
|
867
|
+
sort,
|
|
868
|
+
rule
|
|
869
|
+
];
|
|
870
|
+
rules.add(newEntry);
|
|
871
|
+
context.ruleCache.add(newEntry);
|
|
872
|
+
allRules.push(newEntry);
|
|
635
873
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
rule
|
|
639
|
-
];
|
|
640
|
-
});
|
|
874
|
+
}
|
|
875
|
+
return allRules;
|
|
641
876
|
}
|
|
642
877
|
function isArbitraryValue(input) {
|
|
643
|
-
return input.startsWith(
|
|
878
|
+
return input.startsWith("[") && input.endsWith("]");
|
|
644
879
|
}
|
|
645
|
-
exports.resolveMatches = resolveMatches;
|
|
646
|
-
exports.generateRules = generateRules;
|