tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cb6e45a

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 (190) hide show
  1. package/CHANGELOG.md +526 -2
  2. package/LICENSE +1 -2
  3. package/README.md +13 -6
  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 +4 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli/build/deps.js +54 -0
  11. package/lib/cli/build/index.js +44 -0
  12. package/lib/cli/build/plugin.js +335 -0
  13. package/lib/cli/build/utils.js +78 -0
  14. package/lib/cli/build/watching.js +113 -0
  15. package/lib/cli/help/index.js +71 -0
  16. package/lib/cli/index.js +18 -0
  17. package/lib/cli/init/index.js +46 -0
  18. package/lib/cli/shared.js +12 -0
  19. package/lib/cli-peer-dependencies.js +20 -7
  20. package/lib/cli.js +91 -569
  21. package/lib/constants.js +27 -20
  22. package/lib/corePluginList.js +16 -4
  23. package/lib/corePlugins.js +2247 -1873
  24. package/lib/css/preflight.css +20 -9
  25. package/lib/featureFlags.js +37 -23
  26. package/lib/index.js +28 -12
  27. package/lib/lib/cacheInvalidation.js +90 -0
  28. package/lib/lib/collapseAdjacentRules.js +27 -9
  29. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  30. package/lib/lib/content.js +167 -0
  31. package/lib/lib/defaultExtractor.js +236 -0
  32. package/lib/lib/detectNesting.js +21 -3
  33. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  34. package/lib/lib/expandApplyAtRules.js +439 -160
  35. package/lib/lib/expandTailwindAtRules.js +141 -151
  36. package/lib/lib/findAtConfigPath.js +44 -0
  37. package/lib/lib/generateRules.js +572 -105
  38. package/lib/lib/getModuleDependencies.js +11 -8
  39. package/lib/lib/normalizeTailwindDirectives.js +45 -33
  40. package/lib/lib/offsets.js +217 -0
  41. package/lib/lib/partitionApplyAtRules.js +56 -0
  42. package/lib/lib/regex.js +60 -0
  43. package/lib/lib/resolveDefaultsAtRules.js +114 -81
  44. package/lib/lib/setupContextUtils.js +777 -385
  45. package/lib/lib/setupTrackingContext.js +43 -71
  46. package/lib/lib/sharedState.js +49 -18
  47. package/lib/lib/substituteScreenAtRules.js +13 -8
  48. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  49. package/lib/postcss-plugins/nesting/index.js +19 -0
  50. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  51. package/lib/processTailwindFeatures.js +36 -21
  52. package/lib/public/colors.js +250 -252
  53. package/lib/public/create-plugin.js +6 -4
  54. package/lib/public/default-config.js +7 -5
  55. package/lib/public/default-theme.js +7 -5
  56. package/lib/public/resolve-config.js +8 -5
  57. package/lib/util/bigSign.js +4 -1
  58. package/lib/util/buildMediaQuery.js +18 -24
  59. package/lib/util/cloneDeep.js +7 -6
  60. package/lib/util/cloneNodes.js +21 -3
  61. package/lib/util/color.js +54 -40
  62. package/lib/util/configurePlugins.js +5 -2
  63. package/lib/util/createPlugin.js +6 -6
  64. package/lib/util/createUtilityPlugin.js +11 -13
  65. package/lib/util/dataTypes.js +137 -100
  66. package/lib/util/defaults.js +10 -1
  67. package/lib/util/escapeClassName.js +7 -4
  68. package/lib/util/escapeCommas.js +5 -2
  69. package/lib/util/flattenColorPalette.js +9 -12
  70. package/lib/util/formatVariantSelector.js +285 -0
  71. package/lib/util/getAllConfigs.js +27 -8
  72. package/lib/util/hashConfig.js +6 -3
  73. package/lib/util/isKeyframeRule.js +5 -2
  74. package/lib/util/isPlainObject.js +5 -2
  75. package/lib/util/isValidArbitraryValue.js +72 -0
  76. package/lib/util/log.js +44 -22
  77. package/lib/util/nameClass.js +20 -8
  78. package/lib/util/negateValue.js +23 -6
  79. package/lib/util/normalizeConfig.js +267 -0
  80. package/lib/util/normalizeScreens.js +170 -0
  81. package/lib/util/parseAnimationValue.js +42 -40
  82. package/lib/util/parseBoxShadowValue.js +84 -0
  83. package/lib/util/parseDependency.js +38 -56
  84. package/lib/util/parseGlob.js +34 -0
  85. package/lib/util/parseObjectStyles.js +11 -8
  86. package/lib/util/pluginUtils.js +171 -189
  87. package/lib/util/prefixSelector.js +10 -10
  88. package/lib/util/removeAlphaVariables.js +29 -0
  89. package/lib/util/resolveConfig.js +92 -126
  90. package/lib/util/resolveConfigPath.js +11 -9
  91. package/lib/util/responsive.js +8 -5
  92. package/lib/util/splitAtTopLevelOnly.js +43 -0
  93. package/lib/util/tap.js +4 -1
  94. package/lib/util/toColorValue.js +5 -3
  95. package/lib/util/toPath.js +24 -3
  96. package/lib/util/transformThemeValue.js +49 -31
  97. package/lib/util/validateConfig.js +24 -0
  98. package/lib/util/validateFormalSyntax.js +24 -0
  99. package/lib/util/withAlphaVariable.js +23 -15
  100. package/nesting/index.js +2 -12
  101. package/package.json +48 -46
  102. package/peers/index.js +14817 -12471
  103. package/plugin.d.ts +11 -0
  104. package/plugin.js +2 -1
  105. package/resolveConfig.d.ts +3 -0
  106. package/resolveConfig.js +2 -1
  107. package/scripts/create-plugin-list.js +2 -2
  108. package/scripts/generate-types.js +105 -0
  109. package/scripts/release-channel.js +18 -0
  110. package/scripts/release-notes.js +21 -0
  111. package/scripts/type-utils.js +27 -0
  112. package/src/cli/build/deps.js +56 -0
  113. package/src/cli/build/index.js +45 -0
  114. package/src/cli/build/plugin.js +397 -0
  115. package/src/cli/build/utils.js +76 -0
  116. package/src/cli/build/watching.js +134 -0
  117. package/src/cli/help/index.js +70 -0
  118. package/src/cli/index.js +3 -0
  119. package/src/cli/init/index.js +50 -0
  120. package/src/cli/shared.js +5 -0
  121. package/src/cli-peer-dependencies.js +7 -1
  122. package/src/cli.js +26 -565
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +905 -615
  125. package/src/css/preflight.css +20 -9
  126. package/src/featureFlags.js +26 -10
  127. package/src/index.js +19 -6
  128. package/src/lib/cacheInvalidation.js +52 -0
  129. package/src/lib/collapseAdjacentRules.js +21 -2
  130. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  131. package/src/lib/content.js +205 -0
  132. package/src/lib/defaultExtractor.js +211 -0
  133. package/src/lib/detectNesting.js +22 -3
  134. package/src/lib/evaluateTailwindFunctions.js +84 -10
  135. package/src/lib/expandApplyAtRules.js +488 -153
  136. package/src/lib/expandTailwindAtRules.js +94 -106
  137. package/src/lib/findAtConfigPath.js +50 -0
  138. package/src/lib/generateRules.js +589 -67
  139. package/src/lib/normalizeTailwindDirectives.js +10 -3
  140. package/src/lib/offsets.js +270 -0
  141. package/src/lib/partitionApplyAtRules.js +52 -0
  142. package/src/lib/regex.js +74 -0
  143. package/src/lib/resolveDefaultsAtRules.js +98 -60
  144. package/src/lib/setupContextUtils.js +737 -246
  145. package/src/lib/setupTrackingContext.js +16 -54
  146. package/src/lib/sharedState.js +44 -7
  147. package/src/lib/substituteScreenAtRules.js +6 -3
  148. package/src/postcss-plugins/nesting/README.md +42 -0
  149. package/src/postcss-plugins/nesting/index.js +13 -0
  150. package/src/postcss-plugins/nesting/plugin.js +80 -0
  151. package/src/processTailwindFeatures.js +17 -2
  152. package/src/public/colors.js +4 -9
  153. package/src/util/buildMediaQuery.js +14 -16
  154. package/src/util/cloneNodes.js +19 -2
  155. package/src/util/color.js +31 -14
  156. package/src/util/createUtilityPlugin.js +2 -2
  157. package/src/util/dataTypes.js +57 -21
  158. package/src/util/defaults.js +6 -0
  159. package/src/util/formatVariantSelector.js +319 -0
  160. package/src/util/getAllConfigs.js +19 -0
  161. package/src/util/isValidArbitraryValue.js +61 -0
  162. package/src/util/log.js +23 -22
  163. package/src/util/nameClass.js +6 -2
  164. package/src/util/negateValue.js +14 -4
  165. package/src/util/normalizeConfig.js +282 -0
  166. package/src/util/normalizeScreens.js +140 -0
  167. package/src/util/parseBoxShadowValue.js +72 -0
  168. package/src/util/parseDependency.js +37 -42
  169. package/src/util/parseGlob.js +24 -0
  170. package/src/util/pluginUtils.js +144 -152
  171. package/src/util/prefixSelector.js +7 -8
  172. package/src/util/removeAlphaVariables.js +24 -0
  173. package/src/util/resolveConfig.js +82 -81
  174. package/src/util/splitAtTopLevelOnly.js +45 -0
  175. package/src/util/toPath.js +23 -1
  176. package/src/util/transformThemeValue.js +33 -8
  177. package/src/util/validateConfig.js +13 -0
  178. package/src/util/validateFormalSyntax.js +34 -0
  179. package/src/util/withAlphaVariable.js +1 -1
  180. package/stubs/defaultConfig.stub.js +173 -93
  181. package/stubs/simpleConfig.stub.js +1 -1
  182. package/types/config.d.ts +361 -0
  183. package/types/generated/.gitkeep +0 -0
  184. package/types/generated/colors.d.ts +276 -0
  185. package/types/generated/corePluginList.d.ts +1 -0
  186. package/types/generated/default-theme.d.ts +342 -0
  187. package/types/index.d.ts +7 -0
  188. package/lib/lib/setupWatchingContext.js +0 -284
  189. package/nesting/plugin.js +0 -41
  190. package/src/lib/setupWatchingContext.js +0 -306
