tailwindcss 0.0.0-insiders.e2d5f21 → 0.0.0-insiders.e302ef1

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 (91) hide show
  1. package/CHANGELOG.md +244 -3
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.js +2 -1
  5. package/defaultConfig.js +2 -1
  6. package/defaultTheme.js +2 -1
  7. package/lib/cli.js +123 -88
  8. package/lib/corePlugins.js +288 -360
  9. package/lib/css/preflight.css +4 -4
  10. package/lib/featureFlags.js +4 -5
  11. package/lib/index.js +12 -3
  12. package/lib/lib/cacheInvalidation.js +69 -0
  13. package/lib/lib/collapseAdjacentRules.js +14 -1
  14. package/lib/lib/collapseDuplicateDeclarations.js +52 -1
  15. package/lib/lib/defaultExtractor.js +44 -0
  16. package/lib/lib/evaluateTailwindFunctions.js +1 -1
  17. package/lib/lib/expandApplyAtRules.js +265 -60
  18. package/lib/lib/expandTailwindAtRules.js +63 -48
  19. package/lib/lib/generateRules.js +136 -34
  20. package/lib/lib/normalizeTailwindDirectives.js +10 -2
  21. package/lib/lib/partitionApplyAtRules.js +53 -0
  22. package/lib/lib/resolveDefaultsAtRules.js +30 -12
  23. package/lib/lib/setupContextUtils.js +137 -81
  24. package/lib/lib/setupTrackingContext.js +8 -7
  25. package/lib/lib/sharedState.js +38 -5
  26. package/{nesting → lib/postcss-plugins/nesting}/README.md +0 -0
  27. package/lib/postcss-plugins/nesting/index.js +17 -0
  28. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  29. package/lib/processTailwindFeatures.js +10 -2
  30. package/lib/util/cloneNodes.js +12 -1
  31. package/lib/util/color.js +23 -8
  32. package/lib/util/createPlugin.js +1 -2
  33. package/lib/util/createUtilityPlugin.js +4 -8
  34. package/lib/util/dataTypes.js +4 -2
  35. package/lib/util/defaults.js +6 -0
  36. package/lib/util/flattenColorPalette.js +1 -3
  37. package/lib/util/log.js +10 -6
  38. package/lib/util/normalizeConfig.js +47 -15
  39. package/lib/util/normalizeScreens.js +6 -5
  40. package/lib/util/parseBoxShadowValue.js +44 -4
  41. package/lib/util/pluginUtils.js +6 -13
  42. package/lib/util/prefixSelector.js +4 -5
  43. package/lib/util/resolveConfig.js +48 -27
  44. package/lib/util/resolveConfigPath.js +1 -2
  45. package/lib/util/toColorValue.js +1 -2
  46. package/lib/util/toPath.js +6 -1
  47. package/lib/util/transformThemeValue.js +4 -8
  48. package/nesting/index.js +2 -12
  49. package/package.json +28 -33
  50. package/peers/index.js +3209 -4239
  51. package/plugin.js +2 -1
  52. package/resolveConfig.js +2 -1
  53. package/src/cli.js +62 -15
  54. package/src/corePlugins.js +212 -217
  55. package/src/css/preflight.css +4 -4
  56. package/src/featureFlags.js +3 -3
  57. package/src/index.js +14 -6
  58. package/src/lib/cacheInvalidation.js +52 -0
  59. package/src/lib/collapseAdjacentRules.js +16 -1
  60. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  61. package/src/lib/defaultExtractor.js +50 -0
  62. package/src/lib/evaluateTailwindFunctions.js +1 -1
  63. package/src/lib/expandApplyAtRules.js +285 -56
  64. package/src/lib/expandTailwindAtRules.js +75 -37
  65. package/src/lib/generateRules.js +121 -27
  66. package/src/lib/normalizeTailwindDirectives.js +7 -1
  67. package/src/lib/partitionApplyAtRules.js +52 -0
  68. package/src/lib/resolveDefaultsAtRules.js +35 -10
  69. package/src/lib/setupContextUtils.js +127 -45
  70. package/src/lib/setupTrackingContext.js +8 -7
  71. package/src/lib/sharedState.js +42 -4
  72. package/src/postcss-plugins/nesting/README.md +42 -0
  73. package/src/postcss-plugins/nesting/index.js +13 -0
  74. package/src/postcss-plugins/nesting/plugin.js +80 -0
  75. package/src/processTailwindFeatures.js +12 -2
  76. package/src/util/cloneNodes.js +14 -1
  77. package/src/util/color.js +20 -7
  78. package/src/util/dataTypes.js +7 -5
  79. package/src/util/defaults.js +6 -0
  80. package/src/util/log.js +10 -6
  81. package/src/util/normalizeConfig.js +24 -3
  82. package/src/util/normalizeScreens.js +6 -3
  83. package/src/util/parseBoxShadowValue.js +51 -3
  84. package/src/util/pluginUtils.js +1 -1
  85. package/src/util/prefixSelector.js +7 -5
  86. package/src/util/resolveConfig.js +41 -1
  87. package/src/util/toPath.js +23 -1
  88. package/stubs/defaultConfig.stub.js +2 -2
  89. package/lib/lib/setupWatchingContext.js +0 -288
  90. package/nesting/plugin.js +0 -41
  91. package/src/lib/setupWatchingContext.js +0 -311
