@adia-ai/web-modules 0.8.28 → 0.8.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,12 +7,12 @@ var nC=Object.defineProperty;var W=(s,t,e)=>()=>{if(e)throw e[0];try{return s&&(
7
7
  `+c+" Compute the full attr value as a single expression and interpolate the whole.")}continue}let a=+o[1],l=n.name;l[0]==="@"?(r.removeAttribute(l),e[a]={t:"e",n:r,name:l.slice(1),c:void 0,_fx:null}):l[0]==="."?(r.removeAttribute(l),e[a]={t:"p",n:r,name:fy(r,l.slice(1)),c:void 0,_fx:null,_resolved:!1}):l[0]==="?"?(r.removeAttribute(l),console.warn(`[template] Lit-style boolean attribute "${l}=" is not supported.
8
8
  Element: <${r.tagName.toLowerCase()}>
9
9
  Use .${l.slice(1)}=\${value} (property binding) instead \u2014 the primitive reflects the property to the DOM attribute for you.
10
- See USAGE.md \xA7 Template parser \u2014 invariants + unsupported syntaxes.`),e[a]={t:"n",n:document.createTextNode(""),c:void 0,_fx:null}):e[a]={t:"a",n:r,name:l,c:void 0,_fx:null}}return e}function Ih(s){for(let t of s)t&&t._fx&&(t._fx(),t._fx=null)}function Wd(s){if(s.n.nodeType===1&&s.n[jd])return s.n;let t=document.createElement("span");return t.style.display="contents",t.setAttribute("role","presentation"),t[jd]=!0,s.n.replaceWith(t),s.n=t,t}function Fd(s,t){if(t!==s.c){if(s.t==="n")if(t!=null&&t._directive)t._commit(Wd(s));else if(gy(t))rr(t,Wd(s));else if(Array.isArray(t)){let e=Wd(s);e.replaceChildren();for(let i of t)if(gy(i)){let r=document.createElement("span");r.style.display="contents",r.setAttribute("role","presentation"),e.appendChild(r),rr(i,r)}else e.appendChild(document.createTextNode(i??""))}else if(t instanceof Node)s.n.replaceWith(t),s.n=t;else if(s.n[jd]){let e=document.createTextNode(t??"");s.n.replaceWith(e),s.n=e}else s.n.textContent=t??"";else if(s.t==="a")t==null||t===!1?s.n.removeAttribute(s.name):s.n.setAttribute(s.name,t===!0?"":t);else if(s.t==="p"){if(!s._resolved){let e=fy(s.n,s.name);e!==s.name&&(s.name=e),s._resolved=!0}s.n[s.name]=t}else s.t==="e"&&(by(s.c)&&s.n.removeEventListener(s.name,s.c),by(t)&&s.n.addEventListener(s.name,t));s.c=t}}function OC(s,t){for(let e=0;e<s.length;e++){let i=s[e];if(!i)continue;let r=t[e],n=i.t!=="e"&&typeof r=="function",o=!n&&i.t!=="e"&&Vd(r);if(i._fx&&!n&&!o&&(i._fx(),i._fx=null),n){i._fx||(i._fx=cs(()=>Fd(i,r())));continue}if(o){i._fx||(i._fx=cs(()=>Fd(i,r.value)));continue}Fd(i,r)}}function yC(s,t,e){return{_directive:!0,_commit(i){let r=i[nr]||new Map,n=new Map,o=[];for(let l=0;l<s.length;l++){let h=t(s[l],l);if(n.has(h))continue;o.push(h);let c=e(s[l],l);if(r.has(h)){let u=r.get(h);rr(c,u),n.set(h,u)}else{let u=document.createElement("span");u.style.display="contents",u.setAttribute("role","presentation"),rr(c,u),n.set(h,u)}}for(let[l,h]of r)n.has(l)||(h._i&&Ih(h._i.p),h.remove());let a=null;for(let l=o.length-1;l>=0;l--){let h=n.get(o[l]);(h.nextSibling!==a||h.parentNode!==i)&&i.insertBefore(h,a),a=h}i[nr]=n}}}var jd,nr,uy,dy,Rh,La,py,gy,by,Ud=W(()=>{"use strict";Pt();[jd,nr]=[Symbol(),Symbol()];uy=new WeakMap;dy={classname:"className",innertext:"innerText",innerhtml:"innerHTML",outerhtml:"outerHTML",textcontent:"textContent",tabindex:"tabIndex",arialabel:"ariaLabel",ariadescribedby:"ariaDescribedBy",arialabelledby:"ariaLabelledBy",ariarole:"role",contenteditable:"contentEditable",readonly:"readOnly",maxlength:"maxLength",minlength:"minLength",colspan:"colSpan",rowspan:"rowSpan",cellpadding:"cellPadding",cellspacing:"cellSpacing",usemap:"useMap",ismap:"isMap",accesskey:"accessKey",defaultchecked:"defaultChecked",defaultvalue:"defaultValue",defaultselected:"defaultSelected"};Rh="http://www.w3.org/2000/svg",La="http://www.w3.org/1998/Math/MathML",py="http://www.w3.org/1999/xhtml";gy=s=>s!=null&&typeof s=="object"&&s.strings,by=s=>typeof s=="function"||s!=null&&typeof s.handleEvent=="function"});function yy(s){if(!s.name)throw new Error("Trait requires a name");if(!s.setup)throw new Error(`Trait "${s.name}" requires a setup function`);if(!s.category)throw new Error(`Trait "${s.name}" requires a category`);if(!Oy.has(s.category))throw new Error(`Trait "${s.name}" has unknown category "${s.category}". Known: ${[...Oy].join(", ")}`);if(!s.description)throw new Error(`Trait "${s.name}" requires a description`);let t=Object.freeze({name:s.name,category:s.category,description:s.description,attributes:Object.freeze(s.attributes||[]),events:Object.freeze(s.events||[]),config:Object.freeze(s.config||[])});function e(){let i=null;return{schema:t,connect(r,n){i=s.setup({host:r,...n||{}})},disconnect(r){i&&(i(),i=null);for(let n of t.attributes)r.hasAttribute(n)&&(console.warn(`Trait "${t.name}": attribute "${n}" still present after disconnect`),r.removeAttribute(n))}}}return e.schema=t,Dh.set(s.name,e),e}function vy(s){return Dh.get(s)||null}function Pq(s){return Dh.get(s)?.schema||null}function Qq(){return[...Dh.keys()]}var Dh,Oy,Yd=W(()=>{"use strict";Dh=new Map,Oy=new Set(["input-interaction","keyboard-navigation","forms-data","layout-measurement","motion-positioning","animation-feedback","visual-dynamics","interaction-delight","audio-haptics-sensory"])});function vC(s,t){s[Ma]=new Map,s[Hd]=new Map;for(let[e,i]of Object.entries(t)){let r=i.attribute??e.toLowerCase(),n=i.type??String,o=Object.prototype.hasOwnProperty.call(s,e),a=o?s[e]:void 0;o&&delete s[e];let l=Zi(i.default??void 0);s[Hd].set(e,l),Object.defineProperty(s,e,{get(){return l.value},set(h){let c=l.peek();Object.is(c,h)||(s[Ma].set(e,c),l.value=h,i.reflect&&SC(s,r,h,n))},configurable:!0}),o&&(l.value=a)}}function SC(s,t,e,i){i===Boolean?e?s.setAttribute(t,""):s.removeAttribute(t):e==null?s.removeAttribute(t):s.setAttribute(t,String(e))}function wC(s){if(Object.hasOwn(s,"_sa"))return;s._sa=!0;let t=s.styles;if(!t||!("adoptedStyleSheets"in document))return;let e=Array.isArray(t)?t:[t];document.adoptedStyleSheets=[...document.adoptedStyleSheets,...e.filter(i=>!document.adoptedStyleSheets.includes(i))]}function Sy(s){if(Object.hasOwn(s,"_pp"))return;s._pp={};let t=s.parts;if(t)for(let[e,i]of Object.entries(t)){let r=document.createElement("template");r.innerHTML=i,s._pp[e]=r.content.firstElementChild}}var Hd,Ma,xC,xy,v,P=W(()=>{"use strict";Pt();Ud();Pt();Ud();Yd();Hd=Symbol(),Ma=Symbol();xC=Object.freeze({setFormValue(){},setValidity(){},checkValidity(){return!0},reportValidity(){return!0},get form(){return null},get labels(){return[]},get validity(){return{}},get validationMessage(){return""},get willValidate(){return!1}});xy=(s,t)=>t===Boolean?s!==null:t===Number?s===null?null:+s:s;v=class extends HTMLElement{static get properties(){return{}}static get traits(){return[]}static get observedAttributes(){let t=Object.entries(this.properties).map(([e,i])=>i.attribute??e.toLowerCase());return t.includes("traits")?t:[...t,"traits"]}#t=[];#e=[];#i=[];#s=null;#r=null;#n=null;#a=Zi(0);constructor(){super(),this.internals=typeof this.attachInternals=="function"?this.attachInternals():xC,vC(this,this.constructor.properties)}connectedCallback(){let t=this.constructor;t._tag||(t._tag=this.localName),wC(t),Sy(t);for(let[e,i]of Object.entries(t.properties)){let r=i.attribute??e.toLowerCase();this.hasAttribute(r)&&(this[e]=xy(this.getAttribute(r),i.type??String))}H(()=>this.connected()),this.#t.push(cs(()=>{for(let i of this[Hd].values())i.value;this.#a.value;let e=t.template(this);if(e&&rr(e,this),this.render(),this[Ma].size){let i=new Map(this[Ma]);this[Ma].clear(),this.updated(i)}},{host:this.localName,onError:this.onError?e=>this.onError(e):null})),this.#n||(this.#n=new Set);for(let e of t.traits)this.#l(e);this.#h(),this.#s&&this.#o()}disconnectedCallback(){this._i&&Ih(this._i.p);for(let t of this.#t)t();this.#t.length=0;for(let t of this.#i)t.value=void 0;this.#i.length=0;for(let t of this.#e)t.disconnect(this);this.#e.length=0,this.#n?.clear(),this.#r?.(),this.#r=null,this.#s?.disconnect?.(this),this.disconnected()}#o(){let t=this.#s;t.connect?.(this),this.#r=t.subscribe?.(()=>{this.#a.value++})}get controller(){return this.#s}set controller(t){this.#r?.(),this.#r=null,this.#s?.disconnect?.(this),this.#s=t,t&&this.isConnected&&this.#o()}#l(t,{declarative:e=!1}={}){this.#n.add(t);let i=t();i.connect(this,{host:this,signal:Zi,computed:_d,effect:cs}),e&&(i._declarative=!0),this.#e.push(i)}addTrait(t){return this.#n||(this.#n=new Set),this.#n.has(t)?this:(this.#l(t),this)}#h(){let t=this.getAttribute("traits");if(t)for(let e of t.split(/\s+/).filter(Boolean)){let i=vy(e);if(!i){console.warn(`<${this.localName}> traits="${e}" \u2014 trait not found. Did you forget to import it?`);continue}this.#n.has(i)||this.#l(i,{declarative:!0})}}#c(){if(!this.#n)return;let t=[];for(let e of this.#e)if(e._declarative){e.disconnect(this);for(let i of this.#n)if(i.schema?.name&&e.schema?.name===i.schema.name){this.#n.delete(i);break}}else t.push(e);this.#e.length=0,this.#e.push(...t),this.#h()}attributeChangedCallback(t,e,i){if(t==="traits"){this.isConnected&&this.#c();return}for(let[r,n]of Object.entries(this.constructor.properties))if((n.attribute??r.toLowerCase())===t){this[r]=xy(i,n.type??String);break}}static template=()=>null;static create(t={}){let e=this._tag??customElements.getName?.(this);if(!e)throw new Error("Component not registered");let i=document.createElement(e);for(let[r,n]of Object.entries(t))i[r]=n;return i}signal(t){let e=Zi(t);return this.#i.push(e),e}ensure(t){for(let n of this.children)if(n.getAttribute("slot")===t)return n;let e=this.#d(t);if(e)return e;Sy(this.constructor);let i=this.constructor._pp?.[t];if(!i)return null;let r=i.cloneNode(!0);return r._uiPart=!0,this.appendChild(r),r}drop(t){for(let i of this.children)if(i.getAttribute("slot")===t){i.remove();return}let e=this.#d(t);e&&e.remove()}#d(t){for(let e of this.querySelectorAll(`[slot="${t}"]`)){let i=e.parentElement,r=!0;for(;i&&i!==this;){if(i.localName.includes("-")){r=!1;break}i=i.parentElement}if(r&&i===this)return e}return null}reconcile(t,e,i,r){let n=t[nr]||new Map,o=new Map,a=[];for(let h=0;h<e.length;h++){let c=e[h],u=i(c,h);if(o.has(u))continue;let d=n.get(u);d?r(c,h,d):d=r(c,h,null),o.set(u,d),a.push(u)}for(let[h,c]of n)o.has(h)||c.remove();let l=null;for(let h=a.length-1;h>=0;h--){let c=o.get(a[h]);(c.nextSibling!==l||c.parentNode!==t)&&t.insertBefore(c,l),l=c}t[nr]=o}connected(){}render(){}disconnected(){}updated(t){}}});function Nq(s,t){customElements.define(s,t)}function y(s,t){return customElements.get(s)?!1:(customElements.define(s,t),!0)}function Xq(s){return!!customElements.get(s)}var C=W(()=>{"use strict"});function Gy(s,t,e,i){switch(s){case-2:return e<t;case-1:return i>=t&&e<t;case 0:return e<t&&i>t;case 1:return e<=t&&i>t;case 2:return i>t;case 4:return!0}}function za(s,t,e,i){for(var r;s.from==s.to||(e<1?s.from>=t:s.from>t)||(e>-1?s.to<=t:s.to<t);){let o=!i&&s instanceof ue&&s.index<0?null:s.parent;if(!o)return s;s=o}let n=i?0:it.IgnoreOverlays;if(i)for(let o=s,a=o.parent;a;o=a,a=o.parent)o instanceof ue&&o.index<0&&((r=a.enter(t,e,n))===null||r===void 0?void 0:r.from)!=o.from&&(s=a);for(;;){let o=s.enter(t,e,n);if(!o)return s;s=o}}function Ky(s,t,e,i){let r=s.cursor(),n=[];if(!r.firstChild())return n;if(e!=null){for(let o=!1;!o;)if(o=r.type.is(e),!r.nextSibling())return n}for(;;){if(i!=null&&r.type.is(i))return n;if(r.type.is(t)&&n.push(r.node),!r.nextSibling())return i==null?n:[]}}function gf(s,t,e=t.length-1){for(let i=s;e>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[e]&&t[e]!=i.name)return!1;e--}}return!0}function Jy(s){if(!s.length)return null;let t=0,e=s[0];for(let n=1;n<s.length;n++){let o=s[n];(o.from>e.from||o.to<e.to)&&(e=o,t=n)}let i=e instanceof ue&&e.index<0?null:e.parent,r=s.slice();return i?r[t]=i:r.splice(t,1),new Of(r,e)}function X$(s,t,e){let i=s.resolveInner(t,e),r=null;for(let n=i instanceof ue?i:i.context.parent;n;n=n.parent)if(n.index<0){let o=n.parent;(r||(r=[i])).push(o.resolve(t,e)),n=o}else{let o=mi.get(n.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let a=new ue(o.tree,o.overlay[0].from+n.from,-1,n);(r||(r=[i])).push(za(a,t,e,!1))}}return r?Jy(r):i}function yf(s){return s.children.some(t=>t instanceof gi||!t.type.isAnonymous||yf(t))}function B$(s){var t;let{buffer:e,nodeSet:i,maxBufferLength:r=1024,reused:n=[],minRepeatType:o=i.types.length}=s,a=Array.isArray(e)?new mf(e,e.length):e,l=i.types,h=0,c=0;function u(k,A,E,$,L,T){let{id:q,start:I,end:z,size:V}=a,U=c,tt=h;if(V<0)if(a.next(),V==-1){let wt=n[q];E.push(wt),$.push(I-k);return}else if(V==-3){h=q;return}else if(V==-4){c=q;return}else throw new RangeError(`Unrecognized record size: ${V}`);let nt=l[q],ft,lt,yt=I-k;if(z-I<=r&&(lt=b(a.pos-A,L))){let wt=new Uint16Array(lt.size-lt.skip),vt=a.pos-lt.size,$t=wt.length;for(;a.pos>vt;)$t=g(lt.start,wt,$t);ft=new gi(wt,z-lt.start,i),yt=lt.start-k}else{let wt=a.pos-V;a.next();let vt=[],$t=[],Mt=q>=o?q:-1,Ht=0,ls=z;for(;a.pos>wt;)Mt>=0&&a.id==Mt&&a.size>=0?(a.end<=ls-r&&(p(vt,$t,I,Ht,a.end,ls,Mt,U,tt),Ht=vt.length,ls=a.end),a.next()):T>2500?d(I,wt,vt,$t):u(I,wt,vt,$t,Mt,T+1);if(Mt>=0&&Ht>0&&Ht<vt.length&&p(vt,$t,I,Ht,I,ls,Mt,U,tt),vt.reverse(),$t.reverse(),Mt>-1&&Ht>0){let KO=f(nt,tt);ft=vf(nt,vt,$t,0,vt.length,0,z-I,KO,KO)}else ft=m(nt,vt,$t,z-I,U-z,tt)}E.push(ft),$.push(yt)}function d(k,A,E,$){let L=[],T=0,q=-1;for(;a.pos>A;){let{id:I,start:z,end:V,size:U}=a;if(U>4)a.next();else{if(q>-1&&z<q)break;q<0&&(q=V-r),L.push(I,z,V),T++,a.next()}}if(T){let I=new Uint16Array(T*4),z=L[L.length-2];for(let V=L.length-3,U=0;V>=0;V-=3)I[U++]=L[V],I[U++]=L[V+1]-z,I[U++]=L[V+2]-z,I[U++]=U;E.push(new gi(I,L[2]-z,i)),$.push(z-k)}}function f(k,A){return(E,$,L)=>{let T=0,q=E.length-1,I,z;if(q>=0&&(I=E[q])instanceof G){if(!q&&I.type==k&&I.length==L)return I;(z=I.prop(_.lookAhead))&&(T=$[q]+I.length+z)}return m(k,E,$,L,T,A)}}function p(k,A,E,$,L,T,q,I,z){let V=[],U=[];for(;k.length>$;)V.push(k.pop()),U.push(A.pop()+E-L);k.push(m(i.types[q],V,U,T-L,I-T,z)),A.push(L-E)}function m(k,A,E,$,L,T,q){if(T){let I=[_.contextHash,T];q=q?[I].concat(q):[I]}if(L>25){let I=[_.lookAhead,L];q=q?[I].concat(q):[I]}return new G(k,A,E,$,q)}function b(k,A){let E=a.fork(),$=0,L=0,T=0,q=E.end-r,I={size:0,start:0,skip:0};t:for(let z=E.pos-k;E.pos>z;){let V=E.size;if(E.id==A&&V>=0){I.size=$,I.start=L,I.skip=T,T+=4,$+=4,E.next();continue}let U=E.pos-V;if(V<0||U<z||E.start<q)break;let tt=E.id>=o?4:0,nt=E.start;for(E.next();E.pos>U;){if(E.size<0)if(E.size==-3||E.size==-4)tt+=4;else break t;else E.id>=o&&(tt+=4);E.next()}L=nt,$+=V,T+=tt}return(A<0||$==k)&&(I.size=$,I.start=L,I.skip=T),I.size>4?I:void 0}function g(k,A,E){let{id:$,start:L,end:T,size:q}=a;if(a.next(),q>=0&&$<o){let I=E;if(q>4){let z=a.pos-(q-4);for(;a.pos>z;)E=g(k,A,E)}A[--E]=I,A[--E]=T-k,A[--E]=L-k,A[--E]=$}else q==-3?h=$:q==-4&&(c=$);return E}let x=[],S=[];for(;a.pos>0;)u(s.start||0,s.bufferStart||0,x,S,-1,0);let w=(t=s.length)!==null&&t!==void 0?t:x.length?S[0]+x[0].length:0;return new G(l[s.topID],x.reverse(),S.reverse(),w)}function Vh(s,t){if(!s.isAnonymous||t instanceof gi||t.type!=s)return 1;let e=tv.get(t);if(e==null){e=1;for(let i of t.children){if(i.type!=s||!(i instanceof G)){e=1;break}e+=Vh(s,i)}tv.set(t,e)}return e}function vf(s,t,e,i,r,n,o,a,l){let h=0;for(let p=i;p<r;p++)h+=Vh(s,t[p]);let c=Math.ceil(h*1.5/8),u=[],d=[];function f(p,m,b,g,x){for(let S=b;S<g;){let w=S,k=m[S],A=Vh(s,p[S]);for(S++;S<g;S++){let E=Vh(s,p[S]);if(A+E>=c)break;A+=E}if(S==w+1){if(A>c){let E=p[w];f(E.children,E.positions,0,E.children.length,m[w]+x);continue}u.push(p[w])}else{let E=m[S-1]+p[S-1].length-k;u.push(vf(s,p,m,w,S,k,E,null,l))}d.push(k+x-n)}}return f(t,e,i,r,0),(a||l)(u,d,o)}function Os(s){return(t,e,i,r)=>new kf(t,s,e,i,r)}function ev(s){if(!s.length||s.some(t=>t.from>=t.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(s))}function Z$(s,t,e){for(let i of s){if(i.from>=e)break;if(i.to>t)return i.from<=t&&i.to>=e?2:1}return 0}function iv(s,t,e,i,r,n){if(t<e){let o=s.buffer[t+1];i.push(s.slice(t,e,o)),r.push(o-n)}}function z$(s){let{node:t}=s,e=[],i=t.context.buffer;do e.push(s.index),s.parent();while(!s.tree);let r=s.tree,n=r.children.indexOf(i),o=r.children[n],a=o.buffer,l=[n];function h(c,u,d,f,p,m){let b=e[m],g=[],x=[];iv(o,c,b,g,x,f);let S=a[b+1],w=a[b+2];l.push(g.length);let k=m?h(b+4,a[b+3],o.set.types[a[b]],S,w-S,m-1):t.toTree();return g.push(k),x.push(S-f),iv(o,a[b+3],u,g,x,f),new G(d,g,x,p)}r.children[n]=h(0,a.length,pt.none,0,o.length,e.length-1);for(let c of l){let u=s.tree.children[c],d=s.tree.positions[c];s.yield(new ue(u,d+s.from,c,s._tree))}}function sv(s,t){let e=null,i=t;for(let r=1,n=0;r<s.length;r++){let o=s[r-1].to,a=s[r].from;for(;n<i.length;n++){let l=i[n];if(l.from>=a)break;l.to<=o||(e||(i=e=t.slice()),l.from<o?(e[n]=new ce(l.from,o),l.to>a&&e.splice(n+1,0,new ce(a,l.to))):l.to>a?e[n--]=new ce(a,l.to):e.splice(n--,1))}}return i}function _$(s,t,e,i){let r=0,n=0,o=!1,a=!1,l=-1e9,h=[];for(;;){let c=r==s.length?1e9:o?s[r].to:s[r].from,u=n==t.length?1e9:a?t[n].to:t[n].from;if(o!=a){let d=Math.max(l,e),f=Math.min(c,u,i);d<f&&h.push(new ce(d,f))}if(l=Math.min(c,u),l==1e9)break;c==l&&(o?(o=!1,r++):o=!0),u==l&&(a?(a=!1,n++):a=!0)}return h}function rv(s,t){let e=[];for(let{pos:i,mount:r,frag:n}of s){let o=i+(r.overlay?r.overlay[0].from:0),a=o+r.tree.length,l=Math.max(n.from,o),h=Math.min(n.to,a);if(r.overlay){let c=r.overlay.map(d=>new ce(d.from+i,d.to+i)),u=_$(t,c,l,h);for(let d=0,f=l;;d++){let p=d==u.length,m=p?h:u[d].from;if(m>f&&e.push(new He(f,m,r.tree,-o,n.from>=f||n.openStart,n.to<=m||n.openEnd)),p)break;f=u[d].to}}else e.push(new He(l,h,r.tree,-o,n.from>=o||n.openStart,n.to<=a||n.openEnd))}return e}var Ef,q$,ce,_,mi,N$,pt,Ge,zh,Hy,it,G,mf,gi,_h,ue,bf,ms,Of,gs,tv,bs,He,Ke,xf,jh,Sf,wf,kf,Wh,Af,_e=W(()=>{Ef=1024,q$=0,ce=class{constructor(t,e){this.from=t,this.to=e}},_=class{constructor(t={}){this.id=q$++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=pt.match(t)),e=>{let i=t(e);return i===void 0?null:[this,i]}}};_.closedBy=new _({deserialize:s=>s.split(" ")}),_.openedBy=new _({deserialize:s=>s.split(" ")}),_.group=new _({deserialize:s=>s.split(" ")}),_.isolate=new _({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}}),_.contextHash=new _({perNode:!0}),_.lookAhead=new _({perNode:!0}),_.mounted=new _({perNode:!0});mi=class{constructor(t,e,i,r=!1){this.tree=t,this.overlay=e,this.parser=i,this.bracketed=r}static get(t){return t&&t.props&&t.props[_.mounted.id]}},N$=Object.create(null),pt=class s{constructor(t,e,i,r=0){this.name=t,this.props=e,this.id=i,this.flags=r}static define(t){let e=t.props&&t.props.length?Object.create(null):N$,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),r=new s(t.name||"",e,t.id,i);if(t.props){for(let n of t.props)if(Array.isArray(n)||(n=n(r)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}}return r}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(_.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let r of i.split(" "))e[r]=t[i];return i=>{for(let r=i.prop(_.group),n=-1;n<(r?r.length:0);n++){let o=e[n<0?i.name:r[n]];if(o)return o}}}};pt.none=new pt("",Object.create(null),0,8);Ge=class s{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let r=null;for(let n of t){let o=n(i);if(o){r||(r=Object.assign({},i.props));let a=o[1],l=o[0];l.combine&&l.id in r&&(a=l.combine(r[l.id],a)),r[l.id]=a}}e.push(r?new pt(i.name,r,i.id,i.flags):i)}return new s(e)}},zh=new WeakMap,Hy=new WeakMap;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays",s[s.EnterBracketed=16]="EnterBracketed"})(it||(it={}));G=class s{constructor(t,e,i,r,n){if(this.type=t,this.children=e,this.positions=i,this.length=r,this.props=null,n&&n.length){this.props=Object.create(null);for(let[o,a]of n)this.props[typeof o=="number"?o:o.id]=a}}toString(){let t=mi.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let i of this.children){let r=i.toString();r&&(e&&(e+=","),e+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new gs(this.topNode,t)}cursorAt(t,e=0,i=0){let r=zh.get(this)||this.topNode,n=new gs(r);return n.moveTo(t,e),zh.set(this,n._tree),n}get topNode(){return new ue(this,0,0,null)}resolve(t,e=0){let i=za(zh.get(this)||this.topNode,t,e,!1);return zh.set(this,i),i}resolveInner(t,e=0){let i=za(Hy.get(this)||this.topNode,t,e,!0);return Hy.set(this,i),i}resolveStack(t,e=0){return X$(this,t,e)}iterate(t){let{enter:e,leave:i,from:r=0,to:n=this.length}=t,o=t.mode||0,a=(o&it.IncludeAnonymous)>0;for(let l=this.cursor(o|it.IncludeAnonymous);;){let h=!1;if(l.from<=n&&l.to>=r&&(!a&&l.type.isAnonymous||e(l)!==!1)){if(l.firstChild())continue;h=!0}for(;h&&i&&(a||!l.type.isAnonymous)&&i(l),!l.nextSibling();){if(!l.parent())return;h=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:vf(pt.none,this.children,this.positions,0,this.children.length,0,this.length,(e,i,r)=>new s(this.type,e,i,r,this.propValues),t.makeTree||((e,i,r)=>new s(pt.none,e,i,r)))}static build(t){return B$(t)}};G.empty=new G(pt.none,[],[],0);mf=class s{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new s(this.buffer,this.index)}},gi=class s{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return pt.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],r=this.set.types[e],n=r.name;if(/\W/.test(n)&&!r.isError&&(n=JSON.stringify(n)),t+=4,i==t)return n;let o=[];for(;t<i;)o.push(this.childString(t)),t=this.buffer[t+3];return n+"("+o.join(",")+")"}findChild(t,e,i,r,n){let{buffer:o}=this,a=-1;for(let l=t;l!=e&&!(Gy(n,r,o[l+1],o[l+2])&&(a=l,i>0));l=o[l+3]);return a}slice(t,e,i){let r=this.buffer,n=new Uint16Array(e-t),o=0;for(let a=t,l=0;a<e;){n[l++]=r[a++],n[l++]=r[a++]-i;let h=n[l++]=r[a++]-i;n[l++]=r[a++]-t,o=Math.max(o,h)}return new s(n,o,this.set)}};_h=class{cursor(t=0){return new gs(this,t)}getChild(t,e=null,i=null){let r=Ky(this,t,e,i);return r.length?r[0]:null}getChildren(t,e=null,i=null){return Ky(this,t,e,i)}resolve(t,e=0){return za(this,t,e,!1)}resolveInner(t,e=0){return za(this,t,e,!0)}matchContext(t){return gf(this.parent,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let r=e.lastChild;if(!r||r.to!=e.to)break;r.type.isError&&r.from==r.to?(i=e,e=r.prevSibling):e=r}return i}get node(){return this}get next(){return this.parent}},ue=class s extends _h{constructor(t,e,i,r){super(),this._tree=t,this.from=e,this.index=i,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,i,r,n=0){for(let o=this;;){for(let{children:a,positions:l}=o._tree,h=e>0?a.length:-1;t!=h;t+=e){let c=a[t],u=l[t]+o.from,d;if(!(!(n&it.EnterBracketed&&c instanceof G&&(d=mi.get(c))&&!d.overlay&&d.bracketed&&i>=u&&i<=u+c.length)&&!Gy(r,i,u,u+c.length))){if(c instanceof gi){if(n&it.ExcludeBuffers)continue;let f=c.findChild(0,c.buffer.length,e,i-u,r);if(f>-1)return new ms(new bf(o,c,t,u),null,f)}else if(n&it.IncludeAnonymous||!c.type.isAnonymous||yf(c)){let f;if(!(n&it.IgnoreMounts)&&(f=mi.get(c))&&!f.overlay)return new s(f.tree,u,t,o);let p=new s(c,u,t,o);return n&it.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(e<0?c.children.length-1:0,e,i,r,n)}}}if(n&it.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,e,i=0){let r;if(!(i&it.IgnoreOverlays)&&(r=mi.get(this._tree))&&r.overlay){let n=t-this.from,o=i&it.EnterBracketed&&r.bracketed;for(let{from:a,to:l}of r.overlay)if((e>0||o?a<=n:a<n)&&(e<0||o?l>=n:l>n))return new s(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};bf=class{constructor(t,e,i,r){this.parent=t,this.buffer=e,this.index=i,this.start=r}},ms=class s extends _h{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,i);return n<0?null:new s(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,e,i=0){if(i&it.ExcludeBuffers)return null;let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return n<0?null:new s(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new s(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new s(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,r=this.index+4,n=i.buffer[this.index+3];if(n>r){let o=i.buffer[this.index+1];t.push(i.slice(r,n,o)),e.push(0)}return new G(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};Of=class{constructor(t,e){this.heads=t,this.node=e}get next(){return Jy(this.heads)}};gs=class{get name(){return this.type.name}constructor(t,e=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=e&~it.EnterBracketed,t instanceof ue)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let i=t._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:i,buffer:r}=this.buffer;return this.type=e||r.set.types[r.buffer[t]],this.from=i+r.buffer[t+1],this.to=i+r.buffer[t+2],!0}yield(t){return t?t instanceof ue?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:r}=this.buffer,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,i);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?i&it.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&it.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&it.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let r=i<0?0:this.stack[i]+4;if(this.index!=r)return this.yieldBuf(e.findChild(r,this.index,-1,0,4))}else{let r=e.buffer[this.index+3];if(r<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(r)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:r}=this;if(r){if(t>0){if(this.index<r.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(r.buffer.buffer[n+3]<this.index)return!1;({index:e,parent:i}=r)}else({index:e,_parent:i}=this._tree);for(;i;{index:e,_parent:i}=i)if(e>-1)for(let n=e+t,o=t<0?-1:i._tree.children.length;n!=o;n+=t){let a=i._tree.children[n];if(this.mode&it.IncludeAnonymous||a instanceof gi||!a.type.isAnonymous||yf(a))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let r=this.index,n=this.stack.length;n>=0;){for(let o=t;o;o=o._parent)if(o.index==r){if(r==this.index)return o;e=o,i=n+1;break t}r=this.stack[--n]}for(let r=i;r<this.stack.length;r++)e=new ms(this.buffer,e,this.stack[r]);return this.bufferNode=new ms(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let r=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&e&&e(this),r=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,r=!0}}}matchContext(t){if(!this.buffer)return gf(this.node.parent,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let r=t.length-1,n=this.stack.length-1;r>=0;n--){if(n<0)return gf(this._tree,t,r);let o=i[e.buffer[this.stack[n]]];if(!o.isAnonymous){if(t[r]&&t[r]!=o.name)return!1;r--}}return!0}};tv=new WeakMap;bs=class{constructor(){this.map=new WeakMap}setBuffer(t,e,i){let r=this.map.get(t);r||this.map.set(t,r=new Map),r.set(e,i)}getBuffer(t,e){let i=this.map.get(t);return i&&i.get(e)}set(t,e){t instanceof ms?this.setBuffer(t.context.buffer,t.index,e):t instanceof ue&&this.map.set(t.tree,e)}get(t){return t instanceof ms?this.getBuffer(t.context.buffer,t.index):t instanceof ue?this.map.get(t.tree):void 0}cursorSet(t,e){t.buffer?this.setBuffer(t.buffer.buffer,t.index,e):this.map.set(t.tree,e)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}},He=class s{constructor(t,e,i,r,n=!1,o=!1){this.from=t,this.to=e,this.tree=i,this.offset=r,this.open=(n?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,e=[],i=!1){let r=[new s(0,t.length,t,0,!1,i)];for(let n of e)n.to>t.length&&r.push(n);return r}static applyChanges(t,e,i=128){if(!e.length)return t;let r=[],n=1,o=t.length?t[0]:null;for(let a=0,l=0,h=0;;a++){let c=a<e.length?e[a]:null,u=c?c.fromA:1e9;if(u-l>=i)for(;o&&o.from<u;){let d=o;if(l>=d.from||u<=d.to||h){let f=Math.max(d.from,l)-h,p=Math.min(d.to,u)-h;d=f>=p?null:new s(f,p,d.tree,d.offset+h,a>0,!!c)}if(d&&r.push(d),o.to>u)break;o=n<t.length?t[n++]:null}if(!c)break;l=c.toA,h=c.toA-c.toB}return r}},Ke=class{startParse(t,e,i){return typeof t=="string"&&(t=new xf(t)),i=i?i.length?i.map(r=>new ce(r.from,r.to)):[new ce(0,0)]:[new ce(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let r=this.startParse(t,e,i);for(;;){let n=r.advance();if(n)return n}}},xf=class{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}};jh=class{constructor(t,e,i,r,n,o){this.parser=t,this.parse=e,this.overlay=i,this.bracketed=r,this.target=n,this.from=o}};Sf=class{constructor(t,e,i,r,n,o,a,l){this.parser=t,this.predicate=e,this.mounts=i,this.index=r,this.start=n,this.bracketed=o,this.target=a,this.prev=l,this.depth=0,this.ranges=[]}},wf=new _({perNode:!0}),kf=class{constructor(t,e,i,r,n){this.nest=e,this.input=i,this.fragments=r,this.ranges=n,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let r of this.inner)r.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new G(i.type,i.children,i.positions,i.length,i.propValues.concat([[wf,this.stoppedAt]]))),i}let t=this.inner[this.innerDone],e=t.parse.advance();if(e){this.innerDone++;let i=Object.assign(Object.create(null),t.target.props);i[_.mounted.id]=new mi(e,t.overlay,t.parser,t.bracketed),t.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].from<t&&(t=Math.min(t,this.inner[e].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].parse.stopAt(t)}startInner(){let t=new Af(this.fragments),e=null,i=null,r=new gs(new ue(this.baseTree,this.ranges[0].from,0,null),it.IncludeAnonymous|it.IgnoreMounts);t:for(let n,o;;){let a=!0,l;if(this.stoppedAt!=null&&r.from>=this.stoppedAt)a=!1;else if(t.hasNode(r)){if(e){let h=e.mounts.find(c=>c.frag.from<=r.from&&c.frag.to>=r.to&&c.mount.overlay);if(h)for(let c of h.mount.overlay){let u=c.from+h.pos,d=c.to+h.pos;u>=r.from&&d<=r.to&&!e.ranges.some(f=>f.from<d&&f.to>u)&&e.ranges.push({from:u,to:d})}}a=!1}else if(i&&(o=Z$(i.ranges,r.from,r.to)))a=o!=2;else if(!r.type.isAnonymous&&(n=this.nest(r,this.input))&&(r.from<r.to||!n.overlay)){r.tree||(z$(r),e&&e.depth++,i&&i.depth++);let h=t.findMounts(r.from,n.parser);if(typeof n.overlay=="function")e=new Sf(n.parser,n.overlay,h,this.inner.length,r.from,!!n.bracketed,r.tree,e);else{let c=sv(this.ranges,n.overlay||(r.from<r.to?[new ce(r.from,r.to)]:[]));c.length&&ev(c),(c.length||!n.overlay)&&this.inner.push(new jh(n.parser,c.length?n.parser.startParse(this.input,rv(h,c),c):n.parser.startParse(""),n.overlay?n.overlay.map(u=>new ce(u.from-r.from,u.to-r.from)):null,!!n.bracketed,r.tree,c.length?c[0].from:r.from)),n.overlay?c.length&&(i={ranges:c,depth:0,prev:i}):a=!1}}else if(e&&(l=e.predicate(r))&&(l===!0&&(l=new ce(r.from,r.to)),l.from<l.to)){let h=e.ranges.length-1;h>=0&&e.ranges[h].to==l.from?e.ranges[h]={from:e.ranges[h].from,to:l.to}:e.ranges.push(l)}if(a&&r.firstChild())e&&e.depth++,i&&i.depth++;else for(;!r.nextSibling();){if(!r.parent())break t;if(e&&!--e.depth){let h=sv(this.ranges,e.ranges);h.length&&(ev(h),this.inner.splice(e.index,0,new jh(e.parser,e.parser.startParse(this.input,rv(e.mounts,h),h),e.ranges.map(c=>new ce(c.from-e.start,c.to-e.start)),e.bracketed,e.target,h[0].from))),e=e.prev}i&&!--i.depth&&(i=i.prev)}}}};Wh=class{constructor(t,e){this.offset=e,this.done=!1,this.cursor=t.cursor(it.IncludeAnonymous|it.IgnoreMounts)}moveTo(t){let{cursor:e}=this,i=t-this.offset;for(;!this.done&&e.from<i;)if(!(e.to>=t&&e.enter(i,1,it.IgnoreOverlays|it.ExcludeBuffers)))if(e.to<=t)e.next(!1)||(this.done=!0);else break}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let e=this.cursor.tree;;){if(e==t.tree)return!0;if(e.children.length&&e.positions[0]==0&&e.children[0]instanceof G)e=e.children[0];else break}return!1}},Af=class{constructor(t){var e;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let i=this.curFrag=t[0];this.curTo=(e=i.tree.prop(wf))!==null&&e!==void 0?e:i.to,this.inner=new Wh(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=(t=e.tree.prop(wf))!==null&&t!==void 0?t:e.to,this.inner=new Wh(e.tree,-e.offset)}}findMounts(t,e){var i;let r=[];if(this.inner){this.inner.cursor.moveTo(t,1);for(let n=this.inner.cursor.node;n;n=n.parent){let o=(i=n.tree)===null||i===void 0?void 0:i.prop(_.mounted);if(o&&o.parser==e)for(let a=this.fragI;a<this.fragments.length;a++){let l=this.fragments[a];if(l.from>=n.to)break;l.tree==this.curFrag.tree&&r.push({frag:l,pos:n.from-l.offset,mount:o})}}}return r}}});function _a(s,t=Uint16Array){if(typeof s!="string")return s;let e=null;for(let i=0,r=0;i<s.length;){let n=0;for(;;){let o=s.charCodeAt(i++),a=!1;if(o==126){n=65535;break}o>=92&&o--,o>=34&&o--;let l=o-32;if(l>=46&&(l-=46,a=!0),n+=l,a)break;n*=46}e?e[r++]=n:e=new t(n)}return e}function ov(s,t,e,i,r,n){let o=0,a=1<<i,{dialect:l}=e.p.parser;t:for(;(a&s[o])!=0;){let h=s[o+1];for(let f=o+3;f<h;f+=2)if((s[f+1]&a)>0){let p=s[f];if(l.allows(p)&&(t.token.value==-1||t.token.value==p||V$(p,t.token.value,r,n))){t.acceptToken(p);break}}let c=t.next,u=0,d=s[o+2];if(t.next<0&&d>u&&s[h+d*3-3]==65535){o=s[h+d*3-1];continue t}for(;u<d;){let f=u+d>>1,p=h+f+(f<<1),m=s[p],b=s[p+1]||65536;if(c<m)d=f;else if(c>=b)u=f+1;else{o=s[p+2],t.advance();continue t}}break}}function av(s,t,e){for(let i=t,r;(r=s[i])!=65535;i++)if(r==e)return i-t;return-1}function V$(s,t,e,i){let r=av(e,i,t);return r<0||av(e,i,s)<r}function lv(s,t,e){let i=s.cursor(it.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(s.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:s.length}}function hv(s,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==s.pos&&i.sameState(s)){t[e].score<s.score&&(t[e]=s);return}}t.push(s)}function bi(s,t){return s[t]|s[t+1]<<16}function j$(s){let t=null;for(let e of s){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function cv(s){if(s.external){let t=s.extend?1:0;return(e,i)=>s.external(e,i)<<1|t}return s.get}var Fh,Uh,Cf,$f,Mn,nv,Yh,_i,Oi,mt,we,Pf,Qf,Tf,Lf,Mf,Rf,yi,Kt,ys=W(()=>{_e();Fh=class s{constructor(t,e,i,r,n,o,a,l,h,c=0,u){this.p=t,this.stack=e,this.state=i,this.reducePos=r,this.pos=n,this.score=o,this.buffer=a,this.bufferBase=l,this.curContext=h,this.lookAhead=c,this.parent=u}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let r=t.parser.context;return new s(t,[],e,i,i,0,[],0,r?new Uh(r,r.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,r=t&65535,{parser:n}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),a=n.dynamicPrecedence(r);if(a&&(this.score+=a),i==0){r<n.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(n.getGoto(this.state,r,!0),this.reducePos),r<n.minRepeatTerm&&this.storeNode(r,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(r,this.reducePos);return}let l=this.stack.length-(i-1)*3-(t&262144?6:0),h=l?this.stack[l-2]:this.p.ranges[0].from;r<n.minRepeatTerm&&h==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let c=this.reducePos-h;c>=2e3&&!(!((e=this.p.parser.nodeSet.types[r])===null||e===void 0)&&e.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=c));let u=l?this.stack[l-1]:0,d=this.bufferBase+this.buffer.length-u;if(r<n.minRepeatTerm||t&131072){let f=n.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(r,h,f,d+4,!0)}if(t&262144)this.state=this.stack[l];else{let f=this.stack[l-3];this.state=n.getGoto(f,r,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(r,h)}storeNode(t,e,i,r=4,n=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this.buffer.length;if(o>0&&this.buffer[o-4]==0&&this.buffer[o-1]>-1){if(e==i)return;if(this.buffer[o-2]>=e){this.buffer[o-2]=i;return}}}if(!n||this.pos==i)this.buffer.push(t,e,i,r);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let a=!1;for(let l=o;l>0&&this.buffer[l-2]>i;l-=4)if(this.buffer[l-1]>=0){a=!0;break}if(a)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,r>4&&(r-=4)}this.buffer[o]=t,this.buffer[o+1]=e,this.buffer[o+2]=i,this.buffer[o+3]=r}}shift(t,e,i,r){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let n=t,{parser:o}=this.p;this.pos=r;let a=o.stateFlag(n,1);!a&&(r>i||e<=o.maxNode)&&(this.reducePos=r),this.pushState(n,a?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=o.maxNode&&this.buffer.push(e,i,r,4)}else this.pos=r,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,r,4)}apply(t,e,i,r){t&65536?this.reduce(t):this.shift(t,e,i,r)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let r=this.pos;this.reducePos=this.pos=r+t.length,this.pushState(e,r),this.buffer.push(i,r,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),r=t.bufferBase+e;for(;t&&r==t.bufferBase;)t=t.parent;return new s(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,r,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Cf(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let r=[];for(let n=0,o;n<e.length;n+=2)(o=e[n+1])!=this.state&&this.p.parser.hasAction(o,t)&&r.push(e[n],o);if(this.stack.length<120)for(let n=0;r.length<8&&n<e.length;n+=2){let o=e[n+1];r.some((a,l)=>l&1&&a==o)||r.push(e[n],o)}e=r}let i=[];for(let r=0;r<e.length&&i.length<4;r+=2){let n=e[r+1];if(n==this.state)continue;let o=this.split();o.pushState(n,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(e[r],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,r=e&65535,n=this.stack.length-i*3;if(n<0||t.getGoto(this.stack[n],r,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;e=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(r,n)=>{if(!e.includes(r))return e.push(r),t.allActions(r,o=>{if(!(o&393216))if(o&65536){let a=(o>>19)-n;if(a>1){let l=o&65535,h=this.stack.length-a*3;if(h>=0&&t.getGoto(this.stack[h],l,!1)>=0)return a<<19|65536|l}}else{let a=i(o,n+1);if(a!=null)return a}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new Uh(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},Uh=class{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}},Cf=class{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,i=t>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let r=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=r}},$f=class s{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new s(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new s(this.stack,this.pos,this.index)}};Mn=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},nv=new Mn,Yh=class{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=nv,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,r=this.rangeIndex,n=this.pos+t;for(;n<i.from;){if(!r)return null;let o=this.ranges[--r];n-=i.from-o.to,i=o}for(;e<0?n>i.to:n>=i.to;){if(r==this.ranges.length-1)return null;let o=this.ranges[++r];n+=o.from-i.to,i=o}return n}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,i,r;if(e>=0&&e<this.chunk.length)i=this.pos+t,r=this.chunk.charCodeAt(e);else{let n=this.resolveOffset(t,1);if(n==null)return-1;if(i=n,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)r=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,a=this.range;for(;a.to<=i;)a=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>a.to&&(this.chunk2=this.chunk2.slice(0,a.to-i)),r=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),r}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=i}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=nv,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let r of this.ranges){if(r.from>=e)break;r.to>t&&(i+=this.input.read(Math.max(r.from,t),Math.min(r.to,e)))}return i}},_i=class{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;ov(this.data,t,e,this.id,i.data,i.tokenPrecTable)}};_i.prototype.contextual=_i.prototype.fallback=_i.prototype.extend=!1;Oi=class{constructor(t,e,i){this.precTable=e,this.elseToken=i,this.data=typeof t=="string"?_a(t):t}token(t,e){let i=t.pos,r=0;for(;;){let n=t.next<0,o=t.resolveOffset(1,1);if(ov(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(n||r++,o==null)break;t.reset(o,t.token)}r&&(t.reset(i,t.token),t.acceptToken(this.elseToken,r))}};Oi.prototype.contextual=_i.prototype.fallback=_i.prototype.extend=!1;mt=class{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}};we=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Pf=null;Qf=class{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?lv(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?lv(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let i=this.trees[e],r=this.index[e];if(r==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=i.children[r],o=this.start[e]+i.positions[r];if(o>t)return this.nextStart=o,null;if(n instanceof G){if(o==t){if(o<this.safeFrom)return null;let a=o+n.length;if(a<=this.safeTo){let l=n.prop(_.lookAhead);if(!l||a+l<this.fragment.to)return n}}this.index[e]++,o+n.length>=Math.max(this.safeFrom,t)&&(this.trees.push(n),this.start.push(o),this.index.push(0))}else this.index[e]++,this.nextStart=o+n.length}}},Tf=class{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(i=>new Mn)}getActions(t){let e=0,i=null,{parser:r}=t.p,{tokenizers:n}=r,o=r.stateSlot(t.state,3),a=t.curContext?t.curContext.hash:0,l=0;for(let h=0;h<n.length;h++){if((1<<h&o)==0)continue;let c=n[h],u=this.tokens[h];if(!(i&&!c.fallback)&&((c.contextual||u.start!=t.pos||u.mask!=o||u.context!=a)&&(this.updateCachedToken(u,c,t),u.mask=o,u.context=a),u.lookAhead>u.end+25&&(l=Math.max(u.lookAhead,l)),u.value!=0)){let d=e;if(u.extended>-1&&(e=this.addActions(t,u.extended,u.end,e)),e=this.addActions(t,u.value,u.end,e),!c.extend&&(i=u,e>d))break}}for(;this.actions.length>e;)this.actions.pop();return l&&t.setLookAhead(l),!i&&t.pos==this.stream.end&&(i=new Mn,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new Mn,{pos:i,p:r}=t;return e.start=i,e.end=Math.min(i+1,r.stream.end),e.value=i==r.stream.end?r.parser.eofTerm:0,e}updateCachedToken(t,e,i){let r=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(r,t),i),t.value>-1){let{parser:n}=i.p;for(let o=0;o<n.specialized.length;o++)if(n.specialized[o]==t.value){let a=n.specializers[o](this.stream.read(t.start,t.end),i);if(a>=0&&i.p.parser.dialect.allows(a>>1)){(a&1)==0?t.value=a>>1:t.extended=a>>1;break}}}else t.value=0,t.end=this.stream.clipPos(r+1)}putAction(t,e,i,r){for(let n=0;n<r;n+=3)if(this.actions[n]==t)return r;return this.actions[r++]=t,this.actions[r++]=e,this.actions[r++]=i,r}addActions(t,e,i,r){let{state:n}=t,{parser:o}=t.p,{data:a}=o;for(let l=0;l<2;l++)for(let h=o.stateSlot(n,l?2:1);;h+=3){if(a[h]==65535)if(a[h+1]==1)h=bi(a,h+2);else{r==0&&a[h+1]==2&&(r=this.putAction(bi(a,h+2),e,i,r));break}a[h]==e&&(r=this.putAction(bi(a,h+1),e,i,r))}return r}},Lf=class{constructor(t,e,i,r){this.parser=t,this.input=e,this.ranges=r,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new Yh(e,r),this.tokens=new Tf(t,this.stream),this.topTerm=t.top[1];let{from:n}=r[0];this.stacks=[Fh.start(this,t.top[0],n)],this.fragments=i.length&&this.stream.end-n>t.bufferLength*4?new Qf(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,i=this.stacks=[],r,n;if(this.bigReductionCount>300&&t.length==1){let[o]=t;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<t.length;o++){let a=t[o];for(;;){if(this.tokens.mainToken=null,a.pos>e)i.push(a);else{if(this.advanceStack(a,i,t))continue;{r||(r=[],n=[]),r.push(a);let l=this.tokens.getMainToken(a);n.push(l.value,l.end)}}break}}if(!i.length){let o=r&&j$(r);if(o)return we&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw we&&r&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&r){let o=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,n,i);if(o)return we&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((a,l)=>l.score-a.score);i.length>o;)i.pop();i.some(a=>a.reducePos>e)&&this.recovering--}else if(i.length>1){t:for(let o=0;o<i.length-1;o++){let a=i[o];for(let l=o+1;l<i.length;l++){let h=i[l];if(a.sameState(h)||a.buffer.length>500&&h.buffer.length>500)if((a.score-h.score||a.buffer.length-h.buffer.length)>0)i.splice(l--,1);else{i.splice(o--,1);continue t}}}i.length>12&&(i.sort((o,a)=>a.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,i){let r=t.pos,{parser:n}=this,o=we?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&r>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let h=t.curContext&&t.curContext.tracker.strict,c=h?t.curContext.hash:0;for(let u=this.fragments.nodeAt(r);u;){let d=this.parser.nodeSet.types[u.type.id]==u.type?n.getGoto(t.state,u.type.id):-1;if(d>-1&&u.length&&(!h||(u.prop(_.contextHash)||0)==c))return t.useNode(u,d),we&&console.log(o+this.stackID(t)+` (via reuse of ${n.getName(u.type.id)})`),!0;if(!(u instanceof G)||u.children.length==0||u.positions[0]>0)break;let f=u.children[0];if(f instanceof G&&u.positions[0]==0)u=f;else break}}let a=n.stateSlot(t.state,4);if(a>0)return t.reduce(a),we&&console.log(o+this.stackID(t)+` (via always-reduce ${n.getName(a&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let l=this.tokens.getActions(t);for(let h=0;h<l.length;){let c=l[h++],u=l[h++],d=l[h++],f=h==l.length||!i,p=f?t:t.split(),m=this.tokens.mainToken;if(p.apply(c,u,m?m.start:p.pos,d),we&&console.log(o+this.stackID(p)+` (via ${(c&65536)==0?"shift":`reduce of ${n.getName(c&65535)}`} for ${n.getName(u)} @ ${r}${p==t?"":", split"})`),f)return!0;p.pos>r?e.push(p):i.push(p)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return hv(t,e),!0}}runRecovery(t,e,i){let r=null,n=!1;for(let o=0;o<t.length;o++){let a=t[o],l=e[o<<1],h=e[(o<<1)+1],c=we?this.stackID(a)+" -> ":"";if(a.deadEnd&&(n||(n=!0,a.restart(),we&&console.log(c+this.stackID(a)+" (restarted)"),this.advanceFully(a,i))))continue;let u=a.split(),d=c;for(let f=0;f<10&&u.forceReduce()&&(we&&console.log(d+this.stackID(u)+" (via force-reduce)"),!this.advanceFully(u,i));f++)we&&(d=this.stackID(u)+" -> ");for(let f of a.recoverByInsert(l))we&&console.log(c+this.stackID(f)+" (via recover-insert)"),this.advanceFully(f,i);this.stream.end>a.pos?(h==a.pos&&(h++,l=0),a.recoverByDelete(l,h),we&&console.log(c+this.stackID(a)+` (via recover-delete ${this.parser.getName(l)})`),hv(a,i)):(!r||r.score<u.score)&&(r=u)}return r}stackToTree(t){return t.close(),G.build({buffer:$f.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(Pf||(Pf=new WeakMap)).get(t);return e||Pf.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}};Mf=class{constructor(t,e,i){this.source=t,this.flags=e,this.disabled=i}allows(t){return!this.disabled||this.disabled[t]==0}},Rf=s=>s,yi=class{constructor(t){this.start=t.start,this.shift=t.shift||Rf,this.reduce=t.reduce||Rf,this.reuse=t.reuse||Rf,this.hash=t.hash||(()=>0),this.strict=t.strict!==!1}},Kt=class s extends Ke{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let a=0;a<t.repeatNodeCount;a++)e.push("");let i=Object.keys(t.topRules).map(a=>t.topRules[a][1]),r=[];for(let a=0;a<e.length;a++)r.push([]);function n(a,l,h){r[a].push([l,l.deserialize(String(h))])}if(t.nodeProps)for(let a of t.nodeProps){let l=a[0];typeof l=="string"&&(l=_[l]);for(let h=1;h<a.length;){let c=a[h++];if(c>=0)n(c,l,a[h++]);else{let u=a[h+-c];for(let d=-c;d>0;d--)n(a[h++],l,u);h++}}}this.nodeSet=new Ge(e.map((a,l)=>pt.define({name:l>=this.minRepeatTerm?void 0:a,id:l,props:r[l],top:i.indexOf(l)>-1,error:l==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(l)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=1024;let o=_a(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let a=0;a<this.specializerSpecs.length;a++)this.specialized[a]=this.specializerSpecs[a].term;this.specializers=this.specializerSpecs.map(cv),this.states=_a(t.states,Uint32Array),this.data=_a(t.stateData),this.goto=_a(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(a=>typeof a=="number"?new _i(o,a):a),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let r=new Lf(this,t,e,i);for(let n of this.wrappers)r=n(r,t,e,i);return r}getGoto(t,e,i=!1){let r=this.goto;if(e>=r[0])return-1;for(let n=r[e+1];;){let o=r[n++],a=o&1,l=r[n++];if(a&&i)return l;for(let h=n+(o>>1);n<h;n++)if(r[n]==t)return l;if(a)return-1}}hasAction(t,e){let i=this.data;for(let r=0;r<2;r++)for(let n=this.stateSlot(t,r?2:1),o;;n+=3){if((o=i[n])==65535)if(i[n+1]==1)o=i[n=bi(i,n+2)];else{if(i[n+1]==2)return bi(i,n+2);break}if(o==e||o==0)return bi(i,n+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),r=i?e(i):void 0;for(let n=this.stateSlot(t,1);r==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=bi(this.data,n+2);else break;r=e(bi(this.data,n+1))}return r}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=bi(this.data,i+2);else break;if((this.data[i+2]&1)==0){let r=this.data[i+1];e.some((n,o)=>o&1&&n==r)||e.push(this.data[i],r)}}return e}configure(t){let e=Object.assign(Object.create(s.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let r=t.tokenizers.find(n=>n.from==i);return r?r.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,r)=>{let n=t.specializers.find(a=>a.from==i.external);if(!n)return i;let o=Object.assign(Object.assign({},i),{external:n.to});return e.specializers[r]=cv(o),o})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let n of t.split(" ")){let o=e.indexOf(n);o>=0&&(i[o]=!0)}let r=null;for(let n=0;n<e.length;n++)if(!i[n])for(let o=this.dialects[e[n]],a;(a=this.data[o++])!=65535;)(r||(r=new Uint8Array(this.maxTerm+1)))[a]=1;return new Mf(t,i,r)}static deserialize(t){return new s(t)}}});function U$(s,t){return s.length==t.length&&s.every((e,i)=>e==t[i])}function Y$(s){let t=[[]];for(let e=0;e<s.length;e++)for(let i=0,r=t.length;i<r;i++)t.push(t[i].concat(s[e]));return t.sort((e,i)=>i.length-e.length)}function It(s){let t=Object.create(null);for(let e in s){let i=s[e];Array.isArray(i)||(i=[i]);for(let r of e.split(" "))if(r){let n=[],o=2,a=r;for(let u=0;;){if(a=="..."&&u>0&&u+3==r.length){o=1;break}let d=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!d)throw new RangeError("Invalid path: "+r);if(n.push(d[0]=="*"?"":d[0][0]=='"'?JSON.parse(d[0]):d[0]),u+=d[0].length,u==r.length)break;let f=r[u++];if(u==r.length&&f=="!"){o=0;break}if(f!="/")throw new RangeError("Invalid path: "+r);a=r.slice(u)}let l=n.length-1,h=n[l];if(!h)throw new RangeError("Invalid path: "+r);let c=new vs(i,o,l>0?n.slice(0,l):null);t[h]=c.sort(t[h])}}return uv.add(t)}function tc(s,t){let e=Object.create(null);for(let n of s)if(!Array.isArray(n.tag))e[n.tag.id]=n.class;else for(let o of n.tag)e[o.id]=n.class;let{scope:i,all:r=null}=t||{};return{style:n=>{let o=r;for(let a of n)for(let l of a.set){let h=e[l.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function H$(s,t){let e=null;for(let i of s){let r=i.style(t);r&&(e=e?e+" "+r:r)}return e}function ec(s,t,e,i=0,r=s.length){let n=new If(i,Array.isArray(t)?t:[t],e);n.highlightRange(s.cursor(),i,r,"",n.highlighters),n.flush(r)}function G$(s,t,e,i,r,n=0,o=s.length){let a=n;function l(h,c){if(!(h<=a)){for(let u=s.slice(a,h),d=0;;){let f=u.indexOf(`
11
- `,d),p=f<0?u.length:f;if(p>d&&i(u.slice(d,p),c),f<0)break;r(),d=f+1}a=h}}ec(t,e,(h,c,u)=>{l(h,""),l(c,u)},n,o),l(o,"")}function dv(s){let t=s.type.prop(uv);for(;t&&t.context&&!s.matchContext(t.context);)t=t.next;return t||null}var W$,de,F$,Hh,uv,vs,If,N,Gh,Vi,fv,pv,ji,Kh,Df,Je,xs,ti,ei,qf,Va,Jh,O,K$,ii=W(()=>{_e();W$=0,de=class s{constructor(t,e,i,r){this.name=t,this.set=e,this.base=i,this.modified=r,this.id=W$++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i=typeof t=="string"?t:"?";if(t instanceof s&&(e=t),e?.base)throw new Error("Can not derive from a modified tag");let r=new s(i,[],null,[]);if(r.set.push(r),e)for(let n of e.set)r.set.push(n);return r}static defineModifier(t){let e=new Hh(t);return i=>i.modified.indexOf(e)>-1?i:Hh.get(i.base||i,i.modified.concat(e).sort((r,n)=>r.id-n.id))}},F$=0,Hh=class s{constructor(t){this.name=t,this.instances=[],this.id=F$++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(a=>a.base==t&&U$(e,a.modified));if(i)return i;let r=[],n=new de(t.name,r,t,e);for(let a of e)a.instances.push(n);let o=Y$(e);for(let a of t.set)if(!a.modified.length)for(let l of o)r.push(s.get(a,l));return n}};uv=new _({combine(s,t){let e,i,r;for(;s||t;){if(!s||t&&s.depth>=t.depth?(r=t,t=t.next):(r=s,s=s.next),e&&e.mode==r.mode&&!r.context&&!e.context)continue;let n=new vs(r.tags,r.mode,r.context);e?e.next=n:i=n,e=n}return i}}),vs=class{constructor(t,e,i,r){this.tags=t,this.mode=e,this.context=i,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}};vs.empty=new vs([],2,null);If=class{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,r,n){let{type:o,from:a,to:l}=t;if(a>=i||l<=e)return;o.isTop&&(n=this.highlighters.filter(f=>!f.scope||f.scope(o)));let h=r,c=dv(t)||vs.empty,u=H$(n,c.tags);if(u&&(h&&(h+=" "),h+=u,c.mode==1&&(r+=(r?" ":"")+u)),this.startSpan(Math.max(e,a),h),c.opaque)return;let d=t.tree&&t.tree.prop(_.mounted);if(d&&d.overlay){let f=t.node.enter(d.overlay[0].from+a,1),p=this.highlighters.filter(b=>!b.scope||b.scope(d.tree.type)),m=t.firstChild();for(let b=0,g=a;;b++){let x=b<d.overlay.length?d.overlay[b]:null,S=x?x.from+a:l,w=Math.max(e,g),k=Math.min(i,S);if(w<k&&m)for(;t.from<k&&(this.highlightRange(t,w,k,r,n),this.startSpan(Math.min(k,t.to),h),!(t.to>=S||!t.nextSibling())););if(!x||S>i)break;g=x.to+a,g>e&&(this.highlightRange(f.cursor(),Math.max(e,x.from+a),Math.min(i,g),"",p),this.startSpan(Math.min(i,g),h))}m&&t.parent()}else if(t.firstChild()){d&&(r="");do if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,r,n),this.startSpan(Math.min(i,t.to),h)}while(t.nextSibling());t.parent()}}};N=de.define,Gh=N(),Vi=N(),fv=N(Vi),pv=N(Vi),ji=N(),Kh=N(ji),Df=N(ji),Je=N(),xs=N(Je),ti=N(),ei=N(),qf=N(),Va=N(qf),Jh=N(),O={comment:Gh,lineComment:N(Gh),blockComment:N(Gh),docComment:N(Gh),name:Vi,variableName:N(Vi),typeName:fv,tagName:N(fv),propertyName:pv,attributeName:N(pv),className:N(Vi),labelName:N(Vi),namespace:N(Vi),macroName:N(Vi),literal:ji,string:Kh,docString:N(Kh),character:N(Kh),attributeValue:N(Kh),number:Df,integer:N(Df),float:N(Df),bool:N(ji),regexp:N(ji),escape:N(ji),color:N(ji),url:N(ji),keyword:ti,self:N(ti),null:N(ti),atom:N(ti),unit:N(ti),modifier:N(ti),operatorKeyword:N(ti),controlKeyword:N(ti),definitionKeyword:N(ti),moduleKeyword:N(ti),operator:ei,derefOperator:N(ei),arithmeticOperator:N(ei),logicOperator:N(ei),bitwiseOperator:N(ei),compareOperator:N(ei),updateOperator:N(ei),definitionOperator:N(ei),typeOperator:N(ei),controlOperator:N(ei),punctuation:qf,separator:N(qf),bracket:Va,angleBracket:N(Va),squareBracket:N(Va),paren:N(Va),brace:N(Va),content:Je,heading:xs,heading1:N(xs),heading2:N(xs),heading3:N(xs),heading4:N(xs),heading5:N(xs),heading6:N(xs),contentSeparator:N(Je),list:N(Je),quote:N(Je),emphasis:N(Je),strong:N(Je),link:N(Je),monospace:N(Je),strikethrough:N(Je),inserted:N(),deleted:N(),changed:N(),invalid:N(),meta:Jh,documentMeta:N(Jh),annotation:N(Jh),processingInstruction:N(Jh),definition:de.defineModifier("definition"),constant:de.defineModifier("constant"),function:de.defineModifier("function"),standard:de.defineModifier("standard"),local:de.defineModifier("local"),special:de.defineModifier("special")};for(let s in O){let t=O[s];t instanceof de&&(t.name=s)}K$=tc([{tag:O.link,class:"tok-link"},{tag:O.heading,class:"tok-heading"},{tag:O.emphasis,class:"tok-emphasis"},{tag:O.strong,class:"tok-strong"},{tag:O.keyword,class:"tok-keyword"},{tag:O.atom,class:"tok-atom"},{tag:O.bool,class:"tok-bool"},{tag:O.url,class:"tok-url"},{tag:O.labelName,class:"tok-labelName"},{tag:O.inserted,class:"tok-inserted"},{tag:O.deleted,class:"tok-deleted"},{tag:O.literal,class:"tok-literal"},{tag:O.string,class:"tok-string"},{tag:O.number,class:"tok-number"},{tag:[O.regexp,O.escape,O.special(O.string)],class:"tok-string2"},{tag:O.variableName,class:"tok-variableName"},{tag:O.local(O.variableName),class:"tok-variableName tok-local"},{tag:O.definition(O.variableName),class:"tok-variableName tok-definition"},{tag:O.special(O.variableName),class:"tok-variableName2"},{tag:O.definition(O.propertyName),class:"tok-propertyName tok-definition"},{tag:O.typeName,class:"tok-typeName"},{tag:O.namespace,class:"tok-namespace"},{tag:O.className,class:"tok-className"},{tag:O.macroName,class:"tok-macroName"},{tag:O.propertyName,class:"tok-propertyName"},{tag:O.operator,class:"tok-operator"},{tag:O.comment,class:"tok-comment"},{tag:O.meta,class:"tok-meta"},{tag:O.invalid,class:"tok-invalid"},{tag:O.punctuation,class:"tok-punctuation"}])});var J$,Nf,mv=W(()=>{ys();ii();J$=It({String:O.string,Number:O.number,"True False":O.bool,PropertyName:O.propertyName,Null:O.null,", :":O.separator,"[ ]":O.squareBracket,"{ }":O.brace}),Nf=Kt.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:"#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O",goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:"\u26A0 JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array",maxTerm:25,nodeProps:[["isolate",-2,6,11,""],["openedBy",7,"{",14,"["],["closedBy",8,"}",15,"]"]],propSources:[J$],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0})});function tP(s){if(s<768)return!1;for(let t=0,e=ja.length;;){let i=t+e>>1;if(s<ja[i])e=i;else if(s>=Xf[i])t=i+1;else return!0;if(t==e)return!1}}function gv(s){return s>=127462&&s<=127487}function T_(s){for(let t=0;t<ja.length;t++)if(Xf[t]>s)return ja[t]<=s;return!1}function Sv(s,t,e=!0,i=!0){return(e?Ov:eP)(s,t,i)}function Ov(s,t,e){if(t==s.length)return t;t&&yv(s.charCodeAt(t))&&vv(s.charCodeAt(t-1))&&t--;let i=Bf(s,t);for(t+=xv(i);t<s.length;){let r=Bf(s,t);if(i==bv||r==bv||e&&tP(r))t+=xv(r),i=r;else if(gv(r)){let n=0,o=t-2;for(;o>=0&&gv(Bf(s,o));)n++,o-=2;if(n%2==0)break;t+=2}else break}return t}function eP(s,t,e){for(;t>0;){let i=Ov(s,t-2,e);if(i<t)return i;t--}return 0}function Bf(s,t){let e=s.charCodeAt(t);if(!vv(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return yv(i)?(e-55296<<10)+(i-56320)+65536:e}function yv(s){return s>=56320&&s<57344}function vv(s){return s>=55296&&s<56320}function xv(s){return s<65536?1:2}var ja,Xf,bv,wv=W(()=>{ja=[],Xf=[];(()=>{let s="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let t=0,e=0;t<s.length;t++)(t%2?Xf:ja).push(e=e+s[t])})();bv=8205});function iP(s){let t=-1;for(let e of s)t+=e.length+1;return t}function ic(s,t,e=0,i=1e9){for(let r=0,n=0,o=!0;n<s.length&&r<=i;n++){let a=s[n],l=r+a.length;l>=e&&(l>i&&(a=a.slice(0,i-r)),r<e&&(a=a.slice(e-r)),o?(t[t.length-1]+=a,o=!1):t.push(a)),r=l+1}return t}function kv(s,t,e){return ic(s,[""],t,e)}function In(s,t,e){return t=Math.max(0,Math.min(s.length,t)),[t,Math.max(t,Math.min(s.length,e))]}function Et(s,t,e=!0,i=!0){return Sv(s,t,e,i)}function sP(s){return s>=56320&&s<57344}function rP(s){return s>=55296&&s<56320}function Vt(s,t){let e=s.charCodeAt(t);if(!rP(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return sP(i)?(e-55296<<10)+(i-56320)+65536:e}function mc(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function Qe(s){return s<65536?1:2}function zt(s,t,e,i=!1){if(t==0&&e<=0)return;let r=s.length-2;r>=0&&e<=0&&e==s[r+1]?s[r]+=t:r>=0&&t==0&&s[r]==0?s[r+1]+=e:i?(s[r]+=t,s[r+1]+=e):s.push(t,e)}function Wi(s,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(e);else{for(;s.length<i;)s.push(et.empty);s.push(e)}}function zf(s,t,e){let i=s.inserted;for(let r=0,n=0,o=0;o<s.sections.length;){let a=s.sections[o++],l=s.sections[o++];if(l<0)r+=a,n+=a;else{let h=r,c=n,u=et.empty;for(;h+=a,c+=l,l&&i&&(u=u.append(i[o-2>>1])),!(e||o==s.sections.length||s.sections[o+1]<0);)a=s.sections[o++],l=s.sections[o++];t(r,h,n,c,u),r=h,n=c}}}function _f(s,t,e,i=!1){let r=[],n=i?[]:null,o=new ws(s),a=new ws(t);for(let l=-1;;){if(o.done&&a.len||a.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&a.ins==-1){let h=Math.min(o.len,a.len);zt(r,h,-1),o.forward(h),a.forward(h)}else if(a.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(a.len<o.len||a.len==o.len&&!e))){let h=a.len;for(zt(r,a.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&l<o.i&&o.len<=c&&(zt(r,0,o.ins),n&&Wi(n,r,o.text),l=o.i),o.forward(c),h-=c}a.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(a.ins==-1){let u=Math.min(c,a.len);h+=u,c-=u,a.forward(u)}else if(a.ins==0&&a.len<c)c-=a.len,a.next();else break;zt(r,h,l<o.i?o.ins:0),n&&l<o.i&&Wi(n,r,o.text),l=o.i,o.forward(o.len-c)}else{if(o.done&&a.done)return n?_t.createSet(r,n):si.create(r);throw new Error("Mismatched change set lengths")}}}function Av(s,t,e=!1){let i=[],r=e?[]:null,n=new ws(s),o=new ws(t);for(let a=!1;;){if(n.done&&o.done)return r?_t.createSet(i,r):si.create(i);if(n.ins==0)zt(i,n.len,0,a),n.next();else if(o.len==0&&!o.done)zt(i,0,o.ins,a),r&&Wi(r,i,o.text),o.next();else{if(n.done||o.done)throw new Error("Mismatched change set lengths");{let l=Math.min(n.len2,o.len),h=i.length;if(n.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;zt(i,l,c,a),r&&c&&Wi(r,i,o.text)}else o.ins==-1?(zt(i,n.off?0:n.len,l,a),r&&Wi(r,i,n.textBit(l))):(zt(i,n.off?0:n.len,o.off?0:o.ins,a),r&&!o.off&&Wi(r,i,o.text));a=(n.ins>l||o.ins>=0&&o.len>l)&&(a||i.length>h),n.forward2(l),o.forward(l)}}}}function Ev(s,t){for(let e of s.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}function jf(s,t){return s==t||s.length==t.length&&s.every((e,i)=>e===t[i])}function Cv(s,t,e){if(s.length!=t.length)return!1;for(let i=0;i<s.length;i++)if(!e(s[i],t[i]))return!1;return!0}function Wf(s,t){let e=!1;for(let i of t)Ua(s,i)&1&&(e=!0);return e}function nP(s,t,e){let i=e.map(l=>s[l.id]),r=e.map(l=>l.type),n=i.filter(l=>!(l&1)),o=s[t.id]>>1;function a(l){let h=[];for(let c=0;c<i.length;c++){let u=hc(l,i[c]);if(r[c]==2)for(let d of u)h.push(d);else h.push(u)}return t.combine(h)}return{create(l){for(let h of i)Ua(l,h);return l.values[o]=a(l),1},update(l,h){if(!Wf(l,n))return 0;let c=a(l);return t.compare(c,l.values[o])?0:(l.values[o]=c,1)},reconfigure(l,h){let c=Wf(l,i),u=h.config.facets[t.id],d=h.facet(t);if(u&&!c&&jf(e,u))return l.values[o]=d,0;let f=a(l);return t.compare(f,d)?(l.values[o]=d,0):(l.values[o]=f,1)}}}function Wa(s){return t=>new ac(t,s)}function oP(s,t,e){let i=[[],[],[],[],[]],r=new Map;function n(o,a){let l=r.get(o);if(l!=null){if(l<=a)return;let h=i[l].indexOf(o);h>-1&&i[l].splice(h,1),o instanceof Fa&&e.delete(o.compartment)}if(r.set(o,a),Array.isArray(o))for(let h of o)n(h,a);else if(o instanceof Fa){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=t.get(o.compartment)||o.inner;e.set(o.compartment,h),n(h,a)}else if(o instanceof ac)n(o.inner,o.prec);else if(o instanceof bt)i[a].push(o),o.provides&&n(o.provides,a);else if(o instanceof Dn)i[a].push(o),o.facet.extensions&&n(o.facet.extensions,As.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(h,a)}}return n(s,As.default),i.reduce((o,a)=>o.concat(a))}function Ua(s,t){if(t&1)return 2;let e=t>>1,i=s.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[e]=4;let r=s.computeSlot(s,s.config.dynamicSlots[e]);return s.status[e]=2|r}function hc(s,t){return t&1?s.config.staticValues[t>>1]:s.values[t>>1]}function aP(s,t){let e=[];for(let i=0,r=0;;){let n,o;if(i<s.length&&(r==t.length||t[r]>=s[i]))n=s[i++],o=s[i++];else if(r<t.length)n=t[r++],o=t[r++];else return e;!e.length||e[e.length-1]<n?e.push(n,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function Rv(s,t,e){var i;let r,n,o;return e?(r=t.changes,n=_t.empty(t.changes.length),o=s.changes.compose(t.changes)):(r=t.changes.map(s.changes),n=s.changes.mapDesc(t.changes,!0),o=s.changes.compose(r)),{changes:o,selection:t.selection?t.selection.map(n):(i=s.selection)===null||i===void 0?void 0:i.map(r),effects:F.mapEffects(s.effects,r).concat(F.mapEffects(t.effects,n)),annotations:s.annotations.length?s.annotations.concat(t.annotations):t.annotations,scrollIntoView:s.scrollIntoView||t.scrollIntoView}}function Uf(s,t,e){let i=t.selection,r=qn(t.annotations);return t.userEvent&&(r=r.concat(xt.userEvent.of(t.userEvent))),{changes:t.changes instanceof _t?t.changes:_t.of(t.changes||[],e,s.facet(Pv)),selection:i&&(i instanceof Q?i:Q.single(i.anchor,i.head)),effects:qn(t.effects),annotations:r,scrollIntoView:!!t.scrollIntoView}}function Iv(s,t,e){let i=Uf(s,t.length?t[0]:{},s.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let n=1;n<t.length;n++){t[n].filter===!1&&(e=!1);let o=!!t[n].sequential;i=Rv(i,Uf(s,t[n],o?i.changes.newLength:s.doc.length),o)}let r=xt.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return hP(e?lP(r):r)}function lP(s){let t=s.startState,e=!0;for(let r of t.facet(Qv)){let n=r(s);if(n===!1){e=!1;break}Array.isArray(n)&&(e=e===!0?n:aP(e,n))}if(e!==!0){let r,n;if(e===!1)n=s.changes.invertedDesc,r=_t.empty(t.doc.length);else{let o=s.changes.filter(e);r=o.changes,n=o.filtered.mapDesc(o.changes).invertedDesc}s=xt.create(t,r,s.selection&&s.selection.map(n),F.mapEffects(s.effects,n),s.annotations,s.scrollIntoView)}let i=t.facet(Tv);for(let r=i.length-1;r>=0;r--){let n=i[r](s);n instanceof xt?s=n:Array.isArray(n)&&n.length==1&&n[0]instanceof xt?s=n[0]:s=Iv(t,qn(n),!1)}return s}function hP(s){let t=s.startState,e=t.facet(Lv),i=s;for(let r=e.length-1;r>=0;r--){let n=e[r](s);n&&Object.keys(n).length&&(i=Rv(i,Uf(t,n,s.changes.newLength),!0))}return i==s?s:xt.create(t,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}function qn(s){return s==null?cP:Array.isArray(s)?s:[s]}function dP(s){if(Yf)return Yf.test(s);for(let t=0;t<s.length;t++){let e=s[t];if(/\w/.test(e)||e>"\x80"&&(e.toUpperCase()!=e.toLowerCase()||uP.test(e)))return!0}return!1}function fP(s){return t=>{if(!/\S/.test(t))return gt.Space;if(dP(t))return gt.Word;for(let e=0;e<s.length;e++)if(t.indexOf(s[e])>-1)return gt.Word;return gt.Other}}function te(s,t,e={}){let i={};for(let r of s)for(let n of Object.keys(r)){let o=r[n],a=i[n];if(a===void 0)i[n]=o;else if(!(a===o||o===void 0))if(Object.hasOwnProperty.call(e,n))i[n]=e[n](a,o);else throw new Error("Config merge conflict for field "+n)}for(let r in t)i[r]===void 0&&(i[r]=t[r]);return i}function Hf(s,t){return s==t||s.constructor==t.constructor&&s.eq(t)}function Gf(s,t){return s.from-t.from||s.value.startSide-t.value.startSide}function pP(s){if(s.length>1)for(let t=s[0],e=1;e<s.length;e++){let i=s[e];if(Gf(t,i)>0)return s.slice().sort(Gf);t=i}return s}function Dv(s,t,e){let i=new Map;for(let n of s)for(let o=0;o<n.chunk.length;o++)n.chunk[o].maxPoint<=0&&i.set(n.chunk[o],n.chunkPos[o]);let r=new Set;for(let n of t)for(let o=0;o<n.chunk.length;o++){let a=i.get(n.chunk[o]);a!=null&&(e?e.mapPos(a):a)==n.chunkPos[o]&&!e?.touchesRange(a,a+n.chunk[o].length)&&r.add(n.chunk[o])}return r}function Jf(s,t){for(let e=s[t];;){let i=(t<<1)+1;if(i>=s.length)break;let r=s[i];if(i+1<s.length&&r.compare(s[i+1])>=0&&(r=s[i+1],i++),e.compare(r)<0)break;s[i]=e,s[t]=r,t=i}}function qv(s,t,e,i,r,n){s.goto(t),e.goto(i);let o=i+r,a=i,l=i-t,h=!!n.boundChange;for(let c=!1;;){let u=s.to+l-e.to,d=u||s.endSide-e.endSide,f=d<0?s.to+l:e.to,p=Math.min(f,o);if(s.point||e.point?(s.point&&e.point&&Hf(s.point,e.point)&&tp(s.activeForPoint(s.to),e.activeForPoint(e.to))||n.comparePoint(a,p,s.point,e.point),c=!1):(c&&n.boundChange(a),p>a&&!tp(s.active,e.active)&&n.compareRange(a,p,s.active,e.active),h&&p<o&&(u||s.openEnd(f)!=e.openEnd(f))&&(c=!0)),f>o)break;a=f,d<=0&&s.next(),d>=0&&e.next()}}function tp(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++)if(s[e]!=t[e]&&!Hf(s[e],t[e]))return!1;return!0}function fc(s,t){for(let e=t,i=s.length-1;e<i;e++)s[e]=s[e+1];s.pop()}function pc(s,t,e){for(let i=s.length-1;i>=t;i--)s[i+1]=s[i];s[t]=e}function Nv(s,t){let e=-1,i=1e9;for(let r=0;r<t.length;r++)(t[r]-i||s[r].endSide-s[e].endSide)<0&&(e=r,i=t[r]);return e}function jt(s,t,e=s.length){let i=0;for(let r=0;r<e&&r<s.length;)s.charCodeAt(r)==9?(i+=t-i%t,r++):(i++,r=Et(s,r));return i}function Ha(s,t,e,i){for(let r=0,n=0;;){if(n>=t)return r;if(r==s.length)break;n+=s.charCodeAt(r)==9?e-n%e:1,r=Et(s,r)}return i===!0?-1:s.length}var et,ke,Rn,Ss,sc,rc,nc,Zf,At,si,_t,ws,ks,Q,Vf,X,Dn,oc,bt,As,fe,ac,Fi,Fa,lc,$v,Ff,Pv,Qv,Tv,Lv,Mv,Jt,cc,uc,F,xt,cP,gt,uP,Yf,at,Ae,Nn,Kf,K,Ee,dc,Ya,Es,ri=W(()=>{wv();et=class s{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=In(this,t,e);let r=[];return this.decompose(0,t,r,2),i.length&&i.decompose(0,i.length,r,3),this.decompose(e,this.length,r,1),Rn.from(r,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=In(this,t,e);let i=[];return this.decompose(t,e,i,0),Rn.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),r=new Ss(this),n=new Ss(t);for(let o=e,a=e;;){if(r.next(o),n.next(o),o=0,r.lineBreak!=n.lineBreak||r.done!=n.done||r.value!=n.value)return!1;if(a+=r.value.length,r.done||a>=i)return!0}}iter(t=1){return new Ss(this,t)}iterRange(t,e=this.length){return new sc(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let r=this.line(t).from;i=this.iterRange(r,Math.max(r,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new rc(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?s.empty:t.length<=32?new ke(t):Rn.from(ke.split(t,[]))}},ke=class s extends et{constructor(t,e=iP(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,r){for(let n=0;;n++){let o=this.text[n],a=r+o.length;if((e?i:a)>=t)return new nc(r,a,i,o);r=a+1,i++}}decompose(t,e,i,r){let n=t<=0&&e>=this.length?this:new s(kv(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(r&1){let o=i.pop(),a=ic(n.text,o.text.slice(),0,n.length);if(a.length<=32)i.push(new s(a,o.length+n.length));else{let l=a.length>>1;i.push(new s(a.slice(0,l)),new s(a.slice(l)))}}else i.push(n)}replace(t,e,i){if(!(i instanceof s))return super.replace(t,e,i);[t,e]=In(this,t,e);let r=ic(this.text,ic(i.text,kv(this.text,0,t)),e),n=this.length+i.length-(e-t);return r.length<=32?new s(r,n):Rn.from(s.split(r,[]),n)}sliceString(t,e=this.length,i=`
10
+ See USAGE.md \xA7 Template parser \u2014 invariants + unsupported syntaxes.`),e[a]={t:"n",n:document.createTextNode(""),c:void 0,_fx:null}):e[a]={t:"a",n:r,name:l,c:void 0,_fx:null}}return e}function Ih(s){for(let t of s)t&&t._fx&&(t._fx(),t._fx=null)}function Wd(s){if(s.n.nodeType===1&&s.n[jd])return s.n;let t=document.createElement("span");return t.style.display="contents",t.setAttribute("role","presentation"),t[jd]=!0,s.n.replaceWith(t),s.n=t,t}function Fd(s,t){if(t!==s.c){if(s.t==="n")if(t!=null&&t._directive)t._commit(Wd(s));else if(gy(t))rr(t,Wd(s));else if(Array.isArray(t)){let e=Wd(s);e.replaceChildren();for(let i of t)if(gy(i)){let r=document.createElement("span");r.style.display="contents",r.setAttribute("role","presentation"),e.appendChild(r),rr(i,r)}else e.appendChild(document.createTextNode(i??""))}else if(t instanceof Node)s.n.replaceWith(t),s.n=t;else if(s.n[jd]){let e=document.createTextNode(t??"");s.n.replaceWith(e),s.n=e}else s.n.textContent=t??"";else if(s.t==="a")t==null||t===!1?s.n.removeAttribute(s.name):s.n.setAttribute(s.name,t===!0?"":t);else if(s.t==="p"){if(!s._resolved){let e=fy(s.n,s.name);e!==s.name&&(s.name=e),s._resolved=!0}s.n[s.name]=t}else s.t==="e"&&(by(s.c)&&s.n.removeEventListener(s.name,s.c),by(t)&&s.n.addEventListener(s.name,t));s.c=t}}function OC(s,t){for(let e=0;e<s.length;e++){let i=s[e];if(!i)continue;let r=t[e],n=i.t!=="e"&&typeof r=="function",o=!n&&i.t!=="e"&&Vd(r);if(i._fx&&!n&&!o&&(i._fx(),i._fx=null),n){i._fx||(i._fx=cs(()=>Fd(i,r())));continue}if(o){i._fx||(i._fx=cs(()=>Fd(i,r.value)));continue}Fd(i,r)}}function yC(s,t,e){return{_directive:!0,_commit(i){let r=i[nr]||new Map,n=new Map,o=[];for(let l=0;l<s.length;l++){let h=t(s[l],l);if(n.has(h))continue;o.push(h);let c=e(s[l],l);if(r.has(h)){let u=r.get(h);rr(c,u),n.set(h,u)}else{let u=document.createElement("span");u.style.display="contents",u.setAttribute("role","presentation"),rr(c,u),n.set(h,u)}}for(let[l,h]of r)n.has(l)||(h._i&&Ih(h._i.p),h.remove());let a=null;for(let l=o.length-1;l>=0;l--){let h=n.get(o[l]);(h.nextSibling!==a||h.parentNode!==i)&&i.insertBefore(h,a),a=h}i[nr]=n}}}var jd,nr,uy,dy,Rh,La,py,gy,by,Ud=W(()=>{"use strict";Pt();[jd,nr]=[Symbol(),Symbol()];uy=new WeakMap;dy={classname:"className",innertext:"innerText",innerhtml:"innerHTML",outerhtml:"outerHTML",textcontent:"textContent",tabindex:"tabIndex",arialabel:"ariaLabel",ariadescribedby:"ariaDescribedBy",arialabelledby:"ariaLabelledBy",ariarole:"role",contenteditable:"contentEditable",readonly:"readOnly",maxlength:"maxLength",minlength:"minLength",colspan:"colSpan",rowspan:"rowSpan",cellpadding:"cellPadding",cellspacing:"cellSpacing",usemap:"useMap",ismap:"isMap",accesskey:"accessKey",defaultchecked:"defaultChecked",defaultvalue:"defaultValue",defaultselected:"defaultSelected"};Rh="http://www.w3.org/2000/svg",La="http://www.w3.org/1998/Math/MathML",py="http://www.w3.org/1999/xhtml";gy=s=>s!=null&&typeof s=="object"&&s.strings,by=s=>typeof s=="function"||s!=null&&typeof s.handleEvent=="function"});function yy(s){if(!s.name)throw new Error("Trait requires a name");if(!s.setup)throw new Error(`Trait "${s.name}" requires a setup function`);if(!s.category)throw new Error(`Trait "${s.name}" requires a category`);if(!Oy.has(s.category))throw new Error(`Trait "${s.name}" has unknown category "${s.category}". Known: ${[...Oy].join(", ")}`);if(!s.description)throw new Error(`Trait "${s.name}" requires a description`);let t=Object.freeze({name:s.name,category:s.category,description:s.description,attributes:Object.freeze(s.attributes||[]),events:Object.freeze(s.events||[]),config:Object.freeze(s.config||[])});function e(){let i=null;return{schema:t,connect(r,n){i=s.setup({host:r,...n||{}})},disconnect(r){i&&(i(),i=null);for(let n of t.attributes)r.hasAttribute(n)&&(console.warn(`Trait "${t.name}": attribute "${n}" still present after disconnect`),r.removeAttribute(n))}}}return e.schema=t,Dh.set(s.name,e),e}function vy(s){return Dh.get(s)||null}function Lq(s){return Dh.get(s)?.schema||null}function Mq(){return[...Dh.keys()]}var Dh,Oy,Yd=W(()=>{"use strict";Dh=new Map,Oy=new Set(["input-interaction","keyboard-navigation","forms-data","layout-measurement","motion-positioning","animation-feedback","visual-dynamics","interaction-delight","audio-haptics-sensory"])});function vC(s,t){s[Ma]=new Map,s[Hd]=new Map;for(let[e,i]of Object.entries(t)){let r=i.attribute??e.toLowerCase(),n=i.type??String,o=Object.prototype.hasOwnProperty.call(s,e),a=o?s[e]:void 0;o&&delete s[e];let l=Zi(i.default??void 0);s[Hd].set(e,l),Object.defineProperty(s,e,{get(){return l.value},set(h){let c=l.peek();Object.is(c,h)||(s[Ma].set(e,c),l.value=h,i.reflect&&SC(s,r,h,n))},configurable:!0}),o&&(l.value=a)}}function SC(s,t,e,i){i===Boolean?e?s.setAttribute(t,""):s.removeAttribute(t):e==null?s.removeAttribute(t):s.setAttribute(t,String(e))}function wC(s){if(Object.hasOwn(s,"_sa"))return;s._sa=!0;let t=s.styles;if(!t||!("adoptedStyleSheets"in document))return;let e=Array.isArray(t)?t:[t];document.adoptedStyleSheets=[...document.adoptedStyleSheets,...e.filter(i=>!document.adoptedStyleSheets.includes(i))]}function Sy(s){if(Object.hasOwn(s,"_pp"))return;s._pp={};let t=s.parts;if(t)for(let[e,i]of Object.entries(t)){let r=document.createElement("template");r.innerHTML=i,s._pp[e]=r.content.firstElementChild}}var Hd,Ma,xC,xy,v,P=W(()=>{"use strict";Pt();Ud();Pt();Ud();Yd();Hd=Symbol(),Ma=Symbol();xC=Object.freeze({setFormValue(){},setValidity(){},checkValidity(){return!0},reportValidity(){return!0},get form(){return null},get labels(){return[]},get validity(){return{}},get validationMessage(){return""},get willValidate(){return!1}});xy=(s,t)=>t===Boolean?s!==null:t===Number?s===null?null:+s:s;v=class extends HTMLElement{static get properties(){return{}}static get traits(){return[]}static get observedAttributes(){let t=Object.entries(this.properties).map(([e,i])=>i.attribute??e.toLowerCase());return t.includes("traits")?t:[...t,"traits"]}#t=[];#e=[];#i=[];#s=null;#r=null;#n=null;#a=Zi(0);constructor(){super(),this.internals=typeof this.attachInternals=="function"?this.attachInternals():xC,vC(this,this.constructor.properties)}connectedCallback(){let t=this.constructor;t._tag||(t._tag=this.localName),wC(t),Sy(t);for(let[e,i]of Object.entries(t.properties)){let r=i.attribute??e.toLowerCase();this.hasAttribute(r)&&(this[e]=xy(this.getAttribute(r),i.type??String))}H(()=>this.connected()),this.#t.push(cs(()=>{for(let i of this[Hd].values())i.value;this.#a.value;let e=t.template(this);if(e&&rr(e,this),this.render(),this[Ma].size){let i=new Map(this[Ma]);this[Ma].clear(),this.updated(i)}},{host:this.localName,onError:this.onError?e=>this.onError(e):null})),this.#n||(this.#n=new Set);for(let e of t.traits)this.#l(e);this.#h(),this.#s&&this.#o()}disconnectedCallback(){this._i&&Ih(this._i.p);for(let t of this.#t)t();this.#t.length=0;for(let t of this.#i)t.value=void 0;this.#i.length=0;for(let t of this.#e)t.disconnect(this);this.#e.length=0,this.#n?.clear(),this.#r?.(),this.#r=null,this.#s?.disconnect?.(this),this.disconnected()}#o(){let t=this.#s;t.connect?.(this),this.#r=t.subscribe?.(()=>{this.#a.value++})}get controller(){return this.#s}set controller(t){this.#r?.(),this.#r=null,this.#s?.disconnect?.(this),this.#s=t,t&&this.isConnected&&this.#o()}#l(t,{declarative:e=!1}={}){this.#n.add(t);let i=t();i.connect(this,{host:this,signal:Zi,computed:_d,effect:cs}),e&&(i._declarative=!0),this.#e.push(i)}addTrait(t){return this.#n||(this.#n=new Set),this.#n.has(t)?this:(this.#l(t),this)}#h(){let t=this.getAttribute("traits");if(t)for(let e of t.split(/\s+/).filter(Boolean)){let i=vy(e);if(!i){console.warn(`<${this.localName}> traits="${e}" \u2014 trait not found. Did you forget to import it?`);continue}this.#n.has(i)||this.#l(i,{declarative:!0})}}#c(){if(!this.#n)return;let t=[];for(let e of this.#e)if(e._declarative){e.disconnect(this);for(let i of this.#n)if(i.schema?.name&&e.schema?.name===i.schema.name){this.#n.delete(i);break}}else t.push(e);this.#e.length=0,this.#e.push(...t),this.#h()}attributeChangedCallback(t,e,i){if(t==="traits"){this.isConnected&&this.#c();return}for(let[r,n]of Object.entries(this.constructor.properties))if((n.attribute??r.toLowerCase())===t){this[r]=xy(i,n.type??String);break}}static template=()=>null;static create(t={}){let e=this._tag??customElements.getName?.(this);if(!e)throw new Error("Component not registered");let i=document.createElement(e);for(let[r,n]of Object.entries(t))i[r]=n;return i}signal(t){let e=Zi(t);return this.#i.push(e),e}ensure(t){for(let n of this.children)if(n.getAttribute("slot")===t)return n;let e=this.#d(t);if(e)return e;Sy(this.constructor);let i=this.constructor._pp?.[t];if(!i)return null;let r=i.cloneNode(!0);return r._uiPart=!0,this.appendChild(r),r}drop(t){for(let i of this.children)if(i.getAttribute("slot")===t){i.remove();return}let e=this.#d(t);e&&e.remove()}#d(t){for(let e of this.querySelectorAll(`[slot="${t}"]`)){let i=e.parentElement,r=!0;for(;i&&i!==this;){if(i.localName.includes("-")){r=!1;break}i=i.parentElement}if(r&&i===this)return e}return null}reconcile(t,e,i,r){let n=t[nr]||new Map,o=new Map,a=[];for(let h=0;h<e.length;h++){let c=e[h],u=i(c,h);if(o.has(u))continue;let d=n.get(u);d?r(c,h,d):d=r(c,h,null),o.set(u,d),a.push(u)}for(let[h,c]of n)o.has(h)||c.remove();let l=null;for(let h=a.length-1;h>=0;h--){let c=o.get(a[h]);(c.nextSibling!==l||c.parentNode!==t)&&t.insertBefore(c,l),l=c}t[nr]=o}connected(){}render(){}disconnected(){}updated(t){}}});function Zq(s,t){customElements.define(s,t)}function y(s,t){return customElements.get(s)?!1:(customElements.define(s,t),!0)}function zq(s){return!!customElements.get(s)}var C=W(()=>{"use strict"});function Gy(s,t,e,i){switch(s){case-2:return e<t;case-1:return i>=t&&e<t;case 0:return e<t&&i>t;case 1:return e<=t&&i>t;case 2:return i>t;case 4:return!0}}function za(s,t,e,i){for(var r;s.from==s.to||(e<1?s.from>=t:s.from>t)||(e>-1?s.to<=t:s.to<t);){let o=!i&&s instanceof ue&&s.index<0?null:s.parent;if(!o)return s;s=o}let n=i?0:it.IgnoreOverlays;if(i)for(let o=s,a=o.parent;a;o=a,a=o.parent)o instanceof ue&&o.index<0&&((r=a.enter(t,e,n))===null||r===void 0?void 0:r.from)!=o.from&&(s=a);for(;;){let o=s.enter(t,e,n);if(!o)return s;s=o}}function Ky(s,t,e,i){let r=s.cursor(),n=[];if(!r.firstChild())return n;if(e!=null){for(let o=!1;!o;)if(o=r.type.is(e),!r.nextSibling())return n}for(;;){if(i!=null&&r.type.is(i))return n;if(r.type.is(t)&&n.push(r.node),!r.nextSibling())return i==null?n:[]}}function gf(s,t,e=t.length-1){for(let i=s;e>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[e]&&t[e]!=i.name)return!1;e--}}return!0}function Jy(s){if(!s.length)return null;let t=0,e=s[0];for(let n=1;n<s.length;n++){let o=s[n];(o.from>e.from||o.to<e.to)&&(e=o,t=n)}let i=e instanceof ue&&e.index<0?null:e.parent,r=s.slice();return i?r[t]=i:r.splice(t,1),new Of(r,e)}function X$(s,t,e){let i=s.resolveInner(t,e),r=null;for(let n=i instanceof ue?i:i.context.parent;n;n=n.parent)if(n.index<0){let o=n.parent;(r||(r=[i])).push(o.resolve(t,e)),n=o}else{let o=mi.get(n.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let a=new ue(o.tree,o.overlay[0].from+n.from,-1,n);(r||(r=[i])).push(za(a,t,e,!1))}}return r?Jy(r):i}function yf(s){return s.children.some(t=>t instanceof gi||!t.type.isAnonymous||yf(t))}function B$(s){var t;let{buffer:e,nodeSet:i,maxBufferLength:r=1024,reused:n=[],minRepeatType:o=i.types.length}=s,a=Array.isArray(e)?new mf(e,e.length):e,l=i.types,h=0,c=0;function u(k,A,E,$,L,T){let{id:q,start:I,end:z,size:V}=a,U=c,tt=h;if(V<0)if(a.next(),V==-1){let wt=n[q];E.push(wt),$.push(I-k);return}else if(V==-3){h=q;return}else if(V==-4){c=q;return}else throw new RangeError(`Unrecognized record size: ${V}`);let nt=l[q],ft,lt,yt=I-k;if(z-I<=r&&(lt=b(a.pos-A,L))){let wt=new Uint16Array(lt.size-lt.skip),vt=a.pos-lt.size,$t=wt.length;for(;a.pos>vt;)$t=g(lt.start,wt,$t);ft=new gi(wt,z-lt.start,i),yt=lt.start-k}else{let wt=a.pos-V;a.next();let vt=[],$t=[],Mt=q>=o?q:-1,Ht=0,ls=z;for(;a.pos>wt;)Mt>=0&&a.id==Mt&&a.size>=0?(a.end<=ls-r&&(p(vt,$t,I,Ht,a.end,ls,Mt,U,tt),Ht=vt.length,ls=a.end),a.next()):T>2500?d(I,wt,vt,$t):u(I,wt,vt,$t,Mt,T+1);if(Mt>=0&&Ht>0&&Ht<vt.length&&p(vt,$t,I,Ht,I,ls,Mt,U,tt),vt.reverse(),$t.reverse(),Mt>-1&&Ht>0){let KO=f(nt,tt);ft=vf(nt,vt,$t,0,vt.length,0,z-I,KO,KO)}else ft=m(nt,vt,$t,z-I,U-z,tt)}E.push(ft),$.push(yt)}function d(k,A,E,$){let L=[],T=0,q=-1;for(;a.pos>A;){let{id:I,start:z,end:V,size:U}=a;if(U>4)a.next();else{if(q>-1&&z<q)break;q<0&&(q=V-r),L.push(I,z,V),T++,a.next()}}if(T){let I=new Uint16Array(T*4),z=L[L.length-2];for(let V=L.length-3,U=0;V>=0;V-=3)I[U++]=L[V],I[U++]=L[V+1]-z,I[U++]=L[V+2]-z,I[U++]=U;E.push(new gi(I,L[2]-z,i)),$.push(z-k)}}function f(k,A){return(E,$,L)=>{let T=0,q=E.length-1,I,z;if(q>=0&&(I=E[q])instanceof G){if(!q&&I.type==k&&I.length==L)return I;(z=I.prop(_.lookAhead))&&(T=$[q]+I.length+z)}return m(k,E,$,L,T,A)}}function p(k,A,E,$,L,T,q,I,z){let V=[],U=[];for(;k.length>$;)V.push(k.pop()),U.push(A.pop()+E-L);k.push(m(i.types[q],V,U,T-L,I-T,z)),A.push(L-E)}function m(k,A,E,$,L,T,q){if(T){let I=[_.contextHash,T];q=q?[I].concat(q):[I]}if(L>25){let I=[_.lookAhead,L];q=q?[I].concat(q):[I]}return new G(k,A,E,$,q)}function b(k,A){let E=a.fork(),$=0,L=0,T=0,q=E.end-r,I={size:0,start:0,skip:0};t:for(let z=E.pos-k;E.pos>z;){let V=E.size;if(E.id==A&&V>=0){I.size=$,I.start=L,I.skip=T,T+=4,$+=4,E.next();continue}let U=E.pos-V;if(V<0||U<z||E.start<q)break;let tt=E.id>=o?4:0,nt=E.start;for(E.next();E.pos>U;){if(E.size<0)if(E.size==-3||E.size==-4)tt+=4;else break t;else E.id>=o&&(tt+=4);E.next()}L=nt,$+=V,T+=tt}return(A<0||$==k)&&(I.size=$,I.start=L,I.skip=T),I.size>4?I:void 0}function g(k,A,E){let{id:$,start:L,end:T,size:q}=a;if(a.next(),q>=0&&$<o){let I=E;if(q>4){let z=a.pos-(q-4);for(;a.pos>z;)E=g(k,A,E)}A[--E]=I,A[--E]=T-k,A[--E]=L-k,A[--E]=$}else q==-3?h=$:q==-4&&(c=$);return E}let x=[],S=[];for(;a.pos>0;)u(s.start||0,s.bufferStart||0,x,S,-1,0);let w=(t=s.length)!==null&&t!==void 0?t:x.length?S[0]+x[0].length:0;return new G(l[s.topID],x.reverse(),S.reverse(),w)}function Vh(s,t){if(!s.isAnonymous||t instanceof gi||t.type!=s)return 1;let e=tv.get(t);if(e==null){e=1;for(let i of t.children){if(i.type!=s||!(i instanceof G)){e=1;break}e+=Vh(s,i)}tv.set(t,e)}return e}function vf(s,t,e,i,r,n,o,a,l){let h=0;for(let p=i;p<r;p++)h+=Vh(s,t[p]);let c=Math.ceil(h*1.5/8),u=[],d=[];function f(p,m,b,g,x){for(let S=b;S<g;){let w=S,k=m[S],A=Vh(s,p[S]);for(S++;S<g;S++){let E=Vh(s,p[S]);if(A+E>=c)break;A+=E}if(S==w+1){if(A>c){let E=p[w];f(E.children,E.positions,0,E.children.length,m[w]+x);continue}u.push(p[w])}else{let E=m[S-1]+p[S-1].length-k;u.push(vf(s,p,m,w,S,k,E,null,l))}d.push(k+x-n)}}return f(t,e,i,r,0),(a||l)(u,d,o)}function Os(s){return(t,e,i,r)=>new kf(t,s,e,i,r)}function ev(s){if(!s.length||s.some(t=>t.from>=t.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(s))}function Z$(s,t,e){for(let i of s){if(i.from>=e)break;if(i.to>t)return i.from<=t&&i.to>=e?2:1}return 0}function iv(s,t,e,i,r,n){if(t<e){let o=s.buffer[t+1];i.push(s.slice(t,e,o)),r.push(o-n)}}function z$(s){let{node:t}=s,e=[],i=t.context.buffer;do e.push(s.index),s.parent();while(!s.tree);let r=s.tree,n=r.children.indexOf(i),o=r.children[n],a=o.buffer,l=[n];function h(c,u,d,f,p,m){let b=e[m],g=[],x=[];iv(o,c,b,g,x,f);let S=a[b+1],w=a[b+2];l.push(g.length);let k=m?h(b+4,a[b+3],o.set.types[a[b]],S,w-S,m-1):t.toTree();return g.push(k),x.push(S-f),iv(o,a[b+3],u,g,x,f),new G(d,g,x,p)}r.children[n]=h(0,a.length,pt.none,0,o.length,e.length-1);for(let c of l){let u=s.tree.children[c],d=s.tree.positions[c];s.yield(new ue(u,d+s.from,c,s._tree))}}function sv(s,t){let e=null,i=t;for(let r=1,n=0;r<s.length;r++){let o=s[r-1].to,a=s[r].from;for(;n<i.length;n++){let l=i[n];if(l.from>=a)break;l.to<=o||(e||(i=e=t.slice()),l.from<o?(e[n]=new ce(l.from,o),l.to>a&&e.splice(n+1,0,new ce(a,l.to))):l.to>a?e[n--]=new ce(a,l.to):e.splice(n--,1))}}return i}function _$(s,t,e,i){let r=0,n=0,o=!1,a=!1,l=-1e9,h=[];for(;;){let c=r==s.length?1e9:o?s[r].to:s[r].from,u=n==t.length?1e9:a?t[n].to:t[n].from;if(o!=a){let d=Math.max(l,e),f=Math.min(c,u,i);d<f&&h.push(new ce(d,f))}if(l=Math.min(c,u),l==1e9)break;c==l&&(o?(o=!1,r++):o=!0),u==l&&(a?(a=!1,n++):a=!0)}return h}function rv(s,t){let e=[];for(let{pos:i,mount:r,frag:n}of s){let o=i+(r.overlay?r.overlay[0].from:0),a=o+r.tree.length,l=Math.max(n.from,o),h=Math.min(n.to,a);if(r.overlay){let c=r.overlay.map(d=>new ce(d.from+i,d.to+i)),u=_$(t,c,l,h);for(let d=0,f=l;;d++){let p=d==u.length,m=p?h:u[d].from;if(m>f&&e.push(new He(f,m,r.tree,-o,n.from>=f||n.openStart,n.to<=m||n.openEnd)),p)break;f=u[d].to}}else e.push(new He(l,h,r.tree,-o,n.from>=o||n.openStart,n.to<=a||n.openEnd))}return e}var Ef,q$,ce,_,mi,N$,pt,Ge,zh,Hy,it,G,mf,gi,_h,ue,bf,ms,Of,gs,tv,bs,He,Ke,xf,jh,Sf,wf,kf,Wh,Af,_e=W(()=>{Ef=1024,q$=0,ce=class{constructor(t,e){this.from=t,this.to=e}},_=class{constructor(t={}){this.id=q$++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=pt.match(t)),e=>{let i=t(e);return i===void 0?null:[this,i]}}};_.closedBy=new _({deserialize:s=>s.split(" ")}),_.openedBy=new _({deserialize:s=>s.split(" ")}),_.group=new _({deserialize:s=>s.split(" ")}),_.isolate=new _({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}}),_.contextHash=new _({perNode:!0}),_.lookAhead=new _({perNode:!0}),_.mounted=new _({perNode:!0});mi=class{constructor(t,e,i,r=!1){this.tree=t,this.overlay=e,this.parser=i,this.bracketed=r}static get(t){return t&&t.props&&t.props[_.mounted.id]}},N$=Object.create(null),pt=class s{constructor(t,e,i,r=0){this.name=t,this.props=e,this.id=i,this.flags=r}static define(t){let e=t.props&&t.props.length?Object.create(null):N$,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),r=new s(t.name||"",e,t.id,i);if(t.props){for(let n of t.props)if(Array.isArray(n)||(n=n(r)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}}return r}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(_.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let r of i.split(" "))e[r]=t[i];return i=>{for(let r=i.prop(_.group),n=-1;n<(r?r.length:0);n++){let o=e[n<0?i.name:r[n]];if(o)return o}}}};pt.none=new pt("",Object.create(null),0,8);Ge=class s{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let r=null;for(let n of t){let o=n(i);if(o){r||(r=Object.assign({},i.props));let a=o[1],l=o[0];l.combine&&l.id in r&&(a=l.combine(r[l.id],a)),r[l.id]=a}}e.push(r?new pt(i.name,r,i.id,i.flags):i)}return new s(e)}},zh=new WeakMap,Hy=new WeakMap;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays",s[s.EnterBracketed=16]="EnterBracketed"})(it||(it={}));G=class s{constructor(t,e,i,r,n){if(this.type=t,this.children=e,this.positions=i,this.length=r,this.props=null,n&&n.length){this.props=Object.create(null);for(let[o,a]of n)this.props[typeof o=="number"?o:o.id]=a}}toString(){let t=mi.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let i of this.children){let r=i.toString();r&&(e&&(e+=","),e+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new gs(this.topNode,t)}cursorAt(t,e=0,i=0){let r=zh.get(this)||this.topNode,n=new gs(r);return n.moveTo(t,e),zh.set(this,n._tree),n}get topNode(){return new ue(this,0,0,null)}resolve(t,e=0){let i=za(zh.get(this)||this.topNode,t,e,!1);return zh.set(this,i),i}resolveInner(t,e=0){let i=za(Hy.get(this)||this.topNode,t,e,!0);return Hy.set(this,i),i}resolveStack(t,e=0){return X$(this,t,e)}iterate(t){let{enter:e,leave:i,from:r=0,to:n=this.length}=t,o=t.mode||0,a=(o&it.IncludeAnonymous)>0;for(let l=this.cursor(o|it.IncludeAnonymous);;){let h=!1;if(l.from<=n&&l.to>=r&&(!a&&l.type.isAnonymous||e(l)!==!1)){if(l.firstChild())continue;h=!0}for(;h&&i&&(a||!l.type.isAnonymous)&&i(l),!l.nextSibling();){if(!l.parent())return;h=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:vf(pt.none,this.children,this.positions,0,this.children.length,0,this.length,(e,i,r)=>new s(this.type,e,i,r,this.propValues),t.makeTree||((e,i,r)=>new s(pt.none,e,i,r)))}static build(t){return B$(t)}};G.empty=new G(pt.none,[],[],0);mf=class s{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new s(this.buffer,this.index)}},gi=class s{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return pt.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],r=this.set.types[e],n=r.name;if(/\W/.test(n)&&!r.isError&&(n=JSON.stringify(n)),t+=4,i==t)return n;let o=[];for(;t<i;)o.push(this.childString(t)),t=this.buffer[t+3];return n+"("+o.join(",")+")"}findChild(t,e,i,r,n){let{buffer:o}=this,a=-1;for(let l=t;l!=e&&!(Gy(n,r,o[l+1],o[l+2])&&(a=l,i>0));l=o[l+3]);return a}slice(t,e,i){let r=this.buffer,n=new Uint16Array(e-t),o=0;for(let a=t,l=0;a<e;){n[l++]=r[a++],n[l++]=r[a++]-i;let h=n[l++]=r[a++]-i;n[l++]=r[a++]-t,o=Math.max(o,h)}return new s(n,o,this.set)}};_h=class{cursor(t=0){return new gs(this,t)}getChild(t,e=null,i=null){let r=Ky(this,t,e,i);return r.length?r[0]:null}getChildren(t,e=null,i=null){return Ky(this,t,e,i)}resolve(t,e=0){return za(this,t,e,!1)}resolveInner(t,e=0){return za(this,t,e,!0)}matchContext(t){return gf(this.parent,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let r=e.lastChild;if(!r||r.to!=e.to)break;r.type.isError&&r.from==r.to?(i=e,e=r.prevSibling):e=r}return i}get node(){return this}get next(){return this.parent}},ue=class s extends _h{constructor(t,e,i,r){super(),this._tree=t,this.from=e,this.index=i,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,i,r,n=0){for(let o=this;;){for(let{children:a,positions:l}=o._tree,h=e>0?a.length:-1;t!=h;t+=e){let c=a[t],u=l[t]+o.from,d;if(!(!(n&it.EnterBracketed&&c instanceof G&&(d=mi.get(c))&&!d.overlay&&d.bracketed&&i>=u&&i<=u+c.length)&&!Gy(r,i,u,u+c.length))){if(c instanceof gi){if(n&it.ExcludeBuffers)continue;let f=c.findChild(0,c.buffer.length,e,i-u,r);if(f>-1)return new ms(new bf(o,c,t,u),null,f)}else if(n&it.IncludeAnonymous||!c.type.isAnonymous||yf(c)){let f;if(!(n&it.IgnoreMounts)&&(f=mi.get(c))&&!f.overlay)return new s(f.tree,u,t,o);let p=new s(c,u,t,o);return n&it.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(e<0?c.children.length-1:0,e,i,r,n)}}}if(n&it.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,e,i=0){let r;if(!(i&it.IgnoreOverlays)&&(r=mi.get(this._tree))&&r.overlay){let n=t-this.from,o=i&it.EnterBracketed&&r.bracketed;for(let{from:a,to:l}of r.overlay)if((e>0||o?a<=n:a<n)&&(e<0||o?l>=n:l>n))return new s(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};bf=class{constructor(t,e,i,r){this.parent=t,this.buffer=e,this.index=i,this.start=r}},ms=class s extends _h{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,i);return n<0?null:new s(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,e,i=0){if(i&it.ExcludeBuffers)return null;let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return n<0?null:new s(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new s(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new s(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,r=this.index+4,n=i.buffer[this.index+3];if(n>r){let o=i.buffer[this.index+1];t.push(i.slice(r,n,o)),e.push(0)}return new G(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};Of=class{constructor(t,e){this.heads=t,this.node=e}get next(){return Jy(this.heads)}};gs=class{get name(){return this.type.name}constructor(t,e=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=e&~it.EnterBracketed,t instanceof ue)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let i=t._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:i,buffer:r}=this.buffer;return this.type=e||r.set.types[r.buffer[t]],this.from=i+r.buffer[t+1],this.to=i+r.buffer[t+2],!0}yield(t){return t?t instanceof ue?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:r}=this.buffer,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,i);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?i&it.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&it.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&it.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let r=i<0?0:this.stack[i]+4;if(this.index!=r)return this.yieldBuf(e.findChild(r,this.index,-1,0,4))}else{let r=e.buffer[this.index+3];if(r<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(r)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:r}=this;if(r){if(t>0){if(this.index<r.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(r.buffer.buffer[n+3]<this.index)return!1;({index:e,parent:i}=r)}else({index:e,_parent:i}=this._tree);for(;i;{index:e,_parent:i}=i)if(e>-1)for(let n=e+t,o=t<0?-1:i._tree.children.length;n!=o;n+=t){let a=i._tree.children[n];if(this.mode&it.IncludeAnonymous||a instanceof gi||!a.type.isAnonymous||yf(a))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let r=this.index,n=this.stack.length;n>=0;){for(let o=t;o;o=o._parent)if(o.index==r){if(r==this.index)return o;e=o,i=n+1;break t}r=this.stack[--n]}for(let r=i;r<this.stack.length;r++)e=new ms(this.buffer,e,this.stack[r]);return this.bufferNode=new ms(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let r=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&e&&e(this),r=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,r=!0}}}matchContext(t){if(!this.buffer)return gf(this.node.parent,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let r=t.length-1,n=this.stack.length-1;r>=0;n--){if(n<0)return gf(this._tree,t,r);let o=i[e.buffer[this.stack[n]]];if(!o.isAnonymous){if(t[r]&&t[r]!=o.name)return!1;r--}}return!0}};tv=new WeakMap;bs=class{constructor(){this.map=new WeakMap}setBuffer(t,e,i){let r=this.map.get(t);r||this.map.set(t,r=new Map),r.set(e,i)}getBuffer(t,e){let i=this.map.get(t);return i&&i.get(e)}set(t,e){t instanceof ms?this.setBuffer(t.context.buffer,t.index,e):t instanceof ue&&this.map.set(t.tree,e)}get(t){return t instanceof ms?this.getBuffer(t.context.buffer,t.index):t instanceof ue?this.map.get(t.tree):void 0}cursorSet(t,e){t.buffer?this.setBuffer(t.buffer.buffer,t.index,e):this.map.set(t.tree,e)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}},He=class s{constructor(t,e,i,r,n=!1,o=!1){this.from=t,this.to=e,this.tree=i,this.offset=r,this.open=(n?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,e=[],i=!1){let r=[new s(0,t.length,t,0,!1,i)];for(let n of e)n.to>t.length&&r.push(n);return r}static applyChanges(t,e,i=128){if(!e.length)return t;let r=[],n=1,o=t.length?t[0]:null;for(let a=0,l=0,h=0;;a++){let c=a<e.length?e[a]:null,u=c?c.fromA:1e9;if(u-l>=i)for(;o&&o.from<u;){let d=o;if(l>=d.from||u<=d.to||h){let f=Math.max(d.from,l)-h,p=Math.min(d.to,u)-h;d=f>=p?null:new s(f,p,d.tree,d.offset+h,a>0,!!c)}if(d&&r.push(d),o.to>u)break;o=n<t.length?t[n++]:null}if(!c)break;l=c.toA,h=c.toA-c.toB}return r}},Ke=class{startParse(t,e,i){return typeof t=="string"&&(t=new xf(t)),i=i?i.length?i.map(r=>new ce(r.from,r.to)):[new ce(0,0)]:[new ce(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let r=this.startParse(t,e,i);for(;;){let n=r.advance();if(n)return n}}},xf=class{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}};jh=class{constructor(t,e,i,r,n,o){this.parser=t,this.parse=e,this.overlay=i,this.bracketed=r,this.target=n,this.from=o}};Sf=class{constructor(t,e,i,r,n,o,a,l){this.parser=t,this.predicate=e,this.mounts=i,this.index=r,this.start=n,this.bracketed=o,this.target=a,this.prev=l,this.depth=0,this.ranges=[]}},wf=new _({perNode:!0}),kf=class{constructor(t,e,i,r,n){this.nest=e,this.input=i,this.fragments=r,this.ranges=n,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let r of this.inner)r.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new G(i.type,i.children,i.positions,i.length,i.propValues.concat([[wf,this.stoppedAt]]))),i}let t=this.inner[this.innerDone],e=t.parse.advance();if(e){this.innerDone++;let i=Object.assign(Object.create(null),t.target.props);i[_.mounted.id]=new mi(e,t.overlay,t.parser,t.bracketed),t.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].from<t&&(t=Math.min(t,this.inner[e].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].parse.stopAt(t)}startInner(){let t=new Af(this.fragments),e=null,i=null,r=new gs(new ue(this.baseTree,this.ranges[0].from,0,null),it.IncludeAnonymous|it.IgnoreMounts);t:for(let n,o;;){let a=!0,l;if(this.stoppedAt!=null&&r.from>=this.stoppedAt)a=!1;else if(t.hasNode(r)){if(e){let h=e.mounts.find(c=>c.frag.from<=r.from&&c.frag.to>=r.to&&c.mount.overlay);if(h)for(let c of h.mount.overlay){let u=c.from+h.pos,d=c.to+h.pos;u>=r.from&&d<=r.to&&!e.ranges.some(f=>f.from<d&&f.to>u)&&e.ranges.push({from:u,to:d})}}a=!1}else if(i&&(o=Z$(i.ranges,r.from,r.to)))a=o!=2;else if(!r.type.isAnonymous&&(n=this.nest(r,this.input))&&(r.from<r.to||!n.overlay)){r.tree||(z$(r),e&&e.depth++,i&&i.depth++);let h=t.findMounts(r.from,n.parser);if(typeof n.overlay=="function")e=new Sf(n.parser,n.overlay,h,this.inner.length,r.from,!!n.bracketed,r.tree,e);else{let c=sv(this.ranges,n.overlay||(r.from<r.to?[new ce(r.from,r.to)]:[]));c.length&&ev(c),(c.length||!n.overlay)&&this.inner.push(new jh(n.parser,c.length?n.parser.startParse(this.input,rv(h,c),c):n.parser.startParse(""),n.overlay?n.overlay.map(u=>new ce(u.from-r.from,u.to-r.from)):null,!!n.bracketed,r.tree,c.length?c[0].from:r.from)),n.overlay?c.length&&(i={ranges:c,depth:0,prev:i}):a=!1}}else if(e&&(l=e.predicate(r))&&(l===!0&&(l=new ce(r.from,r.to)),l.from<l.to)){let h=e.ranges.length-1;h>=0&&e.ranges[h].to==l.from?e.ranges[h]={from:e.ranges[h].from,to:l.to}:e.ranges.push(l)}if(a&&r.firstChild())e&&e.depth++,i&&i.depth++;else for(;!r.nextSibling();){if(!r.parent())break t;if(e&&!--e.depth){let h=sv(this.ranges,e.ranges);h.length&&(ev(h),this.inner.splice(e.index,0,new jh(e.parser,e.parser.startParse(this.input,rv(e.mounts,h),h),e.ranges.map(c=>new ce(c.from-e.start,c.to-e.start)),e.bracketed,e.target,h[0].from))),e=e.prev}i&&!--i.depth&&(i=i.prev)}}}};Wh=class{constructor(t,e){this.offset=e,this.done=!1,this.cursor=t.cursor(it.IncludeAnonymous|it.IgnoreMounts)}moveTo(t){let{cursor:e}=this,i=t-this.offset;for(;!this.done&&e.from<i;)if(!(e.to>=t&&e.enter(i,1,it.IgnoreOverlays|it.ExcludeBuffers)))if(e.to<=t)e.next(!1)||(this.done=!0);else break}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let e=this.cursor.tree;;){if(e==t.tree)return!0;if(e.children.length&&e.positions[0]==0&&e.children[0]instanceof G)e=e.children[0];else break}return!1}},Af=class{constructor(t){var e;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let i=this.curFrag=t[0];this.curTo=(e=i.tree.prop(wf))!==null&&e!==void 0?e:i.to,this.inner=new Wh(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=(t=e.tree.prop(wf))!==null&&t!==void 0?t:e.to,this.inner=new Wh(e.tree,-e.offset)}}findMounts(t,e){var i;let r=[];if(this.inner){this.inner.cursor.moveTo(t,1);for(let n=this.inner.cursor.node;n;n=n.parent){let o=(i=n.tree)===null||i===void 0?void 0:i.prop(_.mounted);if(o&&o.parser==e)for(let a=this.fragI;a<this.fragments.length;a++){let l=this.fragments[a];if(l.from>=n.to)break;l.tree==this.curFrag.tree&&r.push({frag:l,pos:n.from-l.offset,mount:o})}}}return r}}});function _a(s,t=Uint16Array){if(typeof s!="string")return s;let e=null;for(let i=0,r=0;i<s.length;){let n=0;for(;;){let o=s.charCodeAt(i++),a=!1;if(o==126){n=65535;break}o>=92&&o--,o>=34&&o--;let l=o-32;if(l>=46&&(l-=46,a=!0),n+=l,a)break;n*=46}e?e[r++]=n:e=new t(n)}return e}function ov(s,t,e,i,r,n){let o=0,a=1<<i,{dialect:l}=e.p.parser;t:for(;(a&s[o])!=0;){let h=s[o+1];for(let f=o+3;f<h;f+=2)if((s[f+1]&a)>0){let p=s[f];if(l.allows(p)&&(t.token.value==-1||t.token.value==p||V$(p,t.token.value,r,n))){t.acceptToken(p);break}}let c=t.next,u=0,d=s[o+2];if(t.next<0&&d>u&&s[h+d*3-3]==65535){o=s[h+d*3-1];continue t}for(;u<d;){let f=u+d>>1,p=h+f+(f<<1),m=s[p],b=s[p+1]||65536;if(c<m)d=f;else if(c>=b)u=f+1;else{o=s[p+2],t.advance();continue t}}break}}function av(s,t,e){for(let i=t,r;(r=s[i])!=65535;i++)if(r==e)return i-t;return-1}function V$(s,t,e,i){let r=av(e,i,t);return r<0||av(e,i,s)<r}function lv(s,t,e){let i=s.cursor(it.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(s.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:s.length}}function hv(s,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==s.pos&&i.sameState(s)){t[e].score<s.score&&(t[e]=s);return}}t.push(s)}function bi(s,t){return s[t]|s[t+1]<<16}function j$(s){let t=null;for(let e of s){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function cv(s){if(s.external){let t=s.extend?1:0;return(e,i)=>s.external(e,i)<<1|t}return s.get}var Fh,Uh,Cf,$f,Mn,nv,Yh,_i,Oi,mt,we,Pf,Qf,Tf,Lf,Mf,Rf,yi,Kt,ys=W(()=>{_e();Fh=class s{constructor(t,e,i,r,n,o,a,l,h,c=0,u){this.p=t,this.stack=e,this.state=i,this.reducePos=r,this.pos=n,this.score=o,this.buffer=a,this.bufferBase=l,this.curContext=h,this.lookAhead=c,this.parent=u}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let r=t.parser.context;return new s(t,[],e,i,i,0,[],0,r?new Uh(r,r.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,r=t&65535,{parser:n}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),a=n.dynamicPrecedence(r);if(a&&(this.score+=a),i==0){r<n.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(n.getGoto(this.state,r,!0),this.reducePos),r<n.minRepeatTerm&&this.storeNode(r,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(r,this.reducePos);return}let l=this.stack.length-(i-1)*3-(t&262144?6:0),h=l?this.stack[l-2]:this.p.ranges[0].from;r<n.minRepeatTerm&&h==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let c=this.reducePos-h;c>=2e3&&!(!((e=this.p.parser.nodeSet.types[r])===null||e===void 0)&&e.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=c));let u=l?this.stack[l-1]:0,d=this.bufferBase+this.buffer.length-u;if(r<n.minRepeatTerm||t&131072){let f=n.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(r,h,f,d+4,!0)}if(t&262144)this.state=this.stack[l];else{let f=this.stack[l-3];this.state=n.getGoto(f,r,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(r,h)}storeNode(t,e,i,r=4,n=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this.buffer.length;if(o>0&&this.buffer[o-4]==0&&this.buffer[o-1]>-1){if(e==i)return;if(this.buffer[o-2]>=e){this.buffer[o-2]=i;return}}}if(!n||this.pos==i)this.buffer.push(t,e,i,r);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let a=!1;for(let l=o;l>0&&this.buffer[l-2]>i;l-=4)if(this.buffer[l-1]>=0){a=!0;break}if(a)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,r>4&&(r-=4)}this.buffer[o]=t,this.buffer[o+1]=e,this.buffer[o+2]=i,this.buffer[o+3]=r}}shift(t,e,i,r){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let n=t,{parser:o}=this.p;this.pos=r;let a=o.stateFlag(n,1);!a&&(r>i||e<=o.maxNode)&&(this.reducePos=r),this.pushState(n,a?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=o.maxNode&&this.buffer.push(e,i,r,4)}else this.pos=r,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,r,4)}apply(t,e,i,r){t&65536?this.reduce(t):this.shift(t,e,i,r)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let r=this.pos;this.reducePos=this.pos=r+t.length,this.pushState(e,r),this.buffer.push(i,r,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),r=t.bufferBase+e;for(;t&&r==t.bufferBase;)t=t.parent;return new s(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,r,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Cf(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let r=[];for(let n=0,o;n<e.length;n+=2)(o=e[n+1])!=this.state&&this.p.parser.hasAction(o,t)&&r.push(e[n],o);if(this.stack.length<120)for(let n=0;r.length<8&&n<e.length;n+=2){let o=e[n+1];r.some((a,l)=>l&1&&a==o)||r.push(e[n],o)}e=r}let i=[];for(let r=0;r<e.length&&i.length<4;r+=2){let n=e[r+1];if(n==this.state)continue;let o=this.split();o.pushState(n,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(e[r],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,r=e&65535,n=this.stack.length-i*3;if(n<0||t.getGoto(this.stack[n],r,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;e=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(r,n)=>{if(!e.includes(r))return e.push(r),t.allActions(r,o=>{if(!(o&393216))if(o&65536){let a=(o>>19)-n;if(a>1){let l=o&65535,h=this.stack.length-a*3;if(h>=0&&t.getGoto(this.stack[h],l,!1)>=0)return a<<19|65536|l}}else{let a=i(o,n+1);if(a!=null)return a}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new Uh(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},Uh=class{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}},Cf=class{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,i=t>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let r=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=r}},$f=class s{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new s(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new s(this.stack,this.pos,this.index)}};Mn=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},nv=new Mn,Yh=class{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=nv,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,r=this.rangeIndex,n=this.pos+t;for(;n<i.from;){if(!r)return null;let o=this.ranges[--r];n-=i.from-o.to,i=o}for(;e<0?n>i.to:n>=i.to;){if(r==this.ranges.length-1)return null;let o=this.ranges[++r];n+=o.from-i.to,i=o}return n}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,i,r;if(e>=0&&e<this.chunk.length)i=this.pos+t,r=this.chunk.charCodeAt(e);else{let n=this.resolveOffset(t,1);if(n==null)return-1;if(i=n,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)r=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,a=this.range;for(;a.to<=i;)a=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>a.to&&(this.chunk2=this.chunk2.slice(0,a.to-i)),r=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),r}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=i}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=nv,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let r of this.ranges){if(r.from>=e)break;r.to>t&&(i+=this.input.read(Math.max(r.from,t),Math.min(r.to,e)))}return i}},_i=class{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;ov(this.data,t,e,this.id,i.data,i.tokenPrecTable)}};_i.prototype.contextual=_i.prototype.fallback=_i.prototype.extend=!1;Oi=class{constructor(t,e,i){this.precTable=e,this.elseToken=i,this.data=typeof t=="string"?_a(t):t}token(t,e){let i=t.pos,r=0;for(;;){let n=t.next<0,o=t.resolveOffset(1,1);if(ov(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(n||r++,o==null)break;t.reset(o,t.token)}r&&(t.reset(i,t.token),t.acceptToken(this.elseToken,r))}};Oi.prototype.contextual=_i.prototype.fallback=_i.prototype.extend=!1;mt=class{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}};we=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Pf=null;Qf=class{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?lv(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?lv(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let i=this.trees[e],r=this.index[e];if(r==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=i.children[r],o=this.start[e]+i.positions[r];if(o>t)return this.nextStart=o,null;if(n instanceof G){if(o==t){if(o<this.safeFrom)return null;let a=o+n.length;if(a<=this.safeTo){let l=n.prop(_.lookAhead);if(!l||a+l<this.fragment.to)return n}}this.index[e]++,o+n.length>=Math.max(this.safeFrom,t)&&(this.trees.push(n),this.start.push(o),this.index.push(0))}else this.index[e]++,this.nextStart=o+n.length}}},Tf=class{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(i=>new Mn)}getActions(t){let e=0,i=null,{parser:r}=t.p,{tokenizers:n}=r,o=r.stateSlot(t.state,3),a=t.curContext?t.curContext.hash:0,l=0;for(let h=0;h<n.length;h++){if((1<<h&o)==0)continue;let c=n[h],u=this.tokens[h];if(!(i&&!c.fallback)&&((c.contextual||u.start!=t.pos||u.mask!=o||u.context!=a)&&(this.updateCachedToken(u,c,t),u.mask=o,u.context=a),u.lookAhead>u.end+25&&(l=Math.max(u.lookAhead,l)),u.value!=0)){let d=e;if(u.extended>-1&&(e=this.addActions(t,u.extended,u.end,e)),e=this.addActions(t,u.value,u.end,e),!c.extend&&(i=u,e>d))break}}for(;this.actions.length>e;)this.actions.pop();return l&&t.setLookAhead(l),!i&&t.pos==this.stream.end&&(i=new Mn,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new Mn,{pos:i,p:r}=t;return e.start=i,e.end=Math.min(i+1,r.stream.end),e.value=i==r.stream.end?r.parser.eofTerm:0,e}updateCachedToken(t,e,i){let r=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(r,t),i),t.value>-1){let{parser:n}=i.p;for(let o=0;o<n.specialized.length;o++)if(n.specialized[o]==t.value){let a=n.specializers[o](this.stream.read(t.start,t.end),i);if(a>=0&&i.p.parser.dialect.allows(a>>1)){(a&1)==0?t.value=a>>1:t.extended=a>>1;break}}}else t.value=0,t.end=this.stream.clipPos(r+1)}putAction(t,e,i,r){for(let n=0;n<r;n+=3)if(this.actions[n]==t)return r;return this.actions[r++]=t,this.actions[r++]=e,this.actions[r++]=i,r}addActions(t,e,i,r){let{state:n}=t,{parser:o}=t.p,{data:a}=o;for(let l=0;l<2;l++)for(let h=o.stateSlot(n,l?2:1);;h+=3){if(a[h]==65535)if(a[h+1]==1)h=bi(a,h+2);else{r==0&&a[h+1]==2&&(r=this.putAction(bi(a,h+2),e,i,r));break}a[h]==e&&(r=this.putAction(bi(a,h+1),e,i,r))}return r}},Lf=class{constructor(t,e,i,r){this.parser=t,this.input=e,this.ranges=r,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new Yh(e,r),this.tokens=new Tf(t,this.stream),this.topTerm=t.top[1];let{from:n}=r[0];this.stacks=[Fh.start(this,t.top[0],n)],this.fragments=i.length&&this.stream.end-n>t.bufferLength*4?new Qf(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,i=this.stacks=[],r,n;if(this.bigReductionCount>300&&t.length==1){let[o]=t;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<t.length;o++){let a=t[o];for(;;){if(this.tokens.mainToken=null,a.pos>e)i.push(a);else{if(this.advanceStack(a,i,t))continue;{r||(r=[],n=[]),r.push(a);let l=this.tokens.getMainToken(a);n.push(l.value,l.end)}}break}}if(!i.length){let o=r&&j$(r);if(o)return we&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw we&&r&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&r){let o=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,n,i);if(o)return we&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((a,l)=>l.score-a.score);i.length>o;)i.pop();i.some(a=>a.reducePos>e)&&this.recovering--}else if(i.length>1){t:for(let o=0;o<i.length-1;o++){let a=i[o];for(let l=o+1;l<i.length;l++){let h=i[l];if(a.sameState(h)||a.buffer.length>500&&h.buffer.length>500)if((a.score-h.score||a.buffer.length-h.buffer.length)>0)i.splice(l--,1);else{i.splice(o--,1);continue t}}}i.length>12&&(i.sort((o,a)=>a.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,i){let r=t.pos,{parser:n}=this,o=we?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&r>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let h=t.curContext&&t.curContext.tracker.strict,c=h?t.curContext.hash:0;for(let u=this.fragments.nodeAt(r);u;){let d=this.parser.nodeSet.types[u.type.id]==u.type?n.getGoto(t.state,u.type.id):-1;if(d>-1&&u.length&&(!h||(u.prop(_.contextHash)||0)==c))return t.useNode(u,d),we&&console.log(o+this.stackID(t)+` (via reuse of ${n.getName(u.type.id)})`),!0;if(!(u instanceof G)||u.children.length==0||u.positions[0]>0)break;let f=u.children[0];if(f instanceof G&&u.positions[0]==0)u=f;else break}}let a=n.stateSlot(t.state,4);if(a>0)return t.reduce(a),we&&console.log(o+this.stackID(t)+` (via always-reduce ${n.getName(a&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let l=this.tokens.getActions(t);for(let h=0;h<l.length;){let c=l[h++],u=l[h++],d=l[h++],f=h==l.length||!i,p=f?t:t.split(),m=this.tokens.mainToken;if(p.apply(c,u,m?m.start:p.pos,d),we&&console.log(o+this.stackID(p)+` (via ${(c&65536)==0?"shift":`reduce of ${n.getName(c&65535)}`} for ${n.getName(u)} @ ${r}${p==t?"":", split"})`),f)return!0;p.pos>r?e.push(p):i.push(p)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return hv(t,e),!0}}runRecovery(t,e,i){let r=null,n=!1;for(let o=0;o<t.length;o++){let a=t[o],l=e[o<<1],h=e[(o<<1)+1],c=we?this.stackID(a)+" -> ":"";if(a.deadEnd&&(n||(n=!0,a.restart(),we&&console.log(c+this.stackID(a)+" (restarted)"),this.advanceFully(a,i))))continue;let u=a.split(),d=c;for(let f=0;f<10&&u.forceReduce()&&(we&&console.log(d+this.stackID(u)+" (via force-reduce)"),!this.advanceFully(u,i));f++)we&&(d=this.stackID(u)+" -> ");for(let f of a.recoverByInsert(l))we&&console.log(c+this.stackID(f)+" (via recover-insert)"),this.advanceFully(f,i);this.stream.end>a.pos?(h==a.pos&&(h++,l=0),a.recoverByDelete(l,h),we&&console.log(c+this.stackID(a)+` (via recover-delete ${this.parser.getName(l)})`),hv(a,i)):(!r||r.score<u.score)&&(r=u)}return r}stackToTree(t){return t.close(),G.build({buffer:$f.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(Pf||(Pf=new WeakMap)).get(t);return e||Pf.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}};Mf=class{constructor(t,e,i){this.source=t,this.flags=e,this.disabled=i}allows(t){return!this.disabled||this.disabled[t]==0}},Rf=s=>s,yi=class{constructor(t){this.start=t.start,this.shift=t.shift||Rf,this.reduce=t.reduce||Rf,this.reuse=t.reuse||Rf,this.hash=t.hash||(()=>0),this.strict=t.strict!==!1}},Kt=class s extends Ke{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let a=0;a<t.repeatNodeCount;a++)e.push("");let i=Object.keys(t.topRules).map(a=>t.topRules[a][1]),r=[];for(let a=0;a<e.length;a++)r.push([]);function n(a,l,h){r[a].push([l,l.deserialize(String(h))])}if(t.nodeProps)for(let a of t.nodeProps){let l=a[0];typeof l=="string"&&(l=_[l]);for(let h=1;h<a.length;){let c=a[h++];if(c>=0)n(c,l,a[h++]);else{let u=a[h+-c];for(let d=-c;d>0;d--)n(a[h++],l,u);h++}}}this.nodeSet=new Ge(e.map((a,l)=>pt.define({name:l>=this.minRepeatTerm?void 0:a,id:l,props:r[l],top:i.indexOf(l)>-1,error:l==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(l)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=1024;let o=_a(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let a=0;a<this.specializerSpecs.length;a++)this.specialized[a]=this.specializerSpecs[a].term;this.specializers=this.specializerSpecs.map(cv),this.states=_a(t.states,Uint32Array),this.data=_a(t.stateData),this.goto=_a(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(a=>typeof a=="number"?new _i(o,a):a),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let r=new Lf(this,t,e,i);for(let n of this.wrappers)r=n(r,t,e,i);return r}getGoto(t,e,i=!1){let r=this.goto;if(e>=r[0])return-1;for(let n=r[e+1];;){let o=r[n++],a=o&1,l=r[n++];if(a&&i)return l;for(let h=n+(o>>1);n<h;n++)if(r[n]==t)return l;if(a)return-1}}hasAction(t,e){let i=this.data;for(let r=0;r<2;r++)for(let n=this.stateSlot(t,r?2:1),o;;n+=3){if((o=i[n])==65535)if(i[n+1]==1)o=i[n=bi(i,n+2)];else{if(i[n+1]==2)return bi(i,n+2);break}if(o==e||o==0)return bi(i,n+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),r=i?e(i):void 0;for(let n=this.stateSlot(t,1);r==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=bi(this.data,n+2);else break;r=e(bi(this.data,n+1))}return r}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=bi(this.data,i+2);else break;if((this.data[i+2]&1)==0){let r=this.data[i+1];e.some((n,o)=>o&1&&n==r)||e.push(this.data[i],r)}}return e}configure(t){let e=Object.assign(Object.create(s.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let r=t.tokenizers.find(n=>n.from==i);return r?r.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,r)=>{let n=t.specializers.find(a=>a.from==i.external);if(!n)return i;let o=Object.assign(Object.assign({},i),{external:n.to});return e.specializers[r]=cv(o),o})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let n of t.split(" ")){let o=e.indexOf(n);o>=0&&(i[o]=!0)}let r=null;for(let n=0;n<e.length;n++)if(!i[n])for(let o=this.dialects[e[n]],a;(a=this.data[o++])!=65535;)(r||(r=new Uint8Array(this.maxTerm+1)))[a]=1;return new Mf(t,i,r)}static deserialize(t){return new s(t)}}});function U$(s,t){return s.length==t.length&&s.every((e,i)=>e==t[i])}function Y$(s){let t=[[]];for(let e=0;e<s.length;e++)for(let i=0,r=t.length;i<r;i++)t.push(t[i].concat(s[e]));return t.sort((e,i)=>i.length-e.length)}function It(s){let t=Object.create(null);for(let e in s){let i=s[e];Array.isArray(i)||(i=[i]);for(let r of e.split(" "))if(r){let n=[],o=2,a=r;for(let u=0;;){if(a=="..."&&u>0&&u+3==r.length){o=1;break}let d=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!d)throw new RangeError("Invalid path: "+r);if(n.push(d[0]=="*"?"":d[0][0]=='"'?JSON.parse(d[0]):d[0]),u+=d[0].length,u==r.length)break;let f=r[u++];if(u==r.length&&f=="!"){o=0;break}if(f!="/")throw new RangeError("Invalid path: "+r);a=r.slice(u)}let l=n.length-1,h=n[l];if(!h)throw new RangeError("Invalid path: "+r);let c=new vs(i,o,l>0?n.slice(0,l):null);t[h]=c.sort(t[h])}}return uv.add(t)}function tc(s,t){let e=Object.create(null);for(let n of s)if(!Array.isArray(n.tag))e[n.tag.id]=n.class;else for(let o of n.tag)e[o.id]=n.class;let{scope:i,all:r=null}=t||{};return{style:n=>{let o=r;for(let a of n)for(let l of a.set){let h=e[l.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function H$(s,t){let e=null;for(let i of s){let r=i.style(t);r&&(e=e?e+" "+r:r)}return e}function ec(s,t,e,i=0,r=s.length){let n=new If(i,Array.isArray(t)?t:[t],e);n.highlightRange(s.cursor(),i,r,"",n.highlighters),n.flush(r)}function G$(s,t,e,i,r,n=0,o=s.length){let a=n;function l(h,c){if(!(h<=a)){for(let u=s.slice(a,h),d=0;;){let f=u.indexOf(`
11
+ `,d),p=f<0?u.length:f;if(p>d&&i(u.slice(d,p),c),f<0)break;r(),d=f+1}a=h}}ec(t,e,(h,c,u)=>{l(h,""),l(c,u)},n,o),l(o,"")}function dv(s){let t=s.type.prop(uv);for(;t&&t.context&&!s.matchContext(t.context);)t=t.next;return t||null}var W$,de,F$,Hh,uv,vs,If,N,Gh,Vi,fv,pv,ji,Kh,Df,Je,xs,ti,ei,qf,Va,Jh,O,K$,ii=W(()=>{_e();W$=0,de=class s{constructor(t,e,i,r){this.name=t,this.set=e,this.base=i,this.modified=r,this.id=W$++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i=typeof t=="string"?t:"?";if(t instanceof s&&(e=t),e?.base)throw new Error("Can not derive from a modified tag");let r=new s(i,[],null,[]);if(r.set.push(r),e)for(let n of e.set)r.set.push(n);return r}static defineModifier(t){let e=new Hh(t);return i=>i.modified.indexOf(e)>-1?i:Hh.get(i.base||i,i.modified.concat(e).sort((r,n)=>r.id-n.id))}},F$=0,Hh=class s{constructor(t){this.name=t,this.instances=[],this.id=F$++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(a=>a.base==t&&U$(e,a.modified));if(i)return i;let r=[],n=new de(t.name,r,t,e);for(let a of e)a.instances.push(n);let o=Y$(e);for(let a of t.set)if(!a.modified.length)for(let l of o)r.push(s.get(a,l));return n}};uv=new _({combine(s,t){let e,i,r;for(;s||t;){if(!s||t&&s.depth>=t.depth?(r=t,t=t.next):(r=s,s=s.next),e&&e.mode==r.mode&&!r.context&&!e.context)continue;let n=new vs(r.tags,r.mode,r.context);e?e.next=n:i=n,e=n}return i}}),vs=class{constructor(t,e,i,r){this.tags=t,this.mode=e,this.context=i,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}};vs.empty=new vs([],2,null);If=class{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,r,n){let{type:o,from:a,to:l}=t;if(a>=i||l<=e)return;o.isTop&&(n=this.highlighters.filter(f=>!f.scope||f.scope(o)));let h=r,c=dv(t)||vs.empty,u=H$(n,c.tags);if(u&&(h&&(h+=" "),h+=u,c.mode==1&&(r+=(r?" ":"")+u)),this.startSpan(Math.max(e,a),h),c.opaque)return;let d=t.tree&&t.tree.prop(_.mounted);if(d&&d.overlay){let f=t.node.enter(d.overlay[0].from+a,1),p=this.highlighters.filter(b=>!b.scope||b.scope(d.tree.type)),m=t.firstChild();for(let b=0,g=a;;b++){let x=b<d.overlay.length?d.overlay[b]:null,S=x?x.from+a:l,w=Math.max(e,g),k=Math.min(i,S);if(w<k&&m)for(;t.from<k&&(this.highlightRange(t,w,k,r,n),this.startSpan(Math.min(k,t.to),h),!(t.to>=S||!t.nextSibling())););if(!x||S>i)break;g=x.to+a,g>e&&(this.highlightRange(f.cursor(),Math.max(e,x.from+a),Math.min(i,g),"",p),this.startSpan(Math.min(i,g),h))}m&&t.parent()}else if(t.firstChild()){d&&(r="");do if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,r,n),this.startSpan(Math.min(i,t.to),h)}while(t.nextSibling());t.parent()}}};N=de.define,Gh=N(),Vi=N(),fv=N(Vi),pv=N(Vi),ji=N(),Kh=N(ji),Df=N(ji),Je=N(),xs=N(Je),ti=N(),ei=N(),qf=N(),Va=N(qf),Jh=N(),O={comment:Gh,lineComment:N(Gh),blockComment:N(Gh),docComment:N(Gh),name:Vi,variableName:N(Vi),typeName:fv,tagName:N(fv),propertyName:pv,attributeName:N(pv),className:N(Vi),labelName:N(Vi),namespace:N(Vi),macroName:N(Vi),literal:ji,string:Kh,docString:N(Kh),character:N(Kh),attributeValue:N(Kh),number:Df,integer:N(Df),float:N(Df),bool:N(ji),regexp:N(ji),escape:N(ji),color:N(ji),url:N(ji),keyword:ti,self:N(ti),null:N(ti),atom:N(ti),unit:N(ti),modifier:N(ti),operatorKeyword:N(ti),controlKeyword:N(ti),definitionKeyword:N(ti),moduleKeyword:N(ti),operator:ei,derefOperator:N(ei),arithmeticOperator:N(ei),logicOperator:N(ei),bitwiseOperator:N(ei),compareOperator:N(ei),updateOperator:N(ei),definitionOperator:N(ei),typeOperator:N(ei),controlOperator:N(ei),punctuation:qf,separator:N(qf),bracket:Va,angleBracket:N(Va),squareBracket:N(Va),paren:N(Va),brace:N(Va),content:Je,heading:xs,heading1:N(xs),heading2:N(xs),heading3:N(xs),heading4:N(xs),heading5:N(xs),heading6:N(xs),contentSeparator:N(Je),list:N(Je),quote:N(Je),emphasis:N(Je),strong:N(Je),link:N(Je),monospace:N(Je),strikethrough:N(Je),inserted:N(),deleted:N(),changed:N(),invalid:N(),meta:Jh,documentMeta:N(Jh),annotation:N(Jh),processingInstruction:N(Jh),definition:de.defineModifier("definition"),constant:de.defineModifier("constant"),function:de.defineModifier("function"),standard:de.defineModifier("standard"),local:de.defineModifier("local"),special:de.defineModifier("special")};for(let s in O){let t=O[s];t instanceof de&&(t.name=s)}K$=tc([{tag:O.link,class:"tok-link"},{tag:O.heading,class:"tok-heading"},{tag:O.emphasis,class:"tok-emphasis"},{tag:O.strong,class:"tok-strong"},{tag:O.keyword,class:"tok-keyword"},{tag:O.atom,class:"tok-atom"},{tag:O.bool,class:"tok-bool"},{tag:O.url,class:"tok-url"},{tag:O.labelName,class:"tok-labelName"},{tag:O.inserted,class:"tok-inserted"},{tag:O.deleted,class:"tok-deleted"},{tag:O.literal,class:"tok-literal"},{tag:O.string,class:"tok-string"},{tag:O.number,class:"tok-number"},{tag:[O.regexp,O.escape,O.special(O.string)],class:"tok-string2"},{tag:O.variableName,class:"tok-variableName"},{tag:O.local(O.variableName),class:"tok-variableName tok-local"},{tag:O.definition(O.variableName),class:"tok-variableName tok-definition"},{tag:O.special(O.variableName),class:"tok-variableName2"},{tag:O.definition(O.propertyName),class:"tok-propertyName tok-definition"},{tag:O.typeName,class:"tok-typeName"},{tag:O.namespace,class:"tok-namespace"},{tag:O.className,class:"tok-className"},{tag:O.macroName,class:"tok-macroName"},{tag:O.propertyName,class:"tok-propertyName"},{tag:O.operator,class:"tok-operator"},{tag:O.comment,class:"tok-comment"},{tag:O.meta,class:"tok-meta"},{tag:O.invalid,class:"tok-invalid"},{tag:O.punctuation,class:"tok-punctuation"}])});var J$,Nf,mv=W(()=>{ys();ii();J$=It({String:O.string,Number:O.number,"True False":O.bool,PropertyName:O.propertyName,Null:O.null,", :":O.separator,"[ ]":O.squareBracket,"{ }":O.brace}),Nf=Kt.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:"#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O",goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:"\u26A0 JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array",maxTerm:25,nodeProps:[["isolate",-2,6,11,""],["openedBy",7,"{",14,"["],["closedBy",8,"}",15,"]"]],propSources:[J$],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0})});function tP(s){if(s<768)return!1;for(let t=0,e=ja.length;;){let i=t+e>>1;if(s<ja[i])e=i;else if(s>=Xf[i])t=i+1;else return!0;if(t==e)return!1}}function gv(s){return s>=127462&&s<=127487}function R_(s){for(let t=0;t<ja.length;t++)if(Xf[t]>s)return ja[t]<=s;return!1}function Sv(s,t,e=!0,i=!0){return(e?Ov:eP)(s,t,i)}function Ov(s,t,e){if(t==s.length)return t;t&&yv(s.charCodeAt(t))&&vv(s.charCodeAt(t-1))&&t--;let i=Bf(s,t);for(t+=xv(i);t<s.length;){let r=Bf(s,t);if(i==bv||r==bv||e&&tP(r))t+=xv(r),i=r;else if(gv(r)){let n=0,o=t-2;for(;o>=0&&gv(Bf(s,o));)n++,o-=2;if(n%2==0)break;t+=2}else break}return t}function eP(s,t,e){for(;t>0;){let i=Ov(s,t-2,e);if(i<t)return i;t--}return 0}function Bf(s,t){let e=s.charCodeAt(t);if(!vv(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return yv(i)?(e-55296<<10)+(i-56320)+65536:e}function yv(s){return s>=56320&&s<57344}function vv(s){return s>=55296&&s<56320}function xv(s){return s<65536?1:2}var ja,Xf,bv,wv=W(()=>{ja=[],Xf=[];(()=>{let s="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let t=0,e=0;t<s.length;t++)(t%2?Xf:ja).push(e=e+s[t])})();bv=8205});function iP(s){let t=-1;for(let e of s)t+=e.length+1;return t}function ic(s,t,e=0,i=1e9){for(let r=0,n=0,o=!0;n<s.length&&r<=i;n++){let a=s[n],l=r+a.length;l>=e&&(l>i&&(a=a.slice(0,i-r)),r<e&&(a=a.slice(e-r)),o?(t[t.length-1]+=a,o=!1):t.push(a)),r=l+1}return t}function kv(s,t,e){return ic(s,[""],t,e)}function In(s,t,e){return t=Math.max(0,Math.min(s.length,t)),[t,Math.max(t,Math.min(s.length,e))]}function Et(s,t,e=!0,i=!0){return Sv(s,t,e,i)}function sP(s){return s>=56320&&s<57344}function rP(s){return s>=55296&&s<56320}function Vt(s,t){let e=s.charCodeAt(t);if(!rP(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return sP(i)?(e-55296<<10)+(i-56320)+65536:e}function mc(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function Qe(s){return s<65536?1:2}function zt(s,t,e,i=!1){if(t==0&&e<=0)return;let r=s.length-2;r>=0&&e<=0&&e==s[r+1]?s[r]+=t:r>=0&&t==0&&s[r]==0?s[r+1]+=e:i?(s[r]+=t,s[r+1]+=e):s.push(t,e)}function Wi(s,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(e);else{for(;s.length<i;)s.push(et.empty);s.push(e)}}function zf(s,t,e){let i=s.inserted;for(let r=0,n=0,o=0;o<s.sections.length;){let a=s.sections[o++],l=s.sections[o++];if(l<0)r+=a,n+=a;else{let h=r,c=n,u=et.empty;for(;h+=a,c+=l,l&&i&&(u=u.append(i[o-2>>1])),!(e||o==s.sections.length||s.sections[o+1]<0);)a=s.sections[o++],l=s.sections[o++];t(r,h,n,c,u),r=h,n=c}}}function _f(s,t,e,i=!1){let r=[],n=i?[]:null,o=new ws(s),a=new ws(t);for(let l=-1;;){if(o.done&&a.len||a.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&a.ins==-1){let h=Math.min(o.len,a.len);zt(r,h,-1),o.forward(h),a.forward(h)}else if(a.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(a.len<o.len||a.len==o.len&&!e))){let h=a.len;for(zt(r,a.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&l<o.i&&o.len<=c&&(zt(r,0,o.ins),n&&Wi(n,r,o.text),l=o.i),o.forward(c),h-=c}a.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(a.ins==-1){let u=Math.min(c,a.len);h+=u,c-=u,a.forward(u)}else if(a.ins==0&&a.len<c)c-=a.len,a.next();else break;zt(r,h,l<o.i?o.ins:0),n&&l<o.i&&Wi(n,r,o.text),l=o.i,o.forward(o.len-c)}else{if(o.done&&a.done)return n?_t.createSet(r,n):si.create(r);throw new Error("Mismatched change set lengths")}}}function Av(s,t,e=!1){let i=[],r=e?[]:null,n=new ws(s),o=new ws(t);for(let a=!1;;){if(n.done&&o.done)return r?_t.createSet(i,r):si.create(i);if(n.ins==0)zt(i,n.len,0,a),n.next();else if(o.len==0&&!o.done)zt(i,0,o.ins,a),r&&Wi(r,i,o.text),o.next();else{if(n.done||o.done)throw new Error("Mismatched change set lengths");{let l=Math.min(n.len2,o.len),h=i.length;if(n.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;zt(i,l,c,a),r&&c&&Wi(r,i,o.text)}else o.ins==-1?(zt(i,n.off?0:n.len,l,a),r&&Wi(r,i,n.textBit(l))):(zt(i,n.off?0:n.len,o.off?0:o.ins,a),r&&!o.off&&Wi(r,i,o.text));a=(n.ins>l||o.ins>=0&&o.len>l)&&(a||i.length>h),n.forward2(l),o.forward(l)}}}}function Ev(s,t){for(let e of s.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}function jf(s,t){return s==t||s.length==t.length&&s.every((e,i)=>e===t[i])}function Cv(s,t,e){if(s.length!=t.length)return!1;for(let i=0;i<s.length;i++)if(!e(s[i],t[i]))return!1;return!0}function Wf(s,t){let e=!1;for(let i of t)Ua(s,i)&1&&(e=!0);return e}function nP(s,t,e){let i=e.map(l=>s[l.id]),r=e.map(l=>l.type),n=i.filter(l=>!(l&1)),o=s[t.id]>>1;function a(l){let h=[];for(let c=0;c<i.length;c++){let u=hc(l,i[c]);if(r[c]==2)for(let d of u)h.push(d);else h.push(u)}return t.combine(h)}return{create(l){for(let h of i)Ua(l,h);return l.values[o]=a(l),1},update(l,h){if(!Wf(l,n))return 0;let c=a(l);return t.compare(c,l.values[o])?0:(l.values[o]=c,1)},reconfigure(l,h){let c=Wf(l,i),u=h.config.facets[t.id],d=h.facet(t);if(u&&!c&&jf(e,u))return l.values[o]=d,0;let f=a(l);return t.compare(f,d)?(l.values[o]=d,0):(l.values[o]=f,1)}}}function Wa(s){return t=>new ac(t,s)}function oP(s,t,e){let i=[[],[],[],[],[]],r=new Map;function n(o,a){let l=r.get(o);if(l!=null){if(l<=a)return;let h=i[l].indexOf(o);h>-1&&i[l].splice(h,1),o instanceof Fa&&e.delete(o.compartment)}if(r.set(o,a),Array.isArray(o))for(let h of o)n(h,a);else if(o instanceof Fa){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=t.get(o.compartment)||o.inner;e.set(o.compartment,h),n(h,a)}else if(o instanceof ac)n(o.inner,o.prec);else if(o instanceof bt)i[a].push(o),o.provides&&n(o.provides,a);else if(o instanceof Dn)i[a].push(o),o.facet.extensions&&n(o.facet.extensions,As.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(h,a)}}return n(s,As.default),i.reduce((o,a)=>o.concat(a))}function Ua(s,t){if(t&1)return 2;let e=t>>1,i=s.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[e]=4;let r=s.computeSlot(s,s.config.dynamicSlots[e]);return s.status[e]=2|r}function hc(s,t){return t&1?s.config.staticValues[t>>1]:s.values[t>>1]}function aP(s,t){let e=[];for(let i=0,r=0;;){let n,o;if(i<s.length&&(r==t.length||t[r]>=s[i]))n=s[i++],o=s[i++];else if(r<t.length)n=t[r++],o=t[r++];else return e;!e.length||e[e.length-1]<n?e.push(n,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function Rv(s,t,e){var i;let r,n,o;return e?(r=t.changes,n=_t.empty(t.changes.length),o=s.changes.compose(t.changes)):(r=t.changes.map(s.changes),n=s.changes.mapDesc(t.changes,!0),o=s.changes.compose(r)),{changes:o,selection:t.selection?t.selection.map(n):(i=s.selection)===null||i===void 0?void 0:i.map(r),effects:F.mapEffects(s.effects,r).concat(F.mapEffects(t.effects,n)),annotations:s.annotations.length?s.annotations.concat(t.annotations):t.annotations,scrollIntoView:s.scrollIntoView||t.scrollIntoView}}function Uf(s,t,e){let i=t.selection,r=qn(t.annotations);return t.userEvent&&(r=r.concat(xt.userEvent.of(t.userEvent))),{changes:t.changes instanceof _t?t.changes:_t.of(t.changes||[],e,s.facet(Pv)),selection:i&&(i instanceof Q?i:Q.single(i.anchor,i.head)),effects:qn(t.effects),annotations:r,scrollIntoView:!!t.scrollIntoView}}function Iv(s,t,e){let i=Uf(s,t.length?t[0]:{},s.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let n=1;n<t.length;n++){t[n].filter===!1&&(e=!1);let o=!!t[n].sequential;i=Rv(i,Uf(s,t[n],o?i.changes.newLength:s.doc.length),o)}let r=xt.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return hP(e?lP(r):r)}function lP(s){let t=s.startState,e=!0;for(let r of t.facet(Qv)){let n=r(s);if(n===!1){e=!1;break}Array.isArray(n)&&(e=e===!0?n:aP(e,n))}if(e!==!0){let r,n;if(e===!1)n=s.changes.invertedDesc,r=_t.empty(t.doc.length);else{let o=s.changes.filter(e);r=o.changes,n=o.filtered.mapDesc(o.changes).invertedDesc}s=xt.create(t,r,s.selection&&s.selection.map(n),F.mapEffects(s.effects,n),s.annotations,s.scrollIntoView)}let i=t.facet(Tv);for(let r=i.length-1;r>=0;r--){let n=i[r](s);n instanceof xt?s=n:Array.isArray(n)&&n.length==1&&n[0]instanceof xt?s=n[0]:s=Iv(t,qn(n),!1)}return s}function hP(s){let t=s.startState,e=t.facet(Lv),i=s;for(let r=e.length-1;r>=0;r--){let n=e[r](s);n&&Object.keys(n).length&&(i=Rv(i,Uf(t,n,s.changes.newLength),!0))}return i==s?s:xt.create(t,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}function qn(s){return s==null?cP:Array.isArray(s)?s:[s]}function dP(s){if(Yf)return Yf.test(s);for(let t=0;t<s.length;t++){let e=s[t];if(/\w/.test(e)||e>"\x80"&&(e.toUpperCase()!=e.toLowerCase()||uP.test(e)))return!0}return!1}function fP(s){return t=>{if(!/\S/.test(t))return gt.Space;if(dP(t))return gt.Word;for(let e=0;e<s.length;e++)if(t.indexOf(s[e])>-1)return gt.Word;return gt.Other}}function te(s,t,e={}){let i={};for(let r of s)for(let n of Object.keys(r)){let o=r[n],a=i[n];if(a===void 0)i[n]=o;else if(!(a===o||o===void 0))if(Object.hasOwnProperty.call(e,n))i[n]=e[n](a,o);else throw new Error("Config merge conflict for field "+n)}for(let r in t)i[r]===void 0&&(i[r]=t[r]);return i}function Hf(s,t){return s==t||s.constructor==t.constructor&&s.eq(t)}function Gf(s,t){return s.from-t.from||s.value.startSide-t.value.startSide}function pP(s){if(s.length>1)for(let t=s[0],e=1;e<s.length;e++){let i=s[e];if(Gf(t,i)>0)return s.slice().sort(Gf);t=i}return s}function Dv(s,t,e){let i=new Map;for(let n of s)for(let o=0;o<n.chunk.length;o++)n.chunk[o].maxPoint<=0&&i.set(n.chunk[o],n.chunkPos[o]);let r=new Set;for(let n of t)for(let o=0;o<n.chunk.length;o++){let a=i.get(n.chunk[o]);a!=null&&(e?e.mapPos(a):a)==n.chunkPos[o]&&!e?.touchesRange(a,a+n.chunk[o].length)&&r.add(n.chunk[o])}return r}function Jf(s,t){for(let e=s[t];;){let i=(t<<1)+1;if(i>=s.length)break;let r=s[i];if(i+1<s.length&&r.compare(s[i+1])>=0&&(r=s[i+1],i++),e.compare(r)<0)break;s[i]=e,s[t]=r,t=i}}function qv(s,t,e,i,r,n){s.goto(t),e.goto(i);let o=i+r,a=i,l=i-t,h=!!n.boundChange;for(let c=!1;;){let u=s.to+l-e.to,d=u||s.endSide-e.endSide,f=d<0?s.to+l:e.to,p=Math.min(f,o);if(s.point||e.point?(s.point&&e.point&&Hf(s.point,e.point)&&tp(s.activeForPoint(s.to),e.activeForPoint(e.to))||n.comparePoint(a,p,s.point,e.point),c=!1):(c&&n.boundChange(a),p>a&&!tp(s.active,e.active)&&n.compareRange(a,p,s.active,e.active),h&&p<o&&(u||s.openEnd(f)!=e.openEnd(f))&&(c=!0)),f>o)break;a=f,d<=0&&s.next(),d>=0&&e.next()}}function tp(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++)if(s[e]!=t[e]&&!Hf(s[e],t[e]))return!1;return!0}function fc(s,t){for(let e=t,i=s.length-1;e<i;e++)s[e]=s[e+1];s.pop()}function pc(s,t,e){for(let i=s.length-1;i>=t;i--)s[i+1]=s[i];s[t]=e}function Nv(s,t){let e=-1,i=1e9;for(let r=0;r<t.length;r++)(t[r]-i||s[r].endSide-s[e].endSide)<0&&(e=r,i=t[r]);return e}function jt(s,t,e=s.length){let i=0;for(let r=0;r<e&&r<s.length;)s.charCodeAt(r)==9?(i+=t-i%t,r++):(i++,r=Et(s,r));return i}function Ha(s,t,e,i){for(let r=0,n=0;;){if(n>=t)return r;if(r==s.length)break;n+=s.charCodeAt(r)==9?e-n%e:1,r=Et(s,r)}return i===!0?-1:s.length}var et,ke,Rn,Ss,sc,rc,nc,Zf,At,si,_t,ws,ks,Q,Vf,X,Dn,oc,bt,As,fe,ac,Fi,Fa,lc,$v,Ff,Pv,Qv,Tv,Lv,Mv,Jt,cc,uc,F,xt,cP,gt,uP,Yf,at,Ae,Nn,Kf,K,Ee,dc,Ya,Es,ri=W(()=>{wv();et=class s{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=In(this,t,e);let r=[];return this.decompose(0,t,r,2),i.length&&i.decompose(0,i.length,r,3),this.decompose(e,this.length,r,1),Rn.from(r,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=In(this,t,e);let i=[];return this.decompose(t,e,i,0),Rn.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),r=new Ss(this),n=new Ss(t);for(let o=e,a=e;;){if(r.next(o),n.next(o),o=0,r.lineBreak!=n.lineBreak||r.done!=n.done||r.value!=n.value)return!1;if(a+=r.value.length,r.done||a>=i)return!0}}iter(t=1){return new Ss(this,t)}iterRange(t,e=this.length){return new sc(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let r=this.line(t).from;i=this.iterRange(r,Math.max(r,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new rc(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?s.empty:t.length<=32?new ke(t):Rn.from(ke.split(t,[]))}},ke=class s extends et{constructor(t,e=iP(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,r){for(let n=0;;n++){let o=this.text[n],a=r+o.length;if((e?i:a)>=t)return new nc(r,a,i,o);r=a+1,i++}}decompose(t,e,i,r){let n=t<=0&&e>=this.length?this:new s(kv(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(r&1){let o=i.pop(),a=ic(n.text,o.text.slice(),0,n.length);if(a.length<=32)i.push(new s(a,o.length+n.length));else{let l=a.length>>1;i.push(new s(a.slice(0,l)),new s(a.slice(l)))}}else i.push(n)}replace(t,e,i){if(!(i instanceof s))return super.replace(t,e,i);[t,e]=In(this,t,e);let r=ic(this.text,ic(i.text,kv(this.text,0,t)),e),n=this.length+i.length-(e-t);return r.length<=32?new s(r,n):Rn.from(s.split(r,[]),n)}sliceString(t,e=this.length,i=`
12
12
  `){[t,e]=In(this,t,e);let r="";for(let n=0,o=0;n<=e&&o<this.text.length;o++){let a=this.text[o],l=n+a.length;n>t&&o&&(r+=i),t<l&&e>n&&(r+=a.slice(Math.max(0,t-n),e-n)),n=l+1}return r}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],r=-1;for(let n of t)i.push(n),r+=n.length+1,i.length==32&&(e.push(new s(i,r)),i=[],r=-1);return r>-1&&e.push(new s(i,r)),e}},Rn=class s extends et{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let i of t)this.lines+=i.lines}lineInner(t,e,i,r){for(let n=0;;n++){let o=this.children[n],a=r+o.length,l=i+o.lines-1;if((e?l:a)>=t)return o.lineInner(t,e,i,r);r=a+1,i=l+1}}decompose(t,e,i,r){for(let n=0,o=0;o<=e&&n<this.children.length;n++){let a=this.children[n],l=o+a.length;if(t<=l&&e>=o){let h=r&((o<=t?1:0)|(l>=e?2:0));o>=t&&l<=e&&!h?i.push(a):a.decompose(t-o,e-o,i,h)}o=l+1}}replace(t,e,i){if([t,e]=In(this,t,e),i.lines<this.lines)for(let r=0,n=0;r<this.children.length;r++){let o=this.children[r],a=n+o.length;if(t>=n&&e<=a){let l=o.replace(t-n,e-n,i),h=this.lines-o.lines+l.lines;if(l.lines<h>>4&&l.lines>h>>6){let c=this.children.slice();return c[r]=l,new s(c,this.length-(e-t)+i.length)}return super.replace(n,a,l)}n=a+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i=`
13
13
  `){[t,e]=In(this,t,e);let r="";for(let n=0,o=0;n<this.children.length&&o<=e;n++){let a=this.children[n],l=o+a.length;o>t&&n&&(r+=i),t<l&&e>o&&(r+=a.sliceString(t-o,e-o,i)),o=l+1}return r}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof s))return 0;let i=0,[r,n,o,a]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;r+=e,n+=e){if(r==o||n==a)return i;let l=this.children[r],h=t.children[n];if(l!=h)return i+l.scanIdentical(h,e);i+=l.length+1}}static from(t,e=t.reduce((i,r)=>i+r.length+1,-1)){let i=0;for(let f of t)i+=f.lines;if(i<32){let f=[];for(let p of t)p.flatten(f);return new ke(f,e)}let r=Math.max(32,i>>5),n=r<<1,o=r>>1,a=[],l=0,h=-1,c=[];function u(f){let p;if(f.lines>n&&f instanceof s)for(let m of f.children)u(m);else f.lines>o&&(l>o||!l)?(d(),a.push(f)):f instanceof ke&&l&&(p=c[c.length-1])instanceof ke&&f.lines+p.lines<=32?(l+=f.lines,h+=f.length+1,c[c.length-1]=new ke(p.text.concat(f.text),p.length+1+f.length)):(l+f.lines>r&&d(),l+=f.lines,h+=f.length+1,c.push(f))}function d(){l!=0&&(a.push(c.length==1?c[0]:s.from(c,h)),h=-1,l=c.length=0)}for(let f of t)u(f);return d(),a.length==1?a[0]:new s(a,e)}};et.empty=new ke([""],0);Ss=class{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof ke?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,r=this.nodes[i],n=this.offsets[i],o=n>>1,a=r instanceof ke?r.text.length:r.children.length;if(o==(e>0?a:0)){if(i==0)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((n&1)==(e>0?0:1)){if(this.offsets[i]+=e,t==0)return this.lineBreak=!0,this.value=`
14
14
  `,this;t--}else if(r instanceof ke){let l=r.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,l.length>Math.max(0,t))return this.value=t==0?l:e>0?l.slice(t):l.slice(0,l.length-t),this;t-=l.length}else{let l=r.children[o+(e<0?-1:0)];t>l.length?(t-=l.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(l),this.offsets.push(e>0?1:(l instanceof ke?l.text.length:l.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}},sc=class{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new Ss(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:r}=this.cursor.next(t);return this.pos+=(r.length+t)*e,this.value=r.length<=i?r:e<0?r.slice(r.length-i):r.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},rc=class{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:r}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(et.prototype[Symbol.iterator]=function(){return this.iter()},Ss.prototype[Symbol.iterator]=sc.prototype[Symbol.iterator]=rc.prototype[Symbol.iterator]=function(){return this});nc=class{constructor(t,e,i,r){this.from=t,this.to=e,this.number=i,this.text=r}get length(){return this.to-this.from}};Zf=/\r\n?|\n/,At=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(At||(At={})),si=class s{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,r=0;e<this.sections.length;){let n=this.sections[e++],o=this.sections[e++];o<0?(t(i,r,n),r+=n):r+=o,i+=n}}iterChangedRanges(t,e=!1){zf(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],r=this.sections[e++];r<0?t.push(i,r):t.push(r,i)}return new s(t)}composeDesc(t){return this.empty?t:t.empty?this:Av(this,t)}mapDesc(t,e=!1){return t.empty?this:_f(this,t,e)}mapPos(t,e=-1,i=At.Simple){let r=0,n=0;for(let o=0;o<this.sections.length;){let a=this.sections[o++],l=this.sections[o++],h=r+a;if(l<0){if(h>t)return n+(t-r);n+=a}else{if(i!=At.Simple&&h>=t&&(i==At.TrackDel&&r<t&&h>t||i==At.TrackBefore&&r<t||i==At.TrackAfter&&h>t))return null;if(h>t||h==t&&e<0&&!a)return t==r||e<0?n:n+l;n+=l}r=h}if(t>r)throw new RangeError(`Position ${t} is out of range for changeset of length ${r}`);return n}touchesRange(t,e=t){for(let i=0,r=0;i<this.sections.length&&r<=e;){let n=this.sections[i++],o=this.sections[i++],a=r+n;if(o>=0&&r<=e&&a>=t)return r<t&&a>e?"cover":!0;r=a}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],r=this.sections[e++];t+=(t?" ":"")+i+(r>=0?":"+r:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new s(t)}static create(t){return new s(t)}},_t=class s extends si{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return zf(this,(e,i,r,n,o)=>t=t.replace(r,r+(i-e),o),!1),t}mapDesc(t,e=!1){return _f(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let r=0,n=0;r<e.length;r+=2){let o=e[r],a=e[r+1];if(a>=0){e[r]=a,e[r+1]=o;let l=r>>1;for(;i.length<l;)i.push(et.empty);i.push(o?t.slice(n,n+o):et.empty)}n+=o}return new s(e,i)}compose(t){return this.empty?t:t.empty?this:Av(this,t,!0)}map(t,e=!1){return t.empty?this:_f(this,t,e,!0)}iterChanges(t,e=!1){zf(this,t,e)}get desc(){return si.create(this.sections)}filter(t){let e=[],i=[],r=[],n=new ws(this);t:for(let o=0,a=0;;){let l=o==t.length?1e9:t[o++];for(;a<l||a==l&&n.len==0;){if(n.done)break t;let c=Math.min(n.len,l-a);zt(r,c,-1);let u=n.ins==-1?-1:n.off==0?n.ins:0;zt(e,c,u),u>0&&Wi(i,e,n.text),n.forward(c),a+=c}let h=t[o++];for(;a<h;){if(n.done)break t;let c=Math.min(n.len,h-a);zt(e,c,-1),zt(r,c,n.ins==-1?-1:n.off==0?n.ins:0),n.forward(c),a+=c}}return{changes:new s(e,i),filtered:si.create(r)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],r=this.sections[e+1];r<0?t.push(i):r==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let r=[],n=[],o=0,a=null;function l(c=!1){if(!c&&!r.length)return;o<e&&zt(r,e-o,-1);let u=new s(r,n);a=a?a.compose(u.map(a)):u,r=[],n=[],o=0}function h(c){if(Array.isArray(c))for(let u of c)h(u);else if(c instanceof s){if(c.length!=e)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${e})`);l(),a=a?a.compose(c.map(a)):c}else{let{from:u,to:d=u,insert:f}=c;if(u>d||u<0||d>e)throw new RangeError(`Invalid change range ${u} to ${d} (in doc of length ${e})`);let p=f?typeof f=="string"?et.of(f.split(i||Zf)):f:et.empty,m=p.length;if(u==d&&m==0)return;u<o&&l(),u>o&&zt(r,u-o,-1),zt(r,d-u,m),Wi(n,r,p),o=d}}return h(t),l(!a),a}static empty(t){return new s(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let r=0;r<t.length;r++){let n=t[r];if(typeof n=="number")e.push(n,-1);else{if(!Array.isArray(n)||typeof n[0]!="number"||n.some((o,a)=>a&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(n.length==1)e.push(n[0],0);else{for(;i.length<r;)i.push(et.empty);i[r]=et.of(n.slice(1)),e.push(n[0],i[r].length)}}}return new s(e,i)}static createSet(t,e){return new s(t,e)}};ws=class{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,e=this.i-2>>1;return e>=t.length?et.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?et.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}},ks=class s{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let i,r;return this.empty?i=r=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),r=t.mapPos(this.to,-1)),i==this.from&&r==this.to?this:new s(i,r,this.flags)}extend(t,e=t,i=0){if(t<=this.anchor&&e>=this.anchor)return Q.range(t,e,void 0,void 0,i);let r=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return Q.range(this.anchor,r,void 0,void 0,i)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&this.goalColumn==t.goalColumn&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return Q.range(t.anchor,t.head)}static create(t,e,i){return new s(t,e,i)}},Q=class s{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:s.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(t.ranges[i],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new s([this.main],0)}addRange(t,e=!0){return s.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,s.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new s(t.ranges.map(e=>ks.fromJSON(e)),t.main)}static single(t,e=t){return new s([s.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,r=0;r<t.length;r++){let n=t[r];if(n.empty?n.from<=i:n.from<i)return s.normalized(t.slice(),e);i=n.to}return new s(t,e)}static cursor(t,e=0,i,r){return ks.create(t,t,(e==0?0:e<0?8:16)|(i==null?7:Math.min(6,i))|(r??16777215)<<6)}static range(t,e,i,r,n){let o=(i??16777215)<<6|(r==null?7:Math.min(6,r));return!n&&t!=e&&(n=e<t?1:-1),e<t?ks.create(e,t,48|o):ks.create(t,e,(n?n<0?8:16:0)|o)}static normalized(t,e=0){let i=t[e];t.sort((r,n)=>r.from-n.from),e=t.indexOf(i);for(let r=1;r<t.length;r++){let n=t[r],o=t[r-1];if(n.empty?n.from<=o.to:n.from<o.to){let a=o.from,l=Math.max(n.to,o.to);r<=e&&e--,t.splice(--r,2,n.anchor>n.head?s.range(l,a):s.range(a,l))}}return new s(t,e)}};Vf=0,X=class s{constructor(t,e,i,r,n){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=r,this.id=Vf++,this.default=t([]),this.extensions=typeof n=="function"?n(this):n}get reader(){return this}static define(t={}){return new s(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:jf),!!t.static,t.enables)}of(t){return new Dn([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Dn(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Dn(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}};Dn=class{constructor(t,e,i,r){this.dependencies=t,this.facet=e,this.type=i,this.value=r,this.id=Vf++}dynamicSlot(t){var e;let i=this.value,r=this.facet.compareInput,n=this.id,o=t[n]>>1,a=this.type==2,l=!1,h=!1,c=[];for(let u of this.dependencies)u=="doc"?l=!0:u=="selection"?h=!0:(((e=t[u.id])!==null&&e!==void 0?e:1)&1)==0&&c.push(t[u.id]);return{create(u){return u.values[o]=i(u),1},update(u,d){if(l&&d.docChanged||h&&(d.docChanged||d.selection)||Wf(u,c)){let f=i(u);if(a?!Cv(f,u.values[o],r):!r(f,u.values[o]))return u.values[o]=f,1}return 0},reconfigure:(u,d)=>{let f,p=d.config.address[n];if(p!=null){let m=hc(d,p);if(this.dependencies.every(b=>b instanceof X?d.facet(b)===u.facet(b):b instanceof bt?d.field(b,!1)==u.field(b,!1):!0)||(a?Cv(f=i(u),m,r):r(f=i(u),m)))return u.values[o]=m,0}else f=i(u);return u.values[o]=f,1}}}};oc=X.define({static:!0}),bt=class s{constructor(t,e,i,r,n){this.id=t,this.createF=e,this.updateF=i,this.compareF=r,this.spec=n,this.provides=void 0}static define(t){let e=new s(Vf++,t.create,t.update,t.compare||((i,r)=>i===r),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(oc).find(i=>i.field==this);return(e?.create||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,r)=>{let n=i.values[e],o=this.updateF(n,r);return this.compareF(n,o)?0:(i.values[e]=o,1)},reconfigure:(i,r)=>{let n=i.facet(oc),o=r.facet(oc),a;return(a=n.find(l=>l.field==this))&&a!=o.find(l=>l.field==this)?(i.values[e]=a.create(i),1):r.config.address[this.id]!=null?(i.values[e]=r.field(this),0):(i.values[e]=this.create(i),1)}}}init(t){return[this,oc.of({field:this,create:t})]}get extension(){return this}},As={lowest:4,low:3,default:2,high:1,highest:0};fe={highest:Wa(As.highest),high:Wa(As.high),default:Wa(As.default),low:Wa(As.low),lowest:Wa(As.lowest)},ac=class{constructor(t,e){this.inner=t,this.prec=e}},Fi=class s{of(t){return new Fa(this,t)}reconfigure(t){return s.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}},Fa=class{constructor(t,e){this.compartment=t,this.inner=e}},lc=class s{constructor(t,e,i,r,n,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=r,this.staticValues=n,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let r=[],n=Object.create(null),o=new Map;for(let d of oP(t,e,o))d instanceof bt?r.push(d):(n[d.facet.id]||(n[d.facet.id]=[])).push(d);let a=Object.create(null),l=[],h=[];for(let d of r)a[d.id]=h.length<<1,h.push(f=>d.slot(f));let c=i?.config.facets;for(let d in n){let f=n[d],p=f[0].facet,m=c&&c[d]||[];if(f.every(b=>b.type==0))if(a[p.id]=l.length<<1|1,jf(m,f))l.push(i.facet(p));else{let b=p.combine(f.map(g=>g.value));l.push(i&&p.compare(b,i.facet(p))?i.facet(p):b)}else{for(let b of f)b.type==0?(a[b.id]=l.length<<1|1,l.push(b.value)):(a[b.id]=h.length<<1,h.push(g=>b.dynamicSlot(g)));a[p.id]=h.length<<1,h.push(b=>nP(b,p,f))}}let u=h.map(d=>d(a));return new s(t,o,u,a,l,n)}};$v=X.define(),Ff=X.define({combine:s=>s.some(t=>t),static:!0}),Pv=X.define({combine:s=>s.length?s[0]:void 0,static:!0}),Qv=X.define(),Tv=X.define(),Lv=X.define(),Mv=X.define({combine:s=>s.length?s[0]:!1}),Jt=class{constructor(t,e){this.type=t,this.value=e}static define(){return new cc}},cc=class{of(t){return new Jt(this,t)}},uc=class{constructor(t){this.map=t}of(t){return new F(this,t)}},F=class s{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new s(this.type,e)}is(t){return this.type==t}static define(t={}){return new uc(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let r of t){let n=r.map(e);n&&i.push(n)}return i}};F.reconfigure=F.define(),F.appendConfig=F.define();xt=class s{constructor(t,e,i,r,n,o){this.startState=t,this.changes=e,this.selection=i,this.effects=r,this.annotations=n,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Ev(i,e.newLength),n.some(a=>a.type==s.time)||(this.annotations=n.concat(s.time.of(Date.now())))}static create(t,e,i,r,n,o){return new s(t,e,i,r,n,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(s.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}};xt.time=Jt.define(),xt.userEvent=Jt.define(),xt.addToHistory=Jt.define(),xt.remote=Jt.define();cP=[];gt=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})(gt||(gt={})),uP=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;try{Yf=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}at=class s{constructor(t,e,i,r,n,o){this.config=t,this.doc=e,this.selection=i,this.values=r,this.status=t.statusTemplate.slice(),this.computeSlot=n,o&&(o._state=this);for(let a=0;a<this.config.dynamicSlots.length;a++)Ua(this,a<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return Ua(this,i),hc(this,i)}update(...t){return Iv(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:r}=e;for(let a of t.effects)a.is(Fi.reconfigure)?(e&&(r=new Map,e.compartments.forEach((l,h)=>r.set(h,l)),e=null),r.set(a.value.compartment,a.value.extension)):a.is(F.reconfigure)?(e=null,i=a.value):a.is(F.appendConfig)&&(e=null,i=qn(i).concat(a.value));let n;e?n=t.startState.values.slice():(e=lc.resolve(i,r,this),n=new s(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(l,h)=>h.reconfigure(l,this),null).values);let o=t.startState.facet(Ff)?t.newSelection:t.newSelection.asSingle();new s(e,t.newDoc,o,n,(a,l)=>l.update(a,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:Q.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),r=this.changes(i.changes),n=[i.range],o=qn(i.effects);for(let a=1;a<e.ranges.length;a++){let l=t(e.ranges[a]),h=this.changes(l.changes),c=h.map(r);for(let d=0;d<a;d++)n[d]=n[d].map(c);let u=r.mapDesc(h,!0);n.push(l.range.map(u)),r=r.compose(c),o=F.mapEffects(o,c).concat(F.mapEffects(qn(l.effects),u))}return{changes:r,selection:Q.create(n,e.mainIndex),effects:o}}changes(t=[]){return t instanceof _t?t:_t.of(t,this.doc.length,this.facet(s.lineSeparator))}toText(t){return et.of(t.split(this.facet(s.lineSeparator)||Zf))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(Ua(this,e),hc(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let r=t[i];r instanceof bt&&this.config.address[r.id]!=null&&(e[i]=r.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let r=[];if(i){for(let n in i)if(Object.prototype.hasOwnProperty.call(t,n)){let o=i[n],a=t[n];r.push(o.init(l=>o.spec.fromJSON(a,l)))}}return s.create({doc:t.doc,selection:Q.fromJSON(t.selection),extensions:e.extensions?r.concat([e.extensions]):r})}static create(t={}){let e=lc.resolve(t.extensions||[],new Map),i=t.doc instanceof et?t.doc:et.of((t.doc||"").split(e.staticFacet(s.lineSeparator)||Zf)),r=t.selection?t.selection instanceof Q?t.selection:Q.single(t.selection.anchor,t.selection.head):Q.single(0);return Ev(r,i.length),e.staticFacet(Ff)||(r=r.asSingle()),new s(e,i,r,e.dynamicSlots.map(()=>null),(n,o)=>o.create(n),null)}get tabSize(){return this.facet(s.tabSize)}get lineBreak(){return this.facet(s.lineSeparator)||`
15
- `}get readOnly(){return this.facet(Mv)}phrase(t,...e){for(let i of this.facet(s.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,r)=>{if(r=="$")return"$";let n=+(r||1);return!n||n>e.length?i:e[n-1]})),t}languageDataAt(t,e,i=-1){let r=[];for(let n of this.facet($v))for(let o of n(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&r.push(o[t]);return r}charCategorizer(t){let e=this.languageDataAt("wordChars",t);return fP(e.length?e[0]:"")}wordAt(t){let{text:e,from:i,length:r}=this.doc.lineAt(t),n=this.charCategorizer(t),o=t-i,a=t-i;for(;o>0;){let l=Et(e,o,!1);if(n(e.slice(l,o))!=gt.Word)break;o=l}for(;a<r;){let l=Et(e,a);if(n(e.slice(a,l))!=gt.Word)break;a=l}return o==a?null:Q.range(o+i,a+i)}};at.allowMultipleSelections=Ff,at.tabSize=X.define({combine:s=>s.length?s[0]:4}),at.lineSeparator=Pv,at.readOnly=Mv,at.phrases=X.define({compare(s,t){let e=Object.keys(s),i=Object.keys(t);return e.length==i.length&&e.every(r=>s[r]==t[r])}}),at.languageData=$v,at.changeFilter=Qv,at.transactionFilter=Tv,at.transactionExtender=Lv,Fi.reconfigure=F.define();Ae=class{eq(t){return this==t}range(t,e=t){return Nn.create(t,e,this)}};Ae.prototype.startSide=Ae.prototype.endSide=0,Ae.prototype.point=!1,Ae.prototype.mapMode=At.TrackDel;Nn=class s{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new s(t,e,i)}};Kf=class s{constructor(t,e,i,r){this.from=t,this.to=e,this.value=i,this.maxPoint=r}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,r=0){let n=i?this.to:this.from;for(let o=r,a=n.length;;){if(o==a)return o;let l=o+a>>1,h=n[l]-t||(i?this.value[l].endSide:this.value[l].startSide)-e;if(l==o)return h>=0?o:a;h>=0?a=l:o=l+1}}between(t,e,i,r){for(let n=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,n);n<o;n++)if(r(this.from[n]+t,this.to[n]+t,this.value[n])===!1)return!1}map(t,e){let i=[],r=[],n=[],o=-1,a=-1;for(let l=0;l<this.value.length;l++){let h=this.value[l],c=this.from[l]+t,u=this.to[l]+t,d,f;if(c==u){let p=e.mapPos(c,h.startSide,h.mapMode);if(p==null||(d=f=p,h.startSide!=h.endSide&&(f=e.mapPos(c,h.endSide),f<d)))continue}else if(d=e.mapPos(c,h.startSide),f=e.mapPos(u,h.endSide),d>f||d==f&&h.startSide>0&&h.endSide<=0)continue;(f-d||h.endSide-h.startSide)<0||(o<0&&(o=d),h.point&&(a=Math.max(a,f-d)),i.push(h),r.push(d-o),n.push(f-o))}return{mapped:i.length?new s(r,n,i,a):null,pos:o}}},K=class s{constructor(t,e,i,r){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=r}static create(t,e,i,r){return new s(t,e,i,r)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:r=0,filterTo:n=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(Gf)),this.isEmpty)return e.length?s.of(e):this;let a=new dc(this,null,-1).goto(0),l=0,h=[],c=new Ee;for(;a.value||l<e.length;)if(l<e.length&&(a.from-e[l].from||a.startSide-e[l].value.startSide)>=0){let u=e[l++];c.addInner(u.from,u.to,u.value)||h.push(u)}else a.rangeIndex==1&&a.chunkIndex<this.chunk.length&&(l==e.length||this.chunkEnd(a.chunkIndex)<e[l].from)&&(!o||r>this.chunkEnd(a.chunkIndex)||n<this.chunkPos[a.chunkIndex])&&c.addChunk(this.chunkPos[a.chunkIndex],this.chunk[a.chunkIndex])?a.nextChunk():((!o||r>a.to||n<a.from||o(a.from,a.to,a.value))&&(c.addInner(a.from,a.to,a.value)||h.push(Nn.create(a.from,a.to,a.value))),a.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?s.empty:this.nextLayer.update({add:h,filter:o,filterFrom:r,filterTo:n}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],r=-1;for(let o=0;o<this.chunk.length;o++){let a=this.chunkPos[o],l=this.chunk[o],h=t.touchesRange(a,a+l.length);if(h===!1)r=Math.max(r,l.maxPoint),e.push(l),i.push(t.mapPos(a));else if(h===!0){let{mapped:c,pos:u}=l.map(a,t);c&&(r=Math.max(r,c.maxPoint),e.push(c),i.push(u))}}let n=this.nextLayer.map(t);return e.length==0?n:new s(i,e,n||s.empty,r)}between(t,e,i){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let n=this.chunkPos[r],o=this.chunk[r];if(e>=n&&t<=n+o.length&&o.between(n,t-n,e-n,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return Ya.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Ya.from(t).goto(e)}static compare(t,e,i,r,n=-1){let o=t.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=n),a=e.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=n),l=Dv(o,a,i),h=new Es(o,l,n),c=new Es(a,l,n);i.iterGaps((u,d,f)=>qv(h,u,c,d,f,r)),i.empty&&i.length==0&&qv(h,0,c,0,0,r)}static eq(t,e,i=0,r){r==null&&(r=999999999);let n=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0),o=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0);if(n.length!=o.length)return!1;if(!n.length)return!0;let a=Dv(n,o),l=new Es(n,a,0).goto(i),h=new Es(o,a,0).goto(i);for(;;){if(l.to!=h.to||!tp(l.active,h.active)||l.point&&(!h.point||!Hf(l.point,h.point)))return!1;if(l.to>r)return!0;l.next(),h.next()}}static spans(t,e,i,r,n=-1){let o=new Es(t,null,n).goto(e),a=e,l=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),u=o.pointFrom<e?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,l);r.point(a,h,o.point,c,u,o.pointRank),l=Math.min(o.openEnd(h),c.length)}else h>a&&(r.span(a,h,o.active,l),l=o.openEnd(h));if(o.to>i)return l+(o.point&&o.to>i?1:0);a=o.to,o.next()}}static of(t,e=!1){let i=new Ee;for(let r of t instanceof Nn?[t]:e?pP(t):t)i.add(r.from,r.to,r.value);return i.finish()}static join(t){if(!t.length)return s.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let r=t[i];r!=s.empty;r=r.nextLayer)e=new s(r.chunkPos,r.chunk,e,Math.max(r.maxPoint,e.maxPoint));return e}};K.empty=new K([],[],null,-1);K.empty.nextLayer=K.empty;Ee=class s{finishChunk(t){this.chunks.push(new Kf(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new s)).add(t,e,i)}addInner(t,e,i){let r=t-this.lastTo||i.startSide-this.last.endSide;if(r<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(K.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=K.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}};dc=class{constructor(t,e,i,r=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let r=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(r)||this.layer.chunkEnd(this.chunkIndex)<t||r.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}},Ya=class s{constructor(t){this.heap=t}static from(t,e=null,i=-1){let r=[];for(let n=0;n<t.length;n++)for(let o=t[n];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&r.push(new dc(o,e,i,n));return r.length==1?r[0]:new s(r)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)Jf(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)Jf(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Jf(this.heap,0)}}};Es=class{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ya.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){fc(this.active,t),fc(this.activeTo,t),fc(this.activeRank,t),this.minActive=Nv(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:r,rank:n}=this.cursor;for(;e<this.activeRank.length&&(n-this.activeRank[e]||r-this.activeTo[e])>0;)e++;pc(this.active,e,i),pc(this.activeTo,e,r),pc(this.activeRank,e,n),t&&pc(t,e,this.cursor.from),this.minActive=Nv(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>t){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&fc(i,r)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let n=this.cursor.value;if(!n.point)this.addActive(i),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=n,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=n.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let r=i.length-1;r>=0&&i[r]<t;r--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}});var I_,Xv,ep,Bv,Te,Zv,ip,sp=W(()=>{I_="\u037C",Xv=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),ep=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Bv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},Te=class{constructor(t,e){this.rules=[];let{finish:i}=e||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function n(o,a,l,h){let c=[],u=/^@(\w+)\b/.exec(o[0]),d=u&&u[1]=="keyframes";if(u&&a==null)return l.push(o[0]+";");for(let f in a){let p=a[f];if(/&/.test(f))n(f.split(/,\s*/).map(m=>o.map(b=>m.replace(/&/,b))).reduce((m,b)=>m.concat(b)),p,l);else if(p&&typeof p=="object"){if(!u)throw new RangeError("The value of a property ("+f+") should be a primitive value.");n(r(f),p,c,d)}else p!=null&&c.push(f.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||d)&&l.push((i&&!u&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in t)n(r(o),t[o],this.rules)}getRules(){return this.rules.join(`
15
+ `}get readOnly(){return this.facet(Mv)}phrase(t,...e){for(let i of this.facet(s.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,r)=>{if(r=="$")return"$";let n=+(r||1);return!n||n>e.length?i:e[n-1]})),t}languageDataAt(t,e,i=-1){let r=[];for(let n of this.facet($v))for(let o of n(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&r.push(o[t]);return r}charCategorizer(t){let e=this.languageDataAt("wordChars",t);return fP(e.length?e[0]:"")}wordAt(t){let{text:e,from:i,length:r}=this.doc.lineAt(t),n=this.charCategorizer(t),o=t-i,a=t-i;for(;o>0;){let l=Et(e,o,!1);if(n(e.slice(l,o))!=gt.Word)break;o=l}for(;a<r;){let l=Et(e,a);if(n(e.slice(a,l))!=gt.Word)break;a=l}return o==a?null:Q.range(o+i,a+i)}};at.allowMultipleSelections=Ff,at.tabSize=X.define({combine:s=>s.length?s[0]:4}),at.lineSeparator=Pv,at.readOnly=Mv,at.phrases=X.define({compare(s,t){let e=Object.keys(s),i=Object.keys(t);return e.length==i.length&&e.every(r=>s[r]==t[r])}}),at.languageData=$v,at.changeFilter=Qv,at.transactionFilter=Tv,at.transactionExtender=Lv,Fi.reconfigure=F.define();Ae=class{eq(t){return this==t}range(t,e=t){return Nn.create(t,e,this)}};Ae.prototype.startSide=Ae.prototype.endSide=0,Ae.prototype.point=!1,Ae.prototype.mapMode=At.TrackDel;Nn=class s{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new s(t,e,i)}};Kf=class s{constructor(t,e,i,r){this.from=t,this.to=e,this.value=i,this.maxPoint=r}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,r=0){let n=i?this.to:this.from;for(let o=r,a=n.length;;){if(o==a)return o;let l=o+a>>1,h=n[l]-t||(i?this.value[l].endSide:this.value[l].startSide)-e;if(l==o)return h>=0?o:a;h>=0?a=l:o=l+1}}between(t,e,i,r){for(let n=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,n);n<o;n++)if(r(this.from[n]+t,this.to[n]+t,this.value[n])===!1)return!1}map(t,e){let i=[],r=[],n=[],o=-1,a=-1;for(let l=0;l<this.value.length;l++){let h=this.value[l],c=this.from[l]+t,u=this.to[l]+t,d,f;if(c==u){let p=e.mapPos(c,h.startSide,h.mapMode);if(p==null||(d=f=p,h.startSide!=h.endSide&&(f=e.mapPos(c,h.endSide),f<d)))continue}else if(d=e.mapPos(c,h.startSide),f=e.mapPos(u,h.endSide),d>f||d==f&&h.startSide>0&&h.endSide<=0)continue;(f-d||h.endSide-h.startSide)<0||(o<0&&(o=d),h.point&&(a=Math.max(a,f-d)),i.push(h),r.push(d-o),n.push(f-o))}return{mapped:i.length?new s(r,n,i,a):null,pos:o}}},K=class s{constructor(t,e,i,r){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=r}static create(t,e,i,r){return new s(t,e,i,r)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:r=0,filterTo:n=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(Gf)),this.isEmpty)return e.length?s.of(e):this;let a=new dc(this,null,-1).goto(0),l=0,h=[],c=new Ee;for(;a.value||l<e.length;)if(l<e.length&&(a.from-e[l].from||a.startSide-e[l].value.startSide)>=0){let u=e[l++];c.addInner(u.from,u.to,u.value)||h.push(u)}else a.rangeIndex==1&&a.chunkIndex<this.chunk.length&&(l==e.length||this.chunkEnd(a.chunkIndex)<e[l].from)&&(!o||r>this.chunkEnd(a.chunkIndex)||n<this.chunkPos[a.chunkIndex])&&c.addChunk(this.chunkPos[a.chunkIndex],this.chunk[a.chunkIndex])?a.nextChunk():((!o||r>a.to||n<a.from||o(a.from,a.to,a.value))&&(c.addInner(a.from,a.to,a.value)||h.push(Nn.create(a.from,a.to,a.value))),a.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?s.empty:this.nextLayer.update({add:h,filter:o,filterFrom:r,filterTo:n}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],r=-1;for(let o=0;o<this.chunk.length;o++){let a=this.chunkPos[o],l=this.chunk[o],h=t.touchesRange(a,a+l.length);if(h===!1)r=Math.max(r,l.maxPoint),e.push(l),i.push(t.mapPos(a));else if(h===!0){let{mapped:c,pos:u}=l.map(a,t);c&&(r=Math.max(r,c.maxPoint),e.push(c),i.push(u))}}let n=this.nextLayer.map(t);return e.length==0?n:new s(i,e,n||s.empty,r)}between(t,e,i){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let n=this.chunkPos[r],o=this.chunk[r];if(e>=n&&t<=n+o.length&&o.between(n,t-n,e-n,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return Ya.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Ya.from(t).goto(e)}static compare(t,e,i,r,n=-1){let o=t.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=n),a=e.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=n),l=Dv(o,a,i),h=new Es(o,l,n),c=new Es(a,l,n);i.iterGaps((u,d,f)=>qv(h,u,c,d,f,r)),i.empty&&i.length==0&&qv(h,0,c,0,0,r)}static eq(t,e,i=0,r){r==null&&(r=999999999);let n=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0),o=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0);if(n.length!=o.length)return!1;if(!n.length)return!0;let a=Dv(n,o),l=new Es(n,a,0).goto(i),h=new Es(o,a,0).goto(i);for(;;){if(l.to!=h.to||!tp(l.active,h.active)||l.point&&(!h.point||!Hf(l.point,h.point)))return!1;if(l.to>r)return!0;l.next(),h.next()}}static spans(t,e,i,r,n=-1){let o=new Es(t,null,n).goto(e),a=e,l=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),u=o.pointFrom<e?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,l);r.point(a,h,o.point,c,u,o.pointRank),l=Math.min(o.openEnd(h),c.length)}else h>a&&(r.span(a,h,o.active,l),l=o.openEnd(h));if(o.to>i)return l+(o.point&&o.to>i?1:0);a=o.to,o.next()}}static of(t,e=!1){let i=new Ee;for(let r of t instanceof Nn?[t]:e?pP(t):t)i.add(r.from,r.to,r.value);return i.finish()}static join(t){if(!t.length)return s.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let r=t[i];r!=s.empty;r=r.nextLayer)e=new s(r.chunkPos,r.chunk,e,Math.max(r.maxPoint,e.maxPoint));return e}};K.empty=new K([],[],null,-1);K.empty.nextLayer=K.empty;Ee=class s{finishChunk(t){this.chunks.push(new Kf(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new s)).add(t,e,i)}addInner(t,e,i){let r=t-this.lastTo||i.startSide-this.last.endSide;if(r<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(K.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=K.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}};dc=class{constructor(t,e,i,r=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let r=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(r)||this.layer.chunkEnd(this.chunkIndex)<t||r.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}},Ya=class s{constructor(t){this.heap=t}static from(t,e=null,i=-1){let r=[];for(let n=0;n<t.length;n++)for(let o=t[n];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&r.push(new dc(o,e,i,n));return r.length==1?r[0]:new s(r)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)Jf(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)Jf(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Jf(this.heap,0)}}};Es=class{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ya.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){fc(this.active,t),fc(this.activeTo,t),fc(this.activeRank,t),this.minActive=Nv(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:r,rank:n}=this.cursor;for(;e<this.activeRank.length&&(n-this.activeRank[e]||r-this.activeTo[e])>0;)e++;pc(this.active,e,i),pc(this.activeTo,e,r),pc(this.activeRank,e,n),t&&pc(t,e,this.cursor.from),this.minActive=Nv(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>t){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&fc(i,r)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let n=this.cursor.value;if(!n.point)this.addActive(i),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=n,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=n.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let r=i.length-1;r>=0&&i[r]<t;r--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}});var N_,Xv,ep,Bv,Te,Zv,ip,sp=W(()=>{N_="\u037C",Xv=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),ep=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Bv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},Te=class{constructor(t,e){this.rules=[];let{finish:i}=e||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function n(o,a,l,h){let c=[],u=/^@(\w+)\b/.exec(o[0]),d=u&&u[1]=="keyframes";if(u&&a==null)return l.push(o[0]+";");for(let f in a){let p=a[f];if(/&/.test(f))n(f.split(/,\s*/).map(m=>o.map(b=>m.replace(/&/,b))).reduce((m,b)=>m.concat(b)),p,l);else if(p&&typeof p=="object"){if(!u)throw new RangeError("The value of a property ("+f+") should be a primitive value.");n(r(f),p,c,d)}else p!=null&&c.push(f.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||d)&&l.push((i&&!u&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in t)n(r(o),t[o],this.rules)}getRules(){return this.rules.join(`
16
16
  `)}static newName(){let t=Bv[Xv]||1;return Bv[Xv]=t+1,"\u037C"+t.toString(36)}static mount(t,e,i){let r=t[ep],n=i&&i.nonce;r?n&&r.setNonce(n):r=new ip(t,n),r.mount(Array.isArray(e)?e:[e],t)}},Zv=new Map,ip=class{constructor(t,e){let i=t.ownerDocument||t,r=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&r.CSSStyleSheet){let n=Zv.get(i);if(n)return t[ep]=n;this.sheet=new r.CSSStyleSheet,Zv.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[ep]=this}mount(t,e){let i=this.sheet,r=0,n=0;for(let o=0;o<t.length;o++){let a=t[o],l=this.modules.indexOf(a);if(l<n&&l>-1&&(this.modules.splice(l,1),n--,l=-1),l==-1){if(this.modules.splice(n++,0,a),i)for(let h=0;h<a.rules.length;h++)i.insertRule(a.rules[h],r++)}else{for(;n<l;)r+=this.modules[n++].rules.length;r+=a.rules.length,n++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let o="";for(let l=0;l<this.modules.length;l++)o+=this.modules[l].getRules()+`
17
17
  `;this.styleTag.textContent=o;let a=e.head||e;this.styleTag.parentNode!=a&&a.insertBefore(this.styleTag,a.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}});function zv(s){var t=mP&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||gP&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",e=!t&&s.key||(s.shiftKey?Xn:vi)[s.keyCode]||s.key||"Unidentified";return e=="Esc"&&(e="Escape"),e=="Del"&&(e="Delete"),e=="Left"&&(e="ArrowLeft"),e=="Up"&&(e="ArrowUp"),e=="Right"&&(e="ArrowRight"),e=="Down"&&(e="ArrowDown"),e}var vi,Xn,mP,gP,Ct,gc,_v=W(()=>{vi={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Xn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},mP=typeof navigator<"u"&&/Mac/.test(navigator.platform),gP=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(Ct=0;Ct<10;Ct++)vi[48+Ct]=vi[96+Ct]=String(Ct);for(Ct=1;Ct<=24;Ct++)vi[Ct+111]="F"+Ct;for(Ct=65;Ct<=90;Ct++)vi[Ct]=String.fromCharCode(Ct+32),Xn[Ct]=String.fromCharCode(Ct);for(gc in vi)Xn.hasOwnProperty(gc)||(Xn[gc]=vi[gc])});function Qt(){var s=arguments[0];typeof s=="string"&&(s=document.createElement(s));var t=1,e=arguments[1];if(e&&typeof e=="object"&&e.nodeType==null&&!Array.isArray(e)){for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var r=e[i];typeof r=="string"?s.setAttribute(i,r):r!=null&&(s[i]=r)}t++}for(;t<arguments.length;t++)Vv(s,arguments[t]);return s}function Vv(s,t){if(typeof t=="string")s.appendChild(document.createTextNode(t));else if(t!=null)if(t.nodeType!=null)s.appendChild(t);else if(Array.isArray(t))for(var e=0;e<t.length;e++)Vv(s,t[e]);else throw new RangeError("Unsupported child node: "+t)}var rp=W(()=>{});function cp(s,t){for(let e in s)e=="class"&&t.class?t.class+=" "+s.class:e=="style"&&t.style?t.style+=";"+s.style:t[e]=s[e];return t}function up(s,t,e){if(s==t)return!0;s||(s=Oc),t||(t=Oc);let i=Object.keys(s),r=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=r.length-(e&&r.indexOf(e)>-1?1:0))return!1;for(let n of i)if(n!=e&&(r.indexOf(n)==-1||s[n]!==t[n]))return!1;return!0}function bP(s,t){for(let e=s.attributes.length-1;e>=0;e--){let i=s.attributes[e].name;t[i]==null&&s.removeAttribute(i)}for(let e in t){let i=t[e];e=="style"?s.style.cssText=i:s.getAttribute(e)!=i&&s.setAttribute(e,i)}}function Yv(s,t,e){let i=!1;if(t)for(let r in t)e&&r in e||(i=!0,r=="style"?s.style.cssText="":s.removeAttribute(r));if(e)for(let r in e)t&&t[r]==e[r]||(i=!0,r=="style"?s.style.cssText=e[r]:s.setAttribute(r,e[r]));return i}function OP(s){let t=Object.create(null);for(let e=0;e<s.attributes.length;e++){let i=s.attributes[e];t[i.name]=i.value}return t}function Hv(s,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=s;return e==null&&(e=s.inclusive),i==null&&(i=s.inclusive),{start:e??t,end:i??t}}function yP(s,t){return s==t||!!(s&&t&&s.compare(t))}function Bn(s,t,e,i=0){let r=e.length-1;r>=0&&e[r]+i>=s?e[r]=Math.max(e[r],t):e.push(s,t)}function tl(s){let t;return s.nodeType==11?t=s.getSelection?s:s.ownerDocument:t=s,t.getSelection()}function dp(s,t){return t?s==t||s.contains(t.nodeType!=1?t.parentNode:t):!1}function el(s,t){if(!t.anchorNode)return!1;try{return dp(s,t.anchorNode)}catch{return!1}}function il(s){return s.nodeType==3?nl(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function sl(s,t,e,i){return e?Gv(s,t,e,i,-1)||Gv(s,t,e,i,1):!1}function Ui(s){for(var t=0;;t++)if(s=s.previousSibling,!s)return t}function yc(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function Gv(s,t,e,i,r){for(;;){if(s==e&&t==i)return!0;if(t==(r<0?0:xi(s))){if(s.nodeName=="DIV")return!1;let n=s.parentNode;if(!n||n.nodeType!=1)return!1;t=Ui(s)+(r<0?0:1),s=n}else if(s.nodeType==1){if(s=s.childNodes[t+(r<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;t=r<0?xi(s):0}else return!1}}function xi(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function rl(s,t){let e=t?s.left:s.right;return{left:e,right:e,top:s.top,bottom:s.bottom}}function vP(s){let t=s.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function Kv(s,t){let e=t.width/s.offsetWidth,i=t.height/s.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-s.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-s.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function xP(s,t,e,i,r,n,o,a){let l=s.ownerDocument,h=l.defaultView||window;for(let c=s,u=!1;c&&!u;)if(c.nodeType==1){let d,f=c==l.body,p=1,m=1;if(f)d=vP(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let x=c.getBoundingClientRect();({scaleX:p,scaleY:m}=Kv(c,x)),d={left:x.left,right:x.left+c.clientWidth*p,top:x.top,bottom:x.top+c.clientHeight*m}}let b=0,g=0;if(r=="nearest")t.top<d.top+o?(g=t.top-(d.top+o),e>0&&t.bottom>d.bottom+g&&(g=t.bottom-d.bottom+o)):t.bottom>d.bottom-o&&(g=t.bottom-d.bottom+o,e<0&&t.top-g<d.top&&(g=t.top-(d.top+o)));else{let x=t.bottom-t.top,S=d.bottom-d.top;g=(r=="center"&&x<=S?t.top+x/2-S/2:r=="start"||r=="center"&&e<0?t.top-o:t.bottom-S+o)-d.top}if(i=="nearest"?t.left<d.left+n?(b=t.left-(d.left+n),e>0&&t.right>d.right+b&&(b=t.right-d.right+n)):t.right>d.right-n&&(b=t.right-d.right+n,e<0&&t.left<d.left+b&&(b=t.left-(d.left+n))):b=(i=="center"?t.left+(t.right-t.left)/2-(d.right-d.left)/2:i=="start"==a?t.left-n:t.right-(d.right-d.left)+n)-d.left,b||g)if(f)h.scrollBy(b,g);else{let x=0,S=0;if(g){let w=c.scrollTop;c.scrollTop+=g/m,S=(c.scrollTop-w)*m}if(b){let w=c.scrollLeft;c.scrollLeft+=b/p,x=(c.scrollLeft-w)*p}t={left:t.left-x,top:t.top-S,right:t.right-x,bottom:t.bottom-S},x&&Math.abs(x-b)<1&&(i="nearest"),S&&Math.abs(S-g)<1&&(r="nearest")}if(f)break;(t.top<d.top||t.bottom>d.bottom||t.left<d.left||t.right>d.right)&&(t={left:Math.max(t.left,d.left),right:Math.min(t.right,d.right),top:Math.max(t.top,d.top),bottom:Math.min(t.bottom,d.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Jv(s,t=!0){let e=s.ownerDocument,i=null,r=null;for(let n=s.parentNode;n&&!(n==e.body||(!t||i)&&r);)if(n.nodeType==1)!r&&n.scrollHeight>n.clientHeight&&(r=n),t&&!i&&n.scrollWidth>n.clientWidth&&(i=n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;return{x:i,y:r}}function t0(s){if(s.setActive)return s.setActive();if($s)return s.focus($s);let t=[];for(let e=s;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(s.focus($s==null?{get preventScroll(){return $s={preventScroll:!0},!0}}:void 0),!$s){$s=!1;for(let e=0;e<t.length;){let i=t[e++],r=t[e++],n=t[e++];i.scrollTop!=r&&(i.scrollTop=r),i.scrollLeft!=n&&(i.scrollLeft=n)}}}function nl(s,t,e=t){let i=e0||(e0=document.createRange());return i.setEnd(s,e),i.setStart(s,t),i}function Zn(s,t,e,i){let r={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=i);let n=new KeyboardEvent("keydown",r);n.synthetic=!0,s.dispatchEvent(n);let o=new KeyboardEvent("keyup",r);return o.synthetic=!0,s.dispatchEvent(o),n.defaultPrevented||o.defaultPrevented}function SP(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function wP(s,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,xi(e));;)if(i){if(e.nodeType!=1)return!1;let r=e.childNodes[i-1];r.contentEditable=="false"?i--:(e=r,i=xi(e))}else{if(e==s)return!0;i=Ui(e),e=e.parentNode}}function i0(s){return s instanceof Window?s.pageYOffset>Math.max(0,s.document.documentElement.scrollHeight-s.innerHeight-4):s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function s0(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=xi(e)}else if(e.parentNode&&!yc(e))i=Ui(e),e=e.parentNode;else return null}}function r0(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!yc(e))i=Ui(e)+1,e=e.parentNode;else return null}}function n0(s){let t=[];for(let e=0;e<s.length;e++)t.push(1<<+s[e]);return t}function o0(s){return s<=247?kP[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?AP[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}function a0(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++){let i=s[e],r=t[e];if(i.from!=r.from||i.to!=r.to||i.direction!=r.direction||!a0(i.inner,r.inner))return!1}return!0}function CP(s,t,e,i,r){for(let n=0;n<=i.length;n++){let o=n?i[n-1].to:t,a=n<i.length?i[n].from:e,l=n?256:r;for(let h=o,c=l,u=l;h<a;h++){let d=o0(s.charCodeAt(h));d==512?d=c:d==8&&u==4&&(d=16),ht[h]=d==4?2:d,d&7&&(u=d),c=d}for(let h=o,c=l,u=l;h<a;h++){let d=ht[h];if(d==128)h<a-1&&c==ht[h+1]&&c&24?d=ht[h]=c:ht[h]=256;else if(d==64){let f=h+1;for(;f<a&&ht[f]==64;)f++;let p=h&&c==8||f<e&&ht[f]==8?u==1?1:8:256;for(let m=h;m<f;m++)ht[m]=p;h=f-1}else d==8&&u==1&&(ht[h]=1);c=d,d&7&&(u=d)}}}function $P(s,t,e,i,r){let n=r==1?2:1;for(let o=0,a=0,l=0;o<=i.length;o++){let h=o?i[o-1].to:t,c=o<i.length?i[o].from:e;for(let u=h,d,f,p;u<c;u++)if(f=mp[d=s.charCodeAt(u)])if(f<0){for(let m=a-3;m>=0;m-=3)if(oi[m+1]==-f){let b=oi[m+2],g=b&2?r:b&4?b&1?n:r:0;g&&(ht[u]=ht[oi[m]]=g),a=m;break}}else{if(oi.length==189)break;oi[a++]=u,oi[a++]=d,oi[a++]=l}else if((p=ht[u])==2||p==1){let m=p==r;l=m?0:1;for(let b=a-3;b>=0;b-=3){let g=oi[b+2];if(g&2)break;if(m)oi[b+2]|=2;else{if(g&4)break;oi[b+2]|=4}}}}}function PP(s,t,e,i){for(let r=0,n=i;r<=e.length;r++){let o=r?e[r-1].to:s,a=r<e.length?e[r].from:t;for(let l=o;l<a;){let h=ht[l];if(h==256){let c=l+1;for(;;)if(c==a){if(r==e.length)break;c=e[r++].to,a=r<e.length?e[r].from:t}else if(ht[c]==256)c++;else break;let u=n==1,d=(c<t?ht[c]:i)==1,f=u==d?u?1:2:i;for(let p=c,m=r,b=m?e[m-1].to:s;p>l;)p==b&&(p=e[--m].from,b=m?e[m-1].to:s),ht[--p]=f;l=c}else n=h,l++}}}function gp(s,t,e,i,r,n,o){let a=i%2?2:1;if(i%2==r%2)for(let l=t,h=0;l<e;){let c=!0,u=!1;if(h==n.length||l<n[h].from){let m=ht[l];m!=a&&(c=!1,u=m==16)}let d=!c&&a==1?[]:null,f=c?i:i+1,p=l;t:for(;;)if(h<n.length&&p==n[h].from){if(u)break t;let m=n[h];if(!c)for(let b=m.to,g=h+1;;){if(b==e)break t;if(g<n.length&&n[g].from==b)b=n[g++].to;else{if(ht[b]==a)break t;break}}if(h++,d)d.push(m);else{m.from>l&&o.push(new Ce(l,m.from,f));let b=m.direction==Ps!=!(f%2);bp(s,b?i+1:i,r,m.inner,m.from,m.to,o),l=m.to}p=m.to}else{if(p==e||(c?ht[p]!=a:ht[p]==a))break;p++}d?gp(s,l,p,i+1,r,d,o):l<p&&o.push(new Ce(l,p,f)),l=p}else for(let l=e,h=n.length;l>t;){let c=!0,u=!1;if(!h||l>n[h-1].to){let m=ht[l-1];m!=a&&(c=!1,u=m==16)}let d=!c&&a==1?[]:null,f=c?i:i+1,p=l;t:for(;;)if(h&&p==n[h-1].to){if(u)break t;let m=n[--h];if(!c)for(let b=m.from,g=h;;){if(b==t)break t;if(g&&n[g-1].to==b)b=n[--g].from;else{if(ht[b-1]==a)break t;break}}if(d)d.push(m);else{m.to<l&&o.push(new Ce(m.to,l,f));let b=m.direction==Ps!=!(f%2);bp(s,b?i+1:i,r,m.inner,m.from,m.to,o),l=m.from}p=m.from}else{if(p==t||(c?ht[p-1]!=a:ht[p-1]==a))break;p--}d?gp(s,p,l,i+1,r,d,o):p<l&&o.push(new Ce(p,l,f)),l=p}}function bp(s,t,e,i,r,n,o){let a=t%2?2:1;CP(s,r,n,i,a),$P(s,r,n,i,a),PP(r,n,i,a),gp(s,r,n,t,e,i,o)}function l0(s,t,e){if(!s)return[new Ce(0,0,t==pp?1:0)];if(t==Ps&&!e.length&&!EP.test(s))return h0(s.length);if(e.length)for(;s.length>ht.length;)ht[ht.length]=256;let i=[],r=t==Ps?0:1;return bp(s,r,r,e,0,s.length,i),i}function h0(s){return[new Ce(0,s,0)]}function u0(s,t,e,i,r){var n;let o=i.head-s.from,a=Ce.find(t,o,(n=i.bidiLevel)!==null&&n!==void 0?n:-1,i.assoc),l=t[a],h=l.side(r,e);if(o==h){let d=a+=r?1:-1;if(d<0||d>=t.length)return null;l=t[a=d],o=l.side(!r,e),h=l.side(r,e)}let c=Et(s.text,o,l.forward(r,e));(c<l.from||c>l.to)&&(c=h),c0=s.text.slice(Math.min(o,c),Math.max(o,c));let u=a==(r?t.length-1:0)?null:t[a+(r?1:-1)];return u&&c==h&&u.level+(r?0:1)<l.level?Q.cursor(u.side(!r,e)+s.from,u.forward(r,e)?1:-1,u.level):Q.cursor(c+s.from,l.forward(r,e)?-1:1,l.level)}function QP(s,t,e){for(let i=t;i<e;i++){let r=o0(s.charCodeAt(i));if(r==1)return Ps;if(r==2||r==4)return pp}return Ps}function Tt(s,t,e){let i=s.facet(m0);i.length?i[0](t):window.onerror&&window.onerror(String(t),e,void 0,void 0,t)||(e?console.error(e+":",t):console.error(t))}function A0(s,t){let e=s.state.facet(k0);if(!e.length)return e;let i=e.map(n=>n instanceof Function?n(s):n),r=[];return K.spans(i,t.from,t.to,{point(){},span(n,o,a,l){let h=n-t.from,c=o-t.from,u=r;for(let d=a.length-1;d>=0;d--,l--){let f=a[d].spec.bidiIsolate,p;if(f==null&&(f=QP(t.text,h,c)),l>0&&u.length&&(p=u[u.length-1]).to==h&&p.direction==f)p.to=c,u=p.inner;else{let m={from:h,to:c,direction:f,inner:[]};u.push(m),u=m.inner}}}}),r}function Sp(s){let t=0,e=0,i=0,r=0;for(let n of s.state.facet(E0)){let o=n(s);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(r=Math.max(r,o.bottom)))}return{left:t,right:e,top:i,bottom:r}}function C0(s){let t=s.nextSibling;return s.parentNode.removeChild(s),t}function MP(s){let t=s.dom.lastChild;if(!t)return s.dom.getBoundingClientRect();let e=il(t);return e[e.length-1]||null}function RP(s,t){let e=s.coordsIn(0,1),i=t.coordsIn(0,1);return e&&i&&i.top<e.bottom}function $0(s,t){let e=i=>{for(let r of i.children)if((t?r.isText():r.length)||e(r))return!0;return!1};return e(s)}function IP(s){let t=s.isReplace?(s.startSide<0?64:0)|(s.endSide>0?128:0):s.startSide>0?32:16;return s.block&&(t|=256),t}function DP(s,t){let e=t.spec.attributes,i=t.spec.class;return!e&&!i||(s||(s={class:"cm-line"}),e&&cp(e,s),i&&(s.class+=" "+i)),s}function qP(s){let t=[];for(let e=s.parents.length;e>1;e--){let i=e==s.parents.length?s.tile:s.parents[e].tile;i instanceof pe&&t.push(i.mark)}return t}function Pp(s){let t=Ot.get(s);return t&&t.setDOM(s.cloneNode()),s}function Tp(s,t){let e=t?.get(s);if(e!=1){e==null&&s.destroy();for(let i of s.children)Tp(i,t)}}function NP(s){return s.node.nodeType==1&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}function Q0(s,t){let e=s.observer.selectionRange;if(!e.focusNode)return null;let i=s0(e.focusNode,e.focusOffset),r=r0(e.focusNode,e.focusOffset),n=i||r;if(r&&i&&r.node!=i.node){let a=Ot.get(r.node);if(!a||a.isText()&&a.text!=r.node.nodeValue)n=r;else if(s.docView.lastCompositionAfterCursor){let l=Ot.get(i.node);!l||l.isText()&&l.text!=i.node.nodeValue||(n=r)}}if(s.docView.lastCompositionAfterCursor=n!=i,!n)return null;let o=t-n.offset;return{from:o,to:o+n.node.nodeValue.length,node:n.node}}function XP(s,t,e){let i=Q0(s,e);if(!i)return null;let{node:r,from:n,to:o}=i,a=r.nodeValue;if(/[\n\r]/.test(a)||s.state.doc.sliceString(i.from,i.to)!=a)return null;let l=t.invertedDesc;return{range:new Le(l.mapPos(n),l.mapPos(o),n,o),text:r}}function BP(s,t){return s.nodeType!=1?0:(t&&s.childNodes[t-1].contentEditable=="false"?1:0)|(t<s.childNodes.length&&s.childNodes[t].contentEditable=="false"?2:0)}function zP(s,t,e){let i=new ZP;return K.compare(s,t,e,i),i.changes}function _P(s,t,e){let i=new Lp;return K.compare(s,t,e,i),i.changes}function VP(s,t){for(let e=s;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function jP(s,t){let e=!1;return t&&s.iterChangedRanges((i,r)=>{i<t.to&&r>t.from&&(e=!0)}),e}function WP(s,t,e=1){let i=s.charCategorizer(t),r=s.doc.lineAt(t),n=t-r.from;if(r.length==0)return Q.cursor(t);n==0?e=1:n==r.length&&(e=-1);let o=n,a=n;e<0?o=Et(r.text,n,!1):a=Et(r.text,n);let l=i(r.text.slice(o,a));for(;o>0;){let h=Et(r.text,o,!1);if(i(r.text.slice(h,o))!=l)break;o=h}for(;a<r.length;){let h=Et(r.text,a);if(i(r.text.slice(a,h))!=l)break;a=h}return Q.range(o+r.from,a+r.from)}function FP(s,t,e,i,r){let n=Math.round((i-t.left)*s.defaultCharacterWidth);if(s.lineWrapping&&e.height>s.defaultLineHeight*1.5){let a=s.viewState.heightOracle.textHeight,l=Math.floor((r-e.top-(s.defaultLineHeight-a)*.5)/a);n+=l*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(e.from,e.to);return e.from+Ha(o,n,s.state.tabSize)}function Mp(s,t,e){let i=s.lineBlockAt(t);if(Array.isArray(i.type)){let r;for(let n of i.type){if(n.from>t)break;if(!(n.to<t)){if(n.from<t&&n.to>t)return n;(!r||n.type==Dt.Text&&(r.type!=n.type||(e<0?n.from<t:n.to>t)))&&(r=n)}}return r||i}return i}function UP(s,t,e,i){let r=Mp(s,t.head,t.assoc||-1),n=!i||r.type!=Dt.Text||!(s.lineWrapping||r.widgetLineBreaks)?null:s.coordsAtPos(t.assoc<0&&t.head>r.from?t.head-1:t.head);if(n){let o=s.dom.getBoundingClientRect(),a=s.textDirectionAt(r.from),l=s.posAtCoords({x:e==(a==rt.LTR)?o.right-1:o.left+1,y:(n.top+n.bottom)/2});if(l!=null)return Q.cursor(l,e?-1:1)}return Q.cursor(e?r.to:r.from,e?-1:1)}function T0(s,t,e,i){let r=s.state.doc.lineAt(t.head),n=s.bidiSpans(r),o=s.textDirectionAt(r.from);for(let a=t,l=null;;){let h=u0(r,n,o,a,e),c=c0;if(!h){if(r.number==(e?s.state.doc.lines:1))return a;c=`
18
18
  `,r=s.state.doc.line(r.number+(e?1:-1)),n=s.bidiSpans(r),h=s.visualLineSide(r,!e)}if(l){if(!l(c))return a}else{if(!i)return h;l=i(c)}a=h}}function YP(s,t,e){let i=s.state.charCategorizer(t),r=i(e);return n=>{let o=i(n);return r==gt.Space&&(r=o),r==o}}function HP(s,t,e,i){let r=t.head,n=e?1:-1;if(r==(e?s.state.doc.length:0))return Q.cursor(r,t.assoc);let o=t.goalColumn,a,l=s.contentDOM.getBoundingClientRect(),h=s.coordsAtPos(r,t.assoc||((t.empty?e:t.head==t.from)?1:-1)),c=s.documentTop;if(h)o==null&&(o=h.left-l.left),a=n<0?h.top:h.bottom;else{let p=s.viewState.lineBlockAt(r);o==null&&(o=Math.min(l.right-l.left,s.defaultCharacterWidth*(r-p.from))),a=(n<0?p.top:p.bottom)+c}let u=l.left+o,d=s.viewState.heightOracle.textHeight>>1,f=i??d;for(let p=0;;p+=d){let m=a+(f+p)*n,b=Ip(s,{x:u,y:m},!1,n);if(e?m>l.bottom:m<l.top)return Q.cursor(b.pos,b.assoc);let g=s.coordsAtPos(b.pos,b.assoc),x=g?(g.top+g.bottom)/2:0;if(!g||(e?x>a:x<a))return Q.cursor(b.pos,b.assoc,void 0,o)}}function dl(s,t,e){for(;;){let i=0;for(let r of s)r.between(t-1,t+1,(n,o,a)=>{if(t>n&&t<o){let l=i||e||(t-n<o-t?-1:1);t=l<0?n:o,i=l}});if(!i)return t}}function L0(s,t){let e=null;for(let i=0;i<t.ranges.length;i++){let r=t.ranges[i],n=null;if(r.empty){let o=dl(s,r.from,0);o!=r.from&&(n=Q.cursor(o,-1))}else{let o=dl(s,r.from,-1),a=dl(s,r.to,1);(o!=r.from||a!=r.to)&&(n=Q.range(r.from==r.anchor?o:a,r.from==r.head?o:a))}n&&(e||(e=t.ranges.slice()),e[i]=n)}return e?Q.create(e,t.mainIndex):t}function Rp(s,t,e){let i=dl(s.state.facet(ll).map(r=>r(s)),e.from,t.head>e.from?-1:1);return i==e.from?e:Q.cursor(i,i<e.from?1:-1)}function Ip(s,t,e,i){let r=s.contentDOM.getBoundingClientRect(),n=r.top+s.viewState.paddingTop,{x:o,y:a}=t,l=a-n,h;for(;;){if(l<0)return new Me(0,1);if(l>s.viewState.docHeight)return new Me(s.state.doc.length,-1);if(h=s.elementAtHeight(l),i==null)break;if(h.type==Dt.Text){if(i<0?h.to<s.viewport.from:h.from>s.viewport.to)break;let d=s.docView.coordsAt(i<0?h.from:h.to,i>0?-1:1);if(d&&(i<0?d.top<=l+n:d.bottom>=l+n))break}let u=s.viewState.heightOracle.textHeight/2;l=i>0?h.bottom+u:h.top-u}if(s.viewport.from>=h.to||s.viewport.to<=h.from){if(e)return null;if(h.type==Dt.Text){let u=FP(s,r,h,o,a);return new Me(u,u==h.from?1:-1)}}if(h.type!=Dt.Text)return l<(h.top+h.bottom)/2?new Me(h.from,1):new Me(h.to,-1);let c=s.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=s.docView.lineAt(h.from,-2)),new Dp(s,o,a,s.textDirectionAt(h.from)).scanTile(c,h.from)}function GP(s,t,e){for(;;){if(!t||e<xi(t))return!1;if(t==s)return!0;e=Ui(t)+1,t=t.parentNode}}function KP(s,t){let e;for(;!(s==t||!s);s=s.nextSibling){let i=Ot.get(s);if(!i?.isWidget())return!1;i&&(e||(e=[])).push(i)}if(e)for(let i of e){let r=i.overrideDOMText;if(r?.length)return!1}return!0}function M0(s,t,e,i){if(s.isComposite()){let r=-1,n=-1,o=-1,a=-1;for(let l=0,h=i,c=i;l<s.children.length;l++){let u=s.children[l],d=h+u.length;if(h<t&&d>e)return M0(u,t,e,h);if(d>=t&&r==-1&&(r=l,n=h),h>e&&u.dom.parentNode==s.dom){o=l,a=c;break}c=d,h=d+u.breakAfter}return{from:n,to:a<0?i+s.length:a,startDOM:(r?s.children[r-1].dom.nextSibling:null)||s.dom.firstChild,endDOM:o<s.children.length&&o>=0?s.children[o].dom:null}}else return s.isText()?{from:i,to:i+s.length,startDOM:s.dom,endDOM:s.dom.nextSibling}:null}function R0(s,t){let e,{newSel:i}=t,{state:r}=s,n=r.selection.main,o=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(t.bounds){let{from:a,to:l}=t.bounds,h=n.from,c=null;(o===8||B.android&&t.text.length<l-a)&&(h=n.to,c="end");let u=r.doc.sliceString(a,l,Fn),d,f;!n.empty&&n.from>=a&&n.to<=l&&(t.typeOver||u!=t.text)&&u.slice(0,n.from-a)==t.text.slice(0,n.from-a)&&u.slice(n.to-a)==t.text.slice(d=t.text.length-(u.length-(n.to-a)))?e={from:n.from,to:n.to,insert:et.of(t.text.slice(n.from-a,d).split(Fn))}:(f=I0(u,t.text,h-a,c))&&(B.chrome&&o==13&&f.toB==f.from+2&&t.text.slice(f.from,f.toB)==Fn+Fn&&f.toB--,e={from:a+f.from,to:a+f.toA,insert:et.of(t.text.slice(f.from,f.toB).split(Fn))})}else i&&(!s.hasFocus&&r.facet(Si)||Ec(i,n))&&(i=null);if(!e&&!i)return!1;if((B.mac||B.android)&&e&&e.from==e.to&&e.from==n.head-1&&/^\. ?$/.test(e.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=Q.single(i.main.anchor-1,i.main.head-1)),e={from:e.from,to:e.to,insert:et.of([e.insert.toString().replace("."," ")])}):r.doc.lineAt(n.from).to<n.to&&s.docView.lineHasWidget(n.to)&&s.inputState.insertingTextAt>Date.now()-50?e={from:n.from,to:n.to,insert:r.toText(s.inputState.insertingText)}:B.chrome&&e&&e.from==e.to&&e.from==n.head&&e.insert.toString()==`
@@ -38,7 +38,7 @@ var nC=Object.defineProperty;var W=(s,t,e)=>()=>{if(e)throw e[0];try{return s&&(
38
38
  `?"":e;else{let r=e.indexOf(`
39
39
  `);i=r<0?e:e.slice(0,r)}return t+i.length>this.to?i.slice(0,this.to-t):i}prevLineEnd(){return this.atEnd?this.lineStart:this.lineStart-1}startContext(t,e,i=0){this.block=Tu.create(t,i,this.lineStart+e,this.block.hash,this.lineStart+this.line.text.length),this.stack.push(this.block)}startComposite(t,e,i=0){this.startContext(this.parser.getNodeType(t),e,i)}addNode(t,e,i){typeof t=="number"&&(t=new G(this.parser.nodeSet.types[t],lo,lo,(i??this.prevLineEnd())-e)),this.block.addChild(t,e-this.block.from)}addElement(t){this.block.addChild(t.toTree(this.parser.nodeSet),t.from-this.block.from)}addLeafElement(t,e){this.addNode(this.buffer.writeElements(Vg(e.children,t.marks),-e.from).finish(e.type,e.to-e.from),e.from)}finishContext(){let t=this.stack.pop(),e=this.stack[this.stack.length-1];e.addChild(t.toTree(this.parser.nodeSet),t.from-e.from),this.block=e}finish(){for(;this.stack.length>1;)this.finishContext();return this.addGaps(this.block.toTree(this.parser.nodeSet,this.lineStart))}addGaps(t){return this.ranges.length>1?ok(this.ranges,0,t.topNode,this.ranges[0].from,this.reusePlaceholders):t}finishLeaf(t){for(let i of t.parsers)if(i.finish(this,t))return;let e=Vg(this.parser.parseInline(t.content,t.start),t.marks);this.addNode(this.buffer.writeElements(e,-t.start).finish(M.Paragraph,t.content.length),t.start)}elt(t,e,i,r){return typeof t=="string"?st(this.parser.getNodeType(t),e,i,r):new Nu(t,e)}get buffer(){return new qu(this.parser.nodeSet)}};co=class s extends Ke{constructor(t,e,i,r,n,o,a,l,h){super(),this.nodeSet=t,this.blockParsers=e,this.leafBlockParsers=i,this.blockNames=r,this.endLeafBlock=n,this.skipContextMarkup=o,this.inlineParsers=a,this.inlineNames=l,this.wrappers=h,this.nodeTypes=Object.create(null);for(let c of t.types)this.nodeTypes[c.name]=c.id}createParse(t,e,i){let r=new Iu(this,t,e,i);for(let n of this.wrappers)r=n(r,t,e,i);return r}configure(t){let e=zg(t);if(!e)return this;let{nodeSet:i,skipContextMarkup:r}=this,n=this.blockParsers.slice(),o=this.leafBlockParsers.slice(),a=this.blockNames.slice(),l=this.inlineParsers.slice(),h=this.inlineNames.slice(),c=this.endLeafBlock.slice(),u=this.wrappers;if(Xl(e.defineNodes)){r=Object.assign({},r);let d=i.types.slice(),f;for(let p of e.defineNodes){let{name:m,block:b,composite:g,style:x}=typeof p=="string"?{name:p}:p;if(d.some(k=>k.name==m))continue;g&&(r[d.length]=(k,A,E)=>g(A,E,k.value));let S=d.length,w=g?["Block","BlockContext"]:b?S>=M.ATXHeading1&&S<=M.SetextHeading2?["Block","LeafBlock","Heading"]:["Block","LeafBlock"]:void 0;d.push(pt.define({id:S,name:m,props:w&&[[_.group,w]]})),x&&(f||(f={}),Array.isArray(x)||x instanceof de?f[m]=x:Object.assign(f,x))}i=new Ge(d),f&&(i=i.extend(It(f)))}if(Xl(e.props)&&(i=i.extend(...e.props)),Xl(e.remove))for(let d of e.remove){let f=this.blockNames.indexOf(d),p=this.inlineNames.indexOf(d);f>-1&&(n[f]=o[f]=void 0),p>-1&&(l[p]=void 0)}if(Xl(e.parseBlock))for(let d of e.parseBlock){let f=a.indexOf(d.name);if(f>-1)n[f]=d.parse,o[f]=d.leaf;else{let p=d.before?Du(a,d.before):d.after?Du(a,d.after)+1:a.length-1;n.splice(p,0,d.parse),o.splice(p,0,d.leaf),a.splice(p,0,d.name)}d.endLeaf&&c.push(d.endLeaf)}if(Xl(e.parseInline))for(let d of e.parseInline){let f=h.indexOf(d.name);if(f>-1)l[f]=d.parse;else{let p=d.before?Du(h,d.before):d.after?Du(h,d.after)+1:h.length-1;l.splice(p,0,d.parse),h.splice(p,0,d.name)}}return e.wrap&&(u=u.concat(e.wrap)),new s(i,n,o,a,c,r,l,h,u)}getNodeType(t){let e=this.nodeTypes[t];if(e==null)throw new RangeError(`Unknown node type '${t}'`);return e}parseInline(t,e){let i=new ho(this,t,e);t:for(let r=e;r<i.end;){let n=i.char(r);for(let o of this.inlineParsers)if(o){let a=o(i,n,r);if(a>=0){r=a;continue t}}r++}return i.resolveMarkers(0)}};ak=[pt.none];for(let s=1,t;t=M[s];s++)ak[s]=pt.define({id:s,name:t,props:s>=M.Escape?[]:[[_.group,s in Uw?["Block","BlockContext"]:["Block","LeafBlock"]]],top:t=="Document"});lo=[],qu=class{constructor(t){this.nodeSet=t,this.content=[],this.nodes=[]}write(t,e,i,r=0){return this.content.push(t,e,i,4+r*4),this}writeElements(t,e=0){for(let i of t)i.writeTo(this,e);return this}finish(t,e){return G.build({buffer:this.content,nodeSet:this.nodeSet,reused:this.nodes,topID:t,length:e})}},is=class{constructor(t,e,i,r=lo){this.type=t,this.from=e,this.to=i,this.children=r}writeTo(t,e){let i=t.content.length;t.writeElements(this.children,e),t.content.push(this.type,this.from+e,this.to+e,t.content.length+4-i)}toTree(t){return new qu(t).writeElements(this.children,-this.from).finish(this.type,this.to-this.from)}},Nu=class{constructor(t,e){this.tree=t,this.from=e}get to(){return this.from+this.tree.length}get type(){return this.tree.type.id}get children(){return lo}writeTo(t,e){t.nodes.push(this.tree),t.content.push(t.nodes.length-1,this.from+e,this.to+e,-1)}toTree(){return this.tree}};lk={resolve:"Emphasis",mark:"EmphasisMark"},hk={resolve:"Emphasis",mark:"EmphasisMark"},_s={},Xu={},ne=class{constructor(t,e,i,r){this.type=t,this.from=e,this.to=i,this.side=r}},ck="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",Bl=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;try{Bl=new RegExp("[\\p{S}|\\p{P}]","u")}catch{}_g={Escape(s,t,e){if(t!=92||e==s.end-1)return-1;let i=s.char(e+1);for(let r=0;r<ck.length;r++)if(ck.charCodeAt(r)==i)return s.append(st(M.Escape,e,e+2));return-1},Entity(s,t,e){if(t!=38)return-1;let i=/^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(s.slice(e+1,e+31));return i?s.append(st(M.Entity,e,e+1+i[0].length)):-1},InlineCode(s,t,e){if(t!=96||e&&s.char(e-1)==96)return-1;let i=e+1;for(;i<s.end&&s.char(i)==96;)i++;let r=i-e,n=0;for(;i<s.end;i++)if(s.char(i)==96){if(n++,n==r&&s.char(i+1)!=96)return s.append(st(M.InlineCode,e,i+1,[st(M.CodeMark,e,e+r),st(M.CodeMark,i+1-r,i+1)]))}else n=0;return-1},HTMLTag(s,t,e){if(t!=60||e==s.end-1)return-1;let i=s.slice(e+1,s.end),r=/^(?:[a-z][-\w+.]+:[^\s>]+|[a-z\d.!#$%&'*+/=?^_`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*)>/i.exec(i);if(r)return s.append(st(M.Autolink,e,e+1+r[0].length,[st(M.LinkMark,e,e+1),st(M.URL,e+1,e+r[0].length),st(M.LinkMark,e+r[0].length,e+1+r[0].length)]));let n=/^!--[^>](?:-[^-]|[^-])*?-->/i.exec(i);if(n)return s.append(st(M.Comment,e,e+1+n[0].length));let o=/^\?[^]*?\?>/.exec(i);if(o)return s.append(st(M.ProcessingInstruction,e,e+1+o[0].length));let a=/^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/\s*[a-zA-Z][\w-]*\s*>|\s*[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*(\/\s*)?>)/.exec(i);return a?s.append(st(M.HTMLTag,e,e+1+a[0].length)):-1},Emphasis(s,t,e){if(t!=95&&t!=42)return-1;let i=e+1;for(;s.char(i)==t;)i++;let r=s.slice(e-1,e),n=s.slice(i,i+1),o=Bl.test(r),a=Bl.test(n),l=/\s|^$/.test(r),h=/\s|^$/.test(n),c=!h&&(!a||l||o),u=!l&&(!o||h||a),d=c&&(t==42||!u||o),f=u&&(t==42||!c||a);return s.append(new ne(t==95?lk:hk,e,i,(d?1:0)|(f?2:0)))},HardBreak(s,t,e){if(t==92&&s.char(e+1)==10)return s.append(st(M.HardBreak,e,e+2));if(t==32){let i=e+1;for(;s.char(i)==32;)i++;if(s.char(i)==10&&i>=e+2)return s.append(st(M.HardBreak,e,i+1))}return-1},Link(s,t,e){return t==91?s.append(new ne(_s,e,e+1,1)):-1},Image(s,t,e){return t==33&&s.char(e+1)==91?s.append(new ne(Xu,e,e+2,1)):-1},LinkEnd(s,t,e){if(t!=93)return-1;for(let i=s.parts.length-1;i>=0;i--){let r=s.parts[i];if(r instanceof ne&&(r.type==_s||r.type==Xu)){if(!r.side||s.skipSpace(r.to)==e&&!/[(\[]/.test(s.slice(e+1,e+2)))return s.parts[i]=null,-1;let n=s.takeContent(i),o=s.parts[i]=SR(s,n,r.type==_s?M.Link:M.Image,r.from,e+1);if(r.type==_s)for(let a=0;a<i;a++){let l=s.parts[a];l instanceof ne&&l.type==_s&&(l.side=0)}return o.to}}return-1}};ho=class{constructor(t,e,i){this.parser=t,this.text=e,this.offset=i,this.parts=[]}char(t){return t>=this.end?-1:this.text.charCodeAt(t-this.offset)}get end(){return this.offset+this.text.length}slice(t,e){return this.text.slice(t-this.offset,e-this.offset)}append(t){return this.parts.push(t),t.to}addDelimiter(t,e,i,r,n){return this.append(new ne(t,e,i,(r?1:0)|(n?2:0)))}get hasOpenLink(){for(let t=this.parts.length-1;t>=0;t--){let e=this.parts[t];if(e instanceof ne&&(e.type==_s||e.type==Xu))return!0}return!1}addElement(t){return this.append(t)}resolveMarkers(t){for(let i=t;i<this.parts.length;i++){let r=this.parts[i];if(!(r instanceof ne&&r.type.resolve&&r.side&2))continue;let n=r.type==lk||r.type==hk,o=r.to-r.from,a,l=i-1;for(;l>=t;l--){let m=this.parts[l];if(m instanceof ne&&m.side&1&&m.type==r.type&&!(n&&(r.side&1||m.side&2)&&(m.to-m.from+o)%3==0&&((m.to-m.from)%3||o%3))){a=m;break}}if(!a)continue;let h=r.type.resolve,c=[],u=a.from,d=r.to;if(n){let m=Math.min(2,a.to-a.from,o);u=a.to-m,d=r.from+m,h=m==1?"Emphasis":"StrongEmphasis"}a.type.mark&&c.push(this.elt(a.type.mark,u,a.to));for(let m=l+1;m<i;m++)this.parts[m]instanceof is&&c.push(this.parts[m]),this.parts[m]=null;r.type.mark&&c.push(this.elt(r.type.mark,r.from,d));let f=this.elt(h,u,d,c);this.parts[l]=n&&a.from!=u?new ne(a.type,a.from,u,a.side):null,(this.parts[i]=n&&r.to!=d?new ne(r.type,d,r.to,r.side):null)?this.parts.splice(i,0,f):this.parts[i]=f}let e=[];for(let i=t;i<this.parts.length;i++){let r=this.parts[i];r instanceof is&&e.push(r)}return e}findOpeningDelimiter(t){for(let e=this.parts.length-1;e>=0;e--){let i=this.parts[e];if(i instanceof ne&&i.type==t&&i.side&1)return e}return null}takeContent(t){let e=this.resolveMarkers(t);return this.parts.length=t,e}getDelimiterAt(t){let e=this.parts[t];return e instanceof ne?e:null}skipSpace(t){return Nl(this.text,t-this.offset)+this.offset}elt(t,e,i,r){return typeof t=="string"?st(this.parser.getNodeType(t),e,i,r):new Nu(t,e)}};ho.linkStart=_s,ho.imageStart=Xu;wR=[M.CodeBlock,M.ListItem,M.OrderedList,M.BulletList],jg=class{constructor(t,e){this.fragments=t,this.input=e,this.i=0,this.fragment=null,this.fragmentEnd=-1,this.cursor=null,t.length&&(this.fragment=t[this.i++])}nextFragment(){this.fragment=this.i<this.fragments.length?this.fragments[this.i++]:null,this.cursor=null,this.fragmentEnd=-1}moveTo(t,e){for(;this.fragment&&this.fragment.to<=t;)this.nextFragment();if(!this.fragment||this.fragment.from>(t?t-1:0))return!1;if(this.fragmentEnd<0){let n=this.fragment.to;for(;n>0&&this.input.read(n-1,n)!=`
40
40
  `;)n--;this.fragmentEnd=n?n-1:0}let i=this.cursor;i||(i=this.cursor=this.fragment.tree.cursor(),i.firstChild());let r=t+this.fragment.offset;for(;i.to<=r;)if(!i.parent())return!1;for(;;){if(i.from>=r)return this.fragment.from<=e;if(!i.childAfter(r))return!1}}matches(t){let e=this.cursor.tree;return e&&e.prop(_.contextHash)==t}takeNodes(t){let e=this.cursor,i=this.fragment.offset,r=this.fragmentEnd-(this.fragment.openEnd?1:0),n=t.absoluteLineStart,o=n,a=t.block.children.length,l=o,h=a;for(;;){if(e.to-i>r){if(e.type.isAnonymous&&e.firstChild())continue;break}let c=pk(e.from-i,t.ranges);if(e.to-i<=t.ranges[t.rangeI].to)t.addNode(e.tree,c);else{let u=new G(t.parser.nodeSet.types[M.Paragraph],[],[],0,t.block.hashProp);t.reusePlaceholders.set(u,e.tree),t.addNode(u,c)}if(e.type.is("Block")&&(wR.indexOf(e.type.id)<0?(o=e.to-i,a=t.block.children.length):(o=l,a=h),l=e.to-i,h=t.block.children.length),!e.nextSibling())break}for(;t.block.children.length>a;)t.block.children.pop(),t.block.positions.pop();return o-n}};kR=It({"Blockquote/...":O.quote,HorizontalRule:O.contentSeparator,"ATXHeading1/... SetextHeading1/...":O.heading1,"ATXHeading2/... SetextHeading2/...":O.heading2,"ATXHeading3/...":O.heading3,"ATXHeading4/...":O.heading4,"ATXHeading5/...":O.heading5,"ATXHeading6/...":O.heading6,"Comment CommentBlock":O.comment,Escape:O.escape,Entity:O.character,"Emphasis/...":O.emphasis,"StrongEmphasis/...":O.strong,"Link/... Image/...":O.link,"OrderedList/... BulletList/...":O.list,"BlockQuote/...":O.quote,"InlineCode CodeText":O.monospace,"URL Autolink":O.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":O.processingInstruction,"CodeInfo LinkLabel":O.labelName,LinkTitle:O.string,Paragraph:O.content}),Fg=new co(new Ge(ak).extend(kR),Object.keys(Ru).map(s=>Ru[s]),Object.keys(Ru).map(s=>nk[s]),Object.keys(Ru),vR,Uw,Object.keys(_g).map(s=>_g[s]),Object.keys(_g),[]);ER={resolve:"Strikethrough",mark:"StrikethroughMark"},mk={defineNodes:[{name:"Strikethrough",style:{"Strikethrough/...":O.strikethrough}},{name:"StrikethroughMark",style:O.processingInstruction}],parseInline:[{name:"Strikethrough",parse(s,t,e){if(t!=126||s.char(e+1)!=126||s.char(e+2)==126)return-1;let i=s.slice(e-1,e),r=s.slice(e+2,e+3),n=/\s|^$/.test(i),o=/\s|^$/.test(r),a=Bl.test(i),l=Bl.test(r);return s.addDelimiter(ER,e,e+2,!o&&(!l||n||a),!n&&(!a||o||l))},after:"Emphasis"}]};bk=/^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/,Bu=class{constructor(){this.rows=null}nextLine(t,e,i){if(this.rows==null){this.rows=!1;let r;if((e.next==45||e.next==58||e.next==124)&&bk.test(r=e.text.slice(e.pos))){let n=[];Zl(t,i.content,0,n,i.start)==Zl(t,r,e.pos)&&(this.rows=[t.elt("TableHeader",i.start,i.start+i.content.length,n),t.elt("TableDelimiter",t.lineStart+e.pos,t.lineStart+e.text.length)])}}else if(this.rows){let r=[];Zl(t,e.text,e.pos,r,t.lineStart),this.rows.push(t.elt("TableRow",t.lineStart+e.pos,t.lineStart+e.text.length,r))}return!1}finish(t,e){return this.rows?(t.addLeafElement(e,t.elt("Table",e.start,e.start+e.content.length,this.rows)),!0):!1}},Ok={defineNodes:[{name:"Table",block:!0},{name:"TableHeader",style:{"TableHeader/...":O.heading}},"TableRow",{name:"TableCell",style:O.content},{name:"TableDelimiter",style:O.processingInstruction}],parseBlock:[{name:"Table",leaf(s,t){return gk(t.content,0)?new Bu:null},endLeaf(s,t,e){if(e.parsers.some(r=>r instanceof Bu)||!gk(t.text,t.basePos))return!1;let i=s.peekLine();return bk.test(i)&&Zl(s,t.text,t.basePos)==Zl(s,i,t.basePos)},before:"SetextHeading"}]},Wg=class{nextLine(){return!1}finish(t,e){return t.addLeafElement(e,t.elt("Task",e.start,e.start+e.content.length,[t.elt("TaskMarker",e.start,e.start+3),...t.parser.parseInline(e.content.slice(3),e.start+3)])),!0}},yk={defineNodes:[{name:"Task",block:!0,style:O.list},{name:"TaskMarker",style:O.atom}],parseBlock:[{name:"TaskList",leaf(s,t){return/^\[[ xX]\][ \t]/.test(t.content)&&s.parentType().name=="ListItem"?new Wg:null},after:"SetextHeading"}]},vk=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,xk=/[\w-]+(\.[\w-]+)+(\/[^\s<]*)?/gy,CR=/[\w-]+\.[\w-]+($|\/)/,Sk=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,wk=/\/[a-zA-Z\d@.]+/gy;Ek={parseInline:[{name:"Autolink",parse(s,t,e){let i=e-s.offset;if(i&&/\w/.test(s.text[i-1]))return-1;vk.lastIndex=i;let r=vk.exec(s.text),n=-1;if(!r)return-1;if(r[1]||r[2]){if(n=$R(s.text,i+r[0].length),n>-1&&s.hasOpenLink){let o=/([^\[\]]|\[[^\]]*\])*/.exec(s.text.slice(i,n));n=i+o[0].length}}else r[3]?n=Ak(s.text,i):(n=Ak(s.text,i+r[0].length),n>-1&&r[0]=="xmpp:"&&(wk.lastIndex=n,r=wk.exec(s.text),r&&(n=r.index+r[0].length)));return n<0?-1:(s.addElement(s.elt("URL",e,n+s.offset)),n+s.offset)}}]},Yg=[Ok,yk,mk,Ek];Hg={defineNodes:[{name:"Superscript",style:O.special(O.content)},{name:"SuperscriptMark",style:O.processingInstruction}],parseInline:[{name:"Superscript",parse:Ck(94,"Superscript","SuperscriptMark")}]},Gg={defineNodes:[{name:"Subscript",style:O.special(O.content)},{name:"SubscriptMark",style:O.processingInstruction}],parseInline:[{name:"Subscript",parse:Ck(126,"Subscript","SubscriptMark")}]},Kg={defineNodes:[{name:"Emoji",style:O.character}],parseInline:[{name:"Emoji",parse(s,t,e){let i;return t!=58||!(i=/^[a-zA-Z_0-9]+:/.exec(s.slice(e+1,s.end)))?-1:s.addElement(s.elt("Emoji",e,e+1+i[0].length))}}]}});var Nk={};Gt(Nk,{commonmarkLanguage:()=>rb,deleteMarkupBackward:()=>ab,insertNewlineContinueMarkup:()=>ob,insertNewlineContinueMarkupCommand:()=>nb,markdown:()=>qk,markdownKeymap:()=>lb,markdownLanguage:()=>uo,pasteURLAsLink:()=>hb});function Jg(s){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(s.name);return t?+t[1]:void 0}function PR(s){return s.name=="OrderedList"||s.name=="BulletList"}function QR(s,t){let e=s;for(;;){let i=e.nextSibling,r;if(!i||(r=Jg(i.type))!=null&&r<=t)break;e=i}return e.to}function tb(s){return new Lt(Pk,s,[],"markdown")}function MR(s,t){return e=>{if(e&&s){let i=null;if(e=/\S*/.exec(e)[0],typeof s=="function"?i=s(e):i=eo.matchLanguageName(s,e,!0),i instanceof eo)return i.support?i.support.language.parser:Ji.getSkippingParser(i.load());if(i)return i.parser}return t?t.parser:null}}function Lk(s,t){let e=[],i=[];for(let r=s;r;r=r.parent){if(r.name=="FencedCode")return i;(r.name=="ListItem"||r.name=="Blockquote")&&e.push(r)}for(let r=e.length-1;r>=0;r--){let n=e[r],o,a=t.lineAt(n.from),l=n.from-a.from;if(n.name=="Blockquote"&&(o=/^ *>( ?)/.exec(a.text.slice(l))))i.push(new zl(n,l,l+o[0].length,"",o[1],">",null));else if(n.name=="ListItem"&&n.parent.name=="OrderedList"&&(o=/^( *)\d+([.)])( *)/.exec(a.text.slice(l)))){let h=o[3],c=o[0].length;h.length>=4&&(h=h.slice(0,h.length-4),c-=4),i.push(new zl(n.parent,l,l+c,o[1],h,o[2],n))}else if(n.name=="ListItem"&&n.parent.name=="BulletList"&&(o=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(a.text.slice(l)))){let h=o[4],c=o[0].length;h.length>4&&(h=h.slice(0,h.length-4),c-=4);let u=o[2];o[3]&&(u+=o[3].replace(/[xX]/," ")),i.push(new zl(n.parent,l,l+c,o[1],h,u,n))}}return i}function Mk(s,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(s.from,s.from+10))}function eb(s,t,e,i=0){for(let r=-1,n=s;;){if(n.name=="ListItem"){let a=Mk(n,t),l=+a[2];if(r>=0){if(l!=r+1)return;e.push({from:n.from+a[1].length,to:n.from+a[0].length,insert:String(r+2+i)})}r=l}let o=n.nextSibling;if(!o)break;n=o}}function ib(s,t){let e=/^[ \t]*/.exec(s)[0].length;if(!e||t.facet(Qi)!=" ")return s;let i=jt(s,4,e),r="";for(let n=i;n>0;)n>=4?(r+=" ",n-=4):(r+=" ",n--);return r+s.slice(e)}function Rk(s){return s.name=="QuoteMark"||s.name=="ListMark"}function RR(s,t){if(s.name!="OrderedList"&&s.name!="BulletList")return!1;let e=s.firstChild,i=s.getChild("ListItem","ListItem");if(!i)return!1;let r=t.lineAt(e.to),n=t.lineAt(i.from),o=/^[\s>]*$/.test(r.text);return r.number+(o?0:1)<n.number}function Ik(s,t,e){let i="";for(let r=0,n=s.length-2;r<=n;r++)i+=s[r].blank(r<n?jt(e.text,4,s[r+1].from)-i.length:null,r<n);return ib(i,t)}function IR(s,t){let e=s.resolveInner(t,-1),i=t;Rk(e)&&(i=e.from,e=e.parent);for(let r;r=e.childBefore(i);)if(Rk(r))i=r.from;else if(r.name=="OrderedList"||r.name=="BulletList")e=r.lastChild,i=e.to;else break;return e}function qk(s={}){let{codeLanguages:t,defaultCodeLanguage:e,addKeymap:i=!0,base:{parser:r}=rb,completeHTMLTags:n=!0,pasteURLAsLink:o=!0,htmlTagLanguage:a=Dk}=s;if(!(r instanceof co))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let l=s.extensions?[s.extensions]:[],h=[a.support,TR],c;o&&h.push(hb),e instanceof St?(h.push(e.support),c=e.language):e&&(c=e);let u=t||c?MR(t,c):void 0;l.push(Ug({codeParser:u,htmlParser:a.language.parser})),i&&h.push(fe.high(ai.of(lb)));let d=tb(r.configure(l));return n&&h.push(d.data.of({autocomplete:DR})),new St(d,h)}function DR(s){let{state:t,pos:e}=s,i=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(e-25,e));if(!i)return null;let r=J(t).resolveInner(e,-1);for(;r&&!r.type.isTop;){if(r.name=="CodeBlock"||r.name=="FencedCode"||r.name=="ProcessingInstructionBlock"||r.name=="CommentBlock"||r.name=="Link"||r.name=="Image")return null;r=r.parent}return{from:e-i[0].length,to:e,options:qR(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}function qR(){if(sb)return sb;let s=Pu(new Zs(at.create({extensions:Dk}),0,!0));return sb=s?s.options:[]}var Pk,Qk,Tk,TR,rb,LR,uo,zl,nb,ob,ab,lb,Dk,sb,NR,hb,Xk=W(()=>{ri();ki();ci();yg();$k();Mg();_e();Pk=Ds({commentTokens:{block:{open:"<!--",close:"-->"}}}),Qk=new _,Tk=Fg.configure({props:[re.add(s=>!s.is("Block")||s.is("Document")||Jg(s)!=null||PR(s)?void 0:(t,e)=>({from:e.doc.lineAt(t.from).to,to:t.to})),Qk.add(Jg),se.add({Document:()=>null}),li.add({Document:Pk})]});TR=cu.of((s,t,e)=>{for(let i=J(s).resolveInner(e,-1);i&&!(i.from<t);i=i.parent){let r=i.type.prop(Qk);if(r==null)continue;let n=QR(i,r);if(n>e)return{from:e,to:n}}return null});rb=tb(Tk),LR=Tk.configure([Yg,Gg,Hg,Kg,{props:[re.add({Table:(s,t)=>({from:t.doc.lineAt(s.from).to,to:s.to})})]}]),uo=tb(LR);zl=class{constructor(t,e,i,r,n,o,a){this.node=t,this.from=e,this.to=i,this.spaceBefore=r,this.spaceAfter=n,this.type=o,this.item=a}blank(t,e=!0){let i=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(t!=null){for(;i.length<t;)i+=" ";return i}else{for(let r=this.to-this.from-i.length-this.spaceAfter.length;r>0;r--)i+=" ";return i+(e?this.spaceAfter:"")}}marker(t,e){let i=this.node.name=="OrderedList"?String(+Mk(this.item,t)[2]+e):"";return this.spaceBefore+i+this.type+this.spaceAfter}};nb=(s={})=>({state:t,dispatch:e})=>{let i=J(t),{doc:r}=t,n=null,o=t.changeByRange(a=>{if(!a.empty||!uo.isActiveAt(t,a.from,-1)&&!uo.isActiveAt(t,a.from,1))return n={range:a};let l=a.from,h=r.lineAt(l),c=Lk(i.resolveInner(l,-1),r);for(;c.length&&c[c.length-1].from>l-h.from;)c.pop();if(!c.length)return n={range:a};let u=c[c.length-1];if(u.to-u.spaceAfter.length>l-h.from)return n={range:a};let d=l>=u.to-u.spaceAfter.length&&!/\S/.test(h.text.slice(u.to));if(u.item&&d){let g=u.node.firstChild,x=u.node.getChild("ListItem","ListItem");if(g.to>=l||x&&x.to<l||h.from>0&&!/[^\s>]/.test(r.lineAt(h.from-1).text)||s.nonTightLists===!1){let S=c.length>1?c[c.length-2]:null,w,k="";S&&S.item?(w=h.from+S.from,k=S.marker(r,1)):w=h.from+(S?S.to:0);let A=[{from:w,to:l,insert:k}];return u.node.name=="OrderedList"&&eb(u.item,r,A,-2),S&&S.node.name=="OrderedList"&&eb(S.item,r,A),{range:Q.cursor(w+k.length),changes:A}}else{let S=Ik(c,t,h);return{range:Q.cursor(l+S.length+1),changes:{from:h.from,insert:S+t.lineBreak}}}}if(u.node.name=="Blockquote"&&d&&h.from){let g=r.lineAt(h.from-1),x=/>\s*$/.exec(g.text);if(x&&x.index==u.from){let S=t.changes([{from:g.from+x.index,to:g.to},{from:h.from+u.from,to:h.to}]);return{range:a.map(S),changes:S}}}let f=[];u.node.name=="OrderedList"&&eb(u.item,r,f);let p=u.item&&u.item.from<h.from,m="";if(!p||/^[\s\d.)\-+*>]*/.exec(h.text)[0].length>=u.to)for(let g=0,x=c.length-1;g<=x;g++)m+=g==x&&!p?c[g].marker(r,1):c[g].blank(g<x?jt(h.text,4,c[g+1].from)-m.length:null);let b=l;for(;b>h.from&&/\s/.test(h.text.charAt(b-h.from-1));)b--;return m=ib(m,t),RR(u.node,t.doc)&&(m=Ik(c,t,h)+t.lineBreak+m),f.push({from:b,to:l,insert:t.lineBreak+m}),{range:Q.cursor(b+m.length+1),changes:f}});return n?!1:(e(t.update(o,{scrollIntoView:!0,userEvent:"input"})),!0)},ob=nb();ab=({state:s,dispatch:t})=>{let e=J(s),i=null,r=s.changeByRange(n=>{let o=n.from,{doc:a}=s;if(n.empty&&uo.isActiveAt(s,n.from)){let l=a.lineAt(o),h=Lk(IR(e,o),a);if(h.length){let c=h[h.length-1],u=c.to-c.spaceAfter.length+(c.spaceAfter?1:0);if(o-l.from>u&&!/\S/.test(l.text.slice(u,o-l.from)))return{range:Q.cursor(l.from+u),changes:{from:l.from+u,to:o}};if(o-l.from==u&&(!c.item||l.from<=c.item.from||!/\S/.test(l.text.slice(0,c.to)))){let d=l.from+c.from;if(c.item&&c.node.from<c.item.from&&/\S/.test(l.text.slice(c.from,c.to))){let f=c.blank(jt(l.text,4,c.to)-jt(l.text,4,c.from));return d==l.from&&(f=ib(f,s)),{range:Q.cursor(d+f.length),changes:{from:d,to:l.from+c.to,insert:f}}}if(d<o)return{range:Q.cursor(d),changes:{from:d,to:o}}}}}return i={range:n}});return i?!1:(t(s.update(r,{scrollIntoView:!0,userEvent:"delete"})),!0)},lb=[{key:"Enter",run:ob},{key:"Backspace",run:ab}],Dk=Qu({matchClosingTags:!1});sb=null;NR=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,hb=D.domEventHandlers({paste:(s,t)=>{var e;let{main:i}=t.state.selection;if(i.empty)return!1;let r=(e=s.clipboardData)===null||e===void 0?void 0:e.getData("text/plain");if(!r||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(r)||(/^www\./.test(r)&&(r="https://"+r),!uo.isActiveAt(t.state,i.from,1)))return!1;let n=J(t.state),o=!1;return n.iterate({from:i.from,to:i.to,enter:a=>{(a.from>i.from||NR.test(a.name))&&(o=!0)},leave:a=>{a.to<i.to&&(o=!0)}}),o?!1:(t.dispatch({changes:[{from:i.from,insert:"["},{from:i.to,insert:`](${r})`}],userEvent:"input.paste",scrollIntoView:!0}),!0)}})});function Vl(s,t){for(let e=0,i=t-s.pos-1;;i--,e++){let r=s.peek(i);if(Ii(r)||r==-1)return e}}function fb(s){return s==32||s==9}function Ii(s){return s==10||s==13}function jk(s){return fb(s)||Ii(s)}function Vs(s){return s<0||jk(s)}function po(s,t,e=0){return s.peek(e)==t&&s.peek(e+1)==t&&s.peek(e+2)==t&&Vs(s.peek(e+3))}function oI(s){return s>32&&s<127&&s!=34&&s!=37&&s!=44&&s!=60&&s!=62&&s!=92&&s!=94&&s!=96&&s!=123&&s!=124&&s!=125}function Wk(s){return s>=48&&s<=57||s>=97&&s<=102||s>=65&&s<=70}function Fk(s,t){return s.next==37?(s.advance(),Wk(s.next)&&s.advance(),Wk(s.next)&&s.advance(),!0):oI(s.next)||t&&s.next==44?(s.advance(),!0):!1}function Uk(s){if(s.advance(),s.next==60){for(s.advance();;)if(!Fk(s,!0)){s.next==62&&s.advance();break}}else for(;Fk(s,!1););}function pb(s){for(s.advance();!Vs(s.next)&&Zu(s.next)!="f";)s.advance()}function mb(s,t){let e=s.next,i=!1,r=s.pos;for(s.advance();;){let n=s.next;if(n<0)break;if(s.advance(),n==e)if(n==39)if(s.next==39)s.advance();else break;else break;else if(n==92&&e==34)s.next>=0&&s.advance();else if(Ii(n)){if(t)return!1;i=!0}else if(t&&s.pos>=r+1024)return!1}return!i}function aI(s){for(let t=[],e=s.pos+1024;;)if(s.next==91||s.next==123)t.push(s.next),s.advance();else if(s.next==39||s.next==34){if(!mb(s,!0))return!1}else if(s.next==93||s.next==125){if(t[t.length-1]!=s.next-2)return!1;if(t.pop(),s.advance(),!t.length)return!0}else{if(s.next<0||s.pos>e||Ii(s.next))return!1;s.advance()}}function Zu(s){return s<33?"u":s>125?"s":lI[s-33]}function gb(s,t){let e=Zu(s);return e!="u"&&!(t&&e=="f")}function Yk(s,t,e,i){if(Zu(s.next)=="s"||(s.next==63||s.next==58||s.next==45)&&gb(s.peek(1),e))s.advance();else return!1;let r=s.pos;for(;;){let n=s.next,o=0,a=i+1;for(;jk(n);){if(Ii(n)){if(t)return!1;a=0}else a++;n=s.peek(++o)}if(!(n>=0&&(n==58?gb(s.peek(o+1),e):n==35?s.peek(o-1)!=32:gb(n,e)))||!e&&a<=i||a==0&&!e&&(po(s,45,o)||po(s,46,o)))break;if(t&&Zu(n)=="f")return!1;for(let h=o;h>=0;h--)s.advance();if(t&&s.pos>r+1024)return!1}return!0}var fo,Bk,XR,BR,Zk,ZR,zk,zR,_R,_k,VR,jR,WR,FR,UR,YR,Vk,HR,GR,KR,JR,tI,eI,iI,cb,ub,_l,db,Ri,sI,rI,nI,lI,hI,cI,uI,bb,Hk=W(()=>{ys();ii();fo=63,Bk=64,XR=1,BR=2,Zk=3,ZR=4,zk=5,zR=6,_R=7,_k=65,VR=66,jR=8,WR=9,FR=10,UR=11,YR=12,Vk=13,HR=19,GR=20,KR=29,JR=33,tI=34,eI=47,iI=0,cb=1,ub=2,_l=3,db=4,Ri=class{constructor(t,e,i){this.parent=t,this.depth=e,this.type=i,this.hash=(t?t.hash+t.hash<<8:0)+e+(e<<4)+i}};Ri.top=new Ri(null,-1,iI);sI=new yi({start:Ri.top,reduce(s,t){return s.type==_l&&(t==GR||t==tI)?s.parent:s},shift(s,t,e,i){if(t==Zk)return new Ri(s,Vl(i,i.pos),cb);if(t==_k||t==zk)return new Ri(s,Vl(i,i.pos),ub);if(t==fo)return s.parent;if(t==HR||t==JR)return new Ri(s,0,_l);if(t==Vk&&s.type==db)return s.parent;if(t==eI){let r=/[1-9]/.exec(i.read(i.pos,e.pos));if(r)return new Ri(s,s.depth+ +r[0],db)}return s},hash(s){return s.hash}});rI=new mt((s,t)=>{if(s.next==-1&&t.canShift(Bk))return s.acceptToken(Bk);let e=s.peek(-1);if((Ii(e)||e<0)&&t.context.type!=_l){if(po(s,45))if(t.canShift(fo))s.acceptToken(fo);else return s.acceptToken(XR,3);if(po(s,46))if(t.canShift(fo))s.acceptToken(fo);else return s.acceptToken(BR,3);let i=0;for(;s.next==32;)i++,s.advance();(i<t.context.depth||i==t.context.depth&&t.context.type==cb&&(s.next!=45||!Vs(s.peek(1))))&&s.next!=-1&&!Ii(s.next)&&s.next!=35&&s.acceptToken(fo,-i)}},{contextual:!0}),nI=new mt((s,t)=>{if(t.context.type==_l){s.next==63&&(s.advance(),Vs(s.next)&&s.acceptToken(_R));return}if(s.next==45)s.advance(),Vs(s.next)&&s.acceptToken(t.context.type==cb&&t.context.depth==Vl(s,s.pos-1)?ZR:Zk);else if(s.next==63)s.advance(),Vs(s.next)&&s.acceptToken(t.context.type==ub&&t.context.depth==Vl(s,s.pos-1)?zR:zk);else{let e=s.pos;for(;;)if(fb(s.next)){if(s.pos==e)return;s.advance()}else if(s.next==33)Uk(s);else if(s.next==38)pb(s);else if(s.next==42){pb(s);break}else if(s.next==39||s.next==34){if(mb(s,!0))break;return}else if(s.next==91||s.next==123){if(!aI(s))return;break}else{Yk(s,!0,!1,0);break}for(;fb(s.next);)s.advance();if(s.next==58){if(s.pos==e&&t.canShift(KR))return;let i=s.peek(1);Vs(i)&&s.acceptTokenTo(t.context.type==ub&&t.context.depth==Vl(s,e)?VR:_k,e)}}},{contextual:!0});lI="iiisiiissisfissssssssssssisssiiissssssssssssssssssssssssssfsfssissssssssssssssssssssssssssfif";hI=new mt((s,t)=>{if(s.next==33)Uk(s),s.acceptToken(YR);else if(s.next==38||s.next==42){let e=s.next==38?FR:UR;pb(s),s.acceptToken(e)}else s.next==39||s.next==34?(mb(s,!1),s.acceptToken(WR)):Yk(s,!1,t.context.type==_l,t.context.depth)&&s.acceptToken(jR)}),cI=new mt((s,t)=>{let e=t.context.type==db?t.context.depth:-1,i=s.pos;t:for(;;){let r=0,n=s.next;for(;n==32;)n=s.peek(++r);if(!r&&(po(s,45,r)||po(s,46,r))||!Ii(n)&&(e<0&&(e=Math.max(t.context.depth+1,r)),r<e))break;for(;;){if(s.next<0)break t;let o=Ii(s.next);if(s.advance(),o)continue t;i=s.pos}}s.acceptTokenTo(Vk,i)}),uI=It({DirectiveName:O.keyword,DirectiveContent:O.attributeValue,"DirectiveEnd DocEnd":O.meta,QuotedLiteral:O.string,BlockLiteralHeader:O.special(O.string),BlockLiteralContent:O.content,Literal:O.content,"Key/Literal Key/QuotedLiteral":O.definition(O.propertyName),"Anchor Alias":O.labelName,Tag:O.typeName,Comment:O.lineComment,": , -":O.separator,"?":O.punctuation,"[ ]":O.squareBracket,"{ }":O.brace}),bb=Kt.deserialize({version:14,states:"5lQ!ZQgOOO#PQfO'#CpO#uQfO'#DOOOQR'#Dv'#DvO$qQgO'#DRO%gQdO'#DUO%nQgO'#DUO&ROaO'#D[OOQR'#Du'#DuO&{QgO'#D^O'rQgO'#D`OOQR'#Dt'#DtO(iOqO'#DbOOQP'#Dj'#DjO(zQaO'#CmO)YQgO'#CmOOQP'#Cm'#CmQ)jQaOOQ)uQgOOQ]QgOOO*PQdO'#CrO*nQdO'#CtOOQO'#Dw'#DwO+]Q`O'#CxO+hQdO'#CwO+rQ`O'#CwOOQO'#Cv'#CvO+wQdO'#CvOOQO'#Cq'#CqO,UQ`O,59[O,^QfO,59[OOQR,59[,59[OOQO'#Cx'#CxO,eQ`O'#DPO,pQdO'#DPOOQO'#Dx'#DxO,zQdO'#DxO-XQ`O,59jO-aQfO,59jOOQR,59j,59jOOQR'#DS'#DSO-hQcO,59mO-sQgO'#DVO.TQ`O'#DVO.YQcO,59pOOQR'#DX'#DXO#|QfO'#DWO.hQcO'#DWOOQR,59v,59vO.yOWO,59vO/OOaO,59vO/WOaO,59vO/cQgO'#D_OOQR,59x,59xO0VQgO'#DaOOQR,59z,59zOOQP,59|,59|O0yOaO,59|O1ROaO,59|O1aOqO,59|OOQP-E7h-E7hO1oQgO,59XOOQP,59X,59XO2PQaO'#DeO2_QgO'#DeO2oQgO'#DkOOQP'#Dk'#DkQ)jQaOOO3PQdO'#CsOOQO,59^,59^O3kQdO'#CuOOQO,59`,59`OOQO,59c,59cO4VQdO,59cO4aQdO'#CzO4kQ`O'#CzOOQO,59b,59bOOQU,5:Q,5:QOOQR1G.v1G.vO4pQ`O1G.vOOQU-E7d-E7dO4xQdO,59kOOQO,59k,59kO5SQdO'#DQO5^Q`O'#DQOOQO,5:d,5:dOOQU,5:R,5:ROOQR1G/U1G/UO5cQ`O1G/UOOQU-E7e-E7eO5kQgO'#DhO5xQcO1G/XOOQR1G/X1G/XOOQR,59q,59qO6TQgO,59qO6eQdO'#DiO6lQgO'#DiO7PQcO1G/[OOQR1G/[1G/[OOQR,59r,59rO#|QfO,59rOOQR1G/b1G/bO7_OWO1G/bO7dOaO1G/bOOQR,59y,59yOOQR,59{,59{OOQP1G/h1G/hO7lOaO1G/hO7tOaO1G/hO8POaO1G/hOOQP1G.s1G.sO8_QgO,5:POOQP,5:P,5:POOQP,5:V,5:VOOQP-E7i-E7iOOQO,59_,59_OOQO,59a,59aOOQO1G.}1G.}OOQO,59f,59fO8oQdO,59fOOQR7+$b7+$bP,XQ`O'#DfOOQO1G/V1G/VOOQO,59l,59lO8yQdO,59lOOQR7+$p7+$pP9TQ`O'#DgOOQR'#DT'#DTOOQR,5:S,5:SOOQR-E7f-E7fOOQR7+$s7+$sOOQR1G/]1G/]O9YQgO'#DYO9jQ`O'#DYOOQR,5:T,5:TO#|QfO'#DZO9oQcO'#DZOOQR-E7g-E7gOOQR7+$v7+$vOOQR1G/^1G/^OOQR7+$|7+$|O:QOWO7+$|OOQP7+%S7+%SO:VOaO7+%SO:_OaO7+%SOOQP1G/k1G/kOOQO1G/Q1G/QOOQO1G/W1G/WOOQR,59t,59tO:jQgO,59tOOQR,59u,59uO#|QfO,59uOOQR<<Hh<<HhOOQP<<Hn<<HnO:zOaO<<HnOOQR1G/`1G/`OOQR1G/a1G/aOOQPAN>YAN>Y",stateData:";S~O!fOS!gOS^OS~OP_OQbORSOTUOWROXROYYOZZO[XOcPOqQO!PVO!V[O!cTO~O`cO~P]OVkOWROXROYeOZfO[dOcPOmhOqQO~OboO~P!bOVtOWROXROYeOZfO[dOcPOmrOqQO~OpwO~P#WORSOTUOWROXROYYOZZO[XOcPOqQO!PVO!cTO~OSvP!avP!bvP~P#|OWROXROYeOZfO[dOcPOqQO~OmzO~P%OOm!OOUzP!azP!bzP!dzP~P#|O^!SO!b!QO!f!TO!g!RO~ORSOTUOWROXROcPOqQO!PVO!cTO~OY!UOP!QXQ!QX!V!QX!`!QXS!QX!a!QX!b!QXU!QXm!QX!d!QX~P&aO[!WOP!SXQ!SX!V!SX!`!SXS!SX!a!SX!b!SXU!SXm!SX!d!SX~P&aO^!ZO!W![O!b!YO!f!]O!g!YO~OP!_O!V[OQaX!`aX~OPaXQaX!VaX!`aX~P#|OP!bOQ!cO!V[O~OP_O!V[O~P#|OWROXROY!fOcPOqQObfXmfXofXpfX~OWROXRO[!hOcPOqQObhXmhXohXphX~ObeXmlXoeX~ObkXokX~P%OOm!kO~Om!lObnPonP~P%OOb!pOo!oO~Ob!pO~P!bOm!sOosXpsX~OosXpsX~P%OOm!uOotPptP~P%OOo!xOp!yO~Op!yO~P#WOS!|O!a#OO!b#OO~OUyX!ayX!byX!dyX~P#|Om#QO~OU#SO!a#UO!b#UO!d#RO~Om#WOUzX!azX!bzX!dzX~O]#XO~O!b#XO!g#YO~O^#ZO!b#XO!g#YO~OP!RXQ!RX!V!RX!`!RXS!RX!a!RX!b!RXU!RXm!RX!d!RX~P&aOP!TXQ!TX!V!TX!`!TXS!TX!a!TX!b!TXU!TXm!TX!d!TX~P&aO!b#^O!g#^O~O^#_O!b#^O!f#`O!g#^O~O^#_O!W#aO!b#^O!g#^O~OPaaQaa!Vaa!`aa~P#|OP#cO!V[OQ!XX!`!XX~OP!XXQ!XX!V!XX!`!XX~P#|OP_O!V[OQ!_X!`!_X~P#|OWROXROcPOqQObgXmgXogXpgX~OWROXROcPOqQObiXmiXoiXpiX~Obkaoka~P%OObnXonX~P%OOm#kO~Ob#lOo!oO~Oosapsa~P%OOotXptX~P%OOm#pO~Oo!xOp#qO~OSwP!awP!bwP~P#|OS!|O!a#vO!b#vO~OUya!aya!bya!dya~P#|Om#xO~P%OOm#{OU}P!a}P!b}P!d}P~P#|OU#SO!a$OO!b$OO!d#RO~O]$QO~O!b$QO!g$RO~O!b$SO!g$SO~O^$TO!b$SO!g$SO~O^$TO!b$SO!f$UO!g$SO~OP!XaQ!Xa!V!Xa!`!Xa~P#|Obnaona~P%OOotapta~P%OOo!xO~OU|X!a|X!b|X!d|X~P#|Om$ZO~Om$]OU}X!a}X!b}X!d}X~O]$^O~O!b$_O!g$_O~O^$`O!b$_O!g$_O~OU|a!a|a!b|a!d|a~P#|O!b$cO!g$cO~O",goto:",]!mPPPPPPPPPPPPPPPPP!nPP!v#v#|$`#|$c$f$j$nP%VPPP!v%Y%^%a%{&O%a&R&U&X&_&b%aP&e&{&e'O'RPP']'a'g'm's'y(XPPPPPPPP(_)e*X+c,VUaObcR#e!c!{ROPQSTUXY_bcdehknrtvz!O!U!W!_!b!c!f!h!k!l!s!u!|#Q#R#S#W#c#k#p#x#{$Z$]QmPR!qnqfPQThknrtv!k!l!s!u#R#k#pR!gdR!ieTlPnTjPnSiPnSqQvQ{TQ!mkQ!trQ!vtR#y#RR!nkTsQvR!wt!RWOSUXY_bcz!O!U!W!_!b!c!|#Q#S#W#c#x#{$Z$]RySR#t!|R|TR|UQ!PUR#|#SR#z#RR#z#SyZOSU_bcz!O!_!b!c!|#Q#S#W#c#x#{$Z$]R!VXR!XYa]O^abc!a!c!eT!da!eQnPR!rnQvQR!{vQ!}yR#u!}Q#T|R#}#TW^Obc!cS!^^!aT!aa!eQ!eaR#f!eW`Obc!cQxSS}U#SQ!`_Q#PzQ#V!OQ#b!_Q#d!bQ#s!|Q#w#QQ$P#WQ$V#cQ$Y#xQ$[#{Q$a$ZR$b$]xZOSU_bcz!O!_!b!c!|#Q#S#W#c#x#{$Z$]Q!VXQ!XYQ#[!UR#]!W!QWOSUXY_bcz!O!U!W!_!b!c!|#Q#S#W#c#x#{$Z$]pfPQThknrtv!k!l!s!u#R#k#pQ!gdQ!ieQ#g!fR#h!hSgPn^pQTkrtv#RQ!jhQ#i!kQ#j!lQ#n!sQ#o!uQ$W#kR$X#pQuQR!zv",nodeNames:"\u26A0 DirectiveEnd DocEnd - - ? ? ? Literal QuotedLiteral Anchor Alias Tag BlockLiteralContent Comment Stream BOM Document ] [ FlowSequence Item Tagged Anchored Anchored Tagged FlowMapping Pair Key : Pair , } { FlowMapping Pair Pair BlockSequence Item Item BlockMapping Pair Pair Key Pair Pair BlockLiteral BlockLiteralHeader Tagged Anchored Anchored Tagged Directive DirectiveName DirectiveContent Document",maxTerm:74,context:sI,nodeProps:[["isolate",-3,8,9,14,""],["openedBy",18,"[",32,"{"],["closedBy",19,"]",33,"}"]],propSources:[uI],skippedNodes:[0],repeatNodeCount:6,tokenData:"-Y~RnOX#PXY$QYZ$]Z]#P]^$]^p#Ppq$Qqs#Pst$btu#Puv$yv|#P|}&e}![#P![!]'O!]!`#P!`!a'i!a!}#P!}#O*g#O#P#P#P#Q+Q#Q#o#P#o#p+k#p#q'i#q#r,U#r;'S#P;'S;=`#z<%l?HT#P?HT?HU,o?HUO#PQ#UU!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PQ#kTOY#PZs#Pt;'S#P;'S;=`#z<%lO#PQ#}P;=`<%l#P~$VQ!f~XY$Qpq$Q~$bO!g~~$gS^~OY$bZ;'S$b;'S;=`$s<%lO$b~$vP;=`<%l$bR%OX!WQOX%kXY#PZ]%k]^#P^p%kpq#hq;'S%k;'S;=`&_<%lO%kR%rX!WQ!VPOX%kXY#PZ]%k]^#P^p%kpq#hq;'S%k;'S;=`&_<%lO%kR&bP;=`<%l%kR&lUoP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR'VUmP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR'p[!PP!WQOY#PZp#Ppq#hq{#P{|(f|}#P}!O(f!O!R#P!R![)p![;'S#P;'S;=`#z<%lO#PR(mW!PP!WQOY#PZp#Ppq#hq!R#P!R![)V![;'S#P;'S;=`#z<%lO#PR)^U!PP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR)wY!PP!WQOY#PZp#Ppq#hq{#P{|)V|}#P}!O)V!O;'S#P;'S;=`#z<%lO#PR*nUcP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR+XUbP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR+rUqP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR,]UpP!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#PR,vU`P!WQOY#PZp#Ppq#hq;'S#P;'S;=`#z<%lO#P",tokenizers:[rI,nI,hI,cI,0,1],topRules:{Stream:[0,15]},tokenPrec:0})});var Jk={};Gt(Jk,{yaml:()=>Gk,yamlFrontmatter:()=>Kk,yamlLanguage:()=>zu});function Gk(){return new St(zu)}function Kk(s){let{language:t,support:e}=s.content instanceof St?s.content:{language:s.content,support:[]};return new St(fI.configure({wrap:Os(i=>i.name=="FrontmatterContent"?{parser:zu.parser}:i.name=="Body"?{parser:t.parser}:null)}),e)}var dI,zu,fI,tA=W(()=>{Hk();ci();_e();ii();ys();dI=Kt.deserialize({version:14,states:"!vOQOPOOO]OPO'#C_OhOPO'#C^OOOO'#Cc'#CcOpOPO'#CaQOOOOOO{OPOOOOOO'#Cb'#CbO!WOPO'#C`O!`OPO,58xOOOO-E6a-E6aOOOO-E6`-E6`OOOO'#C_'#C_OOOO1G.d1G.d",stateData:"!h~OXPOYROWTP~OWVXXRXYRX~OYVOXSP~OXROYROWTX~OXROYROWTP~OYVOXSX~OX[O~OXY~",goto:"vWPPX[beioRUOQQOR]XRXQTTOUQWQRZWSSOURYS",nodeNames:"\u26A0 Document Frontmatter DashLine FrontmatterContent Body",maxTerm:10,skippedNodes:[0],repeatNodeCount:2,tokenData:"$z~RXOYnYZ!^Z]n]^!^^}n}!O!i!O;'Sn;'S;=`!c<%lOn~qXOYnYZ!^Z]n]^!^^;'Sn;'S;=`!c<%l~n~On~~!^~!cOY~~!fP;=`<%ln~!lZOYnYZ!^Z]n]^!^^}n}!O#_!O;'Sn;'S;=`!c<%l~n~On~~!^~#bZOYnYZ!^Z]n]^!^^}n}!O$T!O;'Sn;'S;=`!c<%l~n~On~~!^~$WXOYnYZ$sZ]n]^$s^;'Sn;'S;=`!c<%l~n~On~~$s~$zOX~Y~",tokenizers:[0],topRules:{Document:[0,1]},tokenPrec:67}),zu=be.define({name:"yaml",parser:bb.configure({props:[se.add({Stream:s=>{for(let t=s.node.resolve(s.pos,-1);t&&t.to>=s.pos;t=t.parent){if(t.name=="BlockLiteralContent"&&t.from<t.to)return s.baseIndentFor(t);if(t.name=="BlockLiteral")return s.baseIndentFor(t)+s.unit;if(t.name=="BlockSequence"||t.name=="BlockMapping")return s.column(t.firstChild.from,1);if(t.name=="QuotedLiteral")return null;if(t.name=="Literal"){let e=s.column(t.from,1);if(e==s.lineIndent(t.from,1))return e;if(t.to>s.pos)return null}}return null},FlowMapping:so({closing:"}"}),FlowSequence:so({closing:"]"})}),re.add({"FlowMapping FlowSequence":Ti,"Item Pair BlockLiteral":(s,t)=>({from:t.doc.lineAt(s.from).to,to:s.to})})]}),languageData:{commentTokens:{line:"#"},indentOnInput:/^\s*[\]\}]$/}});fI=be.define({name:"yaml-frontmatter",parser:dI.configure({props:[It({DashLine:O.meta})]})})});function js(s,t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let r=s(t,e);return r?(i(e.update(r)),!0):!1}}function Ob(s,t){let e=s.languageDataAt("commentTokens",t,1);return e.length?e[0]:{}}function OI(s,{open:t,close:e},i,r){let n=s.sliceDoc(i-jl,i),o=s.sliceDoc(r,r+jl),a=/\s*$/.exec(n)[0].length,l=/^\s*/.exec(o)[0].length,h=n.length-a;if(n.slice(h-t.length,h)==t&&o.slice(l,l+e.length)==e)return{open:{pos:i-a,margin:a&&1},close:{pos:r+l,margin:l&&1}};let c,u;r-i<=2*jl?c=u=s.sliceDoc(i,r):(c=s.sliceDoc(i,i+jl),u=s.sliceDoc(r-jl,r));let d=/^\s*/.exec(c)[0].length,f=/\s*$/.exec(u)[0].length,p=u.length-f-e.length;return c.slice(d,d+t.length)==t&&u.slice(p,p+e.length)==e?{open:{pos:i+d+t.length,margin:/\s/.test(c.charAt(d+t.length))?1:0},close:{pos:r-f-e.length,margin:/\s/.test(u.charAt(p-1))?1:0}}:null}function yI(s){let t=[];for(let e of s.selection.ranges){let i=s.doc.lineAt(e.from),r=e.to<=i.to?i:s.doc.lineAt(e.to);r.from>i.from&&r.from==e.to&&(r=e.to==i.to+1?i:s.doc.lineAt(e.to-1));let n=t.length-1;n>=0&&t[n].to>i.from?t[n].to=r.to:t.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:r.to})}return t}function _u(s,t,e=t.selection.ranges){let i=e.map(n=>Ob(t,n.from).block);if(!i.every(n=>n))return null;let r=e.map((n,o)=>OI(t,i[o],n.from,n.to));if(s!=2&&!r.every(n=>n))return{changes:t.changes(e.map((n,o)=>r[o]?[]:[{from:n.from,insert:i[o].open+" "},{from:n.to,insert:" "+i[o].close}]))};if(s!=1&&r.some(n=>n)){let n=[];for(let o=0,a;o<r.length;o++)if(a=r[o]){let l=i[o],{open:h,close:c}=a;n.push({from:h.pos-l.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+l.close.length})}return{changes:n}}return null}function yb(s,t,e=t.selection.ranges){let i=[],r=-1;t:for(let{from:n,to:o}of e){let a=i.length,l=1e9,h;for(let c=n;c<=o;){let u=t.doc.lineAt(c);if(h==null&&(h=Ob(t,u.from).line,!h))continue t;if(u.from>r&&(n==o||o>u.from)){r=u.from;let d=/^\s*/.exec(u.text)[0].length,f=d==u.length,p=u.text.slice(d,d+h.length)==h?d:-1;d<u.text.length&&d<l&&(l=d),i.push({line:u,comment:p,token:h,indent:d,empty:f,single:!1})}c=u.to+1}if(l<1e9)for(let c=a;c<i.length;c++)i[c].indent<i[c].line.text.length&&(i[c].indent=l);i.length==a+1&&(i[a].single=!0)}if(s!=2&&i.some(n=>n.comment<0&&(!n.empty||n.single))){let n=[];for(let{line:a,token:l,indent:h,empty:c,single:u}of i)(u||!c)&&n.push({from:a.from+h,insert:l+" "});let o=t.changes(n);return{changes:o,selection:t.selection.map(o,1)}}else if(s!=1&&i.some(n=>n.comment>=0)){let n=[];for(let{line:o,comment:a,token:l}of i)if(a>=0){let h=o.from+a,c=h+l.length;o.text[c-o.from]==" "&&c++,n.push({from:h,to:c})}return{changes:n}}return null}function rd(s={}){return[Vu,aA.of(s),D.domEventHandlers({beforeinput(t,e){let i=t.inputType=="historyUndo"?xb:t.inputType=="historyRedo"?Wu:null;return i?(t.preventDefault(),i(e)):!1}})]}function ju(s,t){return function({state:e,dispatch:i}){if(!t&&e.readOnly)return!1;let r=e.field(Vu,!1);if(!r)return!1;let n=r.pop(s,e,t);return n?(i(n),!0):!1}}function cA(s){return function(t){let e=t.field(Vu,!1);if(!e)return 0;let i=s==0?e.done:e.undone;return i.length-(i.length&&!i[0].changes?1:0)}}function Fu(s,t,e,i){let r=t+1>e+20?t-e-1:0,n=s.slice(r,t);return n.push(i),n}function wI(s,t){let e=[],i=!1;return s.iterChangedRanges((r,n)=>e.push(r,n)),t.iterChangedRanges((r,n,o,a)=>{for(let l=0;l<e.length;){let h=e[l++],c=e[l++];a>=h&&o<=c&&(i=!0)}}),i}function kI(s,t){return s.ranges.length==t.ranges.length&&s.ranges.filter((e,i)=>e.empty!=t.ranges[i].empty).length===0}function uA(s,t){return s.length?t.length?s.concat(t):s:t}function dA(s,t){if(s.length){let e=s[s.length-1],i=e.selectionsAfter.slice(Math.max(0,e.selectionsAfter.length-AI));return i.length&&i[i.length-1].eq(t)?s:(i.push(t),Fu(s,s.length-1,1e9,e.setSelAfter(i)))}else return[je.selection([t])]}function EI(s){let t=s[s.length-1],e=s.slice();return e[s.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),e}function Sb(s,t){if(!s.length)return s;let e=s.length,i=Ne;for(;e;){let r=CI(s[e-1],t,i);if(r.changes&&!r.changes.empty||r.effects.length){let n=s.slice(0,e);return n[e-1]=r,n}else t=r.mapped,e--,i=r.selectionsAfter}return i.length?[je.selection(i)]:Ne}function CI(s,t,e){let i=uA(s.selectionsAfter.length?s.selectionsAfter.map(a=>a.map(t)):Ne,e);if(!s.changes)return je.selection(i);let r=s.changes.map(t),n=t.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(n):n;return new je(r,F.mapEffects(s.effects,t),o,s.startSelection.map(n),i)}function mo(s,t){return Q.create(s.ranges.map(t),s.mainIndex)}function We(s,t){return s.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function ye({state:s,dispatch:t},e){let i=mo(s.selection,e);return i.eq(s.selection,!0)?!1:(t(We(s,i)),!0)}function Fs(s,t){return Q.cursor(t?s.to:s.from)}function Uu(s,t){return ye(s,e=>e.empty?s.moveByChar(e,t):Fs(e,t))}function Ft(s){return s.textDirectionAt(s.state.selection.main.head)==rt.LTR}function Ab(s,t,e){let i=t.head,r=s.doc.lineAt(i);return i==(e?r.to:r.from)?i=e?Math.min(s.doc.length,r.to+1):Math.max(0,r.from-1):i=r.from+Et(r.text,i-r.from,e),Q.cursor(i,e?-1:1)}function fA(s,t){return ye(s,e=>e.empty?Ab(s.state,e,t):Fs(e,t))}function Yu(s,t){return ye(s,e=>e.empty?s.moveByGroup(e,t):Fs(e,t))}function Eb(s,t,e){let i=s.state.charCategorizer(t),r=i(e),n=r!=gt.Space;return o=>{let a=i(o);return a!=gt.Space?n&&a==r:(n=!1,!0)}}function bA(s,t,e){let i=s.state.charCategorizer(t.from),r=gt.Space,n=t.from,o=0,a=!1,l=!1,h=!1,c=d=>{if(a)return!1;n+=e?d.length:-d.length;let f=i(d),p;if(f==gt.Word&&d.charCodeAt(0)<128&&/[\W_]/.test(d)&&(f=-1),r==gt.Space&&(r=f),r!=f)return!1;if(r==gt.Word)if(d.toLowerCase()==d){if(!e&&l)return!1;h=!0}else if(h){if(e)return!1;a=!0}else{if(l&&e&&i(p=s.state.sliceDoc(n,n+1))==gt.Word&&p.toLowerCase()==p)return!1;l=!0}return o++,!0},u=s.moveByChar(t,e,d=>(c(d),c));if(gA&&r==gt.Word&&u.from==t.from+o*(e?1:-1)){let d=Math.min(t.head,u.head),f=Math.max(t.head,u.head),p=s.state.sliceDoc(d,f);if(p.length>1&&/[\u4E00-\uffff]/.test(p)){let m=Array.from(gA.segment(p));if(m.length>1)return e?Q.cursor(t.head+m[1].index,-1):Q.cursor(u.head+m[m.length-1].index,1)}}return u}function OA(s,t){return ye(s,e=>e.empty?bA(s,e,t):Fs(e,t))}function NI(s,t,e){if(t.type.prop(e))return!0;let i=t.to-t.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(t.from,t.to)))||t.firstChild}function Hu(s,t,e){let i=J(s).resolveInner(t.head),r=e?_.closedBy:_.openedBy;for(let l=t.head;;){let h=e?i.childAfter(l):i.childBefore(l);if(!h)break;NI(s,h,r)?i=h:l=e?h.to:h.from}let n=i.type.prop(r),o,a;return n&&(o=e?De(s,i.from,1):De(s,i.to,-1))&&o.matched?a=e?o.end.to:o.end.from:a=e?i.to:i.from,Q.cursor(a,e?-1:1)}function xA(s,t){return ye(s,e=>{if(!e.empty)return Fs(e,t);let i=s.moveVertically(e,t);return i.head!=e.head?i:s.moveToLineBoundary(e,t)})}function SA(s){let t=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,e=0,i=0,r;if(t){for(let n of s.state.facet(D.scrollMargins)){let o=n(s);o?.top&&(e=Math.max(o?.top,e)),o?.bottom&&(i=Math.max(o?.bottom,i))}r=s.scrollDOM.clientHeight-e-i}else r=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:e,marginBottom:i,selfScroll:t,height:Math.max(s.defaultLineHeight,r-5)}}function wA(s,t){let e=SA(s),{state:i}=s,r=mo(i.selection,o=>o.empty?s.moveVertically(o,t,e.height):Fs(o,t));if(r.eq(i.selection))return!1;let n;if(e.selfScroll){let o=s.coordsAtPos(i.selection.main.head),a=s.scrollDOM.getBoundingClientRect(),l=a.top+e.marginTop,h=a.bottom-e.marginBottom;o&&o.top>l&&o.bottom<h&&(n=D.scrollIntoView(r.main.head,{y:"start",yMargin:o.top-l}))}return s.dispatch(We(i,r),{effects:n}),!0}function ss(s,t,e){let i=s.lineBlockAt(t.head),r=s.moveToLineBoundary(t,e);if(r.head==t.head&&r.head!=(e?i.to:i.from)&&(r=s.moveToLineBoundary(t,e,!1)),!e&&r.head==i.from&&i.length){let n=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;n&&t.head!=i.from+n&&(r=Q.cursor(i.from+n))}return r}function QA(s,t,e){let i=!1,r=mo(s.selection,n=>{let o=De(s,n.head,-1)||De(s,n.head,1)||n.head>0&&De(s,n.head-1,1)||n.head<s.doc.length&&De(s,n.head+1,-1);if(!o||!o.end)return n;i=!0;let a=o.start.from==n.head?o.end.to:o.end.from;return e?Q.range(n.anchor,a):Q.cursor(a)});return i?(t(We(s,r)),!0):!1}function Ut(s,t){let e=mo(s.state.selection,i=>{let r=t(i);return Q.range(i.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return e.eq(s.state.selection)?!1:(s.dispatch(We(s.state,e)),!0)}function Ku(s,t){return Ut(s,e=>s.moveByChar(e,t))}function Ju(s,t){return Ut(s,e=>s.moveByGroup(e,t))}function RA(s,t){return Ut(s,e=>bA(s,e,t))}function qA(s,t){return Ut(s,e=>s.moveVertically(e,t))}function NA(s,t){return Ut(s,e=>s.moveVertically(e,t,SA(s).height))}function UA(s,t){let{state:e}=s,i=e.selection,r=e.selection.ranges.slice();for(let n of e.selection.ranges){let o=e.doc.lineAt(n.head);if(t?o.to<s.state.doc.length:o.from>0)for(let a=n;;){let l=s.moveVertically(a,t);if(l.head<o.from||l.head>o.to){r.some(h=>h.head==l.head)||r.push(l);break}else{if(l.head==a.head)break;a=l}}}return r.length==i.ranges.length?!1:(s.dispatch(We(e,Q.create(r,r.length-1))),!0)}function Us(s,t){if(s.state.readOnly)return!1;let e="delete.selection",{state:i}=s,r=i.changeByRange(n=>{let{from:o,to:a}=n;if(o==a){let l=t(n);l<o?(e="delete.backward",l=td(s,l,!1)):l>o&&(e="delete.forward",l=td(s,l,!0)),o=Math.min(o,l),a=Math.max(a,l)}else o=td(s,o,!1),a=td(s,a,!0);return o==a?{range:n}:{changes:{from:o,to:a},range:Q.cursor(o,o<n.head?-1:1)}});return r.changes.empty?!1:(s.dispatch(i.update(r,{scrollIntoView:!0,userEvent:e,effects:e=="delete.selection"?D.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function td(s,t,e){if(s instanceof D)for(let i of s.state.facet(D.atomicRanges).map(r=>r(s)))i.between(t,t,(r,n)=>{r<t&&n>t&&(t=e?n:r)});return t}function id(s){let t=[],e=-1;for(let i of s.selection.ranges){let r=s.doc.lineAt(i.from),n=s.doc.lineAt(i.to);if(!i.empty&&i.to==n.from&&(n=s.doc.lineAt(i.to-1)),e>=r.number){let o=t[t.length-1];o.to=n.to,o.ranges.push(i)}else t.push({from:r.from,to:n.to,ranges:[i]});e=n.number+1}return t}function n1(s,t,e){if(s.readOnly)return!1;let i=[],r=[];for(let n of id(s)){if(e?n.to==s.doc.length:n.from==0)continue;let o=s.doc.lineAt(e?n.to+1:n.from-1),a=o.length+1;if(e){i.push({from:n.to,to:o.to},{from:n.from,insert:o.text+s.lineBreak});for(let l of n.ranges)r.push(Q.range(Math.min(s.doc.length,l.anchor+a),Math.min(s.doc.length,l.head+a)))}else{i.push({from:o.from,to:n.from},{from:n.to,insert:s.lineBreak+o.text});for(let l of n.ranges)r.push(Q.range(l.anchor-a,l.head-a))}}return i.length?(t(s.update({changes:i,scrollIntoView:!0,selection:Q.create(r,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}function l1(s,t,e){if(s.readOnly)return!1;let i=[];for(let n of id(s))e?i.push({from:n.from,insert:s.doc.slice(n.from,n.to)+s.lineBreak}):i.push({from:n.to,insert:s.lineBreak+s.doc.slice(n.from,n.to)});let r=s.changes(i);return t(s.update({changes:r,selection:s.selection.map(r,e?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}function e5(s,t){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(t-1,t+1)))return{from:t,to:t};let e=J(s).resolveInner(t),i=e.childBefore(t),r=e.childAfter(t),n;return i&&r&&i.to<=t&&r.from>=t&&(n=i.type.prop(_.closedBy))&&n.indexOf(r.name)>-1&&s.doc.lineAt(i.to).from==s.doc.lineAt(r.from).from&&!/\S/.test(s.sliceDoc(i.to,r.from))?{from:i.to,to:r.from}:null}function f1(s){return({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(r=>{let{from:n,to:o}=r,a=t.doc.lineAt(n),l=!s&&n==o&&e5(t,n);s&&(n=o=(o<=a.to?a:t.doc.lineAt(o)).to);let h=new Ci(t,{simulateBreak:n,simulateDoubleBreak:!!l}),c=io(h,n);for(c==null&&(c=jt(/^\s*/.exec(t.doc.lineAt(n).text)[0],t.tabSize));o<a.to&&/\s/.test(a.text[o-a.from]);)o++;l?{from:n,to:o}=l:n>a.from&&n<a.from+100&&!/\S/.test(a.text.slice(0,n))&&(n=a.from);let u=["",ts(t,c)];return l&&u.push(ts(t,h.lineIndent(a.from,-1))),{changes:{from:n,to:o,insert:et.of(u)},range:Q.cursor(n+1+u[1].length)}});return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Vb(s,t){let e=-1;return s.changeByRange(i=>{let r=[];for(let o=i.from;o<=i.to;){let a=s.doc.lineAt(o);a.number>e&&(i.empty||i.to>a.from)&&(t(a,r,i),e=a.number),o=a.to+1}let n=s.changes(r);return{changes:r,range:Q.range(n.mapPos(i.anchor,1),n.mapPos(i.head,1))}})}var eA,iA,pI,mI,sA,gI,bI,rA,jl,vb,nA,oA,aA,Vu,vI,xb,Wu,lA,hA,xI,SI,je,Ne,AI,$I,Ws,nd,wb,kb,PI,QI,TI,LI,pA,mA,MI,RI,II,gA,DI,qI,yA,vA,Cb,$b,Pb,Gu,kA,AA,EA,CA,$A,PA,TA,XI,Qb,Tb,BI,ZI,zI,_I,LA,MA,VI,jI,WI,FI,UI,IA,DA,Lb,Mb,Rb,Ib,XA,BA,ZA,zA,_A,VA,Db,qb,Nb,Xb,jA,WA,FA,YA,HA,GA,Bb,ed,YI,Zb,KA,zb,JA,HI,t1,GI,e1,i1,KI,s1,r1,o1,a1,h1,c1,u1,JI,t5,_b,d1,p1,sd,jb,m1,i5,s5,g1,b1,od,ad,O1=W(()=>{ri();ki();ci();_e();eA=s=>{let{state:t}=s,e=t.doc.lineAt(t.selection.main.from),i=Ob(s.state,e.from);return i.line?iA(s):i.block?rA(s):!1};iA=js(yb,0),pI=js(yb,1),mI=js(yb,2),sA=js(_u,0),gI=js(_u,1),bI=js(_u,2),rA=js((s,t)=>_u(s,t,yI(t)),0);jl=50;vb=Jt.define(),nA=Jt.define(),oA=X.define(),aA=X.define({combine(s){return te(s,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,r)=>t(i,r)||e(i,r)})}}),Vu=bt.define({create(){return Ws.empty},update(s,t){let e=t.state.facet(aA),i=t.annotation(vb);if(i){let l=je.fromTransaction(t,i.selection),h=i.side,c=h==0?s.undone:s.done;return l?c=Fu(c,c.length,e.minDepth,l):c=dA(c,t.startState.selection),new Ws(h==0?i.rest:c,h==0?c:i.rest)}let r=t.annotation(nA);if((r=="full"||r=="before")&&(s=s.isolate()),t.annotation(xt.addToHistory)===!1)return t.changes.empty?s:s.addMapping(t.changes.desc);let n=je.fromTransaction(t),o=t.annotation(xt.time),a=t.annotation(xt.userEvent);return n?s=s.addChanges(n,o,a,e,t):t.selection&&(s=s.addSelection(t.startState.selection,o,a,e.newGroupDelay)),(r=="full"||r=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(t=>t.toJSON()),undone:s.undone.map(t=>t.toJSON())}},fromJSON(s){return new Ws(s.done.map(je.fromJSON),s.undone.map(je.fromJSON))}});vI=Vu;xb=ju(0,!1),Wu=ju(1,!1),lA=ju(0,!0),hA=ju(1,!0);xI=cA(0),SI=cA(1),je=class s{constructor(t,e,i,r,n){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=r,this.selectionsAfter=n}setSelAfter(t){return new s(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(e=this.mapped)===null||e===void 0?void 0:e.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(r=>r.toJSON())}}static fromJSON(t){return new s(t.changes&&_t.fromJSON(t.changes),[],t.mapped&&si.fromJSON(t.mapped),t.startSelection&&Q.fromJSON(t.startSelection),t.selectionsAfter.map(Q.fromJSON))}static fromTransaction(t,e){let i=Ne;for(let r of t.startState.facet(oA)){let n=r(t);n.length&&(i=i.concat(n))}return!i.length&&t.changes.empty?null:new s(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,Ne)}static selection(t){return new s(void 0,Ne,void 0,void 0,t)}};Ne=[],AI=200;$I=/^(input\.type|delete)($|\.)/,Ws=class s{constructor(t,e,i=0,r=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=r}isolate(){return this.prevTime?new s(this.done,this.undone):this}addChanges(t,e,i,r,n){let o=this.done,a=o[o.length-1];return a&&a.changes&&!a.changes.empty&&t.changes&&(!i||$I.test(i))&&(!a.selectionsAfter.length&&e-this.prevTime<r.newGroupDelay&&r.joinToEvent(n,wI(a.changes,t.changes))||i=="input.type.compose")?o=Fu(o,o.length-1,r.minDepth,new je(t.changes.compose(a.changes),uA(F.mapEffects(t.effects,a.changes),a.effects),a.mapped,a.startSelection,Ne)):o=Fu(o,o.length,r.minDepth,t),new s(o,Ne,e,i)}addSelection(t,e,i,r){let n=this.done.length?this.done[this.done.length-1].selectionsAfter:Ne;return n.length>0&&e-this.prevTime<r&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&kI(n[n.length-1],t)?this:new s(dA(this.done,t),this.undone,e,i)}addMapping(t){return new s(Sb(this.done,t),Sb(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let r=t==0?this.done:this.undone;if(r.length==0)return null;let n=r[r.length-1],o=n.selectionsAfter[0]||(n.startSelection?n.startSelection.map(n.changes.invertedDesc,1):e.selection);if(i&&n.selectionsAfter.length)return e.update({selection:n.selectionsAfter[n.selectionsAfter.length-1],annotations:vb.of({side:t,rest:EI(r),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(n.changes){let a=r.length==1?Ne:r.slice(0,r.length-1);return n.mapped&&(a=Sb(a,n.mapped)),e.update({changes:n.changes,selection:n.startSelection,effects:n.effects,annotations:vb.of({side:t,rest:a,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}};Ws.empty=new Ws(Ne,Ne);nd=[{key:"Mod-z",run:xb,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Wu,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Wu,preventDefault:!0},{key:"Mod-u",run:lA,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:hA,preventDefault:!0}];wb=s=>Uu(s,!Ft(s)),kb=s=>Uu(s,Ft(s)),PI=s=>Uu(s,!0),QI=s=>Uu(s,!1);TI=s=>fA(s,!0),LI=s=>fA(s,!1);pA=s=>Yu(s,!Ft(s)),mA=s=>Yu(s,Ft(s)),MI=s=>Yu(s,!0),RI=s=>Yu(s,!1);II=s=>ye(s,t=>t.empty?s.moveByChar(t,!0,e=>Eb(s,t.head,e)):Fs(t,!0)),gA=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;DI=s=>OA(s,!0),qI=s=>OA(s,!1);yA=s=>ye(s,t=>Hu(s.state,t,!Ft(s))),vA=s=>ye(s,t=>Hu(s.state,t,Ft(s)));Cb=s=>xA(s,!1),$b=s=>xA(s,!0);Pb=s=>wA(s,!1),Gu=s=>wA(s,!0);kA=s=>ye(s,t=>ss(s,t,!0)),AA=s=>ye(s,t=>ss(s,t,!1)),EA=s=>ye(s,t=>ss(s,t,!Ft(s))),CA=s=>ye(s,t=>ss(s,t,Ft(s))),$A=s=>ye(s,t=>Q.cursor(s.lineBlockAt(t.head).from,1)),PA=s=>ye(s,t=>Q.cursor(s.lineBlockAt(t.head).to,-1));TA=({state:s,dispatch:t})=>QA(s,t,!1),XI=({state:s,dispatch:t})=>QA(s,t,!0);Qb=s=>Ku(s,!Ft(s)),Tb=s=>Ku(s,Ft(s)),BI=s=>Ku(s,!0),ZI=s=>Ku(s,!1),zI=s=>Ut(s,t=>Ab(s.state,t,!0)),_I=s=>Ut(s,t=>Ab(s.state,t,!1));LA=s=>Ju(s,!Ft(s)),MA=s=>Ju(s,Ft(s)),VI=s=>Ju(s,!0),jI=s=>Ju(s,!1),WI=s=>Ut(s,t=>s.moveByChar(t,!0,e=>Eb(s,t.head,e)));FI=s=>RA(s,!0),UI=s=>RA(s,!1),IA=s=>Ut(s,t=>Hu(s.state,t,!Ft(s))),DA=s=>Ut(s,t=>Hu(s.state,t,Ft(s)));Lb=s=>qA(s,!1),Mb=s=>qA(s,!0);Rb=s=>NA(s,!1),Ib=s=>NA(s,!0),XA=s=>Ut(s,t=>ss(s,t,!0)),BA=s=>Ut(s,t=>ss(s,t,!1)),ZA=s=>Ut(s,t=>ss(s,t,!Ft(s))),zA=s=>Ut(s,t=>ss(s,t,Ft(s))),_A=s=>Ut(s,t=>Q.cursor(s.lineBlockAt(t.head).from)),VA=s=>Ut(s,t=>Q.cursor(s.lineBlockAt(t.head).to)),Db=({state:s,dispatch:t})=>(t(We(s,{anchor:0})),!0),qb=({state:s,dispatch:t})=>(t(We(s,{anchor:s.doc.length})),!0),Nb=({state:s,dispatch:t})=>(t(We(s,{anchor:s.selection.main.anchor,head:0})),!0),Xb=({state:s,dispatch:t})=>(t(We(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),jA=({state:s,dispatch:t})=>(t(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),WA=({state:s,dispatch:t})=>{let e=id(s).map(({from:i,to:r})=>Q.range(i,Math.min(r+1,s.doc.length)));return t(s.update({selection:Q.create(e),userEvent:"select"})),!0},FA=({state:s,dispatch:t})=>{let e=mo(s.selection,i=>{let r=J(s),n=r.resolveStack(i.from,1);if(i.empty){let o=r.resolveStack(i.from,-1);o.node.from>=n.node.from&&o.node.to<=n.node.to&&(n=o)}for(let o=n;o;o=o.next){let{node:a}=o;if((a.from<i.from&&a.to>=i.to||a.to>i.to&&a.from<=i.from)&&o.next)return Q.range(a.to,a.from)}return i});return e.eq(s.selection)?!1:(t(We(s,e)),!0)};YA=s=>UA(s,!1),HA=s=>UA(s,!0),GA=({state:s,dispatch:t})=>{let e=s.selection,i=null;return e.ranges.length>1?i=Q.create([e.main]):e.main.empty||(i=Q.create([Q.cursor(e.main.head)])),i?(t(We(s,i)),!0):!1};Bb=(s,t,e)=>Us(s,i=>{let r=i.from,{state:n}=s,o=n.doc.lineAt(r),a,l;if(e&&!t&&r>o.from&&r<o.from+200&&!/[^ \t]/.test(a=o.text.slice(0,r-o.from))){if(a[a.length-1]==" ")return r-1;let h=jt(a,n.tabSize),c=h%$i(n)||$i(n);for(let u=0;u<c&&a[a.length-1-u]==" ";u++)r--;l=r}else l=Et(o.text,r-o.from,t,t)+o.from,l==r&&o.number!=(t?n.doc.lines:1)?l+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(l-o.from,r-o.from))&&(l=Et(o.text,l-o.from,!1,!1)+o.from);return l}),ed=s=>Bb(s,!1,!0),YI=s=>Bb(s,!1,!1),Zb=s=>Bb(s,!0,!1),KA=(s,t)=>Us(s,e=>{let i=e.head,{state:r}=s,n=r.doc.lineAt(i),o=r.charCategorizer(i);for(let a=null;;){if(i==(t?n.to:n.from)){i==e.head&&n.number!=(t?r.doc.lines:1)&&(i+=t?1:-1);break}let l=Et(n.text,i-n.from,t)+n.from,h=n.text.slice(Math.min(i,l)-n.from,Math.max(i,l)-n.from),c=o(h);if(a!=null&&c!=a)break;(h!=" "||i!=e.head)&&(a=c),i=l}return i}),zb=s=>KA(s,!1),JA=s=>KA(s,!0),HI=s=>Us(s,t=>s.moveByChar(t,!0,e=>Eb(s,t.head,e)).head),t1=s=>Us(s,t=>{let e=s.lineBlockAt(t.head).to;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),GI=s=>Us(s,t=>{let e=s.lineBlockAt(t.head).from;return t.head>e?e:Math.max(0,t.head-1)}),e1=s=>Us(s,t=>{let e=s.moveToLineBoundary(t,!1).head;return t.head>e?e:Math.max(0,t.head-1)}),i1=s=>Us(s,t=>{let e=s.moveToLineBoundary(t,!0).head;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),KI=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=[];for(let i=0,r="",n=s.doc.iter();;){if(n.next(),n.lineBreak||n.done){let o=r.search(/\s+$/);if(o>-1&&e.push({from:i-(r.length-o),to:i}),n.done)break;r=""}else r=n.value;i+=n.value.length}return e.length?(t(s.update({changes:e,userEvent:"delete"})),!0):!1},s1=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:et.of(["",""])},range:Q.cursor(i.from)}));return t(s.update(e,{scrollIntoView:!0,userEvent:"input"})),!0},r1=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=s.changeByRange(i=>{if(!i.empty||i.from==0||i.from==s.doc.length)return{range:i};let r=i.from,n=s.doc.lineAt(r),o=r==n.from?r-1:Et(n.text,r-n.from,!1)+n.from,a=r==n.to?r+1:Et(n.text,r-n.from,!0)+n.from;return{changes:{from:o,to:a,insert:s.doc.slice(r,a).append(s.doc.slice(o,r))},range:Q.cursor(a)}});return e.changes.empty?!1:(t(s.update(e,{scrollIntoView:!0,userEvent:"move.character"})),!0)};o1=({state:s,dispatch:t})=>n1(s,t,!1),a1=({state:s,dispatch:t})=>n1(s,t,!0);h1=({state:s,dispatch:t})=>l1(s,t,!1),c1=({state:s,dispatch:t})=>l1(s,t,!0),u1=s=>{if(s.state.readOnly)return!1;let{state:t}=s,e=t.changes(id(t).map(({from:r,to:n})=>(r>0?r--:n<t.doc.length&&n++,{from:r,to:n}))),i=mo(t.selection,r=>{let n;if(s.lineWrapping){let o=s.lineBlockAt(r.head),a=s.coordsAtPos(r.head,r.assoc||1);a&&(n=o.bottom+s.documentTop-a.bottom+s.defaultLineHeight/2)}return s.moveVertically(r,!0,n)}).map(e);return s.dispatch({changes:e,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0},JI=({state:s,dispatch:t})=>(t(s.update(s.replaceSelection(s.lineBreak),{scrollIntoView:!0,userEvent:"input"})),!0),t5=({state:s,dispatch:t})=>(t(s.update(s.changeByRange(e=>{let i=/^\s*/.exec(s.doc.lineAt(e.from).text)[0];return{changes:{from:e.from,to:e.to,insert:s.lineBreak+i},range:Q.cursor(e.from+i.length+1)}}),{scrollIntoView:!0,userEvent:"input"})),!0);_b=f1(!1),d1=f1(!0);p1=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=Object.create(null),i=new Ci(s,{overrideIndentation:n=>{let o=e[n];return o??-1}}),r=Vb(s,(n,o,a)=>{let l=io(i,n.from);if(l==null)return;/\S/.test(n.text)||(l=0);let h=/^\s*/.exec(n.text)[0],c=ts(s,l);(h!=c||a.from<n.from+h.length)&&(e[n.from]=l,o.push({from:n.from,to:n.from+h.length,insert:c}))});return r.changes.empty||t(s.update(r,{userEvent:"indent"})),!0},sd=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Vb(s,(e,i)=>{i.push({from:e.from,insert:s.facet(Qi)})}),{userEvent:"input.indent"})),!0),jb=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Vb(s,(e,i)=>{let r=/^\s*/.exec(e.text)[0];if(!r)return;let n=jt(r,s.tabSize),o=0,a=ts(s,Math.max(0,n-$i(s)));for(;o<r.length&&o<a.length&&r.charCodeAt(o)==a.charCodeAt(o);)o++;i.push({from:e.from+o,to:e.from+r.length,insert:a.slice(o)})}),{userEvent:"delete.dedent"})),!0),m1=s=>(s.setTabFocusMode(),!0),i5=s=>(s.setTabFocusMode(2e3),!0),s5=({state:s,dispatch:t})=>s.selection.ranges.some(e=>!e.empty)?sd({state:s,dispatch:t}):(t(s.update(s.replaceSelection(" "),{scrollIntoView:!0,userEvent:"input"})),!0),g1=[{key:"Ctrl-b",run:wb,shift:Qb,preventDefault:!0},{key:"Ctrl-f",run:kb,shift:Tb},{key:"Ctrl-p",run:Cb,shift:Lb},{key:"Ctrl-n",run:$b,shift:Mb},{key:"Ctrl-a",run:$A,shift:_A},{key:"Ctrl-e",run:PA,shift:VA},{key:"Ctrl-d",run:Zb},{key:"Ctrl-h",run:ed},{key:"Ctrl-k",run:t1},{key:"Ctrl-Alt-h",run:zb},{key:"Ctrl-o",run:s1},{key:"Ctrl-t",run:r1},{key:"Ctrl-v",run:Gu}],b1=[{key:"ArrowLeft",run:wb,shift:Qb,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:pA,shift:LA,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:EA,shift:ZA,preventDefault:!0},{key:"ArrowRight",run:kb,shift:Tb,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:mA,shift:MA,preventDefault:!0},{mac:"Cmd-ArrowRight",run:CA,shift:zA,preventDefault:!0},{key:"ArrowUp",run:Cb,shift:Lb,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Db,shift:Nb},{mac:"Ctrl-ArrowUp",run:Pb,shift:Rb},{key:"ArrowDown",run:$b,shift:Mb,preventDefault:!0},{mac:"Cmd-ArrowDown",run:qb,shift:Xb},{mac:"Ctrl-ArrowDown",run:Gu,shift:Ib},{key:"PageUp",run:Pb,shift:Rb},{key:"PageDown",run:Gu,shift:Ib},{key:"Home",run:AA,shift:BA,preventDefault:!0},{key:"Mod-Home",run:Db,shift:Nb},{key:"End",run:kA,shift:XA,preventDefault:!0},{key:"Mod-End",run:qb,shift:Xb},{key:"Enter",run:_b,shift:_b},{key:"Mod-a",run:jA},{key:"Backspace",run:ed,shift:ed,preventDefault:!0},{key:"Delete",run:Zb,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:zb,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:JA,preventDefault:!0},{mac:"Mod-Backspace",run:e1,preventDefault:!0},{mac:"Mod-Delete",run:i1,preventDefault:!0}].concat(g1.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),od=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:yA,shift:IA},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:vA,shift:DA},{key:"Alt-ArrowUp",run:o1},{key:"Shift-Alt-ArrowUp",run:h1},{key:"Alt-ArrowDown",run:a1},{key:"Shift-Alt-ArrowDown",run:c1},{key:"Mod-Alt-ArrowUp",run:YA},{key:"Mod-Alt-ArrowDown",run:HA},{key:"Escape",run:GA},{key:"Mod-Enter",run:d1},{key:"Alt-l",mac:"Ctrl-l",run:WA},{key:"Mod-i",run:FA,preventDefault:!0},{key:"Mod-[",run:jb},{key:"Mod-]",run:sd},{key:"Mod-Alt-\\",run:p1},{key:"Shift-Mod-k",run:u1},{key:"Shift-Mod-\\",run:TA},{key:"Mod-/",run:eA},{key:"Alt-A",run:sA},{key:"Ctrl-m",mac:"Shift-Alt-m",run:m1}].concat(b1),ad={key:"Tab",run:sd,shift:jb}});function rs(s,t=null,e=0){let i=null;return s.between(e,1e9,(r,n,{spec:o})=>{if(!(t&&o.diagnostics.indexOf(t)<0))if(!i)i=new ld(r,n,t||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new ld(i.from,n,i.diagnostic)}}),i}function y1(s,t){let e=t.pos,i=t.end||e,r=s.state.facet(ui).hideOn(s,e,i);if(r!=null)return r;let n=s.startState.doc.lineAt(t.pos);return!!(s.effects.some(o=>o.is(Wl))||s.changes.touchesRange(n.from,Math.max(n.to,i)))}function v1(s,t){return s.field(Yt,!1)?t:t.concat(F.appendConfig.of(L1))}function x1(s,t){return{effects:v1(s,[Wl.of(t)])}}function r5(s){let t=s.field(Yt,!1);return t?t.diagnostics.size:0}function o5(s,t,e){let{diagnostics:i}=s.state.field(Yt),r,n=-1,o=-1;i.between(t-(e<0?1:0),t+(e>0?1:0),(l,h,{spec:c})=>{if(t>=l&&t<=h&&(l==h||(t>l||e>0)&&(t<h||e<0)))return r=c.diagnostics,n=l,o=h,!1});let a=s.state.facet(ui).tooltipFilter;return r&&a&&(r=a(r,s.state)),r?{pos:n,end:o,above:s.state.doc.lineAt(n).to<o,create(){return{dom:w1(s,r)}}}:null}function w1(s,t){return Qt("ul",{class:"cm-tooltip-lint"},t.map(e=>P1(s,e,!1)))}function h5(s,t,e){let i=[],r=-1;for(let n of s)n.then(o=>{i.push(o),clearTimeout(r),i.length==s.length?t(i):r=setTimeout(()=>t(i),200)},e)}function C1(s,t){return s?t?(e,i)=>t(s(e,i),i):s:t}function Ul(s,t={}){return[ui.of({source:s,config:t}),E1,L1]}function c5(s){let t=s.plugin(E1);t&&t.force()}function $1(s){let t=[];if(s)t:for(let{name:e}of s){for(let i=0;i<e.length;i++){let r=e[i];if(/[a-zA-Z]/.test(r)&&!t.some(n=>n.toLowerCase()==r.toLowerCase())){t.push(r);continue t}}t.push("")}return t}function P1(s,t,e){var i;let r=e?$1(t.actions):[];return Qt("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},Qt("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(s):t.message),(i=t.actions)===null||i===void 0?void 0:i.map((n,o)=>{let a=!1,l=f=>{if(f.preventDefault(),a)return;a=!0;let p=rs(s.state.field(Yt).diagnostics,t);p&&n.apply(s,p.from,p.to)},{name:h}=n,c=r[o]?h.indexOf(r[o]):-1,u=c<0?h:[h.slice(0,c),Qt("u",h.slice(c,c+1)),h.slice(c+1)],d=n.markClass?" "+n.markClass:"";return Qt("button",{type:"button",class:"cm-diagnosticAction"+d,onclick:l,onmousedown:l,"aria-label":` Action: ${h}${c<0?"":` (access key "${r[o]})"`}.`},u)}),t.source&&Qt("div",{class:"cm-diagnosticSource"},t.source))}function cd(s,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(s)}</svg>')`}function ud(s){return cd(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}function d5(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function Q1(s){let t="hint",e=1;for(let i of s){let r=d5(i.severity);r>e&&(e=r,t=i.severity)}return t}function f5(s,t){let e=i=>{let r=t.getBoundingClientRect();if(!(i.clientX>r.left-10&&i.clientX<r.right+10&&i.clientY>r.top-10&&i.clientY<r.bottom+10)){for(let n=i.target;n;n=n.parentNode)if(n.nodeType==1&&n.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",e),s.state.field(T1)&&s.dispatch({effects:Hb.of(null)})}};window.addEventListener("mousemove",e)}function p5(s,t,e){function i(){let o=s.elementAtHeight(t.getBoundingClientRect().top+5-s.documentTop);s.coordsAtPos(o.from)&&s.dispatch({effects:Hb.of({pos:o.from,above:!1,clip:!1,create(){return{dom:w1(s,e),getCoords:()=>t.getBoundingClientRect()}}})}),t.onmouseout=t.onmousemove=null,f5(s,t)}let{hoverTime:r}=s.state.facet(fd),n=setTimeout(i,r);t.onmouseout=()=>{clearTimeout(n),t.onmouseout=t.onmousemove=null},t.onmousemove=()=>{clearTimeout(n),n=setTimeout(i,r)}}function m5(s,t){let e=Object.create(null);for(let r of t){let n=s.lineAt(r.from);(e[n.from]||(e[n.from]=[])).push(r)}let i=[];for(let r in e)i.push(new dd(e[r]).range(+r));return K.of(i,!0)}function pd(s={}){return[fd.of(s),Yb,g5,b5,T1]}function O5(s,t){let e=s.field(Yt,!1);if(e&&e.diagnostics.size){let i=[],r=[],n=-1;for(let o=K.iter([e.diagnostics]);;o.next()){for(let a=0;a<i.length;a++)(!o.value||o.value.spec.diagnostics.indexOf(i[a])<0)&&(t(i[a],r[a],n),i.splice(a,1),r.splice(a--,1));if(!o.value)break;for(let a of o.value.spec.diagnostics)i.indexOf(a)<0&&(i.push(a),r.push(o.from));n=o.to}}}var ld,Ys,Wl,Wb,S1,Yt,n5,k1,Fb,A1,a5,l5,E1,ui,Ub,hd,Fl,u5,dd,g5,Yb,Hb,T1,b5,L1,fd,M1=W(()=>{ki();ri();rp();ld=class{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}},Ys=class s{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let r=i.facet(ui).markerFilter;r&&(t=r(t,i));let n=t.slice().sort((f,p)=>f.from-p.from||f.to-p.to),o=new Ee,a=[],l=0,h=i.doc.iter(),c=0,u=i.doc.length;for(let f=0;;){let p=f==n.length?null:n[f];if(!p&&!a.length)break;let m,b;if(a.length)m=l,b=a.reduce((S,w)=>Math.min(S,w.to),p&&p.from>m?p.from:1e8);else{if(m=p.from,m>u)break;b=p.to,a.push(p),f++}for(;f<n.length;){let S=n[f];if(S.from==m&&(S.to>S.from||S.to==m))a.push(S),f++,b=Math.min(S.to,b);else{b=Math.min(S.from,b);break}}b=Math.min(b,u);let g=!1;if(a.some(S=>S.from==m&&(S.to==b||b==u))&&(g=m==b,!g&&b-m<10)){let S=m-(c+h.value.length);S>0&&(h.next(S),c=m);for(let w=m;;){if(w>=b){g=!0;break}if(!h.lineBreak&&c+h.value.length>w)break;w=c+h.value.length,c+=h.value.length,h.next()}}let x=Q1(a);if(g)o.add(m,m,j.widget({widget:new Ub(x),diagnostics:a.slice()}));else{let S=a.reduce((w,k)=>k.markClass?w+" "+k.markClass:w,"");o.add(m,b,j.mark({class:"cm-lintRange cm-lintRange-"+x+S,diagnostics:a.slice(),inclusiveEnd:a.some(w=>w.to>b)}))}if(l=b,l==u)break;for(let S=0;S<a.length;S++)a[S].to<=l&&a.splice(S--,1)}let d=o.finish();return new s(d,e,rs(d))}};Wl=F.define(),Wb=F.define(),S1=F.define(),Yt=bt.define({create(){return new Ys(j.none,null,null)},update(s,t){if(t.docChanged&&s.diagnostics.size){let e=s.diagnostics.map(t.changes),i=null,r=s.panel;if(s.selected){let n=t.changes.mapPos(s.selected.from,1);i=rs(e,s.selected.diagnostic,n)||rs(e,null,n)}!e.size&&r&&t.state.facet(ui).autoPanel&&(r=null),s=new Ys(e,r,i)}for(let e of t.effects)if(e.is(Wl)){let i=t.state.facet(ui).autoPanel?e.value.length?Fl.open:null:s.panel;s=Ys.init(e.value,i,t.state)}else e.is(Wb)?s=new Ys(s.diagnostics,e.value?Fl.open:null,s.selected):e.is(S1)&&(s=new Ys(s.diagnostics,s.panel,e.value));return s},provide:s=>[Kn.from(s,t=>t.panel),D.decorations.from(s,t=>t.diagnostics)]});n5=j.mark({class:"cm-lintRange cm-lintRange-active"});k1=s=>{let t=s.state.field(Yt,!1);(!t||!t.panel)&&s.dispatch({effects:v1(s.state,[Wb.of(!0)])});let e=Kc(s,Fl.open);return e&&e.dom.querySelector(".cm-panel-lint ul").focus(),!0},Fb=s=>{let t=s.state.field(Yt,!1);return!t||!t.panel?!1:(s.dispatch({effects:Wb.of(!1)}),!0)},A1=s=>{let t=s.state.field(Yt,!1);if(!t)return!1;let e=s.state.selection.main,i=rs(t.diagnostics,null,e.to+1);return!i&&(i=rs(t.diagnostics,null,0),!i||i.from==e.from&&i.to==e.to)?!1:(s.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},a5=s=>{let{state:t}=s,e=t.field(Yt,!1);if(!e)return!1;let i=t.selection.main,r,n,o,a;return e.diagnostics.between(0,t.doc.length,(l,h)=>{h<i.to&&(r==null||r<l)&&(r=l,n=h),(o==null||l>o)&&(o=l,a=h)}),o==null||r==null&&o==i.from?!1:(s.dispatch({selection:{anchor:r??o,head:n??a},scrollIntoView:!0}),!0)},l5=[{key:"Mod-Shift-m",run:k1,preventDefault:!0},{key:"F8",run:A1}],E1=ut.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:t}=s.state.facet(ui);this.lintTime=Date.now()+t,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:t}=this.view,{sources:e}=t.facet(ui);e.length&&h5(e.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==t.doc&&this.view.dispatch(x1(this.view.state,i.reduce((r,n)=>r.concat(n))))},i=>{Tt(this.view.state,i)})}}update(s){let t=s.state.facet(ui);(s.docChanged||t!=s.startState.facet(ui)||t.needsRefresh&&t.needsRefresh(s))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});ui=X.define({combine(s){return{sources:s.map(t=>t.source).filter(t=>t!=null),...te(s.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:C1,tooltipFilter:C1,needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e,hideOn:(t,e)=>t?e?(i,r,n)=>t(i,r,n)||e(i,r,n):t:e,autoPanel:(t,e)=>t||e})}}});Ub=class extends Xt{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return Qt("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}},hd=class{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=P1(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}},Fl=class s{constructor(t){this.view=t,this.items=[];let e=r=>{if(!(r.ctrlKey||r.altKey||r.metaKey)){if(r.keyCode==27)Fb(this.view),this.view.focus();else if(r.keyCode==38||r.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(r.keyCode==40||r.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(r.keyCode==36)this.moveSelection(0);else if(r.keyCode==35)this.moveSelection(this.items.length-1);else if(r.keyCode==13)this.view.focus();else if(r.keyCode>=65&&r.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],o=$1(n.actions);for(let a=0;a<o.length;a++)if(o[a].toUpperCase().charCodeAt(0)==r.keyCode){let l=rs(this.view.state.field(Yt).diagnostics,n);l&&n.actions[a].apply(t,l.from,l.to)}}else return;r.preventDefault()}},i=r=>{for(let n=0;n<this.items.length;n++)this.items[n].dom.contains(r.target)&&this.moveSelection(n)};this.list=Qt("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e,onclick:i}),this.dom=Qt("div",{class:"cm-panel-lint"},this.list,Qt("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Fb(this.view)},"\xD7")),this.update()}get selectedIndex(){let t=this.view.state.field(Yt).selected;if(!t)return-1;for(let e=0;e<this.items.length;e++)if(this.items[e].diagnostic==t.diagnostic)return e;return-1}update(){let{diagnostics:t,selected:e}=this.view.state.field(Yt),i=0,r=!1,n=null,o=new Set;for(t.between(0,this.view.state.doc.length,(a,l,{spec:h})=>{for(let c of h.diagnostics){if(o.has(c))continue;o.add(c);let u=-1,d;for(let f=i;f<this.items.length;f++)if(this.items[f].diagnostic==c){u=f;break}u<0?(d=new hd(this.view,c),this.items.splice(i,0,d),r=!0):(d=this.items[u],u>i&&(this.items.splice(i,u-i),r=!0)),e&&d.diagnostic==e.diagnostic?d.dom.hasAttribute("aria-selected")||(d.dom.setAttribute("aria-selected","true"),n=d):d.dom.hasAttribute("aria-selected")&&d.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new hd(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),r=!0),n?(this.list.setAttribute("aria-activedescendant",n.id),this.view.requestMeasure({key:this,read:()=>({sel:n.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:a,panel:l})=>{let h=l.height/this.list.offsetHeight;a.top<l.top?this.list.scrollTop-=(l.top-a.top)/h:a.bottom>l.bottom&&(this.list.scrollTop+=(a.bottom-l.bottom)/h)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),r&&this.sync()}sync(){let t=this.list.firstChild;function e(){let i=t;t=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=this.view.state.field(Yt),i=rs(e.diagnostics,this.items[t].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:S1.of(i)})}static open(t){return new s(t)}};u5=D.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:ud("#d11")},".cm-lintRange-warning":{backgroundImage:ud("orange")},".cm-lintRange-info":{backgroundImage:ud("#999")},".cm-lintRange-hint":{backgroundImage:ud("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});dd=class extends ie{constructor(t){super(),this.diagnostics=t,this.severity=Q1(t)}toDOM(t){let e=document.createElement("div");e.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,r=t.state.facet(fd).tooltipFilter;return r&&(i=r(i,t.state)),i.length&&(e.onmouseover=()=>p5(t,e,i)),e}};g5=vl({class:"cm-gutter-lint",markers:s=>s.state.field(Yb),widgetMarker:(s,t,e)=>{let i=[];return s.state.field(Yb).between(e.from,e.to,(r,n,o)=>{r>e.from&&r<e.to&&i.push(...o.diagnostics)}),i.length?new dd(i):null}}),Yb=bt.define({create(){return K.empty},update(s,t){s=s.map(t.changes);let e=t.state.facet(fd).markerFilter;for(let i of t.effects)if(i.is(Wl)){let r=i.value;e&&(r=e(r||[],t.state)),s=m5(t.state.doc,r.slice(0))}return s}}),Hb=F.define(),T1=bt.define({create(){return null},update(s,t){return s&&t.docChanged&&(s=y1(t,s)?null:{...s,pos:t.changes.mapPos(s.pos)}),t.effects.reduce((e,i)=>i.is(Hb)?i.value:e,s)},provide:s=>Rs.from(s)}),b5=D.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:cd('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:cd('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:cd('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),L1=[Yt,D.decorations.compute([Yt],s=>{let{selected:t,panel:e}=s.field(Yt);return!t||!e||t.from==t.to?j.none:j.set([n5.range(t.from,t.to)])}),bm(o5,{hideOn:y1}),u5],fd=X.define({combine(s){return te(s,{hoverTime:300,markerFilter:null,tooltipFilter:null})}})});var Kb={};Gt(Kb,{Compartment:()=>Fi,EditorSelection:()=>Q,EditorState:()=>at,EditorView:()=>D,HighlightStyle:()=>Pi,LOAD_TIMEOUT_MS:()=>Gb,LanguageSupport:()=>St,StateEffect:()=>F,adiaBaseTheme:()=>y5,adiaHighlightStyle:()=>v5,defaultHighlightStyle:()=>fu,defaultKeymap:()=>od,drawSelection:()=>Jc,highlightActiveLine:()=>tu,highlightActiveLineGutter:()=>ru,history:()=>rd,historyKeymap:()=>nd,importWithTimeout:()=>S5,indentWithTab:()=>ad,jsonLinter:()=>w5,keymap:()=>ai,languages:()=>x5,lineNumbers:()=>su,lintGutter:()=>pd,linter:()=>Ul,placeholder:()=>eu,syntaxHighlighting:()=>du});function S5(s,t){return Promise.race([s(),new Promise((e,i)=>setTimeout(()=>i(new Error(`code-editor: ${t} load timed out after ${Gb}ms`)),Gb))])}function k5(s,t){let e=t.length,i=s.match(/at position (\d+)/);if(i){let o=Math.min(e,Number(i[1]));return{from:o,to:Math.min(e,o+1)}}let r=s.match(/line (\d+) column (\d+)/);if(r){let o=Number(r[1]),a=Number(r[2]),l=0,h=1;for(let u=0;u<t.length&&h<o;u++)t[u]===`
41
- `&&(h++,l=u+1);let c=Math.min(e,l+Math.max(0,a-1));return{from:c,to:Math.min(e,c+1)}}let n=Math.max(0,e);return{from:Math.max(0,n-1),to:n}}var y5,v5,x5,Gb,w5,Jb=W(()=>{"use strict";ri();ki();O1();ci();M1();ii();y5=D.theme({"&":{fontFamily:"inherit",fontSize:"inherit",color:"inherit",backgroundColor:"transparent"},".cm-content":{caretColor:"inherit"},".cm-focused":{outline:"none"}}),v5=Pi.define([{tag:[O.comment,O.lineComment,O.blockComment,O.docComment],class:"tok-comment"},{tag:[O.keyword,O.controlKeyword,O.modifier,O.operatorKeyword],class:"tok-keyword"},{tag:[O.string,O.character,O.regexp,O.escape,O.special(O.string)],class:"tok-string"},{tag:[O.number,O.integer,O.float],class:"tok-number"},{tag:[O.bool,O.null,O.atom],class:"tok-boolean"},{tag:[O.operator,O.logicOperator,O.arithmeticOperator,O.compareOperator,O.updateOperator,O.definitionOperator],class:"tok-operator"},{tag:[O.punctuation,O.bracket,O.paren,O.brace,O.squareBracket,O.angleBracket,O.separator],class:"tok-punctuation"},{tag:[O.function(O.variableName),O.function(O.propertyName),O.macroName],class:"tok-function"},{tag:[O.variableName,O.local(O.variableName),O.self],class:"tok-variable"},{tag:[O.typeName,O.className,O.namespace],class:"tok-type"},{tag:[O.propertyName,O.labelName,O.definition(O.variableName)],class:"tok-property"},{tag:[O.tagName,O.heading,O.contentSeparator],class:"tok-tag"},{tag:[O.attributeName,O.attributeValue],class:"tok-attribute"},{tag:[O.url,O.link],class:"tok-url"},{tag:[O.invalid,O.deleted],class:"tok-invalid"}]),x5={json:()=>Promise.resolve().then(()=>(pS(),fS)).then(s=>({extension:s.json()})),html:()=>Promise.resolve().then(()=>(Mg(),Ww)).then(s=>({extension:s.html()})),javascript:()=>Promise.resolve().then(()=>(Eg(),Rw)).then(s=>({extension:s.javascript({jsx:!1,typescript:!1})})),css:()=>Promise.resolve().then(()=>(Gm(),VS)).then(s=>({extension:s.css()})),markdown:()=>Promise.resolve().then(()=>(Xk(),Nk)).then(s=>({extension:s.markdown()})),yaml:()=>Promise.resolve().then(()=>(tA(),Jk)).then(s=>({extension:s.yaml()}))},Gb=1e4;w5=Ul(s=>{let t=s.state.doc.toString();if(t.trim()==="")return[];try{return JSON.parse(t),[]}catch(e){let i=e instanceof Error?e.message:String(e),{from:r,to:n}=k5(i,t);return[{from:r,to:n,severity:"error",message:i.replace(/^SyntaxError:\s*/,""),source:"json"}]}})});function Od(s){return Bt.get(s)||null}function G1(s,t){Bt.set(s,t)}var Bt,hO=W(()=>{"use strict";Bt=new Map([["Row","row-ui"],["Column","col-ui"],["List","list-ui"],["ListItem","list-item-ui"],["Grid","grid-ui"],["Stack","stack-ui"],["Block","block-ui"],["Text","text-ui"],["Image","image-ui"],["Icon","icon-ui"],["Divider","divider-ui"],["Badge","badge-ui"],["Avatar","avatar-ui"],["AvatarGroup","avatar-group-ui"],["Progress","progress-ui"],["ProgressRow","progress-row-ui"],["DateRangePicker","date-range-picker-ui"],["DatetimePicker","datetime-picker-ui"],["CalendarGrid","calendar-grid-ui"],["CalendarPicker","calendar-picker-ui"],["Combobox","combobox-ui"],["Skeleton","skeleton-ui"],["Stepper","stepper-ui"],["StepperItem","stepper-item-ui"],["Tour","tour-ui"],["TourStep","tour-step-ui"],["IntegrationCard","integration-card-ui"],["Code","code-ui"],["Stat","stat-ui"],["EmptyState","empty-state-ui"],["Input","input-ui"],["TextField","input-ui"],["TextArea","textarea-ui"],["Field","field-ui"],["CheckBox","check-ui"],["Toggle","switch-ui"],["Switch","switch-ui"],["Slider","slider-ui"],["Range","range-ui"],["Rating","rating-ui"],["ChoicePicker","select-ui"],["Select","select-ui"],["Radio","radio-ui"],["DateTimeInput","calendar-picker-ui"],["CalendarPicker","calendar-picker-ui"],["ColorPicker","color-picker-ui"],["Upload","upload-ui"],["OtpInput","otp-input-ui"],["Button","button-ui"],["LoadingIndicator","progress-ui"],["ErrorContainer","card-ui"],["Card","card-ui"],["Tabs","tabs-ui"],["Tab","tab-ui"],["Panel","pane-ui"],["Pane","pane-ui"],["Modal","modal-ui"],["Dialog","modal-ui"],["Drawer","drawer-ui"],["Toast","toast-ui"],["AnchorBar","anchor-bar-ui"],["Popover","popover-ui"],["Accordion","accordion-ui"],["AccordionItem","accordion-item-ui"],["Alert","alert-ui"],["Tooltip","tooltip-ui"],["Menu","menu-ui"],["Section","section"],["Header","header"],["Footer","footer"],["Stream","stream-ui"],["Table","table-ui"],["ColDef","col-def"],["Chart","chart-ui"],["Embed","embed-ui"],["Swiper","swiper-ui"],["Slideshow","swiper-ui"],["Carousel","swiper-ui"],["Breadcrumb","breadcrumb-ui"],["Link","link-ui"],["Anchor","link-ui"],["Hyperlink","link-ui"],["NavLink","link-ui"],["Nav","nav-ui"],["NavGroup","nav-group-ui"],["NavItem","nav-item-ui"],["Noodles","noodles-ui"],["Pagination","pagination-ui"],["SegmentedControl","segmented-ui"],["Segment","segment-ui"],["ToggleGroup","toggle-group-ui"],["Command","command-ui"],["Kbd","kbd-ui"],["Toolbar","toolbar-ui"],["ToolbarGroup","toolbar-group-ui"],["Tag","tag-ui"],["Timeline","timeline-ui"],["TimelineItem","timeline-item-ui"],["button-ui","button-ui"],["card-ui","card-ui"],["text-ui","text-ui"],["input-ui","input-ui"],["text-field-ui","input-ui"],["select-ui","select-ui"],["toggle-ui","switch-ui"],["check-ui","check-ui"],["slider-ui","slider-ui"],["badge-ui","badge-ui"],["avatar-ui","avatar-ui"],["icon-ui","icon-ui"],["image-ui","image-ui"],["divider-ui","divider-ui"],["progress-ui","progress-ui"],["skeleton-ui","skeleton-ui"],["tabs-ui","tabs-ui"],["tab-ui","tab-ui"],["modal-ui","modal-ui"],["dialog-ui","modal-ui"],["drawer-ui","drawer-ui"],["toast-ui","toast-ui"],["popover-ui","popover-ui"],["panel-ui","pane-ui"],["accordion-ui","accordion-ui"],["alert-ui","alert-ui"],["tooltip-ui","tooltip-ui"],["menu-ui","menu-ui"],["table-ui","table-ui"],["chart-ui","chart-ui"],["code-ui","code-ui"],["textarea-ui","textarea-ui"],["radio-ui","radio-ui"],["tag-ui","tag-ui"],["search-ui","search-ui"],["upload-ui","upload-ui"],["breadcrumb-ui","breadcrumb-ui"],["link-ui","link-ui"],["nav-ui","nav-ui"],["noodles-ui","noodles-ui"],["pagination-ui","pagination-ui"],["segmented-control-ui","segmented-ui"],["segment-ui","segment-ui"],["command-ui","command-ui"],["calendar-picker-ui","calendar-picker-ui"],["color-picker-ui","color-picker-ui"],["kbd-ui","kbd-ui"],["toolbar-ui","toolbar-ui"],["otp-input-ui","otp-input-ui"],["embed-ui","embed-ui"],["stream-ui","stream-ui"],["row-ui","row-ui"],["col-ui","col-ui"],["grid-ui","grid-ui"],["stack-ui","stack-ui"],["block-ui","block-ui"],["list-ui","list-ui"],["range-ui","range-ui"],["datetime-ui","calendar-picker-ui"],["timeline-ui","timeline-ui"],["timeline-item-ui","timeline-item-ui"],["avatar-group-ui","avatar-group-ui"],["Keyboard","kbd-ui"],["DatePicker","calendar-picker-ui"],["CommandPalette","command-ui"],["FormContainer","form"],["Sidebar","admin-sidebar"],["Segmented","segmented-ui"],["OTP","otp-input-ui"],["Textarea","textarea-ui"],["RichText","richtext-ui"],["Richtext","richtext-ui"],["DescriptionList","description-list-ui"],["ActionItem","action-item-ui"],["ActionList","action-list-ui"],["Inspector","inspector-ui"],["Heatmap","heatmap-ui"],["ChatThread","chat-thread"],["ChatInput","chat-input-ui"],["OptionCard","option-card-ui"],["Option","option-card-ui"],["AdminCommand","admin-command"],["AdminContent","admin-content"],["AdminPage","admin-page"],["AdminPageBody","admin-page-body"],["AdminPageHeader","admin-page-header"],["AdminScroll","admin-scroll"],["AdminShell","admin-shell"],["AdminSidebar","admin-sidebar"],["AdminStatusbar","admin-statusbar"],["AdminTopbar","admin-topbar"],["ChatComposer","chat-composer"],["ChatEmpty","chat-empty"],["ChatHeader","chat-header"],["ChatShell","chat-shell"],["ChatSidebar","chat-sidebar"],["ChatStatus","chat-status"],["EditorCanvas","editor-canvas"],["EditorCanvasEmpty","editor-canvas-empty"],["EditorShell","editor-shell"],["EditorSidebar","editor-sidebar"],["EditorStatusbar","editor-statusbar"],["EditorToolbar","editor-toolbar"],["GenRoot","gen-root"],["SimpleContent","simple-content"],["SimpleHero","simple-hero"],["SimpleShell","simple-shell"],["ThemePanel","theme-panel"]])});function K1(s,t){if(!t||t==="/")return s;let e=t.replace(/^\//,"").split("/"),i=s;for(let r of e){if(i==null)return;i=i[r]}return i}function tD(s,t,e){if(!t||t==="/")return;let i=t.replace(/^\//,"").split("/"),r=s;for(let n=0;n<i.length-1;n++){let o=i[n];r[o]==null&&(r[o]={}),r=r[o]}r[i[i.length-1]]=e}var yd,aa,cO=W(()=>{"use strict";yd={provider:0,controller:1,source:2,action:3,lifecycle:4},aa=class{surfaceId;#t=new Map;#e={};#i={};#s=new Map;#r;#n;constructor(t,e,i){this.surfaceId=t,this.#r=e,this.#n=i}get context(){return{surfaceId:this.surfaceId,getElement:t=>this.#n.get(t)||null,getRootElement:()=>this.#r,getModel:t=>t?K1(this.#e,t):this.#e,setModel:(t,e)=>this.#a(t,e),getDockable:(t,e)=>this.#l(t,e),listDockables:t=>this.#h(t),emit:t=>this.#c(t),getParam:t=>this.#i[t],watchModel:(t,e)=>this.#o(t,e)}}dock(t){this.#t.has(t.id)&&this.undock(t.id);let e=t.dock(this.context);this.#t.set(t.id,{dockable:t,cleanup:typeof e=="function"?e:null})}dockAll(t){let e=[...t].sort((i,r)=>(yd[i.kind]??9)-(yd[r.kind]??9));for(let i of e)this.dock(i)}undock(t){let e=this.#t.get(t);e&&(e.cleanup?.(),e.dockable.undock(),this.#t.delete(t))}undockAll(){let t=[...this.#t.entries()].sort((e,i)=>(yd[i[1].dockable.kind]??9)-(yd[e[1].dockable.kind]??9));for(let[e]of t)this.undock(e)}undockMany(t){for(let e of t)this.undock(e)}setInitialModel(t){Object.assign(this.#e,t)}setParams(t){Object.assign(this.#i,t)}updateElements(t){this.#n=t}#a(t,e){tD(this.#e,t,e);for(let[i,r]of this.#s)if(t===i||t.startsWith(i+"/"))for(let n of r)n(K1(this.#e,i))}#o(t,e){return this.#s.has(t)||this.#s.set(t,new Set),this.#s.get(t).add(e),()=>{let i=this.#s.get(t);i?.delete(e),i?.size===0&&this.#s.delete(t)}}#l(t,e){let i=this.#t.get(e);return i&&i.dockable.kind===t?i.dockable:null}#h(t){let e=[];for(let{dockable:i}of this.#t.values())(!t||i.kind===t)&&e.push(i);return e}#c(t){let e=t.target?this.#n.get(t.target):this.#r;e&&e.dispatchEvent(new CustomEvent(t.event,{bubbles:!0,detail:t}))}}});var ve,Ks=W(()=>{"use strict";ve=class{get kind(){throw new Error("Dockable subclass must define kind")}get id(){throw new Error("Dockable subclass must define id")}dock(t){throw new Error("Dockable subclass must implement dock()")}undock(){}}});var la,uO=W(()=>{"use strict";Ks();la=class extends ve{kind="controller";id;type;hostId;config;bind;controller=null;#t;constructor(t,e){super(),this.id=t.id,this.type=t.type,this.hostId=t.host,this.config=t.config||{},this.bind=t.bind||null,this.#t=e}async dock(t){let e=t.getElement(this.hostId);if(!e){console.warn(`ControllerDock: host element "${this.hostId}" not found`);return}let i=await this.#t(this.type);if(!i){console.warn(`ControllerDock: unknown controller type "${this.type}"`);return}this.controller=new i(this.config),this.controller.connect(e);let r=[];if(this.bind)for(let[n,o]of Object.entries(this.bind)){if(this.controller.subscribe){let l=this.controller.subscribe(n,h=>{t.setModel(o,h)});l&&r.push(l)}let a=t.getModel(o);a!==void 0&&this.controller.setState&&this.controller.setState(n,a)}return e.controller=this.controller,()=>{e.controller=null,r.forEach(n=>n())}}undock(){this.controller&&(this.controller.disconnect?.(),this.controller=null)}}});var ha,dO=W(()=>{"use strict";Ks();ha=class extends ve{kind="source";id;uri;path;refresh;#t;#e=null;constructor(t,e){super(),this.id=t.id,this.uri=t.uri,this.path=t.path,this.refresh=t.refresh||"once",this.#t=e}dock(t){if(this.#e=t,this.#i(t),this.refresh==="on-focus"){let e=()=>this.#i(t);return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)}if(this.refresh.startsWith("interval:")){let e=parseInt(this.refresh.split(":")[1],10);if(e>0){let i=setInterval(()=>this.#i(t),e);return()=>clearInterval(i)}}if(this.refresh==="stream"){let e=this.#s(t);try{let i=new EventSource(e);return i.onmessage=r=>{try{t.setModel(this.path,JSON.parse(r.data))}catch{}},()=>i.close()}catch{console.warn(`DataSourceDock: stream failed for ${e}`)}}}undock(){this.#e=null}refetch(){this.#e&&this.#i(this.#e)}async#i(t){let e=this.#s(t);try{let i=await this.#t(e,t);i!==void 0&&t.setModel(this.path,i)}catch(i){console.warn(`DataSourceDock: fetch failed for ${e}`,i)}}#s(t){return this.uri.replace(/\{(\w+)\}/g,(e,i)=>t.getParam(i)??t.getModel("/"+i)??"")}}});var vd,ca,fO=W(()=>{"use strict";Ks();vd={press:"click",submit:"submit",input:"input",change:"change",select:"select",toggle:"change",dismiss:"close",navigate:"click",mount:"connectedCallback",unmount:"disconnectedCallback",focus:"focusin",blur:"focusout",drag:"dragstart",drop:"drop"},ca=class extends ve{kind="action";id;event;handler;config;onSuccess;onError;#t;constructor(t,e){super(),this.event=t.event,this.handler=t.handler,this.config=t.config||{},this.onSuccess=t.onSuccess||null,this.onError=t.onError||null,this.#t=e,this.id=`action:${this.event.event}:${this.event.target||"root"}:${this.handler}`}dock(t){let e=this.event.target?t.getElement(this.event.target):t.getRootElement();if(!e){console.warn(`ActionDock: target "${this.event.target}" not found`);return}let i=vd[this.event.event]||this.event.event,r=this.#t(this.handler);if(!r){console.warn(`ActionDock: unknown handler "${this.handler}"`);return}let n=async o=>{if(this.event.condition){let a=t.getModel(this.event.condition.path);if("equals"in this.event.condition&&a!==this.event.condition.equals||"notEquals"in this.event.condition&&a===this.event.condition.notEquals||"exists"in this.event.condition&&this.event.condition.exists&&a==null)return}try{let a=await r(this.config,t,o);if(this.onSuccess)for(let l of this.onSuccess){let h=this.#t(l.handler);h&&await h(l.config||{},t,a)}}catch(a){if(this.onError)for(let l of this.onError){let h=this.#t(l.handler);h&&await h(l.config||{},t,a)}else console.error(`ActionDock: handler "${this.handler}" failed`,a)}};if(this.event.debounce>0){let o=n,a;n=(...l)=>{clearTimeout(a),a=setTimeout(()=>o(...l),this.event.debounce)}}if(this.event.throttle>0){let o=n,a=0;n=(...l)=>{let h=Date.now();h-a>=this.event.throttle&&(a=h,o(...l))}}return e.addEventListener(i,n),()=>e.removeEventListener(i,n)}undock(){}}});var ua,pO=W(()=>{"use strict";Ks();ua=class extends ve{kind="provider";id;hostId;value;constructor(t){super(),this.id=`provider:${t.name}`,this.hostId=t.host||null,this.value=t.value??null}dock(t){let e=this.hostId?t.getElement(this.hostId):t.getRootElement();if(!e){console.warn(`ProviderDock: host "${this.hostId}" not found`);return}let i=document.createElement("a2ui-provider");return i.setAttribute("name",this.id.replace("provider:","")),i.value=this.value,e.parentNode?.insertBefore(i,e),i.appendChild(e),()=>{i.parentNode&&(i.parentNode.insertBefore(e,i),i.remove())}}undock(){}}});var da,mO=W(()=>{"use strict";Ks();da=class extends ve{kind="lifecycle";id="lifecycle";onMount;onUnmount;onModelChange;#t;#e=null;constructor(t,e){super(),this.onMount=t.onMount||[],this.onUnmount=t.onUnmount||[],this.onModelChange=t.onModelChange||[],this.#t=e}dock(t){this.#e=t;for(let i of this.onMount)this.#i(i,t);let e=this.onModelChange.map(i=>{let r=()=>this.#i(i,t);if(i.debounce>0){let n=r,o;r=()=>{clearTimeout(o),o=setTimeout(n,i.debounce)}}return t.watchModel(i.path,r)});return()=>e.forEach(i=>i())}undock(){if(this.#e){for(let t of this.onUnmount)this.#i(t,this.#e);this.#e=null}}async#i(t,e){let i=this.#t(t.handler);if(i)try{await i(t.config||{},e)}catch(r){console.warn(`LifecycleDock: ${t.handler} failed`,r)}}}});var J1,xe,Js=W(()=>{"use strict";J1=new WeakSet,xe=class s{#t=null;#e=new Set;get host(){return this.#t}connect(t){let e=this.constructor;!J1.has(e)&&e!==s&&(J1.add(e),e.schema||console.warn(`AdiaUI: ${e.name} extends BaseController without static schema`),this.getState===s.prototype.getState&&console.error(`AdiaUI: ${e.schema?.name??e.name} must implement getState()`)),this.#t&&this.#t!==t&&console.warn(`AdiaUI: ${e.schema?.name??e.name} already connected to a different host`),this.#t=t,this.onConnect(t),this.reflect()}disconnect(t){let e=t??this.#t;e&&(this.onDisconnect(e),this.#t=null)}subscribe(t){return this.#e.add(t),()=>this.#e.delete(t)}notify(){this.reflect();for(let t of this.#e)t()}onConnect(t){}onDisconnect(t){}reflect(){}getState(){throw new Error(`${this.constructor.schema?.name??this.constructor.name}: getState() not implemented`)}}});var tE={};Gt(tE,{FormController:()=>gO});var gO,eE=W(()=>{"use strict";Js();gO=class extends xe{static schema=Object.freeze({name:"form",state:{values:"object",errors:"object",dirty:"boolean",valid:"boolean"},commands:["set","validate","reset","setInitial"],attributes:["data-form-valid","data-form-invalid","data-form-dirty"]});#t={};#e={};#i={};#s={};constructor(t={}){super(),this.#t={...t},this.#e={...t}}onDisconnect(t){t.removeAttribute("data-form-valid"),t.removeAttribute("data-form-invalid"),t.removeAttribute("data-form-dirty")}getState(){let t=Object.keys(this.#e).some(i=>this.#e[i]!==this.#t[i]),e=Object.keys(this.#i).length===0;return{values:{...this.#e},errors:{...this.#i},dirty:t,valid:e}}reflect(){if(!this.host)return;let{dirty:t,valid:e}=this.getState();e?(this.host.setAttribute("data-form-valid",""),this.host.removeAttribute("data-form-invalid")):(this.host.setAttribute("data-form-invalid",""),this.host.removeAttribute("data-form-valid")),t?this.host.setAttribute("data-form-dirty",""):this.host.removeAttribute("data-form-dirty")}#r(t){let e=this.#s[t];if(!e){delete this.#i[t];return}let i=e(this.#e[t]);i===!0||i==null?delete this.#i[t]:this.#i[t]=typeof i=="string"?i:"Invalid"}commands={set:(t,e)=>{this.#e[t]=e,this.#r(t),this.notify()},validate:(t,e)=>{this.#s[t]=e,this.#r(t),this.notify()},reset:()=>{this.#e={...this.#t},this.#i={};for(let t of Object.keys(this.#s))this.#r(t);this.notify()},setInitial:t=>{this.#t={...t}}}}});var iE={};Gt(iE,{DataStreamController:()=>bO});var bO,sE=W(()=>{"use strict";Js();bO=class extends xe{static schema=Object.freeze({name:"data-stream",state:{data:"array",status:"string",error:"string"},commands:["push","pushMany","connect","poll","consume","stop","clear"],attributes:["data-stream-status"]});#t=[];#e;#i="idle";#s=null;#r=null;#n=0;#a=1;#o=null;#l=0;constructor({max:t=100,throttle:e=0,sample:i=1,initial:r=[]}={}){super(),this.#e=t,this.#n=e,this.#a=Math.max(1,Math.round(i)),this.#t=r.slice(-t)}getState(){return{data:this.#t,status:this.#i,error:this.#s}}reflect(){this.host&&this.host.setAttribute("data-stream-status",this.#i)}onDisconnect(){this.commands.stop()}#h(t){this.#l++,!(this.#a>1&&this.#l%this.#a!==0)&&(this.#t.push(t),this.#t.length>this.#e&&(this.#t=this.#t.slice(-this.#e)),this.#d())}#c(t){if(this.#a>1){let e=[];for(let i of t)this.#l++,this.#l%this.#a===0&&e.push(i);this.#t.push(...e)}else this.#t.push(...t);this.#t.length>this.#e&&(this.#t=this.#t.slice(-this.#e)),this.#d()}#d(){if(this.#n<=0){this.notify();return}this.#o===null&&(this.#o=setTimeout(()=>{this.#o=null,this.notify()},this.#n))}#u(t,e=null){this.#i=t,this.#s=e,this.notify()}commands={push:t=>{this.#h(t)},pushMany:t=>{this.#c(t)},connect:(t,e)=>{this.commands.stop(),this.#r=new AbortController,t==="sse"?this.#f(e):t==="ws"?this.#p(e):this.#u("error",`Unknown stream type: ${t}`)},poll:(t,e=2e3)=>{this.commands.stop(),this.#r=new AbortController,this.#m(t,e)},consume:t=>{this.commands.stop(),this.#r=new AbortController,this.#g(t)},stop:()=>{this.#r&&(this.#r.abort(),this.#r=null),this.#o!==null&&(clearTimeout(this.#o),this.#o=null),(this.#i==="streaming"||this.#i==="connecting")&&this.#u("stopped")},clear:()=>{this.#t=[],this.notify()}};#f(t){this.#u("connecting");let e=new EventSource(t),i=this.#r.signal;i.addEventListener("abort",()=>e.close()),e.onopen=()=>this.#u("streaming"),e.onmessage=r=>{try{let n=JSON.parse(r.data);this.#h(n)}catch{}},e.onerror=()=>{i.aborted||(this.#u("error","SSE connection lost"),e.close())}}#p(t){this.#u("connecting");let e=new WebSocket(t),i=this.#r.signal;i.addEventListener("abort",()=>e.close()),e.onopen=()=>this.#u("streaming"),e.onmessage=r=>{try{let n=JSON.parse(r.data);Array.isArray(n)?this.#c(n):this.#h(n)}catch{}},e.onerror=()=>{i.aborted||this.#u("error","WebSocket error")},e.onclose=()=>{i.aborted||this.#u("stopped")}}async#m(t,e){this.#u("streaming");let i=this.#r.signal;for(;!i.aborted;){try{let n=await(await fetch(t,{signal:i})).json();Array.isArray(n)?this.#c(n):this.#h(n)}catch(r){if(i.aborted)break;this.#u("error",r.message);break}await new Promise(r=>setTimeout(r,e))}}async#g(t){this.#u("streaming");let e=this.#r.signal;try{for await(let i of t){if(e.aborted)break;Array.isArray(i)?this.#c(i):this.#h(i)}e.aborted||this.#u("idle")}catch(i){e.aborted||this.#u("error",i.message)}}}});var rE={};Gt(rE,{SelectionController:()=>OO});var OO,nE=W(()=>{"use strict";Js();OO=class extends xe{static schema=Object.freeze({name:"selection",state:{selected:"Set",multiple:"boolean"},commands:["select","deselect","toggle","clear","selectAll"],attributes:["data-selection-active","data-selection-selected"]});#t=new Set;#e=!1;constructor({multiple:t=!1,initial:e=[]}={}){super(),this.#e=t;for(let i of e)this.#t.add(String(i))}onConnect(t){t.setAttribute("data-selection-active","")}onDisconnect(t){this.#i(t),t.removeAttribute("data-selection-active")}getState(){return{selected:new Set(this.#t),multiple:this.#e}}reflect(){if(!this.host)return;let t=this.host.querySelectorAll("[data-selection-key]");for(let e of t){let i=e.getAttribute("data-selection-key");this.#t.has(i)?e.setAttribute("data-selection-selected",""):e.removeAttribute("data-selection-selected")}}#i(t){let e=t.querySelectorAll("[data-selection-selected]");for(let i of e)i.removeAttribute("data-selection-selected")}commands={select:t=>{t=String(t),this.#e||this.#t.clear(),this.#t.add(t),this.notify()},deselect:t=>{this.#t.delete(String(t)),this.notify()},toggle:t=>{t=String(t),this.#t.has(t)?this.#t.delete(t):(this.#e||this.#t.clear(),this.#t.add(t)),this.notify()},clear:()=>{this.#t.clear(),this.notify()},selectAll:t=>{if(this.#e){for(let e of t)this.#t.add(String(e));this.notify()}}}}});var oE={};Gt(oE,{ToggleController:()=>yO});var yO,aE=W(()=>{"use strict";Js();yO=class extends xe{static schema=Object.freeze({name:"toggle",state:{on:"boolean"},commands:["toggle","set"],attributes:["data-toggle-on"]});#t=!1;constructor(t=!1){super(),this.#t=t}getState(){return{on:this.#t}}onDisconnect(t){t.removeAttribute("data-toggle-on")}reflect(){this.host&&(this.#t?this.host.setAttribute("data-toggle-on",""):this.host.removeAttribute("data-toggle-on"))}commands={toggle:()=>{this.#t=!this.#t,this.notify()},set:t=>{this.#t=!!t,this.notify()}}}});var lE={};Gt(lE,{AccordionController:()=>vO});var vO,hE=W(()=>{"use strict";Js();vO=class extends xe{static schema=Object.freeze({name:"accordion",state:{expanded:"Set",multiple:"boolean"},commands:["toggle","expand","collapse","collapseAll","expandAll"],attributes:["data-accordion-expanded"]});#t=new Set;#e=!1;constructor({multiple:t=!1,initial:e=[]}={}){super(),this.#e=t;for(let i of e)this.#t.add(String(i))}onDisconnect(t){let e=t.querySelectorAll("[data-accordion-expanded]");for(let i of e)i.removeAttribute("data-accordion-expanded")}getState(){return{expanded:new Set(this.#t),multiple:this.#e}}reflect(){if(!this.host)return;let t=this.host.querySelectorAll("[data-accordion-key]");for(let e of t){let i=e.getAttribute("data-accordion-key");this.#t.has(i)?e.setAttribute("data-accordion-expanded",""):e.removeAttribute("data-accordion-expanded")}}commands={toggle:t=>{t=String(t),this.#t.has(t)?this.#t.delete(t):(this.#e||this.#t.clear(),this.#t.add(t)),this.notify()},expand:t=>{t=String(t),this.#e||this.#t.clear(),this.#t.add(t),this.notify()},collapse:t=>{this.#t.delete(String(t)),this.notify()},collapseAll:()=>{this.#t.clear(),this.notify()},expandAll:t=>{if(this.#e){for(let e of t)this.#t.add(String(e));this.notify()}}}}});var cE={};Gt(cE,{StateMachineController:()=>xO});var xO,uE=W(()=>{"use strict";Js();xO=class extends xe{static schema={name:"state-machine",state:{current:"string",history:"string[]"},commands:["send","transition","reset"],attributes:["data-state"],config:{initial:"string",states:"object"}};#t="";#e="";#i={};#s=[];onConnect(t){let e=this.config||{};this.#e=e.initial||t.dataset?.initial||Object.keys(e.states||{})[0]||"",this.#i=this._validateStates(e.states||{}),this.#t=this.#e,this.#s=this.#t?[this.#t]:[],this.#t&&this._emit("stateEntered",{state:this.#t,initial:!0})}getState(){return{current:this.#t,history:[...this.#s]}}reflect(){this.host&&(this.#t?this.host.setAttribute("data-state",this.#t):this.host.removeAttribute("data-state"))}commands={send:t=>{if(!t||!this.#t)return;let i=(this.#i[this.#t]?.on||{})[t];i&&this._moveTo(i,{event:t})},transition:t=>{!t||!(t in this.#i)||this._moveTo(t,{forced:!0})},reset:()=>{this.#e&&this._moveTo(this.#e,{reset:!0})}};_moveTo(t,e){if(t===this.#t)return;let i=this.#t;i&&this._emit("stateExited",{state:i,target:t,...e}),this.#t=t,this.#s.push(t),this.notify(),this._emit("stateEntered",{state:t,from:i,...e})}_emit(t,e){this.host&&this.host.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:e}))}_validateStates(t){let e={},i=Object.keys(t);for(let r of i){let n=t[r]||{},o={};for(let[a,l]of Object.entries(n.on||{})){if(typeof l!="string"||!(l in t)){console.warn(`[state-machine] state "${r}" transition "${a}" \u2192 "${l}" \u2014 target not declared`);continue}o[a]=l}e[r]={on:o}}return e}}});function dE(s,t){Ni.controllers.set(s,t)}function fE(s,t){Ni.handlers.set(s,t)}function pE(s,t){Ni.resolvers.set(s,t)}async function xd(s){let t=Ni.controllers.get(s);return t?t():null}function Sd(s){return Ni.handlers.get(s)||null}async function Kl(s,t={}){let e=s;for(let[o,a]of Object.entries(t))e=e.replace(`{${o}}`,encodeURIComponent(a));let i=e.indexOf("://");if(i===-1)throw new Error(`Invalid URI: ${s}`);let r=e.slice(0,i),n=Ni.resolvers.get(r);if(!n)throw new Error(`No resolver for scheme "${r}"`);return n(e,t)}async function eD(s){let{action:t,params:e}=s,i=SO(t.body,s),r=t.uri;for(let[c,u]of Object.entries(e))r=r.replace(`{${c}}`,encodeURIComponent(u));let n=r.indexOf("://"),o=n>-1?r.slice(0,n):"api",a=Ni.resolvers.get(o),l=r.replace(/^\w+:\/\//,"/api/"),h=await fetch(l,{method:t.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!h.ok){let c=await h.text().catch(()=>"Request failed");throw new Error(c)}return h.json().catch(()=>({}))}async function iD(s){let{action:t}=s,e=SO(t.value,s);s.updateModel(t.path,e)}async function sD(s){let{action:t,params:e}=s,i=t.navigate||t.path||"";for(let[r,n]of Object.entries(e))i=i.replace(`{${r}}`,encodeURIComponent(n));i==="back"?history.back():i&&(location.hash=i)}async function rD(){history.back()}async function nD(s){let{action:t,controllers:e}=s,i=e[t.controllerId];if(!i?.commands?.[t.command]){console.warn(`Wiring: controller "${t.controllerId}" or command "${t.command}" not found`);return}return i.commands[t.command](t.args)}async function oD(s){let{action:t,source:e}=s,i=SO(t.detail,s);e.dispatchEvent(new CustomEvent(t.eventName||t.event,{bubbles:!0,detail:i}))}async function aD(s){let t=s.action.sourceId;return document.dispatchEvent(new CustomEvent("a2ui-refresh-source",{detail:{sourceId:t}})),{refreshSource:t}}async function lD(s){let{action:t}=s,e=typeof t=="string"?t:t.message||t.notify;document.dispatchEvent(new CustomEvent("a2ui-notify",{bubbles:!0,detail:{message:e,variant:t.variant||"info"}}))}function SO(s,t){if(s){if(typeof s!="object")return s;switch(s.from){case"event-detail":return s.key?t.event?.detail?.[s.key]:t.event?.detail;case"event-target":return s.key?t.source?.[s.key]:t.source?.value;case"model":return hD(t.dataModel,s.path);case"literal":return s.value;case"param":return t.params?.[s.key];default:return s}}}function hD(s,t){if(!t||!s)return;let e=t.split("/").filter(Boolean),i=s;for(let r of e){if(i==null||typeof i!="object")return;i=i[r]}return i}async function cD(s,t){let e=s.replace(/^resource:\/\//,"/api/"),i=await fetch(e);if(!i.ok)throw new Error(`Resource fetch failed: ${i.status}`);return i.json()}async function uD(s,t){let e=s.replace(/^api:\/\//,"https://"),i=await fetch(e);if(!i.ok)throw new Error(`API fetch failed: ${i.status}`);return i.json()}async function dD(s,t){return{_source:s,_mock:!0}}var Ni,wO=W(()=>{"use strict";Ni={controllers:new Map([["FormController",async()=>(await Promise.resolve().then(()=>(eE(),tE))).FormController],["DataStreamController",async()=>(await Promise.resolve().then(()=>(sE(),iE))).DataStreamController],["SelectionController",async()=>(await Promise.resolve().then(()=>(nE(),rE))).SelectionController],["ToggleController",async()=>(await Promise.resolve().then(()=>(aE(),oE))).ToggleController],["AccordionController",async()=>(await Promise.resolve().then(()=>(hE(),lE))).AccordionController],["StateMachineController",async()=>(await Promise.resolve().then(()=>(uE(),cE))).StateMachineController]]),handlers:new Map([["submit-resource",eD],["update-model",iD],["navigate",sD],["navigate-back",rD],["controller-command",nD],["emit-event",oD],["refresh-source",aD],["notify",lD]]),resolvers:new Map([["resource",cD],["api",uD],["mock",dD]])}});function fD(s){return async(t,e,i)=>{let r={action:t,event:i instanceof Event?i:null,source:i instanceof Event?i.target:null,dataModel:e.getModel(),updateModel:(n,o)=>e.setModel(n,o),controllers:Object.fromEntries(e.listDockables("controller").map(n=>[n.id,n.controller])),params:{},resolveData:Kl};return s(r)}}function pD(){let s=new Map;return t=>{if(s.has(t))return s.get(t);let e=Sd(t);if(!e)return null;let i=fD(e);return s.set(t,i),i}}function mD(){return async s=>xd(s)}function gD(){return async(s,t)=>Kl(s,{})}function wd(s){let t=[],e=pD(),i=mD(),r=gD();if(s.data?.sources)for(let o of s.data.sources)t.push(new ha(o,r));if(s.state?.controllers)for(let o of s.state.controllers)t.push(new la(o,i));if(s.actions)for(let o of s.actions)t.push(new ca(o,e));if(s.provides){let o=Array.isArray(s.provides)?s.provides:[s.provides];for(let a of o)t.push(new ua(a))}s.lifecycle&&t.push(new da(s.lifecycle,e));let n=s.state?.model||null;return{dockables:t,initialModel:n}}var kO=W(()=>{"use strict";uO();dO();fO();pO();mO();wO()});var mE={};Gt(mE,{WiringEngine:()=>Jl});var Jl,AO=W(()=>{"use strict";cO();kO();Jl=class{#t=new Map;#e;#i;constructor({updateDataModel:t,getElement:e}){this.#e=t,this.#i=e}async process(t){let{surfaceId:e}=t;if(!e)return;let i=this.#t.get(e);i||(i=this.#s(e),this.#t.set(e,i));try{t.data?.params&&i.setParams(this.#r(t.data.params));let{dockables:r,initialModel:n}=wd(t);n&&i.setInitialModel(n),t.undock&&i.undockMany(t.undock);for(let o of r)await i.dock(o)}catch(r){console.warn(`Wiring: error processing wireComponents for "${e}":`,r.message)}}teardown(t){let e=this.#t.get(t);e&&(e.undockAll(),this.#t.delete(t))}teardownAll(){for(let t of this.#t.keys())this.teardown(t)}getSurface(t){return this.#t.get(t)||null}getSurfaceState(t){let e=this.#t.get(t);if(!e)return null;let i=e.context.listDockables();return{surfaceId:t,controllerCount:i.filter(r=>r.kind==="controller").length,sourceCount:i.filter(r=>r.kind==="source").length,actionCount:i.filter(r=>r.kind==="action").length,providerCount:i.filter(r=>r.kind==="provider").length,hasLifecycle:i.some(r=>r.kind==="lifecycle"),totalDocked:i.length}}#s(t){let e={get:h=>this.#i(t,h),has:h=>!!this.#i(t,h)},i=this.#i(t,"root")||document.createElement("div"),r=new Proxy(new Map,{get(h,c){return c==="get"?u=>e.get(u):c==="has"?u=>e.has(u):h[c]}}),n=new aa(t,i,r),o=n.context,a=o.setModel,l=this.#e;return Object.defineProperty(n,"context",{get(){return{...o,setModel(c,u){a(c,u),l(t,c,u)}}}}),n}#r(t){let e={};for(let[i,r]of Object.entries(t))switch(r.from){case"route":{let o=location.hash.slice(1).match(new RegExp(`${r.key}/([^/]+)`));o&&(e[i]=o[1]);break}case"query":{let o=new URL(location.href).searchParams.get(r.key);o&&(e[i]=o);break}case"literal":e[i]=r.value;break;default:typeof r=="string"&&(e[i]=r)}return e}}});function fa(s){return yD.has(s.toLowerCase())?s.toLowerCase():s.replace(/([A-Z])/g,"-$1").toLowerCase()}function kd(s,t,e){if(t==="style"&&typeof e=="string"){s.style.cssText=e;return}if(bD.has(t)&&e!=null){if(t==="textContent"&&!OD.has(s.localName)){s.setAttribute("text",String(e));return}let i=e;if(typeof i=="string"&&(i.startsWith("[")||i.startsWith("{")))try{i=JSON.parse(i)}catch{}s[t]=i;return}if(typeof e=="boolean"){e?s.setAttribute(t,""):s.removeAttribute(t);return}e!=null?s.setAttribute(fa(t),String(e)):s.removeAttribute(fa(t))}var bD,OD,yD,EO=W(()=>{"use strict";bD=new Set(["data","columns","options","itemRenderer","textContent"]),OD=new Set(["h1","h2","h3","h4","h5","h6","p","small","span","em","strong","code","text-ui","kbd-ui"]),yD=new Set(["autocomplete","autofocus","autocapitalize","autocorrect","inputmode","enterkeyhint","spellcheck","maxlength","minlength","readonly","novalidate","formnovalidate","formaction","formenctype","formmethod","formtarget","multiple","pattern","placeholder","required","tabindex","accesskey","autoplay","autopictureinpicture","controls","crossorigin","disablepictureinpicture","disableremoteplayback","loop","muted","playsinline","preload","srcset","srcdoc","srclang","sizes","loading","decoding","fetchpriority","ismap","usemap","hreflang","referrerpolicy","download","contenteditable","contextmenu","draggable","dirname","colspan","rowspan","headers","allowfullscreen","allowpaymentrequest","itemid","itemprop","itemref","itemscope","itemtype","nomodule","nonce"])});var os,gE=W(()=>{"use strict";hO();EO();os=class s{#t;#e;#i=new Map;#s=new Map;#r=new Map;#n=[];#a=null;#o=!1;constructor(t,e=Bt,{batch:i=!1}={}){this.#t=t,this.#e=e,this.#o=i}process(t){t&&(this.#o?(this.#n.push(t),this.#a===null&&(this.#a=requestAnimationFrame(()=>this.#l()))):this.#h(t))}#l(){this.#a=null;let t=this.#n.splice(0);for(let e of t)this.#h(e)}#h(t){switch(t.type||t.messageType){case"createSurface":this.#u(t);break;case"updateComponents":this.#f(t);break;case"updateDataModel":this.#k(t);break;case"wireComponents":this.#d(t);break;case"deleteSurface":this.#A(t);break;case"updateStyles":this.#$(t);break;case"removeStyles":this.#R(t);break;case"meta":break;default:console.warn("A2UI: unknown message type",t.type)}}#c=null;async#d(t){if(!this.#c){let{WiringEngine:e}=await Promise.resolve().then(()=>(AO(),mE));this.#c=new e({updateDataModel:(i,r,n)=>{this.#k({surfaceId:i,path:r,value:n})},getElement:(i,r)=>this.#i.get(i)?.elements.get(r)||null})}await this.#c.process(t)}async processStream(t){for await(let e of t)this.process(e)}#u({surfaceId:t,catalogId:e,root:i}){if(this.#i.has(t))return;let r=document.createElement("div");r.setAttribute("data-a2ui-surface",t),e&&r.setAttribute("data-catalog",e),this.#t.appendChild(r),this.#i.set(t,{root:r,rootId:typeof i=="string"&&i?i:"root",elements:new Map,dataModel:{},bindings:new Map,adoptedSheets:new Map})}#f({surfaceId:t,components:e}){let i=this.#i.get(t);i||(i={root:this.#t,rootId:"root",elements:new Map,dataModel:{},bindings:new Map,adoptedSheets:new Map},this.#i.set(t,i),this.#t&&typeof this.#t.setAttribute=="function"&&this.#t.setAttribute("data-a2ui-surface",t));for(let l of e)if(!(!l.id&&l.id!==0)){if(l.component==="ContextBindings"){i.contextBindings=l;continue}try{let h=i.elements.get(l.id),c=l.component==="Text"?this.#x(l.variant,l):Od(l.component,this.#e);if(!c){h||(h=document.createElement("div"),h.setAttribute("data-a2ui-id",l.id),h.id=l.id,h.setAttribute("data-a2ui-unknown",l.component),h.textContent=`[unknown: ${l.component}]`,i.elements.set(l.id,h),this.#s.set(l.id,h));continue}if(!h)h=document.createElement(c),h.setAttribute("data-a2ui-id",l.id),h.id=l.id,i.elements.set(l.id,h),this.#s.set(l.id,h);else if(h.localName!==c){let d=document.createElement(c);d.setAttribute("data-a2ui-id",l.id),d.id=l.id,h.replaceWith(d),h=d,i.elements.set(l.id,h),this.#s.set(l.id,h)}l._surfaceId=t,Object.values(l).some(d=>d&&typeof d=="object"&&d.path)&&i.bindings.set(l.id,l),this.#v(h,l)}catch(h){console.warn(`A2UI: component "${l.id}" (${l.component}) failed:`,h.message)}}this.#y(e);let r=new Map;for(let l of e){for(let h of Array.isArray(l.children)?l.children:[])r.set(h,l.id);l.child&&r.set(l.child,l.id)}let n=(l,h)=>{let c=new Set,u=l;for(;u!=null;){if(u===h||c.has(u))return!0;c.add(u),u=r.get(u)}return!1};for(let l of e){let h=i.elements.get(l.id);if(h)try{let c=Array.isArray(l.children)?l.children:[];for(let u of c){if(u===l.id||n(l.id,u))continue;let d=i.elements.get(u);d&&d.parentElement!==h&&h.appendChild(d)}if(l.child&&l.child!==l.id&&!n(l.id,l.child)){let u=i.elements.get(l.child);u&&u.parentElement!==h&&h.appendChild(u)}}catch(c){console.warn(`A2UI: tree build failed for "${l.id}":`,c.message)}}let o=i.rootId??"root";if(e.find(l=>l.id===o)){let l=i.elements.get(o);l&&l.parentElement!==i.root&&i.root.appendChild(l)}}static#p=new Set(["Header","Section","Footer","Img","Image","Video","Picture","Iframe","Aside","Divider"]);static#m=new Set(["Header","Section","Footer"]);static#g=new Set(["header","body","footer"]);#O=new Set;#y(t){let e=new Map;for(let i of t)i.id!=null&&e.set(i.id,i);for(let i of t){let r=i.component==="Card"||i.component==="ErrorContainer",n=i.component==="Drawer";if(!r&&!n)continue;let o=n?s.#m:s.#p,a=n?"<drawer-ui>":"<card-ui>",l=Array.isArray(i.children)?i.children:[];for(let h of l){let c=e.get(h);if(!c||typeof c.slot=="string"&&s.#g.has(c.slot)||o.has(c.component))continue;let u=`${i.id}::${h}::${c.component}`;this.#O.has(u)||(this.#O.add(u),console.warn(`A2UI: ${a} (id="${i.id}") body must wrap "${c.component}" (id="${h}") in <Section>. Direct flow children bypass the canonical body slot and lose --card-inset margin. Canonical children: ${[...o].join(", ")}`+(n?', or slot="header|body|footer".':".")))}}}static#b={h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",h6:"h6",body:"p",caption:"small"};#x(t,e){return!e?.slot&&s.#b[t]?s.#b[t]:"text-ui"}#v(t,e){let i=new Set(["id","component","children","child","_surfaceId"]);e.component==="Text"&&e.variant&&!e.slot&&s.#b[e.variant]&&i.add("variant");let r=this.#r.get(e.id),n={};for(let[o,a]of Object.entries(e)){if(i.has(o))continue;let l=a&&typeof a=="object"&&a.path,h=this.#S(a,e._surfaceId);n[o]=h,!(r&&Object.is(r[o],h))&&(h==null&&!l||kd(t,o,h))}if(r)for(let o of Object.keys(r))!(o in n)&&!i.has(o)&&t.removeAttribute(fa(o));this.#r.set(e.id,n)}#S(t,e){if(t==null)return null;if(typeof t!="object")return t;if(t.path){let i=e?this.#i.get(e):null;return i?this.#w(i.dataModel,t.path):t.path}return t}#w(t,e){return!e||e==="/"?t:e.split("/").filter(Boolean).reduce((i,r)=>i?.[r],t)}#k({surfaceId:t,path:e,value:i}){let r=this.#i.get(t);if(r){if(!e||e==="/")r.dataModel=i??{};else{let n=e.split("/").filter(Boolean),o=r.dataModel;for(let a=0;a<n.length-1;a++)o[n[a]]==null&&(o[n[a]]={}),o=o[n[a]];o[n[n.length-1]]=i}for(let[n,o]of r.bindings){let a=r.elements.get(n);a&&this.#v(a,o)}}}#A({surfaceId:t}){let e=this.#i.get(t);if(e){this.#c?.teardown(t);for(let[i]of e.elements)this.#s.delete(i);if(e.adoptedSheets&&e.adoptedSheets.size>0){let i=new Set;for(let r of e.adoptedSheets.values())i.add(r.sheet);document.adoptedStyleSheets=document.adoptedStyleSheets.filter(r=>!i.has(r)),e.adoptedSheets.clear()}e.root.remove(),this.#i.delete(t)}}static#E=new Set(["root","html","body"]);#$({surfaceId:t,styleId:e,css:i}){if(typeof e!="string"||e.length===0){this.#Q(null,"styles-rejected",{surfaceId:t,styleId:e,reason:"invalid-payload: styleId must be a non-empty string"});return}if(typeof i!="string"){this.#Q(null,"styles-rejected",{surfaceId:t,styleId:e,reason:"invalid-payload: css must be a string"});return}let r=this.#i.get(t);if(!r){this.#Q(null,"styles-rejected",{surfaceId:t,styleId:e,reason:"no-such-surface"});return}let n=this.#T(i,t);if(n.rejected){this.#Q(r.root,"styles-rejected",{surfaceId:t,styleId:e,reason:n.reason});return}let o=r.adoptedSheets.get(e);o&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(a=>a!==o.sheet)),document.adoptedStyleSheets=[...document.adoptedStyleSheets,n.sheet],r.adoptedSheets.set(e,{sheet:n.sheet,ruleCount:n.sheet.cssRules.length,appliedAt:typeof performance<"u"?performance.now():Date.now()}),this.#Q(r.root,"styles-applied",{surfaceId:t,styleId:e,ruleCount:n.sheet.cssRules.length,validationWarnings:n.warnings})}#R({surfaceId:t,styleId:e}){let i=this.#i.get(t);if(!i)return;let r=i.adoptedSheets.get(e);r&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(n=>n!==r.sheet),i.adoptedSheets.delete(e),this.#Q(i.root,"styles-removed",{surfaceId:t,styleId:e}))}#T(t,e){let i=[];if(/^\s*@import\b/im.test(t))return{rejected:!0,reason:"forbidden-import"};if(/^\s*@charset\b/im.test(t))return{rejected:!0,reason:"forbidden-charset"};let r=new CSSStyleSheet;try{r.replaceSync(t)}catch(l){return{rejected:!0,reason:"parse-error: "+(l?.message||String(l))}}for(let l of r.cssRules){let h=this.#C(l);if(h)return{rejected:!0,reason:h}}if(/url\s*\(\s*["']?\s*(?:https?:|\/\/)/i.test(t))return{rejected:!0,reason:"external-url"};for(let l of r.cssRules)if(l.constructor?.name==="CSSPropertyRule"||l.cssText?.startsWith("@property")){let h=l.cssText.match(/@property\s+(--[\w-]+)/);h&&i.push({kind:"property-registered-globally",name:h[1]})}let n=this.#L(r,e),o=this.#M(r,e),a=new CSSStyleSheet;try{a.replaceSync(o)}catch(l){return{rejected:!0,reason:"scope-wrap-failed: "+(l?.message||String(l))}}return n.length>0&&i.push({kind:"animations-namespaced",count:n.length}),{rejected:!1,sheet:a,warnings:i}}#C(t){let e=t.cssText||"";if(/^@import\b/i.test(e))return"forbidden-import";if(/^@charset\b/i.test(e))return"forbidden-charset";if(/^@scope\b/i.test(e))return"forbidden-scope-directive";if(t.selectorText){let i=this.#I(t.selectorText);for(let r of i){let n=r.trim().replace(/^:scope\s*/,"");if(n.startsWith(":root"))return"forbidden-root-selector";let o=n.match(/^([a-zA-Z*][\w-]*)/);if(!o)continue;let a=o[1].toLowerCase();if(s.#E.has(a))return`forbidden-${a}-selector`}}return null}#I(t){let e=[],i=0,r=0;for(let n=0;n<t.length;n++){let o=t[n];o==="("?i++:o===")"?i--:o===","&&i===0&&(e.push(t.slice(r,n)),r=n+1)}return e.push(t.slice(r)),e}#L(t,e){let i=[],r=String(e).replace(/[^a-zA-Z0-9_-]/g,"_");for(let o=0;o<t.cssRules.length;o++){let a=t.cssRules[o];if(a.constructor?.name==="CSSKeyframesRule"||a.cssText?.startsWith("@keyframes")){let l=a.name;if(!l)continue;let h=`${r}_${l}`;try{a.name=h}catch{let c=a.cssText.replace(/@keyframes\s+[\w-]+/,`@keyframes ${h}`);t.deleteRule(o),t.insertRule(c,o)}i.push({from:l,to:h})}}if(i.length===0)return i;let n=new Map(i.map(o=>[o.from,o.to]));for(let o of t.cssRules)if(o.style)for(let a of["animation","animation-name"]){let l=o.style.getPropertyValue(a);if(!l)continue;let h=l.replace(/\b([\w-]+)\b/g,c=>n.has(c)?n.get(c):c);h!==l&&o.style.setProperty(a,h)}return i}#M(t,e){let i=[];for(let n of t.cssRules)i.push(n.cssText);return`@scope ([data-a2ui-surface="${String(e).replace(/"/g,'\\"')}"]) {
41
+ `&&(h++,l=u+1);let c=Math.min(e,l+Math.max(0,a-1));return{from:c,to:Math.min(e,c+1)}}let n=Math.max(0,e);return{from:Math.max(0,n-1),to:n}}var y5,v5,x5,Gb,w5,Jb=W(()=>{"use strict";ri();ki();O1();ci();M1();ii();y5=D.theme({"&":{fontFamily:"inherit",fontSize:"inherit",color:"inherit",backgroundColor:"transparent"},".cm-content":{caretColor:"inherit"},".cm-focused":{outline:"none"}}),v5=Pi.define([{tag:[O.comment,O.lineComment,O.blockComment,O.docComment],class:"tok-comment"},{tag:[O.keyword,O.controlKeyword,O.modifier,O.operatorKeyword],class:"tok-keyword"},{tag:[O.string,O.character,O.regexp,O.escape,O.special(O.string)],class:"tok-string"},{tag:[O.number,O.integer,O.float],class:"tok-number"},{tag:[O.bool,O.null,O.atom],class:"tok-boolean"},{tag:[O.operator,O.logicOperator,O.arithmeticOperator,O.compareOperator,O.updateOperator,O.definitionOperator],class:"tok-operator"},{tag:[O.punctuation,O.bracket,O.paren,O.brace,O.squareBracket,O.angleBracket,O.separator],class:"tok-punctuation"},{tag:[O.function(O.variableName),O.function(O.propertyName),O.macroName],class:"tok-function"},{tag:[O.variableName,O.local(O.variableName),O.self],class:"tok-variable"},{tag:[O.typeName,O.className,O.namespace],class:"tok-type"},{tag:[O.propertyName,O.labelName,O.definition(O.variableName)],class:"tok-property"},{tag:[O.tagName,O.heading,O.contentSeparator],class:"tok-tag"},{tag:[O.attributeName,O.attributeValue],class:"tok-attribute"},{tag:[O.url,O.link],class:"tok-url"},{tag:[O.invalid,O.deleted],class:"tok-invalid"}]),x5={json:()=>Promise.resolve().then(()=>(pS(),fS)).then(s=>({extension:s.json()})),html:()=>Promise.resolve().then(()=>(Mg(),Ww)).then(s=>({extension:s.html()})),javascript:()=>Promise.resolve().then(()=>(Eg(),Rw)).then(s=>({extension:s.javascript({jsx:!1,typescript:!1})})),css:()=>Promise.resolve().then(()=>(Gm(),VS)).then(s=>({extension:s.css()})),markdown:()=>Promise.resolve().then(()=>(Xk(),Nk)).then(s=>({extension:s.markdown()})),yaml:()=>Promise.resolve().then(()=>(tA(),Jk)).then(s=>({extension:s.yaml()}))},Gb=1e4;w5=Ul(s=>{let t=s.state.doc.toString();if(t.trim()==="")return[];try{return JSON.parse(t),[]}catch(e){let i=e instanceof Error?e.message:String(e),{from:r,to:n}=k5(i,t);return[{from:r,to:n,severity:"error",message:i.replace(/^SyntaxError:\s*/,""),source:"json"}]}})});function Od(s){return Bt.get(s)||null}function G1(s,t){Bt.set(s,t)}var Bt,hO=W(()=>{"use strict";Bt=new Map([["Row","row-ui"],["Column","col-ui"],["List","list-ui"],["ListItem","list-item-ui"],["Grid","grid-ui"],["Stack","stack-ui"],["Block","block-ui"],["Text","text-ui"],["Image","image-ui"],["Icon","icon-ui"],["Divider","divider-ui"],["Badge","badge-ui"],["Avatar","avatar-ui"],["AvatarGroup","avatar-group-ui"],["Progress","progress-ui"],["ProgressRow","progress-row-ui"],["DateRangePicker","date-range-picker-ui"],["DatetimePicker","datetime-picker-ui"],["CalendarGrid","calendar-grid-ui"],["CalendarPicker","calendar-picker-ui"],["Combobox","combobox-ui"],["Skeleton","skeleton-ui"],["Stepper","stepper-ui"],["StepperItem","stepper-item-ui"],["Tour","tour-ui"],["TourStep","tour-step-ui"],["IntegrationCard","integration-card-ui"],["Code","code-ui"],["Stat","stat-ui"],["EmptyState","empty-state-ui"],["Input","input-ui"],["TextField","input-ui"],["TextArea","textarea-ui"],["Field","field-ui"],["CheckBox","check-ui"],["Toggle","switch-ui"],["Switch","switch-ui"],["Slider","slider-ui"],["Range","range-ui"],["Rating","rating-ui"],["ChoicePicker","select-ui"],["Select","select-ui"],["Radio","radio-ui"],["DateTimeInput","calendar-picker-ui"],["CalendarPicker","calendar-picker-ui"],["ColorPicker","color-picker-ui"],["Upload","upload-ui"],["OtpInput","otp-input-ui"],["Button","button-ui"],["LoadingIndicator","progress-ui"],["ErrorContainer","card-ui"],["Card","card-ui"],["Tabs","tabs-ui"],["Tab","tab-ui"],["Panel","pane-ui"],["Pane","pane-ui"],["Modal","modal-ui"],["Dialog","modal-ui"],["Drawer","drawer-ui"],["Toast","toast-ui"],["AnchorBar","anchor-bar-ui"],["Popover","popover-ui"],["Accordion","accordion-ui"],["AccordionItem","accordion-item-ui"],["Alert","alert-ui"],["Tooltip","tooltip-ui"],["Menu","menu-ui"],["Section","section"],["Header","header"],["Footer","footer"],["Stream","stream-ui"],["Table","table-ui"],["ColDef","col-def"],["Chart","chart-ui"],["Embed","embed-ui"],["Swiper","swiper-ui"],["Slideshow","swiper-ui"],["Carousel","swiper-ui"],["Breadcrumb","breadcrumb-ui"],["Link","link-ui"],["Anchor","link-ui"],["Hyperlink","link-ui"],["NavLink","link-ui"],["Nav","nav-ui"],["NavGroup","nav-group-ui"],["NavItem","nav-item-ui"],["Noodles","noodles-ui"],["Pagination","pagination-ui"],["SegmentedControl","segmented-ui"],["Segment","segment-ui"],["ToggleGroup","toggle-group-ui"],["Command","command-ui"],["Kbd","kbd-ui"],["Toolbar","toolbar-ui"],["ToolbarGroup","toolbar-group-ui"],["Tag","tag-ui"],["Timeline","timeline-ui"],["TimelineItem","timeline-item-ui"],["button-ui","button-ui"],["card-ui","card-ui"],["text-ui","text-ui"],["input-ui","input-ui"],["text-field-ui","input-ui"],["select-ui","select-ui"],["toggle-ui","switch-ui"],["check-ui","check-ui"],["slider-ui","slider-ui"],["badge-ui","badge-ui"],["avatar-ui","avatar-ui"],["icon-ui","icon-ui"],["image-ui","image-ui"],["divider-ui","divider-ui"],["progress-ui","progress-ui"],["skeleton-ui","skeleton-ui"],["tabs-ui","tabs-ui"],["tab-ui","tab-ui"],["modal-ui","modal-ui"],["dialog-ui","modal-ui"],["drawer-ui","drawer-ui"],["toast-ui","toast-ui"],["popover-ui","popover-ui"],["panel-ui","pane-ui"],["accordion-ui","accordion-ui"],["alert-ui","alert-ui"],["tooltip-ui","tooltip-ui"],["menu-ui","menu-ui"],["table-ui","table-ui"],["chart-ui","chart-ui"],["code-ui","code-ui"],["textarea-ui","textarea-ui"],["radio-ui","radio-ui"],["tag-ui","tag-ui"],["search-ui","search-ui"],["upload-ui","upload-ui"],["breadcrumb-ui","breadcrumb-ui"],["link-ui","link-ui"],["nav-ui","nav-ui"],["noodles-ui","noodles-ui"],["pagination-ui","pagination-ui"],["segmented-control-ui","segmented-ui"],["segment-ui","segment-ui"],["command-ui","command-ui"],["calendar-picker-ui","calendar-picker-ui"],["color-picker-ui","color-picker-ui"],["kbd-ui","kbd-ui"],["toolbar-ui","toolbar-ui"],["otp-input-ui","otp-input-ui"],["embed-ui","embed-ui"],["stream-ui","stream-ui"],["row-ui","row-ui"],["col-ui","col-ui"],["grid-ui","grid-ui"],["stack-ui","stack-ui"],["block-ui","block-ui"],["list-ui","list-ui"],["range-ui","range-ui"],["datetime-ui","calendar-picker-ui"],["timeline-ui","timeline-ui"],["timeline-item-ui","timeline-item-ui"],["avatar-group-ui","avatar-group-ui"],["Keyboard","kbd-ui"],["DatePicker","calendar-picker-ui"],["CommandPalette","command-ui"],["FormContainer","form"],["Sidebar","admin-sidebar"],["Segmented","segmented-ui"],["OTP","otp-input-ui"],["Textarea","textarea-ui"],["RichText","richtext-ui"],["Richtext","richtext-ui"],["DescriptionList","description-list-ui"],["ActionItem","action-item-ui"],["ActionList","action-list-ui"],["Inspector","inspector-ui"],["Heatmap","heatmap-ui"],["ChatThread","chat-thread"],["ChatInput","chat-input-ui"],["OptionCard","option-card-ui"],["Option","option-card-ui"],["AdminCommand","admin-command"],["AdminContent","admin-content"],["AdminPage","admin-page"],["AdminPageBody","admin-page-body"],["AdminPageHeader","admin-page-header"],["AdminScroll","admin-scroll"],["AdminShell","admin-shell"],["AdminSidebar","admin-sidebar"],["AdminStatusbar","admin-statusbar"],["AdminTopbar","admin-topbar"],["ChatComposer","chat-composer"],["ChatEmpty","chat-empty"],["ChatHeader","chat-header"],["ChatShell","chat-shell"],["ChatSidebar","chat-sidebar"],["ChatStatus","chat-status"],["EditorCanvas","editor-canvas"],["EditorCanvasEmpty","editor-canvas-empty"],["EditorShell","editor-shell"],["EditorSidebar","editor-sidebar"],["EditorStatusbar","editor-statusbar"],["EditorToolbar","editor-toolbar"],["GenRoot","gen-root"],["SimpleContent","simple-content"],["SimpleHero","simple-hero"],["SimpleShell","simple-shell"],["ThemePanel","theme-panel"],["AdiaMark","adia-mark-ui"],["AdiaWordmark","adia-wordmark-ui"],["AgentArtifact","agent-artifact-ui"],["AgentFeedbackBar","agent-feedback-bar-ui"],["AgentQuestions","agent-questions-ui"],["AgentReasoning","agent-reasoning-ui"],["AgentSuggestions","agent-suggestions-ui"],["AgentTrace","agent-trace-ui"],["Aside","aside-ui"],["Blockquote","blockquote-ui"],["Canvas","canvas-ui"],["ChartLegend","chart-legend-ui"],["ColorInput","color-input-ui"],["ContextMenu","context-menu-ui"],["DemoToggle","demo-toggle-ui"],["DisplayField","display-field-ui"],["Feed","feed-ui"],["FeedItem","feed-item-ui"],["Fields","fields-ui"],["Frame","frame-ui"],["InlineEdit","inline-edit-ui"],["InlineMessage","inline-message-ui"],["ListWindow","list-window-ui"],["LoadingOverlay","loading-overlay-ui"],["Mark","mark-ui"],["MenuDivider","menu-divider-ui"],["MenuItem","menu-item-ui"],["MenuLabel","menu-label-ui"],["NumberFormat","number-format-ui"],["Page","page-ui"],["PasswordStrength","password-strength-ui"],["PipelineStatus","pipeline-status-ui"],["Preview","preview-ui"],["QRCode","qr-code-ui"],["RelativeTime","relative-time-ui"],["Search","search-ui"],["SkipNav","skip-nav-ui"],["Spinner","spinner-ui"],["StepProgress","step-progress-ui"],["Swatch","swatch-ui"],["TableOfContents","toc-ui"],["TableToolbar","table-toolbar-ui"],["TagsInput","tags-input-ui"],["ThemeProvider","theme-provider"],["TimePicker","time-picker-ui"],["ToggleOption","toggle-option-ui"],["ToggleScheme","toggle-scheme-ui"],["Tree","tree-ui"],["TreeItem","tree-item-ui"],["VisuallyHidden","visually-hidden-ui"]])});function K1(s,t){if(!t||t==="/")return s;let e=t.replace(/^\//,"").split("/"),i=s;for(let r of e){if(i==null)return;i=i[r]}return i}function tD(s,t,e){if(!t||t==="/")return;let i=t.replace(/^\//,"").split("/"),r=s;for(let n=0;n<i.length-1;n++){let o=i[n];r[o]==null&&(r[o]={}),r=r[o]}r[i[i.length-1]]=e}var yd,aa,cO=W(()=>{"use strict";yd={provider:0,controller:1,source:2,action:3,lifecycle:4},aa=class{surfaceId;#t=new Map;#e={};#i={};#s=new Map;#r;#n;constructor(t,e,i){this.surfaceId=t,this.#r=e,this.#n=i}get context(){return{surfaceId:this.surfaceId,getElement:t=>this.#n.get(t)||null,getRootElement:()=>this.#r,getModel:t=>t?K1(this.#e,t):this.#e,setModel:(t,e)=>this.#a(t,e),getDockable:(t,e)=>this.#l(t,e),listDockables:t=>this.#h(t),emit:t=>this.#c(t),getParam:t=>this.#i[t],watchModel:(t,e)=>this.#o(t,e)}}dock(t){this.#t.has(t.id)&&this.undock(t.id);let e=t.dock(this.context);this.#t.set(t.id,{dockable:t,cleanup:typeof e=="function"?e:null})}dockAll(t){let e=[...t].sort((i,r)=>(yd[i.kind]??9)-(yd[r.kind]??9));for(let i of e)this.dock(i)}undock(t){let e=this.#t.get(t);e&&(e.cleanup?.(),e.dockable.undock(),this.#t.delete(t))}undockAll(){let t=[...this.#t.entries()].sort((e,i)=>(yd[i[1].dockable.kind]??9)-(yd[e[1].dockable.kind]??9));for(let[e]of t)this.undock(e)}undockMany(t){for(let e of t)this.undock(e)}setInitialModel(t){Object.assign(this.#e,t)}setParams(t){Object.assign(this.#i,t)}updateElements(t){this.#n=t}#a(t,e){tD(this.#e,t,e);for(let[i,r]of this.#s)if(t===i||t.startsWith(i+"/"))for(let n of r)n(K1(this.#e,i))}#o(t,e){return this.#s.has(t)||this.#s.set(t,new Set),this.#s.get(t).add(e),()=>{let i=this.#s.get(t);i?.delete(e),i?.size===0&&this.#s.delete(t)}}#l(t,e){let i=this.#t.get(e);return i&&i.dockable.kind===t?i.dockable:null}#h(t){let e=[];for(let{dockable:i}of this.#t.values())(!t||i.kind===t)&&e.push(i);return e}#c(t){let e=t.target?this.#n.get(t.target):this.#r;e&&e.dispatchEvent(new CustomEvent(t.event,{bubbles:!0,detail:t}))}}});var ve,Ks=W(()=>{"use strict";ve=class{get kind(){throw new Error("Dockable subclass must define kind")}get id(){throw new Error("Dockable subclass must define id")}dock(t){throw new Error("Dockable subclass must implement dock()")}undock(){}}});var la,uO=W(()=>{"use strict";Ks();la=class extends ve{kind="controller";id;type;hostId;config;bind;controller=null;#t;constructor(t,e){super(),this.id=t.id,this.type=t.type,this.hostId=t.host,this.config=t.config||{},this.bind=t.bind||null,this.#t=e}async dock(t){let e=t.getElement(this.hostId);if(!e){console.warn(`ControllerDock: host element "${this.hostId}" not found`);return}let i=await this.#t(this.type);if(!i){console.warn(`ControllerDock: unknown controller type "${this.type}"`);return}this.controller=new i(this.config),this.controller.connect(e);let r=[];if(this.bind)for(let[n,o]of Object.entries(this.bind)){if(this.controller.subscribe){let l=this.controller.subscribe(n,h=>{t.setModel(o,h)});l&&r.push(l)}let a=t.getModel(o);a!==void 0&&this.controller.setState&&this.controller.setState(n,a)}return e.controller=this.controller,()=>{e.controller=null,r.forEach(n=>n())}}undock(){this.controller&&(this.controller.disconnect?.(),this.controller=null)}}});var ha,dO=W(()=>{"use strict";Ks();ha=class extends ve{kind="source";id;uri;path;refresh;#t;#e=null;constructor(t,e){super(),this.id=t.id,this.uri=t.uri,this.path=t.path,this.refresh=t.refresh||"once",this.#t=e}dock(t){if(this.#e=t,this.#i(t),this.refresh==="on-focus"){let e=()=>this.#i(t);return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)}if(this.refresh.startsWith("interval:")){let e=parseInt(this.refresh.split(":")[1],10);if(e>0){let i=setInterval(()=>this.#i(t),e);return()=>clearInterval(i)}}if(this.refresh==="stream"){let e=this.#s(t);try{let i=new EventSource(e);return i.onmessage=r=>{try{t.setModel(this.path,JSON.parse(r.data))}catch{}},()=>i.close()}catch{console.warn(`DataSourceDock: stream failed for ${e}`)}}}undock(){this.#e=null}refetch(){this.#e&&this.#i(this.#e)}async#i(t){let e=this.#s(t);try{let i=await this.#t(e,t);i!==void 0&&t.setModel(this.path,i)}catch(i){console.warn(`DataSourceDock: fetch failed for ${e}`,i)}}#s(t){return this.uri.replace(/\{(\w+)\}/g,(e,i)=>t.getParam(i)??t.getModel("/"+i)??"")}}});var vd,ca,fO=W(()=>{"use strict";Ks();vd={press:"click",submit:"submit",input:"input",change:"change",select:"select",toggle:"change",dismiss:"close",navigate:"click",mount:"connectedCallback",unmount:"disconnectedCallback",focus:"focusin",blur:"focusout",drag:"dragstart",drop:"drop"},ca=class extends ve{kind="action";id;event;handler;config;onSuccess;onError;#t;constructor(t,e){super(),this.event=t.event,this.handler=t.handler,this.config=t.config||{},this.onSuccess=t.onSuccess||null,this.onError=t.onError||null,this.#t=e,this.id=`action:${this.event.event}:${this.event.target||"root"}:${this.handler}`}dock(t){let e=this.event.target?t.getElement(this.event.target):t.getRootElement();if(!e){console.warn(`ActionDock: target "${this.event.target}" not found`);return}let i=vd[this.event.event]||this.event.event,r=this.#t(this.handler);if(!r){console.warn(`ActionDock: unknown handler "${this.handler}"`);return}let n=async o=>{if(this.event.condition){let a=t.getModel(this.event.condition.path);if("equals"in this.event.condition&&a!==this.event.condition.equals||"notEquals"in this.event.condition&&a===this.event.condition.notEquals||"exists"in this.event.condition&&this.event.condition.exists&&a==null)return}try{let a=await r(this.config,t,o);if(this.onSuccess)for(let l of this.onSuccess){let h=this.#t(l.handler);h&&await h(l.config||{},t,a)}}catch(a){if(this.onError)for(let l of this.onError){let h=this.#t(l.handler);h&&await h(l.config||{},t,a)}else console.error(`ActionDock: handler "${this.handler}" failed`,a)}};if(this.event.debounce>0){let o=n,a;n=(...l)=>{clearTimeout(a),a=setTimeout(()=>o(...l),this.event.debounce)}}if(this.event.throttle>0){let o=n,a=0;n=(...l)=>{let h=Date.now();h-a>=this.event.throttle&&(a=h,o(...l))}}return e.addEventListener(i,n),()=>e.removeEventListener(i,n)}undock(){}}});var ua,pO=W(()=>{"use strict";Ks();ua=class extends ve{kind="provider";id;hostId;value;constructor(t){super(),this.id=`provider:${t.name}`,this.hostId=t.host||null,this.value=t.value??null}dock(t){let e=this.hostId?t.getElement(this.hostId):t.getRootElement();if(!e){console.warn(`ProviderDock: host "${this.hostId}" not found`);return}let i=document.createElement("a2ui-provider");return i.setAttribute("name",this.id.replace("provider:","")),i.value=this.value,e.parentNode?.insertBefore(i,e),i.appendChild(e),()=>{i.parentNode&&(i.parentNode.insertBefore(e,i),i.remove())}}undock(){}}});var da,mO=W(()=>{"use strict";Ks();da=class extends ve{kind="lifecycle";id="lifecycle";onMount;onUnmount;onModelChange;#t;#e=null;constructor(t,e){super(),this.onMount=t.onMount||[],this.onUnmount=t.onUnmount||[],this.onModelChange=t.onModelChange||[],this.#t=e}dock(t){this.#e=t;for(let i of this.onMount)this.#i(i,t);let e=this.onModelChange.map(i=>{let r=()=>this.#i(i,t);if(i.debounce>0){let n=r,o;r=()=>{clearTimeout(o),o=setTimeout(n,i.debounce)}}return t.watchModel(i.path,r)});return()=>e.forEach(i=>i())}undock(){if(this.#e){for(let t of this.onUnmount)this.#i(t,this.#e);this.#e=null}}async#i(t,e){let i=this.#t(t.handler);if(i)try{await i(t.config||{},e)}catch(r){console.warn(`LifecycleDock: ${t.handler} failed`,r)}}}});var J1,xe,Js=W(()=>{"use strict";J1=new WeakSet,xe=class s{#t=null;#e=new Set;get host(){return this.#t}connect(t){let e=this.constructor;!J1.has(e)&&e!==s&&(J1.add(e),e.schema||console.warn(`AdiaUI: ${e.name} extends BaseController without static schema`),this.getState===s.prototype.getState&&console.error(`AdiaUI: ${e.schema?.name??e.name} must implement getState()`)),this.#t&&this.#t!==t&&console.warn(`AdiaUI: ${e.schema?.name??e.name} already connected to a different host`),this.#t=t,this.onConnect(t),this.reflect()}disconnect(t){let e=t??this.#t;e&&(this.onDisconnect(e),this.#t=null)}subscribe(t){return this.#e.add(t),()=>this.#e.delete(t)}notify(){this.reflect();for(let t of this.#e)t()}onConnect(t){}onDisconnect(t){}reflect(){}getState(){throw new Error(`${this.constructor.schema?.name??this.constructor.name}: getState() not implemented`)}}});var tE={};Gt(tE,{FormController:()=>gO});var gO,eE=W(()=>{"use strict";Js();gO=class extends xe{static schema=Object.freeze({name:"form",state:{values:"object",errors:"object",dirty:"boolean",valid:"boolean"},commands:["set","validate","reset","setInitial"],attributes:["data-form-valid","data-form-invalid","data-form-dirty"]});#t={};#e={};#i={};#s={};constructor(t={}){super(),this.#t={...t},this.#e={...t}}onDisconnect(t){t.removeAttribute("data-form-valid"),t.removeAttribute("data-form-invalid"),t.removeAttribute("data-form-dirty")}getState(){let t=Object.keys(this.#e).some(i=>this.#e[i]!==this.#t[i]),e=Object.keys(this.#i).length===0;return{values:{...this.#e},errors:{...this.#i},dirty:t,valid:e}}reflect(){if(!this.host)return;let{dirty:t,valid:e}=this.getState();e?(this.host.setAttribute("data-form-valid",""),this.host.removeAttribute("data-form-invalid")):(this.host.setAttribute("data-form-invalid",""),this.host.removeAttribute("data-form-valid")),t?this.host.setAttribute("data-form-dirty",""):this.host.removeAttribute("data-form-dirty")}#r(t){let e=this.#s[t];if(!e){delete this.#i[t];return}let i=e(this.#e[t]);i===!0||i==null?delete this.#i[t]:this.#i[t]=typeof i=="string"?i:"Invalid"}commands={set:(t,e)=>{this.#e[t]=e,this.#r(t),this.notify()},validate:(t,e)=>{this.#s[t]=e,this.#r(t),this.notify()},reset:()=>{this.#e={...this.#t},this.#i={};for(let t of Object.keys(this.#s))this.#r(t);this.notify()},setInitial:t=>{this.#t={...t}}}}});var iE={};Gt(iE,{DataStreamController:()=>bO});var bO,sE=W(()=>{"use strict";Js();bO=class extends xe{static schema=Object.freeze({name:"data-stream",state:{data:"array",status:"string",error:"string"},commands:["push","pushMany","connect","poll","consume","stop","clear"],attributes:["data-stream-status"]});#t=[];#e;#i="idle";#s=null;#r=null;#n=0;#a=1;#o=null;#l=0;constructor({max:t=100,throttle:e=0,sample:i=1,initial:r=[]}={}){super(),this.#e=t,this.#n=e,this.#a=Math.max(1,Math.round(i)),this.#t=r.slice(-t)}getState(){return{data:this.#t,status:this.#i,error:this.#s}}reflect(){this.host&&this.host.setAttribute("data-stream-status",this.#i)}onDisconnect(){this.commands.stop()}#h(t){this.#l++,!(this.#a>1&&this.#l%this.#a!==0)&&(this.#t.push(t),this.#t.length>this.#e&&(this.#t=this.#t.slice(-this.#e)),this.#d())}#c(t){if(this.#a>1){let e=[];for(let i of t)this.#l++,this.#l%this.#a===0&&e.push(i);this.#t.push(...e)}else this.#t.push(...t);this.#t.length>this.#e&&(this.#t=this.#t.slice(-this.#e)),this.#d()}#d(){if(this.#n<=0){this.notify();return}this.#o===null&&(this.#o=setTimeout(()=>{this.#o=null,this.notify()},this.#n))}#u(t,e=null){this.#i=t,this.#s=e,this.notify()}commands={push:t=>{this.#h(t)},pushMany:t=>{this.#c(t)},connect:(t,e)=>{this.commands.stop(),this.#r=new AbortController,t==="sse"?this.#f(e):t==="ws"?this.#p(e):this.#u("error",`Unknown stream type: ${t}`)},poll:(t,e=2e3)=>{this.commands.stop(),this.#r=new AbortController,this.#m(t,e)},consume:t=>{this.commands.stop(),this.#r=new AbortController,this.#g(t)},stop:()=>{this.#r&&(this.#r.abort(),this.#r=null),this.#o!==null&&(clearTimeout(this.#o),this.#o=null),(this.#i==="streaming"||this.#i==="connecting")&&this.#u("stopped")},clear:()=>{this.#t=[],this.notify()}};#f(t){this.#u("connecting");let e=new EventSource(t),i=this.#r.signal;i.addEventListener("abort",()=>e.close()),e.onopen=()=>this.#u("streaming"),e.onmessage=r=>{try{let n=JSON.parse(r.data);this.#h(n)}catch{}},e.onerror=()=>{i.aborted||(this.#u("error","SSE connection lost"),e.close())}}#p(t){this.#u("connecting");let e=new WebSocket(t),i=this.#r.signal;i.addEventListener("abort",()=>e.close()),e.onopen=()=>this.#u("streaming"),e.onmessage=r=>{try{let n=JSON.parse(r.data);Array.isArray(n)?this.#c(n):this.#h(n)}catch{}},e.onerror=()=>{i.aborted||this.#u("error","WebSocket error")},e.onclose=()=>{i.aborted||this.#u("stopped")}}async#m(t,e){this.#u("streaming");let i=this.#r.signal;for(;!i.aborted;){try{let n=await(await fetch(t,{signal:i})).json();Array.isArray(n)?this.#c(n):this.#h(n)}catch(r){if(i.aborted)break;this.#u("error",r.message);break}await new Promise(r=>setTimeout(r,e))}}async#g(t){this.#u("streaming");let e=this.#r.signal;try{for await(let i of t){if(e.aborted)break;Array.isArray(i)?this.#c(i):this.#h(i)}e.aborted||this.#u("idle")}catch(i){e.aborted||this.#u("error",i.message)}}}});var rE={};Gt(rE,{SelectionController:()=>OO});var OO,nE=W(()=>{"use strict";Js();OO=class extends xe{static schema=Object.freeze({name:"selection",state:{selected:"Set",multiple:"boolean"},commands:["select","deselect","toggle","clear","selectAll"],attributes:["data-selection-active","data-selection-selected"]});#t=new Set;#e=!1;constructor({multiple:t=!1,initial:e=[]}={}){super(),this.#e=t;for(let i of e)this.#t.add(String(i))}onConnect(t){t.setAttribute("data-selection-active","")}onDisconnect(t){this.#i(t),t.removeAttribute("data-selection-active")}getState(){return{selected:new Set(this.#t),multiple:this.#e}}reflect(){if(!this.host)return;let t=this.host.querySelectorAll("[data-selection-key]");for(let e of t){let i=e.getAttribute("data-selection-key");this.#t.has(i)?e.setAttribute("data-selection-selected",""):e.removeAttribute("data-selection-selected")}}#i(t){let e=t.querySelectorAll("[data-selection-selected]");for(let i of e)i.removeAttribute("data-selection-selected")}commands={select:t=>{t=String(t),this.#e||this.#t.clear(),this.#t.add(t),this.notify()},deselect:t=>{this.#t.delete(String(t)),this.notify()},toggle:t=>{t=String(t),this.#t.has(t)?this.#t.delete(t):(this.#e||this.#t.clear(),this.#t.add(t)),this.notify()},clear:()=>{this.#t.clear(),this.notify()},selectAll:t=>{if(this.#e){for(let e of t)this.#t.add(String(e));this.notify()}}}}});var oE={};Gt(oE,{ToggleController:()=>yO});var yO,aE=W(()=>{"use strict";Js();yO=class extends xe{static schema=Object.freeze({name:"toggle",state:{on:"boolean"},commands:["toggle","set"],attributes:["data-toggle-on"]});#t=!1;constructor(t=!1){super(),this.#t=t}getState(){return{on:this.#t}}onDisconnect(t){t.removeAttribute("data-toggle-on")}reflect(){this.host&&(this.#t?this.host.setAttribute("data-toggle-on",""):this.host.removeAttribute("data-toggle-on"))}commands={toggle:()=>{this.#t=!this.#t,this.notify()},set:t=>{this.#t=!!t,this.notify()}}}});var lE={};Gt(lE,{AccordionController:()=>vO});var vO,hE=W(()=>{"use strict";Js();vO=class extends xe{static schema=Object.freeze({name:"accordion",state:{expanded:"Set",multiple:"boolean"},commands:["toggle","expand","collapse","collapseAll","expandAll"],attributes:["data-accordion-expanded"]});#t=new Set;#e=!1;constructor({multiple:t=!1,initial:e=[]}={}){super(),this.#e=t;for(let i of e)this.#t.add(String(i))}onDisconnect(t){let e=t.querySelectorAll("[data-accordion-expanded]");for(let i of e)i.removeAttribute("data-accordion-expanded")}getState(){return{expanded:new Set(this.#t),multiple:this.#e}}reflect(){if(!this.host)return;let t=this.host.querySelectorAll("[data-accordion-key]");for(let e of t){let i=e.getAttribute("data-accordion-key");this.#t.has(i)?e.setAttribute("data-accordion-expanded",""):e.removeAttribute("data-accordion-expanded")}}commands={toggle:t=>{t=String(t),this.#t.has(t)?this.#t.delete(t):(this.#e||this.#t.clear(),this.#t.add(t)),this.notify()},expand:t=>{t=String(t),this.#e||this.#t.clear(),this.#t.add(t),this.notify()},collapse:t=>{this.#t.delete(String(t)),this.notify()},collapseAll:()=>{this.#t.clear(),this.notify()},expandAll:t=>{if(this.#e){for(let e of t)this.#t.add(String(e));this.notify()}}}}});var cE={};Gt(cE,{StateMachineController:()=>xO});var xO,uE=W(()=>{"use strict";Js();xO=class extends xe{static schema={name:"state-machine",state:{current:"string",history:"string[]"},commands:["send","transition","reset"],attributes:["data-state"],config:{initial:"string",states:"object"}};#t="";#e="";#i={};#s=[];onConnect(t){let e=this.config||{};this.#e=e.initial||t.dataset?.initial||Object.keys(e.states||{})[0]||"",this.#i=this._validateStates(e.states||{}),this.#t=this.#e,this.#s=this.#t?[this.#t]:[],this.#t&&this._emit("stateEntered",{state:this.#t,initial:!0})}getState(){return{current:this.#t,history:[...this.#s]}}reflect(){this.host&&(this.#t?this.host.setAttribute("data-state",this.#t):this.host.removeAttribute("data-state"))}commands={send:t=>{if(!t||!this.#t)return;let i=(this.#i[this.#t]?.on||{})[t];i&&this._moveTo(i,{event:t})},transition:t=>{!t||!(t in this.#i)||this._moveTo(t,{forced:!0})},reset:()=>{this.#e&&this._moveTo(this.#e,{reset:!0})}};_moveTo(t,e){if(t===this.#t)return;let i=this.#t;i&&this._emit("stateExited",{state:i,target:t,...e}),this.#t=t,this.#s.push(t),this.notify(),this._emit("stateEntered",{state:t,from:i,...e})}_emit(t,e){this.host&&this.host.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:e}))}_validateStates(t){let e={},i=Object.keys(t);for(let r of i){let n=t[r]||{},o={};for(let[a,l]of Object.entries(n.on||{})){if(typeof l!="string"||!(l in t)){console.warn(`[state-machine] state "${r}" transition "${a}" \u2192 "${l}" \u2014 target not declared`);continue}o[a]=l}e[r]={on:o}}return e}}});function dE(s,t){Ni.controllers.set(s,t)}function fE(s,t){Ni.handlers.set(s,t)}function pE(s,t){Ni.resolvers.set(s,t)}async function xd(s){let t=Ni.controllers.get(s);return t?t():null}function Sd(s){return Ni.handlers.get(s)||null}async function Kl(s,t={}){let e=s;for(let[o,a]of Object.entries(t))e=e.replace(`{${o}}`,encodeURIComponent(a));let i=e.indexOf("://");if(i===-1)throw new Error(`Invalid URI: ${s}`);let r=e.slice(0,i),n=Ni.resolvers.get(r);if(!n)throw new Error(`No resolver for scheme "${r}"`);return n(e,t)}async function eD(s){let{action:t,params:e}=s,i=SO(t.body,s),r=t.uri;for(let[c,u]of Object.entries(e))r=r.replace(`{${c}}`,encodeURIComponent(u));let n=r.indexOf("://"),o=n>-1?r.slice(0,n):"api",a=Ni.resolvers.get(o),l=r.replace(/^\w+:\/\//,"/api/"),h=await fetch(l,{method:t.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!h.ok){let c=await h.text().catch(()=>"Request failed");throw new Error(c)}return h.json().catch(()=>({}))}async function iD(s){let{action:t}=s,e=SO(t.value,s);s.updateModel(t.path,e)}async function sD(s){let{action:t,params:e}=s,i=t.navigate||t.path||"";for(let[r,n]of Object.entries(e))i=i.replace(`{${r}}`,encodeURIComponent(n));i==="back"?history.back():i&&(location.hash=i)}async function rD(){history.back()}async function nD(s){let{action:t,controllers:e}=s,i=e[t.controllerId];if(!i?.commands?.[t.command]){console.warn(`Wiring: controller "${t.controllerId}" or command "${t.command}" not found`);return}return i.commands[t.command](t.args)}async function oD(s){let{action:t,source:e}=s,i=SO(t.detail,s);e.dispatchEvent(new CustomEvent(t.eventName||t.event,{bubbles:!0,detail:i}))}async function aD(s){let t=s.action.sourceId;return document.dispatchEvent(new CustomEvent("a2ui-refresh-source",{detail:{sourceId:t}})),{refreshSource:t}}async function lD(s){let{action:t}=s,e=typeof t=="string"?t:t.message||t.notify;document.dispatchEvent(new CustomEvent("a2ui-notify",{bubbles:!0,detail:{message:e,variant:t.variant||"info"}}))}function SO(s,t){if(s){if(typeof s!="object")return s;switch(s.from){case"event-detail":return s.key?t.event?.detail?.[s.key]:t.event?.detail;case"event-target":return s.key?t.source?.[s.key]:t.source?.value;case"model":return hD(t.dataModel,s.path);case"literal":return s.value;case"param":return t.params?.[s.key];default:return s}}}function hD(s,t){if(!t||!s)return;let e=t.split("/").filter(Boolean),i=s;for(let r of e){if(i==null||typeof i!="object")return;i=i[r]}return i}async function cD(s,t){let e=s.replace(/^resource:\/\//,"/api/"),i=await fetch(e);if(!i.ok)throw new Error(`Resource fetch failed: ${i.status}`);return i.json()}async function uD(s,t){let e=s.replace(/^api:\/\//,"https://"),i=await fetch(e);if(!i.ok)throw new Error(`API fetch failed: ${i.status}`);return i.json()}async function dD(s,t){return{_source:s,_mock:!0}}var Ni,wO=W(()=>{"use strict";Ni={controllers:new Map([["FormController",async()=>(await Promise.resolve().then(()=>(eE(),tE))).FormController],["DataStreamController",async()=>(await Promise.resolve().then(()=>(sE(),iE))).DataStreamController],["SelectionController",async()=>(await Promise.resolve().then(()=>(nE(),rE))).SelectionController],["ToggleController",async()=>(await Promise.resolve().then(()=>(aE(),oE))).ToggleController],["AccordionController",async()=>(await Promise.resolve().then(()=>(hE(),lE))).AccordionController],["StateMachineController",async()=>(await Promise.resolve().then(()=>(uE(),cE))).StateMachineController]]),handlers:new Map([["submit-resource",eD],["update-model",iD],["navigate",sD],["navigate-back",rD],["controller-command",nD],["emit-event",oD],["refresh-source",aD],["notify",lD]]),resolvers:new Map([["resource",cD],["api",uD],["mock",dD]])}});function fD(s){return async(t,e,i)=>{let r={action:t,event:i instanceof Event?i:null,source:i instanceof Event?i.target:null,dataModel:e.getModel(),updateModel:(n,o)=>e.setModel(n,o),controllers:Object.fromEntries(e.listDockables("controller").map(n=>[n.id,n.controller])),params:{},resolveData:Kl};return s(r)}}function pD(){let s=new Map;return t=>{if(s.has(t))return s.get(t);let e=Sd(t);if(!e)return null;let i=fD(e);return s.set(t,i),i}}function mD(){return async s=>xd(s)}function gD(){return async(s,t)=>Kl(s,{})}function wd(s){let t=[],e=pD(),i=mD(),r=gD();if(s.data?.sources)for(let o of s.data.sources)t.push(new ha(o,r));if(s.state?.controllers)for(let o of s.state.controllers)t.push(new la(o,i));if(s.actions)for(let o of s.actions)t.push(new ca(o,e));if(s.provides){let o=Array.isArray(s.provides)?s.provides:[s.provides];for(let a of o)t.push(new ua(a))}s.lifecycle&&t.push(new da(s.lifecycle,e));let n=s.state?.model||null;return{dockables:t,initialModel:n}}var kO=W(()=>{"use strict";uO();dO();fO();pO();mO();wO()});var mE={};Gt(mE,{WiringEngine:()=>Jl});var Jl,AO=W(()=>{"use strict";cO();kO();Jl=class{#t=new Map;#e;#i;constructor({updateDataModel:t,getElement:e}){this.#e=t,this.#i=e}async process(t){let{surfaceId:e}=t;if(!e)return;let i=this.#t.get(e);i||(i=this.#s(e),this.#t.set(e,i));try{t.data?.params&&i.setParams(this.#r(t.data.params));let{dockables:r,initialModel:n}=wd(t);n&&i.setInitialModel(n),t.undock&&i.undockMany(t.undock);for(let o of r)await i.dock(o)}catch(r){console.warn(`Wiring: error processing wireComponents for "${e}":`,r.message)}}teardown(t){let e=this.#t.get(t);e&&(e.undockAll(),this.#t.delete(t))}teardownAll(){for(let t of this.#t.keys())this.teardown(t)}getSurface(t){return this.#t.get(t)||null}getSurfaceState(t){let e=this.#t.get(t);if(!e)return null;let i=e.context.listDockables();return{surfaceId:t,controllerCount:i.filter(r=>r.kind==="controller").length,sourceCount:i.filter(r=>r.kind==="source").length,actionCount:i.filter(r=>r.kind==="action").length,providerCount:i.filter(r=>r.kind==="provider").length,hasLifecycle:i.some(r=>r.kind==="lifecycle"),totalDocked:i.length}}#s(t){let e={get:h=>this.#i(t,h),has:h=>!!this.#i(t,h)},i=this.#i(t,"root")||document.createElement("div"),r=new Proxy(new Map,{get(h,c){return c==="get"?u=>e.get(u):c==="has"?u=>e.has(u):h[c]}}),n=new aa(t,i,r),o=n.context,a=o.setModel,l=this.#e;return Object.defineProperty(n,"context",{get(){return{...o,setModel(c,u){a(c,u),l(t,c,u)}}}}),n}#r(t){let e={};for(let[i,r]of Object.entries(t))switch(r.from){case"route":{let o=location.hash.slice(1).match(new RegExp(`${r.key}/([^/]+)`));o&&(e[i]=o[1]);break}case"query":{let o=new URL(location.href).searchParams.get(r.key);o&&(e[i]=o);break}case"literal":e[i]=r.value;break;default:typeof r=="string"&&(e[i]=r)}return e}}});function fa(s){return yD.has(s.toLowerCase())?s.toLowerCase():s.replace(/([A-Z])/g,"-$1").toLowerCase()}function kd(s,t,e){if(t==="style"&&typeof e=="string"){s.style.cssText=e;return}if(bD.has(t)&&e!=null){if(t==="textContent"&&!OD.has(s.localName)){s.setAttribute("text",String(e));return}let i=e;if(typeof i=="string"&&(i.startsWith("[")||i.startsWith("{")))try{i=JSON.parse(i)}catch{}s[t]=i;return}if(typeof e=="boolean"){e?s.setAttribute(t,""):s.removeAttribute(t);return}e!=null?s.setAttribute(fa(t),String(e)):s.removeAttribute(fa(t))}var bD,OD,yD,EO=W(()=>{"use strict";bD=new Set(["data","columns","options","itemRenderer","textContent"]),OD=new Set(["h1","h2","h3","h4","h5","h6","p","small","span","em","strong","code","text-ui","kbd-ui"]),yD=new Set(["autocomplete","autofocus","autocapitalize","autocorrect","inputmode","enterkeyhint","spellcheck","maxlength","minlength","readonly","novalidate","formnovalidate","formaction","formenctype","formmethod","formtarget","multiple","pattern","placeholder","required","tabindex","accesskey","autoplay","autopictureinpicture","controls","crossorigin","disablepictureinpicture","disableremoteplayback","loop","muted","playsinline","preload","srcset","srcdoc","srclang","sizes","loading","decoding","fetchpriority","ismap","usemap","hreflang","referrerpolicy","download","contenteditable","contextmenu","draggable","dirname","colspan","rowspan","headers","allowfullscreen","allowpaymentrequest","itemid","itemprop","itemref","itemscope","itemtype","nomodule","nonce"])});var os,gE=W(()=>{"use strict";hO();EO();os=class s{#t;#e;#i=new Map;#s=new Map;#r=new Map;#n=[];#a=null;#o=!1;constructor(t,e=Bt,{batch:i=!1}={}){this.#t=t,this.#e=e,this.#o=i}process(t){t&&(this.#o?(this.#n.push(t),this.#a===null&&(this.#a=requestAnimationFrame(()=>this.#l()))):this.#h(t))}#l(){this.#a=null;let t=this.#n.splice(0);for(let e of t)this.#h(e)}#h(t){switch(t.type||t.messageType){case"createSurface":this.#u(t);break;case"updateComponents":this.#f(t);break;case"updateDataModel":this.#k(t);break;case"wireComponents":this.#d(t);break;case"deleteSurface":this.#A(t);break;case"updateStyles":this.#$(t);break;case"removeStyles":this.#R(t);break;case"meta":break;default:console.warn("A2UI: unknown message type",t.type)}}#c=null;async#d(t){if(!this.#c){let{WiringEngine:e}=await Promise.resolve().then(()=>(AO(),mE));this.#c=new e({updateDataModel:(i,r,n)=>{this.#k({surfaceId:i,path:r,value:n})},getElement:(i,r)=>this.#i.get(i)?.elements.get(r)||null})}await this.#c.process(t)}async processStream(t){for await(let e of t)this.process(e)}#u({surfaceId:t,catalogId:e,root:i}){if(this.#i.has(t))return;let r=document.createElement("div");r.setAttribute("data-a2ui-surface",t),e&&r.setAttribute("data-catalog",e),this.#t.appendChild(r),this.#i.set(t,{root:r,rootId:typeof i=="string"&&i?i:"root",elements:new Map,dataModel:{},bindings:new Map,adoptedSheets:new Map})}#f({surfaceId:t,components:e}){let i=this.#i.get(t);i||(i={root:this.#t,rootId:"root",elements:new Map,dataModel:{},bindings:new Map,adoptedSheets:new Map},this.#i.set(t,i),this.#t&&typeof this.#t.setAttribute=="function"&&this.#t.setAttribute("data-a2ui-surface",t));for(let l of e)if(!(!l.id&&l.id!==0)){if(l.component==="ContextBindings"){i.contextBindings=l;continue}try{let h=i.elements.get(l.id),c=l.component==="Text"?this.#x(l.variant,l):Od(l.component,this.#e);if(!c){h||(h=document.createElement("div"),h.setAttribute("data-a2ui-id",l.id),h.id=l.id,h.setAttribute("data-a2ui-unknown",l.component),h.textContent=`[unknown: ${l.component}]`,i.elements.set(l.id,h),this.#s.set(l.id,h));continue}if(!h)h=document.createElement(c),h.setAttribute("data-a2ui-id",l.id),h.id=l.id,i.elements.set(l.id,h),this.#s.set(l.id,h);else if(h.localName!==c){let d=document.createElement(c);d.setAttribute("data-a2ui-id",l.id),d.id=l.id,h.replaceWith(d),h=d,i.elements.set(l.id,h),this.#s.set(l.id,h)}l._surfaceId=t,Object.values(l).some(d=>d&&typeof d=="object"&&d.path)&&i.bindings.set(l.id,l),this.#v(h,l)}catch(h){console.warn(`A2UI: component "${l.id}" (${l.component}) failed:`,h.message)}}this.#y(e);let r=new Map;for(let l of e){for(let h of Array.isArray(l.children)?l.children:[])r.set(h,l.id);l.child&&r.set(l.child,l.id)}let n=(l,h)=>{let c=new Set,u=l;for(;u!=null;){if(u===h||c.has(u))return!0;c.add(u),u=r.get(u)}return!1};for(let l of e){let h=i.elements.get(l.id);if(h)try{let c=Array.isArray(l.children)?l.children:[];for(let u of c){if(u===l.id||n(l.id,u))continue;let d=i.elements.get(u);d&&d.parentElement!==h&&h.appendChild(d)}if(l.child&&l.child!==l.id&&!n(l.id,l.child)){let u=i.elements.get(l.child);u&&u.parentElement!==h&&h.appendChild(u)}}catch(c){console.warn(`A2UI: tree build failed for "${l.id}":`,c.message)}}let o=i.rootId??"root";if(e.find(l=>l.id===o)){let l=i.elements.get(o);l&&l.parentElement!==i.root&&i.root.appendChild(l)}}static#p=new Set(["Header","Section","Footer","Img","Image","Video","Picture","Iframe","Aside","Divider"]);static#m=new Set(["Header","Section","Footer"]);static#g=new Set(["header","body","footer"]);#O=new Set;#y(t){let e=new Map;for(let i of t)i.id!=null&&e.set(i.id,i);for(let i of t){let r=i.component==="Card"||i.component==="ErrorContainer",n=i.component==="Drawer";if(!r&&!n)continue;let o=n?s.#m:s.#p,a=n?"<drawer-ui>":"<card-ui>",l=Array.isArray(i.children)?i.children:[];for(let h of l){let c=e.get(h);if(!c||typeof c.slot=="string"&&s.#g.has(c.slot)||o.has(c.component))continue;let u=`${i.id}::${h}::${c.component}`;this.#O.has(u)||(this.#O.add(u),console.warn(`A2UI: ${a} (id="${i.id}") body must wrap "${c.component}" (id="${h}") in <Section>. Direct flow children bypass the canonical body slot and lose --card-inset margin. Canonical children: ${[...o].join(", ")}`+(n?', or slot="header|body|footer".':".")))}}}static#b={h1:"h1",h2:"h2",h3:"h3",h4:"h4",h5:"h5",h6:"h6",body:"p",caption:"small"};#x(t,e){return!e?.slot&&s.#b[t]?s.#b[t]:"text-ui"}#v(t,e){let i=new Set(["id","component","children","child","_surfaceId"]);e.component==="Text"&&e.variant&&!e.slot&&s.#b[e.variant]&&i.add("variant");let r=this.#r.get(e.id),n={};for(let[o,a]of Object.entries(e)){if(i.has(o))continue;let l=a&&typeof a=="object"&&a.path,h=this.#S(a,e._surfaceId);n[o]=h,!(r&&Object.is(r[o],h))&&(h==null&&!l||kd(t,o,h))}if(r)for(let o of Object.keys(r))!(o in n)&&!i.has(o)&&t.removeAttribute(fa(o));this.#r.set(e.id,n)}#S(t,e){if(t==null)return null;if(typeof t!="object")return t;if(t.path){let i=e?this.#i.get(e):null;return i?this.#w(i.dataModel,t.path):t.path}return t}#w(t,e){return!e||e==="/"?t:e.split("/").filter(Boolean).reduce((i,r)=>i?.[r],t)}#k({surfaceId:t,path:e,value:i}){let r=this.#i.get(t);if(r){if(!e||e==="/")r.dataModel=i??{};else{let n=e.split("/").filter(Boolean),o=r.dataModel;for(let a=0;a<n.length-1;a++)o[n[a]]==null&&(o[n[a]]={}),o=o[n[a]];o[n[n.length-1]]=i}for(let[n,o]of r.bindings){let a=r.elements.get(n);a&&this.#v(a,o)}}}#A({surfaceId:t}){let e=this.#i.get(t);if(e){this.#c?.teardown(t);for(let[i]of e.elements)this.#s.delete(i);if(e.adoptedSheets&&e.adoptedSheets.size>0){let i=new Set;for(let r of e.adoptedSheets.values())i.add(r.sheet);document.adoptedStyleSheets=document.adoptedStyleSheets.filter(r=>!i.has(r)),e.adoptedSheets.clear()}e.root.remove(),this.#i.delete(t)}}static#E=new Set(["root","html","body"]);#$({surfaceId:t,styleId:e,css:i}){if(typeof e!="string"||e.length===0){this.#Q(null,"styles-rejected",{surfaceId:t,styleId:e,reason:"invalid-payload: styleId must be a non-empty string"});return}if(typeof i!="string"){this.#Q(null,"styles-rejected",{surfaceId:t,styleId:e,reason:"invalid-payload: css must be a string"});return}let r=this.#i.get(t);if(!r){this.#Q(null,"styles-rejected",{surfaceId:t,styleId:e,reason:"no-such-surface"});return}let n=this.#T(i,t);if(n.rejected){this.#Q(r.root,"styles-rejected",{surfaceId:t,styleId:e,reason:n.reason});return}let o=r.adoptedSheets.get(e);o&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(a=>a!==o.sheet)),document.adoptedStyleSheets=[...document.adoptedStyleSheets,n.sheet],r.adoptedSheets.set(e,{sheet:n.sheet,ruleCount:n.sheet.cssRules.length,appliedAt:typeof performance<"u"?performance.now():Date.now()}),this.#Q(r.root,"styles-applied",{surfaceId:t,styleId:e,ruleCount:n.sheet.cssRules.length,validationWarnings:n.warnings})}#R({surfaceId:t,styleId:e}){let i=this.#i.get(t);if(!i)return;let r=i.adoptedSheets.get(e);r&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(n=>n!==r.sheet),i.adoptedSheets.delete(e),this.#Q(i.root,"styles-removed",{surfaceId:t,styleId:e}))}#T(t,e){let i=[];if(/^\s*@import\b/im.test(t))return{rejected:!0,reason:"forbidden-import"};if(/^\s*@charset\b/im.test(t))return{rejected:!0,reason:"forbidden-charset"};let r=new CSSStyleSheet;try{r.replaceSync(t)}catch(l){return{rejected:!0,reason:"parse-error: "+(l?.message||String(l))}}for(let l of r.cssRules){let h=this.#C(l);if(h)return{rejected:!0,reason:h}}if(/url\s*\(\s*["']?\s*(?:https?:|\/\/)/i.test(t))return{rejected:!0,reason:"external-url"};for(let l of r.cssRules)if(l.constructor?.name==="CSSPropertyRule"||l.cssText?.startsWith("@property")){let h=l.cssText.match(/@property\s+(--[\w-]+)/);h&&i.push({kind:"property-registered-globally",name:h[1]})}let n=this.#L(r,e),o=this.#M(r,e),a=new CSSStyleSheet;try{a.replaceSync(o)}catch(l){return{rejected:!0,reason:"scope-wrap-failed: "+(l?.message||String(l))}}return n.length>0&&i.push({kind:"animations-namespaced",count:n.length}),{rejected:!1,sheet:a,warnings:i}}#C(t){let e=t.cssText||"";if(/^@import\b/i.test(e))return"forbidden-import";if(/^@charset\b/i.test(e))return"forbidden-charset";if(/^@scope\b/i.test(e))return"forbidden-scope-directive";if(t.selectorText){let i=this.#I(t.selectorText);for(let r of i){let n=r.trim().replace(/^:scope\s*/,"");if(n.startsWith(":root"))return"forbidden-root-selector";let o=n.match(/^([a-zA-Z*][\w-]*)/);if(!o)continue;let a=o[1].toLowerCase();if(s.#E.has(a))return`forbidden-${a}-selector`}}return null}#I(t){let e=[],i=0,r=0;for(let n=0;n<t.length;n++){let o=t[n];o==="("?i++:o===")"?i--:o===","&&i===0&&(e.push(t.slice(r,n)),r=n+1)}return e.push(t.slice(r)),e}#L(t,e){let i=[],r=String(e).replace(/[^a-zA-Z0-9_-]/g,"_");for(let o=0;o<t.cssRules.length;o++){let a=t.cssRules[o];if(a.constructor?.name==="CSSKeyframesRule"||a.cssText?.startsWith("@keyframes")){let l=a.name;if(!l)continue;let h=`${r}_${l}`;try{a.name=h}catch{let c=a.cssText.replace(/@keyframes\s+[\w-]+/,`@keyframes ${h}`);t.deleteRule(o),t.insertRule(c,o)}i.push({from:l,to:h})}}if(i.length===0)return i;let n=new Map(i.map(o=>[o.from,o.to]));for(let o of t.cssRules)if(o.style)for(let a of["animation","animation-name"]){let l=o.style.getPropertyValue(a);if(!l)continue;let h=l.replace(/\b([\w-]+)\b/g,c=>n.has(c)?n.get(c):c);h!==l&&o.style.setProperty(a,h)}return i}#M(t,e){let i=[];for(let n of t.cssRules)i.push(n.cssText);return`@scope ([data-a2ui-surface="${String(e).replace(/"/g,'\\"')}"]) {
42
42
  ${i.join(`
43
43
  `)}
44
44
  }`}#Q(t,e,i){let r=t||this.#t;if(!(!r||typeof CustomEvent>"u"))try{r.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,composed:!1}))}catch{}}getSurface(t){return this.#i.get(t)}getElement(t){return this.#s.get(t)}get surfaces(){return[...this.#i.keys()]}getStylesheets(t){return this.#i.get(t)?.adoptedSheets??new Map}reset(){this.#a!==null&&(cancelAnimationFrame(this.#a),this.#a=null),this.#n.length=0;let t=new Set;for(let[,e]of this.#i)if(e.adoptedSheets)for(let i of e.adoptedSheets.values())t.add(i.sheet);t.size>0&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(e=>!t.has(e)));for(let[,e]of this.#i)e.root===this.#t?e.root.innerHTML="":e.root.remove();this.#i.clear(),this.#s.clear(),this.#r.clear()}set batching(t){this.#o=!!t}get batching(){return this.#o}}});function Ad(s,t={}){let e=s;if(t.catalog){let i=t.catalog instanceof Map?[...t.catalog.keys()]:Object.keys(t.catalog),r=s.includes("?")?"&":"?";e=`${s}${r}a2ui_catalog=${encodeURIComponent(i.join(","))}`}return{[Symbol.asyncIterator](){let i=new EventSource(e),r=[],n=null,o=!1;return i.onmessage=a=>{try{let l=JSON.parse(a.data);if(n){let h=n;n=null,h({value:l,done:!1})}else r.push(l)}catch{console.warn("A2UI SSE: invalid JSON",a.data)}},i.onerror=()=>{if(o=!0,i.close(),n){let a=n;n=null,a({value:void 0,done:!0})}},t.signal&&t.signal.addEventListener("abort",()=>{if(o=!0,i.close(),n){let a=n;n=null,a({value:void 0,done:!0})}}),{next(){return r.length>0?Promise.resolve({value:r.shift(),done:!1}):o?Promise.resolve({value:void 0,done:!0}):new Promise(a=>{n=a})},return(){return o=!0,i.close(),Promise.resolve({value:void 0,done:!0})}}}}}function Ed(s,t={}){return{[Symbol.asyncIterator](){let e=new WebSocket(s),i=[],r=null,n=!1;return e.onopen=()=>{if(t.catalog){let o=t.catalog instanceof Map?[...t.catalog.keys()]:Object.keys(t.catalog);e.send(JSON.stringify({type:"a2ui:catalog",supportedTypes:o}))}},e.onmessage=o=>{try{let a=JSON.parse(o.data);if(r){let l=r;r=null,l({value:a,done:!1})}else i.push(a)}catch{console.warn("A2UI WS: invalid JSON",o.data)}},e.onclose=()=>{if(n=!0,r){let o=r;r=null,o({value:void 0,done:!0})}},e.onerror=()=>{n=!0,e.close()},{next(){return i.length>0?Promise.resolve({value:i.shift(),done:!1}):n?Promise.resolve({value:void 0,done:!0}):new Promise(o=>{r=o})},return(){return n=!0,e.close(),Promise.resolve({value:void 0,done:!0})}}}}}function yE(s,t=0){return{async*[Symbol.asyncIterator](){for(let e of s)t>0&&await new Promise(i=>setTimeout(i,t)),yield e}}}function Cd(s,t={}){let e=(s.split(":")[0]||"").toLowerCase();return e==="ws"||e==="wss"?vD(s,t):OE(s,t)}function bE(s,t){if(s.result?.content){for(let e of s.result.content)if(e.type==="resource"&&e.resource?.mimeType==="application/json+a2ui")try{let i=JSON.parse(e.resource.text);for(let r of Array.isArray(i)?i:[i])t(r)}catch{}else if(e.type==="text")try{let i=JSON.parse(e.text);i.type&&(i.type.startsWith("create")||i.type.startsWith("update")||i.type.startsWith("delete"))&&t(i)}catch{}}}function vD(s,t){return{async*[Symbol.asyncIterator](){let{signal:e,catalog:i,onAction:r}=t,n=new WebSocket(s);if(await new Promise((c,u)=>{n.onopen=c,n.onerror=u,e&&e.addEventListener("abort",()=>{n.close(),u(new DOMException("Aborted","AbortError"))},{once:!0})}),i){let c=i instanceof Map?[...i.keys()]:Object.keys(i);n.send(JSON.stringify({jsonrpc:"2.0",method:"a2ui/catalog",params:{supportedTypes:c}}))}let o=[],a=null,l=!1,h=c=>{if(a){let u=a;a=null,u({value:c,done:!1})}else o.push(c)};for(n.onmessage=c=>{try{let u=JSON.parse(c.data);bE(u,h),u.method==="a2ui/action"&&r&&r(u.params?.name,u.params?.arguments).then(d=>{n.send(JSON.stringify({jsonrpc:"2.0",id:u.id,result:d}))}).catch(d=>{n.send(JSON.stringify({jsonrpc:"2.0",id:u.id,error:{code:-1,message:d.message}}))})}catch{console.warn("A2UI MCP: invalid message",c.data)}},n.onclose=()=>{if(l=!0,a){let c=a;a=null,c({value:void 0,done:!0})}},n.onerror=()=>{l=!0,n.close()},e&&e.addEventListener("abort",()=>{if(l=!0,n.close(),a){let c=a;a=null,c({value:void 0,done:!0})}});!l||o.length>0;)if(o.length>0)yield o.shift();else{if(l)break;{let c=await new Promise(u=>{a=u});if(c.done)break;yield c.value}}}}}function OE(s,t){return{async*[Symbol.asyncIterator](){let{signal:e,catalog:i,onAction:r}=t,n=[],o=null,a=!1,l=g=>{if(o){let x=o;o=null,x({value:g,done:!1})}else n.push(g)},h=()=>{if(a=!0,o){let g=o;o=null,g({value:void 0,done:!0})}},c={jsonrpc:"2.0",id:1,method:"initialize",params:{protocolVersion:"2025-11-25",capabilities:{},clientInfo:{name:"a2ui-runtime",version:"0.0.0"}}},u;try{u=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json, text/event-stream"},body:JSON.stringify(c),signal:e})}catch(g){console.warn("A2UI MCP HTTP: initialize failed",g);return}if(!u.ok){console.warn(`A2UI MCP HTTP: initialize returned ${u.status}`);return}let d=u.headers.get("mcp-session-id");if(!d){console.warn("A2UI MCP HTTP: server did not return mcp-session-id header");try{await u.text()}catch{}return}try{if((u.headers.get("content-type")||"").includes("text/event-stream")){let x=u.body.getReader(),S=new TextDecoder,w="";for(;;){let{done:k,value:A}=await x.read();if(k||(w+=S.decode(A,{stream:!0}),w.includes(`
@@ -48,7 +48,7 @@ ${i.join(`
48
48
  `))!==-1;){let E=S.slice(0,A);S=S.slice(A+2);let $=[];for(let T of E.split(`
49
49
  `))T.startsWith("data:")&&$.push(T.slice(5).trimStart());if($.length===0)continue;let L=$.join(`
50
50
  `);try{let T=JSON.parse(L);p(T)}catch{console.warn("A2UI MCP HTTP: invalid JSON-RPC SSE payload",L)}}}}catch(w){w?.name!=="AbortError"&&console.warn("A2UI MCP HTTP: stream read error",w)}finally{h(),b()}})();!a||n.length>0;)if(n.length>0)yield n.shift();else{if(a)break;{let g=await new Promise(x=>{o=x});if(g.done)break;yield g.value}}}}}function $d(s,t={}){return{async*[Symbol.asyncIterator](){let e={};if(t.catalog){let a=t.catalog instanceof Map?[...t.catalog.keys()]:Object.keys(t.catalog);e["X-A2UI-Catalog"]=a.join(",")}let r=(await fetch(s,{signal:t.signal,headers:e})).body.getReader(),n=new TextDecoder,o="";for(;;){let{done:a,value:l}=await r.read();if(a)break;o+=n.decode(l,{stream:!0});let h=o.split(`
51
- `);o=h.pop();for(let c of h){let u=c.trim();if(u)try{yield JSON.parse(u)}catch{console.warn("A2UI JSONL: invalid JSON",u)}}}if(o.trim())try{yield JSON.parse(o.trim())}catch{}}}}var vE=W(()=>{"use strict"});var Pd,xE=W(()=>{"use strict";Pd=class s{#t;#e;#i;#s=new Map;#r=[];#n=new Map;constructor({id:t,name:e,version:i="1.0.0"}){this.#t=t,this.#e=e,this.#i=i}addSurface(t,e){this.#s.set(t,{...e})}removeSurface(t){this.#s.delete(t),this.#r=this.#r.filter(e=>e.from!==t&&e.to!==t)}getSurface(t){return this.#s.get(t)??null}get surfaceIds(){return[...this.#s.keys()]}addAssociation(t){if(!this.#s.has(t.from)){console.warn(`Manifest: surface "${t.from}" not found`);return}if(!this.#s.has(t.to)){console.warn(`Manifest: surface "${t.to}" not found`);return}this.#r=this.#r.filter(e=>!(e.type===t.type&&e.from===t.from&&e.to===t.to)),this.#r.push({...t})}getAssociationsFrom(t,e){return this.#r.filter(i=>i.from===t&&(!e||i.type===e))}getAssociationsTo(t,e){return this.#r.filter(i=>i.to===t&&(!e||i.type===e))}getSharedContextPeers(t){let e=[];for(let i of this.#r)i.type==="shares-context"&&(i.from===t&&e.push({surfaceId:i.to,context:i.context}),i.to===t&&e.push({surfaceId:i.from,context:i.context}));return e}defineSharedContext(t,e){this.#n.set(t,{...e})}getSharedContext(t){return this.#n.get(t)??null}validate(){let t=[];for(let i of this.#s.keys())!this.#r.some(n=>n.from===i||n.to===i)&&this.#s.size>1&&t.push({severity:"warning",message:`Surface "${i}" has no associations`});[...this.#s.entries()].filter(([,i])=>i.entryPoint).length===0&&this.#s.size>0&&t.push({severity:"warning",message:"No surface marked as entryPoint"});for(let i of this.#r)i.type==="depends-on"&&!i.fallback&&t.push({severity:"warning",message:`depends-on from "${i.from}" to "${i.to}" has no fallback`});for(let i of this.#r)i.type==="shares-context"&&i.context&&!this.#n.has(i.context)&&t.push({severity:"error",message:`Shared context "${i.context}" referenced but not defined`});for(let i of this.#r)i.type==="feeds"&&!i.trigger&&t.push({severity:"warning",message:`feeds from "${i.from}" to "${i.to}" has no trigger`});for(let i of this.#r)if(i.type==="routes-to"){let r=this.#s.get(i.to);r&&!r.route&&t.push({severity:"error",message:`routes-to target "${i.to}" has no route defined`})}return{valid:!t.some(i=>i.severity==="error"),issues:t}}toJSON(){return{$schema:"https://a2ui.dev/schema/relationships/v1",id:this.#t,name:this.#e,version:this.#i,surfaces:Object.fromEntries(this.#s),associations:[...this.#r],sharedContexts:Object.fromEntries(this.#n)}}static fromJSON(t){let e=new s({id:t.id,name:t.name,version:t.version});if(t.surfaces)for(let[i,r]of Object.entries(t.surfaces))e.addSurface(i,r);if(t.sharedContexts)for(let[i,r]of Object.entries(t.sharedContexts))e.defineSharedContext(i,r);if(t.associations)for(let i of t.associations)e.addAssociation(i);return e}}});var CO=W(()=>{"use strict";hO();gE();EO();vE();xE();cO();kO();AO();wO();Ks();uO();dO();fO();pO();mO()});var SE={};Gt(SE,{A2UIRoot:()=>pa});var pa,$O=W(()=>{"use strict";C();P();CO();pa=class extends v{static properties={src:{type:String,default:"",reflect:!0},transport:{type:String,default:"sse",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},active:{type:Boolean,default:!1,reflect:!0},batch:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=!1;#r=t=>{let e=t.target.closest("[data-action]");e&&this.dispatchEvent(new CustomEvent("a2ui-action",{bubbles:!0,detail:{name:e.getAttribute("data-action"),sourceComponentId:e.getAttribute("data-a2ui-id")||"",timestamp:Date.now(),context:{}}}))};connected(){this.#t=new os(this,Bt,{batch:this.batch}),this.#s||(this.#s=!0,this.addEventListener("click",this.#r))}render(){this.src&&!this.active&&this.#n()}async#n(){this.#e?.abort(),this.#e=new AbortController;let t=this.#e.signal;this.loading=!0,this.active=!1;let e;try{switch(this.transport){case"sse":e=Ad(this.src,{signal:t,catalog:Bt});break;case"ws":case"websocket":e=Ed(this.src,{signal:t,catalog:Bt});break;case"jsonl":e=$d(this.src,{signal:t,catalog:Bt});break;case"mcp":e=Cd(this.src,{signal:t,catalog:Bt,onAction:(i,r)=>(this.dispatchEvent(new CustomEvent("a2ui-action",{bubbles:!0,detail:{name:i,params:r,timestamp:Date.now()}})),Promise.resolve({status:"dispatched"}))});break;default:console.warn(`a2ui-root: unknown transport "${this.transport}"`);return}this.active=!0,this.loading=!1,this.dispatchEvent(new Event("a2ui-connected",{bubbles:!0}));for await(let i of e){if(t.aborted)break;this.#t.process(i),this.dispatchEvent(new CustomEvent("a2ui-message",{bubbles:!0,detail:{message:i}}))}}catch(i){t.aborted||this.dispatchEvent(new CustomEvent("a2ui-error",{bubbles:!0,detail:{error:i}}))}this.active=!1,this.loading=!1,this.dispatchEvent(new Event("a2ui-closed",{bubbles:!0}))}process(t){this.#t||(this.#t=new os(this,Bt)),this.#t.process(t)}processAll(t){for(let e of t)this.process(e)}get doc(){return this.#i}set doc(t){this.#i=Array.isArray(t)?t:[],this.#t||(this.#t=new os(this,Bt)),this.#t.reset();for(let e of this.#i)this.#t.process(e);this.dispatchEvent(new CustomEvent("doc-replaced",{bubbles:!0,detail:{count:this.#i.length}}))}reset(){this.#t?.reset()}disconnect(){this.#e?.abort(),this.active=!1}disconnected(){this.#e?.abort(),this.removeEventListener("click",this.#r),this.#s=!1,this.active=!1}get renderer(){return this.#t}};y("a2ui-root",pa)});var yq=["regular","thin","light","bold","fill","duotone"],Ze="regular",ir=(s,t)=>`${t}:${s}`,Bi=new Map,Eh=new Set;function vq(s,t,e=Ze){Bi.set(ir(s,e),t)}function xq(s,t=Ze){for(let[e,i]of Object.entries(s))Bi.set(ir(e,t),i)}function oy(s,t=Ze){if(!s)return"";let e=ir(s,t);return Bi.has(e)?Bi.get(e):(ny(s,t),"")}function Sq(s,t=Ze){return Bi.has(ir(s,t))}function wq(){return[...Bi.keys()]}var JO={regular:{},thin:{},light:{},bold:{},fill:{},duotone:{}},ty=new Set(["regular","thin","light","bold","fill","duotone"]),sr=JO;function oC(s){let t=Object.keys(s);if(t.length===0)return!1;for(let e of t)if(ty.has(e))return!1;for(let e of t)if(e.endsWith(".svg"))return!0;return!1}var ey=new WeakSet,Zd=!1,iy,Ph=new Promise(s=>{iy=s});function ay(){return Bi.size===0&&!Zd}function Qh(s){if(!s||typeof s!="object"){console.error(`[icons] installIconLoaders: expected per-weight map { regular: { ... }, bold: { ... }, ... }, got ${s===null?"null":typeof s}. Install aborted; registry unchanged.`);return}let t=s;if(oC(s))ey.has(s)||(ey.add(s),console.warn(`[icons] installIconLoaders received a flat path\u2192svg map. Auto-promoting to { regular: <flat> }. Wrap explicitly to silence this warning and to load bold/fill/etc. weights:
51
+ `);o=h.pop();for(let c of h){let u=c.trim();if(u)try{yield JSON.parse(u)}catch{console.warn("A2UI JSONL: invalid JSON",u)}}}if(o.trim())try{yield JSON.parse(o.trim())}catch{}}}}var vE=W(()=>{"use strict"});var Pd,xE=W(()=>{"use strict";Pd=class s{#t;#e;#i;#s=new Map;#r=[];#n=new Map;constructor({id:t,name:e,version:i="1.0.0"}){this.#t=t,this.#e=e,this.#i=i}addSurface(t,e){this.#s.set(t,{...e})}removeSurface(t){this.#s.delete(t),this.#r=this.#r.filter(e=>e.from!==t&&e.to!==t)}getSurface(t){return this.#s.get(t)??null}get surfaceIds(){return[...this.#s.keys()]}addAssociation(t){if(!this.#s.has(t.from)){console.warn(`Manifest: surface "${t.from}" not found`);return}if(!this.#s.has(t.to)){console.warn(`Manifest: surface "${t.to}" not found`);return}this.#r=this.#r.filter(e=>!(e.type===t.type&&e.from===t.from&&e.to===t.to)),this.#r.push({...t})}getAssociationsFrom(t,e){return this.#r.filter(i=>i.from===t&&(!e||i.type===e))}getAssociationsTo(t,e){return this.#r.filter(i=>i.to===t&&(!e||i.type===e))}getSharedContextPeers(t){let e=[];for(let i of this.#r)i.type==="shares-context"&&(i.from===t&&e.push({surfaceId:i.to,context:i.context}),i.to===t&&e.push({surfaceId:i.from,context:i.context}));return e}defineSharedContext(t,e){this.#n.set(t,{...e})}getSharedContext(t){return this.#n.get(t)??null}validate(){let t=[];for(let i of this.#s.keys())!this.#r.some(n=>n.from===i||n.to===i)&&this.#s.size>1&&t.push({severity:"warning",message:`Surface "${i}" has no associations`});[...this.#s.entries()].filter(([,i])=>i.entryPoint).length===0&&this.#s.size>0&&t.push({severity:"warning",message:"No surface marked as entryPoint"});for(let i of this.#r)i.type==="depends-on"&&!i.fallback&&t.push({severity:"warning",message:`depends-on from "${i.from}" to "${i.to}" has no fallback`});for(let i of this.#r)i.type==="shares-context"&&i.context&&!this.#n.has(i.context)&&t.push({severity:"error",message:`Shared context "${i.context}" referenced but not defined`});for(let i of this.#r)i.type==="feeds"&&!i.trigger&&t.push({severity:"warning",message:`feeds from "${i.from}" to "${i.to}" has no trigger`});for(let i of this.#r)if(i.type==="routes-to"){let r=this.#s.get(i.to);r&&!r.route&&t.push({severity:"error",message:`routes-to target "${i.to}" has no route defined`})}return{valid:!t.some(i=>i.severity==="error"),issues:t}}toJSON(){return{$schema:"https://a2ui.dev/schema/relationships/v1",id:this.#t,name:this.#e,version:this.#i,surfaces:Object.fromEntries(this.#s),associations:[...this.#r],sharedContexts:Object.fromEntries(this.#n)}}static fromJSON(t){let e=new s({id:t.id,name:t.name,version:t.version});if(t.surfaces)for(let[i,r]of Object.entries(t.surfaces))e.addSurface(i,r);if(t.sharedContexts)for(let[i,r]of Object.entries(t.sharedContexts))e.defineSharedContext(i,r);if(t.associations)for(let i of t.associations)e.addAssociation(i);return e}}});var CO=W(()=>{"use strict";hO();gE();EO();vE();xE();cO();kO();AO();wO();Ks();uO();dO();fO();pO();mO()});var SE={};Gt(SE,{A2UIRoot:()=>pa});var pa,$O=W(()=>{"use strict";C();P();CO();pa=class extends v{static properties={src:{type:String,default:"",reflect:!0},transport:{type:String,default:"sse",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},active:{type:Boolean,default:!1,reflect:!0},batch:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=!1;#r=t=>{let e=t.target.closest("[data-action]");e&&this.dispatchEvent(new CustomEvent("a2ui-action",{bubbles:!0,detail:{name:e.getAttribute("data-action"),sourceComponentId:e.getAttribute("data-a2ui-id")||"",timestamp:Date.now(),context:{}}}))};connected(){this.#t=new os(this,Bt,{batch:this.batch}),this.#s||(this.#s=!0,this.addEventListener("click",this.#r))}render(){this.src&&!this.active&&this.#n()}async#n(){this.#e?.abort(),this.#e=new AbortController;let t=this.#e.signal;this.loading=!0,this.active=!1;let e;try{switch(this.transport){case"sse":e=Ad(this.src,{signal:t,catalog:Bt});break;case"ws":case"websocket":e=Ed(this.src,{signal:t,catalog:Bt});break;case"jsonl":e=$d(this.src,{signal:t,catalog:Bt});break;case"mcp":e=Cd(this.src,{signal:t,catalog:Bt,onAction:(i,r)=>(this.dispatchEvent(new CustomEvent("a2ui-action",{bubbles:!0,detail:{name:i,params:r,timestamp:Date.now()}})),Promise.resolve({status:"dispatched"}))});break;default:console.warn(`a2ui-root: unknown transport "${this.transport}"`);return}this.active=!0,this.loading=!1,this.dispatchEvent(new Event("a2ui-connected",{bubbles:!0}));for await(let i of e){if(t.aborted)break;this.#t.process(i),this.dispatchEvent(new CustomEvent("a2ui-message",{bubbles:!0,detail:{message:i}}))}}catch(i){t.aborted||this.dispatchEvent(new CustomEvent("a2ui-error",{bubbles:!0,detail:{error:i}}))}this.active=!1,this.loading=!1,this.dispatchEvent(new Event("a2ui-closed",{bubbles:!0}))}process(t){this.#t||(this.#t=new os(this,Bt)),this.#t.process(t)}processAll(t){for(let e of t)this.process(e)}get doc(){return this.#i}set doc(t){this.#i=Array.isArray(t)?t:[],this.#t||(this.#t=new os(this,Bt)),this.#t.reset();for(let e of this.#i)this.#t.process(e);this.dispatchEvent(new CustomEvent("doc-replaced",{bubbles:!0,detail:{count:this.#i.length}}))}reset(){this.#t?.reset()}disconnect(){this.#e?.abort(),this.active=!1}disconnected(){this.#e?.abort(),this.removeEventListener("click",this.#r),this.#s=!1,this.active=!1}get renderer(){return this.#t}};y("a2ui-root",pa)});var Sq=["regular","thin","light","bold","fill","duotone"],Ze="regular",ir=(s,t)=>`${t}:${s}`,Bi=new Map,Eh=new Set;function wq(s,t,e=Ze){Bi.set(ir(s,e),t)}function kq(s,t=Ze){for(let[e,i]of Object.entries(s))Bi.set(ir(e,t),i)}function oy(s,t=Ze){if(!s)return"";let e=ir(s,t);return Bi.has(e)?Bi.get(e):(ny(s,t),"")}function Aq(s,t=Ze){return Bi.has(ir(s,t))}function Eq(){return[...Bi.keys()]}var JO={regular:{},thin:{},light:{},bold:{},fill:{},duotone:{}},ty=new Set(["regular","thin","light","bold","fill","duotone"]),sr=JO;function oC(s){let t=Object.keys(s);if(t.length===0)return!1;for(let e of t)if(ty.has(e))return!1;for(let e of t)if(e.endsWith(".svg"))return!0;return!1}var ey=new WeakSet,Zd=!1,iy,Ph=new Promise(s=>{iy=s});function ay(){return Bi.size===0&&!Zd}function Qh(s){if(!s||typeof s!="object"){console.error(`[icons] installIconLoaders: expected per-weight map { regular: { ... }, bold: { ... }, ... }, got ${s===null?"null":typeof s}. Install aborted; registry unchanged.`);return}let t=s;if(oC(s))ey.has(s)||(ey.add(s),console.warn(`[icons] installIconLoaders received a flat path\u2192svg map. Auto-promoting to { regular: <flat> }. Wrap explicitly to silence this warning and to load bold/fill/etc. weights:
52
52
  installIconLoaders({ regular: import.meta.glob('.../regular/*.svg', { ... }) });`)),t={regular:s};else if(!Object.keys(s).some(i=>ty.has(i))){let i=Object.keys(s).slice(0,5).join(", ");console.error(`[icons] installIconLoaders: shape unrecognized. Expected per-weight map keyed by regular/thin/light/bold/fill/duotone, or a flat path\u2192svg map. Received keys: ${i||"(empty)"}. Install aborted; registry unchanged.`);return}if(sr={...JO,...t},Zd=!0,typeof document<"u")for(let e of document.querySelectorAll("icon-ui[name]")){let i=e.getAttribute("name"),r=e.getAttribute("weight")||Ze;i&&ny(i,r)}iy()}function aC(s){let t=sy();return Qh(s),t}function sy(){let s=new Set;if(typeof customElements>"u")return[];let t=["accordion-ui","agent-questions-ui","agent-reasoning-ui","agent-trace-ui","calendar-picker-ui","color-picker-ui","command-ui","pane-ui","select-ui","table-ui","tag-ui","tree-ui"];for(let e of t){let i=customElements.get(e);if(i&&Array.isArray(i.requiredIcons))for(let r of i.requiredIcons)s.add(r)}return[...s]}aC.discover=sy;var ry=new Set;function lC(s,t){let e=ir(s,t);if(ry.has(e))return;ry.add(e);let i=t!==Ze?` at weight="${t}"`:"",r=$h[s],n=r?` (alias "${s}" \u2192 "${r}" \u2014 also not found)`:"";console.warn(`[icon-ui] Icon "${s}"${i} not found in the registry${n}. Check the name against @phosphor-icons/core, use an alias in ICON_ALIASES, or register a custom SVG via registerIcon().`)}function hC(s,t){return t==="regular"?`${s}.svg`:`${s}-${t}.svg`}function Ch(s,t=Ze){let e=sr[t];if(!e)return null;let i=hC(s,t),r=`/node_modules/@phosphor-icons/core/assets/${t}/${i}`;if(e[r])return e[r];let n=`/${i}`;for(let o in e)if(o.endsWith(n))return e[o];if(t===Ze&&s.endsWith("-fill")){let o=`${s}.svg`,a=`/node_modules/@phosphor-icons/core/assets/fill/${o}`;if(sr.fill[a])return sr.fill[a];let l=`/${o}`;for(let h in sr.fill)if(h.endsWith(l))return sr.fill[h]}return null}function Th(s,t=Ze){if(!s||typeof s!="string")return!1;if(Ch(s,t))return!0;let e=$h[s];return!!(e&&Ch(e,t))}var $h={google:"google-logo",github:"github-logo",microsoft:"windows-logo",apple:"apple-logo",twitter:"twitter-logo",facebook:"facebook-logo",discord:"discord-logo",slack:"slack-logo",linkedin:"linkedin-logo",youtube:"youtube-logo",instagram:"instagram-logo",figma:"figma-logo",dribbble:"dribbble-logo",stripe:"stripe-logo",paypal:"paypal-logo","alert-circle":"warning-circle",alert:"warning",error:"x-circle",success:"check-circle",close:"x",delete:"trash",edit:"pencil-simple",save:"floppy-disk",search:"magnifying-glass",settings:"gear",home:"house",mail:"envelope",email:"envelope",phone:"phone",location:"map-pin",calendar:"calendar-blank",time:"clock",user:"user",users:"users-three",menu:"list",more:"dots-three","dots-vertical":"dots-three-vertical",filter:"funnel",inbox:"tray","text-bold":"text-b",bold:"text-b",italic:"text-italic",underline:"text-underline",reset:"arrow-counter-clockwise",undo:"arrow-counter-clockwise",redo:"arrow-clockwise","success-checkmark":"seal-check",circuit:"circuitry",contrast:"circle-half",theme:"circle-half","dark-mode":"moon","light-mode":"sun","alert-triangle":"warning","alert-octagon":"warning-octagon","alert-diamond":"warning-diamond",number:"hash","numbered-list":"list-numbers",numeric:"hash","circle-warning":"warning-circle","circle-x":"x-circle","circle-check":"check-circle","circle-info":"info","circle-question":"question","circle-plus":"plus-circle","circle-minus":"minus-circle",sort:"sort-ascending",refresh:"arrow-clockwise",download:"download-simple",upload:"upload-simple",share:"share-network",copy:"copy-simple",link:"link-simple","external-link":"arrow-square-out","chevron-down":"caret-down","chevron-up":"caret-up","chevron-left":"caret-left","chevron-right":"caret-right","arrow-left":"arrow-left","arrow-right":"arrow-right",plus:"plus",minus:"minus",send:"paper-plane-right",submit:"paper-plane-right",attachment:"paperclip",attach:"paperclip",expand:"arrows-out",collapse:"arrows-in",fullscreen:"arrows-out","exit-fullscreen":"arrows-in",fade:"gradient","fade-presence":"gradient",notification:"bell",notifications:"bell",bookmark:"bookmark-simple",favorite:"heart",like:"heart",comment:"chat-circle",chat:"chat-circle",image:"image",photo:"image",picture:"image",video:"video-camera",camera:"camera",file:"file",document:"file-text",folder:"folder",lock:"lock-simple",unlock:"lock-simple-open","eye-off":"eye-slash",hide:"eye-slash",show:"eye",logout:"sign-out",login:"sign-in",dot:"circle-fill",circle:"circle-fill",marker:"circle-fill"};async function ny(s,t=Ze){let e=ir(s,t);if(!Eh.has(e)){Eh.add(e);try{let i=Ch(s,t);if(!i&&$h[s]&&(i=Ch($h[s],t)),!i){Eh.delete(e),Zd&&lC(s,t);return}let r=typeof i=="function"?await i():i;Bi.set(e,r);let n=t===Ze?`icon-ui[name="${s}"]:not([weight]), icon-ui[name="${s}"][weight="regular"]`:`icon-ui[name="${s}"][weight="${t}"]`;for(let o of document.querySelectorAll(n))o.innerHTML=r}catch{}finally{Eh.delete(e)}}}var zd,ly=!1;try{zd={regular:import.meta.glob("../node_modules/@phosphor-icons/core/assets/regular/*.svg",{query:"?raw",import:"default"}),thin:import.meta.glob("../node_modules/@phosphor-icons/core/assets/thin/*.svg",{query:"?raw",import:"default"}),light:import.meta.glob("../node_modules/@phosphor-icons/core/assets/light/*.svg",{query:"?raw",import:"default"}),bold:import.meta.glob("../node_modules/@phosphor-icons/core/assets/bold/*.svg",{query:"?raw",import:"default"}),fill:import.meta.glob("../node_modules/@phosphor-icons/core/assets/fill/*.svg",{query:"?raw",import:"default"}),duotone:import.meta.glob("../node_modules/@phosphor-icons/core/assets/duotone/*.svg",{query:"?raw",import:"default"})},ly=!0}catch(s){s&&!(s instanceof ReferenceError)&&console.warn(`[icons-phosphor] import.meta.glob threw an unexpected error (not a vanilla ReferenceError): ${s.message}. Falling back to manifest fetch. If you're using Vite, this likely means a misconfigured plugin order or glob root.`)}ly?(Object.values(zd).reduce((t,e)=>t+Object.keys(e).length,0)===0&&console.warn(`[icons-phosphor] No Phosphor icons matched the auto-install glob \`../node_modules/@phosphor-icons/core/assets/<weight>/*.svg\` (resolved relative to this file's own directory \u2014 hoisting-safe under pnpm, gh#287). Two known causes: (1) this package got pre-bundled by Vite's dev-server optimizeDeps, which empties the glob \u2014 add it to optimizeDeps.exclude in your Vite config:
53
53
  optimizeDeps: { exclude: ['@adia-ai/web-components', '@adia-ai/web-modules'] }
54
54
  (2) @phosphor-icons/core is missing, or this file was re-nested to a different depth by a packaging step (Yarn PnP, a custom bundler). If neither fix applies, install loaders manually instead:
@@ -71,7 +71,7 @@ See the JSDoc header of icons-phosphor.js for the full recipe.`),Qh(zd)):import(
71
71
  installIconLoaders({ regular: {
72
72
  '/node_modules/@phosphor-icons/core/assets/regular/caret-right.svg': caretRight,
73
73
  } });
74
- See USAGE.md \xA7 Icons.`)},0))}var or=class extends v{static properties={name:{type:String,default:"",reflect:!0},size:{type:String,default:"",reflect:!0},label:{type:String,default:"",reflect:!0},weight:{type:String,default:"regular",reflect:!0}};#t=this.signal(0);#e=null;connected(){this.setAttribute("role",this.label?"img":"presentation"),this.label||this.setAttribute("aria-hidden","true"),this.#e=new AbortController;let t=this.#e;Ph.then(()=>{t.signal.aborted||this.#t.value++})}disconnected(){this.#e?.abort(),this.#e=null}render(){this.#t.value,this.label&&this.setAttribute("aria-label",this.label);let t=oy(this.name,this.weight||"regular");t&&this.innerHTML!==t?this.innerHTML=t:this.name&&!t&&kC(),this.size&&this.#i(this.size)?this.style.setProperty("--icon-size",this.#s(this.size)):this.style.getPropertyValue("--icon-size")&&this.style.removeProperty("--icon-size")}#i(t){return/^\d+(\.\d+)?(px|rem|em|%)?$/.test(t)}#s(t){return/^\d+(\.\d+)?$/.test(t)?`${t}px`:t}};C();y("icon-ui",or);P();var AC={plus:["+","\uFF0B"],minus:["-","\u2212","\u2013"],x:["\xD7","x ","X "],check:["\u2713","\u2714"],"arrow-right":["\u2192",">"],"arrow-left":["\u2190","<"]},ar=class s extends v{static properties={text:{type:String,default:"",reflect:!0},variant:{type:String,default:"solid",reflect:!0},color:{type:String,default:"",reflect:!0},size:{type:String,default:"md",reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0},stretch:{type:Boolean,default:!1,reflect:!0},icon:{type:String,default:"",reflect:!0},iconTrailing:{type:String,default:"",reflect:!0,attribute:"icon-trailing"},type:{type:String,default:"button",reflect:!0}};static template=()=>null;connected(){this.hasAttribute("role")||this.setAttribute("role","button"),this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.addEventListener("click",this.#i),this.addEventListener("keydown",this.#s)}render(){if(this.text&&this.setAttribute("aria-label",this.text),this.icon){let e=this.querySelector(":scope > icon-ui:not([slot])");if(!e||e.name!==this.icon){e&&e.remove();let i=document.createElement("icon-ui");i.setAttribute("name",this.icon),this.prepend(i)}}if(this.iconTrailing){let e=this.querySelector(':scope > icon-ui[slot="icon-trailing"]');if(!e||e.name!==this.iconTrailing){e&&e.remove();let i=document.createElement("icon-ui");i.setAttribute("name",this.iconTrailing),i.setAttribute("slot","icon-trailing"),this.appendChild(i)}}let t=Array.from(this.childNodes).some(e=>e.nodeType===3&&e.textContent.trim()!=="");if(this.toggleAttribute("data-icon-only",!this.text&&!t),this.icon&&this.text){let e=AC[this.icon];e&&e.some(i=>this.text.startsWith(i))&&(s.#e.has(this)||(s.#e.add(this),console.warn(`[button-ui] text="${this.text}" begins with a symbol that icon="${this.icon}" already renders \u2014 the glyph appears twice. Drop the leading symbol from text= (the icon provides it).`,this)))}if(this.icon&&!this.text&&!t){let e=this.getAttribute("aria-label"),i=this.getAttribute("aria-labelledby"),r=this.getAttribute("title");!e&&!i&&r?this.setAttribute("aria-label",r):!e&&!i&&!r&&(s.#t.has(this)||(s.#t.add(this),console.warn(`[button-ui] Icon-only button is missing an accessible name.
74
+ See USAGE.md \xA7 Icons.`)},0))}var or=class extends v{static properties={name:{type:String,default:"",reflect:!0},size:{type:String,default:"",reflect:!0},label:{type:String,default:"",reflect:!0},weight:{type:String,default:"regular",reflect:!0},tone:{type:String,default:"",reflect:!0}};#t=this.signal(0);#e=null;connected(){this.setAttribute("role",this.label?"img":"presentation"),this.label||this.setAttribute("aria-hidden","true"),this.#e=new AbortController;let t=this.#e;Ph.then(()=>{t.signal.aborted||this.#t.value++})}disconnected(){this.#e?.abort(),this.#e=null}render(){this.#t.value,this.label&&this.setAttribute("aria-label",this.label);let t=oy(this.name,this.weight||"regular");t&&this.innerHTML!==t?this.innerHTML=t:this.name&&!t&&kC(),this.size&&this.#i(this.size)?this.style.setProperty("--icon-size",this.#s(this.size)):this.style.getPropertyValue("--icon-size")&&this.style.removeProperty("--icon-size")}#i(t){return/^\d+(\.\d+)?(px|rem|em|%)?$/.test(t)}#s(t){return/^\d+(\.\d+)?$/.test(t)?`${t}px`:t}};C();y("icon-ui",or);P();var AC={plus:["+","\uFF0B"],minus:["-","\u2212","\u2013"],x:["\xD7","x ","X "],check:["\u2713","\u2714"],"arrow-right":["\u2192",">"],"arrow-left":["\u2190","<"]},ar=class s extends v{static properties={text:{type:String,default:"",reflect:!0},variant:{type:String,default:"solid",reflect:!0},color:{type:String,default:"",reflect:!0},size:{type:String,default:"md",reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0},stretch:{type:Boolean,default:!1,reflect:!0},icon:{type:String,default:"",reflect:!0},iconTrailing:{type:String,default:"",reflect:!0,attribute:"icon-trailing"},type:{type:String,default:"button",reflect:!0}};static template=()=>null;connected(){this.hasAttribute("role")||this.setAttribute("role","button"),this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.addEventListener("click",this.#i),this.addEventListener("keydown",this.#s)}render(){if(this.text&&this.setAttribute("aria-label",this.text),this.icon){let e=this.querySelector(":scope > icon-ui:not([slot])");if(!e||e.name!==this.icon){e&&e.remove();let i=document.createElement("icon-ui");i.setAttribute("name",this.icon),this.prepend(i)}}if(this.iconTrailing){let e=this.querySelector(':scope > icon-ui[slot="icon-trailing"]');if(!e||e.name!==this.iconTrailing){e&&e.remove();let i=document.createElement("icon-ui");i.setAttribute("name",this.iconTrailing),i.setAttribute("slot","icon-trailing"),this.appendChild(i)}}let t=Array.from(this.childNodes).some(e=>e.nodeType===3&&e.textContent.trim()!=="");if(this.toggleAttribute("data-icon-only",!this.text&&!t),this.icon&&this.text){let e=AC[this.icon];e&&e.some(i=>this.text.startsWith(i))&&(s.#e.has(this)||(s.#e.add(this),console.warn(`[button-ui] text="${this.text}" begins with a symbol that icon="${this.icon}" already renders \u2014 the glyph appears twice. Drop the leading symbol from text= (the icon provides it).`,this)))}if(this.icon&&!this.text&&!t){let e=this.getAttribute("aria-label"),i=this.getAttribute("aria-labelledby"),r=this.getAttribute("title");!e&&!i&&r?this.setAttribute("aria-label",r):!e&&!i&&!r&&(s.#t.has(this)||(s.#t.add(this),console.warn(`[button-ui] Icon-only button is missing an accessible name.
75
75
  Element: <button-ui icon="${this.icon}">
76
76
  Add one of:
77
77
  aria-label="Undo" \u2190 explicit accessible name
@@ -221,7 +221,7 @@ Correct shape for <chart-ui x="label" y="value">:
221
221
  <div slot="segment" data-i="3"></div>
222
222
  </div>
223
223
  <span slot="label" aria-live="polite"></span>
224
- `),this.setAttribute("role","meter"),this.setAttribute("aria-valuemin","0"),this.setAttribute("aria-valuemax","3")}render(){let t=v$(this.value);t<0?(this.removeAttribute("data-score"),this.removeAttribute("aria-valuenow"),this.setAttribute("aria-valuetext","Empty")):(this.setAttribute("data-score",String(t)),this.setAttribute("aria-valuenow",String(t)),this.setAttribute("aria-valuetext",df[t])),this.querySelectorAll('[slot="segment"]').forEach((r,n)=>{t>=0&&n<=t?r.setAttribute("data-lit",""):r.removeAttribute("data-lit")});let i=this.querySelector('[slot="label"]');i&&(i.textContent=t>=0&&this.showLabel!==!1?df[t]:""),t!==this.#t&&(this.#t=t,this.dispatchEvent(new CustomEvent("score-change",{bubbles:!0,detail:{score:t,label:t>=0?df[t]:"",satisfied:t>=this.minScore}})))}};C();y("password-strength-ui",Pn);P();function x$(s){return(s||"").trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"section"}var Qn=class extends v{static properties={target:{type:String,default:"",reflect:!0},headings:{type:String,default:"h2,h3",reflect:!0},offset:{type:Number,default:80,reflect:!0},label:{type:String,default:"Table of contents",reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s="";#r=!1;#n(){if(this.target){let t=this.ownerDocument?.querySelector(this.target)||document.querySelector(this.target);return t||null}return this.parentElement}#a(){let t=this.#n();if(!t)return[];let e=(this.headings||"h2,h3").trim();return Array.from(t.querySelectorAll(e)).filter(r=>!this.contains(r))}#o(t){let e=this.ownerDocument||document;for(let i of t){if(i.id)continue;let r=x$(i.textContent),n=r,o=1;for(;e.getElementById(n)&&e.getElementById(n)!==i;)n=`${r}-${o++}`;i.id=n}}#l(t){if(t.length===0)return[];let e=t.map(r=>{let n=/^h([1-6])$/i.exec(r.tagName);return n?parseInt(n[1],10):6}),i=Math.min(...e);return e.map(r=>r-i)}#h(){let t=this.#a();this.#o(t);let e=this.#l(t),i=t.map((a,l)=>`${a.id}:${e[l]}`).join("|");if(i===this.#s&&this.querySelector("nav")){this.#c(t);return}this.#s=i;let r=this.querySelector("nav[data-stamped]");if(r&&r.remove(),t.length===0){this.removeAttribute("aria-label");return}let n=document.createElement("nav");n.setAttribute("data-stamped",""),n.setAttribute("aria-label",this.label||"Table of contents");let o=document.createElement("ul");t.forEach((a,l)=>{let h=document.createElement("li"),c=document.createElement("a");c.setAttribute("href",`#${a.id}`),c.setAttribute("data-target-id",a.id),c.setAttribute("data-depth",String(e[l])),c.textContent=(a.textContent||"").trim(),h.appendChild(c),o.appendChild(h)}),n.appendChild(o),this.appendChild(n),this.#c(t)}#c(t){if(this.#t?.disconnect(),typeof IntersectionObserver>"u"||t.length===0)return;let e=Number.isFinite(this.offset)?this.offset:80;this.#t=new IntersectionObserver(i=>{let r=i.filter(n=>n.isIntersecting).sort((n,o)=>n.boundingClientRect.top-o.boundingClientRect.top);r.length!==0&&this.#d(r[0].target.id)},{rootMargin:`-${e}px 0px -50% 0px`,threshold:0}),t.forEach(i=>this.#t.observe(i))}#d(t){t!==this.#e&&(this.#e=t,this.querySelectorAll("a[data-target-id]").forEach(e=>{e.dataset.targetId===t?e.setAttribute("data-active",""):e.removeAttribute("data-active")}),this.dispatchEvent(new CustomEvent("section-change",{bubbles:!0,detail:{activeId:t}})))}connected(){super.connected(),this.setAttribute("role","navigation"),this.hasAttribute("aria-label")||this.setAttribute("aria-label",this.label||"Table of contents"),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1,this.#h()}))}render(){(this.#s||this.querySelector("nav[data-stamped]"))&&this.#h()}disconnected(){super.disconnected(),this.#t?.disconnect(),this.#t=null}};C();y("toc-ui",Qn);var Za=new Uint8Array(512),Xh=new Uint8Array(256);(function(){let t=1;for(let e=0;e<255;e++)Za[e]=t,Xh[t]=e,t<<=1,t&256&&(t^=285);for(let e=255;e<512;e++)Za[e]=Za[e-255]})();function Bh(s,t){return s===0||t===0?0:Za[(Xh[s]+Xh[t])%255]}function Zy(s){let t=new Array(s).fill(0);t[s-1]=1;let e=1;for(let i=0;i<s;i++){for(let r=0;r<t.length;r++)t[r]=Bh(t[r],e),r+1<t.length&&(t[r]^=t[r+1]);e=Bh(e,2)}return t}function zy(s,t){let e=Zy(t),i=new Array(t).fill(0);for(let r of s){let n=r^i[0];if(i.shift(),i.push(0),n!==0)for(let o=0;o<e.length;o++)i[o]^=Bh(e[o],n)}return i}var ff={L:[[7,1,19,0,0],[10,1,34,0,0],[15,1,55,0,0],[20,1,80,0,0],[26,1,108,0,0],[18,2,68,0,0],[20,2,78,0,0],[24,2,97,0,0],[30,2,116,0,0],[18,2,68,2,69]],M:[[10,1,16,0,0],[16,1,28,0,0],[26,1,44,0,0],[18,2,32,0,0],[24,2,43,0,0],[16,4,27,0,0],[18,4,31,0,0],[22,2,38,2,39],[22,3,36,2,37],[26,4,43,1,44]],Q:[[13,1,13,0,0],[22,1,22,0,0],[18,2,17,0,0],[26,2,24,0,0],[18,2,15,2,16],[24,4,19,0,0],[18,2,14,4,15],[22,4,18,2,19],[20,4,16,4,17],[24,6,19,2,20]],H:[[17,1,9,0,0],[28,1,16,0,0],[22,2,13,0,0],[16,4,9,0,0],[22,2,11,2,12],[28,4,15,0,0],[26,4,13,1,14],[26,4,14,2,15],[24,4,12,4,13],[28,6,15,2,16]]};function _y(s,t){let[,e,i,r,n]=ff[t][s-1];return e*i+r*n}function Vy(s,t){for(let e=1;e<=10;e++){let i=_y(e,t),r=4+(e<10?8:16),n=Math.floor((i*8-r)/8);if(s<=n)return e}return-1}var S$=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50]];function jy(s){let t=[];for(let e=0;e<s.length;e++){let i=s.charCodeAt(e);if(i<128)t.push(i);else if(i<2048)t.push(192|i>>6,128|i&63);else if(i<55296||i>=57344)t.push(224|i>>12,128|i>>6&63,128|i&63);else{e++;let r=s.charCodeAt(e);i=65536+((i&1023)<<10|r&1023),t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}}return t}function Wy(s,t,e){let r=_y(t,e)*8,n=[];Zh(n,4,4);let o=t<10?8:16;Zh(n,s.length,o);for(let u of s)Zh(n,u,8);let a=r-n.length,l=Math.min(4,a);for(let u=0;u<l;u++)n.push(0);for(;n.length%8!==0&&n.length<r;)n.push(0);let h=[236,17],c=0;for(;n.length<r;)Zh(n,h[c%2],8),c++;return w$(n)}function Zh(s,t,e){for(let i=e-1;i>=0;i--)s.push(t>>i&1)}function w$(s){let t=[];for(let e=0;e<s.length;e+=8){let i=0;for(let r=0;r<8;r++)i=i<<1|(s[e+r]||0);t.push(i)}return t}function Fy(s,t,e){let[i,r,n,o,a]=ff[e][t-1],l=[],h=0;for(let f=0;f<r;f++)l.push(s.slice(h,h+n)),h+=n;for(let f=0;f<o;f++)l.push(s.slice(h,h+a)),h+=a;let c=l.map(f=>zy(f,i)),u=[],d=Math.max(n,a||0);for(let f=0;f<d;f++)for(let p of l)f<p.length&&u.push(p[f]);for(let f=0;f<i;f++)for(let p of c)u.push(p[f]);return u}function k$(s){let t=s*4+17,e=Array.from({length:t},()=>new Uint8Array(t)),i=Array.from({length:t},()=>new Uint8Array(t));return{matrix:e,reserved:i,size:t}}function pf(s,t,e,i){for(let r=-1;r<=7;r++)for(let n=-1;n<=7;n++){let o=e+r,a=i+n;if(!(o<0||o>=s.length||a<0||a>=s.length))if(t[o][a]=1,r>=0&&r<=6&&n>=0&&n<=6){let l=r===0||r===6||n===0||n===6,h=r>=2&&r<=4&&n>=2&&n<=4;s[o][a]=l||h?1:0}else s[o][a]=0}}function A$(s,t,e,i){for(let r=-2;r<=2;r++)for(let n=-2;n<=2;n++){let o=e+r,a=i+n;if(o<0||o>=s.length||a<0||a>=s.length)continue;t[o][a]=1;let l=Math.abs(r)===2||Math.abs(n)===2,h=r===0&&n===0;s[o][a]=l||h?1:0}}function E$(s,t){let e=s.length;for(let i=8;i<e-8;i++){let r=i%2===0?1:0;s[6][i]=r,s[i][6]=r,t[6][i]=1,t[i][6]=1}}function C$(s){let t=s.length;for(let e=0;e<=8;e++)s[8][e]=1,s[e][8]=1;for(let e=t-8;e<t;e++)s[8][e]=1;for(let e=t-7;e<t;e++)s[e][8]=1}function $$(s,t,e){let i=s.length;pf(s,t,0,0),pf(s,t,0,i-7),pf(s,t,i-7,0);let r=S$[e-1];for(let n of r)for(let o of r)n===6&&o===6||n===6&&o===i-7||n===i-7&&o===6||A$(s,t,n,o);E$(s,t),s[i-8][8]=1,t[i-8][8]=1,C$(t)}function P$(s,t,e){let i=s.length,r=[];for(let a of e)for(let l=7;l>=0;l--)r.push(a>>l&1);let n=0,o=!0;for(let a=i-1;a>=1;a-=2){a===6&&(a=5);for(let l=0;l<i;l++){let h=o?i-1-l:l;for(let c=0;c<2;c++){let u=a-c;!t[h][u]&&n<r.length&&(s[h][u]=r[n++])}}o=!o}}function Q$(s,t,e){switch(s){case 0:return(t+e)%2===0;case 1:return t%2===0;case 2:return e%3===0;case 3:return(t+e)%3===0;case 4:return(Math.floor(t/2)+Math.floor(e/3))%2===0;case 5:return t*e%2+t*e%3===0;case 6:return(t*e%2+t*e%3)%2===0;case 7:return((t+e)%2+t*e%3)%2===0}return!1}function T$(s,t,e){let i=s.length;for(let r=0;r<i;r++)for(let n=0;n<i;n++)!t[r][n]&&Q$(e,r,n)&&(s[r][n]^=1)}function L$(s,t){let i={L:1,M:0,Q:3,H:2}[s]<<3|t,r=i<<10,n=1335;for(let o=14;o>=10;o--)r&1<<o&&(r^=n<<o-10);return(i<<10|r)^21522}function M$(s,t,e){let i=L$(t,e),r=s.length;for(let n=0;n<=5;n++)s[n][8]=i>>n&1;s[7][8]=i>>6&1,s[8][8]=i>>7&1,s[8][7]=i>>8&1;for(let n=9;n<=14;n++)s[8][14-n]=i>>n&1;for(let n=0;n<=7;n++)s[8][r-1-n]=i>>n&1;for(let n=8;n<=14;n++)s[r-15+n][8]=i>>n&1}function R$(s){let t=s<<12,e=7973;for(let i=17;i>=12;i--)t&1<<i&&(t^=e<<i-12);return s<<12|t}function I$(s,t,e){if(t<7)return;let i=R$(t),r=s.length;for(let n=0;n<18;n++){let o=i>>n&1,a=Math.floor(n/3),l=n%3+r-11;s[a][l]=o,s[l][a]=o,e&&(e[a][l]=1,e[l][a]=1)}}function D$(s){let t=s.length,e=0;for(let l=0;l<t;l++){let h=1;for(let c=1;c<t;c++)s[l][c]===s[l][c-1]?(h++,h===5?e+=3:h>5&&e++):h=1}for(let l=0;l<t;l++){let h=1;for(let c=1;c<t;c++)s[c][l]===s[c-1][l]?(h++,h===5?e+=3:h>5&&e++):h=1}for(let l=0;l<t-1;l++)for(let h=0;h<t-1;h++){let c=s[l][h];s[l][h+1]===c&&s[l+1][h]===c&&s[l+1][h+1]===c&&(e+=3)}let i=[1,0,1,1,1,0,1];for(let l=0;l<t;l++)for(let h=0;h<=t-11;h++){let c=!0;for(let u=0;u<7;u++)if(s[l][h+u]!==i[u]){c=!1;break}if(c){let u=h+7<=t-4&&s[l][h+7]===0&&s[l][h+8]===0&&s[l][h+9]===0&&s[l][h+10]===0,d=h>=4&&s[l][h-1]===0&&s[l][h-2]===0&&s[l][h-3]===0&&s[l][h-4]===0;(u||d)&&(e+=40)}}for(let l=0;l<t;l++)for(let h=0;h<=t-11;h++){let c=!0;for(let u=0;u<7;u++)if(s[h+u][l]!==i[u]){c=!1;break}if(c){let u=h+7<=t-4&&s[h+7][l]===0&&s[h+8][l]===0&&s[h+9][l]===0&&s[h+10][l]===0,d=h>=4&&s[h-1][l]===0&&s[h-2][l]===0&&s[h-3][l]===0&&s[h-4][l]===0;(u||d)&&(e+=40)}}let r=0;for(let l=0;l<t;l++)for(let h=0;h<t;h++)s[l][h]&&r++;let n=t*t,o=r*100/n,a=Math.floor(Math.abs(o-50)/5);return e+=a*10,e}var c_={rsGenerator:Zy,rsEncode:zy,gfMul:Bh,EXP:Za,LOG:Xh,buildDataBits:Wy,interleaveCodewords:Fy,utf8Encode:jy,selectVersion:Vy};function Uy(s,t={}){let e=t.errorCorrection||"M";if(!ff[e])throw new Error(`Unknown error-correction level: ${e}. Expected L/M/Q/H.`);let i=jy(s),r=t.version||Vy(i.length,e);if(r<1||r>10)throw new Error(`QR encoder supports versions 1-10 only; data length ${i.length} bytes exceeds capacity at ECC=${e}.`);let n=Wy(i,r,e),o=Fy(n,r,e),a=null,l=1/0;for(let h=0;h<8;h++){let{matrix:c,reserved:u,size:d}=k$(r);$$(c,u,r),I$(c,r,u),P$(c,u,o),T$(c,u,h),M$(c,e,h);let f=D$(c);f<l&&(l=f,a={matrix:c,size:d,version:r,mask:h,ecc:e})}return a}function Yy(s,t={}){let e=s.length,i=t.cellSize||8,r=t.margin!=null?t.margin:4,n=t.color||"#000",o=t.background||"#fff",a=(e+r*2)*i,l=[];for(let h=0;h<e;h++)for(let c=0;c<e;c++)if(s[h][c]){let u=(c+r)*i,d=(h+r)*i;l.push(`<rect x="${u}" y="${d}" width="${i}" height="${i}"/>`)}return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${a} ${a}" width="${a}" height="${a}" shape-rendering="crispEdges">
224
+ `),this.setAttribute("role","meter"),this.setAttribute("aria-valuemin","0"),this.setAttribute("aria-valuemax","3")}render(){let t=v$(this.value);t<0?(this.removeAttribute("data-score"),this.removeAttribute("aria-valuenow"),this.setAttribute("aria-valuetext","Empty")):(this.setAttribute("data-score",String(t)),this.setAttribute("aria-valuenow",String(t)),this.setAttribute("aria-valuetext",df[t])),this.querySelectorAll('[slot="segment"]').forEach((r,n)=>{t>=0&&n<=t?r.setAttribute("data-lit",""):r.removeAttribute("data-lit")});let i=this.querySelector('[slot="label"]');i&&(i.textContent=t>=0&&this.showLabel!==!1?df[t]:""),t!==this.#t&&(this.#t=t,this.dispatchEvent(new CustomEvent("score-change",{bubbles:!0,detail:{score:t,label:t>=0?df[t]:"",satisfied:t>=this.minScore}})))}};C();y("password-strength-ui",Pn);P();function x$(s){return(s||"").trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"section"}var Qn=class extends v{static properties={target:{type:String,default:"",reflect:!0},headings:{type:String,default:"h2,h3",reflect:!0},offset:{type:Number,default:80,reflect:!0},label:{type:String,default:"Table of contents",reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s="";#r=!1;#n(){if(this.target){let t=this.ownerDocument?.querySelector(this.target)||document.querySelector(this.target);return t||null}return this.parentElement}#a(){let t=this.#n();if(!t)return[];let e=(this.headings||"h2,h3").trim();return Array.from(t.querySelectorAll(e)).filter(r=>!this.contains(r))}#o(t){let e=this.ownerDocument||document;for(let i of t){if(i.id)continue;let r=x$(i.textContent),n=r,o=1;for(;e.getElementById(n)&&e.getElementById(n)!==i;)n=`${r}-${o++}`;i.id=n}}#l(t){if(t.length===0)return[];let e=t.map(r=>{let n=/^h([1-6])$/i.exec(r.tagName);return n?parseInt(n[1],10):6}),i=Math.min(...e);return e.map(r=>r-i)}#h(){let t=this.#a();this.#o(t);let e=this.#l(t),i=t.map((a,l)=>`${a.id}:${e[l]}`).join("|");if(i===this.#s&&this.querySelector("nav")){this.#c(t);return}this.#s=i;let r=this.querySelector("nav[data-stamped]");if(r&&r.remove(),t.length===0){this.removeAttribute("aria-label");return}let n=document.createElement("nav");n.setAttribute("data-stamped",""),n.setAttribute("aria-label",this.label||"Table of contents");let o=document.createElement("ul");t.forEach((a,l)=>{let h=document.createElement("li"),c=document.createElement("a");c.setAttribute("href",`#${a.id}`),c.setAttribute("data-target-id",a.id),c.setAttribute("data-depth",String(e[l])),c.textContent=(a.textContent||"").trim(),h.appendChild(c),o.appendChild(h)}),n.appendChild(o),this.appendChild(n),this.#c(t)}#c(t){if(this.#t?.disconnect(),typeof IntersectionObserver>"u"||t.length===0)return;let e=Number.isFinite(this.offset)?this.offset:80;this.#t=new IntersectionObserver(i=>{let r=i.filter(n=>n.isIntersecting).sort((n,o)=>n.boundingClientRect.top-o.boundingClientRect.top);r.length!==0&&this.#d(r[0].target.id)},{rootMargin:`-${e}px 0px -50% 0px`,threshold:0}),t.forEach(i=>this.#t.observe(i))}#d(t){t!==this.#e&&(this.#e=t,this.querySelectorAll("a[data-target-id]").forEach(e=>{e.dataset.targetId===t?e.setAttribute("data-active",""):e.removeAttribute("data-active")}),this.dispatchEvent(new CustomEvent("section-change",{bubbles:!0,detail:{activeId:t}})))}connected(){super.connected(),this.setAttribute("role","navigation"),this.hasAttribute("aria-label")||this.setAttribute("aria-label",this.label||"Table of contents"),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1,this.#h()}))}render(){(this.#s||this.querySelector("nav[data-stamped]"))&&this.#h()}disconnected(){super.disconnected(),this.#t?.disconnect(),this.#t=null}};C();y("toc-ui",Qn);var Za=new Uint8Array(512),Xh=new Uint8Array(256);(function(){let t=1;for(let e=0;e<255;e++)Za[e]=t,Xh[t]=e,t<<=1,t&256&&(t^=285);for(let e=255;e<512;e++)Za[e]=Za[e-255]})();function Bh(s,t){return s===0||t===0?0:Za[(Xh[s]+Xh[t])%255]}function Zy(s){let t=new Array(s).fill(0);t[s-1]=1;let e=1;for(let i=0;i<s;i++){for(let r=0;r<t.length;r++)t[r]=Bh(t[r],e),r+1<t.length&&(t[r]^=t[r+1]);e=Bh(e,2)}return t}function zy(s,t){let e=Zy(t),i=new Array(t).fill(0);for(let r of s){let n=r^i[0];if(i.shift(),i.push(0),n!==0)for(let o=0;o<e.length;o++)i[o]^=Bh(e[o],n)}return i}var ff={L:[[7,1,19,0,0],[10,1,34,0,0],[15,1,55,0,0],[20,1,80,0,0],[26,1,108,0,0],[18,2,68,0,0],[20,2,78,0,0],[24,2,97,0,0],[30,2,116,0,0],[18,2,68,2,69]],M:[[10,1,16,0,0],[16,1,28,0,0],[26,1,44,0,0],[18,2,32,0,0],[24,2,43,0,0],[16,4,27,0,0],[18,4,31,0,0],[22,2,38,2,39],[22,3,36,2,37],[26,4,43,1,44]],Q:[[13,1,13,0,0],[22,1,22,0,0],[18,2,17,0,0],[26,2,24,0,0],[18,2,15,2,16],[24,4,19,0,0],[18,2,14,4,15],[22,4,18,2,19],[20,4,16,4,17],[24,6,19,2,20]],H:[[17,1,9,0,0],[28,1,16,0,0],[22,2,13,0,0],[16,4,9,0,0],[22,2,11,2,12],[28,4,15,0,0],[26,4,13,1,14],[26,4,14,2,15],[24,4,12,4,13],[28,6,15,2,16]]};function _y(s,t){let[,e,i,r,n]=ff[t][s-1];return e*i+r*n}function Vy(s,t){for(let e=1;e<=10;e++){let i=_y(e,t),r=4+(e<10?8:16),n=Math.floor((i*8-r)/8);if(s<=n)return e}return-1}var S$=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50]];function jy(s){let t=[];for(let e=0;e<s.length;e++){let i=s.charCodeAt(e);if(i<128)t.push(i);else if(i<2048)t.push(192|i>>6,128|i&63);else if(i<55296||i>=57344)t.push(224|i>>12,128|i>>6&63,128|i&63);else{e++;let r=s.charCodeAt(e);i=65536+((i&1023)<<10|r&1023),t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}}return t}function Wy(s,t,e){let r=_y(t,e)*8,n=[];Zh(n,4,4);let o=t<10?8:16;Zh(n,s.length,o);for(let u of s)Zh(n,u,8);let a=r-n.length,l=Math.min(4,a);for(let u=0;u<l;u++)n.push(0);for(;n.length%8!==0&&n.length<r;)n.push(0);let h=[236,17],c=0;for(;n.length<r;)Zh(n,h[c%2],8),c++;return w$(n)}function Zh(s,t,e){for(let i=e-1;i>=0;i--)s.push(t>>i&1)}function w$(s){let t=[];for(let e=0;e<s.length;e+=8){let i=0;for(let r=0;r<8;r++)i=i<<1|(s[e+r]||0);t.push(i)}return t}function Fy(s,t,e){let[i,r,n,o,a]=ff[e][t-1],l=[],h=0;for(let f=0;f<r;f++)l.push(s.slice(h,h+n)),h+=n;for(let f=0;f<o;f++)l.push(s.slice(h,h+a)),h+=a;let c=l.map(f=>zy(f,i)),u=[],d=Math.max(n,a||0);for(let f=0;f<d;f++)for(let p of l)f<p.length&&u.push(p[f]);for(let f=0;f<i;f++)for(let p of c)u.push(p[f]);return u}function k$(s){let t=s*4+17,e=Array.from({length:t},()=>new Uint8Array(t)),i=Array.from({length:t},()=>new Uint8Array(t));return{matrix:e,reserved:i,size:t}}function pf(s,t,e,i){for(let r=-1;r<=7;r++)for(let n=-1;n<=7;n++){let o=e+r,a=i+n;if(!(o<0||o>=s.length||a<0||a>=s.length))if(t[o][a]=1,r>=0&&r<=6&&n>=0&&n<=6){let l=r===0||r===6||n===0||n===6,h=r>=2&&r<=4&&n>=2&&n<=4;s[o][a]=l||h?1:0}else s[o][a]=0}}function A$(s,t,e,i){for(let r=-2;r<=2;r++)for(let n=-2;n<=2;n++){let o=e+r,a=i+n;if(o<0||o>=s.length||a<0||a>=s.length)continue;t[o][a]=1;let l=Math.abs(r)===2||Math.abs(n)===2,h=r===0&&n===0;s[o][a]=l||h?1:0}}function E$(s,t){let e=s.length;for(let i=8;i<e-8;i++){let r=i%2===0?1:0;s[6][i]=r,s[i][6]=r,t[6][i]=1,t[i][6]=1}}function C$(s){let t=s.length;for(let e=0;e<=8;e++)s[8][e]=1,s[e][8]=1;for(let e=t-8;e<t;e++)s[8][e]=1;for(let e=t-7;e<t;e++)s[e][8]=1}function $$(s,t,e){let i=s.length;pf(s,t,0,0),pf(s,t,0,i-7),pf(s,t,i-7,0);let r=S$[e-1];for(let n of r)for(let o of r)n===6&&o===6||n===6&&o===i-7||n===i-7&&o===6||A$(s,t,n,o);E$(s,t),s[i-8][8]=1,t[i-8][8]=1,C$(t)}function P$(s,t,e){let i=s.length,r=[];for(let a of e)for(let l=7;l>=0;l--)r.push(a>>l&1);let n=0,o=!0;for(let a=i-1;a>=1;a-=2){a===6&&(a=5);for(let l=0;l<i;l++){let h=o?i-1-l:l;for(let c=0;c<2;c++){let u=a-c;!t[h][u]&&n<r.length&&(s[h][u]=r[n++])}}o=!o}}function Q$(s,t,e){switch(s){case 0:return(t+e)%2===0;case 1:return t%2===0;case 2:return e%3===0;case 3:return(t+e)%3===0;case 4:return(Math.floor(t/2)+Math.floor(e/3))%2===0;case 5:return t*e%2+t*e%3===0;case 6:return(t*e%2+t*e%3)%2===0;case 7:return((t+e)%2+t*e%3)%2===0}return!1}function T$(s,t,e){let i=s.length;for(let r=0;r<i;r++)for(let n=0;n<i;n++)!t[r][n]&&Q$(e,r,n)&&(s[r][n]^=1)}function L$(s,t){let i={L:1,M:0,Q:3,H:2}[s]<<3|t,r=i<<10,n=1335;for(let o=14;o>=10;o--)r&1<<o&&(r^=n<<o-10);return(i<<10|r)^21522}function M$(s,t,e){let i=L$(t,e),r=s.length;for(let n=0;n<=5;n++)s[n][8]=i>>n&1;s[7][8]=i>>6&1,s[8][8]=i>>7&1,s[8][7]=i>>8&1;for(let n=9;n<=14;n++)s[8][14-n]=i>>n&1;for(let n=0;n<=7;n++)s[8][r-1-n]=i>>n&1;for(let n=8;n<=14;n++)s[r-15+n][8]=i>>n&1}function R$(s){let t=s<<12,e=7973;for(let i=17;i>=12;i--)t&1<<i&&(t^=e<<i-12);return s<<12|t}function I$(s,t,e){if(t<7)return;let i=R$(t),r=s.length;for(let n=0;n<18;n++){let o=i>>n&1,a=Math.floor(n/3),l=n%3+r-11;s[a][l]=o,s[l][a]=o,e&&(e[a][l]=1,e[l][a]=1)}}function D$(s){let t=s.length,e=0;for(let l=0;l<t;l++){let h=1;for(let c=1;c<t;c++)s[l][c]===s[l][c-1]?(h++,h===5?e+=3:h>5&&e++):h=1}for(let l=0;l<t;l++){let h=1;for(let c=1;c<t;c++)s[c][l]===s[c-1][l]?(h++,h===5?e+=3:h>5&&e++):h=1}for(let l=0;l<t-1;l++)for(let h=0;h<t-1;h++){let c=s[l][h];s[l][h+1]===c&&s[l+1][h]===c&&s[l+1][h+1]===c&&(e+=3)}let i=[1,0,1,1,1,0,1];for(let l=0;l<t;l++)for(let h=0;h<=t-11;h++){let c=!0;for(let u=0;u<7;u++)if(s[l][h+u]!==i[u]){c=!1;break}if(c){let u=h+7<=t-4&&s[l][h+7]===0&&s[l][h+8]===0&&s[l][h+9]===0&&s[l][h+10]===0,d=h>=4&&s[l][h-1]===0&&s[l][h-2]===0&&s[l][h-3]===0&&s[l][h-4]===0;(u||d)&&(e+=40)}}for(let l=0;l<t;l++)for(let h=0;h<=t-11;h++){let c=!0;for(let u=0;u<7;u++)if(s[h+u][l]!==i[u]){c=!1;break}if(c){let u=h+7<=t-4&&s[h+7][l]===0&&s[h+8][l]===0&&s[h+9][l]===0&&s[h+10][l]===0,d=h>=4&&s[h-1][l]===0&&s[h-2][l]===0&&s[h-3][l]===0&&s[h-4][l]===0;(u||d)&&(e+=40)}}let r=0;for(let l=0;l<t;l++)for(let h=0;h<t;h++)s[l][h]&&r++;let n=t*t,o=r*100/n,a=Math.floor(Math.abs(o-50)/5);return e+=a*10,e}var f_={rsGenerator:Zy,rsEncode:zy,gfMul:Bh,EXP:Za,LOG:Xh,buildDataBits:Wy,interleaveCodewords:Fy,utf8Encode:jy,selectVersion:Vy};function Uy(s,t={}){let e=t.errorCorrection||"M";if(!ff[e])throw new Error(`Unknown error-correction level: ${e}. Expected L/M/Q/H.`);let i=jy(s),r=t.version||Vy(i.length,e);if(r<1||r>10)throw new Error(`QR encoder supports versions 1-10 only; data length ${i.length} bytes exceeds capacity at ECC=${e}.`);let n=Wy(i,r,e),o=Fy(n,r,e),a=null,l=1/0;for(let h=0;h<8;h++){let{matrix:c,reserved:u,size:d}=k$(r);$$(c,u,r),I$(c,r,u),P$(c,u,o),T$(c,u,h),M$(c,e,h);let f=D$(c);f<l&&(l=f,a={matrix:c,size:d,version:r,mask:h,ecc:e})}return a}function Yy(s,t={}){let e=s.length,i=t.cellSize||8,r=t.margin!=null?t.margin:4,n=t.color||"#000",o=t.background||"#fff",a=(e+r*2)*i,l=[];for(let h=0;h<e;h++)for(let c=0;c<e;c++)if(s[h][c]){let u=(c+r)*i,d=(h+r)*i;l.push(`<rect x="${u}" y="${d}" width="${i}" height="${i}"/>`)}return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${a} ${a}" width="${a}" height="${a}" shape-rendering="crispEdges">
225
225
  <rect width="100%" height="100%" fill="${o}"/>
226
226
  <g fill="${n}">${l.join("")}</g>
227
227
  </svg>`}P();var Tn=class extends v{static properties={value:{type:String,default:"",reflect:!0},matrix:{type:String,default:"",reflect:!0},size:{type:Number,default:200,reflect:!0},errorCorrection:{type:String,default:"M",reflect:!0,attribute:"error-correction"},margin:{type:Number,default:4,reflect:!0},color:{type:String,default:"",reflect:!0},background:{type:String,default:"",reflect:!0},label:{type:String,default:"QR code",reflect:!0}};static template=()=>null;#t="";#e(t){if(!t)return null;try{let e=JSON.parse(t);return!Array.isArray(e)||e.length===0||!Array.isArray(e[0])?null:e.map(i=>i.map(r=>r?1:0))}catch(e){return console.warn("[qr-code-ui] invalid [matrix] JSON:",e.message),null}}#i(){let t=this.#e(this.matrix);if(t)return this.removeAttribute("data-error"),t;if(!this.value)return this.removeAttribute("data-error"),null;try{let e=Uy(this.value,{errorCorrection:this.errorCorrection||"M"});return this.removeAttribute("data-error"),e.matrix}catch(e){return this.setAttribute("data-error",""),console.warn(`[qr-code-ui] encode failed for value (${this.value?.length||0} chars at ECC=${this.errorCorrection}): ${e.message}. Lower ECC, shorten input, or supply a precomputed [matrix].`),null}}connected(){super.connected(),this.setAttribute("role","img"),this.hasAttribute("aria-label")||this.setAttribute("aria-label",this.label||"QR code")}render(){let t=`${this.value}|${this.matrix}|${this.size}|${this.errorCorrection}|${this.margin}|${this.color}|${this.background}`;if(t===this.#t&&this.querySelector("svg"))return;this.#t=t,this.label&&this.setAttribute("aria-label",this.label);let e=this.#i();if(!e){this.innerHTML="";return}let i=Yy(e,{cellSize:8,margin:Number.isFinite(this.margin)?this.margin:4,color:this.color||"#000000",background:this.background||"#ffffff"});this.innerHTML=i;let r=this.querySelector("svg");r&&Number.isFinite(this.size)&&(r.setAttribute("width",String(this.size)),r.setAttribute("height",String(this.size)))}};C();y("qr-code-ui",Tn);P();var Ln=class extends v{static properties={page:{type:Number,default:1,reflect:!0},total:{type:Number,default:1,reflect:!0},siblings:{type:Number,default:1,reflect:!0},variant:{type:String,default:"default",reflect:!0},size:{type:String,default:"md",reflect:!0}};static requiredIcons=["caret-left","caret-right"];static template=()=>null;#t=null;#e=!1;connected(){this.#t||(this.#t=document.createElement("nav"),this.#t.setAttribute("slot","nav"),this.#t.setAttribute("aria-label","Pagination"),this.appendChild(this.#t)),this.#e||(this.#e=!0,this.#t.addEventListener("press",this.#a))}disconnected(){this.#t?.removeEventListener("press",this.#a),this.#t=null,this.#e=!1}render(){if(!this.#t)return;let t=Math.max(1,Math.min(this.page,this.total)),e=Math.max(1,this.total),i=Math.max(0,this.siblings),r=this.#i(t,e,i);this.reconcile(this.#t,r,n=>n.key,(n,o,a)=>a?(this.#n(a,n,t),a):this.#r(n,t))}#i(t,e,i){let r=[];r.push({key:"prev",type:"prev",value:t-1});let n=2*i+5;if(e<=n)for(let o=1;o<=e;o++)r.push({key:`page-${o}`,type:"page",value:o});else{let o=t<=i+3,a=t>=e-i-2;if(o){let l=n-2;for(let h=1;h<=l;h++)r.push({key:`page-${h}`,type:"page",value:h});r.push({key:"ellipsis-end",type:"ellipsis"}),r.push({key:`page-${e}`,type:"page",value:e})}else if(a){r.push({key:"page-1",type:"page",value:1}),r.push({key:"ellipsis-start",type:"ellipsis"});let l=e-n+3;for(let h=l;h<=e;h++)r.push({key:`page-${h}`,type:"page",value:h})}else{r.push({key:"page-1",type:"page",value:1}),r.push({key:"ellipsis-start",type:"ellipsis"});for(let l=t-i;l<=t+i;l++)r.push({key:`page-${l}`,type:"page",value:l});r.push({key:"ellipsis-end",type:"ellipsis"}),r.push({key:`page-${e}`,type:"page",value:e})}}return r.push({key:"next",type:"next",value:t+1}),r}#s(){return this.variant==="button"?"outline":"ghost"}#r(t,e){if(t.type==="ellipsis"){let r=document.createElement("span");return r.setAttribute("data-ellipsis",""),r.textContent="\u2026",r}let i=document.createElement("button-ui");return i.setAttribute("size",this.size),t.type==="prev"?(i.setAttribute("data-prev",""),i.setAttribute("icon","caret-left"),i.setAttribute("aria-label","Previous page")):t.type==="next"?(i.setAttribute("data-next",""),i.setAttribute("icon","caret-right"),i.setAttribute("aria-label","Next page")):(i.setAttribute("data-page",""),i.dataset.value=String(t.value),i.setAttribute("text",String(t.value)),i.setAttribute("aria-label",`Page ${t.value}`)),this.#n(i,t,e),i}#n(t,e,i){e.type!=="ellipsis"&&(t.setAttribute("size",this.size),e.type==="prev"?(t.setAttribute("variant",this.#s()),i<=1?(t.setAttribute("disabled",""),t.setAttribute("tabindex","-1")):(t.removeAttribute("disabled"),t.setAttribute("tabindex","0"))):e.type==="next"?(t.setAttribute("variant",this.#s()),i>=this.total?(t.setAttribute("disabled",""),t.setAttribute("tabindex","-1")):(t.removeAttribute("disabled"),t.setAttribute("tabindex","0"))):(t.dataset.value=String(e.value),t.setAttribute("text",String(e.value)),t.setAttribute("aria-label",`Page ${e.value}`),e.value===i?(t.setAttribute("variant","primary"),t.setAttribute("data-active",""),t.setAttribute("aria-current","page")):(t.setAttribute("variant",this.#s()),t.removeAttribute("data-active"),t.removeAttribute("aria-current"))))}#a=t=>{let e=t.target.closest("[data-prev], [data-next], [data-page]");if(!e||e.hasAttribute("disabled")||!this.#t.contains(e))return;let i;e.hasAttribute("data-prev")?i=this.page-1:e.hasAttribute("data-next")?i=this.page+1:e.hasAttribute("data-page")&&(i=Number(e.dataset.value)),!(i==null||i<1||i>this.total||i===this.page)&&(this.page=i,this.dispatchEvent(new CustomEvent("page-change",{bubbles:!0,detail:{page:this.page}})))}};C();y("pagination-ui",Ln);P();var A5=new Set(["json","html","javascript","js","css","markdown","md","yaml","yml"]),E5={js:"javascript",md:"markdown",yml:"yaml"};function tO(s){if(!s)return"";let t=String(s).toLowerCase();return E5[t]??t}var go=class s extends v{static formAssociated=!0;static properties={language:{type:String,default:"",reflect:!0},inline:{type:Boolean,default:!1,reflect:!0},text:{type:String,default:"",reflect:!0},lineNumbers:{type:Boolean,default:!1,reflect:!0,attribute:"line-numbers"},editable:{type:Boolean,default:!1,reflect:!0},bare:{type:Boolean,default:!1,reflect:!0},placeholder:{type:String,default:"",reflect:!0},name:{type:String,default:"",reflect:!0},required:{type:Boolean,default:!1,reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0},readonly:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=0;#r=!1;#n=null;#a="";#o=null;#l=()=>this.#y();connected(){this.#s+=1,!this.inline&&!this.querySelector(":scope > pre")&&this.#h(),this.#t=this.querySelector(':scope > header [slot="copy"]'),this.#t&&this.#t.addEventListener("click",this.#l);let t=tO(this.language),e=this.hasAttribute("data-line-states")||t==="diff";!this.inline&&!e&&(A5.has(t)||this.editable)&&this.#d()}disconnected(){this.#s+=1,this.#e!=null&&(clearTimeout(this.#e),this.#e=null),this.#t&&(this.#t.removeEventListener("click",this.#l),this.#t=null),this.#i&&(this.#i.destroy(),this.#i=null)}#h(){let t=this.querySelector(":scope > template"),e=this.text?this.text.trim():t?s.#c(t.innerHTML):(this.textContent||"").trim();if(this.textContent="",!this.bare){let l=document.createElement("header"),h=document.createElement("span");h.setAttribute("slot","label"),h.textContent=this.language||"code",l.appendChild(h);let c=document.createElement("div");c.setAttribute("role","button"),c.setAttribute("tabindex","0"),c.setAttribute("slot","copy"),c.textContent="Copy",l.appendChild(c),this.appendChild(l)}let i=document.createElement("pre"),r=document.createElement("code"),n=tO(this.language),o=this.getAttribute("data-line-states");if(o!=null||n==="diff"){r.setAttribute("data-line-state-mode",""),this.lineNumbers&&r.setAttribute("data-line-numbers","");let l=o?.split(",").map(c=>c.trim())??null;e.split(`
@@ -314,7 +314,7 @@ Correct shape for <chart-ui x="label" y="value">:
314
314
  <button-ui variant="ghost" size="sm" icon="caret-left" data-cal-prev aria-label="Previous month"></button-ui>
315
315
  <span data-cal-title>${Z1[e]} ${t}</span>
316
316
  <button-ui variant="ghost" size="sm" icon="caret-right" data-cal-next aria-label="Next month"></button-ui>
317
- </div>`;a+=`<div data-cal-weekdays>${X5.map(f=>`<span>${f}</span>`).join("")}</div>`;let l=new Date(t,e,1).getDay(),h=new Date(t,e+1,0).getDate(),c=new Date(t,e,0).getDate();a+="<div data-cal-grid>";for(let f=l-1;f>=0;f--){let p=c-f;a+=`<button-ui variant="ghost" data-cal-day data-outside disabled tabindex="-1" text="${p}"></button-ui>`}for(let f=1;f<=h;f++){let p=new Date(t,e,f),m=z1(t,e,f),b=_1(p,i),g=r&&_1(p,r),x=n&&p<n||o&&p>o,S=this.#n===f,w=["data-cal-day",`data-date="${m}"`,b?"data-today":"",g?"data-selected":"",x?"disabled":"",S?"data-focused":"",`tabindex="${S?"0":"-1"}"`].filter(Boolean).join(" ");a+=`<button-ui variant="ghost" ${w} text="${f}"></button-ui>`}let d=(7-(l+h)%7)%7;for(let f=1;f<=d;f++)a+=`<button-ui variant="ghost" data-cal-day data-outside disabled tabindex="-1" text="${f}"></button-ui>`;a+="</div>",this.#t.innerHTML=a}#d(t){this.#r+=t,this.#r>11&&(this.#r=0,this.#s++),this.#r<0&&(this.#r=11,this.#s--),this.#n=null,this.#c()}#u(t){this.value=t,this.syncValue(t),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:this.value}})),this.open&&this.#c()}#f=t=>{if(!this.disabled&&!(this.#t&&t.composedPath().includes(this.#t))&&(this.open=!this.open,this.open)){let e=ns(this.value);if(e)this.#s=e.getFullYear(),this.#r=e.getMonth(),this.#n=e.getDate();else{let i=new Date;this.#s=i.getFullYear(),this.#r=i.getMonth(),this.#n=i.getDate()}}};#p=t=>{!this.contains(t.target)&&!(this.#t&&t.composedPath().includes(this.#t))&&(this.open=!1)};#m=t=>{if(!this.open){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),this.open=!0);return}if(t.key==="Escape"){t.preventDefault(),this.open=!1;return}if(t.key==="Enter"){if(t.preventDefault(),this.#n){let i=z1(this.#s,this.#r,this.#n),r=new Date(this.#s,this.#r,this.#n),n=ns(this.min),o=ns(this.max);(!n||r>=n)&&(!o||r<=o)&&this.#u(i)}return}let e={ArrowUp:-7,ArrowDown:7,ArrowLeft:-1,ArrowRight:1};if(e[t.key]!==void 0){t.preventDefault();let i=new Date(this.#s,this.#r+1,0).getDate(),r=(this.#n||1)+e[t.key];if(r<1){this.#d(-1);let o=new Date(this.#s,this.#r+1,0).getDate();this.#n=o+r}else r>i?(this.#d(1),this.#n=r-i):this.#n=r;this.#c(),this.#t?.querySelector("[data-focused]")?.focus()}};disconnected(){super.disconnected(),this.#o!=null&&(cancelAnimationFrame(this.#o),this.#o=null),this.removeEventListener("click",this.#f),this.removeEventListener("keydown",this.#m),document.removeEventListener("pointerdown",this.#p),this.#t&&this.#a&&this.#t.removeEventListener("click",this.#l),this.#a=!1,this.#i?.(),this.#i=null,this.#t?.hidePopover?.(),this.#t=null,this.#e=null}};C();y("calendar-picker-ui",Wo);Pt();var Z5=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],z5=["January","February","March","April","May","June","July","August","September","October","November","December"];function iO(s){return String(s).padStart(2,"0")}function Fe(s){return s?`${s.getFullYear()}-${iO(s.getMonth()+1)}-${iO(s.getDate())}`:""}function sO(s){if(!s)return null;let t=String(s).match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)return null;let e=new Date(+t[1],+t[2]-1,+t[3]);return Number.isNaN(e.getTime())?null:e}function Ue(s){if(s==null)return null;if(typeof s=="object")return!s.from||!s.to?null:{from:String(s.from),to:String(s.to)};if(typeof s!="string"||!s.trim())return null;try{let t=JSON.parse(s);if(t&&t.from&&t.to)return{from:String(t.from),to:String(t.to)}}catch{}return null}function V1(s){return s?s.from<=s.to:!1}function j1(s,t){let e=sO(s);if(!e)return"";switch(t){case"long":return`${z5[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`;case"iso":return s;default:return`${Z5[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`}}function _5(s=new Date){let t=new Date(s.getFullYear(),s.getMonth(),s.getDate()),e=Fe(t),i=a=>{let l=new Date(t);return l.setDate(l.getDate()-a),Fe(l)},r=Fe(new Date(t.getFullYear(),t.getMonth(),1)),n=Fe(new Date(t.getFullYear(),t.getMonth()+1,0)),o=Fe(new Date(t.getFullYear(),0,1));return[{label:"Today",range:{from:e,to:e}},{label:"Last 7 days",range:{from:i(6),to:e}},{label:"Last 30 days",range:{from:i(29),to:e}},{label:"This month",range:{from:r,to:n}},{label:"Year to date",range:{from:o,to:e}}]}function V5(){return[{label:"Previous period"},{label:"Same period last year"},{label:"Same period last month"}]}var Fo=class extends R{static labelDeprecated=!0;static requiredIcons=["calendar","caret-down"];static get properties(){return{...R.properties,compareValue:{type:String,default:"",attribute:"compare-value"},comparison:{type:Boolean,default:!1,reflect:!0},min:{type:String,default:"",reflect:!0},max:{type:String,default:"",reflect:!0},open:{type:Boolean,default:!1,reflect:!0},placeholder:{type:String,default:"Select range",reflect:!0},format:{type:String,default:"short",reflect:!0},noPresets:{type:Boolean,default:!1,attribute:"no-presets",reflect:!0},placement:{type:String,default:"bottom",reflect:!0}}}static parts={trigger:'<button-ui slot="trigger" variant="outline" type="button" icon="calendar" icon-trailing="caret-down" aria-label="Open date range picker"></button-ui>',popover:'<div slot="popover" popover="manual" role="dialog" aria-label="Date range picker"></div>',presets:'<div data-preset-rail role="group" aria-label="Date range presets"></div>',calArea:"<div data-calendar-area></div>",calFrom:'<calendar-grid-ui data-cal-from aria-label="Start date"></calendar-grid-ui>',calTo:'<calendar-grid-ui data-cal-to aria-label="End date"></calendar-grid-ui>'};static template=()=>null;#t=null;#e=null;#i=null;#s=!1;#r=!1;#n=null;#a=null;#o=null;#l=null;#h=null;#c=null;get rangeValue(){return Ue(this.value)}set rangeValue(t){t==null?this.value="":this.value=JSON.stringify({from:String(t.from),to:String(t.to)})}get rangeCompareValue(){return Ue(this.compareValue)}set rangeCompareValue(t){t==null?this.compareValue="":this.compareValue=JSON.stringify({from:String(t.from),to:String(t.to)})}get presets(){return Array.isArray(this.#t)?this.#t:_5()}set presets(t){H(()=>{this.#t=Array.isArray(t)?t.slice():null,this.isConnected&&this.#p()})}open$(){this.open=!0}close$(){this.open=!1}openPopover(){this.disabled||this.readonly||this.open||(this.#i=document.activeElement,this.open=!0,this.dispatchEvent(new CustomEvent("open",{bubbles:!0,detail:{trigger:"programmatic"}})))}closePopover(t="programmatic"){this.open&&(this.open=!1,this.dispatchEvent(new CustomEvent("close",{bubbles:!0,detail:{reason:t}})))}clear(){this.value="",this.comparison&&(this.compareValue=""),this.#e=null,this.syncValue("")}applyPreset(t){let e=this.presets.find(i=>i.label===t);return!e||!e.range?!1:(this.#k(e.range,{presetLabel:e.label}),!0)}syncValue(t){let e=t??this.value??"",i=Ue(e);if(this.comparison&&this.name){let r=new FormData;i&&r.append(this.name,e),Ue(this.compareValue)&&r.append(`${this.name}-compare`,this.compareValue),this.internals.setFormValue(r)}else this.internals.setFormValue(i?e:"");this.#d(i)}#d(t){return this.required&&!t?(this.internals.setValidity({valueMissing:!0},this.getAttribute("data-msg-required")||"Please select a date range.",this),!1):t&&!V1(t)?(this.internals.setValidity({rangeUnderflow:!0},"End date must be on or after start date.",this),!1):t&&this.min&&t.from<this.min?(this.internals.setValidity({rangeUnderflow:!0},`Earliest selectable date is ${this.min}.`,this),!1):t&&this.max&&t.to>this.max?(this.internals.setValidity({rangeOverflow:!0},`Latest selectable date is ${this.max}.`,this),!1):(this.internals.setValidity({}),!0)}connected(){super.connected(),this.setAttribute("role","combobox"),this.setAttribute("aria-haspopup","dialog"),this.setAttribute("aria-expanded",this.open?"true":"false"),this.#s||(this.#s=!0,this.#u(),this.#n.addEventListener("click",this.#g),this.#n.addEventListener("keydown",this.#O,!0),this.#a.addEventListener("click",this.#y),this.#a.addEventListener("keydown",this.#b),this.#l.addEventListener("change",this.#v),this.#h.addEventListener("change",this.#S)),this.syncValue()}disconnected(){super.disconnected(),this.#n&&(this.#n.removeEventListener("click",this.#g),this.#n.removeEventListener("keydown",this.#O,!0)),this.#a&&(this.#a.removeEventListener("click",this.#y),this.#a.removeEventListener("keydown",this.#b),this.#a.hidePopover?.()),this.#l&&this.#l.removeEventListener("change",this.#v),this.#h&&this.#h.removeEventListener("change",this.#S),document.removeEventListener("pointerdown",this.#w),document.removeEventListener("keydown",this.#x),this.#c?.(),this.#c=null,this.#s=!1,this.#r=!1,this.#n=null,this.#a=null,this.#o=null,this.#l=null,this.#h=null}#u(){if(this.#n=this.ensure("trigger"),this.#a=this.ensure("popover"),this.id&&this.#a.setAttribute("aria-labelledby",this.id),!this.#a.querySelector(":scope > [data-calendar-area]")){let r=this.constructor._pp.calArea.cloneNode(!0);this.#a.appendChild(r)}let t=ot(this,"presets")[0];if(t&&t.parentElement!==this.#a)this.#a.appendChild(t),this.#o=t;else if(!this.noPresets&&!t){if(!this.#a.querySelector(":scope > [data-preset-rail]")){let r=this.constructor._pp.presets.cloneNode(!0);this.#a.insertBefore(r,this.#a.querySelector(":scope > [data-calendar-area]"))}this.#o=this.#a.querySelector(":scope > [data-preset-rail]")}let e=this.#a.querySelector(":scope > [data-calendar-area]");if(!e.querySelector(":scope > [data-cal-from]")){let r=this.constructor._pp.calFrom.cloneNode(!0);e.appendChild(r)}if(!e.querySelector(":scope > [data-cal-to]")){let r=this.constructor._pp.calTo.cloneNode(!0),n=Ue(this.value)?.from,o,a;if(n){let[l,h]=n.split("-").map(Number);o=l,a=h-1}else{let l=new Date;o=l.getFullYear(),a=l.getMonth()}a+=1,a>11&&(a=0,o+=1),r.setAttribute("month",`${o}-${iO(a+1)}`),e.appendChild(r)}this.#l=e.querySelector(":scope > [data-cal-from]"),this.#h=e.querySelector(":scope > [data-cal-to]");let i=ot(this,"footer")[0];i&&i.parentElement!==this.#a&&this.#a.appendChild(i)}render(){if(!this.#n)return;let t=this.#f();this.#n.setAttribute("text",t),this.#n.toggleAttribute("data-has-value",t!==this.placeholder),this.#n.toggleAttribute("disabled",this.disabled),this.#n.setAttribute("aria-haspopup","dialog"),this.#n.setAttribute("aria-expanded",this.open?"true":"false"),this.setAttribute("aria-expanded",this.open?"true":"false");let e=Ue(this.value),i=this.#e,r=i?.from||e?.from||"",n=i?.to||e?.to||"",o=a=>{r?a.setAttribute("range-start",r):a.removeAttribute("range-start"),n?a.setAttribute("range-end",n):a.removeAttribute("range-end")};this.#l&&(this.min&&this.#l.setAttribute("min",this.min),this.max&&this.#l.setAttribute("max",this.max),this.#l.value=i?.from||e?.from||"",o(this.#l)),this.#h&&(this.min&&this.#h.setAttribute("min",this.min),this.max&&this.#h.setAttribute("max",this.max),this.#h.value=i?.to||e?.to||"",o(this.#h)),ot(this,"presets").length||(this.noPresets?(this.#o?.remove(),this.#o=null):(this.#o||this.#u(),this.#p())),this.#a&&(this.open&&!this.#r?!this.disabled&&!this.readonly?(this.#r=!0,this.#a.showPopover?.(),this.#c?.(),this.#c=dt(this.#n,this.#a,{placement:this.getAttribute("placement")||"bottom",gap:4}),document.addEventListener("pointerdown",this.#w),document.addEventListener("keydown",this.#x),queueMicrotask(()=>{if(!this.open)return;this.#l?.querySelector?.("[data-cal-day]:not([disabled]):not([data-outside])")?.focus?.()})):this.open=!1:!this.open&&this.#r&&(this.#r=!1,this.#c?.(),this.#c=null,this.#a.hidePopover?.(),document.removeEventListener("pointerdown",this.#w),document.removeEventListener("keydown",this.#x),this.#n?.focus?.()))}#f(){let t=Ue(this.value);if(!t)return this.placeholder;let e=j1(t.from,this.format),i=j1(t.to,this.format);return!e||!i?this.placeholder:`${e} \u2192 ${i}`}#p(){if(this.#o){this.#o.replaceChildren();for(let t of this.presets){let e=document.createElement("button-ui");e.setAttribute("variant","ghost"),e.setAttribute("type","button"),e.setAttribute("text",t.label),e.setAttribute("size","sm"),e.dataset.presetLabel=t.label,this.#o.appendChild(e)}if(this.comparison){let t=document.createElement("divider-ui");t.dataset.presetDivider="",this.#o.appendChild(t);for(let e of V5()){let i=document.createElement("button-ui");i.setAttribute("variant","ghost"),i.setAttribute("type","button"),i.setAttribute("text",e.label),i.setAttribute("size","sm"),i.dataset.comparisonPresetLabel=e.label,this.#o.appendChild(i)}}}}#m=!1;#g=t=>{if(this.disabled||this.readonly)return;t.stopPropagation();let e=this.#m;this.#m=!1,this.open?this.closePopover("outside"):(this.#i=document.activeElement,this.open=!0,this.dispatchEvent(new CustomEvent("open",{bubbles:!0,detail:{trigger:e?"keyboard":"click"}})))};#O=t=>{if(!this.disabled&&(t.key==="Enter"||t.key===" ")){if(this.readonly){t.preventDefault();return}this.#m=!0}};#y=t=>{if(this.readonly){let r=t.target.closest("[data-preset-label],[data-comparison-preset-label]"),n=t.target.closest("[data-cal-day]");if(r||n){t.stopPropagation(),t.preventDefault();return}}let e=t.target.closest("[data-preset-label]");if(e){t.stopPropagation(),this.applyPreset(e.dataset.presetLabel),this.closePopover("apply");return}let i=t.target.closest("[data-comparison-preset-label]");if(i){t.stopPropagation();let r=Ue(this.value);if(!r)return;let n=this.#A(i.dataset.comparisonPresetLabel,r);n&&(this.rangeCompareValue=n);return}};#b=t=>{if(t.key==="Escape"){t.preventDefault(),t.stopPropagation(),this.closePopover("escape");return}if(t.key==="Tab"){let e=this.#E();if(e.length===0)return;let i=e.indexOf(document.activeElement);t.shiftKey?i<=0&&(t.preventDefault(),e[e.length-1].focus()):(i===-1||i===e.length-1)&&(t.preventDefault(),e[0].focus())}};#x=t=>{t.key==="Escape"&&this.open&&this.closePopover("escape")};#v=t=>{if(this.readonly)return;t.stopPropagation();let e=t.detail?.value||this.#l?.value||"";if(!e)return;let i=Ue(this.value);this.#e||(this.#e={from:"",to:""}),this.#e.from=e,this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:{value:{from:e,to:null}}}));let r=this.#e.to||i?.to||null;r&&this.#k({from:e,to:r})};#S=t=>{if(this.readonly)return;t.stopPropagation();let e=t.detail?.value||this.#h?.value||"";if(!e)return;let i=Ue(this.value);this.#e||(this.#e={from:"",to:""}),this.#e.to=e,this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:{value:{from:this.#e.from||i?.from||null,to:e}}}));let r=this.#e.from||i?.from||null;r&&this.#k({from:r,to:e})};#w=t=>{this.open&&(this.contains(t.target)||this.#a&&t.composedPath?.().includes(this.#a)||this.closePopover("outside"))};#k(t,e={}){if(!t||!t.from||!t.to)return;if(!V1(t)){this.dispatchEvent(new CustomEvent("invalid",{bubbles:!0,detail:{value:t,reason:"reversed"}}));return}if(this.min&&t.from<this.min){this.dispatchEvent(new CustomEvent("invalid",{bubbles:!0,detail:{value:t,reason:"below-min"}}));return}if(this.max&&t.to>this.max){this.dispatchEvent(new CustomEvent("invalid",{bubbles:!0,detail:{value:t,reason:"above-max"}}));return}let i=JSON.stringify({from:t.from,to:t.to});this.value=i,this.#e=null,this.syncValue(i),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:{from:t.from,to:t.to},compareValue:Ue(this.compareValue),presetLabel:e.presetLabel||null}}))}#A(t,e){let i=sO(e.from),r=sO(e.to);if(!i||!r)return null;let n=Math.round((r-i)/864e5)+1;switch(t){case"Previous period":{let o=new Date(i);o.setDate(o.getDate()-1);let a=new Date(o);return a.setDate(a.getDate()-(n-1)),{from:Fe(a),to:Fe(o)}}case"Same period last year":{let o=new Date(i);o.setFullYear(o.getFullYear()-1);let a=new Date(r);return a.setFullYear(a.getFullYear()-1),{from:Fe(o),to:Fe(a)}}case"Same period last month":{let o=new Date(i);o.setMonth(o.getMonth()-1);let a=new Date(r);return a.setMonth(a.getMonth()-1),{from:Fe(o),to:Fe(a)}}default:return null}}#E(){if(!this.#a)return[];let t=["button-ui:not([disabled])","button:not([disabled])","calendar-grid-ui:not([disabled])","[data-cal-day]:not([disabled]):not([data-outside])",'[tabindex="0"]'].join(",");return Array.from(this.#a.querySelectorAll(t)).filter(e=>e.offsetParent!==null||e.matches(":popover-open *"))}};C();y("date-range-picker-ui",Fo);var W1=23,F1=12,gU=1,U1=59,Y1=59,j5=["hour","minute"];function Gl(s){if(!s)return null;let t=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(String(s).trim());if(!t)return null;let e=Number(t[1]),i=Number(t[2]),r=t[3]!=null?Number(t[3]):0;return!Number.isFinite(e)||e<0||e>23||!Number.isFinite(i)||i<0||i>59||!Number.isFinite(r)||r<0||r>59?null:{h:e,m:i,s:r}}function rO({h:s,m:t,s:e},i){let r=n=>String(n).padStart(2,"0");return i==="second"?`${r(s)}:${r(t)}:${r(e)}`:`${r(s)}:${r(t)}`}function Uo({h:s,m:t,s:e}){return s*3600+t*60+e}function W5(s){try{let t=s||document?.documentElement?.lang||void 0,i=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions(),r=i.hourCycle||(i.hour12?"h12":"h23");return r==="h11"||r==="h12"?"h12":"h23"}catch{return"h23"}}var Ho=class extends R{static labelDeprecated=!1;static properties={...R.properties,min:{type:String,default:"",reflect:!0},max:{type:String,default:"",reflect:!0},step:{type:Number,default:60,reflect:!0},precision:{type:String,default:"minute",reflect:!0},hourcycle:{type:String,default:"",reflect:!0,attribute:"hour-cycle"},placeholder:{type:String,default:"--",reflect:!1},locale:{type:String,default:"",reflect:!1}};static template=()=>null;#t=null;#e=[];#i="";#s=null;get#r(){return this.hourcycle==="h12"||this.hourcycle==="h23"?this.hourcycle:W5(this.locale)}get#n(){return this.#r==="h12"}get#a(){return this.precision==="second"}get#o(){return`${this.#r}|${this.precision}`}connected(){super.connected(),this.setAttribute("role","group"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Time"),this.required&&this.setAttribute("aria-required","true"),this.#l(),this.addEventListener("keydown",this.#O),this.addEventListener("focusin",this.#y),this.addEventListener("focusout",this.#b)}render(){this.#i&&this.#i!==this.#o&&this.#l(),this.#d(),this.#h()}disconnected(){super.disconnected(),this.removeEventListener("keydown",this.#O),this.removeEventListener("focusin",this.#y),this.removeEventListener("focusout",this.#b),this.#t=null,this.#e=[],this.#s=null}clear(){this.value="",this.syncValue(""),this.#d()}stepUp(t,e=1){this.#f(t,1*(e|0||1))}stepDown(t,e=1){this.#f(t,-1*(e|0||1))}#l(){let t=this.#r,e=this.#a,i=this.#n,r=[...j5];e&&r.push("second"),i&&r.push("meridiem"),this.#e=r;let n=this.querySelector(':scope > [slot="prefix"]'),o=this.querySelector(':scope > [slot="suffix"]'),a=(c,u,d)=>`<span data-segment="${c}" role="spinbutton" tabindex="0"
317
+ </div>`;a+=`<div data-cal-weekdays>${X5.map(f=>`<span>${f}</span>`).join("")}</div>`;let l=new Date(t,e,1).getDay(),h=new Date(t,e+1,0).getDate(),c=new Date(t,e,0).getDate();a+="<div data-cal-grid>";for(let f=l-1;f>=0;f--){let p=c-f;a+=`<button-ui variant="ghost" data-cal-day data-outside disabled tabindex="-1" text="${p}"></button-ui>`}for(let f=1;f<=h;f++){let p=new Date(t,e,f),m=z1(t,e,f),b=_1(p,i),g=r&&_1(p,r),x=n&&p<n||o&&p>o,S=this.#n===f,w=["data-cal-day",`data-date="${m}"`,b?"data-today":"",g?"data-selected":"",x?"disabled":"",S?"data-focused":"",`tabindex="${S?"0":"-1"}"`].filter(Boolean).join(" ");a+=`<button-ui variant="ghost" ${w} text="${f}"></button-ui>`}let d=(7-(l+h)%7)%7;for(let f=1;f<=d;f++)a+=`<button-ui variant="ghost" data-cal-day data-outside disabled tabindex="-1" text="${f}"></button-ui>`;a+="</div>",this.#t.innerHTML=a}#d(t){this.#r+=t,this.#r>11&&(this.#r=0,this.#s++),this.#r<0&&(this.#r=11,this.#s--),this.#n=null,this.#c()}#u(t){this.value=t,this.syncValue(t),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:this.value}})),this.open&&this.#c()}#f=t=>{if(!this.disabled&&!(this.#t&&t.composedPath().includes(this.#t))&&(this.open=!this.open,this.open)){let e=ns(this.value);if(e)this.#s=e.getFullYear(),this.#r=e.getMonth(),this.#n=e.getDate();else{let i=new Date;this.#s=i.getFullYear(),this.#r=i.getMonth(),this.#n=i.getDate()}}};#p=t=>{!this.contains(t.target)&&!(this.#t&&t.composedPath().includes(this.#t))&&(this.open=!1)};#m=t=>{if(!this.open){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),this.open=!0);return}if(t.key==="Escape"){t.preventDefault(),this.open=!1;return}if(t.key==="Enter"){if(t.preventDefault(),this.#n){let i=z1(this.#s,this.#r,this.#n),r=new Date(this.#s,this.#r,this.#n),n=ns(this.min),o=ns(this.max);(!n||r>=n)&&(!o||r<=o)&&this.#u(i)}return}let e={ArrowUp:-7,ArrowDown:7,ArrowLeft:-1,ArrowRight:1};if(e[t.key]!==void 0){t.preventDefault();let i=new Date(this.#s,this.#r+1,0).getDate(),r=(this.#n||1)+e[t.key];if(r<1){this.#d(-1);let o=new Date(this.#s,this.#r+1,0).getDate();this.#n=o+r}else r>i?(this.#d(1),this.#n=r-i):this.#n=r;this.#c(),this.#t?.querySelector("[data-focused]")?.focus()}};disconnected(){super.disconnected(),this.#o!=null&&(cancelAnimationFrame(this.#o),this.#o=null),this.removeEventListener("click",this.#f),this.removeEventListener("keydown",this.#m),document.removeEventListener("pointerdown",this.#p),this.#t&&this.#a&&this.#t.removeEventListener("click",this.#l),this.#a=!1,this.#i?.(),this.#i=null,this.#t?.hidePopover?.(),this.#t=null,this.#e=null}};C();y("calendar-picker-ui",Wo);Pt();var Z5=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],z5=["January","February","March","April","May","June","July","August","September","October","November","December"];function iO(s){return String(s).padStart(2,"0")}function Fe(s){return s?`${s.getFullYear()}-${iO(s.getMonth()+1)}-${iO(s.getDate())}`:""}function sO(s){if(!s)return null;let t=String(s).match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)return null;let e=new Date(+t[1],+t[2]-1,+t[3]);return Number.isNaN(e.getTime())?null:e}function Ue(s){if(s==null)return null;if(typeof s=="object")return!s.from||!s.to?null:{from:String(s.from),to:String(s.to)};if(typeof s!="string"||!s.trim())return null;try{let t=JSON.parse(s);if(t&&t.from&&t.to)return{from:String(t.from),to:String(t.to)}}catch{}return null}function V1(s){return s?s.from<=s.to:!1}function j1(s,t){let e=sO(s);if(!e)return"";switch(t){case"long":return`${z5[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`;case"iso":return s;default:return`${Z5[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`}}function _5(s=new Date){let t=new Date(s.getFullYear(),s.getMonth(),s.getDate()),e=Fe(t),i=a=>{let l=new Date(t);return l.setDate(l.getDate()-a),Fe(l)},r=Fe(new Date(t.getFullYear(),t.getMonth(),1)),n=Fe(new Date(t.getFullYear(),t.getMonth()+1,0)),o=Fe(new Date(t.getFullYear(),0,1));return[{label:"Today",range:{from:e,to:e}},{label:"Last 7 days",range:{from:i(6),to:e}},{label:"Last 30 days",range:{from:i(29),to:e}},{label:"This month",range:{from:r,to:n}},{label:"Year to date",range:{from:o,to:e}}]}function V5(){return[{label:"Previous period"},{label:"Same period last year"},{label:"Same period last month"}]}var Fo=class extends R{static labelDeprecated=!0;static requiredIcons=["calendar","caret-down"];static get properties(){return{...R.properties,compareValue:{type:String,default:"",attribute:"compare-value"},comparison:{type:Boolean,default:!1,reflect:!0},min:{type:String,default:"",reflect:!0},max:{type:String,default:"",reflect:!0},open:{type:Boolean,default:!1,reflect:!0},placeholder:{type:String,default:"Select range",reflect:!0},format:{type:String,default:"short",reflect:!0},noPresets:{type:Boolean,default:!1,attribute:"no-presets",reflect:!0},placement:{type:String,default:"bottom",reflect:!0}}}static parts={trigger:'<button-ui slot="trigger" variant="outline" type="button" icon="calendar" icon-trailing="caret-down" aria-label="Open date range picker"></button-ui>',popover:'<div slot="popover" popover="manual" role="dialog" aria-label="Date range picker"></div>',presets:'<div data-preset-rail role="group" aria-label="Date range presets"></div>',calArea:"<div data-calendar-area></div>",calFrom:'<calendar-grid-ui data-cal-from aria-label="Start date"></calendar-grid-ui>',calTo:'<calendar-grid-ui data-cal-to aria-label="End date"></calendar-grid-ui>'};static template=()=>null;#t=null;#e=null;#i=null;#s=!1;#r=!1;#n=null;#a=null;#o=null;#l=null;#h=null;#c=null;get rangeValue(){return Ue(this.value)}set rangeValue(t){t==null?this.value="":this.value=JSON.stringify({from:String(t.from),to:String(t.to)})}get rangeCompareValue(){return Ue(this.compareValue)}set rangeCompareValue(t){t==null?this.compareValue="":this.compareValue=JSON.stringify({from:String(t.from),to:String(t.to)})}get presets(){return Array.isArray(this.#t)?this.#t:_5()}set presets(t){H(()=>{this.#t=Array.isArray(t)?t.slice():null,this.isConnected&&this.#p()})}open$(){this.open=!0}close$(){this.open=!1}openPopover(){this.disabled||this.readonly||this.open||(this.#i=document.activeElement,this.open=!0,this.dispatchEvent(new CustomEvent("open",{bubbles:!0,detail:{trigger:"programmatic"}})))}closePopover(t="programmatic"){this.open&&(this.open=!1,this.dispatchEvent(new CustomEvent("close",{bubbles:!0,detail:{reason:t}})))}clear(){this.value="",this.comparison&&(this.compareValue=""),this.#e=null,this.syncValue("")}applyPreset(t){let e=this.presets.find(i=>i.label===t);return!e||!e.range?!1:(this.#k(e.range,{presetLabel:e.label}),!0)}syncValue(t){let e=t??this.value??"",i=Ue(e);if(this.comparison&&this.name){let r=new FormData;i&&r.append(this.name,e),Ue(this.compareValue)&&r.append(`${this.name}-compare`,this.compareValue),this.internals.setFormValue(r)}else this.internals.setFormValue(i?e:"");this.#d(i)}#d(t){return this.required&&!t?(this.internals.setValidity({valueMissing:!0},this.getAttribute("data-msg-required")||"Please select a date range.",this),!1):t&&!V1(t)?(this.internals.setValidity({rangeUnderflow:!0},"End date must be on or after start date.",this),!1):t&&this.min&&t.from<this.min?(this.internals.setValidity({rangeUnderflow:!0},`Earliest selectable date is ${this.min}.`,this),!1):t&&this.max&&t.to>this.max?(this.internals.setValidity({rangeOverflow:!0},`Latest selectable date is ${this.max}.`,this),!1):(this.internals.setValidity({}),!0)}connected(){super.connected(),this.setAttribute("role","combobox"),this.setAttribute("aria-haspopup","dialog"),this.setAttribute("aria-expanded",this.open?"true":"false"),this.#s||(this.#s=!0,this.#u(),this.#n.addEventListener("click",this.#g),this.#n.addEventListener("keydown",this.#O,!0),this.#a.addEventListener("click",this.#y),this.#a.addEventListener("keydown",this.#b),this.#l.addEventListener("change",this.#v),this.#h.addEventListener("change",this.#S)),this.syncValue()}disconnected(){super.disconnected(),this.#n&&(this.#n.removeEventListener("click",this.#g),this.#n.removeEventListener("keydown",this.#O,!0)),this.#a&&(this.#a.removeEventListener("click",this.#y),this.#a.removeEventListener("keydown",this.#b),this.#a.hidePopover?.()),this.#l&&this.#l.removeEventListener("change",this.#v),this.#h&&this.#h.removeEventListener("change",this.#S),document.removeEventListener("pointerdown",this.#w),document.removeEventListener("keydown",this.#x),this.#c?.(),this.#c=null,this.#s=!1,this.#r=!1,this.#n=null,this.#a=null,this.#o=null,this.#l=null,this.#h=null}#u(){if(this.#n=this.ensure("trigger"),this.#a=this.ensure("popover"),this.id&&this.#a.setAttribute("aria-labelledby",this.id),!this.#a.querySelector(":scope > [data-calendar-area]")){let r=this.constructor._pp.calArea.cloneNode(!0);this.#a.appendChild(r)}let t=ot(this,"presets")[0];if(t&&t.parentElement!==this.#a)this.#a.appendChild(t),this.#o=t;else if(!this.noPresets&&!t){if(!this.#a.querySelector(":scope > [data-preset-rail]")){let r=this.constructor._pp.presets.cloneNode(!0);this.#a.insertBefore(r,this.#a.querySelector(":scope > [data-calendar-area]"))}this.#o=this.#a.querySelector(":scope > [data-preset-rail]")}let e=this.#a.querySelector(":scope > [data-calendar-area]");if(!e.querySelector(":scope > [data-cal-from]")){let r=this.constructor._pp.calFrom.cloneNode(!0);e.appendChild(r)}if(!e.querySelector(":scope > [data-cal-to]")){let r=this.constructor._pp.calTo.cloneNode(!0),n=Ue(this.value)?.from,o,a;if(n){let[l,h]=n.split("-").map(Number);o=l,a=h-1}else{let l=new Date;o=l.getFullYear(),a=l.getMonth()}a+=1,a>11&&(a=0,o+=1),r.setAttribute("month",`${o}-${iO(a+1)}`),e.appendChild(r)}this.#l=e.querySelector(":scope > [data-cal-from]"),this.#h=e.querySelector(":scope > [data-cal-to]");let i=ot(this,"footer")[0];i&&i.parentElement!==this.#a&&this.#a.appendChild(i)}render(){if(!this.#n)return;let t=this.#f();this.#n.setAttribute("text",t),this.#n.toggleAttribute("data-has-value",t!==this.placeholder),this.#n.toggleAttribute("disabled",this.disabled),this.#n.setAttribute("aria-haspopup","dialog"),this.#n.setAttribute("aria-expanded",this.open?"true":"false"),this.setAttribute("aria-expanded",this.open?"true":"false");let e=Ue(this.value),i=this.#e,r=i?.from||e?.from||"",n=i?.to||e?.to||"",o=a=>{r?a.setAttribute("range-start",r):a.removeAttribute("range-start"),n?a.setAttribute("range-end",n):a.removeAttribute("range-end")};this.#l&&(this.min&&this.#l.setAttribute("min",this.min),this.max&&this.#l.setAttribute("max",this.max),this.#l.value=i?.from||e?.from||"",o(this.#l)),this.#h&&(this.min&&this.#h.setAttribute("min",this.min),this.max&&this.#h.setAttribute("max",this.max),this.#h.value=i?.to||e?.to||"",o(this.#h)),ot(this,"presets").length||(this.noPresets?(this.#o?.remove(),this.#o=null):(this.#o||this.#u(),this.#p())),this.#a&&(this.open&&!this.#r?!this.disabled&&!this.readonly?(this.#r=!0,this.#a.showPopover?.(),this.#c?.(),this.#c=dt(this.#n,this.#a,{placement:this.getAttribute("placement")||"bottom",gap:4}),document.addEventListener("pointerdown",this.#w),document.addEventListener("keydown",this.#x),queueMicrotask(()=>{if(!this.open)return;this.#l?.querySelector?.("[data-cal-day]:not([disabled]):not([data-outside])")?.focus?.()})):this.open=!1:!this.open&&this.#r&&(this.#r=!1,this.#c?.(),this.#c=null,this.#a.hidePopover?.(),document.removeEventListener("pointerdown",this.#w),document.removeEventListener("keydown",this.#x),this.#n?.focus?.()))}#f(){let t=Ue(this.value);if(!t)return this.placeholder;let e=j1(t.from,this.format),i=j1(t.to,this.format);return!e||!i?this.placeholder:`${e} \u2192 ${i}`}#p(){if(this.#o){this.#o.replaceChildren();for(let t of this.presets){let e=document.createElement("button-ui");e.setAttribute("variant","ghost"),e.setAttribute("type","button"),e.setAttribute("text",t.label),e.setAttribute("size","sm"),e.dataset.presetLabel=t.label,this.#o.appendChild(e)}if(this.comparison){let t=document.createElement("divider-ui");t.dataset.presetDivider="",this.#o.appendChild(t);for(let e of V5()){let i=document.createElement("button-ui");i.setAttribute("variant","ghost"),i.setAttribute("type","button"),i.setAttribute("text",e.label),i.setAttribute("size","sm"),i.dataset.comparisonPresetLabel=e.label,this.#o.appendChild(i)}}}}#m=!1;#g=t=>{if(this.disabled||this.readonly)return;t.stopPropagation();let e=this.#m;this.#m=!1,this.open?this.closePopover("outside"):(this.#i=document.activeElement,this.open=!0,this.dispatchEvent(new CustomEvent("open",{bubbles:!0,detail:{trigger:e?"keyboard":"click"}})))};#O=t=>{if(!this.disabled&&(t.key==="Enter"||t.key===" ")){if(this.readonly){t.preventDefault();return}this.#m=!0}};#y=t=>{if(this.readonly){let r=t.target.closest("[data-preset-label],[data-comparison-preset-label]"),n=t.target.closest("[data-cal-day]");if(r||n){t.stopPropagation(),t.preventDefault();return}}let e=t.target.closest("[data-preset-label]");if(e){t.stopPropagation(),this.applyPreset(e.dataset.presetLabel),this.closePopover("apply");return}let i=t.target.closest("[data-comparison-preset-label]");if(i){t.stopPropagation();let r=Ue(this.value);if(!r)return;let n=this.#A(i.dataset.comparisonPresetLabel,r);n&&(this.rangeCompareValue=n);return}};#b=t=>{if(t.key==="Escape"){t.preventDefault(),t.stopPropagation(),this.closePopover("escape");return}if(t.key==="Tab"){let e=this.#E();if(e.length===0)return;let i=e.indexOf(document.activeElement);t.shiftKey?i<=0&&(t.preventDefault(),e[e.length-1].focus()):(i===-1||i===e.length-1)&&(t.preventDefault(),e[0].focus())}};#x=t=>{t.key==="Escape"&&this.open&&this.closePopover("escape")};#v=t=>{if(this.readonly)return;t.stopPropagation();let e=t.detail?.value||this.#l?.value||"";if(!e)return;let i=Ue(this.value);this.#e||(this.#e={from:"",to:""}),this.#e.from=e,this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:{value:{from:e,to:null}}}));let r=this.#e.to||i?.to||null;r&&this.#k({from:e,to:r})};#S=t=>{if(this.readonly)return;t.stopPropagation();let e=t.detail?.value||this.#h?.value||"";if(!e)return;let i=Ue(this.value);this.#e||(this.#e={from:"",to:""}),this.#e.to=e,this.dispatchEvent(new CustomEvent("input",{bubbles:!0,detail:{value:{from:this.#e.from||i?.from||null,to:e}}}));let r=this.#e.from||i?.from||null;r&&this.#k({from:r,to:e})};#w=t=>{this.open&&(this.contains(t.target)||this.#a&&t.composedPath?.().includes(this.#a)||this.closePopover("outside"))};#k(t,e={}){if(!t||!t.from||!t.to)return;if(!V1(t)){this.dispatchEvent(new CustomEvent("invalid",{bubbles:!0,detail:{value:t,reason:"reversed"}}));return}if(this.min&&t.from<this.min){this.dispatchEvent(new CustomEvent("invalid",{bubbles:!0,detail:{value:t,reason:"below-min"}}));return}if(this.max&&t.to>this.max){this.dispatchEvent(new CustomEvent("invalid",{bubbles:!0,detail:{value:t,reason:"above-max"}}));return}let i=JSON.stringify({from:t.from,to:t.to});this.value=i,this.#e=null,this.syncValue(i),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:{from:t.from,to:t.to},compareValue:Ue(this.compareValue),presetLabel:e.presetLabel||null}}))}#A(t,e){let i=sO(e.from),r=sO(e.to);if(!i||!r)return null;let n=Math.round((r-i)/864e5)+1;switch(t){case"Previous period":{let o=new Date(i);o.setDate(o.getDate()-1);let a=new Date(o);return a.setDate(a.getDate()-(n-1)),{from:Fe(a),to:Fe(o)}}case"Same period last year":{let o=new Date(i);o.setFullYear(o.getFullYear()-1);let a=new Date(r);return a.setFullYear(a.getFullYear()-1),{from:Fe(o),to:Fe(a)}}case"Same period last month":{let o=new Date(i);o.setMonth(o.getMonth()-1);let a=new Date(r);return a.setMonth(a.getMonth()-1),{from:Fe(o),to:Fe(a)}}default:return null}}#E(){if(!this.#a)return[];let t=["button-ui:not([disabled])","button:not([disabled])","calendar-grid-ui:not([disabled])","[data-cal-day]:not([disabled]):not([data-outside])",'[tabindex="0"]'].join(",");return Array.from(this.#a.querySelectorAll(t)).filter(e=>e.offsetParent!==null||e.matches(":popover-open *"))}};C();y("date-range-picker-ui",Fo);var W1=23,F1=12,yU=1,U1=59,Y1=59,j5=["hour","minute"];function Gl(s){if(!s)return null;let t=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(String(s).trim());if(!t)return null;let e=Number(t[1]),i=Number(t[2]),r=t[3]!=null?Number(t[3]):0;return!Number.isFinite(e)||e<0||e>23||!Number.isFinite(i)||i<0||i>59||!Number.isFinite(r)||r<0||r>59?null:{h:e,m:i,s:r}}function rO({h:s,m:t,s:e},i){let r=n=>String(n).padStart(2,"0");return i==="second"?`${r(s)}:${r(t)}:${r(e)}`:`${r(s)}:${r(t)}`}function Uo({h:s,m:t,s:e}){return s*3600+t*60+e}function W5(s){try{let t=s||document?.documentElement?.lang||void 0,i=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions(),r=i.hourCycle||(i.hour12?"h12":"h23");return r==="h11"||r==="h12"?"h12":"h23"}catch{return"h23"}}var Ho=class extends R{static labelDeprecated=!1;static properties={...R.properties,min:{type:String,default:"",reflect:!0},max:{type:String,default:"",reflect:!0},step:{type:Number,default:60,reflect:!0},precision:{type:String,default:"minute",reflect:!0},hourcycle:{type:String,default:"",reflect:!0,attribute:"hour-cycle"},placeholder:{type:String,default:"--",reflect:!1},locale:{type:String,default:"",reflect:!1}};static template=()=>null;#t=null;#e=[];#i="";#s=null;get#r(){return this.hourcycle==="h12"||this.hourcycle==="h23"?this.hourcycle:W5(this.locale)}get#n(){return this.#r==="h12"}get#a(){return this.precision==="second"}get#o(){return`${this.#r}|${this.precision}`}connected(){super.connected(),this.setAttribute("role","group"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Time"),this.required&&this.setAttribute("aria-required","true"),this.#l(),this.addEventListener("keydown",this.#O),this.addEventListener("focusin",this.#y),this.addEventListener("focusout",this.#b)}render(){this.#i&&this.#i!==this.#o&&this.#l(),this.#d(),this.#h()}disconnected(){super.disconnected(),this.removeEventListener("keydown",this.#O),this.removeEventListener("focusin",this.#y),this.removeEventListener("focusout",this.#b),this.#t=null,this.#e=[],this.#s=null}clear(){this.value="",this.syncValue(""),this.#d()}stepUp(t,e=1){this.#f(t,1*(e|0||1))}stepDown(t,e=1){this.#f(t,-1*(e|0||1))}#l(){let t=this.#r,e=this.#a,i=this.#n,r=[...j5];e&&r.push("second"),i&&r.push("meridiem"),this.#e=r;let n=this.querySelector(':scope > [slot="prefix"]'),o=this.querySelector(':scope > [slot="suffix"]'),a=(c,u,d)=>`<span data-segment="${c}" role="spinbutton" tabindex="0"
318
318
  aria-label="${u}" aria-valuemin="0" aria-valuemax="${d}"
319
319
  aria-valuenow=""></span>`,l='<span data-separator aria-hidden="true">:</span>',h="";h+=a("hour","Hours",i?F1:W1),h+=l,h+=a("minute","Minutes",U1),e&&(h+=l,h+=a("second","Seconds",Y1)),i&&(h+=`<span data-segment="meridiem" role="spinbutton" tabindex="0"
320
320
  aria-label="AM/PM" aria-valuemin="0" aria-valuemax="1"
@@ -392,7 +392,7 @@ Correct shape for <chart-ui x="label" y="value">:
392
392
  `:typeof t=="string"?t:""}#c(t){let e=t.tone||"neutral",i={success:"var(--a-success-strong)",warning:"var(--a-warning-strong)",danger:"var(--a-danger-strong)",info:"var(--a-primary-strong)",neutral:"var(--a-fg-muted)"}[e]||"var(--a-fg-muted)",r=t.dot===!1?"":`<icon-ui name="circle-fill" data-trace-dot style="color:${i}"></icon-ui>`,n=t.label!=null?String(t.label):"",o=t.value!=null?String(t.value):"",a=o?`${o}${n?` ${n}`:""}`:n;return`<span data-trace-pill>${r}<span>${as(a)}</span></span>`}};function as(s){return String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function AE(s){return String(s).replace(/"/g,"&quot;")}y("agent-trace-ui",th);P();function QO({icon:s,text:t="",title:e=""}){let i=document.createElement("button-ui");return i.setAttribute("icon",s),i.setAttribute("variant","ghost"),i.setAttribute("size","sm"),t&&i.setAttribute("text",t),!t&&e&&i.setAttribute("title",e),i}var xa=class extends v{static properties={saveLabel:{type:String,default:"",reflect:!0,attribute:"save-label"},saveIcon:{type:String,default:"bookmark-simple",reflect:!0,attribute:"save-icon"},disabled:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=null;#r=!1;#n=!1;connected(){this.#d()}disconnected(){this.#t?.removeEventListener("press",this.#a),this.#e?.removeEventListener("press",this.#o),this.#i?.removeEventListener("press",this.#l),this.#t=this.#e=this.#i=this.#s=null}setStatus(t,{lock:e=""}={}){this.#s&&(this.#s.textContent=t||"",(e==="rate"||e==="all")&&(this.#r=!0,this.#t&&(this.#t.disabled=!0),this.#e&&(this.#e.disabled=!0)),(e==="save"||e==="all")&&(this.#n=!0,this.#i&&(this.#i.disabled=!0)))}reset(){this.#r=!1,this.#n=!1,this.#s&&(this.#s.textContent=""),this.#t&&(this.#t.disabled=!1),this.#e&&(this.#e.disabled=!1),this.#i&&(this.#i.disabled=!1)}#a=()=>{!this.#r&&!this.disabled&&this.#h(5)};#o=()=>{!this.#r&&!this.disabled&&this.#h(2)};#l=()=>{!this.#n&&!this.disabled&&this.#c()};#h(t){this.dispatchEvent(new CustomEvent("feedback-rate",{bubbles:!0,detail:{rating:t}})),this.#s?.textContent||this.setStatus(t>=4?"Thanks!":"Noted",{lock:"rate"})}#c(){this.dispatchEvent(new CustomEvent("feedback-save",{bubbles:!0,detail:{}}))}render(){let t=this.saveLabel,e=this.saveIcon;this.#i&&(t?(this.#i.setAttribute("text",t),this.#i.hidden=!1):this.#i.hidden=!0,e&&this.#i.setAttribute("icon",e))}#d(){this.innerHTML="",this.#t=QO({icon:"thumbs-up",title:"Rate this response positively"}),this.#e=QO({icon:"thumbs-down",title:"Rate this response negatively"}),this.#i=QO({icon:this.saveIcon||"bookmark-simple",text:this.saveLabel||"",title:this.saveLabel?"":"Save this response"}),this.saveLabel||(this.#i.hidden=!0),this.#t.addEventListener("press",this.#a),this.#e.addEventListener("press",this.#o),this.#i.addEventListener("press",this.#l),this.#s=document.createElement("span"),this.#s.setAttribute("data-feedback-status",""),this.append(this.#t,this.#e,this.#i,this.#s)}};C();y("agent-feedback-bar-ui",xa);P();function wD(s,t){return typeof s!="string"?"":s.length>t?s.slice(0,t-1)+"\u2026":s}var Sa=class extends v{static properties={variant:{type:String,default:"outline",reflect:!0},size:{type:String,default:"sm",reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=[];get suggestions(){return this.#t}set suggestions(t){this.#t=Array.isArray(t)?t.slice():[],this.#e()}connected(){this.#e()}disconnected(){this.innerHTML=""}#e(){this.innerHTML="";for(let t=0;t<this.#t.length;t++){let e=this.#t[t],i=typeof e=="string"?e:e.label||e.prompt||"",r=typeof e=="string"?e:e.prompt||e.label||"",n=typeof e=="object"?e.icon:null,o=document.createElement("button-ui");o.setAttribute("text",wD(i,42)),o.setAttribute("variant",this.variant),o.setAttribute("size",this.size),n&&o.setAttribute("icon",n),this.disabled&&o.setAttribute("disabled",""),o.addEventListener("press",()=>{this.disabled||this.dispatchEvent(new CustomEvent("suggestion-select",{bubbles:!0,detail:{label:i,prompt:r,index:t}}))}),this.appendChild(o)}}};C();y("agent-suggestions-ui",Sa);P();var wa=class extends v{static properties={multi:{type:Boolean,default:!1,reflect:!0},question:{type:String,default:"",reflect:!0},helper:{type:String,default:"",reflect:!0},submitLabel:{type:String,default:"Continue",reflect:!0,attribute:"submit-label"}};static template=()=>null;#t=[];#e=new Set;#i=!1;#s=null;#r=null;#n=null;#a=null;get options(){return this.#t}set options(t){this.#t=Array.isArray(t)?t.slice():[],this.#e.clear(),this.#i=!1,this.#l()}connected(){this.#o()}disconnected(){this.#a?.removeEventListener("press",this.#f),this.#n?.removeEventListener("change",this.#h),this.#n?.removeEventListener("click",this.#c,!0),this.#n?.removeEventListener("keydown",this.#d,!0),this.#s=this.#r=this.#n=this.#a=null}render(){this.#s&&(this.#s.textContent=this.question||"",this.#s.hidden=!this.question),this.#r&&(this.#r.textContent=this.helper||"",this.#r.hidden=!this.helper),this.#a&&(this.#a.setAttribute("text",this.submitLabel||"Continue"),this.#a.hidden=!this.multi)}#o(){this.innerHTML="",this.#s=document.createElement("div"),this.#s.setAttribute("data-questions-q",""),this.question?this.#s.textContent=this.question:this.#s.hidden=!0,this.#r=document.createElement("div"),this.#r.setAttribute("data-questions-helper",""),this.helper?this.#r.textContent=this.helper:this.#r.hidden=!0,this.#n=document.createElement("div"),this.#n.setAttribute("data-questions-options",""),this.#n.addEventListener("change",this.#h),this.#n.addEventListener("click",this.#c,!0),this.#n.addEventListener("keydown",this.#d,!0),this.#a=document.createElement("button-ui"),this.#a.setAttribute("text",this.submitLabel||"Continue"),this.#a.setAttribute("variant","primary"),this.#a.setAttribute("size","sm"),this.#a.setAttribute("disabled",""),this.multi||(this.#a.hidden=!0),this.#a.addEventListener("press",this.#f),this.append(this.#s,this.#r,this.#n,this.#a),this.#l()}#l(){if(this.#n){this.#n.innerHTML="";for(let t of this.#t){let e=document.createElement("option-card-ui");e.setAttribute("data-questions-option",""),e.setAttribute("data-questions-option-id",t.id),e.name="questions-option",e.value=t.id,e.heading=t.label||"",e.description=t.description||"",e.icon=t.icon||"",this.#n.appendChild(e),this.multi&&e.setAttribute("role","checkbox"),e.checked=this.#e.has(t.id),e.disabled=this.#i}this.#a&&(this.#a.disabled=this.#i||this.#e.size===0)}}#h=t=>{if(this.multi||this.#i)return;let e=t.detail?.value,i=this.#t.find(r=>r.id===e);i&&(this.#e.clear(),this.#e.add(i.id),this.#i=!0,this.#l(),this.dispatchEvent(new CustomEvent("questions-answer",{bubbles:!0,detail:{selected:[i.id],option:i}})))};#c=t=>{if(!this.multi)return;let e=t.target.closest?.("option-card-ui[data-questions-option]");!e||!this.#n.contains(e)||(t.stopPropagation(),this.#u(e))};#d=t=>{if(!this.multi)return;let e=t.target.closest?.("option-card-ui[data-questions-option]");if(!(!e||!this.#n.contains(e))){if(t.key===" "||t.key==="Enter"){t.preventDefault(),t.stopPropagation(),this.#u(e);return}(t.key==="ArrowDown"||t.key==="ArrowUp"||t.key==="ArrowLeft"||t.key==="ArrowRight")&&t.stopPropagation()}};#u(t){if(this.#i)return;let e=t.dataset.questionsOptionId,i=this.#t.find(r=>r.id===e);i&&(this.#e.has(i.id)?this.#e.delete(i.id):this.#e.add(i.id),this.#l())}#f=()=>{if(this.#i||this.#e.size===0)return;this.#i=!0,this.#l();let t=[...this.#e],e=this.#t.find(i=>i.id===t[0])||null;this.dispatchEvent(new CustomEvent("questions-answer",{bubbles:!0,detail:{selected:t,option:e}}))}};C();y("agent-questions-ui",wa);P();var EE={neutral:"default",accent:"accent",warning:"warning",danger:"danger"},ka=class extends v{static properties={title:{type:String,default:"",reflect:!0},kind:{type:String,default:"",reflect:!0},icon:{type:String,default:"",reflect:!0},collapsed:{type:Boolean,default:!1,reflect:!0},tone:{type:String,default:"neutral",reflect:!0}};static requiredIcons=["caret-right","caret-down"];static template=()=>null;#t=null;#e=null;#i=null;#s=null;#r=null;#n=null;connected(){this.#l()}disconnected(){this.#t?.removeEventListener("click",this.#a),this.#t?.removeEventListener("keydown",this.#o),this.#t=this.#e=this.#i=null,this.#s=this.#r=this.#n=null}#a=t=>{t.target.closest('[slot="primary"], [slot="secondary"]')||(this.collapsed=!this.collapsed,this.dispatchEvent(new CustomEvent("artifact-toggle",{bubbles:!0,detail:{collapsed:this.collapsed}})),this.render())};#o=t=>{if(t.key===" "||t.key==="Enter"){if(t.target.closest('[slot="primary"], [slot="secondary"]'))return;t.preventDefault(),this.#a(t)}};render(){this.#t&&(this.#e&&(this.icon?(this.#e.setAttribute("name",this.icon),this.#e.hidden=!1):this.#e.hidden=!0),this.#i&&(this.#i.textContent=this.title||"",this.#i.hidden=!this.title),this.#s&&(this.#s.setAttribute("text",(this.kind||"").toUpperCase()),this.#s.setAttribute("variant",EE[this.tone]||"default"),this.#s.hidden=!this.kind),this.#r&&this.#r.setAttribute("name",this.collapsed?"caret-right":"caret-down"),this.#n&&(this.#n.hidden=this.collapsed),this.#t&&this.#t.setAttribute("aria-expanded",String(!this.collapsed)))}#l(){let t=[],e=[],i=[],r=a=>a.getAttribute("role")==="presentation"||a.style?.display==="contents",n=a=>{for(let l of a){if(l.nodeType===1){let h=l;if(r(h)){n(h.childNodes);continue}let c=h.getAttribute("slot")||"";if(c==="primary"){t.push(h);continue}if(c==="secondary"){e.push(h);continue}}i.push(l)}};n(Array.from(this.childNodes)),this.innerHTML="",this.#t=document.createElement("div"),this.#t.setAttribute("data-artifact-header",""),this.#t.setAttribute("role","button"),this.#t.setAttribute("tabindex","0"),this.#t.setAttribute("aria-expanded",String(!this.collapsed)),this.#t.addEventListener("click",this.#a),this.#t.addEventListener("keydown",this.#o),this.#e=document.createElement("icon-ui"),this.#e.setAttribute("data-artifact-icon",""),this.#e.setAttribute("color","muted"),this.icon?this.#e.setAttribute("name",this.icon):this.#e.hidden=!0,this.#i=document.createElement("span"),this.#i.setAttribute("data-artifact-title",""),this.title?this.#i.textContent=this.title:this.#i.hidden=!0,this.#s=document.createElement("badge-ui"),this.#s.setAttribute("data-artifact-kind",""),this.#s.setAttribute("size","sm"),this.#s.setAttribute("variant",EE[this.tone]||"default"),this.kind?this.#s.setAttribute("text",this.kind.toUpperCase()):this.#s.hidden=!0;let o=document.createElement("span");o.setAttribute("data-artifact-actions","");for(let a of e)o.appendChild(a);for(let a of t)o.appendChild(a);this.#r=document.createElement("icon-ui"),this.#r.setAttribute("color","muted"),this.#r.setAttribute("data-artifact-caret",""),this.#r.setAttribute("name",this.collapsed?"caret-right":"caret-down"),this.#t.append(this.#e,this.#i,this.#s,o,this.#r),this.#n=document.createElement("div"),this.#n.setAttribute("data-artifact-body","");for(let a of i)this.#n.appendChild(a);this.collapsed&&(this.#n.hidden=!0),this.append(this.#t,this.#n)}};C();y("agent-artifact-ui",ka);C();P();var kD="rounded borderless",eh=class s extends v{static properties={mode:{type:String,default:"",reflect:!0}};static template=()=>null;connected(){this.hasAttribute("mode")||(this.mode=kD),this.addEventListener("click",this.#e),this.#i()}#t(t){return this.querySelector(`admin-sidebar[slot="${t}"], admin-sidebar[name="${t}"]`)}#e=t=>{let e=t.target.closest("[data-sidebar-toggle]");if(e&&this.contains(e)){let r=e.getAttribute("data-sidebar-toggle"),n=this.#t(r);n&&typeof n.toggle!="function"&&this.#r("admin-sidebar",`slot="${r}"`,"Sidebar toggle"),n?.toggle?.();return}let i=t.target.closest("[data-command-trigger]");if(i&&this.contains(i)){t.stopPropagation();let r=this.querySelector("admin-command");if(!r)return;if(typeof r.show!="function"){this.#r("admin-command","","Command palette");return}r.show()}};#i(){let t=this.querySelector("admin-command"),e=this.querySelector("nav-ui");!t||!e||t.addEventListener("command-select",i=>{let r=e.querySelector(`nav-item-ui[value="${i.detail.value}"]`);r&&e.select(r)})}static#s=new WeakSet;#r(t,e,i){let r=e?this.querySelector(`${t}[${e}], ${t}[${e.replace("slot=","name=")}]`):this.querySelector(t);if(!r||s.#s.has(r))return;s.#s.add(r);let n=t==="admin-sidebar"?"shell/admin-sidebar":"shell/admin-command";console.warn(`[admin-shell] <${t}${e?" "+e:""}> is in the DOM but ${t==="admin-sidebar"?"AdminSidebar":"AdminCommand"} is NOT registered \u2014 ${i} will not work. Import the cluster barrel \`@adia-ai/web-modules/shell\` (which registers all shell elements), OR add \`@adia-ai/web-modules/${n}\` alongside \`@adia-ai/web-modules/shell/admin-shell\` on the per-component path. Closes FB-55 silent-failure trap.`)}};y("admin-shell",eh);C();P();var Aa=96,CE=160,ih=class s extends v{static properties={collapsed:{type:Boolean,default:!1,reflect:!0},resizing:{type:Boolean,default:!1,reflect:!0},resizable:{type:Boolean,default:!1,reflect:!0},collapsible:{type:Boolean,default:!1,reflect:!0},name:{type:String,default:"",reflect:!0},minWidth:{type:String,default:"",reflect:!0,attribute:"min-width"}};static template=()=>null;static#t=new WeakSet;#e="";#i=[];#s=null;connected(){this.#a(),this.resizable&&this.#l(),this.#h(),this.#o()}disconnected(){for(let t of this.#i)t();this.#i=[],this.#s?.disconnect(),this.#s=null}toggle(){return this.collapsed?this.expand():this.collapse(),this.collapsed}collapse(){if(this.collapsed)return;let t=this.style.width||getComputedStyle(this).width;parseFloat(t)>Aa&&(this.#e=t);let e=this.minWidth||getComputedStyle(this).minWidth;this.style.width=e,this.#n(e),this.collapsed=!0,this.#c(!1)}expand(){if(!this.collapsed)return;let t=this.#e||"";this.style.width=t,this.#n(t),this.collapsed=!1,this.#c(!0)}#r(){return`adia-sidebar-${this.name||this.getAttribute("slot")||"default"}`}#n(t){try{localStorage.setItem(this.#r(),t)}catch{}}#a(){try{let t=localStorage.getItem(this.#r());if(!t)return;this.style.width=t;let e=parseFloat(t);!isNaN(e)&&e>Aa&&(this.#e=t)}catch{}}#o(){let t=this.getBoundingClientRect().width;t!==0&&(this.collapsed=t<=Aa)}#l(){let t=this.querySelector(":scope > [data-resize]");if(!t){s.#t.has(this)||(s.#t.add(this),console.warn("[admin-sidebar] `resizable` is set but no `[data-resize]` child was found. Add `<div data-resize></div>` as a direct child to enable drag-to-resize. (Unlike `collapsible`, `resizable` requires this author-supplied handle.)",this));return}let e=this.getAttribute("slot"),i=e==="leading",r=n=>{n.preventDefault(),t.setPointerCapture(n.pointerId);let o=n.clientX,a=this.getBoundingClientRect().width;this.resizing=!0,document.documentElement.style.cursor="col-resize";let l=c=>{let u=c.clientX-o,d=parseInt(getComputedStyle(this).getPropertyValue("max-width"))||480,f=Math.max(48,Math.min(d,a+(i?u:-u)));this.style.width=`${f}px`},h=()=>{this.resizing=!1,document.documentElement.style.cursor="",t.removeEventListener("pointermove",l),t.removeEventListener("pointerup",h);let c=this.getBoundingClientRect().width;c<=Aa?this.style.width=this.minWidth||getComputedStyle(this).minWidth:c<CE&&(this.style.width=`${CE}px`),this.#n(this.style.width),this.#o(),this.dispatchEvent(new CustomEvent("sidebar-resize",{bubbles:!0,detail:{name:this.name||e,width:this.getBoundingClientRect().width}}))};t.addEventListener("pointermove",l),t.addEventListener("pointerup",h)};t.addEventListener("pointerdown",r),this.#i.push(()=>t.removeEventListener("pointerdown",r))}#h(){typeof ResizeObserver>"u"||(this.#s=new ResizeObserver(t=>{for(let e of t){let i=e.contentBoxSize[0].inlineSize;i>0&&(this.collapsed=i<=Aa);for(let r of this.querySelectorAll("select-ui"))r.setAttribute("placement",i<=Aa?"right":"bottom-start")}}),this.#s.observe(this))}#c(t){this.dispatchEvent(new CustomEvent("sidebar-toggle",{bubbles:!0,detail:{name:this.name||this.getAttribute("slot")||"default",expanded:t}}))}};y("admin-sidebar",ih);C();P();var sh=class extends v{static properties={open:{type:Boolean,default:!1,reflect:!0},shortcut:{type:String,default:"both",reflect:!0},noShortcut:{type:Boolean,default:!1,reflect:!0,attribute:"no-shortcut"}};static template=()=>null;#t=null;#e=null;#i=null;connected(){if(this.#i=this.querySelector(":scope > dialog"),!this.#i){for(this.#i=document.createElement("dialog");this.firstChild;)this.#i.appendChild(this.firstChild);this.appendChild(this.#i)}this.#e=this.querySelector("command-ui"),this.#s(),this.#r(),this.noShortcut||this.#n()}disconnected(){this.#t&&(document.removeEventListener("keydown",this.#t),this.#t=null)}show(){this.#i&&(this.#i.open||(this.#i.showModal(),this.#e&&(this.#e.open=!0,this.#e.value="",this.#e.focus()),this.open=!0))}hide(){this.#i&&this.#i.open&&(this.#i.close(),this.#e&&(this.#e.open=!1),this.open=!1)}toggle(){return this.open?this.hide():this.show(),this.open}#s(){this.#i&&(this.#i.addEventListener("click",t=>{t.target===this.#i&&this.hide()}),this.#i.addEventListener("close",()=>{this.#e&&(this.#e.open=!1),this.open=!1}))}#r(){this.#e&&(this.#e.addEventListener("dismiss",()=>this.hide()),this.#e.addEventListener("select",t=>{this.dispatchEvent(new CustomEvent("command-select",{bubbles:!0,detail:t.detail})),this.hide()}))}#n(){let t=e=>{let i=e.metaKey,r=e.ctrlKey;return e.key!=="k"?!1:this.shortcut==="cmd+k"?i:this.shortcut==="ctrl+k"?r:i||r};this.#t=e=>{t(e)&&(e.preventDefault(),this.toggle())},document.addEventListener("keydown",this.#t)}};y("admin-command",sh);C();P();var rh=class extends v{static template=()=>null;connected(){this.addEventListener("click",this.#t),this.addEventListener("embed:open",this.#e),this.addEventListener("keydown",this.#i)}#t=t=>{let e=t.target.closest?.("[opens]");if(e&&this.contains(e)){this.toggle(e.getAttribute("opens"));return}let i=t.target.closest?.("[close]");i&&this.contains(i)&&this.close()};#e=t=>this.toggle(t.detail?.panel);#i=t=>{t.key==="Escape"&&this.panel&&(t.stopPropagation(),this.close())};get panel(){return this.getAttribute("panel")||""}toggle(t){return this.panel===t?this.close():this.open(t)}open(t){if(!t)return;let e=this.querySelector(`:scope > [panel="${CSS.escape(t)}"]`);if(e){for(let i of this.querySelectorAll(":scope > [panel][active]"))i!==e&&i.removeAttribute("active");e.setAttribute("active",""),this.setAttribute("panel",t),requestAnimationFrame(()=>e.querySelector("[autofocus], [close], button-ui, [tabindex]")?.focus?.({preventScroll:!0})),this.#s(t)}}close(){this.panel&&(this.querySelector(":scope > [panel][active]")?.removeAttribute("active"),this.removeAttribute("panel"),this.#s(""))}#s(t){this.dispatchEvent(new CustomEvent("embed:change",{detail:{panel:t},bubbles:!0}))}};y("embed-shell",rh);C();P();function TO(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var AD=0,nh=class extends v{static properties={streaming:{type:Boolean,default:!1,reflect:!0},provider:{type:String,default:"",reflect:!0},model:{type:String,default:"",reflect:!0},system:{type:String,default:"",reflect:!0},proxyUrl:{type:String,default:"",attribute:"proxy-url",reflect:!0},thinking:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=[];#e=null;#i=null;#s=null;#r=null;#n=null;#a="";get messages(){return[...this.#t]}get conversation(){return this.#t.filter(t=>t.role==="user"||t.role==="assistant").map(t=>t.html?{role:t.role,content:t.content,html:!0}:{role:t.role,content:t.content})}set conversation(t){this.clear();for(let e of t)this.appendMessage({role:e.role,content:e.content,render:!e.html,html:!!e.html})}set apiKey(t){this.#a=t}connected(){this.#i=this.querySelector("chat-thread"),this.#s=this.querySelector("chat-composer"),this.#r=this.querySelector("chat-empty"),this.#n=this.querySelector("chat-status"),this.#s?.addEventListener("composer-submit",this.#l)}disconnected(){this.#s?.removeEventListener("composer-submit",this.#l),this.abort()}#o(t,e){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:e}))}#l=t=>{if(this.streaming)return;let{text:e,model:i}=t.detail||{};e&&(this.#s.clear(),this.#o("submit",{text:e,model:i}),(this.proxyUrl||this.#a)&&this.send(e,i?{model:i}:{}))};appendMessage({role:t,content:e="",render:i=!1,html:r=!1}){let n=`msg_${++AD}`;this.#t.push({id:n,role:t,content:e,html:r});let o=document.createElement("div");if(o.setAttribute("data-role",t),o.setAttribute("data-id",n),t==="user")o.innerHTML=`<div data-bubble>${TO(e)}</div>`;else if(t==="assistant"){let a=i||r,l=r?e:i&&e?di(e):TO(e);o.innerHTML=`
393
393
  <span data-avatar>AI</span>
394
394
  <div data-bubble><div data-content>${l}</div>${a?"":"<span data-cursor></span>"}</div>
395
- `}else t==="error"&&(o.innerHTML=`<icon-ui name="warning"></icon-ui><span>${TO(e)}</span>`);return this.#i?.appendChild(o),this.#h(),this.#o("message",{id:n,role:t,content:e}),o}appendChunk(t){let e=this.#t[this.#t.length-1];if(!e||e.role!=="assistant")return;e.content+=t;let i=this.#i?.querySelector("[data-role]:last-child [data-content]");i&&i.insertAdjacentText("beforeend",t),this.#h()}deleteMessage(t){let e=this.#t.findIndex(i=>i.id===t);e!==-1&&(this.#t.splice(e,1),this.#i?.querySelector(`[data-id="${t}"]`)?.remove())}clear(){if(this.#t.length=0,this.#i){let t=this.#r;this.#i.innerHTML="",t&&this.#i.appendChild(t)}this.#o("clear")}startStreaming(){this.streaming=!0,this.#s&&(this.#s.disabled=!0),this.#n&&(this.#n.textContent="Typing..."),this.#i?.tagName?.toLowerCase()==="chat-thread"&&(this.#i.streaming=!0)}stopStreaming(){this.streaming=!1,this.#s&&(this.#s.disabled=!1),this.#n&&(this.#n.textContent=""),this.#i?.tagName?.toLowerCase()==="chat-thread"&&(this.#i.streaming=!1),this.#i?.querySelector("[data-role]:last-child [data-cursor]")?.remove();let t=this.#t[this.#t.length-1];if(t?.role==="assistant"&&t.content&&!t.html){let e=this.#i?.querySelector("[data-role]:last-child [data-content]");e&&(e.innerHTML=di(t.content),this.#c(e))}this.#s?.focus()}abort(){this.#e&&(this.#e.abort(),this.#e=null,this.#o("abort")),this.streaming&&this.stopStreaming()}async send(t,e={}){let i=e.model||this.model||this.#s?.model;if(!i)throw new Error("No model specified");this.appendMessage({role:"user",content:t}),this.appendMessage({role:"assistant",content:""}),this.startStreaming(),this.#e=new AbortController;try{let r={provider:this.provider||void 0,apiKey:this.#a||void 0,model:i,system:this.system||void 0,proxyUrl:this.proxyUrl||void 0,thinking:this.thinking||void 0,messages:this.conversation.slice(0,-1),signal:this.#e.signal,...e},n;for(let o of["../../../llm/index.js","../../llm/index.js"])try{({streamChat:n}=await import(new URL(o,import.meta.url).href));break}catch{}if(!n){this.appendMessage({role:"error",content:"@adia-ai/llm is not available \u2014 in a fresh checkout run the packages/llm build (see gh#527/gh#541)."}),this.#o("error",{error:new Error("llm build artifact missing")});return}for await(let o of n(r))o.type==="text"?(this.appendChunk(o.text),this.#o("chunk",{text:o.text,snapshot:o.snapshot})):o.type==="thinking"?this.#o("thinking",{text:o.text}):o.type==="done"?this.#o("done",{text:o.text,usage:o.usage,stopReason:o.stopReason}):o.type==="error"&&(this.appendMessage({role:"error",content:o.error.message}),this.#o("error",{error:o.error}))}catch(r){r.name!=="AbortError"&&(this.appendMessage({role:"error",content:r.message}),this.#o("error",{error:r}))}this.#e=null,this.stopStreaming()}export(){return{messages:this.#t.map(t=>({role:t.role,content:t.content})),model:this.model,system:this.system}}import(t){t.model&&(this.model=t.model),t.system&&(this.system=t.system),t.messages&&(this.conversation=t.messages)}#h(){let t=this.#i;t&&requestAnimationFrame(()=>{t.scrollTop=t.scrollHeight})}#c(t){for(let e of t.querySelectorAll("pre")){let i=e.querySelector("code");if(!i)continue;let r=i.getAttribute("data-lang")||"",n=document.createElement("code-ui");r&&n.setAttribute("language",r),n.textContent=i.textContent,e.replaceWith(n)}}};y("chat-shell",nh);C();P();var ED=40,oh=class extends v{static properties={streaming:{type:Boolean,default:!1,reflect:!0},empty:{type:Boolean,default:!0,reflect:!0}};static template=()=>null;#t=null;#e=!0;#i=null;connected(){this.#s(),this.#r(),this.#n()}disconnected(){this.#t?.disconnect(),this.#t=null,this.#i&&(this.removeEventListener("scroll",this.#i),this.#i=null)}scrollToBottom(){this.scrollTo({top:this.scrollHeight,behavior:"smooth"})}scrollToBottomInstant(){this.scrollTop=this.scrollHeight}#s(){let t=Array.from(this.children).filter(e=>e.tagName.toLowerCase()!=="chat-empty");this.empty=t.length===0}#r(){typeof MutationObserver>"u"||(this.#t=new MutationObserver(()=>{this.#s(),this.#e&&this.scrollToBottomInstant()}),this.#t.observe(this,{childList:!0}))}#n(){this.#i=()=>{let t=this.scrollHeight-(this.scrollTop+this.clientHeight);this.#e=t<=ED},this.addEventListener("scroll",this.#i,{passive:!0})}};y("chat-thread",oh);C();P();var ah=class extends v{static properties={disabled:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;connected(){this.#t=this.querySelector("chat-input-ui")||this.querySelector("input-ui")||this.querySelector("textarea-ui"),this.#e=t=>{this.dispatchEvent(new CustomEvent("composer-submit",{bubbles:!0,detail:t.detail||{}}))},this.#t?.addEventListener("submit",this.#e),this.#i()}disconnected(){this.#t&&this.#e&&this.#t.removeEventListener("submit",this.#e),this.#t=null,this.#e=null}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),t==="disabled"&&this.#i()}focus(){this.#t?.focus?.()}clear(){this.#t?.clear?.()}get input(){return this.#t}#i(){this.#t&&(this.disabled?this.#t.setAttribute("disabled",""):this.#t.removeAttribute("disabled"))}};y("chat-composer",ah);C();P();var lh=96,$E=160,hh=class extends v{static properties={collapsed:{type:Boolean,default:!1,reflect:!0},resizing:{type:Boolean,default:!1,reflect:!0},resizable:{type:Boolean,default:!1,reflect:!0},collapsible:{type:Boolean,default:!1,reflect:!0},name:{type:String,default:"",reflect:!0},minWidth:{type:String,default:"",reflect:!0,attribute:"min-width"}};static template=()=>null;#t="";#e=[];#i=null;connected(){this.#n(),this.resizable&&this.#o(),this.#l(),this.#a()}disconnected(){for(let t of this.#e)t();this.#e=[],this.#i?.disconnect(),this.#i=null}toggle(){return this.collapsed?this.expand():this.collapse(),this.collapsed}collapse(){if(this.collapsed)return;let t=this.style.width||getComputedStyle(this).width;parseFloat(t)>lh&&(this.#t=t);let e=this.minWidth||getComputedStyle(this).minWidth;this.style.width=e,this.#r(e),this.collapsed=!0,this.#h(!1)}expand(){if(!this.collapsed)return;let t=this.#t||"";this.style.width=t,this.#r(t),this.collapsed=!1,this.#h(!0)}#s(){return`adia-chat-sidebar-${this.name||this.getAttribute("slot")||"default"}`}#r(t){try{localStorage.setItem(this.#s(),t)}catch{}}#n(){try{let t=localStorage.getItem(this.#s());if(!t)return;this.style.width=t;let e=parseFloat(t);!isNaN(e)&&e>lh&&(this.#t=t)}catch{}}#a(){let t=this.getBoundingClientRect().width;this.collapsed=t<=lh}#o(){let t=this.querySelector(":scope > [data-resize]");if(!t)return;let e=this.getAttribute("slot"),i=e==="leading",r=n=>{n.preventDefault(),t.setPointerCapture(n.pointerId);let o=n.clientX,a=this.getBoundingClientRect().width;this.resizing=!0,document.documentElement.style.cursor="col-resize";let l=c=>{let u=c.clientX-o,d=parseInt(getComputedStyle(this).getPropertyValue("max-width"))||480,f=Math.max(48,Math.min(d,a+(i?u:-u)));this.style.width=`${f}px`},h=()=>{this.resizing=!1,document.documentElement.style.cursor="",t.removeEventListener("pointermove",l),t.removeEventListener("pointerup",h);let c=this.getBoundingClientRect().width;c<=lh?this.style.width=this.minWidth||getComputedStyle(this).minWidth:c<$E&&(this.style.width=`${$E}px`),this.#r(this.style.width),this.#a(),this.dispatchEvent(new CustomEvent("sidebar-resize",{bubbles:!0,detail:{name:this.name||e,width:this.getBoundingClientRect().width}}))};t.addEventListener("pointermove",l),t.addEventListener("pointerup",h)};t.addEventListener("pointerdown",r),this.#e.push(()=>t.removeEventListener("pointerdown",r))}#l(){typeof ResizeObserver>"u"||(this.#i=new ResizeObserver(t=>{for(let e of t){let i=e.contentBoxSize[0].inlineSize<=lh;for(let r of this.querySelectorAll("select-ui"))r.setAttribute("placement",i?"right":"bottom-start")}}),this.#i.observe(this))}#h(t){this.dispatchEvent(new CustomEvent("sidebar-toggle",{bubbles:!0,detail:{name:this.name||this.getAttribute("slot")||"default",expanded:t}}))}};y("chat-sidebar",hh);var CD="Closed.",$D="v1.0";function MO({renderer:s,doc:t=document}){if(!s)throw new Error("createSurfaceRegistry: opts.renderer is required");let e=new Map;function i(h,c){let u=e.get(h);if(u)return u;if(!c)throw new Error(`createSurfaceRegistry.route: no bubble element for fresh surfaceId "${h}"`);let d=t.createElement("div");d.setAttribute("data-surface-root",h),c.appendChild(d);let f=s.attachSurface(h,d),p={surfaceId:h,root:d,handle:f,bubbleEl:c,status:"open"};return e.set(h,p),p}function r(h){let c=t.createElement("div");c.setAttribute("data-surface-closed",h.surfaceId),c.textContent=CD,h.bubbleEl.appendChild(c)}function n(h){let c=e.get(h);if(c)return c.status==="closed"||(s.handleFrame(JSON.stringify({version:$D,deleteSurface:{surfaceId:h}})),c.status="closed",r(c)),c}function o(h,c,u){let d=null;try{d=JSON.parse(c)}catch{}if(d&&Object.hasOwn(d,"deleteSurface")){s.handleFrame(c);let f=e.get(h);return f&&f.status!=="closed"&&(f.status="closed",r(f)),f}return s.handleFrame(c),s.surfaces.has(h)?i(h,u):e.get(h)}function a(h){return e.get(h)}function l(){for(let h of e.values())h.handle.detach();e.clear()}return{route:i,close:n,feed:o,get:a,disposeAll:l,hosts:e}}var LO={sent:"Sending\u2026",started:"Thinking\u2026",reasoning:"Reasoning\u2026",content:"Writing\u2026",validating:"Validating\u2026",retry:"Retrying\u2026",tool:"Using a tool\u2026",done:"Done"};async function RO(s,t,e){let{events:i,statusEl:r=null,isProgressStage:n=a=>Object.hasOwn(LO,a)}=e??{};if(!i)throw new Error("wireAgentEvents: opts.events (AsyncIterable<AgentEvent>) is required");let o=()=>s.querySelector?.("chat-thread")?.querySelector('[data-role="assistant"]:last-child [data-bubble]')??null;for await(let a of i)switch(a.type){case"text":s.appendChunk?.(a.text);break;case"progress":{if(!n(a.stage))break;r&&(r.textContent=LO[a.stage]??"");break}case"surface":{let l=o();t.feed(a.surfaceId,a.line,l);break}case"tool_use":s.appendMessage?.({role:"assistant",content:`\u{1F527} \`${a.name}(${JSON.stringify(a.input)})\``,render:!0}),s.appendMessage?.({role:"assistant",content:""});break;case"tool_result":s.appendMessage?.({role:a.isError?"error":"assistant",content:`\u21A9 \`${a.name}\` \u2192 ${String(a.output).slice(0,300)}`,render:!0}),s.appendMessage?.({role:"assistant",content:""});break;case"error":s.appendMessage?.({role:"error",content:a.error?.message??String(a.error)}),s.stopStreaming?.();break;case"done":s.stopStreaming?.();break;default:break}s.streaming&&s.stopStreaming?.()}C();P();var ch=class extends v{static properties={focusMode:{type:Boolean,default:!1,reflect:!0,attribute:"focus-mode"}};static template=()=>null;#t=null;#e=null;#i=null;connected(){this.#t=this.querySelector("editor-toolbar"),this.#e=this.querySelector("editor-canvas"),this.#s(),this.#i=t=>{let e=t?.detail?.name;e&&(e==="toggle-focus"||e==="full-screen")&&this.toggleFocusMode()},this.addEventListener("toolbar-action",this.#i)}disconnected(){this.#i&&this.removeEventListener("toolbar-action",this.#i),this.#i=null}toggleFocusMode(){this.focusMode=!this.focusMode,this.#t?.tagName?.toLowerCase()==="editor-toolbar"&&(this.#t.fullScreen=this.focusMode),this.#e?.tagName?.toLowerCase()==="editor-canvas"&&(this.focusMode?this.#e.focus?.():this.#e.blur?.()),this.dispatchEvent(new CustomEvent("editor-mode-change",{bubbles:!0,detail:{focusMode:this.focusMode}}))}#s(){for(let t of this.querySelectorAll("select-ui[data-options]"))try{let e=JSON.parse(t.getAttribute("data-options"));t.options=e}catch{}}};y("editor-shell",ch);C();P();var uh=class extends v{static properties={fullScreen:{type:Boolean,default:!1,reflect:!0,attribute:"full-screen"}};static template=()=>null;#t=null;connected(){this.#t=t=>{let e=t.target.closest("[data-toolbar-action]");if(!e||!this.contains(e))return;let i=e.getAttribute("data-toolbar-action");this.dispatchEvent(new CustomEvent("toolbar-action",{bubbles:!0,detail:{name:i}}))},this.addEventListener("click",this.#t)}disconnected(){this.#t&&this.removeEventListener("click",this.#t),this.#t=null}};y("editor-toolbar",uh);C();P();var dh=class extends v{static properties={empty:{type:Boolean,default:!0,reflect:!0},focused:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=1;#e=null;connected(){this.#i(),this.#s()}disconnected(){this.#e?.disconnect(),this.#e=null}get zoom(){return this.#t}set zoom(t){let e=parseFloat(t);!isFinite(e)||e<=0||(this.#t=e,this.style.setProperty("--editor-canvas-zoom",String(e)))}resetView(){this.zoom=1}focus(){super.focus?.(),this.focused=!0}blur(){super.blur?.(),this.focused=!1}#i(){let t=Array.from(this.children).filter(e=>e.tagName.toLowerCase()!=="editor-canvas-empty");this.empty=t.length===0}#s(){typeof MutationObserver>"u"||(this.#e=new MutationObserver(()=>{this.#i()}),this.#e.observe(this,{childList:!0}))}};y("editor-canvas",dh);C();P();var fh=96,PD="adia-editor-sidebar-",ph=class extends v{static properties={collapsed:{type:Boolean,default:!1,reflect:!0},resizing:{type:Boolean,default:!1,reflect:!0},collapsible:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=null;#r=null;#n=null;#a=null;#o=!1;#l=null;connected(){if(this.#t=this.querySelector("pane-ui"),!this.#t)return;let t=this.getAttribute("slot")||"leading",e=this.getAttribute("persist")||this.getAttribute("name")||t;this.#i=`${PD}${e}`,this.#m(),typeof ResizeObserver<"u"&&(this.#e=new ResizeObserver(i=>{if(getComputedStyle(this).display==="none")return;this.#d();let r=this.#t.offsetWidth;r>0&&(this.style.width=`${r}px`)}),this.#e.observe(this.#t)),this.#s=i=>{i.target?.closest?.('[slot="resize"], [data-resize], [class*="handle"]')&&(this.resizing=!0)},this.#t.addEventListener("pointerdown",this.#s),this.#r=()=>{this.resizing&&(this.resizing=!1),this.#f()},document.addEventListener("pointerup",this.#r),this.#n=i=>{i.target!==this.#t||i.propertyName!=="width"||(this.#c(),this.#d())},this.#t.addEventListener("transitionend",this.#n)}disconnected(){this.#a!==null&&(cancelAnimationFrame(this.#a),this.#a=null),this.#l!==null&&(clearTimeout(this.#l),this.#l=null),this.#e?.disconnect(),this.#e=null,this.#s&&this.#t&&(this.#t.removeEventListener("pointerdown",this.#s),this.#s=null),this.#r&&(document.removeEventListener("pointerup",this.#r),this.#r=null),this.#n&&this.#t&&(this.#t.removeEventListener("transitionend",this.#n),this.#n=null)}toggle(){return this.collapsed?this.expand():this.collapse(),this.collapsed}collapse(){this.#t&&(this.collapsed||this.#f(),this.#t.style.width=`${fh}px`,this.collapsed=!0,this.#u())}expand(){if(!this.#t)return;let t=this.#p(),e=t&&t>fh?t:240;this.#t.style.width=`${e}px`,this.collapsed=!1,this.#f(),this.#u(),this.#h()}#h(){this.#l!==null&&(clearTimeout(this.#l),this.#l=null);let t=getComputedStyle(this.#t).transitionDuration.split(",")[0].trim(),e=(parseFloat(t)||0)*(t.endsWith("ms")?1:1e3);e<=0||(this.#o=!0,this.#l=setTimeout(()=>{this.#l=null,this.#c(),this.#d()},e+50))}#c(){this.#o=!1,this.#l!==null&&(clearTimeout(this.#l),this.#l=null)}#d(){if(!this.#t||getComputedStyle(this).display==="none")return;let t=this.#t.getBoundingClientRect();if(t.width!==0){if(t.width>fh){this.#a!==null&&(cancelAnimationFrame(this.#a),this.#a=null),this.collapsed=!1;return}this.#o||this.#a===null&&(this.#a=requestAnimationFrame(()=>{if(this.#a=null,!this.#t||getComputedStyle(this).display==="none"||this.#o)return;let e=this.#t.getBoundingClientRect();e.width>0&&e.width<=fh&&(this.collapsed=!0)}))}}#u(){let t=this.getAttribute("slot")||"leading",e=this.getAttribute("persist")||this.getAttribute("name")||t;this.dispatchEvent(new CustomEvent("sidebar-toggle",{bubbles:!0,detail:{name:e,expanded:!this.collapsed}}))}#f(){if(!(!this.#t||!this.#i))try{let t=this.#t.style.width||"";t&&localStorage.setItem(this.#i,t)}catch{}}#p(){if(!this.#i)return null;try{let t=localStorage.getItem(this.#i);if(!t)return null;let e=parseFloat(t);return isFinite(e)?e:null}catch{return null}}#m(){if(!this.#t)return;let t=this.#p();t&&t>0&&(this.#t.style.width=`${t}px`,this.collapsed=t<=fh)}};y("editor-sidebar",ph);function QD(){let s=document.activeElement;if(!s)return!1;let t=s.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||s.isContentEditable||t==="INPUT-UI"||t==="TEXTAREA-UI"||t==="OTP-INPUT-UI"||t==="SEARCH-UI")}P();var mh=class extends v{static properties={centered:{type:Boolean,default:!1,reflect:!0},"full-bleed":{type:Boolean,default:!1,reflect:!0}};static template=()=>null};customElements.get("simple-shell")||customElements.define("simple-shell",mh);C();P();var Td=class extends v{static properties={mode:{type:String,default:"chat",reflect:!0},inspector:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=!1;#e=null;#i=null;#s=null;connected(){}render(){this.#t||(this.#t=!0,this.#e=document.createElement("chat-thread-ui"),this.#i=document.createElement("canvas-ui"),this.appendChild(this.#e),this.appendChild(this.#i),this.inspector&&(this.#s=document.createElement("inspector-ui"),this.appendChild(this.#s)))}appendMessage(t){this.#e?.appendMessage(t)}appendCoT(t){this.#e?.appendCoT(t)}pushArtifact(t){this.mode==="chat"&&(this.mode="split"),this.#i?.processAll(t)}setSuggestions(t){this.#e?.setSuggestions(t)}appendResultMessage(t){this.#e?.appendResultMessage(t)}showSavePatternBar(t){this.#e?.showSavePatternBar(t)}showFeedbackWidget(t){this.#e?.showFeedbackWidget(t)}showTyping(){this.#e?.showTyping()}hideTyping(){this.#e?.hideTyping()}appendError(t){this.#e?.appendError(t)}startPipelineStatus(){return this.#e?.startPipelineStatus()}updatePipelineStatus(t){this.#e?.updatePipelineStatus(t)}completePipelineStatus(){this.#e?.completePipelineStatus()}reset(){this.#e?.clear(),this.#i?.reset(),this.mode="chat"}get thread(){return this.#e}get canvas(){return this.#i}get inspect(){return this.#s}};y("gen-root",Td);$O();C();P();var TD=["atlas","signal","terrarium","ledger","arcade","meridian","solstice","glacier","ember","botanica","vector","velour"],LD={compact:{density:.85,radius:.75},default:{density:1,radius:1},spacious:{density:1.15,radius:1.25}},IO=["","ui-sm","ui-md","ui-lg","content-sm","content-md","content-lg"],PE=s=>s.length?s[0].toUpperCase()+s.slice(1):s,gh=class extends v{static properties={themes:{type:String,default:TD.join(" "),reflect:!0},parametric:{type:Boolean,default:!1,reflect:!0},presets:{type:Boolean,default:!1,reflect:!0},schemeToggle:{type:Boolean,default:!1,reflect:!0,attribute:"scheme-toggle"},persist:{type:Boolean,default:!1,reflect:!0},storagePrefix:{type:String,default:"adia-theme-",reflect:!0,attribute:"storage-prefix"},target:{type:String,default:":root",reflect:!0},scheme:{type:String,default:"auto",reflect:!0},activeTheme:{type:String,default:"",reflect:!0,attribute:"active-theme"},activeScheme:{type:String,default:"",reflect:!0,attribute:"active-scheme"},activeDensity:{type:String,default:"",reflect:!0,attribute:"active-density"},activeRadius:{type:String,default:"",reflect:!0,attribute:"active-radius"},register:{type:Boolean,default:!1,reflect:!0},activeScale:{type:String,default:"",reflect:!0,attribute:"active-scale"}};static template=()=>null;#t=null;#e=null;#i=[];#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=!1;connected(){this.#h||(this.#c(),this.#h=!0,this.#w(),this.#g(),this.#b())}disconnected(){for(let t of this.#i)t();this.#i=[],this.#v(),this.parametric&&this.#S().removeAttribute("data-parametric-scope")}apply(t={}){this.#p(t,"programmatic")}reset(){let t=this.#S();if(t.removeAttribute("theme"),t.style.removeProperty("--a-density"),t.style.removeProperty("--a-radius-k"),t.style.removeProperty("color-scheme"),t.removeAttribute("scale"),this.persist)for(let e of["theme","scheme","density","radius","scale"])try{localStorage.removeItem(`${this.storagePrefix}${e}`)}catch{}this.activeTheme="",this.activeDensity="",this.activeRadius="",this.activeScale="",this.scheme="auto",this.activeScheme=this.#y(),this.#n&&(this.#n.value="auto"),this.#s&&(this.#s.value=1),this.#r&&(this.#r.value=1),this.#a&&(this.#a.value=""),this.#o&&(this.#o.value=""),this.#m("reset")}#c(){let t=document.createDocumentFragment();if(this.schemeToggle){let o=document.createElement("div");o.setAttribute("part","scheme");let a=document.createElement("segmented-ui");a.id=`${this.#k}-scheme`;let l=document.createElement("segment-ui");l.setAttribute("value","auto"),l.setAttribute("text","System");let h=document.createElement("segment-ui");h.setAttribute("value","light"),h.setAttribute("text","Light");let c=document.createElement("segment-ui");c.setAttribute("value","dark"),c.setAttribute("text","Dark"),a.append(l,h,c),o.appendChild(a),t.appendChild(o),this.#n=a}let e=(this.themes||"").trim().split(/\s+/).filter(Boolean);if(e.length){let o=document.createElement("div");o.setAttribute("part","theme-row");let a=document.createElement("text-ui");a.setAttribute("variant","label"),a.textContent="Theme",o.appendChild(a);let l=document.createElement("select-ui");l.setAttribute("part","themes"),l.setAttribute("size","sm"),l.id=`${this.#k}-theme`;let h=(c,u)=>{let d=document.createElement("option");return d.value=c,d.textContent=u,d};l.append(h("","Default"),...e.map(c=>h(c,PE(c)))),l.setAttribute("value",""),o.appendChild(l),t.appendChild(o),this.#o=l}if(this.parametric){t.appendChild(document.createElement("divider-ui"));let o=document.createElement("text-ui");o.setAttribute("variant","label"),o.textContent="Parametric",t.appendChild(o);let a=document.createElement("slider-ui");a.setAttribute("part","density"),a.setAttribute("label","Density"),a.setAttribute("value","1"),a.setAttribute("min","0.5"),a.setAttribute("max","1.5"),a.setAttribute("step","0.05"),a.setAttribute("suffix","\xD7"),t.appendChild(a),this.#s=a;let l=document.createElement("slider-ui");l.setAttribute("part","radius"),l.setAttribute("label","Radius"),l.setAttribute("value","1"),l.setAttribute("min","0"),l.setAttribute("max","2"),l.setAttribute("step","0.1"),l.setAttribute("suffix","\xD7"),t.appendChild(l),this.#r=l}if(this.presets||this.register){if(t.appendChild(document.createElement("divider-ui")),this.presets){let o=document.createElement("div");o.setAttribute("part","preset-row");let a=document.createElement("text-ui");a.setAttribute("variant","label"),a.textContent="Preset",o.appendChild(a);let l=document.createElement("div");l.setAttribute("part","presets");for(let h of["compact","default","spacious"]){let c=document.createElement("button-ui");c.setAttribute("data-preset",h),c.setAttribute("text",PE(h)),c.setAttribute("variant","outline"),c.setAttribute("size","sm"),l.appendChild(c)}o.appendChild(l),t.appendChild(o)}if(this.register){let o=document.createElement("div");o.setAttribute("part","preset-row");let a=document.createElement("text-ui");a.setAttribute("variant","label"),a.textContent="Scale",o.appendChild(a);let l=document.createElement("select-ui");l.setAttribute("part","scale"),l.setAttribute("size","sm"),l.id=`${this.#k}-scale`,l.innerHTML=IO.map(h=>`<option value="${h}">${h||"Default"}</option>`).join(""),l.setAttribute("value",""),o.appendChild(l),t.appendChild(o),this.#a=l}}t.appendChild(document.createElement("divider-ui"));let i=document.createElement("div");i.setAttribute("part","reset-row");let r=document.createElement("button-ui");r.setAttribute("part","reset"),r.setAttribute("text","Reset"),r.setAttribute("variant","ghost"),r.setAttribute("size","sm"),i.appendChild(r),t.appendChild(i),this.#l=r;let n=document.createElement("theme-provider");n.setAttribute("scale","ui-md"),n.appendChild(t),this.appendChild(n),this.#d()}#d(){if(this.#o){let t=e=>{let i=e.detail?.value??this.#o.value;this.#u(i)};this.#o.addEventListener("change",t),this.#i.push(()=>this.#o.removeEventListener("change",t))}if(this.#l){let t=()=>this.reset();this.#l.addEventListener("press",t),this.#l.addEventListener("click",t),this.#i.push(()=>{this.#l.removeEventListener("press",t),this.#l.removeEventListener("click",t)})}if(this.#s){let t=()=>this.#p({density:parseFloat(this.#s.value)},"slider");this.#s.addEventListener("input",t),this.#i.push(()=>this.#s.removeEventListener("input",t))}if(this.#r){let t=()=>this.#p({radius:parseFloat(this.#r.value)},"slider");this.#r.addEventListener("input",t),this.#i.push(()=>this.#r.removeEventListener("input",t))}for(let t of this.querySelectorAll('[part="presets"] button-ui')){let e=t.getAttribute("data-preset"),i=()=>this.#f(e);t.addEventListener("press",i),t.addEventListener("click",i),this.#i.push(()=>{t.removeEventListener("press",i),t.removeEventListener("click",i)})}if(this.#n){let t=e=>{let i=e.detail?.value??this.#n.value;(i==="light"||i==="dark"||i==="auto")&&this.#p({scheme:i},"scheme")};this.#n.addEventListener("change",t),this.#i.push(()=>this.#n.removeEventListener("change",t))}if(this.#a){let t=e=>{let i=e.detail?.value??this.#a.value;this.#p({scale:i},"scale")};this.#a.addEventListener("change",t),this.#i.push(()=>this.#a.removeEventListener("change",t))}}#u(t){let e=this.#S();if(e.style.removeProperty("--a-density"),e.style.removeProperty("--a-radius-k"),this.persist)try{localStorage.removeItem(`${this.storagePrefix}density`),localStorage.removeItem(`${this.storagePrefix}radius`)}catch{}this.#p({theme:t},"theme"),this.#s&&(this.#s.value=1),this.#r&&(this.#r.value=1),this.activeDensity="",this.activeRadius=""}#f(t){let e=LD[t];e&&(this.#p({density:e.density,radius:e.radius},"preset"),this.#s&&(this.#s.value=e.density),this.#r&&(this.#r.value=e.radius))}#p(t,e){let i=this.#S();if(t.theme!==void 0){if(t.theme===""||t.theme==="default"?(i.removeAttribute("theme"),this.activeTheme=""):(i.setAttribute("theme",t.theme),this.activeTheme=t.theme),this.persist)try{this.activeTheme?localStorage.setItem(`${this.storagePrefix}theme`,this.activeTheme):localStorage.removeItem(`${this.storagePrefix}theme`)}catch{}this.#o&&(this.#o.value=this.activeTheme)}if(t.density!==void 0&&(i.style.setProperty("--a-density",t.density),this.activeDensity=String(t.density),this.persist))try{localStorage.setItem(`${this.storagePrefix}density`,String(t.density))}catch{}if(t.radius!==void 0&&(i.style.setProperty("--a-radius-k",t.radius),this.activeRadius=String(t.radius),this.persist))try{localStorage.setItem(`${this.storagePrefix}radius`,String(t.radius))}catch{}if(t.scheme!==void 0){let r=t.scheme;if(r==="auto"){if(i.style.removeProperty("color-scheme"),this.scheme="auto",this.activeScheme=this.#y(),this.persist)try{localStorage.removeItem(`${this.storagePrefix}scheme`)}catch{}this.#x()}else if(r==="light"||r==="dark"){if(i.style.setProperty("color-scheme",r),this.scheme=r,this.activeScheme=r,this.persist)try{localStorage.setItem(`${this.storagePrefix}scheme`,r)}catch{}this.#v()}this.#n&&(this.#n.value=this.scheme)}if(t.scale!==void 0){let r=t.scale;if(r&&IO.includes(r)?(i.setAttribute("scale",r),this.activeScale=r):(i.removeAttribute("scale"),this.activeScale=""),this.persist)try{this.activeScale?localStorage.setItem(`${this.storagePrefix}scale`,this.activeScale):localStorage.removeItem(`${this.storagePrefix}scale`)}catch{}this.#a&&(this.#a.value=this.activeScale)}this.#m(e)}#m(t){this.dispatchEvent(new CustomEvent("theme-change",{bubbles:!0,detail:{theme:this.activeTheme,scheme:this.activeScheme,density:this.activeDensity?parseFloat(this.activeDensity):1,radius:this.activeRadius?parseFloat(this.activeRadius):1,scale:this.activeScale,source:t}}))}#g(){let t=this.#S(),e,i,r,n,o;if(this.persist)try{e=localStorage.getItem(`${this.storagePrefix}theme`)||"",i=localStorage.getItem(`${this.storagePrefix}scheme`)||"";let a=localStorage.getItem(`${this.storagePrefix}density`),l=localStorage.getItem(`${this.storagePrefix}radius`);r=a!=null?parseFloat(a):void 0,n=l!=null?parseFloat(l):void 0,o=localStorage.getItem(`${this.storagePrefix}scale`)||""}catch{}if(e?(t.setAttribute("theme",e),this.activeTheme=e):this.activeTheme=t.getAttribute("theme")||"",this.#o&&(this.#o.value=this.activeTheme),i==="light"||i==="dark")t.style.setProperty("color-scheme",i),this.scheme=i,this.activeScheme=i,this.#n&&(this.#n.value=i);else{let a=this.scheme||"auto";a==="light"||a==="dark"?(t.style.setProperty("color-scheme",a),this.activeScheme=a):(this.scheme="auto",this.activeScheme=this.#y()),this.#n&&(this.#n.value=this.scheme)}if(r!=null&&!Number.isNaN(r))t.style.setProperty("--a-density",r),this.activeDensity=String(r),this.#s&&(this.#s.value=r);else if(this.#s){let a=this.#O(t,"--a-density");this.#s.value=a,this.activeDensity=String(a)}if(n!=null&&!Number.isNaN(n))t.style.setProperty("--a-radius-k",n),this.activeRadius=String(n),this.#r&&(this.#r.value=n);else if(this.#r){let a=this.#O(t,"--a-radius-k");this.#r.value=a,this.activeRadius=String(a)}if(this.#a){let a=IO.includes(o)?o:t.getAttribute("scale")||"";a&&t.setAttribute("scale",a),this.#a.value=a,this.activeScale=a}}#O(t,e){let i=getComputedStyle(t);return parseFloat(i.getPropertyValue(e))||1}#y(){try{if(typeof matchMedia=="function"&&matchMedia("(prefers-color-scheme: dark)").matches)return"dark"}catch{}return"light"}#b(){if(this.scheme==="auto"){if(this.persist)try{let t=localStorage.getItem(`${this.storagePrefix}scheme`);if(t==="light"||t==="dark")return}catch{}this.#x()}}#x(){if(!(this.#t||typeof matchMedia!="function"))try{this.#t=matchMedia("(prefers-color-scheme: dark)"),this.#e=()=>{let t=this.#t.matches?"dark":"light";this.activeScheme=t,this.#n&&(this.#n.value="auto"),this.#m("scheme")},this.#t.addEventListener("change",this.#e)}catch{}}#v(){if(this.#t&&this.#e)try{this.#t.removeEventListener("change",this.#e)}catch{}this.#t=null,this.#e=null}#S(){let t=this.target||":root";if(t===":root")return document.documentElement;try{return document.querySelector(t)??document.documentElement}catch{return document.documentElement}}#w(){let t=this.#S();t!==document.documentElement&&(this.parametric?t.setAttribute("data-parametric-scope",""):t.removeAttribute("data-parametric-scope"))}get#k(){return this.id||"theme-panel"}};y("theme-panel",gh);P();var QE=["change","input"],bh=class extends v{static properties={label:{type:String,default:"",reflect:!0},heading:{type:String,default:"",reflect:!0},placement:{type:String,default:"bottom-start",reflect:!0}};static template=()=>null;#t=!1;#e=null;#i=null;#s=()=>this.#l();#r=null;connected(){this.#t||(this.#n(),this.#t=!0);for(let t of QE)this.addEventListener(t,this.#s);this.#i&&!this.#r&&(this.#r=new MutationObserver(this.#s),this.#r.observe(this.#i,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["checked"]})),this.#l()}disconnected(){for(let t of QE)this.removeEventListener(t,this.#s);this.#r?.disconnect(),this.#r=null}updated(t){this.#t&&(t.has("label")&&this.#l(),t.has("heading")&&this.#a(),t.has("placement")&&this.querySelector(":scope > popover-ui")?.setAttribute("placement",this.placement))}get summary(){let t=this.#i?this.#i.querySelectorAll("check-ui"):[],e=[];for(let i of t)(i.hasAttribute("checked")||i.checked)&&e.push(i);return{selected:e.length,total:t.length,checked:e}}#n(){let t=document.createDocumentFragment();for(;this.firstChild;)t.appendChild(this.firstChild);let e=document.createElement("popover-ui");e.setAttribute("placement",this.placement);let i=document.createElement("button-ui");i.setAttribute("slot","trigger"),i.setAttribute("data-form-popover-trigger",""),i.setAttribute("icon-trailing","caret-down"),this.#e=i,e.appendChild(i);let r=document.createElement("div");r.setAttribute("slot","content"),r.setAttribute("data-form-popover-body",""),r.appendChild(t),this.#i=r,e.appendChild(r),this.appendChild(e),this.#a()}#a(){if(!this.#i)return;let t=this.#i.querySelector(":scope > [data-form-popover-heading]");if(!this.heading){t?.remove();return}t||(t=document.createElement("div"),t.setAttribute("data-form-popover-heading",""),this.#i.prepend(t)),t.textContent=this.heading}#o(t){return(t.getAttribute("label")||t.label||t.textContent||"").trim()}#l(){if(!this.#e)return;let{selected:t,total:e,checked:i}=this.summary,r=this.label;t===1&&i[0]?r=this.#o(i[0])||r:t>1&&(r=r?`${r} (${t})`:`${t}`),r||(r="Options"),this.#e.setAttribute("text",r),this.dispatchEvent(new CustomEvent("summary-change",{bubbles:!0,detail:{selected:t,total:e}}))}};customElements.get("form-popover-ui")||customElements.define("form-popover-ui",bh);P();var Oh=class extends v{static properties={items:{type:Array,default:[]},"storage-key":{type:String,default:"",reflect:!0},storage:{type:String,default:"local",reflect:!0},"dismiss-on-complete":{type:Boolean,default:!1,reflect:!0},collapsible:{type:Boolean,default:!0,reflect:!0},collapsed:{type:Boolean,default:!1,reflect:!0},value:{type:Object,default:{}},title:{type:String,default:"Get started",reflect:!0}};static template=t=>t._renderTemplate();#t=`obc-h-${Math.random().toString(36).slice(2,8)}`;#e=`obc-l-${Math.random().toString(36).slice(2,8)}`;#i=!1;#s=!1;#r=null;#n=null;attributeChangedCallback(t,e,i){if(t==="items"||t==="value"){if(i==null)this[t]=t==="items"?[]:{};else try{let r=JSON.parse(i);this[t]=r}catch{this[t]=t==="items"?[]:{}}return}super.attributeChangedCallback(t,e,i)}connected(){if(this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#t),this.hasAttribute("items")&&!Array.isArray(this.items))try{this.items=JSON.parse(this.getAttribute("items"))}catch{this.items=[]}if(this.hasAttribute("value")&&(typeof this.value!="object"||Array.isArray(this.value)))try{this.value=JSON.parse(this.getAttribute("value"))}catch{this.value={}}if(this.#i=this.value&&Object.keys(this.value).length>0,!this.#i){let t=this.#x();t&&(this.value=t)}this.#r=this.#o.bind(this),this.#n=this.#l.bind(this),this.addEventListener("change",this.#r),this.addEventListener("click",this.#n),this.#s=this.#p(),this.#m()}disconnected(){this.#r&&this.removeEventListener("change",this.#r),this.#n&&this.removeEventListener("click",this.#n),this.#r=null,this.#n=null,this.#v()}render(){this.#m(),this.#y(),this.#g()}_renderTemplate(){let t=Array.isArray(this.items)?this.items:[],{done:e,total:i,percent:r}=this.#f(),n=this.collapsed?"Expand":"Collapse",o=this.collapsed?"chevron-down":"chevron-up",a=!!this.collapsible,l=this.title||"Get started",h=i>0&&e===i;return Y`
395
+ `}else t==="error"&&(o.innerHTML=`<icon-ui name="warning"></icon-ui><span>${TO(e)}</span>`);return this.#i?.appendChild(o),this.#h(),this.#o("message",{id:n,role:t,content:e}),o}appendChunk(t){let e=this.#t[this.#t.length-1];if(!e||e.role!=="assistant")return;e.content+=t;let i=this.#i?.querySelector("[data-role]:last-child [data-content]");i&&i.insertAdjacentText("beforeend",t),this.#h()}deleteMessage(t){let e=this.#t.findIndex(i=>i.id===t);e!==-1&&(this.#t.splice(e,1),this.#i?.querySelector(`[data-id="${t}"]`)?.remove())}clear(){if(this.#t.length=0,this.#i){let t=this.#r;this.#i.innerHTML="",t&&this.#i.appendChild(t)}this.#o("clear")}startStreaming(){this.streaming=!0,this.#s&&(this.#s.disabled=!0),this.#n&&(this.#n.textContent="Typing..."),this.#i?.tagName?.toLowerCase()==="chat-thread"&&(this.#i.streaming=!0)}stopStreaming(){this.streaming=!1,this.#s&&(this.#s.disabled=!1),this.#n&&(this.#n.textContent=""),this.#i?.tagName?.toLowerCase()==="chat-thread"&&(this.#i.streaming=!1),this.#i?.querySelector("[data-role]:last-child [data-cursor]")?.remove();let t=this.#t[this.#t.length-1];if(t?.role==="assistant"&&t.content&&!t.html){let e=this.#i?.querySelector("[data-role]:last-child [data-content]");e&&(e.innerHTML=di(t.content),this.#c(e))}this.#s?.focus()}abort(){this.#e&&(this.#e.abort(),this.#e=null,this.#o("abort")),this.streaming&&this.stopStreaming()}async send(t,e={}){let i=e.model||this.model||this.#s?.model;if(!i)throw new Error("No model specified");this.appendMessage({role:"user",content:t}),this.appendMessage({role:"assistant",content:""}),this.startStreaming(),this.#e=new AbortController;try{let r={provider:this.provider||void 0,apiKey:this.#a||void 0,model:i,system:this.system||void 0,proxyUrl:this.proxyUrl||void 0,thinking:this.thinking||void 0,messages:this.conversation.slice(0,-1),signal:this.#e.signal,...e},n;for(let o of["../../../llm/index.js","../../llm/index.js"])try{({streamChat:n}=await import(new URL(o,import.meta.url).href));break}catch{}if(!n){this.appendMessage({role:"error",content:"@adia-ai/llm is not available \u2014 in a fresh checkout run the packages/llm build (see gh#527/gh#541)."}),this.#o("error",{error:new Error("llm build artifact missing")});return}for await(let o of n(r))o.type==="text"?(this.appendChunk(o.text),this.#o("chunk",{text:o.text,snapshot:o.snapshot})):o.type==="thinking"?this.#o("thinking",{text:o.text}):o.type==="done"?this.#o("done",{text:o.text,usage:o.usage,stopReason:o.stopReason}):o.type==="error"&&(this.appendMessage({role:"error",content:o.error.message}),this.#o("error",{error:o.error}))}catch(r){r.name!=="AbortError"&&(this.appendMessage({role:"error",content:r.message}),this.#o("error",{error:r}))}this.#e=null,this.stopStreaming()}export(){return{messages:this.#t.map(t=>({role:t.role,content:t.content})),model:this.model,system:this.system}}import(t){t.model&&(this.model=t.model),t.system&&(this.system=t.system),t.messages&&(this.conversation=t.messages)}#h(){let t=this.#i;t&&requestAnimationFrame(()=>{t.scrollTop=t.scrollHeight})}#c(t){for(let e of t.querySelectorAll("pre")){let i=e.querySelector("code");if(!i)continue;let r=i.getAttribute("data-lang")||"",n=document.createElement("code-ui");r&&n.setAttribute("language",r),n.textContent=i.textContent,e.replaceWith(n)}}};y("chat-shell",nh);C();P();var ED=40,oh=class extends v{static properties={streaming:{type:Boolean,default:!1,reflect:!0},empty:{type:Boolean,default:!0,reflect:!0}};static template=()=>null;#t=null;#e=!0;#i=null;connected(){this.#s(),this.#r(),this.#n()}disconnected(){this.#t?.disconnect(),this.#t=null,this.#i&&(this.removeEventListener("scroll",this.#i),this.#i=null)}scrollToBottom(){this.scrollTo({top:this.scrollHeight,behavior:"smooth"})}scrollToBottomInstant(){this.scrollTop=this.scrollHeight}#s(){let t=Array.from(this.children).filter(e=>e.tagName.toLowerCase()!=="chat-empty");this.empty=t.length===0}#r(){typeof MutationObserver>"u"||(this.#t=new MutationObserver(()=>{this.#s(),this.#e&&this.scrollToBottomInstant()}),this.#t.observe(this,{childList:!0}))}#n(){this.#i=()=>{let t=this.scrollHeight-(this.scrollTop+this.clientHeight);this.#e=t<=ED},this.addEventListener("scroll",this.#i,{passive:!0})}};y("chat-thread",oh);C();P();var ah=class extends v{static properties={disabled:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;connected(){this.#t=this.querySelector("chat-input-ui")||this.querySelector("input-ui")||this.querySelector("textarea-ui"),this.#e=t=>{this.dispatchEvent(new CustomEvent("composer-submit",{bubbles:!0,detail:t.detail||{}}))},this.#t?.addEventListener("submit",this.#e),this.#i()}disconnected(){this.#t&&this.#e&&this.#t.removeEventListener("submit",this.#e),this.#t=null,this.#e=null}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),t==="disabled"&&this.#i()}focus(){this.#t?.focus?.()}clear(){this.#t?.clear?.()}get input(){return this.#t}#i(){this.#t&&(this.disabled?this.#t.setAttribute("disabled",""):this.#t.removeAttribute("disabled"))}};y("chat-composer",ah);C();P();var lh=96,$E=160,hh=class extends v{static properties={collapsed:{type:Boolean,default:!1,reflect:!0},resizing:{type:Boolean,default:!1,reflect:!0},resizable:{type:Boolean,default:!1,reflect:!0},collapsible:{type:Boolean,default:!1,reflect:!0},name:{type:String,default:"",reflect:!0},minWidth:{type:String,default:"",reflect:!0,attribute:"min-width"}};static template=()=>null;#t="";#e=[];#i=null;connected(){this.#n(),this.resizable&&this.#o(),this.#l(),this.#a()}disconnected(){for(let t of this.#e)t();this.#e=[],this.#i?.disconnect(),this.#i=null}toggle(){return this.collapsed?this.expand():this.collapse(),this.collapsed}collapse(){if(this.collapsed)return;let t=this.style.width||getComputedStyle(this).width;parseFloat(t)>lh&&(this.#t=t);let e=this.minWidth||getComputedStyle(this).minWidth;this.style.width=e,this.#r(e),this.collapsed=!0,this.#h(!1)}expand(){if(!this.collapsed)return;let t=this.#t||"";this.style.width=t,this.#r(t),this.collapsed=!1,this.#h(!0)}#s(){return`adia-chat-sidebar-${this.name||this.getAttribute("slot")||"default"}`}#r(t){try{localStorage.setItem(this.#s(),t)}catch{}}#n(){try{let t=localStorage.getItem(this.#s());if(!t)return;this.style.width=t;let e=parseFloat(t);!isNaN(e)&&e>lh&&(this.#t=t)}catch{}}#a(){let t=this.getBoundingClientRect().width;this.collapsed=t<=lh}#o(){let t=this.querySelector(":scope > [data-resize]");if(!t)return;let e=this.getAttribute("slot"),i=e==="leading",r=n=>{n.preventDefault(),t.setPointerCapture(n.pointerId);let o=n.clientX,a=this.getBoundingClientRect().width;this.resizing=!0,document.documentElement.style.cursor="col-resize";let l=c=>{let u=c.clientX-o,d=parseInt(getComputedStyle(this).getPropertyValue("max-width"))||480,f=Math.max(48,Math.min(d,a+(i?u:-u)));this.style.width=`${f}px`},h=()=>{this.resizing=!1,document.documentElement.style.cursor="",t.removeEventListener("pointermove",l),t.removeEventListener("pointerup",h);let c=this.getBoundingClientRect().width;c<=lh?this.style.width=this.minWidth||getComputedStyle(this).minWidth:c<$E&&(this.style.width=`${$E}px`),this.#r(this.style.width),this.#a(),this.dispatchEvent(new CustomEvent("sidebar-resize",{bubbles:!0,detail:{name:this.name||e,width:this.getBoundingClientRect().width}}))};t.addEventListener("pointermove",l),t.addEventListener("pointerup",h)};t.addEventListener("pointerdown",r),this.#e.push(()=>t.removeEventListener("pointerdown",r))}#l(){typeof ResizeObserver>"u"||(this.#i=new ResizeObserver(t=>{for(let e of t){let i=e.contentBoxSize[0].inlineSize<=lh;for(let r of this.querySelectorAll("select-ui"))r.setAttribute("placement",i?"right":"bottom-start")}}),this.#i.observe(this))}#h(t){this.dispatchEvent(new CustomEvent("sidebar-toggle",{bubbles:!0,detail:{name:this.name||this.getAttribute("slot")||"default",expanded:t}}))}};y("chat-sidebar",hh);var CD="Closed.",$D="v1.0";function MO({renderer:s,doc:t=document}){if(!s)throw new Error("createSurfaceRegistry: opts.renderer is required");let e=new Map;function i(h,c){let u=e.get(h);if(u)return u;if(!c)throw new Error(`createSurfaceRegistry.route: no bubble element for fresh surfaceId "${h}"`);let d=t.createElement("div");d.setAttribute("data-surface-root",h),c.appendChild(d);let f=s.attachSurface(h,d),p={surfaceId:h,root:d,handle:f,bubbleEl:c,status:"open"};return e.set(h,p),p}function r(h){let c=t.createElement("div");c.setAttribute("data-surface-closed",h.surfaceId),c.textContent=CD,h.bubbleEl.appendChild(c)}function n(h){let c=e.get(h);if(c)return c.status==="closed"||(s.handleFrame(JSON.stringify({version:$D,deleteSurface:{surfaceId:h}})),c.status="closed",r(c)),c}function o(h,c,u){let d=null;try{d=JSON.parse(c)}catch{}if(d&&Object.hasOwn(d,"deleteSurface")){s.handleFrame(c);let f=e.get(h);return f&&f.status!=="closed"&&(f.status="closed",r(f)),f}return s.handleFrame(c),s.surfaces.has(h)?i(h,u):e.get(h)}function a(h){return e.get(h)}function l(){for(let h of e.values())h.handle.detach();e.clear()}return{route:i,close:n,feed:o,get:a,disposeAll:l,hosts:e}}var LO={sent:"Sending\u2026",started:"Thinking\u2026",reasoning:"Reasoning\u2026",content:"Writing\u2026",validating:"Validating\u2026",retry:"Retrying\u2026",tool:"Using a tool\u2026",done:"Done"};function PD(s){let t=s.surfaces.length,e=s.surfaces.map(i=>`${i.surfaceId} \u2014 ${i.rationale}`).join("; ");return`Planning ${t} surface${t===1?"":"s"}: ${e}`}var QD={new:"New",updated:"Updated",closed:"Closed"};function TD(s){let t=["new","updated","closed"].filter(e=>s[e].length>0).map(e=>`${QD[e]}: ${s[e].join(", ")}`);return t.length?`What changed \u2014 ${t.join(" \xB7 ")}`:"What changed \u2014 nothing this turn"}async function RO(s,t,e){let{events:i,statusEl:r=null,isProgressStage:n=a=>Object.hasOwn(LO,a)}=e??{};if(!i)throw new Error("wireAgentEvents: opts.events (AsyncIterable<AgentEvent>) is required");let o=()=>s.querySelector?.("chat-thread")?.querySelector('[data-role="assistant"]:last-child [data-bubble]')??null;for await(let a of i)switch(a.type){case"text":s.appendChunk?.(a.text);break;case"progress":{if(!n(a.stage))break;r&&(r.textContent=LO[a.stage]??"");break}case"surface":{let l=o();t.feed(a.surfaceId,a.line,l);break}case"step":{a.workflow==="plan"&&a.step==="manifest"?(s.appendMessage?.({role:"assistant",content:PD(a.data),render:!0}),s.appendMessage?.({role:"assistant",content:""})):a.workflow==="plan"&&a.step==="synthesis"&&(s.appendMessage?.({role:"assistant",content:TD(a.data),render:!0}),s.appendMessage?.({role:"assistant",content:""}));break}case"tool_use":s.appendMessage?.({role:"assistant",content:`\u{1F527} \`${a.name}(${JSON.stringify(a.input)})\``,render:!0}),s.appendMessage?.({role:"assistant",content:""});break;case"tool_result":s.appendMessage?.({role:a.isError?"error":"assistant",content:`\u21A9 \`${a.name}\` \u2192 ${String(a.output).slice(0,300)}`,render:!0}),s.appendMessage?.({role:"assistant",content:""});break;case"error":s.appendMessage?.({role:"error",content:a.error?.message??String(a.error)}),s.stopStreaming?.();break;case"done":s.stopStreaming?.();break;default:break}s.streaming&&s.stopStreaming?.()}C();P();var ch=class extends v{static properties={focusMode:{type:Boolean,default:!1,reflect:!0,attribute:"focus-mode"}};static template=()=>null;#t=null;#e=null;#i=null;connected(){this.#t=this.querySelector("editor-toolbar"),this.#e=this.querySelector("editor-canvas"),this.#s(),this.#i=t=>{let e=t?.detail?.name;e&&(e==="toggle-focus"||e==="full-screen")&&this.toggleFocusMode()},this.addEventListener("toolbar-action",this.#i)}disconnected(){this.#i&&this.removeEventListener("toolbar-action",this.#i),this.#i=null}toggleFocusMode(){this.focusMode=!this.focusMode,this.#t?.tagName?.toLowerCase()==="editor-toolbar"&&(this.#t.fullScreen=this.focusMode),this.#e?.tagName?.toLowerCase()==="editor-canvas"&&(this.focusMode?this.#e.focus?.():this.#e.blur?.()),this.dispatchEvent(new CustomEvent("editor-mode-change",{bubbles:!0,detail:{focusMode:this.focusMode}}))}#s(){for(let t of this.querySelectorAll("select-ui[data-options]"))try{let e=JSON.parse(t.getAttribute("data-options"));t.options=e}catch{}}};y("editor-shell",ch);C();P();var uh=class extends v{static properties={fullScreen:{type:Boolean,default:!1,reflect:!0,attribute:"full-screen"}};static template=()=>null;#t=null;connected(){this.#t=t=>{let e=t.target.closest("[data-toolbar-action]");if(!e||!this.contains(e))return;let i=e.getAttribute("data-toolbar-action");this.dispatchEvent(new CustomEvent("toolbar-action",{bubbles:!0,detail:{name:i}}))},this.addEventListener("click",this.#t)}disconnected(){this.#t&&this.removeEventListener("click",this.#t),this.#t=null}};y("editor-toolbar",uh);C();P();var dh=class extends v{static properties={empty:{type:Boolean,default:!0,reflect:!0},focused:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=1;#e=null;connected(){this.#i(),this.#s()}disconnected(){this.#e?.disconnect(),this.#e=null}get zoom(){return this.#t}set zoom(t){let e=parseFloat(t);!isFinite(e)||e<=0||(this.#t=e,this.style.setProperty("--editor-canvas-zoom",String(e)))}resetView(){this.zoom=1}focus(){super.focus?.(),this.focused=!0}blur(){super.blur?.(),this.focused=!1}#i(){let t=Array.from(this.children).filter(e=>e.tagName.toLowerCase()!=="editor-canvas-empty");this.empty=t.length===0}#s(){typeof MutationObserver>"u"||(this.#e=new MutationObserver(()=>{this.#i()}),this.#e.observe(this,{childList:!0}))}};y("editor-canvas",dh);C();P();var fh=96,LD="adia-editor-sidebar-",ph=class extends v{static properties={collapsed:{type:Boolean,default:!1,reflect:!0},resizing:{type:Boolean,default:!1,reflect:!0},collapsible:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=null;#r=null;#n=null;#a=null;#o=!1;#l=null;connected(){if(this.#t=this.querySelector("pane-ui"),!this.#t)return;let t=this.getAttribute("slot")||"leading",e=this.getAttribute("persist")||this.getAttribute("name")||t;this.#i=`${LD}${e}`,this.#m(),typeof ResizeObserver<"u"&&(this.#e=new ResizeObserver(i=>{if(getComputedStyle(this).display==="none")return;this.#d();let r=this.#t.offsetWidth;r>0&&(this.style.width=`${r}px`)}),this.#e.observe(this.#t)),this.#s=i=>{i.target?.closest?.('[slot="resize"], [data-resize], [class*="handle"]')&&(this.resizing=!0)},this.#t.addEventListener("pointerdown",this.#s),this.#r=()=>{this.resizing&&(this.resizing=!1),this.#f()},document.addEventListener("pointerup",this.#r),this.#n=i=>{i.target!==this.#t||i.propertyName!=="width"||(this.#c(),this.#d())},this.#t.addEventListener("transitionend",this.#n)}disconnected(){this.#a!==null&&(cancelAnimationFrame(this.#a),this.#a=null),this.#l!==null&&(clearTimeout(this.#l),this.#l=null),this.#e?.disconnect(),this.#e=null,this.#s&&this.#t&&(this.#t.removeEventListener("pointerdown",this.#s),this.#s=null),this.#r&&(document.removeEventListener("pointerup",this.#r),this.#r=null),this.#n&&this.#t&&(this.#t.removeEventListener("transitionend",this.#n),this.#n=null)}toggle(){return this.collapsed?this.expand():this.collapse(),this.collapsed}collapse(){this.#t&&(this.collapsed||this.#f(),this.#t.style.width=`${fh}px`,this.collapsed=!0,this.#u())}expand(){if(!this.#t)return;let t=this.#p(),e=t&&t>fh?t:240;this.#t.style.width=`${e}px`,this.collapsed=!1,this.#f(),this.#u(),this.#h()}#h(){this.#l!==null&&(clearTimeout(this.#l),this.#l=null);let t=getComputedStyle(this.#t).transitionDuration.split(",")[0].trim(),e=(parseFloat(t)||0)*(t.endsWith("ms")?1:1e3);e<=0||(this.#o=!0,this.#l=setTimeout(()=>{this.#l=null,this.#c(),this.#d()},e+50))}#c(){this.#o=!1,this.#l!==null&&(clearTimeout(this.#l),this.#l=null)}#d(){if(!this.#t||getComputedStyle(this).display==="none")return;let t=this.#t.getBoundingClientRect();if(t.width!==0){if(t.width>fh){this.#a!==null&&(cancelAnimationFrame(this.#a),this.#a=null),this.collapsed=!1;return}this.#o||this.#a===null&&(this.#a=requestAnimationFrame(()=>{if(this.#a=null,!this.#t||getComputedStyle(this).display==="none"||this.#o)return;let e=this.#t.getBoundingClientRect();e.width>0&&e.width<=fh&&(this.collapsed=!0)}))}}#u(){let t=this.getAttribute("slot")||"leading",e=this.getAttribute("persist")||this.getAttribute("name")||t;this.dispatchEvent(new CustomEvent("sidebar-toggle",{bubbles:!0,detail:{name:e,expanded:!this.collapsed}}))}#f(){if(!(!this.#t||!this.#i))try{let t=this.#t.style.width||"";t&&localStorage.setItem(this.#i,t)}catch{}}#p(){if(!this.#i)return null;try{let t=localStorage.getItem(this.#i);if(!t)return null;let e=parseFloat(t);return isFinite(e)?e:null}catch{return null}}#m(){if(!this.#t)return;let t=this.#p();t&&t>0&&(this.#t.style.width=`${t}px`,this.collapsed=t<=fh)}};y("editor-sidebar",ph);function MD(){let s=document.activeElement;if(!s)return!1;let t=s.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||s.isContentEditable||t==="INPUT-UI"||t==="TEXTAREA-UI"||t==="OTP-INPUT-UI"||t==="SEARCH-UI")}P();var mh=class extends v{static properties={centered:{type:Boolean,default:!1,reflect:!0},"full-bleed":{type:Boolean,default:!1,reflect:!0}};static template=()=>null};customElements.get("simple-shell")||customElements.define("simple-shell",mh);C();P();var Td=class extends v{static properties={mode:{type:String,default:"chat",reflect:!0},inspector:{type:Boolean,default:!1,reflect:!0}};static template=()=>null;#t=!1;#e=null;#i=null;#s=null;connected(){}render(){this.#t||(this.#t=!0,this.#e=document.createElement("chat-thread-ui"),this.#i=document.createElement("canvas-ui"),this.appendChild(this.#e),this.appendChild(this.#i),this.inspector&&(this.#s=document.createElement("inspector-ui"),this.appendChild(this.#s)))}appendMessage(t){this.#e?.appendMessage(t)}appendCoT(t){this.#e?.appendCoT(t)}pushArtifact(t){this.mode==="chat"&&(this.mode="split"),this.#i?.processAll(t)}setSuggestions(t){this.#e?.setSuggestions(t)}appendResultMessage(t){this.#e?.appendResultMessage(t)}showSavePatternBar(t){this.#e?.showSavePatternBar(t)}showFeedbackWidget(t){this.#e?.showFeedbackWidget(t)}showTyping(){this.#e?.showTyping()}hideTyping(){this.#e?.hideTyping()}appendError(t){this.#e?.appendError(t)}startPipelineStatus(){return this.#e?.startPipelineStatus()}updatePipelineStatus(t){this.#e?.updatePipelineStatus(t)}completePipelineStatus(){this.#e?.completePipelineStatus()}reset(){this.#e?.clear(),this.#i?.reset(),this.mode="chat"}get thread(){return this.#e}get canvas(){return this.#i}get inspect(){return this.#s}};y("gen-root",Td);$O();C();P();var RD=["atlas","signal","terrarium","ledger","arcade","meridian","solstice","glacier","ember","botanica","vector","velour"],ID={compact:{density:.85,radius:.75},default:{density:1,radius:1},spacious:{density:1.15,radius:1.25}},IO=["","ui-sm","ui-md","ui-lg","content-sm","content-md","content-lg"],PE=s=>s.length?s[0].toUpperCase()+s.slice(1):s,gh=class extends v{static properties={themes:{type:String,default:RD.join(" "),reflect:!0},parametric:{type:Boolean,default:!1,reflect:!0},presets:{type:Boolean,default:!1,reflect:!0},schemeToggle:{type:Boolean,default:!1,reflect:!0,attribute:"scheme-toggle"},persist:{type:Boolean,default:!1,reflect:!0},storagePrefix:{type:String,default:"adia-theme-",reflect:!0,attribute:"storage-prefix"},target:{type:String,default:":root",reflect:!0},scheme:{type:String,default:"auto",reflect:!0},activeTheme:{type:String,default:"",reflect:!0,attribute:"active-theme"},activeScheme:{type:String,default:"",reflect:!0,attribute:"active-scheme"},activeDensity:{type:String,default:"",reflect:!0,attribute:"active-density"},activeRadius:{type:String,default:"",reflect:!0,attribute:"active-radius"},register:{type:Boolean,default:!1,reflect:!0},activeScale:{type:String,default:"",reflect:!0,attribute:"active-scale"}};static template=()=>null;#t=null;#e=null;#i=[];#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=!1;connected(){this.#h||(this.#c(),this.#h=!0,this.#w(),this.#g(),this.#b())}disconnected(){for(let t of this.#i)t();this.#i=[],this.#v(),this.parametric&&this.#S().removeAttribute("data-parametric-scope")}apply(t={}){this.#p(t,"programmatic")}reset(){let t=this.#S();if(t.removeAttribute("theme"),t.style.removeProperty("--a-density"),t.style.removeProperty("--a-radius-k"),t.style.removeProperty("color-scheme"),t.removeAttribute("scale"),this.persist)for(let e of["theme","scheme","density","radius","scale"])try{localStorage.removeItem(`${this.storagePrefix}${e}`)}catch{}this.activeTheme="",this.activeDensity="",this.activeRadius="",this.activeScale="",this.scheme="auto",this.activeScheme=this.#y(),this.#n&&(this.#n.value="auto"),this.#s&&(this.#s.value=1),this.#r&&(this.#r.value=1),this.#a&&(this.#a.value=""),this.#o&&(this.#o.value=""),this.#m("reset")}#c(){let t=document.createDocumentFragment();if(this.schemeToggle){let o=document.createElement("div");o.setAttribute("part","scheme");let a=document.createElement("segmented-ui");a.id=`${this.#k}-scheme`;let l=document.createElement("segment-ui");l.setAttribute("value","auto"),l.setAttribute("text","System");let h=document.createElement("segment-ui");h.setAttribute("value","light"),h.setAttribute("text","Light");let c=document.createElement("segment-ui");c.setAttribute("value","dark"),c.setAttribute("text","Dark"),a.append(l,h,c),o.appendChild(a),t.appendChild(o),this.#n=a}let e=(this.themes||"").trim().split(/\s+/).filter(Boolean);if(e.length){let o=document.createElement("div");o.setAttribute("part","theme-row");let a=document.createElement("text-ui");a.setAttribute("variant","label"),a.textContent="Theme",o.appendChild(a);let l=document.createElement("select-ui");l.setAttribute("part","themes"),l.setAttribute("size","sm"),l.id=`${this.#k}-theme`;let h=(c,u)=>{let d=document.createElement("option");return d.value=c,d.textContent=u,d};l.append(h("","Default"),...e.map(c=>h(c,PE(c)))),l.setAttribute("value",""),o.appendChild(l),t.appendChild(o),this.#o=l}if(this.parametric){t.appendChild(document.createElement("divider-ui"));let o=document.createElement("text-ui");o.setAttribute("variant","label"),o.textContent="Parametric",t.appendChild(o);let a=document.createElement("slider-ui");a.setAttribute("part","density"),a.setAttribute("label","Density"),a.setAttribute("value","1"),a.setAttribute("min","0.5"),a.setAttribute("max","1.5"),a.setAttribute("step","0.05"),a.setAttribute("suffix","\xD7"),t.appendChild(a),this.#s=a;let l=document.createElement("slider-ui");l.setAttribute("part","radius"),l.setAttribute("label","Radius"),l.setAttribute("value","1"),l.setAttribute("min","0"),l.setAttribute("max","2"),l.setAttribute("step","0.1"),l.setAttribute("suffix","\xD7"),t.appendChild(l),this.#r=l}if(this.presets||this.register){if(t.appendChild(document.createElement("divider-ui")),this.presets){let o=document.createElement("div");o.setAttribute("part","preset-row");let a=document.createElement("text-ui");a.setAttribute("variant","label"),a.textContent="Preset",o.appendChild(a);let l=document.createElement("div");l.setAttribute("part","presets");for(let h of["compact","default","spacious"]){let c=document.createElement("button-ui");c.setAttribute("data-preset",h),c.setAttribute("text",PE(h)),c.setAttribute("variant","outline"),c.setAttribute("size","sm"),l.appendChild(c)}o.appendChild(l),t.appendChild(o)}if(this.register){let o=document.createElement("div");o.setAttribute("part","preset-row");let a=document.createElement("text-ui");a.setAttribute("variant","label"),a.textContent="Scale",o.appendChild(a);let l=document.createElement("select-ui");l.setAttribute("part","scale"),l.setAttribute("size","sm"),l.id=`${this.#k}-scale`,l.innerHTML=IO.map(h=>`<option value="${h}">${h||"Default"}</option>`).join(""),l.setAttribute("value",""),o.appendChild(l),t.appendChild(o),this.#a=l}}t.appendChild(document.createElement("divider-ui"));let i=document.createElement("div");i.setAttribute("part","reset-row");let r=document.createElement("button-ui");r.setAttribute("part","reset"),r.setAttribute("text","Reset"),r.setAttribute("variant","ghost"),r.setAttribute("size","sm"),i.appendChild(r),t.appendChild(i),this.#l=r;let n=document.createElement("theme-provider");n.setAttribute("scale","ui-md"),n.appendChild(t),this.appendChild(n),this.#d()}#d(){if(this.#o){let t=e=>{let i=e.detail?.value??this.#o.value;this.#u(i)};this.#o.addEventListener("change",t),this.#i.push(()=>this.#o.removeEventListener("change",t))}if(this.#l){let t=()=>this.reset();this.#l.addEventListener("press",t),this.#l.addEventListener("click",t),this.#i.push(()=>{this.#l.removeEventListener("press",t),this.#l.removeEventListener("click",t)})}if(this.#s){let t=()=>this.#p({density:parseFloat(this.#s.value)},"slider");this.#s.addEventListener("input",t),this.#i.push(()=>this.#s.removeEventListener("input",t))}if(this.#r){let t=()=>this.#p({radius:parseFloat(this.#r.value)},"slider");this.#r.addEventListener("input",t),this.#i.push(()=>this.#r.removeEventListener("input",t))}for(let t of this.querySelectorAll('[part="presets"] button-ui')){let e=t.getAttribute("data-preset"),i=()=>this.#f(e);t.addEventListener("press",i),t.addEventListener("click",i),this.#i.push(()=>{t.removeEventListener("press",i),t.removeEventListener("click",i)})}if(this.#n){let t=e=>{let i=e.detail?.value??this.#n.value;(i==="light"||i==="dark"||i==="auto")&&this.#p({scheme:i},"scheme")};this.#n.addEventListener("change",t),this.#i.push(()=>this.#n.removeEventListener("change",t))}if(this.#a){let t=e=>{let i=e.detail?.value??this.#a.value;this.#p({scale:i},"scale")};this.#a.addEventListener("change",t),this.#i.push(()=>this.#a.removeEventListener("change",t))}}#u(t){let e=this.#S();if(e.style.removeProperty("--a-density"),e.style.removeProperty("--a-radius-k"),this.persist)try{localStorage.removeItem(`${this.storagePrefix}density`),localStorage.removeItem(`${this.storagePrefix}radius`)}catch{}this.#p({theme:t},"theme"),this.#s&&(this.#s.value=1),this.#r&&(this.#r.value=1),this.activeDensity="",this.activeRadius=""}#f(t){let e=ID[t];e&&(this.#p({density:e.density,radius:e.radius},"preset"),this.#s&&(this.#s.value=e.density),this.#r&&(this.#r.value=e.radius))}#p(t,e){let i=this.#S();if(t.theme!==void 0){if(t.theme===""||t.theme==="default"?(i.removeAttribute("theme"),this.activeTheme=""):(i.setAttribute("theme",t.theme),this.activeTheme=t.theme),this.persist)try{this.activeTheme?localStorage.setItem(`${this.storagePrefix}theme`,this.activeTheme):localStorage.removeItem(`${this.storagePrefix}theme`)}catch{}this.#o&&(this.#o.value=this.activeTheme)}if(t.density!==void 0&&(i.style.setProperty("--a-density",t.density),this.activeDensity=String(t.density),this.persist))try{localStorage.setItem(`${this.storagePrefix}density`,String(t.density))}catch{}if(t.radius!==void 0&&(i.style.setProperty("--a-radius-k",t.radius),this.activeRadius=String(t.radius),this.persist))try{localStorage.setItem(`${this.storagePrefix}radius`,String(t.radius))}catch{}if(t.scheme!==void 0){let r=t.scheme;if(r==="auto"){if(i.style.removeProperty("color-scheme"),this.scheme="auto",this.activeScheme=this.#y(),this.persist)try{localStorage.removeItem(`${this.storagePrefix}scheme`)}catch{}this.#x()}else if(r==="light"||r==="dark"){if(i.style.setProperty("color-scheme",r),this.scheme=r,this.activeScheme=r,this.persist)try{localStorage.setItem(`${this.storagePrefix}scheme`,r)}catch{}this.#v()}this.#n&&(this.#n.value=this.scheme)}if(t.scale!==void 0){let r=t.scale;if(r&&IO.includes(r)?(i.setAttribute("scale",r),this.activeScale=r):(i.removeAttribute("scale"),this.activeScale=""),this.persist)try{this.activeScale?localStorage.setItem(`${this.storagePrefix}scale`,this.activeScale):localStorage.removeItem(`${this.storagePrefix}scale`)}catch{}this.#a&&(this.#a.value=this.activeScale)}this.#m(e)}#m(t){this.dispatchEvent(new CustomEvent("theme-change",{bubbles:!0,detail:{theme:this.activeTheme,scheme:this.activeScheme,density:this.activeDensity?parseFloat(this.activeDensity):1,radius:this.activeRadius?parseFloat(this.activeRadius):1,scale:this.activeScale,source:t}}))}#g(){let t=this.#S(),e,i,r,n,o;if(this.persist)try{e=localStorage.getItem(`${this.storagePrefix}theme`)||"",i=localStorage.getItem(`${this.storagePrefix}scheme`)||"";let a=localStorage.getItem(`${this.storagePrefix}density`),l=localStorage.getItem(`${this.storagePrefix}radius`);r=a!=null?parseFloat(a):void 0,n=l!=null?parseFloat(l):void 0,o=localStorage.getItem(`${this.storagePrefix}scale`)||""}catch{}if(e?(t.setAttribute("theme",e),this.activeTheme=e):this.activeTheme=t.getAttribute("theme")||"",this.#o&&(this.#o.value=this.activeTheme),i==="light"||i==="dark")t.style.setProperty("color-scheme",i),this.scheme=i,this.activeScheme=i,this.#n&&(this.#n.value=i);else{let a=this.scheme||"auto";a==="light"||a==="dark"?(t.style.setProperty("color-scheme",a),this.activeScheme=a):(this.scheme="auto",this.activeScheme=this.#y()),this.#n&&(this.#n.value=this.scheme)}if(r!=null&&!Number.isNaN(r))t.style.setProperty("--a-density",r),this.activeDensity=String(r),this.#s&&(this.#s.value=r);else if(this.#s){let a=this.#O(t,"--a-density");this.#s.value=a,this.activeDensity=String(a)}if(n!=null&&!Number.isNaN(n))t.style.setProperty("--a-radius-k",n),this.activeRadius=String(n),this.#r&&(this.#r.value=n);else if(this.#r){let a=this.#O(t,"--a-radius-k");this.#r.value=a,this.activeRadius=String(a)}if(this.#a){let a=IO.includes(o)?o:t.getAttribute("scale")||"";a&&t.setAttribute("scale",a),this.#a.value=a,this.activeScale=a}}#O(t,e){let i=getComputedStyle(t);return parseFloat(i.getPropertyValue(e))||1}#y(){try{if(typeof matchMedia=="function"&&matchMedia("(prefers-color-scheme: dark)").matches)return"dark"}catch{}return"light"}#b(){if(this.scheme==="auto"){if(this.persist)try{let t=localStorage.getItem(`${this.storagePrefix}scheme`);if(t==="light"||t==="dark")return}catch{}this.#x()}}#x(){if(!(this.#t||typeof matchMedia!="function"))try{this.#t=matchMedia("(prefers-color-scheme: dark)"),this.#e=()=>{let t=this.#t.matches?"dark":"light";this.activeScheme=t,this.#n&&(this.#n.value="auto"),this.#m("scheme")},this.#t.addEventListener("change",this.#e)}catch{}}#v(){if(this.#t&&this.#e)try{this.#t.removeEventListener("change",this.#e)}catch{}this.#t=null,this.#e=null}#S(){let t=this.target||":root";if(t===":root")return document.documentElement;try{return document.querySelector(t)??document.documentElement}catch{return document.documentElement}}#w(){let t=this.#S();t!==document.documentElement&&(this.parametric?t.setAttribute("data-parametric-scope",""):t.removeAttribute("data-parametric-scope"))}get#k(){return this.id||"theme-panel"}};y("theme-panel",gh);P();var QE=["change","input"],bh=class extends v{static properties={label:{type:String,default:"",reflect:!0},heading:{type:String,default:"",reflect:!0},placement:{type:String,default:"bottom-start",reflect:!0}};static template=()=>null;#t=!1;#e=null;#i=null;#s=()=>this.#l();#r=null;connected(){this.#t||(this.#n(),this.#t=!0);for(let t of QE)this.addEventListener(t,this.#s);this.#i&&!this.#r&&(this.#r=new MutationObserver(this.#s),this.#r.observe(this.#i,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["checked"]})),this.#l()}disconnected(){for(let t of QE)this.removeEventListener(t,this.#s);this.#r?.disconnect(),this.#r=null}updated(t){this.#t&&(t.has("label")&&this.#l(),t.has("heading")&&this.#a(),t.has("placement")&&this.querySelector(":scope > popover-ui")?.setAttribute("placement",this.placement))}get summary(){let t=this.#i?this.#i.querySelectorAll("check-ui"):[],e=[];for(let i of t)(i.hasAttribute("checked")||i.checked)&&e.push(i);return{selected:e.length,total:t.length,checked:e}}#n(){let t=document.createDocumentFragment();for(;this.firstChild;)t.appendChild(this.firstChild);let e=document.createElement("popover-ui");e.setAttribute("placement",this.placement);let i=document.createElement("button-ui");i.setAttribute("slot","trigger"),i.setAttribute("data-form-popover-trigger",""),i.setAttribute("icon-trailing","caret-down"),this.#e=i,e.appendChild(i);let r=document.createElement("div");r.setAttribute("slot","content"),r.setAttribute("data-form-popover-body",""),r.appendChild(t),this.#i=r,e.appendChild(r),this.appendChild(e),this.#a()}#a(){if(!this.#i)return;let t=this.#i.querySelector(":scope > [data-form-popover-heading]");if(!this.heading){t?.remove();return}t||(t=document.createElement("div"),t.setAttribute("data-form-popover-heading",""),this.#i.prepend(t)),t.textContent=this.heading}#o(t){return(t.getAttribute("label")||t.label||t.textContent||"").trim()}#l(){if(!this.#e)return;let{selected:t,total:e,checked:i}=this.summary,r=this.label;t===1&&i[0]?r=this.#o(i[0])||r:t>1&&(r=r?`${r} (${t})`:`${t}`),r||(r="Options"),this.#e.setAttribute("text",r),this.dispatchEvent(new CustomEvent("summary-change",{bubbles:!0,detail:{selected:t,total:e}}))}};customElements.get("form-popover-ui")||customElements.define("form-popover-ui",bh);P();var Oh=class extends v{static properties={items:{type:Array,default:[]},"storage-key":{type:String,default:"",reflect:!0},storage:{type:String,default:"local",reflect:!0},"dismiss-on-complete":{type:Boolean,default:!1,reflect:!0},collapsible:{type:Boolean,default:!0,reflect:!0},collapsed:{type:Boolean,default:!1,reflect:!0},value:{type:Object,default:{}},title:{type:String,default:"Get started",reflect:!0}};static template=t=>t._renderTemplate();#t=`obc-h-${Math.random().toString(36).slice(2,8)}`;#e=`obc-l-${Math.random().toString(36).slice(2,8)}`;#i=!1;#s=!1;#r=null;#n=null;attributeChangedCallback(t,e,i){if(t==="items"||t==="value"){if(i==null)this[t]=t==="items"?[]:{};else try{let r=JSON.parse(i);this[t]=r}catch{this[t]=t==="items"?[]:{}}return}super.attributeChangedCallback(t,e,i)}connected(){if(this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#t),this.hasAttribute("items")&&!Array.isArray(this.items))try{this.items=JSON.parse(this.getAttribute("items"))}catch{this.items=[]}if(this.hasAttribute("value")&&(typeof this.value!="object"||Array.isArray(this.value)))try{this.value=JSON.parse(this.getAttribute("value"))}catch{this.value={}}if(this.#i=this.value&&Object.keys(this.value).length>0,!this.#i){let t=this.#x();t&&(this.value=t)}this.#r=this.#o.bind(this),this.#n=this.#l.bind(this),this.addEventListener("change",this.#r),this.addEventListener("click",this.#n),this.#s=this.#p(),this.#m()}disconnected(){this.#r&&this.removeEventListener("change",this.#r),this.#n&&this.removeEventListener("click",this.#n),this.#r=null,this.#n=null,this.#v()}render(){this.#m(),this.#y(),this.#g()}_renderTemplate(){let t=Array.isArray(this.items)?this.items:[],{done:e,total:i,percent:r}=this.#f(),n=this.collapsed?"Expand":"Collapse",o=this.collapsed?"chevron-down":"chevron-up",a=!!this.collapsible,l=this.title||"Get started",h=i>0&&e===i;return Y`
396
396
  <div data-part="header">
397
397
  <div data-part="title" id=${this.#t}>${l}</div>
398
398
  ${a?Y`<button-ui
@@ -452,10 +452,10 @@ Correct shape for <chart-ui x="label" y="value">:
452
452
  text="Open"
453
453
  ></button-ui>`:null}
454
454
  </list-item-ui>
455
- `}#o(t){let e=t.target;if(!e||!e.closest)return;let i=e.closest("[data-step-check]");if(!i||!this.contains(i))return;let r=i.getAttribute("data-step-id")||"";if(!r)return;let n=this.#d(r),o=!!i.checked;n!==o&&this.#u(r,o,{emit:o})}#l(t){let e=t.target;if(!e||!e.closest)return;let i=e.closest("[data-step-action]");if(!i||!this.contains(i))return;let r=i.getAttribute("data-step-id")||"",n=i.getAttribute("data-href")||"";r&&this.dispatchEvent(new CustomEvent("onboarding-step-action",{bubbles:!0,detail:{id:r,href:n}}))}#h(t){t?.stopPropagation?.();let e=!this.collapsed;this.collapsed=e,e&&this.dispatchEvent(new CustomEvent("onboarding-dismiss",{bubbles:!0,detail:{reason:"collapsed"}}))}#c(t){if(!t)return!1;let e=t.id;return e!=null&&Object.prototype.hasOwnProperty.call(this.value||{},e)?!!this.value[e]:!!t.done}#d(t){let i=(Array.isArray(this.items)?this.items:[]).find(r=>r&&String(r.id)===String(t));return this.#c(i)}#u(t,e,{emit:i=!0}={}){let r={...this.value||{},[t]:!!e};this.value=r,this.#v(),i&&e&&this.dispatchEvent(new CustomEvent("onboarding-step-complete",{bubbles:!0,detail:{id:t,value:r}}))}#f(){let t=Array.isArray(this.items)?this.items:[],e=t.length,i=0;for(let n of t)this.#c(n)&&i++;let r=e===0?0:Math.round(i/e*100);return{done:i,total:e,percent:r}}#p(){let{done:t,total:e}=this.#f();return e>0&&t===e}#m(){this.#p()?this.setAttribute("data-complete",""):this.removeAttribute("data-complete")}#g(){let t=this.#p();t&&!this.#s?(this.#s=!0,this.dispatchEvent(new CustomEvent("onboarding-complete",{bubbles:!0,detail:{value:this.value}})),this["dismiss-on-complete"]&&this.#O("complete")):t||(this.#s=!1)}#O(t="user"){this.setAttribute("hidden",""),this.dispatchEvent(new CustomEvent("onboarding-dismiss",{bubbles:!0,detail:{reason:t}}))}#y(){}#b(){if(this.#i||this.storage==="none"||!this["storage-key"]||typeof window>"u")return null;try{return this.storage==="session"?window.sessionStorage:window.localStorage}catch{return null}}#x(){let t=this.#b();if(!t)return null;try{let e=t.getItem(this["storage-key"]);if(!e)return null;let i=JSON.parse(e);return i&&typeof i=="object"&&!Array.isArray(i)?i:null}catch{return null}}#v(){let t=this.#b();if(t)try{t.setItem(this["storage-key"],JSON.stringify(this.value||{}))}catch{}}complete(t){if(t==null)return;let e=String(t);this.#d(e)||this.#u(e,!0,{emit:!0})}reset(t){if(t==null){this.value={};let i=this.#b();try{i?.removeItem(this["storage-key"])}catch{}this.#s=!1,this.removeAttribute("hidden");return}let e=String(t);Object.prototype.hasOwnProperty.call(this.value||{},e)&&this.#u(e,!1,{emit:!1})}progress(){return this.#f()}};customElements.get("onboarding-checklist-ui")||customElements.define("onboarding-checklist-ui",Oh);P();Pt();var DO=new Set(["","comfortable","compact","spacious"]),qO=new Set(["2","3","4","5","6"]),TE=new Set(["","2","2:1","3:2","3:1"]),NO=["toolbar","kpis","charts","table","aside"],Ld=class extends v{static get properties(){return{density:{type:String,default:"",reflect:!0},"kpi-columns":{type:String,default:"4",reflect:!0,attribute:"kpi-columns"},"chart-split":{type:String,default:"",reflect:!0,attribute:"chart-split"},loading:{type:Boolean,default:!1,reflect:!0},gap:{type:String,default:"",reflect:!0}}}static template=()=>null;#t={toolbar:!1,kpis:!1,charts:!1,table:!1,aside:!1};#e=null;#i=!1;setDensity(t){let e=DO.has(t)?t:"";this.density!==e&&(this.density=e)}getRegion(t){return NO.includes(t)?this.querySelector(`:scope > [slot="${t}"]`):null}connected(){this.hasAttribute("role")||this.setAttribute("role","region"),H(()=>this.#s()),this.#r(),this.#n(),this.#a(),typeof MutationObserver<"u"&&(this.#e=new MutationObserver(t=>this.#o(t)),this.#e.observe(this,{childList:!0}))}disconnected(){this.#e&&(this.#e.disconnect(),this.#e=null)}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback?.(t,e,i),!this.#i){if(t==="density"&&e!==i){if(!DO.has(i)){this.#i=!0;try{this.density=""}finally{this.#i=!1}return}this.isConnected&&this.dispatchEvent(new CustomEvent("density-change",{bubbles:!0,detail:{density:i}}));return}if(t==="kpi-columns"&&e!==i){if(i!=null&&!qO.has(i)){console.warn(`[dashboard-layout-ui] kpi-columns="${i}" out of range \u2014 falling back to "4". Use one of: ${[...qO].join(", ")}.`),this.#i=!0;try{this["kpi-columns"]="4"}finally{this.#i=!1}}return}if(t==="chart-split"&&e!==i){if(i!=null&&!TE.has(i)){console.warn(`[dashboard-layout-ui] chart-split="${i}" not in enum \u2014 falling back to "" (single column). Use one of: "" (full), 2, 2:1, 3:2, 3:1.`),this.#i=!0;try{this["chart-split"]=""}finally{this.#i=!1}}return}if(t==="loading"&&e!==i){this.#r();return}if(t==="gap"&&e!==i){this.#n();return}}}#s(){if(!DO.has(this.density)){this.#i=!0;try{this.density=""}finally{this.#i=!1}}if(!qO.has(this["kpi-columns"])){console.warn(`[dashboard-layout-ui] kpi-columns="${this["kpi-columns"]}" out of range \u2014 clamping to "4".`),this.#i=!0;try{this["kpi-columns"]="4"}finally{this.#i=!1}}if(!TE.has(this["chart-split"])){console.warn(`[dashboard-layout-ui] chart-split="${this["chart-split"]}" not in enum \u2014 clamping to "".`),this.#i=!0;try{this["chart-split"]=""}finally{this.#i=!1}}}#r(){this.loading?this.setAttribute("aria-busy","true"):this.removeAttribute("aria-busy")}#n(){let t=(this.gap||"").trim();if(t===""){this.style.removeProperty("--dashboard-layout-gap");return}/^[1-6]$/.test(t)?this.style.setProperty("--dashboard-layout-gap",`var(--a-space-${t})`):this.style.setProperty("--dashboard-layout-gap",t)}#a(){for(let t of NO)this.#t[t]=!!this.querySelector(`:scope > [slot="${t}"]`)}#o(t){for(let e of NO){let i=this.#t[e],r=!!this.querySelector(`:scope > [slot="${e}"]`);i&&!r&&this.dispatchEvent(new CustomEvent("region-empty",{bubbles:!0,detail:{region:e}})),this.#t[e]=r}}};customElements.get("dashboard-layout-ui")||customElements.define("dashboard-layout-ui",Ld);Pt();var tr=new Set,LE=!1;function ME(s){return String(s).padStart(2,"0")}function Md(s){return`${s.getFullYear()}-${ME(s.getMonth()+1)}-${ME(s.getDate())}`}function RE(s){if(!s)return null;let t=String(s).match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)return null;let e=new Date(+t[1],+t[2]-1,+t[3]);return Number.isNaN(e.getTime())?null:e}var IE={today:"Today","7d":"Last 7 days","30d":"Last 30 days","90d":"Last 90 days",qtd:"Quarter to date",ytd:"Year to date",custom:"Custom"},er=new Set(Object.keys(IE));function yh(s,t=new Date){let e=new Date(t.getFullYear(),t.getMonth(),t.getDate()),i=Md(e),r=n=>{let o=new Date(e);return o.setDate(o.getDate()-n),Md(o)};switch(s){case"today":return{from:i,to:i};case"7d":return{from:r(6),to:i};case"30d":return{from:r(29),to:i};case"90d":return{from:r(89),to:i};case"qtd":{let n=Math.floor(e.getMonth()/3)*3;return{from:Md(new Date(e.getFullYear(),n,1)),to:i}}case"ytd":return{from:Md(new Date(e.getFullYear(),0,1)),to:i};case"custom":return null;default:return null}}function MD(s,t){let e=RE(s),i=RE(t);if(!e||!i)return"";let r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],n=e.getFullYear()===i.getFullYear(),o=n&&e.getMonth()===i.getMonth();return n&&e.getMonth()===i.getMonth()&&e.getDate()===i.getDate()?`${r[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`:o?`${r[e.getMonth()]} ${e.getDate()} \u2013 ${i.getDate()}, ${i.getFullYear()}`:n?`${r[e.getMonth()]} ${e.getDate()} \u2013 ${r[i.getMonth()]} ${i.getDate()}, ${i.getFullYear()}`:`${r[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()} \u2013 ${r[i.getMonth()]} ${i.getDate()}, ${i.getFullYear()}`}var Rd=class s extends R{static labelDeprecated=!0;static get properties(){return{...R.properties,value:{type:String,default:"7d",reflect:!0},from:{type:String,default:"",reflect:!0},to:{type:String,default:"",reflect:!0},presets:{type:String,default:"today,7d,30d,90d,qtd,ytd,custom"},broadcast:{type:String,default:"document",reflect:!0},ariaLabelAttr:{type:String,default:"Time period",attribute:"aria-label",reflect:!0},pickerOpen:{type:Boolean,default:!1,attribute:"picker-open",reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n={prefix:null,chips:null,picker:null,readout:null,suffix:null};#a=!1;#o=!1;static#l=new WeakSet;setRange(t,e,i){if(t==="custom"){if(!e||!i){console.warn('[date-range-selector-ui] setRange("custom", \u2026) requires from + to ISO dates.');return}let n=this.#p(e,i);this.#u("custom",n.from,n.to);return}if(!er.has(t)){console.warn(`[date-range-selector-ui] unknown preset "${t}" \u2014 ignored. Use one of: ${[...er].join(", ")}.`);return}let r=yh(t);r&&this.#u(t,r.from,r.to)}getRange(){return{value:this.value,preset:this.value,from:this.from,to:this.to}}subscribe(t){let e=this.#g();return e?(e.addEventListener("range-change",t),()=>e.removeEventListener("range-change",t)):()=>{}}connected(){super.connected(),this.setAttribute("role","group"),this.hasAttribute("aria-label")||this.setAttribute("aria-label",this.ariaLabelAttr||"Time period"),this.#t||(this.#h(),this.#d(),this.#t=!0),this.broadcast==="document"&&this.#b(),H(()=>{let t=this.#m();t&&this.#u(this.value,t.from,t.to,{initial:!0})})}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0,this.#x()}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#o)){if(t==="presets"){this.#c();return}if(t==="broadcast"){e==="document"&&i!=="document"&&this.#x(),i==="document"?(this.#b(),this.#y()):i==="self"&&this.#y();return}if(t==="value"&&e!==i&&i&&er.has(i)){if(i!=="custom"){let r=yh(i);r&&this.#u(i,r.from,r.to)}return}}}syncValue(t){let e=this.from&&this.to?`${this.from}:${this.to}`:"";this.internals.setFormValue(e)}render(){if(this.#t){if(this.#i&&this.#i.value!==this.value&&(this.#i.value=this.value),this.#s){this.hasAttribute("min")&&this.#s.setAttribute("min",this.getAttribute("min")),this.hasAttribute("max")&&this.#s.setAttribute("max",this.getAttribute("max"));let t=this.from&&this.to?JSON.stringify({from:this.from,to:this.to}):"";this.#s.value!==t&&(this.#s.value=t)}if(this.#r){let t=MD(this.from,this.to);this.#r.textContent=t,this.#r.hidden=!t}}}#h(){let t=document.createElement("segmented-ui");t.setAttribute("data-region","chips"),t.setAttribute("role","radiogroup"),t.setAttribute("aria-label","Preset ranges"),this.appendChild(t),this.#i=t,this.#n.chips=t;let e=document.createElement("date-range-picker-ui");e.setAttribute("data-region","picker"),e.setAttribute("format","short"),e.setAttribute("placeholder","Custom range"),this.appendChild(e),this.#s=e,this.#n.picker=e;let i=document.createElement("text-ui");i.setAttribute("data-region","readout"),i.setAttribute("part","readout"),i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.hidden=!0,this.appendChild(i),this.#r=i,this.#n.readout=i,this.#c()}#c(){if(!this.#i)return;let t=(this.presets||"").split(",").map(i=>i.trim()).filter(Boolean),e=this.#i.querySelector(":scope > [data-indicator]");this.#i.replaceChildren(),e&&this.#i.appendChild(e);for(let i of t){if(!er.has(i)){s.#l.has(this)||(s.#l.add(this),console.warn(`[date-range-selector-ui] unknown preset key "${i}" in [presets] \u2014 ignored. Use one of: ${[...er].join(", ")}.`));continue}let r=document.createElement("segment-ui");r.setAttribute("value",i),r.setAttribute("text",IE[i]),this.#i.appendChild(r)}this.#i.value=this.value}#d(){let t=n=>{let o=n.detail?.value;if(!o||!er.has(o))return;if(n.stopPropagation(),o==="custom"){this.#v(),this.#f("custom");return}let a=yh(o);a&&this.#u(o,a.from,a.to)};this.#i.addEventListener("change",t),this.#e.push(()=>this.#i.removeEventListener("change",t));let e=n=>{n.stopPropagation();let a=(n.detail||{}).value||null;if(!a||!a.from||!a.to)return;let l=this.#p(a.from,a.to);this.#u("custom",l.from,l.to)};this.#s.addEventListener("change",e),this.#e.push(()=>this.#s.removeEventListener("change",e));let i=()=>{this.pickerOpen=!0},r=()=>{this.pickerOpen=!1};this.#s.addEventListener("open",i),this.#s.addEventListener("close",r),this.#e.push(()=>this.#s.removeEventListener("open",i)),this.#e.push(()=>this.#s.removeEventListener("close",r))}#u(t,e,i,r={}){if(this.from===e&&this.to===i&&this.value===t&&!r.initial)return;this.#o=!0;try{this.from=e,this.to=i,this.value=t}finally{this.#o=!1}this.syncValue(),this.#y();let o={value:t,from:e,to:i,preset:t};this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:t,from:e,to:i}}));let a=this.#g();a&&a.dispatchEvent(new CustomEvent("range-change",{bubbles:a===this,detail:o}))}#f(t){if(this.value!==t){this.#o=!0;try{this.value=t}finally{this.#o=!1}}}#p(t,e){return t<=e?{from:t,to:e}:{from:e,to:t}}#m(){if(this.value==="custom")return this.from&&this.to?this.#p(this.from,this.to):yh("7d");let t=er.has(this.value)?this.value:"7d";return yh(t)}#g(){return this.broadcast==="document"?document:this.broadcast==="self"?this:null}#O(){return this.broadcast==="document"?document.documentElement:this.broadcast==="self"?this:null}#y(){let t=this.#O();t&&(this.broadcast==="document"&&!this.#a||(this.from?t.setAttribute("data-range-from",this.from):t.removeAttribute("data-range-from"),this.to?t.setAttribute("data-range-to",this.to):t.removeAttribute("data-range-to")))}#b(){if(tr.size>0&&!tr.has(this)){LE||(LE=!0,console.warn('[date-range-selector-ui] multiple instances with broadcast="document" on the same page; only the first writes data-range-from / data-range-to to <html>. Use broadcast="self" for secondary instances. See SPEC-019 \xA76 nesting rules.')),this.#a=!1,tr.add(this);return}tr.add(this),this.#a=!0}#x(){if(tr.has(this)&&(tr.delete(this),this.#a)){document.documentElement.removeAttribute("data-range-from"),document.documentElement.removeAttribute("data-range-to"),this.#a=!1;let t=tr.values().next().value;t&&(t.#a=!0,t.#y())}}#v(){this.#s&&(typeof this.#s.openPopover=="function"?this.#s.openPopover():this.#s.open=!0)}};customElements.get("date-range-selector-ui")||customElements.define("date-range-selector-ui",Rd);P();var Id=class extends v{static properties={open:{type:Boolean,default:!1,reflect:!0},title:{type:String,default:"",reflect:!0},description:{type:String,default:"",reflect:!0},confirmText:{type:String,default:"Confirm",reflect:!0,attribute:"confirm-text"},cancelText:{type:String,default:"Cancel",reflect:!0,attribute:"cancel-text"},confirmVariant:{type:String,default:"primary",reflect:!0,attribute:"confirm-variant"},size:{type:String,default:"sm",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},icon:{type:String,default:"",reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=null;#c=[];#d=!1;#u="";#f="";#p=!1;connected(){this.#d||(this.#u=`${this.#y}-title`,this.#f=`${this.#y}-desc`,this.#m(),this.#g(),this.#d=!0)}disconnected(){for(let t of this.#c)try{t()}catch{}this.#c.length=0}show(){this.open=!0}hide(){this.open=!1}render(){if(!this.#d)return;this.#t&&(this.#t.setAttribute("size",this.size||"sm"),this.#t.open=!!this.open),this.#s&&(this.#s.id=this.#u,this.#s.textContent=this.title||""),this.#n&&(this.#n.id=this.#f,this.#n.textContent=this.description||"",this.#n.hidden=!this.description),this.#i&&(this.querySelector(':scope > [slot="icon"]')?this.#i.hidden=!0:this.icon?(this.#i.hidden=!1,this.#i.setAttribute("name",this.icon)):this.#i.hidden=!0);let t=this.#t?.querySelector(':scope > [slot="dialog"]');t&&(t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),this.title?t.setAttribute("aria-labelledby",this.#u):t.removeAttribute("aria-labelledby"),this.description?t.setAttribute("aria-describedby",this.#f):t.removeAttribute("aria-describedby")),this.#l&&(this.#l.setAttribute("text",this.cancelText||"Cancel"),this.loading?this.#l.setAttribute("disabled",""):this.#l.removeAttribute("disabled")),this.#h&&(this.#h.setAttribute("text",this.confirmText||"Confirm"),this.#h.setAttribute("variant",this.confirmVariant==="ghost"?"ghost":"primary"),this.loading?(this.#h.setAttribute("disabled",""),this.#h.setAttribute("icon","spinner")):(this.#h.removeAttribute("disabled"),this.#h.removeAttribute("icon"))),this.open&&this.#l&&!this.loading&&this.#O()}#m(){let t=document.createElement("modal-ui");t.setAttribute("size",this.size||"sm");let e=document.createElement("header");e.setAttribute("slot","header");let i=document.createElement("icon-ui");i.setAttribute("slot","icon"),i.hidden=!0,e.appendChild(i),this.#i=i;let r=document.createElement("text-ui");r.setAttribute("slot","heading"),r.id=this.#u,this.title&&(r.textContent=this.title),e.appendChild(r),this.#s=r,this.#e=e;let n=document.createElement("section");n.setAttribute("slot","body");let o=document.createElement("text-ui");o.setAttribute("slot","description"),o.id=this.#f,this.description?o.textContent=this.description:o.hidden=!0,n.appendChild(o),this.#n=o;let a=document.createElement("div");a.setAttribute("data-extra",""),n.appendChild(a),this.#a=a,this.#r=n;let l=document.createElement("footer");l.setAttribute("slot","footer");let h=document.createElement("button-ui");h.setAttribute("slot","action"),h.setAttribute("data-confirm-action","cancel"),h.setAttribute("variant","ghost"),h.setAttribute("text",this.cancelText||"Cancel"),l.appendChild(h),this.#l=h;let c=document.createElement("button-ui");c.setAttribute("slot","action"),c.setAttribute("data-confirm-action","confirm"),c.setAttribute("variant",this.confirmVariant==="ghost"?"ghost":"primary"),c.setAttribute("text",this.confirmText||"Confirm"),l.appendChild(c),this.#h=c,this.#o=l;let u=[...this.children];for(let d of u){let f=d.getAttribute("slot");f==="icon"?e.appendChild(d):f||a.appendChild(d)}t.appendChild(e),t.appendChild(n),t.appendChild(l),this.appendChild(t),this.#t=t}#g(){let t=r=>{this.loading||(r.stopPropagation(),this.#p=!0,this.dispatchEvent(new CustomEvent("confirm",{bubbles:!0,detail:{}})))};this.#h.addEventListener("press",t),this.#c.push(()=>this.#h.removeEventListener("press",t));let e=r=>{this.loading||(r.stopPropagation(),this.#p=!0,this.dispatchEvent(new CustomEvent("cancel",{bubbles:!0,detail:{}})),this.open=!1)};this.#l.addEventListener("press",e),this.#c.push(()=>this.#l.removeEventListener("press",e));let i=r=>{r.stopPropagation(),this.open=!1,this.#p||this.dispatchEvent(new CustomEvent("cancel",{bubbles:!0,detail:{}})),this.#p=!1,this.dispatchEvent(new CustomEvent("close",{bubbles:!0,detail:{}}))};this.#t.addEventListener("close",i),this.#c.push(()=>this.#t.removeEventListener("close",i))}#O(){let t=()=>{if(!(!this.open||!this.#l||this.loading))try{this.#l.focus()}catch{}};typeof requestAnimationFrame=="function"?requestAnimationFrame(t):queueMicrotask(t)}get#y(){return this.id||"confirm-dialog"}};customElements.get("confirm-dialog-ui")||customElements.define("confirm-dialog-ui",Id);P();Pt();var RD=new Set(["active","trialing","past_due","canceled","paused"]),ID={active:"success",trialing:"info",past_due:"danger",canceled:"muted",paused:"warning"},DD={active:"Active",trialing:"Trialing",past_due:"Past due",canceled:"Canceled",paused:"Paused"},qD={update:"update-card",retry:"retry"};function DE(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",maximumFractionDigits:Number.isInteger(i)?0:2}).format(i)}catch{return`${t||"$"}${i}`}}function ND(s,t){if(!s)return"";try{let e=s instanceof Date?s:new Date(s);return Number.isNaN(e.getTime())?String(s):new Intl.DateTimeFormat(t||void 0,{year:"numeric",month:"short",day:"2-digit"}).format(e)}catch{return String(s)}}var Ea=class extends v{static get properties(){return{account:{type:Object,default:null},variant:{type:String,default:"full",reflect:!0},currency:{type:String,default:"USD",reflect:!0},locale:{type:String,default:""},loading:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=null;#c=null;#d=null;#u=null;#f=null;#p=null;#m=null;#g=null;#O=null;#y=null;#b=null;#x=null;#v=null;#S=null;#w="";#k=!1;#A=0;async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#A;this.loading=!0,this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#A)return;this.loading=!1;let n=r&&typeof r=="object"&&r.account?r.account:r;this.account=n,this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{account:n}}))}catch(i){if(e!==this.#A)return;this.loading=!1,this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){this.setAttribute("role","region"),this.#t||(this.#E(),this.#R(),this.#Z(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),this.#t&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}render(){if(!this.#t)return;let t=this.account,e=!t&&!this.getAttribute("data-stream-src");e?this.setAttribute("empty",""):this.removeAttribute("empty"),this.loading?this.setAttribute("aria-busy","true"):this.removeAttribute("aria-busy");let i=t?.status||"";if(i==="past_due"?this.setAttribute("past-due",""):this.removeAttribute("past-due"),i==="trialing"?this.setAttribute("trial",""):this.removeAttribute("trial"),i&&!RD.has(i)&&!this.#k&&(this.#k=!0,console.warn(`[billing-overview-ui] unknown account.status "${i}" \u2014 rendering default chrome.`)),e){this.#T(null),this.#P(null);return}if(!t){this.#T(null);return}this.#T(t),this.#C(t),this.#I(t),this.#L(t),this.#M(t),this.#Q(t),this.#P(t)}#E(){let t=this.querySelector(':scope > script[type="application/json"][data-account]');if(t)try{let e=JSON.parse(t.textContent||"{}");if(e&&typeof e=="object"){let i=e.account&&typeof e.account=="object"?e.account:e;this.account=i}}catch(e){console.warn("[billing-overview-ui] failed to parse <script data-account> JSON:",e?.message)}finally{t.remove()}}#$(t,e){let i=this.querySelectorAll(`:scope > [slot="${t}"]`);for(let r of i)e.appendChild(r)}#R(){this.#w=`bo-h-${Math.random().toString(36).slice(2,8)}`;let t=document.createElement("card-ui");t.setAttribute("data-header","");let e=document.createElement("header"),i=document.createElement("span");i.setAttribute("slot","icon");let r=document.createElement("avatar-ui");r.setAttribute("icon","credit-card"),i.appendChild(r);let n=document.createElement("span");n.setAttribute("slot","heading");let o=document.createElement("h2");o.id=this.#w,o.setAttribute("data-billing-plan-name",""),n.appendChild(o);let a=document.createElement("tag-ui");a.setAttribute("data-billing-status",""),a.setAttribute("size","md"),n.appendChild(a);let l=document.createElement("span");l.setAttribute("slot","description");let h=document.createElement("div");h.setAttribute("data-billing-plan-meta",""),l.appendChild(h);let c=document.createElement("span");c.setAttribute("slot","action");let u=document.createElement("div");u.setAttribute("data-header-actions",""),c.appendChild(u),e.append(i,n,l,c),t.appendChild(e),this.appendChild(t),this.#i=t,this.#s=o,this.#r=h,this.#n=a,this.#a=u,this.#$("header-actions",u);let d=document.createElement("section");d.setAttribute("data-kpis","");let f=(yt,wt,vt)=>{let $t=document.createElement("card-ui");$t.setAttribute("data-kpi-card",yt);let Mt=document.createElement("section"),Ht=document.createElement("stat-ui");return Ht.setAttribute("data-kpi",yt),Ht.setAttribute("label",wt),Ht.setAttribute("value","\u2014"),Ht.setAttribute("icon",vt),Mt.appendChild(Ht),$t.appendChild(Mt),[$t,Ht]},[p,m]=f("spend","Current month","credit-card"),[b,g]=f("seats","Seats","users-three"),[x,S]=f("next-invoice","Next invoice","calendar");d.append(p,b,x),this.appendChild(d),this.#o=d,this.#l=m,this.#h=g,this.#c=S;let w=document.createElement("section");w.setAttribute("data-dunning",""),w.setAttribute("hidden","");let k=document.createElement("alert-ui");k.setAttribute("pattern","dunning"),k.setAttribute("variant","danger"),w.appendChild(k),this.appendChild(w),this.#d=w,this.#u=k;let A=document.createElement("section");A.setAttribute("data-plan-picker","");let E=document.createElement("h3");E.setAttribute("data-section-heading",""),E.textContent="Plan";let $=document.createElement("plan-picker-ui");$.setAttribute("data-billing-plan-picker",""),$.setAttribute("name","billing-overview-plan"),A.append(E,$),this.appendChild(A),this.#f=A,this.#p=E,this.#m=$;let L=document.createElement("div");L.setAttribute("data-before-plan-picker",""),A.insertBefore(L,E),this.#$("before-plan-picker",L);let T=document.createElement("section");T.setAttribute("data-payment-methods","");let q=document.createElement("h3");q.setAttribute("data-section-heading",""),q.textContent="Payment methods";let I=document.createElement("payment-method-list-ui");I.setAttribute("data-billing-payment-methods",""),I.setAttribute("name","billing-overview-payment-method"),T.append(q,I),this.appendChild(T),this.#g=T,this.#O=q,this.#y=I;let z=document.createElement("section");z.setAttribute("data-invoice-history","");let V=document.createElement("h3");V.setAttribute("data-section-heading",""),V.textContent="Invoice history";let U=document.createElement("invoice-history-ui");U.setAttribute("data-billing-invoice-history",""),z.append(V,U),this.appendChild(z),this.#b=z,this.#x=V,this.#v=U;let tt=document.createElement("div");tt.setAttribute("data-after-invoice-history",""),z.appendChild(tt),this.#$("after-invoice-history",tt);let nt=document.createElement("div");nt.setAttribute("data-empty","");let ft=document.createElement("p");ft.setAttribute("data-empty-heading",""),ft.textContent="No billing account loaded";let lt=document.createElement("p");lt.setAttribute("data-empty-description",""),lt.textContent="Pass an `account` snapshot or `data-stream-src` to render the dashboard.",nt.append(ft,lt),this.appendChild(nt),this.#S=nt,this.#$("empty",this)}#T(t){if(!this.#s||!this.#n||!this.#r)return;let e=t?.plan||null,i=e?.name?String(e.name):"Billing overview";this.#s.textContent!==i&&(this.#s.textContent=i);let r=this.#r;if(r.replaceChildren(),e&&Number.isFinite(e.price)){let o=e.currency||this.currency||"USD",a=this.#N(),l=e.cycle==="year"?"/yr":"/mo",h=document.createElement("span");h.setAttribute("data-plan-price",""),h.textContent=`${DE(e.price,o,a)} ${l}`,r.appendChild(h)}if(t?.billingCycle&&t.billingCycle!==e?.cycle){let o=document.createElement("span");o.setAttribute("data-plan-billing-cycle",""),o.textContent=`Billed ${t.billingCycle}ly`,r.appendChild(o)}let n=t?.status||"";if(!n)this.#n.setAttribute("hidden","");else{this.#n.removeAttribute("hidden");let o=ID[n]||"default",a=DD[n]||n;this.#n.getAttribute("variant")!==o&&this.#n.setAttribute("variant",o),this.#n.getAttribute("text")!==a&&this.#n.setAttribute("text",a),this.#n.setAttribute("aria-label",`Account status: ${a}`)}}#C(t){if(!this.#l||!this.#h||!this.#c)return;let e=t?.plan?.currency||this.currency||"USD",i=this.#N();if(Number.isFinite(t?.currentSpend)?this.#l.setAttribute("value",DE(t.currentSpend,e,i)):this.#l.setAttribute("value","\u2014"),t?.seats&&Number.isFinite(t.seats.used)){let r=t.seats.used,n=Number.isFinite(t.seats.total)?t.seats.total:null;this.#h.setAttribute("value",n!=null?`${r} / ${n}`:String(r))}else this.#h.setAttribute("value","\u2014");t?.nextInvoiceDate?this.#c.setAttribute("value",ND(t.nextInvoiceDate,i)):this.#c.setAttribute("value","\u2014");for(let r of[this.#l,this.#h,this.#c])this.loading?r.setAttribute("loading",""):r.removeAttribute("loading")}#I(t){if(!this.#d||!this.#u)return;let e=t?.dunning||null;if(!(t?.status==="past_due")||!e){this.#d.setAttribute("hidden","");return}this.#d.removeAttribute("hidden");let r=Number.isFinite(e.amount)?e.amount:null,n=e.currency||t?.plan?.currency||this.currency||"USD";if(r!=null?this.#u.setAttribute("amount",String(r)):this.#u.removeAttribute("amount"),this.#u.setAttribute("currency",n),e.dueAt&&this.#u.setAttribute("due-at",String(e.dueAt)),e.cardLast4&&this.#u.setAttribute("card-last4",String(e.cardLast4)),e.reason&&this.#u.setAttribute("reason",String(e.reason)),!this.#u.querySelector(':scope > [slot="actions"]')){let o=document.createElement("button-ui");o.setAttribute("slot","actions"),o.setAttribute("data-dunning-action","update"),o.setAttribute("variant","primary"),o.setAttribute("text","Update payment method"),this.#u.appendChild(o);let a=document.createElement("button-ui");a.setAttribute("slot","actions"),a.setAttribute("data-dunning-action","retry"),a.setAttribute("variant","outline"),a.setAttribute("text","Retry charge"),this.#u.appendChild(a)}}#L(t){if(!this.#f||!this.#m)return;let e=this.variant==="full",i=Array.isArray(t?.plans)&&t.plans.length>0;if(!(e&&i)){this.#f.setAttribute("hidden","");return}this.#f.removeAttribute("hidden"),this.#m.plans=t.plans,t?.plan?.id&&this.#m.setAttribute("current",String(t.plan.id)),this.loading?this.#m.setAttribute("loading",""):this.#m.removeAttribute("loading")}#M(t){if(!this.#y)return;let e=Array.isArray(t?.paymentMethods)?t.paymentMethods:[];this.#y.methods=e,this.loading?this.#y.setAttribute("loading",""):this.#y.removeAttribute("loading")}#Q(t){if(!this.#v)return;let e=Array.isArray(t?.invoices)?t.invoices:[];this.#v.invoices=e;let i=t?.plan?.currency||this.currency||"USD";this.#v.setAttribute("currency",i),this.loading?this.#v.setAttribute("loading",""):this.#v.removeAttribute("loading")}#P(t){this.#w&&this.setAttribute("aria-labelledby",this.#w),!t&&!this.hasAttribute("aria-label")?this.setAttribute("aria-label","No billing account loaded"):t&&this.removeAttribute("aria-label")}#N(){return this.locale?this.locale:typeof document<"u"&&document.documentElement.lang||""}#Z(){let t=u=>{let d=u.target?.closest?.("[data-account-action]");if(!d||!this.contains(d))return;let f=d.getAttribute("data-account-action")||"";f&&(u.stopPropagation(),this.#D(f,"header",{target:d}))};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=u=>{let d=u.detail?.action||"",f=qD[d]||d||"dunning";this.#D(f,"alert-dunning",u.detail)};this.addEventListener("dunning-action",e),this.#e.push(()=>this.removeEventListener("dunning-action",e));let i=u=>{let d=u.detail?.value??u.detail?.plan?.id??"";this.#D("select-plan","plan-picker",{planId:d,...u.detail})};this.addEventListener("plan-change",i),this.#e.push(()=>this.removeEventListener("plan-change",i));let r=u=>{!this.#m||!this.#m.contains(u.target)&&u.target!==this.#m||this.#D("select-plan","plan-picker",u.detail)};this.addEventListener("change",r),this.#e.push(()=>this.removeEventListener("change",r));let n=()=>{this.#D("add-payment-method","payment-method-list",null)};this.addEventListener("add",n),this.#e.push(()=>this.removeEventListener("add",n));let o=u=>{this.#D("remove-payment-method","payment-method-list",u.detail)};this.addEventListener("remove",o),this.#e.push(()=>this.removeEventListener("remove",o));let a=u=>{this.#D("set-default-payment-method","payment-method-list",u.detail)};this.addEventListener("select",a),this.#e.push(()=>this.removeEventListener("select",a));let l=u=>{this.#D("view-invoice","invoice-history",u.detail)};this.addEventListener("invoice-row-click",l),this.#e.push(()=>this.removeEventListener("invoice-row-click",l));let h=u=>{this.#D("download-invoice","invoice-history",u.detail)};this.addEventListener("invoice-export",h),this.#e.push(()=>this.removeEventListener("invoice-export",h));let c=u=>{let d=u.detail?.action||"invoice";this.#D(d,"invoice-history",u.detail)};this.addEventListener("invoice-action",c),this.#e.push(()=>this.removeEventListener("invoice-action",c))}#D(t,e,i){this.dispatchEvent(new CustomEvent("account-action",{bubbles:!0,detail:{action:t,source:e,payload:i||null}}))}};customElements.get("billing-overview-ui")||customElements.define("billing-overview-ui",Ea);P();Pt();var XD=new Set(["draft","open","paid","past-due","void"]),BD={paid:"success",open:"info","past-due":"danger",void:"muted",draft:"neutral"},qE={paid:"Paid",open:"Open","past-due":"Past due",void:"Void",draft:"Draft"},ZD=[{value:"",label:"All"},{value:"paid",label:"Paid"},{value:"open",label:"Open"},{value:"past-due",label:"Past due"},{value:"void",label:"Void"},{value:"draft",label:"Draft"}],NE=["Number","Issued","Due","Amount","Currency","Status"];function XE(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",maximumFractionDigits:Number.isInteger(i)?0:2}).format(i)}catch{return`${t||"$"}${i}`}}function BE(s,t){if(!s)return"";try{let e=s instanceof Date?s:new Date(s);return Number.isNaN(e.getTime())?String(s):new Intl.DateTimeFormat(t||void 0,{year:"numeric",month:"short",day:"2-digit"}).format(e)}catch{return String(s)}}function ZE(s,t){return(s||"/invoices/{number}").replace("{number}",encodeURIComponent(t?.number??"")).replace("{id}",encodeURIComponent(t?.id??""))}function Be(s){let t=String(s??"");return t.includes(",")||t.includes('"')||t.includes(`
456
- `)?'"'+t.replace(/"/g,'""')+'"':t}var Ca=class extends v{static properties={invoices:{type:Array,default:[]},currency:{type:String,default:"USD",reflect:!0},density:{type:String,default:"standard",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},selectable:{type:Boolean,default:!1,reflect:!0},hrefPattern:{type:String,default:"/invoices/{number}",reflect:!0,attribute:"href-pattern"},paginate:{type:Number,default:25,reflect:!0},exportable:{type:Boolean,default:!0,reflect:!0},locale:{type:String,default:""},filter:{type:String,default:"",reflect:!0}};static template=()=>null;static requiredIcons=["download-simple","receipt","magnifying-glass"];#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=!1;#c=0;#d=!1;setFilter(t){let e=t||"";return e&&!XD.has(e)?!1:H(()=>{if(this.filter===e)return!0;let i=this.filter;return this.filter=e,this.dispatchEvent(new CustomEvent("invoice-filter-change",{bubbles:!0,detail:{filter:e,previous:i}})),!0})}exportCsv(){let t=this.#m(),e=[NE.join(",")];for(let r of t){let n=[Be(r.number??""),Be(r.issuedAt??""),Be(r.dueAt??""),Be(Number.isFinite(r.amount)?r.amount:""),Be(r.currency||this.currency||"USD"),Be(r.status??"")];e.push(n.join(","))}let i=e.join(`\r
457
- `);return new Blob([i],{type:"text/csv;charset=utf-8;"})}getSelected(){if(!this.#o)return[];let t=this.#o.selected||[],e=this.#m();return t.map(i=>e[i]).filter(Boolean)}async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#c;this.setAttribute("loading",""),this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#c)return;this.removeAttribute("loading");let n=Array.isArray(r)?r:Array.isArray(r?.invoices)?r.invoices:[];this.invoices=n,this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{count:n.length}}))}catch(i){if(e!==this.#c)return;this.removeAttribute("loading"),this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){super.connected?.(),this.setAttribute("role","region"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Invoice history"),this.#t||(this.#u(),this.#f(),this.#O(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){super.disconnected?.();for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#h)&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}render(){if(!this.#t)return;(Array.isArray(this.invoices)?this.invoices:[]).length===0&&!this.loading?this.setAttribute("empty",""):this.removeAttribute("empty"),this.#p(),this.#o&&(this.#o.columns=this.#g(),this.#o.data=this.#m(),this.#o.density!==this.density&&(this.#o.density=this.density),!!this.#o.loading!=!!this.loading&&(this.#o.loading=!!this.loading),Number(this.#o.paginate||0)!==Number(this.paginate||0)&&(this.#o.paginate=Number(this.paginate||0)),!!this.#o.selectable!=!!this.selectable&&(this.#o.selectable=!!this.selectable)),this.#s&&this.#s.setAttribute("count",String(this.#m().length)),this.#n&&(this.#n.hidden=!this.exportable)}#u(){let t=this.querySelector(':scope > script[type="application/json"][data-invoices]');if(t)try{let e=JSON.parse(t.textContent||"[]");Array.isArray(e)&&(this.invoices=e)}catch(e){console.warn("[invoice-history-ui] failed to parse <script data-invoices> JSON:",e?.message)}finally{t.remove()}}#f(){let t=document.createElement("div");t.setAttribute("data-toolbar",""),this.appendChild(t),this.#i=t;let e=this.querySelector(':scope > [slot="toolbar"]');if(e)t.appendChild(e);else{let n=document.createElement("table-toolbar-ui");n.setAttribute("data-default-toolbar",""),n.setAttribute("text","Invoices");let o=document.createElement("div");o.setAttribute("data-invoice-filter",""),o.setAttribute("role","group"),o.setAttribute("aria-label","Filter invoices by status"),o.setAttribute("slot","actions"),n.appendChild(o);let a=document.createElement("button-ui");a.setAttribute("data-export",""),a.setAttribute("slot","actions"),a.setAttribute("variant","outline"),a.setAttribute("size","sm"),a.setAttribute("text","Export CSV"),a.setAttribute("icon","download-simple"),n.appendChild(a),t.appendChild(n),this.#s=n,this.#r=o,this.#n=a}let i=document.createElement("div");i.setAttribute("data-table-host",""),this.appendChild(i),this.#a=i;let r=document.createElement("table-ui");if(r.id=this.id?`${this.id}__table`:`invoice-history-${Math.random().toString(36).slice(2,8)}`,r.setAttribute("data-invoice-table",""),r.setAttribute("sortable",""),i.appendChild(r),this.#o=r,this.#s&&this.#s.setAttribute("for",r.id),!this.querySelector(':scope > [slot="empty"]')){let n=document.createElement("empty-state-ui");n.setAttribute("data-empty",""),n.setAttribute("icon","receipt"),n.setAttribute("heading","No invoices yet"),n.setAttribute("description","Invoices will appear here once issued."),this.appendChild(n),this.#l=n}}#p(){if(!this.#r)return;if(this.#r.children.length===0)for(let e of ZD){let i=document.createElement("button-ui");i.setAttribute("data-filter-chip",""),i.setAttribute("data-filter-value",e.value),i.setAttribute("size","sm"),i.setAttribute("text",e.label),this.#r.appendChild(i)}let t=this.filter||"";for(let e of this.#r.querySelectorAll("[data-filter-chip]"))(e.getAttribute("data-filter-value")||"")===t?(e.setAttribute("variant","primary"),e.setAttribute("aria-pressed","true")):(e.setAttribute("variant","ghost"),e.setAttribute("aria-pressed","false"))}#m(){let t=Array.isArray(this.invoices)?this.invoices:[],e=this.filter||"";return e?t.filter(i=>(i?.status||"")===e):t}#g(){let t=this.locale||typeof document<"u"&&document.documentElement?.lang||"",e=this.currency||"USD";return[{key:"number",label:"Invoice",sortable:!0,wrap:!1},{key:"issuedAt",label:"Issued",sortable:!0,format:i=>BE(i,t)},{key:"dueAt",label:"Due",sortable:!0,format:i=>BE(i,t)},{key:"amount",label:"Amount",sortable:!0,align:"end",render:(i,r,n)=>{let o=r?.currency||e,a=document.createElement("span");return a.setAttribute("data-invoice-amount",""),a.textContent=XE(i,o,t),n.dataset.align="end",a},format:(i,r)=>XE(i,r?.currency||e,t)},{key:"status",label:"Status",sortable:!0,render:i=>{let r=String(i||"").toLowerCase(),n=BD[r]||"neutral",o=qE[r]||(i?String(i):"\u2014"),a=document.createElement("badge-ui");return a.setAttribute("data-invoice-status",""),a.setAttribute("variant",n),a.setAttribute("text",o),a.setAttribute("aria-label",o),a},format:i=>qE[String(i||"").toLowerCase()]||(i?String(i):"")},{key:"actions",label:"",sortable:!1,align:"end",accessor:i=>i,render:(i,r)=>{let n=document.createElement("span");n.setAttribute("data-invoice-actions","");let o=document.createElement("button-ui");o.setAttribute("data-invoice-action","view"),o.setAttribute("data-invoice-id",String(r?.id??r?.number??"")),o.setAttribute("size","sm"),o.setAttribute("variant","ghost"),o.setAttribute("text","View"),n.appendChild(o);let a=document.createElement("button-ui");return a.setAttribute("data-invoice-action","download"),a.setAttribute("data-invoice-id",String(r?.id??r?.number??"")),a.setAttribute("size","sm"),a.setAttribute("variant","ghost"),a.setAttribute("icon","download-simple"),a.setAttribute("aria-label",`Download invoice ${r?.number??""}`),n.appendChild(a),n}}]}#O(){let t=o=>{let a=o.target?.closest?.("[data-filter-chip]");if(!a||!this.#r?.contains(a))return;o.stopPropagation();let l=a.getAttribute("data-filter-value")||"";this.setFilter(l)};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=o=>{let a=o?.detail;if(!a||a.key==="actions")return;let l=a.row;if(!l)return;let h=ZE(this.hrefPattern,l),c=new CustomEvent("invoice-row-click",{bubbles:!0,cancelable:!0,detail:{invoice:l,href:h}});if(this.dispatchEvent(c)&&typeof window<"u"&&window.location?.assign)try{window.location.assign(h)}catch{}};this.addEventListener("cell-click",e),this.#e.push(()=>this.removeEventListener("cell-click",e));let i=o=>{let a=o.target?.closest?.("button-ui[data-invoice-action]");if(!a||!this.#a?.contains(a))return;o.stopPropagation();let l=a.getAttribute("data-invoice-action"),h=a.getAttribute("data-invoice-id")||"",c=(this.invoices||[]).find(u=>String(u?.id??u?.number??"")===h);if(c){if(l==="view"){let u=ZE(this.hrefPattern,c),d=new CustomEvent("invoice-row-click",{bubbles:!0,cancelable:!0,detail:{invoice:c,href:u}});if(this.dispatchEvent(d)&&typeof window<"u"&&window.location?.assign)try{window.location.assign(u)}catch{}}else if(l==="download"){let u=this.#y(c);this.dispatchEvent(new CustomEvent("invoice-export",{bubbles:!0,cancelable:!0,detail:{blob:u,rowCount:1,invoice:c}}))}}};this.addEventListener("press",i),this.addEventListener("click",i),this.#e.push(()=>this.removeEventListener("press",i)),this.#e.push(()=>this.removeEventListener("click",i));let r=o=>{let a=o.target?.closest?.("button-ui[data-export]");if(!a||!this.#i?.contains(a))return;o.stopPropagation();let l=this.exportCsv(),h=new CustomEvent("invoice-export",{bubbles:!0,cancelable:!0,detail:{blob:l,rowCount:this.#m().length}});if(this.dispatchEvent(h)&&typeof document<"u"&&typeof URL<"u")try{let u=URL.createObjectURL(l),d=document.createElement("a");d.href=u,d.download="invoices.csv",document.body.appendChild(d),d.click(),d.remove(),setTimeout(()=>URL.revokeObjectURL(u),0)}catch{}};this.addEventListener("press",r),this.addEventListener("click",r),this.#e.push(()=>this.removeEventListener("press",r)),this.#e.push(()=>this.removeEventListener("click",r));let n=o=>{if(o.target!==this.#o)return;let a=this.getSelected();this.dispatchEvent(new CustomEvent("invoice-selection-change",{bubbles:!0,detail:{selected:a}}))};this.addEventListener("select",n),this.#e.push(()=>this.removeEventListener("select",n))}#y(t){let e=[NE.join(","),[Be(t.number??""),Be(t.issuedAt??""),Be(t.dueAt??""),Be(Number.isFinite(t.amount)?t.amount:""),Be(t.currency||this.currency||"USD"),Be(t.status??"")].join(",")];return new Blob([e.join(`\r
458
- `)],{type:"text/csv;charset=utf-8;"})}};customElements.get("invoice-history-ui")||customElements.define("invoice-history-ui",Ca);P();Pt();var zD=new Set(["draft","open","paid","past-due","void"]),_D={draft:"default",open:"info",paid:"success","past-due":"warning",void:"default"},VD={draft:"Draft",open:"Open",paid:"Paid","past-due":"Past due",void:"Void"};function Dd(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(i)}catch{return`${t||"$"}${i.toFixed(2)}`}}function zE(s,t){if(!s)return"";try{let e=new Date(s);return Number.isNaN(e.getTime())?String(s):new Intl.DateTimeFormat(t||void 0,{year:"numeric",month:"short",day:"numeric"}).format(e)}catch{return String(s)}}var $a=class extends v{static get properties(){return{invoice:{type:Object,default:null},status:{type:String,default:"draft",reflect:!0},currency:{type:String,default:"USD",reflect:!0},density:{type:String,default:"standard",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},printable:{type:Boolean,default:!0,reflect:!0},locale:{type:String,default:""}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=null;#c=null;#d=null;#u=null;#f=null;#p=null;#m="";#g=!1;#O=!1;#y=0;#b="";print(){if(typeof globalThis.window?.print=="function"){try{globalThis.window.print()}catch(t){this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"print-unavailable",message:String(t?.message||t)}}))}return}this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"print-unavailable"}}))}async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#y;this.loading=!0,this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#y)return;this.loading=!1;let n=r&&typeof r=="object"&&r.invoice?r.invoice:r;if(this.invoice=n,n?.status){this.#g=!0;try{this.status=String(n.status)}finally{this.#g=!1}}let o=n?.number||"";this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{invoiceNumber:o}})),this.#b=o}catch(i){if(e!==this.#y)return;this.loading=!1,this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){this.setAttribute("role","region"),this.#t||(this.#x(),this.#S(),this.#R(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#g)&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}render(){if(!this.#t)return;let t=this.invoice,e=!t&&!this.getAttribute("data-stream-src");e?this.setAttribute("empty",""):this.removeAttribute("empty"),this.loading?this.setAttribute("aria-busy","true"):this.removeAttribute("aria-busy");let r=(this.hasAttribute("status")?this.getAttribute("status"):"")||t?.status||this.status||"draft";if(zD.has(r)||this.#O||(this.#O=!0,console.warn(`[invoice-detail-ui] unknown status "${r}" \u2014 rendering default badge.`)),e){this.#w(null,r),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","No invoice loaded");return}if(!t){this.#w(null,r);return}this.#w(t,r),this.#k(t),this.#A(t),this.#E(t),this.#$(t)}#x(){let t=this.querySelector(':scope > script[type="application/json"][data-invoice]');if(t)try{let e=JSON.parse(t.textContent||"{}");if(e&&typeof e=="object"){let i=e.invoice&&typeof e.invoice=="object"?e.invoice:e;if(this.invoice=i,i?.status){this.#g=!0;try{this.status=String(i.status)}finally{this.#g=!1}}}}catch(e){console.warn("[invoice-detail-ui] failed to parse <script data-invoice> JSON:",e?.message)}finally{t.remove()}}#v(t,e){let i=this.querySelectorAll(`:scope > [slot="${t}"]`);for(let r of i)e.appendChild(r)}#S(){this.#m=`inv-h-${Math.random().toString(36).slice(2,8)}`;let t=document.createElement("header");t.setAttribute("data-header","");let e=document.createElement("div");e.setAttribute("data-header-title","");let i=document.createElement("h2");i.id=this.#m,i.setAttribute("data-invoice-number",""),e.appendChild(i);let r=document.createElement("tag-ui");r.setAttribute("data-invoice-status",""),r.setAttribute("size","md"),e.appendChild(r);let n=document.createElement("div");n.setAttribute("data-header-meta","");let o=document.createElement("div");o.setAttribute("data-header-actions",""),o.setAttribute("data-invoice-actions",""),t.append(e,n,o),this.appendChild(t),this.#i=t,this.#s=i,this.#r=r,this.#n=n,this.#a=o,this.#v("header-actions",o);let a=document.createElement("section");a.setAttribute("data-parties","");let l=document.createElement("div");l.setAttribute("data-customer","");let h=document.createElement("div");h.setAttribute("data-customer-default",""),l.appendChild(h),this.#l=h;let c=document.createElement("div");c.setAttribute("data-remit-to","");let u=document.createElement("div");u.setAttribute("data-remit-to-default",""),c.appendChild(u),this.#h=u,a.append(l,c),this.appendChild(a),this.#o=a,this.#v("customer-block",l),this.#v("remit-to-block",c);let d=document.createElement("section");d.setAttribute("data-lines","");let f=document.createElement("card-ui");f.setAttribute("data-lines-card",""),f.setAttribute("padding","none");let p=document.createElement("section");p.setAttribute("bleed",""),f.appendChild(p);let m=document.createElement("table-ui");m.setAttribute("data-lines-table",""),m.setAttribute("density",this.density||"standard"),p.appendChild(m),d.appendChild(f),this.appendChild(d),this.#c=d,this.#d=m;let b=document.createElement("section");b.setAttribute("data-totals",""),this.appendChild(b),this.#u=b;let g=document.createElement("footer");g.setAttribute("data-footer","");let x=document.createElement("div");x.setAttribute("data-footer-notes",""),g.appendChild(x),this.appendChild(g),this.#f=g,this.#v("footer",g);let S=document.createElement("empty-state-ui");S.setAttribute("data-empty",""),S.setAttribute("icon","receipt"),S.setAttribute("heading","No invoice loaded"),S.setAttribute("description","Pass an `invoice` record or `data-stream-src` to render an invoice."),this.appendChild(S),this.#p=S}#w(t,e){if(!this.#s||!this.#r||!this.#n)return;let i=t?.number?String(t.number):"";this.#s.textContent!==i&&(this.#s.textContent=i);let r=_D[e]||"default",n=VD[e]||(e?String(e):"Draft");if(this.#r.getAttribute("variant")!==r&&this.#r.setAttribute("variant",r),this.#r.getAttribute("text")!==n&&this.#r.setAttribute("text",n),this.#r.setAttribute("aria-label",`Status: ${n}`),t?this.#r.removeAttribute("hidden"):this.#r.setAttribute("hidden",""),this.#n.replaceChildren(),!t)return;let o=this.locale||(typeof document<"u"?document.documentElement.lang:"");if(t.issuedAt){let a=document.createElement("span");a.setAttribute("data-issued",""),a.textContent=`Issued ${zE(t.issuedAt,o)}`,this.#n.appendChild(a)}if(t.dueAt){let a=document.createElement("span");a.setAttribute("data-due",""),a.textContent=`Due ${zE(t.dueAt,o)}`,this.#n.appendChild(a)}}#k(t){if(!(!this.#l||!this.#h)){if(this.#l.replaceChildren(),t?.customer){let e=document.createElement("div");if(e.setAttribute("data-party-heading",""),e.textContent="Billed to",this.#l.appendChild(e),t.customer.name){let i=document.createElement("div");i.setAttribute("data-party-name",""),i.textContent=String(t.customer.name),this.#l.appendChild(i)}if(t.customer.email){let i=document.createElement("div");i.setAttribute("data-party-email",""),i.textContent=String(t.customer.email),this.#l.appendChild(i)}if(t.customer.address){let i=document.createElement("div");i.setAttribute("data-party-address",""),i.textContent=String(t.customer.address),this.#l.appendChild(i)}}if(this.#h.replaceChildren(),t?.remitTo){let e=document.createElement("div");if(e.setAttribute("data-party-heading",""),e.textContent="Remit to",this.#h.appendChild(e),t.remitTo.name){let i=document.createElement("div");i.setAttribute("data-party-name",""),i.textContent=String(t.remitTo.name),this.#h.appendChild(i)}if(t.remitTo.address){let i=document.createElement("div");i.setAttribute("data-party-address",""),i.textContent=String(t.remitTo.address),this.#h.appendChild(i)}}}}#A(t){if(!this.#d)return;let e=t?.currency||this.currency||"USD",i=this.locale||(typeof document<"u"?document.documentElement.lang:"");this.#d.columns=[{key:"description",label:"Description",flex:1},{key:"qty",label:"Qty",width:80,format:n=>String(n??"")},{key:"unitAmount",label:"Unit",width:120,format:n=>Dd(n,e,i)},{key:"amount",label:"Amount",width:140,format:n=>Dd(n,e,i)}];let r=Array.isArray(t?.lines)?t.lines:[];this.#d.data=r.map((n,o)=>({__row:o,description:n?.description??"",qty:n?.qty??"",unitAmount:n?.unitAmount??0,amount:n?.amount??0})),this.#d.getAttribute("density")!==this.density&&this.#d.setAttribute("density",this.density||"standard")}#E(t){if(!this.#u)return;let e=t?.currency||this.currency||"USD",i=this.locale||(typeof document<"u"?document.documentElement.lang:"");if(this.#u.replaceChildren(),!t)return;let r=[{key:"subtotal",label:"Subtotal",value:t.subtotal},{key:"tax",label:"Tax",value:t.tax}];Number.isFinite(t.discount)&&t.discount>0&&r.push({key:"discount",label:"Discount",value:-Math.abs(t.discount)});for(let n of r){if(!Number.isFinite(n.value))continue;let o=document.createElement("div");o.setAttribute("data-totals-row",""),o.setAttribute("data-totals-key",n.key);let a=document.createElement("span");a.setAttribute("data-totals-label",""),a.textContent=n.label;let l=document.createElement("span");l.setAttribute("data-totals-value",""),l.textContent=Dd(n.value,e,i),o.append(a,l),this.#u.appendChild(o)}if(Number.isFinite(t.total)){let n=document.createElement("div");n.setAttribute("data-totals-row",""),n.setAttribute("data-totals-key","total"),n.setAttribute("data-grand-total","");let o=document.createElement("span");o.setAttribute("data-totals-label",""),o.textContent="Total";let a=document.createElement("span");a.setAttribute("data-totals-value",""),a.textContent=Dd(t.total,e,i),n.append(o,a),this.#u.appendChild(n)}}#$(t){t&&this.#m&&this.setAttribute("aria-labelledby",this.#m)}#R(){let t=i=>{let r=i.target?.closest?.("[data-invoice-action]");if(!r||!this.contains(r))return;let n=r.getAttribute("data-invoice-action")||"";if(!n)return;let o=this.invoice?.number||"";i.stopPropagation(),this.dispatchEvent(new CustomEvent("invoice-action",{bubbles:!0,detail:{action:n,invoiceNumber:o}}))};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=i=>{if(!this.#c)return;let n=(i.composedPath?i.composedPath():[]).find(l=>l?.getAttribute&&l.getAttribute("data-row")!=null);if(!n||!this.#c.contains(n))return;let o=Number(n.getAttribute("data-row")),a=Array.isArray(this.invoice?.lines)?this.invoice.lines[o]:null;!Number.isFinite(o)||a==null||this.dispatchEvent(new CustomEvent("line-item-click",{bubbles:!0,detail:{index:o,lineItem:a}}))};this.addEventListener("click",e),this.#e.push(()=>this.removeEventListener("click",e))}};customElements.get("invoice-detail-ui")||customElements.define("invoice-detail-ui",$a);Pt();var jD=[{brand:"amex",re:/^3[47]/},{brand:"visa",re:/^4/},{brand:"mastercard",re:/^(5[1-5]|2[2-7])/},{brand:"discover",re:/^6(011|5)/}];function qd(s){if(!s)return"unknown";for(let{brand:t,re:e}of jD)if(e.test(s))return t;return"unknown"}function Nd(s){return String(s||"").replace(/\D+/g,"").slice(0,19)}function iK(s,t){return s?t==="amex"?s.replace(/^(\d{0,4})(\d{0,6})(\d{0,5}).*$/,(e,i,r,n)=>[i,r,n].filter(Boolean).join(" ")):s.match(/.{1,4}/g)?.join(" ")??"":""}function _E(s){if(!s||s.length<12)return!1;let t=0,e=!1;for(let i=s.length-1;i>=0;i--){let r=s.charCodeAt(i)-48;if(r<0||r>9)return!1;e&&(r*=2,r>9&&(r-=9)),t+=r,e=!e}return t%10===0}function VE(s){if(!s)return null;let t=String(s).replace(/\s+/g,"").match(/^(\d{1,2})\/(\d{2}|\d{4})$/);if(!t)return null;let e=Number(t[1]),i=Number(t[2]);return i<100&&(i+=2e3),!Number.isFinite(e)||!Number.isFinite(i)?null:{month:e,year:i}}function jE(s){let t=VE(s);if(!t)return"expiry-format";let{month:e,year:i}=t;if(e<1||e>12)return"expiry-month";let r=new Date,n=r.getFullYear(),o=r.getMonth()+1;return i<n||i===n&&e<o?"expiry-past":i>n+50?"expiry-far":null}function WE(s,t){let e=String(s||"").replace(/\D+/g,""),i=t==="amex"?4:3;return e.length!==i?"cvc-length":null}function WD(s){let t=Math.random().toString(36).slice(2);return`pm_local_${Date.now().toString(36)}_${t}_${String(s).slice(0,4)}`}var FD=["US","CA","GB","DE","FR","AU"],UD={US:"United States",CA:"Canada",GB:"United Kingdom",DE:"Germany",FR:"France",AU:"Australia",JP:"Japan",ES:"Spain",IT:"Italy",NL:"Netherlands",SE:"Sweden",IE:"Ireland",SG:"Singapore",IN:"India",BR:"Brazil",MX:"Mexico"};function YD(s){return UD[s]||s}var Pa=class extends R{static labelDeprecated=!1;static get properties(){return{...R.properties,name:{type:String,default:"paymentMethod",reflect:!0},value:{type:String,default:"",reflect:!0},prefill:{type:String,default:"",attribute:"prefill"},countries:{type:Array,default:[]},defaultCountry:{type:String,default:"US",reflect:!0,attribute:"default-country"},requireBillingAddress:{type:Boolean,default:!1,reflect:!0,attribute:"require-billing-address"},disabled:{type:Boolean,default:!1,reflect:!0},required:{type:Boolean,default:!1,reflect:!0},error:{type:String,default:"",reflect:!0},autofocus:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a={name:null,cardNumber:null,expiry:null,cvc:null,country:null,postalCode:null,addressLine1:null,addressLine2:null};#o={name:null,cardNumber:null,expiry:null,cvc:null,country:null,postalCode:null,addressLine1:null,addressLine2:null};#l="unknown";#h=!1;#c=null;#d=null;#u=!1;async tokenize(){if(this.#u)return Promise.reject(new Error("tokenize-inflight"));this.#u=!0,this.setAttribute("tokenizing","");try{let t=this.#A();if(!t.ok){let r=new Error(t.message);throw r.code=t.code,r.field=t.field,this.dispatchEvent(new CustomEvent("payment-method-error",{bubbles:!0,detail:{message:t.message,code:t.code,field:t.field}})),this.setAttribute("aria-invalid","true"),r}let e=t.detail;this.#h=!0;try{this.value=WD(e.last4)}finally{this.#h=!1}this.syncValue(),this.removeAttribute("aria-invalid");let i={token:this.value,...e};return this.dispatchEvent(new CustomEvent("submit-payment-method",{bubbles:!0,detail:i})),i}finally{this.removeAttribute("tokenizing"),this.#u=!1}}reset(){H(()=>{for(let t of Object.keys(this.#o)){let e=this.#o[t];e&&(e.value="",e.removeAttribute("error"))}this.#o.country&&(this.#o.country.value=this.defaultCountry||"US"),this.#h=!0;try{this.value="",this.error=""}finally{this.#h=!1}this.syncValue(),this.#l="unknown",this.removeAttribute("aria-invalid"),this.removeAttribute("error"),this.#w()})}syncValue(t){this.internals.setFormValue(this.value||""),this.required&&!this.value?this.internals.setValidity({valueMissing:!0},this.getAttribute("data-msg-required")||"Payment method required.",this):this.internals.setValidity({})}connected(){super.connected(),this.setAttribute("role","group"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Payment method form"),this.#t||(this.#f(),this.#g(),this.#t=!0),H(()=>this.render()),this.autofocus&&requestAnimationFrame(()=>{this.#o.name?.focus?.()})}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#h)){if(t==="prefill"&&e!==i)this.render();else if(t==="disabled"&&e!==i)this.#x();else if(t==="error"&&e!==i)this.#v();else if(t==="require-billing-address"&&e!==i)this.#b();else if(t==="default-country"&&e!==i){let r=this.#o.country;r&&!r.value&&(r.value=i||"US")}}}render(){this.#t&&(this.#y(),this.#b(),this.#x(),this.#v(),this.#S(),this.#w())}#f(){let t=document.createElement("alert-ui");t.setAttribute("data-alert",""),t.setAttribute("variant","danger"),t.setAttribute("icon","warning-circle"),t.hidden=!0,this.appendChild(t),this.#i=t;let e=document.createElement("div");e.setAttribute("data-summary",""),e.hidden=!0;let i=document.createElement("icon-ui");i.setAttribute("name","credit-card"),i.setAttribute("aria-hidden","true"),i.setAttribute("data-summary-icon",""),e.appendChild(i);let r=document.createElement("div");r.setAttribute("data-summary-text",""),e.appendChild(r);let n=document.createElement("button-ui");n.setAttribute("data-summary-edit",""),n.setAttribute("variant","ghost"),n.setAttribute("size","sm"),n.setAttribute("text","Edit card"),e.appendChild(n),this.appendChild(e),this.#s=e,this.#r=n;let o=document.createElement("div");o.setAttribute("data-grid",""),this.appendChild(o),this.#n=o,this.#a.name=this.#p("name",{label:"Name on card",required:!0,area:"name",input:{autocomplete:"cc-name",placeholder:"Pat Doe"}}),this.#o.name=this.#a.name.querySelector("input-ui"),this.#a.cardNumber=this.#p("cardNumber",{label:"Card number",required:!0,area:"card",input:{type:"text",inputmode:"numeric",autocomplete:"cc-number",placeholder:"1234 1234 1234 1234",prefix:"credit-card",maxlength:23}}),this.#o.cardNumber=this.#a.cardNumber.querySelector("input-ui");let a=document.createElement("span");a.setAttribute("slot","trailing"),a.setAttribute("data-brand-badge",""),this.#o.cardNumber.appendChild(a),this.#a.expiry=this.#p("expiry",{label:"Expiry",required:!0,area:"expiry",input:{type:"text",inputmode:"numeric",autocomplete:"cc-exp",placeholder:"MM/YY",maxlength:7}}),this.#o.expiry=this.#a.expiry.querySelector("input-ui"),this.#a.cvc=this.#p("cvc",{label:"CVC",required:!0,area:"cvc",input:{type:"text",inputmode:"numeric",autocomplete:"cc-csc",placeholder:"123",maxlength:4}}),this.#o.cvc=this.#a.cvc.querySelector("input-ui"),this.#a.country=this.#p("country",{label:"Country",required:!0,area:"country",kind:"select",input:{autocomplete:"country"},seedOptions:this.#m(),seedValue:this.defaultCountry||"US"}),this.#o.country=this.#a.country.querySelector("select-ui"),this.#a.postalCode=this.#p("postalCode",{label:"Postal code",required:!0,area:"postal",input:{type:"text",inputmode:"text",autocomplete:"postal-code",placeholder:"94105",maxlength:12}}),this.#o.postalCode=this.#a.postalCode.querySelector("input-ui"),this.#a.addressLine1=this.#p("addressLine1",{label:"Address line 1",required:!1,area:"address1",input:{type:"text",autocomplete:"address-line1",placeholder:"123 Main St",maxlength:100}}),this.#o.addressLine1=this.#a.addressLine1.querySelector("input-ui"),this.#a.addressLine1.hidden=!0,this.#a.addressLine2=this.#p("addressLine2",{label:"Address line 2 (optional)",required:!1,area:"address2",input:{type:"text",autocomplete:"address-line2",placeholder:"Apt 4B",maxlength:100}}),this.#o.addressLine2=this.#a.addressLine2.querySelector("input-ui"),this.#a.addressLine2.hidden=!0;let l=document.createElement("div");l.setAttribute("data-legal",""),this.appendChild(l),this.#c=l;for(let h of[...this.children])h!==l&&h.getAttribute&&h.getAttribute("slot")==="legal"&&l.appendChild(h)}#p(t,e){let i=document.createElement("field-ui");i.setAttribute("label",e.label),e.required&&i.setAttribute("required",""),i.setAttribute("data-field",t),i.style.gridArea=e.area;let r;if(e.kind==="select"){if(r=document.createElement("select-ui"),Array.isArray(e.seedOptions))for(let n of e.seedOptions){let o=document.createElement("option");o.value=n.value,o.textContent=n.label,e.seedValue&&n.value===e.seedValue&&o.setAttribute("selected",""),r.appendChild(o)}}else r=document.createElement("input-ui");r.setAttribute("name",t),r.setAttribute("data-control",t),e.required&&r.setAttribute("required","");for(let[n,o]of Object.entries(e.input||{}))o==null||o===""||r.setAttribute(n,String(o));return i.appendChild(r),this.#n.appendChild(i),i}#m(){return(Array.isArray(this.countries)&&this.countries.length>0?this.countries:FD).map(e=>({value:e,label:YD(e)}))}#g(){let t=r=>{if(!this.#o.cardNumber||r.target!==this.#o.cardNumber)return;let n=String(this.#o.cardNumber.value||""),o=Nd(n),a=qd(o);a!==this.#l&&(this.#l=a,this.#w()),this.#O()};this.addEventListener("input",t),this.#e.push(()=>this.removeEventListener("input",t));let e=r=>{r.target!==this&&this.#O()};this.addEventListener("change",e),this.#e.push(()=>this.removeEventListener("change",e));let i=()=>{this.disabled||(this.removeAttribute("prefilled"),this.#s&&(this.#s.hidden=!0),this.#n&&(this.#n.hidden=!1))};this.#r.addEventListener("click",i),this.#r.addEventListener("press",i),this.#e.push(()=>{this.#r.removeEventListener("click",i),this.#r.removeEventListener("press",i)})}#O(){let t=Nd(this.#o.cardNumber?.value),e=qd(t),i=this.#k();this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{valid:i.ok,brand:e}}))}#y(){let t=this.#o.country;if(!t)return;let e=this.#m();Array.isArray(t.options)&&t.options.length===e.length&&t.options.every((r,n)=>r?.value===e[n].value&&r?.label===e[n].label)||(t.options=e),t.value||(t.value=this.defaultCountry||e[0]?.value||"US")}#b(){let t=!!this.requireBillingAddress;this.#a.addressLine1&&(this.#a.addressLine1.hidden=!t),this.#a.addressLine2&&(this.#a.addressLine2.hidden=!t)}#x(){let t=!!this.disabled;for(let e of Object.values(this.#o))e&&(t?e.setAttribute("disabled",""):e.removeAttribute("disabled"))}#v(){if(!this.#i)return;let t=this.error||"";t?(this.#i.setAttribute("text",t),this.#i.hidden=!1,this.setAttribute("aria-invalid","true")):(this.#i.removeAttribute("text"),this.#i.hidden=!0,this.removeAttribute("aria-invalid"))}#S(){if(!this.#s)return;let t=this.#E();if(!t||this.hasAttribute("prefilled-dismissed")){this.#s.hidden=!0,this.#n&&(this.#n.hidden=!1),this.removeAttribute("prefilled");return}let e=this.#s.querySelector(":scope > [data-summary-text]");if(e){let i=(t.brand||"Card").toUpperCase(),r=t.last4||"\u2022\u2022\u2022\u2022",n=t.expMonth&&t.expYear?` \xB7 expires ${String(t.expMonth).padStart(2,"0")}/${String(t.expYear).slice(-2)}`:"";e.textContent=`${i} ending in ${r}${n}`}this.#s.hidden=!1,this.#n&&(this.#n.hidden=!0),this.setAttribute("prefilled","")}#w(){let t=this.#o.cardNumber;if(!t)return;let e=t.querySelector(":scope > [data-brand-badge]");if(!e)return;if(this.#l==="unknown"||!this.#l){e.replaceChildren();return}let i=e.querySelector(":scope > [data-brand]");if(i&&i.getAttribute("data-brand")===this.#l)return;e.replaceChildren();let r=document.createElement("span");r.setAttribute("data-brand",this.#l),r.textContent=this.#l.toUpperCase(),e.appendChild(r)}#k(){let t=Nd(this.#o.cardNumber?.value);return t?_E(t)?jE(this.#o.expiry?.value)?{ok:!1}:WE(this.#o.cvc?.value,qd(t))?{ok:!1}:(this.#o.name?.value||"").trim()?(this.#o.postalCode?.value||"").trim()?{ok:!0}:{ok:!1}:{ok:!1}:{ok:!1}:{ok:!1}}#A(){for(let d of Object.values(this.#o))d?.removeAttribute?.("error");let t=String(this.#o.name?.value||"").trim();if(!t)return this.#o.name?.setAttribute("error","Name on card is required."),{ok:!1,message:"Name on card is required.",code:"validation-failed",field:"name"};let e=this.#o.cardNumber?.value||"",i=Nd(e);if(!i)return this.#o.cardNumber?.setAttribute("error","Card number is required."),{ok:!1,message:"Card number is required.",code:"validation-failed",field:"cardNumber"};if(!_E(i))return this.#o.cardNumber?.setAttribute("error","Card number is invalid."),{ok:!1,message:"Card number is invalid.",code:"card-invalid",field:"cardNumber"};let r=jE(this.#o.expiry?.value||"");if(r){let d=r==="expiry-past"?"Card has expired.":r==="expiry-month"?"Expiry month must be 01-12.":r==="expiry-far"?"Expiry year is too far in the future.":"Expiry must be MM/YY.";return this.#o.expiry?.setAttribute("error",d),{ok:!1,message:d,code:r==="expiry-past"?"expired":"validation-failed",field:"expiry"}}let n=qd(i);if(WE(this.#o.cvc?.value||"",n)){let f=`CVC must be ${n==="amex"?4:3} digits.`;return this.#o.cvc?.setAttribute("error",f),{ok:!1,message:f,code:"cvc-invalid",field:"cvc"}}let a=String(this.#o.country?.value||this.defaultCountry||"US");if(!String(this.#o.postalCode?.value||"").trim())return this.#o.postalCode?.setAttribute("error","Postal code is required."),{ok:!1,message:"Postal code is required.",code:"validation-failed",field:"postalCode"};if(this.requireBillingAddress&&!String(this.#o.addressLine1?.value||"").trim())return this.#o.addressLine1?.setAttribute("error","Address is required."),{ok:!1,message:"Address is required.",code:"validation-failed",field:"addressLine1"};let h=VE(this.#o.expiry.value);return{ok:!0,detail:{last4:i.slice(-4),brand:n,expMonth:h.month,expYear:h.year,name:t,country:a}}}#E(){let t=this.prefill||this.getAttribute("prefill")||"";if(!t)return null;try{let e=JSON.parse(t);return!e||typeof e!="object"?null:e}catch{return null}}};customElements.get("payment-method-form-ui")||customElements.define("payment-method-form-ui",Pa);Pt();var HD=new Set(["visa","mastercard","amex","discover","jcb","unionpay","diners","paypal","apple-pay","google-pay","ach","sepa"]),FE=new Set(["card","bank","wallet"]),UE={paypal:"paypal-logo","apple-pay":"apple-logo",ach:"bank",sepa:"bank"},GD={card:"credit-card",bank:"bank",wallet:"credit-card"},YE={visa:"Visa",mastercard:"Mastercard",amex:"American Express",discover:"Discover",jcb:"JCB",unionpay:"UnionPay",diners:"Diners Club",paypal:"PayPal","apple-pay":"Apple Pay","google-pay":"Google Pay",ach:"Bank account",sepa:"SEPA"};function HE(s){let t=(s?.brand||"").toLowerCase();if(UE[t])return UE[t];let e=(s?.type||"card").toLowerCase();return GD[e]||"credit-card"}function GE(s){let t=(s?.brand||"").toLowerCase();if(YE[t])return YE[t];let e=(s?.type||"card").toLowerCase();return e==="bank"?"Bank account":e==="wallet"?"Wallet":"Card"}function XO(s){let t=(s?.last4||"").trim(),e=(s?.holder||"").trim(),i=GE(s);return(s?.type||"card").toLowerCase()==="bank"&&e?e:t?`${i} \xB7\xB7\xB7\xB7 ${t}`:e?`${i} \u2014 ${e}`:i}function BO(s){let t=(s?.expiry||"").trim();if(!t)return"";let e="",i="",r=t.match(/^(\d{1,2})\/(\d{2}|\d{4})$/);if(r)e=r[1].padStart(2,"0"),i=r[2].length===4?r[2].slice(-2):r[2];else{let n=t.match(/^(\d{4})-(\d{2})-\d{2}$/);n&&(i=n[1].slice(-2),e=n[2])}return!e||!i?"":`Expires ${e}/${i}`}var Qa=class extends R{static get properties(){return{...R.properties,methods:{type:Array,default:[]},value:{type:String,default:"",reflect:!0},"add-label":{type:String,default:"Add payment method",attribute:"add-label"},"add-icon":{type:String,default:"plus",attribute:"add-icon"},"no-add":{type:Boolean,default:!1,reflect:!0,attribute:"no-add"},"no-remove":{type:Boolean,default:!1,reflect:!0,attribute:"no-remove"},disabled:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=new Map;#o=!1;setDefault(t){return t?H(()=>{let e=(this.methods||[]).find(r=>r.id===t);if(!e)return!1;if(this.value===t)return!0;let i=this.value||"";this.#o=!0;try{this.value=t}finally{this.#o=!1}return this.syncValue(),this.#m(t,i,e),!0}):!1}remove(t){return t?H(()=>{let e=Array.isArray(this.methods)?this.methods.slice():[],i=e.findIndex(r=>r.id===t);if(i<0)return!1;if(e.splice(i,1),this.methods=e,this.value===t){let r=e[0]?.id||"";this.#o=!0;try{this.value=r}finally{this.#o=!1}this.syncValue()}return!0}):!1}add(t){!t||!t.id||H(()=>{let e=Array.isArray(this.methods)?this.methods.slice():[],i=e.findIndex(r=>r.id===t.id);if(i>=0?e[i]=t:e.push(t),this.methods=e,t.default){let r=this.value||"";this.#o=!0;try{this.value=t.id}finally{this.#o=!1}this.syncValue(),r!==t.id&&this.#m(t.id,r,t)}})}connected(){super.connected(),this.setAttribute("role","radiogroup"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Payment methods"),this.#t||(this.#h(),this.#c(),this.#p(),this.#t=!0),H(()=>this.render())}disconnected(){super.disconnected?.();for(let t of this.#e)try{t()}catch{}this.#e.length=0}syncValue(t){this.internals.setFormValue(this.value||"")}render(){if(!this.#t)return;let t=Array.isArray(this.methods)?this.methods:[],e=this.#l(t);if(e&&this.value!==e){this.#o=!0;try{this.value=e}finally{this.#o=!1}this.syncValue()}if(t.length===0?this.setAttribute("empty",""):this.removeAttribute("empty"),this.#r&&(this.#r.hidden=!!this["no-add"]),this.#n){this.#n.setAttribute("text",this["add-label"]||"Add payment method");let i=this["add-icon"]||"plus";i?this.#n.setAttribute("icon",i):this.#n.removeAttribute("icon"),this.disabled?this.#n.setAttribute("disabled",""):this.#n.removeAttribute("disabled")}this.#d(t)}#l(t){if(!t.length)return"";if(this.value&&t.some(i=>i.id===this.value))return this.value;let e=t.find(i=>i.default);return e?e.id:t[0].id||""}#h(){let t=this.querySelector(':scope > script[type="application/json"][data-methods]');if(t)try{let e=JSON.parse(t.textContent||"[]");Array.isArray(e)&&(this.methods=e)}catch(e){console.warn("[payment-method-list-ui] failed to parse <script data-methods> JSON:",e?.message)}finally{t.remove()}}#c(){let t=document.createElement("div");if(t.setAttribute("data-rows",""),t.setAttribute("role","presentation"),this.appendChild(t),this.#i=t,!this.querySelector(':scope > [slot="empty"]')){let i=document.createElement("empty-state-ui");i.setAttribute("data-empty",""),i.setAttribute("icon","credit-card"),i.setAttribute("heading","No payment methods"),i.setAttribute("description","Add a method to get started."),this.appendChild(i),this.#s=i}let e=document.createElement("div");if(e.setAttribute("data-add",""),this.appendChild(e),this.#r=e,!this.querySelector(':scope > [slot="add"]')){let i=document.createElement("button-ui");i.setAttribute("data-add-cta",""),i.setAttribute("variant","outline"),i.setAttribute("icon",this["add-icon"]||"plus"),i.setAttribute("text",this["add-label"]||"Add payment method"),e.appendChild(i),this.#n=i}}#d(t){if(!this.#i)return;let e=new Map;for(let i of t){if(!i?.id)continue;let r=this.#a.get(i.id);r||(r=this.#u(i),this.#i.appendChild(r)),this.#f(r,i),e.set(i.id,r)}for(let[i,r]of this.#a)if(!e.has(i))try{r.remove()}catch{}for(let i of t){let r=e.get(i.id);r&&this.#i.appendChild(r)}this.#a=e}#u(t){let e=document.createElement("card-ui");e.setAttribute("data-row",""),e.setAttribute("role","radio"),e.setAttribute("tabindex","0");let i=document.createElement("header"),r=document.createElement("span");r.setAttribute("slot","icon");let n=document.createElement("icon-ui");n.setAttribute("aria-hidden","true"),r.appendChild(n);let o=document.createElement("span");o.setAttribute("slot","heading");let a=document.createElement("span");a.setAttribute("data-primary","");let l=document.createElement("tag-ui");l.setAttribute("data-default-tag",""),l.setAttribute("text","Default"),l.setAttribute("variant","success"),l.setAttribute("size","sm"),l.setAttribute("hidden",""),o.appendChild(a),o.appendChild(l);let h=document.createElement("p");h.setAttribute("slot","description"),h.setAttribute("data-secondary","");let c=document.createElement("span");c.setAttribute("slot","action");let u=document.createElement("button-ui");u.setAttribute("data-action","set-default"),u.setAttribute("variant","ghost"),u.setAttribute("size","sm"),u.setAttribute("text","Set default");let d=document.createElement("button-ui");d.setAttribute("data-action","edit"),d.setAttribute("variant","ghost"),d.setAttribute("size","sm"),d.setAttribute("icon","pencil"),d.setAttribute("aria-label","Edit payment method");let f=document.createElement("button-ui");return f.setAttribute("data-action","remove"),f.setAttribute("variant","ghost"),f.setAttribute("size","sm"),f.setAttribute("icon","trash"),f.setAttribute("aria-label","Remove payment method"),c.appendChild(u),c.appendChild(d),c.appendChild(f),i.appendChild(r),i.appendChild(o),i.appendChild(h),i.appendChild(c),e.appendChild(i),e}#f(t,e){t.setAttribute("data-id",e.id);let i=(e?.brand||"").toLowerCase();i?t.setAttribute("data-brand-key",i):t.removeAttribute("data-brand-key");let r=(e?.type||"card").toLowerCase();FE.has(r)&&t.setAttribute("data-type",r);let n=e.id===this.value;n?(t.setAttribute("data-default",""),t.setAttribute("aria-checked","true"),t.setAttribute("tabindex","0")):(t.removeAttribute("data-default"),t.setAttribute("aria-checked","false"),t.setAttribute("tabindex","-1")),this.disabled?t.setAttribute("aria-disabled","true"):t.removeAttribute("aria-disabled");let o=t.querySelector(':scope > header > [slot="icon"] > icon-ui');if(o){let m=HE(e);o.getAttribute("name")!==m&&o.setAttribute("name",m)}let a=t.querySelector(':scope > header > [slot="heading"] > [data-primary]');a&&(a.textContent=XO(e));let l=t.querySelector(':scope > header > [data-secondary][slot="description"]');if(l){let m=BO(e);l.textContent=m,m?l.removeAttribute("hidden"):l.setAttribute("hidden","")}let h=t.querySelector(':scope > header > [slot="heading"] > [data-default-tag]');h&&(n?h.removeAttribute("hidden"):h.setAttribute("hidden",""));let c=BO(e),u=[XO(e)];c&&u.push(c),n&&u.push("default"),t.setAttribute("aria-label",u.join(", "));let d=t.querySelector(':scope > header > [slot="action"] > [data-action="set-default"]');d&&(n?d.setAttribute("hidden",""):d.removeAttribute("hidden"),this.disabled?d.setAttribute("disabled",""):d.removeAttribute("disabled"));let f=t.querySelector(':scope > header > [slot="action"] > [data-action="edit"]');f&&(this.disabled?f.setAttribute("disabled",""):f.removeAttribute("disabled"));let p=t.querySelector(':scope > header > [slot="action"] > [data-action="remove"]');p&&(this["no-remove"]?p.setAttribute("hidden",""):p.removeAttribute("hidden"),this.disabled?p.setAttribute("disabled",""):p.removeAttribute("disabled"))}#p(){let t=r=>{let n=r.target?.closest?.("button-ui[data-action]");if(n&&this.#i.contains(n)){let a=n.closest("[data-row]");if(!a)return;let l=a.getAttribute("data-id")||"";if(!l)return;if(this.disabled||n.hasAttribute("disabled")){r.stopPropagation();return}let h=(this.methods||[]).find(u=>u.id===l);if(!h)return;let c=n.getAttribute("data-action");r.stopPropagation(),c==="set-default"?this.setDefault(l):c==="remove"?this.dispatchEvent(new CustomEvent("remove",{bubbles:!0,detail:{id:l,method:h}})):c==="edit"&&this.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{id:l,method:h}}));return}let o=r.target?.closest?.("button-ui[data-add-cta]");if(o&&this.#r?.contains(o)){if(this.disabled||o.hasAttribute("disabled")){r.stopPropagation();return}r.stopPropagation(),this.dispatchEvent(new CustomEvent("add",{bubbles:!0,detail:{}}))}};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=r=>{if(r.target?.closest?.("button-ui[data-action]")||r.target?.closest?.("button-ui[data-add-cta]"))return;let n=r.target?.closest?.("[data-row]");if(!n||!this.#i.contains(n))return;let o=n.getAttribute("data-id")||"";o&&(this.disabled||this.setDefault(o))};this.#i.addEventListener("click",e),this.#e.push(()=>this.#i.removeEventListener("click",e));let i=r=>{let o=document.activeElement?.closest?.("[data-row]");if(!o||!this.#i.contains(o))return;let a=Array.from(this.#i.querySelectorAll(":scope > [data-row]")),l=a.indexOf(o);if(!(l<0)){if(r.key==="ArrowDown"||r.key==="ArrowRight")r.preventDefault(),a[(l+1)%a.length]?.focus?.();else if(r.key==="ArrowUp"||r.key==="ArrowLeft")r.preventDefault(),a[(l-1+a.length)%a.length]?.focus?.();else if(r.key==="Home")r.preventDefault(),a[0]?.focus?.();else if(r.key==="End")r.preventDefault(),a[a.length-1]?.focus?.();else if(r.key===" "||r.key==="Enter"){r.preventDefault();let h=o.getAttribute("data-id")||"";h&&!this.disabled&&this.setDefault(h)}}};this.#i.addEventListener("keydown",i),this.#e.push(()=>this.#i.removeEventListener("keydown",i))}#m(t,e,i){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:t,previous:e,method:i}}))}};customElements.get("payment-method-list-ui")||customElements.define("payment-method-list-ui",Qa);Pt();var Xd=new Set(["monthly","annual"]),KD={monthly:"Monthly",annual:"Annual"},JD={monthly:"/month",annual:"/year"};function tq(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",maximumFractionDigits:Number.isInteger(i)?0:2}).format(i)}catch{return`${t||"$"}${i}`}}function eq(s,t,e){if(s.cta)return s.cta;if(!e)return`Choose ${s.name||""}`.trim();if(s.id===e)return"Manage";let i=t.find(r=>r.id===e);if(i&&Number.isFinite(i.rank)&&Number.isFinite(s.rank)){if(s.rank>i.rank)return"Upgrade";if(s.rank<i.rank)return"Downgrade"}return`Switch to ${s.name||""}`.trim()}var Ta=class extends R{static labelDeprecated=!0;static get properties(){return{...R.properties,plans:{type:Array,default:[]},value:{type:String,default:"",reflect:!0},current:{type:String,default:"",reflect:!0},cycle:{type:String,default:"monthly",reflect:!0},cycleToggle:{type:Boolean,default:!1,reflect:!0,attribute:"cycle-toggle"},currency:{type:String,default:"USD"},locale:{type:String,default:""},layout:{type:String,default:"grid",reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=new Map;#l=!1;#h=!1;#c=!1;#d=0;setValue(t){return t?H(()=>{let e=(this.plans||[]).find(r=>r.id===t);if(!e)return!1;if(e.disabled)return this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"plan-disabled"}})),!1;if(this.value===t)return!0;let i=this.value||"";return this.value=t,this.syncValue(),this.#b(t,i),!0}):!1}setCycle(t){return Xd.has(t)?H(()=>{if(this.cycle===t)return!0;let e=this.cycle;return this.cycle=t,this.dispatchEvent(new CustomEvent("cycle-change",{bubbles:!0,detail:{cycle:t,previous:e}})),!0}):!1}async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#d;this.setAttribute("loading",""),this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#d)return;this.removeAttribute("loading");let n=Array.isArray(r)?r:Array.isArray(r?.plans)?r.plans:[];this.plans=n,this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{count:n.length}}))}catch(i){if(e!==this.#d)return;this.removeAttribute("loading"),this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){super.connected(),this.setAttribute("role","radiogroup"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Choose a plan"),this.#t||(this.#u(),this.#f(),this.#y(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#l)&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}syncValue(t){this.internals.setFormValue(this.value||"")}render(){if(!this.#t)return;let t=Array.isArray(this.plans)?this.plans:[];if(!Xd.has(this.cycle)){this.#h||(this.#h=!0,console.warn(`[plan-picker-ui] unknown cycle "${this.cycle}" \u2014 coercing to "monthly".`)),this.#l=!0;try{this.cycle="monthly"}finally{this.#l=!1}}let e=t.filter(r=>r.recommended);e.length>1&&!this.#c&&(this.#c=!0,console.warn(`[plan-picker-ui] ${e.length} plans carry recommended:true \u2014 using the first ("${e[0].id}"); ignoring the rest.`));let i=e[0]?.id||"";if(t.length===0?this.setAttribute("empty",""):this.removeAttribute("empty"),this.#i){let r=this.cycleToggle&&t.length>0;this.#i.hidden=!r,r&&this.#p()}this.#m(t,i)}#u(){let t=this.querySelector(':scope > script[type="application/json"][data-plans]');if(t)try{let e=JSON.parse(t.textContent||"[]");Array.isArray(e)&&(this.plans=e)}catch(e){console.warn("[plan-picker-ui] failed to parse <script data-plans> JSON:",e?.message)}finally{t.remove()}}#f(){let t=document.createElement("div");t.setAttribute("data-toggle",""),t.hidden=!0,this.appendChild(t),this.#i=t;let e=document.createElement("div");e.setAttribute("data-plans",""),e.setAttribute("role","presentation"),this.appendChild(e),this.#r=e;let i=document.createElement("div");if(i.setAttribute("data-skeleton",""),i.hidden=!0,this.appendChild(i),this.#n=i,!this.querySelector(':scope > [slot="empty"]')){let r=document.createElement("empty-state-ui");r.setAttribute("data-empty",""),r.setAttribute("icon","package"),r.setAttribute("heading","No plans available"),r.setAttribute("description","Plans will appear here once configured."),this.appendChild(r),this.#a=r}}#p(){if(!this.#i)return;let t=this.#s;if(!t){t=document.createElement("segmented-ui"),t.setAttribute("aria-label","Billing cycle"),this.#i.appendChild(t),this.#s=t;for(let e of["monthly","annual"]){let i=document.createElement("segment-ui");i.setAttribute("value",e),i.setAttribute("text",KD[e]),t.appendChild(i)}}t.value!==this.cycle&&(t.value=this.cycle)}#m(t,e){if(!this.#r)return;let i=new Map;for(let r of t){if(!r?.id)continue;let n=this.#o.get(r.id);n||(n=document.createElement("option-card-ui"),n.setAttribute("layout","tile"),this.#r.appendChild(n)),this.#g(n,r,e),i.set(r.id,n)}for(let[r,n]of this.#o)if(!i.has(r))try{n.remove()}catch{}for(let r of t){let n=i.get(r.id);n&&this.#r.appendChild(n)}this.#o=i}#g(t,e,i){t.setAttribute("name",`${this.name||"plan"}__${this.id||"pp"}`),t.setAttribute("value",e.id),t.setAttribute("heading",e.name||""),t.setAttribute("description",e.tagline||""),e.icon?t.setAttribute("icon",e.icon):t.removeAttribute("icon");let r=!!(this.current&&e.id===this.current),n=e.id===i;r?t.setAttribute("data-current",""):t.removeAttribute("data-current"),n?t.setAttribute("data-recommended",""):t.removeAttribute("data-recommended"),e.disabled||this.disabled?t.setAttribute("disabled",""):t.removeAttribute("disabled"),this.value&&this.value===e.id||!this.value&&r?t.setAttribute("checked",""):t.removeAttribute("checked");let a=t.querySelector(":scope > [data-plan-body]");a||(a=document.createElement("div"),a.setAttribute("data-plan-body",""),t.appendChild(a)),this.#O(a,e);let l=t.querySelector(":scope > [data-plan-tags]");if(l||(l=document.createElement("div"),l.setAttribute("data-plan-tags",""),l.setAttribute("slot","heading-suffix"),t.appendChild(l)),l.replaceChildren(),r){let h=document.createElement("tag-ui");h.setAttribute("text","Current plan"),h.setAttribute("variant","muted"),l.appendChild(h)}else if(n){let h=document.createElement("tag-ui");h.setAttribute("text","Recommended"),h.setAttribute("variant","accent"),l.appendChild(h)}}#O(t,e){t.replaceChildren();let i=document.createElement("div");i.setAttribute("data-price-row","");let r=Xd.has(this.cycle)?this.cycle:"monthly",n=e.prices||{},o=n[r]||n.monthly||null;if(o){let l=document.createElement("span");l.setAttribute("data-price","");let h=o.currency||this.currency||"USD";l.textContent=tq(o.amount,h,this.locale),i.appendChild(l);let c=document.createElement("span");c.setAttribute("data-cycle","");let u=o.unit?`/${o.unit}`:JD[r];c.textContent=u,i.appendChild(c)}else{let l=document.createElement("span");l.setAttribute("data-price",""),l.textContent="Contact sales",i.appendChild(l)}if(t.appendChild(i),o?.note){let l=document.createElement("span");l.setAttribute("data-price-note",""),l.textContent=o.note,t.appendChild(l)}if(Array.isArray(e.features)&&e.features.length){let l=document.createElement("ul");l.setAttribute("data-features","");for(let h of e.features){let c=document.createElement("li"),u=document.createElement("icon-ui");u.setAttribute("name","check"),u.setAttribute("aria-hidden","true"),c.appendChild(u);let d=document.createElement("span");d.textContent=String(h),c.appendChild(d),l.appendChild(c)}t.appendChild(l)}if(!!!(this.current&&e.id===this.current)||e.cta){let l=document.createElement("button-ui");l.setAttribute("data-cta",""),l.setAttribute("variant",e.recommended?"primary":"outline"),l.setAttribute("text",eq(e,Array.isArray(this.plans)?this.plans:[],this.current)),(e.disabled||this.disabled)&&l.setAttribute("disabled",""),t.appendChild(l)}}#y(){let t=r=>{let n=r?.detail?.value;if(!Xd.has(n)||this.cycle===n)return;r.stopPropagation();let o=this.cycle;this.cycle=n,this.dispatchEvent(new CustomEvent("cycle-change",{bubbles:!0,detail:{cycle:n,previous:o}}))};this.#i.addEventListener("change",t),this.#e.push(()=>this.#i.removeEventListener("change",t));let e=r=>{let n=r.target?.closest?.("option-card-ui");if(!n||!this.#r.contains(n))return;let o=n.getAttribute("value")||"";if(!o)return;let a=(this.plans||[]).find(h=>h.id===o);if(!a)return;if(a.disabled||this.disabled){n.removeAttribute("checked"),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"plan-disabled"}}));return}r.stopPropagation();let l=this.value||"";if(l!==o){this.#l=!0;try{this.value=o}finally{this.#l=!1}this.syncValue(),this.#b(o,l)}};this.#r.addEventListener("change",e),this.#e.push(()=>this.#r.removeEventListener("change",e));let i=r=>{let n=r.target?.closest?.("button-ui[data-cta]");if(!n||!this.#r.contains(n))return;let o=n.closest("option-card-ui");if(!o)return;let a=o.getAttribute("value")||"";if(!a)return;let l=(this.plans||[]).find(c=>c.id===a);if(!l||l.disabled||this.disabled)return;r.stopPropagation();let h=this.value||"";if(h!==a){this.#l=!0;try{this.value=a}finally{this.#l=!1}this.syncValue(),this.#b(a,h)}this.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{value:a,cycle:this.cycle}}))};this.#r.addEventListener("press",i),this.#r.addEventListener("click",i),this.#e.push(()=>this.#r.removeEventListener("press",i)),this.#e.push(()=>this.#r.removeEventListener("click",i))}#b(t,e){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:t,previous:e,cycle:this.cycle}}))}};customElements.get("plan-picker-ui")||customElements.define("plan-picker-ui",Ta);P();var iq=Object.freeze([{value:"all",label:"All"},{value:"available",label:"Available"},{value:"connected",label:"Connected"},{value:"error",label:"Issues"},{value:"coming-soon",label:"Coming soon"}]),sq=6,vh=class extends v{static properties={integrations:{type:Array,default:[]},loading:{type:Boolean,default:!1,reflect:!0},"search-placeholder":{type:String,default:"Search integrations",reflect:!0},"group-by":{type:String,default:"category",reflect:!0},"status-filter":{type:String,default:"all",reflect:!0}};static template=t=>t._renderTemplate();#t="";#e=`intpage-h-${Math.random().toString(36).slice(2,8)}`;#i=null;attributeChangedCallback(t,e,i){if(t==="integrations"){if(i==null)this.integrations=[];else try{let r=JSON.parse(i);this.integrations=Array.isArray(r)?r:[]}catch{this.integrations=[]}return}super.attributeChangedCallback(t,e,i)}connected(){if(this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#e),this.hasAttribute("aria-label")||this.setAttribute("aria-label","Integrations"),this.hasAttribute("integrations")&&!Array.isArray(this.integrations))try{this.integrations=JSON.parse(this.getAttribute("integrations"))}catch{this.integrations=[]}this.addEventListener("input",this.#d),this.addEventListener("change",this.#u)}disconnected(){this.removeEventListener("input",this.#d),this.removeEventListener("change",this.#u),this.#i&&(clearTimeout(this.#i),this.#i=null)}render(){this.#c(),this.querySelector('segmented-ui[data-part="filter"]')?.render?.()}_renderTemplate(){let t=this["search-placeholder"]||"Search integrations",e=this["status-filter"]||"all",i=!!this.loading,r=this.#l();return Y`
455
+ `}#o(t){let e=t.target;if(!e||!e.closest)return;let i=e.closest("[data-step-check]");if(!i||!this.contains(i))return;let r=i.getAttribute("data-step-id")||"";if(!r)return;let n=this.#d(r),o=!!i.checked;n!==o&&this.#u(r,o,{emit:o})}#l(t){let e=t.target;if(!e||!e.closest)return;let i=e.closest("[data-step-action]");if(!i||!this.contains(i))return;let r=i.getAttribute("data-step-id")||"",n=i.getAttribute("data-href")||"";r&&this.dispatchEvent(new CustomEvent("onboarding-step-action",{bubbles:!0,detail:{id:r,href:n}}))}#h(t){t?.stopPropagation?.();let e=!this.collapsed;this.collapsed=e,e&&this.dispatchEvent(new CustomEvent("onboarding-dismiss",{bubbles:!0,detail:{reason:"collapsed"}}))}#c(t){if(!t)return!1;let e=t.id;return e!=null&&Object.prototype.hasOwnProperty.call(this.value||{},e)?!!this.value[e]:!!t.done}#d(t){let i=(Array.isArray(this.items)?this.items:[]).find(r=>r&&String(r.id)===String(t));return this.#c(i)}#u(t,e,{emit:i=!0}={}){let r={...this.value||{},[t]:!!e};this.value=r,this.#v(),i&&e&&this.dispatchEvent(new CustomEvent("onboarding-step-complete",{bubbles:!0,detail:{id:t,value:r}}))}#f(){let t=Array.isArray(this.items)?this.items:[],e=t.length,i=0;for(let n of t)this.#c(n)&&i++;let r=e===0?0:Math.round(i/e*100);return{done:i,total:e,percent:r}}#p(){let{done:t,total:e}=this.#f();return e>0&&t===e}#m(){this.#p()?this.setAttribute("data-complete",""):this.removeAttribute("data-complete")}#g(){let t=this.#p();t&&!this.#s?(this.#s=!0,this.dispatchEvent(new CustomEvent("onboarding-complete",{bubbles:!0,detail:{value:this.value}})),this["dismiss-on-complete"]&&this.#O("complete")):t||(this.#s=!1)}#O(t="user"){this.setAttribute("hidden",""),this.dispatchEvent(new CustomEvent("onboarding-dismiss",{bubbles:!0,detail:{reason:t}}))}#y(){}#b(){if(this.#i||this.storage==="none"||!this["storage-key"]||typeof window>"u")return null;try{return this.storage==="session"?window.sessionStorage:window.localStorage}catch{return null}}#x(){let t=this.#b();if(!t)return null;try{let e=t.getItem(this["storage-key"]);if(!e)return null;let i=JSON.parse(e);return i&&typeof i=="object"&&!Array.isArray(i)?i:null}catch{return null}}#v(){let t=this.#b();if(t)try{t.setItem(this["storage-key"],JSON.stringify(this.value||{}))}catch{}}complete(t){if(t==null)return;let e=String(t);this.#d(e)||this.#u(e,!0,{emit:!0})}reset(t){if(t==null){this.value={};let i=this.#b();try{i?.removeItem(this["storage-key"])}catch{}this.#s=!1,this.removeAttribute("hidden");return}let e=String(t);Object.prototype.hasOwnProperty.call(this.value||{},e)&&this.#u(e,!1,{emit:!1})}progress(){return this.#f()}};customElements.get("onboarding-checklist-ui")||customElements.define("onboarding-checklist-ui",Oh);P();Pt();var DO=new Set(["","comfortable","compact","spacious"]),qO=new Set(["2","3","4","5","6"]),TE=new Set(["","2","2:1","3:2","3:1"]),NO=["toolbar","kpis","charts","table","aside"],Ld=class extends v{static get properties(){return{density:{type:String,default:"",reflect:!0},"kpi-columns":{type:String,default:"4",reflect:!0,attribute:"kpi-columns"},"chart-split":{type:String,default:"",reflect:!0,attribute:"chart-split"},loading:{type:Boolean,default:!1,reflect:!0},gap:{type:String,default:"",reflect:!0}}}static template=()=>null;#t={toolbar:!1,kpis:!1,charts:!1,table:!1,aside:!1};#e=null;#i=!1;setDensity(t){let e=DO.has(t)?t:"";this.density!==e&&(this.density=e)}getRegion(t){return NO.includes(t)?this.querySelector(`:scope > [slot="${t}"]`):null}connected(){this.hasAttribute("role")||this.setAttribute("role","region"),H(()=>this.#s()),this.#r(),this.#n(),this.#a(),typeof MutationObserver<"u"&&(this.#e=new MutationObserver(t=>this.#o(t)),this.#e.observe(this,{childList:!0}))}disconnected(){this.#e&&(this.#e.disconnect(),this.#e=null)}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback?.(t,e,i),!this.#i){if(t==="density"&&e!==i){if(!DO.has(i)){this.#i=!0;try{this.density=""}finally{this.#i=!1}return}this.isConnected&&this.dispatchEvent(new CustomEvent("density-change",{bubbles:!0,detail:{density:i}}));return}if(t==="kpi-columns"&&e!==i){if(i!=null&&!qO.has(i)){console.warn(`[dashboard-layout-ui] kpi-columns="${i}" out of range \u2014 falling back to "4". Use one of: ${[...qO].join(", ")}.`),this.#i=!0;try{this["kpi-columns"]="4"}finally{this.#i=!1}}return}if(t==="chart-split"&&e!==i){if(i!=null&&!TE.has(i)){console.warn(`[dashboard-layout-ui] chart-split="${i}" not in enum \u2014 falling back to "" (single column). Use one of: "" (full), 2, 2:1, 3:2, 3:1.`),this.#i=!0;try{this["chart-split"]=""}finally{this.#i=!1}}return}if(t==="loading"&&e!==i){this.#r();return}if(t==="gap"&&e!==i){this.#n();return}}}#s(){if(!DO.has(this.density)){this.#i=!0;try{this.density=""}finally{this.#i=!1}}if(!qO.has(this["kpi-columns"])){console.warn(`[dashboard-layout-ui] kpi-columns="${this["kpi-columns"]}" out of range \u2014 clamping to "4".`),this.#i=!0;try{this["kpi-columns"]="4"}finally{this.#i=!1}}if(!TE.has(this["chart-split"])){console.warn(`[dashboard-layout-ui] chart-split="${this["chart-split"]}" not in enum \u2014 clamping to "".`),this.#i=!0;try{this["chart-split"]=""}finally{this.#i=!1}}}#r(){this.loading?this.setAttribute("aria-busy","true"):this.removeAttribute("aria-busy")}#n(){let t=(this.gap||"").trim();if(t===""){this.style.removeProperty("--dashboard-layout-gap");return}/^[1-6]$/.test(t)?this.style.setProperty("--dashboard-layout-gap",`var(--a-space-${t})`):this.style.setProperty("--dashboard-layout-gap",t)}#a(){for(let t of NO)this.#t[t]=!!this.querySelector(`:scope > [slot="${t}"]`)}#o(t){for(let e of NO){let i=this.#t[e],r=!!this.querySelector(`:scope > [slot="${e}"]`);i&&!r&&this.dispatchEvent(new CustomEvent("region-empty",{bubbles:!0,detail:{region:e}})),this.#t[e]=r}}};customElements.get("dashboard-layout-ui")||customElements.define("dashboard-layout-ui",Ld);Pt();var tr=new Set,LE=!1;function ME(s){return String(s).padStart(2,"0")}function Md(s){return`${s.getFullYear()}-${ME(s.getMonth()+1)}-${ME(s.getDate())}`}function RE(s){if(!s)return null;let t=String(s).match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)return null;let e=new Date(+t[1],+t[2]-1,+t[3]);return Number.isNaN(e.getTime())?null:e}var IE={today:"Today","7d":"Last 7 days","30d":"Last 30 days","90d":"Last 90 days",qtd:"Quarter to date",ytd:"Year to date",custom:"Custom"},er=new Set(Object.keys(IE));function yh(s,t=new Date){let e=new Date(t.getFullYear(),t.getMonth(),t.getDate()),i=Md(e),r=n=>{let o=new Date(e);return o.setDate(o.getDate()-n),Md(o)};switch(s){case"today":return{from:i,to:i};case"7d":return{from:r(6),to:i};case"30d":return{from:r(29),to:i};case"90d":return{from:r(89),to:i};case"qtd":{let n=Math.floor(e.getMonth()/3)*3;return{from:Md(new Date(e.getFullYear(),n,1)),to:i}}case"ytd":return{from:Md(new Date(e.getFullYear(),0,1)),to:i};case"custom":return null;default:return null}}function DD(s,t){let e=RE(s),i=RE(t);if(!e||!i)return"";let r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],n=e.getFullYear()===i.getFullYear(),o=n&&e.getMonth()===i.getMonth();return n&&e.getMonth()===i.getMonth()&&e.getDate()===i.getDate()?`${r[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`:o?`${r[e.getMonth()]} ${e.getDate()} \u2013 ${i.getDate()}, ${i.getFullYear()}`:n?`${r[e.getMonth()]} ${e.getDate()} \u2013 ${r[i.getMonth()]} ${i.getDate()}, ${i.getFullYear()}`:`${r[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()} \u2013 ${r[i.getMonth()]} ${i.getDate()}, ${i.getFullYear()}`}var Rd=class s extends R{static labelDeprecated=!0;static get properties(){return{...R.properties,value:{type:String,default:"7d",reflect:!0},from:{type:String,default:"",reflect:!0},to:{type:String,default:"",reflect:!0},presets:{type:String,default:"today,7d,30d,90d,qtd,ytd,custom"},broadcast:{type:String,default:"document",reflect:!0},ariaLabelAttr:{type:String,default:"Time period",attribute:"aria-label",reflect:!0},pickerOpen:{type:Boolean,default:!1,attribute:"picker-open",reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n={prefix:null,chips:null,picker:null,readout:null,suffix:null};#a=!1;#o=!1;static#l=new WeakSet;setRange(t,e,i){if(t==="custom"){if(!e||!i){console.warn('[date-range-selector-ui] setRange("custom", \u2026) requires from + to ISO dates.');return}let n=this.#p(e,i);this.#u("custom",n.from,n.to);return}if(!er.has(t)){console.warn(`[date-range-selector-ui] unknown preset "${t}" \u2014 ignored. Use one of: ${[...er].join(", ")}.`);return}let r=yh(t);r&&this.#u(t,r.from,r.to)}getRange(){return{value:this.value,preset:this.value,from:this.from,to:this.to}}subscribe(t){let e=this.#g();return e?(e.addEventListener("range-change",t),()=>e.removeEventListener("range-change",t)):()=>{}}connected(){super.connected(),this.setAttribute("role","group"),this.hasAttribute("aria-label")||this.setAttribute("aria-label",this.ariaLabelAttr||"Time period"),this.#t||(this.#h(),this.#d(),this.#t=!0),this.broadcast==="document"&&this.#b(),H(()=>{let t=this.#m();t&&this.#u(this.value,t.from,t.to,{initial:!0})})}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0,this.#x()}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#o)){if(t==="presets"){this.#c();return}if(t==="broadcast"){e==="document"&&i!=="document"&&this.#x(),i==="document"?(this.#b(),this.#y()):i==="self"&&this.#y();return}if(t==="value"&&e!==i&&i&&er.has(i)){if(i!=="custom"){let r=yh(i);r&&this.#u(i,r.from,r.to)}return}}}syncValue(t){let e=this.from&&this.to?`${this.from}:${this.to}`:"";this.internals.setFormValue(e)}render(){if(this.#t){if(this.#i&&this.#i.value!==this.value&&(this.#i.value=this.value),this.#s){this.hasAttribute("min")&&this.#s.setAttribute("min",this.getAttribute("min")),this.hasAttribute("max")&&this.#s.setAttribute("max",this.getAttribute("max"));let t=this.from&&this.to?JSON.stringify({from:this.from,to:this.to}):"";this.#s.value!==t&&(this.#s.value=t)}if(this.#r){let t=DD(this.from,this.to);this.#r.textContent=t,this.#r.hidden=!t}}}#h(){let t=document.createElement("segmented-ui");t.setAttribute("data-region","chips"),t.setAttribute("role","radiogroup"),t.setAttribute("aria-label","Preset ranges"),this.appendChild(t),this.#i=t,this.#n.chips=t;let e=document.createElement("date-range-picker-ui");e.setAttribute("data-region","picker"),e.setAttribute("format","short"),e.setAttribute("placeholder","Custom range"),this.appendChild(e),this.#s=e,this.#n.picker=e;let i=document.createElement("text-ui");i.setAttribute("data-region","readout"),i.setAttribute("part","readout"),i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.hidden=!0,this.appendChild(i),this.#r=i,this.#n.readout=i,this.#c()}#c(){if(!this.#i)return;let t=(this.presets||"").split(",").map(i=>i.trim()).filter(Boolean),e=this.#i.querySelector(":scope > [data-indicator]");this.#i.replaceChildren(),e&&this.#i.appendChild(e);for(let i of t){if(!er.has(i)){s.#l.has(this)||(s.#l.add(this),console.warn(`[date-range-selector-ui] unknown preset key "${i}" in [presets] \u2014 ignored. Use one of: ${[...er].join(", ")}.`));continue}let r=document.createElement("segment-ui");r.setAttribute("value",i),r.setAttribute("text",IE[i]),this.#i.appendChild(r)}this.#i.value=this.value}#d(){let t=n=>{let o=n.detail?.value;if(!o||!er.has(o))return;if(n.stopPropagation(),o==="custom"){this.#v(),this.#f("custom");return}let a=yh(o);a&&this.#u(o,a.from,a.to)};this.#i.addEventListener("change",t),this.#e.push(()=>this.#i.removeEventListener("change",t));let e=n=>{n.stopPropagation();let a=(n.detail||{}).value||null;if(!a||!a.from||!a.to)return;let l=this.#p(a.from,a.to);this.#u("custom",l.from,l.to)};this.#s.addEventListener("change",e),this.#e.push(()=>this.#s.removeEventListener("change",e));let i=()=>{this.pickerOpen=!0},r=()=>{this.pickerOpen=!1};this.#s.addEventListener("open",i),this.#s.addEventListener("close",r),this.#e.push(()=>this.#s.removeEventListener("open",i)),this.#e.push(()=>this.#s.removeEventListener("close",r))}#u(t,e,i,r={}){if(this.from===e&&this.to===i&&this.value===t&&!r.initial)return;this.#o=!0;try{this.from=e,this.to=i,this.value=t}finally{this.#o=!1}this.syncValue(),this.#y();let o={value:t,from:e,to:i,preset:t};this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:t,from:e,to:i}}));let a=this.#g();a&&a.dispatchEvent(new CustomEvent("range-change",{bubbles:a===this,detail:o}))}#f(t){if(this.value!==t){this.#o=!0;try{this.value=t}finally{this.#o=!1}}}#p(t,e){return t<=e?{from:t,to:e}:{from:e,to:t}}#m(){if(this.value==="custom")return this.from&&this.to?this.#p(this.from,this.to):yh("7d");let t=er.has(this.value)?this.value:"7d";return yh(t)}#g(){return this.broadcast==="document"?document:this.broadcast==="self"?this:null}#O(){return this.broadcast==="document"?document.documentElement:this.broadcast==="self"?this:null}#y(){let t=this.#O();t&&(this.broadcast==="document"&&!this.#a||(this.from?t.setAttribute("data-range-from",this.from):t.removeAttribute("data-range-from"),this.to?t.setAttribute("data-range-to",this.to):t.removeAttribute("data-range-to")))}#b(){if(tr.size>0&&!tr.has(this)){LE||(LE=!0,console.warn('[date-range-selector-ui] multiple instances with broadcast="document" on the same page; only the first writes data-range-from / data-range-to to <html>. Use broadcast="self" for secondary instances. See SPEC-019 \xA76 nesting rules.')),this.#a=!1,tr.add(this);return}tr.add(this),this.#a=!0}#x(){if(tr.has(this)&&(tr.delete(this),this.#a)){document.documentElement.removeAttribute("data-range-from"),document.documentElement.removeAttribute("data-range-to"),this.#a=!1;let t=tr.values().next().value;t&&(t.#a=!0,t.#y())}}#v(){this.#s&&(typeof this.#s.openPopover=="function"?this.#s.openPopover():this.#s.open=!0)}};customElements.get("date-range-selector-ui")||customElements.define("date-range-selector-ui",Rd);P();var Id=class extends v{static properties={open:{type:Boolean,default:!1,reflect:!0},title:{type:String,default:"",reflect:!0},description:{type:String,default:"",reflect:!0},confirmText:{type:String,default:"Confirm",reflect:!0,attribute:"confirm-text"},cancelText:{type:String,default:"Cancel",reflect:!0,attribute:"cancel-text"},confirmVariant:{type:String,default:"primary",reflect:!0,attribute:"confirm-variant"},size:{type:String,default:"sm",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},icon:{type:String,default:"",reflect:!0}};static template=()=>null;#t=null;#e=null;#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=null;#c=[];#d=!1;#u="";#f="";#p=!1;connected(){this.#d||(this.#u=`${this.#y}-title`,this.#f=`${this.#y}-desc`,this.#m(),this.#g(),this.#d=!0)}disconnected(){for(let t of this.#c)try{t()}catch{}this.#c.length=0}show(){this.open=!0}hide(){this.open=!1}render(){if(!this.#d)return;this.#t&&(this.#t.setAttribute("size",this.size||"sm"),this.#t.open=!!this.open),this.#s&&(this.#s.id=this.#u,this.#s.textContent=this.title||""),this.#n&&(this.#n.id=this.#f,this.#n.textContent=this.description||"",this.#n.hidden=!this.description),this.#i&&(this.querySelector(':scope > [slot="icon"]')?this.#i.hidden=!0:this.icon?(this.#i.hidden=!1,this.#i.setAttribute("name",this.icon)):this.#i.hidden=!0);let t=this.#t?.querySelector(':scope > [slot="dialog"]');t&&(t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),this.title?t.setAttribute("aria-labelledby",this.#u):t.removeAttribute("aria-labelledby"),this.description?t.setAttribute("aria-describedby",this.#f):t.removeAttribute("aria-describedby")),this.#l&&(this.#l.setAttribute("text",this.cancelText||"Cancel"),this.loading?this.#l.setAttribute("disabled",""):this.#l.removeAttribute("disabled")),this.#h&&(this.#h.setAttribute("text",this.confirmText||"Confirm"),this.#h.setAttribute("variant",this.confirmVariant==="ghost"?"ghost":"primary"),this.loading?(this.#h.setAttribute("disabled",""),this.#h.setAttribute("icon","spinner")):(this.#h.removeAttribute("disabled"),this.#h.removeAttribute("icon"))),this.open&&this.#l&&!this.loading&&this.#O()}#m(){let t=document.createElement("modal-ui");t.setAttribute("size",this.size||"sm");let e=document.createElement("header");e.setAttribute("slot","header");let i=document.createElement("icon-ui");i.setAttribute("slot","icon"),i.hidden=!0,e.appendChild(i),this.#i=i;let r=document.createElement("text-ui");r.setAttribute("slot","heading"),r.id=this.#u,this.title&&(r.textContent=this.title),e.appendChild(r),this.#s=r,this.#e=e;let n=document.createElement("section");n.setAttribute("slot","body");let o=document.createElement("text-ui");o.setAttribute("slot","description"),o.id=this.#f,this.description?o.textContent=this.description:o.hidden=!0,n.appendChild(o),this.#n=o;let a=document.createElement("div");a.setAttribute("data-extra",""),n.appendChild(a),this.#a=a,this.#r=n;let l=document.createElement("footer");l.setAttribute("slot","footer");let h=document.createElement("button-ui");h.setAttribute("slot","action"),h.setAttribute("data-confirm-action","cancel"),h.setAttribute("variant","ghost"),h.setAttribute("text",this.cancelText||"Cancel"),l.appendChild(h),this.#l=h;let c=document.createElement("button-ui");c.setAttribute("slot","action"),c.setAttribute("data-confirm-action","confirm"),c.setAttribute("variant",this.confirmVariant==="ghost"?"ghost":"primary"),c.setAttribute("text",this.confirmText||"Confirm"),l.appendChild(c),this.#h=c,this.#o=l;let u=[...this.children];for(let d of u){let f=d.getAttribute("slot");f==="icon"?e.appendChild(d):f||a.appendChild(d)}t.appendChild(e),t.appendChild(n),t.appendChild(l),this.appendChild(t),this.#t=t}#g(){let t=r=>{this.loading||(r.stopPropagation(),this.#p=!0,this.dispatchEvent(new CustomEvent("confirm",{bubbles:!0,detail:{}})))};this.#h.addEventListener("press",t),this.#c.push(()=>this.#h.removeEventListener("press",t));let e=r=>{this.loading||(r.stopPropagation(),this.#p=!0,this.dispatchEvent(new CustomEvent("cancel",{bubbles:!0,detail:{}})),this.open=!1)};this.#l.addEventListener("press",e),this.#c.push(()=>this.#l.removeEventListener("press",e));let i=r=>{r.stopPropagation(),this.open=!1,this.#p||this.dispatchEvent(new CustomEvent("cancel",{bubbles:!0,detail:{}})),this.#p=!1,this.dispatchEvent(new CustomEvent("close",{bubbles:!0,detail:{}}))};this.#t.addEventListener("close",i),this.#c.push(()=>this.#t.removeEventListener("close",i))}#O(){let t=()=>{if(!(!this.open||!this.#l||this.loading))try{this.#l.focus()}catch{}};typeof requestAnimationFrame=="function"?requestAnimationFrame(t):queueMicrotask(t)}get#y(){return this.id||"confirm-dialog"}};customElements.get("confirm-dialog-ui")||customElements.define("confirm-dialog-ui",Id);P();Pt();var qD=new Set(["active","trialing","past_due","canceled","paused"]),ND={active:"success",trialing:"info",past_due:"danger",canceled:"muted",paused:"warning"},XD={active:"Active",trialing:"Trialing",past_due:"Past due",canceled:"Canceled",paused:"Paused"},BD={update:"update-card",retry:"retry"};function DE(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",maximumFractionDigits:Number.isInteger(i)?0:2}).format(i)}catch{return`${t||"$"}${i}`}}function ZD(s,t){if(!s)return"";try{let e=s instanceof Date?s:new Date(s);return Number.isNaN(e.getTime())?String(s):new Intl.DateTimeFormat(t||void 0,{year:"numeric",month:"short",day:"2-digit"}).format(e)}catch{return String(s)}}var Ea=class extends v{static get properties(){return{account:{type:Object,default:null},variant:{type:String,default:"full",reflect:!0},currency:{type:String,default:"USD",reflect:!0},locale:{type:String,default:""},loading:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=null;#c=null;#d=null;#u=null;#f=null;#p=null;#m=null;#g=null;#O=null;#y=null;#b=null;#x=null;#v=null;#S=null;#w="";#k=!1;#A=0;async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#A;this.loading=!0,this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#A)return;this.loading=!1;let n=r&&typeof r=="object"&&r.account?r.account:r;this.account=n,this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{account:n}}))}catch(i){if(e!==this.#A)return;this.loading=!1,this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){this.setAttribute("role","region"),this.#t||(this.#E(),this.#R(),this.#Z(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),this.#t&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}render(){if(!this.#t)return;let t=this.account,e=!t&&!this.getAttribute("data-stream-src");e?this.setAttribute("empty",""):this.removeAttribute("empty"),this.loading?this.setAttribute("aria-busy","true"):this.removeAttribute("aria-busy");let i=t?.status||"";if(i==="past_due"?this.setAttribute("past-due",""):this.removeAttribute("past-due"),i==="trialing"?this.setAttribute("trial",""):this.removeAttribute("trial"),i&&!qD.has(i)&&!this.#k&&(this.#k=!0,console.warn(`[billing-overview-ui] unknown account.status "${i}" \u2014 rendering default chrome.`)),e){this.#T(null),this.#P(null);return}if(!t){this.#T(null);return}this.#T(t),this.#C(t),this.#I(t),this.#L(t),this.#M(t),this.#Q(t),this.#P(t)}#E(){let t=this.querySelector(':scope > script[type="application/json"][data-account]');if(t)try{let e=JSON.parse(t.textContent||"{}");if(e&&typeof e=="object"){let i=e.account&&typeof e.account=="object"?e.account:e;this.account=i}}catch(e){console.warn("[billing-overview-ui] failed to parse <script data-account> JSON:",e?.message)}finally{t.remove()}}#$(t,e){let i=this.querySelectorAll(`:scope > [slot="${t}"]`);for(let r of i)e.appendChild(r)}#R(){this.#w=`bo-h-${Math.random().toString(36).slice(2,8)}`;let t=document.createElement("card-ui");t.setAttribute("data-header","");let e=document.createElement("header"),i=document.createElement("span");i.setAttribute("slot","icon");let r=document.createElement("avatar-ui");r.setAttribute("icon","credit-card"),i.appendChild(r);let n=document.createElement("span");n.setAttribute("slot","heading");let o=document.createElement("h2");o.id=this.#w,o.setAttribute("data-billing-plan-name",""),n.appendChild(o);let a=document.createElement("tag-ui");a.setAttribute("data-billing-status",""),a.setAttribute("size","md"),n.appendChild(a);let l=document.createElement("span");l.setAttribute("slot","description");let h=document.createElement("div");h.setAttribute("data-billing-plan-meta",""),l.appendChild(h);let c=document.createElement("span");c.setAttribute("slot","action");let u=document.createElement("div");u.setAttribute("data-header-actions",""),c.appendChild(u),e.append(i,n,l,c),t.appendChild(e),this.appendChild(t),this.#i=t,this.#s=o,this.#r=h,this.#n=a,this.#a=u,this.#$("header-actions",u);let d=document.createElement("section");d.setAttribute("data-kpis","");let f=(yt,wt,vt)=>{let $t=document.createElement("card-ui");$t.setAttribute("data-kpi-card",yt);let Mt=document.createElement("section"),Ht=document.createElement("stat-ui");return Ht.setAttribute("data-kpi",yt),Ht.setAttribute("label",wt),Ht.setAttribute("value","\u2014"),Ht.setAttribute("icon",vt),Mt.appendChild(Ht),$t.appendChild(Mt),[$t,Ht]},[p,m]=f("spend","Current month","credit-card"),[b,g]=f("seats","Seats","users-three"),[x,S]=f("next-invoice","Next invoice","calendar");d.append(p,b,x),this.appendChild(d),this.#o=d,this.#l=m,this.#h=g,this.#c=S;let w=document.createElement("section");w.setAttribute("data-dunning",""),w.setAttribute("hidden","");let k=document.createElement("alert-ui");k.setAttribute("pattern","dunning"),k.setAttribute("variant","danger"),w.appendChild(k),this.appendChild(w),this.#d=w,this.#u=k;let A=document.createElement("section");A.setAttribute("data-plan-picker","");let E=document.createElement("h3");E.setAttribute("data-section-heading",""),E.textContent="Plan";let $=document.createElement("plan-picker-ui");$.setAttribute("data-billing-plan-picker",""),$.setAttribute("name","billing-overview-plan"),A.append(E,$),this.appendChild(A),this.#f=A,this.#p=E,this.#m=$;let L=document.createElement("div");L.setAttribute("data-before-plan-picker",""),A.insertBefore(L,E),this.#$("before-plan-picker",L);let T=document.createElement("section");T.setAttribute("data-payment-methods","");let q=document.createElement("h3");q.setAttribute("data-section-heading",""),q.textContent="Payment methods";let I=document.createElement("payment-method-list-ui");I.setAttribute("data-billing-payment-methods",""),I.setAttribute("name","billing-overview-payment-method"),T.append(q,I),this.appendChild(T),this.#g=T,this.#O=q,this.#y=I;let z=document.createElement("section");z.setAttribute("data-invoice-history","");let V=document.createElement("h3");V.setAttribute("data-section-heading",""),V.textContent="Invoice history";let U=document.createElement("invoice-history-ui");U.setAttribute("data-billing-invoice-history",""),z.append(V,U),this.appendChild(z),this.#b=z,this.#x=V,this.#v=U;let tt=document.createElement("div");tt.setAttribute("data-after-invoice-history",""),z.appendChild(tt),this.#$("after-invoice-history",tt);let nt=document.createElement("div");nt.setAttribute("data-empty","");let ft=document.createElement("p");ft.setAttribute("data-empty-heading",""),ft.textContent="No billing account loaded";let lt=document.createElement("p");lt.setAttribute("data-empty-description",""),lt.textContent="Pass an `account` snapshot or `data-stream-src` to render the dashboard.",nt.append(ft,lt),this.appendChild(nt),this.#S=nt,this.#$("empty",this)}#T(t){if(!this.#s||!this.#n||!this.#r)return;let e=t?.plan||null,i=e?.name?String(e.name):"Billing overview";this.#s.textContent!==i&&(this.#s.textContent=i);let r=this.#r;if(r.replaceChildren(),e&&Number.isFinite(e.price)){let o=e.currency||this.currency||"USD",a=this.#N(),l=e.cycle==="year"?"/yr":"/mo",h=document.createElement("span");h.setAttribute("data-plan-price",""),h.textContent=`${DE(e.price,o,a)} ${l}`,r.appendChild(h)}if(t?.billingCycle&&t.billingCycle!==e?.cycle){let o=document.createElement("span");o.setAttribute("data-plan-billing-cycle",""),o.textContent=`Billed ${t.billingCycle}ly`,r.appendChild(o)}let n=t?.status||"";if(!n)this.#n.setAttribute("hidden","");else{this.#n.removeAttribute("hidden");let o=ND[n]||"default",a=XD[n]||n;this.#n.getAttribute("variant")!==o&&this.#n.setAttribute("variant",o),this.#n.getAttribute("text")!==a&&this.#n.setAttribute("text",a),this.#n.setAttribute("aria-label",`Account status: ${a}`)}}#C(t){if(!this.#l||!this.#h||!this.#c)return;let e=t?.plan?.currency||this.currency||"USD",i=this.#N();if(Number.isFinite(t?.currentSpend)?this.#l.setAttribute("value",DE(t.currentSpend,e,i)):this.#l.setAttribute("value","\u2014"),t?.seats&&Number.isFinite(t.seats.used)){let r=t.seats.used,n=Number.isFinite(t.seats.total)?t.seats.total:null;this.#h.setAttribute("value",n!=null?`${r} / ${n}`:String(r))}else this.#h.setAttribute("value","\u2014");t?.nextInvoiceDate?this.#c.setAttribute("value",ZD(t.nextInvoiceDate,i)):this.#c.setAttribute("value","\u2014");for(let r of[this.#l,this.#h,this.#c])this.loading?r.setAttribute("loading",""):r.removeAttribute("loading")}#I(t){if(!this.#d||!this.#u)return;let e=t?.dunning||null;if(!(t?.status==="past_due")||!e){this.#d.setAttribute("hidden","");return}this.#d.removeAttribute("hidden");let r=Number.isFinite(e.amount)?e.amount:null,n=e.currency||t?.plan?.currency||this.currency||"USD";if(r!=null?this.#u.setAttribute("amount",String(r)):this.#u.removeAttribute("amount"),this.#u.setAttribute("currency",n),e.dueAt&&this.#u.setAttribute("due-at",String(e.dueAt)),e.cardLast4&&this.#u.setAttribute("card-last4",String(e.cardLast4)),e.reason&&this.#u.setAttribute("reason",String(e.reason)),!this.#u.querySelector(':scope > [slot="actions"]')){let o=document.createElement("button-ui");o.setAttribute("slot","actions"),o.setAttribute("data-dunning-action","update"),o.setAttribute("variant","primary"),o.setAttribute("text","Update payment method"),this.#u.appendChild(o);let a=document.createElement("button-ui");a.setAttribute("slot","actions"),a.setAttribute("data-dunning-action","retry"),a.setAttribute("variant","outline"),a.setAttribute("text","Retry charge"),this.#u.appendChild(a)}}#L(t){if(!this.#f||!this.#m)return;let e=this.variant==="full",i=Array.isArray(t?.plans)&&t.plans.length>0;if(!(e&&i)){this.#f.setAttribute("hidden","");return}this.#f.removeAttribute("hidden"),this.#m.plans=t.plans,t?.plan?.id&&this.#m.setAttribute("current",String(t.plan.id)),this.loading?this.#m.setAttribute("loading",""):this.#m.removeAttribute("loading")}#M(t){if(!this.#y)return;let e=Array.isArray(t?.paymentMethods)?t.paymentMethods:[];this.#y.methods=e,this.loading?this.#y.setAttribute("loading",""):this.#y.removeAttribute("loading")}#Q(t){if(!this.#v)return;let e=Array.isArray(t?.invoices)?t.invoices:[];this.#v.invoices=e;let i=t?.plan?.currency||this.currency||"USD";this.#v.setAttribute("currency",i),this.loading?this.#v.setAttribute("loading",""):this.#v.removeAttribute("loading")}#P(t){this.#w&&this.setAttribute("aria-labelledby",this.#w),!t&&!this.hasAttribute("aria-label")?this.setAttribute("aria-label","No billing account loaded"):t&&this.removeAttribute("aria-label")}#N(){return this.locale?this.locale:typeof document<"u"&&document.documentElement.lang||""}#Z(){let t=u=>{let d=u.target?.closest?.("[data-account-action]");if(!d||!this.contains(d))return;let f=d.getAttribute("data-account-action")||"";f&&(u.stopPropagation(),this.#D(f,"header",{target:d}))};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=u=>{let d=u.detail?.action||"",f=BD[d]||d||"dunning";this.#D(f,"alert-dunning",u.detail)};this.addEventListener("dunning-action",e),this.#e.push(()=>this.removeEventListener("dunning-action",e));let i=u=>{let d=u.detail?.value??u.detail?.plan?.id??"";this.#D("select-plan","plan-picker",{planId:d,...u.detail})};this.addEventListener("plan-change",i),this.#e.push(()=>this.removeEventListener("plan-change",i));let r=u=>{!this.#m||!this.#m.contains(u.target)&&u.target!==this.#m||this.#D("select-plan","plan-picker",u.detail)};this.addEventListener("change",r),this.#e.push(()=>this.removeEventListener("change",r));let n=()=>{this.#D("add-payment-method","payment-method-list",null)};this.addEventListener("add",n),this.#e.push(()=>this.removeEventListener("add",n));let o=u=>{this.#D("remove-payment-method","payment-method-list",u.detail)};this.addEventListener("remove",o),this.#e.push(()=>this.removeEventListener("remove",o));let a=u=>{this.#D("set-default-payment-method","payment-method-list",u.detail)};this.addEventListener("select",a),this.#e.push(()=>this.removeEventListener("select",a));let l=u=>{this.#D("view-invoice","invoice-history",u.detail)};this.addEventListener("invoice-row-click",l),this.#e.push(()=>this.removeEventListener("invoice-row-click",l));let h=u=>{this.#D("download-invoice","invoice-history",u.detail)};this.addEventListener("invoice-export",h),this.#e.push(()=>this.removeEventListener("invoice-export",h));let c=u=>{let d=u.detail?.action||"invoice";this.#D(d,"invoice-history",u.detail)};this.addEventListener("invoice-action",c),this.#e.push(()=>this.removeEventListener("invoice-action",c))}#D(t,e,i){this.dispatchEvent(new CustomEvent("account-action",{bubbles:!0,detail:{action:t,source:e,payload:i||null}}))}};customElements.get("billing-overview-ui")||customElements.define("billing-overview-ui",Ea);P();Pt();var zD=new Set(["draft","open","paid","past-due","void"]),_D={paid:"success",open:"info","past-due":"danger",void:"muted",draft:"neutral"},qE={paid:"Paid",open:"Open","past-due":"Past due",void:"Void",draft:"Draft"},VD=[{value:"",label:"All"},{value:"paid",label:"Paid"},{value:"open",label:"Open"},{value:"past-due",label:"Past due"},{value:"void",label:"Void"},{value:"draft",label:"Draft"}],NE=["Number","Issued","Due","Amount","Currency","Status"];function XE(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",maximumFractionDigits:Number.isInteger(i)?0:2}).format(i)}catch{return`${t||"$"}${i}`}}function BE(s,t){if(!s)return"";try{let e=s instanceof Date?s:new Date(s);return Number.isNaN(e.getTime())?String(s):new Intl.DateTimeFormat(t||void 0,{year:"numeric",month:"short",day:"2-digit"}).format(e)}catch{return String(s)}}function ZE(s,t){return(s||"/invoices/{number}").replace("{number}",encodeURIComponent(t?.number??"")).replace("{id}",encodeURIComponent(t?.id??""))}function Be(s){let t=String(s??"");return t.includes(",")||t.includes('"')||t.includes(`
456
+ `)?'"'+t.replace(/"/g,'""')+'"':t}var Ca=class extends v{static properties={invoices:{type:Array,default:[]},currency:{type:String,default:"USD",reflect:!0},density:{type:String,default:"standard",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},selectable:{type:Boolean,default:!1,reflect:!0},hrefPattern:{type:String,default:"/invoices/{number}",reflect:!0,attribute:"href-pattern"},paginate:{type:Number,default:25,reflect:!0},exportable:{type:Boolean,default:!0,reflect:!0},locale:{type:String,default:""},filter:{type:String,default:"",reflect:!0}};static template=()=>null;static requiredIcons=["download-simple","receipt","magnifying-glass"];#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=!1;#c=0;#d=!1;setFilter(t){let e=t||"";return e&&!zD.has(e)?!1:H(()=>{if(this.filter===e)return!0;let i=this.filter;return this.filter=e,this.dispatchEvent(new CustomEvent("invoice-filter-change",{bubbles:!0,detail:{filter:e,previous:i}})),!0})}exportCsv(){let t=this.#m(),e=[NE.join(",")];for(let r of t){let n=[Be(r.number??""),Be(r.issuedAt??""),Be(r.dueAt??""),Be(Number.isFinite(r.amount)?r.amount:""),Be(r.currency||this.currency||"USD"),Be(r.status??"")];e.push(n.join(","))}let i=e.join(`\r
457
+ `);return new Blob([i],{type:"text/csv;charset=utf-8;"})}getSelected(){if(!this.#o)return[];let t=this.#o.selected||[],e=this.#m();return t.map(i=>e[i]).filter(Boolean)}async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#c;this.setAttribute("loading",""),this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#c)return;this.removeAttribute("loading");let n=Array.isArray(r)?r:Array.isArray(r?.invoices)?r.invoices:[];this.invoices=n,this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{count:n.length}}))}catch(i){if(e!==this.#c)return;this.removeAttribute("loading"),this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){super.connected?.(),this.setAttribute("role","region"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Invoice history"),this.#t||(this.#u(),this.#f(),this.#O(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){super.disconnected?.();for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#h)&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}render(){if(!this.#t)return;(Array.isArray(this.invoices)?this.invoices:[]).length===0&&!this.loading?this.setAttribute("empty",""):this.removeAttribute("empty"),this.#p(),this.#o&&(this.#o.columns=this.#g(),this.#o.data=this.#m(),this.#o.density!==this.density&&(this.#o.density=this.density),!!this.#o.loading!=!!this.loading&&(this.#o.loading=!!this.loading),Number(this.#o.paginate||0)!==Number(this.paginate||0)&&(this.#o.paginate=Number(this.paginate||0)),!!this.#o.selectable!=!!this.selectable&&(this.#o.selectable=!!this.selectable)),this.#s&&this.#s.setAttribute("count",String(this.#m().length)),this.#n&&(this.#n.hidden=!this.exportable)}#u(){let t=this.querySelector(':scope > script[type="application/json"][data-invoices]');if(t)try{let e=JSON.parse(t.textContent||"[]");Array.isArray(e)&&(this.invoices=e)}catch(e){console.warn("[invoice-history-ui] failed to parse <script data-invoices> JSON:",e?.message)}finally{t.remove()}}#f(){let t=document.createElement("div");t.setAttribute("data-toolbar",""),this.appendChild(t),this.#i=t;let e=this.querySelector(':scope > [slot="toolbar"]');if(e)t.appendChild(e);else{let n=document.createElement("table-toolbar-ui");n.setAttribute("data-default-toolbar",""),n.setAttribute("text","Invoices");let o=document.createElement("div");o.setAttribute("data-invoice-filter",""),o.setAttribute("role","group"),o.setAttribute("aria-label","Filter invoices by status"),o.setAttribute("slot","actions"),n.appendChild(o);let a=document.createElement("button-ui");a.setAttribute("data-export",""),a.setAttribute("slot","actions"),a.setAttribute("variant","outline"),a.setAttribute("size","sm"),a.setAttribute("text","Export CSV"),a.setAttribute("icon","download-simple"),n.appendChild(a),t.appendChild(n),this.#s=n,this.#r=o,this.#n=a}let i=document.createElement("div");i.setAttribute("data-table-host",""),this.appendChild(i),this.#a=i;let r=document.createElement("table-ui");if(r.id=this.id?`${this.id}__table`:`invoice-history-${Math.random().toString(36).slice(2,8)}`,r.setAttribute("data-invoice-table",""),r.setAttribute("sortable",""),i.appendChild(r),this.#o=r,this.#s&&this.#s.setAttribute("for",r.id),!this.querySelector(':scope > [slot="empty"]')){let n=document.createElement("empty-state-ui");n.setAttribute("data-empty",""),n.setAttribute("icon","receipt"),n.setAttribute("heading","No invoices yet"),n.setAttribute("description","Invoices will appear here once issued."),this.appendChild(n),this.#l=n}}#p(){if(!this.#r)return;if(this.#r.children.length===0)for(let e of VD){let i=document.createElement("button-ui");i.setAttribute("data-filter-chip",""),i.setAttribute("data-filter-value",e.value),i.setAttribute("size","sm"),i.setAttribute("text",e.label),this.#r.appendChild(i)}let t=this.filter||"";for(let e of this.#r.querySelectorAll("[data-filter-chip]"))(e.getAttribute("data-filter-value")||"")===t?(e.setAttribute("variant","primary"),e.setAttribute("aria-pressed","true")):(e.setAttribute("variant","ghost"),e.setAttribute("aria-pressed","false"))}#m(){let t=Array.isArray(this.invoices)?this.invoices:[],e=this.filter||"";return e?t.filter(i=>(i?.status||"")===e):t}#g(){let t=this.locale||typeof document<"u"&&document.documentElement?.lang||"",e=this.currency||"USD";return[{key:"number",label:"Invoice",sortable:!0,wrap:!1},{key:"issuedAt",label:"Issued",sortable:!0,format:i=>BE(i,t)},{key:"dueAt",label:"Due",sortable:!0,format:i=>BE(i,t)},{key:"amount",label:"Amount",sortable:!0,align:"end",render:(i,r,n)=>{let o=r?.currency||e,a=document.createElement("span");return a.setAttribute("data-invoice-amount",""),a.textContent=XE(i,o,t),n.dataset.align="end",a},format:(i,r)=>XE(i,r?.currency||e,t)},{key:"status",label:"Status",sortable:!0,render:i=>{let r=String(i||"").toLowerCase(),n=_D[r]||"neutral",o=qE[r]||(i?String(i):"\u2014"),a=document.createElement("badge-ui");return a.setAttribute("data-invoice-status",""),a.setAttribute("variant",n),a.setAttribute("text",o),a.setAttribute("aria-label",o),a},format:i=>qE[String(i||"").toLowerCase()]||(i?String(i):"")},{key:"actions",label:"",sortable:!1,align:"end",accessor:i=>i,render:(i,r)=>{let n=document.createElement("span");n.setAttribute("data-invoice-actions","");let o=document.createElement("button-ui");o.setAttribute("data-invoice-action","view"),o.setAttribute("data-invoice-id",String(r?.id??r?.number??"")),o.setAttribute("size","sm"),o.setAttribute("variant","ghost"),o.setAttribute("text","View"),n.appendChild(o);let a=document.createElement("button-ui");return a.setAttribute("data-invoice-action","download"),a.setAttribute("data-invoice-id",String(r?.id??r?.number??"")),a.setAttribute("size","sm"),a.setAttribute("variant","ghost"),a.setAttribute("icon","download-simple"),a.setAttribute("aria-label",`Download invoice ${r?.number??""}`),n.appendChild(a),n}}]}#O(){let t=o=>{let a=o.target?.closest?.("[data-filter-chip]");if(!a||!this.#r?.contains(a))return;o.stopPropagation();let l=a.getAttribute("data-filter-value")||"";this.setFilter(l)};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=o=>{let a=o?.detail;if(!a||a.key==="actions")return;let l=a.row;if(!l)return;let h=ZE(this.hrefPattern,l),c=new CustomEvent("invoice-row-click",{bubbles:!0,cancelable:!0,detail:{invoice:l,href:h}});if(this.dispatchEvent(c)&&typeof window<"u"&&window.location?.assign)try{window.location.assign(h)}catch{}};this.addEventListener("cell-click",e),this.#e.push(()=>this.removeEventListener("cell-click",e));let i=o=>{let a=o.target?.closest?.("button-ui[data-invoice-action]");if(!a||!this.#a?.contains(a))return;o.stopPropagation();let l=a.getAttribute("data-invoice-action"),h=a.getAttribute("data-invoice-id")||"",c=(this.invoices||[]).find(u=>String(u?.id??u?.number??"")===h);if(c){if(l==="view"){let u=ZE(this.hrefPattern,c),d=new CustomEvent("invoice-row-click",{bubbles:!0,cancelable:!0,detail:{invoice:c,href:u}});if(this.dispatchEvent(d)&&typeof window<"u"&&window.location?.assign)try{window.location.assign(u)}catch{}}else if(l==="download"){let u=this.#y(c);this.dispatchEvent(new CustomEvent("invoice-export",{bubbles:!0,cancelable:!0,detail:{blob:u,rowCount:1,invoice:c}}))}}};this.addEventListener("press",i),this.addEventListener("click",i),this.#e.push(()=>this.removeEventListener("press",i)),this.#e.push(()=>this.removeEventListener("click",i));let r=o=>{let a=o.target?.closest?.("button-ui[data-export]");if(!a||!this.#i?.contains(a))return;o.stopPropagation();let l=this.exportCsv(),h=new CustomEvent("invoice-export",{bubbles:!0,cancelable:!0,detail:{blob:l,rowCount:this.#m().length}});if(this.dispatchEvent(h)&&typeof document<"u"&&typeof URL<"u")try{let u=URL.createObjectURL(l),d=document.createElement("a");d.href=u,d.download="invoices.csv",document.body.appendChild(d),d.click(),d.remove(),setTimeout(()=>URL.revokeObjectURL(u),0)}catch{}};this.addEventListener("press",r),this.addEventListener("click",r),this.#e.push(()=>this.removeEventListener("press",r)),this.#e.push(()=>this.removeEventListener("click",r));let n=o=>{if(o.target!==this.#o)return;let a=this.getSelected();this.dispatchEvent(new CustomEvent("invoice-selection-change",{bubbles:!0,detail:{selected:a}}))};this.addEventListener("select",n),this.#e.push(()=>this.removeEventListener("select",n))}#y(t){let e=[NE.join(","),[Be(t.number??""),Be(t.issuedAt??""),Be(t.dueAt??""),Be(Number.isFinite(t.amount)?t.amount:""),Be(t.currency||this.currency||"USD"),Be(t.status??"")].join(",")];return new Blob([e.join(`\r
458
+ `)],{type:"text/csv;charset=utf-8;"})}};customElements.get("invoice-history-ui")||customElements.define("invoice-history-ui",Ca);P();Pt();var jD=new Set(["draft","open","paid","past-due","void"]),WD={draft:"default",open:"info",paid:"success","past-due":"warning",void:"default"},FD={draft:"Draft",open:"Open",paid:"Paid","past-due":"Past due",void:"Void"};function Dd(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(i)}catch{return`${t||"$"}${i.toFixed(2)}`}}function zE(s,t){if(!s)return"";try{let e=new Date(s);return Number.isNaN(e.getTime())?String(s):new Intl.DateTimeFormat(t||void 0,{year:"numeric",month:"short",day:"numeric"}).format(e)}catch{return String(s)}}var $a=class extends v{static get properties(){return{invoice:{type:Object,default:null},status:{type:String,default:"draft",reflect:!0},currency:{type:String,default:"USD",reflect:!0},density:{type:String,default:"standard",reflect:!0},loading:{type:Boolean,default:!1,reflect:!0},printable:{type:Boolean,default:!0,reflect:!0},locale:{type:String,default:""}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=null;#h=null;#c=null;#d=null;#u=null;#f=null;#p=null;#m="";#g=!1;#O=!1;#y=0;#b="";print(){if(typeof globalThis.window?.print=="function"){try{globalThis.window.print()}catch(t){this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"print-unavailable",message:String(t?.message||t)}}))}return}this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"print-unavailable"}}))}async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#y;this.loading=!0,this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#y)return;this.loading=!1;let n=r&&typeof r=="object"&&r.invoice?r.invoice:r;if(this.invoice=n,n?.status){this.#g=!0;try{this.status=String(n.status)}finally{this.#g=!1}}let o=n?.number||"";this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{invoiceNumber:o}})),this.#b=o}catch(i){if(e!==this.#y)return;this.loading=!1,this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){this.setAttribute("role","region"),this.#t||(this.#x(),this.#S(),this.#R(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#g)&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}render(){if(!this.#t)return;let t=this.invoice,e=!t&&!this.getAttribute("data-stream-src");e?this.setAttribute("empty",""):this.removeAttribute("empty"),this.loading?this.setAttribute("aria-busy","true"):this.removeAttribute("aria-busy");let r=(this.hasAttribute("status")?this.getAttribute("status"):"")||t?.status||this.status||"draft";if(jD.has(r)||this.#O||(this.#O=!0,console.warn(`[invoice-detail-ui] unknown status "${r}" \u2014 rendering default badge.`)),e){this.#w(null,r),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","No invoice loaded");return}if(!t){this.#w(null,r);return}this.#w(t,r),this.#k(t),this.#A(t),this.#E(t),this.#$(t)}#x(){let t=this.querySelector(':scope > script[type="application/json"][data-invoice]');if(t)try{let e=JSON.parse(t.textContent||"{}");if(e&&typeof e=="object"){let i=e.invoice&&typeof e.invoice=="object"?e.invoice:e;if(this.invoice=i,i?.status){this.#g=!0;try{this.status=String(i.status)}finally{this.#g=!1}}}}catch(e){console.warn("[invoice-detail-ui] failed to parse <script data-invoice> JSON:",e?.message)}finally{t.remove()}}#v(t,e){let i=this.querySelectorAll(`:scope > [slot="${t}"]`);for(let r of i)e.appendChild(r)}#S(){this.#m=`inv-h-${Math.random().toString(36).slice(2,8)}`;let t=document.createElement("header");t.setAttribute("data-header","");let e=document.createElement("div");e.setAttribute("data-header-title","");let i=document.createElement("h2");i.id=this.#m,i.setAttribute("data-invoice-number",""),e.appendChild(i);let r=document.createElement("tag-ui");r.setAttribute("data-invoice-status",""),r.setAttribute("size","md"),e.appendChild(r);let n=document.createElement("div");n.setAttribute("data-header-meta","");let o=document.createElement("div");o.setAttribute("data-header-actions",""),o.setAttribute("data-invoice-actions",""),t.append(e,n,o),this.appendChild(t),this.#i=t,this.#s=i,this.#r=r,this.#n=n,this.#a=o,this.#v("header-actions",o);let a=document.createElement("section");a.setAttribute("data-parties","");let l=document.createElement("div");l.setAttribute("data-customer","");let h=document.createElement("div");h.setAttribute("data-customer-default",""),l.appendChild(h),this.#l=h;let c=document.createElement("div");c.setAttribute("data-remit-to","");let u=document.createElement("div");u.setAttribute("data-remit-to-default",""),c.appendChild(u),this.#h=u,a.append(l,c),this.appendChild(a),this.#o=a,this.#v("customer-block",l),this.#v("remit-to-block",c);let d=document.createElement("section");d.setAttribute("data-lines","");let f=document.createElement("card-ui");f.setAttribute("data-lines-card",""),f.setAttribute("padding","none");let p=document.createElement("section");p.setAttribute("bleed",""),f.appendChild(p);let m=document.createElement("table-ui");m.setAttribute("data-lines-table",""),m.setAttribute("density",this.density||"standard"),p.appendChild(m),d.appendChild(f),this.appendChild(d),this.#c=d,this.#d=m;let b=document.createElement("section");b.setAttribute("data-totals",""),this.appendChild(b),this.#u=b;let g=document.createElement("footer");g.setAttribute("data-footer","");let x=document.createElement("div");x.setAttribute("data-footer-notes",""),g.appendChild(x),this.appendChild(g),this.#f=g,this.#v("footer",g);let S=document.createElement("empty-state-ui");S.setAttribute("data-empty",""),S.setAttribute("icon","receipt"),S.setAttribute("heading","No invoice loaded"),S.setAttribute("description","Pass an `invoice` record or `data-stream-src` to render an invoice."),this.appendChild(S),this.#p=S}#w(t,e){if(!this.#s||!this.#r||!this.#n)return;let i=t?.number?String(t.number):"";this.#s.textContent!==i&&(this.#s.textContent=i);let r=WD[e]||"default",n=FD[e]||(e?String(e):"Draft");if(this.#r.getAttribute("variant")!==r&&this.#r.setAttribute("variant",r),this.#r.getAttribute("text")!==n&&this.#r.setAttribute("text",n),this.#r.setAttribute("aria-label",`Status: ${n}`),t?this.#r.removeAttribute("hidden"):this.#r.setAttribute("hidden",""),this.#n.replaceChildren(),!t)return;let o=this.locale||(typeof document<"u"?document.documentElement.lang:"");if(t.issuedAt){let a=document.createElement("span");a.setAttribute("data-issued",""),a.textContent=`Issued ${zE(t.issuedAt,o)}`,this.#n.appendChild(a)}if(t.dueAt){let a=document.createElement("span");a.setAttribute("data-due",""),a.textContent=`Due ${zE(t.dueAt,o)}`,this.#n.appendChild(a)}}#k(t){if(!(!this.#l||!this.#h)){if(this.#l.replaceChildren(),t?.customer){let e=document.createElement("div");if(e.setAttribute("data-party-heading",""),e.textContent="Billed to",this.#l.appendChild(e),t.customer.name){let i=document.createElement("div");i.setAttribute("data-party-name",""),i.textContent=String(t.customer.name),this.#l.appendChild(i)}if(t.customer.email){let i=document.createElement("div");i.setAttribute("data-party-email",""),i.textContent=String(t.customer.email),this.#l.appendChild(i)}if(t.customer.address){let i=document.createElement("div");i.setAttribute("data-party-address",""),i.textContent=String(t.customer.address),this.#l.appendChild(i)}}if(this.#h.replaceChildren(),t?.remitTo){let e=document.createElement("div");if(e.setAttribute("data-party-heading",""),e.textContent="Remit to",this.#h.appendChild(e),t.remitTo.name){let i=document.createElement("div");i.setAttribute("data-party-name",""),i.textContent=String(t.remitTo.name),this.#h.appendChild(i)}if(t.remitTo.address){let i=document.createElement("div");i.setAttribute("data-party-address",""),i.textContent=String(t.remitTo.address),this.#h.appendChild(i)}}}}#A(t){if(!this.#d)return;let e=t?.currency||this.currency||"USD",i=this.locale||(typeof document<"u"?document.documentElement.lang:"");this.#d.columns=[{key:"description",label:"Description",flex:1},{key:"qty",label:"Qty",width:80,format:n=>String(n??"")},{key:"unitAmount",label:"Unit",width:120,format:n=>Dd(n,e,i)},{key:"amount",label:"Amount",width:140,format:n=>Dd(n,e,i)}];let r=Array.isArray(t?.lines)?t.lines:[];this.#d.data=r.map((n,o)=>({__row:o,description:n?.description??"",qty:n?.qty??"",unitAmount:n?.unitAmount??0,amount:n?.amount??0})),this.#d.getAttribute("density")!==this.density&&this.#d.setAttribute("density",this.density||"standard")}#E(t){if(!this.#u)return;let e=t?.currency||this.currency||"USD",i=this.locale||(typeof document<"u"?document.documentElement.lang:"");if(this.#u.replaceChildren(),!t)return;let r=[{key:"subtotal",label:"Subtotal",value:t.subtotal},{key:"tax",label:"Tax",value:t.tax}];Number.isFinite(t.discount)&&t.discount>0&&r.push({key:"discount",label:"Discount",value:-Math.abs(t.discount)});for(let n of r){if(!Number.isFinite(n.value))continue;let o=document.createElement("div");o.setAttribute("data-totals-row",""),o.setAttribute("data-totals-key",n.key);let a=document.createElement("span");a.setAttribute("data-totals-label",""),a.textContent=n.label;let l=document.createElement("span");l.setAttribute("data-totals-value",""),l.textContent=Dd(n.value,e,i),o.append(a,l),this.#u.appendChild(o)}if(Number.isFinite(t.total)){let n=document.createElement("div");n.setAttribute("data-totals-row",""),n.setAttribute("data-totals-key","total"),n.setAttribute("data-grand-total","");let o=document.createElement("span");o.setAttribute("data-totals-label",""),o.textContent="Total";let a=document.createElement("span");a.setAttribute("data-totals-value",""),a.textContent=Dd(t.total,e,i),n.append(o,a),this.#u.appendChild(n)}}#$(t){t&&this.#m&&this.setAttribute("aria-labelledby",this.#m)}#R(){let t=i=>{let r=i.target?.closest?.("[data-invoice-action]");if(!r||!this.contains(r))return;let n=r.getAttribute("data-invoice-action")||"";if(!n)return;let o=this.invoice?.number||"";i.stopPropagation(),this.dispatchEvent(new CustomEvent("invoice-action",{bubbles:!0,detail:{action:n,invoiceNumber:o}}))};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=i=>{if(!this.#c)return;let n=(i.composedPath?i.composedPath():[]).find(l=>l?.getAttribute&&l.getAttribute("data-row")!=null);if(!n||!this.#c.contains(n))return;let o=Number(n.getAttribute("data-row")),a=Array.isArray(this.invoice?.lines)?this.invoice.lines[o]:null;!Number.isFinite(o)||a==null||this.dispatchEvent(new CustomEvent("line-item-click",{bubbles:!0,detail:{index:o,lineItem:a}}))};this.addEventListener("click",e),this.#e.push(()=>this.removeEventListener("click",e))}};customElements.get("invoice-detail-ui")||customElements.define("invoice-detail-ui",$a);Pt();var UD=[{brand:"amex",re:/^3[47]/},{brand:"visa",re:/^4/},{brand:"mastercard",re:/^(5[1-5]|2[2-7])/},{brand:"discover",re:/^6(011|5)/}];function qd(s){if(!s)return"unknown";for(let{brand:t,re:e}of UD)if(e.test(s))return t;return"unknown"}function Nd(s){return String(s||"").replace(/\D+/g,"").slice(0,19)}function nK(s,t){return s?t==="amex"?s.replace(/^(\d{0,4})(\d{0,6})(\d{0,5}).*$/,(e,i,r,n)=>[i,r,n].filter(Boolean).join(" ")):s.match(/.{1,4}/g)?.join(" ")??"":""}function _E(s){if(!s||s.length<12)return!1;let t=0,e=!1;for(let i=s.length-1;i>=0;i--){let r=s.charCodeAt(i)-48;if(r<0||r>9)return!1;e&&(r*=2,r>9&&(r-=9)),t+=r,e=!e}return t%10===0}function VE(s){if(!s)return null;let t=String(s).replace(/\s+/g,"").match(/^(\d{1,2})\/(\d{2}|\d{4})$/);if(!t)return null;let e=Number(t[1]),i=Number(t[2]);return i<100&&(i+=2e3),!Number.isFinite(e)||!Number.isFinite(i)?null:{month:e,year:i}}function jE(s){let t=VE(s);if(!t)return"expiry-format";let{month:e,year:i}=t;if(e<1||e>12)return"expiry-month";let r=new Date,n=r.getFullYear(),o=r.getMonth()+1;return i<n||i===n&&e<o?"expiry-past":i>n+50?"expiry-far":null}function WE(s,t){let e=String(s||"").replace(/\D+/g,""),i=t==="amex"?4:3;return e.length!==i?"cvc-length":null}function YD(s){let t=Math.random().toString(36).slice(2);return`pm_local_${Date.now().toString(36)}_${t}_${String(s).slice(0,4)}`}var HD=["US","CA","GB","DE","FR","AU"],GD={US:"United States",CA:"Canada",GB:"United Kingdom",DE:"Germany",FR:"France",AU:"Australia",JP:"Japan",ES:"Spain",IT:"Italy",NL:"Netherlands",SE:"Sweden",IE:"Ireland",SG:"Singapore",IN:"India",BR:"Brazil",MX:"Mexico"};function KD(s){return GD[s]||s}var Pa=class extends R{static labelDeprecated=!1;static get properties(){return{...R.properties,name:{type:String,default:"paymentMethod",reflect:!0},value:{type:String,default:"",reflect:!0},prefill:{type:String,default:"",attribute:"prefill"},countries:{type:Array,default:[]},defaultCountry:{type:String,default:"US",reflect:!0,attribute:"default-country"},requireBillingAddress:{type:Boolean,default:!1,reflect:!0,attribute:"require-billing-address"},disabled:{type:Boolean,default:!1,reflect:!0},required:{type:Boolean,default:!1,reflect:!0},error:{type:String,default:"",reflect:!0},autofocus:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a={name:null,cardNumber:null,expiry:null,cvc:null,country:null,postalCode:null,addressLine1:null,addressLine2:null};#o={name:null,cardNumber:null,expiry:null,cvc:null,country:null,postalCode:null,addressLine1:null,addressLine2:null};#l="unknown";#h=!1;#c=null;#d=null;#u=!1;async tokenize(){if(this.#u)return Promise.reject(new Error("tokenize-inflight"));this.#u=!0,this.setAttribute("tokenizing","");try{let t=this.#A();if(!t.ok){let r=new Error(t.message);throw r.code=t.code,r.field=t.field,this.dispatchEvent(new CustomEvent("payment-method-error",{bubbles:!0,detail:{message:t.message,code:t.code,field:t.field}})),this.setAttribute("aria-invalid","true"),r}let e=t.detail;this.#h=!0;try{this.value=YD(e.last4)}finally{this.#h=!1}this.syncValue(),this.removeAttribute("aria-invalid");let i={token:this.value,...e};return this.dispatchEvent(new CustomEvent("submit-payment-method",{bubbles:!0,detail:i})),i}finally{this.removeAttribute("tokenizing"),this.#u=!1}}reset(){H(()=>{for(let t of Object.keys(this.#o)){let e=this.#o[t];e&&(e.value="",e.removeAttribute("error"))}this.#o.country&&(this.#o.country.value=this.defaultCountry||"US"),this.#h=!0;try{this.value="",this.error=""}finally{this.#h=!1}this.syncValue(),this.#l="unknown",this.removeAttribute("aria-invalid"),this.removeAttribute("error"),this.#w()})}syncValue(t){this.internals.setFormValue(this.value||""),this.required&&!this.value?this.internals.setValidity({valueMissing:!0},this.getAttribute("data-msg-required")||"Payment method required.",this):this.internals.setValidity({})}connected(){super.connected(),this.setAttribute("role","group"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Payment method form"),this.#t||(this.#f(),this.#g(),this.#t=!0),H(()=>this.render()),this.autofocus&&requestAnimationFrame(()=>{this.#o.name?.focus?.()})}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#h)){if(t==="prefill"&&e!==i)this.render();else if(t==="disabled"&&e!==i)this.#x();else if(t==="error"&&e!==i)this.#v();else if(t==="require-billing-address"&&e!==i)this.#b();else if(t==="default-country"&&e!==i){let r=this.#o.country;r&&!r.value&&(r.value=i||"US")}}}render(){this.#t&&(this.#y(),this.#b(),this.#x(),this.#v(),this.#S(),this.#w())}#f(){let t=document.createElement("alert-ui");t.setAttribute("data-alert",""),t.setAttribute("variant","danger"),t.setAttribute("icon","warning-circle"),t.hidden=!0,this.appendChild(t),this.#i=t;let e=document.createElement("div");e.setAttribute("data-summary",""),e.hidden=!0;let i=document.createElement("icon-ui");i.setAttribute("name","credit-card"),i.setAttribute("aria-hidden","true"),i.setAttribute("data-summary-icon",""),e.appendChild(i);let r=document.createElement("div");r.setAttribute("data-summary-text",""),e.appendChild(r);let n=document.createElement("button-ui");n.setAttribute("data-summary-edit",""),n.setAttribute("variant","ghost"),n.setAttribute("size","sm"),n.setAttribute("text","Edit card"),e.appendChild(n),this.appendChild(e),this.#s=e,this.#r=n;let o=document.createElement("div");o.setAttribute("data-grid",""),this.appendChild(o),this.#n=o,this.#a.name=this.#p("name",{label:"Name on card",required:!0,area:"name",input:{autocomplete:"cc-name",placeholder:"Pat Doe"}}),this.#o.name=this.#a.name.querySelector("input-ui"),this.#a.cardNumber=this.#p("cardNumber",{label:"Card number",required:!0,area:"card",input:{type:"text",inputmode:"numeric",autocomplete:"cc-number",placeholder:"1234 1234 1234 1234",prefix:"credit-card",maxlength:23}}),this.#o.cardNumber=this.#a.cardNumber.querySelector("input-ui");let a=document.createElement("span");a.setAttribute("slot","trailing"),a.setAttribute("data-brand-badge",""),this.#o.cardNumber.appendChild(a),this.#a.expiry=this.#p("expiry",{label:"Expiry",required:!0,area:"expiry",input:{type:"text",inputmode:"numeric",autocomplete:"cc-exp",placeholder:"MM/YY",maxlength:7}}),this.#o.expiry=this.#a.expiry.querySelector("input-ui"),this.#a.cvc=this.#p("cvc",{label:"CVC",required:!0,area:"cvc",input:{type:"text",inputmode:"numeric",autocomplete:"cc-csc",placeholder:"123",maxlength:4}}),this.#o.cvc=this.#a.cvc.querySelector("input-ui"),this.#a.country=this.#p("country",{label:"Country",required:!0,area:"country",kind:"select",input:{autocomplete:"country"},seedOptions:this.#m(),seedValue:this.defaultCountry||"US"}),this.#o.country=this.#a.country.querySelector("select-ui"),this.#a.postalCode=this.#p("postalCode",{label:"Postal code",required:!0,area:"postal",input:{type:"text",inputmode:"text",autocomplete:"postal-code",placeholder:"94105",maxlength:12}}),this.#o.postalCode=this.#a.postalCode.querySelector("input-ui"),this.#a.addressLine1=this.#p("addressLine1",{label:"Address line 1",required:!1,area:"address1",input:{type:"text",autocomplete:"address-line1",placeholder:"123 Main St",maxlength:100}}),this.#o.addressLine1=this.#a.addressLine1.querySelector("input-ui"),this.#a.addressLine1.hidden=!0,this.#a.addressLine2=this.#p("addressLine2",{label:"Address line 2 (optional)",required:!1,area:"address2",input:{type:"text",autocomplete:"address-line2",placeholder:"Apt 4B",maxlength:100}}),this.#o.addressLine2=this.#a.addressLine2.querySelector("input-ui"),this.#a.addressLine2.hidden=!0;let l=document.createElement("div");l.setAttribute("data-legal",""),this.appendChild(l),this.#c=l;for(let h of[...this.children])h!==l&&h.getAttribute&&h.getAttribute("slot")==="legal"&&l.appendChild(h)}#p(t,e){let i=document.createElement("field-ui");i.setAttribute("label",e.label),e.required&&i.setAttribute("required",""),i.setAttribute("data-field",t),i.style.gridArea=e.area;let r;if(e.kind==="select"){if(r=document.createElement("select-ui"),Array.isArray(e.seedOptions))for(let n of e.seedOptions){let o=document.createElement("option");o.value=n.value,o.textContent=n.label,e.seedValue&&n.value===e.seedValue&&o.setAttribute("selected",""),r.appendChild(o)}}else r=document.createElement("input-ui");r.setAttribute("name",t),r.setAttribute("data-control",t),e.required&&r.setAttribute("required","");for(let[n,o]of Object.entries(e.input||{}))o==null||o===""||r.setAttribute(n,String(o));return i.appendChild(r),this.#n.appendChild(i),i}#m(){return(Array.isArray(this.countries)&&this.countries.length>0?this.countries:HD).map(e=>({value:e,label:KD(e)}))}#g(){let t=r=>{if(!this.#o.cardNumber||r.target!==this.#o.cardNumber)return;let n=String(this.#o.cardNumber.value||""),o=Nd(n),a=qd(o);a!==this.#l&&(this.#l=a,this.#w()),this.#O()};this.addEventListener("input",t),this.#e.push(()=>this.removeEventListener("input",t));let e=r=>{r.target!==this&&this.#O()};this.addEventListener("change",e),this.#e.push(()=>this.removeEventListener("change",e));let i=()=>{this.disabled||(this.removeAttribute("prefilled"),this.#s&&(this.#s.hidden=!0),this.#n&&(this.#n.hidden=!1))};this.#r.addEventListener("click",i),this.#r.addEventListener("press",i),this.#e.push(()=>{this.#r.removeEventListener("click",i),this.#r.removeEventListener("press",i)})}#O(){let t=Nd(this.#o.cardNumber?.value),e=qd(t),i=this.#k();this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{valid:i.ok,brand:e}}))}#y(){let t=this.#o.country;if(!t)return;let e=this.#m();Array.isArray(t.options)&&t.options.length===e.length&&t.options.every((r,n)=>r?.value===e[n].value&&r?.label===e[n].label)||(t.options=e),t.value||(t.value=this.defaultCountry||e[0]?.value||"US")}#b(){let t=!!this.requireBillingAddress;this.#a.addressLine1&&(this.#a.addressLine1.hidden=!t),this.#a.addressLine2&&(this.#a.addressLine2.hidden=!t)}#x(){let t=!!this.disabled;for(let e of Object.values(this.#o))e&&(t?e.setAttribute("disabled",""):e.removeAttribute("disabled"))}#v(){if(!this.#i)return;let t=this.error||"";t?(this.#i.setAttribute("text",t),this.#i.hidden=!1,this.setAttribute("aria-invalid","true")):(this.#i.removeAttribute("text"),this.#i.hidden=!0,this.removeAttribute("aria-invalid"))}#S(){if(!this.#s)return;let t=this.#E();if(!t||this.hasAttribute("prefilled-dismissed")){this.#s.hidden=!0,this.#n&&(this.#n.hidden=!1),this.removeAttribute("prefilled");return}let e=this.#s.querySelector(":scope > [data-summary-text]");if(e){let i=(t.brand||"Card").toUpperCase(),r=t.last4||"\u2022\u2022\u2022\u2022",n=t.expMonth&&t.expYear?` \xB7 expires ${String(t.expMonth).padStart(2,"0")}/${String(t.expYear).slice(-2)}`:"";e.textContent=`${i} ending in ${r}${n}`}this.#s.hidden=!1,this.#n&&(this.#n.hidden=!0),this.setAttribute("prefilled","")}#w(){let t=this.#o.cardNumber;if(!t)return;let e=t.querySelector(":scope > [data-brand-badge]");if(!e)return;if(this.#l==="unknown"||!this.#l){e.replaceChildren();return}let i=e.querySelector(":scope > [data-brand]");if(i&&i.getAttribute("data-brand")===this.#l)return;e.replaceChildren();let r=document.createElement("span");r.setAttribute("data-brand",this.#l),r.textContent=this.#l.toUpperCase(),e.appendChild(r)}#k(){let t=Nd(this.#o.cardNumber?.value);return t?_E(t)?jE(this.#o.expiry?.value)?{ok:!1}:WE(this.#o.cvc?.value,qd(t))?{ok:!1}:(this.#o.name?.value||"").trim()?(this.#o.postalCode?.value||"").trim()?{ok:!0}:{ok:!1}:{ok:!1}:{ok:!1}:{ok:!1}}#A(){for(let d of Object.values(this.#o))d?.removeAttribute?.("error");let t=String(this.#o.name?.value||"").trim();if(!t)return this.#o.name?.setAttribute("error","Name on card is required."),{ok:!1,message:"Name on card is required.",code:"validation-failed",field:"name"};let e=this.#o.cardNumber?.value||"",i=Nd(e);if(!i)return this.#o.cardNumber?.setAttribute("error","Card number is required."),{ok:!1,message:"Card number is required.",code:"validation-failed",field:"cardNumber"};if(!_E(i))return this.#o.cardNumber?.setAttribute("error","Card number is invalid."),{ok:!1,message:"Card number is invalid.",code:"card-invalid",field:"cardNumber"};let r=jE(this.#o.expiry?.value||"");if(r){let d=r==="expiry-past"?"Card has expired.":r==="expiry-month"?"Expiry month must be 01-12.":r==="expiry-far"?"Expiry year is too far in the future.":"Expiry must be MM/YY.";return this.#o.expiry?.setAttribute("error",d),{ok:!1,message:d,code:r==="expiry-past"?"expired":"validation-failed",field:"expiry"}}let n=qd(i);if(WE(this.#o.cvc?.value||"",n)){let f=`CVC must be ${n==="amex"?4:3} digits.`;return this.#o.cvc?.setAttribute("error",f),{ok:!1,message:f,code:"cvc-invalid",field:"cvc"}}let a=String(this.#o.country?.value||this.defaultCountry||"US");if(!String(this.#o.postalCode?.value||"").trim())return this.#o.postalCode?.setAttribute("error","Postal code is required."),{ok:!1,message:"Postal code is required.",code:"validation-failed",field:"postalCode"};if(this.requireBillingAddress&&!String(this.#o.addressLine1?.value||"").trim())return this.#o.addressLine1?.setAttribute("error","Address is required."),{ok:!1,message:"Address is required.",code:"validation-failed",field:"addressLine1"};let h=VE(this.#o.expiry.value);return{ok:!0,detail:{last4:i.slice(-4),brand:n,expMonth:h.month,expYear:h.year,name:t,country:a}}}#E(){let t=this.prefill||this.getAttribute("prefill")||"";if(!t)return null;try{let e=JSON.parse(t);return!e||typeof e!="object"?null:e}catch{return null}}};customElements.get("payment-method-form-ui")||customElements.define("payment-method-form-ui",Pa);Pt();var JD=new Set(["visa","mastercard","amex","discover","jcb","unionpay","diners","paypal","apple-pay","google-pay","ach","sepa"]),FE=new Set(["card","bank","wallet"]),UE={paypal:"paypal-logo","apple-pay":"apple-logo",ach:"bank",sepa:"bank"},tq={card:"credit-card",bank:"bank",wallet:"credit-card"},YE={visa:"Visa",mastercard:"Mastercard",amex:"American Express",discover:"Discover",jcb:"JCB",unionpay:"UnionPay",diners:"Diners Club",paypal:"PayPal","apple-pay":"Apple Pay","google-pay":"Google Pay",ach:"Bank account",sepa:"SEPA"};function HE(s){let t=(s?.brand||"").toLowerCase();if(UE[t])return UE[t];let e=(s?.type||"card").toLowerCase();return tq[e]||"credit-card"}function GE(s){let t=(s?.brand||"").toLowerCase();if(YE[t])return YE[t];let e=(s?.type||"card").toLowerCase();return e==="bank"?"Bank account":e==="wallet"?"Wallet":"Card"}function XO(s){let t=(s?.last4||"").trim(),e=(s?.holder||"").trim(),i=GE(s);return(s?.type||"card").toLowerCase()==="bank"&&e?e:t?`${i} \xB7\xB7\xB7\xB7 ${t}`:e?`${i} \u2014 ${e}`:i}function BO(s){let t=(s?.expiry||"").trim();if(!t)return"";let e="",i="",r=t.match(/^(\d{1,2})\/(\d{2}|\d{4})$/);if(r)e=r[1].padStart(2,"0"),i=r[2].length===4?r[2].slice(-2):r[2];else{let n=t.match(/^(\d{4})-(\d{2})-\d{2}$/);n&&(i=n[1].slice(-2),e=n[2])}return!e||!i?"":`Expires ${e}/${i}`}var Qa=class extends R{static get properties(){return{...R.properties,methods:{type:Array,default:[]},value:{type:String,default:"",reflect:!0},"add-label":{type:String,default:"Add payment method",attribute:"add-label"},"add-icon":{type:String,default:"plus",attribute:"add-icon"},"no-add":{type:Boolean,default:!1,reflect:!0,attribute:"no-add"},"no-remove":{type:Boolean,default:!1,reflect:!0,attribute:"no-remove"},disabled:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=new Map;#o=!1;setDefault(t){return t?H(()=>{let e=(this.methods||[]).find(r=>r.id===t);if(!e)return!1;if(this.value===t)return!0;let i=this.value||"";this.#o=!0;try{this.value=t}finally{this.#o=!1}return this.syncValue(),this.#m(t,i,e),!0}):!1}remove(t){return t?H(()=>{let e=Array.isArray(this.methods)?this.methods.slice():[],i=e.findIndex(r=>r.id===t);if(i<0)return!1;if(e.splice(i,1),this.methods=e,this.value===t){let r=e[0]?.id||"";this.#o=!0;try{this.value=r}finally{this.#o=!1}this.syncValue()}return!0}):!1}add(t){!t||!t.id||H(()=>{let e=Array.isArray(this.methods)?this.methods.slice():[],i=e.findIndex(r=>r.id===t.id);if(i>=0?e[i]=t:e.push(t),this.methods=e,t.default){let r=this.value||"";this.#o=!0;try{this.value=t.id}finally{this.#o=!1}this.syncValue(),r!==t.id&&this.#m(t.id,r,t)}})}connected(){super.connected(),this.setAttribute("role","radiogroup"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Payment methods"),this.#t||(this.#h(),this.#c(),this.#p(),this.#t=!0),H(()=>this.render())}disconnected(){super.disconnected?.();for(let t of this.#e)try{t()}catch{}this.#e.length=0}syncValue(t){this.internals.setFormValue(this.value||"")}render(){if(!this.#t)return;let t=Array.isArray(this.methods)?this.methods:[],e=this.#l(t);if(e&&this.value!==e){this.#o=!0;try{this.value=e}finally{this.#o=!1}this.syncValue()}if(t.length===0?this.setAttribute("empty",""):this.removeAttribute("empty"),this.#r&&(this.#r.hidden=!!this["no-add"]),this.#n){this.#n.setAttribute("text",this["add-label"]||"Add payment method");let i=this["add-icon"]||"plus";i?this.#n.setAttribute("icon",i):this.#n.removeAttribute("icon"),this.disabled?this.#n.setAttribute("disabled",""):this.#n.removeAttribute("disabled")}this.#d(t)}#l(t){if(!t.length)return"";if(this.value&&t.some(i=>i.id===this.value))return this.value;let e=t.find(i=>i.default);return e?e.id:t[0].id||""}#h(){let t=this.querySelector(':scope > script[type="application/json"][data-methods]');if(t)try{let e=JSON.parse(t.textContent||"[]");Array.isArray(e)&&(this.methods=e)}catch(e){console.warn("[payment-method-list-ui] failed to parse <script data-methods> JSON:",e?.message)}finally{t.remove()}}#c(){let t=document.createElement("div");if(t.setAttribute("data-rows",""),t.setAttribute("role","presentation"),this.appendChild(t),this.#i=t,!this.querySelector(':scope > [slot="empty"]')){let i=document.createElement("empty-state-ui");i.setAttribute("data-empty",""),i.setAttribute("icon","credit-card"),i.setAttribute("heading","No payment methods"),i.setAttribute("description","Add a method to get started."),this.appendChild(i),this.#s=i}let e=document.createElement("div");if(e.setAttribute("data-add",""),this.appendChild(e),this.#r=e,!this.querySelector(':scope > [slot="add"]')){let i=document.createElement("button-ui");i.setAttribute("data-add-cta",""),i.setAttribute("variant","outline"),i.setAttribute("icon",this["add-icon"]||"plus"),i.setAttribute("text",this["add-label"]||"Add payment method"),e.appendChild(i),this.#n=i}}#d(t){if(!this.#i)return;let e=new Map;for(let i of t){if(!i?.id)continue;let r=this.#a.get(i.id);r||(r=this.#u(i),this.#i.appendChild(r)),this.#f(r,i),e.set(i.id,r)}for(let[i,r]of this.#a)if(!e.has(i))try{r.remove()}catch{}for(let i of t){let r=e.get(i.id);r&&this.#i.appendChild(r)}this.#a=e}#u(t){let e=document.createElement("card-ui");e.setAttribute("data-row",""),e.setAttribute("role","radio"),e.setAttribute("tabindex","0");let i=document.createElement("header"),r=document.createElement("span");r.setAttribute("slot","icon");let n=document.createElement("icon-ui");n.setAttribute("aria-hidden","true"),r.appendChild(n);let o=document.createElement("span");o.setAttribute("slot","heading");let a=document.createElement("span");a.setAttribute("data-primary","");let l=document.createElement("tag-ui");l.setAttribute("data-default-tag",""),l.setAttribute("text","Default"),l.setAttribute("variant","success"),l.setAttribute("size","sm"),l.setAttribute("hidden",""),o.appendChild(a),o.appendChild(l);let h=document.createElement("p");h.setAttribute("slot","description"),h.setAttribute("data-secondary","");let c=document.createElement("span");c.setAttribute("slot","action");let u=document.createElement("button-ui");u.setAttribute("data-action","set-default"),u.setAttribute("variant","ghost"),u.setAttribute("size","sm"),u.setAttribute("text","Set default");let d=document.createElement("button-ui");d.setAttribute("data-action","edit"),d.setAttribute("variant","ghost"),d.setAttribute("size","sm"),d.setAttribute("icon","pencil"),d.setAttribute("aria-label","Edit payment method");let f=document.createElement("button-ui");return f.setAttribute("data-action","remove"),f.setAttribute("variant","ghost"),f.setAttribute("size","sm"),f.setAttribute("icon","trash"),f.setAttribute("aria-label","Remove payment method"),c.appendChild(u),c.appendChild(d),c.appendChild(f),i.appendChild(r),i.appendChild(o),i.appendChild(h),i.appendChild(c),e.appendChild(i),e}#f(t,e){t.setAttribute("data-id",e.id);let i=(e?.brand||"").toLowerCase();i?t.setAttribute("data-brand-key",i):t.removeAttribute("data-brand-key");let r=(e?.type||"card").toLowerCase();FE.has(r)&&t.setAttribute("data-type",r);let n=e.id===this.value;n?(t.setAttribute("data-default",""),t.setAttribute("aria-checked","true"),t.setAttribute("tabindex","0")):(t.removeAttribute("data-default"),t.setAttribute("aria-checked","false"),t.setAttribute("tabindex","-1")),this.disabled?t.setAttribute("aria-disabled","true"):t.removeAttribute("aria-disabled");let o=t.querySelector(':scope > header > [slot="icon"] > icon-ui');if(o){let m=HE(e);o.getAttribute("name")!==m&&o.setAttribute("name",m)}let a=t.querySelector(':scope > header > [slot="heading"] > [data-primary]');a&&(a.textContent=XO(e));let l=t.querySelector(':scope > header > [data-secondary][slot="description"]');if(l){let m=BO(e);l.textContent=m,m?l.removeAttribute("hidden"):l.setAttribute("hidden","")}let h=t.querySelector(':scope > header > [slot="heading"] > [data-default-tag]');h&&(n?h.removeAttribute("hidden"):h.setAttribute("hidden",""));let c=BO(e),u=[XO(e)];c&&u.push(c),n&&u.push("default"),t.setAttribute("aria-label",u.join(", "));let d=t.querySelector(':scope > header > [slot="action"] > [data-action="set-default"]');d&&(n?d.setAttribute("hidden",""):d.removeAttribute("hidden"),this.disabled?d.setAttribute("disabled",""):d.removeAttribute("disabled"));let f=t.querySelector(':scope > header > [slot="action"] > [data-action="edit"]');f&&(this.disabled?f.setAttribute("disabled",""):f.removeAttribute("disabled"));let p=t.querySelector(':scope > header > [slot="action"] > [data-action="remove"]');p&&(this["no-remove"]?p.setAttribute("hidden",""):p.removeAttribute("hidden"),this.disabled?p.setAttribute("disabled",""):p.removeAttribute("disabled"))}#p(){let t=r=>{let n=r.target?.closest?.("button-ui[data-action]");if(n&&this.#i.contains(n)){let a=n.closest("[data-row]");if(!a)return;let l=a.getAttribute("data-id")||"";if(!l)return;if(this.disabled||n.hasAttribute("disabled")){r.stopPropagation();return}let h=(this.methods||[]).find(u=>u.id===l);if(!h)return;let c=n.getAttribute("data-action");r.stopPropagation(),c==="set-default"?this.setDefault(l):c==="remove"?this.dispatchEvent(new CustomEvent("remove",{bubbles:!0,detail:{id:l,method:h}})):c==="edit"&&this.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{id:l,method:h}}));return}let o=r.target?.closest?.("button-ui[data-add-cta]");if(o&&this.#r?.contains(o)){if(this.disabled||o.hasAttribute("disabled")){r.stopPropagation();return}r.stopPropagation(),this.dispatchEvent(new CustomEvent("add",{bubbles:!0,detail:{}}))}};this.addEventListener("press",t),this.addEventListener("click",t),this.#e.push(()=>this.removeEventListener("press",t)),this.#e.push(()=>this.removeEventListener("click",t));let e=r=>{if(r.target?.closest?.("button-ui[data-action]")||r.target?.closest?.("button-ui[data-add-cta]"))return;let n=r.target?.closest?.("[data-row]");if(!n||!this.#i.contains(n))return;let o=n.getAttribute("data-id")||"";o&&(this.disabled||this.setDefault(o))};this.#i.addEventListener("click",e),this.#e.push(()=>this.#i.removeEventListener("click",e));let i=r=>{let o=document.activeElement?.closest?.("[data-row]");if(!o||!this.#i.contains(o))return;let a=Array.from(this.#i.querySelectorAll(":scope > [data-row]")),l=a.indexOf(o);if(!(l<0)){if(r.key==="ArrowDown"||r.key==="ArrowRight")r.preventDefault(),a[(l+1)%a.length]?.focus?.();else if(r.key==="ArrowUp"||r.key==="ArrowLeft")r.preventDefault(),a[(l-1+a.length)%a.length]?.focus?.();else if(r.key==="Home")r.preventDefault(),a[0]?.focus?.();else if(r.key==="End")r.preventDefault(),a[a.length-1]?.focus?.();else if(r.key===" "||r.key==="Enter"){r.preventDefault();let h=o.getAttribute("data-id")||"";h&&!this.disabled&&this.setDefault(h)}}};this.#i.addEventListener("keydown",i),this.#e.push(()=>this.#i.removeEventListener("keydown",i))}#m(t,e,i){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:t,previous:e,method:i}}))}};customElements.get("payment-method-list-ui")||customElements.define("payment-method-list-ui",Qa);Pt();var Xd=new Set(["monthly","annual"]),eq={monthly:"Monthly",annual:"Annual"},iq={monthly:"/month",annual:"/year"};function sq(s,t,e){let i=Number.isFinite(s)?s:0;try{return new Intl.NumberFormat(e||void 0,{style:"currency",currency:t||"USD",maximumFractionDigits:Number.isInteger(i)?0:2}).format(i)}catch{return`${t||"$"}${i}`}}function rq(s,t,e){if(s.cta)return s.cta;if(!e)return`Choose ${s.name||""}`.trim();if(s.id===e)return"Manage";let i=t.find(r=>r.id===e);if(i&&Number.isFinite(i.rank)&&Number.isFinite(s.rank)){if(s.rank>i.rank)return"Upgrade";if(s.rank<i.rank)return"Downgrade"}return`Switch to ${s.name||""}`.trim()}var Ta=class extends R{static labelDeprecated=!0;static get properties(){return{...R.properties,plans:{type:Array,default:[]},value:{type:String,default:"",reflect:!0},current:{type:String,default:"",reflect:!0},cycle:{type:String,default:"monthly",reflect:!0},cycleToggle:{type:Boolean,default:!1,reflect:!0,attribute:"cycle-toggle"},currency:{type:String,default:"USD"},locale:{type:String,default:""},layout:{type:String,default:"grid",reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=new Map;#l=!1;#h=!1;#c=!1;#d=0;setValue(t){return t?H(()=>{let e=(this.plans||[]).find(r=>r.id===t);if(!e)return!1;if(e.disabled)return this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"plan-disabled"}})),!1;if(this.value===t)return!0;let i=this.value||"";return this.value=t,this.syncValue(),this.#b(t,i),!0}):!1}setCycle(t){return Xd.has(t)?H(()=>{if(this.cycle===t)return!0;let e=this.cycle;return this.cycle=t,this.dispatchEvent(new CustomEvent("cycle-change",{bubbles:!0,detail:{cycle:t,previous:e}})),!0}):!1}async refresh(){let t=this.getAttribute("data-stream-src");if(!t)return;let e=++this.#d;this.setAttribute("loading",""),this.removeAttribute("error");try{let i=await fetch(t);if(!i.ok)throw new Error(`HTTP ${i.status}`);let r=await i.json();if(e!==this.#d)return;this.removeAttribute("loading");let n=Array.isArray(r)?r:Array.isArray(r?.plans)?r.plans:[];this.plans=n,this.dispatchEvent(new CustomEvent("load",{bubbles:!0,detail:{count:n.length}}))}catch(i){if(e!==this.#d)return;this.removeAttribute("loading"),this.setAttribute("error",""),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"fetch-failed",message:String(i?.message||i)}}))}}connected(){super.connected(),this.setAttribute("role","radiogroup"),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Choose a plan"),this.#t||(this.#u(),this.#f(),this.#y(),this.#t=!0),H(()=>this.render()),this.getAttribute("data-stream-src")&&this.refresh()}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0}attributeChangedCallback(t,e,i){super.attributeChangedCallback?.(t,e,i),!(!this.#t||this.#l)&&t==="data-stream-src"&&e!==i&&i&&this.refresh()}syncValue(t){this.internals.setFormValue(this.value||"")}render(){if(!this.#t)return;let t=Array.isArray(this.plans)?this.plans:[];if(!Xd.has(this.cycle)){this.#h||(this.#h=!0,console.warn(`[plan-picker-ui] unknown cycle "${this.cycle}" \u2014 coercing to "monthly".`)),this.#l=!0;try{this.cycle="monthly"}finally{this.#l=!1}}let e=t.filter(r=>r.recommended);e.length>1&&!this.#c&&(this.#c=!0,console.warn(`[plan-picker-ui] ${e.length} plans carry recommended:true \u2014 using the first ("${e[0].id}"); ignoring the rest.`));let i=e[0]?.id||"";if(t.length===0?this.setAttribute("empty",""):this.removeAttribute("empty"),this.#i){let r=this.cycleToggle&&t.length>0;this.#i.hidden=!r,r&&this.#p()}this.#m(t,i)}#u(){let t=this.querySelector(':scope > script[type="application/json"][data-plans]');if(t)try{let e=JSON.parse(t.textContent||"[]");Array.isArray(e)&&(this.plans=e)}catch(e){console.warn("[plan-picker-ui] failed to parse <script data-plans> JSON:",e?.message)}finally{t.remove()}}#f(){let t=document.createElement("div");t.setAttribute("data-toggle",""),t.hidden=!0,this.appendChild(t),this.#i=t;let e=document.createElement("div");e.setAttribute("data-plans",""),e.setAttribute("role","presentation"),this.appendChild(e),this.#r=e;let i=document.createElement("div");if(i.setAttribute("data-skeleton",""),i.hidden=!0,this.appendChild(i),this.#n=i,!this.querySelector(':scope > [slot="empty"]')){let r=document.createElement("empty-state-ui");r.setAttribute("data-empty",""),r.setAttribute("icon","package"),r.setAttribute("heading","No plans available"),r.setAttribute("description","Plans will appear here once configured."),this.appendChild(r),this.#a=r}}#p(){if(!this.#i)return;let t=this.#s;if(!t){t=document.createElement("segmented-ui"),t.setAttribute("aria-label","Billing cycle"),this.#i.appendChild(t),this.#s=t;for(let e of["monthly","annual"]){let i=document.createElement("segment-ui");i.setAttribute("value",e),i.setAttribute("text",eq[e]),t.appendChild(i)}}t.value!==this.cycle&&(t.value=this.cycle)}#m(t,e){if(!this.#r)return;let i=new Map;for(let r of t){if(!r?.id)continue;let n=this.#o.get(r.id);n||(n=document.createElement("option-card-ui"),n.setAttribute("layout","tile"),this.#r.appendChild(n)),this.#g(n,r,e),i.set(r.id,n)}for(let[r,n]of this.#o)if(!i.has(r))try{n.remove()}catch{}for(let r of t){let n=i.get(r.id);n&&this.#r.appendChild(n)}this.#o=i}#g(t,e,i){t.setAttribute("name",`${this.name||"plan"}__${this.id||"pp"}`),t.setAttribute("value",e.id),t.setAttribute("heading",e.name||""),t.setAttribute("description",e.tagline||""),e.icon?t.setAttribute("icon",e.icon):t.removeAttribute("icon");let r=!!(this.current&&e.id===this.current),n=e.id===i;r?t.setAttribute("data-current",""):t.removeAttribute("data-current"),n?t.setAttribute("data-recommended",""):t.removeAttribute("data-recommended"),e.disabled||this.disabled?t.setAttribute("disabled",""):t.removeAttribute("disabled"),this.value&&this.value===e.id||!this.value&&r?t.setAttribute("checked",""):t.removeAttribute("checked");let a=t.querySelector(":scope > [data-plan-body]");a||(a=document.createElement("div"),a.setAttribute("data-plan-body",""),t.appendChild(a)),this.#O(a,e);let l=t.querySelector(":scope > [data-plan-tags]");if(l||(l=document.createElement("div"),l.setAttribute("data-plan-tags",""),l.setAttribute("slot","heading-suffix"),t.appendChild(l)),l.replaceChildren(),r){let h=document.createElement("tag-ui");h.setAttribute("text","Current plan"),h.setAttribute("variant","muted"),l.appendChild(h)}else if(n){let h=document.createElement("tag-ui");h.setAttribute("text","Recommended"),h.setAttribute("variant","accent"),l.appendChild(h)}}#O(t,e){t.replaceChildren();let i=document.createElement("div");i.setAttribute("data-price-row","");let r=Xd.has(this.cycle)?this.cycle:"monthly",n=e.prices||{},o=n[r]||n.monthly||null;if(o){let l=document.createElement("span");l.setAttribute("data-price","");let h=o.currency||this.currency||"USD";l.textContent=sq(o.amount,h,this.locale),i.appendChild(l);let c=document.createElement("span");c.setAttribute("data-cycle","");let u=o.unit?`/${o.unit}`:iq[r];c.textContent=u,i.appendChild(c)}else{let l=document.createElement("span");l.setAttribute("data-price",""),l.textContent="Contact sales",i.appendChild(l)}if(t.appendChild(i),o?.note){let l=document.createElement("span");l.setAttribute("data-price-note",""),l.textContent=o.note,t.appendChild(l)}if(Array.isArray(e.features)&&e.features.length){let l=document.createElement("ul");l.setAttribute("data-features","");for(let h of e.features){let c=document.createElement("li"),u=document.createElement("icon-ui");u.setAttribute("name","check"),u.setAttribute("aria-hidden","true"),c.appendChild(u);let d=document.createElement("span");d.textContent=String(h),c.appendChild(d),l.appendChild(c)}t.appendChild(l)}if(!!!(this.current&&e.id===this.current)||e.cta){let l=document.createElement("button-ui");l.setAttribute("data-cta",""),l.setAttribute("variant",e.recommended?"primary":"outline"),l.setAttribute("text",rq(e,Array.isArray(this.plans)?this.plans:[],this.current)),(e.disabled||this.disabled)&&l.setAttribute("disabled",""),t.appendChild(l)}}#y(){let t=r=>{let n=r?.detail?.value;if(!Xd.has(n)||this.cycle===n)return;r.stopPropagation();let o=this.cycle;this.cycle=n,this.dispatchEvent(new CustomEvent("cycle-change",{bubbles:!0,detail:{cycle:n,previous:o}}))};this.#i.addEventListener("change",t),this.#e.push(()=>this.#i.removeEventListener("change",t));let e=r=>{let n=r.target?.closest?.("option-card-ui");if(!n||!this.#r.contains(n))return;let o=n.getAttribute("value")||"";if(!o)return;let a=(this.plans||[]).find(h=>h.id===o);if(!a)return;if(a.disabled||this.disabled){n.removeAttribute("checked"),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{reason:"plan-disabled"}}));return}r.stopPropagation();let l=this.value||"";if(l!==o){this.#l=!0;try{this.value=o}finally{this.#l=!1}this.syncValue(),this.#b(o,l)}};this.#r.addEventListener("change",e),this.#e.push(()=>this.#r.removeEventListener("change",e));let i=r=>{let n=r.target?.closest?.("button-ui[data-cta]");if(!n||!this.#r.contains(n))return;let o=n.closest("option-card-ui");if(!o)return;let a=o.getAttribute("value")||"";if(!a)return;let l=(this.plans||[]).find(c=>c.id===a);if(!l||l.disabled||this.disabled)return;r.stopPropagation();let h=this.value||"";if(h!==a){this.#l=!0;try{this.value=a}finally{this.#l=!1}this.syncValue(),this.#b(a,h)}this.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{value:a,cycle:this.cycle}}))};this.#r.addEventListener("press",i),this.#r.addEventListener("click",i),this.#e.push(()=>this.#r.removeEventListener("press",i)),this.#e.push(()=>this.#r.removeEventListener("click",i))}#b(t,e){this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:t,previous:e,cycle:this.cycle}}))}};customElements.get("plan-picker-ui")||customElements.define("plan-picker-ui",Ta);P();var nq=Object.freeze([{value:"all",label:"All"},{value:"available",label:"Available"},{value:"connected",label:"Connected"},{value:"error",label:"Issues"},{value:"coming-soon",label:"Coming soon"}]),oq=6,vh=class extends v{static properties={integrations:{type:Array,default:[]},loading:{type:Boolean,default:!1,reflect:!0},"search-placeholder":{type:String,default:"Search integrations",reflect:!0},"group-by":{type:String,default:"category",reflect:!0},"status-filter":{type:String,default:"all",reflect:!0}};static template=t=>t._renderTemplate();#t="";#e=`intpage-h-${Math.random().toString(36).slice(2,8)}`;#i=null;attributeChangedCallback(t,e,i){if(t==="integrations"){if(i==null)this.integrations=[];else try{let r=JSON.parse(i);this.integrations=Array.isArray(r)?r:[]}catch{this.integrations=[]}return}super.attributeChangedCallback(t,e,i)}connected(){if(this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#e),this.hasAttribute("aria-label")||this.setAttribute("aria-label","Integrations"),this.hasAttribute("integrations")&&!Array.isArray(this.integrations))try{this.integrations=JSON.parse(this.getAttribute("integrations"))}catch{this.integrations=[]}this.addEventListener("input",this.#d),this.addEventListener("change",this.#u)}disconnected(){this.removeEventListener("input",this.#d),this.removeEventListener("change",this.#u),this.#i&&(clearTimeout(this.#i),this.#i=null)}render(){this.#c(),this.querySelector('segmented-ui[data-part="filter"]')?.render?.()}_renderTemplate(){let t=this["search-placeholder"]||"Search integrations",e=this["status-filter"]||"all",i=!!this.loading,r=this.#l();return Y`
459
459
  <header data-part="header">
460
460
  <h2 data-part="title" id=${this.#e}>Integrations</h2>
461
461
  <slot name="header"></slot>
@@ -474,7 +474,7 @@ Correct shape for <chart-ui x="label" y="value">:
474
474
  value=${e}
475
475
  aria-label="Filter integrations by status"
476
476
  >
477
- ${iq.map(n=>Y`
477
+ ${nq.map(n=>Y`
478
478
  <segment-ui
479
479
  value=${n.value}
480
480
  text=${n.label}
@@ -485,7 +485,7 @@ Correct shape for <chart-ui x="label" y="value">:
485
485
  </div>
486
486
 
487
487
  ${i?this.#s():this.#r(r)}
488
- `}#s(){let t=[];for(let e=0;e<sq;e++)t.push(Y`
488
+ `}#s(){let t=[];for(let e=0;e<oq;e++)t.push(Y`
489
489
  <div data-part="skeleton-tile" aria-hidden="true"></div>
490
490
  `);return Y`
491
491
  <div data-part="skeleton" aria-busy="true" aria-live="polite">
@@ -527,16 +527,16 @@ Correct shape for <chart-ui x="label" y="value">:
527
527
  <text-ui data-part="empty-description" variant="body" color="subtle">${e?"Try a different keyword or clear the search.":"Integrations will appear here once they are available."}</text-ui>
528
528
  </slot>
529
529
  </div>
530
- `}#l(){let t=Array.isArray(this.integrations)?this.integrations:[],e=(this.#t||"").trim().toLowerCase(),i=this["status-filter"]||"all",r=t.filter(l=>!(!l||typeof l!="object"||i!=="all"&&String(l.status??"available")!==i||e&&![l.name,l.description,l.provider,l.category].map(c=>String(c??"").toLowerCase()).join(" ").includes(e))),n=this["group-by"]||"category";if(n==="none")return[{key:"__none__",label:"",items:r}];let o=[],a=new Map;for(let l of r){let c=String(n==="status"?l.status??"available":l.category??"Other")||"Other";a.has(c)||(a.set(c,[]),o.push(c)),a.get(c).push(l)}return o.map(l=>({key:l,label:n==="status"?this.#h(l):l,items:a.get(l)}))}#h(t){switch(t){case"available":return"Available";case"connected":return"Connected";case"error":return"Issues";case"pending":return"Connecting";case"coming-soon":return"Coming soon";default:return t||"Other"}}#c(){let t=Array.isArray(this.integrations)?this.integrations:[],i=this.#l().reduce((r,n)=>r+n.items.length,0);if(this.loading){this.removeAttribute("data-empty-search"),this.removeAttribute("data-empty-data");return}i===0&&t.length>0?(this.setAttribute("data-empty-search",""),this.removeAttribute("data-empty-data")):t.length===0?(this.setAttribute("data-empty-data",""),this.removeAttribute("data-empty-search")):(this.removeAttribute("data-empty-search"),this.removeAttribute("data-empty-data"))}#d=t=>{let e=t.target;if(!e||!e.closest)return;let i=e.closest('search-ui[data-part="search"]');if(!i||!this.contains(i))return;let r=String(t.detail?.value??i.value??"");this.#t=r,this.integrations=Array.isArray(this.integrations)?[...this.integrations]:[],this.#i&&clearTimeout(this.#i),this.#i=setTimeout(()=>{this.dispatchEvent(new CustomEvent("search",{bubbles:!0,detail:{query:r.toLowerCase().trim()}}))},250)};#u=t=>{let e=t.target;if(!e||!e.closest)return;let i=e.closest('segmented-ui[data-part="filter"]');if(!i||!this.contains(i))return;let r=String(t.detail?.value??i.value??"all");this["status-filter"]!==r&&(this["status-filter"]=r,this.dispatchEvent(new CustomEvent("filter-change",{bubbles:!0,detail:{status:r}})))}};customElements.get("integrations-page-ui")||customElements.define("integrations-page-ui",vh);Pt();var xh=class extends R{static get properties(){return{...R.properties,preferences:{type:Array,default:[]},channels:{type:Array,default:[]},channelEnabled:{type:Object,default:{}},loading:{type:Boolean,default:!1,reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0},"group-by":{type:String,default:"none",reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=new Map;#h=new Map;#c=new Map;#d=new Map;#u=new Map;#f=!1;#p=`np-h-${Math.random().toString(36).slice(2,8)}`;attributeChangedCallback(t,e,i){if(t==="preferences"||t==="channels"||t==="channelenabled"){let r=t==="channelenabled"?"channelEnabled":t;if(i==null)this[r]=r==="channelEnabled"?{}:[];else try{let n=JSON.parse(i);r==="channelEnabled"?this[r]=n&&typeof n=="object"&&!Array.isArray(n)?n:{}:this[r]=Array.isArray(n)?n:[]}catch{this[r]=r==="channelEnabled"?{}:[]}return}super.attributeChangedCallback?.(t,e,i)}connected(){if(super.connected(),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Notification preferences"),this.setAttribute("role","region"),!this.#t){if(this.hasAttribute("preferences")&&!Array.isArray(this.preferences))try{this.preferences=JSON.parse(this.getAttribute("preferences"))}catch{this.preferences=[]}if(this.hasAttribute("channels")&&!Array.isArray(this.channels))try{this.channels=JSON.parse(this.getAttribute("channels"))}catch{this.channels=[]}if(this.hasAttribute("channelenabled")&&(typeof this.channelEnabled!="object"||Array.isArray(this.channelEnabled)))try{this.channelEnabled=JSON.parse(this.getAttribute("channelenabled"))}catch{this.channelEnabled={}}this.#m(),this.#S(),this.#t=!0}H(()=>this.render())}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0}syncValue(){let t={preferences:Array.isArray(this.preferences)?this.preferences:[],channelEnabled:this.channelEnabled&&typeof this.channelEnabled=="object"?this.channelEnabled:{}},e=JSON.stringify(t);this.value=e,this.internals.setFormValue(e)}render(){if(!this.#t)return;let t=Array.isArray(this.channels)?this.channels:[],e=Array.isArray(this.preferences)?this.preferences:[];e.length===0||t.length===0?this.setAttribute("empty",""):this.removeAttribute("empty"),this.style.setProperty("--np-columns",`repeat(${Math.max(t.length,1)}, minmax(var(--notification-preferences-channel-width, var(--notification-preferences-channel-width-default)), auto))`),this.#g(t),(this["group-by"]||"none")==="group"?this.#b(e,t):this.#y(e,t),this.syncValue()}#m(){let t=document.createElement("div");t.setAttribute("data-part","header");let e=document.createElement("slot");e.setAttribute("name","header"),t.appendChild(e),this.appendChild(t),this.#i=t;let i=document.createElement("div");i.setAttribute("data-part","matrix"),i.setAttribute("role","table"),i.setAttribute("aria-labelledby",this.#p),this.appendChild(i),this.#s=i;let r=document.createElement("div");r.setAttribute("data-part","header-row"),r.setAttribute("role","row"),i.appendChild(r),this.#r=r;let n=document.createElement("div");n.setAttribute("data-part","body"),i.appendChild(n),this.#n=n;let o=document.createElement("div");o.setAttribute("data-part","empty");let a=document.createElement("slot");a.setAttribute("name","empty");let l=document.createElement("empty-state-ui");l.setAttribute("icon","bell"),l.setAttribute("heading","No notification types configured"),l.setAttribute("description","Add at least one notification type and one delivery channel to begin."),a.appendChild(l),o.appendChild(a),this.appendChild(o),this.#a=o;let h=document.createElement("div");h.setAttribute("data-part","footer");let c=document.createElement("slot");c.setAttribute("name","footer"),h.appendChild(c),this.appendChild(h),this.#o=h}#g(t){if(!this.#r)return;let e=this.#r.querySelector(":scope > [data-row-label]");e||(e=document.createElement("div"),e.setAttribute("role","columnheader"),e.setAttribute("data-row-label",""),e.id=this.#p,e.textContent="Notification",this.#r.appendChild(e));let i=new Set;for(let r of t){if(!r?.key)continue;i.add(r.key);let n=this.#c.get(r.key);n||(n=document.createElement("div"),n.setAttribute("role","columnheader"),n.setAttribute("data-channel-key",r.key),this.#r.appendChild(n),this.#c.set(r.key,n)),this.#O(n,r)}for(let[r,n]of this.#c)if(!i.has(r)){try{n.remove()}catch{}this.#c.delete(r),this.#d.delete(r)}for(let r of t){let n=this.#c.get(r.key);n&&this.#r.appendChild(n)}}#O(t,e){if(t.replaceChildren(),e.icon){let a=document.createElement("icon-ui");a.setAttribute("name",String(e.icon)),a.setAttribute("aria-hidden","true"),t.appendChild(a)}let i=document.createElement("span");i.setAttribute("data-channel-label",""),i.textContent=String(e.label||e.key),t.appendChild(i);let r=this.#d.get(e.key);r||(r=document.createElement("switch-ui"),r.setAttribute("size","sm"),r.setAttribute("data-channel-master",e.key),this.#d.set(e.key,r));let n=this.channelEnabled&&typeof this.channelEnabled=="object"?this.channelEnabled:{},o=Object.prototype.hasOwnProperty.call(n,e.key)?!!n[e.key]:!0;if(r.checked!==o){this.#f=!0;try{r.checked=o}finally{this.#f=!1}}r.setAttribute("aria-label",`Toggle ${e.label||e.key} for all rows`),this.disabled||this.loading?r.setAttribute("disabled",""):r.removeAttribute("disabled"),t.appendChild(r)}#y(t,e){if(!this.#n)return;for(let[,n]of this.#u)try{n.remove()}catch{}this.#u.clear();let i=new Set,r=new Set;for(let n of t){if(!n?.key)continue;i.add(n.key);let o=this.#x(n);this.#v(o,n,e,r)}for(let[n,o]of this.#l)if(!i.has(n)){try{o.remove()}catch{}this.#l.delete(n)}for(let[n,o]of this.#h)if(!r.has(n)){try{o.remove()}catch{}this.#h.delete(n)}for(let n of t){let o=this.#l.get(n.key);o&&this.#n.appendChild(o)}}#b(t,e){if(!this.#n)return;let i=[],r=new Map;for(let l of t){let h=String(l?.group??"Other")||"Other";r.has(h)||(r.set(h,[]),i.push(h)),r.get(h).push(l)}let n=new Set,o=new Set,a=new Set;for(let l of i){n.add(l);let h=this.#u.get(l);h||(h=document.createElement("div"),h.setAttribute("data-part","group-heading"),h.setAttribute("data-group",l),h.setAttribute("role","rowgroup"),this.#u.set(l,h)),h.textContent=l,this.#n.appendChild(h);for(let c of r.get(l)){if(!c?.key)continue;o.add(c.key);let u=this.#x(c);this.#v(u,c,e,a),this.#n.appendChild(u)}}for(let[l,h]of this.#l)if(!o.has(l)){try{h.remove()}catch{}this.#l.delete(l)}for(let[l,h]of this.#h)if(!a.has(l)){try{h.remove()}catch{}this.#h.delete(l)}for(let[l,h]of this.#u)if(!n.has(l)){try{h.remove()}catch{}this.#u.delete(l)}}#x(t){let e=this.#l.get(t.key);return e||(e=document.createElement("div"),e.setAttribute("role","row"),e.setAttribute("data-row-key",t.key),this.#n.appendChild(e),this.#l.set(t.key,e)),e}#v(t,e,i,r){let n=t.querySelector(':scope > [role="rowheader"]');n||(n=document.createElement("div"),n.setAttribute("role","rowheader"),t.appendChild(n)),n.replaceChildren();let o=document.createElement("span");if(o.setAttribute("data-row-label-text",""),o.textContent=String(e.label||e.key),n.appendChild(o),e.description){let l=document.createElement("span");l.setAttribute("data-row-description",""),l.textContent=String(e.description),n.appendChild(l)}let a=e.channels&&typeof e.channels=="object"?e.channels:{};for(let l of i){if(!l?.key)continue;let h=`${e.key}::${l.key}`;r.add(h);let c=t.querySelector(`:scope > [data-cell-key="${CSS.escape(h)}"]`);c||(c=document.createElement("div"),c.setAttribute("role","cell"),c.setAttribute("data-cell-key",h),t.appendChild(c));let u=this.#h.get(h);u||(u=document.createElement("check-ui"),u.setAttribute("data-row-key",e.key),u.setAttribute("data-channel-key",l.key),c.appendChild(u),this.#h.set(h,u));let d=!!a[l.key];if(u.checked!==d){this.#f=!0;try{u.checked=d}finally{this.#f=!1}}u.setAttribute("aria-label",`${e.label||e.key} via ${l.label||l.key}`),!!this.disabled||!!this.loading||!!e.disabled?u.setAttribute("disabled",""):u.removeAttribute("disabled")}for(let l of i){let h=`${e.key}::${l.key}`,c=t.querySelector(`:scope > [data-cell-key="${CSS.escape(h)}"]`);c&&t.appendChild(c)}}#S(){let t=e=>{if(this.#f)return;let i=e?.target;if(!i)return;let r=i.closest?.("switch-ui[data-channel-master]");if(r&&this.#s.contains(r)){let o=r.getAttribute("data-channel-master")||"";if(!o||this.disabled||this.loading)return;e.stopPropagation();let a=!!r.checked;this.dispatchEvent(new CustomEvent("bulk-toggle",{bubbles:!0,detail:{channel:o,enabled:a}}));return}let n=i.closest?.("check-ui[data-row-key][data-channel-key]");if(n&&this.#n.contains(n)){let o=n.getAttribute("data-row-key")||"",a=n.getAttribute("data-channel-key")||"";if(!o||!a||this.disabled||this.loading)return;e.stopPropagation();let l=!!n.checked;this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{row:o,channel:a,enabled:l}}));return}};this.#s.addEventListener("change",t),this.#e.push(()=>this.#s.removeEventListener("change",t))}};customElements.get("notification-preferences-ui")||customElements.define("notification-preferences-ui",xh);var ZO=["prompt-section","skill","workflow","resource","tool","pattern-source"];function zO(s){return s.filter(t=>t.enabled).sort((t,e)=>t.order-e.order)}function KE(s){return{order:0,enabled:!0,builtin:!0,...s}}function rq(s){return s.map((t,e)=>KE({order:e,...t}))}function _O(s){if(!s.id)throw new Error('definePersona: "id" is required');if(!Number.isInteger(s.seedVersion)||s.seedVersion<1)throw new Error(`definePersona "${s.id}": seedVersion must be an integer >= 1, got ${s.seedVersion}`);let t=new Set;for(let e of s.entries){if(t.has(e.id))throw new Error(`definePersona "${s.id}": duplicate entry id "${e.id}"`);t.add(e.id)}return s}function nq(){try{return typeof localStorage<"u"}catch{return!1}}function eC(s={}){let t=s.persistKey,e=!!t&&nq(),i={...s.initial??{}};if(e)try{let o=localStorage.getItem(t);o&&(i={...i,...JSON.parse(o)})}catch{}let r=new Set;function n(){if(e)try{localStorage.setItem(t,JSON.stringify(i))}catch{}}return{get(o){return i[o]},set(o,a){if(!(o in i&&Object.is(i[o],a))){i={...i,[o]:a},n();for(let l of r)l()}},subscribe(o){return r.add(o),()=>r.delete(o)}}}var JE="__seedVersion";function tC(s,t){return`entry.${s}.${t}`}function oq(s){let t={};for(let e of s.entries)t[tC(e.id,"enabled")]=e.enabled,t[tC(e.id,"order")]=e.order;return t}function VO(s,t={}){let i=(t.createStore??eC)({persistKey:`persona.${s.id}`}),r=oq(s);if(i.get(JE)!==s.seedVersion){for(let[o,a]of Object.entries(r))i.set(o,a);i.set(JE,s.seedVersion)}else for(let[o,a]of Object.entries(r))i.get(o)===void 0&&i.set(o,a);return i}function Sh(s,t,e={}){if(typeof t=="function"&&e.cache)throw new Error(`promptLayer "${s}": a function layer resolves per turn and cannot be cached`);return{name:s,text:t,...e.cache?{cache:!0}:{}}}function jO(s){let t=s.filter(l=>typeof l.text=="string"),e=s.filter(l=>typeof l.text=="function"),i=l=>typeof l.text=="function"?l.text():l.text,r=[...t,...e],n=r.map(i).filter(Boolean),o=[...t].reverse().find(l=>l.cache),a=r.map((l,h)=>({layer:l,text:n[h]??""})).filter(l=>l.text).map(l=>({type:"text",text:l.text,...l.layer===o?{cache_control:{type:"ephemeral"}}:{}}));return{text:n.join(`
530
+ `}#l(){let t=Array.isArray(this.integrations)?this.integrations:[],e=(this.#t||"").trim().toLowerCase(),i=this["status-filter"]||"all",r=t.filter(l=>!(!l||typeof l!="object"||i!=="all"&&String(l.status??"available")!==i||e&&![l.name,l.description,l.provider,l.category].map(c=>String(c??"").toLowerCase()).join(" ").includes(e))),n=this["group-by"]||"category";if(n==="none")return[{key:"__none__",label:"",items:r}];let o=[],a=new Map;for(let l of r){let c=String(n==="status"?l.status??"available":l.category??"Other")||"Other";a.has(c)||(a.set(c,[]),o.push(c)),a.get(c).push(l)}return o.map(l=>({key:l,label:n==="status"?this.#h(l):l,items:a.get(l)}))}#h(t){switch(t){case"available":return"Available";case"connected":return"Connected";case"error":return"Issues";case"pending":return"Connecting";case"coming-soon":return"Coming soon";default:return t||"Other"}}#c(){let t=Array.isArray(this.integrations)?this.integrations:[],i=this.#l().reduce((r,n)=>r+n.items.length,0);if(this.loading){this.removeAttribute("data-empty-search"),this.removeAttribute("data-empty-data");return}i===0&&t.length>0?(this.setAttribute("data-empty-search",""),this.removeAttribute("data-empty-data")):t.length===0?(this.setAttribute("data-empty-data",""),this.removeAttribute("data-empty-search")):(this.removeAttribute("data-empty-search"),this.removeAttribute("data-empty-data"))}#d=t=>{let e=t.target;if(!e||!e.closest)return;let i=e.closest('search-ui[data-part="search"]');if(!i||!this.contains(i))return;let r=String(t.detail?.value??i.value??"");this.#t=r,this.integrations=Array.isArray(this.integrations)?[...this.integrations]:[],this.#i&&clearTimeout(this.#i),this.#i=setTimeout(()=>{this.dispatchEvent(new CustomEvent("search",{bubbles:!0,detail:{query:r.toLowerCase().trim()}}))},250)};#u=t=>{let e=t.target;if(!e||!e.closest)return;let i=e.closest('segmented-ui[data-part="filter"]');if(!i||!this.contains(i))return;let r=String(t.detail?.value??i.value??"all");this["status-filter"]!==r&&(this["status-filter"]=r,this.dispatchEvent(new CustomEvent("filter-change",{bubbles:!0,detail:{status:r}})))}};customElements.get("integrations-page-ui")||customElements.define("integrations-page-ui",vh);Pt();var xh=class extends R{static get properties(){return{...R.properties,preferences:{type:Array,default:[]},channels:{type:Array,default:[]},channelEnabled:{type:Object,default:{}},loading:{type:Boolean,default:!1,reflect:!0},disabled:{type:Boolean,default:!1,reflect:!0},"group-by":{type:String,default:"none",reflect:!0}}}static template=()=>null;#t=!1;#e=[];#i=null;#s=null;#r=null;#n=null;#a=null;#o=null;#l=new Map;#h=new Map;#c=new Map;#d=new Map;#u=new Map;#f=!1;#p=`np-h-${Math.random().toString(36).slice(2,8)}`;attributeChangedCallback(t,e,i){if(t==="preferences"||t==="channels"||t==="channelenabled"){let r=t==="channelenabled"?"channelEnabled":t;if(i==null)this[r]=r==="channelEnabled"?{}:[];else try{let n=JSON.parse(i);r==="channelEnabled"?this[r]=n&&typeof n=="object"&&!Array.isArray(n)?n:{}:this[r]=Array.isArray(n)?n:[]}catch{this[r]=r==="channelEnabled"?{}:[]}return}super.attributeChangedCallback?.(t,e,i)}connected(){if(super.connected(),!this.hasAttribute("aria-label")&&!this.hasAttribute("aria-labelledby")&&this.setAttribute("aria-label","Notification preferences"),this.setAttribute("role","region"),!this.#t){if(this.hasAttribute("preferences")&&!Array.isArray(this.preferences))try{this.preferences=JSON.parse(this.getAttribute("preferences"))}catch{this.preferences=[]}if(this.hasAttribute("channels")&&!Array.isArray(this.channels))try{this.channels=JSON.parse(this.getAttribute("channels"))}catch{this.channels=[]}if(this.hasAttribute("channelenabled")&&(typeof this.channelEnabled!="object"||Array.isArray(this.channelEnabled)))try{this.channelEnabled=JSON.parse(this.getAttribute("channelenabled"))}catch{this.channelEnabled={}}this.#m(),this.#S(),this.#t=!0}H(()=>this.render())}disconnected(){super.disconnected();for(let t of this.#e)try{t()}catch{}this.#e.length=0}syncValue(){let t={preferences:Array.isArray(this.preferences)?this.preferences:[],channelEnabled:this.channelEnabled&&typeof this.channelEnabled=="object"?this.channelEnabled:{}},e=JSON.stringify(t);this.value=e,this.internals.setFormValue(e)}render(){if(!this.#t)return;let t=Array.isArray(this.channels)?this.channels:[],e=Array.isArray(this.preferences)?this.preferences:[];e.length===0||t.length===0?this.setAttribute("empty",""):this.removeAttribute("empty"),this.style.setProperty("--np-columns",`repeat(${Math.max(t.length,1)}, minmax(var(--notification-preferences-channel-width, var(--notification-preferences-channel-width-default)), auto))`),this.#g(t),(this["group-by"]||"none")==="group"?this.#b(e,t):this.#y(e,t),this.syncValue()}#m(){let t=document.createElement("div");t.setAttribute("data-part","header");let e=document.createElement("slot");e.setAttribute("name","header"),t.appendChild(e),this.appendChild(t),this.#i=t;let i=document.createElement("div");i.setAttribute("data-part","matrix"),i.setAttribute("role","table"),i.setAttribute("aria-labelledby",this.#p),this.appendChild(i),this.#s=i;let r=document.createElement("div");r.setAttribute("data-part","header-row"),r.setAttribute("role","row"),i.appendChild(r),this.#r=r;let n=document.createElement("div");n.setAttribute("data-part","body"),i.appendChild(n),this.#n=n;let o=document.createElement("div");o.setAttribute("data-part","empty");let a=document.createElement("slot");a.setAttribute("name","empty");let l=document.createElement("empty-state-ui");l.setAttribute("icon","bell"),l.setAttribute("heading","No notification types configured"),l.setAttribute("description","Add at least one notification type and one delivery channel to begin."),a.appendChild(l),o.appendChild(a),this.appendChild(o),this.#a=o;let h=document.createElement("div");h.setAttribute("data-part","footer");let c=document.createElement("slot");c.setAttribute("name","footer"),h.appendChild(c),this.appendChild(h),this.#o=h}#g(t){if(!this.#r)return;let e=this.#r.querySelector(":scope > [data-row-label]");e||(e=document.createElement("div"),e.setAttribute("role","columnheader"),e.setAttribute("data-row-label",""),e.id=this.#p,e.textContent="Notification",this.#r.appendChild(e));let i=new Set;for(let r of t){if(!r?.key)continue;i.add(r.key);let n=this.#c.get(r.key);n||(n=document.createElement("div"),n.setAttribute("role","columnheader"),n.setAttribute("data-channel-key",r.key),this.#r.appendChild(n),this.#c.set(r.key,n)),this.#O(n,r)}for(let[r,n]of this.#c)if(!i.has(r)){try{n.remove()}catch{}this.#c.delete(r),this.#d.delete(r)}for(let r of t){let n=this.#c.get(r.key);n&&this.#r.appendChild(n)}}#O(t,e){if(t.replaceChildren(),e.icon){let a=document.createElement("icon-ui");a.setAttribute("name",String(e.icon)),a.setAttribute("aria-hidden","true"),t.appendChild(a)}let i=document.createElement("span");i.setAttribute("data-channel-label",""),i.textContent=String(e.label||e.key),t.appendChild(i);let r=this.#d.get(e.key);r||(r=document.createElement("switch-ui"),r.setAttribute("size","sm"),r.setAttribute("data-channel-master",e.key),this.#d.set(e.key,r));let n=this.channelEnabled&&typeof this.channelEnabled=="object"?this.channelEnabled:{},o=Object.prototype.hasOwnProperty.call(n,e.key)?!!n[e.key]:!0;if(r.checked!==o){this.#f=!0;try{r.checked=o}finally{this.#f=!1}}r.setAttribute("aria-label",`Toggle ${e.label||e.key} for all rows`),this.disabled||this.loading?r.setAttribute("disabled",""):r.removeAttribute("disabled"),t.appendChild(r)}#y(t,e){if(!this.#n)return;for(let[,n]of this.#u)try{n.remove()}catch{}this.#u.clear();let i=new Set,r=new Set;for(let n of t){if(!n?.key)continue;i.add(n.key);let o=this.#x(n);this.#v(o,n,e,r)}for(let[n,o]of this.#l)if(!i.has(n)){try{o.remove()}catch{}this.#l.delete(n)}for(let[n,o]of this.#h)if(!r.has(n)){try{o.remove()}catch{}this.#h.delete(n)}for(let n of t){let o=this.#l.get(n.key);o&&this.#n.appendChild(o)}}#b(t,e){if(!this.#n)return;let i=[],r=new Map;for(let l of t){let h=String(l?.group??"Other")||"Other";r.has(h)||(r.set(h,[]),i.push(h)),r.get(h).push(l)}let n=new Set,o=new Set,a=new Set;for(let l of i){n.add(l);let h=this.#u.get(l);h||(h=document.createElement("div"),h.setAttribute("data-part","group-heading"),h.setAttribute("data-group",l),h.setAttribute("role","rowgroup"),this.#u.set(l,h)),h.textContent=l,this.#n.appendChild(h);for(let c of r.get(l)){if(!c?.key)continue;o.add(c.key);let u=this.#x(c);this.#v(u,c,e,a),this.#n.appendChild(u)}}for(let[l,h]of this.#l)if(!o.has(l)){try{h.remove()}catch{}this.#l.delete(l)}for(let[l,h]of this.#h)if(!a.has(l)){try{h.remove()}catch{}this.#h.delete(l)}for(let[l,h]of this.#u)if(!n.has(l)){try{h.remove()}catch{}this.#u.delete(l)}}#x(t){let e=this.#l.get(t.key);return e||(e=document.createElement("div"),e.setAttribute("role","row"),e.setAttribute("data-row-key",t.key),this.#n.appendChild(e),this.#l.set(t.key,e)),e}#v(t,e,i,r){let n=t.querySelector(':scope > [role="rowheader"]');n||(n=document.createElement("div"),n.setAttribute("role","rowheader"),t.appendChild(n)),n.replaceChildren();let o=document.createElement("span");if(o.setAttribute("data-row-label-text",""),o.textContent=String(e.label||e.key),n.appendChild(o),e.description){let l=document.createElement("span");l.setAttribute("data-row-description",""),l.textContent=String(e.description),n.appendChild(l)}let a=e.channels&&typeof e.channels=="object"?e.channels:{};for(let l of i){if(!l?.key)continue;let h=`${e.key}::${l.key}`;r.add(h);let c=t.querySelector(`:scope > [data-cell-key="${CSS.escape(h)}"]`);c||(c=document.createElement("div"),c.setAttribute("role","cell"),c.setAttribute("data-cell-key",h),t.appendChild(c));let u=this.#h.get(h);u||(u=document.createElement("check-ui"),u.setAttribute("data-row-key",e.key),u.setAttribute("data-channel-key",l.key),c.appendChild(u),this.#h.set(h,u));let d=!!a[l.key];if(u.checked!==d){this.#f=!0;try{u.checked=d}finally{this.#f=!1}}u.setAttribute("aria-label",`${e.label||e.key} via ${l.label||l.key}`),!!this.disabled||!!this.loading||!!e.disabled?u.setAttribute("disabled",""):u.removeAttribute("disabled")}for(let l of i){let h=`${e.key}::${l.key}`,c=t.querySelector(`:scope > [data-cell-key="${CSS.escape(h)}"]`);c&&t.appendChild(c)}}#S(){let t=e=>{if(this.#f)return;let i=e?.target;if(!i)return;let r=i.closest?.("switch-ui[data-channel-master]");if(r&&this.#s.contains(r)){let o=r.getAttribute("data-channel-master")||"";if(!o||this.disabled||this.loading)return;e.stopPropagation();let a=!!r.checked;this.dispatchEvent(new CustomEvent("bulk-toggle",{bubbles:!0,detail:{channel:o,enabled:a}}));return}let n=i.closest?.("check-ui[data-row-key][data-channel-key]");if(n&&this.#n.contains(n)){let o=n.getAttribute("data-row-key")||"",a=n.getAttribute("data-channel-key")||"";if(!o||!a||this.disabled||this.loading)return;e.stopPropagation();let l=!!n.checked;this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{row:o,channel:a,enabled:l}}));return}};this.#s.addEventListener("change",t),this.#e.push(()=>this.#s.removeEventListener("change",t))}};customElements.get("notification-preferences-ui")||customElements.define("notification-preferences-ui",xh);var ZO=["prompt-section","skill","workflow","resource","tool","pattern-source"];function zO(s){return s.filter(t=>t.enabled).sort((t,e)=>t.order-e.order)}function KE(s){return{order:0,enabled:!0,builtin:!0,...s}}function aq(s){return s.map((t,e)=>KE({order:e,...t}))}function _O(s){if(!s.id)throw new Error('definePersona: "id" is required');if(!Number.isInteger(s.seedVersion)||s.seedVersion<1)throw new Error(`definePersona "${s.id}": seedVersion must be an integer >= 1, got ${s.seedVersion}`);let t=new Set;for(let e of s.entries){if(t.has(e.id))throw new Error(`definePersona "${s.id}": duplicate entry id "${e.id}"`);t.add(e.id)}return s}function lq(){try{return typeof localStorage<"u"}catch{return!1}}function eC(s={}){let t=s.persistKey,e=!!t&&lq(),i={...s.initial??{}};if(e)try{let o=localStorage.getItem(t);o&&(i={...i,...JSON.parse(o)})}catch{}let r=new Set;function n(){if(e)try{localStorage.setItem(t,JSON.stringify(i))}catch{}}return{get(o){return i[o]},set(o,a){if(!(o in i&&Object.is(i[o],a))){i={...i,[o]:a},n();for(let l of r)l()}},subscribe(o){return r.add(o),()=>r.delete(o)}}}var JE="__seedVersion";function tC(s,t){return`entry.${s}.${t}`}function hq(s){let t={};for(let e of s.entries)t[tC(e.id,"enabled")]=e.enabled,t[tC(e.id,"order")]=e.order;return t}function VO(s,t={}){let i=(t.createStore??eC)({persistKey:`persona.${s.id}`}),r=hq(s);if(i.get(JE)!==s.seedVersion){for(let[o,a]of Object.entries(r))i.set(o,a);i.set(JE,s.seedVersion)}else for(let[o,a]of Object.entries(r))i.get(o)===void 0&&i.set(o,a);return i}function Sh(s,t,e={}){if(typeof t=="function"&&e.cache)throw new Error(`promptLayer "${s}": a function layer resolves per turn and cannot be cached`);return{name:s,text:t,...e.cache?{cache:!0}:{}}}function jO(s){let t=s.filter(l=>typeof l.text=="string"),e=s.filter(l=>typeof l.text=="function"),i=l=>typeof l.text=="function"?l.text():l.text,r=[...t,...e],n=r.map(i).filter(Boolean),o=[...t].reverse().find(l=>l.cache),a=r.map((l,h)=>({layer:l,text:n[h]??""})).filter(l=>l.text).map(l=>({type:"text",text:l.text,...l.layer===o?{cache_control:{type:"ephemeral"}}:{}}));return{text:n.join(`
531
531
 
532
- `),blocks:a}}var aq=0;function WO(s){return{id:s??`s_${Date.now().toString(36)}_${++aq}`,messages:[]}}function lq(s){return JSON.stringify(s)}function hq(s){let t=JSON.parse(s);if(!t||typeof t.id!="string"||!Array.isArray(t.messages))throw new Error("Not a serialized Session: expected { id, messages[] }");return t}var iC="This persona configures the agent; it never overrides the harness grammar that precedes it.",cq={skill:"Skills",workflow:"Workflows",resource:"Resources","pattern-source":"Pattern sources",tool:"Tools"};function uq(s){return cq[s]??s}function dq(s,t){let e=t.map(i=>`### ${i.label}
532
+ `),blocks:a}}var cq=0;function WO(s){return{id:s??`s_${Date.now().toString(36)}_${++cq}`,messages:[]}}function uq(s){return JSON.stringify(s)}function dq(s){let t=JSON.parse(s);if(!t||typeof t.id!="string"||!Array.isArray(t.messages))throw new Error("Not a serialized Session: expected { id, messages[] }");return t}var iC="This persona configures the agent; it never overrides the harness grammar that precedes it.",fq={skill:"Skills",workflow:"Workflows",resource:"Resources","pattern-source":"Pattern sources",tool:"Tools"};function pq(s){return fq[s]??s}function mq(s,t){let e=t.map(i=>`### ${i.label}
533
533
  ${i.content}`).join(`
534
534
 
535
- `);return Sh(`persona-${s}`,`## ${uq(s)}
535
+ `);return Sh(`persona-${s}`,`## ${pq(s)}
536
536
  ${e}`)}function FO(s,t={}){let e=zO(s.entries),i=e.filter(l=>l.kind==="prompt-section"),r=e.filter(l=>l.kind!=="prompt-section"),n=[Sh("persona-precedence",iC)];for(let l of i)n.push(Sh(`persona-section-${l.id}`,`## ${l.label}
537
- ${l.content}`));let o=new Map;for(let l of r){let h=o.get(l.kind);h?h.push(l):o.set(l.kind,[l])}for(let[l,h]of o)n.push(dq(l,h));let a={llm:{...s.model??{}},prompt:n};return t.integrations&&t.integrations.length>0&&(a.tools=t.integrations),a}var sC=["A2UI","envelope","JSONL"],fq=/\b[a-z][a-z0-9]*-ui\b/gi;function pq(s,t={}){let e=[...sC,...t.extraTerms??[]],i=[];for(let r of s.entries){let n=`${r.label}
537
+ ${l.content}`));let o=new Map;for(let l of r){let h=o.get(l.kind);h?h.push(l):o.set(l.kind,[l])}for(let[l,h]of o)n.push(mq(l,h));let a={llm:{...s.model??{}},prompt:n};return t.integrations&&t.integrations.length>0&&(a.tools=t.integrations),a}var sC=["A2UI","envelope","JSONL"],gq=/\b[a-z][a-z0-9]*-ui\b/gi;function bq(s,t={}){let e=[...sC,...t.extraTerms??[]],i=[];for(let r of s.entries){let n=`${r.label}
538
538
  ${r.description??""}
539
- ${r.content}`,o=n.toLowerCase();for(let a of e)o.includes(a.toLowerCase())&&i.push({entryId:r.id,term:a});for(let a of n.matchAll(fq))i.push({entryId:r.id,term:a[0]})}return i}var Bd="persona",UO=1,mq=new Set(["kind","version","id","label","category","seedVersion","entries","model"]);function YO(s){let t={kind:Bd,version:UO,id:s.id,label:s.label,seedVersion:s.seedVersion,entries:s.entries};return s.category!==void 0&&(t.category=s.category),s.model!==void 0&&(t.model=s.model),JSON.stringify(t,null,2)}function gq(s,t){let e=`${s}-imported`,i=2;for(;t.has(e);)e=`${s}-imported-${i}`,i+=1;return e}function HO(s,t){let e;try{e=JSON.parse(s)}catch(c){throw new Error(`importPersona: invalid JSON \u2014 ${c.message}`)}if(typeof e!="object"||e===null||Array.isArray(e))throw new Error("importPersona: expected a JSON object");let i=e,r=Object.keys(i).filter(c=>!mq.has(c));if(r.length>0)throw new Error(`importPersona: unknown key(s): ${r.join(", ")}`);if(i.kind!==Bd)throw new Error(`importPersona: expected kind "${Bd}", got ${JSON.stringify(i.kind)}`);if(i.version!==UO)throw new Error(`importPersona: unsupported version ${JSON.stringify(i.version)}`);if(typeof i.id!="string"||!i.id)throw new Error('importPersona: "id" must be a non-empty string');if(typeof i.label!="string"||!i.label)throw new Error('importPersona: "label" must be a non-empty string');if(typeof i.seedVersion!="number")throw new Error('importPersona: "seedVersion" must be a number');if(!Array.isArray(i.entries))throw new Error('importPersona: "entries" must be an array');let n=new Set(t),a={id:gq(i.id,n),label:`${i.label} (imported)`,seedVersion:i.seedVersion,entries:i.entries.map(c=>({...c,builtin:!1}))},l=i.category;typeof l=="string"&&(a.category=l);let h=i.model;return h&&typeof h=="object"&&!Array.isArray(h)&&(a.model=h),_O(a)}P();var wh=class extends v{static properties={personas:{type:Array,default:[]},"active-id":{type:String,default:"",reflect:!0}};static template=t=>t._renderTemplate();#t=`admin-roster-h-${Math.random().toString(36).slice(2,8)}`;#e=null;attributeChangedCallback(t,e,i){if(t==="personas"){if(i==null)this.personas=[];else try{let r=JSON.parse(i);this.personas=Array.isArray(r)?r:[]}catch{this.personas=[]}return}super.attributeChangedCallback(t,e,i)}connected(){if(this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#t),this.hasAttribute("personas")&&!Array.isArray(this.personas))try{this.personas=JSON.parse(this.getAttribute("personas"))}catch{this.personas=[]}this.addEventListener("click",this.#n),this.addEventListener("keydown",this.#r),this.addEventListener("change",this.#l)}disconnected(){this.removeEventListener("click",this.#n),this.removeEventListener("keydown",this.#r),this.removeEventListener("change",this.#l)}_renderTemplate(){let t=Array.isArray(this.personas)?this.personas:[],e=this["active-id"]||"";return Y`
539
+ ${r.content}`,o=n.toLowerCase();for(let a of e)o.includes(a.toLowerCase())&&i.push({entryId:r.id,term:a});for(let a of n.matchAll(gq))i.push({entryId:r.id,term:a[0]})}return i}var Bd="persona",UO=1,Oq=new Set(["kind","version","id","label","category","seedVersion","entries","model"]);function YO(s){let t={kind:Bd,version:UO,id:s.id,label:s.label,seedVersion:s.seedVersion,entries:s.entries};return s.category!==void 0&&(t.category=s.category),s.model!==void 0&&(t.model=s.model),JSON.stringify(t,null,2)}function yq(s,t){let e=`${s}-imported`,i=2;for(;t.has(e);)e=`${s}-imported-${i}`,i+=1;return e}function HO(s,t){let e;try{e=JSON.parse(s)}catch(c){throw new Error(`importPersona: invalid JSON \u2014 ${c.message}`)}if(typeof e!="object"||e===null||Array.isArray(e))throw new Error("importPersona: expected a JSON object");let i=e,r=Object.keys(i).filter(c=>!Oq.has(c));if(r.length>0)throw new Error(`importPersona: unknown key(s): ${r.join(", ")}`);if(i.kind!==Bd)throw new Error(`importPersona: expected kind "${Bd}", got ${JSON.stringify(i.kind)}`);if(i.version!==UO)throw new Error(`importPersona: unsupported version ${JSON.stringify(i.version)}`);if(typeof i.id!="string"||!i.id)throw new Error('importPersona: "id" must be a non-empty string');if(typeof i.label!="string"||!i.label)throw new Error('importPersona: "label" must be a non-empty string');if(typeof i.seedVersion!="number")throw new Error('importPersona: "seedVersion" must be a number');if(!Array.isArray(i.entries))throw new Error('importPersona: "entries" must be an array');let n=new Set(t),a={id:yq(i.id,n),label:`${i.label} (imported)`,seedVersion:i.seedVersion,entries:i.entries.map(c=>({...c,builtin:!1}))},l=i.category;typeof l=="string"&&(a.category=l);let h=i.model;return h&&typeof h=="object"&&!Array.isArray(h)&&(a.model=h),_O(a)}P();var wh=class extends v{static properties={personas:{type:Array,default:[]},"active-id":{type:String,default:"",reflect:!0}};static template=t=>t._renderTemplate();#t=`admin-roster-h-${Math.random().toString(36).slice(2,8)}`;#e=null;attributeChangedCallback(t,e,i){if(t==="personas"){if(i==null)this.personas=[];else try{let r=JSON.parse(i);this.personas=Array.isArray(r)?r:[]}catch{this.personas=[]}return}super.attributeChangedCallback(t,e,i)}connected(){if(this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#t),this.hasAttribute("personas")&&!Array.isArray(this.personas))try{this.personas=JSON.parse(this.getAttribute("personas"))}catch{this.personas=[]}this.addEventListener("click",this.#n),this.addEventListener("keydown",this.#r),this.addEventListener("change",this.#l)}disconnected(){this.removeEventListener("click",this.#n),this.removeEventListener("keydown",this.#r),this.removeEventListener("change",this.#l)}_renderTemplate(){let t=Array.isArray(this.personas)?this.personas:[],e=this["active-id"]||"";return Y`
540
540
  <header data-part="header">
541
541
  <h2 data-part="title" id=${this.#t}>Personas</h2>
542
542
  </header>
@@ -561,14 +561,14 @@ ${r.content}`,o=n.toLowerCase();for(let a of e)o.includes(a.toLowerCase())&&i.pu
561
561
  >
562
562
  <icon-ui slot="trailing" data-part="row-check" name="check" aria-hidden="true"></icon-ui>
563
563
  </menu-item-ui>
564
- `}#s(){return Y`<div data-part="empty" role="status">No personas yet.</div>`}#r=t=>{if(t.key!=="Enter"&&t.key!==" ")return;let e=t.target.closest?.('[data-part="row"]');e&&this.contains(e)&&(t.preventDefault(),e.click())};#n=t=>{let e=t.target.closest?.('[data-part="row"]');if(e&&this.contains(e)){let n=e.getAttribute("data-persona-id");n&&n!==this["active-id"]&&(this["active-id"]=n,this.dispatchEvent(new CustomEvent("persona-change",{bubbles:!0,detail:{personaId:n}})));return}let i=t.target.closest?.('[data-action="export"]');if(i&&this.contains(i)){this.#a();return}let r=t.target.closest?.('[data-action="import"]');r&&this.contains(r)&&this.#o()};#a(){let t=this["active-id"],e=(Array.isArray(this.personas)?this.personas:[]).find(a=>a.id===t);if(!e)return;let i=YO(e),r=new Blob([i],{type:"application/json"}),n=URL.createObjectURL(r),o=this.ownerDocument.createElement("a");o.href=n,o.download=`${e.id}.persona.json`,o.click(),URL.revokeObjectURL(n)}#o(){this.#e||(this.#e=this.ownerDocument.createElement("input"),this.#e.type="file",this.#e.accept="application/json",this.#e.setAttribute("data-part","import-file"),this.#e.style.display="none",this.appendChild(this.#e)),this.#e.value="",this.#e.click()}#l=async t=>{let e=t.target;if(!e||e!==this.#e)return;let i=e.files?.[0];if(i)try{let r=await i.text(),n=(Array.isArray(this.personas)?this.personas:[]).map(a=>a.id),o=HO(r,n);this.dispatchEvent(new CustomEvent("persona-import",{bubbles:!0,detail:{persona:o}}))}catch(r){this.dispatchEvent(new CustomEvent("persona-import-error",{bubbles:!0,detail:{error:r instanceof Error?r.message:String(r)}}))}}};customElements.get("admin-roster-ui")||customElements.define("admin-roster-ui",wh);function Xi(s,t){return`entry.${s}.${t}`}function GO(s,t){if(!s||!t)return s;let e=s.entries.map(i=>{let r=t.get(Xi(i.id,"enabled")),n=t.get(Xi(i.id,"order")),o=t.get(Xi(i.id,"content"));return{...i,enabled:typeof r=="boolean"?r:i.enabled,order:typeof n=="number"?n:i.order,content:typeof o=="string"?o:i.content}});return{...s,entries:e}}P();var bq={"prompt-section":"Prompt sections",skill:"Skills",workflow:"Workflows",resource:"Resources",tool:"Tools","pattern-source":"Pattern sources"},kh=class extends v{static properties={_v:{type:Number,default:0}};static template=t=>t._renderTemplate();#t=`admin-settings-h-${Math.random().toString(36).slice(2,8)}`;#e=null;#i=null;#s=new Set;#r=null;connected(){this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#t),this.addEventListener("change",this.#c),this.addEventListener("input",this.#d),this.addEventListener("press",this.#u)}disconnected(){this.removeEventListener("change",this.#c),this.removeEventListener("input",this.#d),this.removeEventListener("press",this.#u),this.#r&&(this.#r(),this.#r=null)}get persona(){return this.#e}set persona(t){this.#e=t,this._v++}get store(){return this.#i}set store(t){this.#r&&(this.#r(),this.#r=null),this.#i=t,t?.subscribe&&(this.#r=t.subscribe(()=>{this._v++})),this._v++}_renderTemplate(){this._v;let t=this.#e,e=this.#i;if(!t)return Y`<div data-part="empty" role="status">No persona selected.</div>`;let i=this.#n(t);return Y`
564
+ `}#s(){return Y`<div data-part="empty" role="status">No personas yet.</div>`}#r=t=>{if(t.key!=="Enter"&&t.key!==" ")return;let e=t.target.closest?.('[data-part="row"]');e&&this.contains(e)&&(t.preventDefault(),e.click())};#n=t=>{let e=t.target.closest?.('[data-part="row"]');if(e&&this.contains(e)){let n=e.getAttribute("data-persona-id");n&&n!==this["active-id"]&&(this["active-id"]=n,this.dispatchEvent(new CustomEvent("persona-change",{bubbles:!0,detail:{personaId:n}})));return}let i=t.target.closest?.('[data-action="export"]');if(i&&this.contains(i)){this.#a();return}let r=t.target.closest?.('[data-action="import"]');r&&this.contains(r)&&this.#o()};#a(){let t=this["active-id"],e=(Array.isArray(this.personas)?this.personas:[]).find(a=>a.id===t);if(!e)return;let i=YO(e),r=new Blob([i],{type:"application/json"}),n=URL.createObjectURL(r),o=this.ownerDocument.createElement("a");o.href=n,o.download=`${e.id}.persona.json`,o.click(),URL.revokeObjectURL(n)}#o(){this.#e||(this.#e=this.ownerDocument.createElement("input"),this.#e.type="file",this.#e.accept="application/json",this.#e.setAttribute("data-part","import-file"),this.#e.style.display="none",this.appendChild(this.#e)),this.#e.value="",this.#e.click()}#l=async t=>{let e=t.target;if(!e||e!==this.#e)return;let i=e.files?.[0];if(i)try{let r=await i.text(),n=(Array.isArray(this.personas)?this.personas:[]).map(a=>a.id),o=HO(r,n);this.dispatchEvent(new CustomEvent("persona-import",{bubbles:!0,detail:{persona:o}}))}catch(r){this.dispatchEvent(new CustomEvent("persona-import-error",{bubbles:!0,detail:{error:r instanceof Error?r.message:String(r)}}))}}};customElements.get("admin-roster-ui")||customElements.define("admin-roster-ui",wh);function Xi(s,t){return`entry.${s}.${t}`}function GO(s,t){if(!s||!t)return s;let e=s.entries.map(i=>{let r=t.get(Xi(i.id,"enabled")),n=t.get(Xi(i.id,"order")),o=t.get(Xi(i.id,"content"));return{...i,enabled:typeof r=="boolean"?r:i.enabled,order:typeof n=="number"?n:i.order,content:typeof o=="string"?o:i.content}});return{...s,entries:e}}P();var vq={"prompt-section":"Prompt sections",skill:"Skills",workflow:"Workflows",resource:"Resources",tool:"Tools","pattern-source":"Pattern sources"},kh=class extends v{static properties={_v:{type:Number,default:0}};static template=t=>t._renderTemplate();#t=`admin-settings-h-${Math.random().toString(36).slice(2,8)}`;#e=null;#i=null;#s=new Set;#r=null;connected(){this.setAttribute("role","region"),this.setAttribute("aria-labelledby",this.#t),this.addEventListener("change",this.#c),this.addEventListener("input",this.#d),this.addEventListener("press",this.#u)}disconnected(){this.removeEventListener("change",this.#c),this.removeEventListener("input",this.#d),this.removeEventListener("press",this.#u),this.#r&&(this.#r(),this.#r=null)}get persona(){return this.#e}set persona(t){this.#e=t,this._v++}get store(){return this.#i}set store(t){this.#r&&(this.#r(),this.#r=null),this.#i=t,t?.subscribe&&(this.#r=t.subscribe(()=>{this._v++})),this._v++}_renderTemplate(){this._v;let t=this.#e,e=this.#i;if(!t)return Y`<div data-part="empty" role="status">No persona selected.</div>`;let i=this.#n(t);return Y`
565
565
  <header data-part="header">
566
566
  <h2 data-part="title" id=${this.#t}>${t.label??t.id} — Settings</h2>
567
567
  </header>
568
568
  <div data-part="sections">
569
569
  ${i.map(r=>this.#a(r,e))}
570
570
  </div>
571
- `}#n(t){let e=new Map;for(let i of t.entries){let r=e.get(i.kind);r?r.push(i):e.set(i.kind,[i])}return ZO.filter(i=>e.has(i)).map(i=>({kind:i,label:bq[i]??i,entries:e.get(i).sort((r,n)=>r.order-n.order)}))}#a(t,e){return Y`
571
+ `}#n(t){let e=new Map;for(let i of t.entries){let r=e.get(i.kind);r?r.push(i):e.set(i.kind,[i])}return ZO.filter(i=>e.has(i)).map(i=>({kind:i,label:vq[i]??i,entries:e.get(i).sort((r,n)=>r.order-n.order)}))}#a(t,e){return Y`
572
572
  <section data-part="section" data-kind=${t.kind} aria-label=${t.label}>
573
573
  <text-ui data-part="section-heading" variant="kicker">${t.label}</text-ui>
574
574
  <div data-part="entries">
@@ -598,4 +598,4 @@ ${r.content}`,o=n.toLowerCase();for(let a of e)o.includes(a.toLowerCase())&&i.pu
598
598
  `}#l(t,e){let i=e?.get(Xi(t.id,"enabled"));return typeof i=="boolean"?i:t.enabled}#h(t,e){let i=e?.get(Xi(t.id,"content"));return typeof i=="string"?i:t.content}#c=t=>{let e=t.target.closest?.('[data-part="entry-enabled"]');if(e&&this.contains(e)){let i=e.getAttribute("data-entry-id"),r=!!t.detail?.checked;this.store?.set(Xi(i,"enabled"),r),this.dispatchEvent(new CustomEvent("entry-change",{bubbles:!0,detail:{entryId:i,field:"enabled",value:r}}))}};#d=t=>{let e=t.target.closest?.('[data-part="entry-content-input"]');if(e&&this.contains(e)){let i=e.getAttribute("data-entry-id"),r=t.detail?.value??e.value??"";this.store?.set(Xi(i,"content"),r),this.dispatchEvent(new CustomEvent("entry-change",{bubbles:!0,detail:{entryId:i,field:"content",value:r}}))}};#u=t=>{let e=t.target.closest?.('[data-action="collapse-toggle"]');if(!e||!this.contains(e))return;let i=e.getAttribute("data-entry-id");this.#s.has(i)?this.#s.delete(i):this.#s.add(i),this._v++}};customElements.get("admin-settings-ui")||customElements.define("admin-settings-ui",kh);P();var rC=Object.freeze({route:()=>{},close:()=>{},feed:()=>{},get:()=>{},disposeAll:()=>{},hosts:new Map}),Ah=class extends v{static properties={"active-id":{type:String,default:"",reflect:!0}};static template=()=>null;#t=[];#e=null;#i=null;#s=null;#r=null;#n=null;#a=new Map;#o=null;#l=null;#h=null;#c=rC;get personas(){return this.#t}set personas(t){this.#t=Array.isArray(t)?t:[],this.#f(),this.#d()}get renderer(){return this.#e}set renderer(t){this.#e=t??null,this.#c=t?MO({renderer:t}):rC}get runTurn(){return this.#i}set runTurn(t){this.#i=typeof t=="function"?t:null}get activePersona(){return this.#o}get activeStore(){return this.#l}attributeChangedCallback(t,e,i){if(t==="personas"){if(i==null)this.personas=[];else try{let r=JSON.parse(i);this.personas=Array.isArray(r)?r:[]}catch{this.personas=[]}return}super.attributeChangedCallback(t,e,i)}connected(){this.#s=this.querySelector("admin-roster-ui"),this.#r=this.querySelector("admin-settings-ui"),this.#n=this.querySelector("chat-shell"),this.#s?.addEventListener("persona-change",this.#m),this.#s?.addEventListener("persona-import",this.#g),this.#n?.addEventListener("submit",this.#O),this.#f(),this.#d()}#d(){if(!this.isConnected||this.#o)return;let t=this["active-id"]||this.#t[0]?.id||"";t&&this.setActivePersona(t)}disconnected(){this.#s?.removeEventListener("persona-change",this.#m),this.#s?.removeEventListener("persona-import",this.#g),this.#n?.removeEventListener("submit",this.#O)}setActivePersona(t){let e=this.#t.find(n=>n.id===t);if(!e)return{genuineSwap:!1};let i=this.#u(e),r=i!==this.#l;return this.#o=e,this.#l=i,this["active-id"]=t,this.#s&&(this.#s["active-id"]=t),this.#r&&(this.#r.persona=e,this.#r.store=i),r?(this.#n?.clear?.(),this.#c.disposeAll(),this.#h=WO(),this.dispatchEvent(new CustomEvent("persona-activated",{bubbles:!0,detail:{personaId:t,reset:!0}}))):this.dispatchEvent(new CustomEvent("persona-activated",{bubbles:!0,detail:{personaId:t,reset:!1}})),{genuineSwap:r}}#u(t){let e=this.#a.get(t.id);return e||(e=VO(t),this.#a.set(t.id,e)),e}#f(){this.#s&&(this.#s.personas=this.#t.map(t=>({id:t.id,label:t.label,category:t.category})))}async send(t){if(!this.#n||!this.#o||!t)return;this.#n.appendMessage({role:"user",content:t}),this.#n.appendMessage({role:"assistant",content:""}),this.#n.startStreaming();let e=this.#n.querySelector("chat-status"),i=this.#i?this.#i(this.#h,t):this.#p(t);await RO(this.#n,this.#c,{events:i,statusEl:e})}async*#p(t){let e=GO(this.#o,this.#l),i=FO(e),{text:r}=jO(i.prompt);yield{type:"progress",stage:"started"},yield{type:"text",text:`[stub \u2014 persona "${e.label}" (${e.id})]
599
599
  ${r}
600
600
 
601
- You said: ${t}`},yield{type:"progress",stage:"done"},yield{type:"done"}}#m=t=>{let e=t.detail?.personaId;e&&this.setActivePersona(e)};#g=t=>{let e=t.detail?.persona;e&&(this.#t=[...this.#t,e],this.#f(),this.setActivePersona(e.id),this.dispatchEvent(new CustomEvent("persona-imported",{bubbles:!0,detail:{persona:e}})))};#O=t=>{let e=t.detail?.text;e&&this.send(e)}};customElements.get("agent-admin-ui")||customElements.define("agent-admin-ui",Ah);export{pa as A2UIRoot,sh as AdminCommand,eh as AdminShell,ih as AdminSidebar,ah as ChatComposer,nh as ChatShell,hh as ChatSidebar,oh as ChatThread,Id as ConfirmDialog,dh as EditorCanvas,ch as EditorShell,ph as EditorSidebar,uh as EditorToolbar,rh as EmbedShell,bh as FormPopover,Td as GenRoot,Ca as InvoiceHistory,LO as PROGRESS_LABELS,Qa as PaymentMethodList,Ta as PlanPicker,mh as SimpleShell,gh as ThemePanel,wh as UIAdminRoster,kh as UIAdminSettings,Ah as UIAgentAdmin,Ea as UIBillingOverview,Ld as UIDashboardLayout,Rd as UIDateRangeSelector,vh as UIIntegrationsPage,$a as UIInvoiceDetail,xh as UINotificationPreferences,Oh as UIOnboardingChecklist,Pa as UIPaymentMethodForm,MO as createSurfaceRegistry,Xi as entryStoreKey,QD as isFocusInInput,GO as readLivePersona,RO as wireAgentEvents};
601
+ You said: ${t}`},yield{type:"progress",stage:"done"},yield{type:"done"}}#m=t=>{let e=t.detail?.personaId;e&&this.setActivePersona(e)};#g=t=>{let e=t.detail?.persona;e&&(this.#t=[...this.#t,e],this.#f(),this.setActivePersona(e.id),this.dispatchEvent(new CustomEvent("persona-imported",{bubbles:!0,detail:{persona:e}})))};#O=t=>{let e=t.detail?.text;e&&this.send(e)}};customElements.get("agent-admin-ui")||customElements.define("agent-admin-ui",Ah);export{pa as A2UIRoot,sh as AdminCommand,eh as AdminShell,ih as AdminSidebar,ah as ChatComposer,nh as ChatShell,hh as ChatSidebar,oh as ChatThread,Id as ConfirmDialog,dh as EditorCanvas,ch as EditorShell,ph as EditorSidebar,uh as EditorToolbar,rh as EmbedShell,bh as FormPopover,Td as GenRoot,Ca as InvoiceHistory,LO as PROGRESS_LABELS,Qa as PaymentMethodList,Ta as PlanPicker,mh as SimpleShell,gh as ThemePanel,wh as UIAdminRoster,kh as UIAdminSettings,Ah as UIAgentAdmin,Ea as UIBillingOverview,Ld as UIDashboardLayout,Rd as UIDateRangeSelector,vh as UIIntegrationsPage,$a as UIInvoiceDetail,xh as UINotificationPreferences,Oh as UIOnboardingChecklist,Pa as UIPaymentMethodForm,MO as createSurfaceRegistry,Xi as entryStoreKey,MD as isFocusInInput,GO as readLivePersona,RO as wireAgentEvents};