tailwindcss 0.0.0-insiders.fe08e91 → 0.0.0-oxide.c7d416b

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 (183) hide show
  1. package/CHANGELOG.md +379 -3
  2. package/LICENSE +1 -2
  3. package/README.md +12 -8
  4. package/colors.d.ts +3 -0
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultTheme.d.ts +4 -0
  7. package/lib/cli/build/deps.js +54 -0
  8. package/lib/cli/build/index.js +48 -0
  9. package/lib/cli/build/plugin.js +367 -0
  10. package/lib/cli/build/utils.js +78 -0
  11. package/lib/cli/build/watching.js +178 -0
  12. package/lib/cli/help/index.js +71 -0
  13. package/lib/cli/index.js +239 -0
  14. package/lib/cli/init/index.js +46 -0
  15. package/lib/cli/shared.js +13 -0
  16. package/lib/cli-peer-dependencies.js +20 -7
  17. package/lib/cli.js +4 -740
  18. package/lib/constants.js +27 -20
  19. package/lib/corePluginList.js +6 -3
  20. package/lib/corePlugins.js +2064 -1811
  21. package/lib/css/preflight.css +5 -5
  22. package/lib/featureFlags.js +31 -22
  23. package/lib/index.js +4 -28
  24. package/lib/lib/cacheInvalidation.js +90 -0
  25. package/lib/lib/collapseAdjacentRules.js +27 -9
  26. package/lib/lib/collapseDuplicateDeclarations.js +12 -9
  27. package/lib/lib/content.js +176 -0
  28. package/lib/lib/defaultExtractor.js +225 -31
  29. package/lib/lib/detectNesting.js +13 -10
  30. package/lib/lib/evaluateTailwindFunctions.js +118 -55
  31. package/lib/lib/expandApplyAtRules.js +439 -190
  32. package/lib/lib/expandTailwindAtRules.js +151 -134
  33. package/lib/lib/findAtConfigPath.js +44 -0
  34. package/lib/lib/generateRules.js +454 -187
  35. package/lib/lib/getModuleDependencies.js +11 -8
  36. package/lib/lib/normalizeTailwindDirectives.js +36 -32
  37. package/lib/lib/offsets.js +217 -0
  38. package/lib/lib/partitionApplyAtRules.js +56 -0
  39. package/lib/lib/regex.js +60 -0
  40. package/lib/lib/resolveDefaultsAtRules.js +89 -67
  41. package/lib/lib/setupContextUtils.js +667 -376
  42. package/lib/lib/setupTrackingContext.js +38 -67
  43. package/lib/lib/sharedState.js +27 -14
  44. package/lib/lib/substituteScreenAtRules.js +11 -9
  45. package/lib/plugin.js +48 -0
  46. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  47. package/lib/postcss-plugins/nesting/index.js +19 -0
  48. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  49. package/lib/processTailwindFeatures.js +35 -25
  50. package/lib/public/colors.js +247 -245
  51. package/lib/public/create-plugin.js +6 -4
  52. package/lib/public/default-config.js +7 -5
  53. package/lib/public/default-theme.js +7 -5
  54. package/lib/public/resolve-config.js +8 -5
  55. package/lib/util/bigSign.js +4 -1
  56. package/lib/util/buildMediaQuery.js +11 -6
  57. package/lib/util/cloneDeep.js +7 -6
  58. package/lib/util/cloneNodes.js +21 -3
  59. package/lib/util/color.js +53 -54
  60. package/lib/util/configurePlugins.js +5 -2
  61. package/lib/util/createPlugin.js +6 -6
  62. package/lib/util/createUtilityPlugin.js +12 -14
  63. package/lib/util/dataTypes.js +119 -110
  64. package/lib/util/defaults.js +4 -1
  65. package/lib/util/escapeClassName.js +7 -4
  66. package/lib/util/escapeCommas.js +5 -2
  67. package/lib/util/flattenColorPalette.js +9 -12
  68. package/lib/util/formatVariantSelector.js +184 -85
  69. package/lib/util/getAllConfigs.js +27 -8
  70. package/lib/util/hashConfig.js +6 -3
  71. package/lib/util/isKeyframeRule.js +5 -2
  72. package/lib/util/isPlainObject.js +5 -2
  73. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +23 -15
  74. package/lib/util/log.js +20 -14
  75. package/lib/util/nameClass.js +20 -9
  76. package/lib/util/negateValue.js +23 -8
  77. package/lib/util/normalizeConfig.js +116 -72
  78. package/lib/util/normalizeScreens.js +120 -11
  79. package/lib/util/parseAnimationValue.js +42 -40
  80. package/lib/util/parseBoxShadowValue.js +30 -23
  81. package/lib/util/parseDependency.js +38 -56
  82. package/lib/util/parseGlob.js +34 -0
  83. package/lib/util/parseObjectStyles.js +11 -8
  84. package/lib/util/pluginUtils.js +147 -50
  85. package/lib/util/prefixSelector.js +10 -8
  86. package/lib/util/removeAlphaVariables.js +29 -0
  87. package/lib/util/resolveConfig.js +97 -85
  88. package/lib/util/resolveConfigPath.js +11 -9
  89. package/lib/util/responsive.js +8 -5
  90. package/lib/util/splitAtTopLevelOnly.js +43 -0
  91. package/lib/util/tap.js +4 -1
  92. package/lib/util/toColorValue.js +5 -3
  93. package/lib/util/toPath.js +20 -4
  94. package/lib/util/transformThemeValue.js +37 -29
  95. package/lib/util/validateConfig.js +24 -0
  96. package/lib/util/validateFormalSyntax.js +24 -0
  97. package/lib/util/withAlphaVariable.js +23 -15
  98. package/nesting/index.js +2 -12
  99. package/oxide/README.md +1 -0
  100. package/oxide/package.json +18 -0
  101. package/oxide/packages/tailwindcss/dist/cli.js +2 -0
  102. package/oxide/packages/tailwindcss/dist/postcss-plugin.js +2 -0
  103. package/oxide/packages/tailwindcss/package.json +34 -0
  104. package/package.json +49 -42
  105. package/peers/index.js +11381 -7950
  106. package/plugin.d.ts +11 -0
  107. package/resolveConfig.d.ts +12 -0
  108. package/scripts/generate-types.js +105 -0
  109. package/scripts/release-channel.js +18 -0
  110. package/scripts/release-notes.js +21 -0
  111. package/scripts/type-utils.js +27 -0
  112. package/src/cli/build/deps.js +56 -0
  113. package/src/cli/build/index.js +49 -0
  114. package/src/cli/build/plugin.js +439 -0
  115. package/src/cli/build/utils.js +76 -0
  116. package/src/cli/build/watching.js +227 -0
  117. package/src/cli/help/index.js +70 -0
  118. package/src/cli/index.js +234 -0
  119. package/src/cli/init/index.js +50 -0
  120. package/src/cli/shared.js +6 -0
  121. package/src/cli-peer-dependencies.js +7 -1
  122. package/src/cli.js +4 -810
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +532 -217
  125. package/src/css/preflight.css +5 -5
  126. package/src/featureFlags.js +15 -9
  127. package/src/index.js +4 -27
  128. package/src/lib/cacheInvalidation.js +52 -0
  129. package/src/lib/collapseAdjacentRules.js +21 -2
  130. package/src/lib/content.js +212 -0
  131. package/src/lib/defaultExtractor.js +196 -33
  132. package/src/lib/evaluateTailwindFunctions.js +78 -7
  133. package/src/lib/expandApplyAtRules.js +482 -183
  134. package/src/lib/expandTailwindAtRules.js +106 -85
  135. package/src/lib/findAtConfigPath.js +48 -0
  136. package/src/lib/generateRules.js +418 -129
  137. package/src/lib/normalizeTailwindDirectives.js +1 -0
  138. package/src/lib/offsets.js +270 -0
  139. package/src/lib/partitionApplyAtRules.js +52 -0
  140. package/src/lib/regex.js +74 -0
  141. package/src/lib/resolveDefaultsAtRules.js +51 -30
  142. package/src/lib/setupContextUtils.js +556 -208
  143. package/src/lib/setupTrackingContext.js +11 -48
  144. package/src/lib/sharedState.js +5 -0
  145. package/src/plugin.js +47 -0
  146. package/src/postcss-plugins/nesting/README.md +42 -0
  147. package/src/postcss-plugins/nesting/index.js +13 -0
  148. package/src/postcss-plugins/nesting/plugin.js +80 -0
  149. package/src/processTailwindFeatures.js +8 -0
  150. package/src/util/buildMediaQuery.js +5 -3
  151. package/src/util/cloneNodes.js +19 -2
  152. package/src/util/color.js +25 -21
  153. package/src/util/dataTypes.js +29 -21
  154. package/src/util/formatVariantSelector.js +184 -61
  155. package/src/util/getAllConfigs.js +19 -0
  156. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  157. package/src/util/log.js +8 -8
  158. package/src/util/nameClass.js +4 -0
  159. package/src/util/negateValue.js +11 -3
  160. package/src/util/normalizeConfig.js +44 -6
  161. package/src/util/normalizeScreens.js +99 -4
  162. package/src/util/parseBoxShadowValue.js +4 -3
  163. package/src/util/parseDependency.js +37 -42
  164. package/src/util/parseGlob.js +24 -0
  165. package/src/util/pluginUtils.js +132 -10
  166. package/src/util/prefixSelector.js +7 -5
  167. package/src/util/removeAlphaVariables.js +24 -0
  168. package/src/util/resolveConfig.js +70 -32
  169. package/src/util/splitAtTopLevelOnly.js +45 -0
  170. package/src/util/toPath.js +1 -1
  171. package/src/util/transformThemeValue.js +13 -3
  172. package/src/util/validateConfig.js +13 -0
  173. package/src/util/validateFormalSyntax.js +34 -0
  174. package/src/util/withAlphaVariable.js +1 -1
  175. package/stubs/defaultConfig.stub.js +23 -20
  176. package/stubs/simpleConfig.stub.js +1 -0
  177. package/types/config.d.ts +362 -0
  178. package/types/generated/.gitkeep +0 -0
  179. package/types/generated/colors.d.ts +276 -0
  180. package/types/generated/corePluginList.d.ts +1 -0
  181. package/types/generated/default-theme.d.ts +342 -0
  182. package/types/index.d.ts +7 -0
  183. package/nesting/plugin.js +0 -41
