tailwindcss 3.0.23 → 3.1.1

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 (119) hide show
  1. package/CHANGELOG.md +92 -2
  2. package/colors.d.ts +3 -0
  3. package/defaultConfig.d.ts +3 -0
  4. package/defaultTheme.d.ts +3 -0
  5. package/lib/cli-peer-dependencies.js +10 -5
  6. package/lib/cli.js +266 -203
  7. package/lib/constants.js +8 -8
  8. package/lib/corePluginList.js +1 -0
  9. package/lib/corePlugins.js +1640 -1562
  10. package/lib/css/preflight.css +1 -8
  11. package/lib/featureFlags.js +14 -12
  12. package/lib/index.js +16 -6
  13. package/lib/lib/cacheInvalidation.js +87 -0
  14. package/lib/lib/collapseAdjacentRules.js +30 -15
  15. package/lib/lib/collapseDuplicateDeclarations.js +1 -1
  16. package/lib/lib/defaultExtractor.js +191 -32
  17. package/lib/lib/detectNesting.js +9 -9
  18. package/lib/lib/evaluateTailwindFunctions.js +37 -28
  19. package/lib/lib/expandApplyAtRules.js +379 -189
  20. package/lib/lib/expandTailwindAtRules.js +168 -144
  21. package/lib/lib/generateRules.js +177 -95
  22. package/lib/lib/getModuleDependencies.js +14 -14
  23. package/lib/lib/normalizeTailwindDirectives.js +35 -35
  24. package/lib/lib/partitionApplyAtRules.js +7 -7
  25. package/lib/lib/regex.js +52 -0
  26. package/lib/lib/resolveDefaultsAtRules.js +96 -81
  27. package/lib/lib/setupContextUtils.js +202 -159
  28. package/lib/lib/setupTrackingContext.js +61 -63
  29. package/lib/lib/sharedState.js +10 -9
  30. package/lib/lib/substituteScreenAtRules.js +3 -4
  31. package/lib/postcss-plugins/nesting/README.md +2 -2
  32. package/lib/postcss-plugins/nesting/index.js +1 -1
  33. package/lib/postcss-plugins/nesting/plugin.js +40 -9
  34. package/lib/processTailwindFeatures.js +7 -7
  35. package/lib/public/colors.js +241 -241
  36. package/lib/public/resolve-config.js +5 -5
  37. package/lib/util/buildMediaQuery.js +2 -3
  38. package/lib/util/cloneDeep.js +3 -5
  39. package/lib/util/cloneNodes.js +12 -1
  40. package/lib/util/color.js +42 -51
  41. package/lib/util/createPlugin.js +1 -2
  42. package/lib/util/createUtilityPlugin.js +6 -7
  43. package/lib/util/dataTypes.js +85 -81
  44. package/lib/util/escapeClassName.js +5 -5
  45. package/lib/util/escapeCommas.js +1 -1
  46. package/lib/util/flattenColorPalette.js +4 -7
  47. package/lib/util/formatVariantSelector.js +82 -75
  48. package/lib/util/getAllConfigs.js +15 -10
  49. package/lib/util/hashConfig.js +5 -5
  50. package/lib/util/isKeyframeRule.js +1 -1
  51. package/lib/util/isPlainObject.js +1 -1
  52. package/lib/util/isValidArbitraryValue.js +26 -27
  53. package/lib/util/log.js +9 -10
  54. package/lib/util/nameClass.js +7 -7
  55. package/lib/util/negateValue.js +4 -5
  56. package/lib/util/normalizeConfig.js +68 -58
  57. package/lib/util/normalizeScreens.js +5 -6
  58. package/lib/util/parseAnimationValue.js +56 -57
  59. package/lib/util/parseBoxShadowValue.js +19 -20
  60. package/lib/util/parseDependency.js +32 -32
  61. package/lib/util/parseObjectStyles.js +6 -6
  62. package/lib/util/pluginUtils.js +20 -12
  63. package/lib/util/prefixSelector.js +1 -1
  64. package/lib/util/resolveConfig.js +81 -58
  65. package/lib/util/resolveConfigPath.js +16 -16
  66. package/lib/util/responsive.js +6 -6
  67. package/lib/util/splitAtTopLevelOnly.js +90 -0
  68. package/lib/util/toColorValue.js +1 -1
  69. package/lib/util/toPath.js +2 -2
  70. package/lib/util/transformThemeValue.js +30 -28
  71. package/lib/util/validateConfig.js +21 -0
  72. package/lib/util/withAlphaVariable.js +23 -23
  73. package/package.json +33 -27
  74. package/peers/index.js +7702 -5822
  75. package/plugin.d.ts +11 -0
  76. package/scripts/generate-types.js +52 -0
  77. package/src/cli-peer-dependencies.js +7 -1
  78. package/src/cli.js +118 -24
  79. package/src/corePluginList.js +1 -1
  80. package/src/corePlugins.js +109 -30
  81. package/src/css/preflight.css +1 -8
  82. package/src/featureFlags.js +4 -4
  83. package/src/index.js +15 -1
  84. package/src/lib/cacheInvalidation.js +52 -0
  85. package/src/lib/collapseAdjacentRules.js +21 -2
  86. package/src/lib/defaultExtractor.js +177 -35
  87. package/src/lib/evaluateTailwindFunctions.js +20 -4
  88. package/src/lib/expandApplyAtRules.js +418 -186
  89. package/src/lib/expandTailwindAtRules.js +29 -9
  90. package/src/lib/generateRules.js +137 -51
  91. package/src/lib/regex.js +74 -0
  92. package/src/lib/resolveDefaultsAtRules.js +53 -32
  93. package/src/lib/setupContextUtils.js +128 -65
  94. package/src/lib/setupTrackingContext.js +7 -3
  95. package/src/lib/sharedState.js +1 -0
  96. package/src/postcss-plugins/nesting/README.md +2 -2
  97. package/src/postcss-plugins/nesting/plugin.js +36 -0
  98. package/src/util/cloneNodes.js +14 -1
  99. package/src/util/color.js +25 -21
  100. package/src/util/dataTypes.js +14 -6
  101. package/src/util/formatVariantSelector.js +79 -62
  102. package/src/util/getAllConfigs.js +7 -0
  103. package/src/util/log.js +8 -8
  104. package/src/util/normalizeConfig.js +0 -8
  105. package/src/util/parseBoxShadowValue.js +3 -2
  106. package/src/util/pluginUtils.js +13 -1
  107. package/src/util/resolveConfig.js +66 -22
  108. package/src/util/splitAtTopLevelOnly.js +71 -0
  109. package/src/util/toPath.js +1 -1
  110. package/src/util/transformThemeValue.js +4 -2
  111. package/src/util/validateConfig.js +13 -0
  112. package/src/util/withAlphaVariable.js +1 -1
  113. package/stubs/defaultConfig.stub.js +5 -1
  114. package/stubs/simpleConfig.stub.js +1 -0
  115. package/types/config.d.ts +325 -0
  116. package/types/generated/.gitkeep +0 -0
  117. package/types/generated/colors.d.ts +276 -0
  118. package/types/generated/corePluginList.d.ts +1 -0
  119. package/types/index.d.ts +7 -0
