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

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