@@ -9,7 +9,7 @@
9
9
  box-sizing: border-box; /* 1 */
10
10
  border-width: 0; /* 2 */
11
11
  border-style: solid; /* 2 */
12
- border-color: currentColor; /* 2 */
12
+ border-color: theme('borderColor.DEFAULT', currentColor); /* 2 */
13
13
  }
14
14
 
15
15
  ::before,
@@ -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
 
@@ -144,7 +144,7 @@ sup {
144
144
  table {
145
145
  text-indent: 0; /* 1 */
146
146
  border-color: inherit; /* 2 */
147
- border-collapse: collapse; /* 3 */
147
+ border-collapse: collapse; /* 3 */
148
148
  }
149
149
 
150
150
  /*
@@ -310,7 +310,7 @@ textarea {
310
310
 
311
311
  input::placeholder,
312
312
  textarea::placeholder {
313
- opacity: 1; /* 1 */
313
+ opacity: 1; /* 1 */
314
314
  color: theme('colors.gray.400', #9ca3af); /* 2 */
315
315
  }
316
316
 
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  exports.flagEnabled = flagEnabled;
6
6
  exports.issueFlagNotices = issueFlagNotices;
7
7
  exports.default = void 0;
8
- var _chalk = _interopRequireDefault(require("chalk"));
8
+ var _picocolors = _interopRequireDefault(require("picocolors"));
9
9
  var _log = _interopRequireDefault(require("./util/log"));
10
10
  function _interopRequireDefault(obj) {
11
11
  return obj && obj.__esModule ? obj : {
@@ -13,7 +13,7 @@ function _interopRequireDefault(obj) {
13
13
  };
14
14
  }
15
15
  let defaults = {
16
- optimizeUniversalDefaults: true
16
+ optimizeUniversalDefaults: false
17
17
  };
18
18
  let featureFlags = {
19
19
  future: [],
@@ -39,8 +39,7 @@ function experimentalFlagsEnabled(config) {
39
39
  return featureFlags.experimental;
40
40
  }
41
41
  var ref;
42
- return Object.keys((ref = config === null || config === void 0 ? void 0 : config.experimental) !== null && ref !== void 0 ? ref : {
43
- }).filter((flag)=>featureFlags.experimental.includes(flag) && config.experimental[flag]
42
+ return Object.keys((ref = config === null || config === void 0 ? void 0 : config.experimental) !== null && ref !== void 0 ? ref : {}).filter((flag)=>featureFlags.experimental.includes(flag) && config.experimental[flag]
44
43
  );
45
44
  }
46
45
  function issueFlagNotices(config) {
@@ -48,7 +47,7 @@ function issueFlagNotices(config) {
48
47
  return;
49
48
  }
50
49
  if (experimentalFlagsEnabled(config).length > 0) {
51
- let changes = experimentalFlagsEnabled(config).map((s)=>_chalk.default.yellow(s)
50
+ let changes = experimentalFlagsEnabled(config).map((s)=>_picocolors.default.yellow(s)
52
51
  ).join(', ');
53
52
  _log.default.warn('experimental-flags-enabled', [
54
53
  `You have enabled experimental features: ${changes}`,
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,18 @@ 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
+ let context = (0, _setupTrackingContext).default(configOrPath);
21
+ if (root.type === 'document') {
22
+ let roots = root.nodes.filter((node)=>node.type === 'root'
23
+ );
24
+ for (const root1 of roots){
25
+ if (root1.type === 'root') {
26
+ (0, _processTailwindFeatures).default(context)(root1, result);
27
+ }
28
+ }
29
+ return;
30
+ }
31
+ (0, _processTailwindFeatures).default(context)(root, result);
23
32
  },
24
33
  _sharedState.env.DEBUG && function(root) {
25
34
  console.timeEnd('JIT TOTAL');
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.hasContentChanged = hasContentChanged;
6
+ var _crypto = _interopRequireDefault(require("crypto"));
7
+ var sharedState = _interopRequireWildcard(require("./sharedState"));
8
+ function _interopRequireDefault(obj) {
9
+ return obj && obj.__esModule ? obj : {
10
+ default: obj
11
+ };
12
+ }
13
+ function _interopRequireWildcard(obj) {
14
+ if (obj && obj.__esModule) {
15
+ return obj;
16
+ } else {
17
+ var newObj = {};
18
+ if (obj != null) {
19
+ for(var key in obj){
20
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
21
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
22
+ if (desc.get || desc.set) {
23
+ Object.defineProperty(newObj, key, desc);
24
+ } else {
25
+ newObj[key] = obj[key];
26
+ }
27
+ }
28
+ }
29
+ }
30
+ newObj.default = obj;
31
+ return newObj;
32
+ }
33
+ }
34
+ /**
35
+ * Calculate the hash of a string.
36
+ *
37
+ * This doesn't need to be cryptographically secure or
38
+ * anything like that since it's used only to detect
39
+ * when the CSS changes to invalidate the context.
40
+ *
41
+ * This is wrapped in a try/catch because it's really dependent
42
+ * on how Node itself is build and the environment and OpenSSL
43
+ * version / build that is installed on the user's machine.
44
+ *
45
+ * Based on the environment this can just outright fail.
46
+ *
47
+ * See https://github.com/nodejs/node/issues/40455
48
+ *
49
+ * @param {string} str
50
+ */ function getHash(str) {
51
+ try {
52
+ return _crypto.default.createHash('md5').update(str, 'utf-8').digest('binary');
53
+ } catch (err) {
54
+ return '';
55
+ }
56
+ }
57
+ function hasContentChanged(sourcePath, root) {
58
+ let css = root.toString();
59
+ // We only care about files with @tailwind directives
60
+ // Other files use an existing context
61
+ if (!css.includes('@tailwind')) {
62
+ return false;
63
+ }
64
+ let existingHash = sharedState.sourceHashMap.get(sourcePath);
65
+ let rootHash = getHash(css);
66
+ let didChange = existingHash !== rootHash;
67
+ sharedState.sourceHashMap.set(sourcePath, rootHash);
68
+ return didChange;
69
+ }
@@ -14,7 +14,7 @@ let comparisonMap = {
14
14
  };
15
15
  let types = new Set(Object.keys(comparisonMap));
16
16
  function collapseAdjacentRules() {
17
- return (root)=>{
17
+ function collapseRulesIn(root) {
18
18
  let currentRule = null;
19
19
  root.each((node)=>{
20
20
  if (!types.has(node.type)) {
@@ -37,5 +37,18 @@ function collapseAdjacentRules() {
37
37
  currentRule = node;
38
38
  }
39
39
  });
40
+ // After we've collapsed adjacent rules & at-rules, we need to collapse
41
+ // adjacent rules & at-rules that are children of at-rules.
42
+ // We do not care about nesting rules because Tailwind CSS
43
+ // explicitly does not handle rule nesting on its own as
44
+ // the user is expected to use a nesting plugin
45
+ root.each((node)=>{
46
+ if (node.type === 'atrule') {
47
+ collapseRulesIn(node);
48
+ }
49
+ });
50
+ }
51
+ return (root)=>{
52
+ collapseRulesIn(root);
40
53
  };
41
54
  }
@@ -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,44 @@
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]*\('[^"`\s]*'\)+\])/.source,
17
+ /([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source,
18
+ /([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
19
+ /([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
20
+ /([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
21
+ /([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
22
+ /([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
23
+ /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
24
+ /([^"'`\s]*[^<>"'`\s:\\])/.source,
25
+ /([^<>"'`\s]*[^"'`\s:\\])/.source,
26
+ ].join('|');
27
+ const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
28
+ const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
29
+ function defaultExtractor(content) {
30
+ let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP);
31
+ let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
32
+ let results = [
33
+ ...broadMatches,
34
+ ...innerMatches
35
+ ].flat().filter((v)=>v !== undefined
36
+ );
37
+ return results;
38
+ } // Regular utilities
39
+ // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
40
+ // Arbitrary values
41
+ // {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
42
+ // arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
43
+ // Arbitrary properties
44
+ // {{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);