var e;var t="http://www.w3.org/1999/xhtml",n="undefined"==typeof document?void 0:document,r=!!n&&"content"in n.createElement("template"),o=!!n&&n.createRange&&"createContextualFragment"in n.createRange();function a(t){return t=t.trim(),r?function(e){var t=n.createElement("template");return t.innerHTML=e,t.content.childNodes[0]}(t):o?function(t){return e||(e=n.createRange()).selectNode(n.body),e.createContextualFragment(t).childNodes[0]}(t):function(e){var t=n.createElement("body");return t.innerHTML=e,t.childNodes[0]}(t)}function i(e,t){var n,r,o=e.nodeName,a=t.nodeName;return o===a||(n=o.charCodeAt(0),r=a.charCodeAt(0),n<=90&&r>=97?o===a.toUpperCase():r<=90&&n>=97&&a===o.toUpperCase())}function s(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n))}var l={OPTION:function(e,t){var n=e.parentNode;if(n){var r=n.nodeName.toUpperCase();"OPTGROUP"===r&&(r=(n=n.parentNode)&&n.nodeName.toUpperCase()),"SELECT"!==r||n.hasAttribute("multiple")||(e.hasAttribute("selected")&&!t.selected&&(e.setAttribute("selected","selected"),e.removeAttribute("selected")),n.selectedIndex=-1)}s(e,t,"selected")},INPUT:function(e,t){s(e,t,"checked"),s(e,t,"disabled"),e.value!==t.value&&(e.value=t.value),t.hasAttribute("value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!==n&&(e.value=n);var r=e.firstChild;if(r){var o=r.nodeValue;if(o==n||!n&&o==e.placeholder)return;r.nodeValue=n}},SELECT:function(e,t){if(!t.hasAttribute("multiple")){for(var n,r,o=-1,a=0,i=e.firstChild;i;)if("OPTGROUP"===(r=i.nodeName&&i.nodeName.toUpperCase()))i=(n=i).firstChild;else{if("OPTION"===r){if(i.hasAttribute("selected")){o=a;break}a++}!(i=i.nextSibling)&&n&&(i=n.nextSibling,n=null)}e.selectedIndex=o}}};function c(){}function u(e){if(e)return e.getAttribute&&e.getAttribute("id")||e.id}var d=function(e){return function(r,o,s){if(s||(s={}),"string"==typeof o)if("#document"===r.nodeName||"HTML"===r.nodeName||"BODY"===r.nodeName){var d=o;(o=n.createElement("html")).innerHTML=d}else o=a(o);var m=s.getNodeKey||u,h=s.onBeforeNodeAdded||c,f=s.onNodeAdded||c,p=s.onBeforeElUpdated||c,b=s.onElUpdated||c,g=s.onBeforeNodeDiscarded||c,y=s.onNodeDiscarded||c,v=s.onBeforeElChildrenUpdated||c,w=!0===s.childrenOnly,E=Object.create(null),A=[];function T(e){A.push(e)}function S(e,t){if(1===e.nodeType)for(var n=e.firstChild;n;){var r=void 0;t&&(r=m(n))?T(r):(y(n),n.firstChild&&S(n,t)),n=n.nextSibling}}function C(e,t,n){!1!==g(e)&&(t&&t.removeChild(e),y(e),S(e,n))}function N(e){f(e);for(var t=e.firstChild;t;){var n=t.nextSibling,r=m(t);if(r){var o=E[r];o&&i(t,o)?(t.parentNode.replaceChild(o,t),x(o,t)):N(t)}else N(t);t=n}}function x(t,r,o){var a=m(r);if(a&&delete E[a],!o){if(!1===p(t,r))return;if(e(t,r),b(t),!1===v(t,r))return}"TEXTAREA"!==t.nodeName?function(e,t){var r,o,a,s,c,u=t.firstChild,d=e.firstChild;e:for(;u;){for(s=u.nextSibling,r=m(u);d;){if(a=d.nextSibling,u.isSameNode&&u.isSameNode(d)){u=s,d=a;continue e}o=m(d);var f=d.nodeType,p=void 0;if(f===u.nodeType&&(1===f?(r?r!==o&&((c=E[r])?a===c?p=!1:(e.insertBefore(c,d),o?T(o):C(d,e,!0),d=c):p=!1):o&&(p=!1),(p=!1!==p&&i(d,u))&&x(d,u)):3!==f&&8!=f||(p=!0,d.nodeValue!==u.nodeValue&&(d.nodeValue=u.nodeValue))),p){u=s,d=a;continue e}o?T(o):C(d,e,!0),d=a}if(r&&(c=E[r])&&i(c,u))e.appendChild(c),x(c,u);else{var b=h(u);!1!==b&&(b&&(u=b),u.actualize&&(u=u.actualize(e.ownerDocument||n)),e.appendChild(u),N(u))}u=s,d=a}!function(e,t,n){for(;t;){var r=t.nextSibling;(n=m(t))?T(n):C(t,e,!0),t=r}}(e,d,o);var g=l[e.nodeName];g&&g(e,t)}(t,r):l.TEXTAREA(t,r)}!function e(t){if(1===t.nodeType||11===t.nodeType)for(var n=t.firstChild;n;){var r=m(n);r&&(E[r]=n),e(n),n=n.nextSibling}}(r);var L=r,O=L.nodeType,M=o.nodeType;if(!w)if(1===O)1===M?i(r,o)||(y(r),L=function(e,t){for(var n=e.firstChild;n;){var r=n.nextSibling;t.appendChild(n),n=r}return t}(r,function(e,r){return r&&r!==t?n.createElementNS(r,e):n.createElement(e)}(o.nodeName,o.namespaceURI))):L=o;else if(3===O||8===O){if(M===O)return L.nodeValue!==o.nodeValue&&(L.nodeValue=o.nodeValue),L;L=o}if(L===o)y(r);else{if(o.isSameNode&&o.isSameNode(L))return;if(x(L,o,w),A)for(var $=0,R=A.length;$<R;$++){var U=E[A[$]];U&&C(U,U.parentNode,!1)}}return!w&&L!==r&&r.parentNode&&(L.actualize&&(L=L.actualize(r.ownerDocument||n)),r.parentNode.replaceChild(L,r)),L}}((function(e,t){var n,r,o,a,i=t.attributes;if(11!==t.nodeType&&11!==e.nodeType){for(var s=i.length-1;s>=0;s--)r=(n=i[s]).name,o=n.namespaceURI,a=n.value,o?(r=n.localName||r,e.getAttributeNS(o,r)!==a&&("xmlns"===n.prefix&&(r=n.name),e.setAttributeNS(o,r,a))):e.getAttribute(r)!==a&&e.setAttribute(r,a);for(var l=e.attributes,c=l.length-1;c>=0;c--)r=(n=l[c]).name,(o=n.namespaceURI)?(r=n.localName||r,t.hasAttributeNS(o,r)||e.removeAttributeNS(o,r)):t.hasAttribute(r)||e.removeAttribute(r)}})),m="5.0.1";const h={INPUT:!0,TEXTAREA:!0,SELECT:!0},f={INPUT:!0,TEXTAREA:!0,OPTION:!0},p={"datetime-local":!0,"select-multiple":!0,"select-one":!0,color:!0,date:!0,datetime:!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,textarea:!0,time:!0,url:!0,week:!0};let b;var g={get element(){return b},set(e){b=e}};const y=e=>h[e.tagName]&&p[e.type],v=e=>{const t=(e&&e.nodeType===Node.ELEMENT_NODE?e:document.querySelector(e))||g.element;t&&t.focus&&t.focus()},w=(e,t,n={})=>{const r=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e.dispatchEvent(r),window.jQuery&&window.jQuery(e).trigger(t,n)},E=e=>document.evaluate(e,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,A=(e,t=!1)=>{const n=document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=[];for(let e=0;e<n.snapshotLength;e++)r.push(n.snapshotItem(e));return t?r.reverse():r},T=e=>Array.from(e).flat(),S=(e,t)=>{Array.from(e.selectAll?e.element:[e.element]).forEach(t)},C=(N=function(e,t,n){return e+(n?"-":"")+t.toLowerCase()},function(e){return x(e).reduce(N,"")});var N;const x=e=>(e=null==e?"":e).match(/([A-Z]{2,}|[0-9]+|[A-Z]?[a-z]+|[A-Z])/g)||[],L=(e,t)=>!e.cancel&&(e.delay?setTimeout(t,e.delay):t(),!0),O=(e,t)=>w(e,`cable-ready:before-${C(t.operation)}`,t),M=(e,t)=>w(e,`cable-ready:after-${C(t.operation)}`,t);function $(e,t=250){let n;return(...r)=>{n&&clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}}function R(e){if(!e.ok)throw Error(e.statusText);return e}function U(e){return void 0===e||["string","number","boolean"].includes(typeof e)||console.warn(`Operation expects a string, number or boolean, but got ${e} (${typeof e})`),null!=e?e:""}function D(e){return void 0!==e&&"string"!=typeof e&&console.warn(`Operation expects a string, but got ${e} (${typeof e})`),null!=e?String(e):""}function k(e){return void 0===e||Array.isArray(e)||console.warn(`Operation expects an array, but got ${e} (${typeof e})`),null!=e?Array.from(e):[]}function I(e){return void 0!==e&&"object"!=typeof e&&console.warn(`Operation expects an object, but got ${e} (${typeof e})`),null!=e?Object(e):{}}function P(e){return void 0===e||Array.isArray(e)||"string"==typeof e||console.warn(`Operation expects an Array or a String, but got ${e} (${typeof e})`),null==e?"":Array.isArray(e)?Array.from(e):String(e)}async function q(e,t){try{const n=await fetch(e,{headers:{"X-REQUESTED-WITH":"XmlHttpRequest",...t}});if(null==n)return;return R(n),n}catch(t){console.error(`Could not fetch ${e}`)}}class H{constructor(e){this.maxSize=e,this.queue=[]}push(e){this.isFull()&&this.shift(),this.queue.push(e)}shift(){return this.queue.shift()}isFull(){return this.queue.length===this.maxSize}}Object.freeze({__proto__:null,BoundedQueue:H,after:M,assignFocus:v,before:O,debounce:$,dispatch:w,fragmentToString:function(e){return(new XMLSerializer).serializeToString(e)},getClassNames:T,graciouslyFetch:q,handleErrors:R,isTextInput:y,kebabize:C,operate:L,processElements:S,safeArray:k,safeObject:I,safeScalar:U,safeString:D,safeStringOrArray:P,xpathToElement:E,xpathToElementArray:A});const _=e=>(t,n)=>!X.map((r=>"function"!=typeof r||r(e,t,n))).includes(!1),j=e=>t=>{B.forEach((n=>{"function"==typeof n&&n(e,t)}))},z=(e,t,n)=>!(!f[t.tagName]&&t.isEqualNode(n)),F=(e,t,n)=>t!==g.element||!t.isContentEditable,V=(e,t,n)=>{const{permanentAttributeName:r}=e;if(!r)return!0;const o=t.closest(`[${r}]`);if(!o&&t===g.element&&y(t)){const e={value:!0};return Array.from(n.attributes).forEach((n=>{e[n.name]||t.setAttribute(n.name,n.value)})),!1}return!o},X=[z,V,F],B=[];Object.freeze({__proto__:null,didMorph:j,didMorphCallbacks:B,shouldMorph:_,shouldMorphCallbacks:X,verifyNotContentEditable:F,verifyNotMutable:z,verifyNotPermanent:V});var Y={append:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{html:n,focusSelector:r}=e;t.insertAdjacentHTML("beforeend",U(n)),v(r)})),M(t,e)}))},graft:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{parent:n,focusSelector:r}=e,o=document.querySelector(n);o&&(o.appendChild(t),v(r))})),M(t,e)}))},innerHtml:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{html:n,focusSelector:r}=e;t.innerHTML=U(n),v(r)})),M(t,e)}))},insertAdjacentHtml:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{html:n,position:r,focusSelector:o}=e;t.insertAdjacentHTML(r||"beforeend",U(n)),v(o)})),M(t,e)}))},insertAdjacentText:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{text:n,position:r,focusSelector:o}=e;t.insertAdjacentText(r||"beforeend",U(n)),v(o)})),M(t,e)}))},outerHtml:e=>{S(e,(t=>{const n=t.parentElement,r=n&&Array.from(n.children).indexOf(t);O(t,e),L(e,(()=>{const{html:n,focusSelector:r}=e;t.outerHTML=U(n),v(r)})),M(n?n.children[r]:document.documentElement,e)}))},prepend:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{html:n,focusSelector:r}=e;t.insertAdjacentHTML("afterbegin",U(n)),v(r)})),M(t,e)}))},remove:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{focusSelector:n}=e;t.remove(),v(n)})),M(document,e)}))},replace:e=>{S(e,(t=>{const n=t.parentElement,r=n&&Array.from(n.children).indexOf(t);O(t,e),L(e,(()=>{const{html:n,focusSelector:r}=e;t.outerHTML=U(n),v(r)})),M(n?n.children[r]:document.documentElement,e)}))},textContent:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{text:n,focusSelector:r}=e;t.textContent=U(n),v(r)})),M(t,e)}))},addCssClass:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n}=e;t.classList.add(...T([P(n)]))})),M(t,e)}))},removeAttribute:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n}=e;t.removeAttribute(D(n))})),M(t,e)}))},removeCssClass:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n}=e;t.classList.remove(...T([P(n)])),0===t.classList.length&&t.removeAttribute("class")})),M(t,e)}))},setAttribute:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n,value:r}=e;t.setAttribute(D(n),U(r))})),M(t,e)}))},setDatasetProperty:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n,value:r}=e;t.dataset[D(n)]=U(r)})),M(t,e)}))},setProperty:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n,value:r}=e;n in t&&(t[D(n)]=U(r))})),M(t,e)}))},setStyle:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n,value:r}=e;t.style[D(n)]=U(r)})),M(t,e)}))},setStyles:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{styles:n}=e;for(let[e,r]of Object.entries(n))t.style[D(e)]=U(r)})),M(t,e)}))},setValue:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{value:n}=e;t.value=U(n)})),M(t,e)}))},dispatchEvent:e=>{S(e,(t=>{O(t,e),L(e,(()=>{const{name:n,detail:r}=e;w(t,D(n),I(r))})),M(t,e)}))},setMeta:e=>{O(document,e),L(e,(()=>{const{name:t,content:n}=e;let r=document.head.querySelector(`meta[name='${t}']`);r||(r=document.createElement("meta"),r.name=D(t),document.head.appendChild(r)),r.content=U(n)})),M(document,e)},setTitle:e=>{O(document,e),L(e,(()=>{const{title:t}=e;document.title=U(t)})),M(document,e)},clearStorage:e=>{O(document,e),L(e,(()=>{const{type:t}=e;("session"===t?sessionStorage:localStorage).clear()})),M(document,e)},go:e=>{O(window,e),L(e,(()=>{const{delta:t}=e;history.go(t)})),M(window,e)},pushState:e=>{O(window,e),L(e,(()=>{const{state:t,title:n,url:r}=e;history.pushState(I(t),D(n),D(r))})),M(window,e)},redirectTo:e=>{O(window,e),L(e,(()=>{let{url:t,action:n,turbo:r}=e;n=n||"advance",t=D(t),void 0===r&&(r=!0),r?(window.Turbo&&window.Turbo.visit(t,{action:n}),window.Turbolinks&&window.Turbolinks.visit(t,{action:n}),window.Turbo||window.Turbolinks||(window.location.href=t)):window.location.href=t})),M(window,e)},reload:e=>{O(window,e),L(e,(()=>{window.location.reload()})),M(window,e)},removeStorageItem:e=>{O(document,e),L(e,(()=>{const{key:t,type:n}=e;("session"===n?sessionStorage:localStorage).removeItem(D(t))})),M(document,e)},replaceState:e=>{O(window,e),L(e,(()=>{const{state:t,title:n,url:r}=e;history.replaceState(I(t),D(n),D(r))})),M(window,e)},scrollIntoView:e=>{const{element:t}=e;O(t,e),L(e,(()=>{t.scrollIntoView(e)})),M(t,e)},setCookie:e=>{O(document,e),L(e,(()=>{const{cookie:t}=e;document.cookie=U(t)})),M(document,e)},setFocus:e=>{const{element:t}=e;O(t,e),L(e,(()=>{v(t)})),M(t,e)},setStorageItem:e=>{O(document,e),L(e,(()=>{const{key:t,value:n,type:r}=e;("session"===r?sessionStorage:localStorage).setItem(D(t),U(n))})),M(document,e)},consoleLog:e=>{O(document,e),L(e,(()=>{const{message:t,level:n}=e;n&&["warn","info","error"].includes(n)?console[n](t):console.log(t)})),M(document,e)},consoleTable:e=>{O(document,e),L(e,(()=>{const{data:t,columns:n}=e;console.table(t,k(n))})),M(document,e)},notification:e=>{O(document,e),L(e,(()=>{const{title:t,options:n}=e;Notification.requestPermission().then((r=>{e.permission=r,"granted"===r&&new Notification(D(t),I(n))}))})),M(document,e)},morph:e=>{S(e,(t=>{const{html:n}=e,r=document.createElement("template");r.innerHTML=String(U(n)).trim(),e.content=r.content;const o=t.parentElement,a=o&&Array.from(o.children).indexOf(t);O(t,e),L(e,(()=>{const{childrenOnly:n,focusSelector:o}=e;d(t,n?r.content:r.innerHTML,{childrenOnly:!!n,onBeforeElUpdated:_(e),onElUpdated:j(e)}),v(o)})),M(o?o.children[a]:document.documentElement,e)}))}};let Q=Y;const Z=e=>{Q={...Q,...e}};var G={get all(){return Q}};let J="warn";var K={get behavior(){return J},set(e){["warn","ignore","event","exception"].includes(e)?J=e:console.warn("Invalid 'onMissingElement' option. Defaulting to 'warn'.")}};const W=(e,t={onMissingElement:K.behavior})=>{const n={};e.forEach((e=>{e.batch&&(n[e.batch]=n[e.batch]?++n[e.batch]:1)})),e.forEach((e=>{const r=e.operation;try{if(e.selector?e.xpath?e.element=e.selectAll?A(e.selector):E(e.selector):e.element=e.selectAll?document.querySelectorAll(e.selector):document.querySelector(e.selector):e.element=document,e.element||"ignore"!==t.onMissingElement){g.set(document.activeElement);const t=G.all[r];t?(t(e),e.batch&&0==--n[e.batch]&&w(document,"cable-ready:batch-complete",{batch:e.batch})):console.error(`CableReady couldn't find the "${r}" operation. Make sure you use the camelized form when calling an operation method.`)}}catch(n){if(e.element)console.error(`CableReady detected an error in ${r||"operation"}: ${n.message}. If you need to support older browsers make sure you've included the corresponding polyfills. https://docs.stimulusreflex.com/setup#polyfills-for-ie11.`),console.error(n);else{const n=`CableReady ${r||""} operation failed due to missing DOM element for selector: '${e.selector}'`;switch(t.onMissingElement){case"ignore":break;case"event":w(document,"cable-ready:missing-element",{warning:n,operation:e});break;case"exception":throw n;default:console.warn(n)}}}}))};class ee extends HTMLElement{static get tagName(){throw new Error("Implement the tagName() getter in the inheriting class")}static define(){customElements.get(this.tagName)||customElements.define(this.tagName,this)}disconnectedCallback(){this.channel&&this.channel.unsubscribe()}createSubscription(e,t,n){this.channel=e.subscriptions.create({channel:t,identifier:this.identifier},{received:n})}get preview(){return document.documentElement.hasAttribute("data-turbolinks-preview")||document.documentElement.hasAttribute("data-turbo-preview")}get identifier(){return this.getAttribute("identifier")}}let te;const ne=[25,50,75,100,200,250,500,800,1e3,2e3],re=async(e=0)=>{if(te)return te;if(e>=ne.length)throw new Error("Couldn't obtain a Action Cable consumer within 5s");var t;return await(t=ne[e],new Promise((e=>setTimeout(e,t)))),await re(e+1)};var oe={setConsumer(e){te=e},get consumer(){return te},getConsumer:async()=>await re()};class ae extends ee{static get tagName(){return"cable-ready-stream-from"}async connectedCallback(){if(this.preview)return;const e=await oe.getConsumer();e?this.createSubscription(e,"CableReady::Stream",this.performOperations.bind(this)):console.error("The `cable_ready_stream_from` helper cannot connect. You must initialize CableReady with an Action Cable consumer.")}performOperations(e){e.cableReady&&W(e.operations,{onMissingElement:this.onMissingElement})}get onMissingElement(){const e=this.getAttribute("missing")||K.behavior;return["warn","ignore","event"].includes(e)?e:(console.warn("Invalid 'missing' attribute. Defaulting to 'warn'."),"warn")}}let ie=!1;var se={get enabled(){return ie},get disabled(){return!ie},get value(){return ie},set(e){ie=!!e},set debug(e){ie=!!e}};var le=(e,t)=>{if(se.disabled)return;const n=`↑ Updatable request affecting ${t.length} element(s): `;return console.log(n,{elements:t.map((e=>e.element)),identifiers:t.map((e=>e.element.getAttribute("identifier"))),data:e}),n},ce=(e,t)=>{if(se.disabled)return;const n=`❌ Updatable request canceled after ${new Date-e}ms: ${t}`;return console.log(n),n},ue=(e,t,n)=>{if(se.disabled)return;const r=`↓ Updatable response: All URLs fetched in ${new Date-e}ms`;return console.log(r,{element:t,urls:n}),r},de=(e,t)=>{if(se.disabled)return;const n=`↻ Updatable morph: starting after ${new Date-e}ms`;return console.log(n,{element:t}),n},me=(e,t)=>{if(se.disabled)return;const n=`↺ Updatable morph: completed after ${new Date-e}ms`;return console.log(n,{element:t}),n};class he extends ee{static get tagName(){return"cable-ready-updates-for"}constructor(){super();this.attachShadow({mode:"open"}).innerHTML="\n<style>\n  :host {\n    display: block;\n  }\n</style>\n<slot></slot>\n",this.triggerElementLog=new H(10),this.targetElementLog=new H(10)}async connectedCallback(){if(this.preview)return;this.update=$(this.update.bind(this),this.debounce);const e=await oe.getConsumer();e?this.createSubscription(e,"CableReady::Stream",this.update):console.error("The `cable_ready_updates_for` helper cannot connect. You must initialize CableReady with an Action Cable consumer.")}async update(e){this.lastUpdateTimestamp=new Date;const t=Array.from(document.querySelectorAll(this.query),(e=>new fe(e))).filter((t=>t.shouldUpdate(e)));if(this.triggerElementLog.push(`${(new Date).toLocaleString()}: ${le(e,t)}`),0===t.length)return void this.triggerElementLog.push(`${(new Date).toLocaleString()}: ${ce(this.lastUpdateTimestamp,"All elements filtered out")}`);if(t[0].element!==this)return void this.triggerElementLog.push(`${(new Date).toLocaleString()}: ${ce(this.lastUpdateTimestamp,"Update already requested")}`);g.set(document.activeElement),this.html={};const n=[...new Set(t.map((e=>e.url)))];await Promise.all(n.map((async e=>{if(!this.html.hasOwnProperty(e)){const t=await q(e,{"X-Cable-Ready":"update"});this.html[e]=await t.text()}}))),this.triggerElementLog.push(`${(new Date).toLocaleString()}: ${ue(this.lastUpdateTimestamp,this,n)}`),this.index={},t.forEach((t=>{this.index.hasOwnProperty(t.url)?this.index[t.url]++:this.index[t.url]=0,t.process(e,this.html,this.index,this.lastUpdateTimestamp)}))}get query(){return`${this.tagName}[identifier="${this.identifier}"]`}get identifier(){return this.getAttribute("identifier")}get debounce(){return this.hasAttribute("debounce")?parseInt(this.getAttribute("debounce")):20}}class fe{constructor(e){this.element=e}async process(e,t,n,r){const o=n[this.url],a=document.createElement("template");this.element.setAttribute("updating","updating"),a.innerHTML=String(t[this.url]).trim(),await this.resolveTurboFrames(a.content);const i=a.content.querySelectorAll(this.query);if(i.length<=o)return void console.warn(`Update aborted due to insufficient number of elements. The offending url is ${this.url}, the offending element is:`,this.element);const s={element:this.element,html:i[o],permanentAttributeName:"data-ignore-updates"};w(this.element,"cable-ready:before-update",s),this.element.targetElementLog.push(`${(new Date).toLocaleString()}: ${de(r,this.element)}`),d(this.element,i[o],{childrenOnly:!0,onBeforeElUpdated:_(s),onElUpdated:e=>{this.element.removeAttribute("updating"),w(this.element,"cable-ready:after-update",s),v(s.focusSelector)}}),this.element.targetElementLog.push(`${(new Date).toLocaleString()}: ${me(r,this.element)}`)}async resolveTurboFrames(e){const t=[...e.querySelectorAll('turbo-frame[src]:not([loading="lazy"])')];return Promise.all(t.map((t=>new Promise((async n=>{const r=await q(t.getAttribute("src"),{"Turbo-Frame":t.id,"X-Cable-Ready":"update"}),o=document.createElement("template");o.innerHTML=await r.text(),await this.resolveTurboFrames(o.content);const a=`turbo-frame#${t.id}`,i=o.content.querySelector(a),s=i?i.innerHTML.trim():"";e.querySelector(a).innerHTML=s,n()})))))}shouldUpdate(e){return!this.ignoresInnerUpdates&&this.hasChangesSelectedForUpdate(e)}hasChangesSelectedForUpdate(e){const t=this.element.getAttribute("only");return!(t&&e.changed&&!t.split(" ").some((t=>e.changed.includes(t))))}get ignoresInnerUpdates(){return this.element.hasAttribute("ignore-inner-updates")&&this.element.hasAttribute("performing-inner-update")}get url(){return this.element.hasAttribute("url")?this.element.getAttribute("url"):location.href}get identifier(){return this.element.identifier}get query(){return this.element.query}}const pe=e=>{const t=e&&e.parentElement&&e.parentElement.closest("cable-ready-updates-for");t&&(t.setAttribute("performing-inner-update",""),pe(t))},be=e=>{const t=e&&e.parentElement&&e.parentElement.closest("cable-ready-updates-for");t&&(t.removeAttribute("performing-inner-update"),be(t))},ge=()=>{document.addEventListener("stimulus-reflex:before",(e=>{pe(e.detail.element)})),document.addEventListener("stimulus-reflex:after",(e=>{setTimeout((()=>{be(e.detail.element)}))})),document.addEventListener("turbo:submit-start",(e=>{pe(e.target)})),document.addEventListener("turbo:submit-end",(e=>{setTimeout((()=>{be(e.target)}))})),document.addEventListener("turbo-boost:command:start",(e=>{pe(e.target)})),document.addEventListener("turbo-boost:command:finish",(e=>{setTimeout((()=>{be(e.target)}))})),document.addEventListener("turbo-boost:command:error",(e=>{setTimeout((()=>{be(e.target)}))})),ae.define(),he.define()},ye={perform:W,performAsync:(e,t={onMissingElement:K.behavior})=>new Promise(((n,r)=>{try{n(W(e,t))}catch(e){r(e)}})),shouldMorphCallbacks:X,didMorphCallbacks:B,initialize:(e={})=>{const{consumer:t,onMissingElement:n,debug:r}=e;se.set(!!r),t?oe.setConsumer(t):console.error("CableReady requires a reference to your Action Cable `consumer` for its helpers to function.\nEnsure that you have imported the `CableReady` package as well as `consumer` from your `channels` folder, then call `CableReady.initialize({ consumer })`."),n&&MissingElement.set(n),ge()},addOperation:(e,t)=>{const n={};n[e]=t,Z(n)},addOperations:e=>{Z(e)},version:m,cable:oe,get DOMOperations(){return console.warn("DEPRECATED: Please use `CableReady.operations` instead of `CableReady.DOMOperations`"),G.all},get operations(){return G.all},get consumer(){return oe.consumer}};window.CableReady=ye;class ve extends HTMLElement{static define(){customElements.get("cable-ready")||customElements.define("cable-ready",this)}connectedCallback(){setTimeout((()=>{try{const e=JSON.parse(this.scriptElement.textContent);ye.perform(e)}catch(e){console.error(e)}finally{try{this.remove()}catch{}}}))}get scriptElement(){if(this.firstElementChild instanceof HTMLScriptElement&&"application/json"===this.firstElementChild.getAttribute("type"))return this.firstElementChild;throw new Error('First child element in a `<cable-ready>` tag must be `<script type="application/json">`.')}}ve.define();export{ve as CableReadyElement};
//# sourceMappingURL=cable_ready-element.min.js.map