@@ -1,7 +1,6 @@
1
1
  import selectorParser from 'postcss-selector-parser'
2
2
  import escapeCommas from './escapeCommas'
3
3
  import { withAlphaValue } from './withAlphaVariable'
4
- import isKeyframeRule from './isKeyframeRule'
5
4
  import {
6
5
  normalize,
7
6
  length,
@@ -16,36 +15,16 @@ import {
16
15
  relativeSize,
17
16
  position,
18
17
  lineWidth,
18
+ shadow,
19
19
  } from './dataTypes'
20
-
21
- export function applyStateToMarker(selector, marker, state, join) {
22
- let markerIdx = selector.search(new RegExp(`${marker}[:[]`))
23
-
24
- if (markerIdx === -1) {
25
- return join(marker + state, selector)
26
- }
27
-
28
- let markerSelector = selector.slice(markerIdx, selector.indexOf(' ', markerIdx))
29
-
30
- return join(
31
- marker + state + markerSelector.slice(markerIdx + marker.length),
32
- selector.replace(markerSelector, '')
33
- )
34
- }
20
+ import negateValue from './negateValue'
21
+ import { backgroundSize } from './validateFormalSyntax'
22
+ import { flagEnabled } from '../featureFlags.js'
35
23
 
36
24
  export function updateAllClasses(selectors, updateClass) {
37
25
  let parser = selectorParser((selectors) => {
38
26
  selectors.walkClasses((sel) => {
39
- let updatedClass = updateClass(sel.value, {
40
- withAttr(className, attr) {
41
- sel.parent.insertAfter(sel, selectorParser.attribute({ attribute: attr.slice(1, -1) }))
42
- return className
43
- },
44
- withPseudo(className, pseudo) {
45
- sel.parent.insertAfter(sel, selectorParser.pseudo({ value: pseudo }))
46
- return className
47
- },
48
- })
27
+ let updatedClass = updateClass(sel.value)
49
28
  sel.value = updatedClass
50
29
  if (sel.raws && sel.raws.value) {
51
30
  sel.raws.value = escapeCommas(sel.raws.value)
@@ -58,164 +37,108 @@ export function updateAllClasses(selectors, updateClass) {
58
37
  return result
59
38
  }
60
39
 
61
- export function updateLastClasses(selectors, updateClass) {
62
- let parser = selectorParser((selectors) => {
63
- selectors.each((sel) => {
64
- let lastClass = sel.filter(({ type }) => type === 'class').pop()
65
-
66
- if (lastClass === undefined) {
67
- return
68
- }
69
-
70
- let updatedClass = updateClass(lastClass.value, {
71
- withPseudo(className, pseudo) {
72
- lastClass.parent.insertAfter(lastClass, selectorParser.pseudo({ value: `${pseudo}` }))
73
- return className
74
- },
75
- })
76
- lastClass.value = updatedClass
77
- if (lastClass.raws && lastClass.raws.value) {
78
- lastClass.raws.value = escapeCommas(lastClass.raws.value)
79
- }
80
- })
81
- })
82
- let result = parser.processSync(selectors)
83
-
84
- return result
85
- }
86
-
87
- function splitByNotEscapedCommas(str) {
88
- let chunks = []
89
- let currentChunk = ''
90
- for (let i = 0; i < str.length; i++) {
91
- if (str[i] === ',' && str[i - 1] !== '\\') {
92
- chunks.push(currentChunk)
93
- currentChunk = ''
94
- } else {
95
- currentChunk += str[i]
96
- }
40
+ function resolveArbitraryValue(modifier, validate) {
41
+ if (!isArbitraryValue(modifier)) {
42
+ return undefined
97
43
  }
98
- chunks.push(currentChunk)
99
- return chunks
100
- }
101
44
 
102
- export function transformAllSelectors(transformSelector, { wrap, withRule } = {}) {
103
- return ({ container }) => {
104
- container.walkRules((rule) => {
105
- if (isKeyframeRule(rule)) {
106
- return rule
107
- }
108
- let transformed = splitByNotEscapedCommas(rule.selector).map(transformSelector).join(',')
109
- rule.selector = transformed
110
- if (withRule) {
111
- withRule(rule)
112
- }
113
- return rule
114
- })
45
+ let value = modifier.slice(1, -1)
115
46
 
116
- if (wrap) {
117
- let wrapper = wrap()
118
- let nodes = container.nodes
119
- container.removeAll()
120
- wrapper.append(nodes)
121
- container.append(wrapper)
122
- }
47
+ if (!validate(value)) {
48
+ return undefined
123
49
  }
50
+
51
+ return normalize(value)
124
52
  }
125
53
 
126
- export function transformAllClasses(transformClass, { wrap, withRule } = {}) {
127
- return ({ container }) => {
128
- container.walkRules((rule) => {
129
- let selector = rule.selector
130
- let variantSelector = updateAllClasses(selector, transformClass)
131
- rule.selector = variantSelector
132
- if (withRule) {
133
- withRule(rule)
134
- }
135
- return rule
136
- })
54
+ function asNegativeValue(modifier, lookup = {}, validate) {
55
+ let positiveValue = lookup[modifier]
137
56
 
138
- if (wrap) {
139
- let wrapper = wrap()
140
- let nodes = container.nodes
141
- container.removeAll()
142
- wrapper.append(nodes)
143
- container.append(wrapper)
144
- }
57
+ if (positiveValue !== undefined) {
58
+ return negateValue(positiveValue)
145
59
  }
146
- }
147
60
 
148
- export function transformLastClasses(transformClass, { wrap, withRule } = {}) {
149
- return ({ container }) => {
150
- container.walkRules((rule) => {
151
- let selector = rule.selector
152
- let variantSelector = updateLastClasses(selector, transformClass)
153
- rule.selector = variantSelector
154
- if (withRule) {
155
- withRule(rule)
156
- }
157
- return rule
158
- })
61
+ if (isArbitraryValue(modifier)) {
62
+ let resolved = resolveArbitraryValue(modifier, validate)
159
63
 
160
- if (wrap) {
161
- let wrapper = wrap()
162
- let nodes = container.nodes
163
- container.removeAll()
164
- wrapper.append(nodes)
165
- container.append(wrapper)
64
+ if (resolved === undefined) {
65
+ return undefined
166
66
  }
67
+
68
+ return negateValue(resolved)
167
69
  }
168
70
  }
169
71
 
170
- export function asValue(modifier, lookup = {}, { validate = () => true } = {}) {
171
- let value = lookup[modifier]
72
+ export function asValue(modifier, options = {}, { validate = () => true } = {}) {
73
+ let value = options.values?.[modifier]
172
74
 
173
75
  if (value !== undefined) {
174
76
  return value
175
77
  }
176
78
 
177
- if (!isArbitraryValue(modifier)) {
178
- return undefined
179
- }
180
-
181
- value = modifier.slice(1, -1)
182
-
183
- if (!validate(value)) {
184
- return undefined
79
+ if (options.supportsNegativeValues && modifier.startsWith('-')) {
80
+ return asNegativeValue(modifier.slice(1), options.values, validate)
185
81
  }
186
82
 
187
- return normalize(value)
83
+ return resolveArbitraryValue(modifier, validate)
188
84
  }
189
85
 
190
86
  function isArbitraryValue(input) {
191
87
  return input.startsWith('[') && input.endsWith(']')
192
88
  }
193
89
 
194
- function splitAlpha(modifier) {
90
+ function splitUtilityModifier(modifier) {
195
91
  let slashIdx = modifier.lastIndexOf('/')
196
92
 
197
93
  if (slashIdx === -1 || slashIdx === modifier.length - 1) {
198
- return [modifier]
94
+ return [modifier, undefined]
95
+ }
96
+
97
+ let arbitrary = isArbitraryValue(modifier)
98
+
99
+ // The modifier could be of the form `[foo]/[bar]`
100
+ // We want to handle this case properly
101
+ // without affecting `[foo/bar]`
102
+ if (arbitrary && !modifier.includes(']/[')) {
103
+ return [modifier, undefined]
199
104
  }
200
105
 
201
106
  return [modifier.slice(0, slashIdx), modifier.slice(slashIdx + 1)]
202
107
  }
203
108
 
204
- export function asColor(modifier, lookup = {}, tailwindConfig = {}) {
205
- if (lookup[modifier] !== undefined) {
206
- return lookup[modifier]
109
+ export function parseColorFormat(value) {
110
+ if (typeof value === 'string' && value.includes('<alpha-value>')) {
111
+ let oldValue = value
112
+
113
+ return ({ opacityValue = 1 }) => oldValue.replace('<alpha-value>', opacityValue)
114
+ }
115
+
116
+ return value
117
+ }
118
+
119
+ export function asColor(
120
+ _,
121
+ options = {},
122
+ { tailwindConfig = {}, utilityModifier, rawModifier } = {}
123
+ ) {
124
+ if (options.values?.[rawModifier] !== undefined) {
125
+ return parseColorFormat(options.values?.[rawModifier])
207
126
  }
208
127
 
209
- let [color, alpha] = splitAlpha(modifier)
128
+ // TODO: Hoist this up to getMatchingTypes or something
129
+ // We do this here because we need the alpha value (if any)
130
+ let [color, alpha] = splitUtilityModifier(rawModifier)
210
131
 
211
132
  if (alpha !== undefined) {
212
133
  let normalizedColor =
213
- lookup[color] ?? (isArbitraryValue(color) ? color.slice(1, -1) : undefined)
134
+ options.values?.[color] ?? (isArbitraryValue(color) ? color.slice(1, -1) : undefined)
214
135
 
215
136
  if (normalizedColor === undefined) {
216
137
  return undefined
217
138
  }
218
139
 
140
+ normalizedColor = parseColorFormat(normalizedColor)
141
+
219
142
  if (isArbitraryValue(alpha)) {
220
143
  return withAlphaValue(normalizedColor, alpha.slice(1, -1))
221
144
  }
@@ -227,20 +150,20 @@ export function asColor(modifier, lookup = {}, tailwindConfig = {}) {
227
150
  return withAlphaValue(normalizedColor, tailwindConfig.theme.opacity[alpha])
228
151
  }
229
152
 
230
- return asValue(modifier, lookup, { validate: validateColor })
153
+ return asValue(rawModifier, options, { rawModifier, utilityModifier, validate: validateColor })
231
154
  }
232
155
 
233
- export function asLookupValue(modifier, lookup = {}) {
234
- return lookup[modifier]
156
+ export function asLookupValue(modifier, options = {}) {
157
+ return options.values?.[modifier]
235
158
  }
236
159
 
237
160
  function guess(validate) {
238
- return (modifier, lookup) => {
239
- return asValue(modifier, lookup, { validate })
161
+ return (modifier, options, extras) => {
162
+ return asValue(modifier, options, { ...extras, validate })
240
163
  }
241
164
  }
242
165
 
243
- let typeMap = {
166
+ export let typeMap = {
244
167
  any: asValue,
245
168
  color: asColor,
246
169
  url: guess(url),
@@ -255,6 +178,8 @@ let typeMap = {
255
178
  'line-width': guess(lineWidth),
256
179
  'absolute-size': guess(absoluteSize),
257
180
  'relative-size': guess(relativeSize),
181
+ shadow: guess(shadow),
182
+ size: guess(backgroundSize),
258
183
  }
259
184
 
260
185
  let supportedTypes = Object.keys(typeMap)
@@ -265,24 +190,91 @@ function splitAtFirst(input, delim) {
265
190
  return [input.slice(0, idx), input.slice(idx + 1)]
266
191
  }
267
192
 
268
- export function coerceValue(types, modifier, values, tailwindConfig) {
193
+ export function coerceValue(types, modifier, options, tailwindConfig) {
269
194
  if (isArbitraryValue(modifier)) {
270
- let [explicitType, value] = splitAtFirst(modifier.slice(1, -1), ':')
195
+ let arbitraryValue = modifier.slice(1, -1)
196
+ let [explicitType, value] = splitAtFirst(arbitraryValue, ':')
197
+
198
+ // It could be that this resolves to `url(https` which is not a valid
199
+ // identifier. We currently only support "simple" words with dashes or
200
+ // underscores. E.g.: family-name
201
+ if (!/^[\w-_]+$/g.test(explicitType)) {
202
+ value = arbitraryValue
203
+ }
271
204
 
272
- if (explicitType !== undefined && !supportedTypes.includes(explicitType)) {
205
+ //
206
+ else if (explicitType !== undefined && !supportedTypes.includes(explicitType)) {
273
207
  return []
274
208
  }
275
209
 
276
210
  if (value.length > 0 && supportedTypes.includes(explicitType)) {
277
- return [asValue(`[${value}]`, values, tailwindConfig), explicitType]
211
+ return [asValue(`[${value}]`, options), explicitType, null]
278
212
  }
279
213
  }
280
214
 
215
+ let matches = getMatchingTypes(types, modifier, options, tailwindConfig)
216
+
281
217
  // Find first matching type
282
- for (let type of [].concat(types)) {
283
- let result = typeMap[type](modifier, values, tailwindConfig)
284
- if (result) return [result, type]
218
+ for (let match of matches) {
219
+ return match
285
220
  }
286
221
 
287
222
  return []
288
223
  }
224
+
225
+ /**
226
+ *
227
+ * @param {{type: string}[]} types
228
+ * @param {string} rawModifier
229
+ * @param {any} options
230
+ * @param {any} tailwindConfig
231
+ * @returns {Iterator<[value: string, type: string, modifier: string | null]>}
232
+ */
233
+ export function* getMatchingTypes(types, rawModifier, options, tailwindConfig) {
234
+ let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
235
+
236
+ let canUseUtilityModifier =
237
+ modifiersEnabled &&
238
+ options.modifiers != null &&
239
+ (options.modifiers === 'any' || typeof options.modifiers === 'object')
240
+
241
+ let [modifier, utilityModifier] = canUseUtilityModifier
242
+ ? splitUtilityModifier(rawModifier)
243
+ : [rawModifier, undefined]
244
+
245
+ if (utilityModifier !== undefined && modifier === '') {
246
+ modifier = 'DEFAULT'
247
+ }
248
+
249
+ // Check the full value first
250
+ // TODO: Move to asValue… somehow
251
+ if (utilityModifier !== undefined) {
252
+ if (typeof options.modifiers === 'object') {
253
+ let configValue = options.modifiers?.[utilityModifier] ?? null
254
+ if (configValue !== null) {
255
+ utilityModifier = configValue
256
+ } else if (isArbitraryValue(utilityModifier)) {
257
+ utilityModifier = utilityModifier.slice(1, -1)
258
+ }
259
+ }
260
+
261
+ let result = asValue(rawModifier, options, { rawModifier, utilityModifier, tailwindConfig })
262
+ if (result !== undefined) {
263
+ yield [result, 'any', null]
264
+ }
265
+ }
266
+
267
+ for (const { type } of types ?? []) {
268
+ let result = typeMap[type](modifier, options, {
269
+ rawModifier,
270
+ utilityModifier,
271
+ tailwindConfig,
272
+ })
273
+
274
+ if (result === undefined) {
275
+ continue
276
+ }
277
+
278
+ yield [result, type, utilityModifier ?? null]
279
+ }
280
+ }
@@ -1,15 +1,14 @@
1
1
  import parser from 'postcss-selector-parser'
2
- import { tap } from './tap'
3
-
4
- export default function (prefix, selector) {
5
- const getPrefix =
6
- typeof prefix === 'function' ? prefix : () => (prefix === undefined ? '' : prefix)
7
2
 
3
+ export default function (prefix, selector, prependNegative = false) {
8
4
  return parser((selectors) => {
9
5
  selectors.walkClasses((classSelector) => {
10
- tap(classSelector.value, (baseClass) => {
11
- classSelector.value = `${getPrefix('.' + baseClass)}${baseClass}`
12
- })
6
+ let baseClass = classSelector.value
7
+ let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
8
+
9
+ classSelector.value = shouldPlaceNegativeBeforePrefix
10
+ ? `-${prefix}${baseClass.slice(1)}`
11
+ : `${prefix}${baseClass}`
13
12
  })
14
13
  }).processSync(selector)
15
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
+ }
@@ -3,9 +3,14 @@ import corePluginList from '../corePluginList'
3
3
  import configurePlugins from './configurePlugins'
4
4
  import defaultConfig from '../../stubs/defaultConfig.stub'
5
5
  import colors from '../public/colors'
6
- import log from './log'
7
6
  import { defaults } from './defaults'
8
7
  import { toPath } from './toPath'
8
+ import { normalizeConfig } from './normalizeConfig'
9
+ import isPlainObject from './isPlainObject'
10
+ import { cloneDeep } from './cloneDeep'
11
+ import { parseColorFormat } from './pluginUtils'
12
+ import { withAlphaValue } from './withAlphaVariable'
13
+ import toColorValue from './toColorValue'
9
14
 
10
15
  function isFunction(input) {
11
16
  return typeof input === 'function'
@@ -24,7 +29,7 @@ function mergeWith(target, ...sources) {
24
29
 
25
30
  if (merged === undefined) {
26
31
  if (isObject(target[k]) && isObject(source[k])) {
27
- target[k] = mergeWith(target[k], source[k], customizer)
32
+ target[k] = mergeWith({}, target[k], source[k], customizer)
28
33
  } else {
29
34
  target[k] = source[k]
30
35
  }
@@ -40,15 +45,18 @@ function mergeWith(target, ...sources) {
40
45
  const configUtils = {
41
46
  colors,
42
47
  negative(scale) {
48
+ // TODO: Log that this function isn't really needed anymore?
43
49
  return Object.keys(scale)
44
50
  .filter((key) => scale[key] !== '0')
45
- .reduce(
46
- (negativeScale, key) => ({
47
- ...negativeScale,
48
- [`-${key}`]: negateValue(scale[key]),
49
- }),
50
- {}
51
- )
51
+ .reduce((negativeScale, key) => {
52
+ let negativeValue = negateValue(scale[key])
53
+
54
+ if (negativeValue !== undefined) {
55
+ negativeScale[`-${key}`] = negativeValue
56
+ }
57
+
58
+ return negativeScale
59
+ }, {})
52
60
  },
53
61
  breakpoints(screens) {
54
62
  return Object.keys(screens)
@@ -129,32 +137,81 @@ function mergeExtensions({ extend, ...theme }) {
129
137
  })
130
138
  }
131
139
 
140
+ /**
141
+ *
142
+ * @param {string} key
143
+ * @return {Iterable<string[] & {alpha: string | undefined}>}
144
+ */
145
+ function* toPaths(key) {
146
+ let path = toPath(key)
147
+
148
+ if (path.length === 0) {
149
+ return
150
+ }
151
+
152
+ yield path
153
+
154
+ if (Array.isArray(key)) {
155
+ return
156
+ }
157
+
158
+ let pattern = /^(.*?)\s*\/\s*([^/]+)$/
159
+ let matches = key.match(pattern)
160
+
161
+ if (matches !== null) {
162
+ let [, prefix, alpha] = matches
163
+
164
+ let newPath = toPath(prefix)
165
+ newPath.alpha = alpha
166
+
167
+ yield newPath
168
+ }
169
+ }
170
+
132
171
  function resolveFunctionKeys(object) {
172
+ // theme('colors.red.500 / 0.5') -> ['colors', 'red', '500 / 0', '5]
173
+
133
174
  const resolvePath = (key, defaultValue) => {
134
- const path = toPath(key)
175
+ for (const path of toPaths(key)) {
176
+ let index = 0
177
+ let val = object
135
178
 
136
- let index = 0
137
- let val = object
179
+ while (val !== undefined && val !== null && index < path.length) {
180
+ val = val[path[index++]]
138
181
 
139
- while (val !== undefined && val !== null && index < path.length) {
140
- val = val[path[index++]]
141
- val = isFunction(val) ? val(resolvePath, configUtils) : val
142
- }
182
+ let shouldResolveAsFn =
183
+ isFunction(val) && (path.alpha === undefined || index <= path.length - 1)
143
184
 
144
- return val === undefined ? defaultValue : val
145
- }
185
+ val = shouldResolveAsFn ? val(resolvePath, configUtils) : val
186
+ }
187
+
188
+ if (val !== undefined) {
189
+ if (path.alpha !== undefined) {
190
+ let normalized = parseColorFormat(val)
191
+
192
+ return withAlphaValue(normalized, path.alpha, toColorValue(normalized))
193
+ }
146
194
 
147
- resolvePath.theme = resolvePath
195
+ if (isPlainObject(val)) {
196
+ return cloneDeep(val)
197
+ }
148
198
 
149
- for (let key in configUtils) {
150
- resolvePath[key] = configUtils[key]
199
+ return val
200
+ }
201
+ }
202
+
203
+ return defaultValue
151
204
  }
152
205
 
206
+ Object.assign(resolvePath, {
207
+ theme: resolvePath,
208
+ ...configUtils,
209
+ })
210
+
153
211
  return Object.keys(object).reduce((resolved, key) => {
154
- return {
155
- ...resolved,
156
- [key]: isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key],
157
- }
212
+ resolved[key] = isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key]
213
+
214
+ return resolved
158
215
  }, {})
159
216
  }
160
217
 
@@ -224,59 +281,3 @@ export default function resolveConfig(configs) {
224
281
  )
225
282
  )
226
283
  }
227
-
228
- let warnedAbout = new Set()
229
- function normalizeConfig(config) {
230
- if (!warnedAbout.has('purge-deprecation') && config.hasOwnProperty('purge')) {
231
- log.warn([
232
- 'The `purge` option in your tailwind.config.js file has been deprecated.',
233
- 'Please rename this to `content` instead.',
234
- ])
235
- warnedAbout.add('purge-deprecation')
236
- }
237
-
238
- config.content = {
239
- content: (() => {
240
- let { content, purge } = config
241
-
242
- if (Array.isArray(purge)) return purge
243
- if (Array.isArray(purge?.content)) return purge.content
244
- if (Array.isArray(content)) return content
245
- if (Array.isArray(content?.content)) return content.content
246
-
247
- return []
248
- })(),
249
- safelist: (() => {
250
- let { content, purge } = config
251
-
252
- let [safelistKey, safelistPaths] = (() => {
253
- if (Array.isArray(content?.safelist)) return ['content.safelist', content.safelist]
254
- if (Array.isArray(purge?.safelist)) return ['purge.safelist', purge.safelist]
255
- if (Array.isArray(purge?.options?.safelist))
256
- return ['purge.options.safelist', purge.options.safelist]
257
- return [null, []]
258
- })()
259
-
260
- return safelistPaths.map((content) => {
261
- if (typeof content === 'string') {
262
- return { raw: content, extension: 'html' }
263
- }
264
-
265
- if (content instanceof RegExp) {
266
- throw new Error(
267
- `Values inside '${safelistKey}' can only be of type 'string', found 'regex'.`
268
- )
269
- }
270
-
271
- throw new Error(
272
- `Values inside '${safelistKey}' can only be of type 'string', found '${typeof content}'.`
273
- )
274
- })
275
- })(),
276
- extract: config.content?.extract || config.purge?.extract || {},
277
- options: config.content?.options || config.purge?.options || {},
278
- transform: config.content?.transform || config.purge?.transform || {},
279
- }
280
-
281
- return config
282
- }