tailwindcss 0.0.0-insiders.bbafc8e → 0.0.0-insiders.bbc2f3f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +16 -13
  2. package/dist/chunk-5C7JPVMO.mjs +10 -0
  3. package/dist/chunk-AZANAYY2.mjs +1 -0
  4. package/dist/chunk-V2K3XTS4.mjs +1 -0
  5. package/dist/colors-b_6i0Oi7.d.ts +295 -0
  6. package/dist/colors.d.mts +295 -0
  7. package/dist/colors.d.ts +5 -0
  8. package/dist/colors.js +1 -0
  9. package/dist/colors.mjs +1 -0
  10. package/dist/default-theme.d.mts +1147 -0
  11. package/dist/default-theme.d.ts +1147 -0
  12. package/dist/default-theme.js +1 -0
  13. package/dist/default-theme.mjs +1 -0
  14. package/dist/flatten-color-palette.d.mts +6 -0
  15. package/dist/flatten-color-palette.d.ts +6 -0
  16. package/dist/flatten-color-palette.js +1 -0
  17. package/dist/flatten-color-palette.mjs +1 -0
  18. package/dist/lib.d.mts +260 -0
  19. package/dist/lib.d.ts +3 -0
  20. package/dist/lib.js +33 -0
  21. package/dist/lib.mjs +24 -0
  22. package/dist/plugin.d.mts +11 -0
  23. package/dist/plugin.d.ts +104 -0
  24. package/dist/plugin.js +1 -0
  25. package/dist/plugin.mjs +1 -0
  26. package/dist/resolve-config-BIFUA2FY.d.ts +29 -0
  27. package/dist/resolve-config-QUZ9b-Gn.d.mts +190 -0
  28. package/dist/types-B254mqw1.d.mts +98 -0
  29. package/index.css +865 -0
  30. package/package.json +73 -95
  31. package/preflight.css +383 -0
  32. package/theme.css +453 -0
  33. package/CHANGELOG.md +0 -2084
  34. package/base.css +0 -1
  35. package/colors.js +0 -2
  36. package/components.css +0 -1
  37. package/defaultConfig.js +0 -2
  38. package/defaultTheme.js +0 -2
  39. package/lib/cli-peer-dependencies.js +0 -15
  40. package/lib/cli.js +0 -741
  41. package/lib/constants.js +0 -37
  42. package/lib/corePluginList.js +0 -178
  43. package/lib/corePlugins.js +0 -3587
  44. package/lib/css/LICENSE +0 -25
  45. package/lib/css/preflight.css +0 -367
  46. package/lib/featureFlags.js +0 -59
  47. package/lib/index.js +0 -41
  48. package/lib/lib/cacheInvalidation.js +0 -69
  49. package/lib/lib/collapseAdjacentRules.js +0 -54
  50. package/lib/lib/collapseDuplicateDeclarations.js +0 -80
  51. package/lib/lib/defaultExtractor.js +0 -44
  52. package/lib/lib/detectNesting.js +0 -34
  53. package/lib/lib/evaluateTailwindFunctions.js +0 -171
  54. package/lib/lib/expandApplyAtRules.js +0 -433
  55. package/lib/lib/expandTailwindAtRules.js +0 -262
  56. package/lib/lib/generateRules.js +0 -631
  57. package/lib/lib/getModuleDependencies.js +0 -48
  58. package/lib/lib/normalizeTailwindDirectives.js +0 -84
  59. package/lib/lib/partitionApplyAtRules.js +0 -53
  60. package/lib/lib/resolveDefaultsAtRules.js +0 -143
  61. package/lib/lib/setupContextUtils.js +0 -859
  62. package/lib/lib/setupTrackingContext.js +0 -171
  63. package/lib/lib/sharedState.js +0 -52
  64. package/lib/lib/substituteScreenAtRules.js +0 -27
  65. package/lib/postcss-plugins/nesting/README.md +0 -42
  66. package/lib/postcss-plugins/nesting/index.js +0 -17
  67. package/lib/postcss-plugins/nesting/plugin.js +0 -85
  68. package/lib/processTailwindFeatures.js +0 -59
  69. package/lib/public/colors.js +0 -329
  70. package/lib/public/create-plugin.js +0 -13
  71. package/lib/public/default-config.js +0 -14
  72. package/lib/public/default-theme.js +0 -14
  73. package/lib/public/resolve-config.js +0 -19
  74. package/lib/util/bigSign.js +0 -8
  75. package/lib/util/buildMediaQuery.js +0 -20
  76. package/lib/util/cloneDeep.js +0 -19
  77. package/lib/util/cloneNodes.js +0 -25
  78. package/lib/util/color.js +0 -99
  79. package/lib/util/configurePlugins.js +0 -18
  80. package/lib/util/createPlugin.js +0 -29
  81. package/lib/util/createUtilityPlugin.js +0 -49
  82. package/lib/util/dataTypes.js +0 -233
  83. package/lib/util/defaults.js +0 -22
  84. package/lib/util/escapeClassName.js +0 -19
  85. package/lib/util/escapeCommas.js +0 -8
  86. package/lib/util/flattenColorPalette.js +0 -17
  87. package/lib/util/formatVariantSelector.js +0 -186
  88. package/lib/util/getAllConfigs.js +0 -29
  89. package/lib/util/hashConfig.js +0 -16
  90. package/lib/util/isKeyframeRule.js +0 -8
  91. package/lib/util/isPlainObject.js +0 -12
  92. package/lib/util/isValidArbitraryValue.js +0 -64
  93. package/lib/util/log.js +0 -51
  94. package/lib/util/nameClass.js +0 -32
  95. package/lib/util/negateValue.js +0 -19
  96. package/lib/util/normalizeConfig.js +0 -240
  97. package/lib/util/normalizeScreens.js +0 -59
  98. package/lib/util/parseAnimationValue.js +0 -89
  99. package/lib/util/parseBoxShadowValue.js +0 -117
  100. package/lib/util/parseDependency.js +0 -63
  101. package/lib/util/parseObjectStyles.js +0 -31
  102. package/lib/util/pluginUtils.js +0 -179
  103. package/lib/util/prefixSelector.js +0 -20
  104. package/lib/util/resolveConfig.js +0 -255
  105. package/lib/util/resolveConfigPath.js +0 -51
  106. package/lib/util/responsive.js +0 -19
  107. package/lib/util/tap.js +0 -9
  108. package/lib/util/toColorValue.js +0 -8
  109. package/lib/util/toPath.js +0 -14
  110. package/lib/util/transformThemeValue.js +0 -59
  111. package/lib/util/withAlphaVariable.js +0 -67
  112. package/nesting/index.js +0 -2
  113. package/peers/index.js +0 -75077
  114. package/plugin.js +0 -2
  115. package/prettier.config.js +0 -19
  116. package/resolveConfig.js +0 -2
  117. package/screens.css +0 -1
  118. package/scripts/create-plugin-list.js +0 -10
  119. package/scripts/install-integrations.js +0 -27
  120. package/scripts/rebuildFixtures.js +0 -68
  121. package/src/cli-peer-dependencies.js +0 -9
  122. package/src/cli.js +0 -815
  123. package/src/constants.js +0 -17
  124. package/src/corePluginList.js +0 -1
  125. package/src/corePlugins.js +0 -2365
  126. package/src/css/LICENSE +0 -25
  127. package/src/css/preflight.css +0 -367
  128. package/src/featureFlags.js +0 -54
  129. package/src/index.js +0 -42
  130. package/src/lib/cacheInvalidation.js +0 -52
  131. package/src/lib/collapseAdjacentRules.js +0 -54
  132. package/src/lib/collapseDuplicateDeclarations.js +0 -93
  133. package/src/lib/defaultExtractor.js +0 -50
  134. package/src/lib/detectNesting.js +0 -39
  135. package/src/lib/evaluateTailwindFunctions.js +0 -198
  136. package/src/lib/expandApplyAtRules.js +0 -480
  137. package/src/lib/expandTailwindAtRules.js +0 -292
  138. package/src/lib/generateRules.js +0 -623
  139. package/src/lib/getModuleDependencies.js +0 -39
  140. package/src/lib/normalizeTailwindDirectives.js +0 -84
  141. package/src/lib/partitionApplyAtRules.js +0 -52
  142. package/src/lib/resolveDefaultsAtRules.js +0 -146
  143. package/src/lib/setupContextUtils.js +0 -883
  144. package/src/lib/setupTrackingContext.js +0 -183
  145. package/src/lib/sharedState.js +0 -48
  146. package/src/lib/substituteScreenAtRules.js +0 -19
  147. package/src/postcss-plugins/nesting/README.md +0 -42
  148. package/src/postcss-plugins/nesting/index.js +0 -13
  149. package/src/postcss-plugins/nesting/plugin.js +0 -80
  150. package/src/processTailwindFeatures.js +0 -58
  151. package/src/public/colors.js +0 -300
  152. package/src/public/create-plugin.js +0 -2
  153. package/src/public/default-config.js +0 -4
  154. package/src/public/default-theme.js +0 -4
  155. package/src/public/resolve-config.js +0 -7
  156. package/src/util/bigSign.js +0 -3
  157. package/src/util/buildMediaQuery.js +0 -20
  158. package/src/util/cloneDeep.js +0 -11
  159. package/src/util/cloneNodes.js +0 -24
  160. package/src/util/color.js +0 -69
  161. package/src/util/configurePlugins.js +0 -23
  162. package/src/util/createPlugin.js +0 -27
  163. package/src/util/createUtilityPlugin.js +0 -37
  164. package/src/util/dataTypes.js +0 -248
  165. package/src/util/defaults.js +0 -17
  166. package/src/util/escapeClassName.js +0 -8
  167. package/src/util/escapeCommas.js +0 -3
  168. package/src/util/flattenColorPalette.js +0 -13
  169. package/src/util/formatVariantSelector.js +0 -196
  170. package/src/util/getAllConfigs.js +0 -19
  171. package/src/util/hashConfig.js +0 -5
  172. package/src/util/isKeyframeRule.js +0 -3
  173. package/src/util/isPlainObject.js +0 -8
  174. package/src/util/isValidArbitraryValue.js +0 -61
  175. package/src/util/log.js +0 -29
  176. package/src/util/nameClass.js +0 -26
  177. package/src/util/negateValue.js +0 -16
  178. package/src/util/normalizeConfig.js +0 -270
  179. package/src/util/normalizeScreens.js +0 -45
  180. package/src/util/parseAnimationValue.js +0 -68
  181. package/src/util/parseBoxShadowValue.js +0 -119
  182. package/src/util/parseDependency.js +0 -49
  183. package/src/util/parseObjectStyles.js +0 -19
  184. package/src/util/pluginUtils.js +0 -192
  185. package/src/util/prefixSelector.js +0 -14
  186. package/src/util/resolveConfig.js +0 -269
  187. package/src/util/resolveConfigPath.js +0 -55
  188. package/src/util/responsive.js +0 -10
  189. package/src/util/tap.js +0 -4
  190. package/src/util/toColorValue.js +0 -3
  191. package/src/util/toPath.js +0 -26
  192. package/src/util/transformThemeValue.js +0 -52
  193. package/src/util/withAlphaVariable.js +0 -49
  194. package/stubs/defaultConfig.stub.js +0 -950
  195. package/stubs/defaultPostCssConfig.stub.js +0 -6
  196. package/stubs/simpleConfig.stub.js +0 -7
  197. package/tailwind.css +0 -5
  198. package/variants.css +0 -1
