tailwindcss 0.0.0-insiders.deefbf5 → 0.0.0-insiders.df96ea5

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