tailwindcss 3.4.0 → 4.0.0-alpha.1

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 (285) hide show
  1. package/dist/chunk-GNCUPSHB.mjs +5886 -0
  2. package/dist/cli.d.mts +1 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +6309 -0
  5. package/dist/cli.mjs +432 -0
  6. package/dist/lib.d.mts +324 -0
  7. package/dist/lib.d.ts +324 -0
  8. package/dist/lib.js +5884 -0
  9. package/dist/lib.mjs +1 -0
  10. package/index.css +5 -0
  11. package/package.json +35 -104
  12. package/preflight.css +355 -0
  13. package/theme.css +465 -0
  14. package/CHANGELOG.md +0 -2552
  15. package/README.md +0 -41
  16. package/base.css +0 -1
  17. package/colors.d.ts +0 -3
  18. package/colors.js +0 -2
  19. package/components.css +0 -1
  20. package/defaultConfig.d.ts +0 -3
  21. package/defaultConfig.js +0 -2
  22. package/defaultTheme.d.ts +0 -4
  23. package/defaultTheme.js +0 -2
  24. package/lib/cli/build/deps.js +0 -62
  25. package/lib/cli/build/index.js +0 -54
  26. package/lib/cli/build/plugin.js +0 -378
  27. package/lib/cli/build/utils.js +0 -88
  28. package/lib/cli/build/watching.js +0 -182
  29. package/lib/cli/help/index.js +0 -73
  30. package/lib/cli/index.js +0 -230
  31. package/lib/cli/init/index.js +0 -63
  32. package/lib/cli-peer-dependencies.js +0 -36
  33. package/lib/cli.js +0 -7
  34. package/lib/corePluginList.js +0 -190
  35. package/lib/corePlugins.js +0 -4244
  36. package/lib/css/LICENSE +0 -25
  37. package/lib/css/preflight.css +0 -385
  38. package/lib/featureFlags.js +0 -83
  39. package/lib/index.js +0 -2
  40. package/lib/lib/cacheInvalidation.js +0 -92
  41. package/lib/lib/collapseAdjacentRules.js +0 -61
  42. package/lib/lib/collapseDuplicateDeclarations.js +0 -85
  43. package/lib/lib/content.js +0 -181
  44. package/lib/lib/defaultExtractor.js +0 -251
  45. package/lib/lib/detectNesting.js +0 -45
  46. package/lib/lib/evaluateTailwindFunctions.js +0 -238
  47. package/lib/lib/expandApplyAtRules.js +0 -540
  48. package/lib/lib/expandTailwindAtRules.js +0 -291
  49. package/lib/lib/findAtConfigPath.js +0 -46
  50. package/lib/lib/generateRules.js +0 -896
  51. package/lib/lib/getModuleDependencies.js +0 -99
  52. package/lib/lib/load-config.js +0 -53
  53. package/lib/lib/normalizeTailwindDirectives.js +0 -89
  54. package/lib/lib/offsets.js +0 -306
  55. package/lib/lib/partitionApplyAtRules.js +0 -58
  56. package/lib/lib/regex.js +0 -74
  57. package/lib/lib/remap-bitfield.js +0 -89
  58. package/lib/lib/resolveDefaultsAtRules.js +0 -165
  59. package/lib/lib/setupContextUtils.js +0 -1278
  60. package/lib/lib/setupTrackingContext.js +0 -166
  61. package/lib/lib/sharedState.js +0 -87
  62. package/lib/lib/substituteScreenAtRules.js +0 -31
  63. package/lib/oxide/cli/build/deps.js +0 -89
  64. package/lib/oxide/cli/build/index.js +0 -53
  65. package/lib/oxide/cli/build/plugin.js +0 -375
  66. package/lib/oxide/cli/build/utils.js +0 -87
  67. package/lib/oxide/cli/build/watching.js +0 -179
  68. package/lib/oxide/cli/help/index.js +0 -72
  69. package/lib/oxide/cli/index.js +0 -214
  70. package/lib/oxide/cli/init/index.js +0 -52
  71. package/lib/oxide/cli.js +0 -5
  72. package/lib/oxide/postcss-plugin.js +0 -2
  73. package/lib/plugin.js +0 -98
  74. package/lib/postcss-plugins/nesting/README.md +0 -42
  75. package/lib/postcss-plugins/nesting/index.js +0 -21
  76. package/lib/postcss-plugins/nesting/plugin.js +0 -89
  77. package/lib/processTailwindFeatures.js +0 -64
  78. package/lib/public/colors.js +0 -355
  79. package/lib/public/create-plugin.js +0 -17
  80. package/lib/public/default-config.js +0 -18
  81. package/lib/public/default-theme.js +0 -18
  82. package/lib/public/load-config.js +0 -12
  83. package/lib/public/resolve-config.js +0 -24
  84. package/lib/util/applyImportantSelector.js +0 -36
  85. package/lib/util/bigSign.js +0 -13
  86. package/lib/util/buildMediaQuery.js +0 -27
  87. package/lib/util/cloneDeep.js +0 -22
  88. package/lib/util/cloneNodes.js +0 -54
  89. package/lib/util/color.js +0 -116
  90. package/lib/util/colorNames.js +0 -752
  91. package/lib/util/configurePlugins.js +0 -23
  92. package/lib/util/createPlugin.js +0 -32
  93. package/lib/util/createUtilityPlugin.js +0 -53
  94. package/lib/util/dataTypes.js +0 -405
  95. package/lib/util/defaults.js +0 -27
  96. package/lib/util/escapeClassName.js +0 -24
  97. package/lib/util/escapeCommas.js +0 -13
  98. package/lib/util/flattenColorPalette.js +0 -18
  99. package/lib/util/formatVariantSelector.js +0 -270
  100. package/lib/util/getAllConfigs.js +0 -50
  101. package/lib/util/hashConfig.js +0 -21
  102. package/lib/util/isKeyframeRule.js +0 -13
  103. package/lib/util/isPlainObject.js +0 -17
  104. package/lib/util/isSyntacticallyValidPropertyValue.js +0 -74
  105. package/lib/util/log.js +0 -61
  106. package/lib/util/nameClass.js +0 -49
  107. package/lib/util/negateValue.js +0 -36
  108. package/lib/util/normalizeConfig.js +0 -282
  109. package/lib/util/normalizeScreens.js +0 -178
  110. package/lib/util/parseAnimationValue.js +0 -93
  111. package/lib/util/parseBoxShadowValue.js +0 -88
  112. package/lib/util/parseDependency.js +0 -47
  113. package/lib/util/parseGlob.js +0 -36
  114. package/lib/util/parseObjectStyles.js +0 -36
  115. package/lib/util/pluginUtils.js +0 -289
  116. package/lib/util/prefixSelector.js +0 -39
  117. package/lib/util/pseudoElements.js +0 -209
  118. package/lib/util/removeAlphaVariables.js +0 -31
  119. package/lib/util/resolveConfig.js +0 -256
  120. package/lib/util/resolveConfigPath.js +0 -70
  121. package/lib/util/responsive.js +0 -24
  122. package/lib/util/splitAtTopLevelOnly.js +0 -51
  123. package/lib/util/tap.js +0 -14
  124. package/lib/util/toColorValue.js +0 -13
  125. package/lib/util/toPath.js +0 -32
  126. package/lib/util/transformThemeValue.js +0 -73
  127. package/lib/util/validateConfig.js +0 -37
  128. package/lib/util/validateFormalSyntax.js +0 -26
  129. package/lib/util/withAlphaVariable.js +0 -79
  130. package/lib/value-parser/LICENSE +0 -22
  131. package/lib/value-parser/README.md +0 -3
  132. package/lib/value-parser/index.d.js +0 -2
  133. package/lib/value-parser/index.js +0 -22
  134. package/lib/value-parser/parse.js +0 -259
  135. package/lib/value-parser/stringify.js +0 -38
  136. package/lib/value-parser/unit.js +0 -86
  137. package/lib/value-parser/walk.js +0 -16
  138. package/loadConfig.d.ts +0 -4
  139. package/loadConfig.js +0 -2
  140. package/nesting/index.d.ts +0 -4
  141. package/nesting/index.js +0 -2
  142. package/peers/index.js +0 -96624
  143. package/plugin.d.ts +0 -11
  144. package/plugin.js +0 -2
  145. package/prettier.config.js +0 -19
  146. package/resolveConfig.d.ts +0 -31
  147. package/resolveConfig.js +0 -2
  148. package/screens.css +0 -1
  149. package/scripts/create-plugin-list.js +0 -10
  150. package/scripts/generate-types.js +0 -104
  151. package/scripts/release-channel.js +0 -18
  152. package/scripts/release-notes.js +0 -21
  153. package/scripts/swap-engines.js +0 -40
  154. package/scripts/type-utils.js +0 -27
  155. package/src/cli/build/deps.js +0 -56
  156. package/src/cli/build/index.js +0 -49
  157. package/src/cli/build/plugin.js +0 -444
  158. package/src/cli/build/utils.js +0 -76
  159. package/src/cli/build/watching.js +0 -229
  160. package/src/cli/help/index.js +0 -70
  161. package/src/cli/index.js +0 -216
  162. package/src/cli/init/index.js +0 -79
  163. package/src/cli-peer-dependencies.js +0 -15
  164. package/src/cli.js +0 -7
  165. package/src/corePluginList.js +0 -1
  166. package/src/corePlugins.js +0 -2904
  167. package/src/css/LICENSE +0 -25
  168. package/src/css/preflight.css +0 -385
  169. package/src/featureFlags.js +0 -66
  170. package/src/index.js +0 -1
  171. package/src/lib/cacheInvalidation.js +0 -52
  172. package/src/lib/collapseAdjacentRules.js +0 -58
  173. package/src/lib/collapseDuplicateDeclarations.js +0 -93
  174. package/src/lib/content.js +0 -208
  175. package/src/lib/defaultExtractor.js +0 -230
  176. package/src/lib/detectNesting.js +0 -47
  177. package/src/lib/evaluateTailwindFunctions.js +0 -272
  178. package/src/lib/expandApplyAtRules.js +0 -620
  179. package/src/lib/expandTailwindAtRules.js +0 -300
  180. package/src/lib/findAtConfigPath.js +0 -48
  181. package/src/lib/generateRules.js +0 -941
  182. package/src/lib/getModuleDependencies.js +0 -79
  183. package/src/lib/load-config.ts +0 -39
  184. package/src/lib/normalizeTailwindDirectives.js +0 -84
  185. package/src/lib/offsets.js +0 -373
  186. package/src/lib/partitionApplyAtRules.js +0 -52
  187. package/src/lib/regex.js +0 -74
  188. package/src/lib/remap-bitfield.js +0 -82
  189. package/src/lib/resolveDefaultsAtRules.js +0 -163
  190. package/src/lib/setupContextUtils.js +0 -1345
  191. package/src/lib/setupTrackingContext.js +0 -169
  192. package/src/lib/sharedState.js +0 -61
  193. package/src/lib/substituteScreenAtRules.js +0 -19
  194. package/src/oxide/cli/build/deps.ts +0 -91
  195. package/src/oxide/cli/build/index.ts +0 -47
  196. package/src/oxide/cli/build/plugin.ts +0 -442
  197. package/src/oxide/cli/build/utils.ts +0 -74
  198. package/src/oxide/cli/build/watching.ts +0 -225
  199. package/src/oxide/cli/help/index.ts +0 -69
  200. package/src/oxide/cli/index.ts +0 -204
  201. package/src/oxide/cli/init/index.ts +0 -59
  202. package/src/oxide/cli.ts +0 -1
  203. package/src/oxide/postcss-plugin.ts +0 -1
  204. package/src/plugin.js +0 -107
  205. package/src/postcss-plugins/nesting/README.md +0 -42
  206. package/src/postcss-plugins/nesting/index.js +0 -13
  207. package/src/postcss-plugins/nesting/plugin.js +0 -80
  208. package/src/processTailwindFeatures.js +0 -59
  209. package/src/public/colors.js +0 -322
  210. package/src/public/create-plugin.js +0 -2
  211. package/src/public/default-config.js +0 -4
  212. package/src/public/default-theme.js +0 -4
  213. package/src/public/load-config.js +0 -2
  214. package/src/public/resolve-config.js +0 -7
  215. package/src/util/applyImportantSelector.js +0 -27
  216. package/src/util/bigSign.js +0 -3
  217. package/src/util/buildMediaQuery.js +0 -22
  218. package/src/util/cloneDeep.js +0 -11
  219. package/src/util/cloneNodes.js +0 -49
  220. package/src/util/color.js +0 -88
  221. package/src/util/colorNames.js +0 -150
  222. package/src/util/configurePlugins.js +0 -23
  223. package/src/util/createPlugin.js +0 -27
  224. package/src/util/createUtilityPlugin.js +0 -37
  225. package/src/util/dataTypes.js +0 -394
  226. package/src/util/defaults.js +0 -17
  227. package/src/util/escapeClassName.js +0 -8
  228. package/src/util/escapeCommas.js +0 -3
  229. package/src/util/flattenColorPalette.js +0 -13
  230. package/src/util/formatVariantSelector.js +0 -324
  231. package/src/util/getAllConfigs.js +0 -38
  232. package/src/util/hashConfig.js +0 -5
  233. package/src/util/isKeyframeRule.js +0 -3
  234. package/src/util/isPlainObject.js +0 -8
  235. package/src/util/isSyntacticallyValidPropertyValue.js +0 -61
  236. package/src/util/log.js +0 -29
  237. package/src/util/nameClass.js +0 -30
  238. package/src/util/negateValue.js +0 -24
  239. package/src/util/normalizeConfig.js +0 -301
  240. package/src/util/normalizeScreens.js +0 -140
  241. package/src/util/parseAnimationValue.js +0 -68
  242. package/src/util/parseBoxShadowValue.js +0 -72
  243. package/src/util/parseDependency.js +0 -44
  244. package/src/util/parseGlob.js +0 -24
  245. package/src/util/parseObjectStyles.js +0 -19
  246. package/src/util/pluginUtils.js +0 -307
  247. package/src/util/prefixSelector.js +0 -33
  248. package/src/util/pseudoElements.js +0 -167
  249. package/src/util/removeAlphaVariables.js +0 -24
  250. package/src/util/resolveConfig.js +0 -277
  251. package/src/util/resolveConfigPath.js +0 -66
  252. package/src/util/responsive.js +0 -10
  253. package/src/util/splitAtTopLevelOnly.js +0 -52
  254. package/src/util/tap.js +0 -4
  255. package/src/util/toColorValue.js +0 -3
  256. package/src/util/toPath.js +0 -26
  257. package/src/util/transformThemeValue.js +0 -62
  258. package/src/util/validateConfig.js +0 -26
  259. package/src/util/validateFormalSyntax.js +0 -34
  260. package/src/util/withAlphaVariable.js +0 -49
  261. package/src/value-parser/LICENSE +0 -22
  262. package/src/value-parser/README.md +0 -3
  263. package/src/value-parser/index.d.ts +0 -177
  264. package/src/value-parser/index.js +0 -28
  265. package/src/value-parser/parse.js +0 -303
  266. package/src/value-parser/stringify.js +0 -41
  267. package/src/value-parser/unit.js +0 -118
  268. package/src/value-parser/walk.js +0 -18
  269. package/stubs/.gitignore +0 -1
  270. package/stubs/.prettierrc.json +0 -6
  271. package/stubs/config.full.js +0 -1062
  272. package/stubs/config.simple.js +0 -7
  273. package/stubs/postcss.config.cjs +0 -6
  274. package/stubs/postcss.config.js +0 -6
  275. package/stubs/tailwind.config.cjs +0 -2
  276. package/stubs/tailwind.config.js +0 -2
  277. package/stubs/tailwind.config.ts +0 -3
  278. package/tailwind.css +0 -5
  279. package/types/config.d.ts +0 -369
  280. package/types/generated/.gitkeep +0 -0
  281. package/types/generated/colors.d.ts +0 -298
  282. package/types/generated/corePluginList.d.ts +0 -1
  283. package/types/generated/default-theme.d.ts +0 -397
  284. package/types/index.d.ts +0 -11
  285. package/variants.css +0 -1
