tailwindcss 0.0.0-insiders.ea139f2 → 0.0.0-insiders.ea4e1cd
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 -1
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -1
- package/defaultTheme.d.ts +4 -0
- package/defaultTheme.js +2 -1
- package/lib/cli/build/deps.js +62 -0
- package/lib/cli/build/index.js +54 -0
- package/lib/cli/build/plugin.js +378 -0
- package/lib/cli/build/utils.js +88 -0
- package/lib/cli/build/watching.js +182 -0
- package/lib/cli/help/index.js +73 -0
- package/lib/cli/index.js +230 -0
- package/lib/cli/init/index.js +63 -0
- package/lib/cli-peer-dependencies.js +28 -7
- package/lib/cli.js +4 -703
- package/lib/corePluginList.js +12 -3
- package/lib/corePlugins.js +2373 -1863
- package/lib/css/preflight.css +10 -8
- package/lib/featureFlags.js +49 -26
- package/lib/index.js +1 -31
- package/lib/lib/cacheInvalidation.js +92 -0
- package/lib/lib/collapseAdjacentRules.js +30 -10
- package/lib/lib/collapseDuplicateDeclarations.js +60 -4
- package/lib/lib/content.js +181 -0
- package/lib/lib/defaultExtractor.js +243 -0
- package/lib/lib/detectNesting.js +21 -10
- package/lib/lib/evaluateTailwindFunctions.js +115 -50
- package/lib/lib/expandApplyAtRules.js +467 -161
- package/lib/lib/expandTailwindAtRules.js +160 -133
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +553 -200
- package/lib/lib/getModuleDependencies.js +88 -37
- package/lib/lib/load-config.js +42 -0
- package/lib/lib/normalizeTailwindDirectives.js +46 -33
- package/lib/lib/offsets.js +306 -0
- package/lib/lib/partitionApplyAtRules.js +58 -0
- package/lib/lib/regex.js +74 -0
- package/lib/lib/remap-bitfield.js +89 -0
- package/lib/lib/resolveDefaultsAtRules.js +98 -58
- package/lib/lib/setupContextUtils.js +773 -321
- package/lib/lib/setupTrackingContext.js +70 -75
- package/lib/lib/sharedState.js +78 -10
- package/lib/lib/substituteScreenAtRules.js +14 -10
- package/lib/oxide/cli/build/deps.js +89 -0
- package/lib/oxide/cli/build/index.js +53 -0
- package/lib/oxide/cli/build/plugin.js +375 -0
- package/lib/oxide/cli/build/utils.js +87 -0
- package/lib/oxide/cli/build/watching.js +179 -0
- package/lib/oxide/cli/help/index.js +72 -0
- package/lib/oxide/cli/index.js +214 -0
- package/lib/oxide/cli/init/index.js +52 -0
- package/lib/oxide/cli.js +5 -0
- package/lib/oxide/postcss-plugin.js +2 -0
- package/lib/plugin.js +98 -0
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +21 -0
- package/lib/postcss-plugins/nesting/plugin.js +89 -0
- package/lib/processTailwindFeatures.js +39 -26
- package/lib/public/colors.js +272 -246
- package/lib/public/create-plugin.js +9 -5
- package/lib/public/default-config.js +10 -6
- package/lib/public/default-theme.js +10 -6
- package/lib/public/load-config.js +12 -0
- package/lib/public/resolve-config.js +11 -6
- package/lib/util/applyImportantSelector.js +36 -0
- package/lib/util/bigSign.js +6 -1
- package/lib/util/buildMediaQuery.js +13 -6
- package/lib/util/cloneDeep.js +9 -6
- package/lib/util/cloneNodes.js +23 -3
- package/lib/util/color.js +70 -38
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +7 -2
- package/lib/util/createPlugin.js +8 -6
- package/lib/util/createUtilityPlugin.js +16 -16
- package/lib/util/dataTypes.js +173 -108
- package/lib/util/defaults.js +14 -3
- package/lib/util/escapeClassName.js +13 -8
- package/lib/util/escapeCommas.js +7 -2
- package/lib/util/flattenColorPalette.js +11 -12
- package/lib/util/formatVariantSelector.js +228 -151
- package/lib/util/getAllConfigs.js +33 -12
- package/lib/util/hashConfig.js +9 -4
- package/lib/util/isKeyframeRule.js +7 -2
- package/lib/util/isPlainObject.js +7 -2
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
- package/lib/util/log.js +27 -13
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +139 -65
- package/lib/util/normalizeScreens.js +131 -11
- package/lib/util/parseAnimationValue.js +44 -40
- package/lib/util/parseBoxShadowValue.js +34 -23
- package/lib/util/parseDependency.js +39 -55
- package/lib/util/parseGlob.js +36 -0
- package/lib/util/parseObjectStyles.js +15 -10
- package/lib/util/pluginUtils.js +159 -69
- package/lib/util/prefixSelector.js +30 -12
- package/lib/util/pseudoElements.js +229 -0
- package/lib/util/removeAlphaVariables.js +31 -0
- package/lib/util/resolveConfig.js +97 -75
- package/lib/util/resolveConfigPath.js +30 -12
- package/lib/util/responsive.js +11 -6
- package/lib/util/splitAtTopLevelOnly.js +51 -0
- package/lib/util/tap.js +6 -1
- package/lib/util/toColorValue.js +7 -3
- package/lib/util/toPath.js +26 -3
- package/lib/util/transformThemeValue.js +40 -30
- package/lib/util/validateConfig.js +37 -0
- package/lib/util/validateFormalSyntax.js +26 -0
- package/lib/util/withAlphaVariable.js +27 -15
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/nesting/index.js +2 -12
- package/package.json +66 -57
- package/peers/index.js +75964 -55560
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.d.ts +12 -0
- package/resolveConfig.js +2 -1
- 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 +444 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +229 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +216 -0
- package/src/cli/init/index.js +79 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +4 -765
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +786 -306
- package/src/css/preflight.css +10 -8
- package/src/featureFlags.js +21 -5
- package/src/index.js +1 -34
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +66 -1
- package/src/lib/content.js +208 -0
- package/src/lib/defaultExtractor.js +217 -0
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +79 -8
- package/src/lib/expandApplyAtRules.js +515 -153
- package/src/lib/expandTailwindAtRules.js +115 -86
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +545 -147
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/load-config.ts +31 -0
- package/src/lib/normalizeTailwindDirectives.js +7 -1
- package/src/lib/offsets.js +373 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +59 -17
- package/src/lib/setupContextUtils.js +701 -175
- package/src/lib/setupTrackingContext.js +51 -62
- package/src/lib/sharedState.js +58 -7
- 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 +442 -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 +204 -0
- package/src/oxide/cli/init/index.ts +59 -0
- package/src/oxide/cli.ts +1 -0
- package/src/oxide/postcss-plugin.ts +1 -0
- package/src/plugin.js +107 -0
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +12 -2
- package/src/public/colors.js +22 -0
- package/src/public/default-config.js +1 -1
- package/src/public/default-theme.js +2 -2
- package/src/public/load-config.js +2 -0
- package/src/util/applyImportantSelector.js +27 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +44 -12
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +51 -16
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +264 -144
- package/src/util/getAllConfigs.js +21 -2
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +11 -7
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +57 -5
- package/src/util/normalizeScreens.js +105 -7
- package/src/util/parseBoxShadowValue.js +4 -3
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +123 -24
- package/src/util/prefixSelector.js +30 -10
- package/src/util/pseudoElements.js +170 -0
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +74 -26
- package/src/util/resolveConfigPath.js +12 -1
- package/src/util/splitAtTopLevelOnly.js +52 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +26 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/stubs/.gitignore +1 -0
- package/stubs/.prettierrc.json +6 -0
- package/stubs/{defaultConfig.stub.js → config.full.js} +206 -166
- package/stubs/postcss.config.js +6 -0
- package/stubs/tailwind.config.cjs +2 -0
- package/stubs/tailwind.config.js +2 -0
- package/stubs/tailwind.config.ts +3 -0
- package/types/config.d.ts +368 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +298 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +371 -0
- package/types/index.d.ts +7 -0
- package/CHANGELOG.md +0 -1843
- package/lib/constants.js +0 -37
- package/lib/lib/setupWatchingContext.js +0 -288
- package/nesting/plugin.js +0 -41
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/constants.js +0 -17
- package/src/lib/setupWatchingContext.js +0 -311
- /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
- /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
package/src/util/dataTypes.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import { parseColor } from './color'
|
|
2
2
|
import { parseBoxShadowValue } from './parseBoxShadowValue'
|
|
3
|
+
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
|
|
3
4
|
|
|
4
5
|
let cssFunctions = ['min', 'max', 'clamp', 'calc']
|
|
5
6
|
|
|
6
7
|
// Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
function isCSSFunction(value) {
|
|
10
|
+
return cssFunctions.some((fn) => new RegExp(`^${fn}\\(.*\\)`).test(value))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const placeholder = '--tw-placeholder'
|
|
14
|
+
const placeholderRe = new RegExp(placeholder, 'g')
|
|
10
15
|
|
|
11
16
|
// This is not a data type, but rather a function that can normalize the
|
|
12
17
|
// correct values.
|
|
13
18
|
export function normalize(value, isRoot = true) {
|
|
19
|
+
if (value.startsWith('--')) {
|
|
20
|
+
return `var(${value})`
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
// Keep raw strings if it starts with `url(`
|
|
15
24
|
if (value.includes('url(')) {
|
|
16
25
|
return value
|
|
@@ -40,12 +49,20 @@ export function normalize(value, isRoot = true) {
|
|
|
40
49
|
value = value.trim()
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
// Add spaces around operators inside calc() that do not follow an operator
|
|
52
|
+
// Add spaces around operators inside math functions like calc() that do not follow an operator
|
|
44
53
|
// or '('.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
value = value.replace(/(calc|min|max|clamp)\(.+\)/g, (match) => {
|
|
55
|
+
let vars = []
|
|
56
|
+
return match
|
|
57
|
+
.replace(/var\((--.+?)[,)]/g, (match, g1) => {
|
|
58
|
+
vars.push(g1)
|
|
59
|
+
return match.replace(g1, placeholder)
|
|
60
|
+
})
|
|
61
|
+
.replace(/(-?\d*\.?\d(?!\b-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ')
|
|
62
|
+
.replace(placeholderRe, () => vars.shift())
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
return value
|
|
49
66
|
}
|
|
50
67
|
|
|
51
68
|
export function url(value) {
|
|
@@ -53,13 +70,16 @@ export function url(value) {
|
|
|
53
70
|
}
|
|
54
71
|
|
|
55
72
|
export function number(value) {
|
|
56
|
-
return !isNaN(Number(value)) ||
|
|
73
|
+
return !isNaN(Number(value)) || isCSSFunction(value)
|
|
57
74
|
}
|
|
58
75
|
|
|
59
76
|
export function percentage(value) {
|
|
60
|
-
return
|
|
77
|
+
return (value.endsWith('%') && number(value.slice(0, -1))) || isCSSFunction(value)
|
|
61
78
|
}
|
|
62
79
|
|
|
80
|
+
// Please refer to MDN when updating this list:
|
|
81
|
+
// https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units
|
|
82
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries#container_query_length_units
|
|
63
83
|
let lengthUnits = [
|
|
64
84
|
'cm',
|
|
65
85
|
'mm',
|
|
@@ -73,17 +93,32 @@ let lengthUnits = [
|
|
|
73
93
|
'ch',
|
|
74
94
|
'rem',
|
|
75
95
|
'lh',
|
|
96
|
+
'rlh',
|
|
76
97
|
'vw',
|
|
77
98
|
'vh',
|
|
78
99
|
'vmin',
|
|
79
100
|
'vmax',
|
|
101
|
+
'vb',
|
|
102
|
+
'vi',
|
|
103
|
+
'svw',
|
|
104
|
+
'svh',
|
|
105
|
+
'lvw',
|
|
106
|
+
'lvh',
|
|
107
|
+
'dvw',
|
|
108
|
+
'dvh',
|
|
109
|
+
'cqw',
|
|
110
|
+
'cqh',
|
|
111
|
+
'cqi',
|
|
112
|
+
'cqb',
|
|
113
|
+
'cqmin',
|
|
114
|
+
'cqmax',
|
|
80
115
|
]
|
|
81
116
|
let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
|
|
82
117
|
export function length(value) {
|
|
83
118
|
return (
|
|
84
119
|
value === '0' ||
|
|
85
|
-
new RegExp(
|
|
86
|
-
|
|
120
|
+
new RegExp(`^[+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`).test(value) ||
|
|
121
|
+
isCSSFunction(value)
|
|
87
122
|
)
|
|
88
123
|
}
|
|
89
124
|
|
|
@@ -107,11 +142,11 @@ export function shadow(value) {
|
|
|
107
142
|
export function color(value) {
|
|
108
143
|
let colors = 0
|
|
109
144
|
|
|
110
|
-
let result = value
|
|
145
|
+
let result = splitAtTopLevelOnly(value, '_').every((part) => {
|
|
111
146
|
part = normalize(part)
|
|
112
147
|
|
|
113
148
|
if (part.startsWith('var(')) return true
|
|
114
|
-
if (parseColor(part) !== null) return colors++, true
|
|
149
|
+
if (parseColor(part, { loose: true }) !== null) return colors++, true
|
|
115
150
|
|
|
116
151
|
return false
|
|
117
152
|
})
|
|
@@ -122,7 +157,7 @@ export function color(value) {
|
|
|
122
157
|
|
|
123
158
|
export function image(value) {
|
|
124
159
|
let images = 0
|
|
125
|
-
let result = value
|
|
160
|
+
let result = splitAtTopLevelOnly(value, ',').every((part) => {
|
|
126
161
|
part = normalize(part)
|
|
127
162
|
|
|
128
163
|
if (part.startsWith('var(')) return true
|
|
@@ -163,7 +198,7 @@ export function gradient(value) {
|
|
|
163
198
|
let validPositions = new Set(['center', 'top', 'right', 'bottom', 'left'])
|
|
164
199
|
export function position(value) {
|
|
165
200
|
let positions = 0
|
|
166
|
-
let result = value
|
|
201
|
+
let result = splitAtTopLevelOnly(value, '_').every((part) => {
|
|
167
202
|
part = normalize(part)
|
|
168
203
|
|
|
169
204
|
if (part.startsWith('var(')) return true
|
|
@@ -181,7 +216,7 @@ export function position(value) {
|
|
|
181
216
|
|
|
182
217
|
export function familyName(value) {
|
|
183
218
|
let fonts = 0
|
|
184
|
-
let result = value
|
|
219
|
+
let result = splitAtTopLevelOnly(value, ',').every((part) => {
|
|
185
220
|
part = normalize(part)
|
|
186
221
|
|
|
187
222
|
if (part.startsWith('var(')) return true
|
package/src/util/defaults.js
CHANGED
|
@@ -2,34 +2,155 @@ import selectorParser from 'postcss-selector-parser'
|
|
|
2
2
|
import unescape from 'postcss-selector-parser/dist/util/unesc'
|
|
3
3
|
import escapeClassName from '../util/escapeClassName'
|
|
4
4
|
import prefixSelector from '../util/prefixSelector'
|
|
5
|
+
import { movePseudos } from './pseudoElements'
|
|
6
|
+
|
|
7
|
+
/** @typedef {import('postcss-selector-parser').Root} Root */
|
|
8
|
+
/** @typedef {import('postcss-selector-parser').Selector} Selector */
|
|
9
|
+
/** @typedef {import('postcss-selector-parser').Pseudo} Pseudo */
|
|
10
|
+
/** @typedef {import('postcss-selector-parser').Node} Node */
|
|
11
|
+
|
|
12
|
+
/** @typedef {{format: string, isArbitraryVariant: boolean}[]} RawFormats */
|
|
13
|
+
/** @typedef {import('postcss-selector-parser').Root} ParsedFormats */
|
|
14
|
+
/** @typedef {RawFormats | ParsedFormats} AcceptedFormats */
|
|
5
15
|
|
|
6
16
|
let MERGE = ':merge'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {RawFormats} formats
|
|
20
|
+
* @param {{context: any, candidate: string, base: string | null}} options
|
|
21
|
+
* @returns {ParsedFormats | null}
|
|
22
|
+
*/
|
|
23
|
+
export function formatVariantSelector(formats, { context, candidate }) {
|
|
24
|
+
let prefix = context?.tailwindConfig.prefix ?? ''
|
|
25
|
+
|
|
26
|
+
// Parse the format selector into an AST
|
|
27
|
+
let parsedFormats = formats.map((format) => {
|
|
28
|
+
let ast = selectorParser().astSync(format.format)
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
...format,
|
|
32
|
+
ast: format.isArbitraryVariant ? ast : prefixSelector(prefix, ast),
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// We start with the candidate selector
|
|
37
|
+
let formatAst = selectorParser.root({
|
|
38
|
+
nodes: [
|
|
39
|
+
selectorParser.selector({
|
|
40
|
+
nodes: [selectorParser.className({ value: escapeClassName(candidate) })],
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// And iteratively merge each format selector into the candidate selector
|
|
46
|
+
for (let { ast } of parsedFormats) {
|
|
47
|
+
// 1. Handle :merge() special pseudo-class
|
|
48
|
+
;[formatAst, ast] = handleMergePseudo(formatAst, ast)
|
|
49
|
+
|
|
50
|
+
// 2. Merge the format selector into the current selector AST
|
|
51
|
+
ast.walkNesting((nesting) => nesting.replaceWith(...formatAst.nodes[0].nodes))
|
|
52
|
+
|
|
53
|
+
// 3. Keep going!
|
|
54
|
+
formatAst = ast
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return formatAst
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Given any node in a selector this gets the "simple" selector it's a part of
|
|
62
|
+
* A simple selector is just a list of nodes without any combinators
|
|
63
|
+
* Technically :is(), :not(), :has(), etc… can have combinators but those are nested
|
|
64
|
+
* inside the relevant node and won't be picked up so they're fine to ignore
|
|
65
|
+
*
|
|
66
|
+
* @param {Node} node
|
|
67
|
+
* @returns {Node[]}
|
|
68
|
+
**/
|
|
69
|
+
function simpleSelectorForNode(node) {
|
|
70
|
+
/** @type {Node[]} */
|
|
71
|
+
let nodes = []
|
|
72
|
+
|
|
73
|
+
// Walk backwards until we hit a combinator node (or the start)
|
|
74
|
+
while (node.prev() && node.prev().type !== 'combinator') {
|
|
75
|
+
node = node.prev()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Now record all non-combinator nodes until we hit one (or the end)
|
|
79
|
+
while (node && node.type !== 'combinator') {
|
|
80
|
+
nodes.push(node)
|
|
81
|
+
node = node.next()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return nodes
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Resorts the nodes in a selector to ensure they're in the correct order
|
|
89
|
+
* Tags go before classes, and pseudo classes go after classes
|
|
90
|
+
*
|
|
91
|
+
* @param {Selector} sel
|
|
92
|
+
* @returns {Selector}
|
|
93
|
+
**/
|
|
94
|
+
function resortSelector(sel) {
|
|
95
|
+
sel.sort((a, b) => {
|
|
96
|
+
if (a.type === 'tag' && b.type === 'class') {
|
|
97
|
+
return -1
|
|
98
|
+
} else if (a.type === 'class' && b.type === 'tag') {
|
|
99
|
+
return 1
|
|
100
|
+
} else if (a.type === 'class' && b.type === 'pseudo' && b.value.startsWith('::')) {
|
|
101
|
+
return -1
|
|
102
|
+
} else if (a.type === 'pseudo' && a.value.startsWith('::') && b.type === 'class') {
|
|
103
|
+
return 1
|
|
24
104
|
}
|
|
25
105
|
|
|
26
|
-
|
|
106
|
+
return sel.index(a) - sel.index(b)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
return sel
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Remove extraneous selectors that do not include the base class/candidate
|
|
114
|
+
*
|
|
115
|
+
* Example:
|
|
116
|
+
* Given the utility `.a, .b { color: red}`
|
|
117
|
+
* Given the candidate `sm:b`
|
|
118
|
+
*
|
|
119
|
+
* The final selector should be `.sm\:b` and not `.a, .sm\:b`
|
|
120
|
+
*
|
|
121
|
+
* @param {Selector} ast
|
|
122
|
+
* @param {string} base
|
|
123
|
+
*/
|
|
124
|
+
export function eliminateIrrelevantSelectors(sel, base) {
|
|
125
|
+
let hasClassesMatchingCandidate = false
|
|
126
|
+
|
|
127
|
+
sel.walk((child) => {
|
|
128
|
+
if (child.type === 'class' && child.value === base) {
|
|
129
|
+
hasClassesMatchingCandidate = true
|
|
130
|
+
return false // Stop walking
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
if (!hasClassesMatchingCandidate) {
|
|
135
|
+
sel.remove()
|
|
27
136
|
}
|
|
28
137
|
|
|
29
|
-
|
|
138
|
+
// We do NOT recursively eliminate sub selectors that don't have the base class
|
|
139
|
+
// as this is NOT a safe operation. For example, if we have:
|
|
140
|
+
// `.space-x-2 > :not([hidden]) ~ :not([hidden])`
|
|
141
|
+
// We cannot remove the [hidden] from the :not() because it would change the
|
|
142
|
+
// meaning of the selector.
|
|
143
|
+
|
|
144
|
+
// TODO: Can we do this for :matches, :is, and :where?
|
|
30
145
|
}
|
|
31
146
|
|
|
32
|
-
|
|
147
|
+
/**
|
|
148
|
+
* @param {string} current
|
|
149
|
+
* @param {AcceptedFormats} formats
|
|
150
|
+
* @param {{context: any, candidate: string, base: string | null}} options
|
|
151
|
+
* @returns {string}
|
|
152
|
+
*/
|
|
153
|
+
export function finalizeSelector(current, formats, { context, candidate, base }) {
|
|
33
154
|
let separator = context?.tailwindConfig?.separator ?? ':'
|
|
34
155
|
|
|
35
156
|
// Split by the separator, but ignore the separator inside square brackets:
|
|
@@ -39,14 +160,10 @@ export function finalizeSelector(format, { selector, candidate, context }) {
|
|
|
39
160
|
// │ │ │ ╰── We will not split here
|
|
40
161
|
// ╰──┴─────┴─────────────── We will split here
|
|
41
162
|
//
|
|
42
|
-
|
|
43
|
-
let base = candidate.split(splitter).pop()
|
|
44
|
-
|
|
45
|
-
if (context?.tailwindConfig?.prefix) {
|
|
46
|
-
format = prefixSelector(context.tailwindConfig.prefix, format)
|
|
47
|
-
}
|
|
163
|
+
base = base ?? candidate.split(new RegExp(`\\${separator}(?![^[]*\\])`)).pop()
|
|
48
164
|
|
|
49
|
-
|
|
165
|
+
// Parse the selector into an AST
|
|
166
|
+
let selector = selectorParser().astSync(current)
|
|
50
167
|
|
|
51
168
|
// Normalize escaped classes, e.g.:
|
|
52
169
|
//
|
|
@@ -59,138 +176,141 @@ export function finalizeSelector(format, { selector, candidate, context }) {
|
|
|
59
176
|
// base in selector: bg-\\[rgb\\(255\\,0\\,0\\)\\]
|
|
60
177
|
// escaped base: bg-\\[rgb\\(255\\2c 0\\2c 0\\)\\]
|
|
61
178
|
//
|
|
62
|
-
selector
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
179
|
+
selector.walkClasses((node) => {
|
|
180
|
+
if (node.raws && node.value.includes(base)) {
|
|
181
|
+
node.raws.value = escapeClassName(unescape(node.raws.value))
|
|
182
|
+
}
|
|
183
|
+
})
|
|
67
184
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
185
|
+
// Remove extraneous selectors that do not include the base candidate
|
|
186
|
+
selector.each((sel) => eliminateIrrelevantSelectors(sel, base))
|
|
187
|
+
|
|
188
|
+
// If there are no formats that means there were no variants added to the candidate
|
|
189
|
+
// so we can just return the selector as-is
|
|
190
|
+
let formatAst = Array.isArray(formats)
|
|
191
|
+
? formatVariantSelector(formats, { context, candidate })
|
|
192
|
+
: formats
|
|
193
|
+
|
|
194
|
+
if (formatAst === null) {
|
|
195
|
+
return selector.toString()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
let simpleStart = selectorParser.comment({ value: '/*__simple__*/' })
|
|
199
|
+
let simpleEnd = selectorParser.comment({ value: '/*__simple__*/' })
|
|
71
200
|
|
|
72
201
|
// We can safely replace the escaped base now, since the `base` section is
|
|
73
202
|
// now in a normalized escaped value.
|
|
74
|
-
selector
|
|
203
|
+
selector.walkClasses((node) => {
|
|
204
|
+
if (node.value !== base) {
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let parent = node.parent
|
|
209
|
+
let formatNodes = formatAst.nodes[0].nodes
|
|
210
|
+
|
|
211
|
+
// Perf optimization: if the parent is a single class we can just replace it and be done
|
|
212
|
+
if (parent.nodes.length === 1) {
|
|
213
|
+
node.replaceWith(...formatNodes)
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let simpleSelector = simpleSelectorForNode(node)
|
|
218
|
+
parent.insertBefore(simpleSelector[0], simpleStart)
|
|
219
|
+
parent.insertAfter(simpleSelector[simpleSelector.length - 1], simpleEnd)
|
|
220
|
+
|
|
221
|
+
for (let child of formatNodes) {
|
|
222
|
+
parent.insertBefore(simpleSelector[0], child.clone())
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
node.remove()
|
|
226
|
+
|
|
227
|
+
// Re-sort the simple selector to ensure it's in the correct order
|
|
228
|
+
simpleSelector = simpleSelectorForNode(simpleStart)
|
|
229
|
+
let firstNode = parent.index(simpleStart)
|
|
230
|
+
|
|
231
|
+
parent.nodes.splice(
|
|
232
|
+
firstNode,
|
|
233
|
+
simpleSelector.length,
|
|
234
|
+
...resortSelector(selectorParser.selector({ nodes: simpleSelector })).nodes
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
simpleStart.remove()
|
|
238
|
+
simpleEnd.remove()
|
|
239
|
+
})
|
|
75
240
|
|
|
76
241
|
// Remove unnecessary pseudo selectors that we used as placeholders
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
})
|
|
242
|
+
selector.walkPseudos((p) => {
|
|
243
|
+
if (p.value === MERGE) {
|
|
244
|
+
p.replaceWith(p.nodes)
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// Move pseudo elements to the end of the selector (if necessary)
|
|
249
|
+
selector.each((sel) => movePseudos(sel))
|
|
86
250
|
|
|
87
|
-
|
|
88
|
-
// pseudo elements) because otherwise the selector will never work
|
|
89
|
-
// anyway.
|
|
90
|
-
//
|
|
91
|
-
// E.g.:
|
|
92
|
-
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
93
|
-
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
94
|
-
//
|
|
95
|
-
// `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
|
|
96
|
-
function collectPseudoElements(selector) {
|
|
97
|
-
let nodes = []
|
|
98
|
-
|
|
99
|
-
for (let node of selector.nodes) {
|
|
100
|
-
if (isPseudoElement(node)) {
|
|
101
|
-
nodes.push(node)
|
|
102
|
-
selector.removeChild(node)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (node?.nodes) {
|
|
106
|
-
nodes.push(...collectPseudoElements(node))
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return nodes
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let pseudoElements = collectPseudoElements(selector)
|
|
114
|
-
if (pseudoElements.length > 0) {
|
|
115
|
-
selector.nodes.push(pseudoElements.sort(sortSelector))
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return selector
|
|
119
|
-
})
|
|
120
|
-
}).processSync(selector)
|
|
251
|
+
return selector.toString()
|
|
121
252
|
}
|
|
122
253
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// for you by flipping the order.
|
|
142
|
-
function sortSelector(a, z) {
|
|
143
|
-
// Both nodes are non-pseudo's so we can safely ignore them and keep
|
|
144
|
-
// them in the same order.
|
|
145
|
-
if (a.type !== 'pseudo' && z.type !== 'pseudo') {
|
|
146
|
-
return 0
|
|
147
|
-
}
|
|
254
|
+
/**
|
|
255
|
+
*
|
|
256
|
+
* @param {Selector} selector
|
|
257
|
+
* @param {Selector} format
|
|
258
|
+
*/
|
|
259
|
+
export function handleMergePseudo(selector, format) {
|
|
260
|
+
/** @type {{pseudo: Pseudo, value: string}[]} */
|
|
261
|
+
let merges = []
|
|
262
|
+
|
|
263
|
+
// Find all :merge() pseudo-classes in `selector`
|
|
264
|
+
selector.walkPseudos((pseudo) => {
|
|
265
|
+
if (pseudo.value === MERGE) {
|
|
266
|
+
merges.push({
|
|
267
|
+
pseudo,
|
|
268
|
+
value: pseudo.nodes[0].toString(),
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
})
|
|
148
272
|
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
273
|
+
// Find all :merge() "attachments" in `format` and attach them to the matching selector in `selector`
|
|
274
|
+
format.walkPseudos((pseudo) => {
|
|
275
|
+
if (pseudo.value !== MERGE) {
|
|
276
|
+
return
|
|
277
|
+
}
|
|
154
278
|
|
|
155
|
-
|
|
156
|
-
// the pseudo to the right.
|
|
157
|
-
if ((a.type === 'pseudo') ^ (z.type === 'pseudo')) {
|
|
158
|
-
return (a.type === 'pseudo') - (z.type === 'pseudo')
|
|
159
|
-
}
|
|
279
|
+
let value = pseudo.nodes[0].toString()
|
|
160
280
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return isPseudoElement(a) - isPseudoElement(z)
|
|
164
|
-
}
|
|
281
|
+
// Does `selector` contain a :merge() pseudo-class with the same value?
|
|
282
|
+
let existing = merges.find((merge) => merge.value === value)
|
|
165
283
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
284
|
+
// Nope so there's nothing to do
|
|
285
|
+
if (!existing) {
|
|
286
|
+
return
|
|
287
|
+
}
|
|
169
288
|
|
|
170
|
-
|
|
171
|
-
|
|
289
|
+
// Everything after `:merge()` up to the next combinator is what is attached to the merged selector
|
|
290
|
+
let attachments = []
|
|
291
|
+
let next = pseudo.next()
|
|
292
|
+
while (next && next.type !== 'combinator') {
|
|
293
|
+
attachments.push(next)
|
|
294
|
+
next = next.next()
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let combinator = next
|
|
172
298
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
} else if (char === '(') {
|
|
187
|
-
target += char
|
|
188
|
-
count++
|
|
189
|
-
} else if (char === ')') {
|
|
190
|
-
if (--count < 0) break // unbalanced
|
|
191
|
-
target += char
|
|
299
|
+
existing.pseudo.parent.insertAfter(
|
|
300
|
+
existing.pseudo,
|
|
301
|
+
selectorParser.selector({ nodes: attachments.map((node) => node.clone()) })
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
pseudo.remove()
|
|
305
|
+
attachments.forEach((node) => node.remove())
|
|
306
|
+
|
|
307
|
+
// What about this case:
|
|
308
|
+
// :merge(.group):focus > &
|
|
309
|
+
// :merge(.group):hover &
|
|
310
|
+
if (combinator && combinator.type === 'combinator') {
|
|
311
|
+
combinator.remove()
|
|
192
312
|
}
|
|
193
|
-
}
|
|
313
|
+
})
|
|
194
314
|
|
|
195
|
-
return
|
|
315
|
+
return [selector, format]
|
|
196
316
|
}
|
|
@@ -1,14 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import defaultFullConfig from '../../stubs/config.full.js'
|
|
2
2
|
import { flagEnabled } from '../featureFlags'
|
|
3
3
|
|
|
4
4
|
export default function getAllConfigs(config) {
|
|
5
|
-
const configs = (config?.presets ?? [
|
|
5
|
+
const configs = (config?.presets ?? [defaultFullConfig])
|
|
6
6
|
.slice()
|
|
7
7
|
.reverse()
|
|
8
8
|
.flatMap((preset) => getAllConfigs(preset instanceof Function ? preset() : preset))
|
|
9
9
|
|
|
10
10
|
const features = {
|
|
11
11
|
// Add experimental configs here...
|
|
12
|
+
respectDefaultRingColorOpacity: {
|
|
13
|
+
theme: {
|
|
14
|
+
ringColor: ({ theme }) => ({
|
|
15
|
+
DEFAULT: '#3b82f67f',
|
|
16
|
+
...theme('colors'),
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
disableColorOpacityUtilitiesByDefault: {
|
|
22
|
+
corePlugins: {
|
|
23
|
+
backgroundOpacity: false,
|
|
24
|
+
borderOpacity: false,
|
|
25
|
+
divideOpacity: false,
|
|
26
|
+
placeholderOpacity: false,
|
|
27
|
+
ringOpacity: false,
|
|
28
|
+
textOpacity: false,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
12
31
|
}
|
|
13
32
|
|
|
14
33
|
const experimentals = Object.keys(features)
|
|
@@ -15,7 +15,7 @@ let quotes = new Set(['"', "'", '`'])
|
|
|
15
15
|
// E.g.: w-[this-is]w-[weird-and-invalid]
|
|
16
16
|
// E.g.: w-[this-is\\]w-\\[weird-but-valid]
|
|
17
17
|
// E.g.: content-['this-is-also-valid]-weirdly-enough']
|
|
18
|
-
export default function
|
|
18
|
+
export default function isSyntacticallyValidPropertyValue(value) {
|
|
19
19
|
let stack = []
|
|
20
20
|
let inQuotes = false
|
|
21
21
|
|