@panphora/clayjs 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/clay.standalone.js +6972 -3942
- package/entries/clay-data.js +1 -1
- package/entries/sap.js +6 -4
- package/package.json +1 -1
- package/src/core/admin-contenteditable.js +4 -1
- package/src/core/admin-inputs.js +23 -13
- package/src/core/admin-onclick.js +5 -0
- package/src/core/autosave.js +2 -0
- package/src/core/is-edit-mode.js +7 -2
- package/src/core/save.js +22 -4
- package/src/core/snapshot.js +46 -3
- package/src/core/source-map.js +246 -38
- package/src/lib/autosave-state.js +17 -0
- package/src/lib/dirty-gate.js +5 -0
- package/src/loader-logic.js +8 -2
- package/src/loader.js +2 -0
- package/src/plugins/ai-edit.js +625 -0
- package/src/plugins/source.js +150 -66
- package/src/sync/live-sync.js +467 -311
- package/src/sync/section-notice.js +6 -7
- package/src/vendor/control-serialize.vendor.js +13 -6
- package/src/vendor/hyper-morph.vendor.js +4 -9
- package/src/vendor/hypercms.vendor.js +38 -38
- package/src/sync/splice-merge.js +0 -270
|
@@ -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.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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
|
|
39
|
-
*
|
|
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
|
|
@@ -48,20 +48,27 @@ export function serializeControlToAttributes(el) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// Writes only what changes what a reload would show. A control whose attributes
|
|
52
|
+
// already reload as its live state is left exactly as the author wrote it, because a
|
|
53
|
+
// source-preserving save copies the author's bytes for every node the save did not
|
|
54
|
+
// change, and a rewrite here is a change.
|
|
51
55
|
export function finalizeControlForSave(target, source = target) {
|
|
52
56
|
const tag = target.tagName;
|
|
53
57
|
if (tag === "INPUT") {
|
|
54
58
|
const type = inputType(target);
|
|
55
59
|
if (type === "checkbox" || type === "radio") {
|
|
56
|
-
if (source.checked) target.
|
|
57
|
-
else target.
|
|
58
|
-
} else {
|
|
60
|
+
if (!source.checked) target.removeAttribute("checked");
|
|
61
|
+
else if (!target.hasAttribute("checked")) target.setAttribute("checked", "");
|
|
62
|
+
} else if (source.value !== (target.getAttribute("value") ?? "")) {
|
|
59
63
|
target.setAttribute("value", source.value);
|
|
60
64
|
}
|
|
61
65
|
return;
|
|
62
66
|
}
|
|
63
67
|
if (tag === "TEXTAREA") {
|
|
64
|
-
|
|
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;
|
|
65
72
|
target.removeAttribute("data-value");
|
|
66
73
|
return;
|
|
67
74
|
}
|
|
@@ -69,8 +76,8 @@ export function finalizeControlForSave(target, source = target) {
|
|
|
69
76
|
const tOpts = target.options;
|
|
70
77
|
const sOpts = source.options;
|
|
71
78
|
for (let i = 0; i < tOpts.length; i++) {
|
|
72
|
-
if (sOpts[i] && sOpts[i].selected) tOpts[i].
|
|
73
|
-
else tOpts[i].
|
|
79
|
+
if (!(sOpts[i] && sOpts[i].selected)) tOpts[i].removeAttribute("selected");
|
|
80
|
+
else if (!tOpts[i].hasAttribute("selected")) tOpts[i].setAttribute("selected", "");
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
var HyperMorph=(()=>{var ke=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var it=(e,n)=>{for(var t in n)ke(e,t,{get:n[t],enumerable:!0})},ot=(e,n,t,y)=>{if(n&&typeof n=="object"||typeof n=="function")for(let u of rt(n))!st.call(e,u)&&u!==t&&ke(e,u,{get:()=>n[u],enumerable:!(y=nt(n,u))||y.enumerable});return e};var at=e=>ot(ke({},"__esModule",{value:!0}),e);var Ht={};it(Ht,{HyperMorph:()=>fe,default:()=>Bt,defaults:()=>Ct,findChangedRoots:()=>Lt,mergeJson:()=>Se,mergeScriptText:()=>ve,morph:()=>xt,parseJsonRelaxed:()=>ge,parseRulesRelaxed:()=>Ee,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 n=5381;for(let t=0;t<e.length;t++)n=(n<<5)+n^e.charCodeAt(t);return Math.abs(n).toString(36)}function ct(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let n=e.getAttribute?.("class");return n?n.split(/\s+/).filter(Boolean).sort().join(" "):""}function lt(e,n){let t=[];for(let y of e.attributes||[]){let u=y.name;u==="id"||u==="class"||n.excludeAttributePrefixes.some(b=>u.startsWith(b))||n.includeAttributes.includes(u)&&t.push(`${u}=${y.value}`)}return t.sort().join("|")}function ft(e,n){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,n.textHintLength)}function dt(e,n){let t=[e.tagName];return n.includeClasses&&t.push(ct(e)),t.push(lt(e,n)),ut(t.join("|"))}function ht(e){let n=e.tagName,t=1,y=e.previousElementSibling;for(;y;)y.tagName===n&&t++,y=y.previousElementSibling;return t}function pt(e,n){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:n.landmarks.includes(e.tagName)}function gt(e){let n=e.getAttribute?.("id");if(n)return`#${n}`;let t=e.getAttribute?.("role");return t?`@${t}`:e.tagName}function mt(e,n){let t=[],y=e;for(;y&&y.tagName&&t.length<n.maxPathDepth;){let u=`${y.tagName}:${ht(y)}`;if(t.unshift(u),y!==e&&pt(y,n)){t.unshift(gt(y));break}y=y.parentElement}return t}function yt(e,n){let t=0,y=e.length-1,u=n.length-1;for(;y>=0&&u>=0&&e[y]===n[u];)t++,y--,u--;return t}function X(e,n,t){if(t.has(e))return t.get(e);let y={signature:dt(e,n),path:mt(e,n),textHint:ft(e,n)};return t.set(e,y),y}function qe(e,n,t,y){if(y.has(e))return y.get(e);let u=new Map,b=e.querySelectorAll("*"),S=0;for(let d of b){let M=X(d,n,t);M.domIndex=S++,!n.shouldIgnore?.(d)&&(u.has(M.signature)||u.set(M.signature,[]),u.get(M.signature).push(d))}return y.set(e,u),u}function bt(e,n,t){t.delete(e),n.delete(e);let y=e.querySelectorAll("*");for(let u of y)n.delete(u)}function we(e,n,t,y,u){let b=X(e,t,y),S=X(n,t,y),d=t.weights,M={},$=0;if(b.signature!==S.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};$+=d.signature,M.signature=d.signature;let H=yt(b.path,S.path)*d.pathSegment;$+=H,M.path=H;let I=!0;if(b.textHint&&S.textHint?b.textHint===S.textHint?($+=d.textMatch,M.text=d.textMatch):($-=d.textMismatch,M.text=-d.textMismatch,I=!1):b.textHint!==S.textHint&&($-=d.textMismatch,M.text=-d.textMismatch,I=!1),u.candidateCount===1&&I&&($+=d.uniqueCandidate,M.unique=d.uniqueCandidate),typeof b.domIndex=="number"&&typeof S.domIndex=="number"){let k=Math.abs(b.domIndex-S.domIndex),E=Math.min(k*d.positionPenalty,d.maxDriftPenalty);$-=E,M.drift=-E}return{score:$,breakdown:M}}function De(e,n,t,y,u){if(t.excludeIds&&e.getAttribute("id"))return null;let b=qe(n,t,y,u),S=X(e,t,y);if(typeof S.domIndex!="number"){let I=0,k=e.previousElementSibling;for(;k;)I++,k=k.previousElementSibling;S.domIndex=I}let d=b.get(S.signature)||[],M=t.excludeIds?d.filter(I=>!I.getAttribute("id")):d;if(M.length===0)return null;let $=null,q=0,H=null;for(let I of M){let{score:k,breakdown:E}=we(e,I,t,y,{candidateCount:M.length});k>q&&(q=k,$=I,H=E)}return q<t.minConfidence?null:{element:$,confidence:q,breakdown:H}}function At(e,n,t,y){let u=[],b=t.weights.signature+t.weights.slotMatch,S={slot:b};function d(H){if(H.children)return H.children;let I=H.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(H,I){let k=d(H),E=d(I);if(k.length===E.length)for(let K=0;K<k.length;K++){let U=k[K],J=E[K];if(t.shouldIgnore?.(U)||t.shouldIgnore?.(J)||t.excludeIds&&(U.getAttribute("id")||J.getAttribute("id"))||U.tagName!==J.tagName)continue;let Q=X(U,t,y).signature,ee=X(J,t,y).signature;Q!==ee&&u.push({newEl:U,oldEl:J,score:b,breakdown:S}),M(U,J)}}function $(H,I){for(;;){if(H.tagName===I.tagName)return[H,I];let k=d(H);if(!H.tagName&&k.length===1){H=k[0];continue}let E=d(I);if(E.length===1&&E[0].tagName===H.tagName){I=E[0];continue}return null}}let q=$(e,n);return q&&M(q[0],q[1]),u}function ze(e,n,t,y,u){let b=n.querySelectorAll("*"),S=qe(e,t,y,u),d=0;for(let k of b){let E=X(k,t,y);E.domIndex=d++}let M=[],$=new Map;function q(k,E,K){let U=new Set;if(k.textHint){let G=$.get(k.signature);if(!G){G=new Map;for(let ne of E){let ye=X(ne,t,y).textHint,re=G.get(ye);re||(re=[],G.set(ye,re)),re.push(ne)}$.set(k.signature,G)}let de=G.get(k.textHint);if(de)for(let ne=0;ne<de.length&&ne<K;ne++)U.add(de[ne])}let J=0,Q=E.length;for(;J<Q;){let G=J+Q>>1;X(E[G],t,y).domIndex<k.domIndex?J=G+1:Q=G}let ee=Math.max(0,Math.min(J-(K>>1),E.length-K)),te=Math.min(ee+K,E.length);for(let G=ee;G<te;G++)U.add(E[G]);return[...U]}for(let k of b){if(t.shouldIgnore?.(k)||t.excludeIds&&k.getAttribute("id"))continue;let E=X(k,t,y),K=S.get(E.signature)||[],U=t.excludeIds?K.filter(ee=>!ee.getAttribute("id")):K,J=t.maxScoredCandidates,Q=J&&U.length>J?q(E,U,J):U;for(let ee of Q){let{score:te,breakdown:G}=we(k,ee,t,y,{candidateCount:U.length});te>=t.minConfidence&&M.push({newEl:k,oldEl:ee,score:te,breakdown:G})}}if(t.weights.slotMatch>0){let k=At(n,e,t,y);for(let E of k)M.push(E)}M.sort((k,E)=>E.score-k.score);let H=new Map,I=new Set;for(let{newEl:k,oldEl:E}of M)H.has(k)||I.has(E)||(H.set(k,E),I.add(E));return H}function _e(e,n,t,y){let u=X(e,t,y),b=X(n,t,y),{score:S,breakdown:d}=we(e,n,t,y,{candidateCount:1});return{matches:S>=t.minConfidence,score:S,breakdown:d,newMeta:{signature:u.signature,path:u.path,textHint:u.textHint},oldMeta:{signature:b.signature,path:b.path,textHint:b.textHint}}}function Fe(e={}){let n={...Pe,...e,weights:{...Pe.weights,...e.weights}},t=new WeakMap,y=new WeakMap;return{findMatch:(u,b)=>De(u,b,n,t,y),computeMatches:(u,b)=>ze(u,b,n,t,y),explain:(u,b)=>_e(u,b,n,t),invalidate:u=>bt(u,t,y),session:()=>{let u=new WeakMap,b=new WeakMap;return{findMatch:(S,d)=>De(S,d,n,u,b),computeMatches:(S,d)=>ze(S,d,n,u,b),explain:(S,d)=>_e(S,d,n,u)}},getConfig:()=>({...n})}}function Te(e,n){for(;;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]==="/"&&e[n+1]==="/"){for(;n<e.length&&e[n]!==`
|
|
2
|
-
`;)n++;continue}if(e[n]==="/"&&e[n+1]==="*"){let t=e.indexOf("*/",n+2);if(t===-1)return e.length;n=t+2;continue}return n}}function Ve(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(n,t)=>t.length%2===0?t+'\\"':n)}var St=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,vt=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function ge(e){try{return JSON.parse(e)}catch{return JSON.parse(Mt(e))}}function Mt(e){let n="",t=0,y=(u,b)=>{throw new Error(`Invalid relaxed JSON: ${u} at position ${b}`)};for(;t<e.length&&(t=Te(e,t),!(t>=e.length));){let u=e[t];if("{}[]:".includes(u)){n+=u,t++;continue}if(u===","){let d=Te(e,t+1);if(e[d]==="}"||e[d]==="]"){t++;continue}n+=u,t++;continue}if(u==='"'||u==="'"){let d=t+1;for(;d<e.length&&e[d]!==u;)e[d]==="\\"&&d++,d++;d>=e.length&&y("unterminated string",t);let M=e.slice(t+1,d);u==="'"&&(M=Ve(M)),n+='"'+M+'"',t=d+1;continue}let b=t;for(;b<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[b]);)b++;b===t&&y("unexpected character "+JSON.stringify(u),t);let S=e.slice(t,b);if(S==="true"||S==="false"||S==="null"||St.test(S)){n+=S,t=b;continue}if(vt.test(S)){if(e[Te(e,b)]===":"){n+='"'+S+'"',t=b;continue}y("unquoted value "+JSON.stringify(S),t)}y("invalid token "+JSON.stringify(S),t)}return n}function Ee(e){try{return JSON.parse(e)}catch{}let n={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function t(u){let b=[],S=0;for(;S<u.length;){let d=u[S];if(/\s/.test(d)){S++;continue}if("{}".includes(d)){b.push({type:d,value:d}),S++;continue}if(d==="["){let H=!1,I=S+1;for(;I<u.length&&/\s/.test(u[I]);)I++;if(I<u.length&&/[a-zA-Z_]/.test(u[I])&&(H=!0),!H){b.push({type:d,value:d}),S++;continue}}if(d==="]"){b.push({type:d,value:d}),S++;continue}if(d===":"){b.push({type:n.COLON,value:d}),S++;continue}if(d===","){b.push({type:n.COMMA,value:d}),S++;continue}if(d==='"'||d==="'"){let H=d,I=S+1;for(;I<u.length&&u[I]!==H;)u[I]==="\\"&&I++,I++;b.push({type:n.STRING,value:u.substring(S+1,I),quoted:!0,sourceQuote:H}),S=I+1;continue}let M=S,$;for(;M<u.length&&!/[{},]/.test(u[M]);)if(u[M]===":"){let H=[":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 H){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 H=u[M];for(M++;M<u.length&&u[M]!==H;)u[M]==="\\"&&M++,M++}M++}M<u.length&&u[M]==="]"&&M++}else M++;$=u.substring(S,M);let q=n.IDENTIFIER;/^-?\d+(\.\d+)?$/.test($)?q=n.NUMBER:$==="true"||$==="false"||$==="null"?q=n.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test($)&&(q=n.SELECTOR),b.push({type:q,value:$,quoted:!1}),S=M}return b}function y(u){let b="";for(let S=0;S<u.length;S++){let d=u[S];if("{}".includes(d.type)||"[]".includes(d.type)){b+=d.value;continue}if(d.type===n.COLON){b+=d.value;continue}if(d.type===n.COMMA){let M=u[S+1];if(M&&(M.type==="}"||M.type==="]"))continue;b+=d.value;continue}if(d.type===n.STRING){let M=d.value;d.sourceQuote==="'"&&(M=Ve(M)),b+=`"${M}"`;continue}if(d.type===n.NUMBER||d.type===n.BOOLEAN){b+=d.value;continue}b+=`"${d.value}"`}return b}try{let u=t(e),b=y(u);return JSON.parse(b)}catch(u){throw new Error("Invalid extraction rules syntax: "+u.message)}}var V=Symbol("hyper-morph-json-merge:missing"),Ke=["id","_id","uuid","key","slug","code","name"];function le(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function me(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Nt(e,n,t){Object.defineProperty(e,n,{value:t,enumerable:!0,writable:!0,configurable:!0})}function ie(e,n){if(e===n)return!0;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!ie(e[t],n[t]))return!1;return!0}if(le(e)&&le(n)){let t=Object.keys(e);if(t.length!==Object.keys(n).length)return!1;for(let y of t)if(!me(n,y)||!ie(e[y],n[y]))return!1;return!0}return!1}function Ue(e,n,t,y){return ie(n,t)?n:ie(n,e)?t:ie(t,e)?n:le(n)&&le(t)?kt(le(e)?e:{},n,t,y):Array.isArray(n)&&Array.isArray(t)?It(Array.isArray(e)?e:[],n,t,y):t}function Je(e,n,t,y){return n===V&&t===V?V:n===V?e===V?t:ie(t,e)?V:t:t===V?e===V?n:V:Ue(e,n,t,y)}function kt(e,n,t,y){let u={},b=new Set([...Object.keys(e),...Object.keys(n),...Object.keys(t)]);for(let S of b){let d=Je(me(e,S)?e[S]:V,me(n,S)?n[S]:V,me(t,S)?t[S]:V,y);d!==V&&Nt(u,S,d)}return u}function wt(e){return e===null||typeof e!="object"}function Ae(e){return typeof e+":"+String(e)}function Tt(e,n){for(let t of n){let y=new Set;for(let u of t){if(!me(u,e))return!1;let b=u[e];if(typeof b!="string"&&typeof b!="number")return!1;let S=Ae(b);if(y.has(S))return!1;y.add(S)}}return!0}function Et(e,n,t,y){let u=[e,n,t],b=!0;for(let S of u)for(let d of S)le(d)||(b=!1);if(b){for(let S of y.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 $=Ae(M);if(d.has($))return null;d.add($)}}return{kind:"self"}}function It(e,n,t,y){let u=Et(e,n,t,y);if(!u)return t;let b=u.kind==="self"?Ae:k=>Ae(k[u.field]),S=k=>{let E=new Map;for(let K of k)E.set(b(K),K);return E},d=S(e),M=S(n),$=S(t),q=new Map,H=new Set([...d.keys(),...M.keys(),...$.keys()]);for(let k of H){let E=Je(d.has(k)?d.get(k):V,M.has(k)?M.get(k):V,$.has(k)?$.get(k):V,y);E!==V&&q.set(k,E)}let I=[];for(let k of t){let E=b(k);q.has(E)&&I.push(E)}for(let k=0;k<n.length;k++){let E=b(n[k]);if(!q.has(E)||I.includes(E))continue;let K=0;for(let U=k-1;U>=0;U--){let J=I.indexOf(b(n[U]));if(J!==-1){K=J+1;break}}I.splice(K,0,E)}return I.map(k=>q.get(k))}function Se(e,n,t,y={}){let u=y.keyCandidates?[...y.keyCandidates,...Ke]:Ke;return Ue(e===void 0?V:e,n,t,{keyCandidates:u})}function ve(e,n,t,y={}){let u=y.parse||ge,b=[],S=(H,I)=>{if(typeof H!="string")return V;try{return u(H)}catch(k){return b.push(`${I} side is not valid JSON (${k.message})`),V}},d=S(n,"local"),M=S(t,"remote");if(d===V)return{text:t,warnings:b};if(M===V)return{text:n,warnings:b};let $=S(e,"base"),q=Se($===V?void 0:$,d,M,y);return ie(q,M)?{text:t,warnings:b}:ie(q,d)?{text:n,warnings:b}:{text:JSON.stringify(q,null,2),warnings:b}}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 n=Ot[e];if(!n)throw new Error(`Unknown region capability: ${e}`);return[...n.tokens,...n.bundles].flatMap(t=>[`[clay~="${t}"]`,`[${t}]`]).join(", ")}var fe=(function(){"use strict";let e=()=>{},n='[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"]',t=`${We("history")},[no-undo],[clay~="no-undo"]`;function y(r){if(r?.nodeType!==1)return!1;if(r.matches(n))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(n)?!0:y(r)}function b(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"),A=r.getAttribute("type")||"text/javascript";if(N)try{let w=new URL(N,window.location.href);return`ext:${A}:${w.origin}${w.pathname}${w.search}`}catch{return`ext:${A}:${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:${A}:${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 $(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 H={match:r=>r.hasAttribute("merge"),identity:r=>r.getAttribute("merge")};function I(r,p,h){if(h.merge===!1)return null;let N=[H,...h.mergeTags||[]],A=new WeakMap,w=i=>{if(A.has(i))return A.get(i);let g=null;if(d(i)&&!i.getAttribute("src")&&!u(i)){let m=i;for(let T=0;T<N.length;T++)if(N[T].match(m)){if(!q(m))console.warn("[hyper-morph] merge ignored: script type is not JSON",m);else{let R=N[T].identity(m);R!=null&&R!==""&&(g={key:T+":"+R,raw:R,recognizer:N[T]})}break}}return A.set(i,g),g},a=new Set,c=i=>{let g=new Map,m=T=>{let R=w(T);R&&(g.has(R.key)?(a.add(R.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${R.raw}"`)):g.set(R.key,T))};d(i)&&m(i);for(let T of i.querySelectorAll("script"))m(T);return g},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 g;typeof i=="string"?g=new DOMParser().parseFromString(i,"text/html").documentElement:i?.nodeType===9?g=i.documentElement:g=i;let m=T=>{let R=w(T);R&&!o.has(R.key)&&o.set(R.key,T.textContent)};d(g)&&m(g);for(let T of g.querySelectorAll("script"))m(T);return o}}}function k(r,p,h){let N=r.merge;if(!N)return!1;let A=N.identityOf(p);if(!A||N.disabled.has(A.key))return!1;let w=N.identityOf(h);if(!w||w.key!==A.key)return!1;let a=p,c=h,l=c.getAttribute("merge-key")||a.getAttribute("merge-key"),{text:s,warnings:o}=ve(N.baseTexts().get(A.key),a.textContent,c.textContent,{parse:A.recognizer.parse,keyCandidates:l?l.split(/[\s,]+/).filter(Boolean):void 0});for(let f of o)console.warn(`[hyper-morph] merge "${A.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},K={computeMatches(r,p,h=u){let{computeMatches:N}=Fe({shouldIgnore:h}).session();return N(r,p)}};function U(r,p,h={}){r=Xe(r);let N=Oe(p),A=Qe(r,N,h),w=A.scripts.handle?new Set(Array.from(r.querySelectorAll("script")).map(s=>b(s,A.scripts.matchMode,A.merge))):null,a=ne(A),c;try{c=Ge(A,r,N,s=>s.morphStyle==="innerHTML"?(re(s,r,N),Array.from(r.childNodes)):de(s,r,N))}catch(s){throw Q(A),s}let l=s=>{a&&ye(A,a),J(A);let o=w?Ze(s,w,A):[];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(A),o}},s=>{throw Q(A),s});try{return l(c)}catch(s){throw Q(A),s}}function J(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,A]of h){if(!p.contains(N))continue;let w=A.nextSibling?.parentNode===A.parent?A.nextSibling:null;try{te(A.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 te(r,p,h){if(r.moveBefore)try{r.moveBefore(p,h)}catch{r.insertBefore(p,h)}else r.insertBefore(p,h)}function G(r,p){!r.stagedNodes.has(p)&&p.parentNode&&r.stagedNodes.set(p,{parent:p.parentNode,nextSibling:p.nextSibling}),te(ee(r),p,null)}function de(r,p,h){let N=Oe(p);return re(r,N,h,p,p.nextSibling),Array.from(N.childNodes)}function ne(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:A}=p;return{element:p,id:h,selectionStart:N,selectionEnd:A}}function ye(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 re=(function(){function r(s,o,f,i=null,g=null){o?.tagName==="TEMPLATE"&&f?.tagName==="TEMPLATE"&&(o=o.content,f=f.content),i||=o.firstChild;for(let m of f.childNodes){if(s.shouldIgnore(m))continue;if(i&&i!=g){let R=N(s,m,i,g);if(R){R!==i&&w(s,i,R),be(R,m,s),i=R.nextSibling;continue}}if(m?.nodeType===1){let R=m.getAttribute("id");if(s.persistentIds.has(R)){let v=a(o,R,i,s);be(v,m,s),i=v.nextSibling;continue}if(!s.idMap.has(m)){let v=s.hyperMatches.get(m);if(v&&!s.idMap.has(v)&&!l(v,o)){te(o,v,i),be(v,m,s),i=v.nextSibling;continue}}}let T=p(o,m,i,s);T&&(i=T.nextSibling)}for(;i&&i!=g;){let m=i;i=i.nextSibling,s.shouldIgnore(m)||A(s,m)}}function p(s,o,f,i){if(i.callbacks.beforeNodeAdded(o)===!1)return null;let g=s.ownerDocument||s.realParentNode?.ownerDocument||i.target.ownerDocument;if(i.idMap.has(o)){let m=o,T=g.createElementNS(m.namespaceURI,m.localName);return s.insertBefore(T,f),be(T,o,i),i.callbacks.afterNodeAdded(T),T}else{let m=$(h(o,g,i));return m?(s.insertBefore(m,f),i.callbacks.afterNodeAdded(m),m):null}}function h(s,o,f){if(f.shouldIgnore(s))return null;let i=o.importNode(s,!1),g=s.nodeType===1&&s.tagName==="TEMPLATE"?s.content:s,m=i.nodeType===1&&i.tagName==="TEMPLATE"?i.content:i;for(let T of Array.from(g.childNodes||[])){let R=h(T,o,f);R&&m.appendChild(R)}return i}let N=(function(){function s(i,g,m,T){let R=g?.nodeType===1&&!i.idMap.has(g)?i.hyperMatches.get(g):null,v=null,O=g.nextSibling,P=0,B=m;for(;B&&B!=T;){if(i.shouldIgnore(B)){B=B.nextSibling;continue}if(f(B,g)){if(o(i,B,g)||B===R&&!i.idMap.has(B))return B;if(v===null){let F=B?.nodeType===1&&i.hyperMatchedOldElements.has(B);!i.idMap.has(B)&&!F&&(v=B)}}if(v===null&&O&&f(B,O)&&(P++,O=O.nextSibling,P>=2&&(v=void 0)),i.activeElementAndParents.includes(B))break;B=B.nextSibling}return v||null}function o(i,g,m){let T=i.idMap.get(g),R=i.idMap.get(m);if(!R||!T)return!1;for(let v of T)if(R.has(v))return!0;return!1}function f(i,g){let m=i,T=g;return m.nodeType===T.nodeType&&m.tagName===T.tagName&&(!m.getAttribute?.("id")||m.getAttribute?.("id")===T.getAttribute?.("id"))}return s})();function A(s,o){let f=o?.nodeType===1&&s.hyperMatchedOldElements.has(o)&&!s.idMap.has(o);if(s.idMap.has(o)||f)G(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 g=i;i=i.nextSibling,s.shouldIgnore(g)||A(s,g)}return i}function a(s,o,f,i){let g=i.target.ownerDocument?.defaultView?.CSS?.escape?i.target.ownerDocument.defaultView.CSS.escape(o):String(o).replace(/["\\]/g,"\\$&"),m=i.target.getAttribute?.("id")===o&&i.target||i.target.querySelector(`[id="${g}"]`)||i.pantry?.querySelector(`[id="${g}"]`);return c(m,i),te(s,m,f),m}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})(),be=(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"?Ie(a,c,l):(p(a,c,l),k(l,a,c)||w(a,l)||re(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,g=f.attributes;for(let m of g)A(m.name,o,"update",l)||o.getAttribute(m.name)!==m.value&&o.setAttribute(m.name,m.value);for(let m=i.length-1;0<=m;m--){let T=i[m];if(T&&!f.hasAttribute(T.name)){if(A(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&&(A("value",a,"update",l)||(a.value=s)):c.hasAttribute("value")?o!==s&&(A("value",a,"update",l)||(a.setAttribute("value",s),a.value=s)):A("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(A("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=A(l,a,"update",s);if(i||(a[l]=c[l]),s.formStateSync==="property")return;o?i||a.setAttribute(l,""):A(l,a,"remove",s)||a.removeAttribute(l)}}function A(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 A=p.querySelector("head"),w=h.querySelector("head");if(A&&w){let a=Ie(A,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 Ie(r,p,h){let N=[],A=[],w=[],a=[],c=h.scripts.matchMode,l=f=>{if(f.tagName==="SCRIPT")return b(f,c,h.merge);if(f.tagName==="LINK"&&c==="smart"){let i=f.getAttribute("href");if(i)try{let g=new URL(i,window.location.href);return`link:${f.getAttribute("rel")||""}:${g.origin}${g.pathname}${g.search}`}catch{}}return f.outerHTML},s=new Map;for(let f of p.children){if(h.shouldIgnore(f))continue;let i=l(f),g=s.get(i);g||(g=[],s.set(i,g)),g.push(f)}for(let f of r.children){let i=l(f),g=s.get(i),m=!!(g&&g.length),T=h.head.shouldReAppend(f),R=h.head.shouldPreserve(f);if(m||R)if(T)A.push(f);else{if(g&&g.length){let v=g.pop();g.length||s.delete(i),k(h,f,v)}w.push(f)}else h.head.style==="append"?T&&(A.push(f),a.push(f)):h.head.shouldRemove(f)!==!1&&!h.shouldIgnore(f)&&A.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 g,m=new Promise(function(T){g=T});i.addEventListener("load",function(){g()}),i.addEventListener("error",function(){g()}),o.push(m)}r.appendChild(i),h.callbacks.afterNodeAdded(i),N.push(i)}}for(let f of A)h.callbacks.beforeNodeRemoved(f)!==!1&&(r.removeChild(f),h.callbacks.afterNodeRemoved(f));return h.head.afterHeadMorphed(r,{added:N,kept:w,removed:A}),o}function Ze(r,p,h){if(!h.scripts.handle)return[];let N=[],A=[],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=b(o,c,h.merge),i=p.has(f),g=h.scripts.shouldPreserve(o),m=h.scripts.shouldReAppend(o);i||g?m?(A.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,g=new Promise(function(m){i=m});f.addEventListener("load",function(){i()}),f.addEventListener("error",function(){i()}),s.push(g)}o.replaceWith(f),h.callbacks.afterNodeAdded(f),N.push(f)}return h.scripts.afterScriptsHandled(h.target,{added:N,kept:w,removed:A}),s}let Qe=(function(){function r(c,l,s){let o=s.policy==="history"?t:n,f=s.policy==="raw"?()=>!1:P=>{if(P?.nodeType!==1)return!1;if(s.policy!=="history"&&u(P))return!0;let B=P.closest(o);return!(!B||s.policy==="history"&&B===c&&B.matches('[no-undo],[clay~="no-undo"]')&&!B.matches('[editor-ui],[clay~="editor-ui"]'))},{persistentIds:i,idMap:g}=w(c,l,f),m=K.computeMatches(c,l,f);if(typeof s.key=="function"){let P=new Map,B=new Set,F=x=>{let L=s.key(x);L!=null&&(P.has(L)?B.add(L):P.set(L,x))};c instanceof Element&&F(c);for(let x of c.querySelectorAll("*"))F(x);for(let x of B)P.delete(x);let Y=new Map;for(let[x,L]of m)Y.set(L,x);let Z=l.__hyperMorphRoot||l,z=new Map,C=new Set,D=x=>{let L=s.key(x);L!=null&&(z.has(L)?C.add(L):z.set(L,x))};Z instanceof Element&&D(Z);for(let x of Z.querySelectorAll("*"))D(x);for(let x of C)z.delete(x);for(let[x,L]of z){let _=P.get(x);if(!_||_.tagName!==L.tagName)continue;let oe=Y.get(_);oe&&oe!==L&&m.delete(oe);let ae=m.get(L);ae&&ae!==_&&Y.delete(ae),m.set(L,_),Y.set(_,L)}}let T=p(s),R=I(c,l,T.scripts);if(R){let P=new Map;for(let[B,F]of m)P.set(F,B);for(let[B,F]of R.newByKey){if(R.disabled.has(B))continue;let Y=R.oldByKey.get(B);if(!Y)continue;let Z=P.get(Y);Z&&Z!==F&&m.delete(Z);let z=m.get(F);z&&z!==Y&&P.delete(z),m.set(F,Y),P.set(Y,F)}}let v=new Set;for(let P of m.values())v.add(P);let O=T.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(O))throw new Error(`Do not understand how to morph style ${O}`);return{target:c,newContent:l,config:T,morphStyle:O,ignoreActive:T.ignoreActive,ignoreActiveValue:T.ignoreActiveValue,restoreFocus:T.restoreFocus,formStateSync:T.formStateSync||"attribute",idMap:g,persistentIds:i,hyperMatches:m,hyperMatchedOldElements:v,merge:R,pantry:null,stagedNodes:new Map,activeElementAndParents:h(c),callbacks:T.callbacks,head:T.head,scripts:T.scripts,shouldIgnore:f}}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 A(c,l,s,o){for(let f of o){let i=f.getAttribute("id");if(l.has(i)){let g=f;for(;g;){let m=c.get(g);if(m==null&&(m=new Set,c.set(g,m)),m.add(i),g===s)break;g=g.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),g=new Map;A(g,i,c,o);let m=l.__hyperMorphRoot||l;return A(g,i,m,f),{persistentIds:i,idMap:g}}function a(c,l){let s=new Set,o=new Map;for(let i of c){let g=i.getAttribute("id");o.has(g)?s.add(g):o.set(g,i.tagName)}let f=new Set;for(let i of l){let g=i.getAttribute("id");f.has(g)?s.add(g):o.get(g)===i.tagName&&f.add(g)}for(let i of s)f.delete(i);return f}return r})(),{normalizeElement:Xe,normalizeParent:Oe}=(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 A(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=A(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}})(),xe=Symbol("hyper-morph-duplicate-key"),Ce=[r=>r.getAttribute("data-id"),r=>r.getAttribute("id")];function he(r,p){return p.map(h=>{let N=new Map;for(let A of r){if(A.nodeType!==1)continue;let w=h(A);w==null||w===""||N.set(w,N.has(w)?xe:A)}return N})}function Le(r,p,h,N){for(let A=0;A<N.length;A++){let w=N[A](r);if(w==null||w===""||p[A].get(w)!==r)continue;let a=h[A].get(w);if(!(!a||a===xe)&&a.tagName===r.tagName)return a}return null}function ue(r,p,h){for(let N=0;N<h.length;N++){let A=h[N](r);if(!(A==null||A==="")&&p[N].get(A)===r)return!0}return!1}function et(r,p,h={}){let N=h.skip||(()=>!1),A=h.ignoreAttr||(()=>!1),w=h.tiers&&h.tiers.length?h.tiers:Ce,a=null;function c(){return a||(a=he([r,...r.querySelectorAll("*")],w)),a}let l=null;function s(){return l||(l=he([p,...p.querySelectorAll("*")],w)),l}function o(C){return!C.parentElement||!C.parentElement.parentElement}function f(C,D,x){return o(C)||ue(C,c(),w)?(x.push({type:"subtree",el:C,base:D}),!1):!0}function i(C,D){let x=[];for(let L of C.attributes)A(C,L.name)||D.getAttribute(L.name)!==L.value&&x.push(L.name);for(let L of D.attributes)A(C,L.name)||C.hasAttribute(L.name)||x.push(L.name);return x}function g(C){let D=[],x=null,L=()=>{x!==null&&(D.push({nodeType:3,nodeValue:x}),x=null)};for(let _ of C.childNodes){if(_.nodeType===3){x=(x===null?"":x)+_.nodeValue;continue}_.nodeType===1&&N(_)||(L(),(_.nodeType===1||_.nodeType===8)&&D.push(_))}return L(),D}function m(C,D){if(C.nodeType!==D.nodeType)return!1;if(C.nodeType!==1)return!0;if(C.tagName!==D.tagName)return!1;for(let x of w){let L=x(C),_=x(D);if(L!=null&&L!==""&&_!=null&&_!==""&&L!==_)return!1}return!0}function T(C){let D="";for(let x of C)x.nodeType===3&&x.nodeValue.trim()!==""?D+="\0"+x.nodeValue:x.nodeType===8&&(D+=""+x.nodeValue);return D}function R(C,D,x){let L=g(C),_=g(D);if(L.length===_.length){let j=!0;for(let W=0;W<L.length;W++)if(!m(L[W],_[W])){j=!1;break}if(j){for(let W=0;W<L.length;W++){let ce=L[W];if(ce.nodeType===1){if(v(ce,_[W],x))return!0}else if(ce.nodeValue!==_[W].nodeValue)return!0}return!1}}let oe=L.filter(j=>j.nodeType===1),ae=_.filter(j=>j.nodeType===1);if(T(L)!==T(_))return!0;let Re=he(oe,w),Be=he(ae,w),Me=[],Ne=new Set,He=[];for(let j of oe){let W=Le(j,Re,Be,w);W&&!Ne.has(W)?(Me.push([j,W]),Ne.add(W)):He.push(j)}let se=[];for(let j of He)ue(j,Re,w)?x.push({type:"subtree",el:j,base:null}):se.push(j);let pe=[];for(let j of ae)Ne.has(j)||(ue(j,Be,w)?x.push({type:"deletion",el:j}):pe.push(j));if(se.length!==pe.length)return!0;for(let j=0;j<se.length;j++)if(!m(se[j],pe[j]))return!0;let je=new Map(Me);for(let j=0;j<se.length;j++)je.set(se[j],pe[j]);let $e=-1;for(let j of oe){let W=je.get(j);if(!W)continue;let ce=ae.indexOf(W);if(ce<$e)return!0;$e=ce}for(let j=0;j<se.length;j++)if(v(se[j],pe[j],x))return!0;for(let[j,W]of Me)if(v(j,W,x))return!0;return!1}function v(C,D,x){if(C.tagName!==D.tagName)return f(C,D,x);let L=i(C,D),_=[];if(R(C,D,_))return f(C,D,x);if(L.length){if(!o(C)&&!ue(D,s(),w))return!0;x.push({type:"attrs",el:C,names:L,base:D})}return x.push(..._),!1}let O=[],P=i(r,p);P.length&&O.push({type:"attrs",el:r,names:P});let B=(C,D)=>Array.from(C.children).find(x=>x.tagName===D)||null,F=B(r,"HEAD"),Y=B(p,"HEAD");if(F&&Y){let C=[];v(F,Y,C),C.length&&O.push({type:"head",el:F})}else(F||Y)&&F&&O.push({type:"head",el:F});let Z=B(r,"BODY"),z=B(p,"BODY");return Z&&z?v(Z,z,O):Z&&O.push({type:"subtree",el:Z,base:null}),{entries:O}}function tt(r,p,h={}){let N=h.tiers&&h.tiers.length?h.tiers:Ce,A=r.documentElement,w=[],a=0,c=v=>({ok:!1,placed:w,held:v,skippedAttrs:a});if(!A)return c(null);function l(v){let O=[v,...v.querySelectorAll("*")];return he(O,N)}let s=l(A),o=new Map,f=v=>{let O=v.getRootNode(),P=o.get(O);if(!P){let B=O.nodeType===9?O.documentElement:O;P=l(B),o.set(O,P)}return P};function i(v){if(!v.parentElement&&v.tagName==="HTML")return A;if(v.parentElement&&!v.parentElement.parentElement&&v.parentElement.tagName==="HTML"){if(v.tagName==="BODY")return r.body||null;if(v.tagName==="HEAD")return r.head||null}return null}function g(v){let O=i(v);return O||Le(v,f(v),s,N)}function m(v){if(!v)return null;let O=g(v);return O&&O.isConnected?O:null}function T(v){for(let O=0;O<N.length;O++){let P=N[O](v);P!=null&&P!==""&&s[O].set(P,v)}}for(let v of p){if(v.type!=="deletion")continue;let O=g(v.el);O&&O!==A&&O.remove()}let R=p.filter(v=>v.type!=="deletion").sort((v,O)=>v.el===O.el?0:v.el.compareDocumentPosition(O.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let v of R){if(v.type==="head"){let z=r.importNode(v.el,!0);r.head?r.head.replaceWith(z):A.insertBefore(z,A.firstChild),w.push({entry:v,imported:z});continue}if(v.type==="attrs"){let z=m(v.el)||m(v.base);if(!z){a++;continue}for(let C of v.names)v.el.hasAttribute(C)?z.setAttribute(C,v.el.getAttribute(C)):z.removeAttribute(C);continue}let O=v.el;if(i(O))return c(v);let P=m(O)||m(v.base);if(P){let z=r.importNode(O,!0);P.replaceWith(z),T(z),w.push({entry:v,imported:z});continue}if(v.base!=null&&!ue(v.base,f(v.base),N)||!ue(O,f(O),N))return c(v);let B=O.parentElement;if(!B)return c(v);let F=m(B);if(!F)return c(v);let Y=null;for(let z=O.previousElementSibling;z;z=z.previousElementSibling){let C=m(z);if(C&&C.parentNode===F){Y=C;break}}let Z=r.importNode(O,!0);if(Y)F.insertBefore(Z,Y.nextSibling);else{let z=Array.prototype.indexOf.call(B.children,O);F.insertBefore(Z,F.children[z]||null)}T(Z),w.push({entry:v,imported:Z})}return{ok:!0,placed:w,held:null,skippedAttrs:a}}return{morph:U,defaults:E,findChangedRoots:et,spliceProtected:tt,mergeJson:Se,mergeScriptText:ve,parseJsonRelaxed:ge,parseRulesRelaxed:Ee}})();var xt=fe.morph,Ct=fe.defaults,Lt=fe.findChangedRoots,Rt=fe.spliceProtected;var Bt=fe;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:()=>vo,createParseCache:()=>zn,default:()=>yr,diff:()=>wn,findChangedRoots:()=>os,importMap:()=>qn,merge3:()=>as,merge3Text:()=>yn,mergeDocument:()=>vn,mergeJson:()=>yo,mergeScriptText:()=>Zn,morph:()=>eo,morphDocument:()=>fs,morphElement:()=>to,parseJsonRelaxed:()=>Xn,parseRulesRelaxed:()=>zo,spliceProtected:()=>ss,tieredIdentity:()=>so});function Kn(e,s){if(typeof e=="string"){let o=s&&s.defaultView,n=o&&o.DOMParser||globalThis.DOMParser;return new n().parseFromString(e,"text/html")}if(e&&e.nodeType===9)return e;throw new TypeError("expected an HTML string or a Document")}function zn(e){let s=new Map;return(o,n)=>{if(typeof n!="string")return Kn(n,e);let r=s.get(o);if(r&&r.text===n)return r.doc;let l=Kn(n,e);return s.set(o,{text:n,doc:l}),l}}function So(e,s){let o=s.doctype;if(!o)return!1;let n=e.doctype;if(n&&n.name===o.name&&n.publicId===o.publicId&&n.systemId===o.systemId)return!1;let r=e.implementation.createDocumentType(o.name,o.publicId,o.systemId);return n?e.replaceChild(r,n):e.insertBefore(r,e.documentElement),!0}function oo(e,s=[]){if(typeof e!="function")return()=>!1;let o=new WeakMap,n=new Set(s);return r=>{if(!r||r.nodeType!==1)return!1;let l=o.get(r);if(l!==void 0)return l;let c=[],f=r,d=!1;for(;f&&f.nodeType===1;){let M=o.get(f);if(M!==void 0){d=M;break}if(c.push(f),e(f,n.has(f))){d=!0;break}if(n.has(f))break;f=f.parentElement}for(let M of c)o.set(M,d);return d}}function vo(e){let s=new WeakMap,o=0,n=f=>s.get(f)||null,r=f=>{let d=s.get(f);return d||(d=`${e}:${++o}`,s.set(f,d)),d};return{idOf:n,ensure:r,adopt:(f,d)=>{f&&typeof d=="string"&&d&&s.set(f,d)},exportMap:(f,d)=>{let M={},N=[],y=[],T=(u,b)=>{let x=d(u);x&&(M[b]=r(x));let P=u.children;N.push(P.length),y.push(u.tagName.toLowerCase());for(let v=0;v<P.length;v++)T(P[v],b===""?String(v):`${b}.${v}`)};return T(f,""),M["~"]=N.join(","),M["^"]=y.join(","),M}}}function qn(e,s){let o=new WeakMap;if(!e||!s||typeof s!="object"||Array.isArray(s))return o;let n=s["~"],r=typeof n=="string"?n.split(",").map(Number):null,l=r&&typeof s["^"]=="string"?s["^"].split(","):null,c=y=>Number.isInteger(y)&&y>=0,f=0,d=!1,M=y=>{let T=y;for(;T>0;){let u=r[f++];if(f>r.length||!c(u))return!1;T+=u-1}return!0},N=(y,T)=>{if(d)return;if(r){let x=f++,P=r[x];if(x>=r.length||!c(P)){d=!0;return}let v=!l||l[x]===y.tagName.toLowerCase();if(!v||P!==y.children.length){let j=v&&s[T];typeof j=="string"&&j&&o.set(y,j),M(P)||(d=!0);return}}let u=s[T];typeof u=="string"&&u&&o.set(y,u);let b=y.children;for(let x=0;x<b.length;x++)N(b[x],T===""?String(x):`${T}.${x}`)};return N(e,""),o}function so(e){return s=>{for(let o of e){let n=o(s);if(typeof n=="string"&&n!=="")return n}return null}}var un=so([e=>e.getAttribute("data-id"),e=>e.getAttribute("id")]);function Gn(e,s,o,n=null){let r=new Map,l=new Set,c=f=>{if(o(f))return;let d=s(f);d&&(r.has(d)?l.add(d):r.set(d,f))};if(n){let f=d=>{for(let M of d.querySelectorAll(n))c(M);for(let M of d.querySelectorAll("template"))M.content&&f(M.content)};c(e),f(e.tagName==="TEMPLATE"&&e.content?e.content:e)}else{let f=d=>{c(d);let M=d.tagName==="TEMPLATE"&&d.content?d.content.children:d.children;for(let N=0;N<M.length;N++)f(M[N])};f(e)}for(let f of l)r.delete(f),f.startsWith("merge:")&&console.warn(`[hyper-morph] merge disabled for duplicate identity "${f.slice(f.indexOf(":",6)+1)}"`);return r}var ws=new Set(["href","src","name","type","role"]),Io=new Set(["SCRIPT","STYLE","TEXTAREA","TEMPLATE","IFRAME","OBJECT","CANVAS","VIDEO","AUDIO","svg","SVG"]);function gn(e,s=5381){let o=s;for(let n=0;n<e.length;n++)o=(o<<5)+o^e.charCodeAt(n);return o>>>0}function Mo(e){return e.replace(/\s+/g," ")}function Oo({ignored:e=()=>!1,ignoreAttribute:s=()=>!1}={}){let o=new WeakMap,n=new WeakMap;function r(T){let u=T.attributes,b=u.length;if(b===0)return{all:"",sig:T.tagName+"|"};let x=[],P="",v=[];for(let j=0;j<b;j++){let Y=u[j],le=Y.name;s(T,le)||x.push(le+"="+Y.value),le==="class"?P=Y.value.indexOf(" ")<0?Y.value:Y.value.split(/\s+/).filter(Boolean).sort().join(" "):ws.has(le)&&v.push(le+"="+Y.value)}return x.length>1&&x.sort(),v.length>1&&v.sort(),{all:x.join(""),sig:T.tagName+"|"+P+(v.length?"|"+v.join("|"):"")}}function l(T){return T.nodeType===1&&T.tagName==="TEMPLATE"&&T.content?T.content.childNodes:T.childNodes}function c(T){let u=o.get(T);if(u)return u;if(T.nodeType===3)u={hash:"T"+gn(T.nodeValue),hint:Mo(T.nodeValue).slice(0,64),sig:null,tok:null};else if(T.nodeType===8)u={hash:"C"+gn(T.nodeValue),hint:"",sig:null,tok:null};else if(T.nodeType===1){let b=r(T),x=gn(T.tagName+""+b.all),P="";for(let v of d(T))if(v.nodeType===1){let j=c(v);x=gn(j.hash,x),P.length<64&&(P+=" "+j.hint)}else x=gn(M(v),x),v.kind==="text"&&P.length<64&&(P+=v.value.slice(0,64));u={hash:"E"+x,hint:Mo(P).trim().slice(0,64),sig:b.sig,tok:null}}else u={hash:"N"+T.nodeType,hint:"",sig:null,tok:null};return o.set(T,u),u}function f(T){if(!T.tok){T.tok=new Set;for(let u of T.hint.toLowerCase().split(/[^\p{L}\p{N}]+/u))u&&T.tok.add(u)}return T.tok}function d(T){let u=n.get(T);if(u)return u;u=[];let b=null,x=()=>{b&&(b.value=b.nodes.map(P=>P.nodeValue).join(""),u.push(b),b=null)};for(let P of l(T)){if(P.nodeType===3){b||(b={kind:"text",nodes:[],value:"",parent:T,hash:void 0}),b.nodes.push(P);continue}x(),P.nodeType===8?u.push({kind:"comment",nodes:[P],value:P.nodeValue,parent:T,hash:void 0}):P.nodeType===1&&!e(P)&&u.push(P)}return x(),n.set(T,u),u}function M(T){return T.nodeType===1?c(T).hash:(T.hash===void 0&&(T.hash=(T.kind==="text"?"T":"C")+gn(T.value)),T.hash)}function N(T,u){let b=f(c(T)),x=f(c(u));if(b.size===0&&x.size===0)return{coef:1,share:1};if(b.size===0||x.size===0)return null;let P=0;for(let v of b)x.has(v)&&P++;return{coef:P/Math.min(b.size,x.size),share:P/Math.max(b.size,x.size)}}function y(T,u){let b=N(T,u);return!!b&&b.coef>=.5}return{meta:c,unitsOf:d,unitHash:M,similar:y,score:N,childrenOf:l}}var Lo=16,As=2e3,Ts=3,xs={align:0};function ro(e,s,o){let{meta:n,unitsOf:r,unitHash:l,similar:c,score:f}=o.analyzer,d=o.baseId||(()=>null),M=o.sideId||(()=>null),N=new Map,y=new Map,T=new Set,u=new Map,b=new Set,x=new Set,P=new Set,v=[],j=[],Y=[],le=[],Ne=As,ye=new Map,De=new Map,F=(i,k)=>{N.set(i,k),y.set(k,i)},H=i=>!!i&&i.nodeType===1,Q=(i,k)=>{let g=u.get(i);return!!g&&g.has(k)},ie=i=>Io.has(i.tagName),me=(i,k)=>{let g=d(i);if(!g)return!0;let _=M(k);return!_||g===_},Ie=globalThis.__hyperMorphProfile,ot=Ie?performance.now():0;Ie&&(n(e),n(s),Ie.meta=(Ie.meta||0)+(performance.now()-ot),ot=performance.now()),F(e,s);for(let[i,k]of o.baseIndex){let g=o.sideIndex.get(i);g&&g.tagName===k.tagName&&!N.has(k)&&!y.has(g)&&F(k,g)}le.push([e,s]);for(let[i,k]of N)H(i)&&i!==e&&le.push([i,k]);return at(),bt(),Ie&&(Ie.align=(Ie.align||0)+(performance.now()-ot)),{map:N,reverse:y,moved:b,identical:x,pairIdenticalChildren:E,weak:T,unpair:kt,rematch:bt,insertedByHash:Se};function bt(){ft(),at();for(let i=0;i<Y.length;){let k=Y.length;Ke(i,k),i=k,at(),ft(),at()}}function kt(i){let k=N.get(i);if(!k)return;u.has(i)||u.set(i,new Set),u.get(i).add(k);let g=(I,O)=>{N.delete(I),y.delete(O),b.delete(I),x.delete(I),T.delete(I),P.delete(I)},_=(I,O)=>{for(let U of r(I)){let S=N.get(U);!S||!(H(S)?O.contains(S):O.contains(S.nodes[0]))||(g(U,S),H(U)&&_(U,S))}};g(i,k),H(i)&&_(i,k),v.push(i),j.push(k)}function Se(){let i=new Map;for(let k of new Set(j)){if(y.has(k))continue;let g=n(k).hash;i.has(g)||i.set(g,[]),i.get(g).push(k)}return i}function at(){for(;le.length;){let[i,k]=le.shift();P.has(i)||x.has(i)||xt(i,k)}}function Ge(i,k){if(!ie(i))for(let g of r(i))H(g)&&(k.push(g),Ge(g,k))}function xt(i,k){P.add(i);let g=r(i),_=r(k);xs.align+=g.length+_.length,ye=new Map,De=new Map;for(let B=0;B<g.length;B++)ye.set(g[B],B);for(let B=0;B<_.length;B++)De.set(_[B],B);if(i.tagName==="HTML")for(let B of["HEAD","BODY"]){let J=g.find(we=>H(we)&&we.tagName===B),ee=_.find(we=>H(we)&&we.tagName===B);J&&ee&&!N.has(J)&&!y.has(ee)&&F(J,ee)}for(let B=0;B<g.length&&B<_.length;B++){let J=g[B],ee=_[B];N.has(J)||y.has(ee)||(H(J)?H(ee)&&J.tagName===ee.tagName&&J.isEqualNode(ee)&&w(J,ee):!H(ee)&&J.kind===ee.kind&&J.value===ee.value&&w(J,ee))}nt(g,_);let I=g.filter(B=>!N.has(B)),O=_.filter(B=>!y.has(B));I.length&&O.length&&(it(I,O),oe(I,O),Z(I,O,g,_),Je(g,_));let U=!1,S=!1;for(let B of g){if(!N.has(B)){H(B)&&(v.push(B),Ge(B,v),U=!0);continue}H(B)&&!x.has(B)&&le.push([B,N.get(B)])}for(let B of _)!y.has(B)&&H(B)&&(j.push(B),Ge(B,j),S=!0);U&&S&&Y.push([i,k])}function Ke(i,k){for(let g=i;g<k;g++){let[_,I]=Y[g],O=r(_),U=r(I),S=new Map,B=new Map,J=null;for(let ee of O)H(ee)&&(N.has(ee)?J=ee:(S.has(J)||S.set(J,[]),S.get(J).push(ee)));J=null;for(let ee of U)H(ee)&&(y.has(ee)?J=y.get(ee):(B.has(J)||B.set(J,[]),B.get(J).push(ee)));for(let[ee,we]of S){let et=B.get(ee);if(!(!et||we.length!==et.length)&&we.every((yt,ut)=>et[ut].tagName===yt.tagName&&me(yt,et[ut])&&!Q(yt,et[ut])))for(let yt=0;yt<we.length;yt++)ze(we[yt],et[yt])}}}function ze(i,k){F(i,k),T.add(i),le.push([i,k]),at()}function it(i,k){let g=bn(i,l),_=bn(k,l),I=new Map;for(let O of k){let U=l(O);_.get(U)===1&&I.set(U,O)}for(let O of i){if(N.has(O))continue;let U=l(O);if(g.get(U)!==1)continue;let S=I.get(U);S&&!y.has(S)&&w(O,S)}}function w(i,k){F(i,k),x.add(i),H(i)&&P.add(i)}function E(i){let k=N.get(i);if(!k||!H(i))return;let g=r(i),_=r(k);for(let I=0;I<g.length&&I<_.length;I++)N.has(g[I])||w(g[I],_[I])}function oe(i,k){let g=U=>H(U)&&!ie(U)?n(U).sig+""+n(U).hint:null,_=bn(i,g),I=bn(k,g),O=new Map;for(let U of k){let S=g(U);S!=null&&I.get(S)===1&&O.set(S,U)}for(let U of i){if(N.has(U))continue;let S=g(U);if(S==null||_.get(S)!==1)continue;let B=O.get(S);B&&!y.has(B)&&me(U,B)&&F(U,B)}}function Z(i,k,g,_){let I=new Map;for(let U of k){if(!H(U)||y.has(U)||ie(U))continue;let S=n(U).sig;I.has(S)||I.set(S,[]),I.get(S).push({el:U,index:De.get(U)})}let O=[];for(let U of i){if(N.has(U)||!H(U)||ie(U))continue;let S=I.get(n(U).sig);if(!S||!S.length)continue;let B=ye.get(U),J=S.filter(ee=>!y.has(ee.el)).map(ee=>({c:ee,d:Math.abs(ee.index-B)}));J.sort((ee,we)=>ee.d-we.d),J.length>Lo&&(J=J.slice(0,Lo));for(let{c:ee,d:we}of J){if(!me(U,ee.el))continue;let et=f(U,ee.el);et&&et.coef>=.5&&O.push({b:U,s:ee.el,coef:et.coef,share:et.share,d:we,bi:B})}}O.sort((U,S)=>S.coef-U.coef||S.share-U.share||U.d-S.d||U.bi-S.bi);for(let U of O)!N.has(U.b)&&!y.has(U.s)&&F(U.b,U.s)}function Me(i,k){return H(i)!==H(k)?!1:H(i)?i.tagName!==k.tagName||!me(i,k)?!1:ie(i)||n(i).hint===""||n(k).hint===""?!0:c(i,k):i.kind===k.kind}function st(i,k){let g=(I,O)=>{let U=O===null?-1:I===k?De.get(O):ye.get(O),S=I[U+1];return S&&!H(S)?S:null},_=null;for(let I of i){if(H(I)){_=I;continue}if(N.has(I))continue;let O=_===null?null:N.get(_);if(_!==null&&!O)continue;let U=g(k,O);U&&!y.has(U)&&U.kind===I.kind&&F(I,U)}}function Je(i,k){st(i,k);let g=Xe(i,k),_=(O,U)=>H(O)&&n(O).hint!==""&&n(U).hint===""&&!!U.querySelector("br")&&!g(O,U),I=0;for(let O of i){if(N.has(O)){let S=De.get(N.get(O));S!==void 0&&S>=I&&(I=S+1);continue}let U=0;for(let S=I;S<k.length&&U<Ts;S++){let B=k[S];if(!y.has(B)&&(U++,Me(O,B)&&!Q(O,B)&&!_(O,B))){F(O,B),H(O)&&(n(O).hint===""||n(B).hint==="")&&T.add(O),I=S+1;break}}}nt(i,k)}function Xe(i,k){let g=(_,I,O)=>{for(let U=I-1;U>=0;U--)if(H(_[U])&&O(_[U]))return _[U];return null};return(_,I)=>{let O=ye.get(_),U=De.get(I);if(O===U)return!0;let S=g(i,O,J=>N.has(J)),B=g(k,U,J=>y.has(J));return S?N.get(S)===B:!B}}function nt(i,k){let g=i.filter(S=>H(S)&&!N.has(S)),_=k.filter(S=>H(S)&&!y.has(S));if(!g.length||!_.length)return;let I=bn(g,S=>S.tagName),O=bn(_,S=>S.tagName),U=Xe(i,k);for(let S of g){let B=S.tagName;if(I.get(B)!==1||O.get(B)!==1)continue;let J=_.find(ee=>ee.tagName===B);J&&!y.has(J)&&U(S,J)&&me(S,J)&&!Q(S,J)&&(F(S,J),T.add(S))}}function ft(){let i=new Map;for(let S of T)if(H(S)&&H(N.get(S))){let B=n(S).hash;i.has(B)||i.set(B,[]),i.get(B).push(S)}if(i.size)for(let S of j){if(y.has(S)||!H(S))continue;let B=i.get(n(S).hash),J=B&&B.find(ee=>T.has(ee)&&!Q(ee,S)&&me(ee,S));J&&(kt(J),w(J,S),b.add(J))}let k=new Map,g=new Map,_=new Map;for(let S of T){let B=N.get(S);H(S)&&H(B)&&_.set(B,S)}let I=(S,B)=>{if(!y.has(S))return!0;let J=_.get(S);return J===y.get(S)&&J!==B&&!J.contains(B)},O=S=>{if(y.has(S)){let B=_.get(S);_.delete(S),kt(B)}};for(let S of[...j,..._.keys()]){if(y.has(S)&&!_.has(S))continue;let B=n(S).hash;if(k.has(B)||k.set(B,[]),k.get(B).push(S),ie(S))continue;let J=n(S).sig;g.has(J)||g.set(J,[]),g.get(J).push(S)}let U=new Set;for(let S of T){let B=N.get(S);!H(S)||!H(B)||ie(S)||n(S).hint===""||n(B).hint===""||c(S,B)||U.add(S)}for(let S of[...v,...U]){let B=N.get(S);if(B&&!(T.has(S)&&U.has(S)))continue;let J=ut=>{B&&kt(S),O(ut)},ee=k.get(n(S).hash);if(ee){let ut=ee.find(fe=>fe!==B&&I(fe,S)&&!Q(S,fe));if(ut){J(ut),w(S,ut),b.add(S);continue}}if(ie(S)||Ne<=0)continue;let we=g.get(n(S).sig);if(!we)continue;let et=null,yt=0;for(let ut of we)if(!(ut===B||!I(ut,S)||!me(S,ut)||Q(S,ut))&&(Ne--<=0||c(S,ut)&&(yt++,et=ut,yt>1)))break;yt===1&&(J(et),F(S,et),b.add(S),le.push([S,et]))}}}function bn(e,s){let o=new Map;for(let n of e){let r=s(n);r!=null&&o.set(r,(o.get(r)||0)+1)}return o}var Ns={diff:0},Co=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null,Ss=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u,vs=/[\p{L}\p{M}\p{N}_'’]+|\s+|[\s\S]/gu,Ms=/\P{M}\p{M}*/gu;function fo(e){if(e==="")return[];if(Co){let o=[];for(let n of Co.segment(e))o.push(n.segment);return o}let s=[];for(let o of e.match(vs))if(Ss.test(o))for(let n of o.match(Ms))s.push(n);else s.push(o);return s}var Is=/^[ ]+$/,Os=e=>Is.test(e)?" ".repeat(e.length):e,Rn=e=>typeof e.k=="string"&&/^\s+$/.test(e.k),rt="",Eo=e=>e.every(s=>Rn(s)||s.k===rt),Ls=/^[\x00-\x7f\u00A0]*$/,Cs=/[A-Za-z0-9_']+|[ \u00A0]+|\s|./g;function Es(e){return e===""?[]:e.match(Cs)}function dn(e,s=!1){return(s?Es(e):fo(e)).map(o=>({k:Os(o),raw:o,len:o.length}))}var $n=(...e)=>e.every(s=>Ls.test(s));function io(e,s,o){let n=e.length,r=s.length,l=Math.min(n+r,o),c=l+1,f=new Int32Array(2*l+3),d=[],M=n===0&&r===0;for(let u=0;u<=l&&!M;u++){d.push(f.slice(c-u,c+u+1));for(let b=-u;b<=u;b+=2){let x;b===-u||b!==u&&f[c+b-1]<f[c+b+1]?x=f[c+b+1]:x=f[c+b-1]+1;let P=x-b,v=x;for(;x<n&&P<r&&e[x].k===s[P].k;)x++,P++;if(Ns.diff+=1+x-v,f[c+b]=x,x>=n&&P>=r){M=!0;break}}}if(!M)return null;let N=[],y=n,T=r;for(let u=d.length-1;u>0;u--){let b=d[u],x=y-T,P=x+u,v=x===-u||x!==u&&b[P-1]<b[P+1]?x+1:x-1,j=b[v+u],Y=j-v;for(;y>j&&T>Y;)N.push([0,y-1,T-1]),y--,T--;y===j?(N.push([1,y,T-1]),T--):(N.push([-1,y-1,T]),y--)}for(;y>0&&T>0;)N.push([0,y-1,T-1]),y--,T--;return N.reverse(),N}function Rs(e,s,o){let n=y=>y.k===rt;if(!e.some(n)&&!s.some(n))return io(e,s,o);let r=[],l=[];for(let y=0;y<e.length;y++)n(e[y])||r.push(y);for(let y=0;y<s.length;y++)n(s[y])||l.push(y);let c=io(r.map(y=>e[y]),l.map(y=>s[y]),o);if(!c)return null;let f=[],d=0,M=0,N=(y,T)=>{for(;d<y&&M<T&&e[d].k===s[M].k;)f.push([0,d++,M++]);let u=io(e.slice(d,y),s.slice(M,T),o);if(!u)return!1;for(let[b,x,P]of u)f.push([b,x+d,P+M]);return d=y,M=T,!0};for(let[y,T,u]of c)if(y===0){if(!N(r[T],l[u]))return null;f.push([0,d,M]),d++,M++}return N(e.length,s.length)?f:null}function kn(e,s,o=4e3){let n=[],r=0;for(;r<e.length&&r<s.length&&e[r].k===s[r].k;)e[r].raw!==s[r].raw&&n.push({bi:r,tok:s[r]}),r++;let l=0;for(;l<e.length-r&&l<s.length-r&&e[e.length-1-l].k===s[s.length-1-l].k;)e[e.length-1-l].raw!==s[s.length-1-l].raw&&n.push({bi:e.length-1-l,tok:s[s.length-1-l]}),l++;let c=e.slice(r,e.length-l),f=s.slice(r,s.length-l),d=js(c,f)?null:Rs(c,f,o);if(!d){let v=c.length||f.length?[{bs:r,be:r+c.length,toks:f}]:[];return{hunks:v,cosmetic:n,coarse:!0,parts:v.map(j=>({...j,gap:[],group:0})),cosmeticEq:n}}let M=[],N=(v,j)=>{c[v].raw!==f[j].raw&&n.push({bi:r+v,tok:f[j]})},y=null,T=[],u=0,b=0,x=()=>{y&&M.push(y),y=null;for(let[v,j]of T)N(v,j);T=[],u++};for(let[v,j,Y]of d){if(v===0){y&&Rn(c[j])&&!c[j].k.includes(`
|
|
2
|
+
`)?T.push([j,Y]):(x(),N(j,Y)),b=j+1;continue}(!y||T.length)&&(y&&M.push(y),y={bs:r+b,be:r+b,toks:[],gap:T.map(([le,Ne])=>({bi:r+le,tok:f[Ne]})),group:u},T=[]),v===-1?(y.be=r+b+1,b=j+1):y.toks.push(f[Y])}x(),Hs(M,e);let P=lo(M);return{hunks:P.hunks,cosmetic:n.concat(P.cosmetic),parts:M,cosmeticEq:n}}function Hs(e,s){for(let o=0;o<e.length;o++){let n=e[o];if(n.gap.length)continue;let r=o+1<e.length?e[o+1].bs:1/0;if(n.toks.length){if(n.bs===n.be)for(;n.bs+1<r&&n.bs<s.length&&n.toks[0].k===rt&&s[n.bs].k===rt;)n.toks=[...n.toks.slice(1),n.toks[0]],n.bs++,n.be++}else for(;n.be+1<r&&n.be<s.length&&s[n.bs].k===rt&&s[n.be].k===rt;)n.bs++,n.be++}}function lo(e,s=()=>!1){let o=[],n=[],r=null,l=-1;for(let c of e){let f=s(c);if(r&&!r.alone&&!f&&c.group===l){r.be=c.be;for(let d of c.gap)r.toks.push(d.tok);for(let d of c.toks)r.toks.push(d);continue}r&&o.push({bs:r.bs,be:r.be,toks:r.toks});for(let d of c.gap)n.push(d);r={bs:c.bs,be:c.be,toks:c.toks.slice(),alone:f},l=c.group}return r&&o.push({bs:r.bs,be:r.be,toks:r.toks}),{hunks:o,cosmetic:n}}var Bs=(e,s)=>e.bs===s.bs&&e.be===s.be&&ho(e.toks,s.toks);function uo(e,s,o){let n=N=>y=>N.some(T=>Bs(y,T)),r=lo(e.parts,n(s.parts)),l=lo(s.parts,n(e.parts)),c=e.cosmeticEq.concat(r.cosmetic),f=s.cosmeticEq.concat(l.cosmetic),[d,M]=o?Ds(r.hunks,l.hunks,o,c,f):[r.hunks,l.hunks];return{lh:d,rh:M,cosL:c,cosR:f}}function Ds(e,s,o,n,r){let l=(u,b)=>u.k===b.k&&u.raw===b.raw,c=[{list:e.map(u=>({...u})),resp:new Set(n.map(u=>u.bi))},{list:s.map(u=>({...u})),resp:new Set(r.map(u=>u.bi))}],f=u=>u.bs===u.be,d=(u,b,x,P)=>{let v=u.list[b];if(!f(v))return P(v)===x?v.toks:null;let j=b?u.list[b-1].be:0,Y=b+1<u.list.length?u.list[b+1].bs:o.length;if(x<j||x>Y)return null;let le=v.toks,Ne=v.bs;for(;Ne>x;){let ye=le[le.length-1];if(!l(ye,o[Ne-1])||u.resp.has(Ne-1))return null;le=[ye,...le.slice(0,-1)],Ne--}for(;Ne<x;){if(!l(le[0],o[Ne])||u.resp.has(Ne))return null;le=[...le.slice(1),le[0]],Ne++}return le},M=(u,b,x,P,v,j)=>{let Y=u.list[b],le=v?x.slice(x.length-P):x.slice(0,P),Ne=v?x.slice(0,x.length-P):x.slice(P),ye={bs:j,be:j,toks:le};if(f(Y)){if(!Ne.length){u.list[b]=ye;return}let F={bs:j,be:j,toks:Ne};v&&(F.lead=!0),u.list.splice(b,1,...v?[F,ye]:[ye,F]);return}let De={bs:Y.bs,be:Y.be,toks:Ne};u.list.splice(b,1,...v?[De,ye]:[ye,De])},N=(u,b,x,P,v)=>{let j=u.list[b],Y=v?x.slice(x.length-P):x.slice(0,P),le=v?x.slice(0,x.length-P):x.slice(P),Ne={bs:j.bs,be:j.be,toks:Y};if(!le.length){u.list[b]=Ne;return}let ye=v?{bs:j.bs,be:j.bs,toks:le,lead:!0}:{bs:j.be,be:j.be,toks:le};u.list.splice(b,1,...v?[ye,Ne]:[Ne,ye])},y=c[0],T=c[1];for(let u=0;u<64;u++){let b=!1;e:for(let x=0;x<y.list.length;x++)for(let P=0;P<T.list.length;P++){let v=y.list[x],j=T.list[P];if(!(v.bs===j.bs&&v.be===j.be&&ho(v.toks,j.toks)))for(let Y of[!0,!1]){let le=ye=>Y?ye.be:ye.bs,Ne=f(v)?[le(j),v.bs]:[le(v)];for(let ye of Ne){let De=d(y,x,ye,le),F=De&&d(T,P,ye,le);if(!F)continue;let H=(ot,bt)=>Y?ot[ot.length-1-bt]:ot[bt],Q=0;for(;Q<De.length&&Q<F.length&&H(De,Q).k===H(F,Q).k;)Q++;if(!Q)continue;let ie=Y?De.slice(0,De.length-Q):De.slice(Q),me=Y?F.slice(0,F.length-Q):F.slice(Q);if(!(Q<De.length&&Q<F.length&&!Eo(ie)&&!Eo(me)&&(f(v)&&f(j)||v.bs===j.bs&&v.be===j.be)||!(Y?De.slice(De.length-Q):De.slice(0,Q)).some(ot=>!Rn(ot)))){if(Q===De.length&&Q===F.length&&f(v)&&f(j)){if(v.bs===ye&&j.bs===ye)continue;y.list[x]={bs:ye,be:ye,toks:De},T.list[P]={bs:ye,be:ye,toks:F}}else!f(v)&&v.bs===j.bs&&v.be===j.be?(N(y,x,De,Q,Y),N(T,P,F,Q,Y)):(M(y,x,De,Q,Y,ye),M(T,P,F,Q,Y,ye));b=!0;break e}}}}if(!b)break}return[y.list,T.list]}var Ps=48,Us=.3;function js(e,s){let o=e.filter(c=>!Rn(c)),n=s.filter(c=>!Rn(c));if(Math.min(o.length,n.length)<Ps)return!1;let r=new Map;for(let c of o)r.set(c.k,(r.get(c.k)||0)+1);let l=0;for(let c of n){let f=r.get(c.k);f>0&&(l++,r.set(c.k,f-1))}return l/Math.min(o.length,n.length)<Us}var _s=(e,s)=>{let o=new Set;for(let n of e.toks)typeof n.k!="string"&&o.add(n.k.el);for(let n=e.bs;n<e.be;n++)typeof s[n].k!="string"&&o.add(s[n].k.el);return o},ho=(e,s)=>e.length===s.length&&e.every((o,n)=>o.k===s[n].k);function Ro(e,s,o,n="remote"){let r=kn(e,s),l=kn(e,o),{lh:c,rh:f,cosL:d,cosR:M}=uo(r,l,e),N=w=>w.bs===w.be,y=w=>w.toks.some(E=>typeof E.k=="string"),T=w=>N(w)&&!y(w),u=(w,E)=>E.bs<w.be&&w.bs<E.be,b=(w,E)=>!u(w,E)&&E.bs<=w.be&&w.bs<=E.be&&(N(w)&&y(w)||N(E)&&y(E))&&!(N(w)&&N(E)),x=(w,E)=>w.bs===E.bs&&w.be===E.be&&ho(w.toks,E.toks),P=[],v=new Set;for(let w of c){let E=f.find(oe=>!v.has(oe)&&x(w,oe));E?(v.add(E),P.push({bs:w.bs,be:w.be,side:"both",l:w,r:E,toks:w.toks})):P.push({bs:w.bs,be:w.be,side:"L",l:w,toks:w.toks,lead:!!w.lead})}for(let w of f)v.has(w)||P.push({bs:w.bs,be:w.be,side:"R",r:w,toks:w.toks,lead:!!w.lead});P.sort((w,E)=>w.bs-E.bs||w.be-E.be||E.lead-w.lead);let j=0,Y=0;for(let w of P)w.side==="both"&&(j+=w.toks.length-(w.be-w.bs));let le=P.map((w,E)=>E),Ne=w=>le[w]===w?w:le[w]=Ne(le[w]),ye=(w,E)=>(w=Ne(w),E=Ne(E),w===E?!1:(le[w]=E,!0)),De=P.map(w=>_s({bs:w.bs,be:w.be,toks:w.toks},e)),F={L:new Map,R:new Map};P.forEach((w,E)=>{let oe=w.side==="both"?["L","R"]:[w.side];for(let Z of oe)for(let Me of De[E])F[Z].has(Me)||F[Z].set(Me,[]),F[Z].get(Me).push(E)});for(let w of[F.L,F.R])for(let E of w.values())for(let oe=1;oe<E.length;oe++)ye(E[0],E[oe]);for(let w=0;w<P.length;w++)for(let E=w+1;E<P.length;E++){let oe=P[w],Z=P[E];oe.side===Z.side&&oe.side!=="both"||oe.bs>Z.be||(u(oe,Z)||b(oe,Z)?ye(w,E):oe.bs===Z.bs&&N(oe)&&N(Z)&&Y++)}let H=(w,E)=>{let oe=w==="L"?c:f;for(let Z of oe)if(Z.toks.some(Me=>Me.kind==="close"&&Me.k.el===E.el))return Z.bs;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="close"&&e[Z].k.el===E.el)return Z;return-1};P.forEach((w,E)=>{if(!(!T(w)||w.side==="both"))for(let oe of w.toks){if(oe.kind!=="open")continue;let Z=H(w.side,oe.k);if(Z<=w.bs)continue;let Me=new Uint8Array(Z-w.bs),st=[];if(P.forEach((Je,Xe)=>{if(!(Je.side===w.side||N(Je))&&Je.bs<Z&&Je.be>w.bs){st.push(Xe);for(let nt=Math.max(Je.bs,w.bs);nt<Math.min(Je.be,Z);nt++)Me[nt-w.bs]=1}}),st.length&&Me.every(Je=>Je===1))for(let Je of st)ye(E,Je)}});let Q=!0;for(;Q;){Q=!1;let w=new Map;P.forEach((E,oe)=>{let Z=Ne(oe),Me=w.get(Z)||{bs:E.bs,be:E.be,L:!1,R:!1};Me.bs=Math.min(Me.bs,E.bs),Me.be=Math.max(Me.be,E.be),E.side!=="R"&&(Me.L=!0),E.side!=="L"&&(Me.R=!0),w.set(Z,Me)}),P.forEach((E,oe)=>{for(let[Z,Me]of w){if(Ne(oe)===Ne(Z)||!(Me.L&&Me.R))continue;let st=E.bs<Me.be&&E.be>Me.bs,Je=N(E)&&y(E)&&(E.bs===Me.be||E.bs===Me.bs);(st||Je)&&ye(oe,Z)&&(Q=!0)}})}let ie=new Map;P.forEach((w,E)=>{let oe=Ne(E);ie.has(oe)||ie.set(oe,[]),ie.get(oe).push(w)});let me=[];for(let w of ie.values()){let E=w.some(Z=>Z.side==="L"),oe=w.some(Z=>Z.side==="R");if(E&&oe){let Z=Math.min(...w.map(Xe=>Xe.bs)),Me=Math.max(...w.map(Xe=>Xe.be)),st=w.filter(Xe=>Xe.side!=="R").map(Xe=>Xe.l).sort((Xe,nt)=>Xe.bs-nt.bs),Je=w.filter(Xe=>Xe.side!=="L").map(Xe=>Xe.r).sort((Xe,nt)=>Xe.bs-nt.bs);me.push({bs:Z,be:Me,kind:"conflict",localHunks:st,remoteHunks:Je})}else for(let Z of w)me.push({bs:Z.bs,be:Z.be,kind:Z.side,u:Z})}let Ie=(w,E)=>{let oe=w==="L"?c:f;for(let Z of oe)if(Z.toks.some(Me=>Me.kind==="close"&&Me.k.el===E.el))return Z.bs+.5;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="close"&&e[Z].k.el===E.el)return Z;return 1/0},ot=(w,E)=>{let oe=w==="L"?c:f;for(let Z of oe)if(Z.toks.some(Me=>Me.kind==="open"&&Me.k.el===E.el))return Z.bs-.5;for(let Z=0;Z<e.length;Z++)if(e[Z].kind==="open"&&e[Z].k.el===E.el)return Z;return-1/0},bt=w=>w.kind==="R"?"R":"L",kt=w=>w.kind==="R"?1:0;me.sort((w,E)=>{if(w.bs!==E.bs)return w.bs-E.bs;let oe=w.bs===w.be,Z=E.bs===E.be;if(oe!==Z)return oe?-1:1;if(oe&&Z&&w.kind!=="conflict"&&E.kind!=="conflict"){let st=w.u.toks,Je=E.u.toks,Xe=ft=>ft.length&&ft.every(i=>i.kind==="open"),nt=ft=>ft.length&&ft.every(i=>i.kind==="close");if(Xe(st)&&Xe(Je)){let ft=Math.max(...st.map(k=>Ie(bt(w),k.k))),i=Math.max(...Je.map(k=>Ie(bt(E),k.k)));if(ft!==i)return i-ft}if(nt(st)&&nt(Je)){let ft=Math.min(...st.map(k=>ot(bt(w),k.k))),i=Math.min(...Je.map(k=>ot(bt(E),k.k)));return ft!==i?i-ft:kt(E)-kt(w)}}let Me=st=>st.u&&st.u.lead?1:0;return Me(E)-Me(w)||kt(w)-kt(E)||w.be-E.be});let Se=[],at=[],Ge=0,xt=w=>{w>Ge&&(Se.push({bs:Ge,be:w,toks:e.slice(Ge,w),source:"base"}),Ge=w)};for(let w of me){if(xt(w.bs),w.kind==="conflict"){let E=ao(e,w.localHunks,w.bs,w.be),oe=ao(e,w.remoteHunks,w.bs,w.be),Z=n==="local"?E:n==="both"?E.concat(oe):oe;at.push({bs:w.bs,be:w.be,base:e.slice(w.bs,w.be),local:E,remote:oe,resolved:Z}),Se.push({bs:w.bs,be:w.be,toks:Z,source:"conflict",localHunks:w.localHunks,localToks:E,keepsLocal:n!=="remote"})}else Se.push({bs:w.bs,be:w.be,toks:w.u.toks,source:w.kind==="R"?"remote":"local",localHunks:w.kind==="R"?[]:[w.u.l]});Ge=Math.max(Ge,w.be)}xt(e.length);let Ke=new Map(d.map(w=>[w.bi,w.tok])),ze=new Map(M.map(w=>[w.bi,w.tok])),it=[];for(let w of Se){w.source==="base"&&(w.toks=w.toks.map((E,oe)=>{let Z=w.bs+oe,Me=Ke.get(Z),st=ze.get(Z),Je=Me&&st?n==="remote"?st:Me:Me||st||E;return Je===E?E:{...Je,cosmetic:!0}}));for(let E of w.toks)it.push({...E,src:w.source})}return{tokens:it,segments:Se,conflicts:at,localHunks:c,remoteHunks:f,collapsedDelta:j,samePoint:Y,mapLocalOffset:Vs(e,c,Se)}}function ao(e,s,o,n){let r=[],l=o;for(let c of s)r=r.concat(e.slice(l,c.bs),c.toks),l=c.be;return r.concat(e.slice(l,n))}var co=e=>e.reduce((s,o)=>s+o.len,0);function Vs(e,s,o){let n=new Int32Array(e.length+1);for(let c=0;c<e.length;c++)n[c+1]=n[c]+e[c].len;let r=s.map(c=>({bs:n[c.bs],be:n[c.be],text:c.toks.map(f=>f.raw).join(""),ref:c})),l=o.map(c=>({bs:n[c.bs],be:n[c.be],len:co(c.toks),source:c.source,localHunks:c.localHunks||[],localLen:c.localToks?co(c.localToks):0,keepsLocal:c.keepsLocal,ref:c}));return c=>{let f=null,d=null,M=0,N=0,y=0;for(let u of r){let b=u.bs-y;if(c<=N+b){f=y+(c-N);break}if(N+=b,y=u.bs,c<=N+u.text.length){d=u,M=c-N,f=u.bs;break}N+=u.text.length,y=u.be}f===null&&(f=y+(c-N));let T=0;for(let u of l){if(!d&&f<=u.bs)return T;if(!(d?u.localHunks.includes(d.ref):f<u.be)){T+=u.len;continue}if(u.source==="base")return T+(f-u.bs);if(u.source==="remote")return T+u.len;if(u.source==="local")return T+Math.min(M,u.len);if(!u.keepsLocal||!d)return T+u.len;let x=u.localHunks.indexOf(d.ref),P=co(ao(e,u.localHunks.slice(0,x),u.ref.bs,d.ref.bs));return T+Math.min(P+M,u.localLen)}return T}}function yn(e,s,o,n="remote"){if(s===o||o===e)return{text:s,conflicts:[],mapLocalOffset:u=>Math.min(u,s.length),granularity:"word"};let r=$n(e,s,o),l=dn(e,r),c=dn(s,r),f=dn(o,r),d=l.length<=2e4&&c.length<=2e4&&f.length<=2e4?Ro(l,c,f,n):null,M="word",N=l;if(!d){let u=b=>b.split(/(?<=\n)/).map(x=>({k:x,raw:x,len:x.length}));N=u(e),d=Ro(N,u(s),u(o),n),M="line"}let y=u=>u.map(b=>b.raw).join(""),T=[0];for(let u of N)T.push(T[T.length-1]+u.len);return{text:y(d.tokens),conflicts:d.conflicts.map(u=>({bs:T[u.bs],be:T[u.be],base:y(u.base),local:y(u.local),remote:y(u.remote),resolved:y(u.resolved)})),mapLocalOffset:d.mapLocalOffset,granularity:M}}function wn(e,s,o=4e3){if(e===s)return[];let n=$n(e,s),r=dn(e,n),l=dn(s,n),c=kn(r,l,o),f=[0];for(let d of r)f.push(f[f.length-1]+d.len);return c.hunks.map(d=>({bs:f[d.bs],be:f[d.be],text:d.toks.map(M=>M.raw).join("")}))}var Tn="\uFFFC";var Ws={caret:0},nn=new Set("A ABBR B BDI BDO CITE CODE DATA DEL DFN EM FONT I INS KBD MARK Q S SAMP SMALL SPAN STRIKE STRONG SUB SUP TIME TT U VAR".split(" ")),jo=new Set(["BR","WBR","IMG"]),Fs=new Set("ADDRESS ARTICLE ASIDE AUDIO BLOCKQUOTE BODY CANVAS CAPTION CENTER COL COLGROUP DD DETAILS DIALOG DIR DIV DL DT FIELDSET FIGCAPTION FIGURE FOOTER FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HEADER HGROUP HR HTML IFRAME LEGEND LI MAIN MATH MENU NAV NOSCRIPT OBJECT OL OPTGROUP OPTION P PRE SCRIPT SECTION SELECT STYLE SUMMARY SVG TABLE TBODY TD TEMPLATE TEXTAREA TFOOT TH THEAD TITLE TR UL VIDEO".split(" "));function hn(e,s={}){if(e.nodeType===3)return!0;if(e.nodeType!==1)return!1;if(s.ignored&&s.ignored(e)||jo.has(e.tagName))return!0;if(!nn.has(e.tagName))return!Fs.has(e.tagName);if(s.remoteWins&&s.remoteWins(e))return!1;let o=s.inlineCache&&s.inlineCache.get(e);if(o!==void 0)return o;let n=!0;for(let r of e.childNodes)if(!hn(r,s)){n=!1;break}return s.inlineCache&&s.inlineCache.set(e,n),n}function Ks(e){return!e.firstChild||e.textContent===""&&!e.querySelector("br,img,wbr")}function Hn(e,s={}){let o={text:"",marks:[],atoms:[],nodes:[],stackAt:[],pins:[],placeholder:null},n=(r,l)=>{for(let c of r){if(c.nodeType===3){let N=c.nodeValue;if(!N)continue;o.nodes.push({node:c,s:o.text.length,e:o.text.length+N.length}),o.text+=N;for(let y=0;y<N.length;y++)o.stackAt.push(l);continue}if(c.nodeType!==1)continue;if(s.ignored&&s.ignored(c)){o.pins.push({el:c,i:o.text.length});continue}if(s.skip&&s.skip.has(c))continue;let f=c.tagName;if(s.blocks&&s.blocks.has(c)){o.text.length&&o.text[o.text.length-1]!==rt&&(o.stackAt.push(l),o.text+=rt);let N={el:c,tag:f,from:o.text.length,to:-1,depth:l.length,block:!0};o.marks.push(N);let y=l.concat([N]);n(c.childNodes,y),o.stackAt.push(y),o.text+=rt,N.to=o.text.length;continue}let d=nn.has(f)&&Ks(c);if(jo.has(f)||!nn.has(f)||s.remoteWins&&s.remoteWins(c)||s.atomize&&s.atomize(c)||d){o.atoms.push({i:o.text.length,el:c,key:d?f+":empty":f,stack:l}),o.stackAt.push(l),o.text+=Tn;continue}let M={el:c,tag:f,from:o.text.length,to:-1,depth:l.length};o.marks.push(M),n(c.childNodes,l.concat([M])),M.to=o.text.length}};if(n(e,[]),o.atoms.length===1&&o.atoms[0].el.tagName==="BR"&&o.marks.length===0&&Yn(o).trim()===""){let r=o.atoms[0];o.placeholder=r.el,o.text=o.text.slice(0,r.i)+o.text.slice(r.i+1),o.stackAt.splice(r.i,1);for(let l of o.nodes)l.s>r.i&&(l.s--,l.e--);o.atoms=[]}return o.atomAt=new Map(o.atoms.map(r=>[r.i,r])),o}function zs(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")}function qs(e){let s="<"+e.tagName.toLowerCase();for(let o of e.attributes)s+=` ${o.name}="${o.value.replace(/"/g,""")}"`;return s+">"}function mo(e,s,o){let n="",r=[];for(let l=s;l<o;l++){let c=e.stackAt[l],f=0;for(;f<r.length&&f<c.length&&r[f]===c[f];)f++;for(;r.length>f;)n+=`</${r.pop().tag.toLowerCase()}>`;for(;r.length<c.length;){let M=c[r.length];n+=qs(M.el),r.push(M)}let d=e.atomAt.get(l);n+=d?d.el.outerHTML:e.text[l]===rt?"":zs(e.text[l])}for(;r.length;)n+=`</${r.pop().tag.toLowerCase()}>`;return n}function Gs(e,s){let o=[...e.el.attributes].filter(n=>!s(e.el,n.name)).map(n=>n.name+"="+n.value).sort().join("");return e.tag+"|"+o}function _o(e,s){let o=[...e.attributes].filter(n=>!s(e,n.name)).map(n=>n.name+"="+n.value).sort().join("");return e.tagName+"|"+o+"|"+e.innerHTML}function Ho(e,s=()=>!1){let o=new Map,n=l=>{let c=o.get(l);return c===void 0&&(c="{"+l.map(f=>Gs(f,s)).sort().join(",")+"}",o.set(l,c)),c},r="";for(let l=0;l<e.text.length;l++){let c=e.atomAt.get(l);r+=(c?"["+_o(c.el,s)+"]":e.text[l])+n(e.stackAt[l])}return e.text.length===0&&e.placeholder&&(r+="[br]"),r}function An(e,s,o,n=r=>r.key){let r=[],l=e.text,c=0,f=d=>{if(d<=c)return;let M=l.slice(c,d);if(o)for(let N of M.split(/(?<=\n)/))r.push({k:N,raw:N,len:N.length});else for(let N of dn(M,s))r.push(N)};for(let d of e.atoms)f(d.i),r.push({k:"\0"+n(d),raw:Tn,len:1,atom:!0}),c=d.i+1;return f(l.length),r}function Yn(e){if(!e.atoms.length)return e.text;let s="",o=0;for(let n of e.atoms)s+=e.text.slice(o,n.i),o=n.i+1;return s+e.text.slice(o)}var go=e=>{let s=new Int32Array(e.length+1);for(let o=0;o<e.length;o++)s[o+1]=s[o]+e[o].len;return s};function Bo(e,s,o,n){let r=go(s),l=go(o),c=[],f=0,d=0;for(let N of n.hunks){d+=N.bs-f;let y=d+N.toks.length;c.push({bs:r[N.bs],be:r[N.be],ss:l[d],se:l[y],text:e.text.slice(l[d],l[y]),toks:N.toks,lead:!!N.lead}),d=y,f=N.be}let M=new Map;for(let N of n.cosmetic)M.set(N.bi,N.tok.raw);return{hunks:c,respell:M}}function Do(e,s,o){let n=c=>c===rt||/\s/.test(c),r=c=>c.replace(/[\u001E\s]/g,""),l=[];for(let c of e){let f=s.slice(c.bs,c.be),d=o.slice(c.ss,c.se);if(!f.includes(rt)&&!d.includes(rt)||f.includes(Tn)||d.includes(Tn)||r(f)!==r(d)){l.push(c);continue}let M=0,N=0;for(;;){let y=M,T=N;for(;y<f.length&&n(f[y]);)y++;for(;T<d.length&&n(d[T]);)T++;let u=M,b=N;for(;u<y&&b<T&&f[u]===d[b];)u++,b++;let x=y,P=T;for(;x>u&&P>b&&f[x-1]===d[P-1];)x--,P--;if(x>u||P>b){let v=d.slice(b,P);l.push({bs:c.bs+u,be:c.bs+x,ss:c.ss+b,se:c.ss+P,text:v,toks:[...v].map(j=>({k:j,raw:j,len:1})),lead:c.lead})}if(y>=f.length)break;M=y+1,N=T+1}}return l}function Po(e,s,o){let n=new Int32Array(s+1).fill(-1),r=new Int32Array(o+1).fill(-1),l=0,c=0,f=d=>{for(;l<d;)n[l]=c,r[c]=l,l++,c++};for(let d of e)f(d.bs),l=d.be,c=d.se;return f(s),n[s]=c,r[c]=s,{bTo:n,toB:r}}function Uo(e,s){if(e.size!==s.size)return!1;for(let o of e)if(!s.has(o))return!1;return!0}function bo(e){let{out:s,policy:o="remote",L:n,R:r}=e,l=e.provenance||new WeakMap,c=e.textMappers||new WeakMap,f=e.conflicts||[],d=e.decisions||[],M=f.length,N=!!(n&&n.reverse&&n.map&&r&&r.reverse&&r.map),y={base:null,local:null,remote:null};if(N&&e.moveIn){let t=X=>ke=>X.some($=>$===ke||$.nodeType===1&&$.contains(ke)),a=t(e.local),p=t(e.remote),h=t(e.base),A=new Set,C=X=>{if(!nn.has(X.tagName))return;let ke=n.map.get(X),$=r.map.get(X);(ke&&!a(ke)||$&&!p($))&&A.add(X);for(let re of X.children)C(re)};for(let X of e.base)X.nodeType===1&&C(X);let z=X=>ke=>{if(!nn.has(ke.tagName))return!1;let $=X.reverse.get(ke);return!!$&&(A.has($)||!h($))};A.size&&(y.base=X=>A.has(X)),y.local=z(n),y.remote=z(r)}let T={base:new Set,local:new Set,remote:new Set};if(N&&e.moveIn){let t=h=>A=>h.some(C=>C===A||C.nodeType===1&&C.contains(A)),a=t(e.local),p=t(e.remote);for(let h of Hn(e.base,{...e,atomize:y.base}).atoms){let A=n.map.get(h.el),C=r.map.get(h.el),z=!!A&&!a(A),X=!!C&&!p(C);!z&&!X||(T.base.add(h.el),A&&!z&&T.local.add(A),C&&!X&&T.remote.add(C),a(h.el)&&T.local.add(h.el),p(h.el)&&T.remote.add(h.el))}}let u=Hn(e.base,{...e,atomize:y.base,skip:T.base}),b=Hn(e.local,{...e,atomize:y.local,skip:T.local}),x=Hn(e.remote,{...e,atomize:y.remote,skip:T.remote}),P=new Map(u.atoms.map(t=>[t.el,t])),v=(t,a,p)=>{a.namespaceURI?t.setAttributeNS(a.namespaceURI,a.name,p):t.setAttribute(a.name,p)},j=(t,a,p,h)=>{if(!a&&(!p||!h)){for(let C of(p||h).attributes)v(t,C,C.value);return}let A=new Map;for(let C of[a,p,h])if(C)for(let z of C.attributes)A.set(z.name,z);for(let[C,z]of A){let X=a?a.getAttribute(C):null,ke=p?p.getAttribute(C):X,$=h?h.getAttribute(C):X,re;ke===$?re=ke:ke===X?(re=$,d.push({kind:"attr",el:t,name:C,source:"remote"})):$===X?(re=ke,d.push({kind:"attr",el:t,name:C,source:"local"})):(re=o==="local"?ke:$,f.push({kind:"attr",el:t,name:C,base:X,local:ke,remote:$,resolved:re}),d.push({kind:"attr",el:t,name:C,source:"both"})),re!=null&&v(t,z,re)}},Y=(t,a,p,h)=>t&&e.mergeAttrs?e.mergeAttrs(t,a,p,h):j(h,t,a,p),le=e.mergeElement||((t,a,p)=>{let h=s.createElement(t.tagName);Y(t,a,p,h);let A=a||t,C=p||t,z=o==="local"?A.isEqualNode(t)?C:A:C.isEqualNode(t)?A:C;for(let X of z.childNodes)h.appendChild(s.importNode(X,!0));return l.set(h,{base:t,local:a,remote:p}),h}),Ne=e.cloneUnit||((t,a)=>{let p=s.importNode(t,!0);return l.set(p,{base:null,local:a==="local"?t:null,remote:a==="remote"?t:null}),p}),ye=e.atomKey||(t=>_o(t,()=>!1)),De=(t,a)=>{let p=new Map;for(let h of t.atoms)if(e.remoteWins&&e.remoteWins(h.el)&&nn.has(h.el.tagName))p.set(h,"w"+h.el.tagName+"#"+(h.el.id||""));else if(!N)p.set(h,h.key);else if(t===u)p.set(h,"="+ye(h.el));else{let A=a.reverse.get(h.el),C=A?P.get(A):null;C?p.set(h,"="+ye(C.el)):A?p.set(h,"m"+ye(h.el)):p.set(h,"="+ye(h.el))}return h=>p.get(h)},F=De(u,null),H=De(b,n),Q=De(x,r),ie=$n(Yn(u),Yn(b),Yn(x)),me=An(u,ie,!1,F),Ie=An(b,ie,!1,H),ot=An(x,ie,!1,Q),bt=me.length>2e4||Ie.length>2e4||ot.length>2e4;bt&&(me=An(u,ie,!0,F),Ie=An(b,ie,!0,H),ot=An(x,ie,!0,Q));let kt=uo(kn(me,Ie),kn(me,ot),me),Se=Bo(b,me,Ie,{hunks:kt.lh,cosmetic:kt.cosL}),at=Bo(x,me,ot,{hunks:kt.rh,cosmetic:kt.cosR});Se.hunks=Do(Se.hunks,u.text,b.text),at.hunks=Do(at.hunks,u.text,x.text);let Ge=Po(Se.hunks,u.text.length,b.text.length),xt=Po(at.hunks,u.text.length,x.text.length),Ke=u.text.length,ze=t=>new Map(t.atoms.map(a=>[a.el,a])),it=ze(b),w=ze(x),E=(t,a,p)=>{let h=new Set;if(!N)return h;for(let A of t.atoms){let C=P.get(a.reverse.get(A.el));C&&p.bTo[C.i]<0&&h.add(C)}return h},oe=E(b,n,Ge),Z=E(x,r,xt),Me=t=>!hn(t,{...e,remoteWins:null}),st=new Set;if(N)for(let t of u.atoms){if(!Me(t.el))continue;let a=n.map.get(t.el)||null,p=r.map.get(t.el)||null,h=a&&!p?a:p&&!a?p:null;h&&(it.has(h)||w.has(h))&&!h.isEqualNode(t.el)&&st.add(t)}let Je=1,Xe=(t,a)=>({id:Je++,tag:t,base:null,local:null,remote:null,rank:a}),nt=new Map,ft=[];for(let t of u.marks){let a=Xe(t.tag,t.depth);a.block=!!t.block,a.base=t.el,a.baseMark=t,nt.set(t.el,a),ft.push(a)}let i=(t,a)=>{let p=-1,h=-1;for(let A=t.from;A<t.to;A++){let C=a[A];C>=0&&(p<0&&(p=C),h=C+1)}return p<0?null:[p,h]},k=(t,a,p,h)=>{for(let A of t.marks){let C=p?p.reverse.get(A.el):null;C&&p.identical.has(C)&&p.pairIdenticalChildren&&p.pairIdenticalChildren(C);let z=C?nt.get(C):null;if(z&&z[a]&&(z=null),!z){let X=i(A,h),ke=0;if(X)for(let $ of ft){if($.tag!==A.tag||$[a]||!!$.block!=!!A.block)continue;let re=Math.min(X[1],$.baseMark.to)-Math.max(X[0],$.baseMark.from);(re>ke||re===ke&&re>0&&Math.abs($.rank-A.depth)<Math.abs(z.rank-A.depth))&&(z=$,ke=re)}}z||(z=Xe(A.tag,A.depth),z.block=!!A.block,z.new=a),z[a]=A.el,z[a+"Mark"]=A,nt.set(A.el,z)}};k(b,"local",n,Ge.toB),k(x,"remote",r,xt.toB);let g=t=>t.merged||t,_=t=>{let a=new Set;for(let p of t)p.block||a.add(nt.get(p.el));return a},I=new Map,O=t=>{let a=I.get(t);return a||(a=_(t),I.set(t,a)),a},U=(t,a)=>{let p=[],h=null;for(let A=0;A<Ke;A++){let C=a[A];if(C<0){h&&p.push(h),h=null;continue}let z=O(u.stackAt[A]),X=O(t.stackAt[C]),ke=new Set,$=new Set;for(let re of X)z.has(re)||ke.add(re);for(let re of z)X.has(re)||$.add(re);if(!ke.size&&!$.size){h&&p.push(h),h=null;continue}if(h&&Uo(h.added,ke)&&Uo(h.removed,$)){h.be=A+1;continue}h&&p.push(h),h={bs:A,be:A+1,added:ke,removed:$}}return h&&p.push(h),p},S=U(b,Ge.bTo),B=U(x,xt.bTo),J=t=>t.be>t.bs?[t.bs,t.be-1]:[t.bs-1,t.bs],ee=(t,a)=>{if(Ke===0)return null;let[p,h]=J(t);for(let A of a){if(A.be<=p)continue;if(A.bs>h)break;let C=A.bs<=p&&h<A.be;return C&&t.text===""&&A.bs===t.bs&&A.be===t.be?"straddle":C?A:t.be>t.bs?"straddle":null}return null},we=t=>t.bs===t.be,et=(t,a)=>{let p=!1;for(let h=t.bs;h<t.be;h++){let A=u.text[h];if(A===rt)p=!0;else if(!/\s/.test(A))return!1}for(let h=t.ss;h<t.se;h++){let A=a.text[h];if(A===rt)p=!0;else if(!/\s/.test(A))return!1}return p},yt=(t,a)=>t.bs<a.be&&a.bs<t.be,ut=(t,a)=>t.bs<=a.be&&a.bs<=t.be&&we(t)!==we(a),fe=(t,a)=>u.text.slice(t.bs,t.be).includes(rt)||a.text.slice(t.ss,t.se).includes(rt),Qe=t=>{if(we(t))return!1;let a=t.bs,p=t.be;for(;a>0&&/\s/.test(u.text[a-1]);)a--;for(;p<u.text.length&&/\s/.test(u.text[p]);)p++;return(a===0||u.text[a-1]===rt)&&(p===u.text.length||u.text[p]===rt)},Et=(t,a)=>!fe(t,a)&&!Qe(t),wt=(t,a)=>yt(t,a)||ut(t,a)&&!(et(t,b)&&Et(a,x))&&!(et(a,x)&&Et(t,b)),Bt=(t,a)=>{if(t.bs!==a.bs||t.be!==a.be||t.toks.length!==a.toks.length)return!1;let p=t.ss,h=a.ss;for(let A=0;A<t.toks.length;A++){let C=t.toks[A],z=a.toks[A];if(C.k!==z.k||C.atom&&!b.atomAt.get(p).el.isEqualNode(x.atomAt.get(h).el))return!1;p+=C.len,h+=z.len}return!0},jt=(t,a,p,h)=>{for(let A of u.atoms){if(A.i<t.bs||A.i>=t.be||h.has(A)||st.has(A))continue;let C=a.bTo[A.i],z=C>=0?p.atomAt.get(C):null;if(z&&!z.el.isEqualNode(A.el))return!0}return!1},Nt=[],St=Se.hunks,m=at.hunks,L=0,R=0,W=0,D=0,V=0,G=t=>{t>W&&(Nt.push({src:"base",from:W,to:t,dL:D,dR:V}),W=t)};for(;L<St.length||R<m.length;){let t=St[L],a=m[R],p=!!t&&(!a||t.bs<a.bs||t.bs===a.bs&&t.be<=a.be&&!a.lead);if(t&&a&&t.bs===a.bs&&we(t)&&we(a)){let It=et(t,b),fn=et(a,x);It!==fn&&(p=fn)}let h=p?t:a,A=p?a:t,C=!!A&&Bt(t,a),z=!!A&&(p?!!St[L+1]&&Bt(St[L+1],a):!!m[R+1]&&Bt(t,m[R+1])),X=!!A&&!C&&!z&&(Ke===0||wt(t,a)),ke=X,$=ee(h,p?B:S);if($==="straddle"&&(ke=!0),!ke&&h.be>h.bs&&(ke=jt(h,p?xt:Ge,p?x:b,p?oe:Z)),!ke&&C){G(h.bs),Nt.push({src:"both",lfrom:t.ss,rfrom:a.ss,len:h.text.length}),W=h.be,D+=h.text.length-(h.be-h.bs),V+=h.text.length-(h.be-h.bs),L++,R++;continue}if(!ke){G(h.bs),Nt.push({src:p?"local":"remote",from:h.ss,to:h.se,inherit:$&&$!=="straddle"?$:null}),W=h.be,p?(D+=h.text.length-(h.be-h.bs),L++):(V+=h.text.length-(h.be-h.bs),R++);continue}let re=h.bs,_e=h.be,Ce=L,je=R,mt=It=>It.bs<_e&&It.be>re||we(It)&&(It.bs===re||It.bs===_e);p?Ce++:je++,X&&(re=Math.min(re,A.bs),_e=Math.max(_e,A.be),p?je++:Ce++);let lt=!0;for(;lt;){for(lt=!1;Ce<St.length&&mt(St[Ce]);)re=Math.min(re,St[Ce].bs),_e=Math.max(_e,St[Ce].be),Ce++,lt=!0;for(;je<m.length&&mt(m[je]);)re=Math.min(re,m[je].bs),_e=Math.max(_e,m[je].be),je++,lt=!0}let Wt=re+D,Ht=re+V,Jt=_e-re,Zt=_e-re;for(let It=L;It<Ce;It++)Jt+=St[It].text.length-(St[It].be-St[It].bs);for(let It=R;It<je;It++)Zt+=m[It].text.length-(m[It].be-m[It].bs);let sn=Wt+Jt,rn=Ht+Zt;G(re);let Mt={kind:"text",node:e.node||null,base:mo(u,re,_e),local:mo(b,Wt,sn),remote:mo(x,Ht,rn),resolved:null,range:null,bs:re,be:_e,lss:Wt,lse:sn,rss:Ht,rse:rn};Mt.resolved=o==="local"?Mt.local:o==="remote"?Mt.remote:Mt.local+Mt.remote,o!=="remote"&&Nt.push({src:"local",from:Wt,to:sn,conflict:Mt}),o!=="local"&&Nt.push({src:"remote",from:Ht,to:rn,conflict:Mt}),f.push(Mt),W=_e,D+=Jt-(_e-re),V+=Zt-(_e-re),L=Ce,R=je}G(Ke);let se=u.text,pe=[];if(Se.respell.size||at.respell.size){let t=go(me),a=[];for(let p=0;p<me.length;p++){let h=me[p].raw,A=Se.respell.get(p)??h,C=at.respell.get(p)??h;(A!==h||C!==h)&&pe.push([t[p],A!==h&&C!==h?"both":A!==h?"local":"remote"]),a.push(A===C?A:A===h?C:C===h||o==="local"?A:C)}se=a.join("")}let ue="",ge=[],Pe=[],He=[],At=[];for(let t of Nt){let a=ue.length;if(t.src==="base"){for(let p=t.from;p<t.to;p++)ge.push(p),Pe.push(p+t.dL),He.push(p+t.dR),At.push(t);ue+=se.slice(t.from,t.to)}else if(t.src==="both"){for(let p=0;p<t.len;p++)ge.push(-1),Pe.push(t.lfrom+p),He.push(t.rfrom+p),At.push(t);ue+=b.text.slice(t.lfrom,t.lfrom+t.len)}else{let p=t.src==="local"?b:x;for(let h=t.from;h<t.to;h++)ge.push(-1),Pe.push(t.src==="local"?h:-1),He.push(t.src==="remote"?h:-1),At.push(t);ue+=p.text.slice(t.from,t.to)}t.ms=a,t.me=ue.length,t.conflict&&(t.conflict.range||(t.conflict.range=[a,a]),t.conflict.range[1]=ue.length)}let de=ue.length,$e=new Int32Array(Ke+1).fill(-1),xe=new Int32Array(b.text.length+1).fill(-1),Lt=new Int32Array(x.text.length+1).fill(-1);for(let t=0;t<de;t++)ge[t]>=0&&($e[ge[t]]=t),Pe[t]>=0&&(xe[Pe[t]]=t),He[t]>=0&&(Lt[He[t]]=t);let Tt=(t,a)=>{let p=-1,h=-1;for(let A=t.from;A<t.to;A++){let C=a[A];C>=0&&(p<0&&(p=C),h=C+1)}return p<0?null:[p,h]},Ot=[],ht=[];for(let t of new Set(nt.values()))t.new==="local"?Ot.push(t):t.new==="remote"&&ht.push(t);let On=(t,a)=>{t.remote=a.remote,t.remoteMark=a.remoteMark,t.new="both",a.merged=t,nt.set(a.remote,t)};if(Ot.length&&ht.length){let t=e.idOf;for(let a of Ot){let p=t?t.local(a.local):null;if(!p)continue;let h=ht.find(A=>!A.merged&&A.tag===a.tag&&!!A.block==!!a.block&&t.remote(A.remote)===p);h&&On(a,h)}for(let a of Ot){if(a.remote)continue;let p=Tt(a.localMark,xe);if(p)for(let h of ht){if(h.merged||h.tag!==a.tag||!!h.block!=!!a.block)continue;let A=Tt(h.remoteMark,Lt);if(A&&Math.min(p[1],A[1])-Math.max(p[0],A[0])>0){On(a,h);break}}}}I.clear();let Ln=t=>{for(let a of t)if(a.block)return g(nt.get(a.el));return null},tn=u.marks.some(t=>t.block)||b.marks.some(t=>t.block)||x.marks.some(t=>t.block),Gt=new Array(de).fill(null),pn=new Set;if(tn){let t=($,re,_e)=>{let Ce=new Set([$,re,_e]);Ce.delete(null);let je=[];for(let lt of Ce){let Wt=lt===$,Ht=lt===re,Jt=lt===_e;(Ht===Jt?Ht:Ht===Wt?Jt:Ht)&&je.push(lt)}if(je.length<=1)return je[0]||null;let mt=o==="local"?re:_e;return je.includes(mt)?mt:je[0]},a=($,re)=>re>=0?Ln($.stackAt[re]):null,p=new Map;for(let $=0;$<de;$++){if(ue[$]!==rt)continue;let re=ge[$]>=0?a(u,ge[$]):null,_e=a(b,Pe[$]),Ce=a(x,He[$]);p.set($,[re,ge[$]>=0?t(re,_e,Ce):_e||Ce])}let h=new Set([...p.values()].map($=>$[1])),A=$=>$!==rt&&$!==Tn&&!/\s/.test($),C=($,re)=>{let _e=$;for(;_e<re&&!A(ue[_e]);)_e++;return _e<re&&ge[_e]>=0?a(u,ge[_e]):null},z=new Map,X=0;for(let $=0;$<de;$++){if(ue[$]!==rt)continue;let[re,_e]=p.get($),Ce=C(X,$),je=_e,mt=z.get(je)===je&&Ce===je;je&&z.has(je)&&!mt&&re&&!z.has(re)&&!h.has(re)&&(je=re),je&&!z.has(je)&&z.set(je,Ce);for(let lt=X;lt<=$;lt++)Gt[lt]=je;X=$+1}let ke=$=>{for(let re=0;re<$.text.length;re++)if(A($.text[re])&&!a($,re))return!0;return!1};if(!ke(u)&&!ke(b)&&!ke(x)){let $=[],re=0;for(let Ce=0;Ce<de;Ce++)(ue[Ce]===rt||Ce===de-1)&&($.push([re,Ce]),re=Ce+1);let _e=new Set(Gt);for(let Ce=0;Ce<$.length;Ce++){let[je,mt]=$[Ce];if(Gt[mt])continue;let lt=je;for(;lt<=mt&&!A(ue[lt]);)lt++;if(lt>mt)continue;let Wt=a(u,ge[lt]),Ht=a(b,Pe[lt]),Jt=a(x,He[lt]),Zt=t(Wt,Ht,Jt)||Ht||Jt||Wt;if(Zt&&!_e.has(Zt)){_e.add(Zt);for(let Mt=je;Mt<=mt;Mt++)Gt[Mt]=Zt;continue}let sn=Ce>0&&Gt[$[Ce-1][1]],rn=Ce+1<$.length&&Gt[$[Ce+1][1]];if(sn)pn.add($[Ce-1][1]);else if(rn&&ue[mt]===rt)pn.add(mt);else continue;for(let Mt=je;Mt<=mt;Mt++)Gt[Mt]=sn||rn}}}let jn=new Map,_n=t=>{let a=jn.get(t);if(a)return a;a=[1/0,-1/0];for(let[p,h]of[[t.baseMark,$e],[t.localMark,xe],[t.remoteMark,Lt]]){let A=p&&Tt(p,h);A&&(a[0]=Math.min(a[0],A[0]),a[1]=Math.max(a[1],A[1]))}return jn.set(t,a),a},Vn=(t,a,p)=>{let h=-1,A=-1;for(let C=0;C<t.length;C++){let z=nt.get(t[C].el);z===a&&(h=C),z===p&&(A=C)}return h>=0&&A>=0?h-A:0},mn=(t,a)=>[...t].sort((p,h)=>{for(let z of a){let X=Vn(z,p,h);if(X)return X}let A=_n(p),C=_n(h);return A[0]-C[0]||C[1]-A[1]||p.rank-h.rank||p.id-h.id}),Wn=new Map,K=new Map,Te=t=>{let a=ge[t],p=Pe[t],h=He[t],A=At[t];if(a>=0){let Ce=u.stackAt[a],je=b.stackAt[p],mt=x.stackAt[h],lt=Wn.get(Ce);lt||Wn.set(Ce,lt=new Map);let Wt=lt.get(je);Wt||lt.set(je,Wt=new Map);let Ht=Wt.get(mt);if(Ht)return Ht;let Jt=O(Ce),Zt=O(je),sn=O(mt),rn=new Set;for(let Mt of new Set([...Jt,...Zt,...sn])){let It=Jt.has(Mt),fn=Zt.has(Mt),No=sn.has(Mt);(fn===No?fn:fn===It?No:fn)&&rn.add(Mt)}return Ht=mn(rn,[je,mt,Ce]),Wt.set(mt,Ht),Ht}if(A.src==="both"){let Ce=b.stackAt[p],je=x.stackAt[h];return mn(new Set([...O(Ce),...O(je)]),[Ce,je])}let z=(A.src==="local"?b:x).stackAt[A.src==="local"?p:h];if(!A.inherit)return mn(O(z),[z]);let X=K.get(A);X||K.set(A,X=new Map);let ke=X.get(z);if(ke)return ke;let $=new Set(O(z));for(let Ce of A.inherit.added)$.add(g(Ce));for(let Ce of A.inherit.removed)$.delete(g(Ce));let re=A.src==="local"?x:b,_e=(A.src==="local"?xt.bTo:Ge.bTo)[A.inherit.bs];return ke=mn($,[z,re.stackAt[_e]]),X.set(z,ke),ke},he=new Int32Array(b.text.length+1);he[b.text.length]=de;for(let t=b.text.length-1;t>=0;t--)he[t]=xe[t]>=0?xe[t]:he[t+1];Ws.caret+=b.text.length;let Oe=t=>t<=0?0:(t>b.text.length&&(t=b.text.length),xe[t-1]>=0?xe[t-1]+1:he[t]),Ve=[],ne=[],Ae=null,te=[],Le="",Ue=-1,Ct=t=>{Ae?Ae.appendChild(t):Ve.push(t)},$t=t=>{if(!Le)return;let a=s.createTextNode(Le);Ct(a),ne.push({node:a,ms:Ue,me:t,local:[],u:te.length?te[te.length-1].u:null}),Le=""},on=new Set,Pt=new Map,cn=new Set,Be=t=>{let a=s.createElement(t.tag);if(t.block&&En.add(a),!Pt.has(t)){Pt.set(t,a),Y(t.base,t.local,t.remote,a),l.set(a,{base:t.base,local:t.local,remote:t.remote});let h=(z,X)=>N&&t[X]&&z.reverse.get(t[X])?X:null,A=!t.base&&(h(n,"local")||h(r,"remote"));if(A){let z=A==="local"?n.reverse.get(t.local):r.reverse.get(t.remote),X=l.get(a);X.local=X.local||n.map.get(z)||null,X.remote=X.remote||r.map.get(z)||null,d.push({kind:"move",el:a,source:A})}else t.base||d.push({kind:"insert",el:a,source:t.local&&t.remote?"both":t.local?"local":"remote"});let C=l.get(a);C.local&&(cn.has(C.local)?C.local=null:cn.add(C.local))}else{let h=Pt.get(t);for(let A of h.attributes)A.name!=="id"&&A.name!=="data-id"&&v(a,A,A.value);l.set(a,{base:null,local:null,remote:null})}Ct(a),te.push({u:t,el:a}),Ae=a},We=new Set,q=new Map;for(let t of b.pins){let a=Oe(t.i);q.has(a)||q.set(a,[]),q.get(a).push(t)}let ae=t=>{let a=q.get(t);if(a){$t(t);for(let p of a){let h=p.el.namespaceURI&&p.el.namespaceURI!=="http://www.w3.org/1999/xhtml"?s.createElementNS(p.el.namespaceURI,p.el.tagName):s.createElement(p.el.tagName);l.set(h,{base:null,local:p.el,remote:null,pinned:!0}),We.add(h),Ct(h)}}},be=u.atoms.length||b.atoms.length||x.atoms.length,Re=t=>{if(!be)return null;let a=ge[t]>=0?u.atomAt.get(ge[t]):null,p=Pe[t]>=0?b.atomAt.get(Pe[t]):null,h=He[t]>=0?x.atomAt.get(He[t]):null;return a||p||h?{ab:a,al:p,ar:h}:null},ve=(t,a,p,h)=>{if(!t||!N)return null;let A=P.get(a.reverse.get(t.el))||null;return!A||A===h||(h?A.el.isEqualNode(h.el):p.bTo[A.i]>=0)?null:A},qe=(t,a)=>{if(!t||!N||!e.moveIn)return null;let p=a.reverse.get(t.el);return p&&!P.has(p)?p:null},tt=(t,a)=>{let p=new Map;for(let h of t.atoms)p.set(a(h),(p.get(a(h))||0)+1);return p},Rt=tt(u,F),Ut=tt(b,H),Ft=tt(x,Q),vt=t=>{let a=F(t);return Rt.get(a)===1&&(Ut.get(a)||0)<=1&&(Ft.get(a)||0)<=1},Kt=new Map,dt=new Set,pt=new Set,zt=new Set;for(let t=0;t<de;t++){let a=Re(t);if(!a)continue;let{ab:p,al:h,ar:A}=a,C=ve(A,r,xt,p),z=ve(h,n,Ge,p),X=p,ke=null;if(C?(X=C,ke="remote"):z&&(X=z,ke="local"),X){dt.has(X)?Kt.set(t,{dup:X.el}):(dt.add(X),Kt.set(t,{bk:X,from:ke,al:h,ar:A}));continue}let $=qe(A,r),re=qe(h,n),_e=$||re;if(_e){pt.has(_e)?Kt.set(t,{dup:_e}):(pt.add(_e),Kt.set(t,{moveIn:_e,side:$?"remote":"local",sideEl:$?A.el:h.el}));continue}let Ce=(mt,lt)=>mt&&N&&P.get(lt.reverse.get(mt.el))||null,je=Ce(A,r)||Ce(h,n);if(je&&(zt.add(je),At[t].conflict&&vt(je))){if(dt.has(je)){Kt.set(t,{dup:je.el});continue}dt.add(je)}Kt.set(t,{al:h,ar:A})}let Xt=new Map,Fn=(t,a)=>{if(t[a]>=0)return t[a];for(let p=a-1;p>=0;p--)if(t[p]>=0)return t[p]+1;return 0};if(N)for(let t of u.atoms){if(dt.has(t)||zt.has(t))continue;let a=n.map.get(t.el)||null,p=r.map.get(t.el)||null,h=a&&it.get(a),A=p&&w.get(p);if(a&&!h||p&&!A)continue;let C=!(h&&A)&&st.has(t);if(!C&&!(h&&A&&vt(t)))continue;let z=o==="local"?[[h,xe],[A,Lt]]:[[A,Lt],[h,xe]],[X,ke]=z.find(([re])=>re),$=Fn(ke,X.i);Xt.has($)||Xt.set($,[]),Xt.get($).push({a:t,lt:a,rt:p,edited:C}),dt.add(t)}if(N&&e.moveIn){let t=[[b,n,xe,"local"],[x,r,Lt,"remote"]];o!=="local"&&t.reverse();for(let[a,p,h,A]of t)for(let C of a.atoms){let z=qe(C,p);if(!z||pt.has(z))continue;pt.add(z);let X=Fn(h,C.i);Xt.has(X)||Xt.set(X,[]),Xt.get(X).push({move:z,side:A,sideEl:C.el})}}let Cn=t=>{let a=Xt.get(t);if(a){if($t(t),a.some(p=>Me(p.move?p.sideEl:p.a.el)))for(;te.length;)te.pop(),Ae=te.length?te[te.length-1].el:null;for(let{a:p,lt:h,rt:A,edited:C,move:z,side:X,sideEl:ke}of a){if(z){let re=e.moveIn(z,X,ke);re&&Ct(re);continue}on.add(p);let $=le(p.el,h,A);C&&(f.push({kind:"structure",el:$,detail:"edit-beats-delete",base:p.el}),d.push({kind:"insert",el:$,source:h?"local":"remote"})),Ct($)}}},En=new Set;for(let t=0;t<de;t++){let a=Re(t),h=!!a&&Me((a.ab||a.al||a.ar).el)?[]:Gt[t]?[Gt[t],...Te(t)]:Te(t),A=0;for(;A<te.length&&A<h.length&&te[A].u===h[A];)A++;if(A<te.length)for($t(t);te.length>A;)te.pop(),Ae=te.length?te[te.length-1].el:null;if(ae(t),Cn(t),h.length>te.length)for($t(t);te.length<h.length;)Be(h[te.length]);if(ue[t]===rt){if(pn.has(t))continue;$t(t);let C=te.length;for(;C>0&&!te[C-1].u.block;)C--;if(C>0)for(;te.length>=C;)te.pop(),Ae=te.length?te[te.length-1].el:null;continue}if(a){$t(t);let C=Kt.get(t),z;if(C.dup){f.push({kind:"structure",el:null,detail:"both-moved",base:C.dup});continue}if(C.moveIn){if(z=e.moveIn(C.moveIn,C.side,C.sideEl),!z)continue}else if(C.bk){let X=C.bk;if(on.add(X),X===a.ab)z=le(X.el,C.al.el,C.ar.el);else{let ke=n.map.get(X.el)||null,$=r.map.get(X.el)||null;z=le(X.el,ke,$),(!ke||!$)&&f.push({kind:"structure",el:null,detail:"move-beats-delete",base:X.el}),d.push({kind:"move",el:z,source:C.from})}}else C.al?(z=Ne(C.al.el,"local"),C.ar&&(l.get(z).remote=C.ar.el),d.push({kind:"insert",el:z,source:C.ar?"both":"local"})):(z=Ne(C.ar.el,"remote"),d.push({kind:"insert",el:z,source:"remote"}));Ct(z);continue}Le||(Ue=t),Le+=ue[t]}if($t(de),(q.has(de)||Xt.has(de))&&(te.length=0,Ae=null,ae(de),Cn(de)),de===0&&(b.placeholder||x.placeholder||u.placeholder)){let t=s.createElement("br");l.set(t,{base:u.placeholder,local:b.placeholder,remote:x.placeholder}),Ve.push(t)}let ce=0,Fe=t=>{for(;ce>0&&ne[ce-1].me>=t;)ce--;for(;ce<ne.length&&ne[ce].me<t;)ce++;let a=ne[ce];if(!a)return ne[ne.length-1]||null;let p=ne[ce+1];return a.me===t&&p&&p.ms===t?p:a},ct=new Map,Ze={},Ye=(t,a,p)=>{let h=Fe(t)||(p?Ze:null);if(!h)return;let A=ct.get(h)||{l:!1,r:!1};a!=="remote"&&(A.l=!0),a!=="local"&&(A.r=!0),ct.set(h,A)},Qt=t=>{if(t.conflict)return!0;let a=t.src==="local"?b.text:t.src==="remote"?x.text:"";for(let p=t.from;p<t.to;p++)if(a[p]!==Tn&&a[p]!==rt)return!0;return!1};for(let t of Nt)t.src!=="base"&&Ye(t.ms,t.conflict?"both":t.src,Qt(t));for(let[t,a]of pe)$e[t]>=0&&Ye($e[t],a);for(let t of ne.length?ne:[Ze]){let a=ct.get(t);a&&d.push({kind:"text",node:t.node||null,source:a.l&&a.r?"both":a.l?"local":"remote"})}for(let t of ft){if(Pt.has(t))continue;let a=!t.local&&!(N&&n.map.get(t.base)),p=!t.remote&&!(N&&r.map.get(t.base));!a&&!p||d.push({kind:"remove",source:a&&p?"both":a?"local":"remote",base:t.base})}let Yt=(t,a,p)=>{if(a<=t)return!1;for(let h=t;h<a;h++)if(p[h]>=0)return!1;return!0};for(let t of ft)for(let a of["local","remote"]){let p=t[a+"Mark"],h=t.baseMark;if(!p)continue;let A=a==="local"?Ge:xt;if(!Yt(h.from,h.to,A.bTo)||!Yt(p.from,p.to,A.toB))continue;let C=(a==="local"?St:m).find(z=>z.ss<=p.from&&p.from<z.se);C&&(C.be<=h.from||C.bs>=h.to)&&d.push({kind:"move",el:Pt.get(t)||null,source:a})}let ln=t=>{let a=nt.get(t.node.parentNode);return a?g(a):null};for(let t of b.nodes){let a=-1;for(let h=t.s;h<t.e;h++)if(xe[h]>=0){a=xe[h];break}let p;if(a>=0)p=Fe(a);else{let h=Oe(t.s),A=ln(t);p=ne.find(C=>C.u===A&&C.me>=h)||ne.filter(C=>C.u===A).pop()}p&&p.local.push(t)}let qt=new Map,Dt=ne[ne.length-1]||null,Vt=0;for(let t of b.nodes){let a=null;for(let p=t.s;p<=t.e;p++){let h=Oe(p);for(;Vt>0&&ne[Vt-1].me>=h;)Vt--;for(;Vt<ne.length&&ne[Vt].me<h;)Vt++;let A=z=>z&&h>=z.ms&&h<=z.me&&(h<z.me||p===t.e||z===a),C=A(ne[Vt])?ne[Vt]:A(ne[Vt+1])?ne[Vt+1]:ne[Vt]||Dt;if(!C)break;if(a===C){let z=qt.get(C);z[z.length-1].to=p-t.s;continue}a=C,qt.has(C)||qt.set(C,[]),qt.get(C).push({node:t.node,from:p-t.s,to:p-t.s,flatStart:t.s})}}for(let t of ne){let a=t.local,p=!1;for(let z of a)for(let X=z.s;X<z.e&&!p;X++)(xe[X]<t.ms||xe[X]>=t.me)&&(p=!0);l.set(t.node,{base:null,local:a.map(z=>z.node),remote:null,caret:qt.get(t)||[],partial:p});let h=t.ms,A=t.me-t.ms,C=z=>{let X=0,ke=-1;for(let $ of a){let re=$.e-$.s;if(z<=X+re){ke=$.s+(z-X);break}X+=re}return ke<0&&(ke=a.length?a[a.length-1].e:0),Math.max(0,Math.min(Oe(ke)-h,A))};C.flat=z=>Math.max(0,Math.min(Oe(z)-h,A)),c.set(t.node,C)}function us(){if(!b.text.includes(rt))return[{flatLocal:b.text,localNodes:b.nodes,textNodes:ne,lToM:xe,mapLocal:Oe}];let t=[],a=0,p=0;for(let h=0;h<=b.text.length;h++){if(h<b.text.length&&b.text[h]!==rt)continue;let A=a,C=h;if(C>A){let z=[];for(;p<b.nodes.length&&b.nodes[p].e<=A;)p++;for(let X=p;X<b.nodes.length&&b.nodes[X].s<C;X++){let ke=b.nodes[X],$=Math.max(ke.s,A),re=Math.min(ke.e,C);$<re&&z.push({node:ke.node,s:$-A,e:re-A})}t.push({flatLocal:b.text.slice(A,C),localNodes:z,textNodes:ne,lToM:xe.subarray?xe.subarray(A,C+1):xe.slice(A,C+1),mapLocal:X=>Oe(A+Math.max(0,Math.min(X,C-A)))})}a=h+1}return t}let ds={...e,blocks:En,ignored:t=>We.has(t)||(e.ignored?e.ignored(t):!1)},xo=e.ignoreAttribute||(()=>!1),hs=Ho(Hn(Ve,ds),xo)!==Ho(x,xo);return{nodes:Ve,text:ue,textNodes:ne,localDiverged:hs,mapLocal:Oe,conflicts:f.slice(M),granularity:bt?"line":"word",segments:us(),localHunks:St,remoteHunks:m,lToM:xe}}var $s="http://www.w3.org/1999/xhtml";function Ys(e){let s=5381;for(let o=0;o<e.length;o++)s=(s<<5)+s^e.charCodeAt(o);return(s>>>0).toString(36)}function _t(e){return!!e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.namespaceURI===$s}function Js(e){let s=(e.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return s==="application/json"||s.endsWith("+json")}function Jn(e,s){let o=e.getAttribute("src"),n=(e.getAttribute("type")||"text/javascript").split(";")[0].trim().toLowerCase();if(o){let r=o;try{let l=new URL(o,s);r=l.origin+l.pathname+l.search}catch{}return"script|src|"+n+"|"+r}return"script|inline|"+n+"|"+Ys(e.textContent.trim())}var Xs={match:e=>e.hasAttribute("merge"),identity:e=>e.getAttribute("merge")};function xn(e,s=[],o=!1){if(!_t(e)||e.hasAttribute("src"))return null;let n=[Xs,...s];for(let r=0;r<n.length;r++){let l=n[r];if(!l.match(e))continue;if(!Js(e))return o&&console.warn("[hyper-morph] merge ignored: script type is not JSON",e),null;let c=l.identity(e);return c==null||c===""?null:{key:r+":"+c,raw:c,recognizer:l}}return null}function Vo(e,s,o){let n=new Set,r=l=>{_t(l)&&!s(l)&&n.add(Jn(l,o))};r(e);for(let l of e.querySelectorAll("script"))r(l);return n}function Bn(e,s){let o=s.createElement("div");o.innerHTML="<script><\/script>";let n=o.firstChild;for(let r of e.attributes)n.setAttribute(r.name,r.value);return n.textContent=e.textContent,n}function Wo(e,s,o){let n=[],r=[],l=Array.from(e.querySelectorAll("script"));_t(e)&&l.unshift(e);for(let c of l){if(!_t(c)||o.ignored(c)||o.skip.has(c)||s.has(Jn(c,o.baseURI)))continue;let f=c.ownerDocument.createElement("script");for(let d of c.attributes)f.setAttribute(d.name,d.value);f.textContent=c.textContent,o.beforeNodeAdded(f)!==!1&&(f.hasAttribute("src")&&r.push(new Promise(d=>{f.addEventListener("load",()=>d()),f.addEventListener("error",()=>d())})),c.replaceWith(f),o.afterNodeAdded(f),n.push(f))}return{executed:n,loads:r}}function Qs(e){let s=5381;for(let o=0;o<e.length;o++)s=(s<<5)+s^e.charCodeAt(o);return(s>>>0).toString(36)}function Zs(e,s){try{let o=new URL(e,s);return o.origin+o.pathname+o.search}catch{return e}}function Fo(e,s){let o=e.tagName;if(o==="TITLE"||o==="BASE")return o;if(o==="SCRIPT")return Jn(e,s);if(o==="LINK"){let n=e.getAttribute("href");return n?"link|"+(e.getAttribute("rel")||"")+"|"+Zs(n,s):e.outerHTML}if(o==="META"){for(let n of["charset","name","property","http-equiv","itemprop"])if(e.hasAttribute(n))return"meta|"+n+"="+e.getAttribute(n);return e.outerHTML}return o==="STYLE"?"style|"+Qs(e.textContent):e.outerHTML}function ko(e,s){for(;;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(e[s]==="/"&&e[s+1]==="/"){for(;s<e.length&&e[s]!==`
|
|
3
|
+
`;)s++;continue}if(e[s]==="/"&&e[s+1]==="*"){let o=e.indexOf("*/",s+2);if(o===-1)return e.length;s=o+2;continue}return s}}function Ko(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(s,o)=>o.length%2===0?o+'\\"':s)}var er=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,tr=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Xn(e){try{return JSON.parse(e)}catch{return JSON.parse(nr(e))}}function nr(e){let s="",o=0,n=(r,l)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${l}`)};for(;o<e.length&&(o=ko(e,o),!(o>=e.length));){let r=e[o];if("{}[]:".includes(r)){s+=r,o++;continue}if(r===","){let f=ko(e,o+1);if(e[f]==="}"||e[f]==="]"){o++;continue}s+=r,o++;continue}if(r==='"'||r==="'"){let f=o+1;for(;f<e.length&&e[f]!==r;)e[f]==="\\"&&f++,f++;f>=e.length&&n("unterminated string",o);let d=e.slice(o+1,f);r==="'"&&(d=Ko(d)),s+='"'+d+'"',o=f+1;continue}let l=o;for(;l<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[l]);)l++;l===o&&n("unexpected character "+JSON.stringify(r),o);let c=e.slice(o,l);if(c==="true"||c==="false"||c==="null"||er.test(c)){s+=c,o=l;continue}if(tr.test(c)){if(e[ko(e,l)]===":"){s+='"'+c+'"',o=l;continue}n("unquoted value "+JSON.stringify(c),o)}n("invalid token "+JSON.stringify(c),o)}return s}function zo(e){try{return JSON.parse(e)}catch{}let s={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function o(r){let l=[],c=0;for(;c<r.length;){let f=r[c];if(/\s/.test(f)){c++;continue}if("{}".includes(f)){l.push({type:f,value:f}),c++;continue}if(f==="["){let y=!1,T=c+1;for(;T<r.length&&/\s/.test(r[T]);)T++;if(T<r.length&&/[a-zA-Z_]/.test(r[T])&&(y=!0),!y){l.push({type:f,value:f}),c++;continue}}if(f==="]"){l.push({type:f,value:f}),c++;continue}if(f===":"){l.push({type:s.COLON,value:f}),c++;continue}if(f===","){l.push({type:s.COMMA,value:f}),c++;continue}if(f==='"'||f==="'"){let y=f,T=c+1;for(;T<r.length&&r[T]!==y;)r[T]==="\\"&&T++,T++;l.push({type:s.STRING,value:r.substring(c+1,T),quoted:!0,sourceQuote:y}),c=T+1;continue}let d=c,M;for(;d<r.length&&!/[{},]/.test(r[d]);)if(r[d]===":"){let y=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],T=!1;for(let u of y){let b=u.substring(1);if(r.substring(d+1,d+1+b.length)===b){T=!0,d+=b.length;break}}if(!T)break}else if(r[d]==="["){for(d++;d<r.length&&r[d]!=="]";){if(r[d]==='"'||r[d]==="'"){let y=r[d];for(d++;d<r.length&&r[d]!==y;)r[d]==="\\"&&d++,d++}d++}d<r.length&&r[d]==="]"&&d++}else d++;M=r.substring(c,d);let N=s.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?N=s.NUMBER:M==="true"||M==="false"||M==="null"?N=s.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(N=s.SELECTOR),l.push({type:N,value:M,quoted:!1}),c=d}return l}function n(r){let l="";for(let c=0;c<r.length;c++){let f=r[c];if("{}".includes(f.type)||"[]".includes(f.type)){l+=f.value;continue}if(f.type===s.COLON){l+=f.value;continue}if(f.type===s.COMMA){let d=r[c+1];if(d&&(d.type==="}"||d.type==="]"))continue;l+=f.value;continue}if(f.type===s.STRING){let d=f.value;f.sourceQuote==="'"&&(d=Ko(d)),l+=`"${d}"`;continue}if(f.type===s.NUMBER||f.type===s.BOOLEAN){l+=f.value;continue}l+=`"${f.value}"`}return l}try{let r=o(e),l=n(r);return JSON.parse(l)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var gt=Symbol("hyper-morph-json-merge:missing"),qo=["id","_id","uuid","key","slug","code","name"];function Nn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Dn(e,s){return Object.prototype.hasOwnProperty.call(e,s)}function or(e,s,o){Object.defineProperty(e,s,{value:o,enumerable:!0,writable:!0,configurable:!0})}function an(e,s){if(e===s)return!0;if(Array.isArray(e)&&Array.isArray(s)){if(e.length!==s.length)return!1;for(let o=0;o<e.length;o++)if(!an(e[o],s[o]))return!1;return!0}if(Nn(e)&&Nn(s)){let o=Object.keys(e);if(o.length!==Object.keys(s).length)return!1;for(let n of o)if(!Dn(s,n)||!an(e[n],s[n]))return!1;return!0}return!1}function Go(e,s,o,n){return an(s,o)?s:an(s,e)?o:an(o,e)?s:Nn(s)&&Nn(o)?sr(Nn(e)?e:{},s,o,n):Array.isArray(s)&&Array.isArray(o)?lr(Array.isArray(e)?e:[],s,o,n):o}function $o(e,s,o,n){return s===gt&&o===gt?gt:s===gt?e===gt?o:an(o,e)?gt:o:o===gt?e===gt?s:gt:Go(e,s,o,n)}function sr(e,s,o,n){let r={},l=new Set([...Object.keys(e),...Object.keys(s),...Object.keys(o)]);for(let c of l){let f=$o(Dn(e,c)?e[c]:gt,Dn(s,c)?s[c]:gt,Dn(o,c)?o[c]:gt,n);f!==gt&&or(r,c,f)}return r}function rr(e){return e===null||typeof e!="object"}function Qn(e){return typeof e+":"+String(e)}function ir(e,s){for(let o of s){let n=new Set;for(let r of o){if(!Dn(r,e))return!1;let l=r[e];if(typeof l!="string"&&typeof l!="number")return!1;let c=Qn(l);if(n.has(c))return!1;n.add(c)}}return!0}function cr(e,s,o,n){let r=[e,s,o],l=!0;for(let c of r)for(let f of c)Nn(f)||(l=!1);if(l){for(let c of n.keyCandidates)if(ir(c,r))return{kind:"keyed",field:c};return null}for(let c of r){let f=new Set;for(let d of c){if(!rr(d))return null;let M=Qn(d);if(f.has(M))return null;f.add(M)}}return{kind:"self"}}function lr(e,s,o,n){let r=cr(e,s,o,n);if(!r)return o;let l=r.kind==="self"?Qn:u=>Qn(u[r.field]),c=u=>{let b=new Map;for(let x of u)b.set(l(x),x);return b},f=c(e),d=c(s),M=c(o),N=new Map,y=new Set([...f.keys(),...d.keys(),...M.keys()]);for(let u of y){let b=$o(f.has(u)?f.get(u):gt,d.has(u)?d.get(u):gt,M.has(u)?M.get(u):gt,n);b!==gt&&N.set(u,b)}let T=[];for(let u of o){let b=l(u);N.has(b)&&T.push(b)}for(let u=0;u<s.length;u++){let b=l(s[u]);if(!N.has(b)||T.includes(b))continue;let x=0;for(let P=u-1;P>=0;P--){let v=T.indexOf(l(s[P]));if(v!==-1){x=v+1;break}}T.splice(x,0,b)}return T.map(u=>N.get(u))}function yo(e,s,o,n={}){let r=n.keyCandidates?[...n.keyCandidates,...qo]:qo;return Go(e===void 0?gt:e,s,o,{keyCandidates:r})}function Zn(e,s,o,n={}){let r=n.parse||Xn,l=[],c=(y,T)=>{if(typeof y!="string")return gt;try{return r(y)}catch(u){return l.push(`${T} side is not valid JSON (${u.message})`),gt}},f=c(s,"local"),d=c(o,"remote");if(f===gt)return{text:o,warnings:l};if(d===gt)return{text:s,warnings:l};let M=c(e,"base"),N=yo(M===gt?void 0:M,f,d,n);return an(N,d)?{text:o,warnings:l}:an(N,f)?{text:s,warnings:l}:{text:JSON.stringify(N,null,2),warnings:l}}var Ee=e=>!!e&&e.nodeType===1,ar=new Set("P H1 H2 H3 H4 H5 H6 DIV LI DD DT BLOCKQUOTE FIGCAPTION SUMMARY ADDRESS".split(" ")),Yo=5e4;function wo(e,s,o,n){let r=n.ignored,l=Oo({ignored:r,ignoreAttribute:n.ignoreAttribute}),{unitsOf:c,meta:f}=l,d=n.baseURI,M=n.mergeTags!==null,N=m=>L=>{if(M&&L.tagName==="SCRIPT"){let R=xn(L,n.mergeTags);if(R)return"merge:"+R.key}return L.parentElement&&L.parentElement.tagName==="HEAD"?Fo(L,d):m(L)},y=N(n.identity.base),T=N(n.identity.local),u=N(n.identity.remote),b=n.authored||n.identity,x=m=>m&&m.nodeType===9?m.documentElement:m,P=x(e),v=x(s),j=x(o),Y=globalThis.__hyperMorphProfile,le=Y?performance.now():0,Ne="[id],[data-id],script,head>*",ye=m=>m===un?Ne:null,De=Gn(P,y,r,ye(n.identity.base)),F=n.localIsBase?Xo():ro(P,v,{analyzer:l,baseIndex:De,sideIndex:Gn(v,T,r,ye(n.identity.local)),baseId:b.base,sideId:b.local}),H=ro(P,j,{analyzer:l,baseIndex:De,sideIndex:Gn(j,u,r,ye(n.identity.remote)),baseId:b.base,sideId:b.remote});Je(),Xe(F,H),Xe(H,F),Y&&(Y.alignTotal=(Y.alignTotal||0)+(performance.now()-le),le=performance.now());let Q=P.ownerDocument.implementation.createHTMLDocument(""),ie=new WeakMap,me=new WeakMap,Ie=[],ot=[],bt=new Set,kt=[],Se=new Set,at=new Set,Ge=new Set,xt=new WeakMap,Ke=n.conflicts||"remote",ze=m=>Ie.push(m),it=m=>Ie.push(m),w=m=>ot.push(m),E=Me(),oe=g(P,F.map.get(P),H.map.get(P),!!n.localIsBase,!!n.childrenOnly);oe.tagName==="HTML"?Q.replaceChild(oe,Q.documentElement):Q.body.appendChild(oe),Y&&(Y.build=(Y.build||0)+(performance.now()-le));let Z=n.childrenOnly?!Qe(ut(oe),ut(j)):!yt(oe,j);return{doc:Q,root:oe,provenance:ie,textMappers:me,decisions:Ie,conflicts:ot,localDiverged:Z,mergedScripts:bt,segments:kt,remoteIdOf:n.identity.remote,customIdentity:n.identity.remote!==un,L:F,R:H};function Me(){let m=new Map,L=new Set;if(n.localIsBase||!F.insertedByHash)return{partner:m,drop:L};let R=F.insertedByHash(),W=H.insertedByHash();if(!R.size||!W.size)return{partner:m,drop:L};let D={ignored:r,remoteWins:n.remoteWins,inlineCache:xt},V=de=>{let $e=0;for(let xe=de.parentNode;xe;xe=xe.parentNode)$e++;return $e},G=[],se=de=>{let $e=de.textContent.trim();return $e.split(/\s+/).length>=3||$e.replace(/\s/g,"").length>=12},pe=de=>{let $e=F.map.get(de),xe=H.map.get(de);return $e&&F.reverse.get($e.parentNode)!==de.parentNode||xe&&H.reverse.get(xe.parentNode)!==de.parentNode},ue=(de,$e,xe)=>{for(let Tt of xe.parentNode.children){let Ot=Tt!==xe&&de.reverse.get(Tt);if(Ot&&pe(Ot))return!0}let Lt=de.reverse.get(xe.parentNode);if(Lt){for(let Tt of Lt.children)if(!$e.map.has(Tt)&&!r(Tt))return!0}return!1};for(let[de,$e]of R){let xe=W.get(de);if(!xe)continue;let Lt=$e.length===1&&xe.length===1;for(let Tt of $e)hn(Tt,D)||G.push([Tt,xe,V(Tt),Lt&&(se(Tt)||ue(F,H,Tt)||ue(H,F,xe[0]))])}if(!G.length)return{partner:m,drop:L};G.sort((de,$e)=>de[2]-$e[2]);let ge=new Set,Pe=new Set,He=de=>{for(let $e of de.querySelectorAll("*"))ge.add($e)},At=(de,$e)=>de.reverse.get($e.parentNode)||null;for(let[de,$e,,xe]of G){if(ge.has(de))continue;let Lt=At(F,de),Tt=ht=>!Pe.has(ht)&&!ge.has(ht)&&ht.tagName===de.tagName,Ot=$e.find(ht=>Tt(ht)&&Lt&&At(H,ht)===Lt)||(xe?$e.find(Tt):null);Ot&&(Pe.add(Ot),He(de),He(Ot),!(Lt&&At(H,Ot)===Lt)&&(m.set(de,Ot),m.set(Ot,de),L.add(Ke==="local"?Ot:de)))}return{partner:m,drop:L}}function st(m,L,R){if(Se.add(m),E.drop.has(m))return null;Se.add(R);let W=L==="local"?m:R,D=L==="local"?R:m,V;return l.unitHash(W)===l.unitHash(D)?(V=we(W,"local",!0),ie.get(V).remote=D):V=ee(W,D),w({kind:"structure",el:V,detail:"both-moved",base:null,local:W,remote:D}),ze({kind:"insert",el:V,source:"both"}),V}function Je(){if(!F.weak||!H.weak||!F.weak.size||!H.weak.size||!F.unpair)return;let m=new Map;for(let R of F.weak){let W=F.map.get(R);Ee(R)&&Ee(W)&&m.set(l.unitHash(W),R)}let L=!1;for(let R of Array.from(H.weak)){let W=H.map.get(R);if(!Ee(R)||!Ee(W))continue;let D=m.get(l.unitHash(W));!D||D===R||!F.weak.has(D)||F.map.has(R)&&H.map.has(D)||F.map.get(D).tagName===W.tagName&&(F.unpair(D),H.unpair(R),L=!0)}L&&(F.rematch(),H.rematch())}function Xe(m,L){if(!m.weak||!m.weak.size||!L.insertedByHash)return;let R=L.insertedByHash();if(!R.size)return;let W=!1;for(let D of Array.from(m.weak)){let V=m.map.get(D);if(!V)continue;let G=R.get(l.unitHash(V));G&&G.some(se=>se.tagName===V.tagName)&&(m.unpair(D),W=!0)}W&&m.rematch()}function nt(m,L){if(m.map.has(L))return m.map.get(L);let R=[];for(let D=L.parentNode;D&&!m.map.has(D);D=D.parentNode)R.push(D);let W=R.length?R[R.length-1].parentNode:L.parentNode;if(!W||!m.identical.has(W))return null;m.pairIdenticalChildren(W);for(let D=R.length-1;D>=0;D--)m.pairIdenticalChildren(R[D]);return m.map.get(L)||null}function ft(m,L,R){if(at.has(m)||Ge.has(m))return w({kind:"structure",el:null,detail:"both-moved",base:m}),at.has(m)?null:we(R,L);let W=nt(F,m),D=nt(H,m);(!W||!D)&&w({kind:"structure",el:null,detail:"move-beats-delete",base:m});let V=g(m,W,D,!1);return(L==="local"?ze:it)({kind:"move",el:V,source:L}),V}function i(m,L,R,W){return W||!L||L===R?{el:R,asBase:!0,twin:D=>D,baseOf:D=>D,units:c(R),here:()=>!0,parentOfTwin:()=>R}:{el:L,asBase:!1,twin:D=>m.map.get(D),baseOf:D=>m.reverse.get(D),units:c(L),here:D=>Ee(D)?D.parentNode===L||L.tagName==="TEMPLATE"&&D.parentNode===L.content:D.parent===L||L.tagName==="TEMPLATE"&&D.parent===L.content}}function k(m,L,R){return!L||R&&R.identical.has(m)?!1:Ee(m)?f(m).hash!==f(L).hash:m.value!==L.value}function g(m,L,R,W,D=!1){let V=W||n.remoteWins(m),G=m.namespaceURI&&m.namespaceURI!=="http://www.w3.org/1999/xhtml"?Q.createElementNS(m.namespaceURI,m.tagName):Q.createElement(m.tagName),se={base:m,local:L||null,remote:R||null};if(ie.set(G,se),Se.add(m),at.add(m),L&&Se.add(L),R&&Se.add(R),n.skipUnchanged&&!D&&(n.localIsBase||F.identical.has(m))&&R&&H.identical.has(m)&&!n.remoteWins(m)){se.unchanged=!0;for(let ue of m.attributes)ue.namespaceURI?G.setAttributeNS(ue.namespaceURI,ue.name,ue.value):G.setAttribute(ue.name,ue.value);return G}Ge.add(m),D||O(m,V?m:L,R,G);let pe=m.tagName;if(_t(m))I(m,V?m:L,R,G);else if(pe==="TEXTAREA")G.textContent=_(m.textContent,(V?m:L)?(V?m:L).textContent:m.textContent,R?R.textContent:m.textContent,G,"text");else{let ue=et(m,L,R,V,G),ge=pe==="TEMPLATE"&&G.content?G.content:G;for(let Pe of ue)ge.appendChild(Pe)}return Ge.delete(m),G}function _(m,L,R,W,D){if(L===R)return L;if(L===m)return R!==m&&it({kind:D,node:W,source:"remote"}),R;if(R===m)return ze({kind:D,node:W,source:"local"}),L;let V=Ke==="local"?L:R;return w({kind:D,node:W,base:m,local:L,remote:R,resolved:V}),Ie.push({kind:D,node:W,source:"both"}),V}function I(m,L,R,W){let D=m.textContent,V=L?L.textContent:D,G=R?R.textContent:D,se=M?xn(m,n.mergeTags,!0):null;if(se&&V!==G){let pe=R&&R.getAttribute("merge-key")||m.getAttribute("merge-key"),{text:ue,warnings:ge}=Zn(n.localIsBase?void 0:D,V,G,{parse:se.recognizer.parse,keyCandidates:pe?pe.split(/[\s,]+/).filter(Boolean):void 0});for(let Pe of ge)console.warn(`[hyper-morph] merge "${se.raw}": ${Pe}`);W.textContent=ue,bt.add(W),ue!==G?ze({kind:"text",node:W,source:ue===V?"local":"both"}):ue!==D&&it({kind:"text",node:W,source:"remote"});return}W.textContent=_(D,V,G,W,"text")}function O(m,L,R,W){let D=new Map;for(let V of[m,L,R])if(V)for(let G of V.attributes)n.ignoreAttribute(V,G.name)||D.set(G.name,G);for(let[V,G]of D){let se=m?m.getAttribute(V):null,pe=L?L.getAttribute(V):se,ue=R?R.getAttribute(V):se,ge;pe===ue?ge=pe:pe===se?(ge=ue,it({kind:"attr",el:W,name:V,source:"remote"})):ue===se?(ge=pe,ze({kind:"attr",el:W,name:V,source:"local"})):(ge=U(V,se,pe,ue),ge===void 0&&(ge=Ke==="local"?pe:ue,w({kind:"attr",el:W,name:V,base:se,local:pe,remote:ue,resolved:ge})),Ie.push({kind:"attr",el:W,name:V,source:"both"})),ge!=null&&(G.namespaceURI?W.setAttributeNS(G.namespaceURI,G.name,ge):W.setAttribute(V,ge))}}function U(m,L,R,W){if(m==="class"){let D=ue=>new Set((ue||"").split(/\s+/).filter(Boolean)),V=D(L),G=D(R),se=D(W),pe=new Set;for(let ue of new Set([...V,...G,...se])){let ge=V.has(ue),Pe=G.has(ue),He=se.has(ue);(Pe===He?Pe:Pe===ge?He:Pe)&&pe.add(ue)}return[...pe].join(" ")}if(m==="style"){let D=ge=>{let Pe=new Map;if(!ge)return Pe;let He=0,At=null,de="",$e=()=>{let xe=de.indexOf(":");xe>0&&Pe.set(de.slice(0,xe).trim(),de.slice(xe+1).trim()),de=""};for(let xe of ge){if(At){de+=xe,xe===At&&(At=null);continue}if(xe==='"'||xe==="'"){At=xe,de+=xe;continue}if(xe==="("?He++:xe===")"&&He--,xe===";"&&He===0){$e();continue}de+=xe}return de.trim()&&$e(),Pe},V=D(L),G=D(R),se=D(W),pe=new Map,ue=!1;for(let ge of new Set([...V.keys(),...G.keys(),...se.keys()])){let Pe=V.get(ge)??null,He=G.get(ge)??null,At=se.get(ge)??null,de;He===At?de=He:He===Pe?de=At:At===Pe?de=He:(de=Ke==="local"?He:At,ue=!0),de!=null&&pe.set(ge,de)}return ue?void 0:[...pe].map(([ge,Pe])=>`${ge}: ${Pe}`).join("; ")}}function S(m,L,R,W){let D=m.value,V=W?D:L?L.value:"",G=R?R.value:"";Se.add(m),L&&Se.add(L),R&&Se.add(R);let se=yn(D,V,G,Ke),pe=se.text===""?null:Q.createTextNode(se.text);pe&&(ie.set(pe,{base:m.nodes,local:L?L.nodes:null,remote:R?R.nodes:null}),me.set(pe,se.mapLocalOffset)),V!==D&&G!==D?Ie.push({kind:"text",node:pe,source:"both"}):V!==D?ze({kind:"text",node:pe,source:"local"}):G!==D&&it({kind:"text",node:pe,source:"remote"});for(let ue of se.conflicts)w({kind:"text",node:pe,base:D.slice(ue.bs,ue.be),local:ue.local,remote:ue.remote,resolved:ue.resolved});return pe}function B(m,L){return wn(m,L).every(R=>R.bs===R.be)}function J(m,L){let R=m?m.value:"",W=L?L.value:"",D;if(R===W||!W?D=R:R?B(R,W)?D=W:B(W,R)?D=R:(D=Ke==="local"?R:Ke==="both"?R+W:W,w({kind:"structure",el:null,detail:"insert-collision",local:R,remote:W,resolved:D})):D=W,m&&Se.add(m),L&&Se.add(L),D==="")return null;let V=Q.createTextNode(D);return ie.set(V,{base:null,local:m?m.nodes:null,remote:L?L.nodes:null}),R?ze({kind:"insert",el:V,source:W&&R===W?"both":"local"}):it({kind:"insert",el:V,source:"remote"}),V}function ee(m,L){let R={ignored:r,remoteWins:n.remoteWins,inlineCache:xt},W=se=>c(se).every(pe=>Ee(pe)?hn(pe,R):pe.kind==="text"),D=null;if(W(m)&&W(L)){let se=m.textContent,pe=L.textContent;se===pe||B(pe,se)?D=L:B(se,pe)&&(D=m)}if(!D){let se=Ke==="local",pe=we(se?m:L,se?"local":"remote",!0),ue=ie.get(pe);return se?ue.remote=L:ue.local=m,w({kind:"structure",el:pe,detail:"insert-collision",local:m,remote:L,resolved:se?m:L}),pe}let V=m.namespaceURI&&m.namespaceURI!=="http://www.w3.org/1999/xhtml"?Q.createElementNS(m.namespaceURI,m.tagName):Q.createElement(m.tagName);O(null,m,L,V),ie.set(V,{base:null,local:m,remote:L}),Se.add(m),Se.add(L);let G=bo({base:Array.from(D.childNodes),local:Array.from(m.childNodes),remote:Array.from(L.childNodes),out:Q,policy:Ke,idOf:{local:T,remote:u},ignored:r,ignoreAttribute:n.ignoreAttribute,remoteWins:n.remoteWins,provenance:ie,textMappers:me,conflicts:ot,decisions:Ie,node:V});kt.push(...G.segments);for(let se of G.nodes)V.appendChild(se);return V}function we(m,L,R=!1){if(!R&&Ee(m)){let G=E.partner.get(m);if(G)return st(m,L,G)}if(!Ee(m)){if(m.value==="")return null;let G=m.kind==="comment"?Q.createComment(m.value):Q.createTextNode(m.value);return ie.set(G,{base:null,local:L==="local"?m.nodes:null,remote:L==="remote"?m.nodes:null}),Se.add(m),G}let W=m.namespaceURI&&m.namespaceURI!=="http://www.w3.org/1999/xhtml"?Q.createElementNS(m.namespaceURI,m.tagName):Q.createElement(m.tagName);for(let G of m.attributes)G.namespaceURI?W.setAttributeNS(G.namespaceURI,G.name,G.value):W.setAttribute(G.name,G.value);ie.set(W,{base:null,local:L==="local"?m:null,remote:L==="remote"?m:null}),Se.add(m);let D=m.tagName==="TEMPLATE"&&W.content?W.content:W,V=L==="local"?F:H;for(let G of c(m)){let se=Ee(G)?V.reverse.get(G):null;if(se&&at.has(se)){w({kind:"structure",el:null,detail:"both-moved",base:se});continue}if(se&&!Ge.has(se)){let ue=F.map.get(se)||null,ge=H.map.get(se)||null;if(ue||ge){let Pe=g(se,ue,ge,!1);L==="local"?ze({kind:"move",el:Pe,source:"local"}):it({kind:"move",el:Pe,source:"remote"}),D.appendChild(Pe);continue}}let pe=we(G,L);pe&&D.appendChild(pe)}return W}function et(m,L,R,W,D){L&&F.identical.has(m)&&F.pairIdenticalChildren(m),R&&H.identical.has(m)&&H.pairIdenticalChildren(m);let V=i(F,L,m,W),G=i(H,R,m,!1),se=c(m),pe=new Set(se),ue=new Map;for(let K=0;K<se.length;K++)ue.set(se[K],K);let ge=[],Pe=new Set,He=new Map,At=new Set,de=new Set,$e=[];Wn();let xe=K=>{let Te=[];for(let he of K.units){if(de.has(he))continue;let Oe=K.baseOf(he);Oe&&pe.has(Oe)&&Te.push(ue.get(Oe))}return Te},Lt=K=>K.every((Te,he)=>he===0||Te>=K[he-1]),Tt=!V.asBase&&!Lt(xe(V)),Ot=!G.asBase&&!Lt(xe(G));Tt&&Ot&&w({kind:"structure",el:null,detail:"both-reordered",base:m});let ht=Ot||!Tt?{V:G,A:H,side:"remote",other:V,otherA:F,otherSide:"local"}:{V,A:F,side:"local",other:G,otherA:H,otherSide:"remote"};Tt?ze({kind:"move",el:null,source:Ot?"both":"local",base:m}):Ot&&it({kind:"move",el:null,source:"remote",base:m});let On=V.asBase?[]:V.units.filter(K=>!V.baseOf(K)&&!de.has(K)&&!E.partner.has(K)),Ln=G.asBase?[]:G.units.filter(K=>!G.baseOf(K)&&!de.has(K)&&!E.partner.has(K)),tn=new Map;if(On.length&&Ln.length){let K=new Map,Te=new Map;for(let ne of Ln){if(Ee(ne)){let te=u(ne);te&&K.set(te,ne)}let Ae=l.unitHash(ne);Te.has(Ae)||Te.set(Ae,[]),Te.get(Ae).push(ne)}let he=(ne,Ae)=>{let te=ne.units.indexOf(Ae);for(let Le=te-1;Le>=0;Le--){let Ue=ne.baseOf(ne.units[Le]);if(Ue)return Ue}return"start"},Oe=new Map,Ve=new Map;for(let ne of Ln){let Ae=he(G,ne);Ee(ne)?(Ve.has(Ae)||Ve.set(Ae,[]),Ve.get(Ae).push(ne)):ne.kind==="text"&&!Oe.has(Ae)&&Oe.set(Ae,ne)}for(let ne of On){let Ae=null;if(Ee(ne)){let te=T(ne);te&&K.has(te)&&!tn.has(K.get(te))&&(Ae=K.get(te))}else if(ne.kind==="text"){let te=Oe.get(he(V,ne));te&&!tn.has(te)&&(Ae=te)}if(!Ae){let te=Te.get(l.unitHash(ne));te&&(Ae=te.find(Le=>!tn.has(Le)&&Ee(Le)===Ee(ne)&&(Ee(Le)?Le.tagName===ne.tagName:Le.kind===ne.kind))||null)}if(!Ae&&Ee(ne)){let te=b.local(ne),Le=(Ve.get(he(V,ne))||[]).filter(Ue=>{let Ct=b.remote(Ue);return!tn.has(Ue)&&Ue.tagName===ne.tagName&&!(te&&Ct&&te!==Ct)&&l.similar(ne,Ue)});Le.length===1&&(Ae=Le[0])}Ae&&(tn.set(Ae,ne),tn.set(ne,Ae))}}let Gt=K=>{if(Se.has(K))return He.get(K)||null;let Te=V.twin(K),he=G.twin(K),Oe=Te&&!V.asBase&&!V.here(Te),Ve=he&&!G.asBase&&!G.here(he);if(Oe||Ve){if((!Te||!he)&&w({kind:"structure",el:null,detail:"move-beats-delete",base:K}),!jt(K))return Se.add(K),null;w({kind:"structure",el:null,detail:"both-moved",base:K})}if(!Te&&!he)return Se.add(K),it({kind:"remove",source:"both",base:K}),null;if(!Te&&!k(K,he,H))return Se.add(K),ze({kind:"remove",source:"local",base:K}),null;if(!he&&!k(K,Te,F))return Se.add(K),it({kind:"remove",source:"remote",base:K}),null;let ne=!Te||!he,Ae=V.asBase?F.map.get(K)||null:Te,te;return Ee(K)?te=g(K,Ae,he,V.asBase):K.kind==="comment"?te=wt(K,Ae,he,V.asBase):te=S(K,Ae,he,V.asBase),Se.add(K),te&&(He.set(K,te),Te&&He.set(Te,te),he&&He.set(he,te),ne&&(w({kind:"structure",el:te,detail:"edit-beats-delete",base:K}),Te?ze({kind:"insert",el:te,source:"local"}):it({kind:"insert",el:te,source:"remote"}))),te},pn=(K,Te,he,Oe)=>{if(Se.has(K))return He.get(K)||null;let Ve=Te.baseOf(K);if(Ve&&pe.has(Ve))return de.has(Ve)&&!de.has(K)?jn(Ve,K,Oe):Gt(Ve);if(Ve)return _n(Ve,K,Oe);let ne=tn.get(K);if(ne){let te=Oe==="local"?K:ne,Le=Oe==="local"?ne:K,Ue;return Ee(te)?l.unitHash(te)===l.unitHash(Le)?(Ue=we(te,"local"),ie.get(Ue).remote=Le):Ue=ee(te,Le):Ue=J(te,Le),Se.add(te),Se.add(Le),Ue&&(He.set(te,Ue),He.set(Le,Ue),Ee(te)&&ze({kind:"insert",el:Ue,source:"both"})),Ue}let Ae=we(K,Oe);return Ae&&(He.set(K,Ae),Oe==="local"?ze({kind:"insert",el:Ae,source:"local"}):it({kind:"insert",el:Ae,source:"remote"})),Ae},jn=(K,Te,he)=>{let Oe;return Ee(K)?(Oe=ft(K,he,Te),Oe&&Se.add(Te)):(Oe=we(Te,he),Se.add(Te),Oe&&(he==="local"?ze:it)({kind:"insert",el:Oe,source:he})),Oe&&He.set(Te,Oe),Oe},_n=(K,Te,he)=>{let Ve=(he==="local"?H:F).map.get(K),ne=Te,Ae=Ve?Nt(Ve,he==="local"?R:L,he==="local"?H:F):!1,te=Ve&&!Ae&&!St(K,Ve);if(te&&he===ht.otherSide)return w({kind:"structure",el:null,detail:"both-moved",base:K}),null;if(te&&w({kind:"structure",el:null,detail:"both-moved",base:K}),Ve||w({kind:"structure",el:null,detail:"move-beats-delete",base:K}),Ge.has(K)){w({kind:"structure",el:null,detail:"both-moved",base:K});let Ue=we(ne,he);return Ue&&He.set(Te,Ue),Ue}let Le=Ee(K)?g(K,he==="local"?ne:F.map.get(K)||null,he==="remote"?ne:H.map.get(K)||null,!1):null;return Le&&(He.set(K,Le),He.set(Te,Le),Ve&&He.set(Ve,Le),he==="local"?ze({kind:"move",el:Le,source:"local"}):it({kind:"move",el:Le,source:"remote"})),Le};for(let K of ht.V.units){if(de.has(K)){let he=He.get(K);Pe.has(he)||(ge.push(he),Pe.add(he));continue}if(Se.has(K)&&!(He.get(K)&&Pe.has(He.get(K)))){let he=ht.V.baseOf(K);he&&!pe.has(he)&&w({kind:"structure",el:null,detail:"both-moved",base:he});continue}let Te=pn(K,ht.V,ht.A,ht.side);Te&&!Pe.has(Te)&&(ge.push(Te),Pe.add(Te),!ht.V.baseOf(K)&&!tn.has(K)&&!de.has(K)&&At.add(Te))}for(let K of $e)Pe.has(K.frag)||(ge.splice(Vn(K.at),0,K.frag),Pe.add(K.frag));if(!ht.other.asBase){let K=ht.other,Te=ht.otherSide,he=ht.otherA,Oe=null,Ve=0,ne=null;for(let Ae of K.units){let te=He.get(Ae);if(te&&Pe.has(te)){Oe=te,ne=null;continue}if(Se.has(Ae)){let Ct=K.baseOf(Ae);Ct&&!pe.has(Ct)&&w({kind:"structure",el:null,detail:"both-moved",base:Ct});continue}let Le=pn(Ae,K,he,Te);if(!Le)continue;let Ue;if(ne)Ue=ge.indexOf(ne)+1;else if(Oe){if(Ue=ge.indexOf(Oe)+1,Te==="remote")for(;Ue<ge.length&&At.has(ge[Ue]);)Ue++}else Ue=Ve++;ge.splice(Ue,0,Le),Pe.add(Le),ne=Le}}for(let K=0;K<se.length;K++){let Te=se[K];if(Se.has(Te))continue;let he=Gt(Te);he&&ge.splice(Vn(K),0,he)}return ge;function Vn(K){for(let Te=K-1;Te>=0;Te--){let he=He.get(se[Te]);if(he){let Oe=ge.indexOf(he);if(Oe>=0)return Oe+1}}return 0}function mn(K){let Te={ignored:r,remoteWins:()=>!1},he=q=>K(q)||Ee(q)&&n.remoteWins(q)&&nn.has(q.tagName)&&hn(q,Te),Oe=new Map,Ve=q=>{if(!Ee(q)||!ar.has(q.tagName))return!1;let ae=Oe.get(q);return ae===void 0&&(ae=!r(q)&&!n.remoteWins(q)&&c(q).every(he),Oe.set(q,ae)),ae},ne=q=>!Ee(q)&&q.kind==="text",Ae=null,te=new Map,Le=q=>{let ae=te.get(q);if(ae)return ae;let be=Ee(q)?q.textContent:q.value;ae=new Set;let Re=be.toLowerCase();if(!(be.length>Yo))if(/^[\x00-\x7f]*$/.test(Re))for(let ve of Re.split(/[^\p{L}\p{N}]+/u))ve&&ae.add(ve);else for(let ve of fo(Re))/^[\s\p{P}]+$/u.test(ve)||ae.add(ve);return te.set(q,ae),ae},Ue=q=>(Ee(q)?q.textContent:q.value).toLowerCase().replace(/\s+/g," ").trim(),Ct=new Map,$t=q=>{let ae=Ct.get(q);if(ae)return ae;ae=new Set(Le(q));let be=ve=>{if(ve)for(let qe of Le(ve))ae.add(qe)},Re=pe.has(q)?q:!V.asBase&&V.baseOf(q)||!G.asBase&&G.baseOf(q);return Re&&(be(Re),be(F.map.get(Re)),be(H.map.get(Re))),Ct.set(q,ae),ae},on=(q,ae)=>{let be=Ue(ae),Re=pe.has(q)?q:!V.asBase&&V.baseOf(q)||!G.asBase&&G.baseOf(q),ve=dt=>be?dt.split(be).length-1:0;if(Re&&Ee(ae)&&!pe.has(ae)){let dt=ve(Ue(Re));for(let pt of[F.map.get(Re),H.map.get(Re)]){if(!pt||pt===ae||pt.ownerDocument!==ae.ownerDocument)continue;let zt=Ue(pt);if(zt.length>be.length&&ve(zt)>=dt&&(zt.startsWith(be)||zt.endsWith(be)))return!1}}let qe=Le(ae),tt=$t(q),Rt=0;for(let dt of qe)tt.has(dt)&&Rt++;if(qe.size&&Rt*2>=qe.size)return!0;if(!be||be.length>Yo)return!1;let Ut=Re?[q,Re,F.map.get(Re),H.map.get(Re)]:[q],Ft=(dt,pt)=>dt!==pt&&(dt.startsWith(pt)||dt.endsWith(pt));if(Ut.some(dt=>dt&&Ft(Ue(dt),be)))return!0;if(!pe.has(ae)||!Re)return!1;let vt=Ue(q),Kt=Ue(Re);return[F.map.get(ae),H.map.get(ae)].some(dt=>{let pt=dt&&Ue(dt);return!!pt&&vt!==pt&&(vt.startsWith(pt)&&!Kt.startsWith(pt)||vt.endsWith(pt)&&!Kt.endsWith(pt))})},Pt=q=>{Ae||(Ae=new Set),Ae.add(q)},cn=q=>{Pt(q);for(let[ae,be]of[[F,V],[H,G]]){if(be.asBase)continue;let Re=ae.map.get(q);Re&&be.here(Re)&&Pt(Re)}},Be=(q,ae)=>q.asBase||se.every(be=>!Ee(be)||ae.identical.has(be)&&q.here(ae.map.get(be)))&&q.units.every(be=>!Ee(be)||q.baseOf(be));if(Be(V,F)&&Be(G,H))return null;let We=q=>{if(q.asBase)return!1;let ae=-1;for(let be of q.units){let Re=Ee(be)?q.baseOf(be):null;if(!Re||!pe.has(Re))continue;let ve=ue.get(Re);if(ve<ae)return!0;ae=ve}return!1};if(We(V)||We(G))return null;for(let[q,ae]of[[V,F],[G,H]]){if(q.asBase||Be(q,ae))continue;let be=q.units,Re=ae===F?b.local:b.remote,ve=(ce,Fe)=>{let ct=Ee(ce)&&b.base(ce),Ze=Ee(Fe)&&Re(Fe);return!ct||!Ze||ct===Ze},qe=new Map;for(let ce=0;ce<be.length;ce++)qe.set(be[ce],ce);let tt=ce=>!!ce&&(Ee(ce)?q.here(ce):qe.has(ce)),Rt=ce=>{let Fe=q.twin(ce);return tt(Fe)?Fe:null},Ut=se.filter(ce=>!q.twin(ce)&&Ve(ce)),Ft=be.filter(ce=>!q.baseOf(ce)&&Ve(ce)),vt=(ce,Fe)=>Fe===se?!!Rt(ce):pe.has(q.baseOf(ce)),Kt=ce=>{let Fe=new Int32Array(ce.length),ct=new Int32Array(ce.length),Ze=-1;for(let Ye=0;Ye<ce.length;Ye++)Fe[Ye]=Ze,vt(ce[Ye],ce)&&(Ze=Ye);Ze=ce.length;for(let Ye=ce.length-1;Ye>=0;Ye--)ct[Ye]=Ze,vt(ce[Ye],ce)&&(Ze=Ye);return{prev:Fe,next:ct}},dt=Kt(be),pt=Kt(se),zt=(ce,Fe)=>{cn(ce),Pt(Fe)};for(let ce of Ft){let Fe=qe.get(ce),ct=dt.prev[Fe],Ze=dt.next[Fe],Ye=ct>=0?q.baseOf(be[ct]):null,Qt=Ze<be.length?q.baseOf(be[Ze]):null,Yt=Ye?ue.get(Ye):-1,ln=Qt?ue.get(Qt):se.length;for(let qt=Math.max(0,Yt);qt<=Math.min(ln,se.length-1);qt++){let Dt=se[qt];(Ve(Dt)||ne(Dt))&&(!ve(Dt,ce)||!on(Dt,ce)||(ne(Dt)?Pt(ce):zt(Dt,ce)))}}let Xt=(ce,Fe,ct)=>{for(let Ze=Fe+ct;Ze>=0&&Ze<ce.length;Ze+=ct){let Ye=ce[Ze];if(Ve(Ye))return Ye;if(Ee(Ye)||Ye.value.trim())return null}return null},Fn=ce=>{let Fe=new Set;for(let ct of c(ce))if(!Ee(ct)&&ct.kind==="text")for(let Ze of Le(ct))Fe.add(Ze);return Fe},Cn=(ce,Fe)=>{let ct=Le(Fe),Ze=new Set;for(let Ye of Fn(ce))ct.has(Ye)||Ze.add(Ye);return Ze},En=(ce,Fe)=>{if(!ce.size)return!1;let ct=Le(Fe),Ze=0;for(let Ye of ce)ct.has(Ye)&&Ze++;return Ze*2>=ce.size};for(let ce of se){if(ae.identical.has(ce)||!Ve(ce))continue;let Fe=Rt(ce);if(!Fe||!Ve(Fe))continue;let ct=Cn(Fe,ce),Ze=Cn(ce,Fe);for(let Ye of[-1,1]){let Qt=Xt(se,ue.get(ce),Ye);Qt&&En(ct,Qt)&&(zt(ce,Fe),cn(Qt));let Yt=Xt(be,qe.get(Fe)??-1,Ye);if(Yt&&En(Ze,Yt)){zt(ce,Fe);let ln=q.baseOf(Yt);ln?zt(ln,Yt):Pt(Yt)}}}for(let ce of Ut){let Fe=ue.get(ce),ct=pt.prev[Fe],Ze=pt.next[Fe],Ye=ct>=0?Rt(se[ct]):null,Qt=Ze<se.length?Rt(se[Ze]):null,Yt=Ye?qe.get(Ye)??-1:-1,ln=Qt?qe.get(Qt)??-1:be.length;for(let qt=Math.max(0,Yt);qt<=Math.min(ln,be.length-1);qt++){let Dt=be[qt];if((Ve(Dt)||ne(Dt))&&!(!ve(ce,Dt)||!on(Dt,ce))&&(cn(ce),!ne(Dt))){let Vt=q.baseOf(Dt);Vt?zt(Vt,Dt):Pt(Dt)}}}}if(!Ae)return null;for(let q of Array.from(Ae))if(pe.has(q))for(let ae of[F,H]){let be=ae.map.get(q);be&&be.parentNode!==(ae===F?L:R)&&!(ae===F?V:G).asBase&&Ae.delete(q)}return Ae.size?Ae:null}function Wn(){if((V.asBase||F.identical.has(m))&&(G.asBase||H.identical.has(m)))return;let K={ignored:r,remoteWins:n.remoteWins,inlineCache:xt},Te=Be=>Ee(Be)?hn(Be,K):Be.kind==="text",he=mn(Te),Oe=Be=>he&&he.has(Be)||Te(Be),Ve=se.map(Oe);if(!Ve.includes(!0))return;let ne=Be=>{let We=Be.units,q=new Map;for(let tt=0;tt<We.length;tt++)q.set(We[tt],tt);let ae=[],be=-1;for(let tt=0;tt<se.length;tt++){if(Ve[tt])continue;let Rt=Be.twin(se[tt]),Ut=Rt?q.get(Rt):void 0;Ut===void 0||Ut<=be||Oe(Rt)||(ae.push([tt,Ut]),be=Ut)}let Re=[],ve=-1,qe=-1;for(let tt=0;tt<=ae.length;tt++){let[Rt,Ut]=tt<ae.length?ae[tt]:[se.length,We.length],Ft={bLo:-1,bHi:-1,sLo:-1,sHi:-1,next:Ut};for(let vt=ve+1;vt<Rt;vt++)Ve[vt]&&(Ft.bLo<0&&(Ft.bLo=vt),Ft.bHi=vt);for(let vt=qe+1;vt<Ut;vt++)Oe(We[vt])&&(Ft.sLo<0&&(Ft.sLo=vt),Ft.sHi=vt);Re.push(Ft),ve=Rt,qe=Ut}return{units:We,list:Re}},Ae=ne(V),te=ne(G),Le=[];for(let Be of[Ae,te])for(let We of Be.list)We.bLo>=0&&Le.push([We.bLo,We.bHi]);Le.sort((Be,We)=>Be[0]-We[0]);let Ue=[];for(let[Be,We]of Le){let q=Ue[Ue.length-1];q&&Be<=q.hi?q.hi=Math.max(q.hi,We):Ue.push({lo:Be,hi:We})}let Ct=(Be,We)=>{let q=-1,ae=-1;for(let ve=0;ve<Be.list.length;ve++){let qe=Be.list[ve];qe.bLo<We.lo||qe.bLo>We.hi||(q<0&&(q=ve),ae=ve)}let be=1/0,Re=-1;for(let ve=q;ve>=0&&ve<=ae;ve++){let qe=Be.list[ve];qe.sLo>=0&&(be=Math.min(be,qe.sLo),Re=Math.max(Re,qe.sHi)),ve<ae&&(be=Math.min(be,qe.next),Re=Math.max(Re,qe.next))}return Re<0?[]:Be.units.slice(be,Re+1)},$t=(Be,We)=>Be.length===We.length&&Be.every((q,ae)=>l.unitHash(q)===l.unitHash(We[ae])),on=Be=>!Ee(Be)&&Be.kind==="comment",Pt=Be=>{if(!Be.length)return[];let We=(ve,qe)=>Ee(ve)?ve:ve.nodes[qe?ve.nodes.length-1:0],q=We(Be[0]),ae=We(Be[Be.length-1],!0),be=ve=>ve&&Ee(ve)&&r(ve);for(;be(q.previousSibling);)q=q.previousSibling;for(;be(ae.nextSibling);)ae=ae.nextSibling;let Re=[];for(let ve=q;ve&&(Re.push(ve),ve!==ae);ve=ve.nextSibling);return Re},cn=Be=>Be.some(We=>Ee(We)&&r(We));for(let Be of Ue){let We=se.slice(Be.lo,Be.hi+1),q=V.asBase?null:Ct(Ae,Be),ae=G.asBase?null:Ct(te,Be);if(We.some(on)||q&&q.some(on)||ae&&ae.some(on))continue;let be=Pt(q||We),Re=Pt(ae||We);if((!q||$t(We,q))&&(!ae||$t(We,ae))&&!(q&&cn(be)))continue;let ve=bo({base:Pt(We),local:be,remote:Re,out:Q,policy:Ke,blocks:he,L:q?F:Jo(F,m),R:ae?H:Jo(H,m),idOf:{local:T,remote:u},ignored:r,ignoreAttribute:n.ignoreAttribute,remoteWins:n.remoteWins,mergeElement:(tt,Rt,Ut)=>g(tt,Rt,Ut,!1),cloneUnit:we,mergeAttrs:O,atomKey:l.unitHash,moveIn:ft,provenance:ie,textMappers:me,conflicts:ot,decisions:Ie,node:D});kt.push(...ve.segments);let qe=Q.createDocumentFragment();for(let tt of ve.nodes)qe.appendChild(tt);for(let tt of[...We,...q||[],...ae||[]])Se.add(tt),de.add(tt),He.set(tt,qe);$e.push({frag:qe,at:Be.lo})}}}function yt(m,L){let R=ie.get(m);return R&&R.unchanged?!0:m.tagName!==L.tagName||!fe(m,L)?!1:Qe(ut(m),ut(L))}function ut(m){return m.tagName==="TEMPLATE"&&m.content?m.content:m}function fe(m,L){let R=0;for(let W of m.attributes)if(!n.ignoreAttribute(m,W.name)&&(R++,L.getAttribute(W.name)!==W.value))return!1;for(let W of L.attributes)n.ignoreAttribute(L,W.name)||R--;return R===0}function Qe(m,L){let R=Et(m,D=>{let V=ie.get(D);return!!(V&&V.pinned)}),W=Et(L,r);if(R.length!==W.length)return!1;for(let D=0;D<R.length;D++){let V=R[D],G=W[D];if(typeof V=="string"||typeof G=="string"){if(V!==G)return!1}else{if(V.nodeType!==G.nodeType)return!1;if(V.nodeType===1){if(!yt(V,G))return!1}else if(V.nodeValue!==G.nodeValue)return!1}}return!0}function Et(m,L){let R=[],W=null;for(let D=m.firstChild;D;D=D.nextSibling){if(D.nodeType===3){W=W===null?D.nodeValue:W+D.nodeValue;continue}D.nodeType===1&&L(D)||(W!==null&&(W!==""&&R.push(W),W=null),R.push(D))}return W!==null&&W!==""&&R.push(W),R}function wt(m,L,R,W){let D=m.value,V=W?D:L?L.value:"",G=R?R.value:"";Se.add(m),L&&Se.add(L),R&&Se.add(R);let se=V===G?V:V===D?G:G===D||Ke==="local"?V:G;if(V!==D&&G!==D&&V!==G&&w({kind:"text",node:null,base:D,local:V,remote:G,resolved:se}),!L&&!R)return null;let pe=Q.createComment(se);return ie.set(pe,{base:m.nodes,local:L?L.nodes:null,remote:R?R.nodes:null}),pe}function Bt(m,L){let R=L.map.get(m);if(!R)return null;let W=Ee(R)?R.parentNode:R.parent,D=Ee(m)?m.parentNode:m.parent;return L.map.get(D)===W?null:L.reverse.get(W)||null}function jt(m){let L=new Set([m]),R=m;for(let W=0;W<64;W++){let D=Bt(R,F)||Bt(R,H);if(!D)return!1;if(D===m||Ee(m)&&Ee(D)&&m.contains(D)||L.has(D))return!0;L.add(D),R=D}return!0}function Nt(m,L,R){if(!L)return!1;let W=Ee(m)?m.parentNode:m.parent;return W===L||L.tagName==="TEMPLATE"&&W===L.content}function St(m,L){let R=Ee(m)?m.parentNode:m.parent,W=Ee(L)?L.parentNode:L.parent;return!!(F.map.get(R)===W?F:H.map.get(R)===W?H:null)}}function Jo(e,s){return e.map.get(s)?Xo():{map:{get:n=>n&&n.nodeType===1&&e.map.get(n)||n,has:()=>!0},reverse:{get:n=>e.reverse.get(n)||n,has:()=>!0},moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}function Xo(){let e={get:s=>s,has:()=>!0};return{map:e,reverse:e,moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}var Qo=new Set(["INPUT","OPTION","TEXTAREA"]);function Zo(e,s,o,n){let r=e.ownerDocument,{provenance:l,textMappers:c}=o,f=n.hooks,d=[],M=[],N=[],y=new Set,T=[],u=[],b=new Set,x=new Map,P=i=>!!i&&(i===e||e.contains(i)||e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content.contains(i)),v=new Map,j=new Map,Y=new Map,le=new Map;(function i(k){let g=l.get(k);if(g){if(k.nodeType===1){let I=g.local?n.toLive(g.local):null;I&&P(I)&&I.nodeType===1&&(v.set(k,I),j.set(I,k))}else if(Array.isArray(g.local)){let I=F(g.local,g.local.map(O=>n.toLive(O)).filter(O=>O&&P(O)&&O.nodeType===k.nodeType));if(I.length&&(v.set(k,I[0]),j.set(I[0],k),Y.set(k,I)),Array.isArray(g.caret))for(let O of g.caret){let U=n.toLive(O.node);if(!U||!P(U)||U.nodeType!==3)continue;let S=le.get(U);Array.isArray(S)||le.set(U,S=[]),S.push({merged:k,from:O.from,to:O.to,flatStart:O.flatStart})}else{let O=0;for(let U of I)le.set(U,{merged:k,shift:O}),O+=U.nodeValue.length}}}let _=k.nodeType===1&&k.tagName==="TEMPLATE"&&k.content?k.content.childNodes:k.childNodes;for(let I of _)i(I)})(s);let Ne=new Set;for(let i of v.values())Ne.add(i);for(let i of Y.values())for(let k of i)Ne.add(k);for(let i of o.segments||[])H(i);let ye=n.restoreFocus===!1?null:fr(r,le);n.childrenOnly?Ie(Q(e),Q(s)):ie(e,s);for(let{node:i,parent:k}of T)y.has(i)||!i.parentNode||i.nodeType===1&&(n.ignored(i)||ot(i))||it(i,k);return ur(r,ye,le,c,Y,x),{applied:d,moved:M,replaced:N,identities:u,mergedScriptsLive:b,liveOf:v};function De(i,k){let g=i.slice(k.bs,k.be),_=0;for(;_<g.length&&_<k.text.length&&g[_]===k.text[_];)_++;let I=0;for(;I<g.length-_&&I<k.text.length-_&&g[g.length-1-I]===k.text[k.text.length-1-I];)I++;return{bs:k.bs+_,be:k.be-I,text:k.text.slice(_,k.text.length-I)}}function F(i,k){if(!k.length)return k;let g=new Set;for(let I of i){let O=I.parentNode;if(O)for(let U=O.firstChild;U;U=U.nextSibling)U.nodeType===3&&g.add(n.toLive(U))}let _=[];for(let I of k){_.push(I);for(let O=I.nextSibling;O&&O.nodeType===3&&!g.has(O)&&!_.includes(O);O=O.nextSibling)_.push(O)}return _}function H(i){let k=[];for(let fe of i.localNodes){let Qe=n.toLive(fe.node);if(!Qe||!P(Qe)||Qe.nodeType!==3)return;k.push(Qe)}let g=F(i.localNodes.map(fe=>fe.node),k);if(!g.length)return;let _=g.map(fe=>fe.nodeValue).join(""),{flatLocal:I,lToM:O,mapLocal:U}=i;if(_===I)return;let S=i.textNodes.map(fe=>({node:fe.node,ms:fe.ms,me:fe.me})),B=[],J=0;for(let fe of g)B.push(J),J+=fe.nodeValue.length;let ee=(fe,Qe)=>g.find((Et,wt)=>B[wt]<=fe&&fe+Qe<=B[wt]+Et.nodeValue.length)||null,we=[],et=0;for(let fe of wn(I,_).map(Qe=>De(I,Qe))){let Qe=fe.bs+et;et+=fe.text.length-(fe.be-fe.bs);let Et,wt;if(fe.be>fe.bs){Et=O[fe.bs];let Bt=Et>=0;for(let jt=fe.bs;Bt&&jt<fe.be;jt++)O[jt]!==Et+(jt-fe.bs)&&(Bt=!1);if(!Bt)continue;wt=Et+(fe.be-fe.bs)}else{let Bt=fe.bs>0?O[fe.bs-1]:0,jt=fe.bs<I.length?O[fe.bs]:0;if(Bt<0||jt<0)continue;Et=wt=U(fe.bs)}we.push({ms:Et,me:wt,text:fe.text,live:wt===Et?ee(Qe,fe.text.length):null})}we.sort((fe,Qe)=>Qe.ms-fe.ms);let yt=(fe,Qe)=>(Y.get(fe.node)||[v.get(fe.node)]).includes(Qe),ut=fe=>!!fe&&fe.nodeType===1&&nn.has(fe.tagName);for(let fe of we){let Qe=S.find(wt=>wt.ms<=fe.ms&&fe.me<=wt.me&&fe.ms<wt.me);if(Qe&&fe.live&&Qe.ms===fe.ms&&!yt(Qe,fe.live)){let wt=S.find(Bt=>Bt.me===fe.ms&&yt(Bt,fe.live));wt&&(Qe=wt)}if(!Qe&&fe.me===fe.ms){let wt=S.find(St=>St.me===fe.ms),Bt=S.find(St=>St.ms===fe.ms),jt=wt||Bt;if(!jt)continue;let Nt=jt.node;for(;ut(Nt.parentNode)&&(wt?Nt.parentNode.lastChild:Nt.parentNode.firstChild)===Nt;)Nt=Nt.parentNode;if(Nt===jt.node)Qe=jt;else{let St=Nt.ownerDocument.createTextNode(fe.text);Nt.parentNode.insertBefore(St,wt?Nt.nextSibling:Nt);continue}}if(!Qe)continue;let Et=Qe.node.nodeValue;Qe.node.nodeValue=Et.slice(0,fe.ms-Qe.ms)+fe.text+Et.slice(fe.me-Qe.ms),Qe.me+=fe.text.length-(fe.me-fe.ms)}}function Q(i){return i.nodeType===1&&i.tagName==="TEMPLATE"&&i.content?i.content:i}function ie(i,k){y.add(i);let g=l.get(k);if(g&&g.remote&&o.remoteIdOf){let I=o.remoteIdOf(g.remote);I&&u.push([i,I])}if(g&&g.unchanged){o.customIdentity&&g.remote&&at(i,g.remote),g.remote&&Se(i,g.remote);return}if(f.beforeNodeMorphed(i,k)===!1)return;oe(i,k);let _=i.tagName;if(_t(i))i.textContent!==k.textContent&&(d.push({kind:"text",node:i,before:i.textContent,after:k.textContent}),i.textContent=k.textContent),o.mergedScripts.has(k)&&b.add(i);else if(_==="TEXTAREA")ft(i,k,g);else{Xe(i,k,g);let I=_==="TEMPLATE"&&i.content?i.content:i,O=_==="TEMPLATE"&&k.content?k.content:k;n.protectFocusedValue==="subtree"&&Me(i)&&i!==r.body?me(I):Ie(I,O)}f.afterNodeMorphed(i,k)}function me(i){for(let k=i.firstChild;k;k=k.nextSibling){let g=j.get(k);g&&v.get(g.parentNode)!==i||(y.add(k),k.nodeType===1&&me(k))}}function Ie(i,k){let g=Ke(i.firstChild),_=new Set;for(let I of Array.from(k.childNodes)){let O=v.get(I);O&&y.has(O)&&!_.has(O)&&(O=null);let U=l.get(I);if(U&&U.pinned){O&&O.nodeType===1&&((O.parentNode!==i||Ke(O.nextSibling)!==g)&&ze(i,O,g),y.add(O),_.add(O));continue}if(O&&O.nodeType===1){if(O!==g){let J=O.parentNode;if(J===i&&g&&st(O)){let ee=O.nextSibling;for(let we=g;we&&we!==O;){let et=we.nextSibling;ze(i,we,ee),we=et}}else ze(i,O,g),J!==i&&(M.push(O),d.push({kind:"move",el:O,from:J,to:i}))}_.add(O),ie(O,I),g=Ke(O.nextSibling);continue}if(O&&O.nodeType!==1){let J=Y.get(I)||[O];O!==g&&ze(i,O,g);let ee=I.nodeValue;if(I.nodeType===3){let we=bt(I),et=J.map(yt=>yt.nodeValue).join("");we!=null&&et!==we&&(ee=yn(we,et,I.nodeValue).text)}f.beforeNodeMorphed(O,I)!==!1&&(O.nodeValue!==ee&&(d.push({kind:"text",node:O,before:O.nodeValue,after:ee}),O.nodeValue=ee),f.afterNodeMorphed(O,I)),y.add(O),_.add(O),x.set(I,O),g=Ke(O.nextSibling);continue}if(I.nodeType===3&&g&&g.nodeType===3&&!y.has(g)&&!le.has(g)){g.nodeValue!==I.nodeValue&&(d.push({kind:"text",node:g,before:g.nodeValue,after:I.nodeValue}),g.nodeValue=I.nodeValue),y.add(g),x.set(I,g),g=Ke(g.nextSibling);continue}let S=l.get(I),B=w(S&&S.unchanged&&S.remote?S.remote:I);f.beforeNodeAdded(B)!==!1&&(i.insertBefore(B,g),y.add(B),B.nodeType===3&&x.set(I,B),B.nodeType===1&&(N.push(B),xt(B,I),_t(B)||E(B,I),n.formState==="property"&&Je(S)&&Se(B,S.remote)),g=Ke(B.nextSibling),d.push({kind:"insert",node:B,parent:i}),f.afterNodeAdded(B))}for(let I of Array.from(i.childNodes))y.has(I)||_.has(I)||I.nodeType===1&&(n.ignored(I)||ot(I))||(Ne.has(I)?T.push({node:I,parent:i}):it(I,i))}function ot(i){return n.preserve&&i.parentNode&&i.parentNode.nodeType===1&&i.parentNode.tagName==="HEAD"&&n.preserve(i)===!0}function bt(i){let k=l.get(i);return!k||!Array.isArray(k.local)?null:k.local.map(g=>g.nodeValue).join("")}function kt(i){return l.get(i)}function Se(i,k){if(!Qo.has(i.tagName)&&!i.querySelector("input,option,textarea"))return;let g=(_,I)=>{if(_.tagName!==I.tagName)return;_.tagName==="TEXTAREA"?ft(_,I,{remote:I}):Qo.has(_.tagName)&&Xe(_,I,{remote:I});let O=Ge(_),U=Ge(I);if(O.length===U.length)for(let S=0;S<O.length;S++)g(O[S],U[S])};g(i,k)}function at(i,k){let g=Ge(i),_=Ge(k);if(g.length===_.length)for(let I=0;I<g.length;I++){let O=o.remoteIdOf(_[I]);O&&u.push([g[I],O]),at(g[I],_[I])}}function Ge(i){let k=i.tagName==="TEMPLATE"&&i.content?i.content:i;return Array.from(k.children).filter(g=>!n.ignored(g))}function xt(i,k){if(!o.remoteIdOf)return;let g=(_,I)=>{let O=l.get(I);if(O&&O.remote&&I.nodeType===1){let B=o.remoteIdOf(O.remote);B&&u.push([_,B])}let U=_.childNodes,S=I.childNodes;for(let B=0;B<U.length&&B<S.length;B++)g(U[B],S[B])};g(i,k)}function Ke(i){for(;i&&i.nodeType===1&&n.ignored(i);)i=i.nextSibling;return i}function ze(i,k,g){if(typeof i.moveBefore=="function"&&k.ownerDocument===i.ownerDocument)try{i.moveBefore(k,g);return}catch{}i.insertBefore(k,g)}function it(i,k){f.beforeNodeRemoved(i)!==!1&&(i.parentNode.removeChild(i),d.push({kind:"remove",node:i,parent:k}),f.afterNodeRemoved(i))}function w(i){if(_t(i))return Bn(i,r);let k=r.importNode(i,!0);if(k.nodeType===1)for(let g of Array.from(k.querySelectorAll("script")))_t(g)&&g.replaceWith(Bn(g,r));return k}function E(i,k){let g=i.tagName==="TEMPLATE"&&i.content?i.content:i,_=k.tagName==="TEMPLATE"&&k.content?k.content:k,I=Array.from(g.childNodes),O=Array.from(_.childNodes);for(let U=0;U<O.length&&U<I.length;U++){let S=O[U],B=I[U],J=v.get(S);J&&y.has(J)&&(J=null);let ee=l.get(S);if(ee&&ee.pinned){if(J&&J.nodeType===1){let we=J.parentNode;ze(g,J,B),we!==g&&(M.push(J),d.push({kind:"move",el:J,from:we,to:g})),y.add(J)}B.remove();continue}if(J){let we=J.parentNode;ze(g,J,B),B.remove(),J.nodeType===1?(we!==g&&(M.push(J),d.push({kind:"move",el:J,from:we,to:g})),ie(J,S)):(y.add(J),x.set(S,J),J.nodeValue!==S.nodeValue&&(d.push({kind:"text",node:J,before:J.nodeValue,after:S.nodeValue}),J.nodeValue=S.nodeValue));continue}y.add(B),B.nodeType===3&&x.set(S,B),S.nodeType===1&&!_t(S)&&E(B,S)}}function oe(i,k){for(let g of Array.from(k.attributes)){if(Z(i,g.name)||n.ignoreAttribute(i,g.name))continue;let _=g.namespaceURI?i.getAttributeNS(g.namespaceURI,g.localName):i.getAttribute(g.name);_!==g.value&&f.beforeAttributeUpdated(g.name,i,"update")!==!1&&(g.namespaceURI?i.setAttributeNS(g.namespaceURI,g.name,g.value):i.setAttribute(g.name,g.value),d.push({kind:"attr",el:i,name:g.name,before:_,after:g.value}))}for(let g of Array.from(i.attributes)){if(Z(i,g.name)||n.ignoreAttribute(i,g.name)||(g.namespaceURI?k.hasAttributeNS(g.namespaceURI,g.localName):k.hasAttribute(g.name))||f.beforeAttributeUpdated(g.name,i,"remove")===!1)continue;let I=g.value;g.namespaceURI?i.removeAttributeNS(g.namespaceURI,g.localName):i.removeAttribute(g.name),d.push({kind:"attr",el:i,name:g.name,before:I,after:null})}}function Z(i,k){let g=i.tagName;return g==="INPUT"?k==="value"||k==="checked"||k==="disabled":g==="OPTION"?k==="selected":!1}function Me(i){return i===r.activeElement}function st(i){let k=r.activeElement;return!!k&&k!==r.body&&i.contains(k)}function Je(i){let k=i&&i.remote;return k&&k.nodeType===1?k:null}function Xe(i,k,g){let _=i.tagName,I=Je(g),O=n.formState==="property"&&I?I:k;if(_==="INPUT"){let U=n.protectFocusedValue&&Me(i),S=(i.getAttribute("type")||"").toLowerCase(),B=S!=="file"&&S!=="checkbox"&&S!=="radio",J=I&&I.hasAttribute("value")&&I.value!==I.getAttribute("value")?I.value:null;if(B&&!U)if(n.formState==="property"){let ee=k.getAttribute("value"),we=i.getAttribute("value");(we!==ee||i.value!==O.value)&&f.beforeAttributeUpdated("value",i,ee==null?"remove":"update")!==!1&&(we!==ee&&(ee==null?i.removeAttribute("value"):i.setAttribute("value",ee),d.push({kind:"attr",el:i,name:"value",before:we,after:ee})),i.value!==O.value&&(i.value=O.value))}else if(k.hasAttribute("value")||J!=null){let ee=J??k.getAttribute("value");i.getAttribute("value")!==ee&&f.beforeAttributeUpdated("value",i,"update")!==!1?(i.setAttribute("value",ee),i.value!==ee&&(i.value=ee),d.push({kind:"attr",el:i,name:"value",before:null,after:ee})):i.value!==ee&&i.getAttribute("value")===ee&&(i.value=ee)}else(i.hasAttribute("value")||i.value!=="")&&f.beforeAttributeUpdated("value",i,"remove")!==!1&&(i.removeAttribute("value"),i.value="",d.push({kind:"attr",el:i,name:"value",before:"",after:null}));if(!B&&S!=="file"){let ee=k.getAttribute("value");ee==null?i.hasAttribute("value")&&f.beforeAttributeUpdated("value",i,"remove")!==!1&&i.removeAttribute("value"):i.getAttribute("value")!==ee&&f.beforeAttributeUpdated("value",i,"update")!==!1&&i.setAttribute("value",ee)}U||(nt(i,O,"checked"),n.formState==="property"&&i.indeterminate!==O.indeterminate&&(i.indeterminate=O.indeterminate)),nt(i,O,"disabled")}else if(_==="OPTION"){let U=i.parentNode&&i.closest("select");n.protectFocusedValue&&U&&Me(U)||nt(i,O,"selected")}}function nt(i,k,g){let _=n.formState==="property"?!!k[g]:k.hasAttribute(g);if(n.formState!=="property"){let I=i.hasAttribute(g);if(I!==_){if(f.beforeAttributeUpdated(g,i,_?"update":"remove")===!1)return;_?i.setAttribute(g,""):i.removeAttribute(g),d.push({kind:"attr",el:i,name:g,before:I?"":null,after:_?"":null})}}i[g]!==_&&(i[g]=_)}function ft(i,k,g){if(n.protectFocusedValue&&Me(i)||f.beforeAttributeUpdated("value",i,"update")===!1)return;let _=Je(g),I=k.textContent,O=_&&_.value!==_.defaultValue?_.value:I;n.formState!=="property"&&i.textContent!==I&&(d.push({kind:"text",node:i,before:i.textContent,after:I}),i.textContent=I),i.value!==O&&(i.value=O)}}function fr(e,s){let o=e.activeElement;if(!o||o===e.body||o===e.documentElement)return null;let n={el:o,id:o.getAttribute&&o.getAttribute("id"),scrollTop:o.scrollTop,scrollLeft:o.scrollLeft};if(o.tagName==="INPUT"||o.tagName==="TEXTAREA"){try{n.selection=[o.selectionStart,o.selectionEnd,o.selectionDirection]}catch{}return n}let r=e.getSelection&&e.getSelection();if(r&&r.rangeCount){let l=r.getRangeAt(0);n.range={sc:l.startContainer,so:l.startOffset,ec:l.endContainer,eo:l.endOffset}}return n}function ur(e,s,o,n,r,l){if(!s)return;let c=s.el;if(!c.isConnected&&s.id&&(c=e.getElementById(s.id)),!c||!c.isConnected)return;if(e.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}try{c.scrollTop=s.scrollTop,c.scrollLeft=s.scrollLeft}catch{}if(s.selection){try{c.setSelectionRange&&!c.selectionEnd&&s.selection[1]!=null&&c.setSelectionRange(s.selection[0],s.selection[1],s.selection[2]||"none")}catch{}return}if(!s.range)return;let f=(N,y)=>{let T=o.get(N);if(Array.isArray(T)){let u=T.find(v=>y>=v.from&&y<v.to)||T.find(v=>y===v.to)||T[T.length-1],b=l.get(u.merged);if(!b||!b.isConnected)return null;let x=n.get(u.merged),P=x&&x.flat?x.flat(u.flatStart+y):y;return[b,Math.max(0,Math.min(P,b.nodeValue.length))]}if(T){let u=(r.get(T.merged)||[N])[0];if(!u.isConnected)return null;let b=n.get(T.merged),x=T.shift+y,P=b?b(x):x;return[u,Math.max(0,Math.min(P,u.nodeValue.length))]}return N.isConnected?[N,Math.min(y,N.nodeType===3?N.nodeValue.length:N.childNodes.length)]:null},d=f(s.range.sc,s.range.so),M=f(s.range.ec,s.range.eo);if(!(!d||!M))try{let N=e.createRange();N.setStart(d[0],d[1]),N.setEnd(M[0],M[1]);let y=e.getSelection();y.removeAllRanges(),y.addRange(N)}catch{}}var es=Symbol("hyper-morph-duplicate-key"),ts=[e=>e.getAttribute("data-id"),e=>e.getAttribute("id")];function Pn(e,s){return s.map(o=>{let n=new Map;for(let r of e){if(r.nodeType!==1)continue;let l=o(r);l==null||l===""||n.set(l,n.has(l)?es:r)}return n})}function ns(e,s,o,n){for(let r=0;r<n.length;r++){let l=n[r](e);if(l==null||l===""||s[r].get(l)!==e)continue;let c=o[r].get(l);if(!(!c||c===es)&&c.tagName===e.tagName)return c}return null}function Sn(e,s,o){for(let n=0;n<o.length;n++){let r=o[n](e);if(!(r==null||r==="")&&s[n].get(r)===e)return!0}return!1}function os(e,s,o={}){let n=o.skip||(()=>!1),r=o.ignoreAttr||(()=>!1),l=o.tiers&&o.tiers.length?o.tiers:ts,c=null;function f(){return c||(c=Pn([e,...e.querySelectorAll("*")],l)),c}let d=null;function M(){return d||(d=Pn([s,...s.querySelectorAll("*")],l)),d}function N(H){return!H.parentElement||!H.parentElement.parentElement}function y(H,Q,ie){return N(H)||Sn(H,f(),l)?(ie.push({type:"subtree",el:H,base:Q}),!1):!0}function T(H,Q){let ie=[];for(let me of H.attributes)r(H,me.name)||Q.getAttribute(me.name)!==me.value&&ie.push(me.name);for(let me of Q.attributes)r(H,me.name)||H.hasAttribute(me.name)||ie.push(me.name);return ie}function u(H){let Q=[],ie=null,me=()=>{ie!==null&&(Q.push({nodeType:3,nodeValue:ie}),ie=null)};for(let Ie of H.childNodes){if(Ie.nodeType===3){ie=(ie===null?"":ie)+Ie.nodeValue;continue}Ie.nodeType===1&&n(Ie)||(me(),(Ie.nodeType===1||Ie.nodeType===8)&&Q.push(Ie))}return me(),Q}function b(H,Q){if(H.nodeType!==Q.nodeType)return!1;if(H.nodeType!==1)return!0;if(H.tagName!==Q.tagName)return!1;for(let ie of l){let me=ie(H),Ie=ie(Q);if(me!=null&&me!==""&&Ie!=null&&Ie!==""&&me!==Ie)return!1}return!0}function x(H){let Q="";for(let ie of H)ie.nodeType===3&&ie.nodeValue.trim()!==""?Q+="\0"+ie.nodeValue:ie.nodeType===8&&(Q+=""+ie.nodeValue);return Q}function P(H,Q,ie){let me=u(H),Ie=u(Q);if(me.length===Ie.length){let E=!0;for(let oe=0;oe<me.length;oe++)if(!b(me[oe],Ie[oe])){E=!1;break}if(E){for(let oe=0;oe<me.length;oe++){let Z=me[oe];if(Z.nodeType===1){if(v(Z,Ie[oe],ie))return!0}else if(Z.nodeValue!==Ie[oe].nodeValue)return!0}return!1}}let ot=me.filter(E=>E.nodeType===1),bt=Ie.filter(E=>E.nodeType===1);if(x(me)!==x(Ie))return!0;let kt=Pn(ot,l),Se=Pn(bt,l),at=[],Ge=new Set,xt=[];for(let E of ot){let oe=ns(E,kt,Se,l);oe&&!Ge.has(oe)?(at.push([E,oe]),Ge.add(oe)):xt.push(E)}let Ke=[];for(let E of xt)Sn(E,kt,l)?ie.push({type:"subtree",el:E,base:null}):Ke.push(E);let ze=[];for(let E of bt)Ge.has(E)||(Sn(E,Se,l)?ie.push({type:"deletion",el:E}):ze.push(E));if(Ke.length!==ze.length)return!0;for(let E=0;E<Ke.length;E++)if(!b(Ke[E],ze[E]))return!0;let it=new Map(at);for(let E=0;E<Ke.length;E++)it.set(Ke[E],ze[E]);let w=-1;for(let E of ot){let oe=it.get(E);if(!oe)continue;let Z=bt.indexOf(oe);if(Z<w)return!0;w=Z}for(let E=0;E<Ke.length;E++)if(v(Ke[E],ze[E],ie))return!0;for(let[E,oe]of at)if(v(E,oe,ie))return!0;return!1}function v(H,Q,ie){if(H.tagName!==Q.tagName)return y(H,Q,ie);let me=T(H,Q),Ie=[];if(P(H,Q,Ie))return y(H,Q,ie);if(me.length){if(!N(H)&&!Sn(Q,M(),l))return!0;ie.push({type:"attrs",el:H,names:me,base:Q})}return ie.push(...Ie),!1}let j=[],Y=T(e,s);Y.length&&j.push({type:"attrs",el:e,names:Y});let le=(H,Q)=>Array.from(H.children).find(ie=>ie.tagName===Q)||null,Ne=le(e,"HEAD"),ye=le(s,"HEAD");if(Ne&&ye){let H=[];v(Ne,ye,H),H.length&&j.push({type:"head",el:Ne})}else(Ne||ye)&&Ne&&j.push({type:"head",el:Ne});let De=le(e,"BODY"),F=le(s,"BODY");return De&&F?v(De,F,j):De&&j.push({type:"subtree",el:De,base:null}),{entries:j}}function ss(e,s,o={}){let n=o.tiers&&o.tiers.length?o.tiers:ts,r=e.documentElement,l=[],c=0,f=v=>({ok:!1,placed:l,held:v,skippedAttrs:c});if(!r)return f(null);function d(v){let j=[v,...v.querySelectorAll("*")];return Pn(j,n)}let M=d(r),N=new Map,y=v=>{let j=v.getRootNode(),Y=N.get(j);if(!Y){let le=j.nodeType===9?j.documentElement:j;Y=d(le),N.set(j,Y)}return Y};function T(v){if(!v.parentElement&&v.tagName==="HTML")return r;if(v.parentElement&&!v.parentElement.parentElement&&v.parentElement.tagName==="HTML"){if(v.tagName==="BODY")return e.body||null;if(v.tagName==="HEAD")return e.head||null}return null}function u(v){let j=T(v);return j||ns(v,y(v),M,n)}function b(v){if(!v)return null;let j=u(v);return j&&j.isConnected?j:null}function x(v){for(let j=0;j<n.length;j++){let Y=n[j](v);Y!=null&&Y!==""&&M[j].set(Y,v)}}for(let v of s){if(v.type!=="deletion")continue;let j=u(v.el);j&&j!==r&&j.remove()}let P=s.filter(v=>v.type!=="deletion").sort((v,j)=>v.el===j.el?0:v.el.compareDocumentPosition(j.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let v of P){if(v.type==="head"){let F=e.importNode(v.el,!0);e.head?e.head.replaceWith(F):r.insertBefore(F,r.firstChild),l.push({entry:v,imported:F});continue}if(v.type==="attrs"){let F=b(v.el)||b(v.base);if(!F){c++;continue}for(let H of v.names)v.el.hasAttribute(H)?F.setAttribute(H,v.el.getAttribute(H)):F.removeAttribute(H);continue}let j=v.el;if(T(j))return f(v);let Y=b(j)||b(v.base);if(Y){let F=e.importNode(j,!0);Y.replaceWith(F),x(F),l.push({entry:v,imported:F});continue}if(v.base!=null&&!Sn(v.base,y(v.base),n)||!Sn(j,y(j),n))return f(v);let le=j.parentElement;if(!le)return f(v);let Ne=b(le);if(!Ne)return f(v);let ye=null;for(let F=j.previousElementSibling;F;F=F.previousElementSibling){let H=b(F);if(H&&H.parentNode===Ne){ye=H;break}}let De=e.importNode(j,!0);if(ye)Ne.insertBefore(De,ye.nextSibling);else{let F=Array.prototype.indexOf.call(le.children,j);Ne.insertBefore(De,Ne.children[F]||null)}x(De),l.push({entry:v,imported:De})}return{ok:!0,placed:l,held:null,skippedAttrs:c}}var dr='[editor-ui],[clay~="editor-ui"],[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]',hr='[editor-ui],[clay~="editor-ui"],[no-undo],[clay~="no-undo"]',pr='[no-undo]:not([editor-ui]):not([clay~="editor-ui"]),[clay~="no-undo"]:not([editor-ui]):not([clay~="editor-ui"])';function mr(e){if(e.tagName!=="LINK"&&e.tagName!=="SCRIPT")return!1;let s=e.getAttribute("src")||e.getAttribute("href")||"";return/^(chrome|moz|safari-web)-extension:/.test(s)}function gr(e,s,o,n){if(s==null)return;if(typeof s=="string")return s;let r=s;if(r.nodeType===9){let l=e.getAttribute("id");r=l&&r.getElementById(l)||(e.tagName==="BODY"?r.body:e.tagName==="HTML"?r.documentElement:r.body&&r.body.firstElementChild)}if((!r||r.nodeType!==1||r.tagName!==e.tagName)&&(r=br(e,s,n)),!!r)return o?Array.from(r.childNodes):r}function br(e,s,o){let n=s.nodeType===9?s.documentElement:s;if(!n||n.nodeType!==1)return null;let r=new Map,l=[n,...n.querySelectorAll("script")];for(let d of l){let M=xn(d,o);M&&!r.has(M.key)&&r.set(M.key,d.textContent)}if(!r.size)return null;let c=e.cloneNode(!0),f=!1;for(let d of[c,...c.querySelectorAll("script")]){let M=xn(d,o);M&&r.has(M.key)&&(d.textContent=r.get(M.key),f=!0)}return f?c:null}function rs(e,s){if(typeof e=="string"||e.nodeType===9)return e;if(e.nodeType===1&&e===e.ownerDocument.documentElement)return e.ownerDocument;let o=s.implementation.createHTMLDocument(""),n=e.nodeType===1&&e.tagName==="HTML"?e:null;if(n)return o.replaceChild(o.adoptNode(n),o.documentElement),o;let r=e.nodeType===11?Array.from(e.childNodes):e.nodeType?[e]:Array.from(e);for(let l of r)o.body.appendChild(o.adoptNode(l));return o}function eo(e,s,o={}){let n=o||{};if(!n.head?.block)return is(e,s,n);try{return is(e,s,n)}catch(r){return Promise.reject(r)}}function is(e,s,o){let n=o.policy||"sync",r=n==="raw"?void 0:(d,M)=>mr(d)||(n==="history"?!(M&&d.matches(pr))&&d.matches(hr):d.matches(dr)),l=o.callbacks||{},c={ignore:r,hooks:l,protectFocusedValue:o.ignoreActiveValue===!0?"subtree":!1,restoreFocus:o.restoreFocus!==!1,formState:o.formStateSync||"attribute",scripts:{execute:o.scripts?.handle!==!1,merge:o.scripts?.merge!==!1,mergeTags:o.scripts?.mergeTags||[]},head:{awaitLoads:!!o.head?.block,preserve:o.head?.shouldPreserve||(()=>!1)}};if(typeof o.key=="function"&&(c.identity={base:o.key,local:o.key,remote:o.key}),e&&e.nodeType===9)return vn(Object.assign({},c,{live:e,base:o.scripts?.mergeBase||null,remote:rs(s,e)}));if(e.tagName==="HTML"&&e.parentNode&&e.parentNode.nodeType===9){let d=Object.assign({},c,{live:e.ownerDocument,base:o.scripts?.mergeBase||null,remote:rs(s,e.ownerDocument)});return vn(d)}o.morphStyle==="innerHTML"&&(c.children=!0);let f=gr(e,o.scripts?.mergeBase,!!c.children,c.scripts.mergeTags);return f!==void 0&&(c.base=f),to(e,s,c)}var kr=new Set(["live","base","remote","local","identity","ignore","remoteWins","ignoreAttribute","conflicts","protectFocusedValue","restoreFocus","head","scripts","formState","children","hooks","beforeApply"]),en=()=>{};function Un(e,s=[]){if(!e||typeof e!="object")throw new TypeError("options object required");for(let c of Object.keys(e))if(!kr.has(c))throw new TypeError(`unknown option "${c}"`);let o=Object.assign({beforeNodeAdded:en,afterNodeAdded:en,beforeNodeRemoved:en,afterNodeRemoved:en,beforeNodeMorphed:en,afterNodeMorphed:en,beforeAttributeUpdated:en},e.hooks||{}),n=e.conflicts||"remote";if(!["remote","local","both"].includes(n))throw new TypeError("conflicts must be remote, local or both");let r=e.formState||"attribute";if(!["attribute","property"].includes(r))throw new TypeError("formState must be attribute or property");let l=e.protectFocusedValue;if(l!==void 0&&typeof l!="boolean"&&l!=="subtree")throw new TypeError('protectFocusedValue must be a boolean or "subtree"');return{ignored:oo(e.ignore,s),remoteWins:oo(e.remoteWins,s),ignoreAttribute:typeof e.ignoreAttribute=="function"?e.ignoreAttribute:()=>!1,conflicts:n,protectFocusedValue:l===void 0?!0:l,restoreFocus:e.restoreFocus!==!1,head:Object.assign({awaitLoads:!1,preserve:()=>!1},e.head||{}),scripts:Object.assign({execute:!0,merge:!0,mergeTags:[]},e.scripts||{}),formState:r,hooks:o,children:!!e.children,beforeApply:typeof e.beforeApply=="function"?e.beforeApply:null}}function Mn(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){if(typeof e.first=="function")return e.first;if(typeof e.then=="function")return e.then}return un}function In(e,s){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){let o=qn(s,e.map),n=typeof e.then=="function"?e.then:un;if(typeof e.first=="function"){let r=e.first;return l=>r(l)||o.get(l)||n(l)}return r=>o.get(r)||n(r)}return un}function as(e,s,o,n={}){let r=y=>y&&y.nodeType===9?y.documentElement:y,l=r(s),c=r(o),f=r(e)||l,d=Object.assign({},n);delete d.live,delete d.base,delete d.remote;let M=Un(d,[f,l,c].filter(Boolean)),N=n.identity||{};return wo(f,l,c,{identity:{base:In(N.base,f),local:In(N.local,l),remote:In(N.remote,c)},authored:{base:Mn(N.base),local:Mn(N.local),remote:Mn(N.remote)},skipUnchanged:M.hooks.beforeNodeMorphed===en&&M.hooks.afterNodeMorphed===en,ignored:M.ignored,remoteWins:M.remoteWins,ignoreAttribute:M.ignoreAttribute,conflicts:M.conflicts,mergeTags:M.scripts.merge===!1?null:M.scripts.mergeTags,baseURI:l.ownerDocument&&l.ownerDocument.baseURI||"about:blank",localIsBase:!e||e===s,childrenOnly:M.children})}function Ao({liveRoot:e,baseRoot:s,localRoot:o,remoteRoot:n,toLive:r,options:l,identity:c,childrenOnly:f,isDocument:d}){let M=Un(l,[e,s,o,n].filter(Boolean));if(M.ignored(e))return{report:To(),loads:[]};let N=e.ownerDocument,y=M.scripts.execute?Vo(e,M.ignored,N.baseURI):null,T=wo(s||o,o,n,{identity:{base:In(c.base,s||o),local:In(c.local,o),remote:In(c.remote,n)},authored:{base:Mn(c.base),local:Mn(c.local),remote:Mn(c.remote)},ignored:M.ignored,remoteWins:M.remoteWins,ignoreAttribute:M.ignoreAttribute,conflicts:M.conflicts,mergeTags:M.scripts.merge===!1?null:M.scripts.mergeTags,baseURI:N.baseURI,localIsBase:!s,childrenOnly:f,skipUnchanged:M.hooks.beforeNodeMorphed===en&&M.hooks.afterNodeMorphed===en});M.beforeApply&&M.beforeApply(T.doc);let u=globalThis.__hyperMorphProfile,b=u?performance.now():0,x=Zo(e,T.root,T,{toLive:r,ignored:M.ignored,ignoreAttribute:M.ignoreAttribute,formState:M.formState,protectFocusedValue:M.protectFocusedValue,restoreFocus:M.restoreFocus,preserve:M.head.preserve,hooks:M.hooks,childrenOnly:f});u&&(u.apply=(u.apply||0)+(performance.now()-b));let P=[];if(M.head.awaitLoads)for(let Y of x.applied){if(Y.kind!=="insert"||Y.node.nodeType!==1)continue;let le=Y.node;le.tagName==="LINK"&&/\bstylesheet\b/i.test(le.getAttribute("rel")||"")&&le.getAttribute("href")&&le.closest("head")&&P.push(new Promise(ye=>{le.addEventListener("load",()=>ye()),le.addEventListener("error",()=>ye())}))}if(y){let Y=Wo(e,y,{ignored:M.ignored,skip:x.mergedScriptsLive,baseURI:N.baseURI,beforeNodeAdded:M.hooks.beforeNodeAdded,afterNodeAdded:M.hooks.afterNodeAdded});P.push(...Y.loads)}let v=Y=>Y&&x.liveOf&&x.liveOf.get(Y)||null;return{report:{applied:x.applied,decisions:T.decisions.map(Y=>Object.assign({},Y,{node:Y.node?v(Y.node):null,el:Y.el?v(Y.el):null,applied:!!(Y.node?v(Y.node):Y.el&&v(Y.el))})),conflicts:T.conflicts.map(Y=>Object.assign({},Y,{node:Y.node?v(Y.node):Y.node,el:Y.el?v(Y.el):Y.el})),localDiverged:T.localDiverged,identities:x.identities,moved:x.moved,replaced:x.replaced},loads:P}}var cs=new WeakMap;function To(){return{applied:[],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[]}}function vn(e){let s=e||{},o=s.live;if(!o||o.nodeType!==9)throw new TypeError("live must be a Document");let n=cs.get(o);n||(n=zn(o),cs.set(o,n));let r=n("remote",s.remote),l=typeof s.base=="string"&&s.base===""?null:s.base,c=l?n("base",l):null,f=s.local?s.local.root:o.documentElement,d=s.local?s.local.toLive:y=>y;So(o,r);let{report:M,loads:N}=Ao({liveRoot:o.documentElement,baseRoot:c?c.documentElement:null,localRoot:f,remoteRoot:r.documentElement,toLive:d,options:s,identity:s.identity||{},childrenOnly:!1,isDocument:!0});return Promise.all(N).then(()=>M)}function fs(e,s,o={}){return vn(Object.assign({},o,{live:e,base:null,remote:s}))}function ls(e,s){if(e==null)return{root:s.createElement("template"),first:null};if(typeof e=="string"){let n=/^\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype[^>]*>\s*)?<(html|body)[\s>]/i.exec(e);if(n){let l=Kn(e,s),c=n[1].toLowerCase()==="html"?l.documentElement:l.body;return{root:c,first:c}}let r=s.createElement("template");return r.innerHTML=e,{root:r,first:r.content.firstElementChild}}if(e.nodeType===9)return{root:e.documentElement,first:e.documentElement};if(e.nodeType===1){let n=s.createElement("template"),r=e.isConnected;return n.content.appendChild(r?s.importNode(e,!0):e),{root:n,first:e}}if(e.nodeType===11){let n=s.createElement("template");return n.content.appendChild(e),{root:n,first:n.content.firstElementChild}}let o=s.createElement("template");for(let n of Array.from(e))o.content.appendChild(n.parentNode?s.importNode(n,!0):n);return{root:o,first:o.content.firstElementChild}}function to(e,s,o={}){if(!e||e.nodeType!==1)throw new TypeError("oldEl must be an Element");let n=e.ownerDocument,{base:r,...l}=o,c=!!l.children;if(Un(l,[e]).ignored(e))return Promise.resolve(To());let f=ls(s,n),d=r!=null?ls(r,n):null,M,N=null;if(c)M=f.root,N=d?d.root:null;else{if(M=f.first,N=d?d.first:null,!M){let u=Un(l);return u.hooks.beforeNodeRemoved(e)!==!1&&(e.remove(),u.hooks.afterNodeRemoved(e)),Promise.resolve({applied:[{kind:"remove",node:e,parent:null}],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[e]})}if(M.tagName!==e.tagName){let u=Un(l,[e,M]);if(u.hooks.beforeNodeMorphed(e,M)===!1)return Promise.resolve(To());let b=Ao({liveRoot:e,baseRoot:N&&N.tagName===e.tagName?N:null,localRoot:e,remoteRoot:M,toLive:P=>P,options:l,identity:l.identity||{},childrenOnly:!0,isDocument:!1}),x=_t(M)?Bn(M,n):n.importNode(M,!1);if(!_t(x))for(;e.firstChild;)x.appendChild(e.firstChild);return u.hooks.beforeNodeAdded(x)===!1||u.hooks.beforeNodeRemoved(e)===!1?Promise.resolve(b.report):(e.replaceWith(x),u.hooks.afterNodeRemoved(e),u.hooks.afterNodeAdded(x),u.hooks.afterNodeMorphed(e,M),b.report.replaced.push(x),b.report.applied.push({kind:"insert",node:x,parent:x.parentNode},{kind:"remove",node:e,parent:x.parentNode}),Promise.all(b.loads).then(()=>b.report))}}let{report:y,loads:T}=Ao({liveRoot:e,baseRoot:N,localRoot:e,remoteRoot:M,toLive:u=>u,options:l,identity:l.identity||{},childrenOnly:c,isDocument:!1});return Promise.all(T).then(()=>y)}var yr={mergeDocument:vn,morphDocument:fs,morphElement:to,merge3:as,morph:eo};return ys(wr);})();
|
|
3
4
|
|
|
4
|
-
|
|
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
|
-
};
|
|
5
|
+
var morph = HyperMorph.morph;
|
|
11
6
|
|
|
12
7
|
// Auto-export to window unless suppressed by loader
|
|
13
8
|
if (!window.__hyperclayNoAutoExport) {
|