tailwindcss 0.0.0-insiders.f4635e0 → 0.0.0-insiders.f4a2ccd

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 (238) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -7
  3. package/colors.d.ts +3 -0
  4. package/colors.js +2 -304
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultConfig.js +2 -4
  7. package/defaultTheme.d.ts +4 -0
  8. package/defaultTheme.js +2 -4
  9. package/lib/cli/build/deps.js +54 -0
  10. package/lib/cli/build/index.js +52 -0
  11. package/lib/cli/build/plugin.js +376 -0
  12. package/lib/cli/build/utils.js +78 -0
  13. package/lib/cli/build/watching.js +180 -0
  14. package/lib/cli/help/index.js +71 -0
  15. package/lib/cli/index.js +230 -0
  16. package/lib/cli/init/index.js +61 -0
  17. package/lib/cli-peer-dependencies.js +22 -14
  18. package/lib/cli.js +4 -762
  19. package/lib/corePluginList.js +182 -5
  20. package/lib/corePlugins.js +4109 -2952
  21. package/lib/css/preflight.css +24 -9
  22. package/lib/featureFlags.js +68 -50
  23. package/lib/index.js +5 -30
  24. package/lib/lib/cacheInvalidation.js +90 -0
  25. package/lib/lib/collapseAdjacentRules.js +52 -36
  26. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  27. package/lib/lib/content.js +177 -0
  28. package/lib/lib/defaultExtractor.js +241 -0
  29. package/lib/lib/detectNesting.js +39 -17
  30. package/lib/lib/evaluateTailwindFunctions.js +203 -161
  31. package/lib/lib/expandApplyAtRules.js +503 -221
  32. package/lib/lib/expandTailwindAtRules.js +255 -243
  33. package/lib/lib/findAtConfigPath.js +44 -0
  34. package/lib/lib/generateRules.js +831 -317
  35. package/lib/lib/getModuleDependencies.js +93 -49
  36. package/lib/lib/load-config.js +36 -0
  37. package/lib/lib/normalizeTailwindDirectives.js +79 -60
  38. package/lib/lib/offsets.js +304 -0
  39. package/lib/lib/partitionApplyAtRules.js +56 -0
  40. package/lib/lib/regex.js +60 -0
  41. package/lib/lib/remap-bitfield.js +87 -0
  42. package/lib/lib/resolveDefaultsAtRules.js +150 -94
  43. package/lib/lib/setupContextUtils.js +1197 -685
  44. package/lib/lib/setupTrackingContext.js +150 -177
  45. package/lib/lib/sharedState.js +70 -21
  46. package/lib/lib/substituteScreenAtRules.js +26 -28
  47. package/lib/oxide/cli/build/deps.js +81 -0
  48. package/lib/oxide/cli/build/index.js +51 -0
  49. package/lib/oxide/cli/build/plugin.js +373 -0
  50. package/lib/oxide/cli/build/utils.js +77 -0
  51. package/lib/oxide/cli/build/watching.js +177 -0
  52. package/lib/oxide/cli/help/index.js +70 -0
  53. package/lib/oxide/cli/index.js +214 -0
  54. package/lib/oxide/cli/init/index.js +50 -0
  55. package/lib/oxide/cli.js +5 -0
  56. package/lib/oxide/postcss-plugin.js +2 -0
  57. package/lib/plugin.js +98 -0
  58. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  59. package/lib/postcss-plugins/nesting/index.js +19 -0
  60. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  61. package/lib/processTailwindFeatures.js +58 -56
  62. package/lib/public/colors.js +353 -0
  63. package/lib/public/create-plugin.js +15 -0
  64. package/lib/public/default-config.js +16 -0
  65. package/lib/public/default-theme.js +16 -0
  66. package/lib/public/load-config.js +10 -0
  67. package/lib/public/resolve-config.js +22 -0
  68. package/lib/util/applyImportantSelector.js +22 -0
  69. package/lib/util/bigSign.js +7 -6
  70. package/lib/util/buildMediaQuery.js +21 -32
  71. package/lib/util/cloneDeep.js +16 -14
  72. package/lib/util/cloneNodes.js +29 -15
  73. package/lib/util/color.js +104 -66
  74. package/lib/util/configurePlugins.js +17 -15
  75. package/lib/util/createPlugin.js +23 -26
  76. package/lib/util/createUtilityPlugin.js +46 -46
  77. package/lib/util/dataTypes.js +266 -0
  78. package/lib/util/defaults.js +20 -15
  79. package/lib/util/escapeClassName.js +18 -17
  80. package/lib/util/escapeCommas.js +7 -6
  81. package/lib/util/flattenColorPalette.js +13 -12
  82. package/lib/util/formatVariantSelector.js +341 -0
  83. package/lib/util/getAllConfigs.js +44 -18
  84. package/lib/util/hashConfig.js +15 -12
  85. package/lib/util/isKeyframeRule.js +7 -6
  86. package/lib/util/isPlainObject.js +11 -11
  87. package/lib/util/isSyntacticallyValidPropertyValue.js +72 -0
  88. package/lib/util/log.js +52 -33
  89. package/lib/util/nameClass.js +35 -29
  90. package/lib/util/negateValue.js +31 -17
  91. package/lib/util/normalizeConfig.js +294 -0
  92. package/lib/util/normalizeScreens.js +170 -0
  93. package/lib/util/parseAnimationValue.js +85 -54
  94. package/lib/util/parseBoxShadowValue.js +84 -0
  95. package/lib/util/parseDependency.js +41 -70
  96. package/lib/util/parseGlob.js +34 -0
  97. package/lib/util/parseObjectStyles.js +30 -24
  98. package/lib/util/pluginUtils.js +234 -288
  99. package/lib/util/prefixSelector.js +33 -19
  100. package/lib/util/removeAlphaVariables.js +29 -0
  101. package/lib/util/resolveConfig.js +221 -256
  102. package/lib/util/resolveConfigPath.js +55 -48
  103. package/lib/util/responsive.js +18 -14
  104. package/lib/util/splitAtTopLevelOnly.js +49 -0
  105. package/lib/util/tap.js +8 -7
  106. package/lib/util/toColorValue.js +7 -6
  107. package/lib/util/toPath.js +27 -8
  108. package/lib/util/transformThemeValue.js +67 -28
  109. package/lib/util/validateConfig.js +24 -0
  110. package/lib/util/validateFormalSyntax.js +24 -0
  111. package/lib/util/withAlphaVariable.js +67 -57
  112. package/loadConfig.d.ts +4 -0
  113. package/loadConfig.js +2 -0
  114. package/nesting/index.js +2 -12
  115. package/package.json +69 -66
  116. package/peers/index.js +76328 -84169
  117. package/plugin.d.ts +11 -0
  118. package/plugin.js +1 -2
  119. package/resolveConfig.d.ts +12 -0
  120. package/resolveConfig.js +2 -7
  121. package/scripts/create-plugin-list.js +2 -2
  122. package/scripts/generate-types.js +105 -0
  123. package/scripts/release-channel.js +18 -0
  124. package/scripts/release-notes.js +21 -0
  125. package/scripts/swap-engines.js +40 -0
  126. package/scripts/type-utils.js +27 -0
  127. package/src/cli/build/deps.js +56 -0
  128. package/src/cli/build/index.js +49 -0
  129. package/src/cli/build/plugin.js +444 -0
  130. package/src/cli/build/utils.js +76 -0
  131. package/src/cli/build/watching.js +229 -0
  132. package/src/cli/help/index.js +70 -0
  133. package/src/cli/index.js +216 -0
  134. package/src/cli/init/index.js +79 -0
  135. package/src/cli-peer-dependencies.js +7 -1
  136. package/src/cli.js +4 -756
  137. package/src/corePluginList.js +1 -1
  138. package/src/corePlugins.js +2526 -1956
  139. package/src/css/preflight.css +24 -9
  140. package/src/featureFlags.js +33 -10
  141. package/src/index.js +4 -33
  142. package/src/lib/cacheInvalidation.js +52 -0
  143. package/src/lib/collapseAdjacentRules.js +21 -2
  144. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  145. package/src/lib/content.js +208 -0
  146. package/src/lib/defaultExtractor.js +217 -0
  147. package/src/lib/detectNesting.js +30 -3
  148. package/src/lib/evaluateTailwindFunctions.js +84 -10
  149. package/src/lib/expandApplyAtRules.js +509 -153
  150. package/src/lib/expandTailwindAtRules.js +125 -104
  151. package/src/lib/findAtConfigPath.js +48 -0
  152. package/src/lib/generateRules.js +678 -70
  153. package/src/lib/getModuleDependencies.js +70 -30
  154. package/src/lib/load-config.ts +27 -0
  155. package/src/lib/normalizeTailwindDirectives.js +10 -3
  156. package/src/lib/offsets.js +373 -0
  157. package/src/lib/partitionApplyAtRules.js +52 -0
  158. package/src/lib/regex.js +74 -0
  159. package/src/lib/remap-bitfield.js +82 -0
  160. package/src/lib/resolveDefaultsAtRules.js +105 -47
  161. package/src/lib/setupContextUtils.js +848 -247
  162. package/src/lib/setupTrackingContext.js +53 -64
  163. package/src/lib/sharedState.js +60 -6
  164. package/src/lib/substituteScreenAtRules.js +6 -3
  165. package/src/oxide/cli/build/deps.ts +91 -0
  166. package/src/oxide/cli/build/index.ts +47 -0
  167. package/src/oxide/cli/build/plugin.ts +442 -0
  168. package/src/oxide/cli/build/utils.ts +74 -0
  169. package/src/oxide/cli/build/watching.ts +225 -0
  170. package/src/oxide/cli/help/index.ts +69 -0
  171. package/src/oxide/cli/index.ts +204 -0
  172. package/src/oxide/cli/init/index.ts +59 -0
  173. package/src/oxide/cli.ts +1 -0
  174. package/src/oxide/postcss-plugin.ts +1 -0
  175. package/src/plugin.js +107 -0
  176. package/src/postcss-plugins/nesting/README.md +42 -0
  177. package/src/postcss-plugins/nesting/index.js +13 -0
  178. package/src/postcss-plugins/nesting/plugin.js +80 -0
  179. package/src/processTailwindFeatures.js +18 -3
  180. package/src/public/colors.js +322 -0
  181. package/src/public/create-plugin.js +2 -0
  182. package/src/public/default-config.js +4 -0
  183. package/src/public/default-theme.js +4 -0
  184. package/src/public/load-config.js +2 -0
  185. package/src/public/resolve-config.js +7 -0
  186. package/src/util/applyImportantSelector.js +19 -0
  187. package/src/util/buildMediaQuery.js +14 -16
  188. package/src/util/cloneNodes.js +19 -2
  189. package/src/util/color.js +43 -11
  190. package/src/util/createUtilityPlugin.js +2 -11
  191. package/src/util/dataTypes.js +281 -0
  192. package/src/util/defaults.js +6 -0
  193. package/src/util/formatVariantSelector.js +412 -0
  194. package/src/util/getAllConfigs.js +21 -2
  195. package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
  196. package/src/util/log.js +23 -22
  197. package/src/util/nameClass.js +6 -2
  198. package/src/util/negateValue.js +15 -5
  199. package/src/util/normalizeConfig.js +318 -0
  200. package/src/util/normalizeScreens.js +140 -0
  201. package/src/util/parseAnimationValue.js +7 -1
  202. package/src/util/parseBoxShadowValue.js +72 -0
  203. package/src/util/parseDependency.js +37 -38
  204. package/src/util/parseGlob.js +24 -0
  205. package/src/util/pluginUtils.js +219 -219
  206. package/src/util/prefixSelector.js +30 -13
  207. package/src/util/removeAlphaVariables.js +24 -0
  208. package/src/util/resolveConfig.js +86 -91
  209. package/src/util/resolveConfigPath.js +12 -1
  210. package/src/util/splitAtTopLevelOnly.js +52 -0
  211. package/src/util/toPath.js +23 -1
  212. package/src/util/transformThemeValue.js +33 -8
  213. package/src/util/validateConfig.js +13 -0
  214. package/src/util/validateFormalSyntax.js +34 -0
  215. package/src/util/withAlphaVariable.js +14 -9
  216. package/stubs/.gitignore +1 -0
  217. package/stubs/.prettierrc.json +6 -0
  218. package/stubs/{defaultConfig.stub.js → config.full.js} +332 -249
  219. package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -1
  220. package/stubs/postcss.config.js +6 -0
  221. package/stubs/tailwind.config.cjs +2 -0
  222. package/stubs/tailwind.config.js +2 -0
  223. package/stubs/tailwind.config.ts +3 -0
  224. package/types/config.d.ts +373 -0
  225. package/types/generated/.gitkeep +0 -0
  226. package/types/generated/colors.d.ts +298 -0
  227. package/types/generated/corePluginList.d.ts +1 -0
  228. package/types/generated/default-theme.d.ts +347 -0
  229. package/types/index.d.ts +7 -0
  230. package/CHANGELOG.md +0 -1742
  231. package/lib/constants.js +0 -37
  232. package/lib/lib/setupWatchingContext.js +0 -331
  233. package/nesting/plugin.js +0 -41
  234. package/scripts/install-integrations.js +0 -27
  235. package/scripts/rebuildFixtures.js +0 -68
  236. package/src/constants.js +0 -17
  237. package/src/lib/setupWatchingContext.js +0 -307
  238. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
