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.
Files changed (148) hide show
  1. package/CHANGELOG.md +380 -1
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +3 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli-peer-dependencies.js +10 -5
  11. package/lib/cli.js +311 -213
  12. package/lib/constants.js +9 -9
  13. package/lib/corePluginList.js +11 -1
  14. package/lib/corePlugins.js +1895 -1773
  15. package/lib/css/preflight.css +19 -13
  16. package/lib/featureFlags.js +22 -16
  17. package/lib/index.js +17 -8
  18. package/lib/lib/cacheInvalidation.js +69 -0
  19. package/lib/lib/collapseAdjacentRules.js +30 -14
  20. package/lib/lib/collapseDuplicateDeclarations.js +80 -0
  21. package/lib/lib/defaultExtractor.js +187 -0
  22. package/lib/lib/detectNesting.js +17 -2
  23. package/lib/lib/evaluateTailwindFunctions.js +40 -24
  24. package/lib/lib/expandApplyAtRules.js +414 -157
  25. package/lib/lib/expandTailwindAtRules.js +156 -151
  26. package/lib/lib/generateRules.js +402 -68
  27. package/lib/lib/getModuleDependencies.js +14 -14
  28. package/lib/lib/normalizeTailwindDirectives.js +45 -36
  29. package/lib/lib/partitionApplyAtRules.js +53 -0
  30. package/lib/lib/regex.js +53 -0
  31. package/lib/lib/resolveDefaultsAtRules.js +105 -90
  32. package/lib/lib/setupContextUtils.js +416 -291
  33. package/lib/lib/setupTrackingContext.js +60 -56
  34. package/lib/lib/sharedState.js +38 -15
  35. package/lib/lib/substituteScreenAtRules.js +9 -6
  36. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  37. package/lib/postcss-plugins/nesting/index.js +17 -0
  38. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  39. package/lib/processTailwindFeatures.js +21 -9
  40. package/lib/public/colors.js +244 -248
  41. package/lib/public/resolve-config.js +5 -5
  42. package/lib/util/buildMediaQuery.js +13 -24
  43. package/lib/util/cloneDeep.js +1 -1
  44. package/lib/util/cloneNodes.js +12 -1
  45. package/lib/util/color.js +43 -32
  46. package/lib/util/createPlugin.js +1 -2
  47. package/lib/util/createUtilityPlugin.js +13 -17
  48. package/lib/util/dataTypes.js +114 -74
  49. package/lib/util/defaults.js +6 -0
  50. package/lib/util/escapeClassName.js +5 -5
  51. package/lib/util/escapeCommas.js +1 -1
  52. package/lib/util/flattenColorPalette.js +2 -4
  53. package/lib/util/formatVariantSelector.js +194 -0
  54. package/lib/util/getAllConfigs.js +13 -5
  55. package/lib/util/hashConfig.js +5 -5
  56. package/lib/util/isKeyframeRule.js +1 -1
  57. package/lib/util/isPlainObject.js +1 -1
  58. package/lib/util/isValidArbitraryValue.js +64 -0
  59. package/lib/util/log.js +35 -19
  60. package/lib/util/nameClass.js +7 -6
  61. package/lib/util/negateValue.js +5 -3
  62. package/lib/util/normalizeConfig.js +233 -0
  63. package/lib/util/normalizeScreens.js +59 -0
  64. package/lib/util/parseAnimationValue.js +56 -56
  65. package/lib/util/parseBoxShadowValue.js +76 -0
  66. package/lib/util/parseDependency.js +32 -32
  67. package/lib/util/parseObjectStyles.js +6 -6
  68. package/lib/util/pluginUtils.js +67 -170
  69. package/lib/util/prefixSelector.js +4 -7
  70. package/lib/util/resolveConfig.js +123 -133
  71. package/lib/util/resolveConfigPath.js +17 -18
  72. package/lib/util/responsive.js +6 -6
  73. package/lib/util/splitAtTopLevelOnly.js +72 -0
  74. package/lib/util/toColorValue.js +1 -2
  75. package/lib/util/toPath.js +6 -1
  76. package/lib/util/transformThemeValue.js +42 -34
  77. package/lib/util/validateConfig.js +21 -0
  78. package/lib/util/withAlphaVariable.js +19 -19
  79. package/nesting/index.js +2 -12
  80. package/package.json +41 -42
  81. package/peers/index.js +11539 -10859
  82. package/plugin.d.ts +11 -0
  83. package/plugin.js +2 -1
  84. package/resolveConfig.js +2 -1
  85. package/scripts/create-plugin-list.js +2 -2
  86. package/scripts/generate-types.js +52 -0
  87. package/src/cli-peer-dependencies.js +7 -1
  88. package/src/cli.js +174 -41
  89. package/src/corePluginList.js +1 -1
  90. package/src/corePlugins.js +641 -596
  91. package/src/css/preflight.css +19 -13
  92. package/src/featureFlags.js +16 -10
  93. package/src/index.js +14 -6
  94. package/src/lib/cacheInvalidation.js +52 -0
  95. package/src/lib/collapseAdjacentRules.js +21 -2
  96. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  97. package/src/lib/defaultExtractor.js +192 -0
  98. package/src/lib/detectNesting.js +22 -3
  99. package/src/lib/evaluateTailwindFunctions.js +24 -7
  100. package/src/lib/expandApplyAtRules.js +442 -154
  101. package/src/lib/expandTailwindAtRules.js +91 -65
  102. package/src/lib/generateRules.js +409 -43
  103. package/src/lib/normalizeTailwindDirectives.js +10 -3
  104. package/src/lib/partitionApplyAtRules.js +52 -0
  105. package/src/lib/regex.js +74 -0
  106. package/src/lib/resolveDefaultsAtRules.js +74 -53
  107. package/src/lib/setupContextUtils.js +388 -208
  108. package/src/lib/setupTrackingContext.js +15 -12
  109. package/src/lib/sharedState.js +42 -7
  110. package/src/lib/substituteScreenAtRules.js +6 -3
  111. package/src/postcss-plugins/nesting/README.md +42 -0
  112. package/src/postcss-plugins/nesting/index.js +13 -0
  113. package/src/postcss-plugins/nesting/plugin.js +80 -0
  114. package/src/processTailwindFeatures.js +17 -2
  115. package/src/public/colors.js +4 -9
  116. package/src/util/buildMediaQuery.js +14 -18
  117. package/src/util/cloneNodes.js +14 -1
  118. package/src/util/color.js +31 -14
  119. package/src/util/createUtilityPlugin.js +2 -2
  120. package/src/util/dataTypes.js +56 -16
  121. package/src/util/defaults.js +6 -0
  122. package/src/util/formatVariantSelector.js +213 -0
  123. package/src/util/getAllConfigs.js +7 -0
  124. package/src/util/isValidArbitraryValue.js +61 -0
  125. package/src/util/log.js +23 -22
  126. package/src/util/nameClass.js +2 -2
  127. package/src/util/negateValue.js +4 -2
  128. package/src/util/normalizeConfig.js +262 -0
  129. package/src/util/normalizeScreens.js +45 -0
  130. package/src/util/parseBoxShadowValue.js +72 -0
  131. package/src/util/pluginUtils.js +51 -147
  132. package/src/util/prefixSelector.js +7 -8
  133. package/src/util/resolveConfig.js +108 -79
  134. package/src/util/splitAtTopLevelOnly.js +71 -0
  135. package/src/util/toPath.js +23 -1
  136. package/src/util/transformThemeValue.js +24 -7
  137. package/src/util/validateConfig.js +13 -0
  138. package/stubs/defaultConfig.stub.js +157 -94
  139. package/stubs/simpleConfig.stub.js +0 -1
  140. package/types/config.d.ts +325 -0
  141. package/types/generated/.gitkeep +0 -0
  142. package/types/generated/colors.d.ts +276 -0
  143. package/types/generated/corePluginList.d.ts +1 -0
  144. package/types/index.d.ts +1 -0
  145. package/types.d.ts +1 -0
  146. package/lib/lib/setupWatchingContext.js +0 -284
  147. package/nesting/plugin.js +0 -41
  148. 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 chalk from 'chalk'
1
+ import colors from 'picocolors'
2
2
 
3
- export default {
4
- info(messages) {
5
- if (process.env.JEST_WORKER_ID !== undefined) return
3
+ let alreadyShown = new Set()
6
4
 
7
- console.warn('')
8
- messages.forEach((message) => {
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
- console.warn('')
16
- messages.forEach((message) => {
17
- console.warn(chalk.bold.yellow('warn'), '-', message)
18
- })
19
- },
20
- risk(messages) {
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
- console.warn('')
24
- messages.forEach((message) => {
25
- console.warn(chalk.bold.magenta('risk'), '-', message)
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
  }
@@ -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
 
@@ -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
+ }