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