tailwindcss 0.0.0-oxide-insiders.dddaded → 0.0.0-oxide-insiders.b2e3cf2

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 (112) hide show
  1. package/lib/cli/build/deps.js +10 -18
  2. package/lib/cli/build/index.js +10 -41
  3. package/lib/cli/build/plugin.js +87 -268
  4. package/lib/cli/build/utils.js +18 -40
  5. package/lib/cli/build/watching.js +35 -151
  6. package/lib/cli/help/index.js +15 -58
  7. package/lib/cli/index.js +61 -120
  8. package/lib/cli/init/index.js +21 -43
  9. package/lib/cli-peer-dependencies.js +13 -15
  10. package/lib/cli.js +1 -5
  11. package/lib/corePluginList.js +3 -4
  12. package/lib/corePlugins.js +394 -857
  13. package/lib/featureFlags.js +14 -34
  14. package/lib/index.js +1 -5
  15. package/lib/lib/cacheInvalidation.js +29 -75
  16. package/lib/lib/collapseAdjacentRules.js +22 -43
  17. package/lib/lib/collapseDuplicateDeclarations.js +27 -68
  18. package/lib/lib/content.js +37 -126
  19. package/lib/lib/defaultExtractor.js +96 -199
  20. package/lib/lib/detectNesting.js +12 -36
  21. package/lib/lib/evaluateTailwindFunctions.js +101 -188
  22. package/lib/lib/expandApplyAtRules.js +177 -482
  23. package/lib/lib/expandTailwindAtRules.js +69 -237
  24. package/lib/lib/findAtConfigPath.js +13 -30
  25. package/lib/lib/generateRules.js +349 -765
  26. package/lib/lib/getModuleDependencies.js +27 -63
  27. package/lib/lib/load-config.js +16 -24
  28. package/lib/lib/normalizeTailwindDirectives.js +26 -70
  29. package/lib/lib/offsets.js +61 -224
  30. package/lib/lib/partitionApplyAtRules.js +29 -51
  31. package/lib/lib/regex.js +22 -30
  32. package/lib/lib/remap-bitfield.js +9 -84
  33. package/lib/lib/resolveDefaultsAtRules.js +50 -116
  34. package/lib/lib/setupContextUtils.js +576 -1099
  35. package/lib/lib/setupTrackingContext.js +54 -143
  36. package/lib/lib/sharedState.js +15 -59
  37. package/lib/lib/substituteScreenAtRules.js +8 -16
  38. package/lib/oxide/cli/build/deps.js +17 -32
  39. package/lib/oxide/cli/build/index.js +10 -40
  40. package/lib/oxide/cli/build/plugin.js +87 -267
  41. package/lib/oxide/cli/build/utils.js +18 -39
  42. package/lib/oxide/cli/build/watching.js +34 -149
  43. package/lib/oxide/cli/help/index.js +15 -57
  44. package/lib/oxide/cli/index.js +66 -127
  45. package/lib/oxide/cli/init/index.js +17 -36
  46. package/lib/oxide/cli.js +2 -3
  47. package/lib/plugin.js +30 -57
  48. package/lib/postcss-plugins/nesting/index.js +6 -10
  49. package/lib/postcss-plugins/nesting/plugin.js +17 -60
  50. package/lib/processTailwindFeatures.js +8 -37
  51. package/lib/public/colors.js +15 -22
  52. package/lib/public/create-plugin.js +5 -8
  53. package/lib/public/default-config.js +5 -9
  54. package/lib/public/default-theme.js +5 -9
  55. package/lib/public/load-config.js +4 -6
  56. package/lib/public/resolve-config.js +4 -6
  57. package/lib/util/applyImportantSelector.js +15 -24
  58. package/lib/util/bigSign.js +6 -7
  59. package/lib/util/buildMediaQuery.js +10 -17
  60. package/lib/util/cloneDeep.js +9 -17
  61. package/lib/util/cloneNodes.js +14 -27
  62. package/lib/util/color.js +45 -81
  63. package/lib/util/configurePlugins.js +9 -16
  64. package/lib/util/createPlugin.js +8 -15
  65. package/lib/util/createUtilityPlugin.js +15 -27
  66. package/lib/util/dataTypes.js +23 -144
  67. package/lib/util/defaults.js +9 -19
  68. package/lib/util/escapeClassName.js +6 -10
  69. package/lib/util/escapeCommas.js +6 -7
  70. package/lib/util/flattenColorPalette.js +6 -8
  71. package/lib/util/formatVariantSelector.js +49 -190
  72. package/lib/util/getAllConfigs.js +35 -42
  73. package/lib/util/hashConfig.js +6 -8
  74. package/lib/util/isKeyframeRule.js +6 -7
  75. package/lib/util/isPlainObject.js +8 -11
  76. package/lib/util/isSyntacticallyValidPropertyValue.js +13 -42
  77. package/lib/util/log.js +7 -14
  78. package/lib/util/nameClass.js +6 -21
  79. package/lib/util/negateValue.js +10 -26
  80. package/lib/util/normalizeConfig.js +63 -240
  81. package/lib/util/normalizeScreens.js +70 -137
  82. package/lib/util/parseAnimationValue.js +13 -61
  83. package/lib/util/parseBoxShadowValue.js +12 -57
  84. package/lib/util/parseDependency.js +13 -37
  85. package/lib/util/parseGlob.js +7 -22
  86. package/lib/util/parseObjectStyles.js +17 -26
  87. package/lib/util/pluginUtils.js +69 -176
  88. package/lib/util/prefixSelector.js +11 -28
  89. package/lib/util/pseudoElements.js +29 -105
  90. package/lib/util/removeAlphaVariables.js +8 -21
  91. package/lib/util/resolveConfig.js +103 -220
  92. package/lib/util/resolveConfigPath.js +12 -38
  93. package/lib/util/responsive.js +4 -6
  94. package/lib/util/splitAtTopLevelOnly.js +10 -44
  95. package/lib/util/tap.js +6 -8
  96. package/lib/util/toColorValue.js +6 -7
  97. package/lib/util/toPath.js +8 -26
  98. package/lib/util/transformThemeValue.js +12 -45
  99. package/lib/util/validateConfig.js +14 -22
  100. package/lib/util/validateFormalSyntax.js +5 -11
  101. package/lib/util/withAlphaVariable.js +28 -48
  102. package/package.json +3 -3
  103. package/peers/index.js +14 -16
  104. package/src/cli/build/plugin.js +1 -1
  105. package/src/cli.js +1 -1
  106. package/src/corePlugins.js +16 -17
  107. package/src/featureFlags.js +2 -3
  108. package/src/index.js +1 -5
  109. package/src/lib/expandTailwindAtRules.js +2 -2
  110. package/src/lib/sharedState.js +0 -15
  111. package/src/oxide/cli/build/plugin.ts +1 -1
  112. package/src/plugin.js +1 -1
