varaq-interpreter-go/examples/webassembly-example/index.html

59 lines
1.6 KiB
HTML
Raw Permalink Normal View History

2024-07-11 23:58:35 -04:00
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>varaq online runner</title>
<link
href="https://cdn.jsdelivr.net/npm/daisyui@4.12.10/dist/full.min.css"
rel="stylesheet"
type="text/css"
/>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="container mx-auto p-4 pt-6 md:p-6 lg:p-12">
<h1 class="text-3xl font-bold mb-4">varaq</h1>
<textarea
id="input"
class="textarea textarea-bordered w-full"
rows="5"
placeholder="Enter input"
>
</textarea>
<div class="flex flex-wrap m-4">
<button id="run" class="btn">Run</button>
</div>
<div class="mb-4">
<textarea
id="output"
class="textarea textarea-bordered w-full"
rows="5"
readonly
></textarea>
</div>
</div>
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(
fetch("varaq.wasm"),
go.importObject,
).then((result) => {
go.run(result.instance);
});
const input = document.getElementById("input");
const runButton = document.getElementById("run");
const output = document.getElementById("output");
runButton.addEventListener("click", () => {
const inputValue = input.value.trim();
const result = varaq(inputValue); // call the function here
output.value = result;
});
</script>
</body>
</html>