tailwindcss 0.0.0-insiders.d2bb6f1 → 0.0.0-insiders.d2fdddf

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