tailwindcss 0.0.0-insiders.f9fb2ce → 0.0.0-insiders.fa3f45f

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