hyper-html-api 0.8.0 → 0.9.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 +38 -0
- package/conformance/MANIFEST.json +2 -2
- package/conformance/cases/no-data-list-skipped.expected.json +6 -0
- package/conformance/cases/no-data-list-skipped.html +1 -0
- package/conformance/cases/no-data-list-skipped.meta +4 -0
- package/conformance/cases/no-data-list-skipped.parsed.json +3 -0
- package/conformance/cases/no-data-list-skipped.rules +1 -0
- package/conformance/cases/no-data-text-projected.expected.json +3 -0
- package/conformance/cases/no-data-text-projected.html +1 -0
- package/conformance/cases/no-data-text-projected.meta +4 -0
- package/conformance/cases/no-data-text-projected.parsed.json +3 -0
- package/conformance/cases/no-data-text-projected.rules +1 -0
- package/conformance/cases/props-type-is-attribute.expected.json +5 -0
- package/conformance/cases/props-type-is-attribute.meta +4 -0
- package/conformance/cases/write-attr-app-scheme.after.html +1 -0
- package/conformance/cases/write-attr-app-scheme.after.json +3 -0
- package/conformance/cases/write-attr-app-scheme.data.json +1 -0
- package/conformance/cases/write-attr-app-scheme.html +1 -0
- package/conformance/cases/write-attr-app-scheme.meta +4 -0
- package/conformance/cases/write-attr-app-scheme.write.json +4 -0
- package/conformance/cases/write-attr-href.after.html +1 -0
- package/conformance/cases/write-attr-href.after.json +3 -0
- package/conformance/cases/write-attr-href.data.json +1 -0
- package/conformance/cases/write-attr-href.html +1 -0
- package/conformance/cases/write-attr-href.meta +4 -0
- package/conformance/cases/write-attr-href.write.json +4 -0
- package/conformance/cases/write-checked-false.after.html +1 -0
- package/conformance/cases/write-checked-false.after.json +3 -0
- package/conformance/cases/write-checked-false.data.json +1 -0
- package/conformance/cases/write-checked-false.html +1 -0
- package/conformance/cases/write-checked-false.meta +4 -0
- package/conformance/cases/write-checked-false.write.json +4 -0
- package/conformance/cases/write-checked-true.after.html +1 -0
- package/conformance/cases/write-checked-true.after.json +3 -0
- package/conformance/cases/write-checked-true.data.json +1 -0
- package/conformance/cases/write-checked-true.html +1 -0
- package/conformance/cases/write-checked-true.meta +4 -0
- package/conformance/cases/write-checked-true.write.json +4 -0
- package/conformance/cases/write-crlf-multi.after.html +12 -0
- package/conformance/cases/write-crlf-multi.after.json +8 -0
- package/conformance/cases/write-crlf-multi.data.json +1 -0
- package/conformance/cases/write-crlf-multi.html +12 -0
- package/conformance/cases/write-crlf-multi.meta +4 -0
- package/conformance/cases/write-crlf-multi.write.json +4 -0
- package/conformance/cases/write-fallback-implied.after.html +1 -0
- package/conformance/cases/write-fallback-implied.after.json +3 -0
- package/conformance/cases/write-fallback-implied.data.json +1 -0
- package/conformance/cases/write-fallback-implied.html +1 -0
- package/conformance/cases/write-fallback-implied.meta +4 -0
- package/conformance/cases/write-fallback-implied.write.json +4 -0
- package/conformance/cases/write-flatten.after.html +1 -0
- package/conformance/cases/write-flatten.after.json +3 -0
- package/conformance/cases/write-flatten.data.json +1 -0
- package/conformance/cases/write-flatten.html +1 -0
- package/conformance/cases/write-flatten.meta +4 -0
- package/conformance/cases/write-flatten.write.json +4 -0
- package/conformance/cases/write-list-empty-no-seed.data.json +1 -0
- package/conformance/cases/write-list-empty-no-seed.error.json +8 -0
- package/conformance/cases/write-list-empty-no-seed.html +1 -0
- package/conformance/cases/write-list-empty-no-seed.meta +4 -0
- package/conformance/cases/write-list-grow-from-template.after.html +1 -0
- package/conformance/cases/write-list-grow-from-template.after.json +5 -0
- package/conformance/cases/write-list-grow-from-template.data.json +1 -0
- package/conformance/cases/write-list-grow-from-template.html +1 -0
- package/conformance/cases/write-list-grow-from-template.meta +4 -0
- package/conformance/cases/write-list-grow-from-template.write.json +4 -0
- package/conformance/cases/write-list-object-clone.after.html +1 -0
- package/conformance/cases/write-list-object-clone.after.json +12 -0
- package/conformance/cases/write-list-object-clone.data.json +1 -0
- package/conformance/cases/write-list-object-clone.html +1 -0
- package/conformance/cases/write-list-object-clone.meta +4 -0
- package/conformance/cases/write-list-object-clone.write.json +4 -0
- package/conformance/cases/write-list-scalar-grow.after.html +4 -0
- package/conformance/cases/write-list-scalar-grow.after.json +7 -0
- package/conformance/cases/write-list-scalar-grow.data.json +1 -0
- package/conformance/cases/write-list-scalar-grow.html +4 -0
- package/conformance/cases/write-list-scalar-grow.meta +4 -0
- package/conformance/cases/write-list-scalar-grow.write.json +4 -0
- package/conformance/cases/write-list-scalar-shrink.after.html +4 -0
- package/conformance/cases/write-list-scalar-shrink.after.json +5 -0
- package/conformance/cases/write-list-scalar-shrink.data.json +1 -0
- package/conformance/cases/write-list-scalar-shrink.html +4 -0
- package/conformance/cases/write-list-scalar-shrink.meta +4 -0
- package/conformance/cases/write-list-scalar-shrink.write.json +4 -0
- package/conformance/cases/write-list-shrink-zero.after.html +1 -0
- package/conformance/cases/write-list-shrink-zero.after.json +3 -0
- package/conformance/cases/write-list-shrink-zero.data.json +1 -0
- package/conformance/cases/write-list-shrink-zero.html +1 -0
- package/conformance/cases/write-list-shrink-zero.meta +4 -0
- package/conformance/cases/write-list-shrink-zero.write.json +4 -0
- package/conformance/cases/write-no-data-kept.after.html +1 -0
- package/conformance/cases/write-no-data-kept.after.json +3 -0
- package/conformance/cases/write-no-data-kept.data.json +1 -0
- package/conformance/cases/write-no-data-kept.html +1 -0
- package/conformance/cases/write-no-data-kept.meta +4 -0
- package/conformance/cases/write-no-data-kept.write.json +4 -0
- package/conformance/cases/write-no-rules-tag.data.json +1 -0
- package/conformance/cases/write-no-rules-tag.error.json +6 -0
- package/conformance/cases/write-no-rules-tag.html +1 -0
- package/conformance/cases/write-no-rules-tag.meta +4 -0
- package/conformance/cases/write-noop.after.html +3 -0
- package/conformance/cases/write-noop.after.json +3 -0
- package/conformance/cases/write-noop.data.json +1 -0
- package/conformance/cases/write-noop.html +3 -0
- package/conformance/cases/write-noop.meta +4 -0
- package/conformance/cases/write-noop.write.json +4 -0
- package/conformance/cases/write-outerhtml-unchanged.after.html +1 -0
- package/conformance/cases/write-outerhtml-unchanged.after.json +3 -0
- package/conformance/cases/write-outerhtml-unchanged.data.json +1 -0
- package/conformance/cases/write-outerhtml-unchanged.html +1 -0
- package/conformance/cases/write-outerhtml-unchanged.meta +4 -0
- package/conformance/cases/write-outerhtml-unchanged.write.json +4 -0
- package/conformance/cases/write-readonly-changed.data.json +1 -0
- package/conformance/cases/write-readonly-changed.error.json +6 -0
- package/conformance/cases/write-readonly-changed.html +1 -0
- package/conformance/cases/write-readonly-changed.meta +4 -0
- package/conformance/cases/write-readonly-unchanged.after.html +1 -0
- package/conformance/cases/write-readonly-unchanged.after.json +4 -0
- package/conformance/cases/write-readonly-unchanged.data.json +1 -0
- package/conformance/cases/write-readonly-unchanged.html +1 -0
- package/conformance/cases/write-readonly-unchanged.meta +4 -0
- package/conformance/cases/write-readonly-unchanged.write.json +4 -0
- package/conformance/cases/write-refused-animate.data.json +1 -0
- package/conformance/cases/write-refused-animate.error.json +11 -0
- package/conformance/cases/write-refused-animate.html +1 -0
- package/conformance/cases/write-refused-animate.meta +4 -0
- package/conformance/cases/write-refused-attr-name.data.json +1 -0
- package/conformance/cases/write-refused-attr-name.error.json +11 -0
- package/conformance/cases/write-refused-attr-name.html +1 -0
- package/conformance/cases/write-refused-attr-name.meta +4 -0
- package/conformance/cases/write-refused-data-url.data.json +1 -0
- package/conformance/cases/write-refused-data-url.error.json +11 -0
- package/conformance/cases/write-refused-data-url.html +1 -0
- package/conformance/cases/write-refused-data-url.meta +4 -0
- package/conformance/cases/write-refused-innerhtml.data.json +1 -0
- package/conformance/cases/write-refused-innerhtml.error.json +11 -0
- package/conformance/cases/write-refused-innerhtml.html +1 -0
- package/conformance/cases/write-refused-innerhtml.meta +4 -0
- package/conformance/cases/write-refused-javascript-url.data.json +1 -0
- package/conformance/cases/write-refused-javascript-url.error.json +11 -0
- package/conformance/cases/write-refused-javascript-url.html +1 -0
- package/conformance/cases/write-refused-javascript-url.meta +4 -0
- package/conformance/cases/write-refused-list-removes-rules-tag.data.json +1 -0
- package/conformance/cases/write-refused-list-removes-rules-tag.error.json +11 -0
- package/conformance/cases/write-refused-list-removes-rules-tag.html +1 -0
- package/conformance/cases/write-refused-list-removes-rules-tag.meta +4 -0
- package/conformance/cases/write-refused-multiple.data.json +1 -0
- package/conformance/cases/write-refused-multiple.error.json +15 -0
- package/conformance/cases/write-refused-multiple.html +1 -0
- package/conformance/cases/write-refused-multiple.meta +4 -0
- package/conformance/cases/write-refused-onclick.data.json +1 -0
- package/conformance/cases/write-refused-onclick.error.json +11 -0
- package/conformance/cases/write-refused-onclick.html +1 -0
- package/conformance/cases/write-refused-onclick.meta +4 -0
- package/conformance/cases/write-refused-rules-tag-ancestor.data.json +1 -0
- package/conformance/cases/write-refused-rules-tag-ancestor.error.json +11 -0
- package/conformance/cases/write-refused-rules-tag-ancestor.html +1 -0
- package/conformance/cases/write-refused-rules-tag-ancestor.meta +4 -0
- package/conformance/cases/write-refused-script.data.json +1 -0
- package/conformance/cases/write-refused-script.error.json +11 -0
- package/conformance/cases/write-refused-script.html +1 -0
- package/conformance/cases/write-refused-script.meta +4 -0
- package/conformance/cases/write-shape-mismatch.data.json +1 -0
- package/conformance/cases/write-shape-mismatch.error.json +12 -0
- package/conformance/cases/write-shape-mismatch.html +1 -0
- package/conformance/cases/write-shape-mismatch.meta +4 -0
- package/conformance/cases/write-text-basic.after.html +3 -0
- package/conformance/cases/write-text-basic.after.json +3 -0
- package/conformance/cases/write-text-basic.data.json +1 -0
- package/conformance/cases/write-text-basic.html +3 -0
- package/conformance/cases/write-text-basic.meta +4 -0
- package/conformance/cases/write-text-basic.write.json +4 -0
- package/conformance/cases/write-text-escape.after.html +1 -0
- package/conformance/cases/write-text-escape.after.json +3 -0
- package/conformance/cases/write-text-escape.data.json +1 -0
- package/conformance/cases/write-text-escape.html +1 -0
- package/conformance/cases/write-text-escape.meta +4 -0
- package/conformance/cases/write-text-escape.write.json +4 -0
- package/conformance/cases/write-text-null-clears.after.html +1 -0
- package/conformance/cases/write-text-null-clears.after.json +3 -0
- package/conformance/cases/write-text-null-clears.data.json +1 -0
- package/conformance/cases/write-text-null-clears.html +1 -0
- package/conformance/cases/write-text-null-clears.meta +4 -0
- package/conformance/cases/write-text-null-clears.write.json +4 -0
- package/conformance/cases/write-type-attribute.after.html +1 -0
- package/conformance/cases/write-type-attribute.after.json +3 -0
- package/conformance/cases/write-type-attribute.data.json +1 -0
- package/conformance/cases/write-type-attribute.html +1 -0
- package/conformance/cases/write-type-attribute.meta +4 -0
- package/conformance/cases/write-type-attribute.write.json +4 -0
- package/conformance/cases/write-unknown-key.data.json +1 -0
- package/conformance/cases/write-unknown-key.error.json +11 -0
- package/conformance/cases/write-unknown-key.html +3 -0
- package/conformance/cases/write-unknown-key.meta +4 -0
- package/conformance/cases/write-unmatched.data.json +1 -0
- package/conformance/cases/write-unmatched.error.json +14 -0
- package/conformance/cases/write-unmatched.html +1 -0
- package/conformance/cases/write-unmatched.meta +4 -0
- package/conformance/write-policy.json +78 -0
- package/dist/hyper-html-api.engine.min.js +1 -1
- package/dist/hyper-html-api.min.js +5 -4
- package/dist/hyper-html-api.upgrade.min.js +2 -2
- package/package.json +5 -3
- package/packed-contract.json +1 -0
- package/src/adapters/cheerio.js +109 -10
- package/src/adapters/dom.js +191 -0
- package/src/dom-api.js +17 -6
- package/src/engine/apply.js +16 -2
- package/src/engine/errors.js +25 -0
- package/src/engine/extract.js +3 -0
- package/src/engine/index.js +4 -1
- package/src/engine/splice.js +118 -0
- package/src/engine/write-plan.js +52 -0
- package/src/engine/write-policy.js +136 -0
- package/src/lib/content-dom.js +110 -0
- package/src/lib/region-capabilities.js +71 -0
- package/src/write.js +29 -0
- package/conformance/cases/props-type-is-node-type.expected.json +0 -5
- package/conformance/cases/props-type-is-node-type.meta +0 -11
- /package/conformance/cases/{props-type-is-node-type.html → props-type-is-attribute.html} +0 -0
- /package/conformance/cases/{props-type-is-node-type.parsed.json → props-type-is-attribute.parsed.json} +0 -0
- /package/conformance/cases/{props-type-is-node-type.rules → props-type-is-attribute.rules} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
var HyperHtmlApi=(()=>{var
|
|
2
|
-
`)?{type:"textarea"}:{type:"text"}}function zn(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=we(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function Gn(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function ze(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function Yn(e){return` \xB7 ${e}`}var Gt={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 Zn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return Math.abs(t).toString(36)}function Qn(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function Xn(e,t){let n=[];for(let o of e.attributes||[]){let r=o.name;r==="id"||r==="class"||t.excludeAttributePrefixes.some(i=>r.startsWith(i))||t.includeAttributes.includes(r)&&n.push(`${r}=${o.value}`)}return n.sort().join("|")}function er(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function tr(e,t){let n=[e.tagName];return t.includeClasses&&n.push(Qn(e)),n.push(Xn(e,t)),Zn(n.join("|"))}function nr(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function rr(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function or(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function sr(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${nr(o)}`;if(n.unshift(r),o!==e&&rr(o,t)){n.unshift(or(o));break}o=o.parentElement}return n}function ir(e,t){let n=0,o=e.length-1,r=t.length-1;for(;o>=0&&r>=0&&e[o]===t[r];)n++,o--,r--;return n}function oe(e,t,n){if(n.has(e))return n.get(e);let o={signature:tr(e,t),path:sr(e,t),textHint:er(e,t)};return n.set(e,o),o}function Xt(e,t,n,o){if(o.has(e))return o.get(e);let r=new Map,i=e.querySelectorAll("*"),a=0;for(let s of i){let c=oe(s,t,n);c.domIndex=a++,!t.shouldIgnore?.(s)&&(r.has(c.signature)||r.set(c.signature,[]),r.get(c.signature).push(s))}return o.set(e,r),r}function ar(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function ft(e,t,n,o,r){let i=oe(e,n,o),a=oe(t,n,o),s=n.weights,c={},g=0;if(i.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};g+=s.signature,c.signature=s.signature;let E=ir(i.path,a.path)*s.pathSegment;g+=E,c.path=E;let m=!0;if(i.textHint&&a.textHint?i.textHint===a.textHint?(g+=s.textMatch,c.text=s.textMatch):(g-=s.textMismatch,c.text=-s.textMismatch,m=!1):i.textHint!==a.textHint&&(g-=s.textMismatch,c.text=-s.textMismatch,m=!1),r.candidateCount===1&&m&&(g+=s.uniqueCandidate,c.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof a.domIndex=="number"){let A=Math.abs(i.domIndex-a.domIndex),M=Math.min(A*s.positionPenalty,s.maxDriftPenalty);g-=M,c.drift=-M}return{score:g,breakdown:c}}function Yt(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let i=Xt(t,n,o,r),a=oe(e,n,o);if(typeof a.domIndex!="number"){let m=0,A=e.previousElementSibling;for(;A;)m++,A=A.previousElementSibling;a.domIndex=m}let s=i.get(a.signature)||[],c=n.excludeIds?s.filter(m=>!m.getAttribute("id")):s;if(c.length===0)return null;let g=null,v=0,E=null;for(let m of c){let{score:A,breakdown:M}=ft(e,m,n,o,{candidateCount:c.length});A>v&&(v=A,g=m,E=M)}return v<n.minConfidence?null:{element:g,confidence:v,breakdown:E}}function cr(e,t,n,o){let r=[],i=n.weights.signature+n.weights.slotMatch,a={slot:i};function s(E){if(E.children)return E.children;let m=E.childNodes;if(!m)return[];let A=[];for(let M=0;M<m.length;M++)m[M].nodeType===1&&A.push(m[M]);return A}function c(E,m){let A=s(E),M=s(m);if(A.length===M.length)for(let q=0;q<A.length;q++){let I=A[q],D=M[q];if(n.shouldIgnore?.(I)||n.shouldIgnore?.(D)||n.excludeIds&&(I.getAttribute("id")||D.getAttribute("id"))||I.tagName!==D.tagName)continue;let W=oe(I,n,o).signature,ee=oe(D,n,o).signature;W!==ee&&r.push({newEl:I,oldEl:D,score:i,breakdown:a}),c(I,D)}}function g(E,m){for(;;){if(E.tagName===m.tagName)return[E,m];let A=s(E);if(!E.tagName&&A.length===1){E=A[0];continue}let M=s(m);if(M.length===1&&M[0].tagName===E.tagName){m=M[0];continue}return null}}let v=g(e,t);return v&&c(v[0],v[1]),r}function Zt(e,t,n,o,r){let i=t.querySelectorAll("*"),a=Xt(e,n,o,r),s=0;for(let A of i){let M=oe(A,n,o);M.domIndex=s++}let c=[],g=new Map;function v(A,M,q){let I=new Set;if(A.textHint){let F=g.get(A.signature);if(!F){F=new Map;for(let Q of M){let ce=oe(Q,n,o).textHint,le=F.get(ce);le||(le=[],F.set(ce,le)),le.push(Q)}g.set(A.signature,F)}let ne=F.get(A.textHint);if(ne)for(let Q=0;Q<ne.length&&Q<q;Q++)I.add(ne[Q])}let D=0,W=M.length;for(;D<W;){let F=D+W>>1;oe(M[F],n,o).domIndex<A.domIndex?D=F+1:W=F}let ee=Math.max(0,Math.min(D-(q>>1),M.length-q)),se=Math.min(ee+q,M.length);for(let F=ee;F<se;F++)I.add(M[F]);return[...I]}for(let A of i){if(n.shouldIgnore?.(A)||n.excludeIds&&A.getAttribute("id"))continue;let M=oe(A,n,o),q=a.get(M.signature)||[],I=n.excludeIds?q.filter(ee=>!ee.getAttribute("id")):q,D=n.maxScoredCandidates,W=D&&I.length>D?v(M,I,D):I;for(let ee of W){let{score:se,breakdown:F}=ft(A,ee,n,o,{candidateCount:I.length});se>=n.minConfidence&&c.push({newEl:A,oldEl:ee,score:se,breakdown:F})}}if(n.weights.slotMatch>0){let A=cr(t,e,n,o);for(let M of A)c.push(M)}c.sort((A,M)=>M.score-A.score);let E=new Map,m=new Set;for(let{newEl:A,oldEl:M}of c)E.has(A)||m.has(M)||(E.set(A,M),m.add(M));return E}function Qt(e,t,n,o){let r=oe(e,n,o),i=oe(t,n,o),{score:a,breakdown:s}=ft(e,t,n,o,{candidateCount:1});return{matches:a>=n.minConfidence,score:a,breakdown:s,newMeta:{signature:r.signature,path:r.path,textHint:r.textHint},oldMeta:{signature:i.signature,path:i.path,textHint:i.textHint}}}function en(e={}){let t={...Gt,...e,weights:{...Gt.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,i)=>Yt(r,i,t,n,o),computeMatches:(r,i)=>Zt(r,i,t,n,o),explain:(r,i)=>Qt(r,i,t,n),invalidate:r=>ar(r,n,o),session:()=>{let r=new WeakMap,i=new WeakMap;return{findMatch:(a,s)=>Yt(a,s,t,r,i),computeMatches:(a,s)=>Zt(a,s,t,r,i),explain:(a,s)=>Qt(a,s,t,r)}},getConfig:()=>({...t})}}function dt(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
|
|
3
|
-
`;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function tn(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var lr=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,ur=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Ge(e){try{return JSON.parse(e)}catch{return JSON.parse(fr(e))}}function fr(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=dt(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=dt(e,n+1);if(e[s]==="}"||e[s]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let s=n+1;for(;s<e.length&&e[s]!==r;)e[s]==="\\"&&s++,s++;s>=e.length&&o("unterminated string",n);let c=e.slice(n+1,s);r==="'"&&(c=tn(c)),t+='"'+c+'"',n=s+1;continue}let i=n;for(;i<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[i]);)i++;i===n&&o("unexpected character "+JSON.stringify(r),n);let a=e.slice(n,i);if(a==="true"||a==="false"||a==="null"||lr.test(a)){t+=a,n=i;continue}if(ur.test(a)){if(e[dt(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function nn(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let E=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(E=!0),!E){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let E=s,m=a+1;for(;m<r.length&&r[m]!==E;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:E}),a=m+1;continue}let c=a,g;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let E=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let A of E){let M=A.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let E=r[c];for(c++;c<r.length&&r[c]!==E;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;g=r.substring(a,c);let v=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(g)?v=t.NUMBER:g==="true"||g==="false"||g==="null"?v=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(g)&&(v=t.SELECTOR),i.push({type:v,value:g,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING){let c=s.value;s.sourceQuote==="'"&&(c=tn(c)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var G=Symbol("hyper-morph-json-merge:missing"),rn=["id","_id","uuid","key","slug","code","name"];function ve(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Le(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function dr(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function pe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!pe(e[n],t[n]))return!1;return!0}if(ve(e)&&ve(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Le(t,o)||!pe(e[o],t[o]))return!1;return!0}return!1}function on(e,t,n,o){return pe(t,n)?t:pe(t,e)?n:pe(n,e)?t:ve(t)&&ve(n)?pr(ve(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?yr(Array.isArray(e)?e:[],t,n,o):n}function sn(e,t,n,o){return t===G&&n===G?G:t===G?e===G?n:pe(n,e)?G:n:n===G?e===G?t:G:on(e,t,n,o)}function pr(e,t,n,o){let r={},i=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let a of i){let s=sn(Le(e,a)?e[a]:G,Le(t,a)?t[a]:G,Le(n,a)?n[a]:G,o);s!==G&&dr(r,a,s)}return r}function hr(e){return e===null||typeof e!="object"}function Ye(e){return typeof e+":"+String(e)}function mr(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Le(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=Ye(i);if(o.has(a))return!1;o.add(a)}}return!0}function gr(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)ve(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(mr(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!hr(c))return null;let g=Ye(c);if(s.has(g))return null;s.add(g)}}return{kind:"self"}}function yr(e,t,n,o){let r=gr(e,t,n,o);if(!r)return n;let i=r.kind==="self"?Ye:A=>Ye(A[r.field]),a=A=>{let M=new Map;for(let q of A)M.set(i(q),q);return M},s=a(e),c=a(t),g=a(n),v=new Map,E=new Set([...s.keys(),...c.keys(),...g.keys()]);for(let A of E){let M=sn(s.has(A)?s.get(A):G,c.has(A)?c.get(A):G,g.has(A)?g.get(A):G,o);M!==G&&v.set(A,M)}let m=[];for(let A of n){let M=i(A);v.has(M)&&m.push(M)}for(let A=0;A<t.length;A++){let M=i(t[A]);if(!v.has(M)||m.includes(M))continue;let q=0;for(let I=A-1;I>=0;I--){let D=m.indexOf(i(t[I]));if(D!==-1){q=D+1;break}}m.splice(q,0,M)}return m.map(A=>v.get(A))}function pt(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...rn]:rn;return on(e===void 0?G:e,t,n,{keyCandidates:r})}function ht(e,t,n,o={}){let r=o.parse||Ge,i=[],a=(E,m)=>{if(typeof E!="string")return G;try{return r(E)}catch(A){return i.push(`${m} side is not valid JSON (${A.message})`),G}},s=a(t,"local"),c=a(n,"remote");if(s===G)return{text:n,warnings:i};if(c===G)return{text:t,warnings:i};let g=a(e,"base"),v=pt(g===G?void 0:g,s,c,o);return pe(v,c)?{text:n,warnings:i}:pe(v,s)?{text:t,warnings:i}:{text:JSON.stringify(v,null,2),warnings:i}}var He=function(){"use strict";let e=()=>{},t='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function n(f){if(!(f instanceof Element))return!1;if(f.matches(t))return!0;if(f.tagName==="LINK"||f.tagName==="SCRIPT"){let R=f.getAttribute("src")||f.getAttribute("href")||"";if(R.startsWith("chrome-extension://")||R.startsWith("moz-extension://")||R.startsWith("safari-web-extension://"))return!0}return!1}function o(f){return f instanceof Element?f.closest(t)?!0:n(f):!1}let r=en({shouldIgnore:o});function i(f,R,T){if(T){let k=T.identityOf(f);if(k&&!T.disabled.has(k.key))return"hm-merge:"+k.key}if(R!=="smart")return f.outerHTML;let N=f.getAttribute("src"),O=f.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${O}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${O}:${N}`}else{let k=f.textContent.trim(),h=5381;for(let x=0;x<k.length;x++)h=(h<<5)+h^k.charCodeAt(x);return`inline:${O}:${Math.abs(h).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(f){return f instanceof Element&&f.tagName==="SCRIPT"&&f.namespaceURI===a}function c(f){let R=document.createElement("div");R.innerHTML="<script><\/script>";let T=R.firstChild;for(let N of f.attributes)T.setAttribute(N.name,N.value);return T.textContent=f.textContent,T}function g(f){if(s(f))return c(f);if(f instanceof Element)for(let R of f.querySelectorAll("script"))s(R)&&R.replaceWith(c(R));return f}function v(f){let R=(f.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return R==="application/json"||R.endsWith("+json")}let E={match:f=>f.hasAttribute("merge"),identity:f=>f.getAttribute("merge")};function m(f,R,T){if(T.merge===!1)return null;let N=[E,...T.mergeTags||[]],O=new WeakMap,k=d=>{if(O.has(d))return O.get(d);let b=null;if(s(d)&&!d.getAttribute("src")&&!o(d)){let S=d;for(let L=0;L<N.length;L++)if(N[L].match(S)){if(!v(S))console.warn("[hyper-morph] merge ignored: script type is not JSON",S);else{let B=N[L].identity(S);B!=null&&B!==""&&(b={key:L+":"+B,raw:B,recognizer:N[L]})}break}}return O.set(d,b),b},h=new Set,x=d=>{let b=new Map,S=L=>{let B=k(L);B&&(b.has(B.key)?(h.add(B.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${B.raw}"`)):b.set(B.key,L))};s(d)&&S(d);for(let L of d.querySelectorAll("script"))S(L);return b},p=x(f),u=x(R.__hyperMorphRoot||R);if(p.size===0&&u.size===0)return null;let l=null;return{identityOf:k,disabled:h,oldByKey:p,newByKey:u,baseTexts:()=>{if(l)return l;l=new Map;let d=T.mergeBase;if(!d)return l;let b;typeof d=="string"?b=new DOMParser().parseFromString(d,"text/html").documentElement:d instanceof Document?b=d.documentElement:b=d;let S=L=>{let B=k(L);B&&!l.has(B.key)&&l.set(B.key,L.textContent)};s(b)&&S(b);for(let L of b.querySelectorAll("script"))S(L);return l}}}function A(f,R,T){let N=f.merge;if(!N)return!1;let O=N.identityOf(R);if(!O||N.disabled.has(O.key))return!1;let k=N.identityOf(T);if(!k||k.key!==O.key)return!1;let h=R,x=T,p=x.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=ht(N.baseTexts().get(O.key),h.textContent,x.textContent,{parse:O.recognizer.parse,keyCandidates:p?p.split(/[\s,]+/).filter(Boolean):void 0});for(let y of l)console.warn(`[hyper-morph] merge "${O.raw}": ${y}`);return h.textContent!==u&&(h.textContent=u),!0}let M={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},q={computeMatches(f,R){let{computeMatches:T}=r.session();return T(f,R)}};function I(f,R,T={}){f=Nn(f);let N=Pt(R),O=Rn(f,N,T),k=O.scripts.handle?new Set(Array.from(f.querySelectorAll("script")).map(u=>i(u,O.scripts.matchMode,O.merge))):null,h=ee(O),x=Q(O,f,N,u=>u.morphStyle==="innerHTML"?(F(u,f,N),Array.from(f.childNodes)):W(u,f,N)),p=u=>{h&&se(O,h),D(O);let l=k?tt(u,k,O):[];return l.length>0?Promise.all(l).then(()=>u):u};return x instanceof Promise?x.then(p):p(x)}function D(f){for(let R of Array.from(f.pantry.childNodes))f.callbacks.beforeNodeRemoved(R)!==!1&&f.callbacks.afterNodeRemoved(R);f.pantry.remove()}function W(f,R,T){let N=Pt(R);return F(f,N,T,R,R.nextSibling),Array.from(N.childNodes)}function ee(f){if(!f.config.restoreFocus)return null;let R=document.activeElement;if(!(R instanceof HTMLInputElement||R instanceof HTMLTextAreaElement))return null;let{id:T,selectionStart:N,selectionEnd:O}=R;return{element:R,id:T,selectionStart:N,selectionEnd:O}}function se(f,R){let T=R.element;if(R.id&&R.id!==document.activeElement?.getAttribute("id")&&(T=f.target.querySelector(`[id="${CSS.escape(R.id)}"]`),T?.focus()),T&&!T.selectionEnd&&R.selectionEnd!=null)try{T.setSelectionRange(R.selectionStart,R.selectionEnd)}catch{}}let F=function(){function f(u,l,y,d=null,b=null){l instanceof HTMLTemplateElement&&y instanceof HTMLTemplateElement&&(l=l.content,y=y.content),d||=l.firstChild;for(let S of y.childNodes){if(n(S))continue;if(d&&d!=b){let B=T(u,S,d,b);if(B){B!==d&&O(u,d,B),ne(B,S,u),d=B.nextSibling;continue}}if(S instanceof Element){let B=S.getAttribute("id");if(u.persistentIds.has(B)){let w=k(l,B,d,u);ne(w,S,u),d=w.nextSibling;continue}if(!u.idMap.has(S)){let w=u.hyperMatches.get(S);if(w&&!u.idMap.has(w)&&!p(w,l)){x(l,w,d),ne(w,S,u),d=w.nextSibling;continue}}}let L=R(l,S,d,u);L&&(d=L.nextSibling)}for(;d&&d!=b;){let S=d;d=d.nextSibling,n(S)||N(u,S)}}function R(u,l,y,d){if(d.callbacks.beforeNodeAdded(l)===!1)return null;if(d.idMap.has(l)){let b=l,S=document.createElementNS(b.namespaceURI,b.localName);return u.insertBefore(S,y),ne(S,l,d),d.callbacks.afterNodeAdded(S),S}else{let b=g(document.importNode(l,!0));return u.insertBefore(b,y),d.callbacks.afterNodeAdded(b),b}}let T=function(){function u(d,b,S,L){let B=b instanceof Element&&!d.idMap.has(b)?d.hyperMatches.get(b):null,w=null,C=b.nextSibling,V=0,_=S;for(;_&&_!=L;){if(n(_)){_=_.nextSibling;continue}if(y(_,b)){if(l(d,_,b)||_===B&&!d.idMap.has(_))return _;if(w===null){let K=_ instanceof Element&&d.hyperMatchedOldElements.has(_);!d.idMap.has(_)&&!K&&(w=_)}}if(w===null&&C&&y(_,C)&&(V++,C=C.nextSibling,V>=2&&(w=void 0)),d.activeElementAndParents.includes(_))break;_=_.nextSibling}return w||null}function l(d,b,S){let L=d.idMap.get(b),B=d.idMap.get(S);if(!B||!L)return!1;for(let w of L)if(B.has(w))return!0;return!1}function y(d,b){let S=d,L=b;return S.nodeType===L.nodeType&&S.tagName===L.tagName&&(!S.getAttribute?.("id")||S.getAttribute?.("id")===L.getAttribute?.("id"))}return u}();function N(u,l){let y=l instanceof Element&&u.hyperMatchedOldElements.has(l)&&!u.idMap.has(l);if(u.idMap.has(l)||y)x(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function O(u,l,y){let d=l;for(;d&&d!==y;){let b=d;d=d.nextSibling,n(b)||N(u,b)}return d}function k(u,l,y,d){let b=d.target.getAttribute?.("id")===l&&d.target||d.target.querySelector(`[id="${CSS.escape(l)}"]`)||d.pantry.querySelector(`[id="${CSS.escape(l)}"]`);return h(b,d),x(u,b,y),b}function h(u,l){let y=u.getAttribute("id");for(;u=u.parentNode;){let d=l.idMap.get(u);d&&(d.delete(y),d.size||l.idMap.delete(u))}}function x(u,l,y){if(u.moveBefore)try{u.moveBefore(l,y)}catch{u.insertBefore(l,y)}else u.insertBefore(l,y)}function p(u,l){let y=l instanceof Element?l:l.realParentNode;return!!y&&u.contains(y)}return f}(),ne=function(){function f(h,x,p){return p.ignoreActive&&h===document.activeElement?null:(p.callbacks.beforeNodeMorphed(h,x)===!1||(h instanceof HTMLHeadElement&&p.head.ignore||(h instanceof HTMLHeadElement&&p.head.style!=="morph"?le(h,x,p):(R(h,x,p),A(p,h,x)||k(h,p)||F(p,h,x))),p.callbacks.afterNodeMorphed(h,x)),h)}function R(h,x,p){let u=x.nodeType;if(u===1){let l=h,y=x,d=l.attributes,b=y.attributes;for(let S of b)O(S.name,l,"update",p)||l.getAttribute(S.name)!==S.value&&l.setAttribute(S.name,S.value);for(let S=d.length-1;0<=S;S--){let L=d[S];if(L&&!y.hasAttribute(L.name)){if(O(L.name,l,"remove",p))continue;l.removeAttribute(L.name)}}k(l,p)||T(l,y,p)}(u===8||u===3)&&h.nodeValue!==x.nodeValue&&(h.nodeValue=x.nodeValue)}function T(h,x,p){if(h instanceof HTMLInputElement&&x instanceof HTMLInputElement&&x.type!=="file"){let u=x.value,l=h.value;N(h,x,"checked",p),N(h,x,"disabled",p),p.formStateSync==="property"&&h.indeterminate!==x.indeterminate&&(h.indeterminate=x.indeterminate),p.formStateSync==="property"?l!==u&&(O("value",h,"update",p)||(h.value=u)):x.hasAttribute("value")?l!==u&&(O("value",h,"update",p)||(h.setAttribute("value",u),h.value=u)):O("value",h,"remove",p)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&x instanceof HTMLOptionElement)N(h,x,"selected",p);else if(h instanceof HTMLTextAreaElement&&x instanceof HTMLTextAreaElement){let u=x.value,l=h.value;if(O("value",h,"update",p)||(u!==l&&(h.value=u),p.formStateSync==="property"))return;h.firstChild&&h.firstChild.nodeValue!==u&&(h.firstChild.nodeValue=u)}}function N(h,x,p,u){let l=x[p],y=h[p];if(l!==y){let d=O(p,h,"update",u);if(d||(h[p]=x[p]),u.formStateSync==="property")return;l?d||h.setAttribute(p,""):O(p,h,"remove",u)||h.removeAttribute(p)}}function O(h,x,p,u){return h==="value"&&u.ignoreActiveValue&&x===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,x,p)===!1}function k(h,x){return!!x.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return f}();function Q(f,R,T,N){if(f.head.block){let O=R.querySelector("head"),k=T.querySelector("head");if(O&&k){let h=le(O,k,f);return Promise.all(h).then(()=>(f.head.block=!1,f.head.ignore=!0,N(f)))}}return N(f)}function ce(f){return f.tagName==="SCRIPT"?!!f.getAttribute("src"):f.tagName==="LINK"?(f.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!f.getAttribute("href"):!1}function le(f,R,T){let N=[],O=[],k=[],h=[],x=T.scripts.matchMode,p=y=>{if(y.tagName==="SCRIPT")return i(y,x,T.merge);if(y.tagName==="LINK"&&x==="smart"){let d=y.getAttribute("href");if(d)try{let b=new URL(d,window.location.href);return`link:${y.getAttribute("rel")||""}:${b.origin}${b.pathname}${b.search}`}catch{}}return y.outerHTML},u=new Map;for(let y of R.children){if(n(y))continue;let d=p(y),b=u.get(d);b||(b=[],u.set(d,b)),b.push(y)}for(let y of f.children){let d=p(y),b=u.get(d),S=!!(b&&b.length),L=T.head.shouldReAppend(y),B=T.head.shouldPreserve(y);if(S||B)if(L)O.push(y);else{if(b&&b.length){let w=b.pop();b.length||u.delete(d),A(T,y,w)}k.push(y)}else T.head.style==="append"?L&&(O.push(y),h.push(y)):T.head.shouldRemove(y)!==!1&&!n(y)&&O.push(y)}for(let y of u.values())h.push(...y);let l=[];for(let y of h){let d=document.createRange().createContextualFragment(y.outerHTML).firstChild;if(T.callbacks.beforeNodeAdded(d)!==!1){if(d instanceof Element&&ce(d)){let b,S=new Promise(function(L){b=L});d.addEventListener("load",function(){b()}),d.addEventListener("error",function(){b()}),l.push(S)}f.appendChild(d),T.callbacks.afterNodeAdded(d),N.push(d)}}for(let y of O)T.callbacks.beforeNodeRemoved(y)!==!1&&(f.removeChild(y),T.callbacks.afterNodeRemoved(y));return T.head.afterHeadMorphed(f,{added:N,kept:k,removed:O}),l}function tt(f,R,T){if(!T.scripts.handle)return[];let N=[],O=[],k=[],h=[],x=T.scripts.matchMode,p=[];for(let l of f)if(l instanceof Element){s(l)&&p.push(l);for(let y of l.querySelectorAll("script"))s(y)&&p.push(y)}for(let l of p){if(l.closest("head")||o(l))continue;let y=i(l,x,T.merge),d=R.has(y),b=T.scripts.shouldPreserve(l),S=T.scripts.shouldReAppend(l);d||b?S?(O.push(l),h.push(l)):k.push(l):h.push(l)}let u=[];for(let l of h){if(T.callbacks.beforeNodeAdded(l)===!1)continue;let y=document.createElement("script");for(let d of l.attributes)y.setAttribute(d.name,d.value);if(y.textContent=l.textContent,y.src){let d,b=new Promise(function(S){d=S});y.addEventListener("load",function(){d()}),y.addEventListener("error",function(){d()}),u.push(b)}l.replaceWith(y),T.callbacks.afterNodeAdded(y),N.push(y)}return T.scripts.afterScriptsHandled(T.target,{added:N,kept:k,removed:O}),u}let Rn=function(){function f(p,u,l){let{persistentIds:y,idMap:d}=h(p,u),b=q.computeMatches(p,u);if(typeof l.key=="function"){let C=new Map,V=new Set,_=P=>{let H=l.key(P);H!=null&&(C.has(H)?V.add(H):C.set(H,P))};p instanceof Element&&_(p);for(let P of p.querySelectorAll("*"))_(P);for(let P of V)C.delete(P);let K=new Map;for(let[P,H]of b)K.set(H,P);let te=u.__hyperMorphRoot||u,Z=new Map,z=new Set,j=P=>{let H=l.key(P);H!=null&&(Z.has(H)?z.add(H):Z.set(H,P))};te instanceof Element&&j(te);for(let P of te.querySelectorAll("*"))j(P);for(let P of z)Z.delete(P);for(let[P,H]of Z){let U=C.get(P);if(!U||U.tagName!==H.tagName)continue;let J=K.get(U);J&&J!==H&&b.delete(J);let ge=b.get(H);ge&&ge!==U&&K.delete(ge),b.set(H,U),K.set(U,H)}}let S=R(l),L=m(p,u,S.scripts);if(L){let C=new Map;for(let[V,_]of b)C.set(_,V);for(let[V,_]of L.newByKey){if(L.disabled.has(V))continue;let K=L.oldByKey.get(V);if(!K)continue;let te=C.get(K);te&&te!==_&&b.delete(te);let Z=b.get(_);Z&&Z!==K&&C.delete(Z),b.set(_,K),C.set(K,_)}}let B=new Set;for(let C of b.values())B.add(C);let w=S.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(w))throw new Error(`Do not understand how to morph style ${w}`);return{target:p,newContent:u,config:S,morphStyle:w,ignoreActive:S.ignoreActive,ignoreActiveValue:S.ignoreActiveValue,restoreFocus:S.restoreFocus,formStateSync:S.formStateSync||"attribute",idMap:d,persistentIds:y,hyperMatches:b,hyperMatchedOldElements:B,merge:L,pantry:T(),activeElementAndParents:N(p),callbacks:S.callbacks,head:S.head,scripts:S.scripts}}function R(p){let u=Object.assign({},M);return Object.assign(u,p),u.callbacks=Object.assign({},M.callbacks,p.callbacks),u.head=Object.assign({},M.head,p.head),u.scripts=Object.assign({},M.scripts,p.scripts),u}function T(){let p=document.createElement("div");return p.hidden=!0,document.body.insertAdjacentElement("afterend",p),p}function N(p){let u=[],l=document.activeElement;if(l?.tagName!=="BODY"&&p.contains(l))for(;l&&(u.push(l),l!==p);)l=l.parentElement;return u}function O(p){let u=Array.from(p.querySelectorAll("[id]"));return p.getAttribute?.("id")&&u.push(p),u}function k(p,u,l,y){for(let d of y){let b=d.getAttribute("id");if(u.has(b)){let S=d;for(;S;){let L=p.get(S);if(L==null&&(L=new Set,p.set(S,L)),L.add(b),S===l)break;S=S.parentElement}}}}function h(p,u){let l=O(p),y=O(u),d=x(l,y),b=new Map;k(b,d,p,l);let S=u.__hyperMorphRoot||u;return k(b,d,S,y),{persistentIds:d,idMap:b}}function x(p,u){let l=new Set,y=new Map;for(let b of p){let S=b.getAttribute("id");y.has(S)?l.add(S):y.set(S,b.tagName)}let d=new Set;for(let b of u){let S=b.getAttribute("id");d.has(S)?l.add(S):y.get(S)===b.tagName&&d.add(S)}for(let b of l)d.delete(b);return d}return f}(),{normalizeElement:Nn,normalizeParent:Pt}=function(){let f=new WeakSet;function R(h){return h instanceof Document?h.documentElement:h}function T(h){if(h==null)return document.createElement("div");if(typeof h=="string")return T(k(h));if(f.has(h))return h;if(h instanceof Node){if(h.parentNode)return new N(h);{let x=document.createElement("div");return x.append(h),x}}else{let x=document.createElement("div");for(let p of[...h])x.append(p);return x}}class N{constructor(x){this.originalNode=x,this.realParentNode=x.parentNode,this.previousSibling=x.previousSibling,this.nextSibling=x.nextSibling}get childNodes(){let x=[],p=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;p&&p!=this.nextSibling;)x.push(p),p=p.nextSibling;return x}querySelectorAll(x){return this.childNodes.reduce((p,u)=>{if(u instanceof Element){u.matches(x)&&p.push(u);let l=u.querySelectorAll(x);for(let y=0;y<l.length;y++)p.push(l[y])}return p},[])}insertBefore(x,p){return this.realParentNode.insertBefore(x,p)}moveBefore(x,p){return this.realParentNode.moveBefore(x,p)}get __hyperMorphRoot(){return this.originalNode}}function O(h){let x=y=>`<${y}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,p=h.replace(/<!--[\s\S]*?-->/g,"");for(let y of["script","style","textarea","title"])p=p.replace(new RegExp(`${x(y)}[\\s\\S]*?</${y}\\s*>`,"gi"),"");let u=new RegExp(`${x("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=p,p=p.replace(u,"");while(p!==l);return p}function k(h){let x=new DOMParser,p=O(h);if(p.match(/<\/html>/)||p.match(/<\/head>/)||p.match(/<\/body>/)){let u=x.parseFromString(h,"text/html");if(p.match(/<\/html>/))return f.add(u),u;{let l=u.firstChild;return l&&f.add(l),l}}else{let l=x.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return f.add(l),l}}return{normalizeElement:R,normalizeParent:T}}(),Dt=Symbol("hyper-morph-duplicate-key"),_t=[f=>f.getAttribute("data-id"),f=>f.getAttribute("id")];function ke(f,R){return R.map(T=>{let N=new Map;for(let O of f){if(O.nodeType!==1)continue;let k=T(O);k==null||k===""||N.set(k,N.has(k)?Dt:O)}return N})}function $t(f,R,T,N){for(let O=0;O<N.length;O++){let k=N[O](f);if(k==null||k===""||R[O].get(k)!==f)continue;let h=T[O].get(k);if(!(!h||h===Dt)&&h.tagName===f.tagName)return h}return null}function Ee(f,R,T){for(let N=0;N<T.length;N++){let O=T[N](f);if(!(O==null||O==="")&&R[N].get(O)===f)return!0}return!1}function kn(f,R,T={}){let N=T.skip||(()=>!1),O=T.ignoreAttr||(()=>!1),k=T.tiers&&T.tiers.length?T.tiers:_t,h=null;function x(){return h||(h=ke([f,...f.querySelectorAll("*")],k)),h}let p=null;function u(){return p||(p=ke([R,...R.querySelectorAll("*")],k)),p}function l(j){return!j.parentElement||!j.parentElement.parentElement}function y(j,P,H){return l(j)||Ee(j,x(),k)?(H.push({type:"subtree",el:j,base:P}),!1):!0}function d(j,P){let H=[];for(let U of j.attributes)O(j,U.name)||P.getAttribute(U.name)!==U.value&&H.push(U.name);for(let U of P.attributes)O(j,U.name)||j.hasAttribute(U.name)||H.push(U.name);return H}function b(j){let P=[],H=null,U=()=>{H!==null&&(P.push({nodeType:3,nodeValue:H}),H=null)};for(let J of j.childNodes){if(J.nodeType===3){H=(H===null?"":H)+J.nodeValue;continue}J.nodeType===1&&N(J)||(U(),(J.nodeType===1||J.nodeType===8)&&P.push(J))}return U(),P}function S(j,P){if(j.nodeType!==P.nodeType)return!1;if(j.nodeType!==1)return!0;if(j.tagName!==P.tagName)return!1;for(let H of k){let U=H(j),J=H(P);if(U!=null&&U!==""&&J!=null&&J!==""&&U!==J)return!1}return!0}function L(j){let P="";for(let H of j)H.nodeType===3&&H.nodeValue.trim()!==""?P+="\0"+H.nodeValue:H.nodeType===8&&(P+=""+H.nodeValue);return P}function B(j,P,H){let U=b(j),J=b(P);if(U.length===J.length){let $=!0;for(let Y=0;Y<U.length;Y++)if(!S(U[Y],J[Y])){$=!1;break}if($){for(let Y=0;Y<U.length;Y++){let xe=U[Y];if(xe.nodeType===1){if(w(xe,J[Y],H))return!0}else if(xe.nodeValue!==J[Y].nodeValue)return!0}return!1}}let ge=U.filter($=>$.nodeType===1),nt=J.filter($=>$.nodeType===1);if(L(U)!==L(J))return!0;let Bt=ke(ge,k),Ft=ke(nt,k),rt=[],ot=new Set,Ut=[];for(let $ of ge){let Y=$t($,Bt,Ft,k);Y&&!ot.has(Y)?(rt.push([$,Y]),ot.add(Y)):Ut.push($)}let ue=[];for(let $ of Ut)Ee($,Bt,k)?H.push({type:"subtree",el:$,base:null}):ue.push($);let Ie=[];for(let $ of nt)ot.has($)||(Ee($,Ft,k)?H.push({type:"deletion",el:$}):Ie.push($));if(ue.length!==Ie.length)return!0;for(let $=0;$<ue.length;$++)if(!S(ue[$],Ie[$]))return!0;let qt=new Map(rt);for(let $=0;$<ue.length;$++)qt.set(ue[$],Ie[$]);let Wt=-1;for(let $ of ge){let Y=qt.get($);if(!Y)continue;let xe=nt.indexOf(Y);if(xe<Wt)return!0;Wt=xe}for(let $=0;$<ue.length;$++)if(w(ue[$],Ie[$],H))return!0;for(let[$,Y]of rt)if(w($,Y,H))return!0;return!1}function w(j,P,H){if(j.tagName!==P.tagName)return y(j,P,H);let U=d(j,P),J=[];if(B(j,P,J))return y(j,P,H);if(U.length){if(!l(j)&&!Ee(P,u(),k))return!0;H.push({type:"attrs",el:j,names:U,base:P})}return H.push(...J),!1}let C=[],V=d(f,R);V.length&&C.push({type:"attrs",el:f,names:V});let _=(j,P)=>Array.from(j.children).find(H=>H.tagName===P)||null,K=_(f,"HEAD"),te=_(R,"HEAD");if(K&&te){let j=[];w(K,te,j),j.length&&C.push({type:"head",el:K})}else(K||te)&&K&&C.push({type:"head",el:K});let Z=_(f,"BODY"),z=_(R,"BODY");return Z&&z?w(Z,z,C):Z&&C.push({type:"subtree",el:Z,base:null}),{entries:C}}function In(f,R,T={}){let N=T.tiers&&T.tiers.length?T.tiers:_t,O=f.documentElement,k=[],h=0,x=w=>({ok:!1,placed:k,held:w,skippedAttrs:h});if(!O)return x(null);function p(w){let C=[w,...w.querySelectorAll("*")];return ke(C,N)}let u=p(O),l=new Map,y=w=>{let C=w.getRootNode(),V=l.get(C);if(!V){let _=C.nodeType===9?C.documentElement:C;V=p(_),l.set(C,V)}return V};function d(w){if(!w.parentElement&&w.tagName==="HTML")return O;if(w.parentElement&&!w.parentElement.parentElement&&w.parentElement.tagName==="HTML"){if(w.tagName==="BODY")return f.body||null;if(w.tagName==="HEAD")return f.head||null}return null}function b(w){let C=d(w);return C||$t(w,y(w),u,N)}function S(w){if(!w)return null;let C=b(w);return C&&C.isConnected?C:null}function L(w){for(let C=0;C<N.length;C++){let V=N[C](w);V!=null&&V!==""&&u[C].set(V,w)}}for(let w of R){if(w.type!=="deletion")continue;let C=b(w.el);C&&C!==O&&C.remove()}let B=R.filter(w=>w.type!=="deletion").sort((w,C)=>w.el===C.el?0:w.el.compareDocumentPosition(C.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let w of B){if(w.type==="head"){let z=f.importNode(w.el,!0);f.head?f.head.replaceWith(z):O.insertBefore(z,O.firstChild),k.push({entry:w,imported:z});continue}if(w.type==="attrs"){let z=S(w.el)||S(w.base);if(!z){h++;continue}for(let j of w.names)w.el.hasAttribute(j)?z.setAttribute(j,w.el.getAttribute(j)):z.removeAttribute(j);continue}let C=w.el;if(d(C))return x(w);let V=S(C)||S(w.base);if(V){let z=f.importNode(C,!0);V.replaceWith(z),L(z),k.push({entry:w,imported:z});continue}if(w.base!=null&&!Ee(w.base,y(w.base),N)||!Ee(C,y(C),N))return x(w);let _=C.parentElement;if(!_)return x(w);let K=S(_);if(!K)return x(w);let te=null;for(let z=C.previousElementSibling;z;z=z.previousElementSibling){let j=S(z);if(j&&j.parentNode===K){te=j;break}}let Z=f.importNode(C,!0);if(te)K.insertBefore(Z,te.nextSibling);else{let z=Array.prototype.indexOf.call(_.children,C);K.insertBefore(Z,K.children[z]||null)}L(Z),k.push({entry:w,imported:Z})}return{ok:!0,placed:k,held:null,skippedAttrs:h}}return{morph:I,defaults:M,findChangedRoots:kn,spliceProtected:In,mergeJson:pt,mergeScriptText:ht,parseJsonRelaxed:Ge,parseRulesRelaxed:nn}}();var io=He.morph,ao=He.defaults,co=He.findChangedRoots,lo=He.spliceProtected;var an=He;function mt(e,t,{onWidgetRemoved:n}={}){an.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Je.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var Ar="hha:upgrade-check:";function ie(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function gt(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function cn(e,t){let n=gt(e),o=gt(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let a=n[i]||0,s=o[i]||0;if(a!==s)return a>s}return!1}function Sr(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Er(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function yt({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(m=>fetch(m)),r=r??Date.now(),!t)return null;let a=ie(t,"hyper-source");if(!a)return null;let s=ie(t,"hyper-version"),c;try{c=new URL(a,n?n.href:void 0)}catch{return null}if(n&&c.origin===n.origin&&c.pathname===n.pathname)return null;let g=`${Ar}${c.href}:${s||"none"}`,v,E=e?null:Sr(g);if(E&&typeof E.checkedAt=="number"&&r-E.checkedAt<i)v=E.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let A=await m.text(),M=new DOMParser().parseFromString(A,"text/html");v=ie(M,"hyper-version")}catch{v=null}Er(g,{checkedAt:r,sourceVersion:v})}return v?{available:cn(v,s||"0.0.0"),currentVersion:s,sourceVersion:v,sourceUrl:c.href}:null}var Ze=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],bt=new Set(Ze),ln=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),un=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Qe={};it(Qe,{EmptyListInsert:()=>Pe,MAX_RULE_DEPTH:()=>Oe,MaxRuleDepthExceeded:()=>be,RuleTargetReadOnly:()=>De,RulesParseError:()=>Te,ShapeMismatch:()=>je,UnknownRulesVersion:()=>ye});var Te=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},ye=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},Oe=20,be=class extends Error{constructor(t){super(`rule depth exceeded ${Oe} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},je=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Pe=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},De=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function ae(e,t,n,o={}){return At(e,t,n,{depth:0,path:[]},o)}function At(e,t,n,o,r){if(o.depth>Oe)throw new be(o.path);if(typeof n=="string")return xr(e,t,n,o,r);if(Array.isArray(n)){let[i,a]=n,s=e.find(t,i,r);return dn(r,o,s),s.map((c,g)=>At(e,c,a,{depth:o.depth+1,path:[...o.path,g]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[a,s]of Object.entries(n))i[a]=At(e,t,s,{depth:o.depth+1,path:[...o.path,a]},r);return i}return null}function xr(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),c=e.find(t,s,r);return dn(r,o,c),c.map(g=>e.text(g))}if(n.startsWith("@"))return fn(e,t,n.slice(1));let i=de(n);if(i!==-1){let s=n.slice(0,i),c=n.slice(i+1),g=s?e.find(t,s,r):[t];return g.length===0?null:fn(e,g[0],c)}if(n===".")return e.text(t);let a=e.find(t,n,r);return a.length===0?null:e.text(a[0])}function dn(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function fn(e,t,n){if(bt.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Mr(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function wr(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var vr={find(e,t,n={}){let o=wr(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Mr(s)));let i=[];n.skip&&i.push(n.skip);let a=n.templateAttr===null?null:n.templateAttr||"cms-template";if(a&&i.push("["+a+"]"),i.length){let s=i.join(", ");r=r.filter(c=>!c.closest||!c.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},X=vr;function St(e){try{return JSON.parse(e)}catch(t){throw new Te(`Invalid strict JSON: ${t.message}`,t)}}function Ae(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let E=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(E=!0),!E){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let E=s,m=a+1;for(;m<r.length&&r[m]!==E;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:E}),a=m+1;continue}let c=a,g;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let E=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let A of E){let M=A.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let E=r[c];for(c++;c<r.length&&r[c]!==E;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;g=r.substring(a,c);let v=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(g)?v=t.NUMBER:g==="true"||g==="false"||g==="null"?v=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(g)&&(v=t.SELECTOR),i.push({type:v,value:g,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let c=s.value;s.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(g,v)=>v.length%2===0?v+'\\"':g)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Te("Invalid extraction rules syntax: "+r.message,r)}}var Et="1",pn=/^[a-zA-Z0-9_-]+$/;function Re(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!pn.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${pn})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],a=e.attr(i,"data-rules-version");if(a!==Et)throw new ye(a);return{rules:Ae(e.text(i)),tagNode:i}}var Tr="script[data-rules-name]";function hn(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function _e(e,t){let n=e.find(t,Tr,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=hn(e.attr(i,"data-rules-name"));if(!a)continue;if(o.has(a)){console.warn(`hyper-html-api: duplicate rules tag name "${a}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==Et)throw new ye(s);o.add(a),r.push({name:a,rules:Ae(e.text(i))})}return r}function Xe(e,t){let n={};for(let{name:o,rules:r}of _e(e,t))n[o]=ae(e,t,r);return n}function xt(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Xe(X,t),version:ie(n,"hyper-version")}}var Ne=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},$e=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},he=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Be=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var mn="text/hyper-upgrade";function Mt(e,t){let n=e.find(t,`script[type="${mn}"]`);if(n.length===0)return null;if(n.length>1)throw new Be(n.length);return e.text(n[0])||null}var Or=new Function("url","return import(url)");async function wt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Or(n)}catch(r){throw new he(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new he("transform must `export default` a function");return o.default}function bn(e,t,n,o){let r=e.length,i=t.length,a=new Array(r).fill(-1);if(o){let I=new Set;for(let D=0;D<r;D++){let W=o[D];!(W>=0&&W<i)||I.has(W)||(a[D]=W,I.add(W))}}if(r===0||i===0)return a;let s=e.map(I=>gn(I,n)),c=t.map(I=>gn(I,n)),g=new Array(i).fill(!1);for(let I of a)I>=0&&(g[I]=!0);let v=new Map;c.forEach((I,D)=>{g[D]||v.set(I,v.has(I)?-1:D)});let E=new Map;s.forEach((I,D)=>{a[D]>=0||E.set(I,(E.get(I)||0)+1)}),s.forEach((I,D)=>{if(a[D]>=0||E.get(I)!==1)return;let W=v.get(I);W===void 0||W===-1||g[W]||(a[D]=W,g[W]=!0)});let m=[];for(let I=0;I<r;I++)a[I]<0&&m.push(I);let A=[];for(let I=0;I<i;I++)g[I]||A.push(I);if(m.length===0||A.length===0)return a;let M=r*i+1,q=(I,D)=>Rr(e[I],t[D],n)*M+Math.abs(I-D);for(let[I,D]of Nr(m,A,q))a[I]=D;return a}var An=e=>typeof e=="object"&&e!==null;function gn(e,t){if(!An(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function Rr(e,t,n){if(!An(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let a=JSON.stringify(e?.[i]),s=JSON.stringify(t?.[i]);a!==s&&r++}return r}function Nr(e,t,n){return e.length<=t.length?yn(e,t,n,!1):yn(t,e,(o,r)=>n(r,o),!0)}function yn(e,t,n,o){let r=e.length,i=t.length,a=[];for(let E=0;E<=r;E++)a.push(new Float64Array(i+1).fill(1/0));let s=[];for(let E=0;E<=r;E++)s.push(new Uint8Array(i+1));for(let E=0;E<=i;E++)a[r][E]=0;for(let E=r-1;E>=0;E--)for(let m=i-1;m>=0;m--){let A=n(e[E],t[m])+a[E+1][m+1],M=a[E][m+1];A<=M?(a[E][m]=A,s[E][m]=1):a[E][m]=M}let c=[],g=0,v=0;for(;g<r&&v<i;)s[g][v]&&(c.push(o?[t[v],e[g]]:[e[g],t[v]]),g++),v++;return c}function Tt(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(F=>e.remove(F)),vt(s,"onRowsApplied",i.path,[]);return}let g=r.length>c.length,v=c[0]||null;if(g&&!v&&(v=Lr(e,t,n,s),!v))throw new Pe(i.path);let E=c.map(F=>Cr(e,F,o,s)),m=null;if(g&&v){m=e.clone(v),s.templateAttr&&e.removeAttr(m,s.templateAttr);let F=e.stripIds(m);F>0&&console.warn(`[hyper-html-api] stripped ${F} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let A=bn(r,E,o,kr(e,c,r,i,s)),M=c[0]||v,q=e.parent(M),I=c.length>0?Sn(e,q,M):0,D=Hr(e,c),W=new Set,ee=[],se=r.map((F,ne)=>{let Q=A[ne];if(Q>=0)return W.add(Q),ee.push(!1),c[Q];ee.push(!0);let ce=e.clone(m);return e.stripIds(ce),ce});c.forEach((F,ne)=>{W.has(ne)||e.remove(F)}),D?se.forEach((F,ne)=>{let Q=I+ne;e.children(q).findIndex(tt=>e.sameNode(tt,F))!==Q&&e.insertAt(q,F,Q)}):jr(e,se,ee,q,I),Ir(e,se,o,r,i,a,s),vt(s,"onRowsApplied",i.path,se)}function vt(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function kr(e,t,n,o,r){let i=vt(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let a=new Array(n.length).fill(-1),s=new Set;for(let c=0;c<n.length;c++)if(i[c]){for(let g=0;g<t.length;g++)if(!(s.has(g)||!e.sameNode(t[g],i[c]))){a[c]=g,s.add(g);break}}return a}function Ir(e,t,n,o,r,i,a){t.forEach((s,c)=>{if(n===null){let g=o[c],v=g==null?"":String(g);e.text(s)!==v&&e.text(s,v)}else{let g=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},a);g&&g!==s&&(t[c]=g)}})}function Cr(e,t,n,o){return n===null?e.text(t):ae(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Sn(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Lr(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let a of i)if(e.attr(a,o.templateAttr)!=null)return a;r=e.parent(r)}return null}function Hr(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let a=o.findIndex(s=>e.sameNode(s,i));if(a===-1)return!1;r.push(a)}return r.sort((i,a)=>i-a),r[r.length-1]-r[0]===r.length-1}function jr(e,t,n,o,r){let i=null,a=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let c=i?e.parent(i):o;if(!c)continue;let g=i?Sn(e,c,i)+1:a++;e.insertAt(c,t[s],g),i=t[s]}}var En=new Set(["checked","selected","disabled","readOnly","paused"]);function me(e,t,n,o,r={}){let i=[];if(Ot(n,o,[],i),i.length)throw new je(i);et(e,t,n,o,{depth:0,path:[]},r)}function et(e,t,n,o,r,i={}){if(r.depth>Oe)throw new be(r.path);if(o===void 0)return t;if(typeof n=="string")return Pr(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return Tt(e,t,a,s,o,r,et,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=et(e,t,s,o==null?o:o[a],{depth:r.depth+1,path:[...r.path,a]},i);c&&c!==t&&(t=c)}return t}return t}function Pr(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return Tt(e,t,c,null,o,r,et,i),t}if(n.startsWith("@"))return Mn(e,t,n.slice(1),o);let a=de(n);if(a!==-1){let c=n.slice(0,a),g=n.slice(a+1),v=c?e.find(t,c,i):[t];return v.length===0||Mn(e,v[0],g,o),t}if(n===".")return xn(e,t,o),t;let s=e.find(t,n,i);return s.length===0||xn(e,s[0],o),t}function xn(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Mn(e,t,n,o){if(un.has(n))throw new De(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return ln.has(n)?(e.prop(t,n,Dr(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function Dr(e,t){return t==null?En.has(e)?!1:"":En.has(e)?t==="false"?!1:!!t:t}function Ot(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:Ue([...n,i]),expected:"scalar",got:Fe(r)})}):o.push({path:Ue(n),expected:"array",got:Fe(t)});return}t!==null&&typeof t=="object"&&o.push({path:Ue(n),expected:"scalar",got:Fe(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Ue(n),expected:"array",got:Fe(t)});return}let r=e[1];t.forEach((i,a)=>Ot(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Ue(n),expected:"object",got:Fe(t)});return}for(let[r,i]of Object.entries(e))Ot(i,t[r],[...n,r],o)}}}function Fe(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Ue(e){return e.join(".")}function qe(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Rt(t,e,n);return Nt(t,e,n),{data:o,summary:n}}function Rt(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>Rt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=Rt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function Nt(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?Nt(e[r],t[r],n):n.discarded+=Se(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Nt(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=Se(t))}}function Se(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Se(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Se(n),0):1}function kt(e,t,n){let o=_e(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},a=new Set;for(let{name:s,rules:c}of o){if(a.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:g,summary:v}=qe(n[s],c);me(e,t,c,g),i[s]=v,r.carriedOver+=v.carriedOver,r.discarded+=v.discarded,r.listItems+=v.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=Se(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function It({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(D=>fetch(D)),!o)throw new Error("upgrade.run requires a document context");if(e=e||ie(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let a=new URL(e,r?r.href:void 0);n=n!==void 0?n:ie(o,"hyper-version"),t=t||Xe(X,o);let s;try{s=await i(a.href)}catch(D){throw new Ne(a.href,D)}if(!s.ok)throw new Ne(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),g=new DOMParser().parseFromString(c,"text/html"),v=ie(g,"hyper-version"),E=t,m=!1,A=Mt(X,g);if(A){let W=await(await wt(A))(E,{fromVersion:n,toVersion:v});if(!W||typeof W!="object"||Array.isArray(W))throw new he("transform must return a plain object map of { rulesName: data }");E=W,m=!0}let{totals:M,byName:q,rulesTagCount:I}=kt(X,g,E);if(I===0&&Object.keys(E).length>0)throw new $e(a.href);return{html:_r(g),fromVersion:n,toVersion:v,summary:{transformApplied:m,totals:M,byName:q}}}function _r(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
4
|
-
`+e.documentElement.outerHTML}function Ct(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return Re(e,o,n)}return null}function wn(e,t,n,o){let r=Ct(e,t,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:a}=r;return{rules:i,tagNode:a,get:()=>ae(e,t,i,o),set:s=>me(e,t,i,s,o)}}var We={extract:(e,t,n)=>ae(X,e,t,n),apply:(e,t,n,o)=>me(X,e,t,n,o),findRulesIn:(e,t)=>Re(X,e,t),findRules:(e,t)=>Ct(X,e,t),bind:(e,t,n)=>wn(X,e,t,n),parseStrict:St,parseRelaxed:Ae,ruleAttrIndex:de,splitRule:we,errors:Qe,DOM_PROPERTIES:Ze},Lt=e=>!!e&&typeof e.nodeType=="number";function vn(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=X.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return Re(X,t).rules}function Ht(e,t){let n=Lt(e)?e:document,o=Lt(e)?t:e;return o===void 0?ae(X,n,vn(n)):We.bind(n,o).get()}function jt(e,t,n){if(!Lt(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?me(X,e,vn(e),t):We.bind(e,n).set(t),e}var Tn={buildForm:ct,bindFormEvents:lt,scaffold:Me,morphForm:mt,path:Ke},On={checkForUpdate:yt,run:It,extractAll:xt,shapeMatch:qe};var Fr={engine:We,cms:Tn,upgrade:On,extractData:Ht,applyData:jt},Ur=Fr;return Pn(qr);})();
|
|
1
|
+
var HyperHtmlApi=(()=>{var jo=Object.defineProperty;var Xs=Object.getOwnPropertyDescriptor;var Zs=Object.getOwnPropertyNames;var Qs=Object.prototype.hasOwnProperty;var Bo=(e,t)=>{for(var n in t)jo(e,n,{get:t[n],enumerable:!0})},ei=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Zs(t))!Qs.call(e,r)&&r!==n&&jo(e,r,{get:()=>t[r],enumerable:!(o=Xs(t,r))||o.enumerable});return e};var ti=e=>ei(jo({},"__esModule",{value:!0}),e);var Kc={};Bo(Kc,{applyData:()=>Dr,cms:()=>qs,default:()=>qc,engine:()=>go,extractData:()=>Hr,upgrade:()=>Ks});var To={};Bo(To,{fromString:()=>xo,getRuleAtPath:()=>_o,getValueAtPath:()=>Jn,parseConfigKey:()=>oi,setAtPath:()=>mn,toConfigKey:()=>ni,toString:()=>Zt});function Zt(e){return e.map(String).join(".")}function ni(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function oi(e){return e===""?[]:e.split(".")}function xo(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function _o(e,t){let n=e;for(let o of t){if(n==null||typeof n=="string")return;if(Array.isArray(n)){if(typeof o!="number"&&o!=="*")return;n=n[1];continue}if(typeof n=="object"){if(typeof o=="number"||!(o in n))return;n=n[o];continue}return}return n}function Jn(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function mn(e,t,n){if(t.length===0)return n;let[o,...r]=t;if(typeof o=="number"){let s=Array.isArray(e)?[...e]:[];return s[o]=mn(s[o],r,n),s}return{...e&&typeof e=="object"?e:{},[o]:mn((e||{})[o],r,n)}}function En(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[n,o]of Object.entries(e))t[n]=En(o);return t}return""}var So=new WeakMap;function dn(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let s=e[r];s==="\\"?r++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:s==="@"&&t===0&&(o=r)}return o}function Cn(e){let t=dn(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}var ri=new Set(["checked","selected","disabled","readOnly","paused"]);function Uo({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),s={rules:e,appRoot:n,cmsRoot:o};return r.appendChild($o({rule:e,value:t,path:[],ctx:s})),r}function Wo(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),Wr.set(e,{rules:t,getData:n,onChange:o}),si()}var Wr=new WeakMap,_r=!1;function si(){_r||(document.addEventListener("input",Ur,!0),document.addEventListener("change",Ur,!0),document.addEventListener("click",ii,!0),_r=!0)}function $r(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&Wr.get(t)||null}function ii(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=$r(t);if(!n)return;let{rules:o,getData:r,onChange:s}=n,c=t.getAttribute("data-hha-action"),l=xo(t.getAttribute("data-hha-path")||"");if(c==="scalar-array-add"){let a=Jn(r(),l)||[];s(mn(r(),l,[...a,""]),{structural:!0});return}if(c==="object-array-add"){let a=_o(o,l);if(!Array.isArray(a))return;let b=Jn(r(),l)||[];s(mn(r(),l,[...b,En(a[1])]),{structural:!0});return}if(c==="array-remove"){if(l.length===0)return;let a=l.slice(0,-1),b=l[l.length-1],p=Jn(r(),a)||[];if(typeof b!="number")return;let g=p.filter((m,u)=>u!==b);s(mn(r(),a,g),{structural:!0})}}function Ur(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=$r(t);if(!n)return;let{getData:o,onChange:r}=n,s=t.closest("[data-hha-path]");if(!s)return;let c=xo(s.getAttribute("data-hha-path")||""),l=t.type==="checkbox"?t.checked:t.value;r(mn(o(),c,l),{structural:!1})}function $o({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?ai({rule:e,value:t,path:n,ctx:o}):li({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return fi({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return ci({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function ci({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",Zt(n)),n.length>0){let s=document.createElement("div");s.className="form-section-label",s.textContent=No(n[n.length-1]),r.appendChild(s)}for(let[s,c]of Object.entries(e)){let l=[...n,s],a=t?.[s];r.appendChild($o({rule:c,value:a,path:l,ctx:o}))}return r}function li({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",Zt(n));let s=document.createElement("div");s.className="field-body";let c=document.createElement("label");c.className="field-label",c.textContent=No(n[n.length-1]||".")+mi(e);let l=di(e,o.appRoot),a=ui(l,{value:t,rule:e,path:n,appRoot:o.appRoot}),b=a.el;return b.classList.add(l.type==="textarea"?"field-textarea":"field-input"),s.appendChild(c),s.appendChild(b),r.appendChild(s),So.set(r,a),r}function ai({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",Zt(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=No(n[n.length-1]),r.appendChild(s);let c=Array.isArray(t)?t:[],l=document.createElement("div");r.appendChild(l),c.forEach((b,p)=>{let g=[...n,p],m=document.createElement("div");m.className="scalar-array-row",m.setAttribute("data-hha-path",Zt(g));let u=document.createElement("input");u.type="text",u.className="field-input",u.value=b==null?"":String(b);let h=document.createElement("button");h.type="button",h.className="array-remove",h.textContent="\xD7",h.title="remove",h.setAttribute("data-hha-action","array-remove"),h.setAttribute("data-hha-path",Zt(g)),m.appendChild(u),m.appendChild(h),l.appendChild(m)});let a=document.createElement("button");return a.type="button",a.className="array-add",a.textContent="+ add",a.setAttribute("data-hha-action","scalar-array-add"),a.setAttribute("data-hha-path",Zt(n)),r.appendChild(a),r}function fi({rule:e,value:t,path:n,ctx:o}){let[,r]=e,s=Array.isArray(t)?t:[],c=document.createElement("div");c.className="form-section",c.setAttribute("data-hha-path",Zt(n));let l=document.createElement("div");l.className="form-section-label",l.textContent=No(n[n.length-1]),c.appendChild(l),s.forEach((b,p)=>{let g=[...n,p],m=document.createElement("div");m.className="array-card",m.setAttribute("data-hha-path",Zt(g));let u=document.createElement("button");u.type="button",u.className="array-remove",u.textContent="\xD7",u.title="remove item",u.setAttribute("data-hha-action","array-remove"),u.setAttribute("data-hha-path",Zt(g)),m.appendChild(u);let h=$o({rule:r,value:b,path:g,ctx:o});h.querySelector(".form-section-label")?.remove(),m.appendChild(h),c.appendChild(m)});let a=document.createElement("button");return a.type="button",a.className="array-add",a.textContent="+ add",a.setAttribute("data-hha-action","object-array-add"),a.setAttribute("data-hha-path",Zt(n)),c.appendChild(a),c}function ui(e,t){let n=pi(e);if(e.type==="select"&&e.options)for(let o of e.options){let r=document.createElement("option");r.value=o.value,r.textContent=o.text,String(t.value)===o.value&&(r.selected=!0),n.appendChild(r)}else e.type==="checkbox"?n.checked=t.value===!0||t.value==="true"||t.value==="checked":(e.type,n.value=t.value==null?"":String(t.value));return{el:n,destroy(){},focus(){n.focus()},validate(){}}}function di(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):n=Cn(e).prop,n&&ri.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=hi(e,t);if(!o)return{type:"text"};let r=(o.tagName||"").toLowerCase();if(r==="textarea")return{type:"textarea"};if(r==="select")return{type:"select",options:Array.from(o.querySelectorAll("option")).map(l=>({value:l.getAttribute("value")||l.textContent,text:l.textContent.trim()||l.getAttribute("value")||""}))};if(r==="input"){let c=(o.getAttribute("type")||"text").toLowerCase();if(c==="checkbox"||c==="radio")return{type:"checkbox"};if(c==="number")return{type:"number"}}let s=(o.textContent||"").trim();return s.length>60||s.includes(`
|
|
2
|
+
`)?{type:"textarea"}:{type:"text"}}function hi(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=Cn(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function pi(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function No(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function mi(e){return` \xB7 ${e}`}function Oo(e,t){if(typeof e=="string"){let n=t&&t.defaultView,o=n&&n.DOMParser||globalThis.DOMParser;return new o().parseFromString(e,"text/html")}if(e&&e.nodeType===9)return e;throw new TypeError("expected an HTML string or a Document")}function Fo(e){let t=new Map;return(n,o)=>{if(typeof o!="string")return Oo(o,e);let r=t.get(n);if(r&&r.text===o)return r.doc;let s=Oo(o,e);return t.set(n,{text:o,doc:s}),s}}function Fr(e,t){let n=t.doctype;if(!n)return!1;let o=e.doctype;if(o&&o.name===n.name&&o.publicId===n.publicId&&o.systemId===n.systemId)return!1;let r=e.implementation.createDocumentType(n.name,n.publicId,n.systemId);return o?e.replaceChild(r,o):e.insertBefore(r,e.documentElement),!0}function Vo(e,t=[]){if(typeof e!="function")return()=>!1;let n=new WeakMap,o=new Set(t);return r=>{if(!r||r.nodeType!==1)return!1;let s=n.get(r);if(s!==void 0)return s;let c=[],l=r,a=!1;for(;l&&l.nodeType===1;){let b=n.get(l);if(b!==void 0){a=b;break}if(c.push(l),e(l,o.has(l))){a=!0;break}if(o.has(l))break;l=l.parentElement}for(let b of c)n.set(b,a);return a}}var gi="~",Vr="^";function zo(e,t){let n=new WeakMap;if(!e||!t||typeof t!="object"||Array.isArray(t))return n;let o=t[gi],r=typeof o=="string"?o.split(",").map(Number):null,s=r&&typeof t[Vr]=="string"?t[Vr].split(","):null,c=g=>Number.isInteger(g)&&g>=0,l=0,a=!1,b=g=>{let m=g;for(;m>0;){let u=r[l++];if(l>r.length||!c(u))return!1;m+=u-1}return!0},p=(g,m)=>{if(a)return;if(r){let y=l++,S=r[y];if(y>=r.length||!c(S)){a=!0;return}let v=!s||s[y]===g.tagName.toLowerCase();if(!v||S!==g.children.length){let D=v&&t[m];typeof D=="string"&&D&&n.set(g,D),b(S)||(a=!0);return}}let u=t[m];typeof u=="string"&&u&&n.set(g,u);let h=g.children;for(let y=0;y<h.length;y++)p(h[y],m===""?String(y):`${m}.${y}`)};return p(e,""),n}function zr(e){return t=>{for(let n of e){let o=n(t);if(typeof o=="string"&&o!=="")return o}return null}}var wn=zr([e=>e.getAttribute("data-id"),e=>e.getAttribute("id")]);function Mo(e,t,n,o=null){let r=new Map,s=new Set,c=l=>{if(n(l))return;let a=t(l);a&&(r.has(a)?s.add(a):r.set(a,l))};if(o){let l=a=>{for(let b of a.querySelectorAll(o))c(b);for(let b of a.querySelectorAll("template"))b.content&&l(b.content)};c(e),l(e.tagName==="TEMPLATE"&&e.content?e.content:e)}else{let l=a=>{c(a);let b=a.tagName==="TEMPLATE"&&a.content?a.content.children:a.children;for(let p=0;p<b.length;p++)l(b[p])};l(e)}for(let l of s)r.delete(l),l.startsWith("merge:")&&console.warn(`[hyper-morph] merge disabled for duplicate identity "${l.slice(l.indexOf(":",6)+1)}"`);return r}var bi=new Set(["href","src","name","type","role"]),Kr=new Set(["SCRIPT","STYLE","TEXTAREA","TEMPLATE","IFRAME","OBJECT","CANVAS","VIDEO","AUDIO","svg","SVG"]);function Ln(e,t=5381){let n=t;for(let o=0;o<e.length;o++)n=(n<<5)+n^e.charCodeAt(o);return n>>>0}function qr(e){return e.replace(/\s+/g," ")}function Gr({ignored:e=()=>!1,ignoreAttribute:t=()=>!1}={}){let n=new WeakMap,o=new WeakMap;function r(m){let u=m.attributes,h=u.length;if(h===0)return{all:"",sig:m.tagName+"|"};let y=[],S="",v=[];for(let D=0;D<h;D++){let q=u[D],Z=q.name;t(m,Z)||y.push(Z+"="+q.value),Z==="class"?S=q.value.indexOf(" ")<0?q.value:q.value.split(/\s+/).filter(Boolean).sort().join(" "):bi.has(Z)&&v.push(Z+"="+q.value)}return y.length>1&&y.sort(),v.length>1&&v.sort(),{all:y.join(""),sig:m.tagName+"|"+S+(v.length?"|"+v.join("|"):"")}}function s(m){return m.nodeType===1&&m.tagName==="TEMPLATE"&&m.content?m.content.childNodes:m.childNodes}function c(m){let u=n.get(m);if(u)return u;if(m.nodeType===3)u={hash:"T"+Ln(m.nodeValue),hint:qr(m.nodeValue).slice(0,64),sig:null,tok:null};else if(m.nodeType===8)u={hash:"C"+Ln(m.nodeValue),hint:"",sig:null,tok:null};else if(m.nodeType===1){let h=r(m),y=Ln(m.tagName+""+h.all),S="";for(let v of a(m))if(v.nodeType===1){let D=c(v);y=Ln(D.hash,y),S.length<64&&(S+=" "+D.hint)}else y=Ln(b(v),y),v.kind==="text"&&S.length<64&&(S+=v.value.slice(0,64));u={hash:"E"+y,hint:qr(S).trim().slice(0,64),sig:h.sig,tok:null}}else u={hash:"N"+m.nodeType,hint:"",sig:null,tok:null};return n.set(m,u),u}function l(m){if(!m.tok){m.tok=new Set;for(let u of m.hint.toLowerCase().split(/[^\p{L}\p{N}]+/u))u&&m.tok.add(u)}return m.tok}function a(m){let u=o.get(m);if(u)return u;u=[];let h=null,y=()=>{h&&(h.value=h.nodes.map(S=>S.nodeValue).join(""),u.push(h),h=null)};for(let S of s(m)){if(S.nodeType===3){h||(h={kind:"text",nodes:[],value:"",parent:m,hash:void 0}),h.nodes.push(S);continue}y(),S.nodeType===8?u.push({kind:"comment",nodes:[S],value:S.nodeValue,parent:m,hash:void 0}):S.nodeType===1&&!e(S)&&u.push(S)}return y(),o.set(m,u),u}function b(m){return m.nodeType===1?c(m).hash:(m.hash===void 0&&(m.hash=(m.kind==="text"?"T":"C")+Ln(m.value)),m.hash)}function p(m,u){let h=l(c(m)),y=l(c(u));if(h.size===0&&y.size===0)return{coef:1,share:1};if(h.size===0||y.size===0)return null;let S=0;for(let v of h)y.has(v)&&S++;return{coef:S/Math.min(h.size,y.size),share:S/Math.max(h.size,y.size)}}function g(m,u){let h=p(m,u);return!!h&&h.coef>=.5}return{meta:c,unitsOf:a,unitHash:b,similar:g,score:p,childrenOf:s}}var Jr=16,yi=2e3,ki=3,wi={align:0};function qo(e,t,n){let{meta:o,unitsOf:r,unitHash:s,similar:c,score:l}=n.analyzer,a=n.baseId||(()=>null),b=n.sideId||(()=>null),p=new Map,g=new Map,m=new Set,u=new Map,h=new Set,y=new Set,S=new Set,v=[],D=[],q=[],Z=[],ae=yi,ie=new Map,he=new Map,K=(f,T)=>{p.set(f,T),g.set(T,f)},J=f=>!!f&&f.nodeType===1,ye=(f,T)=>{let x=u.get(f);return!!x&&x.has(T)},je=f=>Kr.has(f.tagName),Fe=(f,T)=>{let x=a(f);if(!x)return!0;let B=b(T);return!B||x===B},ot=globalThis.__hyperMorphProfile,ct=ot?performance.now():0;ot&&(o(e),o(t),ot.meta=(ot.meta||0)+(performance.now()-ct),ct=performance.now()),K(e,t);for(let[f,T]of n.baseIndex){let x=n.sideIndex.get(f);x&&x.tagName===T.tagName&&!p.has(T)&&!g.has(x)&&K(T,x)}Z.push([e,t]);for(let[f,T]of p)J(f)&&f!==e&&Z.push([f,T]);return dt(),Ct(),ot&&(ot.align=(ot.align||0)+(performance.now()-ct)),{map:p,reverse:g,moved:h,identical:y,pairIdenticalChildren:F,weak:m,unpair:vt,rematch:Ct,insertedByHash:Oe};function Ct(){at(),dt();for(let f=0;f<q.length;){let T=q.length;rt(f,T),f=T,dt(),at(),dt()}}function vt(f){let T=p.get(f);if(!T)return;u.has(f)||u.set(f,new Set),u.get(f).add(T);let x=(I,E)=>{p.delete(I),g.delete(E),h.delete(I),y.delete(I),m.delete(I),S.delete(I)},B=(I,E)=>{for(let j of r(I)){let M=p.get(j);!M||!(J(M)?E.contains(M):E.contains(M.nodes[0]))||(x(j,M),J(j)&&B(j,M))}};x(f,T),J(f)&&B(f,T),v.push(f),D.push(T)}function Oe(){let f=new Map;for(let T of new Set(D)){if(g.has(T))continue;let x=o(T).hash;f.has(x)||f.set(x,[]),f.get(x).push(T)}return f}function dt(){for(;Z.length;){let[f,T]=Z.shift();S.has(f)||y.has(f)||Lt(f,T)}}function Qe(f,T){if(!je(f))for(let x of r(f))J(x)&&(T.push(x),Qe(x,T))}function Lt(f,T){S.add(f);let x=r(f),B=r(T);wi.align+=x.length+B.length,ie=new Map,he=new Map;for(let P=0;P<x.length;P++)ie.set(x[P],P);for(let P=0;P<B.length;P++)he.set(B[P],P);if(f.tagName==="HTML")for(let P of["HEAD","BODY"]){let Y=x.find(we=>J(we)&&we.tagName===P),Q=B.find(we=>J(we)&&we.tagName===P);Y&&Q&&!p.has(Y)&&!g.has(Q)&&K(Y,Q)}for(let P=0;P<x.length&&P<B.length;P++){let Y=x[P],Q=B[P];p.has(Y)||g.has(Q)||(J(Y)?J(Q)&&Y.tagName===Q.tagName&&Y.isEqualNode(Q)&&O(Y,Q):!J(Q)&&Y.kind===Q.kind&&Y.value===Q.value&&O(Y,Q))}Ze(x,B);let I=x.filter(P=>!p.has(P)),E=B.filter(P=>!g.has(P));I.length&&E.length&&(lt(I,E),ke(I,E),re(I,E,x,B),qe(x,B));let j=!1,M=!1;for(let P of x){if(!p.has(P)){J(P)&&(v.push(P),Qe(P,v),j=!0);continue}J(P)&&!y.has(P)&&Z.push([P,p.get(P)])}for(let P of B)!g.has(P)&&J(P)&&(D.push(P),Qe(P,D),M=!0);j&&M&&q.push([f,T])}function rt(f,T){for(let x=f;x<T;x++){let[B,I]=q[x],E=r(B),j=r(I),M=new Map,P=new Map,Y=null;for(let Q of E)J(Q)&&(p.has(Q)?Y=Q:(M.has(Y)||M.set(Y,[]),M.get(Y).push(Q)));Y=null;for(let Q of j)J(Q)&&(g.has(Q)?Y=g.get(Q):(P.has(Y)||P.set(Y,[]),P.get(Y).push(Q)));for(let[Q,we]of M){let Ye=P.get(Q);if(!(!Ye||we.length!==Ye.length)&&we.every((bt,ft)=>Ye[ft].tagName===bt.tagName&&Fe(bt,Ye[ft])&&!ye(bt,Ye[ft])))for(let bt=0;bt<we.length;bt++)et(we[bt],Ye[bt])}}}function et(f,T){K(f,T),m.add(f),Z.push([f,T]),dt()}function lt(f,T){let x=Rn(f,s),B=Rn(T,s),I=new Map;for(let E of T){let j=s(E);B.get(j)===1&&I.set(j,E)}for(let E of f){if(p.has(E))continue;let j=s(E);if(x.get(j)!==1)continue;let M=I.get(j);M&&!g.has(M)&&O(E,M)}}function O(f,T){K(f,T),y.add(f),J(f)&&S.add(f)}function F(f){let T=p.get(f);if(!T||!J(f))return;let x=r(f),B=r(T);for(let I=0;I<x.length&&I<B.length;I++)p.has(x[I])||O(x[I],B[I])}function ke(f,T){let x=j=>J(j)&&!je(j)?o(j).sig+""+o(j).hint:null,B=Rn(f,x),I=Rn(T,x),E=new Map;for(let j of T){let M=x(j);M!=null&&I.get(M)===1&&E.set(M,j)}for(let j of f){if(p.has(j))continue;let M=x(j);if(M==null||B.get(M)!==1)continue;let P=E.get(M);P&&!g.has(P)&&Fe(j,P)&&K(j,P)}}function re(f,T,x,B){let I=new Map;for(let j of T){if(!J(j)||g.has(j)||je(j))continue;let M=o(j).sig;I.has(M)||I.set(M,[]),I.get(M).push({el:j,index:he.get(j)})}let E=[];for(let j of f){if(p.has(j)||!J(j)||je(j))continue;let M=I.get(o(j).sig);if(!M||!M.length)continue;let P=ie.get(j),Y=M.filter(Q=>!g.has(Q.el)).map(Q=>({c:Q,d:Math.abs(Q.index-P)}));Y.sort((Q,we)=>Q.d-we.d),Y.length>Jr&&(Y=Y.slice(0,Jr));for(let{c:Q,d:we}of Y){if(!Fe(j,Q.el))continue;let Ye=l(j,Q.el);Ye&&Ye.coef>=.5&&E.push({b:j,s:Q.el,coef:Ye.coef,share:Ye.share,d:we,bi:P})}}E.sort((j,M)=>M.coef-j.coef||M.share-j.share||j.d-M.d||j.bi-M.bi);for(let j of E)!p.has(j.b)&&!g.has(j.s)&&K(j.b,j.s)}function Ne(f,T){return J(f)!==J(T)?!1:J(f)?f.tagName!==T.tagName||!Fe(f,T)?!1:je(f)||o(f).hint===""||o(T).hint===""?!0:c(f,T):f.kind===T.kind}function tt(f,T){let x=(I,E)=>{let j=E===null?-1:I===T?he.get(E):ie.get(E),M=I[j+1];return M&&!J(M)?M:null},B=null;for(let I of f){if(J(I)){B=I;continue}if(p.has(I))continue;let E=B===null?null:p.get(B);if(B!==null&&!E)continue;let j=x(T,E);j&&!g.has(j)&&j.kind===I.kind&&K(I,j)}}function qe(f,T){tt(f,T);let x=Ke(f,T),B=(E,j)=>J(E)&&o(E).hint!==""&&o(j).hint===""&&!!j.querySelector("br")&&!x(E,j),I=0;for(let E of f){if(p.has(E)){let M=he.get(p.get(E));M!==void 0&&M>=I&&(I=M+1);continue}let j=0;for(let M=I;M<T.length&&j<ki;M++){let P=T[M];if(!g.has(P)&&(j++,Ne(E,P)&&!ye(E,P)&&!B(E,P))){K(E,P),J(E)&&(o(E).hint===""||o(P).hint==="")&&m.add(E),I=M+1;break}}}Ze(f,T)}function Ke(f,T){let x=(B,I,E)=>{for(let j=I-1;j>=0;j--)if(J(B[j])&&E(B[j]))return B[j];return null};return(B,I)=>{let E=ie.get(B),j=he.get(I);if(E===j)return!0;let M=x(f,E,Y=>p.has(Y)),P=x(T,j,Y=>g.has(Y));return M?p.get(M)===P:!P}}function Ze(f,T){let x=f.filter(M=>J(M)&&!p.has(M)),B=T.filter(M=>J(M)&&!g.has(M));if(!x.length||!B.length)return;let I=Rn(x,M=>M.tagName),E=Rn(B,M=>M.tagName),j=Ke(f,T);for(let M of x){let P=M.tagName;if(I.get(P)!==1||E.get(P)!==1)continue;let Y=B.find(Q=>Q.tagName===P);Y&&!g.has(Y)&&j(M,Y)&&Fe(M,Y)&&!ye(M,Y)&&(K(M,Y),m.add(M))}}function at(){let f=new Map;for(let M of m)if(J(M)&&J(p.get(M))){let P=o(M).hash;f.has(P)||f.set(P,[]),f.get(P).push(M)}if(f.size)for(let M of D){if(g.has(M)||!J(M))continue;let P=f.get(o(M).hash),Y=P&&P.find(Q=>m.has(Q)&&!ye(Q,M)&&Fe(Q,M));Y&&(vt(Y),O(Y,M),h.add(Y))}let T=new Map,x=new Map,B=new Map;for(let M of m){let P=p.get(M);J(M)&&J(P)&&B.set(P,M)}let I=(M,P)=>{if(!g.has(M))return!0;let Y=B.get(M);return Y===g.get(M)&&Y!==P&&!Y.contains(P)},E=M=>{if(g.has(M)){let P=B.get(M);B.delete(M),vt(P)}};for(let M of[...D,...B.keys()]){if(g.has(M)&&!B.has(M))continue;let P=o(M).hash;if(T.has(P)||T.set(P,[]),T.get(P).push(M),je(M))continue;let Y=o(M).sig;x.has(Y)||x.set(Y,[]),x.get(Y).push(M)}let j=new Set;for(let M of m){let P=p.get(M);!J(M)||!J(P)||je(M)||o(M).hint===""||o(P).hint===""||c(M,P)||j.add(M)}for(let M of[...v,...j]){let P=p.get(M);if(P&&!(m.has(M)&&j.has(M)))continue;let Y=ft=>{P&&vt(M),E(ft)},Q=T.get(o(M).hash);if(Q){let ft=Q.find(le=>le!==P&&I(le,M)&&!ye(M,le));if(ft){Y(ft),O(M,ft),h.add(M);continue}}if(je(M)||ae<=0)continue;let we=x.get(o(M).sig);if(!we)continue;let Ye=null,bt=0;for(let ft of we)if(!(ft===P||!I(ft,M)||!Fe(M,ft)||ye(M,ft))&&(ae--<=0||c(M,ft)&&(bt++,Ye=ft,bt>1)))break;bt===1&&(Y(Ye),K(M,Ye),h.add(M),Z.push([M,Ye]))}}}function Rn(e,t){let n=new Map;for(let o of e){let r=t(o);r!=null&&n.set(r,(n.get(r)||0)+1)}return n}var Ai={diff:0},Yr=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null,xi=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u,Ti=/[\p{L}\p{M}\p{N}_'’]+|\s+|[\s\S]/gu,Si=/\P{M}\p{M}*/gu;function Xo(e){if(e==="")return[];if(Yr){let n=[];for(let o of Yr.segment(e))n.push(o.segment);return n}let t=[];for(let n of e.match(Ti))if(xi.test(n))for(let o of n.match(Si))t.push(o);else t.push(n);return t}var Ni=/^[ ]+$/,Oi=e=>Ni.test(e)?" ".repeat(e.length):e,Yn=e=>typeof e.k=="string"&&/^\s+$/.test(e.k),nt="",Xr=e=>e.every(t=>Yn(t)||t.k===nt),Mi=/^[\x00-\x7f\u00A0]*$/,vi=/[A-Za-z0-9_']+|[ \u00A0]+|\s|./g;function Ii(e){return e===""?[]:e.match(vi)}function An(e,t=!1){return(t?Ii(e):Xo(e)).map(n=>({k:Oi(n),raw:n,len:n.length}))}var vo=(...e)=>e.every(t=>Mi.test(t));function Ko(e,t,n){let o=e.length,r=t.length,s=Math.min(o+r,n),c=s+1,l=new Int32Array(2*s+3),a=[],b=o===0&&r===0;for(let u=0;u<=s&&!b;u++){a.push(l.slice(c-u,c+u+1));for(let h=-u;h<=u;h+=2){let y;h===-u||h!==u&&l[c+h-1]<l[c+h+1]?y=l[c+h+1]:y=l[c+h-1]+1;let S=y-h,v=y;for(;y<o&&S<r&&e[y].k===t[S].k;)y++,S++;if(Ai.diff+=1+y-v,l[c+h]=y,y>=o&&S>=r){b=!0;break}}}if(!b)return null;let p=[],g=o,m=r;for(let u=a.length-1;u>0;u--){let h=a[u],y=g-m,S=y+u,v=y===-u||y!==u&&h[S-1]<h[S+1]?y+1:y-1,D=h[v+u],q=D-v;for(;g>D&&m>q;)p.push([0,g-1,m-1]),g--,m--;g===D?(p.push([1,g,m-1]),m--):(p.push([-1,g-1,m]),g--)}for(;g>0&&m>0;)p.push([0,g-1,m-1]),g--,m--;return p.reverse(),p}function Ei(e,t,n){let o=g=>g.k===nt;if(!e.some(o)&&!t.some(o))return Ko(e,t,n);let r=[],s=[];for(let g=0;g<e.length;g++)o(e[g])||r.push(g);for(let g=0;g<t.length;g++)o(t[g])||s.push(g);let c=Ko(r.map(g=>e[g]),s.map(g=>t[g]),n);if(!c)return null;let l=[],a=0,b=0,p=(g,m)=>{for(;a<g&&b<m&&e[a].k===t[b].k;)l.push([0,a++,b++]);let u=Ko(e.slice(a,g),t.slice(b,m),n);if(!u)return!1;for(let[h,y,S]of u)l.push([h,y+a,S+b]);return a=g,b=m,!0};for(let[g,m,u]of c)if(g===0){if(!p(r[m],s[u]))return null;l.push([0,a,b]),a++,b++}return p(e.length,t.length)?l:null}function Pn(e,t,n=4e3){let o=[],r=0;for(;r<e.length&&r<t.length&&e[r].k===t[r].k;)e[r].raw!==t[r].raw&&o.push({bi:r,tok:t[r]}),r++;let s=0;for(;s<e.length-r&&s<t.length-r&&e[e.length-1-s].k===t[t.length-1-s].k;)e[e.length-1-s].raw!==t[t.length-1-s].raw&&o.push({bi:e.length-1-s,tok:t[t.length-1-s]}),s++;let c=e.slice(r,e.length-s),l=t.slice(r,t.length-s),a=Di(c,l)?null:Ei(c,l,n);if(!a){let v=c.length||l.length?[{bs:r,be:r+c.length,toks:l}]:[];return{hunks:v,cosmetic:o,coarse:!0,parts:v.map(D=>({...D,gap:[],group:0})),cosmeticEq:o}}let b=[],p=(v,D)=>{c[v].raw!==l[D].raw&&o.push({bi:r+v,tok:l[D]})},g=null,m=[],u=0,h=0,y=()=>{g&&b.push(g),g=null;for(let[v,D]of m)p(v,D);m=[],u++};for(let[v,D,q]of a){if(v===0){g&&Yn(c[D])&&!c[D].k.includes(`
|
|
3
|
+
`)?m.push([D,q]):(y(),p(D,q)),h=D+1;continue}(!g||m.length)&&(g&&b.push(g),g={bs:r+h,be:r+h,toks:[],gap:m.map(([Z,ae])=>({bi:r+Z,tok:l[ae]})),group:u},m=[]),v===-1?(g.be=r+h+1,h=D+1):g.toks.push(l[q])}y(),Ci(b,e);let S=Jo(b);return{hunks:S.hunks,cosmetic:o.concat(S.cosmetic),parts:b,cosmeticEq:o}}function Ci(e,t){for(let n=0;n<e.length;n++){let o=e[n];if(o.gap.length)continue;let r=n+1<e.length?e[n+1].bs:1/0;if(o.toks.length){if(o.bs===o.be)for(;o.bs+1<r&&o.bs<t.length&&o.toks[0].k===nt&&t[o.bs].k===nt;)o.toks=[...o.toks.slice(1),o.toks[0]],o.bs++,o.be++}else for(;o.be+1<r&&o.be<t.length&&t[o.bs].k===nt&&t[o.be].k===nt;)o.bs++,o.be++}}function Jo(e,t=()=>!1){let n=[],o=[],r=null,s=-1;for(let c of e){let l=t(c);if(r&&!r.alone&&!l&&c.group===s){r.be=c.be;for(let a of c.gap)r.toks.push(a.tok);for(let a of c.toks)r.toks.push(a);continue}r&&n.push({bs:r.bs,be:r.be,toks:r.toks});for(let a of c.gap)o.push(a);r={bs:c.bs,be:c.be,toks:c.toks.slice(),alone:l},s=c.group}return r&&n.push({bs:r.bs,be:r.be,toks:r.toks}),{hunks:n,cosmetic:o}}var Li=(e,t)=>e.bs===t.bs&&e.be===t.be&&Qo(e.toks,t.toks);function Zo(e,t,n){let o=p=>g=>p.some(m=>Li(g,m)),r=Jo(e.parts,o(t.parts)),s=Jo(t.parts,o(e.parts)),c=e.cosmeticEq.concat(r.cosmetic),l=t.cosmeticEq.concat(s.cosmetic),[a,b]=n?Ri(r.hunks,s.hunks,n,c,l):[r.hunks,s.hunks];return{lh:a,rh:b,cosL:c,cosR:l}}function Ri(e,t,n,o,r){let s=(u,h)=>u.k===h.k&&u.raw===h.raw,c=[{list:e.map(u=>({...u})),resp:new Set(o.map(u=>u.bi))},{list:t.map(u=>({...u})),resp:new Set(r.map(u=>u.bi))}],l=u=>u.bs===u.be,a=(u,h,y,S)=>{let v=u.list[h];if(!l(v))return S(v)===y?v.toks:null;let D=h?u.list[h-1].be:0,q=h+1<u.list.length?u.list[h+1].bs:n.length;if(y<D||y>q)return null;let Z=v.toks,ae=v.bs;for(;ae>y;){let ie=Z[Z.length-1];if(!s(ie,n[ae-1])||u.resp.has(ae-1))return null;Z=[ie,...Z.slice(0,-1)],ae--}for(;ae<y;){if(!s(Z[0],n[ae])||u.resp.has(ae))return null;Z=[...Z.slice(1),Z[0]],ae++}return Z},b=(u,h,y,S,v,D)=>{let q=u.list[h],Z=v?y.slice(y.length-S):y.slice(0,S),ae=v?y.slice(0,y.length-S):y.slice(S),ie={bs:D,be:D,toks:Z};if(l(q)){if(!ae.length){u.list[h]=ie;return}let K={bs:D,be:D,toks:ae};v&&(K.lead=!0),u.list.splice(h,1,...v?[K,ie]:[ie,K]);return}let he={bs:q.bs,be:q.be,toks:ae};u.list.splice(h,1,...v?[he,ie]:[ie,he])},p=(u,h,y,S,v)=>{let D=u.list[h],q=v?y.slice(y.length-S):y.slice(0,S),Z=v?y.slice(0,y.length-S):y.slice(S),ae={bs:D.bs,be:D.be,toks:q};if(!Z.length){u.list[h]=ae;return}let ie=v?{bs:D.bs,be:D.bs,toks:Z,lead:!0}:{bs:D.be,be:D.be,toks:Z};u.list.splice(h,1,...v?[ie,ae]:[ae,ie])},g=c[0],m=c[1];for(let u=0;u<64;u++){let h=!1;e:for(let y=0;y<g.list.length;y++)for(let S=0;S<m.list.length;S++){let v=g.list[y],D=m.list[S];if(!(v.bs===D.bs&&v.be===D.be&&Qo(v.toks,D.toks)))for(let q of[!0,!1]){let Z=ie=>q?ie.be:ie.bs,ae=l(v)?[Z(D),v.bs]:[Z(v)];for(let ie of ae){let he=a(g,y,ie,Z),K=he&&a(m,S,ie,Z);if(!K)continue;let J=(ct,Ct)=>q?ct[ct.length-1-Ct]:ct[Ct],ye=0;for(;ye<he.length&&ye<K.length&&J(he,ye).k===J(K,ye).k;)ye++;if(!ye)continue;let je=q?he.slice(0,he.length-ye):he.slice(ye),Fe=q?K.slice(0,K.length-ye):K.slice(ye);if(!(ye<he.length&&ye<K.length&&!Xr(je)&&!Xr(Fe)&&(l(v)&&l(D)||v.bs===D.bs&&v.be===D.be)||!(q?he.slice(he.length-ye):he.slice(0,ye)).some(ct=>!Yn(ct)))){if(ye===he.length&&ye===K.length&&l(v)&&l(D)){if(v.bs===ie&&D.bs===ie)continue;g.list[y]={bs:ie,be:ie,toks:he},m.list[S]={bs:ie,be:ie,toks:K}}else!l(v)&&v.bs===D.bs&&v.be===D.be?(p(g,y,he,ye,q),p(m,S,K,ye,q)):(b(g,y,he,ye,q,ie),b(m,S,K,ye,q,ie));h=!0;break e}}}}if(!h)break}return[g.list,m.list]}var Pi=48,Hi=.3;function Di(e,t){let n=e.filter(c=>!Yn(c)),o=t.filter(c=>!Yn(c));if(Math.min(n.length,o.length)<Pi)return!1;let r=new Map;for(let c of n)r.set(c.k,(r.get(c.k)||0)+1);let s=0;for(let c of o){let l=r.get(c.k);l>0&&(s++,r.set(c.k,l-1))}return s/Math.min(n.length,o.length)<Hi}var ji=(e,t)=>{let n=new Set;for(let o of e.toks)typeof o.k!="string"&&n.add(o.k.el);for(let o=e.bs;o<e.be;o++)typeof t[o].k!="string"&&n.add(t[o].k.el);return n},Qo=(e,t)=>e.length===t.length&&e.every((n,o)=>n.k===t[o].k);function Zr(e,t,n,o="remote"){let r=Pn(e,t),s=Pn(e,n),{lh:c,rh:l,cosL:a,cosR:b}=Zo(r,s,e),p=O=>O.bs===O.be,g=O=>O.toks.some(F=>typeof F.k=="string"),m=O=>p(O)&&!g(O),u=(O,F)=>F.bs<O.be&&O.bs<F.be,h=(O,F)=>!u(O,F)&&F.bs<=O.be&&O.bs<=F.be&&(p(O)&&g(O)||p(F)&&g(F))&&!(p(O)&&p(F)),y=(O,F)=>O.bs===F.bs&&O.be===F.be&&Qo(O.toks,F.toks),S=[],v=new Set;for(let O of c){let F=l.find(ke=>!v.has(ke)&&y(O,ke));F?(v.add(F),S.push({bs:O.bs,be:O.be,side:"both",l:O,r:F,toks:O.toks})):S.push({bs:O.bs,be:O.be,side:"L",l:O,toks:O.toks,lead:!!O.lead})}for(let O of l)v.has(O)||S.push({bs:O.bs,be:O.be,side:"R",r:O,toks:O.toks,lead:!!O.lead});S.sort((O,F)=>O.bs-F.bs||O.be-F.be||F.lead-O.lead);let D=0,q=0;for(let O of S)O.side==="both"&&(D+=O.toks.length-(O.be-O.bs));let Z=S.map((O,F)=>F),ae=O=>Z[O]===O?O:Z[O]=ae(Z[O]),ie=(O,F)=>(O=ae(O),F=ae(F),O===F?!1:(Z[O]=F,!0)),he=S.map(O=>ji({bs:O.bs,be:O.be,toks:O.toks},e)),K={L:new Map,R:new Map};S.forEach((O,F)=>{let ke=O.side==="both"?["L","R"]:[O.side];for(let re of ke)for(let Ne of he[F])K[re].has(Ne)||K[re].set(Ne,[]),K[re].get(Ne).push(F)});for(let O of[K.L,K.R])for(let F of O.values())for(let ke=1;ke<F.length;ke++)ie(F[0],F[ke]);for(let O=0;O<S.length;O++)for(let F=O+1;F<S.length;F++){let ke=S[O],re=S[F];ke.side===re.side&&ke.side!=="both"||ke.bs>re.be||(u(ke,re)||h(ke,re)?ie(O,F):ke.bs===re.bs&&p(ke)&&p(re)&&q++)}let J=(O,F)=>{let ke=O==="L"?c:l;for(let re of ke)if(re.toks.some(Ne=>Ne.kind==="close"&&Ne.k.el===F.el))return re.bs;for(let re=0;re<e.length;re++)if(e[re].kind==="close"&&e[re].k.el===F.el)return re;return-1};S.forEach((O,F)=>{if(!(!m(O)||O.side==="both"))for(let ke of O.toks){if(ke.kind!=="open")continue;let re=J(O.side,ke.k);if(re<=O.bs)continue;let Ne=new Uint8Array(re-O.bs),tt=[];if(S.forEach((qe,Ke)=>{if(!(qe.side===O.side||p(qe))&&qe.bs<re&&qe.be>O.bs){tt.push(Ke);for(let Ze=Math.max(qe.bs,O.bs);Ze<Math.min(qe.be,re);Ze++)Ne[Ze-O.bs]=1}}),tt.length&&Ne.every(qe=>qe===1))for(let qe of tt)ie(F,qe)}});let ye=!0;for(;ye;){ye=!1;let O=new Map;S.forEach((F,ke)=>{let re=ae(ke),Ne=O.get(re)||{bs:F.bs,be:F.be,L:!1,R:!1};Ne.bs=Math.min(Ne.bs,F.bs),Ne.be=Math.max(Ne.be,F.be),F.side!=="R"&&(Ne.L=!0),F.side!=="L"&&(Ne.R=!0),O.set(re,Ne)}),S.forEach((F,ke)=>{for(let[re,Ne]of O){if(ae(ke)===ae(re)||!(Ne.L&&Ne.R))continue;let tt=F.bs<Ne.be&&F.be>Ne.bs,qe=p(F)&&g(F)&&(F.bs===Ne.be||F.bs===Ne.bs);(tt||qe)&&ie(ke,re)&&(ye=!0)}})}let je=new Map;S.forEach((O,F)=>{let ke=ae(F);je.has(ke)||je.set(ke,[]),je.get(ke).push(O)});let Fe=[];for(let O of je.values()){let F=O.some(re=>re.side==="L"),ke=O.some(re=>re.side==="R");if(F&&ke){let re=Math.min(...O.map(Ke=>Ke.bs)),Ne=Math.max(...O.map(Ke=>Ke.be)),tt=O.filter(Ke=>Ke.side!=="R").map(Ke=>Ke.l).sort((Ke,Ze)=>Ke.bs-Ze.bs),qe=O.filter(Ke=>Ke.side!=="L").map(Ke=>Ke.r).sort((Ke,Ze)=>Ke.bs-Ze.bs);Fe.push({bs:re,be:Ne,kind:"conflict",localHunks:tt,remoteHunks:qe})}else for(let re of O)Fe.push({bs:re.bs,be:re.be,kind:re.side,u:re})}let ot=(O,F)=>{let ke=O==="L"?c:l;for(let re of ke)if(re.toks.some(Ne=>Ne.kind==="close"&&Ne.k.el===F.el))return re.bs+.5;for(let re=0;re<e.length;re++)if(e[re].kind==="close"&&e[re].k.el===F.el)return re;return 1/0},ct=(O,F)=>{let ke=O==="L"?c:l;for(let re of ke)if(re.toks.some(Ne=>Ne.kind==="open"&&Ne.k.el===F.el))return re.bs-.5;for(let re=0;re<e.length;re++)if(e[re].kind==="open"&&e[re].k.el===F.el)return re;return-1/0},Ct=O=>O.kind==="R"?"R":"L",vt=O=>O.kind==="R"?1:0;Fe.sort((O,F)=>{if(O.bs!==F.bs)return O.bs-F.bs;let ke=O.bs===O.be,re=F.bs===F.be;if(ke!==re)return ke?-1:1;if(ke&&re&&O.kind!=="conflict"&&F.kind!=="conflict"){let tt=O.u.toks,qe=F.u.toks,Ke=at=>at.length&&at.every(f=>f.kind==="open"),Ze=at=>at.length&&at.every(f=>f.kind==="close");if(Ke(tt)&&Ke(qe)){let at=Math.max(...tt.map(T=>ot(Ct(O),T.k))),f=Math.max(...qe.map(T=>ot(Ct(F),T.k)));if(at!==f)return f-at}if(Ze(tt)&&Ze(qe)){let at=Math.min(...tt.map(T=>ct(Ct(O),T.k))),f=Math.min(...qe.map(T=>ct(Ct(F),T.k)));return at!==f?f-at:vt(F)-vt(O)}}let Ne=tt=>tt.u&&tt.u.lead?1:0;return Ne(F)-Ne(O)||vt(O)-vt(F)||O.be-F.be});let Oe=[],dt=[],Qe=0,Lt=O=>{O>Qe&&(Oe.push({bs:Qe,be:O,toks:e.slice(Qe,O),source:"base"}),Qe=O)};for(let O of Fe){if(Lt(O.bs),O.kind==="conflict"){let F=Yo(e,O.localHunks,O.bs,O.be),ke=Yo(e,O.remoteHunks,O.bs,O.be),re=o==="local"?F:o==="both"?F.concat(ke):ke;dt.push({bs:O.bs,be:O.be,base:e.slice(O.bs,O.be),local:F,remote:ke,resolved:re}),Oe.push({bs:O.bs,be:O.be,toks:re,source:"conflict",localHunks:O.localHunks,localToks:F,keepsLocal:o!=="remote"})}else Oe.push({bs:O.bs,be:O.be,toks:O.u.toks,source:O.kind==="R"?"remote":"local",localHunks:O.kind==="R"?[]:[O.u.l]});Qe=Math.max(Qe,O.be)}Lt(e.length);let rt=new Map(a.map(O=>[O.bi,O.tok])),et=new Map(b.map(O=>[O.bi,O.tok])),lt=[];for(let O of Oe){O.source==="base"&&(O.toks=O.toks.map((F,ke)=>{let re=O.bs+ke,Ne=rt.get(re),tt=et.get(re),qe=Ne&&tt?o==="remote"?tt:Ne:Ne||tt||F;return qe===F?F:{...qe,cosmetic:!0}}));for(let F of O.toks)lt.push({...F,src:O.source})}return{tokens:lt,segments:Oe,conflicts:dt,localHunks:c,remoteHunks:l,collapsedDelta:D,samePoint:q,mapLocalOffset:Bi(e,c,Oe)}}function Yo(e,t,n,o){let r=[],s=n;for(let c of t)r=r.concat(e.slice(s,c.bs),c.toks),s=c.be;return r.concat(e.slice(s,o))}var Go=e=>e.reduce((t,n)=>t+n.len,0);function Bi(e,t,n){let o=new Int32Array(e.length+1);for(let c=0;c<e.length;c++)o[c+1]=o[c]+e[c].len;let r=t.map(c=>({bs:o[c.bs],be:o[c.be],text:c.toks.map(l=>l.raw).join(""),ref:c})),s=n.map(c=>({bs:o[c.bs],be:o[c.be],len:Go(c.toks),source:c.source,localHunks:c.localHunks||[],localLen:c.localToks?Go(c.localToks):0,keepsLocal:c.keepsLocal,ref:c}));return c=>{let l=null,a=null,b=0,p=0,g=0;for(let u of r){let h=u.bs-g;if(c<=p+h){l=g+(c-p);break}if(p+=h,g=u.bs,c<=p+u.text.length){a=u,b=c-p,l=u.bs;break}p+=u.text.length,g=u.be}l===null&&(l=g+(c-p));let m=0;for(let u of s){if(!a&&l<=u.bs)return m;if(!(a?u.localHunks.includes(a.ref):l<u.be)){m+=u.len;continue}if(u.source==="base")return m+(l-u.bs);if(u.source==="remote")return m+u.len;if(u.source==="local")return m+Math.min(b,u.len);if(!u.keepsLocal||!a)return m+u.len;let y=u.localHunks.indexOf(a.ref),S=Go(Yo(e,u.localHunks.slice(0,y),u.ref.bs,a.ref.bs));return m+Math.min(S+b,u.localLen)}return m}}function Xn(e,t,n,o="remote"){if(t===n||n===e)return{text:t,conflicts:[],mapLocalOffset:u=>Math.min(u,t.length),granularity:"word"};let r=vo(e,t,n),s=An(e,r),c=An(t,r),l=An(n,r),a=s.length<=2e4&&c.length<=2e4&&l.length<=2e4?Zr(s,c,l,o):null,b="word",p=s;if(!a){let u=h=>h.split(/(?<=\n)/).map(y=>({k:y,raw:y,len:y.length}));p=u(e),a=Zr(p,u(t),u(n),o),b="line"}let g=u=>u.map(h=>h.raw).join(""),m=[0];for(let u of p)m.push(m[m.length-1]+u.len);return{text:g(a.tokens),conflicts:a.conflicts.map(u=>({bs:m[u.bs],be:m[u.be],base:g(u.base),local:g(u.local),remote:g(u.remote),resolved:g(u.resolved)})),mapLocalOffset:a.mapLocalOffset,granularity:b}}function Zn(e,t,n=4e3){if(e===t)return[];let o=vo(e,t),r=An(e,o),s=An(t,o),c=Pn(r,s,n),l=[0];for(let a of r)l.push(l[l.length-1]+a.len);return c.hunks.map(a=>({bs:l[a.bs],be:l[a.be],text:a.toks.map(b=>b.raw).join("")}))}var Dn="\uFFFC";var _i={caret:0},sn=new Set("A ABBR B BDI BDO CITE CODE DATA DEL DFN EM FONT I INS KBD MARK Q S SAMP SMALL SPAN STRIKE STRONG SUB SUP TIME TT U VAR".split(" ")),rs=new Set(["BR","WBR","IMG"]),Ui=new Set("ADDRESS ARTICLE ASIDE AUDIO BLOCKQUOTE BODY CANVAS CAPTION CENTER COL COLGROUP DD DETAILS DIALOG DIR DIV DL DT FIELDSET FIGCAPTION FIGURE FOOTER FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HEADER HGROUP HR HTML IFRAME LEGEND LI MAIN MATH MENU NAV NOSCRIPT OBJECT OL OPTGROUP OPTION P PRE SCRIPT SECTION SELECT STYLE SUMMARY SVG TABLE TBODY TD TEMPLATE TEXTAREA TFOOT TH THEAD TITLE TR UL VIDEO".split(" "));function xn(e,t={}){if(e.nodeType===3)return!0;if(e.nodeType!==1)return!1;if(t.ignored&&t.ignored(e)||rs.has(e.tagName))return!0;if(!sn.has(e.tagName))return!Ui.has(e.tagName);if(t.remoteWins&&t.remoteWins(e))return!1;let n=t.inlineCache&&t.inlineCache.get(e);if(n!==void 0)return n;let o=!0;for(let r of e.childNodes)if(!xn(r,t)){o=!1;break}return t.inlineCache&&t.inlineCache.set(e,o),o}function Wi(e){return!e.firstChild||e.textContent===""&&!e.querySelector("br,img,wbr")}function Qn(e,t={}){let n={text:"",marks:[],atoms:[],nodes:[],stackAt:[],pins:[],placeholder:null},o=(r,s)=>{for(let c of r){if(c.nodeType===3){let p=c.nodeValue;if(!p)continue;n.nodes.push({node:c,s:n.text.length,e:n.text.length+p.length}),n.text+=p;for(let g=0;g<p.length;g++)n.stackAt.push(s);continue}if(c.nodeType!==1)continue;if(t.ignored&&t.ignored(c)){n.pins.push({el:c,i:n.text.length});continue}if(t.skip&&t.skip.has(c))continue;let l=c.tagName;if(t.blocks&&t.blocks.has(c)){n.text.length&&n.text[n.text.length-1]!==nt&&(n.stackAt.push(s),n.text+=nt);let p={el:c,tag:l,from:n.text.length,to:-1,depth:s.length,block:!0};n.marks.push(p);let g=s.concat([p]);o(c.childNodes,g),n.stackAt.push(g),n.text+=nt,p.to=n.text.length;continue}let a=sn.has(l)&&Wi(c);if(rs.has(l)||!sn.has(l)||t.remoteWins&&t.remoteWins(c)||t.atomize&&t.atomize(c)||a){n.atoms.push({i:n.text.length,el:c,key:a?l+":empty":l,stack:s}),n.stackAt.push(s),n.text+=Dn;continue}let b={el:c,tag:l,from:n.text.length,to:-1,depth:s.length};n.marks.push(b),o(c.childNodes,s.concat([b])),b.to=n.text.length}};if(o(e,[]),n.atoms.length===1&&n.atoms[0].el.tagName==="BR"&&n.marks.length===0&&Io(n).trim()===""){let r=n.atoms[0];n.placeholder=r.el,n.text=n.text.slice(0,r.i)+n.text.slice(r.i+1),n.stackAt.splice(r.i,1);for(let s of n.nodes)s.s>r.i&&(s.s--,s.e--);n.atoms=[]}return n.atomAt=new Map(n.atoms.map(r=>[r.i,r])),n}function $i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")}function Fi(e){let t="<"+e.tagName.toLowerCase();for(let n of e.attributes)t+=` ${n.name}="${n.value.replace(/"/g,""")}"`;return t+">"}function tr(e,t,n){let o="",r=[];for(let s=t;s<n;s++){let c=e.stackAt[s],l=0;for(;l<r.length&&l<c.length&&r[l]===c[l];)l++;for(;r.length>l;)o+=`</${r.pop().tag.toLowerCase()}>`;for(;r.length<c.length;){let b=c[r.length];o+=Fi(b.el),r.push(b)}let a=e.atomAt.get(s);o+=a?a.el.outerHTML:e.text[s]===nt?"":$i(e.text[s])}for(;r.length;)o+=`</${r.pop().tag.toLowerCase()}>`;return o}function Vi(e,t){let n=[...e.el.attributes].filter(o=>!t(e.el,o.name)).map(o=>o.name+"="+o.value).sort().join("");return e.tag+"|"+n}function ss(e,t){let n=[...e.attributes].filter(o=>!t(e,o.name)).map(o=>o.name+"="+o.value).sort().join("");return e.tagName+"|"+n+"|"+e.innerHTML}function Qr(e,t=()=>!1){let n=new Map,o=s=>{let c=n.get(s);return c===void 0&&(c="{"+s.map(l=>Vi(l,t)).sort().join(",")+"}",n.set(s,c)),c},r="";for(let s=0;s<e.text.length;s++){let c=e.atomAt.get(s);r+=(c?"["+ss(c.el,t)+"]":e.text[s])+o(e.stackAt[s])}return e.text.length===0&&e.placeholder&&(r+="[br]"),r}function Hn(e,t,n,o=r=>r.key){let r=[],s=e.text,c=0,l=a=>{if(a<=c)return;let b=s.slice(c,a);if(n)for(let p of b.split(/(?<=\n)/))r.push({k:p,raw:p,len:p.length});else for(let p of An(b,t))r.push(p)};for(let a of e.atoms)l(a.i),r.push({k:"\0"+o(a),raw:Dn,len:1,atom:!0}),c=a.i+1;return l(s.length),r}function Io(e){if(!e.atoms.length)return e.text;let t="",n=0;for(let o of e.atoms)t+=e.text.slice(n,o.i),n=o.i+1;return t+e.text.slice(n)}var nr=e=>{let t=new Int32Array(e.length+1);for(let n=0;n<e.length;n++)t[n+1]=t[n]+e[n].len;return t};function es(e,t,n,o){let r=nr(t),s=nr(n),c=[],l=0,a=0;for(let p of o.hunks){a+=p.bs-l;let g=a+p.toks.length;c.push({bs:r[p.bs],be:r[p.be],ss:s[a],se:s[g],text:e.text.slice(s[a],s[g]),toks:p.toks,lead:!!p.lead}),a=g,l=p.be}let b=new Map;for(let p of o.cosmetic)b.set(p.bi,p.tok.raw);return{hunks:c,respell:b}}function ts(e,t,n){let o=c=>c===nt||/\s/.test(c),r=c=>c.replace(/[\u001E\s]/g,""),s=[];for(let c of e){let l=t.slice(c.bs,c.be),a=n.slice(c.ss,c.se);if(!l.includes(nt)&&!a.includes(nt)||l.includes(Dn)||a.includes(Dn)||r(l)!==r(a)){s.push(c);continue}let b=0,p=0;for(;;){let g=b,m=p;for(;g<l.length&&o(l[g]);)g++;for(;m<a.length&&o(a[m]);)m++;let u=b,h=p;for(;u<g&&h<m&&l[u]===a[h];)u++,h++;let y=g,S=m;for(;y>u&&S>h&&l[y-1]===a[S-1];)y--,S--;if(y>u||S>h){let v=a.slice(h,S);s.push({bs:c.bs+u,be:c.bs+y,ss:c.ss+h,se:c.ss+S,text:v,toks:[...v].map(D=>({k:D,raw:D,len:1})),lead:c.lead})}if(g>=l.length)break;b=g+1,p=m+1}}return s}function ns(e,t,n){let o=new Int32Array(t+1).fill(-1),r=new Int32Array(n+1).fill(-1),s=0,c=0,l=a=>{for(;s<a;)o[s]=c,r[c]=s,s++,c++};for(let a of e)l(a.bs),s=a.be,c=a.se;return l(t),o[t]=c,r[c]=t,{bTo:o,toB:r}}function os(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function or(e){let{out:t,policy:n="remote",L:o,R:r}=e,s=e.provenance||new WeakMap,c=e.textMappers||new WeakMap,l=e.conflicts||[],a=e.decisions||[],b=l.length,p=!!(o&&o.reverse&&o.map&&r&&r.reverse&&r.map),g={base:null,local:null,remote:null};if(p&&e.moveIn){let i=X=>be=>X.some(G=>G===be||G.nodeType===1&&G.contains(be)),d=i(e.local),w=i(e.remote),k=i(e.base),N=new Set,L=X=>{if(!sn.has(X.tagName))return;let be=o.map.get(X),G=r.map.get(X);(be&&!d(be)||G&&!w(G))&&N.add(X);for(let oe of X.children)L(oe)};for(let X of e.base)X.nodeType===1&&L(X);let $=X=>be=>{if(!sn.has(be.tagName))return!1;let G=X.reverse.get(be);return!!G&&(N.has(G)||!k(G))};N.size&&(g.base=X=>N.has(X)),g.local=$(o),g.remote=$(r)}let m={base:new Set,local:new Set,remote:new Set};if(p&&e.moveIn){let i=k=>N=>k.some(L=>L===N||L.nodeType===1&&L.contains(N)),d=i(e.local),w=i(e.remote);for(let k of Qn(e.base,{...e,atomize:g.base}).atoms){let N=o.map.get(k.el),L=r.map.get(k.el),$=!!N&&!d(N),X=!!L&&!w(L);!$&&!X||(m.base.add(k.el),N&&!$&&m.local.add(N),L&&!X&&m.remote.add(L),d(k.el)&&m.local.add(k.el),w(k.el)&&m.remote.add(k.el))}}let u=Qn(e.base,{...e,atomize:g.base,skip:m.base}),h=Qn(e.local,{...e,atomize:g.local,skip:m.local}),y=Qn(e.remote,{...e,atomize:g.remote,skip:m.remote}),S=new Map(u.atoms.map(i=>[i.el,i])),v=(i,d,w)=>{d.namespaceURI?i.setAttributeNS(d.namespaceURI,d.name,w):i.setAttribute(d.name,w)},D=(i,d,w,k)=>{if(!d&&(!w||!k)){for(let L of(w||k).attributes)v(i,L,L.value);return}let N=new Map;for(let L of[d,w,k])if(L)for(let $ of L.attributes)N.set($.name,$);for(let[L,$]of N){let X=d?d.getAttribute(L):null,be=w?w.getAttribute(L):X,G=k?k.getAttribute(L):X,oe;be===G?oe=be:be===X?(oe=G,a.push({kind:"attr",el:i,name:L,source:"remote"})):G===X?(oe=be,a.push({kind:"attr",el:i,name:L,source:"local"})):(oe=n==="local"?be:G,l.push({kind:"attr",el:i,name:L,base:X,local:be,remote:G,resolved:oe}),a.push({kind:"attr",el:i,name:L,source:"both"})),oe!=null&&v(i,$,oe)}},q=(i,d,w,k)=>i&&e.mergeAttrs?e.mergeAttrs(i,d,w,k):D(k,i,d,w),Z=e.mergeElement||((i,d,w)=>{let k=t.createElement(i.tagName);q(i,d,w,k);let N=d||i,L=w||i,$=n==="local"?N.isEqualNode(i)?L:N:L.isEqualNode(i)?N:L;for(let X of $.childNodes)k.appendChild(t.importNode(X,!0));return s.set(k,{base:i,local:d,remote:w}),k}),ae=e.cloneUnit||((i,d)=>{let w=t.importNode(i,!0);return s.set(w,{base:null,local:d==="local"?i:null,remote:d==="remote"?i:null}),w}),ie=e.atomKey||(i=>ss(i,()=>!1)),he=(i,d)=>{let w=new Map;for(let k of i.atoms)if(e.remoteWins&&e.remoteWins(k.el)&&sn.has(k.el.tagName))w.set(k,"w"+k.el.tagName+"#"+(k.el.id||""));else if(!p)w.set(k,k.key);else if(i===u)w.set(k,"="+ie(k.el));else{let N=d.reverse.get(k.el),L=N?S.get(N):null;L?w.set(k,"="+ie(L.el)):N?w.set(k,"m"+ie(k.el)):w.set(k,"="+ie(k.el))}return k=>w.get(k)},K=he(u,null),J=he(h,o),ye=he(y,r),je=vo(Io(u),Io(h),Io(y)),Fe=Hn(u,je,!1,K),ot=Hn(h,je,!1,J),ct=Hn(y,je,!1,ye),Ct=Fe.length>2e4||ot.length>2e4||ct.length>2e4;Ct&&(Fe=Hn(u,je,!0,K),ot=Hn(h,je,!0,J),ct=Hn(y,je,!0,ye));let vt=Zo(Pn(Fe,ot),Pn(Fe,ct),Fe),Oe=es(h,Fe,ot,{hunks:vt.lh,cosmetic:vt.cosL}),dt=es(y,Fe,ct,{hunks:vt.rh,cosmetic:vt.cosR});Oe.hunks=ts(Oe.hunks,u.text,h.text),dt.hunks=ts(dt.hunks,u.text,y.text);let Qe=ns(Oe.hunks,u.text.length,h.text.length),Lt=ns(dt.hunks,u.text.length,y.text.length),rt=u.text.length,et=i=>new Map(i.atoms.map(d=>[d.el,d])),lt=et(h),O=et(y),F=(i,d,w)=>{let k=new Set;if(!p)return k;for(let N of i.atoms){let L=S.get(d.reverse.get(N.el));L&&w.bTo[L.i]<0&&k.add(L)}return k},ke=F(h,o,Qe),re=F(y,r,Lt),Ne=i=>!xn(i,{...e,remoteWins:null}),tt=new Set;if(p)for(let i of u.atoms){if(!Ne(i.el))continue;let d=o.map.get(i.el)||null,w=r.map.get(i.el)||null,k=d&&!w?d:w&&!d?w:null;k&&(lt.has(k)||O.has(k))&&!k.isEqualNode(i.el)&&tt.add(i)}let qe=1,Ke=(i,d)=>({id:qe++,tag:i,base:null,local:null,remote:null,rank:d}),Ze=new Map,at=[];for(let i of u.marks){let d=Ke(i.tag,i.depth);d.block=!!i.block,d.base=i.el,d.baseMark=i,Ze.set(i.el,d),at.push(d)}let f=(i,d)=>{let w=-1,k=-1;for(let N=i.from;N<i.to;N++){let L=d[N];L>=0&&(w<0&&(w=L),k=L+1)}return w<0?null:[w,k]},T=(i,d,w,k)=>{for(let N of i.marks){let L=w?w.reverse.get(N.el):null;L&&w.identical.has(L)&&w.pairIdenticalChildren&&w.pairIdenticalChildren(L);let $=L?Ze.get(L):null;if($&&$[d]&&($=null),!$){let X=f(N,k),be=0;if(X)for(let G of at){if(G.tag!==N.tag||G[d]||!!G.block!=!!N.block)continue;let oe=Math.min(X[1],G.baseMark.to)-Math.max(X[0],G.baseMark.from);(oe>be||oe===be&&oe>0&&Math.abs(G.rank-N.depth)<Math.abs($.rank-N.depth))&&($=G,be=oe)}}$||($=Ke(N.tag,N.depth),$.block=!!N.block,$.new=d),$[d]=N.el,$[d+"Mark"]=N,Ze.set(N.el,$)}};T(h,"local",o,Qe.toB),T(y,"remote",r,Lt.toB);let x=i=>i.merged||i,B=i=>{let d=new Set;for(let w of i)w.block||d.add(Ze.get(w.el));return d},I=new Map,E=i=>{let d=I.get(i);return d||(d=B(i),I.set(i,d)),d},j=(i,d)=>{let w=[],k=null;for(let N=0;N<rt;N++){let L=d[N];if(L<0){k&&w.push(k),k=null;continue}let $=E(u.stackAt[N]),X=E(i.stackAt[L]),be=new Set,G=new Set;for(let oe of X)$.has(oe)||be.add(oe);for(let oe of $)X.has(oe)||G.add(oe);if(!be.size&&!G.size){k&&w.push(k),k=null;continue}if(k&&os(k.added,be)&&os(k.removed,G)){k.be=N+1;continue}k&&w.push(k),k={bs:N,be:N+1,added:be,removed:G}}return k&&w.push(k),w},M=j(h,Qe.bTo),P=j(y,Lt.bTo),Y=i=>i.be>i.bs?[i.bs,i.be-1]:[i.bs-1,i.bs],Q=(i,d)=>{if(rt===0)return null;let[w,k]=Y(i);for(let N of d){if(N.be<=w)continue;if(N.bs>k)break;let L=N.bs<=w&&k<N.be;return L&&i.text===""&&N.bs===i.bs&&N.be===i.be?"straddle":L?N:i.be>i.bs?"straddle":null}return null},we=i=>i.bs===i.be,Ye=(i,d)=>{let w=!1;for(let k=i.bs;k<i.be;k++){let N=u.text[k];if(N===nt)w=!0;else if(!/\s/.test(N))return!1}for(let k=i.ss;k<i.se;k++){let N=d.text[k];if(N===nt)w=!0;else if(!/\s/.test(N))return!1}return w},bt=(i,d)=>i.bs<d.be&&d.bs<i.be,ft=(i,d)=>i.bs<=d.be&&d.bs<=i.be&&we(i)!==we(d),le=(i,d)=>u.text.slice(i.bs,i.be).includes(nt)||d.text.slice(i.ss,i.se).includes(nt),Ge=i=>{if(we(i))return!1;let d=i.bs,w=i.be;for(;d>0&&/\s/.test(u.text[d-1]);)d--;for(;w<u.text.length&&/\s/.test(u.text[w]);)w++;return(d===0||u.text[d-1]===nt)&&(w===u.text.length||u.text[w]===nt)},Rt=(i,d)=>!le(i,d)&&!Ge(i),yt=(i,d)=>bt(i,d)||ft(i,d)&&!(Ye(i,h)&&Rt(d,y))&&!(Ye(d,y)&&Rt(i,h)),Dt=(i,d)=>{if(i.bs!==d.bs||i.be!==d.be||i.toks.length!==d.toks.length)return!1;let w=i.ss,k=d.ss;for(let N=0;N<i.toks.length;N++){let L=i.toks[N],$=d.toks[N];if(L.k!==$.k||L.atom&&!h.atomAt.get(w).el.isEqualNode(y.atomAt.get(k).el))return!1;w+=L.len,k+=$.len}return!0},Ut=(i,d,w,k)=>{for(let N of u.atoms){if(N.i<i.bs||N.i>=i.be||k.has(N)||tt.has(N))continue;let L=d.bTo[N.i],$=L>=0?w.atomAt.get(L):null;if($&&!$.el.isEqualNode(N.el))return!0}return!1},At=[],xt=Oe.hunks,A=dt.hunks,C=0,R=0,U=0,H=0,_=0,z=i=>{i>U&&(At.push({src:"base",from:U,to:i,dL:H,dR:_}),U=i)};for(;C<xt.length||R<A.length;){let i=xt[C],d=A[R],w=!!i&&(!d||i.bs<d.bs||i.bs===d.bs&&i.be<=d.be&&!d.lead);if(i&&d&&i.bs===d.bs&&we(i)&&we(d)){let Nt=Ye(i,h),kn=Ye(d,y);Nt!==kn&&(w=kn)}let k=w?i:d,N=w?d:i,L=!!N&&Dt(i,d),$=!!N&&(w?!!xt[C+1]&&Dt(xt[C+1],d):!!A[R+1]&&Dt(i,A[R+1])),X=!!N&&!L&&!$&&(rt===0||yt(i,d)),be=X,G=Q(k,w?P:M);if(G==="straddle"&&(be=!0),!be&&k.be>k.bs&&(be=Ut(k,w?Lt:Qe,w?y:h,w?ke:re)),!be&&L){z(k.bs),At.push({src:"both",lfrom:i.ss,rfrom:d.ss,len:k.text.length}),U=k.be,H+=k.text.length-(k.be-k.bs),_+=k.text.length-(k.be-k.bs),C++,R++;continue}if(!be){z(k.bs),At.push({src:w?"local":"remote",from:k.ss,to:k.se,inherit:G&&G!=="straddle"?G:null}),U=k.be,w?(H+=k.text.length-(k.be-k.bs),C++):(_+=k.text.length-(k.be-k.bs),R++);continue}let oe=k.bs,Be=k.be,Ie=C,De=R,mt=Nt=>Nt.bs<Be&&Nt.be>oe||we(Nt)&&(Nt.bs===oe||Nt.bs===Be);w?Ie++:De++,X&&(oe=Math.min(oe,N.bs),Be=Math.max(Be,N.be),w?De++:Ie++);let it=!0;for(;it;){for(it=!1;Ie<xt.length&&mt(xt[Ie]);)oe=Math.min(oe,xt[Ie].bs),Be=Math.max(Be,xt[Ie].be),Ie++,it=!0;for(;De<A.length&&mt(A[De]);)oe=Math.min(oe,A[De].bs),Be=Math.max(Be,A[De].be),De++,it=!0}let Ft=oe+H,Ht=oe+_,Xt=Be-oe,nn=Be-oe;for(let Nt=C;Nt<Ie;Nt++)Xt+=xt[Nt].text.length-(xt[Nt].be-xt[Nt].bs);for(let Nt=R;Nt<De;Nt++)nn+=A[Nt].text.length-(A[Nt].be-A[Nt].bs);let fn=Ft+Xt,un=Ht+nn;z(oe);let St={kind:"text",node:e.node||null,base:tr(u,oe,Be),local:tr(h,Ft,fn),remote:tr(y,Ht,un),resolved:null,range:null,bs:oe,be:Be,lss:Ft,lse:fn,rss:Ht,rse:un};St.resolved=n==="local"?St.local:n==="remote"?St.remote:St.local+St.remote,n!=="remote"&&At.push({src:"local",from:Ft,to:fn,conflict:St}),n!=="local"&&At.push({src:"remote",from:Ht,to:un,conflict:St}),l.push(St),U=Be,H+=Xt-(Be-oe),_+=nn-(Be-oe),C=Ie,R=De}z(rt);let ne=u.text,pe=[];if(Oe.respell.size||dt.respell.size){let i=nr(Fe),d=[];for(let w=0;w<Fe.length;w++){let k=Fe[w].raw,N=Oe.respell.get(w)??k,L=dt.respell.get(w)??k;(N!==k||L!==k)&&pe.push([i[w],N!==k&&L!==k?"both":N!==k?"local":"remote"]),d.push(N===L?N:N===k?L:L===k||n==="local"?N:L)}ne=d.join("")}let fe="",me=[],Pe=[],Le=[],kt=[];for(let i of At){let d=fe.length;if(i.src==="base"){for(let w=i.from;w<i.to;w++)me.push(w),Pe.push(w+i.dL),Le.push(w+i.dR),kt.push(i);fe+=ne.slice(i.from,i.to)}else if(i.src==="both"){for(let w=0;w<i.len;w++)me.push(-1),Pe.push(i.lfrom+w),Le.push(i.rfrom+w),kt.push(i);fe+=h.text.slice(i.lfrom,i.lfrom+i.len)}else{let w=i.src==="local"?h:y;for(let k=i.from;k<i.to;k++)me.push(-1),Pe.push(i.src==="local"?k:-1),Le.push(i.src==="remote"?k:-1),kt.push(i);fe+=w.text.slice(i.from,i.to)}i.ms=d,i.me=fe.length,i.conflict&&(i.conflict.range||(i.conflict.range=[d,d]),i.conflict.range[1]=fe.length)}let ue=fe.length,Ve=new Int32Array(rt+1).fill(-1),Te=new Int32Array(h.text.length+1).fill(-1),It=new Int32Array(y.text.length+1).fill(-1);for(let i=0;i<ue;i++)me[i]>=0&&(Ve[me[i]]=i),Pe[i]>=0&&(Te[Pe[i]]=i),Le[i]>=0&&(It[Le[i]]=i);let wt=(i,d)=>{let w=-1,k=-1;for(let N=i.from;N<i.to;N++){let L=d[N];L>=0&&(w<0&&(w=L),k=L+1)}return w<0?null:[w,k]},Ot=[],ht=[];for(let i of new Set(Ze.values()))i.new==="local"?Ot.push(i):i.new==="remote"&&ht.push(i);let zn=(i,d)=>{i.remote=d.remote,i.remoteMark=d.remoteMark,i.new="both",d.merged=i,Ze.set(d.remote,i)};if(Ot.length&&ht.length){let i=e.idOf;for(let d of Ot){let w=i?i.local(d.local):null;if(!w)continue;let k=ht.find(N=>!N.merged&&N.tag===d.tag&&!!N.block==!!d.block&&i.remote(N.remote)===w);k&&zn(d,k)}for(let d of Ot){if(d.remote)continue;let w=wt(d.localMark,Te);if(w)for(let k of ht){if(k.merged||k.tag!==d.tag||!!k.block!=!!d.block)continue;let N=wt(k.remoteMark,It);if(N&&Math.min(w[1],N[1])-Math.max(w[0],N[0])>0){zn(d,k);break}}}}I.clear();let qn=i=>{for(let d of i)if(d.block)return x(Ze.get(d.el));return null},rn=u.marks.some(i=>i.block)||h.marks.some(i=>i.block)||y.marks.some(i=>i.block),Gt=new Array(ue).fill(null),vn=new Set;if(rn){let i=(G,oe,Be)=>{let Ie=new Set([G,oe,Be]);Ie.delete(null);let De=[];for(let it of Ie){let Ft=it===G,Ht=it===oe,Xt=it===Be;(Ht===Xt?Ht:Ht===Ft?Xt:Ht)&&De.push(it)}if(De.length<=1)return De[0]||null;let mt=n==="local"?oe:Be;return De.includes(mt)?mt:De[0]},d=(G,oe)=>oe>=0?qn(G.stackAt[oe]):null,w=new Map;for(let G=0;G<ue;G++){if(fe[G]!==nt)continue;let oe=me[G]>=0?d(u,me[G]):null,Be=d(h,Pe[G]),Ie=d(y,Le[G]);w.set(G,[oe,me[G]>=0?i(oe,Be,Ie):Be||Ie])}let k=new Set([...w.values()].map(G=>G[1])),N=G=>G!==nt&&G!==Dn&&!/\s/.test(G),L=(G,oe)=>{let Be=G;for(;Be<oe&&!N(fe[Be]);)Be++;return Be<oe&&me[Be]>=0?d(u,me[Be]):null},$=new Map,X=0;for(let G=0;G<ue;G++){if(fe[G]!==nt)continue;let[oe,Be]=w.get(G),Ie=L(X,G),De=Be,mt=$.get(De)===De&&Ie===De;De&&$.has(De)&&!mt&&oe&&!$.has(oe)&&!k.has(oe)&&(De=oe),De&&!$.has(De)&&$.set(De,Ie);for(let it=X;it<=G;it++)Gt[it]=De;X=G+1}let be=G=>{for(let oe=0;oe<G.text.length;oe++)if(N(G.text[oe])&&!d(G,oe))return!0;return!1};if(!be(u)&&!be(h)&&!be(y)){let G=[],oe=0;for(let Ie=0;Ie<ue;Ie++)(fe[Ie]===nt||Ie===ue-1)&&(G.push([oe,Ie]),oe=Ie+1);let Be=new Set(Gt);for(let Ie=0;Ie<G.length;Ie++){let[De,mt]=G[Ie];if(Gt[mt])continue;let it=De;for(;it<=mt&&!N(fe[it]);)it++;if(it>mt)continue;let Ft=d(u,me[it]),Ht=d(h,Pe[it]),Xt=d(y,Le[it]),nn=i(Ft,Ht,Xt)||Ht||Xt||Ft;if(nn&&!Be.has(nn)){Be.add(nn);for(let St=De;St<=mt;St++)Gt[St]=nn;continue}let fn=Ie>0&&Gt[G[Ie-1][1]],un=Ie+1<G.length&&Gt[G[Ie+1][1]];if(fn)vn.add(G[Ie-1][1]);else if(un&&fe[mt]===nt)vn.add(mt);else continue;for(let St=De;St<=mt;St++)Gt[St]=fn||un}}}let bo=new Map,yo=i=>{let d=bo.get(i);if(d)return d;d=[1/0,-1/0];for(let[w,k]of[[i.baseMark,Ve],[i.localMark,Te],[i.remoteMark,It]]){let N=w&&wt(w,k);N&&(d[0]=Math.min(d[0],N[0]),d[1]=Math.max(d[1],N[1]))}return bo.set(i,d),d},ko=(i,d,w)=>{let k=-1,N=-1;for(let L=0;L<i.length;L++){let $=Ze.get(i[L].el);$===d&&(k=L),$===w&&(N=L)}return k>=0&&N>=0?k-N:0},In=(i,d)=>[...i].sort((w,k)=>{for(let $ of d){let X=ko($,w,k);if(X)return X}let N=yo(w),L=yo(k);return N[0]-L[0]||L[1]-N[1]||w.rank-k.rank||w.id-k.id}),wo=new Map,W=new Map,xe=i=>{let d=me[i],w=Pe[i],k=Le[i],N=kt[i];if(d>=0){let Ie=u.stackAt[d],De=h.stackAt[w],mt=y.stackAt[k],it=wo.get(Ie);it||wo.set(Ie,it=new Map);let Ft=it.get(De);Ft||it.set(De,Ft=new Map);let Ht=Ft.get(mt);if(Ht)return Ht;let Xt=E(Ie),nn=E(De),fn=E(mt),un=new Set;for(let St of new Set([...Xt,...nn,...fn])){let Nt=Xt.has(St),kn=nn.has(St),Br=fn.has(St);(kn===Br?kn:kn===Nt?Br:kn)&&un.add(St)}return Ht=In(un,[De,mt,Ie]),Ft.set(mt,Ht),Ht}if(N.src==="both"){let Ie=h.stackAt[w],De=y.stackAt[k];return In(new Set([...E(Ie),...E(De)]),[Ie,De])}let $=(N.src==="local"?h:y).stackAt[N.src==="local"?w:k];if(!N.inherit)return In(E($),[$]);let X=W.get(N);X||W.set(N,X=new Map);let be=X.get($);if(be)return be;let G=new Set(E($));for(let Ie of N.inherit.added)G.add(x(Ie));for(let Ie of N.inherit.removed)G.delete(x(Ie));let oe=N.src==="local"?y:h,Be=(N.src==="local"?Lt.bTo:Qe.bTo)[N.inherit.bs];return be=In(G,[$,oe.stackAt[Be]]),X.set($,be),be},de=new Int32Array(h.text.length+1);de[h.text.length]=ue;for(let i=h.text.length-1;i>=0;i--)de[i]=Te[i]>=0?Te[i]:de[i+1];_i.caret+=h.text.length;let Me=i=>i<=0?0:(i>h.text.length&&(i=h.text.length),Te[i-1]>=0?Te[i-1]+1:de[i]),_e=[],te=[],Ae=null,ee=[],ve="",He=-1,Et=i=>{Ae?Ae.appendChild(i):_e.push(i)},Jt=i=>{if(!ve)return;let d=t.createTextNode(ve);Et(d),te.push({node:d,ms:He,me:i,local:[],u:ee.length?ee[ee.length-1].u:null}),ve=""},an=new Set,Bt=new Map,hn=new Set,Re=i=>{let d=t.createElement(i.tag);if(i.block&&Gn.add(d),!Bt.has(i)){Bt.set(i,d),q(i.base,i.local,i.remote,d),s.set(d,{base:i.base,local:i.local,remote:i.remote});let k=($,X)=>p&&i[X]&&$.reverse.get(i[X])?X:null,N=!i.base&&(k(o,"local")||k(r,"remote"));if(N){let $=N==="local"?o.reverse.get(i.local):r.reverse.get(i.remote),X=s.get(d);X.local=X.local||o.map.get($)||null,X.remote=X.remote||r.map.get($)||null,a.push({kind:"move",el:d,source:N})}else i.base||a.push({kind:"insert",el:d,source:i.local&&i.remote?"both":i.local?"local":"remote"});let L=s.get(d);L.local&&(hn.has(L.local)?L.local=null:hn.add(L.local))}else{let k=Bt.get(i);for(let N of k.attributes)N.name!=="id"&&N.name!=="data-id"&&v(d,N,N.value);s.set(d,{base:null,local:null,remote:null})}Et(d),ee.push({u:i,el:d}),Ae=d},Ue=new Set,V=new Map;for(let i of h.pins){let d=Me(i.i);V.has(d)||V.set(d,[]),V.get(d).push(i)}let ce=i=>{let d=V.get(i);if(d){Jt(i);for(let w of d){let k=w.el.namespaceURI&&w.el.namespaceURI!=="http://www.w3.org/1999/xhtml"?t.createElementNS(w.el.namespaceURI,w.el.tagName):t.createElement(w.el.tagName);s.set(k,{base:null,local:w.el,remote:null,pinned:!0}),Ue.add(k),Et(k)}}},ge=u.atoms.length||h.atoms.length||y.atoms.length,Ce=i=>{if(!ge)return null;let d=me[i]>=0?u.atomAt.get(me[i]):null,w=Pe[i]>=0?h.atomAt.get(Pe[i]):null,k=Le[i]>=0?y.atomAt.get(Le[i]):null;return d||w||k?{ab:d,al:w,ar:k}:null},Se=(i,d,w,k)=>{if(!i||!p)return null;let N=S.get(d.reverse.get(i.el))||null;return!N||N===k||(k?N.el.isEqualNode(k.el):w.bTo[N.i]>=0)?null:N},$e=(i,d)=>{if(!i||!p||!e.moveIn)return null;let w=d.reverse.get(i.el);return w&&!S.has(w)?w:null},Xe=(i,d)=>{let w=new Map;for(let k of i.atoms)w.set(d(k),(w.get(d(k))||0)+1);return w},Pt=Xe(u,K),_t=Xe(h,J),Vt=Xe(y,ye),Tt=i=>{let d=K(i);return Pt.get(d)===1&&(_t.get(d)||0)<=1&&(Vt.get(d)||0)<=1},zt=new Map,ut=new Set,pt=new Set,qt=new Set;for(let i=0;i<ue;i++){let d=Ce(i);if(!d)continue;let{ab:w,al:k,ar:N}=d,L=Se(N,r,Lt,w),$=Se(k,o,Qe,w),X=w,be=null;if(L?(X=L,be="remote"):$&&(X=$,be="local"),X){ut.has(X)?zt.set(i,{dup:X.el}):(ut.add(X),zt.set(i,{bk:X,from:be,al:k,ar:N}));continue}let G=$e(N,r),oe=$e(k,o),Be=G||oe;if(Be){pt.has(Be)?zt.set(i,{dup:Be}):(pt.add(Be),zt.set(i,{moveIn:Be,side:G?"remote":"local",sideEl:G?N.el:k.el}));continue}let Ie=(mt,it)=>mt&&p&&S.get(it.reverse.get(mt.el))||null,De=Ie(N,r)||Ie(k,o);if(De&&(qt.add(De),kt[i].conflict&&Tt(De))){if(ut.has(De)){zt.set(i,{dup:De.el});continue}ut.add(De)}zt.set(i,{al:k,ar:N})}let en=new Map,Ao=(i,d)=>{if(i[d]>=0)return i[d];for(let w=d-1;w>=0;w--)if(i[w]>=0)return i[w]+1;return 0};if(p)for(let i of u.atoms){if(ut.has(i)||qt.has(i))continue;let d=o.map.get(i.el)||null,w=r.map.get(i.el)||null,k=d&<.get(d),N=w&&O.get(w);if(d&&!k||w&&!N)continue;let L=!(k&&N)&&tt.has(i);if(!L&&!(k&&N&&Tt(i)))continue;let $=n==="local"?[[k,Te],[N,It]]:[[N,It],[k,Te]],[X,be]=$.find(([oe])=>oe),G=Ao(be,X.i);en.has(G)||en.set(G,[]),en.get(G).push({a:i,lt:d,rt:w,edited:L}),ut.add(i)}if(p&&e.moveIn){let i=[[h,o,Te,"local"],[y,r,It,"remote"]];n!=="local"&&i.reverse();for(let[d,w,k,N]of i)for(let L of d.atoms){let $=$e(L,w);if(!$||pt.has($))continue;pt.add($);let X=Ao(k,L.i);en.has(X)||en.set(X,[]),en.get(X).push({move:$,side:N,sideEl:L.el})}}let Kn=i=>{let d=en.get(i);if(d){if(Jt(i),d.some(w=>Ne(w.move?w.sideEl:w.a.el)))for(;ee.length;)ee.pop(),Ae=ee.length?ee[ee.length-1].el:null;for(let{a:w,lt:k,rt:N,edited:L,move:$,side:X,sideEl:be}of d){if($){let oe=e.moveIn($,X,be);oe&&Et(oe);continue}an.add(w);let G=Z(w.el,k,N);L&&(l.push({kind:"structure",el:G,detail:"edit-beats-delete",base:w.el}),a.push({kind:"insert",el:G,source:k?"local":"remote"})),Et(G)}}},Gn=new Set;for(let i=0;i<ue;i++){let d=Ce(i),k=!!d&&Ne((d.ab||d.al||d.ar).el)?[]:Gt[i]?[Gt[i],...xe(i)]:xe(i),N=0;for(;N<ee.length&&N<k.length&&ee[N].u===k[N];)N++;if(N<ee.length)for(Jt(i);ee.length>N;)ee.pop(),Ae=ee.length?ee[ee.length-1].el:null;if(ce(i),Kn(i),k.length>ee.length)for(Jt(i);ee.length<k.length;)Re(k[ee.length]);if(fe[i]===nt){if(vn.has(i))continue;Jt(i);let L=ee.length;for(;L>0&&!ee[L-1].u.block;)L--;if(L>0)for(;ee.length>=L;)ee.pop(),Ae=ee.length?ee[ee.length-1].el:null;continue}if(d){Jt(i);let L=zt.get(i),$;if(L.dup){l.push({kind:"structure",el:null,detail:"both-moved",base:L.dup});continue}if(L.moveIn){if($=e.moveIn(L.moveIn,L.side,L.sideEl),!$)continue}else if(L.bk){let X=L.bk;if(an.add(X),X===d.ab)$=Z(X.el,L.al.el,L.ar.el);else{let be=o.map.get(X.el)||null,G=r.map.get(X.el)||null;$=Z(X.el,be,G),(!be||!G)&&l.push({kind:"structure",el:null,detail:"move-beats-delete",base:X.el}),a.push({kind:"move",el:$,source:L.from})}}else L.al?($=ae(L.al.el,"local"),L.ar&&(s.get($).remote=L.ar.el),a.push({kind:"insert",el:$,source:L.ar?"both":"local"})):($=ae(L.ar.el,"remote"),a.push({kind:"insert",el:$,source:"remote"}));Et($);continue}ve||(He=i),ve+=fe[i]}if(Jt(ue),(V.has(ue)||en.has(ue))&&(ee.length=0,Ae=null,ce(ue),Kn(ue)),ue===0&&(h.placeholder||y.placeholder||u.placeholder)){let i=t.createElement("br");s.set(i,{base:u.placeholder,local:h.placeholder,remote:y.placeholder}),_e.push(i)}let se=0,We=i=>{for(;se>0&&te[se-1].me>=i;)se--;for(;se<te.length&&te[se].me<i;)se++;let d=te[se];if(!d)return te[te.length-1]||null;let w=te[se+1];return d.me===i&&w&&w.ms===i?w:d},st=new Map,Je={},ze=(i,d,w)=>{let k=We(i)||(w?Je:null);if(!k)return;let N=st.get(k)||{l:!1,r:!1};d!=="remote"&&(N.l=!0),d!=="local"&&(N.r=!0),st.set(k,N)},tn=i=>{if(i.conflict)return!0;let d=i.src==="local"?h.text:i.src==="remote"?y.text:"";for(let w=i.from;w<i.to;w++)if(d[w]!==Dn&&d[w]!==nt)return!0;return!1};for(let i of At)i.src!=="base"&&ze(i.ms,i.conflict?"both":i.src,tn(i));for(let[i,d]of pe)Ve[i]>=0&&ze(Ve[i],d);for(let i of te.length?te:[Je]){let d=st.get(i);d&&a.push({kind:"text",node:i.node||null,source:d.l&&d.r?"both":d.l?"local":"remote"})}for(let i of at){if(Bt.has(i))continue;let d=!i.local&&!(p&&o.map.get(i.base)),w=!i.remote&&!(p&&r.map.get(i.base));!d&&!w||a.push({kind:"remove",source:d&&w?"both":d?"local":"remote",base:i.base})}let Yt=(i,d,w)=>{if(d<=i)return!1;for(let k=i;k<d;k++)if(w[k]>=0)return!1;return!0};for(let i of at)for(let d of["local","remote"]){let w=i[d+"Mark"],k=i.baseMark;if(!w)continue;let N=d==="local"?Qe:Lt;if(!Yt(k.from,k.to,N.bTo)||!Yt(w.from,w.to,N.toB))continue;let L=(d==="local"?xt:A).find($=>$.ss<=w.from&&w.from<$.se);L&&(L.be<=k.from||L.bs>=k.to)&&a.push({kind:"move",el:Bt.get(i)||null,source:d})}let pn=i=>{let d=Ze.get(i.node.parentNode);return d?x(d):null};for(let i of h.nodes){let d=-1;for(let k=i.s;k<i.e;k++)if(Te[k]>=0){d=Te[k];break}let w;if(d>=0)w=We(d);else{let k=Me(i.s),N=pn(i);w=te.find(L=>L.u===N&&L.me>=k)||te.filter(L=>L.u===N).pop()}w&&w.local.push(i)}let Kt=new Map,jt=te[te.length-1]||null,$t=0;for(let i of h.nodes){let d=null;for(let w=i.s;w<=i.e;w++){let k=Me(w);for(;$t>0&&te[$t-1].me>=k;)$t--;for(;$t<te.length&&te[$t].me<k;)$t++;let N=$=>$&&k>=$.ms&&k<=$.me&&(k<$.me||w===i.e||$===d),L=N(te[$t])?te[$t]:N(te[$t+1])?te[$t+1]:te[$t]||jt;if(!L)break;if(d===L){let $=Kt.get(L);$[$.length-1].to=w-i.s;continue}d=L,Kt.has(L)||Kt.set(L,[]),Kt.get(L).push({node:i.node,from:w-i.s,to:w-i.s,flatStart:i.s})}}for(let i of te){let d=i.local,w=!1;for(let $ of d)for(let X=$.s;X<$.e&&!w;X++)(Te[X]<i.ms||Te[X]>=i.me)&&(w=!0);s.set(i.node,{base:null,local:d.map($=>$.node),remote:null,caret:Kt.get(i)||[],partial:w});let k=i.ms,N=i.me-i.ms,L=$=>{let X=0,be=-1;for(let G of d){let oe=G.e-G.s;if($<=X+oe){be=G.s+($-X);break}X+=oe}return be<0&&(be=d.length?d[d.length-1].e:0),Math.max(0,Math.min(Me(be)-k,N))};L.flat=$=>Math.max(0,Math.min(Me($)-k,N)),c.set(i.node,L)}function Gs(){if(!h.text.includes(nt))return[{flatLocal:h.text,localNodes:h.nodes,textNodes:te,lToM:Te,mapLocal:Me}];let i=[],d=0,w=0;for(let k=0;k<=h.text.length;k++){if(k<h.text.length&&h.text[k]!==nt)continue;let N=d,L=k;if(L>N){let $=[];for(;w<h.nodes.length&&h.nodes[w].e<=N;)w++;for(let X=w;X<h.nodes.length&&h.nodes[X].s<L;X++){let be=h.nodes[X],G=Math.max(be.s,N),oe=Math.min(be.e,L);G<oe&&$.push({node:be.node,s:G-N,e:oe-N})}i.push({flatLocal:h.text.slice(N,L),localNodes:$,textNodes:te,lToM:Te.subarray?Te.subarray(N,L+1):Te.slice(N,L+1),mapLocal:X=>Me(N+Math.max(0,Math.min(X,L-N)))})}d=k+1}return i}let Js={...e,blocks:Gn,ignored:i=>Ue.has(i)||(e.ignored?e.ignored(i):!1)},jr=e.ignoreAttribute||(()=>!1),Ys=Qr(Qn(_e,Js),jr)!==Qr(y,jr);return{nodes:_e,text:fe,textNodes:te,localDiverged:Ys,mapLocal:Me,conflicts:l.slice(b),granularity:Ct?"line":"word",segments:Gs(),localHunks:xt,remoteHunks:A,lToM:Te}}var zi="http://www.w3.org/1999/xhtml";function qi(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Wt(e){return!!e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.namespaceURI===zi}function Ki(e){let t=(e.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Eo(e,t){let n=e.getAttribute("src"),o=(e.getAttribute("type")||"text/javascript").split(";")[0].trim().toLowerCase();if(n){let r=n;try{let s=new URL(n,t);r=s.origin+s.pathname+s.search}catch{}return"script|src|"+o+"|"+r}return"script|inline|"+o+"|"+qi(e.textContent.trim())}var Gi={match:e=>e.hasAttribute("merge"),identity:e=>e.getAttribute("merge")};function jn(e,t=[],n=!1){if(!Wt(e)||e.hasAttribute("src"))return null;let o=[Gi,...t];for(let r=0;r<o.length;r++){let s=o[r];if(!s.match(e))continue;if(!Ki(e))return n&&console.warn("[hyper-morph] merge ignored: script type is not JSON",e),null;let c=s.identity(e);return c==null||c===""?null:{key:r+":"+c,raw:c,recognizer:s}}return null}function is(e,t,n){let o=new Set,r=s=>{Wt(s)&&!t(s)&&o.add(Eo(s,n))};r(e);for(let s of e.querySelectorAll("script"))r(s);return o}function eo(e,t){let n=t.createElement("div");n.innerHTML="<script><\/script>";let o=n.firstChild;for(let r of e.attributes)o.setAttribute(r.name,r.value);return o.textContent=e.textContent,o}function cs(e,t,n){let o=[],r=[],s=Array.from(e.querySelectorAll("script"));Wt(e)&&s.unshift(e);for(let c of s){if(!Wt(c)||n.ignored(c)||n.skip.has(c)||t.has(Eo(c,n.baseURI)))continue;let l=c.ownerDocument.createElement("script");for(let a of c.attributes)l.setAttribute(a.name,a.value);l.textContent=c.textContent,n.beforeNodeAdded(l)!==!1&&(l.hasAttribute("src")&&r.push(new Promise(a=>{l.addEventListener("load",()=>a()),l.addEventListener("error",()=>a())})),c.replaceWith(l),n.afterNodeAdded(l),o.push(l))}return{executed:o,loads:r}}function Ji(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Yi(e,t){try{let n=new URL(e,t);return n.origin+n.pathname+n.search}catch{return e}}function ls(e,t){let n=e.tagName;if(n==="TITLE"||n==="BASE")return n;if(n==="SCRIPT")return Eo(e,t);if(n==="LINK"){let o=e.getAttribute("href");return o?"link|"+(e.getAttribute("rel")||"")+"|"+Yi(o,t):e.outerHTML}if(n==="META"){for(let o of["charset","name","property","http-equiv","itemprop"])if(e.hasAttribute(o))return"meta|"+o+"="+e.getAttribute(o);return e.outerHTML}return n==="STYLE"?"style|"+Ji(e.textContent):e.outerHTML}function rr(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
|
|
4
|
+
`;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function Xi(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var Zi=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Qi=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function sr(e){try{return JSON.parse(e)}catch{return JSON.parse(ec(e))}}function ec(e){let t="",n=0,o=(r,s)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${s}`)};for(;n<e.length&&(n=rr(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let l=rr(e,n+1);if(e[l]==="}"||e[l]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let l=n+1;for(;l<e.length&&e[l]!==r;)e[l]==="\\"&&l++,l++;l>=e.length&&o("unterminated string",n);let a=e.slice(n+1,l);r==="'"&&(a=Xi(a)),t+='"'+a+'"',n=l+1;continue}let s=n;for(;s<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[s]);)s++;s===n&&o("unexpected character "+JSON.stringify(r),n);let c=e.slice(n,s);if(c==="true"||c==="false"||c==="null"||Zi.test(c)){t+=c,n=s;continue}if(Qi.test(c)){if(e[rr(e,s)]===":"){t+='"'+c+'"',n=s;continue}o("unquoted value "+JSON.stringify(c),n)}o("invalid token "+JSON.stringify(c),n)}return t}var gt=Symbol("hyper-morph-json-merge:missing"),as=["id","_id","uuid","key","slug","code","name"];function Bn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function to(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function tc(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function gn(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!gn(e[n],t[n]))return!1;return!0}if(Bn(e)&&Bn(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!to(t,o)||!gn(e[o],t[o]))return!1;return!0}return!1}function fs(e,t,n,o){return gn(t,n)?t:gn(t,e)?n:gn(n,e)?t:Bn(t)&&Bn(n)?nc(Bn(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?ic(Array.isArray(e)?e:[],t,n,o):n}function us(e,t,n,o){return t===gt&&n===gt?gt:t===gt?e===gt?n:gn(n,e)?gt:n:n===gt?e===gt?t:gt:fs(e,t,n,o)}function nc(e,t,n,o){let r={},s=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let c of s){let l=us(to(e,c)?e[c]:gt,to(t,c)?t[c]:gt,to(n,c)?n[c]:gt,o);l!==gt&&tc(r,c,l)}return r}function oc(e){return e===null||typeof e!="object"}function Co(e){return typeof e+":"+String(e)}function rc(e,t){for(let n of t){let o=new Set;for(let r of n){if(!to(r,e))return!1;let s=r[e];if(typeof s!="string"&&typeof s!="number")return!1;let c=Co(s);if(o.has(c))return!1;o.add(c)}}return!0}function sc(e,t,n,o){let r=[e,t,n],s=!0;for(let c of r)for(let l of c)Bn(l)||(s=!1);if(s){for(let c of o.keyCandidates)if(rc(c,r))return{kind:"keyed",field:c};return null}for(let c of r){let l=new Set;for(let a of c){if(!oc(a))return null;let b=Co(a);if(l.has(b))return null;l.add(b)}}return{kind:"self"}}function ic(e,t,n,o){let r=sc(e,t,n,o);if(!r)return n;let s=r.kind==="self"?Co:u=>Co(u[r.field]),c=u=>{let h=new Map;for(let y of u)h.set(s(y),y);return h},l=c(e),a=c(t),b=c(n),p=new Map,g=new Set([...l.keys(),...a.keys(),...b.keys()]);for(let u of g){let h=us(l.has(u)?l.get(u):gt,a.has(u)?a.get(u):gt,b.has(u)?b.get(u):gt,o);h!==gt&&p.set(u,h)}let m=[];for(let u of n){let h=s(u);p.has(h)&&m.push(h)}for(let u=0;u<t.length;u++){let h=s(t[u]);if(!p.has(h)||m.includes(h))continue;let y=0;for(let S=u-1;S>=0;S--){let v=m.indexOf(s(t[S]));if(v!==-1){y=v+1;break}}m.splice(y,0,h)}return m.map(u=>p.get(u))}function ds(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...as]:as;return fs(e===void 0?gt:e,t,n,{keyCandidates:r})}function ir(e,t,n,o={}){let r=o.parse||sr,s=[],c=(g,m)=>{if(typeof g!="string")return gt;try{return r(g)}catch(u){return s.push(`${m} side is not valid JSON (${u.message})`),gt}},l=c(t,"local"),a=c(n,"remote");if(l===gt)return{text:n,warnings:s};if(a===gt)return{text:t,warnings:s};let b=c(e,"base"),p=ds(b===gt?void 0:b,l,a,o);return gn(p,a)?{text:n,warnings:s}:gn(p,l)?{text:t,warnings:s}:{text:JSON.stringify(p,null,2),warnings:s}}var Ee=e=>!!e&&e.nodeType===1,cc=new Set("P H1 H2 H3 H4 H5 H6 DIV LI DD DT BLOCKQUOTE FIGCAPTION SUMMARY ADDRESS".split(" ")),hs=5e4;function cr(e,t,n,o){let r=o.ignored,s=Gr({ignored:r,ignoreAttribute:o.ignoreAttribute}),{unitsOf:c,meta:l}=s,a=o.baseURI,b=o.mergeTags!==null,p=A=>C=>{if(b&&C.tagName==="SCRIPT"){let R=jn(C,o.mergeTags);if(R)return"merge:"+R.key}return C.parentElement&&C.parentElement.tagName==="HEAD"?ls(C,a):A(C)},g=p(o.identity.base),m=p(o.identity.local),u=p(o.identity.remote),h=o.authored||o.identity,y=A=>A&&A.nodeType===9?A.documentElement:A,S=y(e),v=y(t),D=y(n),q=globalThis.__hyperMorphProfile,Z=q?performance.now():0,ae="[id],[data-id],script,head>*",ie=A=>A===wn?ae:null,he=Mo(S,g,r,ie(o.identity.base)),K=o.localIsBase?ms():qo(S,v,{analyzer:s,baseIndex:he,sideIndex:Mo(v,m,r,ie(o.identity.local)),baseId:h.base,sideId:h.local}),J=qo(S,D,{analyzer:s,baseIndex:he,sideIndex:Mo(D,u,r,ie(o.identity.remote)),baseId:h.base,sideId:h.remote});qe(),Ke(K,J),Ke(J,K),q&&(q.alignTotal=(q.alignTotal||0)+(performance.now()-Z),Z=performance.now());let ye=S.ownerDocument.implementation.createHTMLDocument(""),je=new WeakMap,Fe=new WeakMap,ot=[],ct=[],Ct=new Set,vt=[],Oe=new Set,dt=new Set,Qe=new Set,Lt=new WeakMap,rt=o.conflicts||"remote",et=A=>ot.push(A),lt=A=>ot.push(A),O=A=>ct.push(A),F=Ne(),ke=x(S,K.map.get(S),J.map.get(S),!!o.localIsBase,!!o.childrenOnly);ke.tagName==="HTML"?ye.replaceChild(ke,ye.documentElement):ye.body.appendChild(ke),q&&(q.build=(q.build||0)+(performance.now()-Z));let re=o.childrenOnly?!Ge(ft(ke),ft(D)):!bt(ke,D);return{doc:ye,root:ke,provenance:je,textMappers:Fe,decisions:ot,conflicts:ct,localDiverged:re,mergedScripts:Ct,segments:vt,remoteIdOf:o.identity.remote,customIdentity:o.identity.remote!==wn,L:K,R:J};function Ne(){let A=new Map,C=new Set;if(o.localIsBase||!K.insertedByHash)return{partner:A,drop:C};let R=K.insertedByHash(),U=J.insertedByHash();if(!R.size||!U.size)return{partner:A,drop:C};let H={ignored:r,remoteWins:o.remoteWins,inlineCache:Lt},_=ue=>{let Ve=0;for(let Te=ue.parentNode;Te;Te=Te.parentNode)Ve++;return Ve},z=[],ne=ue=>{let Ve=ue.textContent.trim();return Ve.split(/\s+/).length>=3||Ve.replace(/\s/g,"").length>=12},pe=ue=>{let Ve=K.map.get(ue),Te=J.map.get(ue);return Ve&&K.reverse.get(Ve.parentNode)!==ue.parentNode||Te&&J.reverse.get(Te.parentNode)!==ue.parentNode},fe=(ue,Ve,Te)=>{for(let wt of Te.parentNode.children){let Ot=wt!==Te&&ue.reverse.get(wt);if(Ot&&pe(Ot))return!0}let It=ue.reverse.get(Te.parentNode);if(It){for(let wt of It.children)if(!Ve.map.has(wt)&&!r(wt))return!0}return!1};for(let[ue,Ve]of R){let Te=U.get(ue);if(!Te)continue;let It=Ve.length===1&&Te.length===1;for(let wt of Ve)xn(wt,H)||z.push([wt,Te,_(wt),It&&(ne(wt)||fe(K,J,wt)||fe(J,K,Te[0]))])}if(!z.length)return{partner:A,drop:C};z.sort((ue,Ve)=>ue[2]-Ve[2]);let me=new Set,Pe=new Set,Le=ue=>{for(let Ve of ue.querySelectorAll("*"))me.add(Ve)},kt=(ue,Ve)=>ue.reverse.get(Ve.parentNode)||null;for(let[ue,Ve,,Te]of z){if(me.has(ue))continue;let It=kt(K,ue),wt=ht=>!Pe.has(ht)&&!me.has(ht)&&ht.tagName===ue.tagName,Ot=Ve.find(ht=>wt(ht)&&It&&kt(J,ht)===It)||(Te?Ve.find(wt):null);Ot&&(Pe.add(Ot),Le(ue),Le(Ot),!(It&&kt(J,Ot)===It)&&(A.set(ue,Ot),A.set(Ot,ue),C.add(rt==="local"?Ot:ue)))}return{partner:A,drop:C}}function tt(A,C,R){if(Oe.add(A),F.drop.has(A))return null;Oe.add(R);let U=C==="local"?A:R,H=C==="local"?R:A,_;return s.unitHash(U)===s.unitHash(H)?(_=we(U,"local",!0),je.get(_).remote=H):_=Q(U,H),O({kind:"structure",el:_,detail:"both-moved",base:null,local:U,remote:H}),et({kind:"insert",el:_,source:"both"}),_}function qe(){if(!K.weak||!J.weak||!K.weak.size||!J.weak.size||!K.unpair)return;let A=new Map;for(let R of K.weak){let U=K.map.get(R);Ee(R)&&Ee(U)&&A.set(s.unitHash(U),R)}let C=!1;for(let R of Array.from(J.weak)){let U=J.map.get(R);if(!Ee(R)||!Ee(U))continue;let H=A.get(s.unitHash(U));!H||H===R||!K.weak.has(H)||K.map.has(R)&&J.map.has(H)||K.map.get(H).tagName===U.tagName&&(K.unpair(H),J.unpair(R),C=!0)}C&&(K.rematch(),J.rematch())}function Ke(A,C){if(!A.weak||!A.weak.size||!C.insertedByHash)return;let R=C.insertedByHash();if(!R.size)return;let U=!1;for(let H of Array.from(A.weak)){let _=A.map.get(H);if(!_)continue;let z=R.get(s.unitHash(_));z&&z.some(ne=>ne.tagName===_.tagName)&&(A.unpair(H),U=!0)}U&&A.rematch()}function Ze(A,C){if(A.map.has(C))return A.map.get(C);let R=[];for(let H=C.parentNode;H&&!A.map.has(H);H=H.parentNode)R.push(H);let U=R.length?R[R.length-1].parentNode:C.parentNode;if(!U||!A.identical.has(U))return null;A.pairIdenticalChildren(U);for(let H=R.length-1;H>=0;H--)A.pairIdenticalChildren(R[H]);return A.map.get(C)||null}function at(A,C,R){if(dt.has(A)||Qe.has(A))return O({kind:"structure",el:null,detail:"both-moved",base:A}),dt.has(A)?null:we(R,C);let U=Ze(K,A),H=Ze(J,A);(!U||!H)&&O({kind:"structure",el:null,detail:"move-beats-delete",base:A});let _=x(A,U,H,!1);return(C==="local"?et:lt)({kind:"move",el:_,source:C}),_}function f(A,C,R,U){return U||!C||C===R?{el:R,asBase:!0,twin:H=>H,baseOf:H=>H,units:c(R),here:()=>!0,parentOfTwin:()=>R}:{el:C,asBase:!1,twin:H=>A.map.get(H),baseOf:H=>A.reverse.get(H),units:c(C),here:H=>Ee(H)?H.parentNode===C||C.tagName==="TEMPLATE"&&H.parentNode===C.content:H.parent===C||C.tagName==="TEMPLATE"&&H.parent===C.content}}function T(A,C,R){return!C||R&&R.identical.has(A)?!1:Ee(A)?l(A).hash!==l(C).hash:A.value!==C.value}function x(A,C,R,U,H=!1){let _=U||o.remoteWins(A),z=A.namespaceURI&&A.namespaceURI!=="http://www.w3.org/1999/xhtml"?ye.createElementNS(A.namespaceURI,A.tagName):ye.createElement(A.tagName),ne={base:A,local:C||null,remote:R||null};if(je.set(z,ne),Oe.add(A),dt.add(A),C&&Oe.add(C),R&&Oe.add(R),o.skipUnchanged&&!H&&(o.localIsBase||K.identical.has(A))&&R&&J.identical.has(A)&&!o.remoteWins(A)){ne.unchanged=!0;for(let fe of A.attributes)fe.namespaceURI?z.setAttributeNS(fe.namespaceURI,fe.name,fe.value):z.setAttribute(fe.name,fe.value);return z}Qe.add(A),H||E(A,_?A:C,R,z);let pe=A.tagName;if(Wt(A))I(A,_?A:C,R,z);else if(pe==="TEXTAREA")z.textContent=B(A.textContent,(_?A:C)?(_?A:C).textContent:A.textContent,R?R.textContent:A.textContent,z,"text");else{let fe=Ye(A,C,R,_,z),me=pe==="TEMPLATE"&&z.content?z.content:z;for(let Pe of fe)me.appendChild(Pe)}return Qe.delete(A),z}function B(A,C,R,U,H){if(C===R)return C;if(C===A)return R!==A&<({kind:H,node:U,source:"remote"}),R;if(R===A)return et({kind:H,node:U,source:"local"}),C;let _=rt==="local"?C:R;return O({kind:H,node:U,base:A,local:C,remote:R,resolved:_}),ot.push({kind:H,node:U,source:"both"}),_}function I(A,C,R,U){let H=A.textContent,_=C?C.textContent:H,z=R?R.textContent:H,ne=b?jn(A,o.mergeTags,!0):null;if(ne&&_!==z){let pe=R&&R.getAttribute("merge-key")||A.getAttribute("merge-key"),{text:fe,warnings:me}=ir(o.localIsBase?void 0:H,_,z,{parse:ne.recognizer.parse,keyCandidates:pe?pe.split(/[\s,]+/).filter(Boolean):void 0});for(let Pe of me)console.warn(`[hyper-morph] merge "${ne.raw}": ${Pe}`);U.textContent=fe,Ct.add(U),fe!==z?et({kind:"text",node:U,source:fe===_?"local":"both"}):fe!==H&<({kind:"text",node:U,source:"remote"});return}U.textContent=B(H,_,z,U,"text")}function E(A,C,R,U){let H=new Map;for(let _ of[A,C,R])if(_)for(let z of _.attributes)o.ignoreAttribute(_,z.name)||H.set(z.name,z);for(let[_,z]of H){let ne=A?A.getAttribute(_):null,pe=C?C.getAttribute(_):ne,fe=R?R.getAttribute(_):ne,me;pe===fe?me=pe:pe===ne?(me=fe,lt({kind:"attr",el:U,name:_,source:"remote"})):fe===ne?(me=pe,et({kind:"attr",el:U,name:_,source:"local"})):(me=j(_,ne,pe,fe),me===void 0&&(me=rt==="local"?pe:fe,O({kind:"attr",el:U,name:_,base:ne,local:pe,remote:fe,resolved:me})),ot.push({kind:"attr",el:U,name:_,source:"both"})),me!=null&&(z.namespaceURI?U.setAttributeNS(z.namespaceURI,z.name,me):U.setAttribute(_,me))}}function j(A,C,R,U){if(A==="class"){let H=fe=>new Set((fe||"").split(/\s+/).filter(Boolean)),_=H(C),z=H(R),ne=H(U),pe=new Set;for(let fe of new Set([..._,...z,...ne])){let me=_.has(fe),Pe=z.has(fe),Le=ne.has(fe);(Pe===Le?Pe:Pe===me?Le:Pe)&&pe.add(fe)}return[...pe].join(" ")}if(A==="style"){let H=me=>{let Pe=new Map;if(!me)return Pe;let Le=0,kt=null,ue="",Ve=()=>{let Te=ue.indexOf(":");Te>0&&Pe.set(ue.slice(0,Te).trim(),ue.slice(Te+1).trim()),ue=""};for(let Te of me){if(kt){ue+=Te,Te===kt&&(kt=null);continue}if(Te==='"'||Te==="'"){kt=Te,ue+=Te;continue}if(Te==="("?Le++:Te===")"&&Le--,Te===";"&&Le===0){Ve();continue}ue+=Te}return ue.trim()&&Ve(),Pe},_=H(C),z=H(R),ne=H(U),pe=new Map,fe=!1;for(let me of new Set([..._.keys(),...z.keys(),...ne.keys()])){let Pe=_.get(me)??null,Le=z.get(me)??null,kt=ne.get(me)??null,ue;Le===kt?ue=Le:Le===Pe?ue=kt:kt===Pe?ue=Le:(ue=rt==="local"?Le:kt,fe=!0),ue!=null&&pe.set(me,ue)}return fe?void 0:[...pe].map(([me,Pe])=>`${me}: ${Pe}`).join("; ")}}function M(A,C,R,U){let H=A.value,_=U?H:C?C.value:"",z=R?R.value:"";Oe.add(A),C&&Oe.add(C),R&&Oe.add(R);let ne=Xn(H,_,z,rt),pe=ne.text===""?null:ye.createTextNode(ne.text);pe&&(je.set(pe,{base:A.nodes,local:C?C.nodes:null,remote:R?R.nodes:null}),Fe.set(pe,ne.mapLocalOffset)),_!==H&&z!==H?ot.push({kind:"text",node:pe,source:"both"}):_!==H?et({kind:"text",node:pe,source:"local"}):z!==H&<({kind:"text",node:pe,source:"remote"});for(let fe of ne.conflicts)O({kind:"text",node:pe,base:H.slice(fe.bs,fe.be),local:fe.local,remote:fe.remote,resolved:fe.resolved});return pe}function P(A,C){return Zn(A,C).every(R=>R.bs===R.be)}function Y(A,C){let R=A?A.value:"",U=C?C.value:"",H;if(R===U||!U?H=R:R?P(R,U)?H=U:P(U,R)?H=R:(H=rt==="local"?R:rt==="both"?R+U:U,O({kind:"structure",el:null,detail:"insert-collision",local:R,remote:U,resolved:H})):H=U,A&&Oe.add(A),C&&Oe.add(C),H==="")return null;let _=ye.createTextNode(H);return je.set(_,{base:null,local:A?A.nodes:null,remote:C?C.nodes:null}),R?et({kind:"insert",el:_,source:U&&R===U?"both":"local"}):lt({kind:"insert",el:_,source:"remote"}),_}function Q(A,C){let R={ignored:r,remoteWins:o.remoteWins,inlineCache:Lt},U=ne=>c(ne).every(pe=>Ee(pe)?xn(pe,R):pe.kind==="text"),H=null;if(U(A)&&U(C)){let ne=A.textContent,pe=C.textContent;ne===pe||P(pe,ne)?H=C:P(ne,pe)&&(H=A)}if(!H){let ne=rt==="local",pe=we(ne?A:C,ne?"local":"remote",!0),fe=je.get(pe);return ne?fe.remote=C:fe.local=A,O({kind:"structure",el:pe,detail:"insert-collision",local:A,remote:C,resolved:ne?A:C}),pe}let _=A.namespaceURI&&A.namespaceURI!=="http://www.w3.org/1999/xhtml"?ye.createElementNS(A.namespaceURI,A.tagName):ye.createElement(A.tagName);E(null,A,C,_),je.set(_,{base:null,local:A,remote:C}),Oe.add(A),Oe.add(C);let z=or({base:Array.from(H.childNodes),local:Array.from(A.childNodes),remote:Array.from(C.childNodes),out:ye,policy:rt,idOf:{local:m,remote:u},ignored:r,ignoreAttribute:o.ignoreAttribute,remoteWins:o.remoteWins,provenance:je,textMappers:Fe,conflicts:ct,decisions:ot,node:_});vt.push(...z.segments);for(let ne of z.nodes)_.appendChild(ne);return _}function we(A,C,R=!1){if(!R&&Ee(A)){let z=F.partner.get(A);if(z)return tt(A,C,z)}if(!Ee(A)){if(A.value==="")return null;let z=A.kind==="comment"?ye.createComment(A.value):ye.createTextNode(A.value);return je.set(z,{base:null,local:C==="local"?A.nodes:null,remote:C==="remote"?A.nodes:null}),Oe.add(A),z}let U=A.namespaceURI&&A.namespaceURI!=="http://www.w3.org/1999/xhtml"?ye.createElementNS(A.namespaceURI,A.tagName):ye.createElement(A.tagName);for(let z of A.attributes)z.namespaceURI?U.setAttributeNS(z.namespaceURI,z.name,z.value):U.setAttribute(z.name,z.value);je.set(U,{base:null,local:C==="local"?A:null,remote:C==="remote"?A:null}),Oe.add(A);let H=A.tagName==="TEMPLATE"&&U.content?U.content:U,_=C==="local"?K:J;for(let z of c(A)){let ne=Ee(z)?_.reverse.get(z):null;if(ne&&dt.has(ne)){O({kind:"structure",el:null,detail:"both-moved",base:ne});continue}if(ne&&!Qe.has(ne)){let fe=K.map.get(ne)||null,me=J.map.get(ne)||null;if(fe||me){let Pe=x(ne,fe,me,!1);C==="local"?et({kind:"move",el:Pe,source:"local"}):lt({kind:"move",el:Pe,source:"remote"}),H.appendChild(Pe);continue}}let pe=we(z,C);pe&&H.appendChild(pe)}return U}function Ye(A,C,R,U,H){C&&K.identical.has(A)&&K.pairIdenticalChildren(A),R&&J.identical.has(A)&&J.pairIdenticalChildren(A);let _=f(K,C,A,U),z=f(J,R,A,!1),ne=c(A),pe=new Set(ne),fe=new Map;for(let W=0;W<ne.length;W++)fe.set(ne[W],W);let me=[],Pe=new Set,Le=new Map,kt=new Set,ue=new Set,Ve=[];wo();let Te=W=>{let xe=[];for(let de of W.units){if(ue.has(de))continue;let Me=W.baseOf(de);Me&&pe.has(Me)&&xe.push(fe.get(Me))}return xe},It=W=>W.every((xe,de)=>de===0||xe>=W[de-1]),wt=!_.asBase&&!It(Te(_)),Ot=!z.asBase&&!It(Te(z));wt&&Ot&&O({kind:"structure",el:null,detail:"both-reordered",base:A});let ht=Ot||!wt?{V:z,A:J,side:"remote",other:_,otherA:K,otherSide:"local"}:{V:_,A:K,side:"local",other:z,otherA:J,otherSide:"remote"};wt?et({kind:"move",el:null,source:Ot?"both":"local",base:A}):Ot&<({kind:"move",el:null,source:"remote",base:A});let zn=_.asBase?[]:_.units.filter(W=>!_.baseOf(W)&&!ue.has(W)&&!F.partner.has(W)),qn=z.asBase?[]:z.units.filter(W=>!z.baseOf(W)&&!ue.has(W)&&!F.partner.has(W)),rn=new Map;if(zn.length&&qn.length){let W=new Map,xe=new Map;for(let te of qn){if(Ee(te)){let ee=u(te);ee&&W.set(ee,te)}let Ae=s.unitHash(te);xe.has(Ae)||xe.set(Ae,[]),xe.get(Ae).push(te)}let de=(te,Ae)=>{let ee=te.units.indexOf(Ae);for(let ve=ee-1;ve>=0;ve--){let He=te.baseOf(te.units[ve]);if(He)return He}return"start"},Me=new Map,_e=new Map;for(let te of qn){let Ae=de(z,te);Ee(te)?(_e.has(Ae)||_e.set(Ae,[]),_e.get(Ae).push(te)):te.kind==="text"&&!Me.has(Ae)&&Me.set(Ae,te)}for(let te of zn){let Ae=null;if(Ee(te)){let ee=m(te);ee&&W.has(ee)&&!rn.has(W.get(ee))&&(Ae=W.get(ee))}else if(te.kind==="text"){let ee=Me.get(de(_,te));ee&&!rn.has(ee)&&(Ae=ee)}if(!Ae){let ee=xe.get(s.unitHash(te));ee&&(Ae=ee.find(ve=>!rn.has(ve)&&Ee(ve)===Ee(te)&&(Ee(ve)?ve.tagName===te.tagName:ve.kind===te.kind))||null)}if(!Ae&&Ee(te)){let ee=h.local(te),ve=(_e.get(de(_,te))||[]).filter(He=>{let Et=h.remote(He);return!rn.has(He)&&He.tagName===te.tagName&&!(ee&&Et&&ee!==Et)&&s.similar(te,He)});ve.length===1&&(Ae=ve[0])}Ae&&(rn.set(Ae,te),rn.set(te,Ae))}}let Gt=W=>{if(Oe.has(W))return Le.get(W)||null;let xe=_.twin(W),de=z.twin(W),Me=xe&&!_.asBase&&!_.here(xe),_e=de&&!z.asBase&&!z.here(de);if(Me||_e){if((!xe||!de)&&O({kind:"structure",el:null,detail:"move-beats-delete",base:W}),!Ut(W))return Oe.add(W),null;O({kind:"structure",el:null,detail:"both-moved",base:W})}if(!xe&&!de)return Oe.add(W),lt({kind:"remove",source:"both",base:W}),null;if(!xe&&!T(W,de,J))return Oe.add(W),et({kind:"remove",source:"local",base:W}),null;if(!de&&!T(W,xe,K))return Oe.add(W),lt({kind:"remove",source:"remote",base:W}),null;let te=!xe||!de,Ae=_.asBase?K.map.get(W)||null:xe,ee;return Ee(W)?ee=x(W,Ae,de,_.asBase):W.kind==="comment"?ee=yt(W,Ae,de,_.asBase):ee=M(W,Ae,de,_.asBase),Oe.add(W),ee&&(Le.set(W,ee),xe&&Le.set(xe,ee),de&&Le.set(de,ee),te&&(O({kind:"structure",el:ee,detail:"edit-beats-delete",base:W}),xe?et({kind:"insert",el:ee,source:"local"}):lt({kind:"insert",el:ee,source:"remote"}))),ee},vn=(W,xe,de,Me)=>{if(Oe.has(W))return Le.get(W)||null;let _e=xe.baseOf(W);if(_e&&pe.has(_e))return ue.has(_e)&&!ue.has(W)?bo(_e,W,Me):Gt(_e);if(_e)return yo(_e,W,Me);let te=rn.get(W);if(te){let ee=Me==="local"?W:te,ve=Me==="local"?te:W,He;return Ee(ee)?s.unitHash(ee)===s.unitHash(ve)?(He=we(ee,"local"),je.get(He).remote=ve):He=Q(ee,ve):He=Y(ee,ve),Oe.add(ee),Oe.add(ve),He&&(Le.set(ee,He),Le.set(ve,He),Ee(ee)&&et({kind:"insert",el:He,source:"both"})),He}let Ae=we(W,Me);return Ae&&(Le.set(W,Ae),Me==="local"?et({kind:"insert",el:Ae,source:"local"}):lt({kind:"insert",el:Ae,source:"remote"})),Ae},bo=(W,xe,de)=>{let Me;return Ee(W)?(Me=at(W,de,xe),Me&&Oe.add(xe)):(Me=we(xe,de),Oe.add(xe),Me&&(de==="local"?et:lt)({kind:"insert",el:Me,source:de})),Me&&Le.set(xe,Me),Me},yo=(W,xe,de)=>{let _e=(de==="local"?J:K).map.get(W),te=xe,Ae=_e?At(_e,de==="local"?R:C,de==="local"?J:K):!1,ee=_e&&!Ae&&!xt(W,_e);if(ee&&de===ht.otherSide)return O({kind:"structure",el:null,detail:"both-moved",base:W}),null;if(ee&&O({kind:"structure",el:null,detail:"both-moved",base:W}),_e||O({kind:"structure",el:null,detail:"move-beats-delete",base:W}),Qe.has(W)){O({kind:"structure",el:null,detail:"both-moved",base:W});let He=we(te,de);return He&&Le.set(xe,He),He}let ve=Ee(W)?x(W,de==="local"?te:K.map.get(W)||null,de==="remote"?te:J.map.get(W)||null,!1):null;return ve&&(Le.set(W,ve),Le.set(xe,ve),_e&&Le.set(_e,ve),de==="local"?et({kind:"move",el:ve,source:"local"}):lt({kind:"move",el:ve,source:"remote"})),ve};for(let W of ht.V.units){if(ue.has(W)){let de=Le.get(W);Pe.has(de)||(me.push(de),Pe.add(de));continue}if(Oe.has(W)&&!(Le.get(W)&&Pe.has(Le.get(W)))){let de=ht.V.baseOf(W);de&&!pe.has(de)&&O({kind:"structure",el:null,detail:"both-moved",base:de});continue}let xe=vn(W,ht.V,ht.A,ht.side);xe&&!Pe.has(xe)&&(me.push(xe),Pe.add(xe),!ht.V.baseOf(W)&&!rn.has(W)&&!ue.has(W)&&kt.add(xe))}for(let W of Ve)Pe.has(W.frag)||(me.splice(ko(W.at),0,W.frag),Pe.add(W.frag));if(!ht.other.asBase){let W=ht.other,xe=ht.otherSide,de=ht.otherA,Me=null,_e=0,te=null;for(let Ae of W.units){let ee=Le.get(Ae);if(ee&&Pe.has(ee)){Me=ee,te=null;continue}if(Oe.has(Ae)){let Et=W.baseOf(Ae);Et&&!pe.has(Et)&&O({kind:"structure",el:null,detail:"both-moved",base:Et});continue}let ve=vn(Ae,W,de,xe);if(!ve)continue;let He;if(te)He=me.indexOf(te)+1;else if(Me){if(He=me.indexOf(Me)+1,xe==="remote")for(;He<me.length&&kt.has(me[He]);)He++}else He=_e++;me.splice(He,0,ve),Pe.add(ve),te=ve}}for(let W=0;W<ne.length;W++){let xe=ne[W];if(Oe.has(xe))continue;let de=Gt(xe);de&&me.splice(ko(W),0,de)}return me;function ko(W){for(let xe=W-1;xe>=0;xe--){let de=Le.get(ne[xe]);if(de){let Me=me.indexOf(de);if(Me>=0)return Me+1}}return 0}function In(W){let xe={ignored:r,remoteWins:()=>!1},de=V=>W(V)||Ee(V)&&o.remoteWins(V)&&sn.has(V.tagName)&&xn(V,xe),Me=new Map,_e=V=>{if(!Ee(V)||!cc.has(V.tagName))return!1;let ce=Me.get(V);return ce===void 0&&(ce=!r(V)&&!o.remoteWins(V)&&c(V).every(de),Me.set(V,ce)),ce},te=V=>!Ee(V)&&V.kind==="text",Ae=null,ee=new Map,ve=V=>{let ce=ee.get(V);if(ce)return ce;let ge=Ee(V)?V.textContent:V.value;ce=new Set;let Ce=ge.toLowerCase();if(!(ge.length>hs))if(/^[\x00-\x7f]*$/.test(Ce))for(let Se of Ce.split(/[^\p{L}\p{N}]+/u))Se&&ce.add(Se);else for(let Se of Xo(Ce))/^[\s\p{P}]+$/u.test(Se)||ce.add(Se);return ee.set(V,ce),ce},He=V=>(Ee(V)?V.textContent:V.value).toLowerCase().replace(/\s+/g," ").trim(),Et=new Map,Jt=V=>{let ce=Et.get(V);if(ce)return ce;ce=new Set(ve(V));let ge=Se=>{if(Se)for(let $e of ve(Se))ce.add($e)},Ce=pe.has(V)?V:!_.asBase&&_.baseOf(V)||!z.asBase&&z.baseOf(V);return Ce&&(ge(Ce),ge(K.map.get(Ce)),ge(J.map.get(Ce))),Et.set(V,ce),ce},an=(V,ce)=>{let ge=He(ce),Ce=pe.has(V)?V:!_.asBase&&_.baseOf(V)||!z.asBase&&z.baseOf(V),Se=ut=>ge?ut.split(ge).length-1:0;if(Ce&&Ee(ce)&&!pe.has(ce)){let ut=Se(He(Ce));for(let pt of[K.map.get(Ce),J.map.get(Ce)]){if(!pt||pt===ce||pt.ownerDocument!==ce.ownerDocument)continue;let qt=He(pt);if(qt.length>ge.length&&Se(qt)>=ut&&(qt.startsWith(ge)||qt.endsWith(ge)))return!1}}let $e=ve(ce),Xe=Jt(V),Pt=0;for(let ut of $e)Xe.has(ut)&&Pt++;if($e.size&&Pt*2>=$e.size)return!0;if(!ge||ge.length>hs)return!1;let _t=Ce?[V,Ce,K.map.get(Ce),J.map.get(Ce)]:[V],Vt=(ut,pt)=>ut!==pt&&(ut.startsWith(pt)||ut.endsWith(pt));if(_t.some(ut=>ut&&Vt(He(ut),ge)))return!0;if(!pe.has(ce)||!Ce)return!1;let Tt=He(V),zt=He(Ce);return[K.map.get(ce),J.map.get(ce)].some(ut=>{let pt=ut&&He(ut);return!!pt&&Tt!==pt&&(Tt.startsWith(pt)&&!zt.startsWith(pt)||Tt.endsWith(pt)&&!zt.endsWith(pt))})},Bt=V=>{Ae||(Ae=new Set),Ae.add(V)},hn=V=>{Bt(V);for(let[ce,ge]of[[K,_],[J,z]]){if(ge.asBase)continue;let Ce=ce.map.get(V);Ce&&ge.here(Ce)&&Bt(Ce)}},Re=(V,ce)=>V.asBase||ne.every(ge=>!Ee(ge)||ce.identical.has(ge)&&V.here(ce.map.get(ge)))&&V.units.every(ge=>!Ee(ge)||V.baseOf(ge));if(Re(_,K)&&Re(z,J))return null;let Ue=V=>{if(V.asBase)return!1;let ce=-1;for(let ge of V.units){let Ce=Ee(ge)?V.baseOf(ge):null;if(!Ce||!pe.has(Ce))continue;let Se=fe.get(Ce);if(Se<ce)return!0;ce=Se}return!1};if(Ue(_)||Ue(z))return null;for(let[V,ce]of[[_,K],[z,J]]){if(V.asBase||Re(V,ce))continue;let ge=V.units,Ce=ce===K?h.local:h.remote,Se=(se,We)=>{let st=Ee(se)&&h.base(se),Je=Ee(We)&&Ce(We);return!st||!Je||st===Je},$e=new Map;for(let se=0;se<ge.length;se++)$e.set(ge[se],se);let Xe=se=>!!se&&(Ee(se)?V.here(se):$e.has(se)),Pt=se=>{let We=V.twin(se);return Xe(We)?We:null},_t=ne.filter(se=>!V.twin(se)&&_e(se)),Vt=ge.filter(se=>!V.baseOf(se)&&_e(se)),Tt=(se,We)=>We===ne?!!Pt(se):pe.has(V.baseOf(se)),zt=se=>{let We=new Int32Array(se.length),st=new Int32Array(se.length),Je=-1;for(let ze=0;ze<se.length;ze++)We[ze]=Je,Tt(se[ze],se)&&(Je=ze);Je=se.length;for(let ze=se.length-1;ze>=0;ze--)st[ze]=Je,Tt(se[ze],se)&&(Je=ze);return{prev:We,next:st}},ut=zt(ge),pt=zt(ne),qt=(se,We)=>{hn(se),Bt(We)};for(let se of Vt){let We=$e.get(se),st=ut.prev[We],Je=ut.next[We],ze=st>=0?V.baseOf(ge[st]):null,tn=Je<ge.length?V.baseOf(ge[Je]):null,Yt=ze?fe.get(ze):-1,pn=tn?fe.get(tn):ne.length;for(let Kt=Math.max(0,Yt);Kt<=Math.min(pn,ne.length-1);Kt++){let jt=ne[Kt];(_e(jt)||te(jt))&&(!Se(jt,se)||!an(jt,se)||(te(jt)?Bt(se):qt(jt,se)))}}let en=(se,We,st)=>{for(let Je=We+st;Je>=0&&Je<se.length;Je+=st){let ze=se[Je];if(_e(ze))return ze;if(Ee(ze)||ze.value.trim())return null}return null},Ao=se=>{let We=new Set;for(let st of c(se))if(!Ee(st)&&st.kind==="text")for(let Je of ve(st))We.add(Je);return We},Kn=(se,We)=>{let st=ve(We),Je=new Set;for(let ze of Ao(se))st.has(ze)||Je.add(ze);return Je},Gn=(se,We)=>{if(!se.size)return!1;let st=ve(We),Je=0;for(let ze of se)st.has(ze)&&Je++;return Je*2>=se.size};for(let se of ne){if(ce.identical.has(se)||!_e(se))continue;let We=Pt(se);if(!We||!_e(We))continue;let st=Kn(We,se),Je=Kn(se,We);for(let ze of[-1,1]){let tn=en(ne,fe.get(se),ze);tn&&Gn(st,tn)&&(qt(se,We),hn(tn));let Yt=en(ge,$e.get(We)??-1,ze);if(Yt&&Gn(Je,Yt)){qt(se,We);let pn=V.baseOf(Yt);pn?qt(pn,Yt):Bt(Yt)}}}for(let se of _t){let We=fe.get(se),st=pt.prev[We],Je=pt.next[We],ze=st>=0?Pt(ne[st]):null,tn=Je<ne.length?Pt(ne[Je]):null,Yt=ze?$e.get(ze)??-1:-1,pn=tn?$e.get(tn)??-1:ge.length;for(let Kt=Math.max(0,Yt);Kt<=Math.min(pn,ge.length-1);Kt++){let jt=ge[Kt];if((_e(jt)||te(jt))&&!(!Se(se,jt)||!an(jt,se))&&(hn(se),!te(jt))){let $t=V.baseOf(jt);$t?qt($t,jt):Bt(jt)}}}}if(!Ae)return null;for(let V of Array.from(Ae))if(pe.has(V))for(let ce of[K,J]){let ge=ce.map.get(V);ge&&ge.parentNode!==(ce===K?C:R)&&!(ce===K?_:z).asBase&&Ae.delete(V)}return Ae.size?Ae:null}function wo(){if((_.asBase||K.identical.has(A))&&(z.asBase||J.identical.has(A)))return;let W={ignored:r,remoteWins:o.remoteWins,inlineCache:Lt},xe=Re=>Ee(Re)?xn(Re,W):Re.kind==="text",de=In(xe),Me=Re=>de&&de.has(Re)||xe(Re),_e=ne.map(Me);if(!_e.includes(!0))return;let te=Re=>{let Ue=Re.units,V=new Map;for(let Xe=0;Xe<Ue.length;Xe++)V.set(Ue[Xe],Xe);let ce=[],ge=-1;for(let Xe=0;Xe<ne.length;Xe++){if(_e[Xe])continue;let Pt=Re.twin(ne[Xe]),_t=Pt?V.get(Pt):void 0;_t===void 0||_t<=ge||Me(Pt)||(ce.push([Xe,_t]),ge=_t)}let Ce=[],Se=-1,$e=-1;for(let Xe=0;Xe<=ce.length;Xe++){let[Pt,_t]=Xe<ce.length?ce[Xe]:[ne.length,Ue.length],Vt={bLo:-1,bHi:-1,sLo:-1,sHi:-1,next:_t};for(let Tt=Se+1;Tt<Pt;Tt++)_e[Tt]&&(Vt.bLo<0&&(Vt.bLo=Tt),Vt.bHi=Tt);for(let Tt=$e+1;Tt<_t;Tt++)Me(Ue[Tt])&&(Vt.sLo<0&&(Vt.sLo=Tt),Vt.sHi=Tt);Ce.push(Vt),Se=Pt,$e=_t}return{units:Ue,list:Ce}},Ae=te(_),ee=te(z),ve=[];for(let Re of[Ae,ee])for(let Ue of Re.list)Ue.bLo>=0&&ve.push([Ue.bLo,Ue.bHi]);ve.sort((Re,Ue)=>Re[0]-Ue[0]);let He=[];for(let[Re,Ue]of ve){let V=He[He.length-1];V&&Re<=V.hi?V.hi=Math.max(V.hi,Ue):He.push({lo:Re,hi:Ue})}let Et=(Re,Ue)=>{let V=-1,ce=-1;for(let Se=0;Se<Re.list.length;Se++){let $e=Re.list[Se];$e.bLo<Ue.lo||$e.bLo>Ue.hi||(V<0&&(V=Se),ce=Se)}let ge=1/0,Ce=-1;for(let Se=V;Se>=0&&Se<=ce;Se++){let $e=Re.list[Se];$e.sLo>=0&&(ge=Math.min(ge,$e.sLo),Ce=Math.max(Ce,$e.sHi)),Se<ce&&(ge=Math.min(ge,$e.next),Ce=Math.max(Ce,$e.next))}return Ce<0?[]:Re.units.slice(ge,Ce+1)},Jt=(Re,Ue)=>Re.length===Ue.length&&Re.every((V,ce)=>s.unitHash(V)===s.unitHash(Ue[ce])),an=Re=>!Ee(Re)&&Re.kind==="comment",Bt=Re=>{if(!Re.length)return[];let Ue=(Se,$e)=>Ee(Se)?Se:Se.nodes[$e?Se.nodes.length-1:0],V=Ue(Re[0]),ce=Ue(Re[Re.length-1],!0),ge=Se=>Se&&Ee(Se)&&r(Se);for(;ge(V.previousSibling);)V=V.previousSibling;for(;ge(ce.nextSibling);)ce=ce.nextSibling;let Ce=[];for(let Se=V;Se&&(Ce.push(Se),Se!==ce);Se=Se.nextSibling);return Ce},hn=Re=>Re.some(Ue=>Ee(Ue)&&r(Ue));for(let Re of He){let Ue=ne.slice(Re.lo,Re.hi+1),V=_.asBase?null:Et(Ae,Re),ce=z.asBase?null:Et(ee,Re);if(Ue.some(an)||V&&V.some(an)||ce&&ce.some(an))continue;let ge=Bt(V||Ue),Ce=Bt(ce||Ue);if((!V||Jt(Ue,V))&&(!ce||Jt(Ue,ce))&&!(V&&hn(ge)))continue;let Se=or({base:Bt(Ue),local:ge,remote:Ce,out:ye,policy:rt,blocks:de,L:V?K:ps(K,A),R:ce?J:ps(J,A),idOf:{local:m,remote:u},ignored:r,ignoreAttribute:o.ignoreAttribute,remoteWins:o.remoteWins,mergeElement:(Xe,Pt,_t)=>x(Xe,Pt,_t,!1),cloneUnit:we,mergeAttrs:E,atomKey:s.unitHash,moveIn:at,provenance:je,textMappers:Fe,conflicts:ct,decisions:ot,node:H});vt.push(...Se.segments);let $e=ye.createDocumentFragment();for(let Xe of Se.nodes)$e.appendChild(Xe);for(let Xe of[...Ue,...V||[],...ce||[]])Oe.add(Xe),ue.add(Xe),Le.set(Xe,$e);Ve.push({frag:$e,at:Re.lo})}}}function bt(A,C){let R=je.get(A);return R&&R.unchanged?!0:A.tagName!==C.tagName||!le(A,C)?!1:Ge(ft(A),ft(C))}function ft(A){return A.tagName==="TEMPLATE"&&A.content?A.content:A}function le(A,C){let R=0;for(let U of A.attributes)if(!o.ignoreAttribute(A,U.name)&&(R++,C.getAttribute(U.name)!==U.value))return!1;for(let U of C.attributes)o.ignoreAttribute(C,U.name)||R--;return R===0}function Ge(A,C){let R=Rt(A,H=>{let _=je.get(H);return!!(_&&_.pinned)}),U=Rt(C,r);if(R.length!==U.length)return!1;for(let H=0;H<R.length;H++){let _=R[H],z=U[H];if(typeof _=="string"||typeof z=="string"){if(_!==z)return!1}else{if(_.nodeType!==z.nodeType)return!1;if(_.nodeType===1){if(!bt(_,z))return!1}else if(_.nodeValue!==z.nodeValue)return!1}}return!0}function Rt(A,C){let R=[],U=null;for(let H=A.firstChild;H;H=H.nextSibling){if(H.nodeType===3){U=U===null?H.nodeValue:U+H.nodeValue;continue}H.nodeType===1&&C(H)||(U!==null&&(U!==""&&R.push(U),U=null),R.push(H))}return U!==null&&U!==""&&R.push(U),R}function yt(A,C,R,U){let H=A.value,_=U?H:C?C.value:"",z=R?R.value:"";Oe.add(A),C&&Oe.add(C),R&&Oe.add(R);let ne=_===z?_:_===H?z:z===H||rt==="local"?_:z;if(_!==H&&z!==H&&_!==z&&O({kind:"text",node:null,base:H,local:_,remote:z,resolved:ne}),!C&&!R)return null;let pe=ye.createComment(ne);return je.set(pe,{base:A.nodes,local:C?C.nodes:null,remote:R?R.nodes:null}),pe}function Dt(A,C){let R=C.map.get(A);if(!R)return null;let U=Ee(R)?R.parentNode:R.parent,H=Ee(A)?A.parentNode:A.parent;return C.map.get(H)===U?null:C.reverse.get(U)||null}function Ut(A){let C=new Set([A]),R=A;for(let U=0;U<64;U++){let H=Dt(R,K)||Dt(R,J);if(!H)return!1;if(H===A||Ee(A)&&Ee(H)&&A.contains(H)||C.has(H))return!0;C.add(H),R=H}return!0}function At(A,C,R){if(!C)return!1;let U=Ee(A)?A.parentNode:A.parent;return U===C||C.tagName==="TEMPLATE"&&U===C.content}function xt(A,C){let R=Ee(A)?A.parentNode:A.parent,U=Ee(C)?C.parentNode:C.parent;return!!(K.map.get(R)===U?K:J.map.get(R)===U?J:null)}}function ps(e,t){return e.map.get(t)?ms():{map:{get:o=>o&&o.nodeType===1&&e.map.get(o)||o,has:()=>!0},reverse:{get:o=>e.reverse.get(o)||o,has:()=>!0},moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}function ms(){let e={get:t=>t,has:()=>!0};return{map:e,reverse:e,moved:new Set,identical:{has:()=>!0},pairIdenticalChildren:()=>{}}}var gs=new Set(["INPUT","OPTION","TEXTAREA"]);function bs(e,t,n,o){let r=e.ownerDocument,{provenance:s,textMappers:c}=n,l=o.hooks,a=[],b=[],p=[],g=new Set,m=[],u=[],h=new Set,y=new Map,S=f=>!!f&&(f===e||e.contains(f)||e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content.contains(f)),v=new Map,D=new Map,q=new Map,Z=new Map;(function f(T){let x=s.get(T);if(x){if(T.nodeType===1){let I=x.local?o.toLive(x.local):null;I&&S(I)&&I.nodeType===1&&(v.set(T,I),D.set(I,T))}else if(Array.isArray(x.local)){let I=K(x.local,x.local.map(E=>o.toLive(E)).filter(E=>E&&S(E)&&E.nodeType===T.nodeType));if(I.length&&(v.set(T,I[0]),D.set(I[0],T),q.set(T,I)),Array.isArray(x.caret))for(let E of x.caret){let j=o.toLive(E.node);if(!j||!S(j)||j.nodeType!==3)continue;let M=Z.get(j);Array.isArray(M)||Z.set(j,M=[]),M.push({merged:T,from:E.from,to:E.to,flatStart:E.flatStart})}else{let E=0;for(let j of I)Z.set(j,{merged:T,shift:E}),E+=j.nodeValue.length}}}let B=T.nodeType===1&&T.tagName==="TEMPLATE"&&T.content?T.content.childNodes:T.childNodes;for(let I of B)f(I)})(t);let ae=new Set;for(let f of v.values())ae.add(f);for(let f of q.values())for(let T of f)ae.add(T);for(let f of n.segments||[])J(f);let ie=o.restoreFocus===!1?null:lc(r,Z);o.childrenOnly?ot(ye(e),ye(t)):je(e,t);for(let{node:f,parent:T}of m)g.has(f)||!f.parentNode||f.nodeType===1&&(o.ignored(f)||ct(f))||lt(f,T);return ac(r,ie,Z,c,q,y),{applied:a,moved:b,replaced:p,identities:u,mergedScriptsLive:h,liveOf:v};function he(f,T){let x=f.slice(T.bs,T.be),B=0;for(;B<x.length&&B<T.text.length&&x[B]===T.text[B];)B++;let I=0;for(;I<x.length-B&&I<T.text.length-B&&x[x.length-1-I]===T.text[T.text.length-1-I];)I++;return{bs:T.bs+B,be:T.be-I,text:T.text.slice(B,T.text.length-I)}}function K(f,T){if(!T.length)return T;let x=new Set;for(let I of f){let E=I.parentNode;if(E)for(let j=E.firstChild;j;j=j.nextSibling)j.nodeType===3&&x.add(o.toLive(j))}let B=[];for(let I of T){B.push(I);for(let E=I.nextSibling;E&&E.nodeType===3&&!x.has(E)&&!B.includes(E);E=E.nextSibling)B.push(E)}return B}function J(f){let T=[];for(let le of f.localNodes){let Ge=o.toLive(le.node);if(!Ge||!S(Ge)||Ge.nodeType!==3)return;T.push(Ge)}let x=K(f.localNodes.map(le=>le.node),T);if(!x.length)return;let B=x.map(le=>le.nodeValue).join(""),{flatLocal:I,lToM:E,mapLocal:j}=f;if(B===I)return;let M=f.textNodes.map(le=>({node:le.node,ms:le.ms,me:le.me})),P=[],Y=0;for(let le of x)P.push(Y),Y+=le.nodeValue.length;let Q=(le,Ge)=>x.find((Rt,yt)=>P[yt]<=le&&le+Ge<=P[yt]+Rt.nodeValue.length)||null,we=[],Ye=0;for(let le of Zn(I,B).map(Ge=>he(I,Ge))){let Ge=le.bs+Ye;Ye+=le.text.length-(le.be-le.bs);let Rt,yt;if(le.be>le.bs){Rt=E[le.bs];let Dt=Rt>=0;for(let Ut=le.bs;Dt&&Ut<le.be;Ut++)E[Ut]!==Rt+(Ut-le.bs)&&(Dt=!1);if(!Dt)continue;yt=Rt+(le.be-le.bs)}else{let Dt=le.bs>0?E[le.bs-1]:0,Ut=le.bs<I.length?E[le.bs]:0;if(Dt<0||Ut<0)continue;Rt=yt=j(le.bs)}we.push({ms:Rt,me:yt,text:le.text,live:yt===Rt?Q(Ge,le.text.length):null})}we.sort((le,Ge)=>Ge.ms-le.ms);let bt=(le,Ge)=>(q.get(le.node)||[v.get(le.node)]).includes(Ge),ft=le=>!!le&&le.nodeType===1&&sn.has(le.tagName);for(let le of we){let Ge=M.find(yt=>yt.ms<=le.ms&&le.me<=yt.me&&le.ms<yt.me);if(Ge&&le.live&&Ge.ms===le.ms&&!bt(Ge,le.live)){let yt=M.find(Dt=>Dt.me===le.ms&&bt(Dt,le.live));yt&&(Ge=yt)}if(!Ge&&le.me===le.ms){let yt=M.find(xt=>xt.me===le.ms),Dt=M.find(xt=>xt.ms===le.ms),Ut=yt||Dt;if(!Ut)continue;let At=Ut.node;for(;ft(At.parentNode)&&(yt?At.parentNode.lastChild:At.parentNode.firstChild)===At;)At=At.parentNode;if(At===Ut.node)Ge=Ut;else{let xt=At.ownerDocument.createTextNode(le.text);At.parentNode.insertBefore(xt,yt?At.nextSibling:At);continue}}if(!Ge)continue;let Rt=Ge.node.nodeValue;Ge.node.nodeValue=Rt.slice(0,le.ms-Ge.ms)+le.text+Rt.slice(le.me-Ge.ms),Ge.me+=le.text.length-(le.me-le.ms)}}function ye(f){return f.nodeType===1&&f.tagName==="TEMPLATE"&&f.content?f.content:f}function je(f,T){g.add(f);let x=s.get(T);if(x&&x.remote&&n.remoteIdOf){let I=n.remoteIdOf(x.remote);I&&u.push([f,I])}if(x&&x.unchanged){n.customIdentity&&x.remote&&dt(f,x.remote),x.remote&&Oe(f,x.remote);return}if(l.beforeNodeMorphed(f,T)===!1)return;ke(f,T);let B=f.tagName;if(Wt(f))f.textContent!==T.textContent&&(a.push({kind:"text",node:f,before:f.textContent,after:T.textContent}),f.textContent=T.textContent),n.mergedScripts.has(T)&&h.add(f);else if(B==="TEXTAREA")at(f,T,x);else{Ke(f,T,x);let I=B==="TEMPLATE"&&f.content?f.content:f,E=B==="TEMPLATE"&&T.content?T.content:T;o.protectFocusedValue==="subtree"&&Ne(f)&&f!==r.body?Fe(I):ot(I,E)}l.afterNodeMorphed(f,T)}function Fe(f){for(let T=f.firstChild;T;T=T.nextSibling){let x=D.get(T);x&&v.get(x.parentNode)!==f||(g.add(T),T.nodeType===1&&Fe(T))}}function ot(f,T){let x=rt(f.firstChild),B=new Set;for(let I of Array.from(T.childNodes)){let E=v.get(I);E&&g.has(E)&&!B.has(E)&&(E=null);let j=s.get(I);if(j&&j.pinned){E&&E.nodeType===1&&((E.parentNode!==f||rt(E.nextSibling)!==x)&&et(f,E,x),g.add(E),B.add(E));continue}if(E&&E.nodeType===1){if(E!==x){let Y=E.parentNode;if(Y===f&&x&&tt(E)){let Q=E.nextSibling;for(let we=x;we&&we!==E;){let Ye=we.nextSibling;et(f,we,Q),we=Ye}}else et(f,E,x),Y!==f&&(b.push(E),a.push({kind:"move",el:E,from:Y,to:f}))}B.add(E),je(E,I),x=rt(E.nextSibling);continue}if(E&&E.nodeType!==1){let Y=q.get(I)||[E];E!==x&&et(f,E,x);let Q=I.nodeValue;if(I.nodeType===3){let we=Ct(I),Ye=Y.map(bt=>bt.nodeValue).join("");we!=null&&Ye!==we&&(Q=Xn(we,Ye,I.nodeValue).text)}l.beforeNodeMorphed(E,I)!==!1&&(E.nodeValue!==Q&&(a.push({kind:"text",node:E,before:E.nodeValue,after:Q}),E.nodeValue=Q),l.afterNodeMorphed(E,I)),g.add(E),B.add(E),y.set(I,E),x=rt(E.nextSibling);continue}if(I.nodeType===3&&x&&x.nodeType===3&&!g.has(x)&&!Z.has(x)){x.nodeValue!==I.nodeValue&&(a.push({kind:"text",node:x,before:x.nodeValue,after:I.nodeValue}),x.nodeValue=I.nodeValue),g.add(x),y.set(I,x),x=rt(x.nextSibling);continue}let M=s.get(I),P=O(M&&M.unchanged&&M.remote?M.remote:I);l.beforeNodeAdded(P)!==!1&&(f.insertBefore(P,x),g.add(P),P.nodeType===3&&y.set(I,P),P.nodeType===1&&(p.push(P),Lt(P,I),Wt(P)||F(P,I),o.formState==="property"&&qe(M)&&Oe(P,M.remote)),x=rt(P.nextSibling),a.push({kind:"insert",node:P,parent:f}),l.afterNodeAdded(P))}for(let I of Array.from(f.childNodes))g.has(I)||B.has(I)||I.nodeType===1&&(o.ignored(I)||ct(I))||(ae.has(I)?m.push({node:I,parent:f}):lt(I,f))}function ct(f){return o.preserve&&f.parentNode&&f.parentNode.nodeType===1&&f.parentNode.tagName==="HEAD"&&o.preserve(f)===!0}function Ct(f){let T=s.get(f);return!T||!Array.isArray(T.local)?null:T.local.map(x=>x.nodeValue).join("")}function vt(f){return s.get(f)}function Oe(f,T){if(!gs.has(f.tagName)&&!f.querySelector("input,option,textarea"))return;let x=(B,I)=>{if(B.tagName!==I.tagName)return;B.tagName==="TEXTAREA"?at(B,I,{remote:I}):gs.has(B.tagName)&&Ke(B,I,{remote:I});let E=Qe(B),j=Qe(I);if(E.length===j.length)for(let M=0;M<E.length;M++)x(E[M],j[M])};x(f,T)}function dt(f,T){let x=Qe(f),B=Qe(T);if(x.length===B.length)for(let I=0;I<x.length;I++){let E=n.remoteIdOf(B[I]);E&&u.push([x[I],E]),dt(x[I],B[I])}}function Qe(f){let T=f.tagName==="TEMPLATE"&&f.content?f.content:f;return Array.from(T.children).filter(x=>!o.ignored(x))}function Lt(f,T){if(!n.remoteIdOf)return;let x=(B,I)=>{let E=s.get(I);if(E&&E.remote&&I.nodeType===1){let P=n.remoteIdOf(E.remote);P&&u.push([B,P])}let j=B.childNodes,M=I.childNodes;for(let P=0;P<j.length&&P<M.length;P++)x(j[P],M[P])};x(f,T)}function rt(f){for(;f&&f.nodeType===1&&o.ignored(f);)f=f.nextSibling;return f}function et(f,T,x){if(typeof f.moveBefore=="function"&&T.ownerDocument===f.ownerDocument)try{f.moveBefore(T,x);return}catch{}f.insertBefore(T,x)}function lt(f,T){l.beforeNodeRemoved(f)!==!1&&(f.parentNode.removeChild(f),a.push({kind:"remove",node:f,parent:T}),l.afterNodeRemoved(f))}function O(f){if(Wt(f))return eo(f,r);let T=r.importNode(f,!0);if(T.nodeType===1)for(let x of Array.from(T.querySelectorAll("script")))Wt(x)&&x.replaceWith(eo(x,r));return T}function F(f,T){let x=f.tagName==="TEMPLATE"&&f.content?f.content:f,B=T.tagName==="TEMPLATE"&&T.content?T.content:T,I=Array.from(x.childNodes),E=Array.from(B.childNodes);for(let j=0;j<E.length&&j<I.length;j++){let M=E[j],P=I[j],Y=v.get(M);Y&&g.has(Y)&&(Y=null);let Q=s.get(M);if(Q&&Q.pinned){if(Y&&Y.nodeType===1){let we=Y.parentNode;et(x,Y,P),we!==x&&(b.push(Y),a.push({kind:"move",el:Y,from:we,to:x})),g.add(Y)}P.remove();continue}if(Y){let we=Y.parentNode;et(x,Y,P),P.remove(),Y.nodeType===1?(we!==x&&(b.push(Y),a.push({kind:"move",el:Y,from:we,to:x})),je(Y,M)):(g.add(Y),y.set(M,Y),Y.nodeValue!==M.nodeValue&&(a.push({kind:"text",node:Y,before:Y.nodeValue,after:M.nodeValue}),Y.nodeValue=M.nodeValue));continue}g.add(P),P.nodeType===3&&y.set(M,P),M.nodeType===1&&!Wt(M)&&F(P,M)}}function ke(f,T){for(let x of Array.from(T.attributes)){if(re(f,x.name)||o.ignoreAttribute(f,x.name))continue;let B=x.namespaceURI?f.getAttributeNS(x.namespaceURI,x.localName):f.getAttribute(x.name);B!==x.value&&l.beforeAttributeUpdated(x.name,f,"update")!==!1&&(x.namespaceURI?f.setAttributeNS(x.namespaceURI,x.name,x.value):f.setAttribute(x.name,x.value),a.push({kind:"attr",el:f,name:x.name,before:B,after:x.value}))}for(let x of Array.from(f.attributes)){if(re(f,x.name)||o.ignoreAttribute(f,x.name)||(x.namespaceURI?T.hasAttributeNS(x.namespaceURI,x.localName):T.hasAttribute(x.name))||l.beforeAttributeUpdated(x.name,f,"remove")===!1)continue;let I=x.value;x.namespaceURI?f.removeAttributeNS(x.namespaceURI,x.localName):f.removeAttribute(x.name),a.push({kind:"attr",el:f,name:x.name,before:I,after:null})}}function re(f,T){let x=f.tagName;return x==="INPUT"?T==="value"||T==="checked"||T==="disabled":x==="OPTION"?T==="selected":!1}function Ne(f){return f===r.activeElement}function tt(f){let T=r.activeElement;return!!T&&T!==r.body&&f.contains(T)}function qe(f){let T=f&&f.remote;return T&&T.nodeType===1?T:null}function Ke(f,T,x){let B=f.tagName,I=qe(x),E=o.formState==="property"&&I?I:T;if(B==="INPUT"){let j=o.protectFocusedValue&&Ne(f),M=(f.getAttribute("type")||"").toLowerCase(),P=M!=="file"&&M!=="checkbox"&&M!=="radio",Y=I&&I.hasAttribute("value")&&I.value!==I.getAttribute("value")?I.value:null;if(P&&!j)if(o.formState==="property"){let Q=T.getAttribute("value"),we=f.getAttribute("value");(we!==Q||f.value!==E.value)&&l.beforeAttributeUpdated("value",f,Q==null?"remove":"update")!==!1&&(we!==Q&&(Q==null?f.removeAttribute("value"):f.setAttribute("value",Q),a.push({kind:"attr",el:f,name:"value",before:we,after:Q})),f.value!==E.value&&(f.value=E.value))}else if(T.hasAttribute("value")||Y!=null){let Q=Y??T.getAttribute("value");f.getAttribute("value")!==Q&&l.beforeAttributeUpdated("value",f,"update")!==!1?(f.setAttribute("value",Q),f.value!==Q&&(f.value=Q),a.push({kind:"attr",el:f,name:"value",before:null,after:Q})):f.value!==Q&&f.getAttribute("value")===Q&&(f.value=Q)}else(f.hasAttribute("value")||f.value!=="")&&l.beforeAttributeUpdated("value",f,"remove")!==!1&&(f.removeAttribute("value"),f.value="",a.push({kind:"attr",el:f,name:"value",before:"",after:null}));if(!P&&M!=="file"){let Q=T.getAttribute("value");Q==null?f.hasAttribute("value")&&l.beforeAttributeUpdated("value",f,"remove")!==!1&&f.removeAttribute("value"):f.getAttribute("value")!==Q&&l.beforeAttributeUpdated("value",f,"update")!==!1&&f.setAttribute("value",Q)}j||(Ze(f,E,"checked"),o.formState==="property"&&f.indeterminate!==E.indeterminate&&(f.indeterminate=E.indeterminate)),Ze(f,E,"disabled")}else if(B==="OPTION"){let j=f.parentNode&&f.closest("select");o.protectFocusedValue&&j&&Ne(j)||Ze(f,E,"selected")}}function Ze(f,T,x){let B=o.formState==="property"?!!T[x]:T.hasAttribute(x);if(o.formState!=="property"){let I=f.hasAttribute(x);if(I!==B){if(l.beforeAttributeUpdated(x,f,B?"update":"remove")===!1)return;B?f.setAttribute(x,""):f.removeAttribute(x),a.push({kind:"attr",el:f,name:x,before:I?"":null,after:B?"":null})}}f[x]!==B&&(f[x]=B)}function at(f,T,x){if(o.protectFocusedValue&&Ne(f)||l.beforeAttributeUpdated("value",f,"update")===!1)return;let B=qe(x),I=T.textContent,E=B&&B.value!==B.defaultValue?B.value:I;o.formState!=="property"&&f.textContent!==I&&(a.push({kind:"text",node:f,before:f.textContent,after:I}),f.textContent=I),f.value!==E&&(f.value=E)}}function lc(e,t){let n=e.activeElement;if(!n||n===e.body||n===e.documentElement)return null;let o={el:n,id:n.getAttribute&&n.getAttribute("id"),scrollTop:n.scrollTop,scrollLeft:n.scrollLeft};if(n.tagName==="INPUT"||n.tagName==="TEXTAREA"){try{o.selection=[n.selectionStart,n.selectionEnd,n.selectionDirection]}catch{}return o}let r=e.getSelection&&e.getSelection();if(r&&r.rangeCount){let s=r.getRangeAt(0);o.range={sc:s.startContainer,so:s.startOffset,ec:s.endContainer,eo:s.endOffset}}return o}function ac(e,t,n,o,r,s){if(!t)return;let c=t.el;if(!c.isConnected&&t.id&&(c=e.getElementById(t.id)),!c||!c.isConnected)return;if(e.activeElement!==c)try{c.focus({preventScroll:!0})}catch{}try{c.scrollTop=t.scrollTop,c.scrollLeft=t.scrollLeft}catch{}if(t.selection){try{c.setSelectionRange&&!c.selectionEnd&&t.selection[1]!=null&&c.setSelectionRange(t.selection[0],t.selection[1],t.selection[2]||"none")}catch{}return}if(!t.range)return;let l=(p,g)=>{let m=n.get(p);if(Array.isArray(m)){let u=m.find(v=>g>=v.from&&g<v.to)||m.find(v=>g===v.to)||m[m.length-1],h=s.get(u.merged);if(!h||!h.isConnected)return null;let y=o.get(u.merged),S=y&&y.flat?y.flat(u.flatStart+g):g;return[h,Math.max(0,Math.min(S,h.nodeValue.length))]}if(m){let u=(r.get(m.merged)||[p])[0];if(!u.isConnected)return null;let h=o.get(m.merged),y=m.shift+g,S=h?h(y):y;return[u,Math.max(0,Math.min(S,u.nodeValue.length))]}return p.isConnected?[p,Math.min(g,p.nodeType===3?p.nodeValue.length:p.childNodes.length)]:null},a=l(t.range.sc,t.range.so),b=l(t.range.ec,t.range.eo);if(!(!a||!b))try{let p=e.createRange();p.setStart(a[0],a[1]),p.setEnd(b[0],b[1]);let g=e.getSelection();g.removeAllRanges(),g.addRange(p)}catch{}}var Cl=Symbol("hyper-morph-duplicate-key");var fc='[editor-ui],[clay~="editor-ui"],[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]',uc='[editor-ui],[clay~="editor-ui"],[no-undo],[clay~="no-undo"]',dc='[no-undo]:not([editor-ui]):not([clay~="editor-ui"]),[clay~="no-undo"]:not([editor-ui]):not([clay~="editor-ui"])';function hc(e){if(e.tagName!=="LINK"&&e.tagName!=="SCRIPT")return!1;let t=e.getAttribute("src")||e.getAttribute("href")||"";return/^(chrome|moz|safari-web)-extension:/.test(t)}function pc(e,t,n,o){if(t==null)return;if(typeof t=="string")return t;let r=t;if(r.nodeType===9){let s=e.getAttribute("id");r=s&&r.getElementById(s)||(e.tagName==="BODY"?r.body:e.tagName==="HTML"?r.documentElement:r.body&&r.body.firstElementChild)}if((!r||r.nodeType!==1||r.tagName!==e.tagName)&&(r=mc(e,t,o)),!!r)return n?Array.from(r.childNodes):r}function mc(e,t,n){let o=t.nodeType===9?t.documentElement:t;if(!o||o.nodeType!==1)return null;let r=new Map,s=[o,...o.querySelectorAll("script")];for(let a of s){let b=jn(a,n);b&&!r.has(b.key)&&r.set(b.key,a.textContent)}if(!r.size)return null;let c=e.cloneNode(!0),l=!1;for(let a of[c,...c.querySelectorAll("script")]){let b=jn(a,n);b&&r.has(b.key)&&(a.textContent=r.get(b.key),l=!0)}return l?c:null}function ys(e,t){if(typeof e=="string"||e.nodeType===9)return e;if(e.nodeType===1&&e===e.ownerDocument.documentElement)return e.ownerDocument;let n=t.implementation.createHTMLDocument(""),o=e.nodeType===1&&e.tagName==="HTML"?e:null;if(o)return n.replaceChild(n.adoptNode(o),n.documentElement),n;let r=e.nodeType===11?Array.from(e.childNodes):e.nodeType?[e]:Array.from(e);for(let s of r)n.body.appendChild(n.adoptNode(s));return n}function lr(e,t,n={}){let o=n||{};if(!o.head?.block)return ks(e,t,o);try{return ks(e,t,o)}catch(r){return Promise.reject(r)}}function ks(e,t,n){let o=n.policy||"sync",r=o==="raw"?void 0:(a,b)=>hc(a)||(o==="history"?!(b&&a.matches(dc))&&a.matches(uc):a.matches(fc)),s=n.callbacks||{},c={ignore:r,hooks:s,protectFocusedValue:n.ignoreActiveValue===!0?"subtree":!1,restoreFocus:n.restoreFocus!==!1,formState:n.formStateSync||"attribute",scripts:{execute:n.scripts?.handle!==!1,merge:n.scripts?.merge!==!1,mergeTags:n.scripts?.mergeTags||[]},head:{awaitLoads:!!n.head?.block,preserve:n.head?.shouldPreserve||(()=>!1)}};if(typeof n.key=="function"&&(c.identity={base:n.key,local:n.key,remote:n.key}),e&&e.nodeType===9)return no(Object.assign({},c,{live:e,base:n.scripts?.mergeBase||null,remote:ys(t,e)}));if(e.tagName==="HTML"&&e.parentNode&&e.parentNode.nodeType===9){let a=Object.assign({},c,{live:e.ownerDocument,base:n.scripts?.mergeBase||null,remote:ys(t,e.ownerDocument)});return no(a)}n.morphStyle==="innerHTML"&&(c.children=!0);let l=pc(e,n.scripts?.mergeBase,!!c.children,c.scripts.mergeTags);return l!==void 0&&(c.base=l),ar(e,t,c)}var gc=new Set(["live","base","remote","local","identity","ignore","remoteWins","ignoreAttribute","conflicts","protectFocusedValue","restoreFocus","head","scripts","formState","children","hooks","beforeApply"]),on=()=>{};function oo(e,t=[]){if(!e||typeof e!="object")throw new TypeError("options object required");for(let c of Object.keys(e))if(!gc.has(c))throw new TypeError(`unknown option "${c}"`);let n=Object.assign({beforeNodeAdded:on,afterNodeAdded:on,beforeNodeRemoved:on,afterNodeRemoved:on,beforeNodeMorphed:on,afterNodeMorphed:on,beforeAttributeUpdated:on},e.hooks||{}),o=e.conflicts||"remote";if(!["remote","local","both"].includes(o))throw new TypeError("conflicts must be remote, local or both");let r=e.formState||"attribute";if(!["attribute","property"].includes(r))throw new TypeError("formState must be attribute or property");let s=e.protectFocusedValue;if(s!==void 0&&typeof s!="boolean"&&s!=="subtree")throw new TypeError('protectFocusedValue must be a boolean or "subtree"');return{ignored:Vo(e.ignore,t),remoteWins:Vo(e.remoteWins,t),ignoreAttribute:typeof e.ignoreAttribute=="function"?e.ignoreAttribute:()=>!1,conflicts:o,protectFocusedValue:s===void 0?!0:s,restoreFocus:e.restoreFocus!==!1,head:Object.assign({awaitLoads:!1,preserve:()=>!1},e.head||{}),scripts:Object.assign({execute:!0,merge:!0,mergeTags:[]},e.scripts||{}),formState:r,hooks:n,children:!!e.children,beforeApply:typeof e.beforeApply=="function"?e.beforeApply:null}}function _n(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){if(typeof e.first=="function")return e.first;if(typeof e.then=="function")return e.then}return wn}function Un(e,t){if(typeof e=="function")return e;if(e&&typeof e=="object"&&e.map){let n=zo(t,e.map),o=typeof e.then=="function"?e.then:wn;if(typeof e.first=="function"){let r=e.first;return s=>r(s)||n.get(s)||o(s)}return r=>n.get(r)||o(r)}return wn}function bc(e,t,n,o={}){let r=g=>g&&g.nodeType===9?g.documentElement:g,s=r(t),c=r(n),l=r(e)||s,a=Object.assign({},o);delete a.live,delete a.base,delete a.remote;let b=oo(a,[l,s,c].filter(Boolean)),p=o.identity||{};return cr(l,s,c,{identity:{base:Un(p.base,l),local:Un(p.local,s),remote:Un(p.remote,c)},authored:{base:_n(p.base),local:_n(p.local),remote:_n(p.remote)},skipUnchanged:b.hooks.beforeNodeMorphed===on&&b.hooks.afterNodeMorphed===on,ignored:b.ignored,remoteWins:b.remoteWins,ignoreAttribute:b.ignoreAttribute,conflicts:b.conflicts,mergeTags:b.scripts.merge===!1?null:b.scripts.mergeTags,baseURI:s.ownerDocument&&s.ownerDocument.baseURI||"about:blank",localIsBase:!e||e===t,childrenOnly:b.children})}function fr({liveRoot:e,baseRoot:t,localRoot:n,remoteRoot:o,toLive:r,options:s,identity:c,childrenOnly:l,isDocument:a}){let b=oo(s,[e,t,n,o].filter(Boolean));if(b.ignored(e))return{report:ur(),loads:[]};let p=e.ownerDocument,g=b.scripts.execute?is(e,b.ignored,p.baseURI):null,m=cr(t||n,n,o,{identity:{base:Un(c.base,t||n),local:Un(c.local,n),remote:Un(c.remote,o)},authored:{base:_n(c.base),local:_n(c.local),remote:_n(c.remote)},ignored:b.ignored,remoteWins:b.remoteWins,ignoreAttribute:b.ignoreAttribute,conflicts:b.conflicts,mergeTags:b.scripts.merge===!1?null:b.scripts.mergeTags,baseURI:p.baseURI,localIsBase:!t,childrenOnly:l,skipUnchanged:b.hooks.beforeNodeMorphed===on&&b.hooks.afterNodeMorphed===on});b.beforeApply&&b.beforeApply(m.doc);let u=globalThis.__hyperMorphProfile,h=u?performance.now():0,y=bs(e,m.root,m,{toLive:r,ignored:b.ignored,ignoreAttribute:b.ignoreAttribute,formState:b.formState,protectFocusedValue:b.protectFocusedValue,restoreFocus:b.restoreFocus,preserve:b.head.preserve,hooks:b.hooks,childrenOnly:l});u&&(u.apply=(u.apply||0)+(performance.now()-h));let S=[];if(b.head.awaitLoads)for(let q of y.applied){if(q.kind!=="insert"||q.node.nodeType!==1)continue;let Z=q.node;Z.tagName==="LINK"&&/\bstylesheet\b/i.test(Z.getAttribute("rel")||"")&&Z.getAttribute("href")&&Z.closest("head")&&S.push(new Promise(ie=>{Z.addEventListener("load",()=>ie()),Z.addEventListener("error",()=>ie())}))}if(g){let q=cs(e,g,{ignored:b.ignored,skip:y.mergedScriptsLive,baseURI:p.baseURI,beforeNodeAdded:b.hooks.beforeNodeAdded,afterNodeAdded:b.hooks.afterNodeAdded});S.push(...q.loads)}let v=q=>q&&y.liveOf&&y.liveOf.get(q)||null;return{report:{applied:y.applied,decisions:m.decisions.map(q=>Object.assign({},q,{node:q.node?v(q.node):null,el:q.el?v(q.el):null,applied:!!(q.node?v(q.node):q.el&&v(q.el))})),conflicts:m.conflicts.map(q=>Object.assign({},q,{node:q.node?v(q.node):q.node,el:q.el?v(q.el):q.el})),localDiverged:m.localDiverged,identities:y.identities,moved:y.moved,replaced:y.replaced},loads:S}}var ws=new WeakMap;function ur(){return{applied:[],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[]}}function no(e){let t=e||{},n=t.live;if(!n||n.nodeType!==9)throw new TypeError("live must be a Document");let o=ws.get(n);o||(o=Fo(n),ws.set(n,o));let r=o("remote",t.remote),s=typeof t.base=="string"&&t.base===""?null:t.base,c=s?o("base",s):null,l=t.local?t.local.root:n.documentElement,a=t.local?t.local.toLive:g=>g;Fr(n,r);let{report:b,loads:p}=fr({liveRoot:n.documentElement,baseRoot:c?c.documentElement:null,localRoot:l,remoteRoot:r.documentElement,toLive:a,options:t,identity:t.identity||{},childrenOnly:!1,isDocument:!0});return Promise.all(p).then(()=>b)}function yc(e,t,n={}){return no(Object.assign({},n,{live:e,base:null,remote:t}))}function As(e,t){if(e==null)return{root:t.createElement("template"),first:null};if(typeof e=="string"){let o=/^\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype[^>]*>\s*)?<(html|body)[\s>]/i.exec(e);if(o){let s=Oo(e,t),c=o[1].toLowerCase()==="html"?s.documentElement:s.body;return{root:c,first:c}}let r=t.createElement("template");return r.innerHTML=e,{root:r,first:r.content.firstElementChild}}if(e.nodeType===9)return{root:e.documentElement,first:e.documentElement};if(e.nodeType===1){let o=t.createElement("template"),r=e.isConnected;return o.content.appendChild(r?t.importNode(e,!0):e),{root:o,first:e}}if(e.nodeType===11){let o=t.createElement("template");return o.content.appendChild(e),{root:o,first:o.content.firstElementChild}}let n=t.createElement("template");for(let o of Array.from(e))n.content.appendChild(o.parentNode?t.importNode(o,!0):o);return{root:n,first:n.content.firstElementChild}}function ar(e,t,n={}){if(!e||e.nodeType!==1)throw new TypeError("oldEl must be an Element");let o=e.ownerDocument,{base:r,...s}=n,c=!!s.children;if(oo(s,[e]).ignored(e))return Promise.resolve(ur());let l=As(t,o),a=r!=null?As(r,o):null,b,p=null;if(c)b=l.root,p=a?a.root:null;else{if(b=l.first,p=a?a.first:null,!b){let u=oo(s);return u.hooks.beforeNodeRemoved(e)!==!1&&(e.remove(),u.hooks.afterNodeRemoved(e)),Promise.resolve({applied:[{kind:"remove",node:e,parent:null}],decisions:[],conflicts:[],localDiverged:!1,identities:[],moved:[],replaced:[e]})}if(b.tagName!==e.tagName){let u=oo(s,[e,b]);if(u.hooks.beforeNodeMorphed(e,b)===!1)return Promise.resolve(ur());let h=fr({liveRoot:e,baseRoot:p&&p.tagName===e.tagName?p:null,localRoot:e,remoteRoot:b,toLive:S=>S,options:s,identity:s.identity||{},childrenOnly:!0,isDocument:!1}),y=Wt(b)?eo(b,o):o.importNode(b,!1);if(!Wt(y))for(;e.firstChild;)y.appendChild(e.firstChild);return u.hooks.beforeNodeAdded(y)===!1||u.hooks.beforeNodeRemoved(e)===!1?Promise.resolve(h.report):(e.replaceWith(y),u.hooks.afterNodeRemoved(e),u.hooks.afterNodeAdded(y),u.hooks.afterNodeMorphed(e,b),h.report.replaced.push(y),h.report.applied.push({kind:"insert",node:y,parent:y.parentNode},{kind:"remove",node:e,parent:y.parentNode}),Promise.all(h.loads).then(()=>h.report))}}let{report:g,loads:m}=fr({liveRoot:e,baseRoot:p,localRoot:e,remoteRoot:b,toLive:u=>u,options:s,identity:s.identity||{},childrenOnly:c,isDocument:!1});return Promise.all(m).then(()=>g)}var xs={mergeDocument:no,morphDocument:yc,morphElement:ar,merge3:bc,morph:lr};function dr(e,t,{onWidgetRemoved:n}={}){xs.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=So.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var wc="hha:upgrade-check:";function cn(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function hr(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ts(e,t){let n=hr(e),o=hr(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let s=0;s<r;s++){let c=n[s]||0,l=o[s]||0;if(c!==l)return c>l}return!1}function Ac(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function xc(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function pr({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:s=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(m=>fetch(m)),r=r??Date.now(),!t)return null;let c=cn(t,"hyper-source");if(!c)return null;let l=cn(t,"hyper-version"),a;try{a=new URL(c,n?n.href:void 0)}catch{return null}if(n&&a.origin===n.origin&&a.pathname===n.pathname)return null;let b=`${wc}${a.href}:${l||"none"}`,p,g=e?null:Ac(b);if(g&&typeof g.checkedAt=="number"&&r-g.checkedAt<s)p=g.sourceVersion;else{try{let m=await o(a.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let u=await m.text(),h=new DOMParser().parseFromString(u,"text/html");p=cn(h,"hyper-version")}catch{p=null}xc(b,{checkedAt:r,sourceVersion:p})}return p?{available:Ts(p,l||"0.0.0"),currentVersion:l,sourceVersion:p,sourceUrl:a.href}:null}var Lo=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],mr=new Set(Lo),Ss=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),gr=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Po={};Bo(Po,{EmptyListInsert:()=>so,MAX_RULE_DEPTH:()=>$n,MaxRuleDepthExceeded:()=>Sn,NoRulesTag:()=>br,RuleTargetReadOnly:()=>io,RulesParseError:()=>Wn,ShapeMismatch:()=>ro,UnknownRulesVersion:()=>Tn,WriteRefused:()=>Ro,WriteRejected:()=>yr});var Wn=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},Tn=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},$n=20,Sn=class extends Error{constructor(t){super(`rule depth exceeded ${$n} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},ro=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},so=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},io=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},Ro=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}},br=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},yr=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function ln(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return kr(e,t,n,{depth:0,path:[]},o)}function kr(e,t,n,o,r){if(o.depth>$n)throw new Sn(o.path);if(typeof n=="string")return Tc(e,t,n,o,r);if(Array.isArray(n)){let[s,c]=n,l=e.find(t,s,r);return Os(r,o,l),l.map((a,b)=>kr(e,a,c,{depth:o.depth+1,path:[...o.path,b]},r))}if(typeof n=="object"&&n!==null){let s={};for(let[c,l]of Object.entries(n))s[c]=kr(e,t,l,{depth:o.depth+1,path:[...o.path,c]},r);return s}return null}function Tc(e,t,n,o,r){if(n.endsWith("[]")){let l=n.slice(0,-2),a=e.find(t,l,r);return Os(r,o,a),a.map(b=>e.text(b))}if(n.startsWith("@"))return Ns(e,t,n.slice(1));let s=dn(n);if(s!==-1){let l=n.slice(0,s),a=n.slice(s+1),b=l?e.find(t,l,r):[t];return b.length===0?null:Ns(e,b[0],a)}if(n===".")return e.text(t);let c=e.find(t,n,r);return c.length===0?null:e.text(c[0])}function Os(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function Ns(e,t,n){if(mr.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}var Ms=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),Sc=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),vs=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function wr(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Nc(e,t){if(wr(e,t))return!0;for(let[n,o]of Object.entries(Sc))if(o.includes(t)&&wr(e,n))return!0;return!1}function co(e){let t=Ms[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Oc(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=Ms[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Nc(n,r))||o.bundles.some(r=>wr(n,r)))return n;n=n.parentElement}return null}function Is(e,t){return!!Oc(e,t)}var Mc=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Es(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();if("value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&(t.value=e.value),"checked"in e&&"checked"in t&&(t.checked=e.checked),"selected"in e&&"selected"in t&&(t.selected=e.selected),e.tagName==="SELECT")for(let o=0;o<e.options.length;o++)t.options[o].selected=e.options[o].selected;"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Cs(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function Ls(e,t,n,o,r,s,c,l){if(e.nodeType===1&&((c?Is(e,n):Cs(e,o,s,!1))||r&&Cs(e,r,s,c)))return null;let a=t.importNode(e,!1);l.cloneToLive.set(a,e),l.liveToClone.set(e,a);let b=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,p=a.nodeType===1&&a.tagName==="TEMPLATE"?a.content:a;b!==e&&(l.cloneToLive.set(p,b),l.liveToClone.set(b,p));for(let g of b.childNodes||[]){let m=Ls(g,t,n,o,r,s,c,l);m&&(p.appendChild(m),g.nodeType===1&&Es(g,m))}return e.nodeType===1&&Es(e,a),a}function lo(e,{capability:t="data",exclude:n=null,inherit:o=!0}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let r=e.nodeType===9?e:e.ownerDocument;if(!r?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=r.implementation.createHTMLDocument(""),c=new WeakMap,l=new WeakMap,a=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let b=co(t),p=Ls(a,s,t,b,n,a,o,{cloneToLive:c,liveToClone:l});e.nodeType===9&&p&&(s.replaceChild(p,s.documentElement),l.set(e,s),c.set(s,e));let g=m=>{if(Mc.test(m))throw new Error(`Filtered content queries do not support stateful selector: ${m}`)};return{root:p,document:s,capability:t,selector:co(t),cloneToLive:c,liveToClone:l,original(m){return c.get(m)||null},cloneOf(m){return l.get(m)||null},query(m,u=p){return g(m),Array.from(u.querySelectorAll(m),h=>c.get(h)||h)},text(m=p){return(m===p?p:l.get(m))?.textContent||""},html(m=p){return(m===p?p:l.get(m))?.innerHTML??""},clone(m=p){let u=m===p?p:l.get(m);return u?s.importNode(u,!0):null}}}function Rs(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function vc(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Mt={semanticExclude:!0,find(e,t,n={}){let o=vc(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(l=>!Rs(l)));let s=[];n.skip&&s.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&s.push("["+c+"]"),s.length){let l=s.join(", ");r=r.filter(a=>!a.closest||!a.closest(l))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function Nn(e,t={}){if(t.exclude===null)return Mt;let n=[co("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return Mt;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,l=null,a=()=>l||(l=lo(s,{capability:"data",exclude:t.exclude||null})),b=h=>{let y=a();return h===e?y.cloneOf(e):y.cloneOf(h)||h},p=h=>l?.original(h)||h,g=(h,y)=>{a().liveToClone.set(h,y),a().cloneToLive.set(y,h);let S=h.childNodes||[],v=y.childNodes||[];for(let D=0;D<Math.min(S.length,v.length);D++)g(S[D],v[D])},m=(h,y,S,v)=>{let D=Array.from(h.childNodes).filter(he=>l.cloneOf(he)),Z=D[0];for(;Z&&D.includes(Z);)Z=Z.nextSibling;for(let he of D)he.remove();if(S==="innerHTML"){let he=c.createElement("template");he.innerHTML=v;for(let K of Array.from(he.content.childNodes))h.insertBefore(K,Z||null)}else h.insertBefore(c.createTextNode(v),Z||null);let ae=lo(h,{capability:"data",exclude:t.exclude||null});y.replaceChildren(...Array.from(ae.root?.childNodes||[]));let ie=he=>{let K=ae.original(he);K&&(l.liveToClone.set(K,he),l.cloneToLive.set(he,K));for(let J of Array.from(he.childNodes||[]))ie(J)};for(let he of Array.from(y.childNodes))ie(he)},u={...Mt,find(h,y,S={}){let v=b(h);if(!v?.querySelectorAll)return[];let D=a().query(y,v);S.includeRulesTag||(D=D.filter(ae=>!Rs(ae)));let q=[];S.skip&&q.push(S.skip);let Z=S.templateAttr===null?null:S.templateAttr||"cms-template";if(Z&&q.push(`[${Z}]`),q.length){let ae=q.join(", ");D=D.filter(ie=>!ie.closest?.(ae))}return D},parent(h){let y=b(h)?.parentElement;return y?p(y):null},children(h){return Array.from(b(h)?.children||[],p)},text(h,y){if(y===void 0){let D=p(h);return!D?.matches?.(n)&&!D?.querySelector?.(n)?Mt.text(D):(b(h)?.textContent||"").trim()}let S=p(h);if(!S?.matches?.(n)&&!S?.querySelector?.(n)&&!l){Mt.text(S,y);return}let v=a().cloneOf(S);v?m(S,v,"textContent",y):Mt.text(S,y)},attr(h,y,S){let v=p(h);if(S===void 0)return Mt.attr(v,y);Mt.attr(v,y,S);let D=l?.cloneOf(v);D&&(Mt.attr(D,y,S),lo(v,{capability:"data",exclude:t.exclude||null}).root===null&&(D.remove(),l.liveToClone.delete(v),l.cloneToLive.delete(D)))},removeAttr(h,y){let S=p(h);Mt.removeAttr(S,y);let v=l?.cloneOf(S);v&&Mt.removeAttr(v,y)},prop(h,y,S){let v=p(h);if(S===void 0)return y==="innerHTML"||y==="outerHTML"||y==="textContent"||y==="innerText"?Mt.prop(b(v),y):Mt.prop(v,y);let D=y==="innerHTML"||y==="textContent"||y==="innerText",q=D?a().cloneOf(v):l?.cloneOf(v);q&&D?m(v,q,y,S):(Mt.prop(v,y,S),q&&Mt.prop(q,y,S))},clone(h){let y=b(h);return y===h?Mt.clone(h):c.importNode(y,!0)},insertAt(h,y,S){let v=p(h),q=u.children(v)[S]||(()=>{for(let ie=v.children.length-1;ie>=0;ie--){let he=v.children[ie];if(a().cloneOf(he))return he.nextElementSibling}return v.firstElementChild})(),Z=p(y);v.insertBefore(Z,q||null);let ae=a().cloneOf(v);if(ae){let ie=a().cloneOf(Z);ie||(ie=c.importNode(Z,!0),g(Z,ie));let he=Array.from(ae.children);ae.insertBefore(ie,he[S]||null)}},remove(h){let y=p(h),S=a().cloneOf(y);Mt.remove(y),S&&Mt.remove(S)},replaceWith(h,y){let S=p(h),v=a().cloneOf(S),D=Mt.replaceWith(S,y);if(v){let q=lo(D,{capability:"data",exclude:t.exclude||null});if(!q.root)v.remove();else{v.replaceWith(q.root);let Z=ae=>{let ie=q.original(ae);ie&&(l.liveToClone.set(ie,ae),l.cloneToLive.set(ae,ie));for(let he of Array.from(ae.childNodes||[]))Z(he)};Z(q.root)}}return D}};return u}var Qt=Mt;function Ar(e){try{return JSON.parse(e)}catch(t){throw new Wn(`Invalid strict JSON: ${t.message}`,t)}}function On(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let s=[],c=0;for(;c<r.length;){let l=r[c];if(/\s/.test(l)){c++;continue}if("{}".includes(l)){s.push({type:l,value:l}),c++;continue}if(l==="["){let g=!1,m=c+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(g=!0),!g){s.push({type:l,value:l}),c++;continue}}if(l==="]"){s.push({type:l,value:l}),c++;continue}if(l===":"){s.push({type:t.COLON,value:l}),c++;continue}if(l===","){s.push({type:t.COMMA,value:l}),c++;continue}if(l==='"'||l==="'"){let g=l,m=c+1;for(;m<r.length&&r[m]!==g;)r[m]==="\\"&&m++,m++;s.push({type:t.STRING,value:r.substring(c+1,m),quoted:!0,sourceQuote:g}),c=m+1;continue}let a=c,b;for(;a<r.length&&!/[{},]/.test(r[a]);)if(r[a]===":"){let g=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let u of g){let h=u.substring(1);if(r.substring(a+1,a+1+h.length)===h){m=!0,a+=h.length;break}}if(!m)break}else if(r[a]==="["){for(a++;a<r.length&&r[a]!=="]";){if(r[a]==='"'||r[a]==="'"){let g=r[a];for(a++;a<r.length&&r[a]!==g;)r[a]==="\\"&&a++,a++}a++}a<r.length&&r[a]==="]"&&a++}else a++;b=r.substring(c,a);let p=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(b)?p=t.NUMBER:b==="true"||b==="false"||b==="null"?p=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(b)&&(p=t.SELECTOR),s.push({type:p,value:b,quoted:!1}),c=a}return s}function o(r){let s="";for(let c=0;c<r.length;c++){let l=r[c];if("{}".includes(l.type)||"[]".includes(l.type)){s+=l.value;continue}if(l.type===t.COLON){s+=l.value;continue}if(l.type===t.COMMA){let a=r[c+1];if(a&&(a.type==="}"||a.type==="]"))continue;s+=l.value;continue}if(l.type===t.STRING&&l.quoted){let a=l.value;l.sourceQuote==="'"&&(a=a.replace(/\\'/g,"'"),a=a.replace(/(\\*)"/g,(b,p)=>p.length%2===0?p+'\\"':b)),s+=`"${a}"`;continue}if(l.type===t.NUMBER||l.type===t.BOOLEAN){s+=l.value;continue}if(l.type===t.SELECTOR||l.type===t.IDENTIFIER){s+=`"${l.value}"`;continue}s+=`"${l.value}"`}return s}try{let r=n(e),s=o(r);return JSON.parse(s)}catch(r){throw new Wn("Invalid extraction rules syntax: "+r.message,r)}}var xr="1",Ps=/^[a-zA-Z0-9_-]+$/;function Fn(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Ps.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Ps})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=r[0],c=e.attr(s,"data-rules-version");if(c!==xr)throw new Tn(c);return{rules:On(e.text(s)),tagNode:s}}var Ic="script[data-rules-name]";function Hs(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function ao(e,t){let n=e.find(t,Ic,{includeRulesTag:!0}),o=new Set,r=[];for(let s of n){let c=Hs(e.attr(s,"data-rules-name"));if(!c)continue;if(o.has(c)){console.warn(`hyper-html-api: duplicate rules tag name "${c}"; using the first.`);continue}let l=e.attr(s,"data-rules-version");if(l!==xr)throw new Tn(l);o.add(c),r.push({name:c,rules:On(e.text(s))})}return r}function Ho(e,t){let n={};for(let{name:o,rules:r}of ao(e,t))n[o]=ln(e,t,r);return n}function Tr(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Ho(Qt,t),version:cn(n,"hyper-version")}}var Vn=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},fo=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},bn=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},uo=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var Ds="text/hyper-upgrade";function Sr(e,t){let n=e.find(t,`script[type="${Ds}"]`);if(n.length===0)return null;if(n.length>1)throw new uo(n.length);return e.text(n[0])||null}var Ec=new Function("url","return import(url)");async function Nr(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Ec(n)}catch(r){throw new bn(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new bn("transform must `export default` a function");return o.default}function _s(e,t,n,o){let r=e.length,s=t.length,c=new Array(r).fill(-1);if(o){let S=new Set;for(let v=0;v<r;v++){let D=o[v];!(D>=0&&D<s)||S.has(D)||(c[v]=D,S.add(D))}}if(r===0||s===0)return c;let l=e.map(S=>js(S,n)),a=t.map(S=>js(S,n)),b=new Array(s).fill(!1);for(let S of c)S>=0&&(b[S]=!0);let p=new Map;a.forEach((S,v)=>{b[v]||p.set(S,p.has(S)?-1:v)});let g=new Map;l.forEach((S,v)=>{c[v]>=0||g.set(S,(g.get(S)||0)+1)}),l.forEach((S,v)=>{if(c[v]>=0||g.get(S)!==1)return;let D=p.get(S);D===void 0||D===-1||b[D]||(c[v]=D,b[D]=!0)});let m=[];for(let S=0;S<r;S++)c[S]<0&&m.push(S);let u=[];for(let S=0;S<s;S++)b[S]||u.push(S);if(m.length===0||u.length===0)return c;let h=r*s+1,y=(S,v)=>Cc(e[S],t[v],n)*h+Math.abs(S-v);for(let[S,v]of Lc(m,u,y))c[S]=v;return c}var Us=e=>typeof e=="object"&&e!==null;function js(e,t){if(!Us(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function Cc(e,t,n){if(!Us(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let s of o){let c=JSON.stringify(e?.[s]),l=JSON.stringify(t?.[s]);c!==l&&r++}return r}function Lc(e,t,n){return e.length<=t.length?Bs(e,t,n,!1):Bs(t,e,(o,r)=>n(r,o),!0)}function Bs(e,t,n,o){let r=e.length,s=t.length,c=[];for(let g=0;g<=r;g++)c.push(new Float64Array(s+1).fill(1/0));let l=[];for(let g=0;g<=r;g++)l.push(new Uint8Array(s+1));for(let g=0;g<=s;g++)c[r][g]=0;for(let g=r-1;g>=0;g--)for(let m=s-1;m>=0;m--){let u=n(e[g],t[m])+c[g+1][m+1],h=c[g][m+1];u<=h?(c[g][m]=u,l[g][m]=1):c[g][m]=h}let a=[],b=0,p=0;for(;b<r&&p<s;)l[b][p]&&(a.push(o?[t[p],e[b]]:[e[b],t[p]]),b++),p++;return a}function Mr(e,t,n,o,r,s,c,l={}){let a=e.find(t,n,l);if(r.length===0){a.forEach(ae=>e.remove(ae)),Or(l,"onRowsApplied",s.path,[]);return}let b=r.length>a.length,p=a[0]||null;if(b&&!p&&(p=Dc(e,t,n,l),!p))throw new so(s.path);let g=a.map(ae=>Hc(e,ae,o,l)),m=null;if(b&&p){m=e.clone(p),l.templateAttr&&e.removeAttr(m,l.templateAttr);let ae=e.stripIds(m);ae>0&&console.warn(`[hyper-html-api] stripped ${ae} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let u=_s(r,g,o,Rc(e,a,r,s,l)),h=a[0]||p,y=e.parent(h),S=a.length>0?Ws(e,y,h):0,v=jc(e,a),D=new Set,q=[],Z=r.map((ae,ie)=>{let he=u[ie];if(he>=0)return D.add(he),q.push(!1),a[he];q.push(!0);let K=e.clone(m);return e.stripIds(K),K});a.forEach((ae,ie)=>{D.has(ie)||e.remove(ae)}),v?Z.forEach((ae,ie)=>{let he=S+ie;e.children(y).findIndex(ye=>e.sameNode(ye,ae))!==he&&e.insertAt(y,ae,he)}):Bc(e,Z,q,y,S),Pc(e,Z,o,r,s,c,l),Or(l,"onRowsApplied",s.path,Z)}function Or(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function Rc(e,t,n,o,r){let s=Or(r,"identifyRows",o.path,n);if(!Array.isArray(s))return null;let c=new Array(n.length).fill(-1),l=new Set;for(let a=0;a<n.length;a++)if(s[a]){for(let b=0;b<t.length;b++)if(!(l.has(b)||!e.sameNode(t[b],s[a]))){c[a]=b,l.add(b);break}}return c}function Pc(e,t,n,o,r,s,c){t.forEach((l,a)=>{if(n===null){let b=o[a],p=b==null?"":String(b);e.text(l)!==p&&e.text(l,p)}else{let b=s(e,l,n,o[a],{depth:r.depth+1,path:[...r.path,a]},c);b&&b!==l&&(t[a]=b)}})}function Hc(e,t,n,o){return n===null?e.text(t):ln(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Ws(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Dc(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let s=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of s)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}function jc(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let s of t){let c=o.findIndex(l=>e.sameNode(l,s));if(c===-1)return!1;r.push(c)}return r.sort((s,c)=>s-c),r[r.length-1]-r[0]===r.length-1}function Bc(e,t,n,o,r){let s=null,c=r;for(let l=0;l<t.length;l++){if(!n[l]){s=t[l];continue}let a=s?e.parent(s):o;if(!a)continue;let b=s?Ws(e,a,s)+1:c++;e.insertAt(a,t[l],b),s=t[l]}}var $s=new Set(["checked","selected","disabled","readOnly","paused"]);function yn(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(vr(n,o,[],s),s.length)throw new ro(s);Do(e,t,n,o,{depth:0,path:[]},r)}function Do(e,t,n,o,r,s={}){if(r.depth>$n)throw new Sn(r.path);if(o===void 0)return t;if(typeof n=="string")return _c(e,t,n,o,r,s);if(Array.isArray(n)){let[c,l]=n;return Mr(e,t,c,l,o,r,Do,s),t}if(typeof n=="object"&&n!==null){for(let[c,l]of Object.entries(n)){let a=Do(e,t,l,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},s);a&&a!==t&&(t=a)}return t}return t}function _c(e,t,n,o,r,s){if(n.endsWith("[]")){let a=n.slice(0,-2);return Mr(e,t,a,null,o,r,Do,s),t}if(n.startsWith("@"))return Vs(e,t,n.slice(1),o);let c=dn(n);if(c!==-1){let a=n.slice(0,c),b=n.slice(c+1),p=a?e.find(t,a,s):[t];return p.length===0||Vs(e,p[0],b,o),t}if(n===".")return Fs(e,t,o),t;let l=e.find(t,n,s);return l.length===0||Fs(e,l[0],o),t}function Fs(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Vs(e,t,n,o){if(gr.has(n)){let s=e.prop(t,n);if(s===o||s!=null&&o!=null&&String(s)===String(o))return t;throw new io(n)}if(n==="outerHTML"){let s=o==null?"":String(o);return e.replaceWith(t,s)}if(Ss.has(n)){let s=Uc(n,o);return e.prop(t,n)!==s&&e.prop(t,n,s),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function Uc(e,t){return t==null?$s.has(e)?!1:"":$s.has(e)?t==="false"?!1:!!t:t}function vr(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,s)=>{typeof r=="object"&&r!==null&&o.push({path:po([...n,s]),expected:"scalar",got:ho(r)})}):o.push({path:po(n),expected:"array",got:ho(t)});return}t!==null&&typeof t=="object"&&o.push({path:po(n),expected:"scalar",got:ho(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:po(n),expected:"array",got:ho(t)});return}let r=e[1];t.forEach((s,c)=>vr(r,s,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:po(n),expected:"object",got:ho(t)});return}for(let[r,s]of Object.entries(e))vr(s,t[r],[...n,r],o)}}}function ho(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function po(e){return e.join(".")}function mo(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Ir(t,e,n);return Er(t,e,n),{data:o,summary:n}}function Ir(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>Ir(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,s]of Object.entries(e)){let c=Ir(s,t?.[r],n);c!==void 0&&(o[r]=c)}return o}}function Er(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?Er(e[r],t[r],n):n.discarded+=Mn(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Er(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=Mn(t))}}function Mn(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Mn(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Mn(n),0):1}function Cr(e,t,n){let o=ao(e,t),r={carriedOver:0,discarded:0,listItems:0},s={},c=new Set;for(let{name:l,rules:a}of o){if(c.add(l),!Object.prototype.hasOwnProperty.call(n,l)){s[l]={carriedOver:0,discarded:0,listItems:0};continue}let{data:b,summary:p}=mo(n[l],a);yn(e,t,a,b),s[l]=p,r.carriedOver+=p.carriedOver,r.discarded+=p.discarded,r.listItems+=p.listItems}for(let l of Object.keys(n))c.has(l)||(r.discarded+=Mn(n[l]));return{totals:r,byName:s,rulesTagCount:o.length}}async function Lr({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:s}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),s=s||(v=>fetch(v)),!o)throw new Error("upgrade.run requires a document context");if(e=e||cn(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let c=new URL(e,r?r.href:void 0);n=n!==void 0?n:cn(o,"hyper-version"),t=t||Ho(Qt,o);let l;try{l=await s(c.href)}catch(v){throw new Vn(c.href,v)}if(!l.ok)throw new Vn(c.href,new Error(`HTTP ${l.status}`));let a=await l.text(),b=new DOMParser().parseFromString(a,"text/html"),p=cn(b,"hyper-version"),g=t,m=!1,u=Sr(Qt,b);if(u){let D=await(await Nr(u))(g,{fromVersion:n,toVersion:p});if(!D||typeof D!="object"||Array.isArray(D))throw new bn("transform must return a plain object map of { rulesName: data }");g=D,m=!0}let{totals:h,byName:y,rulesTagCount:S}=Cr(Qt,b,g);if(S===0&&Object.keys(g).length>0)throw new fo(c.href);return{html:Wc(b),fromVersion:n,toVersion:p,summary:{transformApplied:m,totals:h,byName:y}}}function Wc(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
5
|
+
`+e.documentElement.outerHTML}var Fc=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...vs],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function Rr(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return Fn(e,o,n)}return null}var go={extract:(e,t,n={})=>ln(Nn(e,n),e,t,n),apply:(e,t,n,o={})=>yn(Nn(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>Fn(Qt,e,t),findRules:(e,t)=>Rr(Qt,e,t),bind:(e,t,n={})=>{let o=Rr(Qt,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>ln(Nn(e,n),e,o.rules,n),set:r=>yn(Nn(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:Ar,parseRelaxed:On,ruleAttrIndex:dn,splitRule:Cn,errors:Po,DOM_PROPERTIES:Lo},Pr=e=>!!e&&typeof e.nodeType=="number";function zs(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=Qt.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return Fn(Qt,t).rules}function Hr(e,t){let n=Pr(e)?e:document,o=Pr(e)?t:e;return o===void 0?ln(Nn(n),n,zs(n)):go.bind(n,o).get()}function Dr(e,t,n){if(!Pr(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?yn(Nn(e),e,zs(e),t):go.bind(e,n).set(t),e}var qs={buildForm:Uo,bindFormEvents:Wo,scaffold:En,morphForm:dr,path:To},Ks={checkForUpdate:pr,run:Lr,extractAll:Tr,shapeMatch:mo};var zc={engine:go,cms:qs,upgrade:Ks,extractData:Hr,applyData:Dr},qc=zc;return ti(Kc);})();
|