tailwindcss 0.0.0-insiders.93e0fdf → 0.0.0-insiders.941ef21
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/CHANGELOG.md +293 -5
- package/README.md +13 -9
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +4 -0
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +48 -0
- package/lib/cli/build/plugin.js +362 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +178 -0
- package/lib/cli/help/index.js +71 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/init/index.js +46 -0
- package/lib/cli/shared.js +12 -0
- package/lib/cli-peer-dependencies.js +20 -7
- package/lib/cli.js +109 -611
- package/lib/constants.js +27 -20
- package/lib/corePluginList.js +6 -3
- package/lib/corePlugins.js +2005 -1686
- package/lib/css/preflight.css +4 -4
- package/lib/featureFlags.js +36 -24
- package/lib/index.js +28 -10
- package/lib/lib/cacheInvalidation.js +90 -0
- package/lib/lib/collapseAdjacentRules.js +28 -10
- package/lib/lib/collapseDuplicateDeclarations.js +14 -11
- package/lib/lib/content.js +177 -0
- package/lib/lib/defaultExtractor.js +225 -33
- package/lib/lib/detectNesting.js +13 -10
- package/lib/lib/evaluateTailwindFunctions.js +118 -55
- package/lib/lib/expandApplyAtRules.js +439 -193
- package/lib/lib/expandTailwindAtRules.js +104 -109
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +405 -197
- package/lib/lib/getModuleDependencies.js +11 -8
- package/lib/lib/normalizeTailwindDirectives.js +35 -32
- package/lib/lib/offsets.js +285 -0
- package/lib/lib/partitionApplyAtRules.js +11 -8
- package/lib/lib/regex.js +60 -0
- package/lib/lib/remap-bitfield.js +87 -0
- package/lib/lib/resolveDefaultsAtRules.js +89 -67
- package/lib/lib/setupContextUtils.js +617 -309
- package/lib/lib/setupTrackingContext.js +38 -67
- package/lib/lib/sharedState.js +25 -15
- package/lib/lib/substituteScreenAtRules.js +11 -9
- package/lib/postcss-plugins/nesting/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +8 -6
- package/lib/postcss-plugins/nesting/plugin.js +48 -14
- package/lib/processTailwindFeatures.js +31 -28
- package/lib/public/colors.js +247 -245
- package/lib/public/create-plugin.js +6 -4
- package/lib/public/default-config.js +7 -5
- package/lib/public/default-theme.js +7 -5
- package/lib/public/resolve-config.js +8 -5
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +11 -6
- package/lib/util/cloneDeep.js +7 -6
- package/lib/util/cloneNodes.js +21 -3
- package/lib/util/color.js +53 -54
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -5
- package/lib/util/createUtilityPlugin.js +10 -8
- package/lib/util/dataTypes.js +143 -110
- package/lib/util/defaults.js +8 -5
- package/lib/util/escapeClassName.js +9 -6
- package/lib/util/escapeCommas.js +5 -2
- package/lib/util/flattenColorPalette.js +9 -10
- package/lib/util/formatVariantSelector.js +193 -86
- package/lib/util/getAllConfigs.js +29 -10
- package/lib/util/hashConfig.js +6 -3
- package/lib/util/isKeyframeRule.js +5 -2
- package/lib/util/isPlainObject.js +5 -2
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +23 -15
- package/lib/util/log.js +20 -14
- package/lib/util/nameClass.js +20 -9
- package/lib/util/negateValue.js +22 -7
- package/lib/util/normalizeConfig.js +124 -83
- package/lib/util/normalizeScreens.js +119 -8
- package/lib/util/parseAnimationValue.js +42 -40
- package/lib/util/parseBoxShadowValue.js +29 -22
- package/lib/util/parseDependency.js +38 -56
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +11 -8
- package/lib/util/pluginUtils.js +155 -51
- package/lib/util/prefixSelector.js +7 -4
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +93 -72
- package/lib/util/resolveConfigPath.js +10 -7
- package/lib/util/responsive.js +8 -5
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +4 -1
- package/lib/util/toColorValue.js +5 -2
- package/lib/util/toPath.js +20 -4
- package/lib/util/transformThemeValue.js +37 -25
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +23 -15
- package/package.json +44 -37
- package/peers/index.js +11099 -7475
- 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/deps.js +56 -0
- package/src/cli/build/index.js +49 -0
- package/src/cli/build/plugin.js +434 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +227 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +3 -0
- package/src/cli/init/index.js +50 -0
- package/src/cli/shared.js +5 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +50 -631
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +399 -84
- package/src/css/preflight.css +4 -4
- package/src/featureFlags.js +14 -4
- package/src/index.js +20 -1
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/content.js +213 -0
- package/src/lib/defaultExtractor.js +196 -35
- package/src/lib/evaluateTailwindFunctions.js +78 -7
- package/src/lib/expandApplyAtRules.js +482 -183
- package/src/lib/expandTailwindAtRules.js +37 -55
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +359 -112
- package/src/lib/offsets.js +351 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -32
- package/src/lib/setupContextUtils.js +517 -146
- package/src/lib/setupTrackingContext.js +11 -48
- package/src/lib/sharedState.js +3 -0
- package/src/postcss-plugins/nesting/README.md +2 -2
- package/src/postcss-plugins/nesting/plugin.js +36 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +25 -21
- package/src/util/dataTypes.js +54 -21
- package/src/util/formatVariantSelector.js +196 -62
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +8 -8
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +10 -2
- package/src/util/normalizeConfig.js +40 -10
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +3 -2
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +132 -10
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -32
- package/src/util/splitAtTopLevelOnly.js +45 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +13 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/stubs/defaultConfig.stub.js +168 -164
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +363 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +342 -0
- package/types/index.d.ts +7 -0
|
@@ -11,21 +11,48 @@ import isPlainObject from '../util/isPlainObject'
|
|
|
11
11
|
import escapeClassName from '../util/escapeClassName'
|
|
12
12
|
import nameClass, { formatClass } from '../util/nameClass'
|
|
13
13
|
import { coerceValue } from '../util/pluginUtils'
|
|
14
|
-
import bigSign from '../util/bigSign'
|
|
15
14
|
import { variantPlugins, corePlugins } from '../corePlugins'
|
|
16
15
|
import * as sharedState from './sharedState'
|
|
17
16
|
import { env } from './sharedState'
|
|
18
17
|
import { toPath } from '../util/toPath'
|
|
19
18
|
import log from '../util/log'
|
|
20
19
|
import negateValue from '../util/negateValue'
|
|
21
|
-
import
|
|
22
|
-
import { generateRules } from './generateRules'
|
|
20
|
+
import isSyntacticallyValidPropertyValue from '../util/isSyntacticallyValidPropertyValue'
|
|
21
|
+
import { generateRules, getClassNameFromSelector } from './generateRules'
|
|
22
|
+
import { hasContentChanged } from './cacheInvalidation.js'
|
|
23
|
+
import { Offsets } from './offsets.js'
|
|
24
|
+
import { flagEnabled } from '../featureFlags.js'
|
|
25
|
+
import { finalizeSelector, formatVariantSelector } from '../util/formatVariantSelector'
|
|
26
|
+
|
|
27
|
+
const VARIANT_TYPES = {
|
|
28
|
+
AddVariant: Symbol.for('ADD_VARIANT'),
|
|
29
|
+
MatchVariant: Symbol.for('MATCH_VARIANT'),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const VARIANT_INFO = {
|
|
33
|
+
Base: 1 << 0,
|
|
34
|
+
Dynamic: 1 << 1,
|
|
35
|
+
}
|
|
23
36
|
|
|
24
37
|
function prefix(context, selector) {
|
|
25
38
|
let prefix = context.tailwindConfig.prefix
|
|
26
39
|
return typeof prefix === 'function' ? prefix(selector) : prefix + selector
|
|
27
40
|
}
|
|
28
41
|
|
|
42
|
+
function normalizeOptionTypes({ type = 'any', ...options }) {
|
|
43
|
+
let types = [].concat(type)
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...options,
|
|
47
|
+
types: types.map((type) => {
|
|
48
|
+
if (Array.isArray(type)) {
|
|
49
|
+
return { type: type[0], ...type[1] }
|
|
50
|
+
}
|
|
51
|
+
return { type, preferOnConflict: false }
|
|
52
|
+
}),
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
29
56
|
function parseVariantFormatString(input) {
|
|
30
57
|
if (input.includes('{')) {
|
|
31
58
|
if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`)
|
|
@@ -84,12 +111,18 @@ function parseStyles(styles) {
|
|
|
84
111
|
})
|
|
85
112
|
}
|
|
86
113
|
|
|
87
|
-
function getClasses(selector) {
|
|
114
|
+
function getClasses(selector, mutate) {
|
|
88
115
|
let parser = selectorParser((selectors) => {
|
|
89
116
|
let allClasses = []
|
|
117
|
+
|
|
118
|
+
if (mutate) {
|
|
119
|
+
mutate(selectors)
|
|
120
|
+
}
|
|
121
|
+
|
|
90
122
|
selectors.walkClasses((classNode) => {
|
|
91
123
|
allClasses.push(classNode.value)
|
|
92
124
|
})
|
|
125
|
+
|
|
93
126
|
return allClasses
|
|
94
127
|
})
|
|
95
128
|
return parser.transformSync(selector)
|
|
@@ -100,8 +133,20 @@ function extractCandidates(node, state = { containsNonOnDemandable: false }, dep
|
|
|
100
133
|
|
|
101
134
|
// Handle normal rules
|
|
102
135
|
if (node.type === 'rule') {
|
|
136
|
+
// Ignore everything inside a :not(...). This allows you to write code like
|
|
137
|
+
// `div:not(.foo)`. If `.foo` is never found in your code, then we used to
|
|
138
|
+
// not generated it. But now we will ignore everything inside a `:not`, so
|
|
139
|
+
// that it still gets generated.
|
|
140
|
+
function ignoreNot(selectors) {
|
|
141
|
+
selectors.walkPseudos((pseudo) => {
|
|
142
|
+
if (pseudo.value === ':not') {
|
|
143
|
+
pseudo.remove()
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
103
148
|
for (let selector of node.selectors) {
|
|
104
|
-
let classCandidates = getClasses(selector)
|
|
149
|
+
let classCandidates = getClasses(selector, ignoreNot)
|
|
105
150
|
// At least one of the selectors contains non-"on-demandable" candidates.
|
|
106
151
|
if (classCandidates.length === 0) {
|
|
107
152
|
state.containsNonOnDemandable = true
|
|
@@ -116,9 +161,7 @@ function extractCandidates(node, state = { containsNonOnDemandable: false }, dep
|
|
|
116
161
|
// Handle at-rules (which contains nested rules)
|
|
117
162
|
else if (node.type === 'atrule') {
|
|
118
163
|
node.walkRules((rule) => {
|
|
119
|
-
for (let classCandidate of rule.selectors.flatMap((selector) =>
|
|
120
|
-
getClasses(selector, state, depth + 1)
|
|
121
|
-
)) {
|
|
164
|
+
for (let classCandidate of rule.selectors.flatMap((selector) => getClasses(selector))) {
|
|
122
165
|
classes.push(classCandidate)
|
|
123
166
|
}
|
|
124
167
|
})
|
|
@@ -153,6 +196,41 @@ function withIdentifiers(styles) {
|
|
|
153
196
|
})
|
|
154
197
|
}
|
|
155
198
|
|
|
199
|
+
export function isValidVariantFormatString(format) {
|
|
200
|
+
return format.startsWith('@') || format.includes('&')
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function parseVariant(variant) {
|
|
204
|
+
variant = variant
|
|
205
|
+
.replace(/\n+/g, '')
|
|
206
|
+
.replace(/\s{1,}/g, ' ')
|
|
207
|
+
.trim()
|
|
208
|
+
|
|
209
|
+
let fns = parseVariantFormatString(variant)
|
|
210
|
+
.map((str) => {
|
|
211
|
+
if (!str.startsWith('@')) {
|
|
212
|
+
return ({ format }) => format(str)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str)
|
|
216
|
+
return ({ wrap }) => wrap(postcss.atRule({ name, params: params.trim() }))
|
|
217
|
+
})
|
|
218
|
+
.reverse()
|
|
219
|
+
|
|
220
|
+
return (api) => {
|
|
221
|
+
for (let fn of fns) {
|
|
222
|
+
fn(api)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
* @param {any} tailwindConfig
|
|
230
|
+
* @param {any} context
|
|
231
|
+
* @param {object} param2
|
|
232
|
+
* @param {Offsets} param2.offsets
|
|
233
|
+
*/
|
|
156
234
|
function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
|
|
157
235
|
function getConfigValue(path, defaultValue) {
|
|
158
236
|
return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
|
|
@@ -174,51 +252,19 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
174
252
|
return context.tailwindConfig.prefix + identifier
|
|
175
253
|
}
|
|
176
254
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return ({ modifySelectors, container, separator }) => {
|
|
183
|
-
return variantFunction({ modifySelectors, container, separator })
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
variantFunction = variantFunction
|
|
188
|
-
.replace(/\n+/g, '')
|
|
189
|
-
.replace(/\s{1,}/g, ' ')
|
|
190
|
-
.trim()
|
|
191
|
-
|
|
192
|
-
let fns = parseVariantFormatString(variantFunction)
|
|
193
|
-
.map((str) => {
|
|
194
|
-
if (!str.startsWith('@')) {
|
|
195
|
-
return ({ format }) => format(str)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
let [, name, params] = /@(.*?) (.*)/g.exec(str)
|
|
199
|
-
return ({ wrap }) => wrap(postcss.atRule({ name, params }))
|
|
200
|
-
})
|
|
201
|
-
.reverse()
|
|
202
|
-
|
|
203
|
-
return (api) => {
|
|
204
|
-
for (let fn of fns) {
|
|
205
|
-
fn(api)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
})
|
|
255
|
+
function resolveThemeValue(path, defaultValue, opts = {}) {
|
|
256
|
+
let parts = toPath(path)
|
|
257
|
+
let value = getConfigValue(['theme', ...parts], defaultValue)
|
|
258
|
+
return transformThemeValue(parts[0])(value, opts)
|
|
259
|
+
}
|
|
209
260
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
},
|
|
261
|
+
let variantIdentifier = 0
|
|
262
|
+
let api = {
|
|
213
263
|
postcss,
|
|
214
264
|
prefix: applyConfiguredPrefix,
|
|
215
265
|
e: escapeClassName,
|
|
216
266
|
config: getConfigValue,
|
|
217
|
-
theme
|
|
218
|
-
const [pathRoot, ...subPaths] = toPath(path)
|
|
219
|
-
const value = getConfigValue(['theme', pathRoot, ...subPaths], defaultValue)
|
|
220
|
-
return transformThemeValue(pathRoot)(value)
|
|
221
|
-
},
|
|
267
|
+
theme: resolveThemeValue,
|
|
222
268
|
corePlugins: (path) => {
|
|
223
269
|
if (Array.isArray(tailwindConfig.corePlugins)) {
|
|
224
270
|
return tailwindConfig.corePlugins.includes(path)
|
|
@@ -230,21 +276,10 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
230
276
|
// Preserved for backwards compatibility but not used in v3.0+
|
|
231
277
|
return []
|
|
232
278
|
},
|
|
233
|
-
addUserCss(userCss) {
|
|
234
|
-
for (let [identifier, rule] of withIdentifiers(userCss)) {
|
|
235
|
-
let offset = offsets.user++
|
|
236
|
-
|
|
237
|
-
if (!context.candidateRuleMap.has(identifier)) {
|
|
238
|
-
context.candidateRuleMap.set(identifier, [])
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
context.candidateRuleMap.get(identifier).push([{ sort: offset, layer: 'user' }, rule])
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
279
|
addBase(base) {
|
|
245
280
|
for (let [identifier, rule] of withIdentifiers(base)) {
|
|
246
281
|
let prefixedIdentifier = prefixIdentifier(identifier, {})
|
|
247
|
-
let offset = offsets.base
|
|
282
|
+
let offset = offsets.create('base')
|
|
248
283
|
|
|
249
284
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
250
285
|
context.candidateRuleMap.set(prefixedIdentifier, [])
|
|
@@ -273,11 +308,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
273
308
|
|
|
274
309
|
context.candidateRuleMap
|
|
275
310
|
.get(prefixedIdentifier)
|
|
276
|
-
.push([{ sort: offsets.
|
|
311
|
+
.push([{ sort: offsets.create('defaults'), layer: 'defaults' }, rule])
|
|
277
312
|
}
|
|
278
313
|
},
|
|
279
314
|
addComponents(components, options) {
|
|
280
315
|
let defaultOptions = {
|
|
316
|
+
preserveSource: false,
|
|
281
317
|
respectPrefix: true,
|
|
282
318
|
respectImportant: false,
|
|
283
319
|
}
|
|
@@ -295,11 +331,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
295
331
|
|
|
296
332
|
context.candidateRuleMap
|
|
297
333
|
.get(prefixedIdentifier)
|
|
298
|
-
.push([{ sort: offsets.components
|
|
334
|
+
.push([{ sort: offsets.create('components'), layer: 'components', options }, rule])
|
|
299
335
|
}
|
|
300
336
|
},
|
|
301
337
|
addUtilities(utilities, options) {
|
|
302
338
|
let defaultOptions = {
|
|
339
|
+
preserveSource: false,
|
|
303
340
|
respectPrefix: true,
|
|
304
341
|
respectImportant: true,
|
|
305
342
|
}
|
|
@@ -317,18 +354,19 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
317
354
|
|
|
318
355
|
context.candidateRuleMap
|
|
319
356
|
.get(prefixedIdentifier)
|
|
320
|
-
.push([{ sort: offsets.utilities
|
|
357
|
+
.push([{ sort: offsets.create('utilities'), layer: 'utilities', options }, rule])
|
|
321
358
|
}
|
|
322
359
|
},
|
|
323
360
|
matchUtilities: function (utilities, options) {
|
|
324
361
|
let defaultOptions = {
|
|
325
362
|
respectPrefix: true,
|
|
326
363
|
respectImportant: true,
|
|
364
|
+
modifiers: false,
|
|
327
365
|
}
|
|
328
366
|
|
|
329
|
-
options = { ...defaultOptions, ...options }
|
|
367
|
+
options = normalizeOptionTypes({ ...defaultOptions, ...options })
|
|
330
368
|
|
|
331
|
-
let offset = offsets.utilities
|
|
369
|
+
let offset = offsets.create('utilities')
|
|
332
370
|
|
|
333
371
|
for (let identifier in utilities) {
|
|
334
372
|
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
@@ -337,24 +375,51 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
337
375
|
classList.add([prefixedIdentifier, options])
|
|
338
376
|
|
|
339
377
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
340
|
-
let
|
|
341
|
-
|
|
342
|
-
|
|
378
|
+
let [value, coercedType, utilityModifier] = coerceValue(
|
|
379
|
+
options.types,
|
|
380
|
+
modifier,
|
|
381
|
+
options,
|
|
382
|
+
tailwindConfig
|
|
383
|
+
)
|
|
343
384
|
|
|
344
385
|
if (value === undefined) {
|
|
345
386
|
return []
|
|
346
387
|
}
|
|
347
388
|
|
|
348
|
-
if (!
|
|
349
|
-
|
|
389
|
+
if (!options.types.some(({ type }) => type === coercedType)) {
|
|
390
|
+
if (isOnlyPlugin) {
|
|
391
|
+
log.warn([
|
|
392
|
+
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
393
|
+
`You can safely update it to \`${identifier}-${modifier.replace(
|
|
394
|
+
coercedType + ':',
|
|
395
|
+
''
|
|
396
|
+
)}\`.`,
|
|
397
|
+
])
|
|
398
|
+
} else {
|
|
399
|
+
return []
|
|
400
|
+
}
|
|
350
401
|
}
|
|
351
402
|
|
|
352
|
-
if (!
|
|
403
|
+
if (!isSyntacticallyValidPropertyValue(value)) {
|
|
353
404
|
return []
|
|
354
405
|
}
|
|
355
406
|
|
|
407
|
+
let extras = {
|
|
408
|
+
get modifier() {
|
|
409
|
+
if (!options.modifiers) {
|
|
410
|
+
log.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
411
|
+
'Your plugin must set `modifiers: true` in its options to support modifiers.',
|
|
412
|
+
])
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return utilityModifier
|
|
416
|
+
},
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
420
|
+
|
|
356
421
|
let ruleSets = []
|
|
357
|
-
.concat(rule(value))
|
|
422
|
+
.concat(modifiersEnabled ? rule(value, extras) : rule(value))
|
|
358
423
|
.filter(Boolean)
|
|
359
424
|
.map((declaration) => ({
|
|
360
425
|
[nameClass(identifier, modifier)]: declaration,
|
|
@@ -376,11 +441,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
376
441
|
let defaultOptions = {
|
|
377
442
|
respectPrefix: true,
|
|
378
443
|
respectImportant: false,
|
|
444
|
+
modifiers: false,
|
|
379
445
|
}
|
|
380
446
|
|
|
381
|
-
options = { ...defaultOptions, ...options }
|
|
447
|
+
options = normalizeOptionTypes({ ...defaultOptions, ...options })
|
|
382
448
|
|
|
383
|
-
let offset = offsets.components
|
|
449
|
+
let offset = offsets.create('components')
|
|
384
450
|
|
|
385
451
|
for (let identifier in components) {
|
|
386
452
|
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
@@ -389,15 +455,18 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
389
455
|
classList.add([prefixedIdentifier, options])
|
|
390
456
|
|
|
391
457
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
392
|
-
let
|
|
393
|
-
|
|
394
|
-
|
|
458
|
+
let [value, coercedType, utilityModifier] = coerceValue(
|
|
459
|
+
options.types,
|
|
460
|
+
modifier,
|
|
461
|
+
options,
|
|
462
|
+
tailwindConfig
|
|
463
|
+
)
|
|
395
464
|
|
|
396
465
|
if (value === undefined) {
|
|
397
466
|
return []
|
|
398
467
|
}
|
|
399
468
|
|
|
400
|
-
if (!
|
|
469
|
+
if (!options.types.some(({ type }) => type === coercedType)) {
|
|
401
470
|
if (isOnlyPlugin) {
|
|
402
471
|
log.warn([
|
|
403
472
|
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
@@ -411,12 +480,26 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
411
480
|
}
|
|
412
481
|
}
|
|
413
482
|
|
|
414
|
-
if (!
|
|
483
|
+
if (!isSyntacticallyValidPropertyValue(value)) {
|
|
415
484
|
return []
|
|
416
485
|
}
|
|
417
486
|
|
|
487
|
+
let extras = {
|
|
488
|
+
get modifier() {
|
|
489
|
+
if (!options.modifiers) {
|
|
490
|
+
log.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
491
|
+
'Your plugin must set `modifiers: true` in its options to support modifiers.',
|
|
492
|
+
])
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return utilityModifier
|
|
496
|
+
},
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
500
|
+
|
|
418
501
|
let ruleSets = []
|
|
419
|
-
.concat(rule(value))
|
|
502
|
+
.concat(modifiersEnabled ? rule(value, extras) : rule(value))
|
|
420
503
|
.filter(Boolean)
|
|
421
504
|
.map((declaration) => ({
|
|
422
505
|
[nameClass(identifier, modifier)]: declaration,
|
|
@@ -434,7 +517,109 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
434
517
|
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
|
|
435
518
|
}
|
|
436
519
|
},
|
|
520
|
+
addVariant(variantName, variantFunctions, options = {}) {
|
|
521
|
+
variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
|
|
522
|
+
if (typeof variantFunction !== 'string') {
|
|
523
|
+
// Safelist public API functions
|
|
524
|
+
return (api = {}) => {
|
|
525
|
+
let { args, modifySelectors, container, separator, wrap, format } = api
|
|
526
|
+
let result = variantFunction(
|
|
527
|
+
Object.assign(
|
|
528
|
+
{ modifySelectors, container, separator },
|
|
529
|
+
options.type === VARIANT_TYPES.MatchVariant && { args, wrap, format }
|
|
530
|
+
)
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
if (typeof result === 'string' && !isValidVariantFormatString(result)) {
|
|
534
|
+
throw new Error(
|
|
535
|
+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
|
|
536
|
+
)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (Array.isArray(result)) {
|
|
540
|
+
return result
|
|
541
|
+
.filter((variant) => typeof variant === 'string')
|
|
542
|
+
.map((variant) => parseVariant(variant))
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// result may be undefined with legacy variants that use APIs like `modifySelectors`
|
|
546
|
+
// result may also be a postcss node if someone was returning the result from `modifySelectors`
|
|
547
|
+
return result && typeof result === 'string' && parseVariant(result)(api)
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (!isValidVariantFormatString(variantFunction)) {
|
|
552
|
+
throw new Error(
|
|
553
|
+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return parseVariant(variantFunction)
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
insertInto(variantList, variantName, options)
|
|
561
|
+
variantMap.set(variantName, variantFunctions)
|
|
562
|
+
context.variantOptions.set(variantName, options)
|
|
563
|
+
},
|
|
564
|
+
matchVariant(variant, variantFn, options) {
|
|
565
|
+
// A unique identifier that "groups" these variants together.
|
|
566
|
+
// This is for internal use only which is why it is not present in the types
|
|
567
|
+
let id = options?.id ?? ++variantIdentifier
|
|
568
|
+
let isSpecial = variant === '@'
|
|
569
|
+
|
|
570
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
571
|
+
|
|
572
|
+
for (let [key, value] of Object.entries(options?.values ?? {})) {
|
|
573
|
+
if (key === 'DEFAULT') continue
|
|
574
|
+
|
|
575
|
+
api.addVariant(
|
|
576
|
+
isSpecial ? `${variant}${key}` : `${variant}-${key}`,
|
|
577
|
+
({ args, container }) => {
|
|
578
|
+
return variantFn(
|
|
579
|
+
value,
|
|
580
|
+
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
|
|
581
|
+
)
|
|
582
|
+
},
|
|
583
|
+
|
|
584
|
+
{
|
|
585
|
+
...options,
|
|
586
|
+
value,
|
|
587
|
+
id,
|
|
588
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
589
|
+
variantInfo: VARIANT_INFO.Base,
|
|
590
|
+
}
|
|
591
|
+
)
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
let hasDefault = 'DEFAULT' in (options?.values ?? {})
|
|
595
|
+
|
|
596
|
+
api.addVariant(
|
|
597
|
+
variant,
|
|
598
|
+
({ args, container }) => {
|
|
599
|
+
if (args?.value === sharedState.NONE && !hasDefault) {
|
|
600
|
+
return null
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return variantFn(
|
|
604
|
+
args?.value === sharedState.NONE
|
|
605
|
+
? options.values.DEFAULT
|
|
606
|
+
: // Falling back to args if it is a string, otherwise '' for older intellisense
|
|
607
|
+
// (JetBrains) plugins.
|
|
608
|
+
args?.value ?? (typeof args === 'string' ? args : ''),
|
|
609
|
+
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
|
|
610
|
+
)
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
...options,
|
|
614
|
+
id,
|
|
615
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
616
|
+
variantInfo: VARIANT_INFO.Dynamic,
|
|
617
|
+
}
|
|
618
|
+
)
|
|
619
|
+
},
|
|
437
620
|
}
|
|
621
|
+
|
|
622
|
+
return api
|
|
438
623
|
}
|
|
439
624
|
|
|
440
625
|
let fileModifiedMapCache = new WeakMap()
|
|
@@ -507,29 +692,20 @@ function collectLayerPlugins(root) {
|
|
|
507
692
|
} else if (layerRule.params === 'components') {
|
|
508
693
|
for (let node of layerRule.nodes) {
|
|
509
694
|
layerPlugins.push(function ({ addComponents }) {
|
|
510
|
-
addComponents(node, { respectPrefix: false })
|
|
695
|
+
addComponents(node, { respectPrefix: false, preserveSource: true })
|
|
511
696
|
})
|
|
512
697
|
}
|
|
513
698
|
layerRule.remove()
|
|
514
699
|
} else if (layerRule.params === 'utilities') {
|
|
515
700
|
for (let node of layerRule.nodes) {
|
|
516
701
|
layerPlugins.push(function ({ addUtilities }) {
|
|
517
|
-
addUtilities(node, { respectPrefix: false })
|
|
702
|
+
addUtilities(node, { respectPrefix: false, preserveSource: true })
|
|
518
703
|
})
|
|
519
704
|
}
|
|
520
705
|
layerRule.remove()
|
|
521
706
|
}
|
|
522
707
|
})
|
|
523
708
|
|
|
524
|
-
root.walkRules((rule) => {
|
|
525
|
-
// At this point it is safe to include all the left-over css from the
|
|
526
|
-
// user's css file. This is because the `@tailwind` and `@layer` directives
|
|
527
|
-
// will already be handled and will be removed from the css tree.
|
|
528
|
-
layerPlugins.push(function ({ addUserCss }) {
|
|
529
|
-
addUserCss(rule, { respectPrefix: false })
|
|
530
|
-
})
|
|
531
|
-
})
|
|
532
|
-
|
|
533
709
|
return layerPlugins
|
|
534
710
|
}
|
|
535
711
|
|
|
@@ -559,10 +735,14 @@ function resolvePlugins(context, root) {
|
|
|
559
735
|
let beforeVariants = [
|
|
560
736
|
variantPlugins['pseudoElementVariants'],
|
|
561
737
|
variantPlugins['pseudoClassVariants'],
|
|
738
|
+
variantPlugins['ariaVariants'],
|
|
739
|
+
variantPlugins['dataVariants'],
|
|
562
740
|
]
|
|
563
741
|
let afterVariants = [
|
|
742
|
+
variantPlugins['supportsVariants'],
|
|
564
743
|
variantPlugins['directionVariants'],
|
|
565
744
|
variantPlugins['reducedMotionVariants'],
|
|
745
|
+
variantPlugins['prefersContrastVariants'],
|
|
566
746
|
variantPlugins['darkVariants'],
|
|
567
747
|
variantPlugins['printVariant'],
|
|
568
748
|
variantPlugins['screenVariants'],
|
|
@@ -575,13 +755,10 @@ function resolvePlugins(context, root) {
|
|
|
575
755
|
function registerPlugins(plugins, context) {
|
|
576
756
|
let variantList = []
|
|
577
757
|
let variantMap = new Map()
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
utilities: 0n,
|
|
583
|
-
user: 0n,
|
|
584
|
-
}
|
|
758
|
+
context.variantMap = variantMap
|
|
759
|
+
|
|
760
|
+
let offsets = new Offsets()
|
|
761
|
+
context.offsets = offsets
|
|
585
762
|
|
|
586
763
|
let classList = new Set()
|
|
587
764
|
|
|
@@ -602,49 +779,17 @@ function registerPlugins(plugins, context) {
|
|
|
602
779
|
}
|
|
603
780
|
}
|
|
604
781
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
offsets.defaults,
|
|
608
|
-
offsets.components,
|
|
609
|
-
offsets.utilities,
|
|
610
|
-
offsets.user,
|
|
611
|
-
])
|
|
612
|
-
let reservedBits = BigInt(highestOffset.toString(2).length)
|
|
613
|
-
|
|
614
|
-
// A number one less than the top range of the highest offset area
|
|
615
|
-
// so arbitrary properties are always sorted at the end.
|
|
616
|
-
context.arbitraryPropertiesSort = ((1n << reservedBits) << 0n) - 1n
|
|
617
|
-
|
|
618
|
-
context.layerOrder = {
|
|
619
|
-
defaults: (1n << reservedBits) << 0n,
|
|
620
|
-
base: (1n << reservedBits) << 1n,
|
|
621
|
-
components: (1n << reservedBits) << 2n,
|
|
622
|
-
utilities: (1n << reservedBits) << 3n,
|
|
623
|
-
user: (1n << reservedBits) << 4n,
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
reservedBits += 5n
|
|
627
|
-
|
|
628
|
-
let offset = 0
|
|
629
|
-
context.variantOrder = new Map(
|
|
630
|
-
variantList
|
|
631
|
-
.map((variant, i) => {
|
|
632
|
-
let variantFunctions = variantMap.get(variant).length
|
|
633
|
-
let bits = (1n << BigInt(i + offset)) << reservedBits
|
|
634
|
-
offset += variantFunctions - 1
|
|
635
|
-
return [variant, bits]
|
|
636
|
-
})
|
|
637
|
-
.sort(([, a], [, z]) => bigSign(a - z))
|
|
638
|
-
)
|
|
639
|
-
|
|
640
|
-
context.minimumScreen = [...context.variantOrder.values()].shift()
|
|
782
|
+
// Make sure to record bit masks for every variant
|
|
783
|
+
offsets.recordVariants(variantList, (variant) => variantMap.get(variant).length)
|
|
641
784
|
|
|
642
785
|
// Build variantMap
|
|
643
786
|
for (let [variantName, variantFunctions] of variantMap.entries()) {
|
|
644
|
-
let sort = context.variantOrder.get(variantName)
|
|
645
787
|
context.variantMap.set(
|
|
646
788
|
variantName,
|
|
647
|
-
variantFunctions.map((variantFunction, idx) => [
|
|
789
|
+
variantFunctions.map((variantFunction, idx) => [
|
|
790
|
+
offsets.forVariant(variantName, idx),
|
|
791
|
+
variantFunction,
|
|
792
|
+
])
|
|
648
793
|
)
|
|
649
794
|
}
|
|
650
795
|
|
|
@@ -673,6 +818,7 @@ function registerPlugins(plugins, context) {
|
|
|
673
818
|
if (checks.length > 0) {
|
|
674
819
|
let patternMatchingCount = new Map()
|
|
675
820
|
let prefixLength = context.tailwindConfig.prefix.length
|
|
821
|
+
let checkImportantUtils = checks.some((check) => check.pattern.source.includes('!'))
|
|
676
822
|
|
|
677
823
|
for (let util of classList) {
|
|
678
824
|
let utils = Array.isArray(util)
|
|
@@ -698,6 +844,21 @@ function registerPlugins(plugins, context) {
|
|
|
698
844
|
]
|
|
699
845
|
}
|
|
700
846
|
|
|
847
|
+
if (options.types.some(({ type }) => type === 'color')) {
|
|
848
|
+
classes = [
|
|
849
|
+
...classes,
|
|
850
|
+
...classes.flatMap((cls) =>
|
|
851
|
+
Object.keys(context.tailwindConfig.theme.opacity).map(
|
|
852
|
+
(opacity) => `${cls}/${opacity}`
|
|
853
|
+
)
|
|
854
|
+
),
|
|
855
|
+
]
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
if (checkImportantUtils && options?.respectImportant) {
|
|
859
|
+
classes = [...classes, ...classes.map((cls) => '!' + cls)]
|
|
860
|
+
}
|
|
861
|
+
|
|
701
862
|
return classes
|
|
702
863
|
})()
|
|
703
864
|
: [util]
|
|
@@ -739,26 +900,41 @@ function registerPlugins(plugins, context) {
|
|
|
739
900
|
}
|
|
740
901
|
}
|
|
741
902
|
|
|
903
|
+
let darkClassName = [].concat(context.tailwindConfig.darkMode ?? 'media')[1] ?? 'dark'
|
|
904
|
+
|
|
742
905
|
// A list of utilities that are used by certain Tailwind CSS utilities but
|
|
743
906
|
// that don't exist on their own. This will result in them "not existing" and
|
|
744
907
|
// sorting could be weird since you still require them in order to make the
|
|
745
|
-
// host
|
|
746
|
-
let parasiteUtilities =
|
|
908
|
+
// host utilities work properly. (Thanks Biology)
|
|
909
|
+
let parasiteUtilities = [
|
|
910
|
+
prefix(context, darkClassName),
|
|
911
|
+
prefix(context, 'group'),
|
|
912
|
+
prefix(context, 'peer'),
|
|
913
|
+
]
|
|
747
914
|
context.getClassOrder = function getClassOrder(classes) {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
915
|
+
// Non-util classes won't be generated, so we default them to null
|
|
916
|
+
let sortedClassNames = new Map(classes.map((className) => [className, null]))
|
|
917
|
+
|
|
918
|
+
// Sort all classes in order
|
|
919
|
+
// Non-tailwind classes won't be generated and will be left as `null`
|
|
920
|
+
let rules = generateRules(new Set(classes), context)
|
|
921
|
+
rules = context.offsets.sort(rules)
|
|
922
|
+
|
|
923
|
+
let idx = BigInt(parasiteUtilities.length)
|
|
924
|
+
|
|
925
|
+
for (const [, rule] of rules) {
|
|
926
|
+
sortedClassNames.set(rule.raws.tailwind.candidate, idx++)
|
|
752
927
|
}
|
|
753
928
|
|
|
754
929
|
return classes.map((className) => {
|
|
755
930
|
let order = sortedClassNames.get(className) ?? null
|
|
931
|
+
let parasiteIndex = parasiteUtilities.indexOf(className)
|
|
756
932
|
|
|
757
|
-
if (order === null &&
|
|
933
|
+
if (order === null && parasiteIndex !== -1) {
|
|
758
934
|
// This will make sure that it is at the very beginning of the
|
|
759
935
|
// `components` layer which technically means 'before any
|
|
760
936
|
// components'.
|
|
761
|
-
order =
|
|
937
|
+
order = BigInt(parasiteIndex)
|
|
762
938
|
}
|
|
763
939
|
|
|
764
940
|
return [className, order]
|
|
@@ -776,6 +952,11 @@ function registerPlugins(plugins, context) {
|
|
|
776
952
|
let negativeClasses = []
|
|
777
953
|
|
|
778
954
|
for (let [key, value] of Object.entries(options?.values ?? {})) {
|
|
955
|
+
// Ignore undefined and null values
|
|
956
|
+
if (value == null) {
|
|
957
|
+
continue
|
|
958
|
+
}
|
|
959
|
+
|
|
779
960
|
output.push(formatClass(utilName, key))
|
|
780
961
|
if (options?.supportsNegativeValues && negateValue(value)) {
|
|
781
962
|
negativeClasses.push(formatClass(utilName, `-${key}`))
|
|
@@ -790,21 +971,205 @@ function registerPlugins(plugins, context) {
|
|
|
790
971
|
|
|
791
972
|
return output
|
|
792
973
|
}
|
|
974
|
+
|
|
975
|
+
// Generate a list of available variants with meta information of the type of variant.
|
|
976
|
+
context.getVariants = function getVariants() {
|
|
977
|
+
let result = []
|
|
978
|
+
for (let [name, options] of context.variantOptions.entries()) {
|
|
979
|
+
if (options.variantInfo === VARIANT_INFO.Base) continue
|
|
980
|
+
|
|
981
|
+
result.push({
|
|
982
|
+
name,
|
|
983
|
+
isArbitrary: options.type === Symbol.for('MATCH_VARIANT'),
|
|
984
|
+
values: Object.keys(options.values ?? {}),
|
|
985
|
+
hasDash: name !== '@',
|
|
986
|
+
selectors({ modifier, value } = {}) {
|
|
987
|
+
let candidate = '__TAILWIND_PLACEHOLDER__'
|
|
988
|
+
|
|
989
|
+
let rule = postcss.rule({ selector: `.${candidate}` })
|
|
990
|
+
let container = postcss.root({ nodes: [rule.clone()] })
|
|
991
|
+
|
|
992
|
+
let before = container.toString()
|
|
993
|
+
|
|
994
|
+
let fns = (context.variantMap.get(name) ?? []).flatMap(([_, fn]) => fn)
|
|
995
|
+
let formatStrings = []
|
|
996
|
+
for (let fn of fns) {
|
|
997
|
+
let localFormatStrings = []
|
|
998
|
+
|
|
999
|
+
let api = {
|
|
1000
|
+
args: { modifier, value: options.values?.[value] ?? value },
|
|
1001
|
+
separator: context.tailwindConfig.separator,
|
|
1002
|
+
modifySelectors(modifierFunction) {
|
|
1003
|
+
// Run the modifierFunction over each rule
|
|
1004
|
+
container.each((rule) => {
|
|
1005
|
+
if (rule.type !== 'rule') {
|
|
1006
|
+
return
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
rule.selectors = rule.selectors.map((selector) => {
|
|
1010
|
+
return modifierFunction({
|
|
1011
|
+
get className() {
|
|
1012
|
+
return getClassNameFromSelector(selector)
|
|
1013
|
+
},
|
|
1014
|
+
selector,
|
|
1015
|
+
})
|
|
1016
|
+
})
|
|
1017
|
+
})
|
|
1018
|
+
|
|
1019
|
+
return container
|
|
1020
|
+
},
|
|
1021
|
+
format(str) {
|
|
1022
|
+
localFormatStrings.push(str)
|
|
1023
|
+
},
|
|
1024
|
+
wrap(wrapper) {
|
|
1025
|
+
localFormatStrings.push(`@${wrapper.name} ${wrapper.params} { & }`)
|
|
1026
|
+
},
|
|
1027
|
+
container,
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
let ruleWithVariant = fn(api)
|
|
1031
|
+
if (localFormatStrings.length > 0) {
|
|
1032
|
+
formatStrings.push(localFormatStrings)
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
1036
|
+
for (let variantFunction of ruleWithVariant) {
|
|
1037
|
+
localFormatStrings = []
|
|
1038
|
+
variantFunction(api)
|
|
1039
|
+
formatStrings.push(localFormatStrings)
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// Reverse engineer the result of the `container`
|
|
1045
|
+
let manualFormatStrings = []
|
|
1046
|
+
let after = container.toString()
|
|
1047
|
+
|
|
1048
|
+
if (before !== after) {
|
|
1049
|
+
// Figure out all selectors
|
|
1050
|
+
container.walkRules((rule) => {
|
|
1051
|
+
let modified = rule.selector
|
|
1052
|
+
|
|
1053
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
1054
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
1055
|
+
// However, plugin authors probably also prepend or append certain
|
|
1056
|
+
// classes, pseudos, ids, ...
|
|
1057
|
+
let rebuiltBase = selectorParser((selectors) => {
|
|
1058
|
+
selectors.walkClasses((classNode) => {
|
|
1059
|
+
classNode.value = `${name}${context.tailwindConfig.separator}${classNode.value}`
|
|
1060
|
+
})
|
|
1061
|
+
}).processSync(modified)
|
|
1062
|
+
|
|
1063
|
+
// Now that we know the original selector, the new selector, and
|
|
1064
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
1065
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
1066
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
1067
|
+
//
|
|
1068
|
+
// E.g.:
|
|
1069
|
+
// variant: foo
|
|
1070
|
+
// selector: .markdown > p
|
|
1071
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
1072
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
1073
|
+
// format: .foo &
|
|
1074
|
+
manualFormatStrings.push(modified.replace(rebuiltBase, '&').replace(candidate, '&'))
|
|
1075
|
+
})
|
|
1076
|
+
|
|
1077
|
+
// Figure out all atrules
|
|
1078
|
+
container.walkAtRules((atrule) => {
|
|
1079
|
+
manualFormatStrings.push(`@${atrule.name} (${atrule.params}) { & }`)
|
|
1080
|
+
})
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
let result = formatStrings.map((formatString) =>
|
|
1084
|
+
finalizeSelector(formatVariantSelector('&', ...formatString), {
|
|
1085
|
+
selector: `.${candidate}`,
|
|
1086
|
+
candidate,
|
|
1087
|
+
context,
|
|
1088
|
+
isArbitraryVariant: !(value in (options.values ?? {})),
|
|
1089
|
+
})
|
|
1090
|
+
.replace(`.${candidate}`, '&')
|
|
1091
|
+
.replace('{ & }', '')
|
|
1092
|
+
.trim()
|
|
1093
|
+
)
|
|
1094
|
+
|
|
1095
|
+
if (manualFormatStrings.length > 0) {
|
|
1096
|
+
result.push(formatVariantSelector('&', ...manualFormatStrings))
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
return result
|
|
1100
|
+
},
|
|
1101
|
+
})
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
return result
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* Mark as class as retroactively invalid
|
|
1110
|
+
*
|
|
1111
|
+
*
|
|
1112
|
+
* @param {string} candidate
|
|
1113
|
+
*/
|
|
1114
|
+
function markInvalidUtilityCandidate(context, candidate) {
|
|
1115
|
+
if (!context.classCache.has(candidate)) {
|
|
1116
|
+
return
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// Mark this as not being a real utility
|
|
1120
|
+
context.notClassCache.add(candidate)
|
|
1121
|
+
|
|
1122
|
+
// Remove it from any candidate-specific caches
|
|
1123
|
+
context.classCache.delete(candidate)
|
|
1124
|
+
context.applyClassCache.delete(candidate)
|
|
1125
|
+
context.candidateRuleMap.delete(candidate)
|
|
1126
|
+
context.candidateRuleCache.delete(candidate)
|
|
1127
|
+
|
|
1128
|
+
// Ensure the stylesheet gets rebuilt
|
|
1129
|
+
context.stylesheetCache = null
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Mark as class as retroactively invalid
|
|
1134
|
+
*
|
|
1135
|
+
* @param {import('postcss').Node} node
|
|
1136
|
+
*/
|
|
1137
|
+
function markInvalidUtilityNode(context, node) {
|
|
1138
|
+
let candidate = node.raws.tailwind.candidate
|
|
1139
|
+
|
|
1140
|
+
if (!candidate) {
|
|
1141
|
+
return
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
for (const entry of context.ruleCache) {
|
|
1145
|
+
if (entry[1].raws.tailwind.candidate === candidate) {
|
|
1146
|
+
context.ruleCache.delete(entry)
|
|
1147
|
+
// context.postCssNodeCache.delete(node)
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
markInvalidUtilityCandidate(context, candidate)
|
|
793
1152
|
}
|
|
794
1153
|
|
|
795
1154
|
export function createContext(tailwindConfig, changedContent = [], root = postcss.root()) {
|
|
796
1155
|
let context = {
|
|
797
1156
|
disposables: [],
|
|
798
1157
|
ruleCache: new Set(),
|
|
1158
|
+
candidateRuleCache: new Map(),
|
|
799
1159
|
classCache: new Map(),
|
|
800
1160
|
applyClassCache: new Map(),
|
|
801
|
-
|
|
1161
|
+
// Seed the not class cache with the blocklist (which is only strings)
|
|
1162
|
+
notClassCache: new Set(tailwindConfig.blocklist ?? []),
|
|
802
1163
|
postCssNodeCache: new Map(),
|
|
803
1164
|
candidateRuleMap: new Map(),
|
|
804
1165
|
tailwindConfig,
|
|
805
1166
|
changedContent: changedContent,
|
|
806
1167
|
variantMap: new Map(),
|
|
807
1168
|
stylesheetCache: null,
|
|
1169
|
+
variantOptions: new Map(),
|
|
1170
|
+
|
|
1171
|
+
markInvalidUtilityCandidate: (candidate) => markInvalidUtilityCandidate(context, candidate),
|
|
1172
|
+
markInvalidUtilityNode: (node) => markInvalidUtilityNode(context, node),
|
|
808
1173
|
}
|
|
809
1174
|
|
|
810
1175
|
let resolvedPlugins = resolvePlugins(context, root)
|
|
@@ -842,6 +1207,8 @@ export function getContext(
|
|
|
842
1207
|
existingContext = context
|
|
843
1208
|
}
|
|
844
1209
|
|
|
1210
|
+
let cssDidChange = hasContentChanged(sourcePath, root)
|
|
1211
|
+
|
|
845
1212
|
// If there's already a context in the cache and we don't need to
|
|
846
1213
|
// reset the context, return the cached context.
|
|
847
1214
|
if (existingContext) {
|
|
@@ -849,7 +1216,7 @@ export function getContext(
|
|
|
849
1216
|
[...contextDependencies],
|
|
850
1217
|
getFileModifiedMap(existingContext)
|
|
851
1218
|
)
|
|
852
|
-
if (!contextDependenciesChanged) {
|
|
1219
|
+
if (!contextDependenciesChanged && !cssDidChange) {
|
|
853
1220
|
return [existingContext, false]
|
|
854
1221
|
}
|
|
855
1222
|
}
|
|
@@ -881,6 +1248,10 @@ export function getContext(
|
|
|
881
1248
|
|
|
882
1249
|
let context = createContext(tailwindConfig, [], root)
|
|
883
1250
|
|
|
1251
|
+
Object.assign(context, {
|
|
1252
|
+
userConfigPath,
|
|
1253
|
+
})
|
|
1254
|
+
|
|
884
1255
|
trackModified([...contextDependencies], getFileModifiedMap(context))
|
|
885
1256
|
|
|
886
1257
|
// ---
|