@@ -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 */
@@ -357,11 +358,3 @@ video {
357
358
  max-width: 100%;
358
359
  height: auto;
359
360
  }
360
-
361
- /*
362
- Ensure the default browser behavior of the `hidden` attribute.
363
- */
364
-
365
- [hidden] {
366
- display: none;
367
- }
@@ -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 : {
@@ -16,42 +16,44 @@ let defaults = {
16
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
35
  var ref3;
32
36
  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);
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 : {}).filter((flag)=>featureFlags.experimental.includes(flag) && config.experimental[flag]
43
- );
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]);
44
47
  }
45
48
  function issueFlagNotices(config) {
46
49
  if (process.env.JEST_WORKER_ID !== undefined) {
47
50
  return;
48
51
  }
49
52
  if (experimentalFlagsEnabled(config).length > 0) {
50
- let changes = experimentalFlagsEnabled(config).map((s)=>_chalk.default.yellow(s)
51
- ).join(', ');
52
- _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", [
53
55
  `You have enabled experimental features: ${changes}`,
54
- '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.",
55
57
  ]);
56
58
  }
57
59
  }
package/lib/index.js CHANGED
@@ -9,19 +9,29 @@ function _interopRequireDefault(obj) {
9
9
  }
10
10
  module.exports = function tailwindcss(configOrPath) {
11
11
  return {
12
- postcssPlugin: 'tailwindcss',
12
+ postcssPlugin: "tailwindcss",
13
13
  plugins: [
14
14
  _sharedState.env.DEBUG && function(root) {
15
- console.log('\n');
16
- console.time('JIT TOTAL');
15
+ console.log("\n");
16
+ console.time("JIT TOTAL");
17
17
  return root;
18
18
  },
19
19
  function(root, result) {
20
- (0, _processTailwindFeatures).default((0, _setupTrackingContext).default(configOrPath))(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);
21
31
  },
22
32
  _sharedState.env.DEBUG && function(root) {
23
- console.timeEnd('JIT TOTAL');
24
- console.log('\n');
33
+ console.timeEnd("JIT TOTAL");
34
+ console.log("\n");
25
35
  return root;
26
36
  },
27
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));
@@ -69,7 +69,7 @@ function collapseDuplicateDeclarations() {
69
69
  });
