tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21

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 (161) hide show
  1. package/CHANGELOG.md +246 -6
  2. package/README.md +13 -9
  3. package/defaultTheme.d.ts +2 -1
  4. package/lib/cli/build/deps.js +54 -0
  5. package/lib/cli/build/index.js +48 -0
  6. package/lib/cli/build/plugin.js +362 -0
  7. package/lib/cli/build/utils.js +78 -0
  8. package/lib/cli/build/watching.js +178 -0
  9. package/lib/cli/help/index.js +71 -0
  10. package/lib/cli/index.js +18 -0
  11. package/lib/cli/init/index.js +46 -0
  12. package/lib/cli/shared.js +12 -0
  13. package/lib/cli-peer-dependencies.js +18 -5
  14. package/lib/cli.js +62 -592
  15. package/lib/constants.js +19 -12
  16. package/lib/corePluginList.js +5 -3
  17. package/lib/corePlugins.js +619 -347
  18. package/lib/css/preflight.css +7 -0
  19. package/lib/featureFlags.js +34 -22
  20. package/lib/index.js +16 -9
  21. package/lib/lib/cacheInvalidation.js +42 -21
  22. package/lib/lib/collapseAdjacentRules.js +16 -14
  23. package/lib/lib/collapseDuplicateDeclarations.js +13 -10
  24. package/lib/lib/content.js +177 -0
  25. package/lib/lib/defaultExtractor.js +230 -33
  26. package/lib/lib/detectNesting.js +13 -4
  27. package/lib/lib/evaluateTailwindFunctions.js +105 -42
  28. package/lib/lib/expandApplyAtRules.js +151 -92
  29. package/lib/lib/expandTailwindAtRules.js +134 -149
  30. package/lib/lib/findAtConfigPath.js +44 -0
  31. package/lib/lib/generateRules.js +404 -185
  32. package/lib/lib/getModuleDependencies.js +21 -18
  33. package/lib/lib/normalizeTailwindDirectives.js +11 -8
  34. package/lib/lib/offsets.js +285 -0
  35. package/lib/lib/partitionApplyAtRules.js +14 -11
  36. package/lib/lib/regex.js +60 -0
  37. package/lib/lib/remap-bitfield.js +87 -0
  38. package/lib/lib/resolveDefaultsAtRules.js +97 -79
  39. package/lib/lib/setupContextUtils.js +567 -242
  40. package/lib/lib/setupTrackingContext.js +77 -106
  41. package/lib/lib/sharedState.js +18 -10
  42. package/lib/lib/substituteScreenAtRules.js +9 -7
  43. package/lib/postcss-plugins/nesting/index.js +7 -5
  44. package/lib/postcss-plugins/nesting/plugin.js +10 -8
  45. package/lib/processTailwindFeatures.js +34 -31
  46. package/lib/public/colors.js +7 -5
  47. package/lib/public/create-plugin.js +6 -4
  48. package/lib/public/default-config.js +7 -5
  49. package/lib/public/default-theme.js +7 -5
  50. package/lib/public/resolve-config.js +13 -10
  51. package/lib/util/bigSign.js +4 -1
  52. package/lib/util/buildMediaQuery.js +10 -5
  53. package/lib/util/cloneDeep.js +6 -5
  54. package/lib/util/cloneNodes.js +9 -2
  55. package/lib/util/color.js +20 -17
  56. package/lib/util/configurePlugins.js +5 -2
  57. package/lib/util/createPlugin.js +6 -5
  58. package/lib/util/createUtilityPlugin.js +15 -13
  59. package/lib/util/dataTypes.js +75 -51
  60. package/lib/util/defaults.js +8 -5
  61. package/lib/util/escapeClassName.js +13 -10
  62. package/lib/util/escapeCommas.js +4 -1
  63. package/lib/util/flattenColorPalette.js +7 -8
  64. package/lib/util/formatVariantSelector.js +270 -103
  65. package/lib/util/getAllConfigs.js +34 -15
  66. package/lib/util/hashConfig.js +10 -7
  67. package/lib/util/isKeyframeRule.js +4 -1
  68. package/lib/util/isPlainObject.js +4 -1
  69. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +34 -26
  70. package/lib/util/log.js +14 -8
  71. package/lib/util/nameClass.js +19 -8
  72. package/lib/util/negateValue.js +20 -5
  73. package/lib/util/normalizeConfig.js +94 -53
  74. package/lib/util/normalizeScreens.js +115 -4
  75. package/lib/util/parseAnimationValue.js +43 -41
  76. package/lib/util/parseBoxShadowValue.js +12 -45
  77. package/lib/util/parseDependency.js +37 -55
  78. package/lib/util/parseGlob.js +34 -0
  79. package/lib/util/parseObjectStyles.js +15 -12
  80. package/lib/util/pluginUtils.js +146 -42
  81. package/lib/util/prefixSelector.js +26 -9
  82. package/lib/util/removeAlphaVariables.js +29 -0
  83. package/lib/util/resolveConfig.js +104 -105
  84. package/lib/util/resolveConfigPath.js +20 -17
  85. package/lib/util/responsive.js +12 -9
  86. package/lib/util/splitAtTopLevelOnly.js +43 -0
  87. package/lib/util/tap.js +4 -1
  88. package/lib/util/toColorValue.js +4 -1
  89. package/lib/util/toPath.js +18 -2
  90. package/lib/util/transformThemeValue.js +23 -11
  91. package/lib/util/validateConfig.js +24 -0
  92. package/lib/util/validateFormalSyntax.js +24 -0
  93. package/lib/util/withAlphaVariable.js +32 -24
  94. package/package.json +32 -29
  95. package/peers/index.js +6693 -3036
  96. package/plugin.d.ts +10 -5
  97. package/resolveConfig.d.ts +12 -0
  98. package/scripts/generate-types.js +53 -0
  99. package/scripts/release-channel.js +18 -0
  100. package/scripts/release-notes.js +21 -0
  101. package/scripts/type-utils.js +27 -0
  102. package/src/cli/build/deps.js +56 -0
  103. package/src/cli/build/index.js +49 -0
  104. package/src/cli/build/plugin.js +434 -0
  105. package/src/cli/build/utils.js +76 -0
  106. package/src/cli/build/watching.js +227 -0
  107. package/src/cli/help/index.js +70 -0
  108. package/src/cli/index.js +3 -0
  109. package/src/cli/init/index.js +50 -0
  110. package/src/cli/shared.js +5 -0
  111. package/src/cli-peer-dependencies.js +7 -1
  112. package/src/cli.js +46 -659
  113. package/src/corePlugins.js +346 -79
  114. package/src/css/preflight.css +7 -0
  115. package/src/featureFlags.js +12 -2
  116. package/src/index.js +5 -0
  117. package/src/lib/content.js +213 -0
  118. package/src/lib/defaultExtractor.js +202 -35
  119. package/src/lib/detectNesting.js +9 -1
  120. package/src/lib/evaluateTailwindFunctions.js +78 -7
  121. package/src/lib/expandApplyAtRules.js +129 -34
  122. package/src/lib/expandTailwindAtRules.js +12 -50
  123. package/src/lib/findAtConfigPath.js +48 -0
  124. package/src/lib/generateRules.js +379 -126
  125. package/src/lib/offsets.js +351 -0
  126. package/src/lib/regex.js +74 -0
  127. package/src/lib/remap-bitfield.js +82 -0
  128. package/src/lib/resolveDefaultsAtRules.js +53 -36
  129. package/src/lib/setupContextUtils.js +510 -120
  130. package/src/lib/setupTrackingContext.js +8 -45
  131. package/src/lib/sharedState.js +2 -0
  132. package/src/util/buildMediaQuery.js +5 -3
  133. package/src/util/cloneNodes.js +5 -1
  134. package/src/util/dataTypes.js +51 -26
  135. package/src/util/formatVariantSelector.js +317 -101
  136. package/src/util/getAllConfigs.js +19 -0
  137. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  138. package/src/util/log.js +1 -1
  139. package/src/util/nameClass.js +4 -0
  140. package/src/util/negateValue.js +10 -2
  141. package/src/util/normalizeConfig.js +40 -10
  142. package/src/util/normalizeScreens.js +99 -4
  143. package/src/util/parseBoxShadowValue.js +3 -50
  144. package/src/util/parseDependency.js +37 -42
  145. package/src/util/parseGlob.js +24 -0
  146. package/src/util/pluginUtils.js +132 -10
  147. package/src/util/prefixSelector.js +28 -10
  148. package/src/util/removeAlphaVariables.js +24 -0
  149. package/src/util/resolveConfig.js +70 -62
  150. package/src/util/splitAtTopLevelOnly.js +45 -0
  151. package/src/util/toPath.js +1 -1
  152. package/src/util/transformThemeValue.js +13 -3
  153. package/src/util/validateConfig.js +13 -0
  154. package/src/util/validateFormalSyntax.js +34 -0
  155. package/src/util/withAlphaVariable.js +1 -1
  156. package/stubs/defaultConfig.stub.js +165 -164
  157. package/stubs/simpleConfig.stub.js +1 -0
  158. package/types/config.d.ts +77 -37
  159. package/types/generated/default-theme.d.ts +342 -0
  160. package/types/index.d.ts +7 -1
  161. package/types.d.ts +0 -1
