-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (63 loc) · 2.52 KB
/
index.js
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
module.exports = function myPostCSSPlugin() {
return {
postcssPlugin: "my-postcss-plugin",
Once(root) {
// Iterate over each rule in the CSS
root.walkRules((rule) => {
// Check if the rule selector matches the overrides
if (rule.selector.includes("[hidden]")) {
rule.selector = rule.selector.replace(
":not([hidden]) ~ :not([hidden])",
":not(:last-child)"
);
const nodes = rule.nodes;
// update style for divide-y
if (rule.selector.includes("divide-y")) {
const bottomIndex = nodes.findIndex((node) => node.prop === "border-bottom-width");
const topIndex = nodes.findIndex((node) => node.prop === "border-top-width");
if (bottomIndex !== -1) {
rule.nodes[bottomIndex].prop = "border-top-width";
}
if (topIndex !== -1) {
rule.nodes[topIndex].prop = "border-bottom-width";
}
}
// update style for divide-x
if (rule.selector.includes("divide-x")) {
const endIndex = nodes.findIndex((node) => node.prop === "border-left-width");
const startIndex = nodes.findIndex((node) => node.prop === "border-right-width");
if (endIndex !== -1) {
rule.nodes[endIndex].prop = "border-right-width";
}
if (startIndex !== -1) {
rule.nodes[startIndex].prop = "border-left-width";
}
}
// update style for space-x
if (rule.selector.includes("space-x")) {
const endIndex = nodes.findIndex((node) => node.prop === "margin-right");
const startIndex = nodes.findIndex((node) => node.prop === "margin-left");
if (endIndex !== -1) {
rule.nodes[endIndex].prop = "margin-left";
}
if (startIndex !== -1) {
rule.nodes[startIndex].prop = "margin-right";
}
}
// update style for space-y
if (rule.selector.includes("space-y")) {
const bottomIndex = nodes.findIndex((node) => node.prop === "margin-bottom");
const topIndex = nodes.findIndex((node) => node.prop === "margin-top");
if (bottomIndex !== -1) {
rule.nodes[bottomIndex].prop = "margin-top";
}
if (topIndex !== -1) {
rule.nodes[topIndex].prop = "margin-bottom";
}
}
}
});
},
};
};
module.exports.postcss = true;