tailwindcss 0.0.0-insiders.bbafc8e → 0.0.0-insiders.bbf2b1b

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 (128) hide show
  1. package/CHANGELOG.md +163 -8
  2. package/README.md +6 -3
  3. package/colors.d.ts +3 -0
  4. package/defaultConfig.d.ts +3 -0
  5. package/defaultTheme.d.ts +4 -0
  6. package/lib/cli-peer-dependencies.js +20 -7
  7. package/lib/cli.js +314 -247
  8. package/lib/constants.js +27 -20
  9. package/lib/corePluginList.js +6 -3
  10. package/lib/corePlugins.js +1719 -1628
  11. package/lib/css/preflight.css +1 -8
  12. package/lib/featureFlags.js +27 -18
  13. package/lib/index.js +17 -15
  14. package/lib/lib/cacheInvalidation.js +45 -24
  15. package/lib/lib/collapseAdjacentRules.js +14 -9
  16. package/lib/lib/collapseDuplicateDeclarations.js +12 -9
  17. package/lib/lib/defaultExtractor.js +220 -33
  18. package/lib/lib/detectNesting.js +13 -10
  19. package/lib/lib/evaluateTailwindFunctions.js +101 -54
  20. package/lib/lib/expandApplyAtRules.js +254 -209
  21. package/lib/lib/expandTailwindAtRules.js +86 -69
  22. package/lib/lib/generateRules.js +244 -145
  23. package/lib/lib/getModuleDependencies.js +11 -8
  24. package/lib/lib/normalizeTailwindDirectives.js +35 -32
  25. package/lib/lib/partitionApplyAtRules.js +11 -8
  26. package/lib/lib/regex.js +60 -0
  27. package/lib/lib/resolveDefaultsAtRules.js +89 -71
  28. package/lib/lib/setupContextUtils.js +290 -205
  29. package/lib/lib/setupTrackingContext.js +44 -37
  30. package/lib/lib/sharedState.js +22 -16
  31. package/lib/lib/substituteScreenAtRules.js +11 -9
  32. package/lib/postcss-plugins/nesting/README.md +2 -2
  33. package/lib/postcss-plugins/nesting/index.js +8 -6
  34. package/lib/postcss-plugins/nesting/plugin.js +18 -16
  35. package/lib/processTailwindFeatures.js +31 -28
  36. package/lib/public/colors.js +247 -245
  37. package/lib/public/create-plugin.js +6 -4
  38. package/lib/public/default-config.js +7 -5
  39. package/lib/public/default-theme.js +7 -5
  40. package/lib/public/resolve-config.js +8 -5
  41. package/lib/util/bigSign.js +4 -1
  42. package/lib/util/buildMediaQuery.js +7 -5
  43. package/lib/util/cloneDeep.js +7 -6
  44. package/lib/util/cloneNodes.js +10 -3
  45. package/lib/util/color.js +53 -54
  46. package/lib/util/configurePlugins.js +4 -1
  47. package/lib/util/createPlugin.js +6 -5
  48. package/lib/util/createUtilityPlugin.js +9 -7
  49. package/lib/util/dataTypes.js +110 -100
  50. package/lib/util/defaults.js +4 -1
  51. package/lib/util/escapeClassName.js +7 -4
  52. package/lib/util/escapeCommas.js +5 -2
  53. package/lib/util/flattenColorPalette.js +9 -10
  54. package/lib/util/formatVariantSelector.js +100 -85
  55. package/lib/util/getAllConfigs.js +17 -8
  56. package/lib/util/hashConfig.js +6 -3
  57. package/lib/util/isKeyframeRule.js +5 -2
  58. package/lib/util/isPlainObject.js +5 -2
  59. package/lib/util/isValidArbitraryValue.js +21 -13
  60. package/lib/util/log.js +18 -12
  61. package/lib/util/nameClass.js +17 -9
  62. package/lib/util/negateValue.js +8 -6
  63. package/lib/util/normalizeConfig.js +84 -71
  64. package/lib/util/normalizeScreens.js +22 -8
  65. package/lib/util/parseAnimationValue.js +42 -40
  66. package/lib/util/parseBoxShadowValue.js +29 -62
  67. package/lib/util/parseDependency.js +18 -15
  68. package/lib/util/parseObjectStyles.js +10 -7
  69. package/lib/util/pluginUtils.js +47 -31
  70. package/lib/util/prefixSelector.js +7 -4
  71. package/lib/util/removeAlphaVariables.js +29 -0
  72. package/lib/util/resolveConfig.js +88 -84
  73. package/lib/util/resolveConfigPath.js +10 -7
  74. package/lib/util/responsive.js +8 -5
  75. package/lib/util/splitAtTopLevelOnly.js +93 -0
  76. package/lib/util/tap.js +4 -1
  77. package/lib/util/toColorValue.js +5 -2
  78. package/lib/util/toPath.js +20 -4
  79. package/lib/util/transformThemeValue.js +30 -25
  80. package/lib/util/validateConfig.js +24 -0
  81. package/lib/util/withAlphaVariable.js +23 -15
  82. package/package.json +32 -27
  83. package/peers/index.js +8612 -4245
  84. package/plugin.d.ts +11 -0
  85. package/resolveConfig.d.ts +3 -0
  86. package/scripts/generate-types.js +105 -0
  87. package/scripts/type-utils.js +27 -0
  88. package/src/cli-peer-dependencies.js +7 -1
  89. package/src/cli.js +125 -25
  90. package/src/corePluginList.js +1 -1
  91. package/src/corePlugins.js +145 -49
  92. package/src/css/preflight.css +1 -8
  93. package/src/featureFlags.js +2 -2
  94. package/src/lib/collapseAdjacentRules.js +5 -1
  95. package/src/lib/defaultExtractor.js +193 -35
  96. package/src/lib/evaluateTailwindFunctions.js +56 -6
  97. package/src/lib/expandApplyAtRules.js +252 -187
  98. package/src/lib/expandTailwindAtRules.js +4 -4
  99. package/src/lib/generateRules.js +156 -59
  100. package/src/lib/regex.js +74 -0
  101. package/src/lib/resolveDefaultsAtRules.js +53 -36
  102. package/src/lib/setupContextUtils.js +142 -46
  103. package/src/lib/setupTrackingContext.js +5 -1
  104. package/src/postcss-plugins/nesting/README.md +2 -2
  105. package/src/util/cloneNodes.js +5 -1
  106. package/src/util/color.js +25 -21
  107. package/src/util/dataTypes.js +13 -7
  108. package/src/util/formatVariantSelector.js +82 -63
  109. package/src/util/getAllConfigs.js +8 -0
  110. package/src/util/log.js +1 -1
  111. package/src/util/normalizeConfig.js +0 -8
  112. package/src/util/parseBoxShadowValue.js +3 -50
  113. package/src/util/pluginUtils.js +13 -1
  114. package/src/util/removeAlphaVariables.js +24 -0
  115. package/src/util/resolveConfig.js +66 -52
  116. package/src/util/splitAtTopLevelOnly.js +71 -0
  117. package/src/util/toPath.js +1 -1
  118. package/src/util/transformThemeValue.js +4 -2
  119. package/src/util/validateConfig.js +13 -0
  120. package/src/util/withAlphaVariable.js +1 -1
  121. package/stubs/defaultConfig.stub.js +5 -1
  122. package/stubs/simpleConfig.stub.js +1 -0
  123. package/types/config.d.ts +327 -0
  124. package/types/generated/.gitkeep +0 -0
  125. package/types/generated/colors.d.ts +276 -0
  126. package/types/generated/corePluginList.d.ts +1 -0
  127. package/types/generated/default-theme.d.ts +331 -0
  128. package/types/index.d.ts +7 -0
