guile-scene/scene.js

53 lines
1.8 KiB
JavaScript
Raw Normal View History

window.addEventListener("load", async () => {
try {
await Scheme.load_main("scene.wasm", {
user_imports: {
document: {
getElementById(id) {
return document.getElementById(id);
2024-10-12 01:34:43 +00:00
},
body() {
return document.body;
},
createTextNode(text) {
return document.createTextNode(text);
},
createElement(tag) {
return document.createElement(tag);
}
},
element: {
innerText(elem) {
return elem.innerText;
},
setInnerText(elem, value) {
elem.innerText = value;
},
addEventListener(elem, event, listener) {
elem.addEventListener(event, listener);
2024-10-12 01:34:43 +00:00
},
appendChild(elem, child) {
return elem.appendChild(child);
},
parentElement(elem) {
return elem.parentElement;
},
replaceChild(elem, child, newChild) {
// intentionally flipped as it's more intuitive than js
elem.replaceChild(newChild, child);
},
setAttribute(elem, name, value) {
elem.setAttribute(name, value);
}
}
}
});
} catch (e) {
if (e instanceof WebAssembly.CompileError) {
document.getElementById("wasm-error").hidden = false;
}
throw e;
}
});