tailwindcss 0.0.0-insiders.fda68f7 → 0.0.0-oxide.6bf5e56

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 (195) hide show
  1. package/CHANGELOG.md +603 -2
  2. package/LICENSE +1 -2
  3. package/README.md +14 -6
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -304
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -4
  8. package/defaultTheme.d.ts +4 -0
  9. package/defaultTheme.js +2 -4
  10. package/lib/cli/build/deps.js +54 -0
  11. package/lib/cli/build/index.js +48 -0
  12. package/lib/cli/build/plugin.js +367 -0
  13. package/lib/cli/build/utils.js +78 -0
  14. package/lib/cli/build/watching.js +178 -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 +13 -0
  19. package/lib/cli-peer-dependencies.js +22 -14
  20. package/lib/cli.js +217 -743
  21. package/lib/constants.js +41 -34
  22. package/lib/corePluginList.js +178 -5
  23. package/lib/corePlugins.js +3879 -2941
  24. package/lib/css/preflight.css +22 -9
  25. package/lib/featureFlags.js +61 -50
  26. package/lib/index.js +45 -28
  27. package/lib/lib/cacheInvalidation.js +90 -0
  28. package/lib/lib/collapseAdjacentRules.js +52 -36
  29. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  30. package/lib/lib/content.js +176 -0
  31. package/lib/lib/defaultExtractor.js +236 -0
  32. package/lib/lib/detectNesting.js +37 -0
  33. package/lib/lib/evaluateTailwindFunctions.js +203 -161
  34. package/lib/lib/expandApplyAtRules.js +502 -221
  35. package/lib/lib/expandTailwindAtRules.js +258 -243
  36. package/lib/lib/findAtConfigPath.js +44 -0
  37. package/lib/lib/generateRules.js +775 -320
  38. package/lib/lib/getModuleDependencies.js +44 -46
  39. package/lib/lib/normalizeTailwindDirectives.js +79 -60
  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 +150 -94
  44. package/lib/lib/setupContextUtils.js +1146 -599
  45. package/lib/lib/setupTrackingContext.js +129 -177
  46. package/lib/lib/sharedState.js +53 -21
  47. package/lib/lib/substituteScreenAtRules.js +26 -28
  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 +58 -53
  52. package/lib/public/colors.js +331 -0
  53. package/lib/public/create-plugin.js +15 -0
  54. package/lib/public/default-config.js +16 -0
  55. package/lib/public/default-theme.js +16 -0
  56. package/lib/public/resolve-config.js +22 -0
  57. package/lib/util/bigSign.js +7 -6
  58. package/lib/util/buildMediaQuery.js +21 -32
  59. package/lib/util/cloneDeep.js +16 -14
  60. package/lib/util/cloneNodes.js +29 -15
  61. package/lib/util/color.js +90 -66
  62. package/lib/util/configurePlugins.js +17 -15
  63. package/lib/util/createPlugin.js +23 -26
  64. package/lib/util/createUtilityPlugin.js +46 -46
  65. package/lib/util/dataTypes.js +242 -0
  66. package/lib/util/defaults.js +20 -15
  67. package/lib/util/escapeClassName.js +18 -17
  68. package/lib/util/escapeCommas.js +7 -6
  69. package/lib/util/flattenColorPalette.js +13 -12
  70. package/lib/util/formatVariantSelector.js +285 -0
  71. package/lib/util/getAllConfigs.js +44 -18
  72. package/lib/util/hashConfig.js +15 -12
  73. package/lib/util/isKeyframeRule.js +7 -6
  74. package/lib/util/isPlainObject.js +11 -11
  75. package/lib/util/isSyntacticallyValidPropertyValue.js +72 -0
  76. package/lib/util/log.js +52 -33
  77. package/lib/util/nameClass.js +37 -26
  78. package/lib/util/negateValue.js +31 -17
  79. package/lib/util/normalizeConfig.js +281 -0
  80. package/lib/util/normalizeScreens.js +170 -0
  81. package/lib/util/parseAnimationValue.js +85 -54
  82. package/lib/util/parseBoxShadowValue.js +84 -0
  83. package/lib/util/parseDependency.js +41 -70
  84. package/lib/util/parseGlob.js +34 -0
  85. package/lib/util/parseObjectStyles.js +30 -24
  86. package/lib/util/pluginUtils.js +252 -287
  87. package/lib/util/prefixSelector.js +20 -20
  88. package/lib/util/removeAlphaVariables.js +29 -0
  89. package/lib/util/resolveConfig.js +221 -256
  90. package/lib/util/resolveConfigPath.js +43 -48
  91. package/lib/util/responsive.js +18 -14
  92. package/lib/util/splitAtTopLevelOnly.js +43 -0
  93. package/lib/util/tap.js +8 -7
  94. package/lib/util/toColorValue.js +7 -6
  95. package/lib/util/toPath.js +27 -8
  96. package/lib/util/transformThemeValue.js +67 -28
  97. package/lib/util/validateConfig.js +24 -0
  98. package/lib/util/validateFormalSyntax.js +24 -0
  99. package/lib/util/withAlphaVariable.js +67 -57
  100. package/nesting/index.js +2 -12
  101. package/package.json +60 -65
  102. package/peers/index.js +76445 -84221
  103. package/plugin.d.ts +11 -0
  104. package/plugin.js +1 -2
  105. package/resolveConfig.d.ts +12 -0
  106. package/resolveConfig.js +2 -7
  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 +49 -0
  114. package/src/cli/build/plugin.js +439 -0
  115. package/src/cli/build/utils.js +76 -0
  116. package/src/cli/build/watching.js +227 -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 +6 -0
  121. package/src/cli-peer-dependencies.js +7 -1
  122. package/src/cli.js +50 -575
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +2405 -1948
  125. package/src/css/preflight.css +22 -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 +212 -0
  132. package/src/lib/defaultExtractor.js +211 -0
  133. package/src/lib/detectNesting.js +39 -0
  134. package/src/lib/evaluateTailwindFunctions.js +84 -10
  135. package/src/lib/expandApplyAtRules.js +508 -153
  136. package/src/lib/expandTailwindAtRules.js +130 -104
  137. package/src/lib/findAtConfigPath.js +48 -0
  138. package/src/lib/generateRules.js +596 -70
  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 +105 -47
  144. package/src/lib/setupContextUtils.js +828 -196
  145. package/src/lib/setupTrackingContext.js +19 -54
  146. package/src/lib/sharedState.js +45 -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 +19 -2
  152. package/src/public/colors.js +300 -0
  153. package/src/public/create-plugin.js +2 -0
  154. package/src/public/default-config.js +4 -0
  155. package/src/public/default-theme.js +4 -0
  156. package/src/public/resolve-config.js +7 -0
  157. package/src/util/buildMediaQuery.js +14 -16
  158. package/src/util/cloneNodes.js +19 -2
  159. package/src/util/color.js +31 -14
  160. package/src/util/createUtilityPlugin.js +2 -11
  161. package/src/util/dataTypes.js +256 -0
  162. package/src/util/defaults.js +6 -0
  163. package/src/util/formatVariantSelector.js +319 -0
  164. package/src/util/getAllConfigs.js +19 -0
  165. package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
  166. package/src/util/log.js +23 -22
  167. package/src/util/nameClass.js +14 -6
  168. package/src/util/negateValue.js +15 -5
  169. package/src/util/normalizeConfig.js +300 -0
  170. package/src/util/normalizeScreens.js +140 -0
  171. package/src/util/parseAnimationValue.js +7 -1
  172. package/src/util/parseBoxShadowValue.js +72 -0
  173. package/src/util/parseDependency.js +37 -38
  174. package/src/util/parseGlob.js +24 -0
  175. package/src/util/pluginUtils.js +216 -197
  176. package/src/util/prefixSelector.js +7 -8
  177. package/src/util/removeAlphaVariables.js +24 -0
  178. package/src/util/resolveConfig.js +86 -91
  179. package/src/util/splitAtTopLevelOnly.js +45 -0
  180. package/src/util/toPath.js +23 -1
  181. package/src/util/transformThemeValue.js +33 -8
  182. package/src/util/validateConfig.js +13 -0
  183. package/src/util/validateFormalSyntax.js +34 -0
  184. package/src/util/withAlphaVariable.js +14 -9
  185. package/stubs/defaultConfig.stub.js +186 -117
  186. package/stubs/simpleConfig.stub.js +1 -1
  187. package/types/config.d.ts +362 -0
  188. package/types/generated/.gitkeep +0 -0
  189. package/types/generated/colors.d.ts +276 -0
  190. package/types/generated/corePluginList.d.ts +1 -0
  191. package/types/generated/default-theme.d.ts +342 -0
  192. package/types/index.d.ts +7 -0
  193. package/lib/lib/setupWatchingContext.js +0 -331
  194. package/nesting/plugin.js +0 -41
  195. package/src/lib/setupWatchingContext.js +0 -306
