tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/CHANGELOG.md +380 -1
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +3 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli-peer-dependencies.js +10 -5
  11. package/lib/cli.js +311 -213
  12. package/lib/constants.js +9 -9
  13. package/lib/corePluginList.js +11 -1
  14. package/lib/corePlugins.js +1895 -1773
  15. package/lib/css/preflight.css +19 -13
  16. package/lib/featureFlags.js +22 -16
  17. package/lib/index.js +17 -8
  18. package/lib/lib/cacheInvalidation.js +69 -0
  19. package/lib/lib/collapseAdjacentRules.js +30 -14
  20. package/lib/lib/collapseDuplicateDeclarations.js +80 -0
  21. package/lib/lib/defaultExtractor.js +187 -0
  22. package/lib/lib/detectNesting.js +17 -2
  23. package/lib/lib/evaluateTailwindFunctions.js +40 -24
  24. package/lib/lib/expandApplyAtRules.js +414 -157
  25. package/lib/lib/expandTailwindAtRules.js +156 -151
  26. package/lib/lib/generateRules.js +402 -68
  27. package/lib/lib/getModuleDependencies.js +14 -14
  28. package/lib/lib/normalizeTailwindDirectives.js +45 -36
  29. package/lib/lib/partitionApplyAtRules.js +53 -0
  30. package/lib/lib/regex.js +53 -0
  31. package/lib/lib/resolveDefaultsAtRules.js +105 -90
  32. package/lib/lib/setupContextUtils.js +416 -291
  33. package/lib/lib/setupTrackingContext.js +60 -56
  34. package/lib/lib/sharedState.js +38 -15
  35. package/lib/lib/substituteScreenAtRules.js +9 -6
  36. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  37. package/lib/postcss-plugins/nesting/index.js +17 -0
  38. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  39. package/lib/processTailwindFeatures.js +21 -9
  40. package/lib/public/colors.js +244 -248
  41. package/lib/public/resolve-config.js +5 -5
  42. package/lib/util/buildMediaQuery.js +13 -24
  43. package/lib/util/cloneDeep.js +1 -1
  44. package/lib/util/cloneNodes.js +12 -1
  45. package/lib/util/color.js +43 -32
  46. package/lib/util/createPlugin.js +1 -2
  47. package/lib/util/createUtilityPlugin.js +13 -17
  48. package/lib/util/dataTypes.js +114 -74
  49. package/lib/util/defaults.js +6 -0
  50. package/lib/util/escapeClassName.js +5 -5
  51. package/lib/util/escapeCommas.js +1 -1
  52. package/lib/util/flattenColorPalette.js +2 -4
  53. package/lib/util/formatVariantSelector.js +194 -0
  54. package/lib/util/getAllConfigs.js +13 -5
  55. package/lib/util/hashConfig.js +5 -5
  56. package/lib/util/isKeyframeRule.js +1 -1
  57. package/lib/util/isPlainObject.js +1 -1
  58. package/lib/util/isValidArbitraryValue.js +64 -0
  59. package/lib/util/log.js +35 -19
  60. package/lib/util/nameClass.js +7 -6
  61. package/lib/util/negateValue.js +5 -3
  62. package/lib/util/normalizeConfig.js +233 -0
  63. package/lib/util/normalizeScreens.js +59 -0
  64. package/lib/util/parseAnimationValue.js +56 -56
  65. package/lib/util/parseBoxShadowValue.js +76 -0
  66. package/lib/util/parseDependency.js +32 -32
  67. package/lib/util/parseObjectStyles.js +6 -6
  68. package/lib/util/pluginUtils.js +67 -170
  69. package/lib/util/prefixSelector.js +4 -7
  70. package/lib/util/resolveConfig.js +123 -133
  71. package/lib/util/resolveConfigPath.js +17 -18
  72. package/lib/util/responsive.js +6 -6
  73. package/lib/util/splitAtTopLevelOnly.js +72 -0
  74. package/lib/util/toColorValue.js +1 -2
  75. package/lib/util/toPath.js +6 -1
  76. package/lib/util/transformThemeValue.js +42 -34
  77. package/lib/util/validateConfig.js +21 -0
  78. package/lib/util/withAlphaVariable.js +19 -19
  79. package/nesting/index.js +2 -12
  80. package/package.json +41 -42
  81. package/peers/index.js +11539 -10859
  82. package/plugin.d.ts +11 -0
  83. package/plugin.js +2 -1
  84. package/resolveConfig.js +2 -1
  85. package/scripts/create-plugin-list.js +2 -2
  86. package/scripts/generate-types.js +52 -0
  87. package/src/cli-peer-dependencies.js +7 -1
  88. package/src/cli.js +174 -41
  89. package/src/corePluginList.js +1 -1
  90. package/src/corePlugins.js +641 -596
  91. package/src/css/preflight.css +19 -13
  92. package/src/featureFlags.js +16 -10
  93. package/src/index.js +14 -6
  94. package/src/lib/cacheInvalidation.js +52 -0
  95. package/src/lib/collapseAdjacentRules.js +21 -2
  96. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  97. package/src/lib/defaultExtractor.js +192 -0
  98. package/src/lib/detectNesting.js +22 -3
  99. package/src/lib/evaluateTailwindFunctions.js +24 -7
  100. package/src/lib/expandApplyAtRules.js +442 -154
  101. package/src/lib/expandTailwindAtRules.js +91 -65
  102. package/src/lib/generateRules.js +409 -43
  103. package/src/lib/normalizeTailwindDirectives.js +10 -3
  104. package/src/lib/partitionApplyAtRules.js +52 -0
  105. package/src/lib/regex.js +74 -0
  106. package/src/lib/resolveDefaultsAtRules.js +74 -53
  107. package/src/lib/setupContextUtils.js +388 -208
  108. package/src/lib/setupTrackingContext.js +15 -12
  109. package/src/lib/sharedState.js +42 -7
  110. package/src/lib/substituteScreenAtRules.js +6 -3
  111. package/src/postcss-plugins/nesting/README.md +42 -0
  112. package/src/postcss-plugins/nesting/index.js +13 -0
  113. package/src/postcss-plugins/nesting/plugin.js +80 -0
  114. package/src/processTailwindFeatures.js +17 -2
  115. package/src/public/colors.js +4 -9
  116. package/src/util/buildMediaQuery.js +14 -18
  117. package/src/util/cloneNodes.js +14 -1
  118. package/src/util/color.js +31 -14
  119. package/src/util/createUtilityPlugin.js +2 -2
  120. package/src/util/dataTypes.js +56 -16
  121. package/src/util/defaults.js +6 -0
  122. package/src/util/formatVariantSelector.js +213 -0
  123. package/src/util/getAllConfigs.js +7 -0
  124. package/src/util/isValidArbitraryValue.js +61 -0
  125. package/src/util/log.js +23 -22
  126. package/src/util/nameClass.js +2 -2
  127. package/src/util/negateValue.js +4 -2
  128. package/src/util/normalizeConfig.js +262 -0
  129. package/src/util/normalizeScreens.js +45 -0
  130. package/src/util/parseBoxShadowValue.js +72 -0
  131. package/src/util/pluginUtils.js +51 -147
  132. package/src/util/prefixSelector.js +7 -8
  133. package/src/util/resolveConfig.js +108 -79
  134. package/src/util/splitAtTopLevelOnly.js +71 -0
  135. package/src/util/toPath.js +23 -1
  136. package/src/util/transformThemeValue.js +24 -7
  137. package/src/util/validateConfig.js +13 -0
  138. package/stubs/defaultConfig.stub.js +157 -94
  139. package/stubs/simpleConfig.stub.js +0 -1
  140. package/types/config.d.ts +325 -0
  141. package/types/generated/.gitkeep +0 -0
  142. package/types/generated/colors.d.ts +276 -0
  143. package/types/generated/corePluginList.d.ts +1 -0
  144. package/types/index.d.ts +1 -0
  145. package/types.d.ts +1 -0
  146. package/lib/lib/setupWatchingContext.js +0 -284
  147. package/nesting/plugin.js +0 -41
  148. package/src/lib/setupWatchingContext.js +0 -306
