hyper-html-api 0.6.1 → 0.6.3
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,4 +1,4 @@
|
|
|
1
1
|
var HyperHtmlApi=(()=>{var Ke=Object.defineProperty;var sn=Object.getOwnPropertyDescriptor;var an=Object.getOwnPropertyNames;var cn=Object.prototype.hasOwnProperty;var ze=(e,t)=>{for(var n in t)Ke(e,n,{get:t[n],enumerable:!0})},ln=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of an(t))!cn.call(e,r)&&r!==n&&Ke(e,r,{get:()=>t[r],enumerable:!(o=sn(t,r))||o.enumerable});return e};var un=e=>ln(Ke({},"__esModule",{value:!0}),e);var gr={};ze(gr,{applyData:()=>Mt,cms:()=>tn,default:()=>mr,engine:()=>Ce,extractData:()=>Et,upgrade:()=>nn});var He={};ze(He,{fromString:()=>Le,getRuleAtPath:()=>Je,getValueAtPath:()=>Ee,parseConfigKey:()=>dn,setAtPath:()=>re,toConfigKey:()=>fn,toString:()=>J});function J(e){return e.map(String).join(".")}function fn(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function dn(e){return e===""?[]:e.split(".")}function Le(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function Je(e,t){let n=e;for(let o of t){if(n==null||typeof n=="string")return;if(Array.isArray(n)){if(typeof o!="number"&&o!=="*")return;n=n[1];continue}if(typeof n=="object"){if(typeof o=="number"||!(o in n))return;n=n[o];continue}return}return n}function Ee(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function re(e,t,n){if(t.length===0)return n;let[o,...r]=t;if(typeof o=="number"){let i=Array.isArray(e)?[...e]:[];return i[o]=re(i[o],r,n),i}return{...e&&typeof e=="object"?e:{},[o]:re((e||{})[o],r,n)}}function pe(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[n,o]of Object.entries(e))t[n]=pe(o);return t}return""}var Pe=new WeakMap;function oe(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function me(e){let t=oe(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}var hn=new Set(["checked","selected","disabled","readOnly","paused"]);function Ge({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(Ze({rule:e,value:t,path:[],ctx:i})),r}function Ye(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),Tt.set(e,{rules:t,getData:n,onChange:o}),pn()}var Tt=new WeakMap,Ot=!1;function pn(){Ot||(document.addEventListener("input",Rt,!0),document.addEventListener("change",Rt,!0),document.addEventListener("click",mn,!0),Ot=!0)}function Nt(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&Tt.get(t)||null}function mn(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=Nt(t);if(!n)return;let{rules:o,getData:r,onChange:i}=n,a=t.getAttribute("data-hha-action"),s=Le(t.getAttribute("data-hha-path")||"");if(a==="scalar-array-add"){let c=Ee(r(),s)||[];i(re(r(),s,[...c,""]),{structural:!0});return}if(a==="object-array-add"){let c=Je(o,s);if(!Array.isArray(c))return;let A=Ee(r(),s)||[];i(re(r(),s,[...A,pe(c[1])]),{structural:!0});return}if(a==="array-remove"){if(s.length===0)return;let c=s.slice(0,-1),A=s[s.length-1],x=Ee(r(),c)||[];if(typeof A!="number")return;let w=x.filter((m,b)=>b!==A);i(re(r(),c,w),{structural:!0})}}function Rt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=Nt(t);if(!n)return;let{getData:o,onChange:r}=n,i=t.closest("[data-hha-path]");if(!i)return;let a=Le(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;r(re(o(),a,s),{structural:!1})}function Ze({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?bn({rule:e,value:t,path:n,ctx:o}):yn({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return An({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return gn({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function gn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",J(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=je(n[n.length-1]),r.appendChild(i)}for(let[i,a]of Object.entries(e)){let s=[...n,i],c=t?.[i];r.appendChild(Ze({rule:a,value:c,path:s,ctx:o}))}return r}function yn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="field-body";let a=document.createElement("label");a.className="field-label",a.textContent=je(n[n.length-1]||".")+wn(e);let s=En(e,o.appRoot),c=Sn(s,{value:t,rule:e,path:n,appRoot:o.appRoot}),A=c.el;return A.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(a),i.appendChild(A),r.appendChild(i),Pe.set(r,c),r}function bn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=je(n[n.length-1]),r.appendChild(i);let a=Array.isArray(t)?t:[],s=document.createElement("div");r.appendChild(s),a.forEach((A,x)=>{let w=[...n,x],m=document.createElement("div");m.className="scalar-array-row",m.setAttribute("data-hha-path",J(w));let b=document.createElement("input");b.type="text",b.className="field-input",b.value=A==null?"":String(A);let M=document.createElement("button");M.type="button",M.className="array-remove",M.textContent="\xD7",M.title="remove",M.setAttribute("data-hha-action","array-remove"),M.setAttribute("data-hha-path",J(w)),m.appendChild(b),m.appendChild(M),s.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","scalar-array-add"),c.setAttribute("data-hha-path",J(n)),r.appendChild(c),r}function An({rule:e,value:t,path:n,ctx:o}){let[,r]=e,i=Array.isArray(t)?t:[],a=document.createElement("div");a.className="form-section",a.setAttribute("data-hha-path",J(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=je(n[n.length-1]),a.appendChild(s),i.forEach((A,x)=>{let w=[...n,x],m=document.createElement("div");m.className="array-card",m.setAttribute("data-hha-path",J(w));let b=document.createElement("button");b.type="button",b.className="array-remove",b.textContent="\xD7",b.title="remove item",b.setAttribute("data-hha-action","array-remove"),b.setAttribute("data-hha-path",J(w)),m.appendChild(b);let M=Ze({rule:r,value:A,path:w,ctx:o});M.querySelector(".form-section-label")?.remove(),m.appendChild(M),a.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","object-array-add"),c.setAttribute("data-hha-path",J(n)),a.appendChild(c),a}function Sn(e,t){let n=xn(e);if(e.type==="select"&&e.options)for(let o of e.options){let r=document.createElement("option");r.value=o.value,r.textContent=o.text,String(t.value)===o.value&&(r.selected=!0),n.appendChild(r)}else e.type==="checkbox"?n.checked=t.value===!0||t.value==="true"||t.value==="checked":(e.type,n.value=t.value==null?"":String(t.value));return{el:n,destroy(){},focus(){n.focus()},validate(){}}}function En(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):n=me(e).prop,n&&hn.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=Mn(e,t);if(!o)return{type:"text"};let r=(o.tagName||"").toLowerCase();if(r==="textarea")return{type:"textarea"};if(r==="select")return{type:"select",options:Array.from(o.querySelectorAll("option")).map(s=>({value:s.getAttribute("value")||s.textContent,text:s.textContent.trim()||s.getAttribute("value")||""}))};if(r==="input"){let a=(o.getAttribute("type")||"text").toLowerCase();if(a==="checkbox"||a==="radio")return{type:"checkbox"};if(a==="number")return{type:"number"}}let i=(o.textContent||"").trim();return i.length>60||i.includes(`
|
|
2
2
|
`)?{type:"textarea"}:{type:"text"}}function Mn(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=me(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function xn(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function je(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function wn(e){return` \xB7 ${e}`}var kt={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 vn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return Math.abs(t).toString(36)}function On(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function Rn(e,t){let n=[];for(let o of e.attributes||[]){let r=o.name;r==="id"||r==="class"||t.excludeAttributePrefixes.some(i=>r.startsWith(i))||t.includeAttributes.includes(r)&&n.push(`${r}=${o.value}`)}return n.sort().join("|")}function Tn(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function Nn(e,t){let n=[e.tagName];return t.includeClasses&&n.push(On(e)),n.push(Rn(e,t)),vn(n.join("|"))}function kn(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function In(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function Cn(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function Ln(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${kn(o)}`;if(n.unshift(r),o!==e&&In(o,t)){n.unshift(Cn(o));break}o=o.parentElement}return n}function Hn(e,t){let n=0,o=e.length-1,r=t.length-1;for(;o>=0&&r>=0&&e[o]===t[r];)n++,o--,r--;return n}function G(e,t,n){if(n.has(e))return n.get(e);let o={signature:Nn(e,t),path:Ln(e,t),textHint:Tn(e,t)};return n.set(e,o),o}function Ht(e,t,n,o){if(o.has(e))return o.get(e);let r=new Map,i=e.querySelectorAll("*"),a=0;for(let s of i){let c=G(s,t,n);c.domIndex=a++,!t.shouldIgnore?.(s)&&(r.has(c.signature)||r.set(c.signature,[]),r.get(c.signature).push(s))}return o.set(e,r),r}function Pn(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function Qe(e,t,n,o,r){let i=G(e,n,o),a=G(t,n,o),s=n.weights,c={},A=0;if(i.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};A+=s.signature,c.signature=s.signature;let w=Hn(i.path,a.path)*s.pathSegment;A+=w,c.path=w;let m=!0;if(i.textHint&&a.textHint?i.textHint===a.textHint?(A+=s.textMatch,c.text=s.textMatch):(A-=s.textMismatch,c.text=-s.textMismatch,m=!1):i.textHint!==a.textHint&&(A-=s.textMismatch,c.text=-s.textMismatch,m=!1),r.candidateCount===1&&m&&(A+=s.uniqueCandidate,c.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof a.domIndex=="number"){let b=Math.abs(i.domIndex-a.domIndex),M=Math.min(b*s.positionPenalty,s.maxDriftPenalty);A-=M,c.drift=-M}return{score:A,breakdown:c}}function It(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let i=Ht(t,n,o,r),a=G(e,n,o);if(typeof a.domIndex!="number"){let m=0,b=e.previousElementSibling;for(;b;)m++,b=b.previousElementSibling;a.domIndex=m}let s=i.get(a.signature)||[],c=n.excludeIds?s.filter(m=>!m.getAttribute("id")):s;if(c.length===0)return null;let A=null,x=0,w=null;for(let m of c){let{score:b,breakdown:M}=Qe(e,m,n,o,{candidateCount:c.length});b>x&&(x=b,A=m,w=M)}return x<n.minConfidence?null:{element:A,confidence:x,breakdown:w}}function jn(e,t,n,o){let r=[],i=n.weights.signature+n.weights.slotMatch,a={slot:i};function s(w){if(w.children)return w.children;let m=w.childNodes;if(!m)return[];let b=[];for(let M=0;M<m.length;M++)m[M].nodeType===1&&b.push(m[M]);return b}function c(w,m){let b=s(w),M=s(m);if(b.length===M.length)for(let L=0;L<b.length;L++){let j=b[L],P=M[L];if(n.shouldIgnore?.(j)||n.shouldIgnore?.(P)||n.excludeIds&&(j.getAttribute("id")||P.getAttribute("id"))||j.tagName!==P.tagName)continue;let D=G(j,n,o).signature,V=G(P,n,o).signature;D!==V&&r.push({newEl:j,oldEl:P,score:i,breakdown:a}),c(j,P)}}function A(w,m){for(;;){if(w.tagName===m.tagName)return[w,m];let b=s(w);if(!w.tagName&&b.length===1){w=b[0];continue}let M=s(m);if(M.length===1&&M[0].tagName===w.tagName){m=M[0];continue}return null}}let x=A(e,t);return x&&c(x[0],x[1]),r}function Ct(e,t,n,o,r){let i=t.querySelectorAll("*"),a=Ht(e,n,o,r),s=0;for(let b of i){let M=G(b,n,o);M.domIndex=s++}let c=[],A=new Map;function x(b,M,L){let j=new Set;if(b.textHint){let I=A.get(b.signature);if(!I){I=new Map;for(let U of M){let ee=G(U,n,o).textHint,te=I.get(ee);te||(te=[],I.set(ee,te)),te.push(U)}A.set(b.signature,I)}let K=I.get(b.textHint);if(K)for(let U=0;U<K.length&&U<L;U++)j.add(K[U])}let P=0,D=M.length;for(;P<D;){let I=P+D>>1;G(M[I],n,o).domIndex<b.domIndex?P=I+1:D=I}let V=Math.max(0,Math.min(P-(L>>1),M.length-L)),Y=Math.min(V+L,M.length);for(let I=V;I<Y;I++)j.add(M[I]);return[...j]}for(let b of i){if(n.shouldIgnore?.(b)||n.excludeIds&&b.getAttribute("id"))continue;let M=G(b,n,o),L=a.get(M.signature)||[],j=n.excludeIds?L.filter(V=>!V.getAttribute("id")):L,P=n.maxScoredCandidates,D=P&&j.length>P?x(M,j,P):j;for(let V of D){let{score:Y,breakdown:I}=Qe(b,V,n,o,{candidateCount:j.length});Y>=n.minConfidence&&c.push({newEl:b,oldEl:V,score:Y,breakdown:I})}}if(n.weights.slotMatch>0){let b=jn(t,e,n,o);for(let M of b)c.push(M)}c.sort((b,M)=>M.score-b.score);let w=new Map,m=new Set;for(let{newEl:b,oldEl:M}of c)w.has(b)||m.has(M)||(w.set(b,M),m.add(M));return w}function Lt(e,t,n,o){let r=G(e,n,o),i=G(t,n,o),{score:a,breakdown:s}=Qe(e,t,n,o,{candidateCount:1});return{matches:a>=n.minConfidence,score:a,breakdown:s,newMeta:{signature:r.signature,path:r.path,textHint:r.textHint},oldMeta:{signature:i.signature,path:i.path,textHint:i.textHint}}}function Pt(e={}){let t={...kt,...e,weights:{...kt.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,i)=>It(r,i,t,n,o),computeMatches:(r,i)=>Ct(r,i,t,n,o),explain:(r,i)=>Lt(r,i,t,n),invalidate:r=>Pn(r,n,o),session:()=>{let r=new WeakMap,i=new WeakMap;return{findMatch:(a,s)=>It(a,s,t,r,i),computeMatches:(a,s)=>Ct(a,s,t,r,i),explain:(a,s)=>Lt(a,s,t,r)}},getConfig:()=>({...t})}}function Xe(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
|
|
3
|
-
`;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function jt(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var _n=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,$n=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function _e(e){try{return JSON.parse(e)}catch{return JSON.parse(Dn(e))}}function Dn(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=Xe(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=Xe(e,n+1);if(e[s]==="}"||e[s]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let s=n+1;for(;s<e.length&&e[s]!==r;)e[s]==="\\"&&s++,s++;s>=e.length&&o("unterminated string",n);let c=e.slice(n+1,s);r==="'"&&(c=jt(c)),t+='"'+c+'"',n=s+1;continue}let i=n;for(;i<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[i]);)i++;i===n&&o("unexpected character "+JSON.stringify(r),n);let a=e.slice(n,i);if(a==="true"||a==="false"||a==="null"||_n.test(a)){t+=a,n=i;continue}if($n.test(a)){if(e[Xe(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function _t(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let w=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(w=!0),!w){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let w=s,m=a+1;for(;m<r.length&&r[m]!==w;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:w}),a=m+1;continue}let c=a,A;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let b of w){let M=b.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let w=r[c];for(c++;c<r.length&&r[c]!==w;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;A=r.substring(a,c);let x=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(A)?x=t.NUMBER:A==="true"||A==="false"||A==="null"?x=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(A)&&(x=t.SELECTOR),i.push({type:x,value:A,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING){let c=s.value;s.sourceQuote==="'"&&(c=jt(c)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var $=Symbol("hyper-morph-json-merge:missing"),$t=["id","_id","uuid","key","slug","code","name"];function ge(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Me(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Bn(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function se(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!se(e[n],t[n]))return!1;return!0}if(ge(e)&&ge(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Me(t,o)||!se(e[o],t[o]))return!1;return!0}return!1}function Dt(e,t,n,o){return se(t,n)?t:se(t,e)?n:se(n,e)?t:ge(t)&&ge(n)?Fn(ge(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?Vn(Array.isArray(e)?e:[],t,n,o):n}function Bt(e,t,n,o){return t===$&&n===$?$:t===$?e===$?n:se(n,e)?$:n:n===$?e===$?t:$:Dt(e,t,n,o)}function Fn(e,t,n,o){let r={},i=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let a of i){let s=Bt(Me(e,a)?e[a]:$,Me(t,a)?t[a]:$,Me(n,a)?n[a]:$,o);s!==$&&Bn(r,a,s)}return r}function Un(e){return e===null||typeof e!="object"}function $e(e){return typeof e+":"+String(e)}function qn(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Me(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=$e(i);if(o.has(a))return!1;o.add(a)}}return!0}function Wn(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)ge(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(qn(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!Un(c))return null;let A=$e(c);if(s.has(A))return null;s.add(A)}}return{kind:"self"}}function Vn(e,t,n,o){let r=Wn(e,t,n,o);if(!r)return n;let i=r.kind==="self"?$e:b=>$e(b[r.field]),a=b=>{let M=new Map;for(let L of b)M.set(i(L),L);return M},s=a(e),c=a(t),A=a(n),x=new Map,w=new Set([...s.keys(),...c.keys(),...A.keys()]);for(let b of w){let M=Bt(s.has(b)?s.get(b):$,c.has(b)?c.get(b):$,A.has(b)?A.get(b):$,o);M!==$&&x.set(b,M)}let m=[];for(let b of n){let M=i(b);x.has(M)&&m.push(M)}for(let b=0;b<t.length;b++){let M=i(t[b]);if(!x.has(M)||m.includes(M))continue;let L=0;for(let j=b-1;j>=0;j--){let P=m.indexOf(i(t[j]));if(P!==-1){L=P+1;break}}m.splice(L,0,M)}return m.map(b=>x.get(b))}function et(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...$t]:$t;return Dt(e===void 0?$:e,t,n,{keyCandidates:r})}function tt(e,t,n,o={}){let r=o.parse||_e,i=[],a=(w,m)=>{if(typeof w!="string")return $;try{return r(w)}catch(b){return i.push(`${m} side is not valid JSON (${b.message})`),$}},s=a(t,"local"),c=a(n,"remote");if(s===$)return{text:n,warnings:i};if(c===$)return{text:t,warnings:i};let A=a(e,"base"),x=et(A===$?void 0:A,s,c,o);return se(x,c)?{text:n,warnings:i}:se(x,s)?{text:t,warnings:i}:{text:JSON.stringify(x,null,2),warnings:i}}var nt=function(){"use strict";let e=()=>{},t='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function n(p){if(!(p instanceof Element))return!1;if(p.matches(t))return!0;if(p.tagName==="LINK"||p.tagName==="SCRIPT"){let O=p.getAttribute("src")||p.getAttribute("href")||"";if(O.startsWith("chrome-extension://")||O.startsWith("moz-extension://")||O.startsWith("safari-web-extension://"))return!0}return!1}function o(p){return p instanceof Element?p.closest(t)?!0:n(p):!1}let r=Pt({shouldIgnore:o});function i(p,O,v){if(v){let k=v.identityOf(p);if(k&&!v.disabled.has(k.key))return"hm-merge:"+k.key}if(O!=="smart")return p.outerHTML;let N=p.getAttribute("src"),R=p.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${R}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${R}:${N}`}else{let k=p.textContent.trim(),h=5381;for(let E=0;E<k.length;E++)h=(h<<5)+h^k.charCodeAt(E);return`inline:${R}:${Math.abs(h).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(p){return p instanceof Element&&p.tagName==="SCRIPT"&&p.namespaceURI===a}function c(p){let O=document.createElement("div");O.innerHTML="<script><\/script>";let v=O.firstChild;for(let N of p.attributes)v.setAttribute(N.name,N.value);return v.textContent=p.textContent,v}function A(p){if(s(p))return c(p);if(p instanceof Element)for(let O of p.querySelectorAll("script"))s(O)&&O.replaceWith(c(O));return p}function x(p){let O=(p.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return O==="application/json"||O.endsWith("+json")}let w={match:p=>p.hasAttribute("merge"),identity:p=>p.getAttribute("merge")};function m(p,O,v){if(v.merge===!1)return null;let N=[w,...v.mergeTags||[]],R=new WeakMap,k=f=>{if(R.has(f))return R.get(f);let y=null;if(s(f)&&!f.getAttribute("src")&&!o(f)){let S=f;for(let T=0;T<N.length;T++)if(N[T].match(S)){if(!x(S))console.warn("[hyper-morph] merge ignored: script type is not JSON",S);else{let C=N[T].identity(S);C!=null&&C!==""&&(y={key:T+":"+C,raw:C,recognizer:N[T]})}break}}return R.set(f,y),y},h=new Set,E=f=>{let y=new Map,S=T=>{let C=k(T);C&&(y.has(C.key)?(h.add(C.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${C.raw}"`)):y.set(C.key,T))};s(f)&&S(f);for(let T of f.querySelectorAll("script"))S(T);return y},d=E(p),u=E(O.__hyperMorphRoot||O);if(d.size===0&&u.size===0)return null;let l=null;return{identityOf:k,disabled:h,oldByKey:d,newByKey:u,baseTexts:()=>{if(l)return l;l=new Map;let f=v.mergeBase;if(!f)return l;let y;typeof f=="string"?y=new DOMParser().parseFromString(f,"text/html").documentElement:f instanceof Document?y=f.documentElement:y=f;let S=T=>{let C=k(T);C&&!l.has(C.key)&&l.set(C.key,T.textContent)};s(y)&&S(y);for(let T of y.querySelectorAll("script"))S(T);return l}}}function b(p,O,v){let N=p.merge;if(!N)return!1;let R=N.identityOf(O);if(!R||N.disabled.has(R.key))return!1;let k=N.identityOf(v);if(!k||k.key!==R.key)return!1;let h=O,E=v,d=E.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=tt(N.baseTexts().get(R.key),h.textContent,E.textContent,{parse:R.recognizer.parse,keyCandidates:d?d.split(/[\s,]+/).filter(Boolean):void 0});for(let g of l)console.warn(`[hyper-morph] merge "${R.raw}": ${g}`);return h.textContent!==u&&(h.textContent=u),!0}let M={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},L={computeMatches(p,O){let{computeMatches:v}=r.session();return v(p,O)}};function j(p,O,v={}){p=on(p);let N=xt(O),R=rn(p,N,v),k=R.scripts.handle?new Set(Array.from(p.querySelectorAll("script")).map(u=>i(u,R.scripts.matchMode,R.merge))):null,h=V(R),E=U(R,p,N,u=>u.morphStyle==="innerHTML"?(I(u,p,N),Array.from(p.childNodes)):D(u,p,N)),d=u=>{h&&Y(R,h),P(R);let l=k?qe(u,k,R):[];return l.length>0?Promise.all(l).then(()=>u):u};return E instanceof Promise?E.then(d):d(E)}function P(p){for(let O of Array.from(p.pantry.childNodes))p.callbacks.beforeNodeRemoved(O)!==!1&&p.callbacks.afterNodeRemoved(O);p.pantry.remove()}function D(p,O,v){let N=xt(O);return I(p,N,v,O,O.nextSibling),Array.from(N.childNodes)}function V(p){if(!p.config.restoreFocus)return null;let O=document.activeElement;if(!(O instanceof HTMLInputElement||O instanceof HTMLTextAreaElement))return null;let{id:v,selectionStart:N,selectionEnd:R}=O;return{element:O,id:v,selectionStart:N,selectionEnd:R}}function Y(p,O){let v=O.element;if(O.id&&O.id!==document.activeElement?.getAttribute("id")&&(v=p.target.querySelector(`[id="${CSS.escape(O.id)}"]`),v?.focus()),v&&!v.selectionEnd&&O.selectionEnd!=null)try{v.setSelectionRange(O.selectionStart,O.selectionEnd)}catch{}}let I=function(){function p(u,l,g,f=null,y=null){l instanceof HTMLTemplateElement&&g instanceof HTMLTemplateElement&&(l=l.content,g=g.content),f||=l.firstChild;for(let S of g.childNodes){if(n(S))continue;if(f&&f!=y){let C=v(u,S,f,y);if(C){C!==f&&R(u,f,C),K(C,S,u),f=C.nextSibling;continue}}if(S instanceof Element){let C=S.getAttribute("id");if(u.persistentIds.has(C)){let _=k(l,C,f,u);K(_,S,u),f=_.nextSibling;continue}if(!u.idMap.has(S)){let _=u.hyperMatches.get(S);if(_&&!u.idMap.has(_)&&!d(_,l)){E(l,_,f),K(_,S,u),f=_.nextSibling;continue}}}let T=O(l,S,f,u);T&&(f=T.nextSibling)}for(;f&&f!=y;){let S=f;f=f.nextSibling,n(S)||N(u,S)}}function O(u,l,g,f){if(f.callbacks.beforeNodeAdded(l)===!1)return null;if(f.idMap.has(l)){let y=l,S=document.createElementNS(y.namespaceURI,y.localName);return u.insertBefore(S,g),K(S,l,f),f.callbacks.afterNodeAdded(S),S}else{let y=A(document.importNode(l,!0));return u.insertBefore(y,g),f.callbacks.afterNodeAdded(y),y}}let v=function(){function u(f,y,S,T){let C=y instanceof Element&&!f.idMap.has(y)?f.hyperMatches.get(y):null,_=null,q=y.nextSibling,Z=0,H=S;for(;H&&H!=T;){if(n(H)){H=H.nextSibling;continue}if(g(H,y)){if(l(f,H,y)||H===C&&!f.idMap.has(H))return H;if(_===null){let z=H instanceof Element&&f.hyperMatchedOldElements.has(H);!f.idMap.has(H)&&!z&&(_=H)}}if(_===null&&q&&g(H,q)&&(Z++,q=q.nextSibling,Z>=2&&(_=void 0)),f.activeElementAndParents.includes(H))break;H=H.nextSibling}return _||null}function l(f,y,S){let T=f.idMap.get(y),C=f.idMap.get(S);if(!C||!T)return!1;for(let _ of T)if(C.has(_))return!0;return!1}function g(f,y){let S=f,T=y;return S.nodeType===T.nodeType&&S.tagName===T.tagName&&(!S.getAttribute?.("id")||S.getAttribute?.("id")===T.getAttribute?.("id"))}return u}();function N(u,l){let g=l instanceof Element&&u.hyperMatchedOldElements.has(l)&&!u.idMap.has(l);if(u.idMap.has(l)||g)E(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function R(u,l,g){let f=l;for(;f&&f!==g;){let y=f;f=f.nextSibling,n(y)||N(u,y)}return f}function k(u,l,g,f){let y=f.target.getAttribute?.("id")===l&&f.target||f.target.querySelector(`[id="${CSS.escape(l)}"]`)||f.pantry.querySelector(`[id="${CSS.escape(l)}"]`);return h(y,f),E(u,y,g),y}function h(u,l){let g=u.getAttribute("id");for(;u=u.parentNode;){let f=l.idMap.get(u);f&&(f.delete(g),f.size||l.idMap.delete(u))}}function E(u,l,g){if(u.moveBefore)try{u.moveBefore(l,g)}catch{u.insertBefore(l,g)}else u.insertBefore(l,g)}function d(u,l){let g=l instanceof Element?l:l.realParentNode;return!!g&&u.contains(g)}return p}(),K=function(){function p(h,E,d){return d.ignoreActive&&h===document.activeElement?null:(d.callbacks.beforeNodeMorphed(h,E)===!1||(h instanceof HTMLHeadElement&&d.head.ignore||(h instanceof HTMLHeadElement&&d.head.style!=="morph"?te(h,E,d):(O(h,E,d),b(d,h,E)||k(h,d)||I(d,h,E))),d.callbacks.afterNodeMorphed(h,E)),h)}function O(h,E,d){let u=E.nodeType;if(u===1){let l=h,g=E,f=l.attributes,y=g.attributes;for(let S of y)R(S.name,l,"update",d)||l.getAttribute(S.name)!==S.value&&l.setAttribute(S.name,S.value);for(let S=f.length-1;0<=S;S--){let T=f[S];if(T&&!g.hasAttribute(T.name)){if(R(T.name,l,"remove",d))continue;l.removeAttribute(T.name)}}k(l,d)||v(l,g,d)}(u===8||u===3)&&h.nodeValue!==E.nodeValue&&(h.nodeValue=E.nodeValue)}function v(h,E,d){if(h instanceof HTMLInputElement&&E instanceof HTMLInputElement&&E.type!=="file"){let u=E.value,l=h.value;N(h,E,"checked",d),N(h,E,"disabled",d),d.formStateSync==="property"&&h.indeterminate!==E.indeterminate&&(h.indeterminate=E.indeterminate),d.formStateSync==="property"?l!==u&&(R("value",h,"update",d)||(h.value=u)):E.hasAttribute("value")?l!==u&&(R("value",h,"update",d)||(h.setAttribute("value",u),h.value=u)):R("value",h,"remove",d)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&E instanceof HTMLOptionElement)N(h,E,"selected",d);else if(h instanceof HTMLTextAreaElement&&E instanceof HTMLTextAreaElement){let u=E.value,l=h.value;if(R("value",h,"update",d)||(u!==l&&(h.value=u),d.formStateSync==="property"))return;h.firstChild&&h.firstChild.nodeValue!==u&&(h.firstChild.nodeValue=u)}}function N(h,E,d,u){let l=E[d],g=h[d];if(l!==g){let f=R(d,h,"update",u);if(f||(h[d]=E[d]),u.formStateSync==="property")return;l?f||h.setAttribute(d,""):R(d,h,"remove",u)||h.removeAttribute(d)}}function R(h,E,d,u){return h==="value"&&u.ignoreActiveValue&&E===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,E,d)===!1}function k(h,E){return!!E.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return p}();function U(p,O,v,N){if(p.head.block){let R=O.querySelector("head"),k=v.querySelector("head");if(R&&k){let h=te(R,k,p);return Promise.all(h).then(()=>(p.head.block=!1,p.head.ignore=!0,N(p)))}}return N(p)}function ee(p){return p.tagName==="SCRIPT"?!!p.getAttribute("src"):p.tagName==="LINK"?(p.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!p.getAttribute("href"):!1}function te(p,O,v){let N=[],R=[],k=[],h=[],E=v.scripts.matchMode,d=g=>{if(g.tagName==="SCRIPT")return i(g,E,v.merge);if(g.tagName==="LINK"&&E==="smart"){let f=g.getAttribute("href");if(f)try{let y=new URL(f,window.location.href);return`link:${g.getAttribute("rel")||""}:${y.origin}${y.pathname}${y.search}`}catch{}}return g.outerHTML},u=new Map;for(let g of O.children){if(n(g))continue;let f=d(g),y=u.get(f);y||(y=[],u.set(f,y)),y.push(g)}for(let g of p.children){let f=d(g),y=u.get(f),S=!!(y&&y.length),T=v.head.shouldReAppend(g),C=v.head.shouldPreserve(g);if(S||C)if(T)R.push(g);else{if(y&&y.length){let _=y.pop();y.length||u.delete(f),b(v,g,_)}k.push(g)}else v.head.style==="append"?T&&(R.push(g),h.push(g)):v.head.shouldRemove(g)!==!1&&!n(g)&&R.push(g)}for(let g of u.values())h.push(...g);let l=[];for(let g of h){let f=document.createRange().createContextualFragment(g.outerHTML).firstChild;if(v.callbacks.beforeNodeAdded(f)!==!1){if(f instanceof Element&&ee(f)){let y,S=new Promise(function(T){y=T});f.addEventListener("load",function(){y()}),f.addEventListener("error",function(){y()}),l.push(S)}p.appendChild(f),v.callbacks.afterNodeAdded(f),N.push(f)}}for(let g of R)v.callbacks.beforeNodeRemoved(g)!==!1&&(p.removeChild(g),v.callbacks.afterNodeRemoved(g));return v.head.afterHeadMorphed(p,{added:N,kept:k,removed:R}),l}function qe(p,O,v){if(!v.scripts.handle)return[];let N=[],R=[],k=[],h=[],E=v.scripts.matchMode,d=[];for(let l of p)if(l instanceof Element){s(l)&&d.push(l);for(let g of l.querySelectorAll("script"))s(g)&&d.push(g)}for(let l of d){if(l.closest("head")||o(l))continue;let g=i(l,E,v.merge),f=O.has(g),y=v.scripts.shouldPreserve(l),S=v.scripts.shouldReAppend(l);f||y?S?(R.push(l),h.push(l)):k.push(l):h.push(l)}let u=[];for(let l of h){if(v.callbacks.beforeNodeAdded(l)===!1)continue;let g=document.createElement("script");for(let f of l.attributes)g.setAttribute(f.name,f.value);if(g.textContent=l.textContent,g.src){let f,y=new Promise(function(S){f=S});g.addEventListener("load",function(){f()}),g.addEventListener("error",function(){f()}),u.push(y)}l.replaceWith(g),v.callbacks.afterNodeAdded(g),N.push(g)}return v.scripts.afterScriptsHandled(v.target,{added:N,kept:k,removed:R}),u}let rn=function(){function p(d,u,l){let{persistentIds:g,idMap:f}=h(d,u),y=L.computeMatches(d,u);if(typeof l.key=="function"){let q=new Map,Z=new Set,H=B=>{let F=l.key(B);F!=null&&(q.has(F)?Z.add(F):q.set(F,B))};d instanceof Element&&H(d);for(let B of d.querySelectorAll("*"))H(B);for(let B of Z)q.delete(B);let z=new Map;for(let[B,F]of y)z.set(F,B);let ce=u.__hyperMorphRoot||u,ne=new Map,wt=new Set,vt=B=>{let F=l.key(B);F!=null&&(ne.has(F)?wt.add(F):ne.set(F,B))};ce instanceof Element&&vt(ce);for(let B of ce.querySelectorAll("*"))vt(B);for(let B of wt)ne.delete(B);for(let[B,F]of ne){let he=q.get(B);if(!he||he.tagName!==F.tagName)continue;let We=z.get(he);We&&We!==F&&y.delete(We);let Ve=y.get(F);Ve&&Ve!==he&&z.delete(Ve),y.set(F,he),z.set(he,F)}}let S=O(l),T=m(d,u,S.scripts);if(T){let q=new Map;for(let[Z,H]of y)q.set(H,Z);for(let[Z,H]of T.newByKey){if(T.disabled.has(Z))continue;let z=T.oldByKey.get(Z);if(!z)continue;let ce=q.get(z);ce&&ce!==H&&y.delete(ce);let ne=y.get(H);ne&&ne!==z&&q.delete(ne),y.set(H,z),q.set(z,H)}}let C=new Set;for(let q of y.values())C.add(q);let _=S.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(_))throw new Error(`Do not understand how to morph style ${_}`);return{target:d,newContent:u,config:S,morphStyle:_,ignoreActive:S.ignoreActive,ignoreActiveValue:S.ignoreActiveValue,restoreFocus:S.restoreFocus,formStateSync:S.formStateSync||"attribute",idMap:f,persistentIds:g,hyperMatches:y,hyperMatchedOldElements:C,merge:T,pantry:v(),activeElementAndParents:N(d),callbacks:S.callbacks,head:S.head,scripts:S.scripts}}function O(d){let u=Object.assign({},M);return Object.assign(u,d),u.callbacks=Object.assign({},M.callbacks,d.callbacks),u.head=Object.assign({},M.head,d.head),u.scripts=Object.assign({},M.scripts,d.scripts),u}function v(){let d=document.createElement("div");return d.hidden=!0,document.body.insertAdjacentElement("afterend",d),d}function N(d){let u=[],l=document.activeElement;if(l?.tagName!=="BODY"&&d.contains(l))for(;l&&(u.push(l),l!==d);)l=l.parentElement;return u}function R(d){let u=Array.from(d.querySelectorAll("[id]"));return d.getAttribute?.("id")&&u.push(d),u}function k(d,u,l,g){for(let f of g){let y=f.getAttribute("id");if(u.has(y)){let S=f;for(;S;){let T=d.get(S);if(T==null&&(T=new Set,d.set(S,T)),T.add(y),S===l)break;S=S.parentElement}}}}function h(d,u){let l=R(d),g=R(u),f=E(l,g),y=new Map;k(y,f,d,l);let S=u.__hyperMorphRoot||u;return k(y,f,S,g),{persistentIds:f,idMap:y}}function E(d,u){let l=new Set,g=new Map;for(let y of d){let S=y.getAttribute("id");g.has(S)?l.add(S):g.set(S,y.tagName)}let f=new Set;for(let y of u){let S=y.getAttribute("id");f.has(S)?l.add(S):g.get(S)===y.tagName&&f.add(S)}for(let y of l)f.delete(y);return f}return p}(),{normalizeElement:on,normalizeParent:xt}=function(){let p=new WeakSet;function O(h){return h instanceof Document?h.documentElement:h}function v(h){if(h==null)return document.createElement("div");if(typeof h=="string")return v(k(h));if(p.has(h))return h;if(h instanceof Node){if(h.parentNode)return new N(h);{let E=document.createElement("div");return E.append(h),E}}else{let E=document.createElement("div");for(let d of[...h])E.append(d);return E}}class N{constructor(E){this.originalNode=E,this.realParentNode=E.parentNode,this.previousSibling=E.previousSibling,this.nextSibling=E.nextSibling}get childNodes(){let E=[],d=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;d&&d!=this.nextSibling;)E.push(d),d=d.nextSibling;return E}querySelectorAll(E){return this.childNodes.reduce((d,u)=>{if(u instanceof Element){u.matches(E)&&d.push(u);let l=u.querySelectorAll(E);for(let g=0;g<l.length;g++)d.push(l[g])}return d},[])}insertBefore(E,d){return this.realParentNode.insertBefore(E,d)}moveBefore(E,d){return this.realParentNode.moveBefore(E,d)}get __hyperMorphRoot(){return this.originalNode}}function R(h){let E=g=>`<${g}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,d=h.replace(/<!--[\s\S]*?-->/g,"");for(let g of["script","style","textarea","title"])d=d.replace(new RegExp(`${E(g)}[\\s\\S]*?</${g}\\s*>`,"gi"),"");let u=new RegExp(`${E("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=d,d=d.replace(u,"");while(d!==l);return d}function k(h){let E=new DOMParser,d=R(h);if(d.match(/<\/html>/)||d.match(/<\/head>/)||d.match(/<\/body>/)){let u=E.parseFromString(h,"text/html");if(d.match(/<\/html>/))return p.add(u),u;{let l=u.firstChild;return l&&p.add(l),l}}else{let l=E.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return p.add(l),l}}return{normalizeElement:O,normalizeParent:v}}();return{morph:j,defaults:M,mergeJson:et,mergeScriptText:tt,parseJsonRelaxed:_e,parseRulesRelaxed:_t}}();var Lr=nt.morph,Hr=nt.defaults;var Ft=nt;function rt(e,t,{onWidgetRemoved:n}={}){Ft.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Pe.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var zn="hha:upgrade-check:";function Q(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function ot(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ut(e,t){let n=ot(e),o=ot(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let a=n[i]||0,s=o[i]||0;if(a!==s)return a>s}return!1}function Jn(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Gn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function st({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(m=>fetch(m)),r=r??Date.now(),!t)return null;let a=Q(t,"hyper-source");if(!a)return null;let s=Q(t,"hyper-version"),c;try{c=new URL(a,n?n.href:void 0)}catch{return null}if(n&&c.origin===n.origin&&c.pathname===n.pathname)return null;let A=`${zn}${c.href}:${s||"none"}`,x,w=e?null:Jn(A);if(w&&typeof w.checkedAt=="number"&&r-w.checkedAt<i)x=w.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let b=await m.text(),M=new DOMParser().parseFromString(b,"text/html");x=Q(M,"hyper-version")}catch{x=null}Gn(A,{checkedAt:r,sourceVersion:x})}return x?{available:Ut(x,s||"0.0.0"),currentVersion:s,sourceVersion:x,sourceUrl:c.href}:null}var De=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],it=new Set(De),qt=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Wt=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Be={};ze(Be,{EmptyListInsert:()=>we,MAX_RULE_DEPTH:()=>be,MaxRuleDepthExceeded:()=>ue,RuleTargetReadOnly:()=>ve,RulesParseError:()=>ye,ShapeMismatch:()=>xe,UnknownRulesVersion:()=>le});var ye=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},le=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},be=20,ue=class extends Error{constructor(t){super(`rule depth exceeded ${be} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},xe=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},we=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},ve=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function X(e,t,n,o={}){return at(e,t,n,{depth:0,path:[]},o)}function at(e,t,n,o,r){if(o.depth>be)throw new ue(o.path);if(typeof n=="string")return Yn(e,t,n,r);if(Array.isArray(n)){let[i,a]=n;return e.find(t,i,r).map((c,A)=>at(e,c,a,{depth:o.depth+1,path:[...o.path,A]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[a,s]of Object.entries(n))i[a]=at(e,t,s,{depth:o.depth+1,path:[...o.path,a]},r);return i}return null}function Yn(e,t,n,o){if(n.endsWith("[]")){let a=n.slice(0,-2);return e.find(t,a,o).map(s=>e.text(s))}if(n.startsWith("@"))return Vt(e,t,n.slice(1));let r=oe(n);if(r!==-1){let a=n.slice(0,r),s=n.slice(r+1),c=a?e.find(t,a,o):[t];return c.length===0?null:Vt(e,c[0],s)}if(n===".")return e.text(t);let i=e.find(t,n,o);return i.length===0?null:e.text(i[0])}function Vt(e,t,n){if(it.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Zn(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Qn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Xn={find(e,t,n={}){let o=Qn(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Zn(s)));let i=[];n.skip&&i.push(n.skip);let a=n.templateAttr===null?null:n.templateAttr||"cms-template";if(a&&i.push("["+a+"]"),i.length){let s=i.join(", ");r=r.filter(c=>!c.closest||!c.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},W=Xn;function ct(e){try{return JSON.parse(e)}catch(t){throw new ye(`Invalid strict JSON: ${t.message}`,t)}}function fe(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let w=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(w=!0),!w){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let w=s,m=a+1;for(;m<r.length&&r[m]!==w;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:w}),a=m+1;continue}let c=a,A;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let b of w){let M=b.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let w=r[c];for(c++;c<r.length&&r[c]!==w;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;A=r.substring(a,c);let x=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(A)?x=t.NUMBER:A==="true"||A==="false"||A==="null"?x=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(A)&&(x=t.SELECTOR),i.push({type:x,value:A,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let c=s.value;s.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(A,x)=>x.length%2===0?x+'\\"':A)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new ye("Invalid extraction rules syntax: "+r.message,r)}}var lt="1",Kt=/^[a-zA-Z0-9_-]+$/;function Ae(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Kt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Kt})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],a=e.attr(i,"data-rules-version");if(a!==lt)throw new le(a);return{rules:fe(e.text(i)),tagNode:i}}var er="script[data-rules-name]";function zt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function Oe(e,t){let n=e.find(t,er,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=zt(e.attr(i,"data-rules-name"));if(!a)continue;if(o.has(a)){console.warn(`hyper-html-api: duplicate rules tag name "${a}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==lt)throw new le(s);o.add(a),r.push({name:a,rules:fe(e.text(i))})}return r}function Fe(e,t){let n={};for(let{name:o,rules:r}of Oe(e,t))n[o]=X(e,t,r);return n}function ut(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Fe(W,t),version:Q(n,"hyper-version")}}var Se=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},Re=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},ie=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Te=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var Jt="text/hyper-upgrade";function ft(e,t){let n=e.find(t,`script[type="${Jt}"]`);if(n.length===0)return null;if(n.length>1)throw new Te(n.length);return e.text(n[0])||null}var tr=new Function("url","return import(url)");async function dt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await tr(n)}catch(r){throw new ie(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new ie("transform must `export default` a function");return o.default}var nr=.5;function ht(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(I=>e.remove(I));return}let A=r.length>c.length,x=c[0]||null;if(A&&!x&&(x=ir(e,t,n,s),!x))throw new we(i.path);let w=c.map(I=>rr(e,I,o,s)),m=null;if(x){m=e.clone(x),s.templateAttr&&e.removeAttr(m,s.templateAttr);let I=e.stripIds(m);I>0&&console.warn(`[hyper-html-api] stripped ${I} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let b=or(r,w,o),M=c[0]||x,L=e.parent(M),j=c.length>0?Yt(e,L,M):0,P=ar(e,c),D=new Set,V=[],Y=r.map((I,K)=>{let U=b[K];if(U>=0)return D.add(U),V.push(!1),c[U];V.push(!0);let ee=e.clone(m);return e.stripIds(ee),ee});if(c.forEach((I,K)=>{D.has(K)||e.remove(I)}),P){Y.forEach((I,K)=>{let U=j+K;e.children(L).findIndex(qe=>e.sameNode(qe,I))!==U&&e.insertAt(L,I,U)}),Gt(e,Y,o,r,i,a,s);return}cr(e,Y,V,L,j),Gt(e,Y,o,r,i,a,s)}function Gt(e,t,n,o,r,i,a){t.forEach((s,c)=>{if(n===null){let A=o[c],x=A==null?"":String(A);e.text(s)!==x&&e.text(s,x)}else{let A=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},a);A&&A!==s&&(t[c]=A)}})}function rr(e,t,n,o){return n===null?e.text(t):X(e,t,n,o)}function or(e,t,n){let o=new Array(e.length).fill(-1),r=new Set;return e.forEach((i,a)=>{let s=-1,c=-1;t.forEach((A,x)=>{if(r.has(x))return;let w=sr(i,A,n),m=w===c&&s>=0?Math.abs(x-a)<Math.abs(s-a):!1;(w>c||m)&&(c=w,s=x)}),c>=nr&&(o[a]=s,r.add(s))}),o}function sr(e,t,n){if(n===null)return e===t?1:0;let o=Object.keys(n||{});if(o.length===0)return 0;let r=0;for(let i of o)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&r++;return r/o.length}function Yt(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function ir(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let a of i)if(e.attr(a,o.templateAttr)!=null)return a;r=e.parent(r)}return null}function ar(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let a=o.findIndex(s=>e.sameNode(s,i));if(a===-1)return!1;r.push(a)}return r.sort((i,a)=>i-a),r[r.length-1]-r[0]===r.length-1}function cr(e,t,n,o,r){let i=null,a=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let c=i?e.parent(i):o;if(!c)continue;let A=i?Yt(e,c,i)+1:a++;e.insertAt(c,t[s],A),i=t[s]}}var Zt=new Set(["checked","selected","disabled","readOnly","paused"]);function ae(e,t,n,o,r={}){let i=[];if(pt(n,o,[],i),i.length)throw new xe(i);Ue(e,t,n,o,{depth:0,path:[]},r)}function Ue(e,t,n,o,r,i={}){if(r.depth>be)throw new ue(r.path);if(o===void 0)return t;if(typeof n=="string")return lr(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return ht(e,t,a,s,o,r,Ue,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=Ue(e,t,s,o==null?o:o[a],{depth:r.depth+1,path:[...r.path,a]},i);c&&c!==t&&(t=c)}return t}return t}function lr(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return ht(e,t,c,null,o,r,Ue,i),t}if(n.startsWith("@"))return Qt(e,t,n.slice(1),o);let a=oe(n);if(a!==-1){let c=n.slice(0,a),A=n.slice(a+1),x=c?e.find(t,c,i):[t];return x.length===0||Qt(e,x[0],A,o),t}if(n===".")return e.text(t,o==null?"":String(o)),t;let s=e.find(t,n,i);return s.length===0||e.text(s[0],o==null?"":String(o)),t}function Qt(e,t,n,o){if(Wt.has(n))throw new ve(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return qt.has(n)?(e.prop(t,n,ur(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function ur(e,t){return t==null?Zt.has(e)?!1:"":Zt.has(e)?!!t:t}function pt(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:ke([...n,i]),expected:"scalar",got:Ne(r)})}):o.push({path:ke(n),expected:"array",got:Ne(t)});return}t!==null&&typeof t=="object"&&o.push({path:ke(n),expected:"scalar",got:Ne(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:ke(n),expected:"array",got:Ne(t)});return}let r=e[1];t.forEach((i,a)=>pt(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:ke(n),expected:"object",got:Ne(t)});return}for(let[r,i]of Object.entries(e))pt(i,t[r],[...n,r],o)}}}function Ne(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function ke(e){return e.join(".")}function Ie(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=mt(t,e,n);return gt(t,e,n),{data:o,summary:n}}function mt(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>mt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=mt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function gt(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?gt(e[r],t[r],n):n.discarded+=de(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>gt(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=de(t))}}function de(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+de(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+de(n),0):1}function yt(e,t,n){let o=Oe(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},a=new Set;for(let{name:s,rules:c}of o){if(a.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:A,summary:x}=Ie(n[s],c);ae(e,t,c,A),i[s]=x,r.carriedOver+=x.carriedOver,r.discarded+=x.discarded,r.listItems+=x.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=de(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function bt({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(P=>fetch(P)),!o)throw new Error("upgrade.run requires a document context");if(e=e||Q(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let a=new URL(e,r?r.href:void 0);n=n!==void 0?n:Q(o,"hyper-version"),t=t||Fe(W,o);let s;try{s=await i(a.href)}catch(P){throw new Se(a.href,P)}if(!s.ok)throw new Se(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),A=new DOMParser().parseFromString(c,"text/html"),x=Q(A,"hyper-version"),w=t,m=!1,b=ft(W,A);if(b){let D=await(await dt(b))(w,{fromVersion:n,toVersion:x});if(!D||typeof D!="object"||Array.isArray(D))throw new ie("transform must return a plain object map of { rulesName: data }");w=D,m=!0}let{totals:M,byName:L,rulesTagCount:j}=yt(W,A,w);if(j===0&&Object.keys(w).length>0)throw new Re(a.href);return{html:fr(A),fromVersion:n,toVersion:x,summary:{transformApplied:m,totals:M,byName:L}}}function fr(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
3
|
+
`;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function jt(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var _n=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,$n=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function _e(e){try{return JSON.parse(e)}catch{return JSON.parse(Dn(e))}}function Dn(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=Xe(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=Xe(e,n+1);if(e[s]==="}"||e[s]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let s=n+1;for(;s<e.length&&e[s]!==r;)e[s]==="\\"&&s++,s++;s>=e.length&&o("unterminated string",n);let c=e.slice(n+1,s);r==="'"&&(c=jt(c)),t+='"'+c+'"',n=s+1;continue}let i=n;for(;i<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[i]);)i++;i===n&&o("unexpected character "+JSON.stringify(r),n);let a=e.slice(n,i);if(a==="true"||a==="false"||a==="null"||_n.test(a)){t+=a,n=i;continue}if($n.test(a)){if(e[Xe(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function _t(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let w=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(w=!0),!w){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let w=s,m=a+1;for(;m<r.length&&r[m]!==w;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:w}),a=m+1;continue}let c=a,A;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let b of w){let M=b.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let w=r[c];for(c++;c<r.length&&r[c]!==w;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;A=r.substring(a,c);let x=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(A)?x=t.NUMBER:A==="true"||A==="false"||A==="null"?x=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(A)&&(x=t.SELECTOR),i.push({type:x,value:A,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING){let c=s.value;s.sourceQuote==="'"&&(c=jt(c)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var $=Symbol("hyper-morph-json-merge:missing"),$t=["id","_id","uuid","key","slug","code","name"];function ge(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Me(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Bn(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function se(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!se(e[n],t[n]))return!1;return!0}if(ge(e)&&ge(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Me(t,o)||!se(e[o],t[o]))return!1;return!0}return!1}function Dt(e,t,n,o){return se(t,n)?t:se(t,e)?n:se(n,e)?t:ge(t)&&ge(n)?Fn(ge(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?Vn(Array.isArray(e)?e:[],t,n,o):n}function Bt(e,t,n,o){return t===$&&n===$?$:t===$?e===$?n:se(n,e)?$:n:n===$?e===$?t:$:Dt(e,t,n,o)}function Fn(e,t,n,o){let r={},i=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let a of i){let s=Bt(Me(e,a)?e[a]:$,Me(t,a)?t[a]:$,Me(n,a)?n[a]:$,o);s!==$&&Bn(r,a,s)}return r}function Un(e){return e===null||typeof e!="object"}function $e(e){return typeof e+":"+String(e)}function qn(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Me(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=$e(i);if(o.has(a))return!1;o.add(a)}}return!0}function Wn(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)ge(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(qn(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!Un(c))return null;let A=$e(c);if(s.has(A))return null;s.add(A)}}return{kind:"self"}}function Vn(e,t,n,o){let r=Wn(e,t,n,o);if(!r)return n;let i=r.kind==="self"?$e:b=>$e(b[r.field]),a=b=>{let M=new Map;for(let L of b)M.set(i(L),L);return M},s=a(e),c=a(t),A=a(n),x=new Map,w=new Set([...s.keys(),...c.keys(),...A.keys()]);for(let b of w){let M=Bt(s.has(b)?s.get(b):$,c.has(b)?c.get(b):$,A.has(b)?A.get(b):$,o);M!==$&&x.set(b,M)}let m=[];for(let b of n){let M=i(b);x.has(M)&&m.push(M)}for(let b=0;b<t.length;b++){let M=i(t[b]);if(!x.has(M)||m.includes(M))continue;let L=0;for(let j=b-1;j>=0;j--){let P=m.indexOf(i(t[j]));if(P!==-1){L=P+1;break}}m.splice(L,0,M)}return m.map(b=>x.get(b))}function et(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...$t]:$t;return Dt(e===void 0?$:e,t,n,{keyCandidates:r})}function tt(e,t,n,o={}){let r=o.parse||_e,i=[],a=(w,m)=>{if(typeof w!="string")return $;try{return r(w)}catch(b){return i.push(`${m} side is not valid JSON (${b.message})`),$}},s=a(t,"local"),c=a(n,"remote");if(s===$)return{text:n,warnings:i};if(c===$)return{text:t,warnings:i};let A=a(e,"base"),x=et(A===$?void 0:A,s,c,o);return se(x,c)?{text:n,warnings:i}:se(x,s)?{text:t,warnings:i}:{text:JSON.stringify(x,null,2),warnings:i}}var nt=function(){"use strict";let e=()=>{},t='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function n(p){if(!(p instanceof Element))return!1;if(p.matches(t))return!0;if(p.tagName==="LINK"||p.tagName==="SCRIPT"){let O=p.getAttribute("src")||p.getAttribute("href")||"";if(O.startsWith("chrome-extension://")||O.startsWith("moz-extension://")||O.startsWith("safari-web-extension://"))return!0}return!1}function o(p){return p instanceof Element?p.closest(t)?!0:n(p):!1}let r=Pt({shouldIgnore:o});function i(p,O,v){if(v){let k=v.identityOf(p);if(k&&!v.disabled.has(k.key))return"hm-merge:"+k.key}if(O!=="smart")return p.outerHTML;let N=p.getAttribute("src"),R=p.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${R}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${R}:${N}`}else{let k=p.textContent.trim(),h=5381;for(let E=0;E<k.length;E++)h=(h<<5)+h^k.charCodeAt(E);return`inline:${R}:${Math.abs(h).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(p){return p instanceof Element&&p.tagName==="SCRIPT"&&p.namespaceURI===a}function c(p){let O=document.createElement("div");O.innerHTML="<script><\/script>";let v=O.firstChild;for(let N of p.attributes)v.setAttribute(N.name,N.value);return v.textContent=p.textContent,v}function A(p){if(s(p))return c(p);if(p instanceof Element)for(let O of p.querySelectorAll("script"))s(O)&&O.replaceWith(c(O));return p}function x(p){let O=(p.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return O==="application/json"||O.endsWith("+json")}let w={match:p=>p.hasAttribute("merge"),identity:p=>p.getAttribute("merge")};function m(p,O,v){if(v.merge===!1)return null;let N=[w,...v.mergeTags||[]],R=new WeakMap,k=f=>{if(R.has(f))return R.get(f);let y=null;if(s(f)&&!f.getAttribute("src")&&!o(f)){let S=f;for(let T=0;T<N.length;T++)if(N[T].match(S)){if(!x(S))console.warn("[hyper-morph] merge ignored: script type is not JSON",S);else{let C=N[T].identity(S);C!=null&&C!==""&&(y={key:T+":"+C,raw:C,recognizer:N[T]})}break}}return R.set(f,y),y},h=new Set,E=f=>{let y=new Map,S=T=>{let C=k(T);C&&(y.has(C.key)?(h.add(C.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${C.raw}"`)):y.set(C.key,T))};s(f)&&S(f);for(let T of f.querySelectorAll("script"))S(T);return y},d=E(p),u=E(O.__hyperMorphRoot||O);if(d.size===0&&u.size===0)return null;let l=null;return{identityOf:k,disabled:h,oldByKey:d,newByKey:u,baseTexts:()=>{if(l)return l;l=new Map;let f=v.mergeBase;if(!f)return l;let y;typeof f=="string"?y=new DOMParser().parseFromString(f,"text/html").documentElement:f instanceof Document?y=f.documentElement:y=f;let S=T=>{let C=k(T);C&&!l.has(C.key)&&l.set(C.key,T.textContent)};s(y)&&S(y);for(let T of y.querySelectorAll("script"))S(T);return l}}}function b(p,O,v){let N=p.merge;if(!N)return!1;let R=N.identityOf(O);if(!R||N.disabled.has(R.key))return!1;let k=N.identityOf(v);if(!k||k.key!==R.key)return!1;let h=O,E=v,d=E.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=tt(N.baseTexts().get(R.key),h.textContent,E.textContent,{parse:R.recognizer.parse,keyCandidates:d?d.split(/[\s,]+/).filter(Boolean):void 0});for(let g of l)console.warn(`[hyper-morph] merge "${R.raw}": ${g}`);return h.textContent!==u&&(h.textContent=u),!0}let M={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},L={computeMatches(p,O){let{computeMatches:v}=r.session();return v(p,O)}};function j(p,O,v={}){p=on(p);let N=xt(O),R=rn(p,N,v),k=R.scripts.handle?new Set(Array.from(p.querySelectorAll("script")).map(u=>i(u,R.scripts.matchMode,R.merge))):null,h=V(R),E=U(R,p,N,u=>u.morphStyle==="innerHTML"?(I(u,p,N),Array.from(p.childNodes)):D(u,p,N)),d=u=>{h&&Y(R,h),P(R);let l=k?qe(u,k,R):[];return l.length>0?Promise.all(l).then(()=>u):u};return E instanceof Promise?E.then(d):d(E)}function P(p){for(let O of Array.from(p.pantry.childNodes))p.callbacks.beforeNodeRemoved(O)!==!1&&p.callbacks.afterNodeRemoved(O);p.pantry.remove()}function D(p,O,v){let N=xt(O);return I(p,N,v,O,O.nextSibling),Array.from(N.childNodes)}function V(p){if(!p.config.restoreFocus)return null;let O=document.activeElement;if(!(O instanceof HTMLInputElement||O instanceof HTMLTextAreaElement))return null;let{id:v,selectionStart:N,selectionEnd:R}=O;return{element:O,id:v,selectionStart:N,selectionEnd:R}}function Y(p,O){let v=O.element;if(O.id&&O.id!==document.activeElement?.getAttribute("id")&&(v=p.target.querySelector(`[id="${CSS.escape(O.id)}"]`),v?.focus()),v&&!v.selectionEnd&&O.selectionEnd!=null)try{v.setSelectionRange(O.selectionStart,O.selectionEnd)}catch{}}let I=function(){function p(u,l,g,f=null,y=null){l instanceof HTMLTemplateElement&&g instanceof HTMLTemplateElement&&(l=l.content,g=g.content),f||=l.firstChild;for(let S of g.childNodes){if(n(S))continue;if(f&&f!=y){let C=v(u,S,f,y);if(C){C!==f&&R(u,f,C),K(C,S,u),f=C.nextSibling;continue}}if(S instanceof Element){let C=S.getAttribute("id");if(u.persistentIds.has(C)){let _=k(l,C,f,u);K(_,S,u),f=_.nextSibling;continue}if(!u.idMap.has(S)){let _=u.hyperMatches.get(S);if(_&&!u.idMap.has(_)&&!d(_,l)){E(l,_,f),K(_,S,u),f=_.nextSibling;continue}}}let T=O(l,S,f,u);T&&(f=T.nextSibling)}for(;f&&f!=y;){let S=f;f=f.nextSibling,n(S)||N(u,S)}}function O(u,l,g,f){if(f.callbacks.beforeNodeAdded(l)===!1)return null;if(f.idMap.has(l)){let y=l,S=document.createElementNS(y.namespaceURI,y.localName);return u.insertBefore(S,g),K(S,l,f),f.callbacks.afterNodeAdded(S),S}else{let y=A(document.importNode(l,!0));return u.insertBefore(y,g),f.callbacks.afterNodeAdded(y),y}}let v=function(){function u(f,y,S,T){let C=y instanceof Element&&!f.idMap.has(y)?f.hyperMatches.get(y):null,_=null,q=y.nextSibling,Z=0,H=S;for(;H&&H!=T;){if(n(H)){H=H.nextSibling;continue}if(g(H,y)){if(l(f,H,y)||H===C&&!f.idMap.has(H))return H;if(_===null){let z=H instanceof Element&&f.hyperMatchedOldElements.has(H);!f.idMap.has(H)&&!z&&(_=H)}}if(_===null&&q&&g(H,q)&&(Z++,q=q.nextSibling,Z>=2&&(_=void 0)),f.activeElementAndParents.includes(H))break;H=H.nextSibling}return _||null}function l(f,y,S){let T=f.idMap.get(y),C=f.idMap.get(S);if(!C||!T)return!1;for(let _ of T)if(C.has(_))return!0;return!1}function g(f,y){let S=f,T=y;return S.nodeType===T.nodeType&&S.tagName===T.tagName&&(!S.getAttribute?.("id")||S.getAttribute?.("id")===T.getAttribute?.("id"))}return u}();function N(u,l){let g=l instanceof Element&&u.hyperMatchedOldElements.has(l)&&!u.idMap.has(l);if(u.idMap.has(l)||g)E(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function R(u,l,g){let f=l;for(;f&&f!==g;){let y=f;f=f.nextSibling,n(y)||N(u,y)}return f}function k(u,l,g,f){let y=f.target.getAttribute?.("id")===l&&f.target||f.target.querySelector(`[id="${CSS.escape(l)}"]`)||f.pantry.querySelector(`[id="${CSS.escape(l)}"]`);return h(y,f),E(u,y,g),y}function h(u,l){let g=u.getAttribute("id");for(;u=u.parentNode;){let f=l.idMap.get(u);f&&(f.delete(g),f.size||l.idMap.delete(u))}}function E(u,l,g){if(u.moveBefore)try{u.moveBefore(l,g)}catch{u.insertBefore(l,g)}else u.insertBefore(l,g)}function d(u,l){let g=l instanceof Element?l:l.realParentNode;return!!g&&u.contains(g)}return p}(),K=function(){function p(h,E,d){return d.ignoreActive&&h===document.activeElement?null:(d.callbacks.beforeNodeMorphed(h,E)===!1||(h instanceof HTMLHeadElement&&d.head.ignore||(h instanceof HTMLHeadElement&&d.head.style!=="morph"?te(h,E,d):(O(h,E,d),b(d,h,E)||k(h,d)||I(d,h,E))),d.callbacks.afterNodeMorphed(h,E)),h)}function O(h,E,d){let u=E.nodeType;if(u===1){let l=h,g=E,f=l.attributes,y=g.attributes;for(let S of y)R(S.name,l,"update",d)||l.getAttribute(S.name)!==S.value&&l.setAttribute(S.name,S.value);for(let S=f.length-1;0<=S;S--){let T=f[S];if(T&&!g.hasAttribute(T.name)){if(R(T.name,l,"remove",d))continue;l.removeAttribute(T.name)}}k(l,d)||v(l,g,d)}(u===8||u===3)&&h.nodeValue!==E.nodeValue&&(h.nodeValue=E.nodeValue)}function v(h,E,d){if(h instanceof HTMLInputElement&&E instanceof HTMLInputElement&&E.type!=="file"){let u=E.value,l=h.value;N(h,E,"checked",d),N(h,E,"disabled",d),d.formStateSync==="property"&&h.indeterminate!==E.indeterminate&&(h.indeterminate=E.indeterminate),d.formStateSync==="property"?l!==u&&(R("value",h,"update",d)||(h.value=u)):E.hasAttribute("value")?l!==u&&(R("value",h,"update",d)||(h.setAttribute("value",u),h.value=u)):R("value",h,"remove",d)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&E instanceof HTMLOptionElement)N(h,E,"selected",d);else if(h instanceof HTMLTextAreaElement&&E instanceof HTMLTextAreaElement){let u=E.value,l=h.value;if(R("value",h,"update",d)||(u!==l&&(h.value=u),d.formStateSync==="property"))return;h.firstChild&&h.firstChild.nodeValue!==u&&(h.firstChild.nodeValue=u)}}function N(h,E,d,u){let l=E[d],g=h[d];if(l!==g){let f=R(d,h,"update",u);if(f||(h[d]=E[d]),u.formStateSync==="property")return;l?f||h.setAttribute(d,""):R(d,h,"remove",u)||h.removeAttribute(d)}}function R(h,E,d,u){return h==="value"&&u.ignoreActiveValue&&E===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,E,d)===!1}function k(h,E){return!!E.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return p}();function U(p,O,v,N){if(p.head.block){let R=O.querySelector("head"),k=v.querySelector("head");if(R&&k){let h=te(R,k,p);return Promise.all(h).then(()=>(p.head.block=!1,p.head.ignore=!0,N(p)))}}return N(p)}function ee(p){return p.tagName==="SCRIPT"?!!p.getAttribute("src"):p.tagName==="LINK"?(p.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!p.getAttribute("href"):!1}function te(p,O,v){let N=[],R=[],k=[],h=[],E=v.scripts.matchMode,d=g=>{if(g.tagName==="SCRIPT")return i(g,E,v.merge);if(g.tagName==="LINK"&&E==="smart"){let f=g.getAttribute("href");if(f)try{let y=new URL(f,window.location.href);return`link:${g.getAttribute("rel")||""}:${y.origin}${y.pathname}${y.search}`}catch{}}return g.outerHTML},u=new Map;for(let g of O.children){if(n(g))continue;let f=d(g),y=u.get(f);y||(y=[],u.set(f,y)),y.push(g)}for(let g of p.children){let f=d(g),y=u.get(f),S=!!(y&&y.length),T=v.head.shouldReAppend(g),C=v.head.shouldPreserve(g);if(S||C)if(T)R.push(g);else{if(y&&y.length){let _=y.pop();y.length||u.delete(f),b(v,g,_)}k.push(g)}else v.head.style==="append"?T&&(R.push(g),h.push(g)):v.head.shouldRemove(g)!==!1&&!n(g)&&R.push(g)}for(let g of u.values())h.push(...g);let l=[];for(let g of h){let f=document.createRange().createContextualFragment(g.outerHTML).firstChild;if(v.callbacks.beforeNodeAdded(f)!==!1){if(f instanceof Element&&ee(f)){let y,S=new Promise(function(T){y=T});f.addEventListener("load",function(){y()}),f.addEventListener("error",function(){y()}),l.push(S)}p.appendChild(f),v.callbacks.afterNodeAdded(f),N.push(f)}}for(let g of R)v.callbacks.beforeNodeRemoved(g)!==!1&&(p.removeChild(g),v.callbacks.afterNodeRemoved(g));return v.head.afterHeadMorphed(p,{added:N,kept:k,removed:R}),l}function qe(p,O,v){if(!v.scripts.handle)return[];let N=[],R=[],k=[],h=[],E=v.scripts.matchMode,d=[];for(let l of p)if(l instanceof Element){s(l)&&d.push(l);for(let g of l.querySelectorAll("script"))s(g)&&d.push(g)}for(let l of d){if(l.closest("head")||o(l))continue;let g=i(l,E,v.merge),f=O.has(g),y=v.scripts.shouldPreserve(l),S=v.scripts.shouldReAppend(l);f||y?S?(R.push(l),h.push(l)):k.push(l):h.push(l)}let u=[];for(let l of h){if(v.callbacks.beforeNodeAdded(l)===!1)continue;let g=document.createElement("script");for(let f of l.attributes)g.setAttribute(f.name,f.value);if(g.textContent=l.textContent,g.src){let f,y=new Promise(function(S){f=S});g.addEventListener("load",function(){f()}),g.addEventListener("error",function(){f()}),u.push(y)}l.replaceWith(g),v.callbacks.afterNodeAdded(g),N.push(g)}return v.scripts.afterScriptsHandled(v.target,{added:N,kept:k,removed:R}),u}let rn=function(){function p(d,u,l){let{persistentIds:g,idMap:f}=h(d,u),y=L.computeMatches(d,u);if(typeof l.key=="function"){let q=new Map,Z=new Set,H=B=>{let F=l.key(B);F!=null&&(q.has(F)?Z.add(F):q.set(F,B))};d instanceof Element&&H(d);for(let B of d.querySelectorAll("*"))H(B);for(let B of Z)q.delete(B);let z=new Map;for(let[B,F]of y)z.set(F,B);let ce=u.__hyperMorphRoot||u,ne=new Map,wt=new Set,vt=B=>{let F=l.key(B);F!=null&&(ne.has(F)?wt.add(F):ne.set(F,B))};ce instanceof Element&&vt(ce);for(let B of ce.querySelectorAll("*"))vt(B);for(let B of wt)ne.delete(B);for(let[B,F]of ne){let he=q.get(B);if(!he||he.tagName!==F.tagName)continue;let We=z.get(he);We&&We!==F&&y.delete(We);let Ve=y.get(F);Ve&&Ve!==he&&z.delete(Ve),y.set(F,he),z.set(he,F)}}let S=O(l),T=m(d,u,S.scripts);if(T){let q=new Map;for(let[Z,H]of y)q.set(H,Z);for(let[Z,H]of T.newByKey){if(T.disabled.has(Z))continue;let z=T.oldByKey.get(Z);if(!z)continue;let ce=q.get(z);ce&&ce!==H&&y.delete(ce);let ne=y.get(H);ne&&ne!==z&&q.delete(ne),y.set(H,z),q.set(z,H)}}let C=new Set;for(let q of y.values())C.add(q);let _=S.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(_))throw new Error(`Do not understand how to morph style ${_}`);return{target:d,newContent:u,config:S,morphStyle:_,ignoreActive:S.ignoreActive,ignoreActiveValue:S.ignoreActiveValue,restoreFocus:S.restoreFocus,formStateSync:S.formStateSync||"attribute",idMap:f,persistentIds:g,hyperMatches:y,hyperMatchedOldElements:C,merge:T,pantry:v(),activeElementAndParents:N(d),callbacks:S.callbacks,head:S.head,scripts:S.scripts}}function O(d){let u=Object.assign({},M);return Object.assign(u,d),u.callbacks=Object.assign({},M.callbacks,d.callbacks),u.head=Object.assign({},M.head,d.head),u.scripts=Object.assign({},M.scripts,d.scripts),u}function v(){let d=document.createElement("div");return d.hidden=!0,document.body.insertAdjacentElement("afterend",d),d}function N(d){let u=[],l=document.activeElement;if(l?.tagName!=="BODY"&&d.contains(l))for(;l&&(u.push(l),l!==d);)l=l.parentElement;return u}function R(d){let u=Array.from(d.querySelectorAll("[id]"));return d.getAttribute?.("id")&&u.push(d),u}function k(d,u,l,g){for(let f of g){let y=f.getAttribute("id");if(u.has(y)){let S=f;for(;S;){let T=d.get(S);if(T==null&&(T=new Set,d.set(S,T)),T.add(y),S===l)break;S=S.parentElement}}}}function h(d,u){let l=R(d),g=R(u),f=E(l,g),y=new Map;k(y,f,d,l);let S=u.__hyperMorphRoot||u;return k(y,f,S,g),{persistentIds:f,idMap:y}}function E(d,u){let l=new Set,g=new Map;for(let y of d){let S=y.getAttribute("id");g.has(S)?l.add(S):g.set(S,y.tagName)}let f=new Set;for(let y of u){let S=y.getAttribute("id");f.has(S)?l.add(S):g.get(S)===y.tagName&&f.add(S)}for(let y of l)f.delete(y);return f}return p}(),{normalizeElement:on,normalizeParent:xt}=function(){let p=new WeakSet;function O(h){return h instanceof Document?h.documentElement:h}function v(h){if(h==null)return document.createElement("div");if(typeof h=="string")return v(k(h));if(p.has(h))return h;if(h instanceof Node){if(h.parentNode)return new N(h);{let E=document.createElement("div");return E.append(h),E}}else{let E=document.createElement("div");for(let d of[...h])E.append(d);return E}}class N{constructor(E){this.originalNode=E,this.realParentNode=E.parentNode,this.previousSibling=E.previousSibling,this.nextSibling=E.nextSibling}get childNodes(){let E=[],d=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;d&&d!=this.nextSibling;)E.push(d),d=d.nextSibling;return E}querySelectorAll(E){return this.childNodes.reduce((d,u)=>{if(u instanceof Element){u.matches(E)&&d.push(u);let l=u.querySelectorAll(E);for(let g=0;g<l.length;g++)d.push(l[g])}return d},[])}insertBefore(E,d){return this.realParentNode.insertBefore(E,d)}moveBefore(E,d){return this.realParentNode.moveBefore(E,d)}get __hyperMorphRoot(){return this.originalNode}}function R(h){let E=g=>`<${g}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,d=h.replace(/<!--[\s\S]*?-->/g,"");for(let g of["script","style","textarea","title"])d=d.replace(new RegExp(`${E(g)}[\\s\\S]*?</${g}\\s*>`,"gi"),"");let u=new RegExp(`${E("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=d,d=d.replace(u,"");while(d!==l);return d}function k(h){let E=new DOMParser,d=R(h);if(d.match(/<\/html>/)||d.match(/<\/head>/)||d.match(/<\/body>/)){let u=E.parseFromString(h,"text/html");if(d.match(/<\/html>/))return p.add(u),u;{let l=u.firstChild;return l&&p.add(l),l}}else{let l=E.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return p.add(l),l}}return{normalizeElement:O,normalizeParent:v}}();return{morph:j,defaults:M,mergeJson:et,mergeScriptText:tt,parseJsonRelaxed:_e,parseRulesRelaxed:_t}}();var Lr=nt.morph,Hr=nt.defaults;var Ft=nt;function rt(e,t,{onWidgetRemoved:n}={}){Ft.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Pe.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var zn="hha:upgrade-check:";function Q(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function ot(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ut(e,t){let n=ot(e),o=ot(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let a=n[i]||0,s=o[i]||0;if(a!==s)return a>s}return!1}function Jn(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Gn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function st({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(m=>fetch(m)),r=r??Date.now(),!t)return null;let a=Q(t,"hyper-source");if(!a)return null;let s=Q(t,"hyper-version"),c;try{c=new URL(a,n?n.href:void 0)}catch{return null}if(n&&c.origin===n.origin&&c.pathname===n.pathname)return null;let A=`${zn}${c.href}:${s||"none"}`,x,w=e?null:Jn(A);if(w&&typeof w.checkedAt=="number"&&r-w.checkedAt<i)x=w.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let b=await m.text(),M=new DOMParser().parseFromString(b,"text/html");x=Q(M,"hyper-version")}catch{x=null}Gn(A,{checkedAt:r,sourceVersion:x})}return x?{available:Ut(x,s||"0.0.0"),currentVersion:s,sourceVersion:x,sourceUrl:c.href}:null}var De=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],it=new Set(De),qt=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Wt=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Be={};ze(Be,{EmptyListInsert:()=>we,MAX_RULE_DEPTH:()=>be,MaxRuleDepthExceeded:()=>ue,RuleTargetReadOnly:()=>ve,RulesParseError:()=>ye,ShapeMismatch:()=>xe,UnknownRulesVersion:()=>le});var ye=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},le=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},be=20,ue=class extends Error{constructor(t){super(`rule depth exceeded ${be} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},xe=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},we=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},ve=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function X(e,t,n,o={}){return at(e,t,n,{depth:0,path:[]},o)}function at(e,t,n,o,r){if(o.depth>be)throw new ue(o.path);if(typeof n=="string")return Yn(e,t,n,r);if(Array.isArray(n)){let[i,a]=n;return e.find(t,i,r).map((c,A)=>at(e,c,a,{depth:o.depth+1,path:[...o.path,A]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[a,s]of Object.entries(n))i[a]=at(e,t,s,{depth:o.depth+1,path:[...o.path,a]},r);return i}return null}function Yn(e,t,n,o){if(n.endsWith("[]")){let a=n.slice(0,-2);return e.find(t,a,o).map(s=>e.text(s))}if(n.startsWith("@"))return Vt(e,t,n.slice(1));let r=oe(n);if(r!==-1){let a=n.slice(0,r),s=n.slice(r+1),c=a?e.find(t,a,o):[t];return c.length===0?null:Vt(e,c[0],s)}if(n===".")return e.text(t);let i=e.find(t,n,o);return i.length===0?null:e.text(i[0])}function Vt(e,t,n){if(it.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Zn(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Qn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Xn={find(e,t,n={}){let o=Qn(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Zn(s)));let i=[];n.skip&&i.push(n.skip);let a=n.templateAttr===null?null:n.templateAttr||"cms-template";if(a&&i.push("["+a+"]"),i.length){let s=i.join(", ");r=r.filter(c=>!c.closest||!c.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},W=Xn;function ct(e){try{return JSON.parse(e)}catch(t){throw new ye(`Invalid strict JSON: ${t.message}`,t)}}function fe(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let w=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(w=!0),!w){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let w=s,m=a+1;for(;m<r.length&&r[m]!==w;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:w}),a=m+1;continue}let c=a,A;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let b of w){let M=b.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let w=r[c];for(c++;c<r.length&&r[c]!==w;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;A=r.substring(a,c);let x=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(A)?x=t.NUMBER:A==="true"||A==="false"||A==="null"?x=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(A)&&(x=t.SELECTOR),i.push({type:x,value:A,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let c=s.value;s.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(A,x)=>x.length%2===0?x+'\\"':A)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new ye("Invalid extraction rules syntax: "+r.message,r)}}var lt="1",Kt=/^[a-zA-Z0-9_-]+$/;function Ae(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Kt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Kt})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],a=e.attr(i,"data-rules-version");if(a!==lt)throw new le(a);return{rules:fe(e.text(i)),tagNode:i}}var er="script[data-rules-name]";function zt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function Oe(e,t){let n=e.find(t,er,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=zt(e.attr(i,"data-rules-name"));if(!a)continue;if(o.has(a)){console.warn(`hyper-html-api: duplicate rules tag name "${a}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==lt)throw new le(s);o.add(a),r.push({name:a,rules:fe(e.text(i))})}return r}function Fe(e,t){let n={};for(let{name:o,rules:r}of Oe(e,t))n[o]=X(e,t,r);return n}function ut(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Fe(W,t),version:Q(n,"hyper-version")}}var Se=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},Re=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},ie=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Te=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var Jt="text/hyper-upgrade";function ft(e,t){let n=e.find(t,`script[type="${Jt}"]`);if(n.length===0)return null;if(n.length>1)throw new Te(n.length);return e.text(n[0])||null}var tr=new Function("url","return import(url)");async function dt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await tr(n)}catch(r){throw new ie(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new ie("transform must `export default` a function");return o.default}var nr=.5;function ht(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(I=>e.remove(I));return}let A=r.length>c.length,x=c[0]||null;if(A&&!x&&(x=ir(e,t,n,s),!x))throw new we(i.path);let w=c.map(I=>rr(e,I,o,s)),m=null;if(x){m=e.clone(x),s.templateAttr&&e.removeAttr(m,s.templateAttr);let I=e.stripIds(m);I>0&&console.warn(`[hyper-html-api] stripped ${I} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let b=or(r,w,o),M=c[0]||x,L=e.parent(M),j=c.length>0?Yt(e,L,M):0,P=ar(e,c),D=new Set,V=[],Y=r.map((I,K)=>{let U=b[K];if(U>=0)return D.add(U),V.push(!1),c[U];V.push(!0);let ee=e.clone(m);return e.stripIds(ee),ee});if(c.forEach((I,K)=>{D.has(K)||e.remove(I)}),P){Y.forEach((I,K)=>{let U=j+K;e.children(L).findIndex(qe=>e.sameNode(qe,I))!==U&&e.insertAt(L,I,U)}),Gt(e,Y,o,r,i,a,s);return}cr(e,Y,V,L,j),Gt(e,Y,o,r,i,a,s)}function Gt(e,t,n,o,r,i,a){t.forEach((s,c)=>{if(n===null){let A=o[c],x=A==null?"":String(A);e.text(s)!==x&&e.text(s,x)}else{let A=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},a);A&&A!==s&&(t[c]=A)}})}function rr(e,t,n,o){return n===null?e.text(t):X(e,t,n,o)}function or(e,t,n){let o=new Array(e.length).fill(-1),r=new Set;return e.forEach((i,a)=>{let s=-1,c=-1;t.forEach((A,x)=>{if(r.has(x))return;let w=sr(i,A,n),m=w===c&&s>=0?Math.abs(x-a)<Math.abs(s-a):!1;(w>c||m)&&(c=w,s=x)}),c>=nr&&(o[a]=s,r.add(s))}),o}function sr(e,t,n){if(n===null)return e===t?1:0;let o=Object.keys(n||{});if(o.length===0)return 0;let r=0;for(let i of o)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&r++;return r/o.length}function Yt(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function ir(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let a of i)if(e.attr(a,o.templateAttr)!=null)return a;r=e.parent(r)}return null}function ar(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let a=o.findIndex(s=>e.sameNode(s,i));if(a===-1)return!1;r.push(a)}return r.sort((i,a)=>i-a),r[r.length-1]-r[0]===r.length-1}function cr(e,t,n,o,r){let i=null,a=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let c=i?e.parent(i):o;if(!c)continue;let A=i?Yt(e,c,i)+1:a++;e.insertAt(c,t[s],A),i=t[s]}}var Zt=new Set(["checked","selected","disabled","readOnly","paused"]);function ae(e,t,n,o,r={}){let i=[];if(pt(n,o,[],i),i.length)throw new xe(i);Ue(e,t,n,o,{depth:0,path:[]},r)}function Ue(e,t,n,o,r,i={}){if(r.depth>be)throw new ue(r.path);if(o===void 0)return t;if(typeof n=="string")return lr(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return ht(e,t,a,s,o,r,Ue,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=Ue(e,t,s,o==null?o:o[a],{depth:r.depth+1,path:[...r.path,a]},i);c&&c!==t&&(t=c)}return t}return t}function lr(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return ht(e,t,c,null,o,r,Ue,i),t}if(n.startsWith("@"))return Qt(e,t,n.slice(1),o);let a=oe(n);if(a!==-1){let c=n.slice(0,a),A=n.slice(a+1),x=c?e.find(t,c,i):[t];return x.length===0||Qt(e,x[0],A,o),t}if(n===".")return e.text(t,o==null?"":String(o)),t;let s=e.find(t,n,i);return s.length===0||e.text(s[0],o==null?"":String(o)),t}function Qt(e,t,n,o){if(Wt.has(n))throw new ve(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return qt.has(n)?(e.prop(t,n,ur(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function ur(e,t){return t==null?Zt.has(e)?!1:"":Zt.has(e)?t==="false"?!1:!!t:t}function pt(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:ke([...n,i]),expected:"scalar",got:Ne(r)})}):o.push({path:ke(n),expected:"array",got:Ne(t)});return}t!==null&&typeof t=="object"&&o.push({path:ke(n),expected:"scalar",got:Ne(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:ke(n),expected:"array",got:Ne(t)});return}let r=e[1];t.forEach((i,a)=>pt(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:ke(n),expected:"object",got:Ne(t)});return}for(let[r,i]of Object.entries(e))pt(i,t[r],[...n,r],o)}}}function Ne(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function ke(e){return e.join(".")}function Ie(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=mt(t,e,n);return gt(t,e,n),{data:o,summary:n}}function mt(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>mt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=mt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function gt(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?gt(e[r],t[r],n):n.discarded+=de(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>gt(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=de(t))}}function de(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+de(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+de(n),0):1}function yt(e,t,n){let o=Oe(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},a=new Set;for(let{name:s,rules:c}of o){if(a.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:A,summary:x}=Ie(n[s],c);ae(e,t,c,A),i[s]=x,r.carriedOver+=x.carriedOver,r.discarded+=x.discarded,r.listItems+=x.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=de(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function bt({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(P=>fetch(P)),!o)throw new Error("upgrade.run requires a document context");if(e=e||Q(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let a=new URL(e,r?r.href:void 0);n=n!==void 0?n:Q(o,"hyper-version"),t=t||Fe(W,o);let s;try{s=await i(a.href)}catch(P){throw new Se(a.href,P)}if(!s.ok)throw new Se(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),A=new DOMParser().parseFromString(c,"text/html"),x=Q(A,"hyper-version"),w=t,m=!1,b=ft(W,A);if(b){let D=await(await dt(b))(w,{fromVersion:n,toVersion:x});if(!D||typeof D!="object"||Array.isArray(D))throw new ie("transform must return a plain object map of { rulesName: data }");w=D,m=!0}let{totals:M,byName:L,rulesTagCount:j}=yt(W,A,w);if(j===0&&Object.keys(w).length>0)throw new Re(a.href);return{html:fr(A),fromVersion:n,toVersion:x,summary:{transformApplied:m,totals:M,byName:L}}}function fr(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
4
4
|
`+e.documentElement.outerHTML}function At(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return Ae(e,o,n)}return null}function Xt(e,t,n,o){let r=At(e,t,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:a}=r;return{rules:i,tagNode:a,get:()=>X(e,t,i,o),set:s=>ae(e,t,i,s,o)}}var Ce={extract:(e,t,n)=>X(W,e,t,n),apply:(e,t,n,o)=>ae(W,e,t,n,o),findRulesIn:(e,t)=>Ae(W,e,t),findRules:(e,t)=>At(W,e,t),bind:(e,t,n)=>Xt(W,e,t,n),parseStrict:ct,parseRelaxed:fe,ruleAttrIndex:oe,splitRule:me,errors:Be,DOM_PROPERTIES:De},St=e=>!!e&&typeof e.nodeType=="number";function en(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=W.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return Ae(W,t).rules}function Et(e,t){let n=St(e)?e:document,o=St(e)?t:e;return o===void 0?X(W,n,en(n)):Ce.bind(n,o).get()}function Mt(e,t,n){if(!St(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?ae(W,e,en(e),t):Ce.bind(e,n).set(t),e}var tn={buildForm:Ge,bindFormEvents:Ye,scaffold:pe,morphForm:rt,path:He},nn={checkForUpdate:st,run:bt,extractAll:ut,shapeMatch:Ie};var pr={engine:Ce,cms:tn,upgrade:nn,extractData:Et,applyData:Mt},mr=pr;return un(gr);})();
|
package/package.json
CHANGED
package/src/engine/apply.js
CHANGED
|
@@ -109,7 +109,9 @@ function coercePropValue(name, value) {
|
|
|
109
109
|
if (value === null || value === undefined) {
|
|
110
110
|
return BOOLEAN_PROPS.has(name) ? false : ''
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
// Form state and attribute round-trips deliver booleans as strings, and
|
|
113
|
+
// Boolean("false") is true: writing "false" would CHECK an unchecked box.
|
|
114
|
+
if (BOOLEAN_PROPS.has(name)) return value === 'false' ? false : Boolean(value)
|
|
113
115
|
return value
|
|
114
116
|
}
|
|
115
117
|
|