@@ -0,0 +1,256 @@
1
+ import { parseColor } from './color'
2
+ import { parseBoxShadowValue } from './parseBoxShadowValue'
3
+ import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
4
+
5
+ let cssFunctions = ['min', 'max', 'clamp', 'calc']
6
+
7
+ // Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
8
+
9
+ function isCSSFunction(value) {
10
+ return cssFunctions.some((fn) => new RegExp(`^${fn}\\(.*\\)`).test(value))
11
+ }
12
+
13
+ // This is not a data type, but rather a function that can normalize the
14
+ // correct values.
15
+ export function normalize(value, isRoot = true) {
16
+ if (value.startsWith('--')) {
17
+ return `var(${value})`
18
+ }
19
+
20
+ // Keep raw strings if it starts with `url(`
21
+ if (value.includes('url(')) {
22
+ return value
23
+ .split(/(url\(.*?\))/g)
24
+ .filter(Boolean)
25
+ .map((part) => {
26
+ if (/^url\(.*?\)$/.test(part)) {
27
+ return part
28
+ }
29
+
30
+ return normalize(part, false)
31
+ })
32
+ .join('')
33
+ }
34
+
35
+ // Convert `_` to ` `, except for escaped underscores `\_`
36
+ value = value
37
+ .replace(
38
+ /([^\\])_+/g,
39
+ (fullMatch, characterBefore) => characterBefore + ' '.repeat(fullMatch.length - 1)
40
+ )
41
+ .replace(/^_/g, ' ')
42
+ .replace(/\\_/g, '_')
43
+
44
+ // Remove leftover whitespace
45
+ if (isRoot) {
46
+ value = value.trim()
47
+ }
48
+
49
+ // Add spaces around operators inside math functions like calc() that do not follow an operator
50
+ // or '('.
51
+ value = value.replace(/(calc|min|max|clamp)\(.+\)/g, (match) => {
52
+ return match.replace(
53
+ /(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
54
+ '$1 $2 '
55
+ )
56
+ })
57
+
58
+ return value
59
+ }
60
+
61
+ export function url(value) {
62
+ return value.startsWith('url(')
63
+ }
64
+
65
+ export function number(value) {
66
+ return !isNaN(Number(value)) || isCSSFunction(value)
67
+ }
68
+
69
+ export function percentage(value) {
70
+ return (value.endsWith('%') && number(value.slice(0, -1))) || isCSSFunction(value)
71
+ }
72
+
73
+ let lengthUnits = [
74
+ 'cm',
75
+ 'mm',
76
+ 'Q',
77
+ 'in',
78
+ 'pc',
79
+ 'pt',
80
+ 'px',
81
+ 'em',
82
+ 'ex',
83
+ 'ch',
84
+ 'rem',
85
+ 'lh',
86
+ 'vw',
87
+ 'vh',
88
+ 'vmin',
89
+ 'vmax',
90
+ ]
91
+ let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
92
+ export function length(value) {
93
+ return (
94
+ value === '0' ||
95
+ new RegExp(`^[+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`).test(value) ||
96
+ isCSSFunction(value)
97
+ )
98
+ }
99
+
100
+ let lineWidths = new Set(['thin', 'medium', 'thick'])
101
+ export function lineWidth(value) {
102
+ return lineWidths.has(value)
103
+ }
104
+
105
+ export function shadow(value) {
106
+ let parsedShadows = parseBoxShadowValue(normalize(value))
107
+
108
+ for (let parsedShadow of parsedShadows) {
109
+ if (!parsedShadow.valid) {
110
+ return false
111
+ }
112
+ }
113
+
114
+ return true
115
+ }
116
+
117
+ export function color(value) {
118
+ let colors = 0
119
+
120
+ let result = splitAtTopLevelOnly(value, '_').every((part) => {
121
+ part = normalize(part)
122
+
123
+ if (part.startsWith('var(')) return true
124
+ if (parseColor(part, { loose: true }) !== null) return colors++, true
125
+
126
+ return false
127
+ })
128
+
129
+ if (!result) return false
130
+ return colors > 0
131
+ }
132
+
133
+ export function image(value) {
134
+ let images = 0
135
+ let result = splitAtTopLevelOnly(value, ',').every((part) => {
136
+ part = normalize(part)
137
+
138
+ if (part.startsWith('var(')) return true
139
+ if (
140
+ url(part) ||
141
+ gradient(part) ||
142
+ ['element(', 'image(', 'cross-fade(', 'image-set('].some((fn) => part.startsWith(fn))
143
+ ) {
144
+ images++
145
+ return true
146
+ }
147
+
148
+ return false
149
+ })
150
+
151
+ if (!result) return false
152
+ return images > 0
153
+ }
154
+
155
+ let gradientTypes = new Set([
156
+ 'linear-gradient',
157
+ 'radial-gradient',
158
+ 'repeating-linear-gradient',
159
+ 'repeating-radial-gradient',
160
+ 'conic-gradient',
161
+ ])
162
+ export function gradient(value) {
163
+ value = normalize(value)
164
+
165
+ for (let type of gradientTypes) {
166
+ if (value.startsWith(`${type}(`)) {
167
+ return true
168
+ }
169
+ }
170
+ return false
171
+ }
172
+
173
+ let validPositions = new Set(['center', 'top', 'right', 'bottom', 'left'])
174
+ export function position(value) {
175
+ let positions = 0
176
+ let result = splitAtTopLevelOnly(value, '_').every((part) => {
177
+ part = normalize(part)
178
+
179
+ if (part.startsWith('var(')) return true
180
+ if (validPositions.has(part) || length(part) || percentage(part)) {
181
+ positions++
182
+ return true
183
+ }
184
+
185
+ return false
186
+ })
187
+
188
+ if (!result) return false
189
+ return positions > 0
190
+ }
191
+
192
+ export function familyName(value) {
193
+ let fonts = 0
194
+ let result = splitAtTopLevelOnly(value, ',').every((part) => {
195
+ part = normalize(part)
196
+
197
+ if (part.startsWith('var(')) return true
198
+
199
+ // If it contains spaces, then it should be quoted
200
+ if (part.includes(' ')) {
201
+ if (!/(['"])([^"']+)\1/g.test(part)) {
202
+ return false
203
+ }
204
+ }
205
+
206
+ // If it starts with a number, it's invalid
207
+ if (/^\d/g.test(part)) {
208
+ return false
209
+ }
210
+
211
+ fonts++
212
+
213
+ return true
214
+ })
215
+
216
+ if (!result) return false
217
+ return fonts > 0
218
+ }
219
+
220
+ let genericNames = new Set([
221
+ 'serif',
222
+ 'sans-serif',
223
+ 'monospace',
224
+ 'cursive',
225
+ 'fantasy',
226
+ 'system-ui',
227
+ 'ui-serif',
228
+ 'ui-sans-serif',
229
+ 'ui-monospace',
230
+ 'ui-rounded',
231
+ 'math',
232
+ 'emoji',
233
+ 'fangsong',
234
+ ])
235
+ export function genericName(value) {
236
+ return genericNames.has(value)
237
+ }
238
+
239
+ let absoluteSizes = new Set([
240
+ 'xx-small',
241
+ 'x-small',
242
+ 'small',
243
+ 'medium',
244
+ 'large',
245
+ 'x-large',
246
+ 'x-large',
247
+ 'xxx-large',
248
+ ])
249
+ export function absoluteSize(value) {
250
+ return absoluteSizes.has(value)
251
+ }
252
+
253
+ let relativeSizes = new Set(['larger', 'smaller'])
254
+ export function relativeSize(value) {
255
+ return relativeSizes.has(value)
256
+ }
@@ -5,6 +5,12 @@ export function defaults(target, ...sources) {
5
5
  target[k] = source[k]
6
6
  }
7
7
  }
