tailwindcss 0.0.0-insiders.ea139f2 → 0.0.0-insiders.ea4e1cd

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 (236) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -7
  3. package/colors.d.ts +3 -0
  4. package/colors.js +2 -1
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultConfig.js +2 -1
  7. package/defaultTheme.d.ts +4 -0
  8. package/defaultTheme.js +2 -1
  9. package/lib/cli/build/deps.js +62 -0
  10. package/lib/cli/build/index.js +54 -0
  11. package/lib/cli/build/plugin.js +378 -0
  12. package/lib/cli/build/utils.js +88 -0
  13. package/lib/cli/build/watching.js +182 -0
  14. package/lib/cli/help/index.js +73 -0
  15. package/lib/cli/index.js +230 -0
  16. package/lib/cli/init/index.js +63 -0
  17. package/lib/cli-peer-dependencies.js +28 -7
  18. package/lib/cli.js +4 -703
  19. package/lib/corePluginList.js +12 -3
  20. package/lib/corePlugins.js +2373 -1863
  21. package/lib/css/preflight.css +10 -8
  22. package/lib/featureFlags.js +49 -26
  23. package/lib/index.js +1 -31
  24. package/lib/lib/cacheInvalidation.js +92 -0
  25. package/lib/lib/collapseAdjacentRules.js +30 -10
  26. package/lib/lib/collapseDuplicateDeclarations.js +60 -4
  27. package/lib/lib/content.js +181 -0
  28. package/lib/lib/defaultExtractor.js +243 -0
  29. package/lib/lib/detectNesting.js +21 -10
  30. package/lib/lib/evaluateTailwindFunctions.js +115 -50
  31. package/lib/lib/expandApplyAtRules.js +467 -161
  32. package/lib/lib/expandTailwindAtRules.js +160 -133
  33. package/lib/lib/findAtConfigPath.js +46 -0
  34. package/lib/lib/generateRules.js +553 -200
  35. package/lib/lib/getModuleDependencies.js +88 -37
  36. package/lib/lib/load-config.js +42 -0
  37. package/lib/lib/normalizeTailwindDirectives.js +46 -33
  38. package/lib/lib/offsets.js +306 -0
  39. package/lib/lib/partitionApplyAtRules.js +58 -0
  40. package/lib/lib/regex.js +74 -0
  41. package/lib/lib/remap-bitfield.js +89 -0
  42. package/lib/lib/resolveDefaultsAtRules.js +98 -58
  43. package/lib/lib/setupContextUtils.js +773 -321
  44. package/lib/lib/setupTrackingContext.js +70 -75
  45. package/lib/lib/sharedState.js +78 -10
  46. package/lib/lib/substituteScreenAtRules.js +14 -10
  47. package/lib/oxide/cli/build/deps.js +89 -0
  48. package/lib/oxide/cli/build/index.js +53 -0
  49. package/lib/oxide/cli/build/plugin.js +375 -0
  50. package/lib/oxide/cli/build/utils.js +87 -0
  51. package/lib/oxide/cli/build/watching.js +179 -0
  52. package/lib/oxide/cli/help/index.js +72 -0
  53. package/lib/oxide/cli/index.js +214 -0
  54. package/lib/oxide/cli/init/index.js +52 -0
  55. package/lib/oxide/cli.js +5 -0
  56. package/lib/oxide/postcss-plugin.js +2 -0
  57. package/lib/plugin.js +98 -0
  58. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  59. package/lib/postcss-plugins/nesting/index.js +21 -0
  60. package/lib/postcss-plugins/nesting/plugin.js +89 -0
  61. package/lib/processTailwindFeatures.js +39 -26
  62. package/lib/public/colors.js +272 -246
  63. package/lib/public/create-plugin.js +9 -5
  64. package/lib/public/default-config.js +10 -6
  65. package/lib/public/default-theme.js +10 -6
  66. package/lib/public/load-config.js +12 -0
  67. package/lib/public/resolve-config.js +11 -6
  68. package/lib/util/applyImportantSelector.js +36 -0
  69. package/lib/util/bigSign.js +6 -1
  70. package/lib/util/buildMediaQuery.js +13 -6
  71. package/lib/util/cloneDeep.js +9 -6
  72. package/lib/util/cloneNodes.js +23 -3
  73. package/lib/util/color.js +70 -38
  74. package/lib/util/colorNames.js +752 -0
  75. package/lib/util/configurePlugins.js +7 -2
  76. package/lib/util/createPlugin.js +8 -6
  77. package/lib/util/createUtilityPlugin.js +16 -16
  78. package/lib/util/dataTypes.js +173 -108
  79. package/lib/util/defaults.js +14 -3
  80. package/lib/util/escapeClassName.js +13 -8
  81. package/lib/util/escapeCommas.js +7 -2
  82. package/lib/util/flattenColorPalette.js +11 -12
  83. package/lib/util/formatVariantSelector.js +228 -151
  84. package/lib/util/getAllConfigs.js +33 -12
  85. package/lib/util/hashConfig.js +9 -4
  86. package/lib/util/isKeyframeRule.js +7 -2
  87. package/lib/util/isPlainObject.js +7 -2
  88. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
  89. package/lib/util/log.js +27 -13
  90. package/lib/util/nameClass.js +27 -10
  91. package/lib/util/negateValue.js +25 -8
  92. package/lib/util/normalizeConfig.js +139 -65
  93. package/lib/util/normalizeScreens.js +131 -11
  94. package/lib/util/parseAnimationValue.js +44 -40
  95. package/lib/util/parseBoxShadowValue.js +34 -23
  96. package/lib/util/parseDependency.js +39 -55
  97. package/lib/util/parseGlob.js +36 -0
  98. package/lib/util/parseObjectStyles.js +15 -10
  99. package/lib/util/pluginUtils.js +159 -69
  100. package/lib/util/prefixSelector.js +30 -12
  101. package/lib/util/pseudoElements.js +229 -0
  102. package/lib/util/removeAlphaVariables.js +31 -0
  103. package/lib/util/resolveConfig.js +97 -75
  104. package/lib/util/resolveConfigPath.js +30 -12
  105. package/lib/util/responsive.js +11 -6
  106. package/lib/util/splitAtTopLevelOnly.js +51 -0
  107. package/lib/util/tap.js +6 -1
  108. package/lib/util/toColorValue.js +7 -3
  109. package/lib/util/toPath.js +26 -3
  110. package/lib/util/transformThemeValue.js +40 -30
  111. package/lib/util/validateConfig.js +37 -0
  112. package/lib/util/validateFormalSyntax.js +26 -0
  113. package/lib/util/withAlphaVariable.js +27 -15
  114. package/loadConfig.d.ts +4 -0
  115. package/loadConfig.js +2 -0
  116. package/nesting/index.js +2 -12
  117. package/package.json +66 -57
  118. package/peers/index.js +75964 -55560
  119. package/plugin.d.ts +11 -0
  120. package/plugin.js +2 -1
  121. package/resolveConfig.d.ts +12 -0
  122. package/resolveConfig.js +2 -1
  123. package/scripts/generate-types.js +105 -0
  124. package/scripts/release-channel.js +18 -0
  125. package/scripts/release-notes.js +21 -0
  126. package/scripts/swap-engines.js +40 -0
  127. package/scripts/type-utils.js +27 -0
  128. package/src/cli/build/deps.js +56 -0
  129. package/src/cli/build/index.js +49 -0
  130. package/src/cli/build/plugin.js +444 -0
  131. package/src/cli/build/utils.js +76 -0
  132. package/src/cli/build/watching.js +229 -0
  133. package/src/cli/help/index.js +70 -0
  134. package/src/cli/index.js +216 -0
  135. package/src/cli/init/index.js +79 -0
  136. package/src/cli-peer-dependencies.js +7 -1
  137. package/src/cli.js +4 -765
  138. package/src/corePluginList.js +1 -1
  139. package/src/corePlugins.js +786 -306
  140. package/src/css/preflight.css +10 -8
  141. package/src/featureFlags.js +21 -5
  142. package/src/index.js +1 -34
  143. package/src/lib/cacheInvalidation.js +52 -0
  144. package/src/lib/collapseAdjacentRules.js +21 -2
  145. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  146. package/src/lib/content.js +208 -0
  147. package/src/lib/defaultExtractor.js +217 -0
  148. package/src/lib/detectNesting.js +9 -1
  149. package/src/lib/evaluateTailwindFunctions.js +79 -8
  150. package/src/lib/expandApplyAtRules.js +515 -153
  151. package/src/lib/expandTailwindAtRules.js +115 -86
  152. package/src/lib/findAtConfigPath.js +48 -0
  153. package/src/lib/generateRules.js +545 -147
  154. package/src/lib/getModuleDependencies.js +70 -30
  155. package/src/lib/load-config.ts +31 -0
  156. package/src/lib/normalizeTailwindDirectives.js +7 -1
  157. package/src/lib/offsets.js +373 -0
  158. package/src/lib/partitionApplyAtRules.js +52 -0
  159. package/src/lib/regex.js +74 -0
  160. package/src/lib/remap-bitfield.js +82 -0
  161. package/src/lib/resolveDefaultsAtRules.js +59 -17
  162. package/src/lib/setupContextUtils.js +701 -175
  163. package/src/lib/setupTrackingContext.js +51 -62
  164. package/src/lib/sharedState.js +58 -7
  165. package/src/oxide/cli/build/deps.ts +91 -0
  166. package/src/oxide/cli/build/index.ts +47 -0
  167. package/src/oxide/cli/build/plugin.ts +442 -0
  168. package/src/oxide/cli/build/utils.ts +74 -0
  169. package/src/oxide/cli/build/watching.ts +225 -0
  170. package/src/oxide/cli/help/index.ts +69 -0
  171. package/src/oxide/cli/index.ts +204 -0
  172. package/src/oxide/cli/init/index.ts +59 -0
  173. package/src/oxide/cli.ts +1 -0
  174. package/src/oxide/postcss-plugin.ts +1 -0
  175. package/src/plugin.js +107 -0
  176. package/src/postcss-plugins/nesting/README.md +42 -0
  177. package/src/postcss-plugins/nesting/index.js +13 -0
  178. package/src/postcss-plugins/nesting/plugin.js +80 -0
  179. package/src/processTailwindFeatures.js +12 -2
  180. package/src/public/colors.js +22 -0
  181. package/src/public/default-config.js +1 -1
  182. package/src/public/default-theme.js +2 -2
  183. package/src/public/load-config.js +2 -0
  184. package/src/util/applyImportantSelector.js +27 -0
  185. package/src/util/buildMediaQuery.js +5 -3
  186. package/src/util/cloneNodes.js +19 -2
  187. package/src/util/color.js +44 -12
  188. package/src/util/colorNames.js +150 -0
  189. package/src/util/dataTypes.js +51 -16
  190. package/src/util/defaults.js +6 -0
  191. package/src/util/formatVariantSelector.js +264 -144
  192. package/src/util/getAllConfigs.js +21 -2
  193. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  194. package/src/util/log.js +11 -7
  195. package/src/util/nameClass.js +4 -0
  196. package/src/util/negateValue.js +11 -3
  197. package/src/util/normalizeConfig.js +57 -5
  198. package/src/util/normalizeScreens.js +105 -7
  199. package/src/util/parseBoxShadowValue.js +4 -3
  200. package/src/util/parseDependency.js +37 -42
  201. package/src/util/parseGlob.js +24 -0
  202. package/src/util/pluginUtils.js +123 -24
  203. package/src/util/prefixSelector.js +30 -10
  204. package/src/util/pseudoElements.js +170 -0
  205. package/src/util/removeAlphaVariables.js +24 -0
  206. package/src/util/resolveConfig.js +74 -26
  207. package/src/util/resolveConfigPath.js +12 -1
  208. package/src/util/splitAtTopLevelOnly.js +52 -0
  209. package/src/util/toPath.js +23 -1
  210. package/src/util/transformThemeValue.js +13 -3
  211. package/src/util/validateConfig.js +26 -0
  212. package/src/util/validateFormalSyntax.js +34 -0
  213. package/src/util/withAlphaVariable.js +1 -1
  214. package/stubs/.gitignore +1 -0
  215. package/stubs/.prettierrc.json +6 -0
  216. package/stubs/{defaultConfig.stub.js → config.full.js} +206 -166
  217. package/stubs/postcss.config.js +6 -0
  218. package/stubs/tailwind.config.cjs +2 -0
  219. package/stubs/tailwind.config.js +2 -0
  220. package/stubs/tailwind.config.ts +3 -0
  221. package/types/config.d.ts +368 -0
  222. package/types/generated/.gitkeep +0 -0
  223. package/types/generated/colors.d.ts +298 -0
  224. package/types/generated/corePluginList.d.ts +1 -0
  225. package/types/generated/default-theme.d.ts +371 -0
  226. package/types/index.d.ts +7 -0
  227. package/CHANGELOG.md +0 -1843
  228. package/lib/constants.js +0 -37
  229. package/lib/lib/setupWatchingContext.js +0 -288
  230. package/nesting/plugin.js +0 -41
  231. package/scripts/install-integrations.js +0 -27
  232. package/scripts/rebuildFixtures.js +0 -68
  233. package/src/constants.js +0 -17
  234. package/src/lib/setupWatchingContext.js +0 -311
  235. /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
  236. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
