UNPKG

webapp-astro-pwa

Version:

A ready-to-use Astro component library for adding Progressive Web App (PWA) support to your Astro projects. This package provides drop-in components and utilities for manifest injection, service worker registration, install prompts, and more. Includes a w

479 lines (468 loc) 12.9 kB
const c = class extends Event { oldState; newState; constructor(t, { oldState: o = "", newState: r = "", ...i } = {}) { super(t, i), (this.oldState = String(o || "")), (this.newState = String(r || "")); } }; const N = new WeakMap(); function P(e, t, o) { N.set( e, setTimeout(() => { N.has(e) && e.dispatchEvent(new c("toggle", { cancelable: !1, oldState: t, newState: o })); }, 0) ); } const x = globalThis.ShadowRoot || function () {}; const V = globalThis.HTMLDialogElement || function () {}; const b = new WeakMap(); const p = new WeakMap(); const h = new WeakMap(); function y(e) { return h.get(e) || "hidden"; } const L = new WeakMap(); function O(e) { const t = e.popoverTargetElement; if (!(t instanceof HTMLElement)) return; const o = y(t); (e.popoverTargetAction === "show" && o === "showing") || (e.popoverTargetAction === "hide" && o === "hidden") || (o === "showing" ? v(t, !0, !0) : f(t, !1) && (L.set(t, e), H(t))); } function f(e, t) { return !( (e.popover !== "auto" && e.popover !== "manual") || !e.isConnected || (t && y(e) !== "showing") || (!t && y(e) !== "hidden") || (e instanceof V && e.hasAttribute("open")) || document.fullscreenElement === e ); } function F(e) { return e ? Array.from(p.get(e.ownerDocument) || []).indexOf(e) + 1 : 0; } function $(e) { const t = W(e); const o = U(e); return F(t) > F(o) ? t : o; } function M(e) { const t = p.get(e); for (const o of t || []) if (!o.isConnected) t.delete(o); else return o; return null; } function d(e) { return typeof e.getRootNode === "function" ? e.getRootNode() : e.parentNode ? d(e.parentNode) : e; } function W(e) { for (; e; ) { if (e instanceof HTMLElement && e.popover === "auto" && h.get(e) === "showing") return e; if ( ((e = (e instanceof Element && e.assignedSlot) || e.parentElement || d(e)), e instanceof x && (e = e.host), e instanceof Document) ) return; } } function U(e) { for (; e; ) { const t = e.popoverTargetElement; if (t instanceof HTMLElement) return t; if (((e = e.parentElement || d(e)), e instanceof x && (e = e.host), e instanceof Document)) return; } } function G(e) { const t = new Map(); let o = 0; for (const l of p.get(e.ownerDocument) || []) t.set(l, o), (o += 1); t.set(e, o), (o += 1); let r = null; function i(l) { const a = W(l); if (a === null) return null; const T = t.get(a); (r === null || t.get(r) < T) && (r = a); } return i(e.parentElement || d(e)), r; } function Q(e) { return e.hidden || e instanceof x || ((e instanceof HTMLButtonElement || e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement || e instanceof HTMLOptGroupElement || e instanceof HTMLOptionElement || e instanceof HTMLFieldSetElement) && e.disabled) || (e instanceof HTMLInputElement && e.type === "hidden") || (e instanceof HTMLAnchorElement && e.href === "") ? !1 : typeof e.tabIndex === "number" && e.tabIndex !== -1; } function _(e) { if (e.shadowRoot && e.shadowRoot.delegatesFocus !== !0) return null; let t = e; t.shadowRoot && (t = t.shadowRoot); let o = t.querySelector("[autofocus]"); if (o) return o; { const l = t.querySelectorAll("slot"); for (const a of l) { const T = a.assignedElements({ flatten: !0 }); for (const n of T) { if (n.hasAttribute("autofocus")) return n; if (((o = n.querySelector("[autofocus]")), o)) return o; } } } const r = e.ownerDocument.createTreeWalker(t, NodeFilter.SHOW_ELEMENT); let i = r.currentNode; for (; i; ) { if (Q(i)) return i; i = r.nextNode(); } } function J(e) { _(e)?.focus(); } const S = new WeakMap(); function H(e) { if (!f(e, !1)) return; const t = e.ownerDocument; if ( !e.dispatchEvent( new c("beforetoggle", { cancelable: !0, oldState: "closed", newState: "open", }) ) || !f(e, !1) ) return; let o = !1; if (e.popover === "auto") { const i = e.getAttribute("popover"); const l = G(e) || t; if ((w(l, !1, !0), i !== e.getAttribute("popover") || !f(e, !1))) return; } M(t) || (o = !0), S.delete(e); const r = t.activeElement; e.classList.add(":popover-open"), h.set(e, "showing"), b.has(t) || b.set(t, new Set()), b.get(t).add(e), J(e), e.popover === "auto" && (p.has(t) || p.set(t, new Set()), p.get(t).add(e), C(L.get(e), !0)), o && r && e.popover === "auto" && S.set(e, r), P(e, "closed", "open"); } function v(e, t = !1, o = !1) { if (!f(e, !0)) return; const r = e.ownerDocument; if ( (e.popover === "auto" && (w(e, t, o), !f(e, !0))) || (C(L.get(e), !1), L.delete(e), o && (e.dispatchEvent(new c("beforetoggle", { oldState: "open", newState: "closed" })), !f(e, !0))) ) return; b.get(r)?.delete(e), p.get(r)?.delete(e), e.classList.remove(":popover-open"), h.set(e, "hidden"), o && P(e, "open", "closed"); const i = S.get(e); i && (S.delete(e), t && i.focus()); } function B(e, t = !1, o = !1) { let r = M(e); for (; r; ) v(r, t, o), (r = M(e)); } function w(e, t, o) { const r = e.ownerDocument || e; if (e instanceof Document) return B(r, t, o); let i = null; let l = !1; for (const a of p.get(r) || []) if (a === e) l = !0; else if (l) { i = a; break; } if (!l) return B(r, t, o); for (; i && y(i) === "showing" && p.get(r)?.size; ) v(i, t, o); } const A = new WeakMap(); function D(e) { if (!e.isTrusted) return; const t = e.composedPath()[0]; if (!t) return; const o = t.ownerDocument; if (!M(o)) return; const i = $(t); if (i && e.type === "pointerdown") A.set(o, i); else if (e.type === "pointerup") { const l = A.get(o) === i; A.delete(o), l && w(i || o, !1, !0); } } const k = new WeakMap(); function C(e, t = !1) { if (!e) return; k.has(e) || k.set(e, e.getAttribute("aria-expanded")); const o = e.popoverTargetElement; if (o instanceof HTMLElement && o.popover === "auto") e.setAttribute("aria-expanded", String(t)); else { const r = k.get(e); r ? e.setAttribute("aria-expanded", r) : e.removeAttribute("aria-expanded"); } } const q = globalThis.ShadowRoot || function () {}; function j() { return ( typeof HTMLElement < "u" && typeof HTMLElement.prototype === "object" && "popover" in HTMLElement.prototype ); } function g(e, t, o) { const r = e[t]; Object.defineProperty(e, t, { value(i) { return r.call(this, o(i)); }, }); } const X = /(^|[^\\]):popover-open\b/g; function Y() { return typeof globalThis.CSSLayerBlockRule === "function"; } function Z() { const e = Y(); return ` ${e ? "@layer popover-polyfill {" : ""} :where([popover]) { position: fixed; z-index: 2147483647; inset: 0; padding: 0.25em; width: fit-content; height: fit-content; border-width: initial; border-color: initial; border-image: initial; border-style: solid; background-color: canvas; color: canvastext; overflow: auto; margin: auto; } :where([popover]:not(.\\:popover-open)) { display: none; } :where(dialog[popover].\\:popover-open) { display: block; } :where(dialog[popover][open]) { display: revert; } :where([anchor].\\:popover-open) { inset: auto; } :where([anchor]:popover-open) { inset: auto; } @supports not (background-color: canvas) { :where([popover]) { background-color: white; color: black; } } @supports (width: -moz-fit-content) { :where([popover]) { width: -moz-fit-content; height: -moz-fit-content; } } @supports not (inset: 0) { :where([popover]) { top: 0; left: 0; right: 0; bottom: 0; } } ${e ? "}" : ""} `; } let m = null; function I(e) { const t = Z(); if (m === null) try { (m = new CSSStyleSheet()), m.replaceSync(t); } catch { m = !1; } if (m === !1) { const o = document.createElement("style"); (o.textContent = t), e instanceof Document ? e.head.prepend(o) : e.prepend(o); } else e.adoptedStyleSheets = [m, ...e.adoptedStyleSheets]; } function K() { if (typeof window > "u") return; window.ToggleEvent = window.ToggleEvent || c; function e(n) { return n?.includes(":popover-open") && (n = n.replace(X, "$1.\\:popover-open")), n; } g(Document.prototype, "querySelector", e), g(Document.prototype, "querySelectorAll", e), g(Element.prototype, "querySelector", e), g(Element.prototype, "querySelectorAll", e), g(Element.prototype, "matches", e), g(Element.prototype, "closest", e), g(DocumentFragment.prototype, "querySelectorAll", e), Object.defineProperties(HTMLElement.prototype, { popover: { enumerable: !0, configurable: !0, get() { if (!this.hasAttribute("popover")) return null; const n = (this.getAttribute("popover") || "").toLowerCase(); return n === "" || n === "auto" ? "auto" : "manual"; }, set(n) { n === null ? this.removeAttribute("popover") : this.setAttribute("popover", n); }, }, showPopover: { enumerable: !0, configurable: !0, value() { H(this); }, }, hidePopover: { enumerable: !0, configurable: !0, value() { v(this, !0, !0); }, }, togglePopover: { enumerable: !0, configurable: !0, value(n) { (h.get(this) === "showing" && n === void 0) || n === !1 ? v(this, !0, !0) : (n === void 0 || n === !0) && H(this); }, }, }); const t = Element.prototype.attachShadow; t && Object.defineProperties(Element.prototype, { attachShadow: { enumerable: !0, configurable: !0, writable: !0, value(n) { const s = t.call(this, n); return I(s), s; }, }, }); const o = HTMLElement.prototype.attachInternals; o && Object.defineProperties(HTMLElement.prototype, { attachInternals: { enumerable: !0, configurable: !0, writable: !0, value() { const n = o.call(this); return n.shadowRoot && I(n.shadowRoot), n; }, }, }); const r = new WeakMap(); function i(n) { Object.defineProperties(n.prototype, { popoverTargetElement: { enumerable: !0, configurable: !0, set(s) { if (s === null) this.removeAttribute("popovertarget"), r.delete(this); else if (s instanceof Element) this.setAttribute("popovertarget", ""), r.set(this, s); else throw new TypeError("popoverTargetElement must be an element or null"); }, get() { if ( (this.localName !== "button" && this.localName !== "input") || (this.localName === "input" && this.type !== "reset" && this.type !== "image" && this.type !== "button") || this.disabled || (this.form && this.type === "submit") ) return null; const s = r.get(this); if (s && s.isConnected) return s; if (s && !s.isConnected) return r.delete(this), null; const u = d(this); const E = this.getAttribute("popovertarget"); return ((u instanceof Document || u instanceof q) && E && u.getElementById(E)) || null; }, }, popoverTargetAction: { enumerable: !0, configurable: !0, get() { const s = (this.getAttribute("popovertargetaction") || "").toLowerCase(); return s === "show" || s === "hide" ? s : "toggle"; }, set(s) { this.setAttribute("popovertargetaction", s); }, }, }); } i(HTMLButtonElement), i(HTMLInputElement); const l = (n) => { const s = n.composedPath(); const u = s[0]; if (!(u instanceof Element) || u?.shadowRoot) return; const E = d(u); if (!(E instanceof q || E instanceof Document)) return; const R = s.find((z) => z.matches?.("[popovertargetaction],[popovertarget]")); if (R) { O(R), n.preventDefault(); } }; const a = (n) => { const s = n.key; const u = n.target; !n.defaultPrevented && u && (s === "Escape" || s === "Esc") && w(u.ownerDocument, !0, !0); }; ((n) => { n.addEventListener("click", l), n.addEventListener("keydown", a), n.addEventListener("pointerdown", D), n.addEventListener("pointerup", D); })(document), I(document); } j() || K(); // # sourceMappingURL=popover.min.js.map