/**
 * Portal action — teleports an element to document.body.
 * Usage: <div use:portal>…</div>
 * SSR-safe: only runs when document is available.
 */
export function portal(node: HTMLElement) {
    if (typeof document === "undefined") return

    document.body.appendChild(node)

    return {
        destroy() {
            if (node.parentNode) {
                node.parentNode.removeChild(node)
            }
        },
    }
}