@@ -1,941 +0,0 @@
1
- import postcss from 'postcss'
2
- import selectorParser from 'postcss-selector-parser'
3
- import parseObjectStyles from '../util/parseObjectStyles'
4
- import isPlainObject from '../util/isPlainObject'
5
- import prefixSelector from '../util/prefixSelector'
6
- import { updateAllClasses, getMatchingTypes } from '../util/pluginUtils'
7
- import log from '../util/log'
8
- import * as sharedState from './sharedState'
9
- import {
10
- formatVariantSelector,
11
- finalizeSelector,
12
- eliminateIrrelevantSelectors,
13
- } from '../util/formatVariantSelector'
14
- import { asClass } from '../util/nameClass'
15
- import { normalize } from '../util/dataTypes'
16
- import { isValidVariantFormatString, parseVariant, INTERNAL_FEATURES } from './setupContextUtils'
17
- import isValidArbitraryValue from '../util/isSyntacticallyValidPropertyValue'
18
- import { splitAtTopLevelOnly } from '../util/splitAtTopLevelOnly.js'
19
- import { flagEnabled } from '../featureFlags'
20
- import { applyImportantSelector } from '../util/applyImportantSelector'
21
-
22
- let classNameParser = selectorParser((selectors) => {
23
- return selectors.first.filter(({ type }) => type === 'class').pop().value
24
- })
25
-
26
- export function getClassNameFromSelector(selector) {
27
- return classNameParser.transformSync(selector)
28
- }
29
-
30
- // Generate match permutations for a class candidate, like:
31
- // ['ring-offset-blue', '100']
32
- // ['ring-offset', 'blue-100']
33
- // ['ring', 'offset-blue-100']
34
- // Example with dynamic classes:
35
- // ['grid-cols', '[[linename],1fr,auto]']
36
- // ['grid', 'cols-[[linename],1fr,auto]']
37
- function* candidatePermutations(candidate) {
38
- let lastIndex = Infinity
39
-
40
- while (lastIndex >= 0) {
41
- let dashIdx
42
- let wasSlash = false
43
-
44
- if (lastIndex === Infinity && candidate.endsWith(']')) {
45
- let bracketIdx = candidate.indexOf('[')
46
-
47
- // If character before `[` isn't a dash or a slash, this isn't a dynamic class
48
- // eg. string[]
49
- if (candidate[bracketIdx - 1] === '-') {
50
- dashIdx = bracketIdx - 1
51
- } else if (candidate[bracketIdx - 1] === '/') {
52
- dashIdx = bracketIdx - 1
53
- wasSlash = true
54
- } else {
55
- dashIdx = -1
56
- }
57
- } else if (lastIndex === Infinity && candidate.includes('/')) {
58
- dashIdx = candidate.lastIndexOf('/')
59
- wasSlash = true
60
- } else {
61
- dashIdx = candidate.lastIndexOf('-', lastIndex)
62
- }
63
-
64
- if (dashIdx < 0) {
65
- break
66
- }
67
-
68
- let prefix = candidate.slice(0, dashIdx)
69
- let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1)
70
-
71
- lastIndex = dashIdx - 1
72
-
73
- // TODO: This feels a bit hacky
74
- if (prefix === '' || modifier === '/') {
75
- continue
76
- }
77
-
78
- yield [prefix, modifier]
79
- }
80
- }
81
-
82
- function applyPrefix(matches, context) {
83
- if (matches.length === 0 || context.tailwindConfig.prefix === '') {
84
- return matches
85
- }
86
-
87
- for (let match of matches) {
88
- let [meta] = match
89
- if (meta.options.respectPrefix) {
90
- let container = postcss.root({ nodes: [match[1].clone()] })
91
- let classCandidate = match[1].raws.tailwind.classCandidate
92
-
93
- container.walkRules((r) => {
94
- // If this is a negative utility with a dash *before* the prefix we
95
- // have to ensure that the generated selector matches the candidate
96
-
97
- // Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
98
- // The disconnect between candidate <-> class can cause @apply to hard crash.
99
- let shouldPrependNegative = classCandidate.startsWith('-')
100
-
101
- r.selector = prefixSelector(
102
- context.tailwindConfig.prefix,
103
- r.selector,
104
- shouldPrependNegative
105
- )
106
- })
107
-
108
- match[1] = container.nodes[0]
109
- }
110
- }
111
-
112
- return matches
113
- }
114
-
115
- function applyImportant(matches, classCandidate) {
116
- if (matches.length === 0) {
117
- return matches
118
- }
119
-
120
- let result = []
121
-
122
- for (let [meta, rule] of matches) {
123
- let container = postcss.root({ nodes: [rule.clone()] })
124
-
125
- container.walkRules((r) => {
126
- let ast = selectorParser().astSync(r.selector)
127
-
128
- // Remove extraneous selectors that do not include the base candidate
129
- ast.each((sel) => eliminateIrrelevantSelectors(sel, classCandidate))
130
-
131
- // Update all instances of the base candidate to include the important marker
132
- updateAllClasses(ast, (className) =>
133
- className === classCandidate ? `!${className}` : className
134
- )
135
-
136
- r.selector = ast.toString()
137
-
138
- r.walkDecls((d) => (d.important = true))
139
- })
140
-
141
- result.push([{ ...meta, important: true }, container.nodes[0]])
142
- }
143
-
144
- return result
145
- }
146
-
147
- // Takes a list of rule tuples and applies a variant like `hover`, sm`,
148
- // whatever to it. We used to do some extra caching here to avoid generating
149
- // a variant of the same rule more than once, but this was never hit because
150
- // we cache at the entire selector level further up the tree.
151
- //
152
- // Technically you can get a cache hit if you have `hover:focus:text-center`
153
- // and `focus:hover:text-center` in the same project, but it doesn't feel
154
- // worth the complexity for that case.
155
-
156
- function applyVariant(variant, matches, context) {
157
- if (matches.length === 0) {
158
- return matches
159
- }
160
-
161
- /** @type {{modifier: string | null, value: string | null}} */
162
- let args = { modifier: null, value: sharedState.NONE }
163
-
164
- // Retrieve "modifier"
165
- {
166
- let [baseVariant, ...modifiers] = splitAtTopLevelOnly(variant, '/')
167
-
168
- // This is a hack to support variants with `/` in them, like `ar-1/10/20:text-red-500`
169
- // In this case 1/10 is a value but /20 is a modifier
170
- if (modifiers.length > 1) {
171
- baseVariant = baseVariant + '/' + modifiers.slice(0, -1).join('/')
172
- modifiers = modifiers.slice(-1)
173
- }
174
-
175
- if (modifiers.length && !context.variantMap.has(variant)) {
176
- variant = baseVariant
177
- args.modifier = modifiers[0]
178
-
179
- if (!flagEnabled(context.tailwindConfig, 'generalizedModifiers')) {
180
- return []
181
- }
182
- }
183
- }
184
-
185
- // Retrieve "arbitrary value"
186
- if (variant.endsWith(']') && !variant.startsWith('[')) {
187
- // We either have:
188
- // @[200px]
189
- // group-[:hover]
190
- //
191
- // But we don't want:
192
- // @-[200px] (`-` is incorrect)
193
- // group[:hover] (`-` is missing)
194
- let match = /(.)(-?)\[(.*)\]/g.exec(variant)
195
- if (match) {
196
- let [, char, separator, value] = match
197
- // @-[200px] case
198
- if (char === '@' && separator === '-') return []
199
- // group[:hover] case
200
- if (char !== '@' && separator === '') return []
201
-
202
- variant = variant.replace(`${separator}[${value}]`, '')
203
- args.value = value
204
- }
205
- }
206
-
207
- // Register arbitrary variants
208
- if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
209
- let sort = context.offsets.recordVariant(variant)
210
-
211
- let selector = normalize(variant.slice(1, -1))
212
- let selectors = splitAtTopLevelOnly(selector, ',')
213
-
214
- // We do not support multiple selectors for arbitrary variants
215
- if (selectors.length > 1) {
216
- return []
217
- }
218
-
219
- if (!selectors.every(isValidVariantFormatString)) {
220
- return []
221
- }
222
-
223
- let records = selectors.map((sel, idx) => [
224
- context.offsets.applyParallelOffset(sort, idx),
225
- parseVariant(sel.trim()),
226
- ])
227
-
228
- context.variantMap.set(variant, records)
229
- }
230
-
231
- if (context.variantMap.has(variant)) {
232
- let isArbitraryVariant = isArbitraryValue(variant)
233
- let internalFeatures = context.variantOptions.get(variant)?.[INTERNAL_FEATURES] ?? {}
234
- let variantFunctionTuples = context.variantMap.get(variant).slice()
235
- let result = []
236
-
237
- let respectPrefix = (() => {
238
- if (isArbitraryVariant) return false
239
- if (internalFeatures.respectPrefix === false) return false
240
- return true
241
- })()
242
-
243
- for (let [meta, rule] of matches) {
244
- // Don't generate variants for user css
245
- if (meta.layer === 'user') {
246
- continue
247
- }
248
-
249
- let container = postcss.root({ nodes: [rule.clone()] })
250
-
251
- for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples) {
252
- let clone = (containerFromArray ?? container).clone()
253
- let collectedFormats = []
254
-
255
- function prepareBackup() {
256
- // Already prepared, chicken out
257
- if (clone.raws.neededBackup) {
258
- return
259
- }
260
- clone.raws.neededBackup = true
261
- clone.walkRules((rule) => (rule.raws.originalSelector = rule.selector))
262
- }
263
-
264
- function modifySelectors(modifierFunction) {
265
- prepareBackup()
266
- clone.each((rule) => {
267
- if (rule.type !== 'rule') {
268
- return
269
- }
270
-
271
- rule.selectors = rule.selectors.map((selector) => {
272
- return modifierFunction({
273
- get className() {
274
- return getClassNameFromSelector(selector)
275
- },
276
- selector,
277
- })
278
- })
279
- })
280
-
281
- return clone
282
- }
283
-
284
- let ruleWithVariant = variantFunction({
285
- // Public API
286
- get container() {
287
- prepareBackup()
288
- return clone
289
- },
290
- separator: context.tailwindConfig.separator,
291
- modifySelectors,
292
-
293
- // Private API for now
294
- wrap(wrapper) {
295
- let nodes = clone.nodes
296
- clone.removeAll()
297
- wrapper.append(nodes)
298
- clone.append(wrapper)
299
- },
300
- format(selectorFormat) {
301
- collectedFormats.push({
302
- format: selectorFormat,
303
- respectPrefix,
304
- })
305
- },
306
- args,
307
- })
308
-
309
- // It can happen that a list of format strings is returned from within the function. In that
310
- // case, we have to process them as well. We can use the existing `variantSort`.
311
- if (Array.isArray(ruleWithVariant)) {
312
- for (let [idx, variantFunction] of ruleWithVariant.entries()) {
313
- // This is a little bit scary since we are pushing to an array of items that we are
314
- // currently looping over. However, you can also think of it like a processing queue
315
- // where you keep handling jobs until everything is done and each job can queue more
316
- // jobs if needed.
317
- variantFunctionTuples.push([
318
- context.offsets.applyParallelOffset(variantSort, idx),
319
- variantFunction,
320
-
321
- // If the clone has been modified we have to pass that back
322
- // though so each rule can use the modified container
323
- clone.clone(),
324
- ])
325
- }
326
- continue
327
- }
328
-
329
- if (typeof ruleWithVariant === 'string') {
330
- collectedFormats.push({
331
- format: ruleWithVariant,
332
- respectPrefix,
333
- })
334
- }
335
-
336
- if (ruleWithVariant === null) {
337
- continue
338
- }
339
-
340
- // We had to backup selectors, therefore we assume that somebody touched
341
- // `container` or `modifySelectors`. Let's see if they did, so that we
342
- // can restore the selectors, and collect the format strings.
343
- if (clone.raws.neededBackup) {
344
- delete clone.raws.neededBackup
345
- clone.walkRules((rule) => {
346
- let before = rule.raws.originalSelector
347
- if (!before) return
348
- delete rule.raws.originalSelector
349
- if (before === rule.selector) return // No mutation happened
350
-
351
- let modified = rule.selector
352
-
353
- // Rebuild the base selector, this is what plugin authors would do
354
- // as well. E.g.: `${variant}${separator}${className}`.
355
- // However, plugin authors probably also prepend or append certain
356
- // classes, pseudos, ids, ...
357
- let rebuiltBase = selectorParser((selectors) => {
358
- selectors.walkClasses((classNode) => {
359
- classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`
360
- })
361
- }).processSync(before)
362
-
363
- // Now that we know the original selector, the new selector, and
364
- // the rebuild part in between, we can replace the part that plugin
365
- // authors need to rebuild with `&`, and eventually store it in the
366
- // collectedFormats. Similar to what `format('...')` would do.
367
- //
368
- // E.g.:
369
- // variant: foo
370
- // selector: .markdown > p
371
- // modified (by plugin): .foo .foo\\:markdown > p
372
- // rebuiltBase (internal): .foo\\:markdown > p
373
- // format: .foo &
374
- collectedFormats.push({
375
- format: modified.replace(rebuiltBase, '&'),
376
- respectPrefix,
377
- })
378
- rule.selector = before
379
- })
380
- }
381
-
382
- // This tracks the originating layer for the variant
383
- // For example:
384
- // .sm:underline {} is a variant of something in the utilities layer
385
- // .sm:container {} is a variant of the container component
386
- clone.nodes[0].raws.tailwind = { ...clone.nodes[0].raws.tailwind, parentLayer: meta.layer }
387
-
388
- let withOffset = [
389
- {
390
- ...meta,
391
- sort: context.offsets.applyVariantOffset(
392
- meta.sort,
393
- variantSort,
394
- Object.assign(args, context.variantOptions.get(variant))
395
- ),
396
- collectedFormats: (meta.collectedFormats ?? []).concat(collectedFormats),
397
- },
398
- clone.nodes[0],
399
- ]
400
- result.push(withOffset)
401
- }
402
- }
403
-
404
- return result
405
- }
406
-
407
- return []
408
- }
409
-
410
- function parseRules(rule, cache, options = {}) {
411
- // PostCSS node
412
- if (!isPlainObject(rule) && !Array.isArray(rule)) {
413
- return [[rule], options]
414
- }
415
-
416
- // Tuple
417
- if (Array.isArray(rule)) {
418
- return parseRules(rule[0], cache, rule[1])
419
- }
420
-
421
- // Simple object
422
- if (!cache.has(rule)) {
423
- cache.set(rule, parseObjectStyles(rule))
424
- }
425
-
426
- return [cache.get(rule), options]
427
- }
428
-
429
- const IS_VALID_PROPERTY_NAME = /^[a-z_-]/
430
-
431
- function isValidPropName(name) {
432
- return IS_VALID_PROPERTY_NAME.test(name)
433
- }
434
-
435
- /**
436
- * @param {string} declaration
437
- * @returns {boolean}
438
- */
439
- function looksLikeUri(declaration) {
440
- // Quick bailout for obvious non-urls
441
- // This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
442
- if (!declaration.includes('://')) {
443
- return false
444
- }
445
-
446
- try {
447
- const url = new URL(declaration)
448
- return url.scheme !== '' && url.host !== ''
449
- } catch (err) {
450
- // Definitely not a valid url
451
- return false
452
- }
453
- }
454
-
455
- function isParsableNode(node) {
456
- let isParsable = true
457
-
458
- node.walkDecls((decl) => {
459
- if (!isParsableCssValue(decl.prop, decl.value)) {
460
- isParsable = false
461
- return false
462
- }
463
- })
464
-
465
- return isParsable
466
- }
467
-
468
- function isParsableCssValue(property, value) {
469
- // We don't want to to treat [https://example.com] as a custom property
470
- // Even though, according to the CSS grammar, it's a totally valid CSS declaration
471
- // So we short-circuit here by checking if the custom property looks like a url
472
- if (looksLikeUri(`${property}:${value}`)) {
473
- return false
474
- }
475
-
476
- try {
477
- postcss.parse(`a{${property}:${value}}`).toResult()
478
- return true
479
- } catch (err) {
480
- return false
481
- }
482
- }
483
-
484
- function extractArbitraryProperty(classCandidate, context) {
485
- let [, property, value] = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/) ?? []
486
-
487
- if (value === undefined) {
488
- return null
489
- }
490
-
491
- if (!isValidPropName(property)) {
492
- return null
493
- }
494
-
495
- if (!isValidArbitraryValue(value)) {
496
- return null
497
- }
498
-
499
- let normalized = normalize(value, { property })
500
-
501
- if (!isParsableCssValue(property, normalized)) {
502
- return null
503
- }
504
-
505
- let sort = context.offsets.arbitraryProperty()
506
-
507
- return [
508
- [
509
- { sort, layer: 'utilities' },
510
- () => ({
511
- [asClass(classCandidate)]: {
512
- [property]: normalized,
513
- },
514
- }),
515
- ],
516
- ]
517
- }
518
-
519
- function* resolveMatchedPlugins(classCandidate, context) {
520
- if (context.candidateRuleMap.has(classCandidate)) {
521
- yield [context.candidateRuleMap.get(classCandidate), 'DEFAULT']
522
- }
523
-
524
- yield* (function* (arbitraryPropertyRule) {
525
- if (arbitraryPropertyRule !== null) {
526
- yield [arbitraryPropertyRule, 'DEFAULT']
527
- }
528
- })(extractArbitraryProperty(classCandidate, context))
529
-
530
- let candidatePrefix = classCandidate
531
- let negative = false
532
-
533
- const twConfigPrefix = context.tailwindConfig.prefix
534
-
535
- const twConfigPrefixLen = twConfigPrefix.length
536
-
537
- const hasMatchingPrefix =
538
- candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`)
539
-
540
- if (candidatePrefix[twConfigPrefixLen] === '-' && hasMatchingPrefix) {
541
- negative = true
542
- candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)
543
- }
544
-
545
- if (negative && context.candidateRuleMap.has(candidatePrefix)) {
546
- yield [context.candidateRuleMap.get(candidatePrefix), '-DEFAULT']
547
- }
548
-
549
- for (let [prefix, modifier] of candidatePermutations(candidatePrefix)) {
550
- if (context.candidateRuleMap.has(prefix)) {
551
- yield [context.candidateRuleMap.get(prefix), negative ? `-${modifier}` : modifier]
552
- }
553
- }
554
- }
555
-
556
- function splitWithSeparator(input, separator) {
557
- if (input === sharedState.NOT_ON_DEMAND) {
558
- return [sharedState.NOT_ON_DEMAND]
559
- }
560
-
561
- return splitAtTopLevelOnly(input, separator)
562
- }
563
-
564
- function* recordCandidates(matches, classCandidate) {
565
- for (const match of matches) {
566
- match[1].raws.tailwind = {
567
- ...match[1].raws.tailwind,
568
- classCandidate,
569
- preserveSource: match[0].options?.preserveSource ?? false,
570
- }
571
-
572
- yield match
573
- }
574
- }
575
-
576
- function* resolveMatches(candidate, context) {
577
- let separator = context.tailwindConfig.separator
578
- let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse()
579
- let important = false
580
-
581
- if (classCandidate.startsWith('!')) {
582
- important = true
583
- classCandidate = classCandidate.slice(1)
584
- }
585
-
586
- // TODO: Reintroduce this in ways that doesn't break on false positives
587
- // function sortAgainst(toSort, against) {
588
- // return toSort.slice().sort((a, z) => {
589
- // return bigSign(against.get(a)[0] - against.get(z)[0])
590
- // })
591
- // }
592
- // let sorted = sortAgainst(variants, context.variantMap)
593
- // if (sorted.toString() !== variants.toString()) {
594
- // let corrected = sorted.reverse().concat(classCandidate).join(':')
595
- // throw new Error(`Class ${candidate} should be written as ${corrected}`)
596
- // }
597
-
598
- for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)) {
599
- let matches = []
600
- let typesByMatches = new Map()
601
-
602
- let [plugins, modifier] = matchedPlugins
603
- let isOnlyPlugin = plugins.length === 1
604
-
605
- for (let [sort, plugin] of plugins) {
606
- let matchesPerPlugin = []
607
-
608
- if (typeof plugin === 'function') {
609
- for (let ruleSet of [].concat(plugin(modifier, { isOnlyPlugin }))) {
610
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
611
- for (let rule of rules) {
612
- matchesPerPlugin.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
613
- }
614
- }
615
- }
616
- // Only process static plugins on exact matches
617
- else if (modifier === 'DEFAULT' || modifier === '-DEFAULT') {
618
- let ruleSet = plugin
619
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
620
- for (let rule of rules) {
621
- matchesPerPlugin.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
622
- }
623
- }
624
-
625
- if (matchesPerPlugin.length > 0) {
626
- let matchingTypes = Array.from(
627
- getMatchingTypes(
628
- sort.options?.types ?? [],
629
- modifier,
630
- sort.options ?? {},
631
- context.tailwindConfig
632
- )
633
- ).map(([_, type]) => type)
634
-
635
- if (matchingTypes.length > 0) {
636
- typesByMatches.set(matchesPerPlugin, matchingTypes)
637
- }
638
-
639
- matches.push(matchesPerPlugin)
640
- }
641
- }
642
-
643
- if (isArbitraryValue(modifier)) {
644
- if (matches.length > 1) {
645
- // Partition plugins in 2 categories so that we can start searching in the plugins that
646
- // don't have `any` as a type first.
647
- let [withAny, withoutAny] = matches.reduce(
648
- (group, plugin) => {
649
- let hasAnyType = plugin.some(([{ options }]) =>
650
- options.types.some(({ type }) => type === 'any')
651
- )
652
-
653
- if (hasAnyType) {
654
- group[0].push(plugin)
655
- } else {
656
- group[1].push(plugin)
657
- }
658
- return group
659
- },
660
- [[], []]
661
- )
662
-
663
- function findFallback(matches) {
664
- // If only a single plugin matches, let's take that one
665
- if (matches.length === 1) {
666
- return matches[0]
667
- }
668
-
669
- // Otherwise, find the plugin that creates a valid rule given the arbitrary value, and
670
- // also has the correct type which preferOnConflicts the plugin in case of clashes.
671
- return matches.find((rules) => {
672
- let matchingTypes = typesByMatches.get(rules)
673
- return rules.some(([{ options }, rule]) => {
674
- if (!isParsableNode(rule)) {
675
- return false
676
- }
677
-
678
- return options.types.some(
679
- ({ type, preferOnConflict }) => matchingTypes.includes(type) && preferOnConflict
680
- )
681
- })
682
- })
683
- }
684
-
685
- // Try to find a fallback plugin, because we already know that multiple plugins matched for
686
- // the given arbitrary value.
687
- let fallback = findFallback(withoutAny) ?? findFallback(withAny)
688
- if (fallback) {
689
- matches = [fallback]
690
- }
691
-
692
- // We couldn't find a fallback plugin which means that there are now multiple plugins that
693
- // generated css for the current candidate. This means that the result is ambiguous and this
694
- // should not happen. We won't generate anything right now, so let's report this to the user
695
- // by logging some options about what they can do.
696
- else {
697
- let typesPerPlugin = matches.map(
698
- (match) => new Set([...(typesByMatches.get(match) ?? [])])
699
- )
700
-
701
- // Remove duplicates, so that we can detect proper unique types for each plugin.
702
- for (let pluginTypes of typesPerPlugin) {
703
- for (let type of pluginTypes) {
704
- let removeFromOwnGroup = false
705
-
706
- for (let otherGroup of typesPerPlugin) {
707
- if (pluginTypes === otherGroup) continue
708
-
709
- if (otherGroup.has(type)) {
710
- otherGroup.delete(type)
711
- removeFromOwnGroup = true
712
- }
713
- }
714
-
715
- if (removeFromOwnGroup) pluginTypes.delete(type)
716
- }
717
- }
718
-
719
- let messages = []
720
-
721
- for (let [idx, group] of typesPerPlugin.entries()) {
722
- for (let type of group) {
723
- let rules = matches[idx]
724
- .map(([, rule]) => rule)
725
- .flat()
726
- .map((rule) =>
727
- rule
728
- .toString()
729
- .split('\n')
730
- .slice(1, -1) // Remove selector and closing '}'
731
- .map((line) => line.trim())
732
- .map((x) => ` ${x}`) // Re-indent
733
- .join('\n')
734
- )
735
- .join('\n\n')
736
-
737
- messages.push(
738
- ` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``
739
- )
740
- break
741
- }
742
- }
743
-
744
- log.warn([
745
- `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
746
- ...messages,
747
- `If this is content and not a class, replace it with \`${candidate
748
- .replace('[', '&lsqb;')
749
- .replace(']', '&rsqb;')}\` to silence this warning.`,
750
- ])
751
- continue
752
- }
753
- }
754
-
755
- matches = matches.map((list) => list.filter((match) => isParsableNode(match[1])))
756
- }
757
-
758
- matches = matches.flat()
759
- matches = Array.from(recordCandidates(matches, classCandidate))
760
- matches = applyPrefix(matches, context)
761
-
762
- if (important) {
763
- matches = applyImportant(matches, classCandidate)
764
- }
765
-
766
- for (let variant of variants) {
767
- matches = applyVariant(variant, matches, context)
768
- }
769
-
770
- for (let match of matches) {
771
- match[1].raws.tailwind = { ...match[1].raws.tailwind, candidate }
772
-
773
- // Apply final format selector
774
- match = applyFinalFormat(match, { context, candidate })
775
-
776
- // Skip rules with invalid selectors
777
- // This will cause the candidate to be added to the "not class"
778
- // cache skipping it entirely for future builds
779
- if (match === null) {
780
- continue
781
- }
782
-
783
- yield match
784
- }
785
- }
786
- }
787
-
788
- function applyFinalFormat(match, { context, candidate }) {
789
- if (!match[0].collectedFormats) {
790
- return match
791
- }
792
-
793
- let isValid = true
794
- let finalFormat
795
-
796
- try {
797
- finalFormat = formatVariantSelector(match[0].collectedFormats, {
798
- context,
799
- candidate,
800
- })
801
- } catch {
802
- // The format selector we produced is invalid
803
- // This could be because:
804
- // - A bug exists
805
- // - A plugin introduced an invalid variant selector (ex: `addVariant('foo', '&;foo')`)
806
- // - The user used an invalid arbitrary variant (ex: `[&;foo]:underline`)
807
- // Either way the build will fail because of this
808
- // We would rather that the build pass "silently" given that this could
809
- // happen because of picking up invalid things when scanning content
810
- // So we'll throw out the candidate instead
811
-
812
- return null
813
- }
814
-
815
- let container = postcss.root({ nodes: [match[1].clone()] })
816
-
817
- container.walkRules((rule) => {
818
- if (inKeyframes(rule)) {
819
- return
820
- }
821
-
822
- try {
823
- let selector = finalizeSelector(rule.selector, finalFormat, {
824
- candidate,
825
- context,
826
- })
827
-
828
- // Finalize Selector determined that this candidate is irrelevant
829
- // TODO: This elimination should happen earlier so this never happens
830
- if (selector === null) {
831
- rule.remove()
832
- return
833
- }
834
-
835
- rule.selector = selector
836
- } catch {
837
- // If this selector is invalid we also want to skip it
838
- // But it's likely that being invalid here means there's a bug in a plugin rather than too loosely matching content
839
- isValid = false
840
- return false
841
- }
842
- })
843
-
844
- if (!isValid) {
845
- return null
846
- }
847
-
848
- // If all rules have been eliminated we can skip this candidate entirely
849
- if (container.nodes.length === 0) {
850
- return null
851
- }
852
-
853
- match[1] = container.nodes[0]
854
-
855
- return match
856
- }
857
-
858
- function inKeyframes(rule) {
859
- return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
860
- }
861
-
862
- function getImportantStrategy(important) {
863
- if (important === true) {
864
- return (rule) => {
865
- if (inKeyframes(rule)) {
866
- return
867
- }
868
-
869
- rule.walkDecls((d) => {
870
- if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
871
- d.important = true
872
- }
873
- })
874
- }
875
- }
876
-
877
- if (typeof important === 'string') {
878
- return (rule) => {
879
- if (inKeyframes(rule)) {
880
- return
881
- }
882
-
883
- rule.selectors = rule.selectors.map((selector) => {
884
- return applyImportantSelector(selector, important)
885
- })
886
- }
887
- }
888
- }
889
-
890
- function generateRules(candidates, context, isSorting = false) {
891
- let allRules = []
892
- let strategy = getImportantStrategy(context.tailwindConfig.important)
893
-
894
- for (let candidate of candidates) {
895
- if (context.notClassCache.has(candidate)) {
896
- continue
897
- }
898
-
899
- if (context.candidateRuleCache.has(candidate)) {
900
- allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)))
901
- continue
902
- }
903
-
904
- let matches = Array.from(resolveMatches(candidate, context))
905
-
906
- if (matches.length === 0) {
907
- context.notClassCache.add(candidate)
908
- continue
909
- }
910
-
911
- context.classCache.set(candidate, matches)
912
-
913
- let rules = context.candidateRuleCache.get(candidate) ?? new Set()
914
- context.candidateRuleCache.set(candidate, rules)
915
-
916
- for (const match of matches) {
917
- let [{ sort, options }, rule] = match
918
-
919
- if (options.respectImportant && strategy) {
920
- let container = postcss.root({ nodes: [rule.clone()] })
921
- container.walkRules(strategy)
922
- rule = container.nodes[0]
923
- }
924
-
925
- // Note: We have to clone rules during sorting
926
- // so we eliminate some shared mutable state
927
- let newEntry = [sort, isSorting ? rule.clone() : rule]
928
- rules.add(newEntry)
929
- context.ruleCache.add(newEntry)
930
- allRules.push(newEntry)
931
- }
932
- }
933
-
934
- return allRules
935
- }
936
-
937
- function isArbitraryValue(input) {
938
- return input.startsWith('[') && input.endsWith(']')
939
- }
940
-
941
- export { resolveMatches, generateRules }