@panphora/clayjs 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,15 +28,14 @@
28
28
  * next. Typing, pasting and every other user edit of a control or a
29
29
  * contenteditable subtree do fire one, which is the case this is for.
30
30
  *
31
- * The region is kept AFTER focus leaves, deliberately. hyper-morph's
32
- * `ignoreActiveValue` skips both the value sync and the child morph for
33
- * `document.activeElement`, so nothing can change under the caret while it is
34
- * still there; the frame worth reporting is the one that lands on the paragraph
35
- * the reader just left.
31
+ * The region is kept AFTER focus leaves, deliberately. The three-way merge
32
+ * keeps the reader's own typing in the focused region and restores the caret,
33
+ * so the frame worth reporting is the one that lands on the paragraph the
34
+ * reader just left.
36
35
  *
37
36
  * DISMISS ONLY. An undo here would mean recovering displaced local work, which
38
- * nothing in this library builds. Unsaved local work is protected before the
39
- * morph by protectPeerDoc, and a refused save is still the conflict bar's job.
37
+ * nothing in this library builds. Unsaved local work survives the three-way
38
+ * merge, and a refused save is still the conflict bar's job.
40
39
  *
41
40
  * Silent with no `by` on the frame, which is the whole gate: the server stamps
42
41
  * an author on live-lane frames alone, so a saved-lane reader — who must never
@@ -65,7 +65,10 @@ export function finalizeControlForSave(target, source = target) {
65
65
  return;
66
66
  }
67
67
  if (tag === "TEXTAREA") {
68
- if (target.textContent !== source.value) target.textContent = source.value;
68
+ // The HTML parser drops one newline right after <textarea>, so a value that
69
+ // starts with one needs a sacrificial newline to survive a reload.
70
+ const text = source.value.startsWith("\n") ? "\n" + source.value : source.value;
71
+ if (target.textContent !== text) target.textContent = text;
69
72
  target.removeAttribute("data-value");
70
73
  return;
71
74
  }
