tailwindcss 3.0.24 → 3.1.0
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 +57 -3
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +3 -0
- package/lib/cli-peer-dependencies.js +8 -3
- package/lib/cli.js +118 -77
- package/lib/corePluginList.js +1 -0
- package/lib/corePlugins.js +146 -117
- package/lib/css/preflight.css +1 -8
- package/lib/featureFlags.js +8 -6
- package/lib/index.js +10 -13
- package/lib/lib/cacheInvalidation.js +32 -14
- package/lib/lib/collapseAdjacentRules.js +5 -3
- package/lib/lib/defaultExtractor.js +191 -32
- package/lib/lib/evaluateTailwindFunctions.js +22 -13
- package/lib/lib/expandApplyAtRules.js +232 -195
- package/lib/lib/expandTailwindAtRules.js +40 -26
- package/lib/lib/generateRules.js +106 -42
- package/lib/lib/regex.js +52 -0
- package/lib/lib/resolveDefaultsAtRules.js +6 -9
- package/lib/lib/setupContextUtils.js +131 -79
- package/lib/lib/setupTrackingContext.js +7 -9
- package/lib/lib/sharedState.js +1 -2
- package/lib/lib/substituteScreenAtRules.js +1 -2
- package/lib/postcss-plugins/nesting/plugin.js +1 -2
- package/lib/util/buildMediaQuery.js +1 -2
- package/lib/util/cloneDeep.js +2 -4
- package/lib/util/color.js +26 -36
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +1 -2
- package/lib/util/dataTypes.js +14 -12
- package/lib/util/flattenColorPalette.js +2 -5
- package/lib/util/formatVariantSelector.js +64 -57
- package/lib/util/getAllConfigs.js +10 -5
- package/lib/util/isValidArbitraryValue.js +1 -2
- package/lib/util/log.js +2 -3
- package/lib/util/negateValue.js +1 -2
- package/lib/util/normalizeConfig.js +33 -23
- package/lib/util/normalizeScreens.js +1 -2
- package/lib/util/parseAnimationValue.js +1 -2
- package/lib/util/parseBoxShadowValue.js +2 -43
- package/lib/util/pluginUtils.js +11 -3
- package/lib/util/resolveConfig.js +57 -34
- package/lib/util/splitAtTopLevelOnly.js +90 -0
- package/lib/util/transformThemeValue.js +4 -2
- package/lib/util/validateConfig.js +21 -0
- package/lib/util/withAlphaVariable.js +5 -5
- package/package.json +21 -16
- package/peers/index.js +3264 -1330
- package/plugin.d.ts +11 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +97 -33
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +57 -40
- package/src/css/preflight.css +1 -8
- package/src/featureFlags.js +2 -2
- package/src/index.js +0 -2
- package/src/lib/collapseAdjacentRules.js +5 -1
- package/src/lib/defaultExtractor.js +177 -35
- package/src/lib/evaluateTailwindFunctions.js +20 -4
- package/src/lib/expandApplyAtRules.js +247 -188
- package/src/lib/expandTailwindAtRules.js +4 -4
- package/src/lib/generateRules.js +69 -5
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +1 -1
- package/src/lib/setupContextUtils.js +103 -39
- package/src/lib/setupTrackingContext.js +4 -0
- package/src/util/color.js +20 -18
- package/src/util/dataTypes.js +11 -5
- package/src/util/formatVariantSelector.js +79 -62
- package/src/util/getAllConfigs.js +7 -0
- package/src/util/log.js +1 -1
- package/src/util/normalizeConfig.js +0 -8
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/pluginUtils.js +13 -1
- package/src/util/resolveConfig.js +66 -54
- package/src/util/splitAtTopLevelOnly.js +71 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +4 -2
- package/src/util/validateConfig.js +13 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/stubs/defaultConfig.stub.js +2 -3
- package/stubs/simpleConfig.stub.js +1 -0
- 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
|
@@ -3,38 +3,197 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.defaultExtractor = defaultExtractor;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
var _featureFlagsJs = require("../featureFlags.js");
|
|
7
|
+
var regex = _interopRequireWildcard(require("./regex"));
|
|
8
|
+
function _getRequireWildcardCache() {
|
|
9
|
+
if (typeof WeakMap !== "function") return null;
|
|
10
|
+
var cache = new WeakMap();
|
|
11
|
+
_getRequireWildcardCache = function() {
|
|
12
|
+
return cache;
|
|
13
|
+
};
|
|
14
|
+
return cache;
|
|
15
|
+
}
|
|
16
|
+
function _interopRequireWildcard(obj) {
|
|
17
|
+
if (obj && obj.__esModule) {
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
21
|
+
return {
|
|
22
|
+
default: obj
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
var cache = _getRequireWildcardCache();
|
|
26
|
+
if (cache && cache.has(obj)) {
|
|
27
|
+
return cache.get(obj);
|
|
28
|
+
}
|
|
29
|
+
var newObj = {};
|
|
30
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
31
|
+
for(var key in obj){
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
33
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
34
|
+
if (desc && (desc.get || desc.set)) {
|
|
35
|
+
Object.defineProperty(newObj, key, desc);
|
|
36
|
+
} else {
|
|
37
|
+
newObj[key] = obj[key];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
newObj.default = obj;
|
|
42
|
+
if (cache) {
|
|
43
|
+
cache.set(obj, newObj);
|
|
44
|
+
}
|
|
45
|
+
return newObj;
|
|
46
|
+
}
|
|
47
|
+
function defaultExtractor(context) {
|
|
48
|
+
let patterns = Array.from(buildRegExps(context));
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} content
|
|
51
|
+
*/ return (content)=>{
|
|
52
|
+
/** @type {(string|string)[]} */ let results = [];
|
|
53
|
+
for (let pattern of patterns){
|
|
54
|
+
var ref;
|
|
55
|
+
results.push(...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []);
|
|
56
|
+
}
|
|
57
|
+
return results.filter((v)=>v !== undefined).map(clipAtBalancedParens);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function* buildRegExps(context) {
|
|
61
|
+
let separator = context.tailwindConfig.separator;
|
|
62
|
+
let variantGroupingEnabled = (0, _featureFlagsJs).flagEnabled(context.tailwindConfig, "variantGrouping");
|
|
63
|
+
let utility = regex.any([
|
|
64
|
+
// Arbitrary properties
|
|
65
|
+
/\[[^\s:'"]+:[^\s\]]+\]/,
|
|
66
|
+
// Utilities
|
|
67
|
+
regex.pattern([
|
|
68
|
+
// Utility Name / Group Name
|
|
69
|
+
/-?(?:\w+)/,
|
|
70
|
+
// Normal/Arbitrary values
|
|
71
|
+
regex.optional(regex.any([
|
|
72
|
+
regex.pattern([
|
|
73
|
+
// Arbitrary values
|
|
74
|
+
/-\[[^\s:]+\]/,
|
|
75
|
+
// Not immediately followed by an `{[(`
|
|
76
|
+
/(?![{([]])/,
|
|
77
|
+
// optionally followed by an opacity modifier
|
|
78
|
+
/(?:\/[^\s'"\\$]*)?/,
|
|
79
|
+
]),
|
|
80
|
+
regex.pattern([
|
|
81
|
+
// Arbitrary values
|
|
82
|
+
/-\[[^\s]+\]/,
|
|
83
|
+
// Not immediately followed by an `{[(`
|
|
84
|
+
/(?![{([]])/,
|
|
85
|
+
// optionally followed by an opacity modifier
|
|
86
|
+
/(?:\/[^\s'"\\$]*)?/,
|
|
87
|
+
]),
|
|
88
|
+
// Normal values w/o quotes — may include an opacity modifier
|
|
89
|
+
/[-\/][^\s'"\\$={]*/,
|
|
90
|
+
])),
|
|
91
|
+
]),
|
|
92
|
+
]);
|
|
93
|
+
yield regex.pattern([
|
|
94
|
+
// Variants
|
|
95
|
+
"((?=((",
|
|
96
|
+
regex.any([
|
|
97
|
+
regex.pattern([
|
|
98
|
+
/([^\s"'\[\\]+-)?\[[^\s"'\\]+\]/,
|
|
99
|
+
separator
|
|
100
|
+
]),
|
|
101
|
+
regex.pattern([
|
|
102
|
+
/[^\s"'\[\\]+/,
|
|
103
|
+
separator
|
|
104
|
+
]),
|
|
105
|
+
], true),
|
|
106
|
+
")+))\\2)?",
|
|
107
|
+
// Important (optional)
|
|
108
|
+
/!?/,
|
|
109
|
+
variantGroupingEnabled ? regex.any([
|
|
110
|
+
// Or any of those things but grouped separated by commas
|
|
111
|
+
regex.pattern([
|
|
112
|
+
/\(/,
|
|
113
|
+
utility,
|
|
114
|
+
regex.zeroOrMore([
|
|
115
|
+
/,/,
|
|
116
|
+
utility
|
|
117
|
+
]),
|
|
118
|
+
/\)/
|
|
119
|
+
]),
|
|
120
|
+
// Arbitrary properties, constrained utilities, arbitrary values, etc…
|
|
121
|
+
utility,
|
|
122
|
+
]) : utility,
|
|
123
|
+
]);
|
|
124
|
+
// 5. Inner matches
|
|
125
|
+
// yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
|
|
126
|
+
}
|
|
127
|
+
// We want to capture any "special" characters
|
|
128
|
+
// AND the characters immediately following them (if there is one)
|
|
129
|
+
let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
|
|
130
|
+
let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
|
|
131
|
+
/**
|
|
132
|
+
* Clips a string ensuring that parentheses, quotes, etc… are balanced
|
|
133
|
+
* Used for arbitrary values only
|
|
134
|
+
*
|
|
135
|
+
* We will go past the end of the balanced parens until we find a non-class character
|
|
136
|
+
*
|
|
137
|
+
* Depth matching behavior:
|
|
138
|
+
* w-[calc(100%-theme('spacing[some_key][1.5]'))]']
|
|
139
|
+
* ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
|
|
140
|
+
* 1 2 3 4 34 3 210 END
|
|
141
|
+
* ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
|
|
142
|
+
*
|
|
143
|
+
* @param {string} input
|
|
144
|
+
*/ function clipAtBalancedParens(input) {
|
|
145
|
+
// We are care about this for arbitrary values
|
|
146
|
+
if (!input.includes("-[")) {
|
|
147
|
+
return input;
|
|
148
|
+
}
|
|
149
|
+
let depth = 0;
|
|
150
|
+
let openStringTypes = [];
|
|
151
|
+
// Find all parens, brackets, quotes, etc
|
|
152
|
+
// Stop when we end at a balanced pair
|
|
153
|
+
// This is naive and will treat mismatched parens as balanced
|
|
154
|
+
// This shouldn't be a problem in practice though
|
|
155
|
+
let matches = input.matchAll(SPECIALS);
|
|
156
|
+
// We can't use lookbehind assertions because we have to support Safari
|
|
157
|
+
// So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
|
|
158
|
+
matches = Array.from(matches).flatMap((match)=>{
|
|
159
|
+
const [, ...groups] = match;
|
|
160
|
+
return groups.map((group, idx)=>Object.assign([], match, {
|
|
161
|
+
index: match.index + idx,
|
|
162
|
+
0: group
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
for (let match1 of matches){
|
|
166
|
+
let char = match1[0];
|
|
167
|
+
let inStringType = openStringTypes[openStringTypes.length - 1];
|
|
168
|
+
if (char === inStringType) {
|
|
169
|
+
openStringTypes.pop();
|
|
170
|
+
} else if (char === "'" || char === '"' || char === "`") {
|
|
171
|
+
openStringTypes.push(char);
|
|
172
|
+
}
|
|
173
|
+
if (inStringType) {
|
|
174
|
+
continue;
|
|
175
|
+
} else if (char === "[") {
|
|
176
|
+
depth++;
|
|
177
|
+
continue;
|
|
178
|
+
} else if (char === "]") {
|
|
179
|
+
depth--;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
// We've gone one character past the point where we should stop
|
|
183
|
+
// This means that there was an extra closing `]`
|
|
184
|
+
// We'll clip to just before it
|
|
185
|
+
if (depth < 0) {
|
|
186
|
+
return input.substring(0, match1.index);
|
|
187
|
+
}
|
|
188
|
+
// We've finished balancing the brackets but there still may be characters that can be included
|
|
189
|
+
// For example in the class `text-[#336699]/[.35]`
|
|
190
|
+
// The depth goes to `0` at the closing `]` but goes up again at the `[`
|
|
191
|
+
// If we're at zero and encounter a non-class character then we clip the class there
|
|
192
|
+
if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
|
|
193
|
+
return input.substring(0, match1.index);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return input;
|
|
38
197
|
} // Regular utilities
|
|
39
198
|
// {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
|
|
40
199
|
// Arbitrary values
|
|
@@ -10,6 +10,8 @@ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser")
|
|
|
10
10
|
var _normalizeScreens = require("../util/normalizeScreens");
|
|
11
11
|
var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
|
|
12
12
|
var _toPath = require("../util/toPath");
|
|
13
|
+
var _withAlphaVariable = require("../util/withAlphaVariable");
|
|
14
|
+
var _pluginUtils = require("../util/pluginUtils");
|
|
13
15
|
function _interopRequireDefault(obj) {
|
|
14
16
|
return obj && obj.__esModule ? obj : {
|
|
15
17
|
default: obj
|
|
@@ -34,13 +36,12 @@ function pathToString(path) {
|
|
|
34
36
|
}, "");
|
|
35
37
|
}
|
|
36
38
|
function list(items) {
|
|
37
|
-
return items.map((key)=>`'${key}'`
|
|
38
|
-
).join(", ");
|
|
39
|
+
return items.map((key)=>`'${key}'`).join(", ");
|
|
39
40
|
}
|
|
40
41
|
function listKeys(obj) {
|
|
41
42
|
return list(Object.keys(obj));
|
|
42
43
|
}
|
|
43
|
-
function validatePath(config, path, defaultValue) {
|
|
44
|
+
function validatePath(config, path, defaultValue, themeOpts = {}) {
|
|
44
45
|
const pathString = Array.isArray(path) ? pathToString(path) : path.replace(/^['"]+/g, "").replace(/['"]+$/g, "");
|
|
45
46
|
const pathSegments = Array.isArray(path) ? path : (0, _toPath).toPath(pathString);
|
|
46
47
|
const value = (0, _dlv).default(config.theme, pathSegments, defaultValue);
|
|
@@ -52,8 +53,7 @@ function validatePath(config, path, defaultValue) {
|
|
|
52
53
|
const validKeys = Object.keys(parentValue).filter((key)=>validatePath(config, [
|
|
53
54
|
...parentSegments,
|
|
54
55
|
key
|
|
55
|
-
]).isValid
|
|
56
|
-
);
|
|
56
|
+
]).isValid);
|
|
57
57
|
const suggestion = (0, _didyoumean).default(pathSegments[pathSegments.length - 1], validKeys);
|
|
58
58
|
if (suggestion) {
|
|
59
59
|
error += ` Did you mean '${pathToString([
|
|
@@ -87,8 +87,7 @@ function validatePath(config, path, defaultValue) {
|
|
|
87
87
|
let validKeys = Object.keys(value).filter((key)=>validatePath(config, [
|
|
88
88
|
...pathSegments,
|
|
89
89
|
key
|
|
90
|
-
]).isValid
|
|
91
|
-
);
|
|
90
|
+
]).isValid);
|
|
92
91
|
if (validKeys.length) {
|
|
93
92
|
error += ` Did you mean something like '${pathToString([
|
|
94
93
|
...pathSegments,
|
|
@@ -104,12 +103,11 @@ function validatePath(config, path, defaultValue) {
|
|
|
104
103
|
const [themeSection] = pathSegments;
|
|
105
104
|
return {
|
|
106
105
|
isValid: true,
|
|
107
|
-
value: (0, _transformThemeValue).default(themeSection)(value)
|
|
106
|
+
value: (0, _transformThemeValue).default(themeSection)(value, themeOpts)
|
|
108
107
|
};
|
|
109
108
|
}
|
|
110
109
|
function extractArgs(node, vNodes, functions) {
|
|
111
|
-
vNodes = vNodes.map((vNode)=>resolveVNode(node, vNode, functions)
|
|
112
|
-
);
|
|
110
|
+
vNodes = vNodes.map((vNode)=>resolveVNode(node, vNode, functions));
|
|
113
111
|
let args = [
|
|
114
112
|
""
|
|
115
113
|
];
|
|
@@ -142,17 +140,28 @@ let nodeTypePropertyMap = {
|
|
|
142
140
|
function _default({ tailwindConfig: config }) {
|
|
143
141
|
let functions = {
|
|
144
142
|
theme: (node, path, ...defaultValue)=>{
|
|
145
|
-
|
|
143
|
+
let matches = path.match(/^([^\/\s]+)(?:\s*\/\s*([^\/\s]+))$/);
|
|
144
|
+
let alpha = undefined;
|
|
145
|
+
if (matches) {
|
|
146
|
+
path = matches[1];
|
|
147
|
+
alpha = matches[2];
|
|
148
|
+
}
|
|
149
|
+
let { isValid , value , error } = validatePath(config, path, defaultValue.length ? defaultValue : undefined, {
|
|
150
|
+
opacityValue: alpha
|
|
151
|
+
});
|
|
146
152
|
if (!isValid) {
|
|
147
153
|
throw node.error(error);
|
|
148
154
|
}
|
|
155
|
+
if (alpha !== undefined) {
|
|
156
|
+
value = (0, _pluginUtils).parseColorFormat(value);
|
|
157
|
+
value = (0, _withAlphaVariable).withAlphaValue(value, alpha, value);
|
|
158
|
+
}
|
|
149
159
|
return value;
|
|
150
160
|
},
|
|
151
161
|
screen: (node, screen)=>{
|
|
152
162
|
screen = screen.replace(/^['"]+/g, "").replace(/['"]+$/g, "");
|
|
153
163
|
let screens = (0, _normalizeScreens).normalizeScreens(config.theme.screens);
|
|
154
|
-
let screenDefinition = screens.find(({ name })=>name === screen
|
|
155
|
-
);
|
|
164
|
+
let screenDefinition = screens.find(({ name })=>name === screen);
|
|
156
165
|
if (!screenDefinition) {
|
|
157
166
|
throw node.error(`The '${screen}' screen does not exist in your theme.`);
|
|
158
167
|
}
|