70
70
  };
71
71
  }
72
- let UNITLESS_NUMBER = Symbol('unitless-number');
72
+ let UNITLESS_NUMBER = Symbol("unitless-number");
73
73
  function resolveUnit(input) {
74
74
  let result = /^-?\d*.?\d+([\w%]+)?$/g.exec(input);
75
75
  if (result) {
@@ -3,38 +3,197 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
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;
6
+ var _featureFlagsJs = require("../featureFlags.js");
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.push(...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []);
56
+ }
57
+ return results.filter((v)=>v !== undefined).map(clipAtBalancedParens);
58
+ };
59
+ }
60
+ function* buildRegExps(context) {
61
+ let separator = context.tailwindConfig.separator;
62
+ let variantGroupingEnabled = (0, _featureFlagsJs).flagEnabled(context.tailwindConfig, "variantGrouping");
63
+ let utility = regex.any([
64
+ // Arbitrary properties
65
+ /\[[^\s:'"`]+:[^\s\]]+\]/,
66
+ // Utilities
67
+ regex.pattern([
68
+ // Utility Name / Group Name
69
+ /-?(?:\w+)/,
70
+ // Normal/Arbitrary values
71
+ regex.optional(regex.any([
72
+ regex.pattern([
73
+ // Arbitrary values
74
+ /-\[[^\s:]+\]/,
75
+ // Not immediately followed by an `{[(`
76
+ /(?![{([]])/,
77
+ // optionally followed by an opacity modifier
78
+ /(?:\/[^\s'"`\\><$]*)?/,
79
+ ]),
80
+ regex.pattern([
81
+ // Arbitrary values
82
+ /-\[[^\s]+\]/,
83
+ // Not immediately followed by an `{[(`
84
+ /(?![{([]])/,
85
+ // optionally followed by an opacity modifier
86
+ /(?:\/[^\s'"`\\$]*)?/,
87
+ ]),
88
+ // Normal values w/o quotes — may include an opacity modifier
89
+ /[-\/][^\s'"`\\$={><]*/,
90
+ ])),
91
+ ]),
92
+ ]);
93
+ yield regex.pattern([
94
+ // Variants
95
+ "((?=((",
96
+ regex.any([
97
+ regex.pattern([
98
+ /([^\s"'`\[\\]+-)?\[[^\s"'`\\]+\]/,
99
+ separator
100
+ ]),
101
+ regex.pattern([
102
+ /[^\s"'`\[\\]+/,
103
+ separator
104
+ ]),
105
+ ], true),
106
+ ")+))\\2)?",
107
+ // Important (optional)
108
+ /!?/,
109
+ variantGroupingEnabled ? regex.any([
110
+ // Or any of those things but grouped separated by commas
111
+ regex.pattern([
112
+ /\(/,
113
+ utility,
114
+ regex.zeroOrMore([
115
+ /,/,
116
+ utility
117
+ ]),
118
+ /\)/
119
+ ]),
120
+ // Arbitrary properties, constrained utilities, arbitrary values, etc…
121
+ utility,
122
+ ]) : utility,
123
+ ]);
124
+ // 5. Inner matches
125
+ yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
126
+ }
127
+ // We want to capture any "special" characters
128
+ // AND the characters immediately following them (if there is one)
129
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
130
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
131
+ /**
132
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
133
+ * Used for arbitrary values only
134
+ *
135
+ * We will go past the end of the balanced parens until we find a non-class character
136
+ *
137
+ * Depth matching behavior:
138
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
139
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
140
+ * 1 2 3 4 34 3 210 END
141
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
142
+ *
143
+ * @param {string} input
144
+ */ function clipAtBalancedParens(input) {
145
+ // We are care about this for arbitrary values
146
+ if (!input.includes("-[")) {
147
+ return input;
148
+ }
149
+ let depth = 0;
150
+ let openStringTypes = [];
151
+ // Find all parens, brackets, quotes, etc
152
+ // Stop when we end at a balanced pair
153
+ // This is naive and will treat mismatched parens as balanced
154
+ // This shouldn't be a problem in practice though
155
+ let matches = input.matchAll(SPECIALS);
156
+ // We can't use lookbehind assertions because we have to support Safari
157
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
158
+ matches = Array.from(matches).flatMap((match)=>{
159
+ const [, ...groups] = match;
160
+ return groups.map((group, idx)=>Object.assign([], match, {
161
+ index: match.index + idx,
162
+ 0: group
163
+ }));
164
+ });
165
+ for (let match1 of matches){
166
+ let char = match1[0];
167
+ let inStringType = openStringTypes[openStringTypes.length - 1];
168
+ if (char === inStringType) {
169
+ openStringTypes.pop();
170
+ } else if (char === "'" || char === '"' || char === "`") {
171
+ openStringTypes.push(char);
172
+ }
173
+ if (inStringType) {
174
+ continue;
175
+ } else if (char === "[") {
176
+ depth++;
177
+ continue;
178
+ } else if (char === "]") {
179
+ depth--;
180
+ continue;
181
+ }
182
+ // We've gone one character past the point where we should stop
183
+ // This means that there was an extra closing `]`
184
+ // We'll clip to just before it
185
+ if (depth < 0) {
186
+ return input.substring(0, match1.index);
187
+ }
188
+ // We've finished balancing the brackets but there still may be characters that can be included
189
+ // For example in the class `text-[#336699]/[.35]`
190
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
191
+ // If we're at zero and encounter a non-class character then we clip the class there
192
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
193
+ return input.substring(0, match1.index);
194
+ }
195
+ }
196
+ return input;
38
197
  } // Regular utilities
39
198
  // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
40
199
  // Arbitrary values
@@ -6,15 +6,15 @@ exports.default = _default;
6
6
  function _default(_context) {
7
7
  return (root, result)=>{
8
8
  let found = false;
9
- root.walkAtRules('tailwind', (node)=>{
9
+ root.walkAtRules("tailwind", (node)=>{
10
10
  if (found) return false;
11
- if (node.parent && node.parent.type !== 'root') {
11
+ if (node.parent && node.parent.type !== "root") {
12
12
  found = true;
13
13
  node.warn(result, [
14
- 'Nested @tailwind rules were detected, but are not supported.',
14
+ "Nested @tailwind rules were detected, but are not supported.",
15
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'));
16
+ "Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy",
17
+ ].join("\n"));
18
18
  return false;
19
19
  }
20
20
  });
@@ -23,10 +23,10 @@ function _default(_context) {
23
23
  rule.walkRules((nestedRule)=>{
24
24
  found = true;
25
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'));
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"));
30
30
  return false;
31
31
  });
32
32
  });