tailwindcss 0.0.0-insiders.d58d5b2 → 0.0.0-insiders.d593a21

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