tailwindcss 0.0.0-insiders.bab689c → 0.0.0-insiders.bbafc8e
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 +84 -1
- package/LICENSE +1 -2
- package/lib/cli.js +9 -3
- package/lib/corePlugins.js +42 -6
- package/lib/css/preflight.css +1 -1
- package/lib/featureFlags.js +2 -2
- package/lib/index.js +12 -1
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +14 -1
- package/lib/lib/defaultExtractor.js +2 -0
- package/lib/lib/expandApplyAtRules.js +173 -17
- package/lib/lib/expandTailwindAtRules.js +16 -6
- package/lib/lib/generateRules.js +105 -30
- package/lib/lib/resolveDefaultsAtRules.js +6 -2
- package/lib/lib/setupContextUtils.js +55 -31
- package/lib/lib/setupTrackingContext.js +3 -3
- package/lib/lib/sharedState.js +5 -1
- package/lib/postcss-plugins/nesting/plugin.js +32 -0
- package/lib/processTailwindFeatures.js +5 -0
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/log.js +7 -7
- package/lib/util/parseBoxShadowValue.js +44 -4
- package/lib/util/prefixSelector.js +4 -5
- package/lib/util/resolveConfig.js +22 -0
- package/package.json +18 -21
- package/peers/index.js +2953 -4001
- package/src/cli.js +5 -3
- package/src/corePlugins.js +45 -6
- package/src/css/preflight.css +1 -1
- package/src/featureFlags.js +2 -2
- package/src/index.js +15 -1
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +16 -1
- package/src/lib/defaultExtractor.js +2 -0
- package/src/lib/expandApplyAtRules.js +184 -11
- package/src/lib/expandTailwindAtRules.js +26 -6
- package/src/lib/generateRules.js +87 -26
- package/src/lib/resolveDefaultsAtRules.js +6 -2
- package/src/lib/setupContextUtils.js +56 -28
- package/src/lib/setupTrackingContext.js +3 -3
- package/src/lib/sharedState.js +2 -0
- package/src/postcss-plugins/nesting/plugin.js +36 -0
- package/src/processTailwindFeatures.js +6 -0
- package/src/util/cloneNodes.js +14 -1
- package/src/util/log.js +7 -7
- package/src/util/parseBoxShadowValue.js +51 -3
- package/src/util/prefixSelector.js +7 -5
- package/src/util/resolveConfig.js +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,7 +9,82 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Fixed
|
|
11
11
|
|
|
12
|
+
- Prevent nesting plugin from breaking other plugins ([#7563](https://github.com/tailwindlabs/tailwindcss/pull/7563))
|
|
13
|
+
- Recursively collapse adjacent rules ([#7565](https://github.com/tailwindlabs/tailwindcss/pull/7565))
|
|
14
|
+
- Preserve source maps for generated CSS ([#7588](https://github.com/tailwindlabs/tailwindcss/pull/7588))
|
|
15
|
+
- Split box shadows on top-level commas only ([#7479](https://github.com/tailwindlabs/tailwindcss/pull/7479))
|
|
16
|
+
- Use local user CSS cache for `@apply` ([#7524](https://github.com/tailwindlabs/tailwindcss/pull/7524))
|
|
17
|
+
- Invalidate context when main CSS changes ([#7626](https://github.com/tailwindlabs/tailwindcss/pull/7626))
|
|
18
|
+
- Only add `!` to selector class matching template candidate when using important modifier with mutli-class selectors ([#7664](https://github.com/tailwindlabs/tailwindcss/pull/7664))
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Replace `chalk` with `picocolors` ([#6039](https://github.com/tailwindlabs/tailwindcss/pull/6039))
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
|
|
27
|
+
- Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
|
|
28
|
+
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
|
|
29
|
+
|
|
30
|
+
## [3.0.23] - 2022-02-16
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- Remove opacity variables from `:visited` pseudo class ([#7458](https://github.com/tailwindlabs/tailwindcss/pull/7458))
|
|
35
|
+
- Support arbitrary values + calc + theme with quotes ([#7462](https://github.com/tailwindlabs/tailwindcss/pull/7462))
|
|
36
|
+
- Don't duplicate layer output when scanning content with variants + wildcards ([#7478](https://github.com/tailwindlabs/tailwindcss/pull/7478))
|
|
37
|
+
- Implement `getClassOrder` instead of `sortClassList` ([#7459](https://github.com/tailwindlabs/tailwindcss/pull/7459))
|
|
38
|
+
|
|
39
|
+
## [3.0.22] - 2022-02-11
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- Temporarily move `postcss` to dependencies ([#7424](https://github.com/tailwindlabs/tailwindcss/pull/7424))
|
|
44
|
+
|
|
45
|
+
## [3.0.21] - 2022-02-10
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- Move prettier plugin to dev dependencies ([#7418](https://github.com/tailwindlabs/tailwindcss/pull/7418))
|
|
50
|
+
|
|
51
|
+
## [3.0.20] - 2022-02-10
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
|
|
55
|
+
- Expose `context.sortClassList(classes)` ([#7412](https://github.com/tailwindlabs/tailwindcss/pull/7412))
|
|
56
|
+
|
|
57
|
+
## [3.0.19] - 2022-02-07
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
|
|
61
|
+
- Fix preflight border color fallback ([#7288](https://github.com/tailwindlabs/tailwindcss/pull/7288))
|
|
62
|
+
- Correctly parse shadow lengths without a leading zero ([#7289](https://github.com/tailwindlabs/tailwindcss/pull/7289))
|
|
63
|
+
- Don't crash when scanning extremely long class candidates ([#7331](https://github.com/tailwindlabs/tailwindcss/pull/7331))
|
|
64
|
+
- Use less hacky fix for URLs detected as custom properties ([#7275](https://github.com/tailwindlabs/tailwindcss/pull/7275))
|
|
65
|
+
- Correctly generate negative utilities when dash is before the prefix ([#7295](https://github.com/tailwindlabs/tailwindcss/pull/7295))
|
|
66
|
+
- Detect prefixed negative utilities in the safelist ([#7295](https://github.com/tailwindlabs/tailwindcss/pull/7295))
|
|
67
|
+
|
|
68
|
+
## [3.0.18] - 2022-01-28
|
|
69
|
+
|
|
70
|
+
### Fixed
|
|
71
|
+
|
|
72
|
+
- Fix `@apply` order regression (in `addComponents`, `addUtilities`, ...) ([#7232](https://github.com/tailwindlabs/tailwindcss/pull/7232))
|
|
73
|
+
- Quick fix for incorrect arbitrary properties when using URLs ([#7252](https://github.com/tailwindlabs/tailwindcss/pull/7252))
|
|
74
|
+
|
|
75
|
+
## [3.0.17] - 2022-01-26
|
|
76
|
+
|
|
77
|
+
### Fixed
|
|
78
|
+
|
|
79
|
+
- Remove false positive warning in CLI when using the `--content` option ([#7220](https://github.com/tailwindlabs/tailwindcss/pull/7220))
|
|
80
|
+
|
|
81
|
+
## [3.0.16] - 2022-01-24
|
|
82
|
+
|
|
83
|
+
### Fixed
|
|
84
|
+
|
|
12
85
|
- Ensure to transpile the PostCSS Nesting plugin (tailwindcss/nesting) ([#7080](https://github.com/tailwindlabs/tailwindcss/pull/7080))
|
|
86
|
+
- Improve various warnings ([#7118](https://github.com/tailwindlabs/tailwindcss/pull/7118))
|
|
87
|
+
- Fix grammatical mistake ([cca5a38](https://github.com/tailwindlabs/tailwindcss/commit/cca5a3804e1d3ee0214491921e1aec35bf62a813))
|
|
13
88
|
|
|
14
89
|
## [3.0.15] - 2022-01-15
|
|
15
90
|
|
|
@@ -1817,7 +1892,15 @@ No release notes
|
|
|
1817
1892
|
|
|
1818
1893
|
- Everything!
|
|
1819
1894
|
|
|
1820
|
-
[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.
|
|
1895
|
+
[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.23...HEAD
|
|
1896
|
+
[3.0.23]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.22...v3.0.23
|
|
1897
|
+
[3.0.22]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.21...v3.0.22
|
|
1898
|
+
[3.0.21]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.20...v3.0.21
|
|
1899
|
+
[3.0.20]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.19...v3.0.20
|
|
1900
|
+
[3.0.19]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.18...v3.0.19
|
|
1901
|
+
[3.0.18]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.17...v3.0.18
|
|
1902
|
+
[3.0.17]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.16...v3.0.17
|
|
1903
|
+
[3.0.16]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.15...v3.0.16
|
|
1821
1904
|
[3.0.15]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.14...v3.0.15
|
|
1822
1905
|
[3.0.14]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.13...v3.0.14
|
|
1823
1906
|
[3.0.13]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.12...v3.0.13
|
package/LICENSE
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
4
|
-
Copyright (c) Jonathan Reinink <jonathan@reinink.ca>
|
|
3
|
+
Copyright (c) Tailwind Labs, Inc.
|
|
5
4
|
|
|
6
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/lib/cli.js
CHANGED
|
@@ -400,7 +400,6 @@ async function build() {
|
|
|
400
400
|
}
|
|
401
401
|
function resolveConfig() {
|
|
402
402
|
let config = configPath ? require(configPath) : {};
|
|
403
|
-
let resolvedConfig = (0, _resolveConfig).default(config);
|
|
404
403
|
if (args['--purge']) {
|
|
405
404
|
_log.default.warn('purge-flag-deprecated', [
|
|
406
405
|
'The `--purge` flag has been deprecated.',
|
|
@@ -411,9 +410,16 @@ async function build() {
|
|
|
411
410
|
}
|
|
412
411
|
}
|
|
413
412
|
if (args['--content']) {
|
|
414
|
-
|
|
413
|
+
let files = args['--content'].split(/(?<!{[^}]+),/);
|
|
414
|
+
let resolvedConfig = (0, _resolveConfig).default(config, {
|
|
415
|
+
content: {
|
|
416
|
+
files
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
resolvedConfig.content.files = files;
|
|
420
|
+
return resolvedConfig;
|
|
415
421
|
}
|
|
416
|
-
return
|
|
422
|
+
return (0, _resolveConfig).default(config);
|
|
417
423
|
}
|
|
418
424
|
function extractFileGlobs(config) {
|
|
419
425
|
return config.content.files.filter((file)=>{
|
package/lib/corePlugins.js
CHANGED
|
@@ -116,7 +116,28 @@ let variantPlugins = {
|
|
|
116
116
|
'last-of-type',
|
|
117
117
|
'only-of-type',
|
|
118
118
|
// State
|
|
119
|
-
|
|
119
|
+
[
|
|
120
|
+
'visited',
|
|
121
|
+
({ container })=>{
|
|
122
|
+
let toRemove = [
|
|
123
|
+
'--tw-text-opacity',
|
|
124
|
+
'--tw-border-opacity',
|
|
125
|
+
'--tw-bg-opacity'
|
|
126
|
+
];
|
|
127
|
+
container.walkDecls((decl)=>{
|
|
128
|
+
if (toRemove.includes(decl.prop)) {
|
|
129
|
+
decl.remove();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const varName of toRemove){
|
|
133
|
+
if (decl.value.includes(`/ var(${varName})`)) {
|
|
134
|
+
decl.value = decl.value.replace(`/ var(${varName})`, '');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return ':visited';
|
|
139
|
+
},
|
|
140
|
+
],
|
|
120
141
|
'target',
|
|
121
142
|
[
|
|
122
143
|
'open',
|
|
@@ -149,13 +170,22 @@ let variantPlugins = {
|
|
|
149
170
|
]
|
|
150
171
|
);
|
|
151
172
|
for (let [variantName, state] of pseudoVariants){
|
|
152
|
-
addVariant(variantName,
|
|
173
|
+
addVariant(variantName, (ctx)=>{
|
|
174
|
+
let result = typeof state === 'function' ? state(ctx) : state;
|
|
175
|
+
return `&${result}`;
|
|
176
|
+
});
|
|
153
177
|
}
|
|
154
178
|
for (let [variantName1, state1] of pseudoVariants){
|
|
155
|
-
addVariant(`group-${variantName1}`,
|
|
179
|
+
addVariant(`group-${variantName1}`, (ctx)=>{
|
|
180
|
+
let result = typeof state1 === 'function' ? state1(ctx) : state1;
|
|
181
|
+
return `:merge(.group)${result} &`;
|
|
182
|
+
});
|
|
156
183
|
}
|
|
157
184
|
for (let [variantName2, state2] of pseudoVariants){
|
|
158
|
-
addVariant(`peer-${variantName2}`,
|
|
185
|
+
addVariant(`peer-${variantName2}`, (ctx)=>{
|
|
186
|
+
let result = typeof state2 === 'function' ? state2(ctx) : state2;
|
|
187
|
+
return `:merge(.peer)${result} ~ &`;
|
|
188
|
+
});
|
|
159
189
|
}
|
|
160
190
|
},
|
|
161
191
|
directionVariants: ({ addVariant })=>{
|
|
@@ -3118,8 +3148,9 @@ let corePlugins = {
|
|
|
3118
3148
|
});
|
|
3119
3149
|
},
|
|
3120
3150
|
ringWidth: ({ matchUtilities , addDefaults , addUtilities , theme })=>{
|
|
3151
|
+
var ref;
|
|
3121
3152
|
let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5');
|
|
3122
|
-
let ringColorDefault = (0, _withAlphaVariable).withAlphaValue(theme('ringColor.DEFAULT
|
|
3153
|
+
let ringColorDefault = (0, _withAlphaVariable).withAlphaValue((ref = theme('ringColor')) === null || ref === void 0 ? void 0 : ref.DEFAULT, ringOpacityDefault, `rgb(147 197 253 / ${ringOpacityDefault})`);
|
|
3123
3154
|
addDefaults('ring-width', {
|
|
3124
3155
|
'--tw-ring-inset': ' ',
|
|
3125
3156
|
'--tw-ring-offset-width': theme('ringOffsetWidth.DEFAULT', '0px'),
|
|
@@ -3154,9 +3185,14 @@ let corePlugins = {
|
|
|
3154
3185
|
}
|
|
3155
3186
|
});
|
|
3156
3187
|
},
|
|
3157
|
-
ringColor: ({ matchUtilities , theme })=>{
|
|
3188
|
+
ringColor: ({ matchUtilities , theme , corePlugins: corePlugins6 })=>{
|
|
3158
3189
|
matchUtilities({
|
|
3159
3190
|
ring: (value)=>{
|
|
3191
|
+
if (!corePlugins6('ringOpacity')) {
|
|
3192
|
+
return {
|
|
3193
|
+
'--tw-ring-color': (0, _toColorValue).default(value)
|
|
3194
|
+
};
|
|
3195
|
+
}
|
|
3160
3196
|
return (0, _withAlphaVariable).default({
|
|
3161
3197
|
color: value,
|
|
3162
3198
|
property: '--tw-ring-color',
|
package/lib/css/preflight.css
CHANGED
package/lib/featureFlags.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
exports.flagEnabled = flagEnabled;
|
|
6
6
|
exports.issueFlagNotices = issueFlagNotices;
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var
|
|
8
|
+
var _picocolors = _interopRequireDefault(require("picocolors"));
|
|
9
9
|
var _log = _interopRequireDefault(require("./util/log"));
|
|
10
10
|
function _interopRequireDefault(obj) {
|
|
11
11
|
return obj && obj.__esModule ? obj : {
|
|
@@ -47,7 +47,7 @@ function issueFlagNotices(config) {
|
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
if (experimentalFlagsEnabled(config).length > 0) {
|
|
50
|
-
let changes = experimentalFlagsEnabled(config).map((s)=>
|
|
50
|
+
let changes = experimentalFlagsEnabled(config).map((s)=>_picocolors.default.yellow(s)
|
|
51
51
|
).join(', ');
|
|
52
52
|
_log.default.warn('experimental-flags-enabled', [
|
|
53
53
|
`You have enabled experimental features: ${changes}`,
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,18 @@ module.exports = function tailwindcss(configOrPath) {
|
|
|
17
17
|
return root;
|
|
18
18
|
},
|
|
19
19
|
function(root, result) {
|
|
20
|
-
|
|
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);
|
|
21
32
|
},
|
|
22
33
|
_sharedState.env.DEBUG && function(root) {
|
|
23
34
|
console.timeEnd('JIT TOTAL');
|
|
@@ -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
|
+
}
|
|
@@ -14,7 +14,7 @@ let comparisonMap = {
|
|
|
14
14
|
};
|
|
15
15
|
let types = new Set(Object.keys(comparisonMap));
|
|
16
16
|
function collapseAdjacentRules() {
|
|
17
|
-
|
|
17
|
+
function collapseRulesIn(root) {
|
|
18
18
|
let currentRule = null;
|
|
19
19
|
root.each((node)=>{
|
|
20
20
|
if (!types.has(node.type)) {
|
|
@@ -37,5 +37,18 @@ function collapseAdjacentRules() {
|
|
|
37
37
|
currentRule = node;
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
|
+
// After we've collapsed adjacent rules & at-rules, we need to collapse
|
|
41
|
+
// adjacent rules & at-rules that are children of at-rules.
|
|
42
|
+
// We do not care about nesting rules because Tailwind CSS
|
|
43
|
+
// explicitly does not handle rule nesting on its own as
|
|
44
|
+
// the user is expected to use a nesting plugin
|
|
45
|
+
root.each((node)=>{
|
|
46
|
+
if (node.type === 'atrule') {
|
|
47
|
+
collapseRulesIn(node);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return (root)=>{
|
|
52
|
+
collapseRulesIn(root);
|
|
40
53
|
};
|
|
41
54
|
}
|
|
@@ -13,6 +13,8 @@ const PATTERNS = [
|
|
|
13
13
|
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
|
|
14
14
|
/([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
|
|
15
15
|
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
|
|
16
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*\('[^"`\s]*'\)+\])/.source,
|
|
17
|
+
/([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source,
|
|
16
18
|
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
|
|
17
19
|
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
18
20
|
/([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
|
|
@@ -13,7 +13,7 @@ function _interopRequireDefault(obj) {
|
|
|
13
13
|
default: obj
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
function extractClasses(node) {
|
|
16
|
+
/** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
|
|
17
17
|
let classes = new Set();
|
|
18
18
|
let container = _postcss.default.root({
|
|
19
19
|
nodes: [
|
|
@@ -40,7 +40,114 @@ function prefix(context, selector) {
|
|
|
40
40
|
let prefix1 = context.tailwindConfig.prefix;
|
|
41
41
|
return typeof prefix1 === 'function' ? prefix1(selector) : prefix1 + selector;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function* pathToRoot(node) {
|
|
44
|
+
yield node;
|
|
45
|
+
while(node.parent){
|
|
46
|
+
yield node.parent;
|
|
47
|
+
node = node.parent;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Only clone the node itself and not its children
|
|
52
|
+
*
|
|
53
|
+
* @param {*} node
|
|
54
|
+
* @param {*} overrides
|
|
55
|
+
* @returns
|
|
56
|
+
*/ function shallowClone(node, overrides = {}) {
|
|
57
|
+
let children = node.nodes;
|
|
58
|
+
node.nodes = [];
|
|
59
|
+
let tmp = node.clone(overrides);
|
|
60
|
+
node.nodes = children;
|
|
61
|
+
return tmp;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Clone just the nodes all the way to the top that are required to represent
|
|
65
|
+
* this singular rule in the tree.
|
|
66
|
+
*
|
|
67
|
+
* For example, if we have CSS like this:
|
|
68
|
+
* ```css
|
|
69
|
+
* @media (min-width: 768px) {
|
|
70
|
+
* @supports (display: grid) {
|
|
71
|
+
* .foo {
|
|
72
|
+
* display: grid;
|
|
73
|
+
* grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* @supports (backdrop-filter: blur(1px)) {
|
|
78
|
+
* .bar {
|
|
79
|
+
* backdrop-filter: blur(1px);
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* .baz {
|
|
84
|
+
* color: orange;
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* And we're cloning `.bar` it'll return a cloned version of what's required for just that single node:
|
|
90
|
+
*
|
|
91
|
+
* ```css
|
|
92
|
+
* @media (min-width: 768px) {
|
|
93
|
+
* @supports (backdrop-filter: blur(1px)) {
|
|
94
|
+
* .bar {
|
|
95
|
+
* backdrop-filter: blur(1px);
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param {import('postcss').Node} node
|
|
102
|
+
*/ function nestedClone(node) {
|
|
103
|
+
for (let parent of pathToRoot(node)){
|
|
104
|
+
if (node === parent) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (parent.type === 'root') {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
node = shallowClone(parent, {
|
|
111
|
+
nodes: [
|
|
112
|
+
node
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return node;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @param {import('postcss').Root} root
|
|
120
|
+
*/ function buildLocalApplyCache(root, context) {
|
|
121
|
+
/** @type {ApplyCache} */ let cache = new Map();
|
|
122
|
+
let highestOffset = context.layerOrder.user >> 4n;
|
|
123
|
+
root.walkRules((rule, idx)=>{
|
|
124
|
+
// Ignore rules generated by Tailwind
|
|
125
|
+
for (let node of pathToRoot(rule)){
|
|
126
|
+
var ref;
|
|
127
|
+
if (((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.layer) !== undefined) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Clone what's required to represent this singular rule in the tree
|
|
132
|
+
let container = nestedClone(rule);
|
|
133
|
+
for (let className of extractClasses(rule)){
|
|
134
|
+
let list = cache.get(className) || [];
|
|
135
|
+
cache.set(className, list);
|
|
136
|
+
list.push([
|
|
137
|
+
{
|
|
138
|
+
layer: 'user',
|
|
139
|
+
sort: BigInt(idx) + highestOffset,
|
|
140
|
+
important: false
|
|
141
|
+
},
|
|
142
|
+
container,
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return cache;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @returns {ApplyCache}
|
|
150
|
+
*/ function buildApplyCache(applyCandidates, context) {
|
|
44
151
|
for (let candidate of applyCandidates){
|
|
45
152
|
if (context.notClassCache.has(candidate) || context.applyClassCache.has(candidate)) {
|
|
46
153
|
continue;
|
|
@@ -62,6 +169,39 @@ function buildApplyCache(applyCandidates, context) {
|
|
|
62
169
|
}
|
|
63
170
|
return context.applyClassCache;
|
|
64
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Build a cache only when it's first used
|
|
174
|
+
*
|
|
175
|
+
* @param {() => ApplyCache} buildCacheFn
|
|
176
|
+
* @returns {ApplyCache}
|
|
177
|
+
*/ function lazyCache(buildCacheFn) {
|
|
178
|
+
let cache = null;
|
|
179
|
+
return {
|
|
180
|
+
get: (name)=>{
|
|
181
|
+
cache = cache || buildCacheFn();
|
|
182
|
+
return cache.get(name);
|
|
183
|
+
},
|
|
184
|
+
has: (name)=>{
|
|
185
|
+
cache = cache || buildCacheFn();
|
|
186
|
+
return cache.has(name);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Take a series of multiple caches and merge
|
|
192
|
+
* them so they act like one large cache
|
|
193
|
+
*
|
|
194
|
+
* @param {ApplyCache[]} caches
|
|
195
|
+
* @returns {ApplyCache}
|
|
196
|
+
*/ function combineCaches(caches) {
|
|
197
|
+
return {
|
|
198
|
+
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
|
|
199
|
+
)
|
|
200
|
+
,
|
|
201
|
+
has: (name)=>caches.some((cache)=>cache.has(name)
|
|
202
|
+
)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
65
205
|
function extractApplyCandidates(params) {
|
|
66
206
|
let candidates = params.split(/[\s\t\n]+/g);
|
|
67
207
|
if (candidates[candidates.length - 1] === '!important') {
|
|
@@ -75,7 +215,7 @@ function extractApplyCandidates(params) {
|
|
|
75
215
|
false
|
|
76
216
|
];
|
|
77
217
|
}
|
|
78
|
-
function processApply(root, context) {
|
|
218
|
+
function processApply(root, context, localCache) {
|
|
79
219
|
let applyCandidates = new Set();
|
|
80
220
|
// Collect all @apply rules and candidates
|
|
81
221
|
let applies = [];
|
|
@@ -89,7 +229,10 @@ function processApply(root, context) {
|
|
|
89
229
|
// Start the @apply process if we have rules with @apply in them
|
|
90
230
|
if (applies.length > 0) {
|
|
91
231
|
// Fill up some caches!
|
|
92
|
-
let applyClassCache =
|
|
232
|
+
let applyClassCache = combineCaches([
|
|
233
|
+
localCache,
|
|
234
|
+
buildApplyCache(applyCandidates, context)
|
|
235
|
+
]);
|
|
93
236
|
/**
|
|
94
237
|
* When we have an apply like this:
|
|
95
238
|
*
|
|
@@ -129,7 +272,10 @@ function processApply(root, context) {
|
|
|
129
272
|
// Collect all apply candidates and their rules
|
|
130
273
|
for (let apply of applies){
|
|
131
274
|
let candidates = perParentApplies.get(apply.parent) || [];
|
|
132
|
-
perParentApplies.set(apply.parent,
|
|
275
|
+
perParentApplies.set(apply.parent, [
|
|
276
|
+
candidates,
|
|
277
|
+
apply.source
|
|
278
|
+
]);
|
|
133
279
|
let [applyCandidates, important] = extractApplyCandidates(apply.params);
|
|
134
280
|
if (apply.parent.type === 'atrule') {
|
|
135
281
|
if (apply.parent.name === 'screen') {
|
|
@@ -140,11 +286,14 @@ function processApply(root, context) {
|
|
|
140
286
|
throw apply.error(`@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`);
|
|
141
287
|
}
|
|
142
288
|
for (let applyCandidate of applyCandidates){
|
|
289
|
+
if ([
|
|
290
|
+
prefix(context, 'group'),
|
|
291
|
+
prefix(context, 'peer')
|
|
292
|
+
].includes(applyCandidate)) {
|
|
293
|
+
// TODO: Link to specific documentation page with error code.
|
|
294
|
+
throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
|
|
295
|
+
}
|
|
143
296
|
if (!applyClassCache.has(applyCandidate)) {
|
|
144
|
-
if (applyCandidate === prefix(context, 'group')) {
|
|
145
|
-
// TODO: Link to specific documentation page with error code.
|
|
146
|
-
throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
|
|
147
|
-
}
|
|
148
297
|
throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
|
|
149
298
|
}
|
|
150
299
|
let rules = applyClassCache.get(applyCandidate);
|
|
@@ -155,12 +304,12 @@ function processApply(root, context) {
|
|
|
155
304
|
]);
|
|
156
305
|
}
|
|
157
306
|
}
|
|
158
|
-
for (const [parent, candidates] of perParentApplies){
|
|
307
|
+
for (const [parent, [candidates, atApplySource]] of perParentApplies){
|
|
159
308
|
let siblings = [];
|
|
160
309
|
for (let [applyCandidate, important, rules] of candidates){
|
|
161
|
-
for (let [meta,
|
|
310
|
+
for (let [meta, node1] of rules){
|
|
162
311
|
let parentClasses = extractClasses(parent);
|
|
163
|
-
let nodeClasses = extractClasses(
|
|
312
|
+
let nodeClasses = extractClasses(node1);
|
|
164
313
|
// Add base utility classes from the @apply node to the list of
|
|
165
314
|
// classes to check whether it intersects and therefore results in a
|
|
166
315
|
// circular dependency or not.
|
|
@@ -187,14 +336,18 @@ function processApply(root, context) {
|
|
|
187
336
|
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
|
|
188
337
|
);
|
|
189
338
|
if (intersects) {
|
|
190
|
-
throw
|
|
339
|
+
throw node1.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
|
|
191
340
|
}
|
|
192
341
|
let root = _postcss.default.root({
|
|
193
342
|
nodes: [
|
|
194
|
-
|
|
343
|
+
node1.clone()
|
|
195
344
|
]
|
|
196
345
|
});
|
|
197
|
-
|
|
346
|
+
// Make sure every node in the entire tree points back at the @apply rule that generated it
|
|
347
|
+
root.walk((node)=>{
|
|
348
|
+
node.source = atApplySource;
|
|
349
|
+
});
|
|
350
|
+
let canRewriteSelector = node1.type !== 'atrule' || node1.type === 'atrule' && node1.name !== 'keyframes';
|
|
198
351
|
if (canRewriteSelector) {
|
|
199
352
|
root.walkRules((rule)=>{
|
|
200
353
|
// Let's imagine you have the following structure:
|
|
@@ -267,11 +420,14 @@ function processApply(root, context) {
|
|
|
267
420
|
}
|
|
268
421
|
}
|
|
269
422
|
// Do it again, in case we have other `@apply` rules
|
|
270
|
-
processApply(root, context);
|
|
423
|
+
processApply(root, context, localCache);
|
|
271
424
|
}
|
|
272
425
|
}
|
|
273
426
|
function expandApplyAtRules(context) {
|
|
274
427
|
return (root)=>{
|
|
275
|
-
|
|
428
|
+
// Build a cache of the user's CSS so we can use it to resolve classes used by @apply
|
|
429
|
+
let localCache = lazyCache(()=>buildLocalApplyCache(root, context)
|
|
430
|
+
);
|
|
431
|
+
processApply(root, context, localCache);
|
|
276
432
|
};
|
|
277
433
|
}
|