@@ -1,116 +1,187 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.resolveMatches = resolveMatches;
7
- exports.generateRules = generateRules;
8
-
9
- var _postcss = _interopRequireDefault(require("postcss"));
10
-
11
- var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
12
-
13
- var _parseObjectStyles = _interopRequireDefault(require("../util/parseObjectStyles"));
14
-
15
- var _isPlainObject = _interopRequireDefault(require("../util/isPlainObject"));
16
-
17
- var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
18
-
19
- var _pluginUtils = require("../util/pluginUtils");
20
-
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
23
- let classNameParser = (0, _postcssSelectorParser.default)(selectors => {
24
- return selectors.first.filter(({
25
- type
26
- }) => type === 'class').pop().value;
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
+ getClassNameFromSelector: ()=>getClassNameFromSelector,
13
+ resolveMatches: ()=>resolveMatches,
14
+ generateRules: ()=>generateRules
15
+ });
16
+ const _postcss = /*#__PURE__*/ _interopRequireDefault(require("postcss"));
17
+ const _postcssSelectorParser = /*#__PURE__*/ _interopRequireDefault(require("postcss-selector-parser"));
18
+ const _parseObjectStyles = /*#__PURE__*/ _interopRequireDefault(require("../util/parseObjectStyles"));
19
+ const _isPlainObject = /*#__PURE__*/ _interopRequireDefault(require("../util/isPlainObject"));
20
+ const _prefixSelector = /*#__PURE__*/ _interopRequireDefault(require("../util/prefixSelector"));
21
+ const _pluginUtils = require("../util/pluginUtils");
22
+ const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
23
+ const _sharedState = /*#__PURE__*/ _interopRequireWildcard(require("./sharedState"));
24
+ const _formatVariantSelector = require("../util/formatVariantSelector");
25
+ const _nameClass = require("../util/nameClass");
26
+ const _dataTypes = require("../util/dataTypes");
27
+ const _setupContextUtils = require("./setupContextUtils");
28
+ const _isSyntacticallyValidPropertyValue = /*#__PURE__*/ _interopRequireDefault(require("../util/isSyntacticallyValidPropertyValue"));
29
+ const _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
30
+ const _featureFlags = require("../featureFlags");
31
+ const _applyImportantSelector = require("../util/applyImportantSelector");
32
+ function _interopRequireDefault(obj) {
33
+ return obj && obj.__esModule ? obj : {
34
+ default: obj
35
+ };
36
+ }
37
+ function _getRequireWildcardCache(nodeInterop) {
38
+ if (typeof WeakMap !== "function") return null;
39
+ var cacheBabelInterop = new WeakMap();
40
+ var cacheNodeInterop = new WeakMap();
41
+ return (_getRequireWildcardCache = function(nodeInterop) {
42
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
43
+ })(nodeInterop);
44
+ }
45
+ function _interopRequireWildcard(obj, nodeInterop) {
46
+ if (!nodeInterop && obj && obj.__esModule) {
47
+ return obj;
48
+ }
49
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
50
+ return {
51
+ default: obj
52
+ };
53
+ }
54
+ var cache = _getRequireWildcardCache(nodeInterop);
55
+ if (cache && cache.has(obj)) {
56
+ return cache.get(obj);
57
+ }
58
+ var newObj = {};
59
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
60
+ for(var key in obj){
61
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
62
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
63
+ if (desc && (desc.get || desc.set)) {
64
+ Object.defineProperty(newObj, key, desc);
65
+ } else {
66
+ newObj[key] = obj[key];
67
+ }
68
+ }
69
+ }
70
+ newObj.default = obj;
71
+ if (cache) {
72
+ cache.set(obj, newObj);
73
+ }
74
+ return newObj;
75
+ }
76
+ let classNameParser = (0, _postcssSelectorParser.default)((selectors)=>{
77
+ return selectors.first.filter(({ type })=>type === "class").pop().value;
27
78
  });
