tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21

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 (161) hide show
  1. package/CHANGELOG.md +246 -6
  2. package/README.md +13 -9
  3. package/defaultTheme.d.ts +2 -1
  4. package/lib/cli/build/deps.js +54 -0
  5. package/lib/cli/build/index.js +48 -0
  6. package/lib/cli/build/plugin.js +362 -0
  7. package/lib/cli/build/utils.js +78 -0
  8. package/lib/cli/build/watching.js +178 -0
  9. package/lib/cli/help/index.js +71 -0
  10. package/lib/cli/index.js +18 -0
  11. package/lib/cli/init/index.js +46 -0
  12. package/lib/cli/shared.js +12 -0
  13. package/lib/cli-peer-dependencies.js +18 -5
  14. package/lib/cli.js +62 -592
  15. package/lib/constants.js +19 -12
  16. package/lib/corePluginList.js +5 -3
  17. package/lib/corePlugins.js +619 -347
  18. package/lib/css/preflight.css +7 -0
  19. package/lib/featureFlags.js +34 -22
  20. package/lib/index.js +16 -9
  21. package/lib/lib/cacheInvalidation.js +42 -21
  22. package/lib/lib/collapseAdjacentRules.js +16 -14
  23. package/lib/lib/collapseDuplicateDeclarations.js +13 -10
  24. package/lib/lib/content.js +177 -0
  25. package/lib/lib/defaultExtractor.js +230 -33
  26. package/lib/lib/detectNesting.js +13 -4
  27. package/lib/lib/evaluateTailwindFunctions.js +105 -42
  28. package/lib/lib/expandApplyAtRules.js +151 -92
  29. package/lib/lib/expandTailwindAtRules.js +134 -149
  30. package/lib/lib/findAtConfigPath.js +44 -0
  31. package/lib/lib/generateRules.js +404 -185
  32. package/lib/lib/getModuleDependencies.js +21 -18
  33. package/lib/lib/normalizeTailwindDirectives.js +11 -8
  34. package/lib/lib/offsets.js +285 -0
  35. package/lib/lib/partitionApplyAtRules.js +14 -11
  36. package/lib/lib/regex.js +60 -0
  37. package/lib/lib/remap-bitfield.js +87 -0
  38. package/lib/lib/resolveDefaultsAtRules.js +97 -79
  39. package/lib/lib/setupContextUtils.js +567 -242
  40. package/lib/lib/setupTrackingContext.js +77 -106
  41. package/lib/lib/sharedState.js +18 -10
  42. package/lib/lib/substituteScreenAtRules.js +9 -7
  43. package/lib/postcss-plugins/nesting/index.js +7 -5
  44. package/lib/postcss-plugins/nesting/plugin.js +10 -8
  45. package/lib/processTailwindFeatures.js +34 -31
  46. package/lib/public/colors.js +7 -5
  47. package/lib/public/create-plugin.js +6 -4
  48. package/lib/public/default-config.js +7 -5
  49. package/lib/public/default-theme.js +7 -5
  50. package/lib/public/resolve-config.js +13 -10
  51. package/lib/util/bigSign.js +4 -1
  52. package/lib/util/buildMediaQuery.js +10 -5
  53. package/lib/util/cloneDeep.js +6 -5
  54. package/lib/util/cloneNodes.js +9 -2
  55. package/lib/util/color.js +20 -17
  56. package/lib/util/configurePlugins.js +5 -2
  57. package/lib/util/createPlugin.js +6 -5
  58. package/lib/util/createUtilityPlugin.js +15 -13
  59. package/lib/util/dataTypes.js +75 -51
  60. package/lib/util/defaults.js +8 -5
  61. package/lib/util/escapeClassName.js +13 -10
  62. package/lib/util/escapeCommas.js +4 -1
  63. package/lib/util/flattenColorPalette.js +7 -8
  64. package/lib/util/formatVariantSelector.js +270 -103
  65. package/lib/util/getAllConfigs.js +34 -15
  66. package/lib/util/hashConfig.js +10 -7
  67. package/lib/util/isKeyframeRule.js +4 -1
  68. package/lib/util/isPlainObject.js +4 -1
  69. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +34 -26
  70. package/lib/util/log.js +14 -8
  71. package/lib/util/nameClass.js +19 -8
  72. package/lib/util/negateValue.js +20 -5
  73. package/lib/util/normalizeConfig.js +94 -53
  74. package/lib/util/normalizeScreens.js +115 -4
  75. package/lib/util/parseAnimationValue.js +43 -41
  76. package/lib/util/parseBoxShadowValue.js +12 -45
  77. package/lib/util/parseDependency.js +37 -55
  78. package/lib/util/parseGlob.js +34 -0
  79. package/lib/util/parseObjectStyles.js +15 -12
  80. package/lib/util/pluginUtils.js +146 -42
  81. package/lib/util/prefixSelector.js +26 -9
  82. package/lib/util/removeAlphaVariables.js +29 -0
  83. package/lib/util/resolveConfig.js +104 -105
  84. package/lib/util/resolveConfigPath.js +20 -17
  85. package/lib/util/responsive.js +12 -9
  86. package/lib/util/splitAtTopLevelOnly.js +43 -0
  87. package/lib/util/tap.js +4 -1
  88. package/lib/util/toColorValue.js +4 -1
  89. package/lib/util/toPath.js +18 -2
  90. package/lib/util/transformThemeValue.js +23 -11
  91. package/lib/util/validateConfig.js +24 -0
  92. package/lib/util/validateFormalSyntax.js +24 -0
  93. package/lib/util/withAlphaVariable.js +32 -24
  94. package/package.json +32 -29
  95. package/peers/index.js +6693 -3036
  96. package/plugin.d.ts +10 -5
  97. package/resolveConfig.d.ts +12 -0
  98. package/scripts/generate-types.js +53 -0
  99. package/scripts/release-channel.js +18 -0
  100. package/scripts/release-notes.js +21 -0
  101. package/scripts/type-utils.js +27 -0
  102. package/src/cli/build/deps.js +56 -0
  103. package/src/cli/build/index.js +49 -0
  104. package/src/cli/build/plugin.js +434 -0
  105. package/src/cli/build/utils.js +76 -0
  106. package/src/cli/build/watching.js +227 -0
  107. package/src/cli/help/index.js +70 -0
  108. package/src/cli/index.js +3 -0
  109. package/src/cli/init/index.js +50 -0
  110. package/src/cli/shared.js +5 -0
  111. package/src/cli-peer-dependencies.js +7 -1
  112. package/src/cli.js +46 -659
  113. package/src/corePlugins.js +346 -79
  114. package/src/css/preflight.css +7 -0
  115. package/src/featureFlags.js +12 -2
  116. package/src/index.js +5 -0
  117. package/src/lib/content.js +213 -0
  118. package/src/lib/defaultExtractor.js +202 -35
  119. package/src/lib/detectNesting.js +9 -1
  120. package/src/lib/evaluateTailwindFunctions.js +78 -7
  121. package/src/lib/expandApplyAtRules.js +129 -34
  122. package/src/lib/expandTailwindAtRules.js +12 -50
  123. package/src/lib/findAtConfigPath.js +48 -0
  124. package/src/lib/generateRules.js +379 -126
  125. package/src/lib/offsets.js +351 -0
  126. package/src/lib/regex.js +74 -0
  127. package/src/lib/remap-bitfield.js +82 -0
  128. package/src/lib/resolveDefaultsAtRules.js +53 -36
  129. package/src/lib/setupContextUtils.js +510 -120
  130. package/src/lib/setupTrackingContext.js +8 -45
  131. package/src/lib/sharedState.js +2 -0
  132. package/src/util/buildMediaQuery.js +5 -3
  133. package/src/util/cloneNodes.js +5 -1
  134. package/src/util/dataTypes.js +51 -26
  135. package/src/util/formatVariantSelector.js +317 -101
  136. package/src/util/getAllConfigs.js +19 -0
  137. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  138. package/src/util/log.js +1 -1
  139. package/src/util/nameClass.js +4 -0
  140. package/src/util/negateValue.js +10 -2
  141. package/src/util/normalizeConfig.js +40 -10
  142. package/src/util/normalizeScreens.js +99 -4
  143. package/src/util/parseBoxShadowValue.js +3 -50
  144. package/src/util/parseDependency.js +37 -42
  145. package/src/util/parseGlob.js +24 -0
  146. package/src/util/pluginUtils.js +132 -10
  147. package/src/util/prefixSelector.js +28 -10
  148. package/src/util/removeAlphaVariables.js +24 -0
  149. package/src/util/resolveConfig.js +70 -62
  150. package/src/util/splitAtTopLevelOnly.js +45 -0
  151. package/src/util/toPath.js +1 -1
  152. package/src/util/transformThemeValue.js +13 -3
  153. package/src/util/validateConfig.js +13 -0
  154. package/src/util/validateFormalSyntax.js +34 -0
  155. package/src/util/withAlphaVariable.js +1 -1
  156. package/stubs/defaultConfig.stub.js +165 -164
  157. package/stubs/simpleConfig.stub.js +1 -0
  158. package/types/config.d.ts +77 -37
  159. package/types/generated/default-theme.d.ts +342 -0
  160. package/types/index.d.ts +7 -1
  161. package/types.d.ts +0 -1
