tailwindcss 0.0.0-insiders.bb4f5da → 0.0.0-insiders.bbc2f3f

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 (215) hide show
  1. package/README.md +16 -13
  2. package/dist/chunk-5C7JPVMO.mjs +10 -0
  3. package/dist/chunk-AZANAYY2.mjs +1 -0
  4. package/dist/chunk-V2K3XTS4.mjs +1 -0
  5. package/dist/colors-b_6i0Oi7.d.ts +295 -0
  6. package/dist/colors.d.mts +295 -0
  7. package/dist/colors.d.ts +5 -0
  8. package/dist/colors.js +1 -0
  9. package/dist/colors.mjs +1 -0
  10. package/dist/default-theme.d.mts +1147 -0
  11. package/dist/default-theme.d.ts +1147 -0
  12. package/dist/default-theme.js +1 -0
  13. package/dist/default-theme.mjs +1 -0
  14. package/dist/flatten-color-palette.d.mts +6 -0
  15. package/dist/flatten-color-palette.d.ts +6 -0
  16. package/dist/flatten-color-palette.js +1 -0
  17. package/dist/flatten-color-palette.mjs +1 -0
  18. package/dist/lib.d.mts +260 -0
  19. package/dist/lib.d.ts +3 -0
  20. package/dist/lib.js +33 -0
  21. package/dist/lib.mjs +24 -0
  22. package/dist/plugin.d.mts +11 -0
  23. package/dist/plugin.d.ts +104 -0
  24. package/dist/plugin.js +1 -0
  25. package/dist/plugin.mjs +1 -0
  26. package/dist/resolve-config-BIFUA2FY.d.ts +29 -0
  27. package/dist/resolve-config-QUZ9b-Gn.d.mts +190 -0
  28. package/dist/types-B254mqw1.d.mts +98 -0
  29. package/index.css +865 -0
  30. package/package.json +73 -98
  31. package/preflight.css +383 -0
  32. package/theme.css +453 -0
  33. package/CHANGELOG.md +0 -2130
  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 -3
  41. package/defaultTheme.js +0 -2
  42. package/lib/cli-peer-dependencies.js +0 -16
  43. package/lib/cli.js +0 -798
  44. package/lib/constants.js +0 -37
  45. package/lib/corePluginList.js +0 -179
  46. package/lib/corePlugins.js +0 -3634
  47. package/lib/css/LICENSE +0 -25
  48. package/lib/css/preflight.css +0 -360
  49. package/lib/featureFlags.js +0 -59
  50. package/lib/index.js +0 -41
  51. package/lib/lib/cacheInvalidation.js +0 -69
  52. package/lib/lib/collapseAdjacentRules.js +0 -57
  53. package/lib/lib/collapseDuplicateDeclarations.js +0 -80
  54. package/lib/lib/defaultExtractor.js +0 -171
  55. package/lib/lib/detectNesting.js +0 -34
  56. package/lib/lib/evaluateTailwindFunctions.js +0 -171
  57. package/lib/lib/expandApplyAtRules.js +0 -485
  58. package/lib/lib/expandTailwindAtRules.js +0 -262
  59. package/lib/lib/generateRules.js +0 -672
  60. package/lib/lib/getModuleDependencies.js +0 -48
  61. package/lib/lib/normalizeTailwindDirectives.js +0 -84
  62. package/lib/lib/partitionApplyAtRules.js +0 -53
  63. package/lib/lib/regex.js +0 -53
  64. package/lib/lib/resolveDefaultsAtRules.js +0 -143
  65. package/lib/lib/setupContextUtils.js +0 -908
  66. package/lib/lib/setupTrackingContext.js +0 -174
  67. package/lib/lib/sharedState.js +0 -52
  68. package/lib/lib/substituteScreenAtRules.js +0 -27
  69. package/lib/postcss-plugins/nesting/README.md +0 -42
  70. package/lib/postcss-plugins/nesting/index.js +0 -17
  71. package/lib/postcss-plugins/nesting/plugin.js +0 -85
  72. package/lib/processTailwindFeatures.js +0 -59
  73. package/lib/public/colors.js +0 -329
  74. package/lib/public/create-plugin.js +0 -13
  75. package/lib/public/default-config.js +0 -14
  76. package/lib/public/default-theme.js +0 -14
  77. package/lib/public/resolve-config.js +0 -19
  78. package/lib/util/bigSign.js +0 -8
  79. package/lib/util/buildMediaQuery.js +0 -20
  80. package/lib/util/cloneDeep.js +0 -19
  81. package/lib/util/cloneNodes.js +0 -25
  82. package/lib/util/color.js +0 -95
  83. package/lib/util/configurePlugins.js +0 -18
  84. package/lib/util/createPlugin.js +0 -29
  85. package/lib/util/createUtilityPlugin.js +0 -49
  86. package/lib/util/dataTypes.js +0 -242
  87. package/lib/util/defaults.js +0 -22
  88. package/lib/util/escapeClassName.js +0 -19
  89. package/lib/util/escapeCommas.js +0 -8
  90. package/lib/util/flattenColorPalette.js +0 -17
  91. package/lib/util/formatVariantSelector.js +0 -196
  92. package/lib/util/getAllConfigs.js +0 -29
  93. package/lib/util/hashConfig.js +0 -16
  94. package/lib/util/isKeyframeRule.js +0 -8
  95. package/lib/util/isPlainObject.js +0 -12
  96. package/lib/util/isValidArbitraryValue.js +0 -64
  97. package/lib/util/log.js +0 -51
  98. package/lib/util/nameClass.js +0 -32
  99. package/lib/util/negateValue.js +0 -19
  100. package/lib/util/normalizeConfig.js +0 -233
  101. package/lib/util/normalizeScreens.js +0 -59
  102. package/lib/util/parseAnimationValue.js +0 -89
  103. package/lib/util/parseBoxShadowValue.js +0 -76
  104. package/lib/util/parseDependency.js +0 -63
  105. package/lib/util/parseObjectStyles.js +0 -31
  106. package/lib/util/pluginUtils.js +0 -179
  107. package/lib/util/prefixSelector.js +0 -20
  108. package/lib/util/resolveConfig.js +0 -255
  109. package/lib/util/resolveConfigPath.js +0 -51
  110. package/lib/util/responsive.js +0 -19
  111. package/lib/util/splitAtTopLevelOnly.js +0 -72
  112. package/lib/util/tap.js +0 -9
  113. package/lib/util/toColorValue.js +0 -8
  114. package/lib/util/toPath.js +0 -14
  115. package/lib/util/transformThemeValue.js +0 -59
  116. package/lib/util/validateConfig.js +0 -21
  117. package/lib/util/withAlphaVariable.js +0 -67
  118. package/nesting/index.js +0 -2
  119. package/peers/index.js +0 -75881
  120. package/plugin.d.ts +0 -6
  121. package/plugin.js +0 -2
  122. package/prettier.config.js +0 -19
  123. package/resolveConfig.js +0 -2
  124. package/screens.css +0 -1
  125. package/scripts/create-plugin-list.js +0 -10
  126. package/scripts/generate-types.js +0 -52
  127. package/scripts/install-integrations.js +0 -27
  128. package/scripts/rebuildFixtures.js +0 -68
  129. package/src/cli-peer-dependencies.js +0 -11
  130. package/src/cli.js +0 -883
  131. package/src/constants.js +0 -17
  132. package/src/corePluginList.js +0 -1
  133. package/src/corePlugins.js +0 -2409
  134. package/src/css/LICENSE +0 -25
  135. package/src/css/preflight.css +0 -360
  136. package/src/featureFlags.js +0 -54
  137. package/src/index.js +0 -42
  138. package/src/lib/cacheInvalidation.js +0 -52
  139. package/src/lib/collapseAdjacentRules.js +0 -58
  140. package/src/lib/collapseDuplicateDeclarations.js +0 -93
  141. package/src/lib/defaultExtractor.js +0 -180
  142. package/src/lib/detectNesting.js +0 -39
  143. package/src/lib/evaluateTailwindFunctions.js +0 -198
  144. package/src/lib/expandApplyAtRules.js +0 -539
  145. package/src/lib/expandTailwindAtRules.js +0 -292
  146. package/src/lib/generateRules.js +0 -672
  147. package/src/lib/getModuleDependencies.js +0 -39
  148. package/src/lib/normalizeTailwindDirectives.js +0 -84
  149. package/src/lib/partitionApplyAtRules.js +0 -52
  150. package/src/lib/regex.js +0 -74
  151. package/src/lib/resolveDefaultsAtRules.js +0 -146
  152. package/src/lib/setupContextUtils.js +0 -945
  153. package/src/lib/setupTrackingContext.js +0 -187
  154. package/src/lib/sharedState.js +0 -48
  155. package/src/lib/substituteScreenAtRules.js +0 -19
  156. package/src/postcss-plugins/nesting/README.md +0 -42
  157. package/src/postcss-plugins/nesting/index.js +0 -13
  158. package/src/postcss-plugins/nesting/plugin.js +0 -80
  159. package/src/processTailwindFeatures.js +0 -58
  160. package/src/public/colors.js +0 -300
  161. package/src/public/create-plugin.js +0 -2
  162. package/src/public/default-config.js +0 -4
  163. package/src/public/default-theme.js +0 -4
  164. package/src/public/resolve-config.js +0 -7
  165. package/src/util/bigSign.js +0 -3
  166. package/src/util/buildMediaQuery.js +0 -20
  167. package/src/util/cloneDeep.js +0 -11
  168. package/src/util/cloneNodes.js +0 -24
  169. package/src/util/color.js +0 -73
  170. package/src/util/configurePlugins.js +0 -23
  171. package/src/util/createPlugin.js +0 -27
  172. package/src/util/createUtilityPlugin.js +0 -37
  173. package/src/util/dataTypes.js +0 -256
  174. package/src/util/defaults.js +0 -17
  175. package/src/util/escapeClassName.js +0 -8
  176. package/src/util/escapeCommas.js +0 -3
  177. package/src/util/flattenColorPalette.js +0 -13
  178. package/src/util/formatVariantSelector.js +0 -207
  179. package/src/util/getAllConfigs.js +0 -19
  180. package/src/util/hashConfig.js +0 -5
  181. package/src/util/isKeyframeRule.js +0 -3
  182. package/src/util/isPlainObject.js +0 -8
  183. package/src/util/isValidArbitraryValue.js +0 -61
  184. package/src/util/log.js +0 -29
  185. package/src/util/nameClass.js +0 -26
  186. package/src/util/negateValue.js +0 -16
  187. package/src/util/normalizeConfig.js +0 -262
  188. package/src/util/normalizeScreens.js +0 -45
  189. package/src/util/parseAnimationValue.js +0 -68
  190. package/src/util/parseBoxShadowValue.js +0 -72
  191. package/src/util/parseDependency.js +0 -49
  192. package/src/util/parseObjectStyles.js +0 -19
  193. package/src/util/pluginUtils.js +0 -192
  194. package/src/util/prefixSelector.js +0 -14
  195. package/src/util/resolveConfig.js +0 -269
  196. package/src/util/resolveConfigPath.js +0 -55
  197. package/src/util/responsive.js +0 -10
  198. package/src/util/splitAtTopLevelOnly.js +0 -71
  199. package/src/util/tap.js +0 -4
  200. package/src/util/toColorValue.js +0 -3
  201. package/src/util/toPath.js +0 -26
  202. package/src/util/transformThemeValue.js +0 -52
  203. package/src/util/validateConfig.js +0 -13
  204. package/src/util/withAlphaVariable.js +0 -49
  205. package/stubs/defaultConfig.stub.js +0 -953
  206. package/stubs/defaultPostCssConfig.stub.js +0 -6
  207. package/stubs/simpleConfig.stub.js +0 -7
  208. package/tailwind.css +0 -5
  209. package/types/config.d.ts +0 -323
  210. package/types/generated/.gitkeep +0 -0
  211. package/types/generated/colors.d.ts +0 -276
  212. package/types/generated/corePluginList.d.ts +0 -1
  213. package/types/index.d.ts +0 -1
  214. package/types.d.ts +0 -1
  215. package/variants.css +0 -1