@@ -2,32 +2,50 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.default = expandApplyAtRules;
6
- var _postcss = _interopRequireDefault(require("postcss"));
7
- var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
8
- var _generateRules = require("./generateRules");
9
- var _bigSign = _interopRequireDefault(require("../util/bigSign"));
10
- var _escapeClassName = _interopRequireDefault(require("../util/escapeClassName"));
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>expandApplyAtRules
8
+ });
9
+ const _postcss = /*#__PURE__*/ _interopRequireDefault(require("postcss"));
10
+ const _postcssSelectorParser = /*#__PURE__*/ _interopRequireDefault(require("postcss-selector-parser"));
11
+ const _generateRules = require("./generateRules");
12
+ const _bigSign = /*#__PURE__*/ _interopRequireDefault(require("../util/bigSign"));
13
+ const _escapeClassName = /*#__PURE__*/ _interopRequireDefault(require("../util/escapeClassName"));
11
14
  function _interopRequireDefault(obj) {
12
15
  return obj && obj.__esModule ? obj : {
13
16
  default: obj
14
17
  };
15
18
  }
16
19
  /** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
17
- let classes = new Set();
20
+ /** @type {Map<string, Set<string>>} */ let groups = new Map();
18
21
  let container = _postcss.default.root({
19
22
  nodes: [
20
23
  node.clone()
21
24
  ]
22
25
  });