28
-
29
79
  function getClassNameFromSelector(selector) {
30
- return classNameParser.transformSync(selector);
31
- } // Generate match permutations for a class candidate, like:
80
+ return classNameParser.transformSync(selector);
81
+ }
82
+ // Generate match permutations for a class candidate, like:
32
83
  // ['ring-offset-blue', '100']
33
84
  // ['ring-offset', 'blue-100']
34
85
  // ['ring', 'offset-blue-100']
35
86
  // Example with dynamic classes:
36
87
  // ['grid-cols', '[[linename],1fr,auto]']
37
88
  // ['grid', 'cols-[[linename],1fr,auto]']
38
-
39
-
40
- function* candidatePermutations(candidate, lastIndex = Infinity) {
41
- if (lastIndex < 0) {
42
- return;
43
- }
44
-
45
- let dashIdx;
46
-
47
- if (lastIndex === Infinity && candidate.endsWith(']')) {
48
- let bracketIdx = candidate.indexOf('['); // If character before `[` isn't a dash or a slash, this isn't a dynamic class
49
- // eg. string[]
50
-
51
- dashIdx = ['-', '/'].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
52
- } else {
53
- dashIdx = candidate.lastIndexOf('-', lastIndex);
54
- }
55
-
56
- if (dashIdx < 0) {
57
- return;
58
- }
59
-
60
- let prefix = candidate.slice(0, dashIdx);
61
- let modifier = candidate.slice(dashIdx + 1);
62
- yield [prefix, modifier];
63
- yield* candidatePermutations(candidate, dashIdx - 1);
89
+ function* candidatePermutations(candidate) {
90
+ let lastIndex = Infinity;
91
+ while(lastIndex >= 0){
92
+ let dashIdx;
93
+ let wasSlash = false;
94
+ if (lastIndex === Infinity && candidate.endsWith("]")) {
95
+ let bracketIdx = candidate.indexOf("[");
96
+ // If character before `[` isn't a dash or a slash, this isn't a dynamic class
97
+ // eg. string[]
98
+ if (candidate[bracketIdx - 1] === "-") {
99
+ dashIdx = bracketIdx - 1;
100
+ } else if (candidate[bracketIdx - 1] === "/") {
101
+ dashIdx = bracketIdx - 1;
102
+ wasSlash = true;
103
+ } else {
104
+ dashIdx = -1;
105
+ }
106
+ } else if (lastIndex === Infinity && candidate.includes("/")) {
107
+ dashIdx = candidate.lastIndexOf("/");
108
+ wasSlash = true;
109
+ } else {
110
+ dashIdx = candidate.lastIndexOf("-", lastIndex);
111
+ }
112
+ if (dashIdx < 0) {
113
+ break;
114
+ }
115
+ let prefix = candidate.slice(0, dashIdx);
116
+ let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1);
117
+ lastIndex = dashIdx - 1;
118
+ // TODO: This feels a bit hacky
119
+ if (prefix === "" || modifier === "/") {
120
+ continue;
121
+ }
122
+ yield [
123
+ prefix,
124
+ modifier
125
+ ];
126
+ }
64
127
  }
65
-
66
128
  function applyPrefix(matches, context) {
67
- if (matches.length === 0 || context.tailwindConfig.prefix === '') {
129
+ if (matches.length === 0 || context.tailwindConfig.prefix === "") {
130
+ return matches;
131
+ }
132
+ for (let match of matches){
133
+ let [meta] = match;
134
+ if (meta.options.respectPrefix) {
135
+ let container = _postcss.default.root({
136
+ nodes: [
137
+ match[1].clone()
138
+ ]
139
+ });
140
+ let classCandidate = match[1].raws.tailwind.classCandidate;
141
+ container.walkRules((r)=>{
142
+ // If this is a negative utility with a dash *before* the prefix we
143
+ // have to ensure that the generated selector matches the candidate
144
+ // Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
145
+ // The disconnect between candidate <-> class can cause @apply to hard crash.
146
+ let shouldPrependNegative = classCandidate.startsWith("-");
147
+ r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
148
+ });
149
+ match[1] = container.nodes[0];
150
+ }
151
+ }
68
152
  return matches;
69
- }
70
-
71
- for (let match of matches) {
72
- let [meta] = match;
73
-
74
- if (meta.options.respectPrefix) {
75
- let container = _postcss.default.root({
76
- nodes: [match[1].clone()]
77
- });
78
-
79
- container.walkRules(r => {
80
- r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector);
81
- });
82
- match[1] = container.nodes[0];
83
- }
84
- }
85
-
86
- return matches;
87
153
  }
