tailwindcss 0.0.0-insiders.89bf2ed → 0.0.0-insiders.8a2f9ed
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 +204 -6
- package/README.md +12 -8
- package/defaultTheme.d.ts +2 -1
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +44 -0
- package/lib/cli/build/plugin.js +351 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +175 -0
- package/lib/cli/help/index.js +71 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/init/index.js +46 -0
- package/lib/cli/shared.js +12 -0
- package/lib/cli-peer-dependencies.js +18 -5
- package/lib/cli.js +44 -576
- package/lib/constants.js +19 -12
- package/lib/corePluginList.js +5 -3
- package/lib/corePlugins.js +609 -344
- package/lib/css/preflight.css +3 -4
- package/lib/featureFlags.js +27 -15
- package/lib/index.js +16 -9
- package/lib/lib/cacheInvalidation.js +42 -21
- package/lib/lib/collapseAdjacentRules.js +15 -13
- package/lib/lib/collapseDuplicateDeclarations.js +11 -8
- package/lib/lib/content.js +177 -0
- package/lib/lib/defaultExtractor.js +225 -33
- package/lib/lib/detectNesting.js +6 -3
- package/lib/lib/evaluateTailwindFunctions.js +105 -42
- package/lib/lib/expandApplyAtRules.js +162 -82
- package/lib/lib/expandTailwindAtRules.js +130 -145
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +337 -167
- package/lib/lib/getModuleDependencies.js +21 -18
- package/lib/lib/normalizeTailwindDirectives.js +11 -8
- package/lib/lib/offsets.js +217 -0
- package/lib/lib/partitionApplyAtRules.js +14 -11
- package/lib/lib/regex.js +60 -0
- package/lib/lib/resolveDefaultsAtRules.js +97 -79
- package/lib/lib/setupContextUtils.js +551 -230
- package/lib/lib/setupTrackingContext.js +77 -106
- package/lib/lib/sharedState.js +18 -10
- package/lib/lib/substituteScreenAtRules.js +9 -7
- package/lib/postcss-plugins/nesting/index.js +7 -5
- package/lib/postcss-plugins/nesting/plugin.js +8 -6
- package/lib/processTailwindFeatures.js +34 -31
- package/lib/public/colors.js +7 -5
- 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 +13 -10
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +10 -5
- package/lib/util/cloneDeep.js +6 -5
- package/lib/util/cloneNodes.js +9 -2
- package/lib/util/color.js +37 -39
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -5
- package/lib/util/createUtilityPlugin.js +14 -12
- package/lib/util/dataTypes.js +49 -50
- package/lib/util/defaults.js +4 -1
- package/lib/util/escapeClassName.js +12 -9
- package/lib/util/escapeCommas.js +4 -1
- package/lib/util/flattenColorPalette.js +7 -8
- package/lib/util/formatVariantSelector.js +166 -67
- package/lib/util/getAllConfigs.js +32 -13
- package/lib/util/hashConfig.js +10 -7
- package/lib/util/isKeyframeRule.js +4 -1
- package/lib/util/isPlainObject.js +4 -1
- package/lib/util/isValidArbitraryValue.js +33 -25
- package/lib/util/log.js +14 -8
- package/lib/util/nameClass.js +19 -8
- package/lib/util/negateValue.js +20 -5
- package/lib/util/normalizeConfig.js +68 -41
- package/lib/util/normalizeScreens.js +115 -4
- package/lib/util/parseAnimationValue.js +43 -41
- package/lib/util/parseBoxShadowValue.js +12 -45
- package/lib/util/parseDependency.js +37 -55
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +15 -12
- package/lib/util/pluginUtils.js +136 -37
- package/lib/util/prefixSelector.js +6 -3
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +104 -103
- package/lib/util/resolveConfigPath.js +20 -17
- package/lib/util/responsive.js +12 -9
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +4 -1
- package/lib/util/toColorValue.js +4 -1
- package/lib/util/toPath.js +18 -2
- package/lib/util/transformThemeValue.js +23 -11
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +32 -24
- package/package.json +25 -22
- package/peers/index.js +6664 -3011
- package/plugin.d.ts +10 -5
- package/resolveConfig.d.ts +3 -0
- package/scripts/generate-types.js +53 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/deps.js +56 -0
- package/src/cli/build/index.js +45 -0
- package/src/cli/build/plugin.js +417 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +224 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +3 -0
- package/src/cli/init/index.js +50 -0
- package/src/cli/shared.js +5 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +22 -637
- package/src/corePlugins.js +336 -78
- package/src/css/preflight.css +3 -4
- package/src/featureFlags.js +12 -2
- package/src/index.js +5 -0
- package/src/lib/content.js +213 -0
- package/src/lib/defaultExtractor.js +196 -35
- package/src/lib/evaluateTailwindFunctions.js +78 -7
- package/src/lib/expandApplyAtRules.js +156 -36
- package/src/lib/expandTailwindAtRules.js +12 -50
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +308 -109
- package/src/lib/offsets.js +270 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -36
- package/src/lib/setupContextUtils.js +493 -115
- package/src/lib/setupTrackingContext.js +8 -45
- package/src/lib/sharedState.js +2 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +5 -1
- package/src/util/color.js +20 -18
- package/src/util/dataTypes.js +19 -23
- package/src/util/formatVariantSelector.js +184 -61
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/log.js +1 -1
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +10 -2
- package/src/util/normalizeConfig.js +22 -10
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +125 -14
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -60
- package/src/util/splitAtTopLevelOnly.js +45 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +13 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/stubs/defaultConfig.stub.js +20 -2
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +74 -35
- package/types/generated/default-theme.d.ts +342 -0
- package/types/index.d.ts +7 -1
- package/types.d.ts +0 -1
|
@@ -2,40 +2,49 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// Build a cache of the user's CSS so we can use it to resolve classes used by @apply
|
|
14
|
-
let localCache = lazyCache(()=>buildLocalApplyCache(root, context)
|
|
15
|
-
);
|
|
16
|
-
processApply(root, context, localCache);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
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 _escapeClassName = /*#__PURE__*/ _interopRequireDefault(require("../util/escapeClassName"));
|
|
19
13
|
function _interopRequireDefault(obj) {
|
|
20
14
|
return obj && obj.__esModule ? obj : {
|
|
21
15
|
default: obj
|
|
22
16
|
};
|
|
23
17
|
}
|
|
24
18
|
/** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
|
|
25
|
-
let
|
|
19
|
+
/** @type {Map<string, Set<string>>} */ let groups = new Map();
|
|
26
20
|
let container = _postcss.default.root({
|
|
27
21
|
nodes: [
|
|
28
22
|
node.clone()
|
|
29
23
|
]
|
|
30
24
|
});
|
|
31
25
|
container.walkRules((rule)=>{
|
|
32
|
-
(0, _postcssSelectorParser
|
|
26
|
+
(0, _postcssSelectorParser.default)((selectors)=>{
|
|
33
27
|
selectors.walkClasses((classSelector)=>{
|
|
28
|
+
let parentSelector = classSelector.parent.toString();
|
|
29
|
+
let classes = groups.get(parentSelector);
|
|
30
|
+
if (!classes) {
|
|
31
|
+
groups.set(parentSelector, classes = new Set());
|
|
32
|
+
}
|
|
34
33
|
classes.add(classSelector.value);
|
|
35
34
|
});
|
|
36
35
|
}).processSync(rule.selector);
|
|
37
36
|
});
|
|
38
|
-
|
|
37
|
+
let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
|
|
38
|
+
let classes = normalizedGroups.flat();
|
|
39
|
+
return Object.assign(classes, {
|
|
40
|
+
groups: normalizedGroups
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
let selectorExtractor = (0, _postcssSelectorParser.default)();
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} ruleSelectors
|
|
46
|
+
*/ function extractSelectors(ruleSelectors) {
|
|
47
|
+
return selectorExtractor.astSync(ruleSelectors);
|
|
39
48
|
}
|
|
40
49
|
function extractBaseCandidates(candidates, separator) {
|
|
41
50
|
let baseClasses = new Set();
|
|
@@ -45,8 +54,8 @@ function extractBaseCandidates(candidates, separator) {
|
|
|
45
54
|
return Array.from(baseClasses);
|
|
46
55
|
}
|
|
47
56
|
function prefix(context, selector) {
|
|
48
|
-
let
|
|
49
|
-
return typeof
|
|
57
|
+
let prefix = context.tailwindConfig.prefix;
|
|
58
|
+
return typeof prefix === "function" ? prefix(selector) : prefix + selector;
|
|
50
59
|
}
|
|
51
60
|
function* pathToRoot(node) {
|
|
52
61
|
yield node;
|
|
@@ -127,8 +136,7 @@ function* pathToRoot(node) {
|
|
|
127
136
|
* @param {import('postcss').Root} root
|
|
128
137
|
*/ function buildLocalApplyCache(root, context) {
|
|
129
138
|
/** @type {ApplyCache} */ let cache = new Map();
|
|
130
|
-
|
|
131
|
-
root.walkRules((rule, idx)=>{
|
|
139
|
+
root.walkRules((rule)=>{
|
|
132
140
|
// Ignore rules generated by Tailwind
|
|
133
141
|
for (let node of pathToRoot(rule)){
|
|
134
142
|
var ref;
|
|
@@ -138,16 +146,17 @@ function* pathToRoot(node) {
|
|
|
138
146
|
}
|
|
139
147
|
// Clone what's required to represent this singular rule in the tree
|
|
140
148
|
let container = nestedClone(rule);
|
|
149
|
+
let sort = context.offsets.create("user");
|
|
141
150
|
for (let className of extractClasses(rule)){
|
|
142
151
|
let list = cache.get(className) || [];
|
|
143
152
|
cache.set(className, list);
|
|
144
153
|
list.push([
|
|
145
154
|
{
|
|
146
155
|
layer: "user",
|
|
147
|
-
sort
|
|
156
|
+
sort,
|
|
148
157
|
important: false
|
|
149
158
|
},
|
|
150
|
-
container
|
|
159
|
+
container
|
|
151
160
|
]);
|
|
152
161
|
}
|
|
153
162
|
});
|
|
@@ -164,11 +173,10 @@ function* pathToRoot(node) {
|
|
|
164
173
|
context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
|
|
165
174
|
meta,
|
|
166
175
|
rule.clone()
|
|
167
|
-
]
|
|
168
|
-
));
|
|
176
|
+
]));
|
|
169
177
|
continue;
|
|
170
178
|
}
|
|
171
|
-
let matches = Array.from((0, _generateRules
|
|
179
|
+
let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
|
|
172
180
|
if (matches.length === 0) {
|
|
173
181
|
context.notClassCache.add(candidate);
|
|
174
182
|
continue;
|
|
@@ -203,11 +211,8 @@ function* pathToRoot(node) {
|
|
|
203
211
|
* @returns {ApplyCache}
|
|
204
212
|
*/ function combineCaches(caches) {
|
|
205
213
|
return {
|
|
206
|
-
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
|
|
207
|
-
|
|
208
|
-
,
|
|
209
|
-
has: (name)=>caches.some((cache)=>cache.has(name)
|
|
210
|
-
)
|
|
214
|
+
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
|
|
215
|
+
has: (name)=>caches.some((cache)=>cache.has(name))
|
|
211
216
|
};
|
|
212
217
|
}
|
|
213
218
|
function extractApplyCandidates(params) {
|
|
@@ -262,30 +267,83 @@ function processApply(root, context, localCache) {
|
|
|
262
267
|
* What happens in this function is that we prepend a `.` and escape the candidate.
|
|
263
268
|
* This will result in `.hover\:font-bold`
|
|
264
269
|
* Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
];
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
270
|
+
*
|
|
271
|
+
* @param {string} selector
|
|
272
|
+
* @param {string} utilitySelectors
|
|
273
|
+
* @param {string} candidate
|
|
274
|
+
*/ function replaceSelector(selector, utilitySelectors, candidate) {
|
|
275
|
+
let selectorList = extractSelectors(selector);
|
|
276
|
+
let utilitySelectorsList = extractSelectors(utilitySelectors);
|
|
277
|
+
let candidateList = extractSelectors(`.${(0, _escapeClassName.default)(candidate)}`);
|
|
278
|
+
let candidateClass = candidateList.nodes[0].nodes[0];
|
|
279
|
+
selectorList.each((sel)=>{
|
|
280
|
+
/** @type {Set<import('postcss-selector-parser').Selector>} */ let replaced = new Set();
|
|
281
|
+
utilitySelectorsList.each((utilitySelector)=>{
|
|
282
|
+
let hasReplaced = false;
|
|
283
|
+
utilitySelector = utilitySelector.clone();
|
|
284
|
+
utilitySelector.walkClasses((node)=>{
|
|
285
|
+
if (node.value !== candidateClass.value) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// Don't replace multiple instances of the same class
|
|
289
|
+
// This is theoretically correct but only partially
|
|
290
|
+
// We'd need to generate every possible permutation of the replacement
|
|
291
|
+
// For example with `.foo + .foo { … }` and `section { @apply foo; }`
|
|
292
|
+
// We'd need to generate all of these:
|
|
293
|
+
// - `.foo + .foo`
|
|
294
|
+
// - `.foo + section`
|
|
295
|
+
// - `section + .foo`
|
|
296
|
+
// - `section + section`
|
|
297
|
+
if (hasReplaced) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
// Since you can only `@apply` class names this is sufficient
|
|
301
|
+
// We want to replace the matched class name with the selector the user is using
|
|
302
|
+
// Ex: Replace `.text-blue-500` with `.foo.bar:is(.something-cool)`
|
|
303
|
+
node.replaceWith(...sel.nodes.map((node)=>node.clone()));
|
|
304
|
+
// Record that we did something and we want to use this new selector
|
|
305
|
+
replaced.add(utilitySelector);
|
|
306
|
+
hasReplaced = true;
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
// Sort tag names before class names (but only sort each group (separated by a combinator)
|
|
310
|
+
// separately and not in total)
|
|
311
|
+
// This happens when replacing `.bar` in `.foo.bar` with a tag like `section`
|
|
312
|
+
for (let sel1 of replaced){
|
|
313
|
+
let groups = [
|
|
314
|
+
[]
|
|
315
|
+
];
|
|
316
|
+
for (let node of sel1.nodes){
|
|
317
|
+
if (node.type === "combinator") {
|
|
318
|
+
groups.push(node);
|
|
319
|
+
groups.push([]);
|
|
320
|
+
} else {
|
|
321
|
+
let last = groups[groups.length - 1];
|
|
322
|
+
last.push(node);
|
|
323
|
+
}
|
|
281
324
|
}
|
|
282
|
-
|
|
283
|
-
|
|
325
|
+
sel1.nodes = [];
|
|
326
|
+
for (let group of groups){
|
|
327
|
+
if (Array.isArray(group)) {
|
|
328
|
+
group.sort((a, b)=>{
|
|
329
|
+
if (a.type === "tag" && b.type === "class") {
|
|
330
|
+
return -1;
|
|
331
|
+
} else if (a.type === "class" && b.type === "tag") {
|
|
332
|
+
return 1;
|
|
333
|
+
} else if (a.type === "class" && b.type === "pseudo" && b.value.startsWith("::")) {
|
|
334
|
+
return -1;
|
|
335
|
+
} else if (a.type === "pseudo" && a.value.startsWith("::") && b.type === "class") {
|
|
336
|
+
return 1;
|
|
337
|
+
}
|
|
338
|
+
return 0;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
sel1.nodes = sel1.nodes.concat(group);
|
|
284
342
|
}
|
|
285
|
-
replaced.push(replacedSelector);
|
|
286
343
|
}
|
|
287
|
-
|
|
288
|
-
})
|
|
344
|
+
sel.replaceWith(...replaced);
|
|
345
|
+
});
|
|
346
|
+
return selectorList.toString();
|
|
289
347
|
}
|
|
290
348
|
let perParentApplies = new Map();
|
|
291
349
|
// Collect all apply candidates and their rules
|
|
@@ -298,16 +356,15 @@ function processApply(root, context, localCache) {
|
|
|
298
356
|
candidates,
|
|
299
357
|
apply.source
|
|
300
358
|
]);
|
|
301
|
-
let [
|
|
359
|
+
let [applyCandidates1, important] = extractApplyCandidates(apply.params);
|
|
302
360
|
if (apply.parent.type === "atrule") {
|
|
303
361
|
if (apply.parent.name === "screen") {
|
|
304
|
-
|
|
305
|
-
throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${
|
|
306
|
-
).join(" ")} instead.`);
|
|
362
|
+
let screenType = apply.parent.params;
|
|
363
|
+
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.`);
|
|
307
364
|
}
|
|
308
365
|
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}.`);
|
|
309
366
|
}
|
|
310
|
-
for (let applyCandidate of
|
|
367
|
+
for (let applyCandidate of applyCandidates1){
|
|
311
368
|
if ([
|
|
312
369
|
prefix(context, "group"),
|
|
313
370
|
prefix(context, "peer")
|
|
@@ -326,12 +383,21 @@ function processApply(root, context, localCache) {
|
|
|
326
383
|
]);
|
|
327
384
|
}
|
|
328
385
|
}
|
|
329
|
-
for (
|
|
386
|
+
for (let [parent, [candidates1, atApplySource]] of perParentApplies){
|
|
330
387
|
let siblings = [];
|
|
331
|
-
for (let [
|
|
332
|
-
|
|
388
|
+
for (let [applyCandidate1, important1, rules1] of candidates1){
|
|
389
|
+
let potentialApplyCandidates = [
|
|
390
|
+
applyCandidate1,
|
|
391
|
+
...extractBaseCandidates([
|
|
392
|
+
applyCandidate1
|
|
393
|
+
], context.tailwindConfig.separator)
|
|
394
|
+
];
|
|
395
|
+
for (let [meta, node] of rules1){
|
|
333
396
|
let parentClasses = extractClasses(parent);
|
|
334
|
-
let nodeClasses = extractClasses(
|
|
397
|
+
let nodeClasses = extractClasses(node);
|
|
398
|
+
// 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`
|
|
399
|
+
// So we've split them into groups
|
|
400
|
+
nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
|
|
335
401
|
// Add base utility classes from the @apply node to the list of
|
|
336
402
|
// classes to check whether it intersects and therefore results in a
|
|
337
403
|
// circular dependency or not.
|
|
@@ -355,23 +421,22 @@ function processApply(root, context, localCache) {
|
|
|
355
421
|
// unrelated. However, if we were to apply `hover:foo` then we _did_
|
|
356
422
|
// have to include this one.
|
|
357
423
|
nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
|
|
358
|
-
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
|
|
359
|
-
);
|
|
424
|
+
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
|
|
360
425
|
if (intersects) {
|
|
361
|
-
throw
|
|
426
|
+
throw node.error(`You cannot \`@apply\` the \`${applyCandidate1}\` utility here because it creates a circular dependency.`);
|
|
362
427
|
}
|
|
363
|
-
let
|
|
428
|
+
let root1 = _postcss.default.root({
|
|
364
429
|
nodes: [
|
|
365
|
-
|
|
430
|
+
node.clone()
|
|
366
431
|
]
|
|
367
432
|
});
|
|
368
433
|
// Make sure every node in the entire tree points back at the @apply rule that generated it
|
|
369
|
-
|
|
434
|
+
root1.walk((node)=>{
|
|
370
435
|
node.source = atApplySource;
|
|
371
436
|
});
|
|
372
|
-
let canRewriteSelector =
|
|
437
|
+
let canRewriteSelector = node.type !== "atrule" || node.type === "atrule" && node.name !== "keyframes";
|
|
373
438
|
if (canRewriteSelector) {
|
|
374
|
-
|
|
439
|
+
root1.walkRules((rule)=>{
|
|
375
440
|
// Let's imagine you have the following structure:
|
|
376
441
|
//
|
|
377
442
|
// .foo {
|
|
@@ -403,32 +468,40 @@ function processApply(root, context, localCache) {
|
|
|
403
468
|
// would have replaced this with something that didn't exist and
|
|
404
469
|
// therefore it removed the selector altogether. In this specific
|
|
405
470
|
// case it would result in `{}` instead of `.something-unrelated {}`
|
|
406
|
-
if (!extractClasses(rule).some((candidate)=>candidate ===
|
|
407
|
-
)) {
|
|
471
|
+
if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate1)) {
|
|
408
472
|
rule.remove();
|
|
409
473
|
return;
|
|
410
474
|
}
|
|
411
|
-
|
|
475
|
+
// Strip the important selector from the parent selector if at the beginning
|
|
476
|
+
let importantSelector = typeof context.tailwindConfig.important === "string" ? context.tailwindConfig.important : null;
|
|
477
|
+
// We only want to move the "important" selector if this is a Tailwind-generated utility
|
|
478
|
+
// We do *not* want to do this for user CSS that happens to be structured the same
|
|
479
|
+
let isGenerated = parent.raws.tailwind !== undefined;
|
|
480
|
+
let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
|
|
481
|
+
rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate1);
|
|
482
|
+
// And then re-add it if it was removed
|
|
483
|
+
if (importantSelector && parentSelector !== parent.selector) {
|
|
484
|
+
rule.selector = `${importantSelector} ${rule.selector}`;
|
|
485
|
+
}
|
|
412
486
|
rule.walkDecls((d)=>{
|
|
413
|
-
d.important = meta.important ||
|
|
487
|
+
d.important = meta.important || important1;
|
|
414
488
|
});
|
|
415
489
|
});
|
|
416
490
|
}
|
|
491
|
+
// It could be that the node we were inserted was removed because the class didn't match
|
|
492
|
+
// If that was the *only* rule in the parent, then we have nothing add so we skip it
|
|
493
|
+
if (!root1.nodes[0]) {
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
417
496
|
// Insert it
|
|
418
497
|
siblings.push([
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
...meta,
|
|
422
|
-
sort: meta.sort | context.layerOrder[meta.layer]
|
|
423
|
-
},
|
|
424
|
-
root.nodes[0],
|
|
498
|
+
meta.sort,
|
|
499
|
+
root1.nodes[0]
|
|
425
500
|
]);
|
|
426
501
|
}
|
|
427
502
|
}
|
|
428
503
|
// Inject the rules, sorted, correctly
|
|
429
|
-
let nodes =
|
|
430
|
-
).map((s)=>s[1]
|
|
431
|
-
);
|
|
504
|
+
let nodes = context.offsets.sort(siblings).map((s)=>s[1]);
|
|
432
505
|
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
433
506
|
parent.after(nodes);
|
|
434
507
|
}
|
|
@@ -444,3 +517,10 @@ function processApply(root, context, localCache) {
|
|
|
444
517
|
// Do it again, in case we have other `@apply` rules
|
|
445
518
|
processApply(root, context, localCache);
|
|
446
519
|
}
|
|
520
|
+
function expandApplyAtRules(context) {
|
|
521
|
+
return (root)=>{
|
|
522
|
+
// Build a cache of the user's CSS so we can use it to resolve classes used by @apply
|
|
523
|
+
let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
|
|
524
|
+
processApply(root, context, localCache);
|
|
525
|
+
};
|
|
526
|
+
}
|