-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpostcss.config.js
More file actions
50 lines (41 loc) · 1.14 KB
/
Copy pathpostcss.config.js
File metadata and controls
50 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const tailwindcss = require('@tailwindcss/postcss');
const pluginRootSelector = '.ask-o11y-plugin-root';
const ignoredAtRules = new Set(['keyframes', '-webkit-keyframes', 'property']);
const isInsideIgnoredAtRule = (rule) => {
let parent = rule.parent;
while (parent) {
if (parent.type === 'atrule' && ignoredAtRules.has(parent.name)) {
return true;
}
parent = parent.parent;
}
return false;
};
const scopeSelector = (selector) => {
const trimmed = selector.trim();
if (
trimmed === '' ||
trimmed.startsWith(pluginRootSelector) ||
trimmed.startsWith(':local') ||
trimmed.startsWith(':global') ||
trimmed.includes('&')
) {
return selector;
}
if (trimmed === ':root' || trimmed === ':host' || trimmed === 'html' || trimmed === 'body') {
return pluginRootSelector;
}
return `${pluginRootSelector} ${selector}`;
};
const scopePluginCss = {
postcssPlugin: 'scope-ask-o11y-plugin-css',
Rule(rule) {
if (isInsideIgnoredAtRule(rule)) {
return;
}
rule.selectors = rule.selectors.map(scopeSelector);
},
};
module.exports = {
plugins: [tailwindcss(), scopePluginCss],
};