tailwindcss 0.0.0-insiders.ebc1c7a → 0.0.0-insiders.ec0049a

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