tailwindcss 3.1.6 → 3.1.7
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 +18 -2
- package/lib/cli-peer-dependencies.js +12 -4
- package/lib/cli.js +78 -75
- package/lib/constants.js +19 -12
- package/lib/corePluginList.js +5 -3
- package/lib/corePlugins.js +194 -187
- package/lib/featureFlags.js +14 -7
- package/lib/index.js +9 -6
- package/lib/lib/cacheInvalidation.js +18 -15
- package/lib/lib/collapseAdjacentRules.js +14 -11
- package/lib/lib/collapseDuplicateDeclarations.js +11 -8
- package/lib/lib/defaultExtractor.js +38 -35
- package/lib/lib/detectNesting.js +4 -1
- package/lib/lib/evaluateTailwindFunctions.js +37 -34
- package/lib/lib/expandApplyAtRules.js +45 -42
- package/lib/lib/expandTailwindAtRules.js +153 -150
- package/lib/lib/generateRules.js +80 -70
- package/lib/lib/getModuleDependencies.js +21 -18
- package/lib/lib/normalizeTailwindDirectives.js +10 -7
- package/lib/lib/partitionApplyAtRules.js +14 -11
- package/lib/lib/regex.js +15 -7
- package/lib/lib/resolveDefaultsAtRules.js +92 -85
- package/lib/lib/setupContextUtils.js +109 -97
- package/lib/lib/setupTrackingContext.js +82 -75
- package/lib/lib/sharedState.js +15 -8
- package/lib/lib/substituteScreenAtRules.js +8 -5
- package/lib/postcss-plugins/nesting/index.js +7 -5
- package/lib/postcss-plugins/nesting/plugin.js +7 -4
- package/lib/processTailwindFeatures.js +34 -31
- package/lib/public/colors.js +6 -4
- 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 +5 -2
- package/lib/util/cloneDeep.js +4 -1
- package/lib/util/cloneNodes.js +9 -2
- package/lib/util/color.js +11 -3
- package/lib/util/configurePlugins.js +4 -1
- package/lib/util/createPlugin.js +5 -3
- package/lib/util/createUtilityPlugin.js +13 -10
- package/lib/util/dataTypes.js +27 -19
- 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 +5 -3
- package/lib/util/formatVariantSelector.js +21 -14
- package/lib/util/getAllConfigs.js +12 -9
- 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 -24
- package/lib/util/log.js +12 -5
- package/lib/util/nameClass.js +16 -8
- package/lib/util/negateValue.js +4 -1
- package/lib/util/normalizeConfig.js +26 -23
- package/lib/util/normalizeScreens.js +17 -2
- package/lib/util/parseAnimationValue.js +42 -39
- package/lib/util/parseBoxShadowValue.js +12 -4
- package/lib/util/parseDependency.js +35 -32
- package/lib/util/parseObjectStyles.js +14 -11
- package/lib/util/pluginUtils.js +28 -20
- package/lib/util/prefixSelector.js +6 -3
- package/lib/util/removeAlphaVariables.js +13 -2
- package/lib/util/resolveConfig.js +55 -52
- package/lib/util/resolveConfigPath.js +20 -17
- package/lib/util/responsive.js +12 -9
- package/lib/util/splitAtTopLevelOnly.js +16 -13
- 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 +10 -7
- package/lib/util/validateConfig.js +5 -2
- package/lib/util/withAlphaVariable.js +30 -22
- package/package.json +8 -8
- package/peers/index.js +13 -4
- package/resolveConfig.d.ts +3 -0
- package/src/lib/generateRules.js +5 -1
- package/src/lib/setupContextUtils.js +4 -2
- package/src/util/cloneNodes.js +5 -1
|
@@ -2,19 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
|
|
15
|
-
processApply(root, context, localCache);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
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"));
|
|
18
14
|
function _interopRequireDefault(obj) {
|
|
19
15
|
return obj && obj.__esModule ? obj : {
|
|
20
16
|
default: obj
|
|
@@ -28,7 +24,7 @@ function _interopRequireDefault(obj) {
|
|
|
28
24
|
]
|
|
29
25
|
});
|
|
30
26
|
container.walkRules((rule)=>{
|
|
31
|
-
(0, _postcssSelectorParser
|
|
27
|
+
(0, _postcssSelectorParser.default)((selectors)=>{
|
|
32
28
|
selectors.walkClasses((classSelector)=>{
|
|
33
29
|
let parentSelector = classSelector.parent.toString();
|
|
34
30
|
let classes = groups.get(parentSelector);
|
|
@@ -40,12 +36,12 @@ function _interopRequireDefault(obj) {
|
|
|
40
36
|
}).processSync(rule.selector);
|
|
41
37
|
});
|
|
42
38
|
let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
|
|
43
|
-
let
|
|
44
|
-
return Object.assign(
|
|
39
|
+
let classes = normalizedGroups.flat();
|
|
40
|
+
return Object.assign(classes, {
|
|
45
41
|
groups: normalizedGroups
|
|
46
42
|
});
|
|
47
43
|
}
|
|
48
|
-
let selectorExtractor = (0, _postcssSelectorParser
|
|
44
|
+
let selectorExtractor = (0, _postcssSelectorParser.default)((root)=>root.nodes.map((node)=>node.toString()));
|
|
49
45
|
/**
|
|
50
46
|
* @param {string} ruleSelectors
|
|
51
47
|
*/ function extractSelectors(ruleSelectors) {
|
|
@@ -59,8 +55,8 @@ function extractBaseCandidates(candidates, separator) {
|
|
|
59
55
|
return Array.from(baseClasses);
|
|
60
56
|
}
|
|
61
57
|
function prefix(context, selector) {
|
|
62
|
-
let
|
|
63
|
-
return typeof
|
|
58
|
+
let prefix = context.tailwindConfig.prefix;
|
|
59
|
+
return typeof prefix === "function" ? prefix(selector) : prefix + selector;
|
|
64
60
|
}
|
|
65
61
|
function* pathToRoot(node) {
|
|
66
62
|
yield node;
|
|
@@ -181,7 +177,7 @@ function* pathToRoot(node) {
|
|
|
181
177
|
]));
|
|
182
178
|
continue;
|
|
183
179
|
}
|
|
184
|
-
let matches = Array.from((0, _generateRules
|
|
180
|
+
let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
|
|
185
181
|
if (matches.length === 0) {
|
|
186
182
|
context.notClassCache.add(candidate);
|
|
187
183
|
continue;
|
|
@@ -274,11 +270,11 @@ function processApply(root, context, localCache) {
|
|
|
274
270
|
* Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
|
|
275
271
|
*/ // TODO: Should we use postcss-selector-parser for this instead?
|
|
276
272
|
function replaceSelector(selector, utilitySelectors, candidate) {
|
|
277
|
-
let
|
|
273
|
+
let needle = `.${(0, _escapeClassName.default)(candidate)}`;
|
|
278
274
|
let needles = [
|
|
279
275
|
...new Set([
|
|
280
|
-
|
|
281
|
-
|
|
276
|
+
needle,
|
|
277
|
+
needle.replace(/\\2c /g, "\\,")
|
|
282
278
|
])
|
|
283
279
|
];
|
|
284
280
|
let utilitySelectorsList = extractSelectors(utilitySelectors);
|
|
@@ -308,15 +304,15 @@ function processApply(root, context, localCache) {
|
|
|
308
304
|
candidates,
|
|
309
305
|
apply.source
|
|
310
306
|
]);
|
|
311
|
-
let [
|
|
307
|
+
let [applyCandidates1, important] = extractApplyCandidates(apply.params);
|
|
312
308
|
if (apply.parent.type === "atrule") {
|
|
313
309
|
if (apply.parent.name === "screen") {
|
|
314
310
|
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 ${
|
|
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.`);
|
|
316
312
|
}
|
|
317
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}.`);
|
|
318
314
|
}
|
|
319
|
-
for (let applyCandidate of
|
|
315
|
+
for (let applyCandidate of applyCandidates1){
|
|
320
316
|
if ([
|
|
321
317
|
prefix(context, "group"),
|
|
322
318
|
prefix(context, "peer")
|
|
@@ -337,16 +333,16 @@ function processApply(root, context, localCache) {
|
|
|
337
333
|
}
|
|
338
334
|
for (const [parent, [candidates1, atApplySource]] of perParentApplies){
|
|
339
335
|
let siblings = [];
|
|
340
|
-
for (let [
|
|
336
|
+
for (let [applyCandidate1, important1, rules1] of candidates1){
|
|
341
337
|
let potentialApplyCandidates = [
|
|
342
|
-
|
|
338
|
+
applyCandidate1,
|
|
343
339
|
...extractBaseCandidates([
|
|
344
|
-
|
|
340
|
+
applyCandidate1
|
|
345
341
|
], context.tailwindConfig.separator),
|
|
346
342
|
];
|
|
347
|
-
for (let [meta,
|
|
343
|
+
for (let [meta, node] of rules1){
|
|
348
344
|
let parentClasses = extractClasses(parent);
|
|
349
|
-
let nodeClasses = extractClasses(
|
|
345
|
+
let nodeClasses = extractClasses(node);
|
|
350
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`
|
|
351
347
|
// So we've split them into groups
|
|
352
348
|
nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
|
|
@@ -375,20 +371,20 @@ function processApply(root, context, localCache) {
|
|
|
375
371
|
nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
|
|
376
372
|
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
|
|
377
373
|
if (intersects) {
|
|
378
|
-
throw
|
|
374
|
+
throw node.error(`You cannot \`@apply\` the \`${applyCandidate1}\` utility here because it creates a circular dependency.`);
|
|
379
375
|
}
|
|
380
|
-
let
|
|
376
|
+
let root1 = _postcss.default.root({
|
|
381
377
|
nodes: [
|
|
382
|
-
|
|
378
|
+
node.clone()
|
|
383
379
|
]
|
|
384
380
|
});
|
|
385
381
|
// Make sure every node in the entire tree points back at the @apply rule that generated it
|
|
386
|
-
|
|
382
|
+
root1.walk((node)=>{
|
|
387
383
|
node.source = atApplySource;
|
|
388
384
|
});
|
|
389
|
-
let canRewriteSelector =
|
|
385
|
+
let canRewriteSelector = node.type !== "atrule" || node.type === "atrule" && node.name !== "keyframes";
|
|
390
386
|
if (canRewriteSelector) {
|
|
391
|
-
|
|
387
|
+
root1.walkRules((rule)=>{
|
|
392
388
|
// Let's imagine you have the following structure:
|
|
393
389
|
//
|
|
394
390
|
// .foo {
|
|
@@ -420,7 +416,7 @@ function processApply(root, context, localCache) {
|
|
|
420
416
|
// would have replaced this with something that didn't exist and
|
|
421
417
|
// therefore it removed the selector altogether. In this specific
|
|
422
418
|
// case it would result in `{}` instead of `.something-unrelated {}`
|
|
423
|
-
if (!extractClasses(rule).some((candidate)=>candidate ===
|
|
419
|
+
if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate1)) {
|
|
424
420
|
rule.remove();
|
|
425
421
|
return;
|
|
426
422
|
}
|
|
@@ -430,13 +426,13 @@ function processApply(root, context, localCache) {
|
|
|
430
426
|
// We do *not* want to do this for user CSS that happens to be structured the same
|
|
431
427
|
let isGenerated = parent.raws.tailwind !== undefined;
|
|
432
428
|
let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
|
|
433
|
-
rule.selector = replaceSelector(parentSelector, rule.selector,
|
|
429
|
+
rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate1);
|
|
434
430
|
// And then re-add it if it was removed
|
|
435
431
|
if (importantSelector && parentSelector !== parent.selector) {
|
|
436
432
|
rule.selector = `${importantSelector} ${rule.selector}`;
|
|
437
433
|
}
|
|
438
434
|
rule.walkDecls((d)=>{
|
|
439
|
-
d.important = meta.important ||
|
|
435
|
+
d.important = meta.important || important1;
|
|
440
436
|
});
|
|
441
437
|
});
|
|
442
438
|
}
|
|
@@ -447,12 +443,12 @@ function processApply(root, context, localCache) {
|
|
|
447
443
|
...meta,
|
|
448
444
|
sort: meta.sort | context.layerOrder[meta.layer]
|
|
449
445
|
},
|
|
450
|
-
|
|
446
|
+
root1.nodes[0],
|
|
451
447
|
]);
|
|
452
448
|
}
|
|
453
449
|
}
|
|
454
450
|
// Inject the rules, sorted, correctly
|
|
455
|
-
let nodes = siblings.sort(([a], [z])=>(0, _bigSign
|
|
451
|
+
let nodes = siblings.sort(([a], [z])=>(0, _bigSign.default)(a.sort - z.sort)).map((s)=>s[1]);
|
|
456
452
|
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
457
453
|
parent.after(nodes);
|
|
458
454
|
}
|
|
@@ -468,3 +464,10 @@ function processApply(root, context, localCache) {
|
|
|
468
464
|
// Do it again, in case we have other `@apply` rules
|
|
469
465
|
processApply(root, context, localCache);
|
|
470
466
|
}
|
|
467
|
+
function expandApplyAtRules(context) {
|
|
468
|
+
return (root)=>{
|
|
469
|
+
// Build a cache of the user's CSS so we can use it to resolve classes used by @apply
|
|
470
|
+
let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
|
|
471
|
+
processApply(root, context, localCache);
|
|
472
|
+
};
|
|
473
|
+
}
|
|
@@ -2,157 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
base: null,
|
|
17
|
-
components: null,
|
|
18
|
-
utilities: null,
|
|
19
|
-
variants: null
|
|
20
|
-
};
|
|
21
|
-
root.walkAtRules((rule)=>{
|
|
22
|
-
// Make sure this file contains Tailwind directives. If not, we can save
|
|
23
|
-
// a lot of work and bail early. Also we don't have to register our touch
|
|
24
|
-
// file as a dependency since the output of this CSS does not depend on
|
|
25
|
-
// the source of any templates. Think Vue <style> blocks for example.
|
|
26
|
-
if (rule.name === "tailwind") {
|
|
27
|
-
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
28
|
-
layerNodes[rule.params] = rule;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
if (Object.values(layerNodes).every((n)=>n === null)) {
|
|
33
|
-
return root;
|
|
34
|
-
}
|
|
35
|
-
// ---
|
|
36
|
-
// Find potential rules in changed files
|
|
37
|
-
let candidates = new Set([
|
|
38
|
-
sharedState.NOT_ON_DEMAND
|
|
39
|
-
]);
|
|
40
|
-
let seen = new Set();
|
|
41
|
-
env.DEBUG && console.time("Reading changed files");
|
|
42
|
-
for (let { content , extension } of context.changedContent){
|
|
43
|
-
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
44
|
-
let extractor = getExtractor(context, extension);
|
|
45
|
-
getClassCandidates(transformer(content), extractor, candidates, seen);
|
|
46
|
-
}
|
|
47
|
-
env.DEBUG && console.timeEnd("Reading changed files");
|
|
48
|
-
// ---
|
|
49
|
-
// Generate the actual CSS
|
|
50
|
-
let classCacheCount = context.classCache.size;
|
|
51
|
-
env.DEBUG && console.time("Generate rules");
|
|
52
|
-
let rules = (0, _generateRules).generateRules(candidates, context);
|
|
53
|
-
env.DEBUG && console.timeEnd("Generate rules");
|
|
54
|
-
// We only ever add to the classCache, so if it didn't grow, there is nothing new.
|
|
55
|
-
env.DEBUG && console.time("Build stylesheet");
|
|
56
|
-
if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
|
|
57
|
-
for (let rule of rules){
|
|
58
|
-
context.ruleCache.add(rule);
|
|
59
|
-
}
|
|
60
|
-
context.stylesheetCache = buildStylesheet([
|
|
61
|
-
...context.ruleCache
|
|
62
|
-
], context);
|
|
63
|
-
}
|
|
64
|
-
env.DEBUG && console.timeEnd("Build stylesheet");
|
|
65
|
-
let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
66
|
-
// ---
|
|
67
|
-
// Replace any Tailwind directives with generated CSS
|
|
68
|
-
if (layerNodes.base) {
|
|
69
|
-
layerNodes.base.before((0, _cloneNodes).default([
|
|
70
|
-
...baseNodes,
|
|
71
|
-
...defaultNodes
|
|
72
|
-
], layerNodes.base.source, {
|
|
73
|
-
layer: "base"
|
|
74
|
-
}));
|
|
75
|
-
layerNodes.base.remove();
|
|
76
|
-
}
|
|
77
|
-
if (layerNodes.components) {
|
|
78
|
-
layerNodes.components.before((0, _cloneNodes).default([
|
|
79
|
-
...componentNodes
|
|
80
|
-
], layerNodes.components.source, {
|
|
81
|
-
layer: "components"
|
|
82
|
-
}));
|
|
83
|
-
layerNodes.components.remove();
|
|
84
|
-
}
|
|
85
|
-
if (layerNodes.utilities) {
|
|
86
|
-
layerNodes.utilities.before((0, _cloneNodes).default([
|
|
87
|
-
...utilityNodes
|
|
88
|
-
], layerNodes.utilities.source, {
|
|
89
|
-
layer: "utilities"
|
|
90
|
-
}));
|
|
91
|
-
layerNodes.utilities.remove();
|
|
92
|
-
}
|
|
93
|
-
// We do post-filtering to not alter the emitted order of the variants
|
|
94
|
-
const variantNodes = Array.from(screenNodes).filter((node)=>{
|
|
95
|
-
var ref;
|
|
96
|
-
const parentLayer = (ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer;
|
|
97
|
-
if (parentLayer === "components") {
|
|
98
|
-
return layerNodes.components !== null;
|
|
99
|
-
}
|
|
100
|
-
if (parentLayer === "utilities") {
|
|
101
|
-
return layerNodes.utilities !== null;
|
|
102
|
-
}
|
|
103
|
-
return true;
|
|
104
|
-
});
|
|
105
|
-
if (layerNodes.variants) {
|
|
106
|
-
layerNodes.variants.before((0, _cloneNodes).default(variantNodes, layerNodes.variants.source, {
|
|
107
|
-
layer: "variants"
|
|
108
|
-
}));
|
|
109
|
-
layerNodes.variants.remove();
|
|
110
|
-
} else if (variantNodes.length > 0) {
|
|
111
|
-
root.append((0, _cloneNodes).default(variantNodes, root.source, {
|
|
112
|
-
layer: "variants"
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
// If we've got a utility layer and no utilities are generated there's likely something wrong
|
|
116
|
-
const hasUtilityVariants = variantNodes.some((node)=>{
|
|
117
|
-
var ref;
|
|
118
|
-
return ((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer) === "utilities";
|
|
119
|
-
});
|
|
120
|
-
if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
|
|
121
|
-
_log.default.warn("content-problems", [
|
|
122
|
-
"No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.",
|
|
123
|
-
"https://tailwindcss.com/docs/content-configuration",
|
|
124
|
-
]);
|
|
125
|
-
}
|
|
126
|
-
// ---
|
|
127
|
-
if (env.DEBUG) {
|
|
128
|
-
console.log("Potential classes: ", candidates.size);
|
|
129
|
-
console.log("Active contexts: ", sharedState.contextSourcesMap.size);
|
|
130
|
-
}
|
|
131
|
-
// Clear the cache for the changed files
|
|
132
|
-
context.changedContent = [];
|
|
133
|
-
// Cleanup any leftover @layer atrules
|
|
134
|
-
root.walkAtRules("layer", (rule)=>{
|
|
135
|
-
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
136
|
-
rule.remove();
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
}
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>expandTailwindAtRules
|
|
8
|
+
});
|
|
9
|
+
const _quickLru = /*#__PURE__*/ _interopRequireDefault(require("quick-lru"));
|
|
10
|
+
const _sharedState = /*#__PURE__*/ _interopRequireWildcard(require("./sharedState"));
|
|
11
|
+
const _generateRules = require("./generateRules");
|
|
12
|
+
const _bigSign = /*#__PURE__*/ _interopRequireDefault(require("../util/bigSign"));
|
|
13
|
+
const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
|
|
14
|
+
const _cloneNodes = /*#__PURE__*/ _interopRequireDefault(require("../util/cloneNodes"));
|
|
15
|
+
const _defaultExtractor = require("./defaultExtractor");
|
|
141
16
|
function _interopRequireDefault(obj) {
|
|
142
17
|
return obj && obj.__esModule ? obj : {
|
|
143
18
|
default: obj
|
|
144
19
|
};
|
|
145
20
|
}
|
|
146
|
-
function _getRequireWildcardCache() {
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
147
22
|
if (typeof WeakMap !== "function") return null;
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
23
|
+
var cacheBabelInterop = new WeakMap();
|
|
24
|
+
var cacheNodeInterop = new WeakMap();
|
|
25
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
26
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
27
|
+
})(nodeInterop);
|
|
153
28
|
}
|
|
154
|
-
function _interopRequireWildcard(obj) {
|
|
155
|
-
if (obj && obj.__esModule) {
|
|
29
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
30
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
156
31
|
return obj;
|
|
157
32
|
}
|
|
158
33
|
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
@@ -160,14 +35,14 @@ function _interopRequireWildcard(obj) {
|
|
|
160
35
|
default: obj
|
|
161
36
|
};
|
|
162
37
|
}
|
|
163
|
-
var cache = _getRequireWildcardCache();
|
|
38
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
164
39
|
if (cache && cache.has(obj)) {
|
|
165
40
|
return cache.get(obj);
|
|
166
41
|
}
|
|
167
42
|
var newObj = {};
|
|
168
43
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
169
44
|
for(var key in obj){
|
|
170
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
45
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
171
46
|
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
172
47
|
if (desc && (desc.get || desc.set)) {
|
|
173
48
|
Object.defineProperty(newObj, key, desc);
|
|
@@ -182,7 +57,7 @@ function _interopRequireWildcard(obj) {
|
|
|
182
57
|
}
|
|
183
58
|
return newObj;
|
|
184
59
|
}
|
|
185
|
-
let env =
|
|
60
|
+
let env = _sharedState.env;
|
|
186
61
|
const builtInExtractors = {
|
|
187
62
|
DEFAULT: _defaultExtractor.defaultExtractor
|
|
188
63
|
};
|
|
@@ -221,15 +96,15 @@ function getClassCandidates(content, extractor, candidates, seen) {
|
|
|
221
96
|
} else {
|
|
222
97
|
let extractorMatches = extractor(line).filter((s)=>s !== "!*");
|
|
223
98
|
let lineMatchesSet = new Set(extractorMatches);
|
|
224
|
-
for (let
|
|
225
|
-
candidates.add(
|
|
99
|
+
for (let match1 of lineMatchesSet){
|
|
100
|
+
candidates.add(match1);
|
|
226
101
|
}
|
|
227
102
|
extractorCache.get(extractor).set(line, lineMatchesSet);
|
|
228
103
|
}
|
|
229
104
|
}
|
|
230
105
|
}
|
|
231
106
|
function buildStylesheet(rules, context) {
|
|
232
|
-
let sortedRules = rules.sort(([a], [z])=>(0, _bigSign
|
|
107
|
+
let sortedRules = rules.sort(([a], [z])=>(0, _bigSign.default)(a - z));
|
|
233
108
|
let returnValue = {
|
|
234
109
|
base: new Set(),
|
|
235
110
|
defaults: new Set(),
|
|
@@ -274,3 +149,131 @@ function buildStylesheet(rules, context) {
|
|
|
274
149
|
}
|
|
275
150
|
return returnValue;
|
|
276
151
|
}
|
|
152
|
+
function expandTailwindAtRules(context) {
|
|
153
|
+
return (root)=>{
|
|
154
|
+
let layerNodes = {
|
|
155
|
+
base: null,
|
|
156
|
+
components: null,
|
|
157
|
+
utilities: null,
|
|
158
|
+
variants: null
|
|
159
|
+
};
|
|
160
|
+
root.walkAtRules((rule)=>{
|
|
161
|
+
// Make sure this file contains Tailwind directives. If not, we can save
|
|
162
|
+
// a lot of work and bail early. Also we don't have to register our touch
|
|
163
|
+
// file as a dependency since the output of this CSS does not depend on
|
|
164
|
+
// the source of any templates. Think Vue <style> blocks for example.
|
|
165
|
+
if (rule.name === "tailwind") {
|
|
166
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
167
|
+
layerNodes[rule.params] = rule;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
if (Object.values(layerNodes).every((n)=>n === null)) {
|
|
172
|
+
return root;
|
|
173
|
+
}
|
|
174
|
+
// ---
|
|
175
|
+
// Find potential rules in changed files
|
|
176
|
+
let candidates = new Set([
|
|
177
|
+
_sharedState.NOT_ON_DEMAND
|
|
178
|
+
]);
|
|
179
|
+
let seen = new Set();
|
|
180
|
+
env.DEBUG && console.time("Reading changed files");
|
|
181
|
+
for (let { content , extension } of context.changedContent){
|
|
182
|
+
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
183
|
+
let extractor = getExtractor(context, extension);
|
|
184
|
+
getClassCandidates(transformer(content), extractor, candidates, seen);
|
|
185
|
+
}
|
|
186
|
+
env.DEBUG && console.timeEnd("Reading changed files");
|
|
187
|
+
// ---
|
|
188
|
+
// Generate the actual CSS
|
|
189
|
+
let classCacheCount = context.classCache.size;
|
|
190
|
+
env.DEBUG && console.time("Generate rules");
|
|
191
|
+
let rules = (0, _generateRules.generateRules)(candidates, context);
|
|
192
|
+
env.DEBUG && console.timeEnd("Generate rules");
|
|
193
|
+
// We only ever add to the classCache, so if it didn't grow, there is nothing new.
|
|
194
|
+
env.DEBUG && console.time("Build stylesheet");
|
|
195
|
+
if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
|
|
196
|
+
for (let rule of rules){
|
|
197
|
+
context.ruleCache.add(rule);
|
|
198
|
+
}
|
|
199
|
+
context.stylesheetCache = buildStylesheet([
|
|
200
|
+
...context.ruleCache
|
|
201
|
+
], context);
|
|
202
|
+
}
|
|
203
|
+
env.DEBUG && console.timeEnd("Build stylesheet");
|
|
204
|
+
let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
205
|
+
// ---
|
|
206
|
+
// Replace any Tailwind directives with generated CSS
|
|
207
|
+
if (layerNodes.base) {
|
|
208
|
+
layerNodes.base.before((0, _cloneNodes.default)([
|
|
209
|
+
...baseNodes,
|
|
210
|
+
...defaultNodes
|
|
211
|
+
], layerNodes.base.source, {
|
|
212
|
+
layer: "base"
|
|
213
|
+
}));
|
|
214
|
+
layerNodes.base.remove();
|
|
215
|
+
}
|
|
216
|
+
if (layerNodes.components) {
|
|
217
|
+
layerNodes.components.before((0, _cloneNodes.default)([
|
|
218
|
+
...componentNodes
|
|
219
|
+
], layerNodes.components.source, {
|
|
220
|
+
layer: "components"
|
|
221
|
+
}));
|
|
222
|
+
layerNodes.components.remove();
|
|
223
|
+
}
|
|
224
|
+
if (layerNodes.utilities) {
|
|
225
|
+
layerNodes.utilities.before((0, _cloneNodes.default)([
|
|
226
|
+
...utilityNodes
|
|
227
|
+
], layerNodes.utilities.source, {
|
|
228
|
+
layer: "utilities"
|
|
229
|
+
}));
|
|
230
|
+
layerNodes.utilities.remove();
|
|
231
|
+
}
|
|
232
|
+
// We do post-filtering to not alter the emitted order of the variants
|
|
233
|
+
const variantNodes = Array.from(screenNodes).filter((node)=>{
|
|
234
|
+
var ref;
|
|
235
|
+
const parentLayer = (ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer;
|
|
236
|
+
if (parentLayer === "components") {
|
|
237
|
+
return layerNodes.components !== null;
|
|
238
|
+
}
|
|
239
|
+
if (parentLayer === "utilities") {
|
|
240
|
+
return layerNodes.utilities !== null;
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
});
|
|
244
|
+
if (layerNodes.variants) {
|
|
245
|
+
layerNodes.variants.before((0, _cloneNodes.default)(variantNodes, layerNodes.variants.source, {
|
|
246
|
+
layer: "variants"
|
|
247
|
+
}));
|
|
248
|
+
layerNodes.variants.remove();
|
|
249
|
+
} else if (variantNodes.length > 0) {
|
|
250
|
+
root.append((0, _cloneNodes.default)(variantNodes, root.source, {
|
|
251
|
+
layer: "variants"
|
|
252
|
+
}));
|
|
253
|
+
}
|
|
254
|
+
// If we've got a utility layer and no utilities are generated there's likely something wrong
|
|
255
|
+
const hasUtilityVariants = variantNodes.some((node)=>{
|
|
256
|
+
var ref;
|
|
257
|
+
return ((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer) === "utilities";
|
|
258
|
+
});
|
|
259
|
+
if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
|
|
260
|
+
_log.default.warn("content-problems", [
|
|
261
|
+
"No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.",
|
|
262
|
+
"https://tailwindcss.com/docs/content-configuration",
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
265
|
+
// ---
|
|
266
|
+
if (env.DEBUG) {
|
|
267
|
+
console.log("Potential classes: ", candidates.size);
|
|
268
|
+
console.log("Active contexts: ", _sharedState.contextSourcesMap.size);
|
|
269
|
+
}
|
|
270
|
+
// Clear the cache for the changed files
|
|
271
|
+
context.changedContent = [];
|
|
272
|
+
// Cleanup any leftover @layer atrules
|
|
273
|
+
root.walkAtRules("layer", (rule)=>{
|
|
274
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
275
|
+
rule.remove();
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
}
|