tailwindcss 0.0.0-insiders.de1bdb4 → 0.0.0-insiders.deefbf5

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 (148) hide show
  1. package/CHANGELOG.md +415 -3
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +4 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli-peer-dependencies.js +10 -5
  11. package/lib/cli.js +329 -230
  12. package/lib/constants.js +9 -9
  13. package/lib/corePluginList.js +9 -1
  14. package/lib/corePlugins.js +1836 -1684
  15. package/lib/css/preflight.css +7 -13
  16. package/lib/featureFlags.js +17 -16
  17. package/lib/index.js +16 -8
  18. package/lib/lib/cacheInvalidation.js +87 -0
  19. package/lib/lib/collapseAdjacentRules.js +30 -15
  20. package/lib/lib/collapseDuplicateDeclarations.js +54 -3
  21. package/lib/lib/defaultExtractor.js +228 -0
  22. package/lib/lib/detectNesting.js +17 -2
  23. package/lib/lib/evaluateTailwindFunctions.js +79 -31
  24. package/lib/lib/expandApplyAtRules.js +401 -159
  25. package/lib/lib/expandTailwindAtRules.js +175 -144
  26. package/lib/lib/generateRules.js +342 -113
  27. package/lib/lib/getModuleDependencies.js +14 -14
  28. package/lib/lib/normalizeTailwindDirectives.js +43 -35
  29. package/lib/lib/partitionApplyAtRules.js +53 -0
  30. package/lib/lib/regex.js +52 -0
  31. package/lib/lib/resolveDefaultsAtRules.js +98 -69
  32. package/lib/lib/setupContextUtils.js +331 -258
  33. package/lib/lib/setupTrackingContext.js +61 -62
  34. package/lib/lib/sharedState.js +37 -5
  35. package/lib/lib/substituteScreenAtRules.js +8 -6
  36. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  37. package/lib/postcss-plugins/nesting/index.js +17 -0
  38. package/lib/postcss-plugins/nesting/plugin.js +84 -0
  39. package/lib/processTailwindFeatures.js +17 -9
  40. package/lib/public/colors.js +241 -241
  41. package/lib/public/resolve-config.js +5 -5
  42. package/lib/util/buildMediaQuery.js +12 -24
  43. package/lib/util/cloneDeep.js +3 -5
  44. package/lib/util/cloneNodes.js +12 -1
  45. package/lib/util/color.js +43 -37
  46. package/lib/util/createPlugin.js +1 -3
  47. package/lib/util/createUtilityPlugin.js +11 -16
  48. package/lib/util/dataTypes.js +99 -75
  49. package/lib/util/defaults.js +6 -0
  50. package/lib/util/escapeClassName.js +5 -5
  51. package/lib/util/escapeCommas.js +1 -1
  52. package/lib/util/flattenColorPalette.js +4 -9
  53. package/lib/util/formatVariantSelector.js +122 -30
  54. package/lib/util/getAllConfigs.js +15 -10
  55. package/lib/util/hashConfig.js +5 -5
  56. package/lib/util/isKeyframeRule.js +1 -1
  57. package/lib/util/isPlainObject.js +1 -1
  58. package/lib/util/isValidArbitraryValue.js +63 -0
  59. package/lib/util/log.js +12 -9
  60. package/lib/util/nameClass.js +7 -6
  61. package/lib/util/negateValue.js +4 -5
  62. package/lib/util/normalizeConfig.js +93 -51
  63. package/lib/util/normalizeScreens.js +58 -0
  64. package/lib/util/parseAnimationValue.js +56 -57
  65. package/lib/util/parseBoxShadowValue.js +76 -0
  66. package/lib/util/parseDependency.js +32 -32
  67. package/lib/util/parseObjectStyles.js +6 -6
  68. package/lib/util/pluginUtils.js +34 -32
  69. package/lib/util/prefixSelector.js +4 -5
  70. package/lib/util/removeAlphaVariables.js +18 -0
  71. package/lib/util/resolveConfig.js +95 -73
  72. package/lib/util/resolveConfigPath.js +17 -18
  73. package/lib/util/responsive.js +6 -6
  74. package/lib/util/splitAtTopLevelOnly.js +90 -0
  75. package/lib/util/toColorValue.js +1 -2
  76. package/lib/util/toPath.js +6 -1
  77. package/lib/util/transformThemeValue.js +42 -34
  78. package/lib/util/validateConfig.js +21 -0
  79. package/lib/util/withAlphaVariable.js +23 -23
  80. package/nesting/index.js +2 -12
  81. package/package.json +43 -43
  82. package/peers/index.js +11870 -9389
  83. package/plugin.d.ts +11 -0
  84. package/plugin.js +2 -1
  85. package/resolveConfig.js +2 -1
  86. package/scripts/generate-types.js +105 -0
  87. package/scripts/type-utils.js +27 -0
  88. package/src/cli-peer-dependencies.js +7 -1
  89. package/src/cli.js +185 -38
  90. package/src/corePluginList.js +1 -1
  91. package/src/corePlugins.js +460 -286
  92. package/src/css/preflight.css +7 -13
  93. package/src/featureFlags.js +5 -5
  94. package/src/index.js +14 -6
  95. package/src/lib/cacheInvalidation.js +52 -0
  96. package/src/lib/collapseAdjacentRules.js +21 -2
  97. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  98. package/src/lib/defaultExtractor.js +208 -0
  99. package/src/lib/detectNesting.js +22 -3
  100. package/src/lib/evaluateTailwindFunctions.js +62 -9
  101. package/src/lib/expandApplyAtRules.js +442 -154
  102. package/src/lib/expandTailwindAtRules.js +79 -39
  103. package/src/lib/generateRules.js +308 -84
  104. package/src/lib/normalizeTailwindDirectives.js +7 -1
  105. package/src/lib/partitionApplyAtRules.js +52 -0
  106. package/src/lib/regex.js +74 -0
  107. package/src/lib/resolveDefaultsAtRules.js +59 -17
  108. package/src/lib/setupContextUtils.js +261 -136
  109. package/src/lib/setupTrackingContext.js +12 -7
  110. package/src/lib/sharedState.js +42 -4
  111. package/src/lib/substituteScreenAtRules.js +6 -3
  112. package/src/postcss-plugins/nesting/README.md +42 -0
  113. package/src/postcss-plugins/nesting/index.js +13 -0
  114. package/src/postcss-plugins/nesting/plugin.js +80 -0
  115. package/src/processTailwindFeatures.js +12 -2
  116. package/src/util/buildMediaQuery.js +14 -18
  117. package/src/util/cloneNodes.js +14 -1
  118. package/src/util/color.js +31 -14
  119. package/src/util/dataTypes.js +36 -12
  120. package/src/util/defaults.js +6 -0
  121. package/src/util/formatVariantSelector.js +134 -24
  122. package/src/util/getAllConfigs.js +7 -0
  123. package/src/util/isValidArbitraryValue.js +61 -0
  124. package/src/util/log.js +11 -7
  125. package/src/util/nameClass.js +1 -1
  126. package/src/util/normalizeConfig.js +16 -3
  127. package/src/util/normalizeScreens.js +45 -0
  128. package/src/util/parseBoxShadowValue.js +72 -0
  129. package/src/util/pluginUtils.js +16 -2
  130. package/src/util/prefixSelector.js +7 -5
  131. package/src/util/removeAlphaVariables.js +24 -0
  132. package/src/util/resolveConfig.js +70 -16
  133. package/src/util/splitAtTopLevelOnly.js +71 -0
  134. package/src/util/toPath.js +23 -1
  135. package/src/util/transformThemeValue.js +24 -7
  136. package/src/util/validateConfig.js +13 -0
  137. package/src/util/withAlphaVariable.js +1 -1
  138. package/stubs/defaultConfig.stub.js +47 -17
  139. package/stubs/simpleConfig.stub.js +1 -0
  140. package/types/config.d.ts +327 -0
  141. package/types/generated/.gitkeep +0 -0
  142. package/types/generated/colors.d.ts +276 -0
  143. package/types/generated/corePluginList.d.ts +1 -0
  144. package/types/generated/default-theme.d.ts +331 -0
  145. package/types/index.d.ts +7 -0
  146. package/lib/lib/setupWatchingContext.js +0 -288
  147. package/nesting/plugin.js +0 -41
  148. 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
  /*
@@ -160,6 +160,7 @@ select,
160
160
  textarea {
161
161
  font-family: inherit; /* 1 */
