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