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
|
@@ -29,15 +29,117 @@ export function formatVariantSelector(current, ...others) {
|
|
|
29
29
|
return current
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Given any node in a selector this gets the "simple" selector it's a part of
|
|
34
|
+
* A simple selector is just a list of nodes without any combinators
|
|
35
|
+
* Technically :is(), :not(), :has(), etc… can have combinators but those are nested
|
|
36
|
+
* inside the relevant node and won't be picked up so they're fine to ignore
|
|
37
|
+
*
|
|
38
|
+
* @param {import('postcss-selector-parser').Node} node
|
|
39
|
+
* @returns {import('postcss-selector-parser').Node[]}
|
|
40
|
+
**/
|
|
41
|
+
function simpleSelectorForNode(node) {
|
|
42
|
+
/** @type {import('postcss-selector-parser').Node[]} */
|
|
43
|
+
let nodes = []
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
// Walk backwards until we hit a combinator node (or the start)
|
|
46
|
+
while (node.prev() && node.prev().type !== 'combinator') {
|
|
47
|
+
node = node.prev()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Now record all non-combinator nodes until we hit one (or the end)
|
|
51
|
+
while (node && node.type !== 'combinator') {
|
|
52
|
+
nodes.push(node)
|
|
53
|
+
node = node.next()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return nodes
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Resorts the nodes in a selector to ensure they're in the correct order
|
|
61
|
+
* Tags go before classes, and pseudo classes go after classes
|
|
62
|
+
*
|
|
63
|
+
* @param {import('postcss-selector-parser').Selector} sel
|
|
64
|
+
* @returns {import('postcss-selector-parser').Selector}
|
|
65
|
+
**/
|
|
66
|
+
function resortSelector(sel) {
|
|
67
|
+
sel.sort((a, b) => {
|
|
68
|
+
if (a.type === 'tag' && b.type === 'class') {
|
|
69
|
+
return -1
|
|
70
|
+
} else if (a.type === 'class' && b.type === 'tag') {
|
|
71
|
+
return 1
|
|
72
|
+
} else if (a.type === 'class' && b.type === 'pseudo' && b.value !== ':merge') {
|
|
73
|
+
return -1
|
|
74
|
+
} else if (a.type === 'pseudo' && a.value !== ':merge' && b.type === 'class') {
|
|
75
|
+
return 1
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return sel.index(a) - sel.index(b)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return sel
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function eliminateIrrelevantSelectors(sel, base) {
|
|
85
|
+
let hasClassesMatchingCandidate = false
|
|
86
|
+
|
|
87
|
+
sel.walk((child) => {
|
|
88
|
+
if (child.type === 'class' && child.value === base) {
|
|
89
|
+
hasClassesMatchingCandidate = true
|
|
90
|
+
return false // Stop walking
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
if (!hasClassesMatchingCandidate) {
|
|
95
|
+
sel.remove()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// We do NOT recursively eliminate sub selectors that don't have the base class
|
|
99
|
+
// as this is NOT a safe operation. For example, if we have:
|
|
100
|
+
// `.space-x-2 > :not([hidden]) ~ :not([hidden])`
|
|
101
|
+
// We cannot remove the [hidden] from the :not() because it would change the
|
|
102
|
+
// meaning of the selector.
|
|
103
|
+
|
|
104
|
+
// TODO: Can we do this for :matches, :is, and :where?
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function finalizeSelector(
|
|
108
|
+
format,
|
|
109
|
+
{
|
|
110
|
+
selector,
|
|
111
|
+
candidate,
|
|
112
|
+
context,
|
|
113
|
+
isArbitraryVariant,
|
|
114
|
+
|
|
115
|
+
// Split by the separator, but ignore the separator inside square brackets:
|
|
116
|
+
//
|
|
117
|
+
// E.g.: dark:lg:hover:[paint-order:markers]
|
|
118
|
+
// ┬ ┬ ┬ ┬
|
|
119
|
+
// │ │ │ ╰── We will not split here
|
|
120
|
+
// ╰──┴─────┴─────────────── We will split here
|
|
121
|
+
//
|
|
122
|
+
base = candidate
|
|
123
|
+
.split(new RegExp(`\\${context?.tailwindConfig?.separator ?? ':'}(?![^[]*\\])`))
|
|
124
|
+
.pop(),
|
|
125
|
+
}
|
|
126
|
+
) {
|
|
127
|
+
let ast = selectorParser().astSync(selector)
|
|
128
|
+
|
|
129
|
+
// We explicitly DO NOT prefix classes in arbitrary variants
|
|
130
|
+
if (context?.tailwindConfig?.prefix && !isArbitraryVariant) {
|
|
36
131
|
format = prefixSelector(context.tailwindConfig.prefix, format)
|
|
37
132
|
}
|
|
38
133
|
|
|
39
134
|
format = format.replace(PARENT, `.${escapeClassName(candidate)}`)
|
|
40
135
|
|
|
136
|
+
let formatAst = selectorParser().astSync(format)
|
|
137
|
+
|
|
138
|
+
// Remove extraneous selectors that do not include the base class/candidate being matched against
|
|
139
|
+
// For example if we have a utility defined `.a, .b { color: red}`
|
|
140
|
+
// And the formatted variant is sm:b then we want the final selector to be `.sm\:b` and not `.a, .sm\:b`
|
|
141
|
+
ast.each((sel) => eliminateIrrelevantSelectors(sel, base))
|
|
142
|
+
|
|
41
143
|
// Normalize escaped classes, e.g.:
|
|
42
144
|
//
|
|
43
145
|
// The idea would be to replace the escaped `base` in the selector with the
|
|
@@ -49,34 +151,146 @@ export function finalizeSelector(format, { selector, candidate, context }) {
|
|
|
49
151
|
// base in selector: bg-\\[rgb\\(255\\,0\\,0\\)\\]
|
|
50
152
|
// escaped base: bg-\\[rgb\\(255\\2c 0\\2c 0\\)\\]
|
|
51
153
|
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
154
|
+
ast.walkClasses((node) => {
|
|
155
|
+
if (node.raws && node.value.includes(base)) {
|
|
156
|
+
node.raws.value = escapeClassName(unescape(node.raws.value))
|
|
157
|
+
}
|
|
158
|
+
})
|
|
57
159
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}).processSync(selector)
|
|
160
|
+
let simpleStart = selectorParser.comment({ value: '/*__simple__*/' })
|
|
161
|
+
let simpleEnd = selectorParser.comment({ value: '/*__simple__*/' })
|
|
61
162
|
|
|
62
163
|
// We can safely replace the escaped base now, since the `base` section is
|
|
63
164
|
// now in a normalized escaped value.
|
|
64
|
-
|
|
165
|
+
ast.walkClasses((node) => {
|
|
166
|
+
if (node.value !== base) {
|
|
167
|
+
return
|
|
168
|
+
}
|
|
65
169
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return selectors.map((selector) => {
|
|
69
|
-
selector.walkPseudos((p) => {
|
|
70
|
-
if (selectorFunctions.has(p.value)) {
|
|
71
|
-
p.replaceWith(p.nodes)
|
|
72
|
-
}
|
|
170
|
+
let parent = node.parent
|
|
171
|
+
let formatNodes = formatAst.nodes[0].nodes
|
|
73
172
|
|
|
74
|
-
|
|
75
|
-
|
|
173
|
+
// Perf optimization: if the parent is a single class we can just replace it and be done
|
|
174
|
+
if (parent.nodes.length === 1) {
|
|
175
|
+
node.replaceWith(...formatNodes)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let simpleSelector = simpleSelectorForNode(node)
|
|
180
|
+
parent.insertBefore(simpleSelector[0], simpleStart)
|
|
181
|
+
parent.insertAfter(simpleSelector[simpleSelector.length - 1], simpleEnd)
|
|
182
|
+
|
|
183
|
+
for (let child of formatNodes) {
|
|
184
|
+
parent.insertBefore(simpleSelector[0], child)
|
|
185
|
+
}
|
|
76
186
|
|
|
77
|
-
|
|
187
|
+
node.remove()
|
|
188
|
+
|
|
189
|
+
// Re-sort the simple selector to ensure it's in the correct order
|
|
190
|
+
simpleSelector = simpleSelectorForNode(simpleStart)
|
|
191
|
+
let firstNode = parent.index(simpleStart)
|
|
192
|
+
|
|
193
|
+
parent.nodes.splice(
|
|
194
|
+
firstNode,
|
|
195
|
+
simpleSelector.length,
|
|
196
|
+
...resortSelector(selectorParser.selector({ nodes: simpleSelector })).nodes
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
simpleStart.remove()
|
|
200
|
+
simpleEnd.remove()
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
// This will make sure to move pseudo's to the correct spot (the end for
|
|
204
|
+
// pseudo elements) because otherwise the selector will never work
|
|
205
|
+
// anyway.
|
|
206
|
+
//
|
|
207
|
+
// E.g.:
|
|
208
|
+
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
209
|
+
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
210
|
+
//
|
|
211
|
+
// `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
|
|
212
|
+
function collectPseudoElements(selector) {
|
|
213
|
+
let nodes = []
|
|
214
|
+
|
|
215
|
+
for (let node of selector.nodes) {
|
|
216
|
+
if (isPseudoElement(node)) {
|
|
217
|
+
nodes.push(node)
|
|
218
|
+
selector.removeChild(node)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (node?.nodes) {
|
|
222
|
+
nodes.push(...collectPseudoElements(node))
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return nodes
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Remove unnecessary pseudo selectors that we used as placeholders
|
|
230
|
+
ast.each((selector) => {
|
|
231
|
+
selector.walkPseudos((p) => {
|
|
232
|
+
if (selectorFunctions.has(p.value)) {
|
|
233
|
+
p.replaceWith(p.nodes)
|
|
234
|
+
}
|
|
78
235
|
})
|
|
79
|
-
|
|
236
|
+
|
|
237
|
+
let pseudoElements = collectPseudoElements(selector)
|
|
238
|
+
if (pseudoElements.length > 0) {
|
|
239
|
+
selector.nodes.push(pseudoElements.sort(sortSelector))
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
return ast.toString()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Note: As a rule, double colons (::) should be used instead of a single colon
|
|
247
|
+
// (:). This distinguishes pseudo-classes from pseudo-elements. However, since
|
|
248
|
+
// this distinction was not present in older versions of the W3C spec, most
|
|
249
|
+
// browsers support both syntaxes for the original pseudo-elements.
|
|
250
|
+
let pseudoElementsBC = [':before', ':after', ':first-line', ':first-letter']
|
|
251
|
+
|
|
252
|
+
// These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
|
|
253
|
+
let pseudoElementExceptions = ['::file-selector-button']
|
|
254
|
+
|
|
255
|
+
// This will make sure to move pseudo's to the correct spot (the end for
|
|
256
|
+
// pseudo elements) because otherwise the selector will never work
|
|
257
|
+
// anyway.
|
|
258
|
+
//
|
|
259
|
+
// E.g.:
|
|
260
|
+
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
261
|
+
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
262
|
+
//
|
|
263
|
+
// `::before:hover` doesn't work, which means that we can make it work
|
|
264
|
+
// for you by flipping the order.
|
|
265
|
+
function sortSelector(a, z) {
|
|
266
|
+
// Both nodes are non-pseudo's so we can safely ignore them and keep
|
|
267
|
+
// them in the same order.
|
|
268
|
+
if (a.type !== 'pseudo' && z.type !== 'pseudo') {
|
|
269
|
+
return 0
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// If one of them is a combinator, we need to keep it in the same order
|
|
273
|
+
// because that means it will start a new "section" in the selector.
|
|
274
|
+
if ((a.type === 'combinator') ^ (z.type === 'combinator')) {
|
|
275
|
+
return 0
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// One of the items is a pseudo and the other one isn't. Let's move
|
|
279
|
+
// the pseudo to the right.
|
|
280
|
+
if ((a.type === 'pseudo') ^ (z.type === 'pseudo')) {
|
|
281
|
+
return (a.type === 'pseudo') - (z.type === 'pseudo')
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Both are pseudo's, move the pseudo elements (except for
|
|
285
|
+
// ::file-selector-button) to the right.
|
|
286
|
+
return isPseudoElement(a) - isPseudoElement(z)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function isPseudoElement(node) {
|
|
290
|
+
if (node.type !== 'pseudo') return false
|
|
291
|
+
if (pseudoElementExceptions.includes(node.value)) return false
|
|
292
|
+
|
|
293
|
+
return node.value.startsWith('::') || pseudoElementsBC.includes(node.value)
|
|
80
294
|
}
|
|
81
295
|
|
|
82
296
|
function resolveFunctionArgument(haystack, needle, arg) {
|
|
@@ -9,6 +9,25 @@ export default function getAllConfigs(config) {
|
|
|
9
9
|
|
|
10
10
|
const features = {
|
|
11
11
|
// Add experimental configs here...
|
|
12
|
+
respectDefaultRingColorOpacity: {
|
|
13
|
+
theme: {
|
|
14
|
+
ringColor: ({ theme }) => ({
|
|
15
|
+
DEFAULT: '#3b82f67f',
|
|
16
|
+
...theme('colors'),
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
disableColorOpacityUtilitiesByDefault: {
|
|
22
|
+
corePlugins: {
|
|
23
|
+
backgroundOpacity: false,
|
|
24
|
+
borderOpacity: false,
|
|
25
|
+
divideOpacity: false,
|
|
26
|
+
placeholderOpacity: false,
|
|
27
|
+
ringOpacity: false,
|
|
28
|
+
textOpacity: false,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
12
31
|
}
|
|
13
32
|
|
|
14
33
|
const experimentals = Object.keys(features)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
let matchingBrackets = new Map([
|
|
2
|
+
['{', '}'],
|
|
3
|
+
['[', ']'],
|
|
4
|
+
['(', ')'],
|
|
5
|
+
])
|
|
6
|
+
let inverseMatchingBrackets = new Map(
|
|
7
|
+
Array.from(matchingBrackets.entries()).map(([k, v]) => [v, k])
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
let quotes = new Set(['"', "'", '`'])
|
|
11
|
+
|
|
12
|
+
// Arbitrary values must contain balanced brackets (), [] and {}. Escaped
|
|
13
|
+
// values don't count, and brackets inside quotes also don't count.
|
|
14
|
+
//
|
|
15
|
+
// E.g.: w-[this-is]w-[weird-and-invalid]
|
|
16
|
+
// E.g.: w-[this-is\\]w-\\[weird-but-valid]
|
|
17
|
+
// E.g.: content-['this-is-also-valid]-weirdly-enough']
|
|
18
|
+
export default function isValidArbitraryValue(value) {
|
|
19
|
+
let stack = []
|
|
20
|
+
let inQuotes = false
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < value.length; i++) {
|
|
23
|
+
let char = value[i]
|
|
24
|
+
|
|
25
|
+
if (char === ':' && !inQuotes && stack.length === 0) {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Non-escaped quotes allow us to "allow" anything in between
|
|
30
|
+
if (quotes.has(char) && value[i - 1] !== '\\') {
|
|
31
|
+
inQuotes = !inQuotes
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (inQuotes) continue
|
|
35
|
+
if (value[i - 1] === '\\') continue // Escaped
|
|
36
|
+
|
|
37
|
+
if (matchingBrackets.has(char)) {
|
|
38
|
+
stack.push(char)
|
|
39
|
+
} else if (inverseMatchingBrackets.has(char)) {
|
|
40
|
+
let inverse = inverseMatchingBrackets.get(char)
|
|
41
|
+
|
|
42
|
+
// Nothing to pop from, therefore it is unbalanced
|
|
43
|
+
if (stack.length <= 0) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Popped value must match the inverse value, otherwise it is unbalanced
|
|
48
|
+
if (stack.pop() !== inverse) {
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// If there is still something on the stack, it is also unbalanced
|
|
55
|
+
if (stack.length > 0) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// All good, totally balanced!
|
|
60
|
+
return true
|
|
61
|
+
}
|
package/src/util/log.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import colors from 'picocolors'
|
|
2
2
|
|
|
3
3
|
let alreadyShown = new Set()
|
|
4
4
|
|
|
5
|
-
function log(
|
|
6
|
-
if (process.env.JEST_WORKER_ID
|
|
5
|
+
function log(type, messages, key) {
|
|
6
|
+
if (typeof process !== 'undefined' && process.env.JEST_WORKER_ID) return
|
|
7
7
|
|
|
8
8
|
if (key && alreadyShown.has(key)) return
|
|
9
9
|
if (key) alreadyShown.add(key)
|
|
10
10
|
|
|
11
11
|
console.warn('')
|
|
12
|
-
messages.forEach((message) => console.warn(
|
|
12
|
+
messages.forEach((message) => console.warn(type, '-', message))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function dim(input) {
|
|
16
|
+
return colors.dim(input)
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
export default {
|
|
16
20
|
info(key, messages) {
|
|
17
|
-
log(
|
|
21
|
+
log(colors.bold(colors.cyan('info')), ...(Array.isArray(key) ? [key] : [messages, key]))
|
|
18
22
|
},
|
|
19
23
|
warn(key, messages) {
|
|
20
|
-
log(
|
|
24
|
+
log(colors.bold(colors.yellow('warn')), ...(Array.isArray(key) ? [key] : [messages, key]))
|
|
21
25
|
},
|
|
22
26
|
risk(key, messages) {
|
|
23
|
-
log(
|
|
27
|
+
log(colors.bold(colors.magenta('risk')), ...(Array.isArray(key) ? [key] : [messages, key]))
|
|
24
28
|
},
|
|
25
29
|
}
|
package/src/util/nameClass.js
CHANGED
package/src/util/negateValue.js
CHANGED
|
@@ -10,7 +10,15 @@ export default function (value) {
|
|
|
10
10
|
return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-'))
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
// What functions we support negating numeric values for
|
|
14
|
+
// var() isn't inherently a numeric function but we support it anyway
|
|
15
|
+
// The trigonometric functions are omitted because you'll need to use calc(…) with them _anyway_
|
|
16
|
+
// to produce generally useful results and that will be covered already
|
|
17
|
+
let numericFunctions = ['var', 'calc', 'min', 'max', 'clamp']
|
|
18
|
+
|
|
19
|
+
for (const fn of numericFunctions) {
|
|
20
|
+
if (value.includes(`${fn}(`)) {
|
|
21
|
+
return `calc(${value} * -1)`
|
|
22
|
+
}
|
|
15
23
|
}
|
|
16
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import log from './log'
|
|
1
|
+
import log, { dim } from './log'
|
|
2
2
|
|
|
3
3
|
export function normalizeConfig(config) {
|
|
4
4
|
// Quick structure validation
|
|
@@ -124,7 +124,7 @@ export function normalizeConfig(config) {
|
|
|
124
124
|
log.warn('purge-deprecation', [
|
|
125
125
|
'The `purge`/`content` options have changed in Tailwind CSS v3.0.',
|
|
126
126
|
'Update your configuration file to eliminate this warning.',
|
|
127
|
-
|
|
127
|
+
'https://tailwindcss.com/docs/upgrade-guide#configure-content-sources',
|
|
128
128
|
])
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -145,7 +145,7 @@ export function normalizeConfig(config) {
|
|
|
145
145
|
log.warn('prefix-function', [
|
|
146
146
|
'As of Tailwind CSS v3.0, `prefix` cannot be a function.',
|
|
147
147
|
'Update `prefix` in your configuration to be a string to eliminate this warning.',
|
|
148
|
-
|
|
148
|
+
'https://tailwindcss.com/docs/upgrade-guide#prefix-cannot-be-a-function',
|
|
149
149
|
])
|
|
150
150
|
config.prefix = ''
|
|
151
151
|
} else {
|
|
@@ -245,5 +245,18 @@ export function normalizeConfig(config) {
|
|
|
245
245
|
})(),
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
// Validate globs to prevent bogus globs.
|
|
249
|
+
// E.g.: `./src/*.{html}` is invalid, the `{html}` should just be `html`
|
|
250
|
+
for (let file of config.content.files) {
|
|
251
|
+
if (typeof file === 'string' && /{([^,]*?)}/g.test(file)) {
|
|
252
|
+
log.warn('invalid-glob-braces', [
|
|
253
|
+
`The glob pattern ${dim(file)} in your Tailwind CSS configuration is invalid.`,
|
|
254
|
+
`Update it to ${dim(file.replace(/{([^,]*?)}/g, '$1'))} to silence this warning.`,
|
|
255
|
+
// TODO: Add https://tw.wtf/invalid-glob-braces
|
|
256
|
+
])
|
|
257
|
+
break
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
248
261
|
return config
|
|
249
262
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function that normalizes the various forms that the screens object can be
|
|
3
|
+
* provided in.
|
|
4
|
+
*
|
|
5
|
+
* Input(s):
|
|
6
|
+
* - ['100px', '200px'] // Raw strings
|
|
7
|
+
* - { sm: '100px', md: '200px' } // Object with string values
|
|
8
|
+
* - { sm: { min: '100px' }, md: { max: '100px' } } // Object with object values
|
|
9
|
+
* - { sm: [{ min: '100px' }, { max: '200px' }] } // Object with object array (multiple values)
|
|
10
|
+
*
|
|
11
|
+
* Output(s):
|
|
12
|
+
* - [{ name: 'sm', values: [{ min: '100px', max: '200px' }] }] // List of objects, that contains multiple values
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeScreens(screens, root = true) {
|
|
15
|
+
if (Array.isArray(screens)) {
|
|
16
|
+
return screens.map((screen) => {
|
|
17
|
+
if (root && Array.isArray(screen)) {
|
|
18
|
+
throw new Error('The tuple syntax is not supported for `screens`.')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof screen === 'string') {
|
|
22
|
+
return { name: screen.toString(), values: [{ min: screen, max: undefined }] }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let [name, options] = screen
|
|
26
|
+
name = name.toString()
|
|
27
|
+
|
|
28
|
+
if (typeof options === 'string') {
|
|
29
|
+
return { name, values: [{ min: options, max: undefined }] }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(options)) {
|
|
33
|
+
return { name, values: options.map((option) => resolveValue(option)) }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { name, values: [resolveValue(options)] }
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return normalizeScreens(Object.entries(screens ?? {}), false)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function resolveValue({ 'min-width': _minWidth, min = _minWidth, max, raw } = {}) {
|
|
44
|
+
return { min, max, raw }
|
|
45
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
|
|
2
|
+
|
|
1
3
|
let KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
|
|
2
|
-
let COMMA = /\,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
|
|
3
4
|
let SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
|
4
|
-
let LENGTH = /^-?(\d+)(.*?)$/g
|
|
5
|
+
let LENGTH = /^-?(\d+|\.\d+)(.*?)$/g
|
|
5
6
|
|
|
6
7
|
export function parseBoxShadowValue(input) {
|
|
7
|
-
let shadows = input
|
|
8
|
+
let shadows = splitAtTopLevelOnly(input, ',')
|
|
8
9
|
return shadows.map((shadow) => {
|
|
9
10
|
let value = shadow.trim()
|
|
10
11
|
let result = { raw: value }
|
package/src/util/pluginUtils.js
CHANGED
|
@@ -95,9 +95,19 @@ function splitAlpha(modifier) {
|
|
|
95
95
|
return [modifier.slice(0, slashIdx), modifier.slice(slashIdx + 1)]
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
export function parseColorFormat(value) {
|
|
99
|
+
if (typeof value === 'string' && value.includes('<alpha-value>')) {
|
|
100
|
+
let oldValue = value
|
|
101
|
+
|
|
102
|
+
return ({ opacityValue = 1 }) => oldValue.replace('<alpha-value>', opacityValue)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return value
|
|
106
|
+
}
|
|
107
|
+
|
|
98
108
|
export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
|
|
99
109
|
if (options.values?.[modifier] !== undefined) {
|
|
100
|
-
return options.values?.[modifier]
|
|
110
|
+
return parseColorFormat(options.values?.[modifier])
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
let [color, alpha] = splitAlpha(modifier)
|
|
@@ -110,6 +120,8 @@ export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
|
|
|
110
120
|
return undefined
|
|
111
121
|
}
|
|
112
122
|
|
|
123
|
+
normalizedColor = parseColorFormat(normalizedColor)
|
|
124
|
+
|
|
113
125
|
if (isArbitraryValue(alpha)) {
|
|
114
126
|
return withAlphaValue(normalizedColor, alpha.slice(1, -1))
|
|
115
127
|
}
|
|
@@ -185,7 +197,7 @@ export function coerceValue(types, modifier, options, tailwindConfig) {
|
|
|
185
197
|
// Find first matching type
|
|
186
198
|
for (let type of [].concat(types)) {
|
|
187
199
|
let result = typeMap[type](modifier, options, { tailwindConfig })
|
|
188
|
-
if (result) return [result, type]
|
|
200
|
+
if (result !== undefined) return [result, type]
|
|
189
201
|
}
|
|
190
202
|
|
|
191
203
|
return []
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import parser from 'postcss-selector-parser'
|
|
2
|
-
import { tap } from './tap'
|
|
3
2
|
|
|
4
|
-
export default function (prefix, selector) {
|
|
3
|
+
export default function (prefix, selector, prependNegative = false) {
|
|
5
4
|
return parser((selectors) => {
|
|
6
5
|
selectors.walkClasses((classSelector) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
let baseClass = classSelector.value
|
|
7
|
+
let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
|
|
8
|
+
|
|
9
|
+
classSelector.value = shouldPlaceNegativeBeforePrefix
|
|
10
|
+
? `-${prefix}${baseClass.slice(1)}`
|
|
11
|
+
: `${prefix}${baseClass}`
|
|
10
12
|
})
|
|
11
13
|
}).processSync(selector)
|
|
12
14
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function removes any uses of CSS variables used as an alpha channel
|
|
3
|
+
*
|
|
4
|
+
* This is required for selectors like `:visited` which do not allow
|
|
5
|
+
* changes in opacity or external control using CSS variables.
|
|
6
|
+
*
|
|
7
|
+
* @param {import('postcss').Container} container
|
|
8
|
+
* @param {string[]} toRemove
|
|
9
|
+
*/
|
|
10
|
+
export function removeAlphaVariables(container, toRemove) {
|
|
11
|
+
container.walkDecls((decl) => {
|
|
12
|
+
if (toRemove.includes(decl.prop)) {
|
|
13
|
+
decl.remove()
|
|
14
|
+
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
for (let varName of toRemove) {
|
|
19
|
+
if (decl.value.includes(`/ var(${varName})`)) {
|
|
20
|
+
decl.value = decl.value.replace(`/ var(${varName})`, '')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|