/
build.ts
46 lines (43 loc) · 1.08 KB
/
build.ts
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
import * as canvas from "https://deno.land/x/canvas@v1.4.1/mod.ts";
const ctxOnce = (() => {
const emuCanvas = canvas.createCanvas(200, 200);
const ctx = emuCanvas.getContext("2d");
ctx.font = "bold 100px Arial";
return ctx;
})();
function getTextWidth100px(options: { text: string }) {
const textMetrics = ctxOnce.measureText(options.text);
const measured = {
width: textMetrics.width,
height:
textMetrics.actualBoundingBoxAscent +
textMetrics.actualBoundingBoxDescent,
};
return {
widthOfArialBoldAt100px: measured.width,
};
}
const encoder = new TextEncoder();
const decoder = new TextDecoder();
Deno.writeFileSync(
"SERVERS.gen.json",
encoder.encode(
JSON.stringify(
Object.fromEntries(
decoder
.decode(Deno.readFileSync("SERVERS.txt"))
.split(/\n/)
.map((v) => v.trim())
.filter(Boolean)
.map((host) => [
host,
{
w100px: getTextWidth100px({ text: host }).widthOfArialBoldAt100px,
},
])
),
null,
1
)
)
);