tailwindcss 3.0.22 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +92 -2
  2. package/colors.d.ts +3 -0
  3. package/defaultConfig.d.ts +3 -0
  4. package/defaultTheme.d.ts +3 -0
  5. package/lib/cli-peer-dependencies.js +10 -5
  6. package/lib/cli.js +266 -203
  7. package/lib/constants.js +8 -8
  8. package/lib/corePluginList.js +1 -0
  9. package/lib/corePlugins.js +1662 -1554
  10. package/lib/css/preflight.css +1 -8
  11. package/lib/featureFlags.js +14 -12
  12. package/lib/index.js +16 -6
  13. package/lib/lib/cacheInvalidation.js +87 -0
  14. package/lib/lib/collapseAdjacentRules.js +30 -15
  15. package/lib/lib/collapseDuplicateDeclarations.js +1 -1
  16. package/lib/lib/defaultExtractor.js +191 -30
  17. package/lib/lib/detectNesting.js +9 -9
  18. package/lib/lib/evaluateTailwindFunctions.js +37 -28
  19. package/lib/lib/expandApplyAtRules.js +379 -189
  20. package/lib/lib/expandTailwindAtRules.js +168 -144
  21. package/lib/lib/generateRules.js +190 -81
  22. package/lib/lib/getModuleDependencies.js +14 -14
  23. package/lib/lib/normalizeTailwindDirectives.js +35 -35
  24. package/lib/lib/partitionApplyAtRules.js +7 -7
  25. package/lib/lib/regex.js +52 -0
  26. package/lib/lib/resolveDefaultsAtRules.js +80 -79
  27. package/lib/lib/setupContextUtils.js +207 -170
  28. package/lib/lib/setupTrackingContext.js +61 -63
  29. package/lib/lib/sharedState.js +11 -8
  30. package/lib/lib/substituteScreenAtRules.js +3 -4
  31. package/lib/postcss-plugins/nesting/README.md +2 -2
  32. package/lib/postcss-plugins/nesting/index.js +1 -1
  33. package/lib/postcss-plugins/nesting/plugin.js +40 -9
  34. package/lib/processTailwindFeatures.js +7 -7
  35. package/lib/public/colors.js +241 -241
  36. package/lib/public/resolve-config.js +5 -5
  37. package/lib/util/buildMediaQuery.js +2 -3
  38. package/lib/util/cloneDeep.js +3 -5
  39. package/lib/util/cloneNodes.js +12 -1
  40. package/lib/util/color.js +42 -51
  41. package/lib/util/createPlugin.js +1 -2
  42. package/lib/util/createUtilityPlugin.js +6 -7
  43. package/lib/util/dataTypes.js +85 -81
  44. package/lib/util/escapeClassName.js +5 -5
  45. package/lib/util/escapeCommas.js +1 -1
  46. package/lib/util/flattenColorPalette.js +4 -7
  47. package/lib/util/formatVariantSelector.js +82 -75
  48. package/lib/util/getAllConfigs.js +15 -10
  49. package/lib/util/hashConfig.js +5 -5
  50. package/lib/util/isKeyframeRule.js +1 -1
  51. package/lib/util/isPlainObject.js +1 -1
  52. package/lib/util/isValidArbitraryValue.js +26 -27
  53. package/lib/util/log.js +9 -10
  54. package/lib/util/nameClass.js +7 -7
  55. package/lib/util/negateValue.js +4 -5
  56. package/lib/util/normalizeConfig.js +68 -58
  57. package/lib/util/normalizeScreens.js +5 -6
  58. package/lib/util/parseAnimationValue.js +56 -57
  59. package/lib/util/parseBoxShadowValue.js +19 -20
  60. package/lib/util/parseDependency.js +32 -32
  61. package/lib/util/parseObjectStyles.js +6 -6
  62. package/lib/util/pluginUtils.js +20 -12
  63. package/lib/util/prefixSelector.js +1 -1
  64. package/lib/util/resolveConfig.js +81 -58
  65. package/lib/util/resolveConfigPath.js +16 -16
  66. package/lib/util/responsive.js +6 -6
  67. package/lib/util/splitAtTopLevelOnly.js +90 -0
  68. package/lib/util/toColorValue.js +1 -1
  69. package/lib/util/toPath.js +2 -2
  70. package/lib/util/transformThemeValue.js +30 -28
  71. package/lib/util/validateConfig.js +21 -0
  72. package/lib/util/withAlphaVariable.js +23 -23
  73. package/package.json +33 -27
  74. package/peers/index.js +7728 -5848
  75. package/plugin.d.ts +11 -0
  76. package/scripts/generate-types.js +52 -0
  77. package/src/cli-peer-dependencies.js +7 -1
  78. package/src/cli.js +118 -24
  79. package/src/corePluginList.js +1 -1
  80. package/src/corePlugins.js +142 -30
  81. package/src/css/preflight.css +1 -8
  82. package/src/featureFlags.js +4 -4
  83. package/src/index.js +15 -1
  84. package/src/lib/cacheInvalidation.js +52 -0
  85. package/src/lib/collapseAdjacentRules.js +21 -2
  86. package/src/lib/defaultExtractor.js +177 -33
  87. package/src/lib/evaluateTailwindFunctions.js +20 -4
  88. package/src/lib/expandApplyAtRules.js +418 -186
  89. package/src/lib/expandTailwindAtRules.js +30 -10
  90. package/src/lib/generateRules.js +142 -51
  91. package/src/lib/regex.js +74 -0
  92. package/src/lib/resolveDefaultsAtRules.js +7 -3
  93. package/src/lib/setupContextUtils.js +142 -87
  94. package/src/lib/setupTrackingContext.js +7 -3
  95. package/src/lib/sharedState.js +2 -0
  96. package/src/postcss-plugins/nesting/README.md +2 -2
  97. package/src/postcss-plugins/nesting/plugin.js +36 -0
  98. package/src/util/cloneNodes.js +14 -1
  99. package/src/util/color.js +25 -21
  100. package/src/util/dataTypes.js +14 -6
  101. package/src/util/formatVariantSelector.js +79 -62
  102. package/src/util/getAllConfigs.js +7 -0
  103. package/src/util/log.js +8 -8
  104. package/src/util/normalizeConfig.js +0 -8
  105. package/src/util/parseBoxShadowValue.js +3 -2
  106. package/src/util/pluginUtils.js +13 -1
  107. package/src/util/resolveConfig.js +66 -22
  108. package/src/util/splitAtTopLevelOnly.js +71 -0
  109. package/src/util/toPath.js +1 -1
  110. package/src/util/transformThemeValue.js +4 -2
  111. package/src/util/validateConfig.js +13 -0
  112. package/src/util/withAlphaVariable.js +1 -1
  113. package/stubs/defaultConfig.stub.js +5 -1
  114. package/stubs/simpleConfig.stub.js +1 -0
  115. package/types/config.d.ts +325 -0
  116. package/types/generated/.gitkeep +0 -0
  117. package/types/generated/colors.d.ts +276 -0
  118. package/types/generated/corePluginList.d.ts +1 -0
  119. package/types/index.d.ts +1 -0
