hyper-html-api 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Self-describing data layer for HTML files — a bidirectional engine that reads structured data out of an HTML page and writes structured data back into it, driven by a single declarative rules tag.
4
4
 
5
- Status: **early development** (Phase 0 — repo bootstrap). API shape and behavior are being ported from `hyperclay/server-lib/data-extractor.js`. See `plans/hyperclay/hyper-html-api/` in the workspace for the full specification.
5
+ Runs in production behind [hyperclay](https://hyperclay.com), Hyperclay Local, and [`@panphora/hyper-cms`](https://github.com/panphora/hypercms), and is vendored into [hyperclayjs](https://github.com/panphora/hyperclayjs) and [clayjs](https://clayjs.com). The same rules run in the browser and in Node under cheerio, through a pluggable adapter.
6
6
 
7
7
  ## Install
8
8
 
@@ -1,3 +1,4 @@
1
- var HyperHtmlApi=(()=>{var Te=Object.defineProperty;var Tt=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var Ot=Object.prototype.hasOwnProperty;var Re=(e,t)=>{for(var n in t)Te(e,n,{get:t[n],enumerable:!0})},Nt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Rt(t))!Ot.call(e,r)&&r!==n&&Te(e,r,{get:()=>t[r],enumerable:!(o=Tt(t,r))||o.enumerable});return e};var It=e=>Nt(Te({},"__esModule",{value:!0}),e);var On={};Re(On,{applyData:()=>Qe,cms:()=>vt,default:()=>Rn,engine:()=>pe,extractData:()=>Ze,upgrade:()=>wt});var ge={};Re(ge,{fromString:()=>me,getRuleAtPath:()=>Oe,getValueAtPath:()=>re,parseConfigKey:()=>Ct,setAtPath:()=>B,toConfigKey:()=>kt,toString:()=>_});function _(e){return e.map(String).join(".")}function kt(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function Ct(e){return e===""?[]:e.split(".")}function me(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function Oe(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 re(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function B(e,t,n){if(t.length===0)return n;let[o,...r]=t;if(typeof o=="number"){let s=Array.isArray(e)?[...e]:[];return s[o]=B(s[o],r,n),s}return{...e&&typeof e=="object"?e:{},[o]:B((e||{})[o],r,n)}}function X(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]=X(o);return t}return""}var ye=new WeakMap;var Lt=new Set(["checked","selected","disabled","readOnly","paused"]);function Ne({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),s={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(ke({rule:e,value:t,path:[],ctx:s})),r}function Ie(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),ot.set(e,{rules:t,getData:n,onChange:o}),Ht()}var ot=new WeakMap,nt=!1;function Ht(){nt||(document.addEventListener("input",rt,!0),document.addEventListener("change",rt,!0),document.addEventListener("click",Pt,!0),nt=!0)}function st(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&ot.get(t)||null}function Pt(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=st(t);if(!n)return;let{rules:o,getData:r,onChange:s}=n,a=t.getAttribute("data-hha-action"),i=me(t.getAttribute("data-hha-path")||"");if(a==="scalar-array-add"){let c=re(r(),i)||[];s(B(r(),i,[...c,""]),{structural:!0});return}if(a==="object-array-add"){let c=Oe(o,i);if(!Array.isArray(c))return;let A=re(r(),i)||[];s(B(r(),i,[...A,X(c[1])]),{structural:!0});return}if(a==="array-remove"){if(i.length===0)return;let c=i.slice(0,-1),A=i[i.length-1],x=re(r(),c)||[];if(typeof A!="number")return;let y=x.filter((p,R)=>R!==A);s(B(r(),c,y),{structural:!0})}}function rt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=st(t);if(!n)return;let{getData:o,onChange:r}=n,s=t.closest("[data-hha-path]");if(!s)return;let a=me(s.getAttribute("data-hha-path")||""),i=t.type==="checkbox"?t.checked:t.value;r(B(o(),a,i),{structural:!1})}function ke({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?$t({rule:e,value:t,path:n,ctx:o}):_t({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return jt({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return Dt({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function Dt({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",_(n)),n.length>0){let s=document.createElement("div");s.className="form-section-label",s.textContent=be(n[n.length-1]),r.appendChild(s)}for(let[s,a]of Object.entries(e)){let i=[...n,s],c=t?.[s];r.appendChild(ke({rule:a,value:c,path:i,ctx:o}))}return r}function _t({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",_(n));let s=document.createElement("div");s.className="field-body";let a=document.createElement("label");a.className="field-label",a.textContent=be(n[n.length-1]||".")+Vt(e);let i=Ft(e,o.appRoot),c=Ut(i,{value:t,rule:e,path:n,appRoot:o.appRoot}),A=c.el;return A.classList.add(i.type==="textarea"?"field-textarea":"field-input"),s.appendChild(a),s.appendChild(A),r.appendChild(s),ye.set(r,c),r}function $t({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",_(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=be(n[n.length-1]),r.appendChild(s);let a=Array.isArray(t)?t:[],i=document.createElement("div");r.appendChild(i),a.forEach((A,x)=>{let y=[...n,x],p=document.createElement("div");p.className="scalar-array-row",p.setAttribute("data-hha-path",_(y));let R=document.createElement("input");R.type="text",R.className="field-input",R.value=A==null?"":String(A);let N=document.createElement("button");N.type="button",N.className="array-remove",N.textContent="\xD7",N.title="remove",N.setAttribute("data-hha-action","array-remove"),N.setAttribute("data-hha-path",_(y)),p.appendChild(R),p.appendChild(N),i.appendChild(p)});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",_(n)),r.appendChild(c),r}function jt({rule:e,value:t,path:n,ctx:o}){let[,r]=e,s=Array.isArray(t)?t:[],a=document.createElement("div");a.className="form-section",a.setAttribute("data-hha-path",_(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=be(n[n.length-1]),a.appendChild(i),s.forEach((A,x)=>{let y=[...n,x],p=document.createElement("div");p.className="array-card",p.setAttribute("data-hha-path",_(y));let R=document.createElement("button");R.type="button",R.className="array-remove",R.textContent="\xD7",R.title="remove item",R.setAttribute("data-hha-action","array-remove"),R.setAttribute("data-hha-path",_(y)),p.appendChild(R);let N=ke({rule:r,value:A,path:y,ctx:o});N.querySelector(".form-section-label")?.remove(),p.appendChild(N),a.appendChild(p)});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",_(n)),a.appendChild(c),a}function Ut(e,t){let n=Wt(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 Ft(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):e.includes("@")&&(n=e.split("@")[1]||null),n&&Lt.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=Bt(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(i=>({value:i.getAttribute("value")||i.textContent,text:i.textContent.trim()||i.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 s=(o.textContent||"").trim();return s.length>60||s.includes(`
2
- `)?{type:"textarea"}:{type:"text"}}function Bt(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=e.includes("@")?e.split("@")[0]:e;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function Wt(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 be(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 Vt(e){return` \xB7 ${e}`}var it={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,slotMatch:30},minConfidence:101};function qt(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 Kt(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 zt(e,t){let n=[];for(let o of e.attributes||[]){let r=o.name;r==="id"||r==="class"||t.excludeAttributePrefixes.some(s=>r.startsWith(s))||t.includeAttributes.includes(r)&&n.push(`${r}=${o.value}`)}return n.sort().join("|")}function Jt(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function Yt(e,t){let n=[e.tagName];return t.includeClasses&&n.push(Kt(e)),n.push(zt(e,t)),qt(n.join("|"))}function Gt(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function Xt(e,t){return e.id||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function Zt(e){if(e.id)return`#${e.id}`;let t=e.getAttribute?.("role");return t?`@${t}`:e.tagName}function Qt(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${Gt(o)}`;if(n.unshift(r),o!==e&&Xt(o,t)){n.unshift(Zt(o));break}o=o.parentElement}return n}function en(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 j(e,t,n){if(n.has(e))return n.get(e);let o={signature:Yt(e,t),path:Qt(e,t),textHint:Jt(e,t)};return n.set(e,o),o}function ut(e,t,n,o){if(o.has(e))return o.get(e);let r=new Map,s=e.querySelectorAll("*"),a=0;for(let i of s){let c=j(i,t,n);c.domIndex=a++,r.has(c.signature)||r.set(c.signature,[]),r.get(c.signature).push(i)}return o.set(e,r),r}function tn(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function Ce(e,t,n,o,r){let s=j(e,n,o),a=j(t,n,o),i=n.weights,c={},A=0;if(s.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};A+=i.signature,c.signature=i.signature;let y=en(s.path,a.path)*i.pathSegment;A+=y,c.path=y;let p=!0;if(s.textHint&&a.textHint?s.textHint===a.textHint?(A+=i.textMatch,c.text=i.textMatch):(A-=i.textMismatch,c.text=-i.textMismatch,p=!1):s.textHint!==a.textHint&&(A-=i.textMismatch,c.text=-i.textMismatch,p=!1),r.candidateCount===1&&p&&(A+=i.uniqueCandidate,c.unique=i.uniqueCandidate),typeof s.domIndex=="number"&&typeof a.domIndex=="number"){let R=Math.abs(s.domIndex-a.domIndex),N=Math.min(R*i.positionPenalty,20);A-=N,c.drift=-N}return{score:A,breakdown:c}}function at(e,t,n,o,r){if(n.excludeIds&&e.id)return null;let s=ut(t,n,o,r),a=j(e,n,o);if(typeof a.domIndex!="number"){let p=0,R=e.previousElementSibling;for(;R;)p++,R=R.previousElementSibling;a.domIndex=p}let i=s.get(a.signature)||[],c=n.excludeIds?i.filter(p=>!p.id):i;if(c.length===0)return null;let A=null,x=0,y=null;for(let p of c){let{score:R,breakdown:N}=Ce(e,p,n,o,{candidateCount:c.length});R>x&&(x=R,A=p,y=N)}return x<n.minConfidence?null:{element:A,confidence:x,breakdown:y}}function nn(e,t,n,o){let r=[],s=n.weights.signature+n.weights.slotMatch,a={slot:s};function i(y){if(y.children)return y.children;let p=y.childNodes;if(!p)return[];let R=[];for(let N=0;N<p.length;N++)p[N].nodeType===1&&R.push(p[N]);return R}function c(y,p){let R=i(y),N=i(p);if(R.length===N.length)for(let C=0;C<R.length;C++){let g=R[C],T=N[C];if(n.excludeIds&&(g.id||T.id)||g.tagName!==T.tagName)continue;let E=j(g,n,o).signature,v=j(T,n,o).signature;E!==v&&r.push({newEl:g,oldEl:T,score:s,breakdown:a}),c(g,T)}}function A(y,p){for(;;){if(y.tagName===p.tagName)return[y,p];let R=i(y);if(!y.tagName&&R.length===1){y=R[0];continue}let N=i(p);if(N.length===1&&N[0].tagName===y.tagName){p=N[0];continue}return null}}let x=A(e,t);return x&&c(x[0],x[1]),r}function ct(e,t,n,o,r){let s=t.querySelectorAll("*"),a=ut(e,n,o,r),i=0;for(let y of s){let p=j(y,n,o);p.domIndex=i++}let c=[];for(let y of s){if(n.excludeIds&&y.id)continue;let p=j(y,n,o),R=a.get(p.signature)||[],N=n.excludeIds?R.filter(C=>!C.id):R;for(let C of N){let{score:g,breakdown:T}=Ce(y,C,n,o,{candidateCount:N.length});g>=n.minConfidence&&c.push({newEl:y,oldEl:C,score:g,breakdown:T})}}if(n.weights.slotMatch>0){let y=nn(t,e,n,o);for(let p of y)c.push(p)}c.sort((y,p)=>p.score-y.score);let A=new Map,x=new Set;for(let{newEl:y,oldEl:p}of c)A.has(y)||x.has(p)||(A.set(y,p),x.add(p));return A}function lt(e,t,n,o){let r=j(e,n,o),s=j(t,n,o),{score:a,breakdown:i}=Ce(e,t,n,o,{candidateCount:1});return{matches:a>=n.minConfidence,score:a,breakdown:i,newMeta:{signature:r.signature,path:r.path,textHint:r.textHint},oldMeta:{signature:s.signature,path:s.path,textHint:s.textHint}}}function ft(e={}){let t={...it,...e,weights:{...it.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,s)=>at(r,s,t,n,o),computeMatches:(r,s)=>ct(r,s,t,n,o),explain:(r,s)=>lt(r,s,t,n),invalidate:r=>tn(r,n,o),session:()=>{let r=new WeakMap,s=new WeakMap;return{findMatch:(a,i)=>at(a,i,t,r,s),computeMatches:(a,i)=>ct(a,i,t,r,s),explain:(a,i)=>lt(a,i,t,r)}},getConfig:()=>({...t})}}var rn=ft(),Le=function(){"use strict";let e=()=>{};function t(g){if(!(g instanceof Element))return!1;if(g.hasAttribute("save-ignore"))return!0;if(g.tagName==="LINK"||g.tagName==="SCRIPT"){let T=g.getAttribute("src")||g.getAttribute("href")||"";if(T.startsWith("chrome-extension://")||T.startsWith("moz-extension://")||T.startsWith("safari-web-extension://"))return!0}return!1}function n(g,T){if(T!=="smart")return g.outerHTML;let E=g.getAttribute("src"),v=g.getAttribute("type")||"text/javascript";if(E)try{let w=new URL(E,window.location.href);return`ext:${v}:${w.origin}${w.pathname}${w.search}`}catch{return`ext:${v}:${E}`}else{let w=g.textContent.trim(),M=5381;for(let d=0;d<w.length;d++)M=(M<<5)+M^w.charCodeAt(d);return`inline:${v}:${Math.abs(M).toString(36)}`}}let o={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:g=>g.getAttribute("im-preserve")==="true",shouldReAppend:g=>g.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!1,matchMode:"outerHTML",shouldPreserve:g=>g.getAttribute("im-preserve")==="true",shouldReAppend:g=>g.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},r={computeMatches(g,T){let{computeMatches:E}=rn.session();return E(g,T)}};function s(g,T,E={}){g=N(g);let v=C(T),w=R(g,v,E),M=w.scripts.matchMode,d=new Set(Array.from(g.querySelectorAll("script")).map(u=>n(u,M))),b=i(w,()=>x(w,g,v,u=>u.morphStyle==="innerHTML"?(c(u,g,v),Array.from(g.childNodes)):a(u,g,v)));w.pantry.remove();let l=p(g,d,w);return l.length>0?b instanceof Promise?b.then(u=>Promise.all(l).then(()=>u)):Promise.all(l).then(()=>b):b}function a(g,T,E){let v=C(T);return c(g,v,E,T,T.nextSibling),Array.from(v.childNodes)}function i(g,T){if(!g.config.restoreFocus)return T();let E=document.activeElement;if(!(E instanceof HTMLInputElement||E instanceof HTMLTextAreaElement))return T();let{id:v,selectionStart:w,selectionEnd:M}=E,d=T();return v&&v!==document.activeElement?.getAttribute("id")&&(E=g.target.querySelector(`[id="${v}"]`),E?.focus()),E&&!E.selectionEnd&&M!=null&&E.setSelectionRange(w,M),d}let c=function(){function g(l,u,h,f=null,m=null){u instanceof HTMLTemplateElement&&h instanceof HTMLTemplateElement&&(u=u.content,h=h.content),f||=u.firstChild;for(let S of h.childNodes){if(t(S))continue;if(f&&f!=m){let I=E(l,S,f,m);if(I){I!==f&&w(l,f,I),A(I,S,l),f=I.nextSibling;continue}}if(S instanceof Element){let I=S.getAttribute("id");if(l.persistentIds.has(I)){let k=M(u,I,f,l);A(k,S,l),f=k.nextSibling;continue}if(!l.idMap.has(S)){let k=l.hyperMatches.get(S);if(k&&!l.idMap.has(k)){b(u,k,f),A(k,S,l),f=k.nextSibling;continue}}}let O=T(u,S,f,l);O&&(f=O.nextSibling)}for(;f&&f!=m;){let S=f;f=f.nextSibling,t(S)||v(l,S)}}function T(l,u,h,f){if(f.callbacks.beforeNodeAdded(u)===!1)return null;if(f.idMap.has(u)){let m=document.createElement(u.tagName);return l.insertBefore(m,h),A(m,u,f),f.callbacks.afterNodeAdded(m),m}else{let m=document.importNode(u,!0);return l.insertBefore(m,h),f.callbacks.afterNodeAdded(m),m}}let E=function(){function l(f,m,S,O){let I=m instanceof Element&&!f.idMap.has(m)?f.hyperMatches.get(m):null,k=null,$=m.nextSibling,ne=0,L=S;for(;L&&L!=O;){if(h(L,m)){if(u(f,L,m)||L===I&&!f.idMap.has(L))return L;if(k===null){let Y=L instanceof Element&&f.hyperMatchedOldElements.has(L);!f.idMap.has(L)&&!Y&&(k=L)}}if(k===null&&$&&h(L,$)&&(ne++,$=$.nextSibling,ne>=2&&(k=void 0)),f.activeElementAndParents.includes(L))break;L=L.nextSibling}return k||null}function u(f,m,S){let O=f.idMap.get(m),I=f.idMap.get(S);if(!I||!O)return!1;for(let k of O)if(I.has(k))return!0;return!1}function h(f,m){let S=f,O=m;return S.nodeType===O.nodeType&&S.tagName===O.tagName&&(!S.getAttribute?.("id")||S.getAttribute?.("id")===O.getAttribute?.("id"))}return l}();function v(l,u){let h=u instanceof Element&&l.hyperMatchedOldElements.has(u)&&!l.idMap.has(u);if(l.idMap.has(u)||h)b(l.pantry,u,null);else{if(l.callbacks.beforeNodeRemoved(u)===!1)return;u.parentNode?.removeChild(u),l.callbacks.afterNodeRemoved(u)}}function w(l,u,h){let f=u;for(;f&&f!==h;){let m=f;f=f.nextSibling,t(m)||v(l,m)}return f}function M(l,u,h,f){let m=f.target.getAttribute?.("id")===u&&f.target||f.target.querySelector(`[id="${u}"]`)||f.pantry.querySelector(`[id="${u}"]`);return d(m,f),b(l,m,h),m}function d(l,u){let h=l.getAttribute("id");for(;l=l.parentNode;){let f=u.idMap.get(l);f&&(f.delete(h),f.size||u.idMap.delete(l))}}function b(l,u,h){if(l.moveBefore)try{l.moveBefore(u,h)}catch{l.insertBefore(u,h)}else l.insertBefore(u,h)}return g}(),A=function(){function g(d,b,l){return l.ignoreActive&&d===document.activeElement?null:(l.callbacks.beforeNodeMorphed(d,b)===!1||(d instanceof HTMLHeadElement&&l.head.ignore||(d instanceof HTMLHeadElement&&l.head.style!=="morph"?y(d,b,l):(T(d,b,l),M(d,l)||c(l,d,b))),l.callbacks.afterNodeMorphed(d,b)),d)}function T(d,b,l){let u=b.nodeType;if(u===1){let h=d,f=b,m=h.attributes,S=f.attributes;for(let O of S)w(O.name,h,"update",l)||h.getAttribute(O.name)!==O.value&&h.setAttribute(O.name,O.value);for(let O=m.length-1;0<=O;O--){let I=m[O];if(I&&!f.hasAttribute(I.name)){if(w(I.name,h,"remove",l))continue;h.removeAttribute(I.name)}}M(h,l)||E(h,f,l)}(u===8||u===3)&&d.nodeValue!==b.nodeValue&&(d.nodeValue=b.nodeValue)}function E(d,b,l){if(d instanceof HTMLInputElement&&b instanceof HTMLInputElement&&b.type!=="file"){let u=b.value,h=d.value;v(d,b,"checked",l),v(d,b,"disabled",l),l.formStateSync==="property"?h!==u&&(w("value",d,"update",l)||(d.value=u)):b.hasAttribute("value")?h!==u&&(w("value",d,"update",l)||(d.setAttribute("value",u),d.value=u)):w("value",d,"remove",l)||(d.value="",d.removeAttribute("value"))}else if(d instanceof HTMLOptionElement&&b instanceof HTMLOptionElement)v(d,b,"selected",l);else if(d instanceof HTMLTextAreaElement&&b instanceof HTMLTextAreaElement){let u=b.value,h=d.value;if(w("value",d,"update",l))return;u!==h&&(d.value=u),d.firstChild&&d.firstChild.nodeValue!==u&&(d.firstChild.nodeValue=u)}}function v(d,b,l,u){let h=b[l],f=d[l];if(h!==f){let m=w(l,d,"update",u);if(m||(d[l]=b[l]),u.formStateSync==="property")return;h?m||d.setAttribute(l,""):w(l,d,"remove",u)||d.removeAttribute(l)}}function w(d,b,l,u){return d==="value"&&u.ignoreActiveValue&&b===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(d,b,l)===!1}function M(d,b){return!!b.ignoreActiveValue&&d===document.activeElement&&d!==document.body}return g}();function x(g,T,E,v){if(g.head.block){let w=T.querySelector("head"),M=E.querySelector("head");if(w&&M){let d=y(w,M,g);return Promise.all(d).then(()=>{let b=Object.assign(g,{head:{block:!1,ignore:!0}});return v(b)})}}return v(g)}function y(g,T,E){let v=[],w=[],M=[],d=[],b=E.scripts.matchMode,l=f=>{if(f.tagName==="SCRIPT")return n(f,b);if(f.tagName==="LINK"&&b==="smart"){let m=f.getAttribute("href");if(m)try{let S=new URL(m,window.location.href);return`link:${f.getAttribute("rel")||""}:${S.origin}${S.pathname}${S.search}`}catch{}}return f.outerHTML},u=new Map;for(let f of T.children)t(f)||u.set(l(f),f);for(let f of g.children){let m=l(f),S=u.has(m),O=E.head.shouldReAppend(f),I=E.head.shouldPreserve(f);S||I?O?w.push(f):(u.delete(m),M.push(f)):E.head.style==="append"?O&&(w.push(f),d.push(f)):E.head.shouldRemove(f)!==!1&&!t(f)&&w.push(f)}d.push(...u.values());let h=[];for(let f of d){let m=document.createRange().createContextualFragment(f.outerHTML).firstChild;if(E.callbacks.beforeNodeAdded(m)!==!1){if("href"in m&&m.href||"src"in m&&m.src){let S,O=new Promise(function(I){S=I});m.addEventListener("load",function(){S()}),h.push(O)}g.appendChild(m),E.callbacks.afterNodeAdded(m),v.push(m)}}for(let f of w)E.callbacks.beforeNodeRemoved(f)!==!1&&(g.removeChild(f),E.callbacks.afterNodeRemoved(f));return E.head.afterHeadMorphed(g,{added:v,kept:M,removed:w}),h}function p(g,T,E){if(!E.scripts.handle)return[];let v=[],w=[],M=[],d=[],b=E.scripts.matchMode,l=Array.from(g.querySelectorAll("script"));for(let h of l){let f=n(h,b),m=T.has(f),S=E.scripts.shouldPreserve(h),O=E.scripts.shouldReAppend(h);m||S?O?(w.push(h),d.push(h)):M.push(h):d.push(h)}for(let h of T){let f=l.some(m=>m.outerHTML===h)}let u=[];for(let h of d){if(E.callbacks.beforeNodeAdded(h)===!1)continue;let f=document.createRange().createContextualFragment(h.outerHTML).firstChild;if(f.src){let m,S=new Promise(function(O){m=O});f.addEventListener("load",function(){m()}),f.addEventListener("error",function(){m()}),u.push(S)}h.replaceWith(f),E.callbacks.afterNodeAdded(f),v.push(f)}return E.scripts.afterScriptsHandled(g,{added:v,kept:M,removed:w}),u}let R=function(){function g(l,u,h){let{persistentIds:f,idMap:m}=d(l,u),S=r.computeMatches(l,u);if(typeof h.key=="function"){let $=new Map,ne=new Set,L=H=>{let P=h.key(H);P!=null&&($.has(P)?ne.add(P):$.set(P,H))};l instanceof Element&&L(l);for(let H of l.querySelectorAll("*"))L(H);for(let H of ne)$.delete(H);let Y=new Map;for(let[H,P]of S)Y.set(P,H);let xe=u.__hyperMorphRoot||u,he=new Map,et=new Set,tt=H=>{let P=h.key(H);P!=null&&(he.has(P)?et.add(P):he.set(P,H))};xe instanceof Element&&tt(xe);for(let H of xe.querySelectorAll("*"))tt(H);for(let H of et)he.delete(H);for(let[H,P]of he){let G=$.get(H);if(!G||G.tagName!==P.tagName)continue;let ve=Y.get(G);ve&&ve!==P&&S.delete(ve);let we=S.get(P);we&&we!==G&&Y.delete(we),S.set(P,G),Y.set(G,P)}}let O=new Set;for(let $ of S.values())O.add($);let I=T(h),k=I.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(k))throw`Do not understand how to morph style ${k}`;return{target:l,newContent:u,config:I,morphStyle:k,ignoreActive:I.ignoreActive,ignoreActiveValue:I.ignoreActiveValue,restoreFocus:I.restoreFocus,formStateSync:I.formStateSync||"attribute",idMap:m,persistentIds:f,hyperMatches:S,hyperMatchedOldElements:O,pantry:E(),activeElementAndParents:v(l),callbacks:I.callbacks,head:I.head,scripts:I.scripts}}function T(l){let u=Object.assign({},o);return Object.assign(u,l),u.callbacks=Object.assign({},o.callbacks,l.callbacks),u.head=Object.assign({},o.head,l.head),u.scripts=Object.assign({},o.scripts,l.scripts),u}function E(){let l=document.createElement("div");return l.hidden=!0,document.body.insertAdjacentElement("afterend",l),l}function v(l){let u=[],h=document.activeElement;if(h?.tagName!=="BODY"&&l.contains(h))for(;h&&(u.push(h),h!==l);)h=h.parentElement;return u}function w(l){let u=Array.from(l.querySelectorAll("[id]"));return l.getAttribute?.("id")&&u.push(l),u}function M(l,u,h,f){for(let m of f){let S=m.getAttribute("id");if(u.has(S)){let O=m;for(;O;){let I=l.get(O);if(I==null&&(I=new Set,l.set(O,I)),I.add(S),O===h)break;O=O.parentElement}}}}function d(l,u){let h=w(l),f=w(u),m=b(h,f),S=new Map;M(S,m,l,h);let O=u.__hyperMorphRoot||u;return M(S,m,O,f),{persistentIds:m,idMap:S}}function b(l,u){let h=new Set,f=new Map;for(let{id:S,tagName:O}of l)f.has(S)?h.add(S):f.set(S,O);let m=new Set;for(let{id:S,tagName:O}of u)m.has(S)?h.add(S):f.get(S)===O&&m.add(S);for(let S of h)m.delete(S);return m}return g}(),{normalizeElement:N,normalizeParent:C}=function(){let g=new WeakSet;function T(M){return M instanceof Document?M.documentElement:M}function E(M){if(M==null)return document.createElement("div");if(typeof M=="string")return E(w(M));if(g.has(M))return M;if(M instanceof Node){if(M.parentNode)return new v(M);{let d=document.createElement("div");return d.append(M),d}}else{let d=document.createElement("div");for(let b of[...M])d.append(b);return d}}class v{constructor(d){this.originalNode=d,this.realParentNode=d.parentNode,this.previousSibling=d.previousSibling,this.nextSibling=d.nextSibling}get childNodes(){let d=[],b=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;b&&b!=this.nextSibling;)d.push(b),b=b.nextSibling;return d}querySelectorAll(d){return this.childNodes.reduce((b,l)=>{if(l instanceof Element){l.matches(d)&&b.push(l);let u=l.querySelectorAll(d);for(let h=0;h<u.length;h++)b.push(u[h])}return b},[])}insertBefore(d,b){return this.realParentNode.insertBefore(d,b)}moveBefore(d,b){return this.realParentNode.moveBefore(d,b)}get __hyperMorphRoot(){return this.originalNode}}function w(M){let d=new DOMParser,b=M.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(b.match(/<\/html>/)||b.match(/<\/head>/)||b.match(/<\/body>/)){let l=d.parseFromString(M,"text/html");if(b.match(/<\/html>/))return g.add(l),l;{let u=l.firstChild;return u&&g.add(u),u}}else{let u=d.parseFromString("<body><template>"+M+"</template></body>","text/html").body.querySelector("template").content;return g.add(u),u}}return{normalizeElement:T,normalizeParent:E}}();return{morph:s,defaults:o}}();var $n=Le.morph,jn=Le.defaults,dt=Le;function He(e,t,{onWidgetRemoved:n}={}){dt.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=ye.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var sn="hha:upgrade-check:";function U(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function Pe(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function pt(e,t){let n=Pe(e),o=Pe(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let s=0;s<r;s++){let a=n[s]||0,i=o[s]||0;if(a!==i)return a>i}return!1}function an(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function cn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function De({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:s=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(p=>fetch(p)),r=r??Date.now(),!t)return null;let a=U(t,"hyper-source");if(!a)return null;let i=U(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=`${sn}${c.href}:${i||"none"}`,x,y=e?null:an(A);if(y&&typeof y.checkedAt=="number"&&r-y.checkedAt<s)x=y.sourceVersion;else{try{let p=await o(c.href);if(!p.ok)throw new Error(`HTTP ${p.status}`);let R=await p.text(),N=new DOMParser().parseFromString(R,"text/html");x=U(N,"hyper-version")}catch{x=null}cn(A,{checkedAt:r,sourceVersion:x})}return x?{available:pt(x,i||"0.0.0"),currentVersion:i,sourceVersion:x,sourceUrl:c.href}:null}var Ae=["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"],_e=new Set(Ae),ht=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),mt=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Se={};Re(Se,{EmptyListInsert:()=>se,MAX_RULE_DEPTH:()=>Q,MaxRuleDepthExceeded:()=>K,RuleTargetReadOnly:()=>ie,RulesParseError:()=>Z,ShapeMismatch:()=>oe,UnknownRulesVersion:()=>q});var Z=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},q=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},Q=20,K=class extends Error{constructor(t){super(`rule depth exceeded ${Q} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},oe=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},se=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}},ie=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function F(e,t,n,o={}){return $e(e,t,n,{depth:0,path:[]},o)}function $e(e,t,n,o,r){if(o.depth>Q)throw new K(o.path);if(typeof n=="string")return ln(e,t,n,r);if(Array.isArray(n)){let[s,a]=n;return e.find(t,s,r).map((c,A)=>$e(e,c,a,{depth:o.depth+1,path:[...o.path,A]},r))}if(typeof n=="object"&&n!==null){let s={};for(let[a,i]of Object.entries(n))s[a]=$e(e,t,i,{depth:o.depth+1,path:[...o.path,a]},r);return s}return null}function ln(e,t,n,o){if(n.endsWith("[]")){let s=n.slice(0,-2);return e.find(t,s,o).map(a=>e.text(a))}if(n.startsWith("@"))return gt(e,t,n.slice(1));if(n.includes("@")){let s=n.lastIndexOf("@"),a=n.slice(0,s),i=n.slice(s+1),c=a?e.find(t,a,o):[t];return c.length===0?null:gt(e,c[0],i)}if(n===".")return e.text(t);let r=e.find(t,n,o);return r.length===0?null:e.text(r[0])}function gt(e,t,n){if(_e.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function un(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function fn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var dn={find(e,t,n={}){let o=fn(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(i=>!un(i)));let s=[];n.skip&&s.push(n.skip);let a=n.templateAttr===null?null:n.templateAttr||"cms-template";if(a&&s.push("["+a+"]"),s.length){let i=s.join(", ");r=r.filter(c=>!c.closest||!c.closest(i))}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}},D=dn;function je(e){try{return JSON.parse(e)}catch(t){throw new Z(`Invalid strict JSON: ${t.message}`,t)}}function z(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let s=[],a=0;for(;a<r.length;){let i=r[a];if(/\s/.test(i)){a++;continue}if("{}".includes(i)){s.push({type:i,value:i}),a++;continue}if(i==="["){let y=!1,p=a+1;for(;p<r.length&&/\s/.test(r[p]);)p++;if(p<r.length&&/[a-zA-Z_]/.test(r[p])&&(y=!0),!y){s.push({type:i,value:i}),a++;continue}}if(i==="]"){s.push({type:i,value:i}),a++;continue}if(i===":"){s.push({type:t.COLON,value:i}),a++;continue}if(i===","){s.push({type:t.COMMA,value:i}),a++;continue}if(i==='"'||i==="'"){let y=i,p=a+1;for(;p<r.length&&r[p]!==y;)r[p]==="\\"&&p++,p++;s.push({type:t.STRING,value:r.substring(a+1,p),quoted:!0,sourceQuote:y}),a=p+1;continue}let c=a,A;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let y=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],p=!1;for(let R of y){let N=R.substring(1);if(r.substring(c+1,c+1+N.length)===N){p=!0,c+=N.length;break}}if(!p)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let y=r[c];for(c++;c<r.length&&r[c]!==y;)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),s.push({type:x,value:A,quoted:!1}),a=c}return s}function o(r){let s="";for(let a=0;a<r.length;a++){let i=r[a];if("{}".includes(i.type)||"[]".includes(i.type)){s+=i.value;continue}if(i.type===t.COLON){s+=i.value;continue}if(i.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;s+=i.value;continue}if(i.type===t.STRING&&i.quoted){let c=i.value;i.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(A,x)=>x.length%2===0?x+'\\"':A)),s+=`"${c}"`;continue}if(i.type===t.NUMBER||i.type===t.BOOLEAN){s+=i.value;continue}if(i.type===t.SELECTOR||i.type===t.IDENTIFIER){s+=`"${i.value}"`;continue}s+=`"${i.value}"`}return s}try{let r=n(e),s=o(r);return JSON.parse(s)}catch(r){throw new Z("Invalid extraction rules syntax: "+r.message,r)}}var Ue="1",yt=/^[a-zA-Z0-9_-]+$/;function ee(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!yt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${yt})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=r[0],a=e.attr(s,"data-rules-version");if(a!==Ue)throw new q(a);return{rules:z(e.text(s)),tagNode:s}}var pn="script[data-rules-name]";function bt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function ae(e,t){let n=e.find(t,pn,{includeRulesTag:!0}),o=new Set,r=[];for(let s of n){let a=bt(e.attr(s,"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 i=e.attr(s,"data-rules-version");if(i!==Ue)throw new q(i);o.add(a),r.push({name:a,rules:z(e.text(s))})}return r}function Me(e,t){let n={};for(let{name:o,rules:r}of ae(e,t))n[o]=F(e,t,r);return n}function Fe(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Me(D,t),version:U(n,"hyper-version")}}var te=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},ce=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}},W=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},le=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 At="text/hyper-upgrade";function Be(e,t){let n=e.find(t,`script[type="${At}"]`);if(n.length===0)return null;if(n.length>1)throw new le(n.length);return e.text(n[0])||null}var hn=new Function("url","return import(url)");async function We(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await hn(n)}catch(r){throw new W(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new W("transform must `export default` a function");return o.default}var mn=.5;function Ve(e,t,n,o,r,s,a,i={}){let c=e.find(t,n,i);if(r.length===0){c.forEach(v=>e.remove(v));return}let A=r.length>c.length,x=c[0]||null;if(A&&!x&&(x=Sn(e,t,n,i),!x))throw new se(s.path);let y=c.map(v=>gn(e,v,o,i)),p=null;if(x){p=e.clone(x),i.templateAttr&&e.removeAttr(p,i.templateAttr);let v=e.stripIds(p);v>0&&console.warn(`[hyper-html-api] stripped ${v} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let R=yn(r,y,o),N=c[0]||x,C=e.parent(N),g=c.length>0?An(e,C,N):0,T=new Set,E=r.map((v,w)=>{let M=R[w];if(M>=0)return T.add(M),c[M];let d=e.clone(p);return e.stripIds(d),d});c.forEach((v,w)=>{T.has(w)||e.remove(v)}),E.forEach((v,w)=>{let M=g+w;e.children(C).findIndex(l=>e.sameNode(l,v))!==M&&e.insertAt(C,v,M)}),E.forEach((v,w)=>{if(o===null){let M=r[w],d=M==null?"":String(M);e.text(v)!==d&&e.text(v,d)}else{let M=a(e,v,o,r[w],{depth:s.depth+1,path:[...s.path,w]},i);M&&M!==v&&(E[w]=M)}})}function gn(e,t,n,o){return n===null?e.text(t):F(e,t,n,o)}function yn(e,t,n){let o=new Array(e.length).fill(-1),r=new Set;return e.forEach((s,a)=>{let i=-1,c=-1;t.forEach((A,x)=>{if(r.has(x))return;let y=bn(s,A,n),p=y===c&&i>=0?Math.abs(x-a)<Math.abs(i-a):!1;(y>c||p)&&(c=y,i=x)}),c>=mn&&(o[a]=i,r.add(i))}),o}function bn(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 s of o)JSON.stringify(e?.[s])===JSON.stringify(t?.[s])&&r++;return r/o.length}function An(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 Sn(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let s=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let a of s)if(e.attr(a,o.templateAttr)!=null)return a;r=e.parent(r)}return null}var St=new Set(["checked","selected","disabled","readOnly","paused"]);function V(e,t,n,o,r={}){let s=[];if(qe(n,o,[],s),s.length)throw new oe(s);Ee(e,t,n,o,{depth:0,path:[]},r)}function Ee(e,t,n,o,r,s={}){if(r.depth>Q)throw new K(r.path);if(o===void 0)return t;if(typeof n=="string")return Mn(e,t,n,o,r,s);if(Array.isArray(n)){let[a,i]=n;return Ve(e,t,a,i,o,r,Ee,s),t}if(typeof n=="object"&&n!==null){for(let[a,i]of Object.entries(n)){let c=Ee(e,t,i,o==null?o:o[a],{depth:r.depth+1,path:[...r.path,a]},s);c&&c!==t&&(t=c)}return t}return t}function Mn(e,t,n,o,r,s){if(n.endsWith("[]")){let i=n.slice(0,-2);return Ve(e,t,i,null,o,r,Ee,s),t}if(n.startsWith("@"))return Mt(e,t,n.slice(1),o);if(n.includes("@")){let i=n.lastIndexOf("@"),c=n.slice(0,i),A=n.slice(i+1),x=c?e.find(t,c,s):[t];return x.length===0||Mt(e,x[0],A,o),t}if(n===".")return e.text(t,o==null?"":String(o)),t;let a=e.find(t,n,s);return a.length===0||e.text(a[0],o==null?"":String(o)),t}function Mt(e,t,n,o){if(mt.has(n))throw new ie(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return ht.has(n)?(e.prop(t,n,En(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function En(e,t){return t==null?St.has(e)?!1:"":St.has(e)?!!t:t}function qe(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,s)=>{typeof r=="object"&&r!==null&&o.push({path:fe([...n,s]),expected:"scalar",got:ue(r)})}):o.push({path:fe(n),expected:"array",got:ue(t)});return}t!==null&&typeof t=="object"&&o.push({path:fe(n),expected:"scalar",got:ue(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:fe(n),expected:"array",got:ue(t)});return}let r=e[1];t.forEach((s,a)=>qe(r,s,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:fe(n),expected:"object",got:ue(t)});return}for(let[r,s]of Object.entries(e))qe(s,t[r],[...n,r],o)}}}function ue(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function fe(e){return e.join(".")}function de(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Ke(t,e,n);return ze(t,e,n),{data:o,summary:n}}function Ke(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=>Ke(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,s]of Object.entries(e)){let a=Ke(s,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function ze(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)?ze(e[r],t[r],n):n.discarded+=J(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>ze(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=J(t))}}function J(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+J(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+J(n),0):1}function Je(e,t,n){let o=ae(e,t),r={carriedOver:0,discarded:0,listItems:0},s={},a=new Set;for(let{name:i,rules:c}of o){if(a.add(i),!Object.prototype.hasOwnProperty.call(n,i)){s[i]={carriedOver:0,discarded:0,listItems:0};continue}let{data:A,summary:x}=de(n[i],c);V(e,t,c,A),s[i]=x,r.carriedOver+=x.carriedOver,r.discarded+=x.discarded,r.listItems+=x.listItems}for(let i of Object.keys(n))a.has(i)||(r.discarded+=J(n[i]));return{totals:r,byName:s,rulesTagCount:o.length}}async function Ye({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:s}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),s=s||(T=>fetch(T)),!o)throw new Error("upgrade.run requires a document context");if(e=e||U(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:U(o,"hyper-version"),t=t||Me(D,o);let i;try{i=await s(a.href)}catch(T){throw new te(a.href,T)}if(!i.ok)throw new te(a.href,new Error(`HTTP ${i.status}`));let c=await i.text(),A=new DOMParser().parseFromString(c,"text/html"),x=U(A,"hyper-version"),y=t,p=!1,R=Be(D,A);if(R){let E=await(await We(R))(y,{fromVersion:n,toVersion:x});if(!E||typeof E!="object"||Array.isArray(E))throw new W("transform must return a plain object map of { rulesName: data }");y=E,p=!0}let{totals:N,byName:C,rulesTagCount:g}=Je(D,A,y);if(g===0&&Object.keys(y).length>0)throw new ce(a.href);return{html:xn(A),fromVersion:n,toVersion:x,summary:{transformApplied:p,totals:N,byName:C}}}function xn(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
3
- `+e.documentElement.outerHTML}function Ge(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 ee(e,o,n)}return null}function Et(e,t,n,o){let r=Ge(e,t,n);if(!r){let i=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${i}`)}let{rules:s,tagNode:a}=r;return{rules:s,tagNode:a,get:()=>F(e,t,s,o),set:i=>V(e,t,s,i,o)}}var pe={extract:(e,t,n)=>F(D,e,t,n),apply:(e,t,n,o)=>V(D,e,t,n,o),findRulesIn:(e,t)=>ee(D,e,t),findRules:(e,t)=>Ge(D,e,t),bind:(e,t,n)=>Et(D,e,t,n),parseStrict:je,parseRelaxed:z,errors:Se,DOM_PROPERTIES:Ae},Xe=e=>!!e&&typeof e.nodeType=="number";function xt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=D.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 ee(D,t).rules}function Ze(e,t){let n=Xe(e)?e:document,o=Xe(e)?t:e;return o===void 0?F(D,n,xt(n)):pe.bind(n,o).get()}function Qe(e,t,n){if(!Xe(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?V(D,e,xt(e),t):pe.bind(e,n).set(t),e}var vt={buildForm:Ne,bindFormEvents:Ie,scaffold:X,morphForm:He,path:ge},wt={checkForUpdate:De,run:Ye,extractAll:Fe,shapeMatch:de};var Tn={engine:pe,cms:vt,upgrade:wt,extractData:Ze,applyData:Qe},Rn=Tn;return It(On);})();
1
+ var HyperHtmlApi=(()=>{var qe=Object.defineProperty;var tn=Object.getOwnPropertyDescriptor;var nn=Object.getOwnPropertyNames;var rn=Object.prototype.hasOwnProperty;var We=(e,t)=>{for(var n in t)qe(e,n,{get:t[n],enumerable:!0})},on=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of nn(t))!rn.call(e,r)&&r!==n&&qe(e,r,{get:()=>t[r],enumerable:!(o=tn(t,r))||o.enumerable});return e};var sn=e=>on(qe({},"__esModule",{value:!0}),e);var fr={};We(fr,{applyData:()=>At,cms:()=>Yt,default:()=>ur,engine:()=>ke,extractData:()=>bt,upgrade:()=>Zt});var Ce={};We(Ce,{fromString:()=>Ie,getRuleAtPath:()=>Ve,getValueAtPath:()=>Ae,parseConfigKey:()=>cn,setAtPath:()=>te,toConfigKey:()=>an,toString:()=>J});function J(e){return e.map(String).join(".")}function an(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function cn(e){return e===""?[]:e.split(".")}function Ie(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function Ve(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 Ae(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function te(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]=te(i[o],r,n),i}return{...e&&typeof e=="object"?e:{},[o]:te((e||{})[o],r,n)}}function he(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]=he(o);return t}return""}var Le=new WeakMap;var ln=new Set(["checked","selected","disabled","readOnly","paused"]);function Ke({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(Je({rule:e,value:t,path:[],ctx:i})),r}function ze(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),vt.set(e,{rules:t,getData:n,onChange:o}),un()}var vt=new WeakMap,xt=!1;function un(){xt||(document.addEventListener("input",wt,!0),document.addEventListener("change",wt,!0),document.addEventListener("click",fn,!0),xt=!0)}function Ot(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&vt.get(t)||null}function fn(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=Ot(t);if(!n)return;let{rules:o,getData:r,onChange:i}=n,a=t.getAttribute("data-hha-action"),s=Ie(t.getAttribute("data-hha-path")||"");if(a==="scalar-array-add"){let c=Ae(r(),s)||[];i(te(r(),s,[...c,""]),{structural:!0});return}if(a==="object-array-add"){let c=Ve(o,s);if(!Array.isArray(c))return;let M=Ae(r(),s)||[];i(te(r(),s,[...M,he(c[1])]),{structural:!0});return}if(a==="array-remove"){if(s.length===0)return;let c=s.slice(0,-1),M=s[s.length-1],w=Ae(r(),c)||[];if(typeof M!="number")return;let x=w.filter((m,b)=>b!==M);i(te(r(),c,x),{structural:!0})}}function wt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=Ot(t);if(!n)return;let{getData:o,onChange:r}=n,i=t.closest("[data-hha-path]");if(!i)return;let a=Ie(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;r(te(o(),a,s),{structural:!1})}function Je({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?pn({rule:e,value:t,path:n,ctx:o}):hn({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return mn({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",J(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=He(n[n.length-1]),r.appendChild(i)}for(let[i,a]of Object.entries(e)){let s=[...n,i],c=t?.[i];r.appendChild(Je({rule:a,value:c,path:s,ctx:o}))}return r}function hn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="field-body";let a=document.createElement("label");a.className="field-label",a.textContent=He(n[n.length-1]||".")+Sn(e);let s=yn(e,o.appRoot),c=gn(s,{value:t,rule:e,path:n,appRoot:o.appRoot}),M=c.el;return M.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(a),i.appendChild(M),r.appendChild(i),Le.set(r,c),r}function pn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=He(n[n.length-1]),r.appendChild(i);let a=Array.isArray(t)?t:[],s=document.createElement("div");r.appendChild(s),a.forEach((M,w)=>{let x=[...n,w],m=document.createElement("div");m.className="scalar-array-row",m.setAttribute("data-hha-path",J(x));let b=document.createElement("input");b.type="text",b.className="field-input",b.value=M==null?"":String(M);let E=document.createElement("button");E.type="button",E.className="array-remove",E.textContent="\xD7",E.title="remove",E.setAttribute("data-hha-action","array-remove"),E.setAttribute("data-hha-path",J(x)),m.appendChild(b),m.appendChild(E),s.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","scalar-array-add"),c.setAttribute("data-hha-path",J(n)),r.appendChild(c),r}function mn({rule:e,value:t,path:n,ctx:o}){let[,r]=e,i=Array.isArray(t)?t:[],a=document.createElement("div");a.className="form-section",a.setAttribute("data-hha-path",J(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=He(n[n.length-1]),a.appendChild(s),i.forEach((M,w)=>{let x=[...n,w],m=document.createElement("div");m.className="array-card",m.setAttribute("data-hha-path",J(x));let b=document.createElement("button");b.type="button",b.className="array-remove",b.textContent="\xD7",b.title="remove item",b.setAttribute("data-hha-action","array-remove"),b.setAttribute("data-hha-path",J(x)),m.appendChild(b);let E=Je({rule:r,value:M,path:x,ctx:o});E.querySelector(".form-section-label")?.remove(),m.appendChild(E),a.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","object-array-add"),c.setAttribute("data-hha-path",J(n)),a.appendChild(c),a}function gn(e,t){let n=An(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 yn(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):e.includes("@")&&(n=e.split("@")[1]||null),n&&ln.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=bn(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 bn(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=e.includes("@")?e.split("@")[0]:e;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function An(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 He(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 Sn(e){return` \xB7 ${e}`}var Tt={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 En(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 Mn(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function xn(e,t){let n=[];for(let o of e.attributes||[]){let r=o.name;r==="id"||r==="class"||t.excludeAttributePrefixes.some(i=>r.startsWith(i))||t.includeAttributes.includes(r)&&n.push(`${r}=${o.value}`)}return n.sort().join("|")}function wn(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function vn(e,t){let n=[e.tagName];return t.includeClasses&&n.push(Mn(e)),n.push(xn(e,t)),En(n.join("|"))}function On(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function Tn(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function Rn(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function Nn(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${On(o)}`;if(n.unshift(r),o!==e&&Tn(o,t)){n.unshift(Rn(o));break}o=o.parentElement}return n}function kn(e,t){let n=0,o=e.length-1,r=t.length-1;for(;o>=0&&r>=0&&e[o]===t[r];)n++,o--,r--;return n}function G(e,t,n){if(n.has(e))return n.get(e);let o={signature:vn(e,t),path:Nn(e,t),textHint:wn(e,t)};return n.set(e,o),o}function It(e,t,n,o){if(o.has(e))return o.get(e);let r=new Map,i=e.querySelectorAll("*"),a=0;for(let s of i){let c=G(s,t,n);c.domIndex=a++,!t.shouldIgnore?.(s)&&(r.has(c.signature)||r.set(c.signature,[]),r.get(c.signature).push(s))}return o.set(e,r),r}function In(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function Ge(e,t,n,o,r){let i=G(e,n,o),a=G(t,n,o),s=n.weights,c={},M=0;if(i.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};M+=s.signature,c.signature=s.signature;let x=kn(i.path,a.path)*s.pathSegment;M+=x,c.path=x;let m=!0;if(i.textHint&&a.textHint?i.textHint===a.textHint?(M+=s.textMatch,c.text=s.textMatch):(M-=s.textMismatch,c.text=-s.textMismatch,m=!1):i.textHint!==a.textHint&&(M-=s.textMismatch,c.text=-s.textMismatch,m=!1),r.candidateCount===1&&m&&(M+=s.uniqueCandidate,c.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof a.domIndex=="number"){let b=Math.abs(i.domIndex-a.domIndex),E=Math.min(b*s.positionPenalty,s.maxDriftPenalty);M-=E,c.drift=-E}return{score:M,breakdown:c}}function Rt(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let i=It(t,n,o,r),a=G(e,n,o);if(typeof a.domIndex!="number"){let m=0,b=e.previousElementSibling;for(;b;)m++,b=b.previousElementSibling;a.domIndex=m}let s=i.get(a.signature)||[],c=n.excludeIds?s.filter(m=>!m.getAttribute("id")):s;if(c.length===0)return null;let M=null,w=0,x=null;for(let m of c){let{score:b,breakdown:E}=Ge(e,m,n,o,{candidateCount:c.length});b>w&&(w=b,M=m,x=E)}return w<n.minConfidence?null:{element:M,confidence:w,breakdown:x}}function Cn(e,t,n,o){let r=[],i=n.weights.signature+n.weights.slotMatch,a={slot:i};function s(x){if(x.children)return x.children;let m=x.childNodes;if(!m)return[];let b=[];for(let E=0;E<m.length;E++)m[E].nodeType===1&&b.push(m[E]);return b}function c(x,m){let b=s(x),E=s(m);if(b.length===E.length)for(let P=0;P<b.length;P++){let _=b[P],j=E[P];if(n.shouldIgnore?.(_)||n.shouldIgnore?.(j)||n.excludeIds&&(_.getAttribute("id")||j.getAttribute("id"))||_.tagName!==j.tagName)continue;let B=G(_,n,o).signature,L=G(j,n,o).signature;B!==L&&r.push({newEl:_,oldEl:j,score:i,breakdown:a}),c(_,j)}}function M(x,m){for(;;){if(x.tagName===m.tagName)return[x,m];let b=s(x);if(!x.tagName&&b.length===1){x=b[0];continue}let E=s(m);if(E.length===1&&E[0].tagName===x.tagName){m=E[0];continue}return null}}let w=M(e,t);return w&&c(w[0],w[1]),r}function Nt(e,t,n,o,r){let i=t.querySelectorAll("*"),a=It(e,n,o,r),s=0;for(let b of i){let E=G(b,n,o);E.domIndex=s++}let c=[],M=new Map;function w(b,E,P){let _=new Set;if(b.textHint){let I=M.get(b.signature);if(!I){I=new Map;for(let Y of E){let fe=G(Y,n,o).textHint,se=I.get(fe);se||(se=[],I.set(fe,se)),se.push(Y)}M.set(b.signature,I)}let K=I.get(b.textHint);if(K)for(let Y=0;Y<K.length&&Y<P;Y++)_.add(K[Y])}let j=0,B=E.length;for(;j<B;){let I=j+B>>1;G(E[I],n,o).domIndex<b.domIndex?j=I+1:B=I}let L=Math.max(0,Math.min(j-(P>>1),E.length-P)),F=Math.min(L+P,E.length);for(let I=L;I<F;I++)_.add(E[I]);return[..._]}for(let b of i){if(n.shouldIgnore?.(b)||n.excludeIds&&b.getAttribute("id"))continue;let E=G(b,n,o),P=a.get(E.signature)||[],_=n.excludeIds?P.filter(L=>!L.getAttribute("id")):P,j=n.maxScoredCandidates,B=j&&_.length>j?w(E,_,j):_;for(let L of B){let{score:F,breakdown:I}=Ge(b,L,n,o,{candidateCount:_.length});F>=n.minConfidence&&c.push({newEl:b,oldEl:L,score:F,breakdown:I})}}if(n.weights.slotMatch>0){let b=Cn(t,e,n,o);for(let E of b)c.push(E)}c.sort((b,E)=>E.score-b.score);let x=new Map,m=new Set;for(let{newEl:b,oldEl:E}of c)x.has(b)||m.has(E)||(x.set(b,E),m.add(E));return x}function kt(e,t,n,o){let r=G(e,n,o),i=G(t,n,o),{score:a,breakdown:s}=Ge(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 Ct(e={}){let t={...Tt,...e,weights:{...Tt.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,i)=>Rt(r,i,t,n,o),computeMatches:(r,i)=>Nt(r,i,t,n,o),explain:(r,i)=>kt(r,i,t,n),invalidate:r=>In(r,n,o),session:()=>{let r=new WeakMap,i=new WeakMap;return{findMatch:(a,s)=>Rt(a,s,t,r,i),computeMatches:(a,s)=>Nt(a,s,t,r,i),explain:(a,s)=>kt(a,s,t,r)}},getConfig:()=>({...t})}}function Ye(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 Lt(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var Ln=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Hn=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Pe(e){try{return JSON.parse(e)}catch{return JSON.parse(Pn(e))}}function Pn(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=Ye(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=Ye(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=Lt(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"||Ln.test(a)){t+=a,n=i;continue}if(Hn.test(a)){if(e[Ye(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function Ht(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 x=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(x=!0),!x){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 x=s,m=a+1;for(;m<r.length&&r[m]!==x;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:x}),a=m+1;continue}let c=a,M;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let x=[":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 x){let E=b.substring(1);if(r.substring(c+1,c+1+E.length)===E){m=!0,c+=E.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let x=r[c];for(c++;c<r.length&&r[c]!==x;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;M=r.substring(a,c);let w=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?w=t.NUMBER:M==="true"||M==="false"||M==="null"?w=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(w=t.SELECTOR),i.push({type:w,value:M,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=Lt(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 D=Symbol("hyper-morph-json-merge:missing"),Pt=["id","_id","uuid","key","slug","code","name"];function pe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Se(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function jn(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function ne(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(!ne(e[n],t[n]))return!1;return!0}if(pe(e)&&pe(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Se(t,o)||!ne(e[o],t[o]))return!1;return!0}return!1}function jt(e,t,n,o){return ne(t,n)?t:ne(t,e)?n:ne(n,e)?t:pe(t)&&pe(n)?_n(pe(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?Fn(Array.isArray(e)?e:[],t,n,o):n}function _t(e,t,n,o){return t===D&&n===D?D:t===D?e===D?n:ne(n,e)?D:n:n===D?e===D?t:D:jt(e,t,n,o)}function _n(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=_t(Se(e,a)?e[a]:D,Se(t,a)?t[a]:D,Se(n,a)?n[a]:D,o);s!==D&&jn(r,a,s)}return r}function $n(e){return e===null||typeof e!="object"}function je(e){return typeof e+":"+String(e)}function Dn(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Se(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=je(i);if(o.has(a))return!1;o.add(a)}}return!0}function Bn(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)pe(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(Dn(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!$n(c))return null;let M=je(c);if(s.has(M))return null;s.add(M)}}return{kind:"self"}}function Fn(e,t,n,o){let r=Bn(e,t,n,o);if(!r)return n;let i=r.kind==="self"?je:b=>je(b[r.field]),a=b=>{let E=new Map;for(let P of b)E.set(i(P),P);return E},s=a(e),c=a(t),M=a(n),w=new Map,x=new Set([...s.keys(),...c.keys(),...M.keys()]);for(let b of x){let E=_t(s.has(b)?s.get(b):D,c.has(b)?c.get(b):D,M.has(b)?M.get(b):D,o);E!==D&&w.set(b,E)}let m=[];for(let b of n){let E=i(b);w.has(E)&&m.push(E)}for(let b=0;b<t.length;b++){let E=i(t[b]);if(!w.has(E)||m.includes(E))continue;let P=0;for(let _=b-1;_>=0;_--){let j=m.indexOf(i(t[_]));if(j!==-1){P=j+1;break}}m.splice(P,0,E)}return m.map(b=>w.get(b))}function Ze(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...Pt]:Pt;return jt(e===void 0?D:e,t,n,{keyCandidates:r})}function Qe(e,t,n,o={}){let r=o.parse||Pe,i=[],a=(x,m)=>{if(typeof x!="string")return D;try{return r(x)}catch(b){return i.push(`${m} side is not valid JSON (${b.message})`),D}},s=a(t,"local"),c=a(n,"remote");if(s===D)return{text:n,warnings:i};if(c===D)return{text:t,warnings:i};let M=a(e,"base"),w=Ze(M===D?void 0:M,s,c,o);return ne(w,c)?{text:n,warnings:i}:ne(w,s)?{text:t,warnings:i}:{text:JSON.stringify(w,null,2),warnings:i}}var Xe=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=Ct({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"),T=p.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${T}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${T}:${N}`}else{let k=p.textContent.trim(),h=5381;for(let S=0;S<k.length;S++)h=(h<<5)+h^k.charCodeAt(S);return`inline:${T}:${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 M(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 w(p){let O=(p.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return O==="application/json"||O.endsWith("+json")}let x={match:p=>p.hasAttribute("merge"),identity:p=>p.getAttribute("merge")};function m(p,O,v){if(v.merge===!1)return null;let N=[x,...v.mergeTags||[]],T=new WeakMap,k=f=>{if(T.has(f))return T.get(f);let y=null;if(s(f)&&!f.getAttribute("src")&&!o(f)){let A=f;for(let R=0;R<N.length;R++)if(N[R].match(A)){if(!w(A))console.warn("[hyper-morph] merge ignored: script type is not JSON",A);else{let C=N[R].identity(A);C!=null&&C!==""&&(y={key:R+":"+C,raw:C,recognizer:N[R]})}break}}return T.set(f,y),y},h=new Set,S=f=>{let y=new Map,A=R=>{let C=k(R);C&&(y.has(C.key)?(h.add(C.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${C.raw}"`)):y.set(C.key,R))};s(f)&&A(f);for(let R of f.querySelectorAll("script"))A(R);return y},d=S(p),u=S(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 A=R=>{let C=k(R);C&&!l.has(C.key)&&l.set(C.key,R.textContent)};s(y)&&A(y);for(let R of y.querySelectorAll("script"))A(R);return l}}}function b(p,O,v){let N=p.merge;if(!N)return!1;let T=N.identityOf(O);if(!T||N.disabled.has(T.key))return!1;let k=N.identityOf(v);if(!k||k.key!==T.key)return!1;let h=O,S=v,d=S.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=Qe(N.baseTexts().get(T.key),h.textContent,S.textContent,{parse:T.recognizer.parse,keyCandidates:d?d.split(/[\s,]+/).filter(Boolean):void 0});for(let g of l)console.warn(`[hyper-morph] merge "${T.raw}": ${g}`);return h.textContent!==u&&(h.textContent=u),!0}let E={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},P={computeMatches(p,O){let{computeMatches:v}=r.session();return v(p,O)}};function _(p,O,v={}){p=en(p);let N=St(O),T=Xt(p,N,v),k=T.scripts.handle?new Set(Array.from(p.querySelectorAll("script")).map(u=>i(u,T.scripts.matchMode,T.merge))):null,h=L(T),S=Y(T,p,N,u=>u.morphStyle==="innerHTML"?(I(u,p,N),Array.from(p.childNodes)):B(u,p,N)),d=u=>{h&&F(T,h),j(T);let l=k?Qt(u,k,T):[];return l.length>0?Promise.all(l).then(()=>u):u};return S instanceof Promise?S.then(d):d(S)}function j(p){for(let O of Array.from(p.pantry.childNodes))p.callbacks.beforeNodeRemoved(O)!==!1&&p.callbacks.afterNodeRemoved(O);p.pantry.remove()}function B(p,O,v){let N=St(O);return I(p,N,v,O,O.nextSibling),Array.from(N.childNodes)}function L(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:T}=O;return{element:O,id:v,selectionStart:N,selectionEnd:T}}function F(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 A of g.childNodes){if(n(A))continue;if(f&&f!=y){let C=v(u,A,f,y);if(C){C!==f&&T(u,f,C),K(C,A,u),f=C.nextSibling;continue}}if(A instanceof Element){let C=A.getAttribute("id");if(u.persistentIds.has(C)){let $=k(l,C,f,u);K($,A,u),f=$.nextSibling;continue}if(!u.idMap.has(A)){let $=u.hyperMatches.get(A);if($&&!u.idMap.has($)&&!d($,l)){S(l,$,f),K($,A,u),f=$.nextSibling;continue}}}let R=O(l,A,f,u);R&&(f=R.nextSibling)}for(;f&&f!=y;){let A=f;f=f.nextSibling,n(A)||N(u,A)}}function O(u,l,g,f){if(f.callbacks.beforeNodeAdded(l)===!1)return null;if(f.idMap.has(l)){let y=l,A=document.createElementNS(y.namespaceURI,y.localName);return u.insertBefore(A,g),K(A,l,f),f.callbacks.afterNodeAdded(A),A}else{let y=M(document.importNode(l,!0));return u.insertBefore(y,g),f.callbacks.afterNodeAdded(y),y}}let v=function(){function u(f,y,A,R){let C=y instanceof Element&&!f.idMap.has(y)?f.hyperMatches.get(y):null,$=null,W=y.nextSibling,Z=0,H=A;for(;H&&H!=R;){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&&W&&g(H,W)&&(Z++,W=W.nextSibling,Z>=2&&($=void 0)),f.activeElementAndParents.includes(H))break;H=H.nextSibling}return $||null}function l(f,y,A){let R=f.idMap.get(y),C=f.idMap.get(A);if(!C||!R)return!1;for(let $ of R)if(C.has($))return!0;return!1}function g(f,y){let A=f,R=y;return A.nodeType===R.nodeType&&A.tagName===R.tagName&&(!A.getAttribute?.("id")||A.getAttribute?.("id")===R.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)S(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function T(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),S(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 S(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,S,d){return d.ignoreActive&&h===document.activeElement?null:(d.callbacks.beforeNodeMorphed(h,S)===!1||(h instanceof HTMLHeadElement&&d.head.ignore||(h instanceof HTMLHeadElement&&d.head.style!=="morph"?se(h,S,d):(O(h,S,d),b(d,h,S)||k(h,d)||I(d,h,S))),d.callbacks.afterNodeMorphed(h,S)),h)}function O(h,S,d){let u=S.nodeType;if(u===1){let l=h,g=S,f=l.attributes,y=g.attributes;for(let A of y)T(A.name,l,"update",d)||l.getAttribute(A.name)!==A.value&&l.setAttribute(A.name,A.value);for(let A=f.length-1;0<=A;A--){let R=f[A];if(R&&!g.hasAttribute(R.name)){if(T(R.name,l,"remove",d))continue;l.removeAttribute(R.name)}}k(l,d)||v(l,g,d)}(u===8||u===3)&&h.nodeValue!==S.nodeValue&&(h.nodeValue=S.nodeValue)}function v(h,S,d){if(h instanceof HTMLInputElement&&S instanceof HTMLInputElement&&S.type!=="file"){let u=S.value,l=h.value;N(h,S,"checked",d),N(h,S,"disabled",d),d.formStateSync==="property"&&h.indeterminate!==S.indeterminate&&(h.indeterminate=S.indeterminate),d.formStateSync==="property"?l!==u&&(T("value",h,"update",d)||(h.value=u)):S.hasAttribute("value")?l!==u&&(T("value",h,"update",d)||(h.setAttribute("value",u),h.value=u)):T("value",h,"remove",d)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&S instanceof HTMLOptionElement)N(h,S,"selected",d);else if(h instanceof HTMLTextAreaElement&&S instanceof HTMLTextAreaElement){let u=S.value,l=h.value;if(T("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,S,d,u){let l=S[d],g=h[d];if(l!==g){let f=T(d,h,"update",u);if(f||(h[d]=S[d]),u.formStateSync==="property")return;l?f||h.setAttribute(d,""):T(d,h,"remove",u)||h.removeAttribute(d)}}function T(h,S,d,u){return h==="value"&&u.ignoreActiveValue&&S===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,S,d)===!1}function k(h,S){return!!S.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return p}();function Y(p,O,v,N){if(p.head.block){let T=O.querySelector("head"),k=v.querySelector("head");if(T&&k){let h=se(T,k,p);return Promise.all(h).then(()=>(p.head.block=!1,p.head.ignore=!0,N(p)))}}return N(p)}function fe(p){return p.tagName==="SCRIPT"?!!p.getAttribute("src"):p.tagName==="LINK"?(p.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!p.getAttribute("href"):!1}function se(p,O,v){let N=[],T=[],k=[],h=[],S=v.scripts.matchMode,d=g=>{if(g.tagName==="SCRIPT")return i(g,S,v.merge);if(g.tagName==="LINK"&&S==="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),A=!!(y&&y.length),R=v.head.shouldReAppend(g),C=v.head.shouldPreserve(g);if(A||C)if(R)T.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"?R&&(T.push(g),h.push(g)):v.head.shouldRemove(g)!==!1&&!n(g)&&T.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&&fe(f)){let y,A=new Promise(function(R){y=R});f.addEventListener("load",function(){y()}),f.addEventListener("error",function(){y()}),l.push(A)}p.appendChild(f),v.callbacks.afterNodeAdded(f),N.push(f)}}for(let g of T)v.callbacks.beforeNodeRemoved(g)!==!1&&(p.removeChild(g),v.callbacks.afterNodeRemoved(g));return v.head.afterHeadMorphed(p,{added:N,kept:k,removed:T}),l}function Qt(p,O,v){if(!v.scripts.handle)return[];let N=[],T=[],k=[],h=[],S=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,S,v.merge),f=O.has(g),y=v.scripts.shouldPreserve(l),A=v.scripts.shouldReAppend(l);f||y?A?(T.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(A){f=A});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:T}),u}let Xt=function(){function p(d,u,l){let{persistentIds:g,idMap:f}=h(d,u),y=P.computeMatches(d,u);if(typeof l.key=="function"){let W=new Map,Z=new Set,H=U=>{let q=l.key(U);q!=null&&(W.has(q)?Z.add(q):W.set(q,U))};d instanceof Element&&H(d);for(let U of d.querySelectorAll("*"))H(U);for(let U of Z)W.delete(U);let z=new Map;for(let[U,q]of y)z.set(q,U);let ie=u.__hyperMorphRoot||u,ee=new Map,Et=new Set,Mt=U=>{let q=l.key(U);q!=null&&(ee.has(q)?Et.add(q):ee.set(q,U))};ie instanceof Element&&Mt(ie);for(let U of ie.querySelectorAll("*"))Mt(U);for(let U of Et)ee.delete(U);for(let[U,q]of ee){let de=W.get(U);if(!de||de.tagName!==q.tagName)continue;let Fe=z.get(de);Fe&&Fe!==q&&y.delete(Fe);let Ue=y.get(q);Ue&&Ue!==de&&z.delete(Ue),y.set(q,de),z.set(de,q)}}let A=O(l),R=m(d,u,A.scripts);if(R){let W=new Map;for(let[Z,H]of y)W.set(H,Z);for(let[Z,H]of R.newByKey){if(R.disabled.has(Z))continue;let z=R.oldByKey.get(Z);if(!z)continue;let ie=W.get(z);ie&&ie!==H&&y.delete(ie);let ee=y.get(H);ee&&ee!==z&&W.delete(ee),y.set(H,z),W.set(z,H)}}let C=new Set;for(let W of y.values())C.add(W);let $=A.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes($))throw new Error(`Do not understand how to morph style ${$}`);return{target:d,newContent:u,config:A,morphStyle:$,ignoreActive:A.ignoreActive,ignoreActiveValue:A.ignoreActiveValue,restoreFocus:A.restoreFocus,formStateSync:A.formStateSync||"attribute",idMap:f,persistentIds:g,hyperMatches:y,hyperMatchedOldElements:C,merge:R,pantry:v(),activeElementAndParents:N(d),callbacks:A.callbacks,head:A.head,scripts:A.scripts}}function O(d){let u=Object.assign({},E);return Object.assign(u,d),u.callbacks=Object.assign({},E.callbacks,d.callbacks),u.head=Object.assign({},E.head,d.head),u.scripts=Object.assign({},E.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 T(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 A=f;for(;A;){let R=d.get(A);if(R==null&&(R=new Set,d.set(A,R)),R.add(y),A===l)break;A=A.parentElement}}}}function h(d,u){let l=T(d),g=T(u),f=S(l,g),y=new Map;k(y,f,d,l);let A=u.__hyperMorphRoot||u;return k(y,f,A,g),{persistentIds:f,idMap:y}}function S(d,u){let l=new Set,g=new Map;for(let y of d){let A=y.getAttribute("id");g.has(A)?l.add(A):g.set(A,y.tagName)}let f=new Set;for(let y of u){let A=y.getAttribute("id");f.has(A)?l.add(A):g.get(A)===y.tagName&&f.add(A)}for(let y of l)f.delete(y);return f}return p}(),{normalizeElement:en,normalizeParent:St}=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 S=document.createElement("div");return S.append(h),S}}else{let S=document.createElement("div");for(let d of[...h])S.append(d);return S}}class N{constructor(S){this.originalNode=S,this.realParentNode=S.parentNode,this.previousSibling=S.previousSibling,this.nextSibling=S.nextSibling}get childNodes(){let S=[],d=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;d&&d!=this.nextSibling;)S.push(d),d=d.nextSibling;return S}querySelectorAll(S){return this.childNodes.reduce((d,u)=>{if(u instanceof Element){u.matches(S)&&d.push(u);let l=u.querySelectorAll(S);for(let g=0;g<l.length;g++)d.push(l[g])}return d},[])}insertBefore(S,d){return this.realParentNode.insertBefore(S,d)}moveBefore(S,d){return this.realParentNode.moveBefore(S,d)}get __hyperMorphRoot(){return this.originalNode}}function T(h){let S=g=>`<${g}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,d=h.replace(/<!--[\s\S]*?-->/g,"");for(let g of["script","style","textarea","title"])d=d.replace(new RegExp(`${S(g)}[\\s\\S]*?</${g}\\s*>`,"gi"),"");let u=new RegExp(`${S("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=d,d=d.replace(u,"");while(d!==l);return d}function k(h){let S=new DOMParser,d=T(h);if(d.match(/<\/html>/)||d.match(/<\/head>/)||d.match(/<\/body>/)){let u=S.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=S.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return p.add(l),l}}return{normalizeElement:O,normalizeParent:v}}();return{morph:_,defaults:E,mergeJson:Ze,mergeScriptText:Qe,parseJsonRelaxed:Pe,parseRulesRelaxed:Ht}}();var Or=Xe.morph,Tr=Xe.defaults;var $t=Xe;function et(e,t,{onWidgetRemoved:n}={}){$t.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Le.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var qn="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 tt(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Dt(e,t){let n=tt(e),o=tt(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 Wn(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Vn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function nt({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 M=`${qn}${c.href}:${s||"none"}`,w,x=e?null:Wn(M);if(x&&typeof x.checkedAt=="number"&&r-x.checkedAt<i)w=x.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let b=await m.text(),E=new DOMParser().parseFromString(b,"text/html");w=Q(E,"hyper-version")}catch{w=null}Vn(M,{checkedAt:r,sourceVersion:w})}return w?{available:Dt(w,s||"0.0.0"),currentVersion:s,sourceVersion:w,sourceUrl:c.href}:null}var _e=["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"],rt=new Set(_e),Bt=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Ft=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var $e={};We($e,{EmptyListInsert:()=>Me,MAX_RULE_DEPTH:()=>ge,MaxRuleDepthExceeded:()=>ce,RuleTargetReadOnly:()=>xe,RulesParseError:()=>me,ShapeMismatch:()=>Ee,UnknownRulesVersion:()=>ae});var me=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},ae=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},ge=20,ce=class extends Error{constructor(t){super(`rule depth exceeded ${ge} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},Ee=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Me=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}},xe=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 ot(e,t,n,{depth:0,path:[]},o)}function ot(e,t,n,o,r){if(o.depth>ge)throw new ce(o.path);if(typeof n=="string")return Kn(e,t,n,r);if(Array.isArray(n)){let[i,a]=n;return e.find(t,i,r).map((c,M)=>ot(e,c,a,{depth:o.depth+1,path:[...o.path,M]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[a,s]of Object.entries(n))i[a]=ot(e,t,s,{depth:o.depth+1,path:[...o.path,a]},r);return i}return null}function Kn(e,t,n,o){if(n.endsWith("[]")){let i=n.slice(0,-2);return e.find(t,i,o).map(a=>e.text(a))}if(n.startsWith("@"))return Ut(e,t,n.slice(1));if(n.includes("@")){let i=n.lastIndexOf("@"),a=n.slice(0,i),s=n.slice(i+1),c=a?e.find(t,a,o):[t];return c.length===0?null:Ut(e,c[0],s)}if(n===".")return e.text(t);let r=e.find(t,n,o);return r.length===0?null:e.text(r[0])}function Ut(e,t,n){if(rt.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 Jn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Gn={find(e,t,n={}){let o=Jn(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}},V=Gn;function st(e){try{return JSON.parse(e)}catch(t){throw new me(`Invalid strict JSON: ${t.message}`,t)}}function le(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 x=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(x=!0),!x){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 x=s,m=a+1;for(;m<r.length&&r[m]!==x;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:x}),a=m+1;continue}let c=a,M;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let x=[":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 x){let E=b.substring(1);if(r.substring(c+1,c+1+E.length)===E){m=!0,c+=E.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let x=r[c];for(c++;c<r.length&&r[c]!==x;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;M=r.substring(a,c);let w=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?w=t.NUMBER:M==="true"||M==="false"||M==="null"?w=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(w=t.SELECTOR),i.push({type:w,value:M,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,(M,w)=>w.length%2===0?w+'\\"':M)),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 me("Invalid extraction rules syntax: "+r.message,r)}}var it="1",qt=/^[a-zA-Z0-9_-]+$/;function ye(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!qt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${qt})`);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!==it)throw new ae(a);return{rules:le(e.text(i)),tagNode:i}}var Yn="script[data-rules-name]";function Wt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function we(e,t){let n=e.find(t,Yn,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=Wt(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!==it)throw new ae(s);o.add(a),r.push({name:a,rules:le(e.text(i))})}return r}function De(e,t){let n={};for(let{name:o,rules:r}of we(e,t))n[o]=X(e,t,r);return n}function at(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:De(V,t),version:Q(n,"hyper-version")}}var be=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},ve=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}},re=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Oe=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 Vt="text/hyper-upgrade";function ct(e,t){let n=e.find(t,`script[type="${Vt}"]`);if(n.length===0)return null;if(n.length>1)throw new Oe(n.length);return e.text(n[0])||null}var Zn=new Function("url","return import(url)");async function lt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Zn(n)}catch(r){throw new re(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new re("transform must `export default` a function");return o.default}var Qn=.5;function ut(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(L=>e.remove(L));return}let M=r.length>c.length,w=c[0]||null;if(M&&!w&&(w=rr(e,t,n,s),!w))throw new Me(i.path);let x=c.map(L=>Xn(e,L,o,s)),m=null;if(w){m=e.clone(w),s.templateAttr&&e.removeAttr(m,s.templateAttr);let L=e.stripIds(m);L>0&&console.warn(`[hyper-html-api] stripped ${L} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let b=er(r,x,o),E=c[0]||w,P=e.parent(E),_=c.length>0?nr(e,P,E):0,j=new Set,B=r.map((L,F)=>{let I=b[F];if(I>=0)return j.add(I),c[I];let K=e.clone(m);return e.stripIds(K),K});c.forEach((L,F)=>{j.has(F)||e.remove(L)}),B.forEach((L,F)=>{let I=_+F;e.children(P).findIndex(fe=>e.sameNode(fe,L))!==I&&e.insertAt(P,L,I)}),B.forEach((L,F)=>{if(o===null){let I=r[F],K=I==null?"":String(I);e.text(L)!==K&&e.text(L,K)}else{let I=a(e,L,o,r[F],{depth:i.depth+1,path:[...i.path,F]},s);I&&I!==L&&(B[F]=I)}})}function Xn(e,t,n,o){return n===null?e.text(t):X(e,t,n,o)}function er(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((M,w)=>{if(r.has(w))return;let x=tr(i,M,n),m=x===c&&s>=0?Math.abs(w-a)<Math.abs(s-a):!1;(x>c||m)&&(c=x,s=w)}),c>=Qn&&(o[a]=s,r.add(s))}),o}function tr(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 nr(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 rr(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}var Kt=new Set(["checked","selected","disabled","readOnly","paused"]);function oe(e,t,n,o,r={}){let i=[];if(ft(n,o,[],i),i.length)throw new Ee(i);Be(e,t,n,o,{depth:0,path:[]},r)}function Be(e,t,n,o,r,i={}){if(r.depth>ge)throw new ce(r.path);if(o===void 0)return t;if(typeof n=="string")return or(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return ut(e,t,a,s,o,r,Be,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=Be(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 or(e,t,n,o,r,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return ut(e,t,s,null,o,r,Be,i),t}if(n.startsWith("@"))return zt(e,t,n.slice(1),o);if(n.includes("@")){let s=n.lastIndexOf("@"),c=n.slice(0,s),M=n.slice(s+1),w=c?e.find(t,c,i):[t];return w.length===0||zt(e,w[0],M,o),t}if(n===".")return e.text(t,o==null?"":String(o)),t;let a=e.find(t,n,i);return a.length===0||e.text(a[0],o==null?"":String(o)),t}function zt(e,t,n,o){if(Ft.has(n))throw new xe(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return Bt.has(n)?(e.prop(t,n,sr(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function sr(e,t){return t==null?Kt.has(e)?!1:"":Kt.has(e)?!!t:t}function ft(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:Re([...n,i]),expected:"scalar",got:Te(r)})}):o.push({path:Re(n),expected:"array",got:Te(t)});return}t!==null&&typeof t=="object"&&o.push({path:Re(n),expected:"scalar",got:Te(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Re(n),expected:"array",got:Te(t)});return}let r=e[1];t.forEach((i,a)=>ft(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Re(n),expected:"object",got:Te(t)});return}for(let[r,i]of Object.entries(e))ft(i,t[r],[...n,r],o)}}}function Te(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Re(e){return e.join(".")}function Ne(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=dt(t,e,n);return ht(t,e,n),{data:o,summary:n}}function dt(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=>dt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=dt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function ht(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)?ht(e[r],t[r],n):n.discarded+=ue(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>ht(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=ue(t))}}function ue(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+ue(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+ue(n),0):1}function pt(e,t,n){let o=we(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:M,summary:w}=Ne(n[s],c);oe(e,t,c,M),i[s]=w,r.carriedOver+=w.carriedOver,r.discarded+=w.discarded,r.listItems+=w.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=ue(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function mt({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||(j=>fetch(j)),!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||De(V,o);let s;try{s=await i(a.href)}catch(j){throw new be(a.href,j)}if(!s.ok)throw new be(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),M=new DOMParser().parseFromString(c,"text/html"),w=Q(M,"hyper-version"),x=t,m=!1,b=ct(V,M);if(b){let B=await(await lt(b))(x,{fromVersion:n,toVersion:w});if(!B||typeof B!="object"||Array.isArray(B))throw new re("transform must return a plain object map of { rulesName: data }");x=B,m=!0}let{totals:E,byName:P,rulesTagCount:_}=pt(V,M,x);if(_===0&&Object.keys(x).length>0)throw new ve(a.href);return{html:ir(M),fromVersion:n,toVersion:w,summary:{transformApplied:m,totals:E,byName:P}}}function ir(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
4
+ `+e.documentElement.outerHTML}function gt(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 ye(e,o,n)}return null}function Jt(e,t,n,o){let r=gt(e,t,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:a}=r;return{rules:i,tagNode:a,get:()=>X(e,t,i,o),set:s=>oe(e,t,i,s,o)}}var ke={extract:(e,t,n)=>X(V,e,t,n),apply:(e,t,n,o)=>oe(V,e,t,n,o),findRulesIn:(e,t)=>ye(V,e,t),findRules:(e,t)=>gt(V,e,t),bind:(e,t,n)=>Jt(V,e,t,n),parseStrict:st,parseRelaxed:le,errors:$e,DOM_PROPERTIES:_e},yt=e=>!!e&&typeof e.nodeType=="number";function Gt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=V.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 ye(V,t).rules}function bt(e,t){let n=yt(e)?e:document,o=yt(e)?t:e;return o===void 0?X(V,n,Gt(n)):ke.bind(n,o).get()}function At(e,t,n){if(!yt(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?oe(V,e,Gt(e),t):ke.bind(e,n).set(t),e}var Yt={buildForm:Ke,bindFormEvents:ze,scaffold:he,morphForm:et,path:Ce},Zt={checkForUpdate:nt,run:mt,extractAll:at,shapeMatch:Ne};var lr={engine:ke,cms:Yt,upgrade:Zt,extractData:bt,applyData:At},ur=lr;return sn(fr);})();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "apply",
10
10
  "CMS"
11
11
  ],
12
- "version": "0.5.0",
12
+ "version": "0.5.2",
13
13
  "homepage": "https://github.com/panphora/hyper-html-api",
14
14
  "bugs": {
15
15
  "url": "https://github.com/panphora/hyper-html-api/issues"
@@ -38,6 +38,7 @@
38
38
  "build:engine": "npx esbuild src/data.js --bundle --minify --format=iife --global-name=hyperHtmlApiData --outfile=dist/hyper-html-api.engine.min.js",
39
39
  "build:upgrade": "npx esbuild src/upgrade.js --bundle --minify --format=iife --global-name=hyperHtmlApiUpgrade --outfile=dist/hyper-html-api.upgrade.min.js",
40
40
  "copy-to-hyperclayjs": "npm run build:engine && npm run build:upgrade && node scripts/copy-to-hyperclayjs.js",
41
+ "copy-to-clayjs": "npm run build:engine && node scripts/copy-to-clayjs.js",
41
42
  "prepublishOnly": "npm run build",
42
43
  "demo": "http-server . -p 5693 -c-1 -o /demo/",
43
44
  "test": "web-test-runner",
@@ -57,7 +58,7 @@
57
58
  "url": "git+https://github.com/panphora/hyper-html-api.git"
58
59
  },
59
60
  "dependencies": {
60
- "hyper-morph": "^0.3.0"
61
+ "hyper-morph": "^0.4.0"
61
62
  },
62
63
  "devDependencies": {
63
64
  "@web/test-runner": "^0.20.0",
@@ -72,5 +73,10 @@
72
73
  "mocha": "^11.0.1",
73
74
  "prettier": "^3.4.2",
74
75
  "sinon": "^9.2.4"
76
+ },
77
+ "hyper": {
78
+ "kind": "lib",
79
+ "status": "active",
80
+ "url": "https://github.com/panphora/hyper-html-api"
75
81
  }
76
82
  }