162
162
  font-size: 100%; /* 1 */
163
+ font-weight: inherit; /* 1 */
163
164
  line-height: inherit; /* 1 */
164
165
  color: inherit; /* 1 */
165
166
  margin: 0; /* 2 */
@@ -288,7 +289,8 @@ legend {
288
289
  }
289
290
 
290
291
  ol,
291
- ul {
292
+ ul,
293
+ menu {
292
294
  list-style: none;
293
295
  margin: 0;
294
296
  padding: 0;
@@ -309,7 +311,7 @@ textarea {
309
311
 
310
312
  input::placeholder,
311
313
  textarea::placeholder {
312
- opacity: 1; /* 1 */
314
+ opacity: 1; /* 1 */
313
315
  color: theme('colors.gray.400', #9ca3af); /* 2 */
314
316
  }
315
317
 
@@ -356,11 +358,3 @@ video {
356
358
  max-width: 100%;
357
359
  height: auto;
358
360
  }
359
-
360
- /*
361
- Ensure the default browser behavior of the `hidden` attribute.
362
- */
363
-
364
- [hidden] {
365
- display: none;
366
- }
@@ -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,46 +13,47 @@ function _interopRequireDefault(obj) {
13
13
  };
14
14
  }
15
15
  let defaults = {
16
- optimizeUniversalDefaults: true
16
+ optimizeUniversalDefaults: false
17
17
  };
18
18
  let featureFlags = {
19
- future: [],
19
+ future: [
20
+ "hoverOnlyWhenSupported",
21
+ "respectDefaultRingColorOpacity"
22
+ ],
20
23
  experimental: [
21
- 'optimizeUniversalDefaults'
24
+ "optimizeUniversalDefaults",
25
+ "matchVariant" /* , 'variantGrouping' */
22
26
  ]
23
27
  };
24
28
  function flagEnabled(config, flag) {
25
29
  if (featureFlags.future.includes(flag)) {
26
30
  var ref;
27
31
  var ref1, ref2;
28
- return config.future === 'all' || ((ref2 = (ref1 = config === null || config === void 0 ? void 0 : (ref = config.future) === null || ref === void 0 ? void 0 : ref[flag]) !== null && ref1 !== void 0 ? ref1 : defaults[flag]) !== null && ref2 !== void 0 ? ref2 : false);
32
+ return config.future === "all" || ((ref2 = (ref1 = config === null || config === void 0 ? void 0 : (ref = config.future) === null || ref === void 0 ? void 0 : ref[flag]) !== null && ref1 !== void 0 ? ref1 : defaults[flag]) !== null && ref2 !== void 0 ? ref2 : false);
29
33
  }
30
34
  if (featureFlags.experimental.includes(flag)) {
31
- var ref;
32
- var ref11, ref12;
33
- return config.experimental === 'all' || ((ref12 = (ref11 = config === null || config === void 0 ? void 0 : (ref = config.experimental) === null || ref === void 0 ? void 0 : ref[flag]) !== null && ref11 !== void 0 ? ref11 : defaults[flag]) !== null && ref12 !== void 0 ? ref12 : false);
35
+ var ref3;
36
+ var ref4, ref5;
37
+ return config.experimental === "all" || ((ref5 = (ref4 = config === null || config === void 0 ? void 0 : (ref3 = config.experimental) === null || ref3 === void 0 ? void 0 : ref3[flag]) !== null && ref4 !== void 0 ? ref4 : defaults[flag]) !== null && ref5 !== void 0 ? ref5 : false);
34
38
  }
35
39
  return false;
36
40
  }
37
41
  function experimentalFlagsEnabled(config) {
38
- if (config.experimental === 'all') {
42
+ if (config.experimental === "all") {
39
43
  return featureFlags.experimental;
40
44
  }
41
45
  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]
44
- );
46
+ 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]);
45
47
  }
