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