tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.ca7b10e

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 (179) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +18 -11
  3. package/dist/chunk-7MHEDNEU.mjs +1 -0
  4. package/dist/chunk-AZANAYY2.mjs +1 -0
  5. package/dist/chunk-YTVGJJD3.mjs +12 -0
  6. package/dist/colors-b_6i0Oi7.d.ts +295 -0
  7. package/dist/colors.d.mts +295 -0
  8. package/dist/colors.d.ts +5 -0
  9. package/dist/colors.js +1 -0
  10. package/dist/colors.mjs +1 -0
  11. package/dist/default-theme.d.mts +1147 -0
  12. package/dist/default-theme.d.ts +1147 -0
  13. package/dist/default-theme.js +1 -0
  14. package/dist/default-theme.mjs +1 -0
  15. package/dist/flatten-color-palette.d.mts +6 -0
  16. package/dist/flatten-color-palette.d.ts +6 -0
  17. package/dist/flatten-color-palette.js +1 -0
  18. package/dist/flatten-color-palette.mjs +1 -0
  19. package/dist/lib.d.mts +264 -0
  20. package/dist/lib.d.ts +3 -0
  21. package/dist/lib.js +33 -0
  22. package/dist/lib.mjs +22 -0
  23. package/dist/plugin.d.mts +11 -0
  24. package/dist/plugin.d.ts +104 -0
  25. package/dist/plugin.js +1 -0
  26. package/dist/plugin.mjs +1 -0
  27. package/dist/resolve-config-BIFUA2FY.d.ts +29 -0
  28. package/dist/resolve-config-QUZ9b-Gn.d.mts +190 -0
  29. package/dist/types-B254mqw1.d.mts +98 -0
  30. package/index.css +866 -0
  31. package/package.json +73 -100
  32. package/preflight.css +375 -0
  33. package/theme.css +453 -0
  34. package/CHANGELOG.md +0 -1758
  35. package/base.css +0 -1
  36. package/colors.js +0 -1
  37. package/components.css +0 -1
  38. package/defaultConfig.js +0 -1
  39. package/defaultTheme.js +0 -1
  40. package/lib/cli-peer-dependencies.js +0 -15
  41. package/lib/cli.js +0 -707
  42. package/lib/constants.js +0 -37
  43. package/lib/corePluginList.js +0 -169
  44. package/lib/corePlugins.js +0 -3525
  45. package/lib/css/LICENSE +0 -25
  46. package/lib/css/preflight.css +0 -354
  47. package/lib/featureFlags.js +0 -57
  48. package/lib/index.js +0 -32
  49. package/lib/lib/collapseAdjacentRules.js +0 -41
  50. package/lib/lib/detectNesting.js +0 -19
  51. package/lib/lib/evaluateTailwindFunctions.js +0 -167
  52. package/lib/lib/expandApplyAtRules.js +0 -228
  53. package/lib/lib/expandTailwindAtRules.js +0 -257
  54. package/lib/lib/generateRules.js +0 -350
  55. package/lib/lib/getModuleDependencies.js +0 -48
  56. package/lib/lib/normalizeTailwindDirectives.js +0 -75
  57. package/lib/lib/resolveDefaultsAtRules.js +0 -128
  58. package/lib/lib/setupContextUtils.js +0 -791
  59. package/lib/lib/setupTrackingContext.js +0 -170
  60. package/lib/lib/setupWatchingContext.js +0 -284
  61. package/lib/lib/sharedState.js +0 -29
  62. package/lib/lib/substituteScreenAtRules.js +0 -24
  63. package/lib/processTailwindFeatures.js +0 -47
  64. package/lib/public/colors.js +0 -333
  65. package/lib/public/create-plugin.js +0 -13
  66. package/lib/public/default-config.js +0 -14
  67. package/lib/public/default-theme.js +0 -14
  68. package/lib/public/resolve-config.js +0 -19
  69. package/lib/util/bigSign.js +0 -8
  70. package/lib/util/buildMediaQuery.js +0 -31
  71. package/lib/util/cloneDeep.js +0 -19
  72. package/lib/util/cloneNodes.js +0 -14
  73. package/lib/util/color.js +0 -84
  74. package/lib/util/configurePlugins.js +0 -18
  75. package/lib/util/createPlugin.js +0 -30
  76. package/lib/util/createUtilityPlugin.js +0 -53
  77. package/lib/util/dataTypes.js +0 -202
  78. package/lib/util/defaults.js +0 -16
  79. package/lib/util/escapeClassName.js +0 -19
  80. package/lib/util/escapeCommas.js +0 -8
  81. package/lib/util/flattenColorPalette.js +0 -19
  82. package/lib/util/getAllConfigs.js +0 -29
  83. package/lib/util/hashConfig.js +0 -16
  84. package/lib/util/isKeyframeRule.js +0 -8
  85. package/lib/util/isPlainObject.js +0 -12
  86. package/lib/util/log.js +0 -35
  87. package/lib/util/nameClass.js +0 -31
  88. package/lib/util/negateValue.js +0 -17
  89. package/lib/util/parseAnimationValue.js +0 -89
  90. package/lib/util/parseDependency.js +0 -63
  91. package/lib/util/parseObjectStyles.js +0 -31
  92. package/lib/util/pluginUtils.js +0 -282
  93. package/lib/util/prefixSelector.js +0 -23
  94. package/lib/util/resolveConfig.js +0 -293
  95. package/lib/util/resolveConfigPath.js +0 -52
  96. package/lib/util/responsive.js +0 -19
  97. package/lib/util/tap.js +0 -9
  98. package/lib/util/toColorValue.js +0 -9
  99. package/lib/util/toPath.js +0 -9
  100. package/lib/util/transformThemeValue.js +0 -53
  101. package/lib/util/withAlphaVariable.js +0 -67
  102. package/nesting/README.md +0 -42
  103. package/nesting/index.js +0 -12
  104. package/nesting/plugin.js +0 -41
  105. package/peers/index.js +0 -77111
  106. package/plugin.js +0 -1
  107. package/prettier.config.js +0 -19
  108. package/resolveConfig.js +0 -1
  109. package/screens.css +0 -1
  110. package/scripts/create-plugin-list.js +0 -10
  111. package/scripts/install-integrations.js +0 -27
  112. package/scripts/rebuildFixtures.js +0 -68
  113. package/src/cli-peer-dependencies.js +0 -9
  114. package/src/cli.js +0 -762
  115. package/src/constants.js +0 -17
  116. package/src/corePluginList.js +0 -1
  117. package/src/corePlugins.js +0 -2382
  118. package/src/css/LICENSE +0 -25
  119. package/src/css/preflight.css +0 -354
  120. package/src/featureFlags.js +0 -48
  121. package/src/index.js +0 -34
  122. package/src/lib/collapseAdjacentRules.js +0 -39
  123. package/src/lib/detectNesting.js +0 -20
  124. package/src/lib/evaluateTailwindFunctions.js +0 -195
  125. package/src/lib/expandApplyAtRules.js +0 -251
  126. package/src/lib/expandTailwindAtRules.js +0 -266
  127. package/src/lib/generateRules.js +0 -320
  128. package/src/lib/getModuleDependencies.js +0 -39
  129. package/src/lib/normalizeTailwindDirectives.js +0 -77
  130. package/src/lib/resolveDefaultsAtRules.js +0 -125
  131. package/src/lib/setupContextUtils.js +0 -775
  132. package/src/lib/setupTrackingContext.js +0 -184
  133. package/src/lib/setupWatchingContext.js +0 -306
  134. package/src/lib/sharedState.js +0 -13
  135. package/src/lib/substituteScreenAtRules.js +0 -16
  136. package/src/processTailwindFeatures.js +0 -43
  137. package/src/public/colors.js +0 -305
  138. package/src/public/create-plugin.js +0 -2
  139. package/src/public/default-config.js +0 -4
  140. package/src/public/default-theme.js +0 -4
  141. package/src/public/resolve-config.js +0 -7
  142. package/src/util/bigSign.js +0 -3
  143. package/src/util/buildMediaQuery.js +0 -24
  144. package/src/util/cloneDeep.js +0 -11
  145. package/src/util/cloneNodes.js +0 -11
  146. package/src/util/color.js +0 -56
  147. package/src/util/configurePlugins.js +0 -23
  148. package/src/util/createPlugin.js +0 -27
  149. package/src/util/createUtilityPlugin.js +0 -37
  150. package/src/util/dataTypes.js +0 -216
  151. package/src/util/defaults.js +0 -11
  152. package/src/util/escapeClassName.js +0 -8
  153. package/src/util/escapeCommas.js +0 -3
  154. package/src/util/flattenColorPalette.js +0 -13
  155. package/src/util/getAllConfigs.js +0 -19
  156. package/src/util/hashConfig.js +0 -5
  157. package/src/util/isKeyframeRule.js +0 -3
  158. package/src/util/isPlainObject.js +0 -8
  159. package/src/util/log.js +0 -28
  160. package/src/util/nameClass.js +0 -26
  161. package/src/util/negateValue.js +0 -14
  162. package/src/util/parseAnimationValue.js +0 -68
  163. package/src/util/parseDependency.js +0 -49
  164. package/src/util/parseObjectStyles.js +0 -19
  165. package/src/util/pluginUtils.js +0 -288
  166. package/src/util/prefixSelector.js +0 -15
  167. package/src/util/resolveConfig.js +0 -282
  168. package/src/util/resolveConfigPath.js +0 -55
  169. package/src/util/responsive.js +0 -10
  170. package/src/util/tap.js +0 -4
  171. package/src/util/toColorValue.js +0 -3
  172. package/src/util/toPath.js +0 -4
  173. package/src/util/transformThemeValue.js +0 -37
  174. package/src/util/withAlphaVariable.js +0 -49
  175. package/stubs/defaultConfig.stub.js +0 -890
  176. package/stubs/defaultPostCssConfig.stub.js +0 -6
  177. package/stubs/simpleConfig.stub.js +0 -8
  178. package/tailwind.css +0 -5
  179. package/variants.css +0 -1