@@ -2,20 +2,14 @@
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"));
11
- function expandApplyAtRules(context) {
12
- return (root)=>{
13
- // Build a cache of the user's CSS so we can use it to resolve classes used by @apply
14
- let localCache = lazyCache(()=>buildLocalApplyCache(root, context)
15
- );
16
- processApply(root, context, localCache);
17
- };
18
- }
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 _escapeClassName = /*#__PURE__*/ _interopRequireDefault(require("../util/escapeClassName"));
19
13
  function _interopRequireDefault(obj) {
20
14
  return obj && obj.__esModule ? obj : {
21
15
  default: obj
@@ -29,7 +23,7 @@ function _interopRequireDefault(obj) {
29
23
  ]
30
24
  });
31
25
  container.walkRules((rule)=>{
32
- (0, _postcssSelectorParser).default((selectors)=>{
26
+ (0, _postcssSelectorParser.default)((selectors)=>{
33
27
  selectors.walkClasses((classSelector)=>{
34
28
  let parentSelector = classSelector.parent.toString();
35
29
  let classes = groups.get(parentSelector);
@@ -40,13 +34,18 @@ function _interopRequireDefault(obj) {
40
34
  });
41
35
  }).processSync(rule.selector);
42
36
  });
43
- let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes)
44
- );
45
- let classes1 = normalizedGroups.flat();
46
- return Object.assign(classes1, {
37
+ let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
38
+ let classes = normalizedGroups.flat();
39
+ return Object.assign(classes, {
47
40
  groups: normalizedGroups
48
41
  });
49
42
  }
43
+ let selectorExtractor = (0, _postcssSelectorParser.default)();
44
+ /**
45
+ * @param {string} ruleSelectors
46
+ */ function extractSelectors(ruleSelectors) {
47
+ return selectorExtractor.astSync(ruleSelectors);
48
+ }
50
49
  function extractBaseCandidates(candidates, separator) {
51
50
  let baseClasses = new Set();
52
51
  for (let candidate of candidates){
@@ -55,8 +54,8 @@ function extractBaseCandidates(candidates, separator) {
55
54
  return Array.from(baseClasses);
56
55
  }
57
56
  function prefix(context, selector) {
58
- let prefix1 = context.tailwindConfig.prefix;
59
- return typeof prefix1 === "function" ? prefix1(selector) : prefix1 + selector;
57
+ let prefix = context.tailwindConfig.prefix;
58
+ return typeof prefix === "function" ? prefix(selector) : prefix + selector;
60
59
  }
61
60
  function* pathToRoot(node) {
62
61
  yield node;
@@ -137,27 +136,27 @@ function* pathToRoot(node) {
137
136
  * @param {import('postcss').Root} root
138
137
  */ function buildLocalApplyCache(root, context) {
139
138
  /** @type {ApplyCache} */ let cache = new Map();
140
- let highestOffset = context.layerOrder.user >> 4n;
141
- root.walkRules((rule, idx)=>{
139
+ root.walkRules((rule)=>{
142
140
  // Ignore rules generated by Tailwind
143
141
  for (let node of pathToRoot(rule)){
144
- var ref;
145
- if (((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.layer) !== undefined) {
142
+ var _node_raws_tailwind;
143
+ if (((_node_raws_tailwind = node.raws.tailwind) === null || _node_raws_tailwind === void 0 ? void 0 : _node_raws_tailwind.layer) !== undefined) {
146
144
  return;
147
145
  }
148
146
  }
149
147
  // Clone what's required to represent this singular rule in the tree
150
148
  let container = nestedClone(rule);
149
+ let sort = context.offsets.create("user");
151
150
  for (let className of extractClasses(rule)){
152
151
  let list = cache.get(className) || [];
153
152
  cache.set(className, list);
154
153
  list.push([
155
154
  {
156
155
  layer: "user",
157
- sort: BigInt(idx) + highestOffset,
156
+ sort,
158
157
  important: false
159
158
  },
160
- container,
159
+ container
161
160
  ]);
162
161
  }
163
162
  });
@@ -174,11 +173,10 @@ function* pathToRoot(node) {
174
173
  context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
175
174
  meta,
176
175
  rule.clone()
177
- ]
178
- ));
176
+ ]));
179
177
  continue;
180
178
  }
181
- let matches = Array.from((0, _generateRules).resolveMatches(candidate, context));
179
+ let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
182
180
  if (matches.length === 0) {
183
181
  context.notClassCache.add(candidate);
184
182
  continue;
@@ -213,11 +211,8 @@ function* pathToRoot(node) {
213
211
  * @returns {ApplyCache}
214
212
  */ function combineCaches(caches) {
215
213
  return {
216
- get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
217
- )
218
- ,
219
- has: (name)=>caches.some((cache)=>cache.has(name)
220
- )
214
+ get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
215
+ has: (name)=>caches.some((cache)=>cache.has(name))
221
216
  };
222
217
  }
223
218
  function extractApplyCandidates(params) {
@@ -272,30 +267,83 @@ function processApply(root, context, localCache) {
272
267
  * What happens in this function is that we prepend a `.` and escape the candidate.
273
268
  * This will result in `.hover\:font-bold`
274
269
  * Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
275
- */ // TODO: Should we use postcss-selector-parser for this instead?
276
- function replaceSelector(selector, utilitySelectors, candidate) {
277
- let needle1 = `.${(0, _escapeClassName).default(candidate)}`;
278
- let needles = [
279
- ...new Set([
280
- needle1,
281
- needle1.replace(/\\2c /g, "\\,")
282
- ])
283
- ];
284
- let utilitySelectorsList = utilitySelectors.split(/\s*(?<!\\)\,(?![^(]*\))\s*/g);
285
- return selector.split(/\s*(?<!\\)\,(?![^(]*\))\s*/g).map((s)=>{
286
- let replaced = [];
287
- for (let utilitySelector of utilitySelectorsList){
288
- let replacedSelector = utilitySelector;
289
- for (const needle of needles){
290
- replacedSelector = replacedSelector.replace(needle, s);
270
+ *
271
+ * @param {string} selector
272
+ * @param {string} utilitySelectors
273
+ * @param {string} candidate
274
+ */ function replaceSelector(selector, utilitySelectors, candidate) {
275
+ let selectorList = extractSelectors(selector);
276
+ let utilitySelectorsList = extractSelectors(utilitySelectors);
277
+ let candidateList = extractSelectors(`.${(0, _escapeClassName.default)(candidate)}`);
278
+ let candidateClass = candidateList.nodes[0].nodes[0];
279
+ selectorList.each((sel)=>{
280
+ /** @type {Set<import('postcss-selector-parser').Selector>} */ let replaced = new Set();
281
+ utilitySelectorsList.each((utilitySelector)=>{
282
+ let hasReplaced = false;
283
+ utilitySelector = utilitySelector.clone();
284
+ utilitySelector.walkClasses((node)=>{
285
+ if (node.value !== candidateClass.value) {
286
+ return;
287
+ }
288
+ // Don't replace multiple instances of the same class
289
+ // This is theoretically correct but only partially
290
+ // We'd need to generate every possible permutation of the replacement
291
+ // For example with `.foo + .foo { … }` and `section { @apply foo; }`
292
+ // We'd need to generate all of these:
293
+ // - `.foo + .foo`
294
+ // - `.foo + section`
295
+ // - `section + .foo`
296
+ // - `section + section`
297
+ if (hasReplaced) {
298
+ return;
299
+ }
300
+ // Since you can only `@apply` class names this is sufficient
301
+ // We want to replace the matched class name with the selector the user is using
302
+ // Ex: Replace `.text-blue-500` with `.foo.bar:is(.something-cool)`
303
+ node.replaceWith(...sel.nodes.map((node)=>node.clone()));
304
+ // Record that we did something and we want to use this new selector
305
+ replaced.add(utilitySelector);
306
+ hasReplaced = true;
307
+ });
308
+ });
309
+ // Sort tag names before class names (but only sort each group (separated by a combinator)
310
+ // separately and not in total)
311
+ // This happens when replacing `.bar` in `.foo.bar` with a tag like `section`
312
+ for (let sel1 of replaced){
313
+ let groups = [
314
+ []
315
+ ];
316
+ for (let node of sel1.nodes){
317
+ if (node.type === "combinator") {
318
+ groups.push(node);
319
+ groups.push([]);
320
+ } else {
321
+ let last = groups[groups.length - 1];
322
+ last.push(node);
323
+ }
291
324
  }
292
- if (replacedSelector === utilitySelector) {
293
- continue;
325
+ sel1.nodes = [];
326
+ for (let group of groups){
327
+ if (Array.isArray(group)) {
328
+ group.sort((a, b)=>{
329
+ if (a.type === "tag" && b.type === "class") {
330
+ return -1;
331
+ } else if (a.type === "class" && b.type === "tag") {
332
+ return 1;
333
+ } else if (a.type === "class" && b.type === "pseudo" && b.value.startsWith("::")) {
334
+ return -1;
335
+ } else if (a.type === "pseudo" && a.value.startsWith("::") && b.type === "class") {
336
+ return 1;
337
+ }
338
+ return 0;
339
+ });
340
+ }
341
+ sel1.nodes = sel1.nodes.concat(group);
294
342
  }
295
- replaced.push(replacedSelector);
296
343
  }
297
- return replaced.join(", ");
298
- }).join(", ");
344
+ sel.replaceWith(...replaced);
345
+ });
346
+ return selectorList.toString();
299
347
  }
300
348
  let perParentApplies = new Map();
301
349
  // Collect all apply candidates and their rules
@@ -308,16 +356,15 @@ function processApply(root, context, localCache) {
308
356
  candidates,
309
357
  apply.source
310
358
  ]);
311
- let [applyCandidates, important] = extractApplyCandidates(apply.params);
359
+ let [applyCandidates1, important] = extractApplyCandidates(apply.params);
312
360
  if (apply.parent.type === "atrule") {
313
361
  if (apply.parent.name === "screen") {
314
- const screenType = apply.parent.params;
315
- 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}`
316
- ).join(" ")} instead.`);
362
+ let screenType = apply.parent.params;
363
+ 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.`);
317
364
  }
318
365
  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}.`);
319
366
  }
320
- for (let applyCandidate of applyCandidates){
367
+ for (let applyCandidate of applyCandidates1){
321
368
  if ([
322
369
  prefix(context, "group"),
323
370
  prefix(context, "peer")
@@ -336,23 +383,21 @@ function processApply(root, context, localCache) {
336
383
  ]);
337
384
  }
338
385
  }
339
- for (const [parent, [candidates1, atApplySource]] of perParentApplies){
386
+ for (let [parent, [candidates1, atApplySource]] of perParentApplies){
340
387
  let siblings = [];
341
- for (let [applyCandidate, important, rules] of candidates1){
388
+ for (let [applyCandidate1, important1, rules1] of candidates1){
342
389
  let potentialApplyCandidates = [
343
- applyCandidate,
390
+ applyCandidate1,
344
391
  ...extractBaseCandidates([
345
- applyCandidate
346
- ], context.tailwindConfig.separator),
392
+ applyCandidate1
393
+ ], context.tailwindConfig.separator)
347
394
  ];
348
- for (let [meta, node1] of rules){
395
+ for (let [meta, node] of rules1){
349
396
  let parentClasses = extractClasses(parent);
350
- let nodeClasses = extractClasses(node1);
397
+ let nodeClasses = extractClasses(node);
351
398
  // 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`
352
399
  // So we've split them into groups
353
- nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className)
354
- )
355
- ).flat();
400
+ nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
356
401
  // Add base utility classes from the @apply node to the list of
357
402
  // classes to check whether it intersects and therefore results in a
358
403
  // circular dependency or not.
@@ -376,23 +421,22 @@ function processApply(root, context, localCache) {
376
421
  // unrelated. However, if we were to apply `hover:foo` then we _did_
377
422
  // have to include this one.
378
423
  nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
379
- let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
380
- );
424
+ let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
381
425
  if (intersects) {
382
- throw node1.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
426
+ throw node.error(`You cannot \`@apply\` the \`${applyCandidate1}\` utility here because it creates a circular dependency.`);
383
427
  }
384
- let root = _postcss.default.root({
428
+ let root1 = _postcss.default.root({
385
429
  nodes: [
386
- node1.clone()
430
+ node.clone()
387
431
  ]
388
432
  });
389
433
  // Make sure every node in the entire tree points back at the @apply rule that generated it
390
- root.walk((node)=>{
434
+ root1.walk((node)=>{
391
435
  node.source = atApplySource;
392
436
  });
393
- let canRewriteSelector = node1.type !== "atrule" || node1.type === "atrule" && node1.name !== "keyframes";
437
+ let canRewriteSelector = node.type !== "atrule" || node.type === "atrule" && node.name !== "keyframes";
394
438
  if (canRewriteSelector) {
395
- root.walkRules((rule)=>{
439
+ root1.walkRules((rule)=>{
396
440
  // Let's imagine you have the following structure:
397
441
  //
398
442
  // .foo {
@@ -424,32 +468,40 @@ function processApply(root, context, localCache) {
424
468
  // would have replaced this with something that didn't exist and
425
469
  // therefore it removed the selector altogether. In this specific
426
470
  // case it would result in `{}` instead of `.something-unrelated {}`
427
- if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate
428
- )) {
471
+ if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate1)) {
429
472
  rule.remove();
430
473
  return;
431
474
  }
432
- rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate);
475
+ // Strip the important selector from the parent selector if at the beginning
476
+ let importantSelector = typeof context.tailwindConfig.important === "string" ? context.tailwindConfig.important : null;
477
+ // We only want to move the "important" selector if this is a Tailwind-generated utility
478
+ // We do *not* want to do this for user CSS that happens to be structured the same
479
+ let isGenerated = parent.raws.tailwind !== undefined;
480
+ let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
481
+ rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate1);
482
+ // And then re-add it if it was removed
483
+ if (importantSelector && parentSelector !== parent.selector) {
484
+ rule.selector = `${importantSelector} ${rule.selector}`;
485
+ }
433
486
  rule.walkDecls((d)=>{
434
- d.important = meta.important || important;
487
+ d.important = meta.important || important1;
435
488
  });
436
489
  });
437
490
  }
491
+ // It could be that the node we were inserted was removed because the class didn't match
492
+ // If that was the *only* rule in the parent, then we have nothing add so we skip it
493
+ if (!root1.nodes[0]) {
494
+ continue;
495
+ }
438
496
  // Insert it
439
497
  siblings.push([
440
- // Ensure that when we are sorting, that we take the layer order into account
441
- {
442
- ...meta,
443
- sort: meta.sort | context.layerOrder[meta.layer]
444
- },
445
- root.nodes[0],
498
+ meta.sort,
499
+ root1.nodes[0]
446
500
  ]);
447
501
  }
448
502
  }
449
503
  // Inject the rules, sorted, correctly
450
- let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)
451
- ).map((s)=>s[1]
452
- );
504
+ let nodes = context.offsets.sort(siblings).map((s)=>s[1]);
453
505
  // `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
454
506
  parent.after(nodes);
455
507
  }
@@ -465,3 +517,10 @@ function processApply(root, context, localCache) {
465
517
  // Do it again, in case we have other `@apply` rules
466
518
  processApply(root, context, localCache);
467
519
  }
520
+ function expandApplyAtRules(context) {
521
+ return (root)=>{
522
+ // Build a cache of the user's CSS so we can use it to resolve classes used by @apply
523
+ let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
524
+ processApply(root, context, localCache);
525
+ };
526
+ }