tailwindcss 0.0.0-insiders.fda68f7 → 0.0.0-oxide.6bf5e56
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 +603 -2
- package/LICENSE +1 -2
- package/README.md +14 -6
- package/colors.d.ts +3 -0
- package/colors.js +2 -304
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -4
- package/defaultTheme.d.ts +4 -0
- package/defaultTheme.js +2 -4
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +48 -0
- package/lib/cli/build/plugin.js +367 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +178 -0
- package/lib/cli/help/index.js +71 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/init/index.js +46 -0
- package/lib/cli/shared.js +13 -0
- package/lib/cli-peer-dependencies.js +22 -14
- package/lib/cli.js +217 -743
- package/lib/constants.js +41 -34
- package/lib/corePluginList.js +178 -5
- package/lib/corePlugins.js +3879 -2941
- package/lib/css/preflight.css +22 -9
- package/lib/featureFlags.js +61 -50
- package/lib/index.js +45 -28
- package/lib/lib/cacheInvalidation.js +90 -0
- package/lib/lib/collapseAdjacentRules.js +52 -36
- package/lib/lib/collapseDuplicateDeclarations.js +83 -0
- package/lib/lib/content.js +176 -0
- package/lib/lib/defaultExtractor.js +236 -0
- package/lib/lib/detectNesting.js +37 -0
- package/lib/lib/evaluateTailwindFunctions.js +203 -161
- package/lib/lib/expandApplyAtRules.js +502 -221
- package/lib/lib/expandTailwindAtRules.js +258 -243
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +775 -320
- package/lib/lib/getModuleDependencies.js +44 -46
- package/lib/lib/normalizeTailwindDirectives.js +79 -60
- package/lib/lib/offsets.js +217 -0
- package/lib/lib/partitionApplyAtRules.js +56 -0
- package/lib/lib/regex.js +60 -0
- package/lib/lib/resolveDefaultsAtRules.js +150 -94
- package/lib/lib/setupContextUtils.js +1146 -599
- package/lib/lib/setupTrackingContext.js +129 -177
- package/lib/lib/sharedState.js +53 -21
- package/lib/lib/substituteScreenAtRules.js +26 -28
- 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 +58 -53
- package/lib/public/colors.js +331 -0
- package/lib/public/create-plugin.js +15 -0
- package/lib/public/default-config.js +16 -0
- package/lib/public/default-theme.js +16 -0
- package/lib/public/resolve-config.js +22 -0
- package/lib/util/bigSign.js +7 -6
- package/lib/util/buildMediaQuery.js +21 -32
- package/lib/util/cloneDeep.js +16 -14
- package/lib/util/cloneNodes.js +29 -15
- package/lib/util/color.js +90 -66
- package/lib/util/configurePlugins.js +17 -15
- package/lib/util/createPlugin.js +23 -26
- package/lib/util/createUtilityPlugin.js +46 -46
- package/lib/util/dataTypes.js +242 -0
- package/lib/util/defaults.js +20 -15
- package/lib/util/escapeClassName.js +18 -17
- package/lib/util/escapeCommas.js +7 -6
- package/lib/util/flattenColorPalette.js +13 -12
- package/lib/util/formatVariantSelector.js +285 -0
- package/lib/util/getAllConfigs.js +44 -18
- package/lib/util/hashConfig.js +15 -12
- package/lib/util/isKeyframeRule.js +7 -6
- package/lib/util/isPlainObject.js +11 -11
- package/lib/util/isSyntacticallyValidPropertyValue.js +72 -0
- package/lib/util/log.js +52 -33
- package/lib/util/nameClass.js +37 -26
- package/lib/util/negateValue.js +31 -17
- package/lib/util/normalizeConfig.js +281 -0
- package/lib/util/normalizeScreens.js +170 -0
- package/lib/util/parseAnimationValue.js +85 -54
- package/lib/util/parseBoxShadowValue.js +84 -0
- package/lib/util/parseDependency.js +41 -70
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +30 -24
- package/lib/util/pluginUtils.js +252 -287
- package/lib/util/prefixSelector.js +20 -20
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +221 -256
- package/lib/util/resolveConfigPath.js +43 -48
- package/lib/util/responsive.js +18 -14
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +8 -7
- package/lib/util/toColorValue.js +7 -6
- package/lib/util/toPath.js +27 -8
- package/lib/util/transformThemeValue.js +67 -28
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +67 -57
- package/nesting/index.js +2 -12
- package/package.json +60 -65
- package/peers/index.js +76445 -84221
- package/plugin.d.ts +11 -0
- package/plugin.js +1 -2
- package/resolveConfig.d.ts +12 -0
- package/resolveConfig.js +2 -7
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +105 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/deps.js +56 -0
- package/src/cli/build/index.js +49 -0
- package/src/cli/build/plugin.js +439 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +227 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +3 -0
- package/src/cli/init/index.js +50 -0
- package/src/cli/shared.js +6 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +50 -575
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +2405 -1948
- package/src/css/preflight.css +22 -9
- package/src/featureFlags.js +26 -10
- package/src/index.js +19 -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/content.js +212 -0
- package/src/lib/defaultExtractor.js +211 -0
- package/src/lib/detectNesting.js +39 -0
- package/src/lib/evaluateTailwindFunctions.js +84 -10
- package/src/lib/expandApplyAtRules.js +508 -153
- package/src/lib/expandTailwindAtRules.js +130 -104
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +596 -70
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/offsets.js +270 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +105 -47
- package/src/lib/setupContextUtils.js +828 -196
- package/src/lib/setupTrackingContext.js +19 -54
- package/src/lib/sharedState.js +45 -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 +19 -2
- package/src/public/colors.js +300 -0
- package/src/public/create-plugin.js +2 -0
- package/src/public/default-config.js +4 -0
- package/src/public/default-theme.js +4 -0
- package/src/public/resolve-config.js +7 -0
- package/src/util/buildMediaQuery.js +14 -16
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -11
- package/src/util/dataTypes.js +256 -0
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +319 -0
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +14 -6
- package/src/util/negateValue.js +15 -5
- package/src/util/normalizeConfig.js +300 -0
- package/src/util/normalizeScreens.js +140 -0
- package/src/util/parseAnimationValue.js +7 -1
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/parseDependency.js +37 -38
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +216 -197
- package/src/util/prefixSelector.js +7 -8
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +86 -91
- package/src/util/splitAtTopLevelOnly.js +45 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +33 -8
- package/src/util/validateConfig.js +13 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +14 -9
- package/stubs/defaultConfig.stub.js +186 -117
- package/stubs/simpleConfig.stub.js +1 -1
- package/types/config.d.ts +362 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +342 -0
- package/types/index.d.ts +7 -0
- package/lib/lib/setupWatchingContext.js +0 -331
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -306
package/lib/lib/generateRules.js
CHANGED
|
@@ -1,116 +1,186 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getClassNameFromSelector: ()=>getClassNameFromSelector,
|
|
13
|
+
resolveMatches: ()=>resolveMatches,
|
|
14
|
+
generateRules: ()=>generateRules
|
|
15
|
+
});
|
|
16
|
+
const _postcss = /*#__PURE__*/ _interopRequireDefault(require("postcss"));
|
|
17
|
+
const _postcssSelectorParser = /*#__PURE__*/ _interopRequireDefault(require("postcss-selector-parser"));
|
|
18
|
+
const _parseObjectStyles = /*#__PURE__*/ _interopRequireDefault(require("../util/parseObjectStyles"));
|
|
19
|
+
const _isPlainObject = /*#__PURE__*/ _interopRequireDefault(require("../util/isPlainObject"));
|
|
20
|
+
const _prefixSelector = /*#__PURE__*/ _interopRequireDefault(require("../util/prefixSelector"));
|
|
21
|
+
const _pluginUtils = require("../util/pluginUtils");
|
|
22
|
+
const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
|
|
23
|
+
const _sharedState = /*#__PURE__*/ _interopRequireWildcard(require("./sharedState"));
|
|
24
|
+
const _formatVariantSelector = require("../util/formatVariantSelector");
|
|
25
|
+
const _nameClass = require("../util/nameClass");
|
|
26
|
+
const _dataTypes = require("../util/dataTypes");
|
|
27
|
+
const _setupContextUtils = require("./setupContextUtils");
|
|
28
|
+
const _isSyntacticallyValidPropertyValue = /*#__PURE__*/ _interopRequireDefault(require("../util/isSyntacticallyValidPropertyValue"));
|
|
29
|
+
const _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
|
|
30
|
+
const _featureFlags = require("../featureFlags");
|
|
31
|
+
function _interopRequireDefault(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
37
|
+
if (typeof WeakMap !== "function") return null;
|
|
38
|
+
var cacheBabelInterop = new WeakMap();
|
|
39
|
+
var cacheNodeInterop = new WeakMap();
|
|
40
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
41
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
42
|
+
})(nodeInterop);
|
|
43
|
+
}
|
|
44
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
45
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
49
|
+
return {
|
|
50
|
+
default: obj
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
54
|
+
if (cache && cache.has(obj)) {
|
|
55
|
+
return cache.get(obj);
|
|
56
|
+
}
|
|
57
|
+
var newObj = {};
|
|
58
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
59
|
+
for(var key in obj){
|
|
60
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
61
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
62
|
+
if (desc && (desc.get || desc.set)) {
|
|
63
|
+
Object.defineProperty(newObj, key, desc);
|
|
64
|
+
} else {
|
|
65
|
+
newObj[key] = obj[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
newObj.default = obj;
|
|
70
|
+
if (cache) {
|
|
71
|
+
cache.set(obj, newObj);
|
|
72
|
+
}
|
|
73
|
+
return newObj;
|
|
74
|
+
}
|
|
75
|
+
let classNameParser = (0, _postcssSelectorParser.default)((selectors)=>{
|
|
76
|
+
return selectors.first.filter(({ type })=>type === "class").pop().value;
|
|
27
77
|
});
|
|
28
|
-
|
|
29
78
|
function getClassNameFromSelector(selector) {
|
|
30
|
-
|
|
31
|
-
}
|
|
79
|
+
return classNameParser.transformSync(selector);
|
|
80
|
+
}
|
|
81
|
+
// Generate match permutations for a class candidate, like:
|
|
32
82
|
// ['ring-offset-blue', '100']
|
|
33
83
|
// ['ring-offset', 'blue-100']
|
|
34
84
|
// ['ring', 'offset-blue-100']
|
|
35
85
|
// Example with dynamic classes:
|
|
36
86
|
// ['grid-cols', '[[linename],1fr,auto]']
|
|
37
87
|
// ['grid', 'cols-[[linename],1fr,auto]']
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
88
|
+
function* candidatePermutations(candidate) {
|
|
89
|
+
let lastIndex = Infinity;
|
|
90
|
+
while(lastIndex >= 0){
|
|
91
|
+
let dashIdx;
|
|
92
|
+
let wasSlash = false;
|
|
93
|
+
if (lastIndex === Infinity && candidate.endsWith("]")) {
|
|
94
|
+
let bracketIdx = candidate.indexOf("[");
|
|
95
|
+
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
96
|
+
// eg. string[]
|
|
97
|
+
if (candidate[bracketIdx - 1] === "-") {
|
|
98
|
+
dashIdx = bracketIdx - 1;
|
|
99
|
+
} else if (candidate[bracketIdx - 1] === "/") {
|
|
100
|
+
dashIdx = bracketIdx - 1;
|
|
101
|
+
wasSlash = true;
|
|
102
|
+
} else {
|
|
103
|
+
dashIdx = -1;
|
|
104
|
+
}
|
|
105
|
+
} else if (lastIndex === Infinity && candidate.includes("/")) {
|
|
106
|
+
dashIdx = candidate.lastIndexOf("/");
|
|
107
|
+
wasSlash = true;
|
|
108
|
+
} else {
|
|
109
|
+
dashIdx = candidate.lastIndexOf("-", lastIndex);
|
|
110
|
+
}
|
|
111
|
+
if (dashIdx < 0) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
let prefix = candidate.slice(0, dashIdx);
|
|
115
|
+
let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1);
|
|
116
|
+
lastIndex = dashIdx - 1;
|
|
117
|
+
// TODO: This feels a bit hacky
|
|
118
|
+
if (prefix === "" || modifier === "/") {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
yield [
|
|
122
|
+
prefix,
|
|
123
|
+
modifier
|
|
124
|
+
];
|
|
125
|
+
}
|
|
64
126
|
}
|
|
65
|
-
|
|
66
127
|
function applyPrefix(matches, context) {
|
|
67
|
-
|
|
128
|
+
if (matches.length === 0 || context.tailwindConfig.prefix === "") {
|
|
129
|
+
return matches;
|
|
130
|
+
}
|
|
131
|
+
for (let match of matches){
|
|
132
|
+
let [meta] = match;
|
|
133
|
+
if (meta.options.respectPrefix) {
|
|
134
|
+
let container = _postcss.default.root({
|
|
135
|
+
nodes: [
|
|
136
|
+
match[1].clone()
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
let classCandidate = match[1].raws.tailwind.classCandidate;
|
|
140
|
+
container.walkRules((r)=>{
|
|
141
|
+
// If this is a negative utility with a dash *before* the prefix we
|
|
142
|
+
// have to ensure that the generated selector matches the candidate
|
|
143
|
+
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
144
|
+
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
145
|
+
let shouldPrependNegative = classCandidate.startsWith("-");
|
|
146
|
+
r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
|
|
147
|
+
});
|
|
148
|
+
match[1] = container.nodes[0];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
68
151
|
return matches;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for (let match of matches) {
|
|
72
|
-
let [meta] = match;
|
|
73
|
-
|
|
74
|
-
if (meta.options.respectPrefix) {
|
|
75
|
-
let container = _postcss.default.root({
|
|
76
|
-
nodes: [match[1].clone()]
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
container.walkRules(r => {
|
|
80
|
-
r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector);
|
|
81
|
-
});
|
|
82
|
-
match[1] = container.nodes[0];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return matches;
|
|
87
152
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
153
|
+
function applyImportant(matches, classCandidate) {
|
|
154
|
+
if (matches.length === 0) {
|
|
155
|
+
return matches;
|
|
156
|
+
}
|
|
157
|
+
let result = [];
|
|
158
|
+
for (let [meta, rule] of matches){
|
|
159
|
+
let container = _postcss.default.root({
|
|
160
|
+
nodes: [
|
|
161
|
+
rule.clone()
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
container.walkRules((r)=>{
|
|
165
|
+
r.selector = (0, _pluginUtils.updateAllClasses)((0, _pluginUtils.filterSelectorsForClass)(r.selector, classCandidate), (className)=>{
|
|
166
|
+
if (className === classCandidate) {
|
|
167
|
+
return `!${className}`;
|
|
168
|
+
}
|
|
169
|
+
return className;
|
|
170
|
+
});
|
|
171
|
+
r.walkDecls((d)=>d.important = true);
|
|
172
|
+
});
|
|
173
|
+
result.push([
|
|
174
|
+
{
|
|
175
|
+
...meta,
|
|
176
|
+
important: true
|
|
177
|
+
},
|
|
178
|
+
container.nodes[0]
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
// Takes a list of rule tuples and applies a variant like `hover`, sm`,
|
|
114
184
|
// whatever to it. We used to do some extra caching here to avoid generating
|
|
115
185
|
// a variant of the same rule more than once, but this was never hit because
|
|
116
186
|
// we cache at the entire selector level further up the tree.
|
|
@@ -118,245 +188,630 @@ function applyImportant(matches) {
|
|
|
118
188
|
// Technically you can get a cache hit if you have `hover:focus:text-center`
|
|
119
189
|
// and `focus:hover:text-center` in the same project, but it doesn't feel
|
|
120
190
|
// worth the complexity for that case.
|
|
121
|
-
|
|
122
|
-
|
|
123
191
|
function applyVariant(variant, matches, context) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
nodes: [rule.clone()]
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
for (let [variantSort, variantFunction] of variantFunctionTuples) {
|
|
143
|
-
let clone = container.clone();
|
|
144
|
-
|
|
145
|
-
function modifySelectors(modifierFunction) {
|
|
146
|
-
clone.each(rule => {
|
|
147
|
-
if (rule.type !== 'rule') {
|
|
148
|
-
return;
|
|
192
|
+
if (matches.length === 0) {
|
|
193
|
+
return matches;
|
|
194
|
+
}
|
|
195
|
+
/** @type {{modifier: string | null, value: string | null}} */ let args = {
|
|
196
|
+
modifier: null,
|
|
197
|
+
value: _sharedState.NONE
|
|
198
|
+
};
|
|
199
|
+
// Retrieve "modifier"
|
|
200
|
+
{
|
|
201
|
+
let match = /(.*)\/(.*)$/g.exec(variant);
|
|
202
|
+
if (match) {
|
|
203
|
+
variant = match[1];
|
|
204
|
+
args.modifier = match[2];
|
|
205
|
+
if (!(0, _featureFlags.flagEnabled)(context.tailwindConfig, "generalizedModifiers")) {
|
|
206
|
+
return [];
|
|
149
207
|
}
|
|
150
|
-
|
|
151
|
-
rule.selectors = rule.selectors.map(selector => {
|
|
152
|
-
return modifierFunction({
|
|
153
|
-
get className() {
|
|
154
|
-
return getClassNameFromSelector(selector);
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
selector
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
return clone;
|
|
162
208
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
209
|
+
}
|
|
210
|
+
// Retrieve "arbitrary value"
|
|
211
|
+
if (variant.endsWith("]") && !variant.startsWith("[")) {
|
|
212
|
+
// We either have:
|
|
213
|
+
// @[200px]
|
|
214
|
+
// group-[:hover]
|
|
215
|
+
//
|
|
216
|
+
// But we don't want:
|
|
217
|
+
// @-[200px] (`-` is incorrect)
|
|
218
|
+
// group[:hover] (`-` is missing)
|
|
219
|
+
let match1 = /(.)(-?)\[(.*)\]/g.exec(variant);
|
|
220
|
+
if (match1) {
|
|
221
|
+
let [, char, seperator, value] = match1;
|
|
222
|
+
// @-[200px] case
|
|
223
|
+
if (char === "@" && seperator === "-") return [];
|
|
224
|
+
// group[:hover] case
|
|
225
|
+
if (char !== "@" && seperator === "") return [];
|
|
226
|
+
variant = variant.replace(`${seperator}[${value}]`, "");
|
|
227
|
+
args.value = value;
|
|
172
228
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
229
|
+
}
|
|
230
|
+
// Register arbitrary variants
|
|
231
|
+
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
|
|
232
|
+
let selector = (0, _dataTypes.normalize)(variant.slice(1, -1));
|
|
233
|
+
if (!(0, _setupContextUtils.isValidVariantFormatString)(selector)) {
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
let fn = (0, _setupContextUtils.parseVariant)(selector);
|
|
237
|
+
let sort = context.offsets.recordVariant(variant);
|
|
238
|
+
context.variantMap.set(variant, [
|
|
239
|
+
[
|
|
240
|
+
sort,
|
|
241
|
+
fn
|
|
242
|
+
]
|
|
243
|
+
]);
|
|
244
|
+
}
|
|
245
|
+
if (context.variantMap.has(variant)) {
|
|
246
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice();
|
|
247
|
+
let result = [];
|
|
248
|
+
for (let [meta, rule] of matches){
|
|
249
|
+
// Don't generate variants for user css
|
|
250
|
+
if (meta.layer === "user") {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
let container = _postcss.default.root({
|
|
254
|
+
nodes: [
|
|
255
|
+
rule.clone()
|
|
256
|
+
]
|
|
257
|
+
});
|
|
258
|
+
for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples){
|
|
259
|
+
let clone = (containerFromArray !== null && containerFromArray !== void 0 ? containerFromArray : container).clone();
|
|
260
|
+
let collectedFormats = [];
|
|
261
|
+
function prepareBackup() {
|
|
262
|
+
// Already prepared, chicken out
|
|
263
|
+
if (clone.raws.neededBackup) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
clone.raws.neededBackup = true;
|
|
267
|
+
clone.walkRules((rule)=>rule.raws.originalSelector = rule.selector);
|
|
268
|
+
}
|
|
269
|
+
function modifySelectors(modifierFunction) {
|
|
270
|
+
prepareBackup();
|
|
271
|
+
clone.each((rule)=>{
|
|
272
|
+
if (rule.type !== "rule") {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
276
|
+
return modifierFunction({
|
|
277
|
+
get className () {
|
|
278
|
+
return getClassNameFromSelector(selector);
|
|
279
|
+
},
|
|
280
|
+
selector
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
return clone;
|
|
285
|
+
}
|
|
286
|
+
let ruleWithVariant = variantFunction({
|
|
287
|
+
// Public API
|
|
288
|
+
get container () {
|
|
289
|
+
prepareBackup();
|
|
290
|
+
return clone;
|
|
291
|
+
},
|
|
292
|
+
separator: context.tailwindConfig.separator,
|
|
293
|
+
modifySelectors,
|
|
294
|
+
// Private API for now
|
|
295
|
+
wrap (wrapper) {
|
|
296
|
+
let nodes = clone.nodes;
|
|
297
|
+
clone.removeAll();
|
|
298
|
+
wrapper.append(nodes);
|
|
299
|
+
clone.append(wrapper);
|
|
300
|
+
},
|
|
301
|
+
format (selectorFormat) {
|
|
302
|
+
collectedFormats.push(selectorFormat);
|
|
303
|
+
},
|
|
304
|
+
args
|
|
305
|
+
});
|
|
306
|
+
// It can happen that a list of format strings is returned from within the function. In that
|
|
307
|
+
// case, we have to process them as well. We can use the existing `variantSort`.
|
|
308
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
309
|
+
for (let [idx, variantFunction1] of ruleWithVariant.entries()){
|
|
310
|
+
// This is a little bit scary since we are pushing to an array of items that we are
|
|
311
|
+
// currently looping over. However, you can also think of it like a processing queue
|
|
312
|
+
// where you keep handling jobs until everything is done and each job can queue more
|
|
313
|
+
// jobs if needed.
|
|
314
|
+
variantFunctionTuples.push([
|
|
315
|
+
context.offsets.applyParallelOffset(variantSort, idx),
|
|
316
|
+
variantFunction1,
|
|
317
|
+
// If the clone has been modified we have to pass that back
|
|
318
|
+
// though so each rule can use the modified container
|
|
319
|
+
clone.clone()
|
|
320
|
+
]);
|
|
321
|
+
}
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (typeof ruleWithVariant === "string") {
|
|
325
|
+
collectedFormats.push(ruleWithVariant);
|
|
326
|
+
}
|
|
327
|
+
if (ruleWithVariant === null) {
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
// We had to backup selectors, therefore we assume that somebody touched
|
|
331
|
+
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
332
|
+
// can restore the selectors, and collect the format strings.
|
|
333
|
+
if (clone.raws.neededBackup) {
|
|
334
|
+
delete clone.raws.neededBackup;
|
|
335
|
+
clone.walkRules((rule)=>{
|
|
336
|
+
let before = rule.raws.originalSelector;
|
|
337
|
+
if (!before) return;
|
|
338
|
+
delete rule.raws.originalSelector;
|
|
339
|
+
if (before === rule.selector) return; // No mutation happened
|
|
340
|
+
let modified = rule.selector;
|
|
341
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
342
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
343
|
+
// However, plugin authors probably also prepend or append certain
|
|
344
|
+
// classes, pseudos, ids, ...
|
|
345
|
+
let rebuiltBase = (0, _postcssSelectorParser.default)((selectors)=>{
|
|
346
|
+
selectors.walkClasses((classNode)=>{
|
|
347
|
+
classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
|
|
348
|
+
});
|
|
349
|
+
}).processSync(before);
|
|
350
|
+
// Now that we know the original selector, the new selector, and
|
|
351
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
352
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
353
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
354
|
+
//
|
|
355
|
+
// E.g.:
|
|
356
|
+
// variant: foo
|
|
357
|
+
// selector: .markdown > p
|
|
358
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
359
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
360
|
+
// format: .foo &
|
|
361
|
+
collectedFormats.push(modified.replace(rebuiltBase, "&"));
|
|
362
|
+
rule.selector = before;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
// This tracks the originating layer for the variant
|
|
366
|
+
// For example:
|
|
367
|
+
// .sm:underline {} is a variant of something in the utilities layer
|
|
368
|
+
// .sm:container {} is a variant of the container component
|
|
369
|
+
clone.nodes[0].raws.tailwind = {
|
|
370
|
+
...clone.nodes[0].raws.tailwind,
|
|
371
|
+
parentLayer: meta.layer
|
|
372
|
+
};
|
|
373
|
+
var _collectedFormats;
|
|
374
|
+
let withOffset = [
|
|
375
|
+
{
|
|
376
|
+
...meta,
|
|
377
|
+
sort: context.offsets.applyVariantOffset(meta.sort, variantSort, Object.assign(args, context.variantOptions.get(variant))),
|
|
378
|
+
collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats),
|
|
379
|
+
isArbitraryVariant: isArbitraryValue(variant)
|
|
380
|
+
},
|
|
381
|
+
clone.nodes[0]
|
|
382
|
+
];
|
|
383
|
+
result.push(withOffset);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
return [];
|
|
185
389
|
}
|
|
186
|
-
|
|
187
390
|
function parseRules(rule, cache, options = {}) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
391
|
+
// PostCSS node
|
|
392
|
+
if (!(0, _isPlainObject.default)(rule) && !Array.isArray(rule)) {
|
|
393
|
+
return [
|
|
394
|
+
[
|
|
395
|
+
rule
|
|
396
|
+
],
|
|
397
|
+
options
|
|
398
|
+
];
|
|
399
|
+
}
|
|
400
|
+
// Tuple
|
|
401
|
+
if (Array.isArray(rule)) {
|
|
402
|
+
return parseRules(rule[0], cache, rule[1]);
|
|
403
|
+
}
|
|
404
|
+
// Simple object
|
|
405
|
+
if (!cache.has(rule)) {
|
|
406
|
+
cache.set(rule, (0, _parseObjectStyles.default)(rule));
|
|
407
|
+
}
|
|
408
|
+
return [
|
|
409
|
+
cache.get(rule),
|
|
410
|
+
options
|
|
411
|
+
];
|
|
204
412
|
}
|
|
205
|
-
|
|
206
|
-
function
|
|
207
|
-
|
|
208
|
-
yield [context.candidateRuleMap.get(classCandidate), 'DEFAULT'];
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
let candidatePrefix = classCandidate;
|
|
212
|
-
let negative = false;
|
|
213
|
-
const twConfigPrefix = context.tailwindConfig.prefix || '';
|
|
214
|
-
const twConfigPrefixLen = twConfigPrefix.length;
|
|
215
|
-
|
|
216
|
-
if (candidatePrefix[twConfigPrefixLen] === '-') {
|
|
217
|
-
negative = true;
|
|
218
|
-
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)) {
|
|
222
|
-
if (context.candidateRuleMap.has(prefix)) {
|
|
223
|
-
yield [context.candidateRuleMap.get(prefix), negative ? `-${modifier}` : modifier];
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
413
|
+
const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
|
|
414
|
+
function isValidPropName(name) {
|
|
415
|
+
return IS_VALID_PROPERTY_NAME.test(name);
|
|
227
416
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
417
|
+
/**
|
|
418
|
+
* @param {string} declaration
|
|
419
|
+
* @returns {boolean}
|
|
420
|
+
*/ function looksLikeUri(declaration) {
|
|
421
|
+
// Quick bailout for obvious non-urls
|
|
422
|
+
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
423
|
+
if (!declaration.includes("://")) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
const url = new URL(declaration);
|
|
428
|
+
return url.scheme !== "" && url.host !== "";
|
|
429
|
+
} catch (err) {
|
|
430
|
+
// Definitely not a valid url
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
231
433
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (classCandidate.startsWith('!')) {
|
|
239
|
-
important = true;
|
|
240
|
-
classCandidate = classCandidate.slice(1);
|
|
241
|
-
} // TODO: Reintroduce this in ways that doesn't break on false positives
|
|
242
|
-
// function sortAgainst(toSort, against) {
|
|
243
|
-
// return toSort.slice().sort((a, z) => {
|
|
244
|
-
// return bigSign(against.get(a)[0] - against.get(z)[0])
|
|
245
|
-
// })
|
|
246
|
-
// }
|
|
247
|
-
// let sorted = sortAgainst(variants, context.variantMap)
|
|
248
|
-
// if (sorted.toString() !== variants.toString()) {
|
|
249
|
-
// let corrected = sorted.reverse().concat(classCandidate).join(':')
|
|
250
|
-
// throw new Error(`Class ${candidate} should be written as ${corrected}`)
|
|
251
|
-
// }
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)) {
|
|
255
|
-
let matches = [];
|
|
256
|
-
let [plugins, modifier] = matchedPlugins;
|
|
257
|
-
|
|
258
|
-
for (let [sort, plugin] of plugins) {
|
|
259
|
-
if (typeof plugin === 'function') {
|
|
260
|
-
for (let ruleSet of [].concat(plugin(modifier))) {
|
|
261
|
-
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
262
|
-
|
|
263
|
-
for (let rule of rules) {
|
|
264
|
-
matches.push([{ ...sort,
|
|
265
|
-
options: { ...sort.options,
|
|
266
|
-
...options
|
|
267
|
-
}
|
|
268
|
-
}, rule]);
|
|
269
|
-
}
|
|
434
|
+
function isParsableNode(node) {
|
|
435
|
+
let isParsable = true;
|
|
436
|
+
node.walkDecls((decl)=>{
|
|
437
|
+
if (!isParsableCssValue(decl.name, decl.value)) {
|
|
438
|
+
isParsable = false;
|
|
439
|
+
return false;
|
|
270
440
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
441
|
+
});
|
|
442
|
+
return isParsable;
|
|
443
|
+
}
|
|
444
|
+
function isParsableCssValue(property, value) {
|
|
445
|
+
// We don't want to to treat [https://example.com] as a custom property
|
|
446
|
+
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
447
|
+
// So we short-circuit here by checking if the custom property looks like a url
|
|
448
|
+
if (looksLikeUri(`${property}:${value}`)) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
try {
|
|
452
|
+
_postcss.default.parse(`a{${property}:${value}}`).toResult();
|
|
453
|
+
return true;
|
|
454
|
+
} catch (err) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function extractArbitraryProperty(classCandidate, context) {
|
|
459
|
+
var ref;
|
|
460
|
+
let [, property, value] = (ref = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && ref !== void 0 ? ref : [];
|
|
461
|
+
if (value === undefined) {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
if (!isValidPropName(property)) {
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
if (!(0, _isSyntacticallyValidPropertyValue.default)(value)) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
let normalized = (0, _dataTypes.normalize)(value);
|
|
471
|
+
if (!isParsableCssValue(property, normalized)) {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
let sort = context.offsets.arbitraryProperty();
|
|
475
|
+
return [
|
|
476
|
+
[
|
|
477
|
+
{
|
|
478
|
+
sort,
|
|
479
|
+
layer: "utilities"
|
|
480
|
+
},
|
|
481
|
+
()=>({
|
|
482
|
+
[(0, _nameClass.asClass)(classCandidate)]: {
|
|
483
|
+
[property]: normalized
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
]
|
|
487
|
+
];
|
|
488
|
+
}
|
|
489
|
+
function* resolveMatchedPlugins(classCandidate, context) {
|
|
490
|
+
if (context.candidateRuleMap.has(classCandidate)) {
|
|
491
|
+
yield [
|
|
492
|
+
context.candidateRuleMap.get(classCandidate),
|
|
493
|
+
"DEFAULT"
|
|
494
|
+
];
|
|
495
|
+
}
|
|
496
|
+
yield* function*(arbitraryPropertyRule) {
|
|
497
|
+
if (arbitraryPropertyRule !== null) {
|
|
498
|
+
yield [
|
|
499
|
+
arbitraryPropertyRule,
|
|
500
|
+
"DEFAULT"
|
|
501
|
+
];
|
|
282
502
|
}
|
|
283
|
-
|
|
503
|
+
}(extractArbitraryProperty(classCandidate, context));
|
|
504
|
+
let candidatePrefix = classCandidate;
|
|
505
|
+
let negative = false;
|
|
506
|
+
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
507
|
+
const twConfigPrefixLen = twConfigPrefix.length;
|
|
508
|
+
const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
|
|
509
|
+
if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
|
|
510
|
+
negative = true;
|
|
511
|
+
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
512
|
+
}
|
|
513
|
+
if (negative && context.candidateRuleMap.has(candidatePrefix)) {
|
|
514
|
+
yield [
|
|
515
|
+
context.candidateRuleMap.get(candidatePrefix),
|
|
516
|
+
"-DEFAULT"
|
|
517
|
+
];
|
|
518
|
+
}
|
|
519
|
+
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
|
|
520
|
+
if (context.candidateRuleMap.has(prefix)) {
|
|
521
|
+
yield [
|
|
522
|
+
context.candidateRuleMap.get(prefix),
|
|
523
|
+
negative ? `-${modifier}` : modifier
|
|
524
|
+
];
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function splitWithSeparator(input, separator) {
|
|
529
|
+
if (input === _sharedState.NOT_ON_DEMAND) {
|
|
530
|
+
return [
|
|
531
|
+
_sharedState.NOT_ON_DEMAND
|
|
532
|
+
];
|
|
284
533
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
534
|
+
return (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(input, separator);
|
|
535
|
+
}
|
|
536
|
+
function* recordCandidates(matches, classCandidate) {
|
|
537
|
+
for (const match of matches){
|
|
538
|
+
var ref;
|
|
539
|
+
var ref1;
|
|
540
|
+
match[1].raws.tailwind = {
|
|
541
|
+
...match[1].raws.tailwind,
|
|
542
|
+
classCandidate,
|
|
543
|
+
preserveSource: (ref1 = (ref = match[0].options) === null || ref === void 0 ? void 0 : ref.preserveSource) !== null && ref1 !== void 0 ? ref1 : false
|
|
544
|
+
};
|
|
545
|
+
yield match;
|
|
290
546
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
547
|
+
}
|
|
548
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
549
|
+
let separator = context.tailwindConfig.separator;
|
|
550
|
+
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
551
|
+
let important = false;
|
|
552
|
+
if (classCandidate.startsWith("!")) {
|
|
553
|
+
important = true;
|
|
554
|
+
classCandidate = classCandidate.slice(1);
|
|
555
|
+
}
|
|
556
|
+
if ((0, _featureFlags.flagEnabled)(context.tailwindConfig, "variantGrouping")) {
|
|
557
|
+
if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
|
|
558
|
+
let base = variants.slice().reverse().join(separator);
|
|
559
|
+
for (let part of (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(classCandidate.slice(1, -1), ",")){
|
|
560
|
+
yield* resolveMatches(base + separator + part, context, original);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
294
563
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
564
|
+
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
565
|
+
// function sortAgainst(toSort, against) {
|
|
566
|
+
// return toSort.slice().sort((a, z) => {
|
|
567
|
+
// return bigSign(against.get(a)[0] - against.get(z)[0])
|
|
568
|
+
// })
|
|
569
|
+
// }
|
|
570
|
+
// let sorted = sortAgainst(variants, context.variantMap)
|
|
571
|
+
// if (sorted.toString() !== variants.toString()) {
|
|
572
|
+
// let corrected = sorted.reverse().concat(classCandidate).join(':')
|
|
573
|
+
// throw new Error(`Class ${candidate} should be written as ${corrected}`)
|
|
574
|
+
// }
|
|
575
|
+
for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)){
|
|
576
|
+
let matches = [];
|
|
577
|
+
let typesByMatches = new Map();
|
|
578
|
+
let [plugins, modifier] = matchedPlugins;
|
|
579
|
+
let isOnlyPlugin = plugins.length === 1;
|
|
580
|
+
for (let [sort, plugin] of plugins){
|
|
581
|
+
let matchesPerPlugin = [];
|
|
582
|
+
if (typeof plugin === "function") {
|
|
583
|
+
for (let ruleSet of [].concat(plugin(modifier, {
|
|
584
|
+
isOnlyPlugin
|
|
585
|
+
}))){
|
|
586
|
+
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
587
|
+
for (let rule of rules){
|
|
588
|
+
matchesPerPlugin.push([
|
|
589
|
+
{
|
|
590
|
+
...sort,
|
|
591
|
+
options: {
|
|
592
|
+
...sort.options,
|
|
593
|
+
...options
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
rule
|
|
597
|
+
]);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
} else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
|
|
601
|
+
let ruleSet1 = plugin;
|
|
602
|
+
let [rules1, options1] = parseRules(ruleSet1, context.postCssNodeCache);
|
|
603
|
+
for (let rule1 of rules1){
|
|
604
|
+
matchesPerPlugin.push([
|
|
605
|
+
{
|
|
606
|
+
...sort,
|
|
607
|
+
options: {
|
|
608
|
+
...sort.options,
|
|
609
|
+
...options1
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
rule1
|
|
613
|
+
]);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (matchesPerPlugin.length > 0) {
|
|
617
|
+
var ref;
|
|
618
|
+
var ref1, _options;
|
|
619
|
+
let matchingTypes = Array.from((0, _pluginUtils.getMatchingTypes)((ref1 = (ref = sort.options) === null || ref === void 0 ? void 0 : ref.types) !== null && ref1 !== void 0 ? ref1 : [], modifier, (_options = sort.options) !== null && _options !== void 0 ? _options : {}, context.tailwindConfig)).map(([_, type])=>type);
|
|
620
|
+
if (matchingTypes.length > 0) {
|
|
621
|
+
typesByMatches.set(matchesPerPlugin, matchingTypes);
|
|
622
|
+
}
|
|
623
|
+
matches.push(matchesPerPlugin);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (isArbitraryValue(modifier)) {
|
|
627
|
+
if (matches.length > 1) {
|
|
628
|
+
// Partition plugins in 2 categories so that we can start searching in the plugins that
|
|
629
|
+
// don't have `any` as a type first.
|
|
630
|
+
let [withAny, withoutAny] = matches.reduce((group, plugin)=>{
|
|
631
|
+
let hasAnyType = plugin.some(([{ options }])=>options.types.some(({ type })=>type === "any"));
|
|
632
|
+
if (hasAnyType) {
|
|
633
|
+
group[0].push(plugin);
|
|
634
|
+
} else {
|
|
635
|
+
group[1].push(plugin);
|
|
636
|
+
}
|
|
637
|
+
return group;
|
|
638
|
+
}, [
|
|
639
|
+
[],
|
|
640
|
+
[]
|
|
641
|
+
]);
|
|
642
|
+
function findFallback(matches) {
|
|
643
|
+
// If only a single plugin matches, let's take that one
|
|
644
|
+
if (matches.length === 1) {
|
|
645
|
+
return matches[0];
|
|
646
|
+
}
|
|
647
|
+
// Otherwise, find the plugin that creates a valid rule given the arbitrary value, and
|
|
648
|
+
// also has the correct type which preferOnConflicts the plugin in case of clashes.
|
|
649
|
+
return matches.find((rules)=>{
|
|
650
|
+
let matchingTypes = typesByMatches.get(rules);
|
|
651
|
+
return rules.some(([{ options }, rule])=>{
|
|
652
|
+
if (!isParsableNode(rule)) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
return options.types.some(({ type , preferOnConflict })=>matchingTypes.includes(type) && preferOnConflict);
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
var ref2;
|
|
660
|
+
// Try to find a fallback plugin, because we already know that multiple plugins matched for
|
|
661
|
+
// the given arbitrary value.
|
|
662
|
+
let fallback = (ref2 = findFallback(withoutAny)) !== null && ref2 !== void 0 ? ref2 : findFallback(withAny);
|
|
663
|
+
if (fallback) {
|
|
664
|
+
matches = [
|
|
665
|
+
fallback
|
|
666
|
+
];
|
|
667
|
+
} else {
|
|
668
|
+
var ref3;
|
|
669
|
+
let typesPerPlugin = matches.map((match)=>new Set([
|
|
670
|
+
...(ref3 = typesByMatches.get(match)) !== null && ref3 !== void 0 ? ref3 : []
|
|
671
|
+
]));
|
|
672
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
673
|
+
for (let pluginTypes of typesPerPlugin){
|
|
674
|
+
for (let type of pluginTypes){
|
|
675
|
+
let removeFromOwnGroup = false;
|
|
676
|
+
for (let otherGroup of typesPerPlugin){
|
|
677
|
+
if (pluginTypes === otherGroup) continue;
|
|
678
|
+
if (otherGroup.has(type)) {
|
|
679
|
+
otherGroup.delete(type);
|
|
680
|
+
removeFromOwnGroup = true;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
let messages = [];
|
|
687
|
+
for (let [idx, group] of typesPerPlugin.entries()){
|
|
688
|
+
for (let type1 of group){
|
|
689
|
+
let rules2 = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
|
|
690
|
+
.map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
|
|
691
|
+
.join("\n")).join("\n\n");
|
|
692
|
+
messages.push(` Use \`${candidate.replace("[", `[${type1}:`)}\` for \`${rules2.trim()}\``);
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
_log.default.warn([
|
|
697
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
698
|
+
...messages,
|
|
699
|
+
`If this is content and not a class, replace it with \`${candidate.replace("[", "[").replace("]", "]")}\` to silence this warning.`
|
|
700
|
+
]);
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
|
|
705
|
+
}
|
|
706
|
+
matches = matches.flat();
|
|
707
|
+
matches = Array.from(recordCandidates(matches, classCandidate));
|
|
708
|
+
matches = applyPrefix(matches, context);
|
|
709
|
+
if (important) {
|
|
710
|
+
matches = applyImportant(matches, classCandidate);
|
|
711
|
+
}
|
|
712
|
+
for (let variant of variants){
|
|
713
|
+
matches = applyVariant(variant, matches, context);
|
|
714
|
+
}
|
|
715
|
+
for (let match of matches){
|
|
716
|
+
match[1].raws.tailwind = {
|
|
717
|
+
...match[1].raws.tailwind,
|
|
718
|
+
candidate
|
|
719
|
+
};
|
|
720
|
+
// Apply final format selector
|
|
721
|
+
if (match[0].collectedFormats) {
|
|
722
|
+
let finalFormat = (0, _formatVariantSelector.formatVariantSelector)("&", ...match[0].collectedFormats);
|
|
723
|
+
let container = _postcss.default.root({
|
|
724
|
+
nodes: [
|
|
725
|
+
match[1].clone()
|
|
726
|
+
]
|
|
727
|
+
});
|
|
728
|
+
container.walkRules((rule)=>{
|
|
729
|
+
var ref;
|
|
730
|
+
if (inKeyframes(rule)) return;
|
|
731
|
+
var ref1;
|
|
732
|
+
rule.selector = (0, _formatVariantSelector.finalizeSelector)(finalFormat, {
|
|
733
|
+
selector: rule.selector,
|
|
734
|
+
candidate: original,
|
|
735
|
+
base: candidate.split(new RegExp(`\\${(ref1 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref1 !== void 0 ? ref1 : ":"}(?![^[]*\\])`)).pop(),
|
|
736
|
+
isArbitraryVariant: match[0].isArbitraryVariant,
|
|
737
|
+
context
|
|
738
|
+
});
|
|
739
|
+
});
|
|
740
|
+
match[1] = container.nodes[0];
|
|
741
|
+
}
|
|
742
|
+
yield match;
|
|
743
|
+
}
|
|
298
744
|
}
|
|
299
|
-
}
|
|
300
745
|
}
|
|
301
|
-
|
|
302
746
|
function inKeyframes(rule) {
|
|
303
|
-
|
|
747
|
+
return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
|
|
748
|
+
}
|
|
749
|
+
function getImportantStrategy(important) {
|
|
750
|
+
if (important === true) {
|
|
751
|
+
return (rule)=>{
|
|
752
|
+
if (inKeyframes(rule)) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
rule.walkDecls((d)=>{
|
|
756
|
+
if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
|
|
757
|
+
d.important = true;
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
if (typeof important === "string") {
|
|
763
|
+
return (rule)=>{
|
|
764
|
+
if (inKeyframes(rule)) {
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
768
|
+
return `${important} ${selector}`;
|
|
769
|
+
});
|
|
770
|
+
};
|
|
771
|
+
}
|
|
304
772
|
}
|
|
305
|
-
|
|
306
773
|
function generateRules(candidates, context) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
container.walkRules(r => {
|
|
348
|
-
if (inKeyframes(r)) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
r.selectors = r.selectors.map(selector => {
|
|
353
|
-
return `${context.tailwindConfig.important} ${selector}`;
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
rule = container.nodes[0];
|
|
357
|
-
}
|
|
774
|
+
let allRules = [];
|
|
775
|
+
let strategy = getImportantStrategy(context.tailwindConfig.important);
|
|
776
|
+
for (let candidate of candidates){
|
|
777
|
+
if (context.notClassCache.has(candidate)) {
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
if (context.candidateRuleCache.has(candidate)) {
|
|
781
|
+
allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)));
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
let matches = Array.from(resolveMatches(candidate, context));
|
|
785
|
+
if (matches.length === 0) {
|
|
786
|
+
context.notClassCache.add(candidate);
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
context.classCache.set(candidate, matches);
|
|
790
|
+
var ref;
|
|
791
|
+
let rules = (ref = context.candidateRuleCache.get(candidate)) !== null && ref !== void 0 ? ref : new Set();
|
|
792
|
+
context.candidateRuleCache.set(candidate, rules);
|
|
793
|
+
for (const match of matches){
|
|
794
|
+
let [{ sort , options }, rule] = match;
|
|
795
|
+
if (options.respectImportant && strategy) {
|
|
796
|
+
let container = _postcss.default.root({
|
|
797
|
+
nodes: [
|
|
798
|
+
rule.clone()
|
|
799
|
+
]
|
|
800
|
+
});
|
|
801
|
+
container.walkRules(strategy);
|
|
802
|
+
rule = container.nodes[0];
|
|
803
|
+
}
|
|
804
|
+
let newEntry = [
|
|
805
|
+
sort,
|
|
806
|
+
rule
|
|
807
|
+
];
|
|
808
|
+
rules.add(newEntry);
|
|
809
|
+
context.ruleCache.add(newEntry);
|
|
810
|
+
allRules.push(newEntry);
|
|
811
|
+
}
|
|
358
812
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
813
|
+
return allRules;
|
|
814
|
+
}
|
|
815
|
+
function isArbitraryValue(input) {
|
|
816
|
+
return input.startsWith("[") && input.endsWith("]");
|
|
817
|
+
}
|