tailwindcss 0.0.0-insiders.f84ee8b → 0.0.0-insiders.f980ca4
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 +20 -2
- package/lib/cli.js +18 -6
- package/lib/corePluginList.js +1 -0
- package/lib/corePlugins.js +49 -5
- package/lib/index.js +12 -1
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/defaultExtractor.js +4 -4
- package/lib/lib/expandApplyAtRules.js +152 -6
- package/lib/lib/expandTailwindAtRules.js +15 -5
- package/lib/lib/generateRules.js +58 -40
- package/lib/lib/setupContextUtils.js +3 -26
- package/lib/lib/setupTrackingContext.js +3 -3
- package/lib/lib/sharedState.js +3 -1
- package/lib/util/cloneNodes.js +7 -1
- package/lib/util/resolveConfig.js +22 -0
- package/package.json +9 -9
- package/peers/index.js +15 -7
- package/src/cli.js +22 -10
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +50 -5
- package/src/index.js +15 -1
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/defaultExtractor.js +4 -4
- package/src/lib/expandApplyAtRules.js +171 -4
- package/src/lib/expandTailwindAtRules.js +25 -5
- package/src/lib/generateRules.js +68 -46
- package/src/lib/setupContextUtils.js +4 -21
- package/src/lib/setupTrackingContext.js +3 -3
- package/src/lib/sharedState.js +1 -0
- package/src/util/cloneNodes.js +8 -1
- package/src/util/resolveConfig.js +30 -0
- package/stubs/defaultConfig.stub.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,15 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
10
12
|
- Prevent nesting plugin from breaking other plugins ([#7563](https://github.com/tailwindlabs/tailwindcss/pull/7563))
|
|
11
13
|
- Recursively collapse adjacent rules ([#7565](https://github.com/tailwindlabs/tailwindcss/pull/7565))
|
|
12
|
-
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
|
|
13
14
|
- Preserve source maps for generated CSS ([#7588](https://github.com/tailwindlabs/tailwindcss/pull/7588))
|
|
14
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
|
+
- Correctly parse and prefix animation names with dots ([#7163](https://github.com/tailwindlabs/tailwindcss/pull/7163))
|
|
20
|
+
- Fix extraction from template literal/function with array ([#7481](https://github.com/tailwindlabs/tailwindcss/pull/7481))
|
|
21
|
+
- Don't output unparsable arbitrary values ([#7789](https://github.com/tailwindlabs/tailwindcss/pull/7789))
|
|
15
22
|
|
|
16
23
|
### Changed
|
|
17
24
|
|
|
18
25
|
- Replace `chalk` with `picocolors` ([#6039](https://github.com/tailwindlabs/tailwindcss/pull/6039))
|
|
26
|
+
- Replace `cosmiconfig` with `lilconfig` ([#6039](https://github.com/tailwindlabs/tailwindcss/pull/6038))
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
|
|
31
|
+
- Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
|
|
32
|
+
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
|
|
33
|
+
- Add `text-start` and `text-end` utilities ([#6656](https://github.com/tailwindlabs/tailwindcss/pull/6656))
|
|
34
|
+
- Support customizing class name when using `darkMode: 'class'` ([#5800](https://github.com/tailwindlabs/tailwindcss/pull/5800))
|
|
35
|
+
- Add `--poll` option to the CLI ([#7725](https://github.com/tailwindlabs/tailwindcss/pull/7725))
|
|
36
|
+
- Add new `border-spacing` utilities ([#7102](https://github.com/tailwindlabs/tailwindcss/pull/7102))
|
|
19
37
|
|
|
20
38
|
## [3.0.23] - 2022-02-16
|
|
21
39
|
|
|
@@ -30,7 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
30
48
|
|
|
31
49
|
### Fixed
|
|
32
50
|
|
|
33
|
-
- Temporarily move postcss to dependencies ([#7424](https://github.com/tailwindlabs/tailwindcss/pull/7424))
|
|
51
|
+
- Temporarily move `postcss` to dependencies ([#7424](https://github.com/tailwindlabs/tailwindcss/pull/7424))
|
|
34
52
|
|
|
35
53
|
## [3.0.21] - 2022-02-10
|
|
36
54
|
|
package/lib/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
6
6
|
var _arg = _interopRequireDefault(require("arg"));
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
8
|
var _postcssLoadConfig = _interopRequireDefault(require("postcss-load-config"));
|
|
9
|
-
var
|
|
9
|
+
var _lilconfig = require("lilconfig");
|
|
10
10
|
var _plugins // Little bit scary, looking at private/internal API
|
|
11
11
|
= _interopRequireDefault(require("postcss-load-config/src/plugins"));
|
|
12
12
|
var _processTailwindFeatures = _interopRequireDefault(require("./processTailwindFeatures"));
|
|
@@ -159,6 +159,10 @@ let commands = {
|
|
|
159
159
|
type: Boolean,
|
|
160
160
|
description: 'Watch for changes and rebuild as needed'
|
|
161
161
|
},
|
|
162
|
+
'--poll': {
|
|
163
|
+
type: Boolean,
|
|
164
|
+
description: 'Use polling instead of filesystem events when watching'
|
|
165
|
+
},
|
|
162
166
|
'--content': {
|
|
163
167
|
type: String,
|
|
164
168
|
description: 'Content paths to use for removing unused classes'
|
|
@@ -187,7 +191,8 @@ let commands = {
|
|
|
187
191
|
'-i': '--input',
|
|
188
192
|
'-o': '--output',
|
|
189
193
|
'-m': '--minify',
|
|
190
|
-
'-w': '--watch'
|
|
194
|
+
'-w': '--watch',
|
|
195
|
+
'-p': '--poll'
|
|
191
196
|
}
|
|
192
197
|
}
|
|
193
198
|
};
|
|
@@ -348,7 +353,12 @@ async function build() {
|
|
|
348
353
|
let input = args['--input'];
|
|
349
354
|
let output = args['--output'];
|
|
350
355
|
let shouldWatch = args['--watch'];
|
|
356
|
+
let shouldPoll = args['--poll'];
|
|
357
|
+
let shouldCoalesceWriteEvents = shouldPoll || process.platform === 'win32';
|
|
351
358
|
let includePostCss = args['--postcss'];
|
|
359
|
+
// Polling interval in milliseconds
|
|
360
|
+
// Used only when polling or coalescing add/change events on Windows
|
|
361
|
+
let pollInterval = 10;
|
|
352
362
|
// TODO: Deprecate this in future versions
|
|
353
363
|
if (!input && args['_'][1]) {
|
|
354
364
|
console.error('[deprecation] Running tailwindcss without -i, please provide an input file.');
|
|
@@ -368,8 +378,8 @@ async function build() {
|
|
|
368
378
|
let customPostCssPath = typeof args['--postcss'] === 'string' ? args['--postcss'] : undefined;
|
|
369
379
|
let { plugins: configPlugins } = customPostCssPath ? await (async ()=>{
|
|
370
380
|
let file = _path.default.resolve(customPostCssPath);
|
|
371
|
-
// Implementation, see: https://unpkg.com/browse/postcss-load-config@3.0
|
|
372
|
-
let { config ={} } = await (0,
|
|
381
|
+
// Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
|
|
382
|
+
let { config ={} } = await (0, _lilconfig).lilconfig('postcss').load(file);
|
|
373
383
|
if (typeof config === 'function') {
|
|
374
384
|
config = config();
|
|
375
385
|
} else {
|
|
@@ -684,10 +694,12 @@ async function build() {
|
|
|
684
694
|
...contextDependencies,
|
|
685
695
|
...extractFileGlobs(config1)
|
|
686
696
|
], {
|
|
697
|
+
usePolling: shouldPoll,
|
|
698
|
+
interval: shouldPoll ? pollInterval : undefined,
|
|
687
699
|
ignoreInitial: true,
|
|
688
|
-
awaitWriteFinish:
|
|
700
|
+
awaitWriteFinish: shouldCoalesceWriteEvents ? {
|
|
689
701
|
stabilityThreshold: 50,
|
|
690
|
-
pollInterval:
|
|
702
|
+
pollInterval: pollInterval
|
|
691
703
|
} : false
|
|
692
704
|
});
|
|
693
705
|
let chain = Promise.resolve();
|
package/lib/corePluginList.js
CHANGED
package/lib/corePlugins.js
CHANGED
|
@@ -8,6 +8,7 @@ var path = _interopRequireWildcard(require("path"));
|
|
|
8
8
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
9
|
var _createUtilityPlugin = _interopRequireDefault(require("./util/createUtilityPlugin"));
|
|
10
10
|
var _buildMediaQuery = _interopRequireDefault(require("./util/buildMediaQuery"));
|
|
11
|
+
var _escapeClassName = _interopRequireDefault(require("./util/escapeClassName"));
|
|
11
12
|
var _parseAnimationValue = _interopRequireDefault(require("./util/parseAnimationValue"));
|
|
12
13
|
var _flattenColorPalette = _interopRequireDefault(require("./util/flattenColorPalette"));
|
|
13
14
|
var _withAlphaVariable = _interopRequireWildcard(require("./util/withAlphaVariable"));
|
|
@@ -209,7 +210,7 @@ let variantPlugins = {
|
|
|
209
210
|
addVariant('motion-reduce', '@media (prefers-reduced-motion: reduce)');
|
|
210
211
|
},
|
|
211
212
|
darkVariants: ({ config , addVariant })=>{
|
|
212
|
-
let mode = config('darkMode', 'media');
|
|
213
|
+
let [mode, className = '.dark'] = [].concat(config('darkMode', 'media'));
|
|
213
214
|
if (mode === false) {
|
|
214
215
|
mode = 'media';
|
|
215
216
|
_log.default.warn('darkmode-false', [
|
|
@@ -219,7 +220,7 @@ let variantPlugins = {
|
|
|
219
220
|
]);
|
|
220
221
|
}
|
|
221
222
|
if (mode === 'class') {
|
|
222
|
-
addVariant('dark',
|
|
223
|
+
addVariant('dark', `${className} &`);
|
|
223
224
|
} else if (mode === 'media') {
|
|
224
225
|
addVariant('dark', '@media (prefers-color-scheme: dark)');
|
|
225
226
|
}
|
|
@@ -820,6 +821,38 @@ let corePlugins = {
|
|
|
820
821
|
}
|
|
821
822
|
});
|
|
822
823
|
},
|
|
824
|
+
borderSpacing: ({ addDefaults , matchUtilities , theme })=>{
|
|
825
|
+
addDefaults('border-spacing', {
|
|
826
|
+
'--tw-border-spacing-x': 0,
|
|
827
|
+
'--tw-border-spacing-y': 0
|
|
828
|
+
});
|
|
829
|
+
matchUtilities({
|
|
830
|
+
'border-spacing': (value)=>{
|
|
831
|
+
return {
|
|
832
|
+
'--tw-border-spacing-x': value,
|
|
833
|
+
'--tw-border-spacing-y': value,
|
|
834
|
+
'@defaults border-spacing': {},
|
|
835
|
+
'border-spacing': 'var(--tw-border-spacing-x) var(--tw-border-spacing-y)'
|
|
836
|
+
};
|
|
837
|
+
},
|
|
838
|
+
'border-spacing-x': (value)=>{
|
|
839
|
+
return {
|
|
840
|
+
'--tw-border-spacing-x': value,
|
|
841
|
+
'@defaults border-spacing': {},
|
|
842
|
+
'border-spacing': 'var(--tw-border-spacing-x) var(--tw-border-spacing-y)'
|
|
843
|
+
};
|
|
844
|
+
},
|
|
845
|
+
'border-spacing-y': (value)=>{
|
|
846
|
+
return {
|
|
847
|
+
'--tw-border-spacing-y': value,
|
|
848
|
+
'@defaults border-spacing': {},
|
|
849
|
+
'border-spacing': 'var(--tw-border-spacing-x) var(--tw-border-spacing-y)'
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
}, {
|
|
853
|
+
values: theme('borderSpacing')
|
|
854
|
+
});
|
|
855
|
+
},
|
|
823
856
|
transformOrigin: (0, _createUtilityPlugin).default('transformOrigin', [
|
|
824
857
|
[
|
|
825
858
|
'origin',
|
|
@@ -989,8 +1022,8 @@ let corePlugins = {
|
|
|
989
1022
|
}
|
|
990
1023
|
});
|
|
991
1024
|
},
|
|
992
|
-
animation: ({ matchUtilities , theme ,
|
|
993
|
-
let prefixName = (name)
|
|
1025
|
+
animation: ({ matchUtilities , theme , config })=>{
|
|
1026
|
+
let prefixName = (name)=>`${config('prefix')}${(0, _escapeClassName).default(name)}`
|
|
994
1027
|
;
|
|
995
1028
|
var ref;
|
|
996
1029
|
let keyframes = Object.fromEntries(Object.entries((ref = theme('keyframes')) !== null && ref !== void 0 ? ref : {}).map(([key, value])=>{
|
|
@@ -2531,6 +2564,12 @@ let corePlugins = {
|
|
|
2531
2564
|
},
|
|
2532
2565
|
'.text-justify': {
|
|
2533
2566
|
'text-align': 'justify'
|
|
2567
|
+
},
|
|
2568
|
+
'.text-start': {
|
|
2569
|
+
'text-align': 'start'
|
|
2570
|
+
},
|
|
2571
|
+
'.text-end': {
|
|
2572
|
+
'text-align': 'end'
|
|
2534
2573
|
}
|
|
2535
2574
|
});
|
|
2536
2575
|
},
|
|
@@ -3185,9 +3224,14 @@ let corePlugins = {
|
|
|
3185
3224
|
}
|
|
3186
3225
|
});
|
|
3187
3226
|
},
|
|
3188
|
-
ringColor: ({ matchUtilities , theme })=>{
|
|
3227
|
+
ringColor: ({ matchUtilities , theme , corePlugins: corePlugins6 })=>{
|
|
3189
3228
|
matchUtilities({
|
|
3190
3229
|
ring: (value)=>{
|
|
3230
|
+
if (!corePlugins6('ringOpacity')) {
|
|
3231
|
+
return {
|
|
3232
|
+
'--tw-ring-color': (0, _toColorValue).default(value)
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3191
3235
|
return (0, _withAlphaVariable).default({
|
|
3192
3236
|
color: value,
|
|
3193
3237
|
property: '--tw-ring-color',
|
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
|
+
}
|
|
@@ -7,16 +7,16 @@ const PATTERNS = [
|
|
|
7
7
|
/(?:\['([^'\s]+[^<>"'`\s:\\])')/.source,
|
|
8
8
|
/(?:\["([^"\s]+[^<>"'`\s:\\])")/.source,
|
|
9
9
|
/(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source,
|
|
10
|
-
/([
|
|
11
|
-
/([
|
|
10
|
+
/([^${(<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
|
|
11
|
+
/([^${(<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source,
|
|
12
12
|
/([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
|
|
13
13
|
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
|
|
14
14
|
/([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
|
|
15
15
|
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
|
|
16
16
|
/([^<>"'`\s]*\[[^<>"'`\s]*\('[^"`\s]*'\)+\])/.source,
|
|
17
17
|
/([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source,
|
|
18
|
-
/([
|
|
19
|
-
/([
|
|
18
|
+
/([^${(<>"'`\s]*\['[^"'`\s]*'\])/.source,
|
|
19
|
+
/([^${(<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
20
20
|
/([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
|
|
21
21
|
/([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
|
|
22
22
|
/([^<>"'`\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
|
*
|
|
@@ -277,11 +420,14 @@ function processApply(root, context) {
|
|
|
277
420
|
}
|
|
278
421
|
}
|
|
279
422
|
// Do it again, in case we have other `@apply` rules
|
|
280
|
-
processApply(root, context);
|
|
423
|
+
processApply(root, context, localCache);
|
|
281
424
|
}
|
|
282
425
|
}
|
|
283
426
|
function expandApplyAtRules(context) {
|
|
284
427
|
return (root)=>{
|
|
285
|
-
|
|
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);
|
|
286
432
|
};
|
|
287
433
|
}
|
|
@@ -191,19 +191,25 @@ function expandTailwindAtRules(context) {
|
|
|
191
191
|
layerNodes.base.before((0, _cloneNodes).default([
|
|
192
192
|
...baseNodes,
|
|
193
193
|
...defaultNodes
|
|
194
|
-
], layerNodes.base.source
|
|
194
|
+
], layerNodes.base.source, {
|
|
195
|
+
layer: 'base'
|
|
196
|
+
}));
|
|
195
197
|
layerNodes.base.remove();
|
|
196
198
|
}
|
|
197
199
|
if (layerNodes.components) {
|
|
198
200
|
layerNodes.components.before((0, _cloneNodes).default([
|
|
199
201
|
...componentNodes
|
|
200
|
-
], layerNodes.components.source
|
|
202
|
+
], layerNodes.components.source, {
|
|
203
|
+
layer: 'components'
|
|
204
|
+
}));
|
|
201
205
|
layerNodes.components.remove();
|
|
202
206
|
}
|
|
203
207
|
if (layerNodes.utilities) {
|
|
204
208
|
layerNodes.utilities.before((0, _cloneNodes).default([
|
|
205
209
|
...utilityNodes
|
|
206
|
-
], layerNodes.utilities.source
|
|
210
|
+
], layerNodes.utilities.source, {
|
|
211
|
+
layer: 'utilities'
|
|
212
|
+
}));
|
|
207
213
|
layerNodes.utilities.remove();
|
|
208
214
|
}
|
|
209
215
|
// We do post-filtering to not alter the emitted order of the variants
|
|
@@ -219,10 +225,14 @@ function expandTailwindAtRules(context) {
|
|
|
219
225
|
return true;
|
|
220
226
|
});
|
|
221
227
|
if (layerNodes.variants) {
|
|
222
|
-
layerNodes.variants.before((0, _cloneNodes).default(variantNodes, layerNodes.variants.source
|
|
228
|
+
layerNodes.variants.before((0, _cloneNodes).default(variantNodes, layerNodes.variants.source, {
|
|
229
|
+
layer: 'variants'
|
|
230
|
+
}));
|
|
223
231
|
layerNodes.variants.remove();
|
|
224
232
|
} else if (variantNodes.length > 0) {
|
|
225
|
-
root.append((0, _cloneNodes).default(variantNodes, root.source
|
|
233
|
+
root.append((0, _cloneNodes).default(variantNodes, root.source, {
|
|
234
|
+
layer: 'variants'
|
|
235
|
+
}));
|
|
226
236
|
}
|
|
227
237
|
// If we've got a utility layer and no utilities are generated there's likely something wrong
|
|
228
238
|
const hasUtilityVariants = variantNodes.some((node)=>{
|