tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.ca7b10e

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 (179) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +18 -11
  3. package/dist/chunk-7MHEDNEU.mjs +1 -0
  4. package/dist/chunk-AZANAYY2.mjs +1 -0
  5. package/dist/chunk-YTVGJJD3.mjs +12 -0
  6. package/dist/colors-b_6i0Oi7.d.ts +295 -0
  7. package/dist/colors.d.mts +295 -0
  8. package/dist/colors.d.ts +5 -0
  9. package/dist/colors.js +1 -0
  10. package/dist/colors.mjs +1 -0
  11. package/dist/default-theme.d.mts +1147 -0
  12. package/dist/default-theme.d.ts +1147 -0
  13. package/dist/default-theme.js +1 -0
  14. package/dist/default-theme.mjs +1 -0
  15. package/dist/flatten-color-palette.d.mts +6 -0
  16. package/dist/flatten-color-palette.d.ts +6 -0
  17. package/dist/flatten-color-palette.js +1 -0
  18. package/dist/flatten-color-palette.mjs +1 -0
  19. package/dist/lib.d.mts +264 -0
  20. package/dist/lib.d.ts +3 -0
  21. package/dist/lib.js +33 -0
  22. package/dist/lib.mjs +22 -0
  23. package/dist/plugin.d.mts +11 -0
  24. package/dist/plugin.d.ts +104 -0
  25. package/dist/plugin.js +1 -0
  26. package/dist/plugin.mjs +1 -0
  27. package/dist/resolve-config-BIFUA2FY.d.ts +29 -0
  28. package/dist/resolve-config-QUZ9b-Gn.d.mts +190 -0
  29. package/dist/types-B254mqw1.d.mts +98 -0
  30. package/index.css +866 -0
  31. package/package.json +73 -100
  32. package/preflight.css +375 -0
  33. package/theme.css +453 -0
  34. package/CHANGELOG.md +0 -1758
  35. package/base.css +0 -1
  36. package/colors.js +0 -1
  37. package/components.css +0 -1
  38. package/defaultConfig.js +0 -1
  39. package/defaultTheme.js +0 -1
  40. package/lib/cli-peer-dependencies.js +0 -15
  41. package/lib/cli.js +0 -707
  42. package/lib/constants.js +0 -37
  43. package/lib/corePluginList.js +0 -169
  44. package/lib/corePlugins.js +0 -3525
  45. package/lib/css/LICENSE +0 -25
  46. package/lib/css/preflight.css +0 -354
  47. package/lib/featureFlags.js +0 -57
  48. package/lib/index.js +0 -32
  49. package/lib/lib/collapseAdjacentRules.js +0 -41
  50. package/lib/lib/detectNesting.js +0 -19
  51. package/lib/lib/evaluateTailwindFunctions.js +0 -167
  52. package/lib/lib/expandApplyAtRules.js +0 -228
  53. package/lib/lib/expandTailwindAtRules.js +0 -257
  54. package/lib/lib/generateRules.js +0 -350
  55. package/lib/lib/getModuleDependencies.js +0 -48
  56. package/lib/lib/normalizeTailwindDirectives.js +0 -75
  57. package/lib/lib/resolveDefaultsAtRules.js +0 -128
  58. package/lib/lib/setupContextUtils.js +0 -791
  59. package/lib/lib/setupTrackingContext.js +0 -170
  60. package/lib/lib/setupWatchingContext.js +0 -284
  61. package/lib/lib/sharedState.js +0 -29
  62. package/lib/lib/substituteScreenAtRules.js +0 -24
  63. package/lib/processTailwindFeatures.js +0 -47
  64. package/lib/public/colors.js +0 -333
  65. package/lib/public/create-plugin.js +0 -13
  66. package/lib/public/default-config.js +0 -14
  67. package/lib/public/default-theme.js +0 -14
  68. package/lib/public/resolve-config.js +0 -19
  69. package/lib/util/bigSign.js +0 -8
  70. package/lib/util/buildMediaQuery.js +0 -31
  71. package/lib/util/cloneDeep.js +0 -19
  72. package/lib/util/cloneNodes.js +0 -14
  73. package/lib/util/color.js +0 -84
  74. package/lib/util/configurePlugins.js +0 -18
  75. package/lib/util/createPlugin.js +0 -30
  76. package/lib/util/createUtilityPlugin.js +0 -53
  77. package/lib/util/dataTypes.js +0 -202
  78. package/lib/util/defaults.js +0 -16
  79. package/lib/util/escapeClassName.js +0 -19
  80. package/lib/util/escapeCommas.js +0 -8
  81. package/lib/util/flattenColorPalette.js +0 -19
  82. package/lib/util/getAllConfigs.js +0 -29
  83. package/lib/util/hashConfig.js +0 -16
  84. package/lib/util/isKeyframeRule.js +0 -8
  85. package/lib/util/isPlainObject.js +0 -12
  86. package/lib/util/log.js +0 -35
  87. package/lib/util/nameClass.js +0 -31
  88. package/lib/util/negateValue.js +0 -17
  89. package/lib/util/parseAnimationValue.js +0 -89
  90. package/lib/util/parseDependency.js +0 -63
  91. package/lib/util/parseObjectStyles.js +0 -31
  92. package/lib/util/pluginUtils.js +0 -282
  93. package/lib/util/prefixSelector.js +0 -23
  94. package/lib/util/resolveConfig.js +0 -293
  95. package/lib/util/resolveConfigPath.js +0 -52
  96. package/lib/util/responsive.js +0 -19
  97. package/lib/util/tap.js +0 -9
  98. package/lib/util/toColorValue.js +0 -9
  99. package/lib/util/toPath.js +0 -9
  100. package/lib/util/transformThemeValue.js +0 -53
  101. package/lib/util/withAlphaVariable.js +0 -67
  102. package/nesting/README.md +0 -42
  103. package/nesting/index.js +0 -12
  104. package/nesting/plugin.js +0 -41
  105. package/peers/index.js +0 -77111
  106. package/plugin.js +0 -1
  107. package/prettier.config.js +0 -19
  108. package/resolveConfig.js +0 -1
  109. package/screens.css +0 -1
  110. package/scripts/create-plugin-list.js +0 -10
  111. package/scripts/install-integrations.js +0 -27
  112. package/scripts/rebuildFixtures.js +0 -68
  113. package/src/cli-peer-dependencies.js +0 -9
  114. package/src/cli.js +0 -762
  115. package/src/constants.js +0 -17
  116. package/src/corePluginList.js +0 -1
  117. package/src/corePlugins.js +0 -2382
  118. package/src/css/LICENSE +0 -25
  119. package/src/css/preflight.css +0 -354
  120. package/src/featureFlags.js +0 -48
  121. package/src/index.js +0 -34
  122. package/src/lib/collapseAdjacentRules.js +0 -39
  123. package/src/lib/detectNesting.js +0 -20
  124. package/src/lib/evaluateTailwindFunctions.js +0 -195
  125. package/src/lib/expandApplyAtRules.js +0 -251
  126. package/src/lib/expandTailwindAtRules.js +0 -266
  127. package/src/lib/generateRules.js +0 -320
  128. package/src/lib/getModuleDependencies.js +0 -39
  129. package/src/lib/normalizeTailwindDirectives.js +0 -77
  130. package/src/lib/resolveDefaultsAtRules.js +0 -125
  131. package/src/lib/setupContextUtils.js +0 -775
  132. package/src/lib/setupTrackingContext.js +0 -184
  133. package/src/lib/setupWatchingContext.js +0 -306
  134. package/src/lib/sharedState.js +0 -13
  135. package/src/lib/substituteScreenAtRules.js +0 -16
  136. package/src/processTailwindFeatures.js +0 -43
  137. package/src/public/colors.js +0 -305
  138. package/src/public/create-plugin.js +0 -2
  139. package/src/public/default-config.js +0 -4
  140. package/src/public/default-theme.js +0 -4
  141. package/src/public/resolve-config.js +0 -7
  142. package/src/util/bigSign.js +0 -3
  143. package/src/util/buildMediaQuery.js +0 -24
  144. package/src/util/cloneDeep.js +0 -11
  145. package/src/util/cloneNodes.js +0 -11
  146. package/src/util/color.js +0 -56
  147. package/src/util/configurePlugins.js +0 -23
  148. package/src/util/createPlugin.js +0 -27
  149. package/src/util/createUtilityPlugin.js +0 -37
  150. package/src/util/dataTypes.js +0 -216
  151. package/src/util/defaults.js +0 -11
  152. package/src/util/escapeClassName.js +0 -8
  153. package/src/util/escapeCommas.js +0 -3
  154. package/src/util/flattenColorPalette.js +0 -13
  155. package/src/util/getAllConfigs.js +0 -19
  156. package/src/util/hashConfig.js +0 -5
  157. package/src/util/isKeyframeRule.js +0 -3
  158. package/src/util/isPlainObject.js +0 -8
  159. package/src/util/log.js +0 -28
  160. package/src/util/nameClass.js +0 -26
  161. package/src/util/negateValue.js +0 -14
  162. package/src/util/parseAnimationValue.js +0 -68
  163. package/src/util/parseDependency.js +0 -49
  164. package/src/util/parseObjectStyles.js +0 -19
  165. package/src/util/pluginUtils.js +0 -288
  166. package/src/util/prefixSelector.js +0 -15
  167. package/src/util/resolveConfig.js +0 -282
  168. package/src/util/resolveConfigPath.js +0 -55
  169. package/src/util/responsive.js +0 -10
  170. package/src/util/tap.js +0 -4
  171. package/src/util/toColorValue.js +0 -3
  172. package/src/util/toPath.js +0 -4
  173. package/src/util/transformThemeValue.js +0 -37
  174. package/src/util/withAlphaVariable.js +0 -49
  175. package/stubs/defaultConfig.stub.js +0 -890
  176. package/stubs/defaultPostCssConfig.stub.js +0 -6
  177. package/stubs/simpleConfig.stub.js +0 -8
  178. package/tailwind.css +0 -5
  179. package/variants.css +0 -1