@@ -49,6 +49,7 @@ export default function normalizeTailwindDirectives(root) {
49
49
  log.warn(`${atRule.name}-at-rule-deprecated`, [
50
50
  `The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
51
51
  `Use \`@layer utilities\` or \`@layer components\` instead.`,
52
+ 'https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer',
52
53
  ])
53
54
  }
54
55
  layerDirectives.add(atRule)
@@ -0,0 +1,270 @@
1
+ // @ts-check
2
+
3
+ import bigSign from '../util/bigSign'
4
+
5
+ /**
6
+ * @typedef {'base' | 'defaults' | 'components' | 'utilities' | 'variants' | 'user'} Layer
7
+ */
8
+
9
+ /**
10
+ * @typedef {object} VariantOption
11
+ * @property {number} id An unique identifier to identify `matchVariant`
12
+ * @property {function | undefined} sort The sort function
13
+ * @property {string|null} value The value we want to compare
14
+ * @property {string|null} modifier The modifier that was used (if any)
15
+ */
16
+
17
+ /**
18
+ * @typedef {object} RuleOffset
19
+ * @property {Layer} layer The layer that this rule belongs to
20
+ * @property {Layer} parentLayer The layer that this rule originally belonged to. Only different from layer if this is a variant.
21
+ * @property {bigint} arbitrary 0n if false, 1n if true
22
+ * @property {bigint} variants Dynamic size. 1 bit per registered variant. 0n means no variants
23
+ * @property {bigint} parallelIndex Rule index for the parallel variant. 0 if not applicable.
24
+ * @property {bigint} index Index of the rule / utility in it's given *parent* layer. Monotonically increasing.
25
+ * @property {VariantOption[]} options Some information on how we can sort arbitrary variants
26
+ */
27
+
28
+ export class Offsets {
29
+ constructor() {
30
+ /**
31
+ * Offsets for the next rule in a given layer
32
+ *
33
+ * @type {Record<Layer, bigint>}
34
+ */
35
+ this.offsets = {
36
+ defaults: 0n,
37
+ base: 0n,
38
+ components: 0n,
39
+ utilities: 0n,
40
+ variants: 0n,
41
+ user: 0n,
42
+ }
43
+
44
+ /**
45
+ * Positions for a given layer
46
+ *
47
+ * @type {Record<Layer, bigint>}
48
+ */
49
+ this.layerPositions = {
50
+ defaults: 0n,
51
+ base: 1n,
52
+ components: 2n,
53
+ utilities: 3n,
54
+
55
+ // There isn't technically a "user" layer, but we need to give it a position
56
+ // Because it's used for ordering user-css from @apply
57
+ user: 4n,
58
+
59
+ variants: 5n,
60
+ }
61
+
62
+ /**
63
+ * The total number of functions currently registered across all variants (including arbitrary variants)
64
+ *
65
+ * @type {bigint}
66
+ */
67
+ this.reservedVariantBits = 0n
68
+
69
+ /**
70
+ * Positions for a given variant
71
+ *
72
+ * @type {Map<string, bigint>}
73
+ */
74
+ this.variantOffsets = new Map()
75
+ }
76
+
77
+ /**
78
+ * @param {Layer} layer
79
+ * @returns {RuleOffset}
80
+ */
81
+ create(layer) {
82
+ return {
83
+ layer,
84
+ parentLayer: layer,
85
+ arbitrary: 0n,
86
+ variants: 0n,
87
+ parallelIndex: 0n,
88
+ index: this.offsets[layer]++,
89
+ options: [],
90
+ }
91
+ }
92
+
93
+ /**
94
+ * @returns {RuleOffset}
95
+ */
96
+ arbitraryProperty() {
97
+ return {
98
+ ...this.create('utilities'),
99
+ arbitrary: 1n,
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Get the offset for a variant
105
+ *
106
+ * @param {string} variant
107
+ * @param {number} index
108
+ * @returns {RuleOffset}
109
+ */
110
+ forVariant(variant, index = 0) {
111
+ let offset = this.variantOffsets.get(variant)
112
+ if (offset === undefined) {
113
+ throw new Error(`Cannot find offset for unknown variant ${variant}`)
114
+ }
115
+
116
+ return {
117
+ ...this.create('variants'),
118
+ variants: offset << BigInt(index),
119
+ }
120
+ }
121
+
122
+ /**
123
+ * @param {RuleOffset} rule
124
+ * @param {RuleOffset} variant
125
+ * @param {VariantOption} options
126
+ * @returns {RuleOffset}
127
+ */
128
+ applyVariantOffset(rule, variant, options) {
129
+ return {
130
+ ...rule,
131
+ layer: 'variants',
132
+ parentLayer: rule.layer === 'variants' ? rule.parentLayer : rule.layer,
133
+ variants: rule.variants | variant.variants,
134
+ options: options.sort ? [].concat(options, rule.options) : rule.options,
135
+
136
+ // TODO: Technically this is wrong. We should be handling parallel index on a per variant basis.
137
+ // We'll take the max of all the parallel indexes for now.
138
+ // @ts-ignore
139
+ parallelIndex: max([rule.parallelIndex, variant.parallelIndex]),
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @param {RuleOffset} offset
145
+ * @param {number} parallelIndex
146
+ * @returns {RuleOffset}
147
+ */
148
+ applyParallelOffset(offset, parallelIndex) {
149
+ return {
150
+ ...offset,
151
+ parallelIndex: BigInt(parallelIndex),
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Each variant gets 1 bit per function / rule registered.
157
+ * This is because multiple variants can be applied to a single rule and we need to know which ones are present and which ones are not.
158
+ * Additionally, every unique group of variants is grouped together in the stylesheet.
159
+ *
160
+ * This grouping is order-independent. For instance, we do not differentiate between `hover:focus` and `focus:hover`.
161
+ *
162
+ * @param {string[]} variants
163
+ * @param {(name: string) => number} getLength
164
+ */
165
+ recordVariants(variants, getLength) {
166
+ for (let variant of variants) {
167
+ this.recordVariant(variant, getLength(variant))
168
+ }
169
+ }
170
+
171
+ /**
172
+ * The same as `recordVariants` but for a single arbitrary variant at runtime.
173
+ * @param {string} variant
174
+ * @param {number} fnCount
175
+ *
176
+ * @returns {RuleOffset} The highest offset for this variant
177
+ */
178
+ recordVariant(variant, fnCount = 1) {
179
+ this.variantOffsets.set(variant, 1n << this.reservedVariantBits)
180
+
181
+ // Ensure space is reserved for each "function" in the parallel variant
182
+ // by offsetting the next variant by the number of parallel variants
183
+ // in the one we just added.
184
+
185
+ // Single functions that return parallel variants are NOT handled separately here
186
+ // They're offset by 1 (or the number of functions) as usual
187
+ // And each rule returned is tracked separately since the functions are evaluated lazily.
188
+ // @see `RuleOffset.parallelIndex`
189
+ this.reservedVariantBits += BigInt(fnCount)
190
+
191
+ return {
192
+ ...this.create('variants'),
193
+ variants: 1n << this.reservedVariantBits,
194
+ }
195
+ }
196
+
197
+ /**
198
+ * @param {RuleOffset} a
199
+ * @param {RuleOffset} b
200
+ * @returns {bigint}
201
+ */
202
+ compare(a, b) {
203
+ // Sort layers together
204
+ if (a.layer !== b.layer) {
205
+ return this.layerPositions[a.layer] - this.layerPositions[b.layer]
206
+ }
207
+
208
+ // Sort based on the sorting function
209
+ for (let aOptions of a.options) {
210
+ for (let bOptions of b.options) {
211
+ if (aOptions.id !== bOptions.id) continue
212
+ if (!aOptions.sort || !bOptions.sort) continue
213
+ let result = aOptions.sort(
214
+ {
215
+ value: aOptions.value,
216
+ modifier: aOptions.modifier,
217
+ },
218
+ {
219
+ value: bOptions.value,
220
+ modifier: bOptions.modifier,
221
+ }
222
+ )
223
+ if (result !== 0) return result
224
+ }
225
+ }
226
+
227
+ // Sort variants in the order they were registered
228
+ if (a.variants !== b.variants) {
229
+ return a.variants - b.variants
230
+ }
231
+
232
+ // Make sure each rule returned by a parallel variant is sorted in ascending order
233
+ if (a.parallelIndex !== b.parallelIndex) {
234
+ return a.parallelIndex - b.parallelIndex
235
+ }
236
+
237
+ // Always sort arbitrary properties after other utilities
238
+ if (a.arbitrary !== b.arbitrary) {
239
+ return a.arbitrary - b.arbitrary
240
+ }
241
+
242
+ // Sort utilities, components, etc… in the order they were registered
243
+ return a.index - b.index
244
+ }
245
+
246
+ /**
247
+ * @template T
248
+ * @param {[RuleOffset, T][]} list
249
+ * @returns {[RuleOffset, T][]}
250
+ */
251
+ sort(list) {
252
+ return list.sort(([a], [b]) => bigSign(this.compare(a, b)))
253
+ }
254
+ }
255
+
256
+ /**
257
+ *
258
+ * @param {bigint[]} nums
259
+ * @returns {bigint|null}
260
+ */
261
+ function max(nums) {
262
+ let max = null
263
+
264
+ for (const num of nums) {
265
+ max = max ?? num
266
+ max = max > num ? max : num
267
+ }
268
+
269
+ return max
270
+ }
@@ -0,0 +1,52 @@
1
+ function partitionRules(root) {
2
+ if (!root.walkAtRules) return
3
+
4
+ let applyParents = new Set()
5
+
6
+ root.walkAtRules('apply', (rule) => {
7
+ applyParents.add(rule.parent)
8
+ })
9
+
10
+ if (applyParents.size === 0) {
11
+ return
12
+ }
13
+
14
+ for (let rule of applyParents) {
15
+ let nodeGroups = []
16
+ let lastGroup = []
17
+
18
+ for (let node of rule.nodes) {
19
+ if (node.type === 'atrule' && node.name === 'apply') {
20
+ if (lastGroup.length > 0) {
21
+ nodeGroups.push(lastGroup)
22
+ lastGroup = []
23
+ }
24
+ nodeGroups.push([node])
25
+ } else {
26
+ lastGroup.push(node)
27
+ }
28
+ }
29
+
30
+ if (lastGroup.length > 0) {
31
+ nodeGroups.push(lastGroup)
32
+ }
33
+
34
+ if (nodeGroups.length === 1) {
35
+ continue
36
+ }
37
+
38
+ for (let group of [...nodeGroups].reverse()) {
39
+ let clone = rule.clone({ nodes: [] })
40
+ clone.append(group)
41
+ rule.after(clone)
42
+ }
43
+
44
+ rule.remove()
45
+ }
46
+ }
47
+
48
+ export default function expandApplyAtRules() {
49
+ return (root) => {
50
+ partitionRules(root)
51
+ }
52
+ }
@@ -0,0 +1,74 @@
1
+ const REGEX_SPECIAL = /[\\^$.*+?()[\]{}|]/g
2
+ const REGEX_HAS_SPECIAL = RegExp(REGEX_SPECIAL.source)
3
+
4
+ /**
5
+ * @param {string|RegExp|Array<string|RegExp>} source
6
+ */
7
+ function toSource(source) {
8
+ source = Array.isArray(source) ? source : [source]
9
+
10
+ source = source.map((item) => (item instanceof RegExp ? item.source : item))
11
+
12
+ return source.join('')
13
+ }
14
+
15
+ /**
16
+ * @param {string|RegExp|Array<string|RegExp>} source
17
+ */
18
+ export function pattern(source) {
19
+ return new RegExp(toSource(source), 'g')
20
+ }
21
+
22
+ /**
23
+ * @param {string|RegExp|Array<string|RegExp>} source
24
+ */
25
+ export function withoutCapturing(source) {
26
+ return new RegExp(`(?:${toSource(source)})`, 'g')
27
+ }
28
+
29
+ /**
30
+ * @param {Array<string|RegExp>} sources
31
+ */
32
+ export function any(sources) {
33
+ return `(?:${sources.map(toSource).join('|')})`
34
+ }
35
+
36
+ /**
37
+ * @param {string|RegExp} source
38
+ */
39
+ export function optional(source) {
40
+ return `(?:${toSource(source)})?`
41
+ }
42
+
43
+ /**
44
+ * @param {string|RegExp|Array<string|RegExp>} source
45
+ */
46
+ export function zeroOrMore(source) {
47
+ return `(?:${toSource(source)})*`
48
+ }
49
+
50
+ /**
51
+ * Generate a RegExp that matches balanced brackets for a given depth
52
+ * We have to specify a depth because JS doesn't support recursive groups using ?R
53
+ *
54
+ * Based on https://stackoverflow.com/questions/17759004/how-to-match-string-within-parentheses-nested-in-java/17759264#17759264
55
+ *
56
+ * @param {string|RegExp|Array<string|RegExp>} source
57
+ */
58
+ export function nestedBrackets(open, close, depth = 1) {
59
+ return withoutCapturing([
60
+ escape(open),
61
+ /[^\s]*/,
62
+ depth === 1
63
+ ? `[^${escape(open)}${escape(close)}\s]*`
64
+ : any([`[^${escape(open)}${escape(close)}\s]*`, nestedBrackets(open, close, depth - 1)]),
65
+ /[^\s]*/,
66
+ escape(close),
67
+ ])
68
+ }
69
+
70
+ export function escape(string) {
71
+ return string && REGEX_HAS_SPECIAL.test(string)
72
+ ? string.replace(REGEX_SPECIAL, '\\$&')
73
+ : string || ''
74
+ }
@@ -91,52 +91,73 @@ export default function resolveDefaultsAtRules({ tailwindConfig }) {
91
91
  rule.remove()
92
92
  })
93
93
 
94
- for (let universal of universals) {
95
- /** @type {Map<string, Set<string>>} */
96
- let selectorGroups = new Map()
94
+ if (flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
95
+ for (let universal of universals) {
96
+ /** @type {Map<string, Set<string>>} */
97
+ let selectorGroups = new Map()
98
+
99
+ let rules = variableNodeMap.get(universal.params) ?? []
100
+
101
+ for (let rule of rules) {
102
+ for (let selector of extractElementSelector(rule.selector)) {
103
+ // If selector contains a vendor prefix after a pseudo element or class,
104
+ // we consider them separately because merging the declarations into
105
+ // a single rule will cause browsers that do not understand the
106
+ // vendor prefix to throw out the whole rule
107
+ let selectorGroupName =
108
+ selector.includes(':-') || selector.includes('::-') ? selector : '__DEFAULT__'
109
+
110
+ let selectors = selectorGroups.get(selectorGroupName) ?? new Set()
111
+ selectorGroups.set(selectorGroupName, selectors)
112
+
113
+ selectors.add(selector)
114
+ }
115
+ }
97
116
 
98
- let rules = variableNodeMap.get(universal.params) ?? []
117
+ if (flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
118
+ if (selectorGroups.size === 0) {
119
+ universal.remove()
120
+ continue
121
+ }
99
122
 
100
- for (let rule of rules) {
101
- for (let selector of extractElementSelector(rule.selector)) {
102
- // If selector contains a vendor prefix after a pseudo element or class,
103
- // we consider them separately because merging the declarations into
104
- // a single rule will cause browsers that do not understand the
105
- // vendor prefix to throw out the whole rule
106
- let selectorGroupName =
107
- selector.includes(':-') || selector.includes('::-') ? selector : '__DEFAULT__'
123
+ for (let [, selectors] of selectorGroups) {
124
+ let universalRule = postcss.rule({
125
+ source: universal.source,
126
+ })
108
127
 
109
- let selectors = selectorGroups.get(selectorGroupName) ?? new Set()
110
- selectorGroups.set(selectorGroupName, selectors)
128
+ universalRule.selectors = [...selectors]
111
129
 
112
- selectors.add(selector)
130
+ universalRule.append(universal.nodes.map((node) => node.clone()))
131
+ universal.before(universalRule)
132
+ }
113
133
  }
114
- }
115
134
 
116
- if (selectorGroups.size === 0) {
117
135
  universal.remove()
118
- continue
119
136
  }
137
+ } else if (universals.size) {
138
+ let universalRule = postcss.rule({
139
+ selectors: ['*', '::before', '::after'],
140
+ })
120
141
 
121
- if (flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
122
- for (let [, selectors] of selectorGroups) {
123
- let universalRule = postcss.rule()
124
-
125
- universalRule.selectors = [...selectors]
142
+ for (let universal of universals) {
143
+ universalRule.append(universal.nodes)
126
144
 
127
- universalRule.append(universal.nodes.map((node) => node.clone()))
145
+ if (!universalRule.parent) {
128
146
  universal.before(universalRule)
129
147
  }
130
- } else {
131
- let universalRule = postcss.rule()
132
148
 
133
- universalRule.selectors = ['*', '::before', '::after']
149
+ if (!universalRule.source) {
150
+ universalRule.source = universal.source
151
+ }
134
152
 
135
- universalRule.append(universal.nodes)
136
- universal.before(universalRule)
153
+ universal.remove()
137
154
  }
138
155
 
139
- universal.remove()
156
+ let backdropRule = universalRule.clone({
157
+ selectors: ['::backdrop'],
158
+ })
159
+
160
+ universalRule.after(backdropRule)
140
161
  }
141
162
  }
142
163
  }