@@ -1,532 +1,227 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
3
+ value: !0
4
+ }), Object.defineProperty(exports, "default", {
5
+ enumerable: !0,
7
6
  get: ()=>expandApplyAtRules
8
7
  });
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"));
13
- const _applyImportantSelector = require("../util/applyImportantSelector");
14
- const _pseudoElements = require("../util/pseudoElements");
8
+ const _postcss = _interopRequireDefault(require("postcss")), _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser")), _generateRules = require("./generateRules"), _escapeClassName = _interopRequireDefault(require("../util/escapeClassName")), _applyImportantSelector = require("../util/applyImportantSelector"), _pseudoElements = require("../util/pseudoElements");
15
9
  function _interopRequireDefault(obj) {
16
10
  return obj && obj.__esModule ? obj : {
17
11
  default: obj
18
12
  };
19
13
  }
20
- /** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
21
- /** @type {Map<string, Set<string>>} */ let groups = new Map();
22
- let container = _postcss.default.root({
14
+ function extractClasses(node) {
15
+ let groups = new Map();
16
+ _postcss.default.root({
23
17
  nodes: [
24
18
  node.clone()
25
19
  ]
26
- });
27
- container.walkRules((rule)=>{
20
+ }).walkRules((rule)=>{
28
21
  (0, _postcssSelectorParser.default)((selectors)=>{
29
22
  selectors.walkClasses((classSelector)=>{
30
- let parentSelector = classSelector.parent.toString();
31
- let classes = groups.get(parentSelector);
32
- if (!classes) {
33
- groups.set(parentSelector, classes = new Set());
34
- }
35
- classes.add(classSelector.value);
23
+ let parentSelector = classSelector.parent.toString(), classes = groups.get(parentSelector);
24
+ classes || groups.set(parentSelector, classes = new Set()), classes.add(classSelector.value);
36
25
  });
37
26
  }).processSync(rule.selector);
38
27
  });
39
28
  let normalizedGroups = Array.from(groups.values(), (classes)=>Array.from(classes));
40
- let classes = normalizedGroups.flat();
41
- return Object.assign(classes, {
29
+ return Object.assign(normalizedGroups.flat(), {
42
30
  groups: normalizedGroups
43
31
  });
44
32
  }
45
33
  let selectorExtractor = (0, _postcssSelectorParser.default)();
46
- /**
47
- * @param {string} ruleSelectors
48
- */ function extractSelectors(ruleSelectors) {
34
+ function extractSelectors(ruleSelectors) {
49
35
  return selectorExtractor.astSync(ruleSelectors);
50
36
  }
51
37
  function extractBaseCandidates(candidates, separator) {
52
38
  let baseClasses = new Set();
53
- for (let candidate of candidates){
54
- baseClasses.add(candidate.split(separator).pop());
55
- }
39
+ for (let candidate of candidates)baseClasses.add(candidate.split(separator).pop());
56
40
  return Array.from(baseClasses);
57
41
  }
58
42
  function prefix(context, selector) {
59
43
  let prefix = context.tailwindConfig.prefix;
60
- return typeof prefix === "function" ? prefix(selector) : prefix + selector;
44
+ return "function" == typeof prefix ? prefix(selector) : prefix + selector;
61
45
  }
62
46
  function* pathToRoot(node) {
63
- yield node;
64
- while(node.parent){
65
- yield node.parent;
66
- node = node.parent;
67
- }
68
- }
69
- /**
70
- * Only clone the node itself and not its children
71
- *
72
- * @param {*} node
73
- * @param {*} overrides
74
- * @returns
75
- */ function shallowClone(node, overrides = {}) {
76
- let children = node.nodes;
77
- node.nodes = [];
78
- let tmp = node.clone(overrides);
79
- node.nodes = children;
80
- return tmp;
81
- }
82
- /**
83
- * Clone just the nodes all the way to the top that are required to represent
84
- * this singular rule in the tree.
85
- *
86
- * For example, if we have CSS like this:
87
- * ```css
88
- * @media (min-width: 768px) {
89
- * @supports (display: grid) {
90
- * .foo {
91
- * display: grid;
92
- * grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
93
- * }
94
- * }
95
- *
96
- * @supports (backdrop-filter: blur(1px)) {
97
- * .bar {
98
- * backdrop-filter: blur(1px);
99
- * }
100
- * }
101
- *
102
- * .baz {
103
- * color: orange;
104
- * }
105
- * }
106
- * ```
107
- *
108
- * And we're cloning `.bar` it'll return a cloned version of what's required for just that single node:
109
- *
110
- * ```css
111
- * @media (min-width: 768px) {
112
- * @supports (backdrop-filter: blur(1px)) {
113
- * .bar {
114
- * backdrop-filter: blur(1px);
115
- * }
116
- * }
117
- * }
118
- * ```
119
- *
120
- * @param {import('postcss').Node} node
121
- */ function nestedClone(node) {
122
- for (let parent of pathToRoot(node)){
123
- if (node === parent) {
124
- continue;
125
- }
126
- if (parent.type === "root") {
127
- break;
128
- }
129
- node = shallowClone(parent, {
130
- nodes: [
131
- node
132
- ]
133
- });
134
- }
135
- return node;
136
- }
137
- /**
138
- * @param {import('postcss').Root} root
139
- */ function buildLocalApplyCache(root, context) {
140
- /** @type {ApplyCache} */ let cache = new Map();
141
- root.walkRules((rule)=>{
142
- // Ignore rules generated by Tailwind
143
- for (let node of pathToRoot(rule)){
144
- var _node_raws_tailwind;
145
- if (((_node_raws_tailwind = node.raws.tailwind) === null || _node_raws_tailwind === void 0 ? void 0 : _node_raws_tailwind.layer) !== undefined) {
146
- return;
147
- }
148
- }
149
- // Clone what's required to represent this singular rule in the tree
150
- let container = nestedClone(rule);
151
- let sort = context.offsets.create("user");
152
- for (let className of extractClasses(rule)){
153
- let list = cache.get(className) || [];
154
- cache.set(className, list);
155
- list.push([
156
- {
157
- layer: "user",
158
- sort,
159
- important: false
160
- },
161
- container
162
- ]);
163
- }
164
- });
165
- return cache;
166
- }
167
- /**
168
- * @returns {ApplyCache}
169
- */ function buildApplyCache(applyCandidates, context) {
170
- for (let candidate of applyCandidates){
171
- if (context.notClassCache.has(candidate) || context.applyClassCache.has(candidate)) {
172
- continue;
173
- }
174
- if (context.classCache.has(candidate)) {
175
- context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
176
- meta,
177
- rule.clone()
178
- ]));
179
- continue;
180
- }
181
- let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
182
- if (matches.length === 0) {
183
- context.notClassCache.add(candidate);
184
- continue;
185
- }
186
- context.applyClassCache.set(candidate, matches);
187
- }
188
- return context.applyClassCache;
189
- }
190
- /**
191
- * Build a cache only when it's first used
192
- *
193
- * @param {() => ApplyCache} buildCacheFn
194
- * @returns {ApplyCache}
195
- */ function lazyCache(buildCacheFn) {
196
- let cache = null;
197
- return {
198
- get: (name)=>{
199
- cache = cache || buildCacheFn();
200
- return cache.get(name);
201
- },
202
- has: (name)=>{
203
- cache = cache || buildCacheFn();
204
- return cache.has(name);
205
- }
206
- };
207
- }
208
- /**
209
- * Take a series of multiple caches and merge
210
- * them so they act like one large cache
211
- *
212
- * @param {ApplyCache[]} caches
213
- * @returns {ApplyCache}
214
- */ function combineCaches(caches) {
215
- return {
216
- get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
217
- has: (name)=>caches.some((cache)=>cache.has(name))
218
- };
47
+ for(yield node; node.parent;)yield node.parent, node = node.parent;
219
48
  }
220
49
  function extractApplyCandidates(params) {
221
50
  let candidates = params.split(/[\s\t\n]+/g);
222
- if (candidates[candidates.length - 1] === "!important") {
223
- return [
224
- candidates.slice(0, -1),
225
- true
226
- ];
227
- }
228
- return [
51
+ return "!important" === candidates[candidates.length - 1] ? [
52
+ candidates.slice(0, -1),
53
+ !0
54
+ ] : [
229
55
  candidates,
230
- false
56
+ !1
231
57
  ];
232
58
  }
233
- function processApply(root, context, localCache) {
234
- let applyCandidates = new Set();
235
- // Collect all @apply rules and candidates
236
- let applies = [];
237
- root.walkAtRules("apply", (rule)=>{
238
- let [candidates] = extractApplyCandidates(rule.params);
239
- for (let util of candidates){
240
- applyCandidates.add(util);
241
- }
242
- applies.push(rule);
243
- });
244
- // Start the @apply process if we have rules with @apply in them
245
- if (applies.length === 0) {
246
- return;
247
- }
248
- // Fill up some caches!
249
- let applyClassCache = combineCaches([
250
- localCache,
251
- buildApplyCache(applyCandidates, context)
252
- ]);
253
- /**
254
- * When we have an apply like this:
255
- *
256
- * .abc {
257
- * @apply hover:font-bold;
258
- * }
259
- *
260
- * What we essentially will do is resolve to this:
261
- *
262
- * .abc {
263
- * @apply .hover\:font-bold:hover {
264
- * font-weight: 500;
265
- * }
266
- * }
267
- *
268
- * Notice that the to-be-applied class is `.hover\:font-bold:hover` and that the utility candidate was `hover:font-bold`.
269
- * What happens in this function is that we prepend a `.` and escape the candidate.
270
- * This will result in `.hover\:font-bold`
271
- * Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
272
- *
273
- * @param {string} selector
274
- * @param {string} utilitySelectors
275
- * @param {string} candidate
276
- */ function replaceSelector(selector, utilitySelectors, candidate) {
277
- let selectorList = extractSelectors(selector);
278
- let utilitySelectorsList = extractSelectors(utilitySelectors);
279
- let candidateList = extractSelectors(`.${(0, _escapeClassName.default)(candidate)}`);
280
- let candidateClass = candidateList.nodes[0].nodes[0];
281
- selectorList.each((sel)=>{
282
- /** @type {Set<import('postcss-selector-parser').Selector>} */ let replaced = new Set();
283
- utilitySelectorsList.each((utilitySelector)=>{
284
- let hasReplaced = false;
285
- utilitySelector = utilitySelector.clone();
286
- utilitySelector.walkClasses((node)=>{
287
- if (node.value !== candidateClass.value) {
288
- return;
289
- }
290
- // Don't replace multiple instances of the same class
291
- // This is theoretically correct but only partially
292
- // We'd need to generate every possible permutation of the replacement
293
- // For example with `.foo + .foo { … }` and `section { @apply foo; }`
294
- // We'd need to generate all of these:
295
- // - `.foo + .foo`
296
- // - `.foo + section`
297
- // - `section + .foo`
298
- // - `section + section`
299
- if (hasReplaced) {
300
- return;
301
- }
302
- // Since you can only `@apply` class names this is sufficient
303
- // We want to replace the matched class name with the selector the user is using
304
- // Ex: Replace `.text-blue-500` with `.foo.bar:is(.something-cool)`
305
- node.replaceWith(...sel.nodes.map((node)=>node.clone()));
306
- // Record that we did something and we want to use this new selector
307
- replaced.add(utilitySelector);
308
- hasReplaced = true;
309
- });
310
- });
311
- // Sort tag names before class names (but only sort each group (separated by a combinator)
312
- // separately and not in total)
313
- // This happens when replacing `.bar` in `.foo.bar` with a tag like `section`
314
- for (let sel of replaced){
315
- let groups = [
316
- []
317
- ];
318
- for (let node of sel.nodes){
319
- if (node.type === "combinator") {
320
- groups.push(node);
321
- groups.push([]);
322
- } else {
323
- let last = groups[groups.length - 1];
324
- last.push(node);
325
- }
59
+ function expandApplyAtRules(context) {
60
+ return (root)=>{
61
+ var buildCacheFn;
62
+ let cache;
63
+ let localCache = (buildCacheFn = ()=>{
64
+ let cache;
65
+ return cache = new Map(), root.walkRules((rule)=>{
66
+ for (let node of pathToRoot(rule)){
67
+ var _node_raws_tailwind;
68
+ if ((null === (_node_raws_tailwind = node.raws.tailwind) || void 0 === _node_raws_tailwind ? void 0 : _node_raws_tailwind.layer) !== void 0) return;
326
69
  }
327
- sel.nodes = [];
328
- for (let group of groups){
329
- if (Array.isArray(group)) {
330
- group.sort((a, b)=>{
331
- if (a.type === "tag" && b.type === "class") {
332
- return -1;
333
- } else if (a.type === "class" && b.type === "tag") {
334
- return 1;
335
- } else if (a.type === "class" && b.type === "pseudo" && b.value.startsWith("::")) {
336
- return -1;
337
- } else if (a.type === "pseudo" && a.value.startsWith("::") && b.type === "class") {
338
- return 1;
339
- }
340
- return 0;
70
+ let container = function(node) {
71
+ for (let parent of pathToRoot(node))if (node !== parent) {
72
+ if ("root" === parent.type) break;
73
+ node = function(node, overrides = {}) {
74
+ let children = node.nodes;
75
+ node.nodes = [];
76
+ let tmp = node.clone(overrides);
77
+ return node.nodes = children, tmp;
78
+ }(parent, {
79
+ nodes: [
80
+ node
81
+ ]
341
82
  });
342
83
  }
343
- sel.nodes = sel.nodes.concat(group);
84
+ return node;
85
+ }(rule), sort = context.offsets.create("user");
86
+ for (let className of extractClasses(rule)){
87
+ let list = cache.get(className) || [];
88
+ cache.set(className, list), list.push([
89
+ {
90
+ layer: "user",
91
+ sort,
92
+ important: !1
93
+ },
94
+ container
95
+ ]);
344
96
  }
345
- }
346
- sel.replaceWith(...replaced);
97
+ }), cache;
98
+ }, cache = null, {
99
+ get: (name)=>(cache = cache || buildCacheFn()).get(name),
100
+ has: (name)=>(cache = cache || buildCacheFn()).has(name)
347
101
  });
348
- return selectorList.toString();
349
- }
350
- let perParentApplies = new Map();
351
- // Collect all apply candidates and their rules
352
- for (let apply of applies){
353
- let [candidates] = perParentApplies.get(apply.parent) || [
354
- [],
355
- apply.source
356
- ];
357
- perParentApplies.set(apply.parent, [
358
- candidates,
359
- apply.source
360
- ]);
361
- let [applyCandidates, important] = extractApplyCandidates(apply.params);
362
- if (apply.parent.type === "atrule") {
363
- if (apply.parent.name === "screen") {
364
- let screenType = apply.parent.params;
365
- 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}`).join(" ")} instead.`);
366
- }
367
- 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}.`);
368
- }
369
- for (let applyCandidate of applyCandidates){
370
- if ([
371
- prefix(context, "group"),
372
- prefix(context, "peer")
373
- ].includes(applyCandidate)) {
374
- // TODO: Link to specific documentation page with error code.
375
- throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
376
- }
377
- if (!applyClassCache.has(applyCandidate)) {
378
- throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
379
- }
380
- let rules = applyClassCache.get(applyCandidate);
381
- candidates.push([
382
- applyCandidate,
383
- important,
384
- rules
385
- ]);
386
- }
387
- }
388
- for (let [parent, [candidates, atApplySource]] of perParentApplies){
389
- let siblings = [];
390
- for (let [applyCandidate, important, rules] of candidates){
391
- let potentialApplyCandidates = [
392
- applyCandidate,
393
- ...extractBaseCandidates([
394
- applyCandidate
395
- ], context.tailwindConfig.separator)
396
- ];
397
- for (let [meta, node] of rules){
398
- let parentClasses = extractClasses(parent);
399
- let nodeClasses = extractClasses(node);
400
- // 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`
401
- // So we've split them into groups
402
- nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat();
403
- // Add base utility classes from the @apply node to the list of
404
- // classes to check whether it intersects and therefore results in a
405
- // circular dependency or not.
406
- //
407
- // E.g.:
408
- // .foo {
409
- // @apply hover:a; // This applies "a" but with a modifier
410
- // }
411
- //
412
- // We only have to do that with base classes of the `node`, not of the `parent`
413
- // E.g.:
414
- // .hover\:foo {
415
- // @apply bar;
416
- // }
417
- // .bar {
418
- // @apply foo;
419
- // }
420
- //
421
- // This should not result in a circular dependency because we are
422
- // just applying `.foo` and the rule above is `.hover\:foo` which is
423
- // unrelated. However, if we were to apply `hover:foo` then we _did_
424
- // have to include this one.
425
- nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
426
- let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector));
427
- if (intersects) {
428
- throw node.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
429
- }
430
- let root = _postcss.default.root({
431
- nodes: [
432
- node.clone()
433
- ]
434
- });
435
- // Make sure every node in the entire tree points back at the @apply rule that generated it
436
- root.walk((node)=>{
437
- node.source = atApplySource;
438
- });
439
- let canRewriteSelector = node.type !== "atrule" || node.type === "atrule" && node.name !== "keyframes";
440
- if (canRewriteSelector) {
441
- root.walkRules((rule)=>{
442
- // Let's imagine you have the following structure:
443
- //
444
- // .foo {
445
- // @apply bar;
446
- // }
447
- //
448
- // @supports (a: b) {
449
- // .bar {
450
- // color: blue
451
- // }
452
- //
453
- // .something-unrelated {}
454
- // }
455
- //
456
- // In this case we want to apply `.bar` but it happens to be in
457
- // an atrule node. We clone that node instead of the nested one
458
- // because we still want that @supports rule to be there once we
459
- // applied everything.
460
- //
461
- // However it happens to be that the `.something-unrelated` is
462
- // also in that same shared @supports atrule. This is not good,
463
- // and this should not be there. The good part is that this is
464
- // a clone already and it can be safely removed. The question is
465
- // how do we know we can remove it. Basically what we can do is
466
- // match it against the applyCandidate that you want to apply. If
467
- // it doesn't match the we can safely delete it.
468
- //
469
- // If we didn't do this, then the `replaceSelector` function
470
- // would have replaced this with something that didn't exist and
471
- // therefore it removed the selector altogether. In this specific
472
- // case it would result in `{}` instead of `.something-unrelated {}`
473
- if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate)) {
474
- rule.remove();
475
- return;
102
+ !function processApply(root, context, localCache) {
103
+ var caches;
104
+ let applyCandidates = new Set(), applies = [];
105
+ if (root.walkAtRules("apply", (rule)=>{
106
+ let [candidates] = extractApplyCandidates(rule.params);
107
+ for (let util of candidates)applyCandidates.add(util);
108
+ applies.push(rule);
109
+ }), 0 === applies.length) return;
110
+ let applyClassCache = (caches = [
111
+ localCache,
112
+ function(applyCandidates, context) {
113
+ for (let candidate of applyCandidates){
114
+ if (context.notClassCache.has(candidate) || context.applyClassCache.has(candidate)) continue;
115
+ if (context.classCache.has(candidate)) {
116
+ context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
117
+ meta,
118
+ rule.clone()
119
+ ]));
120
+ continue;
476
121
  }
477
- // Strip the important selector from the parent selector if at the beginning
478
- let importantSelector = typeof context.tailwindConfig.important === "string" ? context.tailwindConfig.important : null;
479
- // We only want to move the "important" selector if this is a Tailwind-generated utility
480
- // We do *not* want to do this for user CSS that happens to be structured the same
481
- let isGenerated = parent.raws.tailwind !== undefined;
482
- let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
483
- rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate);
484
- // And then re-add it if it was removed
485
- if (importantSelector && parentSelector !== parent.selector) {
486
- rule.selector = (0, _applyImportantSelector.applyImportantSelector)(rule.selector, importantSelector);
122
+ let matches = Array.from((0, _generateRules.resolveMatches)(candidate, context));
123
+ if (0 === matches.length) {
124
+ context.notClassCache.add(candidate);
125
+ continue;
487
126
  }
488
- rule.walkDecls((d)=>{
489
- d.important = meta.important || important;
490
- });
491
- // Move pseudo elements to the end of the selector (if necessary)
492
- let selector = (0, _postcssSelectorParser.default)().astSync(rule.selector);
493
- selector.each((sel)=>(0, _pseudoElements.movePseudos)(sel));
494
- rule.selector = selector.toString();
495
- });
127
+ context.applyClassCache.set(candidate, matches);
128
+ }
129
+ return context.applyClassCache;
130
+ }(applyCandidates, context)
131
+ ], {
132
+ get: (name)=>caches.flatMap((cache)=>cache.get(name) || []),
133
+ has: (name)=>caches.some((cache)=>cache.has(name))
134
+ }), perParentApplies = new Map();
135
+ for (let apply of applies){
136
+ let [candidates] = perParentApplies.get(apply.parent) || [
137
+ [],
138
+ apply.source
139
+ ];
140
+ perParentApplies.set(apply.parent, [
141
+ candidates,
142
+ apply.source
143
+ ]);
144
+ let [applyCandidates, important] = extractApplyCandidates(apply.params);
145
+ if ("atrule" === apply.parent.type) {
146
+ if ("screen" === apply.parent.name) {
147
+ let screenType = apply.parent.params;
148
+ 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}`).join(" ")} instead.`);
149
+ }
150
+ 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}.`);
496
151
  }
497
- // It could be that the node we were inserted was removed because the class didn't match
498
- // If that was the *only* rule in the parent, then we have nothing add so we skip it
499
- if (!root.nodes[0]) {
500
- continue;
152
+ for (let applyCandidate of applyCandidates){
153
+ if ([
154
+ prefix(context, "group"),
155
+ prefix(context, "peer")
156
+ ].includes(applyCandidate)) throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
157
+ if (!applyClassCache.has(applyCandidate)) throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
158
+ let rules = applyClassCache.get(applyCandidate);
159
+ candidates.push([
160
+ applyCandidate,
161
+ important,
162
+ rules
163
+ ]);
501
164
  }
502
- // Insert it
503
- siblings.push([
504
- meta.sort,
505
- root.nodes[0]
506
- ]);
507
165
  }
508
- }
509
- // Inject the rules, sorted, correctly
510
- let nodes = context.offsets.sort(siblings).map((s)=>s[1]);
511
- // `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
512
- parent.after(nodes);
513
- }
514
- for (let apply of applies){
515
- // If there are left-over declarations, just remove the @apply
516
- if (apply.parent.nodes.length > 1) {
517
- apply.remove();
518
- } else {
519
- // The node is empty, drop the full node
520
- apply.parent.remove();
521
- }
522
- }
523
- // Do it again, in case we have other `@apply` rules
524
- processApply(root, context, localCache);
525
- }
526
- function expandApplyAtRules(context) {
527
- return (root)=>{
528
- // Build a cache of the user's CSS so we can use it to resolve classes used by @apply
529
- let localCache = lazyCache(()=>buildLocalApplyCache(root, context));
530
- processApply(root, context, localCache);
166
+ for (let [parent, [candidates, atApplySource]] of perParentApplies){
167
+ let siblings = [];
168
+ for (let [applyCandidate, important, rules] of candidates){
169
+ let potentialApplyCandidates = [
170
+ applyCandidate,
171
+ ...extractBaseCandidates([
172
+ applyCandidate
173
+ ], context.tailwindConfig.separator)
174
+ ];
175
+ for (let [meta, node] of rules){
176
+ let parentClasses = extractClasses(parent), nodeClasses = extractClasses(node);
177
+ if (nodeClasses = (nodeClasses = nodeClasses.groups.filter((classList)=>classList.some((className)=>potentialApplyCandidates.includes(className))).flat()).concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator)), parentClasses.some((selector)=>nodeClasses.includes(selector))) throw node.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
178
+ let root = _postcss.default.root({
179
+ nodes: [
180
+ node.clone()
181
+ ]
182
+ });
183
+ root.walk((node)=>{
184
+ node.source = atApplySource;
185
+ }), ("atrule" !== node.type || "atrule" === node.type && "keyframes" !== node.name) && root.walkRules((rule)=>{
186
+ if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate)) {
187
+ rule.remove();
188
+ return;
189
+ }
190
+ let importantSelector = "string" == typeof context.tailwindConfig.important ? context.tailwindConfig.important : null, parentSelector = void 0 !== parent.raws.tailwind && importantSelector && 0 === parent.selector.indexOf(importantSelector) ? parent.selector.slice(importantSelector.length) : parent.selector;
191
+ rule.selector = function(selector, utilitySelectors, candidate) {
192
+ let selectorList = extractSelectors(selector), utilitySelectorsList = extractSelectors(utilitySelectors), candidateClass = extractSelectors(`.${(0, _escapeClassName.default)(candidate)}`).nodes[0].nodes[0];
193
+ return selectorList.each((sel)=>{
194
+ let replaced = new Set();
195
+ for (let sel1 of (utilitySelectorsList.each((utilitySelector)=>{
196
+ let hasReplaced = !1;
197
+ (utilitySelector = utilitySelector.clone()).walkClasses((node)=>{
198
+ node.value !== candidateClass.value || hasReplaced || (node.replaceWith(...sel.nodes.map((node)=>node.clone())), replaced.add(utilitySelector), hasReplaced = !0);
199
+ });
200
+ }), replaced)){
201
+ let groups = [
202
+ []
203
+ ];
204
+ for (let node of sel1.nodes)"combinator" === node.type ? (groups.push(node), groups.push([])) : groups[groups.length - 1].push(node);
205
+ for (let group of (sel1.nodes = [], groups))Array.isArray(group) && group.sort((a, b)=>"tag" === a.type && "class" === b.type ? -1 : "class" === a.type && "tag" === b.type ? 1 : "class" === a.type && "pseudo" === b.type && b.value.startsWith("::") ? -1 : "pseudo" === a.type && a.value.startsWith("::") && "class" === b.type ? 1 : 0), sel1.nodes = sel1.nodes.concat(group);
206
+ }
207
+ sel.replaceWith(...replaced);
208
+ }), selectorList.toString();
209
+ }(parentSelector, rule.selector, applyCandidate), importantSelector && parentSelector !== parent.selector && (rule.selector = (0, _applyImportantSelector.applyImportantSelector)(rule.selector, importantSelector)), rule.walkDecls((d)=>{
210
+ d.important = meta.important || important;
211
+ });
212
+ let selector = (0, _postcssSelectorParser.default)().astSync(rule.selector);
213
+ selector.each((sel)=>(0, _pseudoElements.movePseudos)(sel)), rule.selector = selector.toString();
214
+ }), root.nodes[0] && siblings.push([
215
+ meta.sort,
216
+ root.nodes[0]
217
+ ]);
218
+ }
219
+ }
220
+ let nodes = context.offsets.sort(siblings).map((s)=>s[1]);
221
+ parent.after(nodes);
222
+ }
223
+ for (let apply of applies)apply.parent.nodes.length > 1 ? apply.remove() : apply.parent.remove();
224
+ processApply(root, context, localCache);
225
+ }(root, context, localCache);
531
226
  };
532
227
  }