8
+
9
+ for (let k of Object.getOwnPropertySymbols(source)) {
10
+ if (!target?.hasOwnProperty?.(k)) {
11
+ target[k] = source[k]
12
+ }
13
+ }
8
14
  }
9
15
 
10
16
  return target
@@ -0,0 +1,319 @@
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
+ /**
33
+ * Given any node in a selector this gets the "simple" selector it's a part of
34
+ * A simple selector is just a list of nodes without any combinators
35
+ * Technically :is(), :not(), :has(), etc… can have combinators but those are nested
36
+ * inside the relevant node and won't be picked up so they're fine to ignore
37
+ *
38
+ * @param {import('postcss-selector-parser').Node} node
39
+ * @returns {import('postcss-selector-parser').Node[]}
40
+ **/
41
+ function simpleSelectorForNode(node) {
42
+ /** @type {import('postcss-selector-parser').Node[]} */
43
+ let nodes = []
44
+
45
+ // Walk backwards until we hit a combinator node (or the start)
46
+ while (node.prev() && node.prev().type !== 'combinator') {
47
+ node = node.prev()
48
+ }
49
+
50
+ // Now record all non-combinator nodes until we hit one (or the end)
51
+ while (node && node.type !== 'combinator') {
52
+ nodes.push(node)
53
+ node = node.next()
54
+ }
55
+
56
+ return nodes
57
+ }
58
+
59
+ /**
60
+ * Resorts the nodes in a selector to ensure they're in the correct order
61
+ * Tags go before classes, and pseudo classes go after classes
62
+ *
63
+ * @param {import('postcss-selector-parser').Selector} sel
64
+ * @returns {import('postcss-selector-parser').Selector}
65
+ **/
66
+ function resortSelector(sel) {
67
+ sel.sort((a, b) => {
68
+ if (a.type === 'tag' && b.type === 'class') {
69
+ return -1
70
+ } else if (a.type === 'class' && b.type === 'tag') {
71
+ return 1
72
+ } else if (a.type === 'class' && b.type === 'pseudo' && b.value.startsWith('::')) {
73
+ return -1
74
+ } else if (a.type === 'pseudo' && a.value.startsWith('::') && b.type === 'class') {
75
+ return 1
76
+ }
77
+
78
+ return sel.index(a) - sel.index(b)
79
+ })
80
+
81
+ return sel
82
+ }
83
+
84
+ function eliminateIrrelevantSelectors(sel, base) {
85
+ let hasClassesMatchingCandidate = false
86
+
87
+ sel.walk((child) => {
88
+ if (child.type === 'class' && child.value === base) {
89
+ hasClassesMatchingCandidate = true
90
+ return false // Stop walking
91
+ }
92
+ })
93
+
94
+ if (!hasClassesMatchingCandidate) {
95
+ sel.remove()
96
+ }
97
+
98
+ // We do NOT recursively eliminate sub selectors that don't have the base class
99
+ // as this is NOT a safe operation. For example, if we have:
100
+ // `.space-x-2 > :not([hidden]) ~ :not([hidden])`
101
+ // We cannot remove the [hidden] from the :not() because it would change the
102
+ // meaning of the selector.
103
+
104
+ // TODO: Can we do this for :matches, :is, and :where?
105
+ }
106
+
107
+ export function finalizeSelector(
108
+ format,
109
+ {
110
+ selector,
111
+ candidate,
112
+ context,
113
+ isArbitraryVariant,
114
+
115
+ // Split by the separator, but ignore the separator inside square brackets:
116
+ //
117
+ // E.g.: dark:lg:hover:[paint-order:markers]
118
+ // ┬ ┬ ┬ ┬
119
+ // │ │ │ ╰── We will not split here
120
+ // ╰──┴─────┴─────────────── We will split here
121
+ //
122
+ base = candidate
123
+ .split(new RegExp(`\\${context?.tailwindConfig?.separator ?? ':'}(?![^[]*\\])`))
124
+ .pop(),
125
+ }
126
+ ) {
127
+ let ast = selectorParser().astSync(selector)
128
+
129
+ // We explicitly DO NOT prefix classes in arbitrary variants
130
+ if (context?.tailwindConfig?.prefix && !isArbitraryVariant) {
131
+ format = prefixSelector(context.tailwindConfig.prefix, format)
132
+ }
133
+
134
+ format = format.replace(PARENT, `.${escapeClassName(candidate)}`)
135
+
136
+ let formatAst = selectorParser().astSync(format)
137
+
138
+ // Remove extraneous selectors that do not include the base class/candidate being matched against
139
+ // For example if we have a utility defined `.a, .b { color: red}`
140
+ // And the formatted variant is sm:b then we want the final selector to be `.sm\:b` and not `.a, .sm\:b`
141
+ ast.each((sel) => eliminateIrrelevantSelectors(sel, base))
142
+
143
+ // Normalize escaped classes, e.g.:
144
+ //
145
+ // The idea would be to replace the escaped `base` in the selector with the
146
+ // `format`. However, in css you can escape the same selector in a few
147
+ // different ways. This would result in different strings and therefore we
148
+ // can't replace it properly.
149
+ //
150
+ // base: bg-[rgb(255,0,0)]
151
+ // base in selector: bg-\\[rgb\\(255\\,0\\,0\\)\\]
152
+ // escaped base: bg-\\[rgb\\(255\\2c 0\\2c 0\\)\\]
153
+ //
154
+ ast.walkClasses((node) => {
155
+ if (node.raws && node.value.includes(base)) {
156
+ node.raws.value = escapeClassName(unescape(node.raws.value))
157
+ }
158
+ })
159
+
160
+ let simpleStart = selectorParser.comment({ value: '/*__simple__*/' })
161
+ let simpleEnd = selectorParser.comment({ value: '/*__simple__*/' })
162
+
163
+ // We can safely replace the escaped base now, since the `base` section is
164
+ // now in a normalized escaped value.
165
+ ast.walkClasses((node) => {
166
+ if (node.value !== base) {
167
+ return
168
+ }
169
+
170
+ let parent = node.parent
171
+ let formatNodes = formatAst.nodes[0].nodes
172
+
173
+ // Perf optimization: if the parent is a single class we can just replace it and be done
174
+ if (parent.nodes.length === 1) {
175
+ node.replaceWith(...formatNodes)
176
+ return
177
+ }
178
+
179
+ let simpleSelector = simpleSelectorForNode(node)
180
+ parent.insertBefore(simpleSelector[0], simpleStart)
181
+ parent.insertAfter(simpleSelector[simpleSelector.length - 1], simpleEnd)
182
+
183
+ for (let child of formatNodes) {
184
+ parent.insertBefore(simpleSelector[0], child)
185
+ }
186
+
187
+ node.remove()
188
+
189
+ // Re-sort the simple selector to ensure it's in the correct order
190
+ simpleSelector = simpleSelectorForNode(simpleStart)
191
+ let firstNode = parent.index(simpleStart)
192
+
193
+ parent.nodes.splice(
194
+ firstNode,
195
+ simpleSelector.length,
196
+ ...resortSelector(selectorParser.selector({ nodes: simpleSelector })).nodes
197
+ )
198
+
199
+ simpleStart.remove()
200
+ simpleEnd.remove()
201
+ })
202
+
203
+ // This will make sure to move pseudo's to the correct spot (the end for
204
+ // pseudo elements) because otherwise the selector will never work
205
+ // anyway.
206
+ //
207
+ // E.g.:
208
+ // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
209
+ // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
210
+ //
211
+ // `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
212
+ function collectPseudoElements(selector) {
213
+ let nodes = []
214
+
215
+ for (let node of selector.nodes) {
216
+ if (isPseudoElement(node)) {
217
+ nodes.push(node)
218
+ selector.removeChild(node)
219
+ }
220
+
221
+ if (node?.nodes) {
222
+ nodes.push(...collectPseudoElements(node))
223
+ }
224
+ }
225
+
226
+ return nodes
227
+ }
228
+
229
+ // Remove unnecessary pseudo selectors that we used as placeholders
230
+ ast.each((selector) => {
231
+ selector.walkPseudos((p) => {
232
+ if (selectorFunctions.has(p.value)) {
233
+ p.replaceWith(p.nodes)
234
+ }
235
+ })
236
+
237
+ let pseudoElements = collectPseudoElements(selector)
238
+ if (pseudoElements.length > 0) {
239
+ selector.nodes.push(pseudoElements.sort(sortSelector))
240
+ }
241
+ })
242
+
243
+ return ast.toString()
244
+ }
245
+
246
+ // Note: As a rule, double colons (::) should be used instead of a single colon
247
+ // (:). This distinguishes pseudo-classes from pseudo-elements. However, since
248
+ // this distinction was not present in older versions of the W3C spec, most
249
+ // browsers support both syntaxes for the original pseudo-elements.
250
+ let pseudoElementsBC = [':before', ':after', ':first-line', ':first-letter']
251
+
252
+ // These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
253
+ let pseudoElementExceptions = ['::file-selector-button']
254
+
255
+ // This will make sure to move pseudo's to the correct spot (the end for
256
+ // pseudo elements) because otherwise the selector will never work
257
+ // anyway.
258
+ //
259
+ // E.g.:
260
+ // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
261
+ // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
262
+ //
263
+ // `::before:hover` doesn't work, which means that we can make it work
264
+ // for you by flipping the order.
265
+ function sortSelector(a, z) {
266
+ // Both nodes are non-pseudo's so we can safely ignore them and keep
267
+ // them in the same order.
268
+ if (a.type !== 'pseudo' && z.type !== 'pseudo') {
269
+ return 0
270
+ }
271
+
272
+ // If one of them is a combinator, we need to keep it in the same order
273
+ // because that means it will start a new "section" in the selector.
274
+ if ((a.type === 'combinator') ^ (z.type === 'combinator')) {
275
+ return 0
276
+ }
277
+
278
+ // One of the items is a pseudo and the other one isn't. Let's move
279
+ // the pseudo to the right.
280
+ if ((a.type === 'pseudo') ^ (z.type === 'pseudo')) {
281
+ return (a.type === 'pseudo') - (z.type === 'pseudo')
282
+ }
283
+
284
+ // Both are pseudo's, move the pseudo elements (except for
285
+ // ::file-selector-button) to the right.
286
+ return isPseudoElement(a) - isPseudoElement(z)
287
+ }
288
+
289
+ function isPseudoElement(node) {
290
+ if (node.type !== 'pseudo') return false
291
+ if (pseudoElementExceptions.includes(node.value)) return false
292
+
293
+ return node.value.startsWith('::') || pseudoElementsBC.includes(node.value)
294
+ }
295
+
296
+ function resolveFunctionArgument(haystack, needle, arg) {
297
+ let startIdx = haystack.indexOf(arg ? `${needle}(${arg})` : needle)
298
+ if (startIdx === -1) return null
299
+
300
+ // Start inside the `(`
301
+ startIdx += needle.length + 1
302
+
303
+ let target = ''
304
+ let count = 0
305
+
306
+ for (let char of haystack.slice(startIdx)) {
307
+ if (char !== '(' && char !== ')') {
308
+ target += char
309
+ } else if (char === '(') {
310
+ target += char
311
+ count++
312
+ } else if (char === ')') {
313
+ if (--count < 0) break // unbalanced
314
+ target += char
315
+ }
316
+ }
317
+
318
+ return target
319
+ }
@@ -9,6 +9,25 @@ export default function getAllConfigs(config) {
9
9
 
10
10
  const features = {
11
11
  // Add experimental configs here...
12
+ respectDefaultRingColorOpacity: {
13
+ theme: {
14
+ ringColor: ({ theme }) => ({
15
+ DEFAULT: '#3b82f67f',
16
+ ...theme('colors'),
17
+ }),
18
+ },
19
+ },
20
+
21
+ disableColorOpacityUtilitiesByDefault: {
22
+ corePlugins: {
23
+ backgroundOpacity: false,
24
+ borderOpacity: false,
25
+ divideOpacity: false,
26
+ placeholderOpacity: false,
27
+ ringOpacity: false,
28
+ textOpacity: false,
29
+ },
30
+ },
12
31
  }
13
32
 
14
33
  const experimentals = Object.keys(features)
@@ -0,0 +1,61 @@
1
+ let matchingBrackets = new Map([
2
+ ['{', '}'],
3
+ ['[', ']'],
4
+ ['(', ')'],
5
+ ])
6
+ let inverseMatchingBrackets = new Map(
7
+ Array.from(matchingBrackets.entries()).map(([k, v]) => [v, k])
8
+ )
9
+
10
+ let quotes = new Set(['"', "'", '`'])
11
+
12
+ // Arbitrary values must contain balanced brackets (), [] and {}. Escaped
13
+ // values don't count, and brackets inside quotes also don't count.
14
+ //
15
+ // E.g.: w-[this-is]w-[weird-and-invalid]
16
+ // E.g.: w-[this-is\\]w-\\[weird-but-valid]
17
+ // E.g.: content-['this-is-also-valid]-weirdly-enough']
18
+ export default function isSyntacticallyValidPropertyValue(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
+ }