hyper-html-api 0.6.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +14 -11
- package/README.md +2 -2
- 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 -4
- package/src/engine/apply.js +14 -2
- package/src/engine/diff.js +67 -54
- package/src/engine/extract.js +26 -3
- package/src/engine/row-match.js +155 -0
package/LICENSE
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
=============
|
|
1
|
+
MIT No Attribution
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
any purpose with or without fee is hereby granted.
|
|
3
|
+
Copyright (c) 2026 David Miranda
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
6
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
7
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
8
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
permit persons to whom the Software is furnished to do so.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
12
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
13
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
14
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
15
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
16
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Self-describing data layer for HTML files — a bidirectional engine that reads structured data out of an HTML page and writes structured data back into it, driven by a single declarative rules tag.
|
|
4
4
|
|
|
5
|
-
Runs in production behind [
|
|
5
|
+
Runs in production behind [Hyperclay™](https://hyperclay.com), Hyperclay Local, and [`@panphora/hyper-cms`](https://github.com/panphora/hypercms), and is vendored into [hyperclayjs](https://github.com/panphora/hyperclayjs) and [clayjs](https://clayjs.com). The same rules run in the browser and in Node under cheerio, through a pluggable adapter.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -122,4 +122,4 @@ const data = extract(cheerioAdapter, $.root(), rules)
|
|
|
122
122
|
|
|
123
123
|
## License
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
MIT-0 (MIT No Attribution).
|
|
@@ -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 q=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var Ot=Object.prototype.hasOwnProperty;var nt=(t,e)=>{for(var n in e)q(t,n,{get:e[n],enumerable:!0})},wt=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of At(e))!Ot.call(t,r)&&r!==n&&q(t,r,{get:()=>e[r],enumerable:!(o=Rt(e,r))||o.enumerable});return t};var St=t=>wt(q({},"__esModule",{value:!0}),t);var vt={};nt(vt,{applyData:()=>et,default:()=>Ut,engine:()=>k,extractData:()=>tt});var W=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],F=new Set(W),rt=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),ot=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var B={};nt(B,{EmptyListInsert:()=>P,MAX_RULE_DEPTH:()=>b,MaxRuleDepthExceeded:()=>S,RuleTargetReadOnly:()=>j,RulesParseError:()=>T,ShapeMismatch:()=>D,UnknownRulesVersion:()=>_});var T=class extends Error{constructor(e,n){super(e),this.name="RulesParseError",this.cause=n}},_=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=e}},b=20,S=class extends Error{constructor(e){super(`rule depth exceeded ${b} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},D=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},P=class extends Error{constructor(e){super(`cannot add items to empty list at "${e.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=e}},j=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}};function A(t){let e=0,n=null,o=-1;for(let r=0;r<t.length;r++){let i=t[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?e++:i==="]"||i===")"?e>0&&e--:i==="@"&&e===0&&(o=r)}return o}function K(t){let e=A(t);return e===-1?{selector:t,prop:null}:{selector:t.slice(0,e),prop:t.slice(e+1)||null}}function O(t,e,n,o={}){return G(t,e,n,{depth:0,path:[]},o)}function G(t,e,n,o,r){if(o.depth>b)throw new S(o.path);if(typeof n=="string")return xt(t,e,n,o,r);if(Array.isArray(n)){let[i,f]=n,s=t.find(e,i,r);return st(r,o,s),s.map((l,c)=>G(t,l,f,{depth:o.depth+1,path:[...o.path,c]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[f,s]of Object.entries(n))i[f]=G(t,e,s,{depth:o.depth+1,path:[...o.path,f]},r);return i}return null}function xt(t,e,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),l=t.find(e,s,r);return st(r,o,l),l.map(c=>t.text(c))}if(n.startsWith("@"))return it(t,e,n.slice(1));let i=A(n);if(i!==-1){let s=n.slice(0,i),l=n.slice(i+1),c=s?t.find(e,s,r):[e];return c.length===0?null:it(t,c[0],l)}if(n===".")return t.text(e);let f=t.find(e,n,r);return f.length===0?null:t.text(f[0])}function st(t,e,n){if(typeof t.onRowsRead=="function")try{t.onRowsRead(e.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${e.path.join(".")||"(root)"}"`,o)}}function it(t,e,n){if(F.has(n)){let r=t.prop(e,n);return r==null?null:String(r)}let o=t.attr(e,n);return o||null}function ct(t,e,n,o){let r=t.length,i=e.length,f=new Array(r).fill(-1);if(o){let u=new Set;for(let d=0;d<r;d++){let g=o[d];!(g>=0&&g<i)||u.has(g)||(f[d]=g,u.add(g))}}if(r===0||i===0)return f;let s=t.map(u=>lt(u,n)),l=e.map(u=>lt(u,n)),c=new Array(i).fill(!1);for(let u of f)u>=0&&(c[u]=!0);let p=new Map;l.forEach((u,d)=>{c[d]||p.set(u,p.has(u)?-1:d)});let a=new Map;s.forEach((u,d)=>{f[d]>=0||a.set(u,(a.get(u)||0)+1)}),s.forEach((u,d)=>{if(f[d]>=0||a.get(u)!==1)return;let g=p.get(u);g===void 0||g===-1||c[g]||(f[d]=g,c[g]=!0)});let h=[];for(let u=0;u<r;u++)f[u]<0&&h.push(u);let E=[];for(let u=0;u<i;u++)c[u]||E.push(u);if(h.length===0||E.length===0)return f;let y=r*i+1,w=(u,d)=>Tt(t[u],e[d],n)*y+Math.abs(u-d);for(let[u,d]of bt(h,E,w))f[u]=d;return f}var ut=t=>typeof t=="object"&&t!==null;function lt(t,e){if(!ut(e))return t==null?" null":String(t);let n=Object.keys(e);return JSON.stringify(n.map(o=>{let r=JSON.stringify(t?.[o]);return r===void 0?" undef":r}))}function Tt(t,e,n){if(!ut(n))return t===e?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let f=JSON.stringify(t?.[i]),s=JSON.stringify(e?.[i]);f!==s&&r++}return r}function bt(t,e,n){return t.length<=e.length?ft(t,e,n,!1):ft(e,t,(o,r)=>n(r,o),!0)}function ft(t,e,n,o){let r=t.length,i=e.length,f=[];for(let a=0;a<=r;a++)f.push(new Float64Array(i+1).fill(1/0));let s=[];for(let a=0;a<=r;a++)s.push(new Uint8Array(i+1));for(let a=0;a<=i;a++)f[r][a]=0;for(let a=r-1;a>=0;a--)for(let h=i-1;h>=0;h--){let E=n(t[a],e[h])+f[a+1][h+1],y=f[a][h+1];E<=y?(f[a][h]=E,s[a][h]=1):f[a][h]=y}let l=[],c=0,p=0;for(;c<r&&p<i;)s[c][p]&&(l.push(o?[e[p],t[c]]:[t[c],e[p]]),c++),p++;return l}function X(t,e,n,o,r,i,f,s={}){let l=t.find(e,n,s);if(r.length===0){l.forEach(m=>t.remove(m)),V(s,"onRowsApplied",i.path,[]);return}let c=r.length>l.length,p=l[0]||null;if(c&&!p&&(p=_t(t,e,n,s),!p))throw new P(i.path);let a=l.map(m=>Mt(t,m,o,s)),h=null;if(c&&p){h=t.clone(p),s.templateAttr&&t.removeAttr(h,s.templateAttr);let m=t.stripIds(h);m>0&&console.warn(`[hyper-html-api] stripped ${m} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let E=ct(r,a,o,Nt(t,l,r,i,s)),y=l[0]||p,w=t.parent(y),u=l.length>0?at(t,w,y):0,d=Dt(t,l),g=new Set,v=[],H=r.map((m,M)=>{let x=E[M];if(x>=0)return g.add(x),v.push(!1),l[x];v.push(!0);let J=t.clone(h);return t.stripIds(J),J});l.forEach((m,M)=>{g.has(M)||t.remove(m)}),d?H.forEach((m,M)=>{let x=u+M;t.children(w).findIndex(Et=>t.sameNode(Et,m))!==x&&t.insertAt(w,m,x)}):Pt(t,H,v,w,u),It(t,H,o,r,i,f,s),V(s,"onRowsApplied",i.path,H)}function V(t,e,n,o){if(typeof t[e]=="function")try{return t[e](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${e} threw at "${n.join(".")||"(root)"}"`,r);return}}function Nt(t,e,n,o,r){let i=V(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let f=new Array(n.length).fill(-1),s=new Set;for(let l=0;l<n.length;l++)if(i[l]){for(let c=0;c<e.length;c++)if(!(s.has(c)||!t.sameNode(e[c],i[l]))){f[l]=c,s.add(c);break}}return f}function It(t,e,n,o,r,i,f){e.forEach((s,l)=>{if(n===null){let c=o[l],p=c==null?"":String(c);t.text(s)!==p&&t.text(s,p)}else{let c=i(t,s,n,o[l],{depth:r.depth+1,path:[...r.path,l]},f);c&&c!==s&&(e[l]=c)}})}function Mt(t,e,n,o){return n===null?t.text(e):O(t,e,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function at(t,e,n){let o=t.children(e);for(let r=0;r<o.length;r++)if(t.sameNode(o[r],n))return r;return-1}function _t(t,e,n,o){if(!o.templateAttr)return null;let r=e;for(;r;){let i=t.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let f of i)if(t.attr(f,o.templateAttr)!=null)return f;r=t.parent(r)}return null}function Dt(t,e){if(e.length<=1)return!0;let n=t.parent(e[0]);if(!n)return!1;let o=t.children(n),r=[];for(let i of e){let f=o.findIndex(s=>t.sameNode(s,i));if(f===-1)return!1;r.push(f)}return r.sort((i,f)=>i-f),r[r.length-1]-r[0]===r.length-1}function Pt(t,e,n,o,r){let i=null,f=r;for(let s=0;s<e.length;s++){if(!n[s]){i=e[s];continue}let l=i?t.parent(i):o;if(!l)continue;let c=i?at(t,l,i)+1:f++;t.insertAt(l,e[s],c),i=e[s]}}var ht=new Set(["checked","selected","disabled","readOnly","paused"]);function N(t,e,n,o,r={}){let i=[];if(z(n,o,[],i),i.length)throw new D(i);U(t,e,n,o,{depth:0,path:[]},r)}function U(t,e,n,o,r,i={}){if(r.depth>b)throw new S(r.path);if(o===void 0)return e;if(typeof n=="string")return jt(t,e,n,o,r,i);if(Array.isArray(n)){let[f,s]=n;return X(t,e,f,s,o,r,U,i),e}if(typeof n=="object"&&n!==null){for(let[f,s]of Object.entries(n)){let l=U(t,e,s,o==null?o:o[f],{depth:r.depth+1,path:[...r.path,f]},i);l&&l!==e&&(e=l)}return e}return e}function jt(t,e,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return X(t,e,l,null,o,r,U,i),e}if(n.startsWith("@"))return dt(t,e,n.slice(1),o);let f=A(n);if(f!==-1){let l=n.slice(0,f),c=n.slice(f+1),p=l?t.find(e,l,i):[e];return p.length===0||dt(t,p[0],c,o),e}if(n===".")return pt(t,e,o),e;let s=t.find(e,n,i);return s.length===0||pt(t,s[0],o),e}function pt(t,e,n){let o=n==null?"":String(n);t.text(e)!==o&&t.text(e,o)}function dt(t,e,n,o){if(ot.has(n))throw new j(n);if(n==="outerHTML"){let r=o==null?"":String(o);return t.replaceWith(e,r)}return rt.has(n)?(t.prop(e,n,Ct(n,o)),e):(t.attr(e,n,o==null?"":String(o)),e)}function Ct(t,e){return e==null?ht.has(t)?!1:"":ht.has(t)?e==="false"?!1:!!e:e}function z(t,e,n,o){if(e!==void 0){if(typeof t=="string"){if(t.endsWith("[]")){Array.isArray(e)?e.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:L([...n,i]),expected:"scalar",got:C(r)})}):o.push({path:L(n),expected:"array",got:C(e)});return}e!==null&&typeof e=="object"&&o.push({path:L(n),expected:"scalar",got:C(e)});return}if(Array.isArray(t)){if(!Array.isArray(e)){o.push({path:L(n),expected:"array",got:C(e)});return}let r=t[1];e.forEach((i,f)=>z(r,i,[...n,f],o));return}if(typeof t=="object"&&t!==null){if(e===null||Array.isArray(e)||typeof e!="object"){o.push({path:L(n),expected:"object",got:C(e)});return}for(let[r,i]of Object.entries(t))z(i,e[r],[...n,r],o)}}}function C(t){return t===null?"null":Array.isArray(t)?"array":typeof t}function L(t){return t.join(".")}function Q(t){try{return JSON.parse(t)}catch(e){throw new T(`Invalid strict JSON: ${e.message}`,e)}}function $(t){try{return JSON.parse(t)}catch{}let e={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],f=0;for(;f<r.length;){let s=r[f];if(/\s/.test(s)){f++;continue}if("{}".includes(s)){i.push({type:s,value:s}),f++;continue}if(s==="["){let a=!1,h=f+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(a=!0),!a){i.push({type:s,value:s}),f++;continue}}if(s==="]"){i.push({type:s,value:s}),f++;continue}if(s===":"){i.push({type:e.COLON,value:s}),f++;continue}if(s===","){i.push({type:e.COMMA,value:s}),f++;continue}if(s==='"'||s==="'"){let a=s,h=f+1;for(;h<r.length&&r[h]!==a;)r[h]==="\\"&&h++,h++;i.push({type:e.STRING,value:r.substring(f+1,h),quoted:!0,sourceQuote:a}),f=h+1;continue}let l=f,c;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let a=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],h=!1;for(let E of a){let y=E.substring(1);if(r.substring(l+1,l+1+y.length)===y){h=!0,l+=y.length;break}}if(!h)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let a=r[l];for(l++;l<r.length&&r[l]!==a;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;c=r.substring(f,l);let p=e.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?p=e.NUMBER:c==="true"||c==="false"||c==="null"?p=e.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(p=e.SELECTOR),i.push({type:p,value:c,quoted:!1}),f=l}return i}function o(r){let i="";for(let f=0;f<r.length;f++){let s=r[f];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===e.COLON){i+=s.value;continue}if(s.type===e.COMMA){let l=r[f+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===e.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(c,p)=>p.length%2===0?p+'\\"':c)),i+=`"${l}"`;continue}if(s.type===e.NUMBER||s.type===e.BOOLEAN){i+=s.value;continue}if(s.type===e.SELECTOR||s.type===e.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(t),i=o(r);return JSON.parse(i)}catch(r){throw new T("Invalid extraction rules syntax: "+r.message,r)}}var Lt="1",gt=/^[a-zA-Z0-9_-]+$/;function I(t,e,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!gt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${gt})`);o=`script[data-rules-name~="${n}"]`}let r=t.find(e,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],f=t.attr(i,"data-rules-version");if(f!==Lt)throw new _(f);return{rules:$(t.text(i)),tagNode:i}}function Y(t,e,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=e&&e.ownerDocument?e.ownerDocument:e;return I(t,o,n)}return null}function mt(t,e,n,o){let r=Y(t,e,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:f}=r;return{rules:i,tagNode:f,get:()=>O(t,e,i,o),set:s=>N(t,e,i,s,o)}}function kt(t){return t&&t.nodeType===1&&t.tagName==="SCRIPT"&&t.hasAttribute&&t.hasAttribute("data-rules-name")}function Ht(t){return t?(t.nodeType===9||t.nodeType===11,t):null}var Wt={find(t,e,n={}){let o=Ht(t);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(e));n.includeRulesTag||(r=r.filter(s=>!kt(s)));let i=[];n.skip&&i.push(n.skip);let f=n.templateAttr===null?null:n.templateAttr||"cms-template";if(f&&i.push("["+f+"]"),i.length){let s=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(s))}return r},parent(t){return t?t.parentElement:null},children(t){return t?Array.from(t.children):[]},text(t,e){if(e===void 0)return(t.textContent||"").trim();t.textContent=e},attr(t,e,n){if(n===void 0)return t.hasAttribute&&t.hasAttribute(e)?t.getAttribute(e):null;t.setAttribute(e,n)},removeAttr(t,e){t&&t.removeAttribute&&t.removeAttribute(e)},prop(t,e,n){if(n===void 0){let o=t?t[e]:void 0;return o!==void 0?o:null}t[e]=n},clone(t){return t.cloneNode(!0)},insertAt(t,e,n){let o=t.children[n]||null;t.insertBefore(e,o)},remove(t){t&&t.parentNode&&t.parentNode.removeChild(t)},replaceWith(t,e){if(!t||!t.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=t.ownerDocument.createElement("template");o.innerHTML=e;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return t.parentNode.replaceChild(r,t),r},stripIds(t){let e=0;return t.id&&(t.removeAttribute("id"),e++),(t.querySelectorAll?t.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),e++}),e},sameNode(t,e){return t===e}},R=Wt;var k={extract:(t,e,n)=>O(R,t,e,n),apply:(t,e,n,o)=>N(R,t,e,n,o),findRulesIn:(t,e)=>I(R,t,e),findRules:(t,e)=>Y(R,t,e),bind:(t,e,n)=>mt(R,t,e,n),parseStrict:Q,parseRelaxed:$,ruleAttrIndex:A,splitRule:K,errors:B,DOM_PROPERTIES:W},Z=t=>!!t&&typeof t.nodeType=="number";function yt(t){let e=t&&t.ownerDocument?t.ownerDocument:t,n=R.find(e,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return I(R,e).rules}function tt(t,e){let n=Z(t)?t:document,o=Z(t)?e:t;return o===void 0?O(R,n,yt(n)):k.bind(n,o).get()}function et(t,e,n){if(!Z(t))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?N(R,t,yt(t),e):k.bind(t,n).set(e),t}var Bt={engine:k,extractData:tt,applyData:et},Ut=Bt;return St(vt);})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var HyperHtmlApi=(()=>{var st=Object.defineProperty;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 st=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var Ln=Object.getOwnPropertyNames;var Hn=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var n in t)st(e,n,{get:t[n],enumerable:!0})},jn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ln(t))!Hn.call(e,r)&&r!==n&&st(e,r,{get:()=>t[r],enumerable:!(o=Cn(t,r))||o.enumerable});return e};var Pn=e=>jn(st({},"__esModule",{value:!0}),e);var qr={};it(qr,{applyData:()=>jt,cms:()=>Tn,default:()=>Ur,engine:()=>We,extractData:()=>Ht,upgrade:()=>On});var Ke={};it(Ke,{fromString:()=>Ve,getRuleAtPath:()=>at,getValueAtPath:()=>Ce,parseConfigKey:()=>_n,setAtPath:()=>fe,toConfigKey:()=>Dn,toString:()=>re});function re(e){return e.map(String).join(".")}function Dn(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function _n(e){return e===""?[]:e.split(".")}function Ve(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function at(e,t){let n=e;for(let o of t){if(n==null||typeof n=="string")return;if(Array.isArray(n)){if(typeof o!="number"&&o!=="*")return;n=n[1];continue}if(typeof n=="object"){if(typeof o=="number"||!(o in n))return;n=n[o];continue}return}return n}function Ce(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function fe(e,t,n){if(t.length===0)return n;let[o,...r]=t;if(typeof o=="number"){let i=Array.isArray(e)?[...e]:[];return i[o]=fe(i[o],r,n),i}return{...e&&typeof e=="object"?e:{},[o]:fe((e||{})[o],r,n)}}function Me(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[n,o]of Object.entries(e))t[n]=Me(o);return t}return""}var Je=new WeakMap;function de(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function we(e){let t=de(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}var $n=new Set(["checked","selected","disabled","readOnly","paused"]);function ct({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(ut({rule:e,value:t,path:[],ctx:i})),r}function lt(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),Jt.set(e,{rules:t,getData:n,onChange:o}),Bn()}var Jt=new WeakMap,Vt=!1;function Bn(){Vt||(document.addEventListener("input",Kt,!0),document.addEventListener("change",Kt,!0),document.addEventListener("click",Fn,!0),Vt=!0)}function zt(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&Jt.get(t)||null}function Fn(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=zt(t);if(!n)return;let{rules:o,getData:r,onChange:i}=n,a=t.getAttribute("data-hha-action"),s=Ve(t.getAttribute("data-hha-path")||"");if(a==="scalar-array-add"){let c=Ce(r(),s)||[];i(fe(r(),s,[...c,""]),{structural:!0});return}if(a==="object-array-add"){let c=at(o,s);if(!Array.isArray(c))return;let g=Ce(r(),s)||[];i(fe(r(),s,[...g,Me(c[1])]),{structural:!0});return}if(a==="array-remove"){if(s.length===0)return;let c=s.slice(0,-1),g=s[s.length-1],v=Ce(r(),c)||[];if(typeof g!="number")return;let E=v.filter((m,A)=>A!==g);i(fe(r(),c,E),{structural:!0})}}function Kt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=zt(t);if(!n)return;let{getData:o,onChange:r}=n,i=t.closest("[data-hha-path]");if(!i)return;let a=Ve(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;r(fe(o(),a,s),{structural:!1})}function ut({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?Wn({rule:e,value:t,path:n,ctx:o}):qn({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return Vn({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return Un({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function Un({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",re(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=ze(n[n.length-1]),r.appendChild(i)}for(let[i,a]of Object.entries(e)){let s=[...n,i],c=t?.[i];r.appendChild(ut({rule:a,value:c,path:s,ctx:o}))}return r}function qn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",re(n));let i=document.createElement("div");i.className="field-body";let a=document.createElement("label");a.className="field-label",a.textContent=ze(n[n.length-1]||".")+Yn(e);let s=Jn(e,o.appRoot),c=Kn(s,{value:t,rule:e,path:n,appRoot:o.appRoot}),g=c.el;return g.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(a),i.appendChild(g),r.appendChild(i),Je.set(r,c),r}function Wn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",re(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=ze(n[n.length-1]),r.appendChild(i);let a=Array.isArray(t)?t:[],s=document.createElement("div");r.appendChild(s),a.forEach((g,v)=>{let E=[...n,v],m=document.createElement("div");m.className="scalar-array-row",m.setAttribute("data-hha-path",re(E));let A=document.createElement("input");A.type="text",A.className="field-input",A.value=g==null?"":String(g);let M=document.createElement("button");M.type="button",M.className="array-remove",M.textContent="\xD7",M.title="remove",M.setAttribute("data-hha-action","array-remove"),M.setAttribute("data-hha-path",re(E)),m.appendChild(A),m.appendChild(M),s.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","scalar-array-add"),c.setAttribute("data-hha-path",re(n)),r.appendChild(c),r}function Vn({rule:e,value:t,path:n,ctx:o}){let[,r]=e,i=Array.isArray(t)?t:[],a=document.createElement("div");a.className="form-section",a.setAttribute("data-hha-path",re(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=ze(n[n.length-1]),a.appendChild(s),i.forEach((g,v)=>{let E=[...n,v],m=document.createElement("div");m.className="array-card",m.setAttribute("data-hha-path",re(E));let A=document.createElement("button");A.type="button",A.className="array-remove",A.textContent="\xD7",A.title="remove item",A.setAttribute("data-hha-action","array-remove"),A.setAttribute("data-hha-path",re(E)),m.appendChild(A);let M=ut({rule:r,value:g,path:E,ctx:o});M.querySelector(".form-section-label")?.remove(),m.appendChild(M),a.appendChild(m)});let c=document.createElement("button");return c.type="button",c.className="array-add",c.textContent="+ add",c.setAttribute("data-hha-action","object-array-add"),c.setAttribute("data-hha-path",re(n)),a.appendChild(c),a}function Kn(e,t){let n=Gn(e);if(e.type==="select"&&e.options)for(let o of e.options){let r=document.createElement("option");r.value=o.value,r.textContent=o.text,String(t.value)===o.value&&(r.selected=!0),n.appendChild(r)}else e.type==="checkbox"?n.checked=t.value===!0||t.value==="true"||t.value==="checked":(e.type,n.value=t.value==null?"":String(t.value));return{el:n,destroy(){},focus(){n.focus()},validate(){}}}function Jn(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):n=we(e).prop,n&&$n.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=zn(e,t);if(!o)return{type:"text"};let r=(o.tagName||"").toLowerCase();if(r==="textarea")return{type:"textarea"};if(r==="select")return{type:"select",options:Array.from(o.querySelectorAll("option")).map(s=>({value:s.getAttribute("value")||s.textContent,text:s.textContent.trim()||s.getAttribute("value")||""}))};if(r==="input"){let a=(o.getAttribute("type")||"text").toLowerCase();if(a==="checkbox"||a==="radio")return{type:"checkbox"};if(a==="number")return{type:"number"}}let i=(o.textContent||"").trim();return i.length>60||i.includes(`
|
|
2
|
+
`)?{type:"textarea"}:{type:"text"}}function zn(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=we(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function Gn(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function ze(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function Yn(e){return` \xB7 ${e}`}var Gt={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function Zn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return Math.abs(t).toString(36)}function Qn(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function Xn(e,t){let n=[];for(let o of e.attributes||[]){let r=o.name;r==="id"||r==="class"||t.excludeAttributePrefixes.some(i=>r.startsWith(i))||t.includeAttributes.includes(r)&&n.push(`${r}=${o.value}`)}return n.sort().join("|")}function er(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function tr(e,t){let n=[e.tagName];return t.includeClasses&&n.push(Qn(e)),n.push(Xn(e,t)),Zn(n.join("|"))}function nr(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function rr(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function or(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function sr(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${nr(o)}`;if(n.unshift(r),o!==e&&rr(o,t)){n.unshift(or(o));break}o=o.parentElement}return n}function ir(e,t){let n=0,o=e.length-1,r=t.length-1;for(;o>=0&&r>=0&&e[o]===t[r];)n++,o--,r--;return n}function oe(e,t,n){if(n.has(e))return n.get(e);let o={signature:tr(e,t),path:sr(e,t),textHint:er(e,t)};return n.set(e,o),o}function Xt(e,t,n,o){if(o.has(e))return o.get(e);let r=new Map,i=e.querySelectorAll("*"),a=0;for(let s of i){let c=oe(s,t,n);c.domIndex=a++,!t.shouldIgnore?.(s)&&(r.has(c.signature)||r.set(c.signature,[]),r.get(c.signature).push(s))}return o.set(e,r),r}function ar(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function ft(e,t,n,o,r){let i=oe(e,n,o),a=oe(t,n,o),s=n.weights,c={},g=0;if(i.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};g+=s.signature,c.signature=s.signature;let E=ir(i.path,a.path)*s.pathSegment;g+=E,c.path=E;let m=!0;if(i.textHint&&a.textHint?i.textHint===a.textHint?(g+=s.textMatch,c.text=s.textMatch):(g-=s.textMismatch,c.text=-s.textMismatch,m=!1):i.textHint!==a.textHint&&(g-=s.textMismatch,c.text=-s.textMismatch,m=!1),r.candidateCount===1&&m&&(g+=s.uniqueCandidate,c.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof a.domIndex=="number"){let A=Math.abs(i.domIndex-a.domIndex),M=Math.min(A*s.positionPenalty,s.maxDriftPenalty);g-=M,c.drift=-M}return{score:g,breakdown:c}}function Yt(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let i=Xt(t,n,o,r),a=oe(e,n,o);if(typeof a.domIndex!="number"){let m=0,A=e.previousElementSibling;for(;A;)m++,A=A.previousElementSibling;a.domIndex=m}let s=i.get(a.signature)||[],c=n.excludeIds?s.filter(m=>!m.getAttribute("id")):s;if(c.length===0)return null;let g=null,v=0,E=null;for(let m of c){let{score:A,breakdown:M}=ft(e,m,n,o,{candidateCount:c.length});A>v&&(v=A,g=m,E=M)}return v<n.minConfidence?null:{element:g,confidence:v,breakdown:E}}function cr(e,t,n,o){let r=[],i=n.weights.signature+n.weights.slotMatch,a={slot:i};function s(E){if(E.children)return E.children;let m=E.childNodes;if(!m)return[];let A=[];for(let M=0;M<m.length;M++)m[M].nodeType===1&&A.push(m[M]);return A}function c(E,m){let A=s(E),M=s(m);if(A.length===M.length)for(let q=0;q<A.length;q++){let I=A[q],D=M[q];if(n.shouldIgnore?.(I)||n.shouldIgnore?.(D)||n.excludeIds&&(I.getAttribute("id")||D.getAttribute("id"))||I.tagName!==D.tagName)continue;let W=oe(I,n,o).signature,ee=oe(D,n,o).signature;W!==ee&&r.push({newEl:I,oldEl:D,score:i,breakdown:a}),c(I,D)}}function g(E,m){for(;;){if(E.tagName===m.tagName)return[E,m];let A=s(E);if(!E.tagName&&A.length===1){E=A[0];continue}let M=s(m);if(M.length===1&&M[0].tagName===E.tagName){m=M[0];continue}return null}}let v=g(e,t);return v&&c(v[0],v[1]),r}function Zt(e,t,n,o,r){let i=t.querySelectorAll("*"),a=Xt(e,n,o,r),s=0;for(let A of i){let M=oe(A,n,o);M.domIndex=s++}let c=[],g=new Map;function v(A,M,q){let I=new Set;if(A.textHint){let F=g.get(A.signature);if(!F){F=new Map;for(let Q of M){let ce=oe(Q,n,o).textHint,le=F.get(ce);le||(le=[],F.set(ce,le)),le.push(Q)}g.set(A.signature,F)}let ne=F.get(A.textHint);if(ne)for(let Q=0;Q<ne.length&&Q<q;Q++)I.add(ne[Q])}let D=0,W=M.length;for(;D<W;){let F=D+W>>1;oe(M[F],n,o).domIndex<A.domIndex?D=F+1:W=F}let ee=Math.max(0,Math.min(D-(q>>1),M.length-q)),se=Math.min(ee+q,M.length);for(let F=ee;F<se;F++)I.add(M[F]);return[...I]}for(let A of i){if(n.shouldIgnore?.(A)||n.excludeIds&&A.getAttribute("id"))continue;let M=oe(A,n,o),q=a.get(M.signature)||[],I=n.excludeIds?q.filter(ee=>!ee.getAttribute("id")):q,D=n.maxScoredCandidates,W=D&&I.length>D?v(M,I,D):I;for(let ee of W){let{score:se,breakdown:F}=ft(A,ee,n,o,{candidateCount:I.length});se>=n.minConfidence&&c.push({newEl:A,oldEl:ee,score:se,breakdown:F})}}if(n.weights.slotMatch>0){let A=cr(t,e,n,o);for(let M of A)c.push(M)}c.sort((A,M)=>M.score-A.score);let E=new Map,m=new Set;for(let{newEl:A,oldEl:M}of c)E.has(A)||m.has(M)||(E.set(A,M),m.add(M));return E}function Qt(e,t,n,o){let r=oe(e,n,o),i=oe(t,n,o),{score:a,breakdown:s}=ft(e,t,n,o,{candidateCount:1});return{matches:a>=n.minConfidence,score:a,breakdown:s,newMeta:{signature:r.signature,path:r.path,textHint:r.textHint},oldMeta:{signature:i.signature,path:i.path,textHint:i.textHint}}}function en(e={}){let t={...Gt,...e,weights:{...Gt.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,i)=>Yt(r,i,t,n,o),computeMatches:(r,i)=>Zt(r,i,t,n,o),explain:(r,i)=>Qt(r,i,t,n),invalidate:r=>ar(r,n,o),session:()=>{let r=new WeakMap,i=new WeakMap;return{findMatch:(a,s)=>Yt(a,s,t,r,i),computeMatches:(a,s)=>Zt(a,s,t,r,i),explain:(a,s)=>Qt(a,s,t,r)}},getConfig:()=>({...t})}}function dt(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
|
|
3
|
+
`;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let n=e.indexOf("*/",t+2);if(n===-1)return e.length;t=n+2;continue}return t}}function tn(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var lr=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,ur=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Ge(e){try{return JSON.parse(e)}catch{return JSON.parse(fr(e))}}function fr(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=dt(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=dt(e,n+1);if(e[s]==="}"||e[s]==="]"){n++;continue}t+=r,n++;continue}if(r==='"'||r==="'"){let s=n+1;for(;s<e.length&&e[s]!==r;)e[s]==="\\"&&s++,s++;s>=e.length&&o("unterminated string",n);let c=e.slice(n+1,s);r==="'"&&(c=tn(c)),t+='"'+c+'"',n=s+1;continue}let i=n;for(;i<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[i]);)i++;i===n&&o("unexpected character "+JSON.stringify(r),n);let a=e.slice(n,i);if(a==="true"||a==="false"||a==="null"||lr.test(a)){t+=a,n=i;continue}if(ur.test(a)){if(e[dt(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function nn(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let E=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(E=!0),!E){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let E=s,m=a+1;for(;m<r.length&&r[m]!==E;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:E}),a=m+1;continue}let c=a,g;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let E=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let A of E){let M=A.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let E=r[c];for(c++;c<r.length&&r[c]!==E;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;g=r.substring(a,c);let v=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(g)?v=t.NUMBER:g==="true"||g==="false"||g==="null"?v=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(g)&&(v=t.SELECTOR),i.push({type:v,value:g,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING){let c=s.value;s.sourceQuote==="'"&&(c=tn(c)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Error("Invalid extraction rules syntax: "+r.message)}}var G=Symbol("hyper-morph-json-merge:missing"),rn=["id","_id","uuid","key","slug","code","name"];function ve(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Le(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function dr(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function pe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!pe(e[n],t[n]))return!1;return!0}if(ve(e)&&ve(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Le(t,o)||!pe(e[o],t[o]))return!1;return!0}return!1}function on(e,t,n,o){return pe(t,n)?t:pe(t,e)?n:pe(n,e)?t:ve(t)&&ve(n)?pr(ve(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?yr(Array.isArray(e)?e:[],t,n,o):n}function sn(e,t,n,o){return t===G&&n===G?G:t===G?e===G?n:pe(n,e)?G:n:n===G?e===G?t:G:on(e,t,n,o)}function pr(e,t,n,o){let r={},i=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(n)]);for(let a of i){let s=sn(Le(e,a)?e[a]:G,Le(t,a)?t[a]:G,Le(n,a)?n[a]:G,o);s!==G&&dr(r,a,s)}return r}function hr(e){return e===null||typeof e!="object"}function Ye(e){return typeof e+":"+String(e)}function mr(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Le(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=Ye(i);if(o.has(a))return!1;o.add(a)}}return!0}function gr(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)ve(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(mr(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!hr(c))return null;let g=Ye(c);if(s.has(g))return null;s.add(g)}}return{kind:"self"}}function yr(e,t,n,o){let r=gr(e,t,n,o);if(!r)return n;let i=r.kind==="self"?Ye:A=>Ye(A[r.field]),a=A=>{let M=new Map;for(let q of A)M.set(i(q),q);return M},s=a(e),c=a(t),g=a(n),v=new Map,E=new Set([...s.keys(),...c.keys(),...g.keys()]);for(let A of E){let M=sn(s.has(A)?s.get(A):G,c.has(A)?c.get(A):G,g.has(A)?g.get(A):G,o);M!==G&&v.set(A,M)}let m=[];for(let A of n){let M=i(A);v.has(M)&&m.push(M)}for(let A=0;A<t.length;A++){let M=i(t[A]);if(!v.has(M)||m.includes(M))continue;let q=0;for(let I=A-1;I>=0;I--){let D=m.indexOf(i(t[I]));if(D!==-1){q=D+1;break}}m.splice(q,0,M)}return m.map(A=>v.get(A))}function pt(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...rn]:rn;return on(e===void 0?G:e,t,n,{keyCandidates:r})}function ht(e,t,n,o={}){let r=o.parse||Ge,i=[],a=(E,m)=>{if(typeof E!="string")return G;try{return r(E)}catch(A){return i.push(`${m} side is not valid JSON (${A.message})`),G}},s=a(t,"local"),c=a(n,"remote");if(s===G)return{text:n,warnings:i};if(c===G)return{text:t,warnings:i};let g=a(e,"base"),v=pt(g===G?void 0:g,s,c,o);return pe(v,c)?{text:n,warnings:i}:pe(v,s)?{text:t,warnings:i}:{text:JSON.stringify(v,null,2),warnings:i}}var He=function(){"use strict";let e=()=>{},t='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function n(f){if(!(f instanceof Element))return!1;if(f.matches(t))return!0;if(f.tagName==="LINK"||f.tagName==="SCRIPT"){let R=f.getAttribute("src")||f.getAttribute("href")||"";if(R.startsWith("chrome-extension://")||R.startsWith("moz-extension://")||R.startsWith("safari-web-extension://"))return!0}return!1}function o(f){return f instanceof Element?f.closest(t)?!0:n(f):!1}let r=en({shouldIgnore:o});function i(f,R,T){if(T){let k=T.identityOf(f);if(k&&!T.disabled.has(k.key))return"hm-merge:"+k.key}if(R!=="smart")return f.outerHTML;let N=f.getAttribute("src"),O=f.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${O}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${O}:${N}`}else{let k=f.textContent.trim(),h=5381;for(let x=0;x<k.length;x++)h=(h<<5)+h^k.charCodeAt(x);return`inline:${O}:${Math.abs(h).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(f){return f instanceof Element&&f.tagName==="SCRIPT"&&f.namespaceURI===a}function c(f){let R=document.createElement("div");R.innerHTML="<script><\/script>";let T=R.firstChild;for(let N of f.attributes)T.setAttribute(N.name,N.value);return T.textContent=f.textContent,T}function g(f){if(s(f))return c(f);if(f instanceof Element)for(let R of f.querySelectorAll("script"))s(R)&&R.replaceWith(c(R));return f}function v(f){let R=(f.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return R==="application/json"||R.endsWith("+json")}let E={match:f=>f.hasAttribute("merge"),identity:f=>f.getAttribute("merge")};function m(f,R,T){if(T.merge===!1)return null;let N=[E,...T.mergeTags||[]],O=new WeakMap,k=d=>{if(O.has(d))return O.get(d);let b=null;if(s(d)&&!d.getAttribute("src")&&!o(d)){let S=d;for(let L=0;L<N.length;L++)if(N[L].match(S)){if(!v(S))console.warn("[hyper-morph] merge ignored: script type is not JSON",S);else{let B=N[L].identity(S);B!=null&&B!==""&&(b={key:L+":"+B,raw:B,recognizer:N[L]})}break}}return O.set(d,b),b},h=new Set,x=d=>{let b=new Map,S=L=>{let B=k(L);B&&(b.has(B.key)?(h.add(B.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${B.raw}"`)):b.set(B.key,L))};s(d)&&S(d);for(let L of d.querySelectorAll("script"))S(L);return b},p=x(f),u=x(R.__hyperMorphRoot||R);if(p.size===0&&u.size===0)return null;let l=null;return{identityOf:k,disabled:h,oldByKey:p,newByKey:u,baseTexts:()=>{if(l)return l;l=new Map;let d=T.mergeBase;if(!d)return l;let b;typeof d=="string"?b=new DOMParser().parseFromString(d,"text/html").documentElement:d instanceof Document?b=d.documentElement:b=d;let S=L=>{let B=k(L);B&&!l.has(B.key)&&l.set(B.key,L.textContent)};s(b)&&S(b);for(let L of b.querySelectorAll("script"))S(L);return l}}}function A(f,R,T){let N=f.merge;if(!N)return!1;let O=N.identityOf(R);if(!O||N.disabled.has(O.key))return!1;let k=N.identityOf(T);if(!k||k.key!==O.key)return!1;let h=R,x=T,p=x.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=ht(N.baseTexts().get(O.key),h.textContent,x.textContent,{parse:O.recognizer.parse,keyCandidates:p?p.split(/[\s,]+/).filter(Boolean):void 0});for(let y of l)console.warn(`[hyper-morph] merge "${O.raw}": ${y}`);return h.textContent!==u&&(h.textContent=u),!0}let M={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},q={computeMatches(f,R){let{computeMatches:T}=r.session();return T(f,R)}};function I(f,R,T={}){f=Nn(f);let N=Pt(R),O=Rn(f,N,T),k=O.scripts.handle?new Set(Array.from(f.querySelectorAll("script")).map(u=>i(u,O.scripts.matchMode,O.merge))):null,h=ee(O),x=Q(O,f,N,u=>u.morphStyle==="innerHTML"?(F(u,f,N),Array.from(f.childNodes)):W(u,f,N)),p=u=>{h&&se(O,h),D(O);let l=k?tt(u,k,O):[];return l.length>0?Promise.all(l).then(()=>u):u};return x instanceof Promise?x.then(p):p(x)}function D(f){for(let R of Array.from(f.pantry.childNodes))f.callbacks.beforeNodeRemoved(R)!==!1&&f.callbacks.afterNodeRemoved(R);f.pantry.remove()}function W(f,R,T){let N=Pt(R);return F(f,N,T,R,R.nextSibling),Array.from(N.childNodes)}function ee(f){if(!f.config.restoreFocus)return null;let R=document.activeElement;if(!(R instanceof HTMLInputElement||R instanceof HTMLTextAreaElement))return null;let{id:T,selectionStart:N,selectionEnd:O}=R;return{element:R,id:T,selectionStart:N,selectionEnd:O}}function se(f,R){let T=R.element;if(R.id&&R.id!==document.activeElement?.getAttribute("id")&&(T=f.target.querySelector(`[id="${CSS.escape(R.id)}"]`),T?.focus()),T&&!T.selectionEnd&&R.selectionEnd!=null)try{T.setSelectionRange(R.selectionStart,R.selectionEnd)}catch{}}let F=function(){function f(u,l,y,d=null,b=null){l instanceof HTMLTemplateElement&&y instanceof HTMLTemplateElement&&(l=l.content,y=y.content),d||=l.firstChild;for(let S of y.childNodes){if(n(S))continue;if(d&&d!=b){let B=T(u,S,d,b);if(B){B!==d&&O(u,d,B),ne(B,S,u),d=B.nextSibling;continue}}if(S instanceof Element){let B=S.getAttribute("id");if(u.persistentIds.has(B)){let w=k(l,B,d,u);ne(w,S,u),d=w.nextSibling;continue}if(!u.idMap.has(S)){let w=u.hyperMatches.get(S);if(w&&!u.idMap.has(w)&&!p(w,l)){x(l,w,d),ne(w,S,u),d=w.nextSibling;continue}}}let L=R(l,S,d,u);L&&(d=L.nextSibling)}for(;d&&d!=b;){let S=d;d=d.nextSibling,n(S)||N(u,S)}}function R(u,l,y,d){if(d.callbacks.beforeNodeAdded(l)===!1)return null;if(d.idMap.has(l)){let b=l,S=document.createElementNS(b.namespaceURI,b.localName);return u.insertBefore(S,y),ne(S,l,d),d.callbacks.afterNodeAdded(S),S}else{let b=g(document.importNode(l,!0));return u.insertBefore(b,y),d.callbacks.afterNodeAdded(b),b}}let T=function(){function u(d,b,S,L){let B=b instanceof Element&&!d.idMap.has(b)?d.hyperMatches.get(b):null,w=null,C=b.nextSibling,V=0,_=S;for(;_&&_!=L;){if(n(_)){_=_.nextSibling;continue}if(y(_,b)){if(l(d,_,b)||_===B&&!d.idMap.has(_))return _;if(w===null){let K=_ instanceof Element&&d.hyperMatchedOldElements.has(_);!d.idMap.has(_)&&!K&&(w=_)}}if(w===null&&C&&y(_,C)&&(V++,C=C.nextSibling,V>=2&&(w=void 0)),d.activeElementAndParents.includes(_))break;_=_.nextSibling}return w||null}function l(d,b,S){let L=d.idMap.get(b),B=d.idMap.get(S);if(!B||!L)return!1;for(let w of L)if(B.has(w))return!0;return!1}function y(d,b){let S=d,L=b;return S.nodeType===L.nodeType&&S.tagName===L.tagName&&(!S.getAttribute?.("id")||S.getAttribute?.("id")===L.getAttribute?.("id"))}return u}();function N(u,l){let y=l instanceof Element&&u.hyperMatchedOldElements.has(l)&&!u.idMap.has(l);if(u.idMap.has(l)||y)x(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function O(u,l,y){let d=l;for(;d&&d!==y;){let b=d;d=d.nextSibling,n(b)||N(u,b)}return d}function k(u,l,y,d){let b=d.target.getAttribute?.("id")===l&&d.target||d.target.querySelector(`[id="${CSS.escape(l)}"]`)||d.pantry.querySelector(`[id="${CSS.escape(l)}"]`);return h(b,d),x(u,b,y),b}function h(u,l){let y=u.getAttribute("id");for(;u=u.parentNode;){let d=l.idMap.get(u);d&&(d.delete(y),d.size||l.idMap.delete(u))}}function x(u,l,y){if(u.moveBefore)try{u.moveBefore(l,y)}catch{u.insertBefore(l,y)}else u.insertBefore(l,y)}function p(u,l){let y=l instanceof Element?l:l.realParentNode;return!!y&&u.contains(y)}return f}(),ne=function(){function f(h,x,p){return p.ignoreActive&&h===document.activeElement?null:(p.callbacks.beforeNodeMorphed(h,x)===!1||(h instanceof HTMLHeadElement&&p.head.ignore||(h instanceof HTMLHeadElement&&p.head.style!=="morph"?le(h,x,p):(R(h,x,p),A(p,h,x)||k(h,p)||F(p,h,x))),p.callbacks.afterNodeMorphed(h,x)),h)}function R(h,x,p){let u=x.nodeType;if(u===1){let l=h,y=x,d=l.attributes,b=y.attributes;for(let S of b)O(S.name,l,"update",p)||l.getAttribute(S.name)!==S.value&&l.setAttribute(S.name,S.value);for(let S=d.length-1;0<=S;S--){let L=d[S];if(L&&!y.hasAttribute(L.name)){if(O(L.name,l,"remove",p))continue;l.removeAttribute(L.name)}}k(l,p)||T(l,y,p)}(u===8||u===3)&&h.nodeValue!==x.nodeValue&&(h.nodeValue=x.nodeValue)}function T(h,x,p){if(h instanceof HTMLInputElement&&x instanceof HTMLInputElement&&x.type!=="file"){let u=x.value,l=h.value;N(h,x,"checked",p),N(h,x,"disabled",p),p.formStateSync==="property"&&h.indeterminate!==x.indeterminate&&(h.indeterminate=x.indeterminate),p.formStateSync==="property"?l!==u&&(O("value",h,"update",p)||(h.value=u)):x.hasAttribute("value")?l!==u&&(O("value",h,"update",p)||(h.setAttribute("value",u),h.value=u)):O("value",h,"remove",p)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&x instanceof HTMLOptionElement)N(h,x,"selected",p);else if(h instanceof HTMLTextAreaElement&&x instanceof HTMLTextAreaElement){let u=x.value,l=h.value;if(O("value",h,"update",p)||(u!==l&&(h.value=u),p.formStateSync==="property"))return;h.firstChild&&h.firstChild.nodeValue!==u&&(h.firstChild.nodeValue=u)}}function N(h,x,p,u){let l=x[p],y=h[p];if(l!==y){let d=O(p,h,"update",u);if(d||(h[p]=x[p]),u.formStateSync==="property")return;l?d||h.setAttribute(p,""):O(p,h,"remove",u)||h.removeAttribute(p)}}function O(h,x,p,u){return h==="value"&&u.ignoreActiveValue&&x===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,x,p)===!1}function k(h,x){return!!x.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return f}();function Q(f,R,T,N){if(f.head.block){let O=R.querySelector("head"),k=T.querySelector("head");if(O&&k){let h=le(O,k,f);return Promise.all(h).then(()=>(f.head.block=!1,f.head.ignore=!0,N(f)))}}return N(f)}function ce(f){return f.tagName==="SCRIPT"?!!f.getAttribute("src"):f.tagName==="LINK"?(f.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!f.getAttribute("href"):!1}function le(f,R,T){let N=[],O=[],k=[],h=[],x=T.scripts.matchMode,p=y=>{if(y.tagName==="SCRIPT")return i(y,x,T.merge);if(y.tagName==="LINK"&&x==="smart"){let d=y.getAttribute("href");if(d)try{let b=new URL(d,window.location.href);return`link:${y.getAttribute("rel")||""}:${b.origin}${b.pathname}${b.search}`}catch{}}return y.outerHTML},u=new Map;for(let y of R.children){if(n(y))continue;let d=p(y),b=u.get(d);b||(b=[],u.set(d,b)),b.push(y)}for(let y of f.children){let d=p(y),b=u.get(d),S=!!(b&&b.length),L=T.head.shouldReAppend(y),B=T.head.shouldPreserve(y);if(S||B)if(L)O.push(y);else{if(b&&b.length){let w=b.pop();b.length||u.delete(d),A(T,y,w)}k.push(y)}else T.head.style==="append"?L&&(O.push(y),h.push(y)):T.head.shouldRemove(y)!==!1&&!n(y)&&O.push(y)}for(let y of u.values())h.push(...y);let l=[];for(let y of h){let d=document.createRange().createContextualFragment(y.outerHTML).firstChild;if(T.callbacks.beforeNodeAdded(d)!==!1){if(d instanceof Element&&ce(d)){let b,S=new Promise(function(L){b=L});d.addEventListener("load",function(){b()}),d.addEventListener("error",function(){b()}),l.push(S)}f.appendChild(d),T.callbacks.afterNodeAdded(d),N.push(d)}}for(let y of O)T.callbacks.beforeNodeRemoved(y)!==!1&&(f.removeChild(y),T.callbacks.afterNodeRemoved(y));return T.head.afterHeadMorphed(f,{added:N,kept:k,removed:O}),l}function tt(f,R,T){if(!T.scripts.handle)return[];let N=[],O=[],k=[],h=[],x=T.scripts.matchMode,p=[];for(let l of f)if(l instanceof Element){s(l)&&p.push(l);for(let y of l.querySelectorAll("script"))s(y)&&p.push(y)}for(let l of p){if(l.closest("head")||o(l))continue;let y=i(l,x,T.merge),d=R.has(y),b=T.scripts.shouldPreserve(l),S=T.scripts.shouldReAppend(l);d||b?S?(O.push(l),h.push(l)):k.push(l):h.push(l)}let u=[];for(let l of h){if(T.callbacks.beforeNodeAdded(l)===!1)continue;let y=document.createElement("script");for(let d of l.attributes)y.setAttribute(d.name,d.value);if(y.textContent=l.textContent,y.src){let d,b=new Promise(function(S){d=S});y.addEventListener("load",function(){d()}),y.addEventListener("error",function(){d()}),u.push(b)}l.replaceWith(y),T.callbacks.afterNodeAdded(y),N.push(y)}return T.scripts.afterScriptsHandled(T.target,{added:N,kept:k,removed:O}),u}let Rn=function(){function f(p,u,l){let{persistentIds:y,idMap:d}=h(p,u),b=q.computeMatches(p,u);if(typeof l.key=="function"){let C=new Map,V=new Set,_=P=>{let H=l.key(P);H!=null&&(C.has(H)?V.add(H):C.set(H,P))};p instanceof Element&&_(p);for(let P of p.querySelectorAll("*"))_(P);for(let P of V)C.delete(P);let K=new Map;for(let[P,H]of b)K.set(H,P);let te=u.__hyperMorphRoot||u,Z=new Map,z=new Set,j=P=>{let H=l.key(P);H!=null&&(Z.has(H)?z.add(H):Z.set(H,P))};te instanceof Element&&j(te);for(let P of te.querySelectorAll("*"))j(P);for(let P of z)Z.delete(P);for(let[P,H]of Z){let U=C.get(P);if(!U||U.tagName!==H.tagName)continue;let J=K.get(U);J&&J!==H&&b.delete(J);let ge=b.get(H);ge&&ge!==U&&K.delete(ge),b.set(H,U),K.set(U,H)}}let S=R(l),L=m(p,u,S.scripts);if(L){let C=new Map;for(let[V,_]of b)C.set(_,V);for(let[V,_]of L.newByKey){if(L.disabled.has(V))continue;let K=L.oldByKey.get(V);if(!K)continue;let te=C.get(K);te&&te!==_&&b.delete(te);let Z=b.get(_);Z&&Z!==K&&C.delete(Z),b.set(_,K),C.set(K,_)}}let B=new Set;for(let C of b.values())B.add(C);let w=S.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(w))throw new Error(`Do not understand how to morph style ${w}`);return{target:p,newContent:u,config:S,morphStyle:w,ignoreActive:S.ignoreActive,ignoreActiveValue:S.ignoreActiveValue,restoreFocus:S.restoreFocus,formStateSync:S.formStateSync||"attribute",idMap:d,persistentIds:y,hyperMatches:b,hyperMatchedOldElements:B,merge:L,pantry:T(),activeElementAndParents:N(p),callbacks:S.callbacks,head:S.head,scripts:S.scripts}}function R(p){let u=Object.assign({},M);return Object.assign(u,p),u.callbacks=Object.assign({},M.callbacks,p.callbacks),u.head=Object.assign({},M.head,p.head),u.scripts=Object.assign({},M.scripts,p.scripts),u}function T(){let p=document.createElement("div");return p.hidden=!0,document.body.insertAdjacentElement("afterend",p),p}function N(p){let u=[],l=document.activeElement;if(l?.tagName!=="BODY"&&p.contains(l))for(;l&&(u.push(l),l!==p);)l=l.parentElement;return u}function O(p){let u=Array.from(p.querySelectorAll("[id]"));return p.getAttribute?.("id")&&u.push(p),u}function k(p,u,l,y){for(let d of y){let b=d.getAttribute("id");if(u.has(b)){let S=d;for(;S;){let L=p.get(S);if(L==null&&(L=new Set,p.set(S,L)),L.add(b),S===l)break;S=S.parentElement}}}}function h(p,u){let l=O(p),y=O(u),d=x(l,y),b=new Map;k(b,d,p,l);let S=u.__hyperMorphRoot||u;return k(b,d,S,y),{persistentIds:d,idMap:b}}function x(p,u){let l=new Set,y=new Map;for(let b of p){let S=b.getAttribute("id");y.has(S)?l.add(S):y.set(S,b.tagName)}let d=new Set;for(let b of u){let S=b.getAttribute("id");d.has(S)?l.add(S):y.get(S)===b.tagName&&d.add(S)}for(let b of l)d.delete(b);return d}return f}(),{normalizeElement:Nn,normalizeParent:Pt}=function(){let f=new WeakSet;function R(h){return h instanceof Document?h.documentElement:h}function T(h){if(h==null)return document.createElement("div");if(typeof h=="string")return T(k(h));if(f.has(h))return h;if(h instanceof Node){if(h.parentNode)return new N(h);{let x=document.createElement("div");return x.append(h),x}}else{let x=document.createElement("div");for(let p of[...h])x.append(p);return x}}class N{constructor(x){this.originalNode=x,this.realParentNode=x.parentNode,this.previousSibling=x.previousSibling,this.nextSibling=x.nextSibling}get childNodes(){let x=[],p=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;p&&p!=this.nextSibling;)x.push(p),p=p.nextSibling;return x}querySelectorAll(x){return this.childNodes.reduce((p,u)=>{if(u instanceof Element){u.matches(x)&&p.push(u);let l=u.querySelectorAll(x);for(let y=0;y<l.length;y++)p.push(l[y])}return p},[])}insertBefore(x,p){return this.realParentNode.insertBefore(x,p)}moveBefore(x,p){return this.realParentNode.moveBefore(x,p)}get __hyperMorphRoot(){return this.originalNode}}function O(h){let x=y=>`<${y}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,p=h.replace(/<!--[\s\S]*?-->/g,"");for(let y of["script","style","textarea","title"])p=p.replace(new RegExp(`${x(y)}[\\s\\S]*?</${y}\\s*>`,"gi"),"");let u=new RegExp(`${x("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=p,p=p.replace(u,"");while(p!==l);return p}function k(h){let x=new DOMParser,p=O(h);if(p.match(/<\/html>/)||p.match(/<\/head>/)||p.match(/<\/body>/)){let u=x.parseFromString(h,"text/html");if(p.match(/<\/html>/))return f.add(u),u;{let l=u.firstChild;return l&&f.add(l),l}}else{let l=x.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return f.add(l),l}}return{normalizeElement:R,normalizeParent:T}}(),Dt=Symbol("hyper-morph-duplicate-key"),_t=[f=>f.getAttribute("data-id"),f=>f.getAttribute("id")];function ke(f,R){return R.map(T=>{let N=new Map;for(let O of f){if(O.nodeType!==1)continue;let k=T(O);k==null||k===""||N.set(k,N.has(k)?Dt:O)}return N})}function $t(f,R,T,N){for(let O=0;O<N.length;O++){let k=N[O](f);if(k==null||k===""||R[O].get(k)!==f)continue;let h=T[O].get(k);if(!(!h||h===Dt)&&h.tagName===f.tagName)return h}return null}function Ee(f,R,T){for(let N=0;N<T.length;N++){let O=T[N](f);if(!(O==null||O==="")&&R[N].get(O)===f)return!0}return!1}function kn(f,R,T={}){let N=T.skip||(()=>!1),O=T.ignoreAttr||(()=>!1),k=T.tiers&&T.tiers.length?T.tiers:_t,h=null;function x(){return h||(h=ke([f,...f.querySelectorAll("*")],k)),h}let p=null;function u(){return p||(p=ke([R,...R.querySelectorAll("*")],k)),p}function l(j){return!j.parentElement||!j.parentElement.parentElement}function y(j,P,H){return l(j)||Ee(j,x(),k)?(H.push({type:"subtree",el:j,base:P}),!1):!0}function d(j,P){let H=[];for(let U of j.attributes)O(j,U.name)||P.getAttribute(U.name)!==U.value&&H.push(U.name);for(let U of P.attributes)O(j,U.name)||j.hasAttribute(U.name)||H.push(U.name);return H}function b(j){let P=[],H=null,U=()=>{H!==null&&(P.push({nodeType:3,nodeValue:H}),H=null)};for(let J of j.childNodes){if(J.nodeType===3){H=(H===null?"":H)+J.nodeValue;continue}J.nodeType===1&&N(J)||(U(),(J.nodeType===1||J.nodeType===8)&&P.push(J))}return U(),P}function S(j,P){if(j.nodeType!==P.nodeType)return!1;if(j.nodeType!==1)return!0;if(j.tagName!==P.tagName)return!1;for(let H of k){let U=H(j),J=H(P);if(U!=null&&U!==""&&J!=null&&J!==""&&U!==J)return!1}return!0}function L(j){let P="";for(let H of j)H.nodeType===3&&H.nodeValue.trim()!==""?P+="\0"+H.nodeValue:H.nodeType===8&&(P+=""+H.nodeValue);return P}function B(j,P,H){let U=b(j),J=b(P);if(U.length===J.length){let $=!0;for(let Y=0;Y<U.length;Y++)if(!S(U[Y],J[Y])){$=!1;break}if($){for(let Y=0;Y<U.length;Y++){let xe=U[Y];if(xe.nodeType===1){if(w(xe,J[Y],H))return!0}else if(xe.nodeValue!==J[Y].nodeValue)return!0}return!1}}let ge=U.filter($=>$.nodeType===1),nt=J.filter($=>$.nodeType===1);if(L(U)!==L(J))return!0;let Bt=ke(ge,k),Ft=ke(nt,k),rt=[],ot=new Set,Ut=[];for(let $ of ge){let Y=$t($,Bt,Ft,k);Y&&!ot.has(Y)?(rt.push([$,Y]),ot.add(Y)):Ut.push($)}let ue=[];for(let $ of Ut)Ee($,Bt,k)?H.push({type:"subtree",el:$,base:null}):ue.push($);let Ie=[];for(let $ of nt)ot.has($)||(Ee($,Ft,k)?H.push({type:"deletion",el:$}):Ie.push($));if(ue.length!==Ie.length)return!0;for(let $=0;$<ue.length;$++)if(!S(ue[$],Ie[$]))return!0;let qt=new Map(rt);for(let $=0;$<ue.length;$++)qt.set(ue[$],Ie[$]);let Wt=-1;for(let $ of ge){let Y=qt.get($);if(!Y)continue;let xe=nt.indexOf(Y);if(xe<Wt)return!0;Wt=xe}for(let $=0;$<ue.length;$++)if(w(ue[$],Ie[$],H))return!0;for(let[$,Y]of rt)if(w($,Y,H))return!0;return!1}function w(j,P,H){if(j.tagName!==P.tagName)return y(j,P,H);let U=d(j,P),J=[];if(B(j,P,J))return y(j,P,H);if(U.length){if(!l(j)&&!Ee(P,u(),k))return!0;H.push({type:"attrs",el:j,names:U,base:P})}return H.push(...J),!1}let C=[],V=d(f,R);V.length&&C.push({type:"attrs",el:f,names:V});let _=(j,P)=>Array.from(j.children).find(H=>H.tagName===P)||null,K=_(f,"HEAD"),te=_(R,"HEAD");if(K&&te){let j=[];w(K,te,j),j.length&&C.push({type:"head",el:K})}else(K||te)&&K&&C.push({type:"head",el:K});let Z=_(f,"BODY"),z=_(R,"BODY");return Z&&z?w(Z,z,C):Z&&C.push({type:"subtree",el:Z,base:null}),{entries:C}}function In(f,R,T={}){let N=T.tiers&&T.tiers.length?T.tiers:_t,O=f.documentElement,k=[],h=0,x=w=>({ok:!1,placed:k,held:w,skippedAttrs:h});if(!O)return x(null);function p(w){let C=[w,...w.querySelectorAll("*")];return ke(C,N)}let u=p(O),l=new Map,y=w=>{let C=w.getRootNode(),V=l.get(C);if(!V){let _=C.nodeType===9?C.documentElement:C;V=p(_),l.set(C,V)}return V};function d(w){if(!w.parentElement&&w.tagName==="HTML")return O;if(w.parentElement&&!w.parentElement.parentElement&&w.parentElement.tagName==="HTML"){if(w.tagName==="BODY")return f.body||null;if(w.tagName==="HEAD")return f.head||null}return null}function b(w){let C=d(w);return C||$t(w,y(w),u,N)}function S(w){if(!w)return null;let C=b(w);return C&&C.isConnected?C:null}function L(w){for(let C=0;C<N.length;C++){let V=N[C](w);V!=null&&V!==""&&u[C].set(V,w)}}for(let w of R){if(w.type!=="deletion")continue;let C=b(w.el);C&&C!==O&&C.remove()}let B=R.filter(w=>w.type!=="deletion").sort((w,C)=>w.el===C.el?0:w.el.compareDocumentPosition(C.el)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1);for(let w of B){if(w.type==="head"){let z=f.importNode(w.el,!0);f.head?f.head.replaceWith(z):O.insertBefore(z,O.firstChild),k.push({entry:w,imported:z});continue}if(w.type==="attrs"){let z=S(w.el)||S(w.base);if(!z){h++;continue}for(let j of w.names)w.el.hasAttribute(j)?z.setAttribute(j,w.el.getAttribute(j)):z.removeAttribute(j);continue}let C=w.el;if(d(C))return x(w);let V=S(C)||S(w.base);if(V){let z=f.importNode(C,!0);V.replaceWith(z),L(z),k.push({entry:w,imported:z});continue}if(w.base!=null&&!Ee(w.base,y(w.base),N)||!Ee(C,y(C),N))return x(w);let _=C.parentElement;if(!_)return x(w);let K=S(_);if(!K)return x(w);let te=null;for(let z=C.previousElementSibling;z;z=z.previousElementSibling){let j=S(z);if(j&&j.parentNode===K){te=j;break}}let Z=f.importNode(C,!0);if(te)K.insertBefore(Z,te.nextSibling);else{let z=Array.prototype.indexOf.call(_.children,C);K.insertBefore(Z,K.children[z]||null)}L(Z),k.push({entry:w,imported:Z})}return{ok:!0,placed:k,held:null,skippedAttrs:h}}return{morph:I,defaults:M,findChangedRoots:kn,spliceProtected:In,mergeJson:pt,mergeScriptText:ht,parseJsonRelaxed:Ge,parseRulesRelaxed:nn}}();var io=He.morph,ao=He.defaults,co=He.findChangedRoots,lo=He.spliceProtected;var an=He;function mt(e,t,{onWidgetRemoved:n}={}){an.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Je.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var Ar="hha:upgrade-check:";function ie(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function gt(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function cn(e,t){let n=gt(e),o=gt(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let a=n[i]||0,s=o[i]||0;if(a!==s)return a>s}return!1}function Sr(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Er(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function yt({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(m=>fetch(m)),r=r??Date.now(),!t)return null;let a=ie(t,"hyper-source");if(!a)return null;let s=ie(t,"hyper-version"),c;try{c=new URL(a,n?n.href:void 0)}catch{return null}if(n&&c.origin===n.origin&&c.pathname===n.pathname)return null;let g=`${Ar}${c.href}:${s||"none"}`,v,E=e?null:Sr(g);if(E&&typeof E.checkedAt=="number"&&r-E.checkedAt<i)v=E.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let A=await m.text(),M=new DOMParser().parseFromString(A,"text/html");v=ie(M,"hyper-version")}catch{v=null}Er(g,{checkedAt:r,sourceVersion:v})}return v?{available:cn(v,s||"0.0.0"),currentVersion:s,sourceVersion:v,sourceUrl:c.href}:null}var Ze=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],bt=new Set(Ze),ln=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),un=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Qe={};it(Qe,{EmptyListInsert:()=>Pe,MAX_RULE_DEPTH:()=>Oe,MaxRuleDepthExceeded:()=>be,RuleTargetReadOnly:()=>De,RulesParseError:()=>Te,ShapeMismatch:()=>je,UnknownRulesVersion:()=>ye});var Te=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},ye=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},Oe=20,be=class extends Error{constructor(t){super(`rule depth exceeded ${Oe} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},je=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Pe=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},De=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function ae(e,t,n,o={}){return At(e,t,n,{depth:0,path:[]},o)}function At(e,t,n,o,r){if(o.depth>Oe)throw new be(o.path);if(typeof n=="string")return xr(e,t,n,o,r);if(Array.isArray(n)){let[i,a]=n,s=e.find(t,i,r);return dn(r,o,s),s.map((c,g)=>At(e,c,a,{depth:o.depth+1,path:[...o.path,g]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[a,s]of Object.entries(n))i[a]=At(e,t,s,{depth:o.depth+1,path:[...o.path,a]},r);return i}return null}function xr(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),c=e.find(t,s,r);return dn(r,o,c),c.map(g=>e.text(g))}if(n.startsWith("@"))return fn(e,t,n.slice(1));let i=de(n);if(i!==-1){let s=n.slice(0,i),c=n.slice(i+1),g=s?e.find(t,s,r):[t];return g.length===0?null:fn(e,g[0],c)}if(n===".")return e.text(t);let a=e.find(t,n,r);return a.length===0?null:e.text(a[0])}function dn(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function fn(e,t,n){if(bt.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Mr(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function wr(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var vr={find(e,t,n={}){let o=wr(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Mr(s)));let i=[];n.skip&&i.push(n.skip);let a=n.templateAttr===null?null:n.templateAttr||"cms-template";if(a&&i.push("["+a+"]"),i.length){let s=i.join(", ");r=r.filter(c=>!c.closest||!c.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},X=vr;function St(e){try{return JSON.parse(e)}catch(t){throw new Te(`Invalid strict JSON: ${t.message}`,t)}}function Ae(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],a=0;for(;a<r.length;){let s=r[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){i.push({type:s,value:s}),a++;continue}if(s==="["){let E=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(E=!0),!E){i.push({type:s,value:s}),a++;continue}}if(s==="]"){i.push({type:s,value:s}),a++;continue}if(s===":"){i.push({type:t.COLON,value:s}),a++;continue}if(s===","){i.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let E=s,m=a+1;for(;m<r.length&&r[m]!==E;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:E}),a=m+1;continue}let c=a,g;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let E=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let A of E){let M=A.substring(1);if(r.substring(c+1,c+1+M.length)===M){m=!0,c+=M.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let E=r[c];for(c++;c<r.length&&r[c]!==E;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;g=r.substring(a,c);let v=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(g)?v=t.NUMBER:g==="true"||g==="false"||g==="null"?v=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(g)&&(v=t.SELECTOR),i.push({type:v,value:g,quoted:!1}),a=c}return i}function o(r){let i="";for(let a=0;a<r.length;a++){let s=r[a];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[a+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let c=s.value;s.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(g,v)=>v.length%2===0?v+'\\"':g)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new Te("Invalid extraction rules syntax: "+r.message,r)}}var Et="1",pn=/^[a-zA-Z0-9_-]+$/;function Re(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!pn.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${pn})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],a=e.attr(i,"data-rules-version");if(a!==Et)throw new ye(a);return{rules:Ae(e.text(i)),tagNode:i}}var Tr="script[data-rules-name]";function hn(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function _e(e,t){let n=e.find(t,Tr,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=hn(e.attr(i,"data-rules-name"));if(!a)continue;if(o.has(a)){console.warn(`hyper-html-api: duplicate rules tag name "${a}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==Et)throw new ye(s);o.add(a),r.push({name:a,rules:Ae(e.text(i))})}return r}function Xe(e,t){let n={};for(let{name:o,rules:r}of _e(e,t))n[o]=ae(e,t,r);return n}function xt(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Xe(X,t),version:ie(n,"hyper-version")}}var Ne=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},$e=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},he=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Be=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var mn="text/hyper-upgrade";function Mt(e,t){let n=e.find(t,`script[type="${mn}"]`);if(n.length===0)return null;if(n.length>1)throw new Be(n.length);return e.text(n[0])||null}var Or=new Function("url","return import(url)");async function wt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Or(n)}catch(r){throw new he(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new he("transform must `export default` a function");return o.default}function bn(e,t,n,o){let r=e.length,i=t.length,a=new Array(r).fill(-1);if(o){let I=new Set;for(let D=0;D<r;D++){let W=o[D];!(W>=0&&W<i)||I.has(W)||(a[D]=W,I.add(W))}}if(r===0||i===0)return a;let s=e.map(I=>gn(I,n)),c=t.map(I=>gn(I,n)),g=new Array(i).fill(!1);for(let I of a)I>=0&&(g[I]=!0);let v=new Map;c.forEach((I,D)=>{g[D]||v.set(I,v.has(I)?-1:D)});let E=new Map;s.forEach((I,D)=>{a[D]>=0||E.set(I,(E.get(I)||0)+1)}),s.forEach((I,D)=>{if(a[D]>=0||E.get(I)!==1)return;let W=v.get(I);W===void 0||W===-1||g[W]||(a[D]=W,g[W]=!0)});let m=[];for(let I=0;I<r;I++)a[I]<0&&m.push(I);let A=[];for(let I=0;I<i;I++)g[I]||A.push(I);if(m.length===0||A.length===0)return a;let M=r*i+1,q=(I,D)=>Rr(e[I],t[D],n)*M+Math.abs(I-D);for(let[I,D]of Nr(m,A,q))a[I]=D;return a}var An=e=>typeof e=="object"&&e!==null;function gn(e,t){if(!An(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function Rr(e,t,n){if(!An(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let a=JSON.stringify(e?.[i]),s=JSON.stringify(t?.[i]);a!==s&&r++}return r}function Nr(e,t,n){return e.length<=t.length?yn(e,t,n,!1):yn(t,e,(o,r)=>n(r,o),!0)}function yn(e,t,n,o){let r=e.length,i=t.length,a=[];for(let E=0;E<=r;E++)a.push(new Float64Array(i+1).fill(1/0));let s=[];for(let E=0;E<=r;E++)s.push(new Uint8Array(i+1));for(let E=0;E<=i;E++)a[r][E]=0;for(let E=r-1;E>=0;E--)for(let m=i-1;m>=0;m--){let A=n(e[E],t[m])+a[E+1][m+1],M=a[E][m+1];A<=M?(a[E][m]=A,s[E][m]=1):a[E][m]=M}let c=[],g=0,v=0;for(;g<r&&v<i;)s[g][v]&&(c.push(o?[t[v],e[g]]:[e[g],t[v]]),g++),v++;return c}function Tt(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(F=>e.remove(F)),vt(s,"onRowsApplied",i.path,[]);return}let g=r.length>c.length,v=c[0]||null;if(g&&!v&&(v=Lr(e,t,n,s),!v))throw new Pe(i.path);let E=c.map(F=>Cr(e,F,o,s)),m=null;if(g&&v){m=e.clone(v),s.templateAttr&&e.removeAttr(m,s.templateAttr);let F=e.stripIds(m);F>0&&console.warn(`[hyper-html-api] stripped ${F} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let A=bn(r,E,o,kr(e,c,r,i,s)),M=c[0]||v,q=e.parent(M),I=c.length>0?Sn(e,q,M):0,D=Hr(e,c),W=new Set,ee=[],se=r.map((F,ne)=>{let Q=A[ne];if(Q>=0)return W.add(Q),ee.push(!1),c[Q];ee.push(!0);let ce=e.clone(m);return e.stripIds(ce),ce});c.forEach((F,ne)=>{W.has(ne)||e.remove(F)}),D?se.forEach((F,ne)=>{let Q=I+ne;e.children(q).findIndex(tt=>e.sameNode(tt,F))!==Q&&e.insertAt(q,F,Q)}):jr(e,se,ee,q,I),Ir(e,se,o,r,i,a,s),vt(s,"onRowsApplied",i.path,se)}function vt(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function kr(e,t,n,o,r){let i=vt(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let a=new Array(n.length).fill(-1),s=new Set;for(let c=0;c<n.length;c++)if(i[c]){for(let g=0;g<t.length;g++)if(!(s.has(g)||!e.sameNode(t[g],i[c]))){a[c]=g,s.add(g);break}}return a}function Ir(e,t,n,o,r,i,a){t.forEach((s,c)=>{if(n===null){let g=o[c],v=g==null?"":String(g);e.text(s)!==v&&e.text(s,v)}else{let g=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},a);g&&g!==s&&(t[c]=g)}})}function Cr(e,t,n,o){return n===null?e.text(t):ae(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Sn(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Lr(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let a of i)if(e.attr(a,o.templateAttr)!=null)return a;r=e.parent(r)}return null}function Hr(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let a=o.findIndex(s=>e.sameNode(s,i));if(a===-1)return!1;r.push(a)}return r.sort((i,a)=>i-a),r[r.length-1]-r[0]===r.length-1}function jr(e,t,n,o,r){let i=null,a=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let c=i?e.parent(i):o;if(!c)continue;let g=i?Sn(e,c,i)+1:a++;e.insertAt(c,t[s],g),i=t[s]}}var En=new Set(["checked","selected","disabled","readOnly","paused"]);function me(e,t,n,o,r={}){let i=[];if(Ot(n,o,[],i),i.length)throw new je(i);et(e,t,n,o,{depth:0,path:[]},r)}function et(e,t,n,o,r,i={}){if(r.depth>Oe)throw new be(r.path);if(o===void 0)return t;if(typeof n=="string")return Pr(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return Tt(e,t,a,s,o,r,et,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=et(e,t,s,o==null?o:o[a],{depth:r.depth+1,path:[...r.path,a]},i);c&&c!==t&&(t=c)}return t}return t}function Pr(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return Tt(e,t,c,null,o,r,et,i),t}if(n.startsWith("@"))return Mn(e,t,n.slice(1),o);let a=de(n);if(a!==-1){let c=n.slice(0,a),g=n.slice(a+1),v=c?e.find(t,c,i):[t];return v.length===0||Mn(e,v[0],g,o),t}if(n===".")return xn(e,t,o),t;let s=e.find(t,n,i);return s.length===0||xn(e,s[0],o),t}function xn(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Mn(e,t,n,o){if(un.has(n))throw new De(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return ln.has(n)?(e.prop(t,n,Dr(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function Dr(e,t){return t==null?En.has(e)?!1:"":En.has(e)?t==="false"?!1:!!t:t}function Ot(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:Ue([...n,i]),expected:"scalar",got:Fe(r)})}):o.push({path:Ue(n),expected:"array",got:Fe(t)});return}t!==null&&typeof t=="object"&&o.push({path:Ue(n),expected:"scalar",got:Fe(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Ue(n),expected:"array",got:Fe(t)});return}let r=e[1];t.forEach((i,a)=>Ot(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Ue(n),expected:"object",got:Fe(t)});return}for(let[r,i]of Object.entries(e))Ot(i,t[r],[...n,r],o)}}}function Fe(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Ue(e){return e.join(".")}function qe(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Rt(t,e,n);return Nt(t,e,n),{data:o,summary:n}}function Rt(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>Rt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=Rt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function Nt(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?Nt(e[r],t[r],n):n.discarded+=Se(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Nt(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=Se(t))}}function Se(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+Se(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+Se(n),0):1}function kt(e,t,n){let o=_e(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},a=new Set;for(let{name:s,rules:c}of o){if(a.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:g,summary:v}=qe(n[s],c);me(e,t,c,g),i[s]=v,r.carriedOver+=v.carriedOver,r.discarded+=v.discarded,r.listItems+=v.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=Se(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function It({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(D=>fetch(D)),!o)throw new Error("upgrade.run requires a document context");if(e=e||ie(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let a=new URL(e,r?r.href:void 0);n=n!==void 0?n:ie(o,"hyper-version"),t=t||Xe(X,o);let s;try{s=await i(a.href)}catch(D){throw new Ne(a.href,D)}if(!s.ok)throw new Ne(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),g=new DOMParser().parseFromString(c,"text/html"),v=ie(g,"hyper-version"),E=t,m=!1,A=Mt(X,g);if(A){let W=await(await wt(A))(E,{fromVersion:n,toVersion:v});if(!W||typeof W!="object"||Array.isArray(W))throw new he("transform must return a plain object map of { rulesName: data }");E=W,m=!0}let{totals:M,byName:q,rulesTagCount:I}=kt(X,g,E);if(I===0&&Object.keys(E).length>0)throw new $e(a.href);return{html:_r(g),fromVersion:n,toVersion:v,summary:{transformApplied:m,totals:M,byName:q}}}function _r(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
4
|
+
`+e.documentElement.outerHTML}function Ct(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return Re(e,o,n)}return null}function wn(e,t,n,o){let r=Ct(e,t,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:a}=r;return{rules:i,tagNode:a,get:()=>ae(e,t,i,o),set:s=>me(e,t,i,s,o)}}var We={extract:(e,t,n)=>ae(X,e,t,n),apply:(e,t,n,o)=>me(X,e,t,n,o),findRulesIn:(e,t)=>Re(X,e,t),findRules:(e,t)=>Ct(X,e,t),bind:(e,t,n)=>wn(X,e,t,n),parseStrict:St,parseRelaxed:Ae,ruleAttrIndex:de,splitRule:we,errors:Qe,DOM_PROPERTIES:Ze},Lt=e=>!!e&&typeof e.nodeType=="number";function vn(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=X.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return Re(X,t).rules}function Ht(e,t){let n=Lt(e)?e:document,o=Lt(e)?t:e;return o===void 0?ae(X,n,vn(n)):We.bind(n,o).get()}function jt(e,t,n){if(!Lt(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?me(X,e,vn(e),t):We.bind(e,n).set(t),e}var Tn={buildForm:ct,bindFormEvents:lt,scaffold:Me,morphForm:mt,path:Ke},On={checkForUpdate:yt,run:It,extractAll:xt,shapeMatch:qe};var Fr={engine:We,cms:Tn,upgrade:On,extractData:Ht,applyData:jt},Ur=Fr;return Pn(qr);})();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var hyperHtmlApiUpgrade=(()=>{var X=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var r in t)X(e,r,{get:t[r],enumerable:!0})},De=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of _e(t))!Pe.call(e,n)&&n!==r&&X(e,n,{get:()=>t[n],enumerable:!(o=Ne(t,n))||o.enumerable});return e};var Le=e=>De(X({},"__esModule",{value:!0}),e);var st={};fe(st,{default:()=>ot,engine:()=>ie,upgrade:()=>Ie});var q=["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(q),ae=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),pe=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var F={};fe(F,{EmptyListInsert:()=>j,MAX_RULE_DEPTH:()=>_,MaxRuleDepthExceeded:()=>w,RuleTargetReadOnly:()=>C,RulesParseError:()=>N,ShapeMismatch:()=>L,UnknownRulesVersion:()=>O});var N=class extends Error{constructor(t,r){super(t),this.name="RulesParseError",this.cause=r}},O=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},_=20,w=class extends Error{constructor(t){super(`rule depth exceeded ${_} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},L=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},j=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}},C=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function x(e){let t=0,r=null,o=-1;for(let n=0;n<e.length;n++){let s=e[n];s==="\\"?n++:r?s===r&&(r=null):s==='"'||s==="'"?r=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:s==="@"&&t===0&&(o=n)}return o}function Z(e){let t=x(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function g(e,t,r,o={}){return ee(e,t,r,{depth:0,path:[]},o)}function ee(e,t,r,o,n){if(o.depth>_)throw new w(o.path);if(typeof r=="string")return je(e,t,r,n);if(Array.isArray(r)){let[s,l]=r;return e.find(t,s,n).map((c,f)=>ee(e,c,l,{depth:o.depth+1,path:[...o.path,f]},n))}if(typeof r=="object"&&r!==null){let s={};for(let[l,i]of Object.entries(r))s[l]=ee(e,t,i,{depth:o.depth+1,path:[...o.path,l]},n);return s}return null}function je(e,t,r,o){if(r.endsWith("[]")){let l=r.slice(0,-2);return e.find(t,l,o).map(i=>e.text(i))}if(r.startsWith("@"))return de(e,t,r.slice(1));let n=x(r);if(n!==-1){let l=r.slice(0,n),i=r.slice(n+1),c=l?e.find(t,l,o):[t];return c.length===0?null:de(e,c[0],i)}if(r===".")return e.text(t);let s=e.find(t,r,o);return s.length===0?null:e.text(s[0])}function de(e,t,r){if(Q.has(r)){let n=e.prop(t,r);return n==null?null:String(n)}let o=e.attr(t,r);return o||null}var Ce=.5;function te(e,t,r,o,n,s,l,i={}){let c=e.find(t,r,i);if(n.length===0){c.forEach(d=>e.remove(d));return}let f=n.length>c.length,u=c[0]||null;if(f&&!u&&(u=He(e,t,r,i),!u))throw new j(s.path);let p=c.map(d=>ke(e,d,o,i)),a=null;if(u){a=e.clone(u),i.templateAttr&&e.removeAttr(a,i.templateAttr);let d=e.stripIds(a);d>0&&console.warn(`[hyper-html-api] stripped ${d} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let E=$e(n,p,o),m=c[0]||u,R=e.parent(m),W=c.length>0?me(e,R,m):0,I=We(e,c),A=new Set,Y=[],B=n.map((d,D)=>{let M=E[D];if(M>=0)return A.add(M),Y.push(!1),c[M];Y.push(!0);let z=e.clone(a);return e.stripIds(z),z});if(c.forEach((d,D)=>{A.has(D)||e.remove(d)}),I){B.forEach((d,D)=>{let M=W+D;e.children(R).findIndex(Me=>e.sameNode(Me,d))!==M&&e.insertAt(R,d,M)}),he(e,B,o,n,s,l,i);return}Be(e,B,Y,R,W),he(e,B,o,n,s,l,i)}function he(e,t,r,o,n,s,l){t.forEach((i,c)=>{if(r===null){let f=o[c],u=f==null?"":String(f);e.text(i)!==u&&e.text(i,u)}else{let f=s(e,i,r,o[c],{depth:n.depth+1,path:[...n.path,c]},l);f&&f!==i&&(t[c]=f)}})}function ke(e,t,r,o){return r===null?e.text(t):g(e,t,r,o)}function $e(e,t,r){let o=new Array(e.length).fill(-1),n=new Set;return e.forEach((s,l)=>{let i=-1,c=-1;t.forEach((f,u)=>{if(n.has(u))return;let p=Ue(s,f,r),a=p===c&&i>=0?Math.abs(u-l)<Math.abs(i-l):!1;(p>c||a)&&(c=p,i=u)}),c>=Ce&&(o[l]=i,n.add(i))}),o}function Ue(e,t,r){if(r===null)return e===t?1:0;let o=Object.keys(r||{});if(o.length===0)return 0;let n=0;for(let s of o)JSON.stringify(e?.[s])===JSON.stringify(t?.[s])&&n++;return n/o.length}function me(e,t,r){let o=e.children(t);for(let n=0;n<o.length;n++)if(e.sameNode(o[n],r))return n;return-1}function He(e,t,r,o){if(!o.templateAttr)return null;let n=t;for(;n;){let s=e.find(n,r,{includeRulesTag:!1,templateAttr:null});for(let l of s)if(e.attr(l,o.templateAttr)!=null)return l;n=e.parent(n)}return null}function We(e,t){if(t.length<=1)return!0;let r=e.parent(t[0]);if(!r)return!1;let o=e.children(r),n=[];for(let s of t){let l=o.findIndex(i=>e.sameNode(i,s));if(l===-1)return!1;n.push(l)}return n.sort((s,l)=>s-l),n[n.length-1]-n[0]===n.length-1}function Be(e,t,r,o,n){let s=null,l=n;for(let i=0;i<t.length;i++){if(!r[i]){s=t[i];continue}let c=s?e.parent(s):o;if(!c)continue;let f=s?me(e,c,s)+1:l++;e.insertAt(c,t[i],f),s=t[i]}}var ge=new Set(["checked","selected","disabled","readOnly","paused"]);function T(e,t,r,o,n={}){let s=[];if(re(r,o,[],s),s.length)throw new L(s);J(e,t,r,o,{depth:0,path:[]},n)}function J(e,t,r,o,n,s={}){if(n.depth>_)throw new w(n.path);if(o===void 0)return t;if(typeof r=="string")return qe(e,t,r,o,n,s);if(Array.isArray(r)){let[l,i]=r;return te(e,t,l,i,o,n,J,s),t}if(typeof r=="object"&&r!==null){for(let[l,i]of Object.entries(r)){let c=J(e,t,i,o==null?o:o[l],{depth:n.depth+1,path:[...n.path,l]},s);c&&c!==t&&(t=c)}return t}return t}function qe(e,t,r,o,n,s){if(r.endsWith("[]")){let c=r.slice(0,-2);return te(e,t,c,null,o,n,J,s),t}if(r.startsWith("@"))return ye(e,t,r.slice(1),o);let l=x(r);if(l!==-1){let c=r.slice(0,l),f=r.slice(l+1),u=c?e.find(t,c,s):[t];return u.length===0||ye(e,u[0],f,o),t}if(r===".")return e.text(t,o==null?"":String(o)),t;let i=e.find(t,r,s);return i.length===0||e.text(i[0],o==null?"":String(o)),t}function ye(e,t,r,o){if(pe.has(r))throw new C(r);if(r==="outerHTML"){let n=o==null?"":String(o);return e.replaceWith(t,n)}return ae.has(r)?(e.prop(t,r,Fe(r,o)),t):(e.attr(t,r,o==null?"":String(o)),t)}function Fe(e,t){return t==null?ge.has(e)?!1:"":ge.has(e)?!!t:t}function re(e,t,r,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((n,s)=>{typeof n=="object"&&n!==null&&o.push({path:$([...r,s]),expected:"scalar",got:k(n)})}):o.push({path:$(r),expected:"array",got:k(t)});return}t!==null&&typeof t=="object"&&o.push({path:$(r),expected:"scalar",got:k(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:$(r),expected:"array",got:k(t)});return}let n=e[1];t.forEach((s,l)=>re(n,s,[...r,l],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:$(r),expected:"object",got:k(t)});return}for(let[n,s]of Object.entries(e))re(s,t[n],[...r,n],o)}}}function k(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function $(e){return e.join(".")}function ne(e){try{return JSON.parse(e)}catch(t){throw new N(`Invalid strict JSON: ${t.message}`,t)}}function S(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(n){let s=[],l=0;for(;l<n.length;){let i=n[l];if(/\s/.test(i)){l++;continue}if("{}".includes(i)){s.push({type:i,value:i}),l++;continue}if(i==="["){let p=!1,a=l+1;for(;a<n.length&&/\s/.test(n[a]);)a++;if(a<n.length&&/[a-zA-Z_]/.test(n[a])&&(p=!0),!p){s.push({type:i,value:i}),l++;continue}}if(i==="]"){s.push({type:i,value:i}),l++;continue}if(i===":"){s.push({type:t.COLON,value:i}),l++;continue}if(i===","){s.push({type:t.COMMA,value:i}),l++;continue}if(i==='"'||i==="'"){let p=i,a=l+1;for(;a<n.length&&n[a]!==p;)n[a]==="\\"&&a++,a++;s.push({type:t.STRING,value:n.substring(l+1,a),quoted:!0,sourceQuote:p}),l=a+1;continue}let c=l,f;for(;c<n.length&&!/[{},]/.test(n[c]);)if(n[c]===":"){let p=[":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"],a=!1;for(let E of p){let m=E.substring(1);if(n.substring(c+1,c+1+m.length)===m){a=!0,c+=m.length;break}}if(!a)break}else if(n[c]==="["){for(c++;c<n.length&&n[c]!=="]";){if(n[c]==='"'||n[c]==="'"){let p=n[c];for(c++;c<n.length&&n[c]!==p;)n[c]==="\\"&&c++,c++}c++}c<n.length&&n[c]==="]"&&c++}else c++;f=n.substring(l,c);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),s.push({type:u,value:f,quoted:!1}),l=c}return s}function o(n){let s="";for(let l=0;l<n.length;l++){let i=n[l];if("{}".includes(i.type)||"[]".includes(i.type)){s+=i.value;continue}if(i.type===t.COLON){s+=i.value;continue}if(i.type===t.COMMA){let c=n[l+1];if(c&&(c.type==="}"||c.type==="]"))continue;s+=i.value;continue}if(i.type===t.STRING&&i.quoted){let c=i.value;i.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),s+=`"${c}"`;continue}if(i.type===t.NUMBER||i.type===t.BOOLEAN){s+=i.value;continue}if(i.type===t.SELECTOR||i.type===t.IDENTIFIER){s+=`"${i.value}"`;continue}s+=`"${i.value}"`}return s}try{let n=r(e),s=o(n);return JSON.parse(s)}catch(n){throw new N("Invalid extraction rules syntax: "+n.message,n)}}var oe="1",Ee=/^[a-zA-Z0-9_-]+$/;function U(e,t,r){let o;if(r===void 0)o="script[data-rules-name]";else{if(typeof r!="string"||!Ee.test(r))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(r)} (must match ${Ee})`);o=`script[data-rules-name~="${r}"]`}let n=e.find(t,o,{includeRulesTag:!0});if(n.length===0)return null;r!==void 0&&n.length>1&&console.warn(`hyper-html-api: ${n.length} rules tags match data-rules-name~="${r}"; using the first.`);let s=n[0],l=e.attr(s,"data-rules-version");if(l!==oe)throw new O(l);return{rules:S(e.text(s)),tagNode:s}}function se(e,t,r){if(r&&typeof r=="object")return{rules:r,tagNode:null};if(typeof r=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return U(e,o,r)}return null}function xe(e,t,r,o){let n=se(e,t,r);if(!n){let i=typeof r=="string"?`data-rules-name~="${r}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${i}`)}let{rules:s,tagNode:l}=n;return{rules:s,tagNode:l,get:()=>g(e,t,s,o),set:i=>T(e,t,s,i,o)}}function Ve(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function ve(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Ke={find(e,t,r={}){let o=ve(e);if(!o||!o.querySelectorAll)return[];let n=Array.from(o.querySelectorAll(t));r.includeRulesTag||(n=n.filter(i=>!Ve(i)));let s=[];r.skip&&s.push(r.skip);let l=r.templateAttr===null?null:r.templateAttr||"cms-template";if(l&&s.push("["+l+"]"),s.length){let i=s.join(", ");n=n.filter(c=>!c.closest||!c.closest(i))}return n},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,r){if(r===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=r},clone(e){return e.cloneNode(!0)},insertAt(e,t,r){let o=e.children[r]||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 n=o.content.firstElementChild;if(!n)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(n,e),n},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}},h=Ke;var ie={extract:(e,t,r)=>g(h,e,t,r),apply:(e,t,r,o)=>T(h,e,t,r,o),findRulesIn:(e,t)=>U(h,e,t),findRules:(e,t)=>se(h,e,t),bind:(e,t,r)=>xe(h,e,t,r),parseStrict:ne,parseRelaxed:S,ruleAttrIndex:x,splitRule:Z,errors:F,DOM_PROPERTIES:q};var Ge="hha:upgrade-check:";function y(e,t){let r=e.querySelector(`meta[name="${t}"]`),o=r?r.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function Re(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ye(e,t){let r=Re(e),o=Re(t);if(!r||!o)return!1;let n=Math.max(r.length,o.length);for(let s=0;s<n;s++){let l=r[s]||0,i=o[s]||0;if(l!==i)return l>i}return!1}function ze(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Xe(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Ae({force:e=!1,doc:t,loc:r,fetchFn:o,now:n,ttlMs:s=864e5}={}){if(t=t||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),o=o||(a=>fetch(a)),n=n??Date.now(),!t)return null;let l=y(t,"hyper-source");if(!l)return null;let i=y(t,"hyper-version"),c;try{c=new URL(l,r?r.href:void 0)}catch{return null}if(r&&c.origin===r.origin&&c.pathname===r.pathname)return null;let f=`${Ge}${c.href}:${i||"none"}`,u,p=e?null:ze(f);if(p&&typeof p.checkedAt=="number"&&n-p.checkedAt<s)u=p.sourceVersion;else{try{let a=await o(c.href);if(!a.ok)throw new Error(`HTTP ${a.status}`);let E=await a.text(),m=new DOMParser().parseFromString(E,"text/html");u=y(m,"hyper-version")}catch{u=null}Xe(f,{checkedAt:n,sourceVersion:u})}return u?{available:Ye(u,i||"0.0.0"),currentVersion:i,sourceVersion:u,sourceUrl:c.href}:null}var Qe="script[data-rules-name]";function Ze(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function V(e,t){let r=e.find(t,Qe,{includeRulesTag:!0}),o=new Set,n=[];for(let s of r){let l=Ze(e.attr(s,"data-rules-name"));if(!l)continue;if(o.has(l)){console.warn(`hyper-html-api: duplicate rules tag name "${l}"; using the first.`);continue}let i=e.attr(s,"data-rules-version");if(i!==oe)throw new O(i);o.add(l),n.push({name:l,rules:S(e.text(s))})}return n}function le(e,t){let r={};for(let{name:o,rules:n}of V(e,t))r[o]=g(e,t,n);return r}function Oe(e){let t=e||document,r=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:le(h,t),version:y(r,"hyper-version")}}var H=class extends Error{constructor(t,r){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=r}},v=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}},b=class extends Error{constructor(t,r){super(t),this.name="UpgradeTransformInvalid",this.cause=r}},K=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 et="text/hyper-upgrade";function we(e,t){let r=e.find(t,`script[type="${et}"]`);if(r.length===0)return null;if(r.length>1)throw new K(r.length);return e.text(r[0])||null}var tt=new Function("url","return import(url)");async function Te(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t),o;try{o=await tt(r)}catch(n){throw new b(`transform failed to load: ${n&&n.message?n.message:n}`,n)}finally{URL.revokeObjectURL(r)}if(typeof o.default!="function")throw new b("transform must `export default` a function");return o.default}function G(e,t){let r={carriedOver:0,discarded:0,listItems:0},o=ce(t,e,r);return ue(t,e,r),{data:o,summary:r}}function ce(e,t,r){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(r.listItems+=t.length,r.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(r.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(r.listItems+=t.length,t.map(n=>ce(o,n,r))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[n,s]of Object.entries(e)){let l=ce(s,t?.[n],r);l!==void 0&&(o[n]=l)}return o}}function ue(e,t,r){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 n of Object.keys(t))o.has(n)?ue(e[n],t[n],r):r.discarded+=P(t[n]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(n=>ue(o,n,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=P(t))}}function P(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+P(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+P(r),0):1}function Se(e,t,r){let o=V(e,t),n={carriedOver:0,discarded:0,listItems:0},s={},l=new Set;for(let{name:i,rules:c}of o){if(l.add(i),!Object.prototype.hasOwnProperty.call(r,i)){s[i]={carriedOver:0,discarded:0,listItems:0};continue}let{data:f,summary:u}=G(r[i],c);T(e,t,c,f),s[i]=u,n.carriedOver+=u.carriedOver,n.discarded+=u.discarded,n.listItems+=u.listItems}for(let i of Object.keys(r))l.has(i)||(n.discarded+=P(r[i]));return{totals:n,byName:s,rulesTagCount:o.length}}async function be({sourceUrl:e,dataByName:t,fromVersion:r,doc:o,loc:n,fetchFn:s}={}){if(o=o||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),s=s||(I=>fetch(I)),!o)throw new Error("upgrade.run requires a document context");if(e=e||y(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let l=new URL(e,n?n.href:void 0);r=r!==void 0?r:y(o,"hyper-version"),t=t||le(h,o);let i;try{i=await s(l.href)}catch(I){throw new H(l.href,I)}if(!i.ok)throw new H(l.href,new Error(`HTTP ${i.status}`));let c=await i.text(),f=new DOMParser().parseFromString(c,"text/html"),u=y(f,"hyper-version"),p=t,a=!1,E=we(h,f);if(E){let A=await(await Te(E))(p,{fromVersion:r,toVersion:u});if(!A||typeof A!="object"||Array.isArray(A))throw new b("transform must return a plain object map of { rulesName: data }");p=A,a=!0}let{totals:m,byName:R,rulesTagCount:W}=Se(h,f,p);if(W===0&&Object.keys(p).length>0)throw new v(l.href);return{html:rt(f),fromVersion:r,toVersion:u,summary:{transformApplied:a,totals:m,byName:R}}}function rt(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
2
|
-
`+e.documentElement.outerHTML}var
|
|
1
|
+
var hyperHtmlApiUpgrade=(()=>{var Y=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var $e=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},Ue=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ce(t))!$e.call(e,r)&&r!==n&&Y(e,r,{get:()=>t[r],enumerable:!(o=Le(t,r))||o.enumerable});return e};var He=e=>Ue(Y({},"__esModule",{value:!0}),e);var pt={};ae(pt,{default:()=>at,engine:()=>le,upgrade:()=>De});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"],Q=new Set(F),pe=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),de=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var J={};ae(J,{EmptyListInsert:()=>L,MAX_RULE_DEPTH:()=>_,MaxRuleDepthExceeded:()=>T,RuleTargetReadOnly:()=>C,RulesParseError:()=>j,ShapeMismatch:()=>k,UnknownRulesVersion:()=>S});var j=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},S=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},_=20,T=class extends Error{constructor(t){super(`rule depth exceeded ${_} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},k=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},L=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}},C=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function O(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 Z(e){let t=O(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function x(e,t,n,o={}){return ee(e,t,n,{depth:0,path:[]},o)}function ee(e,t,n,o,r){if(o.depth>_)throw new T(o.path);if(typeof n=="string")return We(e,t,n,o,r);if(Array.isArray(n)){let[i,l]=n,s=e.find(t,i,r);return me(r,o,s),s.map((c,f)=>ee(e,c,l,{depth:o.depth+1,path:[...o.path,f]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[l,s]of Object.entries(n))i[l]=ee(e,t,s,{depth:o.depth+1,path:[...o.path,l]},r);return i}return null}function We(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),c=e.find(t,s,r);return me(r,o,c),c.map(f=>e.text(f))}if(n.startsWith("@"))return he(e,t,n.slice(1));let i=O(n);if(i!==-1){let s=n.slice(0,i),c=n.slice(i+1),f=s?e.find(t,s,r):[t];return f.length===0?null:he(e,f[0],c)}if(n===".")return e.text(t);let l=e.find(t,n,r);return l.length===0?null:e.text(l[0])}function me(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 he(e,t,n){if(Q.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Ee(e,t,n,o){let r=e.length,i=t.length,l=new Array(r).fill(-1);if(o){let d=new Set;for(let h=0;h<r;h++){let m=o[h];!(m>=0&&m<i)||d.has(m)||(l[h]=m,d.add(m))}}if(r===0||i===0)return l;let s=e.map(d=>ye(d,n)),c=t.map(d=>ye(d,n)),f=new Array(i).fill(!1);for(let d of l)d>=0&&(f[d]=!0);let u=new Map;c.forEach((d,h)=>{f[h]||u.set(d,u.has(d)?-1:h)});let a=new Map;s.forEach((d,h)=>{l[h]>=0||a.set(d,(a.get(d)||0)+1)}),s.forEach((d,h)=>{if(l[h]>=0||a.get(d)!==1)return;let m=u.get(d);m===void 0||m===-1||f[m]||(l[h]=m,f[m]=!0)});let p=[];for(let d=0;d<r;d++)l[d]<0&&p.push(d);let y=[];for(let d=0;d<i;d++)f[d]||y.push(d);if(p.length===0||y.length===0)return l;let g=r*i+1,w=(d,h)=>Be(e[d],t[h],n)*g+Math.abs(d-h);for(let[d,h]of Fe(p,y,w))l[d]=h;return l}var Re=e=>typeof e=="object"&&e!==null;function ye(e,t){if(!Re(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 Be(e,t,n){if(!Re(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 l=JSON.stringify(e?.[i]),s=JSON.stringify(t?.[i]);l!==s&&r++}return r}function Fe(e,t,n){return e.length<=t.length?ge(e,t,n,!1):ge(t,e,(o,r)=>n(r,o),!0)}function ge(e,t,n,o){let r=e.length,i=t.length,l=[];for(let a=0;a<=r;a++)l.push(new Float64Array(i+1).fill(1/0));let s=[];for(let a=0;a<=r;a++)s.push(new Uint8Array(i+1));for(let a=0;a<=i;a++)l[r][a]=0;for(let a=r-1;a>=0;a--)for(let p=i-1;p>=0;p--){let y=n(e[a],t[p])+l[a+1][p+1],g=l[a][p+1];y<=g?(l[a][p]=y,s[a][p]=1):l[a][p]=g}let c=[],f=0,u=0;for(;f<r&&u<i;)s[f][u]&&(c.push(o?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return c}function ne(e,t,n,o,r,i,l,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(E=>e.remove(E)),te(s,"onRowsApplied",i.path,[]);return}let f=r.length>c.length,u=c[0]||null;if(f&&!u&&(u=ve(e,t,n,s),!u))throw new L(i.path);let a=c.map(E=>qe(e,E,o,s)),p=null;if(f&&u){p=e.clone(u),s.templateAttr&&e.removeAttr(p,s.templateAttr);let E=e.stripIds(p);E>0&&console.warn(`[hyper-html-api] stripped ${E} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let y=Ee(r,a,o,Je(e,c,r,i,s)),g=c[0]||u,w=e.parent(g),d=c.length>0?we(e,w,g):0,h=Ve(e,c),m=new Set,z=[],B=r.map((E,D)=>{let M=y[D];if(M>=0)return m.add(M),z.push(!1),c[M];z.push(!0);let X=e.clone(p);return e.stripIds(X),X});c.forEach((E,D)=>{m.has(D)||e.remove(E)}),h?B.forEach((E,D)=>{let M=d+D;e.children(w).findIndex(ke=>e.sameNode(ke,E))!==M&&e.insertAt(w,E,M)}):Ge(e,B,z,w,d),Ke(e,B,o,r,i,l,s),te(s,"onRowsApplied",i.path,B)}function te(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 Je(e,t,n,o,r){let i=te(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let l=new Array(n.length).fill(-1),s=new Set;for(let c=0;c<n.length;c++)if(i[c]){for(let f=0;f<t.length;f++)if(!(s.has(f)||!e.sameNode(t[f],i[c]))){l[c]=f,s.add(f);break}}return l}function Ke(e,t,n,o,r,i,l){t.forEach((s,c)=>{if(n===null){let f=o[c],u=f==null?"":String(f);e.text(s)!==u&&e.text(s,u)}else{let f=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},l);f&&f!==s&&(t[c]=f)}})}function qe(e,t,n,o){return n===null?e.text(t):x(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function we(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 ve(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 l of i)if(e.attr(l,o.templateAttr)!=null)return l;r=e.parent(r)}return null}function Ve(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 l=o.findIndex(s=>e.sameNode(s,i));if(l===-1)return!1;r.push(l)}return r.sort((i,l)=>i-l),r[r.length-1]-r[0]===r.length-1}function Ge(e,t,n,o,r){let i=null,l=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 f=i?we(e,c,i)+1:l++;e.insertAt(c,t[s],f),i=t[s]}}var xe=new Set(["checked","selected","disabled","readOnly","paused"]);function b(e,t,n,o,r={}){let i=[];if(re(n,o,[],i),i.length)throw new k(i);K(e,t,n,o,{depth:0,path:[]},r)}function K(e,t,n,o,r,i={}){if(r.depth>_)throw new T(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[l,s]=n;return ne(e,t,l,s,o,r,K,i),t}if(typeof n=="object"&&n!==null){for(let[l,s]of Object.entries(n)){let c=K(e,t,s,o==null?o:o[l],{depth:r.depth+1,path:[...r.path,l]},i);c&&c!==t&&(t=c)}return t}return t}function ze(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return ne(e,t,c,null,o,r,K,i),t}if(n.startsWith("@"))return Oe(e,t,n.slice(1),o);let l=O(n);if(l!==-1){let c=n.slice(0,l),f=n.slice(l+1),u=c?e.find(t,c,i):[t];return u.length===0||Oe(e,u[0],f,o),t}if(n===".")return Ae(e,t,o),t;let s=e.find(t,n,i);return s.length===0||Ae(e,s[0],o),t}function Ae(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Oe(e,t,n,o){if(de.has(n))throw new C(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return pe.has(n)?(e.prop(t,n,Xe(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function Xe(e,t){return t==null?xe.has(e)?!1:"":xe.has(e)?t==="false"?!1:!!t:t}function re(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:U([...n,i]),expected:"scalar",got:$(r)})}):o.push({path:U(n),expected:"array",got:$(t)});return}t!==null&&typeof t=="object"&&o.push({path:U(n),expected:"scalar",got:$(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:U(n),expected:"array",got:$(t)});return}let r=e[1];t.forEach((i,l)=>re(r,i,[...n,l],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:U(n),expected:"object",got:$(t)});return}for(let[r,i]of Object.entries(e))re(i,t[r],[...n,r],o)}}}function $(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function U(e){return e.join(".")}function oe(e){try{return JSON.parse(e)}catch(t){throw new j(`Invalid strict JSON: ${t.message}`,t)}}function I(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=[],l=0;for(;l<r.length;){let s=r[l];if(/\s/.test(s)){l++;continue}if("{}".includes(s)){i.push({type:s,value:s}),l++;continue}if(s==="["){let a=!1,p=l+1;for(;p<r.length&&/\s/.test(r[p]);)p++;if(p<r.length&&/[a-zA-Z_]/.test(r[p])&&(a=!0),!a){i.push({type:s,value:s}),l++;continue}}if(s==="]"){i.push({type:s,value:s}),l++;continue}if(s===":"){i.push({type:t.COLON,value:s}),l++;continue}if(s===","){i.push({type:t.COMMA,value:s}),l++;continue}if(s==='"'||s==="'"){let a=s,p=l+1;for(;p<r.length&&r[p]!==a;)r[p]==="\\"&&p++,p++;i.push({type:t.STRING,value:r.substring(l+1,p),quoted:!0,sourceQuote:a}),l=p+1;continue}let c=l,f;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){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"],p=!1;for(let y of a){let g=y.substring(1);if(r.substring(c+1,c+1+g.length)===g){p=!0,c+=g.length;break}}if(!p)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let a=r[c];for(c++;c<r.length&&r[c]!==a;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;f=r.substring(l,c);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),i.push({type:u,value:f,quoted:!1}),l=c}return i}function o(r){let i="";for(let l=0;l<r.length;l++){let s=r[l];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[l+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,(f,u)=>u.length%2===0?u+'\\"':f)),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 j("Invalid extraction rules syntax: "+r.message,r)}}var ie="1",Se=/^[a-zA-Z0-9_-]+$/;function H(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Se.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Se})`);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],l=e.attr(i,"data-rules-version");if(l!==ie)throw new S(l);return{rules:I(e.text(i)),tagNode:i}}function se(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 H(e,o,n)}return null}function Te(e,t,n,o){let r=se(e,t,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:l}=r;return{rules:i,tagNode:l,get:()=>x(e,t,i,o),set:s=>b(e,t,i,s,o)}}function Qe(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Ze(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var et={find(e,t,n={}){let o=Ze(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Qe(s)));let i=[];n.skip&&i.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&i.push("["+l+"]"),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}},R=et;var le={extract:(e,t,n)=>x(R,e,t,n),apply:(e,t,n,o)=>b(R,e,t,n,o),findRulesIn:(e,t)=>H(R,e,t),findRules:(e,t)=>se(R,e,t),bind:(e,t,n)=>Te(R,e,t,n),parseStrict:oe,parseRelaxed:I,ruleAttrIndex:O,splitRule:Z,errors:J,DOM_PROPERTIES:F};var tt="hha:upgrade-check:";function A(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function be(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function nt(e,t){let n=be(e),o=be(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let l=n[i]||0,s=o[i]||0;if(l!==s)return l>s}return!1}function rt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function ot(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Ie({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||(p=>fetch(p)),r=r??Date.now(),!t)return null;let l=A(t,"hyper-source");if(!l)return null;let s=A(t,"hyper-version"),c;try{c=new URL(l,n?n.href:void 0)}catch{return null}if(n&&c.origin===n.origin&&c.pathname===n.pathname)return null;let f=`${tt}${c.href}:${s||"none"}`,u,a=e?null:rt(f);if(a&&typeof a.checkedAt=="number"&&r-a.checkedAt<i)u=a.sourceVersion;else{try{let p=await o(c.href);if(!p.ok)throw new Error(`HTTP ${p.status}`);let y=await p.text(),g=new DOMParser().parseFromString(y,"text/html");u=A(g,"hyper-version")}catch{u=null}ot(f,{checkedAt:r,sourceVersion:u})}return u?{available:nt(u,s||"0.0.0"),currentVersion:s,sourceVersion:u,sourceUrl:c.href}:null}var it="script[data-rules-name]";function st(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function q(e,t){let n=e.find(t,it,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let l=st(e.attr(i,"data-rules-name"));if(!l)continue;if(o.has(l)){console.warn(`hyper-html-api: duplicate rules tag name "${l}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==ie)throw new S(s);o.add(l),r.push({name:l,rules:I(e.text(i))})}return r}function ce(e,t){let n={};for(let{name:o,rules:r}of q(e,t))n[o]=x(e,t,r);return n}function Ne(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:ce(R,t),version:A(n,"hyper-version")}}var W=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},v=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}},N=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},V=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 lt="text/hyper-upgrade";function Me(e,t){let n=e.find(t,`script[type="${lt}"]`);if(n.length===0)return null;if(n.length>1)throw new V(n.length);return e.text(n[0])||null}var ct=new Function("url","return import(url)");async function je(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await ct(n)}catch(r){throw new N(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new N("transform must `export default` a function");return o.default}function G(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=fe(t,e,n);return ue(t,e,n),{data:o,summary:n}}function fe(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=>fe(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let l=fe(i,t?.[r],n);l!==void 0&&(o[r]=l)}return o}}function ue(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)?ue(e[r],t[r],n):n.discarded+=P(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>ue(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=P(t))}}function P(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+P(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+P(n),0):1}function _e(e,t,n){let o=q(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},l=new Set;for(let{name:s,rules:c}of o){if(l.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:f,summary:u}=G(n[s],c);b(e,t,c,f),i[s]=u,r.carriedOver+=u.carriedOver,r.discarded+=u.discarded,r.listItems+=u.listItems}for(let s of Object.keys(n))l.has(s)||(r.discarded+=P(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function Pe({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||(h=>fetch(h)),!o)throw new Error("upgrade.run requires a document context");if(e=e||A(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let l=new URL(e,r?r.href:void 0);n=n!==void 0?n:A(o,"hyper-version"),t=t||ce(R,o);let s;try{s=await i(l.href)}catch(h){throw new W(l.href,h)}if(!s.ok)throw new W(l.href,new Error(`HTTP ${s.status}`));let c=await s.text(),f=new DOMParser().parseFromString(c,"text/html"),u=A(f,"hyper-version"),a=t,p=!1,y=Me(R,f);if(y){let m=await(await je(y))(a,{fromVersion:n,toVersion:u});if(!m||typeof m!="object"||Array.isArray(m))throw new N("transform must return a plain object map of { rulesName: data }");a=m,p=!0}let{totals:g,byName:w,rulesTagCount:d}=_e(R,f,a);if(d===0&&Object.keys(a).length>0)throw new v(l.href);return{html:ft(f),fromVersion:n,toVersion:u,summary:{transformApplied:p,totals:g,byName:w}}}function ft(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
|
|
2
|
+
`+e.documentElement.outerHTML}var De={checkForUpdate:Ie,run:Pe,extractAll:Ne,shapeMatch:G};var ut={engine:le,upgrade:De},at=ut;return He(pt);})();
|
package/package.json
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
"apply",
|
|
10
10
|
"CMS"
|
|
11
11
|
],
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.8.0",
|
|
13
13
|
"homepage": "https://github.com/panphora/hyper-html-api",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/panphora/hyper-html-api/issues"
|
|
16
16
|
},
|
|
17
|
-
"license": "
|
|
17
|
+
"license": "MIT-0",
|
|
18
18
|
"files": [
|
|
19
19
|
"LICENSE",
|
|
20
20
|
"README.md",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"build:upgrade": "npx esbuild src/upgrade.js --bundle --minify --format=iife --global-name=hyperHtmlApiUpgrade --outfile=dist/hyper-html-api.upgrade.min.js",
|
|
41
41
|
"copy-to-hyperclayjs": "npm run build:engine && npm run build:upgrade && node scripts/copy-to-hyperclayjs.js",
|
|
42
42
|
"copy-to-clayjs": "npm run build:engine && node scripts/copy-to-clayjs.js",
|
|
43
|
-
"prepublishOnly": "npm run build",
|
|
43
|
+
"prepublishOnly": "npm run build && npm run build:engine && npm run build:upgrade",
|
|
44
44
|
"demo": "http-server . -p 5693 -c-1 -o /demo/",
|
|
45
45
|
"test": "web-test-runner",
|
|
46
46
|
"test:debug": "web-test-runner --manual --open",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"url": "git+https://github.com/panphora/hyper-html-api.git"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"hyper-morph": "^0.5.
|
|
64
|
+
"hyper-morph": "^0.5.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@web/test-runner": "^0.20.0",
|
package/src/engine/apply.js
CHANGED
|
@@ -76,16 +76,28 @@ function applyScalar(adapter, ctx, rule, value, trace, opts) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
if (rule === '.') {
|
|
79
|
-
adapter
|
|
79
|
+
writeText(adapter, ctx, value)
|
|
80
80
|
return ctx
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const matches = adapter.find(ctx, rule, opts)
|
|
84
84
|
if (matches.length === 0) return ctx
|
|
85
|
-
adapter
|
|
85
|
+
writeText(adapter, matches[0], value)
|
|
86
86
|
return ctx
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
// Writing identical text still replaces the text node, so an apply of unchanged
|
|
90
|
+
// data emitted a childList record for every text rule on the page. The CMS
|
|
91
|
+
// re-applies the whole page on each keystroke, so those records reached the undo
|
|
92
|
+
// observer and live sync on every one. Scalar lists already compared before
|
|
93
|
+
// writing (see writeItems); this is the same comparison for every other text
|
|
94
|
+
// rule. adapter.text reads trimmed, so surrounding whitespace alone no longer
|
|
95
|
+
// counts as a change, which is exactly what writeItems has always done.
|
|
96
|
+
function writeText(adapter, node, value) {
|
|
97
|
+
const target = value == null ? '' : String(value)
|
|
98
|
+
if (adapter.text(node) !== target) adapter.text(node, target)
|
|
99
|
+
}
|
|
100
|
+
|
|
89
101
|
// Returns the (possibly new) node. For outerHTML, the original is detached
|
|
90
102
|
// and a freshly parsed element takes its place; that new node is returned.
|
|
91
103
|
// For every other write, returns the original node unchanged.
|
package/src/engine/diff.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EmptyListInsert } from './errors.js'
|
|
2
2
|
import { extract } from './extract.js'
|
|
3
|
-
|
|
4
|
-
const SIMILARITY_THRESHOLD = 0.5
|
|
3
|
+
import { matchRows } from './row-match.js'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Reconcile `newItems` (array of incoming items) into the DOM subtree matched
|
|
@@ -16,6 +15,8 @@ export function listDiff(adapter, parentCtx, selector, shape, newItems, trace, a
|
|
|
16
15
|
|
|
17
16
|
if (newItems.length === 0) {
|
|
18
17
|
oldNodes.forEach((n) => adapter.remove(n))
|
|
18
|
+
// Still once per list: a consumer keyed by path has to learn it settled empty.
|
|
19
|
+
callHook(opts, 'onRowsApplied', trace.path, [])
|
|
19
20
|
return
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -28,8 +29,11 @@ export function listDiff(adapter, parentCtx, selector, shape, newItems, trace, a
|
|
|
28
29
|
|
|
29
30
|
const oldValues = oldNodes.map((n) => extractItem(adapter, n, shape, opts))
|
|
30
31
|
|
|
32
|
+
// Only a list that grew can need a clone, because matchRows pairs every row
|
|
33
|
+
// it can. Cloning unconditionally made a plain edit strip the ids off a
|
|
34
|
+
// template it never used, and warn about it, on every keystroke.
|
|
31
35
|
let template = null
|
|
32
|
-
if (templateSource) {
|
|
36
|
+
if (needsTemplate && templateSource) {
|
|
33
37
|
template = adapter.clone(templateSource)
|
|
34
38
|
if (opts.templateAttr) adapter.removeAttr(template, opts.templateAttr)
|
|
35
39
|
const stripped = adapter.stripIds(template)
|
|
@@ -41,7 +45,7 @@ export function listDiff(adapter, parentCtx, selector, shape, newItems, trace, a
|
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
const matches =
|
|
48
|
+
const matches = matchRows(newItems, oldValues, shape, lockSuppliedRows(adapter, oldNodes, newItems, trace, opts))
|
|
45
49
|
|
|
46
50
|
const referenceNode = oldNodes[0] || templateSource
|
|
47
51
|
const parent = adapter.parent(referenceNode)
|
|
@@ -83,19 +87,61 @@ export function listDiff(adapter, parentCtx, selector, shape, newItems, trace, a
|
|
|
83
87
|
if (currentIdx === targetIdx) return
|
|
84
88
|
adapter.insertAt(parent, node, targetIdx)
|
|
85
89
|
})
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
} else {
|
|
91
|
+
// The matched nodes are not a contiguous run of siblings, so this list has
|
|
92
|
+
// no DOM order to restore: any repositioning would move elements the list
|
|
93
|
+
// does not own. Anchoring every node to parent(oldNodes[0]) is what
|
|
94
|
+
// reparents a cross-parent list into its first container and compacts past
|
|
95
|
+
// unowned siblings, and both destroy content on a write that changed
|
|
96
|
+
// nothing. Leave every surviving node exactly where the author put it and
|
|
97
|
+
// only place the grown ones.
|
|
98
|
+
placeGrownItems(adapter, finalNodes, fresh, parent, anchorIdx)
|
|
88
99
|
}
|
|
89
100
|
|
|
90
|
-
// The matched nodes are not a contiguous run of siblings, so this list has no
|
|
91
|
-
// DOM order to restore: any repositioning would move elements the list does
|
|
92
|
-
// not own. Anchoring every node to parent(oldNodes[0]) is what reparents a
|
|
93
|
-
// cross-parent list into its first container and compacts past unowned
|
|
94
|
-
// siblings, and both destroy content on a write that changed nothing. Leave
|
|
95
|
-
// every surviving node exactly where the author put it and only place the
|
|
96
|
-
// grown ones.
|
|
97
|
-
placeGrownItems(adapter, finalNodes, fresh, parent, anchorIdx)
|
|
98
101
|
writeItems(adapter, finalNodes, shape, newItems, trace, applyItem, opts)
|
|
102
|
+
|
|
103
|
+
// writeItems can replace a node (@outerHTML on the item itself) and updates
|
|
104
|
+
// finalNodes in place, so this reports the nodes the list actually ended with.
|
|
105
|
+
callHook(opts, 'onRowsApplied', trace.path, finalNodes)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Consumer code runs in the middle of an engine write, and onRowsApplied runs
|
|
109
|
+
// after the list is already written. Letting it throw left the page written and
|
|
110
|
+
// the apply reported as failed, which in hypercms meant an error banner, a stale
|
|
111
|
+
// fingerprint, and a page that no longer matched it. A hook is an optional
|
|
112
|
+
// report; a broken one is the consumer's bug to see, not a reason to abandon a
|
|
113
|
+
// finished write.
|
|
114
|
+
function callHook(opts, name, path, arg) {
|
|
115
|
+
if (typeof opts[name] !== 'function') return undefined
|
|
116
|
+
try {
|
|
117
|
+
return opts[name](path.slice(), arg)
|
|
118
|
+
} catch (err) {
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.warn(`[hyper-html-api] ${name} threw at "${path.join('.') || '(root)'}"`, err)
|
|
121
|
+
return undefined
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// A caller that already knows which node each incoming item belongs to can say
|
|
126
|
+
// so, and content matching cannot tell two byte-identical rows apart however
|
|
127
|
+
// good it gets. `identifyRows` returns an array parallel to newItems of
|
|
128
|
+
// Node | null. A node that is not in this list right now is ignored, so a stale
|
|
129
|
+
// handle degrades to matching rather than corrupting the list.
|
|
130
|
+
function lockSuppliedRows(adapter, oldNodes, newItems, trace, opts) {
|
|
131
|
+
const supplied = callHook(opts, 'identifyRows', trace.path, newItems)
|
|
132
|
+
if (!Array.isArray(supplied)) return null
|
|
133
|
+
const locked = new Array(newItems.length).fill(-1)
|
|
134
|
+
const taken = new Set()
|
|
135
|
+
for (let i = 0; i < newItems.length; i++) {
|
|
136
|
+
if (!supplied[i]) continue
|
|
137
|
+
for (let j = 0; j < oldNodes.length; j++) {
|
|
138
|
+
if (taken.has(j) || !adapter.sameNode(oldNodes[j], supplied[i])) continue
|
|
139
|
+
locked[i] = j
|
|
140
|
+
taken.add(j)
|
|
141
|
+
break
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return locked
|
|
99
145
|
}
|
|
100
146
|
|
|
101
147
|
// Apply per-item content. Skip when the existing value already matches
|
|
@@ -120,46 +166,13 @@ function writeItems(adapter, finalNodes, shape, newItems, trace, applyItem, opts
|
|
|
120
166
|
|
|
121
167
|
function extractItem(adapter, node, shape, opts) {
|
|
122
168
|
if (shape === null) return adapter.text(node)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let bestIdx = -1
|
|
131
|
-
let bestScore = -1
|
|
132
|
-
oldValues.forEach((oldVal, j) => {
|
|
133
|
-
if (taken.has(j)) return
|
|
134
|
-
const score = similarity(newItem, oldVal, shape)
|
|
135
|
-
const closerIdx =
|
|
136
|
-
score === bestScore && bestIdx >= 0
|
|
137
|
-
? Math.abs(j - i) < Math.abs(bestIdx - i)
|
|
138
|
-
: false
|
|
139
|
-
if (score > bestScore || closerIdx) {
|
|
140
|
-
bestScore = score
|
|
141
|
-
bestIdx = j
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
if (bestScore >= SIMILARITY_THRESHOLD) {
|
|
145
|
-
matches[i] = bestIdx
|
|
146
|
-
taken.add(bestIdx)
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
return matches
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function similarity(a, b, shape) {
|
|
153
|
-
if (shape === null) return a === b ? 1 : 0
|
|
154
|
-
const fields = Object.keys(shape || {})
|
|
155
|
-
if (fields.length === 0) return 0
|
|
156
|
-
let equal = 0
|
|
157
|
-
for (const f of fields) {
|
|
158
|
-
if (JSON.stringify(a == null ? undefined : a[f]) === JSON.stringify(b == null ? undefined : b[f])) {
|
|
159
|
-
equal++
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return equal / fields.length
|
|
169
|
+
// This is a per-row read whose path restarts at the row, so a caller's
|
|
170
|
+
// onRowsRead would see a nested list under a truncated path and bind it to the
|
|
171
|
+
// wrong parent. The read hook belongs to a top-level extract only, and
|
|
172
|
+
// engine.bind() hands one opts object to both halves, so the caller cannot
|
|
173
|
+
// always keep them apart. Drop it here instead of documenting a rule the API
|
|
174
|
+
// does not let everyone follow.
|
|
175
|
+
return extract(adapter, node, shape, opts.onRowsRead ? { ...opts, onRowsRead: undefined } : opts)
|
|
163
176
|
}
|
|
164
177
|
|
|
165
178
|
function indexInParent(adapter, parent, targetNode) {
|
package/src/engine/extract.js
CHANGED
|
@@ -9,11 +9,18 @@ export function extract(adapter, root, rules, opts = {}) {
|
|
|
9
9
|
function extractAt(adapter, ctx, rule, trace, opts) {
|
|
10
10
|
if (trace.depth > MAX_RULE_DEPTH) throw new MaxRuleDepthExceeded(trace.path)
|
|
11
11
|
|
|
12
|
-
if (typeof rule === 'string') return extractScalar(adapter, ctx, rule, opts)
|
|
12
|
+
if (typeof rule === 'string') return extractScalar(adapter, ctx, rule, trace, opts)
|
|
13
13
|
|
|
14
14
|
if (Array.isArray(rule)) {
|
|
15
15
|
const [selector, shape] = rule
|
|
16
16
|
const matches = adapter.find(ctx, selector, opts)
|
|
17
|
+
// The read-side mirror of apply's onRowsApplied: it tells a caller which
|
|
18
|
+
// node each item came from, so identity can be established before anything
|
|
19
|
+
// is written. Only pass this to a TOP-LEVEL extract. listDiff extracts each
|
|
20
|
+
// existing row through this same function with a fresh path, so an opts
|
|
21
|
+
// carrying this hook into apply() would report nested lists under a
|
|
22
|
+
// truncated path.
|
|
23
|
+
reportRows(opts, trace, matches)
|
|
17
24
|
return matches.map((node, i) =>
|
|
18
25
|
extractAt(adapter, node, shape, {
|
|
19
26
|
depth: trace.depth + 1,
|
|
@@ -36,10 +43,14 @@ function extractAt(adapter, ctx, rule, trace, opts) {
|
|
|
36
43
|
return null
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
function extractScalar(adapter, ctx, rule, opts) {
|
|
46
|
+
function extractScalar(adapter, ctx, rule, trace, opts) {
|
|
40
47
|
if (rule.endsWith('[]')) {
|
|
41
48
|
const selector = rule.slice(0, -2)
|
|
42
|
-
|
|
49
|
+
const matches = adapter.find(ctx, selector, opts)
|
|
50
|
+
// A scalar list is still a list, and its rows still need identity. Reported
|
|
51
|
+
// here as well as in the tuple branch, because this one returns before it.
|
|
52
|
+
reportRows(opts, trace, matches)
|
|
53
|
+
return matches.map((n) => adapter.text(n))
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
if (rule.startsWith('@')) {
|
|
@@ -61,6 +72,18 @@ function extractScalar(adapter, ctx, rule, opts) {
|
|
|
61
72
|
return matches.length === 0 ? null : adapter.text(matches[0])
|
|
62
73
|
}
|
|
63
74
|
|
|
75
|
+
// The path is copied because the caller is handed it and every nested path is
|
|
76
|
+
// built from the same array. A throwing hook must not abandon the extract.
|
|
77
|
+
function reportRows(opts, trace, nodes) {
|
|
78
|
+
if (typeof opts.onRowsRead !== 'function') return
|
|
79
|
+
try {
|
|
80
|
+
opts.onRowsRead(trace.path.slice(), nodes)
|
|
81
|
+
} catch (err) {
|
|
82
|
+
// eslint-disable-next-line no-console
|
|
83
|
+
console.warn(`[hyper-html-api] onRowsRead threw at "${trace.path.join('.') || '(root)'}"`, err)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
64
87
|
function readPropOrAttr(adapter, node, name) {
|
|
65
88
|
if (DOM_PROPERTIES_SET.has(name)) {
|
|
66
89
|
const v = adapter.prop(node, name)
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map incoming list items onto the existing rows a list already has.
|
|
3
|
+
*
|
|
4
|
+
* A list arrives as plain JSON with no ids, so identity has to be inferred.
|
|
5
|
+
* The rule this file follows is that a list creates a node only when it grows
|
|
6
|
+
* and destroys one only when it shrinks: `matchRows` always pairs
|
|
7
|
+
* min(newItems.length, oldValues.length) rows. Content decides WHICH old row a
|
|
8
|
+
* new item is, never WHETHER it is one, because the field a person is editing
|
|
9
|
+
* is the same field that would have to prove who the row is.
|
|
10
|
+
*
|
|
11
|
+
* Two passes:
|
|
12
|
+
* A. anchors, content appearing exactly once on each side is unambiguous and
|
|
13
|
+
* matches wherever it moved to (this is what carries a reorder)
|
|
14
|
+
* B. everything left over, aligned in order at minimum cost, so surviving
|
|
15
|
+
* rows keep their relative order and edits stay put
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export function matchRows(newItems, oldValues, shape, locked) {
|
|
19
|
+
const n = newItems.length
|
|
20
|
+
const m = oldValues.length
|
|
21
|
+
const matches = new Array(n).fill(-1)
|
|
22
|
+
// A caller that knows which old row an item is keeps that pairing; the passes
|
|
23
|
+
// below only fill in what it did not answer for. Range-checked and deduped so
|
|
24
|
+
// the min(n, m) guarantee in the header holds for any `locked`, not only the
|
|
25
|
+
// sanitised one lockSuppliedRows produces.
|
|
26
|
+
if (locked) {
|
|
27
|
+
const seen = new Set()
|
|
28
|
+
for (let i = 0; i < n; i++) {
|
|
29
|
+
const j = locked[i]
|
|
30
|
+
if (!(j >= 0 && j < m) || seen.has(j)) continue
|
|
31
|
+
matches[i] = j
|
|
32
|
+
seen.add(j)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (n === 0 || m === 0) return matches
|
|
36
|
+
|
|
37
|
+
const newKeys = newItems.map((item) => itemKey(item, shape))
|
|
38
|
+
const oldKeys = oldValues.map((item) => itemKey(item, shape))
|
|
39
|
+
|
|
40
|
+
const takenOld = new Array(m).fill(false)
|
|
41
|
+
for (const j of matches) if (j >= 0) takenOld[j] = true
|
|
42
|
+
|
|
43
|
+
// Uniqueness is counted over the rows still in play, never over the locked
|
|
44
|
+
// ones. A value can be duplicated across the whole list and still be the only
|
|
45
|
+
// unlocked row of its kind, and that is exactly the case a lock should make
|
|
46
|
+
// decidable: locking one of two identical rows leaves the other unambiguous.
|
|
47
|
+
// Counting the locked rows too left it looking as ambiguous as before, and
|
|
48
|
+
// since alignInOrder only ever produces order-preserving pairs, losing the
|
|
49
|
+
// anchor loses the ability to express a crossing move at all.
|
|
50
|
+
const oldByKey = new Map()
|
|
51
|
+
oldKeys.forEach((key, j) => {
|
|
52
|
+
if (takenOld[j]) return
|
|
53
|
+
oldByKey.set(key, oldByKey.has(key) ? -1 : j)
|
|
54
|
+
})
|
|
55
|
+
const newCounts = new Map()
|
|
56
|
+
newKeys.forEach((key, i) => {
|
|
57
|
+
if (matches[i] >= 0) return
|
|
58
|
+
newCounts.set(key, (newCounts.get(key) || 0) + 1)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
newKeys.forEach((key, i) => {
|
|
62
|
+
if (matches[i] >= 0) return
|
|
63
|
+
if (newCounts.get(key) !== 1) return
|
|
64
|
+
const j = oldByKey.get(key)
|
|
65
|
+
if (j === undefined || j === -1 || takenOld[j]) return
|
|
66
|
+
matches[i] = j
|
|
67
|
+
takenOld[j] = true
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const leftNew = []
|
|
71
|
+
for (let i = 0; i < n; i++) if (matches[i] < 0) leftNew.push(i)
|
|
72
|
+
const leftOld = []
|
|
73
|
+
for (let j = 0; j < m; j++) if (!takenOld[j]) leftOld.push(j)
|
|
74
|
+
if (leftNew.length === 0 || leftOld.length === 0) return matches
|
|
75
|
+
|
|
76
|
+
// Changed content outranks displacement: the scale is larger than any total
|
|
77
|
+
// displacement this list can produce, so position only ever breaks a tie.
|
|
78
|
+
const scale = n * m + 1
|
|
79
|
+
const cost = (i, j) => differingFields(newItems[i], oldValues[j], shape) * scale + Math.abs(i - j)
|
|
80
|
+
for (const [i, j] of alignInOrder(leftNew, leftOld, cost)) matches[i] = j
|
|
81
|
+
return matches
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// An item is an object only when its shape is one. Both `".r[]"` and
|
|
85
|
+
// `[".r", "."]` produce string items, and Object.keys('.') is ["0"], which
|
|
86
|
+
// compared the first CHARACTER of two strings as though it were a field.
|
|
87
|
+
const isObjectShape = (shape) => typeof shape === 'object' && shape !== null
|
|
88
|
+
|
|
89
|
+
function itemKey(item, shape) {
|
|
90
|
+
if (!isObjectShape(shape)) return item == null ? ' null' : String(item)
|
|
91
|
+
const fields = Object.keys(shape)
|
|
92
|
+
return JSON.stringify(
|
|
93
|
+
fields.map((f) => {
|
|
94
|
+
const encoded = JSON.stringify(item == null ? undefined : item[f])
|
|
95
|
+
return encoded === undefined ? ' undef' : encoded
|
|
96
|
+
}),
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function differingFields(a, b, shape) {
|
|
101
|
+
if (!isObjectShape(shape)) return a === b ? 0 : 1
|
|
102
|
+
const fields = Object.keys(shape)
|
|
103
|
+
if (fields.length === 0) return 0
|
|
104
|
+
let differing = 0
|
|
105
|
+
for (const f of fields) {
|
|
106
|
+
const av = JSON.stringify(a == null ? undefined : a[f])
|
|
107
|
+
const bv = JSON.stringify(b == null ? undefined : b[f])
|
|
108
|
+
if (av !== bv) differing++
|
|
109
|
+
}
|
|
110
|
+
return differing
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Pair every entry of the shorter list with one of the longer, keeping both in
|
|
114
|
+
// order and minimising total cost. Returns [newIndex, oldIndex] pairs.
|
|
115
|
+
function alignInOrder(newIdx, oldIdx, cost) {
|
|
116
|
+
if (newIdx.length <= oldIdx.length) return align(newIdx, oldIdx, cost, false)
|
|
117
|
+
return align(oldIdx, newIdx, (j, i) => cost(i, j), true)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function align(short, long, cost, flipped) {
|
|
121
|
+
const s = short.length
|
|
122
|
+
const l = long.length
|
|
123
|
+
const table = []
|
|
124
|
+
for (let i = 0; i <= s; i++) table.push(new Float64Array(l + 1).fill(Infinity))
|
|
125
|
+
const takeHere = []
|
|
126
|
+
for (let i = 0; i <= s; i++) takeHere.push(new Uint8Array(l + 1))
|
|
127
|
+
for (let j = 0; j <= l; j++) table[s][j] = 0
|
|
128
|
+
|
|
129
|
+
for (let i = s - 1; i >= 0; i--) {
|
|
130
|
+
for (let j = l - 1; j >= 0; j--) {
|
|
131
|
+
const take = cost(short[i], long[j]) + table[i + 1][j + 1]
|
|
132
|
+
const skip = table[i][j + 1]
|
|
133
|
+
if (take <= skip) {
|
|
134
|
+
table[i][j] = take
|
|
135
|
+
takeHere[i][j] = 1
|
|
136
|
+
} else {
|
|
137
|
+
table[i][j] = skip
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const pairs = []
|
|
143
|
+
let i = 0
|
|
144
|
+
let j = 0
|
|
145
|
+
while (i < s && j < l) {
|
|
146
|
+
if (takeHere[i][j]) {
|
|
147
|
+
pairs.push(flipped ? [long[j], short[i]] : [short[i], long[j]])
|
|
148
|
+
i++
|
|
149
|
+
j++
|
|
150
|
+
} else {
|
|
151
|
+
j++
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return pairs
|
|
155
|
+
}
|