tailwindcss 0.0.0-insiders.eebf529 → 0.0.0-insiders.ef2ebb2
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 +15 -7
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +4 -0
- package/index.css +5 -0
- package/lib/cli/build/index.js +57 -0
- package/lib/cli/build/plugin.js +433 -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 -704
- package/lib/corePluginList.js +13 -3
- package/lib/corePlugins.js +2399 -1867
- package/lib/css/preflight.css +17 -9
- package/lib/featureFlags.js +50 -26
- package/lib/index.js +1 -31
- package/lib/lib/cacheInvalidation.js +92 -0
- package/lib/lib/collapseAdjacentRules.js +30 -10
- package/lib/lib/collapseDuplicateDeclarations.js +60 -4
- package/lib/lib/content.js +207 -0
- package/lib/lib/defaultExtractor.js +243 -0
- package/lib/lib/detectNesting.js +21 -10
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +467 -161
- package/lib/lib/expandTailwindAtRules.js +200 -133
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +550 -200
- 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 +36 -38
- package/lib/lib/offsets.js +306 -0
- package/lib/lib/partitionApplyAtRules.js +58 -0
- package/lib/lib/regex.js +74 -0
- package/lib/lib/remap-bitfield.js +89 -0
- package/lib/lib/resolveDefaultsAtRules.js +98 -58
- package/lib/lib/setupContextUtils.js +767 -325
- package/lib/lib/setupTrackingContext.js +71 -75
- package/lib/lib/sharedState.js +70 -10
- package/lib/lib/substituteScreenAtRules.js +14 -10
- package/lib/plugin.js +166 -0
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +21 -0
- package/lib/postcss-plugins/nesting/plugin.js +89 -0
- package/lib/processTailwindFeatures.js +39 -26
- 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 +23 -3
- package/lib/util/color.js +70 -38
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +7 -2
- package/lib/util/createPlugin.js +8 -6
- package/lib/util/createUtilityPlugin.js +16 -16
- package/lib/util/dataTypes.js +182 -111
- package/lib/util/defaults.js +14 -3
- package/lib/util/escapeClassName.js +13 -8
- package/lib/util/escapeCommas.js +7 -2
- package/lib/util/flattenColorPalette.js +11 -12
- 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 +44 -13
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +167 -67
- package/lib/util/normalizeScreens.js +128 -11
- package/lib/util/parseAnimationValue.js +44 -40
- package/lib/util/parseBoxShadowValue.js +34 -23
- 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 +157 -69
- package/lib/util/prefixSelector.js +30 -12
- package/lib/util/pseudoElements.js +209 -0
- package/lib/util/removeAlphaVariables.js +31 -0
- package/lib/util/resolveConfig.js +101 -79
- package/lib/util/resolveConfigPath.js +30 -12
- 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 -3
- package/lib/util/toPath.js +26 -3
- package/lib/util/transformThemeValue.js +40 -30
- 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/nesting/index.js +2 -12
- package/package.json +63 -62
- package/plugin.d.ts +11 -0
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +105 -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 +476 -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 -766
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +800 -296
- package/src/css/preflight.css +17 -9
- package/src/featureFlags.js +20 -6
- package/src/index.js +1 -34
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +66 -1
- package/src/lib/content.js +240 -0
- package/src/lib/defaultExtractor.js +217 -0
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +83 -9
- package/src/lib/expandApplyAtRules.js +515 -153
- package/src/lib/expandTailwindAtRules.js +147 -86
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +541 -147
- 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 +5 -26
- package/src/lib/offsets.js +373 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +59 -17
- package/src/lib/setupContextUtils.js +693 -176
- package/src/lib/setupTrackingContext.js +52 -65
- package/src/lib/sharedState.js +54 -7
- package/src/plugin.js +141 -0
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +12 -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 +19 -2
- package/src/util/color.js +44 -12
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +67 -23
- package/src/util/defaults.js +6 -0
- 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 +35 -7
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +86 -7
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +4 -3
- 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 +30 -10
- package/src/util/pseudoElements.js +167 -0
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +74 -26
- package/src/util/resolveConfigPath.js +12 -1
- package/src/util/splitAtTopLevelOnly.js +52 -0
- package/src/util/toPath.js +23 -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} +220 -167
- 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 +369 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +298 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +372 -0
- package/types/index.d.ts +7 -0
- package/CHANGELOG.md +0 -1853
- package/lib/cli-peer-dependencies.js +0 -15
- package/lib/constants.js +0 -37
- package/lib/lib/setupWatchingContext.js +0 -288
- package/nesting/plugin.js +0 -41
- package/peers/index.js +0 -76107
- 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/src/lib/setupWatchingContext.js +0 -311
package/src/lib/generateRules.js
CHANGED
|
@@ -3,18 +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
|
-
import
|
|
8
|
+
import * as sharedState from './sharedState'
|
|
9
|
+
import {
|
|
10
|
+
formatVariantSelector,
|
|
11
|
+
finalizeSelector,
|
|
12
|
+
eliminateIrrelevantSelectors,
|
|
13
|
+
} from '../util/formatVariantSelector'
|
|
9
14
|
import { asClass } from '../util/nameClass'
|
|
10
15
|
import { normalize } from '../util/dataTypes'
|
|
11
|
-
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'
|
|
12
21
|
|
|
13
22
|
let classNameParser = selectorParser((selectors) => {
|
|
14
23
|
return selectors.first.filter(({ type }) => type === 'class').pop().value
|
|
15
24
|
})
|
|
16
25
|
|
|
17
|
-
function getClassNameFromSelector(selector) {
|
|
26
|
+
export function getClassNameFromSelector(selector) {
|
|
18
27
|
return classNameParser.transformSync(selector)
|
|
19
28
|
}
|
|
20
29
|
|
|
@@ -25,33 +34,49 @@ function getClassNameFromSelector(selector) {
|
|
|
25
34
|
// Example with dynamic classes:
|
|
26
35
|
// ['grid-cols', '[[linename],1fr,auto]']
|
|
27
36
|
// ['grid', 'cols-[[linename],1fr,auto]']
|
|
28
|
-
function* candidatePermutations(candidate
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
function* candidatePermutations(candidate) {
|
|
38
|
+
let lastIndex = Infinity
|
|
39
|
+
|
|
40
|
+
while (lastIndex >= 0) {
|
|
41
|
+
let dashIdx
|
|
42
|
+
let wasSlash = false
|
|
43
|
+
|
|
44
|
+
if (lastIndex === Infinity && candidate.endsWith(']')) {
|
|
45
|
+
let bracketIdx = candidate.indexOf('[')
|
|
46
|
+
|
|
47
|
+
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
48
|
+
// eg. 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
|
|
60
|
+
} else {
|
|
61
|
+
dashIdx = candidate.lastIndexOf('-', lastIndex)
|
|
62
|
+
}
|
|
37
63
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} else {
|
|
42
|
-
dashIdx = candidate.lastIndexOf('-', lastIndex)
|
|
43
|
-
}
|
|
64
|
+
if (dashIdx < 0) {
|
|
65
|
+
break
|
|
66
|
+
}
|
|
44
67
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
68
|
+
let prefix = candidate.slice(0, dashIdx)
|
|
69
|
+
let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1)
|
|
48
70
|
|
|
49
|
-
|
|
50
|
-
let modifier = candidate.slice(dashIdx + 1)
|
|
71
|
+
lastIndex = dashIdx - 1
|
|
51
72
|
|
|
52
|
-
|
|
73
|
+
// TODO: This feels a bit hacky
|
|
74
|
+
if (prefix === '' || modifier === '/') {
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
53
77
|
|
|
54
|
-
|
|
78
|
+
yield [prefix, modifier]
|
|
79
|
+
}
|
|
55
80
|
}
|
|
56
81
|
|
|
57
82
|
function applyPrefix(matches, context) {
|
|
@@ -63,9 +88,23 @@ function applyPrefix(matches, context) {
|
|
|
63
88
|
let [meta] = match
|
|
64
89
|
if (meta.options.respectPrefix) {
|
|
65
90
|
let container = postcss.root({ nodes: [match[1].clone()] })
|
|
91
|
+
let classCandidate = match[1].raws.tailwind.classCandidate
|
|
92
|
+
|
|
66
93
|
container.walkRules((r) => {
|
|
67
|
-
|
|
94
|
+
// If this is a negative utility with a dash *before* the prefix we
|
|
95
|
+
// have to ensure that the generated selector matches the candidate
|
|
96
|
+
|
|
97
|
+
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
98
|
+
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
99
|
+
let shouldPrependNegative = classCandidate.startsWith('-')
|
|
100
|
+
|
|
101
|
+
r.selector = prefixSelector(
|
|
102
|
+
context.tailwindConfig.prefix,
|
|
103
|
+
r.selector,
|
|
104
|
+
shouldPrependNegative
|
|
105
|
+
)
|
|
68
106
|
})
|
|
107
|
+
|
|
69
108
|
match[1] = container.nodes[0]
|
|
70
109
|
}
|
|
71
110
|
}
|
|
@@ -73,20 +112,32 @@ function applyPrefix(matches, context) {
|
|
|
73
112
|
return matches
|
|
74
113
|
}
|
|
75
114
|
|
|
76
|
-
function applyImportant(matches) {
|
|
115
|
+
function applyImportant(matches, classCandidate) {
|
|
77
116
|
if (matches.length === 0) {
|
|
78
117
|
return matches
|
|
79
118
|
}
|
|
119
|
+
|
|
80
120
|
let result = []
|
|
81
121
|
|
|
82
122
|
for (let [meta, rule] of matches) {
|
|
83
123
|
let container = postcss.root({ nodes: [rule.clone()] })
|
|
124
|
+
|
|
84
125
|
container.walkRules((r) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
|
|
88
138
|
r.walkDecls((d) => (d.important = true))
|
|
89
139
|
})
|
|
140
|
+
|
|
90
141
|
result.push([{ ...meta, important: true }, container.nodes[0]])
|
|
91
142
|
}
|
|
92
143
|
|
|
@@ -107,22 +158,96 @@ function applyVariant(variant, matches, context) {
|
|
|
107
158
|
return matches
|
|
108
159
|
}
|
|
109
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
|
+
|
|
110
227
|
if (context.variantMap.has(variant)) {
|
|
111
|
-
let
|
|
228
|
+
let isArbitraryVariant = isArbitraryValue(variant)
|
|
229
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice()
|
|
112
230
|
let result = []
|
|
113
231
|
|
|
114
232
|
for (let [meta, rule] of matches) {
|
|
233
|
+
// Don't generate variants for user css
|
|
234
|
+
if (meta.layer === 'user') {
|
|
235
|
+
continue
|
|
236
|
+
}
|
|
237
|
+
|
|
115
238
|
let container = postcss.root({ nodes: [rule.clone()] })
|
|
116
239
|
|
|
117
|
-
for (let [variantSort, variantFunction] of variantFunctionTuples) {
|
|
118
|
-
let clone = container.clone()
|
|
240
|
+
for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples) {
|
|
241
|
+
let clone = (containerFromArray ?? container).clone()
|
|
119
242
|
let collectedFormats = []
|
|
120
243
|
|
|
121
|
-
let originals = new Map()
|
|
122
|
-
|
|
123
244
|
function prepareBackup() {
|
|
124
|
-
|
|
125
|
-
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))
|
|
126
251
|
}
|
|
127
252
|
|
|
128
253
|
function modifySelectors(modifierFunction) {
|
|
@@ -162,25 +287,54 @@ function applyVariant(variant, matches, context) {
|
|
|
162
287
|
clone.append(wrapper)
|
|
163
288
|
},
|
|
164
289
|
format(selectorFormat) {
|
|
165
|
-
collectedFormats.push(
|
|
290
|
+
collectedFormats.push({
|
|
291
|
+
format: selectorFormat,
|
|
292
|
+
isArbitraryVariant,
|
|
293
|
+
})
|
|
166
294
|
},
|
|
295
|
+
args,
|
|
167
296
|
})
|
|
168
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
|
+
|
|
169
318
|
if (typeof ruleWithVariant === 'string') {
|
|
170
|
-
collectedFormats.push(
|
|
319
|
+
collectedFormats.push({
|
|
320
|
+
format: ruleWithVariant,
|
|
321
|
+
isArbitraryVariant,
|
|
322
|
+
})
|
|
171
323
|
}
|
|
172
324
|
|
|
173
325
|
if (ruleWithVariant === null) {
|
|
174
326
|
continue
|
|
175
327
|
}
|
|
176
328
|
|
|
177
|
-
// We
|
|
329
|
+
// We had to backup selectors, therefore we assume that somebody touched
|
|
178
330
|
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
179
331
|
// can restore the selectors, and collect the format strings.
|
|
180
|
-
if (
|
|
332
|
+
if (clone.raws.neededBackup) {
|
|
333
|
+
delete clone.raws.neededBackup
|
|
181
334
|
clone.walkRules((rule) => {
|
|
182
|
-
|
|
183
|
-
|
|
335
|
+
let before = rule.raws.originalSelector
|
|
336
|
+
if (!before) return
|
|
337
|
+
delete rule.raws.originalSelector
|
|
184
338
|
if (before === rule.selector) return // No mutation happened
|
|
185
339
|
|
|
186
340
|
let modified = rule.selector
|
|
@@ -206,15 +360,28 @@ function applyVariant(variant, matches, context) {
|
|
|
206
360
|
// modified (by plugin): .foo .foo\\:markdown > p
|
|
207
361
|
// rebuiltBase (internal): .foo\\:markdown > p
|
|
208
362
|
// format: .foo &
|
|
209
|
-
collectedFormats.push(
|
|
363
|
+
collectedFormats.push({
|
|
364
|
+
format: modified.replace(rebuiltBase, '&'),
|
|
365
|
+
isArbitraryVariant,
|
|
366
|
+
})
|
|
210
367
|
rule.selector = before
|
|
211
368
|
})
|
|
212
369
|
}
|
|
213
370
|
|
|
371
|
+
// This tracks the originating layer for the variant
|
|
372
|
+
// For example:
|
|
373
|
+
// .sm:underline {} is a variant of something in the utilities layer
|
|
374
|
+
// .sm:container {} is a variant of the container component
|
|
375
|
+
clone.nodes[0].raws.tailwind = { ...clone.nodes[0].raws.tailwind, parentLayer: meta.layer }
|
|
376
|
+
|
|
214
377
|
let withOffset = [
|
|
215
378
|
{
|
|
216
379
|
...meta,
|
|
217
|
-
sort:
|
|
380
|
+
sort: context.offsets.applyVariantOffset(
|
|
381
|
+
meta.sort,
|
|
382
|
+
variantSort,
|
|
383
|
+
Object.assign(args, context.variantOptions.get(variant))
|
|
384
|
+
),
|
|
218
385
|
collectedFormats: (meta.collectedFormats ?? []).concat(collectedFormats),
|
|
219
386
|
},
|
|
220
387
|
clone.nodes[0],
|
|
@@ -248,6 +415,61 @@ function parseRules(rule, cache, options = {}) {
|
|
|
248
415
|
return [cache.get(rule), options]
|
|
249
416
|
}
|
|
250
417
|
|
|
418
|
+
const IS_VALID_PROPERTY_NAME = /^[a-z_-]/
|
|
419
|
+
|
|
420
|
+
function isValidPropName(name) {
|
|
421
|
+
return IS_VALID_PROPERTY_NAME.test(name)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* @param {string} declaration
|
|
426
|
+
* @returns {boolean}
|
|
427
|
+
*/
|
|
428
|
+
function looksLikeUri(declaration) {
|
|
429
|
+
// Quick bailout for obvious non-urls
|
|
430
|
+
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
431
|
+
if (!declaration.includes('://')) {
|
|
432
|
+
return false
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
try {
|
|
436
|
+
const url = new URL(declaration)
|
|
437
|
+
return url.scheme !== '' && url.host !== ''
|
|
438
|
+
} catch (err) {
|
|
439
|
+
// Definitely not a valid url
|
|
440
|
+
return false
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function isParsableNode(node) {
|
|
445
|
+
let isParsable = true
|
|
446
|
+
|
|
447
|
+
node.walkDecls((decl) => {
|
|
448
|
+
if (!isParsableCssValue(decl.prop, decl.value)) {
|
|
449
|
+
isParsable = false
|
|
450
|
+
return false
|
|
451
|
+
}
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
return isParsable
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function isParsableCssValue(property, value) {
|
|
458
|
+
// We don't want to to treat [https://example.com] as a custom property
|
|
459
|
+
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
460
|
+
// So we short-circuit here by checking if the custom property looks like a url
|
|
461
|
+
if (looksLikeUri(`${property}:${value}`)) {
|
|
462
|
+
return false
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
try {
|
|
466
|
+
postcss.parse(`a{${property}:${value}}`).toResult()
|
|
467
|
+
return true
|
|
468
|
+
} catch (err) {
|
|
469
|
+
return false
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
251
473
|
function extractArbitraryProperty(classCandidate, context) {
|
|
252
474
|
let [, property, value] = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/) ?? []
|
|
253
475
|
|
|
@@ -255,15 +477,25 @@ function extractArbitraryProperty(classCandidate, context) {
|
|
|
255
477
|
return null
|
|
256
478
|
}
|
|
257
479
|
|
|
480
|
+
if (!isValidPropName(property)) {
|
|
481
|
+
return null
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!isValidArbitraryValue(value)) {
|
|
485
|
+
return null
|
|
486
|
+
}
|
|
487
|
+
|
|
258
488
|
let normalized = normalize(value)
|
|
259
489
|
|
|
260
|
-
if (!
|
|
490
|
+
if (!isParsableCssValue(property, normalized)) {
|
|
261
491
|
return null
|
|
262
492
|
}
|
|
263
493
|
|
|
494
|
+
let sort = context.offsets.arbitraryProperty()
|
|
495
|
+
|
|
264
496
|
return [
|
|
265
497
|
[
|
|
266
|
-
{ sort
|
|
498
|
+
{ sort, layer: 'utilities' },
|
|
267
499
|
() => ({
|
|
268
500
|
[asClass(classCandidate)]: {
|
|
269
501
|
[property]: normalized,
|
|
@@ -290,7 +522,11 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
290
522
|
const twConfigPrefix = context.tailwindConfig.prefix
|
|
291
523
|
|
|
292
524
|
const twConfigPrefixLen = twConfigPrefix.length
|
|
293
|
-
|
|
525
|
+
|
|
526
|
+
const hasMatchingPrefix =
|
|
527
|
+
candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`)
|
|
528
|
+
|
|
529
|
+
if (candidatePrefix[twConfigPrefixLen] === '-' && hasMatchingPrefix) {
|
|
294
530
|
negative = true
|
|
295
531
|
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)
|
|
296
532
|
}
|
|
@@ -302,16 +538,31 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
302
538
|
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)) {
|
|
303
539
|
if (context.candidateRuleMap.has(prefix)) {
|
|
304
540
|
yield [context.candidateRuleMap.get(prefix), negative ? `-${modifier}` : modifier]
|
|
305
|
-
return
|
|
306
541
|
}
|
|
307
542
|
}
|
|
308
543
|
}
|
|
309
544
|
|
|
310
545
|
function splitWithSeparator(input, separator) {
|
|
311
|
-
|
|
546
|
+
if (input === sharedState.NOT_ON_DEMAND) {
|
|
547
|
+
return [sharedState.NOT_ON_DEMAND]
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return splitAtTopLevelOnly(input, separator)
|
|
312
551
|
}
|
|
313
552
|
|
|
314
|
-
function*
|
|
553
|
+
function* recordCandidates(matches, classCandidate) {
|
|
554
|
+
for (const match of matches) {
|
|
555
|
+
match[1].raws.tailwind = {
|
|
556
|
+
...match[1].raws.tailwind,
|
|
557
|
+
classCandidate,
|
|
558
|
+
preserveSource: match[0].options?.preserveSource ?? false,
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
yield match
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
315
566
|
let separator = context.tailwindConfig.separator
|
|
316
567
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse()
|
|
317
568
|
let important = false
|
|
@@ -321,6 +572,15 @@ function* resolveMatches(candidate, context) {
|
|
|
321
572
|
classCandidate = classCandidate.slice(1)
|
|
322
573
|
}
|
|
323
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
|
+
|
|
324
584
|
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
325
585
|
// function sortAgainst(toSort, against) {
|
|
326
586
|
// return toSort.slice().sort((a, z) => {
|
|
@@ -361,71 +621,144 @@ function* resolveMatches(candidate, context) {
|
|
|
361
621
|
}
|
|
362
622
|
|
|
363
623
|
if (matchesPerPlugin.length > 0) {
|
|
364
|
-
|
|
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
|
+
|
|
365
637
|
matches.push(matchesPerPlugin)
|
|
366
638
|
}
|
|
367
639
|
}
|
|
368
640
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
for (let otherGroup of typesPerPlugin) {
|
|
380
|
-
if (pluginTypes === otherGroup) continue
|
|
641
|
+
if (isArbitraryValue(modifier)) {
|
|
642
|
+
if (matches.length > 1) {
|
|
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
|
+
)
|
|
381
650
|
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
651
|
+
if (hasAnyType) {
|
|
652
|
+
group[0].push(plugin)
|
|
653
|
+
} else {
|
|
654
|
+
group[1].push(plugin)
|
|
385
655
|
}
|
|
656
|
+
return group
|
|
657
|
+
},
|
|
658
|
+
[[], []]
|
|
659
|
+
)
|
|
660
|
+
|
|
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]
|
|
386
665
|
}
|
|
387
666
|
|
|
388
|
-
|
|
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
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return options.types.some(
|
|
677
|
+
({ type, preferOnConflict }) => matchingTypes.includes(type) && preferOnConflict
|
|
678
|
+
)
|
|
679
|
+
})
|
|
680
|
+
})
|
|
389
681
|
}
|
|
390
|
-
}
|
|
391
682
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
.flat()
|
|
399
|
-
.map((rule) =>
|
|
400
|
-
rule
|
|
401
|
-
.toString()
|
|
402
|
-
.split('\n')
|
|
403
|
-
.slice(1, -1) // Remove selector and closing '}'
|
|
404
|
-
.map((line) => line.trim())
|
|
405
|
-
.map((x) => ` ${x}`) // Re-indent
|
|
406
|
-
.join('\n')
|
|
407
|
-
)
|
|
408
|
-
.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
|
+
}
|
|
409
689
|
|
|
410
|
-
|
|
411
|
-
|
|
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
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
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
|
|
412
750
|
}
|
|
413
751
|
}
|
|
414
752
|
|
|
415
|
-
|
|
416
|
-
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
417
|
-
...messages,
|
|
418
|
-
`If this is content and not a class, replace it with \`${candidate
|
|
419
|
-
.replace('[', '[')
|
|
420
|
-
.replace(']', ']')}\` to silence this warning.`,
|
|
421
|
-
])
|
|
422
|
-
continue
|
|
753
|
+
matches = matches.map((list) => list.filter((match) => isParsableNode(match[1])))
|
|
423
754
|
}
|
|
424
755
|
|
|
425
|
-
matches =
|
|
756
|
+
matches = matches.flat()
|
|
757
|
+
matches = Array.from(recordCandidates(matches, classCandidate))
|
|
758
|
+
matches = applyPrefix(matches, context)
|
|
426
759
|
|
|
427
760
|
if (important) {
|
|
428
|
-
matches = applyImportant(matches,
|
|
761
|
+
matches = applyImportant(matches, classCandidate)
|
|
429
762
|
}
|
|
430
763
|
|
|
431
764
|
for (let variant of variants) {
|
|
@@ -433,20 +766,16 @@ function* resolveMatches(candidate, context) {
|
|
|
433
766
|
}
|
|
434
767
|
|
|
435
768
|
for (let match of matches) {
|
|
769
|
+
match[1].raws.tailwind = { ...match[1].raws.tailwind, candidate }
|
|
770
|
+
|
|
436
771
|
// Apply final format selector
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
selector: rule.selector,
|
|
445
|
-
candidate,
|
|
446
|
-
context,
|
|
447
|
-
})
|
|
448
|
-
})
|
|
449
|
-
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
|
|
450
779
|
}
|
|
451
780
|
|
|
452
781
|
yield match
|
|
@@ -454,20 +783,105 @@ function* resolveMatches(candidate, context) {
|
|
|
454
783
|
}
|
|
455
784
|
}
|
|
456
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
|
+
|
|
457
842
|
function inKeyframes(rule) {
|
|
458
843
|
return rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'
|
|
459
844
|
}
|
|
460
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
|
+
|
|
461
874
|
function generateRules(candidates, context) {
|
|
462
875
|
let allRules = []
|
|
876
|
+
let strategy = getImportantStrategy(context.tailwindConfig.important)
|
|
463
877
|
|
|
464
878
|
for (let candidate of candidates) {
|
|
465
879
|
if (context.notClassCache.has(candidate)) {
|
|
466
880
|
continue
|
|
467
881
|
}
|
|
468
882
|
|
|
469
|
-
if (context.
|
|
470
|
-
allRules.
|
|
883
|
+
if (context.candidateRuleCache.has(candidate)) {
|
|
884
|
+
allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)))
|
|
471
885
|
continue
|
|
472
886
|
}
|
|
473
887
|
|
|
@@ -479,47 +893,27 @@ function generateRules(candidates, context) {
|
|
|
479
893
|
}
|
|
480
894
|
|
|
481
895
|
context.classCache.set(candidate, matches)
|
|
482
|
-
allRules.push(matches)
|
|
483
|
-
}
|
|
484
896
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (important === true) {
|
|
488
|
-
return (rule) => {
|
|
489
|
-
rule.walkDecls((d) => {
|
|
490
|
-
if (d.parent.type === 'rule' && !inKeyframes(d.parent)) {
|
|
491
|
-
d.important = true
|
|
492
|
-
}
|
|
493
|
-
})
|
|
494
|
-
}
|
|
495
|
-
}
|
|
897
|
+
let rules = context.candidateRuleCache.get(candidate) ?? new Set()
|
|
898
|
+
context.candidateRuleCache.set(candidate, rules)
|
|
496
899
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
rule.selectors = rule.selectors.map((selector) => {
|
|
500
|
-
return `${important} ${selector}`
|
|
501
|
-
})
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
})(context.tailwindConfig.important)
|
|
900
|
+
for (const match of matches) {
|
|
901
|
+
let [{ sort, options }, rule] = match
|
|
505
902
|
|
|
506
|
-
|
|
507
|
-
if (options.respectImportant) {
|
|
508
|
-
if (strategy) {
|
|
903
|
+
if (options.respectImportant && strategy) {
|
|
509
904
|
let container = postcss.root({ nodes: [rule.clone()] })
|
|
510
|
-
container.walkRules(
|
|
511
|
-
if (inKeyframes(r)) {
|
|
512
|
-
return
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
strategy(r)
|
|
516
|
-
})
|
|
905
|
+
container.walkRules(strategy)
|
|
517
906
|
rule = container.nodes[0]
|
|
518
907
|
}
|
|
908
|
+
|
|
909
|
+
let newEntry = [sort, rule]
|
|
910
|
+
rules.add(newEntry)
|
|
911
|
+
context.ruleCache.add(newEntry)
|
|
912
|
+
allRules.push(newEntry)
|
|
519
913
|
}
|
|
914
|
+
}
|
|
520
915
|
|
|
521
|
-
|
|
522
|
-
})
|
|
916
|
+
return allRules
|
|
523
917
|
}
|
|
524
918
|
|
|
525
919
|
function isArbitraryValue(input) {
|