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