@panphora/clayjs 1.5.0 → 1.5.2
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.
- package/dist/clay.standalone.js +2358 -2304
- package/package.json +1 -1
- package/src/core/etag.js +4 -1
- package/src/core/save-conflict-notice.js +1 -0
- package/src/core/save-core.js +4 -0
- package/src/core/save.js +35 -3
- package/src/core/snapshot.js +1 -1
- package/src/sync/live-sync.js +104 -91
- package/src/vendor/hyper-morph.vendor.js +4 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
var HyperMorph=(()=>{var no=Object.defineProperty;var ps=Object.getOwnPropertyDescriptor;var ms=Object.getOwnPropertyNames;var gs=Object.prototype.hasOwnProperty;var bs=(e,s)=>{for(var o in s)no(e,o,{get:s[o],enumerable:!0})},ks=(e,s,o,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of ms(s))!gs.call(e,r)&&r!==o&&no(e,r,{get:()=>s[r],enumerable:!(n=ps(s,r))||n.enumerable});return e};var ys=e=>ks(no({},"__esModule",{value:!0}),e);var wr={};bs(wr,{createIdentityStore:()=>vo,createParseCache:()=>zn,default:()=>yr,diff:()=>wn,findChangedRoots:()=>os,importMap:()=>qn,merge3:()=>as,merge3Text:()=>yn,mergeDocument:()=>vn,mergeJson:()=>yo,mergeScriptText:()=>Zn,morph:()=>eo,morphDocument:()=>fs,morphElement:()=>to,parseJsonRelaxed:()=>Xn,parseRulesRelaxed:()=>zo,spliceProtected:()=>ss,tieredIdentity:()=>so});function Kn(e,s){if(typeof e=="string"){let o=s&&s.defaultView,n=o&&o.DOMParser||globalThis.DOMParser;return new n().parseFromString(e,"text/html")}if(e&&e.nodeType===9)return e;throw new TypeError("expected an HTML string or a Document")}function zn(e){let s=new Map;return(o,n)=>{if(typeof n!="string")return Kn(n,e);let r=s.get(o);if(r&&r.text===n)return r.doc;let l=Kn(n,e);return s.set(o,{text:n,doc:l}),l}}function So(e,s){let o=s.doctype;if(!o)return!1;let n=e.doctype;if(n&&n.name===o.name&&n.publicId===o.publicId&&n.systemId===o.systemId)return!1;let r=e.implementation.createDocumentType(o.name,o.publicId,o.systemId);return n?e.replaceChild(r,n):e.insertBefore(r,e.documentElement),!0}function oo(e,s=[]){if(typeof e!="function")return()=>!1;let o=new WeakMap,n=new Set(s);return r=>{if(!r||r.nodeType!==1)return!1;let l=o.get(r);if(l!==void 0)return l;let c=[],f=r,d=!1;for(;f&&f.nodeType===1;){let M=o.get(f);if(M!==void 0){d=M;break}if(c.push(f),e(f,n.has(f))){d=!0;break}if(n.has(f))break;f=f.parentElement}for(let M of c)o.set(M,d);return d}}function vo(e){let s=new WeakMap,o=0,n=f=>s.get(f)||null,r=f=>{let d=s.get(f);return d||(d=`${e}:${++o}`,s.set(f,d)),d};return{idOf:n,ensure:r,adopt:(f,d)=>{f&&typeof d=="string"&&d&&s.set(f,d)},exportMap:(f,d)=>{let M={},N=[],y=[],T=(u,b)=>{let x=d(u);x&&(M[b]=r(x));let P=u.children;N.push(P.length),y.push(u.tagName.toLowerCase());for(let v=0;v<P.length;v++)T(P[v],b===""?String(v):`${b}.${v}`)};return T(f,""),M["~"]=N.join(","),M["^"]=y.join(","),M}}}function qn(e,s){let o=new WeakMap;if(!e||!s||typeof s!="object"||Array.isArray(s))return o;let n=s["~"],r=typeof n=="string"?n.split(",").map(Number):null,l=r&&typeof s["^"]=="string"?s["^"].split(","):null,c=y=>Number.isInteger(y)&&y>=0,f=0,d=!1,M=y=>{let T=y;for(;T>0;){let u=r[f++];if(f>r.length||!c(u))return!1;T+=u-1}return!0},N=(y,T)=>{if(d)return;if(r){let x=f++,P=r[x];if(x>=r.length||!c(P)){d=!0;return}let v=!l||l[x]===y.tagName.toLowerCase();if(!v||P!==y.children.length){let j=v&&s[T];typeof j=="string"&&j&&o.set(y,j),M(P)||(d=!0);return}}let u=s[T];typeof u=="string"&&u&&o.set(y,u);let b=y.children;for(let x=0;x<b.length;x++)N(b[x],T===""?String(x):`${T}.${x}`)};return N(e,""),o}function so(e){return s=>{for(let o of e){let n=o(s);if(typeof n=="string"&&n!=="")return n}return null}}var un=so([e=>e.getAttribute("data-id"),e=>e.getAttribute("id")]);function Gn(e,s,o,n=null){let r=new Map,l=new Set,c=f=>{if(o(f))return;let d=s(f);d&&(r.has(d)?l.add(d):r.set(d,f))};if(n){let f=d=>{for(let M of d.querySelectorAll(n))c(M);for(let M of d.querySelectorAll("template"))M.content&&f(M.content)};c(e),f(e.tagName==="TEMPLATE"&&e.content?e.content:e)}else{let f=d=>{c(d);let M=d.tagName==="TEMPLATE"&&d.content?d.content.children:d.children;for(let N=0;N<M.length;N++)f(M[N])};f(e)}for(let f of l)r.delete(f),f.startsWith("merge:")&&console.warn(`[hyper-morph] merge disabled for duplicate identity "${f.slice(f.indexOf(":",6)+1)}"`);return r}var ws=new Set(["href","src","name","type","role"]),Io=new Set(["SCRIPT","STYLE","TEXTAREA","TEMPLATE","IFRAME","OBJECT","CANVAS","VIDEO","AUDIO","svg","SVG"]);function gn(e,s=5381){let o=s;for(let n=0;n<e.length;n++)o=(o<<5)+o^e.charCodeAt(n);return o>>>0}function Mo(e){return e.replace(/\s+/g," ")}function Oo({ignored:e=()=>!1,ignoreAttribute:s=()=>!1}={}){let o=new WeakMap,n=new WeakMap;function r(T){let u=T.attributes,b=u.length;if(b===0)return{all:"",sig:T.tagName+"|"};let x=[],P="",v=[];for(let j=0;j<b;j++){let Y=u[j],le=Y.name;s(T,le)||x.push(le+"="+Y.value),le==="class"?P=Y.value.indexOf(" ")<0?Y.value:Y.value.split(/\s+/).filter(Boolean).sort().join(" "):ws.has(le)&&v.push(le+"="+Y.value)}return x.length>1&&x.sort(),v.length>1&&v.sort(),{all:x.join(""),sig:T.tagName+"|"+P+(v.length?"|"+v.join("|"):"")}}function l(T){return T.nodeType===1&&T.tagName==="TEMPLATE"&&T.content?T.content.childNodes:T.childNodes}function c(T){let u=o.get(T);if(u)return u;if(T.nodeType===3)u={hash:"T"+gn(T.nodeValue),hint:Mo(T.nodeValue).slice(0,64),sig:null,tok:null};else if(T.nodeType===8)u={hash:"C"+gn(T.nodeValue),hint:"",sig:null,tok:null};else if(T.nodeType===1){let b=r(T),x=gn(T.tagName+""+b.all),P="";for(let v of d(T))if(v.nodeType===1){let j=c(v);x=gn(j.hash,x),P.length<64&&(P+=" "+j.hint)}else x=gn(M(v),x),v.kind==="text"&&P.length<64&&(P+=v.value.slice(0,64));u={hash:"E"+x,hint:Mo(P).trim().slice(0,64),sig:b.sig,tok:null}}else u={hash:"N"+T.nodeType,hint:"",sig:null,tok:null};return o.set(T,u),u}function f(T){if(!T.tok){T.tok=new Set;for(let u of T.hint.toLowerCase().split(/[^\p{L}\p{N}]+/u))u&&T.tok.add(u)}return T.tok}function d(T){let u=n.get(T);if(u)return u;u=[];let b=null,x=()=>{b&&(b.value=b.nodes.map(P=>P.nodeValue).join(""),u.push(b),b=null)};for(let P of l(T)){if(P.nodeType===3){b||(b={kind:"text",nodes:[],value:"",parent:T,hash:void 0}),b.nodes.push(P);continue}x(),P.nodeType===8?u.push({kind:"comment",nodes:[P],value:P.nodeValue,parent:T,hash:void 0}):P.nodeType===1&&!e(P)&&u.push(P)}return x(),n.set(T,u),u}function M(T){return T.nodeType===1?c(T).hash:(T.hash===void 0&&(T.hash=(T.kind==="text"?"T":"C")+gn(T.value)),T.hash)}function N(T,u){let b=f(c(T)),x=f(c(u));if(b.size===0&&x.size===0)return{coef:1,share:1};if(b.size===0||x.size===0)return null;let P=0;for(let v of b)x.has(v)&&P++;return{coef:P/Math.min(b.size,x.size),share:P/Math.max(b.size,x.size)}}function y(T,u){let b=N(T,u);return!!b&&b.coef>=.5}return{meta:c,unitsOf:d,unitHash:M,similar:y,score:N,childrenOf:l}}var Lo=16,As=2e3,Ts=3,xs={align:0};function ro(e,s,o){let{meta:n,unitsOf:r,unitHash:l,similar:c,score:f}=o.analyzer,d=o.baseId||(()=>null),M=o.sideId||(()=>null),N=new Map,y=new Map,T=new Set,u=new Map,b=new Set,x=new Set,P=new Set,v=[],j=[],Y=[],le=[],Ne=As,ye=new Map,De=new Map,F=(i,k)=>{N.set(i,k),y.set(k,i)},H=i=>!!i&&i.nodeType===1,Q=(i,k)=>{let g=u.get(i);return!!g&&g.has(k)},ie=i=>Io.has(i.tagName),me=(i,k)=>{let g=d(i);if(!g)return!0;let _=M(k);return!_||g===_},Ie=globalThis.__hyperMorphProfile,ot=Ie?performance.now():0;Ie&&(n(e),n(s),Ie.meta=(Ie.meta||0)+(performance.now()-ot),ot=performance.now()),F(e,s);for(let[i,k]of o.baseIndex){let g=o.sideIndex.get(i);g&&g.tagName===k.tagName&&!N.has(k)&&!y.has(g)&&F(k,g)}le.push([e,s]);for(let[i,k]of N)H(i)&&i!==e&&le.push([i,k]);return at(),bt(),Ie&&(Ie.align=(Ie.align||0)+(performance.now()-ot)),{map:N,reverse:y,moved:b,identical:x,pairIdenticalChildren:E,weak:T,unpair:kt,rematch:bt,insertedByHash:Se};function bt(){ft(),at();for(let i=0;i<Y.length;){let k=Y.length;Ke(i,k),i=k,at(),ft(),at()}}function kt(i){let k=N.get(i);if(!k)return;u.has(i)||u.set(i,new Set),u.get(i).add(k);let g=(I,O)=>{N.delete(I),y.delete(O),b.delete(I),x.delete(I),T.delete(I),P.delete(I)},_=(I,O)=>{for(let U of r(I)){let S=N.get(U);!S||!(H(S)?O.contains(S):O.contains(S.nodes[0]))||(g(U,S),H(U)&&_(U,S))}};g(i,k),H(i)&&_(i,k),v.push(i),j.push(k)}function Se(){let i=new Map;for(let k of new Set(j)){if(y.has(k))continue;let g=n(k).hash;i.has(g)||i.set(g,[]),i.get(g).push(k)}return i}function at(){for(;le.length;){let[i,k]=le.shift();P.has(i)||x.has(i)||xt(i,k)}}function Ge(i,k){if(!ie(i))for(let g of r(i))H(g)&&(k.push(g),Ge(g,k))}function xt(i,k){P.add(i);let g=r(i),_=r(k);xs.align+=g.length+_.length,ye=new Map,De=new Map;for(let B=0;B<g.length;B++)ye.set(g[B],B);for(let B=0;B<_.length;B++)De.set(_[B],B);if(i.tagName==="HTML")for(let B of["HEAD","BODY"]){let J=g.find(we=>H(we)&&we.tagName===B),ee=_.find(we=>H(we)&&we.tagName===B);J&&ee&&!N.has(J)&&!y.has(ee)&&F(J,ee)}for(let B=0;B<g.length&&B<_.length;B++){let J=g[B],ee=_[B];N.has(J)||y.has(ee)||(H(J)?H(ee)&&J.tagName===ee.tagName&&J.isEqualNode(ee)&&w(J,ee):!H(ee)&&J.kind===ee.kind&&J.value===ee.value&&w(J,ee))}nt(g,_);let I=g.filter(B=>!N.has(B)),O=_.filter(B=>!y.has(B));I.length&&O.length&&(it(I,O),oe(I,O),Z(I,O,g,_),Je(g,_));let U=!1,S=!1;for(let B of g){if(!N.has(B)){H(B)&&(v.push(B),Ge(B,v),U=!0);continue}H(B)&&!x.has(B)&&le.push([B,N.get(B)])}for(let B of _)!y.has(B)&&H(B)&&(j.push(B),Ge(B,j),S=!0);U&&S&&Y.push([i,k])}function Ke(i,k){for(let g=i;g<k;g++){let[_,I]=Y[g],O=r(_),U=r(I),S=new Map,B=new Map,J=null;for(let ee of O)H(ee)&&(N.has(ee)?J=ee:(S.has(J)||S.set(J,[]),S.get(J).push(ee)));J=null;for(let ee of U)H(ee)&&(y.has(ee)?J=y.get(ee):(B.has(J)||B.set(J,[]),B.get(J).push(ee)));for(let[ee,we]of S){let et=B.get(ee);if(!(!et||we.length!==et.length)&&we.every((yt,ut)=>et[ut].tagName===yt.tagName&&me(yt,et[ut])&&!Q(yt,et[ut])))for(let yt=0;yt<we.length;yt++)ze(we[yt],et[yt])}}}function ze(i,k){F(i,k),T.add(i),le.push([i,k]),at()}function it(i,k){let g=bn(i,l),_=bn(k,l),I=new Map;for(let O of k){let U=l(O);_.get(U)===1&&I.set(U,O)}for(let O of i){if(N.has(O))continue;let U=l(O);if(g.get(U)!==1)continue;let S=I.get(U);S&&!y.has(S)&&w(O,S)}}function w(i,k){F(i,k),x.add(i),H(i)&&P.add(i)}function E(i){let k=N.get(i);if(!k||!H(i))return;let g=r(i),_=r(k);for(let I=0;I<g.length&&I<_.length;I++)N.has(g[I])||w(g[I],_[I])}function oe(i,k){let g=U=>H(U)&&!ie(U)?n(U).sig+""+n(U).hint:null,_=bn(i,g),I=bn(k,g),O=new Map;for(let U of k){let S=g(U);S!=null&&I.get(S)===1&&O.set(S,U)}for(let U of i){if(N.has(U))continue;let S=g(U);if(S==null||_.get(S)!==1)continue;let B=O.get(S);B&&!y.has(B)&&me(U,B)&&F(U,B)}}function Z(i,k,g,_){let I=new Map;for(let U of k){if(!H(U)||y.has(U)||ie(U))continue;let S=n(U).sig;I.has(S)||I.set(S,[]),I.get(S).push({el:U,index:De.get(U)})}let O=[];for(let U of i){if(N.has(U)||!H(U)||ie(U))continue;let S=I.get(n(U).sig);if(!S||!S.length)continue;let B=ye.get(U),J=S.filter(ee=>!y.has(ee.el)).map(ee=>({c:ee,d:Math.abs(ee.index-B)}));J.sort((ee,we)=>ee.d-we.d),J.length>Lo&&(J=J.slice(0,Lo));for(let{c:ee,d:we}of J){if(!me(U,ee.el))continue;let et=f(U,ee.el);et&&et.coef>=.5&&O.push({b:U,s:ee.el,coef:et.coef,share:et.share,d:we,bi:B})}}O.sort((U,S)=>S.coef-U.coef||S.share-U.share||U.d-S.d||U.bi-S.bi);for(let U of O)!N.has(U.b)&&!y.has(U.s)&&F(U.b,U.s)}function Me(i,k){return H(i)!==H(k)?!1:H(i)?i.tagName!==k.tagName||!me(i,k)?!1:ie(i)||n(i).hint===""||n(k).hint===""?!0:c(i,k):i.kind===k.kind}function st(i,k){let g=(I,O)=>{let U=O===null?-1:I===k?De.get(O):ye.get(O),S=I[U+1];return S&&!H(S)?S:null},_=null;for(let I of i){if(H(I)){_=I;continue}if(N.has(I))continue;let O=_===null?null:N.get(_);if(_!==null&&!O)continue;let U=g(k,O);U&&!y.has(U)&&U.kind===I.kind&&F(I,U)}}function Je(i,k){st(i,k);let g=Xe(i,k),_=(O,U)=>H(O)&&n(O).hint!==""&&n(U).hint===""&&!!U.querySelector("br")&&!g(O,U),I=0;for(let O of i){if(N.has(O)){let S=De.get(N.get(O));S!==void 0&&S>=I&&(I=S+1);continue}let U=0;for(let S=I;S<k.length&&U<Ts;S++){let B=k[S];if(!y.has(B)&&(U++,Me(O,B)&&!Q(O,B)&&!_(O,B))){F(O,B),H(O)&&(n(O).hint===""||n(B).hint==="")&&T.add(O),I=S+1;break}}}nt(i,k)}function Xe(i,k){let g=(_,I,O)=>{for(let U=I-1;U>=0;U--)if(H(_[U])&&O(_[U]))return _[U];return null};return(_,I)=>{let O=ye.get(_),U=De.get(I);if(O===U)return!0;let S=g(i,O,J=>N.has(J)),B=g(k,U,J=>y.has(J));return S?N.get(S)===B:!B}}function nt(i,k){let g=i.filter(S=>H(S)&&!N.has(S)),_=k.filter(S=>H(S)&&!y.has(S));if(!g.length||!_.length)return;let I=bn(g,S=>S.tagName),O=bn(_,S=>S.tagName),U=Xe(i,k);for(let S of g){let B=S.tagName;if(I.get(B)!==1||O.get(B)!==1)continue;let J=_.find(ee=>ee.tagName===B);J&&!y.has(J)&&U(S,J)&&me(S,J)&&!Q(S,J)&&(F(S,J),T.add(S))}}function ft(){let i=new Map;for(let S of T)if(H(S)&&H(N.get(S))){let B=n(S).hash;i.has(B)||i.set(B,[]),i.get(B).push(S)}if(i.size)for(let S of j){if(y.has(S)||!H(S))continue;let B=i.get(n(S).hash),J=B&&B.find(ee=>T.has(ee)&&!Q(ee,S)&&me(ee,S));J&&(kt(J),w(J,S),b.add(J))}let k=new Map,g=new Map,_=new Map;for(let S of T){let B=N.get(S);H(S)&&H(B)&&_.set(B,S)}let I=(S,B)=>{if(!y.has(S))return!0;let J=_.get(S);return J===y.get(S)&&J!==B&&!J.contains(B)},O=S=>{if(y.has(S)){let B=_.get(S);_.delete(S),kt(B)}};for(let S of[...j,..._.keys()]){if(y.has(S)&&!_.has(S))continue;let B=n(S).hash;if(k.has(B)||k.set(B,[]),k.get(B).push(S),ie(S))continue;let J=n(S).sig;g.has(J)||g.set(J,[]),g.get(J).push(S)}let U=new Set;for(let S of T){let B=N.get(S);!H(S)||!H(B)||ie(S)||n(S).hint===""||n(B).hint===""||c(S,B)||U.add(S)}for(let S of[...v,...U]){let B=N.get(S);if(B&&!(T.has(S)&&U.has(S)))continue;let J=ut=>{B&&kt(S),O(ut)},ee=k.get(n(S).hash);if(ee){let ut=ee.find(fe=>fe!==B&&I(fe,S)&&!Q(S,fe));if(ut){J(ut),w(S,ut),b.add(S);continue}}if(ie(S)||Ne<=0)continue;let we=g.get(n(S).sig);if(!we)continue;let et=null,yt=0;for(let ut of we)if(!(ut===B||!I(ut,S)||!me(S,ut)||Q(S,ut))&&(Ne--<=0||c(S,ut)&&(yt++,et=ut,yt>1)))break;yt===1&&(J(et),F(S,et),b.add(S),le.push([S,et]))}}}function bn(e,s){let o=new Map;for(let n of e){let r=s(n);r!=null&&o.set(r,(o.get(r)||0)+1)}return o}var Ns={diff:0},Co=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null,Ss=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u,vs=/[\p{L}\p{M}\p{N}_'’]+|\s+|[\s\S]/gu,Ms=/\P{M}\p{M}*/gu;function fo(e){if(e==="")return[];if(Co){let o=[];for(let n of Co.segment(e))o.push(n.segment);return o}let s=[];for(let o of e.match(vs))if(Ss.test(o))for(let n of o.match(Ms))s.push(n);else s.push(o);return s}var Is=/^[ ]+$/,Os=e=>Is.test(e)?" ".repeat(e.length):e,Rn=e=>typeof e.k=="string"&&/^\s+$/.test(e.k),rt="",Eo=e=>e.every(s=>Rn(s)||s.k===rt),Ls=/^[\x00-\x7f\u00A0]*$/,Cs=/[A-Za-z0-9_']+|[ \u00A0]+|\s|./g;function Es(e){return e===""?[]:e.match(Cs)}function dn(e,s=!1){return(s?Es(e):fo(e)).map(o=>({k:Os(o),raw:o,len:o.length}))}var $n=(...e)=>e.every(s=>Ls.test(s));function io(e,s,o){let n=e.length,r=s.length,l=Math.min(n+r,o),c=l+1,f=new Int32Array(2*l+3),d=[],M=n===0&&r===0;for(let u=0;u<=l&&!M;u++){d.push(f.slice(c-u,c+u+1));for(let b=-u;b<=u;b+=2){let x;b===-u||b!==u&&f[c+b-1]<f[c+b+1]?x=f[c+b+1]:x=f[c+b-1]+1;let P=x-b,v=x;for(;x<n&&P<r&&e[x].k===s[P].k;)x++,P++;if(Ns.diff+=1+x-v,f[c+b]=x,x>=n&&P>=r){M=!0;break}}}if(!M)return null;let N=[],y=n,T=r;for(let u=d.length-1;u>0;u--){let b=d[u],x=y-T,P=x+u,v=x===-u||x!==u&&b[P-1]<b[P+1]?x+1:x-1,j=b[v+u],Y=j-v;for(;y>j&&T>Y;)N.push([0,y-1,T-1]),y--,T--;y===j?(N.push([1,y,T-1]),T--):(N.push([-1,y-1,T]),y--)}for(;y>0&&T>0;)N.push([0,y-1,T-1]),y--,T--;return N.reverse(),N}function Rs(e,s,o){let n=y=>y.k===rt;if(!e.some(n)&&!s.some(n))return io(e,s,o);let r=[],l=[];for(let y=0;y<e.length;y++)n(e[y])||r.push(y);for(let y=0;y<s.length;y++)n(s[y])||l.push(y);let c=io(r.map(y=>e[y]),l.map(y=>s[y]),o);if(!c)return null;let f=[],d=0,M=0,N=(y,T)=>{for(;d<y&&M<T&&e[d].k===s[M].k;)f.push([0,d++,M++]);let u=io(e.slice(d,y),s.slice(M,T),o);if(!u)return!1;for(let[b,x,P]of u)f.push([b,x+d,P+M]);return d=y,M=T,!0};for(let[y,T,u]of c)if(y===0){if(!N(r[T],l[u]))return null;f.push([0,d,M]),d++,M++}return N(e.length,s.length)?f:null}function kn(e,s,o=4e3){let n=[],r=0;for(;r<e.length&&r<s.length&&e[r].k===s[r].k;)e[r].raw!==s[r].raw&&n.push({bi:r,tok:s[r]}),r++;let l=0;for(;l<e.length-r&&l<s.length-r&&e[e.length-1-l].k===s[s.length-1-l].k;)e[e.length-1-l].raw!==s[s.length-1-l].raw&&n.push({bi:e.length-1-l,tok:s[s.length-1-l]}),l++;let c=e.slice(r,e.length-l),f=s.slice(r,s.length-l),d=js(c,f)?null:Rs(c,f,o);if(!d){let v=c.length||f.length?[{bs:r,be:r+c.length,toks:f}]:[];return{hunks:v,cosmetic:n,coarse:!0,parts:v.map(j=>({...j,gap:[],group:0})),cosmeticEq:n}}let M=[],N=(v,j)=>{c[v].raw!==f[j].raw&&n.push({bi:r+v,tok:f[j]})},y=null,T=[],u=0,b=0,x=()=>{y&&M.push(y),y=null;for(let[v,j]of T)N(v,j);T=[],u++};for(let[v,j,Y]of d){if(v===0){y&&Rn(c[j])&&!c[j].k.includes(`
|
|
2
|
-
`)?T.push([j,Y]):(x(),N(j,Y)),b=j+1;continue}(!y||T.length)&&(y&&M.push(y),y={bs:r+b,be:r+b,toks:[],gap:T.map(([le,Ne])=>({bi:r+le,tok:f[Ne]})),group:u},T=[]),v===-1?(y.be=r+b+1,b=j+1):y.toks.push(f[Y])}x(),Hs(M,e);let P=lo(M);return{hunks:P.hunks,cosmetic:n.concat(P.cosmetic),parts:M,cosmeticEq:n}}function Hs(e,s){for(let o=0;o<e.length;o++){let n=e[o];if(n.gap.length)continue;let r=o+1<e.length?e[o+1].bs:1/0;if(n.toks.length){if(n.bs===n.be)for(;n.bs+1<r&&n.bs<s.length&&n.toks[0].k===rt&&s[n.bs].k===rt;)n.toks=[...n.toks.slice(1),n.toks[0]],n.bs++,n.be++}else for(;n.be+1<r&&n.be<s.length&&s[n.bs].k===rt&&s[n.be].k===rt;)n.bs++,n.be++}}function lo(e,s=()=>!1){let o=[],n=[],r=null,l=-1;for(let c of e){let f=s(c);if(r&&!r.alone&&!f&&c.group===l){r.be=c.be;for(let d of c.gap)r.toks.push(d.tok);for(let d of c.toks)r.toks.push(d);continue}r&&o.push({bs:r.bs,be:r.be,toks:r.toks});for(let d of c.gap)n.push(d);r={bs:c.bs,be:c.be,toks:c.toks.slice(),alone:f},l=c.group}return r&&o.push({bs:r.bs,be:r.be,toks:r.toks}),{hunks:o,cosmetic:n}}var Bs=(e,s)=>e.bs===s.bs&&e.be===s.be&&ho(e.toks,s.toks);function uo(e,s,o){let n=N=>y=>N.some(T=>Bs(y,T)),r=lo(e.parts,n(s.parts)),l=lo(s.parts,n(e.parts)),c=e.cosmeticEq.concat(r.cosmetic),f=s.cosmeticEq.concat(l.cosmetic),[d,M]=o?Ds(r.hunks,l.hunks,o,c,f):[r.hunks,l.hunks];return{lh:d,rh:M,cosL:c,cosR:f}}function Ds(e,s,o,n,r){let l=(u,b)=>u.k===b.k&&u.raw===b.raw,c=[{list:e.map(u=>({...u})),resp:new Set(n.map(u=>u.bi))},{list:s.map(u=>({...u})),resp:new Set(r.map(u=>u.bi))}],f=u=>u.bs===u.be,d=(u,b,x,P)=>{let v=u.list[b];if(!f(v))return P(v)===x?v.toks:null;let j=b?u.list[b-1].be:0,Y=b+1<u.list.length?u.list[b+1].bs:o.length;if(x<j||x>Y)return null;let le=v.toks,Ne=v.bs;for(;Ne>x;){let ye=le[le.length-1];if(!l(ye,o[Ne-1])||u.resp.has(Ne-1))return null;le=[ye,...le.slice(0,-1)],Ne--}for(;Ne<x;){if(!l(le[0],o[Ne])||u.resp.has(Ne))return null;le=[...le.slice(1),le[0]],Ne++}return le},M=(u,b,x,P,v,j)=>{let Y=u.list[b],le=v?x.slice(x.length-P):x.slice(0,P),Ne=v?x.slice(0,x.length-P):x.slice(P),ye={bs:j,be:j,toks:le};if(f(Y)){if(!Ne.length){u.list[b]=ye;return}let F={bs:j,be:j,toks:Ne};v&&(F.lead=!0),u.list.splice(b,1,...v?[F,ye]:[ye,F]);return}let De={bs:Y.bs,be:Y.be,toks:Ne};u.list.splice(b,1,...v?[De,ye]:[ye,De])},N=(u,b,x,P,v)=>{let j=u.list[b],Y=v?x.slice(x.length-P):x.slice(0,P),le=v?x.slice(0,x.length-P):x.slice(P),Ne={bs:j.bs,be:j.be,toks:Y};if(!le.length){u.list[b]=Ne;return}let ye=v?{bs:j.bs,be:j.bs,toks:le,lead:!0}:{bs:j.be,be:j.be,toks:le};u.list.splice(b,1,...v?[ye,Ne]:[Ne,ye])},y=c[0],T=c[1];for(let u=0;u<64;u++){let b=!1;e:for(let x=0;x<y.list.length;x++)for(let P=0;P<T.list.length;P++){let v=y.list[x],j=T.list[P];if(!(v.bs===j.bs&&v.be===j.be&&ho(v.toks,j.toks)))for(let Y of[!0,!1]){let le=ye=>Y?ye.be:ye.bs,Ne=f(v)?[le(j),v.bs]:[le(v)];for(let ye of Ne){let De=d(y,x,ye,le),F=De&&d(T,P,ye,le);if(!F)continue;let H=(ot,bt)=>Y?ot[ot.length-1-bt]:ot[bt],Q=0;for(;Q<De.length&&Q<F.length&&H(De,Q).k===H(F,Q).k;)Q++;if(!Q)continue;let ie=Y?De.slice(0,De.length-Q):De.slice(Q),me=Y?F.slice(0,F.length-Q):F.slice(Q);if(!(Q<De.length&&Q<F.length&&!Eo(ie)&&!Eo(me)&&(f(v)&&f(j)||v.bs===j.bs&&v.be===j.be)||!(Y?De.slice(De.length-Q):De.slice(0,Q)).some(ot=>!Rn(ot)))){if(Q===De.length&&Q===F.length&&f(v)&&f(j)){if(v.bs===ye&&j.bs===ye)continue;y.list[x]={bs:ye,be:ye,toks:De},T.list[P]={bs:ye,be:ye,toks:F}}else!f(v)&&v.bs===j.bs&&v.be===j.be?(N(y,x,De,Q,Y),N(T,P,F,Q,Y)):(M(y,x,De,Q,Y,ye),M(T,P,F,Q,Y,ye));b=!0;break e}}}}if(!b)break}return[y.list,T.list]}var Ps=48,Us=.3;function js(e,s){let o=e.filter(c=>!Rn(c)),n=s.filter(c=>!Rn(c));if(Math.min(o.length,n.length)<Ps)return!1;let r=new Map;for(let c of o)r.set(c.k,(r.get(c.k)||0)+1);let l=0;for(let c of n){let f=r.get(c.k);f>0&&(l++,r.set(c.k,f-1))}return l/Math.min(o.length,n.length)<Us}var _s=(e,s)=>{let o=new Set;for(let n of e.toks)typeof n.k!="string"&&o.add(n.k.el);for(let n=e.bs;n<e.be;n++)typeof s[n].k!="string"&&o.add(s[n].k.el);return o},ho=(e,s)=>e.length===s.length&&e.every((o,n)=>o.k===s[n].k);function Ro(e,s,o,n="remote"){let r=kn(e,s),l=kn(e,o),{lh:c,rh:f,cosL:d,cosR:M}=uo(r,l,e),N=w=>w.bs===w.be,y=w=>w.toks.some(E=>typeof E.k=="string"),T=w=>N(w)&&!y(w),u=(w,E)=>E.bs<w.be&&w.bs<E.be,b=(w,E)=>!u(w,E)&&E.bs<=w.be&&w.bs<=E.be&&(N(w)&&y(w)||N(E)&&y(E))&&!(N(w)&&N(E)),x=(w,E)=>w.bs===E.bs&&w.be===E.be&&ho(w.toks,E.toks),P=[],v=new Set;for(let w of c){let E=f.find(oe=>!v.has(oe)&&x(w,oe));E?(v.add(E),P.push({bs:w.bs,be:w.be,side:"both",l:w,r:E,toks:w.toks})):P.push({bs:w.bs,be:w.be,side:"L",l:w,toks:w.toks,lead:!!w.lead})}for(let w of f)v.has(w)||P.push({bs:w.bs,be:w.be,side:"R",r:w,toks:w.toks,lead:!!w.lead});P.sort((w,E)=>w.bs-E.bs||w.be-E.be||E.lead-w.lead);let j=0,Y=0;for(let w of P)w.side==="both"&&(j+=w.toks.length-(w.be-w.bs));let le=P.map((w,E)=>E),Ne=w=>le[w]===w?w:le[w]=Ne(le[w]),ye=(w,E)=>(w=Ne(w),E=Ne(E),w===E?!1:(le[w]=E,!0)),De=P.map(w=>_s({bs:w.bs,be:w.be,toks:w.toks},e)),F={L:new Map,R:new Map};P.forEach((w,E)=>{let oe=w.side==="both"?["L","R"]:[w.side];for(let Z of oe)for(let Me of De[E])F[Z].has(Me)||F[Z].set(Me,[]),F[Z].get(Me).push(E)});for(let w of[F.L,F.R])for(let E of w.values())for(let oe=1;oe<E.length;oe++)ye(E[0],E[oe]);for(let w=0;w<P.length;w++)for(let E=w+1;E<P.length;E++){let oe=P[w],Z=P[E];oe.side===Z.side&&oe.side!=="both"||oe.bs>Z.be||(u(oe,Z)||b(oe,Z)?ye(w,E):oe.bs===Z.bs&&N(oe)&&N(Z)&&Y++)}let H=(w,E)=>{let oe=w==="L"?c:f;for(let Z of oe)if(Z.toks.some(Me=>Me.kind==="close"&&Me.k.el===E.el))return Z.bs;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="close"&&e[Z].k.el===E.el)return Z;return-1};P.forEach((w,E)=>{if(!(!T(w)||w.side==="both"))for(let oe of w.toks){if(oe.kind!=="open")continue;let Z=H(w.side,oe.k);if(Z<=w.bs)continue;let Me=new Uint8Array(Z-w.bs),st=[];if(P.forEach((Je,Xe)=>{if(!(Je.side===w.side||N(Je))&&Je.bs<Z&&Je.be>w.bs){st.push(Xe);for(let nt=Math.max(Je.bs,w.bs);nt<Math.min(Je.be,Z);nt++)Me[nt-w.bs]=1}}),st.length&&Me.every(Je=>Je===1))for(let Je of st)ye(E,Je)}});let Q=!0;for(;Q;){Q=!1;let w=new Map;P.forEach((E,oe)=>{let Z=Ne(oe),Me=w.get(Z)||{bs:E.bs,be:E.be,L:!1,R:!1};Me.bs=Math.min(Me.bs,E.bs),Me.be=Math.max(Me.be,E.be),E.side!=="R"&&(Me.L=!0),E.side!=="L"&&(Me.R=!0),w.set(Z,Me)}),P.forEach((E,oe)=>{for(let[Z,Me]of w){if(Ne(oe)===Ne(Z)||!(Me.L&&Me.R))continue;let st=E.bs<Me.be&&E.be>Me.bs,Je=N(E)&&y(E)&&(E.bs===Me.be||E.bs===Me.bs);(st||Je)&&ye(oe,Z)&&(Q=!0)}})}let ie=new Map;P.forEach((w,E)=>{let oe=Ne(E);ie.has(oe)||ie.set(oe,[]),ie.get(oe).push(w)});let me=[];for(let w of ie.values()){let E=w.some(Z=>Z.side==="L"),oe=w.some(Z=>Z.side==="R");if(E&&oe){let Z=Math.min(...w.map(Xe=>Xe.bs)),Me=Math.max(...w.map(Xe=>Xe.be)),st=w.filter(Xe=>Xe.side!=="R").map(Xe=>Xe.l).sort((Xe,nt)=>Xe.bs-nt.bs),Je=w.filter(Xe=>Xe.side!=="L").map(Xe=>Xe.r).sort((Xe,nt)=>Xe.bs-nt.bs);me.push({bs:Z,be:Me,kind:"conflict",localHunks:st,remoteHunks:Je})}else for(let Z of w)me.push({bs:Z.bs,be:Z.be,kind:Z.side,u:Z})}let Ie=(w,E)=>{let oe=w==="L"?c:f;for(let Z of oe)if(Z.toks.some(Me=>Me.kind==="close"&&Me.k.el===E.el))return Z.bs+.5;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="close"&&e[Z].k.el===E.el)return Z;return 1/0},ot=(w,E)=>{let oe=w==="L"?c:f;for(let Z of oe)if(Z.toks.some(Me=>Me.kind==="open"&&Me.k.el===E.el))return Z.bs-.5;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="open"&&e[Z].k.el===E.el)return Z;return-1/0},bt=w=>w.kind==="R"?"R":"L",kt=w=>w.kind==="R"?1:0;me.sort((w,E)=>{if(w.bs!==E.bs)return w.bs-E.bs;let oe=w.bs===w.be,Z=E.bs===E.be;if(oe!==Z)return oe?-1:1;if(oe&&Z&&w.kind!=="conflict"&&E.kind!=="conflict"){let st=w.u.toks,Je=E.u.toks,Xe=ft=>ft.length&&ft.every(i=>i.kind==="open"),nt=ft=>ft.length&&ft.every(i=>i.kind==="close");if(Xe(st)&&Xe(Je)){let ft=Math.max(...st.map(k=>Ie(bt(w),k.k))),i=Math.max(...Je.map(k=>Ie(bt(E),k.k)));if(ft!==i)return i-ft}if(nt(st)&&nt(Je)){let ft=Math.min(...st.map(k=>ot(bt(w),k.k))),i=Math.min(...Je.map(k=>ot(bt(E),k.k)));return ft!==i?i-ft:kt(E)-kt(w)}}let Me=st=>st.u&&st.u.lead?1:0;return Me(E)-Me(w)||kt(w)-kt(E)||w.be-E.be});let Se=[],at=[],Ge=0,xt=w=>{w>Ge&&(Se.push({bs:Ge,be:w,toks:e.slice(Ge,w),source:"base"}),Ge=w)};for(let w of me){if(xt(w.bs),w.kind==="conflict"){let E=ao(e,w.localHunks,w.bs,w.be),oe=ao(e,w.remoteHunks,w.bs,w.be),Z=n==="local"?E:n==="both"?E.concat(oe):oe;at.push({bs:w.bs,be:w.be,base:e.slice(w.bs,w.be),local:E,remote:oe,resolved:Z}),Se.push({bs:w.bs,be:w.be,toks:Z,source:"conflict",localHunks:w.localHunks,localToks:E,keepsLocal:n!=="remote"})}else Se.push({bs:w.bs,be:w.be,toks:w.u.toks,source:w.kind==="R"?"remote":"local",localHunks:w.kind==="R"?[]:[w.u.l]});Ge=Math.max(Ge,w.be)}xt(e.length);let Ke=new Map(d.map(w=>[w.bi,w.tok])),ze=new Map(M.map(w=>[w.bi,w.tok])),it=[];for(let w of Se){w.source==="base"&&(w.toks=w.toks.map((E,oe)=>{let Z=w.bs+oe,Me=Ke.get(Z),st=ze.get(Z),Je=Me&&st?n==="remote"?st:Me:Me||st||E;return Je===E?E:{...Je,cosmetic:!0}}));for(let E of w.toks)it.push({...E,src:w.source})}return{tokens:it,segments:Se,conflicts:at,localHunks:c,remoteHunks:f,collapsedDelta:j,samePoint:Y,mapLocalOffset:Vs(e,c,Se)}}function ao(e,s,o,n){let r=[],l=o;for(let c of s)r=r.concat(e.slice(l,c.bs),c.toks),l=c.be;return r.concat(e.slice(l,n))}var co=e=>e.reduce((s,o)=>s+o.len,0);function Vs(e,s,o){let n=new Int32Array(e.length+1);for(let c=0;c<e.length;c++)n[c+1]=n[c]+e[c].len;let r=s.map(c=>({bs:n[c.bs],be:n[c.be],text:c.toks.map(f=>f.raw).join(""),ref:c})),l=o.map(c=>({bs:n[c.bs],be:n[c.be],len:co(c.toks),source:c.source,localHunks:c.localHunks||[],localLen:c.localToks?co(c.localToks):0,keepsLocal:c.keepsLocal,ref:c}));return c=>{let f=null,d=null,M=0,N=0,y=0;for(let u of r){let b=u.bs-y;if(c<=N+b){f=y+(c-N);break}if(N+=b,y=u.bs,c<=N+u.text.length){d=u,M=c-N,f=u.bs;break}N+=u.text.length,y=u.be}f===null&&(f=y+(c-N));let T=0;for(let u of l){if(!d&&f<=u.bs)return T;if(!(d?u.localHunks.includes(d.ref):f<u.be)){T+=u.len;continue}if(u.source==="base")return T+(f-u.bs);if(u.source==="remote")return T+u.len;if(u.source==="local")return T+Math.min(M,u.len);if(!u.keepsLocal||!d)return T+u.len;let x=u.localHunks.indexOf(d.ref),P=co(ao(e,u.localHunks.slice(0,x),u.ref.bs,d.ref.bs));return T+Math.min(P+M,u.localLen)}return T}}function yn(e,s,o,n="remote"){if(s===o||o===e)return{text:s,conflicts:[],mapLocalOffset:u=>Math.min(u,s.length),granularity:"word"};let r=$n(e,s,o),l=dn(e,r),c=dn(s,r),f=dn(o,r),d=l.length<=2e4&&c.length<=2e4&&f.length<=2e4?Ro(l,c,f,n):null,M="word",N=l;if(!d){let u=b=>b.split(/(?<=\n)/).map(x=>({k:x,raw:x,len:x.length}));N=u(e),d=Ro(N,u(s),u(o),n),M="line"}let y=u=>u.map(b=>b.raw).join(""),T=[0];for(let u of N)T.push(T[T.length-1]+u.len);return{text:y(d.tokens),conflicts:d.conflicts.map(u=>({bs:T[u.bs],be:T[u.be],base:y(u.base),local:y(u.local),remote:y(u.remote),resolved:y(u.resolved)})),mapLocalOffset:d.mapLocalOffset,granularity:M}}function wn(e,s,o=4e3){if(e===s)return[];let n=$n(e,s),r=dn(e,n),l=dn(s,n),c=kn(r,l,o),f=[0];for(let d of r)f.push(f[f.length-1]+d.len);return c.hunks.map(d=>({bs:f[d.bs],be:f[d.be],text:d.toks.map(M=>M.raw).join("")}))}var Tn="\uFFFC";var Ws={caret:0},nn=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(" ")),jo=new Set(["BR","WBR","IMG"]),Fs=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 hn(e,s={}){if(e.nodeType===3)return!0;if(e.nodeType!==1)return!1;if(s.ignored&&s.ignored(e)||jo.has(e.tagName))return!0;if(!nn.has(e.tagName))return!Fs.has(e.tagName);if(s.remoteWins&&s.remoteWins(e))return!1;let o=s.inlineCache&&s.inlineCache.get(e);if(o!==void 0)return o;let n=!0;for(let r of e.childNodes)if(!hn(r,s)){n=!1;break}return s.inlineCache&&s.inlineCache.set(e,n),n}function Ks(e){return!e.firstChild||e.textContent===""&&!e.querySelector("br,img,wbr")}function Hn(e,s={}){let o={text:"",marks:[],atoms:[],nodes:[],stackAt:[],pins:[],placeholder:null},n=(r,l)=>{for(let c of r){if(c.nodeType===3){let N=c.nodeValue;if(!N)continue;o.nodes.push({node:c,s:o.text.length,e:o.text.length+N.length}),o.text+=N;for(let y=0;y<N.length;y++)o.stackAt.push(l);continue}if(c.nodeType!==1)continue;if(s.ignored&&s.ignored(c)){o.pins.push({el:c,i:o.text.length});continue}if(s.skip&&s.skip.has(c))continue;let f=c.tagName;if(s.blocks&&s.blocks.has(c)){o.text.length&&o.text[o.text.length-1]!==rt&&(o.stackAt.push(l),o.text+=rt);let N={el:c,tag:f,from:o.text.length,to:-1,depth:l.length,block:!0};o.marks.push(N);let y=l.concat([N]);n(c.childNodes,y),o.stackAt.push(y),o.text+=rt,N.to=o.text.length;continue}let d=nn.has(f)&&Ks(c);if(jo.has(f)||!nn.has(f)||s.remoteWins&&s.remoteWins(c)||s.atomize&&s.atomize(c)||d){o.atoms.push({i:o.text.length,el:c,key:d?f+":empty":f,stack:l}),o.stackAt.push(l),o.text+=Tn;continue}let M={el:c,tag:f,from:o.text.length,to:-1,depth:l.length};o.marks.push(M),n(c.childNodes,l.concat([M])),M.to=o.text.length}};if(n(e,[]),o.atoms.length===1&&o.atoms[0].el.tagName==="BR"&&o.marks.length===0&&Yn(o).trim()===""){let r=o.atoms[0];o.placeholder=r.el,o.text=o.text.slice(0,r.i)+o.text.slice(r.i+1),o.stackAt.splice(r.i,1);for(let l of o.nodes)l.s>r.i&&(l.s--,l.e--);o.atoms=[]}return o.atomAt=new Map(o.atoms.map(r=>[r.i,r])),o}function zs(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")}function qs(e){let s="<"+e.tagName.toLowerCase();for(let o of e.attributes)s+=` ${o.name}="${o.value.replace(/"/g,""")}"`;return s+">"}function mo(e,s,o){let n="",r=[];for(let l=s;l<o;l++){let c=e.stackAt[l],f=0;for(;f<r.length&&f<c.length&&r[f]===c[f];)f++;for(;r.length>f;)n+=`</${r.pop().tag.toLowerCase()}>`;for(;r.length<c.length;){let M=c[r.length];n+=qs(M.el),r.push(M)}let d=e.atomAt.get(l);n+=d?d.el.outerHTML:e.text[l]===rt?"":zs(e.text[l])}for(;r.length;)n+=`</${r.pop().tag.toLowerCase()}>`;return n}function Gs(e,s){let o=[...e.el.attributes].filter(n=>!s(e.el,n.name)).map(n=>n.name+"="+n.value).sort().join("");return e.tag+"|"+o}function _o(e,s){let o=[...e.attributes].filter(n=>!s(e,n.name)).map(n=>n.name+"="+n.value).sort().join("");return e.tagName+"|"+o+"|"+e.innerHTML}function Ho(e,s=()=>!1){let o=new Map,n=l=>{let c=o.get(l);return c===void 0&&(c="{"+l.map(f=>Gs(f,s)).sort().join(",")+"}",o.set(l,c)),c},r="";for(let l=0;l<e.text.length;l++){let c=e.atomAt.get(l);r+=(c?"["+_o(c.el,s)+"]":e.text[l])+n(e.stackAt[l])}return e.text.length===0&&e.placeholder&&(r+="[br]"),r}function An(e,s,o,n=r=>r.key){let r=[],l=e.text,c=0,f=d=>{if(d<=c)return;let M=l.slice(c,d);if(o)for(let N of M.split(/(?<=\n)/))r.push({k:N,raw:N,len:N.length});else for(let N of dn(M,s))r.push(N)};for(let d of e.atoms)f(d.i),r.push({k:"\0"+n(d),raw:Tn,len:1,atom:!0}),c=d.i+1;return f(l.length),r}function Yn(e){if(!e.atoms.length)return e.text;let s="",o=0;for(let n of e.atoms)s+=e.text.slice(o,n.i),o=n.i+1;return s+e.text.slice(o)}var go=e=>{let s=new Int32Array(e.length+1);for(let o=0;o<e.length;o++)s[o+1]=s[o]+e[o].len;return s};function Bo(e,s,o,n){let r=go(s),l=go(o),c=[],f=0,d=0;for(let N of n.hunks){d+=N.bs-f;let y=d+N.toks.length;c.push({bs:r[N.bs],be:r[N.be],ss:l[d],se:l[y],text:e.text.slice(l[d],l[y]),toks:N.toks,lead:!!N.lead}),d=y,f=N.be}let M=new Map;for(let N of n.cosmetic)M.set(N.bi,N.tok.raw);return{hunks:c,respell:M}}function Do(e,s,o){let n=c=>c===rt||/\s/.test(c),r=c=>c.replace(/[\u001E\s]/g,""),l=[];for(let c of e){let f=s.slice(c.bs,c.be),d=o.slice(c.ss,c.se);if(!f.includes(rt)&&!d.includes(rt)||f.includes(Tn)||d.includes(Tn)||r(f)!==r(d)){l.push(c);continue}let M=0,N=0;for(;;){let y=M,T=N;for(;y<f.length&&n(f[y]);)y++;for(;T<d.length&&n(d[T]);)T++;let u=M,b=N;for(;u<y&&b<T&&f[u]===d[b];)u++,b++;let x=y,P=T;for(;x>u&&P>b&&f[x-1]===d[P-1];)x--,P--;if(x>u||P>b){let v=d.slice(b,P);l.push({bs:c.bs+u,be:c.bs+x,ss:c.ss+b,se:c.ss+P,text:v,toks:[...v].map(j=>({k:j,raw:j,len:1})),lead:c.lead})}if(y>=f.length)break;M=y+1,N=T+1}}return l}function Po(e,s,o){let n=new Int32Array(s+1).fill(-1),r=new Int32Array(o+1).fill(-1),l=0,c=0,f=d=>{for(;l<d;)n[l]=c,r[c]=l,l++,c++};for(let d of e)f(d.bs),l=d.be,c=d.se;return f(s),n[s]=c,r[c]=s,{bTo:n,toB:r}}function Uo(e,s){if(e.size!==s.size)return!1;for(let o of e)if(!s.has(o))return!1;return!0}function bo(e){let{out:s,policy:o="remote",L:n,R:r}=e,l=e.provenance||new WeakMap,c=e.textMappers||new WeakMap,f=e.conflicts||[],d=e.decisions||[],M=f.length,N=!!(n&&n.reverse&&n.map&&r&&r.reverse&&r.map),y={base:null,local:null,remote:null};if(N&&e.moveIn){let t=X=>ke=>X.some($=>$===ke||$.nodeType===1&&$.contains(ke)),a=t(e.local),p=t(e.remote),h=t(e.base),A=new Set,C=X=>{if(!nn.has(X.tagName))return;let ke=n.map.get(X),$=r.map.get(X);(ke&&!a(ke)||$&&!p($))&&A.add(X);for(let re of X.children)C(re)};for(let X of e.base)X.nodeType===1&&C(X);let z=X=>ke=>{if(!nn.has(ke.tagName))return!1;let $=X.reverse.get(ke);return!!$&&(A.has($)||!h($))};A.size&&(y.base=X=>A.has(X)),y.local=z(n),y.remote=z(r)}let T={base:new Set,local:new Set,remote:new Set};if(N&&e.moveIn){let t=h=>A=>h.some(C=>C===A||C.nodeType===1&&C.contains(A)),a=t(e.local),p=t(e.remote);for(let h of Hn(e.base,{...e,atomize:y.base}).atoms){let A=n.map.get(h.el),C=r.map.get(h.el),z=!!A&&!a(A),X=!!C&&!p(C);!z&&!X||(T.base.add(h.el),A&&!z&&T.local.add(A),C&&!X&&T.remote.add(C),a(h.el)&&T.local.add(h.el),p(h.el)&&T.remote.add(h.el))}}let u=Hn(e.base,{...e,atomize:y.base,skip:T.base}),b=Hn(e.local,{...e,atomize:y.local,skip:T.local}),x=Hn(e.remote,{...e,atomize:y.remote,skip:T.remote}),P=new Map(u.atoms.map(t=>[t.el,t])),v=(t,a,p)=>{a.namespaceURI?t.setAttributeNS(a.namespaceURI,a.name,p):t.setAttribute(a.name,p)},j=(t,a,p,h)=>{if(!a&&(!p||!h)){for(let C of(p||h).attributes)v(t,C,C.value);return}let A=new Map;for(let C of[a,p,h])if(C)for(let z of C.attributes)A.set(z.name,z);for(let[C,z]of A){let X=a?a.getAttribute(C):null,ke=p?p.getAttribute(C):X,$=h?h.getAttribute(C):X,re;ke===$?re=ke:ke===X?(re=$,d.push({kind:"attr",el:t,name:C,source:"remote"})):$===X?(re=ke,d.push({kind:"attr",el:t,name:C,source:"local"})):(re=o==="local"?ke:$,f.push({kind:"attr",el:t,name:C,base:X,local:ke,remote:$,resolved:re}),d.push({kind:"attr",el:t,name:C,source:"both"})),re!=null&&v(t,z,re)}},Y=(t,a,p,h)=>t&&e.mergeAttrs?e.mergeAttrs(t,a,p,h):j(h,t,a,p),le=e.mergeElement||((t,a,p)=>{let h=s.createElement(t.tagName);Y(t,a,p,h);let A=a||t,C=p||t,z=o==="local"?A.isEqualNode(t)?C:A:C.isEqualNode(t)?A:C;for(let X of z.childNodes)h.appendChild(s.importNode(X,!0));return l.set(h,{base:t,local:a,remote:p}),h}),Ne=e.cloneUnit||((t,a)=>{let p=s.importNode(t,!0);return l.set(p,{base:null,local:a==="local"?t:null,remote:a==="remote"?t:null}),p}),ye=e.atomKey||(t=>_o(t,()=>!1)),De=(t,a)=>{let p=new Map;for(let h of t.atoms)if(e.remoteWins&&e.remoteWins(h.el)&&nn.has(h.el.tagName))p.set(h,"w"+h.el.tagName+"#"+(h.el.id||""));else if(!N)p.set(h,h.key);else if(t===u)p.set(h,"="+ye(h.el));else{let A=a.reverse.get(h.el),C=A?P.get(A):null;C?p.set(h,"="+ye(C.el)):A?p.set(h,"m"+ye(h.el)):p.set(h,"="+ye(h.el))}return h=>p.get(h)},F=De(u,null),H=De(b,n),Q=De(x,r),ie=$n(Yn(u),Yn(b),Yn(x)),me=An(u,ie,!1,F),Ie=An(b,ie,!1,H),ot=An(x,ie,!1,Q),bt=me.length>2e4||Ie.length>2e4||ot.length>2e4;bt&&(me=An(u,ie,!0,F),Ie=An(b,ie,!0,H),ot=An(x,ie,!0,Q));let kt=uo(kn(me,Ie),kn(me,ot),me),Se=Bo(b,me,Ie,{hunks:kt.lh,cosmetic:kt.cosL}),at=Bo(x,me,ot,{hunks:kt.rh,cosmetic:kt.cosR});Se.hunks=Do(Se.hunks,u.text,b.text),at.hunks=Do(at.hunks,u.text,x.text);let Ge=Po(Se.hunks,u.text.length,b.text.length),xt=Po(at.hunks,u.text.length,x.text.length),Ke=u.text.length,ze=t=>new Map(t.atoms.map(a=>[a.el,a])),it=ze(b),w=ze(x),E=(t,a,p)=>{let h=new Set;if(!N)return h;for(let A of t.atoms){let C=P.get(a.reverse.get(A.el));C&&p.bTo[C.i]<0&&h.add(C)}return h},oe=E(b,n,Ge),Z=E(x,r,xt),Me=t=>!hn(t,{...e,remoteWins:null}),st=new Set;if(N)for(let t of u.atoms){if(!Me(t.el))continue;let a=n.map.get(t.el)||null,p=r.map.get(t.el)||null,h=a&&!p?a:p&&!a?p:null;h&&(it.has(h)||w.has(h))&&!h.isEqualNode(t.el)&&st.add(t)}let Je=1,Xe=(t,a)=>({id:Je++,tag:t,base:null,local:null,remote:null,rank:a}),nt=new Map,ft=[];for(let t of u.marks){let a=Xe(t.tag,t.depth);a.block=!!t.block,a.base=t.el,a.baseMark=t,nt.set(t.el,a),ft.push(a)}let i=(t,a)=>{let p=-1,h=-1;for(let A=t.from;A<t.to;A++){let C=a[A];C>=0&&(p<0&&(p=C),h=C+1)}return p<0?null:[p,h]},k=(t,a,p,h)=>{for(let A of t.marks){let C=p?p.reverse.get(A.el):null;C&&p.identical.has(C)&&p.pairIdenticalChildren&&p.pairIdenticalChildren(C);let z=C?nt.get(C):null;if(z&&z[a]&&(z=null),!z){let X=i(A,h),ke=0;if(X)for(let $ of ft){if($.tag!==A.tag||$[a]||!!$.block!=!!A.block)continue;let re=Math.min(X[1],$.baseMark.to)-Math.max(X[0],$.baseMark.from);(re>ke||re===ke&&re>0&&Math.abs($.rank-A.depth)<Math.abs(z.rank-A.depth))&&(z=$,ke=re)}}z||(z=Xe(A.tag,A.depth),z.block=!!A.block,z.new=a),z[a]=A.el,z[a+"Mark"]=A,nt.set(A.el,z)}};k(b,"local",n,Ge.toB),k(x,"remote",r,xt.toB);let g=t=>t.merged||t,_=t=>{let a=new Set;for(let p of t)p.block||a.add(nt.get(p.el));return a},I=new Map,O=t=>{let a=I.get(t);return a||(a=_(t),I.set(t,a)),a},U=(t,a)=>{let p=[],h=null;for(let A=0;A<Ke;A++){let C=a[A];if(C<0){h&&p.push(h),h=null;continue}let z=O(u.stackAt[A]),X=O(t.stackAt[C]),ke=new Set,$=new Set;for(let re of X)z.has(re)||ke.add(re);for(let re of z)X.has(re)||$.add(re);if(!ke.size&&!$.size){h&&p.push(h),h=null;continue}if(h&&Uo(h.added,ke)&&Uo(h.removed,$)){h.be=A+1;continue}h&&p.push(h),h={bs:A,be:A+1,added:ke,removed:$}}return h&&p.push(h),p},S=U(b,Ge.bTo),B=U(x,xt.bTo),J=t=>t.be>t.bs?[t.bs,t.be-1]:[t.bs-1,t.bs],ee=(t,a)=>{if(Ke===0)return null;let[p,h]=J(t);for(let A of a){if(A.be<=p)continue;if(A.bs>h)break;let C=A.bs<=p&&h<A.be;return C&&t.text===""&&A.bs===t.bs&&A.be===t.be?"straddle":C?A:t.be>t.bs?"straddle":null}return null},we=t=>t.bs===t.be,et=(t,a)=>{let p=!1;for(let h=t.bs;h<t.be;h++){let A=u.text[h];if(A===rt)p=!0;else if(!/\s/.test(A))return!1}for(let h=t.ss;h<t.se;h++){let A=a.text[h];if(A===rt)p=!0;else if(!/\s/.test(A))return!1}return p},yt=(t,a)=>t.bs<a.be&&a.bs<t.be,ut=(t,a)=>t.bs<=a.be&&a.bs<=t.be&&we(t)!==we(a),fe=(t,a)=>u.text.slice(t.bs,t.be).includes(rt)||a.text.slice(t.ss,t.se).includes(rt),Qe=t=>{if(we(t))return!1;let a=t.bs,p=t.be;for(;a>0&&/\s/.test(u.text[a-1]);)a--;for(;p<u.text.length&&/\s/.test(u.text[p]);)p++;return(a===0||u.text[a-1]===rt)&&(p===u.text.length||u.text[p]===rt)},Et=(t,a)=>!fe(t,a)&&!Qe(t),wt=(t,a)=>yt(t,a)||ut(t,a)&&!(et(t,b)&&Et(a,x))&&!(et(a,x)&&Et(t,b)),Bt=(t,a)=>{if(t.bs!==a.bs||t.be!==a.be||t.toks.length!==a.toks.length)return!1;let p=t.ss,h=a.ss;for(let A=0;A<t.toks.length;A++){let C=t.toks[A],z=a.toks[A];if(C.k!==z.k||C.atom&&!b.atomAt.get(p).el.isEqualNode(x.atomAt.get(h).el))return!1;p+=C.len,h+=z.len}return!0},jt=(t,a,p,h)=>{for(let A of u.atoms){if(A.i<t.bs||A.i>=t.be||h.has(A)||st.has(A))continue;let C=a.bTo[A.i],z=C>=0?p.atomAt.get(C):null;if(z&&!z.el.isEqualNode(A.el))return!0}return!1},Nt=[],St=Se.hunks,m=at.hunks,L=0,R=0,W=0,D=0,V=0,G=t=>{t>W&&(Nt.push({src:"base",from:W,to:t,dL:D,dR:V}),W=t)};for(;L<St.length||R<m.length;){let t=St[L],a=m[R],p=!!t&&(!a||t.bs<a.bs||t.bs===a.bs&&t.be<=a.be&&!a.lead);if(t&&a&&t.bs===a.bs&&we(t)&&we(a)){let It=et(t,b),fn=et(a,x);It!==fn&&(p=fn)}let h=p?t:a,A=p?a:t,C=!!A&&Bt(t,a),z=!!A&&(p?!!St[L+1]&&Bt(St[L+1],a):!!m[R+1]&&Bt(t,m[R+1])),X=!!A&&!C&&!z&&(Ke===0||wt(t,a)),ke=X,$=ee(h,p?B:S);if($==="straddle"&&(ke=!0),!ke&&h.be>h.bs&&(ke=jt(h,p?xt:Ge,p?x:b,p?oe:Z)),!ke&&C){G(h.bs),Nt.push({src:"both",lfrom:t.ss,rfrom:a.ss,len:h.text.length}),W=h.be,D+=h.text.length-(h.be-h.bs),V+=h.text.length-(h.be-h.bs),L++,R++;continue}if(!ke){G(h.bs),Nt.push({src:p?"local":"remote",from:h.ss,to:h.se,inherit:$&&$!=="straddle"?$:null}),W=h.be,p?(D+=h.text.length-(h.be-h.bs),L++):(V+=h.text.length-(h.be-h.bs),R++);continue}let re=h.bs,_e=h.be,Ce=L,je=R,mt=It=>It.bs<_e&&It.be>re||we(It)&&(It.bs===re||It.bs===_e);p?Ce++:je++,X&&(re=Math.min(re,A.bs),_e=Math.max(_e,A.be),p?je++:Ce++);let lt=!0;for(;lt;){for(lt=!1;Ce<St.length&&mt(St[Ce]);)re=Math.min(re,St[Ce].bs),_e=Math.max(_e,St[Ce].be),Ce++,lt=!0;for(;je<m.length&&mt(m[je]);)re=Math.min(re,m[je].bs),_e=Math.max(_e,m[je].be),je++,lt=!0}let Wt=re+D,Ht=re+V,Jt=_e-re,Zt=_e-re;for(let It=L;It<Ce;It++)Jt+=St[It].text.length-(St[It].be-St[It].bs);for(let It=R;It<je;It++)Zt+=m[It].text.length-(m[It].be-m[It].bs);let sn=Wt+Jt,rn=Ht+Zt;G(re);let Mt={kind:"text",node:e.node||null,base:mo(u,re,_e),local:mo(b,Wt,sn),remote:mo(x,Ht,rn),resolved:null,range:null,bs:re,be:_e,lss:Wt,lse:sn,rss:Ht,rse:rn};Mt.resolved=o==="local"?Mt.local:o==="remote"?Mt.remote:Mt.local+Mt.remote,o!=="remote"&&Nt.push({src:"local",from:Wt,to:sn,conflict:Mt}),o!=="local"&&Nt.push({src:"remote",from:Ht,to:rn,conflict:Mt}),f.push(Mt),W=_e,D+=Jt-(_e-re),V+=Zt-(_e-re),L=Ce,R=je}G(Ke);let se=u.text,pe=[];if(Se.respell.size||at.respell.size){let t=go(me),a=[];for(let p=0;p<me.length;p++){let h=me[p].raw,A=Se.respell.get(p)??h,C=at.respell.get(p)??h;(A!==h||C!==h)&&pe.push([t[p],A!==h&&C!==h?"both":A!==h?"local":"remote"]),a.push(A===C?A:A===h?C:C===h||o==="local"?A:C)}se=a.join("")}let ue="",ge=[],Pe=[],He=[],At=[];for(let t of Nt){let a=ue.length;if(t.src==="base"){for(let p=t.from;p<t.to;p++)ge.push(p),Pe.push(p+t.dL),He.push(p+t.dR),At.push(t);ue+=se.slice(t.from,t.to)}else if(t.src==="both"){for(let p=0;p<t.len;p++)ge.push(-1),Pe.push(t.lfrom+p),He.push(t.rfrom+p),At.push(t);ue+=b.text.slice(t.lfrom,t.lfrom+t.len)}else{let p=t.src==="local"?b:x;for(let h=t.from;h<t.to;h++)ge.push(-1),Pe.push(t.src==="local"?h:-1),He.push(t.src==="remote"?h:-1),At.push(t);ue+=p.text.slice(t.from,t.to)}t.ms=a,t.me=ue.length,t.conflict&&(t.conflict.range||(t.conflict.range=[a,a]),t.conflict.range[1]=ue.length)}let de=ue.length,$e=new Int32Array(Ke+1).fill(-1),xe=new Int32Array(b.text.length+1).fill(-1),Lt=new Int32Array(x.text.length+1).fill(-1);for(let t=0;t<de;t++)ge[t]>=0&&($e[ge[t]]=t),Pe[t]>=0&&(xe[Pe[t]]=t),He[t]>=0&&(Lt[He[t]]=t);let Tt=(t,a)=>{let p=-1,h=-1;for(let A=t.from;A<t.to;A++){let C=a[A];C>=0&&(p<0&&(p=C),h=C+1)}return p<0?null:[p,h]},Ot=[],ht=[];for(let t of new Set(nt.values()))t.new==="local"?Ot.push(t):t.new==="remote"&&ht.push(t);let On=(t,a)=>{t.remote=a.remote,t.remoteMark=a.remoteMark,t.new="both",a.merged=t,nt.set(a.remote,t)};if(Ot.length&&ht.length){let t=e.idOf;for(let a of Ot){let p=t?t.local(a.local):null;if(!p)continue;let h=ht.find(A=>!A.merged&&A.tag===a.tag&&!!A.block==!!a.block&&t.remote(A.remote)===p);h&&On(a,h)}for(let a of Ot){if(a.remote)continue;let p=Tt(a.localMark,xe);if(p)for(let h of ht){if(h.merged||h.tag!==a.tag||!!h.block!=!!a.block)continue;let A=Tt(h.remoteMark,Lt);if(A&&Math.min(p[1],A[1])-Math.max(p[0],A[0])>0){On(a,h);break}}}}I.clear();let Ln=t=>{for(let a of t)if(a.block)return g(nt.get(a.el));return null},tn=u.marks.some(t=>t.block)||b.marks.some(t=>t.block)||x.marks.some(t=>t.block),Gt=new Array(de).fill(null),pn=new Set;if(tn){let t=($,re,_e)=>{let Ce=new Set([$,re,_e]);Ce.delete(null);let je=[];for(let lt of Ce){let Wt=lt===$,Ht=lt===re,Jt=lt===_e;(Ht===Jt?Ht:Ht===Wt?Jt:Ht)&&je.push(lt)}if(je.length<=1)return je[0]||null;let mt=o==="local"?re:_e;return je.includes(mt)?mt:je[0]},a=($,re)=>re>=0?Ln($.stackAt[re]):null,p=new Map;for(let $=0;$<de;$++){if(ue[$]!==rt)continue;let re=ge[$]>=0?a(u,ge[$]):null,_e=a(b,Pe[$]),Ce=a(x,He[$]);p.set($,[re,ge[$]>=0?t(re,_e,Ce):_e||Ce])}let h=new Set([...p.values()].map($=>$[1])),A=$=>$!==rt&&$!==Tn&&!/\s/.test($),C=($,re)=>{let _e=$;for(;_e<re&&!A(ue[_e]);)_e++;return _e<re&&ge[_e]>=0?a(u,ge[_e]):null},z=new Map,X=0;for(let $=0;$<de;$++){if(ue[$]!==rt)continue;let[re,_e]=p.get($),Ce=C(X,$),je=_e,mt=z.get(je)===je&&Ce===je;je&&z.has(je)&&!mt&&re&&!z.has(re)&&!h.has(re)&&(je=re),je&&!z.has(je)&&z.set(je,Ce);for(let lt=X;lt<=$;lt++)Gt[lt]=je;X=$+1}let ke=$=>{for(let re=0;re<$.text.length;re++)if(A($.text[re])&&!a($,re))return!0;return!1};if(!ke(u)&&!ke(b)&&!ke(x)){let $=[],re=0;for(let Ce=0;Ce<de;Ce++)(ue[Ce]===rt||Ce===de-1)&&($.push([re,Ce]),re=Ce+1);let _e=new Set(Gt);for(let Ce=0;Ce<$.length;Ce++){let[je,mt]=$[Ce];if(Gt[mt])continue;let lt=je;for(;lt<=mt&&!A(ue[lt]);)lt++;if(lt>mt)continue;let Wt=a(u,ge[lt]),Ht=a(b,Pe[lt]),Jt=a(x,He[lt]),Zt=t(Wt,Ht,Jt)||Ht||Jt||Wt;if(Zt&&!_e.has(Zt)){_e.add(Zt);for(let Mt=je;Mt<=mt;Mt++)Gt[Mt]=Zt;continue}let sn=Ce>0&&Gt[$[Ce-1][1]],rn=Ce+1<$.length&&Gt[$[Ce+1][1]];if(sn)pn.add($[Ce-1][1]);else if(rn&&ue[mt]===rt)pn.add(mt);else continue;for(let Mt=je;Mt<=mt;Mt++)Gt[Mt]=sn||rn}}}let jn=new Map,_n=t=>{let a=jn.get(t);if(a)return a;a=[1/0,-1/0];for(let[p,h]of[[t.baseMark,$e],[t.localMark,xe],[t.remoteMark,Lt]]){let A=p&&Tt(p,h);A&&(a[0]=Math.min(a[0],A[0]),a[1]=Math.max(a[1],A[1]))}return jn.set(t,a),a},Vn=(t,a,p)=>{let h=-1,A=-1;for(let C=0;C<t.length;C++){let z=nt.get(t[C].el);z===a&&(h=C),z===p&&(A=C)}return h>=0&&A>=0?h-A:0},mn=(t,a)=>[...t].sort((p,h)=>{for(let z of a){let X=Vn(z,p,h);if(X)return X}let A=_n(p),C=_n(h);return A[0]-C[0]||C[1]-A[1]||p.rank-h.rank||p.id-h.id}),Wn=new Map,K=new Map,Te=t=>{let a=ge[t],p=Pe[t],h=He[t],A=At[t];if(a>=0){let Ce=u.stackAt[a],je=b.stackAt[p],mt=x.stackAt[h],lt=Wn.get(Ce);lt||Wn.set(Ce,lt=new Map);let Wt=lt.get(je);Wt||lt.set(je,Wt=new Map);let Ht=Wt.get(mt);if(Ht)return Ht;let Jt=O(Ce),Zt=O(je),sn=O(mt),rn=new Set;for(let Mt of new Set([...Jt,...Zt,...sn])){let It=Jt.has(Mt),fn=Zt.has(Mt),No=sn.has(Mt);(fn===No?fn:fn===It?No:fn)&&rn.add(Mt)}return Ht=mn(rn,[je,mt,Ce]),Wt.set(mt,Ht),Ht}if(A.src==="both"){let Ce=b.stackAt[p],je=x.stackAt[h];return mn(new Set([...O(Ce),...O(je)]),[Ce,je])}let z=(A.src==="local"?b:x).stackAt[A.src==="local"?p:h];if(!A.inherit)return mn(O(z),[z]);let X=K.get(A);X||K.set(A,X=new Map);let ke=X.get(z);if(ke)return ke;let $=new Set(O(z));for(let Ce of A.inherit.added)$.add(g(Ce));for(let Ce of A.inherit.removed)$.delete(g(Ce));let re=A.src==="local"?x:b,_e=(A.src==="local"?xt.bTo:Ge.bTo)[A.inherit.bs];return ke=mn($,[z,re.stackAt[_e]]),X.set(z,ke),ke},he=new Int32Array(b.text.length+1);he[b.text.length]=de;for(let t=b.text.length-1;t>=0;t--)he[t]=xe[t]>=0?xe[t]:he[t+1];Ws.caret+=b.text.length;let Oe=t=>t<=0?0:(t>b.text.length&&(t=b.text.length),xe[t-1]>=0?xe[t-1]+1:he[t]),Ve=[],ne=[],Ae=null,te=[],Le="",Ue=-1,Ct=t=>{Ae?Ae.appendChild(t):Ve.push(t)},$t=t=>{if(!Le)return;let a=s.createTextNode(Le);Ct(a),ne.push({node:a,ms:Ue,me:t,local:[],u:te.length?te[te.length-1].u:null}),Le=""},on=new Set,Pt=new Map,cn=new Set,Be=t=>{let a=s.createElement(t.tag);if(t.block&&En.add(a),!Pt.has(t)){Pt.set(t,a),Y(t.base,t.local,t.remote,a),l.set(a,{base:t.base,local:t.local,remote:t.remote});let h=(z,X)=>N&&t[X]&&z.reverse.get(t[X])?X:null,A=!t.base&&(h(n,"local")||h(r,"remote"));if(A){let z=A==="local"?n.reverse.get(t.local):r.reverse.get(t.remote),X=l.get(a);X.local=X.local||n.map.get(z)||null,X.remote=X.remote||r.map.get(z)||null,d.push({kind:"move",el:a,source:A})}else t.base||d.push({kind:"insert",el:a,source:t.local&&t.remote?"both":t.local?"local":"remote"});let C=l.get(a);C.local&&(cn.has(C.local)?C.local=null:cn.add(C.local))}else{let h=Pt.get(t);for(let A of h.attributes)A.name!=="id"&&A.name!=="data-id"&&v(a,A,A.value);l.set(a,{base:null,local:null,remote:null})}Ct(a),te.push({u:t,el:a}),Ae=a},We=new Set,q=new Map;for(let t of b.pins){let a=Oe(t.i);q.has(a)||q.set(a,[]),q.get(a).push(t)}let ae=t=>{let a=q.get(t);if(a){$t(t);for(let p of a){let h=p.el.namespaceURI&&p.el.namespaceURI!=="http://www.w3.org/1999/xhtml"?s.createElementNS(p.el.namespaceURI,p.el.tagName):s.createElement(p.el.tagName);l.set(h,{base:null,local:p.el,remote:null,pinned:!0}),We.add(h),Ct(h)}}},be=u.atoms.length||b.atoms.length||x.atoms.length,Re=t=>{if(!be)return null;let a=ge[t]>=0?u.atomAt.get(ge[t]):null,p=Pe[t]>=0?b.atomAt.get(Pe[t]):null,h=He[t]>=0?x.atomAt.get(He[t]):null;return a||p||h?{ab:a,al:p,ar:h}:null},ve=(t,a,p,h)=>{if(!t||!N)return null;let A=P.get(a.reverse.get(t.el))||null;return!A||A===h||(h?A.el.isEqualNode(h.el):p.bTo[A.i]>=0)?null:A},qe=(t,a)=>{if(!t||!N||!e.moveIn)return null;let p=a.reverse.get(t.el);return p&&!P.has(p)?p:null},tt=(t,a)=>{let p=new Map;for(let h of t.atoms)p.set(a(h),(p.get(a(h))||0)+1);return p},Rt=tt(u,F),Ut=tt(b,H),Ft=tt(x,Q),vt=t=>{let a=F(t);return Rt.get(a)===1&&(Ut.get(a)||0)<=1&&(Ft.get(a)||0)<=1},Kt=new Map,dt=new Set,pt=new Set,zt=new Set;for(let t=0;t<de;t++){let a=Re(t);if(!a)continue;let{ab:p,al:h,ar:A}=a,C=ve(A,r,xt,p),z=ve(h,n,Ge,p),X=p,ke=null;if(C?(X=C,ke="remote"):z&&(X=z,ke="local"),X){dt.has(X)?Kt.set(t,{dup:X.el}):(dt.add(X),Kt.set(t,{bk:X,from:ke,al:h,ar:A}));continue}let $=qe(A,r),re=qe(h,n),_e=$||re;if(_e){pt.has(_e)?Kt.set(t,{dup:_e}):(pt.add(_e),Kt.set(t,{moveIn:_e,side:$?"remote":"local",sideEl:$?A.el:h.el}));continue}let Ce=(mt,lt)=>mt&&N&&P.get(lt.reverse.get(mt.el))||null,je=Ce(A,r)||Ce(h,n);if(je&&(zt.add(je),At[t].conflict&&vt(je))){if(dt.has(je)){Kt.set(t,{dup:je.el});continue}dt.add(je)}Kt.set(t,{al:h,ar:A})}let Xt=new Map,Fn=(t,a)=>{if(t[a]>=0)return t[a];for(let p=a-1;p>=0;p--)if(t[p]>=0)return t[p]+1;return 0};if(N)for(let t of u.atoms){if(dt.has(t)||zt.has(t))continue;let a=n.map.get(t.el)||null,p=r.map.get(t.el)||null,h=a&&it.get(a),A=p&&w.get(p);if(a&&!h||p&&!A)continue;let C=!(h&&A)&&st.has(t);if(!C&&!(h&&A&&vt(t)))continue;let z=o==="local"?[[h,xe],[A,Lt]]:[[A,Lt],[h,xe]],[X,ke]=z.find(([re])=>re),$=Fn(ke,X.i);Xt.has($)||Xt.set($,[]),Xt.get($).push({a:t,lt:a,rt:p,edited:C}),dt.add(t)}if(N&&e.moveIn){let t=[[b,n,xe,"local"],[x,r,Lt,"remote"]];o!=="local"&&t.reverse();for(let[a,p,h,A]of t)for(let C of a.atoms){let z=qe(C,p);if(!z||pt.has(z))continue;pt.add(z);let X=Fn(h,C.i);Xt.has(X)||Xt.set(X,[]),Xt.get(X).push({move:z,side:A,sideEl:C.el})}}let Cn=t=>{let a=Xt.get(t);if(a){if($t(t),a.some(p=>Me(p.move?p.sideEl:p.a.el)))for(;te.length;)te.pop(),Ae=te.length?te[te.length-1].el:null;for(let{a:p,lt:h,rt:A,edited:C,move:z,side:X,sideEl:ke}of a){if(z){let re=e.moveIn(z,X,ke);re&&Ct(re);continue}on.add(p);let $=le(p.el,h,A);C&&(f.push({kind:"structure",el:$,detail:"edit-beats-delete",base:p.el}),d.push({kind:"insert",el:$,source:h?"local":"remote"})),Ct($)}}},En=new Set;for(let t=0;t<de;t++){let a=Re(t),h=!!a&&Me((a.ab||a.al||a.ar).el)?[]:Gt[t]?[Gt[t],...Te(t)]:Te(t),A=0;for(;A<te.length&&A<h.length&&te[A].u===h[A];)A++;if(A<te.length)for($t(t);te.length>A;)te.pop(),Ae=te.length?te[te.length-1].el:null;if(ae(t),Cn(t),h.length>te.length)for($t(t);te.length<h.length;)Be(h[te.length]);if(ue[t]===rt){if(pn.has(t))continue;$t(t);let C=te.length;for(;C>0&&!te[C-1].u.block;)C--;if(C>0)for(;te.length>=C;)te.pop(),Ae=te.length?te[te.length-1].el:null;continue}if(a){$t(t);let C=Kt.get(t),z;if(C.dup){f.push({kind:"structure",el:null,detail:"both-moved",base:C.dup});continue}if(C.moveIn){if(z=e.moveIn(C.moveIn,C.side,C.sideEl),!z)continue}else if(C.bk){let X=C.bk;if(on.add(X),X===a.ab)z=le(X.el,C.al.el,C.ar.el);else{let ke=n.map.get(X.el)||null,$=r.map.get(X.el)||null;z=le(X.el,ke,$),(!ke||!$)&&f.push({kind:"structure",el:null,detail:"move-beats-delete",base:X.el}),d.push({kind:"move",el:z,source:C.from})}}else C.al?(z=Ne(C.al.el,"local"),C.ar&&(l.get(z).remote=C.ar.el),d.push({kind:"insert",el:z,source:C.ar?"both":"local"})):(z=Ne(C.ar.el,"remote"),d.push({kind:"insert",el:z,source:"remote"}));Ct(z);continue}Le||(Ue=t),Le+=ue[t]}if($t(de),(q.has(de)||Xt.has(de))&&(te.length=0,Ae=null,ae(de),Cn(de)),de===0&&(b.placeholder||x.placeholder||u.placeholder)){let t=s.createElement("br");l.set(t,{base:u.placeholder,local:b.placeholder,remote:x.placeholder}),Ve.push(t)}let ce=0,Fe=t=>{for(;ce>0&&ne[ce-1].me>=t;)ce--;for(;ce<ne.length&&ne[ce].me<t;)ce++;let a=ne[ce];if(!a)return ne[ne.length-1]||null;let p=ne[ce+1];return a.me===t&&p&&p.ms===t?p:a},ct=new Map,Ze={},Ye=(t,a,p)=>{let h=Fe(t)||(p?Ze:null);if(!h)return;let A=ct.get(h)||{l:!1,r:!1};a!=="remote"&&(A.l=!0),a!=="local"&&(A.r=!0),ct.set(h,A)},Qt=t=>{if(t.conflict)return!0;let a=t.src==="local"?b.text:t.src==="remote"?x.text:"";for(let p=t.from;p<t.to;p++)if(a[p]!==Tn&&a[p]!==rt)return!0;return!1};for(let t of Nt)t.src!=="base"&&Ye(t.ms,t.conflict?"both":t.src,Qt(t));for(let[t,a]of pe)$e[t]>=0&&Ye($e[t],a);for(let t of ne.length?ne:[Ze]){let a=ct.get(t);a&&d.push({kind:"text",node:t.node||null,source:a.l&&a.r?"both":a.l?"local":"remote"})}for(let t of ft){if(Pt.has(t))continue;let a=!t.local&&!(N&&n.map.get(t.base)),p=!t.remote&&!(N&&r.map.get(t.base));!a&&!p||d.push({kind:"remove",source:a&&p?"both":a?"local":"remote",base:t.base})}let Yt=(t,a,p)=>{if(a<=t)return!1;for(let h=t;h<a;h++)if(p[h]>=0)return!1;return!0};for(let t of ft)for(let a of["local","remote"]){let p=t[a+"Mark"],h=t.baseMark;if(!p)continue;let A=a==="local"?Ge:xt;if(!Yt(h.from,h.to,A.bTo)||!Yt(p.from,p.to,A.toB))continue;let C=(a==="local"?St:m).find(z=>z.ss<=p.from&&p.from<z.se);C&&(C.be<=h.from||C.bs>=h.to)&&d.push({kind:"move",el:Pt.get(t)||null,source:a})}let ln=t=>{let a=nt.get(t.node.parentNode);return a?g(a):null};for(let t of b.nodes){let a=-1;for(let h=t.s;h<t.e;h++)if(xe[h]>=0){a=xe[h];break}let p;if(a>=0)p=Fe(a);else{let h=Oe(t.s),A=ln(t);p=ne.find(C=>C.u===A&&C.me>=h)||ne.filter(C=>C.u===A).pop()}p&&p.local.push(t)}let qt=new Map,Dt=ne[ne.length-1]||null,Vt=0;for(let t of b.nodes){let a=null;for(let p=t.s;p<=t.e;p++){let h=Oe(p);for(;Vt>0&&ne[Vt-1].me>=h;)Vt--;for(;Vt<ne.length&&ne[Vt].me<h;)Vt++;let A=z=>z&&h>=z.ms&&h<=z.me&&(h<z.me||p===t.e||z===a),C=A(ne[Vt])?ne[Vt]:A(ne[Vt+1])?ne[Vt+1]:ne[Vt]||Dt;if(!C)break;if(a===C){let z=qt.get(C);z[z.length-1].to=p-t.s;continue}a=C,qt.has(C)||qt.set(C,[]),qt.get(C).push({node:t.node,from:p-t.s,to:p-t.s,flatStart:t.s})}}for(let t of ne){let a=t.local,p=!1;for(let z of a)for(let X=z.s;X<z.e&&!p;X++)(xe[X]<t.ms||xe[X]>=t.me)&&(p=!0);l.set(t.node,{base:null,local:a.map(z=>z.node),remote:null,caret:qt.get(t)||[],partial:p});let h=t.ms,A=t.me-t.ms,C=z=>{let X=0,ke=-1;for(let $ of a){let re=$.e-$.s;if(z<=X+re){ke=$.s+(z-X);break}X+=re}return ke<0&&(ke=a.length?a[a.length-1].e:0),Math.max(0,Math.min(Oe(ke)-h,A))};C.flat=z=>Math.max(0,Math.min(Oe(z)-h,A)),c.set(t.node,C)}function us(){if(!b.text.includes(rt))return[{flatLocal:b.text,localNodes:b.nodes,textNodes:ne,lToM:xe,mapLocal:Oe}];let t=[],a=0,p=0;for(let h=0;h<=b.text.length;h++){if(h<b.text.length&&b.text[h]!==rt)continue;let A=a,C=h;if(C>A){let z=[];for(;p<b.nodes.length&&b.nodes[p].e<=A;)p++;for(let X=p;X<b.nodes.length&&b.nodes[X].s<C;X++){let ke=b.nodes[X],$=Math.max(ke.s,A),re=Math.min(ke.e,C);$<re&&z.push({node:ke.node,s:$-A,e:re-A})}t.push({flatLocal:b.text.slice(A,C),localNodes:z,textNodes:ne,lToM:xe.subarray?xe.subarray(A,C+1):xe.slice(A,C+1),mapLocal:X=>Oe(A+Math.max(0,Math.min(X,C-A)))})}a=h+1}return t}let ds={...e,blocks:En,ignored:t=>We.has(t)||(e.ignored?e.ignored(t):!1)},xo=e.ignoreAttribute||(()=>!1),hs=Ho(Hn(Ve,ds),xo)!==Ho(x,xo);return{nodes:Ve,text:ue,textNodes:ne,localDiverged:hs,mapLocal:Oe,conflicts:f.slice(M),granularity:bt?"line":"word",segments:us(),localHunks:St,remoteHunks:m,lToM:xe}}var $s="http://www.w3.org/1999/xhtml";function Ys(e){let s=5381;for(let o=0;o<e.length;o++)s=(s<<5)+s^e.charCodeAt(o);return(s>>>0).toString(36)}function _t(e){return!!e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.namespaceURI===$s}function Js(e){let s=(e.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return s==="application/json"||s.endsWith("+json")}function Jn(e,s){let o=e.getAttribute("src"),n=(e.getAttribute("type")||"text/javascript").split(";")[0].trim().toLowerCase();if(o){let r=o;try{let l=new URL(o,s);r=l.origin+l.pathname+l.search}catch{}return"script|src|"+n+"|"+r}return"script|inline|"+n+"|"+Ys(e.textContent.trim())}var Xs={match:e=>e.hasAttribute("merge"),identity:e=>e.getAttribute("merge")};function xn(e,s=[],o=!1){if(!_t(e)||e.hasAttribute("src"))return null;let n=[Xs,...s];for(let r=0;r<n.length;r++){let l=n[r];if(!l.match(e))continue;if(!Js(e))return o&&console.warn("[hyper-morph] merge ignored: script type is not JSON",e),null;let c=l.identity(e);return c==null||c===""?null:{key:r+":"+c,raw:c,recognizer:l}}return null}function Vo(e,s,o){let n=new Set,r=l=>{_t(l)&&!s(l)&&n.add(Jn(l,o))};r(e);for(let l of e.querySelectorAll("script"))r(l);return n}function Bn(e,s){let o=s.createElement("div");o.innerHTML="<script><\/script>";let n=o.firstChild;for(let r of e.attributes)n.setAttribute(r.name,r.value);return n.textContent=e.textContent,n}function Wo(e,s,o){let n=[],r=[],l=Array.from(e.querySelectorAll("script"));_t(e)&&l.unshift(e);for(let c of l){if(!_t(c)||o.ignored(c)||o.skip.has(c)||s.has(Jn(c,o.baseURI)))continue;let f=c.ownerDocument.createElement("script");for(let d of c.attributes)f.setAttribute(d.name,d.value);f.textContent=c.textContent,o.beforeNodeAdded(f)!==!1&&(f.hasAttribute("src")&&r.push(new Promise(d=>{f.addEventListener("load",()=>d()),f.addEventListener("error",()=>d())})),c.replaceWith(f),o.afterNodeAdded(f),n.push(f))}return{executed:n,loads:r}}function Qs(e){let s=5381;for(let o=0;o<e.length;o++)s=(s<<5)+s^e.charCodeAt(o);return(s>>>0).toString(36)}function Zs(e,s){try{let o=new URL(e,s);return o.origin+o.pathname+o.search}catch{return e}}function Fo(e,s){let o=e.tagName;if(o==="TITLE"||o==="BASE")return o;if(o==="SCRIPT")return Jn(e,s);if(o==="LINK"){let n=e.getAttribute("href");return n?"link|"+(e.getAttribute("rel")||"")+"|"+Zs(n,s):e.outerHTML}if(o==="META"){for(let n of["charset","name","property","http-equiv","itemprop"])if(e.hasAttribute(n))return"meta|"+n+"="+e.getAttribute(n);return e.outerHTML}return o==="STYLE"?"style|"+Qs(e.textContent):e.outerHTML}function ko(e,s){for(;;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(e[s]==="/"&&e[s+1]==="/"){for(;s<e.length&&e[s]!==`
|
|
3
|
-
`;)s++;continue}if(e[s]==="/"&&e[s+1]==="*"){let o=e.indexOf("*/",s+2);if(o===-1)return e.length;s=o+2;continue}return s}}function Ko(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(s,o)=>o.length%2===0?o+'\\"':s)}var er=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,tr=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Xn(e){try{return JSON.parse(e)}catch{return JSON.parse(nr(e))}}function nr(e){let s="",o=0,n=(r,l)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${l}`)};for(;o<e.length&&(o=ko(e,o),!(o>=e.length));){let r=e[o];if("{}[]:".includes(r)){s+=r,o++;continue}if(r===","){let f=ko(e,o+1);if(e[f]==="}"||e[f]==="]"){o++;continue}s+=r,o++;continue}if(r==='"'||r==="'"){let f=o+1;for(;f<e.length&&e[f]!==r;)e[f]==="\\"&&f++,f++;f>=e.length&&n("unterminated string",o);let d=e.slice(o+1,f);r==="'"&&(d=Ko(d)),s+='"'+d+'"',o=f+1;continue}let l=o;for(;l<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[l]);)l++;l===o&&n("unexpected character "+JSON.stringify(r),o);let c=e.slice(o,l);if(c==="true"||c==="false"||c==="null"||er.test(c)){s+=c,o=l;continue}if(tr.test(c)){if(e[ko(e,l)]===":"){s+='"'+c+'"',o=l;continue}n("unquoted value "+JSON.stringify(c),o)}n("invalid token "+JSON.stringify(c),o)}return s}function zo(e){try{return JSON.parse(e)}catch{}let s={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function o(r){let l=[],c=0;for(;c<r.length;){let f=r[c];if(/\s/.test(f)){c++;continue}if("{}".includes(f)){l.push({type:f,value:f}),c++;continue}if(f==="["){let y=!1,T=c+1;for(;T<r.length&&/\s/.test(r[T]);)T++;if(T<r.length&&/[a-zA-Z_]/.test(r[T])&&(y=!0),!y){l.push({type:f,value:f}),c++;continue}}if(f==="]"){l.push({type:f,value:f}),c++;continue}if(f===":"){l.push({type:s.COLON,value:f}),c++;continue}if(f===","){l.push({type:s.COMMA,value:f}),c++;continue}if(f==='"'||f==="'"){let y=f,T=c+1;for(;T<r.length&&r[T]!==y;)r[T]==="\\"&&T++,T++;l.push({type:s.STRING,value:r.substring(c+1,T),quoted:!0,sourceQuote:y}),c=T+1;continue}let d=c,M;for(;d<r.length&&!/[{},]/.test(r[d]);)if(r[d]===":"){let y=[":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"],T=!1;for(let u of y){let b=u.substring(1);if(r.substring(d+1,d+1+b.length)===b){T=!0,d+=b.length;break}}if(!T)break}else if(r[d]==="["){for(d++;d<r.length&&r[d]!=="]";){if(r[d]==='"'||r[d]==="'"){let y=r[d];for(d++;d<r.length&&r[d]!==y;)r[d]==="\\"&&d++,d++}d++}d<r.length&&r[d]==="]"&&d++}else d++;M=r.substring(c,d);let N=s.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?N=s.NUMBER:M==="true"||M==="false"||M==="null"?N=s.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(N=s.SELECTOR),l.push({type:N,value:M,quoted:!1}),c=d}return l}function n(r){let l="";for(let c=0;c<r.length;c++){let f=r[c];if("{}".includes(f.type)||"[]".includes(f.type)){l+=f.value;continue}if(f.type===s.COLON){l+=f.value;continue}if(f.type===s.COMMA){let d=r[c+1];if(d&&(d.type==="}"||d.type==="]"))continue;l+=f.value;continue}if(f.type===s.STRING){let d=f.value;f.sourceQuote==="'"&&(d=Ko(d)),l+=`"${d}"`;continue}if(f.type===s.NUMBER||f.type===s.BOOLEAN){l+=f.value;continue}l+=`"${f.value}"`}return l}try{let r=o(e),l=n(r);return JSON.parse(l)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var gt=Symbol("hyper-morph-json-merge:missing"),qo=["id","_id","uuid","key","slug","code","name"];function Nn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Dn(e,s){return Object.prototype.hasOwnProperty.call(e,s)}function or(e,s,o){Object.defineProperty(e,s,{value:o,enumerable:!0,writable:!0,configurable:!0})}function an(e,s){if(e===s)return!0;if(Array.isArray(e)&&Array.isArray(s)){if(e.length!==s.length)return!1;for(let o=0;o<e.length;o++)if(!an(e[o],s[o]))return!1;return!0}if(Nn(e)&&Nn(s)){let o=Object.keys(e);if(o.length!==Object.keys(s).length)return!1;for(let n of o)if(!Dn(s,n)||!an(e[n],s[n]))return!1;return!0}return!1}function Go(e,s,o,n){return an(s,o)?s:an(s,e)?o:an(o,e)?s:Nn(s)&&Nn(o)?sr(Nn(e)?e:{},s,o,n):Array.isArray(s)&&Array.isArray(o)?lr(Array.isArray(e)?e:[],s,o,n):o}function $o(e,s,o,n){return s===gt&&o===gt?gt:s===gt?e===gt?o:an(o,e)?gt:o:o===gt?e===gt?s:gt:Go(e,s,o,n)}function sr(e,s,o,n){let r={},l=new Set([...Object.keys(e),...Object.keys(s),...Object.keys(o)]);for(let c of l){let f=$o(Dn(e,c)?e[c]:gt,Dn(s,c)?s[c]:gt,Dn(o,c)?o[c]:gt,n);f!==gt&&or(r,c,f)}return r}function rr(e){return e===null||typeof e!="object"}function Qn(e){return typeof e+":"+String(e)}function ir(e,s){for(let o of s){let n=new Set;for(let r of o){if(!Dn(r,e))return!1;let l=r[e];if(typeof l!="string"&&typeof l!="number")return!1;let c=Qn(l);if(n.has(c))return!1;n.add(c)}}return!0}function cr(e,s,o,n){let r=[e,s,o],l=!0;for(let c of r)for(let f of c)Nn(f)||(l=!1);if(l){for(let c of n.keyCandidates)if(ir(c,r))return{kind:"keyed",field:c};return null}for(let c of r){let f=new Set;for(let d of c){if(!rr(d))return null;let M=Qn(d);if(f.has(M))return null;f.add(M)}}return{kind:"self"}}function lr(e,s,o,n){let r=cr(e,s,o,n);if(!r)return o;let l=r.kind==="self"?Qn:u=>Qn(u[r.field]),c=u=>{let b=new Map;for(let x of u)b.set(l(x),x);return b},f=c(e),d=c(s),M=c(o),N=new Map,y=new Set([...f.keys(),...d.keys(),...M.keys()]);for(let u of y){let b=$o(f.has(u)?f.get(u):gt,d.has(u)?d.get(u):gt,M.has(u)?M.get(u):gt,n);b!==gt&&N.set(u,b)}let T=[];for(let u of o){let b=l(u);N.has(b)&&T.push(b)}for(let u=0;u<s.length;u++){let b=l(s[u]);if(!N.has(b)||T.includes(b))continue;let x=0;for(let P=u-1;P>=0;P--){let v=T.indexOf(l(s[P]));if(v!==-1){x=v+1;break}}T.splice(x,0,b)}return T.map(u=>N.get(u))}function yo(e,s,o,n={}){let r=n.keyCandidates?[...n.keyCandidates,...qo]:qo;return Go(e===void 0?gt:e,s,o,{keyCandidates:r})}function Zn(e,s,o,n={}){let r=n.parse||Xn,l=[],c=(y,T)=>{if(typeof y!="string")return gt;try{return r(y)}catch(u){return l.push(`${T} side is not valid JSON (${u.message})`),gt}},f=c(s,"local"),d=c(o,"remote");if(f===gt)return{text:o,warnings:l};if(d===gt)return{text:s,warnings:l};let M=c(e,"base"),N=yo(M===gt?void 0:M,f,d,n);return an(N,d)?{text:o,warnings:l}:an(N,f)?{text:s,warnings:l}:{text:JSON.stringify(N,null,2),warnings:l}}var Ee=e=>!!e&&e.nodeType===1,ar=new Set("P H1 H2 H3 H4 H5 H6 DIV LI DD DT BLOCKQUOTE FIGCAPTION SUMMARY ADDRESS".split(" ")),Yo=5e4;function wo(e,s,o,n){let r=n.ignored,l=Oo({ignored:r,ignoreAttribute:n.ignoreAttribute}),{unitsOf:c,meta:f}=l,d=n.baseURI,M=n.mergeTags!==null,N=m=>L=>{if(M&&L.tagName==="SCRIPT"){let R=xn(L,n.mergeTags);if(R)return"merge:"+R.key}return L.parentElement&&L.parentElement.tagName==="HEAD"?Fo(L,d):m(L)},y=N(n.identity.base),T=N(n.identity.local),u=N(n.identity.remote),b=n.authored||n.identity,x=m=>m&&m.nodeType===9?m.documentElement:m,P=x(e),v=x(s),j=x(o),Y=globalThis.__hyperMorphProfile,le=Y?performance.now():0,Ne="[id],[data-id],script,head>*",ye=m=>m===un?Ne:null,De=Gn(P,y,r,ye(n.identity.base)),F=n.localIsBase?Xo():ro(P,v,{analyzer:l,baseIndex:De,sideIndex:Gn(v,T,r,ye(n.identity.local)),baseId:b.base,sideId:b.local}),H=ro(P,j,{analyzer:l,baseIndex:De,sideIndex:Gn(j,u,r,ye(n.identity.remote)),baseId:b.base,sideId:b.remote});Je(),Xe(F,H),Xe(H,F),Y&&(Y.alignTotal=(Y.alignTotal||0)+(performance.now()-le),le=performance.now());let Q=P.ownerDocument.implementation.createHTMLDocument(""),ie=new WeakMap,me=new WeakMap,Ie=[],ot=[],bt=new Set,kt=[],Se=new Set,at=new Set,Ge=new Set,xt=new WeakMap,Ke=n.conflicts||"remote",ze=m=>Ie.push(m),it=m=>Ie.push(m),w=m=>ot.push(m),E=Me(),oe=g(P,F.map.get(P),H.map.get(P),!!n.localIsBase,!!n.childrenOnly);oe.tagName==="HTML"?Q.replaceChild(oe,Q.documentElement):Q.body.appendChild(oe),Y&&(Y.build=(Y.build||0)+(performance.now()-le));let Z=n.childrenOnly?!Qe(ut(oe),ut(j)):!yt(oe,j);return{doc:Q,root:oe,provenance:ie,textMappers:me,decisions:Ie,conflicts:ot,localDiverged:Z,mergedScripts:bt,segments:kt,remoteIdOf:n.identity.remote,customIdentity:n.identity.remote!==un,L:F,R:H};function Me(){let m=new Map,L=new Set;if(n.localIsBase||!F.insertedByHash)return{partner:m,drop:L};let R=F.insertedByHash(),W=H.insertedByHash();if(!R.size||!W.size)return{partner:m,drop:L};let D={ignored:r,remoteWins:n.remoteWins,inlineCache:xt},V=de=>{let $e=0;for(let xe=de.parentNode;xe;xe=xe.parentNode)$e++;return $e},G=[],se=de=>{let $e=de.textContent.trim();return $e.split(/\s+/).length>=3||$e.replace(/\s/g,"").length>=12},pe=de=>{let $e=F.map.get(de),xe=H.map.get(de);return $e&&F.reverse.get($e.parentNode)!==de.parentNode||xe&&H.reverse.get(xe.parentNode)!==de.parentNode},ue=(de,$e,xe)=>{for(let Tt of xe.parentNode.children){let Ot=Tt!==xe&&de.reverse.get(Tt);if(Ot&&pe(Ot))return!0}let Lt=de.reverse.get(xe.parentNode);if(Lt){for(let Tt of Lt.children)if(!$e.map.has(Tt)&&!r(Tt))return!0}return!1};for(let[de,$e]of R){let xe=W.get(de);if(!xe)continue;let Lt=$e.length===1&&xe.length===1;for(let Tt of $e)hn(Tt,D)||G.push([Tt,xe,V(Tt),Lt&&(se(Tt)||ue(F,H,Tt)||ue(H,F,xe[0]))])}if(!G.length)return{partner:m,drop:L};G.sort((de,$e)=>de[2]-$e[2]);let ge=new Set,Pe=new Set,He=de=>{for(let $e of de.querySelectorAll("*"))ge.add($e)},At=(de,$e)=>de.reverse.get($e.parentNode)||null;for(let[de,$e,,xe]of G){if(ge.has(de))continue;let Lt=At(F,de),Tt=ht=>!Pe.has(ht)&&!ge.has(ht)&&ht.tagName===de.tagName,Ot=$e.find(ht=>Tt(ht)&&Lt&&At(H,ht)===Lt)||(xe?$e.find(Tt):null);Ot&&(Pe.add(Ot),He(de),He(Ot),!(Lt&&At(H,Ot)===Lt)&&(m.set(de,Ot),m.set(Ot,de),L.add(Ke==="local"?Ot:de)))}return{partner:m,drop:L}}function st(m,L,R){if(Se.add(m),E.drop.has(m))return null;Se.add(R);let W=L==="local"?m:R,D=L==="local"?R:m,V;return l.unitHash(W)===l.unitHash(D)?(V=we(W,"local",!0),ie.get(V).remote=D):V=ee(W,D),w({kind:"structure",el:V,detail:"both-moved",base:null,local:W,remote:D}),ze({kind:"insert",el:V,source:"both"}),V}function Je(){if(!F.weak||!H.weak||!F.weak.size||!H.weak.size||!F.unpair)return;let m=new Map;for(let R of F.weak){let W=F.map.get(R);Ee(R)&&Ee(W)&&m.set(l.unitHash(W),R)}let L=!1;for(let R of Array.from(H.weak)){let W=H.map.get(R);if(!Ee(R)||!Ee(W))continue;let D=m.get(l.unitHash(W));!D||D===R||!F.weak.has(D)||F.map.has(R)&&H.map.has(D)||F.map.get(D).tagName===W.tagName&&(F.unpair(D),H.unpair(R),L=!0)}L&&(F.rematch(),H.rematch())}function Xe(m,L){if(!m.weak||!m.weak.size||!L.insertedByHash)return;let R=L.insertedByHash();if(!R.size)return;let W=!1;for(let D of Array.from(m.weak)){let V=m.map.get(D);if(!V)continue;let G=R.get(l.unitHash(V));G&&G.some(se=>se.tagName===V.tagName)&&(m.unpair(D),W=!0)}W&&m.rematch()}function nt(m,L){if(m.map.has(L))return m.map.get(L);let R=[];for(let D=L.parentNode;D&&!m.map.has(D);D=D.parentNode)R.push(D);let W=R.length?R[R.length-1].parentNode:L.parentNode;if(!W||!m.identical.has(W))return null;m.pairIdenticalChildren(W);for(let D=R.length-1;D>=0;D--)m.pairIdenticalChildren(R[D]);return m.map.get(L)||null}function ft(m,L,R){if(at.has(m)||Ge.has(m))return w({kind:"structure",el:null,detail:"both-moved",base:m}),at.has(m)?null:we(R,L);let W=nt(F,m),D=nt(H,m);(!W||!D)&&w({kind:"structure",el:null,detail:"move-beats-delete",base:m});let V=g(m,W,D,!1);return(L==="local"?ze:it)({kind:"move",el:V,source:L}),V}function i(m,L,R,W){return W||!L||L===R?{el:R,asBase:!0,twin:D=>D,baseOf:D=>D,units:c(R),here:()=>!0,parentOfTwin:()=>R}:{el:L,asBase:!1,twin:D=>m.map.get(D),baseOf:D=>m.reverse.get(D),units:c(L),here:D=>Ee(D)?D.parentNode===L||L.tagName==="TEMPLATE"&&D.parentNode===L.content:D.parent===L||L.tagName==="TEMPLATE"&&D.parent===L.content}}function k(m,L,R){return!L||R&&R.identical.has(m)?!1:Ee(m)?f(m).hash!==f(L).hash:m.value!==L.value}function g(m,L,R,W,D=!1){let V=W||n.remoteWins(m),G=m.namespaceURI&&m.namespaceURI!=="http://www.w3.org/1999/xhtml"?Q.createElementNS(m.namespaceURI,m.tagName):Q.createElement(m.tagName),se={base:m,local:L||null,remote:R||null};if(ie.set(G,se),Se.add(m),at.add(m),L&&Se.add(L),R&&Se.add(R),n.skipUnchanged&&!D&&(n.localIsBase||F.identical.has(m))&&R&&H.identical.has(m)&&!n.remoteWins(m)){se.unchanged=!0;for(let ue of m.attributes)ue.namespaceURI?G.setAttributeNS(ue.namespaceURI,ue.name,ue.value):G.setAttribute(ue.name,ue.value);return G}Ge.add(m),D||O(m,V?m:L,R,G);let pe=m.tagName;if(_t(m))I(m,V?m:L,R,G);else if(pe==="TEXTAREA")G.textContent=_(m.textContent,(V?m:L)?(V?m:L).textContent:m.textContent,R?R.textContent:m.textContent,G,"text");else{let ue=et(m,L,R,V,G),ge=pe==="TEMPLATE"&&G.content?G.content:G;for(let Pe of ue)ge.appendChild(Pe)}return Ge.delete(m),G}function _(m,L,R,W,D){if(L===R)return L;if(L===m)return R!==m&&it({kind:D,node:W,source:"remote"}),R;if(R===m)return ze({kind:D,node:W,source:"local"}),L;let V=Ke==="local"?L:R;return w({kind:D,node:W,base:m,local:L,remote:R,resolved:V}),Ie.push({kind:D,node:W,source:"both"}),V}function I(m,L,R,W){let D=m.textContent,V=L?L.textContent:D,G=R?R.textContent:D,se=M?xn(m,n.mergeTags,!0):null;if(se&&V!==G){let pe=R&&R.getAttribute("merge-key")||m.getAttribute("merge-key"),{text:ue,warnings:ge}=Zn(n.localIsBase?void 0:D,V,G,{parse:se.recognizer.parse,keyCandidates:pe?pe.split(/[\s,]+/).filter(Boolean):void 0});for(let Pe of ge)console.warn(`[hyper-morph] merge "${se.raw}": ${Pe}`);W.textContent=ue,bt.add(W),ue!==G?ze({kind:"text",node:W,source:ue===V?"local":"both"}):ue!==D&&it({kind:"text",node:W,source:"remote"});return}W.textContent=_(D,V,G,W,"text")}function O(m,L,R,W){let D=new Map;for(let V of[m,L,R])if(V)for(let G of V.attributes)n.ignoreAttribute(V,G.name)||D.set(G.name,G);for(let[V,G]of D){let se=m?m.getAttribute(V):null,pe=L?L.getAttribute(V):se,ue=R?R.getAttribute(V):se,ge;pe===ue?ge=pe:pe===se?(ge=ue,it({kind:"attr",el:W,name:V,source:"remote"})):ue===se?(ge=pe,ze({kind:"attr",el:W,name:V,source:"local"})):(ge=U(V,se,pe,ue),ge===void 0&&(ge=Ke==="local"?pe:ue,w({kind:"attr",el:W,name:V,base:se,local:pe,remote:ue,resolved:ge})),Ie.push({kind:"attr",el:W,name:V,source:"both"})),ge!=null&&(G.namespaceURI?W.setAttributeNS(G.namespaceURI,G.name,ge):W.setAttribute(V,ge))}}function U(m,L,R,W){if(m==="class"){let D=ue=>new Set((ue||"").split(/\s+/).filter(Boolean)),V=D(L),G=D(R),se=D(W),pe=new Set;for(let ue of new Set([...V,...G,...se])){let ge=V.has(ue),Pe=G.has(ue),He=se.has(ue);(Pe===He?Pe:Pe===ge?He:Pe)&&pe.add(ue)}return[...pe].join(" ")}if(m==="style"){let D=ge=>{let Pe=new Map;if(!ge)return Pe;let He=0,At=null,de="",$e=()=>{let xe=de.indexOf(":");xe>0&&Pe.set(de.slice(0,xe).trim(),de.slice(xe+1).trim()),de=""};for(let xe of ge){if(At){de+=xe,xe===At&&(At=null);continue}if(xe==='"'||xe==="'"){At=xe,de+=xe;continue}if(xe==="("?He++:xe===")"&&He--,xe===";"&&He===0){$e();continue}de+=xe}return de.trim()&&$e(),Pe},V=D(L),G=D(R),se=D(W),pe=new Map,ue=!1;for(let ge of new Set([...V.keys(),...G.keys(),...se.keys()])){let Pe=V.get(ge)??null,He=G.get(ge)??null,At=se.get(ge)??null,de;He===At?de=He:He===Pe?de=At:At===Pe?de=He:(de=Ke==="local"?He:At,ue=!0),de!=null&&pe.set(ge,de)}return ue?void 0:[...pe].map(([ge,Pe])=>`${ge}: ${Pe}`).join("; ")}}function S(m,L,R,W){let D=m.value,V=W?D:L?L.value:"",G=R?R.value:"";Se.add(m),L&&Se.add(L),R&&Se.add(R);let se=yn(D,V,G,Ke),pe=se.text===""?null:Q.createTextNode(se.text);pe&&(ie.set(pe,{base:m.nodes,local:L?L.nodes:null,remote:R?R.nodes:null}),me.set(pe,se.mapLocalOffset)),V!==D&&G!==D?Ie.push({kind:"text",node:pe,source:"both"}):V!==D?ze({kind:"text",node:pe,source:"local"}):G!==D&&it({kind:"text",node:pe,source:"remote"});for(let ue of se.conflicts)w({kind:"text",node:pe,base:D.slice(ue.bs,ue.be),local:ue.local,remote:ue.remote,resolved:ue.resolved});return pe}function B(m,L){return wn(m,L).every(R=>R.bs===R.be)}function J(m,L){let R=m?m.value:"",W=L?L.value:"",D;if(R===W||!W?D=R:R?B(R,W)?D=W:B(W,R)?D=R:(D=Ke==="local"?R:Ke==="both"?R+W:W,w({kind:"structure",el:null,detail:"insert-collision",local:R,remote:W,resolved:D})):D=W,m&&Se.add(m),L&&Se.add(L),D==="")return null;let V=Q.createTextNode(D);return ie.set(V,{base:null,local:m?m.nodes:null,remote:L?L.nodes:null}),R?ze({kind:"insert",el:V,source:W&&R===W?"both":"local"}):it({kind:"insert",el:V,source:"remote"}),V}function ee(m,L){let R={ignored:r,remoteWins:n.remoteWins,inlineCache:xt},W=se=>c(se).every(pe=>Ee(pe)?hn(pe,R):pe.kind==="text"),D=null;if(W(m)&&W(L)){let se=m.textContent,pe=L.textContent;se===pe||B(pe,se)?D=L:B(se,pe)&&(D=m)}if(!D){let se=Ke==="local",pe=we(se?m:L,se?"local":"remote",!0),ue=ie.get(pe);return se?ue.remote=L:ue.local=m,w({kind:"structure",el:pe,detail:"insert-collision",local:m,remote:L,resolved:se?m:L}),pe}let V=m.namespaceURI&&m.namespaceURI!=="http://www.w3.org/1999/xhtml"?Q.createElementNS(m.namespaceURI,m.tagName):Q.createElement(m.tagName);O(null,m,L,V),ie.set(V,{base:null,local:m,remote:L}),Se.add(m),Se.add(L);let G=bo({base:Array.from(D.childNodes),local:Array.from(m.childNodes),remote:Array.from(L.childNodes),out:Q,policy:Ke,idOf:{local:T,remote:u},ignored:r,ignoreAttribute:n.ignoreAttribute,remoteWins:n.remoteWins,provenance:ie,textMappers:me,conflicts:ot,decisions:Ie,node:V});kt.push(...G.segments);for(let se of G.nodes)V.appendChild(se);return V}function we(m,L,R=!1){if(!R&&Ee(m)){let G=E.partner.get(m);if(G)return st(m,L,G)}if(!Ee(m)){if(m.value==="")return null;let G=m.kind==="comment"?Q.createComment(m.value):Q.createTextNode(m.value);return ie.set(G,{base:null,local:L==="local"?m.nodes:null,remote:L==="remote"?m.nodes:null}),Se.add(m),G}let W=m.namespaceURI&&m.namespaceURI!=="http://www.w3.org/1999/xhtml"?Q.createElementNS(m.namespaceURI,m.tagName):Q.createElement(m.tagName);for(let G of m.attributes)G.namespaceURI?W.setAttributeNS(G.namespaceURI,G.name,G.value):W.setAttribute(G.name,G.value);ie.set(W,{base:null,local:L==="local"?m:null,remote:L==="remote"?m:null}),Se.add(m);let D=m.tagName==="TEMPLATE"&&W.content?W.content:W,V=L==="local"?F:H;for(let G of c(m)){let se=Ee(G)?V.reverse.get(G):null;if(se&&at.has(se)){w({kind:"structure",el:null,detail:"both-moved",base:se});continue}if(se&&!Ge.has(se)){let ue=F.map.get(se)||null,ge=H.map.get(se)||null;if(ue||ge){let Pe=g(se,ue,ge,!1);L==="local"?ze({kind:"move",el:Pe,source:"local"}):it({kind:"move",el:Pe,source:"remote"}),D.appendChild(Pe);continue}}let pe=we(G,L);pe&&D.appendChild(pe)}return W}function et(m,L,R,W,D){L&&F.identical.has(m)&&F.pairIdenticalChildren(m),R&&H.identical.has(m)&&H.pairIdenticalChildren(m);let V=i(F,L,m,W),G=i(H,R,m,!1),se=c(m),pe=new Set(se),ue=new Map;for(let K=0;K<se.length;K++)ue.set(se[K],K);let ge=[],Pe=new Set,He=new Map,At=new Set,de=new Set,$e=[];Wn();let xe=K=>{let Te=[];for(let he of K.units){if(de.has(he))continue;let Oe=K.baseOf(he);Oe&&pe.has(Oe)&&Te.push(ue.get(Oe))}return Te},Lt=K=>K.every((Te,he)=>he===0||Te>=K[he-1]),Tt=!V.asBase&&!Lt(xe(V)),Ot=!G.asBase&&!Lt(xe(G));Tt&&Ot&&w({kind:"structure",el:null,detail:"both-reordered",base:m});let ht=Ot||!Tt?{V:G,A:H,side:"remote",other:V,otherA:F,otherSide:"local"}:{V,A:F,side:"local",other:G,otherA:H,otherSide:"remote"};Tt?ze({kind:"move",el:null,source:Ot?"both":"local",base:m}):Ot&&it({kind:"move",el:null,source:"remote",base:m});let On=V.asBase?[]:V.units.filter(K=>!V.baseOf(K)&&!de.has(K)&&!E.partner.has(K)),Ln=G.asBase?[]:G.units.filter(K=>!G.baseOf(K)&&!de.has(K)&&!E.partner.has(K)),tn=new Map;if(On.length&&Ln.length){let K=new Map,Te=new Map;for(let ne of Ln){if(Ee(ne)){let te=u(ne);te&&K.set(te,ne)}let Ae=l.unitHash(ne);Te.has(Ae)||Te.set(Ae,[]),Te.get(Ae).push(ne)}let he=(ne,Ae)=>{let te=ne.units.indexOf(Ae);for(let Le=te-1;Le>=0;Le--){let Ue=ne.baseOf(ne.units[Le]);if(Ue)return Ue}return"start"},Oe=new Map,Ve=new Map;for(let ne of Ln){let Ae=he(G,ne);Ee(ne)?(Ve.has(Ae)||Ve.set(Ae,[]),Ve.get(Ae).push(ne)):ne.kind==="text"&&!Oe.has(Ae)&&Oe.set(Ae,ne)}for(let ne of On){let Ae=null;if(Ee(ne)){let te=T(ne);te&&K.has(te)&&!tn.has(K.get(te))&&(Ae=K.get(te))}else if(ne.kind==="text"){let te=Oe.get(he(V,ne));te&&!tn.has(te)&&(Ae=te)}if(!Ae){let te=Te.get(l.unitHash(ne));te&&(Ae=te.find(Le=>!tn.has(Le)&&Ee(Le)===Ee(ne)&&(Ee(Le)?Le.tagName===ne.tagName:Le.kind===ne.kind))||null)}if(!Ae&&Ee(ne)){let te=b.local(ne),Le=(Ve.get(he(V,ne))||[]).filter(Ue=>{let Ct=b.remote(Ue);return!tn.has(Ue)&&Ue.tagName===ne.tagName&&!(te&&Ct&&te!==Ct)&&l.similar(ne,Ue)});Le.length===1&&(Ae=Le[0])}Ae&&(tn.set(Ae,ne),tn.set(ne,Ae))}}let Gt=K=>{if(Se.has(K))return He.get(K)||null;let Te=V.twin(K),he=G.twin(K),Oe=Te&&!V.asBase&&!V.here(Te),Ve=he&&!G.asBase&&!G.here(he);if(Oe||Ve){if((!Te||!he)&&w({kind:"structure",el:null,detail:"move-beats-delete",base:K}),!jt(K))return Se.add(K),null;w({kind:"structure",el:null,detail:"both-moved",base:K})}if(!Te&&!he)return Se.add(K),it({kind:"remove",source:"both",base:K}),null;if(!Te&&!k(K,he,H))return Se.add(K),ze({kind:"remove",source:"local",base:K}),null;if(!he&&!k(K,Te,F))return Se.add(K),it({kind:"remove",source:"remote",base:K}),null;let ne=!Te||!he,Ae=V.asBase?F.map.get(K)||null:Te,te;return Ee(K)?te=g(K,Ae,he,V.asBase):K.kind==="comment"?te=wt(K,Ae,he,V.asBase):te=S(K,Ae,he,V.asBase),Se.add(K),te&&(He.set(K,te),Te&&He.set(Te,te),he&&He.set(he,te),ne&&(w({kind:"structure",el:te,detail:"edit-beats-delete",base:K}),Te?ze({kind:"insert",el:te,source:"local"}):it({kind:"insert",el:te,source:"remote"}))),te},pn=(K,Te,he,Oe)=>{if(Se.has(K))return He.get(K)||null;let Ve=Te.baseOf(K);if(Ve&&pe.has(Ve))return de.has(Ve)&&!de.has(K)?jn(Ve,K,Oe):Gt(Ve);if(Ve)return _n(Ve,K,Oe);let ne=tn.get(K);if(ne){let te=Oe==="local"?K:ne,Le=Oe==="local"?ne:K,Ue;return Ee(te)?l.unitHash(te)===l.unitHash(Le)?(Ue=we(te,"local"),ie.get(Ue).remote=Le):Ue=ee(te,Le):Ue=J(te,Le),Se.add(te),Se.add(Le),Ue&&(He.set(te,Ue),He.set(Le,Ue),Ee(te)&&ze({kind:"insert",el:Ue,source:"both"})),Ue}let Ae=we(K,Oe);return Ae&&(He.set(K,Ae),Oe==="local"?ze({kind:"insert",el:Ae,source:"local"}):it({kind:"insert",el:Ae,source:"remote"})),Ae},jn=(K,Te,he)=>{let Oe;return Ee(K)?(Oe=ft(K,he,Te),Oe&&Se.add(Te)):(Oe=we(Te,he),Se.add(Te),Oe&&(he==="local"?ze:it)({kind:"insert",el:Oe,source:he})),Oe&&He.set(Te,Oe),Oe},_n=(K,Te,he)=>{let Ve=(he==="local"?H:F).map.get(K),ne=Te,Ae=Ve?Nt(Ve,he==="local"?R:L,he==="local"?H:F):!1,te=Ve&&!Ae&&!St(K,Ve);if(te&&he===ht.otherSide)return w({kind:"structure",el:null,detail:"both-moved",base:K}),null;if(te&&w({kind:"structure",el:null,detail:"both-moved",base:K}),Ve||w({kind:"structure",el:null,detail:"move-beats-delete",base:K}),Ge.has(K)){w({kind:"structure",el:null,detail:"both-moved",base:K});let Ue=we(ne,he);return Ue&&He.set(Te,Ue),Ue}let Le=Ee(K)?g(K,he==="local"?ne:F.map.get(K)||null,he==="remote"?ne:H.map.get(K)||null,!1):null;return Le&&(He.set(K,Le),He.set(Te,Le),Ve&&He.set(Ve,Le),he==="local"?ze({kind:"move",el:Le,source:"local"}):it({kind:"move",el:Le,source:"remote"})),Le};for(let K of ht.V.units){if(de.has(K)){let he=He.get(K);Pe.has(he)||(ge.push(he),Pe.add(he));continue}if(Se.has(K)&&!(He.get(K)&&Pe.has(He.get(K)))){let he=ht.V.baseOf(K);he&&!pe.has(he)&&w({kind:"structure",el:null,detail:"both-moved",base:he});continue}let Te=pn(K,ht.V,ht.A,ht.side);Te&&!Pe.has(Te)&&(ge.push(Te),Pe.add(Te),!ht.V.baseOf(K)&&!tn.has(K)&&!de.has(K)&&At.add(Te))}for(let K of $e)Pe.has(K.frag)||(ge.splice(Vn(K.at),0,K.frag),Pe.add(K.frag));if(!ht.other.asBase){let K=ht.other,Te=ht.otherSide,he=ht.otherA,Oe=null,Ve=0,ne=null;for(let Ae of K.units){let te=He.get(Ae);if(te&&Pe.has(te)){Oe=te,ne=null;continue}if(Se.has(Ae)){let Ct=K.baseOf(Ae);Ct&&!pe.has(Ct)&&w({kind:"structure",el:null,detail:"both-moved",base:Ct});continue}let Le=pn(Ae,K,he,Te);if(!Le)continue;let Ue;if(ne)Ue=ge.indexOf(ne)+1;else if(Oe){if(Ue=ge.indexOf(Oe)+1,Te==="remote")for(;Ue<ge.length&&At.has(ge[Ue]);)Ue++}else Ue=Ve++;ge.splice(Ue,0,Le),Pe.add(Le),ne=Le}}for(let K=0;K<se.length;K++){let Te=se[K];if(Se.has(Te))continue;let he=Gt(Te);he&&ge.splice(Vn(K),0,he)}return ge;function Vn(K){for(let Te=K-1;Te>=0;Te--){let he=He.get(se[Te]);if(he){let Oe=ge.indexOf(he);if(Oe>=0)return Oe+1}}return 0}function mn(K){let Te={ignored:r,remoteWins:()=>!1},he=q=>K(q)||Ee(q)&&n.remoteWins(q)&&nn.has(q.tagName)&&hn(q,Te),Oe=new Map,Ve=q=>{if(!Ee(q)||!ar.has(q.tagName))return!1;let ae=Oe.get(q);return ae===void 0&&(ae=!r(q)&&!n.remoteWins(q)&&c(q).every(he),Oe.set(q,ae)),ae},ne=q=>!Ee(q)&&q.kind==="text",Ae=null,te=new Map,Le=q=>{let ae=te.get(q);if(ae)return ae;let be=Ee(q)?q.textContent:q.value;ae=new Set;let Re=be.toLowerCase();if(!(be.length>Yo))if(/^[\x00-\x7f]*$/.test(Re))for(let ve of Re.split(/[^\p{L}\p{N}]+/u))ve&&ae.add(ve);else for(let ve of fo(Re))/^[\s\p{P}]+$/u.test(ve)||ae.add(ve);return te.set(q,ae),ae},Ue=q=>(Ee(q)?q.textContent:q.value).toLowerCase().replace(/\s+/g," ").trim(),Ct=new Map,$t=q=>{let ae=Ct.get(q);if(ae)return ae;ae=new Set(Le(q));let be=ve=>{if(ve)for(let qe of Le(ve))ae.add(qe)},Re=pe.has(q)?q:!V.asBase&&V.baseOf(q)||!G.asBase&&G.baseOf(q);return Re&&(be(Re),be(F.map.get(Re)),be(H.map.get(Re))),Ct.set(q,ae),ae},on=(q,ae)=>{let be=Ue(ae),Re=pe.has(q)?q:!V.asBase&&V.baseOf(q)||!G.asBase&&G.baseOf(q),ve=dt=>be?dt.split(be).length-1:0;if(Re&&Ee(ae)&&!pe.has(ae)){let dt=ve(Ue(Re));for(let pt of[F.map.get(Re),H.map.get(Re)]){if(!pt||pt===ae||pt.ownerDocument!==ae.ownerDocument)continue;let zt=Ue(pt);if(zt.length>be.length&&ve(zt)>=dt&&(zt.startsWith(be)||zt.endsWith(be)))return!1}}let qe=Le(ae),tt=$t(q),Rt=0;for(let dt of qe)tt.has(dt)&&Rt++;if(qe.size&&Rt*2>=qe.size)return!0;if(!be||be.length>Yo)return!1;let Ut=Re?[q,Re,F.map.get(Re),H.map.get(Re)]:[q],Ft=(dt,pt)=>dt!==pt&&(dt.startsWith(pt)||dt.endsWith(pt));if(Ut.some(dt=>dt&&Ft(Ue(dt),be)))return!0;if(!pe.has(ae)||!Re)return!1;let vt=Ue(q),Kt=Ue(Re);return[F.map.get(ae),H.map.get(ae)].some(dt=>{let pt=dt&&Ue(dt);return!!pt&&vt!==pt&&(vt.startsWith(pt)&&!Kt.startsWith(pt)||vt.endsWith(pt)&&!Kt.endsWith(pt))})},Pt=q=>{Ae||(Ae=new Set),Ae.add(q)},cn=q=>{Pt(q);for(let[ae,be]of[[F,V],[H,G]]){if(be.asBase)continue;let Re=ae.map.get(q);Re&&be.here(Re)&&Pt(Re)}},Be=(q,ae)=>q.asBase||se.every(be=>!Ee(be)||ae.identical.has(be)&&q.here(ae.map.get(be)))&&q.units.every(be=>!Ee(be)||q.baseOf(be));if(Be(V,F)&&Be(G,H))return null;let We=q=>{if(q.asBase)return!1;let ae=-1;for(let be of q.units){let Re=Ee(be)?q.baseOf(be):null;if(!Re||!pe.has(Re))continue;let ve=ue.get(Re);if(ve<ae)return!0;ae=ve}return!1};if(We(V)||We(G))return null;for(let[q,ae]of[[V,F],[G,H]]){if(q.asBase||Be(q,ae))continue;let be=q.units,Re=ae===F?b.local:b.remote,ve=(ce,Fe)=>{let ct=Ee(ce)&&b.base(ce),Ze=Ee(Fe)&&Re(Fe);return!ct||!Ze||ct===Ze},qe=new Map;for(let ce=0;ce<be.length;ce++)qe.set(be[ce],ce);let tt=ce=>!!ce&&(Ee(ce)?q.here(ce):qe.has(ce)),Rt=ce=>{let Fe=q.twin(ce);return tt(Fe)?Fe:null},Ut=se.filter(ce=>!q.twin(ce)&&Ve(ce)),Ft=be.filter(ce=>!q.baseOf(ce)&&Ve(ce)),vt=(ce,Fe)=>Fe===se?!!Rt(ce):pe.has(q.baseOf(ce)),Kt=ce=>{let Fe=new Int32Array(ce.length),ct=new Int32Array(ce.length),Ze=-1;for(let Ye=0;Ye<ce.length;Ye++)Fe[Ye]=Ze,vt(ce[Ye],ce)&&(Ze=Ye);Ze=ce.length;for(let Ye=ce.length-1;Ye>=0;Ye--)ct[Ye]=Ze,vt(ce[Ye],ce)&&(Ze=Ye);return{prev:Fe,next:ct}},dt=Kt(be),pt=Kt(se),zt=(ce,Fe)=>{cn(ce),Pt(Fe)};for(let ce of Ft){let Fe=qe.get(ce),ct=dt.prev[Fe],Ze=dt.next[Fe],Ye=ct>=0?q.baseOf(be[ct]):null,Qt=Ze<be.length?q.baseOf(be[Ze]):null,Yt=Ye?ue.get(Ye):-1,ln=Qt?ue.get(Qt):se.length;for(let qt=Math.max(0,Yt);qt<=Math.min(ln,se.length-1);qt++){let Dt=se[qt];(Ve(Dt)||ne(Dt))&&(!ve(Dt,ce)||!on(Dt,ce)||(ne(Dt)?Pt(ce):zt(Dt,ce)))}}let Xt=(ce,Fe,ct)=>{for(let Ze=Fe+ct;Ze>=0&&Ze<ce.length;Ze+=ct){let Ye=ce[Ze];if(Ve(Ye))return Ye;if(Ee(Ye)||Ye.value.trim())return null}return null},Fn=ce=>{let Fe=new Set;for(let ct of c(ce))if(!Ee(ct)&&ct.kind==="text")for(let Ze of Le(ct))Fe.add(Ze);return Fe},Cn=(ce,Fe)=>{let ct=Le(Fe),Ze=new Set;for(let Ye of Fn(ce))ct.has(Ye)||Ze.add(Ye);return Ze},En=(ce,Fe)=>{if(!ce.size)return!1;let ct=Le(Fe),Ze=0;for(let Ye of ce)ct.has(Ye)&&Ze++;return Ze*2>=ce.size};for(let ce of se){if(ae.identical.has(ce)||!Ve(ce))continue;let Fe=Rt(ce);if(!Fe||!Ve(Fe))continue;let ct=Cn(Fe,ce),Ze=Cn(ce,Fe);for(let Ye of[-1,1]){let Qt=Xt(se,ue.get(ce),Ye);Qt&&En(ct,Qt)&&(zt(ce,Fe),cn(Qt));let Yt=Xt(be,qe.get(Fe)??-1,Ye);if(Yt&&En(Ze,Yt)){zt(ce,Fe);let ln=q.baseOf(Yt);ln?zt(ln,Yt):Pt(Yt)}}}for(let ce of Ut){let Fe=ue.get(ce),ct=pt.prev[Fe],Ze=pt.next[Fe],Ye=ct>=0?Rt(se[ct]):null,Qt=Ze<se.length?Rt(se[Ze]):null,Yt=Ye?qe.get(Ye)??-1:-1,ln=Qt?qe.get(Qt)??-1:be.length;for(let qt=Math.max(0,Yt);qt<=Math.min(ln,be.length-1);qt++){let Dt=be[qt];if((Ve(Dt)||ne(Dt))&&!(!ve(ce,Dt)||!on(Dt,ce))&&(cn(ce),!ne(Dt))){let Vt=q.baseOf(Dt);Vt?zt(Vt,Dt):Pt(Dt)}}}}if(!Ae)return null;for(let q of Array.from(Ae))if(pe.has(q))for(let ae of[F,H]){let be=ae.map.get(q);be&&be.parentNode!==(ae===F?L:R)&&!(ae===F?V:G).asBase&&Ae.delete(q)}return Ae.size?Ae:null}function Wn(){if((V.asBase||F.identical.has(m))&&(G.asBase||H.identical.has(m)))return;let K={ignored:r,remoteWins:n.remoteWins,inlineCache:xt},Te=Be=>Ee(Be)?hn(Be,K):Be.kind==="text",he=mn(Te),Oe=Be=>he&&he.has(Be)||Te(Be),Ve=se.map(Oe);if(!Ve.includes(!0))return;let ne=Be=>{let We=Be.units,q=new Map;for(let tt=0;tt<We.length;tt++)q.set(We[tt],tt);let ae=[],be=-1;for(let tt=0;tt<se.length;tt++){if(Ve[tt])continue;let Rt=Be.twin(se[tt]),Ut=Rt?q.get(Rt):void 0;Ut===void 0||Ut<=be||Oe(Rt)||(ae.push([tt,Ut]),be=Ut)}let Re=[],ve=-1,qe=-1;for(let tt=0;tt<=ae.length;tt++){let[Rt,Ut]=tt<ae.length?ae[tt]:[se.length,We.length],Ft={bLo:-1,bHi:-1,sLo:-1,sHi:-1,next:Ut};for(let vt=ve+1;vt<Rt;vt++)Ve[vt]&&(Ft.bLo<0&&(Ft.bLo=vt),Ft.bHi=vt);for(let vt=qe+1;vt<Ut;vt++)Oe(We[vt])&&(Ft.sLo<0&&(Ft.sLo=vt),Ft.sHi=vt);Re.push(Ft),ve=Rt,qe=Ut}return{units:We,list:Re}},Ae=ne(V),te=ne(G),Le=[];for(let Be of[Ae,te])for(let We of Be.list)We.bLo>=0&&Le.push([We.bLo,We.bHi]);Le.sort((Be,We)=>Be[0]-We[0]);let Ue=[];for(let[Be,We]of Le){let q=Ue[Ue.length-1];q&&Be<=q.hi?q.hi=Math.max(q.hi,We):Ue.push({lo:Be,hi:We})}let Ct=(Be,We)=>{let q=-1,ae=-1;for(let ve=0;ve<Be.list.length;ve++){let qe=Be.list[ve];qe.bLo<We.lo||qe.bLo>We.hi||(q<0&&(q=ve),ae=ve)}let be=1/0,Re=-1;for(let ve=q;ve>=0&&ve<=ae;ve++){let qe=Be.list[ve];qe.sLo>=0&&(be=Math.min(be,qe.sLo),Re=Math.max(Re,qe.sHi)),ve<ae&&(be=Math.min(be,qe.next),Re=Math.max(Re,qe.next))}return Re<0?[]:Be.units.slice(be,Re+1)},$t=(Be,We)=>Be.length===We.length&&Be.every((q,ae)=>l.unitHash(q)===l.unitHash(We[ae])),on=Be=>!Ee(Be)&&Be.kind==="comment",Pt=Be=>{if(!Be.length)return[];let We=(ve,qe)=>Ee(ve)?ve:ve.nodes[qe?ve.nodes.length-1:0],q=We(Be[0]),ae=We(Be[Be.length-1],!0),be=ve=>ve&&Ee(ve)&&r(ve);for(;be(q.previousSibling);)q=q.previousSibling;for(;be(ae.nextSibling);)ae=ae.nextSibling;let Re=[];for(let ve=q;ve&&(Re.push(ve),ve!==ae);ve=ve.nextSibling);return Re},cn=Be=>Be.some(We=>Ee(We)&&r(We));for(let Be of Ue){let We=se.slice(Be.lo,Be.hi+1),q=V.asBase?null:Ct(Ae,Be),ae=G.asBase?null:Ct(te,Be);if(We.some(on)||q&&q.some(on)||ae&&ae.some(on))continue;let be=Pt(q||We),Re=Pt(ae||We);if((!q||$t(We,q))&&(!ae||$t(We,ae))&&!(q&&cn(be)))continue;let ve=bo({base:Pt(We),local:be,remote:Re,out:Q,policy:Ke,blocks:he,L:q?F:Jo(F,m),R:ae?H:Jo(H,m),idOf:{local:T,remote:u},ignored:r,ignoreAttribute:n.ignoreAttribute,remoteWins:n.remoteWins,mergeElement:(tt,Rt,Ut)=>g(tt,Rt,Ut,!1),cloneUnit:we,mergeAttrs:O,atomKey:l.unitHash,moveIn:ft,provenance:ie,textMappers:me,conflicts:ot,decisions:Ie,node:D});kt.push(...ve.segments);let qe=Q.createDocumentFragment();for(let tt of ve.nodes)qe.appendChild(tt);for(let tt of[...We,...q||[],...ae||[]])Se.add(tt),de.add(tt),He.set(tt,qe);$e.push({frag:qe,at:Be.lo})}}}function yt(m,L){let R=ie.get(m);return R&&R.unchanged?!0:m.tagName!==L.tagName||!fe(m,L)?!1:Qe(ut(m),ut(L))}function ut(m){return m.tagName==="TEMPLATE"&&m.content?m.content:m}function fe(m,L){let R=0;for(let W of m.attributes)if(!n.ignoreAttribute(m,W.name)&&(R++,L.getAttribute(W.name)!==W.value))return!1;for(let W of L.attributes)n.ignoreAttribute(L,W.name)||R--;return R===0}function Qe(m,L){let R=Et(m,D=>{let V=ie.get(D);return!!(V&&V.pinned)}),W=Et(L,r);if(R.length!==W.length)return!1;for(let D=0;D<R.length;D++){let V=R[D],G=W[D];if(typeof V=="string"||typeof G=="string"){if(V!==G)return!1}else{if(V.nodeType!==G.nodeType)return!1;if(V.nodeType===1){if(!yt(V,G))return!1}else if(V.nodeValue!==G.nodeValue)return!1}}return!0}function Et(m,L){let R=[],W=null;for(let D=m.firstChild;D;D=D.nextSibling){if(D.nodeType===3){W=W===null?D.nodeValue:W+D.nodeValue;continue}D.nodeType===1&&L(D)||(W!==null&&(W!==""&&R.push(W),W=null),R.push(D))}return W!==null&&W!==""&&R.push(W),R}function wt(m,L,R,W){let D=m.value,V=W?D:L?L.value:"",G=R?R.value:"";Se.add(m),L&&Se.add(L),R&&Se.add(R);let se=V===G?V:V===D?G:G===D||Ke==="local"?V:G;if(V!==D&&G!==D&&V!==G&&w({kind:"text",node:null,base:D,local:V,remote:G,resolved:se}),!L&&!R)return null;let pe=Q.createComment(se);return ie.set(pe,{base:m.nodes,local:L?L.nodes:null,remote:R?R.nodes:null}),pe}function Bt(m,L){let R=L.map.get(m);if(!R)return null;let W=Ee(R)?R.parentNode:R.parent,D=Ee(m)?m.parentNode:m.parent;return L.map.get(D)===W?null:L.reverse.get(W)||null}function jt(m){let L=new Set([m]),R=m;for(let W=0;W<64;W++){let D=Bt(R,F)||Bt(R,H);if(!D)return!1;if(D===m||Ee(m)&&Ee(D)&&m.contains(D)||L.has(D))return!0;L.add(D),R=D}return!0}function Nt(m,L,R){if(!L)return!1;let W=Ee(m)?m.parentNode:m.parent;return W===L||L.tagName==="TEMPLATE"&&W===L.content}function St(m,L){let R=Ee(m)?m.parentNode:m.parent,W=Ee(L)?L.parentNode:L.parent;return!!(F.map.get(R)===W?F:H.map.get(R)===W?H:null)}}function Jo(e,s){return e.map.get(s)?Xo():{map:{get:n=>n&&n.nodeType===1&&e.map.get(n)||n,has:()=>!0},reverse:{get:n=>e.reverse.get(n)||n,has:()=>!0},moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}function Xo(){let e={get:s=>s,has:()=>!0};return{map:e,reverse:e,moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}var Qo=new Set(["INPUT","OPTION","TEXTAREA"]);function Zo(e,s,o,n){let r=e.ownerDocument,{provenance:l,textMappers:c}=o,f=n.hooks,d=[],M=[],N=[],y=new Set,T=[],u=[],b=new Set,x=new Map,P=i=>!!i&&(i===e||e.contains(i)||e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content.contains(i)),v=new Map,j=new Map,Y=new Map,le=new Map;(function i(k){let g=l.get(k);if(g){if(k.nodeType===1){let I=g.local?n.toLive(g.local):null;I&&P(I)&&I.nodeType===1&&(v.set(k,I),j.set(I,k))}else if(Array.isArray(g.local)){let I=F(g.local,g.local.map(O=>n.toLive(O)).filter(O=>O&&P(O)&&O.nodeType===k.nodeType));if(I.length&&(v.set(k,I[0]),j.set(I[0],k),Y.set(k,I)),Array.isArray(g.caret))for(let O of g.caret){let U=n.toLive(O.node);if(!U||!P(U)||U.nodeType!==3)continue;let S=le.get(U);Array.isArray(S)||le.set(U,S=[]),S.push({merged:k,from:O.from,to:O.to,flatStart:O.flatStart})}else{let O=0;for(let U of I)le.set(U,{merged:k,shift:O}),O+=U.nodeValue.length}}}let _=k.nodeType===1&&k.tagName==="TEMPLATE"&&k.content?k.content.childNodes:k.childNodes;for(let I of _)i(I)})(s);let Ne=new Set;for(let i of v.values())Ne.add(i);for(let i of Y.values())for(let k of i)Ne.add(k);for(let i of o.segments||[])H(i);let ye=n.restoreFocus===!1?null:fr(r,le);n.childrenOnly?Ie(Q(e),Q(s)):ie(e,s);for(let{node:i,parent:k}of T)y.has(i)||!i.parentNode||i.nodeType===1&&(n.ignored(i)||ot(i))||it(i,k);return ur(r,ye,le,c,Y,x),{applied:d,moved:M,replaced:N,identities:u,mergedScriptsLive:b,liveOf:v};function De(i,k){let g=i.slice(k.bs,k.be),_=0;for(;_<g.length&&_<k.text.length&&g[_]===k.text[_];)_++;let I=0;for(;I<g.length-_&&I<k.text.length-_&&g[g.length-1-I]===k.text[k.text.length-1-I];)I++;return{bs:k.bs+_,be:k.be-I,text:k.text.slice(_,k.text.length-I)}}function F(i,k){if(!k.length)return k;let g=new Set;for(let I of i){let O=I.parentNode;if(O)for(let U=O.firstChild;U;U=U.nextSibling)U.nodeType===3&&g.add(n.toLive(U))}let _=[];for(let I of k){_.push(I);for(let O=I.nextSibling;O&&O.nodeType===3&&!g.has(O)&&!_.includes(O);O=O.nextSibling)_.push(O)}return _}function H(i){let k=[];for(let fe of i.localNodes){let Qe=n.toLive(fe.node);if(!Qe||!P(Qe)||Qe.nodeType!==3)return;k.push(Qe)}let g=F(i.localNodes.map(fe=>fe.node),k);if(!g.length)return;let _=g.map(fe=>fe.nodeValue).join(""),{flatLocal:I,lToM:O,mapLocal:U}=i;if(_===I)return;let S=i.textNodes.map(fe=>({node:fe.node,ms:fe.ms,me:fe.me})),B=[],J=0;for(let fe of g)B.push(J),J+=fe.nodeValue.length;let ee=(fe,Qe)=>g.find((Et,wt)=>B[wt]<=fe&&fe+Qe<=B[wt]+Et.nodeValue.length)||null,we=[],et=0;for(let fe of wn(I,_).map(Qe=>De(I,Qe))){let Qe=fe.bs+et;et+=fe.text.length-(fe.be-fe.bs);let Et,wt;if(fe.be>fe.bs){Et=O[fe.bs];let Bt=Et>=0;for(let jt=fe.bs;Bt&&jt<fe.be;jt++)O[jt]!==Et+(jt-fe.bs)&&(Bt=!1);if(!Bt)continue;wt=Et+(fe.be-fe.bs)}else{let Bt=fe.bs>0?O[fe.bs-1]:0,jt=fe.bs<I.length?O[fe.bs]:0;if(Bt<0||jt<0)continue;Et=wt=U(fe.bs)}we.push({ms:Et,me:wt,text:fe.text,live:wt===Et?ee(Qe,fe.text.length):null})}we.sort((fe,Qe)=>Qe.ms-fe.ms);let yt=(fe,Qe)=>(Y.get(fe.node)||[v.get(fe.node)]).includes(Qe),ut=fe=>!!fe&&fe.nodeType===1&&nn.has(fe.tagName);for(let fe of we){let Qe=S.find(wt=>wt.ms<=fe.ms&&fe.me<=wt.me&&fe.ms<wt.me);if(Qe&&fe.live&&Qe.ms===fe.ms&&!yt(Qe,fe.live)){let wt=S.find(Bt=>Bt.me===fe.ms&&yt(Bt,fe.live));wt&&(Qe=wt)}if(!Qe&&fe.me===fe.ms){let wt=S.find(St=>St.me===fe.ms),Bt=S.find(St=>St.ms===fe.ms),jt=wt||Bt;if(!jt)continue;let Nt=jt.node;for(;ut(Nt.parentNode)&&(wt?Nt.parentNode.lastChild:Nt.parentNode.firstChild)===Nt;)Nt=Nt.parentNode;if(Nt===jt.node)Qe=jt;else{let St=Nt.ownerDocument.createTextNode(fe.text);Nt.parentNode.insertBefore(St,wt?Nt.nextSibling:Nt);continue}}if(!Qe)continue;let Et=Qe.node.nodeValue;Qe.node.nodeValue=Et.slice(0,fe.ms-Qe.ms)+fe.text+Et.slice(fe.me-Qe.ms),Qe.me+=fe.text.length-(fe.me-fe.ms)}}function Q(i){return i.nodeType===1&&i.tagName==="TEMPLATE"&&i.content?i.content:i}function ie(i,k){y.add(i);let g=l.get(k);if(g&&g.remote&&o.remoteIdOf){let I=o.remoteIdOf(g.remote);I&&u.push([i,I])}if(g&&g.unchanged){o.customIdentity&&g.remote&&at(i,g.remote),g.remote&&Se(i,g.remote);return}if(f.beforeNodeMorphed(i,k)===!1)return;oe(i,k);let _=i.tagName;if(_t(i))i.textContent!==k.textContent&&(d.push({kind:"text",node:i,before:i.textContent,after:k.textContent}),i.textContent=k.textContent),o.mergedScripts.has(k)&&b.add(i);else if(_==="TEXTAREA")ft(i,k,g);else{Xe(i,k,g);let I=_==="TEMPLATE"&&i.content?i.content:i,O=_==="TEMPLATE"&&k.content?k.content:k;n.protectFocusedValue==="subtree"&&Me(i)&&i!==r.body?me(I):Ie(I,O)}f.afterNodeMorphed(i,k)}function me(i){for(let k=i.firstChild;k;k=k.nextSibling){let g=j.get(k);g&&v.get(g.parentNode)!==i||(y.add(k),k.nodeType===1&&me(k))}}function Ie(i,k){let g=Ke(i.firstChild),_=new Set;for(let I of Array.from(k.childNodes)){let O=v.get(I);O&&y.has(O)&&!_.has(O)&&(O=null);let U=l.get(I);if(U&&U.pinned){O&&O.nodeType===1&&((O.parentNode!==i||Ke(O.nextSibling)!==g)&&ze(i,O,g),y.add(O),_.add(O));continue}if(O&&O.nodeType===1){if(O!==g){let J=O.parentNode;if(J===i&&g&&st(O)){let ee=O.nextSibling;for(let we=g;we&&we!==O;){let et=we.nextSibling;ze(i,we,ee),we=et}}else ze(i,O,g),J!==i&&(M.push(O),d.push({kind:"move",el:O,from:J,to:i}))}_.add(O),ie(O,I),g=Ke(O.nextSibling);continue}if(O&&O.nodeType!==1){let J=Y.get(I)||[O];O!==g&&ze(i,O,g);let ee=I.nodeValue;if(I.nodeType===3){let we=bt(I),et=J.map(yt=>yt.nodeValue).join("");we!=null&&et!==we&&(ee=yn(we,et,I.nodeValue).text)}f.beforeNodeMorphed(O,I)!==!1&&(O.nodeValue!==ee&&(d.push({kind:"text",node:O,before:O.nodeValue,after:ee}),O.nodeValue=ee),f.afterNodeMorphed(O,I)),y.add(O),_.add(O),x.set(I,O),g=Ke(O.nextSibling);continue}if(I.nodeType===3&&g&&g.nodeType===3&&!y.has(g)&&!le.has(g)){g.nodeValue!==I.nodeValue&&(d.push({kind:"text",node:g,before:g.nodeValue,after:I.nodeValue}),g.nodeValue=I.nodeValue),y.add(g),x.set(I,g),g=Ke(g.nextSibling);continue}let S=l.get(I),B=w(S&&S.unchanged&&S.remote?S.remote:I);f.beforeNodeAdded(B)!==!1&&(i.insertBefore(B,g),y.add(B),B.nodeType===3&&x.set(I,B),B.nodeType===1&&(N.push(B),xt(B,I),_t(B)||E(B,I),n.formState==="property"&&Je(S)&&Se(B,S.remote)),g=Ke(B.nextSibling),d.push({kind:"insert",node:B,parent:i}),f.afterNodeAdded(B))}for(let I of Array.from(i.childNodes))y.has(I)||_.has(I)||I.nodeType===1&&(n.ignored(I)||ot(I))||(Ne.has(I)?T.push({node:I,parent:i}):it(I,i))}function ot(i){return n.preserve&&i.parentNode&&i.parentNode.nodeType===1&&i.parentNode.tagName==="HEAD"&&n.preserve(i)===!0}function bt(i){let k=l.get(i);return!k||!Array.isArray(k.local)?null:k.local.map(g=>g.nodeValue).join("")}function kt(i){return l.get(i)}function Se(i,k){if(!Qo.has(i.tagName)&&!i.querySelector("input,option,textarea"))return;let g=(_,I)=>{if(_.tagName!==I.tagName)return;_.tagName==="TEXTAREA"?ft(_,I,{remote:I}):Qo.has(_.tagName)&&Xe(_,I,{remote:I});let O=Ge(_),U=Ge(I);if(O.length===U.length)for(let S=0;S<O.length;S++)g(O[S],U[S])};g(i,k)}function at(i,k){let g=Ge(i),_=Ge(k);if(g.length===_.length)for(let I=0;I<g.length;I++){let O=o.remoteIdOf(_[I]);O&&u.push([g[I],O]),at(g[I],_[I])}}function Ge(i){let k=i.tagName==="TEMPLATE"&&i.content?i.content:i;return Array.from(k.children).filter(g=>!n.ignored(g))}function xt(i,k){if(!o.remoteIdOf)return;let g=(_,I)=>{let O=l.get(I);if(O&&O.remote&&I.nodeType===1){let B=o.remoteIdOf(O.remote);B&&u.push([_,B])}let U=_.childNodes,S=I.childNodes;for(let B=0;B<U.length&&B<S.length;B++)g(U[B],S[B])};g(i,k)}function Ke(i){for(;i&&i.nodeType===1&&n.ignored(i);)i=i.nextSibling;return i}function ze(i,k,g){if(typeof i.moveBefore=="function"&&k.ownerDocument===i.ownerDocument)try{i.moveBefore(k,g);return}catch{}i.insertBefore(k,g)}function it(i,k){f.beforeNodeRemoved(i)!==!1&&(i.parentNode.removeChild(i),d.push({kind:"remove",node:i,parent:k}),f.afterNodeRemoved(i))}function w(i){if(_t(i))return Bn(i,r);let k=r.importNode(i,!0);if(k.nodeType===1)for(let g of Array.from(k.querySelectorAll("script")))_t(g)&&g.replaceWith(Bn(g,r));return k}function E(i,k){let g=i.tagName==="TEMPLATE"&&i.content?i.content:i,_=k.tagName==="TEMPLATE"&&k.content?k.content:k,I=Array.from(g.childNodes),O=Array.from(_.childNodes);for(let U=0;U<O.length&&U<I.length;U++){let S=O[U],B=I[U],J=v.get(S);J&&y.has(J)&&(J=null);let ee=l.get(S);if(ee&&ee.pinned){if(J&&J.nodeType===1){let we=J.parentNode;ze(g,J,B),we!==g&&(M.push(J),d.push({kind:"move",el:J,from:we,to:g})),y.add(J)}B.remove();continue}if(J){let we=J.parentNode;ze(g,J,B),B.remove(),J.nodeType===1?(we!==g&&(M.push(J),d.push({kind:"move",el:J,from:we,to:g})),ie(J,S)):(y.add(J),x.set(S,J),J.nodeValue!==S.nodeValue&&(d.push({kind:"text",node:J,before:J.nodeValue,after:S.nodeValue}),J.nodeValue=S.nodeValue));continue}y.add(B),B.nodeType===3&&x.set(S,B),S.nodeType===1&&!_t(S)&&E(B,S)}}function oe(i,k){for(let g of Array.from(k.attributes)){if(Z(i,g.name)||n.ignoreAttribute(i,g.name))continue;let _=g.namespaceURI?i.getAttributeNS(g.namespaceURI,g.localName):i.getAttribute(g.name);_!==g.value&&f.beforeAttributeUpdated(g.name,i,"update")!==!1&&(g.namespaceURI?i.setAttributeNS(g.namespaceURI,g.name,g.value):i.setAttribute(g.name,g.value),d.push({kind:"attr",el:i,name:g.name,before:_,after:g.value}))}for(let g of Array.from(i.attributes)){if(Z(i,g.name)||n.ignoreAttribute(i,g.name)||(g.namespaceURI?k.hasAttributeNS(g.namespaceURI,g.localName):k.hasAttribute(g.name))||f.beforeAttributeUpdated(g.name,i,"remove")===!1)continue;let I=g.value;g.namespaceURI?i.removeAttributeNS(g.namespaceURI,g.localName):i.removeAttribute(g.name),d.push({kind:"attr",el:i,name:g.name,before:I,after:null})}}function Z(i,k){let g=i.tagName;return g==="INPUT"?k==="value"||k==="checked"||k==="disabled":g==="OPTION"?k==="selected":!1}function Me(i){return i===r.activeElement}function st(i){let k=r.activeElement;return!!k&&k!==r.body&&i.contains(k)}function Je(i){let k=i&&i.remote;return k&&k.nodeType===1?k:null}function Xe(i,k,g){let _=i.tagName,I=Je(g),O=n.formState==="property"&&I?I:k;if(_==="INPUT"){let U=n.protectFocusedValue&&Me(i),S=(i.getAttribute("type")||"").toLowerCase(),B=S!=="file"&&S!=="checkbox"&&S!=="radio",J=I&&I.hasAttribute("value")&&I.value!==I.getAttribute("value")?I.value:null;if(B&&!U)if(n.formState==="property"){let ee=k.getAttribute("value"),we=i.getAttribute("value");(we!==ee||i.value!==O.value)&&f.beforeAttributeUpdated("value",i,ee==null?"remove":"update")!==!1&&(we!==ee&&(ee==null?i.removeAttribute("value"):i.setAttribute("value",ee),d.push({kind:"attr",el:i,name:"value",before:we,after:ee})),i.value!==O.value&&(i.value=O.value))}else if(k.hasAttribute("value")||J!=null){let ee=J??k.getAttribute("value");i.getAttribute("value")!==ee&&f.beforeAttributeUpdated("value",i,"update")!==!1?(i.setAttribute("value",ee),i.value!==ee&&(i.value=ee),d.push({kind:"attr",el:i,name:"value",before:null,after:ee})):i.value!==ee&&i.getAttribute("value")===ee&&(i.value=ee)}else(i.hasAttribute("value")||i.value!=="")&&f.beforeAttributeUpdated("value",i,"remove")!==!1&&(i.removeAttribute("value"),i.value="",d.push({kind:"attr",el:i,name:"value",before:"",after:null}));if(!B&&S!=="file"){let ee=k.getAttribute("value");ee==null?i.hasAttribute("value")&&f.beforeAttributeUpdated("value",i,"remove")!==!1&&i.removeAttribute("value"):i.getAttribute("value")!==ee&&f.beforeAttributeUpdated("value",i,"update")!==!1&&i.setAttribute("value",ee)}U||(nt(i,O,"checked"),n.formState==="property"&&i.indeterminate!==O.indeterminate&&(i.indeterminate=O.indeterminate)),nt(i,O,"disabled")}else if(_==="OPTION"){let U=i.parentNode&&i.closest("select");n.protectFocusedValue&&U&&Me(U)||nt(i,O,"selected")}}function nt(i,k,g){let _=n.formState==="property"?!!k[g]:k.hasAttribute(g);if(n.formState!=="property"){let I=i.hasAttribute(g);if(I!==_){if(f.beforeAttributeUpdated(g,i,_?"update":"remove")===!1)return;_?i.setAttribute(g,""):i.removeAttribute(g),d.push({kind:"attr",el:i,name:g,before:I?"":null,after:_?"":null})}}i[g]!==_&&(i[g]=_)}function ft(i,k,g){if(n.protectFocusedValue&&Me(i)||f.beforeAttributeUpdated("value",i,"update")===!1)return;let _=Je(g),I=k.textContent,O=_&&_.value!==_.defaultValue?_.value:I;n.formState!=="property"&&i.textContent!==I&&(d.push({kind:"text",node:i,before:i.textContent,after:I}),i.textContent=I),i.value!==O&&(i.value=O)}}function fr(e,s){let o=e.activeElement;if(!o||o===e.body||o===e.documentElement)return null;let n={el:o,id:o.getAttribute&&o.getAttribute("id"),scrollTop:o.scrollTop,scrollLeft:o.scrollLeft};if(o.tagName==="INPUT"||o.tagName==="TEXTAREA"){try{n.selection=[o.selectionStart,o.selectionEnd,o.selectionDirection]}catch{}return n}let r=e.getSelection&&e.getSelection();if(r&&r.rangeCount){let l=r.getRangeAt(0);n.range={sc:l.startContainer,so:l.startOffset,ec:l.endContainer,eo:l.endOffset}}return n}function ur(e,s,o,n,r,l){if(!s)return;let c=s.el;if(!c.isConnected&&s.id&&(c=e.getElementById(s.id)),!c||!c.isConnected)return;if(e.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}try{c.scrollTop=s.scrollTop,c.scrollLeft=s.scrollLeft}catch{}if(s.selection){try{c.setSelectionRange&&!c.selectionEnd&&s.selection[1]!=null&&c.setSelectionRange(s.selection[0],s.selection[1],s.selection[2]||"none")}catch{}return}if(!s.range)return;let f=(N,y)=>{let T=o.get(N);if(Array.isArray(T)){let u=T.find(v=>y>=v.from&&y<v.to)||T.find(v=>y===v.to)||T[T.length-1],b=l.get(u.merged);if(!b||!b.isConnected)return null;let x=n.get(u.merged),P=x&&x.flat?x.flat(u.flatStart+y):y;return[b,Math.max(0,Math.min(P,b.nodeValue.length))]}if(T){let u=(r.get(T.merged)||[N])[0];if(!u.isConnected)return null;let b=n.get(T.merged),x=T.shift+y,P=b?b(x):x;return[u,Math.max(0,Math.min(P,u.nodeValue.length))]}return N.isConnected?[N,Math.min(y,N.nodeType===3?N.nodeValue.length:N.childNodes.length)]:null},d=f(s.range.sc,s.range.so),M=f(s.range.ec,s.range.eo);if(!(!d||!M))try{let N=e.createRange();N.setStart(d[0],d[1]),N.setEnd(M[0],M[1]);let y=e.getSelection();y.removeAllRanges(),y.addRange(N)}catch{}}var es=Symbol("hyper-morph-duplicate-key"),ts=[e=>e.getAttribute("data-id"),e=>e.getAttribute("id")];function Pn(e,s){return s.map(o=>{let n=new Map;for(let r of e){if(r.nodeType!==1)continue;let l=o(r);l==null||l===""||n.set(l,n.has(l)?es:r)}return n})}function ns(e,s,o,n){for(let r=0;r<n.length;r++){let l=n[r](e);if(l==null||l===""||s[r].get(l)!==e)continue;let c=o[r].get(l);if(!(!c||c===es)&&c.tagName===e.tagName)return c}return null}function Sn(e,s,o){for(let n=0;n<o.length;n++){let r=o[n](e);if(!(r==null||r==="")&&s[n].get(r)===e)return!0}return!1}function os(e,s,o={}){let n=o.skip||(()=>!1),r=o.ignoreAttr||(()=>!1),l=o.tiers&&o.tiers.length?o.tiers:ts,c=null;function f(){return c||(c=Pn([e,...e.querySelectorAll("*")],l)),c}let d=null;function M(){return d||(d=Pn([s,...s.querySelectorAll("*")],l)),d}function N(H){return!H.parentElement||!H.parentElement.parentElement}function y(H,Q,ie){return N(H)||Sn(H,f(),l)?(ie.push({type:"subtree",el:H,base:Q}),!1):!0}function T(H,Q){let ie=[];for(let me of H.attributes)r(H,me.name)||Q.getAttribute(me.name)!==me.value&&ie.push(me.name);for(let me of Q.attributes)r(H,me.name)||H.hasAttribute(me.name)||ie.push(me.name);return ie}function u(H){let Q=[],ie=null,me=()=>{ie!==null&&(Q.push({nodeType:3,nodeValue:ie}),ie=null)};for(let Ie of H.childNodes){if(Ie.nodeType===3){ie=(ie===null?"":ie)+Ie.nodeValue;continue}Ie.nodeType===1&&n(Ie)||(me(),(Ie.nodeType===1||Ie.nodeType===8)&&Q.push(Ie))}return me(),Q}function b(H,Q){if(H.nodeType!==Q.nodeType)return!1;if(H.nodeType!==1)return!0;if(H.tagName!==Q.tagName)return!1;for(let ie of l){let me=ie(H),Ie=ie(Q);if(me!=null&&me!==""&&Ie!=null&&Ie!==""&&me!==Ie)return!1}return!0}function x(H){let Q="";for(let ie of H)ie.nodeType===3&&ie.nodeValue.trim()!==""?Q+="\0"+ie.nodeValue:ie.nodeType===8&&(Q+=""+ie.nodeValue);return Q}function P(H,Q,ie){let me=u(H),Ie=u(Q);if(me.length===Ie.length){let E=!0;for(let oe=0;oe<me.length;oe++)if(!b(me[oe],Ie[oe])){E=!1;break}if(E){for(let oe=0;oe<me.length;oe++){let Z=me[oe];if(Z.nodeType===1){if(v(Z,Ie[oe],ie))return!0}else if(Z.nodeValue!==Ie[oe].nodeValue)return!0}return!1}}let ot=me.filter(E=>E.nodeType===1),bt=Ie.filter(E=>E.nodeType===1);if(x(me)!==x(Ie))return!0;let kt=Pn(ot,l),Se=Pn(bt,l),at=[],Ge=new Set,xt=[];for(let E of ot){let oe=ns(E,kt,Se,l);oe&&!Ge.has(oe)?(at.push([E,oe]),Ge.add(oe)):xt.push(E)}let Ke=[];for(let E of xt)Sn(E,kt,l)?ie.push({type:"subtree",el:E,base:null}):Ke.push(E);let ze=[];for(let E of bt)Ge.has(E)||(Sn(E,Se,l)?ie.push({type:"deletion",el:E}):ze.push(E));if(Ke.length!==ze.length)return!0;for(let E=0;E<Ke.length;E++)if(!b(Ke[E],ze[E]))return!0;let it=new Map(at);for(let E=0;E<Ke.length;E++)it.set(Ke[E],ze[E]);let w=-1;for(let E of ot){let oe=it.get(E);if(!oe)continue;let Z=bt.indexOf(oe);if(Z<w)return!0;w=Z}for(let E=0;E<Ke.length;E++)if(v(Ke[E],ze[E],ie))return!0;for(let[E,oe]of at)if(v(E,oe,ie))return!0;return!1}function v(H,Q,ie){if(H.tagName!==Q.tagName)return y(H,Q,ie);let me=T(H,Q),Ie=[];if(P(H,Q,Ie))return y(H,Q,ie);if(me.length){if(!N(H)&&!Sn(Q,M(),l))return!0;ie.push({type:"attrs",el:H,names:me,base:Q})}return ie.push(...Ie),!1}let j=[],Y=T(e,s);Y.length&&j.push({type:"attrs",el:e,names:Y});let le=(H,Q)=>Array.from(H.children).find(ie=>ie.tagName===Q)||null,Ne=le(e,"HEAD"),ye=le(s,"HEAD");if(Ne&&ye){let H=[];v(Ne,ye,H),H.length&&j.push({type:"head",el:Ne})}else(Ne||ye)&&Ne&&j.push({type:"head",el:Ne});let De=le(e,"BODY"),F=le(s,"BODY");return De&&F?v(De,F,j):De&&j.push({type:"subtree",el:De,base:null}),{entries:j}}function ss(e,s,o={}){let n=o.tiers&&o.tiers.length?o.tiers:ts,r=e.documentElement,l=[],c=0,f=v=>({ok:!1,placed:l,held:v,skippedAttrs:c});if(!r)return f(null);function d(v){let j=[v,...v.querySelectorAll("*")];return Pn(j,n)}let M=d(r),N=new Map,y=v=>{let j=v.getRootNode(),Y=N.get(j);if(!Y){let le=j.nodeType===9?j.documentElement:j;Y=d(le),N.set(j,Y)}return Y};function T(v){if(!v.parentElement&&v.tagName==="HTML")return r;if(v.parentElement&&!v.parentElement.parentElement&&v.parentElement.tagName==="HTML"){if(v.tagName==="BODY")return e.body||null;if(v.tagName==="HEAD")return e.head||null}return null}function u(v){let j=T(v);return j||ns(v,y(v),M,n)}function b(v){if(!v)return null;let j=u(v);return j&&j.isConnected?j:null}function x(v){for(let j=0;j<n.length;j++){let Y=n[j](v);Y!=null&&Y!==""&&M[j].set(Y,v)}}for(let v of s){if(v.type!=="deletion")continue;let j=u(v.el);j&&j!==r&&j.remove()}let P=s.filter(v=>v.type!=="deletion").sort((v,j)=>v.el===j.el?0:v.el.compareDocumentPosition(j.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let v of P){if(v.type==="head"){let F=e.importNode(v.el,!0);e.head?e.head.replaceWith(F):r.insertBefore(F,r.firstChild),l.push({entry:v,imported:F});continue}if(v.type==="attrs"){let F=b(v.el)||b(v.base);if(!F){c++;continue}for(let H of v.names)v.el.hasAttribute(H)?F.setAttribute(H,v.el.getAttribute(H)):F.removeAttribute(H);continue}let j=v.el;if(T(j))return f(v);let Y=b(j)||b(v.base);if(Y){let F=e.importNode(j,!0);Y.replaceWith(F),x(F),l.push({entry:v,imported:F});continue}if(v.base!=null&&!Sn(v.base,y(v.base),n)||!Sn(j,y(j),n))return f(v);let le=j.parentElement;if(!le)return f(v);let Ne=b(le);if(!Ne)return f(v);let ye=null;for(let F=j.previousElementSibling;F;F=F.previousElementSibling){let H=b(F);if(H&&H.parentNode===Ne){ye=H;break}}let De=e.importNode(j,!0);if(ye)Ne.insertBefore(De,ye.nextSibling);else{let F=Array.prototype.indexOf.call(le.children,j);Ne.insertBefore(De,Ne.children[F]||null)}x(De),l.push({entry:v,imported:De})}return{ok:!0,placed:l,held:null,skippedAttrs:c}}var dr='[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"]',hr='[editor-ui],[clay~="editor-ui"],[no-undo],[clay~="no-undo"]',pr='[no-undo]:not([editor-ui]):not([clay~="editor-ui"]),[clay~="no-undo"]:not([editor-ui]):not([clay~="editor-ui"])';function mr(e){if(e.tagName!=="LINK"&&e.tagName!=="SCRIPT")return!1;let s=e.getAttribute("src")||e.getAttribute("href")||"";return/^(chrome|moz|safari-web)-extension:/.test(s)}function gr(e,s,o,n){if(s==null)return;if(typeof s=="string")return s;let r=s;if(r.nodeType===9){let l=e.getAttribute("id");r=l&&r.getElementById(l)||(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=br(e,s,n)),!!r)return o?Array.from(r.childNodes):r}function br(e,s,o){let n=s.nodeType===9?s.documentElement:s;if(!n||n.nodeType!==1)return null;let r=new Map,l=[n,...n.querySelectorAll("script")];for(let d of l){let M=xn(d,o);M&&!r.has(M.key)&&r.set(M.key,d.textContent)}if(!r.size)return null;let c=e.cloneNode(!0),f=!1;for(let d of[c,...c.querySelectorAll("script")]){let M=xn(d,o);M&&r.has(M.key)&&(d.textContent=r.get(M.key),f=!0)}return f?c:null}function rs(e,s){if(typeof e=="string"||e.nodeType===9)return e;if(e.nodeType===1&&e===e.ownerDocument.documentElement)return e.ownerDocument;let o=s.implementation.createHTMLDocument(""),n=e.nodeType===1&&e.tagName==="HTML"?e:null;if(n)return o.replaceChild(o.adoptNode(n),o.documentElement),o;let r=e.nodeType===11?Array.from(e.childNodes):e.nodeType?[e]:Array.from(e);for(let l of r)o.body.appendChild(o.adoptNode(l));return o}function eo(e,s,o={}){let n=o||{};if(!n.head?.block)return is(e,s,n);try{return is(e,s,n)}catch(r){return Promise.reject(r)}}function is(e,s,o){let n=o.policy||"sync",r=n==="raw"?void 0:(d,M)=>mr(d)||(n==="history"?!(M&&d.matches(pr))&&d.matches(hr):d.matches(dr)),l=o.callbacks||{},c={ignore:r,hooks:l,protectFocusedValue:o.ignoreActiveValue===!0?"subtree":!1,restoreFocus:o.restoreFocus!==!1,formState:o.formStateSync||"attribute",scripts:{execute:o.scripts?.handle!==!1,merge:o.scripts?.merge!==!1,mergeTags:o.scripts?.mergeTags||[]},head:{awaitLoads:!!o.head?.block,preserve:o.head?.shouldPreserve||(()=>!1)}};if(typeof o.key=="function"&&(c.identity={base:o.key,local:o.key,remote:o.key}),e&&e.nodeType===9)return vn(Object.assign({},c,{live:e,base:o.scripts?.mergeBase||null,remote:rs(s,e)}));if(e.tagName==="HTML"&&e.parentNode&&e.parentNode.nodeType===9){let d=Object.assign({},c,{live:e.ownerDocument,base:o.scripts?.mergeBase||null,remote:rs(s,e.ownerDocument)});return vn(d)}o.morphStyle==="innerHTML"&&(c.children=!0);let f=gr(e,o.scripts?.mergeBase,!!c.children,c.scripts.mergeTags);return f!==void 0&&(c.base=f),to(e,s,c)}var kr=new Set(["live","base","remote","local","identity","ignore","remoteWins","ignoreAttribute","conflicts","protectFocusedValue","restoreFocus","head","scripts","formState","children","hooks","beforeApply"]),en=()=>{};function Un(e,s=[]){if(!e||typeof e!="object")throw new TypeError("options object required");for(let c of Object.keys(e))if(!kr.has(c))throw new TypeError(`unknown option "${c}"`);let o=Object.assign({beforeNodeAdded:en,afterNodeAdded:en,beforeNodeRemoved:en,afterNodeRemoved:en,beforeNodeMorphed:en,afterNodeMorphed:en,beforeAttributeUpdated:en},e.hooks||{}),n=e.conflicts||"remote";if(!["remote","local","both"].includes(n))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 l=e.protectFocusedValue;if(l!==void 0&&typeof l!="boolean"&&l!=="subtree")throw new TypeError('protectFocusedValue must be a boolean or "subtree"');return{ignored:oo(e.ignore,s),remoteWins:oo(e.remoteWins,s),ignoreAttribute:typeof e.ignoreAttribute=="function"?e.ignoreAttribute:()=>!1,conflicts:n,protectFocusedValue:l===void 0?!0:l,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:o,children:!!e.children,beforeApply:typeof e.beforeApply=="function"?e.beforeApply:null}}function Mn(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 un}function In(e,s){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){let o=qn(s,e.map),n=typeof e.then=="function"?e.then:un;if(typeof e.first=="function"){let r=e.first;return l=>r(l)||o.get(l)||n(l)}return r=>o.get(r)||n(r)}return un}function as(e,s,o,n={}){let r=y=>y&&y.nodeType===9?y.documentElement:y,l=r(s),c=r(o),f=r(e)||l,d=Object.assign({},n);delete d.live,delete d.base,delete d.remote;let M=Un(d,[f,l,c].filter(Boolean)),N=n.identity||{};return wo(f,l,c,{identity:{base:In(N.base,f),local:In(N.local,l),remote:In(N.remote,c)},authored:{base:Mn(N.base),local:Mn(N.local),remote:Mn(N.remote)},skipUnchanged:M.hooks.beforeNodeMorphed===en&&M.hooks.afterNodeMorphed===en,ignored:M.ignored,remoteWins:M.remoteWins,ignoreAttribute:M.ignoreAttribute,conflicts:M.conflicts,mergeTags:M.scripts.merge===!1?null:M.scripts.mergeTags,baseURI:l.ownerDocument&&l.ownerDocument.baseURI||"about:blank",localIsBase:!e||e===s,childrenOnly:M.children})}function Ao({liveRoot:e,baseRoot:s,localRoot:o,remoteRoot:n,toLive:r,options:l,identity:c,childrenOnly:f,isDocument:d}){let M=Un(l,[e,s,o,n].filter(Boolean));if(M.ignored(e))return{report:To(),loads:[]};let N=e.ownerDocument,y=M.scripts.execute?Vo(e,M.ignored,N.baseURI):null,T=wo(s||o,o,n,{identity:{base:In(c.base,s||o),local:In(c.local,o),remote:In(c.remote,n)},authored:{base:Mn(c.base),local:Mn(c.local),remote:Mn(c.remote)},ignored:M.ignored,remoteWins:M.remoteWins,ignoreAttribute:M.ignoreAttribute,conflicts:M.conflicts,mergeTags:M.scripts.merge===!1?null:M.scripts.mergeTags,baseURI:N.baseURI,localIsBase:!s,childrenOnly:f,skipUnchanged:M.hooks.beforeNodeMorphed===en&&M.hooks.afterNodeMorphed===en});M.beforeApply&&M.beforeApply(T.doc);let u=globalThis.__hyperMorphProfile,b=u?performance.now():0,x=Zo(e,T.root,T,{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:f});u&&(u.apply=(u.apply||0)+(performance.now()-b));let P=[];if(M.head.awaitLoads)for(let Y of x.applied){if(Y.kind!=="insert"||Y.node.nodeType!==1)continue;let le=Y.node;le.tagName==="LINK"&&/\bstylesheet\b/i.test(le.getAttribute("rel")||"")&&le.getAttribute("href")&&le.closest("head")&&P.push(new Promise(ye=>{le.addEventListener("load",()=>ye()),le.addEventListener("error",()=>ye())}))}if(y){let Y=Wo(e,y,{ignored:M.ignored,skip:x.mergedScriptsLive,baseURI:N.baseURI,beforeNodeAdded:M.hooks.beforeNodeAdded,afterNodeAdded:M.hooks.afterNodeAdded});P.push(...Y.loads)}let v=Y=>Y&&x.liveOf&&x.liveOf.get(Y)||null;return{report:{applied:x.applied,decisions:T.decisions.map(Y=>Object.assign({},Y,{node:Y.node?v(Y.node):null,el:Y.el?v(Y.el):null,applied:!!(Y.node?v(Y.node):Y.el&&v(Y.el))})),conflicts:T.conflicts.map(Y=>Object.assign({},Y,{node:Y.node?v(Y.node):Y.node,el:Y.el?v(Y.el):Y.el})),localDiverged:T.localDiverged,identities:x.identities,moved:x.moved,replaced:x.replaced},loads:P}}var cs=new WeakMap;function To(){return{applied:[],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[]}}function vn(e){let s=e||{},o=s.live;if(!o||o.nodeType!==9)throw new TypeError("live must be a Document");let n=cs.get(o);n||(n=zn(o),cs.set(o,n));let r=n("remote",s.remote),l=typeof s.base=="string"&&s.base===""?null:s.base,c=l?n("base",l):null,f=s.local?s.local.root:o.documentElement,d=s.local?s.local.toLive:y=>y;So(o,r);let{report:M,loads:N}=Ao({liveRoot:o.documentElement,baseRoot:c?c.documentElement:null,localRoot:f,remoteRoot:r.documentElement,toLive:d,options:s,identity:s.identity||{},childrenOnly:!1,isDocument:!0});return Promise.all(N).then(()=>M)}function fs(e,s,o={}){return vn(Object.assign({},o,{live:e,base:null,remote:s}))}function ls(e,s){if(e==null)return{root:s.createElement("template"),first:null};if(typeof e=="string"){let n=/^\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype[^>]*>\s*)?<(html|body)[\s>]/i.exec(e);if(n){let l=Kn(e,s),c=n[1].toLowerCase()==="html"?l.documentElement:l.body;return{root:c,first:c}}let r=s.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 n=s.createElement("template"),r=e.isConnected;return n.content.appendChild(r?s.importNode(e,!0):e),{root:n,first:e}}if(e.nodeType===11){let n=s.createElement("template");return n.content.appendChild(e),{root:n,first:n.content.firstElementChild}}let o=s.createElement("template");for(let n of Array.from(e))o.content.appendChild(n.parentNode?s.importNode(n,!0):n);return{root:o,first:o.content.firstElementChild}}function to(e,s,o={}){if(!e||e.nodeType!==1)throw new TypeError("oldEl must be an Element");let n=e.ownerDocument,{base:r,...l}=o,c=!!l.children;if(Un(l,[e]).ignored(e))return Promise.resolve(To());let f=ls(s,n),d=r!=null?ls(r,n):null,M,N=null;if(c)M=f.root,N=d?d.root:null;else{if(M=f.first,N=d?d.first:null,!M){let u=Un(l);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(M.tagName!==e.tagName){let u=Un(l,[e,M]);if(u.hooks.beforeNodeMorphed(e,M)===!1)return Promise.resolve(To());let b=Ao({liveRoot:e,baseRoot:N&&N.tagName===e.tagName?N:null,localRoot:e,remoteRoot:M,toLive:P=>P,options:l,identity:l.identity||{},childrenOnly:!0,isDocument:!1}),x=_t(M)?Bn(M,n):n.importNode(M,!1);if(!_t(x))for(;e.firstChild;)x.appendChild(e.firstChild);return u.hooks.beforeNodeAdded(x)===!1||u.hooks.beforeNodeRemoved(e)===!1?Promise.resolve(b.report):(e.replaceWith(x),u.hooks.afterNodeRemoved(e),u.hooks.afterNodeAdded(x),u.hooks.afterNodeMorphed(e,M),b.report.replaced.push(x),b.report.applied.push({kind:"insert",node:x,parent:x.parentNode},{kind:"remove",node:e,parent:x.parentNode}),Promise.all(b.loads).then(()=>b.report))}}let{report:y,loads:T}=Ao({liveRoot:e,baseRoot:N,localRoot:e,remoteRoot:M,toLive:u=>u,options:l,identity:l.identity||{},childrenOnly:c,isDocument:!1});return Promise.all(T).then(()=>y)}var yr={mergeDocument:vn,morphDocument:fs,morphElement:to,merge3:as,morph:eo};return ys(wr);})();
|
|
1
|
+
var HyperMorph=(()=>{var no=Object.defineProperty;var ps=Object.getOwnPropertyDescriptor;var ms=Object.getOwnPropertyNames;var gs=Object.prototype.hasOwnProperty;var bs=(e,s)=>{for(var o in s)no(e,o,{get:s[o],enumerable:!0})},ks=(e,s,o,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of ms(s))!gs.call(e,r)&&r!==o&&no(e,r,{get:()=>s[r],enumerable:!(n=ps(s,r))||n.enumerable});return e};var ys=e=>ks(no({},"__esModule",{value:!0}),e);var wr={};bs(wr,{createIdentityStore:()=>Mo,createParseCache:()=>zn,default:()=>yr,diff:()=>An,findChangedRoots:()=>os,importMap:()=>qn,merge3:()=>as,merge3Text:()=>wn,mergeDocument:()=>Mn,mergeJson:()=>wo,mergeScriptText:()=>Zn,morph:()=>eo,morphDocument:()=>fs,morphElement:()=>to,parseJsonRelaxed:()=>Xn,parseRulesRelaxed:()=>zo,spliceProtected:()=>ss,tieredIdentity:()=>so});function Kn(e,s){if(typeof e=="string"){let o=s&&s.defaultView,n=o&&o.DOMParser||globalThis.DOMParser;return new n().parseFromString(e,"text/html")}if(e&&e.nodeType===9)return e;throw new TypeError("expected an HTML string or a Document")}function zn(e){let s=new Map;return(o,n)=>{if(typeof n!="string")return Kn(n,e);let r=s.get(o);if(r&&r.text===n)return r.doc;let l=Kn(n,e);return s.set(o,{text:n,doc:l}),l}}function vo(e,s){let o=s.doctype;if(!o)return!1;let n=e.doctype;if(n&&n.name===o.name&&n.publicId===o.publicId&&n.systemId===o.systemId)return!1;let r=e.implementation.createDocumentType(o.name,o.publicId,o.systemId);return n?e.replaceChild(r,n):e.insertBefore(r,e.documentElement),!0}function oo(e,s=[]){if(typeof e!="function")return()=>!1;let o=new WeakMap,n=new Set(s);return r=>{if(!r||r.nodeType!==1)return!1;let l=o.get(r);if(l!==void 0)return l;let c=[],f=r,u=!1;for(;f&&f.nodeType===1;){let v=o.get(f);if(v!==void 0){u=v;break}if(c.push(f),e(f,n.has(f))){u=!0;break}if(n.has(f))break;f=f.parentElement}for(let v of c)o.set(v,u);return u}}function Mo(e){let s=new WeakMap,o=0,n=f=>s.get(f)||null,r=f=>{let u=s.get(f);return u||(u=`${e}:${++o}`,s.set(f,u)),u};return{idOf:n,ensure:r,adopt:(f,u)=>{f&&typeof u=="string"&&u&&s.set(f,u)},exportMap:(f,u)=>{let v={},N=[],A=[],T=(p,h)=>{let x=u(p);x&&(v[h]=r(x));let R=p.children;N.push(R.length),A.push(p.tagName.toLowerCase());for(let M=0;M<R.length;M++)T(R[M],h===""?String(M):`${h}.${M}`)};return T(f,""),v["~"]=N.join(","),v["^"]=A.join(","),v}}}function qn(e,s){let o=new WeakMap;if(!e||!s||typeof s!="object"||Array.isArray(s))return o;let n=s["~"],r=typeof n=="string"?n.split(",").map(Number):null,l=r&&typeof s["^"]=="string"?s["^"].split(","):null,c=A=>Number.isInteger(A)&&A>=0,f=0,u=!1,v=A=>{let T=A;for(;T>0;){let p=r[f++];if(f>r.length||!c(p))return!1;T+=p-1}return!0},N=(A,T)=>{if(u)return;if(r){let x=f++,R=r[x];if(x>=r.length||!c(R)){u=!0;return}let M=!l||l[x]===A.tagName.toLowerCase();if(!M||R!==A.children.length){let D=M&&s[T];typeof D=="string"&&D&&o.set(A,D),v(R)||(u=!0);return}}let p=s[T];typeof p=="string"&&p&&o.set(A,p);let h=A.children;for(let x=0;x<h.length;x++)N(h[x],T===""?String(x):`${T}.${x}`)};return N(e,""),o}function so(e){return s=>{for(let o of e){let n=o(s);if(typeof n=="string"&&n!=="")return n}return null}}var dn=so([e=>e.getAttribute("data-id"),e=>e.getAttribute("id")]);function Gn(e,s,o,n=null){let r=new Map,l=new Set,c=f=>{if(o(f))return;let u=s(f);u&&(r.has(u)?l.add(u):r.set(u,f))};if(n){let f=u=>{for(let v of u.querySelectorAll(n))c(v);for(let v of u.querySelectorAll("template"))v.content&&f(v.content)};c(e),f(e.tagName==="TEMPLATE"&&e.content?e.content:e)}else{let f=u=>{c(u);let v=u.tagName==="TEMPLATE"&&u.content?u.content.children:u.children;for(let N=0;N<v.length;N++)f(v[N])};f(e)}for(let f of l)r.delete(f),f.startsWith("merge:")&&console.warn(`[hyper-morph] merge disabled for duplicate identity "${f.slice(f.indexOf(":",6)+1)}"`);return r}var ws=new Set(["href","src","name","type","role"]),Oo=new Set(["SCRIPT","STYLE","TEXTAREA","TEMPLATE","IFRAME","OBJECT","CANVAS","VIDEO","AUDIO","svg","SVG"]);function bn(e,s=5381){let o=s;for(let n=0;n<e.length;n++)o=(o<<5)+o^e.charCodeAt(n);return o>>>0}function Io(e){return e.replace(/\s+/g," ")}function Lo({ignored:e=()=>!1,ignoreAttribute:s=()=>!1}={}){let o=new WeakMap,n=new WeakMap;function r(T){let p=T.attributes,h=p.length;if(h===0)return{all:"",sig:T.tagName+"|"};let x=[],R="",M=[];for(let D=0;D<h;D++){let K=p[D],ie=K.name;s(T,ie)||x.push(ie+"="+K.value),ie==="class"?R=K.value.indexOf(" ")<0?K.value:K.value.split(/\s+/).filter(Boolean).sort().join(" "):ws.has(ie)&&M.push(ie+"="+K.value)}return x.length>1&&x.sort(),M.length>1&&M.sort(),{all:x.join(""),sig:T.tagName+"|"+R+(M.length?"|"+M.join("|"):"")}}function l(T){return T.nodeType===1&&T.tagName==="TEMPLATE"&&T.content?T.content.childNodes:T.childNodes}function c(T){let p=o.get(T);if(p)return p;if(T.nodeType===3)p={hash:"T"+bn(T.nodeValue),hint:Io(T.nodeValue).slice(0,64),sig:null,tok:null};else if(T.nodeType===8)p={hash:"C"+bn(T.nodeValue),hint:"",sig:null,tok:null};else if(T.nodeType===1){let h=r(T),x=bn(T.tagName+""+h.all),R="";for(let M of u(T))if(M.nodeType===1){let D=c(M);x=bn(D.hash,x),R.length<64&&(R+=" "+D.hint)}else x=bn(v(M),x),M.kind==="text"&&R.length<64&&(R+=M.value.slice(0,64));p={hash:"E"+x,hint:Io(R).trim().slice(0,64),sig:h.sig,tok:null}}else p={hash:"N"+T.nodeType,hint:"",sig:null,tok:null};return o.set(T,p),p}function f(T){if(!T.tok){T.tok=new Set;for(let p of T.hint.toLowerCase().split(/[^\p{L}\p{N}]+/u))p&&T.tok.add(p)}return T.tok}function u(T){let p=n.get(T);if(p)return p;p=[];let h=null,x=()=>{h&&(h.value=h.nodes.map(R=>R.nodeValue).join(""),p.push(h),h=null)};for(let R of l(T)){if(R.nodeType===3){h||(h={kind:"text",nodes:[],value:"",parent:T,hash:void 0}),h.nodes.push(R);continue}x(),R.nodeType===8?p.push({kind:"comment",nodes:[R],value:R.nodeValue,parent:T,hash:void 0}):R.nodeType===1&&!e(R)&&p.push(R)}return x(),n.set(T,p),p}function v(T){return T.nodeType===1?c(T).hash:(T.hash===void 0&&(T.hash=(T.kind==="text"?"T":"C")+bn(T.value)),T.hash)}function N(T,p){let h=f(c(T)),x=f(c(p));if(h.size===0&&x.size===0)return{coef:1,share:1};if(h.size===0||x.size===0)return null;let R=0;for(let M of h)x.has(M)&&R++;return{coef:R/Math.min(h.size,x.size),share:R/Math.max(h.size,x.size)}}function A(T,p){let h=N(T,p);return!!h&&h.coef>=.5}return{meta:c,unitsOf:u,unitHash:v,similar:A,score:N,childrenOf:l}}var Co=16,As=2e3,Ts=3,xs={align:0};function ro(e,s,o){let{meta:n,unitsOf:r,unitHash:l,similar:c,score:f}=o.analyzer,u=o.baseId||(()=>null),v=o.sideId||(()=>null),N=new Map,A=new Map,T=new Set,p=new Map,h=new Set,x=new Set,R=new Set,M=[],D=[],K=[],ie=[],ge=As,Me=new Map,Ae=new Map,_=(i,k)=>{N.set(i,k),A.set(k,i)},C=i=>!!i&&i.nodeType===1,fe=(i,k)=>{let b=p.get(i);return!!b&&b.has(k)},J=i=>Oo.has(i.tagName),he=(i,k)=>{let b=u(i);if(!b)return!0;let V=v(k);return!V||b===V},Se=globalThis.__hyperMorphProfile,ct=Se?performance.now():0;Se&&(n(e),n(s),Se.meta=(Se.meta||0)+(performance.now()-ct),ct=performance.now()),_(e,s);for(let[i,k]of o.baseIndex){let b=o.sideIndex.get(i);b&&b.tagName===k.tagName&&!N.has(k)&&!A.has(b)&&_(k,b)}ie.push([e,s]);for(let[i,k]of N)C(i)&&i!==e&&ie.push([i,k]);return We(),ot(),Se&&(Se.align=(Se.align||0)+(performance.now()-ct)),{map:N,reverse:A,moved:h,identical:x,pairIdenticalChildren:H,weak:T,unpair:lt,rematch:ot,insertedByHash:oe};function ot(){ht(),We();for(let i=0;i<K.length;){let k=K.length;ze(i,k),i=k,We(),ht(),We()}}function lt(i){let k=N.get(i);if(!k)return;p.has(i)||p.set(i,new Set),p.get(i).add(k);let b=(I,O)=>{N.delete(I),A.delete(O),h.delete(I),x.delete(I),T.delete(I),R.delete(I)},V=(I,O)=>{for(let j of r(I)){let S=N.get(j);!S||!(C(S)?O.contains(S):O.contains(S.nodes[0]))||(b(j,S),C(j)&&V(j,S))}};b(i,k),C(i)&&V(i,k),M.push(i),D.push(k)}function oe(){let i=new Map;for(let k of new Set(D)){if(A.has(k))continue;let b=n(k).hash;i.has(b)||i.set(b,[]),i.get(b).push(k)}return i}function We(){for(;ie.length;){let[i,k]=ie.shift();R.has(i)||x.has(i)||dt(i,k)}}function Fe(i,k){if(!J(i))for(let b of r(i))C(b)&&(k.push(b),Fe(b,k))}function dt(i,k){R.add(i);let b=r(i),V=r(k);xs.align+=b.length+V.length,Me=new Map,Ae=new Map;for(let P=0;P<b.length;P++)Me.set(b[P],P);for(let P=0;P<V.length;P++)Ae.set(V[P],P);if(i.tagName==="HTML")for(let P of["HEAD","BODY"]){let X=b.find(Te=>C(Te)&&Te.tagName===P),ee=V.find(Te=>C(Te)&&Te.tagName===P);X&&ee&&!N.has(X)&&!A.has(ee)&&_(X,ee)}for(let P=0;P<b.length&&P<V.length;P++){let X=b[P],ee=V[P];N.has(X)||A.has(ee)||(C(X)?C(ee)&&X.tagName===ee.tagName&&X.isEqualNode(ee)&&y(X,ee):!C(ee)&&X.kind===ee.kind&&X.value===ee.value&&y(X,ee))}st(b,V);let I=b.filter(P=>!N.has(P)),O=V.filter(P=>!A.has(P));I.length&&O.length&&(at(I,O),se(I,O),Z(I,O,b,V),Xe(b,V));let j=!1,S=!1;for(let P of b){if(!N.has(P)){C(P)&&(M.push(P),Fe(P,M),j=!0);continue}C(P)&&!x.has(P)&&ie.push([P,N.get(P)])}for(let P of V)!A.has(P)&&C(P)&&(D.push(P),Fe(P,D),S=!0);j&&S&&K.push([i,k])}function ze(i,k){for(let b=i;b<k;b++){let[V,I]=K[b],O=r(V),j=r(I),S=new Map,P=new Map,X=null;for(let ee of O)C(ee)&&(N.has(ee)?X=ee:(S.has(X)||S.set(X,[]),S.get(X).push(ee)));X=null;for(let ee of j)C(ee)&&(A.has(ee)?X=A.get(ee):(P.has(X)||P.set(X,[]),P.get(X).push(ee)));for(let[ee,Te]of S){let tt=P.get(ee);if(!(!tt||Te.length!==tt.length)&&Te.every((wt,pt)=>tt[pt].tagName===wt.tagName&&he(wt,tt[pt])&&!fe(wt,tt[pt])))for(let wt=0;wt<Te.length;wt++)Ge(Te[wt],tt[wt])}}}function Ge(i,k){_(i,k),T.add(i),ie.push([i,k]),We()}function at(i,k){let b=kn(i,l),V=kn(k,l),I=new Map;for(let O of k){let j=l(O);V.get(j)===1&&I.set(j,O)}for(let O of i){if(N.has(O))continue;let j=l(O);if(b.get(j)!==1)continue;let S=I.get(j);S&&!A.has(S)&&y(O,S)}}function y(i,k){_(i,k),x.add(i),C(i)&&R.add(i)}function H(i){let k=N.get(i);if(!k||!C(i))return;let b=r(i),V=r(k);for(let I=0;I<b.length&&I<V.length;I++)N.has(b[I])||y(b[I],V[I])}function se(i,k){let b=j=>C(j)&&!J(j)?n(j).sig+""+n(j).hint:null,V=kn(i,b),I=kn(k,b),O=new Map;for(let j of k){let S=b(j);S!=null&&I.get(S)===1&&O.set(S,j)}for(let j of i){if(N.has(j))continue;let S=b(j);if(S==null||V.get(S)!==1)continue;let P=O.get(S);P&&!A.has(P)&&he(j,P)&&_(j,P)}}function Z(i,k,b,V){let I=new Map;for(let j of k){if(!C(j)||A.has(j)||J(j))continue;let S=n(j).sig;I.has(S)||I.set(S,[]),I.get(S).push({el:j,index:Ae.get(j)})}let O=[];for(let j of i){if(N.has(j)||!C(j)||J(j))continue;let S=I.get(n(j).sig);if(!S||!S.length)continue;let P=Me.get(j),X=S.filter(ee=>!A.has(ee.el)).map(ee=>({c:ee,d:Math.abs(ee.index-P)}));X.sort((ee,Te)=>ee.d-Te.d),X.length>Co&&(X=X.slice(0,Co));for(let{c:ee,d:Te}of X){if(!he(j,ee.el))continue;let tt=f(j,ee.el);tt&&tt.coef>=.5&&O.push({b:j,s:ee.el,coef:tt.coef,share:tt.share,d:Te,bi:P})}}O.sort((j,S)=>S.coef-j.coef||S.share-j.share||j.d-S.d||j.bi-S.bi);for(let j of O)!N.has(j.b)&&!A.has(j.s)&&_(j.b,j.s)}function Oe(i,k){return C(i)!==C(k)?!1:C(i)?i.tagName!==k.tagName||!he(i,k)?!1:J(i)||n(i).hint===""||n(k).hint===""?!0:c(i,k):i.kind===k.kind}function rt(i,k){let b=(I,O)=>{let j=O===null?-1:I===k?Ae.get(O):Me.get(O),S=I[j+1];return S&&!C(S)?S:null},V=null;for(let I of i){if(C(I)){V=I;continue}if(N.has(I))continue;let O=V===null?null:N.get(V);if(V!==null&&!O)continue;let j=b(k,O);j&&!A.has(j)&&j.kind===I.kind&&_(I,j)}}function Xe(i,k){rt(i,k);let b=Qe(i,k),V=(O,j)=>C(O)&&n(O).hint!==""&&n(j).hint===""&&!!j.querySelector("br")&&!b(O,j),I=0;for(let O of i){if(N.has(O)){let S=Ae.get(N.get(O));S!==void 0&&S>=I&&(I=S+1);continue}let j=0;for(let S=I;S<k.length&&j<Ts;S++){let P=k[S];if(!A.has(P)&&(j++,Oe(O,P)&&!fe(O,P)&&!V(O,P))){_(O,P),C(O)&&(n(O).hint===""||n(P).hint==="")&&T.add(O),I=S+1;break}}}st(i,k)}function Qe(i,k){let b=(V,I,O)=>{for(let j=I-1;j>=0;j--)if(C(V[j])&&O(V[j]))return V[j];return null};return(V,I)=>{let O=Me.get(V),j=Ae.get(I);if(O===j)return!0;let S=b(i,O,X=>N.has(X)),P=b(k,j,X=>A.has(X));return S?N.get(S)===P:!P}}function st(i,k){let b=i.filter(S=>C(S)&&!N.has(S)),V=k.filter(S=>C(S)&&!A.has(S));if(!b.length||!V.length)return;let I=kn(b,S=>S.tagName),O=kn(V,S=>S.tagName),j=Qe(i,k);for(let S of b){let P=S.tagName;if(I.get(P)!==1||O.get(P)!==1)continue;let X=V.find(ee=>ee.tagName===P);X&&!A.has(X)&&j(S,X)&&he(S,X)&&!fe(S,X)&&(_(S,X),T.add(S))}}function ht(){let i=new Map;for(let S of T)if(C(S)&&C(N.get(S))){let P=n(S).hash;i.has(P)||i.set(P,[]),i.get(P).push(S)}if(i.size)for(let S of D){if(A.has(S)||!C(S))continue;let P=i.get(n(S).hash),X=P&&P.find(ee=>T.has(ee)&&!fe(ee,S)&&he(ee,S));X&&(lt(X),y(X,S),h.add(X))}let k=new Map,b=new Map,V=new Map;for(let S of T){let P=N.get(S);C(S)&&C(P)&&V.set(P,S)}let I=(S,P)=>{if(!A.has(S))return!0;let X=V.get(S);return X===A.get(S)&&X!==P&&!X.contains(P)},O=S=>{if(A.has(S)){let P=V.get(S);V.delete(S),lt(P)}};for(let S of[...D,...V.keys()]){if(A.has(S)&&!V.has(S))continue;let P=n(S).hash;if(k.has(P)||k.set(P,[]),k.get(P).push(S),J(S))continue;let X=n(S).sig;b.has(X)||b.set(X,[]),b.get(X).push(S)}let j=new Set;for(let S of T){let P=N.get(S);!C(S)||!C(P)||J(S)||n(S).hint===""||n(P).hint===""||c(S,P)||j.add(S)}for(let S of[...M,...j]){let P=N.get(S);if(P&&!(T.has(S)&&j.has(S)))continue;let X=pt=>{P&<(S),O(pt)},ee=k.get(n(S).hash);if(ee){let pt=ee.find(ue=>ue!==P&&I(ue,S)&&!fe(S,ue));if(pt){X(pt),y(S,pt),h.add(S);continue}}if(J(S)||ge<=0)continue;let Te=b.get(n(S).sig);if(!Te)continue;let tt=null,wt=0;for(let pt of Te)if(!(pt===P||!I(pt,S)||!he(S,pt)||fe(S,pt))&&(ge--<=0||c(S,pt)&&(wt++,tt=pt,wt>1)))break;wt===1&&(X(tt),_(S,tt),h.add(S),ie.push([S,tt]))}}}function kn(e,s){let o=new Map;for(let n of e){let r=s(n);r!=null&&o.set(r,(o.get(r)||0)+1)}return o}var Ns={diff:0},Eo=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null,Ss=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u,vs=/[\p{L}\p{M}\p{N}_'’]+|\s+|[\s\S]/gu,Ms=/\P{M}\p{M}*/gu;function uo(e){if(e==="")return[];if(Eo){let o=[];for(let n of Eo.segment(e))o.push(n.segment);return o}let s=[];for(let o of e.match(vs))if(Ss.test(o))for(let n of o.match(Ms))s.push(n);else s.push(o);return s}var Is=/^[ ]+$/,Os=e=>Is.test(e)?" ".repeat(e.length):e,an=e=>typeof e.k=="string"&&/^\s+$/.test(e.k),it="",io=e=>e.every(s=>an(s)||s.k===it),Ls=/^[\x00-\x7f\u00A0]*$/,Cs=/[A-Za-z0-9_']+|[ \u00A0]+|\s|./g;function Es(e){return e===""?[]:e.match(Cs)}function hn(e,s=!1){return(s?Es(e):uo(e)).map(o=>({k:Os(o),raw:o,len:o.length}))}var $n=(...e)=>e.every(s=>Ls.test(s));function co(e,s,o){let n=e.length,r=s.length,l=Math.min(n+r,o),c=l+1,f=new Int32Array(2*l+3),u=[],v=n===0&&r===0;for(let p=0;p<=l&&!v;p++){u.push(f.slice(c-p,c+p+1));for(let h=-p;h<=p;h+=2){let x;h===-p||h!==p&&f[c+h-1]<f[c+h+1]?x=f[c+h+1]:x=f[c+h-1]+1;let R=x-h,M=x;for(;x<n&&R<r&&e[x].k===s[R].k;)x++,R++;if(Ns.diff+=1+x-M,f[c+h]=x,x>=n&&R>=r){v=!0;break}}}if(!v)return null;let N=[],A=n,T=r;for(let p=u.length-1;p>0;p--){let h=u[p],x=A-T,R=x+p,M=x===-p||x!==p&&h[R-1]<h[R+1]?x+1:x-1,D=h[M+p],K=D-M;for(;A>D&&T>K;)N.push([0,A-1,T-1]),A--,T--;A===D?(N.push([1,A,T-1]),T--):(N.push([-1,A-1,T]),A--)}for(;A>0&&T>0;)N.push([0,A-1,T-1]),A--,T--;return N.reverse(),N}function Rs(e,s,o){let n=A=>A.k===it;if(!e.some(n)&&!s.some(n))return co(e,s,o);let r=[],l=[];for(let A=0;A<e.length;A++)n(e[A])||r.push(A);for(let A=0;A<s.length;A++)n(s[A])||l.push(A);let c=co(r.map(A=>e[A]),l.map(A=>s[A]),o);if(!c)return null;let f=[],u=0,v=0,N=(A,T)=>{for(;u<A&&v<T&&e[u].k===s[v].k;)f.push([0,u++,v++]);let p=co(e.slice(u,A),s.slice(v,T),o);if(!p)return!1;for(let[h,x,R]of p)f.push([h,x+u,R+v]);return u=A,v=T,!0};for(let[A,T,p]of c)if(A===0){if(!N(r[T],l[p]))return null;f.push([0,u,v]),u++,v++}return N(e.length,s.length)?f:null}function yn(e,s,o=4e3){let n=[],r=0;for(;r<e.length&&r<s.length&&e[r].k===s[r].k;)e[r].raw!==s[r].raw&&n.push({bi:r,tok:s[r]}),r++;let l=0;for(;l<e.length-r&&l<s.length-r&&e[e.length-1-l].k===s[s.length-1-l].k;)e[e.length-1-l].raw!==s[s.length-1-l].raw&&n.push({bi:e.length-1-l,tok:s[s.length-1-l]}),l++;let c=e.slice(r,e.length-l),f=s.slice(r,s.length-l),u=js(c,f)?null:Rs(c,f,o);if(!u){let M=c.length||f.length?[{bs:r,be:r+c.length,toks:f}]:[];return{hunks:M,cosmetic:n,coarse:!0,parts:M.map(D=>({...D,gap:[],group:0})),cosmeticEq:n}}let v=[],N=(M,D)=>{c[M].raw!==f[D].raw&&n.push({bi:r+M,tok:f[D]})},A=null,T=[],p=0,h=0,x=()=>{A&&v.push(A),A=null;for(let[M,D]of T)N(M,D);T=[],p++};for(let[M,D,K]of u){if(M===0){A&&an(c[D])&&!c[D].k.includes(`
|
|
2
|
+
`)?T.push([D,K]):(x(),N(D,K)),h=D+1;continue}(!A||T.length)&&(A&&v.push(A),A={bs:r+h,be:r+h,toks:[],gap:T.map(([ie,ge])=>({bi:r+ie,tok:f[ge]})),group:p},T=[]),M===-1?(A.be=r+h+1,h=D+1):A.toks.push(f[K])}x(),Hs(v,e);let R=ao(v);return{hunks:R.hunks,cosmetic:n.concat(R.cosmetic),parts:v,cosmeticEq:n}}function Hs(e,s){for(let o=0;o<e.length;o++){let n=e[o];if(n.gap.length)continue;let r=o+1<e.length?e[o+1].bs:1/0;if(n.toks.length){if(n.bs===n.be)for(;n.bs+1<r&&n.bs<s.length&&n.toks[0].k===it&&s[n.bs].k===it;)n.toks=[...n.toks.slice(1),n.toks[0]],n.bs++,n.be++}else for(;n.be+1<r&&n.be<s.length&&s[n.bs].k===it&&s[n.be].k===it;)n.bs++,n.be++}}function ao(e,s=()=>!1){let o=[],n=[],r=null,l=-1;for(let c of e){let f=s(c);if(r&&!r.alone&&!f&&c.group===l){r.be=c.be;for(let u of c.gap)r.toks.push(u.tok);for(let u of c.toks)r.toks.push(u);continue}r&&o.push({bs:r.bs,be:r.be,toks:r.toks});for(let u of c.gap)n.push(u);r={bs:c.bs,be:c.be,toks:c.toks.slice(),alone:f},l=c.group}return r&&o.push({bs:r.bs,be:r.be,toks:r.toks}),{hunks:o,cosmetic:n}}var Bs=(e,s)=>e.bs===s.bs&&e.be===s.be&&po(e.toks,s.toks);function ho(e,s,o){let n=N=>A=>N.some(T=>Bs(A,T)),r=ao(e.parts,n(s.parts)),l=ao(s.parts,n(e.parts)),c=e.cosmeticEq.concat(r.cosmetic),f=s.cosmeticEq.concat(l.cosmetic),[u,v]=o?Ds(r.hunks,l.hunks,o,c,f):[r.hunks,l.hunks];return{lh:u,rh:v,cosL:c,cosR:f}}function Ds(e,s,o,n,r){let l=(h,x)=>h.k===x.k&&h.raw===x.raw,c=[{list:e.map(h=>({...h})),resp:new Set(n.map(h=>h.bi)),raw:new Map(n.map(h=>[h.bi,h.tok]))},{list:s.map(h=>({...h})),resp:new Set(r.map(h=>h.bi)),raw:new Map(r.map(h=>[h.bi,h.tok]))}],f=h=>h.bs===h.be,u=(h,x,R,M)=>{let D=h.list[x];if(!f(D))return M(D)===R?D.toks:null;let K=x?h.list[x-1].be:0,ie=x+1<h.list.length?h.list[x+1].bs:o.length;if(R<K||R>ie)return null;let ge=D.toks,Me=D.bs;for(;Me>R;){let Ae=ge[ge.length-1];if(!l(Ae,o[Me-1])||h.resp.has(Me-1))return null;ge=[Ae,...ge.slice(0,-1)],Me--}for(;Me<R;){if(!l(ge[0],o[Me])||h.resp.has(Me))return null;ge=[...ge.slice(1),ge[0]],Me++}return ge},v=(h,x,R,M,D,K)=>{let ie=h.list[x],ge=D?R.slice(R.length-M):R.slice(0,M),Me=D?R.slice(0,R.length-M):R.slice(M),Ae={bs:K,be:K,toks:ge};if(f(ie)){if(!Me.length){h.list[x]=Ae;return}let C={bs:K,be:K,toks:Me};D&&(C.lead=!0),h.list.splice(x,1,...D?[C,Ae]:[Ae,C]);return}let _={bs:ie.bs,be:ie.be,toks:Me};h.list.splice(x,1,...D?[_,Ae]:[Ae,_])},N=(h,x,R,M,D)=>{let K=h.list[x],ie=D?R.slice(R.length-M):R.slice(0,M),ge=D?R.slice(0,R.length-M):R.slice(M),Me={bs:K.bs,be:K.be,toks:ie};if(!ge.length){h.list[x]=Me;return}let Ae=D?{bs:K.bs,be:K.bs,toks:ge,lead:!0}:{bs:K.be,be:K.be,toks:ge};h.list.splice(x,1,...D?[Ae,Me]:[Me,Ae])},A=(h,x,R,M)=>{let D=h.list[x],K=R.list[M],ie=D.be,ge=K.bs;if(ie>=ge||x+1<h.list.length&&h.list[x+1].bs<=K.be||M>0&&R.list[M-1].be>=D.bs)return!1;for(let oe=ie;oe<ge;oe++)if(!an(o[oe])||o[oe].k.includes(`
|
|
3
|
+
`))return!1;let Me=oe=>o.slice(ie,ge).map((We,Fe)=>oe.raw.get(ie+Fe)||We),Ae=[...D.toks,...Me(h)],_=[...Me(R),...K.toks],C=(oe,We,Fe)=>We>=0&&We+Fe.length<=oe.length&&Fe.every((dt,ze)=>oe[We+ze].k===dt.k),fe=(oe,We,Fe)=>io(oe)&&o.slice(We,Fe).some(dt=>!an(dt)),J=oe=>oe.some(We=>!an(We)),he,Se,ct,ot;if(f(D)&&J(D.toks)&&C(_,0,D.toks)){let oe=_.slice(D.toks.length);fe(oe,ie,K.be)||(he=ie,Se=D.toks,ct=_.slice(0,D.toks.length),ot=[null,{bs:ie,be:K.be,toks:oe}])}if(he===void 0&&f(K)&&J(K.toks)){let oe=Ae.length-K.toks.length,We=Ae.slice(0,oe);C(Ae,oe,K.toks)&&!fe(We,D.bs,ge)&&(he=ge,Se=Ae.slice(oe),ct=K.toks,ot=[{bs:D.bs,be:ge,toks:We},null])}if(he===void 0)return!1;let lt=oe=>oe&&(oe.bs<oe.be||oe.toks.length);return h.list.splice(x,1,...[ot[0],{bs:he,be:he,toks:Se}].filter(lt)),R.list.splice(M,1,...[{bs:he,be:he,toks:ct},ot[1]].filter(lt)),!0},T=c[0],p=c[1];for(let h=0;h<64;h++){let x=!1;e:for(let R=0;R<T.list.length;R++)for(let M=0;M<p.list.length;M++){let D=T.list[R],K=p.list[M];if(!(D.bs===K.bs&&D.be===K.be&&po(D.toks,K.toks))){for(let ie of[!0,!1]){let ge=Ae=>ie?Ae.be:Ae.bs,Me=f(D)?[ge(K),D.bs]:[ge(D)];for(let Ae of Me){let _=u(T,R,Ae,ge),C=_&&u(p,M,Ae,ge);if(!C)continue;let fe=(ot,lt)=>ie?ot[ot.length-1-lt]:ot[lt],J=0;for(;J<_.length&&J<C.length&&fe(_,J).k===fe(C,J).k;)J++;if(!J)continue;let he=ie?_.slice(0,_.length-J):_.slice(J),Se=ie?C.slice(0,C.length-J):C.slice(J);if(!(J<_.length&&J<C.length&&!io(he)&&!io(Se)&&(f(D)&&f(K)||D.bs===K.bs&&D.be===K.be)||!(ie?_.slice(_.length-J):_.slice(0,J)).some(ot=>!an(ot)))){if(J===_.length&&J===C.length&&f(D)&&f(K)){if(D.bs===Ae&&K.bs===Ae)continue;T.list[R]={bs:Ae,be:Ae,toks:_},p.list[M]={bs:Ae,be:Ae,toks:C}}else!f(D)&&D.bs===K.bs&&D.be===K.be?(N(T,R,_,J,ie),N(p,M,C,J,ie)):(v(T,R,_,J,ie,Ae),v(p,M,C,J,ie,Ae));x=!0;break e}}}if(A(T,R,p,M)||A(p,M,T,R)){x=!0;break e}}}if(!x)break}return[T.list,p.list]}var Ps=48,Us=.3;function js(e,s){let o=e.filter(c=>!an(c)),n=s.filter(c=>!an(c));if(Math.min(o.length,n.length)<Ps)return!1;let r=new Map;for(let c of o)r.set(c.k,(r.get(c.k)||0)+1);let l=0;for(let c of n){let f=r.get(c.k);f>0&&(l++,r.set(c.k,f-1))}return l/Math.min(o.length,n.length)<Us}var _s=(e,s)=>{let o=new Set;for(let n of e.toks)typeof n.k!="string"&&o.add(n.k.el);for(let n=e.bs;n<e.be;n++)typeof s[n].k!="string"&&o.add(s[n].k.el);return o},po=(e,s)=>e.length===s.length&&e.every((o,n)=>o.k===s[n].k);function Ro(e,s,o,n="remote"){let r=yn(e,s),l=yn(e,o),{lh:c,rh:f,cosL:u,cosR:v}=ho(r,l,e),N=y=>y.bs===y.be,A=y=>y.toks.some(H=>typeof H.k=="string"),T=y=>N(y)&&!A(y),p=(y,H)=>H.bs<y.be&&y.bs<H.be,h=(y,H)=>!p(y,H)&&H.bs<=y.be&&y.bs<=H.be&&(N(y)&&A(y)||N(H)&&A(H))&&!(N(y)&&N(H)),x=(y,H)=>y.bs===H.bs&&y.be===H.be&&po(y.toks,H.toks),R=[],M=new Set;for(let y of c){let H=f.find(se=>!M.has(se)&&x(y,se));H?(M.add(H),R.push({bs:y.bs,be:y.be,side:"both",l:y,r:H,toks:y.toks})):R.push({bs:y.bs,be:y.be,side:"L",l:y,toks:y.toks,lead:!!y.lead})}for(let y of f)M.has(y)||R.push({bs:y.bs,be:y.be,side:"R",r:y,toks:y.toks,lead:!!y.lead});R.sort((y,H)=>y.bs-H.bs||y.be-H.be||H.lead-y.lead);let D=0,K=0;for(let y of R)y.side==="both"&&(D+=y.toks.length-(y.be-y.bs));let ie=R.map((y,H)=>H),ge=y=>ie[y]===y?y:ie[y]=ge(ie[y]),Me=(y,H)=>(y=ge(y),H=ge(H),y===H?!1:(ie[y]=H,!0)),Ae=R.map(y=>_s({bs:y.bs,be:y.be,toks:y.toks},e)),_={L:new Map,R:new Map};R.forEach((y,H)=>{let se=y.side==="both"?["L","R"]:[y.side];for(let Z of se)for(let Oe of Ae[H])_[Z].has(Oe)||_[Z].set(Oe,[]),_[Z].get(Oe).push(H)});for(let y of[_.L,_.R])for(let H of y.values())for(let se=1;se<H.length;se++)Me(H[0],H[se]);for(let y=0;y<R.length;y++)for(let H=y+1;H<R.length;H++){let se=R[y],Z=R[H];se.side===Z.side&&se.side!=="both"||se.bs>Z.be||(p(se,Z)||h(se,Z)?Me(y,H):se.bs===Z.bs&&N(se)&&N(Z)&&K++)}let C=(y,H)=>{let se=y==="L"?c:f;for(let Z of se)if(Z.toks.some(Oe=>Oe.kind==="close"&&Oe.k.el===H.el))return Z.bs;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="close"&&e[Z].k.el===H.el)return Z;return-1};R.forEach((y,H)=>{if(!(!T(y)||y.side==="both"))for(let se of y.toks){if(se.kind!=="open")continue;let Z=C(y.side,se.k);if(Z<=y.bs)continue;let Oe=new Uint8Array(Z-y.bs),rt=[];if(R.forEach((Xe,Qe)=>{if(!(Xe.side===y.side||N(Xe))&&Xe.bs<Z&&Xe.be>y.bs){rt.push(Qe);for(let st=Math.max(Xe.bs,y.bs);st<Math.min(Xe.be,Z);st++)Oe[st-y.bs]=1}}),rt.length&&Oe.every(Xe=>Xe===1))for(let Xe of rt)Me(H,Xe)}});let fe=!0;for(;fe;){fe=!1;let y=new Map;R.forEach((H,se)=>{let Z=ge(se),Oe=y.get(Z)||{bs:H.bs,be:H.be,L:!1,R:!1};Oe.bs=Math.min(Oe.bs,H.bs),Oe.be=Math.max(Oe.be,H.be),H.side!=="R"&&(Oe.L=!0),H.side!=="L"&&(Oe.R=!0),y.set(Z,Oe)}),R.forEach((H,se)=>{for(let[Z,Oe]of y){if(ge(se)===ge(Z)||!(Oe.L&&Oe.R))continue;let rt=H.bs<Oe.be&&H.be>Oe.bs,Xe=N(H)&&A(H)&&(H.bs===Oe.be||H.bs===Oe.bs);(rt||Xe)&&Me(se,Z)&&(fe=!0)}})}let J=new Map;R.forEach((y,H)=>{let se=ge(H);J.has(se)||J.set(se,[]),J.get(se).push(y)});let he=[];for(let y of J.values()){let H=y.some(Z=>Z.side==="L"),se=y.some(Z=>Z.side==="R");if(H&&se){let Z=Math.min(...y.map(Qe=>Qe.bs)),Oe=Math.max(...y.map(Qe=>Qe.be)),rt=y.filter(Qe=>Qe.side!=="R").map(Qe=>Qe.l).sort((Qe,st)=>Qe.bs-st.bs),Xe=y.filter(Qe=>Qe.side!=="L").map(Qe=>Qe.r).sort((Qe,st)=>Qe.bs-st.bs);he.push({bs:Z,be:Oe,kind:"conflict",localHunks:rt,remoteHunks:Xe})}else for(let Z of y)he.push({bs:Z.bs,be:Z.be,kind:Z.side,u:Z})}let Se=(y,H)=>{let se=y==="L"?c:f;for(let Z of se)if(Z.toks.some(Oe=>Oe.kind==="close"&&Oe.k.el===H.el))return Z.bs+.5;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="close"&&e[Z].k.el===H.el)return Z;return 1/0},ct=(y,H)=>{let se=y==="L"?c:f;for(let Z of se)if(Z.toks.some(Oe=>Oe.kind==="open"&&Oe.k.el===H.el))return Z.bs-.5;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="open"&&e[Z].k.el===H.el)return Z;return-1/0},ot=y=>y.kind==="R"?"R":"L",lt=y=>y.kind==="R"?1:0;he.sort((y,H)=>{if(y.bs!==H.bs)return y.bs-H.bs;let se=y.bs===y.be,Z=H.bs===H.be;if(se!==Z)return se?-1:1;if(se&&Z&&y.kind!=="conflict"&&H.kind!=="conflict"){let rt=y.u.toks,Xe=H.u.toks,Qe=ht=>ht.length&&ht.every(i=>i.kind==="open"),st=ht=>ht.length&&ht.every(i=>i.kind==="close");if(Qe(rt)&&Qe(Xe)){let ht=Math.max(...rt.map(k=>Se(ot(y),k.k))),i=Math.max(...Xe.map(k=>Se(ot(H),k.k)));if(ht!==i)return i-ht}if(st(rt)&&st(Xe)){let ht=Math.min(...rt.map(k=>ct(ot(y),k.k))),i=Math.min(...Xe.map(k=>ct(ot(H),k.k)));return ht!==i?i-ht:lt(H)-lt(y)}}let Oe=rt=>rt.u&&rt.u.lead?1:0;return Oe(H)-Oe(y)||lt(y)-lt(H)||y.be-H.be});let oe=[],We=[],Fe=0,dt=y=>{y>Fe&&(oe.push({bs:Fe,be:y,toks:e.slice(Fe,y),source:"base"}),Fe=y)};for(let y of he){if(dt(y.bs),y.kind==="conflict"){let H=fo(e,y.localHunks,y.bs,y.be),se=fo(e,y.remoteHunks,y.bs,y.be),Z=n==="local"?H:n==="both"?H.concat(se):se;We.push({bs:y.bs,be:y.be,base:e.slice(y.bs,y.be),local:H,remote:se,resolved:Z}),oe.push({bs:y.bs,be:y.be,toks:Z,source:"conflict",localHunks:y.localHunks,localToks:H,keepsLocal:n!=="remote"})}else oe.push({bs:y.bs,be:y.be,toks:y.u.toks,source:y.kind==="R"?"remote":"local",localHunks:y.kind==="R"?[]:[y.u.l]});Fe=Math.max(Fe,y.be)}dt(e.length);let ze=new Map(u.map(y=>[y.bi,y.tok])),Ge=new Map(v.map(y=>[y.bi,y.tok])),at=[];for(let y of oe){y.source==="base"&&(y.toks=y.toks.map((H,se)=>{let Z=y.bs+se,Oe=ze.get(Z),rt=Ge.get(Z),Xe=Oe&&rt?n==="remote"?rt:Oe:Oe||rt||H;return Xe===H?H:{...Xe,cosmetic:!0}}));for(let H of y.toks)at.push({...H,src:y.source})}return{tokens:at,segments:oe,conflicts:We,localHunks:c,remoteHunks:f,collapsedDelta:D,samePoint:K,mapLocalOffset:Vs(e,c,oe)}}function fo(e,s,o,n){let r=[],l=o;for(let c of s)r=r.concat(e.slice(l,c.bs),c.toks),l=c.be;return r.concat(e.slice(l,n))}var lo=e=>e.reduce((s,o)=>s+o.len,0);function Vs(e,s,o){let n=new Int32Array(e.length+1);for(let c=0;c<e.length;c++)n[c+1]=n[c]+e[c].len;let r=s.map(c=>({bs:n[c.bs],be:n[c.be],text:c.toks.map(f=>f.raw).join(""),ref:c})),l=o.map(c=>({bs:n[c.bs],be:n[c.be],len:lo(c.toks),source:c.source,localHunks:c.localHunks||[],localLen:c.localToks?lo(c.localToks):0,keepsLocal:c.keepsLocal,ref:c}));return c=>{let f=null,u=null,v=0,N=0,A=0;for(let p of r){let h=p.bs-A;if(c<=N+h){f=A+(c-N);break}if(N+=h,A=p.bs,c<=N+p.text.length){u=p,v=c-N,f=p.bs;break}N+=p.text.length,A=p.be}f===null&&(f=A+(c-N));let T=0;for(let p of l){if(!u&&f<=p.bs)return T;if(!(u?p.localHunks.includes(u.ref):f<p.be)){T+=p.len;continue}if(p.source==="base")return T+(f-p.bs);if(p.source==="remote")return T+p.len;if(p.source==="local")return T+Math.min(v,p.len);if(!p.keepsLocal||!u)return T+p.len;let x=p.localHunks.indexOf(u.ref),R=lo(fo(e,p.localHunks.slice(0,x),p.ref.bs,u.ref.bs));return T+Math.min(R+v,p.localLen)}return T}}function wn(e,s,o,n="remote"){if(s===o||o===e)return{text:s,conflicts:[],mapLocalOffset:p=>Math.min(p,s.length),granularity:"word"};let r=$n(e,s,o),l=hn(e,r),c=hn(s,r),f=hn(o,r),u=l.length<=2e4&&c.length<=2e4&&f.length<=2e4?Ro(l,c,f,n):null,v="word",N=l;if(!u){let p=h=>h.split(/(?<=\n)/).map(x=>({k:x,raw:x,len:x.length}));N=p(e),u=Ro(N,p(s),p(o),n),v="line"}let A=p=>p.map(h=>h.raw).join(""),T=[0];for(let p of N)T.push(T[T.length-1]+p.len);return{text:A(u.tokens),conflicts:u.conflicts.map(p=>({bs:T[p.bs],be:T[p.be],base:A(p.base),local:A(p.local),remote:A(p.remote),resolved:A(p.resolved)})),mapLocalOffset:u.mapLocalOffset,granularity:v}}function An(e,s,o=4e3){if(e===s)return[];let n=$n(e,s),r=hn(e,n),l=hn(s,n),c=yn(r,l,o),f=[0];for(let u of r)f.push(f[f.length-1]+u.len);return c.hunks.map(u=>({bs:f[u.bs],be:f[u.be],text:u.toks.map(v=>v.raw).join("")}))}var xn="\uFFFC";var Ws={caret:0},nn=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(" ")),jo=new Set(["BR","WBR","IMG"]),Fs=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 pn(e,s={}){if(e.nodeType===3)return!0;if(e.nodeType!==1)return!1;if(s.ignored&&s.ignored(e)||jo.has(e.tagName))return!0;if(!nn.has(e.tagName))return!Fs.has(e.tagName);if(s.remoteWins&&s.remoteWins(e))return!1;let o=s.inlineCache&&s.inlineCache.get(e);if(o!==void 0)return o;let n=!0;for(let r of e.childNodes)if(!pn(r,s)){n=!1;break}return s.inlineCache&&s.inlineCache.set(e,n),n}function Ks(e){return!e.firstChild||e.textContent===""&&!e.querySelector("br,img,wbr")}function Hn(e,s={}){let o={text:"",marks:[],atoms:[],nodes:[],stackAt:[],pins:[],placeholder:null},n=(r,l)=>{for(let c of r){if(c.nodeType===3){let N=c.nodeValue;if(!N)continue;o.nodes.push({node:c,s:o.text.length,e:o.text.length+N.length}),o.text+=N;for(let A=0;A<N.length;A++)o.stackAt.push(l);continue}if(c.nodeType!==1)continue;if(s.ignored&&s.ignored(c)){o.pins.push({el:c,i:o.text.length});continue}if(s.skip&&s.skip.has(c))continue;let f=c.tagName;if(s.blocks&&s.blocks.has(c)){o.text.length&&o.text[o.text.length-1]!==it&&(o.stackAt.push(l),o.text+=it);let N={el:c,tag:f,from:o.text.length,to:-1,depth:l.length,block:!0};o.marks.push(N);let A=l.concat([N]);n(c.childNodes,A),o.stackAt.push(A),o.text+=it,N.to=o.text.length;continue}let u=nn.has(f)&&Ks(c);if(jo.has(f)||!nn.has(f)||s.remoteWins&&s.remoteWins(c)||s.atomize&&s.atomize(c)||u){o.atoms.push({i:o.text.length,el:c,key:u?f+":empty":f,stack:l}),o.stackAt.push(l),o.text+=xn;continue}let v={el:c,tag:f,from:o.text.length,to:-1,depth:l.length};o.marks.push(v),n(c.childNodes,l.concat([v])),v.to=o.text.length}};if(n(e,[]),o.atoms.length===1&&o.atoms[0].el.tagName==="BR"&&o.marks.length===0&&Yn(o).trim()===""){let r=o.atoms[0];o.placeholder=r.el,o.text=o.text.slice(0,r.i)+o.text.slice(r.i+1),o.stackAt.splice(r.i,1);for(let l of o.nodes)l.s>r.i&&(l.s--,l.e--);o.atoms=[]}return o.atomAt=new Map(o.atoms.map(r=>[r.i,r])),o}function zs(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")}function qs(e){let s="<"+e.tagName.toLowerCase();for(let o of e.attributes)s+=` ${o.name}="${o.value.replace(/"/g,""")}"`;return s+">"}function go(e,s,o){let n="",r=[];for(let l=s;l<o;l++){let c=e.stackAt[l],f=0;for(;f<r.length&&f<c.length&&r[f]===c[f];)f++;for(;r.length>f;)n+=`</${r.pop().tag.toLowerCase()}>`;for(;r.length<c.length;){let v=c[r.length];n+=qs(v.el),r.push(v)}let u=e.atomAt.get(l);n+=u?u.el.outerHTML:e.text[l]===it?"":zs(e.text[l])}for(;r.length;)n+=`</${r.pop().tag.toLowerCase()}>`;return n}function Gs(e,s){let o=[...e.el.attributes].filter(n=>!s(e.el,n.name)).map(n=>n.name+"="+n.value).sort().join("");return e.tag+"|"+o}function _o(e,s){let o=[...e.attributes].filter(n=>!s(e,n.name)).map(n=>n.name+"="+n.value).sort().join("");return e.tagName+"|"+o+"|"+e.innerHTML}function Ho(e,s=()=>!1){let o=new Map,n=l=>{let c=o.get(l);return c===void 0&&(c="{"+l.map(f=>Gs(f,s)).sort().join(",")+"}",o.set(l,c)),c},r="";for(let l=0;l<e.text.length;l++){let c=e.atomAt.get(l);r+=(c?"["+_o(c.el,s)+"]":e.text[l])+n(e.stackAt[l])}return e.text.length===0&&e.placeholder&&(r+="[br]"),r}function Tn(e,s,o,n=r=>r.key){let r=[],l=e.text,c=0,f=u=>{if(u<=c)return;let v=l.slice(c,u);if(o)for(let N of v.split(/(?<=\n)/))r.push({k:N,raw:N,len:N.length});else for(let N of hn(v,s))r.push(N)};for(let u of e.atoms)f(u.i),r.push({k:"\0"+n(u),raw:xn,len:1,atom:!0}),c=u.i+1;return f(l.length),r}function Yn(e){if(!e.atoms.length)return e.text;let s="",o=0;for(let n of e.atoms)s+=e.text.slice(o,n.i),o=n.i+1;return s+e.text.slice(o)}var bo=e=>{let s=new Int32Array(e.length+1);for(let o=0;o<e.length;o++)s[o+1]=s[o]+e[o].len;return s};function Bo(e,s,o,n){let r=bo(s),l=bo(o),c=[],f=0,u=0;for(let N of n.hunks){u+=N.bs-f;let A=u+N.toks.length;c.push({bs:r[N.bs],be:r[N.be],ss:l[u],se:l[A],text:e.text.slice(l[u],l[A]),toks:N.toks,lead:!!N.lead}),u=A,f=N.be}let v=new Map;for(let N of n.cosmetic)v.set(N.bi,N.tok.raw);return{hunks:c,respell:v}}function Do(e,s,o){let n=c=>c===it||/\s/.test(c),r=c=>c.replace(/[\u001E\s]/g,""),l=[];for(let c of e){let f=s.slice(c.bs,c.be),u=o.slice(c.ss,c.se);if(!f.includes(it)&&!u.includes(it)||f.includes(xn)||u.includes(xn)||r(f)!==r(u)){l.push(c);continue}let v=0,N=0;for(;;){let A=v,T=N;for(;A<f.length&&n(f[A]);)A++;for(;T<u.length&&n(u[T]);)T++;let p=v,h=N;for(;p<A&&h<T&&f[p]===u[h];)p++,h++;let x=A,R=T;for(;x>p&&R>h&&f[x-1]===u[R-1];)x--,R--;if(x>p||R>h){let M=u.slice(h,R);l.push({bs:c.bs+p,be:c.bs+x,ss:c.ss+h,se:c.ss+R,text:M,toks:[...M].map(D=>({k:D,raw:D,len:1})),lead:c.lead})}if(A>=f.length)break;v=A+1,N=T+1}}return l}function Po(e,s,o){let n=new Int32Array(s+1).fill(-1),r=new Int32Array(o+1).fill(-1),l=0,c=0,f=u=>{for(;l<u;)n[l]=c,r[c]=l,l++,c++};for(let u of e)f(u.bs),l=u.be,c=u.se;return f(s),n[s]=c,r[c]=s,{bTo:n,toB:r}}function Uo(e,s){if(e.size!==s.size)return!1;for(let o of e)if(!s.has(o))return!1;return!0}function ko(e){let{out:s,policy:o="remote",L:n,R:r}=e,l=e.provenance||new WeakMap,c=e.textMappers||new WeakMap,f=e.conflicts||[],u=e.decisions||[],v=f.length,N=!!(n&&n.reverse&&n.map&&r&&r.reverse&&r.map),A={base:null,local:null,remote:null};if(N&&e.moveIn){let t=Q=>we=>Q.some(Y=>Y===we||Y.nodeType===1&&Y.contains(we)),a=t(e.local),m=t(e.remote),d=t(e.base),w=new Set,E=Q=>{if(!nn.has(Q.tagName))return;let we=n.map.get(Q),Y=r.map.get(Q);(we&&!a(we)||Y&&!m(Y))&&w.add(Q);for(let ce of Q.children)E(ce)};for(let Q of e.base)Q.nodeType===1&&E(Q);let q=Q=>we=>{if(!nn.has(we.tagName))return!1;let Y=Q.reverse.get(we);return!!Y&&(w.has(Y)||!d(Y))};w.size&&(A.base=Q=>w.has(Q)),A.local=q(n),A.remote=q(r)}let T={base:new Set,local:new Set,remote:new Set};if(N&&e.moveIn){let t=d=>w=>d.some(E=>E===w||E.nodeType===1&&E.contains(w)),a=t(e.local),m=t(e.remote);for(let d of Hn(e.base,{...e,atomize:A.base}).atoms){let w=n.map.get(d.el),E=r.map.get(d.el),q=!!w&&!a(w),Q=!!E&&!m(E);!q&&!Q||(T.base.add(d.el),w&&!q&&T.local.add(w),E&&!Q&&T.remote.add(E),a(d.el)&&T.local.add(d.el),m(d.el)&&T.remote.add(d.el))}}let p=Hn(e.base,{...e,atomize:A.base,skip:T.base}),h=Hn(e.local,{...e,atomize:A.local,skip:T.local}),x=Hn(e.remote,{...e,atomize:A.remote,skip:T.remote}),R=new Map(p.atoms.map(t=>[t.el,t])),M=(t,a,m)=>{a.namespaceURI?t.setAttributeNS(a.namespaceURI,a.name,m):t.setAttribute(a.name,m)},D=(t,a,m,d)=>{if(!a&&(!m||!d)){for(let E of(m||d).attributes)M(t,E,E.value);return}let w=new Map;for(let E of[a,m,d])if(E)for(let q of E.attributes)w.set(q.name,q);for(let[E,q]of w){let Q=a?a.getAttribute(E):null,we=m?m.getAttribute(E):Q,Y=d?d.getAttribute(E):Q,ce;we===Y?ce=we:we===Q?(ce=Y,u.push({kind:"attr",el:t,name:E,source:"remote"})):Y===Q?(ce=we,u.push({kind:"attr",el:t,name:E,source:"local"})):(ce=o==="local"?we:Y,f.push({kind:"attr",el:t,name:E,base:Q,local:we,remote:Y,resolved:ce}),u.push({kind:"attr",el:t,name:E,source:"both"})),ce!=null&&M(t,q,ce)}},K=(t,a,m,d)=>t&&e.mergeAttrs?e.mergeAttrs(t,a,m,d):D(d,t,a,m),ie=e.mergeElement||((t,a,m)=>{let d=s.createElement(t.tagName);K(t,a,m,d);let w=a||t,E=m||t,q=o==="local"?w.isEqualNode(t)?E:w:E.isEqualNode(t)?w:E;for(let Q of q.childNodes)d.appendChild(s.importNode(Q,!0));return l.set(d,{base:t,local:a,remote:m}),d}),ge=e.cloneUnit||((t,a)=>{let m=s.importNode(t,!0);return l.set(m,{base:null,local:a==="local"?t:null,remote:a==="remote"?t:null}),m}),Me=e.atomKey||(t=>_o(t,()=>!1)),Ae=(t,a)=>{let m=new Map;for(let d of t.atoms)if(e.remoteWins&&e.remoteWins(d.el)&&nn.has(d.el.tagName))m.set(d,"w"+d.el.tagName+"#"+(d.el.id||""));else if(!N)m.set(d,d.key);else if(t===p)m.set(d,"="+Me(d.el));else{let w=a.reverse.get(d.el),E=w?R.get(w):null;E?m.set(d,"="+Me(E.el)):w?m.set(d,"m"+Me(d.el)):m.set(d,"="+Me(d.el))}return d=>m.get(d)},_=Ae(p,null),C=Ae(h,n),fe=Ae(x,r),J=$n(Yn(p),Yn(h),Yn(x)),he=Tn(p,J,!1,_),Se=Tn(h,J,!1,C),ct=Tn(x,J,!1,fe),ot=he.length>2e4||Se.length>2e4||ct.length>2e4;ot&&(he=Tn(p,J,!0,_),Se=Tn(h,J,!0,C),ct=Tn(x,J,!0,fe));let lt=ho(yn(he,Se),yn(he,ct),he),oe=Bo(h,he,Se,{hunks:lt.lh,cosmetic:lt.cosL}),We=Bo(x,he,ct,{hunks:lt.rh,cosmetic:lt.cosR});oe.hunks=Do(oe.hunks,p.text,h.text),We.hunks=Do(We.hunks,p.text,x.text);let Fe=Po(oe.hunks,p.text.length,h.text.length),dt=Po(We.hunks,p.text.length,x.text.length),ze=p.text.length,Ge=t=>new Map(t.atoms.map(a=>[a.el,a])),at=Ge(h),y=Ge(x),H=(t,a,m)=>{let d=new Set;if(!N)return d;for(let w of t.atoms){let E=R.get(a.reverse.get(w.el));E&&m.bTo[E.i]<0&&d.add(E)}return d},se=H(h,n,Fe),Z=H(x,r,dt),Oe=t=>!pn(t,{...e,remoteWins:null}),rt=new Set;if(N)for(let t of p.atoms){if(!Oe(t.el))continue;let a=n.map.get(t.el)||null,m=r.map.get(t.el)||null,d=a&&!m?a:m&&!a?m:null;d&&(at.has(d)||y.has(d))&&!d.isEqualNode(t.el)&&rt.add(t)}let Xe=1,Qe=(t,a)=>({id:Xe++,tag:t,base:null,local:null,remote:null,rank:a}),st=new Map,ht=[];for(let t of p.marks){let a=Qe(t.tag,t.depth);a.block=!!t.block,a.base=t.el,a.baseMark=t,st.set(t.el,a),ht.push(a)}let i=(t,a)=>{let m=-1,d=-1;for(let w=t.from;w<t.to;w++){let E=a[w];E>=0&&(m<0&&(m=E),d=E+1)}return m<0?null:[m,d]},k=(t,a,m,d)=>{for(let w of t.marks){let E=m?m.reverse.get(w.el):null;E&&m.identical.has(E)&&m.pairIdenticalChildren&&m.pairIdenticalChildren(E);let q=E?st.get(E):null;if(q&&q[a]&&(q=null),!q){let Q=i(w,d),we=0;if(Q)for(let Y of ht){if(Y.tag!==w.tag||Y[a]||!!Y.block!=!!w.block)continue;let ce=Math.min(Q[1],Y.baseMark.to)-Math.max(Q[0],Y.baseMark.from);(ce>we||ce===we&&ce>0&&Math.abs(Y.rank-w.depth)<Math.abs(q.rank-w.depth))&&(q=Y,we=ce)}}q||(q=Qe(w.tag,w.depth),q.block=!!w.block,q.new=a),q[a]=w.el,q[a+"Mark"]=w,st.set(w.el,q)}};k(h,"local",n,Fe.toB),k(x,"remote",r,dt.toB);let b=t=>t.merged||t,V=t=>{let a=new Set;for(let m of t)m.block||a.add(st.get(m.el));return a},I=new Map,O=t=>{let a=I.get(t);return a||(a=V(t),I.set(t,a)),a},j=(t,a)=>{let m=[],d=null;for(let w=0;w<ze;w++){let E=a[w];if(E<0){d&&m.push(d),d=null;continue}let q=O(p.stackAt[w]),Q=O(t.stackAt[E]),we=new Set,Y=new Set;for(let ce of Q)q.has(ce)||we.add(ce);for(let ce of q)Q.has(ce)||Y.add(ce);if(!we.size&&!Y.size){d&&m.push(d),d=null;continue}if(d&&Uo(d.added,we)&&Uo(d.removed,Y)){d.be=w+1;continue}d&&m.push(d),d={bs:w,be:w+1,added:we,removed:Y}}return d&&m.push(d),m},S=j(h,Fe.bTo),P=j(x,dt.bTo),X=t=>t.be>t.bs?[t.bs,t.be-1]:[t.bs-1,t.bs],ee=(t,a)=>{if(ze===0)return null;let[m,d]=X(t);for(let w of a){if(w.be<=m)continue;if(w.bs>d)break;let E=w.bs<=m&&d<w.be;return E&&t.text===""&&w.bs===t.bs&&w.be===t.be?"straddle":E?w:t.be>t.bs?"straddle":null}return null},Te=t=>t.bs===t.be,tt=(t,a)=>{let m=!1;for(let d=t.bs;d<t.be;d++){let w=p.text[d];if(w===it)m=!0;else if(!/\s/.test(w))return!1}for(let d=t.ss;d<t.se;d++){let w=a.text[d];if(w===it)m=!0;else if(!/\s/.test(w))return!1}return m},wt=(t,a)=>t.bs<a.be&&a.bs<t.be,pt=(t,a)=>t.bs<=a.be&&a.bs<=t.be&&Te(t)!==Te(a),ue=(t,a)=>p.text.slice(t.bs,t.be).includes(it)||a.text.slice(t.ss,t.se).includes(it),Ze=t=>{if(Te(t))return!1;let a=t.bs,m=t.be;for(;a>0&&/\s/.test(p.text[a-1]);)a--;for(;m<p.text.length&&/\s/.test(p.text[m]);)m++;return(a===0||p.text[a-1]===it)&&(m===p.text.length||p.text[m]===it)},Et=(t,a)=>!ue(t,a)&&!Ze(t),At=(t,a)=>wt(t,a)||pt(t,a)&&!(tt(t,h)&&Et(a,x))&&!(tt(a,x)&&Et(t,h)),Bt=(t,a)=>{if(t.bs!==a.bs||t.be!==a.be||t.toks.length!==a.toks.length)return!1;let m=t.ss,d=a.ss;for(let w=0;w<t.toks.length;w++){let E=t.toks[w],q=a.toks[w];if(E.k!==q.k||E.atom&&!h.atomAt.get(m).el.isEqualNode(x.atomAt.get(d).el))return!1;m+=E.len,d+=q.len}return!0},jt=(t,a,m,d)=>{for(let w of p.atoms){if(w.i<t.bs||w.i>=t.be||d.has(w)||rt.has(w))continue;let E=a.bTo[w.i],q=E>=0?m.atomAt.get(E):null;if(q&&!q.el.isEqualNode(w.el))return!0}return!1},Nt=[],St=oe.hunks,g=We.hunks,L=0,B=0,F=0,U=0,W=0,$=t=>{t>F&&(Nt.push({src:"base",from:F,to:t,dL:U,dR:W}),F=t)};for(;L<St.length||B<g.length;){let t=St[L],a=g[B],m=!!t&&(!a||t.bs<a.bs||t.bs===a.bs&&t.be<=a.be&&!a.lead);if(t&&a&&t.bs===a.bs&&Te(t)&&Te(a)){let It=tt(t,h),un=tt(a,x);It!==un&&(m=un)}let d=m?t:a,w=m?a:t,E=!!w&&Bt(t,a),q=!!w&&(m?!!St[L+1]&&Bt(St[L+1],a):!!g[B+1]&&Bt(t,g[B+1])),Q=!!w&&!E&&!q&&(ze===0||At(t,a)),we=Q,Y=ee(d,m?P:S);if(Y==="straddle"&&(we=!0),!we&&d.be>d.bs&&(we=jt(d,m?dt:Fe,m?x:h,m?se:Z)),!we&&E){$(d.bs),Nt.push({src:"both",lfrom:t.ss,rfrom:a.ss,len:d.text.length}),F=d.be,U+=d.text.length-(d.be-d.bs),W+=d.text.length-(d.be-d.bs),L++,B++;continue}if(!we){$(d.bs),Nt.push({src:m?"local":"remote",from:d.ss,to:d.se,inherit:Y&&Y!=="straddle"?Y:null}),F=d.be,m?(U+=d.text.length-(d.be-d.bs),L++):(W+=d.text.length-(d.be-d.bs),B++);continue}let ce=d.bs,_e=d.be,Ee=L,je=B,kt=It=>It.bs<_e&&It.be>ce||Te(It)&&(It.bs===ce||It.bs===_e);m?Ee++:je++,Q&&(ce=Math.min(ce,w.bs),_e=Math.max(_e,w.be),m?je++:Ee++);let ut=!0;for(;ut;){for(ut=!1;Ee<St.length&&kt(St[Ee]);)ce=Math.min(ce,St[Ee].bs),_e=Math.max(_e,St[Ee].be),Ee++,ut=!0;for(;je<g.length&&kt(g[je]);)ce=Math.min(ce,g[je].bs),_e=Math.max(_e,g[je].be),je++,ut=!0}let Wt=ce+U,Ht=ce+W,Jt=_e-ce,Zt=_e-ce;for(let It=L;It<Ee;It++)Jt+=St[It].text.length-(St[It].be-St[It].bs);for(let It=B;It<je;It++)Zt+=g[It].text.length-(g[It].be-g[It].bs);let sn=Wt+Jt,rn=Ht+Zt;$(ce);let Mt={kind:"text",node:e.node||null,base:go(p,ce,_e),local:go(h,Wt,sn),remote:go(x,Ht,rn),resolved:null,range:null,bs:ce,be:_e,lss:Wt,lse:sn,rss:Ht,rse:rn};Mt.resolved=o==="local"?Mt.local:o==="remote"?Mt.remote:Mt.local+Mt.remote,o!=="remote"&&Nt.push({src:"local",from:Wt,to:sn,conflict:Mt}),o!=="local"&&Nt.push({src:"remote",from:Ht,to:rn,conflict:Mt}),f.push(Mt),F=_e,U+=Jt-(_e-ce),W+=Zt-(_e-ce),L=Ee,B=je}$(ze);let re=p.text,be=[];if(oe.respell.size||We.respell.size){let t=bo(he),a=[];for(let m=0;m<he.length;m++){let d=he[m].raw,w=oe.respell.get(m)??d,E=We.respell.get(m)??d;(w!==d||E!==d)&&be.push([t[m],w!==d&&E!==d?"both":w!==d?"local":"remote"]),a.push(w===E?w:w===d?E:E===d||o==="local"?w:E)}re=a.join("")}let de="",ke=[],Pe=[],Be=[],Tt=[];for(let t of Nt){let a=de.length;if(t.src==="base"){for(let m=t.from;m<t.to;m++)ke.push(m),Pe.push(m+t.dL),Be.push(m+t.dR),Tt.push(t);de+=re.slice(t.from,t.to)}else if(t.src==="both"){for(let m=0;m<t.len;m++)ke.push(-1),Pe.push(t.lfrom+m),Be.push(t.rfrom+m),Tt.push(t);de+=h.text.slice(t.lfrom,t.lfrom+t.len)}else{let m=t.src==="local"?h:x;for(let d=t.from;d<t.to;d++)ke.push(-1),Pe.push(t.src==="local"?d:-1),Be.push(t.src==="remote"?d:-1),Tt.push(t);de+=m.text.slice(t.from,t.to)}t.ms=a,t.me=de.length,t.conflict&&(t.conflict.range||(t.conflict.range=[a,a]),t.conflict.range[1]=de.length)}let pe=de.length,Ye=new Int32Array(ze+1).fill(-1),ve=new Int32Array(h.text.length+1).fill(-1),Lt=new Int32Array(x.text.length+1).fill(-1);for(let t=0;t<pe;t++)ke[t]>=0&&(Ye[ke[t]]=t),Pe[t]>=0&&(ve[Pe[t]]=t),Be[t]>=0&&(Lt[Be[t]]=t);let xt=(t,a)=>{let m=-1,d=-1;for(let w=t.from;w<t.to;w++){let E=a[w];E>=0&&(m<0&&(m=E),d=E+1)}return m<0?null:[m,d]},Ot=[],gt=[];for(let t of new Set(st.values()))t.new==="local"?Ot.push(t):t.new==="remote"&>.push(t);let Ln=(t,a)=>{t.remote=a.remote,t.remoteMark=a.remoteMark,t.new="both",a.merged=t,st.set(a.remote,t)};if(Ot.length&>.length){let t=e.idOf;for(let a of Ot){let m=t?t.local(a.local):null;if(!m)continue;let d=gt.find(w=>!w.merged&&w.tag===a.tag&&!!w.block==!!a.block&&t.remote(w.remote)===m);d&&Ln(a,d)}for(let a of Ot){if(a.remote)continue;let m=xt(a.localMark,ve);if(m)for(let d of gt){if(d.merged||d.tag!==a.tag||!!d.block!=!!a.block)continue;let w=xt(d.remoteMark,Lt);if(w&&Math.min(m[1],w[1])-Math.max(m[0],w[0])>0){Ln(a,d);break}}}}I.clear();let Cn=t=>{for(let a of t)if(a.block)return b(st.get(a.el));return null},tn=p.marks.some(t=>t.block)||h.marks.some(t=>t.block)||x.marks.some(t=>t.block),Gt=new Array(pe).fill(null),mn=new Set;if(tn){let t=(Y,ce,_e)=>{let Ee=new Set([Y,ce,_e]);Ee.delete(null);let je=[];for(let ut of Ee){let Wt=ut===Y,Ht=ut===ce,Jt=ut===_e;(Ht===Jt?Ht:Ht===Wt?Jt:Ht)&&je.push(ut)}if(je.length<=1)return je[0]||null;let kt=o==="local"?ce:_e;return je.includes(kt)?kt:je[0]},a=(Y,ce)=>ce>=0?Cn(Y.stackAt[ce]):null,m=new Map;for(let Y=0;Y<pe;Y++){if(de[Y]!==it)continue;let ce=ke[Y]>=0?a(p,ke[Y]):null,_e=a(h,Pe[Y]),Ee=a(x,Be[Y]);m.set(Y,[ce,ke[Y]>=0?t(ce,_e,Ee):_e||Ee])}let d=new Set([...m.values()].map(Y=>Y[1])),w=Y=>Y!==it&&Y!==xn&&!/\s/.test(Y),E=(Y,ce)=>{let _e=Y;for(;_e<ce&&!w(de[_e]);)_e++;return _e<ce&&ke[_e]>=0?a(p,ke[_e]):null},q=new Map,Q=0;for(let Y=0;Y<pe;Y++){if(de[Y]!==it)continue;let[ce,_e]=m.get(Y),Ee=E(Q,Y),je=_e,kt=q.get(je)===je&&Ee===je;je&&q.has(je)&&!kt&&ce&&!q.has(ce)&&!d.has(ce)&&(je=ce),je&&!q.has(je)&&q.set(je,Ee);for(let ut=Q;ut<=Y;ut++)Gt[ut]=je;Q=Y+1}let we=Y=>{for(let ce=0;ce<Y.text.length;ce++)if(w(Y.text[ce])&&!a(Y,ce))return!0;return!1};if(!we(p)&&!we(h)&&!we(x)){let Y=[],ce=0;for(let Ee=0;Ee<pe;Ee++)(de[Ee]===it||Ee===pe-1)&&(Y.push([ce,Ee]),ce=Ee+1);let _e=new Set(Gt);for(let Ee=0;Ee<Y.length;Ee++){let[je,kt]=Y[Ee];if(Gt[kt])continue;let ut=je;for(;ut<=kt&&!w(de[ut]);)ut++;if(ut>kt)continue;let Wt=a(p,ke[ut]),Ht=a(h,Pe[ut]),Jt=a(x,Be[ut]),Zt=t(Wt,Ht,Jt)||Ht||Jt||Wt;if(Zt&&!_e.has(Zt)){_e.add(Zt);for(let Mt=je;Mt<=kt;Mt++)Gt[Mt]=Zt;continue}let sn=Ee>0&&Gt[Y[Ee-1][1]],rn=Ee+1<Y.length&&Gt[Y[Ee+1][1]];if(sn)mn.add(Y[Ee-1][1]);else if(rn&&de[kt]===it)mn.add(kt);else continue;for(let Mt=je;Mt<=kt;Mt++)Gt[Mt]=sn||rn}}}let jn=new Map,_n=t=>{let a=jn.get(t);if(a)return a;a=[1/0,-1/0];for(let[m,d]of[[t.baseMark,Ye],[t.localMark,ve],[t.remoteMark,Lt]]){let w=m&&xt(m,d);w&&(a[0]=Math.min(a[0],w[0]),a[1]=Math.max(a[1],w[1]))}return jn.set(t,a),a},Vn=(t,a,m)=>{let d=-1,w=-1;for(let E=0;E<t.length;E++){let q=st.get(t[E].el);q===a&&(d=E),q===m&&(w=E)}return d>=0&&w>=0?d-w:0},gn=(t,a)=>[...t].sort((m,d)=>{for(let q of a){let Q=Vn(q,m,d);if(Q)return Q}let w=_n(m),E=_n(d);return w[0]-E[0]||E[1]-w[1]||m.rank-d.rank||m.id-d.id}),Wn=new Map,z=new Map,Ne=t=>{let a=ke[t],m=Pe[t],d=Be[t],w=Tt[t];if(a>=0){let Ee=p.stackAt[a],je=h.stackAt[m],kt=x.stackAt[d],ut=Wn.get(Ee);ut||Wn.set(Ee,ut=new Map);let Wt=ut.get(je);Wt||ut.set(je,Wt=new Map);let Ht=Wt.get(kt);if(Ht)return Ht;let Jt=O(Ee),Zt=O(je),sn=O(kt),rn=new Set;for(let Mt of new Set([...Jt,...Zt,...sn])){let It=Jt.has(Mt),un=Zt.has(Mt),So=sn.has(Mt);(un===So?un:un===It?So:un)&&rn.add(Mt)}return Ht=gn(rn,[je,kt,Ee]),Wt.set(kt,Ht),Ht}if(w.src==="both"){let Ee=h.stackAt[m],je=x.stackAt[d];return gn(new Set([...O(Ee),...O(je)]),[Ee,je])}let q=(w.src==="local"?h:x).stackAt[w.src==="local"?m:d];if(!w.inherit)return gn(O(q),[q]);let Q=z.get(w);Q||z.set(w,Q=new Map);let we=Q.get(q);if(we)return we;let Y=new Set(O(q));for(let Ee of w.inherit.added)Y.add(b(Ee));for(let Ee of w.inherit.removed)Y.delete(b(Ee));let ce=w.src==="local"?x:h,_e=(w.src==="local"?dt.bTo:Fe.bTo)[w.inherit.bs];return we=gn(Y,[q,ce.stackAt[_e]]),Q.set(q,we),we},me=new Int32Array(h.text.length+1);me[h.text.length]=pe;for(let t=h.text.length-1;t>=0;t--)me[t]=ve[t]>=0?ve[t]:me[t+1];Ws.caret+=h.text.length;let Le=t=>t<=0?0:(t>h.text.length&&(t=h.text.length),ve[t-1]>=0?ve[t-1]+1:me[t]),Ve=[],ne=[],xe=null,te=[],Ce="",Ue=-1,Ct=t=>{xe?xe.appendChild(t):Ve.push(t)},$t=t=>{if(!Ce)return;let a=s.createTextNode(Ce);Ct(a),ne.push({node:a,ms:Ue,me:t,local:[],u:te.length?te[te.length-1].u:null}),Ce=""},on=new Set,Pt=new Map,cn=new Set,De=t=>{let a=s.createElement(t.tag);if(t.block&&Rn.add(a),!Pt.has(t)){Pt.set(t,a),K(t.base,t.local,t.remote,a),l.set(a,{base:t.base,local:t.local,remote:t.remote});let d=(q,Q)=>N&&t[Q]&&q.reverse.get(t[Q])?Q:null,w=!t.base&&(d(n,"local")||d(r,"remote"));if(w){let q=w==="local"?n.reverse.get(t.local):r.reverse.get(t.remote),Q=l.get(a);Q.local=Q.local||n.map.get(q)||null,Q.remote=Q.remote||r.map.get(q)||null,u.push({kind:"move",el:a,source:w})}else t.base||u.push({kind:"insert",el:a,source:t.local&&t.remote?"both":t.local?"local":"remote"});let E=l.get(a);E.local&&(cn.has(E.local)?E.local=null:cn.add(E.local))}else{let d=Pt.get(t);for(let w of d.attributes)w.name!=="id"&&w.name!=="data-id"&&M(a,w,w.value);l.set(a,{base:null,local:null,remote:null})}Ct(a),te.push({u:t,el:a}),xe=a},Ke=new Set,G=new Map;for(let t of h.pins){let a=Le(t.i);G.has(a)||G.set(a,[]),G.get(a).push(t)}let ae=t=>{let a=G.get(t);if(a){$t(t);for(let m of a){let d=m.el.namespaceURI&&m.el.namespaceURI!=="http://www.w3.org/1999/xhtml"?s.createElementNS(m.el.namespaceURI,m.el.tagName):s.createElement(m.el.tagName);l.set(d,{base:null,local:m.el,remote:null,pinned:!0}),Ke.add(d),Ct(d)}}},ye=p.atoms.length||h.atoms.length||x.atoms.length,He=t=>{if(!ye)return null;let a=ke[t]>=0?p.atomAt.get(ke[t]):null,m=Pe[t]>=0?h.atomAt.get(Pe[t]):null,d=Be[t]>=0?x.atomAt.get(Be[t]):null;return a||m||d?{ab:a,al:m,ar:d}:null},Ie=(t,a,m,d)=>{if(!t||!N)return null;let w=R.get(a.reverse.get(t.el))||null;return!w||w===d||(d?w.el.isEqualNode(d.el):m.bTo[w.i]>=0)?null:w},$e=(t,a)=>{if(!t||!N||!e.moveIn)return null;let m=a.reverse.get(t.el);return m&&!R.has(m)?m:null},nt=(t,a)=>{let m=new Map;for(let d of t.atoms)m.set(a(d),(m.get(a(d))||0)+1);return m},Rt=nt(p,_),Ut=nt(h,C),Ft=nt(x,fe),vt=t=>{let a=_(t);return Rt.get(a)===1&&(Ut.get(a)||0)<=1&&(Ft.get(a)||0)<=1},Kt=new Map,mt=new Set,bt=new Set,zt=new Set;for(let t=0;t<pe;t++){let a=He(t);if(!a)continue;let{ab:m,al:d,ar:w}=a,E=Ie(w,r,dt,m),q=Ie(d,n,Fe,m),Q=m,we=null;if(E?(Q=E,we="remote"):q&&(Q=q,we="local"),Q){mt.has(Q)?Kt.set(t,{dup:Q.el}):(mt.add(Q),Kt.set(t,{bk:Q,from:we,al:d,ar:w}));continue}let Y=$e(w,r),ce=$e(d,n),_e=Y||ce;if(_e){bt.has(_e)?Kt.set(t,{dup:_e}):(bt.add(_e),Kt.set(t,{moveIn:_e,side:Y?"remote":"local",sideEl:Y?w.el:d.el}));continue}let Ee=(kt,ut)=>kt&&N&&R.get(ut.reverse.get(kt.el))||null,je=Ee(w,r)||Ee(d,n);if(je&&(zt.add(je),Tt[t].conflict&&vt(je))){if(mt.has(je)){Kt.set(t,{dup:je.el});continue}mt.add(je)}Kt.set(t,{al:d,ar:w})}let Xt=new Map,Fn=(t,a)=>{if(t[a]>=0)return t[a];for(let m=a-1;m>=0;m--)if(t[m]>=0)return t[m]+1;return 0};if(N)for(let t of p.atoms){if(mt.has(t)||zt.has(t))continue;let a=n.map.get(t.el)||null,m=r.map.get(t.el)||null,d=a&&at.get(a),w=m&&y.get(m);if(a&&!d||m&&!w)continue;let E=!(d&&w)&&rt.has(t);if(!E&&!(d&&w&&vt(t)))continue;let q=o==="local"?[[d,ve],[w,Lt]]:[[w,Lt],[d,ve]],[Q,we]=q.find(([ce])=>ce),Y=Fn(we,Q.i);Xt.has(Y)||Xt.set(Y,[]),Xt.get(Y).push({a:t,lt:a,rt:m,edited:E}),mt.add(t)}if(N&&e.moveIn){let t=[[h,n,ve,"local"],[x,r,Lt,"remote"]];o!=="local"&&t.reverse();for(let[a,m,d,w]of t)for(let E of a.atoms){let q=$e(E,m);if(!q||bt.has(q))continue;bt.add(q);let Q=Fn(d,E.i);Xt.has(Q)||Xt.set(Q,[]),Xt.get(Q).push({move:q,side:w,sideEl:E.el})}}let En=t=>{let a=Xt.get(t);if(a){if($t(t),a.some(m=>Oe(m.move?m.sideEl:m.a.el)))for(;te.length;)te.pop(),xe=te.length?te[te.length-1].el:null;for(let{a:m,lt:d,rt:w,edited:E,move:q,side:Q,sideEl:we}of a){if(q){let ce=e.moveIn(q,Q,we);ce&&Ct(ce);continue}on.add(m);let Y=ie(m.el,d,w);E&&(f.push({kind:"structure",el:Y,detail:"edit-beats-delete",base:m.el}),u.push({kind:"insert",el:Y,source:d?"local":"remote"})),Ct(Y)}}},Rn=new Set;for(let t=0;t<pe;t++){let a=He(t),d=!!a&&Oe((a.ab||a.al||a.ar).el)?[]:Gt[t]?[Gt[t],...Ne(t)]:Ne(t),w=0;for(;w<te.length&&w<d.length&&te[w].u===d[w];)w++;if(w<te.length)for($t(t);te.length>w;)te.pop(),xe=te.length?te[te.length-1].el:null;if(ae(t),En(t),d.length>te.length)for($t(t);te.length<d.length;)De(d[te.length]);if(de[t]===it){if(mn.has(t))continue;$t(t);let E=te.length;for(;E>0&&!te[E-1].u.block;)E--;if(E>0)for(;te.length>=E;)te.pop(),xe=te.length?te[te.length-1].el:null;continue}if(a){$t(t);let E=Kt.get(t),q;if(E.dup){f.push({kind:"structure",el:null,detail:"both-moved",base:E.dup});continue}if(E.moveIn){if(q=e.moveIn(E.moveIn,E.side,E.sideEl),!q)continue}else if(E.bk){let Q=E.bk;if(on.add(Q),Q===a.ab)q=ie(Q.el,E.al.el,E.ar.el);else{let we=n.map.get(Q.el)||null,Y=r.map.get(Q.el)||null;q=ie(Q.el,we,Y),(!we||!Y)&&f.push({kind:"structure",el:null,detail:"move-beats-delete",base:Q.el}),u.push({kind:"move",el:q,source:E.from})}}else E.al?(q=ge(E.al.el,"local"),E.ar&&(l.get(q).remote=E.ar.el),u.push({kind:"insert",el:q,source:E.ar?"both":"local"})):(q=ge(E.ar.el,"remote"),u.push({kind:"insert",el:q,source:"remote"}));Ct(q);continue}Ce||(Ue=t),Ce+=de[t]}if($t(pe),(G.has(pe)||Xt.has(pe))&&(te.length=0,xe=null,ae(pe),En(pe)),pe===0&&(h.placeholder||x.placeholder||p.placeholder)){let t=s.createElement("br");l.set(t,{base:p.placeholder,local:h.placeholder,remote:x.placeholder}),Ve.push(t)}let le=0,qe=t=>{for(;le>0&&ne[le-1].me>=t;)le--;for(;le<ne.length&&ne[le].me<t;)le++;let a=ne[le];if(!a)return ne[ne.length-1]||null;let m=ne[le+1];return a.me===t&&m&&m.ms===t?m:a},ft=new Map,et={},Je=(t,a,m)=>{let d=qe(t)||(m?et:null);if(!d)return;let w=ft.get(d)||{l:!1,r:!1};a!=="remote"&&(w.l=!0),a!=="local"&&(w.r=!0),ft.set(d,w)},Qt=t=>{if(t.conflict)return!0;let a=t.src==="local"?h.text:t.src==="remote"?x.text:"";for(let m=t.from;m<t.to;m++)if(a[m]!==xn&&a[m]!==it)return!0;return!1};for(let t of Nt)t.src!=="base"&&Je(t.ms,t.conflict?"both":t.src,Qt(t));for(let[t,a]of be)Ye[t]>=0&&Je(Ye[t],a);for(let t of ne.length?ne:[et]){let a=ft.get(t);a&&u.push({kind:"text",node:t.node||null,source:a.l&&a.r?"both":a.l?"local":"remote"})}for(let t of ht){if(Pt.has(t))continue;let a=!t.local&&!(N&&n.map.get(t.base)),m=!t.remote&&!(N&&r.map.get(t.base));!a&&!m||u.push({kind:"remove",source:a&&m?"both":a?"local":"remote",base:t.base})}let Yt=(t,a,m)=>{if(a<=t)return!1;for(let d=t;d<a;d++)if(m[d]>=0)return!1;return!0};for(let t of ht)for(let a of["local","remote"]){let m=t[a+"Mark"],d=t.baseMark;if(!m)continue;let w=a==="local"?Fe:dt;if(!Yt(d.from,d.to,w.bTo)||!Yt(m.from,m.to,w.toB))continue;let E=(a==="local"?St:g).find(q=>q.ss<=m.from&&m.from<q.se);E&&(E.be<=d.from||E.bs>=d.to)&&u.push({kind:"move",el:Pt.get(t)||null,source:a})}let ln=t=>{let a=st.get(t.node.parentNode);return a?b(a):null};for(let t of h.nodes){let a=-1;for(let d=t.s;d<t.e;d++)if(ve[d]>=0){a=ve[d];break}let m;if(a>=0)m=qe(a);else{let d=Le(t.s),w=ln(t);m=ne.find(E=>E.u===w&&E.me>=d)||ne.filter(E=>E.u===w).pop()}m&&m.local.push(t)}let qt=new Map,Dt=ne[ne.length-1]||null,Vt=0;for(let t of h.nodes){let a=null;for(let m=t.s;m<=t.e;m++){let d=Le(m);for(;Vt>0&&ne[Vt-1].me>=d;)Vt--;for(;Vt<ne.length&&ne[Vt].me<d;)Vt++;let w=q=>q&&d>=q.ms&&d<=q.me&&(d<q.me||m===t.e||q===a),E=w(ne[Vt])?ne[Vt]:w(ne[Vt+1])?ne[Vt+1]:ne[Vt]||Dt;if(!E)break;if(a===E){let q=qt.get(E);q[q.length-1].to=m-t.s;continue}a=E,qt.has(E)||qt.set(E,[]),qt.get(E).push({node:t.node,from:m-t.s,to:m-t.s,flatStart:t.s})}}for(let t of ne){let a=t.local,m=!1;for(let q of a)for(let Q=q.s;Q<q.e&&!m;Q++)(ve[Q]<t.ms||ve[Q]>=t.me)&&(m=!0);l.set(t.node,{base:null,local:a.map(q=>q.node),remote:null,caret:qt.get(t)||[],partial:m});let d=t.ms,w=t.me-t.ms,E=q=>{let Q=0,we=-1;for(let Y of a){let ce=Y.e-Y.s;if(q<=Q+ce){we=Y.s+(q-Q);break}Q+=ce}return we<0&&(we=a.length?a[a.length-1].e:0),Math.max(0,Math.min(Le(we)-d,w))};E.flat=q=>Math.max(0,Math.min(Le(q)-d,w)),c.set(t.node,E)}function us(){if(!h.text.includes(it))return[{flatLocal:h.text,localNodes:h.nodes,textNodes:ne,lToM:ve,mapLocal:Le}];let t=[],a=0,m=0;for(let d=0;d<=h.text.length;d++){if(d<h.text.length&&h.text[d]!==it)continue;let w=a,E=d;if(E>w){let q=[];for(;m<h.nodes.length&&h.nodes[m].e<=w;)m++;for(let Q=m;Q<h.nodes.length&&h.nodes[Q].s<E;Q++){let we=h.nodes[Q],Y=Math.max(we.s,w),ce=Math.min(we.e,E);Y<ce&&q.push({node:we.node,s:Y-w,e:ce-w})}t.push({flatLocal:h.text.slice(w,E),localNodes:q,textNodes:ne,lToM:ve.subarray?ve.subarray(w,E+1):ve.slice(w,E+1),mapLocal:Q=>Le(w+Math.max(0,Math.min(Q,E-w)))})}a=d+1}return t}let ds={...e,blocks:Rn,ignored:t=>Ke.has(t)||(e.ignored?e.ignored(t):!1)},No=e.ignoreAttribute||(()=>!1),hs=Ho(Hn(Ve,ds),No)!==Ho(x,No);return{nodes:Ve,text:de,textNodes:ne,localDiverged:hs,mapLocal:Le,conflicts:f.slice(v),granularity:ot?"line":"word",segments:us(),localHunks:St,remoteHunks:g,lToM:ve}}var $s="http://www.w3.org/1999/xhtml";function Ys(e){let s=5381;for(let o=0;o<e.length;o++)s=(s<<5)+s^e.charCodeAt(o);return(s>>>0).toString(36)}function _t(e){return!!e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.namespaceURI===$s}function Js(e){let s=(e.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return s==="application/json"||s.endsWith("+json")}function Jn(e,s){let o=e.getAttribute("src"),n=(e.getAttribute("type")||"text/javascript").split(";")[0].trim().toLowerCase();if(o){let r=o;try{let l=new URL(o,s);r=l.origin+l.pathname+l.search}catch{}return"script|src|"+n+"|"+r}return"script|inline|"+n+"|"+Ys(e.textContent.trim())}var Xs={match:e=>e.hasAttribute("merge"),identity:e=>e.getAttribute("merge")};function Nn(e,s=[],o=!1){if(!_t(e)||e.hasAttribute("src"))return null;let n=[Xs,...s];for(let r=0;r<n.length;r++){let l=n[r];if(!l.match(e))continue;if(!Js(e))return o&&console.warn("[hyper-morph] merge ignored: script type is not JSON",e),null;let c=l.identity(e);return c==null||c===""?null:{key:r+":"+c,raw:c,recognizer:l}}return null}function Vo(e,s,o){let n=new Set,r=l=>{_t(l)&&!s(l)&&n.add(Jn(l,o))};r(e);for(let l of e.querySelectorAll("script"))r(l);return n}function Bn(e,s){let o=s.createElement("div");o.innerHTML="<script><\/script>";let n=o.firstChild;for(let r of e.attributes)n.setAttribute(r.name,r.value);return n.textContent=e.textContent,n}function Wo(e,s,o){let n=[],r=[],l=Array.from(e.querySelectorAll("script"));_t(e)&&l.unshift(e);for(let c of l){if(!_t(c)||o.ignored(c)||o.skip.has(c)||s.has(Jn(c,o.baseURI)))continue;let f=c.ownerDocument.createElement("script");for(let u of c.attributes)f.setAttribute(u.name,u.value);f.textContent=c.textContent,o.beforeNodeAdded(f)!==!1&&(f.hasAttribute("src")&&r.push(new Promise(u=>{f.addEventListener("load",()=>u()),f.addEventListener("error",()=>u())})),c.replaceWith(f),o.afterNodeAdded(f),n.push(f))}return{executed:n,loads:r}}function Qs(e){let s=5381;for(let o=0;o<e.length;o++)s=(s<<5)+s^e.charCodeAt(o);return(s>>>0).toString(36)}function Zs(e,s){try{let o=new URL(e,s);return o.origin+o.pathname+o.search}catch{return e}}function Fo(e,s){let o=e.tagName;if(o==="TITLE"||o==="BASE")return o;if(o==="SCRIPT")return Jn(e,s);if(o==="LINK"){let n=e.getAttribute("href");return n?"link|"+(e.getAttribute("rel")||"")+"|"+Zs(n,s):e.outerHTML}if(o==="META"){for(let n of["charset","name","property","http-equiv","itemprop"])if(e.hasAttribute(n))return"meta|"+n+"="+e.getAttribute(n);return e.outerHTML}return o==="STYLE"?"style|"+Qs(e.textContent):e.outerHTML}function yo(e,s){for(;;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(e[s]==="/"&&e[s+1]==="/"){for(;s<e.length&&e[s]!==`
|
|
4
|
+
`;)s++;continue}if(e[s]==="/"&&e[s+1]==="*"){let o=e.indexOf("*/",s+2);if(o===-1)return e.length;s=o+2;continue}return s}}function Ko(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(s,o)=>o.length%2===0?o+'\\"':s)}var er=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,tr=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Xn(e){try{return JSON.parse(e)}catch{return JSON.parse(nr(e))}}function nr(e){let s="",o=0,n=(r,l)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${l}`)};for(;o<e.length&&(o=yo(e,o),!(o>=e.length));){let r=e[o];if("{}[]:".includes(r)){s+=r,o++;continue}if(r===","){let f=yo(e,o+1);if(e[f]==="}"||e[f]==="]"){o++;continue}s+=r,o++;continue}if(r==='"'||r==="'"){let f=o+1;for(;f<e.length&&e[f]!==r;)e[f]==="\\"&&f++,f++;f>=e.length&&n("unterminated string",o);let u=e.slice(o+1,f);r==="'"&&(u=Ko(u)),s+='"'+u+'"',o=f+1;continue}let l=o;for(;l<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[l]);)l++;l===o&&n("unexpected character "+JSON.stringify(r),o);let c=e.slice(o,l);if(c==="true"||c==="false"||c==="null"||er.test(c)){s+=c,o=l;continue}if(tr.test(c)){if(e[yo(e,l)]===":"){s+='"'+c+'"',o=l;continue}n("unquoted value "+JSON.stringify(c),o)}n("invalid token "+JSON.stringify(c),o)}return s}function zo(e){try{return JSON.parse(e)}catch{}let s={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function o(r){let l=[],c=0;for(;c<r.length;){let f=r[c];if(/\s/.test(f)){c++;continue}if("{}".includes(f)){l.push({type:f,value:f}),c++;continue}if(f==="["){let A=!1,T=c+1;for(;T<r.length&&/\s/.test(r[T]);)T++;if(T<r.length&&/[a-zA-Z_]/.test(r[T])&&(A=!0),!A){l.push({type:f,value:f}),c++;continue}}if(f==="]"){l.push({type:f,value:f}),c++;continue}if(f===":"){l.push({type:s.COLON,value:f}),c++;continue}if(f===","){l.push({type:s.COMMA,value:f}),c++;continue}if(f==='"'||f==="'"){let A=f,T=c+1;for(;T<r.length&&r[T]!==A;)r[T]==="\\"&&T++,T++;l.push({type:s.STRING,value:r.substring(c+1,T),quoted:!0,sourceQuote:A}),c=T+1;continue}let u=c,v;for(;u<r.length&&!/[{},]/.test(r[u]);)if(r[u]===":"){let A=[":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"],T=!1;for(let p of A){let h=p.substring(1);if(r.substring(u+1,u+1+h.length)===h){T=!0,u+=h.length;break}}if(!T)break}else if(r[u]==="["){for(u++;u<r.length&&r[u]!=="]";){if(r[u]==='"'||r[u]==="'"){let A=r[u];for(u++;u<r.length&&r[u]!==A;)r[u]==="\\"&&u++,u++}u++}u<r.length&&r[u]==="]"&&u++}else u++;v=r.substring(c,u);let N=s.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(v)?N=s.NUMBER:v==="true"||v==="false"||v==="null"?N=s.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(v)&&(N=s.SELECTOR),l.push({type:N,value:v,quoted:!1}),c=u}return l}function n(r){let l="";for(let c=0;c<r.length;c++){let f=r[c];if("{}".includes(f.type)||"[]".includes(f.type)){l+=f.value;continue}if(f.type===s.COLON){l+=f.value;continue}if(f.type===s.COMMA){let u=r[c+1];if(u&&(u.type==="}"||u.type==="]"))continue;l+=f.value;continue}if(f.type===s.STRING){let u=f.value;f.sourceQuote==="'"&&(u=Ko(u)),l+=`"${u}"`;continue}if(f.type===s.NUMBER||f.type===s.BOOLEAN){l+=f.value;continue}l+=`"${f.value}"`}return l}try{let r=o(e),l=n(r);return JSON.parse(l)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var yt=Symbol("hyper-morph-json-merge:missing"),qo=["id","_id","uuid","key","slug","code","name"];function Sn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Dn(e,s){return Object.prototype.hasOwnProperty.call(e,s)}function or(e,s,o){Object.defineProperty(e,s,{value:o,enumerable:!0,writable:!0,configurable:!0})}function fn(e,s){if(e===s)return!0;if(Array.isArray(e)&&Array.isArray(s)){if(e.length!==s.length)return!1;for(let o=0;o<e.length;o++)if(!fn(e[o],s[o]))return!1;return!0}if(Sn(e)&&Sn(s)){let o=Object.keys(e);if(o.length!==Object.keys(s).length)return!1;for(let n of o)if(!Dn(s,n)||!fn(e[n],s[n]))return!1;return!0}return!1}function Go(e,s,o,n){return fn(s,o)?s:fn(s,e)?o:fn(o,e)?s:Sn(s)&&Sn(o)?sr(Sn(e)?e:{},s,o,n):Array.isArray(s)&&Array.isArray(o)?lr(Array.isArray(e)?e:[],s,o,n):o}function $o(e,s,o,n){return s===yt&&o===yt?yt:s===yt?e===yt?o:fn(o,e)?yt:o:o===yt?e===yt?s:yt:Go(e,s,o,n)}function sr(e,s,o,n){let r={},l=new Set([...Object.keys(e),...Object.keys(s),...Object.keys(o)]);for(let c of l){let f=$o(Dn(e,c)?e[c]:yt,Dn(s,c)?s[c]:yt,Dn(o,c)?o[c]:yt,n);f!==yt&&or(r,c,f)}return r}function rr(e){return e===null||typeof e!="object"}function Qn(e){return typeof e+":"+String(e)}function ir(e,s){for(let o of s){let n=new Set;for(let r of o){if(!Dn(r,e))return!1;let l=r[e];if(typeof l!="string"&&typeof l!="number")return!1;let c=Qn(l);if(n.has(c))return!1;n.add(c)}}return!0}function cr(e,s,o,n){let r=[e,s,o],l=!0;for(let c of r)for(let f of c)Sn(f)||(l=!1);if(l){for(let c of n.keyCandidates)if(ir(c,r))return{kind:"keyed",field:c};return null}for(let c of r){let f=new Set;for(let u of c){if(!rr(u))return null;let v=Qn(u);if(f.has(v))return null;f.add(v)}}return{kind:"self"}}function lr(e,s,o,n){let r=cr(e,s,o,n);if(!r)return o;let l=r.kind==="self"?Qn:p=>Qn(p[r.field]),c=p=>{let h=new Map;for(let x of p)h.set(l(x),x);return h},f=c(e),u=c(s),v=c(o),N=new Map,A=new Set([...f.keys(),...u.keys(),...v.keys()]);for(let p of A){let h=$o(f.has(p)?f.get(p):yt,u.has(p)?u.get(p):yt,v.has(p)?v.get(p):yt,n);h!==yt&&N.set(p,h)}let T=[];for(let p of o){let h=l(p);N.has(h)&&T.push(h)}for(let p=0;p<s.length;p++){let h=l(s[p]);if(!N.has(h)||T.includes(h))continue;let x=0;for(let R=p-1;R>=0;R--){let M=T.indexOf(l(s[R]));if(M!==-1){x=M+1;break}}T.splice(x,0,h)}return T.map(p=>N.get(p))}function wo(e,s,o,n={}){let r=n.keyCandidates?[...n.keyCandidates,...qo]:qo;return Go(e===void 0?yt:e,s,o,{keyCandidates:r})}function Zn(e,s,o,n={}){let r=n.parse||Xn,l=[],c=(A,T)=>{if(typeof A!="string")return yt;try{return r(A)}catch(p){return l.push(`${T} side is not valid JSON (${p.message})`),yt}},f=c(s,"local"),u=c(o,"remote");if(f===yt)return{text:o,warnings:l};if(u===yt)return{text:s,warnings:l};let v=c(e,"base"),N=wo(v===yt?void 0:v,f,u,n);return fn(N,u)?{text:o,warnings:l}:fn(N,f)?{text:s,warnings:l}:{text:JSON.stringify(N,null,2),warnings:l}}var Re=e=>!!e&&e.nodeType===1,ar=new Set("P H1 H2 H3 H4 H5 H6 DIV LI DD DT BLOCKQUOTE FIGCAPTION SUMMARY ADDRESS".split(" ")),Yo=5e4;function Ao(e,s,o,n){let r=n.ignored,l=Lo({ignored:r,ignoreAttribute:n.ignoreAttribute}),{unitsOf:c,meta:f}=l,u=n.baseURI,v=n.mergeTags!==null,N=g=>L=>{if(v&&L.tagName==="SCRIPT"){let B=Nn(L,n.mergeTags);if(B)return"merge:"+B.key}return L.parentElement&&L.parentElement.tagName==="HEAD"?Fo(L,u):g(L)},A=N(n.identity.base),T=N(n.identity.local),p=N(n.identity.remote),h=n.authored||n.identity,x=g=>g&&g.nodeType===9?g.documentElement:g,R=x(e),M=x(s),D=x(o),K=globalThis.__hyperMorphProfile,ie=K?performance.now():0,ge="[id],[data-id],script,head>*",Me=g=>g===dn?ge:null,Ae=Gn(R,A,r,Me(n.identity.base)),_=n.localIsBase?Xo():ro(R,M,{analyzer:l,baseIndex:Ae,sideIndex:Gn(M,T,r,Me(n.identity.local)),baseId:h.base,sideId:h.local}),C=ro(R,D,{analyzer:l,baseIndex:Ae,sideIndex:Gn(D,p,r,Me(n.identity.remote)),baseId:h.base,sideId:h.remote});Xe(),Qe(_,C),Qe(C,_),K&&(K.alignTotal=(K.alignTotal||0)+(performance.now()-ie),ie=performance.now());let fe=R.ownerDocument.implementation.createHTMLDocument(""),J=new WeakMap,he=new WeakMap,Se=[],ct=[],ot=new Set,lt=[],oe=new Set,We=new Set,Fe=new Set,dt=new WeakMap,ze=n.conflicts||"remote",Ge=g=>Se.push(g),at=g=>Se.push(g),y=g=>ct.push(g),H=Oe(),se=b(R,_.map.get(R),C.map.get(R),!!n.localIsBase,!!n.childrenOnly);se.tagName==="HTML"?fe.replaceChild(se,fe.documentElement):fe.body.appendChild(se),K&&(K.build=(K.build||0)+(performance.now()-ie));let Z=n.childrenOnly?!Ze(pt(se),pt(D)):!wt(se,D);return{doc:fe,root:se,provenance:J,textMappers:he,decisions:Se,conflicts:ct,localDiverged:Z,mergedScripts:ot,segments:lt,remoteIdOf:n.identity.remote,customIdentity:n.identity.remote!==dn,L:_,R:C};function Oe(){let g=new Map,L=new Set;if(n.localIsBase||!_.insertedByHash)return{partner:g,drop:L};let B=_.insertedByHash(),F=C.insertedByHash();if(!B.size||!F.size)return{partner:g,drop:L};let U={ignored:r,remoteWins:n.remoteWins,inlineCache:dt},W=pe=>{let Ye=0;for(let ve=pe.parentNode;ve;ve=ve.parentNode)Ye++;return Ye},$=[],re=pe=>{let Ye=pe.textContent.trim();return Ye.split(/\s+/).length>=3||Ye.replace(/\s/g,"").length>=12},be=pe=>{let Ye=_.map.get(pe),ve=C.map.get(pe);return Ye&&_.reverse.get(Ye.parentNode)!==pe.parentNode||ve&&C.reverse.get(ve.parentNode)!==pe.parentNode},de=(pe,Ye,ve)=>{for(let xt of ve.parentNode.children){let Ot=xt!==ve&&pe.reverse.get(xt);if(Ot&&be(Ot))return!0}let Lt=pe.reverse.get(ve.parentNode);if(Lt){for(let xt of Lt.children)if(!Ye.map.has(xt)&&!r(xt))return!0}return!1};for(let[pe,Ye]of B){let ve=F.get(pe);if(!ve)continue;let Lt=Ye.length===1&&ve.length===1;for(let xt of Ye)pn(xt,U)||$.push([xt,ve,W(xt),Lt&&(re(xt)||de(_,C,xt)||de(C,_,ve[0]))])}if(!$.length)return{partner:g,drop:L};$.sort((pe,Ye)=>pe[2]-Ye[2]);let ke=new Set,Pe=new Set,Be=pe=>{for(let Ye of pe.querySelectorAll("*"))ke.add(Ye)},Tt=(pe,Ye)=>pe.reverse.get(Ye.parentNode)||null;for(let[pe,Ye,,ve]of $){if(ke.has(pe))continue;let Lt=Tt(_,pe),xt=gt=>!Pe.has(gt)&&!ke.has(gt)&>.tagName===pe.tagName,Ot=Ye.find(gt=>xt(gt)&&Lt&&Tt(C,gt)===Lt)||(ve?Ye.find(xt):null);Ot&&(Pe.add(Ot),Be(pe),Be(Ot),!(Lt&&Tt(C,Ot)===Lt)&&(g.set(pe,Ot),g.set(Ot,pe),L.add(ze==="local"?Ot:pe)))}return{partner:g,drop:L}}function rt(g,L,B){if(oe.add(g),H.drop.has(g))return null;oe.add(B);let F=L==="local"?g:B,U=L==="local"?B:g,W;return l.unitHash(F)===l.unitHash(U)?(W=Te(F,"local",!0),J.get(W).remote=U):W=ee(F,U),y({kind:"structure",el:W,detail:"both-moved",base:null,local:F,remote:U}),Ge({kind:"insert",el:W,source:"both"}),W}function Xe(){if(!_.weak||!C.weak||!_.weak.size||!C.weak.size||!_.unpair)return;let g=new Map;for(let B of _.weak){let F=_.map.get(B);Re(B)&&Re(F)&&g.set(l.unitHash(F),B)}let L=!1;for(let B of Array.from(C.weak)){let F=C.map.get(B);if(!Re(B)||!Re(F))continue;let U=g.get(l.unitHash(F));!U||U===B||!_.weak.has(U)||_.map.has(B)&&C.map.has(U)||_.map.get(U).tagName===F.tagName&&(_.unpair(U),C.unpair(B),L=!0)}L&&(_.rematch(),C.rematch())}function Qe(g,L){if(!g.weak||!g.weak.size||!L.insertedByHash)return;let B=L.insertedByHash();if(!B.size)return;let F=!1;for(let U of Array.from(g.weak)){let W=g.map.get(U);if(!W)continue;let $=B.get(l.unitHash(W));$&&$.some(re=>re.tagName===W.tagName)&&(g.unpair(U),F=!0)}F&&g.rematch()}function st(g,L){if(g.map.has(L))return g.map.get(L);let B=[];for(let U=L.parentNode;U&&!g.map.has(U);U=U.parentNode)B.push(U);let F=B.length?B[B.length-1].parentNode:L.parentNode;if(!F||!g.identical.has(F))return null;g.pairIdenticalChildren(F);for(let U=B.length-1;U>=0;U--)g.pairIdenticalChildren(B[U]);return g.map.get(L)||null}function ht(g,L,B){if(We.has(g)||Fe.has(g))return y({kind:"structure",el:null,detail:"both-moved",base:g}),We.has(g)?null:Te(B,L);let F=st(_,g),U=st(C,g);(!F||!U)&&y({kind:"structure",el:null,detail:"move-beats-delete",base:g});let W=b(g,F,U,!1);return(L==="local"?Ge:at)({kind:"move",el:W,source:L}),W}function i(g,L,B,F){return F||!L||L===B?{el:B,asBase:!0,twin:U=>U,baseOf:U=>U,units:c(B),here:()=>!0,parentOfTwin:()=>B}:{el:L,asBase:!1,twin:U=>g.map.get(U),baseOf:U=>g.reverse.get(U),units:c(L),here:U=>Re(U)?U.parentNode===L||L.tagName==="TEMPLATE"&&U.parentNode===L.content:U.parent===L||L.tagName==="TEMPLATE"&&U.parent===L.content}}function k(g,L,B){return!L||B&&B.identical.has(g)?!1:Re(g)?f(g).hash!==f(L).hash:g.value!==L.value}function b(g,L,B,F,U=!1){let W=F||n.remoteWins(g),$=g.namespaceURI&&g.namespaceURI!=="http://www.w3.org/1999/xhtml"?fe.createElementNS(g.namespaceURI,g.tagName):fe.createElement(g.tagName),re={base:g,local:L||null,remote:B||null};if(J.set($,re),oe.add(g),We.add(g),L&&oe.add(L),B&&oe.add(B),n.skipUnchanged&&!U&&(n.localIsBase||_.identical.has(g))&&B&&C.identical.has(g)&&!n.remoteWins(g)){re.unchanged=!0;for(let de of g.attributes)de.namespaceURI?$.setAttributeNS(de.namespaceURI,de.name,de.value):$.setAttribute(de.name,de.value);return $}Fe.add(g),U||O(g,W?g:L,B,$);let be=g.tagName;if(_t(g))I(g,W?g:L,B,$);else if(be==="TEXTAREA")$.textContent=V(g.textContent,(W?g:L)?(W?g:L).textContent:g.textContent,B?B.textContent:g.textContent,$,"text");else{let de=tt(g,L,B,W,$),ke=be==="TEMPLATE"&&$.content?$.content:$;for(let Pe of de)ke.appendChild(Pe)}return Fe.delete(g),$}function V(g,L,B,F,U){if(L===B)return L;if(L===g)return B!==g&&at({kind:U,node:F,source:"remote"}),B;if(B===g)return Ge({kind:U,node:F,source:"local"}),L;let W=ze==="local"?L:B;return y({kind:U,node:F,base:g,local:L,remote:B,resolved:W}),Se.push({kind:U,node:F,source:"both"}),W}function I(g,L,B,F){let U=g.textContent,W=L?L.textContent:U,$=B?B.textContent:U,re=v?Nn(g,n.mergeTags,!0):null;if(re&&W!==$){let be=B&&B.getAttribute("merge-key")||g.getAttribute("merge-key"),{text:de,warnings:ke}=Zn(n.localIsBase?void 0:U,W,$,{parse:re.recognizer.parse,keyCandidates:be?be.split(/[\s,]+/).filter(Boolean):void 0});for(let Pe of ke)console.warn(`[hyper-morph] merge "${re.raw}": ${Pe}`);F.textContent=de,ot.add(F),de!==$?Ge({kind:"text",node:F,source:de===W?"local":"both"}):de!==U&&at({kind:"text",node:F,source:"remote"});return}F.textContent=V(U,W,$,F,"text")}function O(g,L,B,F){let U=new Map;for(let W of[g,L,B])if(W)for(let $ of W.attributes)n.ignoreAttribute(W,$.name)||U.set($.name,$);for(let[W,$]of U){let re=g?g.getAttribute(W):null,be=L?L.getAttribute(W):re,de=B?B.getAttribute(W):re,ke;be===de?ke=be:be===re?(ke=de,at({kind:"attr",el:F,name:W,source:"remote"})):de===re?(ke=be,Ge({kind:"attr",el:F,name:W,source:"local"})):(ke=j(W,re,be,de),ke===void 0&&(ke=ze==="local"?be:de,y({kind:"attr",el:F,name:W,base:re,local:be,remote:de,resolved:ke})),Se.push({kind:"attr",el:F,name:W,source:"both"})),ke!=null&&($.namespaceURI?F.setAttributeNS($.namespaceURI,$.name,ke):F.setAttribute(W,ke))}}function j(g,L,B,F){if(g==="class"){let U=de=>new Set((de||"").split(/\s+/).filter(Boolean)),W=U(L),$=U(B),re=U(F),be=new Set;for(let de of new Set([...W,...$,...re])){let ke=W.has(de),Pe=$.has(de),Be=re.has(de);(Pe===Be?Pe:Pe===ke?Be:Pe)&&be.add(de)}return[...be].join(" ")}if(g==="style"){let U=ke=>{let Pe=new Map;if(!ke)return Pe;let Be=0,Tt=null,pe="",Ye=()=>{let ve=pe.indexOf(":");ve>0&&Pe.set(pe.slice(0,ve).trim(),pe.slice(ve+1).trim()),pe=""};for(let ve of ke){if(Tt){pe+=ve,ve===Tt&&(Tt=null);continue}if(ve==='"'||ve==="'"){Tt=ve,pe+=ve;continue}if(ve==="("?Be++:ve===")"&&Be--,ve===";"&&Be===0){Ye();continue}pe+=ve}return pe.trim()&&Ye(),Pe},W=U(L),$=U(B),re=U(F),be=new Map,de=!1;for(let ke of new Set([...W.keys(),...$.keys(),...re.keys()])){let Pe=W.get(ke)??null,Be=$.get(ke)??null,Tt=re.get(ke)??null,pe;Be===Tt?pe=Be:Be===Pe?pe=Tt:Tt===Pe?pe=Be:(pe=ze==="local"?Be:Tt,de=!0),pe!=null&&be.set(ke,pe)}return de?void 0:[...be].map(([ke,Pe])=>`${ke}: ${Pe}`).join("; ")}}function S(g,L,B,F){let U=g.value,W=F?U:L?L.value:"",$=B?B.value:"";oe.add(g),L&&oe.add(L),B&&oe.add(B);let re=wn(U,W,$,ze),be=re.text===""?null:fe.createTextNode(re.text);be&&(J.set(be,{base:g.nodes,local:L?L.nodes:null,remote:B?B.nodes:null}),he.set(be,re.mapLocalOffset)),W!==U&&$!==U?Se.push({kind:"text",node:be,source:"both"}):W!==U?Ge({kind:"text",node:be,source:"local"}):$!==U&&at({kind:"text",node:be,source:"remote"});for(let de of re.conflicts)y({kind:"text",node:be,base:U.slice(de.bs,de.be),local:de.local,remote:de.remote,resolved:de.resolved});return be}function P(g,L){return An(g,L).every(B=>B.bs===B.be)}function X(g,L){let B=g?g.value:"",F=L?L.value:"",U;if(B===F||!F?U=B:B?P(B,F)?U=F:P(F,B)?U=B:(U=ze==="local"?B:ze==="both"?B+F:F,y({kind:"structure",el:null,detail:"insert-collision",local:B,remote:F,resolved:U})):U=F,g&&oe.add(g),L&&oe.add(L),U==="")return null;let W=fe.createTextNode(U);return J.set(W,{base:null,local:g?g.nodes:null,remote:L?L.nodes:null}),B?Ge({kind:"insert",el:W,source:F&&B===F?"both":"local"}):at({kind:"insert",el:W,source:"remote"}),W}function ee(g,L){let B={ignored:r,remoteWins:n.remoteWins,inlineCache:dt},F=re=>c(re).every(be=>Re(be)?pn(be,B):be.kind==="text"),U=null;if(F(g)&&F(L)){let re=g.textContent,be=L.textContent;re===be||P(be,re)?U=L:P(re,be)&&(U=g)}if(!U){let re=ze==="local",be=Te(re?g:L,re?"local":"remote",!0),de=J.get(be);return re?de.remote=L:de.local=g,y({kind:"structure",el:be,detail:"insert-collision",local:g,remote:L,resolved:re?g:L}),be}let W=g.namespaceURI&&g.namespaceURI!=="http://www.w3.org/1999/xhtml"?fe.createElementNS(g.namespaceURI,g.tagName):fe.createElement(g.tagName);O(null,g,L,W),J.set(W,{base:null,local:g,remote:L}),oe.add(g),oe.add(L);let $=ko({base:Array.from(U.childNodes),local:Array.from(g.childNodes),remote:Array.from(L.childNodes),out:fe,policy:ze,idOf:{local:T,remote:p},ignored:r,ignoreAttribute:n.ignoreAttribute,remoteWins:n.remoteWins,provenance:J,textMappers:he,conflicts:ct,decisions:Se,node:W});lt.push(...$.segments);for(let re of $.nodes)W.appendChild(re);return W}function Te(g,L,B=!1){if(!B&&Re(g)){let $=H.partner.get(g);if($)return rt(g,L,$)}if(!Re(g)){if(g.value==="")return null;let $=g.kind==="comment"?fe.createComment(g.value):fe.createTextNode(g.value);return J.set($,{base:null,local:L==="local"?g.nodes:null,remote:L==="remote"?g.nodes:null}),oe.add(g),$}let F=g.namespaceURI&&g.namespaceURI!=="http://www.w3.org/1999/xhtml"?fe.createElementNS(g.namespaceURI,g.tagName):fe.createElement(g.tagName);for(let $ of g.attributes)$.namespaceURI?F.setAttributeNS($.namespaceURI,$.name,$.value):F.setAttribute($.name,$.value);J.set(F,{base:null,local:L==="local"?g:null,remote:L==="remote"?g:null}),oe.add(g);let U=g.tagName==="TEMPLATE"&&F.content?F.content:F,W=L==="local"?_:C;for(let $ of c(g)){let re=Re($)?W.reverse.get($):null;if(re&&We.has(re)){y({kind:"structure",el:null,detail:"both-moved",base:re});continue}if(re&&!Fe.has(re)){let de=_.map.get(re)||null,ke=C.map.get(re)||null;if(de||ke){let Pe=b(re,de,ke,!1);L==="local"?Ge({kind:"move",el:Pe,source:"local"}):at({kind:"move",el:Pe,source:"remote"}),U.appendChild(Pe);continue}}let be=Te($,L);be&&U.appendChild(be)}return F}function tt(g,L,B,F,U){L&&_.identical.has(g)&&_.pairIdenticalChildren(g),B&&C.identical.has(g)&&C.pairIdenticalChildren(g);let W=i(_,L,g,F),$=i(C,B,g,!1),re=c(g),be=new Set(re),de=new Map;for(let z=0;z<re.length;z++)de.set(re[z],z);let ke=[],Pe=new Set,Be=new Map,Tt=new Set,pe=new Set,Ye=[];Wn();let ve=z=>{let Ne=[];for(let me of z.units){if(pe.has(me))continue;let Le=z.baseOf(me);Le&&be.has(Le)&&Ne.push(de.get(Le))}return Ne},Lt=z=>z.every((Ne,me)=>me===0||Ne>=z[me-1]),xt=!W.asBase&&!Lt(ve(W)),Ot=!$.asBase&&!Lt(ve($));xt&&Ot&&y({kind:"structure",el:null,detail:"both-reordered",base:g});let gt=Ot||!xt?{V:$,A:C,side:"remote",other:W,otherA:_,otherSide:"local"}:{V:W,A:_,side:"local",other:$,otherA:C,otherSide:"remote"};xt?Ge({kind:"move",el:null,source:Ot?"both":"local",base:g}):Ot&&at({kind:"move",el:null,source:"remote",base:g});let Ln=W.asBase?[]:W.units.filter(z=>!W.baseOf(z)&&!pe.has(z)&&!H.partner.has(z)),Cn=$.asBase?[]:$.units.filter(z=>!$.baseOf(z)&&!pe.has(z)&&!H.partner.has(z)),tn=new Map;if(Ln.length&&Cn.length){let z=new Map,Ne=new Map;for(let ne of Cn){if(Re(ne)){let te=p(ne);te&&z.set(te,ne)}let xe=l.unitHash(ne);Ne.has(xe)||Ne.set(xe,[]),Ne.get(xe).push(ne)}let me=(ne,xe)=>{let te=ne.units.indexOf(xe);for(let Ce=te-1;Ce>=0;Ce--){let Ue=ne.baseOf(ne.units[Ce]);if(Ue)return Ue}return"start"},Le=new Map,Ve=new Map;for(let ne of Cn){let xe=me($,ne);Re(ne)?(Ve.has(xe)||Ve.set(xe,[]),Ve.get(xe).push(ne)):ne.kind==="text"&&!Le.has(xe)&&Le.set(xe,ne)}for(let ne of Ln){let xe=null;if(Re(ne)){let te=T(ne);te&&z.has(te)&&!tn.has(z.get(te))&&(xe=z.get(te))}else if(ne.kind==="text"){let te=Le.get(me(W,ne));te&&!tn.has(te)&&(xe=te)}if(!xe){let te=Ne.get(l.unitHash(ne));te&&(xe=te.find(Ce=>!tn.has(Ce)&&Re(Ce)===Re(ne)&&(Re(Ce)?Ce.tagName===ne.tagName:Ce.kind===ne.kind))||null)}if(!xe&&Re(ne)){let te=h.local(ne),Ce=(Ve.get(me(W,ne))||[]).filter(Ue=>{let Ct=h.remote(Ue);return!tn.has(Ue)&&Ue.tagName===ne.tagName&&!(te&&Ct&&te!==Ct)&&l.similar(ne,Ue)});Ce.length===1&&(xe=Ce[0])}xe&&(tn.set(xe,ne),tn.set(ne,xe))}}let Gt=z=>{if(oe.has(z))return Be.get(z)||null;let Ne=W.twin(z),me=$.twin(z),Le=Ne&&!W.asBase&&!W.here(Ne),Ve=me&&!$.asBase&&!$.here(me);if(Le||Ve){if((!Ne||!me)&&y({kind:"structure",el:null,detail:"move-beats-delete",base:z}),!jt(z))return oe.add(z),null;y({kind:"structure",el:null,detail:"both-moved",base:z})}if(!Ne&&!me)return oe.add(z),at({kind:"remove",source:"both",base:z}),null;if(!Ne&&!k(z,me,C))return oe.add(z),Ge({kind:"remove",source:"local",base:z}),null;if(!me&&!k(z,Ne,_))return oe.add(z),at({kind:"remove",source:"remote",base:z}),null;let ne=!Ne||!me,xe=W.asBase?_.map.get(z)||null:Ne,te;return Re(z)?te=b(z,xe,me,W.asBase):z.kind==="comment"?te=At(z,xe,me,W.asBase):te=S(z,xe,me,W.asBase),oe.add(z),te&&(Be.set(z,te),Ne&&Be.set(Ne,te),me&&Be.set(me,te),ne&&(y({kind:"structure",el:te,detail:"edit-beats-delete",base:z}),Ne?Ge({kind:"insert",el:te,source:"local"}):at({kind:"insert",el:te,source:"remote"}))),te},mn=(z,Ne,me,Le)=>{if(oe.has(z))return Be.get(z)||null;let Ve=Ne.baseOf(z);if(Ve&&be.has(Ve))return pe.has(Ve)&&!pe.has(z)?jn(Ve,z,Le):Gt(Ve);if(Ve)return _n(Ve,z,Le);let ne=tn.get(z);if(ne){let te=Le==="local"?z:ne,Ce=Le==="local"?ne:z,Ue;return Re(te)?l.unitHash(te)===l.unitHash(Ce)?(Ue=Te(te,"local"),J.get(Ue).remote=Ce):Ue=ee(te,Ce):Ue=X(te,Ce),oe.add(te),oe.add(Ce),Ue&&(Be.set(te,Ue),Be.set(Ce,Ue),Re(te)&&Ge({kind:"insert",el:Ue,source:"both"})),Ue}let xe=Te(z,Le);return xe&&(Be.set(z,xe),Le==="local"?Ge({kind:"insert",el:xe,source:"local"}):at({kind:"insert",el:xe,source:"remote"})),xe},jn=(z,Ne,me)=>{let Le;return Re(z)?(Le=ht(z,me,Ne),Le&&oe.add(Ne)):(Le=Te(Ne,me),oe.add(Ne),Le&&(me==="local"?Ge:at)({kind:"insert",el:Le,source:me})),Le&&Be.set(Ne,Le),Le},_n=(z,Ne,me)=>{let Ve=(me==="local"?C:_).map.get(z),ne=Ne,xe=Ve?Nt(Ve,me==="local"?B:L,me==="local"?C:_):!1,te=Ve&&!xe&&!St(z,Ve);if(te&&me===gt.otherSide)return y({kind:"structure",el:null,detail:"both-moved",base:z}),null;if(te&&y({kind:"structure",el:null,detail:"both-moved",base:z}),Ve||y({kind:"structure",el:null,detail:"move-beats-delete",base:z}),Fe.has(z)){y({kind:"structure",el:null,detail:"both-moved",base:z});let Ue=Te(ne,me);return Ue&&Be.set(Ne,Ue),Ue}let Ce=Re(z)?b(z,me==="local"?ne:_.map.get(z)||null,me==="remote"?ne:C.map.get(z)||null,!1):null;return Ce&&(Be.set(z,Ce),Be.set(Ne,Ce),Ve&&Be.set(Ve,Ce),me==="local"?Ge({kind:"move",el:Ce,source:"local"}):at({kind:"move",el:Ce,source:"remote"})),Ce};for(let z of gt.V.units){if(pe.has(z)){let me=Be.get(z);Pe.has(me)||(ke.push(me),Pe.add(me));continue}if(oe.has(z)&&!(Be.get(z)&&Pe.has(Be.get(z)))){let me=gt.V.baseOf(z);me&&!be.has(me)&&y({kind:"structure",el:null,detail:"both-moved",base:me});continue}let Ne=mn(z,gt.V,gt.A,gt.side);Ne&&!Pe.has(Ne)&&(ke.push(Ne),Pe.add(Ne),!gt.V.baseOf(z)&&!tn.has(z)&&!pe.has(z)&&Tt.add(Ne))}for(let z of Ye)Pe.has(z.frag)||(ke.splice(Vn(z.at),0,z.frag),Pe.add(z.frag));if(!gt.other.asBase){let z=gt.other,Ne=gt.otherSide,me=gt.otherA,Le=null,Ve=0,ne=null;for(let xe of z.units){let te=Be.get(xe);if(te&&Pe.has(te)){Le=te,ne=null;continue}if(oe.has(xe)){let Ct=z.baseOf(xe);Ct&&!be.has(Ct)&&y({kind:"structure",el:null,detail:"both-moved",base:Ct});continue}let Ce=mn(xe,z,me,Ne);if(!Ce)continue;let Ue;if(ne)Ue=ke.indexOf(ne)+1;else if(Le){if(Ue=ke.indexOf(Le)+1,Ne==="remote")for(;Ue<ke.length&&Tt.has(ke[Ue]);)Ue++}else Ue=Ve++;ke.splice(Ue,0,Ce),Pe.add(Ce),ne=Ce}}for(let z=0;z<re.length;z++){let Ne=re[z];if(oe.has(Ne))continue;let me=Gt(Ne);me&&ke.splice(Vn(z),0,me)}return ke;function Vn(z){for(let Ne=z-1;Ne>=0;Ne--){let me=Be.get(re[Ne]);if(me){let Le=ke.indexOf(me);if(Le>=0)return Le+1}}return 0}function gn(z){let Ne={ignored:r,remoteWins:()=>!1},me=G=>z(G)||Re(G)&&n.remoteWins(G)&&nn.has(G.tagName)&&pn(G,Ne),Le=new Map,Ve=G=>{if(!Re(G)||!ar.has(G.tagName))return!1;let ae=Le.get(G);return ae===void 0&&(ae=!r(G)&&!n.remoteWins(G)&&c(G).every(me),Le.set(G,ae)),ae},ne=G=>!Re(G)&&G.kind==="text",xe=null,te=new Map,Ce=G=>{let ae=te.get(G);if(ae)return ae;let ye=Re(G)?G.textContent:G.value;ae=new Set;let He=ye.toLowerCase();if(!(ye.length>Yo))if(/^[\x00-\x7f]*$/.test(He))for(let Ie of He.split(/[^\p{L}\p{N}]+/u))Ie&&ae.add(Ie);else for(let Ie of uo(He))/^[\s\p{P}]+$/u.test(Ie)||ae.add(Ie);return te.set(G,ae),ae},Ue=G=>(Re(G)?G.textContent:G.value).toLowerCase().replace(/\s+/g," ").trim(),Ct=new Map,$t=G=>{let ae=Ct.get(G);if(ae)return ae;ae=new Set(Ce(G));let ye=Ie=>{if(Ie)for(let $e of Ce(Ie))ae.add($e)},He=be.has(G)?G:!W.asBase&&W.baseOf(G)||!$.asBase&&$.baseOf(G);return He&&(ye(He),ye(_.map.get(He)),ye(C.map.get(He))),Ct.set(G,ae),ae},on=(G,ae)=>{let ye=Ue(ae),He=be.has(G)?G:!W.asBase&&W.baseOf(G)||!$.asBase&&$.baseOf(G),Ie=mt=>ye?mt.split(ye).length-1:0;if(He&&Re(ae)&&!be.has(ae)){let mt=Ie(Ue(He));for(let bt of[_.map.get(He),C.map.get(He)]){if(!bt||bt===ae||bt.ownerDocument!==ae.ownerDocument)continue;let zt=Ue(bt);if(zt.length>ye.length&&Ie(zt)>=mt&&(zt.startsWith(ye)||zt.endsWith(ye)))return!1}}let $e=Ce(ae),nt=$t(G),Rt=0;for(let mt of $e)nt.has(mt)&&Rt++;if($e.size&&Rt*2>=$e.size)return!0;if(!ye||ye.length>Yo)return!1;let Ut=He?[G,He,_.map.get(He),C.map.get(He)]:[G],Ft=(mt,bt)=>mt!==bt&&(mt.startsWith(bt)||mt.endsWith(bt));if(Ut.some(mt=>mt&&Ft(Ue(mt),ye)))return!0;if(!be.has(ae)||!He)return!1;let vt=Ue(G),Kt=Ue(He);return[_.map.get(ae),C.map.get(ae)].some(mt=>{let bt=mt&&Ue(mt);return!!bt&&vt!==bt&&(vt.startsWith(bt)&&!Kt.startsWith(bt)||vt.endsWith(bt)&&!Kt.endsWith(bt))})},Pt=G=>{xe||(xe=new Set),xe.add(G)},cn=G=>{Pt(G);for(let[ae,ye]of[[_,W],[C,$]]){if(ye.asBase)continue;let He=ae.map.get(G);He&&ye.here(He)&&Pt(He)}},De=(G,ae)=>G.asBase||re.every(ye=>!Re(ye)||ae.identical.has(ye)&&G.here(ae.map.get(ye)))&&G.units.every(ye=>!Re(ye)||G.baseOf(ye));if(De(W,_)&&De($,C))return null;let Ke=G=>{if(G.asBase)return!1;let ae=-1;for(let ye of G.units){let He=Re(ye)?G.baseOf(ye):null;if(!He||!be.has(He))continue;let Ie=de.get(He);if(Ie<ae)return!0;ae=Ie}return!1};if(Ke(W)||Ke($))return null;for(let[G,ae]of[[W,_],[$,C]]){if(G.asBase||De(G,ae))continue;let ye=G.units,He=ae===_?h.local:h.remote,Ie=(le,qe)=>{let ft=Re(le)&&h.base(le),et=Re(qe)&&He(qe);return!ft||!et||ft===et},$e=new Map;for(let le=0;le<ye.length;le++)$e.set(ye[le],le);let nt=le=>!!le&&(Re(le)?G.here(le):$e.has(le)),Rt=le=>{let qe=G.twin(le);return nt(qe)?qe:null},Ut=re.filter(le=>!G.twin(le)&&Ve(le)),Ft=ye.filter(le=>!G.baseOf(le)&&Ve(le)),vt=(le,qe)=>qe===re?!!Rt(le):be.has(G.baseOf(le)),Kt=le=>{let qe=new Int32Array(le.length),ft=new Int32Array(le.length),et=-1;for(let Je=0;Je<le.length;Je++)qe[Je]=et,vt(le[Je],le)&&(et=Je);et=le.length;for(let Je=le.length-1;Je>=0;Je--)ft[Je]=et,vt(le[Je],le)&&(et=Je);return{prev:qe,next:ft}},mt=Kt(ye),bt=Kt(re),zt=(le,qe)=>{cn(le),Pt(qe)};for(let le of Ft){let qe=$e.get(le),ft=mt.prev[qe],et=mt.next[qe],Je=ft>=0?G.baseOf(ye[ft]):null,Qt=et<ye.length?G.baseOf(ye[et]):null,Yt=Je?de.get(Je):-1,ln=Qt?de.get(Qt):re.length;for(let qt=Math.max(0,Yt);qt<=Math.min(ln,re.length-1);qt++){let Dt=re[qt];(Ve(Dt)||ne(Dt))&&(!Ie(Dt,le)||!on(Dt,le)||(ne(Dt)?Pt(le):zt(Dt,le)))}}let Xt=(le,qe,ft)=>{for(let et=qe+ft;et>=0&&et<le.length;et+=ft){let Je=le[et];if(Ve(Je))return Je;if(Re(Je)||Je.value.trim())return null}return null},Fn=le=>{let qe=new Set;for(let ft of c(le))if(!Re(ft)&&ft.kind==="text")for(let et of Ce(ft))qe.add(et);return qe},En=(le,qe)=>{let ft=Ce(qe),et=new Set;for(let Je of Fn(le))ft.has(Je)||et.add(Je);return et},Rn=(le,qe)=>{if(!le.size)return!1;let ft=Ce(qe),et=0;for(let Je of le)ft.has(Je)&&et++;return et*2>=le.size};for(let le of re){if(ae.identical.has(le)||!Ve(le))continue;let qe=Rt(le);if(!qe||!Ve(qe))continue;let ft=En(qe,le),et=En(le,qe);for(let Je of[-1,1]){let Qt=Xt(re,de.get(le),Je);Qt&&Rn(ft,Qt)&&(zt(le,qe),cn(Qt));let Yt=Xt(ye,$e.get(qe)??-1,Je);if(Yt&&Rn(et,Yt)){zt(le,qe);let ln=G.baseOf(Yt);ln?zt(ln,Yt):Pt(Yt)}}}for(let le of Ut){let qe=de.get(le),ft=bt.prev[qe],et=bt.next[qe],Je=ft>=0?Rt(re[ft]):null,Qt=et<re.length?Rt(re[et]):null,Yt=Je?$e.get(Je)??-1:-1,ln=Qt?$e.get(Qt)??-1:ye.length;for(let qt=Math.max(0,Yt);qt<=Math.min(ln,ye.length-1);qt++){let Dt=ye[qt];if((Ve(Dt)||ne(Dt))&&!(!Ie(le,Dt)||!on(Dt,le))&&(cn(le),!ne(Dt))){let Vt=G.baseOf(Dt);Vt?zt(Vt,Dt):Pt(Dt)}}}}if(!xe)return null;for(let G of Array.from(xe))if(be.has(G))for(let ae of[_,C]){let ye=ae.map.get(G);ye&&ye.parentNode!==(ae===_?L:B)&&!(ae===_?W:$).asBase&&xe.delete(G)}return xe.size?xe:null}function Wn(){if((W.asBase||_.identical.has(g))&&($.asBase||C.identical.has(g)))return;let z={ignored:r,remoteWins:n.remoteWins,inlineCache:dt},Ne=De=>Re(De)?pn(De,z):De.kind==="text",me=gn(Ne),Le=De=>me&&me.has(De)||Ne(De),Ve=re.map(Le);if(!Ve.includes(!0))return;let ne=De=>{let Ke=De.units,G=new Map;for(let nt=0;nt<Ke.length;nt++)G.set(Ke[nt],nt);let ae=[],ye=-1;for(let nt=0;nt<re.length;nt++){if(Ve[nt])continue;let Rt=De.twin(re[nt]),Ut=Rt?G.get(Rt):void 0;Ut===void 0||Ut<=ye||Le(Rt)||(ae.push([nt,Ut]),ye=Ut)}let He=[],Ie=-1,$e=-1;for(let nt=0;nt<=ae.length;nt++){let[Rt,Ut]=nt<ae.length?ae[nt]:[re.length,Ke.length],Ft={bLo:-1,bHi:-1,sLo:-1,sHi:-1,next:Ut};for(let vt=Ie+1;vt<Rt;vt++)Ve[vt]&&(Ft.bLo<0&&(Ft.bLo=vt),Ft.bHi=vt);for(let vt=$e+1;vt<Ut;vt++)Le(Ke[vt])&&(Ft.sLo<0&&(Ft.sLo=vt),Ft.sHi=vt);He.push(Ft),Ie=Rt,$e=Ut}return{units:Ke,list:He}},xe=ne(W),te=ne($),Ce=[];for(let De of[xe,te])for(let Ke of De.list)Ke.bLo>=0&&Ce.push([Ke.bLo,Ke.bHi]);Ce.sort((De,Ke)=>De[0]-Ke[0]);let Ue=[];for(let[De,Ke]of Ce){let G=Ue[Ue.length-1];G&&De<=G.hi?G.hi=Math.max(G.hi,Ke):Ue.push({lo:De,hi:Ke})}let Ct=(De,Ke)=>{let G=-1,ae=-1;for(let Ie=0;Ie<De.list.length;Ie++){let $e=De.list[Ie];$e.bLo<Ke.lo||$e.bLo>Ke.hi||(G<0&&(G=Ie),ae=Ie)}let ye=1/0,He=-1;for(let Ie=G;Ie>=0&&Ie<=ae;Ie++){let $e=De.list[Ie];$e.sLo>=0&&(ye=Math.min(ye,$e.sLo),He=Math.max(He,$e.sHi)),Ie<ae&&(ye=Math.min(ye,$e.next),He=Math.max(He,$e.next))}return He<0?[]:De.units.slice(ye,He+1)},$t=(De,Ke)=>De.length===Ke.length&&De.every((G,ae)=>l.unitHash(G)===l.unitHash(Ke[ae])),on=De=>!Re(De)&&De.kind==="comment",Pt=De=>{if(!De.length)return[];let Ke=(Ie,$e)=>Re(Ie)?Ie:Ie.nodes[$e?Ie.nodes.length-1:0],G=Ke(De[0]),ae=Ke(De[De.length-1],!0),ye=Ie=>Ie&&Re(Ie)&&r(Ie);for(;ye(G.previousSibling);)G=G.previousSibling;for(;ye(ae.nextSibling);)ae=ae.nextSibling;let He=[];for(let Ie=G;Ie&&(He.push(Ie),Ie!==ae);Ie=Ie.nextSibling);return He},cn=De=>De.some(Ke=>Re(Ke)&&r(Ke));for(let De of Ue){let Ke=re.slice(De.lo,De.hi+1),G=W.asBase?null:Ct(xe,De),ae=$.asBase?null:Ct(te,De);if(Ke.some(on)||G&&G.some(on)||ae&&ae.some(on))continue;let ye=Pt(G||Ke),He=Pt(ae||Ke);if((!G||$t(Ke,G))&&(!ae||$t(Ke,ae))&&!(G&&cn(ye)))continue;let Ie=ko({base:Pt(Ke),local:ye,remote:He,out:fe,policy:ze,blocks:me,L:G?_:Jo(_,g),R:ae?C:Jo(C,g),idOf:{local:T,remote:p},ignored:r,ignoreAttribute:n.ignoreAttribute,remoteWins:n.remoteWins,mergeElement:(nt,Rt,Ut)=>b(nt,Rt,Ut,!1),cloneUnit:Te,mergeAttrs:O,atomKey:l.unitHash,moveIn:ht,provenance:J,textMappers:he,conflicts:ct,decisions:Se,node:U});lt.push(...Ie.segments);let $e=fe.createDocumentFragment();for(let nt of Ie.nodes)$e.appendChild(nt);for(let nt of[...Ke,...G||[],...ae||[]])oe.add(nt),pe.add(nt),Be.set(nt,$e);Ye.push({frag:$e,at:De.lo})}}}function wt(g,L){let B=J.get(g);return B&&B.unchanged?!0:g.tagName!==L.tagName||!ue(g,L)?!1:Ze(pt(g),pt(L))}function pt(g){return g.tagName==="TEMPLATE"&&g.content?g.content:g}function ue(g,L){let B=0;for(let F of g.attributes)if(!n.ignoreAttribute(g,F.name)&&(B++,L.getAttribute(F.name)!==F.value))return!1;for(let F of L.attributes)n.ignoreAttribute(L,F.name)||B--;return B===0}function Ze(g,L){let B=Et(g,U=>{let W=J.get(U);return!!(W&&W.pinned)}),F=Et(L,r);if(B.length!==F.length)return!1;for(let U=0;U<B.length;U++){let W=B[U],$=F[U];if(typeof W=="string"||typeof $=="string"){if(W!==$)return!1}else{if(W.nodeType!==$.nodeType)return!1;if(W.nodeType===1){if(!wt(W,$))return!1}else if(W.nodeValue!==$.nodeValue)return!1}}return!0}function Et(g,L){let B=[],F=null;for(let U=g.firstChild;U;U=U.nextSibling){if(U.nodeType===3){F=F===null?U.nodeValue:F+U.nodeValue;continue}U.nodeType===1&&L(U)||(F!==null&&(F!==""&&B.push(F),F=null),B.push(U))}return F!==null&&F!==""&&B.push(F),B}function At(g,L,B,F){let U=g.value,W=F?U:L?L.value:"",$=B?B.value:"";oe.add(g),L&&oe.add(L),B&&oe.add(B);let re=W===$?W:W===U?$:$===U||ze==="local"?W:$;if(W!==U&&$!==U&&W!==$&&y({kind:"text",node:null,base:U,local:W,remote:$,resolved:re}),!L&&!B)return null;let be=fe.createComment(re);return J.set(be,{base:g.nodes,local:L?L.nodes:null,remote:B?B.nodes:null}),be}function Bt(g,L){let B=L.map.get(g);if(!B)return null;let F=Re(B)?B.parentNode:B.parent,U=Re(g)?g.parentNode:g.parent;return L.map.get(U)===F?null:L.reverse.get(F)||null}function jt(g){let L=new Set([g]),B=g;for(let F=0;F<64;F++){let U=Bt(B,_)||Bt(B,C);if(!U)return!1;if(U===g||Re(g)&&Re(U)&&g.contains(U)||L.has(U))return!0;L.add(U),B=U}return!0}function Nt(g,L,B){if(!L)return!1;let F=Re(g)?g.parentNode:g.parent;return F===L||L.tagName==="TEMPLATE"&&F===L.content}function St(g,L){let B=Re(g)?g.parentNode:g.parent,F=Re(L)?L.parentNode:L.parent;return!!(_.map.get(B)===F?_:C.map.get(B)===F?C:null)}}function Jo(e,s){return e.map.get(s)?Xo():{map:{get:n=>n&&n.nodeType===1&&e.map.get(n)||n,has:()=>!0},reverse:{get:n=>e.reverse.get(n)||n,has:()=>!0},moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}function Xo(){let e={get:s=>s,has:()=>!0};return{map:e,reverse:e,moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}var Qo=new Set(["INPUT","OPTION","TEXTAREA"]);function Zo(e,s,o,n){let r=e.ownerDocument,{provenance:l,textMappers:c}=o,f=n.hooks,u=[],v=[],N=[],A=new Set,T=[],p=[],h=new Set,x=new Map,R=i=>!!i&&(i===e||e.contains(i)||e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content.contains(i)),M=new Map,D=new Map,K=new Map,ie=new Map;(function i(k){let b=l.get(k);if(b){if(k.nodeType===1){let I=b.local?n.toLive(b.local):null;I&&R(I)&&I.nodeType===1&&(M.set(k,I),D.set(I,k))}else if(Array.isArray(b.local)){let I=_(b.local,b.local.map(O=>n.toLive(O)).filter(O=>O&&R(O)&&O.nodeType===k.nodeType));if(I.length&&(M.set(k,I[0]),D.set(I[0],k),K.set(k,I)),Array.isArray(b.caret))for(let O of b.caret){let j=n.toLive(O.node);if(!j||!R(j)||j.nodeType!==3)continue;let S=ie.get(j);Array.isArray(S)||ie.set(j,S=[]),S.push({merged:k,from:O.from,to:O.to,flatStart:O.flatStart})}else{let O=0;for(let j of I)ie.set(j,{merged:k,shift:O}),O+=j.nodeValue.length}}}let V=k.nodeType===1&&k.tagName==="TEMPLATE"&&k.content?k.content.childNodes:k.childNodes;for(let I of V)i(I)})(s);let ge=new Set;for(let i of M.values())ge.add(i);for(let i of K.values())for(let k of i)ge.add(k);for(let i of o.segments||[])C(i);let Me=n.restoreFocus===!1?null:fr(r,ie);n.childrenOnly?Se(fe(e),fe(s)):J(e,s);for(let{node:i,parent:k}of T)A.has(i)||!i.parentNode||i.nodeType===1&&(n.ignored(i)||ct(i))||at(i,k);return ur(r,Me,ie,c,K,x),{applied:u,moved:v,replaced:N,identities:p,mergedScriptsLive:h,liveOf:M};function Ae(i,k){let b=i.slice(k.bs,k.be),V=0;for(;V<b.length&&V<k.text.length&&b[V]===k.text[V];)V++;let I=0;for(;I<b.length-V&&I<k.text.length-V&&b[b.length-1-I]===k.text[k.text.length-1-I];)I++;return{bs:k.bs+V,be:k.be-I,text:k.text.slice(V,k.text.length-I)}}function _(i,k){if(!k.length)return k;let b=new Set;for(let I of i){let O=I.parentNode;if(O)for(let j=O.firstChild;j;j=j.nextSibling)j.nodeType===3&&b.add(n.toLive(j))}let V=[];for(let I of k){V.push(I);for(let O=I.nextSibling;O&&O.nodeType===3&&!b.has(O)&&!V.includes(O);O=O.nextSibling)V.push(O)}return V}function C(i){let k=[];for(let ue of i.localNodes){let Ze=n.toLive(ue.node);if(!Ze||!R(Ze)||Ze.nodeType!==3)return;k.push(Ze)}let b=_(i.localNodes.map(ue=>ue.node),k);if(!b.length)return;let V=b.map(ue=>ue.nodeValue).join(""),{flatLocal:I,lToM:O,mapLocal:j}=i;if(V===I)return;let S=i.textNodes.map(ue=>({node:ue.node,ms:ue.ms,me:ue.me})),P=[],X=0;for(let ue of b)P.push(X),X+=ue.nodeValue.length;let ee=(ue,Ze)=>b.find((Et,At)=>P[At]<=ue&&ue+Ze<=P[At]+Et.nodeValue.length)||null,Te=[],tt=0;for(let ue of An(I,V).map(Ze=>Ae(I,Ze))){let Ze=ue.bs+tt;tt+=ue.text.length-(ue.be-ue.bs);let Et,At;if(ue.be>ue.bs){Et=O[ue.bs];let Bt=Et>=0;for(let jt=ue.bs;Bt&&jt<ue.be;jt++)O[jt]!==Et+(jt-ue.bs)&&(Bt=!1);if(!Bt)continue;At=Et+(ue.be-ue.bs)}else{let Bt=ue.bs>0?O[ue.bs-1]:0,jt=ue.bs<I.length?O[ue.bs]:0;if(Bt<0||jt<0)continue;Et=At=j(ue.bs)}Te.push({ms:Et,me:At,text:ue.text,live:At===Et?ee(Ze,ue.text.length):null})}Te.sort((ue,Ze)=>Ze.ms-ue.ms);let wt=(ue,Ze)=>(K.get(ue.node)||[M.get(ue.node)]).includes(Ze),pt=ue=>!!ue&&ue.nodeType===1&&nn.has(ue.tagName);for(let ue of Te){let Ze=S.find(At=>At.ms<=ue.ms&&ue.me<=At.me&&ue.ms<At.me);if(Ze&&ue.live&&Ze.ms===ue.ms&&!wt(Ze,ue.live)){let At=S.find(Bt=>Bt.me===ue.ms&&wt(Bt,ue.live));At&&(Ze=At)}if(!Ze&&ue.me===ue.ms){let At=S.find(St=>St.me===ue.ms),Bt=S.find(St=>St.ms===ue.ms),jt=At||Bt;if(!jt)continue;let Nt=jt.node;for(;pt(Nt.parentNode)&&(At?Nt.parentNode.lastChild:Nt.parentNode.firstChild)===Nt;)Nt=Nt.parentNode;if(Nt===jt.node)Ze=jt;else{let St=Nt.ownerDocument.createTextNode(ue.text);Nt.parentNode.insertBefore(St,At?Nt.nextSibling:Nt);continue}}if(!Ze)continue;let Et=Ze.node.nodeValue;Ze.node.nodeValue=Et.slice(0,ue.ms-Ze.ms)+ue.text+Et.slice(ue.me-Ze.ms),Ze.me+=ue.text.length-(ue.me-ue.ms)}}function fe(i){return i.nodeType===1&&i.tagName==="TEMPLATE"&&i.content?i.content:i}function J(i,k){A.add(i);let b=l.get(k);if(b&&b.remote&&o.remoteIdOf){let I=o.remoteIdOf(b.remote);I&&p.push([i,I])}if(b&&b.unchanged){o.customIdentity&&b.remote&&We(i,b.remote),b.remote&&oe(i,b.remote);return}if(f.beforeNodeMorphed(i,k)===!1)return;se(i,k);let V=i.tagName;if(_t(i))i.textContent!==k.textContent&&(u.push({kind:"text",node:i,before:i.textContent,after:k.textContent}),i.textContent=k.textContent),o.mergedScripts.has(k)&&h.add(i);else if(V==="TEXTAREA")ht(i,k,b);else{Qe(i,k,b);let I=V==="TEMPLATE"&&i.content?i.content:i,O=V==="TEMPLATE"&&k.content?k.content:k;n.protectFocusedValue==="subtree"&&Oe(i)&&i!==r.body?he(I):Se(I,O)}f.afterNodeMorphed(i,k)}function he(i){for(let k=i.firstChild;k;k=k.nextSibling){let b=D.get(k);b&&M.get(b.parentNode)!==i||(A.add(k),k.nodeType===1&&he(k))}}function Se(i,k){let b=ze(i.firstChild),V=new Set;for(let I of Array.from(k.childNodes)){let O=M.get(I);O&&A.has(O)&&!V.has(O)&&(O=null);let j=l.get(I);if(j&&j.pinned){O&&O.nodeType===1&&((O.parentNode!==i||ze(O.nextSibling)!==b)&&Ge(i,O,b),A.add(O),V.add(O));continue}if(O&&O.nodeType===1){if(O!==b){let X=O.parentNode;if(X===i&&b&&rt(O)){let ee=O.nextSibling;for(let Te=b;Te&&Te!==O;){let tt=Te.nextSibling;Ge(i,Te,ee),Te=tt}}else Ge(i,O,b),X!==i&&(v.push(O),u.push({kind:"move",el:O,from:X,to:i}))}V.add(O),J(O,I),b=ze(O.nextSibling);continue}if(O&&O.nodeType!==1){let X=K.get(I)||[O];O!==b&&Ge(i,O,b);let ee=I.nodeValue;if(I.nodeType===3){let Te=ot(I),tt=X.map(wt=>wt.nodeValue).join("");Te!=null&&tt!==Te&&(ee=wn(Te,tt,I.nodeValue).text)}f.beforeNodeMorphed(O,I)!==!1&&(O.nodeValue!==ee&&(u.push({kind:"text",node:O,before:O.nodeValue,after:ee}),O.nodeValue=ee),f.afterNodeMorphed(O,I)),A.add(O),V.add(O),x.set(I,O),b=ze(O.nextSibling);continue}if(I.nodeType===3&&b&&b.nodeType===3&&!A.has(b)&&!ie.has(b)){b.nodeValue!==I.nodeValue&&(u.push({kind:"text",node:b,before:b.nodeValue,after:I.nodeValue}),b.nodeValue=I.nodeValue),A.add(b),x.set(I,b),b=ze(b.nextSibling);continue}let S=l.get(I),P=y(S&&S.unchanged&&S.remote?S.remote:I);f.beforeNodeAdded(P)!==!1&&(i.insertBefore(P,b),A.add(P),P.nodeType===3&&x.set(I,P),P.nodeType===1&&(N.push(P),dt(P,I),_t(P)||H(P,I),n.formState==="property"&&Xe(S)&&oe(P,S.remote)),b=ze(P.nextSibling),u.push({kind:"insert",node:P,parent:i}),f.afterNodeAdded(P))}for(let I of Array.from(i.childNodes))A.has(I)||V.has(I)||I.nodeType===1&&(n.ignored(I)||ct(I))||(ge.has(I)?T.push({node:I,parent:i}):at(I,i))}function ct(i){return n.preserve&&i.parentNode&&i.parentNode.nodeType===1&&i.parentNode.tagName==="HEAD"&&n.preserve(i)===!0}function ot(i){let k=l.get(i);return!k||!Array.isArray(k.local)?null:k.local.map(b=>b.nodeValue).join("")}function lt(i){return l.get(i)}function oe(i,k){if(!Qo.has(i.tagName)&&!i.querySelector("input,option,textarea"))return;let b=(V,I)=>{if(V.tagName!==I.tagName)return;V.tagName==="TEXTAREA"?ht(V,I,{remote:I}):Qo.has(V.tagName)&&Qe(V,I,{remote:I});let O=Fe(V),j=Fe(I);if(O.length===j.length)for(let S=0;S<O.length;S++)b(O[S],j[S])};b(i,k)}function We(i,k){let b=Fe(i),V=Fe(k);if(b.length===V.length)for(let I=0;I<b.length;I++){let O=o.remoteIdOf(V[I]);O&&p.push([b[I],O]),We(b[I],V[I])}}function Fe(i){let k=i.tagName==="TEMPLATE"&&i.content?i.content:i;return Array.from(k.children).filter(b=>!n.ignored(b))}function dt(i,k){if(!o.remoteIdOf)return;let b=(V,I)=>{let O=l.get(I);if(O&&O.remote&&I.nodeType===1){let P=o.remoteIdOf(O.remote);P&&p.push([V,P])}let j=V.childNodes,S=I.childNodes;for(let P=0;P<j.length&&P<S.length;P++)b(j[P],S[P])};b(i,k)}function ze(i){for(;i&&i.nodeType===1&&n.ignored(i);)i=i.nextSibling;return i}function Ge(i,k,b){if(typeof i.moveBefore=="function"&&k.ownerDocument===i.ownerDocument)try{i.moveBefore(k,b);return}catch{}i.insertBefore(k,b)}function at(i,k){f.beforeNodeRemoved(i)!==!1&&(i.parentNode.removeChild(i),u.push({kind:"remove",node:i,parent:k}),f.afterNodeRemoved(i))}function y(i){if(_t(i))return Bn(i,r);let k=r.importNode(i,!0);if(k.nodeType===1)for(let b of Array.from(k.querySelectorAll("script")))_t(b)&&b.replaceWith(Bn(b,r));return k}function H(i,k){let b=i.tagName==="TEMPLATE"&&i.content?i.content:i,V=k.tagName==="TEMPLATE"&&k.content?k.content:k,I=Array.from(b.childNodes),O=Array.from(V.childNodes);for(let j=0;j<O.length&&j<I.length;j++){let S=O[j],P=I[j],X=M.get(S);X&&A.has(X)&&(X=null);let ee=l.get(S);if(ee&&ee.pinned){if(X&&X.nodeType===1){let Te=X.parentNode;Ge(b,X,P),Te!==b&&(v.push(X),u.push({kind:"move",el:X,from:Te,to:b})),A.add(X)}P.remove();continue}if(X){let Te=X.parentNode;Ge(b,X,P),P.remove(),X.nodeType===1?(Te!==b&&(v.push(X),u.push({kind:"move",el:X,from:Te,to:b})),J(X,S)):(A.add(X),x.set(S,X),X.nodeValue!==S.nodeValue&&(u.push({kind:"text",node:X,before:X.nodeValue,after:S.nodeValue}),X.nodeValue=S.nodeValue));continue}A.add(P),P.nodeType===3&&x.set(S,P),S.nodeType===1&&!_t(S)&&H(P,S)}}function se(i,k){for(let b of Array.from(k.attributes)){if(Z(i,b.name)||n.ignoreAttribute(i,b.name))continue;let V=b.namespaceURI?i.getAttributeNS(b.namespaceURI,b.localName):i.getAttribute(b.name);V!==b.value&&f.beforeAttributeUpdated(b.name,i,"update")!==!1&&(b.namespaceURI?i.setAttributeNS(b.namespaceURI,b.name,b.value):i.setAttribute(b.name,b.value),u.push({kind:"attr",el:i,name:b.name,before:V,after:b.value}))}for(let b of Array.from(i.attributes)){if(Z(i,b.name)||n.ignoreAttribute(i,b.name)||(b.namespaceURI?k.hasAttributeNS(b.namespaceURI,b.localName):k.hasAttribute(b.name))||f.beforeAttributeUpdated(b.name,i,"remove")===!1)continue;let I=b.value;b.namespaceURI?i.removeAttributeNS(b.namespaceURI,b.localName):i.removeAttribute(b.name),u.push({kind:"attr",el:i,name:b.name,before:I,after:null})}}function Z(i,k){let b=i.tagName;return b==="INPUT"?k==="value"||k==="checked"||k==="disabled":b==="OPTION"?k==="selected":!1}function Oe(i){return i===r.activeElement}function rt(i){let k=r.activeElement;return!!k&&k!==r.body&&i.contains(k)}function Xe(i){let k=i&&i.remote;return k&&k.nodeType===1?k:null}function Qe(i,k,b){let V=i.tagName,I=Xe(b),O=n.formState==="property"&&I?I:k;if(V==="INPUT"){let j=n.protectFocusedValue&&Oe(i),S=(i.getAttribute("type")||"").toLowerCase(),P=S!=="file"&&S!=="checkbox"&&S!=="radio",X=I&&I.hasAttribute("value")&&I.value!==I.getAttribute("value")?I.value:null;if(P&&!j)if(n.formState==="property"){let ee=k.getAttribute("value"),Te=i.getAttribute("value");(Te!==ee||i.value!==O.value)&&f.beforeAttributeUpdated("value",i,ee==null?"remove":"update")!==!1&&(Te!==ee&&(ee==null?i.removeAttribute("value"):i.setAttribute("value",ee),u.push({kind:"attr",el:i,name:"value",before:Te,after:ee})),i.value!==O.value&&(i.value=O.value))}else if(k.hasAttribute("value")||X!=null){let ee=X??k.getAttribute("value");i.getAttribute("value")!==ee&&f.beforeAttributeUpdated("value",i,"update")!==!1?(i.setAttribute("value",ee),i.value!==ee&&(i.value=ee),u.push({kind:"attr",el:i,name:"value",before:null,after:ee})):i.value!==ee&&i.getAttribute("value")===ee&&(i.value=ee)}else(i.hasAttribute("value")||i.value!=="")&&f.beforeAttributeUpdated("value",i,"remove")!==!1&&(i.removeAttribute("value"),i.value="",u.push({kind:"attr",el:i,name:"value",before:"",after:null}));if(!P&&S!=="file"){let ee=k.getAttribute("value");ee==null?i.hasAttribute("value")&&f.beforeAttributeUpdated("value",i,"remove")!==!1&&i.removeAttribute("value"):i.getAttribute("value")!==ee&&f.beforeAttributeUpdated("value",i,"update")!==!1&&i.setAttribute("value",ee)}j||(st(i,O,"checked"),n.formState==="property"&&i.indeterminate!==O.indeterminate&&(i.indeterminate=O.indeterminate)),st(i,O,"disabled")}else if(V==="OPTION"){let j=i.parentNode&&i.closest("select");n.protectFocusedValue&&j&&Oe(j)||st(i,O,"selected")}}function st(i,k,b){let V=n.formState==="property"?!!k[b]:k.hasAttribute(b);if(n.formState!=="property"){let I=i.hasAttribute(b);if(I!==V){if(f.beforeAttributeUpdated(b,i,V?"update":"remove")===!1)return;V?i.setAttribute(b,""):i.removeAttribute(b),u.push({kind:"attr",el:i,name:b,before:I?"":null,after:V?"":null})}}i[b]!==V&&(i[b]=V)}function ht(i,k,b){if(n.protectFocusedValue&&Oe(i)||f.beforeAttributeUpdated("value",i,"update")===!1)return;let V=Xe(b),I=k.textContent,O=V&&V.value!==V.defaultValue?V.value:I;n.formState!=="property"&&i.textContent!==I&&(u.push({kind:"text",node:i,before:i.textContent,after:I}),i.textContent=I),i.value!==O&&(i.value=O)}}function fr(e,s){let o=e.activeElement;if(!o||o===e.body||o===e.documentElement)return null;let n={el:o,id:o.getAttribute&&o.getAttribute("id"),scrollTop:o.scrollTop,scrollLeft:o.scrollLeft};if(o.tagName==="INPUT"||o.tagName==="TEXTAREA"){try{n.selection=[o.selectionStart,o.selectionEnd,o.selectionDirection]}catch{}return n}let r=e.getSelection&&e.getSelection();if(r&&r.rangeCount){let l=r.getRangeAt(0);n.range={sc:l.startContainer,so:l.startOffset,ec:l.endContainer,eo:l.endOffset}}return n}function ur(e,s,o,n,r,l){if(!s)return;let c=s.el;if(!c.isConnected&&s.id&&(c=e.getElementById(s.id)),!c||!c.isConnected)return;if(e.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}try{c.scrollTop=s.scrollTop,c.scrollLeft=s.scrollLeft}catch{}if(s.selection){try{c.setSelectionRange&&!c.selectionEnd&&s.selection[1]!=null&&c.setSelectionRange(s.selection[0],s.selection[1],s.selection[2]||"none")}catch{}return}if(!s.range)return;let f=(N,A)=>{let T=o.get(N);if(Array.isArray(T)){let p=T.find(M=>A>=M.from&&A<M.to)||T.find(M=>A===M.to)||T[T.length-1],h=l.get(p.merged);if(!h||!h.isConnected)return null;let x=n.get(p.merged),R=x&&x.flat?x.flat(p.flatStart+A):A;return[h,Math.max(0,Math.min(R,h.nodeValue.length))]}if(T){let p=(r.get(T.merged)||[N])[0];if(!p.isConnected)return null;let h=n.get(T.merged),x=T.shift+A,R=h?h(x):x;return[p,Math.max(0,Math.min(R,p.nodeValue.length))]}return N.isConnected?[N,Math.min(A,N.nodeType===3?N.nodeValue.length:N.childNodes.length)]:null},u=f(s.range.sc,s.range.so),v=f(s.range.ec,s.range.eo);if(!(!u||!v))try{let N=e.createRange();N.setStart(u[0],u[1]),N.setEnd(v[0],v[1]);let A=e.getSelection();A.removeAllRanges(),A.addRange(N)}catch{}}var es=Symbol("hyper-morph-duplicate-key"),ts=[e=>e.getAttribute("data-id"),e=>e.getAttribute("id")];function Pn(e,s){return s.map(o=>{let n=new Map;for(let r of e){if(r.nodeType!==1)continue;let l=o(r);l==null||l===""||n.set(l,n.has(l)?es:r)}return n})}function ns(e,s,o,n){for(let r=0;r<n.length;r++){let l=n[r](e);if(l==null||l===""||s[r].get(l)!==e)continue;let c=o[r].get(l);if(!(!c||c===es)&&c.tagName===e.tagName)return c}return null}function vn(e,s,o){for(let n=0;n<o.length;n++){let r=o[n](e);if(!(r==null||r==="")&&s[n].get(r)===e)return!0}return!1}function os(e,s,o={}){let n=o.skip||(()=>!1),r=o.ignoreAttr||(()=>!1),l=o.tiers&&o.tiers.length?o.tiers:ts,c=null;function f(){return c||(c=Pn([e,...e.querySelectorAll("*")],l)),c}let u=null;function v(){return u||(u=Pn([s,...s.querySelectorAll("*")],l)),u}function N(C){return!C.parentElement||!C.parentElement.parentElement}function A(C,fe,J){return N(C)||vn(C,f(),l)?(J.push({type:"subtree",el:C,base:fe}),!1):!0}function T(C,fe){let J=[];for(let he of C.attributes)r(C,he.name)||fe.getAttribute(he.name)!==he.value&&J.push(he.name);for(let he of fe.attributes)r(C,he.name)||C.hasAttribute(he.name)||J.push(he.name);return J}function p(C){let fe=[],J=null,he=()=>{J!==null&&(fe.push({nodeType:3,nodeValue:J}),J=null)};for(let Se of C.childNodes){if(Se.nodeType===3){J=(J===null?"":J)+Se.nodeValue;continue}Se.nodeType===1&&n(Se)||(he(),(Se.nodeType===1||Se.nodeType===8)&&fe.push(Se))}return he(),fe}function h(C,fe){if(C.nodeType!==fe.nodeType)return!1;if(C.nodeType!==1)return!0;if(C.tagName!==fe.tagName)return!1;for(let J of l){let he=J(C),Se=J(fe);if(he!=null&&he!==""&&Se!=null&&Se!==""&&he!==Se)return!1}return!0}function x(C){let fe="";for(let J of C)J.nodeType===3&&J.nodeValue.trim()!==""?fe+="\0"+J.nodeValue:J.nodeType===8&&(fe+=""+J.nodeValue);return fe}function R(C,fe,J){let he=p(C),Se=p(fe);if(he.length===Se.length){let H=!0;for(let se=0;se<he.length;se++)if(!h(he[se],Se[se])){H=!1;break}if(H){for(let se=0;se<he.length;se++){let Z=he[se];if(Z.nodeType===1){if(M(Z,Se[se],J))return!0}else if(Z.nodeValue!==Se[se].nodeValue)return!0}return!1}}let ct=he.filter(H=>H.nodeType===1),ot=Se.filter(H=>H.nodeType===1);if(x(he)!==x(Se))return!0;let lt=Pn(ct,l),oe=Pn(ot,l),We=[],Fe=new Set,dt=[];for(let H of ct){let se=ns(H,lt,oe,l);se&&!Fe.has(se)?(We.push([H,se]),Fe.add(se)):dt.push(H)}let ze=[];for(let H of dt)vn(H,lt,l)?J.push({type:"subtree",el:H,base:null}):ze.push(H);let Ge=[];for(let H of ot)Fe.has(H)||(vn(H,oe,l)?J.push({type:"deletion",el:H}):Ge.push(H));if(ze.length!==Ge.length)return!0;for(let H=0;H<ze.length;H++)if(!h(ze[H],Ge[H]))return!0;let at=new Map(We);for(let H=0;H<ze.length;H++)at.set(ze[H],Ge[H]);let y=-1;for(let H of ct){let se=at.get(H);if(!se)continue;let Z=ot.indexOf(se);if(Z<y)return!0;y=Z}for(let H=0;H<ze.length;H++)if(M(ze[H],Ge[H],J))return!0;for(let[H,se]of We)if(M(H,se,J))return!0;return!1}function M(C,fe,J){if(C.tagName!==fe.tagName)return A(C,fe,J);let he=T(C,fe),Se=[];if(R(C,fe,Se))return A(C,fe,J);if(he.length){if(!N(C)&&!vn(fe,v(),l))return!0;J.push({type:"attrs",el:C,names:he,base:fe})}return J.push(...Se),!1}let D=[],K=T(e,s);K.length&&D.push({type:"attrs",el:e,names:K});let ie=(C,fe)=>Array.from(C.children).find(J=>J.tagName===fe)||null,ge=ie(e,"HEAD"),Me=ie(s,"HEAD");if(ge&&Me){let C=[];M(ge,Me,C),C.length&&D.push({type:"head",el:ge})}else(ge||Me)&&ge&&D.push({type:"head",el:ge});let Ae=ie(e,"BODY"),_=ie(s,"BODY");return Ae&&_?M(Ae,_,D):Ae&&D.push({type:"subtree",el:Ae,base:null}),{entries:D}}function ss(e,s,o={}){let n=o.tiers&&o.tiers.length?o.tiers:ts,r=e.documentElement,l=[],c=0,f=M=>({ok:!1,placed:l,held:M,skippedAttrs:c});if(!r)return f(null);function u(M){let D=[M,...M.querySelectorAll("*")];return Pn(D,n)}let v=u(r),N=new Map,A=M=>{let D=M.getRootNode(),K=N.get(D);if(!K){let ie=D.nodeType===9?D.documentElement:D;K=u(ie),N.set(D,K)}return K};function T(M){if(!M.parentElement&&M.tagName==="HTML")return r;if(M.parentElement&&!M.parentElement.parentElement&&M.parentElement.tagName==="HTML"){if(M.tagName==="BODY")return e.body||null;if(M.tagName==="HEAD")return e.head||null}return null}function p(M){let D=T(M);return D||ns(M,A(M),v,n)}function h(M){if(!M)return null;let D=p(M);return D&&D.isConnected?D:null}function x(M){for(let D=0;D<n.length;D++){let K=n[D](M);K!=null&&K!==""&&v[D].set(K,M)}}for(let M of s){if(M.type!=="deletion")continue;let D=p(M.el);D&&D!==r&&D.remove()}let R=s.filter(M=>M.type!=="deletion").sort((M,D)=>M.el===D.el?0:M.el.compareDocumentPosition(D.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let M of R){if(M.type==="head"){let _=e.importNode(M.el,!0);e.head?e.head.replaceWith(_):r.insertBefore(_,r.firstChild),l.push({entry:M,imported:_});continue}if(M.type==="attrs"){let _=h(M.el)||h(M.base);if(!_){c++;continue}for(let C of M.names)M.el.hasAttribute(C)?_.setAttribute(C,M.el.getAttribute(C)):_.removeAttribute(C);continue}let D=M.el;if(T(D))return f(M);let K=h(D)||h(M.base);if(K){let _=e.importNode(D,!0);K.replaceWith(_),x(_),l.push({entry:M,imported:_});continue}if(M.base!=null&&!vn(M.base,A(M.base),n)||!vn(D,A(D),n))return f(M);let ie=D.parentElement;if(!ie)return f(M);let ge=h(ie);if(!ge)return f(M);let Me=null;for(let _=D.previousElementSibling;_;_=_.previousElementSibling){let C=h(_);if(C&&C.parentNode===ge){Me=C;break}}let Ae=e.importNode(D,!0);if(Me)ge.insertBefore(Ae,Me.nextSibling);else{let _=Array.prototype.indexOf.call(ie.children,D);ge.insertBefore(Ae,ge.children[_]||null)}x(Ae),l.push({entry:M,imported:Ae})}return{ok:!0,placed:l,held:null,skippedAttrs:c}}var dr='[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"]',hr='[editor-ui],[clay~="editor-ui"],[no-undo],[clay~="no-undo"]',pr='[no-undo]:not([editor-ui]):not([clay~="editor-ui"]),[clay~="no-undo"]:not([editor-ui]):not([clay~="editor-ui"])';function mr(e){if(e.tagName!=="LINK"&&e.tagName!=="SCRIPT")return!1;let s=e.getAttribute("src")||e.getAttribute("href")||"";return/^(chrome|moz|safari-web)-extension:/.test(s)}function gr(e,s,o,n){if(s==null)return;if(typeof s=="string")return s;let r=s;if(r.nodeType===9){let l=e.getAttribute("id");r=l&&r.getElementById(l)||(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=br(e,s,n)),!!r)return o?Array.from(r.childNodes):r}function br(e,s,o){let n=s.nodeType===9?s.documentElement:s;if(!n||n.nodeType!==1)return null;let r=new Map,l=[n,...n.querySelectorAll("script")];for(let u of l){let v=Nn(u,o);v&&!r.has(v.key)&&r.set(v.key,u.textContent)}if(!r.size)return null;let c=e.cloneNode(!0),f=!1;for(let u of[c,...c.querySelectorAll("script")]){let v=Nn(u,o);v&&r.has(v.key)&&(u.textContent=r.get(v.key),f=!0)}return f?c:null}function rs(e,s){if(typeof e=="string"||e.nodeType===9)return e;if(e.nodeType===1&&e===e.ownerDocument.documentElement)return e.ownerDocument;let o=s.implementation.createHTMLDocument(""),n=e.nodeType===1&&e.tagName==="HTML"?e:null;if(n)return o.replaceChild(o.adoptNode(n),o.documentElement),o;let r=e.nodeType===11?Array.from(e.childNodes):e.nodeType?[e]:Array.from(e);for(let l of r)o.body.appendChild(o.adoptNode(l));return o}function eo(e,s,o={}){let n=o||{};if(!n.head?.block)return is(e,s,n);try{return is(e,s,n)}catch(r){return Promise.reject(r)}}function is(e,s,o){let n=o.policy||"sync",r=n==="raw"?void 0:(u,v)=>mr(u)||(n==="history"?!(v&&u.matches(pr))&&u.matches(hr):u.matches(dr)),l=o.callbacks||{},c={ignore:r,hooks:l,protectFocusedValue:o.ignoreActiveValue===!0?"subtree":!1,restoreFocus:o.restoreFocus!==!1,formState:o.formStateSync||"attribute",scripts:{execute:o.scripts?.handle!==!1,merge:o.scripts?.merge!==!1,mergeTags:o.scripts?.mergeTags||[]},head:{awaitLoads:!!o.head?.block,preserve:o.head?.shouldPreserve||(()=>!1)}};if(typeof o.key=="function"&&(c.identity={base:o.key,local:o.key,remote:o.key}),e&&e.nodeType===9)return Mn(Object.assign({},c,{live:e,base:o.scripts?.mergeBase||null,remote:rs(s,e)}));if(e.tagName==="HTML"&&e.parentNode&&e.parentNode.nodeType===9){let u=Object.assign({},c,{live:e.ownerDocument,base:o.scripts?.mergeBase||null,remote:rs(s,e.ownerDocument)});return Mn(u)}o.morphStyle==="innerHTML"&&(c.children=!0);let f=gr(e,o.scripts?.mergeBase,!!c.children,c.scripts.mergeTags);return f!==void 0&&(c.base=f),to(e,s,c)}var kr=new Set(["live","base","remote","local","identity","ignore","remoteWins","ignoreAttribute","conflicts","protectFocusedValue","restoreFocus","head","scripts","formState","children","hooks","beforeApply"]),en=()=>{};function Un(e,s=[]){if(!e||typeof e!="object")throw new TypeError("options object required");for(let c of Object.keys(e))if(!kr.has(c))throw new TypeError(`unknown option "${c}"`);let o=Object.assign({beforeNodeAdded:en,afterNodeAdded:en,beforeNodeRemoved:en,afterNodeRemoved:en,beforeNodeMorphed:en,afterNodeMorphed:en,beforeAttributeUpdated:en},e.hooks||{}),n=e.conflicts||"remote";if(!["remote","local","both"].includes(n))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 l=e.protectFocusedValue;if(l!==void 0&&typeof l!="boolean"&&l!=="subtree")throw new TypeError('protectFocusedValue must be a boolean or "subtree"');return{ignored:oo(e.ignore,s),remoteWins:oo(e.remoteWins,s),ignoreAttribute:typeof e.ignoreAttribute=="function"?e.ignoreAttribute:()=>!1,conflicts:n,protectFocusedValue:l===void 0?!0:l,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:o,children:!!e.children,beforeApply:typeof e.beforeApply=="function"?e.beforeApply:null}}function In(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 dn}function On(e,s){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){let o=qn(s,e.map),n=typeof e.then=="function"?e.then:dn;if(typeof e.first=="function"){let r=e.first;return l=>r(l)||o.get(l)||n(l)}return r=>o.get(r)||n(r)}return dn}function as(e,s,o,n={}){let r=A=>A&&A.nodeType===9?A.documentElement:A,l=r(s),c=r(o),f=r(e)||l,u=Object.assign({},n);delete u.live,delete u.base,delete u.remote;let v=Un(u,[f,l,c].filter(Boolean)),N=n.identity||{};return Ao(f,l,c,{identity:{base:On(N.base,f),local:On(N.local,l),remote:On(N.remote,c)},authored:{base:In(N.base),local:In(N.local),remote:In(N.remote)},skipUnchanged:v.hooks.beforeNodeMorphed===en&&v.hooks.afterNodeMorphed===en,ignored:v.ignored,remoteWins:v.remoteWins,ignoreAttribute:v.ignoreAttribute,conflicts:v.conflicts,mergeTags:v.scripts.merge===!1?null:v.scripts.mergeTags,baseURI:l.ownerDocument&&l.ownerDocument.baseURI||"about:blank",localIsBase:!e||e===s,childrenOnly:v.children})}function To({liveRoot:e,baseRoot:s,localRoot:o,remoteRoot:n,toLive:r,options:l,identity:c,childrenOnly:f,isDocument:u}){let v=Un(l,[e,s,o,n].filter(Boolean));if(v.ignored(e))return{report:xo(),loads:[]};let N=e.ownerDocument,A=v.scripts.execute?Vo(e,v.ignored,N.baseURI):null,T=Ao(s||o,o,n,{identity:{base:On(c.base,s||o),local:On(c.local,o),remote:On(c.remote,n)},authored:{base:In(c.base),local:In(c.local),remote:In(c.remote)},ignored:v.ignored,remoteWins:v.remoteWins,ignoreAttribute:v.ignoreAttribute,conflicts:v.conflicts,mergeTags:v.scripts.merge===!1?null:v.scripts.mergeTags,baseURI:N.baseURI,localIsBase:!s,childrenOnly:f,skipUnchanged:v.hooks.beforeNodeMorphed===en&&v.hooks.afterNodeMorphed===en});v.beforeApply&&v.beforeApply(T.doc);let p=globalThis.__hyperMorphProfile,h=p?performance.now():0,x=Zo(e,T.root,T,{toLive:r,ignored:v.ignored,ignoreAttribute:v.ignoreAttribute,formState:v.formState,protectFocusedValue:v.protectFocusedValue,restoreFocus:v.restoreFocus,preserve:v.head.preserve,hooks:v.hooks,childrenOnly:f});p&&(p.apply=(p.apply||0)+(performance.now()-h));let R=[];if(v.head.awaitLoads)for(let K of x.applied){if(K.kind!=="insert"||K.node.nodeType!==1)continue;let ie=K.node;ie.tagName==="LINK"&&/\bstylesheet\b/i.test(ie.getAttribute("rel")||"")&&ie.getAttribute("href")&&ie.closest("head")&&R.push(new Promise(Me=>{ie.addEventListener("load",()=>Me()),ie.addEventListener("error",()=>Me())}))}if(A){let K=Wo(e,A,{ignored:v.ignored,skip:x.mergedScriptsLive,baseURI:N.baseURI,beforeNodeAdded:v.hooks.beforeNodeAdded,afterNodeAdded:v.hooks.afterNodeAdded});R.push(...K.loads)}let M=K=>K&&x.liveOf&&x.liveOf.get(K)||null;return{report:{applied:x.applied,decisions:T.decisions.map(K=>Object.assign({},K,{node:K.node?M(K.node):null,el:K.el?M(K.el):null,applied:!!(K.node?M(K.node):K.el&&M(K.el))})),conflicts:T.conflicts.map(K=>Object.assign({},K,{node:K.node?M(K.node):K.node,el:K.el?M(K.el):K.el})),localDiverged:T.localDiverged,identities:x.identities,moved:x.moved,replaced:x.replaced},loads:R}}var cs=new WeakMap;function xo(){return{applied:[],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[]}}function Mn(e){let s=e||{},o=s.live;if(!o||o.nodeType!==9)throw new TypeError("live must be a Document");let n=cs.get(o);n||(n=zn(o),cs.set(o,n));let r=n("remote",s.remote),l=typeof s.base=="string"&&s.base===""?null:s.base,c=l?n("base",l):null,f=s.local?s.local.root:o.documentElement,u=s.local?s.local.toLive:A=>A;vo(o,r);let{report:v,loads:N}=To({liveRoot:o.documentElement,baseRoot:c?c.documentElement:null,localRoot:f,remoteRoot:r.documentElement,toLive:u,options:s,identity:s.identity||{},childrenOnly:!1,isDocument:!0});return Promise.all(N).then(()=>v)}function fs(e,s,o={}){return Mn(Object.assign({},o,{live:e,base:null,remote:s}))}function ls(e,s){if(e==null)return{root:s.createElement("template"),first:null};if(typeof e=="string"){let n=/^\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype[^>]*>\s*)?<(html|body)[\s>]/i.exec(e);if(n){let l=Kn(e,s),c=n[1].toLowerCase()==="html"?l.documentElement:l.body;return{root:c,first:c}}let r=s.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 n=s.createElement("template"),r=e.isConnected;return n.content.appendChild(r?s.importNode(e,!0):e),{root:n,first:e}}if(e.nodeType===11){let n=s.createElement("template");return n.content.appendChild(e),{root:n,first:n.content.firstElementChild}}let o=s.createElement("template");for(let n of Array.from(e))o.content.appendChild(n.parentNode?s.importNode(n,!0):n);return{root:o,first:o.content.firstElementChild}}function to(e,s,o={}){if(!e||e.nodeType!==1)throw new TypeError("oldEl must be an Element");let n=e.ownerDocument,{base:r,...l}=o,c=!!l.children;if(Un(l,[e]).ignored(e))return Promise.resolve(xo());let f=ls(s,n),u=r!=null?ls(r,n):null,v,N=null;if(c)v=f.root,N=u?u.root:null;else{if(v=f.first,N=u?u.first:null,!v){let p=Un(l);return p.hooks.beforeNodeRemoved(e)!==!1&&(e.remove(),p.hooks.afterNodeRemoved(e)),Promise.resolve({applied:[{kind:"remove",node:e,parent:null}],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[e]})}if(v.tagName!==e.tagName){let p=Un(l,[e,v]);if(p.hooks.beforeNodeMorphed(e,v)===!1)return Promise.resolve(xo());let h=To({liveRoot:e,baseRoot:N&&N.tagName===e.tagName?N:null,localRoot:e,remoteRoot:v,toLive:R=>R,options:l,identity:l.identity||{},childrenOnly:!0,isDocument:!1}),x=_t(v)?Bn(v,n):n.importNode(v,!1);if(!_t(x))for(;e.firstChild;)x.appendChild(e.firstChild);return p.hooks.beforeNodeAdded(x)===!1||p.hooks.beforeNodeRemoved(e)===!1?Promise.resolve(h.report):(e.replaceWith(x),p.hooks.afterNodeRemoved(e),p.hooks.afterNodeAdded(x),p.hooks.afterNodeMorphed(e,v),h.report.replaced.push(x),h.report.applied.push({kind:"insert",node:x,parent:x.parentNode},{kind:"remove",node:e,parent:x.parentNode}),Promise.all(h.loads).then(()=>h.report))}}let{report:A,loads:T}=To({liveRoot:e,baseRoot:N,localRoot:e,remoteRoot:v,toLive:p=>p,options:l,identity:l.identity||{},childrenOnly:c,isDocument:!1});return Promise.all(T).then(()=>A)}var yr={mergeDocument:Mn,morphDocument:fs,morphElement:to,merge3:as,morph:eo};return ys(wr);})();
|
|
4
5
|
|
|
5
6
|
var morph = HyperMorph.morph;
|
|
6
7
|
|