tailwindcss 0.0.0-insiders.4e21639 → 0.0.0-insiders.4e62334
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.
- package/CHANGELOG.md +435 -3
- package/LICENSE +1 -2
- package/README.md +13 -6
- package/colors.d.ts +3 -0
- package/colors.js +2 -1
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -1
- package/defaultTheme.d.ts +4 -0
- package/defaultTheme.js +2 -1
- package/lib/cli-peer-dependencies.js +20 -7
- package/lib/cli.js +460 -259
- package/lib/constants.js +27 -20
- package/lib/corePluginList.js +9 -3
- package/lib/corePlugins.js +1840 -1753
- package/lib/css/preflight.css +8 -9
- package/lib/featureFlags.js +29 -20
- package/lib/index.js +22 -11
- package/lib/lib/cacheInvalidation.js +90 -0
- package/lib/lib/collapseAdjacentRules.js +27 -9
- package/lib/lib/collapseDuplicateDeclarations.js +58 -4
- package/lib/lib/defaultExtractor.js +231 -0
- package/lib/lib/detectNesting.js +13 -10
- package/lib/lib/evaluateTailwindFunctions.js +119 -52
- package/lib/lib/expandApplyAtRules.js +440 -161
- package/lib/lib/expandTailwindAtRules.js +130 -128
- package/lib/lib/generateRules.js +410 -171
- package/lib/lib/getModuleDependencies.js +11 -8
- package/lib/lib/normalizeTailwindDirectives.js +43 -32
- package/lib/lib/offsets.js +199 -0
- package/lib/lib/partitionApplyAtRules.js +56 -0
- package/lib/lib/regex.js +60 -0
- package/lib/lib/resolveDefaultsAtRules.js +91 -55
- package/lib/lib/setupContextUtils.js +453 -347
- package/lib/lib/setupTrackingContext.js +52 -44
- package/lib/lib/sharedState.js +48 -9
- package/lib/lib/substituteScreenAtRules.js +13 -8
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +19 -0
- package/lib/postcss-plugins/nesting/plugin.js +87 -0
- package/lib/processTailwindFeatures.js +36 -25
- package/lib/public/colors.js +247 -245
- package/lib/public/create-plugin.js +6 -4
- package/lib/public/default-config.js +7 -5
- package/lib/public/default-theme.js +7 -5
- package/lib/public/resolve-config.js +8 -5
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +16 -25
- package/lib/util/cloneDeep.js +7 -6
- package/lib/util/cloneNodes.js +21 -3
- package/lib/util/color.js +54 -40
- package/lib/util/configurePlugins.js +4 -1
- package/lib/util/createPlugin.js +6 -6
- package/lib/util/createUtilityPlugin.js +12 -14
- package/lib/util/dataTypes.js +119 -102
- package/lib/util/defaults.js +10 -1
- package/lib/util/escapeClassName.js +7 -4
- package/lib/util/escapeCommas.js +5 -2
- package/lib/util/flattenColorPalette.js +9 -12
- package/lib/util/formatVariantSelector.js +223 -40
- package/lib/util/getAllConfigs.js +27 -8
- package/lib/util/hashConfig.js +6 -3
- package/lib/util/isKeyframeRule.js +5 -2
- package/lib/util/isPlainObject.js +5 -2
- package/lib/util/isValidArbitraryValue.js +72 -0
- package/lib/util/log.js +22 -12
- package/lib/util/nameClass.js +17 -8
- package/lib/util/negateValue.js +22 -7
- package/lib/util/normalizeConfig.js +99 -54
- package/lib/util/normalizeScreens.js +73 -0
- package/lib/util/parseAnimationValue.js +42 -40
- package/lib/util/parseBoxShadowValue.js +30 -23
- package/lib/util/parseDependency.js +18 -15
- package/lib/util/parseObjectStyles.js +10 -7
- package/lib/util/pluginUtils.js +51 -42
- package/lib/util/prefixSelector.js +10 -8
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +91 -66
- package/lib/util/resolveConfigPath.js +11 -9
- package/lib/util/responsive.js +8 -5
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +4 -1
- package/lib/util/toColorValue.js +5 -3
- package/lib/util/toPath.js +24 -3
- package/lib/util/transformThemeValue.js +37 -29
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/withAlphaVariable.js +23 -15
- package/nesting/index.js +2 -12
- package/package.json +43 -43
- package/peers/index.js +11543 -8114
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.d.ts +3 -0
- package/resolveConfig.js +2 -1
- package/scripts/generate-types.js +105 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +293 -36
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +428 -285
- package/src/css/preflight.css +8 -9
- package/src/featureFlags.js +9 -5
- package/src/index.js +14 -6
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +66 -1
- package/src/lib/defaultExtractor.js +208 -0
- package/src/lib/evaluateTailwindFunctions.js +84 -10
- package/src/lib/expandApplyAtRules.js +488 -153
- package/src/lib/expandTailwindAtRules.js +82 -80
- package/src/lib/generateRules.js +352 -120
- package/src/lib/normalizeTailwindDirectives.js +7 -1
- package/src/lib/offsets.js +239 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +59 -17
- package/src/lib/setupContextUtils.js +337 -174
- package/src/lib/setupTrackingContext.js +13 -8
- package/src/lib/sharedState.js +42 -4
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +12 -2
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +31 -14
- package/src/util/dataTypes.js +28 -19
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +237 -23
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +11 -7
- package/src/util/nameClass.js +1 -1
- package/src/util/negateValue.js +10 -2
- package/src/util/normalizeConfig.js +16 -3
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +4 -3
- package/src/util/pluginUtils.js +14 -2
- package/src/util/prefixSelector.js +7 -5
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +71 -17
- package/src/util/splitAtTopLevelOnly.js +45 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +13 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/stubs/defaultConfig.stub.js +24 -3
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +334 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +331 -0
- package/types/index.d.ts +7 -0
- package/lib/lib/setupWatchingContext.js +0 -288
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -311
|
@@ -0,0 +1,239 @@
|
|
|
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} RuleOffset
|
|
11
|
+
* @property {Layer} layer The layer that this rule belongs to
|
|
12
|
+
* @property {Layer} parentLayer The layer that this rule originally belonged to. Only different from layer if this is a variant.
|
|
13
|
+
* @property {bigint} arbitrary 0n if false, 1n if true
|
|
14
|
+
* @property {bigint} variants Dynamic size. 1 bit per registered variant. 0n means no variants
|
|
15
|
+
* @property {bigint} parallelIndex Rule index for the parallel variant. 0 if not applicable.
|
|
16
|
+
* @property {bigint} index Index of the rule / utility in it's given *parent* layer. Monotonically increasing.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export class Offsets {
|
|
20
|
+
constructor() {
|
|
21
|
+
/**
|
|
22
|
+
* Offsets for the next rule in a given layer
|
|
23
|
+
*
|
|
24
|
+
* @type {Record<Layer, bigint>}
|
|
25
|
+
*/
|
|
26
|
+
this.offsets = {
|
|
27
|
+
defaults: 0n,
|
|
28
|
+
base: 0n,
|
|
29
|
+
components: 0n,
|
|
30
|
+
utilities: 0n,
|
|
31
|
+
variants: 0n,
|
|
32
|
+
user: 0n,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Positions for a given layer
|
|
37
|
+
*
|
|
38
|
+
* @type {Record<Layer, bigint>}
|
|
39
|
+
*/
|
|
40
|
+
this.layerPositions = {
|
|
41
|
+
defaults: 0n,
|
|
42
|
+
base: 1n,
|
|
43
|
+
components: 2n,
|
|
44
|
+
utilities: 3n,
|
|
45
|
+
|
|
46
|
+
// There isn't technically a "user" layer, but we need to give it a position
|
|
47
|
+
// Because it's used for ordering user-css from @apply
|
|
48
|
+
user: 4n,
|
|
49
|
+
|
|
50
|
+
variants: 5n,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The total number of functions currently registered across all variants (including arbitrary variants)
|
|
55
|
+
*
|
|
56
|
+
* @type {bigint}
|
|
57
|
+
*/
|
|
58
|
+
this.reservedVariantBits = 0n
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Positions for a given variant
|
|
62
|
+
*
|
|
63
|
+
* @type {Map<string, bigint>}
|
|
64
|
+
*/
|
|
65
|
+
this.variantOffsets = new Map()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {Layer} layer
|
|
70
|
+
* @returns {RuleOffset}
|
|
71
|
+
*/
|
|
72
|
+
create(layer) {
|
|
73
|
+
return {
|
|
74
|
+
layer,
|
|
75
|
+
parentLayer: layer,
|
|
76
|
+
arbitrary: 0n,
|
|
77
|
+
variants: 0n,
|
|
78
|
+
parallelIndex: 0n,
|
|
79
|
+
index: this.offsets[layer]++,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @returns {RuleOffset}
|
|
85
|
+
*/
|
|
86
|
+
arbitraryProperty() {
|
|
87
|
+
return {
|
|
88
|
+
...this.create('utilities'),
|
|
89
|
+
arbitrary: 1n,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the offset for a variant
|
|
95
|
+
*
|
|
96
|
+
* @param {string} variant
|
|
97
|
+
* @param {number} index
|
|
98
|
+
* @returns {RuleOffset}
|
|
99
|
+
*/
|
|
100
|
+
forVariant(variant, index = 0) {
|
|
101
|
+
let offset = this.variantOffsets.get(variant)
|
|
102
|
+
if (offset === undefined) {
|
|
103
|
+
throw new Error(`Cannot find offset for unknown variant ${variant}`)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
...this.create('variants'),
|
|
108
|
+
variants: offset << BigInt(index),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {RuleOffset} rule
|
|
114
|
+
* @param {RuleOffset} variant
|
|
115
|
+
* @returns {RuleOffset}
|
|
116
|
+
*/
|
|
117
|
+
applyVariantOffset(rule, variant) {
|
|
118
|
+
return {
|
|
119
|
+
...rule,
|
|
120
|
+
layer: 'variants',
|
|
121
|
+
parentLayer: rule.layer === 'variants' ? rule.parentLayer : rule.layer,
|
|
122
|
+
variants: rule.variants | variant.variants,
|
|
123
|
+
|
|
124
|
+
// TODO: Technically this is wrong. We should be handling parallel index on a per variant basis.
|
|
125
|
+
// We'll take the max of all the parallel indexes for now.
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
parallelIndex: max([rule.parallelIndex, variant.parallelIndex]),
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {RuleOffset} offset
|
|
133
|
+
* @param {number} parallelIndex
|
|
134
|
+
* @returns {RuleOffset}
|
|
135
|
+
*/
|
|
136
|
+
applyParallelOffset(offset, parallelIndex) {
|
|
137
|
+
return {
|
|
138
|
+
...offset,
|
|
139
|
+
parallelIndex: BigInt(parallelIndex),
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Each variant gets 1 bit per function / rule registered.
|
|
145
|
+
* 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.
|
|
146
|
+
* Additionally, every unique group of variants is grouped together in the stylesheet.
|
|
147
|
+
*
|
|
148
|
+
* This grouping is order-independent. For instance, we do not differentiate between `hover:focus` and `focus:hover`.
|
|
149
|
+
*
|
|
150
|
+
* @param {string[]} variants
|
|
151
|
+
* @param {(name: string) => number} getLength
|
|
152
|
+
*/
|
|
153
|
+
recordVariants(variants, getLength) {
|
|
154
|
+
for (const variant of variants) {
|
|
155
|
+
this.recordVariant(variant, getLength(variant))
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The same as `recordVariants` but for a single arbitrary variant at runtime.
|
|
161
|
+
* @param {string} variant
|
|
162
|
+
* @param {number} fnCount
|
|
163
|
+
*
|
|
164
|
+
* @returns {RuleOffset} The highest offset for this variant
|
|
165
|
+
*/
|
|
166
|
+
recordVariant(variant, fnCount = 1) {
|
|
167
|
+
this.variantOffsets.set(variant, 1n << this.reservedVariantBits)
|
|
168
|
+
|
|
169
|
+
// Ensure space is reserved for each "function" in the parallel variant
|
|
170
|
+
// by offsetting the next variant by the number of parallel variants
|
|
171
|
+
// in the one we just added.
|
|
172
|
+
|
|
173
|
+
// Single functions that return parallel variants are NOT handled separately here
|
|
174
|
+
// They're offset by 1 (or the number of functions) as usual
|
|
175
|
+
// And each rule returned is tracked separately since the functions are evaluated lazily.
|
|
176
|
+
// @see `RuleOffset.parallelIndex`
|
|
177
|
+
this.reservedVariantBits += BigInt(fnCount)
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
...this.create('variants'),
|
|
181
|
+
variants: 1n << this.reservedVariantBits,
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @param {RuleOffset} a
|
|
187
|
+
* @param {RuleOffset} b
|
|
188
|
+
* @returns {bigint}
|
|
189
|
+
*/
|
|
190
|
+
compare(a, b) {
|
|
191
|
+
// Sort layers together
|
|
192
|
+
if (a.layer !== b.layer) {
|
|
193
|
+
return this.layerPositions[a.layer] - this.layerPositions[b.layer]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Sort variants in the order they were registered
|
|
197
|
+
if (a.variants !== b.variants) {
|
|
198
|
+
return a.variants - b.variants
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Make sure each rule returned by a parallel variant is sorted in ascending order
|
|
202
|
+
if (a.parallelIndex !== b.parallelIndex) {
|
|
203
|
+
return a.parallelIndex - b.parallelIndex
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Always sort arbitrary properties after other utilities
|
|
207
|
+
if (a.arbitrary !== b.arbitrary) {
|
|
208
|
+
return a.arbitrary - b.arbitrary
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Sort utilities, components, etc… in the order they were registered
|
|
212
|
+
return a.index - b.index
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @template T
|
|
217
|
+
* @param {[RuleOffset, T][]} list
|
|
218
|
+
* @returns {[RuleOffset, T][]}
|
|
219
|
+
*/
|
|
220
|
+
sort(list) {
|
|
221
|
+
return list.sort(([a], [b]) => bigSign(this.compare(a, b)))
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
*
|
|
227
|
+
* @param {bigint[]} nums
|
|
228
|
+
* @returns {bigint|null}
|
|
229
|
+
*/
|
|
230
|
+
function max(nums) {
|
|
231
|
+
let max = null
|
|
232
|
+
|
|
233
|
+
for (const num of nums) {
|
|
234
|
+
max = max ?? num
|
|
235
|
+
max = max > num ? max : num
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return max
|
|
239
|
+
}
|
|
@@ -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
|
+
}
|
package/src/lib/regex.js
ADDED
|
@@ -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
|
+
}
|
|
@@ -71,6 +71,8 @@ function extractElementSelector(selector) {
|
|
|
71
71
|
export default function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
72
72
|
return (root) => {
|
|
73
73
|
let variableNodeMap = new Map()
|
|
74
|
+
|
|
75
|
+
/** @type {Set<import('postcss').AtRule>} */
|
|
74
76
|
let universals = new Set()
|
|
75
77
|
|
|
76
78
|
root.walkAtRules('defaults', (rule) => {
|
|
@@ -89,33 +91,73 @@ export default function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
|
89
91
|
rule.remove()
|
|
90
92
|
})
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
let
|
|
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) ?? []
|
|
94
100
|
|
|
95
|
-
|
|
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__'
|
|
96
109
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
let selectors = selectorGroups.get(selectorGroupName) ?? new Set()
|
|
111
|
+
selectorGroups.set(selectorGroupName, selectors)
|
|
112
|
+
|
|
113
|
+
selectors.add(selector)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
|
|
118
|
+
if (selectorGroups.size === 0) {
|
|
119
|
+
universal.remove()
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (let [, selectors] of selectorGroups) {
|
|
124
|
+
let universalRule = postcss.rule({
|
|
125
|
+
source: universal.source,
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
universalRule.selectors = [...selectors]
|
|
129
|
+
|
|
130
|
+
universalRule.append(universal.nodes.map((node) => node.clone()))
|
|
131
|
+
universal.before(universalRule)
|
|
132
|
+
}
|
|
100
133
|
}
|
|
101
|
-
}
|
|
102
134
|
|
|
103
|
-
if (selectors.size === 0) {
|
|
104
135
|
universal.remove()
|
|
105
|
-
continue
|
|
106
136
|
}
|
|
137
|
+
} else if (universals.size) {
|
|
138
|
+
let universalRule = postcss.rule({
|
|
139
|
+
selectors: ['*', '::before', '::after'],
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
for (let universal of universals) {
|
|
143
|
+
universalRule.append(universal.nodes)
|
|
107
144
|
|
|
108
|
-
|
|
145
|
+
if (!universalRule.parent) {
|
|
146
|
+
universal.before(universalRule)
|
|
147
|
+
}
|
|
109
148
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
if (!universalRule.source) {
|
|
150
|
+
universalRule.source = universal.source
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
universal.remove()
|
|
114
154
|
}
|
|
115
155
|
|
|
116
|
-
universalRule.
|
|
117
|
-
|
|
118
|
-
|
|
156
|
+
let backdropRule = universalRule.clone({
|
|
157
|
+
selectors: ['::backdrop'],
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
universalRule.after(backdropRule)
|
|
119
161
|
}
|
|
120
162
|
}
|
|
121
163
|
}
|