tailwindcss 3.0.24 → 3.1.0
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 +57 -3
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +3 -0
- package/lib/cli-peer-dependencies.js +8 -3
- package/lib/cli.js +118 -77
- package/lib/corePluginList.js +1 -0
- package/lib/corePlugins.js +146 -117
- package/lib/css/preflight.css +1 -8
- package/lib/featureFlags.js +8 -6
- package/lib/index.js +10 -13
- package/lib/lib/cacheInvalidation.js +32 -14
- package/lib/lib/collapseAdjacentRules.js +5 -3
- package/lib/lib/defaultExtractor.js +191 -32
- package/lib/lib/evaluateTailwindFunctions.js +22 -13
- package/lib/lib/expandApplyAtRules.js +232 -195
- package/lib/lib/expandTailwindAtRules.js +40 -26
- package/lib/lib/generateRules.js +106 -42
- package/lib/lib/regex.js +52 -0
- package/lib/lib/resolveDefaultsAtRules.js +6 -9
- package/lib/lib/setupContextUtils.js +131 -79
- package/lib/lib/setupTrackingContext.js +7 -9
- package/lib/lib/sharedState.js +1 -2
- package/lib/lib/substituteScreenAtRules.js +1 -2
- package/lib/postcss-plugins/nesting/plugin.js +1 -2
- package/lib/util/buildMediaQuery.js +1 -2
- package/lib/util/cloneDeep.js +2 -4
- package/lib/util/color.js +26 -36
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +1 -2
- package/lib/util/dataTypes.js +14 -12
- package/lib/util/flattenColorPalette.js +2 -5
- package/lib/util/formatVariantSelector.js +64 -57
- package/lib/util/getAllConfigs.js +10 -5
- package/lib/util/isValidArbitraryValue.js +1 -2
- package/lib/util/log.js +2 -3
- package/lib/util/negateValue.js +1 -2
- package/lib/util/normalizeConfig.js +33 -23
- package/lib/util/normalizeScreens.js +1 -2
- package/lib/util/parseAnimationValue.js +1 -2
- package/lib/util/parseBoxShadowValue.js +2 -43
- package/lib/util/pluginUtils.js +11 -3
- package/lib/util/resolveConfig.js +57 -34
- package/lib/util/splitAtTopLevelOnly.js +90 -0
- package/lib/util/transformThemeValue.js +4 -2
- package/lib/util/validateConfig.js +21 -0
- package/lib/util/withAlphaVariable.js +5 -5
- package/package.json +21 -16
- package/peers/index.js +3264 -1330
- package/plugin.d.ts +11 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +97 -33
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +57 -40
- package/src/css/preflight.css +1 -8
- package/src/featureFlags.js +2 -2
- package/src/index.js +0 -2
- package/src/lib/collapseAdjacentRules.js +5 -1
- package/src/lib/defaultExtractor.js +177 -35
- package/src/lib/evaluateTailwindFunctions.js +20 -4
- package/src/lib/expandApplyAtRules.js +247 -188
- package/src/lib/expandTailwindAtRules.js +4 -4
- package/src/lib/generateRules.js +69 -5
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +1 -1
- package/src/lib/setupContextUtils.js +103 -39
- package/src/lib/setupTrackingContext.js +4 -0
- package/src/util/color.js +20 -18
- package/src/util/dataTypes.js +11 -5
- package/src/util/formatVariantSelector.js +79 -62
- package/src/util/getAllConfigs.js +7 -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/resolveConfig.js +66 -54
- 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 +2 -3
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +325 -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/index.d.ts +1 -0
|
@@ -11,8 +11,7 @@ var _escapeClassName = _interopRequireDefault(require("../util/escapeClassName")
|
|
|
11
11
|
function expandApplyAtRules(context) {
|
|
12
12
|
return (root)=>{
|
|
13
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
|
-
);
|
|
14
|
+
let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
|
|
16
15
|
processApply(root, context, localCache);
|
|
17
16
|
};
|
|
18
17
|
}
|
|
@@ -22,7 +21,7 @@ function _interopRequireDefault(obj) {
|
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
23
|
/** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
|
|
25
|
-
let
|
|
24
|
+
/** @type {Map<string, Set<string>>} */ let groups = new Map();
|
|
26
25
|
let container = _postcss.default.root({
|
|
27
26
|
nodes: [
|
|
28
27
|
node.clone()
|
|
@@ -31,11 +30,26 @@ function _interopRequireDefault(obj) {
|
|
|
31
30
|
container.walkRules((rule)=>{
|
|
32
31
|
(0, _postcssSelectorParser).default((selectors)=>{
|
|
33
32
|
selectors.walkClasses((classSelector)=>{
|
|
33
|
+
let parentSelector = classSelector.parent.toString();
|
|
34
|
+
let classes = groups.get(parentSelector);
|
|
35
|
+
if (!classes) {
|
|
36
|
+
groups.set(parentSelector, classes = new Set());
|
|
37
|
+
}
|
|
34
38
|
classes.add(classSelector.value);
|
|
35
39
|
});
|
|
36
40
|
}).processSync(rule.selector);
|
|
37
41
|
});
|
|
38
|
-
|
|
42
|
+
let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
|
|
43
|
+
let classes1 = normalizedGroups.flat();
|
|
44
|
+
return Object.assign(classes1, {
|
|
45
|
+
groups: normalizedGroups
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
let selectorExtractor = (0, _postcssSelectorParser).default((root)=>root.nodes.map((node)=>node.toString()));
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} ruleSelectors
|
|
51
|
+
*/ function extractSelectors(ruleSelectors) {
|
|
52
|
+
return selectorExtractor.transformSync(ruleSelectors);
|
|
39
53
|
}
|
|
40
54
|
function extractBaseCandidates(candidates, separator) {
|
|
41
55
|
let baseClasses = new Set();
|
|
@@ -164,8 +178,7 @@ function* pathToRoot(node) {
|
|
|
164
178
|
context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
|
|
165
179
|
meta,
|
|
166
180
|
rule.clone()
|
|
167
|
-
]
|
|
168
|
-
));
|
|
181
|
+
]));
|
|
169
182
|
continue;
|
|
170
183
|
}
|
|
171
184
|
let matches = Array.from((0, _generateRules).resolveMatches(candidate, context));
|
|
@@ -203,11 +216,8 @@ function* pathToRoot(node) {
|
|
|
203
216
|
* @returns {ApplyCache}
|
|
204
217
|
*/ function combineCaches(caches) {
|
|
205
218
|
return {
|
|
206
|
-
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
|
|
207
|
-
|
|
208
|
-
,
|
|
209
|
-
has: (name)=>caches.some((cache)=>cache.has(name)
|
|
210
|
-
)
|
|
219
|
+
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
|
|
220
|
+
has: (name)=>caches.some((cache)=>cache.has(name))
|
|
211
221
|
};
|
|
212
222
|
}
|
|
213
223
|
function extractApplyCandidates(params) {
|
|
@@ -235,199 +245,226 @@ function processApply(root, context, localCache) {
|
|
|
235
245
|
applies.push(rule);
|
|
236
246
|
});
|
|
237
247
|
// Start the @apply process if we have rules with @apply in them
|
|
238
|
-
if (applies.length
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
248
|
+
if (applies.length === 0) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
// Fill up some caches!
|
|
252
|
+
let applyClassCache = combineCaches([
|
|
253
|
+
localCache,
|
|
254
|
+
buildApplyCache(applyCandidates, context)
|
|
255
|
+
]);
|
|
256
|
+
/**
|
|
257
|
+
* When we have an apply like this:
|
|
258
|
+
*
|
|
259
|
+
* .abc {
|
|
260
|
+
* @apply hover:font-bold;
|
|
261
|
+
* }
|
|
262
|
+
*
|
|
263
|
+
* What we essentially will do is resolve to this:
|
|
264
|
+
*
|
|
265
|
+
* .abc {
|
|
266
|
+
* @apply .hover\:font-bold:hover {
|
|
267
|
+
* font-weight: 500;
|
|
268
|
+
* }
|
|
269
|
+
* }
|
|
270
|
+
*
|
|
271
|
+
* Notice that the to-be-applied class is `.hover\:font-bold:hover` and that the utility candidate was `hover:font-bold`.
|
|
272
|
+
* What happens in this function is that we prepend a `.` and escape the candidate.
|
|
273
|
+
* This will result in `.hover\:font-bold`
|
|
274
|
+
* Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
|
|
275
|
+
*/ // TODO: Should we use postcss-selector-parser for this instead?
|
|
276
|
+
function replaceSelector(selector, utilitySelectors, candidate) {
|
|
277
|
+
let needle1 = `.${(0, _escapeClassName).default(candidate)}`;
|
|
278
|
+
let needles = [
|
|
279
|
+
...new Set([
|
|
280
|
+
needle1,
|
|
281
|
+
needle1.replace(/\\2c /g, "\\,")
|
|
282
|
+
])
|
|
283
|
+
];
|
|
284
|
+
let utilitySelectorsList = extractSelectors(utilitySelectors);
|
|
285
|
+
return extractSelectors(selector).map((s)=>{
|
|
286
|
+
let replaced = [];
|
|
287
|
+
for (let utilitySelector of utilitySelectorsList){
|
|
288
|
+
let replacedSelector = utilitySelector;
|
|
289
|
+
for (const needle of needles){
|
|
290
|
+
replacedSelector = replacedSelector.replace(needle, s);
|
|
275
291
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
let perParentApplies = new Map();
|
|
280
|
-
// Collect all apply candidates and their rules
|
|
281
|
-
for (let apply of applies){
|
|
282
|
-
let candidates = perParentApplies.get(apply.parent) || [];
|
|
283
|
-
perParentApplies.set(apply.parent, [
|
|
284
|
-
candidates,
|
|
285
|
-
apply.source
|
|
286
|
-
]);
|
|
287
|
-
let [applyCandidates, important] = extractApplyCandidates(apply.params);
|
|
288
|
-
if (apply.parent.type === "atrule") {
|
|
289
|
-
if (apply.parent.name === "screen") {
|
|
290
|
-
const screenType = apply.parent.params;
|
|
291
|
-
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}`
|
|
292
|
-
).join(" ")} instead.`);
|
|
292
|
+
if (replacedSelector === utilitySelector) {
|
|
293
|
+
continue;
|
|
293
294
|
}
|
|
294
|
-
|
|
295
|
+
replaced.push(replacedSelector);
|
|
295
296
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
297
|
+
return replaced.join(", ");
|
|
298
|
+
}).join(", ");
|
|
299
|
+
}
|
|
300
|
+
let perParentApplies = new Map();
|
|
301
|
+
// Collect all apply candidates and their rules
|
|
302
|
+
for (let apply of applies){
|
|
303
|
+
let [candidates] = perParentApplies.get(apply.parent) || [
|
|
304
|
+
[],
|
|
305
|
+
apply.source
|
|
306
|
+
];
|
|
307
|
+
perParentApplies.set(apply.parent, [
|
|
308
|
+
candidates,
|
|
309
|
+
apply.source
|
|
310
|
+
]);
|
|
311
|
+
let [applyCandidates, important] = extractApplyCandidates(apply.params);
|
|
312
|
+
if (apply.parent.type === "atrule") {
|
|
313
|
+
if (apply.parent.name === "screen") {
|
|
314
|
+
const screenType = apply.parent.params;
|
|
315
|
+
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}`).join(" ")} instead.`);
|
|
313
316
|
}
|
|
317
|
+
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}.`);
|
|
314
318
|
}
|
|
315
|
-
for (
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
319
|
+
for (let applyCandidate of applyCandidates){
|
|
320
|
+
if ([
|
|
321
|
+
prefix(context, "group"),
|
|
322
|
+
prefix(context, "peer")
|
|
323
|
+
].includes(applyCandidate)) {
|
|
324
|
+
// TODO: Link to specific documentation page with error code.
|
|
325
|
+
throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
|
|
326
|
+
}
|
|
327
|
+
if (!applyClassCache.has(applyCandidate)) {
|
|
328
|
+
throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
|
|
329
|
+
}
|
|
330
|
+
let rules = applyClassCache.get(applyCandidate);
|
|
331
|
+
candidates.push([
|
|
332
|
+
applyCandidate,
|
|
333
|
+
important,
|
|
334
|
+
rules
|
|
335
|
+
]);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
for (const [parent, [candidates1, atApplySource]] of perParentApplies){
|
|
339
|
+
let siblings = [];
|
|
340
|
+
for (let [applyCandidate, important, rules] of candidates1){
|
|
341
|
+
let potentialApplyCandidates = [
|
|
342
|
+
applyCandidate,
|
|
343
|
+
...extractBaseCandidates([
|
|
344
|
+
applyCandidate
|
|
345
|
+
], context.tailwindConfig.separator),
|
|
346
|
+
];
|
|
347
|
+
for (let [meta, node1] of rules){
|
|
348
|
+
let parentClasses = extractClasses(parent);
|
|
349
|
+
let nodeClasses = extractClasses(node1);
|
|
350
|
+
// 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`
|
|
351
|
+
// So we've split them into groups
|
|
352
|
+
nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
|
|
353
|
+
// Add base utility classes from the @apply node to the list of
|
|
354
|
+
// classes to check whether it intersects and therefore results in a
|
|
355
|
+
// circular dependency or not.
|
|
356
|
+
//
|
|
357
|
+
// E.g.:
|
|
358
|
+
// .foo {
|
|
359
|
+
// @apply hover:a; // This applies "a" but with a modifier
|
|
360
|
+
// }
|
|
361
|
+
//
|
|
362
|
+
// We only have to do that with base classes of the `node`, not of the `parent`
|
|
363
|
+
// E.g.:
|
|
364
|
+
// .hover\:foo {
|
|
365
|
+
// @apply bar;
|
|
366
|
+
// }
|
|
367
|
+
// .bar {
|
|
368
|
+
// @apply foo;
|
|
369
|
+
// }
|
|
370
|
+
//
|
|
371
|
+
// This should not result in a circular dependency because we are
|
|
372
|
+
// just applying `.foo` and the rule above is `.hover\:foo` which is
|
|
373
|
+
// unrelated. However, if we were to apply `hover:foo` then we _did_
|
|
374
|
+
// have to include this one.
|
|
375
|
+
nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
|
|
376
|
+
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
|
|
377
|
+
if (intersects) {
|
|
378
|
+
throw node1.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
|
|
379
|
+
}
|
|
380
|
+
let root = _postcss.default.root({
|
|
381
|
+
nodes: [
|
|
382
|
+
node1.clone()
|
|
383
|
+
]
|
|
384
|
+
});
|
|
385
|
+
// Make sure every node in the entire tree points back at the @apply rule that generated it
|
|
386
|
+
root.walk((node)=>{
|
|
387
|
+
node.source = atApplySource;
|
|
388
|
+
});
|
|
389
|
+
let canRewriteSelector = node1.type !== "atrule" || node1.type === "atrule" && node1.name !== "keyframes";
|
|
390
|
+
if (canRewriteSelector) {
|
|
391
|
+
root.walkRules((rule)=>{
|
|
392
|
+
// Let's imagine you have the following structure:
|
|
393
|
+
//
|
|
394
|
+
// .foo {
|
|
395
|
+
// @apply bar;
|
|
396
|
+
// }
|
|
397
|
+
//
|
|
398
|
+
// @supports (a: b) {
|
|
399
|
+
// .bar {
|
|
400
|
+
// color: blue
|
|
401
|
+
// }
|
|
402
|
+
//
|
|
403
|
+
// .something-unrelated {}
|
|
404
|
+
// }
|
|
405
|
+
//
|
|
406
|
+
// In this case we want to apply `.bar` but it happens to be in
|
|
407
|
+
// an atrule node. We clone that node instead of the nested one
|
|
408
|
+
// because we still want that @supports rule to be there once we
|
|
409
|
+
// applied everything.
|
|
410
|
+
//
|
|
411
|
+
// However it happens to be that the `.something-unrelated` is
|
|
412
|
+
// also in that same shared @supports atrule. This is not good,
|
|
413
|
+
// and this should not be there. The good part is that this is
|
|
414
|
+
// a clone already and it can be safely removed. The question is
|
|
415
|
+
// how do we know we can remove it. Basically what we can do is
|
|
416
|
+
// match it against the applyCandidate that you want to apply. If
|
|
417
|
+
// it doesn't match the we can safely delete it.
|
|
418
|
+
//
|
|
419
|
+
// If we didn't do this, then the `replaceSelector` function
|
|
420
|
+
// would have replaced this with something that didn't exist and
|
|
421
|
+
// therefore it removed the selector altogether. In this specific
|
|
422
|
+
// case it would result in `{}` instead of `.something-unrelated {}`
|
|
423
|
+
if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate)) {
|
|
424
|
+
rule.remove();
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
// Strip the important selector from the parent selector if at the beginning
|
|
428
|
+
let importantSelector = typeof context.tailwindConfig.important === "string" ? context.tailwindConfig.important : null;
|
|
429
|
+
// We only want to move the "important" selector if this is a Tailwind-generated utility
|
|
430
|
+
// We do *not* want to do this for user CSS that happens to be structured the same
|
|
431
|
+
let isGenerated = parent.raws.tailwind !== undefined;
|
|
432
|
+
let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
|
|
433
|
+
rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate);
|
|
434
|
+
// And then re-add it if it was removed
|
|
435
|
+
if (importantSelector && parentSelector !== parent.selector) {
|
|
436
|
+
rule.selector = `${importantSelector} ${rule.selector}`;
|
|
437
|
+
}
|
|
438
|
+
rule.walkDecls((d)=>{
|
|
439
|
+
d.important = meta.important || important;
|
|
401
440
|
});
|
|
402
|
-
}
|
|
403
|
-
// Insert it
|
|
404
|
-
siblings.push([
|
|
405
|
-
// Ensure that when we are sorting, that we take the layer order into account
|
|
406
|
-
{
|
|
407
|
-
...meta,
|
|
408
|
-
sort: meta.sort | context.layerOrder[meta.layer]
|
|
409
|
-
},
|
|
410
|
-
root.nodes[0],
|
|
411
|
-
]);
|
|
441
|
+
});
|
|
412
442
|
}
|
|
443
|
+
// Insert it
|
|
444
|
+
siblings.push([
|
|
445
|
+
// Ensure that when we are sorting, that we take the layer order into account
|
|
446
|
+
{
|
|
447
|
+
...meta,
|
|
448
|
+
sort: meta.sort | context.layerOrder[meta.layer]
|
|
449
|
+
},
|
|
450
|
+
root.nodes[0],
|
|
451
|
+
]);
|
|
413
452
|
}
|
|
414
|
-
// Inject the rules, sorted, correctly
|
|
415
|
-
let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)
|
|
416
|
-
).map((s)=>s[1]
|
|
417
|
-
);
|
|
418
|
-
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
419
|
-
parent.after(nodes);
|
|
420
453
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
454
|
+
// Inject the rules, sorted, correctly
|
|
455
|
+
let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)).map((s)=>s[1]);
|
|
456
|
+
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
457
|
+
parent.after(nodes);
|
|
458
|
+
}
|
|
459
|
+
for (let apply1 of applies){
|
|
460
|
+
// If there are left-over declarations, just remove the @apply
|
|
461
|
+
if (apply1.parent.nodes.length > 1) {
|
|
462
|
+
apply1.remove();
|
|
463
|
+
} else {
|
|
464
|
+
// The node is empty, drop the full node
|
|
465
|
+
apply1.parent.remove();
|
|
429
466
|
}
|
|
430
|
-
// Do it again, in case we have other `@apply` rules
|
|
431
|
-
processApply(root, context, localCache);
|
|
432
467
|
}
|
|
468
|
+
// Do it again, in case we have other `@apply` rules
|
|
469
|
+
processApply(root, context, localCache);
|
|
433
470
|
}
|
|
@@ -29,8 +29,7 @@ function expandTailwindAtRules(context) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
if (Object.values(layerNodes).every((n)=>n === null
|
|
33
|
-
)) {
|
|
32
|
+
if (Object.values(layerNodes).every((n)=>n === null)) {
|
|
34
33
|
return root;
|
|
35
34
|
}
|
|
36
35
|
// ---
|
|
@@ -42,7 +41,7 @@ function expandTailwindAtRules(context) {
|
|
|
42
41
|
env.DEBUG && console.time("Reading changed files");
|
|
43
42
|
for (let { content , extension } of context.changedContent){
|
|
44
43
|
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
45
|
-
let extractor = getExtractor(context
|
|
44
|
+
let extractor = getExtractor(context, extension);
|
|
46
45
|
getClassCandidates(transformer(content), extractor, candidates, seen);
|
|
47
46
|
}
|
|
48
47
|
env.DEBUG && console.timeEnd("Reading changed files");
|
|
@@ -144,39 +143,56 @@ function _interopRequireDefault(obj) {
|
|
|
144
143
|
default: obj
|
|
145
144
|
};
|
|
146
145
|
}
|
|
146
|
+
function _getRequireWildcardCache() {
|
|
147
|
+
if (typeof WeakMap !== "function") return null;
|
|
148
|
+
var cache = new WeakMap();
|
|
149
|
+
_getRequireWildcardCache = function() {
|
|
150
|
+
return cache;
|
|
151
|
+
};
|
|
152
|
+
return cache;
|
|
153
|
+
}
|
|
147
154
|
function _interopRequireWildcard(obj) {
|
|
148
155
|
if (obj && obj.__esModule) {
|
|
149
156
|
return obj;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
}
|
|
158
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
159
|
+
return {
|
|
160
|
+
default: obj
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
var cache = _getRequireWildcardCache();
|
|
164
|
+
if (cache && cache.has(obj)) {
|
|
165
|
+
return cache.get(obj);
|
|
166
|
+
}
|
|
167
|
+
var newObj = {};
|
|
168
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
169
|
+
for(var key in obj){
|
|
170
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
171
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
172
|
+
if (desc && (desc.get || desc.set)) {
|
|
173
|
+
Object.defineProperty(newObj, key, desc);
|
|
174
|
+
} else {
|
|
175
|
+
newObj[key] = obj[key];
|
|
162
176
|
}
|
|
163
177
|
}
|
|
164
|
-
newObj.default = obj;
|
|
165
|
-
return newObj;
|
|
166
178
|
}
|
|
179
|
+
newObj.default = obj;
|
|
180
|
+
if (cache) {
|
|
181
|
+
cache.set(obj, newObj);
|
|
182
|
+
}
|
|
183
|
+
return newObj;
|
|
167
184
|
}
|
|
168
185
|
let env = sharedState.env;
|
|
169
186
|
const builtInExtractors = {
|
|
170
187
|
DEFAULT: _defaultExtractor.defaultExtractor
|
|
171
188
|
};
|
|
172
189
|
const builtInTransformers = {
|
|
173
|
-
DEFAULT: (content)=>content
|
|
174
|
-
,
|
|
190
|
+
DEFAULT: (content)=>content,
|
|
175
191
|
svelte: (content)=>content.replace(/(?:^|\s)class:/g, " ")
|
|
176
192
|
};
|
|
177
|
-
function getExtractor(
|
|
178
|
-
let extractors = tailwindConfig.content.extract;
|
|
179
|
-
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT;
|
|
193
|
+
function getExtractor(context, fileExtension) {
|
|
194
|
+
let extractors = context.tailwindConfig.content.extract;
|
|
195
|
+
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT(context);
|
|
180
196
|
}
|
|
181
197
|
function getTransformer(tailwindConfig, fileExtension) {
|
|
182
198
|
let transformers = tailwindConfig.content.transform;
|
|
@@ -203,8 +219,7 @@ function getClassCandidates(content, extractor, candidates, seen) {
|
|
|
203
219
|
candidates.add(match);
|
|
204
220
|
}
|
|
205
221
|
} else {
|
|
206
|
-
let extractorMatches = extractor(line).filter((s)=>s !== "!*"
|
|
207
|
-
);
|
|
222
|
+
let extractorMatches = extractor(line).filter((s)=>s !== "!*");
|
|
208
223
|
let lineMatchesSet = new Set(extractorMatches);
|
|
209
224
|
for (let match of lineMatchesSet){
|
|
210
225
|
candidates.add(match);
|
|
@@ -214,8 +229,7 @@ function getClassCandidates(content, extractor, candidates, seen) {
|
|
|
214
229
|
}
|
|
215
230
|
}
|
|
216
231
|
function buildStylesheet(rules, context) {
|
|
217
|
-
let sortedRules = rules.sort(([a], [z])=>(0, _bigSign).default(a - z)
|
|
218
|
-
);
|
|
232
|
+
let sortedRules = rules.sort(([a], [z])=>(0, _bigSign).default(a - z));
|
|
219
233
|
let returnValue = {
|
|
220
234
|
base: new Set(),
|
|
221
235
|
defaults: new Set(),
|