UNPKG

@tempots/ui

Version:

Provides a higher level of renderables to help fast development with Tempo.

1,789 lines 51.6 kB
var Le = Object.defineProperty; var Pe = (t, e, o) => e in t ? Le(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o; var At = (t, e, o) => Pe(t, typeof e != "symbol" ? e + "" : e, o); import { getWindow as at, prop as F, makeProviderMark as Wt, Signal as te, Use as st, html as Et, on as ee, Value as E, attr as ne, Empty as Lt, OneOfType as oe, WithElement as H, OnDispose as M, Portal as re, Fragment as Q, renderableOfTNode as Ft, When as se, effectOf as Se, computedOf as ie, WithBrowserCtx as Te, Provide as ke, OneOfTuple as ce, Prop as Ce } from "@tempots/dom"; import { delayed as ae, AsyncResult as U, nearEqual as ht, interval as De } from "@tempots/std"; const We = (t) => { const e = t.split("/").pop(); if (e == null || e.startsWith(".")) return; const o = e.split(".") || []; return o.length > 1 ? "." + o.pop() : void 0; }, Fe = (t, e) => { const o = We(e); return o != null && (t.length === 0 || !t.some((n) => o == n)); }, Me = (t, e, o, n) => { let r = t.target; for (; r != null && !(r instanceof HTMLAnchorElement); ) r = r.parentElement; if (r == null) return !0; const s = r; if (t.button !== 0 || t.ctrlKey || t.metaKey || s.target !== "_self" && s.target !== "" || s.getAttribute("download") != null) return !0; const { pathname: i, search: c, hash: a } = s; if (n) { const l = i + c + a, h = s.getAttribute("href"); if (!(h != null && h.startsWith("#")) && h !== l) return !0; } return e ? !1 : Fe(o, i); }, Ne = (t, e = { ignoreUrlWithExtension: !0, allowedExtensions: [], ignoreExternalUrl: !0 }) => { const o = e.ignoreUrlWithExtension === !0 && Array.isArray(e.allowedExtensions) ? e.allowedExtensions.map( (n) => n.startsWith(".") ? n : "." + n ) : []; return (n) => { Me( n, e.ignoreUrlWithExtension ?? !0, o, e.ignoreExternalUrl ?? !0 ) || t() && n.preventDefault(); }; }, Ve = (t, e) => t.pathname === e.pathname && JSON.stringify(t.search) === JSON.stringify(e.search) && t.hash === e.hash, le = (t, e) => { var s, i; const o = new URL(t, e ?? ((s = at()) == null ? void 0 : s.location.toString())), n = Object.fromEntries(((i = o.searchParams) == null ? void 0 : i.entries()) ?? []); let r = o.hash; return r.startsWith("#") && (r = r.substring(1)), { pathname: o.pathname, search: n, hash: r === "" ? void 0 : r }; }, zt = (t, e) => { const o = le(e); return t.set(o), t; }, Pt = (t) => { const o = new URLSearchParams(t.search).toString(), n = t.hash; return `${t.pathname}${o ? `?${o}` : ""}${n ? `#${n}` : ""}`; }, $e = (t) => t.startsWith("http://") || t.startsWith("https://") || t.startsWith("//"), He = (t) => { const e = t.container.currentURL, o = e.iso( (n) => le(n), (n) => { if ($e(n.pathname)) return Pt(n); const r = new URL(n.pathname, e.value), s = r.origin + r.pathname; return Pt({ ...n, pathname: s }); } ); return { value: o, dispose: o.dispose }; }, Be = () => { const t = at(), e = (t == null ? void 0 : t.location.hash) === "" ? void 0 : (t == null ? void 0 : t.location.hash.substring(1)) ?? void 0; return { pathname: (t == null ? void 0 : t.location.pathname) ?? "", search: Object.fromEntries( new URLSearchParams((t == null ? void 0 : t.location.search) ?? "").entries() ), hash: e }; }, Ue = () => { const t = F(Be(), Ve), e = at(), o = () => { let n = (e == null ? void 0 : e.location.hash) ?? ""; n.startsWith("#") && (n = n.substring(1)); const r = { pathname: (e == null ? void 0 : e.location.pathname) ?? "", search: Object.fromEntries( new URLSearchParams((e == null ? void 0 : e.location.search) ?? "").entries() ), hash: n === "" ? void 0 : n }; t.set(r); }; return e == null || e.addEventListener("popstate", o), t.onDispose(() => { e == null || e.removeEventListener("popstate", o); }), t.on((n) => { e == null || e.history.pushState({}, "", Pt(n)); }), { value: t, dispose: t.dispose }; }, Mt = { mark: Wt("Location"), create: (t, e) => { if (e.isBrowser()) return Ue(); if (e.isHeadless()) return He(e); throw new Error("Unknown context"); } }, ze = (t) => { document.startViewTransition ? document.startViewTransition(t) : t(); }, Ke = (t, ...e) => { if (typeof t == "string" || te.is(t)) return Ke({ href: t }, ...e); const { href: o, withViewTransition: n, ...r } = t; return st(Mt, (s) => Et.a( ee.click( Ne(() => (n === !0 ? ze(() => { zt(s, E.get(o)); }) : zt(s, E.get(o)), !0), r) ), ne.href(o), ...e /* c8 ignore next 2 */ )); }, Yn = { mark: Wt("Appearance"), create: () => { const t = _e(); return { value: t, dispose: t.dispose }; } }; function _e() { const t = at(), e = t != null && t.matchMedia != null ? t.matchMedia("(prefers-color-scheme: dark)") : void 0, o = (e == null ? void 0 : e.matches) ?? !1, n = F(o ? "dark" : "light"), r = (s) => n.set(s.matches ? "dark" : "light"); return e == null || e.addEventListener("change", r), n.onDispose(() => e == null ? void 0 : e.removeEventListener("change", r)), n; } const ue = (t, e) => { if (typeof e == "function") return ue(t, { success: e }); const o = e.failure ?? ((i) => i.map((c) => `Error: ${c}`)), n = e.success, r = e.loading ?? (() => Lt), s = e.notAsked ?? (() => Lt); return oe(E.toSignal(t), { AsyncSuccess: (i) => n(i.$.value), AsyncFailure: (i) => o(i.$.error), Loading: (i) => r(i.map((c) => c.previousValue)), NotAsked: s }); }, qn = (t = 10) => H((e) => M(ae(() => e == null ? void 0 : e.focus(), t))), Xn = (t = 10) => H((e) => { const o = ae(() => e.select(), t); return M(o); }), Jn = H((t) => { const e = t.style.getPropertyValue(":empty"); return t.style.setProperty(":empty", "display:none"), M((o) => { o && t.style.setProperty(":empty", e); }); }), Gn = (t) => re("head > title", ne.innerText(t)), je = { partial: { root: null, rootMargin: "0px", threshold: 0 }, full: { root: null, rootMargin: "0px", threshold: 1 } }, mt = { partial: /* @__PURE__ */ new Map(), full: /* @__PURE__ */ new Map() }, rt = { partial: null, full: null }; function Ie(t) { return rt[t] == null && (rt[t] = new IntersectionObserver((e) => { e.forEach((o) => { const n = mt[t].get(o.target); n == null || n.set(o.isIntersecting); }); }, je[t])), rt[t]; } const Ye = ({ mode: t = "partial", once: e = !1 }, o) => { const n = F(!1); return Q( H((r) => { const s = typeof IntersectionObserver < "u" ? Ie(t) : null; mt[t].set(r, n), s == null || s.observe(r); function i() { var a; s == null || s.unobserve(r), mt[t].delete(r), mt[t].size === 0 && ((a = rt[t]) == null || a.disconnect(), rt[t] = null); } let c = null; return e && (c = n.on((a) => { a && i(); })), M(() => { n.dispose(), i(), c == null || c(); }); }), Ft(o(n)) ); }, Qn = (t, e, o) => Ye(t, (n) => se(n, e, o ?? (() => Lt))); function qe(t) { return H((e) => { const o = (n) => { e.contains(n.target) || t(n); }; return document.addEventListener("click", o), M(() => { document.removeEventListener("click", o); }); }); } const G = (t, e) => t === void 0 || t === e, Kt = (t, e) => t === void 0 || t === e; function Xe(t, e) { return typeof t == "string" ? e.key === t : Kt(t.key, e.key) && Kt(t.code, e.code) && G(t.ctrlKey, e.ctrlKey) && G(t.altKey, e.altKey) && G(t.shiftKey, e.shiftKey) && G(t.metaKey, e.metaKey) && G(t.repeat, e.repeat) && G( t.commandOrControlKey, e.metaKey || e.ctrlKey ); } function fe({ allowedKeys: t, handler: e }) { return H((o) => { const n = (r) => { if (o.contains(r.target)) { for (const s of t) if (Xe(s, r)) { e(r); break; } } }; return document.addEventListener("keydown", n), M(() => { document.removeEventListener("keydown", n); }); }); } function Zn(t) { return fe({ allowedKeys: ["Enter"], handler: t }); } function to(t) { return fe({ allowedKeys: ["Escape"], handler: t }); } const tt = Math.min, q = Math.max, gt = Math.round, dt = Math.floor, D = (t) => ({ x: t, y: t }), Je = { left: "right", right: "left", bottom: "top", top: "bottom" }, Ge = { start: "end", end: "start" }; function St(t, e, o) { return q(t, tt(e, o)); } function lt(t, e) { return typeof t == "function" ? t(e) : t; } function X(t) { return t.split("-")[0]; } function ut(t) { return t.split("-")[1]; } function he(t) { return t === "x" ? "y" : "x"; } function Nt(t) { return t === "y" ? "height" : "width"; } function z(t) { return ["top", "bottom"].includes(X(t)) ? "y" : "x"; } function Vt(t) { return he(z(t)); } function Qe(t, e, o) { o === void 0 && (o = !1); const n = ut(t), r = Vt(t), s = Nt(r); let i = r === "x" ? n === (o ? "end" : "start") ? "right" : "left" : n === "start" ? "bottom" : "top"; return e.reference[s] > e.floating[s] && (i = pt(i)), [i, pt(i)]; } function Ze(t) { const e = pt(t); return [Tt(t), e, Tt(e)]; } function Tt(t) { return t.replace(/start|end/g, (e) => Ge[e]); } function tn(t, e, o) { const n = ["left", "right"], r = ["right", "left"], s = ["top", "bottom"], i = ["bottom", "top"]; switch (t) { case "top": case "bottom": return o ? e ? r : n : e ? n : r; case "left": case "right": return e ? s : i; default: return []; } } function en(t, e, o, n) { const r = ut(t); let s = tn(X(t), o === "start", n); return r && (s = s.map((i) => i + "-" + r), e && (s = s.concat(s.map(Tt)))), s; } function pt(t) { return t.replace(/left|right|bottom|top/g, (e) => Je[e]); } function nn(t) { return { top: 0, right: 0, bottom: 0, left: 0, ...t }; } function de(t) { return typeof t != "number" ? nn(t) : { top: t, right: t, bottom: t, left: t }; } function wt(t) { const { x: e, y: o, width: n, height: r } = t; return { width: n, height: r, top: o, left: e, right: e + n, bottom: o + r, x: e, y: o }; } function _t(t, e, o) { let { reference: n, floating: r } = t; const s = z(e), i = Vt(e), c = Nt(i), a = X(e), l = s === "y", h = n.x + n.width / 2 - r.width / 2, f = n.y + n.height / 2 - r.height / 2, m = n[c] / 2 - r[c] / 2; let u; switch (a) { case "top": u = { x: h, y: n.y - r.height }; break; case "bottom": u = { x: h, y: n.y + n.height }; break; case "right": u = { x: n.x + n.width, y: f }; break; case "left": u = { x: n.x - r.width, y: f }; break; default: u = { x: n.x, y: n.y }; } switch (ut(e)) { case "start": u[i] -= m * (o && l ? -1 : 1); break; case "end": u[i] += m * (o && l ? -1 : 1); break; } return u; } const on = async (t, e, o) => { const { placement: n = "bottom", strategy: r = "absolute", middleware: s = [], platform: i } = o, c = s.filter(Boolean), a = await (i.isRTL == null ? void 0 : i.isRTL(e)); let l = await i.getElementRects({ reference: t, floating: e, strategy: r }), { x: h, y: f } = _t(l, n, a), m = n, u = {}, d = 0; for (let p = 0; p < c.length; p++) { const { name: w, fn: g } = c[p], { x, y, data: b, reset: v } = await g({ x: h, y: f, initialPlacement: n, placement: m, strategy: r, middlewareData: u, rects: l, platform: i, elements: { reference: t, floating: e } }); h = x ?? h, f = y ?? f, u = { ...u, [w]: { ...u[w], ...b } }, v && d <= 50 && (d++, typeof v == "object" && (v.placement && (m = v.placement), v.rects && (l = v.rects === !0 ? await i.getElementRects({ reference: t, floating: e, strategy: r }) : v.rects), { x: h, y: f } = _t(l, m, a)), p = -1); } return { x: h, y: f, placement: m, strategy: r, middlewareData: u }; }; async function me(t, e) { var o; e === void 0 && (e = {}); const { x: n, y: r, platform: s, rects: i, elements: c, strategy: a } = t, { boundary: l = "clippingAncestors", rootBoundary: h = "viewport", elementContext: f = "floating", altBoundary: m = !1, padding: u = 0 } = lt(e, t), d = de(u), w = c[m ? f === "floating" ? "reference" : "floating" : f], g = wt(await s.getClippingRect({ element: (o = await (s.isElement == null ? void 0 : s.isElement(w))) == null || o ? w : w.contextElement || await (s.getDocumentElement == null ? void 0 : s.getDocumentElement(c.floating)), boundary: l, rootBoundary: h, strategy: a })), x = f === "floating" ? { x: n, y: r, width: i.floating.width, height: i.floating.height } : i.reference, y = await (s.getOffsetParent == null ? void 0 : s.getOffsetParent(c.floating)), b = await (s.isElement == null ? void 0 : s.isElement(y)) ? await (s.getScale == null ? void 0 : s.getScale(y)) || { x: 1, y: 1 } : { x: 1, y: 1 }, v = wt(s.convertOffsetParentRelativeRectToViewportRelativeRect ? await s.convertOffsetParentRelativeRectToViewportRelativeRect({ elements: c, rect: x, offsetParent: y, strategy: a }) : x); return { top: (g.top - v.top + d.top) / b.y, bottom: (v.bottom - g.bottom + d.bottom) / b.y, left: (g.left - v.left + d.left) / b.x, right: (v.right - g.right + d.right) / b.x }; } const rn = (t) => ({ name: "arrow", options: t, async fn(e) { const { x: o, y: n, placement: r, rects: s, platform: i, elements: c, middlewareData: a } = e, { element: l, padding: h = 0 } = lt(t, e) || {}; if (l == null) return {}; const f = de(h), m = { x: o, y: n }, u = Vt(r), d = Nt(u), p = await i.getDimensions(l), w = u === "y", g = w ? "top" : "left", x = w ? "bottom" : "right", y = w ? "clientHeight" : "clientWidth", b = s.reference[d] + s.reference[u] - m[u] - s.floating[d], v = m[u] - s.reference[u], L = await (i.getOffsetParent == null ? void 0 : i.getOffsetParent(l)); let R = L ? L[y] : 0; (!R || !await (i.isElement == null ? void 0 : i.isElement(L))) && (R = c.floating[y] || s.floating[d]); const _ = b / 2 - v / 2, V = R / 2 - p[d] / 2 - 1, P = tt(f[g], V), j = tt(f[x], V), I = P, ot = R - p[d] - j, A = R / 2 - p[d] / 2 + _, Y = St(I, A, ot), $ = !a.arrow && ut(r) != null && A !== Y && s.reference[d] / 2 - (A < I ? P : j) - p[d] / 2 < 0, S = $ ? A < I ? A - I : A - ot : 0; return { [u]: m[u] + S, data: { [u]: Y, centerOffset: A - Y - S, ...$ && { alignmentOffset: S } }, reset: $ }; } }), sn = function(t) { return t === void 0 && (t = {}), { name: "flip", options: t, async fn(e) { var o, n; const { placement: r, middlewareData: s, rects: i, initialPlacement: c, platform: a, elements: l } = e, { mainAxis: h = !0, crossAxis: f = !0, fallbackPlacements: m, fallbackStrategy: u = "bestFit", fallbackAxisSideDirection: d = "none", flipAlignment: p = !0, ...w } = lt(t, e); if ((o = s.arrow) != null && o.alignmentOffset) return {}; const g = X(r), x = z(c), y = X(c) === c, b = await (a.isRTL == null ? void 0 : a.isRTL(l.floating)), v = m || (y || !p ? [pt(c)] : Ze(c)), L = d !== "none"; !m && L && v.push(...en(c, p, d, b)); const R = [c, ...v], _ = await me(e, w), V = []; let P = ((n = s.flip) == null ? void 0 : n.overflows) || []; if (h && V.push(_[g]), f) { const A = Qe(r, i, b); V.push(_[A[0]], _[A[1]]); } if (P = [...P, { placement: r, overflows: V }], !V.every((A) => A <= 0)) { var j, I; const A = (((j = s.flip) == null ? void 0 : j.index) || 0) + 1, Y = R[A]; if (Y && (!(f === "alignment" ? x !== z(Y) : !1) || // We leave the current main axis only if every placement on that axis // overflows the main axis. P.every((T) => T.overflows[0] > 0 && z(T.placement) === x))) return { data: { index: A, overflows: P }, reset: { placement: Y } }; let $ = (I = P.filter((S) => S.overflows[0] <= 0).sort((S, T) => S.overflows[1] - T.overflows[1])[0]) == null ? void 0 : I.placement; if (!$) switch (u) { case "bestFit": { var ot; const S = (ot = P.filter((T) => { if (L) { const B = z(T.placement); return B === x || // Create a bias to the `y` side axis due to horizontal // reading directions favoring greater width. B === "y"; } return !0; }).map((T) => [T.placement, T.overflows.filter((B) => B > 0).reduce((B, Ee) => B + Ee, 0)]).sort((T, B) => T[1] - B[1])[0]) == null ? void 0 : ot[0]; S && ($ = S); break; } case "initialPlacement": $ = c; break; } if (r !== $) return { reset: { placement: $ } }; } return {}; } }; }; async function cn(t, e) { const { placement: o, platform: n, elements: r } = t, s = await (n.isRTL == null ? void 0 : n.isRTL(r.floating)), i = X(o), c = ut(o), a = z(o) === "y", l = ["left", "top"].includes(i) ? -1 : 1, h = s && a ? -1 : 1, f = lt(e, t); let { mainAxis: m, crossAxis: u, alignmentAxis: d } = typeof f == "number" ? { mainAxis: f, crossAxis: 0, alignmentAxis: null } : { mainAxis: f.mainAxis || 0, crossAxis: f.crossAxis || 0, alignmentAxis: f.alignmentAxis }; return c && typeof d == "number" && (u = c === "end" ? d * -1 : d), a ? { x: u * h, y: m * l } : { x: m * l, y: u * h }; } const an = function(t) { return t === void 0 && (t = 0), { name: "offset", options: t, async fn(e) { var o, n; const { x: r, y: s, placement: i, middlewareData: c } = e, a = await cn(e, t); return i === ((o = c.offset) == null ? void 0 : o.placement) && (n = c.arrow) != null && n.alignmentOffset ? {} : { x: r + a.x, y: s + a.y, data: { ...a, placement: i } }; } }; }, ln = function(t) { return t === void 0 && (t = {}), { name: "shift", options: t, async fn(e) { const { x: o, y: n, placement: r } = e, { mainAxis: s = !0, crossAxis: i = !1, limiter: c = { fn: (w) => { let { x: g, y: x } = w; return { x: g, y: x }; } }, ...a } = lt(t, e), l = { x: o, y: n }, h = await me(e, a), f = z(X(r)), m = he(f); let u = l[m], d = l[f]; if (s) { const w = m === "y" ? "top" : "left", g = m === "y" ? "bottom" : "right", x = u + h[w], y = u - h[g]; u = St(x, u, y); } if (i) { const w = f === "y" ? "top" : "left", g = f === "y" ? "bottom" : "right", x = d + h[w], y = d - h[g]; d = St(x, d, y); } const p = c.fn({ ...e, [m]: u, [f]: d }); return { ...p, data: { x: p.x - o, y: p.y - n, enabled: { [m]: s, [f]: i } } }; } }; }; function xt() { return typeof window < "u"; } function nt(t) { return ge(t) ? (t.nodeName || "").toLowerCase() : "#document"; } function O(t) { var e; return (t == null || (e = t.ownerDocument) == null ? void 0 : e.defaultView) || window; } function N(t) { var e; return (e = (ge(t) ? t.ownerDocument : t.document) || window.document) == null ? void 0 : e.documentElement; } function ge(t) { return xt() ? t instanceof Node || t instanceof O(t).Node : !1; } function k(t) { return xt() ? t instanceof Element || t instanceof O(t).Element : !1; } function W(t) { return xt() ? t instanceof HTMLElement || t instanceof O(t).HTMLElement : !1; } function jt(t) { return !xt() || typeof ShadowRoot > "u" ? !1 : t instanceof ShadowRoot || t instanceof O(t).ShadowRoot; } function ft(t) { const { overflow: e, overflowX: o, overflowY: n, display: r } = C(t); return /auto|scroll|overlay|hidden|clip/.test(e + n + o) && !["inline", "contents"].includes(r); } function un(t) { return ["table", "td", "th"].includes(nt(t)); } function vt(t) { return [":popover-open", ":modal"].some((e) => { try { return t.matches(e); } catch { return !1; } }); } function $t(t) { const e = Ht(), o = k(t) ? C(t) : t; return ["transform", "translate", "scale", "rotate", "perspective"].some((n) => o[n] ? o[n] !== "none" : !1) || (o.containerType ? o.containerType !== "normal" : !1) || !e && (o.backdropFilter ? o.backdropFilter !== "none" : !1) || !e && (o.filter ? o.filter !== "none" : !1) || ["transform", "translate", "scale", "rotate", "perspective", "filter"].some((n) => (o.willChange || "").includes(n)) || ["paint", "layout", "strict", "content"].some((n) => (o.contain || "").includes(n)); } function fn(t) { let e = K(t); for (; W(e) && !et(e); ) { if ($t(e)) return e; if (vt(e)) return null; e = K(e); } return null; } function Ht() { return typeof CSS > "u" || !CSS.supports ? !1 : CSS.supports("-webkit-backdrop-filter", "none"); } function et(t) { return ["html", "body", "#document"].includes(nt(t)); } function C(t) { return O(t).getComputedStyle(t); } function bt(t) { return k(t) ? { scrollLeft: t.scrollLeft, scrollTop: t.scrollTop } : { scrollLeft: t.scrollX, scrollTop: t.scrollY }; } function K(t) { if (nt(t) === "html") return t; const e = ( // Step into the shadow DOM of the parent of a slotted node. t.assignedSlot || // DOM Element detected. t.parentNode || // ShadowRoot detected. jt(t) && t.host || // Fallback. N(t) ); return jt(e) ? e.host : e; } function pe(t) { const e = K(t); return et(e) ? t.ownerDocument ? t.ownerDocument.body : t.body : W(e) && ft(e) ? e : pe(e); } function it(t, e, o) { var n; e === void 0 && (e = []), o === void 0 && (o = !0); const r = pe(t), s = r === ((n = t.ownerDocument) == null ? void 0 : n.body), i = O(r); if (s) { const c = kt(i); return e.concat(i, i.visualViewport || [], ft(r) ? r : [], c && o ? it(c) : []); } return e.concat(r, it(r, [], o)); } function kt(t) { return t.parent && Object.getPrototypeOf(t.parent) ? t.frameElement : null; } function we(t) { const e = C(t); let o = parseFloat(e.width) || 0, n = parseFloat(e.height) || 0; const r = W(t), s = r ? t.offsetWidth : o, i = r ? t.offsetHeight : n, c = gt(o) !== s || gt(n) !== i; return c && (o = s, n = i), { width: o, height: n, $: c }; } function Bt(t) { return k(t) ? t : t.contextElement; } function Z(t) { const e = Bt(t); if (!W(e)) return D(1); const o = e.getBoundingClientRect(), { width: n, height: r, $: s } = we(e); let i = (s ? gt(o.width) : o.width) / n, c = (s ? gt(o.height) : o.height) / r; return (!i || !Number.isFinite(i)) && (i = 1), (!c || !Number.isFinite(c)) && (c = 1), { x: i, y: c }; } const hn = /* @__PURE__ */ D(0); function ye(t) { const e = O(t); return !Ht() || !e.visualViewport ? hn : { x: e.visualViewport.offsetLeft, y: e.visualViewport.offsetTop }; } function dn(t, e, o) { return e === void 0 && (e = !1), !o || e && o !== O(t) ? !1 : e; } function J(t, e, o, n) { e === void 0 && (e = !1), o === void 0 && (o = !1); const r = t.getBoundingClientRect(), s = Bt(t); let i = D(1); e && (n ? k(n) && (i = Z(n)) : i = Z(t)); const c = dn(s, o, n) ? ye(s) : D(0); let a = (r.left + c.x) / i.x, l = (r.top + c.y) / i.y, h = r.width / i.x, f = r.height / i.y; if (s) { const m = O(s), u = n && k(n) ? O(n) : n; let d = m, p = kt(d); for (; p && n && u !== d; ) { const w = Z(p), g = p.getBoundingClientRect(), x = C(p), y = g.left + (p.clientLeft + parseFloat(x.paddingLeft)) * w.x, b = g.top + (p.clientTop + parseFloat(x.paddingTop)) * w.y; a *= w.x, l *= w.y, h *= w.x, f *= w.y, a += y, l += b, d = O(p), p = kt(d); } } return wt({ width: h, height: f, x: a, y: l }); } function Ut(t, e) { const o = bt(t).scrollLeft; return e ? e.left + o : J(N(t)).left + o; } function xe(t, e, o) { o === void 0 && (o = !1); const n = t.getBoundingClientRect(), r = n.left + e.scrollLeft - (o ? 0 : ( // RTL <body> scrollbar. Ut(t, n) )), s = n.top + e.scrollTop; return { x: r, y: s }; } function mn(t) { let { elements: e, rect: o, offsetParent: n, strategy: r } = t; const s = r === "fixed", i = N(n), c = e ? vt(e.floating) : !1; if (n === i || c && s) return o; let a = { scrollLeft: 0, scrollTop: 0 }, l = D(1); const h = D(0), f = W(n); if ((f || !f && !s) && ((nt(n) !== "body" || ft(i)) && (a = bt(n)), W(n))) { const u = J(n); l = Z(n), h.x = u.x + n.clientLeft, h.y = u.y + n.clientTop; } const m = i && !f && !s ? xe(i, a, !0) : D(0); return { width: o.width * l.x, height: o.height * l.y, x: o.x * l.x - a.scrollLeft * l.x + h.x + m.x, y: o.y * l.y - a.scrollTop * l.y + h.y + m.y }; } function gn(t) { return Array.from(t.getClientRects()); } function pn(t) { const e = N(t), o = bt(t), n = t.ownerDocument.body, r = q(e.scrollWidth, e.clientWidth, n.scrollWidth, n.clientWidth), s = q(e.scrollHeight, e.clientHeight, n.scrollHeight, n.clientHeight); let i = -o.scrollLeft + Ut(t); const c = -o.scrollTop; return C(n).direction === "rtl" && (i += q(e.clientWidth, n.clientWidth) - r), { width: r, height: s, x: i, y: c }; } function wn(t, e) { const o = O(t), n = N(t), r = o.visualViewport; let s = n.clientWidth, i = n.clientHeight, c = 0, a = 0; if (r) { s = r.width, i = r.height; const l = Ht(); (!l || l && e === "fixed") && (c = r.offsetLeft, a = r.offsetTop); } return { width: s, height: i, x: c, y: a }; } function yn(t, e) { const o = J(t, !0, e === "fixed"), n = o.top + t.clientTop, r = o.left + t.clientLeft, s = W(t) ? Z(t) : D(1), i = t.clientWidth * s.x, c = t.clientHeight * s.y, a = r * s.x, l = n * s.y; return { width: i, height: c, x: a, y: l }; } function It(t, e, o) { let n; if (e === "viewport") n = wn(t, o); else if (e === "document") n = pn(N(t)); else if (k(e)) n = yn(e, o); else { const r = ye(t); n = { x: e.x - r.x, y: e.y - r.y, width: e.width, height: e.height }; } return wt(n); } function ve(t, e) { const o = K(t); return o === e || !k(o) || et(o) ? !1 : C(o).position === "fixed" || ve(o, e); } function xn(t, e) { const o = e.get(t); if (o) return o; let n = it(t, [], !1).filter((c) => k(c) && nt(c) !== "body"), r = null; const s = C(t).position === "fixed"; let i = s ? K(t) : t; for (; k(i) && !et(i); ) { const c = C(i), a = $t(i); !a && c.position === "fixed" && (r = null), (s ? !a && !r : !a && c.position === "static" && !!r && ["absolute", "fixed"].includes(r.position) || ft(i) && !a && ve(t, i)) ? n = n.filter((h) => h !== i) : r = c, i = K(i); } return e.set(t, n), n; } function vn(t) { let { element: e, boundary: o, rootBoundary: n, strategy: r } = t; const i = [...o === "clippingAncestors" ? vt(e) ? [] : xn(e, this._c) : [].concat(o), n], c = i[0], a = i.reduce((l, h) => { const f = It(e, h, r); return l.top = q(f.top, l.top), l.right = tt(f.right, l.right), l.bottom = tt(f.bottom, l.bottom), l.left = q(f.left, l.left), l; }, It(e, c, r)); return { width: a.right - a.left, height: a.bottom - a.top, x: a.left, y: a.top }; } function bn(t) { const { width: e, height: o } = we(t); return { width: e, height: o }; } function Rn(t, e, o) { const n = W(e), r = N(e), s = o === "fixed", i = J(t, !0, s, e); let c = { scrollLeft: 0, scrollTop: 0 }; const a = D(0); function l() { a.x = Ut(r); } if (n || !n && !s) if ((nt(e) !== "body" || ft(r)) && (c = bt(e)), n) { const u = J(e, !0, s, e); a.x = u.x + e.clientLeft, a.y = u.y + e.clientTop; } else r && l(); s && !n && r && l(); const h = r && !n && !s ? xe(r, c) : D(0), f = i.left + c.scrollLeft - a.x - h.x, m = i.top + c.scrollTop - a.y - h.y; return { x: f, y: m, width: i.width, height: i.height }; } function Ot(t) { return C(t).position === "static"; } function Yt(t, e) { if (!W(t) || C(t).position === "fixed") return null; if (e) return e(t); let o = t.offsetParent; return N(t) === o && (o = o.ownerDocument.body), o; } function be(t, e) { const o = O(t); if (vt(t)) return o; if (!W(t)) { let r = K(t); for (; r && !et(r); ) { if (k(r) && !Ot(r)) return r; r = K(r); } return o; } let n = Yt(t, e); for (; n && un(n) && Ot(n); ) n = Yt(n, e); return n && et(n) && Ot(n) && !$t(n) ? o : n || fn(t) || o; } const An = async function(t) { const e = this.getOffsetParent || be, o = this.getDimensions, n = await o(t.floating); return { reference: Rn(t.reference, await e(t.floating), t.strategy), floating: { x: 0, y: 0, width: n.width, height: n.height } }; }; function On(t) { return C(t).direction === "rtl"; } const En = { convertOffsetParentRelativeRectToViewportRelativeRect: mn, getDocumentElement: N, getClippingRect: vn, getOffsetParent: be, getElementRects: An, getClientRects: gn, getDimensions: bn, getScale: Z, isElement: k, isRTL: On }; function Re(t, e) { return t.x === e.x && t.y === e.y && t.width === e.width && t.height === e.height; } function Ln(t, e) { let o = null, n; const r = N(t); function s() { var c; clearTimeout(n), (c = o) == null || c.disconnect(), o = null; } function i(c, a) { c === void 0 && (c = !1), a === void 0 && (a = 1), s(); const l = t.getBoundingClientRect(), { left: h, top: f, width: m, height: u } = l; if (c || e(), !m || !u) return; const d = dt(f), p = dt(r.clientWidth - (h + m)), w = dt(r.clientHeight - (f + u)), g = dt(h), y = { rootMargin: -d + "px " + -p + "px " + -w + "px " + -g + "px", threshold: q(0, tt(1, a)) || 1 }; let b = !0; function v(L) { const R = L[0].intersectionRatio; if (R !== a) { if (!b) return i(); R ? i(!1, R) : n = setTimeout(() => { i(!1, 1e-7); }, 1e3); } R === 1 && !Re(l, t.getBoundingClientRect()) && i(), b = !1; } try { o = new IntersectionObserver(v, { ...y, // Handle <iframe>s root: r.ownerDocument }); } catch { o = new IntersectionObserver(v, y); } o.observe(t); } return i(!0), s; } function Pn(t, e, o, n) { n === void 0 && (n = {}); const { ancestorScroll: r = !0, ancestorResize: s = !0, elementResize: i = typeof ResizeObserver == "function", layoutShift: c = typeof IntersectionObserver == "function", animationFrame: a = !1 } = n, l = Bt(t), h = r || s ? [...l ? it(l) : [], ...it(e)] : []; h.forEach((g) => { r && g.addEventListener("scroll", o, { passive: !0 }), s && g.addEventListener("resize", o); }); const f = l && c ? Ln(l, o) : null; let m = -1, u = null; i && (u = new ResizeObserver((g) => { let [x] = g; x && x.target === l && u && (u.unobserve(e), cancelAnimationFrame(m), m = requestAnimationFrame(() => { var y; (y = u) == null || y.observe(e); })), o(); }), l && !a && u.observe(l), u.observe(e)); let d, p = a ? J(t) : null; a && w(); function w() { const g = J(t); p && !Re(p, g) && o(), p = g, d = requestAnimationFrame(w); } return o(), () => { var g; h.forEach((x) => { r && x.removeEventListener("scroll", o), s && x.removeEventListener("resize", o); }), f == null || f(), (g = u) == null || g.disconnect(), u = null, a && cancelAnimationFrame(d); }; } const Sn = an, Tn = ln, qt = sn, kn = rn, Cn = (t, e, o) => { const n = /* @__PURE__ */ new Map(), r = { platform: En, ...o }, s = { ...r.platform, _c: n }; return on(t, e, { ...r, platform: s }); }, eo = [ "top", "top-start", "top-end", "right", "right-start", "right-end", "bottom", "bottom-start", "bottom-end", "left", "left-start", "left-end" ], no = (t, e = { isOpen: !1 }) => { const o = []; let n = null; const r = E.deriveProp(e.isOpen); function s(c) { n = c, r.set(!0); } function i() { r.set(!1), o.forEach((c) => c()), o.length = 0; } return Q( t(s, i), se( r, () => Q( (n == null ? void 0 : n.onClickOutside) != null ? qe(n.onClickOutside) : null, H( (c) => re( "body", Et.div( H((a) => { a.style.position = "absolute"; const l = typeof (n == null ? void 0 : n.target) == "string" ? c.querySelector( n.target ) : (n == null ? void 0 : n.target) ?? c; if (l == null) throw new Error(`Target not found: ${n == null ? void 0 : n.target}`); let h = null; const f = E.toSignal((n == null ? void 0 : n.mainAxisOffset) ?? 0), m = E.toSignal( (n == null ? void 0 : n.crossAxisOffset) ?? 0 ), u = E.toSignal( /* c8 ignore next 3 */ (n == null ? void 0 : n.placement) ?? "top" ), d = E.toSignal( (n == null ? void 0 : n.arrowPadding) ?? 0 ), p = n == null ? void 0 : n.arrow, w = F({ centerOffset: 0, alignmentOffset: 0, containerWidth: 0, containerHeight: 0, x: void 0, y: void 0 }); async function g() { const y = [ qt(), Sn({ mainAxis: f.get(), crossAxis: m.get() }), Tn(), qt() ]; p != null && h != null && y.push( kn({ element: h, padding: d.get() }) ); const b = await Cn(l, a, { placement: u.get(), strategy: "absolute", middleware: y }), { x: v, y: L, middlewareData: R } = b; if (a.style.top = `${L}px`, a.style.left = `${v}px`, h != null && R.arrow != null) { const { x: _, y: V, centerOffset: P, alignmentOffset: j } = R.arrow; w.set({ x: _, y: V, centerOffset: P, alignmentOffset: j, containerWidth: a.offsetWidth, containerHeight: a.offsetHeight }); } } const x = Se( f, m, u )(g); return Q( n == null ? void 0 : n.content, (n == null ? void 0 : n.arrow) != null ? Et.div( n == null ? void 0 : n.arrow( ie( w, u )((y, b) => ({ ...y, placement: b })) ), H((y) => { h = y, g(); }) ) : null, M( w.dispose, Pn(l, a, g), x ) ); }) ) ) ) ) ) ); }, Dn = (t, e, o) => { const n = F(U.notAsked), r = n.map( (f) => U.isSuccess(f) ? f.value : void 0 ), s = n.map( (f) => U.isFailure(f) ? f.error : void 0 ), i = n.map((f) => U.isLoading(f)); let c; const a = async (f) => { c == null || c.abort(), c = new AbortController(); const m = c.signal, u = n.get(); n.set(U.loading(U.getOrUndefined(u))); try { const d = await e({ request: f, abortSignal: m, previous: u }); await Promise.resolve(), c = void 0, n.set(U.success(d)); } catch (d) { c = void 0, n.set(U.failure(o(d))); } }, l = () => a(E.get(t)), h = () => { c == null || c.abort(), c = void 0, n.dispose(); }; return n.onDispose(E.on(t, a)), { status: n, value: r, error: s, loading: i, reload: l, dispose: h }; }, Wn = (t, e) => { const { status: o, dispose: n, reload: r } = t, { loading: s, failure: i, success: c } = e; return Q( M(n), ue(o, { loading: s != null ? (a) => s(a, r) : void 0, failure: i != null ? (a) => i(a, r) : void 0, success: (a) => c(a, r) }) ); }, oo = ({ request: t, load: e, mapError: o = (n) => n }) => { const n = Dn(t, e, o); return (r) => Wn(n, r); }, Fn = (t, e) => { if (typeof e == "function") return Fn(t, { success: e }); const o = e.failure ?? ((r) => Q( M(r.on(console.error)), r.map((s) => `Error: ${s}`) )), n = e.success; return oe(E.toSignal(t), { Success: (r) => n(r.$.value), Failure: (r) => o(r.$.error) }); }, ro = () => ee.focus((t) => { var e; return (e = t.target) == null ? void 0 : e.select(); }); class Rt { /** * Creates a new Rect instance. * * @param left - The x-coordinate of the left edge * @param top - The y-coordinate of the top edge * @param width - The width of the rectangle * @param height - The height of the rectangle * * @example * ```typescript * const rect = new Rect(10, 20, 100, 50); * console.log(rect.left); // 10 * console.log(rect.top); // 20 * console.log(rect.width); // 100 * console.log(rect.height); // 50 * ``` */ constructor(e, o, n, r) { /** * Compares this rectangle with another rectangle for equality. * * Uses near-equality comparison for floating-point precision tolerance. * Two rectangles are considered equal if all their corresponding properties * (left, top, width, height) are nearly equal within a small tolerance. * * @param other - The rectangle to compare with * @returns True if the rectangles are equal, false otherwise * * @example * ```typescript * const rect1 = new Rect(10, 20, 100, 50); * const rect2 = new Rect(10, 20, 100, 50); * const rect3 = new Rect(10.00000001, 20, 100, 50); // Very close values * * console.log(rect1.equals(rect2)); // true * console.log(rect1.equals(rect3)); // true (within tolerance) * ``` */ At(this, "equals", (e) => ht(this.left, e.left) && ht(this.top, e.top) && ht(this.width, e.width) && ht(this.height, e.height)); this.left = e, this.top = o, this.width = n, this.height = r; } /** * Creates a new Rect instance using an object with optional properties. * * This factory method provides a convenient way to create rectangles with * default values for any unspecified properties. * * @param options - Object containing rectangle properties * @param options.left - The x-coordinate of the left edge (default: 0) * @param options.top - The y-coordinate of the top edge (default: 0) * @param options.width - The width of the rectangle (default: 0) * @param options.height - The height of the rectangle (default: 0) * @returns A new Rect instance * * @example * ```typescript * // Create a rectangle at origin with no size * const emptyRect = Rect.of({}); * * // Create a rectangle with only position * const positioned = Rect.of({ left: 10, top: 20 }); * * // Create a rectangle with all properties * const fullRect = Rect.of({ left: 10, top: 20, width: 100, height: 50 }); * ``` */ static of({ left: e = 0, top: o = 0, width: n = 0, height: r = 0 }) { return new Rt(e, o, n, r); } /** * Gets the x-coordinate of the right edge of the rectangle. * * @returns The right edge position (left + width) * * @example * ```typescript * const rect = new Rect(10, 20, 100, 50); * console.log(rect.right); // 110 * ``` */ get right() { return this.left + this.width; } /** * Gets the y-coordinate of the bottom edge of the rectangle. * * @returns The bottom edge position (top + height) * * @example * ```typescript * const rect = new Rect(10, 20, 100, 50); * console.log(rect.bottom); // 70 * ``` */ get bottom() { return this.top + this.height; } /** * Gets the center point of the rectangle. * * @returns An object with x and y coordinates of the center point * * @example * ```typescript * const rect = new Rect(10, 20, 100, 50); * const center = rect.center; * console.log(center.x); // 60 (left + width/2) * console.log(center.y); // 45 (top + height/2) * ``` */ get center() { return { x: this.left + this.width / 2, y: this.top + this.height / 2 }; } /** * Gets the size dimensions of the rectangle. * * @returns An object containing width and height properties * * @example * ```typescript * const rect = new Rect(10, 20, 100, 50); * const size = rect.size; * console.log(size.width); // 100 * console.log(size.height); // 50 * ``` */ get size() { return { width: this.width, height: this.height }; } } function Xt(t) { const e = t.getBoundingClientRect(); return Rt.of({ top: e.top + window.scrollY, left: e.left + window.scrollX, width: e.width, height: e.height }); } const so = (t) => Te((e) => { const { element: o } = e, n = F(Xt(o), (c, a) => c.equals(a)), r = Ft(t(n))(e), s = () => n.set(Rt.of(Xt(o))); let i = null; return typeof ResizeObserver < "u" && (i = new ResizeObserver(s)), i == null || i.observe(o), M((c) => { i == null || i.disconnect(), r(c); }); }); function Jt(t) { return { /* c8 ignore next 6 */ width: (t == null ? void 0 : t.innerWidth) ?? 0, height: (t == null ? void 0 : t.innerHeight) ?? 0 }; } const io = (t) => (e) => { const o = at(), n = F( Jt(o), (i, c) => i.width === c.width && i.height === c.height ), r = Ft(t(n))(e), s = () => n.set(Jt(o)); return o == null || o.addEventListener("resize", s), (i) => { o == null || o.removeEventListener("resize", s), r(i); }; }, Mn = (t, e) => { const o = e.split("/").filter((r) => r !== ""), n = {}; for (let r = 0; r < t.length; r++) { const s = t[r], i = o[r]; if (!i && s.type !== "catch-all") return null; if (s.type === "literal") { if (s.value !== i) return null; } else if (s.type === "param") n[s.name] = i; else if (s.type === "catch-all") return { params: n, path: e }; } return o.length !== t.length ? null : { params: n, path: e }; }, Ae = (t) => t.split("/").map((e) => e.startsWith(":") ? { type: "param", name: e.slice(1) } : e === "*" ? { type: "catch-all" } : { type: "literal", value: e }).filter((e) => e.type !== "literal" || e.value !== ""), co = (t) => { const e = t.map((o) => { const n = Ae(o); return { route: o, segments: n }; }); return function(n) { for (const { segments: r, route: s } of e) { const i = Mn(r, n); if (i) return { ...i, route: s }; } return null; }; }, Ct = { mark: Wt("RouterContext"), create: () => { const t = F([]); return { value: t, dispose: () => t.dispose() }; } }, Nn = (t, e, o) => { const n = o.split("/").filter((i) => i !== ""), r = {}; let s = 0; for (let i = 0; i < t.length; i++) { const c = t[i], a = n[i]; if (!a && c.type !== "catch-all") return null; if (c.type === "literal") { if (c.value !== a) return null; s++; } else if (c.type === "param") r[c.name] = a, s++; else if (c.type === "catch-all") { const l = "/" + n.slice(0, s).join("/"), h = "/" + n.slice(s).join("/"); return { params: r, matchedPath: l === "/" ? "" : l, remainingPath: h === "/" ? "" : h, route: e }; } } if (n.length === t.length) { const i = "/" + n.join("/"); return { params: r, matchedPath: i === "/" ? "" : i, remainingPath: "", route: e }; } return null; }, Oe = (t) => { const e = t.map((o) => { const n = Ae(o); return { route: o, segments: n }; }); return function(n) { for (const { segments: r, route: s } of e) { const i = Nn(r, s, n); if (i) return i; } return null; }; }, ao = (t) => { const e = Oe(Object.keys(t)); return ke( Ct, {}, () => st(Mt, (o) => st(Ct, (n) => { const r = o.map((s) => { const i = e(s.pathname); if (i == null) throw console.error("No route found for", s), new Error("No route found"); const c = { matchedPath: i.matchedPath, remainingPath: i.remainingPath, fullPath: s.pathname, params: i.params }; return n.value = [...n.value, c], { params: i.params, route: i.route, path: i.matchedPath || s.pathname, search: s.search, hash: s.hash }; }); return ce( r.map((s) => [s.route, s]), // eslint-disable-next-line @typescript-eslint/no-explicit-any t ); })) ); }, lo = (t) => { const e = Oe(Object.keys(t)); return st(Ct, (o) => st(Mt, (n) => { const r = o.map((s) => { const i = s[s.length - 1], c = (i == null ? void 0 : i.remainingPath) || ""; if (c === "") throw console.error("No remaining path for SubRouter", s), new Error("No remaining path for SubRouter"); const a = e(c); if (a == null) throw console.error("No route found for remaining path", c), new Error("No route found"); return { params: a.params, // Only this router's parameters route: a.route, path: a.matchedPath, search: n.value.search, hash: n.value.hash }; }); return ce( r.map((s) => [s.route, s]), // eslint-disable-next-line @typescript-eslint/no-explicit-any t ); })); }, yt = 60 * 1e3, Dt = 60 * yt, ct = 24 * Dt, Gt = 7 * ct, Qt = 30 * ct, Vn = 365 * ct, $n = [ { max: yt * 90, value: yt, name: "minute", past: { singular: "a minute ago", plural: "{} minutes ago" }, future: { singular: "in a minute", plural: "in {} minutes" } }, { max: Dt * 36, value: Dt, name: "hour", past: { singular: "an hour ago", plural: "{} hours ago" }, future: { singular: "in an hour", plural: "in {} hours" } }, { max: ct * 10, value: ct, name: "day", past: { singular: "yesterday", plural: "{} days ago" }, future: { singular: "tomorrow", plural: "in {} days" } }, { max: Gt * 6, value: Gt, name: "week", past: { singular: "last week", plural: "{} weeks ago" }, future: { singular: "in a week", plural: "in {} weeks" } }, { max: Qt * 18, value: Qt, name: "month", past: { singular: "last month", plural: "{} months ago" }, future: { singular: "in a month", plural: "in {} months" } }, { max: 1 / 0, value: Vn, name: "year", past: { singular: "last year", plural: "{} years ago" }, future: { singular: "in a year", plural: "in {} years" } } ]; function Zt(t, e, o, n) { const r = Math.round(t / e); return r <= 1 ? o : n.replace( "{}", r.toLocaleString(void 0, { maximumFractionDigits: 0, minimumFractionDigits: 0 }) ); } const Hn = (t = 1e3) => { const e = F(/* @__PURE__ */ new Date()), o = De(() => e.set(/* @__PURE__ */ new Date()), t); return e.onDispose(o), e; }, Bn = (t) => { const e = Math.abs(t); if (e < yt) return t < 0 ? "just now" : "in a moment"; for (const o of $n) if (e < o.max) return t < 0 ? Zt(e, o.value, o.past.singular, o.past.plural) : Zt(e, o.value, o.future.singular, o.future.plural); throw new Error("unreachable"); }, Un = (t, { now: e, frequency: o = 1e4 } = {}) => { const n = e != null ? te.is(e) ? e.derive() : F(e) : H