tailwindcss 0.0.0-insiders.ea80db2 → 0.0.0-insiders.eae2b7a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/defaultTheme.d.ts +2 -1
- package/index.css +5 -0
- package/lib/cli/build/index.js +57 -0
- package/lib/cli/build/plugin.js +427 -0
- package/lib/cli/build/utils.js +88 -0
- package/lib/cli/build/watching.js +182 -0
- package/lib/cli/help/index.js +73 -0
- package/lib/cli/index.js +231 -0
- package/lib/cli/init/index.js +63 -0
- package/lib/cli.js +1 -759
- package/lib/corePluginList.js +12 -3
- package/lib/corePlugins.js +2308 -1739
- package/lib/css/preflight.css +13 -5
- package/lib/featureFlags.js +50 -25
- package/lib/index.js +1 -40
- package/lib/lib/cacheInvalidation.js +48 -25
- package/lib/lib/collapseAdjacentRules.js +17 -10
- package/lib/lib/collapseDuplicateDeclarations.js +13 -8
- package/lib/lib/content.js +207 -0
- package/lib/lib/defaultExtractor.js +232 -33
- package/lib/lib/detectNesting.js +21 -10
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +316 -215
- package/lib/lib/expandTailwindAtRules.js +167 -115
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +444 -211
- package/lib/lib/getModuleDependencies.js +88 -37
- package/lib/lib/handleImportAtRules.js +50 -0
- package/lib/lib/load-config.js +42 -0
- package/lib/lib/normalizeTailwindDirectives.js +29 -39
- package/lib/lib/offsets.js +306 -0
- package/lib/lib/partitionApplyAtRules.js +13 -8
- package/lib/lib/regex.js +74 -0
- package/lib/lib/remap-bitfield.js +89 -0
- package/lib/lib/resolveDefaultsAtRules.js +96 -74
- package/lib/lib/setupContextUtils.js +672 -300
- package/lib/lib/setupTrackingContext.js +63 -68
- package/lib/lib/sharedState.js +44 -17
- package/lib/lib/substituteScreenAtRules.js +14 -10
- package/lib/plugin.js +160 -0
- package/lib/postcss-plugins/nesting/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +10 -6
- package/lib/postcss-plugins/nesting/plugin.js +24 -20
- package/lib/processTailwindFeatures.js +34 -29
- 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 +12 -3
- package/lib/util/color.js +66 -50
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +7 -2
- package/lib/util/createPlugin.js +8 -5
- package/lib/util/createUtilityPlugin.js +13 -9
- package/lib/util/dataTypes.js +182 -111
- package/lib/util/defaults.js +12 -7
- package/lib/util/escapeClassName.js +13 -8
- package/lib/util/escapeCommas.js +7 -2
- package/lib/util/flattenColorPalette.js +11 -10
- 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 +40 -13
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +155 -87
- package/lib/util/normalizeScreens.js +127 -8
- package/lib/util/parseAnimationValue.js +44 -40
- package/lib/util/parseBoxShadowValue.js +33 -62
- package/lib/util/parseDependency.js +39 -55
- package/lib/util/parseGlob.js +36 -0
- package/lib/util/parseObjectStyles.js +15 -10
- package/lib/util/pluginUtils.js +154 -59
- package/lib/util/prefixSelector.js +29 -10
- package/lib/util/pseudoElements.js +209 -0
- package/lib/util/removeAlphaVariables.js +31 -0
- package/lib/util/resolveConfig.js +96 -95
- package/lib/util/resolveConfigPath.js +29 -10
- 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 -2
- package/lib/util/toPath.js +22 -4
- package/lib/util/transformThemeValue.js +40 -26
- package/lib/util/validateConfig.js +48 -0
- package/lib/util/validateFormalSyntax.js +26 -0
- package/lib/util/withAlphaVariable.js +27 -15
- package/lib/value-parser/LICENSE +22 -0
- package/lib/value-parser/README.md +3 -0
- package/lib/value-parser/index.d.js +2 -0
- package/lib/value-parser/index.js +22 -0
- package/lib/value-parser/parse.js +259 -0
- package/lib/value-parser/stringify.js +38 -0
- package/lib/value-parser/unit.js +86 -0
- package/lib/value-parser/walk.js +16 -0
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/package.json +54 -52
- package/plugin.d.ts +10 -5
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +53 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/index.js +53 -0
- package/src/cli/build/plugin.js +465 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +229 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +217 -0
- package/src/cli/init/index.js +79 -0
- package/src/cli.js +1 -836
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +576 -106
- package/src/css/preflight.css +13 -5
- package/src/featureFlags.js +17 -3
- package/src/index.js +1 -42
- package/src/lib/collapseAdjacentRules.js +5 -1
- package/src/lib/content.js +240 -0
- package/src/lib/defaultExtractor.js +202 -35
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +82 -8
- package/src/lib/expandApplyAtRules.js +322 -189
- package/src/lib/expandTailwindAtRules.js +82 -59
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +413 -132
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/handleImportAtRules.js +34 -0
- package/src/lib/load-config.ts +31 -0
- package/src/lib/normalizeTailwindDirectives.js +0 -27
- package/src/lib/offsets.js +373 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -36
- package/src/lib/setupContextUtils.js +570 -151
- package/src/lib/setupTrackingContext.js +44 -58
- package/src/lib/sharedState.js +13 -4
- package/src/plugin.js +128 -0
- package/src/postcss-plugins/nesting/README.md +2 -2
- package/src/public/colors.js +22 -0
- package/src/public/default-config.js +1 -1
- package/src/public/default-theme.js +2 -2
- package/src/public/load-config.js +2 -0
- package/src/util/applyImportantSelector.js +27 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +5 -1
- package/src/util/color.js +34 -17
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +67 -23
- 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 +25 -1
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +78 -20
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +118 -23
- package/src/util/prefixSelector.js +28 -10
- package/src/util/pseudoElements.js +167 -0
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -62
- package/src/util/resolveConfigPath.js +12 -1
- package/src/util/splitAtTopLevelOnly.js +52 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +36 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/src/value-parser/LICENSE +22 -0
- package/src/value-parser/README.md +3 -0
- package/src/value-parser/index.d.ts +177 -0
- package/src/value-parser/index.js +28 -0
- package/src/value-parser/parse.js +303 -0
- package/src/value-parser/stringify.js +41 -0
- package/src/value-parser/unit.js +118 -0
- package/src/value-parser/walk.js +18 -0
- package/stubs/.gitignore +1 -0
- package/stubs/.prettierrc.json +6 -0
- package/stubs/{defaultConfig.stub.js → config.full.js} +215 -165
- package/stubs/{simpleConfig.stub.js → config.simple.js} +1 -1
- package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -1
- package/stubs/postcss.config.js +5 -0
- package/stubs/tailwind.config.cjs +2 -0
- package/stubs/tailwind.config.js +2 -0
- package/stubs/tailwind.config.ts +3 -0
- package/types/config.d.ts +102 -56
- package/types/generated/colors.d.ts +22 -0
- package/types/generated/corePluginList.d.ts +1 -1
- package/types/generated/default-theme.d.ts +372 -0
- package/types/index.d.ts +7 -1
- package/CHANGELOG.md +0 -2099
- package/lib/cli-peer-dependencies.js +0 -15
- package/lib/constants.js +0 -37
- package/peers/index.js +0 -75156
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/cli-peer-dependencies.js +0 -9
- package/src/constants.js +0 -17
- package/types.d.ts +0 -1
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import parser from 'postcss-selector-parser'
|
|
2
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
|
+
*/
|
|
3
15
|
export default function (prefix, selector, prependNegative = false) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
14
32
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/** @typedef {import('postcss-selector-parser').Root} Root */
|
|
2
|
+
/** @typedef {import('postcss-selector-parser').Selector} Selector */
|
|
3
|
+
/** @typedef {import('postcss-selector-parser').Pseudo} Pseudo */
|
|
4
|
+
/** @typedef {import('postcss-selector-parser').Node} Node */
|
|
5
|
+
|
|
6
|
+
// There are some pseudo-elements that may or may not be:
|
|
7
|
+
|
|
8
|
+
// **Actionable**
|
|
9
|
+
// Zero or more user-action pseudo-classes may be attached to the pseudo-element itself
|
|
10
|
+
// structural-pseudo-classes are NOT allowed but we don't make
|
|
11
|
+
// The spec is not clear on whether this is allowed or not — but in practice it is.
|
|
12
|
+
|
|
13
|
+
// **Terminal**
|
|
14
|
+
// It MUST be placed at the end of a selector
|
|
15
|
+
//
|
|
16
|
+
// This is the required in the spec. However, some pseudo elements are not "terminal" because
|
|
17
|
+
// they represent a "boundary piercing" that is compiled out by a build step.
|
|
18
|
+
|
|
19
|
+
// **Jumpable**
|
|
20
|
+
// Any terminal element may "jump" over combinators when moving to the end of the selector
|
|
21
|
+
//
|
|
22
|
+
// This is a backwards-compat quirk of pseudo element variants from earlier versions of Tailwind CSS.
|
|
23
|
+
|
|
24
|
+
/** @typedef {'terminal' | 'actionable' | 'jumpable'} PseudoProperty */
|
|
25
|
+
|
|
26
|
+
/** @type {Record<string, PseudoProperty[]>} */
|
|
27
|
+
let elementProperties = {
|
|
28
|
+
// Pseudo elements from the spec
|
|
29
|
+
'::after': ['terminal', 'jumpable'],
|
|
30
|
+
'::backdrop': ['terminal', 'jumpable'],
|
|
31
|
+
'::before': ['terminal', 'jumpable'],
|
|
32
|
+
'::cue': ['terminal'],
|
|
33
|
+
'::cue-region': ['terminal'],
|
|
34
|
+
'::first-letter': ['terminal', 'jumpable'],
|
|
35
|
+
'::first-line': ['terminal', 'jumpable'],
|
|
36
|
+
'::grammar-error': ['terminal'],
|
|
37
|
+
'::marker': ['terminal', 'jumpable'],
|
|
38
|
+
'::part': ['terminal', 'actionable'],
|
|
39
|
+
'::placeholder': ['terminal', 'jumpable'],
|
|
40
|
+
'::selection': ['terminal', 'jumpable'],
|
|
41
|
+
'::slotted': ['terminal'],
|
|
42
|
+
'::spelling-error': ['terminal'],
|
|
43
|
+
'::target-text': ['terminal'],
|
|
44
|
+
|
|
45
|
+
// Pseudo elements from the spec with special rules
|
|
46
|
+
'::file-selector-button': ['terminal', 'actionable'],
|
|
47
|
+
|
|
48
|
+
// Library-specific pseudo elements used by component libraries
|
|
49
|
+
// These are Shadow DOM-like
|
|
50
|
+
'::deep': ['actionable'],
|
|
51
|
+
'::v-deep': ['actionable'],
|
|
52
|
+
'::ng-deep': ['actionable'],
|
|
53
|
+
|
|
54
|
+
// Note: As a rule, double colons (::) should be used instead of a single colon
|
|
55
|
+
// (:). This distinguishes pseudo-classes from pseudo-elements. However, since
|
|
56
|
+
// this distinction was not present in older versions of the W3C spec, most
|
|
57
|
+
// browsers support both syntaxes for the original pseudo-elements.
|
|
58
|
+
':after': ['terminal', 'jumpable'],
|
|
59
|
+
':before': ['terminal', 'jumpable'],
|
|
60
|
+
':first-letter': ['terminal', 'jumpable'],
|
|
61
|
+
':first-line': ['terminal', 'jumpable'],
|
|
62
|
+
|
|
63
|
+
// The default value is used when the pseudo-element is not recognized
|
|
64
|
+
// Because it's not recognized, we don't know if it's terminal or not
|
|
65
|
+
// So we assume it can be moved AND can have user-action pseudo classes attached to it
|
|
66
|
+
__default__: ['terminal', 'actionable'],
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {Selector} sel
|
|
71
|
+
* @returns {Selector}
|
|
72
|
+
*/
|
|
73
|
+
export function movePseudos(sel) {
|
|
74
|
+
let [pseudos] = movablePseudos(sel)
|
|
75
|
+
|
|
76
|
+
// Remove all pseudo elements from their respective selectors
|
|
77
|
+
pseudos.forEach(([sel, pseudo]) => sel.removeChild(pseudo))
|
|
78
|
+
|
|
79
|
+
// Re-add them to the end of the selector in the correct order.
|
|
80
|
+
// This moves terminal pseudo elements to the end of the
|
|
81
|
+
// selector otherwise the selector will not be valid.
|
|
82
|
+
//
|
|
83
|
+
// Examples:
|
|
84
|
+
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
85
|
+
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
86
|
+
//
|
|
87
|
+
// The selector `::before:hover` does not work but we
|
|
88
|
+
// can make it work for you by flipping the order.
|
|
89
|
+
sel.nodes.push(...pseudos.map(([, pseudo]) => pseudo))
|
|
90
|
+
|
|
91
|
+
return sel
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @typedef {[sel: Selector, pseudo: Pseudo, attachedTo: Pseudo | null]} MovablePseudo */
|
|
95
|
+
/** @typedef {[pseudos: MovablePseudo[], lastSeenElement: Pseudo | null]} MovablePseudosResult */
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {Selector} sel
|
|
99
|
+
* @returns {MovablePseudosResult}
|
|
100
|
+
*/
|
|
101
|
+
function movablePseudos(sel) {
|
|
102
|
+
/** @type {MovablePseudo[]} */
|
|
103
|
+
let buffer = []
|
|
104
|
+
|
|
105
|
+
/** @type {Pseudo | null} */
|
|
106
|
+
let lastSeenElement = null
|
|
107
|
+
|
|
108
|
+
for (let node of sel.nodes) {
|
|
109
|
+
if (node.type === 'combinator') {
|
|
110
|
+
buffer = buffer.filter(([, node]) => propertiesForPseudo(node).includes('jumpable'))
|
|
111
|
+
lastSeenElement = null
|
|
112
|
+
} else if (node.type === 'pseudo') {
|
|
113
|
+
if (isMovablePseudoElement(node)) {
|
|
114
|
+
lastSeenElement = node
|
|
115
|
+
buffer.push([sel, node, null])
|
|
116
|
+
} else if (lastSeenElement && isAttachablePseudoClass(node, lastSeenElement)) {
|
|
117
|
+
buffer.push([sel, node, lastSeenElement])
|
|
118
|
+
} else {
|
|
119
|
+
lastSeenElement = null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (let sub of node.nodes ?? []) {
|
|
123
|
+
let [movable, lastSeenElementInSub] = movablePseudos(sub)
|
|
124
|
+
lastSeenElement = lastSeenElementInSub || lastSeenElement
|
|
125
|
+
buffer.push(...movable)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return [buffer, lastSeenElement]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {Node} node
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
*/
|
|
137
|
+
function isPseudoElement(node) {
|
|
138
|
+
return node.value.startsWith('::') || elementProperties[node.value] !== undefined
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {Node} node
|
|
143
|
+
* @returns {boolean}
|
|
144
|
+
*/
|
|
145
|
+
function isMovablePseudoElement(node) {
|
|
146
|
+
return isPseudoElement(node) && propertiesForPseudo(node).includes('terminal')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @param {Node} node
|
|
151
|
+
* @param {Pseudo} pseudo
|
|
152
|
+
* @returns {boolean}
|
|
153
|
+
*/
|
|
154
|
+
function isAttachablePseudoClass(node, pseudo) {
|
|
155
|
+
if (node.type !== 'pseudo') return false
|
|
156
|
+
if (isPseudoElement(node)) return false
|
|
157
|
+
|
|
158
|
+
return propertiesForPseudo(pseudo).includes('actionable')
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {Pseudo} pseudo
|
|
163
|
+
* @returns {PseudoProperty[]}
|
|
164
|
+
*/
|
|
165
|
+
function propertiesForPseudo(pseudo) {
|
|
166
|
+
return elementProperties[pseudo.value] ?? elementProperties.__default__
|
|
167
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import negateValue from './negateValue'
|
|
2
2
|
import corePluginList from '../corePluginList'
|
|
3
3
|
import configurePlugins from './configurePlugins'
|
|
4
|
-
import defaultConfig from '../../stubs/defaultConfig.stub'
|
|
5
4
|
import colors from '../public/colors'
|
|
6
5
|
import { defaults } from './defaults'
|
|
7
6
|
import { toPath } from './toPath'
|
|
8
7
|
import { normalizeConfig } from './normalizeConfig'
|
|
9
8
|
import isPlainObject from './isPlainObject'
|
|
10
9
|
import { cloneDeep } from './cloneDeep'
|
|
10
|
+
import { parseColorFormat } from './pluginUtils'
|
|
11
|
+
import { withAlphaValue } from './withAlphaVariable'
|
|
12
|
+
import toColorValue from './toColorValue'
|
|
11
13
|
|
|
12
14
|
function isFunction(input) {
|
|
13
15
|
return typeof input === 'function'
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
function isObject(input) {
|
|
17
|
-
return typeof input === 'object' && input !== null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
18
|
function mergeWith(target, ...sources) {
|
|
21
19
|
let customizer = sources.pop()
|
|
22
20
|
|
|
@@ -25,8 +23,8 @@ function mergeWith(target, ...sources) {
|
|
|
25
23
|
let merged = customizer(target[k], source[k])
|
|
26
24
|
|
|
27
25
|
if (merged === undefined) {
|
|
28
|
-
if (
|
|
29
|
-
target[k] = mergeWith(target[k], source[k], customizer)
|
|
26
|
+
if (isPlainObject(target[k]) && isPlainObject(source[k])) {
|
|
27
|
+
target[k] = mergeWith({}, target[k], source[k], customizer)
|
|
30
28
|
} else {
|
|
31
29
|
target[k] = source[k]
|
|
32
30
|
}
|
|
@@ -66,36 +64,6 @@ const configUtils = {
|
|
|
66
64
|
{}
|
|
67
65
|
)
|
|
68
66
|
},
|
|
69
|
-
rgb(property) {
|
|
70
|
-
if (!property.startsWith('--')) {
|
|
71
|
-
throw new Error(
|
|
72
|
-
'The rgb() helper requires a custom property name to be passed as the first argument.'
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return ({ opacityValue }) => {
|
|
77
|
-
if (opacityValue === undefined || opacityValue === 1) {
|
|
78
|
-
return `rgb(var(${property}) / 1.0)`
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return `rgb(var(${property}) / ${opacityValue})`
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
hsl(property) {
|
|
85
|
-
if (!property.startsWith('--')) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
'The hsl() helper requires a custom property name to be passed as the first argument.'
|
|
88
|
-
)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return ({ opacityValue }) => {
|
|
92
|
-
if (opacityValue === undefined || opacityValue === 1) {
|
|
93
|
-
return `hsl(var(${property}) / 1)`
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return `hsl(var(${property}) / ${opacityValue})`
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
67
|
}
|
|
100
68
|
|
|
101
69
|
function value(valueToResolve, ...args) {
|
|
@@ -130,12 +98,12 @@ function mergeThemes(themes) {
|
|
|
130
98
|
|
|
131
99
|
function mergeExtensionCustomizer(merged, value) {
|
|
132
100
|
// When we have an array of objects, we do want to merge it
|
|
133
|
-
if (Array.isArray(merged) &&
|
|
101
|
+
if (Array.isArray(merged) && isPlainObject(merged[0])) {
|
|
134
102
|
return merged.concat(value)
|
|
135
103
|
}
|
|
136
104
|
|
|
137
105
|
// When the incoming value is an array, and the existing config is an object, prepend the existing object
|
|
138
|
-
if (Array.isArray(value) &&
|
|
106
|
+
if (Array.isArray(value) && isPlainObject(value[0]) && isPlainObject(merged)) {
|
|
139
107
|
return [merged, ...value]
|
|
140
108
|
}
|
|
141
109
|
|
|
@@ -164,40 +132,81 @@ function mergeExtensions({ extend, ...theme }) {
|
|
|
164
132
|
})
|
|
165
133
|
}
|
|
166
134
|
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* @param {string} key
|
|
138
|
+
* @return {Iterable<string[] & {alpha: string | undefined}>}
|
|
139
|
+
*/
|
|
140
|
+
function* toPaths(key) {
|
|
141
|
+
let path = toPath(key)
|
|
142
|
+
|
|
143
|
+
if (path.length === 0) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
yield path
|
|
148
|
+
|
|
149
|
+
if (Array.isArray(key)) {
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let pattern = /^(.*?)\s*\/\s*([^/]+)$/
|
|
154
|
+
let matches = key.match(pattern)
|
|
155
|
+
|
|
156
|
+
if (matches !== null) {
|
|
157
|
+
let [, prefix, alpha] = matches
|
|
158
|
+
|
|
159
|
+
let newPath = toPath(prefix)
|
|
160
|
+
newPath.alpha = alpha
|
|
161
|
+
|
|
162
|
+
yield newPath
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
167
166
|
function resolveFunctionKeys(object) {
|
|
167
|
+
// theme('colors.red.500 / 0.5') -> ['colors', 'red', '500 / 0', '5]
|
|
168
|
+
|
|
168
169
|
const resolvePath = (key, defaultValue) => {
|
|
169
|
-
const path
|
|
170
|
+
for (const path of toPaths(key)) {
|
|
171
|
+
let index = 0
|
|
172
|
+
let val = object
|
|
170
173
|
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
while (val !== undefined && val !== null && index < path.length) {
|
|
175
|
+
val = val[path[index++]]
|
|
173
176
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
val = isFunction(val) ? val(resolvePath, configUtils) : val
|
|
177
|
-
}
|
|
177
|
+
let shouldResolveAsFn =
|
|
178
|
+
isFunction(val) && (path.alpha === undefined || index <= path.length - 1)
|
|
178
179
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
180
|
+
val = shouldResolveAsFn ? val(resolvePath, configUtils) : val
|
|
181
|
+
}
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
if (val !== undefined) {
|
|
184
|
+
if (path.alpha !== undefined) {
|
|
185
|
+
let normalized = parseColorFormat(val)
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
return withAlphaValue(normalized, path.alpha, toColorValue(normalized))
|
|
188
|
+
}
|
|
189
189
|
|
|
190
|
-
|
|
190
|
+
if (isPlainObject(val)) {
|
|
191
|
+
return cloneDeep(val)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return val
|
|
195
|
+
}
|
|
196
|
+
}
|
|
191
197
|
|
|
192
|
-
|
|
193
|
-
resolvePath[key] = configUtils[key]
|
|
198
|
+
return defaultValue
|
|
194
199
|
}
|
|
195
200
|
|
|
201
|
+
Object.assign(resolvePath, {
|
|
202
|
+
theme: resolvePath,
|
|
203
|
+
...configUtils,
|
|
204
|
+
})
|
|
205
|
+
|
|
196
206
|
return Object.keys(object).reduce((resolved, key) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
207
|
+
resolved[key] = isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key]
|
|
208
|
+
|
|
209
|
+
return resolved
|
|
201
210
|
}, {})
|
|
202
211
|
}
|
|
203
212
|
|
|
@@ -250,7 +259,6 @@ export default function resolveConfig(configs) {
|
|
|
250
259
|
prefix: '',
|
|
251
260
|
important: false,
|
|
252
261
|
separator: ':',
|
|
253
|
-
variantOrder: defaultConfig.variantOrder,
|
|
254
262
|
},
|
|
255
263
|
]
|
|
256
264
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
3
|
|
|
4
|
+
const defaultConfigFiles = [
|
|
5
|
+
'./tailwind.config.js',
|
|
6
|
+
'./tailwind.config.cjs',
|
|
7
|
+
'./tailwind.config.mjs',
|
|
8
|
+
'./tailwind.config.ts',
|
|
9
|
+
]
|
|
10
|
+
|
|
4
11
|
function isObject(value) {
|
|
5
12
|
return typeof value === 'object' && value !== null
|
|
6
13
|
}
|
|
@@ -43,7 +50,11 @@ export default function resolveConfigPath(pathOrConfig) {
|
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
// require('tailwindcss')
|
|
46
|
-
|
|
53
|
+
return resolveDefaultConfigPath()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function resolveDefaultConfigPath() {
|
|
57
|
+
for (const configFile of defaultConfigFiles) {
|
|
47
58
|
try {
|
|
48
59
|
const configPath = path.resolve(configFile)
|
|
49
60
|
fs.accessSync(configPath)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This splits a string on a top-level character.
|
|
3
|
+
*
|
|
4
|
+
* Regex doesn't support recursion (at least not the JS-flavored version).
|
|
5
|
+
* So we have to use a tiny state machine to keep track of paren placement.
|
|
6
|
+
*
|
|
7
|
+
* Expected behavior using commas:
|
|
8
|
+
* var(--a, 0 0 1px rgb(0, 0, 0)), 0 0 1px rgb(0, 0, 0)
|
|
9
|
+
* ─┬─ ┬ ┬ ┬
|
|
10
|
+
* x x x ╰──────── Split because top-level
|
|
11
|
+
* ╰──────────────┴──┴───────────── Ignored b/c inside >= 1 levels of parens
|
|
12
|
+
*
|
|
13
|
+
* @param {string} input
|
|
14
|
+
* @param {string} separator
|
|
15
|
+
*/
|
|
16
|
+
export function splitAtTopLevelOnly(input, separator) {
|
|
17
|
+
let stack = []
|
|
18
|
+
let parts = []
|
|
19
|
+
let lastPos = 0
|
|
20
|
+
let isEscaped = false
|
|
21
|
+
|
|
22
|
+
for (let idx = 0; idx < input.length; idx++) {
|
|
23
|
+
let char = input[idx]
|
|
24
|
+
|
|
25
|
+
if (stack.length === 0 && char === separator[0] && !isEscaped) {
|
|
26
|
+
if (separator.length === 1 || input.slice(idx, idx + separator.length) === separator) {
|
|
27
|
+
parts.push(input.slice(lastPos, idx))
|
|
28
|
+
lastPos = idx + separator.length
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (isEscaped) {
|
|
33
|
+
isEscaped = false
|
|
34
|
+
} else if (char === '\\') {
|
|
35
|
+
isEscaped = true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (char === '(' || char === '[' || char === '{') {
|
|
39
|
+
stack.push(char)
|
|
40
|
+
} else if (
|
|
41
|
+
(char === ')' && stack[stack.length - 1] === '(') ||
|
|
42
|
+
(char === ']' && stack[stack.length - 1] === '[') ||
|
|
43
|
+
(char === '}' && stack[stack.length - 1] === '{')
|
|
44
|
+
) {
|
|
45
|
+
stack.pop()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
parts.push(input.slice(lastPos))
|
|
50
|
+
|
|
51
|
+
return parts
|
|
52
|
+
}
|
package/src/util/toPath.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import postcss from 'postcss'
|
|
2
|
+
import isPlainObject from './isPlainObject'
|
|
2
3
|
|
|
3
4
|
export default function transformThemeValue(themeSection) {
|
|
4
5
|
if (['fontSize', 'outline'].includes(themeSection)) {
|
|
@@ -10,9 +11,16 @@ export default function transformThemeValue(themeSection) {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
if (themeSection === 'fontFamily') {
|
|
15
|
+
return (value) => {
|
|
16
|
+
if (typeof value === 'function') value = value({})
|
|
17
|
+
let families = Array.isArray(value) && isPlainObject(value[1]) ? value[0] : value
|
|
18
|
+
return Array.isArray(families) ? families.join(', ') : families
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
if (
|
|
14
23
|
[
|
|
15
|
-
'fontFamily',
|
|
16
24
|
'boxShadow',
|
|
17
25
|
'transitionProperty',
|
|
18
26
|
'transitionDuration',
|
|
@@ -44,8 +52,10 @@ export default function transformThemeValue(themeSection) {
|
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
return (value) => {
|
|
48
|
-
if (typeof value === 'function')
|
|
55
|
+
return (value, opts = {}) => {
|
|
56
|
+
if (typeof value === 'function') {
|
|
57
|
+
value = value(opts)
|
|
58
|
+
}
|
|
49
59
|
|
|
50
60
|
return value
|
|
51
61
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import pc from 'picocolors'
|
|
2
|
+
import log from './log'
|
|
3
|
+
|
|
4
|
+
export function validateConfig(config) {
|
|
5
|
+
if (config.content.files.length === 0) {
|
|
6
|
+
log.warn('content-problems', [
|
|
7
|
+
'The `content` option in your Tailwind CSS configuration is missing or empty.',
|
|
8
|
+
'Configure your content sources or your generated CSS will be missing styles.',
|
|
9
|
+
'https://tailwindcss.com/docs/content-configuration',
|
|
10
|
+
])
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (config.content.files.includes('auto')) {
|
|
14
|
+
log.group('auto-content-experimental', (log) => {
|
|
15
|
+
log.info([pc.bold('Automatically detecting Tailwind CSS content sources...')])
|
|
16
|
+
log.warn([
|
|
17
|
+
'Automatic content detection is experimental, and the behavior may change at any time.',
|
|
18
|
+
])
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Warn if the line-clamp plugin is installed
|
|
23
|
+
try {
|
|
24
|
+
let plugin = require('@tailwindcss/line-clamp')
|
|
25
|
+
if (config.plugins.includes(plugin)) {
|
|
26
|
+
log.warn('line-clamp-in-core', [
|
|
27
|
+
'As of Tailwind CSS v3.3, the `@tailwindcss/line-clamp` plugin is now included by default.',
|
|
28
|
+
'Remove it from the `plugins` array in your configuration to eliminate this warning.',
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
config.plugins = config.plugins.filter((p) => p !== plugin)
|
|
32
|
+
}
|
|
33
|
+
} catch {}
|
|
34
|
+
|
|
35
|
+
return config
|
|
36
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { length, percentage } from './dataTypes'
|
|
2
|
+
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/background-size#formal_syntax
|
|
7
|
+
*
|
|
8
|
+
* background-size =
|
|
9
|
+
* <bg-size>#
|
|
10
|
+
*
|
|
11
|
+
* <bg-size> =
|
|
12
|
+
* [ <length-percentage [0,∞]> | auto ]{1,2} |
|
|
13
|
+
* cover |
|
|
14
|
+
* contain
|
|
15
|
+
*
|
|
16
|
+
* <length-percentage> =
|
|
17
|
+
* <length> |
|
|
18
|
+
* <percentage>
|
|
19
|
+
*
|
|
20
|
+
* @param {string} value
|
|
21
|
+
*/
|
|
22
|
+
export function backgroundSize(value) {
|
|
23
|
+
let keywordValues = ['cover', 'contain']
|
|
24
|
+
// the <length-percentage> type will probably be a css function
|
|
25
|
+
// so we have to use `splitAtTopLevelOnly`
|
|
26
|
+
return splitAtTopLevelOnly(value, ',').every((part) => {
|
|
27
|
+
let sizes = splitAtTopLevelOnly(part, '_').filter(Boolean)
|
|
28
|
+
if (sizes.length === 1 && keywordValues.includes(sizes[0])) return true
|
|
29
|
+
|
|
30
|
+
if (sizes.length !== 1 && sizes.length !== 2) return false
|
|
31
|
+
|
|
32
|
+
return sizes.every((size) => length(size) || percentage(size) || size === 'auto')
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) Bogdan Chadkin <trysound@yandex.ru>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|