tailwindcss 0.0.0-insiders.f4635e0 → 0.0.0-insiders.f6eeed3
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 +360 -1
- package/LICENSE +1 -2
- package/README.md +8 -4
- package/colors.d.ts +3 -0
- package/colors.js +2 -304
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -4
- package/defaultTheme.d.ts +3 -0
- package/defaultTheme.js +2 -4
- package/lib/cli-peer-dependencies.js +5 -10
- package/lib/cli.js +702 -706
- package/lib/constants.js +23 -23
- package/lib/corePluginList.js +175 -4
- package/lib/corePlugins.js +3601 -2950
- package/lib/css/preflight.css +18 -5
- package/lib/featureFlags.js +44 -45
- package/lib/index.js +35 -25
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +47 -36
- package/lib/lib/collapseDuplicateDeclarations.js +80 -0
- package/lib/lib/defaultExtractor.js +44 -0
- package/lib/lib/detectNesting.js +29 -16
- package/lib/lib/evaluateTailwindFunctions.js +134 -155
- package/lib/lib/expandApplyAtRules.js +391 -203
- package/lib/lib/expandTailwindAtRules.js +238 -236
- package/lib/lib/generateRules.js +594 -310
- package/lib/lib/getModuleDependencies.js +38 -43
- package/lib/lib/normalizeTailwindDirectives.js +74 -58
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +129 -91
- package/lib/lib/setupContextUtils.js +806 -666
- package/lib/lib/setupTrackingContext.js +145 -164
- package/lib/lib/sharedState.js +40 -17
- package/lib/lib/substituteScreenAtRules.js +22 -26
- package/{nesting → lib/postcss-plugins/nesting}/README.md +0 -0
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +45 -46
- package/lib/public/colors.js +329 -0
- package/lib/public/create-plugin.js +13 -0
- package/lib/public/default-config.js +14 -0
- package/lib/public/default-theme.js +14 -0
- package/lib/public/resolve-config.js +19 -0
- package/lib/util/bigSign.js +3 -5
- package/lib/util/buildMediaQuery.js +15 -31
- package/lib/util/cloneDeep.js +14 -13
- package/lib/util/cloneNodes.js +21 -14
- package/lib/util/color.js +89 -63
- package/lib/util/configurePlugins.js +13 -14
- package/lib/util/createPlugin.js +20 -24
- package/lib/util/createUtilityPlugin.js +43 -45
- package/lib/util/dataTypes.js +235 -0
- package/lib/util/defaults.js +16 -14
- package/lib/util/escapeClassName.js +12 -14
- package/lib/util/escapeCommas.js +3 -5
- package/lib/util/flattenColorPalette.js +12 -10
- package/lib/util/formatVariantSelector.js +186 -0
- package/lib/util/getAllConfigs.js +23 -16
- package/lib/util/hashConfig.js +10 -10
- package/lib/util/isKeyframeRule.js +3 -5
- package/lib/util/isPlainObject.js +7 -10
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +45 -32
- package/lib/util/nameClass.js +22 -27
- package/lib/util/negateValue.js +14 -15
- package/lib/util/normalizeConfig.js +240 -0
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseAnimationValue.js +83 -54
- package/lib/util/parseBoxShadowValue.js +117 -0
- package/lib/util/parseDependency.js +51 -62
- package/lib/util/parseObjectStyles.js +23 -20
- package/lib/util/pluginUtils.js +146 -285
- package/lib/util/prefixSelector.js +15 -18
- package/lib/util/resolveConfig.js +218 -252
- package/lib/util/resolveConfigPath.js +39 -47
- package/lib/util/responsive.js +12 -11
- package/lib/util/tap.js +4 -6
- package/lib/util/toColorValue.js +3 -5
- package/lib/util/toPath.js +9 -6
- package/lib/util/transformThemeValue.js +53 -26
- package/lib/util/withAlphaVariable.js +59 -57
- package/nesting/index.js +2 -12
- package/package.json +48 -60
- package/peers/index.js +72849 -84292
- package/plugin.d.ts +6 -0
- package/plugin.js +1 -2
- package/resolveConfig.js +2 -7
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +52 -0
- package/src/cli.js +115 -36
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +2147 -1968
- package/src/css/preflight.css +18 -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 +16 -1
- 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 +285 -56
- package/src/lib/expandTailwindAtRules.js +87 -57
- package/src/lib/generateRules.js +364 -41
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/resolveDefaultsAtRules.js +81 -40
- package/src/lib/setupContextUtils.js +374 -201
- package/src/lib/setupTrackingContext.js +17 -16
- 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 +18 -3
- package/src/public/colors.js +300 -0
- package/src/public/create-plugin.js +2 -0
- package/src/public/default-config.js +4 -0
- package/src/public/default-theme.js +4 -0
- package/src/public/resolve-config.js +7 -0
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +25 -10
- package/src/util/createUtilityPlugin.js +2 -11
- package/src/util/dataTypes.js +250 -0
- 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/parseAnimationValue.js +7 -1
- package/src/util/parseBoxShadowValue.js +119 -0
- package/src/util/parseDependency.js +4 -0
- package/src/util/pluginUtils.js +101 -204
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +53 -66
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +22 -7
- package/src/util/withAlphaVariable.js +13 -8
- package/stubs/defaultConfig.stub.js +168 -99
- 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 -331
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -307
package/lib/css/preflight.css
CHANGED
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
box-sizing: border-box; /* 1 */
|
|
10
10
|
border-width: 0; /* 2 */
|
|
11
11
|
border-style: solid; /* 2 */
|
|
12
|
-
border-color: currentColor; /* 2 */
|
|
12
|
+
border-color: theme('borderColor.DEFAULT', currentColor); /* 2 */
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
::before,
|
|
16
|
+
::after {
|
|
17
|
+
--tw-content: '';
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
/*
|
|
@@ -53,7 +58,7 @@ hr {
|
|
|
53
58
|
Add the correct text decoration in Chrome, Edge, and Safari.
|
|
54
59
|
*/
|
|
55
60
|
|
|
56
|
-
abbr[title] {
|
|
61
|
+
abbr:where([title]) {
|
|
57
62
|
text-decoration: underline dotted;
|
|
58
63
|
}
|
|
59
64
|
|
|
@@ -139,7 +144,7 @@ sup {
|
|
|
139
144
|
table {
|
|
140
145
|
text-indent: 0; /* 1 */
|
|
141
146
|
border-color: inherit; /* 2 */
|
|
142
|
-
border-collapse: collapse;
|
|
147
|
+
border-collapse: collapse; /* 3 */
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
/*
|
|
@@ -283,7 +288,8 @@ legend {
|
|
|
283
288
|
}
|
|
284
289
|
|
|
285
290
|
ol,
|
|
286
|
-
ul
|
|
291
|
+
ul,
|
|
292
|
+
menu {
|
|
287
293
|
list-style: none;
|
|
288
294
|
margin: 0;
|
|
289
295
|
padding: 0;
|
|
@@ -304,7 +310,7 @@ textarea {
|
|
|
304
310
|
|
|
305
311
|
input::placeholder,
|
|
306
312
|
textarea::placeholder {
|
|
307
|
-
opacity: 1;
|
|
313
|
+
opacity: 1; /* 1 */
|
|
308
314
|
color: theme('colors.gray.400', #9ca3af); /* 2 */
|
|
309
315
|
}
|
|
310
316
|
|
|
@@ -317,6 +323,13 @@ button,
|
|
|
317
323
|
cursor: pointer;
|
|
318
324
|
}
|
|
319
325
|
|
|
326
|
+
/*
|
|
327
|
+
Make sure disabled buttons don't get the pointer cursor.
|
|
328
|
+
*/
|
|
329
|
+
:disabled {
|
|
330
|
+
cursor: default;
|
|
331
|
+
}
|
|
332
|
+
|
|
320
333
|
/*
|
|
321
334
|
1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
|
|
322
335
|
2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
|
package/lib/featureFlags.js
CHANGED
|
@@ -1,60 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
5
|
exports.flagEnabled = flagEnabled;
|
|
7
6
|
exports.issueFlagNotices = issueFlagNotices;
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
8
|
+
var _picocolors = _interopRequireDefault(require("picocolors"));
|
|
12
9
|
var _log = _interopRequireDefault(require("./util/log"));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
function _interopRequireDefault(obj) {
|
|
11
|
+
return obj && obj.__esModule ? obj : {
|
|
12
|
+
default: obj
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
let defaults = {
|
|
16
|
+
optimizeUniversalDefaults: false
|
|
17
|
+
};
|
|
18
|
+
let featureFlags = {
|
|
19
|
+
future: [],
|
|
20
|
+
experimental: [
|
|
21
|
+
"optimizeUniversalDefaults"
|
|
22
|
+
]
|
|
19
23
|
};
|
|
20
|
-
|
|
21
24
|
function flagEnabled(config, flag) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return false;
|
|
25
|
+
if (featureFlags.future.includes(flag)) {
|
|
26
|
+
var ref;
|
|
27
|
+
var ref1, ref2;
|
|
28
|
+
return config.future === "all" || ((ref2 = (ref1 = config === null || config === void 0 ? void 0 : (ref = config.future) === null || ref === void 0 ? void 0 : ref[flag]) !== null && ref1 !== void 0 ? ref1 : defaults[flag]) !== null && ref2 !== void 0 ? ref2 : false);
|
|
29
|
+
}
|
|
30
|
+
if (featureFlags.experimental.includes(flag)) {
|
|
31
|
+
var ref3;
|
|
32
|
+
var ref4, ref5;
|
|
33
|
+
return config.experimental === "all" || ((ref5 = (ref4 = config === null || config === void 0 ? void 0 : (ref3 = config.experimental) === null || ref3 === void 0 ? void 0 : ref3[flag]) !== null && ref4 !== void 0 ? ref4 : defaults[flag]) !== null && ref5 !== void 0 ? ref5 : false);
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
35
36
|
}
|
|
36
|
-
|
|
37
37
|
function experimentalFlagsEnabled(config) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return Object.keys((_config$experimental2 = config === null || config === void 0 ? void 0 : config.experimental) !== null && _config$experimental2 !== void 0 ? _config$experimental2 : {}).filter(flag => featureFlags.experimental.includes(flag) && config.experimental[flag]);
|
|
38
|
+
if (config.experimental === "all") {
|
|
39
|
+
return featureFlags.experimental;
|
|
40
|
+
}
|
|
41
|
+
var ref;
|
|
42
|
+
return Object.keys((ref = config === null || config === void 0 ? void 0 : config.experimental) !== null && ref !== void 0 ? ref : {}).filter((flag)=>featureFlags.experimental.includes(flag) && config.experimental[flag]
|
|
43
|
+
);
|
|
45
44
|
}
|
|
46
|
-
|
|
47
45
|
function issueFlagNotices(config) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
if (process.env.JEST_WORKER_ID !== undefined) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (experimentalFlagsEnabled(config).length > 0) {
|
|
50
|
+
let changes = experimentalFlagsEnabled(config).map((s)=>_picocolors.default.yellow(s)
|
|
51
|
+
).join(", ");
|
|
52
|
+
_log.default.warn("experimental-flags-enabled", [
|
|
53
|
+
`You have enabled experimental features: ${changes}`,
|
|
54
|
+
"Experimental features in Tailwind CSS are not covered by semver, may introduce breaking changes, and can change at any time.",
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
57
|
}
|
|
58
|
-
|
|
59
58
|
var _default = featureFlags;
|
|
60
|
-
exports.default = _default;
|
|
59
|
+
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -1,31 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
var _setupTrackingContext = _interopRequireDefault(require("./lib/setupTrackingContext"));
|
|
4
|
-
|
|
5
|
-
var _setupWatchingContext = _interopRequireDefault(require("./lib/setupWatchingContext"));
|
|
6
|
-
|
|
7
3
|
var _processTailwindFeatures = _interopRequireDefault(require("./processTailwindFeatures"));
|
|
8
|
-
|
|
9
4
|
var _sharedState = require("./lib/sharedState");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
function _interopRequireDefault(obj) {
|
|
6
|
+
return obj && obj.__esModule ? obj : {
|
|
7
|
+
default: obj
|
|
8
|
+
};
|
|
9
|
+
}
|
|
13
10
|
module.exports = function tailwindcss(configOrPath) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
return {
|
|
12
|
+
postcssPlugin: "tailwindcss",
|
|
13
|
+
plugins: [
|
|
14
|
+
_sharedState.env.DEBUG && function(root) {
|
|
15
|
+
console.log("\n");
|
|
16
|
+
console.time("JIT TOTAL");
|
|
17
|
+
return root;
|
|
18
|
+
},
|
|
19
|
+
function(root, result) {
|
|
20
|
+
let context = (0, _setupTrackingContext).default(configOrPath);
|
|
21
|
+
if (root.type === "document") {
|
|
22
|
+
let roots = root.nodes.filter((node)=>node.type === "root"
|
|
23
|
+
);
|
|
24
|
+
for (const root1 of roots){
|
|
25
|
+
if (root1.type === "root") {
|
|
26
|
+
(0, _processTailwindFeatures).default(context)(root1, result);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
(0, _processTailwindFeatures).default(context)(root, result);
|
|
32
|
+
},
|
|
33
|
+
_sharedState.env.DEBUG && function(root) {
|
|
34
|
+
console.timeEnd("JIT TOTAL");
|
|
35
|
+
console.log("\n");
|
|
36
|
+
return root;
|
|
37
|
+
},
|
|
38
|
+
].filter(Boolean)
|
|
39
|
+
};
|
|
29
40
|
};
|
|
30
|
-
|
|
31
|
-
module.exports.postcss = true;
|
|
41
|
+
module.exports.postcss = true;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.hasContentChanged = hasContentChanged;
|
|
6
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
7
|
+
var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function _interopRequireWildcard(obj) {
|
|
14
|
+
if (obj && obj.__esModule) {
|
|
15
|
+
return obj;
|
|
16
|
+
} else {
|
|
17
|
+
var newObj = {};
|
|
18
|
+
if (obj != null) {
|
|
19
|
+
for(var key in obj){
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
21
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
22
|
+
if (desc.get || desc.set) {
|
|
23
|
+
Object.defineProperty(newObj, key, desc);
|
|
24
|
+
} else {
|
|
25
|
+
newObj[key] = obj[key];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
newObj.default = obj;
|
|
31
|
+
return newObj;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Calculate the hash of a string.
|
|
36
|
+
*
|
|
37
|
+
* This doesn't need to be cryptographically secure or
|
|
38
|
+
* anything like that since it's used only to detect
|
|
39
|
+
* when the CSS changes to invalidate the context.
|
|
40
|
+
*
|
|
41
|
+
* This is wrapped in a try/catch because it's really dependent
|
|
42
|
+
* on how Node itself is build and the environment and OpenSSL
|
|
43
|
+
* version / build that is installed on the user's machine.
|
|
44
|
+
*
|
|
45
|
+
* Based on the environment this can just outright fail.
|
|
46
|
+
*
|
|
47
|
+
* See https://github.com/nodejs/node/issues/40455
|
|
48
|
+
*
|
|
49
|
+
* @param {string} str
|
|
50
|
+
*/ function getHash(str) {
|
|
51
|
+
try {
|
|
52
|
+
return _crypto.default.createHash("md5").update(str, "utf-8").digest("binary");
|
|
53
|
+
} catch (err) {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function hasContentChanged(sourcePath, root) {
|
|
58
|
+
let css = root.toString();
|
|
59
|
+
// We only care about files with @tailwind directives
|
|
60
|
+
// Other files use an existing context
|
|
61
|
+
if (!css.includes("@tailwind")) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
let existingHash = sharedState.sourceHashMap.get(sourcePath);
|
|
65
|
+
let rootHash = getHash(css);
|
|
66
|
+
let didChange = existingHash !== rootHash;
|
|
67
|
+
sharedState.sourceHashMap.set(sourcePath, rootHash);
|
|
68
|
+
return didChange;
|
|
69
|
+
}
|
|
@@ -1,43 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
5
|
exports.default = collapseAdjacentRules;
|
|
6
|
+
function collapseAdjacentRules() {
|
|
7
|
+
function collapseRulesIn(root) {
|
|
8
|
+
let currentRule = null;
|
|
9
|
+
root.each((node)=>{
|
|
10
|
+
if (!types.has(node.type)) {
|
|
11
|
+
currentRule = null;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (currentRule === null) {
|
|
15
|
+
currentRule = node;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
let properties = comparisonMap[node.type];
|
|
19
|
+
var _property, _property1;
|
|
20
|
+
if (node.type === "atrule" && node.name === "font-face") {
|
|
21
|
+
currentRule = node;
|
|
22
|
+
} else if (properties.every((property)=>((_property = node[property]) !== null && _property !== void 0 ? _property : "").replace(/\s+/g, " ") === ((_property1 = currentRule[property]) !== null && _property1 !== void 0 ? _property1 : "").replace(/\s+/g, " ")
|
|
23
|
+
)) {
|
|
24
|
+
currentRule.append(node.nodes);
|
|
25
|
+
node.remove();
|
|
26
|
+
} else {
|
|
27
|
+
currentRule = node;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
// After we've collapsed adjacent rules & at-rules, we need to collapse
|
|
31
|
+
// adjacent rules & at-rules that are children of at-rules.
|
|
32
|
+
// We do not care about nesting rules because Tailwind CSS
|
|
33
|
+
// explicitly does not handle rule nesting on its own as
|
|
34
|
+
// the user is expected to use a nesting plugin
|
|
35
|
+
root.each((node)=>{
|
|
36
|
+
if (node.type === "atrule") {
|
|
37
|
+
collapseRulesIn(node);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return (root)=>{
|
|
42
|
+
collapseRulesIn(root);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
7
45
|
let comparisonMap = {
|
|
8
|
-
|
|
9
|
-
|
|
46
|
+
atrule: [
|
|
47
|
+
"name",
|
|
48
|
+
"params"
|
|
49
|
+
],
|
|
50
|
+
rule: [
|
|
51
|
+
"selector"
|
|
52
|
+
]
|
|
10
53
|
};
|
|
11
54
|
let types = new Set(Object.keys(comparisonMap));
|
|
12
|
-
|
|
13
|
-
function collapseAdjacentRules() {
|
|
14
|
-
return root => {
|
|
15
|
-
let currentRule = null;
|
|
16
|
-
root.each(node => {
|
|
17
|
-
if (!types.has(node.type)) {
|
|
18
|
-
currentRule = null;
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (currentRule === null) {
|
|
23
|
-
currentRule = node;
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let properties = comparisonMap[node.type];
|
|
28
|
-
|
|
29
|
-
if (node.type === 'atrule' && node.name === 'font-face') {
|
|
30
|
-
currentRule = node;
|
|
31
|
-
} else if (properties.every(property => {
|
|
32
|
-
var _node$property, _currentRule$property;
|
|
33
|
-
|
|
34
|
-
return ((_node$property = node[property]) !== null && _node$property !== void 0 ? _node$property : '').replace(/\s+/g, ' ') === ((_currentRule$property = currentRule[property]) !== null && _currentRule$property !== void 0 ? _currentRule$property : '').replace(/\s+/g, ' ');
|
|
35
|
-
})) {
|
|
36
|
-
currentRule.append(node.nodes);
|
|
37
|
-
node.remove();
|
|
38
|
-
} else {
|
|
39
|
-
currentRule = node;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = collapseDuplicateDeclarations;
|
|
6
|
+
function collapseDuplicateDeclarations() {
|
|
7
|
+
return (root)=>{
|
|
8
|
+
root.walkRules((node)=>{
|
|
9
|
+
let seen = new Map();
|
|
10
|
+
let droppable = new Set([]);
|
|
11
|
+
let byProperty = new Map();
|
|
12
|
+
node.walkDecls((decl)=>{
|
|
13
|
+
// This could happen if we have nested selectors. In that case the
|
|
14
|
+
// parent will loop over all its declarations but also the declarations
|
|
15
|
+
// of nested rules. With this we ensure that we are shallowly checking
|
|
16
|
+
// declarations.
|
|
17
|
+
if (decl.parent !== node) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (seen.has(decl.prop)) {
|
|
21
|
+
// Exact same value as what we have seen so far
|
|
22
|
+
if (seen.get(decl.prop).value === decl.value) {
|
|
23
|
+
// Keep the last one, drop the one we've seen so far
|
|
24
|
+
droppable.add(seen.get(decl.prop));
|
|
25
|
+
// Override the existing one with the new value. This is necessary
|
|
26
|
+
// so that if we happen to have more than one declaration with the
|
|
27
|
+
// same value, that we keep removing the previous one. Otherwise we
|
|
28
|
+
// will only remove the *first* one.
|
|
29
|
+
seen.set(decl.prop, decl);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Not the same value, so we need to check if we can merge it so
|
|
33
|
+
// let's collect it first.
|
|
34
|
+
if (!byProperty.has(decl.prop)) {
|
|
35
|
+
byProperty.set(decl.prop, new Set());
|
|
36
|
+
}
|
|
37
|
+
byProperty.get(decl.prop).add(seen.get(decl.prop));
|
|
38
|
+
byProperty.get(decl.prop).add(decl);
|
|
39
|
+
}
|
|
40
|
+
seen.set(decl.prop, decl);
|
|
41
|
+
});
|
|
42
|
+
// Drop all the duplicate declarations with the exact same value we've
|
|
43
|
+
// already seen so far.
|
|
44
|
+
for (let decl1 of droppable){
|
|
45
|
+
decl1.remove();
|
|
46
|
+
}
|
|
47
|
+
// Analyze the declarations based on its unit, drop all the declarations
|
|
48
|
+
// with the same unit but the last one in the list.
|
|
49
|
+
for (let declarations of byProperty.values()){
|
|
50
|
+
let byUnit = new Map();
|
|
51
|
+
for (let decl of declarations){
|
|
52
|
+
let unit = resolveUnit(decl.value);
|
|
53
|
+
if (unit === null) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!byUnit.has(unit)) {
|
|
57
|
+
byUnit.set(unit, new Set());
|
|
58
|
+
}
|
|
59
|
+
byUnit.get(unit).add(decl);
|
|
60
|
+
}
|
|
61
|
+
for (let declarations1 of byUnit.values()){
|
|
62
|
+
// Get all but the last one
|
|
63
|
+
let removableDeclarations = Array.from(declarations1).slice(0, -1);
|
|
64
|
+
for (let decl of removableDeclarations){
|
|
65
|
+
decl.remove();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
let UNITLESS_NUMBER = Symbol("unitless-number");
|
|
73
|
+
function resolveUnit(input) {
|
|
74
|
+
let result = /^-?\d*.?\d+([\w%]+)?$/g.exec(input);
|
|
75
|
+
if (result) {
|
|
76
|
+
var ref;
|
|
77
|
+
return (ref = result[1]) !== null && ref !== void 0 ? ref : UNITLESS_NUMBER;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.defaultExtractor = defaultExtractor;
|
|
6
|
+
const PATTERNS = [
|
|
7
|
+
/(?:\['([^'\s]+[^<>"'`\s:\\])')/.source,
|
|
8
|
+
/(?:\["([^"\s]+[^<>"'`\s:\\])")/.source,
|
|
9
|
+
/(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source,
|
|
10
|
+
/([^${(<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
|
|
11
|
+
/([^${(<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source,
|
|
12
|
+
/([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
|
|
13
|
+
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
|
|
14
|
+
/([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
|
|
15
|
+
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
|
|
16
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*\('[^"`\s]*'\)+\])/.source,
|
|
17
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source,
|
|
18
|
+
/([^${(<>"'`\s]*\['[^"'`\s]*'\])/.source,
|
|
19
|
+
/([^${(<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
20
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
|
|
21
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
|
|
22
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
|
|
23
|
+
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
|
|
24
|
+
/([^"'`\s]*[^<>"'`\s:\\])/.source,
|
|
25
|
+
/([^<>"'`\s]*[^"'`\s:\\])/.source,
|
|
26
|
+
].join("|");
|
|
27
|
+
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
|
|
28
|
+
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
|
|
29
|
+
function defaultExtractor(content) {
|
|
30
|
+
let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP);
|
|
31
|
+
let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
|
|
32
|
+
let results = [
|
|
33
|
+
...broadMatches,
|
|
34
|
+
...innerMatches
|
|
35
|
+
].flat().filter((v)=>v !== undefined
|
|
36
|
+
);
|
|
37
|
+
return results;
|
|
38
|
+
} // Regular utilities
|
|
39
|
+
// {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
|
|
40
|
+
// Arbitrary values
|
|
41
|
+
// {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
|
|
42
|
+
// arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
|
|
43
|
+
// Arbitrary properties
|
|
44
|
+
// {{modifier}:}*[{validCssPropertyName}:{arbitraryValue}]
|
package/lib/lib/detectNesting.js
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
5
|
exports.default = _default;
|
|
7
|
-
|
|
8
6
|
function _default(_context) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
7
|
+
return (root, result)=>{
|
|
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
|
+
});
|
|
21
|
+
root.walkRules((rule)=>{
|
|
22
|
+
if (found) return false;
|
|
23
|
+
rule.walkRules((nestedRule)=>{
|
|
24
|
+
found = true;
|
|
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"));
|
|
30
|
+
return false;
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|