23
26
  container.walkRules((rule)=>{
24
- (0, _postcssSelectorParser).default((selectors)=>{
27
+ (0, _postcssSelectorParser.default)((selectors)=>{
25
28
  selectors.walkClasses((classSelector)=>{
29
+ let parentSelector = classSelector.parent.toString();
30
+ let classes = groups.get(parentSelector);
31
+ if (!classes) {
32
+ groups.set(parentSelector, classes = new Set());
33
+ }
26
34
  classes.add(classSelector.value);
27
35
  });
28
36
  }).processSync(rule.selector);
29
37
  });
30
- return Array.from(classes);
38
+ let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
39
+ let classes = normalizedGroups.flat();
40
+ return Object.assign(classes, {
41
+ groups: normalizedGroups
42
+ });
43
+ }
44
+ let selectorExtractor = (0, _postcssSelectorParser.default)((root)=>root.nodes.map((node)=>node.toString()));
45
+ /**
46
+ * @param {string} ruleSelectors
47
+ */ function extractSelectors(ruleSelectors) {
48
+ return selectorExtractor.transformSync(ruleSelectors);
31
49
  }
32
50
  function extractBaseCandidates(candidates, separator) {
33
51
  let baseClasses = new Set();
@@ -37,8 +55,8 @@ function extractBaseCandidates(candidates, separator) {
37
55
  return Array.from(baseClasses);
38
56
  }
39
57
  function prefix(context, selector) {
40
- let prefix1 = context.tailwindConfig.prefix;
41
- return typeof prefix1 === 'function' ? prefix1(selector) : prefix1 + selector;
58
+ let prefix = context.tailwindConfig.prefix;
59
+ return typeof prefix === "function" ? prefix(selector) : prefix + selector;
42
60
  }
43
61
  function* pathToRoot(node) {
44
62
  yield node;
@@ -104,7 +122,7 @@ function* pathToRoot(node) {
104
122
  if (node === parent) {
105
123
  continue;
106
124
  }
107
- if (parent.type === 'root') {
125
+ if (parent.type === "root") {
108
126
  break;
109
127
  }
110
128
  node = shallowClone(parent, {
@@ -135,7 +153,7 @@ function* pathToRoot(node) {
135
153
  cache.set(className, list);
136
154
  list.push([
137
155
  {
138
- layer: 'user',
156
+ layer: "user",
139
157
  sort: BigInt(idx) + highestOffset,
140
158
  important: false
141
159
  },
@@ -156,11 +174,10 @@ function* pathToRoot(node) {
156
174
  context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
157
175
  meta,
158
176
  rule.clone()
159
- ]
160
- ));
177
+ ]));
161
178
  continue;
162
179
  }
163
- let matches = Array.from((0, _generateRules).resolveMatches(candidate, context));
180
+ let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
164
181
  if (matches.length === 0) {
165
182
  context.notClassCache.add(candidate);
166
183
  continue;
@@ -195,16 +212,13 @@ function* pathToRoot(node) {
195
212
  * @returns {ApplyCache}
196
213
  */ function combineCaches(caches) {
197
214
  return {
198
- get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
199
- )
200
- ,
201
- has: (name)=>caches.some((cache)=>cache.has(name)
202
- )
215
+ get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
216
+ has: (name)=>caches.some((cache)=>cache.has(name))
203
217
  };
204
218
  }
205
219
  function extractApplyCandidates(params) {
206
220
  let candidates = params.split(/[\s\t\n]+/g);
207
- if (candidates[candidates.length - 1] === '!important') {
221
+ if (candidates[candidates.length - 1] === "!important") {
208
222
  return [
209
223
  candidates.slice(0, -1),
210
224
  true
@@ -219,7 +233,7 @@ function processApply(root, context, localCache) {
219
233
  let applyCandidates = new Set();
220
234
  // Collect all @apply rules and candidates
221
235
  let applies = [];
222
- root.walkAtRules('apply', (rule)=>{
236
+ root.walkAtRules("apply", (rule)=>{
223
237
  let [candidates] = extractApplyCandidates(rule.params);
224
238
  for (let util of candidates){
225
239
  applyCandidates.add(util);
@@ -227,207 +241,238 @@ function processApply(root, context, localCache) {
227
241
  applies.push(rule);
228
242
  });
229
243
  // Start the @apply process if we have rules with @apply in them
230
- if (applies.length > 0) {
231
- // Fill up some caches!
232
- let applyClassCache = combineCaches([
233
- localCache,
234
- buildApplyCache(applyCandidates, context)
235
- ]);
236
- /**
237
- * When we have an apply like this:
238
- *
239
- * .abc {
240
- * @apply hover:font-bold;
241
- * }
242
- *
243
- * What we essentially will do is resolve to this:
244
- *
245
- * .abc {
246
- * @apply .hover\:font-bold:hover {
247
- * font-weight: 500;
248
- * }
249
- * }
250
- *
251
- * Notice that the to-be-applied class is `.hover\:font-bold:hover` and that the utility candidate was `hover:font-bold`.
252
- * What happens in this function is that we prepend a `.` and escape the candidate.
253
- * This will result in `.hover\:font-bold`
254
- * Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
255
- */ // TODO: Should we use postcss-selector-parser for this instead?
256
- function replaceSelector(selector, utilitySelectors, candidate) {
257
- let needle = `.${(0, _escapeClassName).default(candidate)}`;
258
- let utilitySelectorsList = utilitySelectors.split(/\s*\,(?![^(]*\))\s*/g);
259
- return selector.split(/\s*\,(?![^(]*\))\s*/g).map((s)=>{
260
- let replaced = [];
261
- for (let utilitySelector of utilitySelectorsList){
262
- let replacedSelector = utilitySelector.replace(needle, s);
263
- if (replacedSelector === utilitySelector) {
264
- continue;
265
- }
266
- replaced.push(replacedSelector);
244
+ if (applies.length === 0) {
245
+ return;
246
+ }
247
+ // Fill up some caches!
248
+ let applyClassCache = combineCaches([
249
+ localCache,
250
+ buildApplyCache(applyCandidates, context)
251
+ ]);
252
+ /**
253
+ * When we have an apply like this:
254
+ *
255
+ * .abc {
256
+ * @apply hover:font-bold;
257
+ * }
258
+ *
259
+ * What we essentially will do is resolve to this:
260
+ *
261
+ * .abc {
262
+ * @apply .hover\:font-bold:hover {
263
+ * font-weight: 500;
264
+ * }
265
+ * }
266
+ *
267
+ * Notice that the to-be-applied class is `.hover\:font-bold:hover` and that the utility candidate was `hover:font-bold`.
268
+ * What happens in this function is that we prepend a `.` and escape the candidate.
269
+ * This will result in `.hover\:font-bold`
270
+ * Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
271
+ */ // TODO: Should we use postcss-selector-parser for this instead?
272
+ function replaceSelector(selector, utilitySelectors, candidate) {
273
+ let needle = `.${(0, _escapeClassName.default)(candidate)}`;
274
+ let needles = [
275
+ ...new Set([
276
+ needle,
277
+ needle.replace(/\\2c /g, "\\,")
278
+ ])
279
+ ];
280
+ let utilitySelectorsList = extractSelectors(utilitySelectors);
281
+ return extractSelectors(selector).map((s)=>{
282
+ let replaced = [];
283
+ for (let utilitySelector of utilitySelectorsList){
284
+ let replacedSelector = utilitySelector;
285
+ for (const needle of needles){
286
+ replacedSelector = replacedSelector.replace(needle, s);
267
287
  }
268
- return replaced.join(', ');
269
- }).join(', ');
270
- }
271
- let perParentApplies = new Map();
272
- // Collect all apply candidates and their rules
273
- for (let apply of applies){
274
- let candidates = perParentApplies.get(apply.parent) || [];
275
- perParentApplies.set(apply.parent, [
276
- candidates,
277
- apply.source
278
- ]);
279
- let [applyCandidates, important] = extractApplyCandidates(apply.params);
280
- if (apply.parent.type === 'atrule') {
281
- if (apply.parent.name === 'screen') {
282
- const screenType = apply.parent.params;
283
- throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates.map((c)=>`${screenType}:${c}`
284
- ).join(' ')} instead.`);
288
+ if (replacedSelector === utilitySelector) {
289
+ continue;
285
290
  }
286
- throw apply.error(`@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`);
291
+ replaced.push(replacedSelector);
287
292
  }
288
- for (let applyCandidate of applyCandidates){
289
- if ([
290
- prefix(context, 'group'),
291
- prefix(context, 'peer')
292
- ].includes(applyCandidate)) {
293
- // TODO: Link to specific documentation page with error code.
294
- throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
295
- }
296
- if (!applyClassCache.has(applyCandidate)) {
297
- throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
298
- }
299
- let rules = applyClassCache.get(applyCandidate);
300
- candidates.push([
301
- applyCandidate,
302
- important,
303
- rules
304
- ]);
293
+ return replaced.join(", ");
294
+ }).join(", ");
295
+ }
296
+ let perParentApplies = new Map();
297
+ // Collect all apply candidates and their rules
298
+ for (let apply of applies){
299
+ let [candidates] = perParentApplies.get(apply.parent) || [
300
+ [],
301
+ apply.source
302
+ ];
303
+ perParentApplies.set(apply.parent, [
304
+ candidates,
305
+ apply.source
306
+ ]);
307
+ let [applyCandidates1, important] = extractApplyCandidates(apply.params);
308
+ if (apply.parent.type === "atrule") {
309
+ if (apply.parent.name === "screen") {
310
+ const screenType = apply.parent.params;
311
+ throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates1.map((c)=>`${screenType}:${c}`).join(" ")} instead.`);
305
312
  }
313
+ throw apply.error(`@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`);
306
314
  }
307
- for (const [parent, [candidates, atApplySource]] of perParentApplies){
308
- let siblings = [];
309
- for (let [applyCandidate, important, rules] of candidates){
310
- for (let [meta, node1] of rules){
311
- let parentClasses = extractClasses(parent);
312
- let nodeClasses = extractClasses(node1);
313
- // Add base utility classes from the @apply node to the list of
314
- // classes to check whether it intersects and therefore results in a
315
- // circular dependency or not.
316
- //
317
- // E.g.:
318
- // .foo {
319
- // @apply hover:a; // This applies "a" but with a modifier
320
- // }
321
- //
322
- // We only have to do that with base classes of the `node`, not of the `parent`
323
- // E.g.:
324
- // .hover\:foo {
325
- // @apply bar;
326
- // }
327
- // .bar {
328
- // @apply foo;
329
- // }
330
- //
331
- // This should not result in a circular dependency because we are
332
- // just applying `.foo` and the rule above is `.hover\:foo` which is
333
- // unrelated. However, if we were to apply `hover:foo` then we _did_
334
- // have to include this one.
335
- nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
336
- let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
337
- );
338
- if (intersects) {
339
- throw node1.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
340
- }
341
- let root = _postcss.default.root({
342
- nodes: [
343
- node1.clone()
344
- ]
345
- });
346
- // Make sure every node in the entire tree points back at the @apply rule that generated it
347
- root.walk((node)=>{
348
- node.source = atApplySource;
349
- });
350
- let canRewriteSelector = node1.type !== 'atrule' || node1.type === 'atrule' && node1.name !== 'keyframes';
351
- if (canRewriteSelector) {
352
- root.walkRules((rule)=>{
353
- // Let's imagine you have the following structure:
354
- //
355
- // .foo {
356
- // @apply bar;
357
- // }
358
- //
359
- // @supports (a: b) {
360
- // .bar {
361
- // color: blue
362
- // }
363
- //
364
- // .something-unrelated {}
365
- // }
366
- //
367
- // In this case we want to apply `.bar` but it happens to be in
368
- // an atrule node. We clone that node instead of the nested one
369
- // because we still want that @supports rule to be there once we
370
- // applied everything.
371
- //
372
- // However it happens to be that the `.something-unrelated` is
373
- // also in that same shared @supports atrule. This is not good,
374
- // and this should not be there. The good part is that this is
375
- // a clone already and it can be safely removed. The question is
376
- // how do we know we can remove it. Basically what we can do is
377
- // match it against the applyCandidate that you want to apply. If
378
- // it doesn't match the we can safely delete it.
379
- //
380
- // If we didn't do this, then the `replaceSelector` function
381
- // would have replaced this with something that didn't exist and
382
- // therefore it removed the selector altogether. In this specific
383
- // case it would result in `{}` instead of `.something-unrelated {}`
384
- if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate
385
- )) {
386
- rule.remove();
387
- return;
388
- }
389
- rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate);
390
- rule.walkDecls((d)=>{
391
- d.important = meta.important || important;
392
- });
315
+ for (let applyCandidate of applyCandidates1){
316
+ if ([
317
+ prefix(context, "group"),
318
+ prefix(context, "peer")
319
+ ].includes(applyCandidate)) {
320
+ // TODO: Link to specific documentation page with error code.
321
+ throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
322
+ }
323
+ if (!applyClassCache.has(applyCandidate)) {
324
+ throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
325
+ }
326
+ let rules = applyClassCache.get(applyCandidate);
327
+ candidates.push([
328
+ applyCandidate,
329
+ important,
330
+ rules
331
+ ]);
332
+ }
333
+ }
334
+ for (const [parent, [candidates1, atApplySource]] of perParentApplies){
335
+ let siblings = [];
336
+ for (let [applyCandidate1, important1, rules1] of candidates1){
337
+ let potentialApplyCandidates = [
338
+ applyCandidate1,
339
+ ...extractBaseCandidates([
340
+ applyCandidate1
341
+ ], context.tailwindConfig.separator),
342
+ ];
343
+ for (let [meta, node] of rules1){
344
+ let parentClasses = extractClasses(parent);
345
+ let nodeClasses = extractClasses(node);
346
+ // When we encounter a rule like `.dark .a, .b { … }` we only want to be left with `[.dark, .a]` if the base applyCandidate is `.a` or with `[.b]` if the base applyCandidate is `.b`
347
+ // So we've split them into groups
348
+ nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
349
+ // Add base utility classes from the @apply node to the list of
350
+ // classes to check whether it intersects and therefore results in a
351
+ // circular dependency or not.
352
+ //
353
+ // E.g.:
354
+ // .foo {
355
+ // @apply hover:a; // This applies "a" but with a modifier
356
+ // }
357
+ //
358
+ // We only have to do that with base classes of the `node`, not of the `parent`
359
+ // E.g.:
360
+ // .hover\:foo {
361
+ // @apply bar;
362
+ // }
363
+ // .bar {
364
+ // @apply foo;
365
+ // }
366
+ //
367
+ // This should not result in a circular dependency because we are
368
+ // just applying `.foo` and the rule above is `.hover\:foo` which is
369
+ // unrelated. However, if we were to apply `hover:foo` then we _did_
370
+ // have to include this one.
371
+ nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
372
+ let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
373
+ if (intersects) {
374
+ throw node.error(`You cannot \`@apply\` the \`${applyCandidate1}\` utility here because it creates a circular dependency.`);
375
+ }
376
+ let root1 = _postcss.default.root({
377
+ nodes: [
378
+ node.clone()
379
+ ]
380
+ });
381
+ // Make sure every node in the entire tree points back at the @apply rule that generated it
382
+ root1.walk((node)=>{
383
+ node.source = atApplySource;
384
+ });
385
+ let canRewriteSelector = node.type !== "atrule" || node.type === "atrule" && node.name !== "keyframes";
386
+ if (canRewriteSelector) {
387
+ root1.walkRules((rule)=>{
388
+ // Let's imagine you have the following structure:
389
+ //
390
+ // .foo {
391
+ // @apply bar;
392
+ // }
393
+ //
394
+ // @supports (a: b) {
395
+ // .bar {
396
+ // color: blue
397
+ // }
398
+ //
399
+ // .something-unrelated {}
400
+ // }
401
+ //
402
+ // In this case we want to apply `.bar` but it happens to be in
403
+ // an atrule node. We clone that node instead of the nested one
404
+ // because we still want that @supports rule to be there once we
405
+ // applied everything.
406
+ //
407
+ // However it happens to be that the `.something-unrelated` is
408
+ // also in that same shared @supports atrule. This is not good,
409
+ // and this should not be there. The good part is that this is
410
+ // a clone already and it can be safely removed. The question is
411
+ // how do we know we can remove it. Basically what we can do is
412
+ // match it against the applyCandidate that you want to apply. If
413
+ // it doesn't match the we can safely delete it.
414
+ //
415
+ // If we didn't do this, then the `replaceSelector` function
416
+ // would have replaced this with something that didn't exist and
417
+ // therefore it removed the selector altogether. In this specific
418
+ // case it would result in `{}` instead of `.something-unrelated {}`
419
+ if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate1)) {
420
+ rule.remove();
421
+ return;
422
+ }
423
+ // Strip the important selector from the parent selector if at the beginning
424
+ let importantSelector = typeof context.tailwindConfig.important === "string" ? context.tailwindConfig.important : null;
425
+ // We only want to move the "important" selector if this is a Tailwind-generated utility
426
+ // We do *not* want to do this for user CSS that happens to be structured the same
427
+ let isGenerated = parent.raws.tailwind !== undefined;
428
+ let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
429
+ rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate1);
430
+ // And then re-add it if it was removed
431
+ if (importantSelector && parentSelector !== parent.selector) {
432
+ rule.selector = `${importantSelector} ${rule.selector}`;
433
+ }
434
+ rule.walkDecls((d)=>{
435
+ d.important = meta.important || important1;
393
436
  });
394
- }
395
- // Insert it
396
- siblings.push([
397
- // Ensure that when we are sorting, that we take the layer order into account
398
- {
399
- ...meta,
400
- sort: meta.sort | context.layerOrder[meta.layer]
401
- },
402
- root.nodes[0],
403
- ]);
437
+ });
404
438
  }
439
+ // It could be that the node we were inserted was removed because the class didn't match
440
+ // If that was the *only* rule in the parent, then we have nothing add so we skip it
441
+ if (!root1.nodes[0]) {
442
+ continue;
443
+ }
444
+ // Insert it
445
+ siblings.push([
446
+ // Ensure that when we are sorting, that we take the layer order into account
447
+ {
448
+ ...meta,
449
+ sort: meta.sort | context.layerOrder[meta.layer]
450
+ },
451
+ root1.nodes[0],
452
+ ]);
405
453
  }
406
- // Inject the rules, sorted, correctly
407
- let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)
408
- ).map((s)=>s[1]
409
- );
410
- // `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
411
- parent.after(nodes);
412
454
  }
413
- for (let apply1 of applies){
414
- // If there are left-over declarations, just remove the @apply
415
- if (apply1.parent.nodes.length > 1) {
416
- apply1.remove();
417
- } else {
418
- // The node is empty, drop the full node
419
- apply1.parent.remove();
420
- }
455
+ // Inject the rules, sorted, correctly
456
+ let nodes = siblings.sort(([a], [z])=>(0, _bigSign.default)(a.sort - z.sort)).map((s)=>s[1]);
457
+ // `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
458
+ parent.after(nodes);
459
+ }
460
+ for (let apply1 of applies){
461
+ // If there are left-over declarations, just remove the @apply
462
+ if (apply1.parent.nodes.length > 1) {
463
+ apply1.remove();
464
+ } else {
465
+ // The node is empty, drop the full node
466
+ apply1.parent.remove();
421
467
  }
422
- // Do it again, in case we have other `@apply` rules
423
- processApply(root, context, localCache);
424
468
  }
469
+ // Do it again, in case we have other `@apply` rules
470
+ processApply(root, context, localCache);
425
471
  }
426
472
  function expandApplyAtRules(context) {
427
473
  return (root)=>{
428
474
  // Build a cache of the user's CSS so we can use it to resolve classes used by @apply
429
- let localCache = lazyCache(()=>buildLocalApplyCache(root, context)
430
- );
475
+ let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
431
476
  processApply(root, context, localCache);
432
477
  };
433
478
  }