[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
5

Configure Feed

Select the types of activity you want to include in your feed.

ref(wasm): shared decode util

Nate Moore (Jun 1, 2026, 3:16 PM -0500) 8aad2225 9b7e4ac7

+43 -7
+4 -7
tasks/bundle-wasm.ts
··· 47 47 48 48 const z85 = encodeZ85(compressed); 49 49 50 - // Decoder uses division instead of >>> to avoid 32-bit truncation on values near 0xFFFFFFFF. 51 - const source = `import{brotliDecompressSync}from"node:zlib"; 52 - const Z="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"; 53 - const T=new Uint8Array(128);for(let i=0;i<85;i++)T[Z.charCodeAt(i)]=i; 54 - function d(s:string,n:number){const b=new Uint8Array(n);let o=0;for(let i=0;i<s.length&&o<n;i+=5){const v=T[s.charCodeAt(i)]*52200625+T[s.charCodeAt(i+1)]*614125+T[s.charCodeAt(i+2)]*7225+T[s.charCodeAt(i+3)]*85+T[s.charCodeAt(i+4)];if(o<n)b[o++]=Math.floor(v/16777216);if(o<n)b[o++]=Math.floor(v/65536)%256;if(o<n)b[o++]=Math.floor(v/256)%256;if(o<n)b[o++]=v%256;}return b;} 55 - const compressed=d(${JSON.stringify(z85)},${compressed.byteLength}); 56 - export const compiled=await WebAssembly.compile(new Uint8Array(brotliDecompressSync(compressed))); 50 + // args separated to keep deno fmt happy 51 + const args = `${JSON.stringify(z85)}, ${compressed.byteLength}`; 52 + const source = `import { decode } from "./wasm-decode.ts"; 53 + export const compiled = await decode(${args}); 57 54 `; 58 55 59 56 await Deno.writeTextFile(output, source);
+39
wasm-decode.ts
··· 1 + import { brotliDecompressSync } from "node:zlib"; 2 + 3 + const Z85 = 4 + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"; 5 + 6 + const DECODE = new Uint8Array(128); 7 + for (let i = 0; i < 85; i++) DECODE[Z85.charCodeAt(i)] = i; 8 + 9 + // Division instead of >>> avoids 32-bit truncation on values near 0xFFFFFFFF. 10 + function decodeZ85(s: string, n: number): Uint8Array { 11 + let bytes = new Uint8Array(n); 12 + let o = 0; 13 + for (let i = 0; i < s.length && o < n; i += 5) { 14 + let v = DECODE[s.charCodeAt(i)] * 52200625 + 15 + DECODE[s.charCodeAt(i + 1)] * 614125 + 16 + DECODE[s.charCodeAt(i + 2)] * 7225 + 17 + DECODE[s.charCodeAt(i + 3)] * 85 + 18 + DECODE[s.charCodeAt(i + 4)]; 19 + if (o < n) bytes[o++] = Math.floor(v / 16777216); 20 + if (o < n) bytes[o++] = Math.floor(v / 65536) % 256; 21 + if (o < n) bytes[o++] = Math.floor(v / 256) % 256; 22 + if (o < n) bytes[o++] = v % 256; 23 + } 24 + return bytes; 25 + } 26 + 27 + /** 28 + * Decode an inlined WASM blob: z85 → brotli-decompress → compile. 29 + * 30 + * `byteLength` is the brotli-compressed length, used to size the z85 31 + * decode buffer before decompression restores the original module. 32 + */ 33 + export function decode( 34 + z85: string, 35 + byteLength: number, 36 + ): Promise<WebAssembly.Module> { 37 + let compressed = decodeZ85(z85, byteLength); 38 + return WebAssembly.compile(new Uint8Array(brotliDecompressSync(compressed))); 39 + }