-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpostcss.config.cjs
More file actions
81 lines (73 loc) · 1.84 KB
/
Copy pathpostcss.config.cjs
File metadata and controls
81 lines (73 loc) · 1.84 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const path = require("node:path");
const { writeJsonFileAtomic } = require("./write-json-file-atomic.cjs");
const hoverWrapperPlugin = () => {
return {
postcssPlugin: "hover-wrapper",
/** @param {Rule} rule */
Rule(rule) {
if (rule.selector.includes(":hover")) {
rule.selectors = rule.selectors.map((selector) => {
if (selector.includes(":hover")) {
return `body.mouse-active ${selector}`;
}
return selector;
});
}
},
};
};
hoverWrapperPlugin.postcss = true;
const defaultThemeGenerator = () => {
const themeProperties = new Set([
"--accent-color",
"--secondary-background",
"--text-primary",
"--text-secondary",
"background",
"background-color",
"border",
"border-color",
"border-bottom",
"border-top-color",
"box-shadow",
"color",
"filter",
"outline",
"scrollbar-color",
"text-shadow",
"--primary-background",
"border-top",
"font-family",
"--font-family",
]);
const result = {};
return {
postcssPlugin: "default-theme-generator",
prepare() {
return {
/** @param {Rule} rule */
Rule(rule) {
rule.walkDecls((decl) => {
if (themeProperties.has(decl.prop)) {
for (const selector of decl.parent.selectors) {
const selectorProperties = result[selector] || {};
result[selector] = selectorProperties;
selectorProperties[decl.prop] = decl.value;
}
}
});
},
};
},
OnceExit() {
writeJsonFileAtomic(
path.join(__dirname, "src_backend/generated/theme.default.json"),
result,
);
},
};
};
defaultThemeGenerator.postcss = true;
module.exports = {
plugins: [hoverWrapperPlugin(), defaultThemeGenerator()],
};