mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
29 lines
511 B
Svelte
29 lines
511 B
Svelte
<script lang="ts">
|
|
function portal(node: HTMLElement) {
|
|
let target;
|
|
|
|
function update() {
|
|
target = document.querySelector('body');
|
|
if (target) target.appendChild(node);
|
|
node.hidden = false;
|
|
}
|
|
|
|
function destroy() {
|
|
if (node.parentNode) {
|
|
// Child will tell the parent to remove itself
|
|
node.parentNode.removeChild(node);
|
|
}
|
|
}
|
|
|
|
update();
|
|
|
|
return {
|
|
update,
|
|
destroy
|
|
};
|
|
}
|
|
</script>
|
|
|
|
<div use:portal hidden>
|
|
<slot />
|
|
</div>
|