aboutsummaryrefslogtreecommitdiff
path: root/scripts/lib.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib.js')
-rw-r--r--scripts/lib.js40
1 files changed, 0 insertions, 40 deletions
diff --git a/scripts/lib.js b/scripts/lib.js
deleted file mode 100644
index 9a5e957..0000000
--- a/scripts/lib.js
+++ /dev/null
@@ -1,40 +0,0 @@
1const h = preact.h;
2const CELL_SIZE = 32;
3const GRID_SIZE_X = 21;
4const GRID_SIZE_Y = 21;
5const FLOOR_COUNT = 15;
6
7const ASSET_SVG_PROPS = {"width": CELL_SIZE, "height": CELL_SIZE,
8 "version": "1.1"};
9const ASSET_WHITE_BG = h("rect", {"x": 0, "y": 0, "width": CELL_SIZE,
10 "height": CELL_SIZE, "fill": "white",
11 "stroke-width": 0 });
12
13// Bytes is a Uint8Array
14async function compressBytes(bytes)
15{
16 let blob = new Blob([bytes]);
17 const ds = new CompressionStream("deflate");
18 const compressed = blob.stream().pipeThrough(ds);
19 let compressed_blob = await new Response(compressed).blob();
20 const reader = new FileReader();
21 return new Promise((resolve, _) => {
22 reader.onloadend = (event) => {
23 const result = event.target.result;
24 resolve(result.replace(/^data:.+;base64,/, '')
25 .replaceAll("/", "-").replaceAll("+", "_"));
26 }
27 reader.readAsDataURL(compressed_blob);
28 });
29}
30
31// Decompress into Uint8Array
32function decompressBytes(s)
33{
34 const decoded = window.atob(s.replaceAll("_", "+").replaceAll("-", "/"));
35 const decoded_array = Uint8Array.from(decoded, c => c.charCodeAt(0));
36 let blob = new Blob([decoded_array]);
37 const cs = new DecompressionStream("deflate");
38 const decompressed = blob.stream().pipeThrough(cs);
39 return new Response(decompressed).bytes();
40}