1 line
33 KiB
JavaScript
1 line
33 KiB
JavaScript
var htmx=(()=>{class e{#e=null;#t=[];issue(e,t){return e.queueStrategy=t,this.#e?"replace"===t||"abort"!==t&&"abort"===this.#e.queueStrategy?(this.#t.forEach(e=>e.status="dropped"),this.#t=[],this.#e.request?.abort?.(),this.#e=e,!0):("queue all"===t?(this.#t.push(e),e.status="queued"):"drop"===t?e.status="dropped":"queue last"===t?(this.#t.forEach(e=>e.status="dropped"),this.#t=[e],e.status="queued"):0===this.#t.length&&"abort"!==t?(this.#t.push(e),e.status="queued"):e.status="dropped",!1):(this.#e=e,!0)}finish(){this.#e=null}next(){return this.#t.shift()}abort(){this.#e?.request?.abort?.()}more(){return this.#t?.length}}return new class{#r=new Map;#i="";#s=new Set;#n;#a;#o="a,form";#l=["get","post","put","patch","delete"];#h;#u;#c;#d;constructor(){this.#f(),this.#m(),this.#a=`[${this.#p("hx-action")}],[${this.#p("hx-get")}],[${this.#p("hx-post")}],[${this.#p("hx-put")}],[${this.#p("hx-patch")}],[${this.#p("hx-delete")}]`,this.#h=(new XPathEvaluator).createExpression(`.//*[@*[ starts-with(name(), "${this.#p("hx-on")}")]]`),this.#n={attributeValue:this.#g.bind(this),parseTriggerSpecs:this.#b.bind(this),determineMethodAndAction:this.#x.bind(this),createRequestContext:this.#y.bind(this),collectFormData:this.#v.bind(this),getAttributeObject:this.#S.bind(this),insertContent:this.#E.bind(this),morph:this.#w.bind(this),isSoftMatch:this.#C.bind(this),onTrigger:this.#A.bind(this),htmxProp:this.#q.bind(this),triggerHtmxEvent:this.#T.bind(this)};let e=()=>{this.#M(),this.process(document.body)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):setTimeout(e)}#f(){this.version="4.0.0-alpha8",this.config={logAll:!1,prefix:"",transitions:!1,history:!0,mode:"same-origin",defaultSwap:"innerHTML",defaultFocusScroll:!1,indicatorClass:"htmx-indicator",requestClass:"htmx-request",includeIndicatorCSS:!0,defaultTimeout:6e4,extensions:"",morphIgnore:["data-htmx-powered"],morphScanLimit:10,noSwap:[204,304],implicitInheritance:!1,defaultSettleDelay:1};let e=document.querySelector('meta[name="htmx-config"]');e&&this.#N(e.content,this.config),this.#i=this.config.extensions}#m(){if(!1!==this.config.includeIndicatorCSS){let e="";this.config.inlineStyleNonce&&(e=` nonce="${this.config.inlineStyleNonce}"`);let t=this.config.indicatorClass,r=this.config.requestClass;document.head.insertAdjacentHTML("beforeend",`<style${e}>.${t}{opacity:0;visibility: hidden} .${r} .${t}, .${r}.${t}{opacity:1;visibility: visible;transition: opacity 200ms ease-in}</style>`)}}registerExtension(e,t){return!(this.#i&&!this.#i.split(/,\s*/).includes(e))&&(!this.#s.has(e)&&(this.#s.add(e),t.init&&t.init(this.#n),void Object.entries(t).forEach(([e,t])=>{this.#r.get(e)?.push(t)||this.#r.set(e,[t])})))}#H(e){return!e.closest||null!=e.closest(`[${this.#p("hx-ignore")}]`)}#p(e){return this.config.prefix?e.replace("hx-",this.config.prefix):e}#I(e,t){let r=[...e.querySelectorAll?.(t)??[]];return e.matches?.(t)&&r.unshift(e),r}#O(e){return"before"===e?"beforebegin":"after"===e?"afterend":"prepend"===e?"afterbegin":"append"===e?"beforeend":e}#L(e,t){let r=[];return this.#g(e,t,void 0,(e,t)=>{e?.split(/\s*,\s*/).includes("this")&&r.push(t)}),r}#g(e,t,r,i){let s=t,n=(t=this.#k(this.#p(t)))+this.#k(":append"),a=t+(this.config.implicitInheritance?"":this.#k(":inherited")),o=t+this.#k(":inherited:append");if(e.hasAttribute(t)){let r=e.getAttribute(t);return i?i(r,e):r}if(e.hasAttribute(a)){let t=e.getAttribute(a);return i?i(t,e):t}if(e.hasAttribute(n)||e.hasAttribute(o)){let t=e.getAttribute(n)||e.getAttribute(o),r=e.parentNode?.closest?.(`[${CSS.escape(a)}],[${CSS.escape(o)}]`);if(i&&i(t,e),r){let e=this.#g(r,s,void 0,i);return e?(e+","+t).replace(/[{}]/g,""):t}return t}let l=e.parentNode?.closest?.(`[${CSS.escape(a)}],[${CSS.escape(o)}]`);if(l){let r=this.#g(l,s,void 0,i);return!i&&r&&this.config.implicitInheritance&&this.#R(e,"htmx:after:implicitInheritance",{elt:e,name:t,parent:l}),r}return r}#j(e){if(!e)return{};if("{"===e[0])return JSON.parse(e);return[...e.matchAll(/(?:"([^"]+)"|([^\s,:]+))(?:\s*:\s*(?:"([^"]*)"|'([^']*)'|<([^>]+)\/>|([^\s,]+)))?(?=\s|,|$)/g)].reduce((e,t)=>{let r=(t[1]??t[2]).split("."),i=(t[3]??t[4]??t[5]??t[6]??"true").trim();return"true"===i?i=!0:"false"===i?i=!1:/^\d+$/.test(i)&&(i=parseInt(i)),r.some(e=>this.#V(e))||(r.slice(0,-1).reduce((e,t)=>e[t]??={},e)[r.at(-1)]=i),e},{})}#V(e){return"#proto#"===e||"constructor"===e||"prototype"===e}#N(e,t){let r=this.#j(e);for(let e in r){if(this.#V(e))continue;let i=r[e];i&&"object"==typeof i&&!Array.isArray(i)&&t[e]?Object.assign(t[e],i):t[e]=i}return t}#b(e){return e.split(",").map(e=>{let t=e.match(/^\s*(\S+\[[^\]]*\]|\S+)\s*(.*?)\s*$/);if(!t||!t[1])return null;if(t[1].includes("[")&&!t[1].includes("]"))throw"unterminated:"+t[1];let r=t[2]?this.#j(t[2]):{};return r.name=t[1],r}).filter(e=>e)}#x(e,t){if(this.#P(e))return this.#B(e,t);{let t=this.#g(e,"hx-method")||"GET",r=this.#g(e,"hx-action");if(!r)for(let i of this.#l){let s=this.#g(e,"hx-"+i);if(null!=s){r=s,t=i;break}}return t=t.toUpperCase(),{action:r,method:t}}}#B(e,t){if(e.matches("a"))return{action:e.getAttribute("href"),method:"GET"};return{action:t.submitter?.getAttribute?.("formAction")||e.getAttribute("action"),method:(t.submitter?.getAttribute?.("formMethod")||e.getAttribute("method")||"GET").toUpperCase()}}#q(e){return e._htmx||(e._htmx={listeners:[],triggerSpecs:[]},e.setAttribute("data-htmx-powered","true")),e._htmx}#$(e){if(this.#_(e)&&this.#T(e,"htmx:before:init",{},!0)){let t=this.#q(e);t.initialized=!0,t.eventHandler=this.#D(e),this.#F(e),this.#z(e),this.#T(e,"htmx:after:init",{},!0)}}#D(e){return async t=>{try{let r=this.#y(e,t);await this.#U(r)}catch(e){console.error(e)}}}#y(e,t){let{action:r,method:i}=this.#x(e,t),[s,n]=(r||"").split("#"),a=new AbortController,o={sourceElement:e,sourceEvent:t,status:"created",select:this.#g(e,"hx-select"),selectOOB:this.#g(e,"hx-select-oob"),target:this.#g(e,"hx-target"),swap:this.#g(e,"hx-swap")??this.config.defaultSwap,push:this.#g(e,"hx-push-url"),replace:this.#g(e,"hx-replace-url"),transition:this.config.transitions,confirm:this.#g(e,"hx-confirm"),request:{validate:"true"===this.#g(e,"hx-validate",!e.matches("form")||e.noValidate||t.submitter?.formNoValidate?"false":"true"),action:s,anchor:n,method:i,headers:this.#W(e),abort:a.abort.bind(a),credentials:"same-origin",signal:a.signal,mode:this.config.mode}};e._htmx?.boosted&&this.#N(e._htmx.boosted,o),o.target=this.#Q(e,o.target);let l=this.#g(e,"hx-config");return l&&this.#N(l,o.request),o}#J(e){return`${e.tagName.toLowerCase()}${e.id?"#"+e.id:""}`}#W(e){let t={"HX-Request":"true","HX-Source":this.#J(e),"HX-Current-URL":location.href,Accept:"text/html"};return this.#P(e)&&(t["HX-Boosted"]="true"),t}#G(e,t){return this.#S(e,"hx-headers",e=>{for(let r in e)t[r]=String(e[r])})}#Q(e,t){return t instanceof Element?t:null!=t?this.#X(e,t,"hx-target"):this.#P(e)?document.body:e}#P(e){return e?._htmx?.boosted}async#U(e){let t=e.sourceElement,r=e.sourceEvent;if(!t.isConnected)return;if(this.#K(r))return;this.#Y(r)&&r.preventDefault();let i=/GET|DELETE/.test(e.request.method),s=i?t.matches("form")?t:null:t.form||t.closest("form"),n=this.#v(t,s,r.submitter,e.request.validate);if(!n)return;let a=this.#S(t,"hx-vals",t=>{e.vals=t;for(let e in t)n.set(e,t[e])});if(a&&await a,e.values)for(let t in e.values)n.delete(t),n.append(t,e.values[t]);let o=this.#G(t,e.request.headers);if(o&&await o,e.request.headers["HX-Request-Type"]=e.target===document.body||e.select?"full":"partial",e.target&&(e.request.headers["HX-Target"]=this.#J(e.target)),Object.assign(e.request,{form:s,submitter:r.submitter,body:n}),!this.#T(t,"htmx:config:request",{ctx:e}))return;if(!this.#l.includes(e.request.method.toLowerCase()))return;let l=this.#Z(e.request.action);if(null!=l){let t=Object.fromEntries(e.request.body);return void await this.#ee(e.sourceElement,t,l,!1)}if(i){let t=new URL(e.request.action,document.baseURI);for(let r of e.request.body.keys())t.searchParams.delete(r);for(let[r,i]of e.request.body)t.searchParams.append(r,i);t.origin===location.origin?e.request.action=t.pathname+t.search:e.request.action=t.href,e.request.body=null}else"multipart/form-data"!==this.#g(t,"hx-encoding")&&(e.request.body=new URLSearchParams(e.request.body));await this.#te(e)}async#te(e){let t=e.sourceElement,r=this.#re(t),i=this.#ie(t);if(!i.issue(e,r))return;e.status="issuing";let s=[],n=[];try{if(e.confirm){if(!await new Promise(r=>{let i={ctx:e,issueRequest:()=>r(!0),dropRequest:()=>r(!1)};if(this.#T(t,"htmx:confirm",i)){let i=this.#Z(e.confirm);r(i?this.#ee(t,{},i,!0):window.confirm(e.confirm))}}))return}if(this.#se(e),s=this.#ne(t),n=this.#ae(t),e.fetch||=window.fetch.bind(window),!this.#T(t,"htmx:before:request",{ctx:e}))return;let r=await e.fetch(e.request.action,e.request);if(e.response={raw:r,status:r.status,headers:r.headers},this.#oe(e),!this.#T(t,"htmx:before:response",{ctx:e}))return;if(e.text=await r.text(),!this.#T(t,"htmx:after:request",{ctx:e}))return;if(this.#le(e))return void(e.keepIndicators=!0);"issuing"===e.status&&(e.hx.retarget&&(e.target=e.hx.retarget),e.hx.reswap&&(e.swap=e.hx.reswap),e.hx.reselect&&(e.select=e.hx.reselect),e.status="response received",this.#he(e),await this.swap(e),e.status="swapped")}catch(r){e.status="error: "+r,this.#T(t,"htmx:error",{ctx:e,error:r})}finally{clearTimeout(e.requestTimeout),this.#T(t,"htmx:finally:request",{ctx:e}),e.keepIndicators||(this.#ue(s),this.#ce(n)),i.finish(),i.more()&&this.#te(i.next())}}#oe(e){e.hx={};for(let[t,r]of e.response.raw.headers)t.toLowerCase().startsWith("hx-")&&(e.hx[t.slice(3).toLowerCase().replace(/-/g,"")]=r)}#le(e){if(e.hx.trigger&&this.#de(e.hx.trigger,e.sourceElement),"true"===e.hx.refresh)return location.reload(),!0;if(e.hx.redirect)return location.href=e.hx.redirect,!0;if(e.hx.location){let t=e.hx.location,r={};return("{"===t[0]||/[\s,]/.test(t))&&(r=this.#j(t),t=r.path,delete r.path),r.push=r.push||"true",this.ajax("GET",t,r),!0}}#se(e){let t=null!=e.request.timeout?this.parseInterval(e.request.timeout):this.config.defaultTimeout;t&&(e.requestTimeout=setTimeout(()=>e.request?.abort?.(),t))}#re(e){let t=this.#g(e,"hx-sync");return t?t.split(":").pop():"queue first"}#ie(t){let r=this.#g(t,"hx-sync"),i=t;if(r&&r.includes(":")){let e=r.split(":")[0];i=this.#X(t,e,"hx-sync")||t}return i._htmxRequestQueue||=new e}#K(e){return"click"===e.type&&(e.ctrlKey||e.metaKey||e.shiftKey)}#Y(e){let t=e.currentTarget;if("submit"===e.type&&"FORM"===t?.tagName)return!0;if(!("click"===e.type&&0===e.button))return!1;let r=t?.closest?.('button, input[type="submit"], input[type="image"]'),i=r?.form||r?.closest("form");if(r&&!r.disabled&&i&&("submit"===r.type||"image"===r.type||!r.type&&"BUTTON"===r.tagName))return!0;let s=t?.closest?.("a");if(!s||!s.href)return!1;let n=s.getAttribute("href");return!(n&&n.startsWith("#")&&n.length>1)}#F(e,t=e._htmx.eventHandler){let r=this.#g(e,"hx-trigger");r||(r=e.matches("form")?"submit":e.matches("input:not([type=button]):not([type=submit]),select,textarea")?"change":"click"),this.#A(e,r,t)}#A(e,t,r){let i=this.#b(t);this.#q(e).triggerSpecs.push(...i);for(let t of i){t.handler=r,t.listeners=[],t.values=new WeakMap;let[i,s]=this.#fe(t.name);if(t.once){let e=t.handler;t.handler=r=>{e(r);for(let e of t.listeners)e.fromElt.removeEventListener(e.eventName,e.handler)}}if("intersect"===i||"revealed"===i){let r={};t.opts?.root&&(r.root=this.#X(e,t.opts.root)),t.opts?.threshold&&(r.threshold=parseFloat(t.opts.threshold));let s="revealed"===i;t.observer=new IntersectionObserver(r=>{for(let i=0;i<r.length;i++){if(r[i].isIntersecting){this.trigger(e,"intersect",{},!1),s&&t.observer.disconnect();break}}},r),i="intersect",t.observer.observe(e)}if(t.delay){let e=t.handler;t.handler=r=>{clearTimeout(t.timeout),t.timeout=setTimeout(()=>e(r),this.parseInterval(t.delay))}}if(t.throttle){let e=t.handler;t.handler=r=>{t.throttled?t.throttledEvent=r:(t.throttled=!0,e(r),t.throttleTimeout=setTimeout(()=>{if(t.throttled=!1,t.throttledEvent){let e=t.throttledEvent;t.throttledEvent=null,t.handler(e)}},this.parseInterval(t.throttle)))}}if(t.target){let e=t.handler;t.handler=r=>{r.target?.matches?.(t.target)&&e(r)}}if("every"===i){let r=Object.keys(t).find(e=>"name"!==e);t.interval=setInterval(()=>{e.isConnected?this.#T(e,"every",{},!1):clearInterval(t.interval)},this.parseInterval(r))}if(t.consume){let e=t.handler;t.handler=t=>{t.stopPropagation(),e(t)}}if(s){let r=t.handler;t.handler=t=>{this.#Y(t)&&t.preventDefault(),this.#me(e,t,s)&&r(t)}}let n=[e];if(t.from&&(n=this.#pe(e,t.from)),t.changed){let e=t.handler;t.handler=r=>{let i=!1;for(let e of n)t.values.get(e)!==e.value&&(i=!0,t.values.set(e,e.value));i&&e(r)}}if("load"!==i)for(let r of n){let s={fromElt:r,eventName:i,handler:t.handler};e._htmx.listeners.push(s),t.listeners.push(s),r.addEventListener(i,t.handler)}else t.handler(new CustomEvent("load"))}}#fe(e){let t=e.match(/^([^\[]*)\[([^\]]*)]/);return t?[t[1],t[2]]:[e,null]}#de(e,t){if("{"===e[0]){let r=this.#j(e);for(let e in r){let i=r[e],s=t;i?.target&&(s=this.find(i.target)),this.trigger(s,e,"object"==typeof i?i:{value:i})}}else e.split(",").forEach(e=>this.trigger(t,e.trim(),{}))}#ge(e){let t={},r=Object.getPrototypeOf(this);for(let i of Object.getOwnPropertyNames(r))"constructor"!==i&&"function"==typeof this[i]&&(["find","findAll"].includes(i)?t[i]=(t,r)=>void 0===r?this[i](e,t):this[i](t,r):t[i]=this[i].bind(this));return t}async#ee(e,t,r,i=!0){let s={};Object.assign(s,this.#ge(e)),Object.assign(s,t);let n=Object.keys(s),a=Object.values(s),o=new(0,Object.getPrototypeOf(async function(){}).constructor)(...n,i?`return (${r})`:r);return await o.call(e,...a)}#me(e,t,r){let i={};Object.assign(i,this.#ge(e));for(let e in t)i[e]=t[e];let s=Object.keys(i),n=Object.values(i);return new Function(...s,`return (${r})`).call(e,...n)}process(e){if(!e||this.#H(e))return;if(!this.#T(e,"htmx:before:process"))return;let t=[e],r=this.#h.evaluate(e),i=null;for(;i=r.iterateNext();)t.push(i);for(let e of t)this.#H(e)||this.#be(e);for(let t of this.#I(e,this.#a))this.#$(t);for(let t of this.#I(e,this.#o))this.#xe(t);this.#T(e,"htmx:after:process")}#xe(e){let t=this.#g(e,"hx-boost");if(t&&"false"!==t&&this.#ye(e)&&this.#T(e,"htmx:before:init",{},!0)){let r=this.#q(e);r.initialized=!0,r.eventHandler=this.#D(e),r.boosted=t;let i=e.matches("a")?"click":"submit";e._htmx.listeners.push({fromElt:e,eventName:i,handler:e._htmx.eventHandler}),e.addEventListener(i,e._htmx.eventHandler),this.#T(e,"htmx:after:init",{},!0)}}#ye(e){if(this.#_(e))if("A"===e.tagName){if(""===e.target||"_self"===e.target)return!e.getAttribute("href")?.startsWith?.("#")&&this.#ve(e.href)}else if("FORM"===e.tagName)return"dialog"!==e.method&&this.#ve(e.action)}#ve(e){try{return new URL(e,window.location.href).origin===window.location.origin}catch(e){return!1}}#_(e){return!e._htmx?.initialized&&!this.#H(e)}#Se(e){if(e._htmx){this.#T(e,"htmx:before:cleanup");for(let t of e._htmx.triggerSpecs||[])t.interval&&clearInterval(t.interval),t.timeout&&clearTimeout(t.timeout),t.throttleTimeout&&clearTimeout(t.throttleTimeout),t.observer?.disconnect();for(let t of e._htmx.listeners||[])t.fromElt.removeEventListener(t.eventName,t.handler);this.#T(e,"htmx:after:cleanup")}if(e.firstChild)for(let t of e.querySelectorAll("[data-htmx-powered]"))this.#Se(t)}#Ee(e){let t=document.createElement("div");t.style.display="none",document.body.insertAdjacentElement("afterend",t);let r=e.querySelectorAll?.(`[${this.#p("hx-preserve")}]`)||[];for(let e of r){let r=document.getElementById(e.id);r&&this.#we(t,r,null)}return t}#Ce(e){for(let t of[...e.children]){let e=document.getElementById(t.id);e&&(this.#we(e.parentNode,t,e),this.#Se(e),e.remove())}e.remove()}#Ae(e){return Document.parseHTMLUnsafe?.(e)||(new DOMParser).parseFromString(e,"text/html")}#qe(e){let t=e.replace(/<hx-([a-z]+)(\s+|>)/gi,'<template hx type="$1"$2').replace(/<\/hx-[a-z]+>/gi,"</template>"),r="";t=t.replace(/<head(\s[^>]*)?>[\s\S]*?<\/head>/i,e=>(r=this.#Ae(e).title,""));let i,s,n=t.match(/<([a-z][^\/>\x20\t\r\n\f]*)/i)?.[1]?.toLowerCase();if("html"===n||"body"===n)for(i=this.#Ae(t),s=document.createDocumentFragment();i.body.childNodes.length>0;)s.append(i.body.childNodes[0]);else i=this.#Ae(`<template>${t}</template>`),s=i.querySelector("template").content;if(!r){let e=s.querySelector("title:not(svg title)");e&&(r=e.textContent,e.remove())}return this.#Te(s),{fragment:s,title:r}}#Me(e,t,r,i){let s=t.id?"#"+CSS.escape(t.id):null;"true"!==r&&r&&!r.includes(" ")&&([r,s=s]=r.split(/:(.*)/)),"true"!==r&&r||(r="outerHTML");let n=this.#Ne(r);if(s=n.target||s,n.strip??=!n.style.startsWith("outer"),!s)return;let a=[...document.querySelectorAll(s)];for(let r of a){let s=document.createDocumentFragment();s.append(t.cloneNode(!0)),e.push({type:"oob",fragment:s,target:r,swapSpec:n,sourceElement:i})}t.remove()}#He(e,t,r){let i=[];if(r)for(let s of r.split(",")){let[r,n="true"]=s.split(/:(.*)/);for(let s of e.querySelectorAll(r))this.#Me(i,s,n,t)}for(let r of e.querySelectorAll(`[${this.#p("hx-swap-oob")}]`)){let e=r.getAttribute(this.#p("hx-swap-oob"));r.removeAttribute(this.#p("hx-swap-oob")),this.#Me(i,r,e,t)}return i}#Ie(e,t,r){t?t.before(...r.childNodes):e.append(...r.childNodes)}#Ne(e){e=e.trim();let t=this.config.defaultSwap;if(e&&!/^\S*:/.test(e)){let r=e.match(/^(\S+)\s*(.*)$/);t=r[1],e=r[2]}return{style:this.#O(t),...this.#j(e)}}#Oe(e,t){let r=[];for(let i of e.querySelectorAll("template[hx]")){let e=i.getAttribute("type");if("partial"===e){let e=i.getAttribute(this.#p("hx-target"))||(i.id?"#"+CSS.escape(i.id):null);if(e){this.#Te(i.content);let s=this.#Ne(i.getAttribute(this.#p("hx-swap"))||this.config.defaultSwap);for(let n of document.querySelectorAll(e))r.push({type:"partial",fragment:i.content.cloneNode(!0),target:n,swapSpec:s,sourceElement:t.sourceElement})}}else this.#R(i,"htmx:process:"+e,{ctx:t,tasks:r});i.remove()}return r}#Le(e,t,r,i){try{null!=r&&e.setSelectionRange&&e.setSelectionRange(r,i),e.focus(t)}catch(e){}}#ke(e){let t=this.#I(e,"[autofocus]")[0];t&&this.#Le(t)}#Re(e,t){if(e.scroll){let r=e.scrollTarget?this.#je(e.scrollTarget):t;r&&("top"===e.scroll?r.scrollTop=0:"bottom"===e.scroll&&(r.scrollTop=r.scrollHeight))}if(e.show){let r=e.showTarget?this.#je(e.showTarget):t;r?.scrollIntoView("top"===e.show)}}#Ve(e){e.request?.anchor&&document.getElementById(e.request.anchor)?.scrollIntoView({block:"start",behavior:"auto"})}#Te(e){let t=this.#I(e,"script");for(let e of t){let t=document.createElement("script");for(let r of e.attributes)t.setAttribute(r.name,r.value);this.config.inlineScriptNonce&&(t.nonce=this.config.inlineScriptNonce),t.textContent=e.textContent,e.replaceWith(t)}}async swap(e){this.#Pe(e);let{fragment:t,title:r}=this.#qe(e.text);e.title=r;let i=[],s=this.#He(t,e.sourceElement,e.selectOOB),n=this.#Oe(t,e);i.push(...s,...n);let a=this.#Be(e,t,n);if(a&&i.unshift(a),!this.#T(e.sourceElement,"htmx:before:swap",{ctx:e,tasks:i}))return;let o=[],l=[];for(let t of i)t.swapSpec?.transition??a?.transition??e.transition?l.push(t):o.push(this.#E(t));if(l.length>0){let e=async()=>{for(let e of l)await this.#E(e,!1)};o.push(this.#$e(e))}await Promise.all(o),this.#T(e.sourceElement,"htmx:after:swap",{ctx:e}),e.title&&!a?.swapSpec?.ignoreTitle&&(document.title=e.title),this.#Ve(e)}#Be(e,t,r){let i=this.#Ne(e.swap||this.config.defaultSwap);if("delete"===i.style||t.childElementCount>0||/\S/.test(t.textContent)||!r.length){if(e.select){let r=t.querySelectorAll(e.select);(t=document.createDocumentFragment()).append(...r)}return this.#P(e.sourceElement)&&(i.show||="top"),{type:"main",fragment:t,target:this.#Q(e.sourceElement||document.body,i.target||e.target),swapSpec:i,sourceElement:e.sourceElement,transition:e.transition&&!1!==i.transition}}}async#E(e,t=!0){let{target:r,swapSpec:i,fragment:s}=e;if("string"==typeof r&&(r=document.querySelector(r)),!r)return;"string"==typeof i&&(i=this.#Ne(i));let n,a=i.style;if("none"===a)return;if(i.strip&&s.firstElementChild&&(s=document.createDocumentFragment(),s.append(...(e.fragment.firstElementChild.content||e.fragment.firstElementChild).childNodes)),this.#_e(r,"htmx-swapping"),t&&e.swapSpec?.swap&&await this.timeout(e.swapSpec?.swap),"delete"===a)return void(r.parentNode&&(this.#Se(r),r.parentNode.removeChild(r)));let o=[],l=i.settle??this.config.defaultSettleDelay,h=r.parentNode;if("innerHTML"===a||"outerHTML"===a&&h){let e=document.activeElement;if(e?.id){let t,r;try{t=e.selectionStart,r=e.selectionEnd}catch(e){}n={elt:e,start:t,end:r}}o=t&&l?this.#De(s,r):[]}let u=this.#Ee(s),c=[...s.childNodes];try{if("innerHTML"===a){for(const e of r.children)this.#Se(e);r.replaceChildren(...s.childNodes)}else if("textContent"===a){for(const e of r.querySelectorAll("[data-htmx-powered]"))this.#Se(e);r.textContent=s.textContent}else if("outerHTML"===a)h&&(this.#Ie(h,r,s),this.#Se(r),h.removeChild(r));else if("innerMorph"===a)this.#w(r,s,!0),c=[...r.childNodes];else if("outerMorph"===a)this.#w(r,s,!1),c.push(r);else if("beforebegin"===a)h&&this.#Ie(h,r,s);else if("afterbegin"===a)this.#Ie(r,r.firstChild,s);else if("beforeend"===a)this.#Ie(r,null,s);else if("afterend"===a)h&&this.#Ie(h,r.nextSibling,s);else{let e=this.#r.get("handle_swap")||[],t=!1;for(const n of e){let e=n(a,r,s,i);if(e){t=!0,Array.isArray(e)&&(c=e);break}}if(!t)throw new Error(`Unknown swap style: ${a}`)}}finally{this.#Fe(r,"htmx-swapping")}if(this.#Ce(u),n&&!n.elt.matches(":focus")){let e=document.getElementById(n.elt.id);if(e){let t={preventScroll:void 0!==i.focusScroll?!i.focusScroll:!this.config.defaultFocusScroll};this.#Le(e,t,n.start,n.end)}}this.#T(r,"htmx:before:settle",{task:e,newContent:c,settleTasks:o});for(const e of c)this.#_e(e,"htmx-added");if(t&&o.length>0){this.#_e(r,"htmx-settling"),await this.timeout(l);for(let e of o)e();this.#Fe(r,"htmx-settling")}this.#T(r,"htmx:after:settle",{task:e,newContent:c,settleTasks:o});for(const e of c)this.#Fe(e,"htmx-added"),this.process(e),this.#ke(e);this.#Re(i,r)}#T(e,t,r={},i=!0){return this.config.logAll&&console.log(t,r,e),e=this.#ze(e),this.#R(e,t,r),this.trigger(e,this.#k(t),r,i)}#R(e,t,r={}){let i=this.#r.get(t.replace(/:/g,"_"));if(i){r.cancelled=!1;for(const t of i)if(!1===t(e,r)||r.cancelled)return r.cancelled=!0,!1}return!0}timeout(e){if((e=this.parseInterval(e))>0)return new Promise(t=>setTimeout(t,e))}forEvent(e,t,r=document){return new Promise((i,s)=>{let n=e=>{clearTimeout(a),i(e)},a=t&&setTimeout(()=>{r.removeEventListener(e,n),i(null)},t);r.addEventListener(e,n,{once:!0})})}onLoad(e){this.on(this.#k("htmx:after:process"),t=>{e(t.target)})}takeClass(e,t,r=e.parentElement){for(let e of this.#pe(this.#ze(r),"."+t))this.#Fe(e,t);this.#_e(e,t)}on(e,t,r){let i,s=document;return void 0===r?(i=e,r=t):(s=this.#ze(e),i=t),s.addEventListener(i,r),r}find(e,t){return this.#je(e,t)}findAll(e,t){return this.#pe(e,t)}parseInterval(e){if("number"==typeof e)return e;let[,t,r]=e?.match(/^([\d.]+)(ms|s|m)?$/)||[],i=parseFloat(t)*({ms:1,s:1e3,m:6e4}[r]||1);return isNaN(i)?void 0:i}trigger(e,t,r={},i=!0){e=this.#ze(e);let s=new CustomEvent(t,{detail:r,cancelable:!0,bubbles:i,composed:!0}),n=e?.isConnected?e:document;return!r.cancelled&&n.dispatchEvent(s)}ajax(e,t,r){(!r||r instanceof Element||"string"==typeof r)&&(r={target:r});let i="string"==typeof r.source?document.querySelector(r.source):r.source;if("string"==typeof r.source&&!i)return Promise.reject(new Error("Source not found"));if(r.target){let e=this.#Q(document.body,r.target);if(!e)return Promise.reject(new Error("Target not found"));i||=e}i||=document.body;let s=this.#y(i,r.event||{});return Object.assign(s,r),r.target&&(s.target=this.#Q(document.body,r.target)),Object.assign(s.request,{action:t,method:e.toUpperCase()}),r.headers&&Object.assign(s.request.headers,r.headers),this.#U(s)}#M(){this.config.history&&(history.state||history.replaceState({htmx:!0},"",location.href),window.addEventListener("popstate",e=>{e.state&&e.state.htmx&&(this.#c?.abort(),this.#Ue())}))}#We(e){this.config.history&&(history.pushState({htmx:!0},"",e),this.#T(document,"htmx:after:history:push",{path:e}))}#Qe(e){this.config.history&&(history.replaceState({htmx:!0},"",e),this.#T(document,"htmx:after:history:replace",{path:e}))}#Ue(e){e=e||location.pathname+location.search,this.#T(document,"htmx:before:history:restore",{path:e,cacheMiss:!0})&&("reload"===this.config.history?location.reload():(this.#c=new AbortController,this.ajax("GET",e,{target:"body",swap:"innerHTML",request:{headers:{"HX-History-Restore-Request":"true"},signal:this.#c.signal}})))}#Je(e){let{sourceElement:t,push:r,replace:i,hx:s,response:n}=e;if((s?.pushurl||s?.replaceurl)&&(r=s.pushurl,i=s.replaceurl),null==r&&null==i&&this.#P(t)&&(r="true"),"false"!==r&&!1!==r||(r=null),"false"!==i&&!1!==i||(i=null),!r&&!i)return null;let a=r||i;if("true"===a){let t=n?.raw?.url||e.request.action,r=new URL(t,location.href);a=r.pathname+r.search+(e.request.anchor?"#"+e.request.anchor:"")}return{type:r?"push":"replace",path:a}}#Pe(e){let t=this.#Je(e);if(!t)return;let r={history:t,sourceElement:e.sourceElement,response:e.response};this.#T(document,"htmx:before:history:update",r)&&("push"===t.type?this.#We(t.path):this.#Qe(t.path),this.#T(document,"htmx:after:history:update",r))}#be(e){let t=this.#k(this.#p("hx-on:"));for(let r of e.getAttributeNames())if(r.startsWith(t)){let i=r.substring(t.length),s=e.getAttribute(r),n=async t=>{try{await this.#ee(e,{event:t},s,!1)}catch(e){console.error(e)}};e.addEventListener(i,n),this.#q(e).listeners.push({fromElt:e,eventName:i,handler:n})}}#ne(e){let t,r=this.#g(e,"hx-indicator");t=r?this.#pe(e,r,"hx-indicator"):[e];for(const e of t)e._htmxReqCount||=0,e._htmxReqCount++,this.#_e(e,this.config.requestClass);return t}#ue(e){for(let t of e)t._htmxReqCount&&(t._htmxReqCount--,t._htmxReqCount<=0&&(this.#Fe(t,this.config.requestClass),delete t._htmxReqCount))}#ae(e){let t=this.#g(e,"hx-disable"),r=[];if(t){r=this.#pe(e,t,"hx-disable");for(let e of r)e._htmxDisableCount||=0,e._htmxDisableCount++,e.disabled=!0}return r}#ce(e){for(const t of e)t._htmxDisableCount&&(t._htmxDisableCount--,t._htmxDisableCount<=0&&(t.disabled=!1,delete t._htmxDisableCount))}#v(e,t,r,i){if(i&&t&&!t.reportValidity())return;let s=t?new FormData(t):new FormData,n=t?new Set(t.elements):new Set;if(!t&&e.name){if(i&&e.reportValidity&&!e.reportValidity())return;s.append(e.name,e.value),n.add(e)}r&&r.name&&(s.append(r.name,r.value),n.add(r));let a=this.#g(e,"hx-include");if(a)for(let t of this.#pe(e,a)){if(i&&t.reportValidity&&!t.reportValidity())return;this.#Ge(t,n,s)}return s}#Ge(e,t,r){let i=this.#I(e,"input:not([disabled]), select:not([disabled]), textarea:not([disabled])");for(let e of i){if(!e.name||t.has(e))continue;t.add(e);let i=e.type;if("checkbox"===i||"radio"===i)e.checked&&r.append(e.name,e.value);else if("file"===i)for(let t of e.files)r.append(e.name,t);else if("select-multiple"===i)for(let t of e.selectedOptions)r.append(e.name,t.value);else e.matches("select, textarea, input")&&r.append(e.name,e.value)}}#S(e,t,r){let i=this.#g(e,t);if(!i)return null;let s=this.#Z(i);if(s)return 0!==s.indexOf("{")&&(s="{"+s+"}"),this.#ee(e,{},s,!0).then(e=>{r(e)});r(this.#j(i))}#Xe(e){let t=e.trim();return t.startsWith("<")&&t.endsWith("/>")?t.slice(1,-2):t}#pe(e,t,r,i){let s=t??e,n=t?this.#ze(e):document;if(s.startsWith("global "))return this.#pe(n,s.slice(7),r,!0);let a=s?s.replace(/<[^>]+\/>/g,e=>e.replace(/,/g,"%2C")).split(",").map(e=>e.replace(/%2C/g,",")):[],o=[],l=[];for(const e of a){let t,s=this.#Xe(e);if(s.startsWith("closest "))t=n.closest(s.slice(8));else if(s.startsWith("find "))t=n.querySelector(s.slice(5));else if(s.startsWith("findAll "))o.push(...n.querySelectorAll(s.slice(8)));else if("next"===s||"nextElementSibling"===s)t=n.nextElementSibling;else if(s.startsWith("next "))t=this.#Ke(n,s.slice(5),!!i);else if("previous"===s||"previousElementSibling"===s)t=n.previousElementSibling;else if(s.startsWith("previous "))t=this.#Ye(n,s.slice(9),!!i);else if("document"===s)t=document;else if("window"===s)t=window;else if("body"===s)t=document.body;else if("host"===s)t=n.getRootNode().host;else if("this"===s){if(r){o.push(...this.#L(n,r));continue}t=n}else l.push(s);t&&o.push(t)}if(l.length>0){let e=l.join(","),t=this.#Ze(n,!!i);o.push(...t.querySelectorAll(e))}return[...new Set(o)]}#Ke(e,t,r){return this.#et(this.#Ze(e,r).querySelectorAll(t),e,Node.DOCUMENT_POSITION_PRECEDING)}#Ye(e,t,r){let i=[...this.#Ze(e,r).querySelectorAll(t)].reverse();return this.#et(i,e,Node.DOCUMENT_POSITION_FOLLOWING)}#et(e,t,r){for(const i of e)if(i.compareDocumentPosition(t)===r)return i}#Ze(e,t){return e.isConnected&&e.getRootNode?e.getRootNode?.({composed:t}):document}#X(e,t,r){let i=this.#pe(e,t,r)[0];return i||console.warn(`htmx: '${t}' on ${r} did not match any element`),i}#je(e,t,r){return this.#pe(e,t,r)[0]}#Z(e){if(null!=e){if(e.startsWith("js:"))return e.substring(3);if(e.startsWith("javascript:"))return e.substring(11)}}#z(e){let t=()=>{this.#ie(e).abort()};e.addEventListener("htmx:abort",t),e._htmx.listeners.push({fromElt:e,eventName:"htmx:abort",handler:t})}#w(e,t,r){let{persistentIds:i,idMap:s}=this.#tt(e,t),n=document.createElement("div");n.hidden=!0,document.body.after(n);let a={target:e,idMap:s,persistentIds:i,pantry:n,futureMatches:new WeakSet};r?this.#rt(a,e,t):this.#rt(a,e.parentNode,t,e,e.nextSibling),this.#Se(n),n.remove()}#rt(e,t,r,i=null,s=null){t instanceof HTMLTemplateElement&&r instanceof HTMLTemplateElement&&(t=t.content,r=r.content),i||=t.firstChild;let n=r.firstChild;for(;n;){let r;if(i&&i!=s&&(r=this.#it(e,n,i,s),r&&r!==i)){let a=i;for(;a&&a!==r;){let r=a;a=a.nextSibling,r instanceof Element&&(e.idMap.has(r)||this.#st(e,r,n))?this.#we(t,r,s):this.#nt(e,r)}}if(!r&&n instanceof Element&&e.persistentIds.has(n.id)){let s=CSS.escape(n.id);r=e.target.id===n.id&&e.target||e.target.querySelector(`[id="${s}"]`)||e.pantry.querySelector(`[id="${s}"]`);let a=r;for(;a=a.parentNode;){let t=e.idMap.get(a);t&&(t.delete(r.id),t.size||e.idMap.delete(a))}this.#we(t,r,i)}if(r){this.#at(r,n,e),i=r.nextSibling,n=n.nextSibling;continue}let a=n.nextSibling;if(e.idMap.has(n)){let r=document.createElement(n.tagName);t.insertBefore(r,i),this.#at(r,n,e),i=r.nextSibling}else t.insertBefore(n,i),i=n.nextSibling;n=a}for(;i&&i!=s;){let t=i;i=i.nextSibling,this.#nt(e,t)}}#st(e,t,r){if(e.futureMatches.has(t))return!0;for(let i=r.nextSibling,s=0;i&&s<this.config.morphScanLimit;i=i.nextSibling,s++)if(i instanceof Element&&t.isEqualNode(i))return e.futureMatches.add(t),!0;return!1}#it(e,t,r,i){if(!(t instanceof Element))return null;let s=null,n=0,a=this.config.morphScanLimit,o=e.idMap.get(t),l=o?.size||0;if(t.id&&!o)return null;let h=r;for(;h&&h!=i;){let r=e.idMap.get(h);if(this.#n.isSoftMatch(h,t)){if(r&&o&&[...r].some(e=>o.has(e)))return h;if(!r){if(a>0&&h.isEqualNode(t))return h;s||(s=h)}}if(n+=r?.size||0,n>l)break;if(h.contains(document.activeElement))break;if(--a<1&&0===l)break;h=h.nextSibling}return s&&this.#st(e,s,t)?null:s}#C(e,t){return e instanceof Element&&e.tagName===t.tagName&&(!("SCRIPT"===e.tagName&&!e.isEqualNode(t))&&(!(!e._x_bindings?.id||!t.matches?.("[\\:id], [x-bind\\:id]"))||(!e.id||e.id===t.id)))}#nt(e,t){e.idMap.has(t)?this.#we(e.pantry,t,null):(this.#Se(t),t.remove())}#we(e,t,r){if(e.moveBefore)try{return void e.moveBefore(t,r)}catch(e){}e.insertBefore(t,r)}#at(e,t,r){if(this.config.morphSkip&&e.matches?.(this.config.morphSkip))return;if(!this.#R(e,"htmx:before:morph:node",{oldNode:e,newNode:t}))return;this.#ot(e,t),e instanceof HTMLTextAreaElement&&e.defaultValue!=t.defaultValue&&(e.value=t.value),this.config.morphSkipChildren&&e.matches?.(this.config.morphSkipChildren)||e.isEqualNode(t)&&"TEMPLATE"!==t.tagName&&!t.querySelector?.("template")||this.#rt(r,e,t)}#ot(e,t){let r=this.config.morphIgnore||[];for(const i of t.attributes)r.includes(i.name)||e.getAttribute(i.name)===i.value||(e.setAttribute(i.name,i.value),"value"===i.name&&e instanceof HTMLInputElement&&"file"!==e.type&&(e.value=i.value));for(let i=e.attributes.length-1;i>=0;i--){let s=e.attributes[i];!s||t.hasAttribute(s.name)||r.includes(s.name)||e.removeAttribute(s.name)}}#lt(e,t,r,i){for(const s of i)if(t.has(s.id)){let t=s;for(;t&&t!==r;){let r=e.get(t);null==r&&(r=new Set,e.set(t,r)),r.add(s.id),t=t.parentElement}}}#tt(e,t){let r=this.#I(e,"[id]"),i=t.querySelectorAll("[id]"),s=this.#ht(r,i),n=new Map;return this.#lt(n,s,e.parentElement,r),this.#lt(n,s,t,i),{persistentIds:s,idMap:n}}#ht(e,t){let r=new Set,i=new Map;for(const{id:t,tagName:s}of e)i.has(t)?r.add(t):t&&i.set(t,s);let s=new Set;for(const{id:e,tagName:n}of t)s.has(e)?r.add(e):i.get(e)===n&&s.add(e);for(const e of r)s.delete(e);return s}#he(e){let t=e.response.raw.status,r=this.config.noSwap.map(e=>e+""),i=t+"";for(let t of[i,i.slice(0,2)+"x",i[0]+"xx"]){if(r.includes(t))return void(e.swap="none");let i=this.#g(e.sourceElement,this.#k("hx-status:")+t);if(i)return void this.#N(i,e)}}#$e(e){return new Promise(t=>{this.#u||=[],this.#u.push({task:e,resolve:t}),this.#d||this.#ut()})}async#ut(){if(0===this.#u.length||this.#d)return;this.#d=!0;let{task:e,resolve:t}=this.#u.shift();try{document.startViewTransition?(this.#T(document,"htmx:before:viewTransition",{task:e}),await document.startViewTransition(e).finished,this.#T(document,"htmx:after:viewTransition",{task:e})):await e()}catch(e){}finally{this.#d=!1,t(),this.#ut()}}#De(e,t){let r=t.querySelectorAll("[id]"),i=Object.fromEntries([...r].map(e=>[e.id,e])),s=e.querySelectorAll("[id]"),n=[];for(let e of s){let t=i[e.id];if(t?.tagName===e.tagName){let r=e.cloneNode(!1);this.#ot(e,t),n.push(()=>{this.#ot(e,r)})}}return n}#_e(e,t){e?.classList?.add?.(t)}#Fe(e,t){e?.classList?.remove?.(t),0===e?.classList?.length&&e.removeAttribute("class")}#ze(e){return"string"==typeof e?this.find(e):e}#k(e){return this.config.metaCharacter?e.replace(/:/g,this.config.metaCharacter):e}}})(); |