tailwindcss 0.0.0-insiders.8259dfd → 0.0.0-insiders.8293c2d
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 +207 -2
- package/README.md +8 -4
- package/colors.js +2 -1
- package/defaultConfig.js +2 -1
- package/defaultTheme.js +2 -1
- package/lib/cli.js +94 -61
- package/lib/constants.js +1 -1
- package/lib/corePluginList.js +8 -1
- package/lib/corePlugins.js +477 -517
- package/lib/css/preflight.css +18 -5
- package/lib/featureFlags.js +5 -6
- package/lib/index.js +1 -3
- package/lib/lib/collapseDuplicateDeclarations.js +80 -0
- package/lib/lib/defaultExtractor.js +42 -0
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +10 -6
- package/lib/lib/expandApplyAtRules.js +94 -45
- package/lib/lib/expandTailwindAtRules.js +32 -33
- package/lib/lib/generateRules.js +167 -21
- package/lib/lib/normalizeTailwindDirectives.js +8 -1
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +28 -14
- package/lib/lib/setupContextUtils.js +153 -129
- package/lib/lib/setupTrackingContext.js +11 -10
- package/lib/lib/sharedState.js +34 -5
- package/lib/lib/substituteScreenAtRules.js +7 -4
- package/lib/processTailwindFeatures.js +7 -2
- package/lib/util/buildMediaQuery.js +13 -24
- package/lib/util/color.js +23 -8
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +6 -10
- package/lib/util/dataTypes.js +38 -7
- package/lib/util/defaults.js +6 -0
- package/lib/util/flattenColorPalette.js +1 -3
- package/lib/util/formatVariantSelector.js +186 -0
- 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 +63 -21
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseBoxShadowValue.js +77 -0
- package/lib/util/pluginUtils.js +27 -158
- package/lib/util/prefixSelector.js +1 -3
- package/lib/util/resolveConfig.js +30 -31
- package/lib/util/resolveConfigPath.js +1 -2
- package/lib/util/toColorValue.js +1 -2
- package/lib/util/toPath.js +6 -1
- package/lib/util/transformThemeValue.js +19 -13
- package/nesting/plugin.js +4 -1
- package/package.json +19 -21
- package/peers/index.js +4621 -5626
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/src/cli.js +66 -14
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +406 -518
- package/src/css/preflight.css +18 -5
- package/src/featureFlags.js +1 -1
- package/src/index.js +1 -7
- package/src/lib/collapseDuplicateDeclarations.js +93 -0
- package/src/lib/defaultExtractor.js +48 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +6 -3
- package/src/lib/expandApplyAtRules.js +101 -45
- package/src/lib/expandTailwindAtRules.js +33 -27
- package/src/lib/generateRules.js +178 -11
- package/src/lib/normalizeTailwindDirectives.js +6 -1
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/resolveDefaultsAtRules.js +31 -10
- package/src/lib/setupContextUtils.js +140 -84
- package/src/lib/setupTrackingContext.js +11 -10
- package/src/lib/sharedState.js +40 -4
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/processTailwindFeatures.js +8 -2
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/color.js +20 -7
- package/src/util/dataTypes.js +43 -11
- 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 +4 -0
- package/src/util/nameClass.js +1 -1
- package/src/util/normalizeConfig.js +37 -2
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +71 -0
- package/src/util/pluginUtils.js +15 -138
- package/src/util/prefixSelector.js +1 -4
- package/src/util/resolveConfig.js +11 -1
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +22 -7
- package/stubs/defaultConfig.stub.js +42 -16
- package/lib/lib/setupWatchingContext.js +0 -284
- package/src/lib/setupWatchingContext.js +0 -304
|
@@ -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/color.js
CHANGED
|
@@ -15,7 +15,8 @@ let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i;
|
|
|
15
15
|
let VALUE = `(?:\\d+|\\d*\\.\\d+)%?`;
|
|
16
16
|
let SEP = `(?:\\s*,\\s*|\\s+)`;
|
|
17
17
|
let ALPHA_SEP = `\\s*[,/]\\s*`;
|
|
18
|
-
let
|
|
18
|
+
let RGB = new RegExp(`^rgba?\\(\\s*(${VALUE})${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`);
|
|
19
|
+
let HSL = new RegExp(`^hsla?\\(\\s*((?:${VALUE})(?:deg|rad|grad|turn)?)${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`);
|
|
19
20
|
function parseColor(value) {
|
|
20
21
|
if (typeof value !== 'string') {
|
|
21
22
|
return null;
|
|
@@ -62,18 +63,32 @@ function parseColor(value) {
|
|
|
62
63
|
alpha: hex[4] ? (parseInt(hex[4], 16) / 255).toString() : undefined
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
|
-
let
|
|
66
|
-
if (
|
|
66
|
+
let rgbMatch = value.match(RGB);
|
|
67
|
+
if (rgbMatch !== null) {
|
|
67
68
|
var ref, ref1;
|
|
68
69
|
return {
|
|
69
|
-
mode:
|
|
70
|
+
mode: 'rgb',
|
|
71
|
+
color: [
|
|
72
|
+
rgbMatch[1],
|
|
73
|
+
rgbMatch[2],
|
|
74
|
+
rgbMatch[3]
|
|
75
|
+
].map((v)=>v.toString()
|
|
76
|
+
),
|
|
77
|
+
alpha: (ref = rgbMatch[4]) === null || ref === void 0 ? void 0 : (ref1 = ref.toString) === null || ref1 === void 0 ? void 0 : ref1.call(ref)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
let hslMatch = value.match(HSL);
|
|
81
|
+
if (hslMatch !== null) {
|
|
82
|
+
var ref2, ref3;
|
|
83
|
+
return {
|
|
84
|
+
mode: 'hsl',
|
|
70
85
|
color: [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
hslMatch[1],
|
|
87
|
+
hslMatch[2],
|
|
88
|
+
hslMatch[3]
|
|
74
89
|
].map((v)=>v.toString()
|
|
75
90
|
),
|
|
76
|
-
alpha: (
|
|
91
|
+
alpha: (ref2 = hslMatch[4]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.toString) === null || ref3 === void 0 ? void 0 : ref3.call(ref2)
|
|
77
92
|
};
|
|
78
93
|
}
|
|
79
94
|
return null;
|
package/lib/util/createPlugin.js
CHANGED
|
@@ -9,8 +9,7 @@ function createPlugin(plugin, config) {
|
|
|
9
9
|
config
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
createPlugin.withOptions = function(pluginFunction, configFunction = ()=>({
|
|
13
|
-
})
|
|
12
|
+
createPlugin.withOptions = function(pluginFunction, configFunction = ()=>({})
|
|
14
13
|
) {
|
|
15
14
|
const optionsFunction = function(options) {
|
|
16
15
|
return {
|
|
@@ -16,8 +16,7 @@ function createUtilityPlugin(themeKey, utilityVariations = [
|
|
|
16
16
|
themeKey
|
|
17
17
|
]
|
|
18
18
|
]
|
|
19
|
-
], { filterDefault =false , ...options } = {
|
|
20
|
-
}) {
|
|
19
|
+
], { filterDefault =false , ...options } = {}) {
|
|
21
20
|
let transformValue = (0, _transformThemeValue).default(themeKey);
|
|
22
21
|
return function({ matchUtilities , theme }) {
|
|
23
22
|
for (let utilityVariation of utilityVariations){
|
|
@@ -25,8 +24,8 @@ function createUtilityPlugin(themeKey, utilityVariations = [
|
|
|
25
24
|
utilityVariation
|
|
26
25
|
];
|
|
27
26
|
var ref;
|
|
28
|
-
matchUtilities(group.reduce((
|
|
29
|
-
return Object.assign(
|
|
27
|
+
matchUtilities(group.reduce((obj1, [classPrefix, properties])=>{
|
|
28
|
+
return Object.assign(obj1, {
|
|
30
29
|
[classPrefix]: (value)=>{
|
|
31
30
|
return properties.reduce((obj, name)=>{
|
|
32
31
|
if (Array.isArray(name)) {
|
|
@@ -37,15 +36,12 @@ function createUtilityPlugin(themeKey, utilityVariations = [
|
|
|
37
36
|
return Object.assign(obj, {
|
|
38
37
|
[name]: transformValue(value)
|
|
39
38
|
});
|
|
40
|
-
}, {
|
|
41
|
-
});
|
|
39
|
+
}, {});
|
|
42
40
|
}
|
|
43
41
|
});
|
|
44
|
-
}, {
|
|
45
|
-
}), {
|
|
42
|
+
}, {}), {
|
|
46
43
|
...options,
|
|
47
|
-
values: filterDefault ? Object.fromEntries(Object.entries((ref = theme(themeKey)) !== null && ref !== void 0 ? ref : {
|
|
48
|
-
}).filter(([modifier])=>modifier !== 'DEFAULT'
|
|
44
|
+
values: filterDefault ? Object.fromEntries(Object.entries((ref = theme(themeKey)) !== null && ref !== void 0 ? ref : {}).filter(([modifier])=>modifier !== 'DEFAULT'
|
|
49
45
|
)) : theme(themeKey)
|
|
50
46
|
});
|
|
51
47
|
}
|
package/lib/util/dataTypes.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.number = number;
|
|
|
8
8
|
exports.percentage = percentage;
|
|
9
9
|
exports.length = length;
|
|
10
10
|
exports.lineWidth = lineWidth;
|
|
11
|
+
exports.shadow = shadow;
|
|
11
12
|
exports.color = color;
|
|
12
13
|
exports.image = image;
|
|
13
14
|
exports.gradient = gradient;
|
|
@@ -17,19 +18,35 @@ exports.genericName = genericName;
|
|
|
17
18
|
exports.absoluteSize = absoluteSize;
|
|
18
19
|
exports.relativeSize = relativeSize;
|
|
19
20
|
var _color = require("./color");
|
|
21
|
+
var _parseBoxShadowValue = require("./parseBoxShadowValue");
|
|
22
|
+
let cssFunctions = [
|
|
23
|
+
'min',
|
|
24
|
+
'max',
|
|
25
|
+
'clamp',
|
|
26
|
+
'calc'
|
|
27
|
+
];
|
|
20
28
|
// Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
|
|
21
29
|
let COMMA = /,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
|
|
22
30
|
;
|
|
23
31
|
let UNDERSCORE = /_(?![^(]*\))/g // Underscore separator that is not located between brackets. E.g.: `rgba(255,_255,_255)_black` these don't count.
|
|
24
32
|
;
|
|
25
|
-
function normalize(value) {
|
|
33
|
+
function normalize(value, isRoot = true) {
|
|
34
|
+
// Keep raw strings if it starts with `url(`
|
|
35
|
+
if (value.includes('url(')) {
|
|
36
|
+
return value.split(/(url\(.*?\))/g).filter(Boolean).map((part)=>{
|
|
37
|
+
if (/^url\(.*?\)$/.test(part)) {
|
|
38
|
+
return part;
|
|
39
|
+
}
|
|
40
|
+
return normalize(part, false);
|
|
41
|
+
}).join('');
|
|
42
|
+
}
|
|
26
43
|
// Convert `_` to ` `, except for escaped underscores `\_`
|
|
27
44
|
value = value.replace(/([^\\])_+/g, (fullMatch, characterBefore)=>characterBefore + ' '.repeat(fullMatch.length - 1)
|
|
28
45
|
).replace(/^_/g, ' ').replace(/\\_/g, '_');
|
|
29
46
|
// Remove leftover whitespace
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
if (isRoot) {
|
|
48
|
+
value = value.trim();
|
|
49
|
+
}
|
|
33
50
|
// Add spaces around operators inside calc() that do not follow an operator
|
|
34
51
|
// or '('.
|
|
35
52
|
return value.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ');
|
|
@@ -38,10 +55,12 @@ function url(value) {
|
|
|
38
55
|
return value.startsWith('url(');
|
|
39
56
|
}
|
|
40
57
|
function number(value) {
|
|
41
|
-
return !isNaN(Number(value))
|
|
58
|
+
return !isNaN(Number(value)) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?`).test(value)
|
|
59
|
+
);
|
|
42
60
|
}
|
|
43
61
|
function percentage(value) {
|
|
44
|
-
return /%$/g.test(value) ||
|
|
62
|
+
return /%$/g.test(value) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?%`).test(value)
|
|
63
|
+
);
|
|
45
64
|
}
|
|
46
65
|
let lengthUnits = [
|
|
47
66
|
'cm',
|
|
@@ -63,7 +82,10 @@ let lengthUnits = [
|
|
|
63
82
|
];
|
|
64
83
|
let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`;
|
|
65
84
|
function length(value) {
|
|
66
|
-
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
|
+
});
|
|
67
89
|
}
|
|
68
90
|
let lineWidths = new Set([
|
|
69
91
|
'thin',
|
|
@@ -73,6 +95,15 @@ let lineWidths = new Set([
|
|
|
73
95
|
function lineWidth(value) {
|
|
74
96
|
return lineWidths.has(value);
|
|
75
97
|
}
|
|
98
|
+
function shadow(value) {
|
|
99
|
+
let parsedShadows = (0, _parseBoxShadowValue).parseBoxShadowValue(normalize(value));
|
|
100
|
+
for (let parsedShadow of parsedShadows){
|
|
101
|
+
if (!parsedShadow.valid) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
76
107
|
function color(value) {
|
|
77
108
|
let colors = 0;
|
|
78
109
|
let result = value.split(UNDERSCORE).every((part)=>{
|
package/lib/util/defaults.js
CHANGED
|
@@ -11,6 +11,12 @@ function defaults(target, ...sources) {
|
|
|
11
11
|
target[k] = source[k];
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
for (let k1 of Object.getOwnPropertySymbols(source)){
|
|
15
|
+
var ref1;
|
|
16
|
+
if (!(target === null || target === void 0 ? void 0 : (ref1 = target.hasOwnProperty) === null || ref1 === void 0 ? void 0 : ref1.call(target, k1))) {
|
|
17
|
+
target[k1] = source[k1];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
return target;
|
|
16
22
|
}
|
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = void 0;
|
|
6
|
-
const flattenColorPalette = (colors)=>Object.assign({
|
|
7
|
-
}, ...Object.entries(colors !== null && colors !== void 0 ? colors : {
|
|
8
|
-
}).flatMap(([color, values])=>typeof values == 'object' ? Object.entries(flattenColorPalette(values)).map(([number, hex])=>({
|
|
6
|
+
const flattenColorPalette = (colors)=>Object.assign({}, ...Object.entries(colors !== null && colors !== void 0 ? colors : {}).flatMap(([color, values])=>typeof values == 'object' ? Object.entries(flattenColorPalette(values)).map(([number, hex])=>({
|
|
9
7
|
[color + (number === 'DEFAULT' ? '' : `-${number}`)]: hex
|
|
10
8
|
})
|
|
11
9
|
) : [
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.formatVariantSelector = formatVariantSelector;
|
|
6
|
+
exports.finalizeSelector = finalizeSelector;
|
|
7
|
+
exports.selectorFunctions = void 0;
|
|
8
|
+
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
9
|
+
var _unesc = _interopRequireDefault(require("postcss-selector-parser/dist/util/unesc"));
|
|
10
|
+
var _escapeClassName = _interopRequireDefault(require("../util/escapeClassName"));
|
|
11
|
+
var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
|
|
12
|
+
function _interopRequireDefault(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
let MERGE = ':merge';
|
|
18
|
+
let PARENT = '&';
|
|
19
|
+
let selectorFunctions = new Set([
|
|
20
|
+
MERGE
|
|
21
|
+
]);
|
|
22
|
+
exports.selectorFunctions = selectorFunctions;
|
|
23
|
+
function formatVariantSelector(current, ...others) {
|
|
24
|
+
for (let other of others){
|
|
25
|
+
let incomingValue = resolveFunctionArgument(other, MERGE);
|
|
26
|
+
if (incomingValue !== null) {
|
|
27
|
+
let existingValue = resolveFunctionArgument(current, MERGE, incomingValue);
|
|
28
|
+
if (existingValue !== null) {
|
|
29
|
+
let existingTarget = `${MERGE}(${incomingValue})`;
|
|
30
|
+
let splitIdx = other.indexOf(existingTarget);
|
|
31
|
+
let addition = other.slice(splitIdx + existingTarget.length).split(' ')[0];
|
|
32
|
+
current = current.replace(existingTarget, existingTarget + addition);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
current = other.replace(PARENT, current);
|
|
37
|
+
}
|
|
38
|
+
return current;
|
|
39
|
+
}
|
|
40
|
+
function finalizeSelector(format, { selector: selector1 , candidate , context }) {
|
|
41
|
+
var ref, ref1;
|
|
42
|
+
var ref2;
|
|
43
|
+
let separator = (ref2 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref2 !== void 0 ? ref2 : ':';
|
|
44
|
+
// Split by the separator, but ignore the separator inside square brackets:
|
|
45
|
+
//
|
|
46
|
+
// E.g.: dark:lg:hover:[paint-order:markers]
|
|
47
|
+
// ┬ ┬ ┬ ┬
|
|
48
|
+
// │ │ │ ╰── We will not split here
|
|
49
|
+
// ╰──┴─────┴─────────────── We will split here
|
|
50
|
+
//
|
|
51
|
+
let splitter = new RegExp(`\\${separator}(?![^[]*\\])`);
|
|
52
|
+
let base = candidate.split(splitter).pop();
|
|
53
|
+
if (context === null || context === void 0 ? void 0 : (ref1 = context.tailwindConfig) === null || ref1 === void 0 ? void 0 : ref1.prefix) {
|
|
54
|
+
format = (0, _prefixSelector).default(context.tailwindConfig.prefix, format);
|
|
55
|
+
}
|
|
56
|
+
format = format.replace(PARENT, `.${(0, _escapeClassName).default(candidate)}`);
|
|
57
|
+
// Normalize escaped classes, e.g.:
|
|
58
|
+
//
|
|
59
|
+
// The idea would be to replace the escaped `base` in the selector with the
|
|
60
|
+
// `format`. However, in css you can escape the same selector in a few
|
|
61
|
+
// different ways. This would result in different strings and therefore we
|
|
62
|
+
// can't replace it properly.
|
|
63
|
+
//
|
|
64
|
+
// base: bg-[rgb(255,0,0)]
|
|
65
|
+
// base in selector: bg-\\[rgb\\(255\\,0\\,0\\)\\]
|
|
66
|
+
// escaped base: bg-\\[rgb\\(255\\2c 0\\2c 0\\)\\]
|
|
67
|
+
//
|
|
68
|
+
selector1 = (0, _postcssSelectorParser).default((selectors)=>{
|
|
69
|
+
return selectors.walkClasses((node)=>{
|
|
70
|
+
if (node.raws && node.value.includes(base)) {
|
|
71
|
+
node.raws.value = (0, _escapeClassName).default((0, _unesc).default(node.raws.value));
|
|
72
|
+
}
|
|
73
|
+
return node;
|
|
74
|
+
});
|
|
75
|
+
}).processSync(selector1);
|
|
76
|
+
// We can safely replace the escaped base now, since the `base` section is
|
|
77
|
+
// now in a normalized escaped value.
|
|
78
|
+
selector1 = selector1.replace(`.${(0, _escapeClassName).default(base)}`, format);
|
|
79
|
+
// Remove unnecessary pseudo selectors that we used as placeholders
|
|
80
|
+
return (0, _postcssSelectorParser).default((selectors)=>{
|
|
81
|
+
return selectors.map((selector2)=>{
|
|
82
|
+
selector2.walkPseudos((p)=>{
|
|
83
|
+
if (selectorFunctions.has(p.value)) {
|
|
84
|
+
p.replaceWith(p.nodes);
|
|
85
|
+
}
|
|
86
|
+
return p;
|
|
87
|
+
});
|
|
88
|
+
// This will make sure to move pseudo's to the correct spot (the end for
|
|
89
|
+
// pseudo elements) because otherwise the selector will never work
|
|
90
|
+
// anyway.
|
|
91
|
+
//
|
|
92
|
+
// E.g.:
|
|
93
|
+
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
94
|
+
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
95
|
+
//
|
|
96
|
+
// `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
|
|
97
|
+
function collectPseudoElements(selector) {
|
|
98
|
+
let nodes = [];
|
|
99
|
+
for (let node of selector.nodes){
|
|
100
|
+
if (isPseudoElement(node)) {
|
|
101
|
+
nodes.push(node);
|
|
102
|
+
selector.removeChild(node);
|
|
103
|
+
}
|
|
104
|
+
if (node === null || node === void 0 ? void 0 : node.nodes) {
|
|
105
|
+
nodes.push(...collectPseudoElements(node));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return nodes;
|
|
109
|
+
}
|
|
110
|
+
let pseudoElements = collectPseudoElements(selector2);
|
|
111
|
+
if (pseudoElements.length > 0) {
|
|
112
|
+
selector2.nodes.push(pseudoElements.sort(sortSelector));
|
|
113
|
+
}
|
|
114
|
+
return selector2;
|
|
115
|
+
});
|
|
116
|
+
}).processSync(selector1);
|
|
117
|
+
}
|
|
118
|
+
// Note: As a rule, double colons (::) should be used instead of a single colon
|
|
119
|
+
// (:). This distinguishes pseudo-classes from pseudo-elements. However, since
|
|
120
|
+
// this distinction was not present in older versions of the W3C spec, most
|
|
121
|
+
// browsers support both syntaxes for the original pseudo-elements.
|
|
122
|
+
let pseudoElementsBC = [
|
|
123
|
+
':before',
|
|
124
|
+
':after',
|
|
125
|
+
':first-line',
|
|
126
|
+
':first-letter'
|
|
127
|
+
];
|
|
128
|
+
// These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
|
|
129
|
+
let pseudoElementExceptions = [
|
|
130
|
+
'::file-selector-button'
|
|
131
|
+
];
|
|
132
|
+
// This will make sure to move pseudo's to the correct spot (the end for
|
|
133
|
+
// pseudo elements) because otherwise the selector will never work
|
|
134
|
+
// anyway.
|
|
135
|
+
//
|
|
136
|
+
// E.g.:
|
|
137
|
+
// - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
|
|
138
|
+
// - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
|
|
139
|
+
//
|
|
140
|
+
// `::before:hover` doesn't work, which means that we can make it work
|
|
141
|
+
// for you by flipping the order.
|
|
142
|
+
function sortSelector(a, z) {
|
|
143
|
+
// Both nodes are non-pseudo's so we can safely ignore them and keep
|
|
144
|
+
// them in the same order.
|
|
145
|
+
if (a.type !== 'pseudo' && z.type !== 'pseudo') {
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
// If one of them is a combinator, we need to keep it in the same order
|
|
149
|
+
// because that means it will start a new "section" in the selector.
|
|
150
|
+
if (a.type === 'combinator' ^ z.type === 'combinator') {
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
// One of the items is a pseudo and the other one isn't. Let's move
|
|
154
|
+
// the pseudo to the right.
|
|
155
|
+
if (a.type === 'pseudo' ^ z.type === 'pseudo') {
|
|
156
|
+
return (a.type === 'pseudo') - (z.type === 'pseudo');
|
|
157
|
+
}
|
|
158
|
+
// Both are pseudo's, move the pseudo elements (except for
|
|
159
|
+
// ::file-selector-button) to the right.
|
|
160
|
+
return isPseudoElement(a) - isPseudoElement(z);
|
|
161
|
+
}
|
|
162
|
+
function isPseudoElement(node) {
|
|
163
|
+
if (node.type !== 'pseudo') return false;
|
|
164
|
+
if (pseudoElementExceptions.includes(node.value)) return false;
|
|
165
|
+
return node.value.startsWith('::') || pseudoElementsBC.includes(node.value);
|
|
166
|
+
}
|
|
167
|
+
function resolveFunctionArgument(haystack, needle, arg) {
|
|
168
|
+
let startIdx = haystack.indexOf(arg ? `${needle}(${arg})` : needle);
|
|
169
|
+
if (startIdx === -1) return null;
|
|
170
|
+
// Start inside the `(`
|
|
171
|
+
startIdx += needle.length + 1;
|
|
172
|
+
let target = '';
|
|
173
|
+
let count = 0;
|
|
174
|
+
for (let char of haystack.slice(startIdx)){
|
|
175
|
+
if (char !== '(' && char !== ')') {
|
|
176
|
+
target += char;
|
|
177
|
+
} else if (char === '(') {
|
|
178
|
+
target += char;
|
|
179
|
+
count++;
|
|
180
|
+
} else if (char === ')') {
|
|
181
|
+
if (--count < 0) break; // unbalanced
|
|
182
|
+
target += char;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return target;
|
|
186
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = isValidArbitraryValue;
|
|
6
|
+
let matchingBrackets = new Map([
|
|
7
|
+
[
|
|
8
|
+
'{',
|
|
9
|
+
'}'
|
|
10
|
+
],
|
|
11
|
+
[
|
|
12
|
+
'[',
|
|
13
|
+
']'
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
'(',
|
|
17
|
+
')'
|
|
18
|
+
],
|
|
19
|
+
]);
|
|
20
|
+
let inverseMatchingBrackets = new Map(Array.from(matchingBrackets.entries()).map(([k, v])=>[
|
|
21
|
+
v,
|
|
22
|
+
k
|
|
23
|
+
]
|
|
24
|
+
));
|
|
25
|
+
let quotes = new Set([
|
|
26
|
+
'"',
|
|
27
|
+
"'",
|
|
28
|
+
'`'
|
|
29
|
+
]);
|
|
30
|
+
function isValidArbitraryValue(value) {
|
|
31
|
+
let stack = [];
|
|
32
|
+
let inQuotes = false;
|
|
33
|
+
for(let i = 0; i < value.length; i++){
|
|
34
|
+
let char = value[i];
|
|
35
|
+
if (char === ':' && !inQuotes && stack.length === 0) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// Non-escaped quotes allow us to "allow" anything in between
|
|
39
|
+
if (quotes.has(char) && value[i - 1] !== '\\') {
|
|
40
|
+
inQuotes = !inQuotes;
|
|
41
|
+
}
|
|
42
|
+
if (inQuotes) continue;
|
|
43
|
+
if (value[i - 1] === '\\') continue; // Escaped
|
|
44
|
+
if (matchingBrackets.has(char)) {
|
|
45
|
+
stack.push(char);
|
|
46
|
+
} else if (inverseMatchingBrackets.has(char)) {
|
|
47
|
+
let inverse = inverseMatchingBrackets.get(char);
|
|
48
|
+
// Nothing to pop from, therefore it is unbalanced
|
|
49
|
+
if (stack.length <= 0) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
// Popped value must match the inverse value, otherwise it is unbalanced
|
|
53
|
+
if (stack.pop() !== inverse) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// If there is still something on the stack, it is also unbalanced
|
|
59
|
+
if (stack.length > 0) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
// All good, totally balanced!
|
|
63
|
+
return true;
|
|
64
|
+
}
|
package/lib/util/log.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
exports.dim = dim;
|
|
5
6
|
exports.default = void 0;
|
|
6
7
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
7
8
|
function _interopRequireDefault(obj) {
|
|
@@ -18,6 +19,9 @@ function log(chalk, messages, key) {
|
|
|
18
19
|
messages.forEach((message)=>console.warn(chalk, '-', message)
|
|
19
20
|
);
|
|
20
21
|
}
|
|
22
|
+
function dim(input) {
|
|
23
|
+
return _chalk.default.dim(input);
|
|
24
|
+
}
|
|
21
25
|
var _default = {
|
|
22
26
|
info (key, messages) {
|
|
23
27
|
log(_chalk.default.bold.cyan('info'), ...Array.isArray(key) ? [
|
package/lib/util/nameClass.js
CHANGED
|
@@ -3,11 +3,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.normalizeConfig = normalizeConfig;
|
|
6
|
-
var _log =
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
6
|
+
var _log = _interopRequireWildcard(require("./log"));
|
|
7
|
+
function _interopRequireWildcard(obj) {
|
|
8
|
+
if (obj && obj.__esModule) {
|
|
9
|
+
return obj;
|
|
10
|
+
} else {
|
|
11
|
+
var newObj = {};
|
|
12
|
+
if (obj != null) {
|
|
13
|
+
for(var key in obj){
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
15
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
16
|
+
if (desc.get || desc.set) {
|
|
17
|
+
Object.defineProperty(newObj, key, desc);
|
|
18
|
+
} else {
|
|
19
|
+
newObj[key] = obj[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
newObj.default = obj;
|
|
25
|
+
return newObj;
|
|
26
|
+
}
|
|
11
27
|
}
|
|
12
28
|
function normalizeConfig(config) {
|
|
13
29
|
// Quick structure validation
|
|
@@ -120,6 +136,17 @@ function normalizeConfig(config) {
|
|
|
120
136
|
if (Array.isArray(purge === null || purge === void 0 ? void 0 : (ref = purge.options) === null || ref === void 0 ? void 0 : ref.safelist)) return purge.options.safelist;
|
|
121
137
|
return [];
|
|
122
138
|
})();
|
|
139
|
+
// Normalize prefix option
|
|
140
|
+
if (typeof config.prefix === 'function') {
|
|
141
|
+
_log.default.warn('prefix-function', [
|
|
142
|
+
'As of Tailwind CSS v3.0, `prefix` cannot be a function.',
|
|
143
|
+
'Update `prefix` in your configuration to be a string to eliminate this warning.'
|
|
144
|
+
]);
|
|
145
|
+
config.prefix = '';
|
|
146
|
+
} else {
|
|
147
|
+
var _prefix;
|
|
148
|
+
config.prefix = (_prefix = config.prefix) !== null && _prefix !== void 0 ? _prefix : '';
|
|
149
|
+
}
|
|
123
150
|
// Normalize the `content`
|
|
124
151
|
config.content = {
|
|
125
152
|
files: (()=>{
|
|
@@ -140,21 +167,22 @@ function normalizeConfig(config) {
|
|
|
140
167
|
if ((ref4 = config.content) === null || ref4 === void 0 ? void 0 : (ref5 = ref4.extract) === null || ref5 === void 0 ? void 0 : ref5.DEFAULT) return config.content.extract.DEFAULT;
|
|
141
168
|
if ((ref6 = config.purge) === null || ref6 === void 0 ? void 0 : (ref7 = ref6.options) === null || ref7 === void 0 ? void 0 : ref7.extractors) return config.purge.options.extractors;
|
|
142
169
|
if ((ref8 = config.content) === null || ref8 === void 0 ? void 0 : (ref9 = ref8.options) === null || ref9 === void 0 ? void 0 : ref9.extractors) return config.content.options.extractors;
|
|
143
|
-
return {
|
|
144
|
-
};
|
|
170
|
+
return {};
|
|
145
171
|
})();
|
|
146
|
-
let extractors = {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if ((ref = config.purge) === null || ref === void 0 ? void 0 : (ref46 = ref.options) === null || ref46 === void 0 ? void 0 : ref46.defaultExtractor) {
|
|
172
|
+
let extractors = {};
|
|
173
|
+
let defaultExtractor = (()=>{
|
|
174
|
+
var ref, ref10, ref11, ref12;
|
|
175
|
+
if ((ref = config.purge) === null || ref === void 0 ? void 0 : (ref10 = ref.options) === null || ref10 === void 0 ? void 0 : ref10.defaultExtractor) {
|
|
151
176
|
return config.purge.options.defaultExtractor;
|
|
152
177
|
}
|
|
153
|
-
if ((
|
|
178
|
+
if ((ref11 = config.content) === null || ref11 === void 0 ? void 0 : (ref12 = ref11.options) === null || ref12 === void 0 ? void 0 : ref12.defaultExtractor) {
|
|
154
179
|
return config.content.options.defaultExtractor;
|
|
155
180
|
}
|
|
156
181
|
return undefined;
|
|
157
182
|
})();
|
|
183
|
+
if (defaultExtractor !== undefined) {
|
|
184
|
+
extractors.DEFAULT = defaultExtractor;
|
|
185
|
+
}
|
|
158
186
|
// Functions
|
|
159
187
|
if (typeof extract === 'function') {
|
|
160
188
|
extractors.DEFAULT = extract;
|
|
@@ -171,16 +199,14 @@ function normalizeConfig(config) {
|
|
|
171
199
|
})(),
|
|
172
200
|
transform: (()=>{
|
|
173
201
|
let transform = (()=>{
|
|
174
|
-
var ref,
|
|
202
|
+
var ref, ref13, ref14, ref15, ref16, ref17;
|
|
175
203
|
if ((ref = config.purge) === null || ref === void 0 ? void 0 : ref.transform) return config.purge.transform;
|
|
176
|
-
if ((
|
|
177
|
-
if ((
|
|
178
|
-
if ((
|
|
179
|
-
return {
|
|
180
|
-
};
|
|
204
|
+
if ((ref13 = config.content) === null || ref13 === void 0 ? void 0 : ref13.transform) return config.content.transform;
|
|
205
|
+
if ((ref14 = config.purge) === null || ref14 === void 0 ? void 0 : (ref15 = ref14.transform) === null || ref15 === void 0 ? void 0 : ref15.DEFAULT) return config.purge.transform.DEFAULT;
|
|
206
|
+
if ((ref16 = config.content) === null || ref16 === void 0 ? void 0 : (ref17 = ref16.transform) === null || ref17 === void 0 ? void 0 : ref17.DEFAULT) return config.content.transform.DEFAULT;
|
|
207
|
+
return {};
|
|
181
208
|
})();
|
|
182
|
-
let transformers = {
|
|
183
|
-
};
|
|
209
|
+
let transformers = {};
|
|
184
210
|
if (typeof transform === 'function') {
|
|
185
211
|
transformers.DEFAULT = transform;
|
|
186
212
|
}
|
|
@@ -190,5 +216,21 @@ function normalizeConfig(config) {
|
|
|
190
216
|
return transformers;
|
|
191
217
|
})()
|
|
192
218
|
};
|
|
219
|
+
// Validate globs to prevent bogus globs.
|
|
220
|
+
// E.g.: `./src/*.{html}` is invalid, the `{html}` should just be `html`
|
|
221
|
+
for (let file of config.content.files){
|
|
222
|
+
if (typeof file === 'string' && /{([^,]*?)}/g.test(file)) {
|
|
223
|
+
_log.default.warn('invalid-glob-braces', [
|
|
224
|
+
`The glob pattern ${(0, _log).dim(file)} in your config is invalid.`,
|
|
225
|
+
` Update it to ${(0, _log).dim(file.replace(/{([^,]*?)}/g, '$1'))} to silence this warning.`
|
|
226
|
+
]);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (config.content.files.length === 0) {
|
|
231
|
+
_log.default.warn('content-problems', [
|
|
232
|
+
'The `content` key is missing or empty. Please populate the content key as Tailwind generates utilities on-demand based on the files that use them. For more information see the documentation: https://tailwindcss.com/docs/content-configuration',
|
|
233
|
+
]);
|
|
234
|
+
}
|
|
193
235
|
return config;
|
|
194
236
|
}
|