tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce
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 +380 -1
- 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 +311 -213
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +11 -1
- package/lib/corePlugins.js +1895 -1773
- package/lib/css/preflight.css +19 -13
- package/lib/featureFlags.js +22 -16
- 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 +156 -151
- package/lib/lib/generateRules.js +402 -68
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +45 -36
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/regex.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +105 -90
- package/lib/lib/setupContextUtils.js +416 -291
- package/lib/lib/setupTrackingContext.js +60 -56
- package/lib/lib/sharedState.js +38 -15
- 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 +21 -9
- package/lib/public/colors.js +244 -248
- 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 +13 -17
- 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 +35 -19
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +5 -3
- package/lib/util/normalizeConfig.js +233 -0
- 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 +67 -170
- package/lib/util/prefixSelector.js +4 -7
- package/lib/util/resolveConfig.js +123 -133
- 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 +41 -42
- package/peers/index.js +11539 -10859
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +52 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +174 -41
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +641 -596
- package/src/css/preflight.css +19 -13
- package/src/featureFlags.js +16 -10
- 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 +91 -65
- package/src/lib/generateRules.js +409 -43
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +74 -53
- package/src/lib/setupContextUtils.js +388 -208
- package/src/lib/setupTrackingContext.js +15 -12
- package/src/lib/sharedState.js +42 -7
- 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 +17 -2
- package/src/public/colors.js +4 -9
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -2
- 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 +23 -22
- package/src/util/nameClass.js +2 -2
- package/src/util/negateValue.js +4 -2
- package/src/util/normalizeConfig.js +262 -0
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/pluginUtils.js +51 -147
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +108 -79
- 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 +157 -94
- package/stubs/simpleConfig.stub.js +0 -1
- 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 -306
|
@@ -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,28 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import colors from 'picocolors'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
info(messages) {
|
|
5
|
-
if (process.env.JEST_WORKER_ID !== undefined) return
|
|
3
|
+
let alreadyShown = new Set()
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
console.warn(chalk.bold.cyan('info'), '-', message)
|
|
10
|
-
})
|
|
11
|
-
},
|
|
12
|
-
warn(messages) {
|
|
13
|
-
if (process.env.JEST_WORKER_ID !== undefined) return
|
|
5
|
+
function log(type, messages, key) {
|
|
6
|
+
if (process.env.JEST_WORKER_ID !== undefined) return
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (process.env.JEST_WORKER_ID !== undefined) return
|
|
8
|
+
if (key && alreadyShown.has(key)) return
|
|
9
|
+
if (key) alreadyShown.add(key)
|
|
10
|
+
|
|
11
|
+
console.warn('')
|
|
12
|
+
messages.forEach((message) => console.warn(type, '-', message))
|
|
13
|
+
}
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
export function dim(input) {
|
|
16
|
+
return colors.dim(input)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
info(key, messages) {
|
|
21
|
+
log(colors.bold(colors.cyan('info')), ...(Array.isArray(key) ? [key] : [messages, key]))
|
|
22
|
+
},
|
|
23
|
+
warn(key, messages) {
|
|
24
|
+
log(colors.bold(colors.yellow('warn')), ...(Array.isArray(key) ? [key] : [messages, key]))
|
|
25
|
+
},
|
|
26
|
+
risk(key, messages) {
|
|
27
|
+
log(colors.bold(colors.magenta('risk')), ...(Array.isArray(key) ? [key] : [messages, key]))
|
|
27
28
|
},
|
|
28
29
|
}
|
package/src/util/nameClass.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import escapeClassName from './escapeClassName'
|
|
2
2
|
import escapeCommas from './escapeCommas'
|
|
3
3
|
|
|
4
|
-
function asClass(name) {
|
|
4
|
+
export function asClass(name) {
|
|
5
5
|
return escapeCommas(`.${escapeClassName(name)}`)
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ export function formatClass(classPrefix, key) {
|
|
|
14
14
|
return classPrefix
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (key === '-') {
|
|
17
|
+
if (key === '-' || key === '-DEFAULT') {
|
|
18
18
|
return `-${classPrefix}`
|
|
19
19
|
}
|
|
20
20
|
|
package/src/util/negateValue.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export default function (value) {
|
|
2
2
|
value = `${value}`
|
|
3
3
|
|
|
4
|
+
if (value === '0') {
|
|
5
|
+
return '0'
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
// Flip sign of numbers
|
|
5
9
|
if (/^[+-]?(\d+|\d*\.\d+)(e[+-]?\d+)?(%|\w+)?$/.test(value)) {
|
|
6
10
|
return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-'))
|
|
@@ -9,6 +13,4 @@ export default function (value) {
|
|
|
9
13
|
if (value.includes('var(') || value.includes('calc(')) {
|
|
10
14
|
return `calc(${value} * -1)`
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
return value
|
|
14
16
|
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import log, { dim } from './log'
|
|
2
|
+
|
|
3
|
+
export function normalizeConfig(config) {
|
|
4
|
+
// Quick structure validation
|
|
5
|
+
/**
|
|
6
|
+
* type FilePath = string
|
|
7
|
+
* type RawFile = { raw: string, extension?: string }
|
|
8
|
+
* type ExtractorFn = (content: string) => Array<string>
|
|
9
|
+
* type TransformerFn = (content: string) => string
|
|
10
|
+
*
|
|
11
|
+
* type Content =
|
|
12
|
+
* | Array<FilePath | RawFile>
|
|
13
|
+
* | {
|
|
14
|
+
* files: Array<FilePath | RawFile>,
|
|
15
|
+
* extract?: ExtractorFn | { [extension: string]: ExtractorFn }
|
|
16
|
+
* transform?: TransformerFn | { [extension: string]: TransformerFn }
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
let valid = (() => {
|
|
20
|
+
// `config.purge` should not exist anymore
|
|
21
|
+
if (config.purge) {
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// `config.content` should exist
|
|
26
|
+
if (!config.content) {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// `config.content` should be an object or an array
|
|
31
|
+
if (
|
|
32
|
+
!Array.isArray(config.content) &&
|
|
33
|
+
!(typeof config.content === 'object' && config.content !== null)
|
|
34
|
+
) {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// When `config.content` is an array, it should consist of FilePaths or RawFiles
|
|
39
|
+
if (Array.isArray(config.content)) {
|
|
40
|
+
return config.content.every((path) => {
|
|
41
|
+
// `path` can be a string
|
|
42
|
+
if (typeof path === 'string') return true
|
|
43
|
+
|
|
44
|
+
// `path` can be an object { raw: string, extension?: string }
|
|
45
|
+
// `raw` must be a string
|
|
46
|
+
if (typeof path?.raw !== 'string') return false
|
|
47
|
+
|
|
48
|
+
// `extension` (if provided) should also be a string
|
|
49
|
+
if (path?.extension && typeof path?.extension !== 'string') {
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return true
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// When `config.content` is an object
|
|
58
|
+
if (typeof config.content === 'object' && config.content !== null) {
|
|
59
|
+
// Only `files`, `extract` and `transform` can exist in `config.content`
|
|
60
|
+
if (
|
|
61
|
+
Object.keys(config.content).some((key) => !['files', 'extract', 'transform'].includes(key))
|
|
62
|
+
) {
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// `config.content.files` should exist of FilePaths or RawFiles
|
|
67
|
+
if (Array.isArray(config.content.files)) {
|
|
68
|
+
if (
|
|
69
|
+
!config.content.files.every((path) => {
|
|
70
|
+
// `path` can be a string
|
|
71
|
+
if (typeof path === 'string') return true
|
|
72
|
+
|
|
73
|
+
// `path` can be an object { raw: string, extension?: string }
|
|
74
|
+
// `raw` must be a string
|
|
75
|
+
if (typeof path?.raw !== 'string') return false
|
|
76
|
+
|
|
77
|
+
// `extension` (if provided) should also be a string
|
|
78
|
+
if (path?.extension && typeof path?.extension !== 'string') {
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return true
|
|
83
|
+
})
|
|
84
|
+
) {
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// `config.content.extract` is optional, and can be a Function or a Record<String, Function>
|
|
89
|
+
if (typeof config.content.extract === 'object') {
|
|
90
|
+
for (let value of Object.values(config.content.extract)) {
|
|
91
|
+
if (typeof value !== 'function') {
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} else if (
|
|
96
|
+
!(config.content.extract === undefined || typeof config.content.extract === 'function')
|
|
97
|
+
) {
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// `config.content.transform` is optional, and can be a Function or a Record<String, Function>
|
|
102
|
+
if (typeof config.content.transform === 'object') {
|
|
103
|
+
for (let value of Object.values(config.content.transform)) {
|
|
104
|
+
if (typeof value !== 'function') {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} else if (
|
|
109
|
+
!(
|
|
110
|
+
config.content.transform === undefined || typeof config.content.transform === 'function'
|
|
111
|
+
)
|
|
112
|
+
) {
|
|
113
|
+
return false
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return true
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return false
|
|
121
|
+
})()
|
|
122
|
+
|
|
123
|
+
if (!valid) {
|
|
124
|
+
log.warn('purge-deprecation', [
|
|
125
|
+
'The `purge`/`content` options have changed in Tailwind CSS v3.0.',
|
|
126
|
+
'Update your configuration file to eliminate this warning.',
|
|
127
|
+
'https://tailwindcss.com/docs/upgrade-guide#configure-content-sources',
|
|
128
|
+
])
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Normalize the `safelist`
|
|
132
|
+
config.safelist = (() => {
|
|
133
|
+
let { content, purge, safelist } = config
|
|
134
|
+
|
|
135
|
+
if (Array.isArray(safelist)) return safelist
|
|
136
|
+
if (Array.isArray(content?.safelist)) return content.safelist
|
|
137
|
+
if (Array.isArray(purge?.safelist)) return purge.safelist
|
|
138
|
+
if (Array.isArray(purge?.options?.safelist)) return purge.options.safelist
|
|
139
|
+
|
|
140
|
+
return []
|
|
141
|
+
})()
|
|
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
|
+
|
|
155
|
+
// Normalize the `content`
|
|
156
|
+
config.content = {
|
|
157
|
+
files: (() => {
|
|
158
|
+
let { content, purge } = config
|
|
159
|
+
|
|
160
|
+
if (Array.isArray(purge)) return purge
|
|
161
|
+
if (Array.isArray(purge?.content)) return purge.content
|
|
162
|
+
if (Array.isArray(content)) return content
|
|
163
|
+
if (Array.isArray(content?.content)) return content.content
|
|
164
|
+
if (Array.isArray(content?.files)) return content.files
|
|
165
|
+
|
|
166
|
+
return []
|
|
167
|
+
})(),
|
|
168
|
+
|
|
169
|
+
extract: (() => {
|
|
170
|
+
let extract = (() => {
|
|
171
|
+
if (config.purge?.extract) return config.purge.extract
|
|
172
|
+
if (config.content?.extract) return config.content.extract
|
|
173
|
+
|
|
174
|
+
if (config.purge?.extract?.DEFAULT) return config.purge.extract.DEFAULT
|
|
175
|
+
if (config.content?.extract?.DEFAULT) return config.content.extract.DEFAULT
|
|
176
|
+
|
|
177
|
+
if (config.purge?.options?.extractors) return config.purge.options.extractors
|
|
178
|
+
if (config.content?.options?.extractors) return config.content.options.extractors
|
|
179
|
+
|
|
180
|
+
return {}
|
|
181
|
+
})()
|
|
182
|
+
|
|
183
|
+
let extractors = {}
|
|
184
|
+
|
|
185
|
+
let defaultExtractor = (() => {
|
|
186
|
+
if (config.purge?.options?.defaultExtractor) {
|
|
187
|
+
return config.purge.options.defaultExtractor
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (config.content?.options?.defaultExtractor) {
|
|
191
|
+
return config.content.options.defaultExtractor
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return undefined
|
|
195
|
+
})()
|
|
196
|
+
|
|
197
|
+
if (defaultExtractor !== undefined) {
|
|
198
|
+
extractors.DEFAULT = defaultExtractor
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Functions
|
|
202
|
+
if (typeof extract === 'function') {
|
|
203
|
+
extractors.DEFAULT = extract
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Arrays
|
|
207
|
+
else if (Array.isArray(extract)) {
|
|
208
|
+
for (let { extensions, extractor } of extract ?? []) {
|
|
209
|
+
for (let extension of extensions) {
|
|
210
|
+
extractors[extension] = extractor
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Objects
|
|
216
|
+
else if (typeof extract === 'object' && extract !== null) {
|
|
217
|
+
Object.assign(extractors, extract)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return extractors
|
|
221
|
+
})(),
|
|
222
|
+
|
|
223
|
+
transform: (() => {
|
|
224
|
+
let transform = (() => {
|
|
225
|
+
if (config.purge?.transform) return config.purge.transform
|
|
226
|
+
if (config.content?.transform) return config.content.transform
|
|
227
|
+
|
|
228
|
+
if (config.purge?.transform?.DEFAULT) return config.purge.transform.DEFAULT
|
|
229
|
+
if (config.content?.transform?.DEFAULT) return config.content.transform.DEFAULT
|
|
230
|
+
|
|
231
|
+
return {}
|
|
232
|
+
})()
|
|
233
|
+
|
|
234
|
+
let transformers = {}
|
|
235
|
+
|
|
236
|
+
if (typeof transform === 'function') {
|
|
237
|
+
transformers.DEFAULT = transform
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (typeof transform === 'object' && transform !== null) {
|
|
241
|
+
Object.assign(transformers, transform)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return transformers
|
|
245
|
+
})(),
|
|
246
|
+
}
|
|
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
|
+
|
|
261
|
+
return config
|
|
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
|
+
}
|