UNPKG

@westacks/vortex

Version:

Server-based routing for SPAs

44 lines (43 loc) 1.37 kB
import { p as d } from "./page-DkBioJVC.js"; import { c as p, i as f, d as v, a as m } from "./form-6EHLr-hJ.js"; import { u as k, b as E } from "./form-6EHLr-hJ.js"; import { l as S, v as A } from "./dom-BXbsE9_c.js"; async function h(a, t = "#app") { if (typeof t == "string" && (t = document.querySelector(t)), !t) throw new Error("Root element not found!"); const o = JSON.parse(t.dataset?.page ?? "null"); if (!o) throw new Error("Initial page data not defined!"); d.set(o), p(); const r = await a(t, d, f, !!t.dataset?.ssr); return () => { r instanceof Function && r(), v(); }; } function y(a, t = {}) { const { autoStart: o = !0, keepAlive: r = !1 } = t; delete t.autoStart, delete t.keepAlive; let i, s = document.hidden, e = 0, n; const l = () => { s = document.hidden, e = 0; }; function u() { document.addEventListener("visibilitychange", l), i = setInterval(() => { if (r || !s || e !== 0 && e % 10 === 0) return e = 0, n = new AbortController(), m.reload({ ...t, signal: n.signal }); e++; }, a); } function c() { clearInterval(i), n?.abort(), document.removeEventListener("visibilitychange", l); } return o && u(), { start: u, stop: c }; } export { m as axios, h as createVortex, S as link, d as page, k as useForm, y as usePoll, E as useRemember, A as visible };