2024-02-18 00:29:58 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<title>treehouse iframe sandbox</title>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
margin: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2024-02-18 10:58:57 +01:00
|
|
|
|
|
|
|
canvas {
|
|
|
|
display: block;
|
|
|
|
}
|
2024-02-18 00:29:58 +01:00
|
|
|
</style>
|
|
|
|
|
|
|
|
<script type="importmap">{ "imports": { "treehouse/": "{{ config.site }}/static/js/" } }</script>
|
|
|
|
|
|
|
|
<script type="module">
|
|
|
|
import { evaluate } from "treehouse/components/literate-programming/eval.js";
|
2024-02-18 10:58:57 +01:00
|
|
|
|
|
|
|
// I'm aware there's also ResizeObserver but it didn't seem to fire off any events when a
|
|
|
|
// canvas was added, rendering it pretty much useless.
|
|
|
|
let mutationObserver = new MutationObserver(() => {
|
|
|
|
postMessage({
|
|
|
|
kind: "resize",
|
|
|
|
width: document.body.scrollWidth,
|
|
|
|
height: document.body.scrollHeight,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
mutationObserver.observe(document.body, { subtree: true, childList: true });
|
|
|
|
|
2024-02-18 00:29:58 +01:00
|
|
|
addEventListener("message", async event => {
|
|
|
|
let message = event.data;
|
|
|
|
if (message.action == "eval") {
|
|
|
|
document.body.replaceChildren();
|
|
|
|
evaluate(message.input);
|
|
|
|
}
|
|
|
|
});
|
2024-02-18 10:58:57 +01:00
|
|
|
|
2024-02-18 00:29:58 +01:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body></body>
|
|
|
|
|
|
|
|
</html>
|