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