@@ -1,3 +1,17 @@
1
+ /**
2
+ * @typedef {object} ScreenValue
3
+ * @property {number|undefined} min
4
+ * @property {number|undefined} max
5
+ * @property {string|undefined} raw
6
+ */
7
+
8
+ /**
9
+ * @typedef {object} Screen
10
+ * @property {string} name
11
+ * @property {boolean} not
12
+ * @property {ScreenValue[]} values
13
+ */
14
+
1
15
  /**
2
16
  * A function that normalizes the various forms that the screens object can be
3
17
  * provided in.
@@ -10,6 +24,8 @@
10
24
  *
11
25
  * Output(s):
12
26
  * - [{ name: 'sm', values: [{ min: '100px', max: '200px' }] }] // List of objects, that contains multiple values
27
+ *
28
+ * @returns {Screen[]}
13
29
  */
14
30
  export function normalizeScreens(screens, root = true) {
15
31
  if (Array.isArray(screens)) {
@@ -19,27 +35,106 @@ export function normalizeScreens(screens, root = true) {
19
35
  }
20
36
 
21
37
  if (typeof screen === 'string') {
22
- return { name: screen.toString(), values: [{ min: screen, max: undefined }] }
38
+ return { name: screen.toString(), not: false, values: [{ min: screen, max: undefined }] }
23
39
  }
24
40
 
25
41
  let [name, options] = screen
26
42
  name = name.toString()
27
43
 
28
44
  if (typeof options === 'string') {
29
- return { name, values: [{ min: options, max: undefined }] }
45
+ return { name, not: false, values: [{ min: options, max: undefined }] }
30
46
  }
31
47
 
32
48
  if (Array.isArray(options)) {
33
- return { name, values: options.map((option) => resolveValue(option)) }
49
+ return { name, not: false, values: options.map((option) => resolveValue(option)) }
34
50
  }
35
51
 
36
- return { name, values: [resolveValue(options)] }
52
+ return { name, not: false, values: [resolveValue(options)] }
37
53
  })
