tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21
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 +246 -6
- package/README.md +13 -9
- package/defaultTheme.d.ts +2 -1
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +48 -0
- package/lib/cli/build/plugin.js +362 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +178 -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 +62 -592
- package/lib/constants.js +19 -12
- package/lib/corePluginList.js +5 -3
- package/lib/corePlugins.js +619 -347
- package/lib/css/preflight.css +7 -0
- package/lib/featureFlags.js +34 -22
- package/lib/index.js +16 -9
- package/lib/lib/cacheInvalidation.js +42 -21
- package/lib/lib/collapseAdjacentRules.js +16 -14
- package/lib/lib/collapseDuplicateDeclarations.js +13 -10
- package/lib/lib/content.js +177 -0
- package/lib/lib/defaultExtractor.js +230 -33
- package/lib/lib/detectNesting.js +13 -4
- package/lib/lib/evaluateTailwindFunctions.js +105 -42
- package/lib/lib/expandApplyAtRules.js +151 -92
- package/lib/lib/expandTailwindAtRules.js +134 -149
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +404 -185
- package/lib/lib/getModuleDependencies.js +21 -18
- package/lib/lib/normalizeTailwindDirectives.js +11 -8
- package/lib/lib/offsets.js +285 -0
- package/lib/lib/partitionApplyAtRules.js +14 -11
- package/lib/lib/regex.js +60 -0
- package/lib/lib/remap-bitfield.js +87 -0
- package/lib/lib/resolveDefaultsAtRules.js +97 -79
- package/lib/lib/setupContextUtils.js +567 -242
- 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 +10 -8
- 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 +20 -17
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -5
- package/lib/util/createUtilityPlugin.js +15 -13
- package/lib/util/dataTypes.js +75 -51
- package/lib/util/defaults.js +8 -5
- package/lib/util/escapeClassName.js +13 -10
- package/lib/util/escapeCommas.js +4 -1
- package/lib/util/flattenColorPalette.js +7 -8
- package/lib/util/formatVariantSelector.js +270 -103
- package/lib/util/getAllConfigs.js +34 -15
- 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 → isSyntacticallyValidPropertyValue.js} +34 -26
- 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 +94 -53
- 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 +146 -42
- package/lib/util/prefixSelector.js +26 -9
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +104 -105
- 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 +32 -29
- package/peers/index.js +6693 -3036
- package/plugin.d.ts +10 -5
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +53 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/deps.js +56 -0
- package/src/cli/build/index.js +49 -0
- package/src/cli/build/plugin.js +434 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +227 -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 +46 -659
- package/src/corePlugins.js +346 -79
- package/src/css/preflight.css +7 -0
- package/src/featureFlags.js +12 -2
- package/src/index.js +5 -0
- package/src/lib/content.js +213 -0
- package/src/lib/defaultExtractor.js +202 -35
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +78 -7
- package/src/lib/expandApplyAtRules.js +129 -34
- package/src/lib/expandTailwindAtRules.js +12 -50
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +379 -126
- package/src/lib/offsets.js +351 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -36
- package/src/lib/setupContextUtils.js +510 -120
- 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/dataTypes.js +51 -26
- package/src/util/formatVariantSelector.js +317 -101
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- 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 +40 -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 +132 -10
- package/src/util/prefixSelector.js +28 -10
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -62
- 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 +165 -164
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +77 -37
- package/types/generated/default-theme.d.ts +342 -0
- package/types/index.d.ts +7 -1
- package/types.d.ts +0 -1
|
@@ -2,20 +2,14 @@
|
|
|
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
|
|
@@ -29,7 +23,7 @@ function _interopRequireDefault(obj) {
|
|
|
29
23
|
]
|
|
30
24
|
});
|
|
31
25
|
container.walkRules((rule)=>{
|
|
32
|
-
(0, _postcssSelectorParser
|
|
26
|
+
(0, _postcssSelectorParser.default)((selectors)=>{
|
|
33
27
|
selectors.walkClasses((classSelector)=>{
|
|
34
28
|
let parentSelector = classSelector.parent.toString();
|
|
35
29
|
let classes = groups.get(parentSelector);
|
|
@@ -40,13 +34,18 @@ function _interopRequireDefault(obj) {
|
|
|
40
34
|
});
|
|
41
35
|
}).processSync(rule.selector);
|
|
42
36
|
});
|
|
43
|
-
let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes)
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
return Object.assign(classes1, {
|
|
37
|
+
let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
|
|
38
|
+
let classes = normalizedGroups.flat();
|
|
39
|
+
return Object.assign(classes, {
|
|
47
40
|
groups: normalizedGroups
|
|
48
41
|
});
|
|
49
42
|
}
|
|
43
|
+
let selectorExtractor = (0, _postcssSelectorParser.default)();
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} ruleSelectors
|
|
46
|
+
*/ function extractSelectors(ruleSelectors) {
|
|
47
|
+
return selectorExtractor.astSync(ruleSelectors);
|
|
48
|
+
}
|
|
50
49
|
function extractBaseCandidates(candidates, separator) {
|
|
51
50
|
let baseClasses = new Set();
|
|
52
51
|
for (let candidate of candidates){
|
|
@@ -55,8 +54,8 @@ function extractBaseCandidates(candidates, separator) {
|
|
|
55
54
|
return Array.from(baseClasses);
|
|
56
55
|
}
|
|
57
56
|
function prefix(context, selector) {
|
|
58
|
-
let
|
|
59
|
-
return typeof
|
|
57
|
+
let prefix = context.tailwindConfig.prefix;
|
|
58
|
+
return typeof prefix === "function" ? prefix(selector) : prefix + selector;
|
|
60
59
|
}
|
|
61
60
|
function* pathToRoot(node) {
|
|
62
61
|
yield node;
|
|
@@ -137,27 +136,27 @@ function* pathToRoot(node) {
|
|
|
137
136
|
* @param {import('postcss').Root} root
|
|
138
137
|
*/ function buildLocalApplyCache(root, context) {
|
|
139
138
|
/** @type {ApplyCache} */ let cache = new Map();
|
|
140
|
-
|
|
141
|
-
root.walkRules((rule, idx)=>{
|
|
139
|
+
root.walkRules((rule)=>{
|
|
142
140
|
// Ignore rules generated by Tailwind
|
|
143
141
|
for (let node of pathToRoot(rule)){
|
|
144
|
-
var
|
|
145
|
-
if (((
|
|
142
|
+
var _node_raws_tailwind;
|
|
143
|
+
if (((_node_raws_tailwind = node.raws.tailwind) === null || _node_raws_tailwind === void 0 ? void 0 : _node_raws_tailwind.layer) !== undefined) {
|
|
146
144
|
return;
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
// Clone what's required to represent this singular rule in the tree
|
|
150
148
|
let container = nestedClone(rule);
|
|
149
|
+
let sort = context.offsets.create("user");
|
|
151
150
|
for (let className of extractClasses(rule)){
|
|
152
151
|
let list = cache.get(className) || [];
|
|
153
152
|
cache.set(className, list);
|
|
154
153
|
list.push([
|
|
155
154
|
{
|
|
156
155
|
layer: "user",
|
|
157
|
-
sort
|
|
156
|
+
sort,
|
|
158
157
|
important: false
|
|
159
158
|
},
|
|
160
|
-
container
|
|
159
|
+
container
|
|
161
160
|
]);
|
|
162
161
|
}
|
|
163
162
|
});
|
|
@@ -174,11 +173,10 @@ function* pathToRoot(node) {
|
|
|
174
173
|
context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
|
|
175
174
|
meta,
|
|
176
175
|
rule.clone()
|
|
177
|
-
]
|
|
178
|
-
));
|
|
176
|
+
]));
|
|
179
177
|
continue;
|
|
180
178
|
}
|
|
181
|
-
let matches = Array.from((0, _generateRules
|
|
179
|
+
let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
|
|
182
180
|
if (matches.length === 0) {
|
|
183
181
|
context.notClassCache.add(candidate);
|
|
184
182
|
continue;
|
|
@@ -213,11 +211,8 @@ function* pathToRoot(node) {
|
|
|
213
211
|
* @returns {ApplyCache}
|
|
214
212
|
*/ function combineCaches(caches) {
|
|
215
213
|
return {
|
|
216
|
-
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
|
|
217
|
-
|
|
218
|
-
,
|
|
219
|
-
has: (name)=>caches.some((cache)=>cache.has(name)
|
|
220
|
-
)
|
|
214
|
+
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
|
|
215
|
+
has: (name)=>caches.some((cache)=>cache.has(name))
|
|
221
216
|
};
|
|
222
217
|
}
|
|
223
218
|
function extractApplyCandidates(params) {
|
|
@@ -272,30 +267,83 @@ function processApply(root, context, localCache) {
|
|
|
272
267
|
* What happens in this function is that we prepend a `.` and escape the candidate.
|
|
273
268
|
* This will result in `.hover\:font-bold`
|
|
274
269
|
* Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
];
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
+
}
|
|
291
324
|
}
|
|
292
|
-
|
|
293
|
-
|
|
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);
|
|
294
342
|
}
|
|
295
|
-
replaced.push(replacedSelector);
|
|
296
343
|
}
|
|
297
|
-
|
|
298
|
-
})
|
|
344
|
+
sel.replaceWith(...replaced);
|
|
345
|
+
});
|
|
346
|
+
return selectorList.toString();
|
|
299
347
|
}
|
|
300
348
|
let perParentApplies = new Map();
|
|
301
349
|
// Collect all apply candidates and their rules
|
|
@@ -308,16 +356,15 @@ function processApply(root, context, localCache) {
|
|
|
308
356
|
candidates,
|
|
309
357
|
apply.source
|
|
310
358
|
]);
|
|
311
|
-
let [
|
|
359
|
+
let [applyCandidates1, important] = extractApplyCandidates(apply.params);
|
|
312
360
|
if (apply.parent.type === "atrule") {
|
|
313
361
|
if (apply.parent.name === "screen") {
|
|
314
|
-
|
|
315
|
-
throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${
|
|
316
|
-
).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.`);
|
|
317
364
|
}
|
|
318
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}.`);
|
|
319
366
|
}
|
|
320
|
-
for (let applyCandidate of
|
|
367
|
+
for (let applyCandidate of applyCandidates1){
|
|
321
368
|
if ([
|
|
322
369
|
prefix(context, "group"),
|
|
323
370
|
prefix(context, "peer")
|
|
@@ -336,23 +383,21 @@ function processApply(root, context, localCache) {
|
|
|
336
383
|
]);
|
|
337
384
|
}
|
|
338
385
|
}
|
|
339
|
-
for (
|
|
386
|
+
for (let [parent, [candidates1, atApplySource]] of perParentApplies){
|
|
340
387
|
let siblings = [];
|
|
341
|
-
for (let [
|
|
388
|
+
for (let [applyCandidate1, important1, rules1] of candidates1){
|
|
342
389
|
let potentialApplyCandidates = [
|
|
343
|
-
|
|
390
|
+
applyCandidate1,
|
|
344
391
|
...extractBaseCandidates([
|
|
345
|
-
|
|
346
|
-
], context.tailwindConfig.separator)
|
|
392
|
+
applyCandidate1
|
|
393
|
+
], context.tailwindConfig.separator)
|
|
347
394
|
];
|
|
348
|
-
for (let [meta,
|
|
395
|
+
for (let [meta, node] of rules1){
|
|
349
396
|
let parentClasses = extractClasses(parent);
|
|
350
|
-
let nodeClasses = extractClasses(
|
|
397
|
+
let nodeClasses = extractClasses(node);
|
|
351
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`
|
|
352
399
|
// So we've split them into groups
|
|
353
|
-
nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className)
|
|
354
|
-
)
|
|
355
|
-
).flat();
|
|
400
|
+
nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
|
|
356
401
|
// Add base utility classes from the @apply node to the list of
|
|
357
402
|
// classes to check whether it intersects and therefore results in a
|
|
358
403
|
// circular dependency or not.
|
|
@@ -376,23 +421,22 @@ function processApply(root, context, localCache) {
|
|
|
376
421
|
// unrelated. However, if we were to apply `hover:foo` then we _did_
|
|
377
422
|
// have to include this one.
|
|
378
423
|
nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
|
|
379
|
-
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
|
|
380
|
-
);
|
|
424
|
+
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
|
|
381
425
|
if (intersects) {
|
|
382
|
-
throw
|
|
426
|
+
throw node.error(`You cannot \`@apply\` the \`${applyCandidate1}\` utility here because it creates a circular dependency.`);
|
|
383
427
|
}
|
|
384
|
-
let
|
|
428
|
+
let root1 = _postcss.default.root({
|
|
385
429
|
nodes: [
|
|
386
|
-
|
|
430
|
+
node.clone()
|
|
387
431
|
]
|
|
388
432
|
});
|
|
389
433
|
// Make sure every node in the entire tree points back at the @apply rule that generated it
|
|
390
|
-
|
|
434
|
+
root1.walk((node)=>{
|
|
391
435
|
node.source = atApplySource;
|
|
392
436
|
});
|
|
393
|
-
let canRewriteSelector =
|
|
437
|
+
let canRewriteSelector = node.type !== "atrule" || node.type === "atrule" && node.name !== "keyframes";
|
|
394
438
|
if (canRewriteSelector) {
|
|
395
|
-
|
|
439
|
+
root1.walkRules((rule)=>{
|
|
396
440
|
// Let's imagine you have the following structure:
|
|
397
441
|
//
|
|
398
442
|
// .foo {
|
|
@@ -424,32 +468,40 @@ function processApply(root, context, localCache) {
|
|
|
424
468
|
// would have replaced this with something that didn't exist and
|
|
425
469
|
// therefore it removed the selector altogether. In this specific
|
|
426
470
|
// case it would result in `{}` instead of `.something-unrelated {}`
|
|
427
|
-
if (!extractClasses(rule).some((candidate)=>candidate ===
|
|
428
|
-
)) {
|
|
471
|
+
if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate1)) {
|
|
429
472
|
rule.remove();
|
|
430
473
|
return;
|
|
431
474
|
}
|
|
432
|
-
|
|
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
|
+
}
|
|
433
486
|
rule.walkDecls((d)=>{
|
|
434
|
-
d.important = meta.important ||
|
|
487
|
+
d.important = meta.important || important1;
|
|
435
488
|
});
|
|
436
489
|
});
|
|
437
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
|
+
}
|
|
438
496
|
// Insert it
|
|
439
497
|
siblings.push([
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
...meta,
|
|
443
|
-
sort: meta.sort | context.layerOrder[meta.layer]
|
|
444
|
-
},
|
|
445
|
-
root.nodes[0],
|
|
498
|
+
meta.sort,
|
|
499
|
+
root1.nodes[0]
|
|
446
500
|
]);
|
|
447
501
|
}
|
|
448
502
|
}
|
|
449
503
|
// Inject the rules, sorted, correctly
|
|
450
|
-
let nodes =
|
|
451
|
-
).map((s)=>s[1]
|
|
452
|
-
);
|
|
504
|
+
let nodes = context.offsets.sort(siblings).map((s)=>s[1]);
|
|
453
505
|
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
454
506
|
parent.after(nodes);
|
|
455
507
|
}
|
|
@@ -465,3 +517,10 @@ function processApply(root, context, localCache) {
|
|
|
465
517
|
// Do it again, in case we have other `@apply` rules
|
|
466
518
|
processApply(root, context, localCache);
|
|
467
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
|
+
}
|