-
Notifications
You must be signed in to change notification settings - Fork 0
/
genBorderRadius.js
77 lines (62 loc) · 1.96 KB
/
genBorderRadius.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
const _ = require("lodash");
const fs = require("fs");
const FILEPATH = "src/less/";
const FILENAME = "border_radius.less";
const borderRadii = {
0: 0,
s: 0.125, // 2px
m: 0.1875, // 3px
l: 0.25, // 4px
xl: 0.5, // 8px
"10percent": "10%",
};
const CIRCLE_MIXIN = `
.circle(@width) {
border-radius: 50%;
height: @width;
width: @width;
}
`;
const constants = [];
let classes = [];
_.forEach(borderRadii, (radius, name) => {
// Trim leading 0s on fractional radiuss.
let radiusVar = `@borderRadius${name.toUpperCase()}`;
const radiusStr = `${radius}`.replace("0.", ".");
if (`${radius}`.endsWith("%")) {
radiusVar = `@borderRadius${name}`;
constants.push(`${radiusVar}: ${radius}; /* ${radius} */`);
} else {
constants.push(`${radiusVar}: ${radiusStr}rem; /* ${radius * 16}px */`);
}
classes = classes.concat([
"",
`/** ${radiusVar} */`,
`.borderRadius--${name} { border-radius: ${radiusVar}; }\n`,
`.borderRadius--topLeft--${name} { border-top-left-radius: ${radiusVar}; }\n`,
`.borderRadius--topRight--${name} { border-top-right-radius: ${radiusVar}; }\n`,
`.borderRadius--bottomLeft--${name} { border-bottom-left-radius: ${radiusVar}; }\n`,
`.borderRadius--bottomRight--${name} { border-bottom-right-radius: ${radiusVar}; }\n`,
`.borderRadius--top--${name} { .borderRadius--topLeft--${name}; .borderRadius--topRight--${name}; }\n`,
`.borderRadius--bottom--${name} { .borderRadius--bottomLeft--${name}; .borderRadius--bottomRight--${name}; }`,
]);
});
const contents = [
"// stylelint-disable max-line-length",
"",
"/**",
" * Common border-radius definitions.",
" *",
" * Auto-generated file.",
" * To re-generate, run `make border-radius-styles`",
" */",
"",
].concat(
["/**", " * Border radius constants.", " */"],
constants,
"",
["", "/**", " * Border radius classes.", " */", CIRCLE_MIXIN],
classes,
"",
);
fs.writeFileSync(`${FILEPATH}${FILENAME}`, contents.join("\n"));