tailwindcss 0.0.0-insiders.cdbcefc → 0.0.0-insiders.cdc851d

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