tailwindcss 3.1.8 → 3.2.1
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 +64 -3
- package/README.md +6 -5
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +44 -0
- package/lib/cli/build/plugin.js +351 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +113 -0
- package/lib/cli/help/index.js +71 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/init/index.js +46 -0
- package/lib/cli/shared.js +12 -0
- package/lib/cli.js +11 -590
- package/lib/corePlugins.js +332 -108
- package/lib/css/preflight.css +5 -0
- package/lib/featureFlags.js +7 -4
- package/lib/index.js +6 -1
- package/lib/lib/content.js +167 -0
- package/lib/lib/defaultExtractor.js +15 -10
- package/lib/lib/detectNesting.js +2 -2
- package/lib/lib/evaluateTailwindFunctions.js +17 -1
- package/lib/lib/expandApplyAtRules.js +66 -37
- package/lib/lib/expandTailwindAtRules.js +10 -42
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +180 -93
- package/lib/lib/normalizeTailwindDirectives.js +1 -1
- package/lib/lib/offsets.js +217 -0
- package/lib/lib/regex.js +1 -1
- package/lib/lib/setupContextUtils.js +339 -100
- package/lib/lib/setupTrackingContext.js +5 -39
- package/lib/lib/sharedState.js +2 -0
- package/lib/public/colors.js +1 -1
- package/lib/util/buildMediaQuery.js +6 -3
- package/lib/util/configurePlugins.js +1 -1
- package/lib/util/dataTypes.js +15 -19
- package/lib/util/formatVariantSelector.js +92 -8
- package/lib/util/getAllConfigs.js +14 -3
- package/lib/util/isValidArbitraryValue.js +1 -1
- package/lib/util/nameClass.js +3 -0
- package/lib/util/negateValue.js +15 -2
- package/lib/util/normalizeConfig.js +17 -3
- package/lib/util/normalizeScreens.js +100 -3
- package/lib/util/parseAnimationValue.js +1 -1
- package/lib/util/parseBoxShadowValue.js +1 -1
- package/lib/util/parseDependency.js +33 -54
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +1 -1
- package/lib/util/pluginUtils.js +87 -17
- package/lib/util/resolveConfig.js +2 -2
- package/lib/util/splitAtTopLevelOnly.js +31 -81
- package/lib/util/transformThemeValue.js +9 -2
- package/lib/util/validateConfig.js +1 -1
- package/lib/util/validateFormalSyntax.js +24 -0
- package/package.json +14 -13
- package/peers/index.js +3263 -1887
- package/plugin.d.ts +3 -3
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/src/cli/build/deps.js +56 -0
- package/src/cli/build/index.js +45 -0
- package/src/cli/build/plugin.js +417 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +134 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +3 -0
- package/src/cli/init/index.js +50 -0
- package/src/cli/shared.js +5 -0
- package/src/cli.js +4 -696
- package/src/corePlugins.js +262 -39
- package/src/css/preflight.css +5 -0
- package/src/featureFlags.js +12 -2
- package/src/index.js +5 -0
- package/src/lib/content.js +205 -0
- package/src/lib/defaultExtractor.js +3 -0
- package/src/lib/evaluateTailwindFunctions.js +22 -1
- package/src/lib/expandApplyAtRules.js +70 -29
- package/src/lib/expandTailwindAtRules.js +8 -46
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +223 -101
- package/src/lib/offsets.js +270 -0
- package/src/lib/setupContextUtils.js +376 -89
- package/src/lib/setupTrackingContext.js +4 -45
- package/src/lib/sharedState.js +2 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/dataTypes.js +15 -17
- package/src/util/formatVariantSelector.js +113 -9
- package/src/util/getAllConfigs.js +14 -2
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +10 -2
- package/src/util/normalizeConfig.js +22 -2
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +1 -1
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +96 -14
- package/src/util/resolveConfig.js +1 -1
- package/src/util/splitAtTopLevelOnly.js +23 -49
- package/src/util/transformThemeValue.js +9 -1
- package/src/util/validateFormalSyntax.js +34 -0
- package/stubs/defaultConfig.stub.js +20 -3
- package/types/config.d.ts +48 -13
- package/types/generated/default-theme.d.ts +11 -0
|
@@ -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
|
+
}
|