tailwindcss 0.0.0-insiders.bf28bf6 → 0.0.0-insiders.bf2e2fe

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