╭ changed ───────────╮ │src/assets/script.js│ ╰────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────────────────────────────────────╮ │1 const grid = document.getElementById("grid"); │ │2 +const pageJsonBase64 = document.getElementById("page").textContent;│ │3 │ │4 let wasmInstance; │ │5 const decoder = new TextDecoder(); │ ╰──────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │27 │ │28 WebAssembly.instantiateStreaming(fetch("haxy.wasm"), importObject).then((result) => { │ │29 wasmInstance = result.instance; │ │29 - wasmInstance.exports._start(); │ │30 + │ │31 + // the page is embedded as base64 so it can sit inside the host html │ │32 + // without worrying about characters that would terminate the script tag. │ │33 + // decode here and hand the raw json bytes to the wasm. │ │34 + const jsonBytes = Uint8Array.from(atob(pageJsonBase64), (c) => c.charCodeAt(0)); │ │35 + const ptr = wasmInstance.exports._alloc(jsonBytes.length); │ │36 + new Uint8Array(wasmInstance.exports.memory.buffer, ptr, jsonBytes.length).set(jsonBytes); │ │37 + wasmInstance.exports._start(ptr, jsonBytes.length); │ │38 │ │39 document.addEventListener("keydown", (event) => { │ │32 - if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { │ │40 + if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(event.key)) {│ │41 event.preventDefault(); │ │42 } │ │43 wasmInstance.exports._onKeyDown(event.keyCode); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