-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathicon.svg.base.js
98 lines (90 loc) · 2.06 KB
/
icon.svg.base.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const s = require("@reeywhaar/svgmaker");
module.exports = function icon(fill = "#4c4c4c") {
const size = 128;
const piece = (n) => (size / 128) * n;
const prop = (x, n) => (x / 128) * n;
const borderWidth = piece(10);
const smallWidth = size - borderWidth * 2;
const height = piece(110);
const topHeight = piece(26);
const innerheight = height - topHeight - borderWidth;
const radius = piece(22);
const innerRadius = prop(radius, 60);
const smallRadius = prop(radius, 20);
const circleRadius = piece(6);
const circleOffsetX = piece(76);
const circleOffsetY = piece(22);
const circleGap = piece(4);
const colors = {
white: "#fff",
black: "#000",
};
function format(str, ...replacements) {
return str.replace(/\{\}/g, (x) => replacements.shift());
}
function* range(max) {
for (let i = 0; i < max; i++) yield i;
}
const circle = (x) =>
s.e("circle", {
fill: colors.black,
r: circleRadius,
cy: circleOffsetY,
cx: x,
});
const circles = () =>
Array.from(range(3)).map((x) =>
circle(circleOffsetX + (circleGap + circleRadius * 2) * x)
);
const mask = s.e(
"mask",
{
id: "icon",
},
[
s.e("rect", {
width: "100%",
height: "100%",
fill: colors.black,
}),
s.rrect(
0,
(piece(128) - height) / 2,
size,
height,
radius,
radius,
radius,
radius,
{
fill: colors.white,
}
),
s.rrect(
borderWidth,
topHeight + (piece(128) - height) / 2,
smallWidth,
innerheight,
smallRadius,
smallRadius,
innerRadius,
innerRadius,
{
fill: colors.black,
}
),
...circles(),
]
);
const svg = s.svgFile(size, size, {}, [
s.e("defs", {}, [mask]),
s.e("rect", {
width: "100%",
height: "100%",
fill: `context-fill ${fill}`,
"fill-opacity": "context-fill-opacity",
mask: "url(#icon)",
}),
]);
return svg;
};