46
48
  function issueFlagNotices(config) {
47
49
  if (process.env.JEST_WORKER_ID !== undefined) {
48
50
  return;
49
51
  }
50
52
  if (experimentalFlagsEnabled(config).length > 0) {
51
- let changes = experimentalFlagsEnabled(config).map((s)=>_chalk.default.yellow(s)
52
- ).join(', ');
53
- _log.default.warn('experimental-flags-enabled', [
53
+ let changes = experimentalFlagsEnabled(config).map((s)=>_picocolors.default.yellow(s)).join(", ");
54
+ _log.default.warn("experimental-flags-enabled", [
54
55
  `You have enabled experimental features: ${changes}`,
55
- 'Experimental features in Tailwind CSS are not covered by semver, may introduce breaking changes, and can change at any time.',
56
+ "Experimental features in Tailwind CSS are not covered by semver, may introduce breaking changes, and can change at any time.",
56
57
  ]);
57
58
  }
58
59
  }
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) {
@@ -10,20 +9,29 @@ function _interopRequireDefault(obj) {
10
9
  }
11
10
  module.exports = function tailwindcss(configOrPath) {
12
11
  return {
13
- postcssPlugin: 'tailwindcss',
12
+ postcssPlugin: "tailwindcss",
14
13
  plugins: [
15
14
  _sharedState.env.DEBUG && function(root) {
16
- console.log('\n');
17
- console.time('JIT TOTAL');
15
+ console.log("\n");
16
+ console.time("JIT TOTAL");
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
+ for (const root1 of roots){
24
+ if (root1.type === "root") {
25
+ (0, _processTailwindFeatures).default(context)(root1, result);
26
+ }
27
+ }
28
+ return;
29
+ }
30
+ (0, _processTailwindFeatures).default(context)(root, result);
23
31
  },
24
32
  _sharedState.env.DEBUG && function(root) {
25
- console.timeEnd('JIT TOTAL');
26
- console.log('\n');
33
+ console.timeEnd("JIT TOTAL");
34
+ console.log("\n");
27
35
  return root;
28
36
  },
29
37
  ].filter(Boolean)
@@ -0,0 +1,87 @@
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 _getRequireWildcardCache() {
14
+ if (typeof WeakMap !== "function") return null;
15
+ var cache = new WeakMap();
16
+ _getRequireWildcardCache = function() {
17
+ return cache;
18
+ };
19
+ return cache;
20
+ }
21
+ function _interopRequireWildcard(obj) {
22
+ if (obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache();
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for(var key in obj){
37
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ /**
53
+ * Calculate the hash of a string.
54
+ *
55
+ * This doesn't need to be cryptographically secure or
56
+ * anything like that since it's used only to detect
57
+ * when the CSS changes to invalidate the context.
58
+ *
59
+ * This is wrapped in a try/catch because it's really dependent
60
+ * on how Node itself is build and the environment and OpenSSL
61
+ * version / build that is installed on the user's machine.
62
+ *
63
+ * Based on the environment this can just outright fail.
64
+ *
65
+ * See https://github.com/nodejs/node/issues/40455
66
+ *
67
+ * @param {string} str
68
+ */ function getHash(str) {
69
+ try {
70
+ return _crypto.default.createHash("md5").update(str, "utf-8").digest("binary");
71
+ } catch (err) {
72
+ return "";
73
+ }
74
+ }
75
+ function hasContentChanged(sourcePath, root) {
76
+ let css = root.toString();
77
+ // We only care about files with @tailwind directives
78
+ // Other files use an existing context
79
+ if (!css.includes("@tailwind")) {
80
+ return false;
81
+ }
82
+ let existingHash = sharedState.sourceHashMap.get(sourcePath);
83
+ let rootHash = getHash(css);
84
+ let didChange = existingHash !== rootHash;
85
+ sharedState.sourceHashMap.set(sourcePath, rootHash);
86
+ return didChange;
87
+ }
@@ -3,18 +3,8 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.default = collapseAdjacentRules;
6
- let comparisonMap = {
7
- atrule: [
8
- 'name',
9
- 'params'
10
- ],
11
- rule: [
12
- 'selector'
13
- ]
14
- };
15
- let types = new Set(Object.keys(comparisonMap));
16
6
  function collapseAdjacentRules() {
17
- return (root)=>{
7
+ function collapseRulesIn(root) {
18
8
  let currentRule = null;
19
9
  root.each((node)=>{
20
10
  if (!types.has(node.type)) {
@@ -27,15 +17,40 @@ function collapseAdjacentRules() {
27
17
  }
28
18
  let properties = comparisonMap[node.type];
29
19
  var _property, _property1;
30
- if (node.type === 'atrule' && node.name === 'font-face') {
20
+ if (node.type === "atrule" && node.name === "font-face") {
31
21
  currentRule = node;
32
- } else if (properties.every((property)=>((_property = node[property]) !== null && _property !== void 0 ? _property : '').replace(/\s+/g, ' ') === ((_property1 = currentRule[property]) !== null && _property1 !== void 0 ? _property1 : '').replace(/\s+/g, ' ')
33
- )) {
34
- currentRule.append(node.nodes);
22
+ } else if (properties.every((property)=>((_property = node[property]) !== null && _property !== void 0 ? _property : "").replace(/\s+/g, " ") === ((_property1 = currentRule[property]) !== null && _property1 !== void 0 ? _property1 : "").replace(/\s+/g, " "))) {
23
+ // An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
24
+ if (node.nodes) {
25
+ currentRule.append(node.nodes);
26
+ }
35
27
  node.remove();
36
28
  } else {
37
29
  currentRule = node;
38
30
  }
39
31
  });
32
+ // After we've collapsed adjacent rules & at-rules, we need to collapse
33
+ // adjacent rules & at-rules that are children of at-rules.
34
+ // We do not care about nesting rules because Tailwind CSS
35
+ // explicitly does not handle rule nesting on its own as
36
+ // the user is expected to use a nesting plugin
37
+ root.each((node)=>{
38
+ if (node.type === "atrule") {
39
+ collapseRulesIn(node);
40
+ }
41
+ });
42
+ }
43
+ return (root)=>{
44
+ collapseRulesIn(root);
40
45
  };
41
46
  }
47
+ let comparisonMap = {
48
+ atrule: [
49
+ "name",
50
+ "params"
51
+ ],
52
+ rule: [
53
+ "selector"
54
+ ]
55
+ };
56
+ let types = new Set(Object.keys(comparisonMap));
@@ -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
  });
24
- for (let decl of droppable){
25
- decl.remove();
42
+ // Drop all the duplicate declarations with the exact same value we've
43
+ // already seen so far.
44
+ for (let decl1 of droppable){
45
+ decl1.remove();
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
+ }
26
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,228 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.defaultExtractor = defaultExtractor;
6
+ var _featureFlags = require("../featureFlags");
7
+ var regex = _interopRequireWildcard(require("./regex"));
8
+ function _getRequireWildcardCache() {
9
+ if (typeof WeakMap !== "function") return null;
10
+ var cache = new WeakMap();
11
+ _getRequireWildcardCache = function() {
12
+ return cache;
13
+ };
14
+ return cache;
15
+ }
16
+ function _interopRequireWildcard(obj) {
17
+ if (obj && obj.__esModule) {
18
+ return obj;
19
+ }
20
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
21
+ return {
22
+ default: obj
23
+ };
24
+ }
25
+ var cache = _getRequireWildcardCache();
26
+ if (cache && cache.has(obj)) {
27
+ return cache.get(obj);
28
+ }
29
+ var newObj = {};
30
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
31
+ for(var key in obj){
32
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
33
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
34
+ if (desc && (desc.get || desc.set)) {
35
+ Object.defineProperty(newObj, key, desc);
36
+ } else {
37
+ newObj[key] = obj[key];
38
+ }
39
+ }
40
+ }
41
+ newObj.default = obj;
42
+ if (cache) {
43
+ cache.set(obj, newObj);
44
+ }
45
+ return newObj;
46
+ }
47
+ function defaultExtractor(context) {
48
+ let patterns = Array.from(buildRegExps(context));
49
+ /**
50
+ * @param {string} content
51
+ */ return (content)=>{
52
+ /** @type {(string|string)[]} */ let results = [];
53
+ for (let pattern of patterns){
54
+ var ref;
55
+ results = [
56
+ ...results,
57
+ ...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []
58
+ ];
59
+ }
60
+ return results.filter((v)=>v !== undefined).map(clipAtBalancedParens);
61
+ };
62
+ }
63
+ function* buildRegExps(context) {
64
+ let separator = context.tailwindConfig.separator;
65
+ let variantGroupingEnabled = (0, _featureFlags).flagEnabled(context.tailwindConfig, "variantGrouping");
66
+ let prefix = context.tailwindConfig.prefix !== "" ? regex.optional(regex.pattern([
67
+ /-?/,
68
+ regex.escape(context.tailwindConfig.prefix)
69
+ ])) : "";
70
+ let utility = regex.any([
71
+ // Arbitrary properties
72
+ /\[[^\s:'"`]+:[^\s\]]+\]/,
73
+ // Utilities
74
+ regex.pattern([
75
+ // Utility Name / Group Name
76
+ /-?(?:\w+)/,
77
+ // Normal/Arbitrary values
78
+ regex.optional(regex.any([
79
+ regex.pattern([
80
+ // Arbitrary values
81
+ /-(?:\w+-)*\[[^\s:]+\]/,
82
+ // Not immediately followed by an `{[(`
83
+ /(?![{([]])/,
84
+ // optionally followed by an opacity modifier
85
+ /(?:\/[^\s'"`\\><$]*)?/,
86
+ ]),
87
+ regex.pattern([
88
+ // Arbitrary values
89
+ /-(?:\w+-)*\[[^\s]+\]/,
90
+ // Not immediately followed by an `{[(`
91
+ /(?![{([]])/,
92
+ // optionally followed by an opacity modifier
93
+ /(?:\/[^\s'"`\\$]*)?/,
94
+ ]),
95
+ // Normal values w/o quotes — may include an opacity modifier
96
+ /[-\/][^\s'"`\\$={><]*/,
97
+ ])),
98
+ ]),
99
+ ]);
100
+ let variantPatterns = [
101
+ // Without quotes
102
+ regex.any([
103
+ regex.pattern([
104
+ /([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/,
105
+ separator
106
+ ]),
107
+ regex.pattern([
108
+ /[^\s"'`\[\\]+/,
109
+ separator
110
+ ]),
111
+ ]),
112
+ // With quotes allowed
113
+ regex.any([
114
+ regex.pattern([
115
+ /([^\s"'`\[\\]+-)?\[[^\s`]+\]/,
116
+ separator
117
+ ]),
118
+ regex.pattern([
119
+ /[^\s`\[\\]+/,
120
+ separator
121
+ ]),
122
+ ]),
123
+ ];
124
+ for (const variantPattern of variantPatterns){
125
+ yield regex.pattern([
126
+ // Variants
127
+ "((?=((",
128
+ variantPattern,
129
+ ")+))\\2)?",
130
+ // Important (optional)
131
+ /!?/,
132
+ prefix,
133
+ variantGroupingEnabled ? regex.any([
134
+ // Or any of those things but grouped separated by commas
135
+ regex.pattern([
136
+ /\(/,
137
+ utility,
138
+ regex.zeroOrMore([
139
+ /,/,
140
+ utility
141
+ ]),
142
+ /\)/
143
+ ]),
144
+ // Arbitrary properties, constrained utilities, arbitrary values, etc…
145
+ utility,
146
+ ]) : utility,
147
+ ]);
148
+ }
149
+ // 5. Inner matches
150
+ yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
151
+ }
152
+ // We want to capture any "special" characters
153
+ // AND the characters immediately following them (if there is one)
154
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
155
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
156
+ /**
157
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
158
+ * Used for arbitrary values only
159
+ *
160
+ * We will go past the end of the balanced parens until we find a non-class character
161
+ *
162
+ * Depth matching behavior:
163
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
164
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
165
+ * 1 2 3 4 34 3 210 END
166
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
167
+ *
168
+ * @param {string} input
169
+ */ function clipAtBalancedParens(input) {
170
+ // We are care about this for arbitrary values
171
+ if (!input.includes("-[")) {
172
+ return input;
173
+ }
174
+ let depth = 0;
175
+ let openStringTypes = [];
176
+ // Find all parens, brackets, quotes, etc
177
+ // Stop when we end at a balanced pair
178
+ // This is naive and will treat mismatched parens as balanced
179
+ // This shouldn't be a problem in practice though
180
+ let matches = input.matchAll(SPECIALS);
181
+ // We can't use lookbehind assertions because we have to support Safari
182
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
183
+ matches = Array.from(matches).flatMap((match)=>{
184
+ const [, ...groups] = match;
185
+ return groups.map((group, idx)=>Object.assign([], match, {
186
+ index: match.index + idx,
187
+ 0: group
188
+ }));
189
+ });
190
+ for (let match1 of matches){
191
+ let char = match1[0];
192
+ let inStringType = openStringTypes[openStringTypes.length - 1];
193
+ if (char === inStringType) {
194
+ openStringTypes.pop();
195
+ } else if (char === "'" || char === '"' || char === "`") {
196
+ openStringTypes.push(char);
197
+ }
198
+ if (inStringType) {
199
+ continue;
200
+ } else if (char === "[") {
201
+ depth++;
202
+ continue;
203
+ } else if (char === "]") {
204
+ depth--;
205
+ continue;
206
+ }
207
+ // We've gone one character past the point where we should stop
208
+ // This means that there was an extra closing `]`
209
+ // We'll clip to just before it
210
+ if (depth < 0) {
211
+ return input.substring(0, match1.index);
212
+ }
213
+ // We've finished balancing the brackets but there still may be characters that can be included
214
+ // For example in the class `text-[#336699]/[.35]`
215
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
216
+ // If we're at zero and encounter a non-class character then we clip the class there
217
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
218
+ return input.substring(0, match1.index);
219
+ }
220
+ }
221
+ return input;
222
+ } // Regular utilities
223
+ // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
224
+ // Arbitrary values
225
+ // {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
226
+ // arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
227
+ // Arbitrary properties
228
+ // {{modifier}:}*[{validCssPropertyName}:{arbitraryValue}]
@@ -6,12 +6,27 @@ exports.default = _default;
6
6
  function _default(_context) {
7
7
  return (root, result)=>{
8
8
  let found = false;
9
+ root.walkAtRules("tailwind", (node)=>{
10
+ if (found) return false;
11
+ if (node.parent && node.parent.type !== "root") {
12
+ found = true;
13
+ node.warn(result, [
14
+ "Nested @tailwind rules were detected, but are not supported.",
15
+ "Consider using a prefix to scope Tailwind's classes: https://tailwindcss.com/docs/configuration#prefix",
16
+ "Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy",
17
+ ].join("\n"));
18
+ return false;
19
+ }
20
+ });
9
21
  root.walkRules((rule)=>{
10
22
  if (found) return false;
11
23
  rule.walkRules((nestedRule)=>{
12
24
  found = true;
13
- nestedRule.warn(result, // TODO: Improve this warning message
14
- 'Nested CSS detected, checkout the docs on how to support nesting: https://tailwindcss.com/docs/using-with-preprocessors#nesting');
25
+ nestedRule.warn(result, [
26
+ "Nested CSS was detected, but CSS nesting has not been configured correctly.",
27
+ "Please enable a CSS nesting plugin *before* Tailwind in your configuration.",
28
+ "See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting",
29
+ ].join("\n"));
15
30
  return false;
16
31
  });
17
32
  });