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,1318 +0,0 @@
1
- import fs from 'fs'
2
- import url from 'url'
3
- import postcss from 'postcss'
4
- import dlv from 'dlv'
5
- import selectorParser from 'postcss-selector-parser'
6
-
7
- import transformThemeValue from '../util/transformThemeValue'
8
- import parseObjectStyles from '../util/parseObjectStyles'
9
- import prefixSelector from '../util/prefixSelector'
10
- import isPlainObject from '../util/isPlainObject'
11
- import escapeClassName from '../util/escapeClassName'
12
- import nameClass, { formatClass } from '../util/nameClass'
13
- import { coerceValue } from '../util/pluginUtils'
14
- import { variantPlugins, corePlugins } from '../corePlugins'
15
- import * as sharedState from './sharedState'
16
- import { env } from './sharedState'
17
- import { toPath } from '../util/toPath'
18
- import log from '../util/log'
19
- import negateValue from '../util/negateValue'
20
- import isSyntacticallyValidPropertyValue from '../util/isSyntacticallyValidPropertyValue'
21
- import { generateRules, getClassNameFromSelector } from './generateRules'
22
- import { hasContentChanged } from './cacheInvalidation.js'
23
- import { Offsets } from './offsets.js'
24
- import { finalizeSelector, formatVariantSelector } from '../util/formatVariantSelector'
25
-
26
- const VARIANT_TYPES = {
27
- AddVariant: Symbol.for('ADD_VARIANT'),
28
- MatchVariant: Symbol.for('MATCH_VARIANT'),
29
- }
30
-
31
- const VARIANT_INFO = {
32
- Base: 1 << 0,
33
- Dynamic: 1 << 1,
34
- }
35
-
36
- function prefix(context, selector) {
37
- let prefix = context.tailwindConfig.prefix
38
- return typeof prefix === 'function' ? prefix(selector) : prefix + selector
39
- }
40
-
41
- function normalizeOptionTypes({ type = 'any', ...options }) {
42
- let types = [].concat(type)
43
-
44
- return {
45
- ...options,
46
- types: types.map((type) => {
47
- if (Array.isArray(type)) {
48
- return { type: type[0], ...type[1] }
49
- }
50
- return { type, preferOnConflict: false }
51
- }),
52
- }
53
- }
54
-
55
- function parseVariantFormatString(input) {
56
- /** @type {string[]} */
57
- let parts = []
58
-
59
- // When parsing whitespace around special characters are insignificant
60
- // However, _inside_ of a variant they could be
61
- // Because the selector could look like this
62
- // @media { &[data-name="foo bar"] }
63
- // This is why we do not skip whitespace
64
-
65
- let current = ''
66
- let depth = 0
67
-
68
- for (let idx = 0; idx < input.length; idx++) {
69
- let char = input[idx]
70
-
71
- if (char === '\\') {
72
- // Escaped characters are not special
73
- current += '\\' + input[++idx]
74
- } else if (char === '{') {
75
- // Nested rule: start
76
- ++depth
77
- parts.push(current.trim())
78
- current = ''
79
- } else if (char === '}') {
80
- // Nested rule: end
81
- if (--depth < 0) {
82
- throw new Error(`Your { and } are unbalanced.`)
83
- }
84
-
85
- parts.push(current.trim())
86
- current = ''
87
- } else {
88
- // Normal character
89
- current += char
90
- }
91
- }
92
-
93
- if (current.length > 0) {
94
- parts.push(current.trim())
95
- }
96
-
97
- parts = parts.filter((part) => part !== '')
98
-
99
- return parts
100
- }
101
-
102
- function insertInto(list, value, { before = [] } = {}) {
103
- before = [].concat(before)
104
-
105
- if (before.length <= 0) {
106
- list.push(value)
107
- return
108
- }
109
-
110
- let idx = list.length - 1
111
- for (let other of before) {
112
- let iidx = list.indexOf(other)
113
- if (iidx === -1) continue
114
- idx = Math.min(idx, iidx)
115
- }
116
-
117
- list.splice(idx, 0, value)
118
- }
119
-
120
- function parseStyles(styles) {
121
- if (!Array.isArray(styles)) {
122
- return parseStyles([styles])
123
- }
124
-
125
- return styles.flatMap((style) => {
126
- let isNode = !Array.isArray(style) && !isPlainObject(style)
127
- return isNode ? style : parseObjectStyles(style)
128
- })
129
- }
130
-
131
- function getClasses(selector, mutate) {
132
- let parser = selectorParser((selectors) => {
133
- let allClasses = []
134
-
135
- if (mutate) {
136
- mutate(selectors)
137
- }
138
-
139
- selectors.walkClasses((classNode) => {
140
- allClasses.push(classNode.value)
141
- })
142
-
143
- return allClasses
144
- })
145
- return parser.transformSync(selector)
146
- }
147
-
148
- function extractCandidates(node, state = { containsNonOnDemandable: false }, depth = 0) {
149
- let classes = []
150
-
151
- // Handle normal rules
152
- if (node.type === 'rule') {
153
- // Ignore everything inside a :not(...). This allows you to write code like
154
- // `div:not(.foo)`. If `.foo` is never found in your code, then we used to
155
- // not generated it. But now we will ignore everything inside a `:not`, so
156
- // that it still gets generated.
157
- function ignoreNot(selectors) {
158
- selectors.walkPseudos((pseudo) => {
159
- if (pseudo.value === ':not') {
160
- pseudo.remove()
161
- }
162
- })
163
- }
164
-
165
- for (let selector of node.selectors) {
166
- let classCandidates = getClasses(selector, ignoreNot)
167
- // At least one of the selectors contains non-"on-demandable" candidates.
168
- if (classCandidates.length === 0) {
169
- state.containsNonOnDemandable = true
170
- }
171
-
172
- for (let classCandidate of classCandidates) {
173
- classes.push(classCandidate)
174
- }
175
- }
176
- }
177
-
178
- // Handle at-rules (which contains nested rules)
179
- else if (node.type === 'atrule') {
180
- node.walkRules((rule) => {
181
- for (let classCandidate of rule.selectors.flatMap((selector) => getClasses(selector))) {
182
- classes.push(classCandidate)
183
- }
184
- })
185
- }
186
-
187
- if (depth === 0) {
188
- return [state.containsNonOnDemandable || classes.length === 0, classes]
189
- }
190
-
191
- return classes
192
- }
193
-
194
- function withIdentifiers(styles) {
195
- return parseStyles(styles).flatMap((node) => {
196
- let nodeMap = new Map()
197
- let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node)
198
-
199
- // If this isn't "on-demandable", assign it a universal candidate to always include it.
200
- if (containsNonOnDemandableSelectors) {
201
- candidates.unshift(sharedState.NOT_ON_DEMAND)
202
- }
203
-
204
- // However, it could be that it also contains "on-demandable" candidates.
205
- // E.g.: `span, .foo {}`, in that case it should still be possible to use
206
- // `@apply foo` for example.
207
- return candidates.map((c) => {
208
- if (!nodeMap.has(node)) {
209
- nodeMap.set(node, node)
210
- }
211
- return [c, nodeMap.get(node)]
212
- })
213
- })
214
- }
215
-
216
- export function isValidVariantFormatString(format) {
217
- return format.startsWith('@') || format.includes('&')
218
- }
219
-
220
- export function parseVariant(variant) {
221
- variant = variant
222
- .replace(/\n+/g, '')
223
- .replace(/\s{1,}/g, ' ')
224
- .trim()
225
-
226
- let fns = parseVariantFormatString(variant)
227
- .map((str) => {
228
- if (!str.startsWith('@')) {
229
- return ({ format }) => format(str)
230
- }
231
-
232
- let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str)
233
- return ({ wrap }) => wrap(postcss.atRule({ name, params: params.trim() }))
234
- })
235
- .reverse()
236
-
237
- return (api) => {
238
- for (let fn of fns) {
239
- fn(api)
240
- }
241
- }
242
- }
243
-
244
- /**
245
- *
246
- * @param {any} tailwindConfig
247
- * @param {any} context
248
- * @param {object} param2
249
- * @param {Offsets} param2.offsets
250
- */
251
- function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
252
- function getConfigValue(path, defaultValue) {
253
- return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
254
- }
255
-
256
- function applyConfiguredPrefix(selector) {
257
- return prefixSelector(tailwindConfig.prefix, selector)
258
- }
259
-
260
- function prefixIdentifier(identifier, options) {
261
- if (identifier === sharedState.NOT_ON_DEMAND) {
262
- return sharedState.NOT_ON_DEMAND
263
- }
264
-
265
- if (!options.respectPrefix) {
266
- return identifier
267
- }
268
-
269
- return context.tailwindConfig.prefix + identifier
270
- }
271
-
272
- function resolveThemeValue(path, defaultValue, opts = {}) {
273
- let parts = toPath(path)
274
- let value = getConfigValue(['theme', ...parts], defaultValue)
275
- return transformThemeValue(parts[0])(value, opts)
276
- }
277
-
278
- let variantIdentifier = 0
279
- let api = {
280
- postcss,
281
- prefix: applyConfiguredPrefix,
282
- e: escapeClassName,
283
- config: getConfigValue,
284
- theme: resolveThemeValue,
285
- corePlugins: (path) => {
286
- if (Array.isArray(tailwindConfig.corePlugins)) {
287
- return tailwindConfig.corePlugins.includes(path)
288
- }
289
-
290
- return getConfigValue(['corePlugins', path], true)
291
- },
292
- variants: () => {
293
- // Preserved for backwards compatibility but not used in v3.0+
294
- return []
295
- },
296
- addBase(base) {
297
- for (let [identifier, rule] of withIdentifiers(base)) {
298
- let prefixedIdentifier = prefixIdentifier(identifier, {})
299
- let offset = offsets.create('base')
300
-
301
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
302
- context.candidateRuleMap.set(prefixedIdentifier, [])
303
- }
304
-
305
- context.candidateRuleMap
306
- .get(prefixedIdentifier)
307
- .push([{ sort: offset, layer: 'base' }, rule])
308
- }
309
- },
310
- /**
311
- * @param {string} group
312
- * @param {Record<string, string | string[]>} declarations
313
- */
314
- addDefaults(group, declarations) {
315
- const groups = {
316
- [`@defaults ${group}`]: declarations,
317
- }
318
-
319
- for (let [identifier, rule] of withIdentifiers(groups)) {
320
- let prefixedIdentifier = prefixIdentifier(identifier, {})
321
-
322
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
323
- context.candidateRuleMap.set(prefixedIdentifier, [])
324
- }
325
-
326
- context.candidateRuleMap
327
- .get(prefixedIdentifier)
328
- .push([{ sort: offsets.create('defaults'), layer: 'defaults' }, rule])
329
- }
330
- },
331
- addComponents(components, options) {
332
- let defaultOptions = {
333
- preserveSource: false,
334
- respectPrefix: true,
335
- respectImportant: false,
336
- }
337
-
338
- options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
339
-
340
- for (let [identifier, rule] of withIdentifiers(components)) {
341
- let prefixedIdentifier = prefixIdentifier(identifier, options)
342
-
343
- classList.add(prefixedIdentifier)
344
-
345
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
346
- context.candidateRuleMap.set(prefixedIdentifier, [])
347
- }
348
-
349
- context.candidateRuleMap
350
- .get(prefixedIdentifier)
351
- .push([{ sort: offsets.create('components'), layer: 'components', options }, rule])
352
- }
353
- },
354
- addUtilities(utilities, options) {
355
- let defaultOptions = {
356
- preserveSource: false,
357
- respectPrefix: true,
358
- respectImportant: true,
359
- }
360
-
361
- options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
362
-
363
- for (let [identifier, rule] of withIdentifiers(utilities)) {
364
- let prefixedIdentifier = prefixIdentifier(identifier, options)
365
-
366
- classList.add(prefixedIdentifier)
367
-
368
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
369
- context.candidateRuleMap.set(prefixedIdentifier, [])
370
- }
371
-
372
- context.candidateRuleMap
373
- .get(prefixedIdentifier)
374
- .push([{ sort: offsets.create('utilities'), layer: 'utilities', options }, rule])
375
- }
376
- },
377
- matchUtilities: function (utilities, options) {
378
- let defaultOptions = {
379
- respectPrefix: true,
380
- respectImportant: true,
381
- modifiers: false,
382
- }
383
-
384
- options = normalizeOptionTypes({ ...defaultOptions, ...options })
385
-
386
- let offset = offsets.create('utilities')
387
-
388
- for (let identifier in utilities) {
389
- let prefixedIdentifier = prefixIdentifier(identifier, options)
390
- let rule = utilities[identifier]
391
-
392
- classList.add([prefixedIdentifier, options])
393
-
394
- function wrapped(modifier, { isOnlyPlugin }) {
395
- let [value, coercedType, utilityModifier] = coerceValue(
396
- options.types,
397
- modifier,
398
- options,
399
- tailwindConfig
400
- )
401
-
402
- if (value === undefined) {
403
- return []
404
- }
405
-
406
- if (!options.types.some(({ type }) => type === coercedType)) {
407
- if (isOnlyPlugin) {
408
- log.warn([
409
- `Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
410
- `You can safely update it to \`${identifier}-${modifier.replace(
411
- coercedType + ':',
412
- ''
413
- )}\`.`,
414
- ])
415
- } else {
416
- return []
417
- }
418
- }
419
-
420
- if (!isSyntacticallyValidPropertyValue(value)) {
421
- return []
422
- }
423
-
424
- let extras = {
425
- get modifier() {
426
- if (!options.modifiers) {
427
- log.warn(`modifier-used-without-options-for-${identifier}`, [
428
- 'Your plugin must set `modifiers: true` in its options to support modifiers.',
429
- ])
430
- }
431
-
432
- return utilityModifier
433
- },
434
- }
435
-
436
- let ruleSets = []
437
- .concat(rule(value, extras))
438
- .filter(Boolean)
439
- .map((declaration) => ({
440
- [nameClass(identifier, modifier)]: declaration,
441
- }))
442
-
443
- return ruleSets
444
- }
445
-
446
- let withOffsets = [{ sort: offset, layer: 'utilities', options }, wrapped]
447
-
448
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
449
- context.candidateRuleMap.set(prefixedIdentifier, [])
450
- }
451
-
452
- context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
453
- }
454
- },
455
- matchComponents: function (components, options) {
456
- let defaultOptions = {
457
- respectPrefix: true,
458
- respectImportant: false,
459
- modifiers: false,
460
- }
461
-
462
- options = normalizeOptionTypes({ ...defaultOptions, ...options })
463
-
464
- let offset = offsets.create('components')
465
-
466
- for (let identifier in components) {
467
- let prefixedIdentifier = prefixIdentifier(identifier, options)
468
- let rule = components[identifier]
469
-
470
- classList.add([prefixedIdentifier, options])
471
-
472
- function wrapped(modifier, { isOnlyPlugin }) {
473
- let [value, coercedType, utilityModifier] = coerceValue(
474
- options.types,
475
- modifier,
476
- options,
477
- tailwindConfig
478
- )
479
-
480
- if (value === undefined) {
481
- return []
482
- }
483
-
484
- if (!options.types.some(({ type }) => type === coercedType)) {
485
- if (isOnlyPlugin) {
486
- log.warn([
487
- `Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
488
- `You can safely update it to \`${identifier}-${modifier.replace(
489
- coercedType + ':',
490
- ''
491
- )}\`.`,
492
- ])
493
- } else {
494
- return []
495
- }
496
- }
497
-
498
- if (!isSyntacticallyValidPropertyValue(value)) {
499
- return []
500
- }
501
-
502
- let extras = {
503
- get modifier() {
504
- if (!options.modifiers) {
505
- log.warn(`modifier-used-without-options-for-${identifier}`, [
506
- 'Your plugin must set `modifiers: true` in its options to support modifiers.',
507
- ])
508
- }
509
-
510
- return utilityModifier
511
- },
512
- }
513
-
514
- let ruleSets = []
515
- .concat(rule(value, extras))
516
- .filter(Boolean)
517
- .map((declaration) => ({
518
- [nameClass(identifier, modifier)]: declaration,
519
- }))
520
-
521
- return ruleSets
522
- }
523
-
524
- let withOffsets = [{ sort: offset, layer: 'components', options }, wrapped]
525
-
526
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
527
- context.candidateRuleMap.set(prefixedIdentifier, [])
528
- }
529
-
530
- context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
531
- }
532
- },
533
- addVariant(variantName, variantFunctions, options = {}) {
534
- variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
535
- if (typeof variantFunction !== 'string') {
536
- // Safelist public API functions
537
- return (api = {}) => {
538
- let { args, modifySelectors, container, separator, wrap, format } = api
539
- let result = variantFunction(
540
- Object.assign(
541
- { modifySelectors, container, separator },
542
- options.type === VARIANT_TYPES.MatchVariant && { args, wrap, format }
543
- )
544
- )
545
-
546
- if (typeof result === 'string' && !isValidVariantFormatString(result)) {
547
- throw new Error(
548
- `Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
549
- )
550
- }
551
-
552
- if (Array.isArray(result)) {
553
- return result
554
- .filter((variant) => typeof variant === 'string')
555
- .map((variant) => parseVariant(variant))
556
- }
557
-
558
- // result may be undefined with legacy variants that use APIs like `modifySelectors`
559
- // result may also be a postcss node if someone was returning the result from `modifySelectors`
560
- return result && typeof result === 'string' && parseVariant(result)(api)
561
- }
562
- }
563
-
564
- if (!isValidVariantFormatString(variantFunction)) {
565
- throw new Error(
566
- `Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
567
- )
568
- }
569
-
570
- return parseVariant(variantFunction)
571
- })
572
-
573
- insertInto(variantList, variantName, options)
574
- variantMap.set(variantName, variantFunctions)
575
- context.variantOptions.set(variantName, options)
576
- },
577
- matchVariant(variant, variantFn, options) {
578
- // A unique identifier that "groups" these variants together.
579
- // This is for internal use only which is why it is not present in the types
580
- let id = options?.id ?? ++variantIdentifier
581
- let isSpecial = variant === '@'
582
-
583
- for (let [key, value] of Object.entries(options?.values ?? {})) {
584
- if (key === 'DEFAULT') continue
585
-
586
- api.addVariant(
587
- isSpecial ? `${variant}${key}` : `${variant}-${key}`,
588
- ({ args, container }) => {
589
- return variantFn(value, { modifier: args?.modifier, container })
590
- },
591
-
592
- {
593
- ...options,
594
- value,
595
- id,
596
- type: VARIANT_TYPES.MatchVariant,
597
- variantInfo: VARIANT_INFO.Base,
598
- }
599
- )
600
- }
601
-
602
- let hasDefault = 'DEFAULT' in (options?.values ?? {})
603
-
604
- api.addVariant(
605
- variant,
606
- ({ args, container }) => {
607
- if (args?.value === sharedState.NONE && !hasDefault) {
608
- return null
609
- }
610
-
611
- return variantFn(
612
- args?.value === sharedState.NONE
613
- ? options.values.DEFAULT
614
- : // Falling back to args if it is a string, otherwise '' for older intellisense
615
- // (JetBrains) plugins.
616
- args?.value ?? (typeof args === 'string' ? args : ''),
617
- { modifier: args?.modifier, container }
618
- )
619
- },
620
- {
621
- ...options,
622
- id,
623
- type: VARIANT_TYPES.MatchVariant,
624
- variantInfo: VARIANT_INFO.Dynamic,
625
- }
626
- )
627
- },
628
- }
629
-
630
- return api
631
- }
632
-
633
- let fileModifiedMapCache = new WeakMap()
634
- export function getFileModifiedMap(context) {
635
- if (!fileModifiedMapCache.has(context)) {
636
- fileModifiedMapCache.set(context, new Map())
637
- }
638
- return fileModifiedMapCache.get(context)
639
- }
640
-
641
- function trackModified(files, fileModifiedMap) {
642
- let changed = false
643
- let mtimesToCommit = new Map()
644
-
645
- for (let file of files) {
646
- if (!file) continue
647
-
648
- let parsed = url.parse(file)
649
- let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href
650
- pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname
651
- let newModified = fs.statSync(decodeURIComponent(pathname), { throwIfNoEntry: false })?.mtimeMs
652
- if (!newModified) {
653
- // It could happen that a file is passed in that doesn't exist. E.g.:
654
- // postcss-cli will provide you a fake path when reading from stdin. This
655
- // path then looks like /path-to-your-project/stdin In that case we just
656
- // want to ignore it and don't track changes at all.
657
- continue
658
- }
659
-
660
- if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
661
- changed = true
662
- }
663
-
664
- mtimesToCommit.set(file, newModified)
665
- }
666
-
667
- return [changed, mtimesToCommit]
668
- }
669
-
670
- function extractVariantAtRules(node) {
671
- node.walkAtRules((atRule) => {
672
- if (['responsive', 'variants'].includes(atRule.name)) {
673
- extractVariantAtRules(atRule)
674
- atRule.before(atRule.nodes)
675
- atRule.remove()
676
- }
677
- })
678
- }
679
-
680
- function collectLayerPlugins(root) {
681
- let layerPlugins = []
682
-
683
- root.each((node) => {
684
- if (node.type === 'atrule' && ['responsive', 'variants'].includes(node.name)) {
685
- node.name = 'layer'
686
- node.params = 'utilities'
687
- }
688
- })
689
-
690
- // Walk @layer rules and treat them like plugins
691
- root.walkAtRules('layer', (layerRule) => {
692
- extractVariantAtRules(layerRule)
693
-
694
- if (layerRule.params === 'base') {
695
- for (let node of layerRule.nodes) {
696
- layerPlugins.push(function ({ addBase }) {
697
- addBase(node, { respectPrefix: false })
698
- })
699
- }
700
- layerRule.remove()
701
- } else if (layerRule.params === 'components') {
702
- for (let node of layerRule.nodes) {
703
- layerPlugins.push(function ({ addComponents }) {
704
- addComponents(node, { respectPrefix: false, preserveSource: true })
705
- })
706
- }
707
- layerRule.remove()
708
- } else if (layerRule.params === 'utilities') {
709
- for (let node of layerRule.nodes) {
710
- layerPlugins.push(function ({ addUtilities }) {
711
- addUtilities(node, { respectPrefix: false, preserveSource: true })
712
- })
713
- }
714
- layerRule.remove()
715
- }
716
- })
717
-
718
- return layerPlugins
719
- }
720
-
721
- function resolvePlugins(context, root) {
722
- let corePluginList = Object.entries(corePlugins)
723
- .map(([name, plugin]) => {
724
- if (!context.tailwindConfig.corePlugins.includes(name)) {
725
- return null
726
- }
727
-
728
- return plugin
729
- })
730
- .filter(Boolean)
731
-
732
- let userPlugins = context.tailwindConfig.plugins.map((plugin) => {
733
- if (plugin.__isOptionsFunction) {
734
- plugin = plugin()
735
- }
736
-
737
- return typeof plugin === 'function' ? plugin : plugin.handler
738
- })
739
-
740
- let layerPlugins = collectLayerPlugins(root)
741
-
742
- // TODO: This is a workaround for backwards compatibility, since custom variants
743
- // were historically sorted before screen/stackable variants.
744
- let beforeVariants = [
745
- variantPlugins['pseudoElementVariants'],
746
- variantPlugins['pseudoClassVariants'],
747
- variantPlugins['hasVariants'],
748
- variantPlugins['ariaVariants'],
749
- variantPlugins['dataVariants'],
750
- ]
751
- let afterVariants = [
752
- variantPlugins['supportsVariants'],
753
- variantPlugins['directionVariants'],
754
- variantPlugins['reducedMotionVariants'],
755
- variantPlugins['prefersContrastVariants'],
756
- variantPlugins['darkVariants'],
757
- variantPlugins['printVariant'],
758
- variantPlugins['screenVariants'],
759
- variantPlugins['orientationVariants'],
760
- ]
761
-
762
- return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
763
- }
764
-
765
- function registerPlugins(plugins, context) {
766
- let variantList = []
767
- let variantMap = new Map()
768
- context.variantMap = variantMap
769
-
770
- let offsets = new Offsets()
771
- context.offsets = offsets
772
-
773
- let classList = new Set()
774
-
775
- let pluginApi = buildPluginApi(context.tailwindConfig, context, {
776
- variantList,
777
- variantMap,
778
- offsets,
779
- classList,
780
- })
781
-
782
- for (let plugin of plugins) {
783
- if (Array.isArray(plugin)) {
784
- for (let pluginItem of plugin) {
785
- pluginItem(pluginApi)
786
- }
787
- } else {
788
- plugin?.(pluginApi)
789
- }
790
- }
791
-
792
- // Make sure to record bit masks for every variant
793
- offsets.recordVariants(variantList, (variant) => variantMap.get(variant).length)
794
-
795
- // Build variantMap
796
- for (let [variantName, variantFunctions] of variantMap.entries()) {
797
- context.variantMap.set(
798
- variantName,
799
- variantFunctions.map((variantFunction, idx) => [
800
- offsets.forVariant(variantName, idx),
801
- variantFunction,
802
- ])
803
- )
804
- }
805
-
806
- let safelist = (context.tailwindConfig.safelist ?? []).filter(Boolean)
807
- if (safelist.length > 0) {
808
- let checks = []
809
-
810
- for (let value of safelist) {
811
- if (typeof value === 'string') {
812
- context.changedContent.push({ content: value, extension: 'html' })
813
- continue
814
- }
815
-
816
- if (value instanceof RegExp) {
817
- log.warn('root-regex', [
818
- 'Regular expressions in `safelist` work differently in Tailwind CSS v3.0.',
819
- 'Update your `safelist` configuration to eliminate this warning.',
820
- 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
821
- ])
822
- continue
823
- }
824
-
825
- checks.push(value)
826
- }
827
-
828
- if (checks.length > 0) {
829
- let patternMatchingCount = new Map()
830
- let prefixLength = context.tailwindConfig.prefix.length
831
- let checkImportantUtils = checks.some((check) => check.pattern.source.includes('!'))
832
-
833
- for (let util of classList) {
834
- let utils = Array.isArray(util)
835
- ? (() => {
836
- let [utilName, options] = util
837
- let values = Object.keys(options?.values ?? {})
838
- let classes = values.map((value) => formatClass(utilName, value))
839
-
840
- if (options?.supportsNegativeValues) {
841
- // This is the normal negated version
842
- // e.g. `-inset-1` or `-tw-inset-1`
843
- classes = [...classes, ...classes.map((cls) => '-' + cls)]
844
-
845
- // This is the negated version *after* the prefix
846
- // e.g. `tw--inset-1`
847
- // The prefix is already attached to util name
848
- // So we add the negative after the prefix
849
- classes = [
850
- ...classes,
851
- ...classes.map(
852
- (cls) => cls.slice(0, prefixLength) + '-' + cls.slice(prefixLength)
853
- ),
854
- ]
855
- }
856
-
857
- if (options.types.some(({ type }) => type === 'color')) {
858
- classes = [
859
- ...classes,
860
- ...classes.flatMap((cls) =>
861
- Object.keys(context.tailwindConfig.theme.opacity).map(
862
- (opacity) => `${cls}/${opacity}`
863
- )
864
- ),
865
- ]
866
- }
867
-
868
- if (checkImportantUtils && options?.respectImportant) {
869
- classes = [...classes, ...classes.map((cls) => '!' + cls)]
870
- }
871
-
872
- return classes
873
- })()
874
- : [util]
875
-
876
- for (let util of utils) {
877
- for (let { pattern, variants = [] } of checks) {
878
- // RegExp with the /g flag are stateful, so let's reset the last
879
- // index pointer to reset the state.
880
- pattern.lastIndex = 0
881
-
882
- if (!patternMatchingCount.has(pattern)) {
883
- patternMatchingCount.set(pattern, 0)
884
- }
885
-
886
- if (!pattern.test(util)) continue
887
-
888
- patternMatchingCount.set(pattern, patternMatchingCount.get(pattern) + 1)
889
-
890
- context.changedContent.push({ content: util, extension: 'html' })
891
- for (let variant of variants) {
892
- context.changedContent.push({
893
- content: variant + context.tailwindConfig.separator + util,
894
- extension: 'html',
895
- })
896
- }
897
- }
898
- }
899
- }
900
-
901
- for (let [regex, count] of patternMatchingCount.entries()) {
902
- if (count !== 0) continue
903
-
904
- log.warn([
905
- `The safelist pattern \`${regex}\` doesn't match any Tailwind CSS classes.`,
906
- 'Fix this pattern or remove it from your `safelist` configuration.',
907
- 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
908
- ])
909
- }
910
- }
911
- }
912
-
913
- let darkClassName = [].concat(context.tailwindConfig.darkMode ?? 'media')[1] ?? 'dark'
914
-
915
- // A list of utilities that are used by certain Tailwind CSS utilities but
916
- // that don't exist on their own. This will result in them "not existing" and
917
- // sorting could be weird since you still require them in order to make the
918
- // host utilities work properly. (Thanks Biology)
919
- let parasiteUtilities = [
920
- prefix(context, darkClassName),
921
- prefix(context, 'group'),
922
- prefix(context, 'peer'),
923
- ]
924
- context.getClassOrder = function getClassOrder(classes) {
925
- // Sort classes so they're ordered in a deterministic manner
926
- let sorted = [...classes].sort((a, z) => {
927
- if (a === z) return 0
928
- if (a < z) return -1
929
- return 1
930
- })
931
-
932
- // Non-util classes won't be generated, so we default them to null
933
- let sortedClassNames = new Map(sorted.map((className) => [className, null]))
934
-
935
- // Sort all classes in order
936
- // Non-tailwind classes won't be generated and will be left as `null`
937
- let rules = generateRules(new Set(sorted), context)
938
- rules = context.offsets.sort(rules)
939
-
940
- let idx = BigInt(parasiteUtilities.length)
941
-
942
- for (const [, rule] of rules) {
943
- sortedClassNames.set(rule.raws.tailwind.candidate, idx++)
944
- }
945
-
946
- return classes.map((className) => {
947
- let order = sortedClassNames.get(className) ?? null
948
- let parasiteIndex = parasiteUtilities.indexOf(className)
949
-
950
- if (order === null && parasiteIndex !== -1) {
951
- // This will make sure that it is at the very beginning of the
952
- // `components` layer which technically means 'before any
953
- // components'.
954
- order = BigInt(parasiteIndex)
955
- }
956
-
957
- return [className, order]
958
- })
959
- }
960
-
961
- // Generate a list of strings for autocompletion purposes, e.g.
962
- // ['uppercase', 'lowercase', ...]
963
- context.getClassList = function getClassList(options = {}) {
964
- let output = []
965
-
966
- for (let util of classList) {
967
- if (Array.isArray(util)) {
968
- let [utilName, utilOptions] = util
969
- let negativeClasses = []
970
-
971
- let modifiers = Object.keys(utilOptions?.modifiers ?? {})
972
-
973
- if (utilOptions?.types?.some(({ type }) => type === 'color')) {
974
- modifiers.push(...Object.keys(context.tailwindConfig.theme.opacity ?? {}))
975
- }
976
-
977
- let metadata = { modifiers }
978
- let includeMetadata = options.includeMetadata && modifiers.length > 0
979
-
980
- for (let [key, value] of Object.entries(utilOptions?.values ?? {})) {
981
- // Ignore undefined and null values
982
- if (value == null) {
983
- continue
984
- }
985
-
986
- let cls = formatClass(utilName, key)
987
- output.push(includeMetadata ? [cls, metadata] : cls)
988
-
989
- if (utilOptions?.supportsNegativeValues && negateValue(value)) {
990
- let cls = formatClass(utilName, `-${key}`)
991
- negativeClasses.push(includeMetadata ? [cls, metadata] : cls)
992
- }
993
- }
994
-
995
- output.push(...negativeClasses)
996
- } else {
997
- output.push(util)
998
- }
999
- }
1000
-
1001
- return output
1002
- }
1003
-
1004
- // Generate a list of available variants with meta information of the type of variant.
1005
- context.getVariants = function getVariants() {
1006
- let result = []
1007
- for (let [name, options] of context.variantOptions.entries()) {
1008
- if (options.variantInfo === VARIANT_INFO.Base) continue
1009
-
1010
- result.push({
1011
- name,
1012
- isArbitrary: options.type === Symbol.for('MATCH_VARIANT'),
1013
- values: Object.keys(options.values ?? {}),
1014
- hasDash: name !== '@',
1015
- selectors({ modifier, value } = {}) {
1016
- let candidate = '__TAILWIND_PLACEHOLDER__'
1017
-
1018
- let rule = postcss.rule({ selector: `.${candidate}` })
1019
- let container = postcss.root({ nodes: [rule.clone()] })
1020
-
1021
- let before = container.toString()
1022
-
1023
- let fns = (context.variantMap.get(name) ?? []).flatMap(([_, fn]) => fn)
1024
- let formatStrings = []
1025
- for (let fn of fns) {
1026
- let localFormatStrings = []
1027
-
1028
- let api = {
1029
- args: { modifier, value: options.values?.[value] ?? value },
1030
- separator: context.tailwindConfig.separator,
1031
- modifySelectors(modifierFunction) {
1032
- // Run the modifierFunction over each rule
1033
- container.each((rule) => {
1034
- if (rule.type !== 'rule') {
1035
- return
1036
- }
1037
-
1038
- rule.selectors = rule.selectors.map((selector) => {
1039
- return modifierFunction({
1040
- get className() {
1041
- return getClassNameFromSelector(selector)
1042
- },
1043
- selector,
1044
- })
1045
- })
1046
- })
1047
-
1048
- return container
1049
- },
1050
- format(str) {
1051
- localFormatStrings.push(str)
1052
- },
1053
- wrap(wrapper) {
1054
- localFormatStrings.push(`@${wrapper.name} ${wrapper.params} { & }`)
1055
- },
1056
- container,
1057
- }
1058
-
1059
- let ruleWithVariant = fn(api)
1060
- if (localFormatStrings.length > 0) {
1061
- formatStrings.push(localFormatStrings)
1062
- }
1063
-
1064
- if (Array.isArray(ruleWithVariant)) {
1065
- for (let variantFunction of ruleWithVariant) {
1066
- localFormatStrings = []
1067
- variantFunction(api)
1068
- formatStrings.push(localFormatStrings)
1069
- }
1070
- }
1071
- }
1072
-
1073
- // Reverse engineer the result of the `container`
1074
- let manualFormatStrings = []
1075
- let after = container.toString()
1076
-
1077
- if (before !== after) {
1078
- // Figure out all selectors
1079
- container.walkRules((rule) => {
1080
- let modified = rule.selector
1081
-
1082
- // Rebuild the base selector, this is what plugin authors would do
1083
- // as well. E.g.: `${variant}${separator}${className}`.
1084
- // However, plugin authors probably also prepend or append certain
1085
- // classes, pseudos, ids, ...
1086
- let rebuiltBase = selectorParser((selectors) => {
1087
- selectors.walkClasses((classNode) => {
1088
- classNode.value = `${name}${context.tailwindConfig.separator}${classNode.value}`
1089
- })
1090
- }).processSync(modified)
1091
-
1092
- // Now that we know the original selector, the new selector, and
1093
- // the rebuild part in between, we can replace the part that plugin
1094
- // authors need to rebuild with `&`, and eventually store it in the
1095
- // collectedFormats. Similar to what `format('...')` would do.
1096
- //
1097
- // E.g.:
1098
- // variant: foo
1099
- // selector: .markdown > p
1100
- // modified (by plugin): .foo .foo\\:markdown > p
1101
- // rebuiltBase (internal): .foo\\:markdown > p
1102
- // format: .foo &
1103
- manualFormatStrings.push(modified.replace(rebuiltBase, '&').replace(candidate, '&'))
1104
- })
1105
-
1106
- // Figure out all atrules
1107
- container.walkAtRules((atrule) => {
1108
- manualFormatStrings.push(`@${atrule.name} (${atrule.params}) { & }`)
1109
- })
1110
- }
1111
-
1112
- let isArbitraryVariant = !(value in (options.values ?? {}))
1113
-
1114
- formatStrings = formatStrings.map((format) =>
1115
- format.map((str) => ({
1116
- format: str,
1117
- isArbitraryVariant,
1118
- }))
1119
- )
1120
-
1121
- manualFormatStrings = manualFormatStrings.map((format) => ({
1122
- format,
1123
- isArbitraryVariant,
1124
- }))
1125
-
1126
- let opts = {
1127
- candidate,
1128
- context,
1129
- }
1130
-
1131
- let result = formatStrings.map((formats) =>
1132
- finalizeSelector(`.${candidate}`, formatVariantSelector(formats, opts), opts)
1133
- .replace(`.${candidate}`, '&')
1134
- .replace('{ & }', '')
1135
- .trim()
1136
- )
1137
-
1138
- if (manualFormatStrings.length > 0) {
1139
- result.push(
1140
- formatVariantSelector(manualFormatStrings, opts)
1141
- .toString()
1142
- .replace(`.${candidate}`, '&')
1143
- )
1144
- }
1145
-
1146
- return result
1147
- },
1148
- })
1149
- }
1150
-
1151
- return result
1152
- }
1153
- }
1154
-
1155
- /**
1156
- * Mark as class as retroactively invalid
1157
- *
1158
- *
1159
- * @param {string} candidate
1160
- */
1161
- function markInvalidUtilityCandidate(context, candidate) {
1162
- if (!context.classCache.has(candidate)) {
1163
- return
1164
- }
1165
-
1166
- // Mark this as not being a real utility
1167
- context.notClassCache.add(candidate)
1168
-
1169
- // Remove it from any candidate-specific caches
1170
- context.classCache.delete(candidate)
1171
- context.applyClassCache.delete(candidate)
1172
- context.candidateRuleMap.delete(candidate)
1173
- context.candidateRuleCache.delete(candidate)
1174
-
1175
- // Ensure the stylesheet gets rebuilt
1176
- context.stylesheetCache = null
1177
- }
1178
-
1179
- /**
1180
- * Mark as class as retroactively invalid
1181
- *
1182
- * @param {import('postcss').Node} node
1183
- */
1184
- function markInvalidUtilityNode(context, node) {
1185
- let candidate = node.raws.tailwind.candidate
1186
-
1187
- if (!candidate) {
1188
- return
1189
- }
1190
-
1191
- for (const entry of context.ruleCache) {
1192
- if (entry[1].raws.tailwind.candidate === candidate) {
1193
- context.ruleCache.delete(entry)
1194
- // context.postCssNodeCache.delete(node)
1195
- }
1196
- }
1197
-
1198
- markInvalidUtilityCandidate(context, candidate)
1199
- }
1200
-
1201
- export function createContext(tailwindConfig, changedContent = [], root = postcss.root()) {
1202
- let context = {
1203
- disposables: [],
1204
- ruleCache: new Set(),
1205
- candidateRuleCache: new Map(),
1206
- classCache: new Map(),
1207
- applyClassCache: new Map(),
1208
- // Seed the not class cache with the blocklist (which is only strings)
1209
- notClassCache: new Set(tailwindConfig.blocklist ?? []),
1210
- postCssNodeCache: new Map(),
1211
- candidateRuleMap: new Map(),
1212
- tailwindConfig,
1213
- changedContent: changedContent,
1214
- variantMap: new Map(),
1215
- stylesheetCache: null,
1216
- variantOptions: new Map(),
1217
-
1218
- markInvalidUtilityCandidate: (candidate) => markInvalidUtilityCandidate(context, candidate),
1219
- markInvalidUtilityNode: (node) => markInvalidUtilityNode(context, node),
1220
- }
1221
-
1222
- let resolvedPlugins = resolvePlugins(context, root)
1223
- registerPlugins(resolvedPlugins, context)
1224
-
1225
- return context
1226
- }
1227
-
1228
- let contextMap = sharedState.contextMap
1229
- let configContextMap = sharedState.configContextMap
1230
- let contextSourcesMap = sharedState.contextSourcesMap
1231
-
1232
- export function getContext(
1233
- root,
1234
- result,
1235
- tailwindConfig,
1236
- userConfigPath,
1237
- tailwindConfigHash,
1238
- contextDependencies
1239
- ) {
1240
- let sourcePath = result.opts.from
1241
- let isConfigFile = userConfigPath !== null
1242
-
1243
- env.DEBUG && console.log('Source path:', sourcePath)
1244
-
1245
- let existingContext
1246
-
1247
- if (isConfigFile && contextMap.has(sourcePath)) {
1248
- existingContext = contextMap.get(sourcePath)
1249
- } else if (configContextMap.has(tailwindConfigHash)) {
1250
- let context = configContextMap.get(tailwindConfigHash)
1251
- contextSourcesMap.get(context).add(sourcePath)
1252
- contextMap.set(sourcePath, context)
1253
-
1254
- existingContext = context
1255
- }
1256
-
1257
- let cssDidChange = hasContentChanged(sourcePath, root)
1258
-
1259
- // If there's already a context in the cache and we don't need to
1260
- // reset the context, return the cached context.
1261
- if (existingContext) {
1262
- let [contextDependenciesChanged, mtimesToCommit] = trackModified(
1263
- [...contextDependencies],
1264
- getFileModifiedMap(existingContext)
1265
- )
1266
- if (!contextDependenciesChanged && !cssDidChange) {
1267
- return [existingContext, false, mtimesToCommit]
1268
- }
1269
- }
1270
-
1271
- // If this source is in the context map, get the old context.
1272
- // Remove this source from the context sources for the old context,
1273
- // and clean up that context if no one else is using it. This can be
1274
- // called by many processes in rapid succession, so we check for presence
1275
- // first because the first process to run this code will wipe it out first.
1276
- if (contextMap.has(sourcePath)) {
1277
- let oldContext = contextMap.get(sourcePath)
1278
- if (contextSourcesMap.has(oldContext)) {
1279
- contextSourcesMap.get(oldContext).delete(sourcePath)
1280
- if (contextSourcesMap.get(oldContext).size === 0) {
1281
- contextSourcesMap.delete(oldContext)
1282
- for (let [tailwindConfigHash, context] of configContextMap) {
1283
- if (context === oldContext) {
1284
- configContextMap.delete(tailwindConfigHash)
1285
- }
1286
- }
1287
- for (let disposable of oldContext.disposables.splice(0)) {
1288
- disposable(oldContext)
1289
- }
1290
- }
1291
- }
1292
- }
1293
-
1294
- env.DEBUG && console.log('Setting up new context...')
1295
-
1296
- let context = createContext(tailwindConfig, [], root)
1297
-
1298
- Object.assign(context, {
1299
- userConfigPath,
1300
- })
1301
-
1302
- let [, mtimesToCommit] = trackModified([...contextDependencies], getFileModifiedMap(context))
1303
-
1304
- // ---
1305
-
1306
- // Update all context tracking state
1307
-
1308
- configContextMap.set(tailwindConfigHash, context)
1309
- contextMap.set(sourcePath, context)
1310
-
1311
- if (!contextSourcesMap.has(context)) {
1312
- contextSourcesMap.set(context, new Set())
1313
- }
1314
-
1315
- contextSourcesMap.get(context).add(sourcePath)
1316
-
1317
- return [context, true, mtimesToCommit]
1318
- }