38
54
  }
39
55
 
40
56
  return normalizeScreens(Object.entries(screens ?? {}), false)
41
57
  }
42
58
 
59
+ /**
60
+ * @param {Screen} screen
61
+ * @returns {{result: false, reason: string} | {result: true, reason: null}}
62
+ */
63
+ export function isScreenSortable(screen) {
64
+ if (screen.values.length !== 1) {
65
+ return { result: false, reason: 'multiple-values' }
66
+ } else if (screen.values[0].raw !== undefined) {
67
+ return { result: false, reason: 'raw-values' }
68
+ } else if (screen.values[0].min !== undefined && screen.values[0].max !== undefined) {
69
+ return { result: false, reason: 'min-and-max' }
70
+ }
71
+
72
+ return { result: true, reason: null }
73
+ }
74
+
75
+ /**
76
+ * @param {'min' | 'max'} type
77
+ * @param {Screen | 'string'} a
78
+ * @param {Screen | 'string'} z
79
+ * @returns {number}
80
+ */
81
+ export function compareScreens(type, a, z) {
82
+ let aScreen = toScreen(a, type)
83
+ let zScreen = toScreen(z, type)
84
+
85
+ let aSorting = isScreenSortable(aScreen)
86
+ let bSorting = isScreenSortable(zScreen)
87
+
88
+ // These cases should never happen and indicate a bug in Tailwind CSS itself
89
+ if (aSorting.reason === 'multiple-values' || bSorting.reason === 'multiple-values') {
90
+ throw new Error(
91
+ 'Attempted to sort a screen with multiple values. This should never happen. Please open a bug report.'
92
+ )
93
+ } else if (aSorting.reason === 'raw-values' || bSorting.reason === 'raw-values') {
94
+ throw new Error(
95
+ 'Attempted to sort a screen with raw values. This should never happen. Please open a bug report.'
96
+ )
97
+ } else if (aSorting.reason === 'min-and-max' || bSorting.reason === 'min-and-max') {
98
+ throw new Error(
99
+ 'Attempted to sort a screen with both min and max values. This should never happen. Please open a bug report.'
100
+ )
101
+ }
102
+
103
+ // Let the sorting begin
104
+ let { min: aMin, max: aMax } = aScreen.values[0]
105
+ let { min: zMin, max: zMax } = zScreen.values[0]
106
+
107
+ // Negating screens flip their behavior. Basically `not min-width` is `max-width`
108
+ if (a.not) [aMin, aMax] = [aMax, aMin]
109
+ if (z.not) [zMin, zMax] = [zMax, zMin]
110
+
111
+ aMin = aMin === undefined ? aMin : parseFloat(aMin)
112
+ aMax = aMax === undefined ? aMax : parseFloat(aMax)
113
+ zMin = zMin === undefined ? zMin : parseFloat(zMin)
114
+ zMax = zMax === undefined ? zMax : parseFloat(zMax)
115
+
116
+ let [aValue, zValue] = type === 'min' ? [aMin, zMin] : [zMax, aMax]
117
+
118
+ return aValue - zValue
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @param {PartialScreen> | string} value
124
+ * @param {'min' | 'max'} type
125
+ * @returns {Screen}
126
+ */
127
+ export function toScreen(value, type) {
128
+ if (typeof value === 'object') {
129
+ return value
130
+ }
131
+
132
+ return {
133
+ name: 'arbitrary-screen',
134
+ values: [{ [type]: value }],
135
+ }
136
+ }
137
+
43
138
  function resolveValue({ 'min-width': _minWidth, min = _minWidth, max, raw } = {}) {
44
139
  return { min, max, raw }
45
140
  }
@@ -1,58 +1,11 @@
1
+ import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
2
+
1
3
  let KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
2
4
  let SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
3
5
  let LENGTH = /^-?(\d+|\.\d+)(.*?)$/g
4
6
 
5
- let SPECIALS = /[(),]/g
6
-
7
- /**
8
- * This splits a string on top-level commas.
9
- *
10
- * Regex doesn't support recursion (at least not the JS-flavored version).
11
- * So we have to use a tiny state machine to keep track of paren vs comma
12
- * placement. Before we'd only exclude commas from the inner-most nested
13
- * set of parens rather than any commas that were not contained in parens
14
- * at all which is the intended behavior here.
15
- *
16
- * Expected behavior:
17
- * var(--a, 0 0 1px rgb(0, 0, 0)), 0 0 1px rgb(0, 0, 0)
18
- * ─┬─ ┬ ┬ ┬
19
- * x x x ╰──────── Split because top-level
20
- * ╰──────────────┴──┴───────────── Ignored b/c inside >= 1 levels of parens
21
- *
22
- * @param {string} input
23
- */
24
- function* splitByTopLevelCommas(input) {
25
- SPECIALS.lastIndex = -1
26
-
27
- let depth = 0
28
- let lastIndex = 0
29
- let found = false
30
-
31
- // Find all parens & commas
32
- // And only split on commas if they're top-level
33
- for (let match of input.matchAll(SPECIALS)) {
34
- if (match[0] === '(') depth++
35
- if (match[0] === ')') depth--
36
- if (match[0] === ',' && depth === 0) {
37
- found = true
38
-
39
- yield input.substring(lastIndex, match.index)
40
- lastIndex = match.index + match[0].length
41
- }
42
- }
43
-
44
- // Provide the last segment of the string if available
45
- // Otherwise the whole string since no commas were found
46
- // This mirrors the behavior of string.split()
47
- if (found) {
48
- yield input.substring(lastIndex)
49
- } else {
50
- yield input
51
- }
52
- }
53
-
54
7
  export function parseBoxShadowValue(input) {
55
- let shadows = Array.from(splitByTopLevelCommas(input))
8
+ let shadows = splitAtTopLevelOnly(input, ',')
56
9
  return shadows.map((shadow) => {
57
10
  let value = shadow.trim()
58
11
  let result = { raw: value }
@@ -1,49 +1,44 @@
1
- import isGlob from 'is-glob'
2
- import globParent from 'glob-parent'
3
- import path from 'path'
4
-
5
- // Based on `glob-base`
6
- // https://github.com/micromatch/glob-base/blob/master/index.js
7
- function parseGlob(pattern) {
8
- let glob = pattern
9
- let base = globParent(pattern)
10
-
11
- if (base !== '.') {
12
- glob = pattern.substr(base.length)
13
- if (glob.charAt(0) === '/') {
14
- glob = glob.substr(1)
15
- }
16
- }
17
-
18
- if (glob.substr(0, 2) === './') {
19
- glob = glob.substr(2)
20
- }
21
- if (glob.charAt(0) === '/') {
22
- glob = glob.substr(1)
1
+ // @ts-check
2
+
3
+ /**
4
+ * @typedef {{type: 'dependency', file: string} | {type: 'dir-dependency', dir: string, glob: string}} Dependency
5
+ */
6
+
7
+ /**
8
+ *
9
+ * @param {import('../lib/content.js').ContentPath} contentPath
10
+ * @returns {Dependency[]}
11
+ */
12
+ export default function parseDependency(contentPath) {
13
+ if (contentPath.ignore) {
14
+ return []
23
15
  }
24
16
 
25
- return { base, glob }
26
- }
27
-
28
- export default function parseDependency(normalizedFileOrGlob) {
29
- if (normalizedFileOrGlob.startsWith('!')) {
30
- return null
31
- }
32
-
33
- let message
34
-
35
- if (isGlob(normalizedFileOrGlob)) {
36
- let { base, glob } = parseGlob(normalizedFileOrGlob)
37
- message = { type: 'dir-dependency', dir: path.resolve(base), glob }
38
- } else {
39
- message = { type: 'dependency', file: path.resolve(normalizedFileOrGlob) }
17
+ if (!contentPath.glob) {
18
+ return [
19
+ {
20
+ type: 'dependency',
21
+ file: contentPath.base,
22
+ },
23
+ ]
40
24
  }
41
25
 
42
- // rollup-plugin-postcss does not support dir-dependency messages
43
- // but directories can be watched in the same way as files
44
- if (message.type === 'dir-dependency' && process.env.ROLLUP_WATCH === 'true') {
45
- message = { type: 'dependency', file: message.dir }
26
+ if (process.env.ROLLUP_WATCH === 'true') {
27
+ // rollup-plugin-postcss does not support dir-dependency messages
28
+ // but directories can be watched in the same way as files
29
+ return [
30
+ {
31
+ type: 'dependency',
32
+ file: contentPath.base,
33
+ },
34
+ ]
46
35
  }
47
36
 
48
- return message
37
+ return [
38
+ {
39
+ type: 'dir-dependency',
40
+ dir: contentPath.base,
41
+ glob: contentPath.glob,
42
+ },
43
+ ]
49
44
  }
@@ -0,0 +1,24 @@
1
+ import globParent from 'glob-parent'
2
+
3
+ // Based on `glob-base`
4
+ // https://github.com/micromatch/glob-base/blob/master/index.js
5
+ export function parseGlob(pattern) {
6
+ let glob = pattern
7
+ let base = globParent(pattern)
8
+
9
+ if (base !== '.') {
10
+ glob = pattern.substr(base.length)
11
+ if (glob.charAt(0) === '/') {
12
+ glob = glob.substr(1)
13
+ }
14
+ }
15
+
16
+ if (glob.substr(0, 2) === './') {
17
+ glob = glob.substr(2)
18
+ }
19
+ if (glob.charAt(0) === '/') {
20
+ glob = glob.substr(1)
21
+ }
22
+
23
+ return { base, glob }
24
+ }
@@ -18,6 +18,8 @@ import {
18
18
  shadow,
19
19
  } from './dataTypes'
20
20
  import negateValue from './negateValue'
21
+ import { backgroundSize } from './validateFormalSyntax'
22
+ import { flagEnabled } from '../featureFlags.js'
21
23
 
22
24
  export function updateAllClasses(selectors, updateClass) {
23
25
  let parser = selectorParser((selectors) => {
@@ -35,6 +37,23 @@ export function updateAllClasses(selectors, updateClass) {
35
37
  return result
36
38
  }
37
39
 
40
+ export function filterSelectorsForClass(selectors, classCandidate) {
41
+ let parser = selectorParser((selectors) => {
42
+ selectors.each((sel) => {
43
+ const containsClass = sel.nodes.some(
44
+ (node) => node.type === 'class' && node.value === classCandidate
45
+ )
46
+ if (!containsClass) {
47
+ sel.remove()
48
+ }
49
+ })
50
+ })
51
+
52
+ let result = parser.processSync(selectors)
53
+
54
+ return result
55
+ }
56
+
38
57
  function resolveArbitraryValue(modifier, validate) {
39
58
  if (!isArbitraryValue(modifier)) {
40
59
  return undefined
@@ -85,22 +104,51 @@ function isArbitraryValue(input) {
85
104
  return input.startsWith('[') && input.endsWith(']')
86
105
  }
87
106
 
88
- function splitAlpha(modifier) {
107
+ function splitUtilityModifier(modifier) {
89
108
  let slashIdx = modifier.lastIndexOf('/')
90
109
 
91
110
  if (slashIdx === -1 || slashIdx === modifier.length - 1) {
92
- return [modifier]
111
+ return [modifier, undefined]
112
+ }
113
+
114
+ let arbitrary = isArbitraryValue(modifier)
115
+
116
+ // The modifier could be of the form `[foo]/[bar]`
117
+ // We want to handle this case properly
118
+ // without affecting `[foo/bar]`
119
+ if (arbitrary && !modifier.includes(']/[')) {
120
+ return [modifier, undefined]
93
121
  }
94
122
 
95
123
  return [modifier.slice(0, slashIdx), modifier.slice(slashIdx + 1)]
96
124
  }
97
125
 
126
+ export function parseColorFormat(value) {
127
+ if (typeof value === 'string' && value.includes('<alpha-value>')) {
128
+ let oldValue = value
129
+
130
+ return ({ opacityValue = 1 }) => oldValue.replace('<alpha-value>', opacityValue)
131
+ }
132
+
133
+ return value
134
+ }
135
+
136
+ function unwrapArbitraryModifier(modifier) {
137
+ modifier = modifier.slice(1, -1)
138
+ if (modifier.startsWith('--')) {
139
+ modifier = `var(${modifier})`
140
+ }
141
+ return modifier
142
+ }
143
+
98
144
  export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
99
145
  if (options.values?.[modifier] !== undefined) {
100
- return options.values?.[modifier]
146
+ return parseColorFormat(options.values?.[modifier])
101
147
  }
102
148
 
103
- let [color, alpha] = splitAlpha(modifier)
149
+ // TODO: Hoist this up to getMatchingTypes or something
150
+ // We do this here because we need the alpha value (if any)
151
+ let [color, alpha] = splitUtilityModifier(modifier)
104
152
 
105
153
  if (alpha !== undefined) {
106
154
  let normalizedColor =
@@ -110,8 +158,10 @@ export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
110
158
  return undefined
111
159
  }
112
160
 
161
+ normalizedColor = parseColorFormat(normalizedColor)
162
+
113
163
  if (isArbitraryValue(alpha)) {
114
- return withAlphaValue(normalizedColor, alpha.slice(1, -1))
164
+ return withAlphaValue(normalizedColor, unwrapArbitraryModifier(alpha))
115
165
  }
116
166
 
117
167
  if (tailwindConfig.theme?.opacity?.[alpha] === undefined) {
@@ -134,7 +184,7 @@ function guess(validate) {
134
184
  }
135
185
  }
136
186
 
137
- let typeMap = {
187
+ export let typeMap = {
138
188
  any: asValue,
139
189
  color: asColor,
140
190
  url: guess(url),
@@ -150,6 +200,7 @@ let typeMap = {
150
200
  'absolute-size': guess(absoluteSize),
151
201
  'relative-size': guess(relativeSize),
152
202
  shadow: guess(shadow),
203
+ size: guess(backgroundSize),
153
204
  }
154
205
 
155
206
  let supportedTypes = Object.keys(typeMap)
@@ -161,6 +212,20 @@ function splitAtFirst(input, delim) {
161
212
  }
162
213
 
163
214
  export function coerceValue(types, modifier, options, tailwindConfig) {
215
+ if (options.values && modifier in options.values) {
216
+ for (let { type } of types ?? []) {
217
+ let result = typeMap[type](modifier, options, {
218
+ tailwindConfig,
219
+ })
220
+
221
+ if (result === undefined) {
222
+ continue
223
+ }
224
+
225
+ return [result, type, null]
226
+ }
227
+ }
228
+
164
229
  if (isArbitraryValue(modifier)) {
165
230
  let arbitraryValue = modifier.slice(1, -1)
166
231
  let [explicitType, value] = splitAtFirst(arbitraryValue, ':')
@@ -178,15 +243,72 @@ export function coerceValue(types, modifier, options, tailwindConfig) {
178
243
  }
179
244
 
180
245
  if (value.length > 0 && supportedTypes.includes(explicitType)) {
181
- return [asValue(`[${value}]`, options), explicitType]
246
+ return [asValue(`[${value}]`, options), explicitType, null]
182
247
  }
183
248
  }
184
249
 
250
+ let matches = getMatchingTypes(types, modifier, options, tailwindConfig)
251
+
185
252
  // Find first matching type
186
- for (let type of [].concat(types)) {
187
- let result = typeMap[type](modifier, options, { tailwindConfig })
188
- if (result !== undefined) return [result, type]
253
+ for (let match of matches) {
254
+ return match
189
255
  }
190
256
 
191
257
  return []
192
258
  }
259
+
260
+ /**
261
+ *
262
+ * @param {{type: string}[]} types
263
+ * @param {string} rawModifier
264
+ * @param {any} options
265
+ * @param {any} tailwindConfig
266
+ * @returns {Iterator<[value: string, type: string, modifier: string | null]>}
267
+ */
268
+ export function* getMatchingTypes(types, rawModifier, options, tailwindConfig) {
269
+ let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
270
+
271
+ let [modifier, utilityModifier] = splitUtilityModifier(rawModifier)
272
+
273
+ let canUseUtilityModifier =
274
+ modifiersEnabled &&
275
+ options.modifiers != null &&
276
+ (options.modifiers === 'any' ||
277
+ (typeof options.modifiers === 'object' &&
278
+ ((utilityModifier && isArbitraryValue(utilityModifier)) ||
279
+ utilityModifier in options.modifiers)))
280
+
281
+ if (!canUseUtilityModifier) {
282
+ modifier = rawModifier
283
+ utilityModifier = undefined
284
+ }
285
+
286
+ if (utilityModifier !== undefined && modifier === '') {
287
+ modifier = 'DEFAULT'
288
+ }
289
+
290
+ // Check the full value first
291
+ // TODO: Move to asValue… somehow
292
+ if (utilityModifier !== undefined) {
293
+ if (typeof options.modifiers === 'object') {
294
+ let configValue = options.modifiers?.[utilityModifier] ?? null
295
+ if (configValue !== null) {
296
+ utilityModifier = configValue
297
+ } else if (isArbitraryValue(utilityModifier)) {
298
+ utilityModifier = unwrapArbitraryModifier(utilityModifier)
299
+ }
300
+ }
301
+ }
302
+
303
+ for (let { type } of types ?? []) {
304
+ let result = typeMap[type](modifier, options, {
305
+ tailwindConfig,
306
+ })
307
+
308
+ if (result === undefined) {
309
+ continue
310
+ }
311
+
312
+ yield [result, type, utilityModifier ?? null]
313
+ }
314
+ }
@@ -1,14 +1,32 @@
1
1
  import parser from 'postcss-selector-parser'
2
2
 
3
+ /**
4
+ * @template {string | import('postcss-selector-parser').Root} T
5
+ *
6
+ * Prefix all classes in the selector with the given prefix
7
+ *
8
+ * It can take either a string or a selector AST and will return the same type
9
+ *
10
+ * @param {string} prefix
11
+ * @param {T} selector
12
+ * @param {boolean} prependNegative
13
+ * @returns {T}
14
+ */
3
15
  export default function (prefix, selector, prependNegative = false) {
4
- return parser((selectors) => {
5
- selectors.walkClasses((classSelector) => {
6
- let baseClass = classSelector.value
7
- let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
8
-
9
- classSelector.value = shouldPlaceNegativeBeforePrefix
10
- ? `-${prefix}${baseClass.slice(1)}`
11
- : `${prefix}${baseClass}`
12
- })
13
- }).processSync(selector)
16
+ if (prefix === '') {
17
+ return selector
18
+ }
19
+
20
+ let ast = typeof selector === 'string' ? parser().astSync(selector) : selector
21
+
22
+ ast.walkClasses((classSelector) => {
23
+ let baseClass = classSelector.value
24
+ let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
25
+
26
+ classSelector.value = shouldPlaceNegativeBeforePrefix
27
+ ? `-${prefix}${baseClass.slice(1)}`
28
+ : `${prefix}${baseClass}`
29
+ })
30
+
31
+ return typeof selector === 'string' ? ast.toString() : ast
14
32
  }
@@ -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
+ }