88
-
89
- function applyImportant(matches) {
90
- if (matches.length === 0) {
91
- return matches;
92
- }
93
-
94
- let result = [];
95
-
96
- for (let [meta, rule] of matches) {
97
- let container = _postcss.default.root({
98
- nodes: [rule.clone()]
99
- });
100
-
101
- container.walkRules(r => {
102
- r.selector = (0, _pluginUtils.updateAllClasses)(r.selector, className => {
103
- return `!${className}`;
104
- });
105
- r.walkDecls(d => d.important = true);
106
- });
107
- result.push([{ ...meta,
108
- important: true
109
- }, container.nodes[0]]);
110
- }
111
-
112
- return result;
113
- } // Takes a list of rule tuples and applies a variant like `hover`, sm`,
154
+ function applyImportant(matches, classCandidate) {
155
+ if (matches.length === 0) {
156
+ return matches;
157
+ }
158
+ let result = [];
159
+ for (let [meta, rule] of matches){
160
+ let container = _postcss.default.root({
161
+ nodes: [
162
+ rule.clone()
163
+ ]
164
+ });
165
+ container.walkRules((r)=>{
166
+ let ast = (0, _postcssSelectorParser.default)().astSync(r.selector);
167
+ // Remove extraneous selectors that do not include the base candidate
168
+ ast.each((sel)=>(0, _formatVariantSelector.eliminateIrrelevantSelectors)(sel, classCandidate));
169
+ // Update all instances of the base candidate to include the important marker
170
+ (0, _pluginUtils.updateAllClasses)(ast, (className)=>className === classCandidate ? `!${className}` : className);
171
+ r.selector = ast.toString();
172
+ r.walkDecls((d)=>d.important = true);
173
+ });
174
+ result.push([
175
+ {
176
+ ...meta,
177
+ important: true
178
+ },
179
+ container.nodes[0]
180
+ ]);
181
+ }
182
+ return result;
183
+ }
184
+ // Takes a list of rule tuples and applies a variant like `hover`, sm`,
114
185
  // whatever to it. We used to do some extra caching here to avoid generating
115
186
  // a variant of the same rule more than once, but this was never hit because
116
187
  // we cache at the entire selector level further up the tree.
