-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (40 loc) · 1.04 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
/**
* @type {import('postcss').PluginCreator}
*/
module.exports = () => {
return {
postcssPlugin: "postcss-line-height-crop",
Declaration: {
"line-height-crop": (decl) => {
const round = (_) => Math.round(_ * 100) / 100;
const selector = decl.parent.selector;
const values = decl.value
.split(" ")
.filter((_) => !!_)
.filter(parseFloat);
decl.parent.before(`
${selector} {
padding: 0.1pt;
}
${selector}::before,
${selector}::after {
content: '';
display: block;
height: 0;
width: 0;
}
${selector}::before {
margin-top: ${round(values[0] * -0.005)}em;
}
${selector}::after {
margin-bottom: ${round(values[1] * -0.005)}em;
}
`);
const parent = decl.parent;
decl.remove();
if (!parent.nodes.length) parent.remove();
},
},
};
};
module.exports.postcss = true;