tailwindcss 0.0.0-insiders.d2b53cd → 0.0.0-insiders.d2fdf9e
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 +364 -2
- package/LICENSE +1 -2
- package/README.md +8 -4
- 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 +3 -0
- package/defaultTheme.js +2 -1
- package/lib/cli-peer-dependencies.js +10 -5
- package/lib/cli.js +306 -203
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +10 -1
- package/lib/corePlugins.js +1835 -1760
- package/lib/css/preflight.css +19 -13
- package/lib/featureFlags.js +18 -15
- package/lib/index.js +17 -8
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +30 -14
- package/lib/lib/collapseDuplicateDeclarations.js +80 -0
- package/lib/lib/defaultExtractor.js +187 -0
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +40 -24
- package/lib/lib/expandApplyAtRules.js +414 -157
- package/lib/lib/expandTailwindAtRules.js +145 -126
- package/lib/lib/generateRules.js +403 -103
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +43 -35
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/regex.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +83 -65
- package/lib/lib/setupContextUtils.js +315 -204
- package/lib/lib/setupTrackingContext.js +60 -56
- package/lib/lib/sharedState.js +38 -5
- package/lib/lib/substituteScreenAtRules.js +9 -6
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +19 -9
- package/lib/public/colors.js +241 -241
- package/lib/public/resolve-config.js +5 -5
- package/lib/util/buildMediaQuery.js +13 -24
- package/lib/util/cloneDeep.js +1 -1
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +43 -32
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +11 -15
- package/lib/util/dataTypes.js +114 -74
- package/lib/util/defaults.js +6 -0
- package/lib/util/escapeClassName.js +5 -5
- package/lib/util/escapeCommas.js +1 -1
- package/lib/util/flattenColorPalette.js +2 -4
- package/lib/util/formatVariantSelector.js +194 -0
- package/lib/util/getAllConfigs.js +13 -5
- package/lib/util/hashConfig.js +5 -5
- package/lib/util/isKeyframeRule.js +1 -1
- package/lib/util/isPlainObject.js +1 -1
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +11 -7
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +4 -4
- package/lib/util/normalizeConfig.js +84 -45
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseAnimationValue.js +56 -56
- package/lib/util/parseBoxShadowValue.js +76 -0
- package/lib/util/parseDependency.js +32 -32
- package/lib/util/parseObjectStyles.js +6 -6
- package/lib/util/pluginUtils.js +34 -165
- package/lib/util/prefixSelector.js +4 -7
- package/lib/util/resolveConfig.js +115 -66
- package/lib/util/resolveConfigPath.js +17 -18
- package/lib/util/responsive.js +6 -6
- package/lib/util/splitAtTopLevelOnly.js +72 -0
- package/lib/util/toColorValue.js +1 -2
- package/lib/util/toPath.js +6 -1
- package/lib/util/transformThemeValue.js +42 -34
- package/lib/util/validateConfig.js +21 -0
- package/lib/util/withAlphaVariable.js +19 -19
- package/nesting/index.js +2 -12
- package/package.json +39 -40
- package/peers/index.js +11511 -10819
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/generate-types.js +52 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +164 -30
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +540 -535
- package/src/css/preflight.css +19 -13
- package/src/featureFlags.js +5 -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 +93 -0
- package/src/lib/defaultExtractor.js +192 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +24 -7
- package/src/lib/expandApplyAtRules.js +442 -154
- package/src/lib/expandTailwindAtRules.js +79 -37
- package/src/lib/generateRules.js +400 -83
- package/src/lib/normalizeTailwindDirectives.js +7 -1
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +35 -10
- package/src/lib/setupContextUtils.js +273 -112
- package/src/lib/setupTrackingContext.js +12 -7
- 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 +14 -2
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- package/src/util/dataTypes.js +56 -16
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +213 -0
- package/src/util/getAllConfigs.js +7 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +10 -6
- package/src/util/nameClass.js +1 -1
- package/src/util/normalizeConfig.js +32 -3
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/pluginUtils.js +15 -138
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +97 -15
- package/src/util/splitAtTopLevelOnly.js +71 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +24 -7
- package/src/util/validateConfig.js +13 -0
- package/stubs/defaultConfig.stub.js +47 -17
- package/types/config.d.ts +325 -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/index.d.ts +1 -0
- package/types.d.ts +1 -0
- package/lib/lib/setupWatchingContext.js +0 -284
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -304
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import selectorParser from 'postcss-selector-parser'
|
|
2
|
+
import unescape from 'postcss-selector-parser/dist/util/unesc'
|
|
3
|
+
import escapeClassName from '../util/escapeClassName'
|
|
4
|
+
import prefixSelector from '../util/prefixSelector'
|
|
5
|
+
|
|
6
|
+
let MERGE = ':merge'
|
|
7
|
+
let PARENT = '&'
|
|
8
|
+
|
|
9
|
+
export let selectorFunctions = new Set([MERGE])
|
|
10
|
+
|
|
11
|
+
export function formatVariantSelector(current, ...others) {
|
|
12
|
+
for (let other of others) {
|
|
13
|
+
let incomingValue = resolveFunctionArgument(other, MERGE)
|
|
14
|
+
if (incomingValue !== null) {
|
|
15
|
+
let existingValue = resolveFunctionArgument(current, MERGE, incomingValue)
|
|
16
|
+
if (existingValue !== null) {
|
|
17
|
+
let existingTarget = `${MERGE}(${incomingValue})`
|
|
18
|
+
let splitIdx = other.indexOf(existingTarget)
|
|
19
|
+
let addition = other.slice(splitIdx + existingTarget.length).split(' ')[0]
|
|
20
|
+
|
|
21
|
+
current = current.replace(existingTarget, existingTarget + addition)
|
|
22
|
+
continue
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
current = other.replace(PARENT, current)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return current
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function finalizeSelector(
|
|
33
|
+
format,
|
|
34
|
+
{
|
|
35
|
+
selector,
|
|
36
|
+
candidate,
|
|
37
|
+
context,
|
|
38
|
+
|
|
39
|
+
// Split by the separator, but ignore the separator inside square brackets:
|
|
40
|
+
//
|
|
41
|
+
// E.g.: dark:lg:hover:[paint-order:markers]
|
|
42
|
+
// ┬ ┬ ┬ ┬
|
|
43
|
+
// │ │ │ ╰── We will not split here
|
|
44
|
+
// ╰──┴─────┴─────────────── We will split here
|
|
45
|
+
//
|
|
46
|
+
base = candidate
|
|
47
|
+
.split(new RegExp(`\\${context?.tailwindConfig?.separator ?? ':'}(?![^[]*\\])`))
|
|
48
|
+
.pop(),
|
|
49
|
+
}
|
|
50
|
+
) {
|
|
51
|
+
let ast = selectorParser().astSync(selector)
|
|
52
|
+
|
|
53
|
+
if (context?.tailwindConfig?.prefix) {
|
|
54
|
+
format = prefixSelector(context.tailwindConfig.prefix, format)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
format = format.replace(PARENT, `.${escapeClassName(candidate)}`)
|
|
58
|
+
|
|
59
|
+
let formatAst = selectorParser().astSync(format)
|
|
60
|
+
|
|
61
|
+
// Remove extraneous selectors that do not include the base class/candidate being matched against
|
|
62
|
+
// For example if we have a utility defined `.a, .b { color: red}`
|
|
63
|
+
// And the formatted variant is sm:b then we want the final selector to be `.sm\:b` and not `.a, .sm\:b`
|
|
64
|
+
ast.each((node) => {
|
|
65
|
+
let hasClassesMatchingCandidate = node.some((n) => n.type === 'class' && n.value === base)
|
|
66
|
+
|
|
67
|
+
if (!hasClassesMatchingCandidate) {
|
|
68
|
+
node.remove()
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
// Normalize escaped classes, e.g.:
|
|
73
|
+
//
|
|
74
|
+
// The idea would be to replace the escaped `base` in the selector with the
|
|
75
|
+
// `format`. However, in css you can escape the same selector in a few
|
|
76
|
+
// different ways. This would result in different strings and therefore we
|
|
77
|
+
// can't replace it properly.
|
|
78
|
+
//
|
|
79
|
+
// base: bg-[rgb(255,0,0)]
|
|
80
|
+
// base in selector: bg-\\[rgb\\(255\\,0\\,0\\)\\]
|
|
81
|
+
// escaped base: bg-\\[rgb\\(255\\2c 0\\2c 0\\)\\]
|
|
82
|
+
//
|
|
83
|
+
ast.walkClasses((node) => {
|
|
84
|
+
if (node.raws && node.value.includes(base)) {
|
|
85
|
+
node.raws.value = escapeClassName(unescape(node.raws.value))
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// We can safely replace the escaped base now, since the `base` section is
|
|
90
|
+
// now in a normalized escaped value.
|
|
91
|
+
ast.walkClasses((node) => {
|
|
92
|
+
if (node.value === base) {
|
|
93
|
+
node.replaceWith(...formatAst.nodes)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// This will make sure to move pseudo's to the correct spot (the end for
|
|
98
|
+
// pseudo elements) because otherwise the selector will never work
|
|
99
|
+
// anyway.
|
|
100
|
+
//
|
|
101
|
+
// E.g.:
|
|
102
|
+
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
103
|
+
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
104
|
+
//
|
|
105
|
+
// `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
|
|
106
|
+
function collectPseudoElements(selector) {
|
|
107
|
+
let nodes = []
|
|
108
|
+
|
|
109
|
+
for (let node of selector.nodes) {
|
|
110
|
+
if (isPseudoElement(node)) {
|
|
111
|
+
nodes.push(node)
|
|
112
|
+
selector.removeChild(node)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (node?.nodes) {
|
|
116
|
+
nodes.push(...collectPseudoElements(node))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return nodes
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Remove unnecessary pseudo selectors that we used as placeholders
|
|
124
|
+
ast.each((selector) => {
|
|
125
|
+
selector.walkPseudos((p) => {
|
|
126
|
+
if (selectorFunctions.has(p.value)) {
|
|
127
|
+
p.replaceWith(p.nodes)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
let pseudoElements = collectPseudoElements(selector)
|
|
132
|
+
if (pseudoElements.length > 0) {
|
|
133
|
+
selector.nodes.push(pseudoElements.sort(sortSelector))
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
return ast.toString()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Note: As a rule, double colons (::) should be used instead of a single colon
|
|
141
|
+
// (:). This distinguishes pseudo-classes from pseudo-elements. However, since
|
|
142
|
+
// this distinction was not present in older versions of the W3C spec, most
|
|
143
|
+
// browsers support both syntaxes for the original pseudo-elements.
|
|
144
|
+
let pseudoElementsBC = [':before', ':after', ':first-line', ':first-letter']
|
|
145
|
+
|
|
146
|
+
// These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
|
|
147
|
+
let pseudoElementExceptions = ['::file-selector-button']
|
|
148
|
+
|
|
149
|
+
// This will make sure to move pseudo's to the correct spot (the end for
|
|
150
|
+
// pseudo elements) because otherwise the selector will never work
|
|
151
|
+
// anyway.
|
|
152
|
+
//
|
|
153
|
+
// E.g.:
|
|
154
|
+
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
155
|
+
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
156
|
+
//
|
|
157
|
+
// `::before:hover` doesn't work, which means that we can make it work
|
|
158
|
+
// for you by flipping the order.
|
|
159
|
+
function sortSelector(a, z) {
|
|
160
|
+
// Both nodes are non-pseudo's so we can safely ignore them and keep
|
|
161
|
+
// them in the same order.
|
|
162
|
+
if (a.type !== 'pseudo' && z.type !== 'pseudo') {
|
|
163
|
+
return 0
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// If one of them is a combinator, we need to keep it in the same order
|
|
167
|
+
// because that means it will start a new "section" in the selector.
|
|
168
|
+
if ((a.type === 'combinator') ^ (z.type === 'combinator')) {
|
|
169
|
+
return 0
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// One of the items is a pseudo and the other one isn't. Let's move
|
|
173
|
+
// the pseudo to the right.
|
|
174
|
+
if ((a.type === 'pseudo') ^ (z.type === 'pseudo')) {
|
|
175
|
+
return (a.type === 'pseudo') - (z.type === 'pseudo')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Both are pseudo's, move the pseudo elements (except for
|
|
179
|
+
// ::file-selector-button) to the right.
|
|
180
|
+
return isPseudoElement(a) - isPseudoElement(z)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function isPseudoElement(node) {
|
|
184
|
+
if (node.type !== 'pseudo') return false
|
|
185
|
+
if (pseudoElementExceptions.includes(node.value)) return false
|
|
186
|
+
|
|
187
|
+
return node.value.startsWith('::') || pseudoElementsBC.includes(node.value)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function resolveFunctionArgument(haystack, needle, arg) {
|
|
191
|
+
let startIdx = haystack.indexOf(arg ? `${needle}(${arg})` : needle)
|
|
192
|
+
if (startIdx === -1) return null
|
|
193
|
+
|
|
194
|
+
// Start inside the `(`
|
|
195
|
+
startIdx += needle.length + 1
|
|
196
|
+
|
|
197
|
+
let target = ''
|
|
198
|
+
let count = 0
|
|
199
|
+
|
|
200
|
+
for (let char of haystack.slice(startIdx)) {
|
|
201
|
+
if (char !== '(' && char !== ')') {
|
|
202
|
+
target += char
|
|
203
|
+
} else if (char === '(') {
|
|
204
|
+
target += char
|
|
205
|
+
count++
|
|
206
|
+
} else if (char === ')') {
|
|
207
|
+
if (--count < 0) break // unbalanced
|
|
208
|
+
target += char
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return target
|
|
213
|
+
}
|
|
@@ -9,6 +9,13 @@ export default function getAllConfigs(config) {
|
|
|
9
9
|
|
|
10
10
|
const features = {
|
|
11
11
|
// Add experimental configs here...
|
|
12
|
+
respectDefaultRingColorOpacity: {
|
|
13
|
+
theme: {
|
|
14
|
+
ringColor: {
|
|
15
|
+
DEFAULT: '#3b82f67f',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
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(
|
|
5
|
+
function log(type, messages, key) {
|
|
6
6
|
if (process.env.JEST_WORKER_ID !== undefined) 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
|
@@ -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
|
|
|
@@ -140,6 +140,18 @@ export function normalizeConfig(config) {
|
|
|
140
140
|
return []
|
|
141
141
|
})()
|
|
142
142
|
|
|
143
|
+
// Normalize prefix option
|
|
144
|
+
if (typeof config.prefix === 'function') {
|
|
145
|
+
log.warn('prefix-function', [
|
|
146
|
+
'As of Tailwind CSS v3.0, `prefix` cannot be a function.',
|
|
147
|
+
'Update `prefix` in your configuration to be a string to eliminate this warning.',
|
|
148
|
+
'https://tailwindcss.com/docs/upgrade-guide#prefix-cannot-be-a-function',
|
|
149
|
+
])
|
|
150
|
+
config.prefix = ''
|
|
151
|
+
} else {
|
|
152
|
+
config.prefix = config.prefix ?? ''
|
|
153
|
+
}
|
|
154
|
+
|
|
143
155
|
// Normalize the `content`
|
|
144
156
|
config.content = {
|
|
145
157
|
files: (() => {
|
|
@@ -170,7 +182,7 @@ export function normalizeConfig(config) {
|
|
|
170
182
|
|
|
171
183
|
let extractors = {}
|
|
172
184
|
|
|
173
|
-
|
|
185
|
+
let defaultExtractor = (() => {
|
|
174
186
|
if (config.purge?.options?.defaultExtractor) {
|
|
175
187
|
return config.purge.options.defaultExtractor
|
|
176
188
|
}
|
|
@@ -182,6 +194,10 @@ export function normalizeConfig(config) {
|
|
|
182
194
|
return undefined
|
|
183
195
|
})()
|
|
184
196
|
|
|
197
|
+
if (defaultExtractor !== undefined) {
|
|
198
|
+
extractors.DEFAULT = defaultExtractor
|
|
199
|
+
}
|
|
200
|
+
|
|
185
201
|
// Functions
|
|
186
202
|
if (typeof extract === 'function') {
|
|
187
203
|
extractors.DEFAULT = extract
|
|
@@ -229,5 +245,18 @@ export function normalizeConfig(config) {
|
|
|
229
245
|
})(),
|
|
230
246
|
}
|
|
231
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
|
+
|
|
232
261
|
return config
|
|
233
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
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
|
|
2
|
+
|
|
3
|
+
let KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
|
|
4
|
+
let SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
|
5
|
+
let LENGTH = /^-?(\d+|\.\d+)(.*?)$/g
|
|
6
|
+
|
|
7
|
+
export function parseBoxShadowValue(input) {
|
|
8
|
+
let shadows = Array.from(splitAtTopLevelOnly(input, ','))
|
|
9
|
+
return shadows.map((shadow) => {
|
|
10
|
+
let value = shadow.trim()
|
|
11
|
+
let result = { raw: value }
|
|
12
|
+
let parts = value.split(SPACE)
|
|
13
|
+
let seen = new Set()
|
|
14
|
+
|
|
15
|
+
for (let part of parts) {
|
|
16
|
+
// Reset index, since the regex is stateful.
|
|
17
|
+
LENGTH.lastIndex = 0
|
|
18
|
+
|
|
19
|
+
// Keyword
|
|
20
|
+
if (!seen.has('KEYWORD') && KEYWORDS.has(part)) {
|
|
21
|
+
result.keyword = part
|
|
22
|
+
seen.add('KEYWORD')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Length value
|
|
26
|
+
else if (LENGTH.test(part)) {
|
|
27
|
+
if (!seen.has('X')) {
|
|
28
|
+
result.x = part
|
|
29
|
+
seen.add('X')
|
|
30
|
+
} else if (!seen.has('Y')) {
|
|
31
|
+
result.y = part
|
|
32
|
+
seen.add('Y')
|
|
33
|
+
} else if (!seen.has('BLUR')) {
|
|
34
|
+
result.blur = part
|
|
35
|
+
seen.add('BLUR')
|
|
36
|
+
} else if (!seen.has('SPREAD')) {
|
|
37
|
+
result.spread = part
|
|
38
|
+
seen.add('SPREAD')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Color or unknown
|
|
43
|
+
else {
|
|
44
|
+
if (!result.color) {
|
|
45
|
+
result.color = part
|
|
46
|
+
} else {
|
|
47
|
+
if (!result.unknown) result.unknown = []
|
|
48
|
+
result.unknown.push(part)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Check if valid
|
|
54
|
+
result.valid = result.x !== undefined && result.y !== undefined
|
|
55
|
+
|
|
56
|
+
return result
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function formatBoxShadowValue(shadows) {
|
|
61
|
+
return shadows
|
|
62
|
+
.map((shadow) => {
|
|
63
|
+
if (!shadow.valid) {
|
|
64
|
+
return shadow.raw
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return [shadow.keyword, shadow.x, shadow.y, shadow.blur, shadow.spread, shadow.color]
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.join(' ')
|
|
70
|
+
})
|
|
71
|
+
.join(', ')
|
|
72
|
+
}
|