UNPKG

mx-ui-components

Version:

mobius ui library

1,354 lines • 88.5 kB
(function() { const htmx = { // Tsc madness here, assigning the functions directly results in an invalid TypeScript output, but reassigning is fine /* Event processing */ /** @type {typeof onLoadHelper} */ onLoad: null, /** @type {typeof processNode} */ process: null, /** @type {typeof addEventListenerImpl} */ on: null, /** @type {typeof removeEventListenerImpl} */ off: null, /** @type {typeof triggerEvent} */ trigger: null, /** @type {typeof ajaxHelper} */ ajax: null, /* DOM querying helpers */ /** @type {typeof find} */ find: null, /** @type {typeof findAll} */ findAll: null, /** @type {typeof closest} */ closest: null, /** * Returns the input values that would resolve for a given element via the htmx value resolution mechanism * * @see https://htmx.org/api/#values * * @param {Element} elt the element to resolve values on * @param {HttpVerb} type the request type (e.g. **get** or **post**) non-GET's will include the enclosing form of the element. Defaults to **post** * @returns {Object} */ values: function(e, t) { return getInputValues(e, t || "post").values; }, /* DOM manipulation helpers */ /** @type {typeof removeElement} */ remove: null, /** @type {typeof addClassToElement} */ addClass: null, /** @type {typeof removeClassFromElement} */ removeClass: null, /** @type {typeof toggleClassOnElement} */ toggleClass: null, /** @type {typeof takeClassForElement} */ takeClass: null, /** @type {typeof swap} */ swap: null, /* Extension entrypoints */ /** @type {typeof defineExtension} */ defineExtension: null, /** @type {typeof removeExtension} */ removeExtension: null, /* Debugging */ /** @type {typeof logAll} */ logAll: null, /** @type {typeof logNone} */ logNone: null, /* Debugging */ /** * The logger htmx uses to log with * * @see https://htmx.org/api/#logger */ logger: null, /** * A property holding the configuration htmx uses at runtime. * * Note that using a [meta tag](https://htmx.org/docs/#config) is the preferred mechanism for setting these properties. * * @see https://htmx.org/api/#config */ config: { /** * Whether to use history. * @type boolean * @default true */ historyEnabled: !0, /** * The number of pages to keep in **localStorage** for history support. * @type number * @default 10 */ historyCacheSize: 10, /** * @type boolean * @default false */ refreshOnHistoryMiss: !1, /** * The default swap style to use if **[hx-swap](https://htmx.org/attributes/hx-swap)** is omitted. * @type HtmxSwapStyle * @default 'innerHTML' */ defaultSwapStyle: "innerHTML", /** * The default delay between receiving a response from the server and doing the swap. * @type number * @default 0 */ defaultSwapDelay: 0, /** * The default delay between completing the content swap and settling attributes. * @type number * @default 20 */ defaultSettleDelay: 20, /** * If true, htmx will inject a small amount of CSS into the page to make indicators invisible unless the **htmx-indicator** class is present. * @type boolean * @default true */ includeIndicatorStyles: !0, /** * The class to place on indicators when a request is in flight. * @type string * @default 'htmx-indicator' */ indicatorClass: "htmx-indicator", /** * The class to place on triggering elements when a request is in flight. * @type string * @default 'htmx-request' */ requestClass: "htmx-request", /** * The class to temporarily place on elements that htmx has added to the DOM. * @type string * @default 'htmx-added' */ addedClass: "htmx-added", /** * The class to place on target elements when htmx is in the settling phase. * @type string * @default 'htmx-settling' */ settlingClass: "htmx-settling", /** * The class to place on target elements when htmx is in the swapping phase. * @type string * @default 'htmx-swapping' */ swappingClass: "htmx-swapping", /** * Allows the use of eval-like functionality in htmx, to enable **hx-vars**, trigger conditions & script tag evaluation. Can be set to **false** for CSP compatibility. * @type boolean * @default true */ allowEval: !0, /** * If set to false, disables the interpretation of script tags. * @type boolean * @default true */ allowScriptTags: !0, /** * If set, the nonce will be added to inline scripts. * @type string * @default '' */ inlineScriptNonce: "", /** * If set, the nonce will be added to inline styles. * @type string * @default '' */ inlineStyleNonce: "", /** * The attributes to settle during the settling phase. * @type string[] * @default ['class', 'style', 'width', 'height'] */ attributesToSettle: ["class", "style", "width", "height"], /** * Allow cross-site Access-Control requests using credentials such as cookies, authorization headers or TLS client certificates. * @type boolean * @default false */ withCredentials: !1, /** * @type number * @default 0 */ timeout: 0, /** * The default implementation of **getWebSocketReconnectDelay** for reconnecting after unexpected connection loss by the event code **Abnormal Closure**, **Service Restart** or **Try Again Later**. * @type {'full-jitter' | ((retryCount:number) => number)} * @default "full-jitter" */ wsReconnectDelay: "full-jitter", /** * The type of binary data being received over the WebSocket connection * @type BinaryType * @default 'blob' */ wsBinaryType: "blob", /** * @type string * @default '[hx-disable], [data-hx-disable]' */ disableSelector: "[hx-disable], [data-hx-disable]", /** * @type {'auto' | 'instant' | 'smooth'} * @default 'instant' */ scrollBehavior: "instant", /** * If the focused element should be scrolled into view. * @type boolean * @default false */ defaultFocusScroll: !1, /** * If set to true htmx will include a cache-busting parameter in GET requests to avoid caching partial responses by the browser * @type boolean * @default false */ getCacheBusterParam: !1, /** * If set to true, htmx will use the View Transition API when swapping in new content. * @type boolean * @default false */ globalViewTransitions: !1, /** * htmx will format requests with these methods by encoding their parameters in the URL, not the request body * @type {(HttpVerb)[]} * @default ['get', 'delete'] */ methodsThatUseUrlParams: ["get", "delete"], /** * If set to true, disables htmx-based requests to non-origin hosts. * @type boolean * @default false */ selfRequestsOnly: !0, /** * If set to true htmx will not update the title of the document when a title tag is found in new content * @type boolean * @default false */ ignoreTitle: !1, /** * Whether the target of a boosted element is scrolled into the viewport. * @type boolean * @default true */ scrollIntoViewOnBoost: !0, /** * The cache to store evaluated trigger specifications into. * You may define a simple object to use a never-clearing cache, or implement your own system using a [proxy object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Proxy) * @type {Object|null} * @default null */ triggerSpecsCache: null, /** @type boolean */ disableInheritance: !1, /** @type HtmxResponseHandlingConfig[] */ responseHandling: [ { code: "204", swap: !1 }, { code: "[23]..", swap: !0 }, { code: "[45]..", swap: !1, error: !0 } ], /** * Whether to process OOB swaps on elements that are nested within the main response element. * @type boolean * @default true */ allowNestedOobSwaps: !0 }, /** @type {typeof parseInterval} */ parseInterval: null, /** @type {typeof internalEval} */ _: null, version: "2.0.4" }; htmx.onLoad = onLoadHelper, htmx.process = processNode, htmx.on = addEventListenerImpl, htmx.off = removeEventListenerImpl, htmx.trigger = triggerEvent, htmx.ajax = ajaxHelper, htmx.find = find, htmx.findAll = findAll, htmx.closest = closest, htmx.remove = removeElement, htmx.addClass = addClassToElement, htmx.removeClass = removeClassFromElement, htmx.toggleClass = toggleClassOnElement, htmx.takeClass = takeClassForElement, htmx.swap = swap, htmx.defineExtension = defineExtension, htmx.removeExtension = removeExtension, htmx.logAll = logAll, htmx.logNone = logNone, htmx.parseInterval = parseInterval, htmx._ = internalEval; const internalAPI = { addTriggerHandler, bodyContains, canAccessLocalStorage, findThisElement, filterValues, swap, hasAttribute, getAttributeValue, getClosestAttributeValue, getClosestMatch, getExpressionVars, getHeaders, getInputValues, getInternalData, getSwapSpecification, getTriggerSpecs, getTarget, makeFragment, mergeObjects, makeSettleInfo, oobSwap, querySelectorExt, settleImmediately, shouldCancel, triggerEvent, triggerErrorEvent, withExtensions }, VERBS = ["get", "post", "put", "delete", "patch"], VERB_SELECTOR = VERBS.map(function(e) { return "[hx-" + e + "], [data-hx-" + e + "]"; }).join(", "); function parseInterval(e) { if (e == null) return; let t = NaN; return e.slice(-2) == "ms" ? t = parseFloat(e.slice(0, -2)) : e.slice(-1) == "s" ? t = parseFloat(e.slice(0, -1)) * 1e3 : e.slice(-1) == "m" ? t = parseFloat(e.slice(0, -1)) * 1e3 * 60 : t = parseFloat(e), isNaN(t) ? void 0 : t; } function getRawAttribute(e, t) { return e instanceof Element && e.getAttribute(t); } function hasAttribute(e, t) { return !!e.hasAttribute && (e.hasAttribute(t) || e.hasAttribute("data-" + t)); } function getAttributeValue(e, t) { return getRawAttribute(e, t) || getRawAttribute(e, "data-" + t); } function parentElt(e) { const t = e.parentElement; return !t && e.parentNode instanceof ShadowRoot ? e.parentNode : t; } function getDocument() { return document; } function getRootNode(e, t) { return e.getRootNode ? e.getRootNode({ composed: t }) : getDocument(); } function getClosestMatch(e, t) { for (; e && !t(e); ) e = parentElt(e); return e || null; } function getAttributeValueWithDisinheritance(e, t, n) { const r = getAttributeValue(t, n), o = getAttributeValue(t, "hx-disinherit"); var i = getAttributeValue(t, "hx-inherit"); if (e !== t) { if (htmx.config.disableInheritance) return i && (i === "*" || i.split(" ").indexOf(n) >= 0) ? r : null; if (o && (o === "*" || o.split(" ").indexOf(n) >= 0)) return "unset"; } return r; } function getClosestAttributeValue(e, t) { let n = null; if (getClosestMatch(e, function(r) { return !!(n = getAttributeValueWithDisinheritance(e, asElement(r), t)); }), n !== "unset") return n; } function matches(e, t) { const n = e instanceof Element && (e.matches || e.matchesSelector || e.msMatchesSelector || e.mozMatchesSelector || e.webkitMatchesSelector || e.oMatchesSelector); return !!n && n.call(e, t); } function getStartTag(e) { const n = /<([a-z][^\/\0>\x20\t\r\n\f]*)/i.exec(e); return n ? n[1].toLowerCase() : ""; } function parseHTML(e) { return new DOMParser().parseFromString(e, "text/html"); } function takeChildrenFor(e, t) { for (; t.childNodes.length > 0; ) e.append(t.childNodes[0]); } function duplicateScript(e) { const t = getDocument().createElement("script"); return forEach(e.attributes, function(n) { t.setAttribute(n.name, n.value); }), t.textContent = e.textContent, t.async = !1, htmx.config.inlineScriptNonce && (t.nonce = htmx.config.inlineScriptNonce), t; } function isJavaScriptScriptNode(e) { return e.matches("script") && (e.type === "text/javascript" || e.type === "module" || e.type === ""); } function normalizeScriptTags(e) { Array.from(e.querySelectorAll("script")).forEach( /** @param {HTMLScriptElement} script */ (t) => { if (isJavaScriptScriptNode(t)) { const n = duplicateScript(t), r = t.parentNode; try { r.insertBefore(n, t); } catch (o) { logError(o); } finally { t.remove(); } } } ); } function makeFragment(e) { const t = e.replace(/<head(\s[^>]*)?>[\s\S]*?<\/head>/i, ""), n = getStartTag(t); let r; if (n === "html") { r = /** @type DocumentFragmentWithTitle */ new DocumentFragment(); const i = parseHTML(e); takeChildrenFor(r, i.body), r.title = i.title; } else if (n === "body") { r = /** @type DocumentFragmentWithTitle */ new DocumentFragment(); const i = parseHTML(t); takeChildrenFor(r, i.body), r.title = i.title; } else { const i = parseHTML('<body><template class="internal-htmx-wrapper">' + t + "</template></body>"); r = /** @type DocumentFragmentWithTitle */ i.querySelector("template").content, r.title = i.title; var o = r.querySelector("title"); o && o.parentNode === r && (o.remove(), r.title = o.innerText); } return r && (htmx.config.allowScriptTags ? normalizeScriptTags(r) : r.querySelectorAll("script").forEach((i) => i.remove())), r; } function maybeCall(e) { e && e(); } function isType(e, t) { return Object.prototype.toString.call(e) === "[object " + t + "]"; } function isFunction(e) { return typeof e == "function"; } function isRawObject(e) { return isType(e, "Object"); } function getInternalData(e) { const t = "htmx-internal-data"; let n = e[t]; return n || (n = e[t] = {}), n; } function toArray(e) { const t = []; if (e) for (let n = 0; n < e.length; n++) t.push(e[n]); return t; } function forEach(e, t) { if (e) for (let n = 0; n < e.length; n++) t(e[n]); } function isScrolledIntoView(e) { const t = e.getBoundingClientRect(), n = t.top, r = t.bottom; return n < window.innerHeight && r >= 0; } function bodyContains(e) { return e.getRootNode({ composed: !0 }) === document; } function splitOnWhitespace(e) { return e.trim().split(/\s+/); } function mergeObjects(e, t) { for (const n in t) t.hasOwnProperty(n) && (e[n] = t[n]); return e; } function parseJSON(e) { try { return JSON.parse(e); } catch (t) { return logError(t), null; } } function canAccessLocalStorage() { const e = "htmx:localStorageTest"; try { return localStorage.setItem(e, e), localStorage.removeItem(e), !0; } catch { return !1; } } function normalizePath(e) { try { const t = new URL(e); return t && (e = t.pathname + t.search), /^\/$/.test(e) || (e = e.replace(/\/+$/, "")), e; } catch { return e; } } function internalEval(str) { return maybeEval(getDocument().body, function() { return eval(str); }); } function onLoadHelper(e) { return htmx.on( "htmx:load", /** @param {CustomEvent} evt */ function(n) { e(n.detail.elt); } ); } function logAll() { htmx.logger = function(e, t, n) { console && console.log(t, e, n); }; } function logNone() { htmx.logger = null; } function find(e, t) { return typeof e != "string" ? e.querySelector(t) : find(getDocument(), e); } function findAll(e, t) { return typeof e != "string" ? e.querySelectorAll(t) : findAll(getDocument(), e); } function getWindow() { return window; } function removeElement(e, t) { e = resolveTarget(e), t ? getWindow().setTimeout(function() { removeElement(e), e = null; }, t) : parentElt(e).removeChild(e); } function asElement(e) { return e instanceof Element ? e : null; } function asHtmlElement(e) { return e instanceof HTMLElement ? e : null; } function asString(e) { return typeof e == "string" ? e : null; } function asParentNode(e) { return e instanceof Element || e instanceof Document || e instanceof DocumentFragment ? e : null; } function addClassToElement(e, t, n) { e = asElement(resolveTarget(e)), e && (n ? getWindow().setTimeout(function() { addClassToElement(e, t), e = null; }, n) : e.classList && e.classList.add(t)); } function removeClassFromElement(e, t, n) { let r = asElement(resolveTarget(e)); r && (n ? getWindow().setTimeout(function() { removeClassFromElement(r, t), r = null; }, n) : r.classList && (r.classList.remove(t), r.classList.length === 0 && r.removeAttribute("class"))); } function toggleClassOnElement(e, t) { e = resolveTarget(e), e.classList.toggle(t); } function takeClassForElement(e, t) { e = resolveTarget(e), forEach(e.parentElement.children, function(n) { removeClassFromElement(n, t); }), addClassToElement(asElement(e), t); } function closest(e, t) { if (e = asElement(resolveTarget(e)), e && e.closest) return e.closest(t); do if (e == null || matches(e, t)) return e; while (e = e && asElement(parentElt(e))); return null; } function startsWith(e, t) { return e.substring(0, t.length) === t; } function endsWith(e, t) { return e.substring(e.length - t.length) === t; } function normalizeSelector(e) { const t = e.trim(); return startsWith(t, "<") && endsWith(t, "/>") ? t.substring(1, t.length - 2) : t; } function querySelectorAllExt(e, t, n) { if (t.indexOf("global ") === 0) return querySelectorAllExt(e, t.slice(7), !0); e = resolveTarget(e); const r = []; { let s = 0, a = 0; for (let u = 0; u < t.length; u++) { const l = t[u]; if (l === "," && s === 0) { r.push(t.substring(a, u)), a = u + 1; continue; } l === "<" ? s++ : l === "/" && u < t.length - 1 && t[u + 1] === ">" && s--; } a < t.length && r.push(t.substring(a)); } const o = [], i = []; for (; r.length > 0; ) { const s = normalizeSelector(r.shift()); let a; s.indexOf("closest ") === 0 ? a = closest(asElement(e), normalizeSelector(s.substr(8))) : s.indexOf("find ") === 0 ? a = find(asParentNode(e), normalizeSelector(s.substr(5))) : s === "next" || s === "nextElementSibling" ? a = asElement(e).nextElementSibling : s.indexOf("next ") === 0 ? a = scanForwardQuery(e, normalizeSelector(s.substr(5)), !!n) : s === "previous" || s === "previousElementSibling" ? a = asElement(e).previousElementSibling : s.indexOf("previous ") === 0 ? a = scanBackwardsQuery(e, normalizeSelector(s.substr(9)), !!n) : s === "document" ? a = document : s === "window" ? a = window : s === "body" ? a = document.body : s === "root" ? a = getRootNode(e, !!n) : s === "host" ? a = /** @type ShadowRoot */ e.getRootNode().host : i.push(s), a && o.push(a); } if (i.length > 0) { const s = i.join(","), a = asParentNode(getRootNode(e, !!n)); o.push(...toArray(a.querySelectorAll(s))); } return o; } var scanForwardQuery = function(e, t, n) { const r = asParentNode(getRootNode(e, n)).querySelectorAll(t); for (let o = 0; o < r.length; o++) { const i = r[o]; if (i.compareDocumentPosition(e) === Node.DOCUMENT_POSITION_PRECEDING) return i; } }, scanBackwardsQuery = function(e, t, n) { const r = asParentNode(getRootNode(e, n)).querySelectorAll(t); for (let o = r.length - 1; o >= 0; o--) { const i = r[o]; if (i.compareDocumentPosition(e) === Node.DOCUMENT_POSITION_FOLLOWING) return i; } }; function querySelectorExt(e, t) { return typeof e != "string" ? querySelectorAllExt(e, t)[0] : querySelectorAllExt(getDocument().body, e)[0]; } function resolveTarget(e, t) { return typeof e == "string" ? find(asParentNode(t) || document, e) : e; } function processEventArgs(e, t, n, r) { return isFunction(t) ? { target: getDocument().body, event: asString(e), listener: t, options: n } : { target: resolveTarget(e), event: asString(t), listener: n, options: r }; } function addEventListenerImpl(e, t, n, r) { return ready(function() { const i = processEventArgs(e, t, n, r); i.target.addEventListener(i.event, i.listener, i.options); }), isFunction(t) ? t : n; } function removeEventListenerImpl(e, t, n) { return ready(function() { const r = processEventArgs(e, t, n); r.target.removeEventListener(r.event, r.listener); }), isFunction(t) ? t : n; } const DUMMY_ELT = getDocument().createElement("output"); function findAttributeTargets(e, t) { const n = getClosestAttributeValue(e, t); if (n) { if (n === "this") return [findThisElement(e, t)]; { const r = querySelectorAllExt(e, n); return r.length === 0 ? (logError('The selector "' + n + '" on ' + t + " returned no matches!"), [DUMMY_ELT]) : r; } } } function findThisElement(e, t) { return asElement(getClosestMatch(e, function(n) { return getAttributeValue(asElement(n), t) != null; })); } function getTarget(e) { const t = getClosestAttributeValue(e, "hx-target"); return t ? t === "this" ? findThisElement(e, "hx-target") : querySelectorExt(e, t) : getInternalData(e).boosted ? getDocument().body : e; } function shouldSettleAttribute(e) { const t = htmx.config.attributesToSettle; for (let n = 0; n < t.length; n++) if (e === t[n]) return !0; return !1; } function cloneAttributes(e, t) { forEach(e.attributes, function(n) { !t.hasAttribute(n.name) && shouldSettleAttribute(n.name) && e.removeAttribute(n.name); }), forEach(t.attributes, function(n) { shouldSettleAttribute(n.name) && e.setAttribute(n.name, n.value); }); } function isInlineSwap(e, t) { const n = getExtensions(t); for (let r = 0; r < n.length; r++) { const o = n[r]; try { if (o.isInlineSwap(e)) return !0; } catch (i) { logError(i); } } return e === "outerHTML"; } function oobSwap(e, t, n, r) { r = r || getDocument(); let o = "#" + getRawAttribute(t, "id"), i = "outerHTML"; e === "true" || (e.indexOf(":") > 0 ? (i = e.substring(0, e.indexOf(":")), o = e.substring(e.indexOf(":") + 1)) : i = e), t.removeAttribute("hx-swap-oob"), t.removeAttribute("data-hx-swap-oob"); const s = querySelectorAllExt(r, o, !1); return s ? (forEach( s, function(a) { let u; const l = t.cloneNode(!0); u = getDocument().createDocumentFragment(), u.appendChild(l), isInlineSwap(i, a) || (u = asParentNode(l)); const f = { shouldSwap: !0, target: a, fragment: u }; triggerEvent(a, "htmx:oobBeforeSwap", f) && (a = f.target, f.shouldSwap && (handlePreservedElements(u), swapWithStyle(i, a, a, u, n), restorePreservedElements()), forEach(n.elts, function(c) { triggerEvent(c, "htmx:oobAfterSwap", f); })); } ), t.parentNode.removeChild(t)) : (t.parentNode.removeChild(t), triggerErrorEvent(getDocument().body, "htmx:oobErrorNoTarget", { content: t })), e; } function restorePreservedElements() { const e = find("#--htmx-preserve-pantry--"); if (e) { for (const t of [...e.children]) { const n = find("#" + t.id); n.parentNode.moveBefore(t, n), n.remove(); } e.remove(); } } function handlePreservedElements(e) { forEach(findAll(e, "[hx-preserve], [data-hx-preserve]"), function(t) { const n = getAttributeValue(t, "id"), r = getDocument().getElementById(n); if (r != null) if (t.moveBefore) { let o = find("#--htmx-preserve-pantry--"); o == null && (getDocument().body.insertAdjacentHTML("afterend", "<div id='--htmx-preserve-pantry--'></div>"), o = find("#--htmx-preserve-pantry--")), o.moveBefore(r, null); } else t.parentNode.replaceChild(r, t); }); } function handleAttributes(e, t, n) { forEach(t.querySelectorAll("[id]"), function(r) { const o = getRawAttribute(r, "id"); if (o && o.length > 0) { const i = o.replace("'", "\\'"), s = r.tagName.replace(":", "\\:"), a = asParentNode(e), u = a && a.querySelector(s + "[id='" + i + "']"); if (u && u !== a) { const l = r.cloneNode(); cloneAttributes(r, u), n.tasks.push(function() { cloneAttributes(r, l); }); } } }); } function makeAjaxLoadTask(e) { return function() { removeClassFromElement(e, htmx.config.addedClass), processNode(asElement(e)), processFocus(asParentNode(e)), triggerEvent(e, "htmx:load"); }; } function processFocus(e) { const t = "[autofocus]", n = asHtmlElement(matches(e, t) ? e : e.querySelector(t)); n != null && n.focus(); } function insertNodesBefore(e, t, n, r) { for (handleAttributes(e, n, r); n.childNodes.length > 0; ) { const o = n.firstChild; addClassToElement(asElement(o), htmx.config.addedClass), e.insertBefore(o, t), o.nodeType !== Node.TEXT_NODE && o.nodeType !== Node.COMMENT_NODE && r.tasks.push(makeAjaxLoadTask(o)); } } function stringHash(e, t) { let n = 0; for (; n < e.length; ) t = (t << 5) - t + e.charCodeAt(n++) | 0; return t; } function attributeHash(e) { let t = 0; if (e.attributes) for (let n = 0; n < e.attributes.length; n++) { const r = e.attributes[n]; r.value && (t = stringHash(r.name, t), t = stringHash(r.value, t)); } return t; } function deInitOnHandlers(e) { const t = getInternalData(e); if (t.onHandlers) { for (let n = 0; n < t.onHandlers.length; n++) { const r = t.onHandlers[n]; removeEventListenerImpl(e, r.event, r.listener); } delete t.onHandlers; } } function deInitNode(e) { const t = getInternalData(e); t.timeout && clearTimeout(t.timeout), t.listenerInfos && forEach(t.listenerInfos, function(n) { n.on && removeEventListenerImpl(n.on, n.trigger, n.listener); }), deInitOnHandlers(e), forEach(Object.keys(t), function(n) { n !== "firstInitCompleted" && delete t[n]; }); } function cleanUpElement(e) { triggerEvent(e, "htmx:beforeCleanupElement"), deInitNode(e), e.children && forEach(e.children, function(t) { cleanUpElement(t); }); } function swapOuterHTML(e, t, n) { if (e instanceof Element && e.tagName === "BODY") return swapInnerHTML(e, t, n); let r; const o = e.previousSibling, i = parentElt(e); if (i) { for (insertNodesBefore(i, e, t, n), o == null ? r = i.firstChild : r = o.nextSibling, n.elts = n.elts.filter(function(s) { return s !== e; }); r && r !== e; ) r instanceof Element && n.elts.push(r), r = r.nextSibling; cleanUpElement(e), e instanceof Element ? e.remove() : e.parentNode.removeChild(e); } } function swapAfterBegin(e, t, n) { return insertNodesBefore(e, e.firstChild, t, n); } function swapBeforeBegin(e, t, n) { return insertNodesBefore(parentElt(e), e, t, n); } function swapBeforeEnd(e, t, n) { return insertNodesBefore(e, null, t, n); } function swapAfterEnd(e, t, n) { return insertNodesBefore(parentElt(e), e.nextSibling, t, n); } function swapDelete(e) { cleanUpElement(e); const t = parentElt(e); if (t) return t.removeChild(e); } function swapInnerHTML(e, t, n) { const r = e.firstChild; if (insertNodesBefore(e, r, t, n), r) { for (; r.nextSibling; ) cleanUpElement(r.nextSibling), e.removeChild(r.nextSibling); cleanUpElement(r), e.removeChild(r); } } function swapWithStyle(e, t, n, r, o) { switch (e) { case "none": return; case "outerHTML": swapOuterHTML(n, r, o); return; case "afterbegin": swapAfterBegin(n, r, o); return; case "beforebegin": swapBeforeBegin(n, r, o); return; case "beforeend": swapBeforeEnd(n, r, o); return; case "afterend": swapAfterEnd(n, r, o); return; case "delete": swapDelete(n); return; default: var i = getExtensions(t); for (let s = 0; s < i.length; s++) { const a = i[s]; try { const u = a.handleSwap(e, n, r, o); if (u) { if (Array.isArray(u)) for (let l = 0; l < u.length; l++) { const f = u[l]; f.nodeType !== Node.TEXT_NODE && f.nodeType !== Node.COMMENT_NODE && o.tasks.push(makeAjaxLoadTask(f)); } return; } } catch (u) { logError(u); } } e === "innerHTML" ? swapInnerHTML(n, r, o) : swapWithStyle(htmx.config.defaultSwapStyle, t, n, r, o); } } function findAndSwapOobElements(e, t, n) { var r = findAll(e, "[hx-swap-oob], [data-hx-swap-oob]"); return forEach(r, function(o) { if (htmx.config.allowNestedOobSwaps || o.parentElement === null) { const i = getAttributeValue(o, "hx-swap-oob"); i != null && oobSwap(i, o, t, n); } else o.removeAttribute("hx-swap-oob"), o.removeAttribute("data-hx-swap-oob"); }), r.length > 0; } function swap(e, t, n, r) { r || (r = {}), e = resolveTarget(e); const o = r.contextElement ? getRootNode(r.contextElement, !1) : getDocument(), i = document.activeElement; let s = {}; try { s = { elt: i, // @ts-ignore start: i ? i.selectionStart : null, // @ts-ignore end: i ? i.selectionEnd : null }; } catch { } const a = makeSettleInfo(e); if (n.swapStyle === "textContent") e.textContent = t; else { let l = makeFragment(t); if (a.title = l.title, r.selectOOB) { const f = r.selectOOB.split(","); for (let c = 0; c < f.length; c++) { const d = f[c].split(":", 2); let g = d[0].trim(); g.indexOf("#") === 0 && (g = g.substring(1)); const C = d[1] || "true", b = l.querySelector("#" + g); b && oobSwap(C, b, a, o); } } if (findAndSwapOobElements(l, a, o), forEach( findAll(l, "template"), /** @param {HTMLTemplateElement} template */ function(f) { f.content && findAndSwapOobElements(f.content, a, o) && f.remove(); } ), r.select) { const f = getDocument().createDocumentFragment(); forEach(l.querySelectorAll(r.select), function(c) { f.appendChild(c); }), l = f; } handlePreservedElements(l), swapWithStyle(n.swapStyle, r.contextElement, e, l, a), restorePreservedElements(); } if (s.elt && !bodyContains(s.elt) && getRawAttribute(s.elt, "id")) { const l = document.getElementById(getRawAttribute(s.elt, "id")), f = { preventScroll: n.focusScroll !== void 0 ? !n.focusScroll : !htmx.config.defaultFocusScroll }; if (l) { if (s.start && l.setSelectionRange) try { l.setSelectionRange(s.start, s.end); } catch { } l.focus(f); } } e.classList.remove(htmx.config.swappingClass), forEach(a.elts, function(l) { l.classList && l.classList.add(htmx.config.settlingClass), triggerEvent(l, "htmx:afterSwap", r.eventInfo); }), r.afterSwapCallback && r.afterSwapCallback(), n.ignoreTitle || handleTitle(a.title); const u = function() { if (forEach(a.tasks, function(l) { l.call(); }), forEach(a.elts, function(l) { l.classList && l.classList.remove(htmx.config.settlingClass), triggerEvent(l, "htmx:afterSettle", r.eventInfo); }), r.anchor) { const l = asElement(resolveTarget("#" + r.anchor)); l && l.scrollIntoView({ block: "start", behavior: "auto" }); } updateScrollState(a.elts, n), r.afterSettleCallback && r.afterSettleCallback(); }; n.settleDelay > 0 ? getWindow().setTimeout(u, n.settleDelay) : u(); } function handleTriggerHeader(e, t, n) { const r = e.getResponseHeader(t); if (r.indexOf("{") === 0) { const o = parseJSON(r); for (const i in o) if (o.hasOwnProperty(i)) { let s = o[i]; isRawObject(s) ? n = s.target !== void 0 ? s.target : n : s = { value: s }, triggerEvent(n, i, s); } } else { const o = r.split(","); for (let i = 0; i < o.length; i++) triggerEvent(n, o[i].trim(), []); } } const WHITESPACE_OR_COMMA = /[\s,]/, SYMBOL_START = /[_$a-zA-Z]/, SYMBOL_CONT = /[_$a-zA-Z0-9]/, STRINGISH_START = ['"', "'", "/"], NOT_WHITESPACE = /[^\s]/, COMBINED_SELECTOR_START = /[{(]/, COMBINED_SELECTOR_END = /[})]/; function tokenizeString(e) { const t = []; let n = 0; for (; n < e.length; ) { if (SYMBOL_START.exec(e.charAt(n))) { for (var r = n; SYMBOL_CONT.exec(e.charAt(n + 1)); ) n++; t.push(e.substring(r, n + 1)); } else if (STRINGISH_START.indexOf(e.charAt(n)) !== -1) { const o = e.charAt(n); var r = n; for (n++; n < e.length && e.charAt(n) !== o; ) e.charAt(n) === "\\" && n++, n++; t.push(e.substring(r, n + 1)); } else { const o = e.charAt(n); t.push(o); } n++; } return t; } function isPossibleRelativeReference(e, t, n) { return SYMBOL_START.exec(e.charAt(0)) && e !== "true" && e !== "false" && e !== "this" && e !== n && t !== "."; } function maybeGenerateConditional(e, t, n) { if (t[0] === "[") { t.shift(); let r = 1, o = " return (function(" + n + "){ return (", i = null; for (; t.length > 0; ) { const s = t[0]; if (s === "]") { if (r--, r === 0) { i === null && (o = o + "true"), t.shift(), o += ")})"; try { const a = maybeEval( e, function() { return Function(o)(); }, function() { return !0; } ); return a.source = o, a; } catch (a) { return triggerErrorEvent(getDocument().body, "htmx:syntax:error", { error: a, source: o }), null; } } } else s === "[" && r++; isPossibleRelativeReference(s, i, n) ? o += "((" + n + "." + s + ") ? (" + n + "." + s + ") : (window." + s + "))" : o = o + s, i = t.shift(); } } } function consumeUntil(e, t) { let n = ""; for (; e.length > 0 && !t.test(e[0]); ) n += e.shift(); return n; } function consumeCSSSelector(e) { let t; return e.length > 0 && COMBINED_SELECTOR_START.test(e[0]) ? (e.shift(), t = consumeUntil(e, COMBINED_SELECTOR_END).trim(), e.shift()) : t = consumeUntil(e, WHITESPACE_OR_COMMA), t; } const INPUT_SELECTOR = "input, textarea, select"; function parseAndCacheTrigger(e, t, n) { const r = [], o = tokenizeString(t); do { consumeUntil(o, NOT_WHITESPACE); const a = o.length, u = consumeUntil(o, /[,\[\s]/); if (u !== "") if (u === "every") { const l = { trigger: "every" }; consumeUntil(o, NOT_WHITESPACE), l.pollInterval = parseInterval(consumeUntil(o, /[,\[\s]/)), consumeUntil(o, NOT_WHITESPACE); var i = maybeGenerateConditional(e, o, "event"); i && (l.eventFilter = i), r.push(l); } else { const l = { trigger: u }; var i = maybeGenerateConditional(e, o, "event"); for (i && (l.eventFilter = i), consumeUntil(o, NOT_WHITESPACE); o.length > 0 && o[0] !== ","; ) { const c = o.shift(); if (c === "changed") l.changed = !0; else if (c === "once") l.once = !0; else if (c === "consume") l.consume = !0; else if (c === "delay" && o[0] === ":") o.shift(), l.delay = parseInterval(consumeUntil(o, WHITESPACE_OR_COMMA)); else if (c === "from" && o[0] === ":") { if (o.shift(), COMBINED_SELECTOR_START.test(o[0])) var s = consumeCSSSelector(o); else { var s = consumeUntil(o, WHITESPACE_OR_COMMA); if (s === "closest" || s === "find" || s === "next" || s === "previous") { o.shift(); const g = consumeCSSSelector(o); g.length > 0 && (s += " " + g); } } l.from = s; } else c === "target" && o[0] === ":" ? (o.shift(), l.target = consumeCSSSelector(o)) : c === "throttle" && o[0] === ":" ? (o.shift(), l.throttle = parseInterval(consumeUntil(o, WHITESPACE_OR_COMMA))) : c === "queue" && o[0] === ":" ? (o.shift(), l.queue = consumeUntil(o, WHITESPACE_OR_COMMA)) : c === "root" && o[0] === ":" ? (o.shift(), l[c] = consumeCSSSelector(o)) : c === "threshold" && o[0] === ":" ? (o.shift(), l[c] = consumeUntil(o, WHITESPACE_OR_COMMA)) : triggerErrorEvent(e, "htmx:syntax:error", { token: o.shift() }); consumeUntil(o, NOT_WHITESPACE); } r.push(l); } o.length === a && triggerErrorEvent(e, "htmx:syntax:error", { token: o.shift() }), consumeUntil(o, NOT_WHITESPACE); } while (o[0] === "," && o.shift()); return n && (n[t] = r), r; } function getTriggerSpecs(e) { const t = getAttributeValue(e, "hx-trigger"); let n = []; if (t) { const r = htmx.config.triggerSpecsCache; n = r && r[t] || parseAndCacheTrigger(e, t, r); } return n.length > 0 ? n : matches(e, "form") ? [{ trigger: "submit" }] : matches(e, 'input[type="button"], input[type="submit"]') ? [{ trigger: "click" }] : matches(e, INPUT_SELECTOR) ? [{ trigger: "change" }] : [{ trigger: "click" }]; } function cancelPolling(e) { getInternalData(e).cancelled = !0; } function processPolling(e, t, n) { const r = getInternalData(e); r.timeout = getWindow().setTimeout(function() { bodyContains(e) && r.cancelled !== !0 && (maybeFilterEvent(n, e, makeEvent("hx:poll:trigger", { triggerSpec: n, target: e })) || t(e), processPolling(e, t, n)); }, n.pollInterval); } function isLocalLink(e) { return location.hostname === e.hostname && getRawAttribute(e, "href") && getRawAttribute(e, "href").indexOf("#") !== 0; } function eltIsDisabled(e) { return closest(e, htmx.config.disableSelector); } function boostElement(e, t, n) { if (e instanceof HTMLAnchorElement && isLocalLink(e) && (e.target === "" || e.target === "_self") || e.tagName === "FORM" && String(getRawAttribute(e, "method")).toLowerCase() !== "dialog") { t.boosted = !0; let r, o; if (e.tagName === "A") r = /** @type HttpVerb */ "get", o = getRawAttribute(e, "href"); else { const i = getRawAttribute(e, "method"); r = /** @type HttpVerb */ i ? i.toLowerCase() : "get", o = getRawAttribute(e, "action"), (o == null || o === "") && (o = getDocument().location.href), r === "get" && o.includes("?") && (o = o.replace(/\?[^#]+/, "")); } n.forEach(function(i) { addEventListener(e, function(s, a) { const u = asElement(s); if (eltIsDisabled(u)) { cleanUpElement(u); return; } issueAjaxRequest(r, o, u, a); }, t, i, !0); }); } } function shouldCancel(e, t) { const n = asElement(t); return n ? !!((e.type === "submit" || e.type === "click") && (n.tagName === "FORM" || matches(n, 'input[type="submit"], button') && (matches(n, "[form]") || closest(n, "form") !== null) || n instanceof HTMLAnchorElement && n.href && (n.getAttribute("href") === "#" || n.getAttribute("href").indexOf("#") !== 0))) : !1; } function ignoreBoostedAnchorCtrlClick(e, t) { return getInternalData(e).boosted && e instanceof HTMLAnchorElement && t.type === "click" && // @ts-ignore this will resolve to undefined for events that don't define those properties, which is fine (t.ctrlKey || t.metaKey); } function maybeFilterEvent(e, t, n) { const r = e.eventFilter; if (r) try { return r.call(t, n) !== !0; } catch (o) { const i = r.source; return triggerErrorEvent(getDocument().body, "htmx:eventFilter:error", { error: o, source: i }), !0; } return !1; } function addEventListener(e, t, n, r, o) { const i = getInternalData(e); let s; r.from ? s = querySelectorAllExt(e, r.from) : s = [e], r.changed && ("lastValue" in i || (i.lastValue = /* @__PURE__ */ new WeakMap()), s.forEach(function(a) { i.lastValue.has(r) || i.lastValue.set(r, /* @__PURE__ */ new WeakMap()), i.lastValue.get(r).set(a, a.value); })), forEach(s, function(a) { const u = function(l) { if (!bodyContains(e)) { a.removeEventListener(r.trigger, u); return; } if (ignoreBoostedAnchorCtrlClick(e, l) || ((o || shouldCancel(l, e)) && l.preventDefault(), maybeFilterEvent(r, e, l))) return; const f = getInternalData(l); if (f.triggerSpec = r, f.handledFor == null && (f.handledFor = []), f.handledFor.indexOf(e) < 0) { if (f.handledFor.push(e), r.consume && l.stopPropagation(), r.target && l.target && !matches(asElement(l.target), r.target)) return; if (r.once) { if (i.triggeredOnce) return; i.triggeredOnce = !0; } if (r.changed) { const c = event.target, d = c.value, g = i.lastValue.get(r); if (g.has(c) && g.get(c) === d) return; g.set(c, d); } if (i.delayed && clearTimeout(i.delayed), i.throttle) return; r.throttle > 0 ? i.throttle || (triggerEvent(e, "htmx:trigger"), t(e, l), i.throttle = getWindow().setTimeout(function() { i.throttle = null; }, r.throttle)) : r.delay > 0 ? i.delayed = getWindow().setTimeout(function() { triggerEvent(e, "htmx:trigger"), t(e, l); }, r.delay) : (triggerEvent(e, "htmx:trigger"), t(e, l)); } }; n.listenerInfos == null && (n.listenerInfos = []), n.listenerInfos.push({ trigger: r.trigger, listener: u, on: a }), a.addEventListener(r.trigger, u); }); } let windowIsScrolling = !1, scrollHandler = null; function initScrollHandler() { scrollHandler || (scrollHandler = function() { windowIsScrolling = !0; }, window.addEventListener("scroll", scrollHandler), window.addEventListener("resize", scrollHandler), setInterval(function() { windowIsScrolling && (windowIsScrolling = !1, forEach(getDocument().querySelectorAll("[hx-trigger*='revealed'],[data-hx-trigger*='revealed']"), function(e) { maybeReveal(e); })); }, 200)); } function maybeReveal(e) { !hasAttribute(e, "data-hx-revealed") && isScrolledIntoView(e) && (e.setAttribute("data-hx-revealed", "true"), getInternalData(e).initHash ? triggerEvent(e, "revealed") : e.addEventListener("htmx:afterProcessNode", function() { triggerEvent(e, "revealed"); }, { once: !0 })); } function loadImmediately(e, t, n, r) { const o = function() { n.loaded || (n.loaded = !0, triggerEvent(e, "htmx:trigger"), t(e)); }; r > 0 ? getWindow().setTimeout(o, r) : o(); } function processVerbs(e, t, n) { let r = !1; return forEach(VERBS, function(o) { if (hasAttribute(e, "hx-" + o)) { const i = getAttributeValue(e, "hx-" + o); r = !0, t.path = i, t.verb = o, n.forEach(function(s) { addTriggerHandler(e, s, t, function(a, u) { const l = asElement(a); if (closest(l, htmx.config.disableSelector)) { cleanUpElement(l); return; } issueAjaxRequest(o, i, l, u); }); }); } }), r; } function addTriggerHandler(e, t, n, r) { if (t.trigger === "revealed") initScrollHandler(), addEventListener(e, r, n, t), maybeReveal(asElement(e)); else if (t.trigger === "intersect") { const o = {}; t.root && (o.root = querySelectorExt(e, t.root)), t.threshold && (o.threshold = parseFloat(t.threshold)), new IntersectionObserver(function(s) { for (let a = 0; a < s.length; a++) if (s[a].isIntersecting) { triggerEvent(e, "intersect"); break; } }, o).observe(asElement(e)), addEventListener(asElement(e), r, n, t); } else !n.firstInitCompleted && t.trigger === "load" ? maybeFilterEvent(t, e, makeEvent("load", { elt: e })) || loadImmediately(asElement(e), r, n, t.delay) : t.pollInterval > 0 ? (n.polling = !0, processPolling(asElement(e), r, t)) : addEventListener(e, r, n, t); } function shouldProcessHxOn(e) { const t = asElement(e); if (!t) return !1; const n = t.attributes; for (let r = 0; r < n.length; r++) { const o = n[r].name; if (startsWith(o, "hx-on:") || startsWith(o, "data-hx-on:") || startsWith(o, "hx-on-") || startsWith(o, "data-hx-on-")) return !0; } return !1; } const HX_ON_QUERY = new XPathEvaluator().createExpression('.//*[@*[ starts-with(name(), "hx-on:") or starts-with(name(), "data-hx-on:") or starts-with(name(), "hx-on-") or starts-with(name(), "data-hx-on-") ]]'); function processHXOnRoot(e, t) { shouldProcessHxOn(e) && t.push(asElement(e)); const n = HX_ON_QUERY.evaluate(e); let r = null; for (; r = n.iterateNext(); ) t.push(asElement(r)); } function findHxOnWildcardElements(e) { const t = []; if (e instanceof DocumentFragment) for (const n of e.childNodes) processHXOnRoot(n, t); else processHXOnRoot(e, t); return t; } function findElementsToProcess(e) { if (e.querySelectorAll) { const n = ", [hx-boost] a, [data-hx-boost] a, a[hx-boost], a[data-hx-boost]", r = []; for (const i in extensions) { const s = extensions[i]; if (s.getSelectors) { var t = s.getSelectors(); t && r.push(t); } } return e.querySelectorAll(VERB_SELECTOR + n + ", form, [type='submit'], [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]" + r.flat().map((i) => ", " + i).join("")); } else return []; } function maybeSetLastButtonClicked(e) { const t = ( /** @type {HTMLButtonElement|HTMLInputElement} */ closest(asElement(e.target), "button, input[type='submit']") ), n = getRelatedFormData(e); n && (n.lastButtonClicked = t); } function maybeUnsetLastButtonClicked(e) { const t = getRelatedFormData(e); t && (t.lastButtonClicked = null); } function getRelatedFormData(e) { const t = closest(asElement(e.target), "button, input[type='submit']"); if (!t) return; const n = resolveTarget("#" + getRawAttribute(t, "form"), t.getRootNode()) || closest(t, "form"); if (n) return getInternalData(n); } function initButtonTracking(e) { e.addEventListener("click", maybeSetLastButtonClicked), e.addEventListener("focusin", maybeSetLastButtonClicked), e.addEventListener("focusout", maybeUnsetLastButtonClicked); } function addHxOnEventHandler(e, t, n) { const r = getInternalData(e); Array.isArray(r.onHandlers) || (r.onHandlers = []); let o; const i = function(s) { maybeEval(e, function() { eltIsDisabled(e) || (o || (o = new Function("event", n)), o.call(e, s)); }); }; e.addEventListener(t, i), r.onHandlers.push({ event: t, listener: i }); } function processHxOnWildcard(e) { deInitOnHandlers(e); for (let t = 0; t < e.attributes.length; t++) { const n = e.attributes[t].name, r = e.attributes[t].value; if (startsWith(n, "hx-on") || startsWith(n, "data-hx-on")) { const o = n.indexOf("-on") + 3, i = n.slice(o, o + 1); if (i === "-" || i === ":") { let s = n.slice(o + 1); startsWith(s, ":") ? s = "htmx" + s : startsWith(s, "-") ? s = "htmx:" + s.slice(1) : startsWith(s, "htmx-") && (s = "htmx:" + s.slice(5)), addHxOnEventHandler(e, s, r); } } } } function initNode(e) { if (closest(e, htmx.config.disableSelector)) { cleanUpElement(e); return; } const t = getInternalData(e), n = attributeHash(e); if (t.initHash !== n) { deInitNode(e), t.initHash = n, triggerEvent(e