@@ -1,775 +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 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
-
21
- function insertInto(list, value, { before = [] } = {}) {
22
- before = [].concat(before)
23
-
24
- if (before.length <= 0) {
25
- list.push(value)
26
- return
27
- }
28
-
29
- let idx = list.length - 1
30
- for (let other of before) {
31
- let iidx = list.indexOf(other)
32
- if (iidx === -1) continue
33
- idx = Math.min(idx, iidx)
34
- }
35
-
36
- list.splice(idx, 0, value)
37
- }
38
-
39
- function parseStyles(styles) {
40
- if (!Array.isArray(styles)) {
41
- return parseStyles([styles])
42
- }
43
-
44
- return styles.flatMap((style) => {
45
- let isNode = !Array.isArray(style) && !isPlainObject(style)
46
- return isNode ? style : parseObjectStyles(style)
47
- })
48
- }
49
-
50
- function getClasses(selector) {
51
- let parser = selectorParser((selectors) => {
52
- let allClasses = []
53
- selectors.walkClasses((classNode) => {
54
- allClasses.push(classNode.value)
55
- })
56
- return allClasses
57
- })
58
- return parser.transformSync(selector)
59
- }
60
-
61
- function extractCandidates(node) {
62
- let classes = []
63
-
64
- if (node.type === 'rule') {
65
- for (let selector of node.selectors) {
66
- let classCandidates = getClasses(selector)
67
- // At least one of the selectors contains non-"on-demandable" candidates.
68
- if (classCandidates.length === 0) return []
69
-
70
- classes = [...classes, ...classCandidates]
71
- }
72
- return classes
73
- }
74
-
75
- if (node.type === 'atrule') {
76
- node.walkRules((rule) => {
77
- classes = [...classes, ...rule.selectors.flatMap((selector) => getClasses(selector))]
78
- })
79
- }
80
-
81
- return classes
82
- }
83
-
84
- function withIdentifiers(styles) {
85
- return parseStyles(styles).flatMap((node) => {
86
- let nodeMap = new Map()
87
- let candidates = extractCandidates(node)
88
-
89
- // If this isn't "on-demandable", assign it a universal candidate.
90
- if (candidates.length === 0) {
91
- return [['*', node]]
92
- }
93
-
94
- return candidates.map((c) => {
95
- if (!nodeMap.has(node)) {
96
- nodeMap.set(node, node)
97
- }
98
- return [c, nodeMap.get(node)]
99
- })
100
- })
101
- }
102
-
103
- let matchingBrackets = new Map([
104
- ['{', '}'],
105
- ['[', ']'],
106
- ['(', ')'],
107
- ])
108
- let inverseMatchingBrackets = new Map(
109
- Array.from(matchingBrackets.entries()).map(([k, v]) => [v, k])
110
- )
111
-
112
- let quotes = new Set(['"', "'", '`'])
113
-
114
- // Arbitrary values must contain balanced brackets (), [] and {}. Escaped
115
- // values don't count, and brackets inside quotes also don't count.
116
- //
117
- // E.g.: w-[this-is]w-[weird-and-invalid]
118
- // E.g.: w-[this-is\\]w-\\[weird-but-valid]
119
- // E.g.: content-['this-is-also-valid]-weirdly-enough']
120
- function isValidArbitraryValue(value) {
121
- let stack = []
122
- let inQuotes = false
123
-
124
- for (let i = 0; i < value.length; i++) {
125
- let char = value[i]
126
-
127
- // Non-escaped quotes allow us to "allow" anything in between
128
- if (quotes.has(char) && value[i - 1] !== '\\') {
129
- inQuotes = !inQuotes
130
- }
131
-
132
- if (inQuotes) continue
133
- if (value[i - 1] === '\\') continue // Escaped
134
-
135
- if (matchingBrackets.has(char)) {
136
- stack.push(char)
137
- } else if (inverseMatchingBrackets.has(char)) {
138
- let inverse = inverseMatchingBrackets.get(char)
139
-
140
- // Nothing to pop from, therefore it is unbalanced
141
- if (stack.length <= 0) {
142
- return false
143
- }
144
-
145
- // Popped value must match the inverse value, otherwise it is unbalanced
146
- if (stack.pop() !== inverse) {
147
- return false
148
- }
149
- }
150
- }
151
-
152
- // If there is still something on the stack, it is also unbalanced
153
- if (stack.length > 0) {
154
- return false
155
- }
156
-
157
- // All good, totally balanced!
158
- return true
159
- }
160
-
161
- function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
162
- function getConfigValue(path, defaultValue) {
163
- return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
164
- }
165
-
166
- function applyConfiguredPrefix(selector) {
167
- return prefixSelector(tailwindConfig.prefix, selector)
168
- }
169
-
170
- function prefixIdentifier(identifier, options) {
171
- if (identifier === '*') {
172
- return '*'
173
- }
174
-
175
- if (!options.respectPrefix) {
176
- return identifier
177
- }
178
-
179
- if (typeof context.tailwindConfig.prefix === 'function') {
180
- return prefixSelector(context.tailwindConfig.prefix, `.${identifier}`).substr(1)
181
- }
182
-
183
- return context.tailwindConfig.prefix + identifier
184
- }
185
-
186
- return {
187
- addVariant(variantName, variantFunctions, options = {}) {
188
- variantFunctions = [].concat(variantFunctions)
189
-
190
- insertInto(variantList, variantName, options)
191
- variantMap.set(variantName, variantFunctions)
192
- },
193
- postcss,
194
- prefix: applyConfiguredPrefix,
195
- e: escapeClassName,
196
- config: getConfigValue,
197
- theme(path, defaultValue) {
198
- const [pathRoot, ...subPaths] = toPath(path)
199
- const value = getConfigValue(['theme', pathRoot, ...subPaths], defaultValue)
200
- return transformThemeValue(pathRoot)(value)
201
- },
202
- corePlugins: (path) => {
203
- if (Array.isArray(tailwindConfig.corePlugins)) {
204
- return tailwindConfig.corePlugins.includes(path)
205
- }
206
-
207
- return getConfigValue(['corePlugins', path], true)
208
- },
209
- variants: () => {
210
- // Preserved for backwards compatibility but not used in v3.0+
211
- return []
212
- },
213
- addUserCss(userCss) {
214
- for (let [identifier, rule] of withIdentifiers(userCss)) {
215
- let offset = offsets.user++
216
-
217
- if (!context.candidateRuleMap.has(identifier)) {
218
- context.candidateRuleMap.set(identifier, [])
219
- }
220
-
221
- context.candidateRuleMap.get(identifier).push([{ sort: offset, layer: 'user' }, rule])
222
- }
223
- },
224
- addBase(base) {
225
- for (let [identifier, rule] of withIdentifiers(base)) {
226
- let prefixedIdentifier = prefixIdentifier(identifier, {})
227
- let offset = offsets.base++
228
-
229
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
230
- context.candidateRuleMap.set(prefixedIdentifier, [])
231
- }
232
-
233
- context.candidateRuleMap
234
- .get(prefixedIdentifier)
235
- .push([{ sort: offset, layer: 'base' }, rule])
236
- }
237
- },
238
- addComponents(components, options) {
239
- let defaultOptions = {
240
- variants: [],
241
- respectPrefix: true,
242
- respectImportant: false,
243
- respectVariants: true,
244
- }
245
-
246
- options = Object.assign(
247
- {},
248
- defaultOptions,
249
- Array.isArray(options) ? { variants: options } : options
250
- )
251
-
252
- for (let [identifier, rule] of withIdentifiers(components)) {
253
- let prefixedIdentifier = prefixIdentifier(identifier, options)
254
- let offset = offsets.components++
255
-
256
- classList.add(prefixedIdentifier)
257
-
258
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
259
- context.candidateRuleMap.set(prefixedIdentifier, [])
260
- }
261
-
262
- context.candidateRuleMap
263
- .get(prefixedIdentifier)
264
- .push([{ sort: offset, layer: 'components', options }, rule])
265
- }
266
- },
267
- addUtilities(utilities, options) {
268
- let defaultOptions = {
269
- variants: [],
270
- respectPrefix: true,
271
- respectImportant: true,
272
- respectVariants: true,
273
- }
274
-
275
- options = Object.assign(
276
- {},
277
- defaultOptions,
278
- Array.isArray(options) ? { variants: options } : options
279
- )
280
-
281
- for (let [identifier, rule] of withIdentifiers(utilities)) {
282
- let prefixedIdentifier = prefixIdentifier(identifier, options)
283
- let offset = offsets.utilities++
284
-
285
- classList.add(prefixedIdentifier)
286
-
287
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
288
- context.candidateRuleMap.set(prefixedIdentifier, [])
289
- }
290
-
291
- context.candidateRuleMap
292
- .get(prefixedIdentifier)
293
- .push([{ sort: offset, layer: 'utilities', options }, rule])
294
- }
295
- },
296
- matchUtilities: function (utilities, options) {
297
- let defaultOptions = {
298
- variants: [],
299
- respectPrefix: true,
300
- respectImportant: true,
301
- respectVariants: true,
302
- }
303
-
304
- options = { ...defaultOptions, ...options }
305
-
306
- let offset = offsets.utilities++
307
-
308
- for (let identifier in utilities) {
309
- let prefixedIdentifier = prefixIdentifier(identifier, options)
310
- let rule = utilities[identifier]
311
-
312
- classList.add([prefixedIdentifier, options])
313
-
314
- function wrapped(modifier, { isOnlyPlugin }) {
315
- let { type = 'any' } = options
316
- type = [].concat(type)
317
- let [value, coercedType] = coerceValue(type, modifier, options.values, tailwindConfig)
318
-
319
- if (value === undefined) {
320
- return []
321
- }
322
-
323
- if (!type.includes(coercedType)) {
324
- if (isOnlyPlugin) {
325
- log.warn([
326
- `Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
327
- `You can safely update it to \`${identifier}-${modifier.replace(
328
- coercedType + ':',
329
- ''
330
- )}\`.`,
331
- ])
332
- } else {
333
- return []
334
- }
335
- }
336
-
337
- if (!isValidArbitraryValue(value)) {
338
- return []
339
- }
340
-
341
- let includedRules = []
342
- let ruleSets = []
343
- .concat(
344
- rule(value, {
345
- includeRules(rules) {
346
- includedRules.push(...rules)
347
- },
348
- })
349
- )
350
- .filter(Boolean)
351
- .map((declaration) => ({
352
- [nameClass(identifier, modifier)]: declaration,
353
- }))
354
-
355
- return [...includedRules, ...ruleSets]
356
- }
357
-
358
- let withOffsets = [{ sort: offset, layer: 'utilities', options }, wrapped]
359
-
360
- if (!context.candidateRuleMap.has(prefixedIdentifier)) {
361
- context.candidateRuleMap.set(prefixedIdentifier, [])
362
- }
363
-
364
- context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
365
- }
366
- },
367
- }
368
- }
369
-
370
- let fileModifiedMapCache = new WeakMap()
371
- export function getFileModifiedMap(context) {
372
- if (!fileModifiedMapCache.has(context)) {
373
- fileModifiedMapCache.set(context, new Map())
374
- }
375
- return fileModifiedMapCache.get(context)
376
- }
377
-
378
- function trackModified(files, fileModifiedMap) {
379
- let changed = false
380
-
381
- for (let file of files) {
382
- if (!file) continue
383
-
384
- let parsed = url.parse(file)
385
- let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href
386
- pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname
387
- let newModified = fs.statSync(decodeURIComponent(pathname)).mtimeMs
388
-
389
- if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
390
- changed = true
391
- }
392
-
393
- fileModifiedMap.set(file, newModified)
394
- }
395
-
396
- return changed
397
- }
398
-
399
- function extractVariantAtRules(node) {
400
- node.walkAtRules((atRule) => {
401
- if (['responsive', 'variants'].includes(atRule.name)) {
402
- extractVariantAtRules(atRule)
403
- atRule.before(atRule.nodes)
404
- atRule.remove()
405
- }
406
- })
407
- }
408
-
409
- function collectLayerPlugins(root) {
410
- let layerPlugins = []
411
-
412
- root.each((node) => {
413
- if (node.type === 'atrule' && ['responsive', 'variants'].includes(node.name)) {
414
- node.name = 'layer'
415
- node.params = 'utilities'
416
- }
417
- })
418
-
419
- // Walk @layer rules and treat them like plugins
420
- root.walkAtRules('layer', (layerRule) => {
421
- extractVariantAtRules(layerRule)
422
-
423
- if (layerRule.params === 'base') {
424
- for (let node of layerRule.nodes) {
425
- layerPlugins.push(function ({ addBase }) {
426
- addBase(node, { respectPrefix: false })
427
- })
428
- }
429
- layerRule.remove()
430
- } else if (layerRule.params === 'components') {
431
- for (let node of layerRule.nodes) {
432
- layerPlugins.push(function ({ addComponents }) {
433
- addComponents(node, { respectPrefix: false })
434
- })
435
- }
436
- layerRule.remove()
437
- } else if (layerRule.params === 'utilities') {
438
- for (let node of layerRule.nodes) {
439
- layerPlugins.push(function ({ addUtilities }) {
440
- addUtilities(node, { respectPrefix: false })
441
- })
442
- }
443
- layerRule.remove()
444
- }
445
- })
446
-
447
- root.walkRules((rule) => {
448
- // At this point it is safe to include all the left-over css from the
449
- // user's css file. This is because the `@tailwind` and `@layer` directives
450
- // will already be handled and will be removed from the css tree.
451
- layerPlugins.push(function ({ addUserCss }) {
452
- addUserCss(rule, { respectPrefix: false })
453
- })
454
- })
455
-
456
- return layerPlugins
457
- }
458
-
459
- function resolvePlugins(context, root) {
460
- let corePluginList = Object.entries(corePlugins)
461
- .map(([name, plugin]) => {
462
- if (!context.tailwindConfig.corePlugins.includes(name)) {
463
- return null
464
- }
465
-
466
- return plugin
467
- })
468
- .filter(Boolean)
469
-
470
- let userPlugins = context.tailwindConfig.plugins.map((plugin) => {
471
- if (plugin.__isOptionsFunction) {
472
- plugin = plugin()
473
- }
474
-
475
- return typeof plugin === 'function' ? plugin : plugin.handler
476
- })
477
-
478
- let layerPlugins = collectLayerPlugins(root)
479
-
480
- // TODO: This is a workaround for backwards compatibility, since custom variants
481
- // were historically sorted before screen/stackable variants.
482
- let beforeVariants = [corePlugins['pseudoElementVariants'], corePlugins['pseudoClassVariants']]
483
- let afterVariants = [
484
- corePlugins['directionVariants'],
485
- corePlugins['reducedMotionVariants'],
486
- corePlugins['darkVariants'],
487
- corePlugins['screenVariants'],
488
- ]
489
-
490
- return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
491
- }
492
-
493
- function registerPlugins(plugins, context) {
494
- let variantList = []
495
- let variantMap = new Map()
496
- let offsets = {
497
- base: 0n,
498
- components: 0n,
499
- utilities: 0n,
500
- user: 0n,
501
- }
502
-
503
- let classList = new Set()
504
-
505
- let pluginApi = buildPluginApi(context.tailwindConfig, context, {
506
- variantList,
507
- variantMap,
508
- offsets,
509
- classList,
510
- })
511
-
512
- for (let plugin of plugins) {
513
- if (Array.isArray(plugin)) {
514
- for (let pluginItem of plugin) {
515
- pluginItem(pluginApi)
516
- }
517
- } else {
518
- plugin?.(pluginApi)
519
- }
520
- }
521
-
522
- let highestOffset = ((args) => args.reduce((m, e) => (e > m ? e : m)))([
523
- offsets.base,
524
- offsets.components,
525
- offsets.utilities,
526
- offsets.user,
527
- ])
528
- let reservedBits = BigInt(highestOffset.toString(2).length)
529
-
530
- context.layerOrder = {
531
- base: (1n << reservedBits) << 0n,
532
- components: (1n << reservedBits) << 1n,
533
- utilities: (1n << reservedBits) << 2n,
534
- user: (1n << reservedBits) << 3n,
535
- }
536
-
537
- reservedBits += 4n
538
-
539
- let offset = 0
540
- context.variantOrder = new Map(
541
- variantList
542
- .map((variant, i) => {
543
- let variantFunctions = variantMap.get(variant).length
544
- let bits = (1n << BigInt(i + offset)) << reservedBits
545
- offset += variantFunctions - 1
546
- return [variant, bits]
547
- })
548
- .sort(([, a], [, z]) => bigSign(a - z))
549
- )
550
-
551
- context.minimumScreen = [...context.variantOrder.values()].shift()
552
-
553
- // Build variantMap
554
- for (let [variantName, variantFunctions] of variantMap.entries()) {
555
- let sort = context.variantOrder.get(variantName)
556
- context.variantMap.set(
557
- variantName,
558
- variantFunctions.map((variantFunction, idx) => [sort << BigInt(idx), variantFunction])
559
- )
560
- }
561
-
562
- //
563
- let warnedAbout = new Set([])
564
- context.safelist = function () {
565
- let safelist = (context.tailwindConfig.safelist ?? []).filter(Boolean)
566
- if (safelist.length <= 0) return []
567
-
568
- let output = []
569
- let checks = []
570
-
571
- for (let value of safelist) {
572
- if (typeof value === 'string') {
573
- output.push(value)
574
- continue
575
- }
576
-
577
- if (value instanceof RegExp) {
578
- if (!warnedAbout.has('root-regex')) {
579
- log.warn([
580
- // TODO: Improve this warning message
581
- 'RegExp in the safelist option is not supported.',
582
- 'Please use the object syntax instead: https://tailwindcss.com/docs/...',
583
- ])
584
- warnedAbout.add('root-regex')
585
- }
586
- continue
587
- }
588
-
589
- checks.push(value)
590
- }
591
-
592
- if (checks.length <= 0) return output.map((value) => ({ raw: value, extension: 'html' }))
593
-
594
- let patternMatchingCount = new Map()
595
-
596
- for (let util of classList) {
597
- let utils = Array.isArray(util)
598
- ? (() => {
599
- let [utilName, options] = util
600
- return Object.keys(options?.values ?? {}).map((value) => formatClass(utilName, value))
601
- })()
602
- : [util]
603
-
604
- for (let util of utils) {
605
- for (let { pattern, variants = [] } of checks) {
606
- // RegExp with the /g flag are stateful, so let's reset the last
607
- // index pointer to reset the state.
608
- pattern.lastIndex = 0
609
-
610
- if (!patternMatchingCount.has(pattern)) {
611
- patternMatchingCount.set(pattern, 0)
612
- }
613
-
614
- if (!pattern.test(util)) continue
615
-
616
- patternMatchingCount.set(pattern, patternMatchingCount.get(pattern) + 1)
617
-
618
- output.push(util)
619
- for (let variant of variants) {
620
- output.push(variant + context.tailwindConfig.separator + util)
621
- }
622
- }
623
- }
624
- }
625
-
626
- for (let [regex, count] of patternMatchingCount.entries()) {
627
- if (count !== 0) continue
628
-
629
- log.warn([
630
- // TODO: Improve this warning message
631
- `You have a regex pattern in your "safelist" config (${regex}) that doesn't match any utilities.`,
632
- 'For more info, visit https://tailwindcss.com/docs/...',
633
- ])
634
- }
635
-
636
- return output.map((value) => ({ raw: value, extension: 'html' }))
637
- }
638
-
639
- // Generate a list of strings for autocompletion purposes. Colors will have a
640
- // tuple with options, e.g.:
641
- // ['uppercase', 'lowercase', ['bg-red', { color: 'rgb(255 0 0)' }]]
642
- context.completions = function () {
643
- // TODO: Try and detect color from components?
644
- // TODO: Should we provide a simple "public api" file with functions?
645
- let output = []
646
-
647
- for (let util of classList) {
648
- if (Array.isArray(util)) {
649
- let [utilName, options] = util
650
- let isColor = [].concat(options.type).includes('color')
651
-
652
- if (isColor) {
653
- for (let [value, color] of Object.entries(options?.values ?? {})) {
654
- output.push([formatClass(utilName, value), { color }])
655
- }
656
- } else {
657
- for (let value of Object.keys(options?.values ?? {})) {
658
- output.push(formatClass(utilName, value))
659
- }
660
- }
661
- } else {
662
- output.push(util)
663
- }
664
- }
665
-
666
- return output
667
- }
668
- }
669
-
670
- export function createContext(tailwindConfig, changedContent = [], root = postcss.root()) {
671
- let context = {
672
- disposables: [],
673
- ruleCache: new Set(),
674
- classCache: new Map(),
675
- applyClassCache: new Map(),
676
- notClassCache: new Set(),
677
- postCssNodeCache: new Map(),
678
- candidateRuleMap: new Map(),
679
- tailwindConfig,
680
- changedContent: changedContent,
681
- variantMap: new Map(),
682
- stylesheetCache: null,
683
- }
684
-
685
- let resolvedPlugins = resolvePlugins(context, root)
686
- registerPlugins(resolvedPlugins, context)
687
-
688
- return context
689
- }
690
-
691
- let contextMap = sharedState.contextMap
692
- let configContextMap = sharedState.configContextMap
693
- let contextSourcesMap = sharedState.contextSourcesMap
694
-
695
- export function getContext(
696
- root,
697
- result,
698
- tailwindConfig,
699
- userConfigPath,
700
- tailwindConfigHash,
701
- contextDependencies
702
- ) {
703
- let sourcePath = result.opts.from
704
- let isConfigFile = userConfigPath !== null
705
-
706
- env.DEBUG && console.log('Source path:', sourcePath)
707
-
708
- let existingContext
709
-
710
- if (isConfigFile && contextMap.has(sourcePath)) {
711
- existingContext = contextMap.get(sourcePath)
712
- } else if (configContextMap.has(tailwindConfigHash)) {
713
- let context = configContextMap.get(tailwindConfigHash)
714
- contextSourcesMap.get(context).add(sourcePath)
715
- contextMap.set(sourcePath, context)
716
-
717
- existingContext = context
718
- }
719
-
720
- // If there's already a context in the cache and we don't need to
721
- // reset the context, return the cached context.
722
- if (existingContext) {
723
- let contextDependenciesChanged = trackModified(
724
- [...contextDependencies],
725
- getFileModifiedMap(existingContext)
726
- )
727
- if (!contextDependenciesChanged) {
728
- return [existingContext, false]
729
- }
730
- }
731
-
732
- // If this source is in the context map, get the old context.
733
- // Remove this source from the context sources for the old context,
734
- // and clean up that context if no one else is using it. This can be
735
- // called by many processes in rapid succession, so we check for presence
736
- // first because the first process to run this code will wipe it out first.
737
- if (contextMap.has(sourcePath)) {
738
- let oldContext = contextMap.get(sourcePath)
739
- if (contextSourcesMap.has(oldContext)) {
740
- contextSourcesMap.get(oldContext).delete(sourcePath)
741
- if (contextSourcesMap.get(oldContext).size === 0) {
742
- contextSourcesMap.delete(oldContext)
743
- for (let [tailwindConfigHash, context] of configContextMap) {
744
- if (context === oldContext) {
745
- configContextMap.delete(tailwindConfigHash)
746
- }
747
- }
748
- for (let disposable of oldContext.disposables.splice(0)) {
749
- disposable(oldContext)
750
- }
751
- }
752
- }
753
- }
754
-
755
- env.DEBUG && console.log('Setting up new context...')
756
-
757
- let context = createContext(tailwindConfig, [], root)
758
-
759
- trackModified([...contextDependencies], getFileModifiedMap(context))
760
-
761
- // ---
762
-
763
- // Update all context tracking state
764
-
765
- configContextMap.set(tailwindConfigHash, context)
766
- contextMap.set(sourcePath, context)
767
-
768
- if (!contextSourcesMap.has(context)) {
769
- contextSourcesMap.set(context, new Set())
770
- }
771
-
772
- contextSourcesMap.get(context).add(sourcePath)
773
-
774
- return [context, true]
775
- }