tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cc69633
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 +356 -1
- package/LICENSE +1 -2
- package/README.md +8 -4
- package/colors.d.ts +3 -0
- package/colors.js +2 -1
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -1
- package/defaultTheme.d.ts +3 -0
- package/defaultTheme.js +2 -1
- package/lib/cli-peer-dependencies.js +3 -3
- package/lib/cli.js +261 -207
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +11 -1
- package/lib/corePlugins.js +1875 -1772
- package/lib/css/preflight.css +19 -5
- package/lib/featureFlags.js +17 -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 +44 -0
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +25 -21
- package/lib/lib/expandApplyAtRules.js +375 -157
- package/lib/lib/expandTailwindAtRules.js +153 -148
- package/lib/lib/generateRules.js +364 -67
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +45 -36
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +105 -90
- package/lib/lib/setupContextUtils.js +364 -282
- package/lib/lib/setupTrackingContext.js +57 -56
- package/lib/lib/sharedState.js +38 -15
- package/lib/lib/substituteScreenAtRules.js +9 -6
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +21 -9
- package/lib/public/colors.js +244 -248
- package/lib/public/resolve-config.js +5 -5
- package/lib/util/buildMediaQuery.js +13 -24
- package/lib/util/cloneDeep.js +1 -1
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +43 -32
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +13 -17
- package/lib/util/dataTypes.js +114 -74
- package/lib/util/defaults.js +6 -0
- package/lib/util/escapeClassName.js +5 -5
- package/lib/util/escapeCommas.js +1 -1
- package/lib/util/flattenColorPalette.js +2 -4
- package/lib/util/formatVariantSelector.js +186 -0
- package/lib/util/getAllConfigs.js +5 -5
- package/lib/util/hashConfig.js +5 -5
- package/lib/util/isKeyframeRule.js +1 -1
- package/lib/util/isPlainObject.js +1 -1
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +35 -19
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +5 -3
- package/lib/util/normalizeConfig.js +240 -0
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseAnimationValue.js +56 -56
- package/lib/util/parseBoxShadowValue.js +117 -0
- package/lib/util/parseDependency.js +32 -32
- package/lib/util/parseObjectStyles.js +6 -6
- package/lib/util/pluginUtils.js +67 -170
- package/lib/util/prefixSelector.js +4 -7
- package/lib/util/resolveConfig.js +83 -121
- package/lib/util/resolveConfigPath.js +17 -18
- package/lib/util/responsive.js +6 -6
- package/lib/util/toColorValue.js +1 -2
- package/lib/util/toPath.js +6 -1
- package/lib/util/transformThemeValue.js +40 -34
- package/lib/util/withAlphaVariable.js +19 -19
- package/nesting/index.js +2 -12
- package/package.json +40 -42
- package/peers/index.js +9110 -10362
- package/plugin.d.ts +6 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +52 -0
- package/src/cli.js +107 -31
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +610 -585
- package/src/css/preflight.css +19 -5
- package/src/featureFlags.js +14 -8
- 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 +50 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +6 -3
- package/src/lib/expandApplyAtRules.js +390 -155
- package/src/lib/expandTailwindAtRules.js +87 -61
- package/src/lib/generateRules.js +367 -41
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/resolveDefaultsAtRules.js +74 -53
- package/src/lib/setupContextUtils.js +330 -206
- package/src/lib/setupTrackingContext.js +11 -12
- package/src/lib/sharedState.js +42 -7
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +17 -2
- package/src/public/colors.js +4 -9
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -2
- package/src/util/dataTypes.js +56 -16
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +196 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +2 -2
- package/src/util/negateValue.js +4 -2
- package/src/util/normalizeConfig.js +270 -0
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +119 -0
- package/src/util/pluginUtils.js +51 -147
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +52 -65
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +22 -7
- package/stubs/defaultConfig.stub.js +156 -93
- package/stubs/simpleConfig.stub.js +0 -1
- package/types/config.d.ts +323 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types.d.ts +1 -0
- package/lib/lib/setupWatchingContext.js +0 -284
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -306
package/lib/lib/generateRules.js
CHANGED
|
@@ -9,13 +9,40 @@ var _parseObjectStyles = _interopRequireDefault(require("../util/parseObjectStyl
|
|
|
9
9
|
var _isPlainObject = _interopRequireDefault(require("../util/isPlainObject"));
|
|
10
10
|
var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
|
|
11
11
|
var _pluginUtils = require("../util/pluginUtils");
|
|
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 _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
12
18
|
function _interopRequireDefault(obj) {
|
|
13
19
|
return obj && obj.__esModule ? obj : {
|
|
14
20
|
default: obj
|
|
15
21
|
};
|
|
16
22
|
}
|
|
23
|
+
function _interopRequireWildcard(obj) {
|
|
24
|
+
if (obj && obj.__esModule) {
|
|
25
|
+
return obj;
|
|
26
|
+
} else {
|
|
27
|
+
var newObj = {};
|
|
28
|
+
if (obj != null) {
|
|
29
|
+
for(var key in obj){
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
31
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
32
|
+
if (desc.get || desc.set) {
|
|
33
|
+
Object.defineProperty(newObj, key, desc);
|
|
34
|
+
} else {
|
|
35
|
+
newObj[key] = obj[key];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
newObj.default = obj;
|
|
41
|
+
return newObj;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
17
44
|
let classNameParser = (0, _postcssSelectorParser).default((selectors)=>{
|
|
18
|
-
return selectors.first.filter(({ type })=>type ===
|
|
45
|
+
return selectors.first.filter(({ type })=>type === "class"
|
|
19
46
|
).pop().value;
|
|
20
47
|
});
|
|
21
48
|
function getClassNameFromSelector(selector) {
|
|
@@ -28,35 +55,35 @@ function getClassNameFromSelector(selector) {
|
|
|
28
55
|
// Example with dynamic classes:
|
|
29
56
|
// ['grid-cols', '[[linename],1fr,auto]']
|
|
30
57
|
// ['grid', 'cols-[[linename],1fr,auto]']
|
|
31
|
-
function* candidatePermutations(candidate
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
function* candidatePermutations(candidate) {
|
|
59
|
+
let lastIndex = Infinity;
|
|
60
|
+
while(lastIndex >= 0){
|
|
61
|
+
let dashIdx;
|
|
62
|
+
if (lastIndex === Infinity && candidate.endsWith("]")) {
|
|
63
|
+
let bracketIdx = candidate.indexOf("[");
|
|
64
|
+
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
|
|
65
|
+
// eg. string[]
|
|
66
|
+
dashIdx = [
|
|
67
|
+
"-",
|
|
68
|
+
"/"
|
|
69
|
+
].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
|
|
70
|
+
} else {
|
|
71
|
+
dashIdx = candidate.lastIndexOf("-", lastIndex);
|
|
72
|
+
}
|
|
73
|
+
if (dashIdx < 0) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
let prefix = candidate.slice(0, dashIdx);
|
|
77
|
+
let modifier = candidate.slice(dashIdx + 1);
|
|
78
|
+
yield [
|
|
79
|
+
prefix,
|
|
80
|
+
modifier
|
|
81
|
+
];
|
|
82
|
+
lastIndex = dashIdx - 1;
|
|
49
83
|
}
|
|
50
|
-
let prefix = candidate.slice(0, dashIdx);
|
|
51
|
-
let modifier = candidate.slice(dashIdx + 1);
|
|
52
|
-
yield [
|
|
53
|
-
prefix,
|
|
54
|
-
modifier
|
|
55
|
-
];
|
|
56
|
-
yield* candidatePermutations(candidate, dashIdx - 1);
|
|
57
84
|
}
|
|
58
85
|
function applyPrefix(matches, context) {
|
|
59
|
-
if (matches.length === 0 || context.tailwindConfig.prefix ===
|
|
86
|
+
if (matches.length === 0 || context.tailwindConfig.prefix === "") {
|
|
60
87
|
return matches;
|
|
61
88
|
}
|
|
62
89
|
for (let match of matches){
|
|
@@ -67,15 +94,21 @@ function applyPrefix(matches, context) {
|
|
|
67
94
|
match[1].clone()
|
|
68
95
|
]
|
|
69
96
|
});
|
|
97
|
+
let classCandidate = match[1].raws.tailwind.classCandidate;
|
|
70
98
|
container.walkRules((r)=>{
|
|
71
|
-
|
|
99
|
+
// If this is a negative utility with a dash *before* the prefix we
|
|
100
|
+
// have to ensure that the generated selector matches the candidate
|
|
101
|
+
// Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
|
|
102
|
+
// The disconnect between candidate <-> class can cause @apply to hard crash.
|
|
103
|
+
let shouldPrependNegative = classCandidate.startsWith("-");
|
|
104
|
+
r.selector = (0, _prefixSelector).default(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
|
|
72
105
|
});
|
|
73
106
|
match[1] = container.nodes[0];
|
|
74
107
|
}
|
|
75
108
|
}
|
|
76
109
|
return matches;
|
|
77
110
|
}
|
|
78
|
-
function applyImportant(matches) {
|
|
111
|
+
function applyImportant(matches, classCandidate) {
|
|
79
112
|
if (matches.length === 0) {
|
|
80
113
|
return matches;
|
|
81
114
|
}
|
|
@@ -88,7 +121,10 @@ function applyImportant(matches) {
|
|
|
88
121
|
});
|
|
89
122
|
container.walkRules((r)=>{
|
|
90
123
|
r.selector = (0, _pluginUtils).updateAllClasses(r.selector, (className)=>{
|
|
91
|
-
|
|
124
|
+
if (className === classCandidate) {
|
|
125
|
+
return `!${className}`;
|
|
126
|
+
}
|
|
127
|
+
return className;
|
|
92
128
|
});
|
|
93
129
|
r.walkDecls((d)=>d.important = true
|
|
94
130
|
);
|
|
@@ -118,24 +154,29 @@ function applyVariant(variant, matches, context) {
|
|
|
118
154
|
if (context.variantMap.has(variant)) {
|
|
119
155
|
let variantFunctionTuples = context.variantMap.get(variant);
|
|
120
156
|
let result = [];
|
|
121
|
-
for (let [meta,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
meta,
|
|
125
|
-
rule
|
|
126
|
-
]);
|
|
157
|
+
for (let [meta, rule1] of matches){
|
|
158
|
+
// Don't generate variants for user css
|
|
159
|
+
if (meta.layer === "user") {
|
|
127
160
|
continue;
|
|
128
161
|
}
|
|
129
162
|
let container = _postcss.default.root({
|
|
130
163
|
nodes: [
|
|
131
|
-
|
|
164
|
+
rule1.clone()
|
|
132
165
|
]
|
|
133
166
|
});
|
|
134
167
|
for (let [variantSort, variantFunction] of variantFunctionTuples){
|
|
135
168
|
let clone = container.clone();
|
|
169
|
+
let collectedFormats = [];
|
|
170
|
+
let originals = new Map();
|
|
171
|
+
function prepareBackup() {
|
|
172
|
+
if (originals.size > 0) return; // Already prepared, chicken out
|
|
173
|
+
clone.walkRules((rule)=>originals.set(rule, rule.selector)
|
|
174
|
+
);
|
|
175
|
+
}
|
|
136
176
|
function modifySelectors(modifierFunction) {
|
|
177
|
+
prepareBackup();
|
|
137
178
|
clone.each((rule)=>{
|
|
138
|
-
if (rule.type !==
|
|
179
|
+
if (rule.type !== "rule") {
|
|
139
180
|
return;
|
|
140
181
|
}
|
|
141
182
|
rule.selectors = rule.selectors.map((selector)=>{
|
|
@@ -150,19 +191,79 @@ function applyVariant(variant, matches, context) {
|
|
|
150
191
|
return clone;
|
|
151
192
|
}
|
|
152
193
|
let ruleWithVariant = variantFunction({
|
|
153
|
-
|
|
194
|
+
// Public API
|
|
195
|
+
get container () {
|
|
196
|
+
prepareBackup();
|
|
197
|
+
return clone;
|
|
198
|
+
},
|
|
154
199
|
separator: context.tailwindConfig.separator,
|
|
155
|
-
modifySelectors
|
|
200
|
+
modifySelectors,
|
|
201
|
+
// Private API for now
|
|
202
|
+
wrap (wrapper) {
|
|
203
|
+
let nodes = clone.nodes;
|
|
204
|
+
clone.removeAll();
|
|
205
|
+
wrapper.append(nodes);
|
|
206
|
+
clone.append(wrapper);
|
|
207
|
+
},
|
|
208
|
+
format (selectorFormat) {
|
|
209
|
+
collectedFormats.push(selectorFormat);
|
|
210
|
+
}
|
|
156
211
|
});
|
|
212
|
+
if (typeof ruleWithVariant === "string") {
|
|
213
|
+
collectedFormats.push(ruleWithVariant);
|
|
214
|
+
}
|
|
157
215
|
if (ruleWithVariant === null) {
|
|
158
216
|
continue;
|
|
159
217
|
}
|
|
218
|
+
// We filled the `originals`, therefore we assume that somebody touched
|
|
219
|
+
// `container` or `modifySelectors`. Let's see if they did, so that we
|
|
220
|
+
// can restore the selectors, and collect the format strings.
|
|
221
|
+
if (originals.size > 0) {
|
|
222
|
+
clone.walkRules((rule)=>{
|
|
223
|
+
if (!originals.has(rule)) return;
|
|
224
|
+
let before = originals.get(rule);
|
|
225
|
+
if (before === rule.selector) return; // No mutation happened
|
|
226
|
+
let modified = rule.selector;
|
|
227
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
228
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
229
|
+
// However, plugin authors probably also prepend or append certain
|
|
230
|
+
// classes, pseudos, ids, ...
|
|
231
|
+
let rebuiltBase = (0, _postcssSelectorParser).default((selectors)=>{
|
|
232
|
+
selectors.walkClasses((classNode)=>{
|
|
233
|
+
classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
|
|
234
|
+
});
|
|
235
|
+
}).processSync(before);
|
|
236
|
+
// Now that we know the original selector, the new selector, and
|
|
237
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
238
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
239
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
240
|
+
//
|
|
241
|
+
// E.g.:
|
|
242
|
+
// variant: foo
|
|
243
|
+
// selector: .markdown > p
|
|
244
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
245
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
246
|
+
// format: .foo &
|
|
247
|
+
collectedFormats.push(modified.replace(rebuiltBase, "&"));
|
|
248
|
+
rule.selector = before;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
// This tracks the originating layer for the variant
|
|
252
|
+
// For example:
|
|
253
|
+
// .sm:underline {} is a variant of something in the utilities layer
|
|
254
|
+
// .sm:container {} is a variant of the container component
|
|
255
|
+
clone.nodes[0].raws.tailwind = {
|
|
256
|
+
...clone.nodes[0].raws.tailwind,
|
|
257
|
+
parentLayer: meta.layer
|
|
258
|
+
};
|
|
259
|
+
var _collectedFormats;
|
|
160
260
|
let withOffset = [
|
|
161
261
|
{
|
|
162
262
|
...meta,
|
|
163
|
-
sort: variantSort | meta.sort
|
|
263
|
+
sort: variantSort | meta.sort,
|
|
264
|
+
collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats)
|
|
164
265
|
},
|
|
165
|
-
clone.nodes[0]
|
|
266
|
+
clone.nodes[0],
|
|
166
267
|
];
|
|
167
268
|
result.push(withOffset);
|
|
168
269
|
}
|
|
@@ -171,8 +272,7 @@ function applyVariant(variant, matches, context) {
|
|
|
171
272
|
}
|
|
172
273
|
return [];
|
|
173
274
|
}
|
|
174
|
-
function parseRules(rule, cache, options = {
|
|
175
|
-
}) {
|
|
275
|
+
function parseRules(rule, cache, options = {}) {
|
|
176
276
|
// PostCSS node
|
|
177
277
|
if (!(0, _isPlainObject).default(rule) && !Array.isArray(rule)) {
|
|
178
278
|
return [
|
|
@@ -195,39 +295,143 @@ function parseRules(rule, cache, options = {
|
|
|
195
295
|
options
|
|
196
296
|
];
|
|
197
297
|
}
|
|
298
|
+
const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
|
|
299
|
+
function isValidPropName(name) {
|
|
300
|
+
return IS_VALID_PROPERTY_NAME.test(name);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @param {string} declaration
|
|
304
|
+
* @returns {boolean}
|
|
305
|
+
*/ function looksLikeUri(declaration) {
|
|
306
|
+
// Quick bailout for obvious non-urls
|
|
307
|
+
// This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
|
|
308
|
+
if (!declaration.includes("://")) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
const url = new URL(declaration);
|
|
313
|
+
return url.scheme !== "" && url.host !== "";
|
|
314
|
+
} catch (err) {
|
|
315
|
+
// Definitely not a valid url
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function isParsableNode(node) {
|
|
320
|
+
let isParsable = true;
|
|
321
|
+
node.walkDecls((decl)=>{
|
|
322
|
+
if (!isParsableCssValue(decl.name, decl.value)) {
|
|
323
|
+
isParsable = false;
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
return isParsable;
|
|
328
|
+
}
|
|
329
|
+
function isParsableCssValue(property, value) {
|
|
330
|
+
// We don't want to to treat [https://example.com] as a custom property
|
|
331
|
+
// Even though, according to the CSS grammar, it's a totally valid CSS declaration
|
|
332
|
+
// So we short-circuit here by checking if the custom property looks like a url
|
|
333
|
+
if (looksLikeUri(`${property}:${value}`)) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
_postcss.default.parse(`a{${property}:${value}}`).toResult();
|
|
338
|
+
return true;
|
|
339
|
+
} catch (err) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function extractArbitraryProperty(classCandidate, context) {
|
|
344
|
+
var ref;
|
|
345
|
+
let [, property, value] = (ref = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && ref !== void 0 ? ref : [];
|
|
346
|
+
if (value === undefined) {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
if (!isValidPropName(property)) {
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
let normalized = (0, _dataTypes).normalize(value);
|
|
356
|
+
if (!isParsableCssValue(property, normalized)) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
return [
|
|
360
|
+
[
|
|
361
|
+
{
|
|
362
|
+
sort: context.arbitraryPropertiesSort,
|
|
363
|
+
layer: "utilities"
|
|
364
|
+
},
|
|
365
|
+
()=>({
|
|
366
|
+
[(0, _nameClass).asClass(classCandidate)]: {
|
|
367
|
+
[property]: normalized
|
|
368
|
+
}
|
|
369
|
+
})
|
|
370
|
+
,
|
|
371
|
+
],
|
|
372
|
+
];
|
|
373
|
+
}
|
|
198
374
|
function* resolveMatchedPlugins(classCandidate, context) {
|
|
199
375
|
if (context.candidateRuleMap.has(classCandidate)) {
|
|
200
376
|
yield [
|
|
201
377
|
context.candidateRuleMap.get(classCandidate),
|
|
202
|
-
|
|
378
|
+
"DEFAULT"
|
|
203
379
|
];
|
|
204
380
|
}
|
|
381
|
+
yield* function*(arbitraryPropertyRule) {
|
|
382
|
+
if (arbitraryPropertyRule !== null) {
|
|
383
|
+
yield [
|
|
384
|
+
arbitraryPropertyRule,
|
|
385
|
+
"DEFAULT"
|
|
386
|
+
];
|
|
387
|
+
}
|
|
388
|
+
}(extractArbitraryProperty(classCandidate, context));
|
|
205
389
|
let candidatePrefix = classCandidate;
|
|
206
390
|
let negative = false;
|
|
207
|
-
const twConfigPrefix = context.tailwindConfig.prefix
|
|
391
|
+
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
208
392
|
const twConfigPrefixLen = twConfigPrefix.length;
|
|
209
|
-
|
|
393
|
+
const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
|
|
394
|
+
if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
|
|
210
395
|
negative = true;
|
|
211
396
|
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
|
|
212
397
|
}
|
|
398
|
+
if (negative && context.candidateRuleMap.has(candidatePrefix)) {
|
|
399
|
+
yield [
|
|
400
|
+
context.candidateRuleMap.get(candidatePrefix),
|
|
401
|
+
"-DEFAULT"
|
|
402
|
+
];
|
|
403
|
+
}
|
|
213
404
|
for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
|
|
214
405
|
if (context.candidateRuleMap.has(prefix)) {
|
|
215
406
|
yield [
|
|
216
407
|
context.candidateRuleMap.get(prefix),
|
|
217
408
|
negative ? `-${modifier}` : modifier
|
|
218
409
|
];
|
|
219
|
-
return;
|
|
220
410
|
}
|
|
221
411
|
}
|
|
222
412
|
}
|
|
223
413
|
function splitWithSeparator(input, separator) {
|
|
224
|
-
|
|
414
|
+
if (input === sharedState.NOT_ON_DEMAND) {
|
|
415
|
+
return [
|
|
416
|
+
sharedState.NOT_ON_DEMAND
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, "g"));
|
|
420
|
+
}
|
|
421
|
+
function* recordCandidates(matches, classCandidate) {
|
|
422
|
+
for (const match of matches){
|
|
423
|
+
match[1].raws.tailwind = {
|
|
424
|
+
...match[1].raws.tailwind,
|
|
425
|
+
classCandidate
|
|
426
|
+
};
|
|
427
|
+
yield match;
|
|
428
|
+
}
|
|
225
429
|
}
|
|
226
430
|
function* resolveMatches(candidate, context) {
|
|
227
431
|
let separator = context.tailwindConfig.separator;
|
|
228
432
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
229
433
|
let important = false;
|
|
230
|
-
if (classCandidate.startsWith(
|
|
434
|
+
if (classCandidate.startsWith("!")) {
|
|
231
435
|
important = true;
|
|
232
436
|
classCandidate = classCandidate.slice(1);
|
|
233
437
|
}
|
|
@@ -244,16 +448,18 @@ function* resolveMatches(candidate, context) {
|
|
|
244
448
|
// }
|
|
245
449
|
for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)){
|
|
246
450
|
let matches = [];
|
|
451
|
+
let typesByMatches = new Map();
|
|
247
452
|
let [plugins, modifier] = matchedPlugins;
|
|
248
453
|
let isOnlyPlugin = plugins.length === 1;
|
|
249
454
|
for (let [sort, plugin] of plugins){
|
|
250
|
-
|
|
455
|
+
let matchesPerPlugin = [];
|
|
456
|
+
if (typeof plugin === "function") {
|
|
251
457
|
for (let ruleSet of [].concat(plugin(modifier, {
|
|
252
458
|
isOnlyPlugin
|
|
253
459
|
}))){
|
|
254
460
|
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
255
461
|
for (let rule of rules){
|
|
256
|
-
|
|
462
|
+
matchesPerPlugin.push([
|
|
257
463
|
{
|
|
258
464
|
...sort,
|
|
259
465
|
options: {
|
|
@@ -265,11 +471,11 @@ function* resolveMatches(candidate, context) {
|
|
|
265
471
|
]);
|
|
266
472
|
}
|
|
267
473
|
}
|
|
268
|
-
} else if (modifier ===
|
|
474
|
+
} else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
|
|
269
475
|
let ruleSet = plugin;
|
|
270
476
|
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
|
|
271
477
|
for (let rule of rules){
|
|
272
|
-
|
|
478
|
+
matchesPerPlugin.push([
|
|
273
479
|
{
|
|
274
480
|
...sort,
|
|
275
481
|
options: {
|
|
@@ -281,21 +487,99 @@ function* resolveMatches(candidate, context) {
|
|
|
281
487
|
]);
|
|
282
488
|
}
|
|
283
489
|
}
|
|
490
|
+
if (matchesPerPlugin.length > 0) {
|
|
491
|
+
var ref;
|
|
492
|
+
typesByMatches.set(matchesPerPlugin, (ref = sort.options) === null || ref === void 0 ? void 0 : ref.type);
|
|
493
|
+
matches.push(matchesPerPlugin);
|
|
494
|
+
}
|
|
284
495
|
}
|
|
496
|
+
if (isArbitraryValue(modifier)) {
|
|
497
|
+
// When generated arbitrary values are ambiguous, we can't know
|
|
498
|
+
// which to pick so don't generate any utilities for them
|
|
499
|
+
if (matches.length > 1) {
|
|
500
|
+
var ref1;
|
|
501
|
+
let typesPerPlugin = matches.map((match)=>new Set([
|
|
502
|
+
...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
|
|
503
|
+
])
|
|
504
|
+
);
|
|
505
|
+
// Remove duplicates, so that we can detect proper unique types for each plugin.
|
|
506
|
+
for (let pluginTypes of typesPerPlugin){
|
|
507
|
+
for (let type of pluginTypes){
|
|
508
|
+
let removeFromOwnGroup = false;
|
|
509
|
+
for (let otherGroup of typesPerPlugin){
|
|
510
|
+
if (pluginTypes === otherGroup) continue;
|
|
511
|
+
if (otherGroup.has(type)) {
|
|
512
|
+
otherGroup.delete(type);
|
|
513
|
+
removeFromOwnGroup = true;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (removeFromOwnGroup) pluginTypes.delete(type);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
let messages = [];
|
|
520
|
+
for (let [idx, group] of typesPerPlugin.entries()){
|
|
521
|
+
for (let type of group){
|
|
522
|
+
let rules = matches[idx].map(([, rule])=>rule
|
|
523
|
+
).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
|
|
524
|
+
.map((line)=>line.trim()
|
|
525
|
+
).map((x)=>` ${x}`
|
|
526
|
+
) // Re-indent
|
|
527
|
+
.join("\n")
|
|
528
|
+
).join("\n\n");
|
|
529
|
+
messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
|
|
530
|
+
break;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
_log.default.warn([
|
|
534
|
+
`The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
|
|
535
|
+
...messages,
|
|
536
|
+
`If this is content and not a class, replace it with \`${candidate.replace("[", "[").replace("]", "]")}\` to silence this warning.`,
|
|
537
|
+
]);
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])
|
|
541
|
+
)
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
matches = matches.flat();
|
|
545
|
+
matches = Array.from(recordCandidates(matches, classCandidate));
|
|
285
546
|
matches = applyPrefix(matches, context);
|
|
286
547
|
if (important) {
|
|
287
|
-
matches = applyImportant(matches,
|
|
548
|
+
matches = applyImportant(matches, classCandidate);
|
|
288
549
|
}
|
|
289
550
|
for (let variant of variants){
|
|
290
551
|
matches = applyVariant(variant, matches, context);
|
|
291
552
|
}
|
|
292
|
-
for (let
|
|
293
|
-
|
|
553
|
+
for (let match1 of matches){
|
|
554
|
+
match1[1].raws.tailwind = {
|
|
555
|
+
...match1[1].raws.tailwind,
|
|
556
|
+
candidate
|
|
557
|
+
};
|
|
558
|
+
// Apply final format selector
|
|
559
|
+
if (match1[0].collectedFormats) {
|
|
560
|
+
let finalFormat = (0, _formatVariantSelector).formatVariantSelector("&", ...match1[0].collectedFormats);
|
|
561
|
+
let container = _postcss.default.root({
|
|
562
|
+
nodes: [
|
|
563
|
+
match1[1].clone()
|
|
564
|
+
]
|
|
565
|
+
});
|
|
566
|
+
container.walkRules((rule)=>{
|
|
567
|
+
if (inKeyframes(rule)) return;
|
|
568
|
+
rule.selector = (0, _formatVariantSelector).finalizeSelector(finalFormat, {
|
|
569
|
+
selector: rule.selector,
|
|
570
|
+
candidate,
|
|
571
|
+
context
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
match1[1] = container.nodes[0];
|
|
575
|
+
}
|
|
576
|
+
yield match1;
|
|
294
577
|
}
|
|
295
578
|
}
|
|
296
579
|
}
|
|
580
|
+
exports.resolveMatches = resolveMatches;
|
|
297
581
|
function inKeyframes(rule) {
|
|
298
|
-
return rule.parent && rule.parent.type ===
|
|
582
|
+
return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
|
|
299
583
|
}
|
|
300
584
|
function generateRules(candidates, context) {
|
|
301
585
|
let allRules = [];
|
|
@@ -315,15 +599,28 @@ function generateRules(candidates, context) {
|
|
|
315
599
|
context.classCache.set(candidate, matches);
|
|
316
600
|
allRules.push(matches);
|
|
317
601
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
602
|
+
// Strategy based on `tailwindConfig.important`
|
|
603
|
+
let strategy = ((important)=>{
|
|
604
|
+
if (important === true) {
|
|
605
|
+
return (rule)=>{
|
|
321
606
|
rule.walkDecls((d)=>{
|
|
322
|
-
if (d.parent.type ===
|
|
607
|
+
if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
|
|
323
608
|
d.important = true;
|
|
324
609
|
}
|
|
325
610
|
});
|
|
326
|
-
}
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
if (typeof important === "string") {
|
|
614
|
+
return (rule)=>{
|
|
615
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
616
|
+
return `${important} ${selector}`;
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
})(context.tailwindConfig.important);
|
|
621
|
+
return allRules.flat(1).map(([{ sort , layer , options }, rule])=>{
|
|
622
|
+
if (options.respectImportant) {
|
|
623
|
+
if (strategy) {
|
|
327
624
|
let container = _postcss.default.root({
|
|
328
625
|
nodes: [
|
|
329
626
|
rule.clone()
|
|
@@ -333,9 +630,7 @@ function generateRules(candidates, context) {
|
|
|
333
630
|
if (inKeyframes(r)) {
|
|
334
631
|
return;
|
|
335
632
|
}
|
|
336
|
-
r
|
|
337
|
-
return `${context.tailwindConfig.important} ${selector}`;
|
|
338
|
-
});
|
|
633
|
+
strategy(r);
|
|
339
634
|
});
|
|
340
635
|
rule = container.nodes[0];
|
|
341
636
|
}
|
|
@@ -346,5 +641,7 @@ function generateRules(candidates, context) {
|
|
|
346
641
|
];
|
|
347
642
|
});
|
|
348
643
|
}
|
|
349
|
-
exports.resolveMatches = resolveMatches;
|
|
350
644
|
exports.generateRules = generateRules;
|
|
645
|
+
function isArbitraryValue(input) {
|
|
646
|
+
return input.startsWith("[") && input.endsWith("]");
|
|
647
|
+
}
|
|
@@ -7,19 +7,6 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
var _resolve = _interopRequireDefault(require("resolve"));
|
|
9
9
|
var _detective = _interopRequireDefault(require("detective"));
|
|
10
|
-
function _interopRequireDefault(obj) {
|
|
11
|
-
return obj && obj.__esModule ? obj : {
|
|
12
|
-
default: obj
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function createModule(file) {
|
|
16
|
-
const source = _fs.default.readFileSync(file, 'utf-8');
|
|
17
|
-
const requires = (0, _detective).default(source);
|
|
18
|
-
return {
|
|
19
|
-
file,
|
|
20
|
-
requires
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
10
|
function getModuleDependencies(entryFile) {
|
|
24
11
|
const rootModule = createModule(entryFile);
|
|
25
12
|
const modules = [
|
|
@@ -30,7 +17,7 @@ function getModuleDependencies(entryFile) {
|
|
|
30
17
|
for (const mdl of modules){
|
|
31
18
|
mdl.requires.filter((dep)=>{
|
|
32
19
|
// Only track local modules, not node_modules
|
|
33
|
-
return dep.startsWith(
|
|
20
|
+
return dep.startsWith("./") || dep.startsWith("../");
|
|
34
21
|
}).forEach((dep)=>{
|
|
35
22
|
try {
|
|
36
23
|
const basedir = _path.default.dirname(mdl.file);
|
|
@@ -46,3 +33,16 @@ function getModuleDependencies(entryFile) {
|
|
|
46
33
|
}
|
|
47
34
|
return modules;
|
|
48
35
|
}
|
|
36
|
+
function _interopRequireDefault(obj) {
|
|
37
|
+
return obj && obj.__esModule ? obj : {
|
|
38
|
+
default: obj
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createModule(file) {
|
|
42
|
+
const source = _fs.default.readFileSync(file, "utf-8");
|
|
43
|
+
const requires = (0, _detective).default(source);
|
|
44
|
+
return {
|
|
45
|
+
file,
|
|
46
|
+
requires
|
|
47
|
+
};
|
|
48
|
+
}
|