@@ -1,623 +0,0 @@
1
- import postcss from 'postcss'
2
- import selectorParser from 'postcss-selector-parser'
3
- import parseObjectStyles from '../util/parseObjectStyles'
4
- import isPlainObject from '../util/isPlainObject'
5
- import prefixSelector from '../util/prefixSelector'
6
- import { updateAllClasses } from '../util/pluginUtils'
7
- import log from '../util/log'
8
- import * as sharedState from './sharedState'
9
- import { formatVariantSelector, finalizeSelector } from '../util/formatVariantSelector'
10
- import { asClass } from '../util/nameClass'
11
- import { normalize } from '../util/dataTypes'
12
- import isValidArbitraryValue from '../util/isValidArbitraryValue'
13
-
14
- let classNameParser = selectorParser((selectors) => {
15
- return selectors.first.filter(({ type }) => type === 'class').pop().value
16
- })
17
-
18
- function getClassNameFromSelector(selector) {
19
- return classNameParser.transformSync(selector)
20
- }
21
-
22
- // Generate match permutations for a class candidate, like:
23
- // ['ring-offset-blue', '100']
24
- // ['ring-offset', 'blue-100']
25
- // ['ring', 'offset-blue-100']
26
- // Example with dynamic classes:
27
- // ['grid-cols', '[[linename],1fr,auto]']
28
- // ['grid', 'cols-[[linename],1fr,auto]']
29
- function* candidatePermutations(candidate) {
30
- let lastIndex = Infinity
31
-
32
- while (lastIndex >= 0) {
33
- let dashIdx
34
-
35
- if (lastIndex === Infinity && candidate.endsWith(']')) {
36
- let bracketIdx = candidate.indexOf('[')
37
-
38
- // If character before `[` isn't a dash or a slash, this isn't a dynamic class
39
- // eg. string[]
40
- dashIdx = ['-', '/'].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1
41
- } else {
42
- dashIdx = candidate.lastIndexOf('-', lastIndex)
43
- }
44
-
45
- if (dashIdx < 0) {
46
- break
47
- }
48
-
49
- let prefix = candidate.slice(0, dashIdx)
50
- let modifier = candidate.slice(dashIdx + 1)
51
-
52
- yield [prefix, modifier]
53
-
54
- lastIndex = dashIdx - 1
55
- }
56
- }
57
-
58
- function applyPrefix(matches, context) {
59
- if (matches.length === 0 || context.tailwindConfig.prefix === '') {
60
- return matches
61
- }
62
-
63
- for (let match of matches) {
64
- let [meta] = match
65
- if (meta.options.respectPrefix) {
66
- let container = postcss.root({ nodes: [match[1].clone()] })
67
- let classCandidate = match[1].raws.tailwind.classCandidate
68
-
69
- container.walkRules((r) => {
70
- // If this is a negative utility with a dash *before* the prefix we
71
- // have to ensure that the generated selector matches the candidate
72
-
73
- // Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
74
- // The disconnect between candidate <-> class can cause @apply to hard crash.
75
- let shouldPrependNegative = classCandidate.startsWith('-')
76
-
77
- r.selector = prefixSelector(
78
- context.tailwindConfig.prefix,
79
- r.selector,
80
- shouldPrependNegative
81
- )
82
- })
83
-
84
- match[1] = container.nodes[0]
85
- }
86
- }
87
-
88
- return matches
89
- }
90
-
91
- function applyImportant(matches, classCandidate) {
92
- if (matches.length === 0) {
93
- return matches
94
- }
95
- let result = []
96
-
97
- for (let [meta, rule] of matches) {
98
- let container = postcss.root({ nodes: [rule.clone()] })
99
- container.walkRules((r) => {
100
- r.selector = updateAllClasses(r.selector, (className) => {
101
- if (className === classCandidate) {
102
- return `!${className}`
103
- }
104
- return className
105
- })
106
- r.walkDecls((d) => (d.important = true))
107
- })
108
- result.push([{ ...meta, important: true }, container.nodes[0]])
109
- }
110
-
111
- return result
112
- }
113
-
114
- // Takes a list of rule tuples and applies a variant like `hover`, sm`,
115
- // whatever to it. We used to do some extra caching here to avoid generating
116
- // a variant of the same rule more than once, but this was never hit because
117
- // we cache at the entire selector level further up the tree.
118
- //
119
- // Technically you can get a cache hit if you have `hover:focus:text-center`
120
- // and `focus:hover:text-center` in the same project, but it doesn't feel
121
- // worth the complexity for that case.
122
-
123
- function applyVariant(variant, matches, context) {
124
- if (matches.length === 0) {
125
- return matches
126
- }
127
-
128
- if (context.variantMap.has(variant)) {
129
- let variantFunctionTuples = context.variantMap.get(variant)
130
- let result = []
131
-
132
- for (let [meta, rule] of matches) {
133
- // Don't generate variants for user css
134
- if (meta.layer === 'user') {
135
- continue
136
- }
137
-
138
- let container = postcss.root({ nodes: [rule.clone()] })
139
-
140
- for (let [variantSort, variantFunction] of variantFunctionTuples) {
141
- let clone = container.clone()
142
- let collectedFormats = []
143
-
144
- let originals = new Map()
145
-
146
- function prepareBackup() {
147
- if (originals.size > 0) return // Already prepared, chicken out
148
- clone.walkRules((rule) => originals.set(rule, rule.selector))
149
- }
150
-
151
- function modifySelectors(modifierFunction) {
152
- prepareBackup()
153
- clone.each((rule) => {
154
- if (rule.type !== 'rule') {
155
- return
156
- }
157
-
158
- rule.selectors = rule.selectors.map((selector) => {
159
- return modifierFunction({
160
- get className() {
161
- return getClassNameFromSelector(selector)
162
- },
163
- selector,
164
- })
165
- })
166
- })
167
-
168
- return clone
169
- }
170
-
171
- let ruleWithVariant = variantFunction({
172
- // Public API
173
- get container() {
174
- prepareBackup()
175
- return clone
176
- },
177
- separator: context.tailwindConfig.separator,
178
- modifySelectors,
179
-
180
- // Private API for now
181
- wrap(wrapper) {
182
- let nodes = clone.nodes
183
- clone.removeAll()
184
- wrapper.append(nodes)
185
- clone.append(wrapper)
186
- },
187
- format(selectorFormat) {
188
- collectedFormats.push(selectorFormat)
189
- },
190
- })
191
-
192
- if (typeof ruleWithVariant === 'string') {
193
- collectedFormats.push(ruleWithVariant)
194
- }
195
-
196
- if (ruleWithVariant === null) {
197
- continue
198
- }
199
-
200
- // We filled the `originals`, therefore we assume that somebody touched
201
- // `container` or `modifySelectors`. Let's see if they did, so that we
202
- // can restore the selectors, and collect the format strings.
203
- if (originals.size > 0) {
204
- clone.walkRules((rule) => {
205
- if (!originals.has(rule)) return
206
- let before = originals.get(rule)
207
- if (before === rule.selector) return // No mutation happened
208
-
209
- let modified = rule.selector
210
-
211
- // Rebuild the base selector, this is what plugin authors would do
212
- // as well. E.g.: `${variant}${separator}${className}`.
213
- // However, plugin authors probably also prepend or append certain
214
- // classes, pseudos, ids, ...
215
- let rebuiltBase = selectorParser((selectors) => {
216
- selectors.walkClasses((classNode) => {
217
- classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`
218
- })
219
- }).processSync(before)
220
-
221
- // Now that we know the original selector, the new selector, and
222
- // the rebuild part in between, we can replace the part that plugin
223
- // authors need to rebuild with `&`, and eventually store it in the
224
- // collectedFormats. Similar to what `format('...')` would do.
225
- //
226
- // E.g.:
227
- // variant: foo
228
- // selector: .markdown > p
229
- // modified (by plugin): .foo .foo\\:markdown > p
230
- // rebuiltBase (internal): .foo\\:markdown > p
231
- // format: .foo &
232
- collectedFormats.push(modified.replace(rebuiltBase, '&'))
233
- rule.selector = before
234
- })
235
- }
236
-
237
- // This tracks the originating layer for the variant
238
- // For example:
239
- // .sm:underline {} is a variant of something in the utilities layer
240
- // .sm:container {} is a variant of the container component
241
- clone.nodes[0].raws.tailwind = { ...clone.nodes[0].raws.tailwind, parentLayer: meta.layer }
242
-
243
- let withOffset = [
244
- {
245
- ...meta,
246
- sort: variantSort | meta.sort,
247
- collectedFormats: (meta.collectedFormats ?? []).concat(collectedFormats),
248
- },
249
- clone.nodes[0],
250
- ]
251
- result.push(withOffset)
252
- }
253
- }
254
-
255
- return result
256
- }
257
-
258
- return []
259
- }
260
-
261
- function parseRules(rule, cache, options = {}) {
262
- // PostCSS node
263
- if (!isPlainObject(rule) && !Array.isArray(rule)) {
264
- return [[rule], options]
265
- }
266
-
267
- // Tuple
268
- if (Array.isArray(rule)) {
269
- return parseRules(rule[0], cache, rule[1])
270
- }
271
-
272
- // Simple object
273
- if (!cache.has(rule)) {
274
- cache.set(rule, parseObjectStyles(rule))
275
- }
276
-
277
- return [cache.get(rule), options]
278
- }
279
-
280
- const IS_VALID_PROPERTY_NAME = /^[a-z_-]/
281
-
282
- function isValidPropName(name) {
283
- return IS_VALID_PROPERTY_NAME.test(name)
284
- }
285
-
286
- /**
287
- * @param {string} declaration
288
- * @returns {boolean}
289
- */
290
- function looksLikeUri(declaration) {
291
- // Quick bailout for obvious non-urls
292
- // This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
293
- if (!declaration.includes('://')) {
294
- return false
295
- }
296
-
297
- try {
298
- const url = new URL(declaration)
299
- return url.scheme !== '' && url.host !== ''
300
- } catch (err) {
301
- // Definitely not a valid url
302
- return false
303
- }
304
- }
305
-
306
- function isParsableCssValue(property, value) {
307
- // We don't want to to treat [https://example.com] as a custom property
308
- // Even though, according to the CSS grammar, it's a totally valid CSS declaration
309
- // So we short-circuit here by checking if the custom property looks like a url
310
- if (looksLikeUri(`${property}:${value}`)) {
311
- return false
312
- }
313
-
314
- try {
315
- postcss.parse(`a{${property}:${value}}`).toResult()
316
- return true
317
- } catch (err) {
318
- return false
319
- }
320
- }
321
-
322
- function extractArbitraryProperty(classCandidate, context) {
323
- let [, property, value] = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/) ?? []
324
-
325
- if (value === undefined) {
326
- return null
327
- }
328
-
329
- if (!isValidPropName(property)) {
330
- return null
331
- }
332
-
333
- if (!isValidArbitraryValue(value)) {
334
- return null
335
- }
336
-
337
- let normalized = normalize(value)
338
-
339
- if (!isParsableCssValue(property, normalized)) {
340
- return null
341
- }
342
-
343
- return [
344
- [
345
- { sort: context.arbitraryPropertiesSort, layer: 'utilities' },
346
- () => ({
347
- [asClass(classCandidate)]: {
348
- [property]: normalized,
349
- },
350
- }),
351
- ],
352
- ]
353
- }
354
-
355
- function* resolveMatchedPlugins(classCandidate, context) {
356
- if (context.candidateRuleMap.has(classCandidate)) {
357
- yield [context.candidateRuleMap.get(classCandidate), 'DEFAULT']
358
- }
359
-
360
- yield* (function* (arbitraryPropertyRule) {
361
- if (arbitraryPropertyRule !== null) {
362
- yield [arbitraryPropertyRule, 'DEFAULT']
363
- }
364
- })(extractArbitraryProperty(classCandidate, context))
365
-
366
- let candidatePrefix = classCandidate
367
- let negative = false
368
-
369
- const twConfigPrefix = context.tailwindConfig.prefix
370
-
371
- const twConfigPrefixLen = twConfigPrefix.length
372
- if (candidatePrefix[twConfigPrefixLen] === '-') {
373
- negative = true
374
- candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)
375
- }
376
-
377
- if (negative && context.candidateRuleMap.has(candidatePrefix)) {
378
- yield [context.candidateRuleMap.get(candidatePrefix), '-DEFAULT']
379
- }
380
-
381
- for (let [prefix, modifier] of candidatePermutations(candidatePrefix)) {
382
- if (context.candidateRuleMap.has(prefix)) {
383
- yield [context.candidateRuleMap.get(prefix), negative ? `-${modifier}` : modifier]
384
- }
385
- }
386
- }
387
-
388
- function splitWithSeparator(input, separator) {
389
- if (input === sharedState.NOT_ON_DEMAND) {
390
- return [sharedState.NOT_ON_DEMAND]
391
- }
392
-
393
- return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'))
394
- }
395
-
396
- function* recordCandidates(matches, classCandidate) {
397
- for (const match of matches) {
398
- match[1].raws.tailwind = { ...match[1].raws.tailwind, classCandidate }
399
-
400
- yield match
401
- }
402
- }
403
-
404
- function* resolveMatches(candidate, context) {
405
- let separator = context.tailwindConfig.separator
406
- let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse()
407
- let important = false
408
-
409
- if (classCandidate.startsWith('!')) {
410
- important = true
411
- classCandidate = classCandidate.slice(1)
412
- }
413
-
414
- // TODO: Reintroduce this in ways that doesn't break on false positives
415
- // function sortAgainst(toSort, against) {
416
- // return toSort.slice().sort((a, z) => {
417
- // return bigSign(against.get(a)[0] - against.get(z)[0])
418
- // })
419
- // }
420
- // let sorted = sortAgainst(variants, context.variantMap)
421
- // if (sorted.toString() !== variants.toString()) {
422
- // let corrected = sorted.reverse().concat(classCandidate).join(':')
423
- // throw new Error(`Class ${candidate} should be written as ${corrected}`)
424
- // }
425
-
426
- for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)) {
427
- let matches = []
428
- let typesByMatches = new Map()
429
-
430
- let [plugins, modifier] = matchedPlugins
431
- let isOnlyPlugin = plugins.length === 1
432
-
433
- for (let [sort, plugin] of plugins) {
434
- let matchesPerPlugin = []
435
-
436
- if (typeof plugin === 'function') {
437
- for (let ruleSet of [].concat(plugin(modifier, { isOnlyPlugin }))) {
438
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
439
- for (let rule of rules) {
440
- matchesPerPlugin.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
441
- }
442
- }
443
- }
444
- // Only process static plugins on exact matches
445
- else if (modifier === 'DEFAULT' || modifier === '-DEFAULT') {
446
- let ruleSet = plugin
447
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
448
- for (let rule of rules) {
449
- matchesPerPlugin.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
450
- }
451
- }
452
-
453
- if (matchesPerPlugin.length > 0) {
454
- typesByMatches.set(matchesPerPlugin, sort.options?.type)
455
- matches.push(matchesPerPlugin)
456
- }
457
- }
458
-
459
- // Only keep the result of the very first plugin if we are dealing with
460
- // arbitrary values, to protect against ambiguity.
461
- if (isArbitraryValue(modifier) && matches.length > 1) {
462
- let typesPerPlugin = matches.map((match) => new Set([...(typesByMatches.get(match) ?? [])]))
463
-
464
- // Remove duplicates, so that we can detect proper unique types for each plugin.
465
- for (let pluginTypes of typesPerPlugin) {
466
- for (let type of pluginTypes) {
467
- let removeFromOwnGroup = false
468
-
469
- for (let otherGroup of typesPerPlugin) {
470
- if (pluginTypes === otherGroup) continue
471
-
472
- if (otherGroup.has(type)) {
473
- otherGroup.delete(type)
474
- removeFromOwnGroup = true
475
- }
476
- }
477
-
478
- if (removeFromOwnGroup) pluginTypes.delete(type)
479
- }
480
- }
481
-
482
- let messages = []
483
-
484
- for (let [idx, group] of typesPerPlugin.entries()) {
485
- for (let type of group) {
486
- let rules = matches[idx]
487
- .map(([, rule]) => rule)
488
- .flat()
489
- .map((rule) =>
490
- rule
491
- .toString()
492
- .split('\n')
493
- .slice(1, -1) // Remove selector and closing '}'
494
- .map((line) => line.trim())
495
- .map((x) => ` ${x}`) // Re-indent
496
- .join('\n')
497
- )
498
- .join('\n\n')
499
-
500
- messages.push(` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``)
501
- break
502
- }
503
- }
504
-
505
- log.warn([
506
- `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
507
- ...messages,
508
- `If this is content and not a class, replace it with \`${candidate
509
- .replace('[', '&lsqb;')
510
- .replace(']', '&rsqb;')}\` to silence this warning.`,
511
- ])
512
- continue
513
- }
514
-
515
- matches = matches.flat()
516
- matches = Array.from(recordCandidates(matches, classCandidate))
517
- matches = applyPrefix(matches, context)
518
-
519
- if (important) {
520
- matches = applyImportant(matches, classCandidate)
521
- }
522
-
523
- for (let variant of variants) {
524
- matches = applyVariant(variant, matches, context)
525
- }
526
-
527
- for (let match of matches) {
528
- match[1].raws.tailwind = { ...match[1].raws.tailwind, candidate }
529
-
530
- // Apply final format selector
531
- if (match[0].collectedFormats) {
532
- let finalFormat = formatVariantSelector('&', ...match[0].collectedFormats)
533
- let container = postcss.root({ nodes: [match[1].clone()] })
534
- container.walkRules((rule) => {
535
- if (inKeyframes(rule)) return
536
-
537
- rule.selector = finalizeSelector(finalFormat, {
538
- selector: rule.selector,
539
- candidate,
540
- context,
541
- })
542
- })
543
- match[1] = container.nodes[0]
544
- }
545
-
546
- yield match
547
- }
548
- }
549
- }
550
-
551
- function inKeyframes(rule) {
552
- return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
553
- }
554
-
555
- function generateRules(candidates, context) {
556
- let allRules = []
557
-
558
- for (let candidate of candidates) {
559
- if (context.notClassCache.has(candidate)) {
560
- continue
561
- }
562
-
563
- if (context.classCache.has(candidate)) {
564
- allRules.push(context.classCache.get(candidate))
565
- continue
566
- }
567
-
568
- let matches = Array.from(resolveMatches(candidate, context))
569
-
570
- if (matches.length === 0) {
571
- context.notClassCache.add(candidate)
572
- continue
573
- }
574
-
575
- context.classCache.set(candidate, matches)
576
- allRules.push(matches)
577
- }
578
-
579
- // Strategy based on `tailwindConfig.important`
580
- let strategy = ((important) => {
581
- if (important === true) {
582
- return (rule) => {
583
- rule.walkDecls((d) => {
584
- if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
585
- d.important = true
586
- }
587
- })
588
- }
589
- }
590
-
591
- if (typeof important === 'string') {
592
- return (rule) => {
593
- rule.selectors = rule.selectors.map((selector) => {
594
- return `${important} ${selector}`
595
- })
596
- }
597
- }
598
- })(context.tailwindConfig.important)
599
-
600
- return allRules.flat(1).map(([{ sort, layer, options }, rule]) => {
601
- if (options.respectImportant) {
602
- if (strategy) {
603
- let container = postcss.root({ nodes: [rule.clone()] })
604
- container.walkRules((r) => {
605
- if (inKeyframes(r)) {
606
- return
607
- }
608
-
609
- strategy(r)
610
- })
611
- rule = container.nodes[0]
612
- }
613
- }
614
-
615
- return [sort | context.layerOrder[layer], rule]
616
- })
617
- }
618
-
619
- function isArbitraryValue(input) {
620
- return input.startsWith('[') && input.endsWith(']')
621
- }
622
-
623
- export { resolveMatches, generateRules }
@@ -1,39 +0,0 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
- import resolve from 'resolve'
4
- import detective from 'detective'
5
-
6
- function createModule(file) {
7
- const source = fs.readFileSync(file, 'utf-8')
8
- const requires = detective(source)
9
-
10
- return { file, requires }
11
- }
12
-
13
- export default function getModuleDependencies(entryFile) {
14
- const rootModule = createModule(entryFile)
15
- const modules = [rootModule]
16
-
17
- // Iterate over the modules, even when new
18
- // ones are being added
19
- for (const mdl of modules) {
20
- mdl.requires
21
- .filter((dep) => {
22
- // Only track local modules, not node_modules
23
- return dep.startsWith('./') || dep.startsWith('../')
24
- })
25
- .forEach((dep) => {
26
- try {
27
- const basedir = path.dirname(mdl.file)
28
- const depPath = resolve.sync(dep, { basedir })
29
- const depModule = createModule(depPath)
30
-
31
- modules.push(depModule)
32
- } catch (_err) {
33
- // eslint-disable-next-line no-empty
34
- }
35
- })
36
- }
37
-
38
- return modules
39
- }