tailwindcss 3.0.0-alpha.2 → 3.0.3
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 +59 -2
- package/colors.js +2 -1
- package/defaultConfig.js +2 -1
- package/defaultTheme.js +2 -1
- package/lib/cli.js +58 -58
- package/lib/corePluginList.js +3 -0
- package/lib/corePlugins.js +227 -172
- package/lib/css/preflight.css +5 -3
- package/lib/featureFlags.js +3 -1
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +6 -2
- package/lib/lib/expandApplyAtRules.js +23 -6
- package/lib/lib/expandTailwindAtRules.js +19 -1
- package/lib/lib/generateRules.js +54 -0
- package/lib/lib/resolveDefaultsAtRules.js +23 -9
- package/lib/lib/setupContextUtils.js +48 -71
- package/lib/lib/substituteScreenAtRules.js +7 -4
- package/lib/util/buildMediaQuery.js +13 -24
- package/lib/util/dataTypes.js +14 -3
- package/lib/util/defaults.js +6 -0
- package/lib/util/formatVariantSelector.js +88 -4
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +4 -0
- package/lib/util/nameClass.js +1 -0
- package/lib/util/normalizeConfig.js +34 -5
- package/lib/util/normalizeScreens.js +61 -0
- package/lib/util/resolveConfig.js +8 -8
- package/package.json +14 -13
- package/peers/index.js +3739 -3027
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +205 -165
- package/src/css/preflight.css +5 -3
- package/src/featureFlags.js +5 -1
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +5 -2
- package/src/lib/expandApplyAtRules.js +29 -2
- package/src/lib/expandTailwindAtRules.js +18 -0
- package/src/lib/generateRules.js +57 -0
- package/src/lib/resolveDefaultsAtRules.js +28 -7
- package/src/lib/setupContextUtils.js +45 -64
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/dataTypes.js +11 -6
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +92 -1
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +4 -0
- package/src/util/nameClass.js +1 -1
- package/src/util/normalizeConfig.js +14 -1
- package/src/util/normalizeScreens.js +45 -0
- package/stubs/defaultConfig.stub.js +17 -0
package/lib/css/preflight.css
CHANGED
|
@@ -144,7 +144,7 @@ sup {
|
|
|
144
144
|
table {
|
|
145
145
|
text-indent: 0; /* 1 */
|
|
146
146
|
border-color: inherit; /* 2 */
|
|
147
|
-
border-collapse: collapse;
|
|
147
|
+
border-collapse: collapse; /* 3 */
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/*
|
|
@@ -288,7 +288,9 @@ legend {
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
ol,
|
|
291
|
-
ul
|
|
291
|
+
ul,
|
|
292
|
+
li,
|
|
293
|
+
menu {
|
|
292
294
|
list-style: none;
|
|
293
295
|
margin: 0;
|
|
294
296
|
padding: 0;
|
|
@@ -309,7 +311,7 @@ textarea {
|
|
|
309
311
|
|
|
310
312
|
input::placeholder,
|
|
311
313
|
textarea::placeholder {
|
|
312
|
-
opacity: 1;
|
|
314
|
+
opacity: 1; /* 1 */
|
|
313
315
|
color: theme('colors.gray.400', #9ca3af); /* 2 */
|
|
314
316
|
}
|
|
315
317
|
|
package/lib/featureFlags.js
CHANGED
|
@@ -13,7 +13,9 @@ function _interopRequireDefault(obj) {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
let defaults = {
|
|
16
|
-
|
|
16
|
+
// TODO: Drop this once we can safely rely on optimizeUniversalDefaults being
|
|
17
|
+
// the default.
|
|
18
|
+
optimizeUniversalDefaults: process.env.NODE_ENV === 'test' ? true : false
|
|
17
19
|
};
|
|
18
20
|
let featureFlags = {
|
|
19
21
|
future: [],
|
package/lib/lib/detectNesting.js
CHANGED
|
@@ -6,12 +6,27 @@ exports.default = _default;
|
|
|
6
6
|
function _default(_context) {
|
|
7
7
|
return (root, result)=>{
|
|
8
8
|
let found = false;
|
|
9
|
+
root.walkAtRules('tailwind', (node)=>{
|
|
10
|
+
if (found) return false;
|
|
11
|
+
if (node.parent && node.parent.type !== 'root') {
|
|
12
|
+
found = true;
|
|
13
|
+
node.warn(result, [
|
|
14
|
+
'Nested @tailwind rules were detected, but are not supported.',
|
|
15
|
+
"Consider using a prefix to scope Tailwind's classes: https://tailwindcss.com/docs/configuration#prefix",
|
|
16
|
+
'Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy',
|
|
17
|
+
].join('\n'));
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
9
21
|
root.walkRules((rule)=>{
|
|
10
22
|
if (found) return false;
|
|
11
23
|
rule.walkRules((nestedRule)=>{
|
|
12
24
|
found = true;
|
|
13
|
-
nestedRule.warn(result,
|
|
14
|
-
|
|
25
|
+
nestedRule.warn(result, [
|
|
26
|
+
'Nested CSS was detected, but CSS nesting has not been configured correctly.',
|
|
27
|
+
'Please enable a CSS nesting plugin *before* Tailwind in your configuration.',
|
|
28
|
+
'See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting',
|
|
29
|
+
].join('\n'));
|
|
15
30
|
return false;
|
|
16
31
|
});
|
|
17
32
|
});
|
|
@@ -7,6 +7,7 @@ var _dlv = _interopRequireDefault(require("dlv"));
|
|
|
7
7
|
var _didyoumean = _interopRequireDefault(require("didyoumean"));
|
|
8
8
|
var _transformThemeValue = _interopRequireDefault(require("../util/transformThemeValue"));
|
|
9
9
|
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
10
|
+
var _normalizeScreens = require("../util/normalizeScreens");
|
|
10
11
|
var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
|
|
11
12
|
var _toPath = require("../util/toPath");
|
|
12
13
|
function _interopRequireDefault(obj) {
|
|
@@ -149,10 +150,13 @@ function _default({ tailwindConfig: config }) {
|
|
|
149
150
|
},
|
|
150
151
|
screen: (node, screen)=>{
|
|
151
152
|
screen = screen.replace(/^['"]+/g, '').replace(/['"]+$/g, '');
|
|
152
|
-
|
|
153
|
+
let screens = (0, _normalizeScreens).normalizeScreens(config.theme.screens);
|
|
154
|
+
let screenDefinition = screens.find(({ name })=>name === screen
|
|
155
|
+
);
|
|
156
|
+
if (!screenDefinition) {
|
|
153
157
|
throw node.error(`The '${screen}' screen does not exist in your theme.`);
|
|
154
158
|
}
|
|
155
|
-
return (0, _buildMediaQuery).default(
|
|
159
|
+
return (0, _buildMediaQuery).default(screenDefinition);
|
|
156
160
|
}
|
|
157
161
|
};
|
|
158
162
|
return (root)=>{
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
exports.default = expandApplyAtRules;
|
|
6
6
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
7
|
+
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
7
8
|
var _generateRules = require("./generateRules");
|
|
8
9
|
var _bigSign = _interopRequireDefault(require("../util/bigSign"));
|
|
9
10
|
var _escapeClassName = _interopRequireDefault(require("../util/escapeClassName"));
|
|
@@ -12,9 +13,21 @@ function _interopRequireDefault(obj) {
|
|
|
12
13
|
default: obj
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
function containsBase(selector, classCandidateBase, separator) {
|
|
17
|
+
return (0, _postcssSelectorParser).default((selectors)=>{
|
|
18
|
+
let contains = false;
|
|
19
|
+
selectors.walkClasses((classSelector)=>{
|
|
20
|
+
if (classSelector.value.split(separator).pop() === classCandidateBase) {
|
|
21
|
+
contains = true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return contains;
|
|
26
|
+
}).transformSync(selector);
|
|
27
|
+
}
|
|
28
|
+
function prefix(context, selector) {
|
|
29
|
+
let prefix1 = context.tailwindConfig.prefix;
|
|
30
|
+
return typeof prefix1 === 'function' ? prefix1(selector) : prefix1 + selector;
|
|
18
31
|
}
|
|
19
32
|
function buildApplyCache(applyCandidates, context) {
|
|
20
33
|
for (let candidate of applyCandidates){
|
|
@@ -127,8 +140,8 @@ function processApply(root, context) {
|
|
|
127
140
|
*/ // TODO: Should we use postcss-selector-parser for this instead?
|
|
128
141
|
function replaceSelector(selector, utilitySelectors, candidate) {
|
|
129
142
|
let needle = `.${(0, _escapeClassName).default(candidate)}`;
|
|
130
|
-
let utilitySelectorsList = utilitySelectors.split(/\s
|
|
131
|
-
return selector.split(/\s
|
|
143
|
+
let utilitySelectorsList = utilitySelectors.split(/\s*\,(?![^(]*\))\s*/g);
|
|
144
|
+
return selector.split(/\s*\,(?![^(]*\))\s*/g).map((s)=>{
|
|
132
145
|
let replaced = [];
|
|
133
146
|
for (let utilitySelector of utilitySelectorsList){
|
|
134
147
|
let replacedSelector = utilitySelector.replace(needle, s);
|
|
@@ -156,7 +169,7 @@ function processApply(root, context) {
|
|
|
156
169
|
}
|
|
157
170
|
for (let applyCandidate of applyCandidates){
|
|
158
171
|
if (!applyClassCache.has(applyCandidate)) {
|
|
159
|
-
if (applyCandidate ===
|
|
172
|
+
if (applyCandidate === prefix(context, 'group')) {
|
|
160
173
|
// TODO: Link to specific documentation page with error code.
|
|
161
174
|
throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
|
|
162
175
|
}
|
|
@@ -173,7 +186,11 @@ function processApply(root, context) {
|
|
|
173
186
|
for (const [parent, candidates] of perParentApplies){
|
|
174
187
|
let siblings = [];
|
|
175
188
|
for (let [applyCandidate, important, rules] of candidates){
|
|
189
|
+
let base = applyCandidate.split(context.tailwindConfig.separator).pop();
|
|
176
190
|
for (let [meta, node] of rules){
|
|
191
|
+
if (containsBase(parent.selector, base, context.tailwindConfig.separator) && containsBase(node.selector, base, context.tailwindConfig.separator)) {
|
|
192
|
+
throw node.error(`Circular dependency detected when using: \`@apply ${applyCandidate}\``);
|
|
193
|
+
}
|
|
177
194
|
let root = _postcss.default.root({
|
|
178
195
|
nodes: [
|
|
179
196
|
node.clone()
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = expandTailwindAtRules;
|
|
6
|
+
exports.DEFAULTS_LAYER = void 0;
|
|
6
7
|
var _quickLru = _interopRequireDefault(require("quick-lru"));
|
|
7
8
|
var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
8
9
|
var _generateRules = require("./generateRules");
|
|
@@ -46,6 +47,8 @@ const PATTERNS = [
|
|
|
46
47
|
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
|
|
47
48
|
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
|
|
48
49
|
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
50
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
|
|
51
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
|
|
49
52
|
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
|
|
50
53
|
/([^<>"'`\s]*[^"'`\s:])/.source
|
|
51
54
|
].join('|');
|
|
@@ -110,6 +113,7 @@ function buildStylesheet(rules, context) {
|
|
|
110
113
|
);
|
|
111
114
|
let returnValue = {
|
|
112
115
|
base: new Set(),
|
|
116
|
+
defaults: new Set(),
|
|
113
117
|
components: new Set(),
|
|
114
118
|
utilities: new Set(),
|
|
115
119
|
variants: new Set(),
|
|
@@ -132,6 +136,10 @@ function buildStylesheet(rules, context) {
|
|
|
132
136
|
returnValue.base.add(rule);
|
|
133
137
|
continue;
|
|
134
138
|
}
|
|
139
|
+
if (sort & context.layerOrder.defaults) {
|
|
140
|
+
returnValue.defaults.add(rule);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
135
143
|
if (sort & context.layerOrder.components) {
|
|
136
144
|
returnValue.components.add(rule);
|
|
137
145
|
continue;
|
|
@@ -147,6 +155,8 @@ function buildStylesheet(rules, context) {
|
|
|
147
155
|
}
|
|
148
156
|
return returnValue;
|
|
149
157
|
}
|
|
158
|
+
const DEFAULTS_LAYER = Symbol('defaults-layer');
|
|
159
|
+
exports.DEFAULTS_LAYER = DEFAULTS_LAYER;
|
|
150
160
|
function expandTailwindAtRules(context) {
|
|
151
161
|
return (root)=>{
|
|
152
162
|
let layerNodes = {
|
|
@@ -197,9 +207,17 @@ function expandTailwindAtRules(context) {
|
|
|
197
207
|
], context);
|
|
198
208
|
}
|
|
199
209
|
env.DEBUG && console.timeEnd('Build stylesheet');
|
|
200
|
-
let { base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
210
|
+
let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
201
211
|
// ---
|
|
202
212
|
// Replace any Tailwind directives with generated CSS
|
|
213
|
+
// @defaults rules are unconditionally added first to ensure that
|
|
214
|
+
// using any utility that relies on defaults will work even when
|
|
215
|
+
// compiled in an isolated environment like CSS modules
|
|
216
|
+
if (context.tailwindConfig[DEFAULTS_LAYER] !== false) {
|
|
217
|
+
root.prepend((0, _cloneNodes).default([
|
|
218
|
+
...defaultNodes
|
|
219
|
+
], root.source));
|
|
220
|
+
}
|
|
203
221
|
if (layerNodes.base) {
|
|
204
222
|
layerNodes.base.before((0, _cloneNodes).default([
|
|
205
223
|
...baseNodes
|
package/lib/lib/generateRules.js
CHANGED
|
@@ -11,6 +11,9 @@ var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
|
|
|
11
11
|
var _pluginUtils = require("../util/pluginUtils");
|
|
12
12
|
var _log = _interopRequireDefault(require("../util/log"));
|
|
13
13
|
var _formatVariantSelector = require("../util/formatVariantSelector");
|
|
14
|
+
var _nameClass = require("../util/nameClass");
|
|
15
|
+
var _dataTypes = require("../util/dataTypes");
|
|
16
|
+
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
14
17
|
function _interopRequireDefault(obj) {
|
|
15
18
|
return obj && obj.__esModule ? obj : {
|
|
16
19
|
default: obj
|
|
@@ -250,6 +253,49 @@ function parseRules(rule, cache, options = {
|
|
|
250
253
|
options
|
|
251
254
|
];
|
|
252
255
|
}
|
|
256
|
+
const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
|
|
257
|
+
function isValidPropName(name) {
|
|
258
|
+
return IS_VALID_PROPERTY_NAME.test(name);
|
|
259
|
+
}
|
|
260
|
+
function isParsableCssValue(property, value) {
|
|
261
|
+
try {
|
|
262
|
+
_postcss.default.parse(`a{${property}:${value}}`).toResult();
|
|
263
|
+
return true;
|
|
264
|
+
} catch (err) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function extractArbitraryProperty(classCandidate, context) {
|
|
269
|
+
var ref;
|
|
270
|
+
let [, property, value] = (ref = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && ref !== void 0 ? ref : [];
|
|
271
|
+
if (value === undefined) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
if (!isValidPropName(property)) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
let normalized = (0, _dataTypes).normalize(value);
|
|
281
|
+
if (!isParsableCssValue(property, normalized)) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
return [
|
|
285
|
+
[
|
|
286
|
+
{
|
|
287
|
+
sort: context.arbitraryPropertiesSort,
|
|
288
|
+
layer: 'utilities'
|
|
289
|
+
},
|
|
290
|
+
()=>({
|
|
291
|
+
[(0, _nameClass).asClass(classCandidate)]: {
|
|
292
|
+
[property]: normalized
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
,
|
|
296
|
+
],
|
|
297
|
+
];
|
|
298
|
+
}
|
|
253
299
|
function* resolveMatchedPlugins(classCandidate, context) {
|
|
254
300
|
if (context.candidateRuleMap.has(classCandidate)) {
|
|
255
301
|
yield [
|
|
@@ -257,6 +303,14 @@ function* resolveMatchedPlugins(classCandidate, context) {
|
|
|
257
303
|
'DEFAULT'
|
|
258
304
|
];
|
|
259
305
|
}
|
|
306
|
+
yield* (function*(arbitraryPropertyRule) {
|
|
307
|
+
if (arbitraryPropertyRule !== null) {
|
|
308
|
+
yield [
|
|
309
|
+
arbitraryPropertyRule,
|
|
310
|
+
'DEFAULT'
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
})(extractArbitraryProperty(classCandidate, context));
|
|
260
314
|
let candidatePrefix = classCandidate;
|
|
261
315
|
let negative = false;
|
|
262
316
|
const twConfigPrefix = context.tailwindConfig.prefix;
|
|
@@ -79,7 +79,7 @@ function extractElementSelector(selector) {
|
|
|
79
79
|
function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
80
80
|
return (root)=>{
|
|
81
81
|
let variableNodeMap = new Map();
|
|
82
|
-
let universals = new Set();
|
|
82
|
+
/** @type {Set<import('postcss').AtRule>} */ let universals = new Set();
|
|
83
83
|
root.walkAtRules('defaults', (rule)=>{
|
|
84
84
|
if (rule.nodes && rule.nodes.length > 0) {
|
|
85
85
|
universals.add(rule);
|
|
@@ -93,32 +93,46 @@ function resolveDefaultsAtRules({ tailwindConfig }) {
|
|
|
93
93
|
rule.remove();
|
|
94
94
|
});
|
|
95
95
|
for (let universal of universals){
|
|
96
|
-
let
|
|
96
|
+
/** @type {Map<string, Set<string>>} */ let selectorGroups = new Map();
|
|
97
97
|
var ref;
|
|
98
98
|
let rules = (ref = variableNodeMap.get(universal.params)) !== null && ref !== void 0 ? ref : [];
|
|
99
99
|
for (let rule of rules){
|
|
100
100
|
for (let selector of extractElementSelector(rule.selector)){
|
|
101
|
+
// If selector contains a vendor prefix after a pseudo element or class,
|
|
102
|
+
// we consider them separately because merging the declarations into
|
|
103
|
+
// a single rule will cause browsers that do not understand the
|
|
104
|
+
// vendor prefix to throw out the whole rule
|
|
105
|
+
let selectorGroupName = selector.includes(':-') || selector.includes('::-') ? selector : '__DEFAULT__';
|
|
106
|
+
var ref1;
|
|
107
|
+
let selectors = (ref1 = selectorGroups.get(selectorGroupName)) !== null && ref1 !== void 0 ? ref1 : new Set();
|
|
108
|
+
selectorGroups.set(selectorGroupName, selectors);
|
|
101
109
|
selectors.add(selector);
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
|
-
if (
|
|
112
|
+
if (selectorGroups.size === 0) {
|
|
105
113
|
universal.remove();
|
|
106
114
|
continue;
|
|
107
115
|
}
|
|
108
|
-
let universalRule = _postcss.default.rule();
|
|
109
116
|
if ((0, _featureFlags).flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
for (let [, selectors] of selectorGroups){
|
|
118
|
+
let universalRule = _postcss.default.rule();
|
|
119
|
+
universalRule.selectors = [
|
|
120
|
+
...selectors
|
|
121
|
+
];
|
|
122
|
+
universalRule.append(universal.nodes.map((node)=>node.clone()
|
|
123
|
+
));
|
|
124
|
+
universal.before(universalRule);
|
|
125
|
+
}
|
|
113
126
|
} else {
|
|
127
|
+
let universalRule = _postcss.default.rule();
|
|
114
128
|
universalRule.selectors = [
|
|
115
129
|
'*',
|
|
116
130
|
'::before',
|
|
117
131
|
'::after'
|
|
118
132
|
];
|
|
133
|
+
universalRule.append(universal.nodes);
|
|
134
|
+
universal.before(universalRule);
|
|
119
135
|
}
|
|
120
|
-
universalRule.append(universal.nodes);
|
|
121
|
-
universal.before(universalRule);
|
|
122
136
|
universal.remove();
|
|
123
137
|
}
|
|
124
138
|
};
|
|
@@ -23,6 +23,7 @@ var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
|
23
23
|
var _toPath = require("../util/toPath");
|
|
24
24
|
var _log = _interopRequireDefault(require("../util/log"));
|
|
25
25
|
var _negateValue = _interopRequireDefault(require("../util/negateValue"));
|
|
26
|
+
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
26
27
|
function _interopRequireDefault(obj) {
|
|
27
28
|
return obj && obj.__esModule ? obj : {
|
|
28
29
|
default: obj
|
|
@@ -160,68 +161,6 @@ function withIdentifiers(styles) {
|
|
|
160
161
|
});
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
|
-
let matchingBrackets = new Map([
|
|
164
|
-
[
|
|
165
|
-
'{',
|
|
166
|
-
'}'
|
|
167
|
-
],
|
|
168
|
-
[
|
|
169
|
-
'[',
|
|
170
|
-
']'
|
|
171
|
-
],
|
|
172
|
-
[
|
|
173
|
-
'(',
|
|
174
|
-
')'
|
|
175
|
-
],
|
|
176
|
-
]);
|
|
177
|
-
let inverseMatchingBrackets = new Map(Array.from(matchingBrackets.entries()).map(([k, v])=>[
|
|
178
|
-
v,
|
|
179
|
-
k
|
|
180
|
-
]
|
|
181
|
-
));
|
|
182
|
-
let quotes = new Set([
|
|
183
|
-
'"',
|
|
184
|
-
"'",
|
|
185
|
-
'`'
|
|
186
|
-
]);
|
|
187
|
-
// Arbitrary values must contain balanced brackets (), [] and {}. Escaped
|
|
188
|
-
// values don't count, and brackets inside quotes also don't count.
|
|
189
|
-
//
|
|
190
|
-
// E.g.: w-[this-is]w-[weird-and-invalid]
|
|
191
|
-
// E.g.: w-[this-is\\]w-\\[weird-but-valid]
|
|
192
|
-
// E.g.: content-['this-is-also-valid]-weirdly-enough']
|
|
193
|
-
function isValidArbitraryValue(value) {
|
|
194
|
-
let stack = [];
|
|
195
|
-
let inQuotes = false;
|
|
196
|
-
for(let i = 0; i < value.length; i++){
|
|
197
|
-
let char = value[i];
|
|
198
|
-
// Non-escaped quotes allow us to "allow" anything in between
|
|
199
|
-
if (quotes.has(char) && value[i - 1] !== '\\') {
|
|
200
|
-
inQuotes = !inQuotes;
|
|
201
|
-
}
|
|
202
|
-
if (inQuotes) continue;
|
|
203
|
-
if (value[i - 1] === '\\') continue; // Escaped
|
|
204
|
-
if (matchingBrackets.has(char)) {
|
|
205
|
-
stack.push(char);
|
|
206
|
-
} else if (inverseMatchingBrackets.has(char)) {
|
|
207
|
-
let inverse = inverseMatchingBrackets.get(char);
|
|
208
|
-
// Nothing to pop from, therefore it is unbalanced
|
|
209
|
-
if (stack.length <= 0) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
// Popped value must match the inverse value, otherwise it is unbalanced
|
|
213
|
-
if (stack.pop() !== inverse) {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
// If there is still something on the stack, it is also unbalanced
|
|
219
|
-
if (stack.length > 0) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
// All good, totally balanced!
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
164
|
function buildPluginApi(tailwindConfig, context, { variantList , variantMap , offsets , classList }) {
|
|
226
165
|
function getConfigValue(path, defaultValue) {
|
|
227
166
|
return path ? (0, _dlv).default(tailwindConfig, path, defaultValue) : tailwindConfig;
|
|
@@ -332,6 +271,29 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
332
271
|
]);
|
|
333
272
|
}
|
|
334
273
|
},
|
|
274
|
+
/**
|
|
275
|
+
* @param {string} group
|
|
276
|
+
* @param {Record<string, string | string[]>} declarations
|
|
277
|
+
*/ addDefaults (group, declarations) {
|
|
278
|
+
const groups = {
|
|
279
|
+
[`@defaults ${group}`]: declarations
|
|
280
|
+
};
|
|
281
|
+
for (let [identifier, rule] of withIdentifiers(groups)){
|
|
282
|
+
let prefixedIdentifier = prefixIdentifier(identifier, {
|
|
283
|
+
});
|
|
284
|
+
let offset = offsets.base++;
|
|
285
|
+
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
286
|
+
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
287
|
+
}
|
|
288
|
+
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
289
|
+
{
|
|
290
|
+
sort: offset,
|
|
291
|
+
layer: 'defaults'
|
|
292
|
+
},
|
|
293
|
+
rule
|
|
294
|
+
]);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
335
297
|
addComponents (components, options) {
|
|
336
298
|
let defaultOptions = {
|
|
337
299
|
respectPrefix: true,
|
|
@@ -409,7 +371,7 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
409
371
|
if (!type.includes(coercedType) && !isOnlyPlugin) {
|
|
410
372
|
return [];
|
|
411
373
|
}
|
|
412
|
-
if (!
|
|
374
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
413
375
|
return [];
|
|
414
376
|
}
|
|
415
377
|
let ruleSets = [].concat(rule(value)).filter(Boolean).map((declaration)=>({
|
|
@@ -466,7 +428,7 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
466
428
|
return [];
|
|
467
429
|
}
|
|
468
430
|
}
|
|
469
|
-
if (!
|
|
431
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
470
432
|
return [];
|
|
471
433
|
}
|
|
472
434
|
let ruleSets = [].concat(rule(value)).filter(Boolean).map((declaration)=>({
|
|
@@ -608,7 +570,8 @@ function resolvePlugins(context, root) {
|
|
|
608
570
|
_corePlugins.variantPlugins['reducedMotionVariants'],
|
|
609
571
|
_corePlugins.variantPlugins['darkVariants'],
|
|
610
572
|
_corePlugins.variantPlugins['printVariant'],
|
|
611
|
-
_corePlugins.variantPlugins['screenVariants'],
|
|
573
|
+
_corePlugins.variantPlugins['screenVariants'],
|
|
574
|
+
_corePlugins.variantPlugins['orientationVariants'],
|
|
612
575
|
];
|
|
613
576
|
return [
|
|
614
577
|
...corePluginList,
|
|
@@ -622,6 +585,7 @@ function registerPlugins(plugins, context) {
|
|
|
622
585
|
let variantList = [];
|
|
623
586
|
let variantMap = new Map();
|
|
624
587
|
let offsets = {
|
|
588
|
+
defaults: 0n,
|
|
625
589
|
base: 0n,
|
|
626
590
|
components: 0n,
|
|
627
591
|
utilities: 0n,
|
|
@@ -647,18 +611,23 @@ function registerPlugins(plugins, context) {
|
|
|
647
611
|
)
|
|
648
612
|
)([
|
|
649
613
|
offsets.base,
|
|
614
|
+
offsets.defaults,
|
|
650
615
|
offsets.components,
|
|
651
616
|
offsets.utilities,
|
|
652
617
|
offsets.user,
|
|
653
618
|
]);
|
|
654
619
|
let reservedBits = BigInt(highestOffset.toString(2).length);
|
|
620
|
+
// A number one less than the top range of the highest offset area
|
|
621
|
+
// so arbitrary properties are always sorted at the end.
|
|
622
|
+
context.arbitraryPropertiesSort = (1n << reservedBits << 0n) - 1n;
|
|
655
623
|
context.layerOrder = {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
624
|
+
defaults: 1n << reservedBits << 0n,
|
|
625
|
+
base: 1n << reservedBits << 1n,
|
|
626
|
+
components: 1n << reservedBits << 2n,
|
|
627
|
+
utilities: 1n << reservedBits << 3n,
|
|
628
|
+
user: 1n << reservedBits << 4n
|
|
660
629
|
};
|
|
661
|
-
reservedBits +=
|
|
630
|
+
reservedBits += 5n;
|
|
662
631
|
let offset = 0;
|
|
663
632
|
context.variantOrder = new Map(variantList.map((variant, i)=>{
|
|
664
633
|
let variantFunctions = variantMap.get(variant).length;
|
|
@@ -709,9 +678,17 @@ function registerPlugins(plugins, context) {
|
|
|
709
678
|
let utils = Array.isArray(util) ? (()=>{
|
|
710
679
|
let [utilName, options] = util;
|
|
711
680
|
var ref;
|
|
712
|
-
|
|
681
|
+
let classes = Object.keys((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {
|
|
713
682
|
}).map((value)=>(0, _nameClass).formatClass(utilName, value)
|
|
714
683
|
);
|
|
684
|
+
if (options === null || options === void 0 ? void 0 : options.supportsNegativeValues) {
|
|
685
|
+
classes = [
|
|
686
|
+
...classes,
|
|
687
|
+
...classes.map((cls)=>'-' + cls
|
|
688
|
+
)
|
|
689
|
+
];
|
|
690
|
+
}
|
|
691
|
+
return classes;
|
|
715
692
|
})() : [
|
|
716
693
|
util
|
|
717
694
|
];
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = _default;
|
|
6
|
+
var _normalizeScreens = require("../util/normalizeScreens");
|
|
6
7
|
var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
|
|
7
8
|
function _interopRequireDefault(obj) {
|
|
8
9
|
return obj && obj.__esModule ? obj : {
|
|
@@ -12,13 +13,15 @@ function _interopRequireDefault(obj) {
|
|
|
12
13
|
function _default({ tailwindConfig: { theme } }) {
|
|
13
14
|
return function(css) {
|
|
14
15
|
css.walkAtRules('screen', (atRule)=>{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
let screen = atRule.params;
|
|
17
|
+
let screens = (0, _normalizeScreens).normalizeScreens(theme.screens);
|
|
18
|
+
let screenDefinition = screens.find(({ name })=>name === screen
|
|
19
|
+
);
|
|
20
|
+
if (!screenDefinition) {
|
|
18
21
|
throw atRule.error(`No \`${screen}\` screen found.`);
|
|
19
22
|
}
|
|
20
23
|
atRule.name = 'media';
|
|
21
|
-
atRule.params = (0, _buildMediaQuery).default(
|
|
24
|
+
atRule.params = (0, _buildMediaQuery).default(screenDefinition);
|
|
22
25
|
});
|
|
23
26
|
};
|
|
24
27
|
}
|
|
@@ -4,28 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
exports.default = buildMediaQuery;
|
|
6
6
|
function buildMediaQuery(screens) {
|
|
7
|
-
|
|
8
|
-
screens
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return screen.raw;
|
|
21
|
-
}
|
|
22
|
-
return Object.entries(screen).map(([feature, value])=>{
|
|
23
|
-
var _feature;
|
|
24
|
-
feature = (_feature = ({
|
|
25
|
-
min: 'min-width',
|
|
26
|
-
max: 'max-width'
|
|
27
|
-
})[feature]) !== null && _feature !== void 0 ? _feature : feature;
|
|
28
|
-
return `(${feature}: ${value})`;
|
|
29
|
-
}).join(' and ');
|
|
30
|
-
}).join(', ');
|
|
7
|
+
screens = Array.isArray(screens) ? screens : [
|
|
8
|
+
screens
|
|
9
|
+
];
|
|
10
|
+
return screens.map((screen1)=>screen1.values.map((screen)=>{
|
|
11
|
+
if (screen.raw !== undefined) {
|
|
12
|
+
return screen.raw;
|
|
13
|
+
}
|
|
14
|
+
return [
|
|
15
|
+
screen.min && `(min-width: ${screen.min})`,
|
|
16
|
+
screen.max && `(max-width: ${screen.max})`,
|
|
17
|
+
].filter(Boolean).join(' and ');
|
|
18
|
+
})
|
|
19
|
+
).join(', ');
|
|
31
20
|
}
|
package/lib/util/dataTypes.js
CHANGED
|
@@ -19,6 +19,12 @@ exports.absoluteSize = absoluteSize;
|
|
|
19
19
|
exports.relativeSize = relativeSize;
|
|
20
20
|
var _color = require("./color");
|
|
21
21
|
var _parseBoxShadowValue = require("./parseBoxShadowValue");
|
|
22
|
+
let cssFunctions = [
|
|
23
|
+
'min',
|
|
24
|
+
'max',
|
|
25
|
+
'clamp',
|
|
26
|
+
'calc'
|
|
27
|
+
];
|
|
22
28
|
// Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
|
|
23
29
|
let COMMA = /,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
|
|
24
30
|
;
|
|
@@ -49,10 +55,12 @@ function url(value) {
|
|
|
49
55
|
return value.startsWith('url(');
|
|
50
56
|
}
|
|
51
57
|
function number(value) {
|
|
52
|
-
return !isNaN(Number(value))
|
|
58
|
+
return !isNaN(Number(value)) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?`).test(value)
|
|
59
|
+
);
|
|
53
60
|
}
|
|
54
61
|
function percentage(value) {
|
|
55
|
-
return /%$/g.test(value) ||
|
|
62
|
+
return /%$/g.test(value) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?%`).test(value)
|
|
63
|
+
);
|
|
56
64
|
}
|
|
57
65
|
let lengthUnits = [
|
|
58
66
|
'cm',
|
|
@@ -74,7 +82,10 @@ let lengthUnits = [
|
|
|
74
82
|
];
|
|
75
83
|
let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`;
|
|
76
84
|
function length(value) {
|
|
77
|
-
return
|
|
85
|
+
return value.split(UNDERSCORE).every((part)=>{
|
|
86
|
+
return part === '0' || new RegExp(`${lengthUnitsPattern}$`).test(part) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(part)
|
|
87
|
+
);
|
|
88
|
+
});
|
|
78
89
|
}
|
|
79
90
|
let lineWidths = new Set([
|
|
80
91
|
'thin',
|