tailwindcss 3.0.6 → 3.0.10
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 +47 -2
- package/README.md +8 -4
- package/lib/cli.js +49 -12
- package/lib/css/preflight.css +1 -1
- package/lib/index.js +1 -3
- package/lib/lib/collapseDuplicateDeclarations.js +52 -1
- package/lib/lib/defaultExtractor.js +42 -0
- package/lib/lib/expandApplyAtRules.js +87 -15
- package/lib/lib/expandTailwindAtRules.js +19 -32
- package/lib/lib/generateRules.js +4 -0
- package/lib/lib/normalizeTailwindDirectives.js +8 -1
- package/lib/lib/setupTrackingContext.js +11 -10
- package/lib/lib/sharedState.js +33 -4
- package/lib/processTailwindFeatures.js +2 -1
- package/lib/util/color.js +23 -8
- package/lib/util/resolveConfig.js +9 -1
- package/package.json +9 -10
- package/peers/index.js +72 -86
- package/src/cli.js +57 -12
- package/src/css/preflight.css +1 -1
- package/src/index.js +1 -7
- package/src/lib/collapseDuplicateDeclarations.js +66 -1
- package/src/lib/defaultExtractor.js +48 -0
- package/src/lib/expandApplyAtRules.js +90 -19
- package/src/lib/expandTailwindAtRules.js +21 -31
- package/src/lib/generateRules.js +5 -0
- package/src/lib/normalizeTailwindDirectives.js +6 -1
- package/src/lib/setupTrackingContext.js +11 -10
- package/src/lib/sharedState.js +40 -4
- package/src/processTailwindFeatures.js +2 -1
- package/src/util/color.js +20 -7
- package/src/util/resolveConfig.js +11 -1
- package/lib/lib/setupWatchingContext.js +0 -288
- package/src/lib/setupWatchingContext.js +0 -311
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
- Nothing yet!
|
|
11
11
|
|
|
12
|
+
## [3.0.10] - 2022-01-04
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- Fix `@apply` in files without `@tailwind` directives ([#6580](https://github.com/tailwindlabs/tailwindcss/pull/6580), [#6875](https://github.com/tailwindlabs/tailwindcss/pull/6875))
|
|
17
|
+
- CLI: avoid unnecessary writes to output files ([#6550](https://github.com/tailwindlabs/tailwindcss/pull/6550))
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Allow piping data into the CLI ([#6876](https://github.com/tailwindlabs/tailwindcss/pull/6876))
|
|
22
|
+
|
|
23
|
+
## [3.0.9] - 2022-01-03
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- Improve `DEBUG` flag ([#6797](https://github.com/tailwindlabs/tailwindcss/pull/6797), [#6804](https://github.com/tailwindlabs/tailwindcss/pull/6804))
|
|
28
|
+
- Ensure we can use `<` and `>` characters in modifiers ([#6851](https://github.com/tailwindlabs/tailwindcss/pull/6851))
|
|
29
|
+
- Validate `theme()` works in arbitrary values ([#6852](https://github.com/tailwindlabs/tailwindcss/pull/6852))
|
|
30
|
+
- Properly detect `theme()` value usage in arbitrary properties ([#6854](https://github.com/tailwindlabs/tailwindcss/pull/6854))
|
|
31
|
+
- Improve collapsing of duplicate declarations ([#6856](https://github.com/tailwindlabs/tailwindcss/pull/6856))
|
|
32
|
+
- Remove support for `TAILWIND_MODE=watch` ([#6858](https://github.com/tailwindlabs/tailwindcss/pull/6858))
|
|
33
|
+
|
|
34
|
+
## [3.0.8] - 2021-12-28
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- Reduce specificity of `abbr` rule in preflight ([#6671](https://github.com/tailwindlabs/tailwindcss/pull/6671))
|
|
39
|
+
- Support HSL with hue units in arbitrary values ([#6726](https://github.com/tailwindlabs/tailwindcss/pull/6726))
|
|
40
|
+
- Add `node16-linux-arm64` target for standalone CLI ([#6693](https://github.com/tailwindlabs/tailwindcss/pull/6693))
|
|
41
|
+
|
|
42
|
+
## [3.0.7] - 2021-12-17
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- Don't mutate custom color palette when overriding per-plugin colors ([#6546](https://github.com/tailwindlabs/tailwindcss/pull/6546))
|
|
47
|
+
- Improve circular dependency detection when using `@apply` ([#6588](https://github.com/tailwindlabs/tailwindcss/pull/6588))
|
|
48
|
+
- Only generate variants for non-`user` layers ([#6589](https://github.com/tailwindlabs/tailwindcss/pull/6589))
|
|
49
|
+
- Properly extract classes with arbitrary values in arrays and classes followed by escaped quotes ([#6590](https://github.com/tailwindlabs/tailwindcss/pull/6590))
|
|
50
|
+
- Improve jsx interpolation candidate matching ([#6593](https://github.com/tailwindlabs/tailwindcss/pull/6593))
|
|
51
|
+
- Ensure `@apply` of a rule inside an AtRule works ([#6594](https://github.com/tailwindlabs/tailwindcss/pull/6594))
|
|
52
|
+
|
|
12
53
|
## [3.0.6] - 2021-12-16
|
|
13
54
|
|
|
14
55
|
### Fixed
|
|
@@ -1730,8 +1771,12 @@ No release notes
|
|
|
1730
1771
|
|
|
1731
1772
|
- Everything!
|
|
1732
1773
|
|
|
1733
|
-
[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.
|
|
1734
|
-
[3.0.
|
|
1774
|
+
[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.10...HEAD
|
|
1775
|
+
[3.0.10]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.9...v3.0.10
|
|
1776
|
+
[3.0.9]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.8...v3.0.9
|
|
1777
|
+
[3.0.8]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.7...v3.0.8
|
|
1778
|
+
[3.0.7]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.6...v3.0.7
|
|
1779
|
+
[3.0.6]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.5...v3.0.6
|
|
1735
1780
|
[3.0.5]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.4...v3.0.5
|
|
1736
1781
|
[3.0.4]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.3...v3.0.4
|
|
1737
1782
|
[3.0.3]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.2...v3.0.3
|
package/README.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
<p>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
<a href="https://tailwindcss.com/#gh-light-mode-only" target="_blank">
|
|
3
|
+
<img src="./.github/logo-light.svg" alt="Tailwind CSS" width="350" height="70">
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://tailwindcss.com/#gh-dark-mode-only" target="_blank">
|
|
6
|
+
<img src="./.github/logo-dark.svg" alt="Tailwind CSS" width="350" height="70">
|
|
7
|
+
</a>
|
|
6
8
|
</p>
|
|
7
9
|
|
|
10
|
+
A utility-first CSS framework for rapidly building custom user interfaces.
|
|
11
|
+
|
|
8
12
|
<p>
|
|
9
13
|
<a href="https://github.com/tailwindlabs/tailwindcss/actions"><img src="https://img.shields.io/github/workflow/status/tailwindlabs/tailwindcss/Node.js%20CI" alt="Build Status"></a>
|
|
10
14
|
<a href="https://www.npmjs.com/package/tailwindcss"><img src="https://img.shields.io/npm/dt/tailwindcss.svg" alt="Total Downloads"></a>
|
package/lib/cli.js
CHANGED
|
@@ -40,6 +40,25 @@ function formatNodes(root) {
|
|
|
40
40
|
root.first.raws.before = '';
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
async function outputFile(file, contents) {
|
|
44
|
+
if (_fs.default.existsSync(file) && await _fs.default.promises.readFile(file, 'utf8') === contents) {
|
|
45
|
+
return; // Skip writing the file
|
|
46
|
+
}
|
|
47
|
+
// Write the file
|
|
48
|
+
await _fs.default.promises.writeFile(file, contents, 'utf8');
|
|
49
|
+
}
|
|
50
|
+
function drainStdin() {
|
|
51
|
+
return new Promise((resolve, reject)=>{
|
|
52
|
+
let result = '';
|
|
53
|
+
process.stdin.on('data', (chunk)=>{
|
|
54
|
+
result += chunk;
|
|
55
|
+
});
|
|
56
|
+
process.stdin.on('end', ()=>resolve(result)
|
|
57
|
+
);
|
|
58
|
+
process.stdin.on('error', (err)=>reject(err)
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
43
62
|
function help({ message , usage , commands: commands1 , options }) {
|
|
44
63
|
let indent = 2;
|
|
45
64
|
// Render header
|
|
@@ -336,7 +355,7 @@ async function build() {
|
|
|
336
355
|
console.error('[deprecation] Running tailwindcss without -i, please provide an input file.');
|
|
337
356
|
input = args['--input'] = args['_'][1];
|
|
338
357
|
}
|
|
339
|
-
if (input && !_fs.default.existsSync(input = _path.default.resolve(input))) {
|
|
358
|
+
if (input && input !== '-' && !_fs.default.existsSync(input = _path.default.resolve(input))) {
|
|
340
359
|
console.error(`Specified input file ${args['--input']} does not exist.`);
|
|
341
360
|
process.exit(9);
|
|
342
361
|
}
|
|
@@ -499,10 +518,8 @@ async function build() {
|
|
|
499
518
|
return process.stdout.write(result.css);
|
|
500
519
|
}
|
|
501
520
|
return Promise.all([
|
|
502
|
-
|
|
503
|
-
),
|
|
504
|
-
result.map && _fs.default.writeFile(output + '.map', result.map.toString(), ()=>true
|
|
505
|
-
),
|
|
521
|
+
outputFile(output, result.css),
|
|
522
|
+
result.map && outputFile(output + '.map', result.map.toString()),
|
|
506
523
|
].filter(Boolean));
|
|
507
524
|
}).then(()=>{
|
|
508
525
|
let end = process.hrtime.bigint();
|
|
@@ -510,7 +527,18 @@ async function build() {
|
|
|
510
527
|
console.error('Done in', (end - start) / BigInt(1000000) + 'ms.');
|
|
511
528
|
});
|
|
512
529
|
}
|
|
513
|
-
let css1 =
|
|
530
|
+
let css1 = await (()=>{
|
|
531
|
+
// Piping in data, let's drain the stdin
|
|
532
|
+
if (input === '-') {
|
|
533
|
+
return drainStdin();
|
|
534
|
+
}
|
|
535
|
+
// Input file has been provided
|
|
536
|
+
if (input) {
|
|
537
|
+
return _fs.default.readFileSync(_path.default.resolve(input), 'utf8');
|
|
538
|
+
}
|
|
539
|
+
// No input file provided, fallback to default atrules
|
|
540
|
+
return '@tailwind base; @tailwind components; @tailwind utilities';
|
|
541
|
+
})();
|
|
514
542
|
return processCSS(css1);
|
|
515
543
|
}
|
|
516
544
|
let context = null;
|
|
@@ -619,11 +647,9 @@ async function build() {
|
|
|
619
647
|
if (!output) {
|
|
620
648
|
return process.stdout.write(result.css);
|
|
621
649
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
),
|
|
625
|
-
result.map && _fs.default.writeFile(output + '.map', result.map.toString(), ()=>true
|
|
626
|
-
),
|
|
650
|
+
return Promise.all([
|
|
651
|
+
outputFile(output, result.css),
|
|
652
|
+
result.map && outputFile(output + '.map', result.map.toString()),
|
|
627
653
|
].filter(Boolean));
|
|
628
654
|
}).then(()=>{
|
|
629
655
|
let end = process.hrtime.bigint();
|
|
@@ -636,7 +662,18 @@ async function build() {
|
|
|
636
662
|
}
|
|
637
663
|
});
|
|
638
664
|
}
|
|
639
|
-
let css2 =
|
|
665
|
+
let css2 = await (()=>{
|
|
666
|
+
// Piping in data, let's drain the stdin
|
|
667
|
+
if (input === '-') {
|
|
668
|
+
return drainStdin();
|
|
669
|
+
}
|
|
670
|
+
// Input file has been provided
|
|
671
|
+
if (input) {
|
|
672
|
+
return _fs.default.readFileSync(_path.default.resolve(input), 'utf8');
|
|
673
|
+
}
|
|
674
|
+
// No input file provided, fallback to default atrules
|
|
675
|
+
return '@tailwind base; @tailwind components; @tailwind utilities';
|
|
676
|
+
})();
|
|
640
677
|
let result1 = await processCSS(css2);
|
|
641
678
|
env.DEBUG && console.timeEnd('Finished in');
|
|
642
679
|
return result1;
|
package/lib/css/preflight.css
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _setupTrackingContext = _interopRequireDefault(require("./lib/setupTrackingContext"));
|
|
3
|
-
var _setupWatchingContext = _interopRequireDefault(require("./lib/setupWatchingContext"));
|
|
4
3
|
var _processTailwindFeatures = _interopRequireDefault(require("./processTailwindFeatures"));
|
|
5
4
|
var _sharedState = require("./lib/sharedState");
|
|
6
5
|
function _interopRequireDefault(obj) {
|
|
@@ -18,8 +17,7 @@ module.exports = function tailwindcss(configOrPath) {
|
|
|
18
17
|
return root;
|
|
19
18
|
},
|
|
20
19
|
function(root, result) {
|
|
21
|
-
|
|
22
|
-
(0, _processTailwindFeatures).default(setupContext)(root, result);
|
|
20
|
+
(0, _processTailwindFeatures).default((0, _setupTrackingContext).default(configOrPath))(root, result);
|
|
23
21
|
},
|
|
24
22
|
_sharedState.env.DEBUG && function(root) {
|
|
25
23
|
console.timeEnd('JIT TOTAL');
|
|
@@ -8,6 +8,7 @@ function collapseDuplicateDeclarations() {
|
|
|
8
8
|
root.walkRules((node)=>{
|
|
9
9
|
let seen = new Map();
|
|
10
10
|
let droppable = new Set([]);
|
|
11
|
+
let byProperty = new Map();
|
|
11
12
|
node.walkDecls((decl)=>{
|
|
12
13
|
// This could happen if we have nested selectors. In that case the
|
|
13
14
|
// parent will loop over all its declarations but also the declarations
|
|
@@ -17,13 +18,63 @@ function collapseDuplicateDeclarations() {
|
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
if (seen.has(decl.prop)) {
|
|
20
|
-
|
|
21
|
+
// Exact same value as what we have seen so far
|
|
22
|
+
if (seen.get(decl.prop).value === decl.value) {
|
|
23
|
+
// Keep the last one, drop the one we've seen so far
|
|
24
|
+
droppable.add(seen.get(decl.prop));
|
|
25
|
+
// Override the existing one with the new value. This is necessary
|
|
26
|
+
// so that if we happen to have more than one declaration with the
|
|
27
|
+
// same value, that we keep removing the previous one. Otherwise we
|
|
28
|
+
// will only remove the *first* one.
|
|
29
|
+
seen.set(decl.prop, decl);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Not the same value, so we need to check if we can merge it so
|
|
33
|
+
// let's collect it first.
|
|
34
|
+
if (!byProperty.has(decl.prop)) {
|
|
35
|
+
byProperty.set(decl.prop, new Set());
|
|
36
|
+
}
|
|
37
|
+
byProperty.get(decl.prop).add(seen.get(decl.prop));
|
|
38
|
+
byProperty.get(decl.prop).add(decl);
|
|
21
39
|
}
|
|
22
40
|
seen.set(decl.prop, decl);
|
|
23
41
|
});
|
|
42
|
+
// Drop all the duplicate declarations with the exact same value we've
|
|
43
|
+
// already seen so far.
|
|
24
44
|
for (let decl1 of droppable){
|
|
25
45
|
decl1.remove();
|
|
26
46
|
}
|
|
47
|
+
// Analyze the declarations based on its unit, drop all the declarations
|
|
48
|
+
// with the same unit but the last one in the list.
|
|
49
|
+
for (let declarations of byProperty.values()){
|
|
50
|
+
let byUnit = new Map();
|
|
51
|
+
for (let decl of declarations){
|
|
52
|
+
let unit = resolveUnit(decl.value);
|
|
53
|
+
if (unit === null) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!byUnit.has(unit)) {
|
|
57
|
+
byUnit.set(unit, new Set());
|
|
58
|
+
}
|
|
59
|
+
byUnit.get(unit).add(decl);
|
|
60
|
+
}
|
|
61
|
+
for (let declarations1 of byUnit.values()){
|
|
62
|
+
// Get all but the last one
|
|
63
|
+
let removableDeclarations = Array.from(declarations1).slice(0, -1);
|
|
64
|
+
for (let decl of removableDeclarations){
|
|
65
|
+
decl.remove();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
27
69
|
});
|
|
28
70
|
};
|
|
29
71
|
}
|
|
72
|
+
let UNITLESS_NUMBER = Symbol('unitless-number');
|
|
73
|
+
function resolveUnit(input) {
|
|
74
|
+
let result = /^-?\d*.?\d+([\w%]+)?$/g.exec(input);
|
|
75
|
+
if (result) {
|
|
76
|
+
var ref;
|
|
77
|
+
return (ref = result[1]) !== null && ref !== void 0 ? ref : UNITLESS_NUMBER;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.defaultExtractor = defaultExtractor;
|
|
6
|
+
const PATTERNS = [
|
|
7
|
+
/(?:\['([^'\s]+[^<>"'`\s:\\])')/.source,
|
|
8
|
+
/(?:\["([^"\s]+[^<>"'`\s:\\])")/.source,
|
|
9
|
+
/(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source,
|
|
10
|
+
/([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
|
|
11
|
+
/([^<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source,
|
|
12
|
+
/([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
|
|
13
|
+
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
|
|
14
|
+
/([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
|
|
15
|
+
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
|
|
16
|
+
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
|
|
17
|
+
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
18
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
|
|
19
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
|
|
20
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
|
|
21
|
+
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
|
|
22
|
+
/([^"'`\s]*[^<>"'`\s:\\])/.source,
|
|
23
|
+
/([^<>"'`\s]*[^"'`\s:\\])/.source,
|
|
24
|
+
].join('|');
|
|
25
|
+
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
|
|
26
|
+
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
|
|
27
|
+
function defaultExtractor(content) {
|
|
28
|
+
let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP);
|
|
29
|
+
let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
|
|
30
|
+
let results = [
|
|
31
|
+
...broadMatches,
|
|
32
|
+
...innerMatches
|
|
33
|
+
].flat().filter((v)=>v !== undefined
|
|
34
|
+
);
|
|
35
|
+
return results;
|
|
36
|
+
} // Regular utilities
|
|
37
|
+
// {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
|
|
38
|
+
// Arbitrary values
|
|
39
|
+
// {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
|
|
40
|
+
// arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
|
|
41
|
+
// Arbitrary properties
|
|
42
|
+
// {{modifier}:}*[{validCssPropertyName}:{arbitraryValue}]
|
|
@@ -13,17 +13,28 @@ function _interopRequireDefault(obj) {
|
|
|
13
13
|
default: obj
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
function extractClasses(node) {
|
|
17
|
+
let classes = new Set();
|
|
18
|
+
let container = _postcss.default.root({
|
|
19
|
+
nodes: [
|
|
20
|
+
node.clone()
|
|
21
|
+
]
|
|
22
|
+
});
|
|
23
|
+
container.walkRules((rule)=>{
|
|
24
|
+
(0, _postcssSelectorParser).default((selectors)=>{
|
|
25
|
+
selectors.walkClasses((classSelector)=>{
|
|
26
|
+
classes.add(classSelector.value);
|
|
27
|
+
});
|
|
28
|
+
}).processSync(rule.selector);
|
|
29
|
+
});
|
|
30
|
+
return Array.from(classes);
|
|
31
|
+
}
|
|
32
|
+
function extractBaseCandidates(candidates, separator) {
|
|
33
|
+
let baseClasses = new Set();
|
|
34
|
+
for (let candidate of candidates){
|
|
35
|
+
baseClasses.add(candidate.split(separator).pop());
|
|
36
|
+
}
|
|
37
|
+
return Array.from(baseClasses);
|
|
27
38
|
}
|
|
28
39
|
function prefix(context, selector) {
|
|
29
40
|
let prefix1 = context.tailwindConfig.prefix;
|
|
@@ -186,10 +197,36 @@ function processApply(root, context) {
|
|
|
186
197
|
for (const [parent, candidates] of perParentApplies){
|
|
187
198
|
let siblings = [];
|
|
188
199
|
for (let [applyCandidate, important, rules] of candidates){
|
|
189
|
-
let base = applyCandidate.split(context.tailwindConfig.separator).pop();
|
|
190
200
|
for (let [meta, node] of rules){
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
let parentClasses = extractClasses(parent);
|
|
202
|
+
let nodeClasses = extractClasses(node);
|
|
203
|
+
// Add base utility classes from the @apply node to the list of
|
|
204
|
+
// classes to check whether it intersects and therefore results in a
|
|
205
|
+
// circular dependency or not.
|
|
206
|
+
//
|
|
207
|
+
// E.g.:
|
|
208
|
+
// .foo {
|
|
209
|
+
// @apply hover:a; // This applies "a" but with a modifier
|
|
210
|
+
// }
|
|
211
|
+
//
|
|
212
|
+
// We only have to do that with base classes of the `node`, not of the `parent`
|
|
213
|
+
// E.g.:
|
|
214
|
+
// .hover\:foo {
|
|
215
|
+
// @apply bar;
|
|
216
|
+
// }
|
|
217
|
+
// .bar {
|
|
218
|
+
// @apply foo;
|
|
219
|
+
// }
|
|
220
|
+
//
|
|
221
|
+
// This should not result in a circular dependency because we are
|
|
222
|
+
// just applying `.foo` and the rule above is `.hover\:foo` which is
|
|
223
|
+
// unrelated. However, if we were to apply `hover:foo` then we _did_
|
|
224
|
+
// have to include this one.
|
|
225
|
+
nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
|
|
226
|
+
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
|
|
227
|
+
);
|
|
228
|
+
if (intersects) {
|
|
229
|
+
throw node.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
|
|
193
230
|
}
|
|
194
231
|
let root = _postcss.default.root({
|
|
195
232
|
nodes: [
|
|
@@ -199,6 +236,42 @@ function processApply(root, context) {
|
|
|
199
236
|
let canRewriteSelector = node.type !== 'atrule' || node.type === 'atrule' && node.name !== 'keyframes';
|
|
200
237
|
if (canRewriteSelector) {
|
|
201
238
|
root.walkRules((rule)=>{
|
|
239
|
+
// Let's imagine you have the following structure:
|
|
240
|
+
//
|
|
241
|
+
// .foo {
|
|
242
|
+
// @apply bar;
|
|
243
|
+
// }
|
|
244
|
+
//
|
|
245
|
+
// @supports (a: b) {
|
|
246
|
+
// .bar {
|
|
247
|
+
// color: blue
|
|
248
|
+
// }
|
|
249
|
+
//
|
|
250
|
+
// .something-unrelated {}
|
|
251
|
+
// }
|
|
252
|
+
//
|
|
253
|
+
// In this case we want to apply `.bar` but it happens to be in
|
|
254
|
+
// an atrule node. We clone that node instead of the nested one
|
|
255
|
+
// because we still want that @supports rule to be there once we
|
|
256
|
+
// applied everything.
|
|
257
|
+
//
|
|
258
|
+
// However it happens to be that the `.something-unrelated` is
|
|
259
|
+
// also in that same shared @supports atrule. This is not good,
|
|
260
|
+
// and this should not be there. The good part is that this is
|
|
261
|
+
// a clone already and it can be safely removed. The question is
|
|
262
|
+
// how do we know we can remove it. Basically what we can do is
|
|
263
|
+
// match it against the applyCandidate that you want to apply. If
|
|
264
|
+
// it doesn't match the we can safely delete it.
|
|
265
|
+
//
|
|
266
|
+
// If we didn't do this, then the `replaceSelector` function
|
|
267
|
+
// would have replaced this with something that didn't exist and
|
|
268
|
+
// therefore it removed the selector altogether. In this specific
|
|
269
|
+
// case it would result in `{}` instead of `.something-unrelated {}`
|
|
270
|
+
if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate
|
|
271
|
+
)) {
|
|
272
|
+
rule.remove();
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
202
275
|
rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate);
|
|
203
276
|
rule.walkDecls((d)=>{
|
|
204
277
|
d.important = meta.important || important;
|
|
@@ -220,7 +293,6 @@ function processApply(root, context) {
|
|
|
220
293
|
let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)
|
|
221
294
|
).map((s)=>s[1]
|
|
222
295
|
);
|
|
223
|
-
// console.log(parent)
|
|
224
296
|
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
225
297
|
parent.after(nodes);
|
|
226
298
|
}
|
|
@@ -9,6 +9,7 @@ var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
|
9
9
|
var _generateRules = require("./generateRules");
|
|
10
10
|
var _bigSign = _interopRequireDefault(require("../util/bigSign"));
|
|
11
11
|
var _cloneNodes = _interopRequireDefault(require("../util/cloneNodes"));
|
|
12
|
+
var _defaultExtractor = require("./defaultExtractor");
|
|
12
13
|
function _interopRequireDefault(obj) {
|
|
13
14
|
return obj && obj.__esModule ? obj : {
|
|
14
15
|
default: obj
|
|
@@ -38,31 +39,8 @@ function _interopRequireWildcard(obj) {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
let env = sharedState.env;
|
|
41
|
-
const PATTERNS = [
|
|
42
|
-
/([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
|
|
43
|
-
/([^<>"'`\s]*\[\w*"[^"`\s]*"?\])/.source,
|
|
44
|
-
/([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
|
|
45
|
-
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
|
|
46
|
-
/([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
|
|
47
|
-
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
|
|
48
|
-
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
|
|
49
|
-
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
50
|
-
/([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
|
|
51
|
-
/([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
|
|
52
|
-
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
|
|
53
|
-
/([^<>"'`\s]*[^"'`\s:])/.source
|
|
54
|
-
].join('|');
|
|
55
|
-
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
|
|
56
|
-
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g;
|
|
57
42
|
const builtInExtractors = {
|
|
58
|
-
DEFAULT:
|
|
59
|
-
let broadMatches = content.match(BROAD_MATCH_GLOBAL_REGEXP) || [];
|
|
60
|
-
let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
|
|
61
|
-
return [
|
|
62
|
-
...broadMatches,
|
|
63
|
-
...innerMatches
|
|
64
|
-
];
|
|
65
|
-
}
|
|
43
|
+
DEFAULT: _defaultExtractor.defaultExtractor
|
|
66
44
|
};
|
|
67
45
|
const builtInTransformers = {
|
|
68
46
|
DEFAULT: (content)=>content
|
|
@@ -165,17 +143,26 @@ function expandTailwindAtRules(context) {
|
|
|
165
143
|
utilities: null,
|
|
166
144
|
variants: null
|
|
167
145
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
146
|
+
let hasApply = false;
|
|
147
|
+
root.walkAtRules((rule)=>{
|
|
148
|
+
// Make sure this file contains Tailwind directives. If not, we can save
|
|
149
|
+
// a lot of work and bail early. Also we don't have to register our touch
|
|
150
|
+
// file as a dependency since the output of this CSS does not depend on
|
|
151
|
+
// the source of any templates. Think Vue <style> blocks for example.
|
|
152
|
+
if (rule.name === 'tailwind') {
|
|
153
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
154
|
+
layerNodes[rule.params] = rule;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// We also want to check for @apply because the user can
|
|
158
|
+
// apply classes in an isolated environment like CSS
|
|
159
|
+
// modules and we still need to inject defaults
|
|
160
|
+
if (rule.name === 'apply') {
|
|
161
|
+
hasApply = true;
|
|
175
162
|
}
|
|
176
163
|
});
|
|
177
164
|
if (Object.values(layerNodes).every((n)=>n === null
|
|
178
|
-
)) {
|
|
165
|
+
) && !hasApply) {
|
|
179
166
|
return root;
|
|
180
167
|
}
|
|
181
168
|
// ---
|
package/lib/lib/generateRules.js
CHANGED
|
@@ -124,6 +124,10 @@ function applyVariant(variant, matches, context) {
|
|
|
124
124
|
let variantFunctionTuples = context.variantMap.get(variant);
|
|
125
125
|
let result = [];
|
|
126
126
|
for (let [meta, rule1] of matches){
|
|
127
|
+
// Don't generate variants for user css
|
|
128
|
+
if (meta.layer === 'user') {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
127
131
|
let container = _postcss.default.root({
|
|
128
132
|
nodes: [
|
|
129
133
|
rule1.clone()
|
|
@@ -12,7 +12,11 @@ function _interopRequireDefault(obj) {
|
|
|
12
12
|
function normalizeTailwindDirectives(root) {
|
|
13
13
|
let tailwindDirectives = new Set();
|
|
14
14
|
let layerDirectives = new Set();
|
|
15
|
+
let applyDirectives = new Set();
|
|
15
16
|
root.walkAtRules((atRule)=>{
|
|
17
|
+
if (atRule.name === 'apply') {
|
|
18
|
+
applyDirectives.add(atRule);
|
|
19
|
+
}
|
|
16
20
|
if (atRule.name === 'import') {
|
|
17
21
|
if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
|
|
18
22
|
atRule.name = 'tailwind';
|
|
@@ -72,5 +76,8 @@ function normalizeTailwindDirectives(root) {
|
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
tailwindDirectives,
|
|
81
|
+
applyDirectives
|
|
82
|
+
};
|
|
76
83
|
}
|
|
@@ -119,16 +119,17 @@ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
|
|
|
119
119
|
return changedFiles;
|
|
120
120
|
}
|
|
121
121
|
function setupTrackingContext(configOrPath) {
|
|
122
|
-
return ({ tailwindDirectives , registerDependency })=>{
|
|
122
|
+
return ({ tailwindDirectives , registerDependency , applyDirectives })=>{
|
|
123
123
|
return (root, result)=>{
|
|
124
124
|
let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] = getTailwindConfig(configOrPath);
|
|
125
125
|
let contextDependencies = new Set(configDependencies);
|
|
126
|
-
// If there are no @tailwind rules, we don't consider this CSS
|
|
127
|
-
// to be dependencies of the context. Can reuse
|
|
128
|
-
// We may want to think about `@layer`
|
|
129
|
-
//
|
|
130
|
-
// in
|
|
131
|
-
|
|
126
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS
|
|
127
|
+
// file or its dependencies to be dependencies of the context. Can reuse
|
|
128
|
+
// the context even if they change. We may want to think about `@layer`
|
|
129
|
+
// being part of this trigger too, but it's tough because it's impossible
|
|
130
|
+
// for a layer in one file to end up in the actual @tailwind rule in
|
|
131
|
+
// another file since independent sources are effectively isolated.
|
|
132
|
+
if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
|
|
132
133
|
// Add current css file as a context dependencies.
|
|
133
134
|
contextDependencies.add(result.opts.from);
|
|
134
135
|
// Add all css @import dependencies as context dependencies.
|
|
@@ -140,12 +141,12 @@ function setupTrackingContext(configOrPath) {
|
|
|
140
141
|
}
|
|
141
142
|
let [context] = (0, _setupContextUtils).getContext(root, result, tailwindConfig, userConfigPath, tailwindConfigHash, contextDependencies);
|
|
142
143
|
let candidateFiles = getCandidateFiles(context, tailwindConfig);
|
|
143
|
-
// If there are no @tailwind rules, we don't consider this CSS file or it's
|
|
144
|
-
// to be dependencies of the context. Can reuse the context even if they change.
|
|
144
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
|
|
145
|
+
// dependencies to be dependencies of the context. Can reuse the context even if they change.
|
|
145
146
|
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
146
147
|
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
147
148
|
// in another file since independent sources are effectively isolated.
|
|
148
|
-
if (tailwindDirectives.size > 0) {
|
|
149
|
+
if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
|
|
149
150
|
let fileModifiedMap = (0, _setupContextUtils).getFileModifiedMap(context);
|
|
150
151
|
// Add template paths as postcss dependencies.
|
|
151
152
|
for (let fileOrGlob of candidateFiles){
|