@@ -10,18 +10,60 @@ var _isPlainObject = _interopRequireDefault(require("../util/isPlainObject"));
10
10
  var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
11
11
  var _pluginUtils = require("../util/pluginUtils");
12
12
  var _log = _interopRequireDefault(require("../util/log"));
13
+ var sharedState = _interopRequireWildcard(require("./sharedState"));
13
14
  var _formatVariantSelector = require("../util/formatVariantSelector");
14
15
  var _nameClass = require("../util/nameClass");
15
16
  var _dataTypes = require("../util/dataTypes");
17
+ var _setupContextUtils = require("./setupContextUtils");
16
18
  var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
19
+ var _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
20
+ var _featureFlags = require("../featureFlags");
17
21
  function _interopRequireDefault(obj) {
18
22
  return obj && obj.__esModule ? obj : {
19
23
  default: obj
20
24
  };
21
25
  }
26
+ function _getRequireWildcardCache() {
27
+ if (typeof WeakMap !== "function") return null;
28
+ var cache = new WeakMap();
29
+ _getRequireWildcardCache = function() {
30
+ return cache;
31
+ };
32
+ return cache;
33
+ }
34
+ function _interopRequireWildcard(obj) {
35
+ if (obj && obj.__esModule) {
36
+ return obj;
37
+ }
38
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
39
+ return {
40
+ default: obj
41
+ };
42
+ }
43
+ var cache = _getRequireWildcardCache();
44
+ if (cache && cache.has(obj)) {
45
+ return cache.get(obj);
46
+ }
47
+ var newObj = {};
48
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
49
+ for(var key in obj){
50
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
51
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
52
+ if (desc && (desc.get || desc.set)) {
53
+ Object.defineProperty(newObj, key, desc);
54
+ } else {
55
+ newObj[key] = obj[key];
56
+ }
57
+ }
58
+ }
59
+ newObj.default = obj;
60
+ if (cache) {
61
+ cache.set(obj, newObj);
62
+ }
63
+ return newObj;
64
+ }
22
65
  let classNameParser = (0, _postcssSelectorParser).default((selectors)=>{
23
- return selectors.first.filter(({ type })=>type === 'class'
24
- ).pop().value;
66
+ return selectors.first.filter(({ type })=>type === "class").pop().value;
25
67
  });