@@ -118,245 +189,688 @@ function applyImportant(matches) {
118
189
  // Technically you can get a cache hit if you have `hover:focus:text-center`
119
190
  // and `focus:hover:text-center` in the same project, but it doesn't feel
120
191
  // worth the complexity for that case.
121
-
122
-
123
192
  function applyVariant(variant, matches, context) {
124
- if (matches.length === 0) {
125
- return matches;
126
- }
127
-
128
- if (context.variantMap.has(variant)) {
129
- let variantFunctionTuples = context.variantMap.get(variant);
130
- let result = [];
131
-
132
- for (let [meta, rule] of matches) {
133
- if (meta.options.respectVariants === false) {
134
- result.push([meta, rule]);
135
- continue;
136
- }
137
-
138
- let container = _postcss.default.root({
139
- nodes: [rule.clone()]
140
- });
141
-
142
- for (let [variantSort, variantFunction] of variantFunctionTuples) {
143
- let clone = container.clone();
144
-
145
- function modifySelectors(modifierFunction) {
146
- clone.each(rule => {
147
- if (rule.type !== 'rule') {
148
- return;
193
+ if (matches.length === 0) {
194
+ return matches;
195
+ }
196
+ /** @type {{modifier: string | null, value: string | null}} */ let args = {
197
+ modifier: null,
198
+ value: _sharedState.NONE
199
+ };
200
+ // Retrieve "modifier"
201
+ {
202
+ let [baseVariant, ...modifiers] = (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(variant, "/");
203
+ // This is a hack to support variants with `/` in them, like `ar-1/10/20:text-red-500`
204
+ // In this case 1/10 is a value but /20 is a modifier
205
+ if (modifiers.length > 1) {
206
+ baseVariant = baseVariant + "/" + modifiers.slice(0, -1).join("/");
207
+ modifiers = modifiers.slice(-1);
208
+ }
209
+ if (modifiers.length && !context.variantMap.has(variant)) {
210
+ variant = baseVariant;
211
+ args.modifier = modifiers[0];
212
+ if (!(0, _featureFlags.flagEnabled)(context.tailwindConfig, "generalizedModifiers")) {
213
+ return [];
149
214
  }
150
-
151
- rule.selectors = rule.selectors.map(selector => {
152
- return modifierFunction({
153
- get className() {
154
- return getClassNameFromSelector(selector);
155
- },
156
-
157
- selector
158
- });
159
- });
160
- });
161
- return clone;
162
215
  }
163
-
164
- let ruleWithVariant = variantFunction({
165
- container: clone,
166
- separator: context.tailwindConfig.separator,
167
- modifySelectors
168
- });
169
-
170
- if (ruleWithVariant === null) {
171
- continue;
216
+ }
217
+ // Retrieve "arbitrary value"
218
+ if (variant.endsWith("]") && !variant.startsWith("[")) {
219
+ // We either have:
220
+ // @[200px]
221
+ // group-[:hover]
222
+ //
223
+ // But we don't want:
224
+ // @-[200px] (`-` is incorrect)
225
+ // group[:hover] (`-` is missing)
226
+ let match = /(.)(-?)\[(.*)\]/g.exec(variant);
227
+ if (match) {
228
+ let [, char, seperator, value] = match;
229
+ // @-[200px] case
230
+ if (char === "@" && seperator === "-") return [];
231
+ // group[:hover] case
232
+ if (char !== "@" && seperator === "") return [];
233
+ variant = variant.replace(`${seperator}[${value}]`, "");
234
+ args.value = value;
172
235
  }
173
-
174
- let withOffset = [{ ...meta,
175
- sort: variantSort | meta.sort
176
- }, clone.nodes[0]];
177
- result.push(withOffset);
178
- }
179
- }
180
-
181
- return result;
182
- }
183
-
184
- return [];
236
+ }
237
+ // Register arbitrary variants
238
+ if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
239
+ let sort = context.offsets.recordVariant(variant);
240
+ let selector = (0, _dataTypes.normalize)(variant.slice(1, -1));
241
+ let selectors = (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(selector, ",");
242
+ // We do not support multiple selectors for arbitrary variants
243
+ if (selectors.length > 1) {
244
+ return [];
245
+ }
246
+ if (!selectors.every(_setupContextUtils.isValidVariantFormatString)) {
247
+ return [];
248
+ }
249
+ let records = selectors.map((sel, idx)=>[
250
+ context.offsets.applyParallelOffset(sort, idx),
251
+ (0, _setupContextUtils.parseVariant)(sel.trim())
252
+ ]);
253
+ context.variantMap.set(variant, records);
254
+ }
255
+ if (context.variantMap.has(variant)) {
256
+ let isArbitraryVariant = isArbitraryValue(variant);
257
+ let variantFunctionTuples = context.variantMap.get(variant).slice();
258
+ let result = [];
259
+ for (let [meta, rule] of matches){
260
+ // Don't generate variants for user css
261
+ if (meta.layer === "user") {
262
+ continue;
263
+ }
264
+ let container = _postcss.default.root({
265
+ nodes: [
266
+ rule.clone()
267
+ ]
268
+ });
269
+ for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples){
270
+ let clone = (containerFromArray !== null && containerFromArray !== void 0 ? containerFromArray : container).clone();
271
+ let collectedFormats = [];
272
+ function prepareBackup() {
273
+ // Already prepared, chicken out
274
+ if (clone.raws.neededBackup) {
275
+ return;
276
+ }
277
+ clone.raws.neededBackup = true;
278
+ clone.walkRules((rule)=>rule.raws.originalSelector = rule.selector);
279
+ }
280
+ function modifySelectors(modifierFunction) {
281
+ prepareBackup();
282
+ clone.each((rule)=>{
283
+ if (rule.type !== "rule") {
284
+ return;
285
+ }
286
+ rule.selectors = rule.selectors.map((selector)=>{
287
+ return modifierFunction({
288
+ get className () {
289
+ return getClassNameFromSelector(selector);
290
+ },
291
+ selector
292
+ });
293
+ });
294
+ });
295
+ return clone;
296
+ }
297
+ let ruleWithVariant = variantFunction({
298
+ // Public API
299
+ get container () {
300
+ prepareBackup();
301
+ return clone;
302
+ },
303
+ separator: context.tailwindConfig.separator,
304
+ modifySelectors,
305
+ // Private API for now
306
+ wrap (wrapper) {
307
+ let nodes = clone.nodes;
308
+ clone.removeAll();
309
+ wrapper.append(nodes);
310
+ clone.append(wrapper);
311
+ },
312
+ format (selectorFormat) {
313
+ collectedFormats.push({
314
+ format: selectorFormat,
315
+ isArbitraryVariant
316
+ });
317
+ },
318
+ args
319
+ });
320
+ // It can happen that a list of format strings is returned from within the function. In that
321
+ // case, we have to process them as well. We can use the existing `variantSort`.
322
+ if (Array.isArray(ruleWithVariant)) {
323
+ for (let [idx, variantFunction1] of ruleWithVariant.entries()){
324
+ // This is a little bit scary since we are pushing to an array of items that we are
325
+ // currently looping over. However, you can also think of it like a processing queue
326
+ // where you keep handling jobs until everything is done and each job can queue more
327
+ // jobs if needed.
328
+ variantFunctionTuples.push([
329
+ context.offsets.applyParallelOffset(variantSort, idx),
330
+ variantFunction1,
331
+ // If the clone has been modified we have to pass that back
332
+ // though so each rule can use the modified container
333
+ clone.clone()
334
+ ]);
335
+ }
336
+ continue;
337
+ }
338
+ if (typeof ruleWithVariant === "string") {
339
+ collectedFormats.push({
340
+ format: ruleWithVariant,
341
+ isArbitraryVariant
342
+ });
343
+ }
344
+ if (ruleWithVariant === null) {
345
+ continue;
346
+ }
347
+ // We had to backup selectors, therefore we assume that somebody touched
348
+ // `container` or `modifySelectors`. Let's see if they did, so that we
349
+ // can restore the selectors, and collect the format strings.
350
+ if (clone.raws.neededBackup) {
351
+ delete clone.raws.neededBackup;
352
+ clone.walkRules((rule)=>{
353
+ let before = rule.raws.originalSelector;
354
+ if (!before) return;
355
+ delete rule.raws.originalSelector;
356
+ if (before === rule.selector) return; // No mutation happened
357
+ let modified = rule.selector;
358
+ // Rebuild the base selector, this is what plugin authors would do
359
+ // as well. E.g.: `${variant}${separator}${className}`.
360
+ // However, plugin authors probably also prepend or append certain
361
+ // classes, pseudos, ids, ...
362
+ let rebuiltBase = (0, _postcssSelectorParser.default)((selectors)=>{
363
+ selectors.walkClasses((classNode)=>{
364
+ classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
365
+ });
366
+ }).processSync(before);
367
+ // Now that we know the original selector, the new selector, and
368
+ // the rebuild part in between, we can replace the part that plugin
369
+ // authors need to rebuild with `&`, and eventually store it in the
370
+ // collectedFormats. Similar to what `format('...')` would do.
371
+ //
372
+ // E.g.:
373
+ // variant: foo
374
+ // selector: .markdown > p
375
+ // modified (by plugin): .foo .foo\\:markdown > p
376
+ // rebuiltBase (internal): .foo\\:markdown > p
377
+ // format: .foo &
378
+ collectedFormats.push({
379
+ format: modified.replace(rebuiltBase, "&"),
380
+ isArbitraryVariant
381
+ });
382
+ rule.selector = before;
383
+ });
384
+ }
385
+ // This tracks the originating layer for the variant
386
+ // For example:
387
+ // .sm:underline {} is a variant of something in the utilities layer
388
+ // .sm:container {} is a variant of the container component
389
+ clone.nodes[0].raws.tailwind = {
390
+ ...clone.nodes[0].raws.tailwind,
391
+ parentLayer: meta.layer
392
+ };
393
+ var _meta_collectedFormats;
394
+ let withOffset = [
395
+ {
396
+ ...meta,
397
+ sort: context.offsets.applyVariantOffset(meta.sort, variantSort, Object.assign(args, context.variantOptions.get(variant))),
398
+ collectedFormats: ((_meta_collectedFormats = meta.collectedFormats) !== null && _meta_collectedFormats !== void 0 ? _meta_collectedFormats : []).concat(collectedFormats)
399
+ },
400
+ clone.nodes[0]
401
+ ];
402
+ result.push(withOffset);
403
+ }
404
+ }
405
+ return result;
406
+ }
407
+ return [];
185
408
  }
186
-
187
409
  function parseRules(rule, cache, options = {}) {
188
- // PostCSS node
189
- if (!(0, _isPlainObject.default)(rule) && !Array.isArray(rule)) {
190
- return [[rule], options];
191
- } // Tuple
192
-
193
-
194
- if (Array.isArray(rule)) {
195
- return parseRules(rule[0], cache, rule[1]);
196
- } // Simple object
197
-
198
-
199
- if (!cache.has(rule)) {
200
- cache.set(rule, (0, _parseObjectStyles.default)(rule));
201
- }
202
-
203
- return [cache.get(rule), options];
410
+ // PostCSS node
411
+ if (!(0, _isPlainObject.default)(rule) && !Array.isArray(rule)) {
412
+ return [
413
+ [
414
+ rule
415
+ ],
416
+ options
417
+ ];
418
+ }
419
+ // Tuple
420
+ if (Array.isArray(rule)) {
421
+ return parseRules(rule[0], cache, rule[1]);
422
+ }
423
+ // Simple object
424
+ if (!cache.has(rule)) {
425
+ cache.set(rule, (0, _parseObjectStyles.default)(rule));
426
+ }
427
+ return [
428
+ cache.get(rule),
429
+ options
430
+ ];
431
+ }
432
+ const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
433
+ function isValidPropName(name) {
434
+ return IS_VALID_PROPERTY_NAME.test(name);
435
+ }
436
+ /**
437
+ * @param {string} declaration
438
+ * @returns {boolean}
439
+ */ function looksLikeUri(declaration) {
440
+ // Quick bailout for obvious non-urls
441
+ // This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
442
+ if (!declaration.includes("://")) {
443
+ return false;
444
+ }
445
+ try {
446
+ const url = new URL(declaration);
447
+ return url.scheme !== "" && url.host !== "";
448
+ } catch (err) {
449
+ // Definitely not a valid url
450
+ return false;
451
+ }
452
+ }
453
+ function isParsableNode(node) {
454
+ let isParsable = true;
455
+ node.walkDecls((decl)=>{
456
+ if (!isParsableCssValue(decl.prop, decl.value)) {
457
+ isParsable = false;
458
+ return false;
459
+ }
460
+ });
461
+ return isParsable;
462
+ }
463
+ function isParsableCssValue(property, value) {
464
+ // We don't want to to treat [https://example.com] as a custom property
465
+ // Even though, according to the CSS grammar, it's a totally valid CSS declaration
466
+ // So we short-circuit here by checking if the custom property looks like a url
467
+ if (looksLikeUri(`${property}:${value}`)) {
468
+ return false;
469
+ }
470
+ try {
471
+ _postcss.default.parse(`a{${property}:${value}}`).toResult();
472
+ return true;
473
+ } catch (err) {
474
+ return false;
475
+ }
476
+ }
477
+ function extractArbitraryProperty(classCandidate, context) {
478
+ var _classCandidate_match;
479
+ let [, property, value] = (_classCandidate_match = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && _classCandidate_match !== void 0 ? _classCandidate_match : [];
480
+ if (value === undefined) {
481
+ return null;
482
+ }
483
+ if (!isValidPropName(property)) {
484
+ return null;
485
+ }
486
+ if (!(0, _isSyntacticallyValidPropertyValue.default)(value)) {
487
+ return null;
488
+ }
489
+ let normalized = (0, _dataTypes.normalize)(value);
490
+ if (!isParsableCssValue(property, normalized)) {
491
+ return null;
492
+ }
493
+ let sort = context.offsets.arbitraryProperty();
494
+ return [
495
+ [
496
+ {
497
+ sort,
498
+ layer: "utilities"
499
+ },
500
+ ()=>({
501
+ [(0, _nameClass.asClass)(classCandidate)]: {
502
+ [property]: normalized
503
+ }
504
+ })
505
+ ]
506
+ ];
204
507
  }
205
-
206
508
  function* resolveMatchedPlugins(classCandidate, context) {
207
- if (context.candidateRuleMap.has(classCandidate)) {
208
- yield [context.candidateRuleMap.get(classCandidate), 'DEFAULT'];
209
- }
210
-
211
- let candidatePrefix = classCandidate;
212
- let negative = false;
213
- const twConfigPrefix = context.tailwindConfig.prefix || '';
214
- const twConfigPrefixLen = twConfigPrefix.length;
215
-
216
- if (candidatePrefix[twConfigPrefixLen] === '-') {
217
- negative = true;
218
- candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
219
- }
220
-
221
- for (let [prefix, modifier] of candidatePermutations(candidatePrefix)) {
222
- if (context.candidateRuleMap.has(prefix)) {
223
- yield [context.candidateRuleMap.get(prefix), negative ? `-${modifier}` : modifier];
224
- return;
225
- }
226
- }
509
+ if (context.candidateRuleMap.has(classCandidate)) {
510
+ yield [
511
+ context.candidateRuleMap.get(classCandidate),
512
+ "DEFAULT"
513
+ ];
514
+ }
515
+ yield* function*(arbitraryPropertyRule) {
516
+ if (arbitraryPropertyRule !== null) {
517
+ yield [
518
+ arbitraryPropertyRule,
519
+ "DEFAULT"
520
+ ];
521
+ }
522
+ }(extractArbitraryProperty(classCandidate, context));
523
+ let candidatePrefix = classCandidate;
524
+ let negative = false;
525
+ const twConfigPrefix = context.tailwindConfig.prefix;
526
+ const twConfigPrefixLen = twConfigPrefix.length;
527
+ const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
528
+ if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
529
+ negative = true;
530
+ candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
531
+ }
532
+ if (negative && context.candidateRuleMap.has(candidatePrefix)) {
533
+ yield [
534
+ context.candidateRuleMap.get(candidatePrefix),
535
+ "-DEFAULT"
536
+ ];
537
+ }
538
+ for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
539
+ if (context.candidateRuleMap.has(prefix)) {
540
+ yield [
541
+ context.candidateRuleMap.get(prefix),
542
+ negative ? `-${modifier}` : modifier
543
+ ];
544
+ }
545
+ }
227
546
  }
228
-
229
547
  function splitWithSeparator(input, separator) {
230
- return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'));
548
+ if (input === _sharedState.NOT_ON_DEMAND) {
549
+ return [
550
+ _sharedState.NOT_ON_DEMAND
551
+ ];
552
+ }
553
+ return (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(input, separator);
554
+ }
555
+ function* recordCandidates(matches, classCandidate) {
556
+ for (const match of matches){
557
+ var _match__options;
558
+ var _match__options_preserveSource;
559
+ match[1].raws.tailwind = {
560
+ ...match[1].raws.tailwind,
561
+ classCandidate,
562
+ preserveSource: (_match__options_preserveSource = (_match__options = match[0].options) === null || _match__options === void 0 ? void 0 : _match__options.preserveSource) !== null && _match__options_preserveSource !== void 0 ? _match__options_preserveSource : false
563
+ };
564
+ yield match;
565
+ }
231
566
  }
232
-
233
- function* resolveMatches(candidate, context) {
234
- let separator = context.tailwindConfig.separator;
235
- let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
236
- let important = false;
237
-
238
- if (classCandidate.startsWith('!')) {
239
- important = true;
240
- classCandidate = classCandidate.slice(1);
241
- } // TODO: Reintroduce this in ways that doesn't break on false positives
242
- // function sortAgainst(toSort, against) {
243
- // return toSort.slice().sort((a, z) => {
244
- // return bigSign(against.get(a)[0] - against.get(z)[0])
245
- // })
246
- // }
247
- // let sorted = sortAgainst(variants, context.variantMap)
248
- // if (sorted.toString() !== variants.toString()) {
249
- // let corrected = sorted.reverse().concat(classCandidate).join(':')
250
- // throw new Error(`Class ${candidate} should be written as ${corrected}`)
251
- // }
252
-
253
-
254
- for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)) {
255
- let matches = [];
256
- let [plugins, modifier] = matchedPlugins;
257
-
258
- for (let [sort, plugin] of plugins) {
259
- if (typeof plugin === 'function') {
260
- for (let ruleSet of [].concat(plugin(modifier))) {
261
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
262
-
263
- for (let rule of rules) {
264
- matches.push([{ ...sort,
265
- options: { ...sort.options,
266
- ...options
267
- }
268
- }, rule]);
269
- }
567
+ function* resolveMatches(candidate, context, original = candidate) {
568
+ let separator = context.tailwindConfig.separator;
569
+ let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
570
+ let important = false;
571
+ if (classCandidate.startsWith("!")) {
572
+ important = true;
573
+ classCandidate = classCandidate.slice(1);
574
+ }
575
+ if ((0, _featureFlags.flagEnabled)(context.tailwindConfig, "variantGrouping")) {
576
+ if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
577
+ let base = variants.slice().reverse().join(separator);
578
+ for (let part of (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(classCandidate.slice(1, -1), ",")){
579
+ yield* resolveMatches(base + separator + part, context, original);
580
+ }
270
581
  }
271
- } // Only process static plugins on exact matches
272
- else if (modifier === 'DEFAULT') {
273
- let ruleSet = plugin;
274
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
275
-
276
- for (let rule of rules) {
277
- matches.push([{ ...sort,
278
- options: { ...sort.options,
279
- ...options
582
+ }
583
+ // TODO: Reintroduce this in ways that doesn't break on false positives
584
+ // function sortAgainst(toSort, against) {
585
+ // return toSort.slice().sort((a, z) => {
586
+ // return bigSign(against.get(a)[0] - against.get(z)[0])
587
+ // })
588
+ // }
589
+ // let sorted = sortAgainst(variants, context.variantMap)
590
+ // if (sorted.toString() !== variants.toString()) {
591
+ // let corrected = sorted.reverse().concat(classCandidate).join(':')
592
+ // throw new Error(`Class ${candidate} should be written as ${corrected}`)
593
+ // }
594
+ for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)){
595
+ let matches = [];
596
+ let typesByMatches = new Map();
597
+ let [plugins, modifier] = matchedPlugins;
598
+ let isOnlyPlugin = plugins.length === 1;
599
+ for (let [sort, plugin] of plugins){
600
+ let matchesPerPlugin = [];
601
+ if (typeof plugin === "function") {
602
+ for (let ruleSet of [].concat(plugin(modifier, {
603
+ isOnlyPlugin
604
+ }))){
605
+ let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
606
+ for (let rule of rules){
607
+ matchesPerPlugin.push([
608
+ {
609
+ ...sort,
610
+ options: {
611
+ ...sort.options,
612
+ ...options
613
+ }
614
+ },
615
+ rule
616
+ ]);
617
+ }
618
+ }
619
+ } else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
620
+ let ruleSet1 = plugin;
621
+ let [rules1, options1] = parseRules(ruleSet1, context.postCssNodeCache);
622
+ for (let rule1 of rules1){
623
+ matchesPerPlugin.push([
624
+ {
625
+ ...sort,
626
+ options: {
627
+ ...sort.options,
628
+ ...options1
629
+ }
630
+ },
631
+ rule1
632
+ ]);
633
+ }
280
634
  }
281
- }, rule]);
635
+ if (matchesPerPlugin.length > 0) {
636
+ var _sort_options;
637
+ var _sort_options_types, _sort_options1;
638
+ let matchingTypes = Array.from((0, _pluginUtils.getMatchingTypes)((_sort_options_types = (_sort_options = sort.options) === null || _sort_options === void 0 ? void 0 : _sort_options.types) !== null && _sort_options_types !== void 0 ? _sort_options_types : [], modifier, (_sort_options1 = sort.options) !== null && _sort_options1 !== void 0 ? _sort_options1 : {}, context.tailwindConfig)).map(([_, type])=>type);
639
+ if (matchingTypes.length > 0) {
640
+ typesByMatches.set(matchesPerPlugin, matchingTypes);
641
+ }
642
+ matches.push(matchesPerPlugin);
643
+ }
644
+ }
645
+ if (isArbitraryValue(modifier)) {
646
+ if (matches.length > 1) {
647
+ // Partition plugins in 2 categories so that we can start searching in the plugins that
648
+ // don't have `any` as a type first.
649
+ let [withAny, withoutAny] = matches.reduce((group, plugin)=>{
650
+ let hasAnyType = plugin.some(([{ options }])=>options.types.some(({ type })=>type === "any"));
651
+ if (hasAnyType) {
652
+ group[0].push(plugin);
653
+ } else {
654
+ group[1].push(plugin);
655
+ }
656
+ return group;
657
+ }, [
658
+ [],
659
+ []
660
+ ]);
661
+ function findFallback(matches) {
662
+ // If only a single plugin matches, let's take that one
663
+ if (matches.length === 1) {
664
+ return matches[0];
665
+ }
666
+ // Otherwise, find the plugin that creates a valid rule given the arbitrary value, and
667
+ // also has the correct type which preferOnConflicts the plugin in case of clashes.
668
+ return matches.find((rules)=>{
669
+ let matchingTypes = typesByMatches.get(rules);
670
+ return rules.some(([{ options }, rule])=>{
671
+ if (!isParsableNode(rule)) {
672
+ return false;
673
+ }
674
+ return options.types.some(({ type , preferOnConflict })=>matchingTypes.includes(type) && preferOnConflict);
675
+ });
676
+ });
677
+ }
678
+ var _findFallback;
679
+ // Try to find a fallback plugin, because we already know that multiple plugins matched for
680
+ // the given arbitrary value.
681
+ let fallback = (_findFallback = findFallback(withoutAny)) !== null && _findFallback !== void 0 ? _findFallback : findFallback(withAny);
682
+ if (fallback) {
683
+ matches = [
684
+ fallback
685
+ ];
686
+ } else {
687
+ var _typesByMatches_get;
688
+ let typesPerPlugin = matches.map((match)=>new Set([
689
+ ...(_typesByMatches_get = typesByMatches.get(match)) !== null && _typesByMatches_get !== void 0 ? _typesByMatches_get : []
690
+ ]));
691
+ // Remove duplicates, so that we can detect proper unique types for each plugin.
692
+ for (let pluginTypes of typesPerPlugin){
693
+ for (let type of pluginTypes){
694
+ let removeFromOwnGroup = false;
695
+ for (let otherGroup of typesPerPlugin){
696
+ if (pluginTypes === otherGroup) continue;
697
+ if (otherGroup.has(type)) {
698
+ otherGroup.delete(type);
699
+ removeFromOwnGroup = true;
700
+ }
701
+ }
702
+ if (removeFromOwnGroup) pluginTypes.delete(type);
703
+ }
704
+ }
705
+ let messages = [];
706
+ for (let [idx, group] of typesPerPlugin.entries()){
707
+ for (let type1 of group){
708
+ let rules2 = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
709
+ .map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
710
+ .join("\n")).join("\n\n");
711
+ messages.push(` Use \`${candidate.replace("[", `[${type1}:`)}\` for \`${rules2.trim()}\``);
712
+ break;
713
+ }
714
+ }
715
+ _log.default.warn([
716
+ `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
717
+ ...messages,
718
+ `If this is content and not a class, replace it with \`${candidate.replace("[", "&lsqb;").replace("]", "&rsqb;")}\` to silence this warning.`
719
+ ]);
720
+ continue;
721
+ }
722
+ }
723
+ matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
724
+ }
725
+ matches = matches.flat();
726
+ matches = Array.from(recordCandidates(matches, classCandidate));
727
+ matches = applyPrefix(matches, context);
728
+ if (important) {
729
+ matches = applyImportant(matches, classCandidate);
730
+ }
731
+ for (let variant of variants){
732
+ matches = applyVariant(variant, matches, context);
733
+ }
734
+ for (let match of matches){
735
+ match[1].raws.tailwind = {
736
+ ...match[1].raws.tailwind,
737
+ candidate
738
+ };
739
+ // Apply final format selector
740
+ match = applyFinalFormat(match, {
741
+ context,
742
+ candidate,
743
+ original
744
+ });
745
+ // Skip rules with invalid selectors
746
+ // This will cause the candidate to be added to the "not class"
747
+ // cache skipping it entirely for future builds
748
+ if (match === null) {
749
+ continue;
750
+ }
751
+ yield match;
282
752
  }
283
- }
284
753
  }
285
-
286
- matches = applyPrefix(matches, context);
287
-
288
- if (important) {
289
- matches = applyImportant(matches, context);
754
+ }
755
+ function applyFinalFormat(match, { context , candidate , original }) {
756
+ if (!match[0].collectedFormats) {
757
+ return match;
290
758
  }
291
-
292
- for (let variant of variants) {
293
- matches = applyVariant(variant, matches, context);
759
+ let isValid = true;
760
+ let finalFormat;
761
+ try {
762
+ finalFormat = (0, _formatVariantSelector.formatVariantSelector)(match[0].collectedFormats, {
763
+ context,
764
+ candidate
765
+ });
766
+ } catch {
767
+ // The format selector we produced is invalid
768
+ // This could be because:
769
+ // - A bug exists
770
+ // - A plugin introduced an invalid variant selector (ex: `addVariant('foo', '&;foo')`)
771
+ // - The user used an invalid arbitrary variant (ex: `[&;foo]:underline`)
772
+ // Either way the build will fail because of this
773
+ // We would rather that the build pass "silently" given that this could
774
+ // happen because of picking up invalid things when scanning content
775
+ // So we'll throw out the candidate instead
776
+ return null;
294
777
  }
295
-
296
- for (let match of matches) {
297
- yield match;
778
+ let container = _postcss.default.root({
779
+ nodes: [
780
+ match[1].clone()
781
+ ]
782
+ });
783
+ container.walkRules((rule)=>{
784
+ if (inKeyframes(rule)) {
785
+ return;
786
+ }
787
+ try {
788
+ rule.selector = (0, _formatVariantSelector.finalizeSelector)(rule.selector, finalFormat, {
789
+ candidate: original,
790
+ context
791
+ });
792
+ } catch {
793
+ // If this selector is invalid we also want to skip it
794
+ // But it's likely that being invalid here means there's a bug in a plugin rather than too loosely matching content
795
+ isValid = false;
796
+ return false;
797
+ }
798
+ });
799
+ if (!isValid) {
800
+ return null;
298
801
  }
299
- }
802
+ match[1] = container.nodes[0];
803
+ return match;
300
804
  }
301
-
302
805
  function inKeyframes(rule) {
303
- return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes';
806
+ return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
807
+ }
808
+ function getImportantStrategy(important) {
809
+ if (important === true) {
810
+ return (rule)=>{
811
+ if (inKeyframes(rule)) {
812
+ return;
813
+ }
814
+ rule.walkDecls((d)=>{
815
+ if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
816
+ d.important = true;
817
+ }
818
+ });
819
+ };
820
+ }
821
+ if (typeof important === "string") {
822
+ return (rule)=>{
823
+ if (inKeyframes(rule)) {
824
+ return;
825
+ }
826
+ rule.selectors = rule.selectors.map((selector)=>{
827
+ return (0, _applyImportantSelector.applyImportantSelector)(selector, important);
828
+ });
829
+ };
830
+ }
304
831
  }
305
-
306
832
  function generateRules(candidates, context) {
307
- let allRules = [];
308
-
309
- for (let candidate of candidates) {
310
- if (context.notClassCache.has(candidate)) {
311
- continue;
312
- }
313
-
314
- if (context.classCache.has(candidate)) {
315
- allRules.push(context.classCache.get(candidate));
316
- continue;
317
- }
318
-
319
- let matches = Array.from(resolveMatches(candidate, context));
320
-
321
- if (matches.length === 0) {
322
- context.notClassCache.add(candidate);
323
- continue;
324
- }
325
-
326
- context.classCache.set(candidate, matches);
327
- allRules.push(matches);
328
- }
329
-
330
- return allRules.flat(1).map(([{
331
- sort,
332
- layer,
333
- options
334
- }, rule]) => {
335
- if (options.respectImportant) {
336
- if (context.tailwindConfig.important === true) {
337
- rule.walkDecls(d => {
338
- if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
339
- d.important = true;
340
- }
341
- });
342
- } else if (typeof context.tailwindConfig.important === 'string') {
343
- let container = _postcss.default.root({
344
- nodes: [rule.clone()]
345
- });
346
-
347
- container.walkRules(r => {
348
- if (inKeyframes(r)) {
349
- return;
350
- }
351
-
352
- r.selectors = r.selectors.map(selector => {
353
- return `${context.tailwindConfig.important} ${selector}`;
354
- });
355
- });
356
- rule = container.nodes[0];
357
- }
833
+ let allRules = [];
834
+ let strategy = getImportantStrategy(context.tailwindConfig.important);
835
+ for (let candidate of candidates){
836
+ if (context.notClassCache.has(candidate)) {
837
+ continue;
838
+ }
839
+ if (context.candidateRuleCache.has(candidate)) {
840
+ allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)));
841
+ continue;
842
+ }
843
+ let matches = Array.from(resolveMatches(candidate, context));
844
+ if (matches.length === 0) {
845
+ context.notClassCache.add(candidate);
846
+ continue;
847
+ }
848
+ context.classCache.set(candidate, matches);
849
+ var _context_candidateRuleCache_get;
850
+ let rules = (_context_candidateRuleCache_get = context.candidateRuleCache.get(candidate)) !== null && _context_candidateRuleCache_get !== void 0 ? _context_candidateRuleCache_get : new Set();
851
+ context.candidateRuleCache.set(candidate, rules);
852
+ for (const match of matches){
853
+ let [{ sort , options }, rule] = match;
854
+ if (options.respectImportant && strategy) {
855
+ let container = _postcss.default.root({
856
+ nodes: [
857
+ rule.clone()
858
+ ]
859
+ });
860
+ container.walkRules(strategy);
861
+ rule = container.nodes[0];
862
+ }
863
+ let newEntry = [
864
+ sort,
865
+ rule
866
+ ];
867
+ rules.add(newEntry);
868
+ context.ruleCache.add(newEntry);
869
+ allRules.push(newEntry);
870
+ }
358
871
  }
359
-
360
- return [sort | context.layerOrder[layer], rule];
361
- });
362
- }
872
+ return allRules;
873
+ }
874
+ function isArbitraryValue(input) {
875
+ return input.startsWith("[") && input.endsWith("]");
876
+ }