tailwindcss 0.0.0-insiders.ebc1c7a → 0.0.0-insiders.ec0049a
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.
- package/LICENSE +1 -2
- package/README.md +18 -11
- package/dist/chunk-AZANAYY2.mjs +1 -0
- package/dist/chunk-CH45MXZF.mjs +10 -0
- package/dist/chunk-V2K3XTS4.mjs +1 -0
- package/dist/colors-b_6i0Oi7.d.ts +295 -0
- package/dist/colors.d.mts +295 -0
- package/dist/colors.d.ts +5 -0
- package/dist/colors.js +1 -0
- package/dist/colors.mjs +1 -0
- package/dist/default-theme.d.mts +1147 -0
- package/dist/default-theme.d.ts +1147 -0
- package/dist/default-theme.js +1 -0
- package/dist/default-theme.mjs +1 -0
- package/dist/flatten-color-palette.d.mts +6 -0
- package/dist/flatten-color-palette.d.ts +6 -0
- package/dist/flatten-color-palette.js +1 -0
- package/dist/flatten-color-palette.mjs +1 -0
- package/dist/lib.d.mts +260 -0
- package/dist/lib.d.ts +3 -0
- package/dist/lib.js +33 -0
- package/dist/lib.mjs +24 -0
- package/dist/plugin.d.mts +11 -0
- package/dist/plugin.d.ts +104 -0
- package/dist/plugin.js +1 -0
- package/dist/plugin.mjs +1 -0
- package/dist/resolve-config-BIFUA2FY.d.ts +29 -0
- package/dist/resolve-config-QUZ9b-Gn.d.mts +190 -0
- package/dist/types-B254mqw1.d.mts +98 -0
- package/index.css +865 -0
- package/package.json +73 -110
- package/preflight.css +383 -0
- package/theme.css +453 -0
- package/CHANGELOG.md +0 -1742
- package/base.css +0 -1
- package/colors.js +0 -304
- package/components.css +0 -1
- package/defaultConfig.js +0 -4
- package/defaultTheme.js +0 -4
- package/lib/cli-peer-dependencies.js +0 -20
- package/lib/cli.js +0 -765
- package/lib/constants.js +0 -37
- package/lib/corePluginList.js +0 -8
- package/lib/corePlugins.js +0 -2977
- package/lib/css/LICENSE +0 -25
- package/lib/css/preflight.css +0 -354
- package/lib/featureFlags.js +0 -60
- package/lib/index.js +0 -31
- package/lib/lib/collapseAdjacentRules.js +0 -43
- package/lib/lib/evaluateTailwindFunctions.js +0 -192
- package/lib/lib/expandApplyAtRules.js +0 -245
- package/lib/lib/expandTailwindAtRules.js +0 -260
- package/lib/lib/generateRules.js +0 -362
- package/lib/lib/getModuleDependencies.js +0 -53
- package/lib/lib/normalizeTailwindDirectives.js +0 -68
- package/lib/lib/resolveDefaultsAtRules.js +0 -105
- package/lib/lib/setupContextUtils.js +0 -643
- package/lib/lib/setupTrackingContext.js +0 -190
- package/lib/lib/setupWatchingContext.js +0 -331
- package/lib/lib/sharedState.js +0 -29
- package/lib/lib/substituteScreenAtRules.js +0 -31
- package/lib/processTailwindFeatures.js +0 -57
- package/lib/util/bigSign.js +0 -10
- package/lib/util/buildMediaQuery.js +0 -36
- package/lib/util/cloneDeep.js +0 -18
- package/lib/util/cloneNodes.js +0 -18
- package/lib/util/color.js +0 -74
- package/lib/util/configurePlugins.js +0 -19
- package/lib/util/createPlugin.js +0 -33
- package/lib/util/createUtilityPlugin.js +0 -51
- package/lib/util/defaults.js +0 -20
- package/lib/util/escapeClassName.js +0 -21
- package/lib/util/escapeCommas.js +0 -10
- package/lib/util/flattenColorPalette.js +0 -15
- package/lib/util/getAllConfigs.js +0 -22
- package/lib/util/hashConfig.js +0 -16
- package/lib/util/isKeyframeRule.js +0 -10
- package/lib/util/isPlainObject.js +0 -15
- package/lib/util/log.js +0 -38
- package/lib/util/nameClass.js +0 -32
- package/lib/util/negateValue.js +0 -20
- package/lib/util/parseAnimationValue.js +0 -60
- package/lib/util/parseDependency.js +0 -74
- package/lib/util/parseObjectStyles.js +0 -28
- package/lib/util/pluginUtils.js +0 -318
- package/lib/util/prefixSelector.js +0 -23
- package/lib/util/resolveConfig.js +0 -289
- package/lib/util/resolveConfigPath.js +0 -59
- package/lib/util/responsive.js +0 -18
- package/lib/util/tap.js +0 -11
- package/lib/util/toColorValue.js +0 -10
- package/lib/util/toPath.js +0 -11
- package/lib/util/transformThemeValue.js +0 -32
- package/lib/util/withAlphaVariable.js +0 -65
- package/nesting/README.md +0 -42
- package/nesting/index.js +0 -12
- package/nesting/plugin.js +0 -41
- package/peers/index.js +0 -87302
- package/plugin.js +0 -3
- package/prettier.config.js +0 -19
- package/resolveConfig.js +0 -7
- package/screens.css +0 -1
- package/scripts/create-plugin-list.js +0 -10
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/cli-peer-dependencies.js +0 -9
- package/src/cli.js +0 -759
- package/src/constants.js +0 -17
- package/src/corePluginList.js +0 -1
- package/src/corePlugins.js +0 -2228
- package/src/css/LICENSE +0 -25
- package/src/css/preflight.css +0 -354
- package/src/featureFlags.js +0 -48
- package/src/index.js +0 -34
- package/src/lib/collapseAdjacentRules.js +0 -39
- package/src/lib/evaluateTailwindFunctions.js +0 -195
- package/src/lib/expandApplyAtRules.js +0 -251
- package/src/lib/expandTailwindAtRules.js +0 -262
- package/src/lib/generateRules.js +0 -319
- package/src/lib/getModuleDependencies.js +0 -39
- package/src/lib/normalizeTailwindDirectives.js +0 -77
- package/src/lib/resolveDefaultsAtRules.js +0 -105
- package/src/lib/setupContextUtils.js +0 -639
- package/src/lib/setupTrackingContext.js +0 -181
- package/src/lib/setupWatchingContext.js +0 -306
- package/src/lib/sharedState.js +0 -13
- package/src/lib/substituteScreenAtRules.js +0 -16
- package/src/processTailwindFeatures.js +0 -41
- package/src/util/bigSign.js +0 -3
- package/src/util/buildMediaQuery.js +0 -24
- package/src/util/cloneDeep.js +0 -11
- package/src/util/cloneNodes.js +0 -11
- package/src/util/color.js +0 -56
- package/src/util/configurePlugins.js +0 -23
- package/src/util/createPlugin.js +0 -27
- package/src/util/createUtilityPlugin.js +0 -46
- package/src/util/defaults.js +0 -11
- package/src/util/escapeClassName.js +0 -8
- package/src/util/escapeCommas.js +0 -3
- package/src/util/flattenColorPalette.js +0 -13
- package/src/util/getAllConfigs.js +0 -19
- package/src/util/hashConfig.js +0 -5
- package/src/util/isKeyframeRule.js +0 -3
- package/src/util/isPlainObject.js +0 -8
- package/src/util/log.js +0 -28
- package/src/util/nameClass.js +0 -22
- package/src/util/negateValue.js +0 -14
- package/src/util/parseAnimationValue.js +0 -62
- package/src/util/parseDependency.js +0 -45
- package/src/util/parseObjectStyles.js +0 -19
- package/src/util/pluginUtils.js +0 -295
- package/src/util/prefixSelector.js +0 -15
- package/src/util/resolveConfig.js +0 -282
- package/src/util/resolveConfigPath.js +0 -55
- package/src/util/responsive.js +0 -10
- package/src/util/tap.js +0 -4
- package/src/util/toColorValue.js +0 -3
- package/src/util/toPath.js +0 -4
- package/src/util/transformThemeValue.js +0 -37
- package/src/util/withAlphaVariable.js +0 -44
- package/stubs/defaultConfig.stub.js +0 -884
- package/stubs/defaultPostCssConfig.stub.js +0 -6
- package/stubs/simpleConfig.stub.js +0 -8
- package/tailwind.css +0 -5
- package/variants.css +0 -1
package/src/lib/generateRules.js
DELETED
|
@@ -1,319 +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
|
-
|
|
230
|
-
for (let [sort, plugin] of plugins) {
|
|
231
|
-
if (typeof plugin === 'function') {
|
|
232
|
-
for (let ruleSet of [].concat(plugin(modifier))) {
|
|
233
|
-
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
|
|
234
|
-
for (let rule of rules) {
|
|
235
|
-
matches.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// Only process static plugins on exact matches
|
|
240
|
-
else if (modifier === 'DEFAULT') {
|
|
241
|
-
let ruleSet = plugin
|
|
242
|
-
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
|
|
243
|
-
for (let rule of rules) {
|
|
244
|
-
matches.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
matches = applyPrefix(matches, context)
|
|
250
|
-
|
|
251
|
-
if (important) {
|
|
252
|
-
matches = applyImportant(matches, context)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
for (let variant of variants) {
|
|
256
|
-
matches = applyVariant(variant, matches, context)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
for (let match of matches) {
|
|
260
|
-
yield match
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function inKeyframes(rule) {
|
|
266
|
-
return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function generateRules(candidates, context) {
|
|
270
|
-
let allRules = []
|
|
271
|
-
|
|
272
|
-
for (let candidate of candidates) {
|
|
273
|
-
if (context.notClassCache.has(candidate)) {
|
|
274
|
-
continue
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (context.classCache.has(candidate)) {
|
|
278
|
-
allRules.push(context.classCache.get(candidate))
|
|
279
|
-
continue
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
let matches = Array.from(resolveMatches(candidate, context))
|
|
283
|
-
|
|
284
|
-
if (matches.length === 0) {
|
|
285
|
-
context.notClassCache.add(candidate)
|
|
286
|
-
continue
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
context.classCache.set(candidate, matches)
|
|
290
|
-
allRules.push(matches)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return allRules.flat(1).map(([{ sort, layer, options }, rule]) => {
|
|
294
|
-
if (options.respectImportant) {
|
|
295
|
-
if (context.tailwindConfig.important === true) {
|
|
296
|
-
rule.walkDecls((d) => {
|
|
297
|
-
if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
|
|
298
|
-
d.important = true
|
|
299
|
-
}
|
|
300
|
-
})
|
|
301
|
-
} else if (typeof context.tailwindConfig.important === 'string') {
|
|
302
|
-
let container = postcss.root({ nodes: [rule.clone()] })
|
|
303
|
-
container.walkRules((r) => {
|
|
304
|
-
if (inKeyframes(r)) {
|
|
305
|
-
return
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
r.selectors = r.selectors.map((selector) => {
|
|
309
|
-
return `${context.tailwindConfig.important} ${selector}`
|
|
310
|
-
})
|
|
311
|
-
})
|
|
312
|
-
rule = container.nodes[0]
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return [sort | context.layerOrder[layer], rule]
|
|
316
|
-
})
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
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,105 +0,0 @@
|
|
|
1
|
-
import postcss from 'postcss'
|
|
2
|
-
import selectorParser from 'postcss-selector-parser'
|
|
3
|
-
import { flagEnabled } from '../featureFlags'
|
|
4
|
-
|
|
5
|
-
function minimumImpactSelector(nodes) {
|
|
6
|
-
let pseudos = nodes.filter((n) => n.type === 'pseudo')
|
|
7
|
-
let [bestNode] = nodes
|
|
8
|
-
|
|
9
|
-
for (let [type, getNode = (n) => n] of [
|
|
10
|
-
['class'],
|
|
11
|
-
[
|
|
12
|
-
'id',
|
|
13
|
-
(n) =>
|
|
14
|
-
selectorParser.attribute({
|
|
15
|
-
attribute: 'id',
|
|
16
|
-
operator: '=',
|
|
17
|
-
value: n.value,
|
|
18
|
-
quoteMark: '"',
|
|
19
|
-
}),
|
|
20
|
-
],
|
|
21
|
-
['attribute'],
|
|
22
|
-
]) {
|
|
23
|
-
let match = nodes.find((n) => n.type === type)
|
|
24
|
-
|
|
25
|
-
if (match) {
|
|
26
|
-
bestNode = getNode(match)
|
|
27
|
-
break
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return [bestNode, ...pseudos].join('').trim()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let elementSelectorParser = selectorParser((selectors) => {
|
|
35
|
-
return selectors.map((s) => {
|
|
36
|
-
let nodes = s
|
|
37
|
-
.split((n) => n.type === 'combinator')
|
|
38
|
-
.pop()
|
|
39
|
-
.filter((n) => n.type !== 'pseudo' || n.value.startsWith('::'))
|
|
40
|
-
|
|
41
|
-
return minimumImpactSelector(nodes)
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
let cache = new Map()
|
|
46
|
-
|
|
47
|
-
function extractElementSelector(selector) {
|
|
48
|
-
if (!cache.has(selector)) {
|
|
49
|
-
cache.set(selector, elementSelectorParser.transformSync(selector))
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return cache.get(selector)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
56
|
-
return (root) => {
|
|
57
|
-
let variableNodeMap = new Map()
|
|
58
|
-
let universals = new Set()
|
|
59
|
-
|
|
60
|
-
root.walkAtRules('defaults', (rule) => {
|
|
61
|
-
if (rule.nodes && rule.nodes.length > 0) {
|
|
62
|
-
universals.add(rule)
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let variable = rule.params
|
|
67
|
-
if (!variableNodeMap.has(variable)) {
|
|
68
|
-
variableNodeMap.set(variable, new Set())
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
variableNodeMap.get(variable).add(rule.parent)
|
|
72
|
-
|
|
73
|
-
rule.remove()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
for (let universal of universals) {
|
|
77
|
-
let selectors = new Set()
|
|
78
|
-
|
|
79
|
-
let rules = variableNodeMap.get(universal.params) ?? []
|
|
80
|
-
|
|
81
|
-
for (let rule of rules) {
|
|
82
|
-
for (let selector of extractElementSelector(rule.selector)) {
|
|
83
|
-
selectors.add(selector)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (selectors.size === 0) {
|
|
88
|
-
universal.remove()
|
|
89
|
-
continue
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let universalRule = postcss.rule()
|
|
93
|
-
|
|
94
|
-
if (flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
|
|
95
|
-
universalRule.selectors = [...selectors]
|
|
96
|
-
} else {
|
|
97
|
-
universalRule.selectors = ['*', '::before', '::after']
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
universalRule.append(universal.nodes)
|
|
101
|
-
universal.before(universalRule)
|
|
102
|
-
universal.remove()
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|