@@ -1,16 +1,25 @@
1
1
  import { parseColor } from './color'
2
2
  import { parseBoxShadowValue } from './parseBoxShadowValue'
3
+ import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
3
4
 
4
5
  let cssFunctions = ['min', 'max', 'clamp', 'calc']
5
6
 
6
7
  // Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
7
8
 
8
- let COMMA = /,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
9
- let UNDERSCORE = /_(?![^(]*\))/g // Underscore separator that is not located between brackets. E.g.: `rgba(255,_255,_255)_black` these don't count.
9
+ function isCSSFunction(value) {
10
+ return cssFunctions.some((fn) => new RegExp(`^${fn}\\(.*\\)`).test(value))
11
+ }
12
+
13
+ const placeholder = '--tw-placeholder'
14
+ const placeholderRe = new RegExp(placeholder, 'g')
10
15
 
11
16
  // This is not a data type, but rather a function that can normalize the
12
17
  // correct values.
13
18
  export function normalize(value, isRoot = true) {
19
+ if (value.startsWith('--')) {
20
+ return `var(${value})`
21
+ }
22
+
14
23
  // Keep raw strings if it starts with `url(`
15
24
  if (value.includes('url(')) {
16
25
  return value
@@ -40,12 +49,20 @@ export function normalize(value, isRoot = true) {
40
49
  value = value.trim()
41
50
  }
42
51
 
43
- // Add spaces around operators inside calc() that do not follow an operator
52
+ // Add spaces around operators inside math functions like calc() that do not follow an operator
44
53
  // or '('.
45
- return value.replace(
46
- /(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
47
- '$1 $2 '
48
- )
54
+ value = value.replace(/(calc|min|max|clamp)\(.+\)/g, (match) => {
55
+ let vars = []
56
+ return match
57
+ .replace(/var\((--.+?)[,)]/g, (match, g1) => {
58
+ vars.push(g1)
59
+ return match.replace(g1, placeholder)
60
+ })
61
+ .replace(/(-?\d*\.?\d(?!\b-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ')
62
+ .replace(placeholderRe, () => vars.shift())
63
+ })
64
+
65
+ return value
49
66
  }
50
67
 
51
68
  export function url(value) {
@@ -53,13 +70,16 @@ export function url(value) {
53
70
  }
54
71
 
55
72
  export function number(value) {
56
- return !isNaN(Number(value)) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?`).test(value))
73
+ return !isNaN(Number(value)) || isCSSFunction(value)
57
74
  }
58
75
 
59
76
  export function percentage(value) {
60
- return /%$/g.test(value) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?%`).test(value))
77
+ return (value.endsWith('%') && number(value.slice(0, -1))) || isCSSFunction(value)
61
78
  }
62
79
 
80
+ // Please refer to MDN when updating this list:
81
+ // https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units
82
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries#container_query_length_units
63
83
  let lengthUnits = [
64
84
  'cm',
65
85
  'mm',
@@ -73,17 +93,32 @@ let lengthUnits = [
73
93
  'ch',
74
94
  'rem',
75
95
  'lh',
96
+ 'rlh',
76
97
  'vw',
77
98
  'vh',
78
99
  'vmin',
79
100
  'vmax',
101
+ 'vb',
102
+ 'vi',
103
+ 'svw',
104
+ 'svh',
105
+ 'lvw',
106
+ 'lvh',
107
+ 'dvw',
108
+ 'dvh',
109
+ 'cqw',
110
+ 'cqh',
111
+ 'cqi',
112
+ 'cqb',
113
+ 'cqmin',
114
+ 'cqmax',
80
115
  ]
81
116
  let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
82
117
  export function length(value) {
83
118
  return (
84
119
  value === '0' ||
85
- new RegExp(`${lengthUnitsPattern}$`).test(value) ||
86
- cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(value))
120
+ new RegExp(`^[+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`).test(value) ||
121
+ isCSSFunction(value)
87
122
  )
88
123
  }
89
124
 
@@ -107,11 +142,11 @@ export function shadow(value) {
107
142
  export function color(value) {
108
143
  let colors = 0
109
144
 
110
- let result = value.split(UNDERSCORE).every((part) => {
145
+ let result = splitAtTopLevelOnly(value, '_').every((part) => {
111
146
  part = normalize(part)
112
147
 
113
148
  if (part.startsWith('var(')) return true
114
- if (parseColor(part) !== null) return colors++, true
149
+ if (parseColor(part, { loose: true }) !== null) return colors++, true
115
150
 
116
151
  return false
117
152
  })
@@ -122,7 +157,7 @@ export function color(value) {
122
157
 
123
158
  export function image(value) {
124
159
  let images = 0
125
- let result = value.split(COMMA).every((part) => {
160
+ let result = splitAtTopLevelOnly(value, ',').every((part) => {
126
161
  part = normalize(part)
127
162
 
128
163
  if (part.startsWith('var(')) return true
@@ -163,7 +198,7 @@ export function gradient(value) {
163
198
  let validPositions = new Set(['center', 'top', 'right', 'bottom', 'left'])
164
199
  export function position(value) {
165
200
  let positions = 0
166
- let result = value.split(UNDERSCORE).every((part) => {
201
+ let result = splitAtTopLevelOnly(value, '_').every((part) => {
167
202
  part = normalize(part)
168
203
 
169
204
  if (part.startsWith('var(')) return true
@@ -181,7 +216,7 @@ export function position(value) {
181
216
 
182
217
  export function familyName(value) {
183
218
  let fonts = 0
184
- let result = value.split(COMMA).every((part) => {
219
+ let result = splitAtTopLevelOnly(value, ',').every((part) => {
185
220
  part = normalize(part)
186
221
 
187
222
  if (part.startsWith('var(')) return true
@@ -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
@@ -2,34 +2,155 @@ import selectorParser from 'postcss-selector-parser'
2
2
  import unescape from 'postcss-selector-parser/dist/util/unesc'
3
3
  import escapeClassName from '../util/escapeClassName'
4
4
  import prefixSelector from '../util/prefixSelector'
5
+ import { movePseudos } from './pseudoElements'
6
+
7
+ /** @typedef {import('postcss-selector-parser').Root} Root */
8
+ /** @typedef {import('postcss-selector-parser').Selector} Selector */
9
+ /** @typedef {import('postcss-selector-parser').Pseudo} Pseudo */
10
+ /** @typedef {import('postcss-selector-parser').Node} Node */
11
+
12
+ /** @typedef {{format: string, isArbitraryVariant: boolean}[]} RawFormats */
13
+ /** @typedef {import('postcss-selector-parser').Root} ParsedFormats */
14
+ /** @typedef {RawFormats | ParsedFormats} AcceptedFormats */
5
15
 
6
16
  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
- }
17
+
18
+ /**
19
+ * @param {RawFormats} formats
20
+ * @param {{context: any, candidate: string, base: string | null}} options
21
+ * @returns {ParsedFormats | null}
22
+ */
23
+ export function formatVariantSelector(formats, { context, candidate }) {
24
+ let prefix = context?.tailwindConfig.prefix ?? ''
25
+
26
+ // Parse the format selector into an AST
27
+ let parsedFormats = formats.map((format) => {
28
+ let ast = selectorParser().astSync(format.format)
29
+
30
+ return {
31
+ ...format,
32
+ ast: format.isArbitraryVariant ? ast : prefixSelector(prefix, ast),
33
+ }
34
+ })
35
+
36
+ // We start with the candidate selector
37
+ let formatAst = selectorParser.root({
38
+ nodes: [
39
+ selectorParser.selector({
40
+ nodes: [selectorParser.className({ value: escapeClassName(candidate) })],
41
+ }),
42
+ ],
43
+ })
44
+
45
+ // And iteratively merge each format selector into the candidate selector
46
+ for (let { ast } of parsedFormats) {
47
+ // 1. Handle :merge() special pseudo-class
48
+ ;[formatAst, ast] = handleMergePseudo(formatAst, ast)
49
+
50
+ // 2. Merge the format selector into the current selector AST
51
+ ast.walkNesting((nesting) => nesting.replaceWith(...formatAst.nodes[0].nodes))
52
+
53
+ // 3. Keep going!
54
+ formatAst = ast
55
+ }
56
+
57
+ return formatAst
58
+ }
59
+
60
+ /**
61
+ * Given any node in a selector this gets the "simple" selector it's a part of
62
+ * A simple selector is just a list of nodes without any combinators
63
+ * Technically :is(), :not(), :has(), etc… can have combinators but those are nested
64
+ * inside the relevant node and won't be picked up so they're fine to ignore
65
+ *
66
+ * @param {Node} node
67
+ * @returns {Node[]}
68
+ **/
69
+ function simpleSelectorForNode(node) {
70
+ /** @type {Node[]} */
71
+ let nodes = []
72
+
73
+ // Walk backwards until we hit a combinator node (or the start)
74
+ while (node.prev() && node.prev().type !== 'combinator') {
75
+ node = node.prev()
76
+ }
77
+
78
+ // Now record all non-combinator nodes until we hit one (or the end)
79
+ while (node && node.type !== 'combinator') {
80
+ nodes.push(node)
81
+ node = node.next()
82
+ }
83
+
84
+ return nodes
85
+ }
86
+
87
+ /**
88
+ * Resorts the nodes in a selector to ensure they're in the correct order
89
+ * Tags go before classes, and pseudo classes go after classes
90
+ *
91
+ * @param {Selector} sel
92
+ * @returns {Selector}
93
+ **/
94
+ function resortSelector(sel) {
95
+ sel.sort((a, b) => {
96
+ if (a.type === 'tag' && b.type === 'class') {
97
+ return -1
98
+ } else if (a.type === 'class' && b.type === 'tag') {
99
+ return 1
100
+ } else if (a.type === 'class' && b.type === 'pseudo' && b.value.startsWith('::')) {
101
+ return -1
102
+ } else if (a.type === 'pseudo' && a.value.startsWith('::') && b.type === 'class') {
103
+ return 1
24
104
  }
25
105
 
26
- current = other.replace(PARENT, current)
106
+ return sel.index(a) - sel.index(b)
107
+ })
108
+
109
+ return sel
110
+ }
111
+
112
+ /**
113
+ * Remove extraneous selectors that do not include the base class/candidate
114
+ *
115
+ * Example:
116
+ * Given the utility `.a, .b { color: red}`
117
+ * Given the candidate `sm:b`
118
+ *
119
+ * The final selector should be `.sm\:b` and not `.a, .sm\:b`
120
+ *
121
+ * @param {Selector} ast
122
+ * @param {string} base
123
+ */
124
+ export function eliminateIrrelevantSelectors(sel, base) {
125
+ let hasClassesMatchingCandidate = false
126
+
127
+ sel.walk((child) => {
128
+ if (child.type === 'class' && child.value === base) {
129
+ hasClassesMatchingCandidate = true
130
+ return false // Stop walking
131
+ }
132
+ })
133
+
134
+ if (!hasClassesMatchingCandidate) {
135
+ sel.remove()
27
136
  }
28
137
 
29
- return current
138
+ // We do NOT recursively eliminate sub selectors that don't have the base class
139
+ // as this is NOT a safe operation. For example, if we have:
140
+ // `.space-x-2 > :not([hidden]) ~ :not([hidden])`
141
+ // We cannot remove the [hidden] from the :not() because it would change the
142
+ // meaning of the selector.
143
+
144
+ // TODO: Can we do this for :matches, :is, and :where?
30
145
  }
31
146
 
32
- export function finalizeSelector(format, { selector, candidate, context }) {
147
+ /**
148
+ * @param {string} current
149
+ * @param {AcceptedFormats} formats
150
+ * @param {{context: any, candidate: string, base: string | null}} options
151
+ * @returns {string}
152
+ */
153
+ export function finalizeSelector(current, formats, { context, candidate, base }) {
33
154
  let separator = context?.tailwindConfig?.separator ?? ':'
34
155
 
35
156
  // Split by the separator, but ignore the separator inside square brackets:
@@ -39,14 +160,10 @@ export function finalizeSelector(format, { selector, candidate, context }) {
39
160
  // │ │ │ ╰── We will not split here
40
161
  // ╰──┴─────┴─────────────── We will split here
41
162
  //
42
- let splitter = new RegExp(`\\${separator}(?![^[]*\\])`)
43
- let base = candidate.split(splitter).pop()
44
-
45
- if (context?.tailwindConfig?.prefix) {
46
- format = prefixSelector(context.tailwindConfig.prefix, format)
47
- }
163
+ base = base ?? candidate.split(new RegExp(`\\${separator}(?![^[]*\\])`)).pop()
48
164
 
49
- format = format.replace(PARENT, `.${escapeClassName(candidate)}`)
165
+ // Parse the selector into an AST
166
+ let selector = selectorParser().astSync(current)
50
167
 
51
168
  // Normalize escaped classes, e.g.:
52
169
  //
@@ -59,138 +176,141 @@ export function finalizeSelector(format, { selector, candidate, context }) {
59
176
  // base in selector: bg-\\[rgb\\(255\\,0\\,0\\)\\]
60
177
  // escaped base: bg-\\[rgb\\(255\\2c 0\\2c 0\\)\\]
61
178
  //
62
- selector = selectorParser((selectors) => {
63
- return selectors.walkClasses((node) => {
64
- if (node.raws && node.value.includes(base)) {
65
- node.raws.value = escapeClassName(unescape(node.raws.value))
66
- }
179
+ selector.walkClasses((node) => {
180
+ if (node.raws && node.value.includes(base)) {
181
+ node.raws.value = escapeClassName(unescape(node.raws.value))
182
+ }
183
+ })
67
184
 
68
- return node
69
- })
70
- }).processSync(selector)
185
+ // Remove extraneous selectors that do not include the base candidate
186
+ selector.each((sel) => eliminateIrrelevantSelectors(sel, base))
187
+
188
+ // If there are no formats that means there were no variants added to the candidate
189
+ // so we can just return the selector as-is
190
+ let formatAst = Array.isArray(formats)
191
+ ? formatVariantSelector(formats, { context, candidate })
192
+ : formats
193
+
194
+ if (formatAst === null) {
195
+ return selector.toString()
196
+ }
197
+
198
+ let simpleStart = selectorParser.comment({ value: '/*__simple__*/' })
199
+ let simpleEnd = selectorParser.comment({ value: '/*__simple__*/' })
71
200
 
72
201
  // We can safely replace the escaped base now, since the `base` section is
73
202
  // now in a normalized escaped value.
74
- selector = selector.replace(`.${escapeClassName(base)}`, format)
203
+ selector.walkClasses((node) => {
204
+ if (node.value !== base) {
205
+ return
206
+ }
207
+
208
+ let parent = node.parent
209
+ let formatNodes = formatAst.nodes[0].nodes
210
+
211
+ // Perf optimization: if the parent is a single class we can just replace it and be done
212
+ if (parent.nodes.length === 1) {
213
+ node.replaceWith(...formatNodes)
214
+ return
215
+ }
216
+
217
+ let simpleSelector = simpleSelectorForNode(node)
218
+ parent.insertBefore(simpleSelector[0], simpleStart)
219
+ parent.insertAfter(simpleSelector[simpleSelector.length - 1], simpleEnd)
220
+
221
+ for (let child of formatNodes) {
222
+ parent.insertBefore(simpleSelector[0], child.clone())
223
+ }
224
+
225
+ node.remove()
226
+
227
+ // Re-sort the simple selector to ensure it's in the correct order
228
+ simpleSelector = simpleSelectorForNode(simpleStart)
229
+ let firstNode = parent.index(simpleStart)
230
+
231
+ parent.nodes.splice(
232
+ firstNode,
233
+ simpleSelector.length,
234
+ ...resortSelector(selectorParser.selector({ nodes: simpleSelector })).nodes
235
+ )
236
+
237
+ simpleStart.remove()
238
+ simpleEnd.remove()
239
+ })
75
240
 
76
241
  // Remove unnecessary pseudo selectors that we used as placeholders
77
- return selectorParser((selectors) => {
78
- return selectors.map((selector) => {
79
- selector.walkPseudos((p) => {
80
- if (selectorFunctions.has(p.value)) {
81
- p.replaceWith(p.nodes)
82
- }
83
-
84
- return p
85
- })
242
+ selector.walkPseudos((p) => {
243
+ if (p.value === MERGE) {
244
+ p.replaceWith(p.nodes)
245
+ }
246
+ })
247
+
248
+ // Move pseudo elements to the end of the selector (if necessary)
249
+ selector.each((sel) => movePseudos(sel))
86
250
 
87
- // This will make sure to move pseudo's to the correct spot (the end for
88
- // pseudo elements) because otherwise the selector will never work
89
- // anyway.
90
- //
91
- // E.g.:
92
- // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
93
- // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
94
- //
95
- // `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
96
- function collectPseudoElements(selector) {
97
- let nodes = []
98
-
99
- for (let node of selector.nodes) {
100
- if (isPseudoElement(node)) {
101
- nodes.push(node)
102
- selector.removeChild(node)
103
- }
104
-
105
- if (node?.nodes) {
106
- nodes.push(...collectPseudoElements(node))
107
- }
108
- }
109
-
110
- return nodes
111
- }
112
-
113
- let pseudoElements = collectPseudoElements(selector)
114
- if (pseudoElements.length > 0) {
115
- selector.nodes.push(pseudoElements.sort(sortSelector))
116
- }
117
-
118
- return selector
119
- })
120
- }).processSync(selector)
251
+ return selector.toString()
121
252
  }
122
253
 
123
- // Note: As a rule, double colons (::) should be used instead of a single colon
124
- // (:). This distinguishes pseudo-classes from pseudo-elements. However, since
125
- // this distinction was not present in older versions of the W3C spec, most
126
- // browsers support both syntaxes for the original pseudo-elements.
127
- let pseudoElementsBC = [':before', ':after', ':first-line', ':first-letter']
128
-
129
- // These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
130
- let pseudoElementExceptions = ['::file-selector-button']
131
-
132
- // This will make sure to move pseudo's to the correct spot (the end for
133
- // pseudo elements) because otherwise the selector will never work
134
- // anyway.
135
- //
136
- // E.g.:
137
- // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
138
- // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
139
- //
140
- // `::before:hover` doesn't work, which means that we can make it work
141
- // for you by flipping the order.
142
- function sortSelector(a, z) {
143
- // Both nodes are non-pseudo's so we can safely ignore them and keep
144
- // them in the same order.
145
- if (a.type !== 'pseudo' && z.type !== 'pseudo') {
146
- return 0
147
- }
254
+ /**
255
+ *
256
+ * @param {Selector} selector
257
+ * @param {Selector} format
258
+ */
259
+ export function handleMergePseudo(selector, format) {
260
+ /** @type {{pseudo: Pseudo, value: string}[]} */
261
+ let merges = []
262
+
263
+ // Find all :merge() pseudo-classes in `selector`
264
+ selector.walkPseudos((pseudo) => {
265
+ if (pseudo.value === MERGE) {
266
+ merges.push({
267
+ pseudo,
268
+ value: pseudo.nodes[0].toString(),
269
+ })
270
+ }
271
+ })
148
272
 
149
- // If one of them is a combinator, we need to keep it in the same order
150
- // because that means it will start a new "section" in the selector.
151
- if ((a.type === 'combinator') ^ (z.type === 'combinator')) {
152
- return 0
153
- }
273
+ // Find all :merge() "attachments" in `format` and attach them to the matching selector in `selector`
274
+ format.walkPseudos((pseudo) => {
275
+ if (pseudo.value !== MERGE) {
276
+ return
277
+ }
154
278
 
155
- // One of the items is a pseudo and the other one isn't. Let's move
156
- // the pseudo to the right.
157
- if ((a.type === 'pseudo') ^ (z.type === 'pseudo')) {
158
- return (a.type === 'pseudo') - (z.type === 'pseudo')
159
- }
279
+ let value = pseudo.nodes[0].toString()
160
280
 
161
- // Both are pseudo's, move the pseudo elements (except for
162
- // ::file-selector-button) to the right.
163
- return isPseudoElement(a) - isPseudoElement(z)
164
- }
281
+ // Does `selector` contain a :merge() pseudo-class with the same value?
282
+ let existing = merges.find((merge) => merge.value === value)
165
283
 
166
- function isPseudoElement(node) {
167
- if (node.type !== 'pseudo') return false
168
- if (pseudoElementExceptions.includes(node.value)) return false
284
+ // Nope so there's nothing to do
285
+ if (!existing) {
286
+ return
287
+ }
169
288
 
170
- return node.value.startsWith('::') || pseudoElementsBC.includes(node.value)
171
- }
289
+ // Everything after `:merge()` up to the next combinator is what is attached to the merged selector
290
+ let attachments = []
291
+ let next = pseudo.next()
292
+ while (next && next.type !== 'combinator') {
293
+ attachments.push(next)
294
+ next = next.next()
295
+ }
296
+
297
+ let combinator = next
172
298
 
173
- function resolveFunctionArgument(haystack, needle, arg) {
174
- let startIdx = haystack.indexOf(arg ? `${needle}(${arg})` : needle)
175
- if (startIdx === -1) return null
176
-
177
- // Start inside the `(`
178
- startIdx += needle.length + 1
179
-
180
- let target = ''
181
- let count = 0
182
-
183
- for (let char of haystack.slice(startIdx)) {
184
- if (char !== '(' && char !== ')') {
185
- target += char
186
- } else if (char === '(') {
187
- target += char
188
- count++
189
- } else if (char === ')') {
190
- if (--count < 0) break // unbalanced
191
- target += char
299
+ existing.pseudo.parent.insertAfter(
300
+ existing.pseudo,
301
+ selectorParser.selector({ nodes: attachments.map((node) => node.clone()) })
302
+ )
303
+
304
+ pseudo.remove()
305
+ attachments.forEach((node) => node.remove())
306
+
307
+ // What about this case:
308
+ // :merge(.group):focus > &
309
+ // :merge(.group):hover &
310
+ if (combinator && combinator.type === 'combinator') {
311
+ combinator.remove()
192
312
  }
193
- }
313
+ })
194
314
 
195
- return target
315
+ return [selector, format]
196
316
  }
@@ -1,14 +1,33 @@
1
- import defaultConfig from '../../stubs/defaultConfig.stub.js'
1
+ import defaultFullConfig from '../../stubs/config.full.js'
2
2
  import { flagEnabled } from '../featureFlags'
3
3
 
4
4
  export default function getAllConfigs(config) {
5
- const configs = (config?.presets ?? [defaultConfig])
5
+ const configs = (config?.presets ?? [defaultFullConfig])
6
6
  .slice()
7
7
  .reverse()
8
8
  .flatMap((preset) => getAllConfigs(preset instanceof Function ? preset() : preset))
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)
@@ -15,7 +15,7 @@ let quotes = new Set(['"', "'", '`'])
15
15
  // E.g.: w-[this-is]w-[weird-and-invalid]
16
16
  // E.g.: w-[this-is\\]w-\\[weird-but-valid]
17
17
  // E.g.: content-['this-is-also-valid]-weirdly-enough']
18
- export default function isValidArbitraryValue(value) {
18
+ export default function isSyntacticallyValidPropertyValue(value) {
19
19
  let stack = []
20
20
  let inQuotes = false
21
21