tailwindcss 0.0.0-insiders.fc623da → 0.0.0-insiders.fc6c27d

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +79 -2
  2. package/README.md +8 -4
  3. package/lib/cli.js +49 -12
  4. package/lib/css/preflight.css +1 -2
  5. package/lib/index.js +1 -3
  6. package/lib/lib/collapseDuplicateDeclarations.js +52 -1
  7. package/lib/lib/defaultExtractor.js +42 -0
  8. package/lib/lib/evaluateTailwindFunctions.js +1 -1
  9. package/lib/lib/expandApplyAtRules.js +87 -15
  10. package/lib/lib/expandTailwindAtRules.js +32 -37
  11. package/lib/lib/generateRules.js +4 -1
  12. package/lib/lib/normalizeTailwindDirectives.js +8 -1
  13. package/lib/lib/setupContextUtils.js +7 -1
  14. package/lib/lib/setupTrackingContext.js +11 -10
  15. package/lib/lib/sharedState.js +33 -4
  16. package/lib/processTailwindFeatures.js +2 -1
  17. package/lib/util/color.js +23 -8
  18. package/lib/util/resolveConfig.js +9 -1
  19. package/lib/util/toPath.js +6 -1
  20. package/package.json +12 -13
  21. package/peers/index.js +681 -693
  22. package/src/cli.js +57 -12
  23. package/src/css/preflight.css +1 -2
  24. package/src/index.js +1 -7
  25. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  26. package/src/lib/defaultExtractor.js +48 -0
  27. package/src/lib/evaluateTailwindFunctions.js +1 -1
  28. package/src/lib/expandApplyAtRules.js +90 -19
  29. package/src/lib/expandTailwindAtRules.js +29 -32
  30. package/src/lib/generateRules.js +5 -1
  31. package/src/lib/normalizeTailwindDirectives.js +6 -1
  32. package/src/lib/setupContextUtils.js +8 -1
  33. package/src/lib/setupTrackingContext.js +11 -10
  34. package/src/lib/sharedState.js +40 -4
  35. package/src/processTailwindFeatures.js +2 -1
  36. package/src/util/color.js +20 -7
  37. package/src/util/resolveConfig.js +11 -1
  38. package/src/util/toPath.js +23 -1
  39. package/stubs/defaultConfig.stub.js +2 -2
  40. package/lib/lib/setupWatchingContext.js +0 -288
  41. package/src/lib/setupWatchingContext.js +0 -311