26
68
  function getClassNameFromSelector(selector) {
27
69
  return classNameParser.transformSync(selector);
@@ -37,16 +79,16 @@ function* candidatePermutations(candidate) {
37
79
  let lastIndex = Infinity;
38
80
  while(lastIndex >= 0){
39
81
  let dashIdx;
40
- if (lastIndex === Infinity && candidate.endsWith(']')) {
41
- let bracketIdx = candidate.indexOf('[');
82
+ if (lastIndex === Infinity && candidate.endsWith("]")) {
83
+ let bracketIdx = candidate.indexOf("[");
42
84
  // If character before `[` isn't a dash or a slash, this isn't a dynamic class
43
85
  // eg. string[]
44
86
  dashIdx = [
45
- '-',
46
- '/'
87
+ "-",
88
+ "/"
47
89
  ].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
48
90
  } else {
49
- dashIdx = candidate.lastIndexOf('-', lastIndex);
91
+ dashIdx = candidate.lastIndexOf("-", lastIndex);
50
92
  }
51
93
  if (dashIdx < 0) {
52
94
  break;
@@ -61,7 +103,7 @@ function* candidatePermutations(candidate) {
61
103
  }
62
104
  }
63
105
  function applyPrefix(matches, context) {
64
- if (matches.length === 0 || context.tailwindConfig.prefix === '') {
106
+ if (matches.length === 0 || context.tailwindConfig.prefix === "") {
65
107
  return matches;
66
108
  }
67
109
  for (let match of matches){
@@ -78,7 +120,7 @@ function applyPrefix(matches, context) {
78
120
  // have to ensure that the generated selector matches the candidate
79
121
  // Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
80
122
  // The disconnect between candidate <-> class can cause @apply to hard crash.
81
- let shouldPrependNegative = classCandidate.startsWith('-');
123
+ let shouldPrependNegative = classCandidate.startsWith("-");
82
124
  r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
83
125
  });
84
126
  match[1] = container.nodes[0];
@@ -86,7 +128,7 @@ function applyPrefix(matches, context) {
86
128
  }
87
129
  return matches;
88
130
  }
89
- function applyImportant(matches) {
131
+ function applyImportant(matches, classCandidate) {
90
132
  if (matches.length === 0) {
91
133
  return matches;
92
134
  }
@@ -99,10 +141,12 @@ function applyImportant(matches) {
99
141
  });
100
142
  container.walkRules((r)=>{
101
143
  r.selector = (0, _pluginUtils).updateAllClasses(r.selector, (className)=>{
102
- return `!${className}`;
144
+ if (className === classCandidate) {
145
+ return `!${className}`;
146
+ }
147
+ return className;
103
148
  });
104
- r.walkDecls((d)=>d.important = true
105
- );
149
+ r.walkDecls((d)=>d.important = true);
106
150
  });
107
151
  result.push([
108
152
  {
@@ -126,12 +170,34 @@ function applyVariant(variant, matches, context) {
126
170
  if (matches.length === 0) {
127
171
  return matches;
128
172
  }
173
+ let args;
174
+ // Find partial arbitrary variants
175
+ if (variant.endsWith("]") && !variant.startsWith("[")) {
176
+ args = variant.slice(variant.lastIndexOf("[") + 1, -1);
177
+ variant = variant.slice(0, variant.indexOf(args) - 1 /* - */ - 1 /* [ */ );
178
+ }
179
+ // Register arbitrary variants
180
+ if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
181
+ let selector = (0, _dataTypes).normalize(variant.slice(1, -1));
182
+ if (!(0, _setupContextUtils).isValidVariantFormatString(selector)) {
183
+ return [];
184
+ }
185
+ let fn = (0, _setupContextUtils).parseVariant(selector);
186
+ let sort = Array.from(context.variantOrder.values()).pop() << 1n;
187
+ context.variantMap.set(variant, [
188
+ [
189
+ sort,
190
+ fn
191
+ ]
192
+ ]);
193
+ context.variantOrder.set(variant, sort);
194
+ }
129
195
  if (context.variantMap.has(variant)) {
130
- let variantFunctionTuples = context.variantMap.get(variant);
196
+ let variantFunctionTuples = context.variantMap.get(variant).slice();
131
197
  let result = [];
132
198
  for (let [meta, rule1] of matches){
133
199
  // Don't generate variants for user css
134
- if (meta.layer === 'user') {
200
+ if (meta.layer === "user") {
135
201
  continue;
136
202
  }
137
203
  let container = _postcss.default.root({
@@ -145,13 +211,12 @@ function applyVariant(variant, matches, context) {
145
211
  let originals = new Map();
146
212
  function prepareBackup() {
147
213
  if (originals.size > 0) return; // Already prepared, chicken out
148
- clone.walkRules((rule)=>originals.set(rule, rule.selector)
149
- );
214
+ clone.walkRules((rule)=>originals.set(rule, rule.selector));
150
215
  }
151
216
  function modifySelectors(modifierFunction) {
152
217
  prepareBackup();
153
218
  clone.each((rule)=>{
154
- if (rule.type !== 'rule') {
219
+ if (rule.type !== "rule") {
155
220
  return;
156
221
  }
157
222
  rule.selectors = rule.selectors.map((selector)=>{
@@ -182,9 +247,29 @@ function applyVariant(variant, matches, context) {
182
247
  },
183
248
  format (selectorFormat) {
184
249
  collectedFormats.push(selectorFormat);
185
- }
250
+ },
251
+ args
186
252
  });
187
- if (typeof ruleWithVariant === 'string') {
253
+ // It can happen that a list of format strings is returned from within the function. In that
254
+ // case, we have to process them as well. We can use the existing `variantSort`.
255
+ if (Array.isArray(ruleWithVariant)) {
256
+ for (let [idx, variantFunction] of ruleWithVariant.entries()){
257
+ // This is a little bit scary since we are pushing to an array of items that we are
258
+ // currently looping over. However, you can also think of it like a processing queue
259
+ // where you keep handling jobs until everything is done and each job can queue more
260
+ // jobs if needed.
261
+ variantFunctionTuples.push([
262
+ // TODO: This could have potential bugs if we shift the sort order from variant A far
263
+ // enough into the sort space of variant B. The chances are low, but if this happens
264
+ // then this might be the place too look at. One potential solution to this problem is
265
+ // reserving additional X places for these 'unknown' variants in between.
266
+ variantSort | BigInt(idx << ruleWithVariant.length),
267
+ variantFunction,
268
+ ]);
269
+ }
270
+ continue;
271
+ }
272
+ if (typeof ruleWithVariant === "string") {
188
273
  collectedFormats.push(ruleWithVariant);
189
274
  }
190
275
  if (ruleWithVariant === null) {
@@ -219,7 +304,7 @@ function applyVariant(variant, matches, context) {
219
304
  // modified (by plugin): .foo .foo\\:markdown > p
220
305
  // rebuiltBase (internal): .foo\\:markdown > p
221
306
  // format: .foo &
222
- collectedFormats.push(modified.replace(rebuiltBase, '&'));
307
+ collectedFormats.push(modified.replace(rebuiltBase, "&"));
223
308
  rule.selector = before;
224
309
  });
225
310
  }
@@ -280,17 +365,27 @@ function isValidPropName(name) {
280
365
  */ function looksLikeUri(declaration) {
281
366
  // Quick bailout for obvious non-urls
282
367
  // This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
283
- if (!declaration.includes('://')) {
368
+ if (!declaration.includes("://")) {
284
369
  return false;
285
370
  }
286
371
  try {
287
372
  const url = new URL(declaration);
288
- return url.scheme !== '' && url.host !== '';
373
+ return url.scheme !== "" && url.host !== "";
289
374
  } catch (err) {
290
375
  // Definitely not a valid url
291
376
  return false;
292
377
  }
293
378
  }
379
+ function isParsableNode(node) {
380
+ let isParsable = true;
381
+ node.walkDecls((decl)=>{
382
+ if (!isParsableCssValue(decl.name, decl.value)) {
383
+ isParsable = false;
384
+ return false;
385
+ }
386
+ });
387
+ return isParsable;
388
+ }
294
389
  function isParsableCssValue(property, value) {
295
390
  // We don't want to to treat [https://example.com] as a custom property
296
391
  // Even though, according to the CSS grammar, it's a totally valid CSS declaration
@@ -325,14 +420,13 @@ function extractArbitraryProperty(classCandidate, context) {
325
420
  [
326
421
  {
327
422
  sort: context.arbitraryPropertiesSort,
328
- layer: 'utilities'
423
+ layer: "utilities"
329
424
  },
330
425
  ()=>({
331
426
  [(0, _nameClass).asClass(classCandidate)]: {
332
427
  [property]: normalized
333
428
  }
334
- })
335
- ,
429
+ }),
336
430
  ],
337
431
  ];
338
432
  }
@@ -340,29 +434,30 @@ function* resolveMatchedPlugins(classCandidate, context) {
340
434
  if (context.candidateRuleMap.has(classCandidate)) {
341
435
  yield [
342
436
  context.candidateRuleMap.get(classCandidate),
343
- 'DEFAULT'
437
+ "DEFAULT"
344
438
  ];
345
439
  }
346
- yield* (function*(arbitraryPropertyRule) {
440
+ yield* function*(arbitraryPropertyRule) {
347
441
  if (arbitraryPropertyRule !== null) {
348
442
  yield [
349
443
  arbitraryPropertyRule,
350
- 'DEFAULT'
444
+ "DEFAULT"
351
445
  ];
352
446
  }
353
- })(extractArbitraryProperty(classCandidate, context));
447
+ }(extractArbitraryProperty(classCandidate, context));
354
448
  let candidatePrefix = classCandidate;
355
449
  let negative = false;
356
450
  const twConfigPrefix = context.tailwindConfig.prefix;
357
451
  const twConfigPrefixLen = twConfigPrefix.length;
358
- if (candidatePrefix[twConfigPrefixLen] === '-') {
452
+ const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
453
+ if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
359
454
  negative = true;
360
455
  candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
361
456
  }
362
457
  if (negative && context.candidateRuleMap.has(candidatePrefix)) {
363
458
  yield [
364
459
  context.candidateRuleMap.get(candidatePrefix),
365
- '-DEFAULT'
460
+ "-DEFAULT"
366
461
  ];
367
462
  }
368
463
  for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
@@ -375,7 +470,12 @@ function* resolveMatchedPlugins(classCandidate, context) {
375
470
  }
376
471
  }
377
472
  function splitWithSeparator(input, separator) {
378
- return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'));
473
+ if (input === sharedState.NOT_ON_DEMAND) {
474
+ return [
475
+ sharedState.NOT_ON_DEMAND
476
+ ];
477
+ }
478
+ return Array.from((0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(input, separator));
379
479
  }
380
480
  function* recordCandidates(matches, classCandidate) {
381
481
  for (const match of matches){
@@ -386,14 +486,22 @@ function* recordCandidates(matches, classCandidate) {
386
486
  yield match;
387
487
  }
388
488
  }
389
- function* resolveMatches(candidate, context) {
489
+ function* resolveMatches(candidate, context, original = candidate) {
390
490
  let separator = context.tailwindConfig.separator;
391
491
  let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
392
492
  let important = false;
393
- if (classCandidate.startsWith('!')) {
493
+ if (classCandidate.startsWith("!")) {
394
494
  important = true;
395
495
  classCandidate = classCandidate.slice(1);
396
496
  }
497
+ if ((0, _featureFlags).flagEnabled(context.tailwindConfig, "variantGrouping")) {
498
+ if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
499
+ let base = variants.slice().reverse().join(separator);
500
+ for (let part of (0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(classCandidate.slice(1, -1), ",")){
501
+ yield* resolveMatches(base + separator + part, context, original);
502
+ }
503
+ }
504
+ }
397
505
  // TODO: Reintroduce this in ways that doesn't break on false positives
398
506
  // function sortAgainst(toSort, against) {
399
507
  // return toSort.slice().sort((a, z) => {
@@ -412,7 +520,7 @@ function* resolveMatches(candidate, context) {
412
520
  let isOnlyPlugin = plugins.length === 1;
413
521
  for (let [sort, plugin] of plugins){
414
522
  let matchesPerPlugin = [];
415
- if (typeof plugin === 'function') {
523
+ if (typeof plugin === "function") {
416
524
  for (let ruleSet of [].concat(plugin(modifier, {
417
525
  isOnlyPlugin
418
526
  }))){
@@ -430,7 +538,7 @@ function* resolveMatches(candidate, context) {
430
538
  ]);
431
539
  }
432
540
  }
433
- } else if (modifier === 'DEFAULT' || modifier === '-DEFAULT') {
541
+ } else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
434
542
  let ruleSet = plugin;
435
543
  let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
436
544
  for (let rule of rules){
@@ -452,54 +560,52 @@ function* resolveMatches(candidate, context) {
452
560
  matches.push(matchesPerPlugin);
453
561
  }
454
562
  }
455
- // Only keep the result of the very first plugin if we are dealing with
456
- // arbitrary values, to protect against ambiguity.
457
- if (isArbitraryValue(modifier) && matches.length > 1) {
458
- var ref1;
459
- let typesPerPlugin = matches.map((match)=>new Set([
460
- ...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
461
- ])
462
- );
463
- // Remove duplicates, so that we can detect proper unique types for each plugin.
464
- for (let pluginTypes of typesPerPlugin){
465
- for (let type of pluginTypes){
466
- let removeFromOwnGroup = false;
467
- for (let otherGroup of typesPerPlugin){
468
- if (pluginTypes === otherGroup) continue;
469
- if (otherGroup.has(type)) {
470
- otherGroup.delete(type);
471
- removeFromOwnGroup = true;
563
+ if (isArbitraryValue(modifier)) {
564
+ // When generated arbitrary values are ambiguous, we can't know
565
+ // which to pick so don't generate any utilities for them
566
+ if (matches.length > 1) {
567
+ var ref1;
568
+ let typesPerPlugin = matches.map((match)=>new Set([
569
+ ...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
570
+ ]));
571
+ // Remove duplicates, so that we can detect proper unique types for each plugin.
572
+ for (let pluginTypes of typesPerPlugin){
573
+ for (let type of pluginTypes){
574
+ let removeFromOwnGroup = false;
575
+ for (let otherGroup of typesPerPlugin){
576
+ if (pluginTypes === otherGroup) continue;
577
+ if (otherGroup.has(type)) {
578
+ otherGroup.delete(type);
579
+ removeFromOwnGroup = true;
580
+ }
472
581
  }
582
+ if (removeFromOwnGroup) pluginTypes.delete(type);
473
583
  }
474
- if (removeFromOwnGroup) pluginTypes.delete(type);
475
584
  }
476
- }
477
- let messages = [];
478
- for (let [idx, group] of typesPerPlugin.entries()){
479
- for (let type of group){
480
- let rules = matches[idx].map(([, rule])=>rule
481
- ).flat().map((rule)=>rule.toString().split('\n').slice(1, -1) // Remove selector and closing '}'
482
- .map((line)=>line.trim()
483
- ).map((x)=>` ${x}`
484
- ) // Re-indent
485
- .join('\n')
486
- ).join('\n\n');
487
- messages.push(` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``);
488
- break;
585
+ let messages = [];
586
+ for (let [idx, group] of typesPerPlugin.entries()){
587
+ for (let type of group){
588
+ let rules = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
589
+ .map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
590
+ .join("\n")).join("\n\n");
591
+ messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
592
+ break;
593
+ }
489
594
  }
595
+ _log.default.warn([
596
+ `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
597
+ ...messages,
598
+ `If this is content and not a class, replace it with \`${candidate.replace("[", "&lsqb;").replace("]", "&rsqb;")}\` to silence this warning.`,
599
+ ]);
600
+ continue;
490
601
  }
491
- _log.default.warn([
492
- `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
493
- ...messages,
494
- `If this is content and not a class, replace it with \`${candidate.replace('[', '&lsqb;').replace(']', '&rsqb;')}\` to silence this warning.`,
495
- ]);
496
- continue;
602
+ matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
497
603
  }
498
604
  matches = matches.flat();
499
605
  matches = Array.from(recordCandidates(matches, classCandidate));
500
606
  matches = applyPrefix(matches, context);
501
607
  if (important) {
502
- matches = applyImportant(matches, context);
608
+ matches = applyImportant(matches, classCandidate);
503
609
  }
504
610
  for (let variant of variants){
505
611
  matches = applyVariant(variant, matches, context);
@@ -511,17 +617,20 @@ function* resolveMatches(candidate, context) {
511
617
  };
512
618
  // Apply final format selector
513
619
  if (match1[0].collectedFormats) {
514
- let finalFormat = (0, _formatVariantSelector).formatVariantSelector('&', ...match1[0].collectedFormats);
620
+ let finalFormat = (0, _formatVariantSelector).formatVariantSelector("&", ...match1[0].collectedFormats);
515
621
  let container = _postcss.default.root({
516
622
  nodes: [
517
623
  match1[1].clone()
518
624
  ]
519
625
  });
520
626
  container.walkRules((rule)=>{
627
+ var ref;
521
628
  if (inKeyframes(rule)) return;
629
+ var ref2;
522
630
  rule.selector = (0, _formatVariantSelector).finalizeSelector(finalFormat, {
523
631
  selector: rule.selector,
524
- candidate,
632
+ candidate: original,
633
+ 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(),
525
634
  context
526
635
  });
527
636
  });
@@ -532,7 +641,7 @@ function* resolveMatches(candidate, context) {
532
641
  }
533
642
  }
534
643
  function inKeyframes(rule) {
535
- return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes';
644
+ return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
536
645
  }
537
646
  function generateRules(candidates, context) {
538
647
  let allRules = [];
@@ -557,13 +666,13 @@ function generateRules(candidates, context) {
557
666
  if (important === true) {
558
667
  return (rule)=>{
559
668
  rule.walkDecls((d)=>{
560
- if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
669
+ if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
561
670
  d.important = true;
562
671
  }
563
672
  });
564
673
  };
565
674
  }
566
- if (typeof important === 'string') {
675
+ if (typeof important === "string") {
567
676
  return (rule)=>{
568
677
  rule.selectors = rule.selectors.map((selector)=>{
569
678
  return `${important} ${selector}`;
@@ -595,7 +704,7 @@ function generateRules(candidates, context) {
595
704
  });
596
705
  }
597
706
  function isArbitraryValue(input) {
598
- return input.startsWith('[') && input.endsWith(']');
707
+ return input.startsWith("[") && input.endsWith("]");
599
708
  }
600
709
  exports.resolveMatches = resolveMatches;
601
710
  exports.generateRules = generateRules;
@@ -7,19 +7,6 @@ var _fs = _interopRequireDefault(require("fs"));
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
  var _resolve = _interopRequireDefault(require("resolve"));
9
9
  var _detective = _interopRequireDefault(require("detective"));
10
- function _interopRequireDefault(obj) {
11
- return obj && obj.__esModule ? obj : {
12
- default: obj
13
- };
14
- }
15
- function createModule(file) {
16
- const source = _fs.default.readFileSync(file, 'utf-8');
17
- const requires = (0, _detective).default(source);
18
- return {
19
- file,
20
- requires
21
- };
22
- }
23
10
  function getModuleDependencies(entryFile) {
24
11
  const rootModule = createModule(entryFile);
25
12
  const modules = [
@@ -30,7 +17,7 @@ function getModuleDependencies(entryFile) {
30
17
  for (const mdl of modules){
31
18
  mdl.requires.filter((dep)=>{
32
19
  // Only track local modules, not node_modules
33
- return dep.startsWith('./') || dep.startsWith('../');
20
+ return dep.startsWith("./") || dep.startsWith("../");
34
21
  }).forEach((dep)=>{
35
22
  try {
36
23
  const basedir = _path.default.dirname(mdl.file);
@@ -46,3 +33,16 @@ function getModuleDependencies(entryFile) {
46
33
  }
47
34
  return modules;
48
35
  }
36
+ function _interopRequireDefault(obj) {
37
+ return obj && obj.__esModule ? obj : {
38
+ default: obj
39
+ };
40
+ }
41
+ function createModule(file) {
42
+ const source = _fs.default.readFileSync(file, "utf-8");
43
+ const requires = (0, _detective).default(source);
44
+ return {
45
+ file,
46
+ requires
47
+ };
48
+ }
@@ -4,75 +4,70 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  exports.default = normalizeTailwindDirectives;
6
6
  var _log = _interopRequireDefault(require("../util/log"));
7
- function _interopRequireDefault(obj) {
8
- return obj && obj.__esModule ? obj : {
9
- default: obj
10
- };
11
- }
12
7
  function normalizeTailwindDirectives(root) {
13
8
  let tailwindDirectives = new Set();
14
9
  let layerDirectives = new Set();
15
10
  let applyDirectives = new Set();
16
11
  root.walkAtRules((atRule)=>{
17
- if (atRule.name === 'apply') {
12
+ if (atRule.name === "apply") {
18
13
  applyDirectives.add(atRule);
19
14
  }
20
- if (atRule.name === 'import') {
15
+ if (atRule.name === "import") {
21
16
  if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
22
- atRule.name = 'tailwind';
23
- atRule.params = 'base';
17
+ atRule.name = "tailwind";
18
+ atRule.params = "base";
24
19
  } else if (atRule.params === '"tailwindcss/components"' || atRule.params === "'tailwindcss/components'") {
25
- atRule.name = 'tailwind';
26
- atRule.params = 'components';
20
+ atRule.name = "tailwind";
21
+ atRule.params = "components";
27
22
  } else if (atRule.params === '"tailwindcss/utilities"' || atRule.params === "'tailwindcss/utilities'") {
28
- atRule.name = 'tailwind';
29
- atRule.params = 'utilities';
23
+ atRule.name = "tailwind";
24
+ atRule.params = "utilities";
30
25
  } else if (atRule.params === '"tailwindcss/screens"' || atRule.params === "'tailwindcss/screens'" || atRule.params === '"tailwindcss/variants"' || atRule.params === "'tailwindcss/variants'") {
31
- atRule.name = 'tailwind';
32
- atRule.params = 'variants';
26
+ atRule.name = "tailwind";
27
+ atRule.params = "variants";
33
28
  }
34
29
  }
35
- if (atRule.name === 'tailwind') {
36
- if (atRule.params === 'screens') {
37
- atRule.params = 'variants';
30
+ if (atRule.name === "tailwind") {
31
+ if (atRule.params === "screens") {
32
+ atRule.params = "variants";
38
33
  }
39
34
  tailwindDirectives.add(atRule.params);
40
35
  }
41
36
  if ([
42
- 'layer',
43
- 'responsive',
44
- 'variants'
37
+ "layer",
38
+ "responsive",
39
+ "variants"
45
40
  ].includes(atRule.name)) {
46
41
  if ([
47
- 'responsive',
48
- 'variants'
42
+ "responsive",
43
+ "variants"
49
44
  ].includes(atRule.name)) {
50
45
  _log.default.warn(`${atRule.name}-at-rule-deprecated`, [
51
46
  `The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
52
47
  `Use \`@layer utilities\` or \`@layer components\` instead.`,
53
- 'https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer',
48
+ "https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer",
54
49
  ]);
55
50
  }
56
51
  layerDirectives.add(atRule);
57
52
  }
58
53
  });
59
- if (!tailwindDirectives.has('base') || !tailwindDirectives.has('components') || !tailwindDirectives.has('utilities')) {
54
+ if (!tailwindDirectives.has("base") || !tailwindDirectives.has("components") || !tailwindDirectives.has("utilities")) {
60
55
  for (let rule of layerDirectives){
61
- if (rule.name === 'layer' && [
62
- 'base',
63
- 'components',
64
- 'utilities'
56
+ if (rule.name === "layer" && [
57
+ "base",
58
+ "components",
59
+ "utilities"
65
60
  ].includes(rule.params)) {
66
61
  if (!tailwindDirectives.has(rule.params)) {
67
62
  throw rule.error(`\`@layer ${rule.params}\` is used but no matching \`@tailwind ${rule.params}\` directive is present.`);
68
63
  }
69
- } else if (rule.name === 'responsive') {
70
- if (!tailwindDirectives.has('utilities')) {
71
- throw rule.error('`@responsive` is used but `@tailwind utilities` is missing.');
64
+ } else if (rule.name === "responsive") {
65
+ if (!tailwindDirectives.has("utilities")) {
66
+ throw rule.error("`@responsive` is used but `@tailwind utilities` is missing.");
72
67
  }
73
- } else if (rule.name === 'variants') {
74
- if (!tailwindDirectives.has('utilities')) {
75
- throw rule.error('`@variants` is used but `@tailwind utilities` is missing.');
68
+ } else if (rule.name === "variants") {
69
+ if (!tailwindDirectives.has("utilities")) {
70
+ throw rule.error("`@variants` is used but `@tailwind utilities` is missing.");
76
71
  }
77
72
  }
78
73
  }
@@ -82,3 +77,8 @@ function normalizeTailwindDirectives(root) {
82
77
  applyDirectives
83
78
  };
84
79
  }
80
+ function _interopRequireDefault(obj) {
81
+ return obj && obj.__esModule ? obj : {
82
+ default: obj
83
+ };
84
+ }