hyper-html-api 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var hyperHtmlApiData=(()=>{var k=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ue=Object.prototype.hasOwnProperty;var Y=(e,t)=>{for(var n in t)k(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fe(t))!ue.call(e,r)&&r!==n&&k(e,r,{get:()=>t[r],enumerable:!(o=ce(t,r))||o.enumerable});return e};var he=e=>ae(k({},"__esModule",{value:!0}),e);var Me={};Y(Me,{applyData:()=>z,default:()=>we,engine:()=>P,extractData:()=>X});var C=["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"],B=new Set(C),Q=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Z=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var j={};Y(j,{EmptyListInsert:()=>I,MAX_RULE_DEPTH:()=>A,MaxRuleDepthExceeded:()=>E,RuleTargetReadOnly:()=>w,RulesParseError:()=>S,ShapeMismatch:()=>b,UnknownRulesVersion:()=>N,UpgradeAlreadyRegistered:()=>U});var S=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},N=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},A=20,E=class extends Error{constructor(t){super(`rule depth exceeded ${A} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},b=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},I=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}},w=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},U=class extends Error{constructor(){super("upgrade transform already registered; only one registration is allowed per page."),this.name="UpgradeAlreadyRegistered"}};function g(e,t,n,o={}){return q(e,t,n,{depth:0,path:[]},o)}function q(e,t,n,o,r){if(o.depth>A)throw new E(o.path);if(typeof n=="string")return de(e,t,n,r);if(Array.isArray(n)){let[i,c]=n;return e.find(t,i,r).map((l,a)=>q(e,l,c,{depth:o.depth+1,path:[...o.path,a]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,s]of Object.entries(n))i[c]=q(e,t,s,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function de(e,t,n,o){if(n.endsWith("[]")){let i=n.slice(0,-2);return e.find(t,i,o).map(c=>e.text(c))}if(n.startsWith("@"))return ee(e,t,n.slice(1));if(n.includes("@")){let i=n.lastIndexOf("@"),c=n.slice(0,i),s=n.slice(i+1),l=c?e.find(t,c,o):[t];return l.length===0?null:ee(e,l[0],s)}if(n===".")return e.text(t);let r=e.find(t,n,o);return r.length===0?null:e.text(r[0])}function ee(e,t,n){if(B.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}var pe=.5;function v(e,t,n,o,r,i,c,s={}){let l=e.find(t,n,s);if(r.length===0){l.forEach(h=>e.remove(h));return}let a=r.length>l.length,u=l[0]||null;if(a&&!u&&(u=Re(e,t,n,s),!u))throw new I(i.path);let d=l.map(h=>me(e,h,o,s)),f=null;if(u){f=e.clone(u),s.templateAttr&&e.removeAttr(f,s.templateAttr);let h=e.stripIds(f);h>0&&console.warn(`[hyper-html-api] stripped ${h} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let H=ye(r,d,o),R=l[0]||u,L=e.parent(R),se=l.length>0?Ee(e,L,R):0,K=new Set,W=r.map((h,m)=>{let p=H[m];if(p>=0)return K.add(p),l[p];let O=e.clone(f);return e.stripIds(O),O});l.forEach((h,m)=>{K.has(m)||e.remove(h)}),W.forEach((h,m)=>{let p=se+m;e.children(L).findIndex(le=>e.sameNode(le,h))!==p&&e.insertAt(L,h,p)}),W.forEach((h,m)=>{if(o===null){let p=r[m],O=p==null?"":String(p);e.text(h)!==O&&e.text(h,O)}else{let p=c(e,h,o,r[m],{depth:i.depth+1,path:[...i.path,m]},s);p&&p!==h&&(W[m]=p)}})}function me(e,t,n,o){return n===null?e.text(t):g(e,t,n,o)}function ye(e,t,n){let o=new Array(e.length).fill(-1),r=new Set;return e.forEach((i,c)=>{let s=-1,l=-1;t.forEach((a,u)=>{if(r.has(u))return;let d=ge(i,a,n),f=d===l&&s>=0?Math.abs(u-c)<Math.abs(s-c):!1;(d>l||f)&&(l=d,s=u)}),l>=pe&&(o[c]=s,r.add(s))}),o}function ge(e,t,n){if(n===null)return e===t?1:0;let o=Object.keys(n||{});if(o.length===0)return 0;let r=0;for(let i of o)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&r++;return r/o.length}function Ee(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 Re(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1});for(let c of i)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}var te=new Set(["checked","selected","disabled","readOnly","paused"]);function T(e,t,n,o,r={}){let i=[];if(J(n,o,[],i),i.length)throw new b(i);$(e,t,n,o,{depth:0,path:[]},r)}function $(e,t,n,o,r,i={}){if(r.depth>A)throw new E(r.path);if(o===void 0)return t;if(typeof n=="string")return Oe(e,t,n,o,r,i);if(Array.isArray(n)){let[c,s]=n;return v(e,t,c,s,o,r,$,i),t}if(typeof n=="object"&&n!==null){for(let[c,s]of Object.entries(n)){let l=$(e,t,s,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);l&&l!==t&&(t=l)}return t}return t}function Oe(e,t,n,o,r,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return v(e,t,s,null,o,r,$,i),t}if(n.startsWith("@"))return ne(e,t,n.slice(1),o);if(n.includes("@")){let s=n.lastIndexOf("@"),l=n.slice(0,s),a=n.slice(s+1),u=l?e.find(t,l,i):[t];return u.length===0||ne(e,u[0],a,o),t}if(n===".")return e.text(t,o==null?"":String(o)),t;let c=e.find(t,n,i);return c.length===0||e.text(c[0],o==null?"":String(o)),t}function ne(e,t,n,o){if(Z.has(n))throw new w(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return Q.has(n)?(e.prop(t,n,Se(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function Se(e,t){return t==null?te.has(e)?!1:"":te.has(e)?!!t:t}function J(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:_([...n,i]),expected:"scalar",got:M(r)})}):o.push({path:_(n),expected:"array",got:M(t)});return}t!==null&&typeof t=="object"&&o.push({path:_(n),expected:"scalar",got:M(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:_(n),expected:"array",got:M(t)});return}let r=e[1];t.forEach((i,c)=>J(r,i,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:_(n),expected:"object",got:M(t)});return}for(let[r,i]of Object.entries(e))J(i,t[r],[...n,r],o)}}}function M(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function _(e){return e.join(".")}function V(e){try{return JSON.parse(e)}catch(t){throw new S(`Invalid strict JSON: ${t.message}`,t)}}function D(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 s=r[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let d=!1,f=c+1;for(;f<r.length&&/\s/.test(r[f]);)f++;if(f<r.length&&/[a-zA-Z_]/.test(r[f])&&(d=!0),!d){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:t.COLON,value:s}),c++;continue}if(s===","){i.push({type:t.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let d=s,f=c+1;for(;f<r.length&&r[f]!==d;)r[f]==="\\"&&f++,f++;i.push({type:t.STRING,value:r.substring(c+1,f),quoted:!0,sourceQuote:d}),c=f+1;continue}let l=c,a;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let d=[":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"],f=!1;for(let H of d){let R=H.substring(1);if(r.substring(l+1,l+1+R.length)===R){f=!0,l+=R.length;break}}if(!f)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let d=r[l];for(l++;l<r.length&&r[l]!==d;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;a=r.substring(c,l);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(a)?u=t.NUMBER:a==="true"||a==="false"||a==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(a)&&(u=t.SELECTOR),i.push({type:u,value:a,quoted:!1}),c=l}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let s=r[c];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 l=r[c+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(a,u)=>u.length%2===0?u+'\\"':a)),i+=`"${l}"`;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 S("Invalid extraction rules syntax: "+r.message,r)}}var Ae="1",re=/^[a-zA-Z0-9_-]+$/;function x(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!re.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${re})`);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!==Ae)throw new N(c);return{rules:D(e.text(i)),tagNode:i}}function F(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 x(e,o,n)}return null}function oe(e,t,n,o){let r=F(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:c}=r;return{rules:i,tagNode:c,get:()=>g(e,t,i,o),set:s=>T(e,t,i,s,o)}}function xe(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Ne(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var be={find(e,t,n={}){let o=Ne(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!xe(c)));let i=[];if(n.skip&&i.push(n.skip),n.templateAttr&&i.push("["+n.templateAttr+"]"),i.length){let c=i.join(", ");r=r.filter(s=>!s.closest||!s.closest(c))}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}},y=be;var P={extract:(e,t,n)=>g(y,e,t,n),apply:(e,t,n,o)=>T(y,e,t,n,o),findRulesIn:(e,t)=>x(y,e,t),findRules:(e,t)=>F(y,e,t),bind:(e,t,n)=>oe(y,e,t,n),parseStrict:V,parseRelaxed:D,errors:j,DOM_PROPERTIES:C},G=e=>!!e&&typeof e.nodeType=="number";function ie(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=y.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 x(y,t).rules}function X(e,t){let n=G(e)?e:document,o=G(e)?t:e;return o===void 0?g(y,n,ie(n)):P.bind(n,o).get()}function z(e,t,n){if(!G(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?T(y,e,ie(e),t):P.bind(e,n).set(t),e}var Ie={engine:P,extractData:X,applyData:z},we=Ie;return he(Me);})();
1
+ var hyperHtmlApiData=(()=>{var k=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ue=Object.prototype.hasOwnProperty;var Y=(e,t)=>{for(var n in t)k(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fe(t))!ue.call(e,r)&&r!==n&&k(e,r,{get:()=>t[r],enumerable:!(o=ce(t,r))||o.enumerable});return e};var he=e=>ae(k({},"__esModule",{value:!0}),e);var Me={};Y(Me,{applyData:()=>z,default:()=>we,engine:()=>P,extractData:()=>X});var C=["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"],B=new Set(C),Q=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Z=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var j={};Y(j,{EmptyListInsert:()=>I,MAX_RULE_DEPTH:()=>A,MaxRuleDepthExceeded:()=>E,RuleTargetReadOnly:()=>w,RulesParseError:()=>S,ShapeMismatch:()=>b,UnknownRulesVersion:()=>N,UpgradeAlreadyRegistered:()=>U});var S=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},N=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},A=20,E=class extends Error{constructor(t){super(`rule depth exceeded ${A} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},b=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},I=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}},w=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},U=class extends Error{constructor(){super("upgrade transform already registered; only one registration is allowed per page."),this.name="UpgradeAlreadyRegistered"}};function g(e,t,n,o={}){return q(e,t,n,{depth:0,path:[]},o)}function q(e,t,n,o,r){if(o.depth>A)throw new E(o.path);if(typeof n=="string")return de(e,t,n,r);if(Array.isArray(n)){let[i,c]=n;return e.find(t,i,r).map((l,a)=>q(e,l,c,{depth:o.depth+1,path:[...o.path,a]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,s]of Object.entries(n))i[c]=q(e,t,s,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function de(e,t,n,o){if(n.endsWith("[]")){let i=n.slice(0,-2);return e.find(t,i,o).map(c=>e.text(c))}if(n.startsWith("@"))return ee(e,t,n.slice(1));if(n.includes("@")){let i=n.lastIndexOf("@"),c=n.slice(0,i),s=n.slice(i+1),l=c?e.find(t,c,o):[t];return l.length===0?null:ee(e,l[0],s)}if(n===".")return e.text(t);let r=e.find(t,n,o);return r.length===0?null:e.text(r[0])}function ee(e,t,n){if(B.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}var pe=.5;function v(e,t,n,o,r,i,c,s={}){let l=e.find(t,n,s);if(r.length===0){l.forEach(h=>e.remove(h));return}let a=r.length>l.length,u=l[0]||null;if(a&&!u&&(u=Re(e,t,n,s),!u))throw new I(i.path);let d=l.map(h=>me(e,h,o,s)),f=null;if(u){f=e.clone(u),s.templateAttr&&e.removeAttr(f,s.templateAttr);let h=e.stripIds(f);h>0&&console.warn(`[hyper-html-api] stripped ${h} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let H=ye(r,d,o),R=l[0]||u,L=e.parent(R),se=l.length>0?Ee(e,L,R):0,K=new Set,W=r.map((h,m)=>{let p=H[m];if(p>=0)return K.add(p),l[p];let O=e.clone(f);return e.stripIds(O),O});l.forEach((h,m)=>{K.has(m)||e.remove(h)}),W.forEach((h,m)=>{let p=se+m;e.children(L).findIndex(le=>e.sameNode(le,h))!==p&&e.insertAt(L,h,p)}),W.forEach((h,m)=>{if(o===null){let p=r[m],O=p==null?"":String(p);e.text(h)!==O&&e.text(h,O)}else{let p=c(e,h,o,r[m],{depth:i.depth+1,path:[...i.path,m]},s);p&&p!==h&&(W[m]=p)}})}function me(e,t,n,o){return n===null?e.text(t):g(e,t,n,o)}function ye(e,t,n){let o=new Array(e.length).fill(-1),r=new Set;return e.forEach((i,c)=>{let s=-1,l=-1;t.forEach((a,u)=>{if(r.has(u))return;let d=ge(i,a,n),f=d===l&&s>=0?Math.abs(u-c)<Math.abs(s-c):!1;(d>l||f)&&(l=d,s=u)}),l>=pe&&(o[c]=s,r.add(s))}),o}function ge(e,t,n){if(n===null)return e===t?1:0;let o=Object.keys(n||{});if(o.length===0)return 0;let r=0;for(let i of o)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&r++;return r/o.length}function Ee(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 Re(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}var te=new Set(["checked","selected","disabled","readOnly","paused"]);function T(e,t,n,o,r={}){let i=[];if(J(n,o,[],i),i.length)throw new b(i);$(e,t,n,o,{depth:0,path:[]},r)}function $(e,t,n,o,r,i={}){if(r.depth>A)throw new E(r.path);if(o===void 0)return t;if(typeof n=="string")return Oe(e,t,n,o,r,i);if(Array.isArray(n)){let[c,s]=n;return v(e,t,c,s,o,r,$,i),t}if(typeof n=="object"&&n!==null){for(let[c,s]of Object.entries(n)){let l=$(e,t,s,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);l&&l!==t&&(t=l)}return t}return t}function Oe(e,t,n,o,r,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return v(e,t,s,null,o,r,$,i),t}if(n.startsWith("@"))return ne(e,t,n.slice(1),o);if(n.includes("@")){let s=n.lastIndexOf("@"),l=n.slice(0,s),a=n.slice(s+1),u=l?e.find(t,l,i):[t];return u.length===0||ne(e,u[0],a,o),t}if(n===".")return e.text(t,o==null?"":String(o)),t;let c=e.find(t,n,i);return c.length===0||e.text(c[0],o==null?"":String(o)),t}function ne(e,t,n,o){if(Z.has(n))throw new w(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return Q.has(n)?(e.prop(t,n,Se(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function Se(e,t){return t==null?te.has(e)?!1:"":te.has(e)?!!t:t}function J(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:_([...n,i]),expected:"scalar",got:M(r)})}):o.push({path:_(n),expected:"array",got:M(t)});return}t!==null&&typeof t=="object"&&o.push({path:_(n),expected:"scalar",got:M(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:_(n),expected:"array",got:M(t)});return}let r=e[1];t.forEach((i,c)=>J(r,i,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:_(n),expected:"object",got:M(t)});return}for(let[r,i]of Object.entries(e))J(i,t[r],[...n,r],o)}}}function M(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function _(e){return e.join(".")}function V(e){try{return JSON.parse(e)}catch(t){throw new S(`Invalid strict JSON: ${t.message}`,t)}}function D(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 s=r[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let d=!1,f=c+1;for(;f<r.length&&/\s/.test(r[f]);)f++;if(f<r.length&&/[a-zA-Z_]/.test(r[f])&&(d=!0),!d){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:t.COLON,value:s}),c++;continue}if(s===","){i.push({type:t.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let d=s,f=c+1;for(;f<r.length&&r[f]!==d;)r[f]==="\\"&&f++,f++;i.push({type:t.STRING,value:r.substring(c+1,f),quoted:!0,sourceQuote:d}),c=f+1;continue}let l=c,a;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let d=[":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"],f=!1;for(let H of d){let R=H.substring(1);if(r.substring(l+1,l+1+R.length)===R){f=!0,l+=R.length;break}}if(!f)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let d=r[l];for(l++;l<r.length&&r[l]!==d;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;a=r.substring(c,l);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(a)?u=t.NUMBER:a==="true"||a==="false"||a==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(a)&&(u=t.SELECTOR),i.push({type:u,value:a,quoted:!1}),c=l}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let s=r[c];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 l=r[c+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(a,u)=>u.length%2===0?u+'\\"':a)),i+=`"${l}"`;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 S("Invalid extraction rules syntax: "+r.message,r)}}var Ae="1",re=/^[a-zA-Z0-9_-]+$/;function x(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!re.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${re})`);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!==Ae)throw new N(c);return{rules:D(e.text(i)),tagNode:i}}function F(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 x(e,o,n)}return null}function oe(e,t,n,o){let r=F(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:c}=r;return{rules:i,tagNode:c,get:()=>g(e,t,i,o),set:s=>T(e,t,i,s,o)}}function xe(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Ne(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var be={find(e,t,n={}){let o=Ne(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!xe(s)));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 s=i.join(", ");r=r.filter(l=>!l.closest||!l.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}},y=be;var P={extract:(e,t,n)=>g(y,e,t,n),apply:(e,t,n,o)=>T(y,e,t,n,o),findRulesIn:(e,t)=>x(y,e,t),findRules:(e,t)=>F(y,e,t),bind:(e,t,n)=>oe(y,e,t,n),parseStrict:V,parseRelaxed:D,errors:j,DOM_PROPERTIES:C},G=e=>!!e&&typeof e.nodeType=="number";function ie(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=y.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 x(y,t).rules}function X(e,t){let n=G(e)?e:document,o=G(e)?t:e;return o===void 0?g(y,n,ie(n)):P.bind(n,o).get()}function z(e,t,n){if(!G(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?T(y,e,ie(e),t):P.bind(e,n).set(t),e}var Ie={engine:P,extractData:X,applyData:z},we=Ie;return he(Me);})();
@@ -1,3 +1,3 @@
1
1
  var HyperHtmlApi=(()=>{var Se=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var Mt=Object.prototype.hasOwnProperty;var xe=(e,t)=>{for(var n in t)Se(e,n,{get:t[n],enumerable:!0})},Et=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of At(t))!Mt.call(e,o)&&o!==n&&Se(e,o,{get:()=>t[o],enumerable:!(r=bt(t,o))||r.enumerable});return e};var St=e=>Et(Se({},"__esModule",{value:!0}),e);var Sn={};xe(Sn,{applyData:()=>ze,cms:()=>gt,default:()=>En,engine:()=>ae,extractData:()=>Ke,upgrade:()=>yt});var le={};xe(le,{fromString:()=>ue,getRuleAtPath:()=>ve,getValueAtPath:()=>Q,parseConfigKey:()=>vt,setAtPath:()=>F,toConfigKey:()=>xt,toString:()=>_});function _(e){return e.map(String).join(".")}function xt(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function vt(e){return e===""?[]:e.split(".")}function ue(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function ve(e,t){let n=e;for(let r of t){if(n==null||typeof n=="string")return;if(Array.isArray(n)){if(typeof r!="number"&&r!=="*")return;n=n[1];continue}if(typeof n=="object"){if(typeof r=="number"||!(r in n))return;n=n[r];continue}return}return n}function Q(e,t){let n=e;for(let r of t){if(n==null)return;n=n[r]}return n}function F(e,t,n){if(t.length===0)return n;let[r,...o]=t;if(typeof r=="number"){let i=Array.isArray(e)?[...e]:[];return i[r]=F(i[r],o,n),i}return{...e&&typeof e=="object"?e:{},[r]:F((e||{})[r],o,n)}}function z(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[n,r]of Object.entries(e))t[n]=z(r);return t}return""}var fe=new WeakMap;var wt=new Set(["checked","selected","disabled","readOnly","paused"]);function we({rules:e,data:t,appRoot:n,cmsRoot:r}){let o=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:r};return o.appendChild(Re({rule:e,value:t,path:[],ctx:i})),o}function Te(e,{rules:t,getData:n,onChange:r}){e.setAttribute("data-hha-form-root",""),Xe.set(e,{rules:t,getData:n,onChange:r}),Tt()}var Xe=new WeakMap,Ge=!1;function Tt(){Ge||(document.addEventListener("input",Qe,!0),document.addEventListener("change",Qe,!0),document.addEventListener("click",Rt,!0),Ge=!0)}function Ze(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&Xe.get(t)||null}function Rt(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=Ze(t);if(!n)return;let{rules:r,getData:o,onChange:i}=n,u=t.getAttribute("data-hha-action"),s=ue(t.getAttribute("data-hha-path")||"");if(u==="scalar-array-add"){let a=Q(o(),s)||[];i(F(o(),s,[...a,""]),{structural:!0});return}if(u==="object-array-add"){let a=ve(r,s);if(!Array.isArray(a))return;let M=Q(o(),s)||[];i(F(o(),s,[...M,z(a[1])]),{structural:!0});return}if(u==="array-remove"){if(s.length===0)return;let a=s.slice(0,-1),M=s[s.length-1],w=Q(o(),a)||[];if(typeof M!="number")return;let b=w.filter((h,R)=>R!==M);i(F(o(),a,b),{structural:!0})}}function Qe(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=Ze(t);if(!n)return;let{getData:r,onChange:o}=n,i=t.closest("[data-hha-path]");if(!i)return;let u=ue(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;o(F(r(),u,s),{structural:!1})}function Re({rule:e,value:t,path:n,ctx:r}){if(typeof e=="string")return e.endsWith("[]")?It({rule:e,value:t,path:n,ctx:r}):Ot({rule:e,value:t,path:n,ctx:r});if(Array.isArray(e))return kt({rule:e,value:t,path:n,ctx:r});if(typeof e=="object"&&e!==null)return Nt({rule:e,value:t,path:n,ctx:r});let o=document.createElement("span");return o.textContent="(unsupported rule)",o}function Nt({rule:e,value:t,path:n,ctx:r}){let o=document.createElement("div");if(o.className="form-section",o.setAttribute("data-hha-path",_(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=de(n[n.length-1]),o.appendChild(i)}for(let[i,u]of Object.entries(e)){let s=[...n,i],a=t?.[i];o.appendChild(Re({rule:u,value:a,path:s,ctx:r}))}return o}function Ot({rule:e,value:t,path:n,ctx:r}){let o=document.createElement("div");o.className="field-row",o.setAttribute("data-hha-path",_(n));let i=document.createElement("div");i.className="field-body";let u=document.createElement("label");u.className="field-label",u.textContent=de(n[n.length-1]||".")+Dt(e);let s=Ct(e,r.appRoot),a=Lt(s,{value:t,rule:e,path:n,appRoot:r.appRoot}),M=a.el;return M.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(u),i.appendChild(M),o.appendChild(i),fe.set(o,a),o}function It({rule:e,value:t,path:n,ctx:r}){let o=document.createElement("div");o.className="form-section",o.setAttribute("data-hha-path",_(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=de(n[n.length-1]),o.appendChild(i);let u=Array.isArray(t)?t:[],s=document.createElement("div");o.appendChild(s),u.forEach((M,w)=>{let b=[...n,w],h=document.createElement("div");h.className="scalar-array-row",h.setAttribute("data-hha-path",_(b));let R=document.createElement("input");R.type="text",R.className="field-input",R.value=M==null?"":String(M);let N=document.createElement("button");N.type="button",N.className="array-remove",N.textContent="\xD7",N.title="remove",N.setAttribute("data-hha-action","array-remove"),N.setAttribute("data-hha-path",_(b)),h.appendChild(R),h.appendChild(N),s.appendChild(h)});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",_(n)),o.appendChild(a),o}function kt({rule:e,value:t,path:n,ctx:r}){let[,o]=e,i=Array.isArray(t)?t:[],u=document.createElement("div");u.className="form-section",u.setAttribute("data-hha-path",_(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=de(n[n.length-1]),u.appendChild(s),i.forEach((M,w)=>{let b=[...n,w],h=document.createElement("div");h.className="array-card",h.setAttribute("data-hha-path",_(b));let R=document.createElement("button");R.type="button",R.className="array-remove",R.textContent="\xD7",R.title="remove item",R.setAttribute("data-hha-action","array-remove"),R.setAttribute("data-hha-path",_(b)),h.appendChild(R);let N=Re({rule:o,value:M,path:b,ctx:r});N.querySelector(".form-section-label")?.remove(),h.appendChild(N),u.appendChild(h)});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",_(n)),u.appendChild(a),u}function Lt(e,t){let n=Pt(e);if(e.type==="select"&&e.options)for(let r of e.options){let o=document.createElement("option");o.value=r.value,o.textContent=r.text,String(t.value)===r.value&&(o.selected=!0),n.appendChild(o)}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 Ct(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):e.includes("@")&&(n=e.split("@")[1]||null),n&&wt.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let r=Ht(e,t);if(!r)return{type:"text"};let o=(r.tagName||"").toLowerCase();if(o==="textarea")return{type:"textarea"};if(o==="select")return{type:"select",options:Array.from(r.querySelectorAll("option")).map(s=>({value:s.getAttribute("value")||s.textContent,text:s.textContent.trim()||s.getAttribute("value")||""}))};if(o==="input"){let u=(r.getAttribute("type")||"text").toLowerCase();if(u==="checkbox"||u==="radio")return{type:"checkbox"};if(u==="number")return{type:"number"}}let i=(r.textContent||"").trim();return i.length>60||i.includes(`
2
- `)?{type:"textarea"}:{type:"text"}}function Ht(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=e.includes("@")?e.split("@")[0]:e;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function Pt(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 de(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 Dt(e){return` \xB7 ${e}`}var et={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,slotMatch:30},minConfidence:101};function _t(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 jt(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 $t(e,t){let n=[];for(let r of e.attributes||[]){let o=r.name;o==="id"||o==="class"||t.excludeAttributePrefixes.some(i=>o.startsWith(i))||t.includeAttributes.includes(o)&&n.push(`${o}=${r.value}`)}return n.sort().join("|")}function Bt(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function Ft(e,t){let n=[e.tagName];return t.includeClasses&&n.push(jt(e)),n.push($t(e,t)),_t(n.join("|"))}function Ut(e){let t=e.tagName,n=1,r=e.previousElementSibling;for(;r;)r.tagName===t&&n++,r=r.previousElementSibling;return n}function Wt(e,t){return e.id||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function qt(e){if(e.id)return`#${e.id}`;let t=e.getAttribute?.("role");return t?`@${t}`:e.tagName}function Vt(e,t){let n=[],r=e;for(;r&&r.tagName&&n.length<t.maxPathDepth;){let o=`${r.tagName}:${Ut(r)}`;if(n.unshift(o),r!==e&&Wt(r,t)){n.unshift(qt(r));break}r=r.parentElement}return n}function Kt(e,t){let n=0,r=e.length-1,o=t.length-1;for(;r>=0&&o>=0&&e[r]===t[o];)n++,r--,o--;return n}function $(e,t,n){if(n.has(e))return n.get(e);let r={signature:Ft(e,t),path:Vt(e,t),textHint:Bt(e,t)};return n.set(e,r),r}function ot(e,t,n,r){if(r.has(e))return r.get(e);let o=new Map,i=e.querySelectorAll("*"),u=0;for(let s of i){let a=$(s,t,n);a.domIndex=u++,o.has(a.signature)||o.set(a.signature,[]),o.get(a.signature).push(s)}return r.set(e,o),o}function zt(e,t,n){n.delete(e),t.delete(e);let r=e.querySelectorAll("*");for(let o of r)t.delete(o)}function Ne(e,t,n,r,o){let i=$(e,n,r),u=$(t,n,r),s=n.weights,a={},M=0;if(i.signature!==u.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};M+=s.signature,a.signature=s.signature;let b=Kt(i.path,u.path)*s.pathSegment;M+=b,a.path=b;let h=!0;if(i.textHint&&u.textHint?i.textHint===u.textHint?(M+=s.textMatch,a.text=s.textMatch):(M-=s.textMismatch,a.text=-s.textMismatch,h=!1):i.textHint!==u.textHint&&(M-=s.textMismatch,a.text=-s.textMismatch,h=!1),o.candidateCount===1&&h&&(M+=s.uniqueCandidate,a.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof u.domIndex=="number"){let R=Math.abs(i.domIndex-u.domIndex),N=Math.min(R*s.positionPenalty,20);M-=N,a.drift=-N}return{score:M,breakdown:a}}function tt(e,t,n,r,o){if(n.excludeIds&&e.id)return null;let i=ot(t,n,r,o),u=$(e,n,r);if(typeof u.domIndex!="number"){let h=0,R=e.previousElementSibling;for(;R;)h++,R=R.previousElementSibling;u.domIndex=h}let s=i.get(u.signature)||[],a=n.excludeIds?s.filter(h=>!h.id):s;if(a.length===0)return null;let M=null,w=0,b=null;for(let h of a){let{score:R,breakdown:N}=Ne(e,h,n,r,{candidateCount:a.length});R>w&&(w=R,M=h,b=N)}return w<n.minConfidence?null:{element:M,confidence:w,breakdown:b}}function Jt(e,t,n,r){let o=[],i=n.weights.signature+n.weights.slotMatch,u={slot:i};function s(b){if(b.children)return b.children;let h=b.childNodes;if(!h)return[];let R=[];for(let N=0;N<h.length;N++)h[N].nodeType===1&&R.push(h[N]);return R}function a(b,h){let R=s(b),N=s(h);if(R.length===N.length)for(let k=0;k<R.length;k++){let m=R[k],O=N[k];if(n.excludeIds&&(m.id||O.id)||m.tagName!==O.tagName)continue;let x=$(m,n,r).signature,S=$(O,n,r).signature;x!==S&&o.push({newEl:m,oldEl:O,score:i,breakdown:u}),a(m,O)}}function M(b,h){for(;;){if(b.tagName===h.tagName)return[b,h];let R=s(b);if(!b.tagName&&R.length===1){b=R[0];continue}let N=s(h);if(N.length===1&&N[0].tagName===b.tagName){h=N[0];continue}return null}}let w=M(e,t);return w&&a(w[0],w[1]),o}function nt(e,t,n,r,o){let i=t.querySelectorAll("*"),u=ot(e,n,r,o),s=0;for(let b of i){let h=$(b,n,r);h.domIndex=s++}let a=[];for(let b of i){if(n.excludeIds&&b.id)continue;let h=$(b,n,r),R=u.get(h.signature)||[],N=n.excludeIds?R.filter(k=>!k.id):R;for(let k of N){let{score:m,breakdown:O}=Ne(b,k,n,r,{candidateCount:N.length});m>=n.minConfidence&&a.push({newEl:b,oldEl:k,score:m,breakdown:O})}}if(n.weights.slotMatch>0){let b=Jt(t,e,n,r);for(let h of b)a.push(h)}a.sort((b,h)=>h.score-b.score);let M=new Map,w=new Set;for(let{newEl:b,oldEl:h}of a)M.has(b)||w.has(h)||(M.set(b,h),w.add(h));return M}function rt(e,t,n,r){let o=$(e,n,r),i=$(t,n,r),{score:u,breakdown:s}=Ne(e,t,n,r,{candidateCount:1});return{matches:u>=n.minConfidence,score:u,breakdown:s,newMeta:{signature:o.signature,path:o.path,textHint:o.textHint},oldMeta:{signature:i.signature,path:i.path,textHint:i.textHint}}}function it(e={}){let t={...et,...e,weights:{...et.weights,...e.weights}},n=new WeakMap,r=new WeakMap;return{findMatch:(o,i)=>tt(o,i,t,n,r),computeMatches:(o,i)=>nt(o,i,t,n,r),explain:(o,i)=>rt(o,i,t,n),invalidate:o=>zt(o,n,r),session:()=>{let o=new WeakMap,i=new WeakMap;return{findMatch:(u,s)=>tt(u,s,t,o,i),computeMatches:(u,s)=>nt(u,s,t,o,i),explain:(u,s)=>rt(u,s,t,o)}},getConfig:()=>({...t})}}var Yt=it(),Oe=function(){"use strict";let e=()=>{};function t(m){if(!(m instanceof Element))return!1;if(m.hasAttribute("save-ignore"))return!0;if(m.tagName==="LINK"||m.tagName==="SCRIPT"){let O=m.getAttribute("src")||m.getAttribute("href")||"";if(O.startsWith("chrome-extension://")||O.startsWith("moz-extension://")||O.startsWith("safari-web-extension://"))return!0}return!1}function n(m,O){if(O!=="smart")return m.outerHTML;let x=m.getAttribute("src"),S=m.getAttribute("type")||"text/javascript";if(x)try{let v=new URL(x,window.location.href);return`ext:${S}:${v.origin}${v.pathname}${v.search}`}catch{return`ext:${S}:${x}`}else{let v=m.textContent.trim(),E=5381;for(let d=0;d<v.length;d++)E=(E<<5)+E^v.charCodeAt(d);return`inline:${S}:${Math.abs(E).toString(36)}`}}let r={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:m=>m.getAttribute("im-preserve")==="true",shouldReAppend:m=>m.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!1,matchMode:"outerHTML",shouldPreserve:m=>m.getAttribute("im-preserve")==="true",shouldReAppend:m=>m.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},o={computeMatches(m,O){let{computeMatches:x}=Yt.session();return x(m,O)}};function i(m,O,x={}){m=N(m);let S=k(O),v=R(m,S,x),E=v.scripts.matchMode,d=new Set(Array.from(m.querySelectorAll("script")).map(l=>n(l,E))),y=s(v,()=>w(v,m,S,l=>l.morphStyle==="innerHTML"?(a(l,m,S),Array.from(m.childNodes)):u(l,m,S)));v.pantry.remove();let c=h(m,d,v);return c.length>0?y instanceof Promise?y.then(l=>Promise.all(c).then(()=>l)):Promise.all(c).then(()=>y):y}function u(m,O,x){let S=k(O);return a(m,S,x,O,O.nextSibling),Array.from(S.childNodes)}function s(m,O){if(!m.config.restoreFocus)return O();let x=document.activeElement;if(!(x instanceof HTMLInputElement||x instanceof HTMLTextAreaElement))return O();let{id:S,selectionStart:v,selectionEnd:E}=x,d=O();return S&&S!==document.activeElement?.getAttribute("id")&&(x=m.target.querySelector(`[id="${S}"]`),x?.focus()),x&&!x.selectionEnd&&E!=null&&x.setSelectionRange(v,E),d}let a=function(){function m(c,l,p,f=null,g=null){l instanceof HTMLTemplateElement&&p instanceof HTMLTemplateElement&&(l=l.content,p=p.content),f||=l.firstChild;for(let A of p.childNodes){if(t(A))continue;if(f&&f!=g){let I=x(c,A,f,g);if(I){I!==f&&v(c,f,I),M(I,A,c),f=I.nextSibling;continue}}if(A instanceof Element){let I=A.getAttribute("id");if(c.persistentIds.has(I)){let L=E(l,I,f,c);M(L,A,c),f=L.nextSibling;continue}if(!c.idMap.has(A)){let L=c.hyperMatches.get(A);if(L&&!c.idMap.has(L)){y(l,L,f),M(L,A,c),f=L.nextSibling;continue}}}let T=O(l,A,f,c);T&&(f=T.nextSibling)}for(;f&&f!=g;){let A=f;f=f.nextSibling,t(A)||S(c,A)}}function O(c,l,p,f){if(f.callbacks.beforeNodeAdded(l)===!1)return null;if(f.idMap.has(l)){let g=document.createElement(l.tagName);return c.insertBefore(g,p),M(g,l,f),f.callbacks.afterNodeAdded(g),g}else{let g=document.importNode(l,!0);return c.insertBefore(g,p),f.callbacks.afterNodeAdded(g),g}}let x=function(){function c(f,g,A,T){let I=g instanceof Element&&!f.idMap.has(g)?f.hyperMatches.get(g):null,L=null,j=g.nextSibling,G=0,C=A;for(;C&&C!=T;){if(p(C,g)){if(l(f,C,g)||C===I&&!f.idMap.has(C))return C;if(L===null){let V=C instanceof Element&&f.hyperMatchedOldElements.has(C);!f.idMap.has(C)&&!V&&(L=C)}}if(L===null&&j&&p(C,j)&&(G++,j=j.nextSibling,G>=2&&(L=void 0)),f.activeElementAndParents.includes(C))break;C=C.nextSibling}return L||null}function l(f,g,A){let T=f.idMap.get(g),I=f.idMap.get(A);if(!I||!T)return!1;for(let L of T)if(I.has(L))return!0;return!1}function p(f,g){let A=f,T=g;return A.nodeType===T.nodeType&&A.tagName===T.tagName&&(!A.getAttribute?.("id")||A.getAttribute?.("id")===T.getAttribute?.("id"))}return c}();function S(c,l){let p=l instanceof Element&&c.hyperMatchedOldElements.has(l)&&!c.idMap.has(l);if(c.idMap.has(l)||p)y(c.pantry,l,null);else{if(c.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),c.callbacks.afterNodeRemoved(l)}}function v(c,l,p){let f=l;for(;f&&f!==p;){let g=f;f=f.nextSibling,t(g)||S(c,g)}return f}function E(c,l,p,f){let g=f.target.getAttribute?.("id")===l&&f.target||f.target.querySelector(`[id="${l}"]`)||f.pantry.querySelector(`[id="${l}"]`);return d(g,f),y(c,g,p),g}function d(c,l){let p=c.getAttribute("id");for(;c=c.parentNode;){let f=l.idMap.get(c);f&&(f.delete(p),f.size||l.idMap.delete(c))}}function y(c,l,p){if(c.moveBefore)try{c.moveBefore(l,p)}catch{c.insertBefore(l,p)}else c.insertBefore(l,p)}return m}(),M=function(){function m(d,y,c){return c.ignoreActive&&d===document.activeElement?null:(c.callbacks.beforeNodeMorphed(d,y)===!1||(d instanceof HTMLHeadElement&&c.head.ignore||(d instanceof HTMLHeadElement&&c.head.style!=="morph"?b(d,y,c):(O(d,y,c),E(d,c)||a(c,d,y))),c.callbacks.afterNodeMorphed(d,y)),d)}function O(d,y,c){let l=y.nodeType;if(l===1){let p=d,f=y,g=p.attributes,A=f.attributes;for(let T of A)v(T.name,p,"update",c)||p.getAttribute(T.name)!==T.value&&p.setAttribute(T.name,T.value);for(let T=g.length-1;0<=T;T--){let I=g[T];if(I&&!f.hasAttribute(I.name)){if(v(I.name,p,"remove",c))continue;p.removeAttribute(I.name)}}E(p,c)||x(p,f,c)}(l===8||l===3)&&d.nodeValue!==y.nodeValue&&(d.nodeValue=y.nodeValue)}function x(d,y,c){if(d instanceof HTMLInputElement&&y instanceof HTMLInputElement&&y.type!=="file"){let l=y.value,p=d.value;S(d,y,"checked",c),S(d,y,"disabled",c),c.formStateSync==="property"?p!==l&&(v("value",d,"update",c)||(d.value=l)):y.hasAttribute("value")?p!==l&&(v("value",d,"update",c)||(d.setAttribute("value",l),d.value=l)):v("value",d,"remove",c)||(d.value="",d.removeAttribute("value"))}else if(d instanceof HTMLOptionElement&&y instanceof HTMLOptionElement)S(d,y,"selected",c);else if(d instanceof HTMLTextAreaElement&&y instanceof HTMLTextAreaElement){let l=y.value,p=d.value;if(v("value",d,"update",c))return;l!==p&&(d.value=l),d.firstChild&&d.firstChild.nodeValue!==l&&(d.firstChild.nodeValue=l)}}function S(d,y,c,l){let p=y[c],f=d[c];if(p!==f){let g=v(c,d,"update",l);if(g||(d[c]=y[c]),l.formStateSync==="property")return;p?g||d.setAttribute(c,""):v(c,d,"remove",l)||d.removeAttribute(c)}}function v(d,y,c,l){return d==="value"&&l.ignoreActiveValue&&y===document.activeElement?!0:l.callbacks.beforeAttributeUpdated(d,y,c)===!1}function E(d,y){return!!y.ignoreActiveValue&&d===document.activeElement&&d!==document.body}return m}();function w(m,O,x,S){if(m.head.block){let v=O.querySelector("head"),E=x.querySelector("head");if(v&&E){let d=b(v,E,m);return Promise.all(d).then(()=>{let y=Object.assign(m,{head:{block:!1,ignore:!0}});return S(y)})}}return S(m)}function b(m,O,x){let S=[],v=[],E=[],d=[],y=x.scripts.matchMode,c=f=>{if(f.tagName==="SCRIPT")return n(f,y);if(f.tagName==="LINK"&&y==="smart"){let g=f.getAttribute("href");if(g)try{let A=new URL(g,window.location.href);return`link:${f.getAttribute("rel")||""}:${A.origin}${A.pathname}${A.search}`}catch{}}return f.outerHTML},l=new Map;for(let f of O.children)t(f)||l.set(c(f),f);for(let f of m.children){let g=c(f),A=l.has(g),T=x.head.shouldReAppend(f),I=x.head.shouldPreserve(f);A||I?T?v.push(f):(l.delete(g),E.push(f)):x.head.style==="append"?T&&(v.push(f),d.push(f)):x.head.shouldRemove(f)!==!1&&!t(f)&&v.push(f)}d.push(...l.values());let p=[];for(let f of d){let g=document.createRange().createContextualFragment(f.outerHTML).firstChild;if(x.callbacks.beforeNodeAdded(g)!==!1){if("href"in g&&g.href||"src"in g&&g.src){let A,T=new Promise(function(I){A=I});g.addEventListener("load",function(){A()}),p.push(T)}m.appendChild(g),x.callbacks.afterNodeAdded(g),S.push(g)}}for(let f of v)x.callbacks.beforeNodeRemoved(f)!==!1&&(m.removeChild(f),x.callbacks.afterNodeRemoved(f));return x.head.afterHeadMorphed(m,{added:S,kept:E,removed:v}),p}function h(m,O,x){if(!x.scripts.handle)return[];let S=[],v=[],E=[],d=[],y=x.scripts.matchMode,c=Array.from(m.querySelectorAll("script"));for(let p of c){let f=n(p,y),g=O.has(f),A=x.scripts.shouldPreserve(p),T=x.scripts.shouldReAppend(p);g||A?T?(v.push(p),d.push(p)):E.push(p):d.push(p)}for(let p of O){let f=c.some(g=>g.outerHTML===p)}let l=[];for(let p of d){if(x.callbacks.beforeNodeAdded(p)===!1)continue;let f=document.createRange().createContextualFragment(p.outerHTML).firstChild;if(f.src){let g,A=new Promise(function(T){g=T});f.addEventListener("load",function(){g()}),f.addEventListener("error",function(){g()}),l.push(A)}p.replaceWith(f),x.callbacks.afterNodeAdded(f),S.push(f)}return x.scripts.afterScriptsHandled(m,{added:S,kept:E,removed:v}),l}let R=function(){function m(c,l,p){let{persistentIds:f,idMap:g}=d(c,l),A=o.computeMatches(c,l);if(typeof p.key=="function"){let j=new Map,G=new Set,C=H=>{let P=p.key(H);P!=null&&(j.has(P)?G.add(P):j.set(P,H))};c instanceof Element&&C(c);for(let H of c.querySelectorAll("*"))C(H);for(let H of G)j.delete(H);let V=new Map;for(let[H,P]of A)V.set(P,H);let Ae=l.__hyperMorphRoot||l,ce=new Map,Je=new Set,Ye=H=>{let P=p.key(H);P!=null&&(ce.has(P)?Je.add(P):ce.set(P,H))};Ae instanceof Element&&Ye(Ae);for(let H of Ae.querySelectorAll("*"))Ye(H);for(let H of Je)ce.delete(H);for(let[H,P]of ce){let K=j.get(H);if(!K||K.tagName!==P.tagName)continue;let Me=V.get(K);Me&&Me!==P&&A.delete(Me);let Ee=A.get(P);Ee&&Ee!==K&&V.delete(Ee),A.set(P,K),V.set(K,P)}}let T=new Set;for(let j of A.values())T.add(j);let I=O(p),L=I.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(L))throw`Do not understand how to morph style ${L}`;return{target:c,newContent:l,config:I,morphStyle:L,ignoreActive:I.ignoreActive,ignoreActiveValue:I.ignoreActiveValue,restoreFocus:I.restoreFocus,formStateSync:I.formStateSync||"attribute",idMap:g,persistentIds:f,hyperMatches:A,hyperMatchedOldElements:T,pantry:x(),activeElementAndParents:S(c),callbacks:I.callbacks,head:I.head,scripts:I.scripts}}function O(c){let l=Object.assign({},r);return Object.assign(l,c),l.callbacks=Object.assign({},r.callbacks,c.callbacks),l.head=Object.assign({},r.head,c.head),l.scripts=Object.assign({},r.scripts,c.scripts),l}function x(){let c=document.createElement("div");return c.hidden=!0,document.body.insertAdjacentElement("afterend",c),c}function S(c){let l=[],p=document.activeElement;if(p?.tagName!=="BODY"&&c.contains(p))for(;p&&(l.push(p),p!==c);)p=p.parentElement;return l}function v(c){let l=Array.from(c.querySelectorAll("[id]"));return c.getAttribute?.("id")&&l.push(c),l}function E(c,l,p,f){for(let g of f){let A=g.getAttribute("id");if(l.has(A)){let T=g;for(;T;){let I=c.get(T);if(I==null&&(I=new Set,c.set(T,I)),I.add(A),T===p)break;T=T.parentElement}}}}function d(c,l){let p=v(c),f=v(l),g=y(p,f),A=new Map;E(A,g,c,p);let T=l.__hyperMorphRoot||l;return E(A,g,T,f),{persistentIds:g,idMap:A}}function y(c,l){let p=new Set,f=new Map;for(let{id:A,tagName:T}of c)f.has(A)?p.add(A):f.set(A,T);let g=new Set;for(let{id:A,tagName:T}of l)g.has(A)?p.add(A):f.get(A)===T&&g.add(A);for(let A of p)g.delete(A);return g}return m}(),{normalizeElement:N,normalizeParent:k}=function(){let m=new WeakSet;function O(E){return E instanceof Document?E.documentElement:E}function x(E){if(E==null)return document.createElement("div");if(typeof E=="string")return x(v(E));if(m.has(E))return E;if(E instanceof Node){if(E.parentNode)return new S(E);{let d=document.createElement("div");return d.append(E),d}}else{let d=document.createElement("div");for(let y of[...E])d.append(y);return d}}class S{constructor(d){this.originalNode=d,this.realParentNode=d.parentNode,this.previousSibling=d.previousSibling,this.nextSibling=d.nextSibling}get childNodes(){let d=[],y=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;y&&y!=this.nextSibling;)d.push(y),y=y.nextSibling;return d}querySelectorAll(d){return this.childNodes.reduce((y,c)=>{if(c instanceof Element){c.matches(d)&&y.push(c);let l=c.querySelectorAll(d);for(let p=0;p<l.length;p++)y.push(l[p])}return y},[])}insertBefore(d,y){return this.realParentNode.insertBefore(d,y)}moveBefore(d,y){return this.realParentNode.moveBefore(d,y)}get __hyperMorphRoot(){return this.originalNode}}function v(E){let d=new DOMParser,y=E.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(y.match(/<\/html>/)||y.match(/<\/head>/)||y.match(/<\/body>/)){let c=d.parseFromString(E,"text/html");if(y.match(/<\/html>/))return m.add(c),c;{let l=c.firstChild;return l&&m.add(l),l}}else{let l=d.parseFromString("<body><template>"+E+"</template></body>","text/html").body.querySelector("template").content;return m.add(l),l}}return{normalizeElement:O,normalizeParent:x}}();return{morph:i,defaults:r}}();var Ln=Oe.morph,Cn=Oe.defaults,st=Oe;function Ie(e,t,{onWidgetRemoved:n}={}){st.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(r){let o=fe.get(r);o?.destroy&&o.destroy(),n?.(r)}}})}var pe={};xe(pe,{EmptyListInsert:()=>ee,MAX_RULE_DEPTH:()=>Y,MaxRuleDepthExceeded:()=>q,RuleTargetReadOnly:()=>te,RulesParseError:()=>J,ShapeMismatch:()=>Z,UnknownRulesVersion:()=>X,UpgradeAlreadyRegistered:()=>ne});var J=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},X=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},Y=20,q=class extends Error{constructor(t){super(`rule depth exceeded ${Y} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},Z=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},ee=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}},te=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},ne=class extends Error{constructor(){super("upgrade transform already registered; only one registration is allowed per page."),this.name="UpgradeAlreadyRegistered"}};var ke=null;function Le(e){if(typeof e!="function")throw new TypeError("registerUpgrade expects a function (v1Data) => v2Data");if(ke)throw new ne;ke=e}function he(){return ke}function re(e,t){let n={carriedOver:0,discarded:0,listItems:0},r=Ce(t,e,n);return He(t,e,n),{data:r,summary:n}}function Ce(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?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,r]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(o=>Ce(r,o,n))):void 0}if(typeof e=="object"&&e!==null){let r={};for(let[o,i]of Object.entries(e)){let u=Ce(i,t?.[o],n);u!==void 0&&(r[o]=u)}return r}}function He(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let r=new Set(Object.keys(e));for(let o of Object.keys(t))r.has(o)?He(e[o],t[o],n):n.discarded+=me(t[o]);return}if(Array.isArray(e)&&Array.isArray(t)){let r=e[1];t.forEach(o=>He(r,o,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=me(t))}}function me(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+me(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+me(n),0):1}async function Pe({sourceUrl:e,v1Data:t,v1Version:n=null,parent:r=typeof window<"u"?window:null,timeoutMs:o=15e3,hidden:i=!0}={}){if(!r)throw new Error("upgrade.run requires a window context");if(!e)throw new Error("upgrade.run requires sourceUrl");let u=Qt(e,r.location.origin),s=new URL(u,r.location.href).origin,a=r.document.createElement("iframe");i&&(a.style.cssText="position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;border:0;"),a.setAttribute("aria-hidden","true"),a.src=u,r.document.body.appendChild(a);let M=()=>{};try{return await new Promise((w,b)=>{let h=setTimeout(()=>{b(new Error(`upgrade.run: helper iframe timed out after ${o}ms`))},o),R=N=>{if(N.source!==a.contentWindow||N.origin!==s)return;let k=N.data;if(!(!k||typeof k!="object")){if(k.type==="hha:upgrade-ready"){a.contentWindow.postMessage({type:"hha:upgrade-data",v1Data:t,v1Version:n},s);return}if(k.type==="hha:upgrade-result"){clearTimeout(h),w({html:k.html,summary:k.summary});return}if(k.type==="hha:upgrade-error"){clearTimeout(h);let m=new Error(k.message||"helper error");m.name=k.name||"UpgradeHelperError",b(m);return}}};r.addEventListener("message",R),M=()=>{r.removeEventListener("message",R),clearTimeout(h),a.parentNode&&a.parentNode.removeChild(a)}})}finally{M()}}function Qt(e,t){let n=new URL(e,typeof location<"u"?location.href:void 0);return n.searchParams.set("_hyperHtmlApi","upgrade-helper"),n.searchParams.set("parentOrigin",t),n.toString()}function De(e){try{return JSON.parse(e)}catch(t){throw new J(`Invalid strict JSON: ${t.message}`,t)}}function oe(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(o){let i=[],u=0;for(;u<o.length;){let s=o[u];if(/\s/.test(s)){u++;continue}if("{}".includes(s)){i.push({type:s,value:s}),u++;continue}if(s==="["){let b=!1,h=u+1;for(;h<o.length&&/\s/.test(o[h]);)h++;if(h<o.length&&/[a-zA-Z_]/.test(o[h])&&(b=!0),!b){i.push({type:s,value:s}),u++;continue}}if(s==="]"){i.push({type:s,value:s}),u++;continue}if(s===":"){i.push({type:t.COLON,value:s}),u++;continue}if(s===","){i.push({type:t.COMMA,value:s}),u++;continue}if(s==='"'||s==="'"){let b=s,h=u+1;for(;h<o.length&&o[h]!==b;)o[h]==="\\"&&h++,h++;i.push({type:t.STRING,value:o.substring(u+1,h),quoted:!0,sourceQuote:b}),u=h+1;continue}let a=u,M;for(;a<o.length&&!/[{},]/.test(o[a]);)if(o[a]===":"){let b=[":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 R of b){let N=R.substring(1);if(o.substring(a+1,a+1+N.length)===N){h=!0,a+=N.length;break}}if(!h)break}else if(o[a]==="["){for(a++;a<o.length&&o[a]!=="]";){if(o[a]==='"'||o[a]==="'"){let b=o[a];for(a++;a<o.length&&o[a]!==b;)o[a]==="\\"&&a++,a++}a++}a<o.length&&o[a]==="]"&&a++}else a++;M=o.substring(u,a);let w=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?w=t.NUMBER:M==="true"||M==="false"||M==="null"?w=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(w=t.SELECTOR),i.push({type:w,value:M,quoted:!1}),u=a}return i}function r(o){let i="";for(let u=0;u<o.length;u++){let s=o[u];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 a=o[u+1];if(a&&(a.type==="}"||a.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let a=s.value;s.sourceQuote==="'"&&(a=a.replace(/\\'/g,"'"),a=a.replace(/(\\*)"/g,(M,w)=>w.length%2===0?w+'\\"':M)),i+=`"${a}"`;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 o=n(e),i=r(o);return JSON.parse(i)}catch(o){throw new J("Invalid extraction rules syntax: "+o.message,o)}}var Xt="1",at=/^[a-zA-Z0-9_-]+$/;function U(e,t,n){let r;if(n===void 0)r="script[data-rules-name]";else{if(typeof n!="string"||!at.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${at})`);r=`script[data-rules-name~="${n}"]`}let o=e.find(t,r,{includeRulesTag:!0});if(o.length===0)return null;n!==void 0&&o.length>1&&console.warn(`hyper-html-api: ${o.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=o[0],u=e.attr(i,"data-rules-version");if(u!==Xt)throw new X(u);return{rules:oe(e.text(i)),tagNode:i}}var ge=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],_e=new Set(ge),ct=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),ut=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);function B(e,t,n,r={}){return je(e,t,n,{depth:0,path:[]},r)}function je(e,t,n,r,o){if(r.depth>Y)throw new q(r.path);if(typeof n=="string")return Zt(e,t,n,o);if(Array.isArray(n)){let[i,u]=n;return e.find(t,i,o).map((a,M)=>je(e,a,u,{depth:r.depth+1,path:[...r.path,M]},o))}if(typeof n=="object"&&n!==null){let i={};for(let[u,s]of Object.entries(n))i[u]=je(e,t,s,{depth:r.depth+1,path:[...r.path,u]},o);return i}return null}function Zt(e,t,n,r){if(n.endsWith("[]")){let i=n.slice(0,-2);return e.find(t,i,r).map(u=>e.text(u))}if(n.startsWith("@"))return lt(e,t,n.slice(1));if(n.includes("@")){let i=n.lastIndexOf("@"),u=n.slice(0,i),s=n.slice(i+1),a=u?e.find(t,u,r):[t];return a.length===0?null:lt(e,a[0],s)}if(n===".")return e.text(t);let o=e.find(t,n,r);return o.length===0?null:e.text(o[0])}function lt(e,t,n){if(_e.has(n)){let o=e.prop(t,n);return o==null?null:String(o)}let r=e.attr(t,n);return r||null}var en=.5;function $e(e,t,n,r,o,i,u,s={}){let a=e.find(t,n,s);if(o.length===0){a.forEach(S=>e.remove(S));return}let M=o.length>a.length,w=a[0]||null;if(M&&!w&&(w=sn(e,t,n,s),!w))throw new ee(i.path);let b=a.map(S=>tn(e,S,r,s)),h=null;if(w){h=e.clone(w),s.templateAttr&&e.removeAttr(h,s.templateAttr);let S=e.stripIds(h);S>0&&console.warn(`[hyper-html-api] stripped ${S} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let R=nn(o,b,r),N=a[0]||w,k=e.parent(N),m=a.length>0?on(e,k,N):0,O=new Set,x=o.map((S,v)=>{let E=R[v];if(E>=0)return O.add(E),a[E];let d=e.clone(h);return e.stripIds(d),d});a.forEach((S,v)=>{O.has(v)||e.remove(S)}),x.forEach((S,v)=>{let E=m+v;e.children(k).findIndex(c=>e.sameNode(c,S))!==E&&e.insertAt(k,S,E)}),x.forEach((S,v)=>{if(r===null){let E=o[v],d=E==null?"":String(E);e.text(S)!==d&&e.text(S,d)}else{let E=u(e,S,r,o[v],{depth:i.depth+1,path:[...i.path,v]},s);E&&E!==S&&(x[v]=E)}})}function tn(e,t,n,r){return n===null?e.text(t):B(e,t,n,r)}function nn(e,t,n){let r=new Array(e.length).fill(-1),o=new Set;return e.forEach((i,u)=>{let s=-1,a=-1;t.forEach((M,w)=>{if(o.has(w))return;let b=rn(i,M,n),h=b===a&&s>=0?Math.abs(w-u)<Math.abs(s-u):!1;(b>a||h)&&(a=b,s=w)}),a>=en&&(r[u]=s,o.add(s))}),r}function rn(e,t,n){if(n===null)return e===t?1:0;let r=Object.keys(n||{});if(r.length===0)return 0;let o=0;for(let i of r)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&o++;return o/r.length}function on(e,t,n){let r=e.children(t);for(let o=0;o<r.length;o++)if(e.sameNode(r[o],n))return o;return-1}function sn(e,t,n,r){if(!r.templateAttr)return null;let o=t;for(;o;){let i=e.find(o,n,{includeRulesTag:!1});for(let u of i)if(e.attr(u,r.templateAttr)!=null)return u;o=e.parent(o)}return null}var ft=new Set(["checked","selected","disabled","readOnly","paused"]);function W(e,t,n,r,o={}){let i=[];if(Be(n,r,[],i),i.length)throw new Z(i);ye(e,t,n,r,{depth:0,path:[]},o)}function ye(e,t,n,r,o,i={}){if(o.depth>Y)throw new q(o.path);if(r===void 0)return t;if(typeof n=="string")return an(e,t,n,r,o,i);if(Array.isArray(n)){let[u,s]=n;return $e(e,t,u,s,r,o,ye,i),t}if(typeof n=="object"&&n!==null){for(let[u,s]of Object.entries(n)){let a=ye(e,t,s,r==null?r:r[u],{depth:o.depth+1,path:[...o.path,u]},i);a&&a!==t&&(t=a)}return t}return t}function an(e,t,n,r,o,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return $e(e,t,s,null,r,o,ye,i),t}if(n.startsWith("@"))return dt(e,t,n.slice(1),r);if(n.includes("@")){let s=n.lastIndexOf("@"),a=n.slice(0,s),M=n.slice(s+1),w=a?e.find(t,a,i):[t];return w.length===0||dt(e,w[0],M,r),t}if(n===".")return e.text(t,r==null?"":String(r)),t;let u=e.find(t,n,i);return u.length===0||e.text(u[0],r==null?"":String(r)),t}function dt(e,t,n,r){if(ut.has(n))throw new te(n);if(n==="outerHTML"){let o=r==null?"":String(r);return e.replaceWith(t,o)}return ct.has(n)?(e.prop(t,n,cn(n,r)),t):(e.attr(t,n,r==null?"":String(r)),t)}function cn(e,t){return t==null?ft.has(e)?!1:"":ft.has(e)?!!t:t}function Be(e,t,n,r){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((o,i)=>{typeof o=="object"&&o!==null&&r.push({path:se([...n,i]),expected:"scalar",got:ie(o)})}):r.push({path:se(n),expected:"array",got:ie(t)});return}t!==null&&typeof t=="object"&&r.push({path:se(n),expected:"scalar",got:ie(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){r.push({path:se(n),expected:"array",got:ie(t)});return}let o=e[1];t.forEach((i,u)=>Be(o,i,[...n,u],r));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){r.push({path:se(n),expected:"object",got:ie(t)});return}for(let[o,i]of Object.entries(e))Be(i,t[o],[...n,o],r)}}}function ie(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function se(e){return e.join(".")}function un(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function ln(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var fn={find(e,t,n={}){let r=ln(e);if(!r||!r.querySelectorAll)return[];let o=Array.from(r.querySelectorAll(t));n.includeRulesTag||(o=o.filter(u=>!un(u)));let i=[];if(n.skip&&i.push(n.skip),n.templateAttr&&i.push("["+n.templateAttr+"]"),i.length){let u=i.join(", ");o=o.filter(s=>!s.closest||!s.closest(u))}return o},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 r=e?e[t]:void 0;return r!==void 0?r:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let r=e.children[n]||null;e.insertBefore(t,r)},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 r=e.ownerDocument.createElement("template");r.innerHTML=t;let o=r.content.firstElementChild;if(!o)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(o,e),o},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},D=fn;var dn="_hyperHtmlApi",pn="upgrade-helper",hn="parentOrigin";function be(e=typeof location<"u"?location:null){if(!e)return!1;try{return new URLSearchParams(e.search).get(dn)===pn}catch{return!1}}function pt(e=typeof location<"u"?location:null){return e?new URLSearchParams(e.search).get(hn):null}function We({win:e,doc:t,parentOrigin:n}={}){if(e=e||(typeof window<"u"?window:null),t=t||(typeof document<"u"?document:null),!e||!t||(n=n||pt(e.location),!n))return;let r=()=>mn({win:e,doc:t,parentOrigin:n});t.readyState==="loading"?t.addEventListener("DOMContentLoaded",r,{once:!0}):r()}function mn({win:e,doc:t,parentOrigin:n}){let r;try{r=U(D,t.body)}catch(a){return Fe(e,n,a)}if(!r)return Fe(e,n,new Error("helper-mode: no rules tag in v2 document"));let o=r.rules,i=yn(t,"hyper-version"),u=!!he(),s=a=>{if(a.source!==e.parent||a.origin!==n)return;let M=a.data;if(!(!M||M.type!=="hha:upgrade-data")){e.removeEventListener("message",s);try{let w=gn({doc:t,rules:o,v1Data:M.v1Data});e.parent.postMessage({type:"hha:upgrade-result",html:w.html,summary:w.summary},n)}catch(w){Fe(e,n,w)}}};e.addEventListener("message",s),e.parent.postMessage({type:"hha:upgrade-ready",rules:o,version:i,hasTransform:u},n)}function gn({doc:e,rules:t,v1Data:n}){let r=he(),o=n,i=!1;r&&(o=r(n),i=!0);let{data:u,summary:s}=re(o,t);W(D,e.body,t,u);let a=B(D,e.body,t);return{html:`<!DOCTYPE html>
2
+ `)?{type:"textarea"}:{type:"text"}}function Ht(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=e.includes("@")?e.split("@")[0]:e;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function Pt(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 de(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 Dt(e){return` \xB7 ${e}`}var et={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,slotMatch:30},minConfidence:101};function _t(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 jt(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 $t(e,t){let n=[];for(let r of e.attributes||[]){let o=r.name;o==="id"||o==="class"||t.excludeAttributePrefixes.some(i=>o.startsWith(i))||t.includeAttributes.includes(o)&&n.push(`${o}=${r.value}`)}return n.sort().join("|")}function Bt(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function Ft(e,t){let n=[e.tagName];return t.includeClasses&&n.push(jt(e)),n.push($t(e,t)),_t(n.join("|"))}function Ut(e){let t=e.tagName,n=1,r=e.previousElementSibling;for(;r;)r.tagName===t&&n++,r=r.previousElementSibling;return n}function Wt(e,t){return e.id||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function qt(e){if(e.id)return`#${e.id}`;let t=e.getAttribute?.("role");return t?`@${t}`:e.tagName}function Vt(e,t){let n=[],r=e;for(;r&&r.tagName&&n.length<t.maxPathDepth;){let o=`${r.tagName}:${Ut(r)}`;if(n.unshift(o),r!==e&&Wt(r,t)){n.unshift(qt(r));break}r=r.parentElement}return n}function Kt(e,t){let n=0,r=e.length-1,o=t.length-1;for(;r>=0&&o>=0&&e[r]===t[o];)n++,r--,o--;return n}function $(e,t,n){if(n.has(e))return n.get(e);let r={signature:Ft(e,t),path:Vt(e,t),textHint:Bt(e,t)};return n.set(e,r),r}function ot(e,t,n,r){if(r.has(e))return r.get(e);let o=new Map,i=e.querySelectorAll("*"),u=0;for(let s of i){let a=$(s,t,n);a.domIndex=u++,o.has(a.signature)||o.set(a.signature,[]),o.get(a.signature).push(s)}return r.set(e,o),o}function zt(e,t,n){n.delete(e),t.delete(e);let r=e.querySelectorAll("*");for(let o of r)t.delete(o)}function Ne(e,t,n,r,o){let i=$(e,n,r),u=$(t,n,r),s=n.weights,a={},M=0;if(i.signature!==u.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};M+=s.signature,a.signature=s.signature;let b=Kt(i.path,u.path)*s.pathSegment;M+=b,a.path=b;let h=!0;if(i.textHint&&u.textHint?i.textHint===u.textHint?(M+=s.textMatch,a.text=s.textMatch):(M-=s.textMismatch,a.text=-s.textMismatch,h=!1):i.textHint!==u.textHint&&(M-=s.textMismatch,a.text=-s.textMismatch,h=!1),o.candidateCount===1&&h&&(M+=s.uniqueCandidate,a.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof u.domIndex=="number"){let R=Math.abs(i.domIndex-u.domIndex),N=Math.min(R*s.positionPenalty,20);M-=N,a.drift=-N}return{score:M,breakdown:a}}function tt(e,t,n,r,o){if(n.excludeIds&&e.id)return null;let i=ot(t,n,r,o),u=$(e,n,r);if(typeof u.domIndex!="number"){let h=0,R=e.previousElementSibling;for(;R;)h++,R=R.previousElementSibling;u.domIndex=h}let s=i.get(u.signature)||[],a=n.excludeIds?s.filter(h=>!h.id):s;if(a.length===0)return null;let M=null,w=0,b=null;for(let h of a){let{score:R,breakdown:N}=Ne(e,h,n,r,{candidateCount:a.length});R>w&&(w=R,M=h,b=N)}return w<n.minConfidence?null:{element:M,confidence:w,breakdown:b}}function Jt(e,t,n,r){let o=[],i=n.weights.signature+n.weights.slotMatch,u={slot:i};function s(b){if(b.children)return b.children;let h=b.childNodes;if(!h)return[];let R=[];for(let N=0;N<h.length;N++)h[N].nodeType===1&&R.push(h[N]);return R}function a(b,h){let R=s(b),N=s(h);if(R.length===N.length)for(let k=0;k<R.length;k++){let m=R[k],O=N[k];if(n.excludeIds&&(m.id||O.id)||m.tagName!==O.tagName)continue;let x=$(m,n,r).signature,S=$(O,n,r).signature;x!==S&&o.push({newEl:m,oldEl:O,score:i,breakdown:u}),a(m,O)}}function M(b,h){for(;;){if(b.tagName===h.tagName)return[b,h];let R=s(b);if(!b.tagName&&R.length===1){b=R[0];continue}let N=s(h);if(N.length===1&&N[0].tagName===b.tagName){h=N[0];continue}return null}}let w=M(e,t);return w&&a(w[0],w[1]),o}function nt(e,t,n,r,o){let i=t.querySelectorAll("*"),u=ot(e,n,r,o),s=0;for(let b of i){let h=$(b,n,r);h.domIndex=s++}let a=[];for(let b of i){if(n.excludeIds&&b.id)continue;let h=$(b,n,r),R=u.get(h.signature)||[],N=n.excludeIds?R.filter(k=>!k.id):R;for(let k of N){let{score:m,breakdown:O}=Ne(b,k,n,r,{candidateCount:N.length});m>=n.minConfidence&&a.push({newEl:b,oldEl:k,score:m,breakdown:O})}}if(n.weights.slotMatch>0){let b=Jt(t,e,n,r);for(let h of b)a.push(h)}a.sort((b,h)=>h.score-b.score);let M=new Map,w=new Set;for(let{newEl:b,oldEl:h}of a)M.has(b)||w.has(h)||(M.set(b,h),w.add(h));return M}function rt(e,t,n,r){let o=$(e,n,r),i=$(t,n,r),{score:u,breakdown:s}=Ne(e,t,n,r,{candidateCount:1});return{matches:u>=n.minConfidence,score:u,breakdown:s,newMeta:{signature:o.signature,path:o.path,textHint:o.textHint},oldMeta:{signature:i.signature,path:i.path,textHint:i.textHint}}}function it(e={}){let t={...et,...e,weights:{...et.weights,...e.weights}},n=new WeakMap,r=new WeakMap;return{findMatch:(o,i)=>tt(o,i,t,n,r),computeMatches:(o,i)=>nt(o,i,t,n,r),explain:(o,i)=>rt(o,i,t,n),invalidate:o=>zt(o,n,r),session:()=>{let o=new WeakMap,i=new WeakMap;return{findMatch:(u,s)=>tt(u,s,t,o,i),computeMatches:(u,s)=>nt(u,s,t,o,i),explain:(u,s)=>rt(u,s,t,o)}},getConfig:()=>({...t})}}var Yt=it(),Oe=function(){"use strict";let e=()=>{};function t(m){if(!(m instanceof Element))return!1;if(m.hasAttribute("save-ignore"))return!0;if(m.tagName==="LINK"||m.tagName==="SCRIPT"){let O=m.getAttribute("src")||m.getAttribute("href")||"";if(O.startsWith("chrome-extension://")||O.startsWith("moz-extension://")||O.startsWith("safari-web-extension://"))return!0}return!1}function n(m,O){if(O!=="smart")return m.outerHTML;let x=m.getAttribute("src"),S=m.getAttribute("type")||"text/javascript";if(x)try{let v=new URL(x,window.location.href);return`ext:${S}:${v.origin}${v.pathname}${v.search}`}catch{return`ext:${S}:${x}`}else{let v=m.textContent.trim(),E=5381;for(let d=0;d<v.length;d++)E=(E<<5)+E^v.charCodeAt(d);return`inline:${S}:${Math.abs(E).toString(36)}`}}let r={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:m=>m.getAttribute("im-preserve")==="true",shouldReAppend:m=>m.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!1,matchMode:"outerHTML",shouldPreserve:m=>m.getAttribute("im-preserve")==="true",shouldReAppend:m=>m.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},o={computeMatches(m,O){let{computeMatches:x}=Yt.session();return x(m,O)}};function i(m,O,x={}){m=N(m);let S=k(O),v=R(m,S,x),E=v.scripts.matchMode,d=new Set(Array.from(m.querySelectorAll("script")).map(l=>n(l,E))),y=s(v,()=>w(v,m,S,l=>l.morphStyle==="innerHTML"?(a(l,m,S),Array.from(m.childNodes)):u(l,m,S)));v.pantry.remove();let c=h(m,d,v);return c.length>0?y instanceof Promise?y.then(l=>Promise.all(c).then(()=>l)):Promise.all(c).then(()=>y):y}function u(m,O,x){let S=k(O);return a(m,S,x,O,O.nextSibling),Array.from(S.childNodes)}function s(m,O){if(!m.config.restoreFocus)return O();let x=document.activeElement;if(!(x instanceof HTMLInputElement||x instanceof HTMLTextAreaElement))return O();let{id:S,selectionStart:v,selectionEnd:E}=x,d=O();return S&&S!==document.activeElement?.getAttribute("id")&&(x=m.target.querySelector(`[id="${S}"]`),x?.focus()),x&&!x.selectionEnd&&E!=null&&x.setSelectionRange(v,E),d}let a=function(){function m(c,l,p,f=null,g=null){l instanceof HTMLTemplateElement&&p instanceof HTMLTemplateElement&&(l=l.content,p=p.content),f||=l.firstChild;for(let A of p.childNodes){if(t(A))continue;if(f&&f!=g){let I=x(c,A,f,g);if(I){I!==f&&v(c,f,I),M(I,A,c),f=I.nextSibling;continue}}if(A instanceof Element){let I=A.getAttribute("id");if(c.persistentIds.has(I)){let L=E(l,I,f,c);M(L,A,c),f=L.nextSibling;continue}if(!c.idMap.has(A)){let L=c.hyperMatches.get(A);if(L&&!c.idMap.has(L)){y(l,L,f),M(L,A,c),f=L.nextSibling;continue}}}let T=O(l,A,f,c);T&&(f=T.nextSibling)}for(;f&&f!=g;){let A=f;f=f.nextSibling,t(A)||S(c,A)}}function O(c,l,p,f){if(f.callbacks.beforeNodeAdded(l)===!1)return null;if(f.idMap.has(l)){let g=document.createElement(l.tagName);return c.insertBefore(g,p),M(g,l,f),f.callbacks.afterNodeAdded(g),g}else{let g=document.importNode(l,!0);return c.insertBefore(g,p),f.callbacks.afterNodeAdded(g),g}}let x=function(){function c(f,g,A,T){let I=g instanceof Element&&!f.idMap.has(g)?f.hyperMatches.get(g):null,L=null,j=g.nextSibling,G=0,C=A;for(;C&&C!=T;){if(p(C,g)){if(l(f,C,g)||C===I&&!f.idMap.has(C))return C;if(L===null){let V=C instanceof Element&&f.hyperMatchedOldElements.has(C);!f.idMap.has(C)&&!V&&(L=C)}}if(L===null&&j&&p(C,j)&&(G++,j=j.nextSibling,G>=2&&(L=void 0)),f.activeElementAndParents.includes(C))break;C=C.nextSibling}return L||null}function l(f,g,A){let T=f.idMap.get(g),I=f.idMap.get(A);if(!I||!T)return!1;for(let L of T)if(I.has(L))return!0;return!1}function p(f,g){let A=f,T=g;return A.nodeType===T.nodeType&&A.tagName===T.tagName&&(!A.getAttribute?.("id")||A.getAttribute?.("id")===T.getAttribute?.("id"))}return c}();function S(c,l){let p=l instanceof Element&&c.hyperMatchedOldElements.has(l)&&!c.idMap.has(l);if(c.idMap.has(l)||p)y(c.pantry,l,null);else{if(c.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),c.callbacks.afterNodeRemoved(l)}}function v(c,l,p){let f=l;for(;f&&f!==p;){let g=f;f=f.nextSibling,t(g)||S(c,g)}return f}function E(c,l,p,f){let g=f.target.getAttribute?.("id")===l&&f.target||f.target.querySelector(`[id="${l}"]`)||f.pantry.querySelector(`[id="${l}"]`);return d(g,f),y(c,g,p),g}function d(c,l){let p=c.getAttribute("id");for(;c=c.parentNode;){let f=l.idMap.get(c);f&&(f.delete(p),f.size||l.idMap.delete(c))}}function y(c,l,p){if(c.moveBefore)try{c.moveBefore(l,p)}catch{c.insertBefore(l,p)}else c.insertBefore(l,p)}return m}(),M=function(){function m(d,y,c){return c.ignoreActive&&d===document.activeElement?null:(c.callbacks.beforeNodeMorphed(d,y)===!1||(d instanceof HTMLHeadElement&&c.head.ignore||(d instanceof HTMLHeadElement&&c.head.style!=="morph"?b(d,y,c):(O(d,y,c),E(d,c)||a(c,d,y))),c.callbacks.afterNodeMorphed(d,y)),d)}function O(d,y,c){let l=y.nodeType;if(l===1){let p=d,f=y,g=p.attributes,A=f.attributes;for(let T of A)v(T.name,p,"update",c)||p.getAttribute(T.name)!==T.value&&p.setAttribute(T.name,T.value);for(let T=g.length-1;0<=T;T--){let I=g[T];if(I&&!f.hasAttribute(I.name)){if(v(I.name,p,"remove",c))continue;p.removeAttribute(I.name)}}E(p,c)||x(p,f,c)}(l===8||l===3)&&d.nodeValue!==y.nodeValue&&(d.nodeValue=y.nodeValue)}function x(d,y,c){if(d instanceof HTMLInputElement&&y instanceof HTMLInputElement&&y.type!=="file"){let l=y.value,p=d.value;S(d,y,"checked",c),S(d,y,"disabled",c),c.formStateSync==="property"?p!==l&&(v("value",d,"update",c)||(d.value=l)):y.hasAttribute("value")?p!==l&&(v("value",d,"update",c)||(d.setAttribute("value",l),d.value=l)):v("value",d,"remove",c)||(d.value="",d.removeAttribute("value"))}else if(d instanceof HTMLOptionElement&&y instanceof HTMLOptionElement)S(d,y,"selected",c);else if(d instanceof HTMLTextAreaElement&&y instanceof HTMLTextAreaElement){let l=y.value,p=d.value;if(v("value",d,"update",c))return;l!==p&&(d.value=l),d.firstChild&&d.firstChild.nodeValue!==l&&(d.firstChild.nodeValue=l)}}function S(d,y,c,l){let p=y[c],f=d[c];if(p!==f){let g=v(c,d,"update",l);if(g||(d[c]=y[c]),l.formStateSync==="property")return;p?g||d.setAttribute(c,""):v(c,d,"remove",l)||d.removeAttribute(c)}}function v(d,y,c,l){return d==="value"&&l.ignoreActiveValue&&y===document.activeElement?!0:l.callbacks.beforeAttributeUpdated(d,y,c)===!1}function E(d,y){return!!y.ignoreActiveValue&&d===document.activeElement&&d!==document.body}return m}();function w(m,O,x,S){if(m.head.block){let v=O.querySelector("head"),E=x.querySelector("head");if(v&&E){let d=b(v,E,m);return Promise.all(d).then(()=>{let y=Object.assign(m,{head:{block:!1,ignore:!0}});return S(y)})}}return S(m)}function b(m,O,x){let S=[],v=[],E=[],d=[],y=x.scripts.matchMode,c=f=>{if(f.tagName==="SCRIPT")return n(f,y);if(f.tagName==="LINK"&&y==="smart"){let g=f.getAttribute("href");if(g)try{let A=new URL(g,window.location.href);return`link:${f.getAttribute("rel")||""}:${A.origin}${A.pathname}${A.search}`}catch{}}return f.outerHTML},l=new Map;for(let f of O.children)t(f)||l.set(c(f),f);for(let f of m.children){let g=c(f),A=l.has(g),T=x.head.shouldReAppend(f),I=x.head.shouldPreserve(f);A||I?T?v.push(f):(l.delete(g),E.push(f)):x.head.style==="append"?T&&(v.push(f),d.push(f)):x.head.shouldRemove(f)!==!1&&!t(f)&&v.push(f)}d.push(...l.values());let p=[];for(let f of d){let g=document.createRange().createContextualFragment(f.outerHTML).firstChild;if(x.callbacks.beforeNodeAdded(g)!==!1){if("href"in g&&g.href||"src"in g&&g.src){let A,T=new Promise(function(I){A=I});g.addEventListener("load",function(){A()}),p.push(T)}m.appendChild(g),x.callbacks.afterNodeAdded(g),S.push(g)}}for(let f of v)x.callbacks.beforeNodeRemoved(f)!==!1&&(m.removeChild(f),x.callbacks.afterNodeRemoved(f));return x.head.afterHeadMorphed(m,{added:S,kept:E,removed:v}),p}function h(m,O,x){if(!x.scripts.handle)return[];let S=[],v=[],E=[],d=[],y=x.scripts.matchMode,c=Array.from(m.querySelectorAll("script"));for(let p of c){let f=n(p,y),g=O.has(f),A=x.scripts.shouldPreserve(p),T=x.scripts.shouldReAppend(p);g||A?T?(v.push(p),d.push(p)):E.push(p):d.push(p)}for(let p of O){let f=c.some(g=>g.outerHTML===p)}let l=[];for(let p of d){if(x.callbacks.beforeNodeAdded(p)===!1)continue;let f=document.createRange().createContextualFragment(p.outerHTML).firstChild;if(f.src){let g,A=new Promise(function(T){g=T});f.addEventListener("load",function(){g()}),f.addEventListener("error",function(){g()}),l.push(A)}p.replaceWith(f),x.callbacks.afterNodeAdded(f),S.push(f)}return x.scripts.afterScriptsHandled(m,{added:S,kept:E,removed:v}),l}let R=function(){function m(c,l,p){let{persistentIds:f,idMap:g}=d(c,l),A=o.computeMatches(c,l);if(typeof p.key=="function"){let j=new Map,G=new Set,C=H=>{let P=p.key(H);P!=null&&(j.has(P)?G.add(P):j.set(P,H))};c instanceof Element&&C(c);for(let H of c.querySelectorAll("*"))C(H);for(let H of G)j.delete(H);let V=new Map;for(let[H,P]of A)V.set(P,H);let Ae=l.__hyperMorphRoot||l,ce=new Map,Je=new Set,Ye=H=>{let P=p.key(H);P!=null&&(ce.has(P)?Je.add(P):ce.set(P,H))};Ae instanceof Element&&Ye(Ae);for(let H of Ae.querySelectorAll("*"))Ye(H);for(let H of Je)ce.delete(H);for(let[H,P]of ce){let K=j.get(H);if(!K||K.tagName!==P.tagName)continue;let Me=V.get(K);Me&&Me!==P&&A.delete(Me);let Ee=A.get(P);Ee&&Ee!==K&&V.delete(Ee),A.set(P,K),V.set(K,P)}}let T=new Set;for(let j of A.values())T.add(j);let I=O(p),L=I.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(L))throw`Do not understand how to morph style ${L}`;return{target:c,newContent:l,config:I,morphStyle:L,ignoreActive:I.ignoreActive,ignoreActiveValue:I.ignoreActiveValue,restoreFocus:I.restoreFocus,formStateSync:I.formStateSync||"attribute",idMap:g,persistentIds:f,hyperMatches:A,hyperMatchedOldElements:T,pantry:x(),activeElementAndParents:S(c),callbacks:I.callbacks,head:I.head,scripts:I.scripts}}function O(c){let l=Object.assign({},r);return Object.assign(l,c),l.callbacks=Object.assign({},r.callbacks,c.callbacks),l.head=Object.assign({},r.head,c.head),l.scripts=Object.assign({},r.scripts,c.scripts),l}function x(){let c=document.createElement("div");return c.hidden=!0,document.body.insertAdjacentElement("afterend",c),c}function S(c){let l=[],p=document.activeElement;if(p?.tagName!=="BODY"&&c.contains(p))for(;p&&(l.push(p),p!==c);)p=p.parentElement;return l}function v(c){let l=Array.from(c.querySelectorAll("[id]"));return c.getAttribute?.("id")&&l.push(c),l}function E(c,l,p,f){for(let g of f){let A=g.getAttribute("id");if(l.has(A)){let T=g;for(;T;){let I=c.get(T);if(I==null&&(I=new Set,c.set(T,I)),I.add(A),T===p)break;T=T.parentElement}}}}function d(c,l){let p=v(c),f=v(l),g=y(p,f),A=new Map;E(A,g,c,p);let T=l.__hyperMorphRoot||l;return E(A,g,T,f),{persistentIds:g,idMap:A}}function y(c,l){let p=new Set,f=new Map;for(let{id:A,tagName:T}of c)f.has(A)?p.add(A):f.set(A,T);let g=new Set;for(let{id:A,tagName:T}of l)g.has(A)?p.add(A):f.get(A)===T&&g.add(A);for(let A of p)g.delete(A);return g}return m}(),{normalizeElement:N,normalizeParent:k}=function(){let m=new WeakSet;function O(E){return E instanceof Document?E.documentElement:E}function x(E){if(E==null)return document.createElement("div");if(typeof E=="string")return x(v(E));if(m.has(E))return E;if(E instanceof Node){if(E.parentNode)return new S(E);{let d=document.createElement("div");return d.append(E),d}}else{let d=document.createElement("div");for(let y of[...E])d.append(y);return d}}class S{constructor(d){this.originalNode=d,this.realParentNode=d.parentNode,this.previousSibling=d.previousSibling,this.nextSibling=d.nextSibling}get childNodes(){let d=[],y=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;y&&y!=this.nextSibling;)d.push(y),y=y.nextSibling;return d}querySelectorAll(d){return this.childNodes.reduce((y,c)=>{if(c instanceof Element){c.matches(d)&&y.push(c);let l=c.querySelectorAll(d);for(let p=0;p<l.length;p++)y.push(l[p])}return y},[])}insertBefore(d,y){return this.realParentNode.insertBefore(d,y)}moveBefore(d,y){return this.realParentNode.moveBefore(d,y)}get __hyperMorphRoot(){return this.originalNode}}function v(E){let d=new DOMParser,y=E.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(y.match(/<\/html>/)||y.match(/<\/head>/)||y.match(/<\/body>/)){let c=d.parseFromString(E,"text/html");if(y.match(/<\/html>/))return m.add(c),c;{let l=c.firstChild;return l&&m.add(l),l}}else{let l=d.parseFromString("<body><template>"+E+"</template></body>","text/html").body.querySelector("template").content;return m.add(l),l}}return{normalizeElement:O,normalizeParent:x}}();return{morph:i,defaults:r}}();var Ln=Oe.morph,Cn=Oe.defaults,st=Oe;function Ie(e,t,{onWidgetRemoved:n}={}){st.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(r){let o=fe.get(r);o?.destroy&&o.destroy(),n?.(r)}}})}var pe={};xe(pe,{EmptyListInsert:()=>ee,MAX_RULE_DEPTH:()=>Y,MaxRuleDepthExceeded:()=>q,RuleTargetReadOnly:()=>te,RulesParseError:()=>J,ShapeMismatch:()=>Z,UnknownRulesVersion:()=>X,UpgradeAlreadyRegistered:()=>ne});var J=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},X=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},Y=20,q=class extends Error{constructor(t){super(`rule depth exceeded ${Y} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},Z=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},ee=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}},te=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},ne=class extends Error{constructor(){super("upgrade transform already registered; only one registration is allowed per page."),this.name="UpgradeAlreadyRegistered"}};var ke=null;function Le(e){if(typeof e!="function")throw new TypeError("registerUpgrade expects a function (v1Data) => v2Data");if(ke)throw new ne;ke=e}function he(){return ke}function re(e,t){let n={carriedOver:0,discarded:0,listItems:0},r=Ce(t,e,n);return He(t,e,n),{data:r,summary:n}}function Ce(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?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,r]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(o=>Ce(r,o,n))):void 0}if(typeof e=="object"&&e!==null){let r={};for(let[o,i]of Object.entries(e)){let u=Ce(i,t?.[o],n);u!==void 0&&(r[o]=u)}return r}}function He(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let r=new Set(Object.keys(e));for(let o of Object.keys(t))r.has(o)?He(e[o],t[o],n):n.discarded+=me(t[o]);return}if(Array.isArray(e)&&Array.isArray(t)){let r=e[1];t.forEach(o=>He(r,o,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=me(t))}}function me(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+me(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+me(n),0):1}async function Pe({sourceUrl:e,v1Data:t,v1Version:n=null,parent:r=typeof window<"u"?window:null,timeoutMs:o=15e3,hidden:i=!0}={}){if(!r)throw new Error("upgrade.run requires a window context");if(!e)throw new Error("upgrade.run requires sourceUrl");let u=Qt(e,r.location.origin),s=new URL(u,r.location.href).origin,a=r.document.createElement("iframe");i&&(a.style.cssText="position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;border:0;"),a.setAttribute("aria-hidden","true"),a.src=u,r.document.body.appendChild(a);let M=()=>{};try{return await new Promise((w,b)=>{let h=setTimeout(()=>{b(new Error(`upgrade.run: helper iframe timed out after ${o}ms`))},o),R=N=>{if(N.source!==a.contentWindow||N.origin!==s)return;let k=N.data;if(!(!k||typeof k!="object")){if(k.type==="hha:upgrade-ready"){a.contentWindow.postMessage({type:"hha:upgrade-data",v1Data:t,v1Version:n},s);return}if(k.type==="hha:upgrade-result"){clearTimeout(h),w({html:k.html,summary:k.summary});return}if(k.type==="hha:upgrade-error"){clearTimeout(h);let m=new Error(k.message||"helper error");m.name=k.name||"UpgradeHelperError",b(m);return}}};r.addEventListener("message",R),M=()=>{r.removeEventListener("message",R),clearTimeout(h),a.parentNode&&a.parentNode.removeChild(a)}})}finally{M()}}function Qt(e,t){let n=new URL(e,typeof location<"u"?location.href:void 0);return n.searchParams.set("_hyperHtmlApi","upgrade-helper"),n.searchParams.set("parentOrigin",t),n.toString()}function De(e){try{return JSON.parse(e)}catch(t){throw new J(`Invalid strict JSON: ${t.message}`,t)}}function oe(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(o){let i=[],u=0;for(;u<o.length;){let s=o[u];if(/\s/.test(s)){u++;continue}if("{}".includes(s)){i.push({type:s,value:s}),u++;continue}if(s==="["){let b=!1,h=u+1;for(;h<o.length&&/\s/.test(o[h]);)h++;if(h<o.length&&/[a-zA-Z_]/.test(o[h])&&(b=!0),!b){i.push({type:s,value:s}),u++;continue}}if(s==="]"){i.push({type:s,value:s}),u++;continue}if(s===":"){i.push({type:t.COLON,value:s}),u++;continue}if(s===","){i.push({type:t.COMMA,value:s}),u++;continue}if(s==='"'||s==="'"){let b=s,h=u+1;for(;h<o.length&&o[h]!==b;)o[h]==="\\"&&h++,h++;i.push({type:t.STRING,value:o.substring(u+1,h),quoted:!0,sourceQuote:b}),u=h+1;continue}let a=u,M;for(;a<o.length&&!/[{},]/.test(o[a]);)if(o[a]===":"){let b=[":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 R of b){let N=R.substring(1);if(o.substring(a+1,a+1+N.length)===N){h=!0,a+=N.length;break}}if(!h)break}else if(o[a]==="["){for(a++;a<o.length&&o[a]!=="]";){if(o[a]==='"'||o[a]==="'"){let b=o[a];for(a++;a<o.length&&o[a]!==b;)o[a]==="\\"&&a++,a++}a++}a<o.length&&o[a]==="]"&&a++}else a++;M=o.substring(u,a);let w=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?w=t.NUMBER:M==="true"||M==="false"||M==="null"?w=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(w=t.SELECTOR),i.push({type:w,value:M,quoted:!1}),u=a}return i}function r(o){let i="";for(let u=0;u<o.length;u++){let s=o[u];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 a=o[u+1];if(a&&(a.type==="}"||a.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let a=s.value;s.sourceQuote==="'"&&(a=a.replace(/\\'/g,"'"),a=a.replace(/(\\*)"/g,(M,w)=>w.length%2===0?w+'\\"':M)),i+=`"${a}"`;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 o=n(e),i=r(o);return JSON.parse(i)}catch(o){throw new J("Invalid extraction rules syntax: "+o.message,o)}}var Xt="1",at=/^[a-zA-Z0-9_-]+$/;function U(e,t,n){let r;if(n===void 0)r="script[data-rules-name]";else{if(typeof n!="string"||!at.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${at})`);r=`script[data-rules-name~="${n}"]`}let o=e.find(t,r,{includeRulesTag:!0});if(o.length===0)return null;n!==void 0&&o.length>1&&console.warn(`hyper-html-api: ${o.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=o[0],u=e.attr(i,"data-rules-version");if(u!==Xt)throw new X(u);return{rules:oe(e.text(i)),tagNode:i}}var ge=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],_e=new Set(ge),ct=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),ut=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);function B(e,t,n,r={}){return je(e,t,n,{depth:0,path:[]},r)}function je(e,t,n,r,o){if(r.depth>Y)throw new q(r.path);if(typeof n=="string")return Zt(e,t,n,o);if(Array.isArray(n)){let[i,u]=n;return e.find(t,i,o).map((a,M)=>je(e,a,u,{depth:r.depth+1,path:[...r.path,M]},o))}if(typeof n=="object"&&n!==null){let i={};for(let[u,s]of Object.entries(n))i[u]=je(e,t,s,{depth:r.depth+1,path:[...r.path,u]},o);return i}return null}function Zt(e,t,n,r){if(n.endsWith("[]")){let i=n.slice(0,-2);return e.find(t,i,r).map(u=>e.text(u))}if(n.startsWith("@"))return lt(e,t,n.slice(1));if(n.includes("@")){let i=n.lastIndexOf("@"),u=n.slice(0,i),s=n.slice(i+1),a=u?e.find(t,u,r):[t];return a.length===0?null:lt(e,a[0],s)}if(n===".")return e.text(t);let o=e.find(t,n,r);return o.length===0?null:e.text(o[0])}function lt(e,t,n){if(_e.has(n)){let o=e.prop(t,n);return o==null?null:String(o)}let r=e.attr(t,n);return r||null}var en=.5;function $e(e,t,n,r,o,i,u,s={}){let a=e.find(t,n,s);if(o.length===0){a.forEach(S=>e.remove(S));return}let M=o.length>a.length,w=a[0]||null;if(M&&!w&&(w=sn(e,t,n,s),!w))throw new ee(i.path);let b=a.map(S=>tn(e,S,r,s)),h=null;if(w){h=e.clone(w),s.templateAttr&&e.removeAttr(h,s.templateAttr);let S=e.stripIds(h);S>0&&console.warn(`[hyper-html-api] stripped ${S} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let R=nn(o,b,r),N=a[0]||w,k=e.parent(N),m=a.length>0?on(e,k,N):0,O=new Set,x=o.map((S,v)=>{let E=R[v];if(E>=0)return O.add(E),a[E];let d=e.clone(h);return e.stripIds(d),d});a.forEach((S,v)=>{O.has(v)||e.remove(S)}),x.forEach((S,v)=>{let E=m+v;e.children(k).findIndex(c=>e.sameNode(c,S))!==E&&e.insertAt(k,S,E)}),x.forEach((S,v)=>{if(r===null){let E=o[v],d=E==null?"":String(E);e.text(S)!==d&&e.text(S,d)}else{let E=u(e,S,r,o[v],{depth:i.depth+1,path:[...i.path,v]},s);E&&E!==S&&(x[v]=E)}})}function tn(e,t,n,r){return n===null?e.text(t):B(e,t,n,r)}function nn(e,t,n){let r=new Array(e.length).fill(-1),o=new Set;return e.forEach((i,u)=>{let s=-1,a=-1;t.forEach((M,w)=>{if(o.has(w))return;let b=rn(i,M,n),h=b===a&&s>=0?Math.abs(w-u)<Math.abs(s-u):!1;(b>a||h)&&(a=b,s=w)}),a>=en&&(r[u]=s,o.add(s))}),r}function rn(e,t,n){if(n===null)return e===t?1:0;let r=Object.keys(n||{});if(r.length===0)return 0;let o=0;for(let i of r)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&o++;return o/r.length}function on(e,t,n){let r=e.children(t);for(let o=0;o<r.length;o++)if(e.sameNode(r[o],n))return o;return-1}function sn(e,t,n,r){if(!r.templateAttr)return null;let o=t;for(;o;){let i=e.find(o,n,{includeRulesTag:!1,templateAttr:null});for(let u of i)if(e.attr(u,r.templateAttr)!=null)return u;o=e.parent(o)}return null}var ft=new Set(["checked","selected","disabled","readOnly","paused"]);function W(e,t,n,r,o={}){let i=[];if(Be(n,r,[],i),i.length)throw new Z(i);ye(e,t,n,r,{depth:0,path:[]},o)}function ye(e,t,n,r,o,i={}){if(o.depth>Y)throw new q(o.path);if(r===void 0)return t;if(typeof n=="string")return an(e,t,n,r,o,i);if(Array.isArray(n)){let[u,s]=n;return $e(e,t,u,s,r,o,ye,i),t}if(typeof n=="object"&&n!==null){for(let[u,s]of Object.entries(n)){let a=ye(e,t,s,r==null?r:r[u],{depth:o.depth+1,path:[...o.path,u]},i);a&&a!==t&&(t=a)}return t}return t}function an(e,t,n,r,o,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return $e(e,t,s,null,r,o,ye,i),t}if(n.startsWith("@"))return dt(e,t,n.slice(1),r);if(n.includes("@")){let s=n.lastIndexOf("@"),a=n.slice(0,s),M=n.slice(s+1),w=a?e.find(t,a,i):[t];return w.length===0||dt(e,w[0],M,r),t}if(n===".")return e.text(t,r==null?"":String(r)),t;let u=e.find(t,n,i);return u.length===0||e.text(u[0],r==null?"":String(r)),t}function dt(e,t,n,r){if(ut.has(n))throw new te(n);if(n==="outerHTML"){let o=r==null?"":String(r);return e.replaceWith(t,o)}return ct.has(n)?(e.prop(t,n,cn(n,r)),t):(e.attr(t,n,r==null?"":String(r)),t)}function cn(e,t){return t==null?ft.has(e)?!1:"":ft.has(e)?!!t:t}function Be(e,t,n,r){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((o,i)=>{typeof o=="object"&&o!==null&&r.push({path:se([...n,i]),expected:"scalar",got:ie(o)})}):r.push({path:se(n),expected:"array",got:ie(t)});return}t!==null&&typeof t=="object"&&r.push({path:se(n),expected:"scalar",got:ie(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){r.push({path:se(n),expected:"array",got:ie(t)});return}let o=e[1];t.forEach((i,u)=>Be(o,i,[...n,u],r));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){r.push({path:se(n),expected:"object",got:ie(t)});return}for(let[o,i]of Object.entries(e))Be(i,t[o],[...n,o],r)}}}function ie(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function se(e){return e.join(".")}function un(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function ln(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var fn={find(e,t,n={}){let r=ln(e);if(!r||!r.querySelectorAll)return[];let o=Array.from(r.querySelectorAll(t));n.includeRulesTag||(o=o.filter(s=>!un(s)));let i=[];n.skip&&i.push(n.skip);let u=n.templateAttr===null?null:n.templateAttr||"cms-template";if(u&&i.push("["+u+"]"),i.length){let s=i.join(", ");o=o.filter(a=>!a.closest||!a.closest(s))}return o},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 r=e?e[t]:void 0;return r!==void 0?r:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let r=e.children[n]||null;e.insertBefore(t,r)},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 r=e.ownerDocument.createElement("template");r.innerHTML=t;let o=r.content.firstElementChild;if(!o)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(o,e),o},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},D=fn;var dn="_hyperHtmlApi",pn="upgrade-helper",hn="parentOrigin";function be(e=typeof location<"u"?location:null){if(!e)return!1;try{return new URLSearchParams(e.search).get(dn)===pn}catch{return!1}}function pt(e=typeof location<"u"?location:null){return e?new URLSearchParams(e.search).get(hn):null}function We({win:e,doc:t,parentOrigin:n}={}){if(e=e||(typeof window<"u"?window:null),t=t||(typeof document<"u"?document:null),!e||!t||(n=n||pt(e.location),!n))return;let r=()=>mn({win:e,doc:t,parentOrigin:n});t.readyState==="loading"?t.addEventListener("DOMContentLoaded",r,{once:!0}):r()}function mn({win:e,doc:t,parentOrigin:n}){let r;try{r=U(D,t.body)}catch(a){return Fe(e,n,a)}if(!r)return Fe(e,n,new Error("helper-mode: no rules tag in v2 document"));let o=r.rules,i=yn(t,"hyper-version"),u=!!he(),s=a=>{if(a.source!==e.parent||a.origin!==n)return;let M=a.data;if(!(!M||M.type!=="hha:upgrade-data")){e.removeEventListener("message",s);try{let w=gn({doc:t,rules:o,v1Data:M.v1Data});e.parent.postMessage({type:"hha:upgrade-result",html:w.html,summary:w.summary},n)}catch(w){Fe(e,n,w)}}};e.addEventListener("message",s),e.parent.postMessage({type:"hha:upgrade-ready",rules:o,version:i,hasTransform:u},n)}function gn({doc:e,rules:t,v1Data:n}){let r=he(),o=n,i=!1;r&&(o=r(n),i=!0);let{data:u,summary:s}=re(o,t);W(D,e.body,t,u);let a=B(D,e.body,t);return{html:`<!DOCTYPE html>
3
3
  `+e.documentElement.outerHTML,summary:{...s,transformApplied:i,appliedFieldCount:Ue(a)}}}function Fe(e,t,n){e.parent.postMessage({type:"hha:upgrade-error",name:n?.name||"Error",message:n?.message||String(n)},t)}function yn(e,t){let n=e.querySelector(`meta[name="${t}"]`);return n?n.getAttribute("content"):null}function Ue(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Ue(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Ue(n),0):1}function qe(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let r=t&&t.ownerDocument?t.ownerDocument:t;return U(e,r,n)}return null}function ht(e,t,n,r){let o=qe(e,t,n);if(!o){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:u}=o;return{rules:i,tagNode:u,get:()=>B(e,t,i,r),set:s=>W(e,t,i,s,r)}}var ae={extract:(e,t,n)=>B(D,e,t,n),apply:(e,t,n,r)=>W(D,e,t,n,r),findRulesIn:(e,t)=>U(D,e,t),findRules:(e,t)=>qe(D,e,t),bind:(e,t,n)=>ht(D,e,t,n),parseStrict:De,parseRelaxed:oe,errors:pe,DOM_PROPERTIES:ge},Ve=e=>!!e&&typeof e.nodeType=="number";function mt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=D.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return U(D,t).rules}function Ke(e,t){let n=Ve(e)?e:document,r=Ve(e)?t:e;return r===void 0?B(D,n,mt(n)):ae.bind(n,r).get()}function ze(e,t,n){if(!Ve(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?W(D,e,mt(e),t):ae.bind(e,n).set(t),e}var gt={buildForm:we,bindFormEvents:Te,scaffold:z,morphForm:Ie,path:le},yt={registerUpgrade:Le,run:Pe,shapeMatch:re,isHelperMode:be};typeof window<"u"&&be(window.location)&&We({win:window,doc:document});var Mn={engine:ae,cms:gt,upgrade:yt,extractData:Ke,applyData:ze},En=Mn;return St(Sn);})();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "apply",
10
10
  "CMS"
11
11
  ],
12
- "version": "0.3.0",
12
+ "version": "0.4.0",
13
13
  "homepage": "https://github.com/panphora/hyper-html-api",
14
14
  "bugs": {
15
15
  "url": "https://github.com/panphora/hyper-html-api/issues"
@@ -18,7 +18,12 @@ const cheerioAdapter = {
18
18
  if (!opts.includeRulesTag) matches = matches.filter((n) => !isRulesTag(n))
19
19
  const skipParts = []
20
20
  if (opts.skip) skipParts.push(opts.skip)
21
- if (opts.templateAttr) skipParts.push('[' + opts.templateAttr + ']')
21
+ // The cms-template seed marker means "not data" for EVERY consumer, so skip
22
+ // it by DEFAULT (not just when a caller opts in). Pass templateAttr:null to
23
+ // include seed elements — used by the grow-from-zero fallback lookup, which
24
+ // must still see the seed to clone it.
25
+ const tplAttr = opts.templateAttr === null ? null : (opts.templateAttr || 'cms-template')
26
+ if (tplAttr) skipParts.push('[' + tplAttr + ']')
22
27
  if (skipParts.length) {
23
28
  const combined = skipParts.join(', ')
24
29
  matches = matches.filter((n) => !n.closest || n.closest(combined).length === 0)
@@ -18,7 +18,12 @@ const dom = {
18
18
  if (!opts.includeRulesTag) all = all.filter((n) => !isRulesTag(n))
19
19
  const skipParts = []
20
20
  if (opts.skip) skipParts.push(opts.skip)
21
- if (opts.templateAttr) skipParts.push('[' + opts.templateAttr + ']')
21
+ // The cms-template seed marker means "not data" for EVERY consumer, so skip
22
+ // it by DEFAULT (not just when a caller opts in). Pass templateAttr:null to
23
+ // include seed elements — used by the grow-from-zero fallback lookup, which
24
+ // must still see the seed to clone it.
25
+ const tplAttr = opts.templateAttr === null ? null : (opts.templateAttr || 'cms-template')
26
+ if (tplAttr) skipParts.push('[' + tplAttr + ']')
22
27
  if (skipParts.length) {
23
28
  const combined = skipParts.join(', ')
24
29
  all = all.filter((n) => !n.closest || !n.closest(combined))
@@ -157,7 +157,9 @@ function findFallbackTemplate(adapter, parentCtx, selector, opts) {
157
157
  if (!opts.templateAttr) return null
158
158
  let scope = parentCtx
159
159
  while (scope) {
160
- const candidates = adapter.find(scope, selector, { includeRulesTag: false })
160
+ // templateAttr:null opts out of the adapter's default cms-template skip — the
161
+ // fallback lookup MUST see the seed element to clone it for grow-from-zero.
162
+ const candidates = adapter.find(scope, selector, { includeRulesTag: false, templateAttr: null })
161
163
  for (const n of candidates) {
162
164
  if (adapter.attr(n, opts.templateAttr) != null) return n
163
165
  }