@@ -9,13 +9,43 @@ var _parseObjectStyles = _interopRequireDefault(require("../util/parseObjectStyl
9
9
  var _isPlainObject = _interopRequireDefault(require("../util/isPlainObject"));
10
10
  var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
11
11
  var _pluginUtils = require("../util/pluginUtils");
12
+ var _log = _interopRequireDefault(require("../util/log"));
13
+ var sharedState = _interopRequireWildcard(require("./sharedState"));
14
+ var _formatVariantSelector = require("../util/formatVariantSelector");
15
+ var _nameClass = require("../util/nameClass");
16
+ var _dataTypes = require("../util/dataTypes");
17
+ var _setupContextUtils = require("./setupContextUtils");
18
+ var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
19
+ var _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
20
+ var _featureFlags = require("../featureFlags");
12
21
  function _interopRequireDefault(obj) {
13
22
  return obj && obj.__esModule ? obj : {
14
23
  default: obj
15
24
  };
16
25
  }
26
+ function _interopRequireWildcard(obj) {
27
+ if (obj && obj.__esModule) {
28
+ return obj;
29
+ } else {
30
+ var newObj = {};
31
+ if (obj != null) {
32
+ for(var key in obj){
33
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
34
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
35
+ if (desc.get || desc.set) {
36
+ Object.defineProperty(newObj, key, desc);
37
+ } else {
38
+ newObj[key] = obj[key];
39
+ }
40
+ }
41
+ }
42
+ }
43
+ newObj.default = obj;
44
+ return newObj;
45
+ }
46
+ }
17
47
  let classNameParser = (0, _postcssSelectorParser).default((selectors)=>{
18
- return selectors.first.filter(({ type })=>type === 'class'
48
+ return selectors.first.filter(({ type })=>type === "class"
19
49
  ).pop().value;
20
50
  });
21
51
  function getClassNameFromSelector(selector) {
@@ -28,35 +58,35 @@ function getClassNameFromSelector(selector) {
28
58
  // Example with dynamic classes:
29
59
  // ['grid-cols', '[[linename],1fr,auto]']
30
60
  // ['grid', 'cols-[[linename],1fr,auto]']
31
- function* candidatePermutations(candidate, lastIndex = Infinity) {
32
- if (lastIndex < 0) {
33
- return;
34
- }
35
- let dashIdx;
36
- if (lastIndex === Infinity && candidate.endsWith(']')) {
37
- let bracketIdx = candidate.indexOf('[');
38
- // If character before `[` isn't a dash or a slash, this isn't a dynamic class
39
- // eg. string[]
40
- dashIdx = [
41
- '-',
42
- '/'
43
- ].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
44
- } else {
45
- dashIdx = candidate.lastIndexOf('-', lastIndex);
46
- }
47
- if (dashIdx < 0) {
48
- return;
61
+ function* candidatePermutations(candidate) {
62
+ let lastIndex = Infinity;
63
+ while(lastIndex >= 0){
64
+ let dashIdx;
65
+ if (lastIndex === Infinity && candidate.endsWith("]")) {
66
+ let bracketIdx = candidate.indexOf("[");
67
+ // If character before `[` isn't a dash or a slash, this isn't a dynamic class
68
+ // eg. string[]
69
+ dashIdx = [
70
+ "-",
71
+ "/"
72
+ ].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
73
+ } else {
74
+ dashIdx = candidate.lastIndexOf("-", lastIndex);
75
+ }
76
+ if (dashIdx < 0) {
77
+ break;
78
+ }
79
+ let prefix = candidate.slice(0, dashIdx);
80
+ let modifier = candidate.slice(dashIdx + 1);
81
+ yield [
82
+ prefix,
83
+ modifier
84
+ ];
85
+ lastIndex = dashIdx - 1;
49
86
  }
50
- let prefix = candidate.slice(0, dashIdx);
51
- let modifier = candidate.slice(dashIdx + 1);
52
- yield [
53
- prefix,
54
- modifier
55
- ];
56
- yield* candidatePermutations(candidate, dashIdx - 1);
57
87
  }
58
88
  function applyPrefix(matches, context) {
59
- if (matches.length === 0 || context.tailwindConfig.prefix === '') {
89
+ if (matches.length === 0 || context.tailwindConfig.prefix === "") {
60
90
  return matches;
61
91
  }
62
92
  for (let match of matches){
@@ -67,15 +97,21 @@ function applyPrefix(matches, context) {
67
97
  match[1].clone()
68
98
  ]
69
99
  });
100
+ let classCandidate = match[1].raws.tailwind.classCandidate;
70
101
  container.walkRules((r)=>{
71
- r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector);
102
+ // If this is a negative utility with a dash *before* the prefix we
103
+ // have to ensure that the generated selector matches the candidate
104
+ // Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
105
+ // The disconnect between candidate <-> class can cause @apply to hard crash.
106
+ let shouldPrependNegative = classCandidate.startsWith("-");
107
+ r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
72
108
  });
73
109
  match[1] = container.nodes[0];
74
110
  }
75
111
  }
76
112
  return matches;
77
113
  }
78
- function applyImportant(matches) {
114
+ function applyImportant(matches, classCandidate) {
79
115
  if (matches.length === 0) {
80
116
  return matches;
81
117
  }
@@ -88,7 +124,10 @@ function applyImportant(matches) {
88
124
  });
89
125
  container.walkRules((r)=>{
90
126
  r.selector = (0, _pluginUtils).updateAllClasses(r.selector, (className)=>{
91
- return `!${className}`;
127
+ if (className === classCandidate) {
128
+ return `!${className}`;
129
+ }
130
+ return className;
92
131
  });
93
132
  r.walkDecls((d)=>d.important = true
94
133
  );
@@ -115,27 +154,54 @@ function applyVariant(variant, matches, context) {
115
154
  if (matches.length === 0) {
116
155
  return matches;
117
156
  }
157
+ let args;
158
+ // Find partial arbitrary variants
159
+ if (variant.endsWith("]") && !variant.startsWith("[")) {
160
+ args = variant.slice(variant.lastIndexOf("[") + 1, -1);
161
+ variant = variant.slice(0, variant.indexOf(args) - 1 /* - */ - 1 /* [ */ );
162
+ }
163
+ // Register arbitrary variants
164
+ if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
165
+ let selector = (0, _dataTypes).normalize(variant.slice(1, -1));
166
+ if (!(0, _setupContextUtils).isValidVariantFormatString(selector)) {
167
+ return [];
168
+ }
169
+ let fn = (0, _setupContextUtils).parseVariant(selector);
170
+ let sort = Array.from(context.variantOrder.values()).pop() << 1n;
171
+ context.variantMap.set(variant, [
172
+ [
173
+ sort,
174
+ fn
175
+ ]
176
+ ]);
177
+ context.variantOrder.set(variant, sort);
178
+ }
118
179
  if (context.variantMap.has(variant)) {
119
180
  let variantFunctionTuples = context.variantMap.get(variant);
120
181
  let result = [];
121
- for (let [meta, rule] of matches){
122
- if (meta.options.respectVariants === false) {
123
- result.push([
124
- meta,
125
- rule
126
- ]);
182
+ for (let [meta, rule1] of matches){
183
+ // Don't generate variants for user css
184
+ if (meta.layer === "user") {
127
185
  continue;
128
186
  }
129
187
  let container = _postcss.default.root({
130
188
  nodes: [
131
- rule.clone()
189
+ rule1.clone()
132
190
  ]
133
191
  });
134
192
  for (let [variantSort, variantFunction] of variantFunctionTuples){
135
193
  let clone = container.clone();
194
+ let collectedFormats = [];
195
+ let originals = new Map();
196
+ function prepareBackup() {
197
+ if (originals.size > 0) return; // Already prepared, chicken out
198
+ clone.walkRules((rule)=>originals.set(rule, rule.selector)
199
+ );
200
+ }
136
201
  function modifySelectors(modifierFunction) {
202
+ prepareBackup();
137
203
  clone.each((rule)=>{
138
- if (rule.type !== 'rule') {
204
+ if (rule.type !== "rule") {
139
205
  return;
140
206
  }
141
207
  rule.selectors = rule.selectors.map((selector)=>{
@@ -150,19 +216,80 @@ function applyVariant(variant, matches, context) {
150
216
  return clone;
151
217
  }
152
218
  let ruleWithVariant = variantFunction({
153
- container: clone,
219
+ // Public API
220
+ get container () {
221
+ prepareBackup();
222
+ return clone;
223
+ },
154
224
  separator: context.tailwindConfig.separator,
155
- modifySelectors
225
+ modifySelectors,
226
+ // Private API for now
227
+ wrap (wrapper) {
228
+ let nodes = clone.nodes;
229
+ clone.removeAll();
230
+ wrapper.append(nodes);
231
+ clone.append(wrapper);
232
+ },
233
+ format (selectorFormat) {
234
+ collectedFormats.push(selectorFormat);
235
+ },
236
+ args
156
237
  });
238
+ if (typeof ruleWithVariant === "string") {
239
+ collectedFormats.push(ruleWithVariant);
240
+ }
157
241
  if (ruleWithVariant === null) {
158
242
  continue;
159
243
  }
244
+ // We filled the `originals`, therefore we assume that somebody touched
245
+ // `container` or `modifySelectors`. Let's see if they did, so that we
246
+ // can restore the selectors, and collect the format strings.
247
+ if (originals.size > 0) {
248
+ clone.walkRules((rule)=>{
249
+ if (!originals.has(rule)) return;
250
+ let before = originals.get(rule);
251
+ if (before === rule.selector) return; // No mutation happened
252
+ let modified = rule.selector;
253
+ // Rebuild the base selector, this is what plugin authors would do
254
+ // as well. E.g.: `${variant}${separator}${className}`.
255
+ // However, plugin authors probably also prepend or append certain
256
+ // classes, pseudos, ids, ...
257
+ let rebuiltBase = (0, _postcssSelectorParser).default((selectors)=>{
258
+ selectors.walkClasses((classNode)=>{
259
+ classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
260
+ });
261
+ }).processSync(before);
262
+ // Now that we know the original selector, the new selector, and
263
+ // the rebuild part in between, we can replace the part that plugin
264
+ // authors need to rebuild with `&`, and eventually store it in the
265
+ // collectedFormats. Similar to what `format('...')` would do.
266
+ //
267
+ // E.g.:
268
+ // variant: foo
269
+ // selector: .markdown > p
270
+ // modified (by plugin): .foo .foo\\:markdown > p
271
+ // rebuiltBase (internal): .foo\\:markdown > p
272
+ // format: .foo &
273
+ collectedFormats.push(modified.replace(rebuiltBase, "&"));
274
+ rule.selector = before;
275
+ });
276
+ }
277
+ // This tracks the originating layer for the variant
278
+ // For example:
279
+ // .sm:underline {} is a variant of something in the utilities layer
280
+ // .sm:container {} is a variant of the container component
281
+ clone.nodes[0].raws.tailwind = {
282
+ ...clone.nodes[0].raws.tailwind,
283
+ parentLayer: meta.layer
284
+ };
285
+ var _collectedFormats;
160
286
  let withOffset = [
161
287
  {
162
288
  ...meta,
163
- sort: variantSort | meta.sort
289
+ sort: variantSort | meta.sort,
290
+ collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats)
164
291
  },
165
- clone.nodes[0]
292
+ clone.nodes[0],
166
293
  ];
167
294
  result.push(withOffset);
168
295
  }
@@ -171,8 +298,7 @@ function applyVariant(variant, matches, context) {
171
298
  }
172
299
  return [];
173
300
  }
174
- function parseRules(rule, cache, options = {
175
- }) {
301
+ function parseRules(rule, cache, options = {}) {
176
302
  // PostCSS node
177
303
  if (!(0, _isPlainObject).default(rule) && !Array.isArray(rule)) {
178
304
  return [
@@ -195,42 +321,154 @@ function parseRules(rule, cache, options = {
195
321
  options
196
322
  ];
197
323
  }
324
+ const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
325
+ function isValidPropName(name) {
326
+ return IS_VALID_PROPERTY_NAME.test(name);
327
+ }
328
+ /**
329
+ * @param {string} declaration
330
+ * @returns {boolean}
331
+ */ function looksLikeUri(declaration) {
332
+ // Quick bailout for obvious non-urls
333
+ // This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
334
+ if (!declaration.includes("://")) {
335
+ return false;
336
+ }
337
+ try {
338
+ const url = new URL(declaration);
339
+ return url.scheme !== "" && url.host !== "";
340
+ } catch (err) {
341
+ // Definitely not a valid url
342
+ return false;
343
+ }
344
+ }
345
+ function isParsableNode(node) {
346
+ let isParsable = true;
347
+ node.walkDecls((decl)=>{
348
+ if (!isParsableCssValue(decl.name, decl.value)) {
349
+ isParsable = false;
350
+ return false;
351
+ }
352
+ });
353
+ return isParsable;
354
+ }
355
+ function isParsableCssValue(property, value) {
356
+ // We don't want to to treat [https://example.com] as a custom property
357
+ // Even though, according to the CSS grammar, it's a totally valid CSS declaration
358
+ // So we short-circuit here by checking if the custom property looks like a url
359
+ if (looksLikeUri(`${property}:${value}`)) {
360
+ return false;
361
+ }
362
+ try {
363
+ _postcss.default.parse(`a{${property}:${value}}`).toResult();
364
+ return true;
365
+ } catch (err) {
366
+ return false;
367
+ }
368
+ }
369
+ function extractArbitraryProperty(classCandidate, context) {
370
+ var ref;
371
+ let [, property, value] = (ref = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && ref !== void 0 ? ref : [];
372
+ if (value === undefined) {
373
+ return null;
374
+ }
375
+ if (!isValidPropName(property)) {
376
+ return null;
377
+ }
378
+ if (!(0, _isValidArbitraryValue).default(value)) {
379
+ return null;
380
+ }
381
+ let normalized = (0, _dataTypes).normalize(value);
382
+ if (!isParsableCssValue(property, normalized)) {
383
+ return null;
384
+ }
385
+ return [
386
+ [
387
+ {
388
+ sort: context.arbitraryPropertiesSort,
389
+ layer: "utilities"
390
+ },
391
+ ()=>({
392
+ [(0, _nameClass).asClass(classCandidate)]: {
393
+ [property]: normalized
394
+ }
395
+ })
396
+ ,
397
+ ],
398
+ ];
399
+ }
198
400
  function* resolveMatchedPlugins(classCandidate, context) {
199
401
  if (context.candidateRuleMap.has(classCandidate)) {
200
402
  yield [
201
403
  context.candidateRuleMap.get(classCandidate),
202
- 'DEFAULT'
404
+ "DEFAULT"
203
405
  ];
204
406
  }
407
+ yield* function*(arbitraryPropertyRule) {
408
+ if (arbitraryPropertyRule !== null) {
409
+ yield [
410
+ arbitraryPropertyRule,
411
+ "DEFAULT"
412
+ ];
413
+ }
414
+ }(extractArbitraryProperty(classCandidate, context));
205
415
  let candidatePrefix = classCandidate;
206
416
  let negative = false;
207
- const twConfigPrefix = context.tailwindConfig.prefix || '';
417
+ const twConfigPrefix = context.tailwindConfig.prefix;
208
418
  const twConfigPrefixLen = twConfigPrefix.length;
209
- if (candidatePrefix[twConfigPrefixLen] === '-') {
419
+ const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
420
+ if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
210
421
  negative = true;
211
422
  candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
212
423
  }
424
+ if (negative && context.candidateRuleMap.has(candidatePrefix)) {
425
+ yield [
426
+ context.candidateRuleMap.get(candidatePrefix),
427
+ "-DEFAULT"
428
+ ];
429
+ }
213
430
  for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
214
431
  if (context.candidateRuleMap.has(prefix)) {
215
432
  yield [
216
433
  context.candidateRuleMap.get(prefix),
217
434
  negative ? `-${modifier}` : modifier
218
435
  ];
219
- return;
220
436
  }
221
437
  }
222
438
  }
223
439
  function splitWithSeparator(input, separator) {
224
- return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'));
440
+ if (input === sharedState.NOT_ON_DEMAND) {
441
+ return [
442
+ sharedState.NOT_ON_DEMAND
443
+ ];
444
+ }
445
+ return Array.from((0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(input, separator));
225
446
  }
226
- function* resolveMatches(candidate, context) {
447
+ function* recordCandidates(matches, classCandidate) {
448
+ for (const match of matches){
449
+ match[1].raws.tailwind = {
450
+ ...match[1].raws.tailwind,
451
+ classCandidate
452
+ };
453
+ yield match;
454
+ }
455
+ }
456
+ function* resolveMatches(candidate, context, original = candidate) {
227
457
  let separator = context.tailwindConfig.separator;
228
458
  let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
229
459
  let important = false;
230
- if (classCandidate.startsWith('!')) {
460
+ if (classCandidate.startsWith("!")) {
231
461
  important = true;
232
462
  classCandidate = classCandidate.slice(1);
233
463
  }
464
+ if ((0, _featureFlags).flagEnabled(context.tailwindConfig, "variantGrouping")) {
465
+ if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
466
+ let base = variants.slice().reverse().join(separator);
467
+ for (let part of (0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(classCandidate.slice(1, -1), ",")){
468
+ yield* resolveMatches(base + separator + part, context, original);
469
+ }
470
+ }
471
+ }
234
472
  // TODO: Reintroduce this in ways that doesn't break on false positives
235
473
  // function sortAgainst(toSort, against) {
236
474
  // return toSort.slice().sort((a, z) => {
@@ -244,16 +482,18 @@ function* resolveMatches(candidate, context) {
244
482
  // }
245
483
  for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)){
246
484
  let matches = [];
485
+ let typesByMatches = new Map();
247
486
  let [plugins, modifier] = matchedPlugins;
248
487
  let isOnlyPlugin = plugins.length === 1;
249
488
  for (let [sort, plugin] of plugins){
250
- if (typeof plugin === 'function') {
489
+ let matchesPerPlugin = [];
490
+ if (typeof plugin === "function") {
251
491
  for (let ruleSet of [].concat(plugin(modifier, {
252
492
  isOnlyPlugin
253
493
  }))){
254
494
  let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
255
495
  for (let rule of rules){
256
- matches.push([
496
+ matchesPerPlugin.push([
257
497
  {
258
498
  ...sort,
259
499
  options: {
@@ -265,11 +505,11 @@ function* resolveMatches(candidate, context) {
265
505
  ]);
266
506
  }
267
507
  }
268
- } else if (modifier === 'DEFAULT') {
508
+ } else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
269
509
  let ruleSet = plugin;
270
510
  let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
271
511
  for (let rule of rules){
272
- matches.push([
512
+ matchesPerPlugin.push([
273
513
  {
274
514
  ...sort,
275
515
  options: {
@@ -281,21 +521,102 @@ function* resolveMatches(candidate, context) {
281
521
  ]);
282
522
  }
283
523
  }
524
+ if (matchesPerPlugin.length > 0) {
525
+ var ref;
526
+ typesByMatches.set(matchesPerPlugin, (ref = sort.options) === null || ref === void 0 ? void 0 : ref.type);
527
+ matches.push(matchesPerPlugin);
528
+ }
284
529
  }
530
+ if (isArbitraryValue(modifier)) {
531
+ // When generated arbitrary values are ambiguous, we can't know
532
+ // which to pick so don't generate any utilities for them
533
+ if (matches.length > 1) {
534
+ var ref1;
535
+ let typesPerPlugin = matches.map((match)=>new Set([
536
+ ...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
537
+ ])
538
+ );
539
+ // Remove duplicates, so that we can detect proper unique types for each plugin.
540
+ for (let pluginTypes of typesPerPlugin){
541
+ for (let type of pluginTypes){
542
+ let removeFromOwnGroup = false;
543
+ for (let otherGroup of typesPerPlugin){
544
+ if (pluginTypes === otherGroup) continue;
545
+ if (otherGroup.has(type)) {
546
+ otherGroup.delete(type);
547
+ removeFromOwnGroup = true;
548
+ }
549
+ }
550
+ if (removeFromOwnGroup) pluginTypes.delete(type);
551
+ }
552
+ }
553
+ let messages = [];
554
+ for (let [idx, group] of typesPerPlugin.entries()){
555
+ for (let type of group){
556
+ let rules = matches[idx].map(([, rule])=>rule
557
+ ).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
558
+ .map((line)=>line.trim()
559
+ ).map((x)=>` ${x}`
560
+ ) // Re-indent
561
+ .join("\n")
562
+ ).join("\n\n");
563
+ messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
564
+ break;
565
+ }
566
+ }
567
+ _log.default.warn([
568
+ `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
569
+ ...messages,
570
+ `If this is content and not a class, replace it with \`${candidate.replace("[", "&lsqb;").replace("]", "&rsqb;")}\` to silence this warning.`,
571
+ ]);
572
+ continue;
573
+ }
574
+ matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])
575
+ )
576
+ );
577
+ }
578
+ matches = matches.flat();
579
+ matches = Array.from(recordCandidates(matches, classCandidate));
285
580
  matches = applyPrefix(matches, context);
286
581
  if (important) {
287
- matches = applyImportant(matches, context);
582
+ matches = applyImportant(matches, classCandidate);
288
583
  }
289
584
  for (let variant of variants){
290
585
  matches = applyVariant(variant, matches, context);
291
586
  }
292
- for (let match of matches){
293
- yield match;
587
+ for (let match1 of matches){
588
+ match1[1].raws.tailwind = {
589
+ ...match1[1].raws.tailwind,
590
+ candidate
591
+ };
592
+ // Apply final format selector
593
+ if (match1[0].collectedFormats) {
594
+ let finalFormat = (0, _formatVariantSelector).formatVariantSelector("&", ...match1[0].collectedFormats);
595
+ let container = _postcss.default.root({
596
+ nodes: [
597
+ match1[1].clone()
598
+ ]
599
+ });
600
+ container.walkRules((rule)=>{
601
+ var ref;
602
+ if (inKeyframes(rule)) return;
603
+ var ref2;
604
+ rule.selector = (0, _formatVariantSelector).finalizeSelector(finalFormat, {
605
+ selector: rule.selector,
606
+ candidate: original,
607
+ base: candidate.split(new RegExp(`\\${(ref2 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref2 !== void 0 ? ref2 : ":"}(?![^[]*\\])`)).pop(),
608
+ context
609
+ });
610
+ });
611
+ match1[1] = container.nodes[0];
612
+ }
613
+ yield match1;
294
614
  }
295
615
  }
296
616
  }
617
+ exports.resolveMatches = resolveMatches;
297
618
  function inKeyframes(rule) {
298
- return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes';
619
+ return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
299
620
  }
300
621
  function generateRules(candidates, context) {
301
622
  let allRules = [];
@@ -315,15 +636,28 @@ function generateRules(candidates, context) {
315
636
  context.classCache.set(candidate, matches);
316
637
  allRules.push(matches);
317
638
  }
318
- return allRules.flat(1).map(([{ sort , layer , options }, rule])=>{
319
- if (options.respectImportant) {
320
- if (context.tailwindConfig.important === true) {
639
+ // Strategy based on `tailwindConfig.important`
640
+ let strategy = ((important)=>{
641
+ if (important === true) {
642
+ return (rule)=>{
321
643
  rule.walkDecls((d)=>{
322
- if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
644
+ if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
323
645
  d.important = true;
324
646
  }
325
647
  });
326
- } else if (typeof context.tailwindConfig.important === 'string') {
648
+ };
649
+ }
650
+ if (typeof important === "string") {
651
+ return (rule)=>{
652
+ rule.selectors = rule.selectors.map((selector)=>{
653
+ return `${important} ${selector}`;
654
+ });
655
+ };
656
+ }
657
+ })(context.tailwindConfig.important);
658
+ return allRules.flat(1).map(([{ sort , layer , options }, rule])=>{
659
+ if (options.respectImportant) {
660
+ if (strategy) {
327
661
  let container = _postcss.default.root({
328
662
  nodes: [
329
663
  rule.clone()
@@ -333,9 +667,7 @@ function generateRules(candidates, context) {
333
667
  if (inKeyframes(r)) {
334
668
  return;
335
669
  }
336
- r.selectors = r.selectors.map((selector)=>{
337
- return `${context.tailwindConfig.important} ${selector}`;
338
- });
670
+ strategy(r);
339
671
  });
340
672
  rule = container.nodes[0];
341
673
  }
@@ -346,5 +678,7 @@ function generateRules(candidates, context) {
346
678
  ];
347
679
  });
348
680
  }
349
- exports.resolveMatches = resolveMatches;
350
681
  exports.generateRules = generateRules;
682
+ function isArbitraryValue(input) {
683
+ return input.startsWith("[") && input.endsWith("]");
684
+ }