tailwindcss 0.0.0-insiders.bbafc8e → 0.0.0-insiders.bbf2b1b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +163 -8
- package/README.md +6 -3
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +4 -0
- package/lib/cli-peer-dependencies.js +20 -7
- package/lib/cli.js +314 -247
- package/lib/constants.js +27 -20
- package/lib/corePluginList.js +6 -3
- package/lib/corePlugins.js +1719 -1628
- package/lib/css/preflight.css +1 -8
- package/lib/featureFlags.js +27 -18
- package/lib/index.js +17 -15
- package/lib/lib/cacheInvalidation.js +45 -24
- package/lib/lib/collapseAdjacentRules.js +14 -9
- package/lib/lib/collapseDuplicateDeclarations.js +12 -9
- package/lib/lib/defaultExtractor.js +220 -33
- package/lib/lib/detectNesting.js +13 -10
- package/lib/lib/evaluateTailwindFunctions.js +101 -54
- package/lib/lib/expandApplyAtRules.js +254 -209
- package/lib/lib/expandTailwindAtRules.js +86 -69
- package/lib/lib/generateRules.js +244 -145
- package/lib/lib/getModuleDependencies.js +11 -8
- package/lib/lib/normalizeTailwindDirectives.js +35 -32
- package/lib/lib/partitionApplyAtRules.js +11 -8
- package/lib/lib/regex.js +60 -0
- package/lib/lib/resolveDefaultsAtRules.js +89 -71
- package/lib/lib/setupContextUtils.js +290 -205
- package/lib/lib/setupTrackingContext.js +44 -37
- package/lib/lib/sharedState.js +22 -16
- package/lib/lib/substituteScreenAtRules.js +11 -9
- package/lib/postcss-plugins/nesting/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +8 -6
- package/lib/postcss-plugins/nesting/plugin.js +18 -16
- package/lib/processTailwindFeatures.js +31 -28
- package/lib/public/colors.js +247 -245
- package/lib/public/create-plugin.js +6 -4
- package/lib/public/default-config.js +7 -5
- package/lib/public/default-theme.js +7 -5
- package/lib/public/resolve-config.js +8 -5
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +7 -5
- package/lib/util/cloneDeep.js +7 -6
- package/lib/util/cloneNodes.js +10 -3
- package/lib/util/color.js +53 -54
- package/lib/util/configurePlugins.js +4 -1
- package/lib/util/createPlugin.js +6 -5
- package/lib/util/createUtilityPlugin.js +9 -7
- package/lib/util/dataTypes.js +110 -100
- package/lib/util/defaults.js +4 -1
- package/lib/util/escapeClassName.js +7 -4
- package/lib/util/escapeCommas.js +5 -2
- package/lib/util/flattenColorPalette.js +9 -10
- package/lib/util/formatVariantSelector.js +100 -85
- package/lib/util/getAllConfigs.js +17 -8
- package/lib/util/hashConfig.js +6 -3
- package/lib/util/isKeyframeRule.js +5 -2
- package/lib/util/isPlainObject.js +5 -2
- package/lib/util/isValidArbitraryValue.js +21 -13
- package/lib/util/log.js +18 -12
- package/lib/util/nameClass.js +17 -9
- package/lib/util/negateValue.js +8 -6
- package/lib/util/normalizeConfig.js +84 -71
- package/lib/util/normalizeScreens.js +22 -8
- package/lib/util/parseAnimationValue.js +42 -40
- package/lib/util/parseBoxShadowValue.js +29 -62
- package/lib/util/parseDependency.js +18 -15
- package/lib/util/parseObjectStyles.js +10 -7
- package/lib/util/pluginUtils.js +47 -31
- package/lib/util/prefixSelector.js +7 -4
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +88 -84
- package/lib/util/resolveConfigPath.js +10 -7
- package/lib/util/responsive.js +8 -5
- package/lib/util/splitAtTopLevelOnly.js +93 -0
- package/lib/util/tap.js +4 -1
- package/lib/util/toColorValue.js +5 -2
- package/lib/util/toPath.js +20 -4
- package/lib/util/transformThemeValue.js +30 -25
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/withAlphaVariable.js +23 -15
- package/package.json +32 -27
- package/peers/index.js +8612 -4245
- package/plugin.d.ts +11 -0
- package/resolveConfig.d.ts +3 -0
- package/scripts/generate-types.js +105 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +125 -25
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +145 -49
- package/src/css/preflight.css +1 -8
- package/src/featureFlags.js +2 -2
- package/src/lib/collapseAdjacentRules.js +5 -1
- package/src/lib/defaultExtractor.js +193 -35
- package/src/lib/evaluateTailwindFunctions.js +56 -6
- package/src/lib/expandApplyAtRules.js +252 -187
- package/src/lib/expandTailwindAtRules.js +4 -4
- package/src/lib/generateRules.js +156 -59
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -36
- package/src/lib/setupContextUtils.js +142 -46
- package/src/lib/setupTrackingContext.js +5 -1
- package/src/postcss-plugins/nesting/README.md +2 -2
- package/src/util/cloneNodes.js +5 -1
- package/src/util/color.js +25 -21
- package/src/util/dataTypes.js +13 -7
- package/src/util/formatVariantSelector.js +82 -63
- package/src/util/getAllConfigs.js +8 -0
- package/src/util/log.js +1 -1
- package/src/util/normalizeConfig.js +0 -8
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/pluginUtils.js +13 -1
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +66 -52
- package/src/util/splitAtTopLevelOnly.js +71 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +4 -2
- package/src/util/validateConfig.js +13 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/stubs/defaultConfig.stub.js +5 -1
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +327 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +331 -0
- package/types/index.d.ts +7 -0
package/lib/lib/generateRules.js
CHANGED
|
@@ -2,48 +2,77 @@
|
|
|
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
|
+
resolveMatches: ()=>resolveMatches,
|
|
13
|
+
generateRules: ()=>generateRules
|
|
14
|
+
});
|
|
15
|
+
const _postcss = /*#__PURE__*/ _interopRequireDefault(require("postcss"));
|
|
16
|
+
const _postcssSelectorParser = /*#__PURE__*/ _interopRequireDefault(require("postcss-selector-parser"));
|
|
17
|
+
const _parseObjectStyles = /*#__PURE__*/ _interopRequireDefault(require("../util/parseObjectStyles"));
|
|
18
|
+
const _isPlainObject = /*#__PURE__*/ _interopRequireDefault(require("../util/isPlainObject"));
|
|
19
|
+
const _prefixSelector = /*#__PURE__*/ _interopRequireDefault(require("../util/prefixSelector"));
|
|
20
|
+
const _pluginUtils = require("../util/pluginUtils");
|
|
21
|
+
const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
|
|
22
|
+
const _sharedState = /*#__PURE__*/ _interopRequireWildcard(require("./sharedState"));
|
|
23
|
+
const _formatVariantSelector = require("../util/formatVariantSelector");
|
|
24
|
+
const _nameClass = require("../util/nameClass");
|
|
25
|
+
const _dataTypes = require("../util/dataTypes");
|
|
26
|
+
const _setupContextUtils = require("./setupContextUtils");
|
|
27
|
+
const _isValidArbitraryValue = /*#__PURE__*/ _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
28
|
+
const _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
|
|
29
|
+
const _featureFlags = require("../featureFlags");
|
|
18
30
|
function _interopRequireDefault(obj) {
|
|
19
31
|
return obj && obj.__esModule ? obj : {
|
|
20
32
|
default: obj
|
|
21
33
|
};
|
|
22
34
|
}
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
35
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
36
|
+
if (typeof WeakMap !== "function") return null;
|
|
37
|
+
var cacheBabelInterop = new WeakMap();
|
|
38
|
+
var cacheNodeInterop = new WeakMap();
|
|
39
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
40
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
41
|
+
})(nodeInterop);
|
|
42
|
+
}
|
|
43
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
44
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
45
|
return obj;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
}
|
|
47
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
48
|
+
return {
|
|
49
|
+
default: obj
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
53
|
+
if (cache && cache.has(obj)) {
|
|
54
|
+
return cache.get(obj);
|
|
55
|
+
}
|
|
56
|
+
var newObj = {};
|
|
57
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
58
|
+
for(var key in obj){
|
|
59
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
60
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
61
|
+
if (desc && (desc.get || desc.set)) {
|
|
62
|
+
Object.defineProperty(newObj, key, desc);
|
|
63
|
+
} else {
|
|
64
|
+
newObj[key] = obj[key];
|
|
38
65
|
}
|
|
39
66
|
}
|
|
40
|
-
newObj.default = obj;
|
|
41
|
-
return newObj;
|
|
42
67
|
}
|
|
68
|
+
newObj.default = obj;
|
|
69
|
+
if (cache) {
|
|
70
|
+
cache.set(obj, newObj);
|
|
71
|
+
}
|
|
72
|
+
return newObj;
|
|
43
73
|
}
|
|
44
|
-
let classNameParser = (0, _postcssSelectorParser
|
|
45
|
-
return selectors.first.filter(({ type })=>type ===
|
|
46
|
-
).pop().value;
|
|
74
|
+
let classNameParser = (0, _postcssSelectorParser.default)((selectors)=>{
|
|
75
|
+
return selectors.first.filter(({ type })=>type === "class").pop().value;
|
|
47
76
|
});
|
|
48
77
|
function getClassNameFromSelector(selector) {
|
|
49
78
|
return classNameParser.transformSync(selector);
|
|
@@ -59,16 +88,16 @@ function* candidatePermutations(candidate) {
|
|
|
59
88
|
let lastIndex = Infinity;
|
|
60
89
|
while(lastIndex >= 0){
|
|
61
90
|
let dashIdx;
|
|
62
|
-
if (lastIndex === Infinity && candidate.endsWith(
|
|
63
|
-
let bracketIdx = candidate.indexOf(
|
|
91
|
+
if (lastIndex === Infinity && candidate.endsWith("]")) {
|
|
92
|
+
let bracketIdx = candidate.indexOf("[");
|
|
64
93
|
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
65
94
|
// eg. string[]
|
|
66
95
|
dashIdx = [
|
|
67
|
-
|
|
68
|
-
|
|
96
|
+
"-",
|
|
97
|
+
"/"
|
|
69
98
|
].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
|
|
70
99
|
} else {
|
|
71
|
-
dashIdx = candidate.lastIndexOf(
|
|
100
|
+
dashIdx = candidate.lastIndexOf("-", lastIndex);
|
|
72
101
|
}
|
|
73
102
|
if (dashIdx < 0) {
|
|
74
103
|
break;
|
|
@@ -83,7 +112,7 @@ function* candidatePermutations(candidate) {
|
|
|
83
112
|
}
|
|
84
113
|
}
|
|
85
114
|
function applyPrefix(matches, context) {
|
|
86
|
-
if (matches.length === 0 || context.tailwindConfig.prefix ===
|
|
115
|
+
if (matches.length === 0 || context.tailwindConfig.prefix === "") {
|
|
87
116
|
return matches;
|
|
88
117
|
}
|
|
89
118
|
for (let match of matches){
|
|
@@ -100,8 +129,8 @@ function applyPrefix(matches, context) {
|
|
|
100
129
|
// have to ensure that the generated selector matches the candidate
|
|
101
130
|
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
102
131
|
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
103
|
-
let shouldPrependNegative = classCandidate.startsWith(
|
|
104
|
-
r.selector = (0, _prefixSelector
|
|
132
|
+
let shouldPrependNegative = classCandidate.startsWith("-");
|
|
133
|
+
r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
|
|
105
134
|
});
|
|
106
135
|
match[1] = container.nodes[0];
|
|
107
136
|
}
|
|
@@ -120,14 +149,13 @@ function applyImportant(matches, classCandidate) {
|
|
|
120
149
|
]
|
|
121
150
|
});
|
|
122
151
|
container.walkRules((r)=>{
|
|
123
|
-
r.selector = (0, _pluginUtils
|
|
152
|
+
r.selector = (0, _pluginUtils.updateAllClasses)(r.selector, (className)=>{
|
|
124
153
|
if (className === classCandidate) {
|
|
125
154
|
return `!${className}`;
|
|
126
155
|
}
|
|
127
156
|
return className;
|
|
128
157
|
});
|
|
129
|
-
r.walkDecls((d)=>d.important = true
|
|
130
|
-
);
|
|
158
|
+
r.walkDecls((d)=>d.important = true);
|
|
131
159
|
});
|
|
132
160
|
result.push([
|
|
133
161
|
{
|
|
@@ -151,32 +179,56 @@ function applyVariant(variant, matches, context) {
|
|
|
151
179
|
if (matches.length === 0) {
|
|
152
180
|
return matches;
|
|
153
181
|
}
|
|
182
|
+
let args;
|
|
183
|
+
// Find partial arbitrary variants
|
|
184
|
+
if (variant.endsWith("]") && !variant.startsWith("[")) {
|
|
185
|
+
args = variant.slice(variant.lastIndexOf("[") + 1, -1);
|
|
186
|
+
variant = variant.slice(0, variant.indexOf(args) - 1 /* - */ - 1 /* [ */ );
|
|
187
|
+
}
|
|
188
|
+
// Register arbitrary variants
|
|
189
|
+
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
|
|
190
|
+
let selector = (0, _dataTypes.normalize)(variant.slice(1, -1));
|
|
191
|
+
if (!(0, _setupContextUtils.isValidVariantFormatString)(selector)) {
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
let fn = (0, _setupContextUtils.parseVariant)(selector);
|
|
195
|
+
let sort = Array.from(context.variantOrder.values()).pop() << 1n;
|
|
196
|
+
context.variantMap.set(variant, [
|
|
197
|
+
[
|
|
198
|
+
sort,
|
|
199
|
+
fn
|
|
200
|
+
]
|
|
201
|
+
]);
|
|
202
|
+
context.variantOrder.set(variant, sort);
|
|
203
|
+
}
|
|
154
204
|
if (context.variantMap.has(variant)) {
|
|
155
|
-
let variantFunctionTuples = context.variantMap.get(variant);
|
|
205
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice();
|
|
156
206
|
let result = [];
|
|
157
|
-
for (let [meta,
|
|
207
|
+
for (let [meta, rule] of matches){
|
|
158
208
|
// Don't generate variants for user css
|
|
159
|
-
if (meta.layer ===
|
|
209
|
+
if (meta.layer === "user") {
|
|
160
210
|
continue;
|
|
161
211
|
}
|
|
162
212
|
let container = _postcss.default.root({
|
|
163
213
|
nodes: [
|
|
164
|
-
|
|
214
|
+
rule.clone()
|
|
165
215
|
]
|
|
166
216
|
});
|
|
167
|
-
for (let [variantSort, variantFunction] of variantFunctionTuples){
|
|
168
|
-
let clone = container.clone();
|
|
217
|
+
for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples){
|
|
218
|
+
let clone = containerFromArray !== null && containerFromArray !== void 0 ? containerFromArray : container.clone();
|
|
169
219
|
let collectedFormats = [];
|
|
170
|
-
let originals = new Map();
|
|
171
220
|
function prepareBackup() {
|
|
172
|
-
|
|
173
|
-
clone.
|
|
174
|
-
|
|
221
|
+
// Already prepared, chicken out
|
|
222
|
+
if (clone.raws.neededBackup) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
clone.raws.neededBackup = true;
|
|
226
|
+
clone.walkRules((rule)=>rule.raws.originalSelector = rule.selector);
|
|
175
227
|
}
|
|
176
228
|
function modifySelectors(modifierFunction) {
|
|
177
229
|
prepareBackup();
|
|
178
230
|
clone.each((rule)=>{
|
|
179
|
-
if (rule.type !==
|
|
231
|
+
if (rule.type !== "rule") {
|
|
180
232
|
return;
|
|
181
233
|
}
|
|
182
234
|
rule.selectors = rule.selectors.map((selector)=>{
|
|
@@ -207,28 +259,53 @@ function applyVariant(variant, matches, context) {
|
|
|
207
259
|
},
|
|
208
260
|
format (selectorFormat) {
|
|
209
261
|
collectedFormats.push(selectorFormat);
|
|
210
|
-
}
|
|
262
|
+
},
|
|
263
|
+
args
|
|
211
264
|
});
|
|
212
|
-
|
|
265
|
+
// It can happen that a list of format strings is returned from within the function. In that
|
|
266
|
+
// case, we have to process them as well. We can use the existing `variantSort`.
|
|
267
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
268
|
+
for (let [idx, variantFunction1] of ruleWithVariant.entries()){
|
|
269
|
+
// This is a little bit scary since we are pushing to an array of items that we are
|
|
270
|
+
// currently looping over. However, you can also think of it like a processing queue
|
|
271
|
+
// where you keep handling jobs until everything is done and each job can queue more
|
|
272
|
+
// jobs if needed.
|
|
273
|
+
variantFunctionTuples.push([
|
|
274
|
+
// TODO: This could have potential bugs if we shift the sort order from variant A far
|
|
275
|
+
// enough into the sort space of variant B. The chances are low, but if this happens
|
|
276
|
+
// then this might be the place too look at. One potential solution to this problem is
|
|
277
|
+
// reserving additional X places for these 'unknown' variants in between.
|
|
278
|
+
variantSort | BigInt(idx << ruleWithVariant.length),
|
|
279
|
+
variantFunction1,
|
|
280
|
+
// If the clone has been modified we have to pass that back
|
|
281
|
+
// though so each rule can use the modified container
|
|
282
|
+
clone.clone(),
|
|
283
|
+
]);
|
|
284
|
+
}
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (typeof ruleWithVariant === "string") {
|
|
213
288
|
collectedFormats.push(ruleWithVariant);
|
|
214
289
|
}
|
|
215
290
|
if (ruleWithVariant === null) {
|
|
216
291
|
continue;
|
|
217
292
|
}
|
|
218
|
-
// We
|
|
293
|
+
// We had to backup selectors, therefore we assume that somebody touched
|
|
219
294
|
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
220
295
|
// can restore the selectors, and collect the format strings.
|
|
221
|
-
if (
|
|
296
|
+
if (clone.raws.neededBackup) {
|
|
297
|
+
delete clone.raws.neededBackup;
|
|
222
298
|
clone.walkRules((rule)=>{
|
|
223
|
-
|
|
224
|
-
|
|
299
|
+
let before = rule.raws.originalSelector;
|
|
300
|
+
if (!before) return;
|
|
301
|
+
delete rule.raws.originalSelector;
|
|
225
302
|
if (before === rule.selector) return; // No mutation happened
|
|
226
303
|
let modified = rule.selector;
|
|
227
304
|
// Rebuild the base selector, this is what plugin authors would do
|
|
228
305
|
// as well. E.g.: `${variant}${separator}${className}`.
|
|
229
306
|
// However, plugin authors probably also prepend or append certain
|
|
230
307
|
// classes, pseudos, ids, ...
|
|
231
|
-
let rebuiltBase = (0, _postcssSelectorParser
|
|
308
|
+
let rebuiltBase = (0, _postcssSelectorParser.default)((selectors)=>{
|
|
232
309
|
selectors.walkClasses((classNode)=>{
|
|
233
310
|
classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
|
|
234
311
|
});
|
|
@@ -244,7 +321,7 @@ function applyVariant(variant, matches, context) {
|
|
|
244
321
|
// modified (by plugin): .foo .foo\\:markdown > p
|
|
245
322
|
// rebuiltBase (internal): .foo\\:markdown > p
|
|
246
323
|
// format: .foo &
|
|
247
|
-
collectedFormats.push(modified.replace(rebuiltBase,
|
|
324
|
+
collectedFormats.push(modified.replace(rebuiltBase, "&"));
|
|
248
325
|
rule.selector = before;
|
|
249
326
|
});
|
|
250
327
|
}
|
|
@@ -261,7 +338,8 @@ function applyVariant(variant, matches, context) {
|
|
|
261
338
|
{
|
|
262
339
|
...meta,
|
|
263
340
|
sort: variantSort | meta.sort,
|
|
264
|
-
collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats)
|
|
341
|
+
collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats),
|
|
342
|
+
isArbitraryVariant: isArbitraryValue(variant)
|
|
265
343
|
},
|
|
266
344
|
clone.nodes[0],
|
|
267
345
|
];
|
|
@@ -274,7 +352,7 @@ function applyVariant(variant, matches, context) {
|
|
|
274
352
|
}
|
|
275
353
|
function parseRules(rule, cache, options = {}) {
|
|
276
354
|
// PostCSS node
|
|
277
|
-
if (!(0, _isPlainObject
|
|
355
|
+
if (!(0, _isPlainObject.default)(rule) && !Array.isArray(rule)) {
|
|
278
356
|
return [
|
|
279
357
|
[
|
|
280
358
|
rule
|
|
@@ -288,7 +366,7 @@ function parseRules(rule, cache, options = {}) {
|
|
|
288
366
|
}
|
|
289
367
|
// Simple object
|
|
290
368
|
if (!cache.has(rule)) {
|
|
291
|
-
cache.set(rule, (0, _parseObjectStyles
|
|
369
|
+
cache.set(rule, (0, _parseObjectStyles.default)(rule));
|
|
292
370
|
}
|
|
293
371
|
return [
|
|
294
372
|
cache.get(rule),
|
|
@@ -305,17 +383,27 @@ function isValidPropName(name) {
|
|
|
305
383
|
*/ function looksLikeUri(declaration) {
|
|
306
384
|
// Quick bailout for obvious non-urls
|
|
307
385
|
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
308
|
-
if (!declaration.includes(
|
|
386
|
+
if (!declaration.includes("://")) {
|
|
309
387
|
return false;
|
|
310
388
|
}
|
|
311
389
|
try {
|
|
312
390
|
const url = new URL(declaration);
|
|
313
|
-
return url.scheme !==
|
|
391
|
+
return url.scheme !== "" && url.host !== "";
|
|
314
392
|
} catch (err) {
|
|
315
393
|
// Definitely not a valid url
|
|
316
394
|
return false;
|
|
317
395
|
}
|
|
318
396
|
}
|
|
397
|
+
function isParsableNode(node) {
|
|
398
|
+
let isParsable = true;
|
|
399
|
+
node.walkDecls((decl)=>{
|
|
400
|
+
if (!isParsableCssValue(decl.name, decl.value)) {
|
|
401
|
+
isParsable = false;
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
return isParsable;
|
|
406
|
+
}
|
|
319
407
|
function isParsableCssValue(property, value) {
|
|
320
408
|
// We don't want to to treat [https://example.com] as a custom property
|
|
321
409
|
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
@@ -339,10 +427,10 @@ function extractArbitraryProperty(classCandidate, context) {
|
|
|
339
427
|
if (!isValidPropName(property)) {
|
|
340
428
|
return null;
|
|
341
429
|
}
|
|
342
|
-
if (!(0, _isValidArbitraryValue
|
|
430
|
+
if (!(0, _isValidArbitraryValue.default)(value)) {
|
|
343
431
|
return null;
|
|
344
432
|
}
|
|
345
|
-
let normalized = (0, _dataTypes
|
|
433
|
+
let normalized = (0, _dataTypes.normalize)(value);
|
|
346
434
|
if (!isParsableCssValue(property, normalized)) {
|
|
347
435
|
return null;
|
|
348
436
|
}
|
|
@@ -350,14 +438,13 @@ function extractArbitraryProperty(classCandidate, context) {
|
|
|
350
438
|
[
|
|
351
439
|
{
|
|
352
440
|
sort: context.arbitraryPropertiesSort,
|
|
353
|
-
layer:
|
|
441
|
+
layer: "utilities"
|
|
354
442
|
},
|
|
355
443
|
()=>({
|
|
356
|
-
[(0, _nameClass
|
|
444
|
+
[(0, _nameClass.asClass)(classCandidate)]: {
|
|
357
445
|
[property]: normalized
|
|
358
446
|
}
|
|
359
|
-
})
|
|
360
|
-
,
|
|
447
|
+
}),
|
|
361
448
|
],
|
|
362
449
|
];
|
|
363
450
|
}
|
|
@@ -365,29 +452,30 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
365
452
|
if (context.candidateRuleMap.has(classCandidate)) {
|
|
366
453
|
yield [
|
|
367
454
|
context.candidateRuleMap.get(classCandidate),
|
|
368
|
-
|
|
455
|
+
"DEFAULT"
|
|
369
456
|
];
|
|
370
457
|
}
|
|
371
|
-
yield*
|
|
458
|
+
yield* function*(arbitraryPropertyRule) {
|
|
372
459
|
if (arbitraryPropertyRule !== null) {
|
|
373
460
|
yield [
|
|
374
461
|
arbitraryPropertyRule,
|
|
375
|
-
|
|
462
|
+
"DEFAULT"
|
|
376
463
|
];
|
|
377
464
|
}
|
|
378
|
-
}
|
|
465
|
+
}(extractArbitraryProperty(classCandidate, context));
|
|
379
466
|
let candidatePrefix = classCandidate;
|
|
380
467
|
let negative = false;
|
|
381
468
|
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
382
469
|
const twConfigPrefixLen = twConfigPrefix.length;
|
|
383
|
-
|
|
470
|
+
const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
|
|
471
|
+
if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
|
|
384
472
|
negative = true;
|
|
385
473
|
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
386
474
|
}
|
|
387
475
|
if (negative && context.candidateRuleMap.has(candidatePrefix)) {
|
|
388
476
|
yield [
|
|
389
477
|
context.candidateRuleMap.get(candidatePrefix),
|
|
390
|
-
|
|
478
|
+
"-DEFAULT"
|
|
391
479
|
];
|
|
392
480
|
}
|
|
393
481
|
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
|
|
@@ -400,30 +488,41 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
400
488
|
}
|
|
401
489
|
}
|
|
402
490
|
function splitWithSeparator(input, separator) {
|
|
403
|
-
if (input ===
|
|
491
|
+
if (input === _sharedState.NOT_ON_DEMAND) {
|
|
404
492
|
return [
|
|
405
|
-
|
|
493
|
+
_sharedState.NOT_ON_DEMAND
|
|
406
494
|
];
|
|
407
495
|
}
|
|
408
|
-
return
|
|
496
|
+
return Array.from((0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(input, separator));
|
|
409
497
|
}
|
|
410
498
|
function* recordCandidates(matches, classCandidate) {
|
|
411
499
|
for (const match of matches){
|
|
500
|
+
var ref;
|
|
501
|
+
var ref1;
|
|
412
502
|
match[1].raws.tailwind = {
|
|
413
503
|
...match[1].raws.tailwind,
|
|
414
|
-
classCandidate
|
|
504
|
+
classCandidate,
|
|
505
|
+
preserveSource: (ref1 = (ref = match[0].options) === null || ref === void 0 ? void 0 : ref.preserveSource) !== null && ref1 !== void 0 ? ref1 : false
|
|
415
506
|
};
|
|
416
507
|
yield match;
|
|
417
508
|
}
|
|
418
509
|
}
|
|
419
|
-
function* resolveMatches(candidate, context) {
|
|
510
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
420
511
|
let separator = context.tailwindConfig.separator;
|
|
421
512
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
422
513
|
let important = false;
|
|
423
|
-
if (classCandidate.startsWith(
|
|
514
|
+
if (classCandidate.startsWith("!")) {
|
|
424
515
|
important = true;
|
|
425
516
|
classCandidate = classCandidate.slice(1);
|
|
426
517
|
}
|
|
518
|
+
if ((0, _featureFlags.flagEnabled)(context.tailwindConfig, "variantGrouping")) {
|
|
519
|
+
if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
|
|
520
|
+
let base = variants.slice().reverse().join(separator);
|
|
521
|
+
for (let part of (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(classCandidate.slice(1, -1), ",")){
|
|
522
|
+
yield* resolveMatches(base + separator + part, context, original);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
427
526
|
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
428
527
|
// function sortAgainst(toSort, against) {
|
|
429
528
|
// return toSort.slice().sort((a, z) => {
|
|
@@ -442,7 +541,7 @@ function* resolveMatches(candidate, context) {
|
|
|
442
541
|
let isOnlyPlugin = plugins.length === 1;
|
|
443
542
|
for (let [sort, plugin] of plugins){
|
|
444
543
|
let matchesPerPlugin = [];
|
|
445
|
-
if (typeof plugin ===
|
|
544
|
+
if (typeof plugin === "function") {
|
|
446
545
|
for (let ruleSet of [].concat(plugin(modifier, {
|
|
447
546
|
isOnlyPlugin
|
|
448
547
|
}))){
|
|
@@ -460,19 +559,19 @@ function* resolveMatches(candidate, context) {
|
|
|
460
559
|
]);
|
|
461
560
|
}
|
|
462
561
|
}
|
|
463
|
-
} else if (modifier ===
|
|
464
|
-
let
|
|
465
|
-
let [
|
|
466
|
-
for (let
|
|
562
|
+
} else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
|
|
563
|
+
let ruleSet1 = plugin;
|
|
564
|
+
let [rules1, options1] = parseRules(ruleSet1, context.postCssNodeCache);
|
|
565
|
+
for (let rule1 of rules1){
|
|
467
566
|
matchesPerPlugin.push([
|
|
468
567
|
{
|
|
469
568
|
...sort,
|
|
470
569
|
options: {
|
|
471
570
|
...sort.options,
|
|
472
|
-
...
|
|
571
|
+
...options1
|
|
473
572
|
}
|
|
474
573
|
},
|
|
475
|
-
|
|
574
|
+
rule1
|
|
476
575
|
]);
|
|
477
576
|
}
|
|
478
577
|
}
|
|
@@ -482,48 +581,46 @@ function* resolveMatches(candidate, context) {
|
|
|
482
581
|
matches.push(matchesPerPlugin);
|
|
483
582
|
}
|
|
484
583
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
584
|
+
if (isArbitraryValue(modifier)) {
|
|
585
|
+
// When generated arbitrary values are ambiguous, we can't know
|
|
586
|
+
// which to pick so don't generate any utilities for them
|
|
587
|
+
if (matches.length > 1) {
|
|
588
|
+
var ref1;
|
|
589
|
+
let typesPerPlugin = matches.map((match)=>new Set([
|
|
590
|
+
...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
|
|
591
|
+
]));
|
|
592
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
593
|
+
for (let pluginTypes of typesPerPlugin){
|
|
594
|
+
for (let type of pluginTypes){
|
|
595
|
+
let removeFromOwnGroup = false;
|
|
596
|
+
for (let otherGroup of typesPerPlugin){
|
|
597
|
+
if (pluginTypes === otherGroup) continue;
|
|
598
|
+
if (otherGroup.has(type)) {
|
|
599
|
+
otherGroup.delete(type);
|
|
600
|
+
removeFromOwnGroup = true;
|
|
601
|
+
}
|
|
502
602
|
}
|
|
603
|
+
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
503
604
|
}
|
|
504
|
-
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
505
605
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
.
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
.join('\n')
|
|
516
|
-
).join('\n\n');
|
|
517
|
-
messages.push(` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
518
|
-
break;
|
|
606
|
+
let messages = [];
|
|
607
|
+
for (let [idx, group] of typesPerPlugin.entries()){
|
|
608
|
+
for (let type1 of group){
|
|
609
|
+
let rules2 = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
|
|
610
|
+
.map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
|
|
611
|
+
.join("\n")).join("\n\n");
|
|
612
|
+
messages.push(` Use \`${candidate.replace("[", `[${type1}:`)}\` for \`${rules2.trim()}\``);
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
519
615
|
}
|
|
616
|
+
_log.default.warn([
|
|
617
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
618
|
+
...messages,
|
|
619
|
+
`If this is content and not a class, replace it with \`${candidate.replace("[", "[").replace("]", "]")}\` to silence this warning.`,
|
|
620
|
+
]);
|
|
621
|
+
continue;
|
|
520
622
|
}
|
|
521
|
-
|
|
522
|
-
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
523
|
-
...messages,
|
|
524
|
-
`If this is content and not a class, replace it with \`${candidate.replace('[', '[').replace(']', ']')}\` to silence this warning.`,
|
|
525
|
-
]);
|
|
526
|
-
continue;
|
|
623
|
+
matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
|
|
527
624
|
}
|
|
528
625
|
matches = matches.flat();
|
|
529
626
|
matches = Array.from(recordCandidates(matches, classCandidate));
|
|
@@ -534,35 +631,39 @@ function* resolveMatches(candidate, context) {
|
|
|
534
631
|
for (let variant of variants){
|
|
535
632
|
matches = applyVariant(variant, matches, context);
|
|
536
633
|
}
|
|
537
|
-
for (let
|
|
538
|
-
|
|
539
|
-
...
|
|
634
|
+
for (let match of matches){
|
|
635
|
+
match[1].raws.tailwind = {
|
|
636
|
+
...match[1].raws.tailwind,
|
|
540
637
|
candidate
|
|
541
638
|
};
|
|
542
639
|
// Apply final format selector
|
|
543
|
-
if (
|
|
544
|
-
let finalFormat = (0, _formatVariantSelector
|
|
640
|
+
if (match[0].collectedFormats) {
|
|
641
|
+
let finalFormat = (0, _formatVariantSelector.formatVariantSelector)("&", ...match[0].collectedFormats);
|
|
545
642
|
let container = _postcss.default.root({
|
|
546
643
|
nodes: [
|
|
547
|
-
|
|
644
|
+
match[1].clone()
|
|
548
645
|
]
|
|
549
646
|
});
|
|
550
647
|
container.walkRules((rule)=>{
|
|
648
|
+
var ref;
|
|
551
649
|
if (inKeyframes(rule)) return;
|
|
552
|
-
|
|
650
|
+
var ref1;
|
|
651
|
+
rule.selector = (0, _formatVariantSelector.finalizeSelector)(finalFormat, {
|
|
553
652
|
selector: rule.selector,
|
|
554
|
-
candidate,
|
|
653
|
+
candidate: original,
|
|
654
|
+
base: candidate.split(new RegExp(`\\${(ref1 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref1 !== void 0 ? ref1 : ":"}(?![^[]*\\])`)).pop(),
|
|
655
|
+
isArbitraryVariant: match[0].isArbitraryVariant,
|
|
555
656
|
context
|
|
556
657
|
});
|
|
557
658
|
});
|
|
558
|
-
|
|
659
|
+
match[1] = container.nodes[0];
|
|
559
660
|
}
|
|
560
|
-
yield
|
|
661
|
+
yield match;
|
|
561
662
|
}
|
|
562
663
|
}
|
|
563
664
|
}
|
|
564
665
|
function inKeyframes(rule) {
|
|
565
|
-
return rule.parent && rule.parent.type ===
|
|
666
|
+
return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
|
|
566
667
|
}
|
|
567
668
|
function generateRules(candidates, context) {
|
|
568
669
|
let allRules = [];
|
|
@@ -587,13 +688,13 @@ function generateRules(candidates, context) {
|
|
|
587
688
|
if (important === true) {
|
|
588
689
|
return (rule)=>{
|
|
589
690
|
rule.walkDecls((d)=>{
|
|
590
|
-
if (d.parent.type ===
|
|
691
|
+
if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
|
|
591
692
|
d.important = true;
|
|
592
693
|
}
|
|
593
694
|
});
|
|
594
695
|
};
|
|
595
696
|
}
|
|
596
|
-
if (typeof important ===
|
|
697
|
+
if (typeof important === "string") {
|
|
597
698
|
return (rule)=>{
|
|
598
699
|
rule.selectors = rule.selectors.map((selector)=>{
|
|
599
700
|
return `${important} ${selector}`;
|
|
@@ -625,7 +726,5 @@ function generateRules(candidates, context) {
|
|
|
625
726
|
});
|
|
626
727
|
}
|
|
627
728
|
function isArbitraryValue(input) {
|
|
628
|
-
return input.startsWith(
|
|
729
|
+
return input.startsWith("[") && input.endsWith("]");
|
|
629
730
|
}
|
|
630
|
-
exports.resolveMatches = resolveMatches;
|
|
631
|
-
exports.generateRules = generateRules;
|