tailwindcss 0.0.0-insiders.eb8d929 → 0.0.0-insiders.ec0049a

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