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
|
@@ -2,32 +2,50 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>expandApplyAtRules
|
|
8
|
+
});
|
|
9
|
+
const _postcss = /*#__PURE__*/ _interopRequireDefault(require("postcss"));
|
|
10
|
+
const _postcssSelectorParser = /*#__PURE__*/ _interopRequireDefault(require("postcss-selector-parser"));
|
|
11
|
+
const _generateRules = require("./generateRules");
|
|
12
|
+
const _bigSign = /*#__PURE__*/ _interopRequireDefault(require("../util/bigSign"));
|
|
13
|
+
const _escapeClassName = /*#__PURE__*/ _interopRequireDefault(require("../util/escapeClassName"));
|
|
11
14
|
function _interopRequireDefault(obj) {
|
|
12
15
|
return obj && obj.__esModule ? obj : {
|
|
13
16
|
default: obj
|
|
14
17
|
};
|
|
15
18
|
}
|
|
16
19
|
/** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
|
|
17
|
-
let
|
|
20
|
+
/** @type {Map<string, Set<string>>} */ let groups = new Map();
|
|
18
21
|
let container = _postcss.default.root({
|
|
19
22
|
nodes: [
|
|
20
23
|
node.clone()
|
|
21
24
|
]
|
|
22
25
|
});
|
|
23
26
|
container.walkRules((rule)=>{
|
|
24
|
-
(0, _postcssSelectorParser
|
|
27
|
+
(0, _postcssSelectorParser.default)((selectors)=>{
|
|
25
28
|
selectors.walkClasses((classSelector)=>{
|
|
29
|
+
let parentSelector = classSelector.parent.toString();
|
|
30
|
+
let classes = groups.get(parentSelector);
|
|
31
|
+
if (!classes) {
|
|
32
|
+
groups.set(parentSelector, classes = new Set());
|
|
33
|
+
}
|
|
26
34
|
classes.add(classSelector.value);
|
|
27
35
|
});
|
|
28
36
|
}).processSync(rule.selector);
|
|
29
37
|
});
|
|
30
|
-
|
|
38
|
+
let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
|
|
39
|
+
let classes = normalizedGroups.flat();
|
|
40
|
+
return Object.assign(classes, {
|
|
41
|
+
groups: normalizedGroups
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
let selectorExtractor = (0, _postcssSelectorParser.default)((root)=>root.nodes.map((node)=>node.toString()));
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} ruleSelectors
|
|
47
|
+
*/ function extractSelectors(ruleSelectors) {
|
|
48
|
+
return selectorExtractor.transformSync(ruleSelectors);
|
|
31
49
|
}
|
|
32
50
|
function extractBaseCandidates(candidates, separator) {
|
|
33
51
|
let baseClasses = new Set();
|
|
@@ -37,8 +55,8 @@ function extractBaseCandidates(candidates, separator) {
|
|
|
37
55
|
return Array.from(baseClasses);
|
|
38
56
|
}
|
|
39
57
|
function prefix(context, selector) {
|
|
40
|
-
let
|
|
41
|
-
return typeof
|
|
58
|
+
let prefix = context.tailwindConfig.prefix;
|
|
59
|
+
return typeof prefix === "function" ? prefix(selector) : prefix + selector;
|
|
42
60
|
}
|
|
43
61
|
function* pathToRoot(node) {
|
|
44
62
|
yield node;
|
|
@@ -104,7 +122,7 @@ function* pathToRoot(node) {
|
|
|
104
122
|
if (node === parent) {
|
|
105
123
|
continue;
|
|
106
124
|
}
|
|
107
|
-
if (parent.type ===
|
|
125
|
+
if (parent.type === "root") {
|
|
108
126
|
break;
|
|
109
127
|
}
|
|
110
128
|
node = shallowClone(parent, {
|
|
@@ -135,7 +153,7 @@ function* pathToRoot(node) {
|
|
|
135
153
|
cache.set(className, list);
|
|
136
154
|
list.push([
|
|
137
155
|
{
|
|
138
|
-
layer:
|
|
156
|
+
layer: "user",
|
|
139
157
|
sort: BigInt(idx) + highestOffset,
|
|
140
158
|
important: false
|
|
141
159
|
},
|
|
@@ -156,11 +174,10 @@ function* pathToRoot(node) {
|
|
|
156
174
|
context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
|
|
157
175
|
meta,
|
|
158
176
|
rule.clone()
|
|
159
|
-
]
|
|
160
|
-
));
|
|
177
|
+
]));
|
|
161
178
|
continue;
|
|
162
179
|
}
|
|
163
|
-
let matches = Array.from((0, _generateRules
|
|
180
|
+
let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
|
|
164
181
|
if (matches.length === 0) {
|
|
165
182
|
context.notClassCache.add(candidate);
|
|
166
183
|
continue;
|
|
@@ -195,16 +212,13 @@ function* pathToRoot(node) {
|
|
|
195
212
|
* @returns {ApplyCache}
|
|
196
213
|
*/ function combineCaches(caches) {
|
|
197
214
|
return {
|
|
198
|
-
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
|
|
199
|
-
|
|
200
|
-
,
|
|
201
|
-
has: (name)=>caches.some((cache)=>cache.has(name)
|
|
202
|
-
)
|
|
215
|
+
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
|
|
216
|
+
has: (name)=>caches.some((cache)=>cache.has(name))
|
|
203
217
|
};
|
|
204
218
|
}
|
|
205
219
|
function extractApplyCandidates(params) {
|
|
206
220
|
let candidates = params.split(/[\s\t\n]+/g);
|
|
207
|
-
if (candidates[candidates.length - 1] ===
|
|
221
|
+
if (candidates[candidates.length - 1] === "!important") {
|
|
208
222
|
return [
|
|
209
223
|
candidates.slice(0, -1),
|
|
210
224
|
true
|
|
@@ -219,7 +233,7 @@ function processApply(root, context, localCache) {
|
|
|
219
233
|
let applyCandidates = new Set();
|
|
220
234
|
// Collect all @apply rules and candidates
|
|
221
235
|
let applies = [];
|
|
222
|
-
root.walkAtRules(
|
|
236
|
+
root.walkAtRules("apply", (rule)=>{
|
|
223
237
|
let [candidates] = extractApplyCandidates(rule.params);
|
|
224
238
|
for (let util of candidates){
|
|
225
239
|
applyCandidates.add(util);
|
|
@@ -227,207 +241,238 @@ function processApply(root, context, localCache) {
|
|
|
227
241
|
applies.push(rule);
|
|
228
242
|
});
|
|
229
243
|
// Start the @apply process if we have rules with @apply in them
|
|
230
|
-
if (applies.length
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
244
|
+
if (applies.length === 0) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// Fill up some caches!
|
|
248
|
+
let applyClassCache = combineCaches([
|
|
249
|
+
localCache,
|
|
250
|
+
buildApplyCache(applyCandidates, context)
|
|
251
|
+
]);
|
|
252
|
+
/**
|
|
253
|
+
* When we have an apply like this:
|
|
254
|
+
*
|
|
255
|
+
* .abc {
|
|
256
|
+
* @apply hover:font-bold;
|
|
257
|
+
* }
|
|
258
|
+
*
|
|
259
|
+
* What we essentially will do is resolve to this:
|
|
260
|
+
*
|
|
261
|
+
* .abc {
|
|
262
|
+
* @apply .hover\:font-bold:hover {
|
|
263
|
+
* font-weight: 500;
|
|
264
|
+
* }
|
|
265
|
+
* }
|
|
266
|
+
*
|
|
267
|
+
* Notice that the to-be-applied class is `.hover\:font-bold:hover` and that the utility candidate was `hover:font-bold`.
|
|
268
|
+
* What happens in this function is that we prepend a `.` and escape the candidate.
|
|
269
|
+
* This will result in `.hover\:font-bold`
|
|
270
|
+
* Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
|
|
271
|
+
*/ // TODO: Should we use postcss-selector-parser for this instead?
|
|
272
|
+
function replaceSelector(selector, utilitySelectors, candidate) {
|
|
273
|
+
let needle = `.${(0, _escapeClassName.default)(candidate)}`;
|
|
274
|
+
let needles = [
|
|
275
|
+
...new Set([
|
|
276
|
+
needle,
|
|
277
|
+
needle.replace(/\\2c /g, "\\,")
|
|
278
|
+
])
|
|
279
|
+
];
|
|
280
|
+
let utilitySelectorsList = extractSelectors(utilitySelectors);
|
|
281
|
+
return extractSelectors(selector).map((s)=>{
|
|
282
|
+
let replaced = [];
|
|
283
|
+
for (let utilitySelector of utilitySelectorsList){
|
|
284
|
+
let replacedSelector = utilitySelector;
|
|
285
|
+
for (const needle of needles){
|
|
286
|
+
replacedSelector = replacedSelector.replace(needle, s);
|
|
267
287
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
let perParentApplies = new Map();
|
|
272
|
-
// Collect all apply candidates and their rules
|
|
273
|
-
for (let apply of applies){
|
|
274
|
-
let candidates = perParentApplies.get(apply.parent) || [];
|
|
275
|
-
perParentApplies.set(apply.parent, [
|
|
276
|
-
candidates,
|
|
277
|
-
apply.source
|
|
278
|
-
]);
|
|
279
|
-
let [applyCandidates, important] = extractApplyCandidates(apply.params);
|
|
280
|
-
if (apply.parent.type === 'atrule') {
|
|
281
|
-
if (apply.parent.name === 'screen') {
|
|
282
|
-
const screenType = apply.parent.params;
|
|
283
|
-
throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates.map((c)=>`${screenType}:${c}`
|
|
284
|
-
).join(' ')} instead.`);
|
|
288
|
+
if (replacedSelector === utilitySelector) {
|
|
289
|
+
continue;
|
|
285
290
|
}
|
|
286
|
-
|
|
291
|
+
replaced.push(replacedSelector);
|
|
287
292
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
293
|
+
return replaced.join(", ");
|
|
294
|
+
}).join(", ");
|
|
295
|
+
}
|
|
296
|
+
let perParentApplies = new Map();
|
|
297
|
+
// Collect all apply candidates and their rules
|
|
298
|
+
for (let apply of applies){
|
|
299
|
+
let [candidates] = perParentApplies.get(apply.parent) || [
|
|
300
|
+
[],
|
|
301
|
+
apply.source
|
|
302
|
+
];
|
|
303
|
+
perParentApplies.set(apply.parent, [
|
|
304
|
+
candidates,
|
|
305
|
+
apply.source
|
|
306
|
+
]);
|
|
307
|
+
let [applyCandidates1, important] = extractApplyCandidates(apply.params);
|
|
308
|
+
if (apply.parent.type === "atrule") {
|
|
309
|
+
if (apply.parent.name === "screen") {
|
|
310
|
+
const screenType = apply.parent.params;
|
|
311
|
+
throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates1.map((c)=>`${screenType}:${c}`).join(" ")} instead.`);
|
|
305
312
|
}
|
|
313
|
+
throw apply.error(`@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`);
|
|
306
314
|
}
|
|
307
|
-
for (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
315
|
+
for (let applyCandidate of applyCandidates1){
|
|
316
|
+
if ([
|
|
317
|
+
prefix(context, "group"),
|
|
318
|
+
prefix(context, "peer")
|
|
319
|
+
].includes(applyCandidate)) {
|
|
320
|
+
// TODO: Link to specific documentation page with error code.
|
|
321
|
+
throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
|
|
322
|
+
}
|
|
323
|
+
if (!applyClassCache.has(applyCandidate)) {
|
|
324
|
+
throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
|
|
325
|
+
}
|
|
326
|
+
let rules = applyClassCache.get(applyCandidate);
|
|
327
|
+
candidates.push([
|
|
328
|
+
applyCandidate,
|
|
329
|
+
important,
|
|
330
|
+
rules
|
|
331
|
+
]);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
for (const [parent, [candidates1, atApplySource]] of perParentApplies){
|
|
335
|
+
let siblings = [];
|
|
336
|
+
for (let [applyCandidate1, important1, rules1] of candidates1){
|
|
337
|
+
let potentialApplyCandidates = [
|
|
338
|
+
applyCandidate1,
|
|
339
|
+
...extractBaseCandidates([
|
|
340
|
+
applyCandidate1
|
|
341
|
+
], context.tailwindConfig.separator),
|
|
342
|
+
];
|
|
343
|
+
for (let [meta, node] of rules1){
|
|
344
|
+
let parentClasses = extractClasses(parent);
|
|
345
|
+
let nodeClasses = extractClasses(node);
|
|
346
|
+
// When we encounter a rule like `.dark .a, .b { … }` we only want to be left with `[.dark, .a]` if the base applyCandidate is `.a` or with `[.b]` if the base applyCandidate is `.b`
|
|
347
|
+
// So we've split them into groups
|
|
348
|
+
nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
|
|
349
|
+
// Add base utility classes from the @apply node to the list of
|
|
350
|
+
// classes to check whether it intersects and therefore results in a
|
|
351
|
+
// circular dependency or not.
|
|
352
|
+
//
|
|
353
|
+
// E.g.:
|
|
354
|
+
// .foo {
|
|
355
|
+
// @apply hover:a; // This applies "a" but with a modifier
|
|
356
|
+
// }
|
|
357
|
+
//
|
|
358
|
+
// We only have to do that with base classes of the `node`, not of the `parent`
|
|
359
|
+
// E.g.:
|
|
360
|
+
// .hover\:foo {
|
|
361
|
+
// @apply bar;
|
|
362
|
+
// }
|
|
363
|
+
// .bar {
|
|
364
|
+
// @apply foo;
|
|
365
|
+
// }
|
|
366
|
+
//
|
|
367
|
+
// This should not result in a circular dependency because we are
|
|
368
|
+
// just applying `.foo` and the rule above is `.hover\:foo` which is
|
|
369
|
+
// unrelated. However, if we were to apply `hover:foo` then we _did_
|
|
370
|
+
// have to include this one.
|
|
371
|
+
nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
|
|
372
|
+
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
|
|
373
|
+
if (intersects) {
|
|
374
|
+
throw node.error(`You cannot \`@apply\` the \`${applyCandidate1}\` utility here because it creates a circular dependency.`);
|
|
375
|
+
}
|
|
376
|
+
let root1 = _postcss.default.root({
|
|
377
|
+
nodes: [
|
|
378
|
+
node.clone()
|
|
379
|
+
]
|
|
380
|
+
});
|
|
381
|
+
// Make sure every node in the entire tree points back at the @apply rule that generated it
|
|
382
|
+
root1.walk((node)=>{
|
|
383
|
+
node.source = atApplySource;
|
|
384
|
+
});
|
|
385
|
+
let canRewriteSelector = node.type !== "atrule" || node.type === "atrule" && node.name !== "keyframes";
|
|
386
|
+
if (canRewriteSelector) {
|
|
387
|
+
root1.walkRules((rule)=>{
|
|
388
|
+
// Let's imagine you have the following structure:
|
|
389
|
+
//
|
|
390
|
+
// .foo {
|
|
391
|
+
// @apply bar;
|
|
392
|
+
// }
|
|
393
|
+
//
|
|
394
|
+
// @supports (a: b) {
|
|
395
|
+
// .bar {
|
|
396
|
+
// color: blue
|
|
397
|
+
// }
|
|
398
|
+
//
|
|
399
|
+
// .something-unrelated {}
|
|
400
|
+
// }
|
|
401
|
+
//
|
|
402
|
+
// In this case we want to apply `.bar` but it happens to be in
|
|
403
|
+
// an atrule node. We clone that node instead of the nested one
|
|
404
|
+
// because we still want that @supports rule to be there once we
|
|
405
|
+
// applied everything.
|
|
406
|
+
//
|
|
407
|
+
// However it happens to be that the `.something-unrelated` is
|
|
408
|
+
// also in that same shared @supports atrule. This is not good,
|
|
409
|
+
// and this should not be there. The good part is that this is
|
|
410
|
+
// a clone already and it can be safely removed. The question is
|
|
411
|
+
// how do we know we can remove it. Basically what we can do is
|
|
412
|
+
// match it against the applyCandidate that you want to apply. If
|
|
413
|
+
// it doesn't match the we can safely delete it.
|
|
414
|
+
//
|
|
415
|
+
// If we didn't do this, then the `replaceSelector` function
|
|
416
|
+
// would have replaced this with something that didn't exist and
|
|
417
|
+
// therefore it removed the selector altogether. In this specific
|
|
418
|
+
// case it would result in `{}` instead of `.something-unrelated {}`
|
|
419
|
+
if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate1)) {
|
|
420
|
+
rule.remove();
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
// Strip the important selector from the parent selector if at the beginning
|
|
424
|
+
let importantSelector = typeof context.tailwindConfig.important === "string" ? context.tailwindConfig.important : null;
|
|
425
|
+
// We only want to move the "important" selector if this is a Tailwind-generated utility
|
|
426
|
+
// We do *not* want to do this for user CSS that happens to be structured the same
|
|
427
|
+
let isGenerated = parent.raws.tailwind !== undefined;
|
|
428
|
+
let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
|
|
429
|
+
rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate1);
|
|
430
|
+
// And then re-add it if it was removed
|
|
431
|
+
if (importantSelector && parentSelector !== parent.selector) {
|
|
432
|
+
rule.selector = `${importantSelector} ${rule.selector}`;
|
|
433
|
+
}
|
|
434
|
+
rule.walkDecls((d)=>{
|
|
435
|
+
d.important = meta.important || important1;
|
|
393
436
|
});
|
|
394
|
-
}
|
|
395
|
-
// Insert it
|
|
396
|
-
siblings.push([
|
|
397
|
-
// Ensure that when we are sorting, that we take the layer order into account
|
|
398
|
-
{
|
|
399
|
-
...meta,
|
|
400
|
-
sort: meta.sort | context.layerOrder[meta.layer]
|
|
401
|
-
},
|
|
402
|
-
root.nodes[0],
|
|
403
|
-
]);
|
|
437
|
+
});
|
|
404
438
|
}
|
|
439
|
+
// It could be that the node we were inserted was removed because the class didn't match
|
|
440
|
+
// If that was the *only* rule in the parent, then we have nothing add so we skip it
|
|
441
|
+
if (!root1.nodes[0]) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
// Insert it
|
|
445
|
+
siblings.push([
|
|
446
|
+
// Ensure that when we are sorting, that we take the layer order into account
|
|
447
|
+
{
|
|
448
|
+
...meta,
|
|
449
|
+
sort: meta.sort | context.layerOrder[meta.layer]
|
|
450
|
+
},
|
|
451
|
+
root1.nodes[0],
|
|
452
|
+
]);
|
|
405
453
|
}
|
|
406
|
-
// Inject the rules, sorted, correctly
|
|
407
|
-
let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)
|
|
408
|
-
).map((s)=>s[1]
|
|
409
|
-
);
|
|
410
|
-
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
411
|
-
parent.after(nodes);
|
|
412
454
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
455
|
+
// Inject the rules, sorted, correctly
|
|
456
|
+
let nodes = siblings.sort(([a], [z])=>(0, _bigSign.default)(a.sort - z.sort)).map((s)=>s[1]);
|
|
457
|
+
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
458
|
+
parent.after(nodes);
|
|
459
|
+
}
|
|
460
|
+
for (let apply1 of applies){
|
|
461
|
+
// If there are left-over declarations, just remove the @apply
|
|
462
|
+
if (apply1.parent.nodes.length > 1) {
|
|
463
|
+
apply1.remove();
|
|
464
|
+
} else {
|
|
465
|
+
// The node is empty, drop the full node
|
|
466
|
+
apply1.parent.remove();
|
|
421
467
|
}
|
|
422
|
-
// Do it again, in case we have other `@apply` rules
|
|
423
|
-
processApply(root, context, localCache);
|
|
424
468
|
}
|
|
469
|
+
// Do it again, in case we have other `@apply` rules
|
|
470
|
+
processApply(root, context, localCache);
|
|
425
471
|
}
|
|
426
472
|
function expandApplyAtRules(context) {
|
|
427
473
|
return (root)=>{
|
|
428
474
|
// Build a cache of the user's CSS so we can use it to resolve classes used by @apply
|
|
429
|
-
let localCache = lazyCache(()=>buildLocalApplyCache(root, context)
|
|
430
|
-
);
|
|
475
|
+
let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
|
|
431
476
|
processApply(root, context, localCache);
|
|
432
477
|
};
|
|
433
478
|
}
|