hyper-html-api 0.8.0 → 0.8.1

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
@@ -48,6 +48,16 @@ extracts data and `set(data)` writes it back. Token resolution is
48
48
  document-scoped, so a tag mounted in `<head>` is found even when `bind` is given
49
49
  a body or form element; `get()`/`set()` stay scoped to that element.
50
50
 
51
+ DOM bound operations exclude `no-data` and `editor-ui` regions by default.
52
+ Both bare attributes and `clay` tokens work, and the exclusion is inherited by
53
+ descendants. The filtered structure is shared by selectors, text and HTML
54
+ reads, cloning, row matching, and insertion coordinates. Writes still update
55
+ the corresponding live authored nodes. Pass `{ exclude: '.selector' }` to add a
56
+ consumer exclusion, or `{ exclude: null }` for an explicit raw view such as a
57
+ CMS reading its own form controls. The generic engine remains adapter neutral.
58
+ The Cheerio adapter rejects semantic `exclude` options because it does not yet
59
+ implement the same structural contract.
60
+
51
61
  ## Upgrade
52
62
 
53
63
  A page that was copied from a template can pull in the template's newer
@@ -1 +1 @@
1
- var hyperHtmlApiData=(()=>{var q=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var Ot=Object.prototype.hasOwnProperty;var nt=(t,e)=>{for(var n in e)q(t,n,{get:e[n],enumerable:!0})},wt=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of At(e))!Ot.call(t,r)&&r!==n&&q(t,r,{get:()=>e[r],enumerable:!(o=Rt(e,r))||o.enumerable});return t};var St=t=>wt(q({},"__esModule",{value:!0}),t);var vt={};nt(vt,{applyData:()=>et,default:()=>Ut,engine:()=>k,extractData:()=>tt});var W=["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"],F=new Set(W),rt=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),ot=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var B={};nt(B,{EmptyListInsert:()=>P,MAX_RULE_DEPTH:()=>b,MaxRuleDepthExceeded:()=>S,RuleTargetReadOnly:()=>j,RulesParseError:()=>T,ShapeMismatch:()=>D,UnknownRulesVersion:()=>_});var T=class extends Error{constructor(e,n){super(e),this.name="RulesParseError",this.cause=n}},_=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=e}},b=20,S=class extends Error{constructor(e){super(`rule depth exceeded ${b} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},D=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},P=class extends Error{constructor(e){super(`cannot add items to empty list at "${e.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=e}},j=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}};function A(t){let e=0,n=null,o=-1;for(let r=0;r<t.length;r++){let i=t[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?e++:i==="]"||i===")"?e>0&&e--:i==="@"&&e===0&&(o=r)}return o}function K(t){let e=A(t);return e===-1?{selector:t,prop:null}:{selector:t.slice(0,e),prop:t.slice(e+1)||null}}function O(t,e,n,o={}){return G(t,e,n,{depth:0,path:[]},o)}function G(t,e,n,o,r){if(o.depth>b)throw new S(o.path);if(typeof n=="string")return xt(t,e,n,o,r);if(Array.isArray(n)){let[i,f]=n,s=t.find(e,i,r);return st(r,o,s),s.map((l,c)=>G(t,l,f,{depth:o.depth+1,path:[...o.path,c]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[f,s]of Object.entries(n))i[f]=G(t,e,s,{depth:o.depth+1,path:[...o.path,f]},r);return i}return null}function xt(t,e,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),l=t.find(e,s,r);return st(r,o,l),l.map(c=>t.text(c))}if(n.startsWith("@"))return it(t,e,n.slice(1));let i=A(n);if(i!==-1){let s=n.slice(0,i),l=n.slice(i+1),c=s?t.find(e,s,r):[e];return c.length===0?null:it(t,c[0],l)}if(n===".")return t.text(e);let f=t.find(e,n,r);return f.length===0?null:t.text(f[0])}function st(t,e,n){if(typeof t.onRowsRead=="function")try{t.onRowsRead(e.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${e.path.join(".")||"(root)"}"`,o)}}function it(t,e,n){if(F.has(n)){let r=t.prop(e,n);return r==null?null:String(r)}let o=t.attr(e,n);return o||null}function ct(t,e,n,o){let r=t.length,i=e.length,f=new Array(r).fill(-1);if(o){let u=new Set;for(let d=0;d<r;d++){let g=o[d];!(g>=0&&g<i)||u.has(g)||(f[d]=g,u.add(g))}}if(r===0||i===0)return f;let s=t.map(u=>lt(u,n)),l=e.map(u=>lt(u,n)),c=new Array(i).fill(!1);for(let u of f)u>=0&&(c[u]=!0);let p=new Map;l.forEach((u,d)=>{c[d]||p.set(u,p.has(u)?-1:d)});let a=new Map;s.forEach((u,d)=>{f[d]>=0||a.set(u,(a.get(u)||0)+1)}),s.forEach((u,d)=>{if(f[d]>=0||a.get(u)!==1)return;let g=p.get(u);g===void 0||g===-1||c[g]||(f[d]=g,c[g]=!0)});let h=[];for(let u=0;u<r;u++)f[u]<0&&h.push(u);let E=[];for(let u=0;u<i;u++)c[u]||E.push(u);if(h.length===0||E.length===0)return f;let y=r*i+1,w=(u,d)=>Tt(t[u],e[d],n)*y+Math.abs(u-d);for(let[u,d]of bt(h,E,w))f[u]=d;return f}var ut=t=>typeof t=="object"&&t!==null;function lt(t,e){if(!ut(e))return t==null?" null":String(t);let n=Object.keys(e);return JSON.stringify(n.map(o=>{let r=JSON.stringify(t?.[o]);return r===void 0?" undef":r}))}function Tt(t,e,n){if(!ut(n))return t===e?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let f=JSON.stringify(t?.[i]),s=JSON.stringify(e?.[i]);f!==s&&r++}return r}function bt(t,e,n){return t.length<=e.length?ft(t,e,n,!1):ft(e,t,(o,r)=>n(r,o),!0)}function ft(t,e,n,o){let r=t.length,i=e.length,f=[];for(let a=0;a<=r;a++)f.push(new Float64Array(i+1).fill(1/0));let s=[];for(let a=0;a<=r;a++)s.push(new Uint8Array(i+1));for(let a=0;a<=i;a++)f[r][a]=0;for(let a=r-1;a>=0;a--)for(let h=i-1;h>=0;h--){let E=n(t[a],e[h])+f[a+1][h+1],y=f[a][h+1];E<=y?(f[a][h]=E,s[a][h]=1):f[a][h]=y}let l=[],c=0,p=0;for(;c<r&&p<i;)s[c][p]&&(l.push(o?[e[p],t[c]]:[t[c],e[p]]),c++),p++;return l}function X(t,e,n,o,r,i,f,s={}){let l=t.find(e,n,s);if(r.length===0){l.forEach(m=>t.remove(m)),V(s,"onRowsApplied",i.path,[]);return}let c=r.length>l.length,p=l[0]||null;if(c&&!p&&(p=_t(t,e,n,s),!p))throw new P(i.path);let a=l.map(m=>Mt(t,m,o,s)),h=null;if(c&&p){h=t.clone(p),s.templateAttr&&t.removeAttr(h,s.templateAttr);let m=t.stripIds(h);m>0&&console.warn(`[hyper-html-api] stripped ${m} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let E=ct(r,a,o,Nt(t,l,r,i,s)),y=l[0]||p,w=t.parent(y),u=l.length>0?at(t,w,y):0,d=Dt(t,l),g=new Set,v=[],H=r.map((m,M)=>{let x=E[M];if(x>=0)return g.add(x),v.push(!1),l[x];v.push(!0);let J=t.clone(h);return t.stripIds(J),J});l.forEach((m,M)=>{g.has(M)||t.remove(m)}),d?H.forEach((m,M)=>{let x=u+M;t.children(w).findIndex(Et=>t.sameNode(Et,m))!==x&&t.insertAt(w,m,x)}):Pt(t,H,v,w,u),It(t,H,o,r,i,f,s),V(s,"onRowsApplied",i.path,H)}function V(t,e,n,o){if(typeof t[e]=="function")try{return t[e](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${e} threw at "${n.join(".")||"(root)"}"`,r);return}}function Nt(t,e,n,o,r){let i=V(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let f=new Array(n.length).fill(-1),s=new Set;for(let l=0;l<n.length;l++)if(i[l]){for(let c=0;c<e.length;c++)if(!(s.has(c)||!t.sameNode(e[c],i[l]))){f[l]=c,s.add(c);break}}return f}function It(t,e,n,o,r,i,f){e.forEach((s,l)=>{if(n===null){let c=o[l],p=c==null?"":String(c);t.text(s)!==p&&t.text(s,p)}else{let c=i(t,s,n,o[l],{depth:r.depth+1,path:[...r.path,l]},f);c&&c!==s&&(e[l]=c)}})}function Mt(t,e,n,o){return n===null?t.text(e):O(t,e,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function at(t,e,n){let o=t.children(e);for(let r=0;r<o.length;r++)if(t.sameNode(o[r],n))return r;return-1}function _t(t,e,n,o){if(!o.templateAttr)return null;let r=e;for(;r;){let i=t.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let f of i)if(t.attr(f,o.templateAttr)!=null)return f;r=t.parent(r)}return null}function Dt(t,e){if(e.length<=1)return!0;let n=t.parent(e[0]);if(!n)return!1;let o=t.children(n),r=[];for(let i of e){let f=o.findIndex(s=>t.sameNode(s,i));if(f===-1)return!1;r.push(f)}return r.sort((i,f)=>i-f),r[r.length-1]-r[0]===r.length-1}function Pt(t,e,n,o,r){let i=null,f=r;for(let s=0;s<e.length;s++){if(!n[s]){i=e[s];continue}let l=i?t.parent(i):o;if(!l)continue;let c=i?at(t,l,i)+1:f++;t.insertAt(l,e[s],c),i=e[s]}}var ht=new Set(["checked","selected","disabled","readOnly","paused"]);function N(t,e,n,o,r={}){let i=[];if(z(n,o,[],i),i.length)throw new D(i);U(t,e,n,o,{depth:0,path:[]},r)}function U(t,e,n,o,r,i={}){if(r.depth>b)throw new S(r.path);if(o===void 0)return e;if(typeof n=="string")return jt(t,e,n,o,r,i);if(Array.isArray(n)){let[f,s]=n;return X(t,e,f,s,o,r,U,i),e}if(typeof n=="object"&&n!==null){for(let[f,s]of Object.entries(n)){let l=U(t,e,s,o==null?o:o[f],{depth:r.depth+1,path:[...r.path,f]},i);l&&l!==e&&(e=l)}return e}return e}function jt(t,e,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return X(t,e,l,null,o,r,U,i),e}if(n.startsWith("@"))return dt(t,e,n.slice(1),o);let f=A(n);if(f!==-1){let l=n.slice(0,f),c=n.slice(f+1),p=l?t.find(e,l,i):[e];return p.length===0||dt(t,p[0],c,o),e}if(n===".")return pt(t,e,o),e;let s=t.find(e,n,i);return s.length===0||pt(t,s[0],o),e}function pt(t,e,n){let o=n==null?"":String(n);t.text(e)!==o&&t.text(e,o)}function dt(t,e,n,o){if(ot.has(n))throw new j(n);if(n==="outerHTML"){let r=o==null?"":String(o);return t.replaceWith(e,r)}return rt.has(n)?(t.prop(e,n,Ct(n,o)),e):(t.attr(e,n,o==null?"":String(o)),e)}function Ct(t,e){return e==null?ht.has(t)?!1:"":ht.has(t)?e==="false"?!1:!!e:e}function z(t,e,n,o){if(e!==void 0){if(typeof t=="string"){if(t.endsWith("[]")){Array.isArray(e)?e.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:L([...n,i]),expected:"scalar",got:C(r)})}):o.push({path:L(n),expected:"array",got:C(e)});return}e!==null&&typeof e=="object"&&o.push({path:L(n),expected:"scalar",got:C(e)});return}if(Array.isArray(t)){if(!Array.isArray(e)){o.push({path:L(n),expected:"array",got:C(e)});return}let r=t[1];e.forEach((i,f)=>z(r,i,[...n,f],o));return}if(typeof t=="object"&&t!==null){if(e===null||Array.isArray(e)||typeof e!="object"){o.push({path:L(n),expected:"object",got:C(e)});return}for(let[r,i]of Object.entries(t))z(i,e[r],[...n,r],o)}}}function C(t){return t===null?"null":Array.isArray(t)?"array":typeof t}function L(t){return t.join(".")}function Q(t){try{return JSON.parse(t)}catch(e){throw new T(`Invalid strict JSON: ${e.message}`,e)}}function $(t){try{return JSON.parse(t)}catch{}let e={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=[],f=0;for(;f<r.length;){let s=r[f];if(/\s/.test(s)){f++;continue}if("{}".includes(s)){i.push({type:s,value:s}),f++;continue}if(s==="["){let a=!1,h=f+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(a=!0),!a){i.push({type:s,value:s}),f++;continue}}if(s==="]"){i.push({type:s,value:s}),f++;continue}if(s===":"){i.push({type:e.COLON,value:s}),f++;continue}if(s===","){i.push({type:e.COMMA,value:s}),f++;continue}if(s==='"'||s==="'"){let a=s,h=f+1;for(;h<r.length&&r[h]!==a;)r[h]==="\\"&&h++,h++;i.push({type:e.STRING,value:r.substring(f+1,h),quoted:!0,sourceQuote:a}),f=h+1;continue}let l=f,c;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let a=[":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"],h=!1;for(let E of a){let y=E.substring(1);if(r.substring(l+1,l+1+y.length)===y){h=!0,l+=y.length;break}}if(!h)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let a=r[l];for(l++;l<r.length&&r[l]!==a;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;c=r.substring(f,l);let p=e.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?p=e.NUMBER:c==="true"||c==="false"||c==="null"?p=e.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(p=e.SELECTOR),i.push({type:p,value:c,quoted:!1}),f=l}return i}function o(r){let i="";for(let f=0;f<r.length;f++){let s=r[f];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===e.COLON){i+=s.value;continue}if(s.type===e.COMMA){let l=r[f+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===e.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(c,p)=>p.length%2===0?p+'\\"':c)),i+=`"${l}"`;continue}if(s.type===e.NUMBER||s.type===e.BOOLEAN){i+=s.value;continue}if(s.type===e.SELECTOR||s.type===e.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(t),i=o(r);return JSON.parse(i)}catch(r){throw new T("Invalid extraction rules syntax: "+r.message,r)}}var Lt="1",gt=/^[a-zA-Z0-9_-]+$/;function I(t,e,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!gt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${gt})`);o=`script[data-rules-name~="${n}"]`}let r=t.find(e,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],f=t.attr(i,"data-rules-version");if(f!==Lt)throw new _(f);return{rules:$(t.text(i)),tagNode:i}}function Y(t,e,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=e&&e.ownerDocument?e.ownerDocument:e;return I(t,o,n)}return null}function mt(t,e,n,o){let r=Y(t,e,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:f}=r;return{rules:i,tagNode:f,get:()=>O(t,e,i,o),set:s=>N(t,e,i,s,o)}}function kt(t){return t&&t.nodeType===1&&t.tagName==="SCRIPT"&&t.hasAttribute&&t.hasAttribute("data-rules-name")}function Ht(t){return t?(t.nodeType===9||t.nodeType===11,t):null}var Wt={find(t,e,n={}){let o=Ht(t);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(e));n.includeRulesTag||(r=r.filter(s=>!kt(s)));let i=[];n.skip&&i.push(n.skip);let f=n.templateAttr===null?null:n.templateAttr||"cms-template";if(f&&i.push("["+f+"]"),i.length){let s=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(s))}return r},parent(t){return t?t.parentElement:null},children(t){return t?Array.from(t.children):[]},text(t,e){if(e===void 0)return(t.textContent||"").trim();t.textContent=e},attr(t,e,n){if(n===void 0)return t.hasAttribute&&t.hasAttribute(e)?t.getAttribute(e):null;t.setAttribute(e,n)},removeAttr(t,e){t&&t.removeAttribute&&t.removeAttribute(e)},prop(t,e,n){if(n===void 0){let o=t?t[e]:void 0;return o!==void 0?o:null}t[e]=n},clone(t){return t.cloneNode(!0)},insertAt(t,e,n){let o=t.children[n]||null;t.insertBefore(e,o)},remove(t){t&&t.parentNode&&t.parentNode.removeChild(t)},replaceWith(t,e){if(!t||!t.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=t.ownerDocument.createElement("template");o.innerHTML=e;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return t.parentNode.replaceChild(r,t),r},stripIds(t){let e=0;return t.id&&(t.removeAttribute("id"),e++),(t.querySelectorAll?t.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),e++}),e},sameNode(t,e){return t===e}},R=Wt;var k={extract:(t,e,n)=>O(R,t,e,n),apply:(t,e,n,o)=>N(R,t,e,n,o),findRulesIn:(t,e)=>I(R,t,e),findRules:(t,e)=>Y(R,t,e),bind:(t,e,n)=>mt(R,t,e,n),parseStrict:Q,parseRelaxed:$,ruleAttrIndex:A,splitRule:K,errors:B,DOM_PROPERTIES:W},Z=t=>!!t&&typeof t.nodeType=="number";function yt(t){let e=t&&t.ownerDocument?t.ownerDocument:t,n=R.find(e,"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 I(R,e).rules}function tt(t,e){let n=Z(t)?t:document,o=Z(t)?e:t;return o===void 0?O(R,n,yt(n)):k.bind(n,o).get()}function et(t,e,n){if(!Z(t))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?N(R,t,yt(t),e):k.bind(t,n).set(e),t}var Bt={engine:k,extractData:tt,applyData:et},Ut=Bt;return St(vt);})();
1
+ var hyperHtmlApiData=(()=>{var K=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var n in t)K(e,n,{get:t[n],enumerable:!0})},De=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of je(t))!Pe.call(e,r)&&r!==n&&K(e,r,{get:()=>t[r],enumerable:!(o=Ie(t,r))||o.enumerable});return e};var Le=e=>De(K({},"__esModule",{value:!0}),e);var tt={};fe(tt,{applyData:()=>se,default:()=>et,engine:()=>z,extractData:()=>le});var F=["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"],G=new Set(F),ue=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),X=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var V={};fe(V,{EmptyListInsert:()=>k,MAX_RULE_DEPTH:()=>j,MaxRuleDepthExceeded:()=>C,RuleTargetReadOnly:()=>$,RulesParseError:()=>I,ShapeMismatch:()=>v,UnknownRulesVersion:()=>_});var I=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},_=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},j=20,C=class extends Error{constructor(t){super(`rule depth exceeded ${j} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},v=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},k=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}},$=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function b(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function Y(e){let t=b(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function N(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return Q(e,t,n,{depth:0,path:[]},o)}function Q(e,t,n,o,r){if(o.depth>j)throw new C(o.path);if(typeof n=="string")return _e(e,t,n,o,r);if(Array.isArray(n)){let[i,c]=n,l=e.find(t,i,r);return de(r,o,l),l.map((s,u)=>Q(e,s,c,{depth:o.depth+1,path:[...o.path,u]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,l]of Object.entries(n))i[c]=Q(e,t,l,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function _e(e,t,n,o,r){if(n.endsWith("[]")){let l=n.slice(0,-2),s=e.find(t,l,r);return de(r,o,s),s.map(u=>e.text(u))}if(n.startsWith("@"))return ae(e,t,n.slice(1));let i=b(n);if(i!==-1){let l=n.slice(0,i),s=n.slice(i+1),u=l?e.find(t,l,r):[t];return u.length===0?null:ae(e,u[0],s)}if(n===".")return e.text(t);let c=e.find(t,n,r);return c.length===0?null:e.text(c[0])}function de(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function ae(e,t,n){if(G.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function me(e,t,n,o){let r=e.length,i=t.length,c=new Array(r).fill(-1);if(o){let f=new Set;for(let h=0;h<r;h++){let y=o[h];!(y>=0&&y<i)||f.has(y)||(c[h]=y,f.add(y))}}if(r===0||i===0)return c;let l=e.map(f=>he(f,n)),s=t.map(f=>he(f,n)),u=new Array(i).fill(!1);for(let f of c)f>=0&&(u[f]=!0);let a=new Map;s.forEach((f,h)=>{u[h]||a.set(f,a.has(f)?-1:h)});let g=new Map;l.forEach((f,h)=>{c[h]>=0||g.set(f,(g.get(f)||0)+1)}),l.forEach((f,h)=>{if(c[h]>=0||g.get(f)!==1)return;let y=a.get(f);y===void 0||y===-1||u[y]||(c[h]=y,u[y]=!0)});let d=[];for(let f=0;f<r;f++)c[f]<0&&d.push(f);let x=[];for(let f=0;f<i;f++)u[f]||x.push(f);if(d.length===0||x.length===0)return c;let m=r*i+1,p=(f,h)=>ve(e[f],t[h],n)*m+Math.abs(f-h);for(let[f,h]of ke(d,x,p))c[f]=h;return c}var ye=e=>typeof e=="object"&&e!==null;function he(e,t){if(!ye(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function ve(e,t,n){if(!ye(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let c=JSON.stringify(e?.[i]),l=JSON.stringify(t?.[i]);c!==l&&r++}return r}function ke(e,t,n){return e.length<=t.length?pe(e,t,n,!1):pe(t,e,(o,r)=>n(r,o),!0)}function pe(e,t,n,o){let r=e.length,i=t.length,c=[];for(let g=0;g<=r;g++)c.push(new Float64Array(i+1).fill(1/0));let l=[];for(let g=0;g<=r;g++)l.push(new Uint8Array(i+1));for(let g=0;g<=i;g++)c[r][g]=0;for(let g=r-1;g>=0;g--)for(let d=i-1;d>=0;d--){let x=n(e[g],t[d])+c[g+1][d+1],m=c[g][d+1];x<=m?(c[g][d]=x,l[g][d]=1):c[g][d]=m}let s=[],u=0,a=0;for(;u<r&&a<i;)l[u][a]&&(s.push(o?[t[a],e[u]]:[e[u],t[a]]),u++),a++;return s}function ee(e,t,n,o,r,i,c,l={}){let s=e.find(t,n,l);if(r.length===0){s.forEach(E=>e.remove(E)),Z(l,"onRowsApplied",i.path,[]);return}let u=r.length>s.length,a=s[0]||null;if(u&&!a&&(a=Be(e,t,n,l),!a))throw new k(i.path);let g=s.map(E=>We(e,E,o,l)),d=null;if(u&&a){d=e.clone(a),l.templateAttr&&e.removeAttr(d,l.templateAttr);let E=e.stripIds(d);E>0&&console.warn(`[hyper-html-api] stripped ${E} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let x=me(r,g,o,$e(e,s,r,i,l)),m=s[0]||a,p=e.parent(m),f=s.length>0?ge(e,p,m):0,h=qe(e,s),y=new Set,A=[],O=r.map((E,w)=>{let T=x[w];if(T>=0)return y.add(T),A.push(!1),s[T];A.push(!0);let S=e.clone(d);return e.stripIds(S),S});s.forEach((E,w)=>{y.has(w)||e.remove(E)}),h?O.forEach((E,w)=>{let T=f+w;e.children(p).findIndex(Me=>e.sameNode(Me,E))!==T&&e.insertAt(p,E,T)}):Ue(e,O,A,p,f),He(e,O,o,r,i,c,l),Z(l,"onRowsApplied",i.path,O)}function Z(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function $e(e,t,n,o,r){let i=Z(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let c=new Array(n.length).fill(-1),l=new Set;for(let s=0;s<n.length;s++)if(i[s]){for(let u=0;u<t.length;u++)if(!(l.has(u)||!e.sameNode(t[u],i[s]))){c[s]=u,l.add(u);break}}return c}function He(e,t,n,o,r,i,c){t.forEach((l,s)=>{if(n===null){let u=o[s],a=u==null?"":String(u);e.text(l)!==a&&e.text(l,a)}else{let u=i(e,l,n,o[s],{depth:r.depth+1,path:[...r.path,s]},c);u&&u!==l&&(t[s]=u)}})}function We(e,t,n,o){return n===null?e.text(t):N(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function ge(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 Be(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 c of i)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}function qe(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let c=o.findIndex(l=>e.sameNode(l,i));if(c===-1)return!1;r.push(c)}return r.sort((i,c)=>i-c),r[r.length-1]-r[0]===r.length-1}function Ue(e,t,n,o,r){let i=null,c=r;for(let l=0;l<t.length;l++){if(!n[l]){i=t[l];continue}let s=i?e.parent(i):o;if(!s)continue;let u=i?ge(e,s,i)+1:c++;e.insertAt(s,t[l],u),i=t[l]}}var Ee=new Set(["checked","selected","disabled","readOnly","paused"]);function P(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(te(n,o,[],i),i.length)throw new v(i);J(e,t,n,o,{depth:0,path:[]},r)}function J(e,t,n,o,r,i={}){if(r.depth>j)throw new C(r.path);if(o===void 0)return t;if(typeof n=="string")return ze(e,t,n,o,r,i);if(Array.isArray(n)){let[c,l]=n;return ee(e,t,c,l,o,r,J,i),t}if(typeof n=="object"&&n!==null){for(let[c,l]of Object.entries(n)){let s=J(e,t,l,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);s&&s!==t&&(t=s)}return t}return t}function ze(e,t,n,o,r,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return ee(e,t,s,null,o,r,J,i),t}if(n.startsWith("@"))return we(e,t,n.slice(1),o);let c=b(n);if(c!==-1){let s=n.slice(0,c),u=n.slice(c+1),a=s?e.find(t,s,i):[t];return a.length===0||we(e,a[0],u,o),t}if(n===".")return Te(e,t,o),t;let l=e.find(t,n,i);return l.length===0||Te(e,l[0],o),t}function Te(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function we(e,t,n,o){if(X.has(n))throw new $(n);if(n==="outerHTML"){let i=o==null?"":String(o);return e.replaceWith(t,i)}if(ue.has(n)){let i=Fe(n,o);return e.prop(t,n)!==i&&e.prop(t,n,i),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function Fe(e,t){return t==null?Ee.has(e)?!1:"":Ee.has(e)?t==="false"?!1:!!t:t}function te(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:W([...n,i]),expected:"scalar",got:H(r)})}):o.push({path:W(n),expected:"array",got:H(t)});return}t!==null&&typeof t=="object"&&o.push({path:W(n),expected:"scalar",got:H(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:W(n),expected:"array",got:H(t)});return}let r=e[1];t.forEach((i,c)=>te(r,i,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:W(n),expected:"object",got:H(t)});return}for(let[r,i]of Object.entries(e))te(i,t[r],[...n,r],o)}}}function H(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function W(e){return e.join(".")}function ne(e){try{return JSON.parse(e)}catch(t){throw new I(`Invalid strict JSON: ${t.message}`,t)}}function B(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=[],c=0;for(;c<r.length;){let l=r[c];if(/\s/.test(l)){c++;continue}if("{}".includes(l)){i.push({type:l,value:l}),c++;continue}if(l==="["){let g=!1,d=c+1;for(;d<r.length&&/\s/.test(r[d]);)d++;if(d<r.length&&/[a-zA-Z_]/.test(r[d])&&(g=!0),!g){i.push({type:l,value:l}),c++;continue}}if(l==="]"){i.push({type:l,value:l}),c++;continue}if(l===":"){i.push({type:t.COLON,value:l}),c++;continue}if(l===","){i.push({type:t.COMMA,value:l}),c++;continue}if(l==='"'||l==="'"){let g=l,d=c+1;for(;d<r.length&&r[d]!==g;)r[d]==="\\"&&d++,d++;i.push({type:t.STRING,value:r.substring(c+1,d),quoted:!0,sourceQuote:g}),c=d+1;continue}let s=c,u;for(;s<r.length&&!/[{},]/.test(r[s]);)if(r[s]===":"){let g=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let x of g){let m=x.substring(1);if(r.substring(s+1,s+1+m.length)===m){d=!0,s+=m.length;break}}if(!d)break}else if(r[s]==="["){for(s++;s<r.length&&r[s]!=="]";){if(r[s]==='"'||r[s]==="'"){let g=r[s];for(s++;s<r.length&&r[s]!==g;)r[s]==="\\"&&s++,s++}s++}s<r.length&&r[s]==="]"&&s++}else s++;u=r.substring(c,s);let a=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(u)?a=t.NUMBER:u==="true"||u==="false"||u==="null"?a=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(u)&&(a=t.SELECTOR),i.push({type:a,value:u,quoted:!1}),c=s}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let l=r[c];if("{}".includes(l.type)||"[]".includes(l.type)){i+=l.value;continue}if(l.type===t.COLON){i+=l.value;continue}if(l.type===t.COMMA){let s=r[c+1];if(s&&(s.type==="}"||s.type==="]"))continue;i+=l.value;continue}if(l.type===t.STRING&&l.quoted){let s=l.value;l.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(u,a)=>a.length%2===0?a+'\\"':u)),i+=`"${s}"`;continue}if(l.type===t.NUMBER||l.type===t.BOOLEAN){i+=l.value;continue}if(l.type===t.SELECTOR||l.type===t.IDENTIFIER){i+=`"${l.value}"`;continue}i+=`"${l.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new I("Invalid extraction rules syntax: "+r.message,r)}}var Ve="1",Oe=/^[a-zA-Z0-9_-]+$/;function D(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Oe.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Oe})`);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],c=e.attr(i,"data-rules-version");if(c!==Ve)throw new _(c);return{rules:B(e.text(i)),tagNode:i}}function re(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 D(e,o,n)}return null}var Ae=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),Ke=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Dt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function oe(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Ge(e,t){if(oe(e,t))return!0;for(let[n,o]of Object.entries(Ke))if(o.includes(t)&&oe(e,n))return!0;return!1}function q(e){let t=Ae[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Xe(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=Ae[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Ge(n,r))||o.bundles.some(r=>oe(n,r)))return n;n=n.parentElement}return null}function xe(e,t){return!!Xe(e,t)}var Ye=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Re(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();if("value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&(t.value=e.value),"checked"in e&&"checked"in t&&(t.checked=e.checked),"selected"in e&&"selected"in t&&(t.selected=e.selected),e.tagName==="SELECT")for(let o=0;o<e.options.length;o++)t.options[o].selected=e.options[o].selected;"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Se(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function be(e,t,n,o,r,i,c,l){if(e.nodeType===1&&((c?xe(e,n):Se(e,o,i,!1))||r&&Se(e,r,i,c)))return null;let s=t.importNode(e,!1);l.cloneToLive.set(s,e),l.liveToClone.set(e,s);let u=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,a=s.nodeType===1&&s.tagName==="TEMPLATE"?s.content:s;u!==e&&(l.cloneToLive.set(a,u),l.liveToClone.set(u,a));for(let g of u.childNodes||[]){let d=be(g,t,n,o,r,i,c,l);d&&(a.appendChild(d),g.nodeType===1&&Re(g,d))}return e.nodeType===1&&Re(e,s),s}function U(e,{capability:t="data",exclude:n=null,inherit:o=!0}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let r=e.nodeType===9?e:e.ownerDocument;if(!r?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let i=r.implementation.createHTMLDocument(""),c=new WeakMap,l=new WeakMap,s=e.nodeType===9?e.documentElement:e;n&&i.documentElement.matches(n);let u=q(t),a=be(s,i,t,u,n,s,o,{cloneToLive:c,liveToClone:l});e.nodeType===9&&a&&(i.replaceChild(a,i.documentElement),l.set(e,i),c.set(i,e));let g=d=>{if(Ye.test(d))throw new Error(`Filtered content queries do not support stateful selector: ${d}`)};return{root:a,document:i,capability:t,selector:q(t),cloneToLive:c,liveToClone:l,original(d){return c.get(d)||null},cloneOf(d){return l.get(d)||null},query(d,x=a){return g(d),Array.from(x.querySelectorAll(d),m=>c.get(m)||m)},text(d=a){return(d===a?a:l.get(d))?.textContent||""},html(d=a){return(d===a?a:l.get(d))?.innerHTML??""},clone(d=a){let x=d===a?a:l.get(d);return x?i.importNode(x,!0):null}}}function Ne(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Qe(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var R={semanticExclude:!0,find(e,t,n={}){let o=Qe(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(l=>!Ne(l)));let i=[];n.skip&&i.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&i.push("["+c+"]"),i.length){let l=i.join(", ");r=r.filter(s=>!s.closest||!s.closest(l))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function M(e,t={}){if(t.exclude===null)return R;let n=[q("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return R;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,l=null,s=()=>l||(l=U(i,{capability:"data",exclude:t.exclude||null})),u=m=>{let p=s();return m===e?p.cloneOf(e):p.cloneOf(m)||m},a=m=>l?.original(m)||m,g=(m,p)=>{s().liveToClone.set(m,p),s().cloneToLive.set(p,m);let f=m.childNodes||[],h=p.childNodes||[];for(let y=0;y<Math.min(f.length,h.length);y++)g(f[y],h[y])},d=(m,p,f,h)=>{let y=Array.from(m.childNodes).filter(T=>l.cloneOf(T)),O=y[0];for(;O&&y.includes(O);)O=O.nextSibling;for(let T of y)T.remove();if(f==="innerHTML"){let T=c.createElement("template");T.innerHTML=h;for(let S of Array.from(T.content.childNodes))m.insertBefore(S,O||null)}else m.insertBefore(c.createTextNode(h),O||null);let E=U(m,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(E.root?.childNodes||[]));let w=T=>{let S=E.original(T);S&&(l.liveToClone.set(S,T),l.cloneToLive.set(T,S));for(let ce of Array.from(T.childNodes||[]))w(ce)};for(let T of Array.from(p.childNodes))w(T)},x={...R,find(m,p,f={}){let h=u(m);if(!h?.querySelectorAll)return[];let y=s().query(p,h);f.includeRulesTag||(y=y.filter(E=>!Ne(E)));let A=[];f.skip&&A.push(f.skip);let O=f.templateAttr===null?null:f.templateAttr||"cms-template";if(O&&A.push(`[${O}]`),A.length){let E=A.join(", ");y=y.filter(w=>!w.closest?.(E))}return y},parent(m){let p=u(m)?.parentElement;return p?a(p):null},children(m){return Array.from(u(m)?.children||[],a)},text(m,p){if(p===void 0){let y=a(m);return!y?.matches?.(n)&&!y?.querySelector?.(n)?R.text(y):(u(m)?.textContent||"").trim()}let f=a(m);if(!f?.matches?.(n)&&!f?.querySelector?.(n)&&!l){R.text(f,p);return}let h=s().cloneOf(f);h?d(f,h,"textContent",p):R.text(f,p)},attr(m,p,f){let h=a(m);if(f===void 0)return R.attr(h,p);R.attr(h,p,f);let y=l?.cloneOf(h);y&&(R.attr(y,p,f),U(h,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),l.liveToClone.delete(h),l.cloneToLive.delete(y)))},removeAttr(m,p){let f=a(m);R.removeAttr(f,p);let h=l?.cloneOf(f);h&&R.removeAttr(h,p)},prop(m,p,f){let h=a(m);if(f===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?R.prop(u(h),p):R.prop(h,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",A=y?s().cloneOf(h):l?.cloneOf(h);A&&y?d(h,A,p,f):(R.prop(h,p,f),A&&R.prop(A,p,f))},clone(m){let p=u(m);return p===m?R.clone(m):c.importNode(p,!0)},insertAt(m,p,f){let h=a(m),A=x.children(h)[f]||(()=>{for(let w=h.children.length-1;w>=0;w--){let T=h.children[w];if(s().cloneOf(T))return T.nextElementSibling}return h.firstElementChild})(),O=a(p);h.insertBefore(O,A||null);let E=s().cloneOf(h);if(E){let w=s().cloneOf(O);w||(w=c.importNode(O,!0),g(O,w));let T=Array.from(E.children);E.insertBefore(w,T[f]||null)}},remove(m){let p=a(m),f=s().cloneOf(p);R.remove(p),f&&R.remove(f)},replaceWith(m,p){let f=a(m),h=s().cloneOf(f),y=R.replaceWith(f,p);if(h){let A=U(y,{capability:"data",exclude:t.exclude||null});if(!A.root)h.remove();else{h.replaceWith(A.root);let O=E=>{let w=A.original(E);w&&(l.liveToClone.set(w,E),l.cloneToLive.set(E,w));for(let T of Array.from(E.childNodes||[]))O(T)};O(A.root)}}return y}};return x}var L=R;var z={extract:(e,t,n={})=>N(M(e,n),e,t,n),apply:(e,t,n,o={})=>P(M(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>D(L,e,t),findRules:(e,t)=>re(L,e,t),bind:(e,t,n={})=>{let o=re(L,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>N(M(e,n),e,o.rules,n),set:r=>P(M(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:ne,parseRelaxed:B,ruleAttrIndex:b,splitRule:Y,errors:V,DOM_PROPERTIES:F},ie=e=>!!e&&typeof e.nodeType=="number";function Ce(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=L.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 D(L,t).rules}function le(e,t){let n=ie(e)?e:document,o=ie(e)?t:e;return o===void 0?N(M(n),n,Ce(n)):z.bind(n,o).get()}function se(e,t,n){if(!ie(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?P(M(e),e,Ce(e),t):z.bind(e,n).set(t),e}var Ze={engine:z,extractData:le,applyData:se},et=Ze;return Le(tt);})();
@@ -1,4 +1,4 @@
1
- var HyperHtmlApi=(()=>{var st=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var Ln=Object.getOwnPropertyNames;var Hn=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var n in t)st(e,n,{get:t[n],enumerable:!0})},jn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ln(t))!Hn.call(e,r)&&r!==n&&st(e,r,{get:()=>t[r],enumerable:!(o=Cn(t,r))||o.enumerable});return e};var Pn=e=>jn(st({},"__esModule",{value:!0}),e);var qr={};it(qr,{applyData:()=>jt,cms:()=>Tn,default:()=>Ur,engine:()=>We,extractData:()=>Ht,upgrade:()=>On});var Ke={};it(Ke,{fromString:()=>Ve,getRuleAtPath:()=>at,getValueAtPath:()=>Ce,parseConfigKey:()=>_n,setAtPath:()=>fe,toConfigKey:()=>Dn,toString:()=>re});function re(e){return e.map(String).join(".")}function Dn(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function _n(e){return e===""?[]:e.split(".")}function Ve(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function at(e,t){let n=e;for(let o of t){if(n==null||typeof n=="string")return;if(Array.isArray(n)){if(typeof o!="number"&&o!=="*")return;n=n[1];continue}if(typeof n=="object"){if(typeof o=="number"||!(o in n))return;n=n[o];continue}return}return n}function Ce(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function fe(e,t,n){if(t.length===0)return n;let[o,...r]=t;if(typeof o=="number"){let i=Array.isArray(e)?[...e]:[];return i[o]=fe(i[o],r,n),i}return{...e&&typeof e=="object"?e:{},[o]:fe((e||{})[o],r,n)}}function Me(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[n,o]of Object.entries(e))t[n]=Me(o);return t}return""}var Je=new WeakMap;function de(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function we(e){let t=de(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}var $n=new Set(["checked","selected","disabled","readOnly","paused"]);function ct({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(ut({rule:e,value:t,path:[],ctx:i})),r}function lt(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),Jt.set(e,{rules:t,getData:n,onChange:o}),Bn()}var Jt=new WeakMap,Vt=!1;function Bn(){Vt||(document.addEventListener("input",Kt,!0),document.addEventListener("change",Kt,!0),document.addEventListener("click",Fn,!0),Vt=!0)}function zt(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&Jt.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=zt(t);if(!n)return;let{rules:o,getData:r,onChange:i}=n,a=t.getAttribute("data-hha-action"),s=Ve(t.getAttribute("data-hha-path")||"");if(a==="scalar-array-add"){let c=Ce(r(),s)||[];i(fe(r(),s,[...c,""]),{structural:!0});return}if(a==="object-array-add"){let c=at(o,s);if(!Array.isArray(c))return;let g=Ce(r(),s)||[];i(fe(r(),s,[...g,Me(c[1])]),{structural:!0});return}if(a==="array-remove"){if(s.length===0)return;let c=s.slice(0,-1),g=s[s.length-1],v=Ce(r(),c)||[];if(typeof g!="number")return;let E=v.filter((m,A)=>A!==g);i(fe(r(),c,E),{structural:!0})}}function Kt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=zt(t);if(!n)return;let{getData:o,onChange:r}=n,i=t.closest("[data-hha-path]");if(!i)return;let a=Ve(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;r(fe(o(),a,s),{structural:!1})}function ut({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?Wn({rule:e,value:t,path:n,ctx:o}):qn({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return Vn({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return Un({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function Un({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",re(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=ze(n[n.length-1]),r.appendChild(i)}for(let[i,a]of Object.entries(e)){let s=[...n,i],c=t?.[i];r.appendChild(ut({rule:a,value:c,path:s,ctx:o}))}return r}function qn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",re(n));let i=document.createElement("div");i.className="field-body";let a=document.createElement("label");a.className="field-label",a.textContent=ze(n[n.length-1]||".")+Yn(e);let s=Jn(e,o.appRoot),c=Kn(s,{value:t,rule:e,path:n,appRoot:o.appRoot}),g=c.el;return g.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(a),i.appendChild(g),r.appendChild(i),Je.set(r,c),r}function Wn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",re(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=ze(n[n.length-1]),r.appendChild(i);let a=Array.isArray(t)?t:[],s=document.createElement("div");r.appendChild(s),a.forEach((g,v)=>{let E=[...n,v],m=document.createElement("div");m.className="scalar-array-row",m.setAttribute("data-hha-path",re(E));let A=document.createElement("input");A.type="text",A.className="field-input",A.value=g==null?"":String(g);let M=document.createElement("button");M.type="button",M.className="array-remove",M.textContent="\xD7",M.title="remove",M.setAttribute("data-hha-action","array-remove"),M.setAttribute("data-hha-path",re(E)),m.appendChild(A),m.appendChild(M),s.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","scalar-array-add"),c.setAttribute("data-hha-path",re(n)),r.appendChild(c),r}function Vn({rule:e,value:t,path:n,ctx:o}){let[,r]=e,i=Array.isArray(t)?t:[],a=document.createElement("div");a.className="form-section",a.setAttribute("data-hha-path",re(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=ze(n[n.length-1]),a.appendChild(s),i.forEach((g,v)=>{let E=[...n,v],m=document.createElement("div");m.className="array-card",m.setAttribute("data-hha-path",re(E));let A=document.createElement("button");A.type="button",A.className="array-remove",A.textContent="\xD7",A.title="remove item",A.setAttribute("data-hha-action","array-remove"),A.setAttribute("data-hha-path",re(E)),m.appendChild(A);let M=ut({rule:r,value:g,path:E,ctx:o});M.querySelector(".form-section-label")?.remove(),m.appendChild(M),a.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","object-array-add"),c.setAttribute("data-hha-path",re(n)),a.appendChild(c),a}function Kn(e,t){let n=Gn(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 Jn(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):n=we(e).prop,n&&$n.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=zn(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 zn(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=we(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function Gn(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function ze(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function Yn(e){return` \xB7 ${e}`}var Gt={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function Zn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return Math.abs(t).toString(36)}function Qn(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function Xn(e,t){let n=[];for(let o of e.attributes||[]){let r=o.name;r==="id"||r==="class"||t.excludeAttributePrefixes.some(i=>r.startsWith(i))||t.includeAttributes.includes(r)&&n.push(`${r}=${o.value}`)}return n.sort().join("|")}function er(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function tr(e,t){let n=[e.tagName];return t.includeClasses&&n.push(Qn(e)),n.push(Xn(e,t)),Zn(n.join("|"))}function nr(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function rr(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function or(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function sr(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${nr(o)}`;if(n.unshift(r),o!==e&&rr(o,t)){n.unshift(or(o));break}o=o.parentElement}return n}function ir(e,t){let n=0,o=e.length-1,r=t.length-1;for(;o>=0&&r>=0&&e[o]===t[r];)n++,o--,r--;return n}function oe(e,t,n){if(n.has(e))return n.get(e);let o={signature:tr(e,t),path:sr(e,t),textHint:er(e,t)};return n.set(e,o),o}function Xt(e,t,n,o){if(o.has(e))return o.get(e);let r=new Map,i=e.querySelectorAll("*"),a=0;for(let s of i){let c=oe(s,t,n);c.domIndex=a++,!t.shouldIgnore?.(s)&&(r.has(c.signature)||r.set(c.signature,[]),r.get(c.signature).push(s))}return o.set(e,r),r}function ar(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function ft(e,t,n,o,r){let i=oe(e,n,o),a=oe(t,n,o),s=n.weights,c={},g=0;if(i.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};g+=s.signature,c.signature=s.signature;let E=ir(i.path,a.path)*s.pathSegment;g+=E,c.path=E;let m=!0;if(i.textHint&&a.textHint?i.textHint===a.textHint?(g+=s.textMatch,c.text=s.textMatch):(g-=s.textMismatch,c.text=-s.textMismatch,m=!1):i.textHint!==a.textHint&&(g-=s.textMismatch,c.text=-s.textMismatch,m=!1),r.candidateCount===1&&m&&(g+=s.uniqueCandidate,c.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof a.domIndex=="number"){let A=Math.abs(i.domIndex-a.domIndex),M=Math.min(A*s.positionPenalty,s.maxDriftPenalty);g-=M,c.drift=-M}return{score:g,breakdown:c}}function Yt(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let i=Xt(t,n,o,r),a=oe(e,n,o);if(typeof a.domIndex!="number"){let m=0,A=e.previousElementSibling;for(;A;)m++,A=A.previousElementSibling;a.domIndex=m}let s=i.get(a.signature)||[],c=n.excludeIds?s.filter(m=>!m.getAttribute("id")):s;if(c.length===0)return null;let g=null,v=0,E=null;for(let m of c){let{score:A,breakdown:M}=ft(e,m,n,o,{candidateCount:c.length});A>v&&(v=A,g=m,E=M)}return v<n.minConfidence?null:{element:g,confidence:v,breakdown:E}}function cr(e,t,n,o){let r=[],i=n.weights.signature+n.weights.slotMatch,a={slot:i};function s(E){if(E.children)return E.children;let m=E.childNodes;if(!m)return[];let A=[];for(let M=0;M<m.length;M++)m[M].nodeType===1&&A.push(m[M]);return A}function c(E,m){let A=s(E),M=s(m);if(A.length===M.length)for(let q=0;q<A.length;q++){let I=A[q],D=M[q];if(n.shouldIgnore?.(I)||n.shouldIgnore?.(D)||n.excludeIds&&(I.getAttribute("id")||D.getAttribute("id"))||I.tagName!==D.tagName)continue;let W=oe(I,n,o).signature,ee=oe(D,n,o).signature;W!==ee&&r.push({newEl:I,oldEl:D,score:i,breakdown:a}),c(I,D)}}function g(E,m){for(;;){if(E.tagName===m.tagName)return[E,m];let A=s(E);if(!E.tagName&&A.length===1){E=A[0];continue}let M=s(m);if(M.length===1&&M[0].tagName===E.tagName){m=M[0];continue}return null}}let v=g(e,t);return v&&c(v[0],v[1]),r}function Zt(e,t,n,o,r){let i=t.querySelectorAll("*"),a=Xt(e,n,o,r),s=0;for(let A of i){let M=oe(A,n,o);M.domIndex=s++}let c=[],g=new Map;function v(A,M,q){let I=new Set;if(A.textHint){let F=g.get(A.signature);if(!F){F=new Map;for(let Q of M){let ce=oe(Q,n,o).textHint,le=F.get(ce);le||(le=[],F.set(ce,le)),le.push(Q)}g.set(A.signature,F)}let ne=F.get(A.textHint);if(ne)for(let Q=0;Q<ne.length&&Q<q;Q++)I.add(ne[Q])}let D=0,W=M.length;for(;D<W;){let F=D+W>>1;oe(M[F],n,o).domIndex<A.domIndex?D=F+1:W=F}let ee=Math.max(0,Math.min(D-(q>>1),M.length-q)),se=Math.min(ee+q,M.length);for(let F=ee;F<se;F++)I.add(M[F]);return[...I]}for(let A of i){if(n.shouldIgnore?.(A)||n.excludeIds&&A.getAttribute("id"))continue;let M=oe(A,n,o),q=a.get(M.signature)||[],I=n.excludeIds?q.filter(ee=>!ee.getAttribute("id")):q,D=n.maxScoredCandidates,W=D&&I.length>D?v(M,I,D):I;for(let ee of W){let{score:se,breakdown:F}=ft(A,ee,n,o,{candidateCount:I.length});se>=n.minConfidence&&c.push({newEl:A,oldEl:ee,score:se,breakdown:F})}}if(n.weights.slotMatch>0){let A=cr(t,e,n,o);for(let M of A)c.push(M)}c.sort((A,M)=>M.score-A.score);let E=new Map,m=new Set;for(let{newEl:A,oldEl:M}of c)E.has(A)||m.has(M)||(E.set(A,M),m.add(M));return E}function Qt(e,t,n,o){let r=oe(e,n,o),i=oe(t,n,o),{score:a,breakdown:s}=ft(e,t,n,o,{candidateCount:1});return{matches:a>=n.minConfidence,score:a,breakdown:s,newMeta:{signature:r.signature,path:r.path,textHint:r.textHint},oldMeta:{signature:i.signature,path:i.path,textHint:i.textHint}}}function en(e={}){let t={...Gt,...e,weights:{...Gt.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,i)=>Yt(r,i,t,n,o),computeMatches:(r,i)=>Zt(r,i,t,n,o),explain:(r,i)=>Qt(r,i,t,n),invalidate:r=>ar(r,n,o),session:()=>{let r=new WeakMap,i=new WeakMap;return{findMatch:(a,s)=>Yt(a,s,t,r,i),computeMatches:(a,s)=>Zt(a,s,t,r,i),explain:(a,s)=>Qt(a,s,t,r)}},getConfig:()=>({...t})}}function dt(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
3
- `;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function tn(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var lr=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,ur=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Ge(e){try{return JSON.parse(e)}catch{return JSON.parse(fr(e))}}function fr(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=dt(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=dt(e,n+1);if(e[s]==="}"||e[s]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let s=n+1;for(;s<e.length&&e[s]!==r;)e[s]==="\\"&&s++,s++;s>=e.length&&o("unterminated string",n);let c=e.slice(n+1,s);r==="'"&&(c=tn(c)),t+='"'+c+'"',n=s+1;continue}let i=n;for(;i<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[i]);)i++;i===n&&o("unexpected character "+JSON.stringify(r),n);let a=e.slice(n,i);if(a==="true"||a==="false"||a==="null"||lr.test(a)){t+=a,n=i;continue}if(ur.test(a)){if(e[dt(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function nn(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let E=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(E=!0),!E){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let E=s,m=a+1;for(;m<r.length&&r[m]!==E;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:E}),a=m+1;continue}let c=a,g;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let E=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let A of E){let M=A.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let E=r[c];for(c++;c<r.length&&r[c]!==E;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;g=r.substring(a,c);let v=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(g)?v=t.NUMBER:g==="true"||g==="false"||g==="null"?v=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(g)&&(v=t.SELECTOR),i.push({type:v,value:g,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING){let c=s.value;s.sourceQuote==="'"&&(c=tn(c)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var G=Symbol("hyper-morph-json-merge:missing"),rn=["id","_id","uuid","key","slug","code","name"];function ve(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Le(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function dr(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function pe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!pe(e[n],t[n]))return!1;return!0}if(ve(e)&&ve(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Le(t,o)||!pe(e[o],t[o]))return!1;return!0}return!1}function on(e,t,n,o){return pe(t,n)?t:pe(t,e)?n:pe(n,e)?t:ve(t)&&ve(n)?pr(ve(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?yr(Array.isArray(e)?e:[],t,n,o):n}function sn(e,t,n,o){return t===G&&n===G?G:t===G?e===G?n:pe(n,e)?G:n:n===G?e===G?t:G:on(e,t,n,o)}function pr(e,t,n,o){let r={},i=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let a of i){let s=sn(Le(e,a)?e[a]:G,Le(t,a)?t[a]:G,Le(n,a)?n[a]:G,o);s!==G&&dr(r,a,s)}return r}function hr(e){return e===null||typeof e!="object"}function Ye(e){return typeof e+":"+String(e)}function mr(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Le(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=Ye(i);if(o.has(a))return!1;o.add(a)}}return!0}function gr(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)ve(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(mr(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!hr(c))return null;let g=Ye(c);if(s.has(g))return null;s.add(g)}}return{kind:"self"}}function yr(e,t,n,o){let r=gr(e,t,n,o);if(!r)return n;let i=r.kind==="self"?Ye:A=>Ye(A[r.field]),a=A=>{let M=new Map;for(let q of A)M.set(i(q),q);return M},s=a(e),c=a(t),g=a(n),v=new Map,E=new Set([...s.keys(),...c.keys(),...g.keys()]);for(let A of E){let M=sn(s.has(A)?s.get(A):G,c.has(A)?c.get(A):G,g.has(A)?g.get(A):G,o);M!==G&&v.set(A,M)}let m=[];for(let A of n){let M=i(A);v.has(M)&&m.push(M)}for(let A=0;A<t.length;A++){let M=i(t[A]);if(!v.has(M)||m.includes(M))continue;let q=0;for(let I=A-1;I>=0;I--){let D=m.indexOf(i(t[I]));if(D!==-1){q=D+1;break}}m.splice(q,0,M)}return m.map(A=>v.get(A))}function pt(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...rn]:rn;return on(e===void 0?G:e,t,n,{keyCandidates:r})}function ht(e,t,n,o={}){let r=o.parse||Ge,i=[],a=(E,m)=>{if(typeof E!="string")return G;try{return r(E)}catch(A){return i.push(`${m} side is not valid JSON (${A.message})`),G}},s=a(t,"local"),c=a(n,"remote");if(s===G)return{text:n,warnings:i};if(c===G)return{text:t,warnings:i};let g=a(e,"base"),v=pt(g===G?void 0:g,s,c,o);return pe(v,c)?{text:n,warnings:i}:pe(v,s)?{text:t,warnings:i}:{text:JSON.stringify(v,null,2),warnings:i}}var He=function(){"use strict";let e=()=>{},t='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function n(f){if(!(f instanceof Element))return!1;if(f.matches(t))return!0;if(f.tagName==="LINK"||f.tagName==="SCRIPT"){let R=f.getAttribute("src")||f.getAttribute("href")||"";if(R.startsWith("chrome-extension://")||R.startsWith("moz-extension://")||R.startsWith("safari-web-extension://"))return!0}return!1}function o(f){return f instanceof Element?f.closest(t)?!0:n(f):!1}let r=en({shouldIgnore:o});function i(f,R,T){if(T){let k=T.identityOf(f);if(k&&!T.disabled.has(k.key))return"hm-merge:"+k.key}if(R!=="smart")return f.outerHTML;let N=f.getAttribute("src"),O=f.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${O}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${O}:${N}`}else{let k=f.textContent.trim(),h=5381;for(let x=0;x<k.length;x++)h=(h<<5)+h^k.charCodeAt(x);return`inline:${O}:${Math.abs(h).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(f){return f instanceof Element&&f.tagName==="SCRIPT"&&f.namespaceURI===a}function c(f){let R=document.createElement("div");R.innerHTML="<script><\/script>";let T=R.firstChild;for(let N of f.attributes)T.setAttribute(N.name,N.value);return T.textContent=f.textContent,T}function g(f){if(s(f))return c(f);if(f instanceof Element)for(let R of f.querySelectorAll("script"))s(R)&&R.replaceWith(c(R));return f}function v(f){let R=(f.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return R==="application/json"||R.endsWith("+json")}let E={match:f=>f.hasAttribute("merge"),identity:f=>f.getAttribute("merge")};function m(f,R,T){if(T.merge===!1)return null;let N=[E,...T.mergeTags||[]],O=new WeakMap,k=d=>{if(O.has(d))return O.get(d);let b=null;if(s(d)&&!d.getAttribute("src")&&!o(d)){let S=d;for(let L=0;L<N.length;L++)if(N[L].match(S)){if(!v(S))console.warn("[hyper-morph] merge ignored: script type is not JSON",S);else{let B=N[L].identity(S);B!=null&&B!==""&&(b={key:L+":"+B,raw:B,recognizer:N[L]})}break}}return O.set(d,b),b},h=new Set,x=d=>{let b=new Map,S=L=>{let B=k(L);B&&(b.has(B.key)?(h.add(B.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${B.raw}"`)):b.set(B.key,L))};s(d)&&S(d);for(let L of d.querySelectorAll("script"))S(L);return b},p=x(f),u=x(R.__hyperMorphRoot||R);if(p.size===0&&u.size===0)return null;let l=null;return{identityOf:k,disabled:h,oldByKey:p,newByKey:u,baseTexts:()=>{if(l)return l;l=new Map;let d=T.mergeBase;if(!d)return l;let b;typeof d=="string"?b=new DOMParser().parseFromString(d,"text/html").documentElement:d instanceof Document?b=d.documentElement:b=d;let S=L=>{let B=k(L);B&&!l.has(B.key)&&l.set(B.key,L.textContent)};s(b)&&S(b);for(let L of b.querySelectorAll("script"))S(L);return l}}}function A(f,R,T){let N=f.merge;if(!N)return!1;let O=N.identityOf(R);if(!O||N.disabled.has(O.key))return!1;let k=N.identityOf(T);if(!k||k.key!==O.key)return!1;let h=R,x=T,p=x.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=ht(N.baseTexts().get(O.key),h.textContent,x.textContent,{parse:O.recognizer.parse,keyCandidates:p?p.split(/[\s,]+/).filter(Boolean):void 0});for(let y of l)console.warn(`[hyper-morph] merge "${O.raw}": ${y}`);return h.textContent!==u&&(h.textContent=u),!0}let M={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},q={computeMatches(f,R){let{computeMatches:T}=r.session();return T(f,R)}};function I(f,R,T={}){f=Nn(f);let N=Pt(R),O=Rn(f,N,T),k=O.scripts.handle?new Set(Array.from(f.querySelectorAll("script")).map(u=>i(u,O.scripts.matchMode,O.merge))):null,h=ee(O),x=Q(O,f,N,u=>u.morphStyle==="innerHTML"?(F(u,f,N),Array.from(f.childNodes)):W(u,f,N)),p=u=>{h&&se(O,h),D(O);let l=k?tt(u,k,O):[];return l.length>0?Promise.all(l).then(()=>u):u};return x instanceof Promise?x.then(p):p(x)}function D(f){for(let R of Array.from(f.pantry.childNodes))f.callbacks.beforeNodeRemoved(R)!==!1&&f.callbacks.afterNodeRemoved(R);f.pantry.remove()}function W(f,R,T){let N=Pt(R);return F(f,N,T,R,R.nextSibling),Array.from(N.childNodes)}function ee(f){if(!f.config.restoreFocus)return null;let R=document.activeElement;if(!(R instanceof HTMLInputElement||R instanceof HTMLTextAreaElement))return null;let{id:T,selectionStart:N,selectionEnd:O}=R;return{element:R,id:T,selectionStart:N,selectionEnd:O}}function se(f,R){let T=R.element;if(R.id&&R.id!==document.activeElement?.getAttribute("id")&&(T=f.target.querySelector(`[id="${CSS.escape(R.id)}"]`),T?.focus()),T&&!T.selectionEnd&&R.selectionEnd!=null)try{T.setSelectionRange(R.selectionStart,R.selectionEnd)}catch{}}let F=function(){function f(u,l,y,d=null,b=null){l instanceof HTMLTemplateElement&&y instanceof HTMLTemplateElement&&(l=l.content,y=y.content),d||=l.firstChild;for(let S of y.childNodes){if(n(S))continue;if(d&&d!=b){let B=T(u,S,d,b);if(B){B!==d&&O(u,d,B),ne(B,S,u),d=B.nextSibling;continue}}if(S instanceof Element){let B=S.getAttribute("id");if(u.persistentIds.has(B)){let w=k(l,B,d,u);ne(w,S,u),d=w.nextSibling;continue}if(!u.idMap.has(S)){let w=u.hyperMatches.get(S);if(w&&!u.idMap.has(w)&&!p(w,l)){x(l,w,d),ne(w,S,u),d=w.nextSibling;continue}}}let L=R(l,S,d,u);L&&(d=L.nextSibling)}for(;d&&d!=b;){let S=d;d=d.nextSibling,n(S)||N(u,S)}}function R(u,l,y,d){if(d.callbacks.beforeNodeAdded(l)===!1)return null;if(d.idMap.has(l)){let b=l,S=document.createElementNS(b.namespaceURI,b.localName);return u.insertBefore(S,y),ne(S,l,d),d.callbacks.afterNodeAdded(S),S}else{let b=g(document.importNode(l,!0));return u.insertBefore(b,y),d.callbacks.afterNodeAdded(b),b}}let T=function(){function u(d,b,S,L){let B=b instanceof Element&&!d.idMap.has(b)?d.hyperMatches.get(b):null,w=null,C=b.nextSibling,V=0,_=S;for(;_&&_!=L;){if(n(_)){_=_.nextSibling;continue}if(y(_,b)){if(l(d,_,b)||_===B&&!d.idMap.has(_))return _;if(w===null){let K=_ instanceof Element&&d.hyperMatchedOldElements.has(_);!d.idMap.has(_)&&!K&&(w=_)}}if(w===null&&C&&y(_,C)&&(V++,C=C.nextSibling,V>=2&&(w=void 0)),d.activeElementAndParents.includes(_))break;_=_.nextSibling}return w||null}function l(d,b,S){let L=d.idMap.get(b),B=d.idMap.get(S);if(!B||!L)return!1;for(let w of L)if(B.has(w))return!0;return!1}function y(d,b){let S=d,L=b;return S.nodeType===L.nodeType&&S.tagName===L.tagName&&(!S.getAttribute?.("id")||S.getAttribute?.("id")===L.getAttribute?.("id"))}return u}();function N(u,l){let y=l instanceof Element&&u.hyperMatchedOldElements.has(l)&&!u.idMap.has(l);if(u.idMap.has(l)||y)x(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function O(u,l,y){let d=l;for(;d&&d!==y;){let b=d;d=d.nextSibling,n(b)||N(u,b)}return d}function k(u,l,y,d){let b=d.target.getAttribute?.("id")===l&&d.target||d.target.querySelector(`[id="${CSS.escape(l)}"]`)||d.pantry.querySelector(`[id="${CSS.escape(l)}"]`);return h(b,d),x(u,b,y),b}function h(u,l){let y=u.getAttribute("id");for(;u=u.parentNode;){let d=l.idMap.get(u);d&&(d.delete(y),d.size||l.idMap.delete(u))}}function x(u,l,y){if(u.moveBefore)try{u.moveBefore(l,y)}catch{u.insertBefore(l,y)}else u.insertBefore(l,y)}function p(u,l){let y=l instanceof Element?l:l.realParentNode;return!!y&&u.contains(y)}return f}(),ne=function(){function f(h,x,p){return p.ignoreActive&&h===document.activeElement?null:(p.callbacks.beforeNodeMorphed(h,x)===!1||(h instanceof HTMLHeadElement&&p.head.ignore||(h instanceof HTMLHeadElement&&p.head.style!=="morph"?le(h,x,p):(R(h,x,p),A(p,h,x)||k(h,p)||F(p,h,x))),p.callbacks.afterNodeMorphed(h,x)),h)}function R(h,x,p){let u=x.nodeType;if(u===1){let l=h,y=x,d=l.attributes,b=y.attributes;for(let S of b)O(S.name,l,"update",p)||l.getAttribute(S.name)!==S.value&&l.setAttribute(S.name,S.value);for(let S=d.length-1;0<=S;S--){let L=d[S];if(L&&!y.hasAttribute(L.name)){if(O(L.name,l,"remove",p))continue;l.removeAttribute(L.name)}}k(l,p)||T(l,y,p)}(u===8||u===3)&&h.nodeValue!==x.nodeValue&&(h.nodeValue=x.nodeValue)}function T(h,x,p){if(h instanceof HTMLInputElement&&x instanceof HTMLInputElement&&x.type!=="file"){let u=x.value,l=h.value;N(h,x,"checked",p),N(h,x,"disabled",p),p.formStateSync==="property"&&h.indeterminate!==x.indeterminate&&(h.indeterminate=x.indeterminate),p.formStateSync==="property"?l!==u&&(O("value",h,"update",p)||(h.value=u)):x.hasAttribute("value")?l!==u&&(O("value",h,"update",p)||(h.setAttribute("value",u),h.value=u)):O("value",h,"remove",p)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&x instanceof HTMLOptionElement)N(h,x,"selected",p);else if(h instanceof HTMLTextAreaElement&&x instanceof HTMLTextAreaElement){let u=x.value,l=h.value;if(O("value",h,"update",p)||(u!==l&&(h.value=u),p.formStateSync==="property"))return;h.firstChild&&h.firstChild.nodeValue!==u&&(h.firstChild.nodeValue=u)}}function N(h,x,p,u){let l=x[p],y=h[p];if(l!==y){let d=O(p,h,"update",u);if(d||(h[p]=x[p]),u.formStateSync==="property")return;l?d||h.setAttribute(p,""):O(p,h,"remove",u)||h.removeAttribute(p)}}function O(h,x,p,u){return h==="value"&&u.ignoreActiveValue&&x===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,x,p)===!1}function k(h,x){return!!x.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return f}();function Q(f,R,T,N){if(f.head.block){let O=R.querySelector("head"),k=T.querySelector("head");if(O&&k){let h=le(O,k,f);return Promise.all(h).then(()=>(f.head.block=!1,f.head.ignore=!0,N(f)))}}return N(f)}function ce(f){return f.tagName==="SCRIPT"?!!f.getAttribute("src"):f.tagName==="LINK"?(f.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!f.getAttribute("href"):!1}function le(f,R,T){let N=[],O=[],k=[],h=[],x=T.scripts.matchMode,p=y=>{if(y.tagName==="SCRIPT")return i(y,x,T.merge);if(y.tagName==="LINK"&&x==="smart"){let d=y.getAttribute("href");if(d)try{let b=new URL(d,window.location.href);return`link:${y.getAttribute("rel")||""}:${b.origin}${b.pathname}${b.search}`}catch{}}return y.outerHTML},u=new Map;for(let y of R.children){if(n(y))continue;let d=p(y),b=u.get(d);b||(b=[],u.set(d,b)),b.push(y)}for(let y of f.children){let d=p(y),b=u.get(d),S=!!(b&&b.length),L=T.head.shouldReAppend(y),B=T.head.shouldPreserve(y);if(S||B)if(L)O.push(y);else{if(b&&b.length){let w=b.pop();b.length||u.delete(d),A(T,y,w)}k.push(y)}else T.head.style==="append"?L&&(O.push(y),h.push(y)):T.head.shouldRemove(y)!==!1&&!n(y)&&O.push(y)}for(let y of u.values())h.push(...y);let l=[];for(let y of h){let d=document.createRange().createContextualFragment(y.outerHTML).firstChild;if(T.callbacks.beforeNodeAdded(d)!==!1){if(d instanceof Element&&ce(d)){let b,S=new Promise(function(L){b=L});d.addEventListener("load",function(){b()}),d.addEventListener("error",function(){b()}),l.push(S)}f.appendChild(d),T.callbacks.afterNodeAdded(d),N.push(d)}}for(let y of O)T.callbacks.beforeNodeRemoved(y)!==!1&&(f.removeChild(y),T.callbacks.afterNodeRemoved(y));return T.head.afterHeadMorphed(f,{added:N,kept:k,removed:O}),l}function tt(f,R,T){if(!T.scripts.handle)return[];let N=[],O=[],k=[],h=[],x=T.scripts.matchMode,p=[];for(let l of f)if(l instanceof Element){s(l)&&p.push(l);for(let y of l.querySelectorAll("script"))s(y)&&p.push(y)}for(let l of p){if(l.closest("head")||o(l))continue;let y=i(l,x,T.merge),d=R.has(y),b=T.scripts.shouldPreserve(l),S=T.scripts.shouldReAppend(l);d||b?S?(O.push(l),h.push(l)):k.push(l):h.push(l)}let u=[];for(let l of h){if(T.callbacks.beforeNodeAdded(l)===!1)continue;let y=document.createElement("script");for(let d of l.attributes)y.setAttribute(d.name,d.value);if(y.textContent=l.textContent,y.src){let d,b=new Promise(function(S){d=S});y.addEventListener("load",function(){d()}),y.addEventListener("error",function(){d()}),u.push(b)}l.replaceWith(y),T.callbacks.afterNodeAdded(y),N.push(y)}return T.scripts.afterScriptsHandled(T.target,{added:N,kept:k,removed:O}),u}let Rn=function(){function f(p,u,l){let{persistentIds:y,idMap:d}=h(p,u),b=q.computeMatches(p,u);if(typeof l.key=="function"){let C=new Map,V=new Set,_=P=>{let H=l.key(P);H!=null&&(C.has(H)?V.add(H):C.set(H,P))};p instanceof Element&&_(p);for(let P of p.querySelectorAll("*"))_(P);for(let P of V)C.delete(P);let K=new Map;for(let[P,H]of b)K.set(H,P);let te=u.__hyperMorphRoot||u,Z=new Map,z=new Set,j=P=>{let H=l.key(P);H!=null&&(Z.has(H)?z.add(H):Z.set(H,P))};te instanceof Element&&j(te);for(let P of te.querySelectorAll("*"))j(P);for(let P of z)Z.delete(P);for(let[P,H]of Z){let U=C.get(P);if(!U||U.tagName!==H.tagName)continue;let J=K.get(U);J&&J!==H&&b.delete(J);let ge=b.get(H);ge&&ge!==U&&K.delete(ge),b.set(H,U),K.set(U,H)}}let S=R(l),L=m(p,u,S.scripts);if(L){let C=new Map;for(let[V,_]of b)C.set(_,V);for(let[V,_]of L.newByKey){if(L.disabled.has(V))continue;let K=L.oldByKey.get(V);if(!K)continue;let te=C.get(K);te&&te!==_&&b.delete(te);let Z=b.get(_);Z&&Z!==K&&C.delete(Z),b.set(_,K),C.set(K,_)}}let B=new Set;for(let C of b.values())B.add(C);let w=S.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(w))throw new Error(`Do not understand how to morph style ${w}`);return{target:p,newContent:u,config:S,morphStyle:w,ignoreActive:S.ignoreActive,ignoreActiveValue:S.ignoreActiveValue,restoreFocus:S.restoreFocus,formStateSync:S.formStateSync||"attribute",idMap:d,persistentIds:y,hyperMatches:b,hyperMatchedOldElements:B,merge:L,pantry:T(),activeElementAndParents:N(p),callbacks:S.callbacks,head:S.head,scripts:S.scripts}}function R(p){let u=Object.assign({},M);return Object.assign(u,p),u.callbacks=Object.assign({},M.callbacks,p.callbacks),u.head=Object.assign({},M.head,p.head),u.scripts=Object.assign({},M.scripts,p.scripts),u}function T(){let p=document.createElement("div");return p.hidden=!0,document.body.insertAdjacentElement("afterend",p),p}function N(p){let u=[],l=document.activeElement;if(l?.tagName!=="BODY"&&p.contains(l))for(;l&&(u.push(l),l!==p);)l=l.parentElement;return u}function O(p){let u=Array.from(p.querySelectorAll("[id]"));return p.getAttribute?.("id")&&u.push(p),u}function k(p,u,l,y){for(let d of y){let b=d.getAttribute("id");if(u.has(b)){let S=d;for(;S;){let L=p.get(S);if(L==null&&(L=new Set,p.set(S,L)),L.add(b),S===l)break;S=S.parentElement}}}}function h(p,u){let l=O(p),y=O(u),d=x(l,y),b=new Map;k(b,d,p,l);let S=u.__hyperMorphRoot||u;return k(b,d,S,y),{persistentIds:d,idMap:b}}function x(p,u){let l=new Set,y=new Map;for(let b of p){let S=b.getAttribute("id");y.has(S)?l.add(S):y.set(S,b.tagName)}let d=new Set;for(let b of u){let S=b.getAttribute("id");d.has(S)?l.add(S):y.get(S)===b.tagName&&d.add(S)}for(let b of l)d.delete(b);return d}return f}(),{normalizeElement:Nn,normalizeParent:Pt}=function(){let f=new WeakSet;function R(h){return h instanceof Document?h.documentElement:h}function T(h){if(h==null)return document.createElement("div");if(typeof h=="string")return T(k(h));if(f.has(h))return h;if(h instanceof Node){if(h.parentNode)return new N(h);{let x=document.createElement("div");return x.append(h),x}}else{let x=document.createElement("div");for(let p of[...h])x.append(p);return x}}class N{constructor(x){this.originalNode=x,this.realParentNode=x.parentNode,this.previousSibling=x.previousSibling,this.nextSibling=x.nextSibling}get childNodes(){let x=[],p=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;p&&p!=this.nextSibling;)x.push(p),p=p.nextSibling;return x}querySelectorAll(x){return this.childNodes.reduce((p,u)=>{if(u instanceof Element){u.matches(x)&&p.push(u);let l=u.querySelectorAll(x);for(let y=0;y<l.length;y++)p.push(l[y])}return p},[])}insertBefore(x,p){return this.realParentNode.insertBefore(x,p)}moveBefore(x,p){return this.realParentNode.moveBefore(x,p)}get __hyperMorphRoot(){return this.originalNode}}function O(h){let x=y=>`<${y}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,p=h.replace(/<!--[\s\S]*?-->/g,"");for(let y of["script","style","textarea","title"])p=p.replace(new RegExp(`${x(y)}[\\s\\S]*?</${y}\\s*>`,"gi"),"");let u=new RegExp(`${x("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=p,p=p.replace(u,"");while(p!==l);return p}function k(h){let x=new DOMParser,p=O(h);if(p.match(/<\/html>/)||p.match(/<\/head>/)||p.match(/<\/body>/)){let u=x.parseFromString(h,"text/html");if(p.match(/<\/html>/))return f.add(u),u;{let l=u.firstChild;return l&&f.add(l),l}}else{let l=x.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return f.add(l),l}}return{normalizeElement:R,normalizeParent:T}}(),Dt=Symbol("hyper-morph-duplicate-key"),_t=[f=>f.getAttribute("data-id"),f=>f.getAttribute("id")];function ke(f,R){return R.map(T=>{let N=new Map;for(let O of f){if(O.nodeType!==1)continue;let k=T(O);k==null||k===""||N.set(k,N.has(k)?Dt:O)}return N})}function $t(f,R,T,N){for(let O=0;O<N.length;O++){let k=N[O](f);if(k==null||k===""||R[O].get(k)!==f)continue;let h=T[O].get(k);if(!(!h||h===Dt)&&h.tagName===f.tagName)return h}return null}function Ee(f,R,T){for(let N=0;N<T.length;N++){let O=T[N](f);if(!(O==null||O==="")&&R[N].get(O)===f)return!0}return!1}function kn(f,R,T={}){let N=T.skip||(()=>!1),O=T.ignoreAttr||(()=>!1),k=T.tiers&&T.tiers.length?T.tiers:_t,h=null;function x(){return h||(h=ke([f,...f.querySelectorAll("*")],k)),h}let p=null;function u(){return p||(p=ke([R,...R.querySelectorAll("*")],k)),p}function l(j){return!j.parentElement||!j.parentElement.parentElement}function y(j,P,H){return l(j)||Ee(j,x(),k)?(H.push({type:"subtree",el:j,base:P}),!1):!0}function d(j,P){let H=[];for(let U of j.attributes)O(j,U.name)||P.getAttribute(U.name)!==U.value&&H.push(U.name);for(let U of P.attributes)O(j,U.name)||j.hasAttribute(U.name)||H.push(U.name);return H}function b(j){let P=[],H=null,U=()=>{H!==null&&(P.push({nodeType:3,nodeValue:H}),H=null)};for(let J of j.childNodes){if(J.nodeType===3){H=(H===null?"":H)+J.nodeValue;continue}J.nodeType===1&&N(J)||(U(),(J.nodeType===1||J.nodeType===8)&&P.push(J))}return U(),P}function S(j,P){if(j.nodeType!==P.nodeType)return!1;if(j.nodeType!==1)return!0;if(j.tagName!==P.tagName)return!1;for(let H of k){let U=H(j),J=H(P);if(U!=null&&U!==""&&J!=null&&J!==""&&U!==J)return!1}return!0}function L(j){let P="";for(let H of j)H.nodeType===3&&H.nodeValue.trim()!==""?P+="\0"+H.nodeValue:H.nodeType===8&&(P+=""+H.nodeValue);return P}function B(j,P,H){let U=b(j),J=b(P);if(U.length===J.length){let $=!0;for(let Y=0;Y<U.length;Y++)if(!S(U[Y],J[Y])){$=!1;break}if($){for(let Y=0;Y<U.length;Y++){let xe=U[Y];if(xe.nodeType===1){if(w(xe,J[Y],H))return!0}else if(xe.nodeValue!==J[Y].nodeValue)return!0}return!1}}let ge=U.filter($=>$.nodeType===1),nt=J.filter($=>$.nodeType===1);if(L(U)!==L(J))return!0;let Bt=ke(ge,k),Ft=ke(nt,k),rt=[],ot=new Set,Ut=[];for(let $ of ge){let Y=$t($,Bt,Ft,k);Y&&!ot.has(Y)?(rt.push([$,Y]),ot.add(Y)):Ut.push($)}let ue=[];for(let $ of Ut)Ee($,Bt,k)?H.push({type:"subtree",el:$,base:null}):ue.push($);let Ie=[];for(let $ of nt)ot.has($)||(Ee($,Ft,k)?H.push({type:"deletion",el:$}):Ie.push($));if(ue.length!==Ie.length)return!0;for(let $=0;$<ue.length;$++)if(!S(ue[$],Ie[$]))return!0;let qt=new Map(rt);for(let $=0;$<ue.length;$++)qt.set(ue[$],Ie[$]);let Wt=-1;for(let $ of ge){let Y=qt.get($);if(!Y)continue;let xe=nt.indexOf(Y);if(xe<Wt)return!0;Wt=xe}for(let $=0;$<ue.length;$++)if(w(ue[$],Ie[$],H))return!0;for(let[$,Y]of rt)if(w($,Y,H))return!0;return!1}function w(j,P,H){if(j.tagName!==P.tagName)return y(j,P,H);let U=d(j,P),J=[];if(B(j,P,J))return y(j,P,H);if(U.length){if(!l(j)&&!Ee(P,u(),k))return!0;H.push({type:"attrs",el:j,names:U,base:P})}return H.push(...J),!1}let C=[],V=d(f,R);V.length&&C.push({type:"attrs",el:f,names:V});let _=(j,P)=>Array.from(j.children).find(H=>H.tagName===P)||null,K=_(f,"HEAD"),te=_(R,"HEAD");if(K&&te){let j=[];w(K,te,j),j.length&&C.push({type:"head",el:K})}else(K||te)&&K&&C.push({type:"head",el:K});let Z=_(f,"BODY"),z=_(R,"BODY");return Z&&z?w(Z,z,C):Z&&C.push({type:"subtree",el:Z,base:null}),{entries:C}}function In(f,R,T={}){let N=T.tiers&&T.tiers.length?T.tiers:_t,O=f.documentElement,k=[],h=0,x=w=>({ok:!1,placed:k,held:w,skippedAttrs:h});if(!O)return x(null);function p(w){let C=[w,...w.querySelectorAll("*")];return ke(C,N)}let u=p(O),l=new Map,y=w=>{let C=w.getRootNode(),V=l.get(C);if(!V){let _=C.nodeType===9?C.documentElement:C;V=p(_),l.set(C,V)}return V};function d(w){if(!w.parentElement&&w.tagName==="HTML")return O;if(w.parentElement&&!w.parentElement.parentElement&&w.parentElement.tagName==="HTML"){if(w.tagName==="BODY")return f.body||null;if(w.tagName==="HEAD")return f.head||null}return null}function b(w){let C=d(w);return C||$t(w,y(w),u,N)}function S(w){if(!w)return null;let C=b(w);return C&&C.isConnected?C:null}function L(w){for(let C=0;C<N.length;C++){let V=N[C](w);V!=null&&V!==""&&u[C].set(V,w)}}for(let w of R){if(w.type!=="deletion")continue;let C=b(w.el);C&&C!==O&&C.remove()}let B=R.filter(w=>w.type!=="deletion").sort((w,C)=>w.el===C.el?0:w.el.compareDocumentPosition(C.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let w of B){if(w.type==="head"){let z=f.importNode(w.el,!0);f.head?f.head.replaceWith(z):O.insertBefore(z,O.firstChild),k.push({entry:w,imported:z});continue}if(w.type==="attrs"){let z=S(w.el)||S(w.base);if(!z){h++;continue}for(let j of w.names)w.el.hasAttribute(j)?z.setAttribute(j,w.el.getAttribute(j)):z.removeAttribute(j);continue}let C=w.el;if(d(C))return x(w);let V=S(C)||S(w.base);if(V){let z=f.importNode(C,!0);V.replaceWith(z),L(z),k.push({entry:w,imported:z});continue}if(w.base!=null&&!Ee(w.base,y(w.base),N)||!Ee(C,y(C),N))return x(w);let _=C.parentElement;if(!_)return x(w);let K=S(_);if(!K)return x(w);let te=null;for(let z=C.previousElementSibling;z;z=z.previousElementSibling){let j=S(z);if(j&&j.parentNode===K){te=j;break}}let Z=f.importNode(C,!0);if(te)K.insertBefore(Z,te.nextSibling);else{let z=Array.prototype.indexOf.call(_.children,C);K.insertBefore(Z,K.children[z]||null)}L(Z),k.push({entry:w,imported:Z})}return{ok:!0,placed:k,held:null,skippedAttrs:h}}return{morph:I,defaults:M,findChangedRoots:kn,spliceProtected:In,mergeJson:pt,mergeScriptText:ht,parseJsonRelaxed:Ge,parseRulesRelaxed:nn}}();var io=He.morph,ao=He.defaults,co=He.findChangedRoots,lo=He.spliceProtected;var an=He;function mt(e,t,{onWidgetRemoved:n}={}){an.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Je.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var Ar="hha:upgrade-check:";function ie(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function gt(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function cn(e,t){let n=gt(e),o=gt(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let a=n[i]||0,s=o[i]||0;if(a!==s)return a>s}return!1}function Sr(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Er(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function yt({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(m=>fetch(m)),r=r??Date.now(),!t)return null;let a=ie(t,"hyper-source");if(!a)return null;let s=ie(t,"hyper-version"),c;try{c=new URL(a,n?n.href:void 0)}catch{return null}if(n&&c.origin===n.origin&&c.pathname===n.pathname)return null;let g=`${Ar}${c.href}:${s||"none"}`,v,E=e?null:Sr(g);if(E&&typeof E.checkedAt=="number"&&r-E.checkedAt<i)v=E.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let A=await m.text(),M=new DOMParser().parseFromString(A,"text/html");v=ie(M,"hyper-version")}catch{v=null}Er(g,{checkedAt:r,sourceVersion:v})}return v?{available:cn(v,s||"0.0.0"),currentVersion:s,sourceVersion:v,sourceUrl:c.href}:null}var Ze=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],bt=new Set(Ze),ln=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),un=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Qe={};it(Qe,{EmptyListInsert:()=>Pe,MAX_RULE_DEPTH:()=>Oe,MaxRuleDepthExceeded:()=>be,RuleTargetReadOnly:()=>De,RulesParseError:()=>Te,ShapeMismatch:()=>je,UnknownRulesVersion:()=>ye});var Te=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},ye=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},Oe=20,be=class extends Error{constructor(t){super(`rule depth exceeded ${Oe} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},je=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Pe=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},De=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function ae(e,t,n,o={}){return At(e,t,n,{depth:0,path:[]},o)}function At(e,t,n,o,r){if(o.depth>Oe)throw new be(o.path);if(typeof n=="string")return xr(e,t,n,o,r);if(Array.isArray(n)){let[i,a]=n,s=e.find(t,i,r);return dn(r,o,s),s.map((c,g)=>At(e,c,a,{depth:o.depth+1,path:[...o.path,g]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[a,s]of Object.entries(n))i[a]=At(e,t,s,{depth:o.depth+1,path:[...o.path,a]},r);return i}return null}function xr(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),c=e.find(t,s,r);return dn(r,o,c),c.map(g=>e.text(g))}if(n.startsWith("@"))return fn(e,t,n.slice(1));let i=de(n);if(i!==-1){let s=n.slice(0,i),c=n.slice(i+1),g=s?e.find(t,s,r):[t];return g.length===0?null:fn(e,g[0],c)}if(n===".")return e.text(t);let a=e.find(t,n,r);return a.length===0?null:e.text(a[0])}function dn(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function fn(e,t,n){if(bt.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Mr(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function wr(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var vr={find(e,t,n={}){let o=wr(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Mr(s)));let i=[];n.skip&&i.push(n.skip);let a=n.templateAttr===null?null:n.templateAttr||"cms-template";if(a&&i.push("["+a+"]"),i.length){let s=i.join(", ");r=r.filter(c=>!c.closest||!c.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},X=vr;function St(e){try{return JSON.parse(e)}catch(t){throw new Te(`Invalid strict JSON: ${t.message}`,t)}}function Ae(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let E=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(E=!0),!E){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let E=s,m=a+1;for(;m<r.length&&r[m]!==E;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:E}),a=m+1;continue}let c=a,g;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let E=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let A of E){let M=A.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let E=r[c];for(c++;c<r.length&&r[c]!==E;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;g=r.substring(a,c);let v=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(g)?v=t.NUMBER:g==="true"||g==="false"||g==="null"?v=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(g)&&(v=t.SELECTOR),i.push({type:v,value:g,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let c=s.value;s.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(g,v)=>v.length%2===0?v+'\\"':g)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Te("Invalid extraction rules syntax: "+r.message,r)}}var Et="1",pn=/^[a-zA-Z0-9_-]+$/;function Re(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!pn.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${pn})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],a=e.attr(i,"data-rules-version");if(a!==Et)throw new ye(a);return{rules:Ae(e.text(i)),tagNode:i}}var Tr="script[data-rules-name]";function hn(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function _e(e,t){let n=e.find(t,Tr,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=hn(e.attr(i,"data-rules-name"));if(!a)continue;if(o.has(a)){console.warn(`hyper-html-api: duplicate rules tag name "${a}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==Et)throw new ye(s);o.add(a),r.push({name:a,rules:Ae(e.text(i))})}return r}function Xe(e,t){let n={};for(let{name:o,rules:r}of _e(e,t))n[o]=ae(e,t,r);return n}function xt(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Xe(X,t),version:ie(n,"hyper-version")}}var Ne=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},$e=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},he=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Be=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var mn="text/hyper-upgrade";function Mt(e,t){let n=e.find(t,`script[type="${mn}"]`);if(n.length===0)return null;if(n.length>1)throw new Be(n.length);return e.text(n[0])||null}var Or=new Function("url","return import(url)");async function wt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Or(n)}catch(r){throw new he(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new he("transform must `export default` a function");return o.default}function bn(e,t,n,o){let r=e.length,i=t.length,a=new Array(r).fill(-1);if(o){let I=new Set;for(let D=0;D<r;D++){let W=o[D];!(W>=0&&W<i)||I.has(W)||(a[D]=W,I.add(W))}}if(r===0||i===0)return a;let s=e.map(I=>gn(I,n)),c=t.map(I=>gn(I,n)),g=new Array(i).fill(!1);for(let I of a)I>=0&&(g[I]=!0);let v=new Map;c.forEach((I,D)=>{g[D]||v.set(I,v.has(I)?-1:D)});let E=new Map;s.forEach((I,D)=>{a[D]>=0||E.set(I,(E.get(I)||0)+1)}),s.forEach((I,D)=>{if(a[D]>=0||E.get(I)!==1)return;let W=v.get(I);W===void 0||W===-1||g[W]||(a[D]=W,g[W]=!0)});let m=[];for(let I=0;I<r;I++)a[I]<0&&m.push(I);let A=[];for(let I=0;I<i;I++)g[I]||A.push(I);if(m.length===0||A.length===0)return a;let M=r*i+1,q=(I,D)=>Rr(e[I],t[D],n)*M+Math.abs(I-D);for(let[I,D]of Nr(m,A,q))a[I]=D;return a}var An=e=>typeof e=="object"&&e!==null;function gn(e,t){if(!An(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function Rr(e,t,n){if(!An(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let a=JSON.stringify(e?.[i]),s=JSON.stringify(t?.[i]);a!==s&&r++}return r}function Nr(e,t,n){return e.length<=t.length?yn(e,t,n,!1):yn(t,e,(o,r)=>n(r,o),!0)}function yn(e,t,n,o){let r=e.length,i=t.length,a=[];for(let E=0;E<=r;E++)a.push(new Float64Array(i+1).fill(1/0));let s=[];for(let E=0;E<=r;E++)s.push(new Uint8Array(i+1));for(let E=0;E<=i;E++)a[r][E]=0;for(let E=r-1;E>=0;E--)for(let m=i-1;m>=0;m--){let A=n(e[E],t[m])+a[E+1][m+1],M=a[E][m+1];A<=M?(a[E][m]=A,s[E][m]=1):a[E][m]=M}let c=[],g=0,v=0;for(;g<r&&v<i;)s[g][v]&&(c.push(o?[t[v],e[g]]:[e[g],t[v]]),g++),v++;return c}function Tt(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(F=>e.remove(F)),vt(s,"onRowsApplied",i.path,[]);return}let g=r.length>c.length,v=c[0]||null;if(g&&!v&&(v=Lr(e,t,n,s),!v))throw new Pe(i.path);let E=c.map(F=>Cr(e,F,o,s)),m=null;if(g&&v){m=e.clone(v),s.templateAttr&&e.removeAttr(m,s.templateAttr);let F=e.stripIds(m);F>0&&console.warn(`[hyper-html-api] stripped ${F} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let A=bn(r,E,o,kr(e,c,r,i,s)),M=c[0]||v,q=e.parent(M),I=c.length>0?Sn(e,q,M):0,D=Hr(e,c),W=new Set,ee=[],se=r.map((F,ne)=>{let Q=A[ne];if(Q>=0)return W.add(Q),ee.push(!1),c[Q];ee.push(!0);let ce=e.clone(m);return e.stripIds(ce),ce});c.forEach((F,ne)=>{W.has(ne)||e.remove(F)}),D?se.forEach((F,ne)=>{let Q=I+ne;e.children(q).findIndex(tt=>e.sameNode(tt,F))!==Q&&e.insertAt(q,F,Q)}):jr(e,se,ee,q,I),Ir(e,se,o,r,i,a,s),vt(s,"onRowsApplied",i.path,se)}function vt(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function kr(e,t,n,o,r){let i=vt(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let a=new Array(n.length).fill(-1),s=new Set;for(let c=0;c<n.length;c++)if(i[c]){for(let g=0;g<t.length;g++)if(!(s.has(g)||!e.sameNode(t[g],i[c]))){a[c]=g,s.add(g);break}}return a}function Ir(e,t,n,o,r,i,a){t.forEach((s,c)=>{if(n===null){let g=o[c],v=g==null?"":String(g);e.text(s)!==v&&e.text(s,v)}else{let g=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},a);g&&g!==s&&(t[c]=g)}})}function Cr(e,t,n,o){return n===null?e.text(t):ae(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Sn(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Lr(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let a of i)if(e.attr(a,o.templateAttr)!=null)return a;r=e.parent(r)}return null}function Hr(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let a=o.findIndex(s=>e.sameNode(s,i));if(a===-1)return!1;r.push(a)}return r.sort((i,a)=>i-a),r[r.length-1]-r[0]===r.length-1}function jr(e,t,n,o,r){let i=null,a=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let c=i?e.parent(i):o;if(!c)continue;let g=i?Sn(e,c,i)+1:a++;e.insertAt(c,t[s],g),i=t[s]}}var En=new Set(["checked","selected","disabled","readOnly","paused"]);function me(e,t,n,o,r={}){let i=[];if(Ot(n,o,[],i),i.length)throw new je(i);et(e,t,n,o,{depth:0,path:[]},r)}function et(e,t,n,o,r,i={}){if(r.depth>Oe)throw new be(r.path);if(o===void 0)return t;if(typeof n=="string")return Pr(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return Tt(e,t,a,s,o,r,et,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=et(e,t,s,o==null?o:o[a],{depth:r.depth+1,path:[...r.path,a]},i);c&&c!==t&&(t=c)}return t}return t}function Pr(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return Tt(e,t,c,null,o,r,et,i),t}if(n.startsWith("@"))return Mn(e,t,n.slice(1),o);let a=de(n);if(a!==-1){let c=n.slice(0,a),g=n.slice(a+1),v=c?e.find(t,c,i):[t];return v.length===0||Mn(e,v[0],g,o),t}if(n===".")return xn(e,t,o),t;let s=e.find(t,n,i);return s.length===0||xn(e,s[0],o),t}function xn(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Mn(e,t,n,o){if(un.has(n))throw new De(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return ln.has(n)?(e.prop(t,n,Dr(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function Dr(e,t){return t==null?En.has(e)?!1:"":En.has(e)?t==="false"?!1:!!t:t}function Ot(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:Ue([...n,i]),expected:"scalar",got:Fe(r)})}):o.push({path:Ue(n),expected:"array",got:Fe(t)});return}t!==null&&typeof t=="object"&&o.push({path:Ue(n),expected:"scalar",got:Fe(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Ue(n),expected:"array",got:Fe(t)});return}let r=e[1];t.forEach((i,a)=>Ot(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Ue(n),expected:"object",got:Fe(t)});return}for(let[r,i]of Object.entries(e))Ot(i,t[r],[...n,r],o)}}}function Fe(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Ue(e){return e.join(".")}function qe(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Rt(t,e,n);return Nt(t,e,n),{data:o,summary:n}}function Rt(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>Rt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=Rt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function Nt(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?Nt(e[r],t[r],n):n.discarded+=Se(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Nt(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=Se(t))}}function Se(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Se(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Se(n),0):1}function kt(e,t,n){let o=_e(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},a=new Set;for(let{name:s,rules:c}of o){if(a.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:g,summary:v}=qe(n[s],c);me(e,t,c,g),i[s]=v,r.carriedOver+=v.carriedOver,r.discarded+=v.discarded,r.listItems+=v.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=Se(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function It({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(D=>fetch(D)),!o)throw new Error("upgrade.run requires a document context");if(e=e||ie(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let a=new URL(e,r?r.href:void 0);n=n!==void 0?n:ie(o,"hyper-version"),t=t||Xe(X,o);let s;try{s=await i(a.href)}catch(D){throw new Ne(a.href,D)}if(!s.ok)throw new Ne(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),g=new DOMParser().parseFromString(c,"text/html"),v=ie(g,"hyper-version"),E=t,m=!1,A=Mt(X,g);if(A){let W=await(await wt(A))(E,{fromVersion:n,toVersion:v});if(!W||typeof W!="object"||Array.isArray(W))throw new he("transform must return a plain object map of { rulesName: data }");E=W,m=!0}let{totals:M,byName:q,rulesTagCount:I}=kt(X,g,E);if(I===0&&Object.keys(E).length>0)throw new $e(a.href);return{html:_r(g),fromVersion:n,toVersion:v,summary:{transformApplied:m,totals:M,byName:q}}}function _r(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
4
- `+e.documentElement.outerHTML}function Ct(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return Re(e,o,n)}return null}function wn(e,t,n,o){let r=Ct(e,t,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:a}=r;return{rules:i,tagNode:a,get:()=>ae(e,t,i,o),set:s=>me(e,t,i,s,o)}}var We={extract:(e,t,n)=>ae(X,e,t,n),apply:(e,t,n,o)=>me(X,e,t,n,o),findRulesIn:(e,t)=>Re(X,e,t),findRules:(e,t)=>Ct(X,e,t),bind:(e,t,n)=>wn(X,e,t,n),parseStrict:St,parseRelaxed:Ae,ruleAttrIndex:de,splitRule:we,errors:Qe,DOM_PROPERTIES:Ze},Lt=e=>!!e&&typeof e.nodeType=="number";function vn(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=X.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return Re(X,t).rules}function Ht(e,t){let n=Lt(e)?e:document,o=Lt(e)?t:e;return o===void 0?ae(X,n,vn(n)):We.bind(n,o).get()}function jt(e,t,n){if(!Lt(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?me(X,e,vn(e),t):We.bind(e,n).set(t),e}var Tn={buildForm:ct,bindFormEvents:lt,scaffold:Me,morphForm:mt,path:Ke},On={checkForUpdate:yt,run:It,extractAll:xt,shapeMatch:qe};var Fr={engine:We,cms:Tn,upgrade:On,extractData:Ht,applyData:jt},Ur=Fr;return Pn(qr);})();
1
+ var HyperHtmlApi=(()=>{var lt=Object.defineProperty;var Kn=Object.getOwnPropertyDescriptor;var Jn=Object.getOwnPropertyNames;var Yn=Object.prototype.hasOwnProperty;var ut=(e,t)=>{for(var n in t)lt(e,n,{get:t[n],enumerable:!0})},Gn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Jn(t))!Yn.call(e,r)&&r!==n&&lt(e,r,{get:()=>t[r],enumerable:!(o=Kn(t,r))||o.enumerable});return e};var Xn=e=>Gn(lt({},"__esModule",{value:!0}),e);var co={};ut(co,{applyData:()=>Ut,cms:()=>$n,default:()=>so,engine:()=>Ge,extractData:()=>Bt,upgrade:()=>_n});var Ze={};ut(Ze,{fromString:()=>Xe,getRuleAtPath:()=>ft,getValueAtPath:()=>De,parseConfigKey:()=>Qn,setAtPath:()=>de,toConfigKey:()=>Zn,toString:()=>ie});function ie(e){return e.map(String).join(".")}function Zn(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function Qn(e){return e===""?[]:e.split(".")}function Xe(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function ft(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 De(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function de(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]=de(s[o],r,n),s}return{...e&&typeof e=="object"?e:{},[o]:de((e||{})[o],r,n)}}function Oe(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]=Oe(o);return t}return""}var Qe=new WeakMap;function pe(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let s=e[r];s==="\\"?r++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:s==="@"&&t===0&&(o=r)}return o}function Ne(e){let t=pe(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}var er=new Set(["checked","selected","disabled","readOnly","paused"]);function dt({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),s={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(ht({rule:e,value:t,path:[],ctx:s})),r}function pt(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),en.set(e,{rules:t,getData:n,onChange:o}),tr()}var en=new WeakMap,Zt=!1;function tr(){Zt||(document.addEventListener("input",Qt,!0),document.addEventListener("change",Qt,!0),document.addEventListener("click",nr,!0),Zt=!0)}function tn(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&en.get(t)||null}function nr(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=tn(t);if(!n)return;let{rules:o,getData:r,onChange:s}=n,c=t.getAttribute("data-hha-action"),i=Xe(t.getAttribute("data-hha-path")||"");if(c==="scalar-array-add"){let a=De(r(),i)||[];s(de(r(),i,[...a,""]),{structural:!0});return}if(c==="object-array-add"){let a=ft(o,i);if(!Array.isArray(a))return;let m=De(r(),i)||[];s(de(r(),i,[...m,Oe(a[1])]),{structural:!0});return}if(c==="array-remove"){if(i.length===0)return;let a=i.slice(0,-1),m=i[i.length-1],A=De(r(),a)||[];if(typeof m!="number")return;let w=A.filter((d,E)=>E!==m);s(de(r(),a,w),{structural:!0})}}function Qt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=tn(t);if(!n)return;let{getData:o,onChange:r}=n,s=t.closest("[data-hha-path]");if(!s)return;let c=Xe(s.getAttribute("data-hha-path")||""),i=t.type==="checkbox"?t.checked:t.value;r(de(o(),c,i),{structural:!1})}function ht({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?ir({rule:e,value:t,path:n,ctx:o}):or({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return sr({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return rr({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function rr({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",ie(n)),n.length>0){let s=document.createElement("div");s.className="form-section-label",s.textContent=et(n[n.length-1]),r.appendChild(s)}for(let[s,c]of Object.entries(e)){let i=[...n,s],a=t?.[s];r.appendChild(ht({rule:c,value:a,path:i,ctx:o}))}return r}function or({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",ie(n));let s=document.createElement("div");s.className="field-body";let c=document.createElement("label");c.className="field-label",c.textContent=et(n[n.length-1]||".")+fr(e);let i=ar(e,o.appRoot),a=cr(i,{value:t,rule:e,path:n,appRoot:o.appRoot}),m=a.el;return m.classList.add(i.type==="textarea"?"field-textarea":"field-input"),s.appendChild(c),s.appendChild(m),r.appendChild(s),Qe.set(r,a),r}function ir({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",ie(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=et(n[n.length-1]),r.appendChild(s);let c=Array.isArray(t)?t:[],i=document.createElement("div");r.appendChild(i),c.forEach((m,A)=>{let w=[...n,A],d=document.createElement("div");d.className="scalar-array-row",d.setAttribute("data-hha-path",ie(w));let E=document.createElement("input");E.type="text",E.className="field-input",E.value=m==null?"":String(m);let p=document.createElement("button");p.type="button",p.className="array-remove",p.textContent="\xD7",p.title="remove",p.setAttribute("data-hha-action","array-remove"),p.setAttribute("data-hha-path",ie(w)),d.appendChild(E),d.appendChild(p),i.appendChild(d)});let a=document.createElement("button");return a.type="button",a.className="array-add",a.textContent="+ add",a.setAttribute("data-hha-action","scalar-array-add"),a.setAttribute("data-hha-path",ie(n)),r.appendChild(a),r}function sr({rule:e,value:t,path:n,ctx:o}){let[,r]=e,s=Array.isArray(t)?t:[],c=document.createElement("div");c.className="form-section",c.setAttribute("data-hha-path",ie(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=et(n[n.length-1]),c.appendChild(i),s.forEach((m,A)=>{let w=[...n,A],d=document.createElement("div");d.className="array-card",d.setAttribute("data-hha-path",ie(w));let E=document.createElement("button");E.type="button",E.className="array-remove",E.textContent="\xD7",E.title="remove item",E.setAttribute("data-hha-action","array-remove"),E.setAttribute("data-hha-path",ie(w)),d.appendChild(E);let p=ht({rule:r,value:m,path:w,ctx:o});p.querySelector(".form-section-label")?.remove(),d.appendChild(p),c.appendChild(d)});let a=document.createElement("button");return a.type="button",a.className="array-add",a.textContent="+ add",a.setAttribute("data-hha-action","object-array-add"),a.setAttribute("data-hha-path",ie(n)),c.appendChild(a),c}function cr(e,t){let n=ur(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 ar(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):n=Ne(e).prop,n&&er.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=lr(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 c=(o.getAttribute("type")||"text").toLowerCase();if(c==="checkbox"||c==="radio")return{type:"checkbox"};if(c==="number")return{type:"number"}}let s=(o.textContent||"").trim();return s.length>60||s.includes(`
2
+ `)?{type:"textarea"}:{type:"text"}}function lr(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=Ne(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function ur(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 et(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 fr(e){return` \xB7 ${e}`}var nn={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 dr(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 pr(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 hr(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 mr(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function gr(e,t){let n=[e.tagName];return t.includeClasses&&n.push(pr(e)),n.push(hr(e,t)),dr(n.join("|"))}function yr(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function br(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function Ar(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function Sr(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${yr(o)}`;if(n.unshift(r),o!==e&&br(o,t)){n.unshift(Ar(o));break}o=o.parentElement}return n}function Er(e,t){let n=0,o=e.length-1,r=t.length-1;for(;o>=0&&r>=0&&e[o]===t[r];)n++,o--,r--;return n}function se(e,t,n){if(n.has(e))return n.get(e);let o={signature:gr(e,t),path:Sr(e,t),textHint:mr(e,t)};return n.set(e,o),o}function cn(e,t,n,o){if(o.has(e))return o.get(e);let r=new Map,s=e.querySelectorAll("*"),c=0;for(let i of s){let a=se(i,t,n);a.domIndex=c++,!t.shouldIgnore?.(i)&&(r.has(a.signature)||r.set(a.signature,[]),r.get(a.signature).push(i))}return o.set(e,r),r}function wr(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function mt(e,t,n,o,r){let s=se(e,n,o),c=se(t,n,o),i=n.weights,a={},m=0;if(s.signature!==c.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};m+=i.signature,a.signature=i.signature;let w=Er(s.path,c.path)*i.pathSegment;m+=w,a.path=w;let d=!0;if(s.textHint&&c.textHint?s.textHint===c.textHint?(m+=i.textMatch,a.text=i.textMatch):(m-=i.textMismatch,a.text=-i.textMismatch,d=!1):s.textHint!==c.textHint&&(m-=i.textMismatch,a.text=-i.textMismatch,d=!1),r.candidateCount===1&&d&&(m+=i.uniqueCandidate,a.unique=i.uniqueCandidate),typeof s.domIndex=="number"&&typeof c.domIndex=="number"){let E=Math.abs(s.domIndex-c.domIndex),p=Math.min(E*i.positionPenalty,i.maxDriftPenalty);m-=p,a.drift=-p}return{score:m,breakdown:a}}function rn(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let s=cn(t,n,o,r),c=se(e,n,o);if(typeof c.domIndex!="number"){let d=0,E=e.previousElementSibling;for(;E;)d++,E=E.previousElementSibling;c.domIndex=d}let i=s.get(c.signature)||[],a=n.excludeIds?i.filter(d=>!d.getAttribute("id")):i;if(a.length===0)return null;let m=null,A=0,w=null;for(let d of a){let{score:E,breakdown:p}=mt(e,d,n,o,{candidateCount:a.length});E>A&&(A=E,m=d,w=p)}return A<n.minConfidence?null:{element:m,confidence:A,breakdown:w}}function Tr(e,t,n,o){let r=[],s=n.weights.signature+n.weights.slotMatch,c={slot:s};function i(w){if(w.children)return w.children;let d=w.childNodes;if(!d)return[];let E=[];for(let p=0;p<d.length;p++)d[p].nodeType===1&&E.push(d[p]);return E}function a(w,d){let E=i(w),p=i(d);if(E.length===p.length)for(let R=0;R<E.length;R++){let x=E[R],k=p[R];if(n.shouldIgnore?.(x)||n.shouldIgnore?.(k)||n.excludeIds&&(x.getAttribute("id")||k.getAttribute("id"))||x.tagName!==k.tagName)continue;let P=se(x,n,o).signature,W=se(k,n,o).signature;P!==W&&r.push({newEl:x,oldEl:k,score:s,breakdown:c}),a(x,k)}}function m(w,d){for(;;){if(w.tagName===d.tagName)return[w,d];let E=i(w);if(!w.tagName&&E.length===1){w=E[0];continue}let p=i(d);if(p.length===1&&p[0].tagName===w.tagName){d=p[0];continue}return null}}let A=m(e,t);return A&&a(A[0],A[1]),r}function on(e,t,n,o,r){let s=t.querySelectorAll("*"),c=cn(e,n,o,r),i=0;for(let E of s){let p=se(E,n,o);p.domIndex=i++}let a=[],m=new Map;function A(E,p,R){let x=new Set;if(E.textHint){let $=m.get(E.signature);if(!$){$=new Map;for(let z of p){let oe=se(z,n,o).textHint,ae=$.get(oe);ae||(ae=[],$.set(oe,ae)),ae.push(z)}m.set(E.signature,$)}let G=$.get(E.textHint);if(G)for(let z=0;z<G.length&&z<R;z++)x.add(G[z])}let k=0,P=p.length;for(;k<P;){let $=k+P>>1;se(p[$],n,o).domIndex<E.domIndex?k=$+1:P=$}let W=Math.max(0,Math.min(k-(R>>1),p.length-R)),K=Math.min(W+R,p.length);for(let $=W;$<K;$++)x.add(p[$]);return[...x]}for(let E of s){if(n.shouldIgnore?.(E)||n.excludeIds&&E.getAttribute("id"))continue;let p=se(E,n,o),R=c.get(p.signature)||[],x=n.excludeIds?R.filter(W=>!W.getAttribute("id")):R,k=n.maxScoredCandidates,P=k&&x.length>k?A(p,x,k):x;for(let W of P){let{score:K,breakdown:$}=mt(E,W,n,o,{candidateCount:x.length});K>=n.minConfidence&&a.push({newEl:E,oldEl:W,score:K,breakdown:$})}}if(n.weights.slotMatch>0){let E=Tr(t,e,n,o);for(let p of E)a.push(p)}a.sort((E,p)=>p.score-E.score);let w=new Map,d=new Set;for(let{newEl:E,oldEl:p}of a)w.has(E)||d.has(p)||(w.set(E,p),d.add(p));return w}function sn(e,t,n,o){let r=se(e,n,o),s=se(t,n,o),{score:c,breakdown:i}=mt(e,t,n,o,{candidateCount:1});return{matches:c>=n.minConfidence,score:c,breakdown:i,newMeta:{signature:r.signature,path:r.path,textHint:r.textHint},oldMeta:{signature:s.signature,path:s.path,textHint:s.textHint}}}function an(e={}){let t={...nn,...e,weights:{...nn.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,s)=>rn(r,s,t,n,o),computeMatches:(r,s)=>on(r,s,t,n,o),explain:(r,s)=>sn(r,s,t,n),invalidate:r=>wr(r,n,o),session:()=>{let r=new WeakMap,s=new WeakMap;return{findMatch:(c,i)=>rn(c,i,t,r,s),computeMatches:(c,i)=>on(c,i,t,r,s),explain:(c,i)=>sn(c,i,t,r)}},getConfig:()=>({...t})}}function gt(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 ln(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var xr=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Mr=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function tt(e){try{return JSON.parse(e)}catch{return JSON.parse(vr(e))}}function vr(e){let t="",n=0,o=(r,s)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${s}`)};for(;n<e.length&&(n=gt(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let i=gt(e,n+1);if(e[i]==="}"||e[i]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let i=n+1;for(;i<e.length&&e[i]!==r;)e[i]==="\\"&&i++,i++;i>=e.length&&o("unterminated string",n);let a=e.slice(n+1,i);r==="'"&&(a=ln(a)),t+='"'+a+'"',n=i+1;continue}let s=n;for(;s<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[s]);)s++;s===n&&o("unexpected character "+JSON.stringify(r),n);let c=e.slice(n,s);if(c==="true"||c==="false"||c==="null"||xr.test(c)){t+=c,n=s;continue}if(Mr.test(c)){if(e[gt(e,s)]===":"){t+='"'+c+'"',n=s;continue}o("unquoted value "+JSON.stringify(c),n)}o("invalid token "+JSON.stringify(c),n)}return t}function un(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let s=[],c=0;for(;c<r.length;){let i=r[c];if(/\s/.test(i)){c++;continue}if("{}".includes(i)){s.push({type:i,value:i}),c++;continue}if(i==="["){let w=!1,d=c+1;for(;d<r.length&&/\s/.test(r[d]);)d++;if(d<r.length&&/[a-zA-Z_]/.test(r[d])&&(w=!0),!w){s.push({type:i,value:i}),c++;continue}}if(i==="]"){s.push({type:i,value:i}),c++;continue}if(i===":"){s.push({type:t.COLON,value:i}),c++;continue}if(i===","){s.push({type:t.COMMA,value:i}),c++;continue}if(i==='"'||i==="'"){let w=i,d=c+1;for(;d<r.length&&r[d]!==w;)r[d]==="\\"&&d++,d++;s.push({type:t.STRING,value:r.substring(c+1,d),quoted:!0,sourceQuote:w}),c=d+1;continue}let a=c,m;for(;a<r.length&&!/[{},]/.test(r[a]);)if(r[a]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let E of w){let p=E.substring(1);if(r.substring(a+1,a+1+p.length)===p){d=!0,a+=p.length;break}}if(!d)break}else if(r[a]==="["){for(a++;a<r.length&&r[a]!=="]";){if(r[a]==='"'||r[a]==="'"){let w=r[a];for(a++;a<r.length&&r[a]!==w;)r[a]==="\\"&&a++,a++}a++}a<r.length&&r[a]==="]"&&a++}else a++;m=r.substring(c,a);let A=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(m)?A=t.NUMBER:m==="true"||m==="false"||m==="null"?A=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(m)&&(A=t.SELECTOR),s.push({type:A,value:m,quoted:!1}),c=a}return s}function o(r){let s="";for(let c=0;c<r.length;c++){let i=r[c];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 a=r[c+1];if(a&&(a.type==="}"||a.type==="]"))continue;s+=i.value;continue}if(i.type===t.STRING){let a=i.value;i.sourceQuote==="'"&&(a=ln(a)),s+=`"${a}"`;continue}if(i.type===t.NUMBER||i.type===t.BOOLEAN){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 Error("Invalid extraction rules syntax: "+r.message)}}var Q=Symbol("hyper-morph-json-merge:missing"),fn=["id","_id","uuid","key","slug","code","name"];function ke(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function He(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Or(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function he(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(!he(e[n],t[n]))return!1;return!0}if(ke(e)&&ke(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!He(t,o)||!he(e[o],t[o]))return!1;return!0}return!1}function dn(e,t,n,o){return he(t,n)?t:he(t,e)?n:he(n,e)?t:ke(t)&&ke(n)?Nr(ke(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?Ir(Array.isArray(e)?e:[],t,n,o):n}function pn(e,t,n,o){return t===Q&&n===Q?Q:t===Q?e===Q?n:he(n,e)?Q:n:n===Q?e===Q?t:Q:dn(e,t,n,o)}function Nr(e,t,n,o){let r={},s=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let c of s){let i=pn(He(e,c)?e[c]:Q,He(t,c)?t[c]:Q,He(n,c)?n[c]:Q,o);i!==Q&&Or(r,c,i)}return r}function kr(e){return e===null||typeof e!="object"}function nt(e){return typeof e+":"+String(e)}function Cr(e,t){for(let n of t){let o=new Set;for(let r of n){if(!He(r,e))return!1;let s=r[e];if(typeof s!="string"&&typeof s!="number")return!1;let c=nt(s);if(o.has(c))return!1;o.add(c)}}return!0}function Rr(e,t,n,o){let r=[e,t,n],s=!0;for(let c of r)for(let i of c)ke(i)||(s=!1);if(s){for(let c of o.keyCandidates)if(Cr(c,r))return{kind:"keyed",field:c};return null}for(let c of r){let i=new Set;for(let a of c){if(!kr(a))return null;let m=nt(a);if(i.has(m))return null;i.add(m)}}return{kind:"self"}}function Ir(e,t,n,o){let r=Rr(e,t,n,o);if(!r)return n;let s=r.kind==="self"?nt:E=>nt(E[r.field]),c=E=>{let p=new Map;for(let R of E)p.set(s(R),R);return p},i=c(e),a=c(t),m=c(n),A=new Map,w=new Set([...i.keys(),...a.keys(),...m.keys()]);for(let E of w){let p=pn(i.has(E)?i.get(E):Q,a.has(E)?a.get(E):Q,m.has(E)?m.get(E):Q,o);p!==Q&&A.set(E,p)}let d=[];for(let E of n){let p=s(E);A.has(p)&&d.push(p)}for(let E=0;E<t.length;E++){let p=s(t[E]);if(!A.has(p)||d.includes(p))continue;let R=0;for(let x=E-1;x>=0;x--){let k=d.indexOf(s(t[x]));if(k!==-1){R=k+1;break}}d.splice(R,0,p)}return d.map(E=>A.get(E))}function yt(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...fn]:fn;return dn(e===void 0?Q:e,t,n,{keyCandidates:r})}function bt(e,t,n,o={}){let r=o.parse||tt,s=[],c=(w,d)=>{if(typeof w!="string")return Q;try{return r(w)}catch(E){return s.push(`${d} side is not valid JSON (${E.message})`),Q}},i=c(t,"local"),a=c(n,"remote");if(i===Q)return{text:n,warnings:s};if(a===Q)return{text:t,warnings:s};let m=c(e,"base"),A=yt(m===Q?void 0:m,i,a,o);return he(A,a)?{text:n,warnings:s}:he(A,i)?{text:t,warnings:s}:{text:JSON.stringify(A,null,2),warnings:s}}var Lr=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),wo=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),To=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function hn(e){let t=Lr[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}var $e=function(){"use strict";let e=()=>{},t='[editor-ui],[clay~="editor-ui"],[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]',n=`${hn("history")},[no-undo],[clay~="no-undo"]`;function o(l){if(l?.nodeType!==1)return!1;if(l.matches(t))return!0;if(l.tagName==="LINK"||l.tagName==="SCRIPT"){let M=l.getAttribute("src")||l.getAttribute("href")||"";if(M.startsWith("chrome-extension://")||M.startsWith("moz-extension://")||M.startsWith("safari-web-extension://"))return!0}return!1}function r(l){return l?.nodeType!==1?!1:l.closest(t)?!0:o(l)}function s(l,M,T){if(T){let L=T.identityOf(l);if(L&&!T.disabled.has(L.key))return"hm-merge:"+L.key}if(M!=="smart")return l.outerHTML;let I=l.getAttribute("src"),N=l.getAttribute("type")||"text/javascript";if(I)try{let L=new URL(I,window.location.href);return`ext:${N}:${L.origin}${L.pathname}${L.search}`}catch{return`ext:${N}:${I}`}else{let L=l.textContent.trim(),g=5381;for(let y=0;y<L.length;y++)g=(g<<5)+g^L.charCodeAt(y);return`inline:${N}:${Math.abs(g).toString(36)}`}}let c="http://www.w3.org/1999/xhtml";function i(l){return l?.nodeType===1&&l.tagName==="SCRIPT"&&l.namespaceURI===c}function a(l){let M=document.createElement("div");M.innerHTML="<script><\/script>";let T=M.firstChild;for(let I of l.attributes)T.setAttribute(I.name,I.value);return T.textContent=l.textContent,T}function m(l){if(i(l))return a(l);if(l?.nodeType===1)for(let M of l.querySelectorAll("script"))i(M)&&M.replaceWith(a(M));return l}function A(l){let M=(l.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return M==="application/json"||M.endsWith("+json")}let w={match:l=>l.hasAttribute("merge"),identity:l=>l.getAttribute("merge")};function d(l,M,T){if(T.merge===!1)return null;let I=[w,...T.mergeTags||[]],N=new WeakMap,L=f=>{if(N.has(f))return N.get(f);let v=null;if(i(f)&&!f.getAttribute("src")&&!r(f)){let O=f;for(let j=0;j<I.length;j++)if(I[j].match(O)){if(!A(O))console.warn("[hyper-morph] merge ignored: script type is not JSON",O);else{let U=I[j].identity(O);U!=null&&U!==""&&(v={key:j+":"+U,raw:U,recognizer:I[j]})}break}}return N.set(f,v),v},g=new Set,y=f=>{let v=new Map,O=j=>{let U=L(j);U&&(v.has(U.key)?(g.add(U.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${U.raw}"`)):v.set(U.key,j))};i(f)&&O(f);for(let j of f.querySelectorAll("script"))O(j);return v},b=y(l),u=y(M.__hyperMorphRoot||M);if(b.size===0&&u.size===0)return null;let h=null;return{identityOf:L,disabled:g,oldByKey:b,newByKey:u,baseTexts:()=>{if(h)return h;h=new Map;let f=T.mergeBase;if(!f)return h;let v;typeof f=="string"?v=new DOMParser().parseFromString(f,"text/html").documentElement:f?.nodeType===9?v=f.documentElement:v=f;let O=j=>{let U=L(j);U&&!h.has(U.key)&&h.set(U.key,j.textContent)};i(v)&&O(v);for(let j of v.querySelectorAll("script"))O(j);return h}}}function E(l,M,T){let I=l.merge;if(!I)return!1;let N=I.identityOf(M);if(!N||I.disabled.has(N.key))return!1;let L=I.identityOf(T);if(!L||L.key!==N.key)return!1;let g=M,y=T,b=y.getAttribute("merge-key")||g.getAttribute("merge-key"),{text:u,warnings:h}=bt(I.baseTexts().get(N.key),g.textContent,y.textContent,{parse:N.recognizer.parse,keyCandidates:b?b.split(/[\s,]+/).filter(Boolean):void 0});for(let S of h)console.warn(`[hyper-morph] merge "${N.raw}": ${S}`);return g.textContent!==u&&(g.textContent=u),!0}let p={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:l=>l.getAttribute("im-preserve")==="true",shouldReAppend:l=>l.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:l=>l.getAttribute("im-preserve")==="true",shouldReAppend:l=>l.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},R={computeMatches(l,M,T=r){let{computeMatches:I}=an({shouldIgnore:T}).session();return I(l,M)}};function x(l,M,T={}){l=zn(l);let I=qt(M),N=qn(l,I,T),L=N.scripts.handle?new Set(Array.from(l.querySelectorAll("script")).map(u=>s(u,N.scripts.matchMode,N.merge))):null,g=z(N),y;try{y=Bn(N,l,I,u=>u.morphStyle==="innerHTML"?(ae(u,l,I),Array.from(l.childNodes)):G(u,l,I))}catch(u){throw P(N),u}let b=u=>{g&&oe(N,g),k(N);let h=L?Fn(u,L,N):[];return h.length>0?Promise.all(h).then(()=>u):u};if(y instanceof Promise)return y.then(u=>{try{return b(u)}catch(h){throw P(N),h}},u=>{throw P(N),u});try{return b(y)}catch(u){throw P(N),u}}function k(l){let M=l.pantry;if(M){for(let T of Array.from(M.childNodes))l.callbacks.beforeNodeRemoved(T)!==!1&&l.callbacks.afterNodeRemoved(T);for(let T of Array.from(M.childNodes))M.removeChild(T);M.remove(),l.pantry=null,l.stagedNodes.clear()}}function P(l){let M=l.pantry;if(!M)return;let T=Array.from(l.stagedNodes.entries()).reverse();for(let[I,N]of T){if(!M.contains(I))continue;let L=N.nextSibling?.parentNode===N.parent?N.nextSibling:null;try{K(N.parent,I,L)}catch{}}for(let I of Array.from(M.childNodes))M.removeChild(I);M.remove(),l.pantry=null,l.stagedNodes.clear()}function W(l){if(l.pantry)return l.pantry;let M=l.target.ownerDocument,T=M.createElement("div");return T.hidden=!0,T.setAttribute("mutations-ignore",""),M.body.insertAdjacentElement("afterend",T),l.pantry=T,T}function K(l,M,T){if(l.moveBefore)try{l.moveBefore(M,T)}catch{l.insertBefore(M,T)}else l.insertBefore(M,T)}function $(l,M){!l.stagedNodes.has(M)&&M.parentNode&&l.stagedNodes.set(M,{parent:M.parentNode,nextSibling:M.nextSibling}),K(W(l),M,null)}function G(l,M,T){let I=qt(M);return ae(l,I,T,M,M.nextSibling),Array.from(I.childNodes)}function z(l){if(!l.config.restoreFocus)return null;let M=document.activeElement;if(!(M instanceof HTMLInputElement||M instanceof HTMLTextAreaElement))return null;let{id:T,selectionStart:I,selectionEnd:N}=M;return{element:M,id:T,selectionStart:I,selectionEnd:N}}function oe(l,M){let T=M.element;if(M.id&&M.id!==document.activeElement?.getAttribute("id")&&(T=l.target.querySelector(`[id="${CSS.escape(M.id)}"]`),T?.focus()),T&&!T.selectionEnd&&M.selectionEnd!=null)try{T.setSelectionRange(M.selectionStart,M.selectionEnd)}catch{}}let ae=function(){function l(u,h,S,f=null,v=null){h?.tagName==="TEMPLATE"&&S?.tagName==="TEMPLATE"&&(h=h.content,S=S.content),f||=h.firstChild;for(let O of S.childNodes){if(u.shouldIgnore(O))continue;if(f&&f!=v){let U=I(u,O,f,v);if(U){U!==f&&L(u,f,U),xe(U,O,u),f=U.nextSibling;continue}}if(O?.nodeType===1){let U=O.getAttribute("id");if(u.persistentIds.has(U)){let C=g(h,U,f,u);xe(C,O,u),f=C.nextSibling;continue}if(!u.idMap.has(O)){let C=u.hyperMatches.get(O);if(C&&!u.idMap.has(C)&&!b(C,h)){K(h,C,f),xe(C,O,u),f=C.nextSibling;continue}}}let j=M(h,O,f,u);j&&(f=j.nextSibling)}for(;f&&f!=v;){let O=f;f=f.nextSibling,u.shouldIgnore(O)||N(u,O)}}function M(u,h,S,f){if(f.callbacks.beforeNodeAdded(h)===!1)return null;let v=u.ownerDocument||u.realParentNode?.ownerDocument||f.target.ownerDocument;if(f.idMap.has(h)){let O=h,j=v.createElementNS(O.namespaceURI,O.localName);return u.insertBefore(j,S),xe(j,h,f),f.callbacks.afterNodeAdded(j),j}else{let O=m(T(h,v,f));return O?(u.insertBefore(O,S),f.callbacks.afterNodeAdded(O),O):null}}function T(u,h,S){if(S.shouldIgnore(u))return null;let f=h.importNode(u,!1),v=u.nodeType===1&&u.tagName==="TEMPLATE"?u.content:u,O=f.nodeType===1&&f.tagName==="TEMPLATE"?f.content:f;for(let j of Array.from(v.childNodes||[])){let U=T(j,h,S);U&&O.appendChild(U)}return f}let I=function(){function u(f,v,O,j){let U=v?.nodeType===1&&!f.idMap.has(v)?f.hyperMatches.get(v):null,C=null,D=v.nextSibling,V=0,F=O;for(;F&&F!=j;){if(f.shouldIgnore(F)){F=F.nextSibling;continue}if(S(F,v)){if(h(f,F,v)||F===U&&!f.idMap.has(F))return F;if(C===null){let Z=F?.nodeType===1&&f.hyperMatchedOldElements.has(F);!f.idMap.has(F)&&!Z&&(C=F)}}if(C===null&&D&&S(F,D)&&(V++,D=D.nextSibling,V>=2&&(C=void 0)),f.activeElementAndParents.includes(F))break;F=F.nextSibling}return C||null}function h(f,v,O){let j=f.idMap.get(v),U=f.idMap.get(O);if(!U||!j)return!1;for(let C of j)if(U.has(C))return!0;return!1}function S(f,v){let O=f,j=v;return O.nodeType===j.nodeType&&O.tagName===j.tagName&&(!O.getAttribute?.("id")||O.getAttribute?.("id")===j.getAttribute?.("id"))}return u}();function N(u,h){let S=h?.nodeType===1&&u.hyperMatchedOldElements.has(h)&&!u.idMap.has(h);if(u.idMap.has(h)||S)$(u,h);else{if(u.callbacks.beforeNodeRemoved(h)===!1)return;h.parentNode?.removeChild(h),u.callbacks.afterNodeRemoved(h)}}function L(u,h,S){let f=h;for(;f&&f!==S;){let v=f;f=f.nextSibling,u.shouldIgnore(v)||N(u,v)}return f}function g(u,h,S,f){let v=f.target.ownerDocument?.defaultView?.CSS?.escape?f.target.ownerDocument.defaultView.CSS.escape(h):String(h).replace(/["\\]/g,"\\$&"),O=f.target.getAttribute?.("id")===h&&f.target||f.target.querySelector(`[id="${v}"]`)||f.pantry?.querySelector(`[id="${v}"]`);return y(O,f),K(u,O,S),O}function y(u,h){let S=u.getAttribute("id");for(;u=u.parentNode;){let f=h.idMap.get(u);f&&(f.delete(S),f.size||h.idMap.delete(u))}}function b(u,h){let S=h?.nodeType===1?h:h.realParentNode;return!!S&&u.contains(S)}return l}(),xe=function(){function l(g,y,b){return b.ignoreActive&&g===document.activeElement?null:(b.callbacks.beforeNodeMorphed(g,y)===!1||(g?.tagName==="HEAD"&&b.head.ignore||(g?.tagName==="HEAD"&&b.head.style!=="morph"?Ft(g,y,b):(M(g,y,b),E(b,g,y)||L(g,b)||ae(b,g,y))),b.callbacks.afterNodeMorphed(g,y)),g)}function M(g,y,b){let u=y.nodeType;if(u===1){let h=g,S=y,f=h.attributes,v=S.attributes;for(let O of v)N(O.name,h,"update",b)||h.getAttribute(O.name)!==O.value&&h.setAttribute(O.name,O.value);for(let O=f.length-1;0<=O;O--){let j=f[O];if(j&&!S.hasAttribute(j.name)){if(N(j.name,h,"remove",b))continue;h.removeAttribute(j.name)}}L(h,b)||T(h,S,b)}(u===8||u===3)&&g.nodeValue!==y.nodeValue&&(g.nodeValue=y.nodeValue)}function T(g,y,b){if(g.tagName==="INPUT"&&y.tagName==="INPUT"&&y.type!=="file"){let u=y.value,h=g.value;I(g,y,"checked",b),I(g,y,"disabled",b),b.formStateSync==="property"&&g.indeterminate!==y.indeterminate&&(g.indeterminate=y.indeterminate),b.formStateSync==="property"?h!==u&&(N("value",g,"update",b)||(g.value=u)):y.hasAttribute("value")?h!==u&&(N("value",g,"update",b)||(g.setAttribute("value",u),g.value=u)):N("value",g,"remove",b)||(g.value="",g.removeAttribute("value"))}else if(g.tagName==="OPTION"&&y.tagName==="OPTION")I(g,y,"selected",b);else if(g.tagName==="TEXTAREA"&&y.tagName==="TEXTAREA"){let u=y.value,h=g.value;if(N("value",g,"update",b)||(u!==h&&(g.value=u),b.formStateSync==="property"))return;g.firstChild&&g.firstChild.nodeValue!==u&&(g.firstChild.nodeValue=u)}}function I(g,y,b,u){let h=y[b],S=g[b];if(h!==S){let f=N(b,g,"update",u);if(f||(g[b]=y[b]),u.formStateSync==="property")return;h?f||g.setAttribute(b,""):N(b,g,"remove",u)||g.removeAttribute(b)}}function N(g,y,b,u){return g==="value"&&u.ignoreActiveValue&&y===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(g,y,b)===!1}function L(g,y){return!!y.ignoreActiveValue&&g===document.activeElement&&g!==document.body}return l}();function Bn(l,M,T,I){if(l.head.block){let N=M.querySelector("head"),L=T.querySelector("head");if(N&&L){let g=Ft(N,L,l);return Promise.all(g).then(()=>(l.head.block=!1,l.head.ignore=!0,I(l)))}}return I(l)}function Un(l){return l.tagName==="SCRIPT"?!!l.getAttribute("src"):l.tagName==="LINK"?(l.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!l.getAttribute("href"):!1}function Ft(l,M,T){let I=[],N=[],L=[],g=[],y=T.scripts.matchMode,b=S=>{if(S.tagName==="SCRIPT")return s(S,y,T.merge);if(S.tagName==="LINK"&&y==="smart"){let f=S.getAttribute("href");if(f)try{let v=new URL(f,window.location.href);return`link:${S.getAttribute("rel")||""}:${v.origin}${v.pathname}${v.search}`}catch{}}return S.outerHTML},u=new Map;for(let S of M.children){if(T.shouldIgnore(S))continue;let f=b(S),v=u.get(f);v||(v=[],u.set(f,v)),v.push(S)}for(let S of l.children){let f=b(S),v=u.get(f),O=!!(v&&v.length),j=T.head.shouldReAppend(S),U=T.head.shouldPreserve(S);if(O||U)if(j)N.push(S);else{if(v&&v.length){let C=v.pop();v.length||u.delete(f),E(T,S,C)}L.push(S)}else T.head.style==="append"?j&&(N.push(S),g.push(S)):T.head.shouldRemove(S)!==!1&&!T.shouldIgnore(S)&&N.push(S)}for(let S of u.values())g.push(...S);let h=[];for(let S of g){let f=document.createRange().createContextualFragment(S.outerHTML).firstChild;if(T.callbacks.beforeNodeAdded(f)!==!1){if(f instanceof Element&&Un(f)){let v,O=new Promise(function(j){v=j});f.addEventListener("load",function(){v()}),f.addEventListener("error",function(){v()}),h.push(O)}l.appendChild(f),T.callbacks.afterNodeAdded(f),I.push(f)}}for(let S of N)T.callbacks.beforeNodeRemoved(S)!==!1&&(l.removeChild(S),T.callbacks.afterNodeRemoved(S));return T.head.afterHeadMorphed(l,{added:I,kept:L,removed:N}),h}function Fn(l,M,T){if(!T.scripts.handle)return[];let I=[],N=[],L=[],g=[],y=T.scripts.matchMode,b=[];for(let h of l)if(h instanceof Element){i(h)&&b.push(h);for(let S of h.querySelectorAll("script"))i(S)&&b.push(S)}for(let h of b){if(h.closest("head")||T.shouldIgnore(h))continue;let S=s(h,y,T.merge),f=M.has(S),v=T.scripts.shouldPreserve(h),O=T.scripts.shouldReAppend(h);f||v?O?(N.push(h),g.push(h)):L.push(h):g.push(h)}let u=[];for(let h of g){if(T.callbacks.beforeNodeAdded(h)===!1)continue;let S=document.createElement("script");for(let f of h.attributes)S.setAttribute(f.name,f.value);if(S.textContent=h.textContent,S.src){let f,v=new Promise(function(O){f=O});S.addEventListener("load",function(){f()}),S.addEventListener("error",function(){f()}),u.push(v)}h.replaceWith(S),T.callbacks.afterNodeAdded(S),I.push(S)}return T.scripts.afterScriptsHandled(T.target,{added:I,kept:L,removed:N}),u}let qn=function(){function l(y,b,u){let h=u.policy==="history"?n:t,S=u.policy==="raw"?()=>!1:V=>{if(V?.nodeType!==1)return!1;if(u.policy!=="history"&&r(V))return!0;let F=V.closest(h);return!(!F||u.policy==="history"&&F===y&&F.matches('[no-undo],[clay~="no-undo"]')&&!F.matches('[editor-ui],[clay~="editor-ui"]'))},{persistentIds:f,idMap:v}=L(y,b,S),O=R.computeMatches(y,b,S);if(typeof u.key=="function"){let V=new Map,F=new Set,Z=H=>{let B=u.key(H);B!=null&&(V.has(B)?F.add(B):V.set(B,H))};y instanceof Element&&Z(y);for(let H of y.querySelectorAll("*"))Z(H);for(let H of F)V.delete(H);let ne=new Map;for(let[H,B]of O)ne.set(B,H);let re=b.__hyperMorphRoot||b,Y=new Map,_=new Set,J=H=>{let B=u.key(H);B!=null&&(Y.has(B)?_.add(B):Y.set(B,H))};re instanceof Element&&J(re);for(let H of re.querySelectorAll("*"))J(H);for(let H of _)Y.delete(H);for(let[H,B]of Y){let X=V.get(H);if(!X||X.tagName!==B.tagName)continue;let ye=ne.get(X);ye&&ye!==B&&O.delete(ye);let be=O.get(B);be&&be!==X&&ne.delete(be),O.set(B,X),ne.set(X,B)}}let j=M(u),U=d(y,b,j.scripts);if(U){let V=new Map;for(let[F,Z]of O)V.set(Z,F);for(let[F,Z]of U.newByKey){if(U.disabled.has(F))continue;let ne=U.oldByKey.get(F);if(!ne)continue;let re=V.get(ne);re&&re!==Z&&O.delete(re);let Y=O.get(Z);Y&&Y!==ne&&V.delete(Y),O.set(Z,ne),V.set(ne,Z)}}let C=new Set;for(let V of O.values())C.add(V);let D=j.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(D))throw new Error(`Do not understand how to morph style ${D}`);return{target:y,newContent:b,config:j,morphStyle:D,ignoreActive:j.ignoreActive,ignoreActiveValue:j.ignoreActiveValue,restoreFocus:j.restoreFocus,formStateSync:j.formStateSync||"attribute",idMap:v,persistentIds:f,hyperMatches:O,hyperMatchedOldElements:C,merge:U,pantry:null,stagedNodes:new Map,activeElementAndParents:T(y),callbacks:j.callbacks,head:j.head,scripts:j.scripts,shouldIgnore:S}}function M(y){let b=Object.assign({},p);return Object.assign(b,y),b.callbacks=Object.assign({},p.callbacks,y.callbacks),b.head=Object.assign({},p.head,y.head),b.scripts=Object.assign({},p.scripts,y.scripts),b}function T(y){let b=[],u=y.ownerDocument?.activeElement;if(u?.tagName!=="BODY"&&y.contains(u))for(;u&&(b.push(u),u!==y);)u=u.parentElement;return b}function I(y){let b=Array.from(y.querySelectorAll("[id]"));return y.getAttribute?.("id")&&b.push(y),b}function N(y,b,u,h){for(let S of h){let f=S.getAttribute("id");if(b.has(f)){let v=S;for(;v;){let O=y.get(v);if(O==null&&(O=new Set,y.set(v,O)),O.add(f),v===u)break;v=v.parentElement}}}}function L(y,b,u){let h=I(y).filter(j=>!u(j)),S=I(b).filter(j=>!u(j)),f=g(h,S),v=new Map;N(v,f,y,h);let O=b.__hyperMorphRoot||b;return N(v,f,O,S),{persistentIds:f,idMap:v}}function g(y,b){let u=new Set,h=new Map;for(let f of y){let v=f.getAttribute("id");h.has(v)?u.add(v):h.set(v,f.tagName)}let S=new Set;for(let f of b){let v=f.getAttribute("id");S.has(v)?u.add(v):h.get(v)===f.tagName&&S.add(v)}for(let f of u)S.delete(f);return S}return l}(),{normalizeElement:zn,normalizeParent:qt}=function(){let l=new WeakSet;function M(g){return g?.nodeType===9?g.documentElement:g}function T(g){if(g==null)return document.createElement("div");if(typeof g=="string")return T(L(g));if(l.has(g))return g;if(g&&typeof g=="object"&&"nodeType"in g){if(g.parentNode)return new I(g);{let y=g.ownerDocument.createElement("div");return y.append(g),y}}else{let b=[...g][0]?.ownerDocument?.createElement("div")||document.createElement("div");for(let u of[...g])b.append(u);return b}}class I{constructor(y){this.originalNode=y,this.realParentNode=y.parentNode,this.previousSibling=y.previousSibling,this.nextSibling=y.nextSibling}get childNodes(){let y=[],b=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;b&&b!=this.nextSibling;)y.push(b),b=b.nextSibling;return y}querySelectorAll(y){return this.childNodes.reduce((b,u)=>{if(u instanceof Element){u.matches(y)&&b.push(u);let h=u.querySelectorAll(y);for(let S=0;S<h.length;S++)b.push(h[S])}return b},[])}insertBefore(y,b){return this.realParentNode.insertBefore(y,b)}moveBefore(y,b){return this.realParentNode.moveBefore(y,b)}get __hyperMorphRoot(){return this.originalNode}}function N(g){let y=S=>`<${S}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,b=g.replace(/<!--[\s\S]*?-->/g,"");for(let S of["script","style","textarea","title"])b=b.replace(new RegExp(`${y(S)}[\\s\\S]*?</${S}\\s*>`,"gi"),"");let u=new RegExp(`${y("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),h;do h=b,b=b.replace(u,"");while(b!==h);return b}function L(g){let y=new DOMParser,b=N(g);if(b.match(/<\/html>/)||b.match(/<\/head>/)||b.match(/<\/body>/)){let u=y.parseFromString(g,"text/html");if(b.match(/<\/html>/))return l.add(u),u;{let h=u.firstChild;return h&&l.add(h),h}}else{let h=y.parseFromString("<body><template>"+g+"</template></body>","text/html").body.querySelector("template").content;return l.add(h),h}}return{normalizeElement:M,normalizeParent:T}}(),zt=Symbol("hyper-morph-duplicate-key"),Vt=[l=>l.getAttribute("data-id"),l=>l.getAttribute("id")];function je(l,M){return M.map(T=>{let I=new Map;for(let N of l){if(N.nodeType!==1)continue;let L=T(N);L==null||L===""||I.set(L,I.has(L)?zt:N)}return I})}function Wt(l,M,T,I){for(let N=0;N<I.length;N++){let L=I[N](l);if(L==null||L===""||M[N].get(L)!==l)continue;let g=T[N].get(L);if(!(!g||g===zt)&&g.tagName===l.tagName)return g}return null}function Me(l,M,T){for(let I=0;I<T.length;I++){let N=T[I](l);if(!(N==null||N==="")&&M[I].get(N)===l)return!0}return!1}function Vn(l,M,T={}){let I=T.skip||(()=>!1),N=T.ignoreAttr||(()=>!1),L=T.tiers&&T.tiers.length?T.tiers:Vt,g=null;function y(){return g||(g=je([l,...l.querySelectorAll("*")],L)),g}let b=null;function u(){return b||(b=je([M,...M.querySelectorAll("*")],L)),b}function h(_){return!_.parentElement||!_.parentElement.parentElement}function S(_,J,H){return h(_)||Me(_,y(),L)?(H.push({type:"subtree",el:_,base:J}),!1):!0}function f(_,J){let H=[];for(let B of _.attributes)N(_,B.name)||J.getAttribute(B.name)!==B.value&&H.push(B.name);for(let B of J.attributes)N(_,B.name)||_.hasAttribute(B.name)||H.push(B.name);return H}function v(_){let J=[],H=null,B=()=>{H!==null&&(J.push({nodeType:3,nodeValue:H}),H=null)};for(let X of _.childNodes){if(X.nodeType===3){H=(H===null?"":H)+X.nodeValue;continue}X.nodeType===1&&I(X)||(B(),(X.nodeType===1||X.nodeType===8)&&J.push(X))}return B(),J}function O(_,J){if(_.nodeType!==J.nodeType)return!1;if(_.nodeType!==1)return!0;if(_.tagName!==J.tagName)return!1;for(let H of L){let B=H(_),X=H(J);if(B!=null&&B!==""&&X!=null&&X!==""&&B!==X)return!1}return!0}function j(_){let J="";for(let H of _)H.nodeType===3&&H.nodeValue.trim()!==""?J+="\0"+H.nodeValue:H.nodeType===8&&(J+=""+H.nodeValue);return J}function U(_,J,H){let B=v(_),X=v(J);if(B.length===X.length){let q=!0;for(let ee=0;ee<B.length;ee++)if(!O(B[ee],X[ee])){q=!1;break}if(q){for(let ee=0;ee<B.length;ee++){let ve=B[ee];if(ve.nodeType===1){if(C(ve,X[ee],H))return!0}else if(ve.nodeValue!==X[ee].nodeValue)return!0}return!1}}let ye=B.filter(q=>q.nodeType===1),be=X.filter(q=>q.nodeType===1);if(j(B)!==j(X))return!0;let Kt=je(ye,L),Jt=je(be,L),ct=[],at=new Set,Yt=[];for(let q of ye){let ee=Wt(q,Kt,Jt,L);ee&&!at.has(ee)?(ct.push([q,ee]),at.add(ee)):Yt.push(q)}let fe=[];for(let q of Yt)Me(q,Kt,L)?H.push({type:"subtree",el:q,base:null}):fe.push(q);let Pe=[];for(let q of be)at.has(q)||(Me(q,Jt,L)?H.push({type:"deletion",el:q}):Pe.push(q));if(fe.length!==Pe.length)return!0;for(let q=0;q<fe.length;q++)if(!O(fe[q],Pe[q]))return!0;let Gt=new Map(ct);for(let q=0;q<fe.length;q++)Gt.set(fe[q],Pe[q]);let Xt=-1;for(let q of ye){let ee=Gt.get(q);if(!ee)continue;let ve=be.indexOf(ee);if(ve<Xt)return!0;Xt=ve}for(let q=0;q<fe.length;q++)if(C(fe[q],Pe[q],H))return!0;for(let[q,ee]of ct)if(C(q,ee,H))return!0;return!1}function C(_,J,H){if(_.tagName!==J.tagName)return S(_,J,H);let B=f(_,J),X=[];if(U(_,J,X))return S(_,J,H);if(B.length){if(!h(_)&&!Me(J,u(),L))return!0;H.push({type:"attrs",el:_,names:B,base:J})}return H.push(...X),!1}let D=[],V=f(l,M);V.length&&D.push({type:"attrs",el:l,names:V});let F=(_,J)=>Array.from(_.children).find(H=>H.tagName===J)||null,Z=F(l,"HEAD"),ne=F(M,"HEAD");if(Z&&ne){let _=[];C(Z,ne,_),_.length&&D.push({type:"head",el:Z})}else(Z||ne)&&Z&&D.push({type:"head",el:Z});let re=F(l,"BODY"),Y=F(M,"BODY");return re&&Y?C(re,Y,D):re&&D.push({type:"subtree",el:re,base:null}),{entries:D}}function Wn(l,M,T={}){let I=T.tiers&&T.tiers.length?T.tiers:Vt,N=l.documentElement,L=[],g=0,y=C=>({ok:!1,placed:L,held:C,skippedAttrs:g});if(!N)return y(null);function b(C){let D=[C,...C.querySelectorAll("*")];return je(D,I)}let u=b(N),h=new Map,S=C=>{let D=C.getRootNode(),V=h.get(D);if(!V){let F=D.nodeType===9?D.documentElement:D;V=b(F),h.set(D,V)}return V};function f(C){if(!C.parentElement&&C.tagName==="HTML")return N;if(C.parentElement&&!C.parentElement.parentElement&&C.parentElement.tagName==="HTML"){if(C.tagName==="BODY")return l.body||null;if(C.tagName==="HEAD")return l.head||null}return null}function v(C){let D=f(C);return D||Wt(C,S(C),u,I)}function O(C){if(!C)return null;let D=v(C);return D&&D.isConnected?D:null}function j(C){for(let D=0;D<I.length;D++){let V=I[D](C);V!=null&&V!==""&&u[D].set(V,C)}}for(let C of M){if(C.type!=="deletion")continue;let D=v(C.el);D&&D!==N&&D.remove()}let U=M.filter(C=>C.type!=="deletion").sort((C,D)=>C.el===D.el?0:C.el.compareDocumentPosition(D.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let C of U){if(C.type==="head"){let Y=l.importNode(C.el,!0);l.head?l.head.replaceWith(Y):N.insertBefore(Y,N.firstChild),L.push({entry:C,imported:Y});continue}if(C.type==="attrs"){let Y=O(C.el)||O(C.base);if(!Y){g++;continue}for(let _ of C.names)C.el.hasAttribute(_)?Y.setAttribute(_,C.el.getAttribute(_)):Y.removeAttribute(_);continue}let D=C.el;if(f(D))return y(C);let V=O(D)||O(C.base);if(V){let Y=l.importNode(D,!0);V.replaceWith(Y),j(Y),L.push({entry:C,imported:Y});continue}if(C.base!=null&&!Me(C.base,S(C.base),I)||!Me(D,S(D),I))return y(C);let F=D.parentElement;if(!F)return y(C);let Z=O(F);if(!Z)return y(C);let ne=null;for(let Y=D.previousElementSibling;Y;Y=Y.previousElementSibling){let _=O(Y);if(_&&_.parentNode===Z){ne=_;break}}let re=l.importNode(D,!0);if(ne)Z.insertBefore(re,ne.nextSibling);else{let Y=Array.prototype.indexOf.call(F.children,D);Z.insertBefore(re,Z.children[Y]||null)}j(re),L.push({entry:C,imported:re})}return{ok:!0,placed:L,held:null,skippedAttrs:g}}return{morph:x,defaults:p,findChangedRoots:Vn,spliceProtected:Wn,mergeJson:yt,mergeScriptText:bt,parseJsonRelaxed:tt,parseRulesRelaxed:un}}();var ko=$e.morph,Co=$e.defaults,Ro=$e.findChangedRoots,Io=$e.spliceProtected;var mn=$e;function At(e,t,{onWidgetRemoved:n}={}){mn.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Qe.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var Pr="hha:upgrade-check:";function le(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function St(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function gn(e,t){let n=St(e),o=St(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let s=0;s<r;s++){let c=n[s]||0,i=o[s]||0;if(c!==i)return c>i}return!1}function Dr(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Hr(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Et({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||(d=>fetch(d)),r=r??Date.now(),!t)return null;let c=le(t,"hyper-source");if(!c)return null;let i=le(t,"hyper-version"),a;try{a=new URL(c,n?n.href:void 0)}catch{return null}if(n&&a.origin===n.origin&&a.pathname===n.pathname)return null;let m=`${Pr}${a.href}:${i||"none"}`,A,w=e?null:Dr(m);if(w&&typeof w.checkedAt=="number"&&r-w.checkedAt<s)A=w.sourceVersion;else{try{let d=await o(a.href);if(!d.ok)throw new Error(`HTTP ${d.status}`);let E=await d.text(),p=new DOMParser().parseFromString(E,"text/html");A=le(p,"hyper-version")}catch{A=null}Hr(m,{checkedAt:r,sourceVersion:A})}return A?{available:gn(A,i||"0.0.0"),currentVersion:i,sourceVersion:A,sourceUrl:a.href}:null}var rt=["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"],wt=new Set(rt),yn=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Tt=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var ot={};ut(ot,{EmptyListInsert:()=>Be,MAX_RULE_DEPTH:()=>Re,MaxRuleDepthExceeded:()=>Se,RuleTargetReadOnly:()=>Ue,RulesParseError:()=>Ce,ShapeMismatch:()=>_e,UnknownRulesVersion:()=>Ae});var Ce=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}},Re=20,Se=class extends Error{constructor(t){super(`rule depth exceeded ${Re} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},_e=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Be=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}},Ue=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function ue(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return xt(e,t,n,{depth:0,path:[]},o)}function xt(e,t,n,o,r){if(o.depth>Re)throw new Se(o.path);if(typeof n=="string")return $r(e,t,n,o,r);if(Array.isArray(n)){let[s,c]=n,i=e.find(t,s,r);return An(r,o,i),i.map((a,m)=>xt(e,a,c,{depth:o.depth+1,path:[...o.path,m]},r))}if(typeof n=="object"&&n!==null){let s={};for(let[c,i]of Object.entries(n))s[c]=xt(e,t,i,{depth:o.depth+1,path:[...o.path,c]},r);return s}return null}function $r(e,t,n,o,r){if(n.endsWith("[]")){let i=n.slice(0,-2),a=e.find(t,i,r);return An(r,o,a),a.map(m=>e.text(m))}if(n.startsWith("@"))return bn(e,t,n.slice(1));let s=pe(n);if(s!==-1){let i=n.slice(0,s),a=n.slice(s+1),m=i?e.find(t,i,r):[t];return m.length===0?null:bn(e,m[0],a)}if(n===".")return e.text(t);let c=e.find(t,n,r);return c.length===0?null:e.text(c[0])}function An(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function bn(e,t,n){if(wt.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}var Sn=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),_r=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Wo=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function Mt(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Br(e,t){if(Mt(e,t))return!0;for(let[n,o]of Object.entries(_r))if(o.includes(t)&&Mt(e,n))return!0;return!1}function Fe(e){let t=Sn[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Ur(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=Sn[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Br(n,r))||o.bundles.some(r=>Mt(n,r)))return n;n=n.parentElement}return null}function En(e,t){return!!Ur(e,t)}var Fr=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function wn(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();if("value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&(t.value=e.value),"checked"in e&&"checked"in t&&(t.checked=e.checked),"selected"in e&&"selected"in t&&(t.selected=e.selected),e.tagName==="SELECT")for(let o=0;o<e.options.length;o++)t.options[o].selected=e.options[o].selected;"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Tn(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function xn(e,t,n,o,r,s,c,i){if(e.nodeType===1&&((c?En(e,n):Tn(e,o,s,!1))||r&&Tn(e,r,s,c)))return null;let a=t.importNode(e,!1);i.cloneToLive.set(a,e),i.liveToClone.set(e,a);let m=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,A=a.nodeType===1&&a.tagName==="TEMPLATE"?a.content:a;m!==e&&(i.cloneToLive.set(A,m),i.liveToClone.set(m,A));for(let w of m.childNodes||[]){let d=xn(w,t,n,o,r,s,c,i);d&&(A.appendChild(d),w.nodeType===1&&wn(w,d))}return e.nodeType===1&&wn(e,a),a}function qe(e,{capability:t="data",exclude:n=null,inherit:o=!0}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let r=e.nodeType===9?e:e.ownerDocument;if(!r?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=r.implementation.createHTMLDocument(""),c=new WeakMap,i=new WeakMap,a=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let m=Fe(t),A=xn(a,s,t,m,n,a,o,{cloneToLive:c,liveToClone:i});e.nodeType===9&&A&&(s.replaceChild(A,s.documentElement),i.set(e,s),c.set(s,e));let w=d=>{if(Fr.test(d))throw new Error(`Filtered content queries do not support stateful selector: ${d}`)};return{root:A,document:s,capability:t,selector:Fe(t),cloneToLive:c,liveToClone:i,original(d){return c.get(d)||null},cloneOf(d){return i.get(d)||null},query(d,E=A){return w(d),Array.from(E.querySelectorAll(d),p=>c.get(p)||p)},text(d=A){return(d===A?A:i.get(d))?.textContent||""},html(d=A){return(d===A?A:i.get(d))?.innerHTML??""},clone(d=A){let E=d===A?A:i.get(d);return E?s.importNode(E,!0):null}}}function Mn(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function qr(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var te={semanticExclude:!0,find(e,t,n={}){let o=qr(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(i=>!Mn(i)));let s=[];n.skip&&s.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&s.push("["+c+"]"),s.length){let i=s.join(", ");r=r.filter(a=>!a.closest||!a.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}};function Ee(e,t={}){if(t.exclude===null)return te;let n=[Fe("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return te;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,i=null,a=()=>i||(i=qe(s,{capability:"data",exclude:t.exclude||null})),m=p=>{let R=a();return p===e?R.cloneOf(e):R.cloneOf(p)||p},A=p=>i?.original(p)||p,w=(p,R)=>{a().liveToClone.set(p,R),a().cloneToLive.set(R,p);let x=p.childNodes||[],k=R.childNodes||[];for(let P=0;P<Math.min(x.length,k.length);P++)w(x[P],k[P])},d=(p,R,x,k)=>{let P=Array.from(p.childNodes).filter(z=>i.cloneOf(z)),K=P[0];for(;K&&P.includes(K);)K=K.nextSibling;for(let z of P)z.remove();if(x==="innerHTML"){let z=c.createElement("template");z.innerHTML=k;for(let oe of Array.from(z.content.childNodes))p.insertBefore(oe,K||null)}else p.insertBefore(c.createTextNode(k),K||null);let $=qe(p,{capability:"data",exclude:t.exclude||null});R.replaceChildren(...Array.from($.root?.childNodes||[]));let G=z=>{let oe=$.original(z);oe&&(i.liveToClone.set(oe,z),i.cloneToLive.set(z,oe));for(let ae of Array.from(z.childNodes||[]))G(ae)};for(let z of Array.from(R.childNodes))G(z)},E={...te,find(p,R,x={}){let k=m(p);if(!k?.querySelectorAll)return[];let P=a().query(R,k);x.includeRulesTag||(P=P.filter($=>!Mn($)));let W=[];x.skip&&W.push(x.skip);let K=x.templateAttr===null?null:x.templateAttr||"cms-template";if(K&&W.push(`[${K}]`),W.length){let $=W.join(", ");P=P.filter(G=>!G.closest?.($))}return P},parent(p){let R=m(p)?.parentElement;return R?A(R):null},children(p){return Array.from(m(p)?.children||[],A)},text(p,R){if(R===void 0){let P=A(p);return!P?.matches?.(n)&&!P?.querySelector?.(n)?te.text(P):(m(p)?.textContent||"").trim()}let x=A(p);if(!x?.matches?.(n)&&!x?.querySelector?.(n)&&!i){te.text(x,R);return}let k=a().cloneOf(x);k?d(x,k,"textContent",R):te.text(x,R)},attr(p,R,x){let k=A(p);if(x===void 0)return te.attr(k,R);te.attr(k,R,x);let P=i?.cloneOf(k);P&&(te.attr(P,R,x),qe(k,{capability:"data",exclude:t.exclude||null}).root===null&&(P.remove(),i.liveToClone.delete(k),i.cloneToLive.delete(P)))},removeAttr(p,R){let x=A(p);te.removeAttr(x,R);let k=i?.cloneOf(x);k&&te.removeAttr(k,R)},prop(p,R,x){let k=A(p);if(x===void 0)return R==="innerHTML"||R==="outerHTML"||R==="textContent"||R==="innerText"?te.prop(m(k),R):te.prop(k,R);let P=R==="innerHTML"||R==="textContent"||R==="innerText",W=P?a().cloneOf(k):i?.cloneOf(k);W&&P?d(k,W,R,x):(te.prop(k,R,x),W&&te.prop(W,R,x))},clone(p){let R=m(p);return R===p?te.clone(p):c.importNode(R,!0)},insertAt(p,R,x){let k=A(p),W=E.children(k)[x]||(()=>{for(let G=k.children.length-1;G>=0;G--){let z=k.children[G];if(a().cloneOf(z))return z.nextElementSibling}return k.firstElementChild})(),K=A(R);k.insertBefore(K,W||null);let $=a().cloneOf(k);if($){let G=a().cloneOf(K);G||(G=c.importNode(K,!0),w(K,G));let z=Array.from($.children);$.insertBefore(G,z[x]||null)}},remove(p){let R=A(p),x=a().cloneOf(R);te.remove(R),x&&te.remove(x)},replaceWith(p,R){let x=A(p),k=a().cloneOf(x),P=te.replaceWith(x,R);if(k){let W=qe(P,{capability:"data",exclude:t.exclude||null});if(!W.root)k.remove();else{k.replaceWith(W.root);let K=$=>{let G=W.original($);G&&(i.liveToClone.set(G,$),i.cloneToLive.set($,G));for(let z of Array.from($.childNodes||[]))K(z)};K(W.root)}}return P}};return E}var ce=te;function vt(e){try{return JSON.parse(e)}catch(t){throw new Ce(`Invalid strict JSON: ${t.message}`,t)}}function we(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let s=[],c=0;for(;c<r.length;){let i=r[c];if(/\s/.test(i)){c++;continue}if("{}".includes(i)){s.push({type:i,value:i}),c++;continue}if(i==="["){let w=!1,d=c+1;for(;d<r.length&&/\s/.test(r[d]);)d++;if(d<r.length&&/[a-zA-Z_]/.test(r[d])&&(w=!0),!w){s.push({type:i,value:i}),c++;continue}}if(i==="]"){s.push({type:i,value:i}),c++;continue}if(i===":"){s.push({type:t.COLON,value:i}),c++;continue}if(i===","){s.push({type:t.COMMA,value:i}),c++;continue}if(i==='"'||i==="'"){let w=i,d=c+1;for(;d<r.length&&r[d]!==w;)r[d]==="\\"&&d++,d++;s.push({type:t.STRING,value:r.substring(c+1,d),quoted:!0,sourceQuote:w}),c=d+1;continue}let a=c,m;for(;a<r.length&&!/[{},]/.test(r[a]);)if(r[a]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let E of w){let p=E.substring(1);if(r.substring(a+1,a+1+p.length)===p){d=!0,a+=p.length;break}}if(!d)break}else if(r[a]==="["){for(a++;a<r.length&&r[a]!=="]";){if(r[a]==='"'||r[a]==="'"){let w=r[a];for(a++;a<r.length&&r[a]!==w;)r[a]==="\\"&&a++,a++}a++}a<r.length&&r[a]==="]"&&a++}else a++;m=r.substring(c,a);let A=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(m)?A=t.NUMBER:m==="true"||m==="false"||m==="null"?A=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(m)&&(A=t.SELECTOR),s.push({type:A,value:m,quoted:!1}),c=a}return s}function o(r){let s="";for(let c=0;c<r.length;c++){let i=r[c];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 a=r[c+1];if(a&&(a.type==="}"||a.type==="]"))continue;s+=i.value;continue}if(i.type===t.STRING&&i.quoted){let a=i.value;i.sourceQuote==="'"&&(a=a.replace(/\\'/g,"'"),a=a.replace(/(\\*)"/g,(m,A)=>A.length%2===0?A+'\\"':m)),s+=`"${a}"`;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 Ce("Invalid extraction rules syntax: "+r.message,r)}}var Ot="1",vn=/^[a-zA-Z0-9_-]+$/;function Ie(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!vn.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${vn})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=r[0],c=e.attr(s,"data-rules-version");if(c!==Ot)throw new Ae(c);return{rules:we(e.text(s)),tagNode:s}}var zr="script[data-rules-name]";function On(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function ze(e,t){let n=e.find(t,zr,{includeRulesTag:!0}),o=new Set,r=[];for(let s of n){let c=On(e.attr(s,"data-rules-name"));if(!c)continue;if(o.has(c)){console.warn(`hyper-html-api: duplicate rules tag name "${c}"; using the first.`);continue}let i=e.attr(s,"data-rules-version");if(i!==Ot)throw new Ae(i);o.add(c),r.push({name:c,rules:we(e.text(s))})}return r}function it(e,t){let n={};for(let{name:o,rules:r}of ze(e,t))n[o]=ue(e,t,r);return n}function Nt(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:it(ce,t),version:le(n,"hyper-version")}}var Le=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}},me=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},We=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 Nn="text/hyper-upgrade";function kt(e,t){let n=e.find(t,`script[type="${Nn}"]`);if(n.length===0)return null;if(n.length>1)throw new We(n.length);return e.text(n[0])||null}var Vr=new Function("url","return import(url)");async function Ct(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Vr(n)}catch(r){throw new me(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new me("transform must `export default` a function");return o.default}function Rn(e,t,n,o){let r=e.length,s=t.length,c=new Array(r).fill(-1);if(o){let x=new Set;for(let k=0;k<r;k++){let P=o[k];!(P>=0&&P<s)||x.has(P)||(c[k]=P,x.add(P))}}if(r===0||s===0)return c;let i=e.map(x=>kn(x,n)),a=t.map(x=>kn(x,n)),m=new Array(s).fill(!1);for(let x of c)x>=0&&(m[x]=!0);let A=new Map;a.forEach((x,k)=>{m[k]||A.set(x,A.has(x)?-1:k)});let w=new Map;i.forEach((x,k)=>{c[k]>=0||w.set(x,(w.get(x)||0)+1)}),i.forEach((x,k)=>{if(c[k]>=0||w.get(x)!==1)return;let P=A.get(x);P===void 0||P===-1||m[P]||(c[k]=P,m[P]=!0)});let d=[];for(let x=0;x<r;x++)c[x]<0&&d.push(x);let E=[];for(let x=0;x<s;x++)m[x]||E.push(x);if(d.length===0||E.length===0)return c;let p=r*s+1,R=(x,k)=>Wr(e[x],t[k],n)*p+Math.abs(x-k);for(let[x,k]of Kr(d,E,R))c[x]=k;return c}var In=e=>typeof e=="object"&&e!==null;function kn(e,t){if(!In(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function Wr(e,t,n){if(!In(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let s of o){let c=JSON.stringify(e?.[s]),i=JSON.stringify(t?.[s]);c!==i&&r++}return r}function Kr(e,t,n){return e.length<=t.length?Cn(e,t,n,!1):Cn(t,e,(o,r)=>n(r,o),!0)}function Cn(e,t,n,o){let r=e.length,s=t.length,c=[];for(let w=0;w<=r;w++)c.push(new Float64Array(s+1).fill(1/0));let i=[];for(let w=0;w<=r;w++)i.push(new Uint8Array(s+1));for(let w=0;w<=s;w++)c[r][w]=0;for(let w=r-1;w>=0;w--)for(let d=s-1;d>=0;d--){let E=n(e[w],t[d])+c[w+1][d+1],p=c[w][d+1];E<=p?(c[w][d]=E,i[w][d]=1):c[w][d]=p}let a=[],m=0,A=0;for(;m<r&&A<s;)i[m][A]&&(a.push(o?[t[A],e[m]]:[e[m],t[A]]),m++),A++;return a}function It(e,t,n,o,r,s,c,i={}){let a=e.find(t,n,i);if(r.length===0){a.forEach($=>e.remove($)),Rt(i,"onRowsApplied",s.path,[]);return}let m=r.length>a.length,A=a[0]||null;if(m&&!A&&(A=Xr(e,t,n,i),!A))throw new Be(s.path);let w=a.map($=>Gr(e,$,o,i)),d=null;if(m&&A){d=e.clone(A),i.templateAttr&&e.removeAttr(d,i.templateAttr);let $=e.stripIds(d);$>0&&console.warn(`[hyper-html-api] stripped ${$} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let E=Rn(r,w,o,Jr(e,a,r,s,i)),p=a[0]||A,R=e.parent(p),x=a.length>0?Ln(e,R,p):0,k=Zr(e,a),P=new Set,W=[],K=r.map(($,G)=>{let z=E[G];if(z>=0)return P.add(z),W.push(!1),a[z];W.push(!0);let oe=e.clone(d);return e.stripIds(oe),oe});a.forEach(($,G)=>{P.has(G)||e.remove($)}),k?K.forEach(($,G)=>{let z=x+G;e.children(R).findIndex(xe=>e.sameNode(xe,$))!==z&&e.insertAt(R,$,z)}):Qr(e,K,W,R,x),Yr(e,K,o,r,s,c,i),Rt(i,"onRowsApplied",s.path,K)}function Rt(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function Jr(e,t,n,o,r){let s=Rt(r,"identifyRows",o.path,n);if(!Array.isArray(s))return null;let c=new Array(n.length).fill(-1),i=new Set;for(let a=0;a<n.length;a++)if(s[a]){for(let m=0;m<t.length;m++)if(!(i.has(m)||!e.sameNode(t[m],s[a]))){c[a]=m,i.add(m);break}}return c}function Yr(e,t,n,o,r,s,c){t.forEach((i,a)=>{if(n===null){let m=o[a],A=m==null?"":String(m);e.text(i)!==A&&e.text(i,A)}else{let m=s(e,i,n,o[a],{depth:r.depth+1,path:[...r.path,a]},c);m&&m!==i&&(t[a]=m)}})}function Gr(e,t,n,o){return n===null?e.text(t):ue(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Ln(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 Xr(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let s=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of s)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}function Zr(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let s of t){let c=o.findIndex(i=>e.sameNode(i,s));if(c===-1)return!1;r.push(c)}return r.sort((s,c)=>s-c),r[r.length-1]-r[0]===r.length-1}function Qr(e,t,n,o,r){let s=null,c=r;for(let i=0;i<t.length;i++){if(!n[i]){s=t[i];continue}let a=s?e.parent(s):o;if(!a)continue;let m=s?Ln(e,a,s)+1:c++;e.insertAt(a,t[i],m),s=t[i]}}var jn=new Set(["checked","selected","disabled","readOnly","paused"]);function ge(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(Lt(n,o,[],s),s.length)throw new _e(s);st(e,t,n,o,{depth:0,path:[]},r)}function st(e,t,n,o,r,s={}){if(r.depth>Re)throw new Se(r.path);if(o===void 0)return t;if(typeof n=="string")return eo(e,t,n,o,r,s);if(Array.isArray(n)){let[c,i]=n;return It(e,t,c,i,o,r,st,s),t}if(typeof n=="object"&&n!==null){for(let[c,i]of Object.entries(n)){let a=st(e,t,i,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},s);a&&a!==t&&(t=a)}return t}return t}function eo(e,t,n,o,r,s){if(n.endsWith("[]")){let a=n.slice(0,-2);return It(e,t,a,null,o,r,st,s),t}if(n.startsWith("@"))return Dn(e,t,n.slice(1),o);let c=pe(n);if(c!==-1){let a=n.slice(0,c),m=n.slice(c+1),A=a?e.find(t,a,s):[t];return A.length===0||Dn(e,A[0],m,o),t}if(n===".")return Pn(e,t,o),t;let i=e.find(t,n,s);return i.length===0||Pn(e,i[0],o),t}function Pn(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Dn(e,t,n,o){if(Tt.has(n))throw new Ue(n);if(n==="outerHTML"){let s=o==null?"":String(o);return e.replaceWith(t,s)}if(yn.has(n)){let s=to(n,o);return e.prop(t,n)!==s&&e.prop(t,n,s),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function to(e,t){return t==null?jn.has(e)?!1:"":jn.has(e)?t==="false"?!1:!!t:t}function Lt(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:Je([...n,s]),expected:"scalar",got:Ke(r)})}):o.push({path:Je(n),expected:"array",got:Ke(t)});return}t!==null&&typeof t=="object"&&o.push({path:Je(n),expected:"scalar",got:Ke(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Je(n),expected:"array",got:Ke(t)});return}let r=e[1];t.forEach((s,c)=>Lt(r,s,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Je(n),expected:"object",got:Ke(t)});return}for(let[r,s]of Object.entries(e))Lt(s,t[r],[...n,r],o)}}}function Ke(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Je(e){return e.join(".")}function Ye(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=jt(t,e,n);return Pt(t,e,n),{data:o,summary:n}}function jt(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=>jt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,s]of Object.entries(e)){let c=jt(s,t?.[r],n);c!==void 0&&(o[r]=c)}return o}}function Pt(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)?Pt(e[r],t[r],n):n.discarded+=Te(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Pt(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=Te(t))}}function Te(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Te(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Te(n),0):1}function Dt(e,t,n){let o=ze(e,t),r={carriedOver:0,discarded:0,listItems:0},s={},c=new Set;for(let{name:i,rules:a}of o){if(c.add(i),!Object.prototype.hasOwnProperty.call(n,i)){s[i]={carriedOver:0,discarded:0,listItems:0};continue}let{data:m,summary:A}=Ye(n[i],a);ge(e,t,a,m),s[i]=A,r.carriedOver+=A.carriedOver,r.discarded+=A.discarded,r.listItems+=A.listItems}for(let i of Object.keys(n))c.has(i)||(r.discarded+=Te(n[i]));return{totals:r,byName:s,rulesTagCount:o.length}}async function Ht({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||(k=>fetch(k)),!o)throw new Error("upgrade.run requires a document context");if(e=e||le(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let c=new URL(e,r?r.href:void 0);n=n!==void 0?n:le(o,"hyper-version"),t=t||it(ce,o);let i;try{i=await s(c.href)}catch(k){throw new Le(c.href,k)}if(!i.ok)throw new Le(c.href,new Error(`HTTP ${i.status}`));let a=await i.text(),m=new DOMParser().parseFromString(a,"text/html"),A=le(m,"hyper-version"),w=t,d=!1,E=kt(ce,m);if(E){let P=await(await Ct(E))(w,{fromVersion:n,toVersion:A});if(!P||typeof P!="object"||Array.isArray(P))throw new me("transform must return a plain object map of { rulesName: data }");w=P,d=!0}let{totals:p,byName:R,rulesTagCount:x}=Dt(ce,m,w);if(x===0&&Object.keys(w).length>0)throw new Ve(c.href);return{html:no(m),fromVersion:n,toVersion:A,summary:{transformApplied:d,totals:p,byName:R}}}function no(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
4
+ `+e.documentElement.outerHTML}function $t(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 Ie(e,o,n)}return null}var Ge={extract:(e,t,n={})=>ue(Ee(e,n),e,t,n),apply:(e,t,n,o={})=>ge(Ee(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>Ie(ce,e,t),findRules:(e,t)=>$t(ce,e,t),bind:(e,t,n={})=>{let o=$t(ce,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>ue(Ee(e,n),e,o.rules,n),set:r=>ge(Ee(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:vt,parseRelaxed:we,ruleAttrIndex:pe,splitRule:Ne,errors:ot,DOM_PROPERTIES:rt},_t=e=>!!e&&typeof e.nodeType=="number";function Hn(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=ce.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 Ie(ce,t).rules}function Bt(e,t){let n=_t(e)?e:document,o=_t(e)?t:e;return o===void 0?ue(Ee(n),n,Hn(n)):Ge.bind(n,o).get()}function Ut(e,t,n){if(!_t(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?ge(Ee(e),e,Hn(e),t):Ge.bind(e,n).set(t),e}var $n={buildForm:dt,bindFormEvents:pt,scaffold:Oe,morphForm:At,path:Ze},_n={checkForUpdate:Et,run:Ht,extractAll:Nt,shapeMatch:Ye};var io={engine:Ge,cms:$n,upgrade:_n,extractData:Bt,applyData:Ut},so=io;return Xn(co);})();