tailwindcss 0.0.0-insiders.4e21639 → 0.0.0-insiders.4e62334

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