tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce
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/CHANGELOG.md +380 -1
- package/LICENSE +1 -2
- package/README.md +8 -4
- 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 +3 -0
- package/defaultTheme.js +2 -1
- package/lib/cli-peer-dependencies.js +10 -5
- package/lib/cli.js +311 -213
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +11 -1
- package/lib/corePlugins.js +1895 -1773
- package/lib/css/preflight.css +19 -13
- package/lib/featureFlags.js +22 -16
- package/lib/index.js +17 -8
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +30 -14
- package/lib/lib/collapseDuplicateDeclarations.js +80 -0
- package/lib/lib/defaultExtractor.js +187 -0
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +40 -24
- package/lib/lib/expandApplyAtRules.js +414 -157
- package/lib/lib/expandTailwindAtRules.js +156 -151
- package/lib/lib/generateRules.js +402 -68
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +45 -36
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/regex.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +105 -90
- package/lib/lib/setupContextUtils.js +416 -291
- package/lib/lib/setupTrackingContext.js +60 -56
- package/lib/lib/sharedState.js +38 -15
- package/lib/lib/substituteScreenAtRules.js +9 -6
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +21 -9
- package/lib/public/colors.js +244 -248
- package/lib/public/resolve-config.js +5 -5
- package/lib/util/buildMediaQuery.js +13 -24
- package/lib/util/cloneDeep.js +1 -1
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +43 -32
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +13 -17
- package/lib/util/dataTypes.js +114 -74
- package/lib/util/defaults.js +6 -0
- package/lib/util/escapeClassName.js +5 -5
- package/lib/util/escapeCommas.js +1 -1
- package/lib/util/flattenColorPalette.js +2 -4
- package/lib/util/formatVariantSelector.js +194 -0
- package/lib/util/getAllConfigs.js +13 -5
- package/lib/util/hashConfig.js +5 -5
- package/lib/util/isKeyframeRule.js +1 -1
- package/lib/util/isPlainObject.js +1 -1
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +35 -19
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +5 -3
- package/lib/util/normalizeConfig.js +233 -0
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseAnimationValue.js +56 -56
- package/lib/util/parseBoxShadowValue.js +76 -0
- package/lib/util/parseDependency.js +32 -32
- package/lib/util/parseObjectStyles.js +6 -6
- package/lib/util/pluginUtils.js +67 -170
- package/lib/util/prefixSelector.js +4 -7
- package/lib/util/resolveConfig.js +123 -133
- package/lib/util/resolveConfigPath.js +17 -18
- package/lib/util/responsive.js +6 -6
- package/lib/util/splitAtTopLevelOnly.js +72 -0
- package/lib/util/toColorValue.js +1 -2
- package/lib/util/toPath.js +6 -1
- package/lib/util/transformThemeValue.js +42 -34
- package/lib/util/validateConfig.js +21 -0
- package/lib/util/withAlphaVariable.js +19 -19
- package/nesting/index.js +2 -12
- package/package.json +41 -42
- package/peers/index.js +11539 -10859
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +52 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +174 -41
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +641 -596
- package/src/css/preflight.css +19 -13
- package/src/featureFlags.js +16 -10
- package/src/index.js +14 -6
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +93 -0
- package/src/lib/defaultExtractor.js +192 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +24 -7
- package/src/lib/expandApplyAtRules.js +442 -154
- package/src/lib/expandTailwindAtRules.js +91 -65
- package/src/lib/generateRules.js +409 -43
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +74 -53
- package/src/lib/setupContextUtils.js +388 -208
- package/src/lib/setupTrackingContext.js +15 -12
- package/src/lib/sharedState.js +42 -7
- package/src/lib/substituteScreenAtRules.js +6 -3
- 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 +17 -2
- package/src/public/colors.js +4 -9
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -2
- package/src/util/dataTypes.js +56 -16
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +213 -0
- package/src/util/getAllConfigs.js +7 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +2 -2
- package/src/util/negateValue.js +4 -2
- package/src/util/normalizeConfig.js +262 -0
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/pluginUtils.js +51 -147
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +108 -79
- package/src/util/splitAtTopLevelOnly.js +71 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +24 -7
- package/src/util/validateConfig.js +13 -0
- package/stubs/defaultConfig.stub.js +157 -94
- package/stubs/simpleConfig.stub.js +0 -1
- package/types/config.d.ts +325 -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/index.d.ts +1 -0
- package/types.d.ts +1 -0
- package/lib/lib/setupWatchingContext.js +0 -284
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -306
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
|
|
2
|
+
|
|
3
|
+
let KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
|
|
4
|
+
let SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
|
5
|
+
let LENGTH = /^-?(\d+|\.\d+)(.*?)$/g
|
|
6
|
+
|
|
7
|
+
export function parseBoxShadowValue(input) {
|
|
8
|
+
let shadows = Array.from(splitAtTopLevelOnly(input, ','))
|
|
9
|
+
return shadows.map((shadow) => {
|
|
10
|
+
let value = shadow.trim()
|
|
11
|
+
let result = { raw: value }
|
|
12
|
+
let parts = value.split(SPACE)
|
|
13
|
+
let seen = new Set()
|
|
14
|
+
|
|
15
|
+
for (let part of parts) {
|
|
16
|
+
// Reset index, since the regex is stateful.
|
|
17
|
+
LENGTH.lastIndex = 0
|
|
18
|
+
|
|
19
|
+
// Keyword
|
|
20
|
+
if (!seen.has('KEYWORD') && KEYWORDS.has(part)) {
|
|
21
|
+
result.keyword = part
|
|
22
|
+
seen.add('KEYWORD')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Length value
|
|
26
|
+
else if (LENGTH.test(part)) {
|
|
27
|
+
if (!seen.has('X')) {
|
|
28
|
+
result.x = part
|
|
29
|
+
seen.add('X')
|
|
30
|
+
} else if (!seen.has('Y')) {
|
|
31
|
+
result.y = part
|
|
32
|
+
seen.add('Y')
|
|
33
|
+
} else if (!seen.has('BLUR')) {
|
|
34
|
+
result.blur = part
|
|
35
|
+
seen.add('BLUR')
|
|
36
|
+
} else if (!seen.has('SPREAD')) {
|
|
37
|
+
result.spread = part
|
|
38
|
+
seen.add('SPREAD')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Color or unknown
|
|
43
|
+
else {
|
|
44
|
+
if (!result.color) {
|
|
45
|
+
result.color = part
|
|
46
|
+
} else {
|
|
47
|
+
if (!result.unknown) result.unknown = []
|
|
48
|
+
result.unknown.push(part)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Check if valid
|
|
54
|
+
result.valid = result.x !== undefined && result.y !== undefined
|
|
55
|
+
|
|
56
|
+
return result
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function formatBoxShadowValue(shadows) {
|
|
61
|
+
return shadows
|
|
62
|
+
.map((shadow) => {
|
|
63
|
+
if (!shadow.valid) {
|
|
64
|
+
return shadow.raw
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return [shadow.keyword, shadow.x, shadow.y, shadow.blur, shadow.spread, shadow.color]
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.join(' ')
|
|
70
|
+
})
|
|
71
|
+
.join(', ')
|
|
72
|
+
}
|
package/src/util/pluginUtils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import selectorParser from 'postcss-selector-parser'
|
|
2
2
|
import escapeCommas from './escapeCommas'
|
|
3
3
|
import { withAlphaValue } from './withAlphaVariable'
|
|
4
|
-
import isKeyframeRule from './isKeyframeRule'
|
|
5
4
|
import {
|
|
6
5
|
normalize,
|
|
7
6
|
length,
|
|
@@ -16,36 +15,14 @@ import {
|
|
|
16
15
|
relativeSize,
|
|
17
16
|
position,
|
|
18
17
|
lineWidth,
|
|
18
|
+
shadow,
|
|
19
19
|
} from './dataTypes'
|
|
20
|
-
|
|
21
|
-
export function applyStateToMarker(selector, marker, state, join) {
|
|
22
|
-
let markerIdx = selector.search(new RegExp(`${marker}[:[]`))
|
|
23
|
-
|
|
24
|
-
if (markerIdx === -1) {
|
|
25
|
-
return join(marker + state, selector)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let markerSelector = selector.slice(markerIdx, selector.indexOf(' ', markerIdx))
|
|
29
|
-
|
|
30
|
-
return join(
|
|
31
|
-
marker + state + markerSelector.slice(markerIdx + marker.length),
|
|
32
|
-
selector.replace(markerSelector, '')
|
|
33
|
-
)
|
|
34
|
-
}
|
|
20
|
+
import negateValue from './negateValue'
|
|
35
21
|
|
|
36
22
|
export function updateAllClasses(selectors, updateClass) {
|
|
37
23
|
let parser = selectorParser((selectors) => {
|
|
38
24
|
selectors.walkClasses((sel) => {
|
|
39
|
-
let updatedClass = updateClass(sel.value
|
|
40
|
-
withAttr(className, attr) {
|
|
41
|
-
sel.parent.insertAfter(sel, selectorParser.attribute({ attribute: attr.slice(1, -1) }))
|
|
42
|
-
return className
|
|
43
|
-
},
|
|
44
|
-
withPseudo(className, pseudo) {
|
|
45
|
-
sel.parent.insertAfter(sel, selectorParser.pseudo({ value: pseudo }))
|
|
46
|
-
return className
|
|
47
|
-
},
|
|
48
|
-
})
|
|
25
|
+
let updatedClass = updateClass(sel.value)
|
|
49
26
|
sel.value = updatedClass
|
|
50
27
|
if (sel.raws && sel.raws.value) {
|
|
51
28
|
sel.raws.value = escapeCommas(sel.raws.value)
|
|
@@ -58,133 +35,50 @@ export function updateAllClasses(selectors, updateClass) {
|
|
|
58
35
|
return result
|
|
59
36
|
}
|
|
60
37
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
let lastClass = sel.filter(({ type }) => type === 'class').pop()
|
|
65
|
-
|
|
66
|
-
if (lastClass === undefined) {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let updatedClass = updateClass(lastClass.value, {
|
|
71
|
-
withPseudo(className, pseudo) {
|
|
72
|
-
lastClass.parent.insertAfter(lastClass, selectorParser.pseudo({ value: `${pseudo}` }))
|
|
73
|
-
return className
|
|
74
|
-
},
|
|
75
|
-
})
|
|
76
|
-
lastClass.value = updatedClass
|
|
77
|
-
if (lastClass.raws && lastClass.raws.value) {
|
|
78
|
-
lastClass.raws.value = escapeCommas(lastClass.raws.value)
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
let result = parser.processSync(selectors)
|
|
83
|
-
|
|
84
|
-
return result
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function splitByNotEscapedCommas(str) {
|
|
88
|
-
let chunks = []
|
|
89
|
-
let currentChunk = ''
|
|
90
|
-
for (let i = 0; i < str.length; i++) {
|
|
91
|
-
if (str[i] === ',' && str[i - 1] !== '\\') {
|
|
92
|
-
chunks.push(currentChunk)
|
|
93
|
-
currentChunk = ''
|
|
94
|
-
} else {
|
|
95
|
-
currentChunk += str[i]
|
|
96
|
-
}
|
|
38
|
+
function resolveArbitraryValue(modifier, validate) {
|
|
39
|
+
if (!isArbitraryValue(modifier)) {
|
|
40
|
+
return undefined
|
|
97
41
|
}
|
|
98
|
-
chunks.push(currentChunk)
|
|
99
|
-
return chunks
|
|
100
|
-
}
|
|
101
42
|
|
|
102
|
-
|
|
103
|
-
return ({ container }) => {
|
|
104
|
-
container.walkRules((rule) => {
|
|
105
|
-
if (isKeyframeRule(rule)) {
|
|
106
|
-
return rule
|
|
107
|
-
}
|
|
108
|
-
let transformed = splitByNotEscapedCommas(rule.selector).map(transformSelector).join(',')
|
|
109
|
-
rule.selector = transformed
|
|
110
|
-
if (withRule) {
|
|
111
|
-
withRule(rule)
|
|
112
|
-
}
|
|
113
|
-
return rule
|
|
114
|
-
})
|
|
43
|
+
let value = modifier.slice(1, -1)
|
|
115
44
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
let nodes = container.nodes
|
|
119
|
-
container.removeAll()
|
|
120
|
-
wrapper.append(nodes)
|
|
121
|
-
container.append(wrapper)
|
|
122
|
-
}
|
|
45
|
+
if (!validate(value)) {
|
|
46
|
+
return undefined
|
|
123
47
|
}
|
|
48
|
+
|
|
49
|
+
return normalize(value)
|
|
124
50
|
}
|
|
125
51
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
container.walkRules((rule) => {
|
|
129
|
-
let selector = rule.selector
|
|
130
|
-
let variantSelector = updateAllClasses(selector, transformClass)
|
|
131
|
-
rule.selector = variantSelector
|
|
132
|
-
if (withRule) {
|
|
133
|
-
withRule(rule)
|
|
134
|
-
}
|
|
135
|
-
return rule
|
|
136
|
-
})
|
|
52
|
+
function asNegativeValue(modifier, lookup = {}, validate) {
|
|
53
|
+
let positiveValue = lookup[modifier]
|
|
137
54
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
let nodes = container.nodes
|
|
141
|
-
container.removeAll()
|
|
142
|
-
wrapper.append(nodes)
|
|
143
|
-
container.append(wrapper)
|
|
144
|
-
}
|
|
55
|
+
if (positiveValue !== undefined) {
|
|
56
|
+
return negateValue(positiveValue)
|
|
145
57
|
}
|
|
146
|
-
}
|
|
147
58
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
container.walkRules((rule) => {
|
|
151
|
-
let selector = rule.selector
|
|
152
|
-
let variantSelector = updateLastClasses(selector, transformClass)
|
|
153
|
-
rule.selector = variantSelector
|
|
154
|
-
if (withRule) {
|
|
155
|
-
withRule(rule)
|
|
156
|
-
}
|
|
157
|
-
return rule
|
|
158
|
-
})
|
|
59
|
+
if (isArbitraryValue(modifier)) {
|
|
60
|
+
let resolved = resolveArbitraryValue(modifier, validate)
|
|
159
61
|
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
let nodes = container.nodes
|
|
163
|
-
container.removeAll()
|
|
164
|
-
wrapper.append(nodes)
|
|
165
|
-
container.append(wrapper)
|
|
62
|
+
if (resolved === undefined) {
|
|
63
|
+
return undefined
|
|
166
64
|
}
|
|
65
|
+
|
|
66
|
+
return negateValue(resolved)
|
|
167
67
|
}
|
|
168
68
|
}
|
|
169
69
|
|
|
170
|
-
export function asValue(modifier,
|
|
171
|
-
let value =
|
|
70
|
+
export function asValue(modifier, options = {}, { validate = () => true } = {}) {
|
|
71
|
+
let value = options.values?.[modifier]
|
|
172
72
|
|
|
173
73
|
if (value !== undefined) {
|
|
174
74
|
return value
|
|
175
75
|
}
|
|
176
76
|
|
|
177
|
-
if (
|
|
178
|
-
return
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
value = modifier.slice(1, -1)
|
|
182
|
-
|
|
183
|
-
if (!validate(value)) {
|
|
184
|
-
return undefined
|
|
77
|
+
if (options.supportsNegativeValues && modifier.startsWith('-')) {
|
|
78
|
+
return asNegativeValue(modifier.slice(1), options.values, validate)
|
|
185
79
|
}
|
|
186
80
|
|
|
187
|
-
return
|
|
81
|
+
return resolveArbitraryValue(modifier, validate)
|
|
188
82
|
}
|
|
189
83
|
|
|
190
84
|
function isArbitraryValue(input) {
|
|
@@ -201,16 +95,16 @@ function splitAlpha(modifier) {
|
|
|
201
95
|
return [modifier.slice(0, slashIdx), modifier.slice(slashIdx + 1)]
|
|
202
96
|
}
|
|
203
97
|
|
|
204
|
-
export function asColor(modifier,
|
|
205
|
-
if (
|
|
206
|
-
return
|
|
98
|
+
export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
|
|
99
|
+
if (options.values?.[modifier] !== undefined) {
|
|
100
|
+
return options.values?.[modifier]
|
|
207
101
|
}
|
|
208
102
|
|
|
209
103
|
let [color, alpha] = splitAlpha(modifier)
|
|
210
104
|
|
|
211
105
|
if (alpha !== undefined) {
|
|
212
106
|
let normalizedColor =
|
|
213
|
-
|
|
107
|
+
options.values?.[color] ?? (isArbitraryValue(color) ? color.slice(1, -1) : undefined)
|
|
214
108
|
|
|
215
109
|
if (normalizedColor === undefined) {
|
|
216
110
|
return undefined
|
|
@@ -227,16 +121,16 @@ export function asColor(modifier, lookup = {}, tailwindConfig = {}) {
|
|
|
227
121
|
return withAlphaValue(normalizedColor, tailwindConfig.theme.opacity[alpha])
|
|
228
122
|
}
|
|
229
123
|
|
|
230
|
-
return asValue(modifier,
|
|
124
|
+
return asValue(modifier, options, { validate: validateColor })
|
|
231
125
|
}
|
|
232
126
|
|
|
233
|
-
export function asLookupValue(modifier,
|
|
234
|
-
return
|
|
127
|
+
export function asLookupValue(modifier, options = {}) {
|
|
128
|
+
return options.values?.[modifier]
|
|
235
129
|
}
|
|
236
130
|
|
|
237
131
|
function guess(validate) {
|
|
238
|
-
return (modifier,
|
|
239
|
-
return asValue(modifier,
|
|
132
|
+
return (modifier, options) => {
|
|
133
|
+
return asValue(modifier, options, { validate })
|
|
240
134
|
}
|
|
241
135
|
}
|
|
242
136
|
|
|
@@ -255,6 +149,7 @@ let typeMap = {
|
|
|
255
149
|
'line-width': guess(lineWidth),
|
|
256
150
|
'absolute-size': guess(absoluteSize),
|
|
257
151
|
'relative-size': guess(relativeSize),
|
|
152
|
+
shadow: guess(shadow),
|
|
258
153
|
}
|
|
259
154
|
|
|
260
155
|
let supportedTypes = Object.keys(typeMap)
|
|
@@ -265,23 +160,32 @@ function splitAtFirst(input, delim) {
|
|
|
265
160
|
return [input.slice(0, idx), input.slice(idx + 1)]
|
|
266
161
|
}
|
|
267
162
|
|
|
268
|
-
export function coerceValue(types, modifier,
|
|
163
|
+
export function coerceValue(types, modifier, options, tailwindConfig) {
|
|
269
164
|
if (isArbitraryValue(modifier)) {
|
|
270
|
-
let
|
|
165
|
+
let arbitraryValue = modifier.slice(1, -1)
|
|
166
|
+
let [explicitType, value] = splitAtFirst(arbitraryValue, ':')
|
|
167
|
+
|
|
168
|
+
// It could be that this resolves to `url(https` which is not a valid
|
|
169
|
+
// identifier. We currently only support "simple" words with dashes or
|
|
170
|
+
// underscores. E.g.: family-name
|
|
171
|
+
if (!/^[\w-_]+$/g.test(explicitType)) {
|
|
172
|
+
value = arbitraryValue
|
|
173
|
+
}
|
|
271
174
|
|
|
272
|
-
|
|
175
|
+
//
|
|
176
|
+
else if (explicitType !== undefined && !supportedTypes.includes(explicitType)) {
|
|
273
177
|
return []
|
|
274
178
|
}
|
|
275
179
|
|
|
276
180
|
if (value.length > 0 && supportedTypes.includes(explicitType)) {
|
|
277
|
-
return [asValue(`[${value}]`,
|
|
181
|
+
return [asValue(`[${value}]`, options), explicitType]
|
|
278
182
|
}
|
|
279
183
|
}
|
|
280
184
|
|
|
281
185
|
// Find first matching type
|
|
282
186
|
for (let type of [].concat(types)) {
|
|
283
|
-
let result = typeMap[type](modifier,
|
|
284
|
-
if (result) return [result, type]
|
|
187
|
+
let result = typeMap[type](modifier, options, { tailwindConfig })
|
|
188
|
+
if (result !== undefined) return [result, type]
|
|
285
189
|
}
|
|
286
190
|
|
|
287
191
|
return []
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import parser from 'postcss-selector-parser'
|
|
2
|
-
import { tap } from './tap'
|
|
3
|
-
|
|
4
|
-
export default function (prefix, selector) {
|
|
5
|
-
const getPrefix =
|
|
6
|
-
typeof prefix === 'function' ? prefix : () => (prefix === undefined ? '' : prefix)
|
|
7
2
|
|
|
3
|
+
export default function (prefix, selector, prependNegative = false) {
|
|
8
4
|
return parser((selectors) => {
|
|
9
5
|
selectors.walkClasses((classSelector) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
let baseClass = classSelector.value
|
|
7
|
+
let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
|
|
8
|
+
|
|
9
|
+
classSelector.value = shouldPlaceNegativeBeforePrefix
|
|
10
|
+
? `-${prefix}${baseClass.slice(1)}`
|
|
11
|
+
: `${prefix}${baseClass}`
|
|
13
12
|
})
|
|
14
13
|
}).processSync(selector)
|
|
15
14
|
}
|
|
@@ -3,9 +3,12 @@ import corePluginList from '../corePluginList'
|
|
|
3
3
|
import configurePlugins from './configurePlugins'
|
|
4
4
|
import defaultConfig from '../../stubs/defaultConfig.stub'
|
|
5
5
|
import colors from '../public/colors'
|
|
6
|
-
import log from './log'
|
|
7
6
|
import { defaults } from './defaults'
|
|
8
7
|
import { toPath } from './toPath'
|
|
8
|
+
import { normalizeConfig } from './normalizeConfig'
|
|
9
|
+
import isPlainObject from './isPlainObject'
|
|
10
|
+
import { cloneDeep } from './cloneDeep'
|
|
11
|
+
import { withAlphaValue } from './withAlphaVariable'
|
|
9
12
|
|
|
10
13
|
function isFunction(input) {
|
|
11
14
|
return typeof input === 'function'
|
|
@@ -40,15 +43,18 @@ function mergeWith(target, ...sources) {
|
|
|
40
43
|
const configUtils = {
|
|
41
44
|
colors,
|
|
42
45
|
negative(scale) {
|
|
46
|
+
// TODO: Log that this function isn't really needed anymore?
|
|
43
47
|
return Object.keys(scale)
|
|
44
48
|
.filter((key) => scale[key] !== '0')
|
|
45
|
-
.reduce(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
.reduce((negativeScale, key) => {
|
|
50
|
+
let negativeValue = negateValue(scale[key])
|
|
51
|
+
|
|
52
|
+
if (negativeValue !== undefined) {
|
|
53
|
+
negativeScale[`-${key}`] = negativeValue
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return negativeScale
|
|
57
|
+
}, {})
|
|
52
58
|
},
|
|
53
59
|
breakpoints(screens) {
|
|
54
60
|
return Object.keys(screens)
|
|
@@ -61,6 +67,36 @@ const configUtils = {
|
|
|
61
67
|
{}
|
|
62
68
|
)
|
|
63
69
|
},
|
|
70
|
+
rgb(property) {
|
|
71
|
+
if (!property.startsWith('--')) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
'The rgb() helper requires a custom property name to be passed as the first argument.'
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return ({ opacityValue }) => {
|
|
78
|
+
if (opacityValue === undefined || opacityValue === 1) {
|
|
79
|
+
return `rgb(var(${property}) / 1.0)`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return `rgb(var(${property}) / ${opacityValue})`
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
hsl(property) {
|
|
86
|
+
if (!property.startsWith('--')) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
'The hsl() helper requires a custom property name to be passed as the first argument.'
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return ({ opacityValue }) => {
|
|
93
|
+
if (opacityValue === undefined || opacityValue === 1) {
|
|
94
|
+
return `hsl(var(${property}) / 1)`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return `hsl(var(${property}) / ${opacityValue})`
|
|
98
|
+
}
|
|
99
|
+
},
|
|
64
100
|
}
|
|
65
101
|
|
|
66
102
|
function value(valueToResolve, ...args) {
|
|
@@ -129,32 +165,81 @@ function mergeExtensions({ extend, ...theme }) {
|
|
|
129
165
|
})
|
|
130
166
|
}
|
|
131
167
|
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param {string} key
|
|
171
|
+
* @return {Iterable<string[] & {alpha: string | undefined}>}
|
|
172
|
+
*/
|
|
173
|
+
function* toPaths(key) {
|
|
174
|
+
let path = toPath(key)
|
|
175
|
+
|
|
176
|
+
if (path.length === 0) {
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
yield path
|
|
181
|
+
|
|
182
|
+
if (Array.isArray(key)) {
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let pattern = /^(.*?)\s*\/\s*([^/]+)$/
|
|
187
|
+
let matches = key.match(pattern)
|
|
188
|
+
|
|
189
|
+
if (matches !== null) {
|
|
190
|
+
let [, prefix, alpha] = matches
|
|
191
|
+
|
|
192
|
+
let newPath = toPath(prefix)
|
|
193
|
+
newPath.alpha = alpha
|
|
194
|
+
|
|
195
|
+
yield newPath
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
132
199
|
function resolveFunctionKeys(object) {
|
|
200
|
+
// theme('colors.red.500 / 0.5') -> ['colors', 'red', '500 / 0', '5]
|
|
201
|
+
|
|
133
202
|
const resolvePath = (key, defaultValue) => {
|
|
134
|
-
const path
|
|
203
|
+
for (const path of toPaths(key)) {
|
|
204
|
+
let index = 0
|
|
205
|
+
let val = object
|
|
206
|
+
|
|
207
|
+
while (val !== undefined && val !== null && index < path.length) {
|
|
208
|
+
val = val[path[index++]]
|
|
135
209
|
|
|
136
|
-
|
|
137
|
-
|
|
210
|
+
let shouldResolveAsFn =
|
|
211
|
+
isFunction(val) && (path.alpha === undefined || index < path.length - 1)
|
|
138
212
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
213
|
+
val = shouldResolveAsFn ? val(resolvePath, configUtils) : val
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (val !== undefined) {
|
|
217
|
+
if (path.alpha !== undefined) {
|
|
218
|
+
return withAlphaValue(val, path.alpha)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (isPlainObject(val)) {
|
|
222
|
+
return cloneDeep(val)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return val
|
|
226
|
+
}
|
|
142
227
|
}
|
|
143
228
|
|
|
144
|
-
return
|
|
229
|
+
return defaultValue
|
|
145
230
|
}
|
|
146
231
|
|
|
147
|
-
|
|
232
|
+
// colors.red.500/50
|
|
148
233
|
|
|
149
|
-
|
|
150
|
-
resolvePath
|
|
151
|
-
|
|
234
|
+
Object.assign(resolvePath, {
|
|
235
|
+
theme: resolvePath,
|
|
236
|
+
...configUtils,
|
|
237
|
+
})
|
|
152
238
|
|
|
153
239
|
return Object.keys(object).reduce((resolved, key) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
240
|
+
resolved[key] = isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key]
|
|
241
|
+
|
|
242
|
+
return resolved
|
|
158
243
|
}, {})
|
|
159
244
|
}
|
|
160
245
|
|
|
@@ -224,59 +309,3 @@ export default function resolveConfig(configs) {
|
|
|
224
309
|
)
|
|
225
310
|
)
|
|
226
311
|
}
|
|
227
|
-
|
|
228
|
-
let warnedAbout = new Set()
|
|
229
|
-
function normalizeConfig(config) {
|
|
230
|
-
if (!warnedAbout.has('purge-deprecation') && config.hasOwnProperty('purge')) {
|
|
231
|
-
log.warn([
|
|
232
|
-
'The `purge` option in your tailwind.config.js file has been deprecated.',
|
|
233
|
-
'Please rename this to `content` instead.',
|
|
234
|
-
])
|
|
235
|
-
warnedAbout.add('purge-deprecation')
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
config.content = {
|
|
239
|
-
content: (() => {
|
|
240
|
-
let { content, purge } = config
|
|
241
|
-
|
|
242
|
-
if (Array.isArray(purge)) return purge
|
|
243
|
-
if (Array.isArray(purge?.content)) return purge.content
|
|
244
|
-
if (Array.isArray(content)) return content
|
|
245
|
-
if (Array.isArray(content?.content)) return content.content
|
|
246
|
-
|
|
247
|
-
return []
|
|
248
|
-
})(),
|
|
249
|
-
safelist: (() => {
|
|
250
|
-
let { content, purge } = config
|
|
251
|
-
|
|
252
|
-
let [safelistKey, safelistPaths] = (() => {
|
|
253
|
-
if (Array.isArray(content?.safelist)) return ['content.safelist', content.safelist]
|
|
254
|
-
if (Array.isArray(purge?.safelist)) return ['purge.safelist', purge.safelist]
|
|
255
|
-
if (Array.isArray(purge?.options?.safelist))
|
|
256
|
-
return ['purge.options.safelist', purge.options.safelist]
|
|
257
|
-
return [null, []]
|
|
258
|
-
})()
|
|
259
|
-
|
|
260
|
-
return safelistPaths.map((content) => {
|
|
261
|
-
if (typeof content === 'string') {
|
|
262
|
-
return { raw: content, extension: 'html' }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (content instanceof RegExp) {
|
|
266
|
-
throw new Error(
|
|
267
|
-
`Values inside '${safelistKey}' can only be of type 'string', found 'regex'.`
|
|
268
|
-
)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
throw new Error(
|
|
272
|
-
`Values inside '${safelistKey}' can only be of type 'string', found '${typeof content}'.`
|
|
273
|
-
)
|
|
274
|
-
})
|
|
275
|
-
})(),
|
|
276
|
-
extract: config.content?.extract || config.purge?.extract || {},
|
|
277
|
-
options: config.content?.options || config.purge?.options || {},
|
|
278
|
-
transform: config.content?.transform || config.purge?.transform || {},
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return config
|
|
282
|
-
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as regex from '../lib/regex'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This splits a string on a top-level character.
|
|
5
|
+
*
|
|
6
|
+
* Regex doesn't support recursion (at least not the JS-flavored version).
|
|
7
|
+
* So we have to use a tiny state machine to keep track of paren placement.
|
|
8
|
+
*
|
|
9
|
+
* Expected behavior using commas:
|
|
10
|
+
* var(--a, 0 0 1px rgb(0, 0, 0)), 0 0 1px rgb(0, 0, 0)
|
|
11
|
+
* ─┬─ ┬ ┬ ┬
|
|
12
|
+
* x x x ╰──────── Split because top-level
|
|
13
|
+
* ╰──────────────┴──┴───────────── Ignored b/c inside >= 1 levels of parens
|
|
14
|
+
*
|
|
15
|
+
* @param {string} input
|
|
16
|
+
* @param {string} separator
|
|
17
|
+
*/
|
|
18
|
+
export function* splitAtTopLevelOnly(input, separator) {
|
|
19
|
+
let SPECIALS = new RegExp(`[(){}\\[\\]${regex.escape(separator)}]`, 'g')
|
|
20
|
+
|
|
21
|
+
let depth = 0
|
|
22
|
+
let lastIndex = 0
|
|
23
|
+
let found = false
|
|
24
|
+
let separatorIndex = 0
|
|
25
|
+
let separatorStart = 0
|
|
26
|
+
let separatorLength = separator.length
|
|
27
|
+
|
|
28
|
+
// Find all paren-like things & character
|
|
29
|
+
// And only split on commas if they're top-level
|
|
30
|
+
for (let match of input.matchAll(SPECIALS)) {
|
|
31
|
+
let matchesSeparator = match[0] === separator[separatorIndex]
|
|
32
|
+
let atEndOfSeparator = separatorIndex === separatorLength - 1
|
|
33
|
+
let matchesFullSeparator = matchesSeparator && atEndOfSeparator
|
|
34
|
+
|
|
35
|
+
if (match[0] === '(') depth++
|
|
36
|
+
if (match[0] === ')') depth--
|
|
37
|
+
if (match[0] === '[') depth++
|
|
38
|
+
if (match[0] === ']') depth--
|
|
39
|
+
if (match[0] === '{') depth++
|
|
40
|
+
if (match[0] === '}') depth--
|
|
41
|
+
|
|
42
|
+
if (matchesSeparator && depth === 0) {
|
|
43
|
+
if (separatorStart === 0) {
|
|
44
|
+
separatorStart = match.index
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
separatorIndex++
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (matchesFullSeparator && depth === 0) {
|
|
51
|
+
found = true
|
|
52
|
+
|
|
53
|
+
yield input.substring(lastIndex, separatorStart)
|
|
54
|
+
lastIndex = separatorStart + separatorLength
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (separatorIndex === separatorLength) {
|
|
58
|
+
separatorIndex = 0
|
|
59
|
+
separatorStart = 0
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Provide the last segment of the string if available
|
|
64
|
+
// Otherwise the whole string since no `char`s were found
|
|
65
|
+
// This mirrors the behavior of string.split()
|
|
66
|
+
if (found) {
|
|
67
|
+
yield input.substring(lastIndex)
|
|
68
|
+
} else {
|
|
69
|
+
yield input
|
|
70
|
+
}
|
|
71
|
+
}
|