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