mach/src/editor/Builder/www/index.html
Stephen Gutekanst d72155df4c fold app/ into src/editor/
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2023-07-12 10:28:21 -07:00

55 lines
No EOL
1.7 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{[app_name]s}</title>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<script type="module">
import {{mach}} from "./mach.js";
import {{sysjs}} from "./mach-sysjs.js";
import setupWasmserve from "./wasmserve.js";
setupWasmserve();
let imports = {{
mach,
sysjs,
}};
fetch("{[wasm_path]s}")
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.instantiate(buffer, imports))
.then(results => results.instance)
.then(instance => {{
sysjs.init(instance);
mach.init(instance);
instance.exports.wasmInit();
let frame = true;
let last_update_time = performance.now();
let update = function () {{
if (!frame) {{
instance.exports.wasmDeinit();
return;
}}
if (mach.machHasEvent() ||
last_update_time + mach.wait_timeout * 1000 <= performance.now()) {{
if (instance.exports.wasmUpdate()) {{
instance.exports.wasmDeinit();
return;
}}
last_update_time = performance.now();
}}
window.requestAnimationFrame(update);
}};
window.requestAnimationFrame(update);
}})
.catch(err => console.error(err));
</script>
</body>
</html>