@@ -1,320 +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
-
8
- let classNameParser = selectorParser((selectors) => {
9
- return selectors.first.filter(({ type }) => type === 'class').pop().value
10
- })
11
-
12
- function getClassNameFromSelector(selector) {
13
- return classNameParser.transformSync(selector)
14
- }
15
-
16
- // Generate match permutations for a class candidate, like:
17
- // ['ring-offset-blue', '100']
18
- // ['ring-offset', 'blue-100']
19
- // ['ring', 'offset-blue-100']
20
- // Example with dynamic classes:
21
- // ['grid-cols', '[[linename],1fr,auto]']
22
- // ['grid', 'cols-[[linename],1fr,auto]']
23
- function* candidatePermutations(candidate, lastIndex = Infinity) {
24
- if (lastIndex < 0) {
25
- return
26
- }
27
-
28
- let dashIdx
29
-
30
- if (lastIndex === Infinity && candidate.endsWith(']')) {
31
- let bracketIdx = candidate.indexOf('[')
32
-
33
- // If character before `[` isn't a dash or a slash, this isn't a dynamic class
34
- // eg. string[]
35
- dashIdx = ['-', '/'].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1
36
- } else {
37
- dashIdx = candidate.lastIndexOf('-', lastIndex)
38
- }
39
-
40
- if (dashIdx < 0) {
41
- return
42
- }
43
-
44
- let prefix = candidate.slice(0, dashIdx)
45
- let modifier = candidate.slice(dashIdx + 1)
46
-
47
- yield [prefix, modifier]
48
-
49
- yield* candidatePermutations(candidate, dashIdx - 1)
50
- }
51
-
52
- function applyPrefix(matches, context) {
53
- if (matches.length === 0 || context.tailwindConfig.prefix === '') {
54
- return matches
55
- }
56
-
57
- for (let match of matches) {
58
- let [meta] = match
59
- if (meta.options.respectPrefix) {
60
- let container = postcss.root({ nodes: [match[1].clone()] })
61
- container.walkRules((r) => {
62
- r.selector = prefixSelector(context.tailwindConfig.prefix, r.selector)
63
- })
64
- match[1] = container.nodes[0]
65
- }
66
- }
67
-
68
- return matches
69
- }
70
-
71
- function applyImportant(matches) {
72
- if (matches.length === 0) {
73
- return matches
74
- }
75
- let result = []
76
-
77
- for (let [meta, rule] of matches) {
78
- let container = postcss.root({ nodes: [rule.clone()] })
79
- container.walkRules((r) => {
80
- r.selector = updateAllClasses(r.selector, (className) => {
81
- return `!${className}`
82
- })
83
- r.walkDecls((d) => (d.important = true))
84
- })
85
- result.push([{ ...meta, important: true }, container.nodes[0]])
86
- }
87
-
88
- return result
89
- }
90
-
91
- // Takes a list of rule tuples and applies a variant like `hover`, sm`,
92
- // whatever to it. We used to do some extra caching here to avoid generating
93
- // a variant of the same rule more than once, but this was never hit because
94
- // we cache at the entire selector level further up the tree.
95
- //
96
- // Technically you can get a cache hit if you have `hover:focus:text-center`
97
- // and `focus:hover:text-center` in the same project, but it doesn't feel
98
- // worth the complexity for that case.
99
-
100
- function applyVariant(variant, matches, context) {
101
- if (matches.length === 0) {
102
- return matches
103
- }
104
-
105
- if (context.variantMap.has(variant)) {
106
- let variantFunctionTuples = context.variantMap.get(variant)
107
- let result = []
108
-
109
- for (let [meta, rule] of matches) {
110
- if (meta.options.respectVariants === false) {
111
- result.push([meta, rule])
112
- continue
113
- }
114
-
115
- let container = postcss.root({ nodes: [rule.clone()] })
116
-
117
- for (let [variantSort, variantFunction] of variantFunctionTuples) {
118
- let clone = container.clone()
119
- function modifySelectors(modifierFunction) {
120
- clone.each((rule) => {
121
- if (rule.type !== 'rule') {
122
- return
123
- }
124
-
125
- rule.selectors = rule.selectors.map((selector) => {
126
- return modifierFunction({
127
- get className() {
128
- return getClassNameFromSelector(selector)
129
- },
130
- selector,
131
- })
132
- })
133
- })
134
- return clone
135
- }
136
-
137
- let ruleWithVariant = variantFunction({
138
- container: clone,
139
- separator: context.tailwindConfig.separator,
140
- modifySelectors,
141
- })
142
-
143
- if (ruleWithVariant === null) {
144
- continue
145
- }
146
-
147
- let withOffset = [{ ...meta, sort: variantSort | meta.sort }, clone.nodes[0]]
148
- result.push(withOffset)
149
- }
150
- }
151
-
152
- return result
153
- }
154
-
155
- return []
156
- }
157
-
158
- function parseRules(rule, cache, options = {}) {
159
- // PostCSS node
160
- if (!isPlainObject(rule) && !Array.isArray(rule)) {
161
- return [[rule], options]
162
- }
163
-
164
- // Tuple
165
- if (Array.isArray(rule)) {
166
- return parseRules(rule[0], cache, rule[1])
167
- }
168
-
169
- // Simple object
170
- if (!cache.has(rule)) {
171
- cache.set(rule, parseObjectStyles(rule))
172
- }
173
-
174
- return [cache.get(rule), options]
175
- }
176
-
177
- function* resolveMatchedPlugins(classCandidate, context) {
178
- if (context.candidateRuleMap.has(classCandidate)) {
179
- yield [context.candidateRuleMap.get(classCandidate), 'DEFAULT']
180
- }
181
-
182
- let candidatePrefix = classCandidate
183
- let negative = false
184
-
185
- const twConfigPrefix = context.tailwindConfig.prefix || ''
186
- const twConfigPrefixLen = twConfigPrefix.length
187
- if (candidatePrefix[twConfigPrefixLen] === '-') {
188
- negative = true
189
- candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)
190
- }
191
-
192
- for (let [prefix, modifier] of candidatePermutations(candidatePrefix)) {
193
- if (context.candidateRuleMap.has(prefix)) {
194
- yield [context.candidateRuleMap.get(prefix), negative ? `-${modifier}` : modifier]
195
- return
196
- }
197
- }
198
- }
199
-
200
- function splitWithSeparator(input, separator) {
201
- return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'))
202
- }
203
-
204
- function* resolveMatches(candidate, context) {
205
- let separator = context.tailwindConfig.separator
206
- let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse()
207
- let important = false
208
-
209
- if (classCandidate.startsWith('!')) {
210
- important = true
211
- classCandidate = classCandidate.slice(1)
212
- }
213
-
214
- // TODO: Reintroduce this in ways that doesn't break on false positives
215
- // function sortAgainst(toSort, against) {
216
- // return toSort.slice().sort((a, z) => {
217
- // return bigSign(against.get(a)[0] - against.get(z)[0])
218
- // })
219
- // }
220
- // let sorted = sortAgainst(variants, context.variantMap)
221
- // if (sorted.toString() !== variants.toString()) {
222
- // let corrected = sorted.reverse().concat(classCandidate).join(':')
223
- // throw new Error(`Class ${candidate} should be written as ${corrected}`)
224
- // }
225
-
226
- for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)) {
227
- let matches = []
228
- let [plugins, modifier] = matchedPlugins
229
- let isOnlyPlugin = plugins.length === 1
230
-
231
- for (let [sort, plugin] of plugins) {
232
- if (typeof plugin === 'function') {
233
- for (let ruleSet of [].concat(plugin(modifier, { isOnlyPlugin }))) {
234
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
235
- for (let rule of rules) {
236
- matches.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
237
- }
238
- }
239
- }
240
- // Only process static plugins on exact matches
241
- else if (modifier === 'DEFAULT') {
242
- let ruleSet = plugin
243
- let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
244
- for (let rule of rules) {
245
- matches.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
246
- }
247
- }
248
- }
249
-
250
- matches = applyPrefix(matches, context)
251
-
252
- if (important) {
253
- matches = applyImportant(matches, context)
254
- }
255
-
256
- for (let variant of variants) {
257
- matches = applyVariant(variant, matches, context)
258
- }
259
-
260
- for (let match of matches) {
261
- yield match
262
- }
263
- }
264
- }
265
-
266
- function inKeyframes(rule) {
267
- return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
268
- }
269
-
270
- function generateRules(candidates, context) {
271
- let allRules = []
272
-
273
- for (let candidate of candidates) {
274
- if (context.notClassCache.has(candidate)) {
275
- continue
276
- }
277
-
278
- if (context.classCache.has(candidate)) {
279
- allRules.push(context.classCache.get(candidate))
280
- continue
281
- }
282
-
283
- let matches = Array.from(resolveMatches(candidate, context))
284
-
285
- if (matches.length === 0) {
286
- context.notClassCache.add(candidate)
287
- continue
288
- }
289
-
290
- context.classCache.set(candidate, matches)
291
- allRules.push(matches)
292
- }
293
-
294
- return allRules.flat(1).map(([{ sort, layer, options }, rule]) => {
295
- if (options.respectImportant) {
296
- if (context.tailwindConfig.important === true) {
297
- rule.walkDecls((d) => {
298
- if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
299
- d.important = true
300
- }
301
- })
302
- } else if (typeof context.tailwindConfig.important === 'string') {
303
- let container = postcss.root({ nodes: [rule.clone()] })
304
- container.walkRules((r) => {
305
- if (inKeyframes(r)) {
306
- return
307
- }
308
-
309
- r.selectors = r.selectors.map((selector) => {
310
- return `${context.tailwindConfig.important} ${selector}`
311
- })
312
- })
313
- rule = container.nodes[0]
314
- }
315
- }
316
- return [sort | context.layerOrder[layer], rule]
317
- })
318
- }
319
-
320
- 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
- }
@@ -1,77 +0,0 @@
1
- import log from '../util/log'
2
-
3
- export default function normalizeTailwindDirectives(root) {
4
- let tailwindDirectives = new Set()
5
- let layerDirectives = new Set()
6
-
7
- root.walkAtRules((atRule) => {
8
- if (atRule.name === 'import') {
9
- if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
10
- atRule.name = 'tailwind'
11
- atRule.params = 'base'
12
- } else if (
13
- atRule.params === '"tailwindcss/components"' ||
14
- atRule.params === "'tailwindcss/components'"
15
- ) {
16
- atRule.name = 'tailwind'
17
- atRule.params = 'components'
18
- } else if (
19
- atRule.params === '"tailwindcss/utilities"' ||
20
- atRule.params === "'tailwindcss/utilities'"
21
- ) {
22
- atRule.name = 'tailwind'
23
- atRule.params = 'utilities'
24
- } else if (
25
- atRule.params === '"tailwindcss/screens"' ||
26
- atRule.params === "'tailwindcss/screens'" ||
27
- atRule.params === '"tailwindcss/variants"' ||
28
- atRule.params === "'tailwindcss/variants'"
29
- ) {
30
- atRule.name = 'tailwind'
31
- atRule.params = 'variants'
32
- }
33
- }
34
-
35
- if (atRule.name === 'tailwind') {
36
- if (atRule.params === 'screens') {
37
- atRule.params = 'variants'
38
- }
39
- tailwindDirectives.add(atRule.params)
40
- }
41
-
42
- if (['layer', 'responsive', 'variants'].includes(atRule.name)) {
43
- if (['responsive', 'variants'].includes(atRule.name)) {
44
- log.warn([
45
- `'@${atRule.name}' is deprecated, use '@layer utilities' or '@layer components' instead.`,
46
- ])
47
- }
48
- layerDirectives.add(atRule)
49
- }
50
- })
51
-
52
- if (
53
- !tailwindDirectives.has('base') ||
54
- !tailwindDirectives.has('components') ||
55
- !tailwindDirectives.has('utilities')
56
- ) {
57
- for (let rule of layerDirectives) {
58
- if (rule.name === 'layer' && ['base', 'components', 'utilities'].includes(rule.params)) {
59
- if (!tailwindDirectives.has(rule.params)) {
60
- throw rule.error(
61
- `\`@layer ${rule.params}\` is used but no matching \`@tailwind ${rule.params}\` directive is present.`
62
- )
63
- }
64
- } else if (rule.name === 'responsive') {
65
- if (!tailwindDirectives.has('utilities')) {
66
- throw rule.error('`@responsive` is used but `@tailwind utilities` is missing.')
67
- }
68
- } else if (rule.name === 'variants') {
69
- if (!tailwindDirectives.has('utilities')) {
70
- throw rule.error('`@variants` is used but `@tailwind utilities` is missing.')
71
- }
72
- }
73
- }
74
- }
75
-
76
- return tailwindDirectives
77
- }
@@ -1,125 +0,0 @@
1
- import postcss from 'postcss'
2
- import selectorParser from 'postcss-selector-parser'
3
- import { flagEnabled } from '../featureFlags'
4
-
5
- function isPseudoElement(n) {
6
- if (n.type !== 'pseudo') {
7
- return false
8
- }
9
-
10
- return (
11
- n.value.startsWith('::') ||
12
- [':before', ':after', ':first-line', ':first-letter'].includes(n.value)
13
- )
14
- }
15
-
16
- function minimumImpactSelector(nodes) {
17
- let rest = nodes
18
- // Keep all pseudo & combinator types (:not([hidden]) ~ :not([hidden]))
19
- .filter((n) => n.type === 'pseudo' || n.type === 'combinator')
20
- // Remove leading pseudo's (:hover, :focus, ...)
21
- .filter((n, idx, all) => {
22
- // Keep pseudo elements
23
- if (isPseudoElement(n)) return true
24
-
25
- if (idx === 0 && n.type === 'pseudo') return false
26
- if (idx > 0 && n.type === 'pseudo' && all[idx - 1].type === 'pseudo') return false
27
-
28
- return true
29
- })
30
-
31
- let [bestNode] = nodes
32
-
33
- for (let [type, getNode = (n) => n] of [
34
- ['class'],
35
- [
36
- 'id',
37
- (n) =>
38
- selectorParser.attribute({
39
- attribute: 'id',
40
- operator: '=',
41
- value: n.value,
42
- quoteMark: '"',
43
- }),
44
- ],
45
- ['attribute'],
46
- ]) {
47
- let match = nodes.find((n) => n.type === type)
48
-
49
- if (match) {
50
- bestNode = getNode(match)
51
- break
52
- }
53
- }
54
-
55
- return [bestNode, ...rest].join('').trim()
56
- }
57
-
58
- let elementSelectorParser = selectorParser((selectors) => {
59
- return selectors.map((s) => {
60
- let nodes = s.split((n) => n.type === 'combinator' && n.value === ' ').pop()
61
- return minimumImpactSelector(nodes)
62
- })
63
- })
64
-
65
- let cache = new Map()
66
-
67
- function extractElementSelector(selector) {
68
- if (!cache.has(selector)) {
69
- cache.set(selector, elementSelectorParser.transformSync(selector))
70
- }
71
-
72
- return cache.get(selector)
73
- }
74
-
75
- export default function resolveDefaultsAtRules({ tailwindConfig }) {
76
- return (root) => {
77
- let variableNodeMap = new Map()
78
- let universals = new Set()
79
-
80
- root.walkAtRules('defaults', (rule) => {
81
- if (rule.nodes && rule.nodes.length > 0) {
82
- universals.add(rule)
83
- return
84
- }
85
-
86
- let variable = rule.params
87
- if (!variableNodeMap.has(variable)) {
88
- variableNodeMap.set(variable, new Set())
89
- }
90
-
91
- variableNodeMap.get(variable).add(rule.parent)
92
-
93
- rule.remove()
94
- })
95
-
96
- for (let universal of universals) {
97
- let selectors = new Set()
98
-
99
- let rules = variableNodeMap.get(universal.params) ?? []
100
-
101
- for (let rule of rules) {
102
- for (let selector of extractElementSelector(rule.selector)) {
103
- selectors.add(selector)
104
- }
105
- }
106
-
107
- if (selectors.size === 0) {
108
- universal.remove()
109
- continue
110
- }
111
-
112
- let universalRule = postcss.rule()
113
-
114
- if (flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
115
- universalRule.selectors = [...selectors]
116
- } else {
117
- universalRule.selectors = ['*', '::before', '::after']
118
- }
119
-
120
- universalRule.append(universal.nodes)
121
- universal.before(universalRule)
122
- universal.remove()
123
- }
124
- }
125
- }