tailwindcss 0.0.0-insiders.ed61821 → 0.0.0-insiders.ed8ff92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/README.md +15 -7
- package/colors.d.ts +3 -0
- package/colors.js +2 -304
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -4
- package/defaultTheme.d.ts +4 -0
- package/defaultTheme.js +2 -4
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +48 -0
- package/lib/cli/build/plugin.js +367 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +178 -0
- package/lib/cli/help/index.js +71 -0
- package/lib/cli/index.js +239 -0
- package/lib/cli/init/index.js +46 -0
- package/lib/cli-peer-dependencies.js +20 -7
- package/lib/cli.js +4 -702
- package/lib/constants.js +27 -20
- package/lib/corePluginList.js +22 -4
- package/lib/corePlugins.js +2558 -1744
- package/lib/css/preflight.css +22 -9
- package/lib/featureFlags.js +39 -25
- package/lib/index.js +4 -30
- package/lib/lib/cacheInvalidation.js +90 -0
- package/lib/lib/collapseAdjacentRules.js +28 -10
- package/lib/lib/collapseDuplicateDeclarations.js +83 -0
- package/lib/lib/content.js +177 -0
- package/lib/lib/defaultExtractor.js +241 -0
- package/lib/lib/detectNesting.js +27 -3
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +457 -159
- package/lib/lib/expandTailwindAtRules.js +169 -153
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +621 -105
- package/lib/lib/getModuleDependencies.js +11 -8
- package/lib/lib/normalizeTailwindDirectives.js +45 -33
- package/lib/lib/offsets.js +299 -0
- package/lib/lib/partitionApplyAtRules.js +56 -0
- package/lib/lib/regex.js +60 -0
- package/lib/lib/remap-bitfield.js +87 -0
- package/lib/lib/resolveDefaultsAtRules.js +114 -81
- package/lib/lib/setupContextUtils.js +839 -364
- package/lib/lib/setupTrackingContext.js +67 -71
- package/lib/lib/sharedState.js +63 -14
- package/lib/lib/substituteScreenAtRules.js +13 -8
- package/lib/oxide/cli/build/deps.js +81 -0
- package/lib/oxide/cli/build/index.js +47 -0
- package/lib/oxide/cli/build/plugin.js +364 -0
- package/lib/oxide/cli/build/utils.js +77 -0
- package/lib/oxide/cli/build/watching.js +177 -0
- package/lib/oxide/cli/help/index.js +70 -0
- package/lib/oxide/cli/index.js +220 -0
- package/lib/oxide/cli/init/index.js +35 -0
- package/lib/oxide/cli.js +5 -0
- package/lib/oxide/postcss-plugin.js +2 -0
- package/lib/plugin.js +48 -0
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +19 -0
- package/lib/postcss-plugins/nesting/plugin.js +87 -0
- package/lib/processTailwindFeatures.js +36 -21
- package/lib/public/colors.js +331 -0
- package/lib/public/create-plugin.js +15 -0
- package/lib/public/default-config.js +16 -0
- package/lib/public/default-theme.js +16 -0
- package/lib/public/resolve-config.js +22 -0
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +18 -24
- package/lib/util/cloneDeep.js +7 -6
- package/lib/util/cloneNodes.js +21 -3
- package/lib/util/color.js +54 -40
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -6
- package/lib/util/createUtilityPlugin.js +12 -14
- package/lib/util/dataTypes.js +164 -100
- package/lib/util/defaults.js +12 -3
- package/lib/util/escapeClassName.js +9 -6
- package/lib/util/escapeCommas.js +5 -2
- package/lib/util/flattenColorPalette.js +9 -12
- package/lib/util/formatVariantSelector.js +351 -0
- package/lib/util/getAllConfigs.js +29 -10
- package/lib/util/hashConfig.js +6 -3
- package/lib/util/isKeyframeRule.js +5 -2
- package/lib/util/isPlainObject.js +5 -2
- package/lib/util/isSyntacticallyValidPropertyValue.js +72 -0
- package/lib/util/log.js +44 -22
- package/lib/util/nameClass.js +20 -8
- package/lib/util/negateValue.js +24 -7
- package/lib/util/normalizeConfig.js +281 -0
- package/lib/util/normalizeScreens.js +170 -0
- package/lib/util/parseAnimationValue.js +47 -39
- package/lib/util/parseBoxShadowValue.js +84 -0
- package/lib/util/parseDependency.js +38 -53
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +11 -8
- package/lib/util/pluginUtils.js +186 -181
- package/lib/util/prefixSelector.js +27 -13
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +98 -137
- package/lib/util/resolveConfigPath.js +11 -9
- package/lib/util/responsive.js +8 -5
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +4 -1
- package/lib/util/toColorValue.js +5 -3
- package/lib/util/toPath.js +24 -3
- package/lib/util/transformThemeValue.js +49 -31
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +47 -24
- package/nesting/index.js +2 -12
- package/oxide-node-api-shim/index.js +21 -0
- package/oxide-node-api-shim/package.json +5 -0
- package/package.json +61 -52
- package/peers/index.js +76301 -84138
- package/plugin.d.ts +11 -0
- package/plugin.js +1 -2
- package/resolveConfig.d.ts +12 -0
- package/resolveConfig.js +2 -7
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +105 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/swap-engines.js +40 -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 +439 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +227 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +234 -0
- package/src/cli/init/index.js +50 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +4 -756
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +1087 -590
- package/src/css/preflight.css +22 -9
- package/src/featureFlags.js +26 -10
- package/src/index.js +4 -33
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +93 -0
- package/src/lib/content.js +208 -0
- package/src/lib/defaultExtractor.js +217 -0
- package/src/lib/detectNesting.js +30 -3
- package/src/lib/evaluateTailwindFunctions.js +84 -10
- package/src/lib/expandApplyAtRules.js +508 -153
- package/src/lib/expandTailwindAtRules.js +127 -108
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +648 -69
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/offsets.js +367 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +98 -60
- package/src/lib/setupContextUtils.js +814 -246
- package/src/lib/setupTrackingContext.js +50 -61
- package/src/lib/sharedState.js +60 -6
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/oxide/cli/build/deps.ts +91 -0
- package/src/oxide/cli/build/index.ts +47 -0
- package/src/oxide/cli/build/plugin.ts +436 -0
- package/src/oxide/cli/build/utils.ts +74 -0
- package/src/oxide/cli/build/watching.ts +225 -0
- package/src/oxide/cli/help/index.ts +69 -0
- package/src/oxide/cli/index.ts +212 -0
- package/src/oxide/cli/init/index.ts +32 -0
- package/src/oxide/cli.ts +1 -0
- package/src/oxide/postcss-plugin.ts +1 -0
- package/src/plugin.js +47 -0
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +18 -3
- package/src/public/colors.js +300 -0
- package/src/public/create-plugin.js +2 -0
- package/src/public/default-config.js +4 -0
- package/src/public/default-theme.js +4 -0
- package/src/public/resolve-config.js +7 -0
- package/src/util/buildMediaQuery.js +14 -16
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -2
- package/src/util/dataTypes.js +86 -21
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +412 -0
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +6 -2
- package/src/util/negateValue.js +15 -5
- package/src/util/normalizeConfig.js +300 -0
- package/src/util/normalizeScreens.js +140 -0
- package/src/util/parseAnimationValue.js +7 -1
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/parseDependency.js +37 -38
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +177 -143
- package/src/util/prefixSelector.js +30 -13
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +86 -91
- package/src/util/splitAtTopLevelOnly.js +45 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +33 -8
- package/src/util/validateConfig.js +13 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +14 -9
- package/stubs/defaultConfig.stub.js +313 -241
- package/stubs/simpleConfig.stub.js +1 -1
- package/types/config.d.ts +367 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +345 -0
- package/types/index.d.ts +7 -0
- package/CHANGELOG.md +0 -1744
- package/lib/lib/setupWatchingContext.js +0 -284
- package/nesting/plugin.js +0 -41
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/lib/setupWatchingContext.js +0 -307
|
@@ -11,12 +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
|
|
15
|
-
import corePlugins from '../corePlugins'
|
|
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'
|
|
19
|
+
import negateValue from '../util/negateValue'
|
|
20
|
+
import isSyntacticallyValidPropertyValue from '../util/isSyntacticallyValidPropertyValue'
|
|
21
|
+
import { generateRules, getClassNameFromSelector } from './generateRules'
|
|
22
|
+
import { hasContentChanged } from './cacheInvalidation.js'
|
|
23
|
+
import { Offsets } from './offsets.js'
|
|
24
|
+
import { flagEnabled } from '../featureFlags.js'
|
|
25
|
+
import { finalizeSelector, formatVariantSelector } from '../util/formatVariantSelector'
|
|
26
|
+
|
|
27
|
+
const VARIANT_TYPES = {
|
|
28
|
+
AddVariant: Symbol.for('ADD_VARIANT'),
|
|
29
|
+
MatchVariant: Symbol.for('MATCH_VARIANT'),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const VARIANT_INFO = {
|
|
33
|
+
Base: 1 << 0,
|
|
34
|
+
Dynamic: 1 << 1,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function prefix(context, selector) {
|
|
38
|
+
let prefix = context.tailwindConfig.prefix
|
|
39
|
+
return typeof prefix === 'function' ? prefix(selector) : prefix + selector
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeOptionTypes({ type = 'any', ...options }) {
|
|
43
|
+
let types = [].concat(type)
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...options,
|
|
47
|
+
types: types.map((type) => {
|
|
48
|
+
if (Array.isArray(type)) {
|
|
49
|
+
return { type: type[0], ...type[1] }
|
|
50
|
+
}
|
|
51
|
+
return { type, preferOnConflict: false }
|
|
52
|
+
}),
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parseVariantFormatString(input) {
|
|
57
|
+
/** @type {string[]} */
|
|
58
|
+
let parts = []
|
|
59
|
+
|
|
60
|
+
// When parsing whitespace around special characters are insignificant
|
|
61
|
+
// However, _inside_ of a variant they could be
|
|
62
|
+
// Because the selector could look like this
|
|
63
|
+
// @media { &[data-name="foo bar"] }
|
|
64
|
+
// This is why we do not skip whitespace
|
|
65
|
+
|
|
66
|
+
let current = ''
|
|
67
|
+
let depth = 0
|
|
68
|
+
|
|
69
|
+
for (let idx = 0; idx < input.length; idx++) {
|
|
70
|
+
let char = input[idx]
|
|
71
|
+
|
|
72
|
+
if (char === '\\') {
|
|
73
|
+
// Escaped characters are not special
|
|
74
|
+
current += '\\' + input[++idx]
|
|
75
|
+
} else if (char === '{') {
|
|
76
|
+
// Nested rule: start
|
|
77
|
+
++depth
|
|
78
|
+
parts.push(current.trim())
|
|
79
|
+
current = ''
|
|
80
|
+
} else if (char === '}') {
|
|
81
|
+
// Nested rule: end
|
|
82
|
+
if (--depth < 0) {
|
|
83
|
+
throw new Error(`Your { and } are unbalanced.`)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
parts.push(current.trim())
|
|
87
|
+
current = ''
|
|
88
|
+
} else {
|
|
89
|
+
// Normal character
|
|
90
|
+
current += char
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (current.length > 0) {
|
|
95
|
+
parts.push(current.trim())
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
parts = parts.filter((part) => part !== '')
|
|
99
|
+
|
|
100
|
+
return parts
|
|
101
|
+
}
|
|
20
102
|
|
|
21
103
|
function insertInto(list, value, { before = [] } = {}) {
|
|
22
104
|
before = [].concat(before)
|
|
@@ -47,39 +129,82 @@ function parseStyles(styles) {
|
|
|
47
129
|
})
|
|
48
130
|
}
|
|
49
131
|
|
|
50
|
-
function getClasses(selector) {
|
|
132
|
+
function getClasses(selector, mutate) {
|
|
51
133
|
let parser = selectorParser((selectors) => {
|
|
52
134
|
let allClasses = []
|
|
135
|
+
|
|
136
|
+
if (mutate) {
|
|
137
|
+
mutate(selectors)
|
|
138
|
+
}
|
|
139
|
+
|
|
53
140
|
selectors.walkClasses((classNode) => {
|
|
54
141
|
allClasses.push(classNode.value)
|
|
55
142
|
})
|
|
143
|
+
|
|
56
144
|
return allClasses
|
|
57
145
|
})
|
|
58
146
|
return parser.transformSync(selector)
|
|
59
147
|
}
|
|
60
148
|
|
|
61
|
-
function extractCandidates(node) {
|
|
62
|
-
let classes =
|
|
149
|
+
function extractCandidates(node, state = { containsNonOnDemandable: false }, depth = 0) {
|
|
150
|
+
let classes = []
|
|
151
|
+
|
|
152
|
+
// Handle normal rules
|
|
153
|
+
if (node.type === 'rule') {
|
|
154
|
+
// Ignore everything inside a :not(...). This allows you to write code like
|
|
155
|
+
// `div:not(.foo)`. If `.foo` is never found in your code, then we used to
|
|
156
|
+
// not generated it. But now we will ignore everything inside a `:not`, so
|
|
157
|
+
// that it still gets generated.
|
|
158
|
+
function ignoreNot(selectors) {
|
|
159
|
+
selectors.walkPseudos((pseudo) => {
|
|
160
|
+
if (pseudo.value === ':not') {
|
|
161
|
+
pseudo.remove()
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
for (let selector of node.selectors) {
|
|
167
|
+
let classCandidates = getClasses(selector, ignoreNot)
|
|
168
|
+
// At least one of the selectors contains non-"on-demandable" candidates.
|
|
169
|
+
if (classCandidates.length === 0) {
|
|
170
|
+
state.containsNonOnDemandable = true
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (let classCandidate of classCandidates) {
|
|
174
|
+
classes.push(classCandidate)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
63
178
|
|
|
64
|
-
|
|
179
|
+
// Handle at-rules (which contains nested rules)
|
|
180
|
+
else if (node.type === 'atrule') {
|
|
65
181
|
node.walkRules((rule) => {
|
|
66
|
-
|
|
182
|
+
for (let classCandidate of rule.selectors.flatMap((selector) => getClasses(selector))) {
|
|
183
|
+
classes.push(classCandidate)
|
|
184
|
+
}
|
|
67
185
|
})
|
|
68
186
|
}
|
|
69
187
|
|
|
188
|
+
if (depth === 0) {
|
|
189
|
+
return [state.containsNonOnDemandable || classes.length === 0, classes]
|
|
190
|
+
}
|
|
191
|
+
|
|
70
192
|
return classes
|
|
71
193
|
}
|
|
72
194
|
|
|
73
195
|
function withIdentifiers(styles) {
|
|
74
196
|
return parseStyles(styles).flatMap((node) => {
|
|
75
197
|
let nodeMap = new Map()
|
|
76
|
-
let candidates = extractCandidates(node)
|
|
198
|
+
let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node)
|
|
77
199
|
|
|
78
|
-
// If this isn't "on-demandable", assign it a universal candidate.
|
|
79
|
-
if (
|
|
80
|
-
|
|
200
|
+
// If this isn't "on-demandable", assign it a universal candidate to always include it.
|
|
201
|
+
if (containsNonOnDemandableSelectors) {
|
|
202
|
+
candidates.unshift(sharedState.NOT_ON_DEMAND)
|
|
81
203
|
}
|
|
82
204
|
|
|
205
|
+
// However, it could be that it also contains "on-demandable" candidates.
|
|
206
|
+
// E.g.: `span, .foo {}`, in that case it should still be possible to use
|
|
207
|
+
// `@apply foo` for example.
|
|
83
208
|
return candidates.map((c) => {
|
|
84
209
|
if (!nodeMap.has(node)) {
|
|
85
210
|
nodeMap.set(node, node)
|
|
@@ -89,64 +214,41 @@ function withIdentifiers(styles) {
|
|
|
89
214
|
})
|
|
90
215
|
}
|
|
91
216
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
['(', ')'],
|
|
96
|
-
])
|
|
97
|
-
let inverseMatchingBrackets = new Map(
|
|
98
|
-
Array.from(matchingBrackets.entries()).map(([k, v]) => [v, k])
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
let quotes = new Set(['"', "'", '`'])
|
|
102
|
-
|
|
103
|
-
// Arbitrary values must contain balanced brackets (), [] and {}. Escaped
|
|
104
|
-
// values don't count, and brackets inside quotes also don't count.
|
|
105
|
-
//
|
|
106
|
-
// E.g.: w-[this-is]w-[weird-and-invalid]
|
|
107
|
-
// E.g.: w-[this-is\\]w-\\[weird-but-valid]
|
|
108
|
-
// E.g.: content-['this-is-also-valid]-weirdly-enough']
|
|
109
|
-
function isValidArbitraryValue(value) {
|
|
110
|
-
let stack = []
|
|
111
|
-
let inQuotes = false
|
|
112
|
-
|
|
113
|
-
for (let i = 0; i < value.length; i++) {
|
|
114
|
-
let char = value[i]
|
|
115
|
-
|
|
116
|
-
// Non-escaped quotes allow us to "allow" anything in between
|
|
117
|
-
if (quotes.has(char) && value[i - 1] !== '\\') {
|
|
118
|
-
inQuotes = !inQuotes
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (inQuotes) continue
|
|
122
|
-
if (value[i - 1] === '\\') continue // Escaped
|
|
217
|
+
export function isValidVariantFormatString(format) {
|
|
218
|
+
return format.startsWith('@') || format.includes('&')
|
|
219
|
+
}
|
|
123
220
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
221
|
+
export function parseVariant(variant) {
|
|
222
|
+
variant = variant
|
|
223
|
+
.replace(/\n+/g, '')
|
|
224
|
+
.replace(/\s{1,}/g, ' ')
|
|
225
|
+
.trim()
|
|
128
226
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
227
|
+
let fns = parseVariantFormatString(variant)
|
|
228
|
+
.map((str) => {
|
|
229
|
+
if (!str.startsWith('@')) {
|
|
230
|
+
return ({ format }) => format(str)
|
|
132
231
|
}
|
|
133
232
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
233
|
+
let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str)
|
|
234
|
+
return ({ wrap }) => wrap(postcss.atRule({ name, params: params.trim() }))
|
|
235
|
+
})
|
|
236
|
+
.reverse()
|
|
140
237
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
238
|
+
return (api) => {
|
|
239
|
+
for (let fn of fns) {
|
|
240
|
+
fn(api)
|
|
241
|
+
}
|
|
144
242
|
}
|
|
145
|
-
|
|
146
|
-
// All good, totally balanced!
|
|
147
|
-
return true
|
|
148
243
|
}
|
|
149
244
|
|
|
245
|
+
/**
|
|
246
|
+
*
|
|
247
|
+
* @param {any} tailwindConfig
|
|
248
|
+
* @param {any} context
|
|
249
|
+
* @param {object} param2
|
|
250
|
+
* @param {Offsets} param2.offsets
|
|
251
|
+
*/
|
|
150
252
|
function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
|
|
151
253
|
function getConfigValue(path, defaultValue) {
|
|
152
254
|
return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
|
|
@@ -157,37 +259,30 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
157
259
|
}
|
|
158
260
|
|
|
159
261
|
function prefixIdentifier(identifier, options) {
|
|
160
|
-
if (identifier ===
|
|
161
|
-
return
|
|
262
|
+
if (identifier === sharedState.NOT_ON_DEMAND) {
|
|
263
|
+
return sharedState.NOT_ON_DEMAND
|
|
162
264
|
}
|
|
163
265
|
|
|
164
266
|
if (!options.respectPrefix) {
|
|
165
267
|
return identifier
|
|
166
268
|
}
|
|
167
269
|
|
|
168
|
-
if (typeof context.tailwindConfig.prefix === 'function') {
|
|
169
|
-
return prefixSelector(context.tailwindConfig.prefix, `.${identifier}`).substr(1)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
270
|
return context.tailwindConfig.prefix + identifier
|
|
173
271
|
}
|
|
174
272
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
273
|
+
function resolveThemeValue(path, defaultValue, opts = {}) {
|
|
274
|
+
let parts = toPath(path)
|
|
275
|
+
let value = getConfigValue(['theme', ...parts], defaultValue)
|
|
276
|
+
return transformThemeValue(parts[0])(value, opts)
|
|
277
|
+
}
|
|
178
278
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
},
|
|
279
|
+
let variantIdentifier = 0
|
|
280
|
+
let api = {
|
|
182
281
|
postcss,
|
|
183
282
|
prefix: applyConfiguredPrefix,
|
|
184
283
|
e: escapeClassName,
|
|
185
284
|
config: getConfigValue,
|
|
186
|
-
theme
|
|
187
|
-
const [pathRoot, ...subPaths] = toPath(path)
|
|
188
|
-
const value = getConfigValue(['theme', pathRoot, ...subPaths], defaultValue)
|
|
189
|
-
return transformThemeValue(pathRoot)(value)
|
|
190
|
-
},
|
|
285
|
+
theme: resolveThemeValue,
|
|
191
286
|
corePlugins: (path) => {
|
|
192
287
|
if (Array.isArray(tailwindConfig.corePlugins)) {
|
|
193
288
|
return tailwindConfig.corePlugins.includes(path)
|
|
@@ -199,21 +294,31 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
199
294
|
// Preserved for backwards compatibility but not used in v3.0+
|
|
200
295
|
return []
|
|
201
296
|
},
|
|
202
|
-
|
|
203
|
-
for (let [identifier, rule] of withIdentifiers(
|
|
204
|
-
let
|
|
297
|
+
addBase(base) {
|
|
298
|
+
for (let [identifier, rule] of withIdentifiers(base)) {
|
|
299
|
+
let prefixedIdentifier = prefixIdentifier(identifier, {})
|
|
300
|
+
let offset = offsets.create('base')
|
|
205
301
|
|
|
206
|
-
if (!context.candidateRuleMap.has(
|
|
207
|
-
context.candidateRuleMap.set(
|
|
302
|
+
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
303
|
+
context.candidateRuleMap.set(prefixedIdentifier, [])
|
|
208
304
|
}
|
|
209
305
|
|
|
210
|
-
context.candidateRuleMap
|
|
306
|
+
context.candidateRuleMap
|
|
307
|
+
.get(prefixedIdentifier)
|
|
308
|
+
.push([{ sort: offset, layer: 'base' }, rule])
|
|
211
309
|
}
|
|
212
310
|
},
|
|
213
|
-
|
|
214
|
-
|
|
311
|
+
/**
|
|
312
|
+
* @param {string} group
|
|
313
|
+
* @param {Record<string, string | string[]>} declarations
|
|
314
|
+
*/
|
|
315
|
+
addDefaults(group, declarations) {
|
|
316
|
+
const groups = {
|
|
317
|
+
[`@defaults ${group}`]: declarations,
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
for (let [identifier, rule] of withIdentifiers(groups)) {
|
|
215
321
|
let prefixedIdentifier = prefixIdentifier(identifier, {})
|
|
216
|
-
let offset = offsets.base++
|
|
217
322
|
|
|
218
323
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
219
324
|
context.candidateRuleMap.set(prefixedIdentifier, [])
|
|
@@ -221,26 +326,20 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
221
326
|
|
|
222
327
|
context.candidateRuleMap
|
|
223
328
|
.get(prefixedIdentifier)
|
|
224
|
-
.push([{ sort:
|
|
329
|
+
.push([{ sort: offsets.create('defaults'), layer: 'defaults' }, rule])
|
|
225
330
|
}
|
|
226
331
|
},
|
|
227
332
|
addComponents(components, options) {
|
|
228
333
|
let defaultOptions = {
|
|
229
|
-
|
|
334
|
+
preserveSource: false,
|
|
230
335
|
respectPrefix: true,
|
|
231
336
|
respectImportant: false,
|
|
232
|
-
respectVariants: true,
|
|
233
337
|
}
|
|
234
338
|
|
|
235
|
-
options = Object.assign(
|
|
236
|
-
{},
|
|
237
|
-
defaultOptions,
|
|
238
|
-
Array.isArray(options) ? { variants: options } : options
|
|
239
|
-
)
|
|
339
|
+
options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
|
|
240
340
|
|
|
241
341
|
for (let [identifier, rule] of withIdentifiers(components)) {
|
|
242
342
|
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
243
|
-
let offset = offsets.components++
|
|
244
343
|
|
|
245
344
|
classList.add(prefixedIdentifier)
|
|
246
345
|
|
|
@@ -250,26 +349,20 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
250
349
|
|
|
251
350
|
context.candidateRuleMap
|
|
252
351
|
.get(prefixedIdentifier)
|
|
253
|
-
.push([{ sort:
|
|
352
|
+
.push([{ sort: offsets.create('components'), layer: 'components', options }, rule])
|
|
254
353
|
}
|
|
255
354
|
},
|
|
256
355
|
addUtilities(utilities, options) {
|
|
257
356
|
let defaultOptions = {
|
|
258
|
-
|
|
357
|
+
preserveSource: false,
|
|
259
358
|
respectPrefix: true,
|
|
260
359
|
respectImportant: true,
|
|
261
|
-
respectVariants: true,
|
|
262
360
|
}
|
|
263
361
|
|
|
264
|
-
options = Object.assign(
|
|
265
|
-
{},
|
|
266
|
-
defaultOptions,
|
|
267
|
-
Array.isArray(options) ? { variants: options } : options
|
|
268
|
-
)
|
|
362
|
+
options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options)
|
|
269
363
|
|
|
270
364
|
for (let [identifier, rule] of withIdentifiers(utilities)) {
|
|
271
365
|
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
272
|
-
let offset = offsets.utilities++
|
|
273
366
|
|
|
274
367
|
classList.add(prefixedIdentifier)
|
|
275
368
|
|
|
@@ -279,20 +372,19 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
279
372
|
|
|
280
373
|
context.candidateRuleMap
|
|
281
374
|
.get(prefixedIdentifier)
|
|
282
|
-
.push([{ sort:
|
|
375
|
+
.push([{ sort: offsets.create('utilities'), layer: 'utilities', options }, rule])
|
|
283
376
|
}
|
|
284
377
|
},
|
|
285
378
|
matchUtilities: function (utilities, options) {
|
|
286
379
|
let defaultOptions = {
|
|
287
|
-
variants: [],
|
|
288
380
|
respectPrefix: true,
|
|
289
381
|
respectImportant: true,
|
|
290
|
-
|
|
382
|
+
modifiers: false,
|
|
291
383
|
}
|
|
292
384
|
|
|
293
|
-
options = { ...defaultOptions, ...options }
|
|
385
|
+
options = normalizeOptionTypes({ ...defaultOptions, ...options })
|
|
294
386
|
|
|
295
|
-
let offset = offsets.utilities
|
|
387
|
+
let offset = offsets.create('utilities')
|
|
296
388
|
|
|
297
389
|
for (let identifier in utilities) {
|
|
298
390
|
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
@@ -301,15 +393,18 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
301
393
|
classList.add([prefixedIdentifier, options])
|
|
302
394
|
|
|
303
395
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
304
|
-
let
|
|
305
|
-
|
|
306
|
-
|
|
396
|
+
let [value, coercedType, utilityModifier] = coerceValue(
|
|
397
|
+
options.types,
|
|
398
|
+
modifier,
|
|
399
|
+
options,
|
|
400
|
+
tailwindConfig
|
|
401
|
+
)
|
|
307
402
|
|
|
308
403
|
if (value === undefined) {
|
|
309
404
|
return []
|
|
310
405
|
}
|
|
311
406
|
|
|
312
|
-
if (!
|
|
407
|
+
if (!options.types.some(({ type }) => type === coercedType)) {
|
|
313
408
|
if (isOnlyPlugin) {
|
|
314
409
|
log.warn([
|
|
315
410
|
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
@@ -323,25 +418,32 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
323
418
|
}
|
|
324
419
|
}
|
|
325
420
|
|
|
326
|
-
if (!
|
|
421
|
+
if (!isSyntacticallyValidPropertyValue(value)) {
|
|
327
422
|
return []
|
|
328
423
|
}
|
|
329
424
|
|
|
330
|
-
let
|
|
425
|
+
let extras = {
|
|
426
|
+
get modifier() {
|
|
427
|
+
if (!options.modifiers) {
|
|
428
|
+
log.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
429
|
+
'Your plugin must set `modifiers: true` in its options to support modifiers.',
|
|
430
|
+
])
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return utilityModifier
|
|
434
|
+
},
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
438
|
+
|
|
331
439
|
let ruleSets = []
|
|
332
|
-
.concat(
|
|
333
|
-
rule(value, {
|
|
334
|
-
includeRules(rules) {
|
|
335
|
-
includedRules.push(...rules)
|
|
336
|
-
},
|
|
337
|
-
})
|
|
338
|
-
)
|
|
440
|
+
.concat(modifiersEnabled ? rule(value, extras) : rule(value))
|
|
339
441
|
.filter(Boolean)
|
|
340
442
|
.map((declaration) => ({
|
|
341
443
|
[nameClass(identifier, modifier)]: declaration,
|
|
342
444
|
}))
|
|
343
445
|
|
|
344
|
-
return
|
|
446
|
+
return ruleSets
|
|
345
447
|
}
|
|
346
448
|
|
|
347
449
|
let withOffsets = [{ sort: offset, layer: 'utilities', options }, wrapped]
|
|
@@ -353,7 +455,189 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
|
|
|
353
455
|
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
|
|
354
456
|
}
|
|
355
457
|
},
|
|
458
|
+
matchComponents: function (components, options) {
|
|
459
|
+
let defaultOptions = {
|
|
460
|
+
respectPrefix: true,
|
|
461
|
+
respectImportant: false,
|
|
462
|
+
modifiers: false,
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
options = normalizeOptionTypes({ ...defaultOptions, ...options })
|
|
466
|
+
|
|
467
|
+
let offset = offsets.create('components')
|
|
468
|
+
|
|
469
|
+
for (let identifier in components) {
|
|
470
|
+
let prefixedIdentifier = prefixIdentifier(identifier, options)
|
|
471
|
+
let rule = components[identifier]
|
|
472
|
+
|
|
473
|
+
classList.add([prefixedIdentifier, options])
|
|
474
|
+
|
|
475
|
+
function wrapped(modifier, { isOnlyPlugin }) {
|
|
476
|
+
let [value, coercedType, utilityModifier] = coerceValue(
|
|
477
|
+
options.types,
|
|
478
|
+
modifier,
|
|
479
|
+
options,
|
|
480
|
+
tailwindConfig
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
if (value === undefined) {
|
|
484
|
+
return []
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (!options.types.some(({ type }) => type === coercedType)) {
|
|
488
|
+
if (isOnlyPlugin) {
|
|
489
|
+
log.warn([
|
|
490
|
+
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
491
|
+
`You can safely update it to \`${identifier}-${modifier.replace(
|
|
492
|
+
coercedType + ':',
|
|
493
|
+
''
|
|
494
|
+
)}\`.`,
|
|
495
|
+
])
|
|
496
|
+
} else {
|
|
497
|
+
return []
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (!isSyntacticallyValidPropertyValue(value)) {
|
|
502
|
+
return []
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
let extras = {
|
|
506
|
+
get modifier() {
|
|
507
|
+
if (!options.modifiers) {
|
|
508
|
+
log.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
509
|
+
'Your plugin must set `modifiers: true` in its options to support modifiers.',
|
|
510
|
+
])
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return utilityModifier
|
|
514
|
+
},
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
518
|
+
|
|
519
|
+
let ruleSets = []
|
|
520
|
+
.concat(modifiersEnabled ? rule(value, extras) : rule(value))
|
|
521
|
+
.filter(Boolean)
|
|
522
|
+
.map((declaration) => ({
|
|
523
|
+
[nameClass(identifier, modifier)]: declaration,
|
|
524
|
+
}))
|
|
525
|
+
|
|
526
|
+
return ruleSets
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
let withOffsets = [{ sort: offset, layer: 'components', options }, wrapped]
|
|
530
|
+
|
|
531
|
+
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
532
|
+
context.candidateRuleMap.set(prefixedIdentifier, [])
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
addVariant(variantName, variantFunctions, options = {}) {
|
|
539
|
+
variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
|
|
540
|
+
if (typeof variantFunction !== 'string') {
|
|
541
|
+
// Safelist public API functions
|
|
542
|
+
return (api = {}) => {
|
|
543
|
+
let { args, modifySelectors, container, separator, wrap, format } = api
|
|
544
|
+
let result = variantFunction(
|
|
545
|
+
Object.assign(
|
|
546
|
+
{ modifySelectors, container, separator },
|
|
547
|
+
options.type === VARIANT_TYPES.MatchVariant && { args, wrap, format }
|
|
548
|
+
)
|
|
549
|
+
)
|
|
550
|
+
|
|
551
|
+
if (typeof result === 'string' && !isValidVariantFormatString(result)) {
|
|
552
|
+
throw new Error(
|
|
553
|
+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (Array.isArray(result)) {
|
|
558
|
+
return result
|
|
559
|
+
.filter((variant) => typeof variant === 'string')
|
|
560
|
+
.map((variant) => parseVariant(variant))
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// result may be undefined with legacy variants that use APIs like `modifySelectors`
|
|
564
|
+
// result may also be a postcss node if someone was returning the result from `modifySelectors`
|
|
565
|
+
return result && typeof result === 'string' && parseVariant(result)(api)
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (!isValidVariantFormatString(variantFunction)) {
|
|
570
|
+
throw new Error(
|
|
571
|
+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
|
|
572
|
+
)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return parseVariant(variantFunction)
|
|
576
|
+
})
|
|
577
|
+
|
|
578
|
+
insertInto(variantList, variantName, options)
|
|
579
|
+
variantMap.set(variantName, variantFunctions)
|
|
580
|
+
context.variantOptions.set(variantName, options)
|
|
581
|
+
},
|
|
582
|
+
matchVariant(variant, variantFn, options) {
|
|
583
|
+
// A unique identifier that "groups" these variants together.
|
|
584
|
+
// This is for internal use only which is why it is not present in the types
|
|
585
|
+
let id = options?.id ?? ++variantIdentifier
|
|
586
|
+
let isSpecial = variant === '@'
|
|
587
|
+
|
|
588
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
589
|
+
|
|
590
|
+
for (let [key, value] of Object.entries(options?.values ?? {})) {
|
|
591
|
+
if (key === 'DEFAULT') continue
|
|
592
|
+
|
|
593
|
+
api.addVariant(
|
|
594
|
+
isSpecial ? `${variant}${key}` : `${variant}-${key}`,
|
|
595
|
+
({ args, container }) => {
|
|
596
|
+
return variantFn(
|
|
597
|
+
value,
|
|
598
|
+
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
|
|
599
|
+
)
|
|
600
|
+
},
|
|
601
|
+
|
|
602
|
+
{
|
|
603
|
+
...options,
|
|
604
|
+
value,
|
|
605
|
+
id,
|
|
606
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
607
|
+
variantInfo: VARIANT_INFO.Base,
|
|
608
|
+
}
|
|
609
|
+
)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
let hasDefault = 'DEFAULT' in (options?.values ?? {})
|
|
613
|
+
|
|
614
|
+
api.addVariant(
|
|
615
|
+
variant,
|
|
616
|
+
({ args, container }) => {
|
|
617
|
+
if (args?.value === sharedState.NONE && !hasDefault) {
|
|
618
|
+
return null
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return variantFn(
|
|
622
|
+
args?.value === sharedState.NONE
|
|
623
|
+
? options.values.DEFAULT
|
|
624
|
+
: // Falling back to args if it is a string, otherwise '' for older intellisense
|
|
625
|
+
// (JetBrains) plugins.
|
|
626
|
+
args?.value ?? (typeof args === 'string' ? args : ''),
|
|
627
|
+
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
|
|
628
|
+
)
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
...options,
|
|
632
|
+
id,
|
|
633
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
634
|
+
variantInfo: VARIANT_INFO.Dynamic,
|
|
635
|
+
}
|
|
636
|
+
)
|
|
637
|
+
},
|
|
356
638
|
}
|
|
639
|
+
|
|
640
|
+
return api
|
|
357
641
|
}
|
|
358
642
|
|
|
359
643
|
let fileModifiedMapCache = new WeakMap()
|
|
@@ -366,6 +650,7 @@ export function getFileModifiedMap(context) {
|
|
|
366
650
|
|
|
367
651
|
function trackModified(files, fileModifiedMap) {
|
|
368
652
|
let changed = false
|
|
653
|
+
let mtimesToCommit = new Map()
|
|
369
654
|
|
|
370
655
|
for (let file of files) {
|
|
371
656
|
if (!file) continue
|
|
@@ -373,16 +658,23 @@ function trackModified(files, fileModifiedMap) {
|
|
|
373
658
|
let parsed = url.parse(file)
|
|
374
659
|
let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href
|
|
375
660
|
pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname
|
|
376
|
-
let newModified = fs.statSync(decodeURIComponent(pathname))
|
|
661
|
+
let newModified = fs.statSync(decodeURIComponent(pathname), { throwIfNoEntry: false })?.mtimeMs
|
|
662
|
+
if (!newModified) {
|
|
663
|
+
// It could happen that a file is passed in that doesn't exist. E.g.:
|
|
664
|
+
// postcss-cli will provide you a fake path when reading from stdin. This
|
|
665
|
+
// path then looks like /path-to-your-project/stdin In that case we just
|
|
666
|
+
// want to ignore it and don't track changes at all.
|
|
667
|
+
continue
|
|
668
|
+
}
|
|
377
669
|
|
|
378
670
|
if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
|
|
379
671
|
changed = true
|
|
380
672
|
}
|
|
381
673
|
|
|
382
|
-
|
|
674
|
+
mtimesToCommit.set(file, newModified)
|
|
383
675
|
}
|
|
384
676
|
|
|
385
|
-
return changed
|
|
677
|
+
return [changed, mtimesToCommit]
|
|
386
678
|
}
|
|
387
679
|
|
|
388
680
|
function extractVariantAtRules(node) {
|
|
@@ -419,34 +711,25 @@ function collectLayerPlugins(root) {
|
|
|
419
711
|
} else if (layerRule.params === 'components') {
|
|
420
712
|
for (let node of layerRule.nodes) {
|
|
421
713
|
layerPlugins.push(function ({ addComponents }) {
|
|
422
|
-
addComponents(node, { respectPrefix: false })
|
|
714
|
+
addComponents(node, { respectPrefix: false, preserveSource: true })
|
|
423
715
|
})
|
|
424
716
|
}
|
|
425
717
|
layerRule.remove()
|
|
426
718
|
} else if (layerRule.params === 'utilities') {
|
|
427
719
|
for (let node of layerRule.nodes) {
|
|
428
720
|
layerPlugins.push(function ({ addUtilities }) {
|
|
429
|
-
addUtilities(node, { respectPrefix: false })
|
|
721
|
+
addUtilities(node, { respectPrefix: false, preserveSource: true })
|
|
430
722
|
})
|
|
431
723
|
}
|
|
432
724
|
layerRule.remove()
|
|
433
725
|
}
|
|
434
726
|
})
|
|
435
727
|
|
|
436
|
-
root.walkRules((rule) => {
|
|
437
|
-
// At this point it is safe to include all the left-over css from the
|
|
438
|
-
// user's css file. This is because the `@tailwind` and `@layer` directives
|
|
439
|
-
// will already be handled and will be removed from the css tree.
|
|
440
|
-
layerPlugins.push(function ({ addUserCss }) {
|
|
441
|
-
addUserCss(rule, { respectPrefix: false })
|
|
442
|
-
})
|
|
443
|
-
})
|
|
444
|
-
|
|
445
728
|
return layerPlugins
|
|
446
729
|
}
|
|
447
730
|
|
|
448
|
-
function resolvePlugins(context,
|
|
449
|
-
let corePluginList = Object.entries(corePlugins)
|
|
731
|
+
function resolvePlugins(context, root) {
|
|
732
|
+
let corePluginList = Object.entries({ ...variantPlugins, ...corePlugins })
|
|
450
733
|
.map(([name, plugin]) => {
|
|
451
734
|
if (!context.tailwindConfig.corePlugins.includes(name)) {
|
|
452
735
|
return null
|
|
@@ -464,16 +747,25 @@ function resolvePlugins(context, tailwindDirectives, root) {
|
|
|
464
747
|
return typeof plugin === 'function' ? plugin : plugin.handler
|
|
465
748
|
})
|
|
466
749
|
|
|
467
|
-
let layerPlugins = collectLayerPlugins(root
|
|
750
|
+
let layerPlugins = collectLayerPlugins(root)
|
|
468
751
|
|
|
469
752
|
// TODO: This is a workaround for backwards compatibility, since custom variants
|
|
470
753
|
// were historically sorted before screen/stackable variants.
|
|
471
|
-
let beforeVariants = [
|
|
754
|
+
let beforeVariants = [
|
|
755
|
+
variantPlugins['pseudoElementVariants'],
|
|
756
|
+
variantPlugins['pseudoClassVariants'],
|
|
757
|
+
variantPlugins['ariaVariants'],
|
|
758
|
+
variantPlugins['dataVariants'],
|
|
759
|
+
]
|
|
472
760
|
let afterVariants = [
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
761
|
+
variantPlugins['supportsVariants'],
|
|
762
|
+
variantPlugins['directionVariants'],
|
|
763
|
+
variantPlugins['reducedMotionVariants'],
|
|
764
|
+
variantPlugins['prefersContrastVariants'],
|
|
765
|
+
variantPlugins['darkVariants'],
|
|
766
|
+
variantPlugins['printVariant'],
|
|
767
|
+
variantPlugins['screenVariants'],
|
|
768
|
+
variantPlugins['orientationVariants'],
|
|
477
769
|
]
|
|
478
770
|
|
|
479
771
|
return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
|
|
@@ -482,12 +774,10 @@ function resolvePlugins(context, tailwindDirectives, root) {
|
|
|
482
774
|
function registerPlugins(plugins, context) {
|
|
483
775
|
let variantList = []
|
|
484
776
|
let variantMap = new Map()
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
user: 0n,
|
|
490
|
-
}
|
|
777
|
+
context.variantMap = variantMap
|
|
778
|
+
|
|
779
|
+
let offsets = new Offsets()
|
|
780
|
+
context.offsets = offsets
|
|
491
781
|
|
|
492
782
|
let classList = new Set()
|
|
493
783
|
|
|
@@ -508,145 +798,418 @@ function registerPlugins(plugins, context) {
|
|
|
508
798
|
}
|
|
509
799
|
}
|
|
510
800
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
offsets.components,
|
|
514
|
-
offsets.utilities,
|
|
515
|
-
offsets.user,
|
|
516
|
-
])
|
|
517
|
-
let reservedBits = BigInt(highestOffset.toString(2).length)
|
|
518
|
-
|
|
519
|
-
context.layerOrder = {
|
|
520
|
-
base: (1n << reservedBits) << 0n,
|
|
521
|
-
components: (1n << reservedBits) << 1n,
|
|
522
|
-
utilities: (1n << reservedBits) << 2n,
|
|
523
|
-
user: (1n << reservedBits) << 3n,
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
reservedBits += 4n
|
|
527
|
-
|
|
528
|
-
let offset = 0
|
|
529
|
-
context.variantOrder = new Map(
|
|
530
|
-
variantList
|
|
531
|
-
.map((variant, i) => {
|
|
532
|
-
let variantFunctions = variantMap.get(variant).length
|
|
533
|
-
let bits = (1n << BigInt(i + offset)) << reservedBits
|
|
534
|
-
offset += variantFunctions - 1
|
|
535
|
-
return [variant, bits]
|
|
536
|
-
})
|
|
537
|
-
.sort(([, a], [, z]) => bigSign(a - z))
|
|
538
|
-
)
|
|
539
|
-
|
|
540
|
-
context.minimumScreen = [...context.variantOrder.values()].shift()
|
|
801
|
+
// Make sure to record bit masks for every variant
|
|
802
|
+
offsets.recordVariants(variantList, (variant) => variantMap.get(variant).length)
|
|
541
803
|
|
|
542
804
|
// Build variantMap
|
|
543
805
|
for (let [variantName, variantFunctions] of variantMap.entries()) {
|
|
544
|
-
let sort = context.variantOrder.get(variantName)
|
|
545
806
|
context.variantMap.set(
|
|
546
807
|
variantName,
|
|
547
|
-
variantFunctions.map((variantFunction, idx) => [
|
|
808
|
+
variantFunctions.map((variantFunction, idx) => [
|
|
809
|
+
offsets.forVariant(variantName, idx),
|
|
810
|
+
variantFunction,
|
|
811
|
+
])
|
|
548
812
|
)
|
|
549
813
|
}
|
|
550
814
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
context.safelist = function () {
|
|
554
|
-
let safelist = (context.tailwindConfig.safelist ?? []).filter(Boolean)
|
|
555
|
-
if (safelist.length <= 0) return []
|
|
556
|
-
|
|
557
|
-
let output = []
|
|
815
|
+
let safelist = (context.tailwindConfig.safelist ?? []).filter(Boolean)
|
|
816
|
+
if (safelist.length > 0) {
|
|
558
817
|
let checks = []
|
|
559
818
|
|
|
560
819
|
for (let value of safelist) {
|
|
561
820
|
if (typeof value === 'string') {
|
|
562
|
-
|
|
821
|
+
context.changedContent.push({ content: value, extension: 'html' })
|
|
563
822
|
continue
|
|
564
823
|
}
|
|
565
824
|
|
|
566
825
|
if (value instanceof RegExp) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
])
|
|
573
|
-
warnedAbout.add('root-regex')
|
|
574
|
-
}
|
|
826
|
+
log.warn('root-regex', [
|
|
827
|
+
'Regular expressions in `safelist` work differently in Tailwind CSS v3.0.',
|
|
828
|
+
'Update your `safelist` configuration to eliminate this warning.',
|
|
829
|
+
'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
|
|
830
|
+
])
|
|
575
831
|
continue
|
|
576
832
|
}
|
|
577
833
|
|
|
578
834
|
checks.push(value)
|
|
579
835
|
}
|
|
580
836
|
|
|
581
|
-
if (checks.length
|
|
837
|
+
if (checks.length > 0) {
|
|
838
|
+
let patternMatchingCount = new Map()
|
|
839
|
+
let prefixLength = context.tailwindConfig.prefix.length
|
|
840
|
+
let checkImportantUtils = checks.some((check) => check.pattern.source.includes('!'))
|
|
841
|
+
|
|
842
|
+
for (let util of classList) {
|
|
843
|
+
let utils = Array.isArray(util)
|
|
844
|
+
? (() => {
|
|
845
|
+
let [utilName, options] = util
|
|
846
|
+
let values = Object.keys(options?.values ?? {})
|
|
847
|
+
let classes = values.map((value) => formatClass(utilName, value))
|
|
848
|
+
|
|
849
|
+
if (options?.supportsNegativeValues) {
|
|
850
|
+
// This is the normal negated version
|
|
851
|
+
// e.g. `-inset-1` or `-tw-inset-1`
|
|
852
|
+
classes = [...classes, ...classes.map((cls) => '-' + cls)]
|
|
853
|
+
|
|
854
|
+
// This is the negated version *after* the prefix
|
|
855
|
+
// e.g. `tw--inset-1`
|
|
856
|
+
// The prefix is already attached to util name
|
|
857
|
+
// So we add the negative after the prefix
|
|
858
|
+
classes = [
|
|
859
|
+
...classes,
|
|
860
|
+
...classes.map(
|
|
861
|
+
(cls) => cls.slice(0, prefixLength) + '-' + cls.slice(prefixLength)
|
|
862
|
+
),
|
|
863
|
+
]
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
if (options.types.some(({ type }) => type === 'color')) {
|
|
867
|
+
classes = [
|
|
868
|
+
...classes,
|
|
869
|
+
...classes.flatMap((cls) =>
|
|
870
|
+
Object.keys(context.tailwindConfig.theme.opacity).map(
|
|
871
|
+
(opacity) => `${cls}/${opacity}`
|
|
872
|
+
)
|
|
873
|
+
),
|
|
874
|
+
]
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if (checkImportantUtils && options?.respectImportant) {
|
|
878
|
+
classes = [...classes, ...classes.map((cls) => '!' + cls)]
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
return classes
|
|
882
|
+
})()
|
|
883
|
+
: [util]
|
|
884
|
+
|
|
885
|
+
for (let util of utils) {
|
|
886
|
+
for (let { pattern, variants = [] } of checks) {
|
|
887
|
+
// RegExp with the /g flag are stateful, so let's reset the last
|
|
888
|
+
// index pointer to reset the state.
|
|
889
|
+
pattern.lastIndex = 0
|
|
890
|
+
|
|
891
|
+
if (!patternMatchingCount.has(pattern)) {
|
|
892
|
+
patternMatchingCount.set(pattern, 0)
|
|
893
|
+
}
|
|
582
894
|
|
|
583
|
-
|
|
895
|
+
if (!pattern.test(util)) continue
|
|
584
896
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
let
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
for (let { pattern, variants = [] } of checks) {
|
|
595
|
-
// RegExp with the /g flag are stateful, so let's reset the last
|
|
596
|
-
// index pointer to reset the state.
|
|
597
|
-
pattern.lastIndex = 0
|
|
598
|
-
|
|
599
|
-
if (!patternMatchingCount.has(pattern)) {
|
|
600
|
-
patternMatchingCount.set(pattern, 0)
|
|
897
|
+
patternMatchingCount.set(pattern, patternMatchingCount.get(pattern) + 1)
|
|
898
|
+
|
|
899
|
+
context.changedContent.push({ content: util, extension: 'html' })
|
|
900
|
+
for (let variant of variants) {
|
|
901
|
+
context.changedContent.push({
|
|
902
|
+
content: variant + context.tailwindConfig.separator + util,
|
|
903
|
+
extension: 'html',
|
|
904
|
+
})
|
|
905
|
+
}
|
|
601
906
|
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
for (let [regex, count] of patternMatchingCount.entries()) {
|
|
911
|
+
if (count !== 0) continue
|
|
602
912
|
|
|
603
|
-
|
|
913
|
+
log.warn([
|
|
914
|
+
`The safelist pattern \`${regex}\` doesn't match any Tailwind CSS classes.`,
|
|
915
|
+
'Fix this pattern or remove it from your `safelist` configuration.',
|
|
916
|
+
'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
|
|
917
|
+
])
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
604
921
|
|
|
605
|
-
|
|
922
|
+
let darkClassName = [].concat(context.tailwindConfig.darkMode ?? 'media')[1] ?? 'dark'
|
|
606
923
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
924
|
+
// A list of utilities that are used by certain Tailwind CSS utilities but
|
|
925
|
+
// that don't exist on their own. This will result in them "not existing" and
|
|
926
|
+
// sorting could be weird since you still require them in order to make the
|
|
927
|
+
// host utilities work properly. (Thanks Biology)
|
|
928
|
+
let parasiteUtilities = [
|
|
929
|
+
prefix(context, darkClassName),
|
|
930
|
+
prefix(context, 'group'),
|
|
931
|
+
prefix(context, 'peer'),
|
|
932
|
+
]
|
|
933
|
+
context.getClassOrder = function getClassOrder(classes) {
|
|
934
|
+
// Non-util classes won't be generated, so we default them to null
|
|
935
|
+
let sortedClassNames = new Map(classes.map((className) => [className, null]))
|
|
936
|
+
|
|
937
|
+
// Sort all classes in order
|
|
938
|
+
// Non-tailwind classes won't be generated and will be left as `null`
|
|
939
|
+
let rules = generateRules(new Set(classes), context)
|
|
940
|
+
rules = context.offsets.sort(rules)
|
|
941
|
+
|
|
942
|
+
let idx = BigInt(parasiteUtilities.length)
|
|
943
|
+
|
|
944
|
+
for (const [, rule] of rules) {
|
|
945
|
+
sortedClassNames.set(rule.raws.tailwind.candidate, idx++)
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
return classes.map((className) => {
|
|
949
|
+
let order = sortedClassNames.get(className) ?? null
|
|
950
|
+
let parasiteIndex = parasiteUtilities.indexOf(className)
|
|
951
|
+
|
|
952
|
+
if (order === null && parasiteIndex !== -1) {
|
|
953
|
+
// This will make sure that it is at the very beginning of the
|
|
954
|
+
// `components` layer which technically means 'before any
|
|
955
|
+
// components'.
|
|
956
|
+
order = BigInt(parasiteIndex)
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
return [className, order]
|
|
960
|
+
})
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// Generate a list of strings for autocompletion purposes, e.g.
|
|
964
|
+
// ['uppercase', 'lowercase', ...]
|
|
965
|
+
context.getClassList = function getClassList() {
|
|
966
|
+
let output = []
|
|
967
|
+
|
|
968
|
+
for (let util of classList) {
|
|
969
|
+
if (Array.isArray(util)) {
|
|
970
|
+
let [utilName, options] = util
|
|
971
|
+
let negativeClasses = []
|
|
972
|
+
|
|
973
|
+
for (let [key, value] of Object.entries(options?.values ?? {})) {
|
|
974
|
+
// Ignore undefined and null values
|
|
975
|
+
if (value == null) {
|
|
976
|
+
continue
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
output.push(formatClass(utilName, key))
|
|
980
|
+
if (options?.supportsNegativeValues && negateValue(value)) {
|
|
981
|
+
negativeClasses.push(formatClass(utilName, `-${key}`))
|
|
610
982
|
}
|
|
611
983
|
}
|
|
984
|
+
|
|
985
|
+
output.push(...negativeClasses)
|
|
986
|
+
} else {
|
|
987
|
+
output.push(util)
|
|
612
988
|
}
|
|
613
989
|
}
|
|
614
990
|
|
|
615
|
-
|
|
616
|
-
|
|
991
|
+
return output
|
|
992
|
+
}
|
|
617
993
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
994
|
+
// Generate a list of available variants with meta information of the type of variant.
|
|
995
|
+
context.getVariants = function getVariants() {
|
|
996
|
+
let result = []
|
|
997
|
+
for (let [name, options] of context.variantOptions.entries()) {
|
|
998
|
+
if (options.variantInfo === VARIANT_INFO.Base) continue
|
|
999
|
+
|
|
1000
|
+
result.push({
|
|
1001
|
+
name,
|
|
1002
|
+
isArbitrary: options.type === Symbol.for('MATCH_VARIANT'),
|
|
1003
|
+
values: Object.keys(options.values ?? {}),
|
|
1004
|
+
hasDash: name !== '@',
|
|
1005
|
+
selectors({ modifier, value } = {}) {
|
|
1006
|
+
let candidate = '__TAILWIND_PLACEHOLDER__'
|
|
1007
|
+
|
|
1008
|
+
let rule = postcss.rule({ selector: `.${candidate}` })
|
|
1009
|
+
let container = postcss.root({ nodes: [rule.clone()] })
|
|
1010
|
+
|
|
1011
|
+
let before = container.toString()
|
|
1012
|
+
|
|
1013
|
+
let fns = (context.variantMap.get(name) ?? []).flatMap(([_, fn]) => fn)
|
|
1014
|
+
let formatStrings = []
|
|
1015
|
+
for (let fn of fns) {
|
|
1016
|
+
let localFormatStrings = []
|
|
1017
|
+
|
|
1018
|
+
let api = {
|
|
1019
|
+
args: { modifier, value: options.values?.[value] ?? value },
|
|
1020
|
+
separator: context.tailwindConfig.separator,
|
|
1021
|
+
modifySelectors(modifierFunction) {
|
|
1022
|
+
// Run the modifierFunction over each rule
|
|
1023
|
+
container.each((rule) => {
|
|
1024
|
+
if (rule.type !== 'rule') {
|
|
1025
|
+
return
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
rule.selectors = rule.selectors.map((selector) => {
|
|
1029
|
+
return modifierFunction({
|
|
1030
|
+
get className() {
|
|
1031
|
+
return getClassNameFromSelector(selector)
|
|
1032
|
+
},
|
|
1033
|
+
selector,
|
|
1034
|
+
})
|
|
1035
|
+
})
|
|
1036
|
+
})
|
|
1037
|
+
|
|
1038
|
+
return container
|
|
1039
|
+
},
|
|
1040
|
+
format(str) {
|
|
1041
|
+
localFormatStrings.push(str)
|
|
1042
|
+
},
|
|
1043
|
+
wrap(wrapper) {
|
|
1044
|
+
localFormatStrings.push(`@${wrapper.name} ${wrapper.params} { & }`)
|
|
1045
|
+
},
|
|
1046
|
+
container,
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
let ruleWithVariant = fn(api)
|
|
1050
|
+
if (localFormatStrings.length > 0) {
|
|
1051
|
+
formatStrings.push(localFormatStrings)
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
1055
|
+
for (let variantFunction of ruleWithVariant) {
|
|
1056
|
+
localFormatStrings = []
|
|
1057
|
+
variantFunction(api)
|
|
1058
|
+
formatStrings.push(localFormatStrings)
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// Reverse engineer the result of the `container`
|
|
1064
|
+
let manualFormatStrings = []
|
|
1065
|
+
let after = container.toString()
|
|
1066
|
+
|
|
1067
|
+
if (before !== after) {
|
|
1068
|
+
// Figure out all selectors
|
|
1069
|
+
container.walkRules((rule) => {
|
|
1070
|
+
let modified = rule.selector
|
|
1071
|
+
|
|
1072
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
1073
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
1074
|
+
// However, plugin authors probably also prepend or append certain
|
|
1075
|
+
// classes, pseudos, ids, ...
|
|
1076
|
+
let rebuiltBase = selectorParser((selectors) => {
|
|
1077
|
+
selectors.walkClasses((classNode) => {
|
|
1078
|
+
classNode.value = `${name}${context.tailwindConfig.separator}${classNode.value}`
|
|
1079
|
+
})
|
|
1080
|
+
}).processSync(modified)
|
|
1081
|
+
|
|
1082
|
+
// Now that we know the original selector, the new selector, and
|
|
1083
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
1084
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
1085
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
1086
|
+
//
|
|
1087
|
+
// E.g.:
|
|
1088
|
+
// variant: foo
|
|
1089
|
+
// selector: .markdown > p
|
|
1090
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
1091
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
1092
|
+
// format: .foo &
|
|
1093
|
+
manualFormatStrings.push(modified.replace(rebuiltBase, '&').replace(candidate, '&'))
|
|
1094
|
+
})
|
|
1095
|
+
|
|
1096
|
+
// Figure out all atrules
|
|
1097
|
+
container.walkAtRules((atrule) => {
|
|
1098
|
+
manualFormatStrings.push(`@${atrule.name} (${atrule.params}) { & }`)
|
|
1099
|
+
})
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
let isArbitraryVariant = !(value in (options.values ?? {}))
|
|
1103
|
+
|
|
1104
|
+
formatStrings = formatStrings.map((format) =>
|
|
1105
|
+
format.map((str) => ({
|
|
1106
|
+
format: str,
|
|
1107
|
+
isArbitraryVariant,
|
|
1108
|
+
}))
|
|
1109
|
+
)
|
|
1110
|
+
|
|
1111
|
+
manualFormatStrings = manualFormatStrings.map((format) => ({
|
|
1112
|
+
format,
|
|
1113
|
+
isArbitraryVariant,
|
|
1114
|
+
}))
|
|
1115
|
+
|
|
1116
|
+
let opts = {
|
|
1117
|
+
candidate,
|
|
1118
|
+
context,
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
let result = formatStrings.map((formats) =>
|
|
1122
|
+
finalizeSelector(`.${candidate}`, formatVariantSelector(formats, opts), opts)
|
|
1123
|
+
.replace(`.${candidate}`, '&')
|
|
1124
|
+
.replace('{ & }', '')
|
|
1125
|
+
.trim()
|
|
1126
|
+
)
|
|
1127
|
+
|
|
1128
|
+
if (manualFormatStrings.length > 0) {
|
|
1129
|
+
result.push(
|
|
1130
|
+
formatVariantSelector(manualFormatStrings, opts)
|
|
1131
|
+
.toString()
|
|
1132
|
+
.replace(`.${candidate}`, '&')
|
|
1133
|
+
)
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
return result
|
|
1137
|
+
},
|
|
1138
|
+
})
|
|
623
1139
|
}
|
|
624
1140
|
|
|
625
|
-
return
|
|
1141
|
+
return result
|
|
626
1142
|
}
|
|
627
1143
|
}
|
|
628
1144
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
1145
|
+
/**
|
|
1146
|
+
* Mark as class as retroactively invalid
|
|
1147
|
+
*
|
|
1148
|
+
*
|
|
1149
|
+
* @param {string} candidate
|
|
1150
|
+
*/
|
|
1151
|
+
function markInvalidUtilityCandidate(context, candidate) {
|
|
1152
|
+
if (!context.classCache.has(candidate)) {
|
|
1153
|
+
return
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// Mark this as not being a real utility
|
|
1157
|
+
context.notClassCache.add(candidate)
|
|
1158
|
+
|
|
1159
|
+
// Remove it from any candidate-specific caches
|
|
1160
|
+
context.classCache.delete(candidate)
|
|
1161
|
+
context.applyClassCache.delete(candidate)
|
|
1162
|
+
context.candidateRuleMap.delete(candidate)
|
|
1163
|
+
context.candidateRuleCache.delete(candidate)
|
|
1164
|
+
|
|
1165
|
+
// Ensure the stylesheet gets rebuilt
|
|
1166
|
+
context.stylesheetCache = null
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Mark as class as retroactively invalid
|
|
1171
|
+
*
|
|
1172
|
+
* @param {import('postcss').Node} node
|
|
1173
|
+
*/
|
|
1174
|
+
function markInvalidUtilityNode(context, node) {
|
|
1175
|
+
let candidate = node.raws.tailwind.candidate
|
|
1176
|
+
|
|
1177
|
+
if (!candidate) {
|
|
1178
|
+
return
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
for (const entry of context.ruleCache) {
|
|
1182
|
+
if (entry[1].raws.tailwind.candidate === candidate) {
|
|
1183
|
+
context.ruleCache.delete(entry)
|
|
1184
|
+
// context.postCssNodeCache.delete(node)
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
markInvalidUtilityCandidate(context, candidate)
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
export function createContext(tailwindConfig, changedContent = [], root = postcss.root()) {
|
|
635
1192
|
let context = {
|
|
636
1193
|
disposables: [],
|
|
637
1194
|
ruleCache: new Set(),
|
|
1195
|
+
candidateRuleCache: new Map(),
|
|
638
1196
|
classCache: new Map(),
|
|
639
1197
|
applyClassCache: new Map(),
|
|
640
|
-
|
|
1198
|
+
// Seed the not class cache with the blocklist (which is only strings)
|
|
1199
|
+
notClassCache: new Set(tailwindConfig.blocklist ?? []),
|
|
641
1200
|
postCssNodeCache: new Map(),
|
|
642
1201
|
candidateRuleMap: new Map(),
|
|
643
1202
|
tailwindConfig,
|
|
644
1203
|
changedContent: changedContent,
|
|
645
1204
|
variantMap: new Map(),
|
|
646
1205
|
stylesheetCache: null,
|
|
1206
|
+
variantOptions: new Map(),
|
|
1207
|
+
|
|
1208
|
+
markInvalidUtilityCandidate: (candidate) => markInvalidUtilityCandidate(context, candidate),
|
|
1209
|
+
markInvalidUtilityNode: (node) => markInvalidUtilityNode(context, node),
|
|
647
1210
|
}
|
|
648
1211
|
|
|
649
|
-
let resolvedPlugins = resolvePlugins(context,
|
|
1212
|
+
let resolvedPlugins = resolvePlugins(context, root)
|
|
650
1213
|
registerPlugins(resolvedPlugins, context)
|
|
651
1214
|
|
|
652
1215
|
return context
|
|
@@ -657,7 +1220,6 @@ let configContextMap = sharedState.configContextMap
|
|
|
657
1220
|
let contextSourcesMap = sharedState.contextSourcesMap
|
|
658
1221
|
|
|
659
1222
|
export function getContext(
|
|
660
|
-
tailwindDirectives,
|
|
661
1223
|
root,
|
|
662
1224
|
result,
|
|
663
1225
|
tailwindConfig,
|
|
@@ -682,15 +1244,17 @@ export function getContext(
|
|
|
682
1244
|
existingContext = context
|
|
683
1245
|
}
|
|
684
1246
|
|
|
1247
|
+
let cssDidChange = hasContentChanged(sourcePath, root)
|
|
1248
|
+
|
|
685
1249
|
// If there's already a context in the cache and we don't need to
|
|
686
1250
|
// reset the context, return the cached context.
|
|
687
1251
|
if (existingContext) {
|
|
688
|
-
let contextDependenciesChanged = trackModified(
|
|
1252
|
+
let [contextDependenciesChanged, mtimesToCommit] = trackModified(
|
|
689
1253
|
[...contextDependencies],
|
|
690
1254
|
getFileModifiedMap(existingContext)
|
|
691
1255
|
)
|
|
692
|
-
if (!contextDependenciesChanged) {
|
|
693
|
-
return [existingContext, false]
|
|
1256
|
+
if (!contextDependenciesChanged && !cssDidChange) {
|
|
1257
|
+
return [existingContext, false, mtimesToCommit]
|
|
694
1258
|
}
|
|
695
1259
|
}
|
|
696
1260
|
|
|
@@ -719,9 +1283,13 @@ export function getContext(
|
|
|
719
1283
|
|
|
720
1284
|
env.DEBUG && console.log('Setting up new context...')
|
|
721
1285
|
|
|
722
|
-
let context = createContext(tailwindConfig, [],
|
|
1286
|
+
let context = createContext(tailwindConfig, [], root)
|
|
1287
|
+
|
|
1288
|
+
Object.assign(context, {
|
|
1289
|
+
userConfigPath,
|
|
1290
|
+
})
|
|
723
1291
|
|
|
724
|
-
trackModified([...contextDependencies], getFileModifiedMap(context))
|
|
1292
|
+
let [, mtimesToCommit] = trackModified([...contextDependencies], getFileModifiedMap(context))
|
|
725
1293
|
|
|
726
1294
|
// ---
|
|
727
1295
|
|
|
@@ -736,5 +1304,5 @@ export function getContext(
|
|
|
736
1304
|
|
|
737
1305
|
contextSourcesMap.get(context).add(sourcePath)
|
|
738
1306
|
|
|
739
|
-
return [context, true]
|
|
1307
|
+
return [context, true, mtimesToCommit]
|
|
740
1308
|
}
|