@@ -1,13 +1,9 @@
1
- var HyperMorph=(()=>{var we=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var n in t)we(e,n,{get:t[n],enumerable:!0})},ot=(e,t,n,g)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of rt(t))!st.call(e,u)&&u!==n&&we(e,u,{get:()=>t[u],enumerable:!(g=nt(t,u))||g.enumerable});return e};var at=e=>ot(we({},"__esModule",{value:!0}),e);var Ht={};it(Ht,{HyperMorph:()=>de,default:()=>Bt,defaults:()=>Ct,findChangedRoots:()=>Lt,mergeJson:()=>ve,mergeScriptText:()=>Me,morph:()=>xt,parseJsonRelaxed:()=>me,parseRulesRelaxed:()=>Ie,spliceProtected:()=>Rt});var Pe={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function ut(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return Math.abs(t).toString(36)}function ct(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function lt(e,t){let n=[];for(let g of e.attributes||[]){let u=g.name;u==="id"||u==="class"||t.excludeAttributePrefixes.some(y=>u.startsWith(y))||t.includeAttributes.includes(u)&&n.push(`${u}=${g.value}`)}return n.sort().join("|")}function ft(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function dt(e,t){let n=[e.tagName];return t.includeClasses&&n.push(ct(e)),n.push(lt(e,t)),ut(n.join("|"))}function ht(e){let t=e.tagName,n=1,g=e.previousElementSibling;for(;g;)g.tagName===t&&n++,g=g.previousElementSibling;return n}function pt(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function gt(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function mt(e,t){let n=[],g=e;for(;g&&g.tagName&&n.length<t.maxPathDepth;){let u=`${g.tagName}:${ht(g)}`;if(n.unshift(u),g!==e&&pt(g,t)){n.unshift(gt(g));break}g=g.parentElement}return n}function yt(e,t){let n=0,g=e.length-1,u=t.length-1;for(;g>=0&&u>=0&&e[g]===t[u];)n++,g--,u--;return n}function X(e,t,n){if(n.has(e))return n.get(e);let g={signature:dt(e,t),path:mt(e,t),textHint:ft(e,t)};return n.set(e,g),g}function qe(e,t,n,g){if(g.has(e))return g.get(e);let u=new Map,y=e.querySelectorAll("*"),S=0;for(let d of y){let M=X(d,t,n);M.domIndex=S++,!t.shouldIgnore?.(d)&&(u.has(M.signature)||u.set(M.signature,[]),u.get(M.signature).push(d))}return g.set(e,u),u}function bt(e,t,n){n.delete(e),t.delete(e);let g=e.querySelectorAll("*");for(let u of g)t.delete(u)}function Te(e,t,n,g,u){let y=X(e,n,g),S=X(t,n,g),d=n.weights,M={},P=0;if(y.signature!==S.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};P+=d.signature,M.signature=d.signature;let B=yt(y.path,S.path)*d.pathSegment;P+=B,M.path=B;let I=!0;if(y.textHint&&S.textHint?y.textHint===S.textHint?(P+=d.textMatch,M.text=d.textMatch):(P-=d.textMismatch,M.text=-d.textMismatch,I=!1):y.textHint!==S.textHint&&(P-=d.textMismatch,M.text=-d.textMismatch,I=!1),u.candidateCount===1&&I&&(P+=d.uniqueCandidate,M.unique=d.uniqueCandidate),typeof y.domIndex=="number"&&typeof S.domIndex=="number"){let k=Math.abs(y.domIndex-S.domIndex),E=Math.min(k*d.positionPenalty,d.maxDriftPenalty);P-=E,M.drift=-E}return{score:P,breakdown:M}}function De(e,t,n,g,u){if(n.excludeIds&&e.getAttribute("id"))return null;let y=qe(t,n,g,u),S=X(e,n,g);if(typeof S.domIndex!="number"){let I=0,k=e.previousElementSibling;for(;k;)I++,k=k.previousElementSibling;S.domIndex=I}let d=y.get(S.signature)||[],M=n.excludeIds?d.filter(I=>!I.getAttribute("id")):d;if(M.length===0)return null;let P=null,q=0,B=null;for(let I of M){let{score:k,breakdown:E}=Te(e,I,n,g,{candidateCount:M.length});k>q&&(q=k,P=I,B=E)}return q<n.minConfidence?null:{element:P,confidence:q,breakdown:B}}function At(e,t,n,g){let u=[],y=n.weights.signature+n.weights.slotMatch,S={slot:y};function d(B){if(B.children)return B.children;let I=B.childNodes;if(!I)return[];let k=[];for(let E=0;E<I.length;E++)I[E].nodeType===1&&k.push(I[E]);return k}function M(B,I){let k=d(B),E=d(I);if(k.length===E.length)for(let U=0;U<k.length;U++){let J=k[U],W=E[U];if(n.shouldIgnore?.(J)||n.shouldIgnore?.(W)||n.excludeIds&&(J.getAttribute("id")||W.getAttribute("id"))||J.tagName!==W.tagName)continue;let Q=X(J,n,g).signature,ee=X(W,n,g).signature;Q!==ee&&u.push({newEl:J,oldEl:W,score:y,breakdown:S}),M(J,W)}}function P(B,I){for(;;){if(B.tagName===I.tagName)return[B,I];let k=d(B);if(!B.tagName&&k.length===1){B=k[0];continue}let E=d(I);if(E.length===1&&E[0].tagName===B.tagName){I=E[0];continue}return null}}let q=P(e,t);return q&&M(q[0],q[1]),u}function ze(e,t,n,g,u){let y=t.querySelectorAll("*"),S=qe(e,n,g,u),d=0;for(let k of y){let E=X(k,n,g);E.domIndex=d++}let M=[],P=new Map;function q(k,E,U){let J=new Set;if(k.textHint){let Z=P.get(k.signature);if(!Z){Z=new Map;for(let re of E){let be=X(re,n,g).textHint,se=Z.get(be);se||(se=[],Z.set(be,se)),se.push(re)}P.set(k.signature,Z)}let he=Z.get(k.textHint);if(he)for(let re=0;re<he.length&&re<U;re++)J.add(he[re])}let W=0,Q=E.length;for(;W<Q;){let Z=W+Q>>1;X(E[Z],n,g).domIndex<k.domIndex?W=Z+1:Q=Z}let ee=Math.max(0,Math.min(W-(U>>1),E.length-U)),ne=Math.min(ee+U,E.length);for(let Z=ee;Z<ne;Z++)J.add(E[Z]);return[...J]}for(let k of y){if(n.shouldIgnore?.(k)||n.excludeIds&&k.getAttribute("id"))continue;let E=X(k,n,g),U=S.get(E.signature)||[],J=n.excludeIds?U.filter(ee=>!ee.getAttribute("id")):U,W=n.maxScoredCandidates,Q=W&&J.length>W?q(E,J,W):J;for(let ee of Q){let{score:ne,breakdown:Z}=Te(k,ee,n,g,{candidateCount:J.length});ne>=n.minConfidence&&M.push({newEl:k,oldEl:ee,score:ne,breakdown:Z})}}if(n.weights.slotMatch>0){let k=At(t,e,n,g);for(let E of k)M.push(E)}M.sort((k,E)=>E.score-k.score);let B=new Map,I=new Set;for(let{newEl:k,oldEl:E}of M)B.has(k)||I.has(E)||(B.set(k,E),I.add(E));return B}function _e(e,t,n,g){let u=X(e,n,g),y=X(t,n,g),{score:S,breakdown:d}=Te(e,t,n,g,{candidateCount:1});return{matches:S>=n.minConfidence,score:S,breakdown:d,newMeta:{signature:u.signature,path:u.path,textHint:u.textHint},oldMeta:{signature:y.signature,path:y.path,textHint:y.textHint}}}function Fe(e={}){let t={...Pe,...e,weights:{...Pe.weights,...e.weights}},n=new WeakMap,g=new WeakMap;return{findMatch:(u,y)=>De(u,y,t,n,g),computeMatches:(u,y)=>ze(u,y,t,n,g),explain:(u,y)=>_e(u,y,t,n),invalidate:u=>bt(u,n,g),session:()=>{let u=new WeakMap,y=new WeakMap;return{findMatch:(S,d)=>De(S,d,t,u,y),computeMatches:(S,d)=>ze(S,d,t,u,y),explain:(S,d)=>_e(S,d,t,u)}},getConfig:()=>({...t})}}function Ee(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
2
- `;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function Ve(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var St=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,vt=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function me(e){try{return JSON.parse(e)}catch{return JSON.parse(Mt(e))}}function Mt(e){let t="",n=0,g=(u,y)=>{throw new Error(`Invalid relaxed JSON: ${u} at position ${y}`)};for(;n<e.length&&(n=Ee(e,n),!(n>=e.length));){let u=e[n];if("{}[]:".includes(u)){t+=u,n++;continue}if(u===","){let d=Ee(e,n+1);if(e[d]==="}"||e[d]==="]"){n++;continue}t+=u,n++;continue}if(u==='"'||u==="'"){let d=n+1;for(;d<e.length&&e[d]!==u;)e[d]==="\\"&&d++,d++;d>=e.length&&g("unterminated string",n);let M=e.slice(n+1,d);u==="'"&&(M=Ve(M)),t+='"'+M+'"',n=d+1;continue}let y=n;for(;y<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[y]);)y++;y===n&&g("unexpected character "+JSON.stringify(u),n);let S=e.slice(n,y);if(S==="true"||S==="false"||S==="null"||St.test(S)){t+=S,n=y;continue}if(vt.test(S)){if(e[Ee(e,y)]===":"){t+='"'+S+'"',n=y;continue}g("unquoted value "+JSON.stringify(S),n)}g("invalid token "+JSON.stringify(S),n)}return t}function Ie(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(u){let y=[],S=0;for(;S<u.length;){let d=u[S];if(/\s/.test(d)){S++;continue}if("{}".includes(d)){y.push({type:d,value:d}),S++;continue}if(d==="["){let B=!1,I=S+1;for(;I<u.length&&/\s/.test(u[I]);)I++;if(I<u.length&&/[a-zA-Z_]/.test(u[I])&&(B=!0),!B){y.push({type:d,value:d}),S++;continue}}if(d==="]"){y.push({type:d,value:d}),S++;continue}if(d===":"){y.push({type:t.COLON,value:d}),S++;continue}if(d===","){y.push({type:t.COMMA,value:d}),S++;continue}if(d==='"'||d==="'"){let B=d,I=S+1;for(;I<u.length&&u[I]!==B;)u[I]==="\\"&&I++,I++;y.push({type:t.STRING,value:u.substring(S+1,I),quoted:!0,sourceQuote:B}),S=I+1;continue}let M=S,P;for(;M<u.length&&!/[{},]/.test(u[M]);)if(u[M]===":"){let B=[":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"],I=!1;for(let k of B){let E=k.substring(1);if(u.substring(M+1,M+1+E.length)===E){I=!0,M+=E.length;break}}if(!I)break}else if(u[M]==="["){for(M++;M<u.length&&u[M]!=="]";){if(u[M]==='"'||u[M]==="'"){let B=u[M];for(M++;M<u.length&&u[M]!==B;)u[M]==="\\"&&M++,M++}M++}M<u.length&&u[M]==="]"&&M++}else M++;P=u.substring(S,M);let q=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(P)?q=t.NUMBER:P==="true"||P==="false"||P==="null"?q=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(P)&&(q=t.SELECTOR),y.push({type:q,value:P,quoted:!1}),S=M}return y}function g(u){let y="";for(let S=0;S<u.length;S++){let d=u[S];if("{}".includes(d.type)||"[]".includes(d.type)){y+=d.value;continue}if(d.type===t.COLON){y+=d.value;continue}if(d.type===t.COMMA){let M=u[S+1];if(M&&(M.type==="}"||M.type==="]"))continue;y+=d.value;continue}if(d.type===t.STRING){let M=d.value;d.sourceQuote==="'"&&(M=Ve(M)),y+=`"${M}"`;continue}if(d.type===t.NUMBER||d.type===t.BOOLEAN){y+=d.value;continue}y+=`"${d.value}"`}return y}try{let u=n(e),y=g(u);return JSON.parse(y)}catch(u){throw new Error("Invalid extraction rules syntax: "+u.message)}}var F=Symbol("hyper-morph-json-merge:missing"),Ke=["id","_id","uuid","key","slug","code","name"];function fe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ye(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Nt(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function oe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!oe(e[n],t[n]))return!1;return!0}if(fe(e)&&fe(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let g of n)if(!ye(t,g)||!oe(e[g],t[g]))return!1;return!0}return!1}function Ue(e,t,n,g){return oe(t,n)?t:oe(t,e)?n:oe(n,e)?t:fe(t)&&fe(n)?kt(fe(e)?e:{},t,n,g):Array.isArray(t)&&Array.isArray(n)?It(Array.isArray(e)?e:[],t,n,g):n}function Je(e,t,n,g){return t===F&&n===F?F:t===F?e===F?n:oe(n,e)?F:n:n===F?e===F?t:F:Ue(e,t,n,g)}function kt(e,t,n,g){let u={},y=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let S of y){let d=Je(ye(e,S)?e[S]:F,ye(t,S)?t[S]:F,ye(n,S)?n[S]:F,g);d!==F&&Nt(u,S,d)}return u}function wt(e){return e===null||typeof e!="object"}function Se(e){return typeof e+":"+String(e)}function Tt(e,t){for(let n of t){let g=new Set;for(let u of n){if(!ye(u,e))return!1;let y=u[e];if(typeof y!="string"&&typeof y!="number")return!1;let S=Se(y);if(g.has(S))return!1;g.add(S)}}return!0}function Et(e,t,n,g){let u=[e,t,n],y=!0;for(let S of u)for(let d of S)fe(d)||(y=!1);if(y){for(let S of g.keyCandidates)if(Tt(S,u))return{kind:"keyed",field:S};return null}for(let S of u){let d=new Set;for(let M of S){if(!wt(M))return null;let P=Se(M);if(d.has(P))return null;d.add(P)}}return{kind:"self"}}function It(e,t,n,g){let u=Et(e,t,n,g);if(!u)return n;let y=u.kind==="self"?Se:k=>Se(k[u.field]),S=k=>{let E=new Map;for(let U of k)E.set(y(U),U);return E},d=S(e),M=S(t),P=S(n),q=new Map,B=new Set([...d.keys(),...M.keys(),...P.keys()]);for(let k of B){let E=Je(d.has(k)?d.get(k):F,M.has(k)?M.get(k):F,P.has(k)?P.get(k):F,g);E!==F&&q.set(k,E)}let I=[];for(let k of n){let E=y(k);q.has(E)&&I.push(E)}for(let k=0;k<t.length;k++){let E=y(t[k]);if(!q.has(E)||I.includes(E))continue;let U=0;for(let J=k-1;J>=0;J--){let W=I.indexOf(y(t[J]));if(W!==-1){U=W+1;break}}I.splice(U,0,E)}return I.map(k=>q.get(k))}function ve(e,t,n,g={}){let u=g.keyCandidates?[...g.keyCandidates,...Ke]:Ke;return Ue(e===void 0?F:e,t,n,{keyCandidates:u})}function Me(e,t,n,g={}){let u=g.parse||me,y=[],S=(B,I)=>{if(typeof B!="string")return F;try{return u(B)}catch(k){return y.push(`${I} side is not valid JSON (${k.message})`),F}},d=S(t,"local"),M=S(n,"remote");if(d===F)return{text:n,warnings:y};if(M===F)return{text:t,warnings:y};let P=S(e,"base"),q=ve(P===F?void 0:P,d,M,g);return oe(q,M)?{text:n,warnings:y}:oe(q,d)?{text:t,warnings:y}:{text:JSON.stringify(q,null,2),warnings:y}}var Ot=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),_t=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),qt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function We(e){let t=Ot[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}var de=(function(){"use strict";let e=()=>{},t='[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"]',n=`${We("history")},[no-undo],[clay~="no-undo"]`;function g(r){if(r?.nodeType!==1)return!1;if(r.matches(t))return!0;if(r.tagName==="LINK"||r.tagName==="SCRIPT"){let p=r.getAttribute("src")||r.getAttribute("href")||"";if(p.startsWith("chrome-extension://")||p.startsWith("moz-extension://")||p.startsWith("safari-web-extension://"))return!0}return!1}function u(r){return r?.nodeType!==1?!1:r.closest(t)?!0:g(r)}function y(r,p,h){if(h){let w=h.identityOf(r);if(w&&!h.disabled.has(w.key))return"hm-merge:"+w.key}if(p!=="smart")return r.outerHTML;let N=r.getAttribute("src"),b=r.getAttribute("type")||"text/javascript";if(N)try{let w=new URL(N,window.location.href);return`ext:${b}:${w.origin}${w.pathname}${w.search}`}catch{return`ext:${b}:${N}`}else{let w=r.textContent.trim(),a=5381;for(let c=0;c<w.length;c++)a=(a<<5)+a^w.charCodeAt(c);return`inline:${b}:${Math.abs(a).toString(36)}`}}let S="http://www.w3.org/1999/xhtml";function d(r){return r?.nodeType===1&&r.tagName==="SCRIPT"&&r.namespaceURI===S}function M(r){let p=document.createElement("div");p.innerHTML="<script><\/script>";let h=p.firstChild;for(let N of r.attributes)h.setAttribute(N.name,N.value);return h.textContent=r.textContent,h}function P(r){if(d(r))return M(r);if(r?.nodeType===1)for(let p of r.querySelectorAll("script"))d(p)&&p.replaceWith(M(p));return r}function q(r){let p=(r.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return p==="application/json"||p.endsWith("+json")}let B={match:r=>r.hasAttribute("merge"),identity:r=>r.getAttribute("merge")};function I(r,p,h){if(h.merge===!1)return null;let N=[B,...h.mergeTags||[]],b=new WeakMap,w=i=>{if(b.has(i))return b.get(i);let m=null;if(d(i)&&!i.getAttribute("src")&&!u(i)){let v=i;for(let T=0;T<N.length;T++)if(N[T].match(v)){if(!q(v))console.warn("[hyper-morph] merge ignored: script type is not JSON",v);else{let L=N[T].identity(v);L!=null&&L!==""&&(m={key:T+":"+L,raw:L,recognizer:N[T]})}break}}return b.set(i,m),m},a=new Set,c=i=>{let m=new Map,v=T=>{let L=w(T);L&&(m.has(L.key)?(a.add(L.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${L.raw}"`)):m.set(L.key,T))};d(i)&&v(i);for(let T of i.querySelectorAll("script"))v(T);return m},l=c(r),s=c(p.__hyperMorphRoot||p);if(l.size===0&&s.size===0)return null;let o=null;return{identityOf:w,disabled:a,oldByKey:l,newByKey:s,baseTexts:()=>{if(o)return o;o=new Map;let i=h.mergeBase;if(!i)return o;let m;typeof i=="string"?m=new DOMParser().parseFromString(i,"text/html").documentElement:i?.nodeType===9?m=i.documentElement:m=i;let v=T=>{let L=w(T);L&&!o.has(L.key)&&o.set(L.key,T.textContent)};d(m)&&v(m);for(let T of m.querySelectorAll("script"))v(T);return o}}}function k(r,p,h){let N=r.merge;if(!N)return!1;let b=N.identityOf(p);if(!b||N.disabled.has(b.key))return!1;let w=N.identityOf(h);if(!w||w.key!==b.key)return!1;let a=p,c=h,l=c.getAttribute("merge-key")||a.getAttribute("merge-key"),{text:s,warnings:o}=Me(N.baseTexts().get(b.key),a.textContent,c.textContent,{parse:b.recognizer.parse,keyCandidates:l?l.split(/[\s,]+/).filter(Boolean):void 0});for(let f of o)console.warn(`[hyper-morph] merge "${b.raw}": ${f}`);return a.textContent!==s&&(a.textContent=s),!0}let E={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:r=>r.getAttribute("im-preserve")==="true",shouldReAppend:r=>r.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:r=>r.getAttribute("im-preserve")==="true",shouldReAppend:r=>r.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},U={computeMatches(r,p,h=u){let{computeMatches:N}=Fe({shouldIgnore:h}).session();return N(r,p)}};function J(r,p,h={}){r=Xe(r);let N=xe(p),b=Qe(r,N,h),w=b.scripts.handle?new Set(Array.from(r.querySelectorAll("script")).map(s=>y(s,b.scripts.matchMode,b.merge))):null,a=re(b),c;try{c=Ge(b,r,N,s=>s.morphStyle==="innerHTML"?(se(s,r,N),Array.from(r.childNodes)):he(s,r,N))}catch(s){throw Q(b),s}let l=s=>{a&&be(b,a),W(b);let o=w?Ze(s,w,b):[];return o.length>0?Promise.all(o).then(()=>s):s};if(c instanceof Promise)return c.then(s=>{try{return l(s)}catch(o){throw Q(b),o}},s=>{throw Q(b),s});try{return l(c)}catch(s){throw Q(b),s}}function W(r){let p=r.pantry;if(p){for(let h of Array.from(p.childNodes))r.callbacks.beforeNodeRemoved(h)!==!1&&r.callbacks.afterNodeRemoved(h);for(let h of Array.from(p.childNodes))p.removeChild(h);p.remove(),r.pantry=null,r.stagedNodes.clear()}}function Q(r){let p=r.pantry;if(!p)return;let h=Array.from(r.stagedNodes.entries()).reverse();for(let[N,b]of h){if(!p.contains(N))continue;let w=b.nextSibling?.parentNode===b.parent?b.nextSibling:null;try{ne(b.parent,N,w)}catch{}}for(let N of Array.from(p.childNodes))p.removeChild(N);p.remove(),r.pantry=null,r.stagedNodes.clear()}function ee(r){if(r.pantry)return r.pantry;let p=r.target.ownerDocument,h=p.createElement("div");return h.hidden=!0,h.setAttribute("mutations-ignore",""),p.body.insertAdjacentElement("afterend",h),r.pantry=h,h}function ne(r,p,h){if(r.moveBefore)try{r.moveBefore(p,h)}catch{r.insertBefore(p,h)}else r.insertBefore(p,h)}function Z(r,p){!r.stagedNodes.has(p)&&p.parentNode&&r.stagedNodes.set(p,{parent:p.parentNode,nextSibling:p.nextSibling}),ne(ee(r),p,null)}function he(r,p,h){let N=xe(p);return se(r,N,h,p,p.nextSibling),Array.from(N.childNodes)}function re(r){if(!r.config.restoreFocus)return null;let p=document.activeElement;if(!(p instanceof HTMLInputElement||p instanceof HTMLTextAreaElement))return null;let{id:h,selectionStart:N,selectionEnd:b}=p;return{element:p,id:h,selectionStart:N,selectionEnd:b}}function be(r,p){let h=p.element;if(p.id&&p.id!==document.activeElement?.getAttribute("id")&&(h=r.target.querySelector(`[id="${CSS.escape(p.id)}"]`),h?.focus()),h&&!h.selectionEnd&&p.selectionEnd!=null)try{h.setSelectionRange(p.selectionStart,p.selectionEnd)}catch{}}let se=(function(){function r(s,o,f,i=null,m=null){o?.tagName==="TEMPLATE"&&f?.tagName==="TEMPLATE"&&(o=o.content,f=f.content),i||=o.firstChild;for(let v of f.childNodes){if(s.shouldIgnore(v))continue;if(i&&i!=m){let L=N(s,v,i,m);if(L){L!==i&&w(s,i,L),Ae(L,v,s),i=L.nextSibling;continue}}if(v?.nodeType===1){let L=v.getAttribute("id");if(s.persistentIds.has(L)){let A=a(o,L,i,s);Ae(A,v,s),i=A.nextSibling;continue}if(!s.idMap.has(v)){let A=s.hyperMatches.get(v);if(A&&!s.idMap.has(A)&&!l(A,o)){ne(o,A,i),Ae(A,v,s),i=A.nextSibling;continue}}}let T=p(o,v,i,s);T&&(i=T.nextSibling)}for(;i&&i!=m;){let v=i;i=i.nextSibling,s.shouldIgnore(v)||b(s,v)}}function p(s,o,f,i){if(i.callbacks.beforeNodeAdded(o)===!1)return null;let m=s.ownerDocument||s.realParentNode?.ownerDocument||i.target.ownerDocument;if(i.idMap.has(o)){let v=o,T=m.createElementNS(v.namespaceURI,v.localName);return s.insertBefore(T,f),Ae(T,o,i),i.callbacks.afterNodeAdded(T),T}else{let v=P(h(o,m,i));return v?(s.insertBefore(v,f),i.callbacks.afterNodeAdded(v),v):null}}function h(s,o,f){if(f.shouldIgnore(s))return null;let i=o.importNode(s,!1),m=s.nodeType===1&&s.tagName==="TEMPLATE"?s.content:s,v=i.nodeType===1&&i.tagName==="TEMPLATE"?i.content:i;for(let T of Array.from(m.childNodes||[])){let L=h(T,o,f);L&&v.appendChild(L)}return i}let N=(function(){function s(i,m,v,T){let L=m?.nodeType===1&&!i.idMap.has(m)?i.hyperMatches.get(m):null,A=null,x=m.nextSibling,V=0,C=v;for(;C&&C!=T;){if(i.shouldIgnore(C)){C=C.nextSibling;continue}if(f(C,m)){if(o(i,C,m)||C===L&&!i.idMap.has(C))return C;if(A===null){let z=C?.nodeType===1&&i.hyperMatchedOldElements.has(C);!i.idMap.has(C)&&!z&&(A=C)}}if(A===null&&x&&f(C,x)&&(V++,x=x.nextSibling,V>=2&&(A=void 0)),i.activeElementAndParents.includes(C))break;C=C.nextSibling}return A||null}function o(i,m,v){let T=i.idMap.get(m),L=i.idMap.get(v);if(!L||!T)return!1;for(let A of T)if(L.has(A))return!0;return!1}function f(i,m){let v=i,T=m;return v.nodeType===T.nodeType&&v.tagName===T.tagName&&(!v.getAttribute?.("id")||v.getAttribute?.("id")===T.getAttribute?.("id"))}return s})();function b(s,o){let f=o?.nodeType===1&&s.hyperMatchedOldElements.has(o)&&!s.idMap.has(o);if(s.idMap.has(o)||f)Z(s,o);else{if(s.callbacks.beforeNodeRemoved(o)===!1)return;o.parentNode?.removeChild(o),s.callbacks.afterNodeRemoved(o)}}function w(s,o,f){let i=o;for(;i&&i!==f;){let m=i;i=i.nextSibling,s.shouldIgnore(m)||b(s,m)}return i}function a(s,o,f,i){let m=i.target.ownerDocument?.defaultView?.CSS?.escape?i.target.ownerDocument.defaultView.CSS.escape(o):String(o).replace(/["\\]/g,"\\$&"),v=i.target.getAttribute?.("id")===o&&i.target||i.target.querySelector(`[id="${m}"]`)||i.pantry?.querySelector(`[id="${m}"]`);return c(v,i),ne(s,v,f),v}function c(s,o){let f=s.getAttribute("id");for(;s=s.parentNode;){let i=o.idMap.get(s);i&&(i.delete(f),i.size||o.idMap.delete(s))}}function l(s,o){let f=o?.nodeType===1?o:o.realParentNode;return!!f&&s.contains(f)}return r})(),Ae=(function(){function r(a,c,l){return l.ignoreActive&&a===document.activeElement?null:(l.callbacks.beforeNodeMorphed(a,c)===!1||(a?.tagName==="HEAD"&&l.head.ignore||(a?.tagName==="HEAD"&&l.head.style!=="morph"?Oe(a,c,l):(p(a,c,l),k(l,a,c)||w(a,l)||se(l,a,c))),l.callbacks.afterNodeMorphed(a,c)),a)}function p(a,c,l){let s=c.nodeType;if(s===1){let o=a,f=c,i=o.attributes,m=f.attributes;for(let v of m)b(v.name,o,"update",l)||o.getAttribute(v.name)!==v.value&&o.setAttribute(v.name,v.value);for(let v=i.length-1;0<=v;v--){let T=i[v];if(T&&!f.hasAttribute(T.name)){if(b(T.name,o,"remove",l))continue;o.removeAttribute(T.name)}}w(o,l)||h(o,f,l)}(s===8||s===3)&&a.nodeValue!==c.nodeValue&&(a.nodeValue=c.nodeValue)}function h(a,c,l){if(a.tagName==="INPUT"&&c.tagName==="INPUT"&&c.type!=="file"){let s=c.value,o=a.value;N(a,c,"checked",l),N(a,c,"disabled",l),l.formStateSync==="property"&&a.indeterminate!==c.indeterminate&&(a.indeterminate=c.indeterminate),l.formStateSync==="property"?o!==s&&(b("value",a,"update",l)||(a.value=s)):c.hasAttribute("value")?o!==s&&(b("value",a,"update",l)||(a.setAttribute("value",s),a.value=s)):b("value",a,"remove",l)||(a.value="",a.removeAttribute("value"))}else if(a.tagName==="OPTION"&&c.tagName==="OPTION")N(a,c,"selected",l);else if(a.tagName==="TEXTAREA"&&c.tagName==="TEXTAREA"){let s=c.value,o=a.value;if(b("value",a,"update",l)||(s!==o&&(a.value=s),l.formStateSync==="property"))return;a.firstChild&&a.firstChild.nodeValue!==s&&(a.firstChild.nodeValue=s)}}function N(a,c,l,s){let o=c[l],f=a[l];if(o!==f){let i=b(l,a,"update",s);if(i||(a[l]=c[l]),s.formStateSync==="property")return;o?i||a.setAttribute(l,""):b(l,a,"remove",s)||a.removeAttribute(l)}}function b(a,c,l,s){return a==="value"&&s.ignoreActiveValue&&c===document.activeElement?!0:s.callbacks.beforeAttributeUpdated(a,c,l)===!1}function w(a,c){return!!c.ignoreActiveValue&&a===document.activeElement&&a!==document.body}return r})();function Ge(r,p,h,N){if(r.head.block){let b=p.querySelector("head"),w=h.querySelector("head");if(b&&w){let a=Oe(b,w,r);return Promise.all(a).then(()=>(r.head.block=!1,r.head.ignore=!0,N(r)))}}return N(r)}function Ye(r){return r.tagName==="SCRIPT"?!!r.getAttribute("src"):r.tagName==="LINK"?(r.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!r.getAttribute("href"):!1}function Oe(r,p,h){let N=[],b=[],w=[],a=[],c=h.scripts.matchMode,l=f=>{if(f.tagName==="SCRIPT")return y(f,c,h.merge);if(f.tagName==="LINK"&&c==="smart"){let i=f.getAttribute("href");if(i)try{let m=new URL(i,window.location.href);return`link:${f.getAttribute("rel")||""}:${m.origin}${m.pathname}${m.search}`}catch{}}return f.outerHTML},s=new Map;for(let f of p.children){if(h.shouldIgnore(f))continue;let i=l(f),m=s.get(i);m||(m=[],s.set(i,m)),m.push(f)}for(let f of r.children){let i=l(f),m=s.get(i),v=!!(m&&m.length),T=h.head.shouldReAppend(f),L=h.head.shouldPreserve(f);if(v||L)if(T)b.push(f);else{if(m&&m.length){let A=m.pop();m.length||s.delete(i),k(h,f,A)}w.push(f)}else h.head.style==="append"?T&&(b.push(f),a.push(f)):h.head.shouldRemove(f)!==!1&&!h.shouldIgnore(f)&&b.push(f)}for(let f of s.values())a.push(...f);let o=[];for(let f of a){let i=document.createRange().createContextualFragment(f.outerHTML).firstChild;if(h.callbacks.beforeNodeAdded(i)!==!1){if(i instanceof Element&&Ye(i)){let m,v=new Promise(function(T){m=T});i.addEventListener("load",function(){m()}),i.addEventListener("error",function(){m()}),o.push(v)}r.appendChild(i),h.callbacks.afterNodeAdded(i),N.push(i)}}for(let f of b)h.callbacks.beforeNodeRemoved(f)!==!1&&(r.removeChild(f),h.callbacks.afterNodeRemoved(f));return h.head.afterHeadMorphed(r,{added:N,kept:w,removed:b}),o}function Ze(r,p,h){if(!h.scripts.handle)return[];let N=[],b=[],w=[],a=[],c=h.scripts.matchMode,l=[];for(let o of r)if(o instanceof Element){d(o)&&l.push(o);for(let f of o.querySelectorAll("script"))d(f)&&l.push(f)}for(let o of l){if(o.closest("head")||h.shouldIgnore(o))continue;let f=y(o,c,h.merge),i=p.has(f),m=h.scripts.shouldPreserve(o),v=h.scripts.shouldReAppend(o);i||m?v?(b.push(o),a.push(o)):w.push(o):a.push(o)}let s=[];for(let o of a){if(h.callbacks.beforeNodeAdded(o)===!1)continue;let f=document.createElement("script");for(let i of o.attributes)f.setAttribute(i.name,i.value);if(f.textContent=o.textContent,f.src){let i,m=new Promise(function(v){i=v});f.addEventListener("load",function(){i()}),f.addEventListener("error",function(){i()}),s.push(m)}o.replaceWith(f),h.callbacks.afterNodeAdded(f),N.push(f)}return h.scripts.afterScriptsHandled(h.target,{added:N,kept:w,removed:b}),s}let Qe=(function(){function r(c,l,s){let o=s.policy==="history"?n:t,f=(C,z)=>{let K=C.closest(z);return K&&(c.contains(K)||l.contains(K))?K:null},i=s.policy==="raw"?()=>!1:C=>{if(C?.nodeType!==1)return!1;if(s.policy!=="history"&&(g(C)||f(C,t)))return!0;let z=f(C,o);return!(!z||s.policy==="history"&&z===c&&z.matches('[no-undo],[clay~="no-undo"]')&&!z.matches('[editor-ui],[clay~="editor-ui"]'))},{persistentIds:m,idMap:v}=w(c,l,i),T=U.computeMatches(c,l,i);if(typeof s.key=="function"){let C=new Map,z=new Set,K=R=>{let H=s.key(R);H!=null&&(C.has(H)?z.add(H):C.set(H,R))};c instanceof Element&&K(c);for(let R of c.querySelectorAll("*"))K(R);for(let R of z)C.delete(R);let G=new Map;for(let[R,H]of T)G.set(H,R);let _=l.__hyperMorphRoot||l,O=new Map,D=new Set,$=R=>{let H=s.key(R);H!=null&&(O.has(H)?D.add(H):O.set(H,R))};_ instanceof Element&&$(_);for(let R of _.querySelectorAll("*"))$(R);for(let R of D)O.delete(R);for(let[R,H]of O){let te=C.get(R);if(!te||te.tagName!==H.tagName)continue;let ae=G.get(te);ae&&ae!==H&&T.delete(ae);let ce=T.get(H);ce&&ce!==te&&G.delete(ce),T.set(H,te),G.set(te,H)}}let L=p(s),A=I(c,l,L.scripts);if(A){let C=new Map;for(let[z,K]of T)C.set(K,z);for(let[z,K]of A.newByKey){if(A.disabled.has(z))continue;let G=A.oldByKey.get(z);if(!G)continue;let _=C.get(G);_&&_!==K&&T.delete(_);let O=T.get(K);O&&O!==G&&C.delete(O),T.set(K,G),C.set(G,K)}}let x=new Set;for(let C of T.values())x.add(C);let V=L.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(V))throw new Error(`Do not understand how to morph style ${V}`);return{target:c,newContent:l,config:L,morphStyle:V,ignoreActive:L.ignoreActive,ignoreActiveValue:L.ignoreActiveValue,restoreFocus:L.restoreFocus,formStateSync:L.formStateSync||"attribute",idMap:v,persistentIds:m,hyperMatches:T,hyperMatchedOldElements:x,merge:A,pantry:null,stagedNodes:new Map,activeElementAndParents:h(c),callbacks:L.callbacks,head:L.head,scripts:L.scripts,shouldIgnore:i}}function p(c){let l=Object.assign({},E);return Object.assign(l,c),l.callbacks=Object.assign({},E.callbacks,c.callbacks),l.head=Object.assign({},E.head,c.head),l.scripts=Object.assign({},E.scripts,c.scripts),l}function h(c){let l=[],s=c.ownerDocument?.activeElement;if(s?.tagName!=="BODY"&&c.contains(s))for(;s&&(l.push(s),s!==c);)s=s.parentElement;return l}function N(c){let l=Array.from(c.querySelectorAll("[id]"));return c.getAttribute?.("id")&&l.push(c),l}function b(c,l,s,o){for(let f of o){let i=f.getAttribute("id");if(l.has(i)){let m=f;for(;m;){let v=c.get(m);if(v==null&&(v=new Set,c.set(m,v)),v.add(i),m===s)break;m=m.parentElement}}}}function w(c,l,s){let o=N(c).filter(T=>!s(T)),f=N(l).filter(T=>!s(T)),i=a(o,f),m=new Map;b(m,i,c,o);let v=l.__hyperMorphRoot||l;return b(m,i,v,f),{persistentIds:i,idMap:m}}function a(c,l){let s=new Set,o=new Map;for(let i of c){let m=i.getAttribute("id");o.has(m)?s.add(m):o.set(m,i.tagName)}let f=new Set;for(let i of l){let m=i.getAttribute("id");f.has(m)?s.add(m):o.get(m)===i.tagName&&f.add(m)}for(let i of s)f.delete(i);return f}return r})(),{normalizeElement:Xe,normalizeParent:xe}=(function(){let r=new WeakSet;function p(a){return a?.nodeType===9?a.documentElement:a}function h(a){if(a==null)return document.createElement("div");if(typeof a=="string")return h(w(a));if(r.has(a))return a;if(a&&typeof a=="object"&&"nodeType"in a){if(a.parentNode)return new N(a);{let c=a.ownerDocument.createElement("div");return c.append(a),c}}else{let l=[...a][0]?.ownerDocument?.createElement("div")||document.createElement("div");for(let s of[...a])l.append(s);return l}}class N{constructor(c){this.originalNode=c,this.realParentNode=c.parentNode,this.previousSibling=c.previousSibling,this.nextSibling=c.nextSibling}get childNodes(){let c=[],l=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;l&&l!=this.nextSibling;)c.push(l),l=l.nextSibling;return c}querySelectorAll(c){return this.childNodes.reduce((l,s)=>{if(s instanceof Element){s.matches(c)&&l.push(s);let o=s.querySelectorAll(c);for(let f=0;f<o.length;f++)l.push(o[f])}return l},[])}insertBefore(c,l){return this.realParentNode.insertBefore(c,l)}moveBefore(c,l){return this.realParentNode.moveBefore(c,l)}get __hyperMorphRoot(){return this.originalNode}}function b(a){let c=f=>`<${f}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,l=a.replace(/<!--[\s\S]*?-->/g,"");for(let f of["script","style","textarea","title"])l=l.replace(new RegExp(`${c(f)}[\\s\\S]*?</${f}\\s*>`,"gi"),"");let s=new RegExp(`${c("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),o;do o=l,l=l.replace(s,"");while(l!==o);return l}function w(a){let c=new DOMParser,l=b(a);if(l.match(/<\/html>/)||l.match(/<\/head>/)||l.match(/<\/body>/)){let s=c.parseFromString(a,"text/html");if(l.match(/<\/html>/))return r.add(s),s;{let o=s.firstChild;return o&&r.add(o),o}}else{let o=c.parseFromString("<body><template>"+a+"</template></body>","text/html").body.querySelector("template").content;return r.add(o),o}}return{normalizeElement:p,normalizeParent:h}})(),Ce=Symbol("hyper-morph-duplicate-key"),Le=[r=>r.getAttribute("data-id"),r=>r.getAttribute("id")];function pe(r,p){return p.map(h=>{let N=new Map;for(let b of r){if(b.nodeType!==1)continue;let w=h(b);w==null||w===""||N.set(w,N.has(w)?Ce:b)}return N})}function Re(r,p,h,N){for(let b=0;b<N.length;b++){let w=N[b](r);if(w==null||w===""||p[b].get(w)!==r)continue;let a=h[b].get(w);if(!(!a||a===Ce)&&a.tagName===r.tagName)return a}return null}function ue(r,p,h){for(let N=0;N<h.length;N++){let b=h[N](r);if(!(b==null||b==="")&&p[N].get(b)===r)return!0}return!1}function et(r,p,h={}){let N=h.skip||(()=>!1),b=h.ignoreAttr||(()=>!1),w=h.tiers&&h.tiers.length?h.tiers:Le,a=null;function c(){return a||(a=pe([r,...r.querySelectorAll("*")],w)),a}let l=null;function s(){return l||(l=pe([p,...p.querySelectorAll("*")],w)),l}function o(O){return!O.parentElement||!O.parentElement.parentElement}function f(O,D,$){return o(O)||ue(O,c(),w)?($.push({type:"subtree",el:O,base:D}),!1):!0}function i(O,D){let $=[];for(let R of O.attributes)b(O,R.name)||D.getAttribute(R.name)!==R.value&&$.push(R.name);for(let R of D.attributes)b(O,R.name)||O.hasAttribute(R.name)||$.push(R.name);return $}function m(O){let D=[],$=null,R=()=>{$!==null&&(D.push({nodeType:3,nodeValue:$}),$=null)};for(let H of O.childNodes){if(H.nodeType===3){$=($===null?"":$)+H.nodeValue;continue}H.nodeType===1&&N(H)||(R(),(H.nodeType===1||H.nodeType===8)&&D.push(H))}return R(),D}function v(O,D){if(O.nodeType!==D.nodeType)return!1;if(O.nodeType!==1)return!0;if(O.tagName!==D.tagName)return!1;for(let $ of w){let R=$(O),H=$(D);if(R!=null&&R!==""&&H!=null&&H!==""&&R!==H)return!1}return!0}function T(O){let D="";for(let $ of O)$.nodeType===3&&$.nodeValue.trim()!==""?D+="\0"+$.nodeValue:$.nodeType===8&&(D+=""+$.nodeValue);return D}function L(O,D,$){let R=m(O),H=m(D);if(R.length===H.length){let j=!0;for(let Y=0;Y<R.length;Y++)if(!v(R[Y],H[Y])){j=!1;break}if(j){for(let Y=0;Y<R.length;Y++){let le=R[Y];if(le.nodeType===1){if(A(le,H[Y],$))return!0}else if(le.nodeValue!==H[Y].nodeValue)return!0}return!1}}let te=R.filter(j=>j.nodeType===1),ae=H.filter(j=>j.nodeType===1);if(T(R)!==T(H))return!0;let ce=pe(te,w),Be=pe(ae,w),Ne=[],ke=new Set,He=[];for(let j of te){let Y=Re(j,ce,Be,w);Y&&!ke.has(Y)?(Ne.push([j,Y]),ke.add(Y)):He.push(j)}let ie=[];for(let j of He)ue(j,ce,w)?$.push({type:"subtree",el:j,base:null}):ie.push(j);let ge=[];for(let j of ae)ke.has(j)||(ue(j,Be,w)?$.push({type:"deletion",el:j}):ge.push(j));if(ie.length!==ge.length)return!0;for(let j=0;j<ie.length;j++)if(!v(ie[j],ge[j]))return!0;let je=new Map(Ne);for(let j=0;j<ie.length;j++)je.set(ie[j],ge[j]);let $e=-1;for(let j of te){let Y=je.get(j);if(!Y)continue;let le=ae.indexOf(Y);if(le<$e)return!0;$e=le}for(let j=0;j<ie.length;j++)if(A(ie[j],ge[j],$))return!0;for(let[j,Y]of Ne)if(A(j,Y,$))return!0;return!1}function A(O,D,$){if(O.tagName!==D.tagName)return f(O,D,$);let R=i(O,D),H=[];if(L(O,D,H))return f(O,D,$);if(R.length){if(!o(O)&&!ue(D,s(),w))return!0;$.push({type:"attrs",el:O,names:R,base:D})}return $.push(...H),!1}let x=[],V=i(r,p);V.length&&x.push({type:"attrs",el:r,names:V});let C=(O,D)=>Array.from(O.children).find($=>$.tagName===D)||null,z=C(r,"HEAD"),K=C(p,"HEAD");if(z&&K){let O=[];A(z,K,O),O.length&&x.push({type:"head",el:z})}else(z||K)&&z&&x.push({type:"head",el:z});let G=C(r,"BODY"),_=C(p,"BODY");return G&&_?A(G,_,x):G&&x.push({type:"subtree",el:G,base:null}),{entries:x}}function tt(r,p,h={}){let N=h.tiers&&h.tiers.length?h.tiers:Le,b=r.documentElement,w=[],a=0,c=A=>({ok:!1,placed:w,held:A,skippedAttrs:a});if(!b)return c(null);function l(A){let x=[A,...A.querySelectorAll("*")];return pe(x,N)}let s=l(b),o=new Map,f=A=>{let x=A.getRootNode(),V=o.get(x);if(!V){let C=x.nodeType===9?x.documentElement:x;V=l(C),o.set(x,V)}return V};function i(A){if(!A.parentElement&&A.tagName==="HTML")return b;if(A.parentElement&&!A.parentElement.parentElement&&A.parentElement.tagName==="HTML"){if(A.tagName==="BODY")return r.body||null;if(A.tagName==="HEAD")return r.head||null}return null}function m(A){let x=i(A);return x||Re(A,f(A),s,N)}function v(A){if(!A)return null;let x=m(A);return x&&x.isConnected?x:null}function T(A){for(let x=0;x<N.length;x++){let V=N[x](A);V!=null&&V!==""&&s[x].set(V,A)}}for(let A of p){if(A.type!=="deletion")continue;let x=m(A.el);x&&x!==b&&x.remove()}let L=p.filter(A=>A.type!=="deletion").sort((A,x)=>A.el===x.el?0:A.el.compareDocumentPosition(x.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let A of L){if(A.type==="head"){let _=r.importNode(A.el,!0);r.head?r.head.replaceWith(_):b.insertBefore(_,b.firstChild),w.push({entry:A,imported:_});continue}if(A.type==="attrs"){let _=v(A.el)||v(A.base);if(!_){a++;continue}for(let O of A.names)A.el.hasAttribute(O)?_.setAttribute(O,A.el.getAttribute(O)):_.removeAttribute(O);continue}let x=A.el;if(i(x))return c(A);let V=v(x)||v(A.base);if(V){let _=r.importNode(x,!0);V.replaceWith(_),T(_),w.push({entry:A,imported:_});continue}if(A.base!=null&&!ue(A.base,f(A.base),N)||!ue(x,f(x),N))return c(A);let C=x.parentElement;if(!C)return c(A);let z=v(C);if(!z)return c(A);let K=null;for(let _=x.previousElementSibling;_;_=_.previousElementSibling){let O=v(_);if(O&&O.parentNode===z){K=O;break}}let G=r.importNode(x,!0);if(K)z.insertBefore(G,K.nextSibling);else{let _=Array.prototype.indexOf.call(C.children,x);z.insertBefore(G,z.children[_]||null)}T(G),w.push({entry:A,imported:G})}return{ok:!0,placed:w,held:null,skippedAttrs:a}}return{morph:J,defaults:E,findChangedRoots:et,spliceProtected:tt,mergeJson:ve,mergeScriptText:Me,parseJsonRelaxed:me,parseRulesRelaxed:Ie}})();var xt=de.morph,Ct=de.defaults,Lt=de.findChangedRoots,Rt=de.spliceProtected;var Bt=de;return at(Ht);})();
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&&lt(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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/ /g,"&nbsp;")}function qs(e){let s="<"+e.tagName.toLowerCase();for(let o of e.attributes)s+=` ${o.name}="${o.value.replace(/"/g,"&quot;")}"`;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"&&gt.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&&gt.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)&&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);})();
3
5
 
4
- // Convenience morph wrapper with data-id support
5
- var morph = function(oldEl, newEl, options = {}) {
6
- return HyperMorph.morph(oldEl, newEl, {
7
- key: (el) => (el.getAttribute && el.getAttribute('data-id')) || el.id || null,
8
- ...options
9
- });
10
- };
6
+ var morph = HyperMorph.morph;
11
7
 
12
8
  // Auto-export to window unless suppressed by loader
13
9
  if (!window.__hyperclayNoAutoExport) {