hyper-html-api 0.9.0 → 0.9.1
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
var HyperHtmlApi=(()=>{var
|
|
2
|
-
`)?{type:"textarea"}:{type:"text"}}function hi(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=Cn(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function pi(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function No(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function mi(e){return` \xB7 ${e}`}function Oo(e,t){if(typeof e=="string"){let n=t&&t.defaultView,o=n&&n.DOMParser||globalThis.DOMParser;return new o().parseFromString(e,"text/html")}if(e&&e.nodeType===9)return e;throw new TypeError("expected an HTML string or a Document")}function Fo(e){let t=new Map;return(n,o)=>{if(typeof o!="string")return Oo(o,e);let r=t.get(n);if(r&&r.text===o)return r.doc;let s=Oo(o,e);return t.set(n,{text:o,doc:s}),s}}function Fr(e,t){let n=t.doctype;if(!n)return!1;let o=e.doctype;if(o&&o.name===n.name&&o.publicId===n.publicId&&o.systemId===n.systemId)return!1;let r=e.implementation.createDocumentType(n.name,n.publicId,n.systemId);return o?e.replaceChild(r,o):e.insertBefore(r,e.documentElement),!0}function Vo(e,t=[]){if(typeof e!="function")return()=>!1;let n=new WeakMap,o=new Set(t);return r=>{if(!r||r.nodeType!==1)return!1;let s=n.get(r);if(s!==void 0)return s;let c=[],l=r,a=!1;for(;l&&l.nodeType===1;){let b=n.get(l);if(b!==void 0){a=b;break}if(c.push(l),e(l,o.has(l))){a=!0;break}if(o.has(l))break;l=l.parentElement}for(let b of c)n.set(b,a);return a}}var gi="~",Vr="^";function zo(e,t){let n=new WeakMap;if(!e||!t||typeof t!="object"||Array.isArray(t))return n;let o=t[gi],r=typeof o=="string"?o.split(",").map(Number):null,s=r&&typeof t[Vr]=="string"?t[Vr].split(","):null,c=g=>Number.isInteger(g)&&g>=0,l=0,a=!1,b=g=>{let m=g;for(;m>0;){let u=r[l++];if(l>r.length||!c(u))return!1;m+=u-1}return!0},p=(g,m)=>{if(a)return;if(r){let y=l++,S=r[y];if(y>=r.length||!c(S)){a=!0;return}let v=!s||s[y]===g.tagName.toLowerCase();if(!v||S!==g.children.length){let D=v&&t[m];typeof D=="string"&&D&&n.set(g,D),b(S)||(a=!0);return}}let u=t[m];typeof u=="string"&&u&&n.set(g,u);let h=g.children;for(let y=0;y<h.length;y++)p(h[y],m===""?String(y):`${m}.${y}`)};return p(e,""),n}function zr(e){return t=>{for(let n of e){let o=n(t);if(typeof o=="string"&&o!=="")return o}return null}}var wn=zr([e=>e.getAttribute("data-id"),e=>e.getAttribute("id")]);function Mo(e,t,n,o=null){let r=new Map,s=new Set,c=l=>{if(n(l))return;let a=t(l);a&&(r.has(a)?s.add(a):r.set(a,l))};if(o){let l=a=>{for(let b of a.querySelectorAll(o))c(b);for(let b of a.querySelectorAll("template"))b.content&&l(b.content)};c(e),l(e.tagName==="TEMPLATE"&&e.content?e.content:e)}else{let l=a=>{c(a);let b=a.tagName==="TEMPLATE"&&a.content?a.content.children:a.children;for(let p=0;p<b.length;p++)l(b[p])};l(e)}for(let l of s)r.delete(l),l.startsWith("merge:")&&console.warn(`[hyper-morph] merge disabled for duplicate identity "${l.slice(l.indexOf(":",6)+1)}"`);return r}var bi=new Set(["href","src","name","type","role"]),Kr=new Set(["SCRIPT","STYLE","TEXTAREA","TEMPLATE","IFRAME","OBJECT","CANVAS","VIDEO","AUDIO","svg","SVG"]);function Ln(e,t=5381){let n=t;for(let o=0;o<e.length;o++)n=(n<<5)+n^e.charCodeAt(o);return n>>>0}function qr(e){return e.replace(/\s+/g," ")}function Gr({ignored:e=()=>!1,ignoreAttribute:t=()=>!1}={}){let n=new WeakMap,o=new WeakMap;function r(m){let u=m.attributes,h=u.length;if(h===0)return{all:"",sig:m.tagName+"|"};let y=[],S="",v=[];for(let D=0;D<h;D++){let q=u[D],Z=q.name;t(m,Z)||y.push(Z+"="+q.value),Z==="class"?S=q.value.indexOf(" ")<0?q.value:q.value.split(/\s+/).filter(Boolean).sort().join(" "):bi.has(Z)&&v.push(Z+"="+q.value)}return y.length>1&&y.sort(),v.length>1&&v.sort(),{all:y.join(""),sig:m.tagName+"|"+S+(v.length?"|"+v.join("|"):"")}}function s(m){return m.nodeType===1&&m.tagName==="TEMPLATE"&&m.content?m.content.childNodes:m.childNodes}function c(m){let u=n.get(m);if(u)return u;if(m.nodeType===3)u={hash:"T"+Ln(m.nodeValue),hint:qr(m.nodeValue).slice(0,64),sig:null,tok:null};else if(m.nodeType===8)u={hash:"C"+Ln(m.nodeValue),hint:"",sig:null,tok:null};else if(m.nodeType===1){let h=r(m),y=Ln(m.tagName+""+h.all),S="";for(let v of a(m))if(v.nodeType===1){let D=c(v);y=Ln(D.hash,y),S.length<64&&(S+=" "+D.hint)}else y=Ln(b(v),y),v.kind==="text"&&S.length<64&&(S+=v.value.slice(0,64));u={hash:"E"+y,hint:qr(S).trim().slice(0,64),sig:h.sig,tok:null}}else u={hash:"N"+m.nodeType,hint:"",sig:null,tok:null};return n.set(m,u),u}function l(m){if(!m.tok){m.tok=new Set;for(let u of m.hint.toLowerCase().split(/[^\p{L}\p{N}]+/u))u&&m.tok.add(u)}return m.tok}function a(m){let u=o.get(m);if(u)return u;u=[];let h=null,y=()=>{h&&(h.value=h.nodes.map(S=>S.nodeValue).join(""),u.push(h),h=null)};for(let S of s(m)){if(S.nodeType===3){h||(h={kind:"text",nodes:[],value:"",parent:m,hash:void 0}),h.nodes.push(S);continue}y(),S.nodeType===8?u.push({kind:"comment",nodes:[S],value:S.nodeValue,parent:m,hash:void 0}):S.nodeType===1&&!e(S)&&u.push(S)}return y(),o.set(m,u),u}function b(m){return m.nodeType===1?c(m).hash:(m.hash===void 0&&(m.hash=(m.kind==="text"?"T":"C")+Ln(m.value)),m.hash)}function p(m,u){let h=l(c(m)),y=l(c(u));if(h.size===0&&y.size===0)return{coef:1,share:1};if(h.size===0||y.size===0)return null;let S=0;for(let v of h)y.has(v)&&S++;return{coef:S/Math.min(h.size,y.size),share:S/Math.max(h.size,y.size)}}function g(m,u){let h=p(m,u);return!!h&&h.coef>=.5}return{meta:c,unitsOf:a,unitHash:b,similar:g,score:p,childrenOf:s}}var Jr=16,yi=2e3,ki=3,wi={align:0};function qo(e,t,n){let{meta:o,unitsOf:r,unitHash:s,similar:c,score:l}=n.analyzer,a=n.baseId||(()=>null),b=n.sideId||(()=>null),p=new Map,g=new Map,m=new Set,u=new Map,h=new Set,y=new Set,S=new Set,v=[],D=[],q=[],Z=[],ae=yi,ie=new Map,he=new Map,K=(f,T)=>{p.set(f,T),g.set(T,f)},J=f=>!!f&&f.nodeType===1,ye=(f,T)=>{let x=u.get(f);return!!x&&x.has(T)},je=f=>Kr.has(f.tagName),Fe=(f,T)=>{let x=a(f);if(!x)return!0;let B=b(T);return!B||x===B},ot=globalThis.__hyperMorphProfile,ct=ot?performance.now():0;ot&&(o(e),o(t),ot.meta=(ot.meta||0)+(performance.now()-ct),ct=performance.now()),K(e,t);for(let[f,T]of n.baseIndex){let x=n.sideIndex.get(f);x&&x.tagName===T.tagName&&!p.has(T)&&!g.has(x)&&K(T,x)}Z.push([e,t]);for(let[f,T]of p)J(f)&&f!==e&&Z.push([f,T]);return dt(),Ct(),ot&&(ot.align=(ot.align||0)+(performance.now()-ct)),{map:p,reverse:g,moved:h,identical:y,pairIdenticalChildren:F,weak:m,unpair:vt,rematch:Ct,insertedByHash:Oe};function Ct(){at(),dt();for(let f=0;f<q.length;){let T=q.length;rt(f,T),f=T,dt(),at(),dt()}}function vt(f){let T=p.get(f);if(!T)return;u.has(f)||u.set(f,new Set),u.get(f).add(T);let x=(I,E)=>{p.delete(I),g.delete(E),h.delete(I),y.delete(I),m.delete(I),S.delete(I)},B=(I,E)=>{for(let j of r(I)){let M=p.get(j);!M||!(J(M)?E.contains(M):E.contains(M.nodes[0]))||(x(j,M),J(j)&&B(j,M))}};x(f,T),J(f)&&B(f,T),v.push(f),D.push(T)}function Oe(){let f=new Map;for(let T of new Set(D)){if(g.has(T))continue;let x=o(T).hash;f.has(x)||f.set(x,[]),f.get(x).push(T)}return f}function dt(){for(;Z.length;){let[f,T]=Z.shift();S.has(f)||y.has(f)||Lt(f,T)}}function Qe(f,T){if(!je(f))for(let x of r(f))J(x)&&(T.push(x),Qe(x,T))}function Lt(f,T){S.add(f);let x=r(f),B=r(T);wi.align+=x.length+B.length,ie=new Map,he=new Map;for(let P=0;P<x.length;P++)ie.set(x[P],P);for(let P=0;P<B.length;P++)he.set(B[P],P);if(f.tagName==="HTML")for(let P of["HEAD","BODY"]){let Y=x.find(we=>J(we)&&we.tagName===P),Q=B.find(we=>J(we)&&we.tagName===P);Y&&Q&&!p.has(Y)&&!g.has(Q)&&K(Y,Q)}for(let P=0;P<x.length&&P<B.length;P++){let Y=x[P],Q=B[P];p.has(Y)||g.has(Q)||(J(Y)?J(Q)&&Y.tagName===Q.tagName&&Y.isEqualNode(Q)&&O(Y,Q):!J(Q)&&Y.kind===Q.kind&&Y.value===Q.value&&O(Y,Q))}Ze(x,B);let I=x.filter(P=>!p.has(P)),E=B.filter(P=>!g.has(P));I.length&&E.length&&(lt(I,E),ke(I,E),re(I,E,x,B),qe(x,B));let j=!1,M=!1;for(let P of x){if(!p.has(P)){J(P)&&(v.push(P),Qe(P,v),j=!0);continue}J(P)&&!y.has(P)&&Z.push([P,p.get(P)])}for(let P of B)!g.has(P)&&J(P)&&(D.push(P),Qe(P,D),M=!0);j&&M&&q.push([f,T])}function rt(f,T){for(let x=f;x<T;x++){let[B,I]=q[x],E=r(B),j=r(I),M=new Map,P=new Map,Y=null;for(let Q of E)J(Q)&&(p.has(Q)?Y=Q:(M.has(Y)||M.set(Y,[]),M.get(Y).push(Q)));Y=null;for(let Q of j)J(Q)&&(g.has(Q)?Y=g.get(Q):(P.has(Y)||P.set(Y,[]),P.get(Y).push(Q)));for(let[Q,we]of M){let Ye=P.get(Q);if(!(!Ye||we.length!==Ye.length)&&we.every((bt,ft)=>Ye[ft].tagName===bt.tagName&&Fe(bt,Ye[ft])&&!ye(bt,Ye[ft])))for(let bt=0;bt<we.length;bt++)et(we[bt],Ye[bt])}}}function et(f,T){K(f,T),m.add(f),Z.push([f,T]),dt()}function lt(f,T){let x=Rn(f,s),B=Rn(T,s),I=new Map;for(let E of T){let j=s(E);B.get(j)===1&&I.set(j,E)}for(let E of f){if(p.has(E))continue;let j=s(E);if(x.get(j)!==1)continue;let M=I.get(j);M&&!g.has(M)&&O(E,M)}}function O(f,T){K(f,T),y.add(f),J(f)&&S.add(f)}function F(f){let T=p.get(f);if(!T||!J(f))return;let x=r(f),B=r(T);for(let I=0;I<x.length&&I<B.length;I++)p.has(x[I])||O(x[I],B[I])}function ke(f,T){let x=j=>J(j)&&!je(j)?o(j).sig+""+o(j).hint:null,B=Rn(f,x),I=Rn(T,x),E=new Map;for(let j of T){let M=x(j);M!=null&&I.get(M)===1&&E.set(M,j)}for(let j of f){if(p.has(j))continue;let M=x(j);if(M==null||B.get(M)!==1)continue;let P=E.get(M);P&&!g.has(P)&&Fe(j,P)&&K(j,P)}}function re(f,T,x,B){let I=new Map;for(let j of T){if(!J(j)||g.has(j)||je(j))continue;let M=o(j).sig;I.has(M)||I.set(M,[]),I.get(M).push({el:j,index:he.get(j)})}let E=[];for(let j of f){if(p.has(j)||!J(j)||je(j))continue;let M=I.get(o(j).sig);if(!M||!M.length)continue;let P=ie.get(j),Y=M.filter(Q=>!g.has(Q.el)).map(Q=>({c:Q,d:Math.abs(Q.index-P)}));Y.sort((Q,we)=>Q.d-we.d),Y.length>Jr&&(Y=Y.slice(0,Jr));for(let{c:Q,d:we}of Y){if(!Fe(j,Q.el))continue;let Ye=l(j,Q.el);Ye&&Ye.coef>=.5&&E.push({b:j,s:Q.el,coef:Ye.coef,share:Ye.share,d:we,bi:P})}}E.sort((j,M)=>M.coef-j.coef||M.share-j.share||j.d-M.d||j.bi-M.bi);for(let j of E)!p.has(j.b)&&!g.has(j.s)&&K(j.b,j.s)}function Ne(f,T){return J(f)!==J(T)?!1:J(f)?f.tagName!==T.tagName||!Fe(f,T)?!1:je(f)||o(f).hint===""||o(T).hint===""?!0:c(f,T):f.kind===T.kind}function tt(f,T){let x=(I,E)=>{let j=E===null?-1:I===T?he.get(E):ie.get(E),M=I[j+1];return M&&!J(M)?M:null},B=null;for(let I of f){if(J(I)){B=I;continue}if(p.has(I))continue;let E=B===null?null:p.get(B);if(B!==null&&!E)continue;let j=x(T,E);j&&!g.has(j)&&j.kind===I.kind&&K(I,j)}}function qe(f,T){tt(f,T);let x=Ke(f,T),B=(E,j)=>J(E)&&o(E).hint!==""&&o(j).hint===""&&!!j.querySelector("br")&&!x(E,j),I=0;for(let E of f){if(p.has(E)){let M=he.get(p.get(E));M!==void 0&&M>=I&&(I=M+1);continue}let j=0;for(let M=I;M<T.length&&j<ki;M++){let P=T[M];if(!g.has(P)&&(j++,Ne(E,P)&&!ye(E,P)&&!B(E,P))){K(E,P),J(E)&&(o(E).hint===""||o(P).hint==="")&&m.add(E),I=M+1;break}}}Ze(f,T)}function Ke(f,T){let x=(B,I,E)=>{for(let j=I-1;j>=0;j--)if(J(B[j])&&E(B[j]))return B[j];return null};return(B,I)=>{let E=ie.get(B),j=he.get(I);if(E===j)return!0;let M=x(f,E,Y=>p.has(Y)),P=x(T,j,Y=>g.has(Y));return M?p.get(M)===P:!P}}function Ze(f,T){let x=f.filter(M=>J(M)&&!p.has(M)),B=T.filter(M=>J(M)&&!g.has(M));if(!x.length||!B.length)return;let I=Rn(x,M=>M.tagName),E=Rn(B,M=>M.tagName),j=Ke(f,T);for(let M of x){let P=M.tagName;if(I.get(P)!==1||E.get(P)!==1)continue;let Y=B.find(Q=>Q.tagName===P);Y&&!g.has(Y)&&j(M,Y)&&Fe(M,Y)&&!ye(M,Y)&&(K(M,Y),m.add(M))}}function at(){let f=new Map;for(let M of m)if(J(M)&&J(p.get(M))){let P=o(M).hash;f.has(P)||f.set(P,[]),f.get(P).push(M)}if(f.size)for(let M of D){if(g.has(M)||!J(M))continue;let P=f.get(o(M).hash),Y=P&&P.find(Q=>m.has(Q)&&!ye(Q,M)&&Fe(Q,M));Y&&(vt(Y),O(Y,M),h.add(Y))}let T=new Map,x=new Map,B=new Map;for(let M of m){let P=p.get(M);J(M)&&J(P)&&B.set(P,M)}let I=(M,P)=>{if(!g.has(M))return!0;let Y=B.get(M);return Y===g.get(M)&&Y!==P&&!Y.contains(P)},E=M=>{if(g.has(M)){let P=B.get(M);B.delete(M),vt(P)}};for(let M of[...D,...B.keys()]){if(g.has(M)&&!B.has(M))continue;let P=o(M).hash;if(T.has(P)||T.set(P,[]),T.get(P).push(M),je(M))continue;let Y=o(M).sig;x.has(Y)||x.set(Y,[]),x.get(Y).push(M)}let j=new Set;for(let M of m){let P=p.get(M);!J(M)||!J(P)||je(M)||o(M).hint===""||o(P).hint===""||c(M,P)||j.add(M)}for(let M of[...v,...j]){let P=p.get(M);if(P&&!(m.has(M)&&j.has(M)))continue;let Y=ft=>{P&&vt(M),E(ft)},Q=T.get(o(M).hash);if(Q){let ft=Q.find(le=>le!==P&&I(le,M)&&!ye(M,le));if(ft){Y(ft),O(M,ft),h.add(M);continue}}if(je(M)||ae<=0)continue;let we=x.get(o(M).sig);if(!we)continue;let Ye=null,bt=0;for(let ft of we)if(!(ft===P||!I(ft,M)||!Fe(M,ft)||ye(M,ft))&&(ae--<=0||c(M,ft)&&(bt++,Ye=ft,bt>1)))break;bt===1&&(Y(Ye),K(M,Ye),h.add(M),Z.push([M,Ye]))}}}function Rn(e,t){let n=new Map;for(let o of e){let r=t(o);r!=null&&n.set(r,(n.get(r)||0)+1)}return n}var Ai={diff:0},Yr=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null,xi=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u,Ti=/[\p{L}\p{M}\p{N}_'’]+|\s+|[\s\S]/gu,Si=/\P{M}\p{M}*/gu;function Xo(e){if(e==="")return[];if(Yr){let n=[];for(let o of Yr.segment(e))n.push(o.segment);return n}let t=[];for(let n of e.match(Ti))if(xi.test(n))for(let o of n.match(Si))t.push(o);else t.push(n);return t}var Ni=/^[ ]+$/,Oi=e=>Ni.test(e)?" ".repeat(e.length):e,Yn=e=>typeof e.k=="string"&&/^\s+$/.test(e.k),nt="",Xr=e=>e.every(t=>Yn(t)||t.k===nt),Mi=/^[\x00-\x7f\u00A0]*$/,vi=/[A-Za-z0-9_']+|[ \u00A0]+|\s|./g;function Ii(e){return e===""?[]:e.match(vi)}function An(e,t=!1){return(t?Ii(e):Xo(e)).map(n=>({k:Oi(n),raw:n,len:n.length}))}var vo=(...e)=>e.every(t=>Mi.test(t));function Ko(e,t,n){let o=e.length,r=t.length,s=Math.min(o+r,n),c=s+1,l=new Int32Array(2*s+3),a=[],b=o===0&&r===0;for(let u=0;u<=s&&!b;u++){a.push(l.slice(c-u,c+u+1));for(let h=-u;h<=u;h+=2){let y;h===-u||h!==u&&l[c+h-1]<l[c+h+1]?y=l[c+h+1]:y=l[c+h-1]+1;let S=y-h,v=y;for(;y<o&&S<r&&e[y].k===t[S].k;)y++,S++;if(Ai.diff+=1+y-v,l[c+h]=y,y>=o&&S>=r){b=!0;break}}}if(!b)return null;let p=[],g=o,m=r;for(let u=a.length-1;u>0;u--){let h=a[u],y=g-m,S=y+u,v=y===-u||y!==u&&h[S-1]<h[S+1]?y+1:y-1,D=h[v+u],q=D-v;for(;g>D&&m>q;)p.push([0,g-1,m-1]),g--,m--;g===D?(p.push([1,g,m-1]),m--):(p.push([-1,g-1,m]),g--)}for(;g>0&&m>0;)p.push([0,g-1,m-1]),g--,m--;return p.reverse(),p}function Ei(e,t,n){let o=g=>g.k===nt;if(!e.some(o)&&!t.some(o))return Ko(e,t,n);let r=[],s=[];for(let g=0;g<e.length;g++)o(e[g])||r.push(g);for(let g=0;g<t.length;g++)o(t[g])||s.push(g);let c=Ko(r.map(g=>e[g]),s.map(g=>t[g]),n);if(!c)return null;let l=[],a=0,b=0,p=(g,m)=>{for(;a<g&&b<m&&e[a].k===t[b].k;)l.push([0,a++,b++]);let u=Ko(e.slice(a,g),t.slice(b,m),n);if(!u)return!1;for(let[h,y,S]of u)l.push([h,y+a,S+b]);return a=g,b=m,!0};for(let[g,m,u]of c)if(g===0){if(!p(r[m],s[u]))return null;l.push([0,a,b]),a++,b++}return p(e.length,t.length)?l:null}function Pn(e,t,n=4e3){let o=[],r=0;for(;r<e.length&&r<t.length&&e[r].k===t[r].k;)e[r].raw!==t[r].raw&&o.push({bi:r,tok:t[r]}),r++;let s=0;for(;s<e.length-r&&s<t.length-r&&e[e.length-1-s].k===t[t.length-1-s].k;)e[e.length-1-s].raw!==t[t.length-1-s].raw&&o.push({bi:e.length-1-s,tok:t[t.length-1-s]}),s++;let c=e.slice(r,e.length-s),l=t.slice(r,t.length-s),a=Di(c,l)?null:Ei(c,l,n);if(!a){let v=c.length||l.length?[{bs:r,be:r+c.length,toks:l}]:[];return{hunks:v,cosmetic:o,coarse:!0,parts:v.map(D=>({...D,gap:[],group:0})),cosmeticEq:o}}let b=[],p=(v,D)=>{c[v].raw!==l[D].raw&&o.push({bi:r+v,tok:l[D]})},g=null,m=[],u=0,h=0,y=()=>{g&&b.push(g),g=null;for(let[v,D]of m)p(v,D);m=[],u++};for(let[v,D,q]of a){if(v===0){g&&Yn(c[D])&&!c[D].k.includes(`
|
|
3
|
-
`)?m.push([D,q]):(y(),p(D,q)),h=D+1;continue}(!g||m.length)&&(g&&b.push(g),g={bs:r+h,be:r+h,toks:[],gap:m.map(([Z,ae])=>({bi:r+Z,tok:l[ae]})),group:u},m=[]),v===-1?(g.be=r+h+1,h=D+1):g.toks.push(l[q])}y(),Ci(b,e);let S=Jo(b);return{hunks:S.hunks,cosmetic:o.concat(S.cosmetic),parts:b,cosmeticEq:o}}function Ci(e,t){for(let n=0;n<e.length;n++){let o=e[n];if(o.gap.length)continue;let r=n+1<e.length?e[n+1].bs:1/0;if(o.toks.length){if(o.bs===o.be)for(;o.bs+1<r&&o.bs<t.length&&o.toks[0].k===nt&&t[o.bs].k===nt;)o.toks=[...o.toks.slice(1),o.toks[0]],o.bs++,o.be++}else for(;o.be+1<r&&o.be<t.length&&t[o.bs].k===nt&&t[o.be].k===nt;)o.bs++,o.be++}}function Jo(e,t=()=>!1){let n=[],o=[],r=null,s=-1;for(let c of e){let l=t(c);if(r&&!r.alone&&!l&&c.group===s){r.be=c.be;for(let a of c.gap)r.toks.push(a.tok);for(let a of c.toks)r.toks.push(a);continue}r&&n.push({bs:r.bs,be:r.be,toks:r.toks});for(let a of c.gap)o.push(a);r={bs:c.bs,be:c.be,toks:c.toks.slice(),alone:l},s=c.group}return r&&n.push({bs:r.bs,be:r.be,toks:r.toks}),{hunks:n,cosmetic:o}}var Li=(e,t)=>e.bs===t.bs&&e.be===t.be&&Qo(e.toks,t.toks);function Zo(e,t,n){let o=p=>g=>p.some(m=>Li(g,m)),r=Jo(e.parts,o(t.parts)),s=Jo(t.parts,o(e.parts)),c=e.cosmeticEq.concat(r.cosmetic),l=t.cosmeticEq.concat(s.cosmetic),[a,b]=n?Ri(r.hunks,s.hunks,n,c,l):[r.hunks,s.hunks];return{lh:a,rh:b,cosL:c,cosR:l}}function Ri(e,t,n,o,r){let s=(u,h)=>u.k===h.k&&u.raw===h.raw,c=[{list:e.map(u=>({...u})),resp:new Set(o.map(u=>u.bi))},{list:t.map(u=>({...u})),resp:new Set(r.map(u=>u.bi))}],l=u=>u.bs===u.be,a=(u,h,y,S)=>{let v=u.list[h];if(!l(v))return S(v)===y?v.toks:null;let D=h?u.list[h-1].be:0,q=h+1<u.list.length?u.list[h+1].bs:n.length;if(y<D||y>q)return null;let Z=v.toks,ae=v.bs;for(;ae>y;){let ie=Z[Z.length-1];if(!s(ie,n[ae-1])||u.resp.has(ae-1))return null;Z=[ie,...Z.slice(0,-1)],ae--}for(;ae<y;){if(!s(Z[0],n[ae])||u.resp.has(ae))return null;Z=[...Z.slice(1),Z[0]],ae++}return Z},b=(u,h,y,S,v,D)=>{let q=u.list[h],Z=v?y.slice(y.length-S):y.slice(0,S),ae=v?y.slice(0,y.length-S):y.slice(S),ie={bs:D,be:D,toks:Z};if(l(q)){if(!ae.length){u.list[h]=ie;return}let K={bs:D,be:D,toks:ae};v&&(K.lead=!0),u.list.splice(h,1,...v?[K,ie]:[ie,K]);return}let he={bs:q.bs,be:q.be,toks:ae};u.list.splice(h,1,...v?[he,ie]:[ie,he])},p=(u,h,y,S,v)=>{let D=u.list[h],q=v?y.slice(y.length-S):y.slice(0,S),Z=v?y.slice(0,y.length-S):y.slice(S),ae={bs:D.bs,be:D.be,toks:q};if(!Z.length){u.list[h]=ae;return}let ie=v?{bs:D.bs,be:D.bs,toks:Z,lead:!0}:{bs:D.be,be:D.be,toks:Z};u.list.splice(h,1,...v?[ie,ae]:[ae,ie])},g=c[0],m=c[1];for(let u=0;u<64;u++){let h=!1;e:for(let y=0;y<g.list.length;y++)for(let S=0;S<m.list.length;S++){let v=g.list[y],D=m.list[S];if(!(v.bs===D.bs&&v.be===D.be&&Qo(v.toks,D.toks)))for(let q of[!0,!1]){let Z=ie=>q?ie.be:ie.bs,ae=l(v)?[Z(D),v.bs]:[Z(v)];for(let ie of ae){let he=a(g,y,ie,Z),K=he&&a(m,S,ie,Z);if(!K)continue;let J=(ct,Ct)=>q?ct[ct.length-1-Ct]:ct[Ct],ye=0;for(;ye<he.length&&ye<K.length&&J(he,ye).k===J(K,ye).k;)ye++;if(!ye)continue;let je=q?he.slice(0,he.length-ye):he.slice(ye),Fe=q?K.slice(0,K.length-ye):K.slice(ye);if(!(ye<he.length&&ye<K.length&&!Xr(je)&&!Xr(Fe)&&(l(v)&&l(D)||v.bs===D.bs&&v.be===D.be)||!(q?he.slice(he.length-ye):he.slice(0,ye)).some(ct=>!Yn(ct)))){if(ye===he.length&&ye===K.length&&l(v)&&l(D)){if(v.bs===ie&&D.bs===ie)continue;g.list[y]={bs:ie,be:ie,toks:he},m.list[S]={bs:ie,be:ie,toks:K}}else!l(v)&&v.bs===D.bs&&v.be===D.be?(p(g,y,he,ye,q),p(m,S,K,ye,q)):(b(g,y,he,ye,q,ie),b(m,S,K,ye,q,ie));h=!0;break e}}}}if(!h)break}return[g.list,m.list]}var Pi=48,Hi=.3;function Di(e,t){let n=e.filter(c=>!Yn(c)),o=t.filter(c=>!Yn(c));if(Math.min(n.length,o.length)<Pi)return!1;let r=new Map;for(let c of n)r.set(c.k,(r.get(c.k)||0)+1);let s=0;for(let c of o){let l=r.get(c.k);l>0&&(s++,r.set(c.k,l-1))}return s/Math.min(n.length,o.length)<Hi}var ji=(e,t)=>{let n=new Set;for(let o of e.toks)typeof o.k!="string"&&n.add(o.k.el);for(let o=e.bs;o<e.be;o++)typeof t[o].k!="string"&&n.add(t[o].k.el);return n},Qo=(e,t)=>e.length===t.length&&e.every((n,o)=>n.k===t[o].k);function Zr(e,t,n,o="remote"){let r=Pn(e,t),s=Pn(e,n),{lh:c,rh:l,cosL:a,cosR:b}=Zo(r,s,e),p=O=>O.bs===O.be,g=O=>O.toks.some(F=>typeof F.k=="string"),m=O=>p(O)&&!g(O),u=(O,F)=>F.bs<O.be&&O.bs<F.be,h=(O,F)=>!u(O,F)&&F.bs<=O.be&&O.bs<=F.be&&(p(O)&&g(O)||p(F)&&g(F))&&!(p(O)&&p(F)),y=(O,F)=>O.bs===F.bs&&O.be===F.be&&Qo(O.toks,F.toks),S=[],v=new Set;for(let O of c){let F=l.find(ke=>!v.has(ke)&&y(O,ke));F?(v.add(F),S.push({bs:O.bs,be:O.be,side:"both",l:O,r:F,toks:O.toks})):S.push({bs:O.bs,be:O.be,side:"L",l:O,toks:O.toks,lead:!!O.lead})}for(let O of l)v.has(O)||S.push({bs:O.bs,be:O.be,side:"R",r:O,toks:O.toks,lead:!!O.lead});S.sort((O,F)=>O.bs-F.bs||O.be-F.be||F.lead-O.lead);let D=0,q=0;for(let O of S)O.side==="both"&&(D+=O.toks.length-(O.be-O.bs));let Z=S.map((O,F)=>F),ae=O=>Z[O]===O?O:Z[O]=ae(Z[O]),ie=(O,F)=>(O=ae(O),F=ae(F),O===F?!1:(Z[O]=F,!0)),he=S.map(O=>ji({bs:O.bs,be:O.be,toks:O.toks},e)),K={L:new Map,R:new Map};S.forEach((O,F)=>{let ke=O.side==="both"?["L","R"]:[O.side];for(let re of ke)for(let Ne of he[F])K[re].has(Ne)||K[re].set(Ne,[]),K[re].get(Ne).push(F)});for(let O of[K.L,K.R])for(let F of O.values())for(let ke=1;ke<F.length;ke++)ie(F[0],F[ke]);for(let O=0;O<S.length;O++)for(let F=O+1;F<S.length;F++){let ke=S[O],re=S[F];ke.side===re.side&&ke.side!=="both"||ke.bs>re.be||(u(ke,re)||h(ke,re)?ie(O,F):ke.bs===re.bs&&p(ke)&&p(re)&&q++)}let J=(O,F)=>{let ke=O==="L"?c:l;for(let re of ke)if(re.toks.some(Ne=>Ne.kind==="close"&&Ne.k.el===F.el))return re.bs;for(let re=0;re<e.length;re++)if(e[re].kind==="close"&&e[re].k.el===F.el)return re;return-1};S.forEach((O,F)=>{if(!(!m(O)||O.side==="both"))for(let ke of O.toks){if(ke.kind!=="open")continue;let re=J(O.side,ke.k);if(re<=O.bs)continue;let Ne=new Uint8Array(re-O.bs),tt=[];if(S.forEach((qe,Ke)=>{if(!(qe.side===O.side||p(qe))&&qe.bs<re&&qe.be>O.bs){tt.push(Ke);for(let Ze=Math.max(qe.bs,O.bs);Ze<Math.min(qe.be,re);Ze++)Ne[Ze-O.bs]=1}}),tt.length&&Ne.every(qe=>qe===1))for(let qe of tt)ie(F,qe)}});let ye=!0;for(;ye;){ye=!1;let O=new Map;S.forEach((F,ke)=>{let re=ae(ke),Ne=O.get(re)||{bs:F.bs,be:F.be,L:!1,R:!1};Ne.bs=Math.min(Ne.bs,F.bs),Ne.be=Math.max(Ne.be,F.be),F.side!=="R"&&(Ne.L=!0),F.side!=="L"&&(Ne.R=!0),O.set(re,Ne)}),S.forEach((F,ke)=>{for(let[re,Ne]of O){if(ae(ke)===ae(re)||!(Ne.L&&Ne.R))continue;let tt=F.bs<Ne.be&&F.be>Ne.bs,qe=p(F)&&g(F)&&(F.bs===Ne.be||F.bs===Ne.bs);(tt||qe)&&ie(ke,re)&&(ye=!0)}})}let je=new Map;S.forEach((O,F)=>{let ke=ae(F);je.has(ke)||je.set(ke,[]),je.get(ke).push(O)});let Fe=[];for(let O of je.values()){let F=O.some(re=>re.side==="L"),ke=O.some(re=>re.side==="R");if(F&&ke){let re=Math.min(...O.map(Ke=>Ke.bs)),Ne=Math.max(...O.map(Ke=>Ke.be)),tt=O.filter(Ke=>Ke.side!=="R").map(Ke=>Ke.l).sort((Ke,Ze)=>Ke.bs-Ze.bs),qe=O.filter(Ke=>Ke.side!=="L").map(Ke=>Ke.r).sort((Ke,Ze)=>Ke.bs-Ze.bs);Fe.push({bs:re,be:Ne,kind:"conflict",localHunks:tt,remoteHunks:qe})}else for(let re of O)Fe.push({bs:re.bs,be:re.be,kind:re.side,u:re})}let ot=(O,F)=>{let ke=O==="L"?c:l;for(let re of ke)if(re.toks.some(Ne=>Ne.kind==="close"&&Ne.k.el===F.el))return re.bs+.5;for(let re=0;re<e.length;re++)if(e[re].kind==="close"&&e[re].k.el===F.el)return re;return 1/0},ct=(O,F)=>{let ke=O==="L"?c:l;for(let re of ke)if(re.toks.some(Ne=>Ne.kind==="open"&&Ne.k.el===F.el))return re.bs-.5;for(let re=0;re<e.length;re++)if(e[re].kind==="open"&&e[re].k.el===F.el)return re;return-1/0},Ct=O=>O.kind==="R"?"R":"L",vt=O=>O.kind==="R"?1:0;Fe.sort((O,F)=>{if(O.bs!==F.bs)return O.bs-F.bs;let ke=O.bs===O.be,re=F.bs===F.be;if(ke!==re)return ke?-1:1;if(ke&&re&&O.kind!=="conflict"&&F.kind!=="conflict"){let tt=O.u.toks,qe=F.u.toks,Ke=at=>at.length&&at.every(f=>f.kind==="open"),Ze=at=>at.length&&at.every(f=>f.kind==="close");if(Ke(tt)&&Ke(qe)){let at=Math.max(...tt.map(T=>ot(Ct(O),T.k))),f=Math.max(...qe.map(T=>ot(Ct(F),T.k)));if(at!==f)return f-at}if(Ze(tt)&&Ze(qe)){let at=Math.min(...tt.map(T=>ct(Ct(O),T.k))),f=Math.min(...qe.map(T=>ct(Ct(F),T.k)));return at!==f?f-at:vt(F)-vt(O)}}let Ne=tt=>tt.u&&tt.u.lead?1:0;return Ne(F)-Ne(O)||vt(O)-vt(F)||O.be-F.be});let Oe=[],dt=[],Qe=0,Lt=O=>{O>Qe&&(Oe.push({bs:Qe,be:O,toks:e.slice(Qe,O),source:"base"}),Qe=O)};for(let O of Fe){if(Lt(O.bs),O.kind==="conflict"){let F=Yo(e,O.localHunks,O.bs,O.be),ke=Yo(e,O.remoteHunks,O.bs,O.be),re=o==="local"?F:o==="both"?F.concat(ke):ke;dt.push({bs:O.bs,be:O.be,base:e.slice(O.bs,O.be),local:F,remote:ke,resolved:re}),Oe.push({bs:O.bs,be:O.be,toks:re,source:"conflict",localHunks:O.localHunks,localToks:F,keepsLocal:o!=="remote"})}else Oe.push({bs:O.bs,be:O.be,toks:O.u.toks,source:O.kind==="R"?"remote":"local",localHunks:O.kind==="R"?[]:[O.u.l]});Qe=Math.max(Qe,O.be)}Lt(e.length);let rt=new Map(a.map(O=>[O.bi,O.tok])),et=new Map(b.map(O=>[O.bi,O.tok])),lt=[];for(let O of Oe){O.source==="base"&&(O.toks=O.toks.map((F,ke)=>{let re=O.bs+ke,Ne=rt.get(re),tt=et.get(re),qe=Ne&&tt?o==="remote"?tt:Ne:Ne||tt||F;return qe===F?F:{...qe,cosmetic:!0}}));for(let F of O.toks)lt.push({...F,src:O.source})}return{tokens:lt,segments:Oe,conflicts:dt,localHunks:c,remoteHunks:l,collapsedDelta:D,samePoint:q,mapLocalOffset:Bi(e,c,Oe)}}function Yo(e,t,n,o){let r=[],s=n;for(let c of t)r=r.concat(e.slice(s,c.bs),c.toks),s=c.be;return r.concat(e.slice(s,o))}var Go=e=>e.reduce((t,n)=>t+n.len,0);function Bi(e,t,n){let o=new Int32Array(e.length+1);for(let c=0;c<e.length;c++)o[c+1]=o[c]+e[c].len;let r=t.map(c=>({bs:o[c.bs],be:o[c.be],text:c.toks.map(l=>l.raw).join(""),ref:c})),s=n.map(c=>({bs:o[c.bs],be:o[c.be],len:Go(c.toks),source:c.source,localHunks:c.localHunks||[],localLen:c.localToks?Go(c.localToks):0,keepsLocal:c.keepsLocal,ref:c}));return c=>{let l=null,a=null,b=0,p=0,g=0;for(let u of r){let h=u.bs-g;if(c<=p+h){l=g+(c-p);break}if(p+=h,g=u.bs,c<=p+u.text.length){a=u,b=c-p,l=u.bs;break}p+=u.text.length,g=u.be}l===null&&(l=g+(c-p));let m=0;for(let u of s){if(!a&&l<=u.bs)return m;if(!(a?u.localHunks.includes(a.ref):l<u.be)){m+=u.len;continue}if(u.source==="base")return m+(l-u.bs);if(u.source==="remote")return m+u.len;if(u.source==="local")return m+Math.min(b,u.len);if(!u.keepsLocal||!a)return m+u.len;let y=u.localHunks.indexOf(a.ref),S=Go(Yo(e,u.localHunks.slice(0,y),u.ref.bs,a.ref.bs));return m+Math.min(S+b,u.localLen)}return m}}function Xn(e,t,n,o="remote"){if(t===n||n===e)return{text:t,conflicts:[],mapLocalOffset:u=>Math.min(u,t.length),granularity:"word"};let r=vo(e,t,n),s=An(e,r),c=An(t,r),l=An(n,r),a=s.length<=2e4&&c.length<=2e4&&l.length<=2e4?Zr(s,c,l,o):null,b="word",p=s;if(!a){let u=h=>h.split(/(?<=\n)/).map(y=>({k:y,raw:y,len:y.length}));p=u(e),a=Zr(p,u(t),u(n),o),b="line"}let g=u=>u.map(h=>h.raw).join(""),m=[0];for(let u of p)m.push(m[m.length-1]+u.len);return{text:g(a.tokens),conflicts:a.conflicts.map(u=>({bs:m[u.bs],be:m[u.be],base:g(u.base),local:g(u.local),remote:g(u.remote),resolved:g(u.resolved)})),mapLocalOffset:a.mapLocalOffset,granularity:b}}function Zn(e,t,n=4e3){if(e===t)return[];let o=vo(e,t),r=An(e,o),s=An(t,o),c=Pn(r,s,n),l=[0];for(let a of r)l.push(l[l.length-1]+a.len);return c.hunks.map(a=>({bs:l[a.bs],be:l[a.be],text:a.toks.map(b=>b.raw).join("")}))}var Dn="\uFFFC";var _i={caret:0},sn=new Set("A ABBR B BDI BDO CITE CODE DATA DEL DFN EM FONT I INS KBD MARK Q S SAMP SMALL SPAN STRIKE STRONG SUB SUP TIME TT U VAR".split(" ")),rs=new Set(["BR","WBR","IMG"]),Ui=new Set("ADDRESS ARTICLE ASIDE AUDIO BLOCKQUOTE BODY CANVAS CAPTION CENTER COL COLGROUP DD DETAILS DIALOG DIR DIV DL DT FIELDSET FIGCAPTION FIGURE FOOTER FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HEADER HGROUP HR HTML IFRAME LEGEND LI MAIN MATH MENU NAV NOSCRIPT OBJECT OL OPTGROUP OPTION P PRE SCRIPT SECTION SELECT STYLE SUMMARY SVG TABLE TBODY TD TEMPLATE TEXTAREA TFOOT TH THEAD TITLE TR UL VIDEO".split(" "));function xn(e,t={}){if(e.nodeType===3)return!0;if(e.nodeType!==1)return!1;if(t.ignored&&t.ignored(e)||rs.has(e.tagName))return!0;if(!sn.has(e.tagName))return!Ui.has(e.tagName);if(t.remoteWins&&t.remoteWins(e))return!1;let n=t.inlineCache&&t.inlineCache.get(e);if(n!==void 0)return n;let o=!0;for(let r of e.childNodes)if(!xn(r,t)){o=!1;break}return t.inlineCache&&t.inlineCache.set(e,o),o}function Wi(e){return!e.firstChild||e.textContent===""&&!e.querySelector("br,img,wbr")}function Qn(e,t={}){let n={text:"",marks:[],atoms:[],nodes:[],stackAt:[],pins:[],placeholder:null},o=(r,s)=>{for(let c of r){if(c.nodeType===3){let p=c.nodeValue;if(!p)continue;n.nodes.push({node:c,s:n.text.length,e:n.text.length+p.length}),n.text+=p;for(let g=0;g<p.length;g++)n.stackAt.push(s);continue}if(c.nodeType!==1)continue;if(t.ignored&&t.ignored(c)){n.pins.push({el:c,i:n.text.length});continue}if(t.skip&&t.skip.has(c))continue;let l=c.tagName;if(t.blocks&&t.blocks.has(c)){n.text.length&&n.text[n.text.length-1]!==nt&&(n.stackAt.push(s),n.text+=nt);let p={el:c,tag:l,from:n.text.length,to:-1,depth:s.length,block:!0};n.marks.push(p);let g=s.concat([p]);o(c.childNodes,g),n.stackAt.push(g),n.text+=nt,p.to=n.text.length;continue}let a=sn.has(l)&&Wi(c);if(rs.has(l)||!sn.has(l)||t.remoteWins&&t.remoteWins(c)||t.atomize&&t.atomize(c)||a){n.atoms.push({i:n.text.length,el:c,key:a?l+":empty":l,stack:s}),n.stackAt.push(s),n.text+=Dn;continue}let b={el:c,tag:l,from:n.text.length,to:-1,depth:s.length};n.marks.push(b),o(c.childNodes,s.concat([b])),b.to=n.text.length}};if(o(e,[]),n.atoms.length===1&&n.atoms[0].el.tagName==="BR"&&n.marks.length===0&&Io(n).trim()===""){let r=n.atoms[0];n.placeholder=r.el,n.text=n.text.slice(0,r.i)+n.text.slice(r.i+1),n.stackAt.splice(r.i,1);for(let s of n.nodes)s.s>r.i&&(s.s--,s.e--);n.atoms=[]}return n.atomAt=new Map(n.atoms.map(r=>[r.i,r])),n}function $i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")}function Fi(e){let t="<"+e.tagName.toLowerCase();for(let n of e.attributes)t+=` ${n.name}="${n.value.replace(/"/g,""")}"`;return t+">"}function tr(e,t,n){let o="",r=[];for(let s=t;s<n;s++){let c=e.stackAt[s],l=0;for(;l<r.length&&l<c.length&&r[l]===c[l];)l++;for(;r.length>l;)o+=`</${r.pop().tag.toLowerCase()}>`;for(;r.length<c.length;){let b=c[r.length];o+=Fi(b.el),r.push(b)}let a=e.atomAt.get(s);o+=a?a.el.outerHTML:e.text[s]===nt?"":$i(e.text[s])}for(;r.length;)o+=`</${r.pop().tag.toLowerCase()}>`;return o}function Vi(e,t){let n=[...e.el.attributes].filter(o=>!t(e.el,o.name)).map(o=>o.name+"="+o.value).sort().join("");return e.tag+"|"+n}function ss(e,t){let n=[...e.attributes].filter(o=>!t(e,o.name)).map(o=>o.name+"="+o.value).sort().join("");return e.tagName+"|"+n+"|"+e.innerHTML}function Qr(e,t=()=>!1){let n=new Map,o=s=>{let c=n.get(s);return c===void 0&&(c="{"+s.map(l=>Vi(l,t)).sort().join(",")+"}",n.set(s,c)),c},r="";for(let s=0;s<e.text.length;s++){let c=e.atomAt.get(s);r+=(c?"["+ss(c.el,t)+"]":e.text[s])+o(e.stackAt[s])}return e.text.length===0&&e.placeholder&&(r+="[br]"),r}function Hn(e,t,n,o=r=>r.key){let r=[],s=e.text,c=0,l=a=>{if(a<=c)return;let b=s.slice(c,a);if(n)for(let p of b.split(/(?<=\n)/))r.push({k:p,raw:p,len:p.length});else for(let p of An(b,t))r.push(p)};for(let a of e.atoms)l(a.i),r.push({k:"\0"+o(a),raw:Dn,len:1,atom:!0}),c=a.i+1;return l(s.length),r}function Io(e){if(!e.atoms.length)return e.text;let t="",n=0;for(let o of e.atoms)t+=e.text.slice(n,o.i),n=o.i+1;return t+e.text.slice(n)}var nr=e=>{let t=new Int32Array(e.length+1);for(let n=0;n<e.length;n++)t[n+1]=t[n]+e[n].len;return t};function es(e,t,n,o){let r=nr(t),s=nr(n),c=[],l=0,a=0;for(let p of o.hunks){a+=p.bs-l;let g=a+p.toks.length;c.push({bs:r[p.bs],be:r[p.be],ss:s[a],se:s[g],text:e.text.slice(s[a],s[g]),toks:p.toks,lead:!!p.lead}),a=g,l=p.be}let b=new Map;for(let p of o.cosmetic)b.set(p.bi,p.tok.raw);return{hunks:c,respell:b}}function ts(e,t,n){let o=c=>c===nt||/\s/.test(c),r=c=>c.replace(/[\u001E\s]/g,""),s=[];for(let c of e){let l=t.slice(c.bs,c.be),a=n.slice(c.ss,c.se);if(!l.includes(nt)&&!a.includes(nt)||l.includes(Dn)||a.includes(Dn)||r(l)!==r(a)){s.push(c);continue}let b=0,p=0;for(;;){let g=b,m=p;for(;g<l.length&&o(l[g]);)g++;for(;m<a.length&&o(a[m]);)m++;let u=b,h=p;for(;u<g&&h<m&&l[u]===a[h];)u++,h++;let y=g,S=m;for(;y>u&&S>h&&l[y-1]===a[S-1];)y--,S--;if(y>u||S>h){let v=a.slice(h,S);s.push({bs:c.bs+u,be:c.bs+y,ss:c.ss+h,se:c.ss+S,text:v,toks:[...v].map(D=>({k:D,raw:D,len:1})),lead:c.lead})}if(g>=l.length)break;b=g+1,p=m+1}}return s}function ns(e,t,n){let o=new Int32Array(t+1).fill(-1),r=new Int32Array(n+1).fill(-1),s=0,c=0,l=a=>{for(;s<a;)o[s]=c,r[c]=s,s++,c++};for(let a of e)l(a.bs),s=a.be,c=a.se;return l(t),o[t]=c,r[c]=t,{bTo:o,toB:r}}function os(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function or(e){let{out:t,policy:n="remote",L:o,R:r}=e,s=e.provenance||new WeakMap,c=e.textMappers||new WeakMap,l=e.conflicts||[],a=e.decisions||[],b=l.length,p=!!(o&&o.reverse&&o.map&&r&&r.reverse&&r.map),g={base:null,local:null,remote:null};if(p&&e.moveIn){let i=X=>be=>X.some(G=>G===be||G.nodeType===1&&G.contains(be)),d=i(e.local),w=i(e.remote),k=i(e.base),N=new Set,L=X=>{if(!sn.has(X.tagName))return;let be=o.map.get(X),G=r.map.get(X);(be&&!d(be)||G&&!w(G))&&N.add(X);for(let oe of X.children)L(oe)};for(let X of e.base)X.nodeType===1&&L(X);let $=X=>be=>{if(!sn.has(be.tagName))return!1;let G=X.reverse.get(be);return!!G&&(N.has(G)||!k(G))};N.size&&(g.base=X=>N.has(X)),g.local=$(o),g.remote=$(r)}let m={base:new Set,local:new Set,remote:new Set};if(p&&e.moveIn){let i=k=>N=>k.some(L=>L===N||L.nodeType===1&&L.contains(N)),d=i(e.local),w=i(e.remote);for(let k of Qn(e.base,{...e,atomize:g.base}).atoms){let N=o.map.get(k.el),L=r.map.get(k.el),$=!!N&&!d(N),X=!!L&&!w(L);!$&&!X||(m.base.add(k.el),N&&!$&&m.local.add(N),L&&!X&&m.remote.add(L),d(k.el)&&m.local.add(k.el),w(k.el)&&m.remote.add(k.el))}}let u=Qn(e.base,{...e,atomize:g.base,skip:m.base}),h=Qn(e.local,{...e,atomize:g.local,skip:m.local}),y=Qn(e.remote,{...e,atomize:g.remote,skip:m.remote}),S=new Map(u.atoms.map(i=>[i.el,i])),v=(i,d,w)=>{d.namespaceURI?i.setAttributeNS(d.namespaceURI,d.name,w):i.setAttribute(d.name,w)},D=(i,d,w,k)=>{if(!d&&(!w||!k)){for(let L of(w||k).attributes)v(i,L,L.value);return}let N=new Map;for(let L of[d,w,k])if(L)for(let $ of L.attributes)N.set($.name,$);for(let[L,$]of N){let X=d?d.getAttribute(L):null,be=w?w.getAttribute(L):X,G=k?k.getAttribute(L):X,oe;be===G?oe=be:be===X?(oe=G,a.push({kind:"attr",el:i,name:L,source:"remote"})):G===X?(oe=be,a.push({kind:"attr",el:i,name:L,source:"local"})):(oe=n==="local"?be:G,l.push({kind:"attr",el:i,name:L,base:X,local:be,remote:G,resolved:oe}),a.push({kind:"attr",el:i,name:L,source:"both"})),oe!=null&&v(i,$,oe)}},q=(i,d,w,k)=>i&&e.mergeAttrs?e.mergeAttrs(i,d,w,k):D(k,i,d,w),Z=e.mergeElement||((i,d,w)=>{let k=t.createElement(i.tagName);q(i,d,w,k);let N=d||i,L=w||i,$=n==="local"?N.isEqualNode(i)?L:N:L.isEqualNode(i)?N:L;for(let X of $.childNodes)k.appendChild(t.importNode(X,!0));return s.set(k,{base:i,local:d,remote:w}),k}),ae=e.cloneUnit||((i,d)=>{let w=t.importNode(i,!0);return s.set(w,{base:null,local:d==="local"?i:null,remote:d==="remote"?i:null}),w}),ie=e.atomKey||(i=>ss(i,()=>!1)),he=(i,d)=>{let w=new Map;for(let k of i.atoms)if(e.remoteWins&&e.remoteWins(k.el)&&sn.has(k.el.tagName))w.set(k,"w"+k.el.tagName+"#"+(k.el.id||""));else if(!p)w.set(k,k.key);else if(i===u)w.set(k,"="+ie(k.el));else{let N=d.reverse.get(k.el),L=N?S.get(N):null;L?w.set(k,"="+ie(L.el)):N?w.set(k,"m"+ie(k.el)):w.set(k,"="+ie(k.el))}return k=>w.get(k)},K=he(u,null),J=he(h,o),ye=he(y,r),je=vo(Io(u),Io(h),Io(y)),Fe=Hn(u,je,!1,K),ot=Hn(h,je,!1,J),ct=Hn(y,je,!1,ye),Ct=Fe.length>2e4||ot.length>2e4||ct.length>2e4;Ct&&(Fe=Hn(u,je,!0,K),ot=Hn(h,je,!0,J),ct=Hn(y,je,!0,ye));let vt=Zo(Pn(Fe,ot),Pn(Fe,ct),Fe),Oe=es(h,Fe,ot,{hunks:vt.lh,cosmetic:vt.cosL}),dt=es(y,Fe,ct,{hunks:vt.rh,cosmetic:vt.cosR});Oe.hunks=ts(Oe.hunks,u.text,h.text),dt.hunks=ts(dt.hunks,u.text,y.text);let Qe=ns(Oe.hunks,u.text.length,h.text.length),Lt=ns(dt.hunks,u.text.length,y.text.length),rt=u.text.length,et=i=>new Map(i.atoms.map(d=>[d.el,d])),lt=et(h),O=et(y),F=(i,d,w)=>{let k=new Set;if(!p)return k;for(let N of i.atoms){let L=S.get(d.reverse.get(N.el));L&&w.bTo[L.i]<0&&k.add(L)}return k},ke=F(h,o,Qe),re=F(y,r,Lt),Ne=i=>!xn(i,{...e,remoteWins:null}),tt=new Set;if(p)for(let i of u.atoms){if(!Ne(i.el))continue;let d=o.map.get(i.el)||null,w=r.map.get(i.el)||null,k=d&&!w?d:w&&!d?w:null;k&&(lt.has(k)||O.has(k))&&!k.isEqualNode(i.el)&&tt.add(i)}let qe=1,Ke=(i,d)=>({id:qe++,tag:i,base:null,local:null,remote:null,rank:d}),Ze=new Map,at=[];for(let i of u.marks){let d=Ke(i.tag,i.depth);d.block=!!i.block,d.base=i.el,d.baseMark=i,Ze.set(i.el,d),at.push(d)}let f=(i,d)=>{let w=-1,k=-1;for(let N=i.from;N<i.to;N++){let L=d[N];L>=0&&(w<0&&(w=L),k=L+1)}return w<0?null:[w,k]},T=(i,d,w,k)=>{for(let N of i.marks){let L=w?w.reverse.get(N.el):null;L&&w.identical.has(L)&&w.pairIdenticalChildren&&w.pairIdenticalChildren(L);let $=L?Ze.get(L):null;if($&&$[d]&&($=null),!$){let X=f(N,k),be=0;if(X)for(let G of at){if(G.tag!==N.tag||G[d]||!!G.block!=!!N.block)continue;let oe=Math.min(X[1],G.baseMark.to)-Math.max(X[0],G.baseMark.from);(oe>be||oe===be&&oe>0&&Math.abs(G.rank-N.depth)<Math.abs($.rank-N.depth))&&($=G,be=oe)}}$||($=Ke(N.tag,N.depth),$.block=!!N.block,$.new=d),$[d]=N.el,$[d+"Mark"]=N,Ze.set(N.el,$)}};T(h,"local",o,Qe.toB),T(y,"remote",r,Lt.toB);let x=i=>i.merged||i,B=i=>{let d=new Set;for(let w of i)w.block||d.add(Ze.get(w.el));return d},I=new Map,E=i=>{let d=I.get(i);return d||(d=B(i),I.set(i,d)),d},j=(i,d)=>{let w=[],k=null;for(let N=0;N<rt;N++){let L=d[N];if(L<0){k&&w.push(k),k=null;continue}let $=E(u.stackAt[N]),X=E(i.stackAt[L]),be=new Set,G=new Set;for(let oe of X)$.has(oe)||be.add(oe);for(let oe of $)X.has(oe)||G.add(oe);if(!be.size&&!G.size){k&&w.push(k),k=null;continue}if(k&&os(k.added,be)&&os(k.removed,G)){k.be=N+1;continue}k&&w.push(k),k={bs:N,be:N+1,added:be,removed:G}}return k&&w.push(k),w},M=j(h,Qe.bTo),P=j(y,Lt.bTo),Y=i=>i.be>i.bs?[i.bs,i.be-1]:[i.bs-1,i.bs],Q=(i,d)=>{if(rt===0)return null;let[w,k]=Y(i);for(let N of d){if(N.be<=w)continue;if(N.bs>k)break;let L=N.bs<=w&&k<N.be;return L&&i.text===""&&N.bs===i.bs&&N.be===i.be?"straddle":L?N:i.be>i.bs?"straddle":null}return null},we=i=>i.bs===i.be,Ye=(i,d)=>{let w=!1;for(let k=i.bs;k<i.be;k++){let N=u.text[k];if(N===nt)w=!0;else if(!/\s/.test(N))return!1}for(let k=i.ss;k<i.se;k++){let N=d.text[k];if(N===nt)w=!0;else if(!/\s/.test(N))return!1}return w},bt=(i,d)=>i.bs<d.be&&d.bs<i.be,ft=(i,d)=>i.bs<=d.be&&d.bs<=i.be&&we(i)!==we(d),le=(i,d)=>u.text.slice(i.bs,i.be).includes(nt)||d.text.slice(i.ss,i.se).includes(nt),Ge=i=>{if(we(i))return!1;let d=i.bs,w=i.be;for(;d>0&&/\s/.test(u.text[d-1]);)d--;for(;w<u.text.length&&/\s/.test(u.text[w]);)w++;return(d===0||u.text[d-1]===nt)&&(w===u.text.length||u.text[w]===nt)},Rt=(i,d)=>!le(i,d)&&!Ge(i),yt=(i,d)=>bt(i,d)||ft(i,d)&&!(Ye(i,h)&&Rt(d,y))&&!(Ye(d,y)&&Rt(i,h)),Dt=(i,d)=>{if(i.bs!==d.bs||i.be!==d.be||i.toks.length!==d.toks.length)return!1;let w=i.ss,k=d.ss;for(let N=0;N<i.toks.length;N++){let L=i.toks[N],$=d.toks[N];if(L.k!==$.k||L.atom&&!h.atomAt.get(w).el.isEqualNode(y.atomAt.get(k).el))return!1;w+=L.len,k+=$.len}return!0},Ut=(i,d,w,k)=>{for(let N of u.atoms){if(N.i<i.bs||N.i>=i.be||k.has(N)||tt.has(N))continue;let L=d.bTo[N.i],$=L>=0?w.atomAt.get(L):null;if($&&!$.el.isEqualNode(N.el))return!0}return!1},At=[],xt=Oe.hunks,A=dt.hunks,C=0,R=0,U=0,H=0,_=0,z=i=>{i>U&&(At.push({src:"base",from:U,to:i,dL:H,dR:_}),U=i)};for(;C<xt.length||R<A.length;){let i=xt[C],d=A[R],w=!!i&&(!d||i.bs<d.bs||i.bs===d.bs&&i.be<=d.be&&!d.lead);if(i&&d&&i.bs===d.bs&&we(i)&&we(d)){let Nt=Ye(i,h),kn=Ye(d,y);Nt!==kn&&(w=kn)}let k=w?i:d,N=w?d:i,L=!!N&&Dt(i,d),$=!!N&&(w?!!xt[C+1]&&Dt(xt[C+1],d):!!A[R+1]&&Dt(i,A[R+1])),X=!!N&&!L&&!$&&(rt===0||yt(i,d)),be=X,G=Q(k,w?P:M);if(G==="straddle"&&(be=!0),!be&&k.be>k.bs&&(be=Ut(k,w?Lt:Qe,w?y:h,w?ke:re)),!be&&L){z(k.bs),At.push({src:"both",lfrom:i.ss,rfrom:d.ss,len:k.text.length}),U=k.be,H+=k.text.length-(k.be-k.bs),_+=k.text.length-(k.be-k.bs),C++,R++;continue}if(!be){z(k.bs),At.push({src:w?"local":"remote",from:k.ss,to:k.se,inherit:G&&G!=="straddle"?G:null}),U=k.be,w?(H+=k.text.length-(k.be-k.bs),C++):(_+=k.text.length-(k.be-k.bs),R++);continue}let oe=k.bs,Be=k.be,Ie=C,De=R,mt=Nt=>Nt.bs<Be&&Nt.be>oe||we(Nt)&&(Nt.bs===oe||Nt.bs===Be);w?Ie++:De++,X&&(oe=Math.min(oe,N.bs),Be=Math.max(Be,N.be),w?De++:Ie++);let it=!0;for(;it;){for(it=!1;Ie<xt.length&&mt(xt[Ie]);)oe=Math.min(oe,xt[Ie].bs),Be=Math.max(Be,xt[Ie].be),Ie++,it=!0;for(;De<A.length&&mt(A[De]);)oe=Math.min(oe,A[De].bs),Be=Math.max(Be,A[De].be),De++,it=!0}let Ft=oe+H,Ht=oe+_,Xt=Be-oe,nn=Be-oe;for(let Nt=C;Nt<Ie;Nt++)Xt+=xt[Nt].text.length-(xt[Nt].be-xt[Nt].bs);for(let Nt=R;Nt<De;Nt++)nn+=A[Nt].text.length-(A[Nt].be-A[Nt].bs);let fn=Ft+Xt,un=Ht+nn;z(oe);let St={kind:"text",node:e.node||null,base:tr(u,oe,Be),local:tr(h,Ft,fn),remote:tr(y,Ht,un),resolved:null,range:null,bs:oe,be:Be,lss:Ft,lse:fn,rss:Ht,rse:un};St.resolved=n==="local"?St.local:n==="remote"?St.remote:St.local+St.remote,n!=="remote"&&At.push({src:"local",from:Ft,to:fn,conflict:St}),n!=="local"&&At.push({src:"remote",from:Ht,to:un,conflict:St}),l.push(St),U=Be,H+=Xt-(Be-oe),_+=nn-(Be-oe),C=Ie,R=De}z(rt);let ne=u.text,pe=[];if(Oe.respell.size||dt.respell.size){let i=nr(Fe),d=[];for(let w=0;w<Fe.length;w++){let k=Fe[w].raw,N=Oe.respell.get(w)??k,L=dt.respell.get(w)??k;(N!==k||L!==k)&&pe.push([i[w],N!==k&&L!==k?"both":N!==k?"local":"remote"]),d.push(N===L?N:N===k?L:L===k||n==="local"?N:L)}ne=d.join("")}let fe="",me=[],Pe=[],Le=[],kt=[];for(let i of At){let d=fe.length;if(i.src==="base"){for(let w=i.from;w<i.to;w++)me.push(w),Pe.push(w+i.dL),Le.push(w+i.dR),kt.push(i);fe+=ne.slice(i.from,i.to)}else if(i.src==="both"){for(let w=0;w<i.len;w++)me.push(-1),Pe.push(i.lfrom+w),Le.push(i.rfrom+w),kt.push(i);fe+=h.text.slice(i.lfrom,i.lfrom+i.len)}else{let w=i.src==="local"?h:y;for(let k=i.from;k<i.to;k++)me.push(-1),Pe.push(i.src==="local"?k:-1),Le.push(i.src==="remote"?k:-1),kt.push(i);fe+=w.text.slice(i.from,i.to)}i.ms=d,i.me=fe.length,i.conflict&&(i.conflict.range||(i.conflict.range=[d,d]),i.conflict.range[1]=fe.length)}let ue=fe.length,Ve=new Int32Array(rt+1).fill(-1),Te=new Int32Array(h.text.length+1).fill(-1),It=new Int32Array(y.text.length+1).fill(-1);for(let i=0;i<ue;i++)me[i]>=0&&(Ve[me[i]]=i),Pe[i]>=0&&(Te[Pe[i]]=i),Le[i]>=0&&(It[Le[i]]=i);let wt=(i,d)=>{let w=-1,k=-1;for(let N=i.from;N<i.to;N++){let L=d[N];L>=0&&(w<0&&(w=L),k=L+1)}return w<0?null:[w,k]},Ot=[],ht=[];for(let i of new Set(Ze.values()))i.new==="local"?Ot.push(i):i.new==="remote"&&ht.push(i);let zn=(i,d)=>{i.remote=d.remote,i.remoteMark=d.remoteMark,i.new="both",d.merged=i,Ze.set(d.remote,i)};if(Ot.length&&ht.length){let i=e.idOf;for(let d of Ot){let w=i?i.local(d.local):null;if(!w)continue;let k=ht.find(N=>!N.merged&&N.tag===d.tag&&!!N.block==!!d.block&&i.remote(N.remote)===w);k&&zn(d,k)}for(let d of Ot){if(d.remote)continue;let w=wt(d.localMark,Te);if(w)for(let k of ht){if(k.merged||k.tag!==d.tag||!!k.block!=!!d.block)continue;let N=wt(k.remoteMark,It);if(N&&Math.min(w[1],N[1])-Math.max(w[0],N[0])>0){zn(d,k);break}}}}I.clear();let qn=i=>{for(let d of i)if(d.block)return x(Ze.get(d.el));return null},rn=u.marks.some(i=>i.block)||h.marks.some(i=>i.block)||y.marks.some(i=>i.block),Gt=new Array(ue).fill(null),vn=new Set;if(rn){let i=(G,oe,Be)=>{let Ie=new Set([G,oe,Be]);Ie.delete(null);let De=[];for(let it of Ie){let Ft=it===G,Ht=it===oe,Xt=it===Be;(Ht===Xt?Ht:Ht===Ft?Xt:Ht)&&De.push(it)}if(De.length<=1)return De[0]||null;let mt=n==="local"?oe:Be;return De.includes(mt)?mt:De[0]},d=(G,oe)=>oe>=0?qn(G.stackAt[oe]):null,w=new Map;for(let G=0;G<ue;G++){if(fe[G]!==nt)continue;let oe=me[G]>=0?d(u,me[G]):null,Be=d(h,Pe[G]),Ie=d(y,Le[G]);w.set(G,[oe,me[G]>=0?i(oe,Be,Ie):Be||Ie])}let k=new Set([...w.values()].map(G=>G[1])),N=G=>G!==nt&&G!==Dn&&!/\s/.test(G),L=(G,oe)=>{let Be=G;for(;Be<oe&&!N(fe[Be]);)Be++;return Be<oe&&me[Be]>=0?d(u,me[Be]):null},$=new Map,X=0;for(let G=0;G<ue;G++){if(fe[G]!==nt)continue;let[oe,Be]=w.get(G),Ie=L(X,G),De=Be,mt=$.get(De)===De&&Ie===De;De&&$.has(De)&&!mt&&oe&&!$.has(oe)&&!k.has(oe)&&(De=oe),De&&!$.has(De)&&$.set(De,Ie);for(let it=X;it<=G;it++)Gt[it]=De;X=G+1}let be=G=>{for(let oe=0;oe<G.text.length;oe++)if(N(G.text[oe])&&!d(G,oe))return!0;return!1};if(!be(u)&&!be(h)&&!be(y)){let G=[],oe=0;for(let Ie=0;Ie<ue;Ie++)(fe[Ie]===nt||Ie===ue-1)&&(G.push([oe,Ie]),oe=Ie+1);let Be=new Set(Gt);for(let Ie=0;Ie<G.length;Ie++){let[De,mt]=G[Ie];if(Gt[mt])continue;let it=De;for(;it<=mt&&!N(fe[it]);)it++;if(it>mt)continue;let Ft=d(u,me[it]),Ht=d(h,Pe[it]),Xt=d(y,Le[it]),nn=i(Ft,Ht,Xt)||Ht||Xt||Ft;if(nn&&!Be.has(nn)){Be.add(nn);for(let St=De;St<=mt;St++)Gt[St]=nn;continue}let fn=Ie>0&&Gt[G[Ie-1][1]],un=Ie+1<G.length&&Gt[G[Ie+1][1]];if(fn)vn.add(G[Ie-1][1]);else if(un&&fe[mt]===nt)vn.add(mt);else continue;for(let St=De;St<=mt;St++)Gt[St]=fn||un}}}let bo=new Map,yo=i=>{let d=bo.get(i);if(d)return d;d=[1/0,-1/0];for(let[w,k]of[[i.baseMark,Ve],[i.localMark,Te],[i.remoteMark,It]]){let N=w&&wt(w,k);N&&(d[0]=Math.min(d[0],N[0]),d[1]=Math.max(d[1],N[1]))}return bo.set(i,d),d},ko=(i,d,w)=>{let k=-1,N=-1;for(let L=0;L<i.length;L++){let $=Ze.get(i[L].el);$===d&&(k=L),$===w&&(N=L)}return k>=0&&N>=0?k-N:0},In=(i,d)=>[...i].sort((w,k)=>{for(let $ of d){let X=ko($,w,k);if(X)return X}let N=yo(w),L=yo(k);return N[0]-L[0]||L[1]-N[1]||w.rank-k.rank||w.id-k.id}),wo=new Map,W=new Map,xe=i=>{let d=me[i],w=Pe[i],k=Le[i],N=kt[i];if(d>=0){let Ie=u.stackAt[d],De=h.stackAt[w],mt=y.stackAt[k],it=wo.get(Ie);it||wo.set(Ie,it=new Map);let Ft=it.get(De);Ft||it.set(De,Ft=new Map);let Ht=Ft.get(mt);if(Ht)return Ht;let Xt=E(Ie),nn=E(De),fn=E(mt),un=new Set;for(let St of new Set([...Xt,...nn,...fn])){let Nt=Xt.has(St),kn=nn.has(St),Br=fn.has(St);(kn===Br?kn:kn===Nt?Br:kn)&&un.add(St)}return Ht=In(un,[De,mt,Ie]),Ft.set(mt,Ht),Ht}if(N.src==="both"){let Ie=h.stackAt[w],De=y.stackAt[k];return In(new Set([...E(Ie),...E(De)]),[Ie,De])}let $=(N.src==="local"?h:y).stackAt[N.src==="local"?w:k];if(!N.inherit)return In(E($),[$]);let X=W.get(N);X||W.set(N,X=new Map);let be=X.get($);if(be)return be;let G=new Set(E($));for(let Ie of N.inherit.added)G.add(x(Ie));for(let Ie of N.inherit.removed)G.delete(x(Ie));let oe=N.src==="local"?y:h,Be=(N.src==="local"?Lt.bTo:Qe.bTo)[N.inherit.bs];return be=In(G,[$,oe.stackAt[Be]]),X.set($,be),be},de=new Int32Array(h.text.length+1);de[h.text.length]=ue;for(let i=h.text.length-1;i>=0;i--)de[i]=Te[i]>=0?Te[i]:de[i+1];_i.caret+=h.text.length;let Me=i=>i<=0?0:(i>h.text.length&&(i=h.text.length),Te[i-1]>=0?Te[i-1]+1:de[i]),_e=[],te=[],Ae=null,ee=[],ve="",He=-1,Et=i=>{Ae?Ae.appendChild(i):_e.push(i)},Jt=i=>{if(!ve)return;let d=t.createTextNode(ve);Et(d),te.push({node:d,ms:He,me:i,local:[],u:ee.length?ee[ee.length-1].u:null}),ve=""},an=new Set,Bt=new Map,hn=new Set,Re=i=>{let d=t.createElement(i.tag);if(i.block&&Gn.add(d),!Bt.has(i)){Bt.set(i,d),q(i.base,i.local,i.remote,d),s.set(d,{base:i.base,local:i.local,remote:i.remote});let k=($,X)=>p&&i[X]&&$.reverse.get(i[X])?X:null,N=!i.base&&(k(o,"local")||k(r,"remote"));if(N){let $=N==="local"?o.reverse.get(i.local):r.reverse.get(i.remote),X=s.get(d);X.local=X.local||o.map.get($)||null,X.remote=X.remote||r.map.get($)||null,a.push({kind:"move",el:d,source:N})}else i.base||a.push({kind:"insert",el:d,source:i.local&&i.remote?"both":i.local?"local":"remote"});let L=s.get(d);L.local&&(hn.has(L.local)?L.local=null:hn.add(L.local))}else{let k=Bt.get(i);for(let N of k.attributes)N.name!=="id"&&N.name!=="data-id"&&v(d,N,N.value);s.set(d,{base:null,local:null,remote:null})}Et(d),ee.push({u:i,el:d}),Ae=d},Ue=new Set,V=new Map;for(let i of h.pins){let d=Me(i.i);V.has(d)||V.set(d,[]),V.get(d).push(i)}let ce=i=>{let d=V.get(i);if(d){Jt(i);for(let w of d){let k=w.el.namespaceURI&&w.el.namespaceURI!=="http://www.w3.org/1999/xhtml"?t.createElementNS(w.el.namespaceURI,w.el.tagName):t.createElement(w.el.tagName);s.set(k,{base:null,local:w.el,remote:null,pinned:!0}),Ue.add(k),Et(k)}}},ge=u.atoms.length||h.atoms.length||y.atoms.length,Ce=i=>{if(!ge)return null;let d=me[i]>=0?u.atomAt.get(me[i]):null,w=Pe[i]>=0?h.atomAt.get(Pe[i]):null,k=Le[i]>=0?y.atomAt.get(Le[i]):null;return d||w||k?{ab:d,al:w,ar:k}:null},Se=(i,d,w,k)=>{if(!i||!p)return null;let N=S.get(d.reverse.get(i.el))||null;return!N||N===k||(k?N.el.isEqualNode(k.el):w.bTo[N.i]>=0)?null:N},$e=(i,d)=>{if(!i||!p||!e.moveIn)return null;let w=d.reverse.get(i.el);return w&&!S.has(w)?w:null},Xe=(i,d)=>{let w=new Map;for(let k of i.atoms)w.set(d(k),(w.get(d(k))||0)+1);return w},Pt=Xe(u,K),_t=Xe(h,J),Vt=Xe(y,ye),Tt=i=>{let d=K(i);return Pt.get(d)===1&&(_t.get(d)||0)<=1&&(Vt.get(d)||0)<=1},zt=new Map,ut=new Set,pt=new Set,qt=new Set;for(let i=0;i<ue;i++){let d=Ce(i);if(!d)continue;let{ab:w,al:k,ar:N}=d,L=Se(N,r,Lt,w),$=Se(k,o,Qe,w),X=w,be=null;if(L?(X=L,be="remote"):$&&(X=$,be="local"),X){ut.has(X)?zt.set(i,{dup:X.el}):(ut.add(X),zt.set(i,{bk:X,from:be,al:k,ar:N}));continue}let G=$e(N,r),oe=$e(k,o),Be=G||oe;if(Be){pt.has(Be)?zt.set(i,{dup:Be}):(pt.add(Be),zt.set(i,{moveIn:Be,side:G?"remote":"local",sideEl:G?N.el:k.el}));continue}let Ie=(mt,it)=>mt&&p&&S.get(it.reverse.get(mt.el))||null,De=Ie(N,r)||Ie(k,o);if(De&&(qt.add(De),kt[i].conflict&&Tt(De))){if(ut.has(De)){zt.set(i,{dup:De.el});continue}ut.add(De)}zt.set(i,{al:k,ar:N})}let en=new Map,Ao=(i,d)=>{if(i[d]>=0)return i[d];for(let w=d-1;w>=0;w--)if(i[w]>=0)return i[w]+1;return 0};if(p)for(let i of u.atoms){if(ut.has(i)||qt.has(i))continue;let d=o.map.get(i.el)||null,w=r.map.get(i.el)||null,k=d&<.get(d),N=w&&O.get(w);if(d&&!k||w&&!N)continue;let L=!(k&&N)&&tt.has(i);if(!L&&!(k&&N&&Tt(i)))continue;let $=n==="local"?[[k,Te],[N,It]]:[[N,It],[k,Te]],[X,be]=$.find(([oe])=>oe),G=Ao(be,X.i);en.has(G)||en.set(G,[]),en.get(G).push({a:i,lt:d,rt:w,edited:L}),ut.add(i)}if(p&&e.moveIn){let i=[[h,o,Te,"local"],[y,r,It,"remote"]];n!=="local"&&i.reverse();for(let[d,w,k,N]of i)for(let L of d.atoms){let $=$e(L,w);if(!$||pt.has($))continue;pt.add($);let X=Ao(k,L.i);en.has(X)||en.set(X,[]),en.get(X).push({move:$,side:N,sideEl:L.el})}}let Kn=i=>{let d=en.get(i);if(d){if(Jt(i),d.some(w=>Ne(w.move?w.sideEl:w.a.el)))for(;ee.length;)ee.pop(),Ae=ee.length?ee[ee.length-1].el:null;for(let{a:w,lt:k,rt:N,edited:L,move:$,side:X,sideEl:be}of d){if($){let oe=e.moveIn($,X,be);oe&&Et(oe);continue}an.add(w);let G=Z(w.el,k,N);L&&(l.push({kind:"structure",el:G,detail:"edit-beats-delete",base:w.el}),a.push({kind:"insert",el:G,source:k?"local":"remote"})),Et(G)}}},Gn=new Set;for(let i=0;i<ue;i++){let d=Ce(i),k=!!d&&Ne((d.ab||d.al||d.ar).el)?[]:Gt[i]?[Gt[i],...xe(i)]:xe(i),N=0;for(;N<ee.length&&N<k.length&&ee[N].u===k[N];)N++;if(N<ee.length)for(Jt(i);ee.length>N;)ee.pop(),Ae=ee.length?ee[ee.length-1].el:null;if(ce(i),Kn(i),k.length>ee.length)for(Jt(i);ee.length<k.length;)Re(k[ee.length]);if(fe[i]===nt){if(vn.has(i))continue;Jt(i);let L=ee.length;for(;L>0&&!ee[L-1].u.block;)L--;if(L>0)for(;ee.length>=L;)ee.pop(),Ae=ee.length?ee[ee.length-1].el:null;continue}if(d){Jt(i);let L=zt.get(i),$;if(L.dup){l.push({kind:"structure",el:null,detail:"both-moved",base:L.dup});continue}if(L.moveIn){if($=e.moveIn(L.moveIn,L.side,L.sideEl),!$)continue}else if(L.bk){let X=L.bk;if(an.add(X),X===d.ab)$=Z(X.el,L.al.el,L.ar.el);else{let be=o.map.get(X.el)||null,G=r.map.get(X.el)||null;$=Z(X.el,be,G),(!be||!G)&&l.push({kind:"structure",el:null,detail:"move-beats-delete",base:X.el}),a.push({kind:"move",el:$,source:L.from})}}else L.al?($=ae(L.al.el,"local"),L.ar&&(s.get($).remote=L.ar.el),a.push({kind:"insert",el:$,source:L.ar?"both":"local"})):($=ae(L.ar.el,"remote"),a.push({kind:"insert",el:$,source:"remote"}));Et($);continue}ve||(He=i),ve+=fe[i]}if(Jt(ue),(V.has(ue)||en.has(ue))&&(ee.length=0,Ae=null,ce(ue),Kn(ue)),ue===0&&(h.placeholder||y.placeholder||u.placeholder)){let i=t.createElement("br");s.set(i,{base:u.placeholder,local:h.placeholder,remote:y.placeholder}),_e.push(i)}let se=0,We=i=>{for(;se>0&&te[se-1].me>=i;)se--;for(;se<te.length&&te[se].me<i;)se++;let d=te[se];if(!d)return te[te.length-1]||null;let w=te[se+1];return d.me===i&&w&&w.ms===i?w:d},st=new Map,Je={},ze=(i,d,w)=>{let k=We(i)||(w?Je:null);if(!k)return;let N=st.get(k)||{l:!1,r:!1};d!=="remote"&&(N.l=!0),d!=="local"&&(N.r=!0),st.set(k,N)},tn=i=>{if(i.conflict)return!0;let d=i.src==="local"?h.text:i.src==="remote"?y.text:"";for(let w=i.from;w<i.to;w++)if(d[w]!==Dn&&d[w]!==nt)return!0;return!1};for(let i of At)i.src!=="base"&&ze(i.ms,i.conflict?"both":i.src,tn(i));for(let[i,d]of pe)Ve[i]>=0&&ze(Ve[i],d);for(let i of te.length?te:[Je]){let d=st.get(i);d&&a.push({kind:"text",node:i.node||null,source:d.l&&d.r?"both":d.l?"local":"remote"})}for(let i of at){if(Bt.has(i))continue;let d=!i.local&&!(p&&o.map.get(i.base)),w=!i.remote&&!(p&&r.map.get(i.base));!d&&!w||a.push({kind:"remove",source:d&&w?"both":d?"local":"remote",base:i.base})}let Yt=(i,d,w)=>{if(d<=i)return!1;for(let k=i;k<d;k++)if(w[k]>=0)return!1;return!0};for(let i of at)for(let d of["local","remote"]){let w=i[d+"Mark"],k=i.baseMark;if(!w)continue;let N=d==="local"?Qe:Lt;if(!Yt(k.from,k.to,N.bTo)||!Yt(w.from,w.to,N.toB))continue;let L=(d==="local"?xt:A).find($=>$.ss<=w.from&&w.from<$.se);L&&(L.be<=k.from||L.bs>=k.to)&&a.push({kind:"move",el:Bt.get(i)||null,source:d})}let pn=i=>{let d=Ze.get(i.node.parentNode);return d?x(d):null};for(let i of h.nodes){let d=-1;for(let k=i.s;k<i.e;k++)if(Te[k]>=0){d=Te[k];break}let w;if(d>=0)w=We(d);else{let k=Me(i.s),N=pn(i);w=te.find(L=>L.u===N&&L.me>=k)||te.filter(L=>L.u===N).pop()}w&&w.local.push(i)}let Kt=new Map,jt=te[te.length-1]||null,$t=0;for(let i of h.nodes){let d=null;for(let w=i.s;w<=i.e;w++){let k=Me(w);for(;$t>0&&te[$t-1].me>=k;)$t--;for(;$t<te.length&&te[$t].me<k;)$t++;let N=$=>$&&k>=$.ms&&k<=$.me&&(k<$.me||w===i.e||$===d),L=N(te[$t])?te[$t]:N(te[$t+1])?te[$t+1]:te[$t]||jt;if(!L)break;if(d===L){let $=Kt.get(L);$[$.length-1].to=w-i.s;continue}d=L,Kt.has(L)||Kt.set(L,[]),Kt.get(L).push({node:i.node,from:w-i.s,to:w-i.s,flatStart:i.s})}}for(let i of te){let d=i.local,w=!1;for(let $ of d)for(let X=$.s;X<$.e&&!w;X++)(Te[X]<i.ms||Te[X]>=i.me)&&(w=!0);s.set(i.node,{base:null,local:d.map($=>$.node),remote:null,caret:Kt.get(i)||[],partial:w});let k=i.ms,N=i.me-i.ms,L=$=>{let X=0,be=-1;for(let G of d){let oe=G.e-G.s;if($<=X+oe){be=G.s+($-X);break}X+=oe}return be<0&&(be=d.length?d[d.length-1].e:0),Math.max(0,Math.min(Me(be)-k,N))};L.flat=$=>Math.max(0,Math.min(Me($)-k,N)),c.set(i.node,L)}function Gs(){if(!h.text.includes(nt))return[{flatLocal:h.text,localNodes:h.nodes,textNodes:te,lToM:Te,mapLocal:Me}];let i=[],d=0,w=0;for(let k=0;k<=h.text.length;k++){if(k<h.text.length&&h.text[k]!==nt)continue;let N=d,L=k;if(L>N){let $=[];for(;w<h.nodes.length&&h.nodes[w].e<=N;)w++;for(let X=w;X<h.nodes.length&&h.nodes[X].s<L;X++){let be=h.nodes[X],G=Math.max(be.s,N),oe=Math.min(be.e,L);G<oe&&$.push({node:be.node,s:G-N,e:oe-N})}i.push({flatLocal:h.text.slice(N,L),localNodes:$,textNodes:te,lToM:Te.subarray?Te.subarray(N,L+1):Te.slice(N,L+1),mapLocal:X=>Me(N+Math.max(0,Math.min(X,L-N)))})}d=k+1}return i}let Js={...e,blocks:Gn,ignored:i=>Ue.has(i)||(e.ignored?e.ignored(i):!1)},jr=e.ignoreAttribute||(()=>!1),Ys=Qr(Qn(_e,Js),jr)!==Qr(y,jr);return{nodes:_e,text:fe,textNodes:te,localDiverged:Ys,mapLocal:Me,conflicts:l.slice(b),granularity:Ct?"line":"word",segments:Gs(),localHunks:xt,remoteHunks:A,lToM:Te}}var zi="http://www.w3.org/1999/xhtml";function qi(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Wt(e){return!!e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.namespaceURI===zi}function Ki(e){let t=(e.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Eo(e,t){let n=e.getAttribute("src"),o=(e.getAttribute("type")||"text/javascript").split(";")[0].trim().toLowerCase();if(n){let r=n;try{let s=new URL(n,t);r=s.origin+s.pathname+s.search}catch{}return"script|src|"+o+"|"+r}return"script|inline|"+o+"|"+qi(e.textContent.trim())}var Gi={match:e=>e.hasAttribute("merge"),identity:e=>e.getAttribute("merge")};function jn(e,t=[],n=!1){if(!Wt(e)||e.hasAttribute("src"))return null;let o=[Gi,...t];for(let r=0;r<o.length;r++){let s=o[r];if(!s.match(e))continue;if(!Ki(e))return n&&console.warn("[hyper-morph] merge ignored: script type is not JSON",e),null;let c=s.identity(e);return c==null||c===""?null:{key:r+":"+c,raw:c,recognizer:s}}return null}function is(e,t,n){let o=new Set,r=s=>{Wt(s)&&!t(s)&&o.add(Eo(s,n))};r(e);for(let s of e.querySelectorAll("script"))r(s);return o}function eo(e,t){let n=t.createElement("div");n.innerHTML="<script><\/script>";let o=n.firstChild;for(let r of e.attributes)o.setAttribute(r.name,r.value);return o.textContent=e.textContent,o}function cs(e,t,n){let o=[],r=[],s=Array.from(e.querySelectorAll("script"));Wt(e)&&s.unshift(e);for(let c of s){if(!Wt(c)||n.ignored(c)||n.skip.has(c)||t.has(Eo(c,n.baseURI)))continue;let l=c.ownerDocument.createElement("script");for(let a of c.attributes)l.setAttribute(a.name,a.value);l.textContent=c.textContent,n.beforeNodeAdded(l)!==!1&&(l.hasAttribute("src")&&r.push(new Promise(a=>{l.addEventListener("load",()=>a()),l.addEventListener("error",()=>a())})),c.replaceWith(l),n.afterNodeAdded(l),o.push(l))}return{executed:o,loads:r}}function Ji(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Yi(e,t){try{let n=new URL(e,t);return n.origin+n.pathname+n.search}catch{return e}}function ls(e,t){let n=e.tagName;if(n==="TITLE"||n==="BASE")return n;if(n==="SCRIPT")return Eo(e,t);if(n==="LINK"){let o=e.getAttribute("href");return o?"link|"+(e.getAttribute("rel")||"")+"|"+Yi(o,t):e.outerHTML}if(n==="META"){for(let o of["charset","name","property","http-equiv","itemprop"])if(e.hasAttribute(o))return"meta|"+o+"="+e.getAttribute(o);return e.outerHTML}return n==="STYLE"?"style|"+Ji(e.textContent):e.outerHTML}function rr(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
|
|
4
|
-
`;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function Xi(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var Zi=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Qi=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function sr(e){try{return JSON.parse(e)}catch{return JSON.parse(ec(e))}}function ec(e){let t="",n=0,o=(r,s)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${s}`)};for(;n<e.length&&(n=rr(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let l=rr(e,n+1);if(e[l]==="}"||e[l]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let l=n+1;for(;l<e.length&&e[l]!==r;)e[l]==="\\"&&l++,l++;l>=e.length&&o("unterminated string",n);let a=e.slice(n+1,l);r==="'"&&(a=Xi(a)),t+='"'+a+'"',n=l+1;continue}let s=n;for(;s<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[s]);)s++;s===n&&o("unexpected character "+JSON.stringify(r),n);let c=e.slice(n,s);if(c==="true"||c==="false"||c==="null"||Zi.test(c)){t+=c,n=s;continue}if(Qi.test(c)){if(e[rr(e,s)]===":"){t+='"'+c+'"',n=s;continue}o("unquoted value "+JSON.stringify(c),n)}o("invalid token "+JSON.stringify(c),n)}return t}var gt=Symbol("hyper-morph-json-merge:missing"),as=["id","_id","uuid","key","slug","code","name"];function Bn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function to(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function tc(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function gn(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!gn(e[n],t[n]))return!1;return!0}if(Bn(e)&&Bn(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!to(t,o)||!gn(e[o],t[o]))return!1;return!0}return!1}function fs(e,t,n,o){return gn(t,n)?t:gn(t,e)?n:gn(n,e)?t:Bn(t)&&Bn(n)?nc(Bn(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?ic(Array.isArray(e)?e:[],t,n,o):n}function us(e,t,n,o){return t===gt&&n===gt?gt:t===gt?e===gt?n:gn(n,e)?gt:n:n===gt?e===gt?t:gt:fs(e,t,n,o)}function nc(e,t,n,o){let r={},s=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let c of s){let l=us(to(e,c)?e[c]:gt,to(t,c)?t[c]:gt,to(n,c)?n[c]:gt,o);l!==gt&&tc(r,c,l)}return r}function oc(e){return e===null||typeof e!="object"}function Co(e){return typeof e+":"+String(e)}function rc(e,t){for(let n of t){let o=new Set;for(let r of n){if(!to(r,e))return!1;let s=r[e];if(typeof s!="string"&&typeof s!="number")return!1;let c=Co(s);if(o.has(c))return!1;o.add(c)}}return!0}function sc(e,t,n,o){let r=[e,t,n],s=!0;for(let c of r)for(let l of c)Bn(l)||(s=!1);if(s){for(let c of o.keyCandidates)if(rc(c,r))return{kind:"keyed",field:c};return null}for(let c of r){let l=new Set;for(let a of c){if(!oc(a))return null;let b=Co(a);if(l.has(b))return null;l.add(b)}}return{kind:"self"}}function ic(e,t,n,o){let r=sc(e,t,n,o);if(!r)return n;let s=r.kind==="self"?Co:u=>Co(u[r.field]),c=u=>{let h=new Map;for(let y of u)h.set(s(y),y);return h},l=c(e),a=c(t),b=c(n),p=new Map,g=new Set([...l.keys(),...a.keys(),...b.keys()]);for(let u of g){let h=us(l.has(u)?l.get(u):gt,a.has(u)?a.get(u):gt,b.has(u)?b.get(u):gt,o);h!==gt&&p.set(u,h)}let m=[];for(let u of n){let h=s(u);p.has(h)&&m.push(h)}for(let u=0;u<t.length;u++){let h=s(t[u]);if(!p.has(h)||m.includes(h))continue;let y=0;for(let S=u-1;S>=0;S--){let v=m.indexOf(s(t[S]));if(v!==-1){y=v+1;break}}m.splice(y,0,h)}return m.map(u=>p.get(u))}function ds(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...as]:as;return fs(e===void 0?gt:e,t,n,{keyCandidates:r})}function ir(e,t,n,o={}){let r=o.parse||sr,s=[],c=(g,m)=>{if(typeof g!="string")return gt;try{return r(g)}catch(u){return s.push(`${m} side is not valid JSON (${u.message})`),gt}},l=c(t,"local"),a=c(n,"remote");if(l===gt)return{text:n,warnings:s};if(a===gt)return{text:t,warnings:s};let b=c(e,"base"),p=ds(b===gt?void 0:b,l,a,o);return gn(p,a)?{text:n,warnings:s}:gn(p,l)?{text:t,warnings:s}:{text:JSON.stringify(p,null,2),warnings:s}}var Ee=e=>!!e&&e.nodeType===1,cc=new Set("P H1 H2 H3 H4 H5 H6 DIV LI DD DT BLOCKQUOTE FIGCAPTION SUMMARY ADDRESS".split(" ")),hs=5e4;function cr(e,t,n,o){let r=o.ignored,s=Gr({ignored:r,ignoreAttribute:o.ignoreAttribute}),{unitsOf:c,meta:l}=s,a=o.baseURI,b=o.mergeTags!==null,p=A=>C=>{if(b&&C.tagName==="SCRIPT"){let R=jn(C,o.mergeTags);if(R)return"merge:"+R.key}return C.parentElement&&C.parentElement.tagName==="HEAD"?ls(C,a):A(C)},g=p(o.identity.base),m=p(o.identity.local),u=p(o.identity.remote),h=o.authored||o.identity,y=A=>A&&A.nodeType===9?A.documentElement:A,S=y(e),v=y(t),D=y(n),q=globalThis.__hyperMorphProfile,Z=q?performance.now():0,ae="[id],[data-id],script,head>*",ie=A=>A===wn?ae:null,he=Mo(S,g,r,ie(o.identity.base)),K=o.localIsBase?ms():qo(S,v,{analyzer:s,baseIndex:he,sideIndex:Mo(v,m,r,ie(o.identity.local)),baseId:h.base,sideId:h.local}),J=qo(S,D,{analyzer:s,baseIndex:he,sideIndex:Mo(D,u,r,ie(o.identity.remote)),baseId:h.base,sideId:h.remote});qe(),Ke(K,J),Ke(J,K),q&&(q.alignTotal=(q.alignTotal||0)+(performance.now()-Z),Z=performance.now());let ye=S.ownerDocument.implementation.createHTMLDocument(""),je=new WeakMap,Fe=new WeakMap,ot=[],ct=[],Ct=new Set,vt=[],Oe=new Set,dt=new Set,Qe=new Set,Lt=new WeakMap,rt=o.conflicts||"remote",et=A=>ot.push(A),lt=A=>ot.push(A),O=A=>ct.push(A),F=Ne(),ke=x(S,K.map.get(S),J.map.get(S),!!o.localIsBase,!!o.childrenOnly);ke.tagName==="HTML"?ye.replaceChild(ke,ye.documentElement):ye.body.appendChild(ke),q&&(q.build=(q.build||0)+(performance.now()-Z));let re=o.childrenOnly?!Ge(ft(ke),ft(D)):!bt(ke,D);return{doc:ye,root:ke,provenance:je,textMappers:Fe,decisions:ot,conflicts:ct,localDiverged:re,mergedScripts:Ct,segments:vt,remoteIdOf:o.identity.remote,customIdentity:o.identity.remote!==wn,L:K,R:J};function Ne(){let A=new Map,C=new Set;if(o.localIsBase||!K.insertedByHash)return{partner:A,drop:C};let R=K.insertedByHash(),U=J.insertedByHash();if(!R.size||!U.size)return{partner:A,drop:C};let H={ignored:r,remoteWins:o.remoteWins,inlineCache:Lt},_=ue=>{let Ve=0;for(let Te=ue.parentNode;Te;Te=Te.parentNode)Ve++;return Ve},z=[],ne=ue=>{let Ve=ue.textContent.trim();return Ve.split(/\s+/).length>=3||Ve.replace(/\s/g,"").length>=12},pe=ue=>{let Ve=K.map.get(ue),Te=J.map.get(ue);return Ve&&K.reverse.get(Ve.parentNode)!==ue.parentNode||Te&&J.reverse.get(Te.parentNode)!==ue.parentNode},fe=(ue,Ve,Te)=>{for(let wt of Te.parentNode.children){let Ot=wt!==Te&&ue.reverse.get(wt);if(Ot&&pe(Ot))return!0}let It=ue.reverse.get(Te.parentNode);if(It){for(let wt of It.children)if(!Ve.map.has(wt)&&!r(wt))return!0}return!1};for(let[ue,Ve]of R){let Te=U.get(ue);if(!Te)continue;let It=Ve.length===1&&Te.length===1;for(let wt of Ve)xn(wt,H)||z.push([wt,Te,_(wt),It&&(ne(wt)||fe(K,J,wt)||fe(J,K,Te[0]))])}if(!z.length)return{partner:A,drop:C};z.sort((ue,Ve)=>ue[2]-Ve[2]);let me=new Set,Pe=new Set,Le=ue=>{for(let Ve of ue.querySelectorAll("*"))me.add(Ve)},kt=(ue,Ve)=>ue.reverse.get(Ve.parentNode)||null;for(let[ue,Ve,,Te]of z){if(me.has(ue))continue;let It=kt(K,ue),wt=ht=>!Pe.has(ht)&&!me.has(ht)&&ht.tagName===ue.tagName,Ot=Ve.find(ht=>wt(ht)&&It&&kt(J,ht)===It)||(Te?Ve.find(wt):null);Ot&&(Pe.add(Ot),Le(ue),Le(Ot),!(It&&kt(J,Ot)===It)&&(A.set(ue,Ot),A.set(Ot,ue),C.add(rt==="local"?Ot:ue)))}return{partner:A,drop:C}}function tt(A,C,R){if(Oe.add(A),F.drop.has(A))return null;Oe.add(R);let U=C==="local"?A:R,H=C==="local"?R:A,_;return s.unitHash(U)===s.unitHash(H)?(_=we(U,"local",!0),je.get(_).remote=H):_=Q(U,H),O({kind:"structure",el:_,detail:"both-moved",base:null,local:U,remote:H}),et({kind:"insert",el:_,source:"both"}),_}function qe(){if(!K.weak||!J.weak||!K.weak.size||!J.weak.size||!K.unpair)return;let A=new Map;for(let R of K.weak){let U=K.map.get(R);Ee(R)&&Ee(U)&&A.set(s.unitHash(U),R)}let C=!1;for(let R of Array.from(J.weak)){let U=J.map.get(R);if(!Ee(R)||!Ee(U))continue;let H=A.get(s.unitHash(U));!H||H===R||!K.weak.has(H)||K.map.has(R)&&J.map.has(H)||K.map.get(H).tagName===U.tagName&&(K.unpair(H),J.unpair(R),C=!0)}C&&(K.rematch(),J.rematch())}function Ke(A,C){if(!A.weak||!A.weak.size||!C.insertedByHash)return;let R=C.insertedByHash();if(!R.size)return;let U=!1;for(let H of Array.from(A.weak)){let _=A.map.get(H);if(!_)continue;let z=R.get(s.unitHash(_));z&&z.some(ne=>ne.tagName===_.tagName)&&(A.unpair(H),U=!0)}U&&A.rematch()}function Ze(A,C){if(A.map.has(C))return A.map.get(C);let R=[];for(let H=C.parentNode;H&&!A.map.has(H);H=H.parentNode)R.push(H);let U=R.length?R[R.length-1].parentNode:C.parentNode;if(!U||!A.identical.has(U))return null;A.pairIdenticalChildren(U);for(let H=R.length-1;H>=0;H--)A.pairIdenticalChildren(R[H]);return A.map.get(C)||null}function at(A,C,R){if(dt.has(A)||Qe.has(A))return O({kind:"structure",el:null,detail:"both-moved",base:A}),dt.has(A)?null:we(R,C);let U=Ze(K,A),H=Ze(J,A);(!U||!H)&&O({kind:"structure",el:null,detail:"move-beats-delete",base:A});let _=x(A,U,H,!1);return(C==="local"?et:lt)({kind:"move",el:_,source:C}),_}function f(A,C,R,U){return U||!C||C===R?{el:R,asBase:!0,twin:H=>H,baseOf:H=>H,units:c(R),here:()=>!0,parentOfTwin:()=>R}:{el:C,asBase:!1,twin:H=>A.map.get(H),baseOf:H=>A.reverse.get(H),units:c(C),here:H=>Ee(H)?H.parentNode===C||C.tagName==="TEMPLATE"&&H.parentNode===C.content:H.parent===C||C.tagName==="TEMPLATE"&&H.parent===C.content}}function T(A,C,R){return!C||R&&R.identical.has(A)?!1:Ee(A)?l(A).hash!==l(C).hash:A.value!==C.value}function x(A,C,R,U,H=!1){let _=U||o.remoteWins(A),z=A.namespaceURI&&A.namespaceURI!=="http://www.w3.org/1999/xhtml"?ye.createElementNS(A.namespaceURI,A.tagName):ye.createElement(A.tagName),ne={base:A,local:C||null,remote:R||null};if(je.set(z,ne),Oe.add(A),dt.add(A),C&&Oe.add(C),R&&Oe.add(R),o.skipUnchanged&&!H&&(o.localIsBase||K.identical.has(A))&&R&&J.identical.has(A)&&!o.remoteWins(A)){ne.unchanged=!0;for(let fe of A.attributes)fe.namespaceURI?z.setAttributeNS(fe.namespaceURI,fe.name,fe.value):z.setAttribute(fe.name,fe.value);return z}Qe.add(A),H||E(A,_?A:C,R,z);let pe=A.tagName;if(Wt(A))I(A,_?A:C,R,z);else if(pe==="TEXTAREA")z.textContent=B(A.textContent,(_?A:C)?(_?A:C).textContent:A.textContent,R?R.textContent:A.textContent,z,"text");else{let fe=Ye(A,C,R,_,z),me=pe==="TEMPLATE"&&z.content?z.content:z;for(let Pe of fe)me.appendChild(Pe)}return Qe.delete(A),z}function B(A,C,R,U,H){if(C===R)return C;if(C===A)return R!==A&<({kind:H,node:U,source:"remote"}),R;if(R===A)return et({kind:H,node:U,source:"local"}),C;let _=rt==="local"?C:R;return O({kind:H,node:U,base:A,local:C,remote:R,resolved:_}),ot.push({kind:H,node:U,source:"both"}),_}function I(A,C,R,U){let H=A.textContent,_=C?C.textContent:H,z=R?R.textContent:H,ne=b?jn(A,o.mergeTags,!0):null;if(ne&&_!==z){let pe=R&&R.getAttribute("merge-key")||A.getAttribute("merge-key"),{text:fe,warnings:me}=ir(o.localIsBase?void 0:H,_,z,{parse:ne.recognizer.parse,keyCandidates:pe?pe.split(/[\s,]+/).filter(Boolean):void 0});for(let Pe of me)console.warn(`[hyper-morph] merge "${ne.raw}": ${Pe}`);U.textContent=fe,Ct.add(U),fe!==z?et({kind:"text",node:U,source:fe===_?"local":"both"}):fe!==H&<({kind:"text",node:U,source:"remote"});return}U.textContent=B(H,_,z,U,"text")}function E(A,C,R,U){let H=new Map;for(let _ of[A,C,R])if(_)for(let z of _.attributes)o.ignoreAttribute(_,z.name)||H.set(z.name,z);for(let[_,z]of H){let ne=A?A.getAttribute(_):null,pe=C?C.getAttribute(_):ne,fe=R?R.getAttribute(_):ne,me;pe===fe?me=pe:pe===ne?(me=fe,lt({kind:"attr",el:U,name:_,source:"remote"})):fe===ne?(me=pe,et({kind:"attr",el:U,name:_,source:"local"})):(me=j(_,ne,pe,fe),me===void 0&&(me=rt==="local"?pe:fe,O({kind:"attr",el:U,name:_,base:ne,local:pe,remote:fe,resolved:me})),ot.push({kind:"attr",el:U,name:_,source:"both"})),me!=null&&(z.namespaceURI?U.setAttributeNS(z.namespaceURI,z.name,me):U.setAttribute(_,me))}}function j(A,C,R,U){if(A==="class"){let H=fe=>new Set((fe||"").split(/\s+/).filter(Boolean)),_=H(C),z=H(R),ne=H(U),pe=new Set;for(let fe of new Set([..._,...z,...ne])){let me=_.has(fe),Pe=z.has(fe),Le=ne.has(fe);(Pe===Le?Pe:Pe===me?Le:Pe)&&pe.add(fe)}return[...pe].join(" ")}if(A==="style"){let H=me=>{let Pe=new Map;if(!me)return Pe;let Le=0,kt=null,ue="",Ve=()=>{let Te=ue.indexOf(":");Te>0&&Pe.set(ue.slice(0,Te).trim(),ue.slice(Te+1).trim()),ue=""};for(let Te of me){if(kt){ue+=Te,Te===kt&&(kt=null);continue}if(Te==='"'||Te==="'"){kt=Te,ue+=Te;continue}if(Te==="("?Le++:Te===")"&&Le--,Te===";"&&Le===0){Ve();continue}ue+=Te}return ue.trim()&&Ve(),Pe},_=H(C),z=H(R),ne=H(U),pe=new Map,fe=!1;for(let me of new Set([..._.keys(),...z.keys(),...ne.keys()])){let Pe=_.get(me)??null,Le=z.get(me)??null,kt=ne.get(me)??null,ue;Le===kt?ue=Le:Le===Pe?ue=kt:kt===Pe?ue=Le:(ue=rt==="local"?Le:kt,fe=!0),ue!=null&&pe.set(me,ue)}return fe?void 0:[...pe].map(([me,Pe])=>`${me}: ${Pe}`).join("; ")}}function M(A,C,R,U){let H=A.value,_=U?H:C?C.value:"",z=R?R.value:"";Oe.add(A),C&&Oe.add(C),R&&Oe.add(R);let ne=Xn(H,_,z,rt),pe=ne.text===""?null:ye.createTextNode(ne.text);pe&&(je.set(pe,{base:A.nodes,local:C?C.nodes:null,remote:R?R.nodes:null}),Fe.set(pe,ne.mapLocalOffset)),_!==H&&z!==H?ot.push({kind:"text",node:pe,source:"both"}):_!==H?et({kind:"text",node:pe,source:"local"}):z!==H&<({kind:"text",node:pe,source:"remote"});for(let fe of ne.conflicts)O({kind:"text",node:pe,base:H.slice(fe.bs,fe.be),local:fe.local,remote:fe.remote,resolved:fe.resolved});return pe}function P(A,C){return Zn(A,C).every(R=>R.bs===R.be)}function Y(A,C){let R=A?A.value:"",U=C?C.value:"",H;if(R===U||!U?H=R:R?P(R,U)?H=U:P(U,R)?H=R:(H=rt==="local"?R:rt==="both"?R+U:U,O({kind:"structure",el:null,detail:"insert-collision",local:R,remote:U,resolved:H})):H=U,A&&Oe.add(A),C&&Oe.add(C),H==="")return null;let _=ye.createTextNode(H);return je.set(_,{base:null,local:A?A.nodes:null,remote:C?C.nodes:null}),R?et({kind:"insert",el:_,source:U&&R===U?"both":"local"}):lt({kind:"insert",el:_,source:"remote"}),_}function Q(A,C){let R={ignored:r,remoteWins:o.remoteWins,inlineCache:Lt},U=ne=>c(ne).every(pe=>Ee(pe)?xn(pe,R):pe.kind==="text"),H=null;if(U(A)&&U(C)){let ne=A.textContent,pe=C.textContent;ne===pe||P(pe,ne)?H=C:P(ne,pe)&&(H=A)}if(!H){let ne=rt==="local",pe=we(ne?A:C,ne?"local":"remote",!0),fe=je.get(pe);return ne?fe.remote=C:fe.local=A,O({kind:"structure",el:pe,detail:"insert-collision",local:A,remote:C,resolved:ne?A:C}),pe}let _=A.namespaceURI&&A.namespaceURI!=="http://www.w3.org/1999/xhtml"?ye.createElementNS(A.namespaceURI,A.tagName):ye.createElement(A.tagName);E(null,A,C,_),je.set(_,{base:null,local:A,remote:C}),Oe.add(A),Oe.add(C);let z=or({base:Array.from(H.childNodes),local:Array.from(A.childNodes),remote:Array.from(C.childNodes),out:ye,policy:rt,idOf:{local:m,remote:u},ignored:r,ignoreAttribute:o.ignoreAttribute,remoteWins:o.remoteWins,provenance:je,textMappers:Fe,conflicts:ct,decisions:ot,node:_});vt.push(...z.segments);for(let ne of z.nodes)_.appendChild(ne);return _}function we(A,C,R=!1){if(!R&&Ee(A)){let z=F.partner.get(A);if(z)return tt(A,C,z)}if(!Ee(A)){if(A.value==="")return null;let z=A.kind==="comment"?ye.createComment(A.value):ye.createTextNode(A.value);return je.set(z,{base:null,local:C==="local"?A.nodes:null,remote:C==="remote"?A.nodes:null}),Oe.add(A),z}let U=A.namespaceURI&&A.namespaceURI!=="http://www.w3.org/1999/xhtml"?ye.createElementNS(A.namespaceURI,A.tagName):ye.createElement(A.tagName);for(let z of A.attributes)z.namespaceURI?U.setAttributeNS(z.namespaceURI,z.name,z.value):U.setAttribute(z.name,z.value);je.set(U,{base:null,local:C==="local"?A:null,remote:C==="remote"?A:null}),Oe.add(A);let H=A.tagName==="TEMPLATE"&&U.content?U.content:U,_=C==="local"?K:J;for(let z of c(A)){let ne=Ee(z)?_.reverse.get(z):null;if(ne&&dt.has(ne)){O({kind:"structure",el:null,detail:"both-moved",base:ne});continue}if(ne&&!Qe.has(ne)){let fe=K.map.get(ne)||null,me=J.map.get(ne)||null;if(fe||me){let Pe=x(ne,fe,me,!1);C==="local"?et({kind:"move",el:Pe,source:"local"}):lt({kind:"move",el:Pe,source:"remote"}),H.appendChild(Pe);continue}}let pe=we(z,C);pe&&H.appendChild(pe)}return U}function Ye(A,C,R,U,H){C&&K.identical.has(A)&&K.pairIdenticalChildren(A),R&&J.identical.has(A)&&J.pairIdenticalChildren(A);let _=f(K,C,A,U),z=f(J,R,A,!1),ne=c(A),pe=new Set(ne),fe=new Map;for(let W=0;W<ne.length;W++)fe.set(ne[W],W);let me=[],Pe=new Set,Le=new Map,kt=new Set,ue=new Set,Ve=[];wo();let Te=W=>{let xe=[];for(let de of W.units){if(ue.has(de))continue;let Me=W.baseOf(de);Me&&pe.has(Me)&&xe.push(fe.get(Me))}return xe},It=W=>W.every((xe,de)=>de===0||xe>=W[de-1]),wt=!_.asBase&&!It(Te(_)),Ot=!z.asBase&&!It(Te(z));wt&&Ot&&O({kind:"structure",el:null,detail:"both-reordered",base:A});let ht=Ot||!wt?{V:z,A:J,side:"remote",other:_,otherA:K,otherSide:"local"}:{V:_,A:K,side:"local",other:z,otherA:J,otherSide:"remote"};wt?et({kind:"move",el:null,source:Ot?"both":"local",base:A}):Ot&<({kind:"move",el:null,source:"remote",base:A});let zn=_.asBase?[]:_.units.filter(W=>!_.baseOf(W)&&!ue.has(W)&&!F.partner.has(W)),qn=z.asBase?[]:z.units.filter(W=>!z.baseOf(W)&&!ue.has(W)&&!F.partner.has(W)),rn=new Map;if(zn.length&&qn.length){let W=new Map,xe=new Map;for(let te of qn){if(Ee(te)){let ee=u(te);ee&&W.set(ee,te)}let Ae=s.unitHash(te);xe.has(Ae)||xe.set(Ae,[]),xe.get(Ae).push(te)}let de=(te,Ae)=>{let ee=te.units.indexOf(Ae);for(let ve=ee-1;ve>=0;ve--){let He=te.baseOf(te.units[ve]);if(He)return He}return"start"},Me=new Map,_e=new Map;for(let te of qn){let Ae=de(z,te);Ee(te)?(_e.has(Ae)||_e.set(Ae,[]),_e.get(Ae).push(te)):te.kind==="text"&&!Me.has(Ae)&&Me.set(Ae,te)}for(let te of zn){let Ae=null;if(Ee(te)){let ee=m(te);ee&&W.has(ee)&&!rn.has(W.get(ee))&&(Ae=W.get(ee))}else if(te.kind==="text"){let ee=Me.get(de(_,te));ee&&!rn.has(ee)&&(Ae=ee)}if(!Ae){let ee=xe.get(s.unitHash(te));ee&&(Ae=ee.find(ve=>!rn.has(ve)&&Ee(ve)===Ee(te)&&(Ee(ve)?ve.tagName===te.tagName:ve.kind===te.kind))||null)}if(!Ae&&Ee(te)){let ee=h.local(te),ve=(_e.get(de(_,te))||[]).filter(He=>{let Et=h.remote(He);return!rn.has(He)&&He.tagName===te.tagName&&!(ee&&Et&&ee!==Et)&&s.similar(te,He)});ve.length===1&&(Ae=ve[0])}Ae&&(rn.set(Ae,te),rn.set(te,Ae))}}let Gt=W=>{if(Oe.has(W))return Le.get(W)||null;let xe=_.twin(W),de=z.twin(W),Me=xe&&!_.asBase&&!_.here(xe),_e=de&&!z.asBase&&!z.here(de);if(Me||_e){if((!xe||!de)&&O({kind:"structure",el:null,detail:"move-beats-delete",base:W}),!Ut(W))return Oe.add(W),null;O({kind:"structure",el:null,detail:"both-moved",base:W})}if(!xe&&!de)return Oe.add(W),lt({kind:"remove",source:"both",base:W}),null;if(!xe&&!T(W,de,J))return Oe.add(W),et({kind:"remove",source:"local",base:W}),null;if(!de&&!T(W,xe,K))return Oe.add(W),lt({kind:"remove",source:"remote",base:W}),null;let te=!xe||!de,Ae=_.asBase?K.map.get(W)||null:xe,ee;return Ee(W)?ee=x(W,Ae,de,_.asBase):W.kind==="comment"?ee=yt(W,Ae,de,_.asBase):ee=M(W,Ae,de,_.asBase),Oe.add(W),ee&&(Le.set(W,ee),xe&&Le.set(xe,ee),de&&Le.set(de,ee),te&&(O({kind:"structure",el:ee,detail:"edit-beats-delete",base:W}),xe?et({kind:"insert",el:ee,source:"local"}):lt({kind:"insert",el:ee,source:"remote"}))),ee},vn=(W,xe,de,Me)=>{if(Oe.has(W))return Le.get(W)||null;let _e=xe.baseOf(W);if(_e&&pe.has(_e))return ue.has(_e)&&!ue.has(W)?bo(_e,W,Me):Gt(_e);if(_e)return yo(_e,W,Me);let te=rn.get(W);if(te){let ee=Me==="local"?W:te,ve=Me==="local"?te:W,He;return Ee(ee)?s.unitHash(ee)===s.unitHash(ve)?(He=we(ee,"local"),je.get(He).remote=ve):He=Q(ee,ve):He=Y(ee,ve),Oe.add(ee),Oe.add(ve),He&&(Le.set(ee,He),Le.set(ve,He),Ee(ee)&&et({kind:"insert",el:He,source:"both"})),He}let Ae=we(W,Me);return Ae&&(Le.set(W,Ae),Me==="local"?et({kind:"insert",el:Ae,source:"local"}):lt({kind:"insert",el:Ae,source:"remote"})),Ae},bo=(W,xe,de)=>{let Me;return Ee(W)?(Me=at(W,de,xe),Me&&Oe.add(xe)):(Me=we(xe,de),Oe.add(xe),Me&&(de==="local"?et:lt)({kind:"insert",el:Me,source:de})),Me&&Le.set(xe,Me),Me},yo=(W,xe,de)=>{let _e=(de==="local"?J:K).map.get(W),te=xe,Ae=_e?At(_e,de==="local"?R:C,de==="local"?J:K):!1,ee=_e&&!Ae&&!xt(W,_e);if(ee&&de===ht.otherSide)return O({kind:"structure",el:null,detail:"both-moved",base:W}),null;if(ee&&O({kind:"structure",el:null,detail:"both-moved",base:W}),_e||O({kind:"structure",el:null,detail:"move-beats-delete",base:W}),Qe.has(W)){O({kind:"structure",el:null,detail:"both-moved",base:W});let He=we(te,de);return He&&Le.set(xe,He),He}let ve=Ee(W)?x(W,de==="local"?te:K.map.get(W)||null,de==="remote"?te:J.map.get(W)||null,!1):null;return ve&&(Le.set(W,ve),Le.set(xe,ve),_e&&Le.set(_e,ve),de==="local"?et({kind:"move",el:ve,source:"local"}):lt({kind:"move",el:ve,source:"remote"})),ve};for(let W of ht.V.units){if(ue.has(W)){let de=Le.get(W);Pe.has(de)||(me.push(de),Pe.add(de));continue}if(Oe.has(W)&&!(Le.get(W)&&Pe.has(Le.get(W)))){let de=ht.V.baseOf(W);de&&!pe.has(de)&&O({kind:"structure",el:null,detail:"both-moved",base:de});continue}let xe=vn(W,ht.V,ht.A,ht.side);xe&&!Pe.has(xe)&&(me.push(xe),Pe.add(xe),!ht.V.baseOf(W)&&!rn.has(W)&&!ue.has(W)&&kt.add(xe))}for(let W of Ve)Pe.has(W.frag)||(me.splice(ko(W.at),0,W.frag),Pe.add(W.frag));if(!ht.other.asBase){let W=ht.other,xe=ht.otherSide,de=ht.otherA,Me=null,_e=0,te=null;for(let Ae of W.units){let ee=Le.get(Ae);if(ee&&Pe.has(ee)){Me=ee,te=null;continue}if(Oe.has(Ae)){let Et=W.baseOf(Ae);Et&&!pe.has(Et)&&O({kind:"structure",el:null,detail:"both-moved",base:Et});continue}let ve=vn(Ae,W,de,xe);if(!ve)continue;let He;if(te)He=me.indexOf(te)+1;else if(Me){if(He=me.indexOf(Me)+1,xe==="remote")for(;He<me.length&&kt.has(me[He]);)He++}else He=_e++;me.splice(He,0,ve),Pe.add(ve),te=ve}}for(let W=0;W<ne.length;W++){let xe=ne[W];if(Oe.has(xe))continue;let de=Gt(xe);de&&me.splice(ko(W),0,de)}return me;function ko(W){for(let xe=W-1;xe>=0;xe--){let de=Le.get(ne[xe]);if(de){let Me=me.indexOf(de);if(Me>=0)return Me+1}}return 0}function In(W){let xe={ignored:r,remoteWins:()=>!1},de=V=>W(V)||Ee(V)&&o.remoteWins(V)&&sn.has(V.tagName)&&xn(V,xe),Me=new Map,_e=V=>{if(!Ee(V)||!cc.has(V.tagName))return!1;let ce=Me.get(V);return ce===void 0&&(ce=!r(V)&&!o.remoteWins(V)&&c(V).every(de),Me.set(V,ce)),ce},te=V=>!Ee(V)&&V.kind==="text",Ae=null,ee=new Map,ve=V=>{let ce=ee.get(V);if(ce)return ce;let ge=Ee(V)?V.textContent:V.value;ce=new Set;let Ce=ge.toLowerCase();if(!(ge.length>hs))if(/^[\x00-\x7f]*$/.test(Ce))for(let Se of Ce.split(/[^\p{L}\p{N}]+/u))Se&&ce.add(Se);else for(let Se of Xo(Ce))/^[\s\p{P}]+$/u.test(Se)||ce.add(Se);return ee.set(V,ce),ce},He=V=>(Ee(V)?V.textContent:V.value).toLowerCase().replace(/\s+/g," ").trim(),Et=new Map,Jt=V=>{let ce=Et.get(V);if(ce)return ce;ce=new Set(ve(V));let ge=Se=>{if(Se)for(let $e of ve(Se))ce.add($e)},Ce=pe.has(V)?V:!_.asBase&&_.baseOf(V)||!z.asBase&&z.baseOf(V);return Ce&&(ge(Ce),ge(K.map.get(Ce)),ge(J.map.get(Ce))),Et.set(V,ce),ce},an=(V,ce)=>{let ge=He(ce),Ce=pe.has(V)?V:!_.asBase&&_.baseOf(V)||!z.asBase&&z.baseOf(V),Se=ut=>ge?ut.split(ge).length-1:0;if(Ce&&Ee(ce)&&!pe.has(ce)){let ut=Se(He(Ce));for(let pt of[K.map.get(Ce),J.map.get(Ce)]){if(!pt||pt===ce||pt.ownerDocument!==ce.ownerDocument)continue;let qt=He(pt);if(qt.length>ge.length&&Se(qt)>=ut&&(qt.startsWith(ge)||qt.endsWith(ge)))return!1}}let $e=ve(ce),Xe=Jt(V),Pt=0;for(let ut of $e)Xe.has(ut)&&Pt++;if($e.size&&Pt*2>=$e.size)return!0;if(!ge||ge.length>hs)return!1;let _t=Ce?[V,Ce,K.map.get(Ce),J.map.get(Ce)]:[V],Vt=(ut,pt)=>ut!==pt&&(ut.startsWith(pt)||ut.endsWith(pt));if(_t.some(ut=>ut&&Vt(He(ut),ge)))return!0;if(!pe.has(ce)||!Ce)return!1;let Tt=He(V),zt=He(Ce);return[K.map.get(ce),J.map.get(ce)].some(ut=>{let pt=ut&&He(ut);return!!pt&&Tt!==pt&&(Tt.startsWith(pt)&&!zt.startsWith(pt)||Tt.endsWith(pt)&&!zt.endsWith(pt))})},Bt=V=>{Ae||(Ae=new Set),Ae.add(V)},hn=V=>{Bt(V);for(let[ce,ge]of[[K,_],[J,z]]){if(ge.asBase)continue;let Ce=ce.map.get(V);Ce&&ge.here(Ce)&&Bt(Ce)}},Re=(V,ce)=>V.asBase||ne.every(ge=>!Ee(ge)||ce.identical.has(ge)&&V.here(ce.map.get(ge)))&&V.units.every(ge=>!Ee(ge)||V.baseOf(ge));if(Re(_,K)&&Re(z,J))return null;let Ue=V=>{if(V.asBase)return!1;let ce=-1;for(let ge of V.units){let Ce=Ee(ge)?V.baseOf(ge):null;if(!Ce||!pe.has(Ce))continue;let Se=fe.get(Ce);if(Se<ce)return!0;ce=Se}return!1};if(Ue(_)||Ue(z))return null;for(let[V,ce]of[[_,K],[z,J]]){if(V.asBase||Re(V,ce))continue;let ge=V.units,Ce=ce===K?h.local:h.remote,Se=(se,We)=>{let st=Ee(se)&&h.base(se),Je=Ee(We)&&Ce(We);return!st||!Je||st===Je},$e=new Map;for(let se=0;se<ge.length;se++)$e.set(ge[se],se);let Xe=se=>!!se&&(Ee(se)?V.here(se):$e.has(se)),Pt=se=>{let We=V.twin(se);return Xe(We)?We:null},_t=ne.filter(se=>!V.twin(se)&&_e(se)),Vt=ge.filter(se=>!V.baseOf(se)&&_e(se)),Tt=(se,We)=>We===ne?!!Pt(se):pe.has(V.baseOf(se)),zt=se=>{let We=new Int32Array(se.length),st=new Int32Array(se.length),Je=-1;for(let ze=0;ze<se.length;ze++)We[ze]=Je,Tt(se[ze],se)&&(Je=ze);Je=se.length;for(let ze=se.length-1;ze>=0;ze--)st[ze]=Je,Tt(se[ze],se)&&(Je=ze);return{prev:We,next:st}},ut=zt(ge),pt=zt(ne),qt=(se,We)=>{hn(se),Bt(We)};for(let se of Vt){let We=$e.get(se),st=ut.prev[We],Je=ut.next[We],ze=st>=0?V.baseOf(ge[st]):null,tn=Je<ge.length?V.baseOf(ge[Je]):null,Yt=ze?fe.get(ze):-1,pn=tn?fe.get(tn):ne.length;for(let Kt=Math.max(0,Yt);Kt<=Math.min(pn,ne.length-1);Kt++){let jt=ne[Kt];(_e(jt)||te(jt))&&(!Se(jt,se)||!an(jt,se)||(te(jt)?Bt(se):qt(jt,se)))}}let en=(se,We,st)=>{for(let Je=We+st;Je>=0&&Je<se.length;Je+=st){let ze=se[Je];if(_e(ze))return ze;if(Ee(ze)||ze.value.trim())return null}return null},Ao=se=>{let We=new Set;for(let st of c(se))if(!Ee(st)&&st.kind==="text")for(let Je of ve(st))We.add(Je);return We},Kn=(se,We)=>{let st=ve(We),Je=new Set;for(let ze of Ao(se))st.has(ze)||Je.add(ze);return Je},Gn=(se,We)=>{if(!se.size)return!1;let st=ve(We),Je=0;for(let ze of se)st.has(ze)&&Je++;return Je*2>=se.size};for(let se of ne){if(ce.identical.has(se)||!_e(se))continue;let We=Pt(se);if(!We||!_e(We))continue;let st=Kn(We,se),Je=Kn(se,We);for(let ze of[-1,1]){let tn=en(ne,fe.get(se),ze);tn&&Gn(st,tn)&&(qt(se,We),hn(tn));let Yt=en(ge,$e.get(We)??-1,ze);if(Yt&&Gn(Je,Yt)){qt(se,We);let pn=V.baseOf(Yt);pn?qt(pn,Yt):Bt(Yt)}}}for(let se of _t){let We=fe.get(se),st=pt.prev[We],Je=pt.next[We],ze=st>=0?Pt(ne[st]):null,tn=Je<ne.length?Pt(ne[Je]):null,Yt=ze?$e.get(ze)??-1:-1,pn=tn?$e.get(tn)??-1:ge.length;for(let Kt=Math.max(0,Yt);Kt<=Math.min(pn,ge.length-1);Kt++){let jt=ge[Kt];if((_e(jt)||te(jt))&&!(!Se(se,jt)||!an(jt,se))&&(hn(se),!te(jt))){let $t=V.baseOf(jt);$t?qt($t,jt):Bt(jt)}}}}if(!Ae)return null;for(let V of Array.from(Ae))if(pe.has(V))for(let ce of[K,J]){let ge=ce.map.get(V);ge&&ge.parentNode!==(ce===K?C:R)&&!(ce===K?_:z).asBase&&Ae.delete(V)}return Ae.size?Ae:null}function wo(){if((_.asBase||K.identical.has(A))&&(z.asBase||J.identical.has(A)))return;let W={ignored:r,remoteWins:o.remoteWins,inlineCache:Lt},xe=Re=>Ee(Re)?xn(Re,W):Re.kind==="text",de=In(xe),Me=Re=>de&&de.has(Re)||xe(Re),_e=ne.map(Me);if(!_e.includes(!0))return;let te=Re=>{let Ue=Re.units,V=new Map;for(let Xe=0;Xe<Ue.length;Xe++)V.set(Ue[Xe],Xe);let ce=[],ge=-1;for(let Xe=0;Xe<ne.length;Xe++){if(_e[Xe])continue;let Pt=Re.twin(ne[Xe]),_t=Pt?V.get(Pt):void 0;_t===void 0||_t<=ge||Me(Pt)||(ce.push([Xe,_t]),ge=_t)}let Ce=[],Se=-1,$e=-1;for(let Xe=0;Xe<=ce.length;Xe++){let[Pt,_t]=Xe<ce.length?ce[Xe]:[ne.length,Ue.length],Vt={bLo:-1,bHi:-1,sLo:-1,sHi:-1,next:_t};for(let Tt=Se+1;Tt<Pt;Tt++)_e[Tt]&&(Vt.bLo<0&&(Vt.bLo=Tt),Vt.bHi=Tt);for(let Tt=$e+1;Tt<_t;Tt++)Me(Ue[Tt])&&(Vt.sLo<0&&(Vt.sLo=Tt),Vt.sHi=Tt);Ce.push(Vt),Se=Pt,$e=_t}return{units:Ue,list:Ce}},Ae=te(_),ee=te(z),ve=[];for(let Re of[Ae,ee])for(let Ue of Re.list)Ue.bLo>=0&&ve.push([Ue.bLo,Ue.bHi]);ve.sort((Re,Ue)=>Re[0]-Ue[0]);let He=[];for(let[Re,Ue]of ve){let V=He[He.length-1];V&&Re<=V.hi?V.hi=Math.max(V.hi,Ue):He.push({lo:Re,hi:Ue})}let Et=(Re,Ue)=>{let V=-1,ce=-1;for(let Se=0;Se<Re.list.length;Se++){let $e=Re.list[Se];$e.bLo<Ue.lo||$e.bLo>Ue.hi||(V<0&&(V=Se),ce=Se)}let ge=1/0,Ce=-1;for(let Se=V;Se>=0&&Se<=ce;Se++){let $e=Re.list[Se];$e.sLo>=0&&(ge=Math.min(ge,$e.sLo),Ce=Math.max(Ce,$e.sHi)),Se<ce&&(ge=Math.min(ge,$e.next),Ce=Math.max(Ce,$e.next))}return Ce<0?[]:Re.units.slice(ge,Ce+1)},Jt=(Re,Ue)=>Re.length===Ue.length&&Re.every((V,ce)=>s.unitHash(V)===s.unitHash(Ue[ce])),an=Re=>!Ee(Re)&&Re.kind==="comment",Bt=Re=>{if(!Re.length)return[];let Ue=(Se,$e)=>Ee(Se)?Se:Se.nodes[$e?Se.nodes.length-1:0],V=Ue(Re[0]),ce=Ue(Re[Re.length-1],!0),ge=Se=>Se&&Ee(Se)&&r(Se);for(;ge(V.previousSibling);)V=V.previousSibling;for(;ge(ce.nextSibling);)ce=ce.nextSibling;let Ce=[];for(let Se=V;Se&&(Ce.push(Se),Se!==ce);Se=Se.nextSibling);return Ce},hn=Re=>Re.some(Ue=>Ee(Ue)&&r(Ue));for(let Re of He){let Ue=ne.slice(Re.lo,Re.hi+1),V=_.asBase?null:Et(Ae,Re),ce=z.asBase?null:Et(ee,Re);if(Ue.some(an)||V&&V.some(an)||ce&&ce.some(an))continue;let ge=Bt(V||Ue),Ce=Bt(ce||Ue);if((!V||Jt(Ue,V))&&(!ce||Jt(Ue,ce))&&!(V&&hn(ge)))continue;let Se=or({base:Bt(Ue),local:ge,remote:Ce,out:ye,policy:rt,blocks:de,L:V?K:ps(K,A),R:ce?J:ps(J,A),idOf:{local:m,remote:u},ignored:r,ignoreAttribute:o.ignoreAttribute,remoteWins:o.remoteWins,mergeElement:(Xe,Pt,_t)=>x(Xe,Pt,_t,!1),cloneUnit:we,mergeAttrs:E,atomKey:s.unitHash,moveIn:at,provenance:je,textMappers:Fe,conflicts:ct,decisions:ot,node:H});vt.push(...Se.segments);let $e=ye.createDocumentFragment();for(let Xe of Se.nodes)$e.appendChild(Xe);for(let Xe of[...Ue,...V||[],...ce||[]])Oe.add(Xe),ue.add(Xe),Le.set(Xe,$e);Ve.push({frag:$e,at:Re.lo})}}}function bt(A,C){let R=je.get(A);return R&&R.unchanged?!0:A.tagName!==C.tagName||!le(A,C)?!1:Ge(ft(A),ft(C))}function ft(A){return A.tagName==="TEMPLATE"&&A.content?A.content:A}function le(A,C){let R=0;for(let U of A.attributes)if(!o.ignoreAttribute(A,U.name)&&(R++,C.getAttribute(U.name)!==U.value))return!1;for(let U of C.attributes)o.ignoreAttribute(C,U.name)||R--;return R===0}function Ge(A,C){let R=Rt(A,H=>{let _=je.get(H);return!!(_&&_.pinned)}),U=Rt(C,r);if(R.length!==U.length)return!1;for(let H=0;H<R.length;H++){let _=R[H],z=U[H];if(typeof _=="string"||typeof z=="string"){if(_!==z)return!1}else{if(_.nodeType!==z.nodeType)return!1;if(_.nodeType===1){if(!bt(_,z))return!1}else if(_.nodeValue!==z.nodeValue)return!1}}return!0}function Rt(A,C){let R=[],U=null;for(let H=A.firstChild;H;H=H.nextSibling){if(H.nodeType===3){U=U===null?H.nodeValue:U+H.nodeValue;continue}H.nodeType===1&&C(H)||(U!==null&&(U!==""&&R.push(U),U=null),R.push(H))}return U!==null&&U!==""&&R.push(U),R}function yt(A,C,R,U){let H=A.value,_=U?H:C?C.value:"",z=R?R.value:"";Oe.add(A),C&&Oe.add(C),R&&Oe.add(R);let ne=_===z?_:_===H?z:z===H||rt==="local"?_:z;if(_!==H&&z!==H&&_!==z&&O({kind:"text",node:null,base:H,local:_,remote:z,resolved:ne}),!C&&!R)return null;let pe=ye.createComment(ne);return je.set(pe,{base:A.nodes,local:C?C.nodes:null,remote:R?R.nodes:null}),pe}function Dt(A,C){let R=C.map.get(A);if(!R)return null;let U=Ee(R)?R.parentNode:R.parent,H=Ee(A)?A.parentNode:A.parent;return C.map.get(H)===U?null:C.reverse.get(U)||null}function Ut(A){let C=new Set([A]),R=A;for(let U=0;U<64;U++){let H=Dt(R,K)||Dt(R,J);if(!H)return!1;if(H===A||Ee(A)&&Ee(H)&&A.contains(H)||C.has(H))return!0;C.add(H),R=H}return!0}function At(A,C,R){if(!C)return!1;let U=Ee(A)?A.parentNode:A.parent;return U===C||C.tagName==="TEMPLATE"&&U===C.content}function xt(A,C){let R=Ee(A)?A.parentNode:A.parent,U=Ee(C)?C.parentNode:C.parent;return!!(K.map.get(R)===U?K:J.map.get(R)===U?J:null)}}function ps(e,t){return e.map.get(t)?ms():{map:{get:o=>o&&o.nodeType===1&&e.map.get(o)||o,has:()=>!0},reverse:{get:o=>e.reverse.get(o)||o,has:()=>!0},moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}function ms(){let e={get:t=>t,has:()=>!0};return{map:e,reverse:e,moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}var gs=new Set(["INPUT","OPTION","TEXTAREA"]);function bs(e,t,n,o){let r=e.ownerDocument,{provenance:s,textMappers:c}=n,l=o.hooks,a=[],b=[],p=[],g=new Set,m=[],u=[],h=new Set,y=new Map,S=f=>!!f&&(f===e||e.contains(f)||e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content.contains(f)),v=new Map,D=new Map,q=new Map,Z=new Map;(function f(T){let x=s.get(T);if(x){if(T.nodeType===1){let I=x.local?o.toLive(x.local):null;I&&S(I)&&I.nodeType===1&&(v.set(T,I),D.set(I,T))}else if(Array.isArray(x.local)){let I=K(x.local,x.local.map(E=>o.toLive(E)).filter(E=>E&&S(E)&&E.nodeType===T.nodeType));if(I.length&&(v.set(T,I[0]),D.set(I[0],T),q.set(T,I)),Array.isArray(x.caret))for(let E of x.caret){let j=o.toLive(E.node);if(!j||!S(j)||j.nodeType!==3)continue;let M=Z.get(j);Array.isArray(M)||Z.set(j,M=[]),M.push({merged:T,from:E.from,to:E.to,flatStart:E.flatStart})}else{let E=0;for(let j of I)Z.set(j,{merged:T,shift:E}),E+=j.nodeValue.length}}}let B=T.nodeType===1&&T.tagName==="TEMPLATE"&&T.content?T.content.childNodes:T.childNodes;for(let I of B)f(I)})(t);let ae=new Set;for(let f of v.values())ae.add(f);for(let f of q.values())for(let T of f)ae.add(T);for(let f of n.segments||[])J(f);let ie=o.restoreFocus===!1?null:lc(r,Z);o.childrenOnly?ot(ye(e),ye(t)):je(e,t);for(let{node:f,parent:T}of m)g.has(f)||!f.parentNode||f.nodeType===1&&(o.ignored(f)||ct(f))||lt(f,T);return ac(r,ie,Z,c,q,y),{applied:a,moved:b,replaced:p,identities:u,mergedScriptsLive:h,liveOf:v};function he(f,T){let x=f.slice(T.bs,T.be),B=0;for(;B<x.length&&B<T.text.length&&x[B]===T.text[B];)B++;let I=0;for(;I<x.length-B&&I<T.text.length-B&&x[x.length-1-I]===T.text[T.text.length-1-I];)I++;return{bs:T.bs+B,be:T.be-I,text:T.text.slice(B,T.text.length-I)}}function K(f,T){if(!T.length)return T;let x=new Set;for(let I of f){let E=I.parentNode;if(E)for(let j=E.firstChild;j;j=j.nextSibling)j.nodeType===3&&x.add(o.toLive(j))}let B=[];for(let I of T){B.push(I);for(let E=I.nextSibling;E&&E.nodeType===3&&!x.has(E)&&!B.includes(E);E=E.nextSibling)B.push(E)}return B}function J(f){let T=[];for(let le of f.localNodes){let Ge=o.toLive(le.node);if(!Ge||!S(Ge)||Ge.nodeType!==3)return;T.push(Ge)}let x=K(f.localNodes.map(le=>le.node),T);if(!x.length)return;let B=x.map(le=>le.nodeValue).join(""),{flatLocal:I,lToM:E,mapLocal:j}=f;if(B===I)return;let M=f.textNodes.map(le=>({node:le.node,ms:le.ms,me:le.me})),P=[],Y=0;for(let le of x)P.push(Y),Y+=le.nodeValue.length;let Q=(le,Ge)=>x.find((Rt,yt)=>P[yt]<=le&&le+Ge<=P[yt]+Rt.nodeValue.length)||null,we=[],Ye=0;for(let le of Zn(I,B).map(Ge=>he(I,Ge))){let Ge=le.bs+Ye;Ye+=le.text.length-(le.be-le.bs);let Rt,yt;if(le.be>le.bs){Rt=E[le.bs];let Dt=Rt>=0;for(let Ut=le.bs;Dt&&Ut<le.be;Ut++)E[Ut]!==Rt+(Ut-le.bs)&&(Dt=!1);if(!Dt)continue;yt=Rt+(le.be-le.bs)}else{let Dt=le.bs>0?E[le.bs-1]:0,Ut=le.bs<I.length?E[le.bs]:0;if(Dt<0||Ut<0)continue;Rt=yt=j(le.bs)}we.push({ms:Rt,me:yt,text:le.text,live:yt===Rt?Q(Ge,le.text.length):null})}we.sort((le,Ge)=>Ge.ms-le.ms);let bt=(le,Ge)=>(q.get(le.node)||[v.get(le.node)]).includes(Ge),ft=le=>!!le&&le.nodeType===1&&sn.has(le.tagName);for(let le of we){let Ge=M.find(yt=>yt.ms<=le.ms&&le.me<=yt.me&&le.ms<yt.me);if(Ge&&le.live&&Ge.ms===le.ms&&!bt(Ge,le.live)){let yt=M.find(Dt=>Dt.me===le.ms&&bt(Dt,le.live));yt&&(Ge=yt)}if(!Ge&&le.me===le.ms){let yt=M.find(xt=>xt.me===le.ms),Dt=M.find(xt=>xt.ms===le.ms),Ut=yt||Dt;if(!Ut)continue;let At=Ut.node;for(;ft(At.parentNode)&&(yt?At.parentNode.lastChild:At.parentNode.firstChild)===At;)At=At.parentNode;if(At===Ut.node)Ge=Ut;else{let xt=At.ownerDocument.createTextNode(le.text);At.parentNode.insertBefore(xt,yt?At.nextSibling:At);continue}}if(!Ge)continue;let Rt=Ge.node.nodeValue;Ge.node.nodeValue=Rt.slice(0,le.ms-Ge.ms)+le.text+Rt.slice(le.me-Ge.ms),Ge.me+=le.text.length-(le.me-le.ms)}}function ye(f){return f.nodeType===1&&f.tagName==="TEMPLATE"&&f.content?f.content:f}function je(f,T){g.add(f);let x=s.get(T);if(x&&x.remote&&n.remoteIdOf){let I=n.remoteIdOf(x.remote);I&&u.push([f,I])}if(x&&x.unchanged){n.customIdentity&&x.remote&&dt(f,x.remote),x.remote&&Oe(f,x.remote);return}if(l.beforeNodeMorphed(f,T)===!1)return;ke(f,T);let B=f.tagName;if(Wt(f))f.textContent!==T.textContent&&(a.push({kind:"text",node:f,before:f.textContent,after:T.textContent}),f.textContent=T.textContent),n.mergedScripts.has(T)&&h.add(f);else if(B==="TEXTAREA")at(f,T,x);else{Ke(f,T,x);let I=B==="TEMPLATE"&&f.content?f.content:f,E=B==="TEMPLATE"&&T.content?T.content:T;o.protectFocusedValue==="subtree"&&Ne(f)&&f!==r.body?Fe(I):ot(I,E)}l.afterNodeMorphed(f,T)}function Fe(f){for(let T=f.firstChild;T;T=T.nextSibling){let x=D.get(T);x&&v.get(x.parentNode)!==f||(g.add(T),T.nodeType===1&&Fe(T))}}function ot(f,T){let x=rt(f.firstChild),B=new Set;for(let I of Array.from(T.childNodes)){let E=v.get(I);E&&g.has(E)&&!B.has(E)&&(E=null);let j=s.get(I);if(j&&j.pinned){E&&E.nodeType===1&&((E.parentNode!==f||rt(E.nextSibling)!==x)&&et(f,E,x),g.add(E),B.add(E));continue}if(E&&E.nodeType===1){if(E!==x){let Y=E.parentNode;if(Y===f&&x&&tt(E)){let Q=E.nextSibling;for(let we=x;we&&we!==E;){let Ye=we.nextSibling;et(f,we,Q),we=Ye}}else et(f,E,x),Y!==f&&(b.push(E),a.push({kind:"move",el:E,from:Y,to:f}))}B.add(E),je(E,I),x=rt(E.nextSibling);continue}if(E&&E.nodeType!==1){let Y=q.get(I)||[E];E!==x&&et(f,E,x);let Q=I.nodeValue;if(I.nodeType===3){let we=Ct(I),Ye=Y.map(bt=>bt.nodeValue).join("");we!=null&&Ye!==we&&(Q=Xn(we,Ye,I.nodeValue).text)}l.beforeNodeMorphed(E,I)!==!1&&(E.nodeValue!==Q&&(a.push({kind:"text",node:E,before:E.nodeValue,after:Q}),E.nodeValue=Q),l.afterNodeMorphed(E,I)),g.add(E),B.add(E),y.set(I,E),x=rt(E.nextSibling);continue}if(I.nodeType===3&&x&&x.nodeType===3&&!g.has(x)&&!Z.has(x)){x.nodeValue!==I.nodeValue&&(a.push({kind:"text",node:x,before:x.nodeValue,after:I.nodeValue}),x.nodeValue=I.nodeValue),g.add(x),y.set(I,x),x=rt(x.nextSibling);continue}let M=s.get(I),P=O(M&&M.unchanged&&M.remote?M.remote:I);l.beforeNodeAdded(P)!==!1&&(f.insertBefore(P,x),g.add(P),P.nodeType===3&&y.set(I,P),P.nodeType===1&&(p.push(P),Lt(P,I),Wt(P)||F(P,I),o.formState==="property"&&qe(M)&&Oe(P,M.remote)),x=rt(P.nextSibling),a.push({kind:"insert",node:P,parent:f}),l.afterNodeAdded(P))}for(let I of Array.from(f.childNodes))g.has(I)||B.has(I)||I.nodeType===1&&(o.ignored(I)||ct(I))||(ae.has(I)?m.push({node:I,parent:f}):lt(I,f))}function ct(f){return o.preserve&&f.parentNode&&f.parentNode.nodeType===1&&f.parentNode.tagName==="HEAD"&&o.preserve(f)===!0}function Ct(f){let T=s.get(f);return!T||!Array.isArray(T.local)?null:T.local.map(x=>x.nodeValue).join("")}function vt(f){return s.get(f)}function Oe(f,T){if(!gs.has(f.tagName)&&!f.querySelector("input,option,textarea"))return;let x=(B,I)=>{if(B.tagName!==I.tagName)return;B.tagName==="TEXTAREA"?at(B,I,{remote:I}):gs.has(B.tagName)&&Ke(B,I,{remote:I});let E=Qe(B),j=Qe(I);if(E.length===j.length)for(let M=0;M<E.length;M++)x(E[M],j[M])};x(f,T)}function dt(f,T){let x=Qe(f),B=Qe(T);if(x.length===B.length)for(let I=0;I<x.length;I++){let E=n.remoteIdOf(B[I]);E&&u.push([x[I],E]),dt(x[I],B[I])}}function Qe(f){let T=f.tagName==="TEMPLATE"&&f.content?f.content:f;return Array.from(T.children).filter(x=>!o.ignored(x))}function Lt(f,T){if(!n.remoteIdOf)return;let x=(B,I)=>{let E=s.get(I);if(E&&E.remote&&I.nodeType===1){let P=n.remoteIdOf(E.remote);P&&u.push([B,P])}let j=B.childNodes,M=I.childNodes;for(let P=0;P<j.length&&P<M.length;P++)x(j[P],M[P])};x(f,T)}function rt(f){for(;f&&f.nodeType===1&&o.ignored(f);)f=f.nextSibling;return f}function et(f,T,x){if(typeof f.moveBefore=="function"&&T.ownerDocument===f.ownerDocument)try{f.moveBefore(T,x);return}catch{}f.insertBefore(T,x)}function lt(f,T){l.beforeNodeRemoved(f)!==!1&&(f.parentNode.removeChild(f),a.push({kind:"remove",node:f,parent:T}),l.afterNodeRemoved(f))}function O(f){if(Wt(f))return eo(f,r);let T=r.importNode(f,!0);if(T.nodeType===1)for(let x of Array.from(T.querySelectorAll("script")))Wt(x)&&x.replaceWith(eo(x,r));return T}function F(f,T){let x=f.tagName==="TEMPLATE"&&f.content?f.content:f,B=T.tagName==="TEMPLATE"&&T.content?T.content:T,I=Array.from(x.childNodes),E=Array.from(B.childNodes);for(let j=0;j<E.length&&j<I.length;j++){let M=E[j],P=I[j],Y=v.get(M);Y&&g.has(Y)&&(Y=null);let Q=s.get(M);if(Q&&Q.pinned){if(Y&&Y.nodeType===1){let we=Y.parentNode;et(x,Y,P),we!==x&&(b.push(Y),a.push({kind:"move",el:Y,from:we,to:x})),g.add(Y)}P.remove();continue}if(Y){let we=Y.parentNode;et(x,Y,P),P.remove(),Y.nodeType===1?(we!==x&&(b.push(Y),a.push({kind:"move",el:Y,from:we,to:x})),je(Y,M)):(g.add(Y),y.set(M,Y),Y.nodeValue!==M.nodeValue&&(a.push({kind:"text",node:Y,before:Y.nodeValue,after:M.nodeValue}),Y.nodeValue=M.nodeValue));continue}g.add(P),P.nodeType===3&&y.set(M,P),M.nodeType===1&&!Wt(M)&&F(P,M)}}function ke(f,T){for(let x of Array.from(T.attributes)){if(re(f,x.name)||o.ignoreAttribute(f,x.name))continue;let B=x.namespaceURI?f.getAttributeNS(x.namespaceURI,x.localName):f.getAttribute(x.name);B!==x.value&&l.beforeAttributeUpdated(x.name,f,"update")!==!1&&(x.namespaceURI?f.setAttributeNS(x.namespaceURI,x.name,x.value):f.setAttribute(x.name,x.value),a.push({kind:"attr",el:f,name:x.name,before:B,after:x.value}))}for(let x of Array.from(f.attributes)){if(re(f,x.name)||o.ignoreAttribute(f,x.name)||(x.namespaceURI?T.hasAttributeNS(x.namespaceURI,x.localName):T.hasAttribute(x.name))||l.beforeAttributeUpdated(x.name,f,"remove")===!1)continue;let I=x.value;x.namespaceURI?f.removeAttributeNS(x.namespaceURI,x.localName):f.removeAttribute(x.name),a.push({kind:"attr",el:f,name:x.name,before:I,after:null})}}function re(f,T){let x=f.tagName;return x==="INPUT"?T==="value"||T==="checked"||T==="disabled":x==="OPTION"?T==="selected":!1}function Ne(f){return f===r.activeElement}function tt(f){let T=r.activeElement;return!!T&&T!==r.body&&f.contains(T)}function qe(f){let T=f&&f.remote;return T&&T.nodeType===1?T:null}function Ke(f,T,x){let B=f.tagName,I=qe(x),E=o.formState==="property"&&I?I:T;if(B==="INPUT"){let j=o.protectFocusedValue&&Ne(f),M=(f.getAttribute("type")||"").toLowerCase(),P=M!=="file"&&M!=="checkbox"&&M!=="radio",Y=I&&I.hasAttribute("value")&&I.value!==I.getAttribute("value")?I.value:null;if(P&&!j)if(o.formState==="property"){let Q=T.getAttribute("value"),we=f.getAttribute("value");(we!==Q||f.value!==E.value)&&l.beforeAttributeUpdated("value",f,Q==null?"remove":"update")!==!1&&(we!==Q&&(Q==null?f.removeAttribute("value"):f.setAttribute("value",Q),a.push({kind:"attr",el:f,name:"value",before:we,after:Q})),f.value!==E.value&&(f.value=E.value))}else if(T.hasAttribute("value")||Y!=null){let Q=Y??T.getAttribute("value");f.getAttribute("value")!==Q&&l.beforeAttributeUpdated("value",f,"update")!==!1?(f.setAttribute("value",Q),f.value!==Q&&(f.value=Q),a.push({kind:"attr",el:f,name:"value",before:null,after:Q})):f.value!==Q&&f.getAttribute("value")===Q&&(f.value=Q)}else(f.hasAttribute("value")||f.value!=="")&&l.beforeAttributeUpdated("value",f,"remove")!==!1&&(f.removeAttribute("value"),f.value="",a.push({kind:"attr",el:f,name:"value",before:"",after:null}));if(!P&&M!=="file"){let Q=T.getAttribute("value");Q==null?f.hasAttribute("value")&&l.beforeAttributeUpdated("value",f,"remove")!==!1&&f.removeAttribute("value"):f.getAttribute("value")!==Q&&l.beforeAttributeUpdated("value",f,"update")!==!1&&f.setAttribute("value",Q)}j||(Ze(f,E,"checked"),o.formState==="property"&&f.indeterminate!==E.indeterminate&&(f.indeterminate=E.indeterminate)),Ze(f,E,"disabled")}else if(B==="OPTION"){let j=f.parentNode&&f.closest("select");o.protectFocusedValue&&j&&Ne(j)||Ze(f,E,"selected")}}function Ze(f,T,x){let B=o.formState==="property"?!!T[x]:T.hasAttribute(x);if(o.formState!=="property"){let I=f.hasAttribute(x);if(I!==B){if(l.beforeAttributeUpdated(x,f,B?"update":"remove")===!1)return;B?f.setAttribute(x,""):f.removeAttribute(x),a.push({kind:"attr",el:f,name:x,before:I?"":null,after:B?"":null})}}f[x]!==B&&(f[x]=B)}function at(f,T,x){if(o.protectFocusedValue&&Ne(f)||l.beforeAttributeUpdated("value",f,"update")===!1)return;let B=qe(x),I=T.textContent,E=B&&B.value!==B.defaultValue?B.value:I;o.formState!=="property"&&f.textContent!==I&&(a.push({kind:"text",node:f,before:f.textContent,after:I}),f.textContent=I),f.value!==E&&(f.value=E)}}function lc(e,t){let n=e.activeElement;if(!n||n===e.body||n===e.documentElement)return null;let o={el:n,id:n.getAttribute&&n.getAttribute("id"),scrollTop:n.scrollTop,scrollLeft:n.scrollLeft};if(n.tagName==="INPUT"||n.tagName==="TEXTAREA"){try{o.selection=[n.selectionStart,n.selectionEnd,n.selectionDirection]}catch{}return o}let r=e.getSelection&&e.getSelection();if(r&&r.rangeCount){let s=r.getRangeAt(0);o.range={sc:s.startContainer,so:s.startOffset,ec:s.endContainer,eo:s.endOffset}}return o}function ac(e,t,n,o,r,s){if(!t)return;let c=t.el;if(!c.isConnected&&t.id&&(c=e.getElementById(t.id)),!c||!c.isConnected)return;if(e.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}try{c.scrollTop=t.scrollTop,c.scrollLeft=t.scrollLeft}catch{}if(t.selection){try{c.setSelectionRange&&!c.selectionEnd&&t.selection[1]!=null&&c.setSelectionRange(t.selection[0],t.selection[1],t.selection[2]||"none")}catch{}return}if(!t.range)return;let l=(p,g)=>{let m=n.get(p);if(Array.isArray(m)){let u=m.find(v=>g>=v.from&&g<v.to)||m.find(v=>g===v.to)||m[m.length-1],h=s.get(u.merged);if(!h||!h.isConnected)return null;let y=o.get(u.merged),S=y&&y.flat?y.flat(u.flatStart+g):g;return[h,Math.max(0,Math.min(S,h.nodeValue.length))]}if(m){let u=(r.get(m.merged)||[p])[0];if(!u.isConnected)return null;let h=o.get(m.merged),y=m.shift+g,S=h?h(y):y;return[u,Math.max(0,Math.min(S,u.nodeValue.length))]}return p.isConnected?[p,Math.min(g,p.nodeType===3?p.nodeValue.length:p.childNodes.length)]:null},a=l(t.range.sc,t.range.so),b=l(t.range.ec,t.range.eo);if(!(!a||!b))try{let p=e.createRange();p.setStart(a[0],a[1]),p.setEnd(b[0],b[1]);let g=e.getSelection();g.removeAllRanges(),g.addRange(p)}catch{}}var Cl=Symbol("hyper-morph-duplicate-key");var fc='[editor-ui],[clay~="editor-ui"],[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]',uc='[editor-ui],[clay~="editor-ui"],[no-undo],[clay~="no-undo"]',dc='[no-undo]:not([editor-ui]):not([clay~="editor-ui"]),[clay~="no-undo"]:not([editor-ui]):not([clay~="editor-ui"])';function hc(e){if(e.tagName!=="LINK"&&e.tagName!=="SCRIPT")return!1;let t=e.getAttribute("src")||e.getAttribute("href")||"";return/^(chrome|moz|safari-web)-extension:/.test(t)}function pc(e,t,n,o){if(t==null)return;if(typeof t=="string")return t;let r=t;if(r.nodeType===9){let s=e.getAttribute("id");r=s&&r.getElementById(s)||(e.tagName==="BODY"?r.body:e.tagName==="HTML"?r.documentElement:r.body&&r.body.firstElementChild)}if((!r||r.nodeType!==1||r.tagName!==e.tagName)&&(r=mc(e,t,o)),!!r)return n?Array.from(r.childNodes):r}function mc(e,t,n){let o=t.nodeType===9?t.documentElement:t;if(!o||o.nodeType!==1)return null;let r=new Map,s=[o,...o.querySelectorAll("script")];for(let a of s){let b=jn(a,n);b&&!r.has(b.key)&&r.set(b.key,a.textContent)}if(!r.size)return null;let c=e.cloneNode(!0),l=!1;for(let a of[c,...c.querySelectorAll("script")]){let b=jn(a,n);b&&r.has(b.key)&&(a.textContent=r.get(b.key),l=!0)}return l?c:null}function ys(e,t){if(typeof e=="string"||e.nodeType===9)return e;if(e.nodeType===1&&e===e.ownerDocument.documentElement)return e.ownerDocument;let n=t.implementation.createHTMLDocument(""),o=e.nodeType===1&&e.tagName==="HTML"?e:null;if(o)return n.replaceChild(n.adoptNode(o),n.documentElement),n;let r=e.nodeType===11?Array.from(e.childNodes):e.nodeType?[e]:Array.from(e);for(let s of r)n.body.appendChild(n.adoptNode(s));return n}function lr(e,t,n={}){let o=n||{};if(!o.head?.block)return ks(e,t,o);try{return ks(e,t,o)}catch(r){return Promise.reject(r)}}function ks(e,t,n){let o=n.policy||"sync",r=o==="raw"?void 0:(a,b)=>hc(a)||(o==="history"?!(b&&a.matches(dc))&&a.matches(uc):a.matches(fc)),s=n.callbacks||{},c={ignore:r,hooks:s,protectFocusedValue:n.ignoreActiveValue===!0?"subtree":!1,restoreFocus:n.restoreFocus!==!1,formState:n.formStateSync||"attribute",scripts:{execute:n.scripts?.handle!==!1,merge:n.scripts?.merge!==!1,mergeTags:n.scripts?.mergeTags||[]},head:{awaitLoads:!!n.head?.block,preserve:n.head?.shouldPreserve||(()=>!1)}};if(typeof n.key=="function"&&(c.identity={base:n.key,local:n.key,remote:n.key}),e&&e.nodeType===9)return no(Object.assign({},c,{live:e,base:n.scripts?.mergeBase||null,remote:ys(t,e)}));if(e.tagName==="HTML"&&e.parentNode&&e.parentNode.nodeType===9){let a=Object.assign({},c,{live:e.ownerDocument,base:n.scripts?.mergeBase||null,remote:ys(t,e.ownerDocument)});return no(a)}n.morphStyle==="innerHTML"&&(c.children=!0);let l=pc(e,n.scripts?.mergeBase,!!c.children,c.scripts.mergeTags);return l!==void 0&&(c.base=l),ar(e,t,c)}var gc=new Set(["live","base","remote","local","identity","ignore","remoteWins","ignoreAttribute","conflicts","protectFocusedValue","restoreFocus","head","scripts","formState","children","hooks","beforeApply"]),on=()=>{};function oo(e,t=[]){if(!e||typeof e!="object")throw new TypeError("options object required");for(let c of Object.keys(e))if(!gc.has(c))throw new TypeError(`unknown option "${c}"`);let n=Object.assign({beforeNodeAdded:on,afterNodeAdded:on,beforeNodeRemoved:on,afterNodeRemoved:on,beforeNodeMorphed:on,afterNodeMorphed:on,beforeAttributeUpdated:on},e.hooks||{}),o=e.conflicts||"remote";if(!["remote","local","both"].includes(o))throw new TypeError("conflicts must be remote, local or both");let r=e.formState||"attribute";if(!["attribute","property"].includes(r))throw new TypeError("formState must be attribute or property");let s=e.protectFocusedValue;if(s!==void 0&&typeof s!="boolean"&&s!=="subtree")throw new TypeError('protectFocusedValue must be a boolean or "subtree"');return{ignored:Vo(e.ignore,t),remoteWins:Vo(e.remoteWins,t),ignoreAttribute:typeof e.ignoreAttribute=="function"?e.ignoreAttribute:()=>!1,conflicts:o,protectFocusedValue:s===void 0?!0:s,restoreFocus:e.restoreFocus!==!1,head:Object.assign({awaitLoads:!1,preserve:()=>!1},e.head||{}),scripts:Object.assign({execute:!0,merge:!0,mergeTags:[]},e.scripts||{}),formState:r,hooks:n,children:!!e.children,beforeApply:typeof e.beforeApply=="function"?e.beforeApply:null}}function _n(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){if(typeof e.first=="function")return e.first;if(typeof e.then=="function")return e.then}return wn}function Un(e,t){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){let n=zo(t,e.map),o=typeof e.then=="function"?e.then:wn;if(typeof e.first=="function"){let r=e.first;return s=>r(s)||n.get(s)||o(s)}return r=>n.get(r)||o(r)}return wn}function bc(e,t,n,o={}){let r=g=>g&&g.nodeType===9?g.documentElement:g,s=r(t),c=r(n),l=r(e)||s,a=Object.assign({},o);delete a.live,delete a.base,delete a.remote;let b=oo(a,[l,s,c].filter(Boolean)),p=o.identity||{};return cr(l,s,c,{identity:{base:Un(p.base,l),local:Un(p.local,s),remote:Un(p.remote,c)},authored:{base:_n(p.base),local:_n(p.local),remote:_n(p.remote)},skipUnchanged:b.hooks.beforeNodeMorphed===on&&b.hooks.afterNodeMorphed===on,ignored:b.ignored,remoteWins:b.remoteWins,ignoreAttribute:b.ignoreAttribute,conflicts:b.conflicts,mergeTags:b.scripts.merge===!1?null:b.scripts.mergeTags,baseURI:s.ownerDocument&&s.ownerDocument.baseURI||"about:blank",localIsBase:!e||e===t,childrenOnly:b.children})}function fr({liveRoot:e,baseRoot:t,localRoot:n,remoteRoot:o,toLive:r,options:s,identity:c,childrenOnly:l,isDocument:a}){let b=oo(s,[e,t,n,o].filter(Boolean));if(b.ignored(e))return{report:ur(),loads:[]};let p=e.ownerDocument,g=b.scripts.execute?is(e,b.ignored,p.baseURI):null,m=cr(t||n,n,o,{identity:{base:Un(c.base,t||n),local:Un(c.local,n),remote:Un(c.remote,o)},authored:{base:_n(c.base),local:_n(c.local),remote:_n(c.remote)},ignored:b.ignored,remoteWins:b.remoteWins,ignoreAttribute:b.ignoreAttribute,conflicts:b.conflicts,mergeTags:b.scripts.merge===!1?null:b.scripts.mergeTags,baseURI:p.baseURI,localIsBase:!t,childrenOnly:l,skipUnchanged:b.hooks.beforeNodeMorphed===on&&b.hooks.afterNodeMorphed===on});b.beforeApply&&b.beforeApply(m.doc);let u=globalThis.__hyperMorphProfile,h=u?performance.now():0,y=bs(e,m.root,m,{toLive:r,ignored:b.ignored,ignoreAttribute:b.ignoreAttribute,formState:b.formState,protectFocusedValue:b.protectFocusedValue,restoreFocus:b.restoreFocus,preserve:b.head.preserve,hooks:b.hooks,childrenOnly:l});u&&(u.apply=(u.apply||0)+(performance.now()-h));let S=[];if(b.head.awaitLoads)for(let q of y.applied){if(q.kind!=="insert"||q.node.nodeType!==1)continue;let Z=q.node;Z.tagName==="LINK"&&/\bstylesheet\b/i.test(Z.getAttribute("rel")||"")&&Z.getAttribute("href")&&Z.closest("head")&&S.push(new Promise(ie=>{Z.addEventListener("load",()=>ie()),Z.addEventListener("error",()=>ie())}))}if(g){let q=cs(e,g,{ignored:b.ignored,skip:y.mergedScriptsLive,baseURI:p.baseURI,beforeNodeAdded:b.hooks.beforeNodeAdded,afterNodeAdded:b.hooks.afterNodeAdded});S.push(...q.loads)}let v=q=>q&&y.liveOf&&y.liveOf.get(q)||null;return{report:{applied:y.applied,decisions:m.decisions.map(q=>Object.assign({},q,{node:q.node?v(q.node):null,el:q.el?v(q.el):null,applied:!!(q.node?v(q.node):q.el&&v(q.el))})),conflicts:m.conflicts.map(q=>Object.assign({},q,{node:q.node?v(q.node):q.node,el:q.el?v(q.el):q.el})),localDiverged:m.localDiverged,identities:y.identities,moved:y.moved,replaced:y.replaced},loads:S}}var ws=new WeakMap;function ur(){return{applied:[],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[]}}function no(e){let t=e||{},n=t.live;if(!n||n.nodeType!==9)throw new TypeError("live must be a Document");let o=ws.get(n);o||(o=Fo(n),ws.set(n,o));let r=o("remote",t.remote),s=typeof t.base=="string"&&t.base===""?null:t.base,c=s?o("base",s):null,l=t.local?t.local.root:n.documentElement,a=t.local?t.local.toLive:g=>g;Fr(n,r);let{report:b,loads:p}=fr({liveRoot:n.documentElement,baseRoot:c?c.documentElement:null,localRoot:l,remoteRoot:r.documentElement,toLive:a,options:t,identity:t.identity||{},childrenOnly:!1,isDocument:!0});return Promise.all(p).then(()=>b)}function yc(e,t,n={}){return no(Object.assign({},n,{live:e,base:null,remote:t}))}function As(e,t){if(e==null)return{root:t.createElement("template"),first:null};if(typeof e=="string"){let o=/^\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype[^>]*>\s*)?<(html|body)[\s>]/i.exec(e);if(o){let s=Oo(e,t),c=o[1].toLowerCase()==="html"?s.documentElement:s.body;return{root:c,first:c}}let r=t.createElement("template");return r.innerHTML=e,{root:r,first:r.content.firstElementChild}}if(e.nodeType===9)return{root:e.documentElement,first:e.documentElement};if(e.nodeType===1){let o=t.createElement("template"),r=e.isConnected;return o.content.appendChild(r?t.importNode(e,!0):e),{root:o,first:e}}if(e.nodeType===11){let o=t.createElement("template");return o.content.appendChild(e),{root:o,first:o.content.firstElementChild}}let n=t.createElement("template");for(let o of Array.from(e))n.content.appendChild(o.parentNode?t.importNode(o,!0):o);return{root:n,first:n.content.firstElementChild}}function ar(e,t,n={}){if(!e||e.nodeType!==1)throw new TypeError("oldEl must be an Element");let o=e.ownerDocument,{base:r,...s}=n,c=!!s.children;if(oo(s,[e]).ignored(e))return Promise.resolve(ur());let l=As(t,o),a=r!=null?As(r,o):null,b,p=null;if(c)b=l.root,p=a?a.root:null;else{if(b=l.first,p=a?a.first:null,!b){let u=oo(s);return u.hooks.beforeNodeRemoved(e)!==!1&&(e.remove(),u.hooks.afterNodeRemoved(e)),Promise.resolve({applied:[{kind:"remove",node:e,parent:null}],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[e]})}if(b.tagName!==e.tagName){let u=oo(s,[e,b]);if(u.hooks.beforeNodeMorphed(e,b)===!1)return Promise.resolve(ur());let h=fr({liveRoot:e,baseRoot:p&&p.tagName===e.tagName?p:null,localRoot:e,remoteRoot:b,toLive:S=>S,options:s,identity:s.identity||{},childrenOnly:!0,isDocument:!1}),y=Wt(b)?eo(b,o):o.importNode(b,!1);if(!Wt(y))for(;e.firstChild;)y.appendChild(e.firstChild);return u.hooks.beforeNodeAdded(y)===!1||u.hooks.beforeNodeRemoved(e)===!1?Promise.resolve(h.report):(e.replaceWith(y),u.hooks.afterNodeRemoved(e),u.hooks.afterNodeAdded(y),u.hooks.afterNodeMorphed(e,b),h.report.replaced.push(y),h.report.applied.push({kind:"insert",node:y,parent:y.parentNode},{kind:"remove",node:e,parent:y.parentNode}),Promise.all(h.loads).then(()=>h.report))}}let{report:g,loads:m}=fr({liveRoot:e,baseRoot:p,localRoot:e,remoteRoot:b,toLive:u=>u,options:s,identity:s.identity||{},childrenOnly:c,isDocument:!1});return Promise.all(m).then(()=>g)}var xs={mergeDocument:no,morphDocument:yc,morphElement:ar,merge3:bc,morph:lr};function dr(e,t,{onWidgetRemoved:n}={}){xs.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=So.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var wc="hha:upgrade-check:";function cn(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function hr(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ts(e,t){let n=hr(e),o=hr(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let s=0;s<r;s++){let c=n[s]||0,l=o[s]||0;if(c!==l)return c>l}return!1}function Ac(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function xc(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function pr({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:s=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(m=>fetch(m)),r=r??Date.now(),!t)return null;let c=cn(t,"hyper-source");if(!c)return null;let l=cn(t,"hyper-version"),a;try{a=new URL(c,n?n.href:void 0)}catch{return null}if(n&&a.origin===n.origin&&a.pathname===n.pathname)return null;let b=`${wc}${a.href}:${l||"none"}`,p,g=e?null:Ac(b);if(g&&typeof g.checkedAt=="number"&&r-g.checkedAt<s)p=g.sourceVersion;else{try{let m=await o(a.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let u=await m.text(),h=new DOMParser().parseFromString(u,"text/html");p=cn(h,"hyper-version")}catch{p=null}xc(b,{checkedAt:r,sourceVersion:p})}return p?{available:Ts(p,l||"0.0.0"),currentVersion:l,sourceVersion:p,sourceUrl:a.href}:null}var Lo=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],mr=new Set(Lo),Ss=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),gr=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Po={};Bo(Po,{EmptyListInsert:()=>so,MAX_RULE_DEPTH:()=>$n,MaxRuleDepthExceeded:()=>Sn,NoRulesTag:()=>br,RuleTargetReadOnly:()=>io,RulesParseError:()=>Wn,ShapeMismatch:()=>ro,UnknownRulesVersion:()=>Tn,WriteRefused:()=>Ro,WriteRejected:()=>yr});var Wn=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},Tn=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},$n=20,Sn=class extends Error{constructor(t){super(`rule depth exceeded ${$n} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},ro=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},so=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},io=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},Ro=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}},br=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},yr=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function ln(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return kr(e,t,n,{depth:0,path:[]},o)}function kr(e,t,n,o,r){if(o.depth>$n)throw new Sn(o.path);if(typeof n=="string")return Tc(e,t,n,o,r);if(Array.isArray(n)){let[s,c]=n,l=e.find(t,s,r);return Os(r,o,l),l.map((a,b)=>kr(e,a,c,{depth:o.depth+1,path:[...o.path,b]},r))}if(typeof n=="object"&&n!==null){let s={};for(let[c,l]of Object.entries(n))s[c]=kr(e,t,l,{depth:o.depth+1,path:[...o.path,c]},r);return s}return null}function Tc(e,t,n,o,r){if(n.endsWith("[]")){let l=n.slice(0,-2),a=e.find(t,l,r);return Os(r,o,a),a.map(b=>e.text(b))}if(n.startsWith("@"))return Ns(e,t,n.slice(1));let s=dn(n);if(s!==-1){let l=n.slice(0,s),a=n.slice(s+1),b=l?e.find(t,l,r):[t];return b.length===0?null:Ns(e,b[0],a)}if(n===".")return e.text(t);let c=e.find(t,n,r);return c.length===0?null:e.text(c[0])}function Os(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function Ns(e,t,n){if(mr.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}var Ms=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),Sc=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),vs=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function wr(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Nc(e,t){if(wr(e,t))return!0;for(let[n,o]of Object.entries(Sc))if(o.includes(t)&&wr(e,n))return!0;return!1}function co(e){let t=Ms[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Oc(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=Ms[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Nc(n,r))||o.bundles.some(r=>wr(n,r)))return n;n=n.parentElement}return null}function Is(e,t){return!!Oc(e,t)}var Mc=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Es(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();if("value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&(t.value=e.value),"checked"in e&&"checked"in t&&(t.checked=e.checked),"selected"in e&&"selected"in t&&(t.selected=e.selected),e.tagName==="SELECT")for(let o=0;o<e.options.length;o++)t.options[o].selected=e.options[o].selected;"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Cs(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function Ls(e,t,n,o,r,s,c,l){if(e.nodeType===1&&((c?Is(e,n):Cs(e,o,s,!1))||r&&Cs(e,r,s,c)))return null;let a=t.importNode(e,!1);l.cloneToLive.set(a,e),l.liveToClone.set(e,a);let b=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,p=a.nodeType===1&&a.tagName==="TEMPLATE"?a.content:a;b!==e&&(l.cloneToLive.set(p,b),l.liveToClone.set(b,p));for(let g of b.childNodes||[]){let m=Ls(g,t,n,o,r,s,c,l);m&&(p.appendChild(m),g.nodeType===1&&Es(g,m))}return e.nodeType===1&&Es(e,a),a}function lo(e,{capability:t="data",exclude:n=null,inherit:o=!0}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let r=e.nodeType===9?e:e.ownerDocument;if(!r?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=r.implementation.createHTMLDocument(""),c=new WeakMap,l=new WeakMap,a=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let b=co(t),p=Ls(a,s,t,b,n,a,o,{cloneToLive:c,liveToClone:l});e.nodeType===9&&p&&(s.replaceChild(p,s.documentElement),l.set(e,s),c.set(s,e));let g=m=>{if(Mc.test(m))throw new Error(`Filtered content queries do not support stateful selector: ${m}`)};return{root:p,document:s,capability:t,selector:co(t),cloneToLive:c,liveToClone:l,original(m){return c.get(m)||null},cloneOf(m){return l.get(m)||null},query(m,u=p){return g(m),Array.from(u.querySelectorAll(m),h=>c.get(h)||h)},text(m=p){return(m===p?p:l.get(m))?.textContent||""},html(m=p){return(m===p?p:l.get(m))?.innerHTML??""},clone(m=p){let u=m===p?p:l.get(m);return u?s.importNode(u,!0):null}}}function Rs(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function vc(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Mt={semanticExclude:!0,find(e,t,n={}){let o=vc(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(l=>!Rs(l)));let s=[];n.skip&&s.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&s.push("["+c+"]"),s.length){let l=s.join(", ");r=r.filter(a=>!a.closest||!a.closest(l))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function Nn(e,t={}){if(t.exclude===null)return Mt;let n=[co("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return Mt;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,l=null,a=()=>l||(l=lo(s,{capability:"data",exclude:t.exclude||null})),b=h=>{let y=a();return h===e?y.cloneOf(e):y.cloneOf(h)||h},p=h=>l?.original(h)||h,g=(h,y)=>{a().liveToClone.set(h,y),a().cloneToLive.set(y,h);let S=h.childNodes||[],v=y.childNodes||[];for(let D=0;D<Math.min(S.length,v.length);D++)g(S[D],v[D])},m=(h,y,S,v)=>{let D=Array.from(h.childNodes).filter(he=>l.cloneOf(he)),Z=D[0];for(;Z&&D.includes(Z);)Z=Z.nextSibling;for(let he of D)he.remove();if(S==="innerHTML"){let he=c.createElement("template");he.innerHTML=v;for(let K of Array.from(he.content.childNodes))h.insertBefore(K,Z||null)}else h.insertBefore(c.createTextNode(v),Z||null);let ae=lo(h,{capability:"data",exclude:t.exclude||null});y.replaceChildren(...Array.from(ae.root?.childNodes||[]));let ie=he=>{let K=ae.original(he);K&&(l.liveToClone.set(K,he),l.cloneToLive.set(he,K));for(let J of Array.from(he.childNodes||[]))ie(J)};for(let he of Array.from(y.childNodes))ie(he)},u={...Mt,find(h,y,S={}){let v=b(h);if(!v?.querySelectorAll)return[];let D=a().query(y,v);S.includeRulesTag||(D=D.filter(ae=>!Rs(ae)));let q=[];S.skip&&q.push(S.skip);let Z=S.templateAttr===null?null:S.templateAttr||"cms-template";if(Z&&q.push(`[${Z}]`),q.length){let ae=q.join(", ");D=D.filter(ie=>!ie.closest?.(ae))}return D},parent(h){let y=b(h)?.parentElement;return y?p(y):null},children(h){return Array.from(b(h)?.children||[],p)},text(h,y){if(y===void 0){let D=p(h);return!D?.matches?.(n)&&!D?.querySelector?.(n)?Mt.text(D):(b(h)?.textContent||"").trim()}let S=p(h);if(!S?.matches?.(n)&&!S?.querySelector?.(n)&&!l){Mt.text(S,y);return}let v=a().cloneOf(S);v?m(S,v,"textContent",y):Mt.text(S,y)},attr(h,y,S){let v=p(h);if(S===void 0)return Mt.attr(v,y);Mt.attr(v,y,S);let D=l?.cloneOf(v);D&&(Mt.attr(D,y,S),lo(v,{capability:"data",exclude:t.exclude||null}).root===null&&(D.remove(),l.liveToClone.delete(v),l.cloneToLive.delete(D)))},removeAttr(h,y){let S=p(h);Mt.removeAttr(S,y);let v=l?.cloneOf(S);v&&Mt.removeAttr(v,y)},prop(h,y,S){let v=p(h);if(S===void 0)return y==="innerHTML"||y==="outerHTML"||y==="textContent"||y==="innerText"?Mt.prop(b(v),y):Mt.prop(v,y);let D=y==="innerHTML"||y==="textContent"||y==="innerText",q=D?a().cloneOf(v):l?.cloneOf(v);q&&D?m(v,q,y,S):(Mt.prop(v,y,S),q&&Mt.prop(q,y,S))},clone(h){let y=b(h);return y===h?Mt.clone(h):c.importNode(y,!0)},insertAt(h,y,S){let v=p(h),q=u.children(v)[S]||(()=>{for(let ie=v.children.length-1;ie>=0;ie--){let he=v.children[ie];if(a().cloneOf(he))return he.nextElementSibling}return v.firstElementChild})(),Z=p(y);v.insertBefore(Z,q||null);let ae=a().cloneOf(v);if(ae){let ie=a().cloneOf(Z);ie||(ie=c.importNode(Z,!0),g(Z,ie));let he=Array.from(ae.children);ae.insertBefore(ie,he[S]||null)}},remove(h){let y=p(h),S=a().cloneOf(y);Mt.remove(y),S&&Mt.remove(S)},replaceWith(h,y){let S=p(h),v=a().cloneOf(S),D=Mt.replaceWith(S,y);if(v){let q=lo(D,{capability:"data",exclude:t.exclude||null});if(!q.root)v.remove();else{v.replaceWith(q.root);let Z=ae=>{let ie=q.original(ae);ie&&(l.liveToClone.set(ie,ae),l.cloneToLive.set(ae,ie));for(let he of Array.from(ae.childNodes||[]))Z(he)};Z(q.root)}}return D}};return u}var Qt=Mt;function Ar(e){try{return JSON.parse(e)}catch(t){throw new Wn(`Invalid strict JSON: ${t.message}`,t)}}function On(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let s=[],c=0;for(;c<r.length;){let l=r[c];if(/\s/.test(l)){c++;continue}if("{}".includes(l)){s.push({type:l,value:l}),c++;continue}if(l==="["){let g=!1,m=c+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(g=!0),!g){s.push({type:l,value:l}),c++;continue}}if(l==="]"){s.push({type:l,value:l}),c++;continue}if(l===":"){s.push({type:t.COLON,value:l}),c++;continue}if(l===","){s.push({type:t.COMMA,value:l}),c++;continue}if(l==='"'||l==="'"){let g=l,m=c+1;for(;m<r.length&&r[m]!==g;)r[m]==="\\"&&m++,m++;s.push({type:t.STRING,value:r.substring(c+1,m),quoted:!0,sourceQuote:g}),c=m+1;continue}let a=c,b;for(;a<r.length&&!/[{},]/.test(r[a]);)if(r[a]===":"){let g=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let u of g){let h=u.substring(1);if(r.substring(a+1,a+1+h.length)===h){m=!0,a+=h.length;break}}if(!m)break}else if(r[a]==="["){for(a++;a<r.length&&r[a]!=="]";){if(r[a]==='"'||r[a]==="'"){let g=r[a];for(a++;a<r.length&&r[a]!==g;)r[a]==="\\"&&a++,a++}a++}a<r.length&&r[a]==="]"&&a++}else a++;b=r.substring(c,a);let p=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(b)?p=t.NUMBER:b==="true"||b==="false"||b==="null"?p=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(b)&&(p=t.SELECTOR),s.push({type:p,value:b,quoted:!1}),c=a}return s}function o(r){let s="";for(let c=0;c<r.length;c++){let l=r[c];if("{}".includes(l.type)||"[]".includes(l.type)){s+=l.value;continue}if(l.type===t.COLON){s+=l.value;continue}if(l.type===t.COMMA){let a=r[c+1];if(a&&(a.type==="}"||a.type==="]"))continue;s+=l.value;continue}if(l.type===t.STRING&&l.quoted){let a=l.value;l.sourceQuote==="'"&&(a=a.replace(/\\'/g,"'"),a=a.replace(/(\\*)"/g,(b,p)=>p.length%2===0?p+'\\"':b)),s+=`"${a}"`;continue}if(l.type===t.NUMBER||l.type===t.BOOLEAN){s+=l.value;continue}if(l.type===t.SELECTOR||l.type===t.IDENTIFIER){s+=`"${l.value}"`;continue}s+=`"${l.value}"`}return s}try{let r=n(e),s=o(r);return JSON.parse(s)}catch(r){throw new Wn("Invalid extraction rules syntax: "+r.message,r)}}var xr="1",Ps=/^[a-zA-Z0-9_-]+$/;function Fn(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Ps.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Ps})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=r[0],c=e.attr(s,"data-rules-version");if(c!==xr)throw new Tn(c);return{rules:On(e.text(s)),tagNode:s}}var Ic="script[data-rules-name]";function Hs(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function ao(e,t){let n=e.find(t,Ic,{includeRulesTag:!0}),o=new Set,r=[];for(let s of n){let c=Hs(e.attr(s,"data-rules-name"));if(!c)continue;if(o.has(c)){console.warn(`hyper-html-api: duplicate rules tag name "${c}"; using the first.`);continue}let l=e.attr(s,"data-rules-version");if(l!==xr)throw new Tn(l);o.add(c),r.push({name:c,rules:On(e.text(s))})}return r}function Ho(e,t){let n={};for(let{name:o,rules:r}of ao(e,t))n[o]=ln(e,t,r);return n}function Tr(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Ho(Qt,t),version:cn(n,"hyper-version")}}var Vn=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},fo=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},bn=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},uo=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var Ds="text/hyper-upgrade";function Sr(e,t){let n=e.find(t,`script[type="${Ds}"]`);if(n.length===0)return null;if(n.length>1)throw new uo(n.length);return e.text(n[0])||null}var Ec=new Function("url","return import(url)");async function Nr(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Ec(n)}catch(r){throw new bn(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new bn("transform must `export default` a function");return o.default}function _s(e,t,n,o){let r=e.length,s=t.length,c=new Array(r).fill(-1);if(o){let S=new Set;for(let v=0;v<r;v++){let D=o[v];!(D>=0&&D<s)||S.has(D)||(c[v]=D,S.add(D))}}if(r===0||s===0)return c;let l=e.map(S=>js(S,n)),a=t.map(S=>js(S,n)),b=new Array(s).fill(!1);for(let S of c)S>=0&&(b[S]=!0);let p=new Map;a.forEach((S,v)=>{b[v]||p.set(S,p.has(S)?-1:v)});let g=new Map;l.forEach((S,v)=>{c[v]>=0||g.set(S,(g.get(S)||0)+1)}),l.forEach((S,v)=>{if(c[v]>=0||g.get(S)!==1)return;let D=p.get(S);D===void 0||D===-1||b[D]||(c[v]=D,b[D]=!0)});let m=[];for(let S=0;S<r;S++)c[S]<0&&m.push(S);let u=[];for(let S=0;S<s;S++)b[S]||u.push(S);if(m.length===0||u.length===0)return c;let h=r*s+1,y=(S,v)=>Cc(e[S],t[v],n)*h+Math.abs(S-v);for(let[S,v]of Lc(m,u,y))c[S]=v;return c}var Us=e=>typeof e=="object"&&e!==null;function js(e,t){if(!Us(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function Cc(e,t,n){if(!Us(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let s of o){let c=JSON.stringify(e?.[s]),l=JSON.stringify(t?.[s]);c!==l&&r++}return r}function Lc(e,t,n){return e.length<=t.length?Bs(e,t,n,!1):Bs(t,e,(o,r)=>n(r,o),!0)}function Bs(e,t,n,o){let r=e.length,s=t.length,c=[];for(let g=0;g<=r;g++)c.push(new Float64Array(s+1).fill(1/0));let l=[];for(let g=0;g<=r;g++)l.push(new Uint8Array(s+1));for(let g=0;g<=s;g++)c[r][g]=0;for(let g=r-1;g>=0;g--)for(let m=s-1;m>=0;m--){let u=n(e[g],t[m])+c[g+1][m+1],h=c[g][m+1];u<=h?(c[g][m]=u,l[g][m]=1):c[g][m]=h}let a=[],b=0,p=0;for(;b<r&&p<s;)l[b][p]&&(a.push(o?[t[p],e[b]]:[e[b],t[p]]),b++),p++;return a}function Mr(e,t,n,o,r,s,c,l={}){let a=e.find(t,n,l);if(r.length===0){a.forEach(ae=>e.remove(ae)),Or(l,"onRowsApplied",s.path,[]);return}let b=r.length>a.length,p=a[0]||null;if(b&&!p&&(p=Dc(e,t,n,l),!p))throw new so(s.path);let g=a.map(ae=>Hc(e,ae,o,l)),m=null;if(b&&p){m=e.clone(p),l.templateAttr&&e.removeAttr(m,l.templateAttr);let ae=e.stripIds(m);ae>0&&console.warn(`[hyper-html-api] stripped ${ae} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let u=_s(r,g,o,Rc(e,a,r,s,l)),h=a[0]||p,y=e.parent(h),S=a.length>0?Ws(e,y,h):0,v=jc(e,a),D=new Set,q=[],Z=r.map((ae,ie)=>{let he=u[ie];if(he>=0)return D.add(he),q.push(!1),a[he];q.push(!0);let K=e.clone(m);return e.stripIds(K),K});a.forEach((ae,ie)=>{D.has(ie)||e.remove(ae)}),v?Z.forEach((ae,ie)=>{let he=S+ie;e.children(y).findIndex(ye=>e.sameNode(ye,ae))!==he&&e.insertAt(y,ae,he)}):Bc(e,Z,q,y,S),Pc(e,Z,o,r,s,c,l),Or(l,"onRowsApplied",s.path,Z)}function Or(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function Rc(e,t,n,o,r){let s=Or(r,"identifyRows",o.path,n);if(!Array.isArray(s))return null;let c=new Array(n.length).fill(-1),l=new Set;for(let a=0;a<n.length;a++)if(s[a]){for(let b=0;b<t.length;b++)if(!(l.has(b)||!e.sameNode(t[b],s[a]))){c[a]=b,l.add(b);break}}return c}function Pc(e,t,n,o,r,s,c){t.forEach((l,a)=>{if(n===null){let b=o[a],p=b==null?"":String(b);e.text(l)!==p&&e.text(l,p)}else{let b=s(e,l,n,o[a],{depth:r.depth+1,path:[...r.path,a]},c);b&&b!==l&&(t[a]=b)}})}function Hc(e,t,n,o){return n===null?e.text(t):ln(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Ws(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Dc(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let s=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of s)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}function jc(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let s of t){let c=o.findIndex(l=>e.sameNode(l,s));if(c===-1)return!1;r.push(c)}return r.sort((s,c)=>s-c),r[r.length-1]-r[0]===r.length-1}function Bc(e,t,n,o,r){let s=null,c=r;for(let l=0;l<t.length;l++){if(!n[l]){s=t[l];continue}let a=s?e.parent(s):o;if(!a)continue;let b=s?Ws(e,a,s)+1:c++;e.insertAt(a,t[l],b),s=t[l]}}var $s=new Set(["checked","selected","disabled","readOnly","paused"]);function yn(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(vr(n,o,[],s),s.length)throw new ro(s);Do(e,t,n,o,{depth:0,path:[]},r)}function Do(e,t,n,o,r,s={}){if(r.depth>$n)throw new Sn(r.path);if(o===void 0)return t;if(typeof n=="string")return _c(e,t,n,o,r,s);if(Array.isArray(n)){let[c,l]=n;return Mr(e,t,c,l,o,r,Do,s),t}if(typeof n=="object"&&n!==null){for(let[c,l]of Object.entries(n)){let a=Do(e,t,l,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},s);a&&a!==t&&(t=a)}return t}return t}function _c(e,t,n,o,r,s){if(n.endsWith("[]")){let a=n.slice(0,-2);return Mr(e,t,a,null,o,r,Do,s),t}if(n.startsWith("@"))return Vs(e,t,n.slice(1),o);let c=dn(n);if(c!==-1){let a=n.slice(0,c),b=n.slice(c+1),p=a?e.find(t,a,s):[t];return p.length===0||Vs(e,p[0],b,o),t}if(n===".")return Fs(e,t,o),t;let l=e.find(t,n,s);return l.length===0||Fs(e,l[0],o),t}function Fs(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Vs(e,t,n,o){if(gr.has(n)){let s=e.prop(t,n);if(s===o||s!=null&&o!=null&&String(s)===String(o))return t;throw new io(n)}if(n==="outerHTML"){let s=o==null?"":String(o);return e.replaceWith(t,s)}if(Ss.has(n)){let s=Uc(n,o);return e.prop(t,n)!==s&&e.prop(t,n,s),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function Uc(e,t){return t==null?$s.has(e)?!1:"":$s.has(e)?t==="false"?!1:!!t:t}function vr(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,s)=>{typeof r=="object"&&r!==null&&o.push({path:po([...n,s]),expected:"scalar",got:ho(r)})}):o.push({path:po(n),expected:"array",got:ho(t)});return}t!==null&&typeof t=="object"&&o.push({path:po(n),expected:"scalar",got:ho(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:po(n),expected:"array",got:ho(t)});return}let r=e[1];t.forEach((s,c)=>vr(r,s,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:po(n),expected:"object",got:ho(t)});return}for(let[r,s]of Object.entries(e))vr(s,t[r],[...n,r],o)}}}function ho(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function po(e){return e.join(".")}function mo(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Ir(t,e,n);return Er(t,e,n),{data:o,summary:n}}function Ir(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>Ir(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,s]of Object.entries(e)){let c=Ir(s,t?.[r],n);c!==void 0&&(o[r]=c)}return o}}function Er(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?Er(e[r],t[r],n):n.discarded+=Mn(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Er(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=Mn(t))}}function Mn(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Mn(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Mn(n),0):1}function Cr(e,t,n){let o=ao(e,t),r={carriedOver:0,discarded:0,listItems:0},s={},c=new Set;for(let{name:l,rules:a}of o){if(c.add(l),!Object.prototype.hasOwnProperty.call(n,l)){s[l]={carriedOver:0,discarded:0,listItems:0};continue}let{data:b,summary:p}=mo(n[l],a);yn(e,t,a,b),s[l]=p,r.carriedOver+=p.carriedOver,r.discarded+=p.discarded,r.listItems+=p.listItems}for(let l of Object.keys(n))c.has(l)||(r.discarded+=Mn(n[l]));return{totals:r,byName:s,rulesTagCount:o.length}}async function Lr({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:s}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),s=s||(v=>fetch(v)),!o)throw new Error("upgrade.run requires a document context");if(e=e||cn(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let c=new URL(e,r?r.href:void 0);n=n!==void 0?n:cn(o,"hyper-version"),t=t||Ho(Qt,o);let l;try{l=await s(c.href)}catch(v){throw new Vn(c.href,v)}if(!l.ok)throw new Vn(c.href,new Error(`HTTP ${l.status}`));let a=await l.text(),b=new DOMParser().parseFromString(a,"text/html"),p=cn(b,"hyper-version"),g=t,m=!1,u=Sr(Qt,b);if(u){let D=await(await Nr(u))(g,{fromVersion:n,toVersion:p});if(!D||typeof D!="object"||Array.isArray(D))throw new bn("transform must return a plain object map of { rulesName: data }");g=D,m=!0}let{totals:h,byName:y,rulesTagCount:S}=Cr(Qt,b,g);if(S===0&&Object.keys(g).length>0)throw new fo(c.href);return{html:Wc(b),fromVersion:n,toVersion:p,summary:{transformApplied:m,totals:h,byName:y}}}function Wc(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
5
|
-
`+e.documentElement.outerHTML}var Fc=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...vs],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function Rr(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return Fn(e,o,n)}return null}var go={extract:(e,t,n={})=>ln(Nn(e,n),e,t,n),apply:(e,t,n,o={})=>yn(Nn(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>Fn(Qt,e,t),findRules:(e,t)=>Rr(Qt,e,t),bind:(e,t,n={})=>{let o=Rr(Qt,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>ln(Nn(e,n),e,o.rules,n),set:r=>yn(Nn(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:Ar,parseRelaxed:On,ruleAttrIndex:dn,splitRule:Cn,errors:Po,DOM_PROPERTIES:Lo},Pr=e=>!!e&&typeof e.nodeType=="number";function zs(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=Qt.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return Fn(Qt,t).rules}function Hr(e,t){let n=Pr(e)?e:document,o=Pr(e)?t:e;return o===void 0?ln(Nn(n),n,zs(n)):go.bind(n,o).get()}function Dr(e,t,n){if(!Pr(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?yn(Nn(e),e,zs(e),t):go.bind(e,n).set(t),e}var qs={buildForm:Uo,bindFormEvents:Wo,scaffold:En,morphForm:dr,path:To},Ks={checkForUpdate:pr,run:Lr,extractAll:Tr,shapeMatch:mo};var zc={engine:go,cms:qs,upgrade:Ks,extractData:Hr,applyData:Dr},qc=zc;return ti(Kc);})();
|
|
1
|
+
var HyperHtmlApi=(()=>{var ir=Object.defineProperty;var Ii=Object.getOwnPropertyDescriptor;var Ci=Object.getOwnPropertyNames;var Li=Object.prototype.hasOwnProperty;var cr=(e,t)=>{for(var n in t)ir(e,n,{get:t[n],enumerable:!0})},Ri=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ci(t))!Li.call(e,r)&&r!==n&&ir(e,r,{get:()=>t[r],enumerable:!(o=Ii(t,r))||o.enumerable});return e};var Pi=e=>Ri(ir({},"__esModule",{value:!0}),e);var El={};cr(El,{applyData:()=>us,cms:()=>Mi,default:()=>Ml,engine:()=>Bo,extractData:()=>fs,upgrade:()=>Ei});var $o={};cr($o,{fromString:()=>Wo,getRuleAtPath:()=>lr,getValueAtPath:()=>ko,parseConfigKey:()=>Di,setAtPath:()=>Pn,toConfigKey:()=>ji,toString:()=>hn});function hn(e){return e.map(String).join(".")}function ji(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function Di(e){return e===""?[]:e.split(".")}function Wo(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function lr(e,t){let n=e;for(let o of t){if(n==null||typeof n=="string")return;if(Array.isArray(n)){if(typeof o!="number"&&o!=="*")return;n=n[1];continue}if(typeof n=="object"){if(typeof o=="number"||!(o in n))return;n=n[o];continue}return}return n}function ko(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function Pn(e,t,n){if(t.length===0)return n;let[o,...r]=t;if(typeof o=="number"){let i=Array.isArray(e)?[...e]:[];return i[o]=Pn(i[o],r,n),i}return{...e&&typeof e=="object"?e:{},[o]:Pn((e||{})[o],r,n)}}function eo(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[n,o]of Object.entries(e))t[n]=eo(o);return t}return""}var qo=new WeakMap;function Mn(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function to(e){let t=Mn(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}var Hi=new Set(["checked","selected","disabled","readOnly","paused"]);function ar({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(ur({rule:e,value:t,path:[],ctx:i})),r}function fr(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),hs.set(e,{rules:t,getData:n,onChange:o}),Bi()}var hs=new WeakMap,ds=!1;function Bi(){ds||(document.addEventListener("input",ps,!0),document.addEventListener("change",ps,!0),document.addEventListener("click",Ui,!0),ds=!0)}function ms(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&hs.get(t)||null}function Ui(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=ms(t);if(!n)return;let{rules:o,getData:r,onChange:i}=n,c=t.getAttribute("data-hha-action"),s=Wo(t.getAttribute("data-hha-path")||"");if(c==="scalar-array-add"){let a=ko(r(),s)||[];i(Pn(r(),s,[...a,""]),{structural:!0});return}if(c==="object-array-add"){let a=lr(o,s);if(!Array.isArray(a))return;let m=ko(r(),s)||[];i(Pn(r(),s,[...m,eo(a[1])]),{structural:!0});return}if(c==="array-remove"){if(s.length===0)return;let a=s.slice(0,-1),m=s[s.length-1],h=ko(r(),a)||[];if(typeof m!="number")return;let d=h.filter((b,A)=>A!==m);i(Pn(r(),a,d),{structural:!0})}}function ps(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=ms(t);if(!n)return;let{getData:o,onChange:r}=n,i=t.closest("[data-hha-path]");if(!i)return;let c=Wo(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;r(Pn(o(),c,s),{structural:!1})}function ur({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?Wi({rule:e,value:t,path:n,ctx:o}):Vi({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return $i({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return _i({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function _i({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",hn(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=Fo(n[n.length-1]),r.appendChild(i)}for(let[i,c]of Object.entries(e)){let s=[...n,i],a=t?.[i];r.appendChild(ur({rule:c,value:a,path:s,ctx:o}))}return r}function Vi({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",hn(n));let i=document.createElement("div");i.className="field-body";let c=document.createElement("label");c.className="field-label",c.textContent=Fo(n[n.length-1]||".")+Gi(e);let s=Fi(e,o.appRoot),a=qi(s,{value:t,rule:e,path:n,appRoot:o.appRoot}),m=a.el;return m.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(c),i.appendChild(m),r.appendChild(i),qo.set(r,a),r}function Wi({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",hn(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=Fo(n[n.length-1]),r.appendChild(i);let c=Array.isArray(t)?t:[],s=document.createElement("div");r.appendChild(s),c.forEach((m,h)=>{let d=[...n,h],b=document.createElement("div");b.className="scalar-array-row",b.setAttribute("data-hha-path",hn(d));let A=document.createElement("input");A.type="text",A.className="field-input",A.value=m==null?"":String(m);let S=document.createElement("button");S.type="button",S.className="array-remove",S.textContent="\xD7",S.title="remove",S.setAttribute("data-hha-action","array-remove"),S.setAttribute("data-hha-path",hn(d)),b.appendChild(A),b.appendChild(S),s.appendChild(b)});let a=document.createElement("button");return a.type="button",a.className="array-add",a.textContent="+ add",a.setAttribute("data-hha-action","scalar-array-add"),a.setAttribute("data-hha-path",hn(n)),r.appendChild(a),r}function $i({rule:e,value:t,path:n,ctx:o}){let[,r]=e,i=Array.isArray(t)?t:[],c=document.createElement("div");c.className="form-section",c.setAttribute("data-hha-path",hn(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=Fo(n[n.length-1]),c.appendChild(s),i.forEach((m,h)=>{let d=[...n,h],b=document.createElement("div");b.className="array-card",b.setAttribute("data-hha-path",hn(d));let A=document.createElement("button");A.type="button",A.className="array-remove",A.textContent="\xD7",A.title="remove item",A.setAttribute("data-hha-action","array-remove"),A.setAttribute("data-hha-path",hn(d)),b.appendChild(A);let S=ur({rule:r,value:m,path:d,ctx:o});S.querySelector(".form-section-label")?.remove(),b.appendChild(S),c.appendChild(b)});let a=document.createElement("button");return a.type="button",a.className="array-add",a.textContent="+ add",a.setAttribute("data-hha-action","object-array-add"),a.setAttribute("data-hha-path",hn(n)),c.appendChild(a),c}function qi(e,t){let n=zi(e);if(e.type==="select"&&e.options)for(let o of e.options){let r=document.createElement("option");r.value=o.value,r.textContent=o.text,String(t.value)===o.value&&(r.selected=!0),n.appendChild(r)}else e.type==="checkbox"?n.checked=t.value===!0||t.value==="true"||t.value==="checked":(e.type,n.value=t.value==null?"":String(t.value));return{el:n,destroy(){},focus(){n.focus()},validate(){}}}function Fi(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):n=to(e).prop,n&&Hi.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=Ki(e,t);if(!o)return{type:"text"};let r=(o.tagName||"").toLowerCase();if(r==="textarea")return{type:"textarea"};if(r==="select")return{type:"select",options:Array.from(o.querySelectorAll("option")).map(s=>({value:s.getAttribute("value")||s.textContent,text:s.textContent.trim()||s.getAttribute("value")||""}))};if(r==="input"){let c=(o.getAttribute("type")||"text").toLowerCase();if(c==="checkbox"||c==="radio")return{type:"checkbox"};if(c==="number")return{type:"number"}}let i=(o.textContent||"").trim();return i.length>60||i.includes(`
|
|
2
|
+
`)?{type:"textarea"}:{type:"text"}}function Ki(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=to(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function zi(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function Fo(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function Gi(e){return` \xB7 ${e}`}function Ko(e,t){if(typeof e=="string"){let n=t&&t.defaultView,o=n&&n.DOMParser||globalThis.DOMParser;return new o().parseFromString(e,"text/html")}if(e&&e.nodeType===9)return e;throw new TypeError("expected an HTML string or a Document")}function dr(e){let t=new Map;return(n,o)=>{if(typeof o!="string")return Ko(o,e);let r=t.get(n);if(r&&r.text===o)return r.doc;let i=Ko(o,e);return t.set(n,{text:o,doc:i}),i}}function gs(e,t){let n=t.doctype;if(!n)return!1;let o=e.doctype;if(o&&o.name===n.name&&o.publicId===n.publicId&&o.systemId===n.systemId)return!1;let r=e.implementation.createDocumentType(n.name,n.publicId,n.systemId);return o?e.replaceChild(r,o):e.insertBefore(r,e.documentElement),!0}var pr=()=>!1;function hr(e,t=[]){if(typeof e!="function")return pr;let n=new WeakMap,o=new Set(t);return r=>{if(!r||r.nodeType!==1)return!1;let i=n.get(r);if(i!==void 0)return i;let c=[],s=r,a=!1;for(;s&&s.nodeType===1;){let m=n.get(s);if(m!==void 0){a=m;break}if(c.push(s),e(s,o.has(s))){a=!0;break}if(o.has(s))break;s=s.parentElement}for(let m of c)n.set(m,a);return a}}var Vl=Object.freeze(["root-tag","equal","root-attrs","root-level","not-in-body","ignored-ancestor","remote-wins-ancestor","form-ancestor","script-or-template","no-live-twin","live-detached","ancestor-live","sibling-live","outside-id-changed","chain-unpaired"]);function jn(){return{lazyTwins:0,hashRejected:0,similarTiesStrict:0,similarTiesLoose:0,ambiguousMoves:0,certificationPairs:0,certificationVisited:0,fastPathAttempted:0,fastPathTaken:0,fastPathFallback:null}}var Yi="~",bs="^";function mr(e,t){let n=new WeakMap;if(!e||!t||typeof t!="object"||Array.isArray(t))return n;let o=t[Yi],r=typeof o=="string"?o.split(",").map(Number):null,i=r&&typeof t[bs]=="string"?t[bs].split(","):null,c=d=>Number.isInteger(d)&&d>=0,s=0,a=!1,m=d=>{let b=d;for(;b>0;){let A=r[s++];if(s>r.length||!c(A))return!1;b+=A-1}return!0},h=(d,b)=>{if(a)return;if(r){let L=s++,f=r[L];if(L>=r.length||!c(f)){a=!0;return}let g=!i||i[L]===d.tagName.toLowerCase();if(!g||f!==d.children.length){let x=g&&t[b];typeof x=="string"&&x&&n.set(d,x),m(f)||(a=!0);return}}let A=t[b];typeof A=="string"&&A&&n.set(d,A);let S=d.children;for(let L=0;L<S.length;L++)h(S[L],b===""?String(L):`${b}.${L}`)};return h(e,""),n}function ys(e){return t=>{for(let n of e){let o=n(t);if(typeof o=="string"&&o!=="")return o}return null}}var fn=ys([e=>e.getAttribute("data-id"),e=>e.getAttribute("id")]);function zo(e,t,n,o=null){let r=new Map,i=new Set,c=s=>{if(n(s))return;let a=t(s);a&&(r.has(a)?i.add(a):r.set(a,s))};if(o){let s=a=>{for(let m of a.querySelectorAll(o))c(m);for(let m of a.querySelectorAll("template"))m.content&&s(m.content)};c(e),s(e.tagName==="TEMPLATE"&&e.content?e.content:e)}else{let s=a=>{c(a);let m=a.tagName==="TEMPLATE"&&a.content?a.content.children:a.children;for(let h=0;h<m.length;h++)s(m[h])};s(e)}for(let s of i)r.delete(s),gr(s);return r}function gr(e){e.startsWith("merge:")&&console.warn(`[hyper-morph] merge disabled for duplicate identity "${e.slice(e.indexOf(":",6)+1)}"`)}var Ji=new Set(["href","src","name","type","role"]),ws=new Set(["SCRIPT","STYLE","TEXTAREA","TEMPLATE","IFRAME","OBJECT","CANVAS","VIDEO","AUDIO","svg","SVG"]);function no(e,t=5381){let n=t;for(let o=0;o<e.length;o++)n=(n<<5)+n^e.charCodeAt(o);return n>>>0}function ks(e){return e.replace(/\s+/g," ")}var Xi=0;function xs({ignored:e=()=>!1,ignoreAttribute:t=()=>!1,stats:n=null}={}){let o=new WeakMap,r=new WeakMap;function i(q){let z=q.attributes,ce=z.length;if(ce===0)return{all:"",sig:q.tagName+"|"};let xe=[],te="",J=[];for(let Ce=0;Ce<ce;Ce++){let we=z[Ce],ne=we.name;t(q,ne)||xe.push(ne+"="+we.value),ne==="class"?te=we.value.indexOf(" ")<0?we.value:we.value.split(/\s+/).filter(Boolean).sort().join(" "):Ji.has(ne)&&J.push(ne+"="+we.value)}return xe.length>1&&xe.sort(),J.length>1&&J.sort(),{all:xe.join(""),sig:q.tagName+"|"+te+(J.length?"|"+J.join("|"):"")}}function c(q){return q.nodeType===1&&q.tagName==="TEMPLATE"&&q.content?q.content.childNodes:q.childNodes}function s(q){let z=o.get(q);if(z)return z;if(q.nodeType===3)z={hash:"T"+no(q.nodeValue),hint:ks(q.nodeValue).slice(0,64),sig:null,tok:null};else if(q.nodeType===8)z={hash:"C"+no(q.nodeValue),hint:"",sig:null,tok:null};else if(q.nodeType===1){let ce=i(q),xe=no(q.tagName+""+ce.all),te="";for(let J of m(q))if(J.nodeType===1){let Ce=s(J);xe=no(Ce.hash,xe),te.length<64&&(te+=" "+Ce.hint)}else xe=no(h(J),xe),J.kind==="text"&&te.length<64&&(te+=J.value.slice(0,64));z={hash:"E"+xe,hint:ks(te).trim().slice(0,64),sig:ce.sig,tok:null}}else z={hash:"N"+q.nodeType,hint:"",sig:null,tok:null};return o.set(q,z),z}function a(q){if(!q.tok){q.tok=new Set;for(let z of q.hint.toLowerCase().split(/[^\p{L}\p{N}]+/u))z&&q.tok.add(z)}return q.tok}function m(q){let z=r.get(q);if(z)return z;z=[];let ce=null,xe=()=>{ce&&(ce.value=ce.nodes.map(te=>te.nodeValue).join(""),z.push(ce),ce=null)};for(let te of c(q)){if(te.nodeType===3){ce||(ce={kind:"text",nodes:[],value:"",parent:q,hash:void 0}),ce.nodes.push(te);continue}xe(),te.nodeType===8?z.push({kind:"comment",nodes:[te],value:te.nodeValue,parent:q,hash:void 0}):te.nodeType===1&&!e(te)&&z.push(te)}return xe(),r.set(q,z),z}function h(q){return q.nodeType===1?s(q).hash:(q.hash===void 0&&(q.hash=(q.kind==="text"?"T":"C")+no(q.value)),q.hash)}function d(q,z){let ce=a(s(q)),xe=a(s(z));if(ce.size===0&&xe.size===0)return{coef:1,share:1};if(ce.size===0||xe.size===0)return null;let te=0;for(let J of ce)xe.has(J)&&te++;return{coef:te/Math.min(ce.size,xe.size),share:te/Math.max(ce.size,xe.size)}}function b(q,z){let ce=d(q,z);return!!ce&&ce.coef>=.5}let A=new WeakMap;function S(q){let z=A.get(q);if(z)return z;z=[];for(let ce of q.attributes)t(q,ce.name)||z.push([ce.namespaceURI||"",ce.localName,ce.value]);return z.sort((ce,xe)=>ce[0]<xe[0]?-1:ce[0]>xe[0]?1:ce[1]<xe[1]?-1:ce[1]>xe[1]?1:0),A.set(q,z),z}let L=new WeakMap;function f(q,z){if(q===z)return!0;if(h(q)!==h(z))return!1;let ce=L.get(q);if(ce&&ce.has(z))return ce.get(z);let xe=L.get(z);if(xe&&xe.has(q))return xe.get(q);let te=g(q,z),J=te===!0;return te===!1&&n&&n.hashRejected++,ce||L.set(q,ce=new WeakMap),ce.set(z,J),J}function g(q,z){if(q.nodeType===1){if(z.nodeType!==1||q.tagName!==z.tagName||q.namespaceURI!==z.namespaceURI)return!1;let ce=S(q),xe=S(z);if(ce.length!==xe.length)return!1;for(let Ce=0;Ce<ce.length;Ce++)if(ce[Ce][0]!==xe[Ce][0]||ce[Ce][1]!==xe[Ce][1]||ce[Ce][2]!==xe[Ce][2])return!1;let te=m(q),J=m(z);if(te.length!==J.length)return!1;for(let Ce=0;Ce<te.length;Ce++){if(h(te[Ce])!==h(J[Ce]))return!1;if(!f(te[Ce],J[Ce]))return Xi}return!0}return z.nodeType===1?!1:q.kind===z.kind&&q.value===z.value}let x=new WeakMap,Q=new Map,se=0;function le(q){let z=x.get(q);if(z)return z;let ce=h(q),xe=Q.get(ce);xe||Q.set(ce,xe=[]);let te=xe.find(J=>f(J.unit,q));return z=te?te.key:"K"+se++,te||xe.push({unit:q,key:z}),x.set(q,z),z}return{meta:s,unitsOf:m,unitHash:h,similar:b,score:d,childrenOf:c,equalUnits:f,exactUnitKey:le,ignored:e}}var Ts=16,Qi=2e3,Zi=3,br={align:0,certifyVisited:0,certifyScheduled:0};function yr(e,t,n){let{meta:o,unitsOf:r,unitHash:i,similar:c,score:s,childrenOf:a,equalUnits:m,ignored:h}=n.analyzer,d=n.baseId||(()=>null),b=n.sideId||(()=>null),A=n.stats||null,S=A?new Set:null,L=A?new Set:null,f=new Map,g=new Map,x=new Set,Q=new Map,se=new Set,le=new Set,q=new Set,z=[],ce=[],xe=[],te=[],J=Qi,Ce=new Map,we=new Map,ne=(p,k)=>{f.set(p,k),g.set(k,p)},_=new Set,ye=new Set,ge=null,Oe=p=>{let k=p.nodeType?p.parentNode:p.parent;if(!k||k.nodeType!==11)return k;if(!ge){ge=new WeakMap;let R=$=>{for(let H of $.querySelectorAll("template"))H.content&&(ge.set(H.content,H),R(H.content))};for(let $ of[e,t])R($.tagName==="TEMPLATE"&&$.content?$.content:$)}return ge.get(k)||null},Be=(p,k)=>{for(let R=Oe(p);R&&!_.has(R);R=Oe(R))_.add(R);for(let R=Oe(k);R&&!ye.has(R);R=Oe(R))ye.add(R)},We=p=>{for(let k=Oe(p);k;k=Oe(k))if(f.has(k))return le.has(k);return!1},rt=p=>{for(let k=Oe(p);k;k=Oe(k)){let R=g.get(k);if(R!==void 0)return le.has(R)}return!1},re=p=>!!p&&p.nodeType===1,ut=(p,k)=>{let R=Q.get(p);return!!R&&R.has(k)},dt=p=>ws.has(p.tagName),Se=n.comparisons||n.scope,O=(p,k)=>{if(Se){if(Se.same.get(p)===k)return!0;if(Se.differ.get(p)===k)return!1}if(!p.isEqualNode(k))return!1;if(p.tagName==="TEMPLATE")return m(p,k);let R=p.getElementsByTagName("template");if(R.length===0)return!0;let $=k.getElementsByTagName("template");if(R.length!==$.length)return!1;for(let H=0;H<R.length;H++)if(!m(R[H],$[H]))return!1;return!0},B=(p,k)=>{let R=d(p);if(!R)return!0;let $=b(k);return!$||R===$},ae=globalThis.__hyperMorphProfile,be=ae?performance.now():0;ae&&!n.scope&&(o(e),o(t),ae.meta=(ae.meta||0)+(performance.now()-be),be=performance.now()),ne(e,t);let de=new Set;for(let[p,k]of n.baseIndex){let R=n.sideIndex.get(p);R&&R.tagName===k.tagName&&!f.has(k)&&!g.has(R)&&(ne(k,R),Be(k,R),de.add(k))}if(de.size){let p=[];if(n.scope)for(let H of n.scope.chain)de.has(H)&&p.push(H);let k=[n.scope?n.scope.root:e];for(;k.length;){let H=k.pop();de.has(H)&&p.push(H);let F=a(H);for(let N=F.length-1;N>=0;N--)F[N].nodeType===1&&k.push(F[N])}let R=new Set;for(let H=p.length-1;H>=0;H--){let F=p[H];n.scope&&n.scope.onChain.has(F)?R.add(F):Xt(F,f.get(F),R)?(le.add(F),q.add(F),A&&A.certificationPairs++):R.add(F)}let $=new Set;for(let H of p)le.has(H)&&!$.has(H)&&ze(H,$)}n.scope&&n.scope.head&&Bt(n.scope.head[0],n.scope.head[1]);function ze(p,k){let R=[p];for(;R.length;){let $=R.pop();if(!k.has($)){k.add($),M($);for(let H of r($))re(H)&&f.has(H)&&R.push(H)}}}te.push([e,t]);for(let[p,k]of f)re(p)&&p!==e&&te.push([p,k]);return wt(),De(),ae&&(ae.align=(ae.align||0)+(performance.now()-be)),{map:f,reverse:g,moved:se,identical:le,pairIdenticalChildren:M,weak:x,unpair:Qe,rematch:De,insertedByHash:st,refused:L,identityPaired:de};function De(){P(),wt();for(let p=0;p<xe.length;){let k=xe.length;nn(p,k),p=k,wt(),P(),wt()}}function Qe(p){let k=f.get(p);if(!k)return;Q.has(p)||Q.set(p,new Set),Q.get(p).add(k);let R=(H,F)=>{f.delete(H),g.delete(F),se.delete(H),le.delete(H),x.delete(H),q.delete(H)},$=(H,F)=>{for(let N of r(H)){let E=f.get(N);!E||de.has(N)||!(re(E)?F.contains(E):F.contains(E.nodes[0]))||(R(N,E),re(N)&&$(N,E))}};R(p,k),re(p)&&$(p,k),z.push(p),ce.push(k)}function st(){let p=new Map;for(let k of new Set(ce)){if(g.has(k))continue;let R=o(k).hash;p.has(R)||p.set(R,[]),p.get(R).push(k)}return p}function wt(){for(;te.length;){let[p,k]=te.shift();f.get(p)!==k||q.has(p)||le.has(p)||Tt(p,k)}}function bt(p,k){if(!dt(p))for(let R of r(p))re(R)&&(k.push(R),bt(R,k))}function Tt(p,k){q.add(p);let R=r(p),$=r(k);br.align+=R.length+$.length,Ce=new Map,we=new Map;for(let G=0;G<R.length;G++)Ce.set(R[G],G);for(let G=0;G<$.length;G++)we.set($[G],G);if(p.tagName==="HTML")for(let G of["HEAD","BODY"]){let he=R.find(u=>re(u)&&u.tagName===G),ve=$.find(u=>re(u)&&u.tagName===G);he&&ve&&!f.has(he)&&!g.has(ve)&&ne(he,ve)}for(let G=0;G<R.length&&G<$.length;G++){let he=R[G],ve=$[G];f.has(he)||g.has(ve)||(re(he)?re(ve)&&he.tagName===ve.tagName&&O(he,ve)&&Bt(he,ve):!re(ve)&&he.kind===ve.kind&&he.value===ve.value&&Bt(he,ve))}T(R,$);let H=R.filter(G=>!f.has(G)),F=$.filter(G=>!g.has(G));H.length&&F.length&&(Qt(H,F),Z(H,F),ee(H,F,R,$),fe(R,$));let N=!1,E=!1;for(let G of R){if(!f.has(G)){re(G)&&(z.push(G),bt(G,z),N=!0);continue}re(G)&&!le.has(G)&&te.push([G,f.get(G)])}for(let G of $)!g.has(G)&&re(G)&&(ce.push(G),bt(G,ce),E=!0);N&&E&&xe.push([p,k])}function nn(p,k){for(let R=p;R<k;R++){let[$,H]=xe[R];if(f.get($)!==H)continue;let F=r($),N=r(H),E=new Map,G=new Map,he=null;for(let ve of F)re(ve)&&(f.has(ve)?he=ve:(E.has(he)||E.set(he,[]),E.get(he).push(ve)));he=null;for(let ve of N)re(ve)&&(g.has(ve)?he=g.get(ve):(G.has(he)||G.set(he,[]),G.get(he).push(ve)));for(let[ve,u]of E){let v=G.get(ve);if(!(!v||u.length!==v.length)&&u.every((j,U)=>v[U].tagName===j.tagName&&B(j,v[U])&&!ut(j,v[U])))for(let j=0;j<u.length;j++)Fe(u[j],v[j])}}}function Fe(p,k){ne(p,k),x.add(p),te.push([p,k]),wt()}function Qt(p,k){let R=oo(p,i),$=oo(k,i),H=new Map;for(let F of k){let N=i(F);$.get(N)===1&&H.set(N,F)}for(let F of p){if(f.has(F))continue;let N=i(F);if(R.get(N)!==1)continue;let E=H.get(N);E&&!g.has(E)&&m(F,E)&&Bt(F,E)}}function Xt(p,k,R){let $=[[p,k]];for(;$.length;){let[H,F]=$.pop();if(br.certifyVisited++,A&&A.certificationVisited++,H.nodeType!==F.nodeType)return!1;if(H.nodeType===3||H.nodeType===8){if(H.nodeValue!==F.nodeValue)return!1;continue}if(H.nodeType!==1){if(!H.isEqualNode(F))return!1;continue}if(H.tagName!==F.tagName||H.namespaceURI!==F.namespaceURI||h(H)!==h(F))return!1;let N=H.attributes,E=F.attributes;if(N.length!==E.length)return!1;for(let v=0;v<N.length;v++){let j=N[v];if(F.getAttributeNS(j.namespaceURI,j.localName)!==j.value)return!1}let G=f.get(H);if(G!==void 0&&G!==F)return!1;let he=g.get(F);if(he!==void 0&&he!==H)return!1;if(H!==p){if(le.has(H))continue;if(R.has(H))return!1}let ve=a(H),u=a(F);if(ve.length!==u.length)return!1;br.certifyScheduled+=ve.length;for(let v=ve.length-1;v>=0;v--)$.push([ve[v],u[v]])}return!0}function Bt(p,k){if(re(p)&&(_.has(p)||ye.has(k))){let R=Lt(p,k);if(!R){ne(p,k),te.push([p,k]);return}for(let $=0;$<R.length;$+=2){let H=R[$],F=R[$+1],N=f.get(H);N!==void 0&&N!==F&&Et(H,N);let E=g.get(F);E!==void 0&&E!==H&&Et(E,F),f.get(H)===F&&(se.delete(H),x.delete(H),le.add(H),q.add(H))}}sn(p,k)}function Et(p,k){f.delete(p),g.delete(k),se.delete(p),le.delete(p),x.delete(p),q.delete(p)}function Lt(p,k){let R=[p,k,!1],$=[];for(;R.length;){let H=R.pop(),F=R.pop(),N=R.pop(),E=f.get(N),G=g.get(F);if(N!==p&&(E!==void 0&&E!==F&&de.has(N)||G!==void 0&&G!==N&&de.has(G)))return null;if(!(E===F&&le.has(N))&&((E!==void 0||G!==void 0)&&$.push(N,F),!!re(N))){if(H||E!==void 0&&E!==F||G!==void 0&&G!==N){let he=r(N),ve=r(F);for(let u=0;u<he.length&&u<ve.length;u++)R.push(he[u],ve[u],!0)}else if(_.has(N)||ye.has(F)){let he=N.tagName==="TEMPLATE"?N.content:N,ve=F.tagName==="TEMPLATE"?F.content:F;for(let u=he.firstElementChild,v=ve.firstElementChild;u&&v;){if(h(u)){u=u.nextElementSibling;continue}if(h(v)){v=v.nextElementSibling;continue}(f.has(u)||g.has(v)||_.has(u)||ye.has(v))&&R.push(u,v,!1),u=u.nextElementSibling,v=v.nextElementSibling}}}}return $}function sn(p,k){ne(p,k),le.add(p),re(p)&&q.add(p)}function M(p){let k=f.get(p);if(!k||!re(p))return;let R=r(p),$=r(k);for(let H=0;H<R.length&&H<$.length;H++)f.has(R[H])||sn(R[H],$[H])}function Z(p,k){let R=N=>re(N)&&!dt(N)?o(N).sig+""+o(N).hint:null,$=oo(p,R),H=oo(k,R),F=new Map;for(let N of k){let E=R(N);E!=null&&H.get(E)===1&&F.set(E,N)}for(let N of p){if(f.has(N))continue;let E=R(N);if(E==null||$.get(E)!==1)continue;let G=F.get(E);G&&!g.has(G)&&B(N,G)&&ne(N,G)}}function ee(p,k,R,$){let H=new Map;for(let N of k){if(!re(N)||g.has(N)||dt(N))continue;let E=o(N).sig;H.has(E)||H.set(E,[]),H.get(E).push({el:N,index:we.get(N)})}let F=[];for(let N of p){if(f.has(N)||!re(N)||dt(N))continue;let E=H.get(o(N).sig);if(!E||!E.length)continue;let G=Ce.get(N),he=E.filter(ve=>!g.has(ve.el)).map(ve=>({c:ve,d:Math.abs(ve.index-G)}));he.sort((ve,u)=>ve.d-u.d),he.length>Ts&&(he=he.slice(0,Ts));for(let{c:ve,d:u}of he){if(!B(N,ve.el))continue;let v=s(N,ve.el);v&&v.coef>=.5&&F.push({b:N,s:ve.el,coef:v.coef,share:v.share,d:u,bi:G})}}if(F.sort((N,E)=>E.coef-N.coef||E.share-N.share||N.d-E.d||N.bi-E.bi),A&&F.length>1){let N=new Map;for(let E of F){let G=N.get(E.b);G?G.coef===E.coef&&(G.share===E.share?G.strict++:G.loose++):N.set(E.b,{coef:E.coef,share:E.share,strict:0,loose:0})}for(let[E,G]of N)S.has(E)||!(G.strict||G.loose)||(S.add(E),G.strict?A.similarTiesStrict++:A.similarTiesLoose++)}for(let N of F)!f.has(N.b)&&!g.has(N.s)&&ne(N.b,N.s)}function ue(p,k){return re(p)!==re(k)?!1:re(p)?p.tagName!==k.tagName||!B(p,k)?!1:dt(p)||o(p).hint===""||o(k).hint===""?!0:c(p,k):p.kind===k.kind}function oe(p,k){let R=(H,F)=>{let N=F===null?-1:H===k?we.get(F):Ce.get(F),E=H[N+1];return E&&!re(E)?E:null},$=null;for(let H of p){if(re(H)){$=H;continue}if(f.has(H))continue;let F=$===null?null:f.get($);if($!==null&&!F)continue;let N=R(k,F);N&&!g.has(N)&&N.kind===H.kind&&ne(H,N)}}function fe(p,k){oe(p,k);let R=y(p,k),$=(F,N)=>re(F)&&o(F).hint!==""&&o(N).hint===""&&!!N.querySelector("br")&&!R(F,N),H=0;for(let F of p){if(f.has(F)){let E=we.get(f.get(F));E!==void 0&&E>=H&&(H=E+1);continue}let N=0;for(let E=H;E<k.length&&N<Zi;E++){let G=k[E];if(!g.has(G)&&(N++,ue(F,G)&&!ut(F,G)&&!$(F,G))){ne(F,G),re(F)&&(o(F).hint===""||o(G).hint==="")&&x.add(F),H=E+1;break}}}T(p,k)}function y(p,k){let R=($,H,F)=>{for(let N=H-1;N>=0;N--)if(re($[N])&&F($[N]))return $[N];return null};return($,H)=>{let F=Ce.get($),N=we.get(H);if(F===N)return!0;let E=R(p,F,he=>f.has(he)),G=R(k,N,he=>g.has(he));return E?f.get(E)===G:!G}}function T(p,k){let R=p.filter(E=>re(E)&&!f.has(E)),$=k.filter(E=>re(E)&&!g.has(E));if(!R.length||!$.length)return;let H=oo(R,E=>E.tagName),F=oo($,E=>E.tagName),N=y(p,k);for(let E of R){let G=E.tagName;if(H.get(G)!==1||F.get(G)!==1)continue;let he=$.find(ve=>ve.tagName===G);he&&!g.has(he)&&N(E,he)&&B(E,he)&&!ut(E,he)&&(m(E,he)?Bt(E,he):(ne(E,he),x.add(E)))}}function P(){let p=new Map;for(let E of x)if(re(E)&&re(f.get(E))){let G=o(E).hash;p.has(G)||p.set(G,[]),p.get(G).push(E)}if(p.size)for(let E of ce){if(g.has(E)||!re(E)||rt(E))continue;let G=p.get(o(E).hash),he=G&&G.find(ve=>x.has(ve)&&!ut(ve,E)&&B(ve,E)&&m(ve,E));he&&(Qe(he),Bt(he,E),Be(he,E),se.add(he))}let k=new Map,R=new Map,$=new Map;for(let E of x){let G=f.get(E);re(E)&&re(G)&&$.set(G,E)}let H=(E,G)=>{if(!g.has(E))return!rt(E);let he=$.get(E);return he===g.get(E)&&he!==G&&!he.contains(G)},F=E=>{if(g.has(E)){let G=$.get(E);$.delete(E),Qe(G)}};for(let E of[...ce,...$.keys()]){if(g.has(E)&&!$.has(E))continue;let G=o(E).hash;if(k.has(G)||k.set(G,[]),k.get(G).push(E),dt(E))continue;let he=o(E).sig;R.has(he)||R.set(he,[]),R.get(he).push(E)}let N=new Set;for(let E of x){let G=f.get(E);!re(E)||!re(G)||dt(E)||o(E).hint===""||o(G).hint===""||c(E,G)||N.add(E)}for(let E of[...z,...N]){let G=f.get(E);if(G?!(x.has(E)&&N.has(E)):We(E))continue;let he=U=>{G&&Qe(E),F(U)},ve=k.get(o(E).hash);if(ve){let U=ve.find(V=>V!==G&&H(V,E)&&!ut(E,V)&&m(E,V));if(U){he(U),Bt(E,U),Be(E,U),se.add(E);continue}}if(dt(E)||J<=0)continue;let u=R.get(o(E).sig);if(!u)continue;let v=null,j=0;for(let U of u)if(!(U===G||!H(U,E)||!B(E,U)||ut(E,U))&&(J--<=0||c(E,U)&&(j++,v=U,j>1)))break;j>1&&L&&L.add(E),j===1&&(he(v),ne(E,v),Be(E,v),se.add(E),te.push([E,v]))}}}function oo(e,t){let n=new Map;for(let o of e){let r=t(o);r!=null&&n.set(r,(n.get(r)||0)+1)}return n}var ec={diff:0},As=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null,tc=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u,nc=/[\p{L}\p{M}\p{N}_'’]+|\s+|[\s\S]/gu,oc=/\P{M}\p{M}*/gu;function Sr(e){if(e==="")return[];if(As){let n=[];for(let o of As.segment(e))n.push(o.segment);return n}let t=[];for(let n of e.match(nc))if(tc.test(n))for(let o of n.match(oc))t.push(o);else t.push(n);return t}var rc=/^[ ]+$/,sc=e=>rc.test(e)?" ".repeat(e.length):e,Dn=e=>typeof e.k=="string"&&/^\s+$/.test(e.k),gt="",kr=e=>e.every(t=>Dn(t)||t.k===gt),ic=/^[\x00-\x7f\u00A0]*$/,cc=/[A-Za-z0-9_']+|[ \u00A0]+|\s|./g;function lc(e){return e===""?[]:e.match(cc)}function $n(e,t=!1){return(t?lc(e):Sr(e)).map(n=>({k:sc(n),raw:n,len:n.length}))}var Go=(...e)=>e.every(t=>ic.test(t));function wr(e,t,n){let o=e.length,r=t.length,i=Math.min(o+r,n),c=i+1,s=new Int32Array(2*i+3),a=[],m=o===0&&r===0;for(let A=0;A<=i&&!m;A++){a.push(s.slice(c-A,c+A+1));for(let S=-A;S<=A;S+=2){let L;S===-A||S!==A&&s[c+S-1]<s[c+S+1]?L=s[c+S+1]:L=s[c+S-1]+1;let f=L-S,g=L;for(;L<o&&f<r&&e[L].k===t[f].k;)L++,f++;if(ec.diff+=1+L-g,s[c+S]=L,L>=o&&f>=r){m=!0;break}}}if(!m)return null;let h=[],d=o,b=r;for(let A=a.length-1;A>0;A--){let S=a[A],L=d-b,f=L+A,g=L===-A||L!==A&&S[f-1]<S[f+1]?L+1:L-1,x=S[g+A],Q=x-g;for(;d>x&&b>Q;)h.push([0,d-1,b-1]),d--,b--;d===x?(h.push([1,d,b-1]),b--):(h.push([-1,d-1,b]),d--)}for(;d>0&&b>0;)h.push([0,d-1,b-1]),d--,b--;return h.reverse(),h}function ac(e,t,n){let o=d=>d.k===gt;if(!e.some(o)&&!t.some(o))return wr(e,t,n);let r=[],i=[];for(let d=0;d<e.length;d++)o(e[d])||r.push(d);for(let d=0;d<t.length;d++)o(t[d])||i.push(d);let c=wr(r.map(d=>e[d]),i.map(d=>t[d]),n);if(!c)return null;let s=[],a=0,m=0,h=(d,b)=>{for(;a<d&&m<b&&e[a].k===t[m].k;)s.push([0,a++,m++]);let A=wr(e.slice(a,d),t.slice(m,b),n);if(!A)return!1;for(let[S,L,f]of A)s.push([S,L+a,f+m]);return a=d,m=b,!0};for(let[d,b,A]of c)if(d===0){if(!h(r[b],i[A]))return null;s.push([0,a,m]),a++,m++}return h(e.length,t.length)?s:null}function ro(e,t,n=4e3){let o=[],r=0;for(;r<e.length&&r<t.length&&e[r].k===t[r].k;)e[r].raw!==t[r].raw&&o.push({bi:r,tok:t[r]}),r++;let i=0;for(;i<e.length-r&&i<t.length-r&&e[e.length-1-i].k===t[t.length-1-i].k;)e[e.length-1-i].raw!==t[t.length-1-i].raw&&o.push({bi:e.length-1-i,tok:t[t.length-1-i]}),i++;let c=e.slice(r,e.length-i),s=t.slice(r,t.length-i),a=mc(c,s)?null:ac(c,s,n);if(!a){let g=c.length||s.length?[{bs:r,be:r+c.length,toks:s}]:[];return{hunks:g,cosmetic:o,coarse:!0,parts:g.map(x=>({...x,gap:[],group:0})),cosmeticEq:o}}let m=[],h=(g,x)=>{c[g].raw!==s[x].raw&&o.push({bi:r+g,tok:s[x]})},d=null,b=[],A=0,S=0,L=()=>{d&&m.push(d),d=null;for(let[g,x]of b)h(g,x);b=[],A++};for(let[g,x,Q]of a){if(g===0){d&&Dn(c[x])&&!c[x].k.includes(`
|
|
3
|
+
`)?b.push([x,Q]):(L(),h(x,Q)),S=x+1;continue}(!d||b.length)&&(d&&m.push(d),d={bs:r+S,be:r+S,toks:[],gap:b.map(([se,le])=>({bi:r+se,tok:s[le]})),group:A},b=[]),g===-1?(d.be=r+S+1,S=x+1):d.toks.push(s[Q])}L(),fc(m,e);let f=Tr(m);return{hunks:f.hunks,cosmetic:o.concat(f.cosmetic),parts:m,cosmeticEq:o}}function fc(e,t){for(let n=0;n<e.length;n++){let o=e[n];if(o.gap.length)continue;let r=n+1<e.length?e[n+1].bs:1/0;if(o.toks.length){if(o.bs===o.be)for(;o.bs+1<r&&o.bs<t.length&&o.toks[0].k===gt&&t[o.bs].k===gt;)o.toks=[...o.toks.slice(1),o.toks[0]],o.bs++,o.be++}else for(;o.be+1<r&&o.be<t.length&&t[o.bs].k===gt&&t[o.be].k===gt;)o.bs++,o.be++}}function Tr(e,t=()=>!1){let n=[],o=[],r=null,i=-1;for(let c of e){let s=t(c);if(r&&!r.alone&&!s&&c.group===i){r.be=c.be;for(let a of c.gap)r.toks.push(a.tok);for(let a of c.toks)r.toks.push(a);continue}r&&n.push({bs:r.bs,be:r.be,toks:r.toks});for(let a of c.gap)o.push(a);r={bs:c.bs,be:c.be,toks:c.toks.slice(),alone:s},i=c.group}return r&&n.push({bs:r.bs,be:r.be,toks:r.toks}),{hunks:n,cosmetic:o}}var uc=(e,t)=>e.bs===t.bs&&e.be===t.be&&Or(e.toks,t.toks);function Nr(e,t,n){let o=h=>d=>h.some(b=>uc(d,b)),r=Tr(e.parts,o(t.parts)),i=Tr(t.parts,o(e.parts)),c=e.cosmeticEq.concat(r.cosmetic),s=t.cosmeticEq.concat(i.cosmetic),[a,m]=n?dc(r.hunks,i.hunks,n,c,s):[r.hunks,i.hunks];return{lh:a,rh:m,cosL:c,cosR:s}}function dc(e,t,n,o,r){let i=(S,L)=>S.k===L.k&&S.raw===L.raw,c=[{list:e.map(S=>({...S})),resp:new Set(o.map(S=>S.bi)),raw:new Map(o.map(S=>[S.bi,S.tok]))},{list:t.map(S=>({...S})),resp:new Set(r.map(S=>S.bi)),raw:new Map(r.map(S=>[S.bi,S.tok]))}],s=S=>S.bs===S.be,a=(S,L,f,g)=>{let x=S.list[L];if(!s(x))return g(x)===f?x.toks:null;let Q=L?S.list[L-1].be:0,se=L+1<S.list.length?S.list[L+1].bs:n.length;if(f<Q||f>se)return null;let le=x.toks,q=x.bs;for(;q>f;){let z=le[le.length-1];if(!i(z,n[q-1])||S.resp.has(q-1))return null;le=[z,...le.slice(0,-1)],q--}for(;q<f;){if(!i(le[0],n[q])||S.resp.has(q))return null;le=[...le.slice(1),le[0]],q++}return le},m=(S,L,f,g,x,Q)=>{let se=S.list[L],le=x?f.slice(f.length-g):f.slice(0,g),q=x?f.slice(0,f.length-g):f.slice(g),z={bs:Q,be:Q,toks:le};if(s(se)){if(!q.length){S.list[L]=z;return}let xe={bs:Q,be:Q,toks:q};x&&(xe.lead=!0),S.list.splice(L,1,...x?[xe,z]:[z,xe]);return}let ce={bs:se.bs,be:se.be,toks:q};S.list.splice(L,1,...x?[ce,z]:[z,ce])},h=(S,L,f,g,x)=>{let Q=S.list[L],se=x?f.slice(f.length-g):f.slice(0,g),le=x?f.slice(0,f.length-g):f.slice(g),q={bs:Q.bs,be:Q.be,toks:se};if(!le.length){S.list[L]=q;return}let z=x?{bs:Q.bs,be:Q.bs,toks:le,lead:!0}:{bs:Q.be,be:Q.be,toks:le};S.list.splice(L,1,...x?[z,q]:[q,z])},d=(S,L,f,g)=>{let x=S.list[L],Q=f.list[g],se=x.be,le=Q.bs;if(se>=le||L+1<S.list.length&&S.list[L+1].bs<=Q.be||g>0&&f.list[g-1].be>=x.bs)return!1;for(let ge=se;ge<le;ge++)if(!Dn(n[ge])||n[ge].k.includes(`
|
|
4
|
+
`))return!1;let q=ge=>n.slice(se,le).map((Oe,Be)=>ge.raw.get(se+Be)||Oe),z=[...x.toks,...q(S)],ce=[...q(f),...Q.toks],xe=(ge,Oe,Be)=>Oe>=0&&Oe+Be.length<=ge.length&&Be.every((We,rt)=>ge[Oe+rt].k===We.k),te=(ge,Oe,Be)=>kr(ge)&&n.slice(Oe,Be).some(We=>!Dn(We)),J=ge=>ge.some(Oe=>!Dn(Oe)),Ce,we,ne,_;if(s(x)&&J(x.toks)&&xe(ce,0,x.toks)){let ge=ce.slice(x.toks.length);te(ge,se,Q.be)||(Ce=se,we=x.toks,ne=ce.slice(0,x.toks.length),_=[null,{bs:se,be:Q.be,toks:ge}])}if(Ce===void 0&&s(Q)&&J(Q.toks)){let ge=z.length-Q.toks.length,Oe=z.slice(0,ge);xe(z,ge,Q.toks)&&!te(Oe,x.bs,le)&&(Ce=le,we=z.slice(ge),ne=Q.toks,_=[{bs:x.bs,be:le,toks:Oe},null])}if(Ce===void 0)return!1;let ye=ge=>ge&&(ge.bs<ge.be||ge.toks.length);return S.list.splice(L,1,...[_[0],{bs:Ce,be:Ce,toks:we}].filter(ye)),f.list.splice(g,1,...[{bs:Ce,be:Ce,toks:ne},_[1]].filter(ye)),!0},b=c[0],A=c[1];for(let S=0;S<64;S++){let L=!1;e:for(let f=0;f<b.list.length;f++)for(let g=0;g<A.list.length;g++){let x=b.list[f],Q=A.list[g];if(!(x.bs===Q.bs&&x.be===Q.be&&Or(x.toks,Q.toks))){for(let se of[!0,!1]){let le=z=>se?z.be:z.bs,q=s(x)?[le(Q),x.bs]:[le(x)];for(let z of q){let ce=a(b,f,z,le),xe=ce&&a(A,g,z,le);if(!xe)continue;let te=(_,ye)=>se?_[_.length-1-ye]:_[ye],J=0;for(;J<ce.length&&J<xe.length&&te(ce,J).k===te(xe,J).k;)J++;if(!J)continue;let Ce=se?ce.slice(0,ce.length-J):ce.slice(J),we=se?xe.slice(0,xe.length-J):xe.slice(J);if(!(J<ce.length&&J<xe.length&&!kr(Ce)&&!kr(we)&&(s(x)&&s(Q)||x.bs===Q.bs&&x.be===Q.be)||!(se?ce.slice(ce.length-J):ce.slice(0,J)).some(_=>!Dn(_)))){if(J===ce.length&&J===xe.length&&s(x)&&s(Q)){if(x.bs===z&&Q.bs===z)continue;b.list[f]={bs:z,be:z,toks:ce},A.list[g]={bs:z,be:z,toks:xe}}else!s(x)&&x.bs===Q.bs&&x.be===Q.be?(h(b,f,ce,J,se),h(A,g,xe,J,se)):(m(b,f,ce,J,se,z),m(A,g,xe,J,se,z));L=!0;break e}}}if(d(b,f,A,g)||d(A,g,b,f)){L=!0;break e}}}if(!L)break}return[b.list,A.list]}var pc=48,hc=.3;function mc(e,t){let n=e.filter(c=>!Dn(c)),o=t.filter(c=>!Dn(c));if(Math.min(n.length,o.length)<pc)return!1;let r=new Map;for(let c of n)r.set(c.k,(r.get(c.k)||0)+1);let i=0;for(let c of o){let s=r.get(c.k);s>0&&(i++,r.set(c.k,s-1))}return i/Math.min(n.length,o.length)<hc}var gc=(e,t)=>{let n=new Set;for(let o of e.toks)typeof o.k!="string"&&n.add(o.k.el);for(let o=e.bs;o<e.be;o++)typeof t[o].k!="string"&&n.add(t[o].k.el);return n},Or=(e,t)=>e.length===t.length&&e.every((n,o)=>n.k===t[o].k);function Ss(e,t,n,o="remote"){let r=ro(e,t),i=ro(e,n),{lh:c,rh:s,cosL:a,cosR:m}=Nr(r,i,e),h=O=>O.bs===O.be,d=O=>O.toks.some(B=>typeof B.k=="string"),b=O=>h(O)&&!d(O),A=(O,B)=>B.bs<O.be&&O.bs<B.be,S=(O,B)=>!A(O,B)&&B.bs<=O.be&&O.bs<=B.be&&(h(O)&&d(O)||h(B)&&d(B))&&!(h(O)&&h(B)),L=(O,B)=>O.bs===B.bs&&O.be===B.be&&Or(O.toks,B.toks),f=[],g=new Set;for(let O of c){let B=s.find(ae=>!g.has(ae)&&L(O,ae));B?(g.add(B),f.push({bs:O.bs,be:O.be,side:"both",l:O,r:B,toks:O.toks})):f.push({bs:O.bs,be:O.be,side:"L",l:O,toks:O.toks,lead:!!O.lead})}for(let O of s)g.has(O)||f.push({bs:O.bs,be:O.be,side:"R",r:O,toks:O.toks,lead:!!O.lead});f.sort((O,B)=>O.bs-B.bs||O.be-B.be||B.lead-O.lead);let x=0,Q=0;for(let O of f)O.side==="both"&&(x+=O.toks.length-(O.be-O.bs));let se=f.map((O,B)=>B),le=O=>se[O]===O?O:se[O]=le(se[O]),q=(O,B)=>(O=le(O),B=le(B),O===B?!1:(se[O]=B,!0)),z=f.map(O=>gc({bs:O.bs,be:O.be,toks:O.toks},e)),ce={L:new Map,R:new Map};f.forEach((O,B)=>{let ae=O.side==="both"?["L","R"]:[O.side];for(let be of ae)for(let de of z[B])ce[be].has(de)||ce[be].set(de,[]),ce[be].get(de).push(B)});for(let O of[ce.L,ce.R])for(let B of O.values())for(let ae=1;ae<B.length;ae++)q(B[0],B[ae]);for(let O=0;O<f.length;O++)for(let B=O+1;B<f.length;B++){let ae=f[O],be=f[B];ae.side===be.side&&ae.side!=="both"||ae.bs>be.be||(A(ae,be)||S(ae,be)?q(O,B):ae.bs===be.bs&&h(ae)&&h(be)&&Q++)}let xe=(O,B)=>{let ae=O==="L"?c:s;for(let be of ae)if(be.toks.some(de=>de.kind==="close"&&de.k.el===B.el))return be.bs;for(let be=0;be<e.length;be++)if(e[be].kind==="close"&&e[be].k.el===B.el)return be;return-1};f.forEach((O,B)=>{if(!(!b(O)||O.side==="both"))for(let ae of O.toks){if(ae.kind!=="open")continue;let be=xe(O.side,ae.k);if(be<=O.bs)continue;let de=new Uint8Array(be-O.bs),ze=[];if(f.forEach((De,Qe)=>{if(!(De.side===O.side||h(De))&&De.bs<be&&De.be>O.bs){ze.push(Qe);for(let st=Math.max(De.bs,O.bs);st<Math.min(De.be,be);st++)de[st-O.bs]=1}}),ze.length&&de.every(De=>De===1))for(let De of ze)q(B,De)}});let te=!0;for(;te;){te=!1;let O=new Map;f.forEach((B,ae)=>{let be=le(ae),de=O.get(be)||{bs:B.bs,be:B.be,L:!1,R:!1};de.bs=Math.min(de.bs,B.bs),de.be=Math.max(de.be,B.be),B.side!=="R"&&(de.L=!0),B.side!=="L"&&(de.R=!0),O.set(be,de)}),f.forEach((B,ae)=>{for(let[be,de]of O){if(le(ae)===le(be)||!(de.L&&de.R))continue;let ze=B.bs<de.be&&B.be>de.bs,De=h(B)&&d(B)&&(B.bs===de.be||B.bs===de.bs);(ze||De)&&q(ae,be)&&(te=!0)}})}let J=new Map;f.forEach((O,B)=>{let ae=le(B);J.has(ae)||J.set(ae,[]),J.get(ae).push(O)});let Ce=[];for(let O of J.values()){let B=O.some(be=>be.side==="L"),ae=O.some(be=>be.side==="R");if(B&&ae){let be=Math.min(...O.map(Qe=>Qe.bs)),de=Math.max(...O.map(Qe=>Qe.be)),ze=O.filter(Qe=>Qe.side!=="R").map(Qe=>Qe.l).sort((Qe,st)=>Qe.bs-st.bs),De=O.filter(Qe=>Qe.side!=="L").map(Qe=>Qe.r).sort((Qe,st)=>Qe.bs-st.bs);Ce.push({bs:be,be:de,kind:"conflict",localHunks:ze,remoteHunks:De})}else for(let be of O)Ce.push({bs:be.bs,be:be.be,kind:be.side,u:be})}let we=(O,B)=>{let ae=O==="L"?c:s;for(let be of ae)if(be.toks.some(de=>de.kind==="close"&&de.k.el===B.el))return be.bs+.5;for(let be=0;be<e.length;be++)if(e[be].kind==="close"&&e[be].k.el===B.el)return be;return 1/0},ne=(O,B)=>{let ae=O==="L"?c:s;for(let be of ae)if(be.toks.some(de=>de.kind==="open"&&de.k.el===B.el))return be.bs-.5;for(let be=0;be<e.length;be++)if(e[be].kind==="open"&&e[be].k.el===B.el)return be;return-1/0},_=O=>O.kind==="R"?"R":"L",ye=O=>O.kind==="R"?1:0;Ce.sort((O,B)=>{if(O.bs!==B.bs)return O.bs-B.bs;let ae=O.bs===O.be,be=B.bs===B.be;if(ae!==be)return ae?-1:1;if(ae&&be&&O.kind!=="conflict"&&B.kind!=="conflict"){let ze=O.u.toks,De=B.u.toks,Qe=wt=>wt.length&&wt.every(bt=>bt.kind==="open"),st=wt=>wt.length&&wt.every(bt=>bt.kind==="close");if(Qe(ze)&&Qe(De)){let wt=Math.max(...ze.map(Tt=>we(_(O),Tt.k))),bt=Math.max(...De.map(Tt=>we(_(B),Tt.k)));if(wt!==bt)return bt-wt}if(st(ze)&&st(De)){let wt=Math.min(...ze.map(Tt=>ne(_(O),Tt.k))),bt=Math.min(...De.map(Tt=>ne(_(B),Tt.k)));return wt!==bt?bt-wt:ye(B)-ye(O)}}let de=ze=>ze.u&&ze.u.lead?1:0;return de(B)-de(O)||ye(O)-ye(B)||O.be-B.be});let ge=[],Oe=[],Be=0,We=O=>{O>Be&&(ge.push({bs:Be,be:O,toks:e.slice(Be,O),source:"base"}),Be=O)};for(let O of Ce){if(We(O.bs),O.kind==="conflict"){let B=Ar(e,O.localHunks,O.bs,O.be),ae=Ar(e,O.remoteHunks,O.bs,O.be),be=o==="local"?B:o==="both"?B.concat(ae):ae,de=(Qe,st)=>{let wt=0;for(let bt of Qe)bt.be<=O.bs&&!st.includes(bt)&&(wt+=bt.toks.length-(bt.be-bt.bs));return wt},ze=O.bs+de(c,O.localHunks),De=O.bs+de(s,O.remoteHunks);Oe.push({bs:O.bs,be:O.be,ls:ze,le:ze+B.length,rs:De,re:De+ae.length,ms:0,me:0,base:e.slice(O.bs,O.be),local:B,remote:ae,resolved:be}),ge.push({bs:O.bs,be:O.be,toks:be,source:"conflict",localHunks:O.localHunks,localToks:B,keepsLocal:o!=="remote"})}else ge.push({bs:O.bs,be:O.be,toks:O.u.toks,source:O.kind==="R"?"remote":"local",localHunks:O.kind==="R"?[]:[O.u.l]});Be=Math.max(Be,O.be)}We(e.length);let rt=0,re=0;for(let O of ge)O.source==="conflict"&&(Oe[re].ms=rt,Oe[re].me=rt+O.toks.length,re++),rt+=O.toks.length;let ut=new Map(a.map(O=>[O.bi,O.tok])),dt=new Map(m.map(O=>[O.bi,O.tok])),Se=[];for(let O of ge){O.source==="base"&&(O.toks=O.toks.map((B,ae)=>{let be=O.bs+ae,de=ut.get(be),ze=dt.get(be),De=de&&ze?o==="remote"?ze:de:de||ze||B;return De===B?B:{...De,cosmetic:!0}}));for(let B of O.toks)Se.push({...B,src:O.source})}return{tokens:Se,segments:ge,conflicts:Oe,localHunks:c,remoteHunks:s,collapsedDelta:x,samePoint:Q,mapLocalOffset:bc(e,c,ge)}}function Ar(e,t,n,o){let r=[],i=n;for(let c of t)r=r.concat(e.slice(i,c.bs),c.toks),i=c.be;return r.concat(e.slice(i,o))}var xr=e=>e.reduce((t,n)=>t+n.len,0);function bc(e,t,n){let o=new Int32Array(e.length+1);for(let c=0;c<e.length;c++)o[c+1]=o[c]+e[c].len;let r=t.map(c=>({bs:o[c.bs],be:o[c.be],text:c.toks.map(s=>s.raw).join(""),ref:c})),i=n.map(c=>({bs:o[c.bs],be:o[c.be],len:xr(c.toks),source:c.source,localHunks:c.localHunks||[],localLen:c.localToks?xr(c.localToks):0,keepsLocal:c.keepsLocal,ref:c}));return c=>{let s=null,a=null,m=0,h=0,d=0;for(let A of r){let S=A.bs-d;if(c<=h+S){s=d+(c-h);break}if(h+=S,d=A.bs,c<=h+A.text.length){a=A,m=c-h,s=A.bs;break}h+=A.text.length,d=A.be}s===null&&(s=d+(c-h));let b=0;for(let A of i){if(!a&&s<=A.bs)return b;if(!(a?A.localHunks.includes(a.ref):s<A.be)){b+=A.len;continue}if(A.source==="base")return b+(s-A.bs);if(A.source==="remote")return b+A.len;if(A.source==="local")return b+Math.min(m,A.len);if(!A.keepsLocal||!a)return b+A.len;let L=A.localHunks.indexOf(a.ref),f=xr(Ar(e,A.localHunks.slice(0,L),A.ref.bs,a.ref.bs));return b+Math.min(f+m,A.localLen)}return b}}function wo(e,t,n,o="remote"){if(t===n||n===e)return{text:t,conflicts:[],mapLocalOffset:g=>Math.min(g,t.length),granularity:"word"};let r=Go(e,t,n),i=$n(e,r),c=$n(t,r),s=$n(n,r),a=i.length<=2e4&&c.length<=2e4&&s.length<=2e4?Ss(i,c,s,o):null,m="word",h=i;if(!a){let g=x=>x.split(/(?<=\n)/).map(Q=>({k:Q,raw:Q,len:Q.length}));h=g(e),a=Ss(h,g(t),g(n),o),m="line"}let d=g=>g.map(x=>x.raw).join(""),b=g=>{let x=[0];for(let Q of g)x.push(x[x.length-1]+Q.len);return x},A=b(h),S=null,L=null,f=null;if(a.conflicts.length){let g=x=>x.split(/(?<=\n)/).map(Q=>({k:Q,raw:Q,len:Q.length}));S=b(m==="line"?g(t):c),L=b(m==="line"?g(n):s),f=b(a.tokens)}return{text:d(a.tokens),conflicts:a.conflicts.map(g=>({bs:A[g.bs],be:A[g.be],ls:S[g.ls],le:S[g.le],rs:L[g.rs],re:L[g.re],ms:f[g.ms],me:f[g.me],base:d(g.base),local:d(g.local),remote:d(g.remote),resolved:d(g.resolved)})),mapLocalOffset:a.mapLocalOffset,granularity:m}}function xo(e,t,n=4e3){if(e===t)return[];let o=Go(e,t),r=$n(e,o),i=$n(t,o),c=ro(r,i,n),s=[0];for(let a of r)s.push(s[s.length-1]+a.len);return c.hunks.map(a=>({bs:s[a.bs],be:s[a.be],text:a.toks.map(m=>m.raw).join("")}))}var co="\uFFFC";var yc={caret:0},An=new Set("A ABBR B BDI BDO CITE CODE DATA DEL DFN EM FONT I INS KBD MARK Q S SAMP SMALL SPAN STRIKE STRONG SUB SUP TIME TT U VAR".split(" ")),Is=new Set(["BR","WBR","IMG"]),Er=new Set("ADDRESS ARTICLE ASIDE AUDIO BLOCKQUOTE BODY CANVAS CAPTION CENTER COL COLGROUP DD DETAILS DIALOG DIR DIV DL DT FIELDSET FIGCAPTION FIGURE FOOTER FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HEADER HGROUP HR HTML IFRAME LEGEND LI MAIN MATH MENU NAV NOSCRIPT OBJECT OL OPTGROUP OPTION P PRE SCRIPT SECTION SELECT STYLE SUMMARY SVG TABLE TBODY TD TEMPLATE TEXTAREA TFOOT TH THEAD TITLE TR UL VIDEO".split(" "));function qn(e,t={}){if(e.nodeType===3)return!0;if(e.nodeType!==1)return!1;if(t.ignored&&t.ignored(e)||Is.has(e.tagName))return!0;if(!An.has(e.tagName))return!Er.has(e.tagName);if(t.remoteWins&&t.remoteWins(e))return!1;let n=t.inlineCache&&t.inlineCache.get(e);if(n!==void 0)return n;let o=!0;for(let r of e.childNodes)if(!qn(r,t)){o=!1;break}return t.inlineCache&&t.inlineCache.set(e,o),o}function kc(e){return!e.firstChild||e.textContent===""&&!e.querySelector("br,img,wbr")}function En(e,t={}){let n={text:"",marks:[],atoms:[],nodes:[],stackAt:[],pins:[],placeholder:null,via:null},o=(r,i)=>{for(let c of r){if(c.nodeType===3){let d=c.nodeValue;if(!d)continue;n.nodes.push({node:c,s:n.text.length,e:n.text.length+d.length}),n.text+=d;for(let b=0;b<d.length;b++)n.stackAt.push(i);continue}if(c.nodeType!==1)continue;if(t.ignored&&t.ignored(c)){n.pins.push({el:c,i:n.text.length});continue}if(t.skip&&t.skip.has(c))continue;let s=t.via&&t.via(c)||c;s!==c&&(n.via||(n.via=new Map)).set(s,c);let a=c.tagName;if(t.blocks&&t.blocks.has(c)){n.text.length&&n.text[n.text.length-1]!==gt&&(n.stackAt.push(i),n.text+=gt);let d={el:c,tag:a,from:n.text.length,to:-1,depth:i.length,block:!0};n.marks.push(d);let b=i.concat([d]);o(s.childNodes,b),n.stackAt.push(b),n.text+=gt,d.to=n.text.length;continue}let m=An.has(a)&&kc(s);if(Is.has(a)||!An.has(a)||t.remoteWins&&t.remoteWins(c)||t.atomize&&t.atomize(c)||m){n.atoms.push({i:n.text.length,el:c,key:m?a+":empty":a,stack:i}),n.stackAt.push(i),n.text+=co;continue}let h={el:c,tag:a,from:n.text.length,to:-1,depth:i.length};n.marks.push(h),o(s.childNodes,i.concat([h])),h.to=n.text.length}};if(o(e,[]),n.atoms.length===1&&n.atoms[0].el.tagName==="BR"&&n.marks.length===0&&Yo(n).trim()===""){let r=n.atoms[0];n.placeholder=r.el,n.text=n.text.slice(0,r.i)+n.text.slice(r.i+1),n.stackAt.splice(r.i,1);for(let i of n.nodes)i.s>r.i&&(i.s--,i.e--);n.atoms=[]}return n.atomAt=new Map(n.atoms.map(r=>[r.i,r])),n}function wc(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")}function xc(e){let t="<"+e.tagName.toLowerCase();for(let n of e.attributes)t+=` ${n.name}="${n.value.replace(/"/g,""")}"`;return t+">"}function io(e,t,n){let o="",r=[];for(let i=t;i<n;i++){let c=e.stackAt[i],s=0;for(;s<r.length&&s<c.length&&r[s]===c[s];)s++;for(;r.length>s;)o+=`</${r.pop().tag.toLowerCase()}>`;for(;r.length<c.length;){let m=c[r.length];o+=xc(m.el),r.push(m)}let a=e.atomAt.get(i);o+=a?a.el.outerHTML:e.text[i]===gt?"":wc(e.text[i])}for(;r.length;)o+=`</${r.pop().tag.toLowerCase()}>`;return o}function Tc(e,t){let n=[...e.el.attributes].filter(o=>!t(e.el,o.name)).map(o=>o.name+"="+o.value).sort().join("");return e.tag+"|"+n}function Cs(e,t){let n=[...e.attributes].filter(o=>!t(e,o.name)).map(o=>o.name+"="+o.value).sort().join("");return e.tagName+"|"+n+"|"+e.innerHTML}function Ns(e,t=()=>!1){let n=new Map,o=i=>{let c=n.get(i);return c===void 0&&(c="{"+i.map(s=>Tc(s,t)).sort().join(",")+"}",n.set(i,c)),c},r="";for(let i=0;i<e.text.length;i++){let c=e.atomAt.get(i);r+=(c?"["+Cs(c.el,t)+"]":e.text[i])+o(e.stackAt[i])}return e.text.length===0&&e.placeholder&&(r+="[br]"),r}function so(e,t,n,o=r=>r.key){let r=[],i=e.text,c=0,s=a=>{if(a<=c)return;let m=i.slice(c,a);if(n)for(let h of m.split(/(?<=\n)/))r.push({k:h,raw:h,len:h.length});else for(let h of $n(m,t))r.push(h)};for(let a of e.atoms)s(a.i),r.push({k:"\0"+o(a),raw:co,len:1,atom:!0}),c=a.i+1;return s(i.length),r}function Yo(e){if(!e.atoms.length)return e.text;let t="",n=0;for(let o of e.atoms)t+=e.text.slice(n,o.i),n=o.i+1;return t+e.text.slice(n)}var Mr=e=>{let t=new Int32Array(e.length+1);for(let n=0;n<e.length;n++)t[n+1]=t[n]+e[n].len;return t};function Os(e,t,n,o){let r=Mr(t),i=Mr(n),c=[],s=0,a=0;for(let h of o.hunks){a+=h.bs-s;let d=a+h.toks.length;c.push({bs:r[h.bs],be:r[h.be],ss:i[a],se:i[d],text:e.text.slice(i[a],i[d]),toks:h.toks,lead:!!h.lead}),a=d,s=h.be}let m=new Map;for(let h of o.cosmetic)m.set(h.bi,h.tok.raw);return{hunks:c,respell:m}}function vs(e,t,n){let o=c=>c===gt||/\s/.test(c),r=c=>c.replace(/[\u001E\s]/g,""),i=[];for(let c of e){let s=t.slice(c.bs,c.be),a=n.slice(c.ss,c.se);if(!s.includes(gt)&&!a.includes(gt)||s.includes(co)||a.includes(co)||r(s)!==r(a)){i.push(c);continue}let m=0,h=0;for(;;){let d=m,b=h;for(;d<s.length&&o(s[d]);)d++;for(;b<a.length&&o(a[b]);)b++;let A=m,S=h;for(;A<d&&S<b&&s[A]===a[S];)A++,S++;let L=d,f=b;for(;L>A&&f>S&&s[L-1]===a[f-1];)L--,f--;if(L>A||f>S){let g=a.slice(S,f);i.push({bs:c.bs+A,be:c.bs+L,ss:c.ss+S,se:c.ss+f,text:g,toks:[...g].map(x=>({k:x,raw:x,len:1})),lead:c.lead})}if(d>=s.length)break;m=d+1,h=b+1}}return i}function Ms(e,t,n){let o=new Int32Array(t+1).fill(-1),r=new Int32Array(n+1).fill(-1),i=0,c=0,s=a=>{for(;i<a;)o[i]=c,r[c]=i,i++,c++};for(let a of e)s(a.bs),i=a.be,c=a.se;return s(t),o[t]=c,r[c]=t,{bTo:o,toB:r}}function Es(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Ir(e){let{out:t,policy:n="remote",L:o,R:r}=e,i=e.provenance||new WeakMap,c=e.textMappers||new WeakMap,s=e.conflicts||[],a=e.decisions||[],m=s.length,h=e.conflict||(l=>s.push(l)),d={textNodes:null,text:"",out:null,atomOut:new Map,breakOut:new Map,node:e.node||null},b=[],A=!!(o&&o.reverse&&o.map&&r&&r.reverse&&r.map),S={base:null,local:null,remote:null};if(A&&e.moveIn){let l=Te=>Ve=>Te.some(ke=>ke===Ve||ke.nodeType===1&&ke.contains(Ve)),w=l(e.local),C=l(e.remote),I=l(e.base),D=new Set,K=Te=>{if(!An.has(Te.tagName))return;let Ve=o.map.get(Te),ke=r.map.get(Te);(Ve&&!w(Ve)||ke&&!C(ke))&&D.add(Te);for(let Ee of Te.children)K(Ee)};for(let Te of e.base)Te.nodeType===1&&K(Te);let pe=Te=>Ve=>{if(!An.has(Ve.tagName))return!1;let ke=Te.reverse.get(Ve);return!!ke&&(D.has(ke)||!I(ke))};D.size&&(S.base=Te=>D.has(Te)),S.local=pe(o),S.remote=pe(r)}let L={base:new Set,local:new Set,remote:new Set};if(A&&e.moveIn){let l=I=>D=>I.some(K=>K===D||K.nodeType===1&&K.contains(D)),w=l(e.local),C=l(e.remote);for(let I of En(e.base,{...e,atomize:S.base}).atoms){let D=o.map.get(I.el),K=r.map.get(I.el),pe=!!D&&!w(D),Te=!!K&&!C(K);!pe&&!Te||(L.base.add(I.el),D&&!pe&&L.local.add(D),K&&!Te&&L.remote.add(K),w(I.el)&&L.local.add(I.el),C(I.el)&&L.remote.add(I.el))}}let f=En(e.base,{...e,atomize:S.base,skip:L.base}),g=En(e.local,{...e,atomize:S.local,skip:L.local}),x=En(e.remote,{...e,atomize:S.remote,skip:L.remote}),Q=new Map(f.atoms.map(l=>[l.el,l])),se={},le=l=>L[l].size?(se[l]||(se[l]=En(e[l],{...e,atomize:S[l]})),se[l]):null,q=(l,w,C)=>{w.namespaceURI?l.setAttributeNS(w.namespaceURI,w.name,C):l.setAttribute(w.name,C)},z=(l,w,C,I)=>{if(!w&&(!C||!I)){for(let K of(C||I).attributes)q(l,K,K.value);return}let D=new Map;for(let K of[w,C,I])if(K)for(let pe of K.attributes)D.set(pe.name,pe);for(let[K,pe]of D){let Te=w?w.getAttribute(K):null,Ve=C?C.getAttribute(K):Te,ke=I?I.getAttribute(K):Te,Ee;Ve===ke?Ee=Ve:Ve===Te?(Ee=ke,a.push({kind:"attr",el:l,name:K,source:"remote"})):ke===Te?(Ee=Ve,a.push({kind:"attr",el:l,name:K,source:"local"})):(Ee=n==="local"?Ve:ke,h({kind:"attr",el:l,name:K,base:Te,local:Ve,remote:ke,resolved:Ee},{el:l,sample:pe}),a.push({kind:"attr",el:l,name:K,source:"both"})),Ee!=null&&q(l,pe,Ee)}},ce=(l,w,C,I)=>l&&e.mergeAttrs?e.mergeAttrs(l,w,C,I):z(I,l,w,C),xe=e.mergeElement||((l,w,C)=>{let I=t.createElement(l.tagName);ce(l,w,C,I);let D=w||l,K=C||l,pe=n==="local"?D.isEqualNode(l)?K:D:K.isEqualNode(l)?D:K;for(let Te of pe.childNodes)I.appendChild(t.importNode(Te,!0));return i.set(I,{base:l,local:w,remote:C}),I}),te=e.cloneUnit||((l,w)=>{let C=t.importNode(l,!0);return i.set(C,{base:null,local:w==="local"?l:null,remote:w==="remote"?l:null}),C}),J=e.atomKey||(l=>Cs(l,()=>!1)),Ce=(l,w)=>{let C=new Map;for(let I of l.atoms)if(e.remoteWins&&e.remoteWins(I.el)&&An.has(I.el.tagName))C.set(I,"w"+I.el.tagName+"#"+(I.el.id||""));else if(!A)C.set(I,I.key);else if(l===f)C.set(I,"="+J(I.el));else{let D=w.reverse.get(I.el),K=D?Q.get(D):null;K?C.set(I,"="+J(K.el)):D?C.set(I,"m"+J(I.el)):C.set(I,"="+J(I.el))}return I=>C.get(I)},we=Ce(f,null),ne=Ce(g,o),_=Ce(x,r),ye=Go(Yo(f),Yo(g),Yo(x)),ge=so(f,ye,!1,we),Oe=so(g,ye,!1,ne),Be=so(x,ye,!1,_),We=ge.length>2e4||Oe.length>2e4||Be.length>2e4;We&&(ge=so(f,ye,!0,we),Oe=so(g,ye,!0,ne),Be=so(x,ye,!0,_));let rt=Nr(ro(ge,Oe),ro(ge,Be),ge),re=Os(g,ge,Oe,{hunks:rt.lh,cosmetic:rt.cosL}),ut=Os(x,ge,Be,{hunks:rt.rh,cosmetic:rt.cosR});re.hunks=vs(re.hunks,f.text,g.text),ut.hunks=vs(ut.hunks,f.text,x.text);let dt=Ms(re.hunks,f.text.length,g.text.length),Se=Ms(ut.hunks,f.text.length,x.text.length),O=f.text.length,B=l=>new Map(l.atoms.map(w=>[w.el,w])),ae=B(g),be=B(x),de=(l,w,C)=>{let I=new Set;if(!A)return I;for(let D of l.atoms){let K=Q.get(w.reverse.get(D.el));K&&C.bTo[K.i]<0&&I.add(K)}return I},ze=de(g,o,dt),De=de(x,r,Se),Qe=l=>!qn(l,{...e,remoteWins:null}),st=new Set;if(A)for(let l of f.atoms){if(!Qe(l.el))continue;let w=o.map.get(l.el)||null,C=r.map.get(l.el)||null,I=w&&!C?w:C&&!w?C:null;I&&(ae.has(I)||be.has(I))&&!I.isEqualNode(l.el)&&st.add(l)}let wt=1,bt=(l,w)=>({id:wt++,tag:l,base:null,local:null,remote:null,rank:w}),Tt=new Map,nn=[];for(let l of f.marks){let w=bt(l.tag,l.depth);w.block=!!l.block,w.base=l.el,w.baseMark=l,Tt.set(l.el,w),nn.push(w)}let Fe=(l,w)=>{let C=-1,I=-1;for(let D=l.from;D<l.to;D++){let K=w[D];K>=0&&(C<0&&(C=K),I=K+1)}return C<0?null:[C,I]},Qt=(l,w,C,I)=>{for(let D of l.marks){let K=C?C.reverse.get(D.el):null;K&&C.identical.has(K)&&C.pairIdenticalChildren&&C.pairIdenticalChildren(K);let pe=K?Tt.get(K):null;if(pe&&pe[w]&&(pe=null),!pe){let Te=Fe(D,I),Ve=0;if(Te)for(let ke of nn){if(ke.tag!==D.tag||ke[w]||!!ke.block!=!!D.block)continue;let Ee=Math.min(Te[1],ke.baseMark.to)-Math.max(Te[0],ke.baseMark.from);(Ee>Ve||Ee===Ve&&Ee>0&&Math.abs(ke.rank-D.depth)<Math.abs(pe.rank-D.depth))&&(pe=ke,Ve=Ee)}}pe||(pe=bt(D.tag,D.depth),pe.block=!!D.block,pe.new=w),pe[w]=D.el,pe[w+"Mark"]=D,Tt.set(D.el,pe)}};Qt(g,"local",o,dt.toB),Qt(x,"remote",r,Se.toB);let Xt=l=>l.merged||l,Bt=l=>{let w=new Set;for(let C of l)C.block||w.add(Tt.get(C.el));return w},Et=new Map,Lt=l=>{let w=Et.get(l);return w||(w=Bt(l),Et.set(l,w)),w},sn=(l,w)=>{let C=[],I=null;for(let D=0;D<O;D++){let K=w[D];if(K<0){I&&C.push(I),I=null;continue}let pe=Lt(f.stackAt[D]),Te=Lt(l.stackAt[K]),Ve=new Set,ke=new Set;for(let Ee of Te)pe.has(Ee)||Ve.add(Ee);for(let Ee of pe)Te.has(Ee)||ke.add(Ee);if(!Ve.size&&!ke.size){I&&C.push(I),I=null;continue}if(I&&Es(I.added,Ve)&&Es(I.removed,ke)){I.be=D+1;continue}I&&C.push(I),I={bs:D,be:D+1,added:Ve,removed:ke}}return I&&C.push(I),C},M=sn(g,dt.bTo),Z=sn(x,Se.bTo),ee=l=>l.be>l.bs?[l.bs,l.be-1]:[l.bs-1,l.bs],ue=(l,w)=>{if(O===0)return null;let[C,I]=ee(l);for(let D of w){if(D.be<=C)continue;if(D.bs>I)break;let K=D.bs<=C&&I<D.be;return K&&l.text===""&&D.bs===l.bs&&D.be===l.be?"straddle":K?D:l.be>l.bs?"straddle":null}return null},oe=l=>l.bs===l.be,fe=(l,w)=>{let C=!1;for(let I=l.bs;I<l.be;I++){let D=f.text[I];if(D===gt)C=!0;else if(!/\s/.test(D))return!1}for(let I=l.ss;I<l.se;I++){let D=w.text[I];if(D===gt)C=!0;else if(!/\s/.test(D))return!1}return C},y=(l,w)=>l.bs<w.be&&w.bs<l.be,T=(l,w)=>l.bs<=w.be&&w.bs<=l.be&&oe(l)!==oe(w),P=(l,w)=>f.text.slice(l.bs,l.be).includes(gt)||w.text.slice(l.ss,l.se).includes(gt),p=l=>{if(oe(l))return!1;let w=l.bs,C=l.be;for(;w>0&&/\s/.test(f.text[w-1]);)w--;for(;C<f.text.length&&/\s/.test(f.text[C]);)C++;return(w===0||f.text[w-1]===gt)&&(C===f.text.length||f.text[C]===gt)},k=(l,w)=>!P(l,w)&&!p(l),R=(l,w)=>y(l,w)||T(l,w)&&!(fe(l,g)&&k(w,x))&&!(fe(w,x)&&k(l,g)),$=(l,w)=>{if(l.bs!==w.bs||l.be!==w.be||l.toks.length!==w.toks.length)return!1;let C=l.ss,I=w.ss;for(let D=0;D<l.toks.length;D++){let K=l.toks[D],pe=w.toks[D];if(K.k!==pe.k||K.atom&&!g.atomAt.get(C).el.isEqualNode(x.atomAt.get(I).el))return!1;C+=K.len,I+=pe.len}return!0},H=(l,w,C,I)=>{for(let D of f.atoms){if(D.i<l.bs||D.i>=l.be||I.has(D)||st.has(D))continue;let K=w.bTo[D.i],pe=K>=0?C.atomAt.get(K):null;if(pe&&!pe.el.isEqualNode(D.el))return!0}return!1},F=[],N=re.hunks,E=ut.hunks,G=0,he=0,ve=0,u=0,v=0,j=l=>{l>ve&&(F.push({src:"base",from:ve,to:l,dL:u,dR:v}),ve=l)};for(;G<N.length||he<E.length;){let l=N[G],w=E[he],C=!!l&&(!w||l.bs<w.bs||l.bs===w.bs&&l.be<=w.be&&!w.lead);if(l&&w&&l.bs===w.bs&&oe(l)&&oe(w)){let Ct=fe(l,g),yo=fe(w,x);Ct!==yo&&(C=yo)}let I=C?l:w,D=C?w:l,K=!!D&&$(l,w),pe=!!D&&(C?!!N[G+1]&&$(N[G+1],w):!!E[he+1]&&$(l,E[he+1])),Te=!!D&&!K&&!pe&&(O===0||R(l,w)),Ve=Te,ke=ue(I,C?Z:M);if(ke==="straddle"&&(Ve=!0),!Ve&&I.be>I.bs&&(Ve=H(I,C?Se:dt,C?x:g,C?ze:De)),!Ve&&K){j(I.bs),F.push({src:"both",lfrom:l.ss,rfrom:w.ss,len:I.text.length}),ve=I.be,u+=I.text.length-(I.be-I.bs),v+=I.text.length-(I.be-I.bs),G++,he++;continue}if(!Ve){j(I.bs),F.push({src:C?"local":"remote",from:I.ss,to:I.se,inherit:ke&&ke!=="straddle"?ke:null}),ve=I.be,C?(u+=I.text.length-(I.be-I.bs),G++):(v+=I.text.length-(I.be-I.bs),he++);continue}let Ee=I.bs,lt=I.be,Ye=G,ot=he,jt=Ct=>Ct.bs<lt&&Ct.be>Ee||oe(Ct)&&(Ct.bs===Ee||Ct.bs===lt);C?Ye++:ot++,Te&&(Ee=Math.min(Ee,D.bs),lt=Math.max(lt,D.be),C?ot++:Ye++);let Nt=!0;for(;Nt;){for(Nt=!1;Ye<N.length&&jt(N[Ye]);)Ee=Math.min(Ee,N[Ye].bs),lt=Math.max(lt,N[Ye].be),Ye++,Nt=!0;for(;ot<E.length&&jt(E[ot]);)Ee=Math.min(Ee,E[ot].bs),lt=Math.max(lt,E[ot].be),ot++,Nt=!0}let rn=Ee+u,Yt=Ee+v,pn=lt-Ee,kn=lt-Ee;for(let Ct=G;Ct<Ye;Ct++)pn+=N[Ct].text.length-(N[Ct].be-N[Ct].bs);for(let Ct=he;Ct<ot;Ct++)kn+=E[Ct].text.length-(E[Ct].be-E[Ct].bs);let On=rn+pn,vn=Yt+kn;j(Ee);let Wt={kind:"text",node:e.node||null,base:io(f,Ee,lt),local:io(g,rn,On),remote:io(x,Yt,vn),resolved:null,range:null,bs:Ee,be:lt,lss:rn,lse:On,rss:Yt,rse:vn};Wt.resolved=n==="local"?Wt.local:n==="remote"?Wt.remote:Wt.local+Wt.remote,n!=="remote"&&F.push({src:"local",from:rn,to:On,conflict:Wt}),n!=="local"&&F.push({src:"remote",from:Yt,to:vn,conflict:Wt});let Vo={site:"inline",fb:f,fl:g,fr:x,scope:e.scope||null,synthetic:!!e.synthetic,full:le,merged:d};b.push(Vo),h(Wt,Vo),ve=lt,u+=pn-(lt-Ee),v+=kn-(lt-Ee),G=Ye,he=ot}j(O);let U=f.text,V=[];if(re.respell.size||ut.respell.size){let l=Mr(ge),w=[];for(let C=0;C<ge.length;C++){let I=ge[C].raw,D=re.respell.get(C)??I,K=ut.respell.get(C)??I;(D!==I||K!==I)&&V.push([l[C],D!==I&&K!==I?"both":D!==I?"local":"remote"]),w.push(D===K?D:D===I?K:K===I||n==="local"?D:K)}U=w.join("")}let W="",Y=[],ie=[],Ne=[],Le=[];for(let l of F){let w=W.length;if(l.src==="base"){for(let C=l.from;C<l.to;C++)Y.push(C),ie.push(C+l.dL),Ne.push(C+l.dR),Le.push(l);W+=U.slice(l.from,l.to)}else if(l.src==="both"){for(let C=0;C<l.len;C++)Y.push(-1),ie.push(l.lfrom+C),Ne.push(l.rfrom+C),Le.push(l);W+=g.text.slice(l.lfrom,l.lfrom+l.len)}else{let C=l.src==="local"?g:x;for(let I=l.from;I<l.to;I++)Y.push(-1),ie.push(l.src==="local"?I:-1),Ne.push(l.src==="remote"?I:-1),Le.push(l);W+=C.text.slice(l.from,l.to)}l.ms=w,l.me=W.length,l.conflict&&(l.conflict.range||(l.conflict.range=[w,w]),l.conflict.range[1]=W.length)}let Me=W.length,Ze=new Int32Array(O+1).fill(-1),je=new Int32Array(g.text.length+1).fill(-1),Ot=new Int32Array(x.text.length+1).fill(-1);for(let l=0;l<Me;l++)Y[l]>=0&&(Ze[Y[l]]=l),ie[l]>=0&&(je[ie[l]]=l),Ne[l]>=0&&(Ot[Ne[l]]=l);let Ue=(l,w)=>{let C=-1,I=-1;for(let D=l.from;D<l.to;D++){let K=w[D];K>=0&&(C<0&&(C=K),I=K+1)}return C<0?null:[C,I]},ht=[],it=[];for(let l of new Set(Tt.values()))l.new==="local"?ht.push(l):l.new==="remote"&&it.push(l);let Kt=(l,w)=>{l.remote=w.remote,l.remoteMark=w.remoteMark,l.new="both",w.merged=l,Tt.set(w.remote,l)};if(ht.length&&it.length){let l=e.idOf;for(let w of ht){let C=l?l.local(w.local):null;if(!C)continue;let I=it.find(D=>!D.merged&&D.tag===w.tag&&!!D.block==!!w.block&&l.remote(D.remote)===C);I&&Kt(w,I)}for(let w of ht){if(w.remote)continue;let C=Ue(w.localMark,je);if(C)for(let I of it){if(I.merged||I.tag!==w.tag||!!I.block!=!!w.block)continue;let D=Ue(I.remoteMark,Ot);if(D&&Math.min(C[1],D[1])-Math.max(C[0],D[0])>0){Kt(w,I);break}}}}Et.clear();let Rt=l=>{for(let w of l)if(w.block)return Xt(Tt.get(w.el));return null},qt=f.marks.some(l=>l.block)||g.marks.some(l=>l.block)||x.marks.some(l=>l.block),It=new Array(Me).fill(null),at=new Set;if(qt){let l=(ke,Ee,lt)=>{let Ye=new Set([ke,Ee,lt]);Ye.delete(null);let ot=[];for(let Nt of Ye){let rn=Nt===ke,Yt=Nt===Ee,pn=Nt===lt;(Yt===pn?Yt:Yt===rn?pn:Yt)&&ot.push(Nt)}if(ot.length<=1)return ot[0]||null;let jt=n==="local"?Ee:lt;return ot.includes(jt)?jt:ot[0]},w=(ke,Ee)=>Ee>=0?Rt(ke.stackAt[Ee]):null,C=new Map;for(let ke=0;ke<Me;ke++){if(W[ke]!==gt)continue;let Ee=Y[ke]>=0?w(f,Y[ke]):null,lt=w(g,ie[ke]),Ye=w(x,Ne[ke]);C.set(ke,[Ee,Y[ke]>=0?l(Ee,lt,Ye):lt||Ye])}let I=new Set([...C.values()].map(ke=>ke[1])),D=ke=>ke!==gt&&ke!==co&&!/\s/.test(ke),K=(ke,Ee)=>{let lt=ke;for(;lt<Ee&&!D(W[lt]);)lt++;return lt<Ee&&Y[lt]>=0?w(f,Y[lt]):null},pe=new Map,Te=0;for(let ke=0;ke<Me;ke++){if(W[ke]!==gt)continue;let[Ee,lt]=C.get(ke),Ye=K(Te,ke),ot=lt,jt=pe.get(ot)===ot&&Ye===ot;ot&&pe.has(ot)&&!jt&&Ee&&!pe.has(Ee)&&!I.has(Ee)&&(ot=Ee),ot&&!pe.has(ot)&&pe.set(ot,Ye);for(let Nt=Te;Nt<=ke;Nt++)It[Nt]=ot;Te=ke+1}let Ve=ke=>{for(let Ee=0;Ee<ke.text.length;Ee++)if(D(ke.text[Ee])&&!w(ke,Ee))return!0;return!1};if(!Ve(f)&&!Ve(g)&&!Ve(x)){let ke=[],Ee=0;for(let Ye=0;Ye<Me;Ye++)(W[Ye]===gt||Ye===Me-1)&&(ke.push([Ee,Ye]),Ee=Ye+1);let lt=new Set(It);for(let Ye=0;Ye<ke.length;Ye++){let[ot,jt]=ke[Ye];if(It[jt])continue;let Nt=ot;for(;Nt<=jt&&!D(W[Nt]);)Nt++;if(Nt>jt)continue;let rn=w(f,Y[Nt]),Yt=w(g,ie[Nt]),pn=w(x,Ne[Nt]),kn=l(rn,Yt,pn)||Yt||pn||rn;if(kn&&!lt.has(kn)){lt.add(kn);for(let Wt=ot;Wt<=jt;Wt++)It[Wt]=kn;continue}let On=Ye>0&&It[ke[Ye-1][1]],vn=Ye+1<ke.length&&It[ke[Ye+1][1]];if(On)at.add(ke[Ye-1][1]);else if(vn&&W[jt]===gt)at.add(jt);else continue;for(let Wt=ot;Wt<=jt;Wt++)It[Wt]=On||vn}}}let St=new Map,At=l=>{let w=St.get(l);if(w)return w;w=[1/0,-1/0];for(let[C,I]of[[l.baseMark,Ze],[l.localMark,je],[l.remoteMark,Ot]]){let D=C&&Ue(C,I);D&&(w[0]=Math.min(w[0],D[0]),w[1]=Math.max(w[1],D[1]))}return St.set(l,w),w},Ht=(l,w,C)=>{let I=-1,D=-1;for(let K=0;K<l.length;K++){let pe=Tt.get(l[K].el);pe===w&&(I=K),pe===C&&(D=K)}return I>=0&&D>=0?I-D:0},Zt=(l,w)=>[...l].sort((C,I)=>{for(let pe of w){let Te=Ht(pe,C,I);if(Te)return Te}let D=At(C),K=At(I);return D[0]-K[0]||K[1]-D[1]||C.rank-I.rank||C.id-I.id}),un=new Map,In=new Map,Cn=l=>{let w=Y[l],C=ie[l],I=Ne[l],D=Le[l];if(w>=0){let Ye=f.stackAt[w],ot=g.stackAt[C],jt=x.stackAt[I],Nt=un.get(Ye);Nt||un.set(Ye,Nt=new Map);let rn=Nt.get(ot);rn||Nt.set(ot,rn=new Map);let Yt=rn.get(jt);if(Yt)return Yt;let pn=Lt(Ye),kn=Lt(ot),On=Lt(jt),vn=new Set;for(let Wt of new Set([...pn,...kn,...On])){let Vo=pn.has(Wt),Ct=kn.has(Wt),yo=On.has(Wt);(Ct===yo?Ct:Ct===Vo?yo:Ct)&&vn.add(Wt)}return Yt=Zt(vn,[ot,jt,Ye]),rn.set(jt,Yt),Yt}if(D.src==="both"){let Ye=g.stackAt[C],ot=x.stackAt[I];return Zt(new Set([...Lt(Ye),...Lt(ot)]),[Ye,ot])}let pe=(D.src==="local"?g:x).stackAt[D.src==="local"?C:I];if(!D.inherit)return Zt(Lt(pe),[pe]);let Te=In.get(D);Te||In.set(D,Te=new Map);let Ve=Te.get(pe);if(Ve)return Ve;let ke=new Set(Lt(pe));for(let Ye of D.inherit.added)ke.add(Xt(Ye));for(let Ye of D.inherit.removed)ke.delete(Xt(Ye));let Ee=D.src==="local"?x:g,lt=(D.src==="local"?Se.bTo:dt.bTo)[D.inherit.bs];return Ve=Zt(ke,[pe,Ee.stackAt[lt]]),Te.set(pe,Ve),Ve},xn=new Int32Array(g.text.length+1);xn[g.text.length]=Me;for(let l=g.text.length-1;l>=0;l--)xn[l]=je[l]>=0?je[l]:xn[l+1];yc.caret+=g.text.length;let cn=l=>l<=0?0:(l>g.text.length&&(l=g.text.length),je[l-1]>=0?je[l-1]+1:xn[l]),zt=[],X=[],Re=null,Ae=[],Ge="",ct=-1,He=l=>{Re?Re.appendChild(l):zt.push(l)},$e=l=>{if(!Ge)return;let w=t.createTextNode(Ge);He(w),X.push({node:w,ms:ct,me:l,local:[],u:Ae.length?Ae[Ae.length-1].u:null}),Ge=""},et=new Set,_e=new Map,nt=new Set,en=l=>{let w=t.createElement(l.tag);if(l.block&&_t.add(w),!_e.has(l)){_e.set(l,w),ce(l.base,l.local,l.remote,w),i.set(w,{base:l.base,local:l.local,remote:l.remote});let I=(pe,Te)=>A&&l[Te]&&pe.reverse.get(l[Te])?Te:null,D=!l.base&&(I(o,"local")||I(r,"remote"));if(D){let pe=D==="local"?o.reverse.get(l.local):r.reverse.get(l.remote),Te=i.get(w);Te.local=Te.local||o.map.get(pe)||null,Te.remote=Te.remote||r.map.get(pe)||null,a.push({kind:"move",el:w,source:D})}else l.base||a.push({kind:"insert",el:w,source:l.local&&l.remote?"both":l.local?"local":"remote"});let K=i.get(w);K.local&&(nt.has(K.local)?K.local=null:nt.add(K.local))}else{let I=_e.get(l);for(let D of I.attributes)D.name!=="id"&&D.name!=="data-id"&&q(w,D,D.value);i.set(w,{base:null,local:null,remote:null})}He(w),Ae.push({u:l,el:w}),Re=w},Vn=new Set,dn=new Map;for(let l of g.pins){let w=cn(l.i);dn.has(w)||dn.set(w,[]),dn.get(w).push(l)}let ln=l=>{let w=dn.get(l);if(w){$e(l);for(let C of w){let I=C.el.namespaceURI&&C.el.namespaceURI!=="http://www.w3.org/1999/xhtml"?t.createElementNS(C.el.namespaceURI,C.el.tagName):t.createElement(C.el.tagName);i.set(I,{base:null,local:C.el,remote:null,pinned:!0}),Vn.add(I),He(I)}}},Wn=f.atoms.length||g.atoms.length||x.atoms.length,Je=l=>{if(!Wn)return null;let w=Y[l]>=0?f.atomAt.get(Y[l]):null,C=ie[l]>=0?g.atomAt.get(ie[l]):null,I=Ne[l]>=0?x.atomAt.get(Ne[l]):null;return w||C||I?{ab:w,al:C,ar:I}:null},ft=(l,w,C,I)=>{if(!l||!A)return null;let D=Q.get(w.reverse.get(l.el))||null;return!D||D===I||(I?D.el.isEqualNode(I.el):C.bTo[D.i]>=0)?null:D},me=(l,w)=>{if(!l||!A||!e.moveIn)return null;let C=w.reverse.get(l.el);return C&&!Q.has(C)?C:null},Ie=(l,w)=>{let C=new Map;for(let I of l.atoms)C.set(w(I),(C.get(w(I))||0)+1);return C},qe=Ie(f,we),tt=Ie(g,ne),Ke=Ie(x,_),kt=l=>{let w=we(l);return qe.get(w)===1&&(tt.get(w)||0)<=1&&(Ke.get(w)||0)<=1},yt=new Map,Pt=new Set,Ft=new Set,on=new Set;for(let l=0;l<Me;l++){let w=Je(l);if(!w)continue;let{ab:C,al:I,ar:D}=w,K=ft(D,r,Se,C),pe=ft(I,o,dt,C),Te=C,Ve=null;if(K?(Te=K,Ve="remote"):pe&&(Te=pe,Ve="local"),Te){Pt.has(Te)?yt.set(l,{dup:Te.el}):(Pt.add(Te),yt.set(l,{bk:Te,from:Ve,al:I,ar:D}));continue}let ke=me(D,r),Ee=me(I,o),lt=ke||Ee;if(lt){Ft.has(lt)?yt.set(l,{dup:lt}):(Ft.add(lt),yt.set(l,{moveIn:lt,side:ke?"remote":"local",sideEl:ke?D.el:I.el}));continue}let Ye=(jt,Nt)=>jt&&A&&Q.get(Nt.reverse.get(jt.el))||null,ot=Ye(D,r)||Ye(I,o);if(ot&&(on.add(ot),Le[l].conflict&&kt(ot))){if(Pt.has(ot)){yt.set(l,{dup:ot.el});continue}Pt.add(ot)}yt.set(l,{al:I,ar:D})}let vt=new Map,Ln=(l,w)=>{if(l[w]>=0)return l[w];for(let C=w-1;C>=0;C--)if(l[C]>=0)return l[C]+1;return 0};if(A)for(let l of f.atoms){if(Pt.has(l)||on.has(l))continue;let w=o.map.get(l.el)||null,C=r.map.get(l.el)||null,I=w&&ae.get(w),D=C&&be.get(C);if(w&&!I||C&&!D)continue;let K=!(I&&D)&&st.has(l);if(!K&&!(I&&D&&kt(l)))continue;let pe=n==="local"?[[I,je],[D,Ot]]:[[D,Ot],[I,je]],[Te,Ve]=pe.find(([Ee])=>Ee),ke=Ln(Ve,Te.i);vt.has(ke)||vt.set(ke,[]),vt.get(ke).push({a:l,lt:w,rt:C,edited:K}),Pt.add(l)}if(A&&e.moveIn){let l=[[g,o,je,"local"],[x,r,Ot,"remote"]];n!=="local"&&l.reverse();for(let[w,C,I,D]of l)for(let K of w.atoms){let pe=me(K,C);if(!pe||Ft.has(pe))continue;Ft.add(pe);let Te=Ln(I,K.i);vt.has(Te)||vt.set(Te,[]),vt.get(Te).push({move:pe,side:D,sideEl:K.el})}}let Ut=l=>{let w=vt.get(l);if(w){if($e(l),w.some(C=>Qe(C.move?C.sideEl:C.a.el)))for(;Ae.length;)Ae.pop(),Re=Ae.length?Ae[Ae.length-1].el:null;for(let{a:C,lt:I,rt:D,edited:K,move:pe,side:Te,sideEl:Ve}of w){if(pe){let Ee=e.moveIn(pe,Te,Ve);Ee&&He(Ee);continue}et.add(C);let ke=xe(C.el,I,D);K&&(h({kind:"structure",el:ke,detail:"edit-beats-delete",base:C.el},{subject:C.el,deleted:I?"remote":"local"}),a.push({kind:"insert",el:ke,source:I?"local":"remote"})),He(ke)}}},_t=new Set,an=s.length>m;for(let l=0;l<Me;l++){let w=Je(l),I=!!w&&Qe((w.ab||w.al||w.ar).el)?[]:It[l]?[It[l],...Cn(l)]:Cn(l),D=0;for(;D<Ae.length&&D<I.length&&Ae[D].u===I[D];)D++;if(D<Ae.length)for($e(l);Ae.length>D;)Ae.pop(),Re=Ae.length?Ae[Ae.length-1].el:null;if(ln(l),Ut(l),I.length>Ae.length)for($e(l);Ae.length<I.length;)en(I[Ae.length]);if(W[l]===gt){if(at.has(l))continue;$e(l);let K=Ae.length;for(;K>0&&!Ae[K-1].u.block;)K--;if(K>0)for(an&&d.breakOut.set(l,Ae[K-1].el);Ae.length>=K;)Ae.pop(),Re=Ae.length?Ae[Ae.length-1].el:null;continue}if(w){$e(l);let K=yt.get(l),pe;if(K.dup){h({kind:"structure",el:null,detail:"both-moved",base:K.dup},{subject:K.dup});continue}if(K.moveIn){if(pe=e.moveIn(K.moveIn,K.side,K.sideEl),!pe)continue}else if(K.bk){let Te=K.bk;if(et.add(Te),Te===w.ab)pe=xe(Te.el,K.al.el,K.ar.el);else{let Ve=o.map.get(Te.el)||null,ke=r.map.get(Te.el)||null;pe=xe(Te.el,Ve,ke),(!Ve||!ke)&&h({kind:"structure",el:null,detail:"move-beats-delete",base:Te.el},{subject:Te.el,deleted:Ve?"remote":"local"}),a.push({kind:"move",el:pe,source:K.from})}}else K.al?(pe=te(K.al.el,"local"),K.ar&&(i.get(pe).remote=K.ar.el),a.push({kind:"insert",el:pe,source:K.ar?"both":"local"})):(pe=te(K.ar.el,"remote"),a.push({kind:"insert",el:pe,source:"remote"}));an&&d.atomOut.set(l,pe),He(pe);continue}Ge||(ct=l),Ge+=W[l]}if($e(Me),(dn.has(Me)||vt.has(Me))&&(Ae.length=0,Re=null,ln(Me),Ut(Me)),Me===0&&(g.placeholder||x.placeholder||f.placeholder)){let l=t.createElement("br");i.set(l,{base:f.placeholder,local:g.placeholder,remote:x.placeholder}),zt.push(l)}let bn=0,Uo=l=>{for(;bn>0&&X[bn-1].me>=l;)bn--;for(;bn<X.length&&X[bn].me<l;)bn++;let w=X[bn];if(!w)return X[X.length-1]||null;let C=X[bn+1];return w.me===l&&C&&C.ms===l?C:w},Zn=new Map,bo={},Pe=(l,w,C)=>{let I=Uo(l)||(C?bo:null);if(!I)return;let D=Zn.get(I)||{l:!1,r:!1};w!=="remote"&&(D.l=!0),w!=="local"&&(D.r=!0),Zn.set(I,D)},pt=l=>{if(l.conflict)return!0;let w=l.src==="local"?g.text:l.src==="remote"?x.text:"";for(let C=l.from;C<l.to;C++)if(w[C]!==co&&w[C]!==gt)return!0;return!1};for(let l of F)l.src!=="base"&&Pe(l.ms,l.conflict?"both":l.src,pt(l));for(let[l,w]of V)Ze[l]>=0&&Pe(Ze[l],w);for(let l of X.length?X:[bo]){let w=Zn.get(l);w&&a.push({kind:"text",node:l.node||null,source:w.l&&w.r?"both":w.l?"local":"remote"})}for(let l of nn){if(_e.has(l))continue;let w=!l.local&&!(A&&o.map.get(l.base)),C=!l.remote&&!(A&&r.map.get(l.base));!w&&!C||a.push({kind:"remove",source:w&&C?"both":w?"local":"remote",base:l.base})}let Mt=(l,w,C)=>{if(w<=l)return!1;for(let I=l;I<w;I++)if(C[I]>=0)return!1;return!0};for(let l of nn)for(let w of["local","remote"]){let C=l[w+"Mark"],I=l.baseMark;if(!C)continue;let D=w==="local"?dt:Se;if(!Mt(I.from,I.to,D.bTo)||!Mt(C.from,C.to,D.toB))continue;let K=(w==="local"?N:E).find(pe=>pe.ss<=C.from&&C.from<pe.se);K&&(K.be<=I.from||K.bs>=I.to)&&a.push({kind:"move",el:_e.get(l)||null,source:w})}let xt=l=>{let w=Tt.get(l.node.parentNode);return w?Xt(w):null};for(let l of g.nodes){let w=-1;for(let I=l.s;I<l.e;I++)if(je[I]>=0){w=je[I];break}let C;if(w>=0)C=Uo(w);else{let I=cn(l.s),D=xt(l);C=X.find(K=>K.u===D&&K.me>=I)||X.filter(K=>K.u===D).pop()}C&&C.local.push(l)}let mt=new Map,yn=X[X.length-1]||null,Vt=0;for(let l of g.nodes){let w=null;for(let C=l.s;C<=l.e;C++){let I=cn(C);for(;Vt>0&&X[Vt-1].me>=I;)Vt--;for(;Vt<X.length&&X[Vt].me<I;)Vt++;let D=pe=>pe&&I>=pe.ms&&I<=pe.me&&(I<pe.me||C===l.e||pe===w),K=D(X[Vt])?X[Vt]:D(X[Vt+1])?X[Vt+1]:X[Vt]||yn;if(!K)break;if(w===K){let pe=mt.get(K);pe[pe.length-1].to=C-l.s;continue}w=K,mt.has(K)||mt.set(K,[]),mt.get(K).push({node:l.node,from:C-l.s,to:C-l.s,flatStart:l.s})}}for(let l of X){let w=l.local,C=!1;for(let pe of w)for(let Te=pe.s;Te<pe.e&&!C;Te++)(je[Te]<l.ms||je[Te]>=l.me)&&(C=!0);i.set(l.node,{base:null,local:w.map(pe=>pe.node),remote:null,caret:mt.get(l)||[],partial:C});let I=l.ms,D=l.me-l.ms,K=pe=>{let Te=0,Ve=-1;for(let ke of w){let Ee=ke.e-ke.s;if(pe<=Te+Ee){Ve=ke.s+(pe-Te);break}Te+=Ee}return Ve<0&&(Ve=w.length?w[w.length-1].e:0),Math.max(0,Math.min(cn(Ve)-I,D))};K.flat=pe=>Math.max(0,Math.min(cn(pe)-I,D)),c.set(l.node,K)}function Rn(){if(!g.text.includes(gt))return[{flatLocal:g.text,localNodes:g.nodes,textNodes:X,lToM:je,mapLocal:cn}];let l=[],w=0,C=0;for(let I=0;I<=g.text.length;I++){if(I<g.text.length&&g.text[I]!==gt)continue;let D=w,K=I;if(K>D){let pe=[];for(;C<g.nodes.length&&g.nodes[C].e<=D;)C++;for(let Te=C;Te<g.nodes.length&&g.nodes[Te].s<K;Te++){let Ve=g.nodes[Te],ke=Math.max(Ve.s,D),Ee=Math.min(Ve.e,K);ke<Ee&&pe.push({node:Ve.node,s:ke-D,e:Ee-D})}l.push({flatLocal:g.text.slice(D,K),localNodes:pe,textNodes:X,lToM:je.subarray?je.subarray(D,K+1):je.slice(D,K+1),mapLocal:Te=>cn(D+Math.max(0,Math.min(Te,K-D)))})}w=I+1}return l}let Tn={...e,blocks:_t,ignored:l=>Vn.has(l)||(e.ignored?e.ignored(l):!1)},Gt=e.ignoreAttribute||(()=>!1),_o=Ns(En(zt,Tn),Gt)!==Ns(x,Gt);if(b.length){let l=w=>{let C=i.get(w);return C&&C.unchanged?C.remote:null};d.text=W,d.textNodes=X,d.out=En(zt,{...Tn,via:l})}return{nodes:zt,text:W,textNodes:X,localDiverged:_o,mapLocal:cn,conflicts:s.slice(m),granularity:We?"line":"word",segments:Rn(),localHunks:N,remoteHunks:E,lToM:je}}var Ac="http://www.w3.org/1999/xhtml";function Sc(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function tn(e){return!!e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.namespaceURI===Ac}function Nc(e){let t=(e.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Jo(e,t){let n=e.getAttribute("src"),o=(e.getAttribute("type")||"text/javascript").split(";")[0].trim().toLowerCase();if(n){let r=n;try{let i=new URL(n,t);r=i.origin+i.pathname+i.search}catch{}return"script|src|"+o+"|"+r}return"script|inline|"+o+"|"+Sc(e.textContent.trim())}var Oc={match:e=>e.hasAttribute("merge"),identity:e=>e.getAttribute("merge")};function lo(e,t=[],n=!1){if(!tn(e)||e.hasAttribute("src"))return null;let o=[Oc,...t];for(let r=0;r<o.length;r++){let i=o[r];if(!i.match(e))continue;if(!Nc(e))return n&&console.warn("[hyper-morph] merge ignored: script type is not JSON",e),null;let c=i.identity(e);return c==null||c===""?null:{key:r+":"+c,raw:c,recognizer:i}}return null}function Ls(e,t,n){let o=new Set,r=i=>{tn(i)&&!t(i)&&o.add(Jo(i,n))};r(e);for(let i of e.querySelectorAll("script"))r(i);return o}function To(e,t){let n=t.createElement("div");n.innerHTML="<script><\/script>";let o=n.firstChild;for(let r of e.attributes)o.setAttribute(r.name,r.value);return o.textContent=e.textContent,o}function Rs(e,t,n){let o=[],r=[],i=new Map,c=n.trackRecovery?new Set:null,s=Array.from(e.querySelectorAll("script"));tn(e)&&s.unshift(e);for(let a of s){if(!tn(a)||n.ignored(a)||n.skip.has(a)||t.has(Jo(a,n.baseURI)))continue;let m=a.ownerDocument.createElement("script");for(let h of a.attributes)m.setAttribute(h.name,h.value);if(m.textContent=a.textContent,n.beforeNodeAdded(m)===!1){c?.add(a);continue}m.hasAttribute("src")&&r.push(new Promise(h=>{m.addEventListener("load",()=>h()),m.addEventListener("error",()=>h())})),a.replaceWith(m),i.set(a,m),n.afterNodeAdded(m),o.push(m)}return{executed:o,loads:r,swapped:i,vetoed:c}}function vc(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Mc(e,t){try{let n=new URL(e,t);return n.origin+n.pathname+n.search}catch{return e}}function Ps(e,t){let n=e.tagName;if(n==="TITLE"||n==="BASE")return n;if(n==="SCRIPT")return Jo(e,t);if(n==="LINK"){let o=e.getAttribute("href");return o?"link|"+(e.getAttribute("rel")||"")+"|"+Mc(o,t):e.outerHTML}if(n==="META"){for(let o of["charset","name","property","http-equiv","itemprop"])if(e.hasAttribute(o))return"meta|"+o+"="+e.getAttribute(o);return e.outerHTML}return n==="STYLE"?"style|"+vc(e.textContent):e.outerHTML}function Cr(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
|
|
5
|
+
`;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function Ec(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var Ic=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Cc=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Lr(e){try{return JSON.parse(e)}catch{return JSON.parse(Lc(e))}}function Lc(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=Cr(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=Cr(e,n+1);if(e[s]==="}"||e[s]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let s=n+1;for(;s<e.length&&e[s]!==r;)e[s]==="\\"&&s++,s++;s>=e.length&&o("unterminated string",n);let a=e.slice(n+1,s);r==="'"&&(a=Ec(a)),t+='"'+a+'"',n=s+1;continue}let i=n;for(;i<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[i]);)i++;i===n&&o("unexpected character "+JSON.stringify(r),n);let c=e.slice(n,i);if(c==="true"||c==="false"||c==="null"||Ic.test(c)){t+=c,n=i;continue}if(Cc.test(c)){if(e[Cr(e,i)]===":"){t+='"'+c+'"',n=i;continue}o("unquoted value "+JSON.stringify(c),n)}o("invalid token "+JSON.stringify(c),n)}return t}var Dt=Symbol("hyper-morph-json-merge:missing"),js=["id","_id","uuid","key","slug","code","name"];function ao(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ao(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Rc(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function Hn(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Hn(e[n],t[n]))return!1;return!0}if(ao(e)&&ao(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Ao(t,o)||!Hn(e[o],t[o]))return!1;return!0}return!1}function Ds(e,t,n,o){return Hn(t,n)?t:Hn(t,e)?n:Hn(n,e)?t:ao(t)&&ao(n)?Pc(ao(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?Bc(Array.isArray(e)?e:[],t,n,o):n}function Hs(e,t,n,o){return t===Dt&&n===Dt?Dt:t===Dt?e===Dt?n:Hn(n,e)?Dt:n:n===Dt?e===Dt?t:Dt:Ds(e,t,n,o)}function Pc(e,t,n,o){let r={},i=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let c of i){let s=Hs(Ao(e,c)?e[c]:Dt,Ao(t,c)?t[c]:Dt,Ao(n,c)?n[c]:Dt,o);s!==Dt&&Rc(r,c,s)}return r}function jc(e){return e===null||typeof e!="object"}function Xo(e){return typeof e+":"+String(e)}function Dc(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Ao(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let c=Xo(i);if(o.has(c))return!1;o.add(c)}}return!0}function Hc(e,t,n,o){let r=[e,t,n],i=!0;for(let c of r)for(let s of c)ao(s)||(i=!1);if(i){for(let c of o.keyCandidates)if(Dc(c,r))return{kind:"keyed",field:c};return null}for(let c of r){let s=new Set;for(let a of c){if(!jc(a))return null;let m=Xo(a);if(s.has(m))return null;s.add(m)}}return{kind:"self"}}function Bc(e,t,n,o){let r=Hc(e,t,n,o);if(!r)return n;let i=r.kind==="self"?Xo:A=>Xo(A[r.field]),c=A=>{let S=new Map;for(let L of A)S.set(i(L),L);return S},s=c(e),a=c(t),m=c(n),h=new Map,d=new Set([...s.keys(),...a.keys(),...m.keys()]);for(let A of d){let S=Hs(s.has(A)?s.get(A):Dt,a.has(A)?a.get(A):Dt,m.has(A)?m.get(A):Dt,o);S!==Dt&&h.set(A,S)}let b=[];for(let A of n){let S=i(A);h.has(S)&&b.push(S)}for(let A=0;A<t.length;A++){let S=i(t[A]);if(!h.has(S)||b.includes(S))continue;let L=0;for(let f=A-1;f>=0;f--){let g=b.indexOf(i(t[f]));if(g!==-1){L=g+1;break}}b.splice(L,0,S)}return b.map(A=>h.get(A))}function Bs(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...js]:js;return Ds(e===void 0?Dt:e,t,n,{keyCandidates:r})}function Rr(e,t,n,o={}){let r=o.parse||Lr,i=[],c=(d,b)=>{if(typeof d!="string")return Dt;try{return r(d)}catch(A){return i.push(`${b} side is not valid JSON (${A.message})`),Dt}},s=c(t,"local"),a=c(n,"remote");if(s===Dt)return{text:n,warnings:i};if(a===Dt)return{text:t,warnings:i};let m=c(e,"base"),h=Bs(m===Dt?void 0:m,s,a,o);return Hn(h,a)?{text:n,warnings:i}:Hn(h,s)?{text:t,warnings:i}:{text:JSON.stringify(h,null,2),warnings:i}}var Us=e=>e.nodeType===3||e.nodeType===8?e.nodeValue.length:e.childNodes.length;function Kn(e){if(!e)return!1;let{startContainer:t,startOffset:n,endContainer:o,endOffset:r}=e;if(!t||!o||!Number.isInteger(n)||!Number.isInteger(r)||n<0||r<0||n>Us(t)||r>Us(o)||t.getRootNode()!==o.getRootNode())return!1;let i=t.ownerDocument.createRange();return i.setStart(t,n),i.setEnd(o,r),i.startContainer===t&&i.startOffset===n}function Bn(e,t,n={}){if(!Kn(e))return null;let{startContainer:o,startOffset:r,endContainer:i,endOffset:c}=e;if(o===i&&(o.nodeType===3||o.nodeType===8))return o.nodeValue.slice(r,c);if(o===i&&r===c)return"";let s=new Set;for(let f=o;f;f=f.parentNode)s.add(f);let a=i;for(;!s.has(a);)a=a.parentNode;let m=(f,g)=>{let x=a.ownerDocument.createRange(),Q=a.ownerDocument.createRange();return x.setStart(f[0],f[1]),x.collapse(!0),Q.setStart(g[0],g[1]),Q.collapse(!0),x.compareBoundaryPoints(0,Q)},h=(f,g=!1)=>[f.parentNode,Array.prototype.indexOf.call(f.parentNode.childNodes,f)+Number(g)],d=[],b;if(t==="plain"){b="";let f=g=>{if(g.nodeType===3||g.nodeType===8){let x=b.length;b+=g.nodeValue,d.push({s:x,e:b.length,a:[g,0],b:[g,g.nodeValue.length],node:g})}else for(let x of g.childNodes)f(x)};f(a)}else{let f=n.blocks;if(!f){f=new Set;let x=Q=>{Q!==a&&Q.nodeType===1&&Er.has(Q.tagName)&&f.add(Q);for(let se of Q.childNodes)x(se)};x(a)}let g=En(Array.from(a.childNodes),{blocks:f,atomize:x=>!!n.atoms?.has(x),ignored:n.ignored});b=g.text;for(let x of g.nodes)d.push({s:x.s,e:x.e,a:[x.node,0],b:[x.node,x.e-x.s],node:x.node});for(let x of g.atoms)d.push({s:x.i,e:x.i+1,a:h(x.el),b:h(x.el,!0)});for(let x=0;x<g.text.length;x++){if(g.text[x]!==gt)continue;let Q=g.marks.find(le=>le.block&&le.to===x+1),se=g.marks.find(le=>le.block&&le.from===x+1);if(Q)d.push({s:x,e:x+1,a:[Q.el,Q.el.childNodes.length],b:h(Q.el,!0)});else if(se)d.push({s:x,e:x+1,a:h(se.el),b:[se.el,0]});else return null}}d.sort((f,g)=>f.s-g.s);let A=f=>{if(f[0].nodeType===3||f[0].nodeType===8){let x=d.find(Q=>Q.node===f[0]);return x?x.s+f[1]:null}let g=0;for(let x of d){if(m(f,x.a)<=0)return x.s;if(m(f,x.b)<0)return null;g=x.e}return g},S=A([o,r]),L=A([i,c]);return S!==null&&L!==null&&S<=L?b.slice(S,L):null}function Fn(e,t){let n=e;for(let o of t.path)if(n=o==="content"?n?.content:n?.childNodes[o],!n)return null;return[n,t.offset]}function _s(e,t){if(!e||!t)return null;let n=Fn(e,t.start),o=Fn(e,t.end);return n&&o?{startContainer:n[0],startOffset:n[1],endContainer:o[0],endOffset:o[1]}:null}var Vs=e=>e.nodeType===1?e.outerHTML:e.nodeValue;function Ws(e,t,n){if(!t)return;let o=new Map,r=new Map,i=s=>{if(!s)return null;if(r.has(s))return r.get(s);let m=s.local.map(h=>Fn(t.localRoot,{path:h,offset:0})?.[0]).map(h=>h&&n(h)).filter(Boolean).map(h=>({node:h,parent:h.parentNode,previous:h.previousSibling,next:h.nextSibling,fragment:Vs(h)}));return r.set(s,m),m},c=s=>{let a=_s(t.localRoot,s);if(!a)return null;let m=n(a.startContainer),h=n(a.endContainer);if(!m||!h)return null;let d={...a,startContainer:m,endContainer:h};return Kn(d)?d:null};for(let s of e){let a=s.recovery;if(o.has(a))continue;let m={subject:i(a.subject),span:null,scope:null,touched:new Set};if(a.text){m.span=c(a.text.local.span),m.scope=c(a.text.local.scope);let h=m.span;if(h){let d=h.startContainer.ownerDocument.createRange();d.setStart(h.startContainer,h.startOffset),d.setEnd(h.endContainer,h.endOffset);let b=A=>{if(d.intersectsNode(A)){m.touched.add(A);for(let S of A.childNodes)b(S)}};b(d.commonAncestorContainer)}}if(a.structure){for(let h of[a.structure.localPlacement])h&&(i(h.parent),h.before.forEach(i),h.after.forEach(i));for(let h of a.structure.localOrder||[])i(h)}o.set(a,m)}t.localState={states:o,refs:r}}function $s(e,t,n,o){let r=n.localState?.states.get(e);if(!r)return!1;let i=s=>{let a=s.node;if(!o(a)||a.parentNode!==s.parent)return!1;let m=h=>Array.prototype.indexOf.call(a.parentNode.childNodes,h);return!(s.previous&&o(s.previous)&&s.previous.parentNode===a.parentNode&&m(s.previous)>=m(a)||s.next&&o(s.next)&&s.next.parentNode===a.parentNode&&m(s.next)<=m(a))};if(e.structure?.localAction==="deleted")return e.subject.live.length===0;if(!r.subject.length||!r.subject.every(i))return!1;if(e.text){let s=e.text.local,a=m=>m&&o(m.startContainer)&&o(m.endContainer);return a(r.span)&&a(r.scope)&&Bn(r.scope,e.text.encoding)===s.text&&Bn(r.span,e.text.encoding)===s.text.slice(s.start,s.end)}if(e.attribute){let s=e.attribute,a=r.subject[0].node;return(s.namespaceURI?a.getAttributeNS(s.namespaceURI,s.localName):a.getAttribute(s.qualifiedName))===t.local}let c=e.structure;if(c.localOrder){let s=-1,a=null;for(let m of c.localOrder){let h=n.localState.refs.get(m)?.[0]?.node;if(!h||!o(h)||a&&h.parentNode!==a)return!1;let d=Array.prototype.indexOf.call(h.parentNode.childNodes,h);if(d<=s)return!1;a=h.parentNode,s=d}return!0}return c.localAction==="moved"||r.subject.every(s=>Vs(s.node)===s.fragment)}var Uc=1,Jt=e=>!!e&&e.nodeType===1,Qo=e=>Jt(e)&&e.tagName==="TEMPLATE"&&!!e.content;function zn(e,t=null,n=null){let o=new Map,r=new Map,i=h=>{if(!t){t=new WeakMap;let d=[e];for(;d.length;){let b=d.pop();Qo(b)&&(t.set(b.content,b),d.push(b.content));for(let A=b.firstChild;A;A=A.nextSibling)A.nodeType===1&&d.push(A)}}return t.get(h)||null},c=(h,d)=>{let b=r.get(h);if(!b){b=new Map;let A=0;for(let S=h.firstChild;S;S=S.nextSibling)b.set(S,A++);r.set(h,b)}return b.get(d)},s=h=>{if(!h)return null;if(n&&n.has(h))return s(n.get(h));if(h===e)return[];let d=o.get(h);if(d!==void 0)return d;let b=h.parentNode,A=null;if(b&&b.nodeType===11){let S=i(b),L=S?s(S):null;L&&(A=L.concat(["content",c(b,h)]))}else if(b){let S=s(b);S&&(A=S.concat([c(b,h)]))}return o.set(h,A),A};return{root:e,pathOf:s,logicalParent:h=>{let d=h.parentNode;return d&&d.nodeType===11?i(d):d},indexIn:c,containerPath:h=>{if(h.nodeType===11){let b=i(h),A=s(b);return A?A.concat(["content"]):null}let d=s(h);return d&&Qo(h)?d.concat(["content"]):d},ownerOf:i}}var wn=e=>Qo(e)?e.content:e;function qs(e){let{L:t,R:n,unitsOf:o,provenance:r,policy:i}=e,c=[];return{note:(h,d)=>{c.push([h,d])},finish:h=>c.length?m(h):null};function m(h){let d={base:zn(e.roots.base),local:zn(e.roots.local),remote:zn(e.roots.remote)},b=y=>y==="local"?t:n,A=(y,T)=>{if(!T)return null;if(y.map.has(T))return y.map.get(T);let P=[],p=Jt(T)?d.base.logicalParent(T):T.parent;for(;p&&!y.map.has(p);p=d.base.logicalParent(p))P.push(p);if(!p||!y.identical.has(p))return null;let k=y.map.get(p);for(let R=P.length-1;R>=0&&k;R--)k=wn(k).childNodes[d.base.indexIn(P[R].parentNode,P[R])];return k?Jt(T)?wn(k).childNodes[d.base.indexIn(T.parentNode,T)]||null:o(k)[o(T.parent).indexOf(T)]||null:null},S=new Map,L=new Map,f=new WeakMap,g=0,x=(y,T)=>{let P=S.get(y);P||S.set(y,P=[]),P.push(T)};(function y(T){L.set(T,g++);let P=r.get(T);if(P&&!P.pinned){for(let p of[P.base,P.local,P.remote])if(p)if(Array.isArray(p))for(let k of p)x(k,T);else x(p,T)}if(Qo(T)){f.set(T.content,T);for(let p=T.content.firstChild;p;p=p.nextSibling)y(p)}for(let p=T.firstChild;p;p=p.nextSibling)y(p)})(h);let Q=new Map;d.out=zn(h,f,Q);let se={refs:new Map,spans:new Map,anchors:new Map,via:Q,outOwners:f,outRoot:h,localRoot:e.roots.local},le=y=>Jt(y)?[y]:y.nodes,q=(y,T)=>{let P=d[T].logicalParent(y);if(!P)return null;for(let p of o(P))if(!Jt(p)&&p.nodes.includes(y))return p;return null},z=(y,T)=>y==null?null:Array.isArray(y)?y.length?q(y[0],T):null:y,ce=y=>{let T=new Set,P=[];for(let p of y)for(let k of S.get(p)||[])T.has(k)||(T.add(k),P.push(k));return P.sort((p,k)=>L.get(p)-L.get(k))},xe=new Map,te=y=>{let T=y.b||y.l||y.r,P=xe.get(T);if(P)return P;let p=[];for(let k of[y.b,y.l,y.r])k&&p.push(...le(k));return P=ce(p),xe.set(T,P),P},J=y=>({b:y,l:A(t,y),r:A(n,y)}),Ce=(y,T)=>{let P=b(T).reverse.get(y);if(P)return J(P);for(let p of ce(le(y))){let k=r.get(p);if(k&&!k.base&&k.local&&k.remote)return{b:null,l:z(k.local,"local"),r:z(k.remote,"remote")}}return T==="local"?{b:null,l:y,r:null}:{b:null,l:null,r:y}},we=new Map,ne=y=>{let T=r.get(y);if(!T||T.pinned)return null;let P=z(T.base,"base");if(P)return J(P);let p=z(T.local,"local"),k=z(T.remote,"remote");if(p){let R=t.reverse.get(p);if(R)return J(R)}if(k){let R=n.reverse.get(k);if(R)return J(R)}return p||k?{b:null,l:p,r:k}:null},_=y=>(we.has(y)||we.set(y,ne(y)),we.get(y)),ye=(y,T)=>Jt(y)?d[T].logicalParent(y):y.parent,ge=new Map,Oe=new Map,Be=(y,T)=>(Jt(y)?[d[T].pathOf(y)]:y.nodes.map(P=>d[T].pathOf(P))).filter(Boolean),We=y=>{let T=y.b||y.l||y.r,P=y.b?"base":y.l?"local":"remote",p=Oe.get(T);if(p)return p;let k=!Jt(T),R=Be(T,P)[0],$=`${P[0]}:${JSON.stringify(R===void 0?null:R)}${k?":run":""}`,H=ge.get($);if(H)return Oe.set(T,H),H;let F=te(y);return H={key:$,nodeType:Jt(T)?1:T.kind==="comment"?8:3,base:y.b?Be(y.b,"base"):[],local:y.l?Be(y.l,"local"):[],remote:y.r?Be(y.r,"remote"):[],merged:F.map(N=>d.out.pathOf(N)).filter(Boolean),live:[]},ge.set($,H),Oe.set(T,H),se.refs.set(H,F),H},rt={base:new Map,local:new Map,remote:new Map},re=new Map,ut=(y,T)=>{let P=ye(y,T);if(!P||P.nodeType!==1)return null;let p=rt[T].get(P);if(!p){let R=o(P),$=H=>We(T==="base"?J(H):Ce(H,T));p={parent:$(P),refs:R.map($),index:new Map(R.map((H,F)=>[H,F]))},rt[T].set(P,p)}let k=p.index.get(y)??-1;return{parent:p.parent,before:p.refs.slice(k+1),after:p.refs.slice(0,Math.max(0,k)).reverse()}},dt=y=>{let T=y.parentNode;if(!T)return null;let P=re.get(T);if(!P){let k=T.nodeType===11?f.get(T):T,R=k&&k.nodeType===1?_(k):null;if(!R)return null;let $=[],H=[],F=new Map;for(let E of T.childNodes){let G=_(E),he=G&&We(G),ve=$.length,u=$.length-1;he&&he!==$[u]&&($.push(he),u++);let v={ref:he,group:u,after:ve};H.push(v),F.set(E,v)}let N=$.length;for(let E=H.length-1;E>=0;E--){let G=H[E];G.before=N,G.ref&&(N=G.group)}P={parent:We(R),refs:$,index:F},re.set(T,P)}let p=P.index.get(y);return{parent:P.parent,before:P.refs.slice(p.before),after:P.refs.slice(0,p.after).reverse()}},Se=y=>Jt(y)?y.outerHTML:y.value,O=y=>Jt(y)?"element":y.kind==="comment"?"comment":"text",B=(y,T)=>({path:y,offset:T}),ae=(y,T,P)=>{if(!y)return null;let p=d[P],k=0;if(T){let R=Jt(T)?T:T.nodes[T.nodes.length-1];R.parentNode&&(k=p.indexIn(R.parentNode,R)+1)}return B(p.containerPath(y),k)},be=(y,T)=>{let P=ye(y,"base"),p=P?A(b(T),P):null;if(!Jt(p))return null;let k=o(P),R=null;for(let $=k.indexOf(y)-1;$>=0&&!R;$--){let H=A(b(T),k[$]);H&&ye(H,T)===p&&(R=H)}return ae(p,R,T)},de=(y,T,P,p)=>{let k=d[p],R=0;for(let $=0;$<y.nodes.length;$++){let H=y.nodes[$],F=H.nodeValue.length,N=$===y.nodes.length-1;if((P==="start"?T<R+F:T<=R+F)||N)return B(k.pathOf(H),Math.max(0,Math.min(T-R,F)));R+=F}return null},ze=(y,T)=>{let P=d[T],p=y.firstChild,k=y.lastChild;return p&&p.nodeType===3&&k.nodeType===3?{start:B(P.pathOf(p),0),end:B(P.pathOf(k),k.nodeValue.length)}:{start:B(P.pathOf(y),0),end:B(P.pathOf(y),y.childNodes.length)}},De=(y,T,P)=>{for(let $ of y.nodes)if(P==="start"?$.s<=T&&T<$.e:$.s<T&&T<=$.e)return{kind:"text",node:$.node,offset:T-$.s};let p=P==="start"?T:T-1,k=()=>{for(let $ of y.nodes)if($.s===T||$.e===T)return{kind:"text",node:$.node,offset:T-$.s};return null},R=y.atomAt.get(p);if(R)return{kind:P==="start"?"before":"after",node:R.el};if(y.text[p]===gt){let $=y.marks.find(F=>F.block&&F.to===p+1);if($)return P==="start"?{kind:"end",node:$.el}:{kind:"after",node:$.el};let H=y.marks.find(F=>F.block&&F.from===p+1);if(H)return P==="start"?{kind:"before",node:H.el}:{kind:"startOf",node:H.el}}return k()},Qe=(y,T)=>De(y,T,"end")||De(y,T,"start"),st=(y,T)=>{switch(T.kind){case"text":return B(y.pathOf(T.node),T.offset);case"end":return B(y.containerPath(T.node),wn(T.node).childNodes.length);case"startOf":return B(y.containerPath(T.node),0);default:{let P=T.node.parentNode;return B(y.containerPath(P),y.indexIn(P,T.node)+(T.kind==="after"?1:0))}}},wt=(y,T,P,p,k)=>{let R=De(y,T,P);return R?st(d[p],R):k()},bt=(y,T,P,p)=>{let k=y.textNodes.map(N=>({s:N.ms,e:N.me,start:{kind:"text",node:N.node,offset:0},end:{kind:"text",node:N.node,offset:N.me-N.ms}}));for(let[N,E]of y.atomOut)k.push({s:N,e:N+1,start:{kind:"before",node:E},end:{kind:"after",node:E}});for(let[N,E]of y.breakOut)k.push({s:N,e:N+1,start:{kind:"end",node:E},end:{kind:"after",node:E}});for(let N of k)if(N.start.kind==="text"&&N.s<T&&T<N.e)return{kind:"text",node:N.start.node,offset:T-N.s};if(P!=="empty"){let N=k.find(E=>P==="start"?E.s===T:E.e===T);if(N)return P==="start"?N.start:N.end}let R=k.find(N=>N.e===T);if(R)return R.end;let $=k.find(N=>N.s===T);if($)return $.start;let H=null,F=null;for(let N of k)N.e<=T&&(!H||N.e>H.e)&&(H=N),N.s>=T&&(!F||N.s<F.s)&&(F=N);return H?H.end:F?F.start:p()},Tt=(y,T)=>{if(!T)return null;if(T.kind==="text"){let k=y.nodes.find(R=>R.node===T.node);return k?k.s+Math.min(T.offset,k.e-k.s):null}let P=y.atoms.find(k=>k.el===T.node);if(P)return T.kind==="after"?P.i+1:P.i;let p=y.marks.find(k=>k.el===T.node);return p?T.kind==="before"&&p.block&&y.text[p.from-1]===gt&&!y.marks.some(k=>k.block&&k.to===p.from)?p.from-1:T.kind==="startOf"||T.kind==="before"?p.from:T.kind==="end"&&p.block?p.to-1:p.to:null},nn=(y,T,P,p)=>{for(let H of y.nodes)if(P==="start"?H.s<=T&&T<H.e:H.s<T&&T<=H.e)return{kind:"text",node:H.node,offset:T-H.s};let k=P==="start"?T:T-1;if(!y.atomAt.has(k)&&y.text[k]!==gt){for(let H of y.nodes)if(H.s===T||H.e===T)return{kind:"text",node:H.node,offset:T-H.s}}let R=y.atomAt.get(k);if(R)return{kind:P==="start"?"before":"after",node:R.el};if(y.text[k]===gt){let H=y.marks.find(N=>N.block&&N.to===k+1);if(H)return P==="start"?{kind:"end",node:H.el}:{kind:"after",node:H.el};let F=y.marks.find(N=>N.block&&N.from===k+1);if(F)return P==="start"?{kind:"before",node:F.el}:{kind:"startOf",node:F.el}}let $=y.marks.find(H=>H.block&&H.from===T);return $?{kind:"startOf",node:$.el}:p?{kind:P==="start"?"startOf":"end",node:p}:null},Fe=y=>{if(!y)return null;if(y.kind==="wholeStart"||y.kind==="wholeEnd"){let T=Qt(y.node);return y.kind==="wholeStart"?T.start:T.end}return st(d.out,y)},Qt=y=>{let T=y.firstChild,P=y.lastChild;return T&&T.nodeType===3&&P.nodeType===3?{start:B(d.out.pathOf(T),0),end:B(d.out.pathOf(P),P.nodeValue.length)}:{start:B(d.out.pathOf(y),0),end:B(d.out.pathOf(y),y.childNodes.length)}},Xt=y=>{let T=ye(y,"base"),P=T?te(J(T))[0]:null;if(!P)return null;let p=wn(P),k=o(T);for(let R=k.indexOf(y)-1;R>=0;R--){let $=te(J(k[R])).filter(H=>H.parentNode===p);if($.length)return{kind:"after",node:$[$.length-1]}}return{kind:"startOf",node:P}},Bt=(y,T,P,p,k,R)=>({text:y,start:T,end:P,fragment:p,span:k,scope:R}),Et=(y,T,P,p,k)=>Bt(y,T,P,y.slice(T,P),p,k),Lt=(y,T,P,p,k)=>(se.spans.set(y,{start:T,end:P,scopeStart:p,scopeEnd:k}),y),sn=new Map,M=new Map,Z=(y,T,P)=>{let p=`text:${y.key}:${T}:${P}`,k=M.get(p)||0;return M.set(p,k+1),`${p}:${k}`},ee=(y,T)=>{let P,p,k,R="plain",$,H,F,N,E,G=(u,v,j,U,V)=>{if(!u){let W=be(V,U);return Et("",0,0,{start:W,end:W},{start:W,end:W})}return Et(u.value,v,j,{start:de(u,v,v===j?"end":"start",U),end:de(u,j,"end",U)},{start:de(u,0,"start",U),end:de(u,u.value.length,"end",U)})};if(T.site==="run"){let{bRun:u,lRun:v,rRun:j,node:U,c:V}=T;P=J(u),p=V.bs,k=V.be,$=G(u,V.bs,V.be,"base",u),H=G(v,V.ls,V.le,"local",u),F=G(j,V.rs,V.re,"remote",u);let W=U?U.nodeValue:"",Y=ie=>U?{kind:"text",node:U,offset:ie}:Xt(u);N=Lt(Et(W,V.ms,V.me,{start:Fe(Y(V.ms)),end:Fe(Y(V.me))},{start:Fe(Y(0)),end:Fe(Y(W.length))}),Y(V.ms),Y(V.me),Y(0),Y(W.length)),E=U||(Xt(u)||{}).node||null}else if(T.site==="whole"){let u=T.el,v=r.get(u);P=J(v.base),p=0,k=y.base.length;let j=(V,W,Y)=>{let ie=ze(W,Y);return Et(V,0,V.length,ie,ie)};$=j(y.base,v.base,"base"),H=j(y.local,v.local,"local"),F=j(y.remote,v.remote,"remote");let U=Qt(u);N=Lt(Et(y.resolved,0,y.resolved.length,U,U),{kind:"wholeStart",node:u},{kind:"wholeEnd",node:u},{kind:"wholeStart",node:u},{kind:"wholeEnd",node:u}),E=u}else if(T.site==="comment"){let{bRun:u,lRun:v,rRun:j,node:U}=T;P=J(u),p=0,k=y.base.length;let V=(Ne,Le)=>{if(!Ne){let je=be(u,Le);return Et("",0,0,{start:je,end:je},{start:je,end:je})}let Me=Ne.nodes[0],Ze={start:B(d[Le].pathOf(Me),0),end:B(d[Le].pathOf(Me),Ne.value.length)};return Et(Ne.value,0,Ne.value.length,Ze,Ze)};$=V(u,"base"),H=V(v,"local"),F=V(j,"remote");let W=y.resolved,Y=Ne=>U?{kind:"text",node:U,offset:Ne}:Xt(u),ie={start:Fe(Y(0)),end:Fe(Y(W.length))};N=Lt(Et(W,0,W.length,ie,ie),Y(0),Y(W.length),Y(0),Y(W.length)),E=U||(Xt(u)||{}).node||null}else{let{fb:u,fl:v,fr:j,scope:U}=T,V=T.merged;R="html",P=U.base?J(U.base):Ce(U.local,"local"),p=y.bs,k=y.be;let W=at=>{let St=U[at];for(let At=U.at-1;At>=0;At--){let Ht=U.units[At],Zt=at==="base"?Ht:A(b(at),Ht);if(Zt&&ye(Zt,at)===St)return Zt}return null},Y=at=>()=>ae(U[at],W(at),at),ie=(at,St,At,Ht,Zt)=>{let un=He=>He?st(d[Zt],He):Y(Zt)(),In=St===At?Qe(at,St):De(at,St,"start"),Cn=St===At?Qe(at,St):De(at,At,"end"),xn=un(In),cn={start:xn,end:St===At?xn:un(Cn)},zt=T.full?T.full(Zt):null;if(!zt)return Bt(at.text,St,At,Ht,cn,{start:un(De(at,0,"start")),end:un(De(at,at.text.length,"end"))});let X=In?Tt(zt,In):null,Re=Cn?Tt(zt,Cn):null,Ae=X===null?0:X,Ge=Math.max(Ae,Re===null?zt.text.length:Re),ct=un(De(zt,0,"start"));return Bt(zt.text,Ae,Ge,io(zt,Ae,Ge),cn,{start:ct,end:zt.text.length?un(De(zt,zt.text.length,"end")):ct})};$=T.synthetic?null:ie(u,y.bs,y.be,y.base,"base"),H=ie(v,y.lss,y.lse,y.local,"local"),F=ie(j,y.rss,y.rse,y.remote,"remote");let[Ne,Le]=y.range||[0,0],Me=V.out,Ze=()=>{let at=wn(V.node);for(let St=U.at-1;St>=0;St--){let At=te(J(U.units[St])).filter(Ht=>Ht.parentNode===at);if(At.length)return{kind:"after",node:At[At.length-1]}}for(let St=U.at;St<U.units.length;St++){let At=te(J(U.units[St])).filter(Ht=>Ht.parentNode===at);if(At.length)return{kind:"before",node:At[0]}}return{kind:"startOf",node:V.node}};if(Me.via)for(let[at,St]of Me.via)Q.set(at,St);let je=bt(V,Ne,Ne===Le?"empty":"start",Ze),Ot=Ne===Le?je:bt(V,Le,"end",Ze),Ue=Me.text.length?nn(Me,0,"start",V.node):Ze(),ht=Me.text.length?nn(Me,Me.text.length,"end",V.node):Ue,it=Tt(Me,je),Kt=Tt(Me,Ot),Rt=it===null?0:it,qt=Math.max(Rt,Kt===null?Me.text.length:Kt);N=Lt(Bt(Me.text,Rt,qt,io(Me,Rt,qt),{start:Fe(je),end:Fe(Ot)},{start:Fe(Ue),end:Fe(ht)}),je,Ot,Ue,ht);let It=se.spans.get(N);if(It.flat=Me,!Me.text.length){let at=Fe(Ue),St=Fn(h,at),At=St[0],Ht=St[1];It.empty={parent:At.nodeType===11?f.get(At):At,previous:At.childNodes[Ht-1]||null,next:At.childNodes[Ht]||null}}E=je?je.node:V.node}let he=We(P),ve=(T.site==="whole"||T.site==="comment"||i!=="both")&&y.resolved!==y.local;return{key:T.site==="comment"&&sn.get(P.b||P.l||P.r)||Z(he,p,k),subject:he,localLost:ve,anchor:E,text:{encoding:R,base:$,local:H,remote:F,merged:N,liveSpan:null,liveScope:null}}},ue=(y,T)=>{let P=_(T.el),p=We(P),k=T.sample;return{key:`attr:${p.key}:${k.namespaceURI||""}:${k.localName}`,subject:p,localLost:y.resolved!==y.local,anchor:T.el,attribute:{namespaceURI:k.namespaceURI||null,localName:k.localName,qualifiedName:k.name}}},oe=(y,T)=>{let P=y.detail,p=T.unit||J(T.subject),k=We(p),R=se.refs.get(k),$=p.l?ut(p.l,"local"):null,H=p.r?ut(p.r,"remote"):null,F=R.length?dt(R[0]):null,N,E,G,he=null,ve=null,u=T.deleted;switch(P){case"both-reordered":{N=E="reordered";let v=new Set(T.rKept),j=T.lKept.filter(ie=>v.has(ie)&&te(J(ie)).length),U=ie=>L.get(te(J(ie))[0]);he=j.map(ie=>We(J(ie))),ve=j.slice().sort((ie,Ne)=>U(ie)-U(Ne)).map(ie=>We(J(ie)));let V=ie=>!Jt(ie)&&ie.kind!=="comment"&&ie.nodes.every(Ne=>!/[^\t\n\f\r ]/.test(Ne.data)),W=j.filter(ie=>!V(ie)),Y=W.slice().sort((ie,Ne)=>U(ie)-U(Ne));G=W.some((ie,Ne)=>ie!==Y[Ne]);break}case"both-moved":N=E="moved",G=!$||!R.some(v=>{let j=v===R[0]?F:dt(v);return j&&j.parent===$.parent});break;case"edit-beats-delete":N=u==="local"?"deleted":"edited",E=u==="remote"?"deleted":"edited",G=u==="local";break;case"move-beats-delete":N=u==="local"?"deleted":"moved",E=u==="remote"?"deleted":"moved",G=u==="local";break;default:N=E="inserted",G=T.localLost}return{key:`structure:${k.key}:${P}`,subject:k,localLost:G,anchor:R[0]||null,structure:{localAction:N,remoteAction:E,localPlacement:$,remotePlacement:H,mergedPlacement:F,localOrder:he,mergedOrder:ve,localFragment:P==="both-reordered"||!p.l?null:Se(p.l),fragmentKind:O(p.b||p.l||p.r)}}};for(let[y,T]of c){if(y.kind!=="structure")continue;let P=T.unit||J(T.subject),p=P.b||P.l||P.r;!Jt(p)&&p.kind==="comment"&&sn.set(p,`structure:${We(P).key}:${y.detail}`)}let fe=new Map;for(let[y,T]of c){if(y.kind==="structure"){let R=We(T.unit||J(T.subject)),$=`structure:${R.key}:${y.detail}`,H=fe.get($);if(H&&H.structure){y.recovery=H;let F=se.refs.get(R);y.el==null&&F.length&&(y.el=Jt(F[0])?F[0]:d.out.logicalParent(F[0]));continue}}let P=y.kind==="text"?ee(y,T):y.kind==="attr"?ue(y,T):oe(y,T),p=fe.get(P.key);p||(p={version:Uc,key:P.key,localLost:P.localLost,subject:P.subject,applied:!1,unavailable:null},fe.set(P.key,p),se.anchors.set(p,P.anchor)),P.text&&(p.text=P.text),P.attribute&&(p.attribute=P.attribute),P.structure&&(p.structure=P.structure),P.text&&(p.localLost=P.localLost),y.recovery=p;let k=se.refs.get(P.subject);y.kind==="structure"&&y.el==null&&k.length&&(y.el=Jt(k[0])?k[0]:d.out.logicalParent(k[0])),y.kind==="text"&&y.node==null&&k.length&&P.subject.nodeType===8&&(y.node=k[0])}return se}}function Fs(e,t,n){if(!t)return;let{lookup:o,vetoed:r,vetoedAttrs:i,liveAttr:c}=n,s=n.ignored||(()=>!1),a=zn(n.liveRoot),m=ne=>!!ne&&a.containerPath(ne)!==null,h=ne=>{let _=ne.parentNode;return _&&_.nodeType===11?t.outOwners.get(_)||null:_},d=ne=>{for(let _=ne;_;_=h(_))if(t.via.has(_)&&(_=t.via.get(_)),r.has(_)||n.vetoedLive?.has(g(_)))return!0;return!1},b=ne=>Array.from(wn(ne).children).filter(_=>!s(_)),A=(ne,_)=>b(ne)[b(_.parentNode).indexOf(_)],S=(ne,_)=>{let ye=null,ge=null,Oe=0;for(let re=_.previousSibling;re;re=re.previousSibling){if(re.nodeType===1&&!s(re)){ye=re;break}re.nodeType===3&&(Oe+=re.nodeValue.length)}for(let re=_.nextSibling;re&&!ge;re=re.nextSibling)re.nodeType===1&&!s(re)&&(ge=re);let Be=ye?A(ne,ye):null,We=ge?A(ne,ge):null;if(ye&&!Be||ge&&!We)return null;let rt=[];for(let re=Be?Be.nextSibling:wn(ne).firstChild;re&&re!==We;re=re.nextSibling)re.nodeType===3&&rt.push(re);return rt.length?{nodes:rt,lead:Oe}:null},L=ne=>{let _=[],ye=ne;for(;ye&&!t.via.has(ye);ye=ye.parentNode)_.push(ye);if(!ye||!_.length)return null;let ge=g(t.via.get(ye));for(let We=_.length-1;We>0&≥We--)ge=A(ge,_[We]);if(!ge)return null;let Oe=_[0];if(Oe.nodeType===3)return S(ge,Oe);let Be=Oe.nodeType===1?A(ge,Oe):null;return Be?{nodes:[Be],lead:0}:null},f=ne=>{let _=o(ne),ye=_?{nodes:Array.isArray(_)?_:[_],lead:0}:t.via.size?L(ne):null;if(!ye)return null;let ge=ye.nodes.filter(m);return ge.length?{nodes:ge,lead:ye.lead}:null},g=ne=>{let _=f(ne);return _?_.nodes[0]:null},x=ne=>{if(!ne)return null;if(ne.kind==="text"){let Oe=f(ne.node);if(!Oe)return null;let Be=Oe.nodes,We=ne.offset+Oe.lead,rt=0;for(let re=0;re<Be.length;re++){let ut=Be[re].nodeValue.length;if(We<=rt+ut||re===Be.length-1)return We>=rt&&We<=rt+ut?[Be[re],We-rt]:null;rt+=ut}return null}let _=g(ne.node);if(!_)return null;if(ne.kind==="end")return[wn(_),wn(_).childNodes.length];if(ne.kind==="startOf")return[wn(_),0];if(ne.kind==="wholeStart")return _.firstChild?[_.firstChild,0]:[_,0];if(ne.kind==="wholeEnd")return _.lastChild?[_.lastChild,_.lastChild.nodeValue.length]:[_,_.childNodes.length];let ye=_.parentNode;if(!ye)return null;let ge=Array.prototype.indexOf.call(ye.childNodes,_);return[ye,ne.kind==="after"?ge+1:ge]},Q=ne=>({blocks:new Set((ne.flat?.marks||[]).filter(_=>_.block).map(_=>g(_.el)).filter(Boolean)),atoms:new Set((ne.flat?.atoms||[]).map(_=>g(_.el)).filter(Boolean)),ignored:s}),se=(ne,_,ye,ge)=>{if(!ne||!_||!Kn(ne)||!Kn(_))return!1;for(let We of[ne,_])if(!m(We.startContainer)||!m(We.endContainer))return!1;let Oe=ye.merged;if(Oe.start===Oe.end&&(ne.startContainer!==ne.endContainer||ne.startOffset!==ne.endOffset))return!1;let Be=Q(ge);return Bn(_,ye.encoding,Be)===Oe.text&&Bn(ne,ye.encoding,Be)===Oe.text.slice(Oe.start,Oe.end)},le=new Map,q=ne=>{let _=ne.parentNode;return _?(le.has(_)||le.set(_,new Map(Array.from(_.childNodes,(ye,ge)=>[ye,ge]))),le.get(_).get(ne)):-1},z=(ne,_)=>{if(!_)return!1;let ye=a.logicalParent(ne);if(!_.parent.live.includes(ye))return!1;let ge=q(ne);for(let[Oe,Be]of[["before",1],["after",-1]]){let We=ge;for(let rt of _[Oe]){if(rt.live.includes(ne))continue;let re=rt.live.filter(dt=>dt!==ne&&dt.parentNode===ne.parentNode);if(!re.length)continue;let ut=Be===1?Math.min(...re.map(q)):Math.max(...re.map(q));if(Be*(ut-We)<=0)return!1;We=ut}}return!0},ce=ne=>{let _=ne.structure;if(_.mergedOrder){let ye=new Set(ne.subject.live.map(wn)),ge=null,Oe=-1;for(let Be of _.mergedOrder){let We=Be.live.find(rt=>ye.has(rt.parentNode));if(!We||ge&&We.parentNode!==ge||q(We)<=Oe)return!1;ge=We.parentNode,Oe=q(We)}return ne.subject.live.length>0}return ne.subject.live.some(ye=>z(ye,_.mergedPlacement))},xe=(ne,_)=>{let ye=x(ne),ge=x(_);return ye&&ge?{startContainer:ye[0],startOffset:ye[1],endContainer:ge[0],endOffset:ge[1]}:null},te=new Set,J=ne=>{if(!ne||te.has(ne))return;te.add(ne);let _=[];for(let ye of t.refs.get(ne)||[]){let ge=f(ye);if(ge)for(let Oe of ge.nodes)_.includes(Oe)||_.push(Oe)}ne.live=_},Ce=ne=>{ne&&(J(ne.parent),ne.before.forEach(J),ne.after.forEach(J))},we=new Set;for(let ne of e){let _=ne.recovery;if(!_||we.has(_))continue;we.add(_),J(_.subject),_.structure&&(Ce(_.structure.localPlacement),Ce(_.structure.remotePlacement),Ce(_.structure.mergedPlacement),(_.structure.localOrder||[]).forEach(J),(_.structure.mergedOrder||[]).forEach(J));let ye=t.anchors.get(_),ge=ye?g(ye):null,Oe=!!ge;if(_.text){let O=t.spans.get(_.text.merged),B=O?xe(O.start,O.end):null,ae=O?xe(O.scopeStart,O.scopeEnd):null;if(O?.empty){let be=O.empty,de=be.previous?{kind:"after",node:be.previous}:{kind:"startOf",node:be.parent},ze=be.next?{kind:"before",node:be.next}:{kind:"end",node:be.parent},De=xe(de,ze);!De||De.startContainer!==De.endContainer||De.startOffset!==De.endOffset?B=null:B=ae=De}se(B,ae,_.text,O)||(B=ae=null),_.text.liveSpan=B,_.text.liveScope=B?ae:null,B||(Oe=!1)}_.structure&&Oe&&(Oe=ce(_)),_.attribute&&Oe&&(Oe=c(ge,_.attribute,ne.resolved));let Be=(!!_.attribute||!!_.text&&ge?.tagName==="TEXTAREA")&&!!i&&[ye,ge].some(O=>i.get(O)?.has(_.attribute?_.attribute.qualifiedName:"value")),We=t.localState?.states.get(_),rt=!!_.text&&[...n.removedVetoes||[]].some(O=>We?.touched.has(O)),re=_.structure?.localAction==="inserted"&&[...r].some(O=>O===ye||ye?.contains(O)),ut=ye&&d(ye)||Be||rt||re,dt=ut&&$s(_,ne,t,m);dt&&(rt||re&&_.localLost)&&(Oe=!1);let Se=!Oe&&dt&&ut;_.applied=Oe,_.unavailable=Oe?null:Se?"hook-veto":"missing-output",Se&&(_.localLost=!1),!Oe&&_.text&&(_.text.liveSpan=_.text.liveScope=null)}}function Zo(e,t,n){let o=zn(t),r=zn(n),i=d=>!!d&&r.containerPath(d)!==null,c=d=>{if(d===t)return n;let b=o.pathOf(d);if(b&&t!==n){let A=Fn(n,{path:b,offset:0});if(A&&A[0].nodeType===d.nodeType)return A[0]}return d},s=new Set,a=d=>{!d||s.has(d)||(s.add(d),d.live=d.live.map(c).filter(i))},m=d=>{d&&(d.startContainer=c(d.startContainer),d.endContainer=c(d.endContainer))},h=new Set;for(let d of e){d.node===t&&n.tagName==="SCRIPT"&&(d.node=n),d.el===t&&d.kind==="structure"&&(d.el=n);let b=d.recovery;if(!b||h.has(b))continue;if(h.add(b),a(b.subject),b.text){m(b.text.liveSpan),m(b.text.liveScope);let S=b.text.liveSpan,L=b.text.liveScope,f=b.text.merged,g=x=>!!x&&Kn(x)&&i(x.startContainer)&&i(x.endContainer);(!g(S)||!g(L)||Bn(L,b.text.encoding)!==f.text||Bn(S,b.text.encoding)!==f.text.slice(f.start,f.end))&&(b.text.liveSpan=null,b.text.liveScope=null,b.applied=!1,b.unavailable="missing-output")}let A=b.structure;if(A){for(let S of[A.localPlacement,A.remotePlacement,A.mergedPlacement])S&&(a(S.parent),S.before.forEach(a),S.after.forEach(a));(A.localOrder||[]).forEach(a),(A.mergedOrder||[]).forEach(a),b.subject.live.length||(b.applied=!1,b.unavailable="missing-output")}}}var Xe=e=>!!e&&e.nodeType===1,_c=new Set("P H1 H2 H3 H4 H5 H6 DIV LI DD DT BLOCKQUOTE FIGCAPTION SUMMARY ADDRESS".split(" ")),Ks=5e4,So="[id],[data-id],script,head>*";function Pr(e,t){return n=>{if(e!==null&&n.tagName==="SCRIPT"){let o=lo(n,e);if(o)return"merge:"+o.key}return n.parentElement&&n.parentElement.tagName==="HEAD"?Ps(n,t):null}}function er(e,t,n,o){let r=o.ignored,i=o.stats||jn(),c=xs({ignored:r,ignoreAttribute:o.ignoreAttribute,stats:i}),{unitsOf:s,meta:a}=c,m=o.baseURI,h=o.mergeTags!==null,d=Pr(o.mergeTags,m),b=u=>v=>{let j=d(v);return j!==null?j:u(v)},A=b(o.identity.base),S=b(o.identity.local),L=b(o.identity.remote),f=o.authored||o.identity,g=u=>u&&u.nodeType===9?u.documentElement:u,x=g(e),Q=g(t),se=g(n),le=globalThis.__hyperMorphProfile,q=le?performance.now():0,z=u=>u===fn?So:null,ce=o.scope||null,xe=ce?ce.baseIndex:zo(x,A,r,z(o.identity.base)),te=o.localIsBase||x===Q?Gs():yr(x,Q,{analyzer:c,baseIndex:xe,sideIndex:zo(Q,S,r,z(o.identity.local)),baseId:f.base,sideId:f.local,stats:i}),J=yr(x,se,{analyzer:c,baseIndex:xe,sideIndex:ce?ce.remoteIndex:zo(se,L,r,z(o.identity.remote)),baseId:f.base,sideId:f.remote,stats:i,scope:ce,comparisons:o.comparisons});if(ce){if(!ce.held(J))return null;for(let u of ce.dropped)gr(u)}let Ce=null;function we(u){if(!Ce){Ce=new WeakMap;let v=[x];for(;v.length;){let j=v.pop();j.tagName==="TEMPLATE"&&j.content&&Ce.set(j.content,j);for(let U of c.childrenOf(j))U.nodeType===1&&v.push(U)}}return Ce.get(u)||null}let ne=u=>{let v=Xe(u)||u.nodeType?u.parentNode:u.parent;return v&&v.nodeType===11?we(v):v};Tt(),nn(te,J),nn(J,te);for(let u of[te,J])if(u.refused)for(let v of u.refused)u.moved.has(v)||i.ambiguousMoves++;le&&(le.alignTotal=(le.alignTotal||0)+(performance.now()-q),q=performance.now());let _=x.ownerDocument.implementation.createHTMLDocument(""),ye=new WeakMap,ge=new WeakMap,Oe=[],Be=[],We=new Set,rt=[],re=new Set,ut=new Set,dt=new Set,Se=new WeakMap,O=o.conflicts||"remote",B=u=>Oe.push(u),ae=u=>Oe.push(u),be=qs({roots:{base:x,local:Q,remote:se},L:te,R:J,unitsOf:s,provenance:ye,policy:O}),de=(u,v)=>{Be.push(u),v&&be.note(u,v)},ze=wt(),De=Et(x,te.map.get(x),J.map.get(x),!!o.localIsBase,!!o.childrenOnly);De.tagName==="HTML"?_.replaceChild(De,_.documentElement):_.body.appendChild(De),le&&(le.build=(le.build||0)+(performance.now()-q));let Qe=o.childrenOnly?!H(R(De),R(se)):!P(De,se),st=be.finish(De);return{doc:_,root:De,provenance:ye,textMappers:ge,decisions:Oe,conflicts:Be,recoveryLinks:st,localDiverged:Qe,mergedScripts:We,segments:rt,remoteIdOf:o.identity.remote,customIdentity:o.identity.remote!==fn,L:te,R:J,stats:i};function wt(){let u=new Map,v=new Set;if(o.localIsBase||!te.insertedByHash)return{partner:u,drop:v};let j=te.insertedByHash(),U=J.insertedByHash();if(!j.size||!U.size)return{partner:u,drop:v};let V={ignored:r,remoteWins:o.remoteWins,inlineCache:Se},W=Ue=>{let ht=0;for(let it=Ue.parentNode;it;it=it.parentNode)ht++;return ht},Y=[],ie=Ue=>{let ht=Ue.textContent.trim();return ht.split(/\s+/).length>=3||ht.replace(/\s/g,"").length>=12},Ne=Ue=>{let ht=Fe(te,Ue),it=Fe(J,Ue);return ht&&te.reverse.get(ht.parentNode)!==Ue.parentNode||it&&J.reverse.get(it.parentNode)!==Ue.parentNode},Le=(Ue,ht,it)=>{for(let Rt of it.parentNode.children){let qt=Rt!==it&&Ue.reverse.get(Rt);if(qt&&Ne(qt))return!0}let Kt=Ue.reverse.get(it.parentNode);if(Kt){for(let Rt of Kt.children)if(!Fe(ht,Rt)&&!r(Rt))return!0}return!1};for(let[Ue,ht]of j){let it=U.get(Ue);if(!it)continue;let Kt=ht.length===1&&it.length===1;for(let Rt of ht)qn(Rt,V)||Y.push([Rt,it,W(Rt),Kt&&(ie(Rt)||Le(te,J,Rt)||Le(J,te,it[0]))])}if(!Y.length)return{partner:u,drop:v};Y.sort((Ue,ht)=>Ue[2]-ht[2]);let Me=new Set,Ze=new Set,je=Ue=>{for(let ht of Ue.querySelectorAll("*"))Me.add(ht)},Ot=(Ue,ht)=>Ue.reverse.get(ht.parentNode)||null;for(let[Ue,ht,,it]of Y){if(Me.has(Ue))continue;let Kt=Ot(te,Ue),Rt=It=>!Ze.has(It)&&!Me.has(It)&&It.tagName===Ue.tagName&&c.equalUnits(Ue,It),qt=ht.find(It=>Kt&&Ot(J,It)===Kt&&Rt(It))||(it?ht.find(Rt):null);qt&&(Ze.add(qt),je(Ue),je(qt),!(Kt&&Ot(J,qt)===Kt)&&(u.set(Ue,qt),u.set(qt,Ue),v.add(O==="local"?qt:Ue)))}return{partner:u,drop:v}}function bt(u,v,j){if(re.add(u),ze.drop.has(u))return null;re.add(j);let U=v==="local"?u:j,V=v==="local"?j:u,W;return c.equalUnits(U,V)?(W=y(U,"local",!0),ye.get(W).remote=V):W=fe(U,V),de({kind:"structure",el:W,detail:"both-moved",base:null,local:U,remote:V},{unit:{b:null,l:U,r:V}}),B({kind:"insert",el:W,source:"both"}),W}function Tt(){if(!te.weak||!J.weak||!te.weak.size||!J.weak.size||!te.unpair)return;let u=new Map;for(let j of te.weak){let U=Fe(te,j);Xe(j)&&Xe(U)&&u.set(c.unitHash(U),j)}let v=!1;for(let j of Array.from(J.weak)){let U=Fe(J,j);if(!Xe(j)||!Xe(U))continue;let V=u.get(c.unitHash(U));if(!V||V===j||!te.weak.has(V)||Fe(te,j)&&Fe(J,V))continue;let W=Fe(te,V);W.tagName===U.tagName&&c.equalUnits(W,U)&&(te.unpair(V),J.unpair(j),v=!0)}v&&(te.rematch(),J.rematch())}function nn(u,v){if(!u.weak||!u.weak.size||!v.insertedByHash)return;let j=v.insertedByHash();if(!j.size)return;let U=!1;for(let V of Array.from(u.weak)){let W=Fe(u,V);if(!W)continue;let Y=j.get(c.unitHash(W));Y&&Y.some(ie=>ie.tagName===W.tagName&&c.equalUnits(ie,W))&&(u.unpair(V),U=!0)}U&&u.rematch()}function Fe(u,v){if(!v)return null;if(u.map.has(v))return u.map.get(v);let j=[],U=ne(v);for(;U&&!u.map.has(U);U=ne(U))j.push(U);let V=U;if(!V||!u.identical.has(V))return null;u.pairIdenticalChildren(V);for(let Y=j.length-1;Y>=0;Y--)u.pairIdenticalChildren(j[Y]);let W=u.map.get(v)||null;return W&&i.lazyTwins++,W}function Qt(u,v,j){if(ut.has(u)||dt.has(u))return de({kind:"structure",el:null,detail:"both-moved",base:u},{subject:u}),ut.has(u)?null:y(j,v);let U=Fe(te,u),V=Fe(J,u);(!U||!V)&&de({kind:"structure",el:null,detail:"move-beats-delete",base:u},{subject:u,deleted:U?"remote":"local"});let W=Et(u,U,V,!1);return(v==="local"?B:ae)({kind:"move",el:W,source:v}),W}function Xt(u,v,j,U){return U||!v||v===j?{el:j,asBase:!0,twin:V=>V,baseOf:V=>V,units:s(j),here:()=>!0,parentOfTwin:()=>j}:{el:v,asBase:!1,twin:V=>Fe(u,V),baseOf:V=>u.reverse.get(V),units:s(v),here:V=>Xe(V)?V.parentNode===v||v.tagName==="TEMPLATE"&&V.parentNode===v.content:V.parent===v||v.tagName==="TEMPLATE"&&V.parent===v.content}}function Bt(u,v,j){return!v||j&&j.identical.has(u)?!1:Xe(u)?!c.equalUnits(u,v):u.value!==v.value}function Et(u,v,j,U,V=!1){let W=U||o.remoteWins(u),Y=u.namespaceURI&&u.namespaceURI!=="http://www.w3.org/1999/xhtml"?_.createElementNS(u.namespaceURI,u.tagName):_.createElement(u.tagName),ie={base:u,local:v||null,remote:j||null};if(ye.set(Y,ie),re.add(u),ut.add(u),v&&re.add(v),j&&re.add(j),o.skipUnchanged&&!V&&(o.localIsBase||te.identical.has(u))&&j&&J.identical.has(u)&&!o.remoteWins(u)){ie.unchanged=!0;for(let Le of u.attributes)Le.namespaceURI?Y.setAttributeNS(Le.namespaceURI,Le.name,Le.value):Y.setAttribute(Le.name,Le.value);return Y}dt.add(u),V||M(u,W?u:v,j,Y);let Ne=u.tagName;if(tn(u))sn(u,W?u:v,j,Y);else if(Ne==="TEXTAREA")Y.textContent=Lt(u.textContent,(W?u:v)?(W?u:v).textContent:u.textContent,j?j.textContent:u.textContent,Y,"text");else{let Le=T(u,v,j,W,Y),Me=Ne==="TEMPLATE"&&Y.content?Y.content:Y;for(let Ze of Le)Me.appendChild(Ze)}return dt.delete(u),Y}function Lt(u,v,j,U,V){if(v===j)return v;if(v===u)return j!==u&&ae({kind:V,node:U,source:"remote"}),j;if(j===u)return B({kind:V,node:U,source:"local"}),v;let W=O==="local"?v:j;return de({kind:V,node:U,base:u,local:v,remote:j,resolved:W},{site:"whole",el:U}),Oe.push({kind:V,node:U,source:"both"}),W}function sn(u,v,j,U){let V=u.textContent,W=v?v.textContent:V,Y=j?j.textContent:V,ie=h?lo(u,o.mergeTags,!0):null;if(ie&&W!==Y){let Ne=j&&j.getAttribute("merge-key")||u.getAttribute("merge-key"),{text:Le,warnings:Me}=Rr(o.localIsBase?void 0:V,W,Y,{parse:ie.recognizer.parse,keyCandidates:Ne?Ne.split(/[\s,]+/).filter(Boolean):void 0});for(let Ze of Me)console.warn(`[hyper-morph] merge "${ie.raw}": ${Ze}`);U.textContent=Le,We.add(U),Le!==Y?B({kind:"text",node:U,source:Le===W?"local":"both"}):Le!==V&&ae({kind:"text",node:U,source:"remote"});return}U.textContent=Lt(V,W,Y,U,"text")}function M(u,v,j,U){let V=new Map;for(let W of[u,v,j])if(W)for(let Y of W.attributes)o.ignoreAttribute(W,Y.name)||V.set(Y.name,Y);for(let[W,Y]of V){let ie=u?u.getAttribute(W):null,Ne=v?v.getAttribute(W):ie,Le=j?j.getAttribute(W):ie,Me;Ne===Le?Me=Ne:Ne===ie?(Me=Le,ae({kind:"attr",el:U,name:W,source:"remote"})):Le===ie?(Me=Ne,B({kind:"attr",el:U,name:W,source:"local"})):(Me=Z(W,ie,Ne,Le),Me===void 0&&(Me=O==="local"?Ne:Le,de({kind:"attr",el:U,name:W,base:ie,local:Ne,remote:Le,resolved:Me},{el:U,sample:Y})),Oe.push({kind:"attr",el:U,name:W,source:"both"})),Me!=null&&(Y.namespaceURI?U.setAttributeNS(Y.namespaceURI,Y.name,Me):U.setAttribute(W,Me))}}function Z(u,v,j,U){if(u==="class"){let V=Le=>new Set((Le||"").split(/\s+/).filter(Boolean)),W=V(v),Y=V(j),ie=V(U),Ne=new Set;for(let Le of new Set([...W,...Y,...ie])){let Me=W.has(Le),Ze=Y.has(Le),je=ie.has(Le);(Ze===je?Ze:Ze===Me?je:Ze)&&Ne.add(Le)}return[...Ne].join(" ")}if(u==="style"){let V=Me=>{let Ze=new Map;if(!Me)return Ze;let je=0,Ot=null,Ue="",ht=()=>{let it=Ue.indexOf(":");it>0&&Ze.set(Ue.slice(0,it).trim(),Ue.slice(it+1).trim()),Ue=""};for(let it of Me){if(Ot){Ue+=it,it===Ot&&(Ot=null);continue}if(it==='"'||it==="'"){Ot=it,Ue+=it;continue}if(it==="("?je++:it===")"&&je--,it===";"&&je===0){ht();continue}Ue+=it}return Ue.trim()&&ht(),Ze},W=V(v),Y=V(j),ie=V(U),Ne=new Map,Le=!1;for(let Me of new Set([...W.keys(),...Y.keys(),...ie.keys()])){let Ze=W.get(Me)??null,je=Y.get(Me)??null,Ot=ie.get(Me)??null,Ue;je===Ot?Ue=je:je===Ze?Ue=Ot:Ot===Ze?Ue=je:(Ue=O==="local"?je:Ot,Le=!0),Ue!=null&&Ne.set(Me,Ue)}return Le?void 0:[...Ne].map(([Me,Ze])=>`${Me}: ${Ze}`).join("; ")}}function ee(u,v,j,U){let V=u.value,W=U?V:v?v.value:"",Y=j?j.value:"";re.add(u),v&&re.add(v),j&&re.add(j);let ie=wo(V,W,Y,O),Ne=ie.text===""?null:_.createTextNode(ie.text);Ne&&(ye.set(Ne,{base:u.nodes,local:v?v.nodes:null,remote:j?j.nodes:null}),ge.set(Ne,ie.mapLocalOffset)),W!==V&&Y!==V?Oe.push({kind:"text",node:Ne,source:"both"}):W!==V?B({kind:"text",node:Ne,source:"local"}):Y!==V&&ae({kind:"text",node:Ne,source:"remote"});for(let Le of ie.conflicts)de({kind:"text",node:Ne,base:V.slice(Le.bs,Le.be),local:Le.local,remote:Le.remote,resolved:Le.resolved},{site:"run",bRun:u,lRun:v,rRun:j,node:Ne,c:Le});return Ne}function ue(u,v){return xo(u,v).every(j=>j.bs===j.be)}function oe(u,v){let j=u?u.value:"",U=v?v.value:"",V;if(j===U||!U?V=j:j?ue(j,U)?V=U:ue(U,j)?V=j:(V=O==="local"?j:O==="both"?j+U:U,de({kind:"structure",el:null,detail:"insert-collision",local:j,remote:U,resolved:V},{unit:{b:null,l:u,r:v},localLost:O==="remote"})):V=U,u&&re.add(u),v&&re.add(v),V==="")return null;let W=_.createTextNode(V);return ye.set(W,{base:null,local:u?u.nodes:null,remote:v?v.nodes:null}),j?B({kind:"insert",el:W,source:U&&j===U?"both":"local"}):ae({kind:"insert",el:W,source:"remote"}),W}function fe(u,v){let j={ignored:r,remoteWins:o.remoteWins,inlineCache:Se},U=ie=>s(ie).every(Ne=>Xe(Ne)?qn(Ne,j):Ne.kind==="text"),V=null;if(U(u)&&U(v)){let ie=u.textContent,Ne=v.textContent;ie===Ne||ue(Ne,ie)?V=v:ue(ie,Ne)&&(V=u)}if(!V){let ie=O==="local",Ne=y(ie?u:v,ie?"local":"remote",!0),Le=ye.get(Ne);return ie?Le.remote=v:Le.local=u,de({kind:"structure",el:Ne,detail:"insert-collision",local:u,remote:v,resolved:ie?u:v},{unit:{b:null,l:u,r:v},localLost:!ie}),Ne}let W=u.namespaceURI&&u.namespaceURI!=="http://www.w3.org/1999/xhtml"?_.createElementNS(u.namespaceURI,u.tagName):_.createElement(u.tagName);M(null,u,v,W),ye.set(W,{base:null,local:u,remote:v}),re.add(u),re.add(v);let Y=Ir({base:Array.from(V.childNodes),local:Array.from(u.childNodes),remote:Array.from(v.childNodes),out:_,policy:O,idOf:{local:S,remote:L},ignored:r,ignoreAttribute:o.ignoreAttribute,remoteWins:o.remoteWins,provenance:ye,textMappers:ge,conflicts:Be,conflict:de,scope:{base:null,local:u,remote:v,units:[],at:0},synthetic:!0,decisions:Oe,node:W});rt.push(...Y.segments);for(let ie of Y.nodes)W.appendChild(ie);return W}function y(u,v,j=!1){if(!j&&Xe(u)){let Y=ze.partner.get(u);if(Y)return bt(u,v,Y)}if(!Xe(u)){if(u.value==="")return null;let Y=u.kind==="comment"?_.createComment(u.value):_.createTextNode(u.value);return ye.set(Y,{base:null,local:v==="local"?u.nodes:null,remote:v==="remote"?u.nodes:null}),re.add(u),Y}let U=u.namespaceURI&&u.namespaceURI!=="http://www.w3.org/1999/xhtml"?_.createElementNS(u.namespaceURI,u.tagName):_.createElement(u.tagName);for(let Y of u.attributes)Y.namespaceURI?U.setAttributeNS(Y.namespaceURI,Y.name,Y.value):U.setAttribute(Y.name,Y.value);ye.set(U,{base:null,local:v==="local"?u:null,remote:v==="remote"?u:null}),re.add(u);let V=u.tagName==="TEMPLATE"&&U.content?U.content:U,W=v==="local"?te:J;for(let Y of s(u)){let ie=Xe(Y)?W.reverse.get(Y):null;if(ie&&ut.has(ie)){de({kind:"structure",el:null,detail:"both-moved",base:ie},{subject:ie});continue}if(ie&&!dt.has(ie)){let Le=Fe(te,ie)||null,Me=Fe(J,ie)||null;if(Le||Me){let Ze=Et(ie,Le,Me,!1);v==="local"?B({kind:"move",el:Ze,source:"local"}):ae({kind:"move",el:Ze,source:"remote"}),V.appendChild(Ze);continue}}let Ne=y(Y,v);Ne&&V.appendChild(Ne)}return U}function T(u,v,j,U,V){v&&te.identical.has(u)&&te.pairIdenticalChildren(u),j&&J.identical.has(u)&&J.pairIdenticalChildren(u);let W=Xt(te,v,u,U),Y=Xt(J,j,u,!1),ie=s(u),Ne=new Set(ie),Le=new Map;for(let X=0;X<ie.length;X++)Le.set(ie[X],X);let Me=[],Ze=new Set,je=new Map,Ot=new Set,Ue=new Set,ht=[];zt();let it=X=>{let Re=[];for(let Ae of X.units){if(Ue.has(Ae))continue;let Ge=X.baseOf(Ae);Ge&&Ne.has(Ge)&&Re.push(Ge)}return Re},Kt=X=>it(X).map(Re=>Le.get(Re)),Rt=X=>X.every((Re,Ae)=>Ae===0||Re>=X[Ae-1]),qt=!W.asBase&&!Rt(Kt(W)),It=!Y.asBase&&!Rt(Kt(Y));qt&&It&&de({kind:"structure",el:V,detail:"both-reordered",base:u},{subject:u,lKept:it(W),rKept:it(Y)});let at=It||!qt?{V:Y,A:J,side:"remote",other:W,otherA:te,otherSide:"local"}:{V:W,A:te,side:"local",other:Y,otherA:J,otherSide:"remote"};qt?B({kind:"move",el:null,source:It?"both":"local",base:u}):It&&ae({kind:"move",el:null,source:"remote",base:u});let St=W.asBase?[]:W.units.filter(X=>!W.baseOf(X)&&!Ue.has(X)&&!ze.partner.has(X)),At=Y.asBase?[]:Y.units.filter(X=>!Y.baseOf(X)&&!Ue.has(X)&&!ze.partner.has(X)),Ht=new Map;if(St.length&&At.length){let X=new Map,Re=new Map;for(let He of At){if(Xe(He)){let et=L(He);et&&X.set(et,He)}let $e=c.unitHash(He);Re.has($e)||Re.set($e,[]),Re.get($e).push(He)}let Ae=(He,$e)=>{let et=He.units.indexOf($e);for(let _e=et-1;_e>=0;_e--){let nt=He.baseOf(He.units[_e]);if(nt)return nt}return"start"},Ge=new Map,ct=new Map;for(let He of At){let $e=Ae(Y,He);Xe(He)?(ct.has($e)||ct.set($e,[]),ct.get($e).push(He)):He.kind==="text"&&!Ge.has($e)&&Ge.set($e,He)}for(let He of St){let $e=null;if(Xe(He)){let et=S(He);et&&X.has(et)&&!Ht.has(X.get(et))&&($e=X.get(et))}else if(He.kind==="text"){let et=Ge.get(Ae(W,He));et&&!Ht.has(et)&&($e=et)}if(!$e){let et=Re.get(c.unitHash(He));et&&($e=et.find(_e=>!Ht.has(_e)&&Xe(_e)===Xe(He)&&(Xe(_e)?_e.tagName===He.tagName:_e.kind===He.kind)&&c.equalUnits(He,_e))||null)}if(!$e&&Xe(He)){let et=f.local(He),_e=(ct.get(Ae(W,He))||[]).filter(nt=>{let en=f.remote(nt);return!Ht.has(nt)&&nt.tagName===He.tagName&&!(et&&en&&et!==en)&&c.similar(He,nt)});_e.length===1&&($e=_e[0])}$e&&(Ht.set($e,He),Ht.set(He,$e))}}let Zt=X=>{if(re.has(X))return je.get(X)||null;let Re=W.twin(X),Ae=Y.twin(X),Ge=Re&&!W.asBase&&!W.here(Re),ct=Ae&&!Y.asBase&&!Y.here(Ae);if(Ge||ct){if((!Re||!Ae)&&de({kind:"structure",el:null,detail:"move-beats-delete",base:X},{subject:X,deleted:Re?"remote":"local"}),!G(X))return re.add(X),null;de({kind:"structure",el:null,detail:"both-moved",base:X},{subject:X})}if(!Re&&!Ae)return re.add(X),ae({kind:"remove",source:"both",base:X}),null;if(!Re&&!Bt(X,Ae,J))return re.add(X),B({kind:"remove",source:"local",base:X}),null;if(!Ae&&!Bt(X,Re,te))return re.add(X),ae({kind:"remove",source:"remote",base:X}),null;let He=!Re||!Ae,$e=W.asBase?Fe(te,X)||null:Re,et=Y.asBase&&Xe(X)&&(J.identityPaired.has(X)||!f.base(X))&&Fe(J,X)||Ae,_e;return Xe(X)?_e=Et(X,$e,et,W.asBase):X.kind==="comment"?_e=N(X,$e,Ae,W.asBase):_e=ee(X,$e,Ae,W.asBase),re.add(X),_e&&(je.set(X,_e),Re&&je.set(Re,_e),Ae&&je.set(Ae,_e),He&&(de({kind:"structure",el:_e,detail:"edit-beats-delete",base:X},{subject:X,deleted:Re?"remote":"local"}),Re?B({kind:"insert",el:_e,source:"local"}):ae({kind:"insert",el:_e,source:"remote"}))),_e},un=(X,Re,Ae,Ge)=>{if(re.has(X))return je.get(X)||null;let ct=Re.baseOf(X);if(ct&&Ne.has(ct))return Ue.has(ct)&&!Ue.has(X)?In(ct,X,Ge):Zt(ct);if(ct)return Cn(ct,X,Ge);let He=Ht.get(X);if(He){let et=Ge==="local"?X:He,_e=Ge==="local"?He:X,nt;return Xe(et)?c.equalUnits(et,_e)?(nt=y(et,"local"),ye.get(nt).remote=_e):nt=fe(et,_e):nt=oe(et,_e),re.add(et),re.add(_e),nt&&(je.set(et,nt),je.set(_e,nt),Xe(et)&&B({kind:"insert",el:nt,source:"both"})),nt}let $e=y(X,Ge);return $e&&(je.set(X,$e),Ge==="local"?B({kind:"insert",el:$e,source:"local"}):ae({kind:"insert",el:$e,source:"remote"})),$e},In=(X,Re,Ae)=>{let Ge;return Xe(X)?(Ge=Qt(X,Ae,Re),Ge&&re.add(Re)):(Ge=y(Re,Ae),re.add(Re),Ge&&(Ae==="local"?B:ae)({kind:"insert",el:Ge,source:Ae})),Ge&&je.set(Re,Ge),Ge},Cn=(X,Re,Ae)=>{let ct=Fe(Ae==="local"?J:te,X),He=Re,$e=ct?he(ct,Ae==="local"?j:v,Ae==="local"?J:te):!1,et=ct&&!$e&&!ve(X,ct);if(et&&Ae===at.otherSide)return de({kind:"structure",el:null,detail:"both-moved",base:X},{subject:X}),null;if(et&&de({kind:"structure",el:null,detail:"both-moved",base:X},{subject:X}),ct||de({kind:"structure",el:null,detail:"move-beats-delete",base:X},{subject:X,deleted:Ae==="local"?"remote":"local"}),dt.has(X)){de({kind:"structure",el:null,detail:"both-moved",base:X},{subject:X});let nt=y(He,Ae);return nt&&je.set(Re,nt),nt}let _e=Xe(X)?Et(X,Ae==="local"?He:Fe(te,X)||null,Ae==="remote"?He:Fe(J,X)||null,!1):null;return _e&&(je.set(X,_e),je.set(Re,_e),ct&&je.set(ct,_e),Ae==="local"?B({kind:"move",el:_e,source:"local"}):ae({kind:"move",el:_e,source:"remote"})),_e};for(let X of at.V.units){if(Ue.has(X)){let Ae=je.get(X);Ze.has(Ae)||(Me.push(Ae),Ze.add(Ae));continue}if(re.has(X)&&!(je.get(X)&&Ze.has(je.get(X)))){let Ae=at.V.baseOf(X);Ae&&!Ne.has(Ae)&&de({kind:"structure",el:null,detail:"both-moved",base:Ae},{subject:Ae});continue}let Re=un(X,at.V,at.A,at.side);Re&&!Ze.has(Re)&&(Me.push(Re),Ze.add(Re),!at.V.baseOf(X)&&!Ht.has(X)&&!Ue.has(X)&&Ot.add(Re))}for(let X of ht)Ze.has(X.frag)||(Me.splice(xn(X.at),0,X.frag),Ze.add(X.frag));if(!at.other.asBase){let X=at.other,Re=at.otherSide,Ae=at.otherA,Ge=null,ct=0,He=null;for(let $e of X.units){let et=je.get($e);if(et&&Ze.has(et)){Ge=et,He=null;continue}if(re.has($e)){let en=X.baseOf($e);en&&!Ne.has(en)&&de({kind:"structure",el:null,detail:"both-moved",base:en},{subject:en});continue}let _e=un($e,X,Ae,Re);if(!_e)continue;let nt;if(He)nt=Me.indexOf(He)+1;else if(Ge){if(nt=Me.indexOf(Ge)+1,Re==="remote")for(;nt<Me.length&&Ot.has(Me[nt]);)nt++}else nt=ct++;Me.splice(nt,0,_e),Ze.add(_e),He=_e}}for(let X=0;X<ie.length;X++){let Re=ie[X];if(re.has(Re))continue;let Ae=Zt(Re);Ae&&Me.splice(xn(X),0,Ae)}return Me;function xn(X){for(let Re=X-1;Re>=0;Re--){let Ae=je.get(ie[Re]);if(Ae){let Ge=Me.indexOf(Ae);if(Ge>=0)return Ge+1}}return 0}function cn(X){let Re={ignored:r,remoteWins:()=>!1},Ae=me=>X(me)||Xe(me)&&o.remoteWins(me)&&An.has(me.tagName)&&qn(me,Re),Ge=new Map,ct=me=>{if(!Xe(me)||!_c.has(me.tagName))return!1;let Ie=Ge.get(me);return Ie===void 0&&(Ie=!r(me)&&!o.remoteWins(me)&&s(me).every(Ae),Ge.set(me,Ie)),Ie},He=me=>!Xe(me)&&me.kind==="text",$e=null,et=new Map,_e=me=>{let Ie=et.get(me);if(Ie)return Ie;let qe=Xe(me)?me.textContent:me.value;Ie=new Set;let tt=qe.toLowerCase();if(!(qe.length>Ks))if(/^[\x00-\x7f]*$/.test(tt))for(let Ke of tt.split(/[^\p{L}\p{N}]+/u))Ke&&Ie.add(Ke);else for(let Ke of Sr(tt))/^[\s\p{P}]+$/u.test(Ke)||Ie.add(Ke);return et.set(me,Ie),Ie},nt=me=>(Xe(me)?me.textContent:me.value).toLowerCase().replace(/\s+/g," ").trim(),en=new Map,Vn=me=>{let Ie=en.get(me);if(Ie)return Ie;Ie=new Set(_e(me));let qe=Ke=>{if(Ke)for(let kt of _e(Ke))Ie.add(kt)},tt=Ne.has(me)?me:!W.asBase&&W.baseOf(me)||!Y.asBase&&Y.baseOf(me);return tt&&(qe(tt),qe(Fe(te,tt)),qe(Fe(J,tt))),en.set(me,Ie),Ie},dn=(me,Ie)=>{let qe=nt(Ie),tt=Ne.has(me)?me:!W.asBase&&W.baseOf(me)||!Y.asBase&&Y.baseOf(me),Ke=Ut=>qe?Ut.split(qe).length-1:0;if(tt&&Xe(Ie)&&!Ne.has(Ie)){let Ut=Ke(nt(tt));for(let _t of[Fe(te,tt),Fe(J,tt)]){if(!_t||_t===Ie||_t.ownerDocument!==Ie.ownerDocument)continue;let an=nt(_t);if(an.length>qe.length&&Ke(an)>=Ut&&(an.startsWith(qe)||an.endsWith(qe)))return!1}}let kt=_e(Ie),yt=Vn(me),Pt=0;for(let Ut of kt)yt.has(Ut)&&Pt++;if(kt.size&&Pt*2>=kt.size)return!0;if(!qe||qe.length>Ks)return!1;let Ft=tt?[me,tt,Fe(te,tt),Fe(J,tt)]:[me],on=(Ut,_t)=>Ut!==_t&&(Ut.startsWith(_t)||Ut.endsWith(_t));if(Ft.some(Ut=>Ut&&on(nt(Ut),qe)))return!0;if(!Ne.has(Ie)||!tt)return!1;let vt=nt(me),Ln=nt(tt);return[Fe(te,Ie),Fe(J,Ie)].some(Ut=>{let _t=Ut&&nt(Ut);return!!_t&&vt!==_t&&(vt.startsWith(_t)&&!Ln.startsWith(_t)||vt.endsWith(_t)&&!Ln.endsWith(_t))})},ln=me=>{$e||($e=new Set),$e.add(me)},Wn=me=>{ln(me);for(let[Ie,qe]of[[te,W],[J,Y]]){if(qe.asBase)continue;let tt=Fe(Ie,me);tt&&qe.here(tt)&&ln(tt)}},Je=(me,Ie)=>me.asBase||ie.every(qe=>!Xe(qe)||Ie.identical.has(qe)&&me.here(Fe(Ie,qe)))&&me.units.every(qe=>!Xe(qe)||me.baseOf(qe));if(Je(W,te)&&Je(Y,J))return null;let ft=me=>{if(me.asBase)return!1;let Ie=-1;for(let qe of me.units){let tt=Xe(qe)?me.baseOf(qe):null;if(!tt||!Ne.has(tt))continue;let Ke=Le.get(tt);if(Ke<Ie)return!0;Ie=Ke}return!1};if(ft(W)||ft(Y))return null;for(let[me,Ie]of[[W,te],[Y,J]]){if(me.asBase||Je(me,Ie))continue;let qe=me.units,tt=Ie===te?f.local:f.remote,Ke=(Pe,pt)=>{let Mt=Xe(Pe)&&f.base(Pe),xt=Xe(pt)&&tt(pt);return!Mt||!xt||Mt===xt},kt=new Map;for(let Pe=0;Pe<qe.length;Pe++)kt.set(qe[Pe],Pe);let yt=Pe=>!!Pe&&(Xe(Pe)?me.here(Pe):kt.has(Pe)),Pt=Pe=>{let pt=me.twin(Pe);return yt(pt)?pt:null},Ft=ie.filter(Pe=>!me.twin(Pe)&&ct(Pe)),on=qe.filter(Pe=>!me.baseOf(Pe)&&ct(Pe)),vt=(Pe,pt)=>pt===ie?!!Pt(Pe):Ne.has(me.baseOf(Pe)),Ln=Pe=>{let pt=new Int32Array(Pe.length),Mt=new Int32Array(Pe.length),xt=-1;for(let mt=0;mt<Pe.length;mt++)pt[mt]=xt,vt(Pe[mt],Pe)&&(xt=mt);xt=Pe.length;for(let mt=Pe.length-1;mt>=0;mt--)Mt[mt]=xt,vt(Pe[mt],Pe)&&(xt=mt);return{prev:pt,next:Mt}},Ut=Ln(qe),_t=Ln(ie),an=(Pe,pt)=>{Wn(Pe),ln(pt)};for(let Pe of on){let pt=kt.get(Pe),Mt=Ut.prev[pt],xt=Ut.next[pt],mt=Mt>=0?me.baseOf(qe[Mt]):null,yn=xt<qe.length?me.baseOf(qe[xt]):null,Vt=mt?Le.get(mt):-1,Rn=yn?Le.get(yn):ie.length;for(let Tn=Math.max(0,Vt);Tn<=Math.min(Rn,ie.length-1);Tn++){let Gt=ie[Tn];(ct(Gt)||He(Gt))&&(!Ke(Gt,Pe)||!dn(Gt,Pe)||(He(Gt)?ln(Pe):an(Gt,Pe)))}}let bn=(Pe,pt,Mt)=>{for(let xt=pt+Mt;xt>=0&&xt<Pe.length;xt+=Mt){let mt=Pe[xt];if(ct(mt))return mt;if(Xe(mt)||mt.value.trim())return null}return null},Uo=Pe=>{let pt=new Set;for(let Mt of s(Pe))if(!Xe(Mt)&&Mt.kind==="text")for(let xt of _e(Mt))pt.add(xt);return pt},Zn=(Pe,pt)=>{let Mt=_e(pt),xt=new Set;for(let mt of Uo(Pe))Mt.has(mt)||xt.add(mt);return xt},bo=(Pe,pt)=>{if(!Pe.size)return!1;let Mt=_e(pt),xt=0;for(let mt of Pe)Mt.has(mt)&&xt++;return xt*2>=Pe.size};for(let Pe of ie){if(Ie.identical.has(Pe)||!ct(Pe))continue;let pt=Pt(Pe);if(!pt||!ct(pt))continue;let Mt=Zn(pt,Pe),xt=Zn(Pe,pt);for(let mt of[-1,1]){let yn=bn(ie,Le.get(Pe),mt);yn&&bo(Mt,yn)&&(an(Pe,pt),Wn(yn));let Vt=bn(qe,kt.get(pt)??-1,mt);if(Vt&&bo(xt,Vt)){an(Pe,pt);let Rn=me.baseOf(Vt);Rn?an(Rn,Vt):ln(Vt)}}}for(let Pe of Ft){let pt=Le.get(Pe),Mt=_t.prev[pt],xt=_t.next[pt],mt=Mt>=0?Pt(ie[Mt]):null,yn=xt<ie.length?Pt(ie[xt]):null,Vt=mt?kt.get(mt)??-1:-1,Rn=yn?kt.get(yn)??-1:qe.length;for(let Tn=Math.max(0,Vt);Tn<=Math.min(Rn,qe.length-1);Tn++){let Gt=qe[Tn];if((ct(Gt)||He(Gt))&&!(!Ke(Pe,Gt)||!dn(Gt,Pe))&&(Wn(Pe),!He(Gt))){let _o=me.baseOf(Gt);_o?an(_o,Gt):ln(Gt)}}}}if(!$e)return null;for(let me of Array.from($e))if(Ne.has(me))for(let Ie of[te,J]){let qe=Fe(Ie,me);qe&&!he(qe,Ie===te?v:j,Ie)&&!(Ie===te?W:Y).asBase&&($e.delete(me),$e.delete(Fe(te,me)),$e.delete(Fe(J,me)))}return $e.size?$e:null}function zt(){if((W.asBase||te.identical.has(u))&&(Y.asBase||J.identical.has(u)))return;let X={ignored:r,remoteWins:o.remoteWins,inlineCache:Se},Re=Je=>Xe(Je)?qn(Je,X):Je.kind==="text",Ae=cn(Re),Ge=Je=>Ae&&Ae.has(Je)||Re(Je),ct=ie.map(Ge);if(!ct.includes(!0))return;let He=Je=>{let ft=Je.units,me=new Map;for(let yt=0;yt<ft.length;yt++)me.set(ft[yt],yt);let Ie=[],qe=-1;for(let yt=0;yt<ie.length;yt++){if(ct[yt])continue;let Pt=Je.twin(ie[yt]),Ft=Pt?me.get(Pt):void 0;Ft===void 0||Ft<=qe||Ge(Pt)||(Ie.push([yt,Ft]),qe=Ft)}let tt=[],Ke=-1,kt=-1;for(let yt=0;yt<=Ie.length;yt++){let[Pt,Ft]=yt<Ie.length?Ie[yt]:[ie.length,ft.length],on={bLo:-1,bHi:-1,sLo:-1,sHi:-1,next:Ft};for(let vt=Ke+1;vt<Pt;vt++)ct[vt]&&(on.bLo<0&&(on.bLo=vt),on.bHi=vt);for(let vt=kt+1;vt<Ft;vt++)Ge(ft[vt])&&(on.sLo<0&&(on.sLo=vt),on.sHi=vt);tt.push(on),Ke=Pt,kt=Ft}return{units:ft,list:tt}},$e=He(W),et=He(Y),_e=[];for(let Je of[$e,et])for(let ft of Je.list)ft.bLo>=0&&_e.push([ft.bLo,ft.bHi]);_e.sort((Je,ft)=>Je[0]-ft[0]);let nt=[];for(let[Je,ft]of _e){let me=nt[nt.length-1];me&&Je<=me.hi?me.hi=Math.max(me.hi,ft):nt.push({lo:Je,hi:ft})}let en=(Je,ft)=>{let me=-1,Ie=-1;for(let Ke=0;Ke<Je.list.length;Ke++){let kt=Je.list[Ke];kt.bLo<ft.lo||kt.bLo>ft.hi||(me<0&&(me=Ke),Ie=Ke)}let qe=1/0,tt=-1;for(let Ke=me;Ke>=0&&Ke<=Ie;Ke++){let kt=Je.list[Ke];kt.sLo>=0&&(qe=Math.min(qe,kt.sLo),tt=Math.max(tt,kt.sHi)),Ke<Ie&&(qe=Math.min(qe,kt.next),tt=Math.max(tt,kt.next))}return tt<0?[]:Je.units.slice(qe,tt+1)},Vn=(Je,ft)=>Je.length===ft.length&&Je.every((me,Ie)=>c.equalUnits(me,ft[Ie])),dn=Je=>!Xe(Je)&&Je.kind==="comment",ln=Je=>{if(!Je.length)return[];let ft=(Ke,kt)=>Xe(Ke)?Ke:Ke.nodes[kt?Ke.nodes.length-1:0],me=ft(Je[0]),Ie=ft(Je[Je.length-1],!0),qe=Ke=>Ke&&Xe(Ke)&&r(Ke);for(;qe(me.previousSibling);)me=me.previousSibling;for(;qe(Ie.nextSibling);)Ie=Ie.nextSibling;let tt=[];for(let Ke=me;Ke&&(tt.push(Ke),Ke!==Ie);Ke=Ke.nextSibling);return tt},Wn=Je=>Je.some(ft=>Xe(ft)&&r(ft));for(let Je of nt){let ft=ie.slice(Je.lo,Je.hi+1),me=W.asBase?null:en($e,Je),Ie=Y.asBase?null:en(et,Je);if(ft.some(dn)||me&&me.some(dn)||Ie&&Ie.some(dn))continue;let qe=ln(me||ft),tt=ln(Ie||ft);if((!me||Vn(ft,me))&&(!Ie||Vn(ft,Ie))&&!(me&&Wn(qe)))continue;let Ke=Ir({base:ln(ft),local:qe,remote:tt,out:_,policy:O,blocks:Ae,L:me?te:zs(te,u),R:Ie?J:zs(J,u),idOf:{local:S,remote:L},ignored:r,ignoreAttribute:o.ignoreAttribute,remoteWins:o.remoteWins,mergeElement:(yt,Pt,Ft)=>Et(yt,Pt,Ft,!1),cloneUnit:y,mergeAttrs:M,atomKey:c.exactUnitKey,moveIn:Qt,provenance:ye,textMappers:ge,conflicts:Be,conflict:de,scope:{base:u,local:W.asBase?null:W.el,remote:Y.asBase?null:Y.el,units:ie,at:Je.lo},decisions:Oe,node:V});rt.push(...Ke.segments);let kt=_.createDocumentFragment();for(let yt of Ke.nodes)kt.appendChild(yt);for(let yt of[...ft,...me||[],...Ie||[]])re.add(yt),Ue.add(yt),je.set(yt,kt);ht.push({frag:kt,at:Je.lo})}}}function P(u,v){let j=ye.get(u);return j&&j.unchanged?!j.remote||j.remote===v?!0:p(j.remote,v):u.tagName!==v.tagName||!$(u,v)?!1:H(R(u),R(v))}function p(u,v){return u===v?!0:u.tagName!==v.tagName||u.namespaceURI!==v.namespaceURI||!$(u,v)?!1:k(R(u),R(v))}function k(u,v){let j=F(u,r),U=F(v,r);if(j.length!==U.length)return!1;for(let V=0;V<j.length;V++){let W=j[V],Y=U[V];if(typeof W=="string"||typeof Y=="string"){if(W!==Y)return!1}else{if(W.nodeType!==Y.nodeType)return!1;if(W.nodeType===1){if(!p(W,Y))return!1}else if(W.nodeValue!==Y.nodeValue)return!1}}return!0}function R(u){return u.tagName==="TEMPLATE"&&u.content?u.content:u}function $(u,v){let j=0;for(let U of u.attributes)if(!o.ignoreAttribute(u,U.name)&&(j++,v.getAttribute(U.name)!==U.value))return!1;for(let U of v.attributes)o.ignoreAttribute(v,U.name)||j--;return j===0}function H(u,v){let j=F(u,V=>{let W=ye.get(V);return!!(W&&W.pinned)}),U=F(v,r);if(j.length!==U.length)return!1;for(let V=0;V<j.length;V++){let W=j[V],Y=U[V];if(typeof W=="string"||typeof Y=="string"){if(W!==Y)return!1}else{if(W.nodeType!==Y.nodeType)return!1;if(W.nodeType===1){if(!P(W,Y))return!1}else if(W.nodeValue!==Y.nodeValue)return!1}}return!0}function F(u,v){let j=[],U=null;for(let V=u.firstChild;V;V=V.nextSibling){if(V.nodeType===3){U=U===null?V.nodeValue:U+V.nodeValue;continue}V.nodeType===1&&v(V)||(U!==null&&(U!==""&&j.push(U),U=null),j.push(V))}return U!==null&&U!==""&&j.push(U),j}function N(u,v,j,U){let V=u.value,W=U?V:v?v.value:"",Y=j?j.value:"";re.add(u),v&&re.add(v),j&&re.add(j);let ie=W===Y?W:W===V?Y:Y===V||O==="local"?W:Y,Ne={site:"comment",bRun:u,lRun:v,rRun:j,node:null};if(W!==V&&Y!==V&&W!==Y&&de({kind:"text",node:null,base:V,local:W,remote:Y,resolved:ie},Ne),!v&&!j)return null;let Le=_.createComment(ie);return Ne.node=Le,ye.set(Le,{base:u.nodes,local:v?v.nodes:null,remote:j?j.nodes:null}),Le}function E(u,v){let j=Fe(v,u);if(!j)return null;let U=Xe(j)?j.parentNode:j.parent,V=Xe(u)?u.parentNode:u.parent;return Fe(v,V)===U?null:v.reverse.get(U)||null}function G(u){let v=new Set([u]),j=u;for(let U=0;U<64;U++){let V=E(j,te)||E(j,J);if(!V)return!1;if(V===u||Xe(u)&&Xe(V)&&u.contains(V)||v.has(V))return!0;v.add(V),j=V}return!0}function he(u,v,j){if(!v)return!1;let U=Xe(u)?u.parentNode:u.parent;return U===v||v.tagName==="TEMPLATE"&&U===v.content}function ve(u,v){let j=ne(u),U=Fe(te,j);if(U&&he(v,U,te))return!0;let V=Fe(J,j);return!!(V&&he(v,V,J))}}function zs(e,t){return e.map.get(t)?Gs():{map:{get:o=>o&&o.nodeType===1&&e.map.get(o)||o,has:()=>!0},reverse:{get:o=>e.reverse.get(o)||o,has:()=>!0},moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}function Gs(){let e={get:t=>t,has:()=>!0};return{map:e,reverse:e,moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}var Ys=new Set(["INPUT","OPTION","TEXTAREA"]),jr=/[\t\n\f\r ]+/;function Js(e,t,n,o){let r=e.ownerDocument,{provenance:i,textMappers:c}=n,s=o.hooks,a=[],m=[],h=[],d=new Set,b=[],A=[],S=new Map,L=new Set,f=new Map,g=n.conflicts.length>0,x=new Map,Q=new Set,se=new Map,le=(M,Z)=>{let ee=se.get(M);ee||se.set(M,ee=new Set),ee.add(Z)},q=g?new Set:null,z=(M,Z,ee)=>{let ue=s.beforeAttributeUpdated(M,Z,ee);return g&&ue===!1&&le(Z,M),ue},ce=M=>!!M&&(M===e||e.contains(M)||e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content.contains(M)),xe=new Map,te=new Map,J=new Map,Ce=new Set,we=new Map;(function M(Z){let ee=i.get(Z);if(ee){if(Z.nodeType===1){let oe=ee.local?o.toLive(ee.local):null;oe&&ce(oe)&&oe.nodeType===1&&(xe.set(Z,oe),te.set(oe,Z))}else if(Array.isArray(ee.local)){let oe=ge(ee.local,ee.local.map(fe=>o.toLive(fe)).filter(fe=>fe&&ce(fe)&&fe.nodeType===Z.nodeType));if(oe.length&&(xe.set(Z,oe[0]),te.set(oe[0],Z),J.set(Z,oe)),Array.isArray(ee.caret))for(let fe of ee.caret){let y=o.toLive(fe.node);if(!y||!ce(y)||y.nodeType!==3)continue;let T=we.get(y);Array.isArray(T)||we.set(y,T=[]),T.push({merged:Z,from:fe.from,to:fe.to,flatStart:fe.flatStart})}else{let fe=0;for(let y of oe)we.set(y,{merged:Z,shift:fe}),fe+=y.nodeValue.length}}}let ue=Z.nodeType===1&&Z.tagName==="TEMPLATE"&&Z.content?Z.content.childNodes:Z.childNodes;for(let oe of ue)M(oe)})(t);let ne=new Set;for(let M of xe.values())ne.add(M);for(let M of J.values())for(let Z of M)ne.add(Z);for(let M of n.segments||[])Oe(M);let _=o.restoreFocus===!1?null:Vc(r,we);o.childrenOnly?re(Be(e),Be(t)):We(e,t);for(let{node:M,parent:Z}of b)d.has(M)||!M.parentNode||M.nodeType===1&&(o.ignored(M)||ut(M))||De(M,Z);return Wc(r,_,we,c,J,f,Ce),{applied:a,moved:m,replaced:h,identities:A,mergedScriptsLive:L,liveOf:xe,heldBy:f,runOf:J,keptRuns:Ce,insertedLive:x,vetoed:Q,vetoedAttrs:se,removedVetoes:q};function ye(M,Z){let ee=M.slice(Z.bs,Z.be),ue=0;for(;ue<ee.length&&ue<Z.text.length&&ee[ue]===Z.text[ue];)ue++;let oe=0;for(;oe<ee.length-ue&&oe<Z.text.length-ue&&ee[ee.length-1-oe]===Z.text[Z.text.length-1-oe];)oe++;return{bs:Z.bs+ue,be:Z.be-oe,text:Z.text.slice(ue,Z.text.length-oe)}}function ge(M,Z){if(!Z.length)return Z;let ee=[];for(let fe of M){let y=fe.parentNode;if(!y)continue;let T=S.get(y);if(!T){T=new Set;for(let P=y.firstChild;P;P=P.nextSibling)P.nodeType===3&&T.add(o.toLive(P));S.set(y,T)}ee.includes(T)||ee.push(T)}let ue={has:fe=>ee.some(y=>y.has(fe))},oe=[];for(let fe of Z){oe.push(fe);for(let y=fe.nextSibling;y&&y.nodeType===3&&!ue.has(y)&&!oe.includes(y);y=y.nextSibling)oe.push(y)}return oe}function Oe(M){let Z=[];for(let N of M.localNodes){let E=o.toLive(N.node);if(!E||!ce(E)||E.nodeType!==3)return;Z.push(E)}let ee=ge(M.localNodes.map(N=>N.node),Z);if(!ee.length)return;let ue=ee.map(N=>N.nodeValue).join(""),{flatLocal:oe,lToM:fe,mapLocal:y}=M;if(ue===oe)return;let T=M.textNodes.map(N=>({node:N.node,ms:N.ms,me:N.me})),P=[],p=0;for(let N of ee)P.push(p),p+=N.nodeValue.length;let k=(N,E)=>ee.find((G,he)=>P[he]<=N&&N+E<=P[he]+G.nodeValue.length)||null,R=[],$=0;for(let N of xo(oe,ue).map(E=>ye(oe,E))){let E=N.bs+$;$+=N.text.length-(N.be-N.bs);let G,he;if(N.be>N.bs){G=fe[N.bs];let ve=G>=0;for(let u=N.bs;ve&&u<N.be;u++)fe[u]!==G+(u-N.bs)&&(ve=!1);if(!ve)continue;he=G+(N.be-N.bs)}else{let ve=N.bs>0?fe[N.bs-1]:0,u=N.bs<oe.length?fe[N.bs]:0;if(ve<0||u<0)continue;G=he=y(N.bs)}R.push({ms:G,me:he,text:N.text,live:he===G?k(E,N.text.length):null})}R.sort((N,E)=>E.ms-N.ms);let H=(N,E)=>(J.get(N.node)||[xe.get(N.node)]).includes(E),F=N=>!!N&&N.nodeType===1&&An.has(N.tagName);for(let N of R){let E=T.find(he=>he.ms<=N.ms&&N.me<=he.me&&N.ms<he.me);if(E&&N.live&&E.ms===N.ms&&!H(E,N.live)){let he=T.find(ve=>ve.me===N.ms&&H(ve,N.live));he&&(E=he)}if(!E&&N.me===N.ms){let he=T.find(j=>j.me===N.ms),ve=T.find(j=>j.ms===N.ms),u=he||ve;if(!u)continue;let v=u.node;for(;F(v.parentNode)&&(he?v.parentNode.lastChild:v.parentNode.firstChild)===v;)v=v.parentNode;if(v===u.node)E=u;else{let j=v.ownerDocument.createTextNode(N.text);v.parentNode.insertBefore(j,he?v.nextSibling:v);continue}}if(!E)continue;let G=E.node.nodeValue;E.node.nodeValue=G.slice(0,N.ms-E.ms)+N.text+G.slice(N.me-E.ms),E.me+=N.text.length-(N.me-N.ms)}}function Be(M){return M.nodeType===1&&M.tagName==="TEMPLATE"&&M.content?M.content:M}function We(M,Z){d.add(M);let ee=i.get(Z);if(ee&&ee.remote&&n.remoteIdOf){let oe=n.remoteIdOf(ee.remote);oe&&A.push([M,oe])}if(ee&&ee.unchanged){n.customIdentity&&ee.remote&&B(M,ee.remote),ee.remote&&O(M,ee.remote);return}if(s.beforeNodeMorphed(M,Z)===!1){Q.add(Z);return}nn(M,Z,o.keepLiveOnly&&ee&&ee.local&&ee.local.nodeType===1&&ee.local!==M?ee.local:null);let ue=M.tagName;if(tn(M))M.textContent!==Z.textContent&&(a.push({kind:"text",node:M,before:M.textContent,after:Z.textContent}),M.textContent=Z.textContent),n.mergedScripts.has(Z)&&L.add(M);else if(ue==="TEXTAREA")sn(M,Z,ee);else{Et(M,Z,ee);let oe=ue==="TEMPLATE"&&M.content?M.content:M,fe=ue==="TEMPLATE"&&Z.content?Z.content:Z;o.protectFocusedValue==="subtree"&&Qt(M)&&M!==r.body?rt(oe):re(oe,fe)}s.afterNodeMorphed(M,Z)}function rt(M){for(let Z=M.firstChild;Z;Z=Z.nextSibling){let ee=te.get(Z);ee&&xe.get(ee.parentNode)!==M||(d.add(Z),Z.nodeType===1&&rt(Z))}}function re(M,Z){let ee=de(M.firstChild),ue=new Set;for(let oe of Array.from(Z.childNodes)){let fe=xe.get(oe);fe&&d.has(fe)&&!ue.has(fe)&&(fe=null);let y=i.get(oe);if(y&&y.pinned){fe&&fe.nodeType===1&&((fe.parentNode!==M||de(fe.nextSibling)!==ee)&&ze(M,fe,ee),d.add(fe),ue.add(fe));continue}if(fe&&fe.nodeType===1){if(fe!==ee){let p=fe.parentNode;if(p===M&&ee&&Xt(fe)){let k=fe.nextSibling;for(let R=ee;R&&R!==fe;){let $=R.nextSibling;ze(M,R,k),R=$}}else ze(M,fe,ee),p!==M&&(m.push(fe),a.push({kind:"move",el:fe,from:p,to:M}))}ue.add(fe),We(fe,oe),ee=de(fe.nextSibling);continue}if(fe&&fe.nodeType!==1){let p=J.get(oe)||[fe],k=p.map($=>$.nodeValue).join(""),R=oe.nodeValue;if(oe.nodeType===3){let $=dt(oe);$!=null&&k!==$&&(R=wo($,k,oe.nodeValue).text)}if(p.length>1&&k===R&&!p.includes(ee,1)&&p.every(($,H)=>$.parentNode===M&&(H===0||p[H-1].nextSibling===$))){if(fe!==ee)for(let $ of p)ze(M,$,ee);s.beforeNodeMorphed(fe,oe)!==!1?s.afterNodeMorphed(fe,oe):g&&Q.add(oe);for(let $ of p)d.add($),ue.add($);f.set(oe,fe),Ce.add(oe),ee=de(p[p.length-1].nextSibling);continue}fe!==ee&&ze(M,fe,ee),s.beforeNodeMorphed(fe,oe)!==!1?(fe.nodeValue!==R&&(a.push({kind:"text",node:fe,before:fe.nodeValue,after:R}),fe.nodeValue=R),s.afterNodeMorphed(fe,oe)):Q.add(oe),d.add(fe),ue.add(fe),f.set(oe,fe),ee=de(fe.nextSibling);continue}if(oe.nodeType===3&&ee&&ee.nodeType===3&&!d.has(ee)&&!we.has(ee)){ee.nodeValue!==oe.nodeValue&&(a.push({kind:"text",node:ee,before:ee.nodeValue,after:oe.nodeValue}),ee.nodeValue=oe.nodeValue),d.add(ee),f.set(oe,ee),ee=de(ee.nextSibling);continue}let T=i.get(oe),P=Qe(T&&T.unchanged&&T.remote?T.remote:oe);if(s.beforeNodeAdded(P)===!1){Q.add(oe);continue}M.insertBefore(P,ee),d.add(P),g&&x.set(oe,P),P.nodeType===3&&f.set(oe,P),P.nodeType===1&&(h.push(P),be(P,oe),n.customIdentity&&T&&T.unchanged&&T.remote&&B(P,T.remote),tn(P)||st(P,oe),o.formState==="property"&&Bt(T)&&O(P,T.remote)),ee=de(P.nextSibling),a.push({kind:"insert",node:P,parent:M}),s.afterNodeAdded(P)}for(let oe of Array.from(M.childNodes))d.has(oe)||ue.has(oe)||oe.nodeType===1&&(o.ignored(oe)||ut(oe))||(ne.has(oe)?b.push({node:oe,parent:M}):De(oe,M))}function ut(M){return o.preserve&&M.parentNode&&M.parentNode.nodeType===1&&M.parentNode.tagName==="HEAD"&&o.preserve(M)===!0}function dt(M){let Z=i.get(M);return!Z||!Array.isArray(Z.local)?null:Z.local.map(ee=>ee.nodeValue).join("")}function Se(M){return i.get(M)}function O(M,Z){if(!Ys.has(M.tagName)&&!M.querySelector("input,option,textarea"))return;let ee=(ue,oe)=>{if(ue.tagName!==oe.tagName)return;ue.tagName==="TEXTAREA"?sn(ue,oe,{remote:oe}):Ys.has(ue.tagName)&&Et(ue,oe,{remote:oe});let fe=ae(ue),y=ae(oe);if(fe.length===y.length)for(let T=0;T<fe.length;T++)ee(fe[T],y[T])};ee(M,Z)}function B(M,Z){let ee=ae(M),ue=ae(Z);if(ee.length===ue.length)for(let oe=0;oe<ee.length;oe++){let fe=n.remoteIdOf(ue[oe]);fe&&A.push([ee[oe],fe]),B(ee[oe],ue[oe])}}function ae(M){let Z=M.tagName==="TEMPLATE"&&M.content?M.content:M;return Array.from(Z.children).filter(ee=>!o.ignored(ee))}function be(M,Z){if(!n.remoteIdOf)return;let ee=(ue,oe)=>{let fe=i.get(oe);if(fe&&fe.remote&&oe.nodeType===1){let P=n.remoteIdOf(fe.remote);P&&A.push([ue,P])}let y=ue.childNodes,T=oe.childNodes;for(let P=0;P<y.length&&P<T.length;P++)ee(y[P],T[P])};ee(M,Z)}function de(M){for(;M&&M.nodeType===1&&o.ignored(M);)M=M.nextSibling;return M}function ze(M,Z,ee){if(typeof M.moveBefore=="function"&&Z.ownerDocument===M.ownerDocument)try{M.moveBefore(Z,ee);return}catch{}M.insertBefore(Z,ee)}function De(M,Z){if(s.beforeNodeRemoved(M)===!1){g&&q.add(M);return}M.parentNode.removeChild(M),a.push({kind:"remove",node:M,parent:Z}),s.afterNodeRemoved(M)}function Qe(M){if(tn(M))return To(M,r);let Z=r.importNode(M,!0);if(Z.nodeType===1)for(let ee of Array.from(Z.querySelectorAll("script")))tn(ee)&&ee.replaceWith(To(ee,r));return Z}function st(M,Z){let ee=M.tagName==="TEMPLATE"&&M.content?M.content:M,ue=Z.tagName==="TEMPLATE"&&Z.content?Z.content:Z,oe=Array.from(ee.childNodes),fe=Array.from(ue.childNodes);for(let y=0;y<fe.length&&y<oe.length;y++){let T=fe[y],P=oe[y],p=xe.get(T);p&&d.has(p)&&(p=null);let k=i.get(T);if(k&&k.pinned){if(p&&p.nodeType===1){let R=p.parentNode;ze(ee,p,P),R!==ee&&(m.push(p),a.push({kind:"move",el:p,from:R,to:ee})),d.add(p)}P.remove();continue}if(p){let R=p.parentNode;ze(ee,p,P),P.remove(),p.nodeType===1?(R!==ee&&(m.push(p),a.push({kind:"move",el:p,from:R,to:ee})),We(p,T)):(d.add(p),f.set(T,p),p.nodeValue!==T.nodeValue&&(a.push({kind:"text",node:p,before:p.nodeValue,after:T.nodeValue}),p.nodeValue=T.nodeValue));continue}d.add(P),g&&x.set(T,P),P.nodeType===3&&f.set(T,P),k&&k.unchanged&&k.remote?(wt(P,k.remote),n.customIdentity&&B(P,k.remote)):T.nodeType===1&&!tn(T)&&st(P,T)}}function wt(M,Z){let ee=M.tagName==="TEMPLATE"&&M.content?M.content:M,ue=Z.tagName==="TEMPLATE"&&Z.content?Z.content:Z;for(let oe of Array.from(ue.childNodes))ee.appendChild(Qe(oe))}function bt(M,Z){return Z.namespaceURI?M.getAttributeNS(Z.namespaceURI,Z.localName):M.getAttribute(Z.name)}function Tt(M,Z){let ee=new Set((Z||"").split(jr).filter(Boolean));return(M||"").split(jr).filter(ue=>ue&&!ee.has(ue))}function nn(M,Z,ee){for(let ue of Array.from(Z.attributes)){if(Fe(M,ue.name)||o.ignoreAttribute(M,ue.name))continue;let oe=bt(M,ue);if(oe===ue.value||ee&&bt(ee,ue)===ue.value)continue;let fe=ue.value;if(ee&&ue.name==="class"&&!ue.namespaceURI){let y=ue.value.split(jr).filter(Boolean),T=Tt(oe,ee.getAttribute("class")).filter(P=>!y.includes(P));T.length&&(fe=[...y,...T].join(" "))}if(oe!==fe){if(s.beforeAttributeUpdated(ue.name,M,"update")===!1){g&&le(Z,ue.name);continue}ue.namespaceURI?M.setAttributeNS(ue.namespaceURI,ue.name,fe):M.setAttribute(ue.name,fe),a.push({kind:"attr",el:M,name:ue.name,before:oe,after:fe})}}for(let ue of Array.from(M.attributes)){if(Fe(M,ue.name)||o.ignoreAttribute(M,ue.name)||(ue.namespaceURI?Z.hasAttributeNS(ue.namespaceURI,ue.localName):Z.hasAttribute(ue.name)))continue;if(ee&&ue.name==="class"&&!ue.namespaceURI){let y=Tt(ue.value,ee.getAttribute("class"));if(y.length){let T=y.join(" ");if(T===ue.value)continue;if(s.beforeAttributeUpdated("class",M,"update")===!1){g&&le(Z,"class");continue}M.setAttribute("class",T),a.push({kind:"attr",el:M,name:"class",before:ue.value,after:T});continue}}if(ee&&bt(ee,ue)===null)continue;if(s.beforeAttributeUpdated(ue.name,M,"remove")===!1){g&&le(Z,ue.name);continue}let fe=ue.value;ue.namespaceURI?M.removeAttributeNS(ue.namespaceURI,ue.localName):M.removeAttribute(ue.name),a.push({kind:"attr",el:M,name:ue.name,before:fe,after:null})}}function Fe(M,Z){let ee=M.tagName;return ee==="INPUT"?Z==="value"||Z==="checked"||Z==="disabled":ee==="OPTION"?Z==="selected":!1}function Qt(M){return M===r.activeElement}function Xt(M){let Z=r.activeElement;return!!Z&&Z!==r.body&&M.contains(Z)}function Bt(M){let Z=M&&M.remote;return Z&&Z.nodeType===1?Z:null}function Et(M,Z,ee){let ue=M.tagName,oe=Bt(ee),fe=o.formState==="property"&&oe?oe:Z;if(ue==="INPUT"){let y=o.protectFocusedValue&&Qt(M),T=(M.getAttribute("type")||"").toLowerCase(),P=T!=="file"&&T!=="checkbox"&&T!=="radio",p=oe&&oe.hasAttribute("value")&&oe.value!==oe.getAttribute("value")?oe.value:null;if(P&&!y)if(o.formState==="property"){let k=Z.getAttribute("value"),R=M.getAttribute("value");(R!==k||M.value!==fe.value)&&z("value",M,k==null?"remove":"update")!==!1&&(R!==k&&(k==null?M.removeAttribute("value"):M.setAttribute("value",k),a.push({kind:"attr",el:M,name:"value",before:R,after:k})),M.value!==fe.value&&(M.value=fe.value))}else if(Z.hasAttribute("value")||p!=null){let k=p??Z.getAttribute("value");M.getAttribute("value")!==k&&z("value",M,"update")!==!1?(M.setAttribute("value",k),M.value!==k&&(M.value=k),a.push({kind:"attr",el:M,name:"value",before:null,after:k})):M.value!==k&&M.getAttribute("value")===k&&(M.value=k)}else(M.hasAttribute("value")||M.value!=="")&&z("value",M,"remove")!==!1&&(M.removeAttribute("value"),M.value="",a.push({kind:"attr",el:M,name:"value",before:"",after:null}));if(!P&&T!=="file"){let k=Z.getAttribute("value");k==null?M.hasAttribute("value")&&z("value",M,"remove")!==!1&&M.removeAttribute("value"):M.getAttribute("value")!==k&&z("value",M,"update")!==!1&&M.setAttribute("value",k)}y||(Lt(M,fe,"checked"),o.formState==="property"&&M.indeterminate!==fe.indeterminate&&(M.indeterminate=fe.indeterminate)),Lt(M,fe,"disabled")}else if(ue==="OPTION"){let y=M.parentNode&&M.closest("select");o.protectFocusedValue&&y&&Qt(y)||Lt(M,fe,"selected")}}function Lt(M,Z,ee){let ue=o.formState==="property"?!!Z[ee]:Z.hasAttribute(ee);if(o.formState!=="property"){let oe=M.hasAttribute(ee);if(oe!==ue){if(z(ee,M,ue?"update":"remove")===!1)return;ue?M.setAttribute(ee,""):M.removeAttribute(ee),a.push({kind:"attr",el:M,name:ee,before:oe?"":null,after:ue?"":null})}}M[ee]!==ue&&(M[ee]=ue)}function sn(M,Z,ee){if(o.protectFocusedValue&&Qt(M)||z("value",M,"update")===!1)return;let ue=Bt(ee),oe=Z.textContent,fe=ue&&ue.value!==ue.defaultValue?ue.value:oe;o.formState!=="property"&&M.textContent!==oe&&(a.push({kind:"text",node:M,before:M.textContent,after:oe}),M.textContent=oe),M.value!==fe&&(M.value=fe)}}function Vc(e,t){let n=e.activeElement;if(!n||n===e.body||n===e.documentElement)return null;let o={el:n,id:n.getAttribute&&n.getAttribute("id"),scrollTop:n.scrollTop,scrollLeft:n.scrollLeft};if(n.tagName==="INPUT"||n.tagName==="TEXTAREA"){try{o.selection=[n.selectionStart,n.selectionEnd,n.selectionDirection]}catch{}return o}let r=e.getSelection&&e.getSelection();if(r&&r.rangeCount){let i=r.getRangeAt(0);o.range={sc:i.startContainer,so:i.startOffset,ec:i.endContainer,eo:i.endOffset}}return o}function Wc(e,t,n,o,r,i,c){if(!t)return;let s=t.el;if(!s.isConnected&&t.id&&(s=e.getElementById(t.id)),!s||!s.isConnected)return;if(e.activeElement!==s)try{s.focus({preventScroll:!0})}catch{}try{s.scrollTop=t.scrollTop,s.scrollLeft=t.scrollLeft}catch{}if(t.selection){try{s.setSelectionRange&&!s.selectionEnd&&t.selection[1]!=null&&s.setSelectionRange(t.selection[0],t.selection[1],t.selection[2]||"none")}catch{}return}if(!t.range)return;let a=(d,b)=>{let A=n.get(d);if(Array.isArray(A)){let S=A.find(x=>b>=x.from&&b<x.to)||A.find(x=>b===x.to)||A[A.length-1],L=i.get(S.merged);if(!L||!L.isConnected)return null;let f=o.get(S.merged),g=f&&f.flat?f.flat(S.flatStart+b):b;return[L,Math.max(0,Math.min(g,L.nodeValue.length))]}if(A&&!c.has(A.merged)){let S=(r.get(A.merged)||[d])[0];if(!S.isConnected)return null;let L=o.get(A.merged),f=A.shift+b,g=L?L(f):f;return[S,Math.max(0,Math.min(g,S.nodeValue.length))]}return d.isConnected?[d,Math.min(b,d.nodeType===3?d.nodeValue.length:d.childNodes.length)]:null},m=a(t.range.sc,t.range.so),h=a(t.range.ec,t.range.eo);if(!(!m||!h))try{let d=e.createRange();d.setStart(m[0],m[1]),d.setEnd(h[0],h[1]);let b=e.getSelection();b.removeAllRanges(),b.addRange(d)}catch{}}var $c={compared:0},qc=new Set(["INPUT","SELECT","OPTION","TEXTAREA"]);function Fc(e,t,n){let o=0;for(let r of e.attributes)if(!n(e,r.name)&&(o++,t.getAttribute(r.name)!==r.value))return!1;for(let r of t.attributes)n(t,r.name)||o--;return o===0}function Dr(e,t){if(e.namespaceURI!==t.namespaceURI||e.prefix!==t.prefix||e.localName!==t.localName)return!1;let n=e.attributes;if(n.length!==t.attributes.length)return!1;for(let o of n)if(t.getAttributeNS(o.namespaceURI,o.localName)!==o.value)return!1;return!0}function Xs(e,t,n,o,r,i,c,s){let a=new Map,m=new Set,h=d=>{if(o(d))return;let b=n(d);b&&(i.add(b),r.has(b)||a.has(b)?m.add(b):a.set(b,d))};for(let d of e)h(d);h(t);for(let d of c||t.querySelectorAll("*"))h(d);for(let d of m)a.delete(d),s.add(d);return a}function Qs(e,t,n,o,r,i){let c=!1;for(let h of r)h.startsWith("merge:")&&(c=!0);if(!c)return[...o];let s=new Map,a=[],m=i===fn?So:"*";for(let h of[e,...e.querySelectorAll(m)]){if(n(h))continue;let d=t(h);if(!d||!(o.has(d)||r.has(d)))continue;let b=(s.get(d)||0)+1;s.set(d,b),b===2&&a.push(d)}return a}function Zs({baseRoot:e,remoteRoot:t,liveRoot:n,toLive:o,o:r,identity:i,baseURI:c}){if(e.tagName!==t.tagName)return{bail:"root-tag"};if(e.getElementsByTagName("template").length||t.getElementsByTagName("template").length)return{bail:"script-or-template"};if(!Fc(e,t,r.ignoreAttribute))return{bail:"root-attrs"};let{ignored:s,remoteWins:a}=r,m=Pr(r.scripts.merge===!1?null:r.scripts.mergeTags,c),h=Se=>{let O=m(Se);return O!==null?O:i.base(Se)||null},d=Se=>{let O=m(Se);return O!==null?O:i.remote(Se)||null},b=[],A=[],S=new Map,L=new Map,f={same:S,differ:L},g=Se=>({bail:Se,comparisons:f}),x=(Se,O,B=!0)=>{if(S.get(Se)===O)return!0;if(L.get(Se)===O)return!1;if($c.compared++,B&&Se.isEqualNode(O))return S.set(Se,O),!0;let ae=Se.nodeType===O.nodeType;if(ae&&Se.nodeType===1){if(ae=Dr(Se,O),ae){let be=Se.firstChild,de=O.firstChild;for(;be&&de;be=be.nextSibling,de=de.nextSibling)if(!x(be,de,!1)){ae=!1;break}(be||de)&&(ae=!1)}}else ae&&(ae=Se.isEqualNode(O));return(ae?S:L).set(Se,O),ae},Q=e,se=t,le=!1,q=()=>{S.set(Q,se);for(let Se=0;Se<b.length;Se++)S.set(b[Se],A[Se]);return g("equal")};for(;;){let Se=Q.childNodes,O=se.childNodes;if(Se.length!==O.length)break;let B=st=>x(Se[st],O[st])?(S.set(Se[st],O[st]),!1):!0,ae=-1,be=-1;for(let st=0;st<Se.length;st++){if(Se[st].nodeType!==1)continue;let wt=0;for(let bt=Se[st].firstElementChild;bt;bt=bt.nextElementSibling)wt++;wt>=be&&(be=wt,ae=st)}let de=[],ze=!1;for(let st=0;st<Se.length&&de.length<2;st++)st!==ae&&B(st)&&de.push(st);if(ae>=0&&de.length<2&&(de.length===0&&Dr(Q,se)?(de.push(ae),ze=!0):B(ae)&&de.push(ae)),de.length!==1){if(!le&&de.length===0&&Dr(Q,se))return q();break}let De=Se[de[0]],Qe=O[de[0]];if(le=le||!ze,le&&L.set(De,Qe),De.nodeType!==1||Qe.nodeType!==1||De.tagName!==Qe.tagName)break;if(h(De)!==d(Qe)){if(!le&&x(De,Qe))return q();break}b.push(Q),A.push(se),Q=De,se=Qe}L.set(Q,se);for(let Se=0;Se<b.length;Se++)L.set(b[Se],A[Se]);if(Q===e||Q.tagName==="HEAD"||Q.tagName==="BODY")return g("root-level");if(b.length<2||b[1].tagName!=="BODY")return g("not-in-body");if(s(Q)||s(se))return g("ignored-ancestor");if(a(Q)||a(se))return g("remote-wins-ancestor");for(let Se of b)if(qc.has(Se.tagName))return g("form-ancestor");if(Q.tagName==="SCRIPT"||Q.getElementsByTagName("script").length||se.getElementsByTagName("script").length)return g("script-or-template");let z=o(Q);if(!z||z.nodeType!==1||z.tagName!==Q.tagName)return g("no-live-twin");if(!n.contains(z))return g("live-detached");for(let Se of b){let O=o(Se);if(!O||O.nodeType!==1)return g("ancestor-live")}let ce=i.base===fn&&i.remote===fn&&s===pr,xe=new Set,te=new Set,J=[],Ce=null,we=Se=>{Se&&(xe.has(Se)?te.add(Se):xe.add(Se))},ne=(Se,O)=>{let B=m(Se),ae=B!==null?B:i.base(Se)||null;return ae!==(B!==null?B:i.remote(O)||null)?!1:(we(ae),!0)},_=(Se,O)=>{for(let B=Se.firstElementChild,ae=O.firstElementChild;B;B=B.nextElementSibling,ae=ae.nextElementSibling){let be=s(B);if(be!==s(ae))return!1;if(!be&&(!ne(B,ae)||!_(B,ae)))return!1}return!0},ye=Se=>{let O=Se+1<b.length?b[Se+1]:Q;for(let B=b[Se].firstElementChild,ae=A[Se].firstElementChild;B;B=B.nextElementSibling,ae=ae.nextElementSibling){if(B===O){let ze=Se+1<b.length?ye(Se+1):null;if(ze)return ze;continue}let be=s(B);if(be!==s(ae))return"outside-id-changed";if(be)continue;let de=o(B);if(!de||de.nodeType!==1)return"sibling-live";if(J.push([B,ae]),!ce&&(!ne(B,ae)||!_(B,ae)))return"outside-id-changed";Se===0&&B.tagName==="HEAD"&&h(B)&&(Ce=[B,ae])}return null},ge=ye(0);if(ge)return g(ge);let Oe=new Set(b),Be=null;if(i.base===fn){Be=[];for(let Se of e.querySelectorAll(So))Se===Q||Oe.has(Se)||(Q.contains(Se)?Be.push(Se):ce&&we(h(Se)))}let We=new Set,rt=new Set,re=new Set,ut=Xs(b,Q,h,s,xe,We,Be,rt),dt=Xs(A,se,d,s,xe,We,i.remote===fn&&se.querySelectorAll(So),re);return Ce&&(te.has(h(Ce[0]))||We.has(h(Ce[0])))&&(Ce=null),{scope:{chain:b,root:Q,onChain:Oe,baseIndex:ut,remoteIndex:dt,head:Ce,same:S,differ:L,dropped:[...Qs(e,h,s,te,rt,i.base),...Qs(t,d,s,te,re,i.remote)],held:Se=>{for(let O=1;O<b.length;O++)if(Se.map.get(b[O])!==A[O])return!1;for(let[O,B]of J)if(Se.map.get(O)!==B)return!1;return!0}}}}var Ca=Symbol("hyper-morph-duplicate-key");var Kc='[editor-ui],[clay~="editor-ui"],[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]',zc='[editor-ui],[clay~="editor-ui"],[no-undo],[clay~="no-undo"]',Gc='[no-undo]:not([editor-ui]):not([clay~="editor-ui"]),[clay~="no-undo"]:not([editor-ui]):not([clay~="editor-ui"])';function Yc(e){if(e.tagName!=="LINK"&&e.tagName!=="SCRIPT")return!1;let t=e.getAttribute("src")||e.getAttribute("href")||"";return/^(chrome|moz|safari-web)-extension:/.test(t)}function Jc(e,t,n,o){if(t==null)return;if(typeof t=="string")return t;let r=t;if(r.nodeType===9){let i=e.getAttribute("id");r=i&&r.getElementById(i)||(e.tagName==="BODY"?r.body:e.tagName==="HTML"?r.documentElement:r.body&&r.body.firstElementChild)}if((!r||r.nodeType!==1||r.tagName!==e.tagName)&&(r=Xc(e,t,o)),!!r)return n?Array.from(r.childNodes):r}function Xc(e,t,n){let o=t.nodeType===9?t.documentElement:t;if(!o||o.nodeType!==1)return null;let r=new Map,i=[o,...o.querySelectorAll("script")];for(let a of i){let m=lo(a,n);m&&!r.has(m.key)&&r.set(m.key,a.textContent)}if(!r.size)return null;let c=e.cloneNode(!0),s=!1;for(let a of[c,...c.querySelectorAll("script")]){let m=lo(a,n);m&&r.has(m.key)&&(a.textContent=r.get(m.key),s=!0)}return s?c:null}function ei(e,t){if(typeof e=="string"||e.nodeType===9)return e;if(e.nodeType===1&&e===e.ownerDocument.documentElement)return e.ownerDocument;let n=t.implementation.createHTMLDocument(""),o=e.nodeType===1&&e.tagName==="HTML"?e:null;if(o)return n.replaceChild(n.adoptNode(o),n.documentElement),n;let r=e.nodeType===11?Array.from(e.childNodes):e.nodeType?[e]:Array.from(e);for(let i of r)n.body.appendChild(n.adoptNode(i));return n}function Hr(e,t,n={}){let o=n||{};if(!o.head?.block)return ti(e,t,o);try{return ti(e,t,o)}catch(r){return Promise.reject(r)}}function ti(e,t,n){let o=n.policy||"sync",r=o==="raw"?void 0:(a,m)=>Yc(a)||(o==="history"?!(m&&a.matches(Gc))&&a.matches(zc):a.matches(Kc)),i=n.callbacks||{},c={ignore:r,hooks:i,protectFocusedValue:n.ignoreActiveValue===!0?"subtree":!1,restoreFocus:n.restoreFocus!==!1,formState:n.formStateSync||"attribute",scripts:{execute:n.scripts?.handle!==!1,merge:n.scripts?.merge!==!1,mergeTags:n.scripts?.mergeTags||[]},head:{awaitLoads:!!n.head?.block,preserve:n.head?.shouldPreserve||(()=>!1)}};if(typeof n.key=="function"&&(c.identity={base:n.key,local:n.key,remote:n.key}),e&&e.nodeType===9)return No(Object.assign({},c,{live:e,base:n.scripts?.mergeBase||null,remote:ei(t,e)}));if(e.tagName==="HTML"&&e.parentNode&&e.parentNode.nodeType===9){let a=Object.assign({},c,{live:e.ownerDocument,base:n.scripts?.mergeBase||null,remote:ei(t,e.ownerDocument)});return No(a)}n.morphStyle==="innerHTML"&&(c.children=!0);let s=Jc(e,n.scripts?.mergeBase,!!c.children,c.scripts.mergeTags);return s!==void 0&&(c.base=s),Br(e,t,c)}var Qc=new Set(["live","base","remote","local","identity","ignore","remoteWins","ignoreAttribute","conflicts","protectFocusedValue","restoreFocus","head","scripts","formState","children","hooks","beforeApply","fastPath","keepLiveOnly"]),mn=()=>{};function Oo(e,t=[]){if(!e||typeof e!="object")throw new TypeError("options object required");for(let c of Object.keys(e))if(!Qc.has(c))throw new TypeError(`unknown option "${c}"`);let n=Object.assign({beforeNodeAdded:mn,afterNodeAdded:mn,beforeNodeRemoved:mn,afterNodeRemoved:mn,beforeNodeMorphed:mn,afterNodeMorphed:mn,beforeAttributeUpdated:mn},e.hooks||{}),o=e.conflicts||"remote";if(!["remote","local","both"].includes(o))throw new TypeError("conflicts must be remote, local or both");let r=e.formState||"attribute";if(!["attribute","property"].includes(r))throw new TypeError("formState must be attribute or property");let i=e.protectFocusedValue;if(i!==void 0&&typeof i!="boolean"&&i!=="subtree")throw new TypeError('protectFocusedValue must be a boolean or "subtree"');if(e.fastPath!==void 0&&typeof e.fastPath!="boolean")throw new TypeError("fastPath must be a boolean");if(e.keepLiveOnly!==void 0&&typeof e.keepLiveOnly!="boolean")throw new TypeError("keepLiveOnly must be a boolean");return{ignored:hr(e.ignore,t),remoteWins:hr(e.remoteWins,t),ignoreAttribute:typeof e.ignoreAttribute=="function"?e.ignoreAttribute:()=>!1,conflicts:o,protectFocusedValue:i===void 0?!0:i,restoreFocus:e.restoreFocus!==!1,head:Object.assign({awaitLoads:!1,preserve:()=>!1},e.head||{}),scripts:Object.assign({execute:!0,merge:!0,mergeTags:[]},e.scripts||{}),formState:r,hooks:n,children:!!e.children,beforeApply:typeof e.beforeApply=="function"?e.beforeApply:null,fastPath:e.fastPath===!0,keepLiveOnly:e.keepLiveOnly===!0}}function fo(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){if(typeof e.first=="function")return e.first;if(typeof e.then=="function")return e.then}return fn}function uo(e,t){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){let n=mr(t,e.map),o=typeof e.then=="function"?e.then:fn;if(typeof e.first=="function"){let r=e.first;return i=>r(i)||n.get(i)||o(i)}return r=>n.get(r)||o(r)}return fn}function Zc(e,t,n,o={}){let r=A=>A&&A.nodeType===9?A.documentElement:A,i=r(t),c=r(n),s=r(e)||i,a=Object.assign({},o);delete a.live,delete a.base,delete a.remote;let m=Oo(a,[s,i,c].filter(Boolean)),h=o.identity||{},d=jn(),b=er(s,i,c,{identity:{base:uo(h.base,s),local:uo(h.local,i),remote:uo(h.remote,c)},authored:{base:fo(h.base),local:fo(h.local),remote:fo(h.remote)},skipUnchanged:m.hooks.beforeNodeMorphed===mn&&m.hooks.afterNodeMorphed===mn,ignored:m.ignored,remoteWins:m.remoteWins,ignoreAttribute:m.ignoreAttribute,conflicts:m.conflicts,mergeTags:m.scripts.merge===!1?null:m.scripts.mergeTags,baseURI:i.ownerDocument&&i.ownerDocument.baseURI||"about:blank",localIsBase:!e||e===t,childrenOnly:m.children,stats:d});return delete b.recoveryLinks,b}function Ur({liveRoot:e,baseRoot:t,localRoot:n,remoteRoot:o,toLive:r,options:i,identity:c,childrenOnly:s,isDocument:a}){let m=Oo(i,[e,t,n,o].filter(Boolean));if(m.ignored(e))return{report:_r(),loads:[]};let h=e.ownerDocument,d=m.scripts.execute?Ls(e,m.ignored,h.baseURI):null,b=jn(),A=m.hooks.beforeNodeMorphed===mn&&m.hooks.afterNodeMorphed===mn,S={identity:{base:uo(c.base,t||n),local:uo(c.local,n),remote:uo(c.remote,o)},authored:{base:fo(c.base),local:fo(c.local),remote:fo(c.remote)},ignored:m.ignored,remoteWins:m.remoteWins,ignoreAttribute:m.ignoreAttribute,conflicts:m.conflicts,mergeTags:m.scripts.merge===!1?null:m.scripts.mergeTags,baseURI:h.baseURI,localIsBase:!t,childrenOnly:s,skipUnchanged:A},L=m.fastPath&&a&&!s&&A&&t===n,f=null,g=null;if(L){let we=Zs({baseRoot:t,remoteRoot:o,liveRoot:e,toLive:r,o:m,identity:S.identity,baseURI:h.baseURI});S.comparisons=we.comparisons||we.scope,we.bail?g=we.bail:(f=er(t,n,o,Object.assign({},S,{stats:b,scope:we.scope})),f||(g="chain-unpaired",b=jn()))}f||(f=er(t||n,n,o,Object.assign({},S,{stats:b}))),L&&(b.fastPathAttempted=1,b.fastPathTaken=g?0:1,b.fastPathFallback=g),f.recoveryLinks&&["beforeNodeMorphed","beforeNodeAdded","beforeNodeRemoved","beforeAttributeUpdated"].some(we=>m.hooks[we]!==mn)&&Ws(f.conflicts,f.recoveryLinks,r),m.beforeApply&&m.beforeApply(f.doc);let x=globalThis.__hyperMorphProfile,Q=x?performance.now():0,se=Js(e,f.root,f,{toLive:r,ignored:m.ignored,ignoreAttribute:m.ignoreAttribute,formState:m.formState,protectFocusedValue:m.protectFocusedValue,restoreFocus:m.restoreFocus,preserve:m.head.preserve,hooks:m.hooks,childrenOnly:s,keepLiveOnly:m.keepLiveOnly});x&&(x.apply=(x.apply||0)+(performance.now()-Q));let le=[];if(m.head.awaitLoads)for(let we of se.applied){if(we.kind!=="insert"||we.node.nodeType!==1)continue;let ne=we.node;ne.tagName==="LINK"&&/\bstylesheet\b/i.test(ne.getAttribute("rel")||"")&&ne.getAttribute("href")&&ne.closest("head")&&le.push(new Promise(ye=>{ne.addEventListener("load",()=>ye()),ne.addEventListener("error",()=>ye())}))}let q=null,z=null;if(d){let we=Rs(e,d,{ignored:m.ignored,skip:se.mergedScriptsLive,baseURI:h.baseURI,beforeNodeAdded:m.hooks.beforeNodeAdded,afterNodeAdded:m.hooks.afterNodeAdded,trackRecovery:!!f.recoveryLinks});le.push(...we.loads),q=we.swapped,z=we.vetoed}let ce=we=>q&&q.get(we)||we,xe=we=>{if(se.keptRuns.has(we))return se.runOf.get(we);let ne=se.liveOf.get(we)||se.heldBy.get(we)||se.insertedLive.get(we);return ne?ce(ne):null},te=we=>{let ne=we&&se.liveOf.get(we);return ne?ce(ne):null},J=we=>{let ne=we&&xe(we);return Array.isArray(ne)?ne[0]:ne};if(f.recoveryLinks){let we=(ne,_,ye)=>(_.namespaceURI?ne.getAttributeNS(_.namespaceURI,_.localName):ne.getAttribute(_.qualifiedName))===ye;Fs(f.conflicts,f.recoveryLinks,{lookup:xe,vetoed:se.vetoed,vetoedAttrs:se.vetoedAttrs,removedVetoes:se.removedVetoes,vetoedLive:z,liveAttr:we,ignored:m.ignored,liveRoot:e})}return{report:{applied:se.applied,decisions:f.decisions.map(we=>Object.assign({},we,{node:we.node?te(we.node):null,el:we.el?te(we.el):null,applied:!!(we.node?te(we.node):we.el&&te(we.el))})),conflicts:f.conflicts.map(we=>Object.assign({},we,{node:we.node?we.kind==="text"&&we.recovery.subject.nodeType===8?J(we.node):te(we.node):we.node,el:we.el?we.kind==="structure"?J(we.el):te(we.el):we.el})),localDiverged:f.localDiverged,identities:se.identities,moved:se.moved,replaced:se.replaced,stats:b},loads:le}}var ni=new WeakMap;function _r(){return{applied:[],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[],stats:jn()}}function No(e){let t=e||{},n=t.live;if(!n||n.nodeType!==9)throw new TypeError("live must be a Document");let o=ni.get(n);o||(o=dr(n),ni.set(n,o));let r=o("remote",t.remote),i=typeof t.base=="string"&&t.base===""?null:t.base,c=i?o("base",i):null,s=t.local?t.local.root:n.documentElement,a=t.local?t.local.toLive:d=>d;gs(n,r);let{report:m,loads:h}=Ur({liveRoot:n.documentElement,baseRoot:c?c.documentElement:null,localRoot:s,remoteRoot:r.documentElement,toLive:a,options:t,identity:t.identity||{},childrenOnly:!1,isDocument:!0});return Promise.all(h).then(()=>m)}function el(e,t,n={}){return No(Object.assign({},n,{live:e,base:null,remote:t}))}function oi(e,t){if(e==null)return{root:t.createElement("template"),first:null};if(typeof e=="string"){let o=/^\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype[^>]*>\s*)?<(html|body)[\s>]/i.exec(e);if(o){let i=Ko(e,t),c=o[1].toLowerCase()==="html"?i.documentElement:i.body;return{root:c,first:c}}let r=t.createElement("template");return r.innerHTML=e,{root:r,first:r.content.firstElementChild}}if(e.nodeType===9)return{root:e.documentElement,first:e.documentElement};if(e.nodeType===1){let o=t.createElement("template"),r=e.isConnected;return o.content.appendChild(r?t.importNode(e,!0):e),{root:o,first:e}}if(e.nodeType===11){let o=t.createElement("template");return o.content.appendChild(e),{root:o,first:o.content.firstElementChild}}let n=t.createElement("template");for(let o of Array.from(e))n.content.appendChild(o.parentNode?t.importNode(o,!0):o);return{root:n,first:n.content.firstElementChild}}function Br(e,t,n={}){if(!e||e.nodeType!==1)throw new TypeError("oldEl must be an Element");let o=e.ownerDocument,{base:r,...i}=n,c=!!i.children;if(Oo(i,[e]).ignored(e))return Promise.resolve(_r());let s=oi(t,o),a=r!=null?oi(r,o):null,m,h=null;if(c)m=s.root,h=a?a.root:null;else{if(m=s.first,h=a?a.first:null,!m){let A=Oo(i);return A.hooks.beforeNodeRemoved(e)!==!1&&(e.remove(),A.hooks.afterNodeRemoved(e)),Promise.resolve({applied:[{kind:"remove",node:e,parent:null}],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[e],stats:jn()})}if(m.tagName!==e.tagName){let A=Oo(i,[e,m]);if(A.hooks.beforeNodeMorphed(e,m)===!1)return Promise.resolve(_r());let S=Ur({liveRoot:e,baseRoot:h&&h.tagName===e.tagName?h:null,localRoot:e,remoteRoot:m,toLive:f=>f,options:i,identity:i.identity||{},childrenOnly:!0,isDocument:!1}),L=tn(m)?To(m,o):o.importNode(m,!1);if(!tn(L))for(;e.firstChild;)L.appendChild(e.firstChild);return A.hooks.beforeNodeAdded(L)===!1?(Zo(S.report.conflicts,e,e),Promise.resolve(S.report)):A.hooks.beforeNodeRemoved(e)===!1?(Zo(S.report.conflicts,e,e),Promise.resolve(S.report)):(e.replaceWith(L),Zo(S.report.conflicts,e,L),A.hooks.afterNodeRemoved(e),A.hooks.afterNodeAdded(L),A.hooks.afterNodeMorphed(e,m),S.report.replaced.push(L),S.report.applied.push({kind:"insert",node:L,parent:L.parentNode},{kind:"remove",node:e,parent:L.parentNode}),Promise.all(S.loads).then(()=>S.report))}}let{report:d,loads:b}=Ur({liveRoot:e,baseRoot:h,localRoot:e,remoteRoot:m,toLive:A=>A,options:i,identity:i.identity||{},childrenOnly:c,isDocument:!1});return Promise.all(b).then(()=>d)}var ri={mergeDocument:No,morphDocument:el,morphElement:Br,merge3:Zc,morph:Hr};function Vr(e,t,{onWidgetRemoved:n}={}){ri.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=qo.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var nl="hha:upgrade-check:";function Sn(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function Wr(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function si(e,t){let n=Wr(e),o=Wr(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let c=n[i]||0,s=o[i]||0;if(c!==s)return c>s}return!1}function ol(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function rl(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function $r({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(b=>fetch(b)),r=r??Date.now(),!t)return null;let c=Sn(t,"hyper-source");if(!c)return null;let s=Sn(t,"hyper-version"),a;try{a=new URL(c,n?n.href:void 0)}catch{return null}if(n&&a.origin===n.origin&&a.pathname===n.pathname)return null;let m=`${nl}${a.href}:${s||"none"}`,h,d=e?null:ol(m);if(d&&typeof d.checkedAt=="number"&&r-d.checkedAt<i)h=d.sourceVersion;else{try{let b=await o(a.href);if(!b.ok)throw new Error(`HTTP ${b.status}`);let A=await b.text(),S=new DOMParser().parseFromString(A,"text/html");h=Sn(S,"hyper-version")}catch{h=null}rl(m,{checkedAt:r,sourceVersion:h})}return h?{available:si(h,s||"0.0.0"),currentVersion:s,sourceVersion:h,sourceUrl:a.href}:null}var tr=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],qr=new Set(tr),ii=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Fr=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var or={};cr(or,{EmptyListInsert:()=>Mo,MAX_RULE_DEPTH:()=>ho,MaxRuleDepthExceeded:()=>Yn,NoRulesTag:()=>Kr,RuleTargetReadOnly:()=>Eo,RulesParseError:()=>po,ShapeMismatch:()=>vo,UnknownRulesVersion:()=>Gn,WriteRefused:()=>nr,WriteRejected:()=>zr});var po=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},Gn=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},ho=20,Yn=class extends Error{constructor(t){super(`rule depth exceeded ${ho} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},vo=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Mo=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},Eo=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},nr=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}},Kr=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},zr=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function Nn(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return Gr(e,t,n,{depth:0,path:[]},o)}function Gr(e,t,n,o,r){if(o.depth>ho)throw new Yn(o.path);if(typeof n=="string")return sl(e,t,n,o,r);if(Array.isArray(n)){let[i,c]=n,s=e.find(t,i,r);return li(r,o,s),s.map((a,m)=>Gr(e,a,c,{depth:o.depth+1,path:[...o.path,m]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,s]of Object.entries(n))i[c]=Gr(e,t,s,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function sl(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),a=e.find(t,s,r);return li(r,o,a),a.map(m=>e.text(m))}if(n.startsWith("@"))return ci(e,t,n.slice(1));let i=Mn(n);if(i!==-1){let s=n.slice(0,i),a=n.slice(i+1),m=s?e.find(t,s,r):[t];return m.length===0?null:ci(e,m[0],a)}if(n===".")return e.text(t);let c=e.find(t,n,r);return c.length===0?null:e.text(c[0])}function li(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function ci(e,t,n){if(qr.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}var ai=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),il=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),fi=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function Yr(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function cl(e,t){if(Yr(e,t))return!0;for(let[n,o]of Object.entries(il))if(o.includes(t)&&Yr(e,n))return!0;return!1}function Io(e){let t=ai[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function ll(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=ai[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>cl(n,r))||o.bundles.some(r=>Yr(n,r)))return n;n=n.parentElement}return null}function ui(e,t){return!!ll(e,t)}var al=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function di(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();if("value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&(t.value=e.value),"checked"in e&&"checked"in t&&(t.checked=e.checked),"selected"in e&&"selected"in t&&(t.selected=e.selected),e.tagName==="SELECT")for(let o=0;o<e.options.length;o++)t.options[o].selected=e.options[o].selected;"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function pi(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function hi(e,t,n,o,r,i,c,s){if(e.nodeType===1&&((c?ui(e,n):pi(e,o,i,!1))||r&&(c&&e!==i?e.matches(r):pi(e,r,i,c))))return null;let a=t.importNode(e,!1);s.cloneToLive.set(a,e),s.liveToClone.set(e,a);let m=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,h=a.nodeType===1&&a.tagName==="TEMPLATE"?a.content:a;m!==e&&(s.cloneToLive.set(h,m),s.liveToClone.set(m,h));for(let d of m.childNodes||[]){let b=hi(d,t,n,o,r,i,c,s);b&&(h.appendChild(b),d.nodeType===1&&di(d,b))}return e.nodeType===1&&di(e,a),a}function Co(e,{capability:t="data",exclude:n=null,inherit:o=!0}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let r=e.nodeType===9?e:e.ownerDocument;if(!r?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let i=r.implementation.createHTMLDocument(""),c=new WeakMap,s=new WeakMap,a=e.nodeType===9?e.documentElement:e;n&&i.documentElement.matches(n);let m=Io(t),h=hi(a,i,t,m,n,a,o,{cloneToLive:c,liveToClone:s});e.nodeType===9&&h&&(i.replaceChild(h,i.documentElement),s.set(e,i),c.set(i,e));let d=b=>{if(al.test(b))throw new Error(`Filtered content queries do not support stateful selector: ${b}`)};return{root:h,document:i,capability:t,selector:Io(t),cloneToLive:c,liveToClone:s,original(b){return c.get(b)||null},cloneOf(b){return s.get(b)||null},query(b,A=h){return d(b),Array.from(A.querySelectorAll(b),S=>c.get(S)||S)},text(b=h){return(b===h?h:s.get(b))?.textContent||""},html(b=h){return(b===h?h:s.get(b))?.innerHTML??""},clone(b=h){let A=b===h?h:s.get(b);return A?i.importNode(A,!0):null}}}function mi(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function fl(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var $t={semanticExclude:!0,find(e,t,n={}){let o=fl(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!mi(s)));let i=[];n.skip&&i.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&i.push("["+c+"]"),i.length){let s=i.join(", ");r=r.filter(a=>!a.closest||!a.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function Jn(e,t={}){if(t.exclude===null)return $t;let n=[Io("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return $t;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,s=null,a=()=>s||(s=Co(i,{capability:"data",exclude:t.exclude||null})),m=S=>{let L=a();return S===e?L.cloneOf(e):L.cloneOf(S)||S},h=S=>s?.original(S)||S,d=(S,L)=>{a().liveToClone.set(S,L),a().cloneToLive.set(L,S);let f=S.childNodes||[],g=L.childNodes||[];for(let x=0;x<Math.min(f.length,g.length);x++)d(f[x],g[x])},b=(S,L,f,g)=>{let x=Array.from(S.childNodes).filter(z=>s.cloneOf(z)),se=x[0];for(;se&&x.includes(se);)se=se.nextSibling;for(let z of x)z.remove();if(f==="innerHTML"){let z=c.createElement("template");z.innerHTML=g;for(let ce of Array.from(z.content.childNodes))S.insertBefore(ce,se||null)}else S.insertBefore(c.createTextNode(g),se||null);let le=Co(S,{capability:"data",exclude:t.exclude||null});L.replaceChildren(...Array.from(le.root?.childNodes||[]));let q=z=>{let ce=le.original(z);ce&&(s.liveToClone.set(ce,z),s.cloneToLive.set(z,ce));for(let xe of Array.from(z.childNodes||[]))q(xe)};for(let z of Array.from(L.childNodes))q(z)},A={...$t,find(S,L,f={}){let g=m(S);if(!g?.querySelectorAll)return[];let x=a().query(L,g);f.includeRulesTag||(x=x.filter(le=>!mi(le)));let Q=[];f.skip&&Q.push(f.skip);let se=f.templateAttr===null?null:f.templateAttr||"cms-template";if(se&&Q.push(`[${se}]`),Q.length){let le=Q.join(", ");x=x.filter(q=>!q.closest?.(le))}return x},parent(S){let L=m(S)?.parentElement;return L?h(L):null},children(S){return Array.from(m(S)?.children||[],h)},text(S,L){if(L===void 0){let x=h(S);return!x?.matches?.(n)&&!x?.querySelector?.(n)?$t.text(x):(m(S)?.textContent||"").trim()}let f=h(S);if(!f?.matches?.(n)&&!f?.querySelector?.(n)&&!s){$t.text(f,L);return}let g=a().cloneOf(f);g?b(f,g,"textContent",L):$t.text(f,L)},attr(S,L,f){let g=h(S);if(f===void 0)return $t.attr(g,L);$t.attr(g,L,f);let x=s?.cloneOf(g);x&&($t.attr(x,L,f),Co(g,{capability:"data",exclude:t.exclude||null}).root===null&&(x.remove(),s.liveToClone.delete(g),s.cloneToLive.delete(x)))},removeAttr(S,L){let f=h(S);$t.removeAttr(f,L);let g=s?.cloneOf(f);g&&$t.removeAttr(g,L)},prop(S,L,f){let g=h(S);if(f===void 0)return L==="innerHTML"||L==="outerHTML"||L==="textContent"||L==="innerText"?$t.prop(m(g),L):$t.prop(g,L);let x=L==="innerHTML"||L==="textContent"||L==="innerText",Q=x?a().cloneOf(g):s?.cloneOf(g);Q&&x?b(g,Q,L,f):($t.prop(g,L,f),Q&&$t.prop(Q,L,f))},clone(S){let L=m(S);return L===S?$t.clone(S):c.importNode(L,!0)},insertAt(S,L,f){let g=h(S),Q=A.children(g)[f]||(()=>{for(let q=g.children.length-1;q>=0;q--){let z=g.children[q];if(a().cloneOf(z))return z.nextElementSibling}return g.firstElementChild})(),se=h(L);g.insertBefore(se,Q||null);let le=a().cloneOf(g);if(le){let q=a().cloneOf(se);q||(q=c.importNode(se,!0),d(se,q));let z=Array.from(le.children);le.insertBefore(q,z[f]||null)}},remove(S){let L=h(S),f=a().cloneOf(L);$t.remove(L),f&&$t.remove(f)},replaceWith(S,L){let f=h(S),g=a().cloneOf(f),x=$t.replaceWith(f,L);if(g){let Q=Co(x,{capability:"data",exclude:t.exclude||null});if(!Q.root)g.remove();else{g.replaceWith(Q.root);let se=le=>{let q=Q.original(le);q&&(s.liveToClone.set(q,le),s.cloneToLive.set(le,q));for(let z of Array.from(le.childNodes||[]))se(z)};se(Q.root)}}return x}};return A}var gn=$t;function Jr(e){try{return JSON.parse(e)}catch(t){throw new po(`Invalid strict JSON: ${t.message}`,t)}}function Xn(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],c=0;for(;c<r.length;){let s=r[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let d=!1,b=c+1;for(;b<r.length&&/\s/.test(r[b]);)b++;if(b<r.length&&/[a-zA-Z_]/.test(r[b])&&(d=!0),!d){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:t.COLON,value:s}),c++;continue}if(s===","){i.push({type:t.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let d=s,b=c+1;for(;b<r.length&&r[b]!==d;)r[b]==="\\"&&b++,b++;i.push({type:t.STRING,value:r.substring(c+1,b),quoted:!0,sourceQuote:d}),c=b+1;continue}let a=c,m;for(;a<r.length&&!/[{},]/.test(r[a]);)if(r[a]===":"){let d=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],b=!1;for(let A of d){let S=A.substring(1);if(r.substring(a+1,a+1+S.length)===S){b=!0,a+=S.length;break}}if(!b)break}else if(r[a]==="["){for(a++;a<r.length&&r[a]!=="]";){if(r[a]==='"'||r[a]==="'"){let d=r[a];for(a++;a<r.length&&r[a]!==d;)r[a]==="\\"&&a++,a++}a++}a<r.length&&r[a]==="]"&&a++}else a++;m=r.substring(c,a);let h=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(m)?h=t.NUMBER:m==="true"||m==="false"||m==="null"?h=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(m)&&(h=t.SELECTOR),i.push({type:h,value:m,quoted:!1}),c=a}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let s=r[c];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let a=r[c+1];if(a&&(a.type==="}"||a.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let a=s.value;s.sourceQuote==="'"&&(a=a.replace(/\\'/g,"'"),a=a.replace(/(\\*)"/g,(m,h)=>h.length%2===0?h+'\\"':m)),i+=`"${a}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new po("Invalid extraction rules syntax: "+r.message,r)}}var Xr="1",gi=/^[a-zA-Z0-9_-]+$/;function mo(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!gi.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${gi})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],c=e.attr(i,"data-rules-version");if(c!==Xr)throw new Gn(c);return{rules:Xn(e.text(i)),tagNode:i}}var ul="script[data-rules-name]";function bi(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function Lo(e,t){let n=e.find(t,ul,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let c=bi(e.attr(i,"data-rules-name"));if(!c)continue;if(o.has(c)){console.warn(`hyper-html-api: duplicate rules tag name "${c}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==Xr)throw new Gn(s);o.add(c),r.push({name:c,rules:Xn(e.text(i))})}return r}function rr(e,t){let n={};for(let{name:o,rules:r}of Lo(e,t))n[o]=Nn(e,t,r);return n}function Qr(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:rr(gn,t),version:Sn(n,"hyper-version")}}var go=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},Ro=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},Un=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Po=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var yi="text/hyper-upgrade";function Zr(e,t){let n=e.find(t,`script[type="${yi}"]`);if(n.length===0)return null;if(n.length>1)throw new Po(n.length);return e.text(n[0])||null}var dl=new Function("url","return import(url)");async function es(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await dl(n)}catch(r){throw new Un(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new Un("transform must `export default` a function");return o.default}function xi(e,t,n,o){let r=e.length,i=t.length,c=new Array(r).fill(-1);if(o){let f=new Set;for(let g=0;g<r;g++){let x=o[g];!(x>=0&&x<i)||f.has(x)||(c[g]=x,f.add(x))}}if(r===0||i===0)return c;let s=e.map(f=>ki(f,n)),a=t.map(f=>ki(f,n)),m=new Array(i).fill(!1);for(let f of c)f>=0&&(m[f]=!0);let h=new Map;a.forEach((f,g)=>{m[g]||h.set(f,h.has(f)?-1:g)});let d=new Map;s.forEach((f,g)=>{c[g]>=0||d.set(f,(d.get(f)||0)+1)}),s.forEach((f,g)=>{if(c[g]>=0||d.get(f)!==1)return;let x=h.get(f);x===void 0||x===-1||m[x]||(c[g]=x,m[x]=!0)});let b=[];for(let f=0;f<r;f++)c[f]<0&&b.push(f);let A=[];for(let f=0;f<i;f++)m[f]||A.push(f);if(b.length===0||A.length===0)return c;let S=r*i+1,L=(f,g)=>pl(e[f],t[g],n)*S+Math.abs(f-g);for(let[f,g]of hl(b,A,L))c[f]=g;return c}var Ti=e=>typeof e=="object"&&e!==null;function ki(e,t){if(!Ti(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function pl(e,t,n){if(!Ti(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let c=JSON.stringify(e?.[i]),s=JSON.stringify(t?.[i]);c!==s&&r++}return r}function hl(e,t,n){return e.length<=t.length?wi(e,t,n,!1):wi(t,e,(o,r)=>n(r,o),!0)}function wi(e,t,n,o){let r=e.length,i=t.length,c=[];for(let d=0;d<=r;d++)c.push(new Float64Array(i+1).fill(1/0));let s=[];for(let d=0;d<=r;d++)s.push(new Uint8Array(i+1));for(let d=0;d<=i;d++)c[r][d]=0;for(let d=r-1;d>=0;d--)for(let b=i-1;b>=0;b--){let A=n(e[d],t[b])+c[d+1][b+1],S=c[d][b+1];A<=S?(c[d][b]=A,s[d][b]=1):c[d][b]=S}let a=[],m=0,h=0;for(;m<r&&h<i;)s[m][h]&&(a.push(o?[t[h],e[m]]:[e[m],t[h]]),m++),h++;return a}function ns(e,t,n,o,r,i,c,s={}){let a=e.find(t,n,s);if(r.length===0){a.forEach(le=>e.remove(le)),ts(s,"onRowsApplied",i.path,[]);return}let m=r.length>a.length,h=a[0]||null;if(m&&!h&&(h=yl(e,t,n,s),!h))throw new Mo(i.path);let d=a.map(le=>bl(e,le,o,s)),b=null;if(m&&h){b=e.clone(h),s.templateAttr&&e.removeAttr(b,s.templateAttr);let le=e.stripIds(b);le>0&&console.warn(`[hyper-html-api] stripped ${le} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let A=xi(r,d,o,ml(e,a,r,i,s)),S=a[0]||h,L=e.parent(S),f=a.length>0?Ai(e,L,S):0,g=kl(e,a),x=new Set,Q=[],se=r.map((le,q)=>{let z=A[q];if(z>=0)return x.add(z),Q.push(!1),a[z];Q.push(!0);let ce=e.clone(b);return e.stripIds(ce),ce});a.forEach((le,q)=>{x.has(q)||e.remove(le)}),g?se.forEach((le,q)=>{let z=f+q;e.children(L).findIndex(te=>e.sameNode(te,le))!==z&&e.insertAt(L,le,z)}):wl(e,se,Q,L,f),gl(e,se,o,r,i,c,s),ts(s,"onRowsApplied",i.path,se)}function ts(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function ml(e,t,n,o,r){let i=ts(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let c=new Array(n.length).fill(-1),s=new Set;for(let a=0;a<n.length;a++)if(i[a]){for(let m=0;m<t.length;m++)if(!(s.has(m)||!e.sameNode(t[m],i[a]))){c[a]=m,s.add(m);break}}return c}function gl(e,t,n,o,r,i,c){t.forEach((s,a)=>{if(n===null){let m=o[a],h=m==null?"":String(m);e.text(s)!==h&&e.text(s,h)}else{let m=i(e,s,n,o[a],{depth:r.depth+1,path:[...r.path,a]},c);m&&m!==s&&(t[a]=m)}})}function bl(e,t,n,o){return n===null?e.text(t):Nn(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Ai(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function yl(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of i)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}function kl(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let c=o.findIndex(s=>e.sameNode(s,i));if(c===-1)return!1;r.push(c)}return r.sort((i,c)=>i-c),r[r.length-1]-r[0]===r.length-1}function wl(e,t,n,o,r){let i=null,c=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let a=i?e.parent(i):o;if(!a)continue;let m=i?Ai(e,a,i)+1:c++;e.insertAt(a,t[s],m),i=t[s]}}var Si=new Set(["checked","selected","disabled","readOnly","paused"]);function _n(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(os(n,o,[],i),i.length)throw new vo(i);sr(e,t,n,o,{depth:0,path:[]},r)}function sr(e,t,n,o,r,i={}){if(r.depth>ho)throw new Yn(r.path);if(o===void 0)return t;if(typeof n=="string")return xl(e,t,n,o,r,i);if(Array.isArray(n)){let[c,s]=n;return ns(e,t,c,s,o,r,sr,i),t}if(typeof n=="object"&&n!==null){for(let[c,s]of Object.entries(n)){let a=sr(e,t,s,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);a&&a!==t&&(t=a)}return t}return t}function xl(e,t,n,o,r,i){if(n.endsWith("[]")){let a=n.slice(0,-2);return ns(e,t,a,null,o,r,sr,i),t}if(n.startsWith("@"))return Oi(e,t,n.slice(1),o);let c=Mn(n);if(c!==-1){let a=n.slice(0,c),m=n.slice(c+1),h=a?e.find(t,a,i):[t];return h.length===0||Oi(e,h[0],m,o),t}if(n===".")return Ni(e,t,o),t;let s=e.find(t,n,i);return s.length===0||Ni(e,s[0],o),t}function Ni(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Oi(e,t,n,o){if(Fr.has(n)){let i=e.prop(t,n);if(i===o||i!=null&&o!=null&&String(i)===String(o))return t;throw new Eo(n)}if(n==="outerHTML"){let i=o==null?"":String(o);return e.replaceWith(t,i)}if(ii.has(n)){let i=Tl(n,o);return e.prop(t,n)!==i&&e.prop(t,n,i),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function Tl(e,t){return t==null?Si.has(e)?!1:"":Si.has(e)?t==="false"?!1:!!t:t}function os(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:Do([...n,i]),expected:"scalar",got:jo(r)})}):o.push({path:Do(n),expected:"array",got:jo(t)});return}t!==null&&typeof t=="object"&&o.push({path:Do(n),expected:"scalar",got:jo(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Do(n),expected:"array",got:jo(t)});return}let r=e[1];t.forEach((i,c)=>os(r,i,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Do(n),expected:"object",got:jo(t)});return}for(let[r,i]of Object.entries(e))os(i,t[r],[...n,r],o)}}}function jo(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Do(e){return e.join(".")}function Ho(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=rs(t,e,n);return ss(t,e,n),{data:o,summary:n}}function rs(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>rs(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let c=rs(i,t?.[r],n);c!==void 0&&(o[r]=c)}return o}}function ss(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?ss(e[r],t[r],n):n.discarded+=Qn(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>ss(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=Qn(t))}}function Qn(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Qn(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Qn(n),0):1}function is(e,t,n){let o=Lo(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},c=new Set;for(let{name:s,rules:a}of o){if(c.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:m,summary:h}=Ho(n[s],a);_n(e,t,a,m),i[s]=h,r.carriedOver+=h.carriedOver,r.discarded+=h.discarded,r.listItems+=h.listItems}for(let s of Object.keys(n))c.has(s)||(r.discarded+=Qn(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function cs({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(g=>fetch(g)),!o)throw new Error("upgrade.run requires a document context");if(e=e||Sn(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let c=new URL(e,r?r.href:void 0);n=n!==void 0?n:Sn(o,"hyper-version"),t=t||rr(gn,o);let s;try{s=await i(c.href)}catch(g){throw new go(c.href,g)}if(!s.ok)throw new go(c.href,new Error(`HTTP ${s.status}`));let a=await s.text(),m=new DOMParser().parseFromString(a,"text/html"),h=Sn(m,"hyper-version"),d=t,b=!1,A=Zr(gn,m);if(A){let x=await(await es(A))(d,{fromVersion:n,toVersion:h});if(!x||typeof x!="object"||Array.isArray(x))throw new Un("transform must return a plain object map of { rulesName: data }");d=x,b=!0}let{totals:S,byName:L,rulesTagCount:f}=is(gn,m,d);if(f===0&&Object.keys(d).length>0)throw new Ro(c.href);return{html:Al(m),fromVersion:n,toVersion:h,summary:{transformApplied:b,totals:S,byName:L}}}function Al(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
6
|
+
`+e.documentElement.outerHTML}var Nl=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...fi],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function ls(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return mo(e,o,n)}return null}var Bo={extract:(e,t,n={})=>Nn(Jn(e,n),e,t,n),apply:(e,t,n,o={})=>_n(Jn(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>mo(gn,e,t),findRules:(e,t)=>ls(gn,e,t),bind:(e,t,n={})=>{let o=ls(gn,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>Nn(Jn(e,n),e,o.rules,n),set:r=>_n(Jn(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:Jr,parseRelaxed:Xn,ruleAttrIndex:Mn,splitRule:to,errors:or,DOM_PROPERTIES:tr},as=e=>!!e&&typeof e.nodeType=="number";function vi(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=gn.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return mo(gn,t).rules}function fs(e,t){let n=as(e)?e:document,o=as(e)?t:e;return o===void 0?Nn(Jn(n),n,vi(n)):Bo.bind(n,o).get()}function us(e,t,n){if(!as(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?_n(Jn(e),e,vi(e),t):Bo.bind(e,n).set(t),e}var Mi={buildForm:ar,bindFormEvents:fr,scaffold:eo,morphForm:Vr,path:$o},Ei={checkForUpdate:$r,run:cs,extractAll:Qr,shapeMatch:Ho};var vl={engine:Bo,cms:Mi,upgrade:Ei,extractData:fs,applyData:us},Ml=vl;return Pi(El);})();
|