tailwindcss 0.0.0-insiders.fda68f7 → 0.0.0-oxide.6bf5e56

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