tailwindcss 0.0.0-insiders.ea80db2 → 0.0.0-insiders.ea90d3a
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 -10
- package/defaultTheme.d.ts +2 -1
- package/lib/cli/build/deps.js +62 -0
- package/lib/cli/build/index.js +54 -0
- package/lib/cli/build/plugin.js +371 -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 +230 -0
- package/lib/cli/init/index.js +63 -0
- package/lib/cli-peer-dependencies.js +28 -7
- package/lib/cli.js +1 -759
- package/lib/corePluginList.js +16 -4
- package/lib/corePlugins.js +2421 -1738
- package/lib/css/preflight.css +31 -12
- package/lib/featureFlags.js +45 -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 +214 -0
- package/lib/lib/defaultExtractor.js +240 -33
- package/lib/lib/detectNesting.js +21 -10
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +322 -215
- package/lib/lib/expandTailwindAtRules.js +132 -115
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +466 -208
- package/lib/lib/getModuleDependencies.js +88 -37
- package/lib/lib/load-config.js +57 -0
- package/lib/lib/normalizeTailwindDirectives.js +38 -33
- package/lib/lib/offsets.js +355 -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 +98 -74
- package/lib/lib/setupContextUtils.js +744 -319
- 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 +48 -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 +35 -30
- 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 +39 -10
- package/lib/util/color.js +67 -51
- 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 +295 -113
- 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 +235 -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 +8 -3
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
- package/lib/util/log.js +23 -13
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +124 -82
- 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 +169 -59
- package/lib/util/prefixSelector.js +29 -10
- package/lib/util/pseudoElements.js +212 -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 +37 -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.d.ts +4 -0
- package/package.json +50 -43
- package/peers/index.js +72234 -50887
- package/plugin.d.ts +10 -5
- package/resolveConfig.d.ts +31 -0
- package/scripts/generate-types.js +52 -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 +437 -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 +216 -0
- package/src/cli/init/index.js +79 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +1 -836
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +665 -107
- package/src/css/preflight.css +31 -12
- package/src/featureFlags.js +10 -2
- package/src/index.js +1 -42
- package/src/lib/collapseAdjacentRules.js +5 -1
- package/src/lib/content.js +249 -0
- package/src/lib/defaultExtractor.js +215 -35
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +82 -8
- package/src/lib/expandApplyAtRules.js +329 -189
- package/src/lib/expandTailwindAtRules.js +46 -56
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +439 -130
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/load-config.ts +44 -0
- package/src/lib/offsets.js +432 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +57 -36
- package/src/lib/setupContextUtils.js +654 -182
- package/src/lib/setupTrackingContext.js +44 -58
- package/src/lib/sharedState.js +13 -4
- package/src/plugin.js +47 -0
- package/src/postcss-plugins/nesting/README.md +2 -2
- package/src/processTailwindFeatures.js +3 -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 +35 -10
- package/src/util/color.js +35 -18
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +183 -25
- package/src/util/formatVariantSelector.js +272 -144
- package/src/util/getAllConfigs.js +21 -2
- package/src/util/isPlainObject.js +1 -1
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +1 -1
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +41 -10
- 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 +139 -24
- package/src/util/prefixSelector.js +29 -10
- package/src/util/pseudoElements.js +171 -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 +26 -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} +287 -178
- package/stubs/postcss.config.js +6 -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 +113 -60
- package/types/generated/colors.d.ts +22 -0
- package/types/generated/corePluginList.d.ts +1 -1
- package/types/generated/default-theme.d.ts +397 -0
- package/types/index.d.ts +11 -1
- package/CHANGELOG.md +0 -2099
- package/lib/constants.js +0 -37
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/constants.js +0 -17
- package/types.d.ts +0 -1
- /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
- /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
|
@@ -11,49 +11,95 @@ 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'
|
|
23
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
|
+
export const INTERNAL_FEATURES = Symbol()
|
|
28
|
+
|
|
29
|
+
const VARIANT_TYPES = {
|
|
30
|
+
AddVariant: Symbol.for('ADD_VARIANT'),
|
|
31
|
+
MatchVariant: Symbol.for('MATCH_VARIANT'),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const VARIANT_INFO = {
|
|
35
|
+
Base: 1 << 0,
|
|
36
|
+
Dynamic: 1 << 1,
|
|
37
|
+
}
|
|
24
38
|
|
|
25
39
|
function prefix(context, selector) {
|
|
26
40
|
let prefix = context.tailwindConfig.prefix
|
|
27
41
|
return typeof prefix === 'function' ? prefix(selector) : prefix + selector
|
|
28
42
|
}
|
|
29
43
|
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`)
|
|
44
|
+
function normalizeOptionTypes({ type = 'any', ...options }) {
|
|
45
|
+
let types = [].concat(type)
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
47
|
+
return {
|
|
48
|
+
...options,
|
|
49
|
+
types: types.map((type) => {
|
|
50
|
+
if (Array.isArray(type)) {
|
|
51
|
+
return { type: type[0], ...type[1] }
|
|
52
|
+
}
|
|
53
|
+
return { type, preferOnConflict: false }
|
|
54
|
+
}),
|
|
38
55
|
}
|
|
39
|
-
|
|
40
|
-
return [input.trim()]
|
|
41
56
|
}
|
|
42
57
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
function parseVariantFormatString(input) {
|
|
59
|
+
/** @type {string[]} */
|
|
60
|
+
let parts = []
|
|
61
|
+
|
|
62
|
+
// When parsing whitespace around special characters are insignificant
|
|
63
|
+
// However, _inside_ of a variant they could be
|
|
64
|
+
// Because the selector could look like this
|
|
65
|
+
// @media { &[data-name="foo bar"] }
|
|
66
|
+
// This is why we do not skip whitespace
|
|
67
|
+
|
|
68
|
+
let current = ''
|
|
69
|
+
let depth = 0
|
|
70
|
+
|
|
71
|
+
for (let idx = 0; idx < input.length; idx++) {
|
|
72
|
+
let char = input[idx]
|
|
73
|
+
|
|
74
|
+
if (char === '\\') {
|
|
75
|
+
// Escaped characters are not special
|
|
76
|
+
current += '\\' + input[++idx]
|
|
77
|
+
} else if (char === '{') {
|
|
78
|
+
// Nested rule: start
|
|
79
|
+
++depth
|
|
80
|
+
parts.push(current.trim())
|
|
81
|
+
current = ''
|
|
49
82
|
} else if (char === '}') {
|
|
50
|
-
|
|
51
|
-
|
|
83
|
+
// Nested rule: end
|
|
84
|
+
if (--depth < 0) {
|
|
85
|
+
throw new Error(`Your { and } are unbalanced.`)
|
|
52
86
|
}
|
|
87
|
+
|
|
88
|
+
parts.push(current.trim())
|
|
89
|
+
current = ''
|
|
90
|
+
} else {
|
|
91
|
+
// Normal character
|
|
92
|
+
current += char
|
|
53
93
|
}
|
|
54
94
|
}
|
|
55
95
|
|
|
56
|
-
|
|
96
|
+
if (current.length > 0) {
|
|
97
|
+
parts.push(current.trim())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
parts = parts.filter((part) => part !== '')
|
|
101
|
+
|
|
102
|
+
return parts
|
|
57
103
|
}
|
|
58
104
|
|
|
59
105
|
function insertInto(list, value, { before = [] } = {}) {
|
|
@@ -102,43 +148,45 @@ function getClasses(selector, mutate) {
|
|
|
102
148
|
return parser.transformSync(selector)
|
|
103
149
|
}
|
|
104
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Ignore everything inside a :not(...). This allows you to write code like
|
|
153
|
+
* `div:not(.foo)`. If `.foo` is never found in your code, then we used to
|
|
154
|
+
* not generated it. But now we will ignore everything inside a `:not`, so
|
|
155
|
+
* that it still gets generated.
|
|
156
|
+
*
|
|
157
|
+
* @param {selectorParser.Root} selectors
|
|
158
|
+
*/
|
|
159
|
+
function ignoreNot(selectors) {
|
|
160
|
+
selectors.walkPseudos((pseudo) => {
|
|
161
|
+
if (pseudo.value === ':not') {
|
|
162
|
+
pseudo.remove()
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
105
167
|
function extractCandidates(node, state = { containsNonOnDemandable: false }, depth = 0) {
|
|
106
168
|
let classes = []
|
|
169
|
+
let selectors = []
|
|
107
170
|
|
|
108
|
-
// Handle normal rules
|
|
109
171
|
if (node.type === 'rule') {
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (pseudo.value === ':not') {
|
|
117
|
-
pseudo.remove()
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
}
|
|
172
|
+
// Handle normal rules
|
|
173
|
+
selectors.push(...node.selectors)
|
|
174
|
+
} else if (node.type === 'atrule') {
|
|
175
|
+
// Handle at-rules (which contains nested rules)
|
|
176
|
+
node.walkRules((rule) => selectors.push(...rule.selectors))
|
|
177
|
+
}
|
|
121
178
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// At least one of the selectors contains non-"on-demandable" candidates.
|
|
125
|
-
if (classCandidates.length === 0) {
|
|
126
|
-
state.containsNonOnDemandable = true
|
|
127
|
-
}
|
|
179
|
+
for (let selector of selectors) {
|
|
180
|
+
let classCandidates = getClasses(selector, ignoreNot)
|
|
128
181
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
182
|
+
// At least one of the selectors contains non-"on-demandable" candidates.
|
|
183
|
+
if (classCandidates.length === 0) {
|
|
184
|
+
state.containsNonOnDemandable = true
|
|
132
185
|
}
|
|
133
|
-
}
|
|
134
186
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
for (let classCandidate of rule.selectors.flatMap((selector) => getClasses(selector))) {
|
|
139
|
-
classes.push(classCandidate)
|
|
140
|
-
}
|
|
141
|
-
})
|
|
187
|
+
for (let classCandidate of classCandidates) {
|
|
188
|
+
classes.push(classCandidate)
|
|
189
|
+
}
|
|
142
190
|
}
|
|
143
191
|
|
|
144
192
|
if (depth === 0) {
|
|
@@ -170,6 +218,41 @@ function withIdentifiers(styles) {
|
|
|
170
218
|
})
|
|
171
219
|
}
|
|
172
220
|
|
|
221
|
+
export function isValidVariantFormatString(format) {
|
|
222
|
+
return format.startsWith('@') || format.includes('&')
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function parseVariant(variant) {
|
|
226
|
+
variant = variant
|
|
227
|
+
.replace(/\n+/g, '')
|
|
228
|
+
.replace(/\s{1,}/g, ' ')
|
|
229
|
+
.trim()
|
|
230
|
+
|
|
231
|
+
let fns = parseVariantFormatString(variant)
|
|
232
|
+
.map((str) => {
|
|
233
|
+
if (!str.startsWith('@')) {
|
|
234
|
+
return ({ format }) => format(str)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let [, name, params] = /@(\S*)( .+|[({].*)?/g.exec(str)
|
|
238
|
+
return ({ wrap }) => wrap(postcss.atRule({ name, params: params?.trim() ?? '' }))
|
|
239
|
+
})
|
|
240
|
+
.reverse()
|
|
241
|
+
|
|
242
|
+
return (api) => {
|
|
243
|
+
for (let fn of fns) {
|
|
244
|
+
fn(api)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
*
|
|
251
|
+
* @param {any} tailwindConfig
|
|
252
|
+
* @param {any} context
|
|
253
|
+
* @param {object} param2
|
|
254
|
+
* @param {Offsets} param2.offsets
|
|
255
|
+
*/
|
|
173
256
|
function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
|
|
174
257
|
function getConfigValue(path, defaultValue) {
|
|
175
258
|
return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
|
|
@@ -191,51 +274,19 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
191
274
|
return context.tailwindConfig.prefix + identifier
|
|
192
275
|
}
|
|
193
276
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return ({ modifySelectors, container, separator }) => {
|
|
200
|
-
return variantFunction({ modifySelectors, container, separator })
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
variantFunction = variantFunction
|
|
205
|
-
.replace(/\n+/g, '')
|
|
206
|
-
.replace(/\s{1,}/g, ' ')
|
|
207
|
-
.trim()
|
|
208
|
-
|
|
209
|
-
let fns = parseVariantFormatString(variantFunction)
|
|
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 }))
|
|
217
|
-
})
|
|
218
|
-
.reverse()
|
|
219
|
-
|
|
220
|
-
return (api) => {
|
|
221
|
-
for (let fn of fns) {
|
|
222
|
-
fn(api)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
})
|
|
277
|
+
function resolveThemeValue(path, defaultValue, opts = {}) {
|
|
278
|
+
let parts = toPath(path)
|
|
279
|
+
let value = getConfigValue(['theme', ...parts], defaultValue)
|
|
280
|
+
return transformThemeValue(parts[0])(value, opts)
|
|
281
|
+
}
|
|
226
282
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
},
|
|
283
|
+
let variantIdentifier = 0
|
|
284
|
+
let api = {
|
|
230
285
|
postcss,
|
|
231
286
|
prefix: applyConfiguredPrefix,
|
|
232
287
|
e: escapeClassName,
|
|
233
288
|
config: getConfigValue,
|
|
234
|
-
theme
|
|
235
|
-
const [pathRoot, ...subPaths] = toPath(path)
|
|
236
|
-
const value = getConfigValue(['theme', pathRoot, ...subPaths], defaultValue)
|
|
237
|
-
return transformThemeValue(pathRoot)(value)
|
|
238
|
-
},
|
|
289
|
+
theme: resolveThemeValue,
|
|
239
290
|
corePlugins: (path) => {
|
|
240
291
|
if (Array.isArray(tailwindConfig.corePlugins)) {
|
|
241
292
|
return tailwindConfig.corePlugins.includes(path)
|
|
@@ -250,7 +301,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
250
301
|
addBase(base) {
|
|
251
302
|
for (let [identifier, rule] of withIdentifiers(base)) {
|
|
252
303
|
let prefixedIdentifier = prefixIdentifier(identifier, {})
|
|
253
|
-
let offset = offsets.base
|
|
304
|
+
let offset = offsets.create('base')
|
|
254
305
|
|
|
255
306
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
256
307
|
context.candidateRuleMap.set(prefixedIdentifier, [])
|
|
@@ -279,11 +330,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
279
330
|
|
|
280
331
|
context.candidateRuleMap
|
|
281
332
|
.get(prefixedIdentifier)
|
|
282
|
-
.push([{ sort: offsets.
|
|
333
|
+
.push([{ sort: offsets.create('defaults'), layer: 'defaults' }, rule])
|
|
283
334
|
}
|
|
284
335
|
},
|
|
285
336
|
addComponents(components, options) {
|
|
286
337
|
let defaultOptions = {
|
|
338
|
+
preserveSource: false,
|
|
287
339
|
respectPrefix: true,
|
|
288
340
|
respectImportant: false,
|
|
289
341
|
}
|
|
@@ -301,11 +353,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
301
353
|
|
|
302
354
|
context.candidateRuleMap
|
|
303
355
|
.get(prefixedIdentifier)
|
|
304
|
-
.push([{ sort: offsets.components
|
|
356
|
+
.push([{ sort: offsets.create('components'), layer: 'components', options }, rule])
|
|
305
357
|
}
|
|
306
358
|
},
|
|
307
359
|
addUtilities(utilities, options) {
|
|
308
360
|
let defaultOptions = {
|
|
361
|
+
preserveSource: false,
|
|
309
362
|
respectPrefix: true,
|
|
310
363
|
respectImportant: true,
|
|
311
364
|
}
|
|
@@ -323,18 +376,19 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
323
376
|
|
|
324
377
|
context.candidateRuleMap
|
|
325
378
|
.get(prefixedIdentifier)
|
|
326
|
-
.push([{ sort: offsets.utilities
|
|
379
|
+
.push([{ sort: offsets.create('utilities'), layer: 'utilities', options }, rule])
|
|
327
380
|
}
|
|
328
381
|
},
|
|
329
382
|
matchUtilities: function (utilities, options) {
|
|
330
383
|
let defaultOptions = {
|
|
331
384
|
respectPrefix: true,
|
|
332
385
|
respectImportant: true,
|
|
386
|
+
modifiers: false,
|
|
333
387
|
}
|
|
334
388
|
|
|
335
|
-
options = { ...defaultOptions, ...options }
|
|
389
|
+
options = normalizeOptionTypes({ ...defaultOptions, ...options })
|
|
336
390
|
|
|
337
|
-
let offset = offsets.utilities
|
|
391
|
+
let offset = offsets.create('utilities')
|
|
338
392
|
|
|
339
393
|
for (let identifier in utilities) {
|
|
340
394
|
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
@@ -343,24 +397,51 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
343
397
|
classList.add([prefixedIdentifier, options])
|
|
344
398
|
|
|
345
399
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
346
|
-
let
|
|
347
|
-
|
|
348
|
-
|
|
400
|
+
let [value, coercedType, utilityModifier] = coerceValue(
|
|
401
|
+
options.types,
|
|
402
|
+
modifier,
|
|
403
|
+
options,
|
|
404
|
+
tailwindConfig
|
|
405
|
+
)
|
|
349
406
|
|
|
350
407
|
if (value === undefined) {
|
|
351
408
|
return []
|
|
352
409
|
}
|
|
353
410
|
|
|
354
|
-
if (!
|
|
355
|
-
|
|
411
|
+
if (!options.types.some(({ type }) => type === coercedType)) {
|
|
412
|
+
if (isOnlyPlugin) {
|
|
413
|
+
log.warn([
|
|
414
|
+
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
415
|
+
`You can safely update it to \`${identifier}-${modifier.replace(
|
|
416
|
+
coercedType + ':',
|
|
417
|
+
''
|
|
418
|
+
)}\`.`,
|
|
419
|
+
])
|
|
420
|
+
} else {
|
|
421
|
+
return []
|
|
422
|
+
}
|
|
356
423
|
}
|
|
357
424
|
|
|
358
|
-
if (!
|
|
425
|
+
if (!isSyntacticallyValidPropertyValue(value)) {
|
|
359
426
|
return []
|
|
360
427
|
}
|
|
361
428
|
|
|
429
|
+
let extras = {
|
|
430
|
+
get modifier() {
|
|
431
|
+
if (!options.modifiers) {
|
|
432
|
+
log.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
433
|
+
'Your plugin must set `modifiers: true` in its options to support modifiers.',
|
|
434
|
+
])
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return utilityModifier
|
|
438
|
+
},
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
442
|
+
|
|
362
443
|
let ruleSets = []
|
|
363
|
-
.concat(rule(value))
|
|
444
|
+
.concat(modifiersEnabled ? rule(value, extras) : rule(value))
|
|
364
445
|
.filter(Boolean)
|
|
365
446
|
.map((declaration) => ({
|
|
366
447
|
[nameClass(identifier, modifier)]: declaration,
|
|
@@ -382,11 +463,12 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
382
463
|
let defaultOptions = {
|
|
383
464
|
respectPrefix: true,
|
|
384
465
|
respectImportant: false,
|
|
466
|
+
modifiers: false,
|
|
385
467
|
}
|
|
386
468
|
|
|
387
|
-
options = { ...defaultOptions, ...options }
|
|
469
|
+
options = normalizeOptionTypes({ ...defaultOptions, ...options })
|
|
388
470
|
|
|
389
|
-
let offset = offsets.components
|
|
471
|
+
let offset = offsets.create('components')
|
|
390
472
|
|
|
391
473
|
for (let identifier in components) {
|
|
392
474
|
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
@@ -395,15 +477,18 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
395
477
|
classList.add([prefixedIdentifier, options])
|
|
396
478
|
|
|
397
479
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
398
|
-
let
|
|
399
|
-
|
|
400
|
-
|
|
480
|
+
let [value, coercedType, utilityModifier] = coerceValue(
|
|
481
|
+
options.types,
|
|
482
|
+
modifier,
|
|
483
|
+
options,
|
|
484
|
+
tailwindConfig
|
|
485
|
+
)
|
|
401
486
|
|
|
402
487
|
if (value === undefined) {
|
|
403
488
|
return []
|
|
404
489
|
}
|
|
405
490
|
|
|
406
|
-
if (!
|
|
491
|
+
if (!options.types.some(({ type }) => type === coercedType)) {
|
|
407
492
|
if (isOnlyPlugin) {
|
|
408
493
|
log.warn([
|
|
409
494
|
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
@@ -417,12 +502,26 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
417
502
|
}
|
|
418
503
|
}
|
|
419
504
|
|
|
420
|
-
if (!
|
|
505
|
+
if (!isSyntacticallyValidPropertyValue(value)) {
|
|
421
506
|
return []
|
|
422
507
|
}
|
|
423
508
|
|
|
509
|
+
let extras = {
|
|
510
|
+
get modifier() {
|
|
511
|
+
if (!options.modifiers) {
|
|
512
|
+
log.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
513
|
+
'Your plugin must set `modifiers: true` in its options to support modifiers.',
|
|
514
|
+
])
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return utilityModifier
|
|
518
|
+
},
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
522
|
+
|
|
424
523
|
let ruleSets = []
|
|
425
|
-
.concat(rule(value))
|
|
524
|
+
.concat(modifiersEnabled ? rule(value, extras) : rule(value))
|
|
426
525
|
.filter(Boolean)
|
|
427
526
|
.map((declaration) => ({
|
|
428
527
|
[nameClass(identifier, modifier)]: declaration,
|
|
@@ -440,7 +539,109 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
440
539
|
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
|
|
441
540
|
}
|
|
442
541
|
},
|
|
542
|
+
addVariant(variantName, variantFunctions, options = {}) {
|
|
543
|
+
variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
|
|
544
|
+
if (typeof variantFunction !== 'string') {
|
|
545
|
+
// Safelist public API functions
|
|
546
|
+
return (api = {}) => {
|
|
547
|
+
let { args, modifySelectors, container, separator, wrap, format } = api
|
|
548
|
+
let result = variantFunction(
|
|
549
|
+
Object.assign(
|
|
550
|
+
{ modifySelectors, container, separator },
|
|
551
|
+
options.type === VARIANT_TYPES.MatchVariant && { args, wrap, format }
|
|
552
|
+
)
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
if (typeof result === 'string' && !isValidVariantFormatString(result)) {
|
|
556
|
+
throw new Error(
|
|
557
|
+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
|
|
558
|
+
)
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (Array.isArray(result)) {
|
|
562
|
+
return result
|
|
563
|
+
.filter((variant) => typeof variant === 'string')
|
|
564
|
+
.map((variant) => parseVariant(variant))
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// result may be undefined with legacy variants that use APIs like `modifySelectors`
|
|
568
|
+
// result may also be a postcss node if someone was returning the result from `modifySelectors`
|
|
569
|
+
return result && typeof result === 'string' && parseVariant(result)(api)
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (!isValidVariantFormatString(variantFunction)) {
|
|
574
|
+
throw new Error(
|
|
575
|
+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
|
|
576
|
+
)
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return parseVariant(variantFunction)
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
insertInto(variantList, variantName, options)
|
|
583
|
+
variantMap.set(variantName, variantFunctions)
|
|
584
|
+
context.variantOptions.set(variantName, options)
|
|
585
|
+
},
|
|
586
|
+
matchVariant(variant, variantFn, options) {
|
|
587
|
+
// A unique identifier that "groups" these variants together.
|
|
588
|
+
// This is for internal use only which is why it is not present in the types
|
|
589
|
+
let id = options?.id ?? ++variantIdentifier
|
|
590
|
+
let isSpecial = variant === '@'
|
|
591
|
+
|
|
592
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
593
|
+
|
|
594
|
+
for (let [key, value] of Object.entries(options?.values ?? {})) {
|
|
595
|
+
if (key === 'DEFAULT') continue
|
|
596
|
+
|
|
597
|
+
api.addVariant(
|
|
598
|
+
isSpecial ? `${variant}${key}` : `${variant}-${key}`,
|
|
599
|
+
({ args, container }) => {
|
|
600
|
+
return variantFn(
|
|
601
|
+
value,
|
|
602
|
+
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
|
|
603
|
+
)
|
|
604
|
+
},
|
|
605
|
+
|
|
606
|
+
{
|
|
607
|
+
...options,
|
|
608
|
+
value,
|
|
609
|
+
id,
|
|
610
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
611
|
+
variantInfo: VARIANT_INFO.Base,
|
|
612
|
+
}
|
|
613
|
+
)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
let hasDefault = 'DEFAULT' in (options?.values ?? {})
|
|
617
|
+
|
|
618
|
+
api.addVariant(
|
|
619
|
+
variant,
|
|
620
|
+
({ args, container }) => {
|
|
621
|
+
if (args?.value === sharedState.NONE && !hasDefault) {
|
|
622
|
+
return null
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
return variantFn(
|
|
626
|
+
args?.value === sharedState.NONE
|
|
627
|
+
? options.values.DEFAULT
|
|
628
|
+
: // Falling back to args if it is a string, otherwise '' for older intellisense
|
|
629
|
+
// (JetBrains) plugins.
|
|
630
|
+
args?.value ?? (typeof args === 'string' ? args : ''),
|
|
631
|
+
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
|
|
632
|
+
)
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
...options,
|
|
636
|
+
id,
|
|
637
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
638
|
+
variantInfo: VARIANT_INFO.Dynamic,
|
|
639
|
+
}
|
|
640
|
+
)
|
|
641
|
+
},
|
|
443
642
|
}
|
|
643
|
+
|
|
644
|
+
return api
|
|
444
645
|
}
|
|
445
646
|
|
|
446
647
|
let fileModifiedMapCache = new WeakMap()
|
|
@@ -453,6 +654,7 @@ export function getFileModifiedMap(context) {
|
|
|
453
654
|
|
|
454
655
|
function trackModified(files, fileModifiedMap) {
|
|
455
656
|
let changed = false
|
|
657
|
+
let mtimesToCommit = new Map()
|
|
456
658
|
|
|
457
659
|
for (let file of files) {
|
|
458
660
|
if (!file) continue
|
|
@@ -473,10 +675,10 @@ function trackModified(files, fileModifiedMap) {
|
|
|
473
675
|
changed = true
|
|
474
676
|
}
|
|
475
677
|
|
|
476
|
-
|
|
678
|
+
mtimesToCommit.set(file, newModified)
|
|
477
679
|
}
|
|
478
680
|
|
|
479
|
-
return changed
|
|
681
|
+
return [changed, mtimesToCommit]
|
|
480
682
|
}
|
|
481
683
|
|
|
482
684
|
function extractVariantAtRules(node) {
|
|
@@ -513,14 +715,14 @@ function collectLayerPlugins(root) {
|
|
|
513
715
|
} else if (layerRule.params === 'components') {
|
|
514
716
|
for (let node of layerRule.nodes) {
|
|
515
717
|
layerPlugins.push(function ({ addComponents }) {
|
|
516
|
-
addComponents(node, { respectPrefix: false })
|
|
718
|
+
addComponents(node, { respectPrefix: false, preserveSource: true })
|
|
517
719
|
})
|
|
518
720
|
}
|
|
519
721
|
layerRule.remove()
|
|
520
722
|
} else if (layerRule.params === 'utilities') {
|
|
521
723
|
for (let node of layerRule.nodes) {
|
|
522
724
|
layerPlugins.push(function ({ addUtilities }) {
|
|
523
|
-
addUtilities(node, { respectPrefix: false })
|
|
725
|
+
addUtilities(node, { respectPrefix: false, preserveSource: true })
|
|
524
726
|
})
|
|
525
727
|
}
|
|
526
728
|
layerRule.remove()
|
|
@@ -554,31 +756,56 @@ function resolvePlugins(context, root) {
|
|
|
554
756
|
// TODO: This is a workaround for backwards compatibility, since custom variants
|
|
555
757
|
// were historically sorted before screen/stackable variants.
|
|
556
758
|
let beforeVariants = [
|
|
759
|
+
variantPlugins['childVariant'],
|
|
557
760
|
variantPlugins['pseudoElementVariants'],
|
|
558
761
|
variantPlugins['pseudoClassVariants'],
|
|
762
|
+
variantPlugins['hasVariants'],
|
|
763
|
+
variantPlugins['ariaVariants'],
|
|
764
|
+
variantPlugins['dataVariants'],
|
|
559
765
|
]
|
|
560
766
|
let afterVariants = [
|
|
561
|
-
variantPlugins['
|
|
767
|
+
variantPlugins['supportsVariants'],
|
|
562
768
|
variantPlugins['reducedMotionVariants'],
|
|
563
|
-
variantPlugins['
|
|
564
|
-
variantPlugins['printVariant'],
|
|
769
|
+
variantPlugins['prefersContrastVariants'],
|
|
565
770
|
variantPlugins['screenVariants'],
|
|
566
771
|
variantPlugins['orientationVariants'],
|
|
772
|
+
variantPlugins['directionVariants'],
|
|
773
|
+
variantPlugins['darkVariants'],
|
|
774
|
+
variantPlugins['forcedColorsVariants'],
|
|
775
|
+
variantPlugins['printVariant'],
|
|
567
776
|
]
|
|
568
777
|
|
|
778
|
+
// This is a compatibility fix for the pre 3.4 dark mode behavior
|
|
779
|
+
// `class` retains the old behavior, but `selector` keeps the new behavior
|
|
780
|
+
let isLegacyDarkMode =
|
|
781
|
+
context.tailwindConfig.darkMode === 'class' ||
|
|
782
|
+
(Array.isArray(context.tailwindConfig.darkMode) &&
|
|
783
|
+
context.tailwindConfig.darkMode[0] === 'class')
|
|
784
|
+
|
|
785
|
+
if (isLegacyDarkMode) {
|
|
786
|
+
afterVariants = [
|
|
787
|
+
variantPlugins['supportsVariants'],
|
|
788
|
+
variantPlugins['reducedMotionVariants'],
|
|
789
|
+
variantPlugins['prefersContrastVariants'],
|
|
790
|
+
variantPlugins['darkVariants'],
|
|
791
|
+
variantPlugins['screenVariants'],
|
|
792
|
+
variantPlugins['orientationVariants'],
|
|
793
|
+
variantPlugins['directionVariants'],
|
|
794
|
+
variantPlugins['forcedColorsVariants'],
|
|
795
|
+
variantPlugins['printVariant'],
|
|
796
|
+
]
|
|
797
|
+
}
|
|
798
|
+
|
|
569
799
|
return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
|
|
570
800
|
}
|
|
571
801
|
|
|
572
802
|
function registerPlugins(plugins, context) {
|
|
573
803
|
let variantList = []
|
|
574
804
|
let variantMap = new Map()
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
utilities: 0n,
|
|
580
|
-
user: 0n,
|
|
581
|
-
}
|
|
805
|
+
context.variantMap = variantMap
|
|
806
|
+
|
|
807
|
+
let offsets = new Offsets()
|
|
808
|
+
context.offsets = offsets
|
|
582
809
|
|
|
583
810
|
let classList = new Set()
|
|
584
811
|
|
|
@@ -599,49 +826,17 @@ function registerPlugins(plugins, context) {
|
|
|
599
826
|
}
|
|
600
827
|
}
|
|
601
828
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
offsets.defaults,
|
|
605
|
-
offsets.components,
|
|
606
|
-
offsets.utilities,
|
|
607
|
-
offsets.user,
|
|
608
|
-
])
|
|
609
|
-
let reservedBits = BigInt(highestOffset.toString(2).length)
|
|
610
|
-
|
|
611
|
-
// A number one less than the top range of the highest offset area
|
|
612
|
-
// so arbitrary properties are always sorted at the end.
|
|
613
|
-
context.arbitraryPropertiesSort = ((1n << reservedBits) << 0n) - 1n
|
|
614
|
-
|
|
615
|
-
context.layerOrder = {
|
|
616
|
-
defaults: (1n << reservedBits) << 0n,
|
|
617
|
-
base: (1n << reservedBits) << 1n,
|
|
618
|
-
components: (1n << reservedBits) << 2n,
|
|
619
|
-
utilities: (1n << reservedBits) << 3n,
|
|
620
|
-
user: (1n << reservedBits) << 4n,
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
reservedBits += 5n
|
|
624
|
-
|
|
625
|
-
let offset = 0
|
|
626
|
-
context.variantOrder = new Map(
|
|
627
|
-
variantList
|
|
628
|
-
.map((variant, i) => {
|
|
629
|
-
let variantFunctions = variantMap.get(variant).length
|
|
630
|
-
let bits = (1n << BigInt(i + offset)) << reservedBits
|
|
631
|
-
offset += variantFunctions - 1
|
|
632
|
-
return [variant, bits]
|
|
633
|
-
})
|
|
634
|
-
.sort(([, a], [, z]) => bigSign(a - z))
|
|
635
|
-
)
|
|
636
|
-
|
|
637
|
-
context.minimumScreen = [...context.variantOrder.values()].shift()
|
|
829
|
+
// Make sure to record bit masks for every variant
|
|
830
|
+
offsets.recordVariants(variantList, (variant) => variantMap.get(variant).length)
|
|
638
831
|
|
|
639
832
|
// Build variantMap
|
|
640
833
|
for (let [variantName, variantFunctions] of variantMap.entries()) {
|
|
641
|
-
let sort = context.variantOrder.get(variantName)
|
|
642
834
|
context.variantMap.set(
|
|
643
835
|
variantName,
|
|
644
|
-
variantFunctions.map((variantFunction, idx) => [
|
|
836
|
+
variantFunctions.map((variantFunction, idx) => [
|
|
837
|
+
offsets.forVariant(variantName, idx),
|
|
838
|
+
variantFunction,
|
|
839
|
+
])
|
|
645
840
|
)
|
|
646
841
|
}
|
|
647
842
|
|
|
@@ -670,6 +865,7 @@ function registerPlugins(plugins, context) {
|
|
|
670
865
|
if (checks.length > 0) {
|
|
671
866
|
let patternMatchingCount = new Map()
|
|
672
867
|
let prefixLength = context.tailwindConfig.prefix.length
|
|
868
|
+
let checkImportantUtils = checks.some((check) => check.pattern.source.includes('!'))
|
|
673
869
|
|
|
674
870
|
for (let util of classList) {
|
|
675
871
|
let utils = Array.isArray(util)
|
|
@@ -695,6 +891,21 @@ function registerPlugins(plugins, context) {
|
|
|
695
891
|
]
|
|
696
892
|
}
|
|
697
893
|
|
|
894
|
+
if (options.types.some(({ type }) => type === 'color')) {
|
|
895
|
+
classes = [
|
|
896
|
+
...classes,
|
|
897
|
+
...classes.flatMap((cls) =>
|
|
898
|
+
Object.keys(context.tailwindConfig.theme.opacity).map(
|
|
899
|
+
(opacity) => `${cls}/${opacity}`
|
|
900
|
+
)
|
|
901
|
+
),
|
|
902
|
+
]
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
if (checkImportantUtils && options?.respectImportant) {
|
|
906
|
+
classes = [...classes, ...classes.map((cls) => '!' + cls)]
|
|
907
|
+
}
|
|
908
|
+
|
|
698
909
|
return classes
|
|
699
910
|
})()
|
|
700
911
|
: [util]
|
|
@@ -736,26 +947,52 @@ function registerPlugins(plugins, context) {
|
|
|
736
947
|
}
|
|
737
948
|
}
|
|
738
949
|
|
|
950
|
+
let darkClassName = [].concat(context.tailwindConfig.darkMode ?? 'media')[1] ?? 'dark'
|
|
951
|
+
|
|
739
952
|
// A list of utilities that are used by certain Tailwind CSS utilities but
|
|
740
953
|
// that don't exist on their own. This will result in them "not existing" and
|
|
741
954
|
// sorting could be weird since you still require them in order to make the
|
|
742
|
-
// host
|
|
743
|
-
let parasiteUtilities =
|
|
955
|
+
// host utilities work properly. (Thanks Biology)
|
|
956
|
+
let parasiteUtilities = [
|
|
957
|
+
prefix(context, darkClassName),
|
|
958
|
+
prefix(context, 'group'),
|
|
959
|
+
prefix(context, 'peer'),
|
|
960
|
+
]
|
|
744
961
|
context.getClassOrder = function getClassOrder(classes) {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
if (
|
|
748
|
-
|
|
962
|
+
// Sort classes so they're ordered in a deterministic manner
|
|
963
|
+
let sorted = [...classes].sort((a, z) => {
|
|
964
|
+
if (a === z) return 0
|
|
965
|
+
if (a < z) return -1
|
|
966
|
+
return 1
|
|
967
|
+
})
|
|
968
|
+
|
|
969
|
+
// Non-util classes won't be generated, so we default them to null
|
|
970
|
+
let sortedClassNames = new Map(sorted.map((className) => [className, null]))
|
|
971
|
+
|
|
972
|
+
// Sort all classes in order
|
|
973
|
+
// Non-tailwind classes won't be generated and will be left as `null`
|
|
974
|
+
let rules = generateRules(new Set(sorted), context, true)
|
|
975
|
+
rules = context.offsets.sort(rules)
|
|
976
|
+
|
|
977
|
+
let idx = BigInt(parasiteUtilities.length)
|
|
978
|
+
|
|
979
|
+
for (const [, rule] of rules) {
|
|
980
|
+
let candidate = rule.raws.tailwind.candidate
|
|
981
|
+
|
|
982
|
+
// When multiple rules match a candidate
|
|
983
|
+
// always take the position of the first one
|
|
984
|
+
sortedClassNames.set(candidate, sortedClassNames.get(candidate) ?? idx++)
|
|
749
985
|
}
|
|
750
986
|
|
|
751
987
|
return classes.map((className) => {
|
|
752
988
|
let order = sortedClassNames.get(className) ?? null
|
|
989
|
+
let parasiteIndex = parasiteUtilities.indexOf(className)
|
|
753
990
|
|
|
754
|
-
if (order === null &&
|
|
991
|
+
if (order === null && parasiteIndex !== -1) {
|
|
755
992
|
// This will make sure that it is at the very beginning of the
|
|
756
993
|
// `components` layer which technically means 'before any
|
|
757
994
|
// components'.
|
|
758
|
-
order =
|
|
995
|
+
order = BigInt(parasiteIndex)
|
|
759
996
|
}
|
|
760
997
|
|
|
761
998
|
return [className, order]
|
|
@@ -764,18 +1001,35 @@ function registerPlugins(plugins, context) {
|
|
|
764
1001
|
|
|
765
1002
|
// Generate a list of strings for autocompletion purposes, e.g.
|
|
766
1003
|
// ['uppercase', 'lowercase', ...]
|
|
767
|
-
context.getClassList = function getClassList() {
|
|
1004
|
+
context.getClassList = function getClassList(options = {}) {
|
|
768
1005
|
let output = []
|
|
769
1006
|
|
|
770
1007
|
for (let util of classList) {
|
|
771
1008
|
if (Array.isArray(util)) {
|
|
772
|
-
let [utilName,
|
|
1009
|
+
let [utilName, utilOptions] = util
|
|
773
1010
|
let negativeClasses = []
|
|
774
1011
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
1012
|
+
let modifiers = Object.keys(utilOptions?.modifiers ?? {})
|
|
1013
|
+
|
|
1014
|
+
if (utilOptions?.types?.some(({ type }) => type === 'color')) {
|
|
1015
|
+
modifiers.push(...Object.keys(context.tailwindConfig.theme.opacity ?? {}))
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
let metadata = { modifiers }
|
|
1019
|
+
let includeMetadata = options.includeMetadata && modifiers.length > 0
|
|
1020
|
+
|
|
1021
|
+
for (let [key, value] of Object.entries(utilOptions?.values ?? {})) {
|
|
1022
|
+
// Ignore undefined and null values
|
|
1023
|
+
if (value == null) {
|
|
1024
|
+
continue
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
let cls = formatClass(utilName, key)
|
|
1028
|
+
output.push(includeMetadata ? [cls, metadata] : cls)
|
|
1029
|
+
|
|
1030
|
+
if (utilOptions?.supportsNegativeValues && negateValue(value)) {
|
|
1031
|
+
let cls = formatClass(utilName, `-${key}`)
|
|
1032
|
+
negativeClasses.push(includeMetadata ? [cls, metadata] : cls)
|
|
779
1033
|
}
|
|
780
1034
|
}
|
|
781
1035
|
|
|
@@ -787,21 +1041,235 @@ function registerPlugins(plugins, context) {
|
|
|
787
1041
|
|
|
788
1042
|
return output
|
|
789
1043
|
}
|
|
1044
|
+
|
|
1045
|
+
// Generate a list of available variants with meta information of the type of variant.
|
|
1046
|
+
context.getVariants = function getVariants() {
|
|
1047
|
+
// We use a unique, random ID for candidate names to avoid conflicts
|
|
1048
|
+
// We can't use characters like `_`, `:`, `@` or `.` because they might
|
|
1049
|
+
// be used as a separator
|
|
1050
|
+
let id = Math.random().toString(36).substring(7).toUpperCase()
|
|
1051
|
+
|
|
1052
|
+
let result = []
|
|
1053
|
+
for (let [name, options] of context.variantOptions.entries()) {
|
|
1054
|
+
if (options.variantInfo === VARIANT_INFO.Base) continue
|
|
1055
|
+
|
|
1056
|
+
result.push({
|
|
1057
|
+
name,
|
|
1058
|
+
isArbitrary: options.type === Symbol.for('MATCH_VARIANT'),
|
|
1059
|
+
values: Object.keys(options.values ?? {}),
|
|
1060
|
+
hasDash: name !== '@',
|
|
1061
|
+
selectors({ modifier, value } = {}) {
|
|
1062
|
+
let candidate = `TAILWINDPLACEHOLDER${id}`
|
|
1063
|
+
|
|
1064
|
+
let rule = postcss.rule({ selector: `.${candidate}` })
|
|
1065
|
+
let container = postcss.root({ nodes: [rule.clone()] })
|
|
1066
|
+
|
|
1067
|
+
let before = container.toString()
|
|
1068
|
+
|
|
1069
|
+
let fns = (context.variantMap.get(name) ?? []).flatMap(([_, fn]) => fn)
|
|
1070
|
+
let formatStrings = []
|
|
1071
|
+
for (let fn of fns) {
|
|
1072
|
+
let localFormatStrings = []
|
|
1073
|
+
|
|
1074
|
+
let api = {
|
|
1075
|
+
args: { modifier, value: options.values?.[value] ?? value },
|
|
1076
|
+
separator: context.tailwindConfig.separator,
|
|
1077
|
+
modifySelectors(modifierFunction) {
|
|
1078
|
+
// Run the modifierFunction over each rule
|
|
1079
|
+
container.each((rule) => {
|
|
1080
|
+
if (rule.type !== 'rule') {
|
|
1081
|
+
return
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
rule.selectors = rule.selectors.map((selector) => {
|
|
1085
|
+
return modifierFunction({
|
|
1086
|
+
get className() {
|
|
1087
|
+
return getClassNameFromSelector(selector)
|
|
1088
|
+
},
|
|
1089
|
+
selector,
|
|
1090
|
+
})
|
|
1091
|
+
})
|
|
1092
|
+
})
|
|
1093
|
+
|
|
1094
|
+
return container
|
|
1095
|
+
},
|
|
1096
|
+
format(str) {
|
|
1097
|
+
localFormatStrings.push(str)
|
|
1098
|
+
},
|
|
1099
|
+
wrap(wrapper) {
|
|
1100
|
+
localFormatStrings.push(`@${wrapper.name} ${wrapper.params} { & }`)
|
|
1101
|
+
},
|
|
1102
|
+
container,
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
let ruleWithVariant = fn(api)
|
|
1106
|
+
if (localFormatStrings.length > 0) {
|
|
1107
|
+
formatStrings.push(localFormatStrings)
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
1111
|
+
for (let variantFunction of ruleWithVariant) {
|
|
1112
|
+
localFormatStrings = []
|
|
1113
|
+
variantFunction(api)
|
|
1114
|
+
formatStrings.push(localFormatStrings)
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// Reverse engineer the result of the `container`
|
|
1120
|
+
let manualFormatStrings = []
|
|
1121
|
+
let after = container.toString()
|
|
1122
|
+
|
|
1123
|
+
if (before !== after) {
|
|
1124
|
+
// Figure out all selectors
|
|
1125
|
+
container.walkRules((rule) => {
|
|
1126
|
+
let modified = rule.selector
|
|
1127
|
+
|
|
1128
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
1129
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
1130
|
+
// However, plugin authors probably also prepend or append certain
|
|
1131
|
+
// classes, pseudos, ids, ...
|
|
1132
|
+
let rebuiltBase = selectorParser((selectors) => {
|
|
1133
|
+
selectors.walkClasses((classNode) => {
|
|
1134
|
+
classNode.value = `${name}${context.tailwindConfig.separator}${classNode.value}`
|
|
1135
|
+
})
|
|
1136
|
+
}).processSync(modified)
|
|
1137
|
+
|
|
1138
|
+
// Now that we know the original selector, the new selector, and
|
|
1139
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
1140
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
1141
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
1142
|
+
//
|
|
1143
|
+
// E.g.:
|
|
1144
|
+
// variant: foo
|
|
1145
|
+
// selector: .markdown > p
|
|
1146
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
1147
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
1148
|
+
// format: .foo &
|
|
1149
|
+
manualFormatStrings.push(modified.replace(rebuiltBase, '&').replace(candidate, '&'))
|
|
1150
|
+
})
|
|
1151
|
+
|
|
1152
|
+
// Figure out all atrules
|
|
1153
|
+
container.walkAtRules((atrule) => {
|
|
1154
|
+
manualFormatStrings.push(`@${atrule.name} (${atrule.params}) { & }`)
|
|
1155
|
+
})
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
let isArbitraryVariant = !(value in (options.values ?? {}))
|
|
1159
|
+
let internalFeatures = options[INTERNAL_FEATURES] ?? {}
|
|
1160
|
+
|
|
1161
|
+
let respectPrefix = (() => {
|
|
1162
|
+
if (isArbitraryVariant) return false
|
|
1163
|
+
if (internalFeatures.respectPrefix === false) return false
|
|
1164
|
+
return true
|
|
1165
|
+
})()
|
|
1166
|
+
|
|
1167
|
+
formatStrings = formatStrings.map((format) =>
|
|
1168
|
+
format.map((str) => ({
|
|
1169
|
+
format: str,
|
|
1170
|
+
respectPrefix,
|
|
1171
|
+
}))
|
|
1172
|
+
)
|
|
1173
|
+
|
|
1174
|
+
manualFormatStrings = manualFormatStrings.map((format) => ({
|
|
1175
|
+
format,
|
|
1176
|
+
respectPrefix,
|
|
1177
|
+
}))
|
|
1178
|
+
|
|
1179
|
+
let opts = {
|
|
1180
|
+
candidate,
|
|
1181
|
+
context,
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
let result = formatStrings.map((formats) =>
|
|
1185
|
+
finalizeSelector(`.${candidate}`, formatVariantSelector(formats, opts), opts)
|
|
1186
|
+
.replace(`.${candidate}`, '&')
|
|
1187
|
+
.replace('{ & }', '')
|
|
1188
|
+
.trim()
|
|
1189
|
+
)
|
|
1190
|
+
|
|
1191
|
+
if (manualFormatStrings.length > 0) {
|
|
1192
|
+
result.push(
|
|
1193
|
+
formatVariantSelector(manualFormatStrings, opts)
|
|
1194
|
+
.toString()
|
|
1195
|
+
.replace(`.${candidate}`, '&')
|
|
1196
|
+
)
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
return result
|
|
1200
|
+
},
|
|
1201
|
+
})
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
return result
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Mark as class as retroactively invalid
|
|
1210
|
+
*
|
|
1211
|
+
*
|
|
1212
|
+
* @param {string} candidate
|
|
1213
|
+
*/
|
|
1214
|
+
function markInvalidUtilityCandidate(context, candidate) {
|
|
1215
|
+
if (!context.classCache.has(candidate)) {
|
|
1216
|
+
return
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// Mark this as not being a real utility
|
|
1220
|
+
context.notClassCache.add(candidate)
|
|
1221
|
+
|
|
1222
|
+
// Remove it from any candidate-specific caches
|
|
1223
|
+
context.classCache.delete(candidate)
|
|
1224
|
+
context.applyClassCache.delete(candidate)
|
|
1225
|
+
context.candidateRuleMap.delete(candidate)
|
|
1226
|
+
context.candidateRuleCache.delete(candidate)
|
|
1227
|
+
|
|
1228
|
+
// Ensure the stylesheet gets rebuilt
|
|
1229
|
+
context.stylesheetCache = null
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* Mark as class as retroactively invalid
|
|
1234
|
+
*
|
|
1235
|
+
* @param {import('postcss').Node} node
|
|
1236
|
+
*/
|
|
1237
|
+
function markInvalidUtilityNode(context, node) {
|
|
1238
|
+
let candidate = node.raws.tailwind.candidate
|
|
1239
|
+
|
|
1240
|
+
if (!candidate) {
|
|
1241
|
+
return
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
for (const entry of context.ruleCache) {
|
|
1245
|
+
if (entry[1].raws.tailwind.candidate === candidate) {
|
|
1246
|
+
context.ruleCache.delete(entry)
|
|
1247
|
+
// context.postCssNodeCache.delete(node)
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
markInvalidUtilityCandidate(context, candidate)
|
|
790
1252
|
}
|
|
791
1253
|
|
|
792
1254
|
export function createContext(tailwindConfig, changedContent = [], root = postcss.root()) {
|
|
793
1255
|
let context = {
|
|
794
1256
|
disposables: [],
|
|
795
1257
|
ruleCache: new Set(),
|
|
1258
|
+
candidateRuleCache: new Map(),
|
|
796
1259
|
classCache: new Map(),
|
|
797
1260
|
applyClassCache: new Map(),
|
|
798
|
-
|
|
1261
|
+
// Seed the not class cache with the blocklist (which is only strings)
|
|
1262
|
+
notClassCache: new Set(tailwindConfig.blocklist ?? []),
|
|
799
1263
|
postCssNodeCache: new Map(),
|
|
800
1264
|
candidateRuleMap: new Map(),
|
|
801
1265
|
tailwindConfig,
|
|
802
1266
|
changedContent: changedContent,
|
|
803
1267
|
variantMap: new Map(),
|
|
804
1268
|
stylesheetCache: null,
|
|
1269
|
+
variantOptions: new Map(),
|
|
1270
|
+
|
|
1271
|
+
markInvalidUtilityCandidate: (candidate) => markInvalidUtilityCandidate(context, candidate),
|
|
1272
|
+
markInvalidUtilityNode: (node) => markInvalidUtilityNode(context, node),
|
|
805
1273
|
}
|
|
806
1274
|
|
|
807
1275
|
let resolvedPlugins = resolvePlugins(context, root)
|
|
@@ -844,12 +1312,12 @@ export function getContext(
|
|
|
844
1312
|
// If there's already a context in the cache and we don't need to
|
|
845
1313
|
// reset the context, return the cached context.
|
|
846
1314
|
if (existingContext) {
|
|
847
|
-
let contextDependenciesChanged = trackModified(
|
|
1315
|
+
let [contextDependenciesChanged, mtimesToCommit] = trackModified(
|
|
848
1316
|
[...contextDependencies],
|
|
849
1317
|
getFileModifiedMap(existingContext)
|
|
850
1318
|
)
|
|
851
1319
|
if (!contextDependenciesChanged && !cssDidChange) {
|
|
852
|
-
return [existingContext, false]
|
|
1320
|
+
return [existingContext, false, mtimesToCommit]
|
|
853
1321
|
}
|
|
854
1322
|
}
|
|
855
1323
|
|
|
@@ -880,7 +1348,11 @@ export function getContext(
|
|
|
880
1348
|
|
|
881
1349
|
let context = createContext(tailwindConfig, [], root)
|
|
882
1350
|
|
|
883
|
-
|
|
1351
|
+
Object.assign(context, {
|
|
1352
|
+
userConfigPath,
|
|
1353
|
+
})
|
|
1354
|
+
|
|
1355
|
+
let [, mtimesToCommit] = trackModified([...contextDependencies], getFileModifiedMap(context))
|
|
884
1356
|
|
|
885
1357
|
// ---
|
|
886
1358
|
|
|
@@ -895,5 +1367,5 @@ export function getContext(
|
|
|
895
1367
|
|
|
896
1368
|
contextSourcesMap.get(context).add(sourcePath)
|
|
897
1369
|
|
|
898
|
-
return [context, true]
|
|
1370
|
+
return [context, true, mtimesToCommit]
|
|
899
1371
|
}
|