import { html } from "sigpro"; export const loading = (show = true, msg = "Cargando...") => { const body = document.body; if (!show) { if (loadingEl) { loadingEl.classList.replace("opacity-100", "opacity-0"); body.style.removeProperty("overflow"); // Restaurar scroll const elToRemove = loadingEl; // Captura para el closure elToRemove.addEventListener( "transitionend", () => { if (elToRemove === loadingEl) { // Solo si sigue siendo el actual elToRemove.remove(); loadingEl = null; } }, { once: true }, ); } return; } if (loadingEl?.isConnected) { loadingEl.querySelector(".loading-text").textContent = msg; return; } body.style.overflow = "hidden"; // Bloquear scroll loadingEl = html`
${msg}
`.firstElementChild; body.appendChild(loadingEl); requestAnimationFrame(() => loadingEl.classList.replace("opacity-0", "opacity-100")); };