tailwindcss 0.0.0-insiders.deefbf5 → 0.0.0-insiders.df96ea5

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