@@ -1,945 +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 bigSign from '../util/bigSign'
15
- import { variantPlugins, corePlugins } from '../corePlugins'
16
- import * as sharedState from './sharedState'
17
- import { env } from './sharedState'
18
- import { toPath } from '../util/toPath'
19
- import log from '../util/log'
20
- import negateValue from '../util/negateValue'
21
- import isValidArbitraryValue from '../util/isValidArbitraryValue'
22
- import { generateRules } from './generateRules'
23
- import { hasContentChanged } from './cacheInvalidation.js'
24
-
25
- let MATCH_VARIANT = Symbol()
26
-
27
- function prefix(context, selector) {
28
- let prefix = context.tailwindConfig.prefix
29
- return typeof prefix === 'function' ? prefix(selector) : prefix + selector
30
- }
31
-
32
- function parseVariantFormatString(input) {
33
- if (input.includes('{')) {
34
- if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`)
35
-
36
- return input
37
- .split(/{(.*)}/gim)
38
- .flatMap((line) => parseVariantFormatString(line))
39
- .filter(Boolean)
40
- }
41
-
42
- return [input.trim()]
43
- }
44
-
45
- function isBalanced(input) {
46
- let count = 0
47
-
48
- for (let char of input) {
49
- if (char === '{') {
50
- count++
51
- } else if (char === '}') {
52
- if (--count < 0) {
53
- return false // unbalanced
54
- }
55
- }
56
- }
57
-
58
- return count === 0
59
- }
60
-
61
- function insertInto(list, value, { before = [] } = {}) {
62
- before = [].concat(before)
63
-
64
- if (before.length <= 0) {
65
- list.push(value)
66
- return
67
- }
68
-
69
- let idx = list.length - 1
70
- for (let other of before) {
71
- let iidx = list.indexOf(other)
72
- if (iidx === -1) continue
73
- idx = Math.min(idx, iidx)
74
- }
75
-
76
- list.splice(idx, 0, value)
77
- }
78
-
79
- function parseStyles(styles) {
80
- if (!Array.isArray(styles)) {
81
- return parseStyles([styles])
82
- }
83
-
84
- return styles.flatMap((style) => {
85
- let isNode = !Array.isArray(style) && !isPlainObject(style)
86
- return isNode ? style : parseObjectStyles(style)
87
- })
88
- }
89
-
90
- function getClasses(selector, mutate) {
91
- let parser = selectorParser((selectors) => {
92
- let allClasses = []
93
-
94
- if (mutate) {
95
- mutate(selectors)
96
- }
97
-
98
- selectors.walkClasses((classNode) => {
99
- allClasses.push(classNode.value)
100
- })
101
-
102
- return allClasses
103
- })
104
- return parser.transformSync(selector)
105
- }
106
-
107
- function extractCandidates(node, state = { containsNonOnDemandable: false }, depth = 0) {
108
- let classes = []
109
-
110
- // Handle normal rules
111
- if (node.type === 'rule') {
112
- // Ignore everything inside a :not(...). This allows you to write code like
113
- // `div:not(.foo)`. If `.foo` is never found in your code, then we used to
114
- // not generated it. But now we will ignore everything inside a `:not`, so
115
- // that it still gets generated.
116
- function ignoreNot(selectors) {
117
- selectors.walkPseudos((pseudo) => {
118
- if (pseudo.value === ':not') {
119
- pseudo.remove()
120
- }
121
- })
122
- }
123
-
124
- for (let selector of node.selectors) {
125
- let classCandidates = getClasses(selector, ignoreNot)
126
- // At least one of the selectors contains non-"on-demandable" candidates.
127
- if (classCandidates.length === 0) {
128
- state.containsNonOnDemandable = true
129
- }
130
-
131
- for (let classCandidate of classCandidates) {
132
- classes.push(classCandidate)
133
- }
134
- }
135
- }
136
-
137
- // Handle at-rules (which contains nested rules)
138
- else if (node.type === 'atrule') {
139
- node.walkRules((rule) => {
140
- for (let classCandidate of rule.selectors.flatMap((selector) => getClasses(selector))) {
141
- classes.push(classCandidate)
142
- }
143
- })
144
- }
145
-
146
- if (depth === 0) {
147
- return [state.containsNonOnDemandable || classes.length === 0, classes]
148
- }
149
-
150
- return classes
151
- }
152
-
153
- function withIdentifiers(styles) {
154
- return parseStyles(styles).flatMap((node) => {
155
- let nodeMap = new Map()
156
- let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node)
157
-
158
- // If this isn't "on-demandable", assign it a universal candidate to always include it.
159
- if (containsNonOnDemandableSelectors) {
160
- candidates.unshift(sharedState.NOT_ON_DEMAND)
161
- }
162
-
163
- // However, it could be that it also contains "on-demandable" candidates.
164
- // E.g.: `span, .foo {}`, in that case it should still be possible to use
165
- // `@apply foo` for example.
166
- return candidates.map((c) => {
167
- if (!nodeMap.has(node)) {
168
- nodeMap.set(node, node)
169
- }
170
- return [c, nodeMap.get(node)]
171
- })
172
- })
173
- }
174
-
175
- export function isValidVariantFormatString(format) {
176
- return format.startsWith('@') || format.includes('&')
177
- }
178
-
179
- export function parseVariant(variant) {
180
- variant = variant
181
- .replace(/\n+/g, '')
182
- .replace(/\s{1,}/g, ' ')
183
- .trim()
184
-
185
- let fns = parseVariantFormatString(variant)
186
- .map((str) => {
187
- if (!str.startsWith('@')) {
188
- return ({ format }) => format(str)
189
- }
190
-
191
- let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str)
192
- return ({ wrap }) => wrap(postcss.atRule({ name, params: params.trim() }))
193
- })
194
- .reverse()
195
-
196
- return (api) => {
197
- for (let fn of fns) {
198
- fn(api)
199
- }
200
- }
201
- }
202
-
203
- function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
204
- function getConfigValue(path, defaultValue) {
205
- return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
206
- }
207
-
208
- function applyConfiguredPrefix(selector) {
209
- return prefixSelector(tailwindConfig.prefix, selector)
210
- }
211
-
212
- function prefixIdentifier(identifier, options) {
213
- if (identifier === sharedState.NOT_ON_DEMAND) {
214
- return sharedState.NOT_ON_DEMAND
215
- }
216
-
217
- if (!options.respectPrefix) {
218
- return identifier
219
- }
220
-
221
- return context.tailwindConfig.prefix + identifier
222
- }
223
-
224
- let api = {
225
- postcss,
226
- prefix: applyConfiguredPrefix,
227
- e: escapeClassName,
228
- config: getConfigValue,
229
- theme(path, defaultValue) {
230
- const [pathRoot, ...subPaths] = toPath(path)
231
- const value = getConfigValue(['theme', pathRoot, ...subPaths], defaultValue)
232
- return transformThemeValue(pathRoot)(value)
233
- },
234
- corePlugins: (path) => {
235
- if (Array.isArray(tailwindConfig.corePlugins)) {
236
- return tailwindConfig.corePlugins.includes(path)
237
- }
238
-
239
- return getConfigValue(['corePlugins', path], true)
240
- },
241
- variants: () => {
242
- // Preserved for backwards compatibility but not used in v3.0+
243
- return []
244
- },
245
- addBase(base) {
246
- for (let [identifier, rule] of withIdentifiers(base)) {
247
- let prefixedIdentifier = prefixIdentifier(identifier, {})
248
- let offset = offsets.base++
249
-
250
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
251
- context.candidateRuleMap.set(prefixedIdentifier, [])
252
- }
253
-
254
- context.candidateRuleMap
255
- .get(prefixedIdentifier)
256
- .push([{ sort: offset, layer: 'base' }, rule])
257
- }
258
- },
259
- /**
260
- * @param {string} group
261
- * @param {Record<string, string | string[]>} declarations
262
- */
263
- addDefaults(group, declarations) {
264
- const groups = {
265
- [`@defaults ${group}`]: declarations,
266
- }
267
-
268
- for (let [identifier, rule] of withIdentifiers(groups)) {
269
- let prefixedIdentifier = prefixIdentifier(identifier, {})
270
-
271
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
272
- context.candidateRuleMap.set(prefixedIdentifier, [])
273
- }
274
-
275
- context.candidateRuleMap
276
- .get(prefixedIdentifier)
277
- .push([{ sort: offsets.base++, layer: 'defaults' }, rule])
278
- }
279
- },
280
- addComponents(components, options) {
281
- let defaultOptions = {
282
- respectPrefix: true,
283
- respectImportant: false,
284
- }
285
-
286
- options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
287
-
288
- for (let [identifier, rule] of withIdentifiers(components)) {
289
- let prefixedIdentifier = prefixIdentifier(identifier, options)
290
-
291
- classList.add(prefixedIdentifier)
292
-
293
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
294
- context.candidateRuleMap.set(prefixedIdentifier, [])
295
- }
296
-
297
- context.candidateRuleMap
298
- .get(prefixedIdentifier)
299
- .push([{ sort: offsets.components++, layer: 'components', options }, rule])
300
- }
301
- },
302
- addUtilities(utilities, options) {
303
- let defaultOptions = {
304
- respectPrefix: true,
305
- respectImportant: true,
306
- }
307
-
308
- options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
309
-
310
- for (let [identifier, rule] of withIdentifiers(utilities)) {
311
- let prefixedIdentifier = prefixIdentifier(identifier, options)
312
-
313
- classList.add(prefixedIdentifier)
314
-
315
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
316
- context.candidateRuleMap.set(prefixedIdentifier, [])
317
- }
318
-
319
- context.candidateRuleMap
320
- .get(prefixedIdentifier)
321
- .push([{ sort: offsets.utilities++, layer: 'utilities', options }, rule])
322
- }
323
- },
324
- matchUtilities: function (utilities, options) {
325
- let defaultOptions = {
326
- respectPrefix: true,
327
- respectImportant: true,
328
- }
329
-
330
- options = { ...defaultOptions, ...options }
331
-
332
- let offset = offsets.utilities++
333
-
334
- for (let identifier in utilities) {
335
- let prefixedIdentifier = prefixIdentifier(identifier, options)
336
- let rule = utilities[identifier]
337
-
338
- classList.add([prefixedIdentifier, options])
339
-
340
- function wrapped(modifier, { isOnlyPlugin }) {
341
- let { type = 'any' } = options
342
- type = [].concat(type)
343
- let [value, coercedType] = coerceValue(type, modifier, options, tailwindConfig)
344
-
345
- if (value === undefined) {
346
- return []
347
- }
348
-
349
- if (!type.includes(coercedType) && !isOnlyPlugin) {
350
- return []
351
- }
352
-
353
- if (!isValidArbitraryValue(value)) {
354
- return []
355
- }
356
-
357
- let ruleSets = []
358
- .concat(rule(value))
359
- .filter(Boolean)
360
- .map((declaration) => ({
361
- [nameClass(identifier, modifier)]: declaration,
362
- }))
363
-
364
- return ruleSets
365
- }
366
-
367
- let withOffsets = [{ sort: offset, layer: 'utilities', options }, wrapped]
368
-
369
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
370
- context.candidateRuleMap.set(prefixedIdentifier, [])
371
- }
372
-
373
- context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
374
- }
375
- },
376
- matchComponents: function (components, options) {
377
- let defaultOptions = {
378
- respectPrefix: true,
379
- respectImportant: false,
380
- }
381
-
382
- options = { ...defaultOptions, ...options }
383
-
384
- let offset = offsets.components++
385
-
386
- for (let identifier in components) {
387
- let prefixedIdentifier = prefixIdentifier(identifier, options)
388
- let rule = components[identifier]
389
-
390
- classList.add([prefixedIdentifier, options])
391
-
392
- function wrapped(modifier, { isOnlyPlugin }) {
393
- let { type = 'any' } = options
394
- type = [].concat(type)
395
- let [value, coercedType] = coerceValue(type, modifier, options, tailwindConfig)
396
-
397
- if (value === undefined) {
398
- return []
399
- }
400
-
401
- if (!type.includes(coercedType)) {
402
- if (isOnlyPlugin) {
403
- log.warn([
404
- `Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
405
- `You can safely update it to \`${identifier}-${modifier.replace(
406
- coercedType + ':',
407
- ''
408
- )}\`.`,
409
- ])
410
- } else {
411
- return []
412
- }
413
- }
414
-
415
- if (!isValidArbitraryValue(value)) {
416
- return []
417
- }
418
-
419
- let ruleSets = []
420
- .concat(rule(value))
421
- .filter(Boolean)
422
- .map((declaration) => ({
423
- [nameClass(identifier, modifier)]: declaration,
424
- }))
425
-
426
- return ruleSets
427
- }
428
-
429
- let withOffsets = [{ sort: offset, layer: 'components', options }, wrapped]
430
-
431
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
432
- context.candidateRuleMap.set(prefixedIdentifier, [])
433
- }
434
-
435
- context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
436
- }
437
- },
438
- addVariant(variantName, variantFunctions, options = {}) {
439
- variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
440
- if (typeof variantFunction !== 'string') {
441
- // Safelist public API functions
442
- return (api) => {
443
- let { args, modifySelectors, container, separator, wrap, format } = api
444
- let result = variantFunction(
445
- Object.assign(
446
- { modifySelectors, container, separator },
447
- variantFunction[MATCH_VARIANT] && { args, wrap, format }
448
- )
449
- )
450
-
451
- if (typeof result === 'string' && !isValidVariantFormatString(result)) {
452
- throw new Error(
453
- `Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
454
- )
455
- }
456
-
457
- // result may be undefined with legacy variants that use APIs like `modifySelectors`
458
- return result && parseVariant(result)(api)
459
- }
460
- }
461
-
462
- if (!isValidVariantFormatString(variantFunction)) {
463
- throw new Error(
464
- `Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
465
- )
466
- }
467
-
468
- return parseVariant(variantFunction)
469
- })
470
-
471
- insertInto(variantList, variantName, options)
472
- variantMap.set(variantName, variantFunctions)
473
- },
474
- matchVariant: function (variants, options) {
475
- for (let variant in variants) {
476
- for (let [k, v] of Object.entries(options?.values ?? {})) {
477
- api.addVariant(`${variant}-${k}`, variants[variant](v))
478
- }
479
-
480
- api.addVariant(
481
- variant,
482
- Object.assign(({ args }) => variants[variant](args), { [MATCH_VARIANT]: true }),
483
- options
484
- )
485
- }
486
- },
487
- }
488
-
489
- return api
490
- }
491
-
492
- let fileModifiedMapCache = new WeakMap()
493
- export function getFileModifiedMap(context) {
494
- if (!fileModifiedMapCache.has(context)) {
495
- fileModifiedMapCache.set(context, new Map())
496
- }
497
- return fileModifiedMapCache.get(context)
498
- }
499
-
500
- function trackModified(files, fileModifiedMap) {
501
- let changed = false
502
-
503
- for (let file of files) {
504
- if (!file) continue
505
-
506
- let parsed = url.parse(file)
507
- let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href
508
- pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname
509
- let newModified = fs.statSync(decodeURIComponent(pathname), { throwIfNoEntry: false })?.mtimeMs
510
- if (!newModified) {
511
- // It could happen that a file is passed in that doesn't exist. E.g.:
512
- // postcss-cli will provide you a fake path when reading from stdin. This
513
- // path then looks like /path-to-your-project/stdin In that case we just
514
- // want to ignore it and don't track changes at all.
515
- continue
516
- }
517
-
518
- if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
519
- changed = true
520
- }
521
-
522
- fileModifiedMap.set(file, newModified)
523
- }
524
-
525
- return changed
526
- }
527
-
528
- function extractVariantAtRules(node) {
529
- node.walkAtRules((atRule) => {
530
- if (['responsive', 'variants'].includes(atRule.name)) {
531
- extractVariantAtRules(atRule)
532
- atRule.before(atRule.nodes)
533
- atRule.remove()
534
- }
535
- })
536
- }
537
-
538
- function collectLayerPlugins(root) {
539
- let layerPlugins = []
540
-
541
- root.each((node) => {
542
- if (node.type === 'atrule' && ['responsive', 'variants'].includes(node.name)) {
543
- node.name = 'layer'
544
- node.params = 'utilities'
545
- }
546
- })
547
-
548
- // Walk @layer rules and treat them like plugins
549
- root.walkAtRules('layer', (layerRule) => {
550
- extractVariantAtRules(layerRule)
551
-
552
- if (layerRule.params === 'base') {
553
- for (let node of layerRule.nodes) {
554
- layerPlugins.push(function ({ addBase }) {
555
- addBase(node, { respectPrefix: false })
556
- })
557
- }
558
- layerRule.remove()
559
- } else if (layerRule.params === 'components') {
560
- for (let node of layerRule.nodes) {
561
- layerPlugins.push(function ({ addComponents }) {
562
- addComponents(node, { respectPrefix: false })
563
- })
564
- }
565
- layerRule.remove()
566
- } else if (layerRule.params === 'utilities') {
567
- for (let node of layerRule.nodes) {
568
- layerPlugins.push(function ({ addUtilities }) {
569
- addUtilities(node, { respectPrefix: false })
570
- })
571
- }
572
- layerRule.remove()
573
- }
574
- })
575
-
576
- return layerPlugins
577
- }
578
-
579
- function resolvePlugins(context, root) {
580
- let corePluginList = Object.entries({ ...variantPlugins, ...corePlugins })
581
- .map(([name, plugin]) => {
582
- if (!context.tailwindConfig.corePlugins.includes(name)) {
583
- return null
584
- }
585
-
586
- return plugin
587
- })
588
- .filter(Boolean)
589
-
590
- let userPlugins = context.tailwindConfig.plugins.map((plugin) => {
591
- if (plugin.__isOptionsFunction) {
592
- plugin = plugin()
593
- }
594
-
595
- return typeof plugin === 'function' ? plugin : plugin.handler
596
- })
597
-
598
- let layerPlugins = collectLayerPlugins(root)
599
-
600
- // TODO: This is a workaround for backwards compatibility, since custom variants
601
- // were historically sorted before screen/stackable variants.
602
- let beforeVariants = [
603
- variantPlugins['pseudoElementVariants'],
604
- variantPlugins['pseudoClassVariants'],
605
- ]
606
- let afterVariants = [
607
- variantPlugins['directionVariants'],
608
- variantPlugins['reducedMotionVariants'],
609
- variantPlugins['darkVariants'],
610
- variantPlugins['printVariant'],
611
- variantPlugins['screenVariants'],
612
- variantPlugins['orientationVariants'],
613
- ]
614
-
615
- return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
616
- }
617
-
618
- function registerPlugins(plugins, context) {
619
- let variantList = []
620
- let variantMap = new Map()
621
- let offsets = {
622
- defaults: 0n,
623
- base: 0n,
624
- components: 0n,
625
- utilities: 0n,
626
- user: 0n,
627
- }
628
-
629
- let classList = new Set()
630
-
631
- let pluginApi = buildPluginApi(context.tailwindConfig, context, {
632
- variantList,
633
- variantMap,
634
- offsets,
635
- classList,
636
- })
637
-
638
- for (let plugin of plugins) {
639
- if (Array.isArray(plugin)) {
640
- for (let pluginItem of plugin) {
641
- pluginItem(pluginApi)
642
- }
643
- } else {
644
- plugin?.(pluginApi)
645
- }
646
- }
647
-
648
- let highestOffset = ((args) => args.reduce((m, e) => (e > m ? e : m)))([
649
- offsets.base,
650
- offsets.defaults,
651
- offsets.components,
652
- offsets.utilities,
653
- offsets.user,
654
- ])
655
- let reservedBits = BigInt(highestOffset.toString(2).length)
656
-
657
- // A number one less than the top range of the highest offset area
658
- // so arbitrary properties are always sorted at the end.
659
- context.arbitraryPropertiesSort = ((1n << reservedBits) << 0n) - 1n
660
-
661
- context.layerOrder = {
662
- defaults: (1n << reservedBits) << 0n,
663
- base: (1n << reservedBits) << 1n,
664
- components: (1n << reservedBits) << 2n,
665
- utilities: (1n << reservedBits) << 3n,
666
- user: (1n << reservedBits) << 4n,
667
- }
668
-
669
- reservedBits += 5n
670
-
671
- let offset = 0
672
- context.variantOrder = new Map(
673
- variantList
674
- .map((variant, i) => {
675
- let variantFunctions = variantMap.get(variant).length
676
- let bits = (1n << BigInt(i + offset)) << reservedBits
677
- offset += variantFunctions - 1
678
- return [variant, bits]
679
- })
680
- .sort(([, a], [, z]) => bigSign(a - z))
681
- )
682
-
683
- context.minimumScreen = [...context.variantOrder.values()].shift()
684
-
685
- // Build variantMap
686
- for (let [variantName, variantFunctions] of variantMap.entries()) {
687
- let sort = context.variantOrder.get(variantName)
688
- context.variantMap.set(
689
- variantName,
690
- variantFunctions.map((variantFunction, idx) => [sort << BigInt(idx), variantFunction])
691
- )
692
- }
693
-
694
- let safelist = (context.tailwindConfig.safelist ?? []).filter(Boolean)
695
- if (safelist.length > 0) {
696
- let checks = []
697
-
698
- for (let value of safelist) {
699
- if (typeof value === 'string') {
700
- context.changedContent.push({ content: value, extension: 'html' })
701
- continue
702
- }
703
-
704
- if (value instanceof RegExp) {
705
- log.warn('root-regex', [
706
- 'Regular expressions in `safelist` work differently in Tailwind CSS v3.0.',
707
- 'Update your `safelist` configuration to eliminate this warning.',
708
- 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
709
- ])
710
- continue
711
- }
712
-
713
- checks.push(value)
714
- }
715
-
716
- if (checks.length > 0) {
717
- let patternMatchingCount = new Map()
718
- let prefixLength = context.tailwindConfig.prefix.length
719
-
720
- for (let util of classList) {
721
- let utils = Array.isArray(util)
722
- ? (() => {
723
- let [utilName, options] = util
724
- let values = Object.keys(options?.values ?? {})
725
- let classes = values.map((value) => formatClass(utilName, value))
726
-
727
- if (options?.supportsNegativeValues) {
728
- // This is the normal negated version
729
- // e.g. `-inset-1` or `-tw-inset-1`
730
- classes = [...classes, ...classes.map((cls) => '-' + cls)]
731
-
732
- // This is the negated version *after* the prefix
733
- // e.g. `tw--inset-1`
734
- // The prefix is already attached to util name
735
- // So we add the negative after the prefix
736
- classes = [
737
- ...classes,
738
- ...classes.map(
739
- (cls) => cls.slice(0, prefixLength) + '-' + cls.slice(prefixLength)
740
- ),
741
- ]
742
- }
743
-
744
- return classes
745
- })()
746
- : [util]
747
-
748
- for (let util of utils) {
749
- for (let { pattern, variants = [] } of checks) {
750
- // RegExp with the /g flag are stateful, so let's reset the last
751
- // index pointer to reset the state.
752
- pattern.lastIndex = 0
753
-
754
- if (!patternMatchingCount.has(pattern)) {
755
- patternMatchingCount.set(pattern, 0)
756
- }
757
-
758
- if (!pattern.test(util)) continue
759
-
760
- patternMatchingCount.set(pattern, patternMatchingCount.get(pattern) + 1)
761
-
762
- context.changedContent.push({ content: util, extension: 'html' })
763
- for (let variant of variants) {
764
- context.changedContent.push({
765
- content: variant + context.tailwindConfig.separator + util,
766
- extension: 'html',
767
- })
768
- }
769
- }
770
- }
771
- }
772
-
773
- for (let [regex, count] of patternMatchingCount.entries()) {
774
- if (count !== 0) continue
775
-
776
- log.warn([
777
- `The safelist pattern \`${regex}\` doesn't match any Tailwind CSS classes.`,
778
- 'Fix this pattern or remove it from your `safelist` configuration.',
779
- 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
780
- ])
781
- }
782
- }
783
- }
784
-
785
- // A list of utilities that are used by certain Tailwind CSS utilities but
786
- // that don't exist on their own. This will result in them "not existing" and
787
- // sorting could be weird since you still require them in order to make the
788
- // host utitlies work properly. (Thanks Biology)
789
- let parasiteUtilities = new Set([prefix(context, 'group'), prefix(context, 'peer')])
790
- context.getClassOrder = function getClassOrder(classes) {
791
- let sortedClassNames = new Map()
792
- for (let [sort, rule] of generateRules(new Set(classes), context)) {
793
- if (sortedClassNames.has(rule.raws.tailwind.candidate)) continue
794
- sortedClassNames.set(rule.raws.tailwind.candidate, sort)
795
- }
796
-
797
- return classes.map((className) => {
798
- let order = sortedClassNames.get(className) ?? null
799
-
800
- if (order === null && parasiteUtilities.has(className)) {
801
- // This will make sure that it is at the very beginning of the
802
- // `components` layer which technically means 'before any
803
- // components'.
804
- order = context.layerOrder.components
805
- }
806
-
807
- return [className, order]
808
- })
809
- }
810
-
811
- // Generate a list of strings for autocompletion purposes, e.g.
812
- // ['uppercase', 'lowercase', ...]
813
- context.getClassList = function getClassList() {
814
- let output = []
815
-
816
- for (let util of classList) {
817
- if (Array.isArray(util)) {
818
- let [utilName, options] = util
819
- let negativeClasses = []
820
-
821
- for (let [key, value] of Object.entries(options?.values ?? {})) {
822
- output.push(formatClass(utilName, key))
823
- if (options?.supportsNegativeValues && negateValue(value)) {
824
- negativeClasses.push(formatClass(utilName, `-${key}`))
825
- }
826
- }
827
-
828
- output.push(...negativeClasses)
829
- } else {
830
- output.push(util)
831
- }
832
- }
833
-
834
- return output
835
- }
836
- }
837
-
838
- export function createContext(tailwindConfig, changedContent = [], root = postcss.root()) {
839
- let context = {
840
- disposables: [],
841
- ruleCache: new Set(),
842
- classCache: new Map(),
843
- applyClassCache: new Map(),
844
- notClassCache: new Set(),
845
- postCssNodeCache: new Map(),
846
- candidateRuleMap: new Map(),
847
- tailwindConfig,
848
- changedContent: changedContent,
849
- variantMap: new Map(),
850
- stylesheetCache: null,
851
- }
852
-
853
- let resolvedPlugins = resolvePlugins(context, root)
854
- registerPlugins(resolvedPlugins, context)
855
-
856
- return context
857
- }
858
-
859
- let contextMap = sharedState.contextMap
860
- let configContextMap = sharedState.configContextMap
861
- let contextSourcesMap = sharedState.contextSourcesMap
862
-
863
- export function getContext(
864
- root,
865
- result,
866
- tailwindConfig,
867
- userConfigPath,
868
- tailwindConfigHash,
869
- contextDependencies
870
- ) {
871
- let sourcePath = result.opts.from
872
- let isConfigFile = userConfigPath !== null
873
-
874
- env.DEBUG && console.log('Source path:', sourcePath)
875
-
876
- let existingContext
877
-
878
- if (isConfigFile && contextMap.has(sourcePath)) {
879
- existingContext = contextMap.get(sourcePath)
880
- } else if (configContextMap.has(tailwindConfigHash)) {
881
- let context = configContextMap.get(tailwindConfigHash)
882
- contextSourcesMap.get(context).add(sourcePath)
883
- contextMap.set(sourcePath, context)
884
-
885
- existingContext = context
886
- }
887
-
888
- let cssDidChange = hasContentChanged(sourcePath, root)
889
-
890
- // If there's already a context in the cache and we don't need to
891
- // reset the context, return the cached context.
892
- if (existingContext) {
893
- let contextDependenciesChanged = trackModified(
894
- [...contextDependencies],
895
- getFileModifiedMap(existingContext)
896
- )
897
- if (!contextDependenciesChanged && !cssDidChange) {
898
- return [existingContext, false]
899
- }
900
- }
901
-
902
- // If this source is in the context map, get the old context.
903
- // Remove this source from the context sources for the old context,
904
- // and clean up that context if no one else is using it. This can be
905
- // called by many processes in rapid succession, so we check for presence
906
- // first because the first process to run this code will wipe it out first.
907
- if (contextMap.has(sourcePath)) {
908
- let oldContext = contextMap.get(sourcePath)
909
- if (contextSourcesMap.has(oldContext)) {
910
- contextSourcesMap.get(oldContext).delete(sourcePath)
911
- if (contextSourcesMap.get(oldContext).size === 0) {
912
- contextSourcesMap.delete(oldContext)
913
- for (let [tailwindConfigHash, context] of configContextMap) {
914
- if (context === oldContext) {
915
- configContextMap.delete(tailwindConfigHash)
916
- }
917
- }
918
- for (let disposable of oldContext.disposables.splice(0)) {
919
- disposable(oldContext)
920
- }
921
- }
922
- }
923
- }
924
-
925
- env.DEBUG && console.log('Setting up new context...')
926
-
927
- let context = createContext(tailwindConfig, [], root)
928
-
929
- trackModified([...contextDependencies], getFileModifiedMap(context))
930
-
931
- // ---
932
-
933
- // Update all context tracking state
934
-
935
- configContextMap.set(tailwindConfigHash, context)
936
- contextMap.set(sourcePath, context)
937
-
938
- if (!contextSourcesMap.has(context)) {
939
- contextSourcesMap.set(context, new Set())
940
- }
941
-
942
- contextSourcesMap.get(context).add(sourcePath)
943
-
944
- return [context, true]
945
- }