package/CHANGELOG.md CHANGED
@@ -9,19 +9,88 @@ 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.11] - 2022-01-05
13
+
14
+ ### Fixed
15
+
16
+ - Preserve casing of CSS variables added by plugins ([#6888](https://github.com/tailwindlabs/tailwindcss/pull/6888))
17
+ - Ignore content paths that are passed in but don't actually exist ([#6901](https://github.com/tailwindlabs/tailwindcss/pull/6901))
18
+ - Revert change that applies Tailwind's defaults in isolated environments like CSS modules ([9fdc391](https://github.com/tailwindlabs/tailwindcss/commit/9fdc391d4ff93e7e350f5ce439060176b1f0162f))
19
+
20
+ ## [3.0.10] - 2022-01-04
21
+
22
+ ### Fixed
23
+
24
+ - Fix `@apply` in files without `@tailwind` directives ([#6580](https://github.com/tailwindlabs/tailwindcss/pull/6580), [#6875](https://github.com/tailwindlabs/tailwindcss/pull/6875))
25
+ - CLI: avoid unnecessary writes to output files ([#6550](https://github.com/tailwindlabs/tailwindcss/pull/6550))
26
+
27
+ ### Added
28
+
29
+ - Allow piping data into the CLI ([#6876](https://github.com/tailwindlabs/tailwindcss/pull/6876))
30
+
31
+ ## [3.0.9] - 2022-01-03
32
+
33
+ ### Fixed
34
+
35
+ - Improve `DEBUG` flag ([#6797](https://github.com/tailwindlabs/tailwindcss/pull/6797), [#6804](https://github.com/tailwindlabs/tailwindcss/pull/6804))
36
+ - Ensure we can use `<` and `>` characters in modifiers ([#6851](https://github.com/tailwindlabs/tailwindcss/pull/6851))
37
+ - Validate `theme()` works in arbitrary values ([#6852](https://github.com/tailwindlabs/tailwindcss/pull/6852))
38
+ - Properly detect `theme()` value usage in arbitrary properties ([#6854](https://github.com/tailwindlabs/tailwindcss/pull/6854))
39
+ - Improve collapsing of duplicate declarations ([#6856](https://github.com/tailwindlabs/tailwindcss/pull/6856))
40
+ - Remove support for `TAILWIND_MODE=watch` ([#6858](https://github.com/tailwindlabs/tailwindcss/pull/6858))
41
+
42
+ ## [3.0.8] - 2021-12-28
43
+
44
+ ### Fixed
45
+
46
+ - Reduce specificity of `abbr` rule in preflight ([#6671](https://github.com/tailwindlabs/tailwindcss/pull/6671))
47
+ - Support HSL with hue units in arbitrary values ([#6726](https://github.com/tailwindlabs/tailwindcss/pull/6726))
48
+ - Add `node16-linux-arm64` target for standalone CLI ([#6693](https://github.com/tailwindlabs/tailwindcss/pull/6693))
49
+
50
+ ## [3.0.7] - 2021-12-17
51
+
52
+ ### Fixed
53
+
54
+ - Don't mutate custom color palette when overriding per-plugin colors ([#6546](https://github.com/tailwindlabs/tailwindcss/pull/6546))
55
+ - Improve circular dependency detection when using `@apply` ([#6588](https://github.com/tailwindlabs/tailwindcss/pull/6588))
56
+ - Only generate variants for non-`user` layers ([#6589](https://github.com/tailwindlabs/tailwindcss/pull/6589))
57
+ - Properly extract classes with arbitrary values in arrays and classes followed by escaped quotes ([#6590](https://github.com/tailwindlabs/tailwindcss/pull/6590))
58
+ - Improve jsx interpolation candidate matching ([#6593](https://github.com/tailwindlabs/tailwindcss/pull/6593))
59
+ - Ensure `@apply` of a rule inside an AtRule works ([#6594](https://github.com/tailwindlabs/tailwindcss/pull/6594))
60
+
61
+ ## [3.0.6] - 2021-12-16
62
+
63
+ ### Fixed
64
+
65
+ - Support square bracket notation in paths ([#6519](https://github.com/tailwindlabs/tailwindcss/pull/6519))
66
+ - Ensure all plugins are executed for a given candidate ([#6540](https://github.com/tailwindlabs/tailwindcss/pull/6540))
67
+
68
+ ## [3.0.5] - 2021-12-15
69
+
70
+ ### Fixed
71
+
72
+ - Revert: add `li` to list-style reset ([9777562d](https://github.com/tailwindlabs/tailwindcss/commit/9777562da37ee631bbf77374c0d14825f09ef9af))
73
+
74
+ ## [3.0.4] - 2021-12-15
75
+
76
+ ### Fixed
77
+
78
+ - Insert always-on defaults layer in correct spot ([#6526](https://github.com/tailwindlabs/tailwindcss/pull/6526))
79
+
12
80
  ## [3.0.3] - 2021-12-15
13
81
 
14
82
  ### Added
15
83
 
16
84
  - Warn about invalid globs in `content` ([#6449](https://github.com/tailwindlabs/tailwindcss/pull/6449))
17
85
  - Add standalone tailwindcss CLI ([#6506](https://github.com/tailwindlabs/tailwindcss/pull/6506))
86
+ - Add `li` to list-style reset ([00f60e6](https://github.com/tailwindlabs/tailwindcss/commit/00f60e61013c6e4e3419e4b699371a13eb30b75d))
18
87
 
19
88
  ### Fixed
20
89
 
21
90
  - Don't output unparsable values ([#6469](https://github.com/tailwindlabs/tailwindcss/pull/6469))
22
91
  - Fix text decoration utilities from overriding the new text decoration color/style/thickness utilities when used with a modifier ([#6378](https://github.com/tailwindlabs/tailwindcss/pull/6378))
23
92
  - Move defaults to their own always-on layer ([#6500](https://github.com/tailwindlabs/tailwindcss/pull/6500))
24
- - Support negative values in safelist patterns ([6480](https://github.com/tailwindlabs/tailwindcss/pull/6480))
93
+ - Support negative values in safelist patterns ([#6480](https://github.com/tailwindlabs/tailwindcss/pull/6480))
25
94
 
26
95
  ## [3.0.2] - 2021-12-13
27
96
 
@@ -1710,7 +1779,15 @@ No release notes
1710
1779
 
1711
1780
  - Everything!
1712
1781
 
1713
- [unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.3...HEAD
1782
+ [unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.11...HEAD
1783
+ [3.0.11]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.10...v3.0.11
1784
+ [3.0.10]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.9...v3.0.10
1785
+ [3.0.9]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.8...v3.0.9
1786
+ [3.0.8]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.7...v3.0.8
1787
+ [3.0.7]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.6...v3.0.7
1788
+ [3.0.6]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.5...v3.0.6
1789
+ [3.0.5]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.4...v3.0.5
1790
+ [3.0.4]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.3...v3.0.4
1714
1791
  [3.0.3]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.2...v3.0.3
1715
1792
  [3.0.2]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.1...v3.0.2
1716
1793
  [3.0.1]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.0...v3.0.1
package/README.md CHANGED
@@ -1,10 +1,14 @@
1
1
  <p>
2
- <a href="https://tailwindcss.com/" target="_blank">
3
- <img alt="Tailwind CSS" width="350" src="https://refactoringui.nyc3.cdn.digitaloceanspaces.com/tailwind-logo-sticker.svg">
4
- </a><br>
5
- A utility-first CSS framework for rapidly building custom user interfaces.
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
- _fs.default.promises.writeFile(output, result.css, ()=>true
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 = input ? _fs.default.readFileSync(_path.default.resolve(input), 'utf8') : '@tailwind base; @tailwind components; @tailwind utilities';
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
- await Promise.all([
623
- _fs.default.promises.writeFile(output, result.css, ()=>true
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 = input ? _fs.default.readFileSync(_path.default.resolve(input), 'utf8') : '@tailwind base; @tailwind components; @tailwind utilities';
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;
@@ -58,7 +58,7 @@ hr {
58
58
  Add the correct text decoration in Chrome, Edge, and Safari.
59
59
  */
60
60
 
61
- abbr[title] {
61
+ abbr:where([title]) {
62
62
  text-decoration: underline dotted;
63
63
  }
64
64
 
@@ -289,7 +289,6 @@ legend {
289
289
 
290
290
  ol,
291
291
  ul,
292
- li,
293
292
  menu {
294
293
  list-style: none;
295
294
  margin: 0;
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
- let setupContext = _sharedState.env.TAILWIND_MODE === 'watch' ? (0, _setupWatchingContext).default(configOrPath) : (0, _setupTrackingContext).default(configOrPath);
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
- droppable.add(seen.get(decl.prop));
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}]
@@ -43,7 +43,7 @@ function listKeys(obj) {
43
43
  function validatePath(config, path, defaultValue) {
44
44
  const pathString = Array.isArray(path) ? pathToString(path) : path.replace(/^['"]+/g, '').replace(/['"]+$/g, '');
45
45
  const pathSegments = Array.isArray(path) ? path : (0, _toPath).toPath(pathString);
46
- const value = (0, _dlv).default(config.theme, pathString, defaultValue);
46
+ const value = (0, _dlv).default(config.theme, pathSegments, defaultValue);
47
47
  if (value === undefined) {
48
48
  let error = `'${pathString}' does not exist in your theme config.`;
49
49
  const parentSegments = pathSegments.slice(0, -1);
@@ -13,17 +13,28 @@ function _interopRequireDefault(obj) {
13
13
  default: obj
14
14
  };
15
15
  }
16
- function containsBase(selector, classCandidateBase, separator) {
17
- return (0, _postcssSelectorParser).default((selectors)=>{
18
- let contains = false;
19
- selectors.walkClasses((classSelector)=>{
20
- if (classSelector.value.split(separator).pop() === classCandidateBase) {
21
- contains = true;
22
- return false;
23
- }
24
- });
25
- return contains;
26
- }).transformSync(selector);
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
- if (containsBase(parent.selector, base, context.tailwindConfig.separator) && containsBase(node.selector, base, context.tailwindConfig.separator)) {
192
- throw node.error(`Circular dependency detected when using: \`@apply ${applyCandidate}\``);
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: (content)=>{
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,14 +143,23 @@ function expandTailwindAtRules(context) {
165
143
  utilities: null,
166
144
  variants: null
167
145
  };
168
- // Make sure this file contains Tailwind directives. If not, we can save
169
- // a lot of work and bail early. Also we don't have to register our touch
170
- // file as a dependency since the output of this CSS does not depend on
171
- // the source of any templates. Think Vue <style> blocks for example.
172
- root.walkAtRules('tailwind', (rule)=>{
173
- if (Object.keys(layerNodes).includes(rule.params)) {
174
- layerNodes[rule.params] = rule;
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
+ }
175
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
162
+ // }
176
163
  });
177
164
  if (Object.values(layerNodes).every((n)=>n === null
178
165
  )) {
@@ -210,18 +197,26 @@ function expandTailwindAtRules(context) {
210
197
  let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
211
198
  // ---
212
199
  // Replace any Tailwind directives with generated CSS
200
+ if (layerNodes.base) {
201
+ layerNodes.base.before((0, _cloneNodes).default([
202
+ ...baseNodes
203
+ ], layerNodes.base.source));
204
+ }
213
205
  // @defaults rules are unconditionally added first to ensure that
214
206
  // using any utility that relies on defaults will work even when
215
207
  // compiled in an isolated environment like CSS modules
216
208
  if (context.tailwindConfig[DEFAULTS_LAYER] !== false) {
217
- root.prepend((0, _cloneNodes).default([
218
- ...defaultNodes
219
- ], root.source));
209
+ if (layerNodes.base) {
210
+ layerNodes.base.after((0, _cloneNodes).default([
211
+ ...defaultNodes
212
+ ], root.source));
213
+ } else {
214
+ root.prepend((0, _cloneNodes).default([
215
+ ...defaultNodes
216
+ ], root.source));
217
+ }
220
218
  }
221
219
  if (layerNodes.base) {
222
- layerNodes.base.before((0, _cloneNodes).default([
223
- ...baseNodes
224
- ], layerNodes.base.source));
225
220
  layerNodes.base.remove();
226
221
  }
227
222
  if (layerNodes.components) {
@@ -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()
@@ -331,7 +335,6 @@ function* resolveMatchedPlugins(classCandidate, context) {
331
335
  context.candidateRuleMap.get(prefix),
332
336
  negative ? `-${modifier}` : modifier
333
337
  ];
334
- return;
335
338
  }
336
339
  }
337
340
  }