tailwindcss 0.0.0-insiders.fb545bc → 0.0.0-insiders.fb796cd
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/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +4 -0
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +52 -0
- package/lib/cli/build/plugin.js +376 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +180 -0
- package/lib/cli/help/index.js +71 -0
- package/lib/cli/index.js +230 -0
- package/lib/cli/init/index.js +61 -0
- package/lib/cli-peer-dependencies.js +20 -7
- package/lib/cli.js +4 -703
- package/lib/corePluginList.js +10 -3
- package/lib/corePlugins.js +2322 -1835
- package/lib/css/preflight.css +8 -6
- package/lib/featureFlags.js +43 -27
- 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 +58 -4
- package/lib/lib/content.js +177 -0
- package/lib/lib/defaultExtractor.js +241 -0
- package/lib/lib/detectNesting.js +19 -10
- package/lib/lib/evaluateTailwindFunctions.js +118 -55
- package/lib/lib/expandApplyAtRules.js +458 -176
- package/lib/lib/expandTailwindAtRules.js +157 -156
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +533 -204
- package/lib/lib/getModuleDependencies.js +85 -36
- package/lib/lib/load-config.js +36 -0
- package/lib/lib/normalizeTailwindDirectives.js +43 -32
- package/lib/lib/offsets.js +304 -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 +89 -67
- package/lib/lib/setupContextUtils.js +754 -346
- package/lib/lib/setupTrackingContext.js +65 -72
- package/lib/lib/sharedState.js +68 -9
- package/lib/lib/substituteScreenAtRules.js +11 -9
- package/lib/oxide/cli/build/deps.js +81 -0
- package/lib/oxide/cli/build/index.js +51 -0
- package/lib/oxide/cli/build/plugin.js +373 -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 +214 -0
- package/lib/oxide/cli/init/index.js +50 -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 +19 -0
- package/lib/postcss-plugins/nesting/plugin.js +87 -0
- package/lib/processTailwindFeatures.js +36 -25
- package/lib/public/colors.js +269 -245
- package/lib/public/create-plugin.js +6 -4
- package/lib/public/default-config.js +7 -5
- package/lib/public/default-theme.js +7 -5
- package/lib/public/load-config.js +10 -0
- package/lib/public/resolve-config.js +8 -5
- package/lib/util/applyImportantSelector.js +22 -0
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +11 -6
- package/lib/util/cloneDeep.js +7 -6
- package/lib/util/cloneNodes.js +21 -3
- package/lib/util/color.js +64 -36
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -6
- package/lib/util/createUtilityPlugin.js +13 -15
- package/lib/util/dataTypes.js +143 -110
- package/lib/util/defaults.js +8 -5
- package/lib/util/escapeClassName.js +9 -6
- package/lib/util/escapeCommas.js +5 -2
- package/lib/util/flattenColorPalette.js +9 -12
- package/lib/util/formatVariantSelector.js +268 -113
- package/lib/util/getAllConfigs.js +30 -11
- package/lib/util/hashConfig.js +6 -3
- package/lib/util/isKeyframeRule.js +5 -2
- package/lib/util/isPlainObject.js +5 -2
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +23 -15
- package/lib/util/log.js +20 -14
- package/lib/util/nameClass.js +20 -9
- package/lib/util/negateValue.js +23 -8
- package/lib/util/normalizeConfig.js +140 -83
- package/lib/util/normalizeScreens.js +120 -11
- package/lib/util/parseAnimationValue.js +42 -40
- package/lib/util/parseBoxShadowValue.js +30 -23
- package/lib/util/parseDependency.js +38 -56
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +11 -8
- package/lib/util/pluginUtils.js +146 -68
- package/lib/util/prefixSelector.js +27 -11
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +98 -78
- package/lib/util/resolveConfigPath.js +25 -11
- package/lib/util/responsive.js +8 -5
- package/lib/util/splitAtTopLevelOnly.js +49 -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 +37 -29
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +23 -15
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/nesting/index.js +2 -12
- package/package.json +62 -50
- package/peers/index.js +11585 -8231
- package/plugin.d.ts +11 -0
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +105 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/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 +675 -236
- package/src/css/preflight.css +8 -6
- package/src/featureFlags.js +22 -9
- 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 +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 +502 -173
- package/src/lib/expandTailwindAtRules.js +112 -106
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +521 -146
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/load-config.ts +27 -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 +51 -30
- package/src/lib/setupContextUtils.js +677 -184
- package/src/lib/setupTrackingContext.js +50 -61
- package/src/lib/sharedState.js +61 -4
- 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 +19 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +43 -11
- package/src/util/dataTypes.js +54 -21
- package/src/util/formatVariantSelector.js +317 -101
- package/src/util/getAllConfigs.js +21 -2
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +8 -8
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +62 -6
- package/src/util/normalizeScreens.js +99 -4
- 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 +127 -24
- package/src/util/prefixSelector.js +30 -10
- 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 +13 -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} +183 -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 +373 -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 +347 -0
- package/types/index.d.ts +7 -0
- package/CHANGELOG.md +0 -1897
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { flagEnabled } from '../featureFlags'
|
|
1
2
|
import log, { dim } from './log'
|
|
2
3
|
|
|
3
4
|
export function normalizeConfig(config) {
|
|
@@ -56,9 +57,11 @@ export function normalizeConfig(config) {
|
|
|
56
57
|
|
|
57
58
|
// When `config.content` is an object
|
|
58
59
|
if (typeof config.content === 'object' && config.content !== null) {
|
|
59
|
-
// Only `files`, `extract
|
|
60
|
+
// Only `files`, `relative`, `extract`, and `transform` can exist in `config.content`
|
|
60
61
|
if (
|
|
61
|
-
Object.keys(config.content).some(
|
|
62
|
+
Object.keys(config.content).some(
|
|
63
|
+
(key) => !['files', 'relative', 'extract', 'transform'].includes(key)
|
|
64
|
+
)
|
|
62
65
|
) {
|
|
63
66
|
return false
|
|
64
67
|
}
|
|
@@ -112,6 +115,14 @@ export function normalizeConfig(config) {
|
|
|
112
115
|
) {
|
|
113
116
|
return false
|
|
114
117
|
}
|
|
118
|
+
|
|
119
|
+
// `config.content.relative` is optional and can be a boolean
|
|
120
|
+
if (
|
|
121
|
+
typeof config.content.relative !== 'boolean' &&
|
|
122
|
+
typeof config.content.relative !== 'undefined'
|
|
123
|
+
) {
|
|
124
|
+
return false
|
|
125
|
+
}
|
|
115
126
|
}
|
|
116
127
|
|
|
117
128
|
return true
|
|
@@ -124,7 +135,7 @@ export function normalizeConfig(config) {
|
|
|
124
135
|
log.warn('purge-deprecation', [
|
|
125
136
|
'The `purge`/`content` options have changed in Tailwind CSS v3.0.',
|
|
126
137
|
'Update your configuration file to eliminate this warning.',
|
|
127
|
-
|
|
138
|
+
'https://tailwindcss.com/docs/upgrade-guide#configure-content-sources',
|
|
128
139
|
])
|
|
129
140
|
}
|
|
130
141
|
|
|
@@ -140,12 +151,30 @@ export function normalizeConfig(config) {
|
|
|
140
151
|
return []
|
|
141
152
|
})()
|
|
142
153
|
|
|
154
|
+
// Normalize the `blocklist`
|
|
155
|
+
config.blocklist = (() => {
|
|
156
|
+
let { blocklist } = config
|
|
157
|
+
|
|
158
|
+
if (Array.isArray(blocklist)) {
|
|
159
|
+
if (blocklist.every((item) => typeof item === 'string')) {
|
|
160
|
+
return blocklist
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
log.warn('blocklist-invalid', [
|
|
164
|
+
'The `blocklist` option must be an array of strings.',
|
|
165
|
+
'https://tailwindcss.com/docs/content-configuration#discarding-classes',
|
|
166
|
+
])
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return []
|
|
170
|
+
})()
|
|
171
|
+
|
|
143
172
|
// Normalize prefix option
|
|
144
173
|
if (typeof config.prefix === 'function') {
|
|
145
174
|
log.warn('prefix-function', [
|
|
146
175
|
'As of Tailwind CSS v3.0, `prefix` cannot be a function.',
|
|
147
176
|
'Update `prefix` in your configuration to be a string to eliminate this warning.',
|
|
148
|
-
|
|
177
|
+
'https://tailwindcss.com/docs/upgrade-guide#prefix-cannot-be-a-function',
|
|
149
178
|
])
|
|
150
179
|
config.prefix = ''
|
|
151
180
|
} else {
|
|
@@ -154,6 +183,16 @@ export function normalizeConfig(config) {
|
|
|
154
183
|
|
|
155
184
|
// Normalize the `content`
|
|
156
185
|
config.content = {
|
|
186
|
+
relative: (() => {
|
|
187
|
+
let { content } = config
|
|
188
|
+
|
|
189
|
+
if (content?.relative) {
|
|
190
|
+
return content.relative
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return flagEnabled(config, 'relativeContentPathsByDefault')
|
|
194
|
+
})(),
|
|
195
|
+
|
|
157
196
|
files: (() => {
|
|
158
197
|
let { content, purge } = config
|
|
159
198
|
|
|
@@ -250,13 +289,30 @@ export function normalizeConfig(config) {
|
|
|
250
289
|
for (let file of config.content.files) {
|
|
251
290
|
if (typeof file === 'string' && /{([^,]*?)}/g.test(file)) {
|
|
252
291
|
log.warn('invalid-glob-braces', [
|
|
253
|
-
`The glob pattern ${dim(file)} in your
|
|
254
|
-
`
|
|
292
|
+
`The glob pattern ${dim(file)} in your Tailwind CSS configuration is invalid.`,
|
|
293
|
+
`Update it to ${dim(file.replace(/{([^,]*?)}/g, '$1'))} to silence this warning.`,
|
|
255
294
|
// TODO: Add https://tw.wtf/invalid-glob-braces
|
|
256
295
|
])
|
|
257
296
|
break
|
|
258
297
|
}
|
|
259
298
|
}
|
|
260
299
|
|
|
300
|
+
// Warn if the line-clamp plugin is installed
|
|
301
|
+
if (config.plugins.length > 0) {
|
|
302
|
+
let plugin
|
|
303
|
+
try {
|
|
304
|
+
plugin = require('@tailwindcss/line-clamp')
|
|
305
|
+
} catch {}
|
|
306
|
+
|
|
307
|
+
if (plugin && config.plugins.includes(plugin)) {
|
|
308
|
+
log.warn('line-clamp-in-core', [
|
|
309
|
+
'As of Tailwind CSS v3.3, the `@tailwindcss/line-clamp` plugin is now included by default.',
|
|
310
|
+
'Remove it from the `plugins` array in your configuration to eliminate this warning.',
|
|
311
|
+
])
|
|
312
|
+
|
|
313
|
+
config.plugins = config.plugins.filter((p) => p !== plugin)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
261
317
|
return config
|
|
262
318
|
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} ScreenValue
|
|
3
|
+
* @property {number|undefined} min
|
|
4
|
+
* @property {number|undefined} max
|
|
5
|
+
* @property {string|undefined} raw
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {object} Screen
|
|
10
|
+
* @property {string} name
|
|
11
|
+
* @property {boolean} not
|
|
12
|
+
* @property {ScreenValue[]} values
|
|
13
|
+
*/
|
|
14
|
+
|
|
1
15
|
/**
|
|
2
16
|
* A function that normalizes the various forms that the screens object can be
|
|
3
17
|
* provided in.
|
|
@@ -10,6 +24,8 @@
|
|
|
10
24
|
*
|
|
11
25
|
* Output(s):
|
|
12
26
|
* - [{ name: 'sm', values: [{ min: '100px', max: '200px' }] }] // List of objects, that contains multiple values
|
|
27
|
+
*
|
|
28
|
+
* @returns {Screen[]}
|
|
13
29
|
*/
|
|
14
30
|
export function normalizeScreens(screens, root = true) {
|
|
15
31
|
if (Array.isArray(screens)) {
|
|
@@ -19,27 +35,106 @@ export function normalizeScreens(screens, root = true) {
|
|
|
19
35
|
}
|
|
20
36
|
|
|
21
37
|
if (typeof screen === 'string') {
|
|
22
|
-
return { name: screen.toString(), values: [{ min: screen, max: undefined }] }
|
|
38
|
+
return { name: screen.toString(), not: false, values: [{ min: screen, max: undefined }] }
|
|
23
39
|
}
|
|
24
40
|
|
|
25
41
|
let [name, options] = screen
|
|
26
42
|
name = name.toString()
|
|
27
43
|
|
|
28
44
|
if (typeof options === 'string') {
|
|
29
|
-
return { name, values: [{ min: options, max: undefined }] }
|
|
45
|
+
return { name, not: false, values: [{ min: options, max: undefined }] }
|
|
30
46
|
}
|
|
31
47
|
|
|
32
48
|
if (Array.isArray(options)) {
|
|
33
|
-
return { name, values: options.map((option) => resolveValue(option)) }
|
|
49
|
+
return { name, not: false, values: options.map((option) => resolveValue(option)) }
|
|
34
50
|
}
|
|
35
51
|
|
|
36
|
-
return { name, values: [resolveValue(options)] }
|
|
52
|
+
return { name, not: false, values: [resolveValue(options)] }
|
|
37
53
|
})
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
return normalizeScreens(Object.entries(screens ?? {}), false)
|
|
41
57
|
}
|
|
42
58
|
|
|
59
|
+
/**
|
|
60
|
+
* @param {Screen} screen
|
|
61
|
+
* @returns {{result: false, reason: string} | {result: true, reason: null}}
|
|
62
|
+
*/
|
|
63
|
+
export function isScreenSortable(screen) {
|
|
64
|
+
if (screen.values.length !== 1) {
|
|
65
|
+
return { result: false, reason: 'multiple-values' }
|
|
66
|
+
} else if (screen.values[0].raw !== undefined) {
|
|
67
|
+
return { result: false, reason: 'raw-values' }
|
|
68
|
+
} else if (screen.values[0].min !== undefined && screen.values[0].max !== undefined) {
|
|
69
|
+
return { result: false, reason: 'min-and-max' }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { result: true, reason: null }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {'min' | 'max'} type
|
|
77
|
+
* @param {Screen | 'string'} a
|
|
78
|
+
* @param {Screen | 'string'} z
|
|
79
|
+
* @returns {number}
|
|
80
|
+
*/
|
|
81
|
+
export function compareScreens(type, a, z) {
|
|
82
|
+
let aScreen = toScreen(a, type)
|
|
83
|
+
let zScreen = toScreen(z, type)
|
|
84
|
+
|
|
85
|
+
let aSorting = isScreenSortable(aScreen)
|
|
86
|
+
let bSorting = isScreenSortable(zScreen)
|
|
87
|
+
|
|
88
|
+
// These cases should never happen and indicate a bug in Tailwind CSS itself
|
|
89
|
+
if (aSorting.reason === 'multiple-values' || bSorting.reason === 'multiple-values') {
|
|
90
|
+
throw new Error(
|
|
91
|
+
'Attempted to sort a screen with multiple values. This should never happen. Please open a bug report.'
|
|
92
|
+
)
|
|
93
|
+
} else if (aSorting.reason === 'raw-values' || bSorting.reason === 'raw-values') {
|
|
94
|
+
throw new Error(
|
|
95
|
+
'Attempted to sort a screen with raw values. This should never happen. Please open a bug report.'
|
|
96
|
+
)
|
|
97
|
+
} else if (aSorting.reason === 'min-and-max' || bSorting.reason === 'min-and-max') {
|
|
98
|
+
throw new Error(
|
|
99
|
+
'Attempted to sort a screen with both min and max values. This should never happen. Please open a bug report.'
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Let the sorting begin
|
|
104
|
+
let { min: aMin, max: aMax } = aScreen.values[0]
|
|
105
|
+
let { min: zMin, max: zMax } = zScreen.values[0]
|
|
106
|
+
|
|
107
|
+
// Negating screens flip their behavior. Basically `not min-width` is `max-width`
|
|
108
|
+
if (a.not) [aMin, aMax] = [aMax, aMin]
|
|
109
|
+
if (z.not) [zMin, zMax] = [zMax, zMin]
|
|
110
|
+
|
|
111
|
+
aMin = aMin === undefined ? aMin : parseFloat(aMin)
|
|
112
|
+
aMax = aMax === undefined ? aMax : parseFloat(aMax)
|
|
113
|
+
zMin = zMin === undefined ? zMin : parseFloat(zMin)
|
|
114
|
+
zMax = zMax === undefined ? zMax : parseFloat(zMax)
|
|
115
|
+
|
|
116
|
+
let [aValue, zValue] = type === 'min' ? [aMin, zMin] : [zMax, aMax]
|
|
117
|
+
|
|
118
|
+
return aValue - zValue
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @param {PartialScreen> | string} value
|
|
124
|
+
* @param {'min' | 'max'} type
|
|
125
|
+
* @returns {Screen}
|
|
126
|
+
*/
|
|
127
|
+
export function toScreen(value, type) {
|
|
128
|
+
if (typeof value === 'object') {
|
|
129
|
+
return value
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
name: 'arbitrary-screen',
|
|
134
|
+
values: [{ [type]: value }],
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
43
138
|
function resolveValue({ 'min-width': _minWidth, min = _minWidth, max, raw } = {}) {
|
|
44
139
|
return { min, max, raw }
|
|
45
140
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
|
|
2
|
+
|
|
1
3
|
let KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
|
|
2
|
-
let COMMA = /\,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
|
|
3
4
|
let SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
|
4
|
-
let LENGTH = /^-?(\d+)(.*?)$/g
|
|
5
|
+
let LENGTH = /^-?(\d+|\.\d+)(.*?)$/g
|
|
5
6
|
|
|
6
7
|
export function parseBoxShadowValue(input) {
|
|
7
|
-
let shadows = input
|
|
8
|
+
let shadows = splitAtTopLevelOnly(input, ',')
|
|
8
9
|
return shadows.map((shadow) => {
|
|
9
10
|
let value = shadow.trim()
|
|
10
11
|
let result = { raw: value }
|
|
@@ -1,49 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (glob.substr(0, 2) === './') {
|
|
19
|
-
glob = glob.substr(2)
|
|
20
|
-
}
|
|
21
|
-
if (glob.charAt(0) === '/') {
|
|
22
|
-
glob = glob.substr(1)
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{type: 'dependency', file: string} | {type: 'dir-dependency', dir: string, glob: string}} Dependency
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {import('../lib/content.js').ContentPath} contentPath
|
|
10
|
+
* @returns {Dependency[]}
|
|
11
|
+
*/
|
|
12
|
+
export default function parseDependency(contentPath) {
|
|
13
|
+
if (contentPath.ignore) {
|
|
14
|
+
return []
|
|
23
15
|
}
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let message
|
|
34
|
-
|
|
35
|
-
if (isGlob(normalizedFileOrGlob)) {
|
|
36
|
-
let { base, glob } = parseGlob(normalizedFileOrGlob)
|
|
37
|
-
message = { type: 'dir-dependency', dir: path.resolve(base), glob }
|
|
38
|
-
} else {
|
|
39
|
-
message = { type: 'dependency', file: path.resolve(normalizedFileOrGlob) }
|
|
17
|
+
if (!contentPath.glob) {
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
type: 'dependency',
|
|
21
|
+
file: contentPath.base,
|
|
22
|
+
},
|
|
23
|
+
]
|
|
40
24
|
}
|
|
41
25
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
if (process.env.ROLLUP_WATCH === 'true') {
|
|
27
|
+
// rollup-plugin-postcss does not support dir-dependency messages
|
|
28
|
+
// but directories can be watched in the same way as files
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
type: 'dependency',
|
|
32
|
+
file: contentPath.base,
|
|
33
|
+
},
|
|
34
|
+
]
|
|
46
35
|
}
|
|
47
36
|
|
|
48
|
-
return
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
type: 'dir-dependency',
|
|
40
|
+
dir: contentPath.base,
|
|
41
|
+
glob: contentPath.glob,
|
|
42
|
+
},
|
|
43
|
+
]
|
|
49
44
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import globParent from 'glob-parent'
|
|
2
|
+
|
|
3
|
+
// Based on `glob-base`
|
|
4
|
+
// https://github.com/micromatch/glob-base/blob/master/index.js
|
|
5
|
+
export function parseGlob(pattern) {
|
|
6
|
+
let glob = pattern
|
|
7
|
+
let base = globParent(pattern)
|
|
8
|
+
|
|
9
|
+
if (base !== '.') {
|
|
10
|
+
glob = pattern.substr(base.length)
|
|
11
|
+
if (glob.charAt(0) === '/') {
|
|
12
|
+
glob = glob.substr(1)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (glob.substr(0, 2) === './') {
|
|
17
|
+
glob = glob.substr(2)
|
|
18
|
+
}
|
|
19
|
+
if (glob.charAt(0) === '/') {
|
|
20
|
+
glob = glob.substr(1)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { base, glob }
|
|
24
|
+
}
|
package/src/util/pluginUtils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import selectorParser from 'postcss-selector-parser'
|
|
2
1
|
import escapeCommas from './escapeCommas'
|
|
3
2
|
import { withAlphaValue } from './withAlphaVariable'
|
|
4
3
|
import {
|
|
@@ -18,21 +17,22 @@ import {
|
|
|
18
17
|
shadow,
|
|
19
18
|
} from './dataTypes'
|
|
20
19
|
import negateValue from './negateValue'
|
|
21
|
-
|
|
20
|
+
import { backgroundSize } from './validateFormalSyntax'
|
|
21
|
+
import { flagEnabled } from '../featureFlags.js'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {import('postcss-selector-parser').Container} selectors
|
|
25
|
+
* @param {(className: string) => string} updateClass
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
22
28
|
export function updateAllClasses(selectors, updateClass) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let updatedClass = updateClass(sel.value)
|
|
26
|
-
sel.value = updatedClass
|
|
27
|
-
if (sel.raws && sel.raws.value) {
|
|
28
|
-
sel.raws.value = escapeCommas(sel.raws.value)
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
let result = parser.processSync(selectors)
|
|
29
|
+
selectors.walkClasses((sel) => {
|
|
30
|
+
sel.value = updateClass(sel.value)
|
|
34
31
|
|
|
35
|
-
|
|
32
|
+
if (sel.raws && sel.raws.value) {
|
|
33
|
+
sel.raws.value = escapeCommas(sel.raws.value)
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function resolveArbitraryValue(modifier, validate) {
|
|
@@ -85,22 +85,51 @@ function isArbitraryValue(input) {
|
|
|
85
85
|
return input.startsWith('[') && input.endsWith(']')
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
function
|
|
88
|
+
function splitUtilityModifier(modifier) {
|
|
89
89
|
let slashIdx = modifier.lastIndexOf('/')
|
|
90
90
|
|
|
91
91
|
if (slashIdx === -1 || slashIdx === modifier.length - 1) {
|
|
92
|
-
return [modifier]
|
|
92
|
+
return [modifier, undefined]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let arbitrary = isArbitraryValue(modifier)
|
|
96
|
+
|
|
97
|
+
// The modifier could be of the form `[foo]/[bar]`
|
|
98
|
+
// We want to handle this case properly
|
|
99
|
+
// without affecting `[foo/bar]`
|
|
100
|
+
if (arbitrary && !modifier.includes(']/[')) {
|
|
101
|
+
return [modifier, undefined]
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
return [modifier.slice(0, slashIdx), modifier.slice(slashIdx + 1)]
|
|
96
105
|
}
|
|
97
106
|
|
|
107
|
+
export function parseColorFormat(value) {
|
|
108
|
+
if (typeof value === 'string' && value.includes('<alpha-value>')) {
|
|
109
|
+
let oldValue = value
|
|
110
|
+
|
|
111
|
+
return ({ opacityValue = 1 }) => oldValue.replace('<alpha-value>', opacityValue)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return value
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function unwrapArbitraryModifier(modifier) {
|
|
118
|
+
modifier = modifier.slice(1, -1)
|
|
119
|
+
if (modifier.startsWith('--')) {
|
|
120
|
+
modifier = `var(${modifier})`
|
|
121
|
+
}
|
|
122
|
+
return modifier
|
|
123
|
+
}
|
|
124
|
+
|
|
98
125
|
export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
|
|
99
126
|
if (options.values?.[modifier] !== undefined) {
|
|
100
|
-
return options.values?.[modifier]
|
|
127
|
+
return parseColorFormat(options.values?.[modifier])
|
|
101
128
|
}
|
|
102
129
|
|
|
103
|
-
|
|
130
|
+
// TODO: Hoist this up to getMatchingTypes or something
|
|
131
|
+
// We do this here because we need the alpha value (if any)
|
|
132
|
+
let [color, alpha] = splitUtilityModifier(modifier)
|
|
104
133
|
|
|
105
134
|
if (alpha !== undefined) {
|
|
106
135
|
let normalizedColor =
|
|
@@ -110,8 +139,10 @@ export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
|
|
|
110
139
|
return undefined
|
|
111
140
|
}
|
|
112
141
|
|
|
142
|
+
normalizedColor = parseColorFormat(normalizedColor)
|
|
143
|
+
|
|
113
144
|
if (isArbitraryValue(alpha)) {
|
|
114
|
-
return withAlphaValue(normalizedColor, alpha
|
|
145
|
+
return withAlphaValue(normalizedColor, unwrapArbitraryModifier(alpha))
|
|
115
146
|
}
|
|
116
147
|
|
|
117
148
|
if (tailwindConfig.theme?.opacity?.[alpha] === undefined) {
|
|
@@ -134,7 +165,7 @@ function guess(validate) {
|
|
|
134
165
|
}
|
|
135
166
|
}
|
|
136
167
|
|
|
137
|
-
let typeMap = {
|
|
168
|
+
export let typeMap = {
|
|
138
169
|
any: asValue,
|
|
139
170
|
color: asColor,
|
|
140
171
|
url: guess(url),
|
|
@@ -150,6 +181,7 @@ let typeMap = {
|
|
|
150
181
|
'absolute-size': guess(absoluteSize),
|
|
151
182
|
'relative-size': guess(relativeSize),
|
|
152
183
|
shadow: guess(shadow),
|
|
184
|
+
size: guess(backgroundSize),
|
|
153
185
|
}
|
|
154
186
|
|
|
155
187
|
let supportedTypes = Object.keys(typeMap)
|
|
@@ -161,6 +193,20 @@ function splitAtFirst(input, delim) {
|
|
|
161
193
|
}
|
|
162
194
|
|
|
163
195
|
export function coerceValue(types, modifier, options, tailwindConfig) {
|
|
196
|
+
if (options.values && modifier in options.values) {
|
|
197
|
+
for (let { type } of types ?? []) {
|
|
198
|
+
let result = typeMap[type](modifier, options, {
|
|
199
|
+
tailwindConfig,
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
if (result === undefined) {
|
|
203
|
+
continue
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return [result, type, null]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
164
210
|
if (isArbitraryValue(modifier)) {
|
|
165
211
|
let arbitraryValue = modifier.slice(1, -1)
|
|
166
212
|
let [explicitType, value] = splitAtFirst(arbitraryValue, ':')
|
|
@@ -178,15 +224,72 @@ export function coerceValue(types, modifier, options, tailwindConfig) {
|
|
|
178
224
|
}
|
|
179
225
|
|
|
180
226
|
if (value.length > 0 && supportedTypes.includes(explicitType)) {
|
|
181
|
-
return [asValue(`[${value}]`, options), explicitType]
|
|
227
|
+
return [asValue(`[${value}]`, options), explicitType, null]
|
|
182
228
|
}
|
|
183
229
|
}
|
|
184
230
|
|
|
231
|
+
let matches = getMatchingTypes(types, modifier, options, tailwindConfig)
|
|
232
|
+
|
|
185
233
|
// Find first matching type
|
|
186
|
-
for (let
|
|
187
|
-
|
|
188
|
-
if (result) return [result, type]
|
|
234
|
+
for (let match of matches) {
|
|
235
|
+
return match
|
|
189
236
|
}
|
|
190
237
|
|
|
191
238
|
return []
|
|
192
239
|
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
*
|
|
243
|
+
* @param {{type: string}[]} types
|
|
244
|
+
* @param {string} rawModifier
|
|
245
|
+
* @param {any} options
|
|
246
|
+
* @param {any} tailwindConfig
|
|
247
|
+
* @returns {Iterator<[value: string, type: string, modifier: string | null]>}
|
|
248
|
+
*/
|
|
249
|
+
export function* getMatchingTypes(types, rawModifier, options, tailwindConfig) {
|
|
250
|
+
let modifiersEnabled = flagEnabled(tailwindConfig, 'generalizedModifiers')
|
|
251
|
+
|
|
252
|
+
let [modifier, utilityModifier] = splitUtilityModifier(rawModifier)
|
|
253
|
+
|
|
254
|
+
let canUseUtilityModifier =
|
|
255
|
+
modifiersEnabled &&
|
|
256
|
+
options.modifiers != null &&
|
|
257
|
+
(options.modifiers === 'any' ||
|
|
258
|
+
(typeof options.modifiers === 'object' &&
|
|
259
|
+
((utilityModifier && isArbitraryValue(utilityModifier)) ||
|
|
260
|
+
utilityModifier in options.modifiers)))
|
|
261
|
+
|
|
262
|
+
if (!canUseUtilityModifier) {
|
|
263
|
+
modifier = rawModifier
|
|
264
|
+
utilityModifier = undefined
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (utilityModifier !== undefined && modifier === '') {
|
|
268
|
+
modifier = 'DEFAULT'
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Check the full value first
|
|
272
|
+
// TODO: Move to asValue… somehow
|
|
273
|
+
if (utilityModifier !== undefined) {
|
|
274
|
+
if (typeof options.modifiers === 'object') {
|
|
275
|
+
let configValue = options.modifiers?.[utilityModifier] ?? null
|
|
276
|
+
if (configValue !== null) {
|
|
277
|
+
utilityModifier = configValue
|
|
278
|
+
} else if (isArbitraryValue(utilityModifier)) {
|
|
279
|
+
utilityModifier = unwrapArbitraryModifier(utilityModifier)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
for (let { type } of types ?? []) {
|
|
285
|
+
let result = typeMap[type](modifier, options, {
|
|
286
|
+
tailwindConfig,
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
if (result === undefined) {
|
|
290
|
+
continue
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
yield [result, type, utilityModifier ?? null]
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import parser from 'postcss-selector-parser'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @template {string | import('postcss-selector-parser').Root} T
|
|
5
|
+
*
|
|
6
|
+
* Prefix all classes in the selector with the given prefix
|
|
7
|
+
*
|
|
8
|
+
* It can take either a string or a selector AST and will return the same type
|
|
9
|
+
*
|
|
10
|
+
* @param {string} prefix
|
|
11
|
+
* @param {T} selector
|
|
12
|
+
* @param {boolean} prependNegative
|
|
13
|
+
* @returns {T}
|
|
14
|
+
*/
|
|
15
|
+
export default function (prefix, selector, prependNegative = false) {
|
|
16
|
+
if (prefix === '') {
|
|
17
|
+
return selector
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let ast = typeof selector === 'string' ? parser().astSync(selector) : selector
|
|
21
|
+
|
|
22
|
+
ast.walkClasses((classSelector) => {
|
|
23
|
+
let baseClass = classSelector.value
|
|
24
|
+
let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
|
|
25
|
+
|
|
26
|
+
classSelector.value = shouldPlaceNegativeBeforePrefix
|
|
27
|
+
? `-${prefix}${baseClass.slice(1)}`
|
|
28
|
+
: `${prefix}${baseClass}`
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return typeof selector === 'string' ? ast.toString() : ast
|
|
12
32
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function removes any uses of CSS variables used as an alpha channel
|
|
3
|
+
*
|
|
4
|
+
* This is required for selectors like `:visited` which do not allow
|
|
5
|
+
* changes in opacity or external control using CSS variables.
|
|
6
|
+
*
|
|
7
|
+
* @param {import('postcss').Container} container
|
|
8
|
+
* @param {string[]} toRemove
|
|
9
|
+
*/
|
|
10
|
+
export function removeAlphaVariables(container, toRemove) {
|
|
11
|
+
container.walkDecls((decl) => {
|
|
12
|
+
if (toRemove.includes(decl.prop)) {
|
|
13
|
+
decl.remove()
|
|
14
|
+
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
for (let varName of toRemove) {
|
|
19
|
+
if (decl.value.includes(`/ var(${varName})`)) {
|
|
20
|
+
decl.value = decl.value.replace(`/ var(${varName})`, '')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|