From f36152d8b0102d83cd22b595642e80b6fd594da9 Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Mon, 4 Nov 2024 01:59:46 +0300 Subject: [PATCH] Improve listener controller --- public/js/orchid.js | 2 +- public/mix-manifest.json | 2 +- .../js/controllers/application_controller.js | 21 +++++++-- .../js/controllers/listener_controller.js | 47 +++++++++++++++---- resources/views/layouts/listener.blade.php | 10 ++-- 5 files changed, 58 insertions(+), 24 deletions(-) diff --git a/public/js/orchid.js b/public/js/orchid.js index 72ccab56f..c9115a848 100644 --- a/public/js/orchid.js +++ b/public/js/orchid.js @@ -13,4 +13,4 @@ opacity ${jt.animationDuration/2}ms ${jt.animationDuration/2}ms ease-in; transform: translate3d(0, 0, 0); } - `}hiding=!1;value=0;visible=!1;constructor(){this.stylesheetElement=this.createStylesheetElement(),this.progressElement=this.createProgressElement(),this.installStylesheetElement(),this.setValue(0)}show(){this.visible||(this.visible=!0,this.installProgressElement(),this.startTrickling())}hide(){this.visible&&!this.hiding&&(this.hiding=!0,this.fadeProgressElement((()=>{this.uninstallProgressElement(),this.stopTrickling(),this.visible=!1,this.hiding=!1})))}setValue(t){this.value=t,this.refresh()}installStylesheetElement(){document.head.insertBefore(this.stylesheetElement,document.head.firstChild)}installProgressElement(){this.progressElement.style.width="0",this.progressElement.style.opacity="1",document.documentElement.insertBefore(this.progressElement,document.body),this.refresh()}fadeProgressElement(t){this.progressElement.style.opacity="0",setTimeout(t,1.5*jt.animationDuration)}uninstallProgressElement(){this.progressElement.parentNode&&document.documentElement.removeChild(this.progressElement)}startTrickling(){this.trickleInterval||(this.trickleInterval=window.setInterval(this.trickle,jt.animationDuration))}stopTrickling(){window.clearInterval(this.trickleInterval),delete this.trickleInterval}trickle=()=>{this.setValue(this.value+Math.random()/100)};refresh(){requestAnimationFrame((()=>{this.progressElement.style.width=10+90*this.value+"%"}))}createStylesheetElement(){const t=document.createElement("style");t.type="text/css",t.textContent=jt.defaultCSS;const e=j();return e&&(t.nonce=e),t}createProgressElement(){const t=document.createElement("div");return t.className="turbo-progress-bar",t}}class Pt extends ct{detailsByOuterHTML=this.children.filter((t=>!function(t){const e=t.localName;return"noscript"==e}(t))).map((t=>function(t){t.hasAttribute("nonce")&&t.setAttribute("nonce","");return t}(t))).reduce(((t,e)=>{const{outerHTML:r}=e,n=r in t?t[r]:{type:_t(e),tracked:Tt(e),elements:[]};return{...t,[r]:{...n,elements:[...n.elements,e]}}}),{});get trackedElementSignature(){return Object.keys(this.detailsByOuterHTML).filter((t=>this.detailsByOuterHTML[t].tracked)).join("")}getScriptElementsNotInSnapshot(t){return this.getElementsMatchingTypeNotInSnapshot("script",t)}getStylesheetElementsNotInSnapshot(t){return this.getElementsMatchingTypeNotInSnapshot("stylesheet",t)}getElementsMatchingTypeNotInSnapshot(t,e){return Object.keys(this.detailsByOuterHTML).filter((t=>!(t in e.detailsByOuterHTML))).map((t=>this.detailsByOuterHTML[t])).filter((({type:e})=>e==t)).map((({elements:[t]})=>t))}get provisionalElements(){return Object.keys(this.detailsByOuterHTML).reduce(((t,e)=>{const{type:r,tracked:n,elements:o}=this.detailsByOuterHTML[e];return null!=r||n?o.length>1?[...t,...o.slice(1)]:t:[...t,...o]}),[])}getMetaValue(t){const e=this.findMetaElementByName(t);return e?e.getAttribute("content"):null}findMetaElementByName(t){return Object.keys(this.detailsByOuterHTML).reduce(((e,r)=>{const{elements:[n]}=this.detailsByOuterHTML[r];return function(t,e){const r=t.localName;return"meta"==r&&t.getAttribute("name")==e}(n,t)?n:e}),0)}}function _t(t){return function(t){const e=t.localName;return"script"==e}(t)?"script":function(t){const e=t.localName;return"style"==e||"link"==e&&"stylesheet"==t.getAttribute("rel")}(t)?"stylesheet":void 0}function Tt(t){return"reload"==t.getAttribute("data-turbo-track")}class kt extends ct{static fromHTMLString(t=""){return this.fromDocument(p(t))}static fromElement(t){return this.fromDocument(t.ownerDocument)}static fromDocument({documentElement:t,body:e,head:r}){return new this(t,e,new Pt(r))}constructor(t,e,r){super(e),this.documentElement=t,this.headSnapshot=r}clone(){const t=this.element.cloneNode(!0),e=this.element.querySelectorAll("select"),r=t.querySelectorAll("select");for(const[t,n]of e.entries()){const e=r[t];for(const t of e.selectedOptions)t.selected=!1;for(const t of n.selectedOptions)e.options[t.index].selected=!0}for(const e of t.querySelectorAll('input[type="password"]'))e.value="";return new kt(this.documentElement,t,this.headSnapshot)}get lang(){return this.documentElement.getAttribute("lang")}get headElement(){return this.headSnapshot.element}get rootLocation(){return M(this.getSetting("root")??"/")}get cacheControlValue(){return this.getSetting("cache-control")}get isPreviewable(){return"no-preview"!=this.cacheControlValue}get isCacheable(){return"no-cache"!=this.cacheControlValue}get isVisitable(){return"reload"!=this.getSetting("visit-control")}get prefersViewTransitions(){return"same-origin"===this.headSnapshot.getMetaValue("view-transition")}get shouldMorphPage(){return"morph"===this.getSetting("refresh-method")}get shouldPreserveScrollPosition(){return"preserve"===this.getSetting("refresh-scroll")}getSetting(t){return this.headSnapshot.getMetaValue(`turbo-${t}`)}}class xt{#l=!1;#f=Promise.resolve();renderChange(t,e){return t&&this.viewTransitionsAvailable&&!this.#l?(this.#l=!0,this.#f=this.#f.then((async()=>{await document.startViewTransition(e).finished}))):this.#f=this.#f.then(e),this.#f}get viewTransitionsAvailable(){return document.startViewTransition}}const Lt={action:"advance",historyChanged:!1,visitCachedSnapshot:()=>{},willRender:!0,updateHistory:!0,shouldCacheSnapshot:!0,acceptsStreamResponse:!1},Rt="visitStart",Nt="requestStart",Ct="requestEnd",Mt="visitEnd",Bt="initialized",It="started",Ft="canceled",Dt="failed",qt="completed",Ut=0,Vt=-1,Ht=-2,zt={advance:"forward",restore:"back",replace:"none"};class Wt{identifier=y();timingMetrics={};followedRedirect=!1;historyChanged=!1;scrolled=!1;shouldCacheSnapshot=!0;acceptsStreamResponse=!1;snapshotCached=!1;state=Bt;viewTransitioner=new xt;constructor(t,e,r,n={}){this.delegate=t,this.location=e,this.restorationIdentifier=r||y();const{action:o,historyChanged:i,referrer:s,snapshot:a,snapshotHTML:c,response:u,visitCachedSnapshot:l,willRender:f,updateHistory:h,shouldCacheSnapshot:d,acceptsStreamResponse:p,direction:m}={...Lt,...n};this.action=o,this.historyChanged=i,this.referrer=s,this.snapshot=a,this.snapshotHTML=c,this.response=u,this.isSamePage=this.delegate.locationWithActionIsSamePage(this.location,this.action),this.isPageRefresh=this.view.isPageRefresh(this),this.visitCachedSnapshot=l,this.willRender=f,this.updateHistory=h,this.scrolled=!f,this.shouldCacheSnapshot=d,this.acceptsStreamResponse=p,this.direction=m||zt[o]}get adapter(){return this.delegate.adapter}get view(){return this.delegate.view}get history(){return this.delegate.history}get restorationData(){return this.history.getRestorationDataForIdentifier(this.restorationIdentifier)}get silent(){return this.isSamePage}start(){this.state==Bt&&(this.recordTimingMetric(Rt),this.state=It,this.adapter.visitStarted(this),this.delegate.visitStarted(this))}cancel(){this.state==It&&(this.request&&this.request.cancel(),this.cancelRender(),this.state=Ft)}complete(){this.state==It&&(this.recordTimingMetric(Mt),this.adapter.visitCompleted(this),this.state=qt,this.followRedirect(),this.followedRedirect||this.delegate.visitCompleted(this))}fail(){this.state==It&&(this.state=Dt,this.adapter.visitFailed(this),this.delegate.visitCompleted(this))}changeHistory(){if(!this.historyChanged&&this.updateHistory){const t=A(this.location.href===this.referrer?.href?"replace":this.action);this.history.update(t,this.location,this.restorationIdentifier),this.historyChanged=!0}}issueRequest(){this.hasPreloadedResponse()?this.simulateRequest():this.shouldIssueRequest()&&!this.request&&(this.request=new Z(this,G.get,this.location),this.request.perform())}simulateRequest(){this.response&&(this.startRequest(),this.recordResponse(),this.finishRequest())}startRequest(){this.recordTimingMetric(Nt),this.adapter.visitRequestStarted(this)}recordResponse(t=this.response){if(this.response=t,t){const{statusCode:e}=t;$t(e)?this.adapter.visitRequestCompleted(this):this.adapter.visitRequestFailedWithStatusCode(this,e)}}finishRequest(){this.recordTimingMetric(Ct),this.adapter.visitRequestFinished(this)}loadResponse(){if(this.response){const{statusCode:t,responseHTML:e}=this.response;this.render((async()=>{if(this.shouldCacheSnapshot&&this.cacheSnapshot(),this.view.renderPromise&&await this.view.renderPromise,$t(t)&&null!=e){const t=kt.fromHTMLString(e);await this.renderPageSnapshot(t,!1),this.adapter.visitRendered(this),this.complete()}else await this.view.renderError(kt.fromHTMLString(e),this),this.adapter.visitRendered(this),this.fail()}))}}getCachedSnapshot(){const t=this.view.getCachedSnapshotForLocation(this.location)||this.getPreloadedSnapshot();if(t&&(!B(this.location)||t.hasAnchor(B(this.location)))&&("restore"==this.action||t.isPreviewable))return t}getPreloadedSnapshot(){if(this.snapshotHTML)return kt.fromHTMLString(this.snapshotHTML)}hasCachedSnapshot(){return null!=this.getCachedSnapshot()}loadCachedSnapshot(){const t=this.getCachedSnapshot();if(t){const e=this.shouldIssueRequest();this.render((async()=>{this.cacheSnapshot(),this.isSamePage||this.isPageRefresh?this.adapter.visitRendered(this):(this.view.renderPromise&&await this.view.renderPromise,await this.renderPageSnapshot(t,e),this.adapter.visitRendered(this),e||this.complete())}))}}followRedirect(){this.redirectedToLocation&&!this.followedRedirect&&this.response?.redirected&&(this.adapter.visitProposedToLocation(this.redirectedToLocation,{action:"replace",response:this.response,shouldCacheSnapshot:!1,willRender:!1}),this.followedRedirect=!0)}goToSamePageAnchor(){this.isSamePage&&this.render((async()=>{this.cacheSnapshot(),this.performScroll(),this.changeHistory(),this.adapter.visitRendered(this)}))}prepareRequest(t){this.acceptsStreamResponse&&t.acceptResponseType(ot.contentType)}requestStarted(){this.startRequest()}requestPreventedHandlingResponse(t,e){}async requestSucceededWithResponse(t,e){const r=await e.responseHTML,{redirected:n,statusCode:o}=e;null==r?this.recordResponse({statusCode:Ht,redirected:n}):(this.redirectedToLocation=e.redirected?e.location:void 0,this.recordResponse({statusCode:o,responseHTML:r,redirected:n}))}async requestFailedWithResponse(t,e){const r=await e.responseHTML,{redirected:n,statusCode:o}=e;null==r?this.recordResponse({statusCode:Ht,redirected:n}):this.recordResponse({statusCode:o,responseHTML:r,redirected:n})}requestErrored(t,e){this.recordResponse({statusCode:Ut,redirected:!1})}requestFinished(){this.finishRequest()}performScroll(){this.scrolled||this.view.forceReloaded||this.view.shouldPreserveScrollPosition(this)||("restore"==this.action?this.scrollToRestoredPosition()||this.scrollToAnchor()||this.view.scrollToTop():this.scrollToAnchor()||this.view.scrollToTop(),this.isSamePage&&this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation,this.location),this.scrolled=!0)}scrollToRestoredPosition(){const{scrollPosition:t}=this.restorationData;if(t)return this.view.scrollToPosition(t),!0}scrollToAnchor(){const t=B(this.location);if(null!=t)return this.view.scrollToAnchor(t),!0}recordTimingMetric(t){this.timingMetrics[t]=(new Date).getTime()}getTimingMetrics(){return{...this.timingMetrics}}getHistoryMethodForAction(t){switch(t){case"replace":return history.replaceState;case"advance":case"restore":return history.pushState}}hasPreloadedResponse(){return"object"==typeof this.response}shouldIssueRequest(){return!this.isSamePage&&("restore"==this.action?!this.hasCachedSnapshot():this.willRender)}cacheSnapshot(){this.snapshotCached||(this.view.cacheSnapshot(this.snapshot).then((t=>t&&this.visitCachedSnapshot(t))),this.snapshotCached=!0)}async render(t){this.cancelRender(),await new Promise((t=>{this.frame="hidden"===document.visibilityState?setTimeout((()=>t()),0):requestAnimationFrame((()=>t()))})),await t(),delete this.frame}async renderPageSnapshot(t,e){await this.viewTransitioner.renderChange(this.view.shouldTransitionTo(t),(async()=>{await this.view.renderPage(t,e,this.willRender,this),this.performScroll()}))}cancelRender(){this.frame&&(cancelAnimationFrame(this.frame),delete this.frame)}}function $t(t){return t>=200&&t<300}class Kt{progressBar=new jt;constructor(t){this.session=t}visitProposedToLocation(t,e){q(t,this.navigator.rootLocation)?this.navigator.startVisit(t,e?.restorationIdentifier||y(),e):window.location.href=t.toString()}visitStarted(t){this.location=t.location,t.loadCachedSnapshot(),t.issueRequest(),t.goToSamePageAnchor()}visitRequestStarted(t){this.progressBar.setValue(0),t.hasCachedSnapshot()||"restore"!=t.action?this.showVisitProgressBarAfterDelay():this.showProgressBar()}visitRequestCompleted(t){t.loadResponse()}visitRequestFailedWithStatusCode(t,e){switch(e){case Ut:case Vt:case Ht:return this.reload({reason:"request_failed",context:{statusCode:e}});default:return t.loadResponse()}}visitRequestFinished(t){}visitCompleted(t){this.progressBar.setValue(1),this.hideVisitProgressBar()}pageInvalidated(t){this.reload(t)}visitFailed(t){this.progressBar.setValue(1),this.hideVisitProgressBar()}visitRendered(t){}formSubmissionStarted(t){this.progressBar.setValue(0),this.showFormProgressBarAfterDelay()}formSubmissionFinished(t){this.progressBar.setValue(1),this.hideFormProgressBar()}showVisitProgressBarAfterDelay(){this.visitProgressBarTimeout=window.setTimeout(this.showProgressBar,this.session.progressBarDelay)}hideVisitProgressBar(){this.progressBar.hide(),null!=this.visitProgressBarTimeout&&(window.clearTimeout(this.visitProgressBarTimeout),delete this.visitProgressBarTimeout)}showFormProgressBarAfterDelay(){null==this.formProgressBarTimeout&&(this.formProgressBarTimeout=window.setTimeout(this.showProgressBar,this.session.progressBarDelay))}hideFormProgressBar(){this.progressBar.hide(),null!=this.formProgressBarTimeout&&(window.clearTimeout(this.formProgressBarTimeout),delete this.formProgressBarTimeout)}showProgressBar=()=>{this.progressBar.show()};reload(t){u("turbo:reload",{detail:t}),window.location.href=this.location?.toString()||window.location.href}get navigator(){return this.session.navigator}}class Yt{selector="[data-turbo-temporary]";deprecatedSelector="[data-turbo-cache=false]";started=!1;start(){this.started||(this.started=!0,addEventListener("turbo:before-cache",this.removeTemporaryElements,!1))}stop(){this.started&&(this.started=!1,removeEventListener("turbo:before-cache",this.removeTemporaryElements,!1))}removeTemporaryElements=t=>{for(const t of this.temporaryElements)t.remove()};get temporaryElements(){return[...document.querySelectorAll(this.selector),...this.temporaryElementsWithDeprecation]}get temporaryElementsWithDeprecation(){const t=document.querySelectorAll(this.deprecatedSelector);return t.length,[...t]}}class Gt{constructor(t,e){this.session=t,this.element=e,this.linkInterceptor=new pt(this,e),this.formSubmitObserver=new ft(this,e)}start(){this.linkInterceptor.start(),this.formSubmitObserver.start()}stop(){this.linkInterceptor.stop(),this.formSubmitObserver.stop()}shouldInterceptLinkClick(t,e,r){return this.#h(t)}linkClickIntercepted(t,e,r){const n=this.#d(t);n&&n.delegate.linkClickIntercepted(t,e,r)}willSubmitForm(t,e){return null==t.closest("turbo-frame")&&this.#p(t,e)&&this.#h(t,e)}formSubmitted(t,e){const r=this.#d(t,e);r&&r.delegate.formSubmitted(t,e)}#p(t,e){const r=I(t,e),n=this.element.ownerDocument.querySelector('meta[name="turbo-root"]'),o=M(n?.content??"/");return this.#h(t,e)&&q(r,o)}#h(t,e){if(t instanceof HTMLFormElement?this.session.submissionIsNavigatable(t,e):this.session.elementIsNavigatable(t)){const r=this.#d(t,e);return!!r&&r!=t.closest("turbo-frame")}return!1}#d(t,e){const r=e?.getAttribute("data-turbo-frame")||t.getAttribute("data-turbo-frame");if(r&&"_top"!=r){const t=this.element.querySelector(`#${r}:not([disabled])`);if(t instanceof s)return t}}}class Jt{location;restorationIdentifier=y();restorationData={};started=!1;pageLoaded=!1;currentIndex=0;constructor(t){this.delegate=t}start(){this.started||(addEventListener("popstate",this.onPopState,!1),addEventListener("load",this.onPageLoad,!1),this.currentIndex=history.state?.turbo?.restorationIndex||0,this.started=!0,this.replace(new URL(window.location.href)))}stop(){this.started&&(removeEventListener("popstate",this.onPopState,!1),removeEventListener("load",this.onPageLoad,!1),this.started=!1)}push(t,e){this.update(history.pushState,t,e)}replace(t,e){this.update(history.replaceState,t,e)}update(t,e,r=y()){t===history.pushState&&++this.currentIndex;const n={turbo:{restorationIdentifier:r,restorationIndex:this.currentIndex}};t.call(history,n,"",e.href),this.location=e,this.restorationIdentifier=r}getRestorationDataForIdentifier(t){return this.restorationData[t]||{}}updateRestorationData(t){const{restorationIdentifier:e}=this,r=this.restorationData[e];this.restorationData[e]={...r,...t}}assumeControlOfScrollRestoration(){this.previousScrollRestoration||(this.previousScrollRestoration=history.scrollRestoration??"auto",history.scrollRestoration="manual")}relinquishControlOfScrollRestoration(){this.previousScrollRestoration&&(history.scrollRestoration=this.previousScrollRestoration,delete this.previousScrollRestoration)}onPopState=t=>{if(this.shouldHandlePopState()){const{turbo:e}=t.state||{};if(e){this.location=new URL(window.location.href);const{restorationIdentifier:t,restorationIndex:r}=e;this.restorationIdentifier=t;const n=r>this.currentIndex?"forward":"back";this.delegate.historyPoppedToLocationWithRestorationIdentifierAndDirection(this.location,t,n),this.currentIndex=r}}};onPageLoad=async t=>{await Promise.resolve(),this.pageLoaded=!0};shouldHandlePopState(){return this.pageIsLoaded()}pageIsLoaded(){return this.pageLoaded||"complete"==document.readyState}}class Qt{started=!1;#m=null;constructor(t,e){this.delegate=t,this.eventTarget=e}start(){this.started||("loading"===this.eventTarget.readyState?this.eventTarget.addEventListener("DOMContentLoaded",this.#y,{once:!0}):this.#y())}stop(){this.started&&(this.eventTarget.removeEventListener("mouseenter",this.#b,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("mouseleave",this.#g,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("turbo:before-fetch-request",this.#v,!0),this.started=!1)}#y=()=>{this.eventTarget.addEventListener("mouseenter",this.#b,{capture:!0,passive:!0}),this.eventTarget.addEventListener("mouseleave",this.#g,{capture:!0,passive:!0}),this.eventTarget.addEventListener("turbo:before-fetch-request",this.#v,!0),this.started=!0};#b=t=>{if("false"===E("turbo-prefetch"))return;const e=t.target;if(e.matches&&e.matches("a[href]:not([target^=_]):not([download])")&&this.#w(e)){const t=e,r=L(t);if(this.delegate.canPrefetchRequestToLocation(t,r)){this.#m=t;const n=new Z(this,G.get,r,new URLSearchParams,e);it.setLater(r.toString(),n,this.#A)}}};#g=t=>{t.target===this.#m&&this.#O()};#O=()=>{it.clear(),this.#m=null};#v=t=>{if("FORM"!==t.target.tagName&&"GET"===t.detail.fetchOptions.method){const e=it.get(t.detail.url.toString());e&&(t.detail.fetchRequest=e),it.clear()}};prepareRequest(t){const e=t.target;t.headers["X-Sec-Purpose"]="prefetch";const r=e.closest("turbo-frame"),n=e.getAttribute("data-turbo-frame")||r?.getAttribute("target")||r?.id;n&&"_top"!==n&&(t.headers["Turbo-Frame"]=n)}requestSucceededWithResponse(){}requestStarted(t){}requestErrored(t){}requestFinished(t){}requestPreventedHandlingResponse(t,e){}requestFailedWithResponse(t,e){}get#A(){return Number(E("turbo-prefetch-cache-time"))||1e4}#w(t){return!!t.getAttribute("href")&&(!Zt(t)&&(!Xt(t)&&(!te(t)&&(!ee(t)&&!ne(t)))))}}const Zt=t=>t.origin!==document.location.origin||!["http:","https:"].includes(t.protocol)||t.hasAttribute("target"),Xt=t=>t.pathname+t.search===document.location.pathname+document.location.search||t.href.startsWith("#"),te=t=>{if("false"===t.getAttribute("data-turbo-prefetch"))return!0;if("false"===t.getAttribute("data-turbo"))return!0;const e=P(t,"[data-turbo-prefetch]");return!(!e||"false"!==e.getAttribute("data-turbo-prefetch"))},ee=t=>{const e=t.getAttribute("data-turbo-method");return!(!e||"get"===e.toLowerCase())||(!!re(t)||(!!t.hasAttribute("data-turbo-confirm")||!!t.hasAttribute("data-turbo-stream")))},re=t=>t.hasAttribute("data-remote")||t.hasAttribute("data-behavior")||t.hasAttribute("data-confirm")||t.hasAttribute("data-method"),ne=t=>u("turbo:before-prefetch",{target:t,cancelable:!0}).defaultPrevented;class oe{constructor(t){this.delegate=t}proposeVisit(t,e={}){this.delegate.allowsVisitingLocationWithAction(t,e.action)&&this.delegate.visitProposedToLocation(t,e)}startVisit(t,e,r={}){this.stop(),this.currentVisit=new Wt(this,M(t),e,{referrer:this.location,...r}),this.currentVisit.start()}submitForm(t,e){this.stop(),this.formSubmission=new at(this,t,e,!0),this.formSubmission.start()}stop(){this.formSubmission&&(this.formSubmission.stop(),delete this.formSubmission),this.currentVisit&&(this.currentVisit.cancel(),delete this.currentVisit)}get adapter(){return this.delegate.adapter}get view(){return this.delegate.view}get rootLocation(){return this.view.snapshot.rootLocation}get history(){return this.delegate.history}formSubmissionStarted(t){"function"==typeof this.adapter.formSubmissionStarted&&this.adapter.formSubmissionStarted(t)}async formSubmissionSucceededWithResponse(t,e){if(t==this.formSubmission){const r=await e.responseHTML;if(r){const n=t.isSafe;n||this.view.clearSnapshotCache();const{statusCode:o,redirected:i}=e,s={action:this.#S(t,e),shouldCacheSnapshot:n,response:{statusCode:o,responseHTML:r,redirected:i}};this.proposeVisit(e.location,s)}}}async formSubmissionFailedWithResponse(t,e){const r=await e.responseHTML;if(r){const t=kt.fromHTMLString(r);e.serverError?await this.view.renderError(t,this.currentVisit):await this.view.renderPage(t,!1,!0,this.currentVisit),t.shouldPreserveScrollPosition||this.view.scrollToTop(),this.view.clearSnapshotCache()}}formSubmissionErrored(t,e){}formSubmissionFinished(t){"function"==typeof this.adapter.formSubmissionFinished&&this.adapter.formSubmissionFinished(t)}visitStarted(t){this.delegate.visitStarted(t)}visitCompleted(t){this.delegate.visitCompleted(t),delete this.currentVisit}locationWithActionIsSamePage(t,e){const r=B(t),n=B(this.view.lastRenderedLocation),o="restore"===e&&void 0===r;return"replace"!==e&&U(t)===U(this.view.lastRenderedLocation)&&(o||null!=r&&r!==n)}visitScrolledToSamePageLocation(t,e){this.delegate.visitScrolledToSamePageLocation(t,e)}get location(){return this.history.location}get restorationIdentifier(){return this.history.restorationIdentifier}#S(t,e){const{submitter:r,formElement:n}=t;return O(r,n)||this.#E(e)}#E(t){return t.redirected&&t.location.href===this.location?.href?"replace":"advance"}}const ie=0,se=1,ae=2,ce=3;class ue{stage=ie;started=!1;constructor(t){this.delegate=t}start(){this.started||(this.stage==ie&&(this.stage=se),document.addEventListener("readystatechange",this.interpretReadyState,!1),addEventListener("pagehide",this.pageWillUnload,!1),this.started=!0)}stop(){this.started&&(document.removeEventListener("readystatechange",this.interpretReadyState,!1),removeEventListener("pagehide",this.pageWillUnload,!1),this.started=!1)}interpretReadyState=()=>{const{readyState:t}=this;"interactive"==t?this.pageIsInteractive():"complete"==t&&this.pageIsComplete()};pageIsInteractive(){this.stage==se&&(this.stage=ae,this.delegate.pageBecameInteractive())}pageIsComplete(){this.pageIsInteractive(),this.stage==ae&&(this.stage=ce,this.delegate.pageLoaded())}pageWillUnload=()=>{this.delegate.pageWillUnload()};get readyState(){return document.readyState}}class le{started=!1;constructor(t){this.delegate=t}start(){this.started||(addEventListener("scroll",this.onScroll,!1),this.onScroll(),this.started=!0)}stop(){this.started&&(removeEventListener("scroll",this.onScroll,!1),this.started=!1)}onScroll=()=>{this.updatePosition({x:window.pageXOffset,y:window.pageYOffset})};updatePosition(t){this.delegate.scrollPositionChanged(t)}}class fe{render({fragment:t}){bt.preservingPermanentElements(this,function(t){const e=lt(document.documentElement),r={};for(const n of e){const{id:e}=n;for(const o of t.querySelectorAll("turbo-stream")){const t=ut(o.templateElement.content,e);t&&(r[e]=[n,t])}}return r}(t),(()=>{!async function(t,e){const r=`turbo-stream-autofocus-${y()}`,n=t.querySelectorAll("turbo-stream"),o=function(t){for(const e of t){const t=T(e.templateElement.content);if(t)return t}return null}(n);let i=null;o&&(i=o.id?o.id:r,o.id=i);e(),await f();if((null==document.activeElement||document.activeElement==document.body)&&i){const t=document.getElementById(i);_(t)&&t.focus(),t&&t.id==r&&t.removeAttribute("id")}}(t,(()=>{!async function(t){const[e,r]=await async function(t,e){const r=e();return t(),await h(),[r,e()]}(t,(()=>document.activeElement)),n=e&&e.id;if(n){const t=document.getElementById(n);_(t)&&t!=r&&t.focus()}}((()=>{document.documentElement.appendChild(t)}))}))}))}enteringBardo(t,e){e.replaceWith(t.cloneNode(!0))}leavingBardo(){}}class he{sources=new Set;#j=!1;constructor(t){this.delegate=t}start(){this.#j||(this.#j=!0,addEventListener("turbo:before-fetch-response",this.inspectFetchResponse,!1))}stop(){this.#j&&(this.#j=!1,removeEventListener("turbo:before-fetch-response",this.inspectFetchResponse,!1))}connectStreamSource(t){this.streamSourceIsConnected(t)||(this.sources.add(t),t.addEventListener("message",this.receiveMessageEvent,!1))}disconnectStreamSource(t){this.streamSourceIsConnected(t)&&(this.sources.delete(t),t.removeEventListener("message",this.receiveMessageEvent,!1))}streamSourceIsConnected(t){return this.sources.has(t)}inspectFetchResponse=t=>{const e=function(t){const e=t.detail?.fetchResponse;if(e instanceof H)return e}(t);e&&function(t){const e=t.contentType??"";return e.startsWith(ot.contentType)}(e)&&(t.preventDefault(),this.receiveMessageResponse(e))};receiveMessageEvent=t=>{this.#j&&"string"==typeof t.data&&this.receiveMessageHTML(t.data)};async receiveMessageResponse(t){const e=await t.responseHTML;e&&this.receiveMessageHTML(e)}receiveMessageHTML(t){this.delegate.receivedMessageFromStream(ot.wrap(t))}}class de extends gt{static renderElement(t,e){const{documentElement:r,body:n}=document;r.replaceChild(e,n)}async render(){this.replaceHeadAndBody(),this.activateScriptElements()}replaceHeadAndBody(){const{documentElement:t,head:e}=document;t.replaceChild(this.newHead,e),this.renderElement(this.currentElement,this.newElement)}activateScriptElements(){for(const t of this.scriptElements){const e=t.parentNode;if(e){const r=c(t);e.replaceChild(r,t)}}}get newHead(){return this.newSnapshot.headSnapshot.element}get scriptElements(){return document.documentElement.querySelectorAll("script")}}class pe extends gt{static renderElement(t,e){document.body&&e instanceof HTMLBodyElement?document.body.replaceWith(e):document.documentElement.appendChild(e)}get shouldRender(){return this.newSnapshot.isVisitable&&this.trackedElementsAreIdentical}get reloadReason(){return this.newSnapshot.isVisitable?this.trackedElementsAreIdentical?void 0:{reason:"tracked_element_mismatch"}:{reason:"turbo_visit_control_is_reload"}}async prepareToRender(){this.#P(),await this.mergeHead()}async render(){this.willRender&&await this.replaceBody()}finishRendering(){super.finishRendering(),this.isPreview||this.focusFirstAutofocusableElement()}get currentHeadSnapshot(){return this.currentSnapshot.headSnapshot}get newHeadSnapshot(){return this.newSnapshot.headSnapshot}get newElement(){return this.newSnapshot.element}#P(){const{documentElement:t}=this.currentSnapshot,{lang:e}=this.newSnapshot;e?t.setAttribute("lang",e):t.removeAttribute("lang")}async mergeHead(){const t=this.mergeProvisionalElements(),e=this.copyNewHeadStylesheetElements();this.copyNewHeadScriptElements(),await t,await e,this.willRender&&this.removeUnusedDynamicStylesheetElements()}async replaceBody(){await this.preservingPermanentElements((async()=>{this.activateNewBody(),await this.assignNewBody()}))}get trackedElementsAreIdentical(){return this.currentHeadSnapshot.trackedElementSignature==this.newHeadSnapshot.trackedElementSignature}async copyNewHeadStylesheetElements(){const t=[];for(const e of this.newHeadStylesheetElements)t.push(w(e)),document.head.appendChild(e);await Promise.all(t)}copyNewHeadScriptElements(){for(const t of this.newHeadScriptElements)document.head.appendChild(c(t))}removeUnusedDynamicStylesheetElements(){for(const t of this.unusedDynamicStylesheetElements)document.head.removeChild(t)}async mergeProvisionalElements(){const t=[...this.newHeadProvisionalElements];for(const e of this.currentHeadProvisionalElements)this.isCurrentElementInElementList(e,t)||document.head.removeChild(e);for(const e of t)document.head.appendChild(e)}isCurrentElementInElementList(t,e){for(const[r,n]of e.entries()){if("TITLE"==t.tagName){if("TITLE"!=n.tagName)continue;if(t.innerHTML==n.innerHTML)return e.splice(r,1),!0}if(n.isEqualNode(t))return e.splice(r,1),!0}return!1}removeCurrentHeadProvisionalElements(){for(const t of this.currentHeadProvisionalElements)document.head.removeChild(t)}copyNewHeadProvisionalElements(){for(const t of this.newHeadProvisionalElements)document.head.appendChild(t)}activateNewBody(){document.adoptNode(this.newElement),this.activateNewBodyScriptElements()}activateNewBodyScriptElements(){for(const t of this.newBodyScriptElements){const e=c(t);t.replaceWith(e)}}async assignNewBody(){await this.renderElement(this.currentElement,this.newElement)}get unusedDynamicStylesheetElements(){return this.oldHeadStylesheetElements.filter((t=>"dynamic"===t.getAttribute("data-turbo-track")))}get oldHeadStylesheetElements(){return this.currentHeadSnapshot.getStylesheetElementsNotInSnapshot(this.newHeadSnapshot)}get newHeadStylesheetElements(){return this.newHeadSnapshot.getStylesheetElementsNotInSnapshot(this.currentHeadSnapshot)}get newHeadScriptElements(){return this.newHeadSnapshot.getScriptElementsNotInSnapshot(this.currentHeadSnapshot)}get currentHeadProvisionalElements(){return this.currentHeadSnapshot.provisionalElements}get newHeadProvisionalElements(){return this.newHeadSnapshot.provisionalElements}get newBodyScriptElements(){return this.newElement.querySelectorAll("script")}}class me extends pe{static renderElement(t,e){At(t,e,{callbacks:{beforeNodeMorphed:t=>!ye(t)}});for(const e of t.querySelectorAll("turbo-frame"))ye(e)&&e.reload();u("turbo:morph",{detail:{currentElement:t,newElement:e}})}async preservingPermanentElements(t){return await t()}get renderMethod(){return"morph"}get shouldAutofocus(){return!1}}function ye(t){return t instanceof s&&t.src&&"morph"===t.refresh&&!t.closest("[data-turbo-permanent]")}class be{keys=[];snapshots={};constructor(t){this.size=t}has(t){return V(t)in this.snapshots}get(t){if(this.has(t)){const e=this.read(t);return this.touch(t),e}}put(t,e){return this.write(t,e),this.touch(t),e}clear(){this.snapshots={}}read(t){return this.snapshots[V(t)]}write(t,e){this.snapshots[V(t)]=e}touch(t){const e=V(t),r=this.keys.indexOf(e);r>-1&&this.keys.splice(r,1),this.keys.unshift(e),this.trim()}trim(){for(const t of this.keys.splice(this.size))delete this.snapshots[t]}}class ge extends ht{snapshotCache=new be(10);lastRenderedLocation=new URL(location.href);forceReloaded=!1;shouldTransitionTo(t){return this.snapshot.prefersViewTransitions&&t.prefersViewTransitions}renderPage(t,e=!1,r=!0,n){const o=new(this.isPageRefresh(n)&&this.snapshot.shouldMorphPage?me:pe)(this.snapshot,t,e,r);return o.shouldRender?n?.changeHistory():this.forceReloaded=!0,this.render(o)}renderError(t,e){e?.changeHistory();const r=new de(this.snapshot,t,!1);return this.render(r)}clearSnapshotCache(){this.snapshotCache.clear()}async cacheSnapshot(t=this.snapshot){if(t.isCacheable){this.delegate.viewWillCacheSnapshot();const{lastRenderedLocation:e}=this;await d();const r=t.clone();return this.snapshotCache.put(e,r),r}}getCachedSnapshotForLocation(t){return this.snapshotCache.get(t)}isPageRefresh(t){return!t||this.lastRenderedLocation.pathname===t.location.pathname&&"replace"===t.action}shouldPreserveScrollPosition(t){return this.isPageRefresh(t)&&this.snapshot.shouldPreserveScrollPosition}get snapshot(){return kt.fromElement(this.element)}}class ve{selector="a[data-turbo-preload]";constructor(t,e){this.delegate=t,this.snapshotCache=e}start(){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",this.#_):this.preloadOnLoadLinksForView(document.body)}stop(){document.removeEventListener("DOMContentLoaded",this.#_)}preloadOnLoadLinksForView(t){for(const e of t.querySelectorAll(this.selector))this.delegate.shouldPreloadLink(e)&&this.preloadURL(e)}async preloadURL(t){const e=new URL(t.href);if(this.snapshotCache.has(e))return;const r=new Z(this,G.get,e,new URLSearchParams,t);await r.perform()}prepareRequest(t){t.headers["X-Sec-Purpose"]="prefetch"}async requestSucceededWithResponse(t,e){try{const r=await e.responseHTML,n=kt.fromHTMLString(r);this.snapshotCache.put(t.url,n)}catch(t){}}requestStarted(t){}requestErrored(t){}requestFinished(t){}requestPreventedHandlingResponse(t,e){}requestFailedWithResponse(t,e){}#_=()=>{this.preloadOnLoadLinksForView(document.body)}}class we{constructor(t){this.session=t}clear(){this.session.clearCache()}resetCacheControl(){this.#T("")}exemptPageFromCache(){this.#T("no-cache")}exemptPageFromPreview(){this.#T("no-preview")}#T(t){!function(t,e){let r=S(t);r||(r=document.createElement("meta"),r.setAttribute("name",t),document.head.appendChild(r)),r.setAttribute("content",e)}("turbo-cache-control",t)}}function Ae(t){Object.defineProperties(t,Oe)}const Oe={absoluteURL:{get(){return this.toString()}}},Se=new class{navigator=new oe(this);history=new Jt(this);view=new ge(this,document.documentElement);adapter=new Kt(this);pageObserver=new ue(this);cacheObserver=new Yt;linkPrefetchObserver=new Qt(this,document);linkClickObserver=new mt(this,window);formSubmitObserver=new ft(this,document);scrollObserver=new le(this);streamObserver=new he(this);formLinkClickObserver=new yt(this,document.documentElement);frameRedirector=new Gt(this,document.documentElement);streamMessageRenderer=new fe;cache=new we(this);enabled=!0;started=!1;#k=150;constructor(t){this.recentRequests=t,this.preloader=new ve(this,this.view.snapshotCache),this.debouncedRefresh=this.refresh,this.pageRefreshDebouncePeriod=this.pageRefreshDebouncePeriod}start(){this.started||(this.pageObserver.start(),this.cacheObserver.start(),this.linkPrefetchObserver.start(),this.formLinkClickObserver.start(),this.linkClickObserver.start(),this.formSubmitObserver.start(),this.scrollObserver.start(),this.streamObserver.start(),this.frameRedirector.start(),this.history.start(),this.preloader.start(),this.started=!0,this.enabled=!0)}disable(){this.enabled=!1}stop(){this.started&&(this.pageObserver.stop(),this.cacheObserver.stop(),this.linkPrefetchObserver.stop(),this.formLinkClickObserver.stop(),this.linkClickObserver.stop(),this.formSubmitObserver.stop(),this.scrollObserver.stop(),this.streamObserver.stop(),this.frameRedirector.stop(),this.history.stop(),this.preloader.stop(),this.started=!1)}registerAdapter(t){this.adapter=t}visit(t,e={}){const r=e.frame?document.getElementById(e.frame):null;if(r instanceof s){const n=e.action||O(r);r.delegate.proposeVisitIfNavigatedWithAction(r,n),r.src=t.toString()}else this.navigator.proposeVisit(M(t),e)}refresh(t,e){e&&this.recentRequests.has(e)||this.navigator.currentVisit||this.visit(t,{action:"replace",shouldCacheSnapshot:!1})}connectStreamSource(t){this.streamObserver.connectStreamSource(t)}disconnectStreamSource(t){this.streamObserver.disconnectStreamSource(t)}renderStreamMessage(t){this.streamMessageRenderer.render(ot.wrap(t))}clearCache(){this.view.clearSnapshotCache()}setProgressBarDelay(t){this.progressBarDelay=t}set progressBarDelay(t){C.drive.progressBarDelay=t}get progressBarDelay(){return C.drive.progressBarDelay}set drive(t){C.drive.enabled=t}get drive(){return C.drive.enabled}set formMode(t){C.forms.mode=t}get formMode(){return C.forms.mode}get location(){return this.history.location}get restorationIdentifier(){return this.history.restorationIdentifier}get pageRefreshDebouncePeriod(){return this.#k}set pageRefreshDebouncePeriod(t){this.refresh=function(t,e){let r=null;return(...n)=>{clearTimeout(r),r=setTimeout((()=>t.apply(this,n)),e)}}(this.debouncedRefresh.bind(this),t),this.#k=t}shouldPreloadLink(t){const e=t.hasAttribute("data-turbo-method"),r=t.hasAttribute("data-turbo-stream"),n=t.getAttribute("data-turbo-frame"),o="_top"==n?null:document.getElementById(n)||P(t,"turbo-frame:not([disabled])");if(e||r||o instanceof s)return!1;{const e=new URL(t.href);return this.elementIsNavigatable(t)&&q(e,this.snapshot.rootLocation)}}historyPoppedToLocationWithRestorationIdentifierAndDirection(t,e,r){this.enabled?this.navigator.startVisit(t,e,{action:"restore",historyChanged:!0,direction:r}):this.adapter.pageInvalidated({reason:"turbo_disabled"})}scrollPositionChanged(t){this.history.updateRestorationData({scrollPosition:t})}willSubmitFormLinkToLocation(t,e){return this.elementIsNavigatable(t)&&q(e,this.snapshot.rootLocation)}submittedFormLinkToLocation(){}canPrefetchRequestToLocation(t,e){return this.elementIsNavigatable(t)&&q(e,this.snapshot.rootLocation)}willFollowLinkToLocation(t,e,r){return this.elementIsNavigatable(t)&&q(e,this.snapshot.rootLocation)&&this.applicationAllowsFollowingLinkToLocation(t,e,r)}followedLinkToLocation(t,e){const r=this.getActionForLink(t),n=t.hasAttribute("data-turbo-stream");this.visit(e.href,{action:r,acceptsStreamResponse:n})}allowsVisitingLocationWithAction(t,e){return this.locationWithActionIsSamePage(t,e)||this.applicationAllowsVisitingLocation(t)}visitProposedToLocation(t,e){Ae(t),this.adapter.visitProposedToLocation(t,e)}visitStarted(t){t.acceptsStreamResponse||(g(document.documentElement),this.view.markVisitDirection(t.direction)),Ae(t.location),t.silent||this.notifyApplicationAfterVisitingLocation(t.location,t.action)}visitCompleted(t){this.view.unmarkVisitDirection(),v(document.documentElement),this.notifyApplicationAfterPageLoad(t.getTimingMetrics())}locationWithActionIsSamePage(t,e){return this.navigator.locationWithActionIsSamePage(t,e)}visitScrolledToSamePageLocation(t,e){this.notifyApplicationAfterVisitingSamePageLocation(t,e)}willSubmitForm(t,e){const r=I(t,e);return this.submissionIsNavigatable(t,e)&&q(M(r),this.snapshot.rootLocation)}formSubmitted(t,e){this.navigator.submitForm(t,e)}pageBecameInteractive(){this.view.lastRenderedLocation=this.location,this.notifyApplicationAfterPageLoad()}pageLoaded(){this.history.assumeControlOfScrollRestoration()}pageWillUnload(){this.history.relinquishControlOfScrollRestoration()}receivedMessageFromStream(t){this.renderStreamMessage(t)}viewWillCacheSnapshot(){this.navigator.currentVisit?.silent||this.notifyApplicationBeforeCachingSnapshot()}allowsImmediateRender({element:t},e){const r=this.notifyApplicationBeforeRender(t,e),{defaultPrevented:n,detail:{render:o}}=r;return this.view.renderer&&o&&(this.view.renderer.renderElement=o),!n}viewRenderedSnapshot(t,e,r){this.view.lastRenderedLocation=this.history.location,this.notifyApplicationAfterRender(r)}preloadOnLoadLinksForView(t){this.preloader.preloadOnLoadLinksForView(t)}viewInvalidated(t){this.adapter.pageInvalidated(t)}frameLoaded(t){this.notifyApplicationAfterFrameLoad(t)}frameRendered(t,e){this.notifyApplicationAfterFrameRender(t,e)}applicationAllowsFollowingLinkToLocation(t,e,r){return!this.notifyApplicationAfterClickingLinkToLocation(t,e,r).defaultPrevented}applicationAllowsVisitingLocation(t){return!this.notifyApplicationBeforeVisitingLocation(t).defaultPrevented}notifyApplicationAfterClickingLinkToLocation(t,e,r){return u("turbo:click",{target:t,detail:{url:e.href,originalEvent:r},cancelable:!0})}notifyApplicationBeforeVisitingLocation(t){return u("turbo:before-visit",{detail:{url:t.href},cancelable:!0})}notifyApplicationAfterVisitingLocation(t,e){return u("turbo:visit",{detail:{url:t.href,action:e}})}notifyApplicationBeforeCachingSnapshot(){return u("turbo:before-cache")}notifyApplicationBeforeRender(t,e){return u("turbo:before-render",{detail:{newBody:t,...e},cancelable:!0})}notifyApplicationAfterRender(t){return u("turbo:render",{detail:{renderMethod:t}})}notifyApplicationAfterPageLoad(t={}){return u("turbo:load",{detail:{url:this.location.href,timing:t}})}notifyApplicationAfterVisitingSamePageLocation(t,e){dispatchEvent(new HashChangeEvent("hashchange",{oldURL:t.toString(),newURL:e.toString()}))}notifyApplicationAfterFrameLoad(t){return u("turbo:frame-load",{target:t})}notifyApplicationAfterFrameRender(t,e){return u("turbo:frame-render",{detail:{fetchResponse:t},target:e,cancelable:!0})}submissionIsNavigatable(t,e){if("off"==C.forms.mode)return!1;{const r=!e||this.elementIsNavigatable(e);return"optin"==C.forms.mode?r&&null!=t.closest('[data-turbo="true"]'):r&&this.elementIsNavigatable(t)}}elementIsNavigatable(t){const e=P(t,"[data-turbo]"),r=P(t,"turbo-frame");return C.drive.enabled||r?!e||"false"!=e.getAttribute("data-turbo"):!!e&&"true"==e.getAttribute("data-turbo")}getActionForLink(t){return O(t)||"advance"}get snapshot(){return this.view.snapshot}}(W),{cache:Ee,navigator:je}=Se;function Pe(){Se.start()}function _e(t){Se.registerAdapter(t)}function Te(t,e){Se.visit(t,e)}function ke(t){Se.connectStreamSource(t)}function xe(t){Se.disconnectStreamSource(t)}function Le(t){Se.renderStreamMessage(t)}function Re(){Se.clearCache()}function Ne(t){C.drive.progressBarDelay=t}function Ce(t){C.forms.confirm=t}function Me(t){C.forms.mode=t}var Be=Object.freeze({__proto__:null,navigator:je,session:Se,cache:Ee,PageRenderer:pe,PageSnapshot:kt,FrameRenderer:vt,fetch:K,config:C,start:Pe,registerAdapter:_e,visit:Te,connectStreamSource:ke,disconnectStreamSource:xe,renderStreamMessage:Le,clearCache:Re,setProgressBarDelay:Ne,setConfirmMethod:Ce,setFormMode:Me});class Ie extends Error{}function Fe(t){if(null!=t){const e=document.getElementById(t);if(e instanceof s)return e}}function De(t,e){if(t){const n=t.getAttribute("src");if(null!=n&&null!=e&&(r=e,M(n).href==M(r).href))throw new Error(`Matching element has a source URL which references itself`);if(t.ownerDocument!==document&&(t=document.importNode(t,!0)),t instanceof s)return t.connectedCallback(),t.disconnectedCallback(),t}var r}const qe={after(){this.targetElements.forEach((t=>t.parentElement?.insertBefore(this.templateContent,t.nextSibling)))},append(){this.removeDuplicateTargetChildren(),this.targetElements.forEach((t=>t.append(this.templateContent)))},before(){this.targetElements.forEach((t=>t.parentElement?.insertBefore(this.templateContent,t)))},prepend(){this.removeDuplicateTargetChildren(),this.targetElements.forEach((t=>t.prepend(this.templateContent)))},remove(){this.targetElements.forEach((t=>t.remove()))},replace(){const t=this.getAttribute("method");this.targetElements.forEach((e=>{"morph"===t?At(e,this.templateContent):e.replaceWith(this.templateContent)}))},update(){const t=this.getAttribute("method");this.targetElements.forEach((e=>{"morph"===t?Ot(e,this.templateContent):(e.innerHTML="",e.append(this.templateContent))}))},refresh(){Se.refresh(this.baseURI,this.requestId)}};class Ue extends HTMLElement{static async renderElement(t){await t.performAction()}async connectedCallback(){try{await this.render()}catch(t){}finally{this.disconnect()}}async render(){return this.renderPromise??=(async()=>{const t=this.beforeRenderEvent;this.dispatchEvent(t)&&(await f(),await t.detail.render(this))})()}disconnect(){try{this.remove()}catch{}}removeDuplicateTargetChildren(){this.duplicateChildren.forEach((t=>t.remove()))}get duplicateChildren(){const t=this.targetElements.flatMap((t=>[...t.children])).filter((t=>!!t.id)),e=[...this.templateContent?.children||[]].filter((t=>!!t.id)).map((t=>t.id));return t.filter((t=>e.includes(t.id)))}get performAction(){if(this.action){const t=qe[this.action];if(t)return t;this.#x("unknown action")}this.#x("action attribute is missing")}get targetElements(){return this.target?this.targetElementsById:this.targets?this.targetElementsByQuery:void this.#x("target or targets attribute is missing")}get templateContent(){return this.templateElement.content.cloneNode(!0)}get templateElement(){if(null===this.firstElementChild){const t=this.ownerDocument.createElement("template");return this.appendChild(t),t}if(this.firstElementChild instanceof HTMLTemplateElement)return this.firstElementChild;this.#x("first child element must be a