tailwindcss 0.0.0-insiders.db475be → 0.0.0-insiders.dbb5b1d
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 +33 -2
- package/lib/cli.js +18 -6
- package/lib/corePluginList.js +1 -0
- package/lib/corePlugins.js +51 -6
- 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 +4 -4
- package/lib/lib/expandApplyAtRules.js +166 -13
- package/lib/lib/expandTailwindAtRules.js +16 -6
- package/lib/lib/generateRules.js +33 -3
- package/lib/lib/resolveDefaultsAtRules.js +6 -2
- package/lib/lib/setupContextUtils.js +8 -37
- 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/util/cloneNodes.js +12 -1
- package/lib/util/log.js +7 -7
- package/lib/util/parseBoxShadowValue.js +43 -3
- package/lib/util/resolveConfig.js +22 -0
- package/package.json +12 -11
- package/peers/index.js +2117 -2945
- package/src/cli.js +22 -10
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +51 -6
- 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 +4 -4
- package/src/lib/expandApplyAtRules.js +179 -6
- package/src/lib/expandTailwindAtRules.js +26 -6
- package/src/lib/generateRules.js +11 -3
- package/src/lib/resolveDefaultsAtRules.js +6 -2
- package/src/lib/setupContextUtils.js +18 -43
- 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/util/cloneNodes.js +14 -1
- package/src/util/log.js +7 -7
- package/src/util/parseBoxShadowValue.js +50 -2
- package/src/util/resolveConfig.js +30 -0
- package/stubs/defaultConfig.stub.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,14 +9,44 @@ 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
|
+
- 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
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Replace `chalk` with `picocolors` ([#6039](https://github.com/tailwindlabs/tailwindcss/pull/6039))
|
|
25
|
+
- Replace `cosmiconfig` with `lilconfig` ([#6039](https://github.com/tailwindlabs/tailwindcss/pull/6038))
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
|
|
30
|
+
- Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
|
|
31
|
+
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
|
|
32
|
+
- Add `text-start` and `text-end` utilities ([#6656](https://github.com/tailwindlabs/tailwindcss/pull/6656))
|
|
33
|
+
- Support customizing class name when using `darkMode: 'class'` ([#5800](https://github.com/tailwindlabs/tailwindcss/pull/5800))
|
|
34
|
+
- Add `--poll` option to the CLI ([#7725](https://github.com/tailwindlabs/tailwindcss/pull/7725))
|
|
35
|
+
|
|
36
|
+
## [3.0.23] - 2022-02-16
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
12
40
|
- Remove opacity variables from `:visited` pseudo class ([#7458](https://github.com/tailwindlabs/tailwindcss/pull/7458))
|
|
13
41
|
- Support arbitrary values + calc + theme with quotes ([#7462](https://github.com/tailwindlabs/tailwindcss/pull/7462))
|
|
42
|
+
- Don't duplicate layer output when scanning content with variants + wildcards ([#7478](https://github.com/tailwindlabs/tailwindcss/pull/7478))
|
|
43
|
+
- Implement `getClassOrder` instead of `sortClassList` ([#7459](https://github.com/tailwindlabs/tailwindcss/pull/7459))
|
|
14
44
|
|
|
15
45
|
## [3.0.22] - 2022-02-11
|
|
16
46
|
|
|
17
47
|
### Fixed
|
|
18
48
|
|
|
19
|
-
- Temporarily move postcss to dependencies ([#7424](https://github.com/tailwindlabs/tailwindcss/pull/7424))
|
|
49
|
+
- Temporarily move `postcss` to dependencies ([#7424](https://github.com/tailwindlabs/tailwindcss/pull/7424))
|
|
20
50
|
|
|
21
51
|
## [3.0.21] - 2022-02-10
|
|
22
52
|
|
|
@@ -1868,7 +1898,8 @@ No release notes
|
|
|
1868
1898
|
|
|
1869
1899
|
- Everything!
|
|
1870
1900
|
|
|
1871
|
-
[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.
|
|
1901
|
+
[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.23...HEAD
|
|
1902
|
+
[3.0.23]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.22...v3.0.23
|
|
1872
1903
|
[3.0.22]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.21...v3.0.22
|
|
1873
1904
|
[3.0.21]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.20...v3.0.21
|
|
1874
1905
|
[3.0.20]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.19...v3.0.20
|
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
|
},
|
|
@@ -3148,8 +3187,9 @@ let corePlugins = {
|
|
|
3148
3187
|
});
|
|
3149
3188
|
},
|
|
3150
3189
|
ringWidth: ({ matchUtilities , addDefaults , addUtilities , theme })=>{
|
|
3190
|
+
var ref;
|
|
3151
3191
|
let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5');
|
|
3152
|
-
let ringColorDefault = (0, _withAlphaVariable).withAlphaValue(theme('ringColor.DEFAULT
|
|
3192
|
+
let ringColorDefault = (0, _withAlphaVariable).withAlphaValue((ref = theme('ringColor')) === null || ref === void 0 ? void 0 : ref.DEFAULT, ringOpacityDefault, `rgb(147 197 253 / ${ringOpacityDefault})`);
|
|
3153
3193
|
addDefaults('ring-width', {
|
|
3154
3194
|
'--tw-ring-inset': ' ',
|
|
3155
3195
|
'--tw-ring-offset-width': theme('ringOffsetWidth.DEFAULT', '0px'),
|
|
@@ -3184,9 +3224,14 @@ let corePlugins = {
|
|
|
3184
3224
|
}
|
|
3185
3225
|
});
|
|
3186
3226
|
},
|
|
3187
|
-
ringColor: ({ matchUtilities , theme })=>{
|
|
3227
|
+
ringColor: ({ matchUtilities , theme , corePlugins: corePlugins6 })=>{
|
|
3188
3228
|
matchUtilities({
|
|
3189
3229
|
ring: (value)=>{
|
|
3230
|
+
if (!corePlugins6('ringOpacity')) {
|
|
3231
|
+
return {
|
|
3232
|
+
'--tw-ring-color': (0, _toColorValue).default(value)
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3190
3235
|
return (0, _withAlphaVariable).default({
|
|
3191
3236
|
color: value,
|
|
3192
3237
|
property: '--tw-ring-color',
|
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
|
}
|
|
@@ -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
|
*
|
|
@@ -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') {
|
|
@@ -158,12 +304,12 @@ function processApply(root, context) {
|
|
|
158
304
|
]);
|
|
159
305
|
}
|
|
160
306
|
}
|
|
161
|
-
for (const [parent, candidates] of perParentApplies){
|
|
307
|
+
for (const [parent, [candidates, atApplySource]] of perParentApplies){
|
|
162
308
|
let siblings = [];
|
|
163
309
|
for (let [applyCandidate, important, rules] of candidates){
|
|
164
|
-
for (let [meta,
|
|
310
|
+
for (let [meta, node1] of rules){
|
|
165
311
|
let parentClasses = extractClasses(parent);
|
|
166
|
-
let nodeClasses = extractClasses(
|
|
312
|
+
let nodeClasses = extractClasses(node1);
|
|
167
313
|
// Add base utility classes from the @apply node to the list of
|
|
168
314
|
// classes to check whether it intersects and therefore results in a
|
|
169
315
|
// circular dependency or not.
|
|
@@ -190,14 +336,18 @@ function processApply(root, context) {
|
|
|
190
336
|
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
|
|
191
337
|
);
|
|
192
338
|
if (intersects) {
|
|
193
|
-
throw
|
|
339
|
+
throw node1.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
|
|
194
340
|
}
|
|
195
341
|
let root = _postcss.default.root({
|
|
196
342
|
nodes: [
|
|
197
|
-
|
|
343
|
+
node1.clone()
|
|
198
344
|
]
|
|
199
345
|
});
|
|
200
|
-
|
|
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';
|
|
201
351
|
if (canRewriteSelector) {
|
|
202
352
|
root.walkRules((rule)=>{
|
|
203
353
|
// Let's imagine you have the following structure:
|
|
@@ -270,11 +420,14 @@ function processApply(root, context) {
|
|
|
270
420
|
}
|
|
271
421
|
}
|
|
272
422
|
// Do it again, in case we have other `@apply` rules
|
|
273
|
-
processApply(root, context);
|
|
423
|
+
processApply(root, context, localCache);
|
|
274
424
|
}
|
|
275
425
|
}
|
|
276
426
|
function expandApplyAtRules(context) {
|
|
277
427
|
return (root)=>{
|
|
278
|
-
|
|
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);
|
|
279
432
|
};
|
|
280
433
|
}
|