From 5f168246cca42ba54b67bd84fbd69fd6a5b9f820 Mon Sep 17 00:00:00 2001 From: MetroWind Date: Thu, 25 Sep 2025 16:16:58 -0700 Subject: This repo will be used for all small web apps. The NMS Freighter Planner is moved into its own dir. --- scripts/lib.js | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 scripts/lib.js (limited to 'scripts/lib.js') 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 @@ -const h = preact.h; -const CELL_SIZE = 32; -const GRID_SIZE_X = 21; -const GRID_SIZE_Y = 21; -const FLOOR_COUNT = 15; - -const ASSET_SVG_PROPS = {"width": CELL_SIZE, "height": CELL_SIZE, - "version": "1.1"}; -const ASSET_WHITE_BG = h("rect", {"x": 0, "y": 0, "width": CELL_SIZE, - "height": CELL_SIZE, "fill": "white", - "stroke-width": 0 }); - -// Bytes is a Uint8Array -async function compressBytes(bytes) -{ - let blob = new Blob([bytes]); - const ds = new CompressionStream("deflate"); - const compressed = blob.stream().pipeThrough(ds); - let compressed_blob = await new Response(compressed).blob(); - const reader = new FileReader(); - return new Promise((resolve, _) => { - reader.onloadend = (event) => { - const result = event.target.result; - resolve(result.replace(/^data:.+;base64,/, '') - .replaceAll("/", "-").replaceAll("+", "_")); - } - reader.readAsDataURL(compressed_blob); - }); -} - -// Decompress into Uint8Array -function decompressBytes(s) -{ - const decoded = window.atob(s.replaceAll("_", "+").replaceAll("-", "/")); - const decoded_array = Uint8Array.from(decoded, c => c.charCodeAt(0)); - let blob = new Blob([decoded_array]); - const cs = new DecompressionStream("deflate"); - const decompressed = blob.stream().pipeThrough(cs); - return new Response(decompressed).bytes(); -} -- cgit v1.2.3-70-g09d2