@panphora/clayjs 1.2.0 → 1.3.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.
@@ -1,5 +1,5 @@
1
- var HyperMorph=(()=>{var ke=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var Xe=Object.prototype.hasOwnProperty;var et=(e,n)=>{for(var t in n)ke(e,t,{get:n[t],enumerable:!0})},tt=(e,n,t,p)=>{if(n&&typeof n=="object"||typeof n=="function")for(let u of Qe(n))!Xe.call(e,u)&&u!==t&&ke(e,u,{get:()=>n[u],enumerable:!(p=Ze(n,u))||p.enumerable});return e};var nt=e=>tt(ke({},"__esModule",{value:!0}),e);var Ot={};et(Ot,{HyperMorph:()=>fe,default:()=>It,defaults:()=>wt,findChangedRoots:()=>Nt,mergeJson:()=>be,mergeScriptText:()=>Ae,morph:()=>Et,parseJsonRelaxed:()=>pe,parseRulesRelaxed:()=>Ne,spliceProtected:()=>Tt});var $e={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 rt(e){let n=5381;for(let t=0;t<e.length;t++)n=(n<<5)+n^e.charCodeAt(t);return Math.abs(n).toString(36)}function st(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let n=e.getAttribute?.("class");return n?n.split(/\s+/).filter(Boolean).sort().join(" "):""}function it(e,n){let t=[];for(let p of e.attributes||[]){let u=p.name;u==="id"||u==="class"||n.excludeAttributePrefixes.some(g=>u.startsWith(g))||n.includeAttributes.includes(u)&&t.push(`${u}=${p.value}`)}return t.sort().join("|")}function ot(e,n){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,n.textHintLength)}function at(e,n){let t=[e.tagName];return n.includeClasses&&t.push(st(e)),t.push(it(e,n)),rt(t.join("|"))}function ut(e){let n=e.tagName,t=1,p=e.previousElementSibling;for(;p;)p.tagName===n&&t++,p=p.previousElementSibling;return t}function ct(e,n){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:n.landmarks.includes(e.tagName)}function lt(e){let n=e.getAttribute?.("id");if(n)return`#${n}`;let t=e.getAttribute?.("role");return t?`@${t}`:e.tagName}function ft(e,n){let t=[],p=e;for(;p&&p.tagName&&t.length<n.maxPathDepth;){let u=`${p.tagName}:${ut(p)}`;if(t.unshift(u),p!==e&&ct(p,n)){t.unshift(lt(p));break}p=p.parentElement}return t}function dt(e,n){let t=0,p=e.length-1,u=n.length-1;for(;p>=0&&u>=0&&e[p]===n[u];)t++,p--,u--;return t}function Q(e,n,t){if(t.has(e))return t.get(e);let p={signature:at(e,n),path:ft(e,n),textHint:ot(e,n)};return t.set(e,p),p}function Pe(e,n,t,p){if(p.has(e))return p.get(e);let u=new Map,g=e.querySelectorAll("*"),y=0;for(let f of g){let S=Q(f,n,t);S.domIndex=y++,!n.shouldIgnore?.(f)&&(u.has(S.signature)||u.set(S.signature,[]),u.get(S.signature).push(f))}return p.set(e,u),u}function ht(e,n,t){t.delete(e),n.delete(e);let p=e.querySelectorAll("*");for(let u of p)n.delete(u)}function Ee(e,n,t,p,u){let g=Q(e,t,p),y=Q(n,t,p),f=t.weights,S={},j=0;if(g.signature!==y.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};j+=f.signature,S.signature=f.signature;let R=dt(g.path,y.path)*f.pathSegment;j+=R,S.path=R;let O=!0;if(g.textHint&&y.textHint?g.textHint===y.textHint?(j+=f.textMatch,S.text=f.textMatch):(j-=f.textMismatch,S.text=-f.textMismatch,O=!1):g.textHint!==y.textHint&&(j-=f.textMismatch,S.text=-f.textMismatch,O=!1),u.candidateCount===1&&O&&(j+=f.uniqueCandidate,S.unique=f.uniqueCandidate),typeof g.domIndex=="number"&&typeof y.domIndex=="number"){let E=Math.abs(g.domIndex-y.domIndex),T=Math.min(E*f.positionPenalty,f.maxDriftPenalty);j-=T,S.drift=-T}return{score:j,breakdown:S}}function je(e,n,t,p,u){if(t.excludeIds&&e.getAttribute("id"))return null;let g=Pe(n,t,p,u),y=Q(e,t,p);if(typeof y.domIndex!="number"){let O=0,E=e.previousElementSibling;for(;E;)O++,E=E.previousElementSibling;y.domIndex=O}let f=g.get(y.signature)||[],S=t.excludeIds?f.filter(O=>!O.getAttribute("id")):f;if(S.length===0)return null;let j=null,q=0,R=null;for(let O of S){let{score:E,breakdown:T}=Ee(e,O,t,p,{candidateCount:S.length});E>q&&(q=E,j=O,R=T)}return q<t.minConfidence?null:{element:j,confidence:q,breakdown:R}}function pt(e,n,t,p){let u=[],g=t.weights.signature+t.weights.slotMatch,y={slot:g};function f(R){if(R.children)return R.children;let O=R.childNodes;if(!O)return[];let E=[];for(let T=0;T<O.length;T++)O[T].nodeType===1&&E.push(O[T]);return E}function S(R,O){let E=f(R),T=f(O);if(E.length===T.length)for(let z=0;z<E.length;z++){let J=E[z],U=T[z];if(t.shouldIgnore?.(J)||t.shouldIgnore?.(U)||t.excludeIds&&(J.getAttribute("id")||U.getAttribute("id"))||J.tagName!==U.tagName)continue;let ee=Q(J,t,p).signature,X=Q(U,t,p).signature;ee!==X&&u.push({newEl:J,oldEl:U,score:g,breakdown:y}),S(J,U)}}function j(R,O){for(;;){if(R.tagName===O.tagName)return[R,O];let E=f(R);if(!R.tagName&&E.length===1){R=E[0];continue}let T=f(O);if(T.length===1&&T[0].tagName===R.tagName){O=T[0];continue}return null}}let q=j(e,n);return q&&S(q[0],q[1]),u}function De(e,n,t,p,u){let g=n.querySelectorAll("*"),y=Pe(e,t,p,u),f=0;for(let E of g){let T=Q(E,t,p);T.domIndex=f++}let S=[],j=new Map;function q(E,T,z){let J=new Set;if(E.textHint){let W=j.get(E.signature);if(!W){W=new Map;for(let te of T){let ge=Q(te,t,p).textHint,ie=W.get(ge);ie||(ie=[],W.set(ge,ie)),ie.push(te)}j.set(E.signature,W)}let ne=W.get(E.textHint);if(ne)for(let te=0;te<ne.length&&te<z;te++)J.add(ne[te])}let U=0,ee=T.length;for(;U<ee;){let W=U+ee>>1;Q(T[W],t,p).domIndex<E.domIndex?U=W+1:ee=W}let X=Math.max(0,Math.min(U-(z>>1),T.length-z)),ae=Math.min(X+z,T.length);for(let W=X;W<ae;W++)J.add(T[W]);return[...J]}for(let E of g){if(t.shouldIgnore?.(E)||t.excludeIds&&E.getAttribute("id"))continue;let T=Q(E,t,p),z=y.get(T.signature)||[],J=t.excludeIds?z.filter(X=>!X.getAttribute("id")):z,U=t.maxScoredCandidates,ee=U&&J.length>U?q(T,J,U):J;for(let X of ee){let{score:ae,breakdown:W}=Ee(E,X,t,p,{candidateCount:J.length});ae>=t.minConfidence&&S.push({newEl:E,oldEl:X,score:ae,breakdown:W})}}if(t.weights.slotMatch>0){let E=pt(n,e,t,p);for(let T of E)S.push(T)}S.sort((E,T)=>T.score-E.score);let R=new Map,O=new Set;for(let{newEl:E,oldEl:T}of S)R.has(E)||O.has(T)||(R.set(E,T),O.add(T));return R}function qe(e,n,t,p){let u=Q(e,t,p),g=Q(n,t,p),{score:y,breakdown:f}=Ee(e,n,t,p,{candidateCount:1});return{matches:y>=t.minConfidence,score:y,breakdown:f,newMeta:{signature:u.signature,path:u.path,textHint:u.textHint},oldMeta:{signature:g.signature,path:g.path,textHint:g.textHint}}}function _e(e={}){let n={...$e,...e,weights:{...$e.weights,...e.weights}},t=new WeakMap,p=new WeakMap;return{findMatch:(u,g)=>je(u,g,n,t,p),computeMatches:(u,g)=>De(u,g,n,t,p),explain:(u,g)=>qe(u,g,n,t),invalidate:u=>ht(u,t,p),session:()=>{let u=new WeakMap,g=new WeakMap;return{findMatch:(y,f)=>je(y,f,n,u,g),computeMatches:(y,f)=>De(y,f,n,u,g),explain:(y,f)=>qe(y,f,n,u)}},getConfig:()=>({...n})}}function we(e,n){for(;;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]==="/"&&e[n+1]==="/"){for(;n<e.length&&e[n]!==`
2
- `;)n++;continue}if(e[n]==="/"&&e[n+1]==="*"){let t=e.indexOf("*/",n+2);if(t===-1)return e.length;n=t+2;continue}return n}}function Fe(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(n,t)=>t.length%2===0?t+'\\"':n)}var mt=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,gt=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function pe(e){try{return JSON.parse(e)}catch{return JSON.parse(yt(e))}}function yt(e){let n="",t=0,p=(u,g)=>{throw new Error(`Invalid relaxed JSON: ${u} at position ${g}`)};for(;t<e.length&&(t=we(e,t),!(t>=e.length));){let u=e[t];if("{}[]:".includes(u)){n+=u,t++;continue}if(u===","){let f=we(e,t+1);if(e[f]==="}"||e[f]==="]"){t++;continue}n+=u,t++;continue}if(u==='"'||u==="'"){let f=t+1;for(;f<e.length&&e[f]!==u;)e[f]==="\\"&&f++,f++;f>=e.length&&p("unterminated string",t);let S=e.slice(t+1,f);u==="'"&&(S=Fe(S)),n+='"'+S+'"',t=f+1;continue}let g=t;for(;g<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[g]);)g++;g===t&&p("unexpected character "+JSON.stringify(u),t);let y=e.slice(t,g);if(y==="true"||y==="false"||y==="null"||mt.test(y)){n+=y,t=g;continue}if(gt.test(y)){if(e[we(e,g)]===":"){n+='"'+y+'"',t=g;continue}p("unquoted value "+JSON.stringify(y),t)}p("invalid token "+JSON.stringify(y),t)}return n}function Ne(e){try{return JSON.parse(e)}catch{}let n={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function t(u){let g=[],y=0;for(;y<u.length;){let f=u[y];if(/\s/.test(f)){y++;continue}if("{}".includes(f)){g.push({type:f,value:f}),y++;continue}if(f==="["){let R=!1,O=y+1;for(;O<u.length&&/\s/.test(u[O]);)O++;if(O<u.length&&/[a-zA-Z_]/.test(u[O])&&(R=!0),!R){g.push({type:f,value:f}),y++;continue}}if(f==="]"){g.push({type:f,value:f}),y++;continue}if(f===":"){g.push({type:n.COLON,value:f}),y++;continue}if(f===","){g.push({type:n.COMMA,value:f}),y++;continue}if(f==='"'||f==="'"){let R=f,O=y+1;for(;O<u.length&&u[O]!==R;)u[O]==="\\"&&O++,O++;g.push({type:n.STRING,value:u.substring(y+1,O),quoted:!0,sourceQuote:R}),y=O+1;continue}let S=y,j;for(;S<u.length&&!/[{},]/.test(u[S]);)if(u[S]===":"){let R=[":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"],O=!1;for(let E of R){let T=E.substring(1);if(u.substring(S+1,S+1+T.length)===T){O=!0,S+=T.length;break}}if(!O)break}else if(u[S]==="["){for(S++;S<u.length&&u[S]!=="]";){if(u[S]==='"'||u[S]==="'"){let R=u[S];for(S++;S<u.length&&u[S]!==R;)u[S]==="\\"&&S++,S++}S++}S<u.length&&u[S]==="]"&&S++}else S++;j=u.substring(y,S);let q=n.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(j)?q=n.NUMBER:j==="true"||j==="false"||j==="null"?q=n.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(j)&&(q=n.SELECTOR),g.push({type:q,value:j,quoted:!1}),y=S}return g}function p(u){let g="";for(let y=0;y<u.length;y++){let f=u[y];if("{}".includes(f.type)||"[]".includes(f.type)){g+=f.value;continue}if(f.type===n.COLON){g+=f.value;continue}if(f.type===n.COMMA){let S=u[y+1];if(S&&(S.type==="}"||S.type==="]"))continue;g+=f.value;continue}if(f.type===n.STRING){let S=f.value;f.sourceQuote==="'"&&(S=Fe(S)),g+=`"${S}"`;continue}if(f.type===n.NUMBER||f.type===n.BOOLEAN){g+=f.value;continue}g+=`"${f.value}"`}return g}try{let u=t(e),g=p(u);return JSON.parse(g)}catch(u){throw new Error("Invalid extraction rules syntax: "+u.message)}}var K=Symbol("hyper-morph-json-merge:missing"),Ve=["id","_id","uuid","key","slug","code","name"];function le(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function me(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function bt(e,n,t){Object.defineProperty(e,n,{value:t,enumerable:!0,writable:!0,configurable:!0})}function se(e,n){if(e===n)return!0;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!se(e[t],n[t]))return!1;return!0}if(le(e)&&le(n)){let t=Object.keys(e);if(t.length!==Object.keys(n).length)return!1;for(let p of t)if(!me(n,p)||!se(e[p],n[p]))return!1;return!0}return!1}function Ke(e,n,t,p){return se(n,t)?n:se(n,e)?t:se(t,e)?n:le(n)&&le(t)?At(le(e)?e:{},n,t,p):Array.isArray(n)&&Array.isArray(t)?kt(Array.isArray(e)?e:[],n,t,p):t}function ze(e,n,t,p){return n===K&&t===K?K:n===K?e===K?t:se(t,e)?K:t:t===K?e===K?n:K:Ke(e,n,t,p)}function At(e,n,t,p){let u={},g=new Set([...Object.keys(e),...Object.keys(n),...Object.keys(t)]);for(let y of g){let f=ze(me(e,y)?e[y]:K,me(n,y)?n[y]:K,me(t,y)?t[y]:K,p);f!==K&&bt(u,y,f)}return u}function St(e){return e===null||typeof e!="object"}function ye(e){return typeof e+":"+String(e)}function Mt(e,n){for(let t of n){let p=new Set;for(let u of t){if(!me(u,e))return!1;let g=u[e];if(typeof g!="string"&&typeof g!="number")return!1;let y=ye(g);if(p.has(y))return!1;p.add(y)}}return!0}function vt(e,n,t,p){let u=[e,n,t],g=!0;for(let y of u)for(let f of y)le(f)||(g=!1);if(g){for(let y of p.keyCandidates)if(Mt(y,u))return{kind:"keyed",field:y};return null}for(let y of u){let f=new Set;for(let S of y){if(!St(S))return null;let j=ye(S);if(f.has(j))return null;f.add(j)}}return{kind:"self"}}function kt(e,n,t,p){let u=vt(e,n,t,p);if(!u)return t;let g=u.kind==="self"?ye:E=>ye(E[u.field]),y=E=>{let T=new Map;for(let z of E)T.set(g(z),z);return T},f=y(e),S=y(n),j=y(t),q=new Map,R=new Set([...f.keys(),...S.keys(),...j.keys()]);for(let E of R){let T=ze(f.has(E)?f.get(E):K,S.has(E)?S.get(E):K,j.has(E)?j.get(E):K,p);T!==K&&q.set(E,T)}let O=[];for(let E of t){let T=g(E);q.has(T)&&O.push(T)}for(let E=0;E<n.length;E++){let T=g(n[E]);if(!q.has(T)||O.includes(T))continue;let z=0;for(let J=E-1;J>=0;J--){let U=O.indexOf(g(n[J]));if(U!==-1){z=U+1;break}}O.splice(z,0,T)}return O.map(E=>q.get(E))}function be(e,n,t,p={}){let u=p.keyCandidates?[...p.keyCandidates,...Ve]:Ve;return Ke(e===void 0?K:e,n,t,{keyCandidates:u})}function Ae(e,n,t,p={}){let u=p.parse||pe,g=[],y=(R,O)=>{if(typeof R!="string")return K;try{return u(R)}catch(E){return g.push(`${O} side is not valid JSON (${E.message})`),K}},f=y(n,"local"),S=y(t,"remote");if(f===K)return{text:t,warnings:g};if(S===K)return{text:n,warnings:g};let j=y(e,"base"),q=be(j===K?void 0:j,f,S,p);return se(q,S)?{text:t,warnings:g}:se(q,f)?{text:n,warnings:g}:{text:JSON.stringify(q,null,2),warnings:g}}var fe=(function(){"use strict";let e=()=>{},n='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function t(i){if(!(i instanceof Element))return!1;if(i.matches(n))return!0;if(i.tagName==="LINK"||i.tagName==="SCRIPT"){let v=i.getAttribute("src")||i.getAttribute("href")||"";if(v.startsWith("chrome-extension://")||v.startsWith("moz-extension://")||v.startsWith("safari-web-extension://"))return!0}return!1}function p(i){return i instanceof Element?i.closest(n)?!0:t(i):!1}let u=_e({shouldIgnore:p});function g(i,v,A){if(A){let w=A.identityOf(i);if(w&&!A.disabled.has(w.key))return"hm-merge:"+w.key}if(v!=="smart")return i.outerHTML;let k=i.getAttribute("src"),M=i.getAttribute("type")||"text/javascript";if(k)try{let w=new URL(k,window.location.href);return`ext:${M}:${w.origin}${w.pathname}${w.search}`}catch{return`ext:${M}:${k}`}else{let w=i.textContent.trim(),c=5381;for(let m=0;m<w.length;m++)c=(c<<5)+c^w.charCodeAt(m);return`inline:${M}:${Math.abs(c).toString(36)}`}}let y="http://www.w3.org/1999/xhtml";function f(i){return i instanceof Element&&i.tagName==="SCRIPT"&&i.namespaceURI===y}function S(i){let v=document.createElement("div");v.innerHTML="<script><\/script>";let A=v.firstChild;for(let k of i.attributes)A.setAttribute(k.name,k.value);return A.textContent=i.textContent,A}function j(i){if(f(i))return S(i);if(i instanceof Element)for(let v of i.querySelectorAll("script"))f(v)&&v.replaceWith(S(v));return i}function q(i){let v=(i.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return v==="application/json"||v.endsWith("+json")}let R={match:i=>i.hasAttribute("merge"),identity:i=>i.getAttribute("merge")};function O(i,v,A){if(A.merge===!1)return null;let k=[R,...A.mergeTags||[]],M=new WeakMap,w=o=>{if(M.has(o))return M.get(o);let d=null;if(f(o)&&!o.getAttribute("src")&&!p(o)){let h=o;for(let I=0;I<k.length;I++)if(k[I].match(h)){if(!q(h))console.warn("[hyper-morph] merge ignored: script type is not JSON",h);else{let $=k[I].identity(h);$!=null&&$!==""&&(d={key:I+":"+$,raw:$,recognizer:k[I]})}break}}return M.set(o,d),d},c=new Set,m=o=>{let d=new Map,h=I=>{let $=w(I);$&&(d.has($.key)?(c.add($.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${$.raw}"`)):d.set($.key,I))};f(o)&&h(o);for(let I of o.querySelectorAll("script"))h(I);return d},a=m(i),s=m(v.__hyperMorphRoot||v);if(a.size===0&&s.size===0)return null;let r=null;return{identityOf:w,disabled:c,oldByKey:a,newByKey:s,baseTexts:()=>{if(r)return r;r=new Map;let o=A.mergeBase;if(!o)return r;let d;typeof o=="string"?d=new DOMParser().parseFromString(o,"text/html").documentElement:o instanceof Document?d=o.documentElement:d=o;let h=I=>{let $=w(I);$&&!r.has($.key)&&r.set($.key,I.textContent)};f(d)&&h(d);for(let I of d.querySelectorAll("script"))h(I);return r}}}function E(i,v,A){let k=i.merge;if(!k)return!1;let M=k.identityOf(v);if(!M||k.disabled.has(M.key))return!1;let w=k.identityOf(A);if(!w||w.key!==M.key)return!1;let c=v,m=A,a=m.getAttribute("merge-key")||c.getAttribute("merge-key"),{text:s,warnings:r}=Ae(k.baseTexts().get(M.key),c.textContent,m.textContent,{parse:M.recognizer.parse,keyCandidates:a?a.split(/[\s,]+/).filter(Boolean):void 0});for(let l of r)console.warn(`[hyper-morph] merge "${M.raw}": ${l}`);return c.textContent!==s&&(c.textContent=s),!0}let T={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:i=>i.getAttribute("im-preserve")==="true",shouldReAppend:i=>i.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:i=>i.getAttribute("im-preserve")==="true",shouldReAppend:i=>i.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},z={computeMatches(i,v){let{computeMatches:A}=u.session();return A(i,v)}};function J(i,v,A={}){i=We(i);let k=Te(v),M=Ue(i,k,A),w=M.scripts.handle?new Set(Array.from(i.querySelectorAll("script")).map(s=>g(s,M.scripts.matchMode,M.merge))):null,c=X(M),m=te(M,i,k,s=>s.morphStyle==="innerHTML"?(W(s,i,k),Array.from(i.childNodes)):ee(s,i,k)),a=s=>{c&&ae(M,c),U(M);let r=w?Je(s,w,M):[];return r.length>0?Promise.all(r).then(()=>s):s};return m instanceof Promise?m.then(a):a(m)}function U(i){for(let v of Array.from(i.pantry.childNodes))i.callbacks.beforeNodeRemoved(v)!==!1&&i.callbacks.afterNodeRemoved(v);i.pantry.remove()}function ee(i,v,A){let k=Te(v);return W(i,k,A,v,v.nextSibling),Array.from(k.childNodes)}function X(i){if(!i.config.restoreFocus)return null;let v=document.activeElement;if(!(v instanceof HTMLInputElement||v instanceof HTMLTextAreaElement))return null;let{id:A,selectionStart:k,selectionEnd:M}=v;return{element:v,id:A,selectionStart:k,selectionEnd:M}}function ae(i,v){let A=v.element;if(v.id&&v.id!==document.activeElement?.getAttribute("id")&&(A=i.target.querySelector(`[id="${CSS.escape(v.id)}"]`),A?.focus()),A&&!A.selectionEnd&&v.selectionEnd!=null)try{A.setSelectionRange(v.selectionStart,v.selectionEnd)}catch{}}let W=(function(){function i(s,r,l,o=null,d=null){r instanceof HTMLTemplateElement&&l instanceof HTMLTemplateElement&&(r=r.content,l=l.content),o||=r.firstChild;for(let h of l.childNodes){if(t(h))continue;if(o&&o!=d){let $=A(s,h,o,d);if($){$!==o&&M(s,o,$),ne($,h,s),o=$.nextSibling;continue}}if(h instanceof Element){let $=h.getAttribute("id");if(s.persistentIds.has($)){let b=w(r,$,o,s);ne(b,h,s),o=b.nextSibling;continue}if(!s.idMap.has(h)){let b=s.hyperMatches.get(h);if(b&&!s.idMap.has(b)&&!a(b,r)){m(r,b,o),ne(b,h,s),o=b.nextSibling;continue}}}let I=v(r,h,o,s);I&&(o=I.nextSibling)}for(;o&&o!=d;){let h=o;o=o.nextSibling,t(h)||k(s,h)}}function v(s,r,l,o){if(o.callbacks.beforeNodeAdded(r)===!1)return null;if(o.idMap.has(r)){let d=r,h=document.createElementNS(d.namespaceURI,d.localName);return s.insertBefore(h,l),ne(h,r,o),o.callbacks.afterNodeAdded(h),h}else{let d=j(document.importNode(r,!0));return s.insertBefore(d,l),o.callbacks.afterNodeAdded(d),d}}let A=(function(){function s(o,d,h,I){let $=d instanceof Element&&!o.idMap.has(d)?o.hyperMatches.get(d):null,b=null,N=d.nextSibling,P=0,H=h;for(;H&&H!=I;){if(t(H)){H=H.nextSibling;continue}if(l(H,d)){if(r(o,H,d)||H===$&&!o.idMap.has(H))return H;if(b===null){let _=H instanceof Element&&o.hyperMatchedOldElements.has(H);!o.idMap.has(H)&&!_&&(b=H)}}if(b===null&&N&&l(H,N)&&(P++,N=N.nextSibling,P>=2&&(b=void 0)),o.activeElementAndParents.includes(H))break;H=H.nextSibling}return b||null}function r(o,d,h){let I=o.idMap.get(d),$=o.idMap.get(h);if(!$||!I)return!1;for(let b of I)if($.has(b))return!0;return!1}function l(o,d){let h=o,I=d;return h.nodeType===I.nodeType&&h.tagName===I.tagName&&(!h.getAttribute?.("id")||h.getAttribute?.("id")===I.getAttribute?.("id"))}return s})();function k(s,r){let l=r instanceof Element&&s.hyperMatchedOldElements.has(r)&&!s.idMap.has(r);if(s.idMap.has(r)||l)m(s.pantry,r,null);else{if(s.callbacks.beforeNodeRemoved(r)===!1)return;r.parentNode?.removeChild(r),s.callbacks.afterNodeRemoved(r)}}function M(s,r,l){let o=r;for(;o&&o!==l;){let d=o;o=o.nextSibling,t(d)||k(s,d)}return o}function w(s,r,l,o){let d=o.target.getAttribute?.("id")===r&&o.target||o.target.querySelector(`[id="${CSS.escape(r)}"]`)||o.pantry.querySelector(`[id="${CSS.escape(r)}"]`);return c(d,o),m(s,d,l),d}function c(s,r){let l=s.getAttribute("id");for(;s=s.parentNode;){let o=r.idMap.get(s);o&&(o.delete(l),o.size||r.idMap.delete(s))}}function m(s,r,l){if(s.moveBefore)try{s.moveBefore(r,l)}catch{s.insertBefore(r,l)}else s.insertBefore(r,l)}function a(s,r){let l=r instanceof Element?r:r.realParentNode;return!!l&&s.contains(l)}return i})(),ne=(function(){function i(c,m,a){return a.ignoreActive&&c===document.activeElement?null:(a.callbacks.beforeNodeMorphed(c,m)===!1||(c instanceof HTMLHeadElement&&a.head.ignore||(c instanceof HTMLHeadElement&&a.head.style!=="morph"?ie(c,m,a):(v(c,m,a),E(a,c,m)||w(c,a)||W(a,c,m))),a.callbacks.afterNodeMorphed(c,m)),c)}function v(c,m,a){let s=m.nodeType;if(s===1){let r=c,l=m,o=r.attributes,d=l.attributes;for(let h of d)M(h.name,r,"update",a)||r.getAttribute(h.name)!==h.value&&r.setAttribute(h.name,h.value);for(let h=o.length-1;0<=h;h--){let I=o[h];if(I&&!l.hasAttribute(I.name)){if(M(I.name,r,"remove",a))continue;r.removeAttribute(I.name)}}w(r,a)||A(r,l,a)}(s===8||s===3)&&c.nodeValue!==m.nodeValue&&(c.nodeValue=m.nodeValue)}function A(c,m,a){if(c instanceof HTMLInputElement&&m instanceof HTMLInputElement&&m.type!=="file"){let s=m.value,r=c.value;k(c,m,"checked",a),k(c,m,"disabled",a),a.formStateSync==="property"&&c.indeterminate!==m.indeterminate&&(c.indeterminate=m.indeterminate),a.formStateSync==="property"?r!==s&&(M("value",c,"update",a)||(c.value=s)):m.hasAttribute("value")?r!==s&&(M("value",c,"update",a)||(c.setAttribute("value",s),c.value=s)):M("value",c,"remove",a)||(c.value="",c.removeAttribute("value"))}else if(c instanceof HTMLOptionElement&&m instanceof HTMLOptionElement)k(c,m,"selected",a);else if(c instanceof HTMLTextAreaElement&&m instanceof HTMLTextAreaElement){let s=m.value,r=c.value;if(M("value",c,"update",a)||(s!==r&&(c.value=s),a.formStateSync==="property"))return;c.firstChild&&c.firstChild.nodeValue!==s&&(c.firstChild.nodeValue=s)}}function k(c,m,a,s){let r=m[a],l=c[a];if(r!==l){let o=M(a,c,"update",s);if(o||(c[a]=m[a]),s.formStateSync==="property")return;r?o||c.setAttribute(a,""):M(a,c,"remove",s)||c.removeAttribute(a)}}function M(c,m,a,s){return c==="value"&&s.ignoreActiveValue&&m===document.activeElement?!0:s.callbacks.beforeAttributeUpdated(c,m,a)===!1}function w(c,m){return!!m.ignoreActiveValue&&c===document.activeElement&&c!==document.body}return i})();function te(i,v,A,k){if(i.head.block){let M=v.querySelector("head"),w=A.querySelector("head");if(M&&w){let c=ie(M,w,i);return Promise.all(c).then(()=>(i.head.block=!1,i.head.ignore=!0,k(i)))}}return k(i)}function ge(i){return i.tagName==="SCRIPT"?!!i.getAttribute("src"):i.tagName==="LINK"?(i.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!i.getAttribute("href"):!1}function ie(i,v,A){let k=[],M=[],w=[],c=[],m=A.scripts.matchMode,a=l=>{if(l.tagName==="SCRIPT")return g(l,m,A.merge);if(l.tagName==="LINK"&&m==="smart"){let o=l.getAttribute("href");if(o)try{let d=new URL(o,window.location.href);return`link:${l.getAttribute("rel")||""}:${d.origin}${d.pathname}${d.search}`}catch{}}return l.outerHTML},s=new Map;for(let l of v.children){if(t(l))continue;let o=a(l),d=s.get(o);d||(d=[],s.set(o,d)),d.push(l)}for(let l of i.children){let o=a(l),d=s.get(o),h=!!(d&&d.length),I=A.head.shouldReAppend(l),$=A.head.shouldPreserve(l);if(h||$)if(I)M.push(l);else{if(d&&d.length){let b=d.pop();d.length||s.delete(o),E(A,l,b)}w.push(l)}else A.head.style==="append"?I&&(M.push(l),c.push(l)):A.head.shouldRemove(l)!==!1&&!t(l)&&M.push(l)}for(let l of s.values())c.push(...l);let r=[];for(let l of c){let o=document.createRange().createContextualFragment(l.outerHTML).firstChild;if(A.callbacks.beforeNodeAdded(o)!==!1){if(o instanceof Element&&ge(o)){let d,h=new Promise(function(I){d=I});o.addEventListener("load",function(){d()}),o.addEventListener("error",function(){d()}),r.push(h)}i.appendChild(o),A.callbacks.afterNodeAdded(o),k.push(o)}}for(let l of M)A.callbacks.beforeNodeRemoved(l)!==!1&&(i.removeChild(l),A.callbacks.afterNodeRemoved(l));return A.head.afterHeadMorphed(i,{added:k,kept:w,removed:M}),r}function Je(i,v,A){if(!A.scripts.handle)return[];let k=[],M=[],w=[],c=[],m=A.scripts.matchMode,a=[];for(let r of i)if(r instanceof Element){f(r)&&a.push(r);for(let l of r.querySelectorAll("script"))f(l)&&a.push(l)}for(let r of a){if(r.closest("head")||p(r))continue;let l=g(r,m,A.merge),o=v.has(l),d=A.scripts.shouldPreserve(r),h=A.scripts.shouldReAppend(r);o||d?h?(M.push(r),c.push(r)):w.push(r):c.push(r)}let s=[];for(let r of c){if(A.callbacks.beforeNodeAdded(r)===!1)continue;let l=document.createElement("script");for(let o of r.attributes)l.setAttribute(o.name,o.value);if(l.textContent=r.textContent,l.src){let o,d=new Promise(function(h){o=h});l.addEventListener("load",function(){o()}),l.addEventListener("error",function(){o()}),s.push(d)}r.replaceWith(l),A.callbacks.afterNodeAdded(l),k.push(l)}return A.scripts.afterScriptsHandled(A.target,{added:k,kept:w,removed:M}),s}let Ue=(function(){function i(a,s,r){let{persistentIds:l,idMap:o}=c(a,s),d=z.computeMatches(a,s);if(typeof r.key=="function"){let N=new Map,P=new Set,H=C=>{let x=r.key(C);x!=null&&(N.has(x)?P.add(x):N.set(x,C))};a instanceof Element&&H(a);for(let C of a.querySelectorAll("*"))H(C);for(let C of P)N.delete(C);let _=new Map;for(let[C,x]of d)_.set(x,C);let Z=s.__hyperMorphRoot||s,Y=new Map,V=new Set,L=C=>{let x=r.key(C);x!=null&&(Y.has(x)?V.add(x):Y.set(x,C))};Z instanceof Element&&L(Z);for(let C of Z.querySelectorAll("*"))L(C);for(let C of V)Y.delete(C);for(let[C,x]of Y){let D=N.get(C);if(!D||D.tagName!==x.tagName)continue;let F=_.get(D);F&&F!==x&&d.delete(F);let oe=d.get(x);oe&&oe!==D&&_.delete(oe),d.set(x,D),_.set(D,x)}}let h=v(r),I=O(a,s,h.scripts);if(I){let N=new Map;for(let[P,H]of d)N.set(H,P);for(let[P,H]of I.newByKey){if(I.disabled.has(P))continue;let _=I.oldByKey.get(P);if(!_)continue;let Z=N.get(_);Z&&Z!==H&&d.delete(Z);let Y=d.get(H);Y&&Y!==_&&N.delete(Y),d.set(H,_),N.set(_,H)}}let $=new Set;for(let N of d.values())$.add(N);let b=h.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(b))throw new Error(`Do not understand how to morph style ${b}`);return{target:a,newContent:s,config:h,morphStyle:b,ignoreActive:h.ignoreActive,ignoreActiveValue:h.ignoreActiveValue,restoreFocus:h.restoreFocus,formStateSync:h.formStateSync||"attribute",idMap:o,persistentIds:l,hyperMatches:d,hyperMatchedOldElements:$,merge:I,pantry:A(),activeElementAndParents:k(a),callbacks:h.callbacks,head:h.head,scripts:h.scripts}}function v(a){let s=Object.assign({},T);return Object.assign(s,a),s.callbacks=Object.assign({},T.callbacks,a.callbacks),s.head=Object.assign({},T.head,a.head),s.scripts=Object.assign({},T.scripts,a.scripts),s}function A(){let a=document.createElement("div");return a.hidden=!0,document.body.insertAdjacentElement("afterend",a),a}function k(a){let s=[],r=document.activeElement;if(r?.tagName!=="BODY"&&a.contains(r))for(;r&&(s.push(r),r!==a);)r=r.parentElement;return s}function M(a){let s=Array.from(a.querySelectorAll("[id]"));return a.getAttribute?.("id")&&s.push(a),s}function w(a,s,r,l){for(let o of l){let d=o.getAttribute("id");if(s.has(d)){let h=o;for(;h;){let I=a.get(h);if(I==null&&(I=new Set,a.set(h,I)),I.add(d),h===r)break;h=h.parentElement}}}}function c(a,s){let r=M(a),l=M(s),o=m(r,l),d=new Map;w(d,o,a,r);let h=s.__hyperMorphRoot||s;return w(d,o,h,l),{persistentIds:o,idMap:d}}function m(a,s){let r=new Set,l=new Map;for(let d of a){let h=d.getAttribute("id");l.has(h)?r.add(h):l.set(h,d.tagName)}let o=new Set;for(let d of s){let h=d.getAttribute("id");o.has(h)?r.add(h):l.get(h)===d.tagName&&o.add(h)}for(let d of r)o.delete(d);return o}return i})(),{normalizeElement:We,normalizeParent:Te}=(function(){let i=new WeakSet;function v(c){return c instanceof Document?c.documentElement:c}function A(c){if(c==null)return document.createElement("div");if(typeof c=="string")return A(w(c));if(i.has(c))return c;if(c instanceof Node){if(c.parentNode)return new k(c);{let m=document.createElement("div");return m.append(c),m}}else{let m=document.createElement("div");for(let a of[...c])m.append(a);return m}}class k{constructor(m){this.originalNode=m,this.realParentNode=m.parentNode,this.previousSibling=m.previousSibling,this.nextSibling=m.nextSibling}get childNodes(){let m=[],a=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;a&&a!=this.nextSibling;)m.push(a),a=a.nextSibling;return m}querySelectorAll(m){return this.childNodes.reduce((a,s)=>{if(s instanceof Element){s.matches(m)&&a.push(s);let r=s.querySelectorAll(m);for(let l=0;l<r.length;l++)a.push(r[l])}return a},[])}insertBefore(m,a){return this.realParentNode.insertBefore(m,a)}moveBefore(m,a){return this.realParentNode.moveBefore(m,a)}get __hyperMorphRoot(){return this.originalNode}}function M(c){let m=l=>`<${l}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,a=c.replace(/<!--[\s\S]*?-->/g,"");for(let l of["script","style","textarea","title"])a=a.replace(new RegExp(`${m(l)}[\\s\\S]*?</${l}\\s*>`,"gi"),"");let s=new RegExp(`${m("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),r;do r=a,a=a.replace(s,"");while(a!==r);return a}function w(c){let m=new DOMParser,a=M(c);if(a.match(/<\/html>/)||a.match(/<\/head>/)||a.match(/<\/body>/)){let s=m.parseFromString(c,"text/html");if(a.match(/<\/html>/))return i.add(s),s;{let r=s.firstChild;return r&&i.add(r),r}}else{let r=m.parseFromString("<body><template>"+c+"</template></body>","text/html").body.querySelector("template").content;return i.add(r),r}}return{normalizeElement:v,normalizeParent:A}})(),Ie=Symbol("hyper-morph-duplicate-key"),Oe=[i=>i.getAttribute("data-id"),i=>i.getAttribute("id")];function de(i,v){return v.map(A=>{let k=new Map;for(let M of i){if(M.nodeType!==1)continue;let w=A(M);w==null||w===""||k.set(w,k.has(w)?Ie:M)}return k})}function xe(i,v,A,k){for(let M=0;M<k.length;M++){let w=k[M](i);if(w==null||w===""||v[M].get(w)!==i)continue;let c=A[M].get(w);if(!(!c||c===Ie)&&c.tagName===i.tagName)return c}return null}function ue(i,v,A){for(let k=0;k<A.length;k++){let M=A[k](i);if(!(M==null||M==="")&&v[k].get(M)===i)return!0}return!1}function Ge(i,v,A={}){let k=A.skip||(()=>!1),M=A.ignoreAttr||(()=>!1),w=A.tiers&&A.tiers.length?A.tiers:Oe,c=null;function m(){return c||(c=de([i,...i.querySelectorAll("*")],w)),c}let a=null;function s(){return a||(a=de([v,...v.querySelectorAll("*")],w)),a}function r(L){return!L.parentElement||!L.parentElement.parentElement}function l(L,C,x){return r(L)||ue(L,m(),w)?(x.push({type:"subtree",el:L,base:C}),!1):!0}function o(L,C){let x=[];for(let D of L.attributes)M(L,D.name)||C.getAttribute(D.name)!==D.value&&x.push(D.name);for(let D of C.attributes)M(L,D.name)||L.hasAttribute(D.name)||x.push(D.name);return x}function d(L){let C=[],x=null,D=()=>{x!==null&&(C.push({nodeType:3,nodeValue:x}),x=null)};for(let F of L.childNodes){if(F.nodeType===3){x=(x===null?"":x)+F.nodeValue;continue}F.nodeType===1&&k(F)||(D(),(F.nodeType===1||F.nodeType===8)&&C.push(F))}return D(),C}function h(L,C){if(L.nodeType!==C.nodeType)return!1;if(L.nodeType!==1)return!0;if(L.tagName!==C.tagName)return!1;for(let x of w){let D=x(L),F=x(C);if(D!=null&&D!==""&&F!=null&&F!==""&&D!==F)return!1}return!0}function I(L){let C="";for(let x of L)x.nodeType===3&&x.nodeValue.trim()!==""?C+="\0"+x.nodeValue:x.nodeType===8&&(C+=""+x.nodeValue);return C}function $(L,C,x){let D=d(L),F=d(C);if(D.length===F.length){let B=!0;for(let G=0;G<D.length;G++)if(!h(D[G],F[G])){B=!1;break}if(B){for(let G=0;G<D.length;G++){let ce=D[G];if(ce.nodeType===1){if(b(ce,F[G],x))return!0}else if(ce.nodeValue!==F[G].nodeValue)return!0}return!1}}let oe=D.filter(B=>B.nodeType===1),Se=F.filter(B=>B.nodeType===1);if(I(D)!==I(F))return!0;let Le=de(oe,w),Ce=de(Se,w),Me=[],ve=new Set,He=[];for(let B of oe){let G=xe(B,Le,Ce,w);G&&!ve.has(G)?(Me.push([B,G]),ve.add(G)):He.push(B)}let re=[];for(let B of He)ue(B,Le,w)?x.push({type:"subtree",el:B,base:null}):re.push(B);let he=[];for(let B of Se)ve.has(B)||(ue(B,Ce,w)?x.push({type:"deletion",el:B}):he.push(B));if(re.length!==he.length)return!0;for(let B=0;B<re.length;B++)if(!h(re[B],he[B]))return!0;let Re=new Map(Me);for(let B=0;B<re.length;B++)Re.set(re[B],he[B]);let Be=-1;for(let B of oe){let G=Re.get(B);if(!G)continue;let ce=Se.indexOf(G);if(ce<Be)return!0;Be=ce}for(let B=0;B<re.length;B++)if(b(re[B],he[B],x))return!0;for(let[B,G]of Me)if(b(B,G,x))return!0;return!1}function b(L,C,x){if(L.tagName!==C.tagName)return l(L,C,x);let D=o(L,C),F=[];if($(L,C,F))return l(L,C,x);if(D.length){if(!r(L)&&!ue(C,s(),w))return!0;x.push({type:"attrs",el:L,names:D,base:C})}return x.push(...F),!1}let N=[],P=o(i,v);P.length&&N.push({type:"attrs",el:i,names:P});let H=(L,C)=>Array.from(L.children).find(x=>x.tagName===C)||null,_=H(i,"HEAD"),Z=H(v,"HEAD");if(_&&Z){let L=[];b(_,Z,L),L.length&&N.push({type:"head",el:_})}else(_||Z)&&_&&N.push({type:"head",el:_});let Y=H(i,"BODY"),V=H(v,"BODY");return Y&&V?b(Y,V,N):Y&&N.push({type:"subtree",el:Y,base:null}),{entries:N}}function Ye(i,v,A={}){let k=A.tiers&&A.tiers.length?A.tiers:Oe,M=i.documentElement,w=[],c=0,m=b=>({ok:!1,placed:w,held:b,skippedAttrs:c});if(!M)return m(null);function a(b){let N=[b,...b.querySelectorAll("*")];return de(N,k)}let s=a(M),r=new Map,l=b=>{let N=b.getRootNode(),P=r.get(N);if(!P){let H=N.nodeType===9?N.documentElement:N;P=a(H),r.set(N,P)}return P};function o(b){if(!b.parentElement&&b.tagName==="HTML")return M;if(b.parentElement&&!b.parentElement.parentElement&&b.parentElement.tagName==="HTML"){if(b.tagName==="BODY")return i.body||null;if(b.tagName==="HEAD")return i.head||null}return null}function d(b){let N=o(b);return N||xe(b,l(b),s,k)}function h(b){if(!b)return null;let N=d(b);return N&&N.isConnected?N:null}function I(b){for(let N=0;N<k.length;N++){let P=k[N](b);P!=null&&P!==""&&s[N].set(P,b)}}for(let b of v){if(b.type!=="deletion")continue;let N=d(b.el);N&&N!==M&&N.remove()}let $=v.filter(b=>b.type!=="deletion").sort((b,N)=>b.el===N.el?0:b.el.compareDocumentPosition(N.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let b of $){if(b.type==="head"){let V=i.importNode(b.el,!0);i.head?i.head.replaceWith(V):M.insertBefore(V,M.firstChild),w.push({entry:b,imported:V});continue}if(b.type==="attrs"){let V=h(b.el)||h(b.base);if(!V){c++;continue}for(let L of b.names)b.el.hasAttribute(L)?V.setAttribute(L,b.el.getAttribute(L)):V.removeAttribute(L);continue}let N=b.el;if(o(N))return m(b);let P=h(N)||h(b.base);if(P){let V=i.importNode(N,!0);P.replaceWith(V),I(V),w.push({entry:b,imported:V});continue}if(b.base!=null&&!ue(b.base,l(b.base),k)||!ue(N,l(N),k))return m(b);let H=N.parentElement;if(!H)return m(b);let _=h(H);if(!_)return m(b);let Z=null;for(let V=N.previousElementSibling;V;V=V.previousElementSibling){let L=h(V);if(L&&L.parentNode===_){Z=L;break}}let Y=i.importNode(N,!0);if(Z)_.insertBefore(Y,Z.nextSibling);else{let V=Array.prototype.indexOf.call(H.children,N);_.insertBefore(Y,_.children[V]||null)}I(Y),w.push({entry:b,imported:Y})}return{ok:!0,placed:w,held:null,skippedAttrs:c}}return{morph:J,defaults:T,findChangedRoots:Ge,spliceProtected:Ye,mergeJson:be,mergeScriptText:Ae,parseJsonRelaxed:pe,parseRulesRelaxed:Ne}})();var Et=fe.morph,wt=fe.defaults,Nt=fe.findChangedRoots,Tt=fe.spliceProtected;var It=fe;return nt(Ot);})();
1
+ var HyperMorph=(()=>{var ke=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var it=(e,n)=>{for(var t in n)ke(e,t,{get:n[t],enumerable:!0})},ot=(e,n,t,y)=>{if(n&&typeof n=="object"||typeof n=="function")for(let u of rt(n))!st.call(e,u)&&u!==t&&ke(e,u,{get:()=>n[u],enumerable:!(y=nt(n,u))||y.enumerable});return e};var at=e=>ot(ke({},"__esModule",{value:!0}),e);var Ht={};it(Ht,{HyperMorph:()=>fe,default:()=>Bt,defaults:()=>Ct,findChangedRoots:()=>Lt,mergeJson:()=>Se,mergeScriptText:()=>ve,morph:()=>xt,parseJsonRelaxed:()=>ge,parseRulesRelaxed:()=>Ee,spliceProtected:()=>Rt});var Pe={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function ut(e){let n=5381;for(let t=0;t<e.length;t++)n=(n<<5)+n^e.charCodeAt(t);return Math.abs(n).toString(36)}function ct(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let n=e.getAttribute?.("class");return n?n.split(/\s+/).filter(Boolean).sort().join(" "):""}function lt(e,n){let t=[];for(let y of e.attributes||[]){let u=y.name;u==="id"||u==="class"||n.excludeAttributePrefixes.some(b=>u.startsWith(b))||n.includeAttributes.includes(u)&&t.push(`${u}=${y.value}`)}return t.sort().join("|")}function ft(e,n){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,n.textHintLength)}function dt(e,n){let t=[e.tagName];return n.includeClasses&&t.push(ct(e)),t.push(lt(e,n)),ut(t.join("|"))}function ht(e){let n=e.tagName,t=1,y=e.previousElementSibling;for(;y;)y.tagName===n&&t++,y=y.previousElementSibling;return t}function pt(e,n){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:n.landmarks.includes(e.tagName)}function gt(e){let n=e.getAttribute?.("id");if(n)return`#${n}`;let t=e.getAttribute?.("role");return t?`@${t}`:e.tagName}function mt(e,n){let t=[],y=e;for(;y&&y.tagName&&t.length<n.maxPathDepth;){let u=`${y.tagName}:${ht(y)}`;if(t.unshift(u),y!==e&&pt(y,n)){t.unshift(gt(y));break}y=y.parentElement}return t}function yt(e,n){let t=0,y=e.length-1,u=n.length-1;for(;y>=0&&u>=0&&e[y]===n[u];)t++,y--,u--;return t}function X(e,n,t){if(t.has(e))return t.get(e);let y={signature:dt(e,n),path:mt(e,n),textHint:ft(e,n)};return t.set(e,y),y}function qe(e,n,t,y){if(y.has(e))return y.get(e);let u=new Map,b=e.querySelectorAll("*"),S=0;for(let d of b){let M=X(d,n,t);M.domIndex=S++,!n.shouldIgnore?.(d)&&(u.has(M.signature)||u.set(M.signature,[]),u.get(M.signature).push(d))}return y.set(e,u),u}function bt(e,n,t){t.delete(e),n.delete(e);let y=e.querySelectorAll("*");for(let u of y)n.delete(u)}function we(e,n,t,y,u){let b=X(e,t,y),S=X(n,t,y),d=t.weights,M={},$=0;if(b.signature!==S.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};$+=d.signature,M.signature=d.signature;let H=yt(b.path,S.path)*d.pathSegment;$+=H,M.path=H;let I=!0;if(b.textHint&&S.textHint?b.textHint===S.textHint?($+=d.textMatch,M.text=d.textMatch):($-=d.textMismatch,M.text=-d.textMismatch,I=!1):b.textHint!==S.textHint&&($-=d.textMismatch,M.text=-d.textMismatch,I=!1),u.candidateCount===1&&I&&($+=d.uniqueCandidate,M.unique=d.uniqueCandidate),typeof b.domIndex=="number"&&typeof S.domIndex=="number"){let k=Math.abs(b.domIndex-S.domIndex),E=Math.min(k*d.positionPenalty,d.maxDriftPenalty);$-=E,M.drift=-E}return{score:$,breakdown:M}}function De(e,n,t,y,u){if(t.excludeIds&&e.getAttribute("id"))return null;let b=qe(n,t,y,u),S=X(e,t,y);if(typeof S.domIndex!="number"){let I=0,k=e.previousElementSibling;for(;k;)I++,k=k.previousElementSibling;S.domIndex=I}let d=b.get(S.signature)||[],M=t.excludeIds?d.filter(I=>!I.getAttribute("id")):d;if(M.length===0)return null;let $=null,q=0,H=null;for(let I of M){let{score:k,breakdown:E}=we(e,I,t,y,{candidateCount:M.length});k>q&&(q=k,$=I,H=E)}return q<t.minConfidence?null:{element:$,confidence:q,breakdown:H}}function At(e,n,t,y){let u=[],b=t.weights.signature+t.weights.slotMatch,S={slot:b};function d(H){if(H.children)return H.children;let I=H.childNodes;if(!I)return[];let k=[];for(let E=0;E<I.length;E++)I[E].nodeType===1&&k.push(I[E]);return k}function M(H,I){let k=d(H),E=d(I);if(k.length===E.length)for(let K=0;K<k.length;K++){let U=k[K],J=E[K];if(t.shouldIgnore?.(U)||t.shouldIgnore?.(J)||t.excludeIds&&(U.getAttribute("id")||J.getAttribute("id"))||U.tagName!==J.tagName)continue;let Q=X(U,t,y).signature,ee=X(J,t,y).signature;Q!==ee&&u.push({newEl:U,oldEl:J,score:b,breakdown:S}),M(U,J)}}function $(H,I){for(;;){if(H.tagName===I.tagName)return[H,I];let k=d(H);if(!H.tagName&&k.length===1){H=k[0];continue}let E=d(I);if(E.length===1&&E[0].tagName===H.tagName){I=E[0];continue}return null}}let q=$(e,n);return q&&M(q[0],q[1]),u}function ze(e,n,t,y,u){let b=n.querySelectorAll("*"),S=qe(e,t,y,u),d=0;for(let k of b){let E=X(k,t,y);E.domIndex=d++}let M=[],$=new Map;function q(k,E,K){let U=new Set;if(k.textHint){let G=$.get(k.signature);if(!G){G=new Map;for(let ne of E){let ye=X(ne,t,y).textHint,re=G.get(ye);re||(re=[],G.set(ye,re)),re.push(ne)}$.set(k.signature,G)}let de=G.get(k.textHint);if(de)for(let ne=0;ne<de.length&&ne<K;ne++)U.add(de[ne])}let J=0,Q=E.length;for(;J<Q;){let G=J+Q>>1;X(E[G],t,y).domIndex<k.domIndex?J=G+1:Q=G}let ee=Math.max(0,Math.min(J-(K>>1),E.length-K)),te=Math.min(ee+K,E.length);for(let G=ee;G<te;G++)U.add(E[G]);return[...U]}for(let k of b){if(t.shouldIgnore?.(k)||t.excludeIds&&k.getAttribute("id"))continue;let E=X(k,t,y),K=S.get(E.signature)||[],U=t.excludeIds?K.filter(ee=>!ee.getAttribute("id")):K,J=t.maxScoredCandidates,Q=J&&U.length>J?q(E,U,J):U;for(let ee of Q){let{score:te,breakdown:G}=we(k,ee,t,y,{candidateCount:U.length});te>=t.minConfidence&&M.push({newEl:k,oldEl:ee,score:te,breakdown:G})}}if(t.weights.slotMatch>0){let k=At(n,e,t,y);for(let E of k)M.push(E)}M.sort((k,E)=>E.score-k.score);let H=new Map,I=new Set;for(let{newEl:k,oldEl:E}of M)H.has(k)||I.has(E)||(H.set(k,E),I.add(E));return H}function _e(e,n,t,y){let u=X(e,t,y),b=X(n,t,y),{score:S,breakdown:d}=we(e,n,t,y,{candidateCount:1});return{matches:S>=t.minConfidence,score:S,breakdown:d,newMeta:{signature:u.signature,path:u.path,textHint:u.textHint},oldMeta:{signature:b.signature,path:b.path,textHint:b.textHint}}}function Fe(e={}){let n={...Pe,...e,weights:{...Pe.weights,...e.weights}},t=new WeakMap,y=new WeakMap;return{findMatch:(u,b)=>De(u,b,n,t,y),computeMatches:(u,b)=>ze(u,b,n,t,y),explain:(u,b)=>_e(u,b,n,t),invalidate:u=>bt(u,t,y),session:()=>{let u=new WeakMap,b=new WeakMap;return{findMatch:(S,d)=>De(S,d,n,u,b),computeMatches:(S,d)=>ze(S,d,n,u,b),explain:(S,d)=>_e(S,d,n,u)}},getConfig:()=>({...n})}}function Te(e,n){for(;;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]==="/"&&e[n+1]==="/"){for(;n<e.length&&e[n]!==`
2
+ `;)n++;continue}if(e[n]==="/"&&e[n+1]==="*"){let t=e.indexOf("*/",n+2);if(t===-1)return e.length;n=t+2;continue}return n}}function Ve(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(n,t)=>t.length%2===0?t+'\\"':n)}var St=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,vt=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function ge(e){try{return JSON.parse(e)}catch{return JSON.parse(Mt(e))}}function Mt(e){let n="",t=0,y=(u,b)=>{throw new Error(`Invalid relaxed JSON: ${u} at position ${b}`)};for(;t<e.length&&(t=Te(e,t),!(t>=e.length));){let u=e[t];if("{}[]:".includes(u)){n+=u,t++;continue}if(u===","){let d=Te(e,t+1);if(e[d]==="}"||e[d]==="]"){t++;continue}n+=u,t++;continue}if(u==='"'||u==="'"){let d=t+1;for(;d<e.length&&e[d]!==u;)e[d]==="\\"&&d++,d++;d>=e.length&&y("unterminated string",t);let M=e.slice(t+1,d);u==="'"&&(M=Ve(M)),n+='"'+M+'"',t=d+1;continue}let b=t;for(;b<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[b]);)b++;b===t&&y("unexpected character "+JSON.stringify(u),t);let S=e.slice(t,b);if(S==="true"||S==="false"||S==="null"||St.test(S)){n+=S,t=b;continue}if(vt.test(S)){if(e[Te(e,b)]===":"){n+='"'+S+'"',t=b;continue}y("unquoted value "+JSON.stringify(S),t)}y("invalid token "+JSON.stringify(S),t)}return n}function Ee(e){try{return JSON.parse(e)}catch{}let n={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function t(u){let b=[],S=0;for(;S<u.length;){let d=u[S];if(/\s/.test(d)){S++;continue}if("{}".includes(d)){b.push({type:d,value:d}),S++;continue}if(d==="["){let H=!1,I=S+1;for(;I<u.length&&/\s/.test(u[I]);)I++;if(I<u.length&&/[a-zA-Z_]/.test(u[I])&&(H=!0),!H){b.push({type:d,value:d}),S++;continue}}if(d==="]"){b.push({type:d,value:d}),S++;continue}if(d===":"){b.push({type:n.COLON,value:d}),S++;continue}if(d===","){b.push({type:n.COMMA,value:d}),S++;continue}if(d==='"'||d==="'"){let H=d,I=S+1;for(;I<u.length&&u[I]!==H;)u[I]==="\\"&&I++,I++;b.push({type:n.STRING,value:u.substring(S+1,I),quoted:!0,sourceQuote:H}),S=I+1;continue}let M=S,$;for(;M<u.length&&!/[{},]/.test(u[M]);)if(u[M]===":"){let H=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],I=!1;for(let k of H){let E=k.substring(1);if(u.substring(M+1,M+1+E.length)===E){I=!0,M+=E.length;break}}if(!I)break}else if(u[M]==="["){for(M++;M<u.length&&u[M]!=="]";){if(u[M]==='"'||u[M]==="'"){let H=u[M];for(M++;M<u.length&&u[M]!==H;)u[M]==="\\"&&M++,M++}M++}M<u.length&&u[M]==="]"&&M++}else M++;$=u.substring(S,M);let q=n.IDENTIFIER;/^-?\d+(\.\d+)?$/.test($)?q=n.NUMBER:$==="true"||$==="false"||$==="null"?q=n.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test($)&&(q=n.SELECTOR),b.push({type:q,value:$,quoted:!1}),S=M}return b}function y(u){let b="";for(let S=0;S<u.length;S++){let d=u[S];if("{}".includes(d.type)||"[]".includes(d.type)){b+=d.value;continue}if(d.type===n.COLON){b+=d.value;continue}if(d.type===n.COMMA){let M=u[S+1];if(M&&(M.type==="}"||M.type==="]"))continue;b+=d.value;continue}if(d.type===n.STRING){let M=d.value;d.sourceQuote==="'"&&(M=Ve(M)),b+=`"${M}"`;continue}if(d.type===n.NUMBER||d.type===n.BOOLEAN){b+=d.value;continue}b+=`"${d.value}"`}return b}try{let u=t(e),b=y(u);return JSON.parse(b)}catch(u){throw new Error("Invalid extraction rules syntax: "+u.message)}}var V=Symbol("hyper-morph-json-merge:missing"),Ke=["id","_id","uuid","key","slug","code","name"];function le(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function me(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Nt(e,n,t){Object.defineProperty(e,n,{value:t,enumerable:!0,writable:!0,configurable:!0})}function ie(e,n){if(e===n)return!0;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!ie(e[t],n[t]))return!1;return!0}if(le(e)&&le(n)){let t=Object.keys(e);if(t.length!==Object.keys(n).length)return!1;for(let y of t)if(!me(n,y)||!ie(e[y],n[y]))return!1;return!0}return!1}function Ue(e,n,t,y){return ie(n,t)?n:ie(n,e)?t:ie(t,e)?n:le(n)&&le(t)?kt(le(e)?e:{},n,t,y):Array.isArray(n)&&Array.isArray(t)?It(Array.isArray(e)?e:[],n,t,y):t}function Je(e,n,t,y){return n===V&&t===V?V:n===V?e===V?t:ie(t,e)?V:t:t===V?e===V?n:V:Ue(e,n,t,y)}function kt(e,n,t,y){let u={},b=new Set([...Object.keys(e),...Object.keys(n),...Object.keys(t)]);for(let S of b){let d=Je(me(e,S)?e[S]:V,me(n,S)?n[S]:V,me(t,S)?t[S]:V,y);d!==V&&Nt(u,S,d)}return u}function wt(e){return e===null||typeof e!="object"}function Ae(e){return typeof e+":"+String(e)}function Tt(e,n){for(let t of n){let y=new Set;for(let u of t){if(!me(u,e))return!1;let b=u[e];if(typeof b!="string"&&typeof b!="number")return!1;let S=Ae(b);if(y.has(S))return!1;y.add(S)}}return!0}function Et(e,n,t,y){let u=[e,n,t],b=!0;for(let S of u)for(let d of S)le(d)||(b=!1);if(b){for(let S of y.keyCandidates)if(Tt(S,u))return{kind:"keyed",field:S};return null}for(let S of u){let d=new Set;for(let M of S){if(!wt(M))return null;let $=Ae(M);if(d.has($))return null;d.add($)}}return{kind:"self"}}function It(e,n,t,y){let u=Et(e,n,t,y);if(!u)return t;let b=u.kind==="self"?Ae:k=>Ae(k[u.field]),S=k=>{let E=new Map;for(let K of k)E.set(b(K),K);return E},d=S(e),M=S(n),$=S(t),q=new Map,H=new Set([...d.keys(),...M.keys(),...$.keys()]);for(let k of H){let E=Je(d.has(k)?d.get(k):V,M.has(k)?M.get(k):V,$.has(k)?$.get(k):V,y);E!==V&&q.set(k,E)}let I=[];for(let k of t){let E=b(k);q.has(E)&&I.push(E)}for(let k=0;k<n.length;k++){let E=b(n[k]);if(!q.has(E)||I.includes(E))continue;let K=0;for(let U=k-1;U>=0;U--){let J=I.indexOf(b(n[U]));if(J!==-1){K=J+1;break}}I.splice(K,0,E)}return I.map(k=>q.get(k))}function Se(e,n,t,y={}){let u=y.keyCandidates?[...y.keyCandidates,...Ke]:Ke;return Ue(e===void 0?V:e,n,t,{keyCandidates:u})}function ve(e,n,t,y={}){let u=y.parse||ge,b=[],S=(H,I)=>{if(typeof H!="string")return V;try{return u(H)}catch(k){return b.push(`${I} side is not valid JSON (${k.message})`),V}},d=S(n,"local"),M=S(t,"remote");if(d===V)return{text:t,warnings:b};if(M===V)return{text:n,warnings:b};let $=S(e,"base"),q=Se($===V?void 0:$,d,M,y);return ie(q,M)?{text:t,warnings:b}:ie(q,d)?{text:n,warnings:b}:{text:JSON.stringify(q,null,2),warnings:b}}var Ot=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),_t=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),qt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function We(e){let n=Ot[e];if(!n)throw new Error(`Unknown region capability: ${e}`);return[...n.tokens,...n.bundles].flatMap(t=>[`[clay~="${t}"]`,`[${t}]`]).join(", ")}var fe=(function(){"use strict";let e=()=>{},n='[editor-ui],[clay~="editor-ui"],[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]',t=`${We("history")},[no-undo],[clay~="no-undo"]`;function y(r){if(r?.nodeType!==1)return!1;if(r.matches(n))return!0;if(r.tagName==="LINK"||r.tagName==="SCRIPT"){let p=r.getAttribute("src")||r.getAttribute("href")||"";if(p.startsWith("chrome-extension://")||p.startsWith("moz-extension://")||p.startsWith("safari-web-extension://"))return!0}return!1}function u(r){return r?.nodeType!==1?!1:r.closest(n)?!0:y(r)}function b(r,p,h){if(h){let w=h.identityOf(r);if(w&&!h.disabled.has(w.key))return"hm-merge:"+w.key}if(p!=="smart")return r.outerHTML;let N=r.getAttribute("src"),A=r.getAttribute("type")||"text/javascript";if(N)try{let w=new URL(N,window.location.href);return`ext:${A}:${w.origin}${w.pathname}${w.search}`}catch{return`ext:${A}:${N}`}else{let w=r.textContent.trim(),a=5381;for(let c=0;c<w.length;c++)a=(a<<5)+a^w.charCodeAt(c);return`inline:${A}:${Math.abs(a).toString(36)}`}}let S="http://www.w3.org/1999/xhtml";function d(r){return r?.nodeType===1&&r.tagName==="SCRIPT"&&r.namespaceURI===S}function M(r){let p=document.createElement("div");p.innerHTML="<script><\/script>";let h=p.firstChild;for(let N of r.attributes)h.setAttribute(N.name,N.value);return h.textContent=r.textContent,h}function $(r){if(d(r))return M(r);if(r?.nodeType===1)for(let p of r.querySelectorAll("script"))d(p)&&p.replaceWith(M(p));return r}function q(r){let p=(r.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return p==="application/json"||p.endsWith("+json")}let H={match:r=>r.hasAttribute("merge"),identity:r=>r.getAttribute("merge")};function I(r,p,h){if(h.merge===!1)return null;let N=[H,...h.mergeTags||[]],A=new WeakMap,w=i=>{if(A.has(i))return A.get(i);let g=null;if(d(i)&&!i.getAttribute("src")&&!u(i)){let m=i;for(let T=0;T<N.length;T++)if(N[T].match(m)){if(!q(m))console.warn("[hyper-morph] merge ignored: script type is not JSON",m);else{let R=N[T].identity(m);R!=null&&R!==""&&(g={key:T+":"+R,raw:R,recognizer:N[T]})}break}}return A.set(i,g),g},a=new Set,c=i=>{let g=new Map,m=T=>{let R=w(T);R&&(g.has(R.key)?(a.add(R.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${R.raw}"`)):g.set(R.key,T))};d(i)&&m(i);for(let T of i.querySelectorAll("script"))m(T);return g},l=c(r),s=c(p.__hyperMorphRoot||p);if(l.size===0&&s.size===0)return null;let o=null;return{identityOf:w,disabled:a,oldByKey:l,newByKey:s,baseTexts:()=>{if(o)return o;o=new Map;let i=h.mergeBase;if(!i)return o;let g;typeof i=="string"?g=new DOMParser().parseFromString(i,"text/html").documentElement:i?.nodeType===9?g=i.documentElement:g=i;let m=T=>{let R=w(T);R&&!o.has(R.key)&&o.set(R.key,T.textContent)};d(g)&&m(g);for(let T of g.querySelectorAll("script"))m(T);return o}}}function k(r,p,h){let N=r.merge;if(!N)return!1;let A=N.identityOf(p);if(!A||N.disabled.has(A.key))return!1;let w=N.identityOf(h);if(!w||w.key!==A.key)return!1;let a=p,c=h,l=c.getAttribute("merge-key")||a.getAttribute("merge-key"),{text:s,warnings:o}=ve(N.baseTexts().get(A.key),a.textContent,c.textContent,{parse:A.recognizer.parse,keyCandidates:l?l.split(/[\s,]+/).filter(Boolean):void 0});for(let f of o)console.warn(`[hyper-morph] merge "${A.raw}": ${f}`);return a.textContent!==s&&(a.textContent=s),!0}let E={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:r=>r.getAttribute("im-preserve")==="true",shouldReAppend:r=>r.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:r=>r.getAttribute("im-preserve")==="true",shouldReAppend:r=>r.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},K={computeMatches(r,p,h=u){let{computeMatches:N}=Fe({shouldIgnore:h}).session();return N(r,p)}};function U(r,p,h={}){r=Xe(r);let N=Oe(p),A=Qe(r,N,h),w=A.scripts.handle?new Set(Array.from(r.querySelectorAll("script")).map(s=>b(s,A.scripts.matchMode,A.merge))):null,a=ne(A),c;try{c=Ge(A,r,N,s=>s.morphStyle==="innerHTML"?(re(s,r,N),Array.from(r.childNodes)):de(s,r,N))}catch(s){throw Q(A),s}let l=s=>{a&&ye(A,a),J(A);let o=w?Ze(s,w,A):[];return o.length>0?Promise.all(o).then(()=>s):s};if(c instanceof Promise)return c.then(s=>{try{return l(s)}catch(o){throw Q(A),o}},s=>{throw Q(A),s});try{return l(c)}catch(s){throw Q(A),s}}function J(r){let p=r.pantry;if(p){for(let h of Array.from(p.childNodes))r.callbacks.beforeNodeRemoved(h)!==!1&&r.callbacks.afterNodeRemoved(h);for(let h of Array.from(p.childNodes))p.removeChild(h);p.remove(),r.pantry=null,r.stagedNodes.clear()}}function Q(r){let p=r.pantry;if(!p)return;let h=Array.from(r.stagedNodes.entries()).reverse();for(let[N,A]of h){if(!p.contains(N))continue;let w=A.nextSibling?.parentNode===A.parent?A.nextSibling:null;try{te(A.parent,N,w)}catch{}}for(let N of Array.from(p.childNodes))p.removeChild(N);p.remove(),r.pantry=null,r.stagedNodes.clear()}function ee(r){if(r.pantry)return r.pantry;let p=r.target.ownerDocument,h=p.createElement("div");return h.hidden=!0,h.setAttribute("mutations-ignore",""),p.body.insertAdjacentElement("afterend",h),r.pantry=h,h}function te(r,p,h){if(r.moveBefore)try{r.moveBefore(p,h)}catch{r.insertBefore(p,h)}else r.insertBefore(p,h)}function G(r,p){!r.stagedNodes.has(p)&&p.parentNode&&r.stagedNodes.set(p,{parent:p.parentNode,nextSibling:p.nextSibling}),te(ee(r),p,null)}function de(r,p,h){let N=Oe(p);return re(r,N,h,p,p.nextSibling),Array.from(N.childNodes)}function ne(r){if(!r.config.restoreFocus)return null;let p=document.activeElement;if(!(p instanceof HTMLInputElement||p instanceof HTMLTextAreaElement))return null;let{id:h,selectionStart:N,selectionEnd:A}=p;return{element:p,id:h,selectionStart:N,selectionEnd:A}}function ye(r,p){let h=p.element;if(p.id&&p.id!==document.activeElement?.getAttribute("id")&&(h=r.target.querySelector(`[id="${CSS.escape(p.id)}"]`),h?.focus()),h&&!h.selectionEnd&&p.selectionEnd!=null)try{h.setSelectionRange(p.selectionStart,p.selectionEnd)}catch{}}let re=(function(){function r(s,o,f,i=null,g=null){o?.tagName==="TEMPLATE"&&f?.tagName==="TEMPLATE"&&(o=o.content,f=f.content),i||=o.firstChild;for(let m of f.childNodes){if(s.shouldIgnore(m))continue;if(i&&i!=g){let R=N(s,m,i,g);if(R){R!==i&&w(s,i,R),be(R,m,s),i=R.nextSibling;continue}}if(m?.nodeType===1){let R=m.getAttribute("id");if(s.persistentIds.has(R)){let v=a(o,R,i,s);be(v,m,s),i=v.nextSibling;continue}if(!s.idMap.has(m)){let v=s.hyperMatches.get(m);if(v&&!s.idMap.has(v)&&!l(v,o)){te(o,v,i),be(v,m,s),i=v.nextSibling;continue}}}let T=p(o,m,i,s);T&&(i=T.nextSibling)}for(;i&&i!=g;){let m=i;i=i.nextSibling,s.shouldIgnore(m)||A(s,m)}}function p(s,o,f,i){if(i.callbacks.beforeNodeAdded(o)===!1)return null;let g=s.ownerDocument||s.realParentNode?.ownerDocument||i.target.ownerDocument;if(i.idMap.has(o)){let m=o,T=g.createElementNS(m.namespaceURI,m.localName);return s.insertBefore(T,f),be(T,o,i),i.callbacks.afterNodeAdded(T),T}else{let m=$(h(o,g,i));return m?(s.insertBefore(m,f),i.callbacks.afterNodeAdded(m),m):null}}function h(s,o,f){if(f.shouldIgnore(s))return null;let i=o.importNode(s,!1),g=s.nodeType===1&&s.tagName==="TEMPLATE"?s.content:s,m=i.nodeType===1&&i.tagName==="TEMPLATE"?i.content:i;for(let T of Array.from(g.childNodes||[])){let R=h(T,o,f);R&&m.appendChild(R)}return i}let N=(function(){function s(i,g,m,T){let R=g?.nodeType===1&&!i.idMap.has(g)?i.hyperMatches.get(g):null,v=null,O=g.nextSibling,P=0,B=m;for(;B&&B!=T;){if(i.shouldIgnore(B)){B=B.nextSibling;continue}if(f(B,g)){if(o(i,B,g)||B===R&&!i.idMap.has(B))return B;if(v===null){let F=B?.nodeType===1&&i.hyperMatchedOldElements.has(B);!i.idMap.has(B)&&!F&&(v=B)}}if(v===null&&O&&f(B,O)&&(P++,O=O.nextSibling,P>=2&&(v=void 0)),i.activeElementAndParents.includes(B))break;B=B.nextSibling}return v||null}function o(i,g,m){let T=i.idMap.get(g),R=i.idMap.get(m);if(!R||!T)return!1;for(let v of T)if(R.has(v))return!0;return!1}function f(i,g){let m=i,T=g;return m.nodeType===T.nodeType&&m.tagName===T.tagName&&(!m.getAttribute?.("id")||m.getAttribute?.("id")===T.getAttribute?.("id"))}return s})();function A(s,o){let f=o?.nodeType===1&&s.hyperMatchedOldElements.has(o)&&!s.idMap.has(o);if(s.idMap.has(o)||f)G(s,o);else{if(s.callbacks.beforeNodeRemoved(o)===!1)return;o.parentNode?.removeChild(o),s.callbacks.afterNodeRemoved(o)}}function w(s,o,f){let i=o;for(;i&&i!==f;){let g=i;i=i.nextSibling,s.shouldIgnore(g)||A(s,g)}return i}function a(s,o,f,i){let g=i.target.ownerDocument?.defaultView?.CSS?.escape?i.target.ownerDocument.defaultView.CSS.escape(o):String(o).replace(/["\\]/g,"\\$&"),m=i.target.getAttribute?.("id")===o&&i.target||i.target.querySelector(`[id="${g}"]`)||i.pantry?.querySelector(`[id="${g}"]`);return c(m,i),te(s,m,f),m}function c(s,o){let f=s.getAttribute("id");for(;s=s.parentNode;){let i=o.idMap.get(s);i&&(i.delete(f),i.size||o.idMap.delete(s))}}function l(s,o){let f=o?.nodeType===1?o:o.realParentNode;return!!f&&s.contains(f)}return r})(),be=(function(){function r(a,c,l){return l.ignoreActive&&a===document.activeElement?null:(l.callbacks.beforeNodeMorphed(a,c)===!1||(a?.tagName==="HEAD"&&l.head.ignore||(a?.tagName==="HEAD"&&l.head.style!=="morph"?Ie(a,c,l):(p(a,c,l),k(l,a,c)||w(a,l)||re(l,a,c))),l.callbacks.afterNodeMorphed(a,c)),a)}function p(a,c,l){let s=c.nodeType;if(s===1){let o=a,f=c,i=o.attributes,g=f.attributes;for(let m of g)A(m.name,o,"update",l)||o.getAttribute(m.name)!==m.value&&o.setAttribute(m.name,m.value);for(let m=i.length-1;0<=m;m--){let T=i[m];if(T&&!f.hasAttribute(T.name)){if(A(T.name,o,"remove",l))continue;o.removeAttribute(T.name)}}w(o,l)||h(o,f,l)}(s===8||s===3)&&a.nodeValue!==c.nodeValue&&(a.nodeValue=c.nodeValue)}function h(a,c,l){if(a.tagName==="INPUT"&&c.tagName==="INPUT"&&c.type!=="file"){let s=c.value,o=a.value;N(a,c,"checked",l),N(a,c,"disabled",l),l.formStateSync==="property"&&a.indeterminate!==c.indeterminate&&(a.indeterminate=c.indeterminate),l.formStateSync==="property"?o!==s&&(A("value",a,"update",l)||(a.value=s)):c.hasAttribute("value")?o!==s&&(A("value",a,"update",l)||(a.setAttribute("value",s),a.value=s)):A("value",a,"remove",l)||(a.value="",a.removeAttribute("value"))}else if(a.tagName==="OPTION"&&c.tagName==="OPTION")N(a,c,"selected",l);else if(a.tagName==="TEXTAREA"&&c.tagName==="TEXTAREA"){let s=c.value,o=a.value;if(A("value",a,"update",l)||(s!==o&&(a.value=s),l.formStateSync==="property"))return;a.firstChild&&a.firstChild.nodeValue!==s&&(a.firstChild.nodeValue=s)}}function N(a,c,l,s){let o=c[l],f=a[l];if(o!==f){let i=A(l,a,"update",s);if(i||(a[l]=c[l]),s.formStateSync==="property")return;o?i||a.setAttribute(l,""):A(l,a,"remove",s)||a.removeAttribute(l)}}function A(a,c,l,s){return a==="value"&&s.ignoreActiveValue&&c===document.activeElement?!0:s.callbacks.beforeAttributeUpdated(a,c,l)===!1}function w(a,c){return!!c.ignoreActiveValue&&a===document.activeElement&&a!==document.body}return r})();function Ge(r,p,h,N){if(r.head.block){let A=p.querySelector("head"),w=h.querySelector("head");if(A&&w){let a=Ie(A,w,r);return Promise.all(a).then(()=>(r.head.block=!1,r.head.ignore=!0,N(r)))}}return N(r)}function Ye(r){return r.tagName==="SCRIPT"?!!r.getAttribute("src"):r.tagName==="LINK"?(r.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!r.getAttribute("href"):!1}function Ie(r,p,h){let N=[],A=[],w=[],a=[],c=h.scripts.matchMode,l=f=>{if(f.tagName==="SCRIPT")return b(f,c,h.merge);if(f.tagName==="LINK"&&c==="smart"){let i=f.getAttribute("href");if(i)try{let g=new URL(i,window.location.href);return`link:${f.getAttribute("rel")||""}:${g.origin}${g.pathname}${g.search}`}catch{}}return f.outerHTML},s=new Map;for(let f of p.children){if(h.shouldIgnore(f))continue;let i=l(f),g=s.get(i);g||(g=[],s.set(i,g)),g.push(f)}for(let f of r.children){let i=l(f),g=s.get(i),m=!!(g&&g.length),T=h.head.shouldReAppend(f),R=h.head.shouldPreserve(f);if(m||R)if(T)A.push(f);else{if(g&&g.length){let v=g.pop();g.length||s.delete(i),k(h,f,v)}w.push(f)}else h.head.style==="append"?T&&(A.push(f),a.push(f)):h.head.shouldRemove(f)!==!1&&!h.shouldIgnore(f)&&A.push(f)}for(let f of s.values())a.push(...f);let o=[];for(let f of a){let i=document.createRange().createContextualFragment(f.outerHTML).firstChild;if(h.callbacks.beforeNodeAdded(i)!==!1){if(i instanceof Element&&Ye(i)){let g,m=new Promise(function(T){g=T});i.addEventListener("load",function(){g()}),i.addEventListener("error",function(){g()}),o.push(m)}r.appendChild(i),h.callbacks.afterNodeAdded(i),N.push(i)}}for(let f of A)h.callbacks.beforeNodeRemoved(f)!==!1&&(r.removeChild(f),h.callbacks.afterNodeRemoved(f));return h.head.afterHeadMorphed(r,{added:N,kept:w,removed:A}),o}function Ze(r,p,h){if(!h.scripts.handle)return[];let N=[],A=[],w=[],a=[],c=h.scripts.matchMode,l=[];for(let o of r)if(o instanceof Element){d(o)&&l.push(o);for(let f of o.querySelectorAll("script"))d(f)&&l.push(f)}for(let o of l){if(o.closest("head")||h.shouldIgnore(o))continue;let f=b(o,c,h.merge),i=p.has(f),g=h.scripts.shouldPreserve(o),m=h.scripts.shouldReAppend(o);i||g?m?(A.push(o),a.push(o)):w.push(o):a.push(o)}let s=[];for(let o of a){if(h.callbacks.beforeNodeAdded(o)===!1)continue;let f=document.createElement("script");for(let i of o.attributes)f.setAttribute(i.name,i.value);if(f.textContent=o.textContent,f.src){let i,g=new Promise(function(m){i=m});f.addEventListener("load",function(){i()}),f.addEventListener("error",function(){i()}),s.push(g)}o.replaceWith(f),h.callbacks.afterNodeAdded(f),N.push(f)}return h.scripts.afterScriptsHandled(h.target,{added:N,kept:w,removed:A}),s}let Qe=(function(){function r(c,l,s){let o=s.policy==="history"?t:n,f=s.policy==="raw"?()=>!1:P=>{if(P?.nodeType!==1)return!1;if(s.policy!=="history"&&u(P))return!0;let B=P.closest(o);return!(!B||s.policy==="history"&&B===c&&B.matches('[no-undo],[clay~="no-undo"]')&&!B.matches('[editor-ui],[clay~="editor-ui"]'))},{persistentIds:i,idMap:g}=w(c,l,f),m=K.computeMatches(c,l,f);if(typeof s.key=="function"){let P=new Map,B=new Set,F=x=>{let L=s.key(x);L!=null&&(P.has(L)?B.add(L):P.set(L,x))};c instanceof Element&&F(c);for(let x of c.querySelectorAll("*"))F(x);for(let x of B)P.delete(x);let Y=new Map;for(let[x,L]of m)Y.set(L,x);let Z=l.__hyperMorphRoot||l,z=new Map,C=new Set,D=x=>{let L=s.key(x);L!=null&&(z.has(L)?C.add(L):z.set(L,x))};Z instanceof Element&&D(Z);for(let x of Z.querySelectorAll("*"))D(x);for(let x of C)z.delete(x);for(let[x,L]of z){let _=P.get(x);if(!_||_.tagName!==L.tagName)continue;let oe=Y.get(_);oe&&oe!==L&&m.delete(oe);let ae=m.get(L);ae&&ae!==_&&Y.delete(ae),m.set(L,_),Y.set(_,L)}}let T=p(s),R=I(c,l,T.scripts);if(R){let P=new Map;for(let[B,F]of m)P.set(F,B);for(let[B,F]of R.newByKey){if(R.disabled.has(B))continue;let Y=R.oldByKey.get(B);if(!Y)continue;let Z=P.get(Y);Z&&Z!==F&&m.delete(Z);let z=m.get(F);z&&z!==Y&&P.delete(z),m.set(F,Y),P.set(Y,F)}}let v=new Set;for(let P of m.values())v.add(P);let O=T.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(O))throw new Error(`Do not understand how to morph style ${O}`);return{target:c,newContent:l,config:T,morphStyle:O,ignoreActive:T.ignoreActive,ignoreActiveValue:T.ignoreActiveValue,restoreFocus:T.restoreFocus,formStateSync:T.formStateSync||"attribute",idMap:g,persistentIds:i,hyperMatches:m,hyperMatchedOldElements:v,merge:R,pantry:null,stagedNodes:new Map,activeElementAndParents:h(c),callbacks:T.callbacks,head:T.head,scripts:T.scripts,shouldIgnore:f}}function p(c){let l=Object.assign({},E);return Object.assign(l,c),l.callbacks=Object.assign({},E.callbacks,c.callbacks),l.head=Object.assign({},E.head,c.head),l.scripts=Object.assign({},E.scripts,c.scripts),l}function h(c){let l=[],s=c.ownerDocument?.activeElement;if(s?.tagName!=="BODY"&&c.contains(s))for(;s&&(l.push(s),s!==c);)s=s.parentElement;return l}function N(c){let l=Array.from(c.querySelectorAll("[id]"));return c.getAttribute?.("id")&&l.push(c),l}function A(c,l,s,o){for(let f of o){let i=f.getAttribute("id");if(l.has(i)){let g=f;for(;g;){let m=c.get(g);if(m==null&&(m=new Set,c.set(g,m)),m.add(i),g===s)break;g=g.parentElement}}}}function w(c,l,s){let o=N(c).filter(T=>!s(T)),f=N(l).filter(T=>!s(T)),i=a(o,f),g=new Map;A(g,i,c,o);let m=l.__hyperMorphRoot||l;return A(g,i,m,f),{persistentIds:i,idMap:g}}function a(c,l){let s=new Set,o=new Map;for(let i of c){let g=i.getAttribute("id");o.has(g)?s.add(g):o.set(g,i.tagName)}let f=new Set;for(let i of l){let g=i.getAttribute("id");f.has(g)?s.add(g):o.get(g)===i.tagName&&f.add(g)}for(let i of s)f.delete(i);return f}return r})(),{normalizeElement:Xe,normalizeParent:Oe}=(function(){let r=new WeakSet;function p(a){return a?.nodeType===9?a.documentElement:a}function h(a){if(a==null)return document.createElement("div");if(typeof a=="string")return h(w(a));if(r.has(a))return a;if(a&&typeof a=="object"&&"nodeType"in a){if(a.parentNode)return new N(a);{let c=a.ownerDocument.createElement("div");return c.append(a),c}}else{let l=[...a][0]?.ownerDocument?.createElement("div")||document.createElement("div");for(let s of[...a])l.append(s);return l}}class N{constructor(c){this.originalNode=c,this.realParentNode=c.parentNode,this.previousSibling=c.previousSibling,this.nextSibling=c.nextSibling}get childNodes(){let c=[],l=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;l&&l!=this.nextSibling;)c.push(l),l=l.nextSibling;return c}querySelectorAll(c){return this.childNodes.reduce((l,s)=>{if(s instanceof Element){s.matches(c)&&l.push(s);let o=s.querySelectorAll(c);for(let f=0;f<o.length;f++)l.push(o[f])}return l},[])}insertBefore(c,l){return this.realParentNode.insertBefore(c,l)}moveBefore(c,l){return this.realParentNode.moveBefore(c,l)}get __hyperMorphRoot(){return this.originalNode}}function A(a){let c=f=>`<${f}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,l=a.replace(/<!--[\s\S]*?-->/g,"");for(let f of["script","style","textarea","title"])l=l.replace(new RegExp(`${c(f)}[\\s\\S]*?</${f}\\s*>`,"gi"),"");let s=new RegExp(`${c("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),o;do o=l,l=l.replace(s,"");while(l!==o);return l}function w(a){let c=new DOMParser,l=A(a);if(l.match(/<\/html>/)||l.match(/<\/head>/)||l.match(/<\/body>/)){let s=c.parseFromString(a,"text/html");if(l.match(/<\/html>/))return r.add(s),s;{let o=s.firstChild;return o&&r.add(o),o}}else{let o=c.parseFromString("<body><template>"+a+"</template></body>","text/html").body.querySelector("template").content;return r.add(o),o}}return{normalizeElement:p,normalizeParent:h}})(),xe=Symbol("hyper-morph-duplicate-key"),Ce=[r=>r.getAttribute("data-id"),r=>r.getAttribute("id")];function he(r,p){return p.map(h=>{let N=new Map;for(let A of r){if(A.nodeType!==1)continue;let w=h(A);w==null||w===""||N.set(w,N.has(w)?xe:A)}return N})}function Le(r,p,h,N){for(let A=0;A<N.length;A++){let w=N[A](r);if(w==null||w===""||p[A].get(w)!==r)continue;let a=h[A].get(w);if(!(!a||a===xe)&&a.tagName===r.tagName)return a}return null}function ue(r,p,h){for(let N=0;N<h.length;N++){let A=h[N](r);if(!(A==null||A==="")&&p[N].get(A)===r)return!0}return!1}function et(r,p,h={}){let N=h.skip||(()=>!1),A=h.ignoreAttr||(()=>!1),w=h.tiers&&h.tiers.length?h.tiers:Ce,a=null;function c(){return a||(a=he([r,...r.querySelectorAll("*")],w)),a}let l=null;function s(){return l||(l=he([p,...p.querySelectorAll("*")],w)),l}function o(C){return!C.parentElement||!C.parentElement.parentElement}function f(C,D,x){return o(C)||ue(C,c(),w)?(x.push({type:"subtree",el:C,base:D}),!1):!0}function i(C,D){let x=[];for(let L of C.attributes)A(C,L.name)||D.getAttribute(L.name)!==L.value&&x.push(L.name);for(let L of D.attributes)A(C,L.name)||C.hasAttribute(L.name)||x.push(L.name);return x}function g(C){let D=[],x=null,L=()=>{x!==null&&(D.push({nodeType:3,nodeValue:x}),x=null)};for(let _ of C.childNodes){if(_.nodeType===3){x=(x===null?"":x)+_.nodeValue;continue}_.nodeType===1&&N(_)||(L(),(_.nodeType===1||_.nodeType===8)&&D.push(_))}return L(),D}function m(C,D){if(C.nodeType!==D.nodeType)return!1;if(C.nodeType!==1)return!0;if(C.tagName!==D.tagName)return!1;for(let x of w){let L=x(C),_=x(D);if(L!=null&&L!==""&&_!=null&&_!==""&&L!==_)return!1}return!0}function T(C){let D="";for(let x of C)x.nodeType===3&&x.nodeValue.trim()!==""?D+="\0"+x.nodeValue:x.nodeType===8&&(D+=""+x.nodeValue);return D}function R(C,D,x){let L=g(C),_=g(D);if(L.length===_.length){let j=!0;for(let W=0;W<L.length;W++)if(!m(L[W],_[W])){j=!1;break}if(j){for(let W=0;W<L.length;W++){let ce=L[W];if(ce.nodeType===1){if(v(ce,_[W],x))return!0}else if(ce.nodeValue!==_[W].nodeValue)return!0}return!1}}let oe=L.filter(j=>j.nodeType===1),ae=_.filter(j=>j.nodeType===1);if(T(L)!==T(_))return!0;let Re=he(oe,w),Be=he(ae,w),Me=[],Ne=new Set,He=[];for(let j of oe){let W=Le(j,Re,Be,w);W&&!Ne.has(W)?(Me.push([j,W]),Ne.add(W)):He.push(j)}let se=[];for(let j of He)ue(j,Re,w)?x.push({type:"subtree",el:j,base:null}):se.push(j);let pe=[];for(let j of ae)Ne.has(j)||(ue(j,Be,w)?x.push({type:"deletion",el:j}):pe.push(j));if(se.length!==pe.length)return!0;for(let j=0;j<se.length;j++)if(!m(se[j],pe[j]))return!0;let je=new Map(Me);for(let j=0;j<se.length;j++)je.set(se[j],pe[j]);let $e=-1;for(let j of oe){let W=je.get(j);if(!W)continue;let ce=ae.indexOf(W);if(ce<$e)return!0;$e=ce}for(let j=0;j<se.length;j++)if(v(se[j],pe[j],x))return!0;for(let[j,W]of Me)if(v(j,W,x))return!0;return!1}function v(C,D,x){if(C.tagName!==D.tagName)return f(C,D,x);let L=i(C,D),_=[];if(R(C,D,_))return f(C,D,x);if(L.length){if(!o(C)&&!ue(D,s(),w))return!0;x.push({type:"attrs",el:C,names:L,base:D})}return x.push(..._),!1}let O=[],P=i(r,p);P.length&&O.push({type:"attrs",el:r,names:P});let B=(C,D)=>Array.from(C.children).find(x=>x.tagName===D)||null,F=B(r,"HEAD"),Y=B(p,"HEAD");if(F&&Y){let C=[];v(F,Y,C),C.length&&O.push({type:"head",el:F})}else(F||Y)&&F&&O.push({type:"head",el:F});let Z=B(r,"BODY"),z=B(p,"BODY");return Z&&z?v(Z,z,O):Z&&O.push({type:"subtree",el:Z,base:null}),{entries:O}}function tt(r,p,h={}){let N=h.tiers&&h.tiers.length?h.tiers:Ce,A=r.documentElement,w=[],a=0,c=v=>({ok:!1,placed:w,held:v,skippedAttrs:a});if(!A)return c(null);function l(v){let O=[v,...v.querySelectorAll("*")];return he(O,N)}let s=l(A),o=new Map,f=v=>{let O=v.getRootNode(),P=o.get(O);if(!P){let B=O.nodeType===9?O.documentElement:O;P=l(B),o.set(O,P)}return P};function i(v){if(!v.parentElement&&v.tagName==="HTML")return A;if(v.parentElement&&!v.parentElement.parentElement&&v.parentElement.tagName==="HTML"){if(v.tagName==="BODY")return r.body||null;if(v.tagName==="HEAD")return r.head||null}return null}function g(v){let O=i(v);return O||Le(v,f(v),s,N)}function m(v){if(!v)return null;let O=g(v);return O&&O.isConnected?O:null}function T(v){for(let O=0;O<N.length;O++){let P=N[O](v);P!=null&&P!==""&&s[O].set(P,v)}}for(let v of p){if(v.type!=="deletion")continue;let O=g(v.el);O&&O!==A&&O.remove()}let R=p.filter(v=>v.type!=="deletion").sort((v,O)=>v.el===O.el?0:v.el.compareDocumentPosition(O.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let v of R){if(v.type==="head"){let z=r.importNode(v.el,!0);r.head?r.head.replaceWith(z):A.insertBefore(z,A.firstChild),w.push({entry:v,imported:z});continue}if(v.type==="attrs"){let z=m(v.el)||m(v.base);if(!z){a++;continue}for(let C of v.names)v.el.hasAttribute(C)?z.setAttribute(C,v.el.getAttribute(C)):z.removeAttribute(C);continue}let O=v.el;if(i(O))return c(v);let P=m(O)||m(v.base);if(P){let z=r.importNode(O,!0);P.replaceWith(z),T(z),w.push({entry:v,imported:z});continue}if(v.base!=null&&!ue(v.base,f(v.base),N)||!ue(O,f(O),N))return c(v);let B=O.parentElement;if(!B)return c(v);let F=m(B);if(!F)return c(v);let Y=null;for(let z=O.previousElementSibling;z;z=z.previousElementSibling){let C=m(z);if(C&&C.parentNode===F){Y=C;break}}let Z=r.importNode(O,!0);if(Y)F.insertBefore(Z,Y.nextSibling);else{let z=Array.prototype.indexOf.call(B.children,O);F.insertBefore(Z,F.children[z]||null)}T(Z),w.push({entry:v,imported:Z})}return{ok:!0,placed:w,held:null,skippedAttrs:a}}return{morph:U,defaults:E,findChangedRoots:et,spliceProtected:tt,mergeJson:Se,mergeScriptText:ve,parseJsonRelaxed:ge,parseRulesRelaxed:Ee}})();var xt=fe.morph,Ct=fe.defaults,Lt=fe.findChangedRoots,Rt=fe.spliceProtected;var Bt=fe;return at(Ht);})();
3
3
 
4
4
  // Convenience morph wrapper with data-id support
5
5
  var morph = function(oldEl, newEl, options = {}) {
@@ -1,4 +1,4 @@
1
- var hyperundo=(()=>{var T=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(e,t)=>{for(var n in t)T(e,n,{get:t[n],enumerable:!0})},oe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of te(t))!re.call(e,o)&&o!==n&&T(e,o,{get:()=>t[o],enumerable:!(r=ee(t,o))||r.enumerable});return e};var ae=e=>oe(T({},"__esModule",{value:!0}),e);var me={};ne(me,{default:()=>pe,undo:()=>C});function ie(e,t=null){let n=[];if(e.type==="attributes"){let r=e.target,o=e.attributeName,i=e.oldValue,u=r.getAttribute(o);return i==null&&u!=null?n.push({kind:"attr-add",target:r,name:o,newValue:u}):i!=null&&u==null?n.push({kind:"attr-remove",target:r,name:o,oldValue:i}):i!==u&&n.push({kind:"attr-set",target:r,name:o,oldValue:i,newValue:u}),n}if(e.type==="characterData")return n.push({kind:"text",target:e.target,oldValue:e.oldValue,newValue:e.target.data}),n;if(e.type==="childList"){let r=e.target,o=e.nextSibling,i=t?Array.from(e.addedNodes).filter(d=>!t(d)):Array.from(e.addedNodes),u=t?Array.from(e.removedNodes).filter(d=>!t(d)):Array.from(e.removedNodes);return i.length>0&&n.push({kind:"add",parent:r,nodes:i,before:o}),u.length>0&&n.push({kind:"remove",parent:r,nodes:u,before:o}),n}return n}function P(e,t=null){let n=[],r=new Map;for(let o of e){if(o.type==="attributes"){let i=o.target,u=o.attributeName,d=r.get(i);d||(d=new Map,r.set(i,d)),d.has(u)||(d.set(u,{idx:n.length,oldValue:o.oldValue}),n.push(null));continue}for(let i of ie(o,t))n.push(i)}for(let[o,i]of r)for(let[u,d]of i){let l=d.oldValue,m=o.getAttribute(u),p=null;l===m?p=null:l==null?p={kind:"attr-add",target:o,name:u,newValue:m}:m==null?p={kind:"attr-remove",target:o,name:u,oldValue:l}:p={kind:"attr-set",target:o,name:u,oldValue:l,newValue:m},n[d.idx]=p}return n.filter(o=>o!=null)}function L(e){switch(e.kind){case"attr-set":case"attr-add":e.target.setAttribute(e.name,e.newValue);return;case"attr-remove":e.target.removeAttribute(e.name);return;case"text":e.target.data=e.newValue;return;case"value":e.target[e.prop]=e.newValue;return;case"add":for(let t of e.nodes)e.before&&e.before.parentNode===e.parent?e.parent.insertBefore(t,e.before):e.parent.appendChild(t);return;case"remove":for(let t of e.nodes)t.parentNode===e.parent&&e.parent.removeChild(t);return}}function D(e){switch(e.kind){case"attr-set":e.target.setAttribute(e.name,e.oldValue);return;case"attr-add":e.target.removeAttribute(e.name);return;case"attr-remove":e.target.setAttribute(e.name,e.oldValue);return;case"text":e.target.data=e.oldValue;return;case"value":e.target[e.prop]=e.oldValue;return;case"add":for(let t of e.nodes)t.parentNode===e.parent&&e.parent.removeChild(t);return;case"remove":for(let t of e.nodes)e.before&&e.before.parentNode===e.parent?e.parent.insertBefore(t,e.before):e.parent.appendChild(t);return}}var se=['[src^="chrome-extension://"]','[href^="chrome-extension://"]','[src^="moz-extension://"]','[href^="moz-extension://"]','[src^="safari-web-extension://"]','[href^="safari-web-extension://"]','[id="1p-menu-live-region"]',"com-1password-button","com-1password-menu","com-1password-notification","grammarly-extension","grammarly-desktop-integration","lt-div","lt-card","lt-toolbar","lt-highlighter","[data-lastpass-root]","[data-lastpass-icon-root]","[data-dashlane-shadowhost]","[data-klarna-extension]",'[class*="klarna-extension"]',".skiptranslate","#goog-gt-tt",".goog-te-banner-frame",".goog-te-balloon-frame","style.darkreader","style[data-darkreader-mode]","style[data-darkreader-scheme]","#loom-companion-mv3","loom-container","[ext-id]"],ue=["data-grammarly","data-lt","data-1p","data-com-onepassword","data-lastpass","data-lp","data-kwimpala","data-bitwarden","data-bw","data-dashlane","data-np","data-protonpass","data-proton-pass","data-keeper","data-rf","data-roboform","data-honey","data-rakuten","data-capital-one","data-wikibuy","data-klarna","data-darkreader","data-evernote","data-pocket","data-pin"],M=se.join(","),U=new RegExp("^(?:"+ue.join("|")+")(?:-|$)");var de=["mutations-ignore","save-remove","save-ignore","save-freeze","no-undo","no-watch"];function le(){if(typeof window>"u")return null;let e=window.clay?.region||window.hyperclay?.region;return e&&typeof e.resolveRegionPolicy=="function"?e.resolveRegionPolicy:null}function ce(e){let t=le();if(t)try{return!t(e).undoable}catch{}let n=e&&e.nodeType!==1?e.parentElement:e;if(n&&n.closest&&n.closest(M))return!0;for(;n&&n.nodeType===1;){for(let r of de)if(n.hasAttribute&&n.hasAttribute(r))return!0;n=n.parentElement}return!1}function R(e,t,n){if(ce(e))return!0;if(n&&n.type==="attributes"){if(n.attributeName&&U.test(n.attributeName.toLowerCase()))return!0;if(t)try{if(t(n.attributeName,n.target))return!0}catch{}}return!1}function X(){let e=new Map;function t(o,i){let u=e.get(o);return u||(u=new Set,e.set(o,u)),u.add(i),()=>n(o,i)}function n(o,i){let u=e.get(o);u&&u.delete(i)}function r(o,i){let u=e.get(o);if(u)for(let d of Array.from(u))try{d(i)}catch(l){console.error("[hyper-undo] listener threw",l)}}return{on:t,off:n,emit:r}}var fe={maxHistory:100,idleWindowMs:500,idleLabel:"Edit",ignoreAttribute:null,debug:!1};function N(e){let t={...fe,...e};if(!t.scope)throw new Error("hyper-undo: scope is required");let n=X(),r=[],o=[],i=[],u=null,d=null,l=0,m=!1;function p(...s){t.debug&&console.log("[hyper-undo]",...s)}function H(){m||(m=!0,d=W(g),d.observe(t.scope,{childList:!0,attributes:!0,characterData:!0,subtree:!0,attributeOldValue:!0,characterDataOldValue:!0}),p("started"))}function W(s){let c=typeof document<"u"&&t.scope===document.body,f=typeof window<"u"&&(window.clay?.Mutation||window.hyperclay?.Mutation)||null;return c&&f&&typeof f.createObserver=="function"?(p("sourcing records from the platform Mutation hub (shared observer)"),f.createObserver(s)):new MutationObserver(s)}function E(){m&&(m=!1,d&&(d.disconnect(),d=null),y(),r.length=0,o.length=0,i=[],l=0,p("stopped"))}function V(){let s=t.scope;return!!(s&&s.nodeType===1&&s.isConnected===!1)}function g(s){if(l>0)return;let c=_(s);if(c.length>0){for(let f of c)i.push(f);I()}}function _(s){let c=s.filter(f=>!R(f.target,t.ignoreAttribute,f));return P(c,f=>R(f,t.ignoreAttribute))}function I(){y(),u=setTimeout(K,t.idleWindowMs)}function y(){u!=null&&(clearTimeout(u),u=null)}function K(){if(u=null,i.length===0)return;let s=i;i=[],v(t.idleLabel,s)}function v(s,c){for(r.push({label:s,timestamp:Date.now(),primitives:c}),o.length=0;r.length>t.maxHistory;)r.shift();p("commit",s,"primitives:",c.length),n.emit("commit")}function j(s,c){if(!m)throw new Error("hyper-undo: scope not started");g(d.takeRecords()),w();let f=c();if(f&&typeof f.then=="function")throw new Error("hyper-undo: commit() fn must be synchronous; returned a Promise");if(g(d.takeRecords()),i.length===0){n.emit("commit");return}y();let b=i;i=[],v(s,b)}function G(s){if(!m)throw new Error("hyper-undo: scope not started");if(!d)return;if(l>1){d.takeRecords();return}w();let c=_(d.takeRecords());c.length!==0&&(y(),v(s,c))}function Z(){d&&d.takeRecords()}function O(s){!m||l>0||!s||(i.push(s),I())}function $(s,{prop:c="value",oldValue:f,newValue:b}={}){!s||f===b||O({kind:"value",target:s,prop:c,oldValue:f,newValue:b})}function w(){l===0&&d&&g(d.takeRecords()),i.length!==0&&(y(),K())}function k(){l===0&&d&&g(d.takeRecords()),l++,p("paused",l)}function x(){l!==0&&(l--,l===0&&d&&d.takeRecords(),p("resumed",l))}function J(){if(V()){E();return}w();let s=r.pop();if(s){k();try{for(let c=s.primitives.length-1;c>=0;c--)try{D(s.primitives[c])}catch(f){p("undo primitive failed (continuing)",f)}}finally{x()}o.push(s),p("undo",s.label),n.emit("undo")}}function Q(){if(V()){E();return}w();let s=o.pop();if(s){k();try{for(let c of s.primitives)try{L(c)}catch(f){p("redo primitive failed (continuing)",f)}}finally{x()}r.push(s),p("redo",s.label),n.emit("redo")}}function Y(){d&&d.takeRecords(),r.length=0,o.length=0,i=[],y(),p("cleared"),n.emit("clear")}return{_config:t,start:H,stop:E,commit:j,commitCaptured:G,discardCaptured:Z,flush:w,record:O,recordValue:$,undo:J,redo:Q,clear:Y,pause:k,resume:x,on:n.on,off:n.off,get canUndo(){return r.length>0},get canRedo(){return o.length>0},get isPaused(){return l>0},get history(){return r.map(s=>({label:s.label,timestamp:s.timestamp}))},get scope(){return t.scope}}}function q(e,t){let n=r=>{let o=e.scope;if(o&&o.nodeType===1&&o.isConnected===!1){t&&t();return}let i=r.target,u=e._config.shadowKeydownIn;if(i&&i.closest&&Array.isArray(u))for(let m of u)try{if(i.closest(m))return}catch{}if(!(r.metaKey||r.ctrlKey))return;let l=(r.key||"").toLowerCase();if(l==="z"&&!r.shiftKey){r.preventDefault(),r.stopPropagation(),e.undo();return}if(l==="z"&&r.shiftKey){r.preventDefault(),r.stopPropagation(),e.redo();return}if(l==="y"&&!r.shiftKey){r.preventDefault(),r.stopPropagation(),e.redo();return}};return window.addEventListener("keydown",n,!0),()=>window.removeEventListener("keydown",n,!0)}var A=[".CodeMirror",".cm-editor",".monaco-editor",".ace_editor",".ql-editor",".tiptap",".ProseMirror"],a=null,S=null,z=null,h=null;function F(e,t){if(h){if(h.inst===e)return h.cleanup;throw new Error("hyper-undo: another scope already owns the global Cmd+Z binding (bindKeys: true). Stop it first, or use bindKeys: false for additional scopes.")}let n=q(e,t);return h={inst:e,cleanup:n},n}function B(e){h&&h.inst===e&&(h.cleanup(),h=null)}var C={defaults:{shadowKeydownIn:A},start(e={}){let t=e.scope||(typeof document<"u"?document.body:null);if(!t)throw new Error("hyper-undo: no scope (need document.body or explicit { scope })");if(a){if(S===t)return console.warn("[hyper-undo] start() called again on existing singleton; ignoring new options"),a;throw new Error("hyper-undo: start() called with a different scope while the singleton is already started. Use undo.create({ scope }) for additional scopes, or call undo.stop() first.")}let n={...e,scope:t,shadowKeydownIn:e.shadowKeydownIn||A};return a=N(n),a.start(),S=t,e.bindKeys!==!1&&(z=F(a,()=>C.stop())),a},stop(){a&&(B(a),z=null,a.stop(),a=null,S=null)},create(e={}){let t=e.scope||(typeof document<"u"?document.body:null);if(!t)throw new Error("hyper-undo: no scope (need document.body or explicit { scope })");let n={...e,scope:t,shadowKeydownIn:e.shadowKeydownIn||A},r=N(n),o=null,i={_config:r._config,commit:r.commit,commitCaptured:r.commitCaptured,discardCaptured:r.discardCaptured,flush:r.flush,record:r.record,recordValue:r.recordValue,undo:r.undo,redo:r.redo,clear:r.clear,pause:r.pause,resume:r.resume,on:r.on,off:r.off,get canUndo(){return r.canUndo},get canRedo(){return r.canRedo},get isPaused(){return r.isPaused},get history(){return r.history},get scope(){return r.scope},start(){e.bindKeys&&(o=F(r,()=>i.stop())),r.start()},stop(){B(r),o=null,r.stop()}};return i},commit(e,t){return a?a.commit(e,t):void 0},commitCaptured(e){return a?a.commitCaptured(e):void 0},discardCaptured(){return a?a.discardCaptured():void 0},record(e){return a?a.record(e):void 0},recordValue(e,t){return a?a.recordValue(e,t):void 0},undo(){return a?a.undo():void 0},redo(){return a?a.redo():void 0},clear(){return a?a.clear():void 0},pause(){return a?a.pause():void 0},resume(){return a?a.resume():void 0},flush(){return a?a.flush():void 0},on(e,t){return a?a.on(e,t):void 0},off(e,t){return a?a.off(e,t):void 0},get canUndo(){return a?a.canUndo:!1},get canRedo(){return a?a.canRedo:!1},get history(){return a?a.history:[]},get isPaused(){return a?a.isPaused:!1}};var pe=C;return ae(me);})();
1
+ var hyperundo=(()=>{var T=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var le=Object.prototype.hasOwnProperty;var de=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},ce=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ue(t))!le.call(e,o)&&o!==r&&T(e,o,{get:()=>t[o],enumerable:!(n=se(t,o))||n.enumerable});return e};var fe=e=>ce(T({},"__esModule",{value:!0}),e);var xe={};de(xe,{default:()=>ke,undo:()=>I});function pe(e,t=null){let r=[];if(e.type==="attributes"){let n=e.target,o=e.attributeName,a=e.oldValue,u=n.getAttribute(o);return a==null&&u!=null?r.push({kind:"attr-add",target:n,name:o,newValue:u}):a!=null&&u==null?r.push({kind:"attr-remove",target:n,name:o,oldValue:a}):a!==u&&r.push({kind:"attr-set",target:n,name:o,oldValue:a,newValue:u}),r}if(e.type==="characterData")return r.push({kind:"text",target:e.target,oldValue:e.oldValue,newValue:e.target.data}),r;if(e.type==="childList"){let n=e.target,o=e.nextSibling,a=e.nextSibling;for(;a&&t?.(a);)a=a.nextSibling;let u=e.previousSibling;for(;u&&t?.(u);)u=u.previousSibling;let l=t?Array.from(e.addedNodes).filter(p=>!t(p)):Array.from(e.addedNodes),d=t?Array.from(e.removedNodes).filter(p=>!t(p)):Array.from(e.removedNodes);return l.length>0&&r.push({kind:"add",parent:n,nodes:l,before:o,afterAuthored:a,beforeAuthored:u}),d.length>0&&r.push({kind:"remove",parent:n,nodes:d,before:o,afterAuthored:a,beforeAuthored:u}),r}return r}function D(e,t=null){let r=[],n=new Map;for(let o of e){if(o.type==="attributes"){let a=o.target,u=o.attributeName,l=n.get(a);l||(l=new Map,n.set(a,l)),l.has(u)||(l.set(u,{idx:r.length,oldValue:o.oldValue}),r.push(null));continue}for(let a of pe(o,t))r.push(a)}for(let[o,a]of n)for(let[u,l]of a){let d=l.oldValue,p=o.getAttribute(u),m=null;d===p?m=null:d==null?m={kind:"attr-add",target:o,name:u,newValue:p}:p==null?m={kind:"attr-remove",target:o,name:u,oldValue:d}:m={kind:"attr-set",target:o,name:u,oldValue:d,newValue:p},r[l.idx]=m}return r.filter(o=>o!=null)}function j(e){switch(e.kind){case"attr-set":case"attr-add":e.target.setAttribute(e.name,e.newValue);return;case"attr-remove":e.target.removeAttribute(e.name);return;case"text":e.target.data=e.newValue;return;case"value":e.write?e.write(e.target,e.newValue):e.target[e.prop]=e.newValue;return;case"add":M(e);return;case"remove":for(let t of e.nodes)t.parentNode===e.parent&&e.parent.removeChild(t);return}}function U(e){switch(e.kind){case"attr-set":if(e.target.getAttribute(e.name)!==e.newValue)return;e.target.setAttribute(e.name,e.oldValue);return;case"attr-add":if(e.target.getAttribute(e.name)!==e.newValue)return;e.target.removeAttribute(e.name);return;case"attr-remove":if(e.target.hasAttribute(e.name))return;e.target.setAttribute(e.name,e.oldValue);return;case"text":if(e.target.data!==e.newValue)return;e.target.data=e.oldValue;return;case"value":if((e.read?e.read(e.target):e.target[e.prop])!==e.newValue)return;e.write?e.write(e.target,e.oldValue):e.target[e.prop]=e.oldValue;return;case"add":for(let t of e.nodes)t.parentNode===e.parent&&e.parent.removeChild(t);return;case"remove":M(e);return}}function M(e){if(e.afterAuthored?.parentNode===e.parent){for(let t of e.nodes)e.parent.insertBefore(t,e.afterAuthored);return}if(e.beforeAuthored?.parentNode===e.parent){let t=e.beforeAuthored;for(let r of e.nodes)t.after(r),t=r;return}for(let t of e.nodes)e.before?.parentNode===e.parent?e.parent.insertBefore(t,e.before):e.parent.appendChild(t)}var me=['[src^="chrome-extension://"]','[href^="chrome-extension://"]','[src^="moz-extension://"]','[href^="moz-extension://"]','[src^="safari-web-extension://"]','[href^="safari-web-extension://"]','[id="1p-menu-live-region"]',"com-1password-button","com-1password-menu","com-1password-notification","grammarly-extension","grammarly-desktop-integration","lt-div","lt-card","lt-toolbar","lt-highlighter","[data-lastpass-root]","[data-lastpass-icon-root]","[data-dashlane-shadowhost]","[data-klarna-extension]",'[class*="klarna-extension"]',".skiptranslate","#goog-gt-tt",".goog-te-banner-frame",".goog-te-balloon-frame","style.darkreader","style[data-darkreader-mode]","style[data-darkreader-scheme]","#loom-companion-mv3","loom-container","[ext-id]"],he=["data-grammarly","data-lt","data-1p","data-com-onepassword","data-lastpass","data-lp","data-kwimpala","data-bitwarden","data-bw","data-dashlane","data-np","data-protonpass","data-proton-pass","data-keeper","data-rf","data-roboform","data-honey","data-rakuten","data-capital-one","data-wikibuy","data-klarna","data-darkreader","data-evernote","data-pocket","data-pin"],X=me.join(","),B=new RegExp("^(?:"+he.join("|")+")(?:-|$)");var Se=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"]})}),ye=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),ge=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function E(e,t){if(!e||e.nodeType!==1)return!1;let r=e.getAttribute?.("clay");return!!(r&&r.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function N(e,t){if(E(e,t))return!0;for(let[r,n]of Object.entries(ye))if(n.includes(t)&&E(e,r))return!0;return!1}function q(e){return e==="clay"||ge.includes(e)}var we=["mutations-ignore","save-remove","save-ignore","save-freeze","no-undo","no-watch"];function be(){if(typeof window>"u")return null;let e=window.clay?.region||window.hyperclay?.region;return e&&typeof e.resolveRegionPolicy=="function"?e.resolveRegionPolicy:null}function S(e){let t=be();if(t)try{if(!t(e).undoable)return!0}catch{}let r=e&&e.nodeType!==1?e.parentElement:e;if(r&&r.closest&&r.closest(X))return!0;for(;r&&r.nodeType===1;){if(N(r,"no-undo")||N(r,"no-watch"))return!0;for(let n of we)if(E(r,n))return!0;r=r.parentElement}return!1}function Ee(e){let t=e.target,r=t.cloneNode(!1),n=r;for(;t.parentElement;){t=t.parentElement;let o=t.cloneNode(!1);o.appendChild(r),r=o}return e.oldValue==null?n.removeAttribute(e.attributeName):n.setAttribute(e.attributeName,e.oldValue),S(n)}function R(e,t,r){if(r?.type==="attributes"&&q(r.attributeName)){if(S(e)&&Ee(r))return!0}else if(S(e))return!0;if(r&&r.type==="attributes"){if(r.attributeName&&B.test(r.attributeName.toLowerCase()))return!0;if(t)try{if(t(r.attributeName,r.target))return!0}catch{}}return!1}function F(){let e=new Map;function t(o,a){let u=e.get(o);return u||(u=new Set,e.set(o,u)),u.add(a),()=>r(o,a)}function r(o,a){let u=e.get(o);u&&u.delete(a)}function n(o,a){let u=e.get(o);if(u)for(let l of Array.from(u))try{l(a)}catch(d){console.error("[hyper-undo] listener threw",d)}}return{on:t,off:r,emit:n}}var ve={maxHistory:100,idleWindowMs:500,idleLabel:"Edit",ignoreAttribute:null,debug:!1};function O(e){let t={...ve,...e};if(!t.scope)throw new Error("hyper-undo: scope is required");let r=F(),n=[],o=[],a=[],u=null,l=null,d=0,p=!1;function m(...s){t.debug&&console.log("[hyper-undo]",...s)}function Y(){p||(p=!0,l=Z(g),l.observe(t.scope,{childList:!0,attributes:!0,characterData:!0,subtree:!0,attributeOldValue:!0,characterDataOldValue:!0}),m("started"))}function Z(s){let c=typeof document<"u"&&t.scope===document.body,f=typeof window<"u"&&(window.clay?.Mutation||window.hyperclay?.Mutation)||null;return c&&f&&typeof f.createObserver=="function"?(m("sourcing records from the platform Mutation hub (shared observer)"),f.createObserver(s)):new MutationObserver(s)}function v(){p&&(p=!1,l&&(l.disconnect(),l=null),y(),n.length=0,o.length=0,a=[],d=0,m("stopped"))}function P(){let s=t.scope;return!!(s&&s.nodeType===1&&s.isConnected===!1)}function g(s){if(d>0)return;let c=_(s);if(c.length>0){for(let f of c)a.push(f);K()}}function _(s){let c=s.filter(f=>!R(f.target,t.ignoreAttribute,f));return D(c,f=>R(f,t.ignoreAttribute))}function K(){y(),u=setTimeout(L,t.idleWindowMs)}function y(){u!=null&&(clearTimeout(u),u=null)}function L(){if(u=null,a.length===0)return;let s=a;a=[],k(t.idleLabel,s)}function k(s,c){for(n.push({label:s,timestamp:Date.now(),primitives:c}),o.length=0;n.length>t.maxHistory;)n.shift();m("commit",s,"primitives:",c.length),r.emit("commit")}function J(s,c){if(!p)throw new Error("hyper-undo: scope not started");g(l.takeRecords()),w();let f=c();if(f&&typeof f.then=="function")throw new Error("hyper-undo: commit() fn must be synchronous; returned a Promise");if(g(l.takeRecords()),a.length===0){r.emit("commit");return}y();let b=a;a=[],k(s,b)}function Q(s){if(!p)throw new Error("hyper-undo: scope not started");if(!l)return;if(d>1){l.takeRecords();return}w();let c=_(l.takeRecords());c.length!==0&&(y(),k(s,c))}function ee(){l&&l.takeRecords()}function z(s){!p||d>0||!s||(a.push(s),K())}function te(s,{prop:c="value",oldValue:f,newValue:b,read:ae,write:ie}={}){!s||f===b||z({kind:"value",target:s,prop:c,oldValue:f,newValue:b,read:ae,write:ie})}function w(){d===0&&l&&g(l.takeRecords()),a.length!==0&&(y(),L())}function x(){d===0&&l&&g(l.takeRecords()),d++,m("paused",d)}function A(){d!==0&&(d--,d===0&&l&&l.takeRecords(),m("resumed",d))}function re(){if(P()){v();return}w();let s=n.pop();if(s){x();try{for(let c=s.primitives.length-1;c>=0;c--)try{U(s.primitives[c])}catch(f){m("undo primitive failed (continuing)",f)}}finally{A()}o.push(s),m("undo",s.label),r.emit("undo")}}function ne(){if(P()){v();return}w();let s=o.pop();if(s){x();try{for(let c of s.primitives)try{j(c)}catch(f){m("redo primitive failed (continuing)",f)}}finally{A()}n.push(s),m("redo",s.label),r.emit("redo")}}function oe(){l&&l.takeRecords(),n.length=0,o.length=0,a=[],y(),m("cleared"),r.emit("clear")}return{_config:t,start:Y,stop:v,commit:J,commitCaptured:Q,discardCaptured:ee,flush:w,record:z,recordValue:te,undo:re,redo:ne,clear:oe,pause:x,resume:A,on:r.on,off:r.off,get canUndo(){return n.length>0},get canRedo(){return o.length>0},get isPaused(){return d>0},get history(){return n.map(s=>({label:s.label,timestamp:s.timestamp}))},get scope(){return t.scope}}}function W(e,t){let r=n=>{let o=e.scope;if(o&&o.nodeType===1&&o.isConnected===!1){t&&t();return}let a=n.target,u=e._config.shadowKeydownIn;if(a&&a.closest&&Array.isArray(u))for(let p of u)try{if(a.closest(p))return}catch{}if(!(n.metaKey||n.ctrlKey))return;let d=(n.key||"").toLowerCase();if(d==="z"&&!n.shiftKey){n.preventDefault(),n.stopPropagation(),e.undo();return}if(d==="z"&&n.shiftKey){n.preventDefault(),n.stopPropagation(),e.redo();return}if(d==="y"&&!n.shiftKey){n.preventDefault(),n.stopPropagation(),e.redo();return}};return window.addEventListener("keydown",r,!0),()=>window.removeEventListener("keydown",r,!0)}var C=[".CodeMirror",".cm-editor",".monaco-editor",".ace_editor",".ql-editor",".tiptap",".ProseMirror","[data-richclay-active]"],i=null,V=null,$=null,h=null;function H(e,t){if(h){if(h.inst===e)return h.cleanup;throw new Error("hyper-undo: another scope already owns the global Cmd+Z binding (bindKeys: true). Stop it first, or use bindKeys: false for additional scopes.")}let r=W(e,t);return h={inst:e,cleanup:r},r}function G(e){h&&h.inst===e&&(h.cleanup(),h=null)}var I={defaults:{shadowKeydownIn:C},start(e={}){let t=e.scope||(typeof document<"u"?document.body:null);if(!t)throw new Error("hyper-undo: no scope (need document.body or explicit { scope })");if(i){if(V===t)return console.warn("[hyper-undo] start() called again on existing singleton; ignoring new options"),i;throw new Error("hyper-undo: start() called with a different scope while the singleton is already started. Use undo.create({ scope }) for additional scopes, or call undo.stop() first.")}let r={...e,scope:t,shadowKeydownIn:e.shadowKeydownIn||C};return i=O(r),i.start(),V=t,e.bindKeys!==!1&&($=H(i,()=>I.stop())),i},stop(){i&&(G(i),$=null,i.stop(),i=null,V=null)},create(e={}){let t=e.scope||(typeof document<"u"?document.body:null);if(!t)throw new Error("hyper-undo: no scope (need document.body or explicit { scope })");let r={...e,scope:t,shadowKeydownIn:e.shadowKeydownIn||C},n=O(r),o=null,a={_config:n._config,commit:n.commit,commitCaptured:n.commitCaptured,discardCaptured:n.discardCaptured,flush:n.flush,record:n.record,recordValue:n.recordValue,undo:n.undo,redo:n.redo,clear:n.clear,pause:n.pause,resume:n.resume,on:n.on,off:n.off,get canUndo(){return n.canUndo},get canRedo(){return n.canRedo},get isPaused(){return n.isPaused},get history(){return n.history},get scope(){return n.scope},start(){e.bindKeys&&(o=H(n,()=>a.stop())),n.start()},stop(){G(n),o=null,n.stop()}};return a},commit(e,t){return i?i.commit(e,t):void 0},commitCaptured(e){return i?i.commitCaptured(e):void 0},discardCaptured(){return i?i.discardCaptured():void 0},record(e){return i?i.record(e):void 0},recordValue(e,t){return i?i.recordValue(e,t):void 0},undo(){return i?i.undo():void 0},redo(){return i?i.redo():void 0},clear(){return i?i.clear():void 0},pause(){return i?i.pause():void 0},resume(){return i?i.resume():void 0},flush(){return i?i.flush():void 0},on(e,t){return i?i.on(e,t):void 0},off(e,t){return i?i.off(e,t):void 0},get canUndo(){return i?i.canUndo:!1},get canRedo(){return i?i.canRedo:!1},get history(){return i?i.history:[]},get isPaused(){return i?i.isPaused:!1}};var ke=I;return fe(xe);})();
2
2
 
3
3
  // Auto-export to window unless suppressed by loader.
4
4
  if (!window.__hyperclayNoAutoExport) {