hyper-html-api 0.2.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.
- package/dist/hyper-html-api.engine.min.js +1 -0
- package/dist/hyper-html-api.min.js +3 -3
- package/package.json +5 -3
- package/src/adapters/cheerio.js +6 -1
- package/src/adapters/dom.js +6 -1
- package/src/data.js +10 -0
- package/src/dom-api.js +60 -0
- package/src/engine/diff.js +3 -1
- package/src/hyper-html-api.js +6 -19
|
@@ -0,0 +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,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
|
-
var HyperHtmlApi=(()=>{var Ee=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var gt=Object.prototype.hasOwnProperty;var Se=(e,t)=>{for(var r in t)Ee(e,r,{get:t[r],enumerable:!0})},yt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of mt(t))!gt.call(e,o)&&o!==r&&Ee(e,o,{get:()=>t[o],enumerable:!(n=ht(t,o))||n.enumerable});return e};var bt=e=>yt(Ee({},"__esModule",{value:!0}),e);var yr={};Se(yr,{cms:()=>dt,default:()=>gr,engine:()=>ft,upgrade:()=>pt});var ce=["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"],ve=new Set(ce),Ke=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),ze=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var ue={};Se(ue,{EmptyListInsert:()=>Z,MAX_RULE_DEPTH:()=>J,MaxRuleDepthExceeded:()=>U,RuleTargetReadOnly:()=>ee,RulesParseError:()=>z,ShapeMismatch:()=>X,UnknownRulesVersion:()=>Q,UpgradeAlreadyRegistered:()=>te});var z=class extends Error{constructor(t,r){super(t),this.name="RulesParseError",this.cause=r}},Q=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},J=20,U=class extends Error{constructor(t){super(`rule depth exceeded ${J} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},X=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Z=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}},ee=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},te=class extends Error{constructor(){super("upgrade transform already registered; only one registration is allowed per page."),this.name="UpgradeAlreadyRegistered"}};function B(e,t,r,n={}){return xe(e,t,r,{depth:0,path:[]},n)}function xe(e,t,r,n,o){if(n.depth>J)throw new U(n.path);if(typeof r=="string")return At(e,t,r,o);if(Array.isArray(r)){let[i,u]=r;return e.find(t,i,o).map((a,M)=>xe(e,a,u,{depth:n.depth+1,path:[...n.path,M]},o))}if(typeof r=="object"&&r!==null){let i={};for(let[u,s]of Object.entries(r))i[u]=xe(e,t,s,{depth:n.depth+1,path:[...n.path,u]},o);return i}return null}function At(e,t,r,n){if(r.endsWith("[]")){let i=r.slice(0,-2);return e.find(t,i,n).map(u=>e.text(u))}if(r.startsWith("@"))return Je(e,t,r.slice(1));if(r.includes("@")){let i=r.lastIndexOf("@"),u=r.slice(0,i),s=r.slice(i+1),a=u?e.find(t,u,n):[t];return a.length===0?null:Je(e,a[0],s)}if(r===".")return e.text(t);let o=e.find(t,r,n);return o.length===0?null:e.text(o[0])}function Je(e,t,r){if(ve.has(r)){let o=e.prop(t,r);return o==null?null:String(o)}let n=e.attr(t,r);return n||null}var Mt=.5;function we(e,t,r,n,o,i,u,s={}){let a=e.find(t,r,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=wt(e,t,r,s),!w))throw new Z(i.path);let b=a.map(S=>Et(e,S,n,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=St(o,b,n),N=a[0]||w,k=e.parent(N),m=a.length>0?xt(e,k,N):0,O=new Set,v=o.map((S,x)=>{let E=R[x];if(E>=0)return O.add(E),a[E];let d=e.clone(h);return e.stripIds(d),d});a.forEach((S,x)=>{O.has(x)||e.remove(S)}),v.forEach((S,x)=>{let E=m+x;e.children(k).findIndex(c=>e.sameNode(c,S))!==E&&e.insertAt(k,S,E)}),v.forEach((S,x)=>{if(n===null){let E=o[x],d=E==null?"":String(E);e.text(S)!==d&&e.text(S,d)}else{let E=u(e,S,n,o[x],{depth:i.depth+1,path:[...i.path,x]},s);E&&E!==S&&(v[x]=E)}})}function Et(e,t,r,n){return r===null?e.text(t):B(e,t,r,n)}function St(e,t,r){let n=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=vt(i,M,r),h=b===a&&s>=0?Math.abs(w-u)<Math.abs(s-u):!1;(b>a||h)&&(a=b,s=w)}),a>=Mt&&(n[u]=s,o.add(s))}),n}function vt(e,t,r){if(r===null)return e===t?1:0;let n=Object.keys(r||{});if(n.length===0)return 0;let o=0;for(let i of n)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&o++;return o/n.length}function xt(e,t,r){let n=e.children(t);for(let o=0;o<n.length;o++)if(e.sameNode(n[o],r))return o;return-1}function wt(e,t,r,n){if(!n.templateAttr)return null;let o=t;for(;o;){let i=e.find(o,r,{includeRulesTag:!1});for(let u of i)if(e.attr(u,n.templateAttr)!=null)return u;o=e.parent(o)}return null}var Ye=new Set(["checked","selected","disabled","readOnly","paused"]);function W(e,t,r,n,o={}){let i=[];if(Te(r,n,[],i),i.length)throw new X(i);le(e,t,r,n,{depth:0,path:[]},o)}function le(e,t,r,n,o,i={}){if(o.depth>J)throw new U(o.path);if(n===void 0)return t;if(typeof r=="string")return Tt(e,t,r,n,o,i);if(Array.isArray(r)){let[u,s]=r;return we(e,t,u,s,n,o,le,i),t}if(typeof r=="object"&&r!==null){for(let[u,s]of Object.entries(r)){let a=le(e,t,s,n==null?n:n[u],{depth:o.depth+1,path:[...o.path,u]},i);a&&a!==t&&(t=a)}return t}return t}function Tt(e,t,r,n,o,i){if(r.endsWith("[]")){let s=r.slice(0,-2);return we(e,t,s,null,n,o,le,i),t}if(r.startsWith("@"))return Ge(e,t,r.slice(1),n);if(r.includes("@")){let s=r.lastIndexOf("@"),a=r.slice(0,s),M=r.slice(s+1),w=a?e.find(t,a,i):[t];return w.length===0||Ge(e,w[0],M,n),t}if(r===".")return e.text(t,n==null?"":String(n)),t;let u=e.find(t,r,i);return u.length===0||e.text(u[0],n==null?"":String(n)),t}function Ge(e,t,r,n){if(ze.has(r))throw new ee(r);if(r==="outerHTML"){let o=n==null?"":String(n);return e.replaceWith(t,o)}return Ke.has(r)?(e.prop(t,r,Rt(r,n)),t):(e.attr(t,r,n==null?"":String(n)),t)}function Rt(e,t){return t==null?Ye.has(e)?!1:"":Ye.has(e)?!!t:t}function Te(e,t,r,n){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((o,i)=>{typeof o=="object"&&o!==null&&n.push({path:ne([...r,i]),expected:"scalar",got:re(o)})}):n.push({path:ne(r),expected:"array",got:re(t)});return}t!==null&&typeof t=="object"&&n.push({path:ne(r),expected:"scalar",got:re(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){n.push({path:ne(r),expected:"array",got:re(t)});return}let o=e[1];t.forEach((i,u)=>Te(o,i,[...r,u],n));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){n.push({path:ne(r),expected:"object",got:re(t)});return}for(let[o,i]of Object.entries(e))Te(i,t[o],[...r,o],n)}}}function re(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function ne(e){return e.join(".")}function Re(e){try{return JSON.parse(e)}catch(t){throw new z(`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 r(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 n(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=r(e),i=n(o);return JSON.parse(i)}catch(o){throw new z("Invalid extraction rules syntax: "+o.message,o)}}var Nt="1",Qe=/^[a-zA-Z0-9_-]+$/;function q(e,t,r){let n;if(r===void 0)n="script[data-rules-name]";else{if(typeof r!="string"||!Qe.test(r))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(r)} (must match ${Qe})`);n=`script[data-rules-name~="${r}"]`}let o=e.find(t,n,{includeRulesTag:!0});if(o.length===0)return null;r!==void 0&&o.length>1&&console.warn(`hyper-html-api: ${o.length} rules tags match data-rules-name~="${r}"; using the first.`);let i=o[0],u=e.attr(i,"data-rules-version");if(u!==Nt)throw new Q(u);return{rules:oe(e.text(i)),tagNode:i}}function Ne(e,t,r){if(r&&typeof r=="object")return{rules:r,tagNode:null};if(typeof r=="string"){let n=t&&t.ownerDocument?t.ownerDocument:t;return q(e,n,r)}return null}function Xe(e,t,r,n){let o=Ne(e,t,r);if(!o){let s=typeof r=="string"?`data-rules-name~="${r}"`:"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,n),set:s=>W(e,t,i,s,n)}}var de={};Se(de,{fromString:()=>fe,getRuleAtPath:()=>Oe,getValueAtPath:()=>ie,parseConfigKey:()=>kt,setAtPath:()=>F,toConfigKey:()=>It,toString:()=>_});function _(e){return e.map(String).join(".")}function It(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function kt(e){return e===""?[]:e.split(".")}function fe(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function Oe(e,t){let r=e;for(let n of t){if(r==null||typeof r=="string")return;if(Array.isArray(r)){if(typeof n!="number"&&n!=="*")return;r=r[1];continue}if(typeof r=="object"){if(typeof n=="number"||!(n in r))return;r=r[n];continue}return}return r}function ie(e,t){let r=e;for(let n of t){if(r==null)return;r=r[n]}return r}function F(e,t,r){if(t.length===0)return r;let[n,...o]=t;if(typeof n=="number"){let i=Array.isArray(e)?[...e]:[];return i[n]=F(i[n],o,r),i}return{...e&&typeof e=="object"?e:{},[n]:F((e||{})[n],o,r)}}function Y(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[r,n]of Object.entries(e))t[r]=Y(n);return t}return""}var pe=new WeakMap;var Lt=new Set(["checked","selected","disabled","readOnly","paused"]);function Ie({rules:e,data:t,appRoot:r,cmsRoot:n}){let o=document.createDocumentFragment(),i={rules:e,appRoot:r,cmsRoot:n};return o.appendChild(Le({rule:e,value:t,path:[],ctx:i})),o}function ke(e,{rules:t,getData:r,onChange:n}){e.setAttribute("data-hha-form-root",""),tt.set(e,{rules:t,getData:r,onChange:n}),Ct()}var tt=new WeakMap,Ze=!1;function Ct(){Ze||(document.addEventListener("input",et,!0),document.addEventListener("change",et,!0),document.addEventListener("click",Ht,!0),Ze=!0)}function rt(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&tt.get(t)||null}function Ht(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let r=rt(t);if(!r)return;let{rules:n,getData:o,onChange:i}=r,u=t.getAttribute("data-hha-action"),s=fe(t.getAttribute("data-hha-path")||"");if(u==="scalar-array-add"){let a=ie(o(),s)||[];i(F(o(),s,[...a,""]),{structural:!0});return}if(u==="object-array-add"){let a=Oe(n,s);if(!Array.isArray(a))return;let M=ie(o(),s)||[];i(F(o(),s,[...M,Y(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=ie(o(),a)||[];if(typeof M!="number")return;let b=w.filter((h,R)=>R!==M);i(F(o(),a,b),{structural:!0})}}function et(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let r=rt(t);if(!r)return;let{getData:n,onChange:o}=r,i=t.closest("[data-hha-path]");if(!i)return;let u=fe(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;o(F(n(),u,s),{structural:!1})}function Le({rule:e,value:t,path:r,ctx:n}){if(typeof e=="string")return e.endsWith("[]")?Dt({rule:e,value:t,path:r,ctx:n}):_t({rule:e,value:t,path:r,ctx:n});if(Array.isArray(e))return jt({rule:e,value:t,path:r,ctx:n});if(typeof e=="object"&&e!==null)return Pt({rule:e,value:t,path:r,ctx:n});let o=document.createElement("span");return o.textContent="(unsupported rule)",o}function Pt({rule:e,value:t,path:r,ctx:n}){let o=document.createElement("div");if(o.className="form-section",o.setAttribute("data-hha-path",_(r)),r.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=he(r[r.length-1]),o.appendChild(i)}for(let[i,u]of Object.entries(e)){let s=[...r,i],a=t?.[i];o.appendChild(Le({rule:u,value:a,path:s,ctx:n}))}return o}function _t({rule:e,value:t,path:r,ctx:n}){let o=document.createElement("div");o.className="field-row",o.setAttribute("data-hha-path",_(r));let i=document.createElement("div");i.className="field-body";let u=document.createElement("label");u.className="field-label",u.textContent=he(r[r.length-1]||".")+Wt(e);let s=Bt(e,n.appRoot),a=$t(s,{value:t,rule:e,path:r,appRoot:n.appRoot}),M=a.el;return M.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(u),i.appendChild(M),o.appendChild(i),pe.set(o,a),o}function Dt({rule:e,value:t,path:r,ctx:n}){let o=document.createElement("div");o.className="form-section",o.setAttribute("data-hha-path",_(r));let i=document.createElement("div");i.className="form-section-label",i.textContent=he(r[r.length-1]),o.appendChild(i);let u=Array.isArray(t)?t:[],s=document.createElement("div");o.appendChild(s),u.forEach((M,w)=>{let b=[...r,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",_(r)),o.appendChild(a),o}function jt({rule:e,value:t,path:r,ctx:n}){let[,o]=e,i=Array.isArray(t)?t:[],u=document.createElement("div");u.className="form-section",u.setAttribute("data-hha-path",_(r));let s=document.createElement("div");s.className="form-section-label",s.textContent=he(r[r.length-1]),u.appendChild(s),i.forEach((M,w)=>{let b=[...r,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=Le({rule:o,value:M,path:b,ctx:n});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",_(r)),u.appendChild(a),u}function $t(e,t){let r=Ut(e);if(e.type==="select"&&e.options)for(let n of e.options){let o=document.createElement("option");o.value=n.value,o.textContent=n.text,String(t.value)===n.value&&(o.selected=!0),r.appendChild(o)}else e.type==="checkbox"?r.checked=t.value===!0||t.value==="true"||t.value==="checked":(e.type,r.value=t.value==null?"":String(t.value));return{el:r,destroy(){},focus(){r.focus()},validate(){}}}function Bt(e,t){let r=null;if(e.startsWith("@")?r=e.slice(1):e.includes("@")&&(r=e.split("@")[1]||null),r&&Lt.has(r))return{type:"checkbox"};if(r==="innerHTML")return{type:"textarea"};let n=Ft(e,t);if(!n)return{type:"text"};let o=(n.tagName||"").toLowerCase();if(o==="textarea")return{type:"textarea"};if(o==="select")return{type:"select",options:Array.from(n.querySelectorAll("option")).map(s=>({value:s.getAttribute("value")||s.textContent,text:s.textContent.trim()||s.getAttribute("value")||""}))};if(o==="input"){let u=(n.getAttribute("type")||"text").toLowerCase();if(u==="checkbox"||u==="radio")return{type:"checkbox"};if(u==="number")return{type:"number"}}let i=(n.textContent||"").trim();return i.length>60||i.includes(`
|
|
2
|
-
`)?{type:"textarea"}:{type:"text"}}function Ft(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let r=e.includes("@")?e.split("@")[0]:e;if(!r)return null;try{return t.querySelector(r)}catch{return null}}function Ut(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function he(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function Wt(e){return` \xB7 ${e}`}var nt={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,slotMatch:30},minConfidence:101};function qt(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t^e.charCodeAt(r);return Math.abs(t).toString(36)}function Vt(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 Kt(e,t){let r=[];for(let n of e.attributes||[]){let o=n.name;o==="id"||o==="class"||t.excludeAttributePrefixes.some(i=>o.startsWith(i))||t.includeAttributes.includes(o)&&r.push(`${o}=${n.value}`)}return r.sort().join("|")}function zt(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function Jt(e,t){let r=[e.tagName];return t.includeClasses&&r.push(Vt(e)),r.push(Kt(e,t)),qt(r.join("|"))}function Yt(e){let t=e.tagName,r=1,n=e.previousElementSibling;for(;n;)n.tagName===t&&r++,n=n.previousElementSibling;return r}function Gt(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 Xt(e,t){let r=[],n=e;for(;n&&n.tagName&&r.length<t.maxPathDepth;){let o=`${n.tagName}:${Yt(n)}`;if(r.unshift(o),n!==e&&Gt(n,t)){r.unshift(Qt(n));break}n=n.parentElement}return r}function Zt(e,t){let r=0,n=e.length-1,o=t.length-1;for(;n>=0&&o>=0&&e[n]===t[o];)r++,n--,o--;return r}function j(e,t,r){if(r.has(e))return r.get(e);let n={signature:Jt(e,t),path:Xt(e,t),textHint:zt(e,t)};return r.set(e,n),n}function at(e,t,r,n){if(n.has(e))return n.get(e);let o=new Map,i=e.querySelectorAll("*"),u=0;for(let s of i){let a=j(s,t,r);a.domIndex=u++,o.has(a.signature)||o.set(a.signature,[]),o.get(a.signature).push(s)}return n.set(e,o),o}function er(e,t,r){r.delete(e),t.delete(e);let n=e.querySelectorAll("*");for(let o of n)t.delete(o)}function Ce(e,t,r,n,o){let i=j(e,r,n),u=j(t,r,n),s=r.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=Zt(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 ot(e,t,r,n,o){if(r.excludeIds&&e.id)return null;let i=at(t,r,n,o),u=j(e,r,n);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=r.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}=Ce(e,h,r,n,{candidateCount:a.length});R>w&&(w=R,M=h,b=N)}return w<r.minConfidence?null:{element:M,confidence:w,breakdown:b}}function tr(e,t,r,n){let o=[],i=r.weights.signature+r.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(r.excludeIds&&(m.id||O.id)||m.tagName!==O.tagName)continue;let v=j(m,r,n).signature,S=j(O,r,n).signature;v!==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 it(e,t,r,n,o){let i=t.querySelectorAll("*"),u=at(e,r,n,o),s=0;for(let b of i){let h=j(b,r,n);h.domIndex=s++}let a=[];for(let b of i){if(r.excludeIds&&b.id)continue;let h=j(b,r,n),R=u.get(h.signature)||[],N=r.excludeIds?R.filter(k=>!k.id):R;for(let k of N){let{score:m,breakdown:O}=Ce(b,k,r,n,{candidateCount:N.length});m>=r.minConfidence&&a.push({newEl:b,oldEl:k,score:m,breakdown:O})}}if(r.weights.slotMatch>0){let b=tr(t,e,r,n);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 st(e,t,r,n){let o=j(e,r,n),i=j(t,r,n),{score:u,breakdown:s}=Ce(e,t,r,n,{candidateCount:1});return{matches:u>=r.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 ct(e={}){let t={...nt,...e,weights:{...nt.weights,...e.weights}},r=new WeakMap,n=new WeakMap;return{findMatch:(o,i)=>ot(o,i,t,r,n),computeMatches:(o,i)=>it(o,i,t,r,n),explain:(o,i)=>st(o,i,t,r),invalidate:o=>er(o,r,n),session:()=>{let o=new WeakMap,i=new WeakMap;return{findMatch:(u,s)=>ot(u,s,t,o,i),computeMatches:(u,s)=>it(u,s,t,o,i),explain:(u,s)=>st(u,s,t,o)}},getConfig:()=>({...t})}}var rr=ct(),He=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 r(m,O){if(O!=="smart")return m.outerHTML;let v=m.getAttribute("src"),S=m.getAttribute("type")||"text/javascript";if(v)try{let x=new URL(v,window.location.href);return`ext:${S}:${x.origin}${x.pathname}${x.search}`}catch{return`ext:${S}:${v}`}else{let x=m.textContent.trim(),E=5381;for(let d=0;d<x.length;d++)E=(E<<5)+E^x.charCodeAt(d);return`inline:${S}:${Math.abs(E).toString(36)}`}}let n={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:v}=rr.session();return v(m,O)}};function i(m,O,v={}){m=N(m);let S=k(O),x=R(m,S,v),E=x.scripts.matchMode,d=new Set(Array.from(m.querySelectorAll("script")).map(l=>r(l,E))),y=s(x,()=>w(x,m,S,l=>l.morphStyle==="innerHTML"?(a(l,m,S),Array.from(m.childNodes)):u(l,m,S)));x.pantry.remove();let c=h(m,d,x);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,v){let S=k(O);return a(m,S,v,O,O.nextSibling),Array.from(S.childNodes)}function s(m,O){if(!m.config.restoreFocus)return O();let v=document.activeElement;if(!(v instanceof HTMLInputElement||v instanceof HTMLTextAreaElement))return O();let{id:S,selectionStart:x,selectionEnd:E}=v,d=O();return S&&S!==document.activeElement?.getAttribute("id")&&(v=m.target.querySelector(`[id="${S}"]`),v?.focus()),v&&!v.selectionEnd&&E!=null&&v.setSelectionRange(x,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=v(c,A,f,g);if(I){I!==f&&x(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 v=function(){function c(f,g,A,T){let I=g instanceof Element&&!f.idMap.has(g)?f.hyperMatches.get(g):null,L=null,D=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&&D&&p(C,D)&&(G++,D=D.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 x(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)x(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(x(I.name,p,"remove",c))continue;p.removeAttribute(I.name)}}E(p,c)||v(p,f,c)}(l===8||l===3)&&d.nodeValue!==y.nodeValue&&(d.nodeValue=y.nodeValue)}function v(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&&(x("value",d,"update",c)||(d.value=l)):y.hasAttribute("value")?p!==l&&(x("value",d,"update",c)||(d.setAttribute("value",l),d.value=l)):x("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(x("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=x(c,d,"update",l);if(g||(d[c]=y[c]),l.formStateSync==="property")return;p?g||d.setAttribute(c,""):x(c,d,"remove",l)||d.removeAttribute(c)}}function x(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,v,S){if(m.head.block){let x=O.querySelector("head"),E=v.querySelector("head");if(x&&E){let d=b(x,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,v){let S=[],x=[],E=[],d=[],y=v.scripts.matchMode,c=f=>{if(f.tagName==="SCRIPT")return r(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=v.head.shouldReAppend(f),I=v.head.shouldPreserve(f);A||I?T?x.push(f):(l.delete(g),E.push(f)):v.head.style==="append"?T&&(x.push(f),d.push(f)):v.head.shouldRemove(f)!==!1&&!t(f)&&x.push(f)}d.push(...l.values());let p=[];for(let f of d){let g=document.createRange().createContextualFragment(f.outerHTML).firstChild;if(v.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),v.callbacks.afterNodeAdded(g),S.push(g)}}for(let f of x)v.callbacks.beforeNodeRemoved(f)!==!1&&(m.removeChild(f),v.callbacks.afterNodeRemoved(f));return v.head.afterHeadMorphed(m,{added:S,kept:E,removed:x}),p}function h(m,O,v){if(!v.scripts.handle)return[];let S=[],x=[],E=[],d=[],y=v.scripts.matchMode,c=Array.from(m.querySelectorAll("script"));for(let p of c){let f=r(p,y),g=O.has(f),A=v.scripts.shouldPreserve(p),T=v.scripts.shouldReAppend(p);g||A?T?(x.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(v.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),v.callbacks.afterNodeAdded(f),S.push(f)}return v.scripts.afterScriptsHandled(m,{added:S,kept:E,removed:x}),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 D=new Map,G=new Set,C=H=>{let P=p.key(H);P!=null&&(D.has(P)?G.add(P):D.set(P,H))};c instanceof Element&&C(c);for(let H of c.querySelectorAll("*"))C(H);for(let H of G)D.delete(H);let V=new Map;for(let[H,P]of A)V.set(P,H);let be=l.__hyperMorphRoot||l,ae=new Map,qe=new Set,Ve=H=>{let P=p.key(H);P!=null&&(ae.has(P)?qe.add(P):ae.set(P,H))};be instanceof Element&&Ve(be);for(let H of be.querySelectorAll("*"))Ve(H);for(let H of qe)ae.delete(H);for(let[H,P]of ae){let K=D.get(H);if(!K||K.tagName!==P.tagName)continue;let Ae=V.get(K);Ae&&Ae!==P&&A.delete(Ae);let Me=A.get(P);Me&&Me!==K&&V.delete(Me),A.set(P,K),V.set(K,P)}}let T=new Set;for(let D of A.values())T.add(D);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:v(),activeElementAndParents:S(c),callbacks:I.callbacks,head:I.head,scripts:I.scripts}}function O(c){let l=Object.assign({},n);return Object.assign(l,c),l.callbacks=Object.assign({},n.callbacks,c.callbacks),l.head=Object.assign({},n.head,c.head),l.scripts=Object.assign({},n.scripts,c.scripts),l}function v(){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 x(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=x(c),f=x(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 v(E){if(E==null)return document.createElement("div");if(typeof E=="string")return v(x(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 x(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:v}}();return{morph:i,defaults:n}}();var Qr=He.morph,Xr=He.defaults,ut=He;function Pe(e,t,{onWidgetRemoved:r}={}){ut.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(n){let o=pe.get(n);o?.destroy&&o.destroy(),r?.(n)}}})}var _e=null;function De(e){if(typeof e!="function")throw new TypeError("registerUpgrade expects a function (v1Data) => v2Data");if(_e)throw new te;_e=e}function me(){return _e}function se(e,t){let r={carriedOver:0,discarded:0,listItems:0},n=je(t,e,r);return $e(t,e,r),{data:n,summary:r}}function je(e,t,r){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(r.listItems+=t.length,r.carriedOver+=t.length,t):void 0:t==null?void 0:(r.carriedOver++,t);if(Array.isArray(e)){let[,n]=e;return Array.isArray(t)?(r.listItems+=t.length,t.map(o=>je(n,o,r))):void 0}if(typeof e=="object"&&e!==null){let n={};for(let[o,i]of Object.entries(e)){let u=je(i,t?.[o],r);u!==void 0&&(n[o]=u)}return n}}function $e(e,t,r){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let n=new Set(Object.keys(e));for(let o of Object.keys(t))n.has(o)?$e(e[o],t[o],r):r.discarded+=ge(t[o]);return}if(Array.isArray(e)&&Array.isArray(t)){let n=e[1];t.forEach(o=>$e(n,o,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=ge(t))}}function ge(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+ge(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+ge(r),0):1}async function Be({sourceUrl:e,v1Data:t,v1Version:r=null,parent:n=typeof window<"u"?window:null,timeoutMs:o=15e3,hidden:i=!0}={}){if(!n)throw new Error("upgrade.run requires a window context");if(!e)throw new Error("upgrade.run requires sourceUrl");let u=or(e,n.location.origin),s=new URL(u,n.location.href).origin,a=n.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,n.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:r},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}}};n.addEventListener("message",R),M=()=>{n.removeEventListener("message",R),clearTimeout(h),a.parentNode&&a.parentNode.removeChild(a)}})}finally{M()}}function or(e,t){let r=new URL(e,typeof location<"u"?location.href:void 0);return r.searchParams.set("_hyperHtmlApi","upgrade-helper"),r.searchParams.set("parentOrigin",t),r.toString()}function ir(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function sr(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var ar={find(e,t,r={}){let n=sr(e);if(!n||!n.querySelectorAll)return[];let o=Array.from(n.querySelectorAll(t));r.includeRulesTag||(o=o.filter(u=>!ir(u)));let i=[];if(r.skip&&i.push(r.skip),r.templateAttr&&i.push("["+r.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,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,r){if(r===void 0){let n=e?e[t]:void 0;return n!==void 0?n:null}e[t]=r},clone(e){return e.cloneNode(!0)},insertAt(e,t,r){let n=e.children[r]||null;e.insertBefore(t,n)},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 n=e.ownerDocument.createElement("template");n.innerHTML=t;let o=n.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(n=>{n.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},$=ar;var cr="_hyperHtmlApi",ur="upgrade-helper",lr="parentOrigin";function ye(e=typeof location<"u"?location:null){if(!e)return!1;try{return new URLSearchParams(e.search).get(cr)===ur}catch{return!1}}function lt(e=typeof location<"u"?location:null){return e?new URLSearchParams(e.search).get(lr):null}function We({win:e,doc:t,parentOrigin:r}={}){if(e=e||(typeof window<"u"?window:null),t=t||(typeof document<"u"?document:null),!e||!t||(r=r||lt(e.location),!r))return;let n=()=>fr({win:e,doc:t,parentOrigin:r});t.readyState==="loading"?t.addEventListener("DOMContentLoaded",n,{once:!0}):n()}function fr({win:e,doc:t,parentOrigin:r}){let n;try{n=q($,t.body)}catch(a){return Fe(e,r,a)}if(!n)return Fe(e,r,new Error("helper-mode: no rules tag in v2 document"));let o=n.rules,i=pr(t,"hyper-version"),u=!!me(),s=a=>{if(a.source!==e.parent||a.origin!==r)return;let M=a.data;if(!(!M||M.type!=="hha:upgrade-data")){e.removeEventListener("message",s);try{let w=dr({doc:t,rules:o,v1Data:M.v1Data});e.parent.postMessage({type:"hha:upgrade-result",html:w.html,summary:w.summary},r)}catch(w){Fe(e,r,w)}}};e.addEventListener("message",s),e.parent.postMessage({type:"hha:upgrade-ready",rules:o,version:i,hasTransform:u},r)}function dr({doc:e,rules:t,v1Data:r}){let n=me(),o=r,i=!1;n&&(o=n(r),i=!0);let{data:u,summary:s}=se(o,t);W($,e.body,t,u);let a=B($,e.body,t);return{html:`<!DOCTYPE html>
|
|
3
|
-
`+e.documentElement.outerHTML,summary:{...s,transformApplied:i,appliedFieldCount:Ue(a)}}}function Fe(e,t,
|
|
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,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
|
+
`+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.
|
|
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"
|
|
@@ -29,12 +29,14 @@
|
|
|
29
29
|
"./engine": "./src/engine/index.js",
|
|
30
30
|
"./cms": "./src/cms/index.js",
|
|
31
31
|
"./cheerio": "./src/adapters/cheerio.js",
|
|
32
|
-
"./dom": "./src/adapters/dom.js"
|
|
32
|
+
"./dom": "./src/adapters/dom.js",
|
|
33
|
+
"./data": "./src/data.js"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "npx esbuild src/hyper-html-api.js --bundle --minify --format=iife --global-name=HyperHtmlApi --outfile=dist/hyper-html-api.min.js",
|
|
37
|
+
"build:engine": "npx esbuild src/data.js --bundle --minify --format=iife --global-name=hyperHtmlApiData --outfile=dist/hyper-html-api.engine.min.js",
|
|
38
|
+
"copy-to-hyperclayjs": "npm run build:engine && node scripts/copy-to-hyperclayjs.js",
|
|
36
39
|
"prepublishOnly": "npm run build",
|
|
37
|
-
"copy-to-hyperclayjs": "npm run build && node scripts/copy-to-hyperclayjs.js",
|
|
38
40
|
"demo": "http-server . -p 5693 -c-1 -o /demo/",
|
|
39
41
|
"test": "web-test-runner",
|
|
40
42
|
"test:debug": "web-test-runner --manual --open",
|
package/src/adapters/cheerio.js
CHANGED
|
@@ -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
|
-
|
|
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)
|
package/src/adapters/dom.js
CHANGED
|
@@ -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
|
-
|
|
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))
|
package/src/data.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Lean data entry: the DOM-bound engine + the data sugar, WITHOUT cms/upgrade.
|
|
2
|
+
// This is what `hyper-html-api/data` exports and what hyperclayjs vendors, so
|
|
3
|
+
// the `window.hyperclay.extractData/applyData` feature stays small (data
|
|
4
|
+
// extract/apply is a core primitive, not a cms one).
|
|
5
|
+
import { engine, extractData, applyData } from './dom-api.js'
|
|
6
|
+
|
|
7
|
+
export { engine, extractData, applyData }
|
|
8
|
+
|
|
9
|
+
const HyperHtmlApiData = { engine, extractData, applyData }
|
|
10
|
+
export default HyperHtmlApiData
|
package/src/dom-api.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as engineMod from './engine/index.js'
|
|
2
|
+
import domAdapter from './adapters/dom.js'
|
|
3
|
+
|
|
4
|
+
// The DOM-bound engine: every engine call pre-wired with the DOM adapter. Lives
|
|
5
|
+
// here (instead of inline in hyper-html-api.js) so both the full CDN bundle and
|
|
6
|
+
// the lean `data.js` entry share one definition.
|
|
7
|
+
export const engine = {
|
|
8
|
+
extract: (root, rules, opts) => engineMod.extract(domAdapter, root, rules, opts),
|
|
9
|
+
apply: (root, rules, data, opts) => engineMod.apply(domAdapter, root, rules, data, opts),
|
|
10
|
+
findRulesIn: (root, token) => engineMod.findRulesIn(domAdapter, root, token),
|
|
11
|
+
findRules: (root, source) => engineMod.resolveRules(domAdapter, root, source),
|
|
12
|
+
bind: (root, source, opts) => engineMod.bind(domAdapter, root, source, opts),
|
|
13
|
+
parseStrict: engineMod.parseStrict,
|
|
14
|
+
parseRelaxed: engineMod.parseRelaxed,
|
|
15
|
+
errors: engineMod.errors,
|
|
16
|
+
DOM_PROPERTIES: engineMod.DOM_PROPERTIES,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const isNode = (x) => !!x && typeof x.nodeType === 'number'
|
|
20
|
+
|
|
21
|
+
// Autodetect the page's single rules tag when no `source` is given.
|
|
22
|
+
// engine.findRulesIn(root) (no token) silently takes the FIRST of many tags, so
|
|
23
|
+
// the sugar counts the tags itself to enforce the one-tag rule with clear,
|
|
24
|
+
// distinct errors for "none" vs "multiple".
|
|
25
|
+
function autodetect(root) {
|
|
26
|
+
const searchRoot = (root && root.ownerDocument) ? root.ownerDocument : root
|
|
27
|
+
const tags = domAdapter.find(searchRoot, 'script[data-rules-name]', { includeRulesTag: true })
|
|
28
|
+
if (tags.length === 0) {
|
|
29
|
+
throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="…" data-rules-version="1"> or pass rules.')
|
|
30
|
+
}
|
|
31
|
+
if (tags.length > 1) {
|
|
32
|
+
throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").')
|
|
33
|
+
}
|
|
34
|
+
// findRulesIn (no token) returns the one tag's rules and enforces data-rules-version="1".
|
|
35
|
+
return engineMod.findRulesIn(domAdapter, searchRoot).rules
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// extractData() → document + autodetect
|
|
39
|
+
// extractData(el) → el + autodetect
|
|
40
|
+
// extractData('api' | {title:'h1'}) → document + named/inline rules
|
|
41
|
+
// extractData(el, 'api' | {...}) → explicit root + source
|
|
42
|
+
// One-shot read; returns the extracted data.
|
|
43
|
+
export function extractData(a, b) {
|
|
44
|
+
const root = isNode(a) ? a : document
|
|
45
|
+
const source = isNode(a) ? b : a
|
|
46
|
+
if (source === undefined) return engineMod.extract(domAdapter, root, autodetect(root))
|
|
47
|
+
return engine.bind(root, source).get()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// applyData(root, data, source?) — writes `data` INTO the live DOM under `root`,
|
|
51
|
+
// using a named/inline `source` or (when omitted) the page's single rules tag.
|
|
52
|
+
// MUTATES the DOM and returns `root`.
|
|
53
|
+
export function applyData(root, data, source) {
|
|
54
|
+
if (!isNode(root)) {
|
|
55
|
+
throw new Error('hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.')
|
|
56
|
+
}
|
|
57
|
+
if (source === undefined) engineMod.apply(domAdapter, root, autodetect(root), data)
|
|
58
|
+
else engine.bind(root, source).set(data)
|
|
59
|
+
return root
|
|
60
|
+
}
|
package/src/engine/diff.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/hyper-html-api.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import * as engineMod from './engine/index.js'
|
|
2
1
|
import * as cmsMod from './cms/index.js'
|
|
3
2
|
import * as upgradeMod from './upgrade/index.js'
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
const engine = {
|
|
7
|
-
extract: (root, rules, opts) => engineMod.extract(domAdapter, root, rules, opts),
|
|
8
|
-
apply: (root, rules, data, opts) => engineMod.apply(domAdapter, root, rules, data, opts),
|
|
9
|
-
findRulesIn: (root, token) => engineMod.findRulesIn(domAdapter, root, token),
|
|
10
|
-
findRules: (root, source) => engineMod.resolveRules(domAdapter, root, source),
|
|
11
|
-
bind: (root, source, opts) => engineMod.bind(domAdapter, root, source, opts),
|
|
12
|
-
parseStrict: engineMod.parseStrict,
|
|
13
|
-
parseRelaxed: engineMod.parseRelaxed,
|
|
14
|
-
errors: engineMod.errors,
|
|
15
|
-
DOM_PROPERTIES: engineMod.DOM_PROPERTIES,
|
|
16
|
-
}
|
|
3
|
+
import { engine, extractData, applyData } from './dom-api.js'
|
|
17
4
|
|
|
18
5
|
const cms = {
|
|
19
6
|
buildForm: cmsMod.buildForm,
|
|
@@ -39,10 +26,10 @@ if (typeof window !== 'undefined' && upgradeMod.isHelperMode(window.location)) {
|
|
|
39
26
|
upgradeMod.bootHelper({ win: window, doc: document })
|
|
40
27
|
}
|
|
41
28
|
|
|
42
|
-
// Named exports ensure the IIFE namespace exposes engine/cms/upgrade
|
|
43
|
-
// properties on the `HyperHtmlApi` global, rather than
|
|
44
|
-
// `.default` key the way `export default` alone would.
|
|
45
|
-
export { engine, cms, upgrade }
|
|
29
|
+
// Named exports ensure the IIFE namespace exposes engine/cms/upgrade and the
|
|
30
|
+
// data sugar as direct properties on the `HyperHtmlApi` global, rather than
|
|
31
|
+
// nesting them under a `.default` key the way `export default` alone would.
|
|
32
|
+
export { engine, cms, upgrade, extractData, applyData }
|
|
46
33
|
|
|
47
|
-
const HyperHtmlApi = { engine, cms, upgrade }
|
|
34
|
+
const HyperHtmlApi = { engine, cms, upgrade, extractData, applyData }
|
|
48
35
|
export default HyperHtmlApi
|