tailwindcss 0.0.0-insiders.d2b53cd → 0.0.0-insiders.d2fdf9e
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 +364 -2
- 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 +306 -203
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +10 -1
- package/lib/corePlugins.js +1835 -1760
- package/lib/css/preflight.css +19 -13
- package/lib/featureFlags.js +18 -15
- 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 +145 -126
- package/lib/lib/generateRules.js +403 -103
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +43 -35
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/regex.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +83 -65
- package/lib/lib/setupContextUtils.js +315 -204
- package/lib/lib/setupTrackingContext.js +60 -56
- package/lib/lib/sharedState.js +38 -5
- 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 +19 -9
- package/lib/public/colors.js +241 -241
- 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 +11 -15
- 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 +11 -7
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +4 -4
- package/lib/util/normalizeConfig.js +84 -45
- 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 +34 -165
- package/lib/util/prefixSelector.js +4 -7
- package/lib/util/resolveConfig.js +115 -66
- 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 +39 -40
- package/peers/index.js +11511 -10819
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/generate-types.js +52 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +164 -30
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +540 -535
- package/src/css/preflight.css +19 -13
- package/src/featureFlags.js +5 -5
- 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 +79 -37
- package/src/lib/generateRules.js +400 -83
- package/src/lib/normalizeTailwindDirectives.js +7 -1
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +35 -10
- package/src/lib/setupContextUtils.js +273 -112
- package/src/lib/setupTrackingContext.js +12 -7
- package/src/lib/sharedState.js +42 -4
- 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 +14 -2
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- 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 +10 -6
- package/src/util/nameClass.js +1 -1
- package/src/util/normalizeConfig.js +32 -3
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/pluginUtils.js +15 -138
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +97 -15
- 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 +47 -17
- 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 -304
package/lib/lib/generateRules.js
CHANGED
|
@@ -10,13 +10,42 @@ var _isPlainObject = _interopRequireDefault(require("../util/isPlainObject"));
|
|
|
10
10
|
var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
|
|
11
11
|
var _pluginUtils = require("../util/pluginUtils");
|
|
12
12
|
var _log = _interopRequireDefault(require("../util/log"));
|
|
13
|
+
var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
14
|
+
var _formatVariantSelector = require("../util/formatVariantSelector");
|
|
15
|
+
var _nameClass = require("../util/nameClass");
|
|
16
|
+
var _dataTypes = require("../util/dataTypes");
|
|
17
|
+
var _setupContextUtils = require("./setupContextUtils");
|
|
18
|
+
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
19
|
+
var _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
|
|
20
|
+
var _featureFlags = require("../featureFlags");
|
|
13
21
|
function _interopRequireDefault(obj) {
|
|
14
22
|
return obj && obj.__esModule ? obj : {
|
|
15
23
|
default: obj
|
|
16
24
|
};
|
|
17
25
|
}
|
|
26
|
+
function _interopRequireWildcard(obj) {
|
|
27
|
+
if (obj && obj.__esModule) {
|
|
28
|
+
return obj;
|
|
29
|
+
} else {
|
|
30
|
+
var newObj = {};
|
|
31
|
+
if (obj != null) {
|
|
32
|
+
for(var key in obj){
|
|
33
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
34
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
35
|
+
if (desc.get || desc.set) {
|
|
36
|
+
Object.defineProperty(newObj, key, desc);
|
|
37
|
+
} else {
|
|
38
|
+
newObj[key] = obj[key];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
newObj.default = obj;
|
|
44
|
+
return newObj;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
18
47
|
let classNameParser = (0, _postcssSelectorParser).default((selectors)=>{
|
|
19
|
-
return selectors.first.filter(({ type })=>type ===
|
|
48
|
+
return selectors.first.filter(({ type })=>type === "class"
|
|
20
49
|
).pop().value;
|
|
21
50
|
});
|
|
22
51
|
function getClassNameFromSelector(selector) {
|
|
@@ -29,35 +58,35 @@ function getClassNameFromSelector(selector) {
|
|
|
29
58
|
// Example with dynamic classes:
|
|
30
59
|
// ['grid-cols', '[[linename],1fr,auto]']
|
|
31
60
|
// ['grid', 'cols-[[linename],1fr,auto]']
|
|
32
|
-
function* candidatePermutations(candidate
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
function* candidatePermutations(candidate) {
|
|
62
|
+
let lastIndex = Infinity;
|
|
63
|
+
while(lastIndex >= 0){
|
|
64
|
+
let dashIdx;
|
|
65
|
+
if (lastIndex === Infinity && candidate.endsWith("]")) {
|
|
66
|
+
let bracketIdx = candidate.indexOf("[");
|
|
67
|
+
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
68
|
+
// eg. string[]
|
|
69
|
+
dashIdx = [
|
|
70
|
+
"-",
|
|
71
|
+
"/"
|
|
72
|
+
].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
|
|
73
|
+
} else {
|
|
74
|
+
dashIdx = candidate.lastIndexOf("-", lastIndex);
|
|
75
|
+
}
|
|
76
|
+
if (dashIdx < 0) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
let prefix = candidate.slice(0, dashIdx);
|
|
80
|
+
let modifier = candidate.slice(dashIdx + 1);
|
|
81
|
+
yield [
|
|
82
|
+
prefix,
|
|
83
|
+
modifier
|
|
84
|
+
];
|
|
85
|
+
lastIndex = dashIdx - 1;
|
|
50
86
|
}
|
|
51
|
-
let prefix = candidate.slice(0, dashIdx);
|
|
52
|
-
let modifier = candidate.slice(dashIdx + 1);
|
|
53
|
-
yield [
|
|
54
|
-
prefix,
|
|
55
|
-
modifier
|
|
56
|
-
];
|
|
57
|
-
yield* candidatePermutations(candidate, dashIdx - 1);
|
|
58
87
|
}
|
|
59
88
|
function applyPrefix(matches, context) {
|
|
60
|
-
if (matches.length === 0 || context.tailwindConfig.prefix ===
|
|
89
|
+
if (matches.length === 0 || context.tailwindConfig.prefix === "") {
|
|
61
90
|
return matches;
|
|
62
91
|
}
|
|
63
92
|
for (let match of matches){
|
|
@@ -68,15 +97,21 @@ function applyPrefix(matches, context) {
|
|
|
68
97
|
match[1].clone()
|
|
69
98
|
]
|
|
70
99
|
});
|
|
100
|
+
let classCandidate = match[1].raws.tailwind.classCandidate;
|
|
71
101
|
container.walkRules((r)=>{
|
|
72
|
-
|
|
102
|
+
// If this is a negative utility with a dash *before* the prefix we
|
|
103
|
+
// have to ensure that the generated selector matches the candidate
|
|
104
|
+
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
105
|
+
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
106
|
+
let shouldPrependNegative = classCandidate.startsWith("-");
|
|
107
|
+
r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
|
|
73
108
|
});
|
|
74
109
|
match[1] = container.nodes[0];
|
|
75
110
|
}
|
|
76
111
|
}
|
|
77
112
|
return matches;
|
|
78
113
|
}
|
|
79
|
-
function applyImportant(matches) {
|
|
114
|
+
function applyImportant(matches, classCandidate) {
|
|
80
115
|
if (matches.length === 0) {
|
|
81
116
|
return matches;
|
|
82
117
|
}
|
|
@@ -89,7 +124,10 @@ function applyImportant(matches) {
|
|
|
89
124
|
});
|
|
90
125
|
container.walkRules((r)=>{
|
|
91
126
|
r.selector = (0, _pluginUtils).updateAllClasses(r.selector, (className)=>{
|
|
92
|
-
|
|
127
|
+
if (className === classCandidate) {
|
|
128
|
+
return `!${className}`;
|
|
129
|
+
}
|
|
130
|
+
return className;
|
|
93
131
|
});
|
|
94
132
|
r.walkDecls((d)=>d.important = true
|
|
95
133
|
);
|
|
@@ -116,20 +154,54 @@ function applyVariant(variant, matches, context) {
|
|
|
116
154
|
if (matches.length === 0) {
|
|
117
155
|
return matches;
|
|
118
156
|
}
|
|
157
|
+
let args;
|
|
158
|
+
// Find partial arbitrary variants
|
|
159
|
+
if (variant.endsWith("]") && !variant.startsWith("[")) {
|
|
160
|
+
args = variant.slice(variant.lastIndexOf("[") + 1, -1);
|
|
161
|
+
variant = variant.slice(0, variant.indexOf(args) - 1 /* - */ - 1 /* [ */ );
|
|
162
|
+
}
|
|
163
|
+
// Register arbitrary variants
|
|
164
|
+
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
|
|
165
|
+
let selector = (0, _dataTypes).normalize(variant.slice(1, -1));
|
|
166
|
+
if (!(0, _setupContextUtils).isValidVariantFormatString(selector)) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
let fn = (0, _setupContextUtils).parseVariant(selector);
|
|
170
|
+
let sort = Array.from(context.variantOrder.values()).pop() << 1n;
|
|
171
|
+
context.variantMap.set(variant, [
|
|
172
|
+
[
|
|
173
|
+
sort,
|
|
174
|
+
fn
|
|
175
|
+
]
|
|
176
|
+
]);
|
|
177
|
+
context.variantOrder.set(variant, sort);
|
|
178
|
+
}
|
|
119
179
|
if (context.variantMap.has(variant)) {
|
|
120
|
-
let variantFunctionTuples = context.variantMap.get(variant);
|
|
180
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice();
|
|
121
181
|
let result = [];
|
|
122
|
-
for (let [meta,
|
|
182
|
+
for (let [meta, rule1] of matches){
|
|
183
|
+
// Don't generate variants for user css
|
|
184
|
+
if (meta.layer === "user") {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
123
187
|
let container = _postcss.default.root({
|
|
124
188
|
nodes: [
|
|
125
|
-
|
|
189
|
+
rule1.clone()
|
|
126
190
|
]
|
|
127
191
|
});
|
|
128
192
|
for (let [variantSort, variantFunction] of variantFunctionTuples){
|
|
129
193
|
let clone = container.clone();
|
|
194
|
+
let collectedFormats = [];
|
|
195
|
+
let originals = new Map();
|
|
196
|
+
function prepareBackup() {
|
|
197
|
+
if (originals.size > 0) return; // Already prepared, chicken out
|
|
198
|
+
clone.walkRules((rule)=>originals.set(rule, rule.selector)
|
|
199
|
+
);
|
|
200
|
+
}
|
|
130
201
|
function modifySelectors(modifierFunction) {
|
|
202
|
+
prepareBackup();
|
|
131
203
|
clone.each((rule)=>{
|
|
132
|
-
if (rule.type !==
|
|
204
|
+
if (rule.type !== "rule") {
|
|
133
205
|
return;
|
|
134
206
|
}
|
|
135
207
|
rule.selectors = rule.selectors.map((selector)=>{
|
|
@@ -144,19 +216,99 @@ function applyVariant(variant, matches, context) {
|
|
|
144
216
|
return clone;
|
|
145
217
|
}
|
|
146
218
|
let ruleWithVariant = variantFunction({
|
|
147
|
-
|
|
219
|
+
// Public API
|
|
220
|
+
get container () {
|
|
221
|
+
prepareBackup();
|
|
222
|
+
return clone;
|
|
223
|
+
},
|
|
148
224
|
separator: context.tailwindConfig.separator,
|
|
149
|
-
modifySelectors
|
|
225
|
+
modifySelectors,
|
|
226
|
+
// Private API for now
|
|
227
|
+
wrap (wrapper) {
|
|
228
|
+
let nodes = clone.nodes;
|
|
229
|
+
clone.removeAll();
|
|
230
|
+
wrapper.append(nodes);
|
|
231
|
+
clone.append(wrapper);
|
|
232
|
+
},
|
|
233
|
+
format (selectorFormat) {
|
|
234
|
+
collectedFormats.push(selectorFormat);
|
|
235
|
+
},
|
|
236
|
+
args
|
|
150
237
|
});
|
|
238
|
+
// It can happen that a list of format strings is returned from within the function. In that
|
|
239
|
+
// case, we have to process them as well. We can use the existing `variantSort`.
|
|
240
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
241
|
+
for (let [idx, variantFunction] of ruleWithVariant.entries()){
|
|
242
|
+
// This is a little bit scary since we are pushing to an array of items that we are
|
|
243
|
+
// currently looping over. However, you can also think of it like a processing queue
|
|
244
|
+
// where you keep handling jobs until everything is done and each job can queue more
|
|
245
|
+
// jobs if needed.
|
|
246
|
+
variantFunctionTuples.push([
|
|
247
|
+
// TODO: This could have potential bugs if we shift the sort order from variant A far
|
|
248
|
+
// enough into the sort space of variant B. The chances are low, but if this happens
|
|
249
|
+
// then this might be the place too look at. One potential solution to this problem is
|
|
250
|
+
// reserving additional X places for these 'unknown' variants in between.
|
|
251
|
+
variantSort | BigInt(idx << ruleWithVariant.length),
|
|
252
|
+
variantFunction,
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (typeof ruleWithVariant === "string") {
|
|
258
|
+
collectedFormats.push(ruleWithVariant);
|
|
259
|
+
}
|
|
151
260
|
if (ruleWithVariant === null) {
|
|
152
261
|
continue;
|
|
153
262
|
}
|
|
263
|
+
// We filled the `originals`, therefore we assume that somebody touched
|
|
264
|
+
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
265
|
+
// can restore the selectors, and collect the format strings.
|
|
266
|
+
if (originals.size > 0) {
|
|
267
|
+
clone.walkRules((rule)=>{
|
|
268
|
+
if (!originals.has(rule)) return;
|
|
269
|
+
let before = originals.get(rule);
|
|
270
|
+
if (before === rule.selector) return; // No mutation happened
|
|
271
|
+
let modified = rule.selector;
|
|
272
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
273
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
274
|
+
// However, plugin authors probably also prepend or append certain
|
|
275
|
+
// classes, pseudos, ids, ...
|
|
276
|
+
let rebuiltBase = (0, _postcssSelectorParser).default((selectors)=>{
|
|
277
|
+
selectors.walkClasses((classNode)=>{
|
|
278
|
+
classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
|
|
279
|
+
});
|
|
280
|
+
}).processSync(before);
|
|
281
|
+
// Now that we know the original selector, the new selector, and
|
|
282
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
283
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
284
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
285
|
+
//
|
|
286
|
+
// E.g.:
|
|
287
|
+
// variant: foo
|
|
288
|
+
// selector: .markdown > p
|
|
289
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
290
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
291
|
+
// format: .foo &
|
|
292
|
+
collectedFormats.push(modified.replace(rebuiltBase, "&"));
|
|
293
|
+
rule.selector = before;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
// This tracks the originating layer for the variant
|
|
297
|
+
// For example:
|
|
298
|
+
// .sm:underline {} is a variant of something in the utilities layer
|
|
299
|
+
// .sm:container {} is a variant of the container component
|
|
300
|
+
clone.nodes[0].raws.tailwind = {
|
|
301
|
+
...clone.nodes[0].raws.tailwind,
|
|
302
|
+
parentLayer: meta.layer
|
|
303
|
+
};
|
|
304
|
+
var _collectedFormats;
|
|
154
305
|
let withOffset = [
|
|
155
306
|
{
|
|
156
307
|
...meta,
|
|
157
|
-
sort: variantSort | meta.sort
|
|
308
|
+
sort: variantSort | meta.sort,
|
|
309
|
+
collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats)
|
|
158
310
|
},
|
|
159
|
-
clone.nodes[0]
|
|
311
|
+
clone.nodes[0],
|
|
160
312
|
];
|
|
161
313
|
result.push(withOffset);
|
|
162
314
|
}
|
|
@@ -165,8 +317,7 @@ function applyVariant(variant, matches, context) {
|
|
|
165
317
|
}
|
|
166
318
|
return [];
|
|
167
319
|
}
|
|
168
|
-
function parseRules(rule, cache, options = {
|
|
169
|
-
}) {
|
|
320
|
+
function parseRules(rule, cache, options = {}) {
|
|
170
321
|
// PostCSS node
|
|
171
322
|
if (!(0, _isPlainObject).default(rule) && !Array.isArray(rule)) {
|
|
172
323
|
return [
|
|
@@ -189,25 +340,110 @@ function parseRules(rule, cache, options = {
|
|
|
189
340
|
options
|
|
190
341
|
];
|
|
191
342
|
}
|
|
343
|
+
const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
|
|
344
|
+
function isValidPropName(name) {
|
|
345
|
+
return IS_VALID_PROPERTY_NAME.test(name);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* @param {string} declaration
|
|
349
|
+
* @returns {boolean}
|
|
350
|
+
*/ function looksLikeUri(declaration) {
|
|
351
|
+
// Quick bailout for obvious non-urls
|
|
352
|
+
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
353
|
+
if (!declaration.includes("://")) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
try {
|
|
357
|
+
const url = new URL(declaration);
|
|
358
|
+
return url.scheme !== "" && url.host !== "";
|
|
359
|
+
} catch (err) {
|
|
360
|
+
// Definitely not a valid url
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function isParsableNode(node) {
|
|
365
|
+
let isParsable = true;
|
|
366
|
+
node.walkDecls((decl)=>{
|
|
367
|
+
if (!isParsableCssValue(decl.name, decl.value)) {
|
|
368
|
+
isParsable = false;
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
return isParsable;
|
|
373
|
+
}
|
|
374
|
+
function isParsableCssValue(property, value) {
|
|
375
|
+
// We don't want to to treat [https://example.com] as a custom property
|
|
376
|
+
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
377
|
+
// So we short-circuit here by checking if the custom property looks like a url
|
|
378
|
+
if (looksLikeUri(`${property}:${value}`)) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
try {
|
|
382
|
+
_postcss.default.parse(`a{${property}:${value}}`).toResult();
|
|
383
|
+
return true;
|
|
384
|
+
} catch (err) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function extractArbitraryProperty(classCandidate, context) {
|
|
389
|
+
var ref;
|
|
390
|
+
let [, property, value] = (ref = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && ref !== void 0 ? ref : [];
|
|
391
|
+
if (value === undefined) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
if (!isValidPropName(property)) {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
let normalized = (0, _dataTypes).normalize(value);
|
|
401
|
+
if (!isParsableCssValue(property, normalized)) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
return [
|
|
405
|
+
[
|
|
406
|
+
{
|
|
407
|
+
sort: context.arbitraryPropertiesSort,
|
|
408
|
+
layer: "utilities"
|
|
409
|
+
},
|
|
410
|
+
()=>({
|
|
411
|
+
[(0, _nameClass).asClass(classCandidate)]: {
|
|
412
|
+
[property]: normalized
|
|
413
|
+
}
|
|
414
|
+
})
|
|
415
|
+
,
|
|
416
|
+
],
|
|
417
|
+
];
|
|
418
|
+
}
|
|
192
419
|
function* resolveMatchedPlugins(classCandidate, context) {
|
|
193
420
|
if (context.candidateRuleMap.has(classCandidate)) {
|
|
194
421
|
yield [
|
|
195
422
|
context.candidateRuleMap.get(classCandidate),
|
|
196
|
-
|
|
423
|
+
"DEFAULT"
|
|
197
424
|
];
|
|
198
425
|
}
|
|
426
|
+
yield* function*(arbitraryPropertyRule) {
|
|
427
|
+
if (arbitraryPropertyRule !== null) {
|
|
428
|
+
yield [
|
|
429
|
+
arbitraryPropertyRule,
|
|
430
|
+
"DEFAULT"
|
|
431
|
+
];
|
|
432
|
+
}
|
|
433
|
+
}(extractArbitraryProperty(classCandidate, context));
|
|
199
434
|
let candidatePrefix = classCandidate;
|
|
200
435
|
let negative = false;
|
|
201
|
-
const twConfigPrefix = context.tailwindConfig.prefix
|
|
436
|
+
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
202
437
|
const twConfigPrefixLen = twConfigPrefix.length;
|
|
203
|
-
|
|
438
|
+
const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
|
|
439
|
+
if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
|
|
204
440
|
negative = true;
|
|
205
441
|
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
206
442
|
}
|
|
207
443
|
if (negative && context.candidateRuleMap.has(candidatePrefix)) {
|
|
208
444
|
yield [
|
|
209
445
|
context.candidateRuleMap.get(candidatePrefix),
|
|
210
|
-
|
|
446
|
+
"-DEFAULT"
|
|
211
447
|
];
|
|
212
448
|
}
|
|
213
449
|
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
|
|
@@ -216,21 +452,42 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
216
452
|
context.candidateRuleMap.get(prefix),
|
|
217
453
|
negative ? `-${modifier}` : modifier
|
|
218
454
|
];
|
|
219
|
-
return;
|
|
220
455
|
}
|
|
221
456
|
}
|
|
222
457
|
}
|
|
223
458
|
function splitWithSeparator(input, separator) {
|
|
224
|
-
|
|
459
|
+
if (input === sharedState.NOT_ON_DEMAND) {
|
|
460
|
+
return [
|
|
461
|
+
sharedState.NOT_ON_DEMAND
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
return Array.from((0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(input, separator));
|
|
225
465
|
}
|
|
226
|
-
function*
|
|
466
|
+
function* recordCandidates(matches, classCandidate) {
|
|
467
|
+
for (const match of matches){
|
|
468
|
+
match[1].raws.tailwind = {
|
|
469
|
+
...match[1].raws.tailwind,
|
|
470
|
+
classCandidate
|
|
471
|
+
};
|
|
472
|
+
yield match;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
227
476
|
let separator = context.tailwindConfig.separator;
|
|
228
477
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
229
478
|
let important = false;
|
|
230
|
-
if (classCandidate.startsWith(
|
|
479
|
+
if (classCandidate.startsWith("!")) {
|
|
231
480
|
important = true;
|
|
232
481
|
classCandidate = classCandidate.slice(1);
|
|
233
482
|
}
|
|
483
|
+
if ((0, _featureFlags).flagEnabled(context.tailwindConfig, "variantGrouping")) {
|
|
484
|
+
if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
|
|
485
|
+
let base = variants.slice().reverse().join(separator);
|
|
486
|
+
for (let part of (0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(classCandidate.slice(1, -1), ",")){
|
|
487
|
+
yield* resolveMatches(base + separator + part, context, original);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
234
491
|
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
235
492
|
// function sortAgainst(toSort, against) {
|
|
236
493
|
// return toSort.slice().sort((a, z) => {
|
|
@@ -249,7 +506,7 @@ function* resolveMatches(candidate, context) {
|
|
|
249
506
|
let isOnlyPlugin = plugins.length === 1;
|
|
250
507
|
for (let [sort, plugin] of plugins){
|
|
251
508
|
let matchesPerPlugin = [];
|
|
252
|
-
if (typeof plugin ===
|
|
509
|
+
if (typeof plugin === "function") {
|
|
253
510
|
for (let ruleSet of [].concat(plugin(modifier, {
|
|
254
511
|
isOnlyPlugin
|
|
255
512
|
}))){
|
|
@@ -267,7 +524,7 @@ function* resolveMatches(candidate, context) {
|
|
|
267
524
|
]);
|
|
268
525
|
}
|
|
269
526
|
}
|
|
270
|
-
} else if (modifier ===
|
|
527
|
+
} else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
|
|
271
528
|
let ruleSet = plugin;
|
|
272
529
|
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
273
530
|
for (let rule of rules){
|
|
@@ -289,63 +546,96 @@ function* resolveMatches(candidate, context) {
|
|
|
289
546
|
matches.push(matchesPerPlugin);
|
|
290
547
|
}
|
|
291
548
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
for (let
|
|
303
|
-
let
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
otherGroup.
|
|
308
|
-
|
|
549
|
+
if (isArbitraryValue(modifier)) {
|
|
550
|
+
// When generated arbitrary values are ambiguous, we can't know
|
|
551
|
+
// which to pick so don't generate any utilities for them
|
|
552
|
+
if (matches.length > 1) {
|
|
553
|
+
var ref1;
|
|
554
|
+
let typesPerPlugin = matches.map((match)=>new Set([
|
|
555
|
+
...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
|
|
556
|
+
])
|
|
557
|
+
);
|
|
558
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
559
|
+
for (let pluginTypes of typesPerPlugin){
|
|
560
|
+
for (let type of pluginTypes){
|
|
561
|
+
let removeFromOwnGroup = false;
|
|
562
|
+
for (let otherGroup of typesPerPlugin){
|
|
563
|
+
if (pluginTypes === otherGroup) continue;
|
|
564
|
+
if (otherGroup.has(type)) {
|
|
565
|
+
otherGroup.delete(type);
|
|
566
|
+
removeFromOwnGroup = true;
|
|
567
|
+
}
|
|
309
568
|
}
|
|
569
|
+
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
310
570
|
}
|
|
311
|
-
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
312
571
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
.join(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
572
|
+
let messages = [];
|
|
573
|
+
for (let [idx, group] of typesPerPlugin.entries()){
|
|
574
|
+
for (let type of group){
|
|
575
|
+
let rules = matches[idx].map(([, rule])=>rule
|
|
576
|
+
).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
|
|
577
|
+
.map((line)=>line.trim()
|
|
578
|
+
).map((x)=>` ${x}`
|
|
579
|
+
) // Re-indent
|
|
580
|
+
.join("\n")
|
|
581
|
+
).join("\n\n");
|
|
582
|
+
messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
326
585
|
}
|
|
586
|
+
_log.default.warn([
|
|
587
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
588
|
+
...messages,
|
|
589
|
+
`If this is content and not a class, replace it with \`${candidate.replace("[", "[").replace("]", "]")}\` to silence this warning.`,
|
|
590
|
+
]);
|
|
591
|
+
continue;
|
|
327
592
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
`If this is content and not a class, replace it with \`${candidate.replace('[', '[').replace(']', ']')}\` to silence this warning.`,
|
|
332
|
-
]);
|
|
333
|
-
continue;
|
|
593
|
+
matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])
|
|
594
|
+
)
|
|
595
|
+
);
|
|
334
596
|
}
|
|
335
|
-
matches =
|
|
597
|
+
matches = matches.flat();
|
|
598
|
+
matches = Array.from(recordCandidates(matches, classCandidate));
|
|
599
|
+
matches = applyPrefix(matches, context);
|
|
336
600
|
if (important) {
|
|
337
|
-
matches = applyImportant(matches,
|
|
601
|
+
matches = applyImportant(matches, classCandidate);
|
|
338
602
|
}
|
|
339
603
|
for (let variant of variants){
|
|
340
604
|
matches = applyVariant(variant, matches, context);
|
|
341
605
|
}
|
|
342
|
-
for (let
|
|
343
|
-
|
|
606
|
+
for (let match1 of matches){
|
|
607
|
+
match1[1].raws.tailwind = {
|
|
608
|
+
...match1[1].raws.tailwind,
|
|
609
|
+
candidate
|
|
610
|
+
};
|
|
611
|
+
// Apply final format selector
|
|
612
|
+
if (match1[0].collectedFormats) {
|
|
613
|
+
let finalFormat = (0, _formatVariantSelector).formatVariantSelector("&", ...match1[0].collectedFormats);
|
|
614
|
+
let container = _postcss.default.root({
|
|
615
|
+
nodes: [
|
|
616
|
+
match1[1].clone()
|
|
617
|
+
]
|
|
618
|
+
});
|
|
619
|
+
container.walkRules((rule)=>{
|
|
620
|
+
var ref;
|
|
621
|
+
if (inKeyframes(rule)) return;
|
|
622
|
+
var ref2;
|
|
623
|
+
rule.selector = (0, _formatVariantSelector).finalizeSelector(finalFormat, {
|
|
624
|
+
selector: rule.selector,
|
|
625
|
+
candidate: original,
|
|
626
|
+
base: candidate.split(new RegExp(`\\${(ref2 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref2 !== void 0 ? ref2 : ":"}(?![^[]*\\])`)).pop(),
|
|
627
|
+
context
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
match1[1] = container.nodes[0];
|
|
631
|
+
}
|
|
632
|
+
yield match1;
|
|
344
633
|
}
|
|
345
634
|
}
|
|
346
635
|
}
|
|
636
|
+
exports.resolveMatches = resolveMatches;
|
|
347
637
|
function inKeyframes(rule) {
|
|
348
|
-
return rule.parent && rule.parent.type ===
|
|
638
|
+
return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
|
|
349
639
|
}
|
|
350
640
|
function generateRules(candidates, context) {
|
|
351
641
|
let allRules = [];
|
|
@@ -365,15 +655,28 @@ function generateRules(candidates, context) {
|
|
|
365
655
|
context.classCache.set(candidate, matches);
|
|
366
656
|
allRules.push(matches);
|
|
367
657
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
658
|
+
// Strategy based on `tailwindConfig.important`
|
|
659
|
+
let strategy = ((important)=>{
|
|
660
|
+
if (important === true) {
|
|
661
|
+
return (rule)=>{
|
|
371
662
|
rule.walkDecls((d)=>{
|
|
372
|
-
if (d.parent.type ===
|
|
663
|
+
if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
|
|
373
664
|
d.important = true;
|
|
374
665
|
}
|
|
375
666
|
});
|
|
376
|
-
}
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
if (typeof important === "string") {
|
|
670
|
+
return (rule)=>{
|
|
671
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
672
|
+
return `${important} ${selector}`;
|
|
673
|
+
});
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
})(context.tailwindConfig.important);
|
|
677
|
+
return allRules.flat(1).map(([{ sort , layer , options }, rule])=>{
|
|
678
|
+
if (options.respectImportant) {
|
|
679
|
+
if (strategy) {
|
|
377
680
|
let container = _postcss.default.root({
|
|
378
681
|
nodes: [
|
|
379
682
|
rule.clone()
|
|
@@ -383,9 +686,7 @@ function generateRules(candidates, context) {
|
|
|
383
686
|
if (inKeyframes(r)) {
|
|
384
687
|
return;
|
|
385
688
|
}
|
|
386
|
-
r
|
|
387
|
-
return `${context.tailwindConfig.important} ${selector}`;
|
|
388
|
-
});
|
|
689
|
+
strategy(r);
|
|
389
690
|
});
|
|
390
691
|
rule = container.nodes[0];
|
|
391
692
|
}
|
|
@@ -396,8 +697,7 @@ function generateRules(candidates, context) {
|
|
|
396
697
|
];
|
|
397
698
|
});
|
|
398
699
|
}
|
|
700
|
+
exports.generateRules = generateRules;
|
|
399
701
|
function isArbitraryValue(input) {
|
|
400
|
-
return input.startsWith(
|
|
702
|
+
return input.startsWith("[") && input.endsWith("]");
|
|
401
703
|
}
|
|
402
|
-
exports.resolveMatches = resolveMatches;
|
|
403
|
-
exports.generateRules = generateRules;
|