tailwindcss 0.0.0-insiders.ea80db2 → 0.0.0-insiders.eae2b7a
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/README.md +13 -9
- package/defaultTheme.d.ts +2 -1
- package/index.css +5 -0
- package/lib/cli/build/index.js +57 -0
- package/lib/cli/build/plugin.js +427 -0
- package/lib/cli/build/utils.js +88 -0
- package/lib/cli/build/watching.js +182 -0
- package/lib/cli/help/index.js +73 -0
- package/lib/cli/index.js +231 -0
- package/lib/cli/init/index.js +63 -0
- package/lib/cli.js +1 -759
- package/lib/corePluginList.js +12 -3
- package/lib/corePlugins.js +2308 -1739
- package/lib/css/preflight.css +13 -5
- package/lib/featureFlags.js +50 -25
- package/lib/index.js +1 -40
- package/lib/lib/cacheInvalidation.js +48 -25
- package/lib/lib/collapseAdjacentRules.js +17 -10
- package/lib/lib/collapseDuplicateDeclarations.js +13 -8
- package/lib/lib/content.js +207 -0
- package/lib/lib/defaultExtractor.js +232 -33
- package/lib/lib/detectNesting.js +21 -10
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +316 -215
- package/lib/lib/expandTailwindAtRules.js +167 -115
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +444 -211
- package/lib/lib/getModuleDependencies.js +88 -37
- package/lib/lib/handleImportAtRules.js +50 -0
- package/lib/lib/load-config.js +42 -0
- package/lib/lib/normalizeTailwindDirectives.js +29 -39
- package/lib/lib/offsets.js +306 -0
- package/lib/lib/partitionApplyAtRules.js +13 -8
- package/lib/lib/regex.js +74 -0
- package/lib/lib/remap-bitfield.js +89 -0
- package/lib/lib/resolveDefaultsAtRules.js +96 -74
- package/lib/lib/setupContextUtils.js +672 -300
- package/lib/lib/setupTrackingContext.js +63 -68
- package/lib/lib/sharedState.js +44 -17
- package/lib/lib/substituteScreenAtRules.js +14 -10
- package/lib/plugin.js +160 -0
- package/lib/postcss-plugins/nesting/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +10 -6
- package/lib/postcss-plugins/nesting/plugin.js +24 -20
- package/lib/processTailwindFeatures.js +34 -29
- package/lib/public/colors.js +272 -246
- package/lib/public/create-plugin.js +9 -5
- package/lib/public/default-config.js +10 -6
- package/lib/public/default-theme.js +10 -6
- package/lib/public/load-config.js +12 -0
- package/lib/public/resolve-config.js +11 -6
- package/lib/util/applyImportantSelector.js +36 -0
- package/lib/util/bigSign.js +6 -1
- package/lib/util/buildMediaQuery.js +13 -6
- package/lib/util/cloneDeep.js +9 -6
- package/lib/util/cloneNodes.js +12 -3
- package/lib/util/color.js +66 -50
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +7 -2
- package/lib/util/createPlugin.js +8 -5
- package/lib/util/createUtilityPlugin.js +13 -9
- package/lib/util/dataTypes.js +182 -111
- package/lib/util/defaults.js +12 -7
- package/lib/util/escapeClassName.js +13 -8
- package/lib/util/escapeCommas.js +7 -2
- package/lib/util/flattenColorPalette.js +11 -10
- package/lib/util/formatVariantSelector.js +228 -151
- package/lib/util/getAllConfigs.js +33 -12
- package/lib/util/hashConfig.js +9 -4
- package/lib/util/isKeyframeRule.js +7 -2
- package/lib/util/isPlainObject.js +7 -2
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
- package/lib/util/log.js +40 -13
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +155 -87
- package/lib/util/normalizeScreens.js +127 -8
- package/lib/util/parseAnimationValue.js +44 -40
- package/lib/util/parseBoxShadowValue.js +33 -62
- package/lib/util/parseDependency.js +39 -55
- package/lib/util/parseGlob.js +36 -0
- package/lib/util/parseObjectStyles.js +15 -10
- package/lib/util/pluginUtils.js +154 -59
- package/lib/util/prefixSelector.js +29 -10
- package/lib/util/pseudoElements.js +209 -0
- package/lib/util/removeAlphaVariables.js +31 -0
- package/lib/util/resolveConfig.js +96 -95
- package/lib/util/resolveConfigPath.js +29 -10
- package/lib/util/responsive.js +11 -6
- package/lib/util/splitAtTopLevelOnly.js +51 -0
- package/lib/util/tap.js +6 -1
- package/lib/util/toColorValue.js +7 -2
- package/lib/util/toPath.js +22 -4
- package/lib/util/transformThemeValue.js +40 -26
- package/lib/util/validateConfig.js +48 -0
- package/lib/util/validateFormalSyntax.js +26 -0
- package/lib/util/withAlphaVariable.js +27 -15
- package/lib/value-parser/LICENSE +22 -0
- package/lib/value-parser/README.md +3 -0
- package/lib/value-parser/index.d.js +2 -0
- package/lib/value-parser/index.js +22 -0
- package/lib/value-parser/parse.js +259 -0
- package/lib/value-parser/stringify.js +38 -0
- package/lib/value-parser/unit.js +86 -0
- package/lib/value-parser/walk.js +16 -0
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/package.json +54 -52
- package/plugin.d.ts +10 -5
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +53 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/index.js +53 -0
- package/src/cli/build/plugin.js +465 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +229 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +217 -0
- package/src/cli/init/index.js +79 -0
- package/src/cli.js +1 -836
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +576 -106
- package/src/css/preflight.css +13 -5
- package/src/featureFlags.js +17 -3
- package/src/index.js +1 -42
- package/src/lib/collapseAdjacentRules.js +5 -1
- package/src/lib/content.js +240 -0
- package/src/lib/defaultExtractor.js +202 -35
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +82 -8
- package/src/lib/expandApplyAtRules.js +322 -189
- package/src/lib/expandTailwindAtRules.js +82 -59
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +413 -132
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/handleImportAtRules.js +34 -0
- package/src/lib/load-config.ts +31 -0
- package/src/lib/normalizeTailwindDirectives.js +0 -27
- package/src/lib/offsets.js +373 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -36
- package/src/lib/setupContextUtils.js +570 -151
- package/src/lib/setupTrackingContext.js +44 -58
- package/src/lib/sharedState.js +13 -4
- package/src/plugin.js +128 -0
- package/src/postcss-plugins/nesting/README.md +2 -2
- package/src/public/colors.js +22 -0
- package/src/public/default-config.js +1 -1
- package/src/public/default-theme.js +2 -2
- package/src/public/load-config.js +2 -0
- package/src/util/applyImportantSelector.js +27 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +5 -1
- package/src/util/color.js +34 -17
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +67 -23
- package/src/util/formatVariantSelector.js +264 -144
- package/src/util/getAllConfigs.js +21 -2
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +25 -1
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +78 -20
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +118 -23
- package/src/util/prefixSelector.js +28 -10
- package/src/util/pseudoElements.js +167 -0
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -62
- package/src/util/resolveConfigPath.js +12 -1
- package/src/util/splitAtTopLevelOnly.js +52 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +36 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/src/value-parser/LICENSE +22 -0
- package/src/value-parser/README.md +3 -0
- package/src/value-parser/index.d.ts +177 -0
- package/src/value-parser/index.js +28 -0
- package/src/value-parser/parse.js +303 -0
- package/src/value-parser/stringify.js +41 -0
- package/src/value-parser/unit.js +118 -0
- package/src/value-parser/walk.js +18 -0
- package/stubs/.gitignore +1 -0
- package/stubs/.prettierrc.json +6 -0
- package/stubs/{defaultConfig.stub.js → config.full.js} +215 -165
- package/stubs/{simpleConfig.stub.js → config.simple.js} +1 -1
- package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -1
- package/stubs/postcss.config.js +5 -0
- package/stubs/tailwind.config.cjs +2 -0
- package/stubs/tailwind.config.js +2 -0
- package/stubs/tailwind.config.ts +3 -0
- package/types/config.d.ts +102 -56
- package/types/generated/colors.d.ts +22 -0
- package/types/generated/corePluginList.d.ts +1 -1
- package/types/generated/default-theme.d.ts +372 -0
- package/types/index.d.ts +7 -1
- package/CHANGELOG.md +0 -2099
- package/lib/cli-peer-dependencies.js +0 -15
- package/lib/constants.js +0 -37
- package/peers/index.js +0 -75156
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/cli-peer-dependencies.js +0 -9
- package/src/constants.js +0 -17
- package/types.d.ts +0 -1
package/src/lib/generateRules.js
CHANGED
|
@@ -3,19 +3,27 @@ import selectorParser from 'postcss-selector-parser'
|
|
|
3
3
|
import parseObjectStyles from '../util/parseObjectStyles'
|
|
4
4
|
import isPlainObject from '../util/isPlainObject'
|
|
5
5
|
import prefixSelector from '../util/prefixSelector'
|
|
6
|
-
import { updateAllClasses } from '../util/pluginUtils'
|
|
6
|
+
import { updateAllClasses, getMatchingTypes } from '../util/pluginUtils'
|
|
7
7
|
import log from '../util/log'
|
|
8
8
|
import * as sharedState from './sharedState'
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
formatVariantSelector,
|
|
11
|
+
finalizeSelector,
|
|
12
|
+
eliminateIrrelevantSelectors,
|
|
13
|
+
} from '../util/formatVariantSelector'
|
|
10
14
|
import { asClass } from '../util/nameClass'
|
|
11
15
|
import { normalize } from '../util/dataTypes'
|
|
12
|
-
import
|
|
16
|
+
import { isValidVariantFormatString, parseVariant } from './setupContextUtils'
|
|
17
|
+
import isValidArbitraryValue from '../util/isSyntacticallyValidPropertyValue'
|
|
18
|
+
import { splitAtTopLevelOnly } from '../util/splitAtTopLevelOnly.js'
|
|
19
|
+
import { flagEnabled } from '../featureFlags'
|
|
20
|
+
import { applyImportantSelector } from '../util/applyImportantSelector'
|
|
13
21
|
|
|
14
22
|
let classNameParser = selectorParser((selectors) => {
|
|
15
23
|
return selectors.first.filter(({ type }) => type === 'class').pop().value
|
|
16
24
|
})
|
|
17
25
|
|
|
18
|
-
function getClassNameFromSelector(selector) {
|
|
26
|
+
export function getClassNameFromSelector(selector) {
|
|
19
27
|
return classNameParser.transformSync(selector)
|
|
20
28
|
}
|
|
21
29
|
|
|
@@ -31,13 +39,24 @@ function* candidatePermutations(candidate) {
|
|
|
31
39
|
|
|
32
40
|
while (lastIndex >= 0) {
|
|
33
41
|
let dashIdx
|
|
42
|
+
let wasSlash = false
|
|
34
43
|
|
|
35
44
|
if (lastIndex === Infinity && candidate.endsWith(']')) {
|
|
36
45
|
let bracketIdx = candidate.indexOf('[')
|
|
37
46
|
|
|
38
47
|
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
39
|
-
//
|
|
40
|
-
|
|
48
|
+
// e.g. string[]
|
|
49
|
+
if (candidate[bracketIdx - 1] === '-') {
|
|
50
|
+
dashIdx = bracketIdx - 1
|
|
51
|
+
} else if (candidate[bracketIdx - 1] === '/') {
|
|
52
|
+
dashIdx = bracketIdx - 1
|
|
53
|
+
wasSlash = true
|
|
54
|
+
} else {
|
|
55
|
+
dashIdx = -1
|
|
56
|
+
}
|
|
57
|
+
} else if (lastIndex === Infinity && candidate.includes('/')) {
|
|
58
|
+
dashIdx = candidate.lastIndexOf('/')
|
|
59
|
+
wasSlash = true
|
|
41
60
|
} else {
|
|
42
61
|
dashIdx = candidate.lastIndexOf('-', lastIndex)
|
|
43
62
|
}
|
|
@@ -47,11 +66,16 @@ function* candidatePermutations(candidate) {
|
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
let prefix = candidate.slice(0, dashIdx)
|
|
50
|
-
let modifier = candidate.slice(dashIdx + 1)
|
|
51
|
-
|
|
52
|
-
yield [prefix, modifier]
|
|
69
|
+
let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1)
|
|
53
70
|
|
|
54
71
|
lastIndex = dashIdx - 1
|
|
72
|
+
|
|
73
|
+
// TODO: This feels a bit hacky
|
|
74
|
+
if (prefix === '' || modifier === '/') {
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
yield [prefix, modifier]
|
|
55
79
|
}
|
|
56
80
|
}
|
|
57
81
|
|
|
@@ -92,19 +116,28 @@ function applyImportant(matches, classCandidate) {
|
|
|
92
116
|
if (matches.length === 0) {
|
|
93
117
|
return matches
|
|
94
118
|
}
|
|
119
|
+
|
|
95
120
|
let result = []
|
|
96
121
|
|
|
97
122
|
for (let [meta, rule] of matches) {
|
|
98
123
|
let container = postcss.root({ nodes: [rule.clone()] })
|
|
124
|
+
|
|
99
125
|
container.walkRules((r) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
126
|
+
let ast = selectorParser().astSync(r.selector)
|
|
127
|
+
|
|
128
|
+
// Remove extraneous selectors that do not include the base candidate
|
|
129
|
+
ast.each((sel) => eliminateIrrelevantSelectors(sel, classCandidate))
|
|
130
|
+
|
|
131
|
+
// Update all instances of the base candidate to include the important marker
|
|
132
|
+
updateAllClasses(ast, (className) =>
|
|
133
|
+
className === classCandidate ? `!${className}` : className
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
r.selector = ast.toString()
|
|
137
|
+
|
|
106
138
|
r.walkDecls((d) => (d.important = true))
|
|
107
139
|
})
|
|
140
|
+
|
|
108
141
|
result.push([{ ...meta, important: true }, container.nodes[0]])
|
|
109
142
|
}
|
|
110
143
|
|
|
@@ -125,8 +158,75 @@ function applyVariant(variant, matches, context) {
|
|
|
125
158
|
return matches
|
|
126
159
|
}
|
|
127
160
|
|
|
161
|
+
/** @type {{modifier: string | null, value: string | null}} */
|
|
162
|
+
let args = { modifier: null, value: sharedState.NONE }
|
|
163
|
+
|
|
164
|
+
// Retrieve "modifier"
|
|
165
|
+
{
|
|
166
|
+
let [baseVariant, ...modifiers] = splitAtTopLevelOnly(variant, '/')
|
|
167
|
+
|
|
168
|
+
// This is a hack to support variants with `/` in them, like `ar-1/10/20:text-red-500`
|
|
169
|
+
// In this case 1/10 is a value but /20 is a modifier
|
|
170
|
+
if (modifiers.length > 1) {
|
|
171
|
+
baseVariant = baseVariant + '/' + modifiers.slice(0, -1).join('/')
|
|
172
|
+
modifiers = modifiers.slice(-1)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (modifiers.length && !context.variantMap.has(variant)) {
|
|
176
|
+
variant = baseVariant
|
|
177
|
+
args.modifier = modifiers[0]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Retrieve "arbitrary value"
|
|
182
|
+
if (variant.endsWith(']') && !variant.startsWith('[')) {
|
|
183
|
+
// We either have:
|
|
184
|
+
// @[200px]
|
|
185
|
+
// group-[:hover]
|
|
186
|
+
//
|
|
187
|
+
// But we don't want:
|
|
188
|
+
// @-[200px] (`-` is incorrect)
|
|
189
|
+
// group[:hover] (`-` is missing)
|
|
190
|
+
let match = /(.)(-?)\[(.*)\]/g.exec(variant)
|
|
191
|
+
if (match) {
|
|
192
|
+
let [, char, separator, value] = match
|
|
193
|
+
// @-[200px] case
|
|
194
|
+
if (char === '@' && separator === '-') return []
|
|
195
|
+
// group[:hover] case
|
|
196
|
+
if (char !== '@' && separator === '') return []
|
|
197
|
+
|
|
198
|
+
variant = variant.replace(`${separator}[${value}]`, '')
|
|
199
|
+
args.value = value
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Register arbitrary variants
|
|
204
|
+
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
|
|
205
|
+
let sort = context.offsets.recordVariant(variant)
|
|
206
|
+
|
|
207
|
+
let selector = normalize(variant.slice(1, -1))
|
|
208
|
+
let selectors = splitAtTopLevelOnly(selector, ',')
|
|
209
|
+
|
|
210
|
+
// We do not support multiple selectors for arbitrary variants
|
|
211
|
+
if (selectors.length > 1) {
|
|
212
|
+
return []
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!selectors.every(isValidVariantFormatString)) {
|
|
216
|
+
return []
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
let records = selectors.map((sel, idx) => [
|
|
220
|
+
context.offsets.applyParallelOffset(sort, idx),
|
|
221
|
+
parseVariant(sel.trim()),
|
|
222
|
+
])
|
|
223
|
+
|
|
224
|
+
context.variantMap.set(variant, records)
|
|
225
|
+
}
|
|
226
|
+
|
|
128
227
|
if (context.variantMap.has(variant)) {
|
|
129
|
-
let
|
|
228
|
+
let isArbitraryVariant = isArbitraryValue(variant)
|
|
229
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice()
|
|
130
230
|
let result = []
|
|
131
231
|
|
|
132
232
|
for (let [meta, rule] of matches) {
|
|
@@ -137,15 +237,17 @@ function applyVariant(variant, matches, context) {
|
|
|
137
237
|
|
|
138
238
|
let container = postcss.root({ nodes: [rule.clone()] })
|
|
139
239
|
|
|
140
|
-
for (let [variantSort, variantFunction] of variantFunctionTuples) {
|
|
141
|
-
let clone = container.clone()
|
|
240
|
+
for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples) {
|
|
241
|
+
let clone = (containerFromArray ?? container).clone()
|
|
142
242
|
let collectedFormats = []
|
|
143
243
|
|
|
144
|
-
let originals = new Map()
|
|
145
|
-
|
|
146
244
|
function prepareBackup() {
|
|
147
|
-
|
|
148
|
-
clone.
|
|
245
|
+
// Already prepared, chicken out
|
|
246
|
+
if (clone.raws.neededBackup) {
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
clone.raws.neededBackup = true
|
|
250
|
+
clone.walkRules((rule) => (rule.raws.originalSelector = rule.selector))
|
|
149
251
|
}
|
|
150
252
|
|
|
151
253
|
function modifySelectors(modifierFunction) {
|
|
@@ -185,25 +287,54 @@ function applyVariant(variant, matches, context) {
|
|
|
185
287
|
clone.append(wrapper)
|
|
186
288
|
},
|
|
187
289
|
format(selectorFormat) {
|
|
188
|
-
collectedFormats.push(
|
|
290
|
+
collectedFormats.push({
|
|
291
|
+
format: selectorFormat,
|
|
292
|
+
isArbitraryVariant,
|
|
293
|
+
})
|
|
189
294
|
},
|
|
295
|
+
args,
|
|
190
296
|
})
|
|
191
297
|
|
|
298
|
+
// It can happen that a list of format strings is returned from within the function. In that
|
|
299
|
+
// case, we have to process them as well. We can use the existing `variantSort`.
|
|
300
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
301
|
+
for (let [idx, variantFunction] of ruleWithVariant.entries()) {
|
|
302
|
+
// This is a little bit scary since we are pushing to an array of items that we are
|
|
303
|
+
// currently looping over. However, you can also think of it like a processing queue
|
|
304
|
+
// where you keep handling jobs until everything is done and each job can queue more
|
|
305
|
+
// jobs if needed.
|
|
306
|
+
variantFunctionTuples.push([
|
|
307
|
+
context.offsets.applyParallelOffset(variantSort, idx),
|
|
308
|
+
variantFunction,
|
|
309
|
+
|
|
310
|
+
// If the clone has been modified we have to pass that back
|
|
311
|
+
// though so each rule can use the modified container
|
|
312
|
+
clone.clone(),
|
|
313
|
+
])
|
|
314
|
+
}
|
|
315
|
+
continue
|
|
316
|
+
}
|
|
317
|
+
|
|
192
318
|
if (typeof ruleWithVariant === 'string') {
|
|
193
|
-
collectedFormats.push(
|
|
319
|
+
collectedFormats.push({
|
|
320
|
+
format: ruleWithVariant,
|
|
321
|
+
isArbitraryVariant,
|
|
322
|
+
})
|
|
194
323
|
}
|
|
195
324
|
|
|
196
325
|
if (ruleWithVariant === null) {
|
|
197
326
|
continue
|
|
198
327
|
}
|
|
199
328
|
|
|
200
|
-
// We
|
|
329
|
+
// We had to backup selectors, therefore we assume that somebody touched
|
|
201
330
|
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
202
331
|
// can restore the selectors, and collect the format strings.
|
|
203
|
-
if (
|
|
332
|
+
if (clone.raws.neededBackup) {
|
|
333
|
+
delete clone.raws.neededBackup
|
|
204
334
|
clone.walkRules((rule) => {
|
|
205
|
-
|
|
206
|
-
|
|
335
|
+
let before = rule.raws.originalSelector
|
|
336
|
+
if (!before) return
|
|
337
|
+
delete rule.raws.originalSelector
|
|
207
338
|
if (before === rule.selector) return // No mutation happened
|
|
208
339
|
|
|
209
340
|
let modified = rule.selector
|
|
@@ -229,7 +360,10 @@ function applyVariant(variant, matches, context) {
|
|
|
229
360
|
// modified (by plugin): .foo .foo\\:markdown > p
|
|
230
361
|
// rebuiltBase (internal): .foo\\:markdown > p
|
|
231
362
|
// format: .foo &
|
|
232
|
-
collectedFormats.push(
|
|
363
|
+
collectedFormats.push({
|
|
364
|
+
format: modified.replace(rebuiltBase, '&'),
|
|
365
|
+
isArbitraryVariant,
|
|
366
|
+
})
|
|
233
367
|
rule.selector = before
|
|
234
368
|
})
|
|
235
369
|
}
|
|
@@ -243,7 +377,11 @@ function applyVariant(variant, matches, context) {
|
|
|
243
377
|
let withOffset = [
|
|
244
378
|
{
|
|
245
379
|
...meta,
|
|
246
|
-
sort:
|
|
380
|
+
sort: context.offsets.applyVariantOffset(
|
|
381
|
+
meta.sort,
|
|
382
|
+
variantSort,
|
|
383
|
+
Object.assign(args, context.variantOptions.get(variant))
|
|
384
|
+
),
|
|
247
385
|
collectedFormats: (meta.collectedFormats ?? []).concat(collectedFormats),
|
|
248
386
|
},
|
|
249
387
|
clone.nodes[0],
|
|
@@ -307,7 +445,7 @@ function isParsableNode(node) {
|
|
|
307
445
|
let isParsable = true
|
|
308
446
|
|
|
309
447
|
node.walkDecls((decl) => {
|
|
310
|
-
if (!isParsableCssValue(decl.
|
|
448
|
+
if (!isParsableCssValue(decl.prop, decl.value)) {
|
|
311
449
|
isParsable = false
|
|
312
450
|
return false
|
|
313
451
|
}
|
|
@@ -317,9 +455,9 @@ function isParsableNode(node) {
|
|
|
317
455
|
}
|
|
318
456
|
|
|
319
457
|
function isParsableCssValue(property, value) {
|
|
320
|
-
// We don't want to
|
|
458
|
+
// We don't want to treat [https://example.com] as a custom property
|
|
321
459
|
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
322
|
-
// So we short-circuit here by checking if the custom property looks like a
|
|
460
|
+
// So we short-circuit here by checking if the custom property looks like a URL
|
|
323
461
|
if (looksLikeUri(`${property}:${value}`)) {
|
|
324
462
|
return false
|
|
325
463
|
}
|
|
@@ -353,9 +491,11 @@ function extractArbitraryProperty(classCandidate, context) {
|
|
|
353
491
|
return null
|
|
354
492
|
}
|
|
355
493
|
|
|
494
|
+
let sort = context.offsets.arbitraryProperty()
|
|
495
|
+
|
|
356
496
|
return [
|
|
357
497
|
[
|
|
358
|
-
{ sort
|
|
498
|
+
{ sort, layer: 'utilities' },
|
|
359
499
|
() => ({
|
|
360
500
|
[asClass(classCandidate)]: {
|
|
361
501
|
[property]: normalized,
|
|
@@ -382,7 +522,11 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
382
522
|
const twConfigPrefix = context.tailwindConfig.prefix
|
|
383
523
|
|
|
384
524
|
const twConfigPrefixLen = twConfigPrefix.length
|
|
385
|
-
|
|
525
|
+
|
|
526
|
+
const hasMatchingPrefix =
|
|
527
|
+
candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`)
|
|
528
|
+
|
|
529
|
+
if (candidatePrefix[twConfigPrefixLen] === '-' && hasMatchingPrefix) {
|
|
386
530
|
negative = true
|
|
387
531
|
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)
|
|
388
532
|
}
|
|
@@ -403,18 +547,22 @@ function splitWithSeparator(input, separator) {
|
|
|
403
547
|
return [sharedState.NOT_ON_DEMAND]
|
|
404
548
|
}
|
|
405
549
|
|
|
406
|
-
return input
|
|
550
|
+
return splitAtTopLevelOnly(input, separator)
|
|
407
551
|
}
|
|
408
552
|
|
|
409
553
|
function* recordCandidates(matches, classCandidate) {
|
|
410
554
|
for (const match of matches) {
|
|
411
|
-
match[1].raws.tailwind = {
|
|
555
|
+
match[1].raws.tailwind = {
|
|
556
|
+
...match[1].raws.tailwind,
|
|
557
|
+
classCandidate,
|
|
558
|
+
preserveSource: match[0].options?.preserveSource ?? false,
|
|
559
|
+
}
|
|
412
560
|
|
|
413
561
|
yield match
|
|
414
562
|
}
|
|
415
563
|
}
|
|
416
564
|
|
|
417
|
-
function* resolveMatches(candidate, context) {
|
|
565
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
418
566
|
let separator = context.tailwindConfig.separator
|
|
419
567
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse()
|
|
420
568
|
let important = false
|
|
@@ -424,6 +572,15 @@ function* resolveMatches(candidate, context) {
|
|
|
424
572
|
classCandidate = classCandidate.slice(1)
|
|
425
573
|
}
|
|
426
574
|
|
|
575
|
+
if (flagEnabled(context.tailwindConfig, 'variantGrouping')) {
|
|
576
|
+
if (classCandidate.startsWith('(') && classCandidate.endsWith(')')) {
|
|
577
|
+
let base = variants.slice().reverse().join(separator)
|
|
578
|
+
for (let part of splitAtTopLevelOnly(classCandidate.slice(1, -1), ',')) {
|
|
579
|
+
yield* resolveMatches(base + separator + part, context, original)
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
427
584
|
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
428
585
|
// function sortAgainst(toSort, against) {
|
|
429
586
|
// return toSort.slice().sort((a, z) => {
|
|
@@ -464,68 +621,133 @@ function* resolveMatches(candidate, context) {
|
|
|
464
621
|
}
|
|
465
622
|
|
|
466
623
|
if (matchesPerPlugin.length > 0) {
|
|
467
|
-
|
|
624
|
+
let matchingTypes = Array.from(
|
|
625
|
+
getMatchingTypes(
|
|
626
|
+
sort.options?.types ?? [],
|
|
627
|
+
modifier,
|
|
628
|
+
sort.options ?? {},
|
|
629
|
+
context.tailwindConfig
|
|
630
|
+
)
|
|
631
|
+
).map(([_, type]) => type)
|
|
632
|
+
|
|
633
|
+
if (matchingTypes.length > 0) {
|
|
634
|
+
typesByMatches.set(matchesPerPlugin, matchingTypes)
|
|
635
|
+
}
|
|
636
|
+
|
|
468
637
|
matches.push(matchesPerPlugin)
|
|
469
638
|
}
|
|
470
639
|
}
|
|
471
640
|
|
|
472
641
|
if (isArbitraryValue(modifier)) {
|
|
473
|
-
// When generated arbitrary values are ambiguous, we can't know
|
|
474
|
-
// which to pick so don't generate any utilities for them
|
|
475
642
|
if (matches.length > 1) {
|
|
476
|
-
|
|
643
|
+
// Partition plugins in 2 categories so that we can start searching in the plugins that
|
|
644
|
+
// don't have `any` as a type first.
|
|
645
|
+
let [withAny, withoutAny] = matches.reduce(
|
|
646
|
+
(group, plugin) => {
|
|
647
|
+
let hasAnyType = plugin.some(([{ options }]) =>
|
|
648
|
+
options.types.some(({ type }) => type === 'any')
|
|
649
|
+
)
|
|
477
650
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
651
|
+
if (hasAnyType) {
|
|
652
|
+
group[0].push(plugin)
|
|
653
|
+
} else {
|
|
654
|
+
group[1].push(plugin)
|
|
655
|
+
}
|
|
656
|
+
return group
|
|
657
|
+
},
|
|
658
|
+
[[], []]
|
|
659
|
+
)
|
|
482
660
|
|
|
483
|
-
|
|
484
|
-
|
|
661
|
+
function findFallback(matches) {
|
|
662
|
+
// If only a single plugin matches, let's take that one
|
|
663
|
+
if (matches.length === 1) {
|
|
664
|
+
return matches[0]
|
|
665
|
+
}
|
|
485
666
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
667
|
+
// Otherwise, find the plugin that creates a valid rule given the arbitrary value, and
|
|
668
|
+
// also has the correct type which preferOnConflicts the plugin in case of clashes.
|
|
669
|
+
return matches.find((rules) => {
|
|
670
|
+
let matchingTypes = typesByMatches.get(rules)
|
|
671
|
+
return rules.some(([{ options }, rule]) => {
|
|
672
|
+
if (!isParsableNode(rule)) {
|
|
673
|
+
return false
|
|
489
674
|
}
|
|
490
|
-
}
|
|
491
675
|
|
|
492
|
-
|
|
493
|
-
|
|
676
|
+
return options.types.some(
|
|
677
|
+
({ type, preferOnConflict }) => matchingTypes.includes(type) && preferOnConflict
|
|
678
|
+
)
|
|
679
|
+
})
|
|
680
|
+
})
|
|
494
681
|
}
|
|
495
682
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
.flat()
|
|
503
|
-
.map((rule) =>
|
|
504
|
-
rule
|
|
505
|
-
.toString()
|
|
506
|
-
.split('\n')
|
|
507
|
-
.slice(1, -1) // Remove selector and closing '}'
|
|
508
|
-
.map((line) => line.trim())
|
|
509
|
-
.map((x) => ` ${x}`) // Re-indent
|
|
510
|
-
.join('\n')
|
|
511
|
-
)
|
|
512
|
-
.join('\n\n')
|
|
683
|
+
// Try to find a fallback plugin, because we already know that multiple plugins matched for
|
|
684
|
+
// the given arbitrary value.
|
|
685
|
+
let fallback = findFallback(withoutAny) ?? findFallback(withAny)
|
|
686
|
+
if (fallback) {
|
|
687
|
+
matches = [fallback]
|
|
688
|
+
}
|
|
513
689
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
690
|
+
// We couldn't find a fallback plugin which means that there are now multiple plugins that
|
|
691
|
+
// generated css for the current candidate. This means that the result is ambiguous and this
|
|
692
|
+
// should not happen. We won't generate anything right now, so let's report this to the user
|
|
693
|
+
// by logging some options about what they can do.
|
|
694
|
+
else {
|
|
695
|
+
let typesPerPlugin = matches.map(
|
|
696
|
+
(match) => new Set([...(typesByMatches.get(match) ?? [])])
|
|
697
|
+
)
|
|
698
|
+
|
|
699
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
700
|
+
for (let pluginTypes of typesPerPlugin) {
|
|
701
|
+
for (let type of pluginTypes) {
|
|
702
|
+
let removeFromOwnGroup = false
|
|
703
|
+
|
|
704
|
+
for (let otherGroup of typesPerPlugin) {
|
|
705
|
+
if (pluginTypes === otherGroup) continue
|
|
706
|
+
|
|
707
|
+
if (otherGroup.has(type)) {
|
|
708
|
+
otherGroup.delete(type)
|
|
709
|
+
removeFromOwnGroup = true
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
if (removeFromOwnGroup) pluginTypes.delete(type)
|
|
714
|
+
}
|
|
518
715
|
}
|
|
519
|
-
}
|
|
520
716
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
717
|
+
let messages = []
|
|
718
|
+
|
|
719
|
+
for (let [idx, group] of typesPerPlugin.entries()) {
|
|
720
|
+
for (let type of group) {
|
|
721
|
+
let rules = matches[idx]
|
|
722
|
+
.map(([, rule]) => rule)
|
|
723
|
+
.flat()
|
|
724
|
+
.map((rule) =>
|
|
725
|
+
rule
|
|
726
|
+
.toString()
|
|
727
|
+
.split('\n')
|
|
728
|
+
.slice(1, -1) // Remove selector and closing '}'
|
|
729
|
+
.map((line) => line.trim())
|
|
730
|
+
.map((x) => ` ${x}`) // Re-indent
|
|
731
|
+
.join('\n')
|
|
732
|
+
)
|
|
733
|
+
.join('\n\n')
|
|
734
|
+
|
|
735
|
+
messages.push(
|
|
736
|
+
` Use \`${candidate.replace('[', `[${type}:`)}\` for \`${rules.trim()}\``
|
|
737
|
+
)
|
|
738
|
+
break
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
log.warn([
|
|
743
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
744
|
+
...messages,
|
|
745
|
+
`If this is content and not a class, replace it with \`${candidate
|
|
746
|
+
.replace('[', '[')
|
|
747
|
+
.replace(']', ']')}\` to silence this warning.`,
|
|
748
|
+
])
|
|
749
|
+
continue
|
|
750
|
+
}
|
|
529
751
|
}
|
|
530
752
|
|
|
531
753
|
matches = matches.map((list) => list.filter((match) => isParsableNode(match[1])))
|
|
@@ -547,19 +769,13 @@ function* resolveMatches(candidate, context) {
|
|
|
547
769
|
match[1].raws.tailwind = { ...match[1].raws.tailwind, candidate }
|
|
548
770
|
|
|
549
771
|
// Apply final format selector
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
selector: rule.selector,
|
|
558
|
-
candidate,
|
|
559
|
-
context,
|
|
560
|
-
})
|
|
561
|
-
})
|
|
562
|
-
match[1] = container.nodes[0]
|
|
772
|
+
match = applyFinalFormat(match, { context, candidate, original })
|
|
773
|
+
|
|
774
|
+
// Skip rules with invalid selectors
|
|
775
|
+
// This will cause the candidate to be added to the "not class"
|
|
776
|
+
// cache skipping it entirely for future builds
|
|
777
|
+
if (match === null) {
|
|
778
|
+
continue
|
|
563
779
|
}
|
|
564
780
|
|
|
565
781
|
yield match
|
|
@@ -567,20 +783,105 @@ function* resolveMatches(candidate, context) {
|
|
|
567
783
|
}
|
|
568
784
|
}
|
|
569
785
|
|
|
786
|
+
function applyFinalFormat(match, { context, candidate, original }) {
|
|
787
|
+
if (!match[0].collectedFormats) {
|
|
788
|
+
return match
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
let isValid = true
|
|
792
|
+
let finalFormat
|
|
793
|
+
|
|
794
|
+
try {
|
|
795
|
+
finalFormat = formatVariantSelector(match[0].collectedFormats, {
|
|
796
|
+
context,
|
|
797
|
+
candidate,
|
|
798
|
+
})
|
|
799
|
+
} catch {
|
|
800
|
+
// The format selector we produced is invalid
|
|
801
|
+
// This could be because:
|
|
802
|
+
// - A bug exists
|
|
803
|
+
// - A plugin introduced an invalid variant selector (ex: `addVariant('foo', '&;foo')`)
|
|
804
|
+
// - The user used an invalid arbitrary variant (ex: `[&;foo]:underline`)
|
|
805
|
+
// Either way the build will fail because of this
|
|
806
|
+
// We would rather that the build pass "silently" given that this could
|
|
807
|
+
// happen because of picking up invalid things when scanning content
|
|
808
|
+
// So we'll throw out the candidate instead
|
|
809
|
+
|
|
810
|
+
return null
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
let container = postcss.root({ nodes: [match[1].clone()] })
|
|
814
|
+
|
|
815
|
+
container.walkRules((rule) => {
|
|
816
|
+
if (inKeyframes(rule)) {
|
|
817
|
+
return
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
try {
|
|
821
|
+
rule.selector = finalizeSelector(rule.selector, finalFormat, {
|
|
822
|
+
candidate: original,
|
|
823
|
+
context,
|
|
824
|
+
})
|
|
825
|
+
} catch {
|
|
826
|
+
// If this selector is invalid we also want to skip it
|
|
827
|
+
// But it's likely that being invalid here means there's a bug in a plugin rather than too loosely matching content
|
|
828
|
+
isValid = false
|
|
829
|
+
return false
|
|
830
|
+
}
|
|
831
|
+
})
|
|
832
|
+
|
|
833
|
+
if (!isValid) {
|
|
834
|
+
return null
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
match[1] = container.nodes[0]
|
|
838
|
+
|
|
839
|
+
return match
|
|
840
|
+
}
|
|
841
|
+
|
|
570
842
|
function inKeyframes(rule) {
|
|
571
843
|
return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
|
|
572
844
|
}
|
|
573
845
|
|
|
846
|
+
function getImportantStrategy(important) {
|
|
847
|
+
if (important === true) {
|
|
848
|
+
return (rule) => {
|
|
849
|
+
if (inKeyframes(rule)) {
|
|
850
|
+
return
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
rule.walkDecls((d) => {
|
|
854
|
+
if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
|
|
855
|
+
d.important = true
|
|
856
|
+
}
|
|
857
|
+
})
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if (typeof important === 'string') {
|
|
862
|
+
return (rule) => {
|
|
863
|
+
if (inKeyframes(rule)) {
|
|
864
|
+
return
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
rule.selectors = rule.selectors.map((selector) => {
|
|
868
|
+
return applyImportantSelector(selector, important)
|
|
869
|
+
})
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
574
874
|
function generateRules(candidates, context) {
|
|
575
875
|
let allRules = []
|
|
876
|
+
let strategy = getImportantStrategy(context.tailwindConfig.important)
|
|
576
877
|
|
|
577
878
|
for (let candidate of candidates) {
|
|
578
879
|
if (context.notClassCache.has(candidate)) {
|
|
579
880
|
continue
|
|
580
881
|
}
|
|
581
882
|
|
|
582
|
-
if (context.
|
|
583
|
-
allRules.
|
|
883
|
+
if (context.candidateRuleCache.has(candidate)) {
|
|
884
|
+
allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)))
|
|
584
885
|
continue
|
|
585
886
|
}
|
|
586
887
|
|
|
@@ -592,47 +893,27 @@ function generateRules(candidates, context) {
|
|
|
592
893
|
}
|
|
593
894
|
|
|
594
895
|
context.classCache.set(candidate, matches)
|
|
595
|
-
allRules.push(matches)
|
|
596
|
-
}
|
|
597
896
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (important === true) {
|
|
601
|
-
return (rule) => {
|
|
602
|
-
rule.walkDecls((d) => {
|
|
603
|
-
if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
|
|
604
|
-
d.important = true
|
|
605
|
-
}
|
|
606
|
-
})
|
|
607
|
-
}
|
|
608
|
-
}
|
|
897
|
+
let rules = context.candidateRuleCache.get(candidate) ?? new Set()
|
|
898
|
+
context.candidateRuleCache.set(candidate, rules)
|
|
609
899
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
rule.selectors = rule.selectors.map((selector) => {
|
|
613
|
-
return `${important} ${selector}`
|
|
614
|
-
})
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
})(context.tailwindConfig.important)
|
|
900
|
+
for (const match of matches) {
|
|
901
|
+
let [{ sort, options }, rule] = match
|
|
618
902
|
|
|
619
|
-
|
|
620
|
-
if (options.respectImportant) {
|
|
621
|
-
if (strategy) {
|
|
903
|
+
if (options.respectImportant && strategy) {
|
|
622
904
|
let container = postcss.root({ nodes: [rule.clone()] })
|
|
623
|
-
container.walkRules(
|
|
624
|
-
if (inKeyframes(r)) {
|
|
625
|
-
return
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
strategy(r)
|
|
629
|
-
})
|
|
905
|
+
container.walkRules(strategy)
|
|
630
906
|
rule = container.nodes[0]
|
|
631
907
|
}
|
|
908
|
+
|
|
909
|
+
let newEntry = [sort, rule]
|
|
910
|
+
rules.add(newEntry)
|
|
911
|
+
context.ruleCache.add(newEntry)
|
|
912
|
+
allRules.push(newEntry)
|
|
632
913
|
}
|
|
914
|
+
}
|
|
633
915
|
|
|
634
|
-
|
|
635
|
-
})
|
|
916
|
+
return allRules
|
|
636
917
|
}
|
|
637
918
|
|
|
638
919
|
function isArbitraryValue(input) {
|