hyper-html-api 0.5.2 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/conformance/MANIFEST.json +6 -0
  2. package/conformance/cases/basic-scalar-and-list.expected.json +7 -0
  3. package/conformance/cases/basic-scalar-and-list.html +4 -0
  4. package/conformance/cases/basic-scalar-and-list.meta +4 -0
  5. package/conformance/cases/basic-scalar-and-list.parsed.json +4 -0
  6. package/conformance/cases/basic-scalar-and-list.rules +1 -0
  7. package/conformance/cases/cms-template-skipped-by-default.expected.json +7 -0
  8. package/conformance/cases/cms-template-skipped-by-default.html +7 -0
  9. package/conformance/cases/cms-template-skipped-by-default.meta +7 -0
  10. package/conformance/cases/cms-template-skipped-by-default.parsed.json +5 -0
  11. package/conformance/cases/cms-template-skipped-by-default.rules +1 -0
  12. package/conformance/cases/depth-at-limit-ok.expected.json +41 -0
  13. package/conformance/cases/depth-at-limit-ok.html +3 -0
  14. package/conformance/cases/depth-at-limit-ok.meta +6 -0
  15. package/conformance/cases/depth-at-limit-ok.parsed.json +41 -0
  16. package/conformance/cases/depth-at-limit-ok.rules +1 -0
  17. package/conformance/cases/depth-exceeded-path-contains-selector.error.json +5 -0
  18. package/conformance/cases/depth-exceeded-path-contains-selector.html +3 -0
  19. package/conformance/cases/depth-exceeded-path-contains-selector.meta +9 -0
  20. package/conformance/cases/depth-exceeded-path-contains-selector.parsed.json +43 -0
  21. package/conformance/cases/depth-exceeded-path-contains-selector.rules +1 -0
  22. package/conformance/cases/depth-exceeded.error.json +5 -0
  23. package/conformance/cases/depth-exceeded.html +3 -0
  24. package/conformance/cases/depth-exceeded.meta +6 -0
  25. package/conformance/cases/depth-exceeded.parsed.json +43 -0
  26. package/conformance/cases/depth-exceeded.rules +1 -0
  27. package/conformance/cases/props-boolean-on-any-element.expected.json +5 -0
  28. package/conformance/cases/props-boolean-on-any-element.html +3 -0
  29. package/conformance/cases/props-boolean-on-any-element.meta +7 -0
  30. package/conformance/cases/props-boolean-on-any-element.parsed.json +5 -0
  31. package/conformance/cases/props-boolean-on-any-element.rules +1 -0
  32. package/conformance/cases/props-empty-attr-vs-empty-prop.expected.json +4 -0
  33. package/conformance/cases/props-empty-attr-vs-empty-prop.html +3 -0
  34. package/conformance/cases/props-empty-attr-vs-empty-prop.meta +6 -0
  35. package/conformance/cases/props-empty-attr-vs-empty-prop.parsed.json +4 -0
  36. package/conformance/cases/props-empty-attr-vs-empty-prop.rules +1 -0
  37. package/conformance/cases/props-null-set.expected.json +9 -0
  38. package/conformance/cases/props-null-set.html +3 -0
  39. package/conformance/cases/props-null-set.meta +7 -0
  40. package/conformance/cases/props-null-set.parsed.json +9 -0
  41. package/conformance/cases/props-null-set.rules +1 -0
  42. package/conformance/cases/props-readonly-always-false.expected.json +4 -0
  43. package/conformance/cases/props-readonly-always-false.html +4 -0
  44. package/conformance/cases/props-readonly-always-false.meta +11 -0
  45. package/conformance/cases/props-readonly-always-false.parsed.json +4 -0
  46. package/conformance/cases/props-readonly-always-false.rules +1 -0
  47. package/conformance/cases/props-select-textarea-value-null.expected.json +5 -0
  48. package/conformance/cases/props-select-textarea-value-null.html +5 -0
  49. package/conformance/cases/props-select-textarea-value-null.meta +8 -0
  50. package/conformance/cases/props-select-textarea-value-null.parsed.json +5 -0
  51. package/conformance/cases/props-select-textarea-value-null.rules +1 -0
  52. package/conformance/cases/props-tagname-and-nodetype.expected.json +5 -0
  53. package/conformance/cases/props-tagname-and-nodetype.html +3 -0
  54. package/conformance/cases/props-tagname-and-nodetype.meta +6 -0
  55. package/conformance/cases/props-tagname-and-nodetype.parsed.json +5 -0
  56. package/conformance/cases/props-tagname-and-nodetype.rules +1 -0
  57. package/conformance/cases/props-type-is-node-type.expected.json +5 -0
  58. package/conformance/cases/props-type-is-node-type.html +5 -0
  59. package/conformance/cases/props-type-is-node-type.meta +11 -0
  60. package/conformance/cases/props-type-is-node-type.parsed.json +5 -0
  61. package/conformance/cases/props-type-is-node-type.rules +1 -0
  62. package/conformance/cases/rules-duplicate-keys-last-wins.expected.json +3 -0
  63. package/conformance/cases/rules-duplicate-keys-last-wins.html +4 -0
  64. package/conformance/cases/rules-duplicate-keys-last-wins.meta +5 -0
  65. package/conformance/cases/rules-duplicate-keys-last-wins.parsed.json +3 -0
  66. package/conformance/cases/rules-duplicate-keys-last-wins.rules +1 -0
  67. package/conformance/cases/rules-iterate-dot-leading-works.expected.json +10 -0
  68. package/conformance/cases/rules-iterate-dot-leading-works.html +3 -0
  69. package/conformance/cases/rules-iterate-dot-leading-works.meta +6 -0
  70. package/conformance/cases/rules-iterate-dot-leading-works.parsed.json +8 -0
  71. package/conformance/cases/rules-iterate-dot-leading-works.rules +1 -0
  72. package/conformance/cases/rules-iterate-lookahead-quoted.error.json +5 -0
  73. package/conformance/cases/rules-iterate-lookahead-quoted.html +3 -0
  74. package/conformance/cases/rules-iterate-lookahead-quoted.meta +7 -0
  75. package/conformance/cases/rules-iterate-lookahead-quoted.rules +1 -0
  76. package/conformance/cases/rules-iterate-lookahead-unquoted.error.json +5 -0
  77. package/conformance/cases/rules-iterate-lookahead-unquoted.html +3 -0
  78. package/conformance/cases/rules-iterate-lookahead-unquoted.meta +8 -0
  79. package/conformance/cases/rules-iterate-lookahead-unquoted.parsed.json +3 -0
  80. package/conformance/cases/rules-iterate-lookahead-unquoted.rules +1 -0
  81. package/conformance/cases/rules-lastindexof-at-split.expected.json +3 -0
  82. package/conformance/cases/rules-lastindexof-at-split.html +3 -0
  83. package/conformance/cases/rules-lastindexof-at-split.meta +11 -0
  84. package/conformance/cases/rules-lastindexof-at-split.parsed.json +3 -0
  85. package/conformance/cases/rules-lastindexof-at-split.rules +1 -0
  86. package/conformance/cases/rules-primitives-extract-null.expected.json +5 -0
  87. package/conformance/cases/rules-primitives-extract-null.html +3 -0
  88. package/conformance/cases/rules-primitives-extract-null.meta +6 -0
  89. package/conformance/cases/rules-primitives-extract-null.parsed.json +5 -0
  90. package/conformance/cases/rules-primitives-extract-null.rules +1 -0
  91. package/conformance/cases/rules-proto-key-omitted.expected.json +3 -0
  92. package/conformance/cases/rules-proto-key-omitted.html +3 -0
  93. package/conformance/cases/rules-proto-key-omitted.meta +7 -0
  94. package/conformance/cases/rules-proto-key-omitted.parsed.json +6 -0
  95. package/conformance/cases/rules-proto-key-omitted.rules +1 -0
  96. package/conformance/cases/rules-quoted-attr-in-unquoted-selector.error.json +5 -0
  97. package/conformance/cases/rules-quoted-attr-in-unquoted-selector.html +4 -0
  98. package/conformance/cases/rules-quoted-attr-in-unquoted-selector.meta +5 -0
  99. package/conformance/cases/rules-quoted-attr-in-unquoted-selector.rules +1 -0
  100. package/conformance/cases/rules-trailing-comma-dropped.expected.json +3 -0
  101. package/conformance/cases/rules-trailing-comma-dropped.html +3 -0
  102. package/conformance/cases/rules-trailing-comma-dropped.meta +5 -0
  103. package/conformance/cases/rules-trailing-comma-dropped.parsed.json +3 -0
  104. package/conformance/cases/rules-trailing-comma-dropped.rules +1 -0
  105. package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.error.json +5 -0
  106. package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.html +3 -0
  107. package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.meta +7 -0
  108. package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.rules +1 -0
  109. package/conformance/cases/rules-whitespace-clings.expected.json +4 -0
  110. package/conformance/cases/rules-whitespace-clings.html +4 -0
  111. package/conformance/cases/rules-whitespace-clings.meta +6 -0
  112. package/conformance/cases/rules-whitespace-clings.parsed.json +4 -0
  113. package/conformance/cases/rules-whitespace-clings.rules +1 -0
  114. package/conformance/cases/selector-unknown-pseudo-is-500.error.json +5 -0
  115. package/conformance/cases/selector-unknown-pseudo-is-500.html +4 -0
  116. package/conformance/cases/selector-unknown-pseudo-is-500.meta +7 -0
  117. package/conformance/cases/selector-unknown-pseudo-is-500.parsed.json +3 -0
  118. package/conformance/cases/selector-unknown-pseudo-is-500.rules +1 -0
  119. package/conformance/cases/tag-basic.expected.json +7 -0
  120. package/conformance/cases/tag-basic.html +5 -0
  121. package/conformance/cases/tag-basic.meta +6 -0
  122. package/conformance/cases/tag-basic.parsed.json +4 -0
  123. package/conformance/cases/tag-duplicate-names-first-wins.expected.json +3 -0
  124. package/conformance/cases/tag-duplicate-names-first-wins.html +6 -0
  125. package/conformance/cases/tag-duplicate-names-first-wins.meta +7 -0
  126. package/conformance/cases/tag-duplicate-names-first-wins.parsed.json +3 -0
  127. package/conformance/cases/tag-missing.error.json +5 -0
  128. package/conformance/cases/tag-missing.html +4 -0
  129. package/conformance/cases/tag-missing.meta +8 -0
  130. package/conformance/cases/tag-name-is-space-separated.expected.json +3 -0
  131. package/conformance/cases/tag-name-is-space-separated.html +4 -0
  132. package/conformance/cases/tag-name-is-space-separated.meta +6 -0
  133. package/conformance/cases/tag-name-is-space-separated.parsed.json +3 -0
  134. package/conformance/cases/tag-relaxed-body.expected.json +7 -0
  135. package/conformance/cases/tag-relaxed-body.html +5 -0
  136. package/conformance/cases/tag-relaxed-body.meta +7 -0
  137. package/conformance/cases/tag-relaxed-body.parsed.json +4 -0
  138. package/conformance/cases/tag-wrong-version.error.json +5 -0
  139. package/conformance/cases/tag-wrong-version.html +4 -0
  140. package/conformance/cases/tag-wrong-version.meta +6 -0
  141. package/conformance/cases/template-simple-vs-combinator.expected.json +7 -0
  142. package/conformance/cases/template-simple-vs-combinator.html +4 -0
  143. package/conformance/cases/template-simple-vs-combinator.meta +8 -0
  144. package/conformance/cases/template-simple-vs-combinator.parsed.json +4 -0
  145. package/conformance/cases/template-simple-vs-combinator.rules +1 -0
  146. package/conformance/cases/text-root-leaks-rules-tag.expected.json +4 -0
  147. package/conformance/cases/text-root-leaks-rules-tag.html +4 -0
  148. package/conformance/cases/text-root-leaks-rules-tag.meta +7 -0
  149. package/conformance/cases/text-root-leaks-rules-tag.parsed.json +4 -0
  150. package/conformance/cases/text-root-leaks-rules-tag.rules +1 -0
  151. package/conformance/cases/text-trim-asymmetry.expected.json +5 -0
  152. package/conformance/cases/text-trim-asymmetry.html +5 -0
  153. package/conformance/cases/text-trim-asymmetry.meta +6 -0
  154. package/conformance/cases/text-trim-asymmetry.parsed.json +5 -0
  155. package/conformance/cases/text-trim-asymmetry.rules +1 -0
  156. package/dist/hyper-html-api.engine.min.js +1 -1
  157. package/dist/hyper-html-api.min.js +4 -4
  158. package/dist/hyper-html-api.upgrade.min.js +2 -2
  159. package/package.json +7 -4
  160. package/src/cms/form-builder.js +3 -2
  161. package/src/dom-api.js +5 -0
  162. package/src/engine/apply.js +3 -2
  163. package/src/engine/diff.js +70 -13
  164. package/src/engine/extract.js +3 -2
  165. package/src/engine/index.js +1 -0
  166. package/src/engine/rule-syntax.js +43 -0
@@ -1,4 +1,4 @@
1
- var HyperHtmlApi=(()=>{var qe=Object.defineProperty;var tn=Object.getOwnPropertyDescriptor;var nn=Object.getOwnPropertyNames;var rn=Object.prototype.hasOwnProperty;var We=(e,t)=>{for(var n in t)qe(e,n,{get:t[n],enumerable:!0})},on=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of nn(t))!rn.call(e,r)&&r!==n&&qe(e,r,{get:()=>t[r],enumerable:!(o=tn(t,r))||o.enumerable});return e};var sn=e=>on(qe({},"__esModule",{value:!0}),e);var fr={};We(fr,{applyData:()=>At,cms:()=>Yt,default:()=>ur,engine:()=>ke,extractData:()=>bt,upgrade:()=>Zt});var Ce={};We(Ce,{fromString:()=>Ie,getRuleAtPath:()=>Ve,getValueAtPath:()=>Ae,parseConfigKey:()=>cn,setAtPath:()=>te,toConfigKey:()=>an,toString:()=>J});function J(e){return e.map(String).join(".")}function an(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function cn(e){return e===""?[]:e.split(".")}function Ie(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function Ve(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 Ae(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function te(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]=te(i[o],r,n),i}return{...e&&typeof e=="object"?e:{},[o]:te((e||{})[o],r,n)}}function he(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]=he(o);return t}return""}var Le=new WeakMap;var ln=new Set(["checked","selected","disabled","readOnly","paused"]);function Ke({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(Je({rule:e,value:t,path:[],ctx:i})),r}function ze(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),vt.set(e,{rules:t,getData:n,onChange:o}),un()}var vt=new WeakMap,xt=!1;function un(){xt||(document.addEventListener("input",wt,!0),document.addEventListener("change",wt,!0),document.addEventListener("click",fn,!0),xt=!0)}function Ot(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&vt.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=Ot(t);if(!n)return;let{rules:o,getData:r,onChange:i}=n,a=t.getAttribute("data-hha-action"),s=Ie(t.getAttribute("data-hha-path")||"");if(a==="scalar-array-add"){let c=Ae(r(),s)||[];i(te(r(),s,[...c,""]),{structural:!0});return}if(a==="object-array-add"){let c=Ve(o,s);if(!Array.isArray(c))return;let M=Ae(r(),s)||[];i(te(r(),s,[...M,he(c[1])]),{structural:!0});return}if(a==="array-remove"){if(s.length===0)return;let c=s.slice(0,-1),M=s[s.length-1],w=Ae(r(),c)||[];if(typeof M!="number")return;let x=w.filter((m,b)=>b!==M);i(te(r(),c,x),{structural:!0})}}function wt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=Ot(t);if(!n)return;let{getData:o,onChange:r}=n,i=t.closest("[data-hha-path]");if(!i)return;let a=Ie(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;r(te(o(),a,s),{structural:!1})}function Je({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?pn({rule:e,value:t,path:n,ctx:o}):hn({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return mn({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return dn({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function dn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",J(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=He(n[n.length-1]),r.appendChild(i)}for(let[i,a]of Object.entries(e)){let s=[...n,i],c=t?.[i];r.appendChild(Je({rule:a,value:c,path:s,ctx:o}))}return r}function hn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="field-body";let a=document.createElement("label");a.className="field-label",a.textContent=He(n[n.length-1]||".")+Sn(e);let s=yn(e,o.appRoot),c=gn(s,{value:t,rule:e,path:n,appRoot:o.appRoot}),M=c.el;return M.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(a),i.appendChild(M),r.appendChild(i),Le.set(r,c),r}function pn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=He(n[n.length-1]),r.appendChild(i);let a=Array.isArray(t)?t:[],s=document.createElement("div");r.appendChild(s),a.forEach((M,w)=>{let x=[...n,w],m=document.createElement("div");m.className="scalar-array-row",m.setAttribute("data-hha-path",J(x));let b=document.createElement("input");b.type="text",b.className="field-input",b.value=M==null?"":String(M);let E=document.createElement("button");E.type="button",E.className="array-remove",E.textContent="\xD7",E.title="remove",E.setAttribute("data-hha-action","array-remove"),E.setAttribute("data-hha-path",J(x)),m.appendChild(b),m.appendChild(E),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",J(n)),r.appendChild(c),r}function mn({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",J(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=He(n[n.length-1]),a.appendChild(s),i.forEach((M,w)=>{let x=[...n,w],m=document.createElement("div");m.className="array-card",m.setAttribute("data-hha-path",J(x));let b=document.createElement("button");b.type="button",b.className="array-remove",b.textContent="\xD7",b.title="remove item",b.setAttribute("data-hha-action","array-remove"),b.setAttribute("data-hha-path",J(x)),m.appendChild(b);let E=Je({rule:r,value:M,path:x,ctx:o});E.querySelector(".form-section-label")?.remove(),m.appendChild(E),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",J(n)),a.appendChild(c),a}function gn(e,t){let n=An(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 yn(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):e.includes("@")&&(n=e.split("@")[1]||null),n&&ln.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=bn(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 bn(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=e.includes("@")?e.split("@")[0]:e;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function An(e){if(e.type==="textarea")return document.createElement("textarea");if(e.type==="select")return document.createElement("select");let t=document.createElement("input");return t.type=e.type==="checkbox"?"checkbox":e.type==="number"?"number":"text",t}function He(e){return typeof e=="number"?`#${e+1}`:String(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/^\w/,t=>t.toUpperCase())}function Sn(e){return` \xB7 ${e}`}var Tt={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 En(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 Mn(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 wn(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function vn(e,t){let n=[e.tagName];return t.includeClasses&&n.push(Mn(e)),n.push(xn(e,t)),En(n.join("|"))}function On(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function Tn(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function Rn(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function Nn(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${On(o)}`;if(n.unshift(r),o!==e&&Tn(o,t)){n.unshift(Rn(o));break}o=o.parentElement}return n}function kn(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 G(e,t,n){if(n.has(e))return n.get(e);let o={signature:vn(e,t),path:Nn(e,t),textHint:wn(e,t)};return n.set(e,o),o}function It(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=G(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 In(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function Ge(e,t,n,o,r){let i=G(e,n,o),a=G(t,n,o),s=n.weights,c={},M=0;if(i.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};M+=s.signature,c.signature=s.signature;let x=kn(i.path,a.path)*s.pathSegment;M+=x,c.path=x;let m=!0;if(i.textHint&&a.textHint?i.textHint===a.textHint?(M+=s.textMatch,c.text=s.textMatch):(M-=s.textMismatch,c.text=-s.textMismatch,m=!1):i.textHint!==a.textHint&&(M-=s.textMismatch,c.text=-s.textMismatch,m=!1),r.candidateCount===1&&m&&(M+=s.uniqueCandidate,c.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof a.domIndex=="number"){let b=Math.abs(i.domIndex-a.domIndex),E=Math.min(b*s.positionPenalty,s.maxDriftPenalty);M-=E,c.drift=-E}return{score:M,breakdown:c}}function Rt(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let i=It(t,n,o,r),a=G(e,n,o);if(typeof a.domIndex!="number"){let m=0,b=e.previousElementSibling;for(;b;)m++,b=b.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 M=null,w=0,x=null;for(let m of c){let{score:b,breakdown:E}=Ge(e,m,n,o,{candidateCount:c.length});b>w&&(w=b,M=m,x=E)}return w<n.minConfidence?null:{element:M,confidence:w,breakdown:x}}function Cn(e,t,n,o){let r=[],i=n.weights.signature+n.weights.slotMatch,a={slot:i};function s(x){if(x.children)return x.children;let m=x.childNodes;if(!m)return[];let b=[];for(let E=0;E<m.length;E++)m[E].nodeType===1&&b.push(m[E]);return b}function c(x,m){let b=s(x),E=s(m);if(b.length===E.length)for(let P=0;P<b.length;P++){let _=b[P],j=E[P];if(n.shouldIgnore?.(_)||n.shouldIgnore?.(j)||n.excludeIds&&(_.getAttribute("id")||j.getAttribute("id"))||_.tagName!==j.tagName)continue;let B=G(_,n,o).signature,L=G(j,n,o).signature;B!==L&&r.push({newEl:_,oldEl:j,score:i,breakdown:a}),c(_,j)}}function M(x,m){for(;;){if(x.tagName===m.tagName)return[x,m];let b=s(x);if(!x.tagName&&b.length===1){x=b[0];continue}let E=s(m);if(E.length===1&&E[0].tagName===x.tagName){m=E[0];continue}return null}}let w=M(e,t);return w&&c(w[0],w[1]),r}function Nt(e,t,n,o,r){let i=t.querySelectorAll("*"),a=It(e,n,o,r),s=0;for(let b of i){let E=G(b,n,o);E.domIndex=s++}let c=[],M=new Map;function w(b,E,P){let _=new Set;if(b.textHint){let I=M.get(b.signature);if(!I){I=new Map;for(let Y of E){let fe=G(Y,n,o).textHint,se=I.get(fe);se||(se=[],I.set(fe,se)),se.push(Y)}M.set(b.signature,I)}let K=I.get(b.textHint);if(K)for(let Y=0;Y<K.length&&Y<P;Y++)_.add(K[Y])}let j=0,B=E.length;for(;j<B;){let I=j+B>>1;G(E[I],n,o).domIndex<b.domIndex?j=I+1:B=I}let L=Math.max(0,Math.min(j-(P>>1),E.length-P)),F=Math.min(L+P,E.length);for(let I=L;I<F;I++)_.add(E[I]);return[..._]}for(let b of i){if(n.shouldIgnore?.(b)||n.excludeIds&&b.getAttribute("id"))continue;let E=G(b,n,o),P=a.get(E.signature)||[],_=n.excludeIds?P.filter(L=>!L.getAttribute("id")):P,j=n.maxScoredCandidates,B=j&&_.length>j?w(E,_,j):_;for(let L of B){let{score:F,breakdown:I}=Ge(b,L,n,o,{candidateCount:_.length});F>=n.minConfidence&&c.push({newEl:b,oldEl:L,score:F,breakdown:I})}}if(n.weights.slotMatch>0){let b=Cn(t,e,n,o);for(let E of b)c.push(E)}c.sort((b,E)=>E.score-b.score);let x=new Map,m=new Set;for(let{newEl:b,oldEl:E}of c)x.has(b)||m.has(E)||(x.set(b,E),m.add(E));return x}function kt(e,t,n,o){let r=G(e,n,o),i=G(t,n,o),{score:a,breakdown:s}=Ge(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 Ct(e={}){let t={...Tt,...e,weights:{...Tt.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,i)=>Rt(r,i,t,n,o),computeMatches:(r,i)=>Nt(r,i,t,n,o),explain:(r,i)=>kt(r,i,t,n),invalidate:r=>In(r,n,o),session:()=>{let r=new WeakMap,i=new WeakMap;return{findMatch:(a,s)=>Rt(a,s,t,r,i),computeMatches:(a,s)=>Nt(a,s,t,r,i),explain:(a,s)=>kt(a,s,t,r)}},getConfig:()=>({...t})}}function Ye(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 Lt(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var Ln=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Hn=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Pe(e){try{return JSON.parse(e)}catch{return JSON.parse(Pn(e))}}function Pn(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=Ye(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=Ye(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=Lt(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"||Ln.test(a)){t+=a,n=i;continue}if(Hn.test(a)){if(e[Ye(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function Ht(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 x=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(x=!0),!x){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 x=s,m=a+1;for(;m<r.length&&r[m]!==x;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:x}),a=m+1;continue}let c=a,M;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let x=[":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 b of x){let E=b.substring(1);if(r.substring(c+1,c+1+E.length)===E){m=!0,c+=E.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let x=r[c];for(c++;c<r.length&&r[c]!==x;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;M=r.substring(a,c);let w=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?w=t.NUMBER:M==="true"||M==="false"||M==="null"?w=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(w=t.SELECTOR),i.push({type:w,value:M,quoted:!1}),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=Lt(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 D=Symbol("hyper-morph-json-merge:missing"),Pt=["id","_id","uuid","key","slug","code","name"];function pe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Se(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function jn(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function ne(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(!ne(e[n],t[n]))return!1;return!0}if(pe(e)&&pe(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Se(t,o)||!ne(e[o],t[o]))return!1;return!0}return!1}function jt(e,t,n,o){return ne(t,n)?t:ne(t,e)?n:ne(n,e)?t:pe(t)&&pe(n)?_n(pe(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?Fn(Array.isArray(e)?e:[],t,n,o):n}function _t(e,t,n,o){return t===D&&n===D?D:t===D?e===D?n:ne(n,e)?D:n:n===D?e===D?t:D:jt(e,t,n,o)}function _n(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=_t(Se(e,a)?e[a]:D,Se(t,a)?t[a]:D,Se(n,a)?n[a]:D,o);s!==D&&jn(r,a,s)}return r}function $n(e){return e===null||typeof e!="object"}function je(e){return typeof e+":"+String(e)}function Dn(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Se(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=je(i);if(o.has(a))return!1;o.add(a)}}return!0}function Bn(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)pe(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(Dn(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!$n(c))return null;let M=je(c);if(s.has(M))return null;s.add(M)}}return{kind:"self"}}function Fn(e,t,n,o){let r=Bn(e,t,n,o);if(!r)return n;let i=r.kind==="self"?je:b=>je(b[r.field]),a=b=>{let E=new Map;for(let P of b)E.set(i(P),P);return E},s=a(e),c=a(t),M=a(n),w=new Map,x=new Set([...s.keys(),...c.keys(),...M.keys()]);for(let b of x){let E=_t(s.has(b)?s.get(b):D,c.has(b)?c.get(b):D,M.has(b)?M.get(b):D,o);E!==D&&w.set(b,E)}let m=[];for(let b of n){let E=i(b);w.has(E)&&m.push(E)}for(let b=0;b<t.length;b++){let E=i(t[b]);if(!w.has(E)||m.includes(E))continue;let P=0;for(let _=b-1;_>=0;_--){let j=m.indexOf(i(t[_]));if(j!==-1){P=j+1;break}}m.splice(P,0,E)}return m.map(b=>w.get(b))}function Ze(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...Pt]:Pt;return jt(e===void 0?D:e,t,n,{keyCandidates:r})}function Qe(e,t,n,o={}){let r=o.parse||Pe,i=[],a=(x,m)=>{if(typeof x!="string")return D;try{return r(x)}catch(b){return i.push(`${m} side is not valid JSON (${b.message})`),D}},s=a(t,"local"),c=a(n,"remote");if(s===D)return{text:n,warnings:i};if(c===D)return{text:t,warnings:i};let M=a(e,"base"),w=Ze(M===D?void 0:M,s,c,o);return ne(w,c)?{text:n,warnings:i}:ne(w,s)?{text:t,warnings:i}:{text:JSON.stringify(w,null,2),warnings:i}}var Xe=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(p){if(!(p instanceof Element))return!1;if(p.matches(t))return!0;if(p.tagName==="LINK"||p.tagName==="SCRIPT"){let O=p.getAttribute("src")||p.getAttribute("href")||"";if(O.startsWith("chrome-extension://")||O.startsWith("moz-extension://")||O.startsWith("safari-web-extension://"))return!0}return!1}function o(p){return p instanceof Element?p.closest(t)?!0:n(p):!1}let r=Ct({shouldIgnore:o});function i(p,O,v){if(v){let k=v.identityOf(p);if(k&&!v.disabled.has(k.key))return"hm-merge:"+k.key}if(O!=="smart")return p.outerHTML;let N=p.getAttribute("src"),T=p.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${T}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${T}:${N}`}else{let k=p.textContent.trim(),h=5381;for(let S=0;S<k.length;S++)h=(h<<5)+h^k.charCodeAt(S);return`inline:${T}:${Math.abs(h).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(p){return p instanceof Element&&p.tagName==="SCRIPT"&&p.namespaceURI===a}function c(p){let O=document.createElement("div");O.innerHTML="<script><\/script>";let v=O.firstChild;for(let N of p.attributes)v.setAttribute(N.name,N.value);return v.textContent=p.textContent,v}function M(p){if(s(p))return c(p);if(p instanceof Element)for(let O of p.querySelectorAll("script"))s(O)&&O.replaceWith(c(O));return p}function w(p){let O=(p.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return O==="application/json"||O.endsWith("+json")}let x={match:p=>p.hasAttribute("merge"),identity:p=>p.getAttribute("merge")};function m(p,O,v){if(v.merge===!1)return null;let N=[x,...v.mergeTags||[]],T=new WeakMap,k=f=>{if(T.has(f))return T.get(f);let y=null;if(s(f)&&!f.getAttribute("src")&&!o(f)){let A=f;for(let R=0;R<N.length;R++)if(N[R].match(A)){if(!w(A))console.warn("[hyper-morph] merge ignored: script type is not JSON",A);else{let C=N[R].identity(A);C!=null&&C!==""&&(y={key:R+":"+C,raw:C,recognizer:N[R]})}break}}return T.set(f,y),y},h=new Set,S=f=>{let y=new Map,A=R=>{let C=k(R);C&&(y.has(C.key)?(h.add(C.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${C.raw}"`)):y.set(C.key,R))};s(f)&&A(f);for(let R of f.querySelectorAll("script"))A(R);return y},d=S(p),u=S(O.__hyperMorphRoot||O);if(d.size===0&&u.size===0)return null;let l=null;return{identityOf:k,disabled:h,oldByKey:d,newByKey:u,baseTexts:()=>{if(l)return l;l=new Map;let f=v.mergeBase;if(!f)return l;let y;typeof f=="string"?y=new DOMParser().parseFromString(f,"text/html").documentElement:f instanceof Document?y=f.documentElement:y=f;let A=R=>{let C=k(R);C&&!l.has(C.key)&&l.set(C.key,R.textContent)};s(y)&&A(y);for(let R of y.querySelectorAll("script"))A(R);return l}}}function b(p,O,v){let N=p.merge;if(!N)return!1;let T=N.identityOf(O);if(!T||N.disabled.has(T.key))return!1;let k=N.identityOf(v);if(!k||k.key!==T.key)return!1;let h=O,S=v,d=S.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=Qe(N.baseTexts().get(T.key),h.textContent,S.textContent,{parse:T.recognizer.parse,keyCandidates:d?d.split(/[\s,]+/).filter(Boolean):void 0});for(let g of l)console.warn(`[hyper-morph] merge "${T.raw}": ${g}`);return h.textContent!==u&&(h.textContent=u),!0}let E={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},P={computeMatches(p,O){let{computeMatches:v}=r.session();return v(p,O)}};function _(p,O,v={}){p=en(p);let N=St(O),T=Xt(p,N,v),k=T.scripts.handle?new Set(Array.from(p.querySelectorAll("script")).map(u=>i(u,T.scripts.matchMode,T.merge))):null,h=L(T),S=Y(T,p,N,u=>u.morphStyle==="innerHTML"?(I(u,p,N),Array.from(p.childNodes)):B(u,p,N)),d=u=>{h&&F(T,h),j(T);let l=k?Qt(u,k,T):[];return l.length>0?Promise.all(l).then(()=>u):u};return S instanceof Promise?S.then(d):d(S)}function j(p){for(let O of Array.from(p.pantry.childNodes))p.callbacks.beforeNodeRemoved(O)!==!1&&p.callbacks.afterNodeRemoved(O);p.pantry.remove()}function B(p,O,v){let N=St(O);return I(p,N,v,O,O.nextSibling),Array.from(N.childNodes)}function L(p){if(!p.config.restoreFocus)return null;let O=document.activeElement;if(!(O instanceof HTMLInputElement||O instanceof HTMLTextAreaElement))return null;let{id:v,selectionStart:N,selectionEnd:T}=O;return{element:O,id:v,selectionStart:N,selectionEnd:T}}function F(p,O){let v=O.element;if(O.id&&O.id!==document.activeElement?.getAttribute("id")&&(v=p.target.querySelector(`[id="${CSS.escape(O.id)}"]`),v?.focus()),v&&!v.selectionEnd&&O.selectionEnd!=null)try{v.setSelectionRange(O.selectionStart,O.selectionEnd)}catch{}}let I=function(){function p(u,l,g,f=null,y=null){l instanceof HTMLTemplateElement&&g instanceof HTMLTemplateElement&&(l=l.content,g=g.content),f||=l.firstChild;for(let A of g.childNodes){if(n(A))continue;if(f&&f!=y){let C=v(u,A,f,y);if(C){C!==f&&T(u,f,C),K(C,A,u),f=C.nextSibling;continue}}if(A instanceof Element){let C=A.getAttribute("id");if(u.persistentIds.has(C)){let $=k(l,C,f,u);K($,A,u),f=$.nextSibling;continue}if(!u.idMap.has(A)){let $=u.hyperMatches.get(A);if($&&!u.idMap.has($)&&!d($,l)){S(l,$,f),K($,A,u),f=$.nextSibling;continue}}}let R=O(l,A,f,u);R&&(f=R.nextSibling)}for(;f&&f!=y;){let A=f;f=f.nextSibling,n(A)||N(u,A)}}function O(u,l,g,f){if(f.callbacks.beforeNodeAdded(l)===!1)return null;if(f.idMap.has(l)){let y=l,A=document.createElementNS(y.namespaceURI,y.localName);return u.insertBefore(A,g),K(A,l,f),f.callbacks.afterNodeAdded(A),A}else{let y=M(document.importNode(l,!0));return u.insertBefore(y,g),f.callbacks.afterNodeAdded(y),y}}let v=function(){function u(f,y,A,R){let C=y instanceof Element&&!f.idMap.has(y)?f.hyperMatches.get(y):null,$=null,W=y.nextSibling,Z=0,H=A;for(;H&&H!=R;){if(n(H)){H=H.nextSibling;continue}if(g(H,y)){if(l(f,H,y)||H===C&&!f.idMap.has(H))return H;if($===null){let z=H instanceof Element&&f.hyperMatchedOldElements.has(H);!f.idMap.has(H)&&!z&&($=H)}}if($===null&&W&&g(H,W)&&(Z++,W=W.nextSibling,Z>=2&&($=void 0)),f.activeElementAndParents.includes(H))break;H=H.nextSibling}return $||null}function l(f,y,A){let R=f.idMap.get(y),C=f.idMap.get(A);if(!C||!R)return!1;for(let $ of R)if(C.has($))return!0;return!1}function g(f,y){let A=f,R=y;return A.nodeType===R.nodeType&&A.tagName===R.tagName&&(!A.getAttribute?.("id")||A.getAttribute?.("id")===R.getAttribute?.("id"))}return u}();function N(u,l){let g=l instanceof Element&&u.hyperMatchedOldElements.has(l)&&!u.idMap.has(l);if(u.idMap.has(l)||g)S(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function T(u,l,g){let f=l;for(;f&&f!==g;){let y=f;f=f.nextSibling,n(y)||N(u,y)}return f}function k(u,l,g,f){let y=f.target.getAttribute?.("id")===l&&f.target||f.target.querySelector(`[id="${CSS.escape(l)}"]`)||f.pantry.querySelector(`[id="${CSS.escape(l)}"]`);return h(y,f),S(u,y,g),y}function h(u,l){let g=u.getAttribute("id");for(;u=u.parentNode;){let f=l.idMap.get(u);f&&(f.delete(g),f.size||l.idMap.delete(u))}}function S(u,l,g){if(u.moveBefore)try{u.moveBefore(l,g)}catch{u.insertBefore(l,g)}else u.insertBefore(l,g)}function d(u,l){let g=l instanceof Element?l:l.realParentNode;return!!g&&u.contains(g)}return p}(),K=function(){function p(h,S,d){return d.ignoreActive&&h===document.activeElement?null:(d.callbacks.beforeNodeMorphed(h,S)===!1||(h instanceof HTMLHeadElement&&d.head.ignore||(h instanceof HTMLHeadElement&&d.head.style!=="morph"?se(h,S,d):(O(h,S,d),b(d,h,S)||k(h,d)||I(d,h,S))),d.callbacks.afterNodeMorphed(h,S)),h)}function O(h,S,d){let u=S.nodeType;if(u===1){let l=h,g=S,f=l.attributes,y=g.attributes;for(let A of y)T(A.name,l,"update",d)||l.getAttribute(A.name)!==A.value&&l.setAttribute(A.name,A.value);for(let A=f.length-1;0<=A;A--){let R=f[A];if(R&&!g.hasAttribute(R.name)){if(T(R.name,l,"remove",d))continue;l.removeAttribute(R.name)}}k(l,d)||v(l,g,d)}(u===8||u===3)&&h.nodeValue!==S.nodeValue&&(h.nodeValue=S.nodeValue)}function v(h,S,d){if(h instanceof HTMLInputElement&&S instanceof HTMLInputElement&&S.type!=="file"){let u=S.value,l=h.value;N(h,S,"checked",d),N(h,S,"disabled",d),d.formStateSync==="property"&&h.indeterminate!==S.indeterminate&&(h.indeterminate=S.indeterminate),d.formStateSync==="property"?l!==u&&(T("value",h,"update",d)||(h.value=u)):S.hasAttribute("value")?l!==u&&(T("value",h,"update",d)||(h.setAttribute("value",u),h.value=u)):T("value",h,"remove",d)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&S instanceof HTMLOptionElement)N(h,S,"selected",d);else if(h instanceof HTMLTextAreaElement&&S instanceof HTMLTextAreaElement){let u=S.value,l=h.value;if(T("value",h,"update",d)||(u!==l&&(h.value=u),d.formStateSync==="property"))return;h.firstChild&&h.firstChild.nodeValue!==u&&(h.firstChild.nodeValue=u)}}function N(h,S,d,u){let l=S[d],g=h[d];if(l!==g){let f=T(d,h,"update",u);if(f||(h[d]=S[d]),u.formStateSync==="property")return;l?f||h.setAttribute(d,""):T(d,h,"remove",u)||h.removeAttribute(d)}}function T(h,S,d,u){return h==="value"&&u.ignoreActiveValue&&S===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,S,d)===!1}function k(h,S){return!!S.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return p}();function Y(p,O,v,N){if(p.head.block){let T=O.querySelector("head"),k=v.querySelector("head");if(T&&k){let h=se(T,k,p);return Promise.all(h).then(()=>(p.head.block=!1,p.head.ignore=!0,N(p)))}}return N(p)}function fe(p){return p.tagName==="SCRIPT"?!!p.getAttribute("src"):p.tagName==="LINK"?(p.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!p.getAttribute("href"):!1}function se(p,O,v){let N=[],T=[],k=[],h=[],S=v.scripts.matchMode,d=g=>{if(g.tagName==="SCRIPT")return i(g,S,v.merge);if(g.tagName==="LINK"&&S==="smart"){let f=g.getAttribute("href");if(f)try{let y=new URL(f,window.location.href);return`link:${g.getAttribute("rel")||""}:${y.origin}${y.pathname}${y.search}`}catch{}}return g.outerHTML},u=new Map;for(let g of O.children){if(n(g))continue;let f=d(g),y=u.get(f);y||(y=[],u.set(f,y)),y.push(g)}for(let g of p.children){let f=d(g),y=u.get(f),A=!!(y&&y.length),R=v.head.shouldReAppend(g),C=v.head.shouldPreserve(g);if(A||C)if(R)T.push(g);else{if(y&&y.length){let $=y.pop();y.length||u.delete(f),b(v,g,$)}k.push(g)}else v.head.style==="append"?R&&(T.push(g),h.push(g)):v.head.shouldRemove(g)!==!1&&!n(g)&&T.push(g)}for(let g of u.values())h.push(...g);let l=[];for(let g of h){let f=document.createRange().createContextualFragment(g.outerHTML).firstChild;if(v.callbacks.beforeNodeAdded(f)!==!1){if(f instanceof Element&&fe(f)){let y,A=new Promise(function(R){y=R});f.addEventListener("load",function(){y()}),f.addEventListener("error",function(){y()}),l.push(A)}p.appendChild(f),v.callbacks.afterNodeAdded(f),N.push(f)}}for(let g of T)v.callbacks.beforeNodeRemoved(g)!==!1&&(p.removeChild(g),v.callbacks.afterNodeRemoved(g));return v.head.afterHeadMorphed(p,{added:N,kept:k,removed:T}),l}function Qt(p,O,v){if(!v.scripts.handle)return[];let N=[],T=[],k=[],h=[],S=v.scripts.matchMode,d=[];for(let l of p)if(l instanceof Element){s(l)&&d.push(l);for(let g of l.querySelectorAll("script"))s(g)&&d.push(g)}for(let l of d){if(l.closest("head")||o(l))continue;let g=i(l,S,v.merge),f=O.has(g),y=v.scripts.shouldPreserve(l),A=v.scripts.shouldReAppend(l);f||y?A?(T.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 g=document.createElement("script");for(let f of l.attributes)g.setAttribute(f.name,f.value);if(g.textContent=l.textContent,g.src){let f,y=new Promise(function(A){f=A});g.addEventListener("load",function(){f()}),g.addEventListener("error",function(){f()}),u.push(y)}l.replaceWith(g),v.callbacks.afterNodeAdded(g),N.push(g)}return v.scripts.afterScriptsHandled(v.target,{added:N,kept:k,removed:T}),u}let Xt=function(){function p(d,u,l){let{persistentIds:g,idMap:f}=h(d,u),y=P.computeMatches(d,u);if(typeof l.key=="function"){let W=new Map,Z=new Set,H=U=>{let q=l.key(U);q!=null&&(W.has(q)?Z.add(q):W.set(q,U))};d instanceof Element&&H(d);for(let U of d.querySelectorAll("*"))H(U);for(let U of Z)W.delete(U);let z=new Map;for(let[U,q]of y)z.set(q,U);let ie=u.__hyperMorphRoot||u,ee=new Map,Et=new Set,Mt=U=>{let q=l.key(U);q!=null&&(ee.has(q)?Et.add(q):ee.set(q,U))};ie instanceof Element&&Mt(ie);for(let U of ie.querySelectorAll("*"))Mt(U);for(let U of Et)ee.delete(U);for(let[U,q]of ee){let de=W.get(U);if(!de||de.tagName!==q.tagName)continue;let Fe=z.get(de);Fe&&Fe!==q&&y.delete(Fe);let Ue=y.get(q);Ue&&Ue!==de&&z.delete(Ue),y.set(q,de),z.set(de,q)}}let A=O(l),R=m(d,u,A.scripts);if(R){let W=new Map;for(let[Z,H]of y)W.set(H,Z);for(let[Z,H]of R.newByKey){if(R.disabled.has(Z))continue;let z=R.oldByKey.get(Z);if(!z)continue;let ie=W.get(z);ie&&ie!==H&&y.delete(ie);let ee=y.get(H);ee&&ee!==z&&W.delete(ee),y.set(H,z),W.set(z,H)}}let C=new Set;for(let W of y.values())C.add(W);let $=A.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes($))throw new Error(`Do not understand how to morph style ${$}`);return{target:d,newContent:u,config:A,morphStyle:$,ignoreActive:A.ignoreActive,ignoreActiveValue:A.ignoreActiveValue,restoreFocus:A.restoreFocus,formStateSync:A.formStateSync||"attribute",idMap:f,persistentIds:g,hyperMatches:y,hyperMatchedOldElements:C,merge:R,pantry:v(),activeElementAndParents:N(d),callbacks:A.callbacks,head:A.head,scripts:A.scripts}}function O(d){let u=Object.assign({},E);return Object.assign(u,d),u.callbacks=Object.assign({},E.callbacks,d.callbacks),u.head=Object.assign({},E.head,d.head),u.scripts=Object.assign({},E.scripts,d.scripts),u}function v(){let d=document.createElement("div");return d.hidden=!0,document.body.insertAdjacentElement("afterend",d),d}function N(d){let u=[],l=document.activeElement;if(l?.tagName!=="BODY"&&d.contains(l))for(;l&&(u.push(l),l!==d);)l=l.parentElement;return u}function T(d){let u=Array.from(d.querySelectorAll("[id]"));return d.getAttribute?.("id")&&u.push(d),u}function k(d,u,l,g){for(let f of g){let y=f.getAttribute("id");if(u.has(y)){let A=f;for(;A;){let R=d.get(A);if(R==null&&(R=new Set,d.set(A,R)),R.add(y),A===l)break;A=A.parentElement}}}}function h(d,u){let l=T(d),g=T(u),f=S(l,g),y=new Map;k(y,f,d,l);let A=u.__hyperMorphRoot||u;return k(y,f,A,g),{persistentIds:f,idMap:y}}function S(d,u){let l=new Set,g=new Map;for(let y of d){let A=y.getAttribute("id");g.has(A)?l.add(A):g.set(A,y.tagName)}let f=new Set;for(let y of u){let A=y.getAttribute("id");f.has(A)?l.add(A):g.get(A)===y.tagName&&f.add(A)}for(let y of l)f.delete(y);return f}return p}(),{normalizeElement:en,normalizeParent:St}=function(){let p=new WeakSet;function O(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(p.has(h))return h;if(h instanceof Node){if(h.parentNode)return new N(h);{let S=document.createElement("div");return S.append(h),S}}else{let S=document.createElement("div");for(let d of[...h])S.append(d);return S}}class N{constructor(S){this.originalNode=S,this.realParentNode=S.parentNode,this.previousSibling=S.previousSibling,this.nextSibling=S.nextSibling}get childNodes(){let S=[],d=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;d&&d!=this.nextSibling;)S.push(d),d=d.nextSibling;return S}querySelectorAll(S){return this.childNodes.reduce((d,u)=>{if(u instanceof Element){u.matches(S)&&d.push(u);let l=u.querySelectorAll(S);for(let g=0;g<l.length;g++)d.push(l[g])}return d},[])}insertBefore(S,d){return this.realParentNode.insertBefore(S,d)}moveBefore(S,d){return this.realParentNode.moveBefore(S,d)}get __hyperMorphRoot(){return this.originalNode}}function T(h){let S=g=>`<${g}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,d=h.replace(/<!--[\s\S]*?-->/g,"");for(let g of["script","style","textarea","title"])d=d.replace(new RegExp(`${S(g)}[\\s\\S]*?</${g}\\s*>`,"gi"),"");let u=new RegExp(`${S("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=d,d=d.replace(u,"");while(d!==l);return d}function k(h){let S=new DOMParser,d=T(h);if(d.match(/<\/html>/)||d.match(/<\/head>/)||d.match(/<\/body>/)){let u=S.parseFromString(h,"text/html");if(d.match(/<\/html>/))return p.add(u),u;{let l=u.firstChild;return l&&p.add(l),l}}else{let l=S.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return p.add(l),l}}return{normalizeElement:O,normalizeParent:v}}();return{morph:_,defaults:E,mergeJson:Ze,mergeScriptText:Qe,parseJsonRelaxed:Pe,parseRulesRelaxed:Ht}}();var Or=Xe.morph,Tr=Xe.defaults;var $t=Xe;function et(e,t,{onWidgetRemoved:n}={}){$t.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Le.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var qn="hha:upgrade-check:";function Q(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function tt(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Dt(e,t){let n=tt(e),o=tt(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 Wn(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Vn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function nt({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=Q(t,"hyper-source");if(!a)return null;let s=Q(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 M=`${qn}${c.href}:${s||"none"}`,w,x=e?null:Wn(M);if(x&&typeof x.checkedAt=="number"&&r-x.checkedAt<i)w=x.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let b=await m.text(),E=new DOMParser().parseFromString(b,"text/html");w=Q(E,"hyper-version")}catch{w=null}Vn(M,{checkedAt:r,sourceVersion:w})}return w?{available:Dt(w,s||"0.0.0"),currentVersion:s,sourceVersion:w,sourceUrl:c.href}:null}var _e=["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"],rt=new Set(_e),Bt=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Ft=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var $e={};We($e,{EmptyListInsert:()=>Me,MAX_RULE_DEPTH:()=>ge,MaxRuleDepthExceeded:()=>ce,RuleTargetReadOnly:()=>xe,RulesParseError:()=>me,ShapeMismatch:()=>Ee,UnknownRulesVersion:()=>ae});var me=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},ae=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},ge=20,ce=class extends Error{constructor(t){super(`rule depth exceeded ${ge} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},Ee=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Me=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}},xe=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function X(e,t,n,o={}){return ot(e,t,n,{depth:0,path:[]},o)}function ot(e,t,n,o,r){if(o.depth>ge)throw new ce(o.path);if(typeof n=="string")return Kn(e,t,n,r);if(Array.isArray(n)){let[i,a]=n;return e.find(t,i,r).map((c,M)=>ot(e,c,a,{depth:o.depth+1,path:[...o.path,M]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[a,s]of Object.entries(n))i[a]=ot(e,t,s,{depth:o.depth+1,path:[...o.path,a]},r);return i}return null}function Kn(e,t,n,o){if(n.endsWith("[]")){let i=n.slice(0,-2);return e.find(t,i,o).map(a=>e.text(a))}if(n.startsWith("@"))return Ut(e,t,n.slice(1));if(n.includes("@")){let i=n.lastIndexOf("@"),a=n.slice(0,i),s=n.slice(i+1),c=a?e.find(t,a,o):[t];return c.length===0?null:Ut(e,c[0],s)}if(n===".")return e.text(t);let r=e.find(t,n,o);return r.length===0?null:e.text(r[0])}function Ut(e,t,n){if(rt.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function zn(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Jn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Gn={find(e,t,n={}){let o=Jn(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!zn(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}},V=Gn;function st(e){try{return JSON.parse(e)}catch(t){throw new me(`Invalid strict JSON: ${t.message}`,t)}}function le(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 x=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(x=!0),!x){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 x=s,m=a+1;for(;m<r.length&&r[m]!==x;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:x}),a=m+1;continue}let c=a,M;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let x=[":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 b of x){let E=b.substring(1);if(r.substring(c+1,c+1+E.length)===E){m=!0,c+=E.length;break}}if(!m)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let x=r[c];for(c++;c<r.length&&r[c]!==x;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;M=r.substring(a,c);let w=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(M)?w=t.NUMBER:M==="true"||M==="false"||M==="null"?w=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(M)&&(w=t.SELECTOR),i.push({type:w,value:M,quoted:!1}),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,(M,w)=>w.length%2===0?w+'\\"':M)),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 me("Invalid extraction rules syntax: "+r.message,r)}}var it="1",qt=/^[a-zA-Z0-9_-]+$/;function ye(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!qt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${qt})`);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!==it)throw new ae(a);return{rules:le(e.text(i)),tagNode:i}}var Yn="script[data-rules-name]";function Wt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function we(e,t){let n=e.find(t,Yn,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=Wt(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!==it)throw new ae(s);o.add(a),r.push({name:a,rules:le(e.text(i))})}return r}function De(e,t){let n={};for(let{name:o,rules:r}of we(e,t))n[o]=X(e,t,r);return n}function at(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:De(V,t),version:Q(n,"hyper-version")}}var be=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},ve=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},re=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Oe=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 Vt="text/hyper-upgrade";function ct(e,t){let n=e.find(t,`script[type="${Vt}"]`);if(n.length===0)return null;if(n.length>1)throw new Oe(n.length);return e.text(n[0])||null}var Zn=new Function("url","return import(url)");async function lt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Zn(n)}catch(r){throw new re(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new re("transform must `export default` a function");return o.default}var Qn=.5;function ut(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(L=>e.remove(L));return}let M=r.length>c.length,w=c[0]||null;if(M&&!w&&(w=rr(e,t,n,s),!w))throw new Me(i.path);let x=c.map(L=>Xn(e,L,o,s)),m=null;if(w){m=e.clone(w),s.templateAttr&&e.removeAttr(m,s.templateAttr);let L=e.stripIds(m);L>0&&console.warn(`[hyper-html-api] stripped ${L} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let b=er(r,x,o),E=c[0]||w,P=e.parent(E),_=c.length>0?nr(e,P,E):0,j=new Set,B=r.map((L,F)=>{let I=b[F];if(I>=0)return j.add(I),c[I];let K=e.clone(m);return e.stripIds(K),K});c.forEach((L,F)=>{j.has(F)||e.remove(L)}),B.forEach((L,F)=>{let I=_+F;e.children(P).findIndex(fe=>e.sameNode(fe,L))!==I&&e.insertAt(P,L,I)}),B.forEach((L,F)=>{if(o===null){let I=r[F],K=I==null?"":String(I);e.text(L)!==K&&e.text(L,K)}else{let I=a(e,L,o,r[F],{depth:i.depth+1,path:[...i.path,F]},s);I&&I!==L&&(B[F]=I)}})}function Xn(e,t,n,o){return n===null?e.text(t):X(e,t,n,o)}function er(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((M,w)=>{if(r.has(w))return;let x=tr(i,M,n),m=x===c&&s>=0?Math.abs(w-a)<Math.abs(s-a):!1;(x>c||m)&&(c=x,s=w)}),c>=Qn&&(o[a]=s,r.add(s))}),o}function tr(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 nr(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 rr(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}var Kt=new Set(["checked","selected","disabled","readOnly","paused"]);function oe(e,t,n,o,r={}){let i=[];if(ft(n,o,[],i),i.length)throw new Ee(i);Be(e,t,n,o,{depth:0,path:[]},r)}function Be(e,t,n,o,r,i={}){if(r.depth>ge)throw new ce(r.path);if(o===void 0)return t;if(typeof n=="string")return or(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return ut(e,t,a,s,o,r,Be,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=Be(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 or(e,t,n,o,r,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return ut(e,t,s,null,o,r,Be,i),t}if(n.startsWith("@"))return zt(e,t,n.slice(1),o);if(n.includes("@")){let s=n.lastIndexOf("@"),c=n.slice(0,s),M=n.slice(s+1),w=c?e.find(t,c,i):[t];return w.length===0||zt(e,w[0],M,o),t}if(n===".")return e.text(t,o==null?"":String(o)),t;let a=e.find(t,n,i);return a.length===0||e.text(a[0],o==null?"":String(o)),t}function zt(e,t,n,o){if(Ft.has(n))throw new xe(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return Bt.has(n)?(e.prop(t,n,sr(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function sr(e,t){return t==null?Kt.has(e)?!1:"":Kt.has(e)?!!t:t}function ft(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:Re([...n,i]),expected:"scalar",got:Te(r)})}):o.push({path:Re(n),expected:"array",got:Te(t)});return}t!==null&&typeof t=="object"&&o.push({path:Re(n),expected:"scalar",got:Te(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Re(n),expected:"array",got:Te(t)});return}let r=e[1];t.forEach((i,a)=>ft(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Re(n),expected:"object",got:Te(t)});return}for(let[r,i]of Object.entries(e))ft(i,t[r],[...n,r],o)}}}function Te(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Re(e){return e.join(".")}function Ne(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=dt(t,e,n);return ht(t,e,n),{data:o,summary:n}}function dt(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=>dt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=dt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function ht(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)?ht(e[r],t[r],n):n.discarded+=ue(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>ht(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=ue(t))}}function ue(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+ue(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+ue(n),0):1}function pt(e,t,n){let o=we(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:M,summary:w}=Ne(n[s],c);oe(e,t,c,M),i[s]=w,r.carriedOver+=w.carriedOver,r.discarded+=w.discarded,r.listItems+=w.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=ue(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function mt({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||(j=>fetch(j)),!o)throw new Error("upgrade.run requires a document context");if(e=e||Q(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:Q(o,"hyper-version"),t=t||De(V,o);let s;try{s=await i(a.href)}catch(j){throw new be(a.href,j)}if(!s.ok)throw new be(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),M=new DOMParser().parseFromString(c,"text/html"),w=Q(M,"hyper-version"),x=t,m=!1,b=ct(V,M);if(b){let B=await(await lt(b))(x,{fromVersion:n,toVersion:w});if(!B||typeof B!="object"||Array.isArray(B))throw new re("transform must return a plain object map of { rulesName: data }");x=B,m=!0}let{totals:E,byName:P,rulesTagCount:_}=pt(V,M,x);if(_===0&&Object.keys(x).length>0)throw new ve(a.href);return{html:ir(M),fromVersion:n,toVersion:w,summary:{transformApplied:m,totals:E,byName:P}}}function ir(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
4
- `+e.documentElement.outerHTML}function gt(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 ye(e,o,n)}return null}function Jt(e,t,n,o){let r=gt(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:()=>X(e,t,i,o),set:s=>oe(e,t,i,s,o)}}var ke={extract:(e,t,n)=>X(V,e,t,n),apply:(e,t,n,o)=>oe(V,e,t,n,o),findRulesIn:(e,t)=>ye(V,e,t),findRules:(e,t)=>gt(V,e,t),bind:(e,t,n)=>Jt(V,e,t,n),parseStrict:st,parseRelaxed:le,errors:$e,DOM_PROPERTIES:_e},yt=e=>!!e&&typeof e.nodeType=="number";function Gt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=V.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 ye(V,t).rules}function bt(e,t){let n=yt(e)?e:document,o=yt(e)?t:e;return o===void 0?X(V,n,Gt(n)):ke.bind(n,o).get()}function At(e,t,n){if(!yt(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?oe(V,e,Gt(e),t):ke.bind(e,n).set(t),e}var Yt={buildForm:Ke,bindFormEvents:ze,scaffold:he,morphForm:et,path:Ce},Zt={checkForUpdate:nt,run:mt,extractAll:at,shapeMatch:Ne};var lr={engine:ke,cms:Yt,upgrade:Zt,extractData:bt,applyData:At},ur=lr;return sn(fr);})();
1
+ var HyperHtmlApi=(()=>{var Ke=Object.defineProperty;var sn=Object.getOwnPropertyDescriptor;var an=Object.getOwnPropertyNames;var cn=Object.prototype.hasOwnProperty;var ze=(e,t)=>{for(var n in t)Ke(e,n,{get:t[n],enumerable:!0})},ln=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of an(t))!cn.call(e,r)&&r!==n&&Ke(e,r,{get:()=>t[r],enumerable:!(o=sn(t,r))||o.enumerable});return e};var un=e=>ln(Ke({},"__esModule",{value:!0}),e);var gr={};ze(gr,{applyData:()=>Mt,cms:()=>tn,default:()=>mr,engine:()=>Ce,extractData:()=>Et,upgrade:()=>nn});var He={};ze(He,{fromString:()=>Le,getRuleAtPath:()=>Je,getValueAtPath:()=>Ee,parseConfigKey:()=>dn,setAtPath:()=>re,toConfigKey:()=>fn,toString:()=>J});function J(e){return e.map(String).join(".")}function fn(e){return e.map(t=>typeof t=="number"?"*":String(t)).join(".")}function dn(e){return e===""?[]:e.split(".")}function Le(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function Je(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 Ee(e,t){let n=e;for(let o of t){if(n==null)return;n=n[o]}return n}function re(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]=re(i[o],r,n),i}return{...e&&typeof e=="object"?e:{},[o]:re((e||{})[o],r,n)}}function pe(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]=pe(o);return t}return""}var Pe=new WeakMap;function oe(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 me(e){let t=oe(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}var hn=new Set(["checked","selected","disabled","readOnly","paused"]);function Ge({rules:e,data:t,appRoot:n,cmsRoot:o}){let r=document.createDocumentFragment(),i={rules:e,appRoot:n,cmsRoot:o};return r.appendChild(Ze({rule:e,value:t,path:[],ctx:i})),r}function Ye(e,{rules:t,getData:n,onChange:o}){e.setAttribute("data-hha-form-root",""),Tt.set(e,{rules:t,getData:n,onChange:o}),pn()}var Tt=new WeakMap,Ot=!1;function pn(){Ot||(document.addEventListener("input",Rt,!0),document.addEventListener("change",Rt,!0),document.addEventListener("click",mn,!0),Ot=!0)}function Nt(e){if(!(e instanceof Element))return null;let t=e.closest("[data-hha-form-root]");return t&&Tt.get(t)||null}function mn(e){if(!(e.target instanceof Element))return;let t=e.target.closest("[data-hha-action]");if(!t||e.defaultPrevented)return;let n=Nt(t);if(!n)return;let{rules:o,getData:r,onChange:i}=n,a=t.getAttribute("data-hha-action"),s=Le(t.getAttribute("data-hha-path")||"");if(a==="scalar-array-add"){let c=Ee(r(),s)||[];i(re(r(),s,[...c,""]),{structural:!0});return}if(a==="object-array-add"){let c=Je(o,s);if(!Array.isArray(c))return;let A=Ee(r(),s)||[];i(re(r(),s,[...A,pe(c[1])]),{structural:!0});return}if(a==="array-remove"){if(s.length===0)return;let c=s.slice(0,-1),A=s[s.length-1],x=Ee(r(),c)||[];if(typeof A!="number")return;let w=x.filter((m,b)=>b!==A);i(re(r(),c,w),{structural:!0})}}function Rt(e){let t=e.target;if(!t?.matches?.("input, textarea, select"))return;let n=Nt(t);if(!n)return;let{getData:o,onChange:r}=n,i=t.closest("[data-hha-path]");if(!i)return;let a=Le(i.getAttribute("data-hha-path")||""),s=t.type==="checkbox"?t.checked:t.value;r(re(o(),a,s),{structural:!1})}function Ze({rule:e,value:t,path:n,ctx:o}){if(typeof e=="string")return e.endsWith("[]")?bn({rule:e,value:t,path:n,ctx:o}):yn({rule:e,value:t,path:n,ctx:o});if(Array.isArray(e))return An({rule:e,value:t,path:n,ctx:o});if(typeof e=="object"&&e!==null)return gn({rule:e,value:t,path:n,ctx:o});let r=document.createElement("span");return r.textContent="(unsupported rule)",r}function gn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");if(r.className="form-section",r.setAttribute("data-hha-path",J(n)),n.length>0){let i=document.createElement("div");i.className="form-section-label",i.textContent=je(n[n.length-1]),r.appendChild(i)}for(let[i,a]of Object.entries(e)){let s=[...n,i],c=t?.[i];r.appendChild(Ze({rule:a,value:c,path:s,ctx:o}))}return r}function yn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="field-row",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="field-body";let a=document.createElement("label");a.className="field-label",a.textContent=je(n[n.length-1]||".")+wn(e);let s=En(e,o.appRoot),c=Sn(s,{value:t,rule:e,path:n,appRoot:o.appRoot}),A=c.el;return A.classList.add(s.type==="textarea"?"field-textarea":"field-input"),i.appendChild(a),i.appendChild(A),r.appendChild(i),Pe.set(r,c),r}function bn({rule:e,value:t,path:n,ctx:o}){let r=document.createElement("div");r.className="form-section",r.setAttribute("data-hha-path",J(n));let i=document.createElement("div");i.className="form-section-label",i.textContent=je(n[n.length-1]),r.appendChild(i);let a=Array.isArray(t)?t:[],s=document.createElement("div");r.appendChild(s),a.forEach((A,x)=>{let w=[...n,x],m=document.createElement("div");m.className="scalar-array-row",m.setAttribute("data-hha-path",J(w));let b=document.createElement("input");b.type="text",b.className="field-input",b.value=A==null?"":String(A);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",J(w)),m.appendChild(b),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",J(n)),r.appendChild(c),r}function An({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",J(n));let s=document.createElement("div");s.className="form-section-label",s.textContent=je(n[n.length-1]),a.appendChild(s),i.forEach((A,x)=>{let w=[...n,x],m=document.createElement("div");m.className="array-card",m.setAttribute("data-hha-path",J(w));let b=document.createElement("button");b.type="button",b.className="array-remove",b.textContent="\xD7",b.title="remove item",b.setAttribute("data-hha-action","array-remove"),b.setAttribute("data-hha-path",J(w)),m.appendChild(b);let M=Ze({rule:r,value:A,path:w,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",J(n)),a.appendChild(c),a}function Sn(e,t){let n=xn(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 En(e,t){let n=null;if(e.startsWith("@")?n=e.slice(1):n=me(e).prop,n&&hn.has(n))return{type:"checkbox"};if(n==="innerHTML")return{type:"textarea"};let o=Mn(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 Mn(e,t){if(!t||e==="."||e===""||e.startsWith("@"))return null;let n=me(e).selector;if(!n)return null;try{return t.querySelector(n)}catch{return null}}function xn(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 je(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 wn(e){return` \xB7 ${e}`}var kt={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 vn(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 On(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 Rn(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 Tn(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function Nn(e,t){let n=[e.tagName];return t.includeClasses&&n.push(On(e)),n.push(Rn(e,t)),vn(n.join("|"))}function kn(e){let t=e.tagName,n=1,o=e.previousElementSibling;for(;o;)o.tagName===t&&n++,o=o.previousElementSibling;return n}function In(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function Cn(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let n=e.getAttribute?.("role");return n?`@${n}`:e.tagName}function Ln(e,t){let n=[],o=e;for(;o&&o.tagName&&n.length<t.maxPathDepth;){let r=`${o.tagName}:${kn(o)}`;if(n.unshift(r),o!==e&&In(o,t)){n.unshift(Cn(o));break}o=o.parentElement}return n}function Hn(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 G(e,t,n){if(n.has(e))return n.get(e);let o={signature:Nn(e,t),path:Ln(e,t),textHint:Tn(e,t)};return n.set(e,o),o}function Ht(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=G(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 Pn(e,t,n){n.delete(e),t.delete(e);let o=e.querySelectorAll("*");for(let r of o)t.delete(r)}function Qe(e,t,n,o,r){let i=G(e,n,o),a=G(t,n,o),s=n.weights,c={},A=0;if(i.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};A+=s.signature,c.signature=s.signature;let w=Hn(i.path,a.path)*s.pathSegment;A+=w,c.path=w;let m=!0;if(i.textHint&&a.textHint?i.textHint===a.textHint?(A+=s.textMatch,c.text=s.textMatch):(A-=s.textMismatch,c.text=-s.textMismatch,m=!1):i.textHint!==a.textHint&&(A-=s.textMismatch,c.text=-s.textMismatch,m=!1),r.candidateCount===1&&m&&(A+=s.uniqueCandidate,c.unique=s.uniqueCandidate),typeof i.domIndex=="number"&&typeof a.domIndex=="number"){let b=Math.abs(i.domIndex-a.domIndex),M=Math.min(b*s.positionPenalty,s.maxDriftPenalty);A-=M,c.drift=-M}return{score:A,breakdown:c}}function It(e,t,n,o,r){if(n.excludeIds&&e.getAttribute("id"))return null;let i=Ht(t,n,o,r),a=G(e,n,o);if(typeof a.domIndex!="number"){let m=0,b=e.previousElementSibling;for(;b;)m++,b=b.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 A=null,x=0,w=null;for(let m of c){let{score:b,breakdown:M}=Qe(e,m,n,o,{candidateCount:c.length});b>x&&(x=b,A=m,w=M)}return x<n.minConfidence?null:{element:A,confidence:x,breakdown:w}}function jn(e,t,n,o){let r=[],i=n.weights.signature+n.weights.slotMatch,a={slot:i};function s(w){if(w.children)return w.children;let m=w.childNodes;if(!m)return[];let b=[];for(let M=0;M<m.length;M++)m[M].nodeType===1&&b.push(m[M]);return b}function c(w,m){let b=s(w),M=s(m);if(b.length===M.length)for(let L=0;L<b.length;L++){let j=b[L],P=M[L];if(n.shouldIgnore?.(j)||n.shouldIgnore?.(P)||n.excludeIds&&(j.getAttribute("id")||P.getAttribute("id"))||j.tagName!==P.tagName)continue;let D=G(j,n,o).signature,V=G(P,n,o).signature;D!==V&&r.push({newEl:j,oldEl:P,score:i,breakdown:a}),c(j,P)}}function A(w,m){for(;;){if(w.tagName===m.tagName)return[w,m];let b=s(w);if(!w.tagName&&b.length===1){w=b[0];continue}let M=s(m);if(M.length===1&&M[0].tagName===w.tagName){m=M[0];continue}return null}}let x=A(e,t);return x&&c(x[0],x[1]),r}function Ct(e,t,n,o,r){let i=t.querySelectorAll("*"),a=Ht(e,n,o,r),s=0;for(let b of i){let M=G(b,n,o);M.domIndex=s++}let c=[],A=new Map;function x(b,M,L){let j=new Set;if(b.textHint){let I=A.get(b.signature);if(!I){I=new Map;for(let U of M){let ee=G(U,n,o).textHint,te=I.get(ee);te||(te=[],I.set(ee,te)),te.push(U)}A.set(b.signature,I)}let K=I.get(b.textHint);if(K)for(let U=0;U<K.length&&U<L;U++)j.add(K[U])}let P=0,D=M.length;for(;P<D;){let I=P+D>>1;G(M[I],n,o).domIndex<b.domIndex?P=I+1:D=I}let V=Math.max(0,Math.min(P-(L>>1),M.length-L)),Y=Math.min(V+L,M.length);for(let I=V;I<Y;I++)j.add(M[I]);return[...j]}for(let b of i){if(n.shouldIgnore?.(b)||n.excludeIds&&b.getAttribute("id"))continue;let M=G(b,n,o),L=a.get(M.signature)||[],j=n.excludeIds?L.filter(V=>!V.getAttribute("id")):L,P=n.maxScoredCandidates,D=P&&j.length>P?x(M,j,P):j;for(let V of D){let{score:Y,breakdown:I}=Qe(b,V,n,o,{candidateCount:j.length});Y>=n.minConfidence&&c.push({newEl:b,oldEl:V,score:Y,breakdown:I})}}if(n.weights.slotMatch>0){let b=jn(t,e,n,o);for(let M of b)c.push(M)}c.sort((b,M)=>M.score-b.score);let w=new Map,m=new Set;for(let{newEl:b,oldEl:M}of c)w.has(b)||m.has(M)||(w.set(b,M),m.add(M));return w}function Lt(e,t,n,o){let r=G(e,n,o),i=G(t,n,o),{score:a,breakdown:s}=Qe(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 Pt(e={}){let t={...kt,...e,weights:{...kt.weights,...e.weights}},n=new WeakMap,o=new WeakMap;return{findMatch:(r,i)=>It(r,i,t,n,o),computeMatches:(r,i)=>Ct(r,i,t,n,o),explain:(r,i)=>Lt(r,i,t,n),invalidate:r=>Pn(r,n,o),session:()=>{let r=new WeakMap,i=new WeakMap;return{findMatch:(a,s)=>It(a,s,t,r,i),computeMatches:(a,s)=>Ct(a,s,t,r,i),explain:(a,s)=>Lt(a,s,t,r)}},getConfig:()=>({...t})}}function Xe(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 jt(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,n)=>n.length%2===0?n+'\\"':t)}var _n=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,$n=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function _e(e){try{return JSON.parse(e)}catch{return JSON.parse(Dn(e))}}function Dn(e){let t="",n=0,o=(r,i)=>{throw new Error(`Invalid relaxed JSON: ${r} at position ${i}`)};for(;n<e.length&&(n=Xe(e,n),!(n>=e.length));){let r=e[n];if("{}[]:".includes(r)){t+=r,n++;continue}if(r===","){let s=Xe(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=jt(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"||_n.test(a)){t+=a,n=i;continue}if($n.test(a)){if(e[Xe(e,i)]===":"){t+='"'+a+'"',n=i;continue}o("unquoted value "+JSON.stringify(a),n)}o("invalid token "+JSON.stringify(a),n)}return t}function _t(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 w=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(w=!0),!w){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 w=s,m=a+1;for(;m<r.length&&r[m]!==w;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:w}),a=m+1;continue}let c=a,A;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let b of w){let M=b.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 w=r[c];for(c++;c<r.length&&r[c]!==w;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;A=r.substring(a,c);let x=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(A)?x=t.NUMBER:A==="true"||A==="false"||A==="null"?x=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(A)&&(x=t.SELECTOR),i.push({type:x,value:A,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=jt(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 $=Symbol("hyper-morph-json-merge:missing"),$t=["id","_id","uuid","key","slug","code","name"];function ge(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Me(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Bn(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function se(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(!se(e[n],t[n]))return!1;return!0}if(ge(e)&&ge(t)){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n)if(!Me(t,o)||!se(e[o],t[o]))return!1;return!0}return!1}function Dt(e,t,n,o){return se(t,n)?t:se(t,e)?n:se(n,e)?t:ge(t)&&ge(n)?Fn(ge(e)?e:{},t,n,o):Array.isArray(t)&&Array.isArray(n)?Vn(Array.isArray(e)?e:[],t,n,o):n}function Bt(e,t,n,o){return t===$&&n===$?$:t===$?e===$?n:se(n,e)?$:n:n===$?e===$?t:$:Dt(e,t,n,o)}function Fn(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=Bt(Me(e,a)?e[a]:$,Me(t,a)?t[a]:$,Me(n,a)?n[a]:$,o);s!==$&&Bn(r,a,s)}return r}function Un(e){return e===null||typeof e!="object"}function $e(e){return typeof e+":"+String(e)}function qn(e,t){for(let n of t){let o=new Set;for(let r of n){if(!Me(r,e))return!1;let i=r[e];if(typeof i!="string"&&typeof i!="number")return!1;let a=$e(i);if(o.has(a))return!1;o.add(a)}}return!0}function Wn(e,t,n,o){let r=[e,t,n],i=!0;for(let a of r)for(let s of a)ge(s)||(i=!1);if(i){for(let a of o.keyCandidates)if(qn(a,r))return{kind:"keyed",field:a};return null}for(let a of r){let s=new Set;for(let c of a){if(!Un(c))return null;let A=$e(c);if(s.has(A))return null;s.add(A)}}return{kind:"self"}}function Vn(e,t,n,o){let r=Wn(e,t,n,o);if(!r)return n;let i=r.kind==="self"?$e:b=>$e(b[r.field]),a=b=>{let M=new Map;for(let L of b)M.set(i(L),L);return M},s=a(e),c=a(t),A=a(n),x=new Map,w=new Set([...s.keys(),...c.keys(),...A.keys()]);for(let b of w){let M=Bt(s.has(b)?s.get(b):$,c.has(b)?c.get(b):$,A.has(b)?A.get(b):$,o);M!==$&&x.set(b,M)}let m=[];for(let b of n){let M=i(b);x.has(M)&&m.push(M)}for(let b=0;b<t.length;b++){let M=i(t[b]);if(!x.has(M)||m.includes(M))continue;let L=0;for(let j=b-1;j>=0;j--){let P=m.indexOf(i(t[j]));if(P!==-1){L=P+1;break}}m.splice(L,0,M)}return m.map(b=>x.get(b))}function et(e,t,n,o={}){let r=o.keyCandidates?[...o.keyCandidates,...$t]:$t;return Dt(e===void 0?$:e,t,n,{keyCandidates:r})}function tt(e,t,n,o={}){let r=o.parse||_e,i=[],a=(w,m)=>{if(typeof w!="string")return $;try{return r(w)}catch(b){return i.push(`${m} side is not valid JSON (${b.message})`),$}},s=a(t,"local"),c=a(n,"remote");if(s===$)return{text:n,warnings:i};if(c===$)return{text:t,warnings:i};let A=a(e,"base"),x=et(A===$?void 0:A,s,c,o);return se(x,c)?{text:n,warnings:i}:se(x,s)?{text:t,warnings:i}:{text:JSON.stringify(x,null,2),warnings:i}}var nt=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(p){if(!(p instanceof Element))return!1;if(p.matches(t))return!0;if(p.tagName==="LINK"||p.tagName==="SCRIPT"){let O=p.getAttribute("src")||p.getAttribute("href")||"";if(O.startsWith("chrome-extension://")||O.startsWith("moz-extension://")||O.startsWith("safari-web-extension://"))return!0}return!1}function o(p){return p instanceof Element?p.closest(t)?!0:n(p):!1}let r=Pt({shouldIgnore:o});function i(p,O,v){if(v){let k=v.identityOf(p);if(k&&!v.disabled.has(k.key))return"hm-merge:"+k.key}if(O!=="smart")return p.outerHTML;let N=p.getAttribute("src"),R=p.getAttribute("type")||"text/javascript";if(N)try{let k=new URL(N,window.location.href);return`ext:${R}:${k.origin}${k.pathname}${k.search}`}catch{return`ext:${R}:${N}`}else{let k=p.textContent.trim(),h=5381;for(let E=0;E<k.length;E++)h=(h<<5)+h^k.charCodeAt(E);return`inline:${R}:${Math.abs(h).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(p){return p instanceof Element&&p.tagName==="SCRIPT"&&p.namespaceURI===a}function c(p){let O=document.createElement("div");O.innerHTML="<script><\/script>";let v=O.firstChild;for(let N of p.attributes)v.setAttribute(N.name,N.value);return v.textContent=p.textContent,v}function A(p){if(s(p))return c(p);if(p instanceof Element)for(let O of p.querySelectorAll("script"))s(O)&&O.replaceWith(c(O));return p}function x(p){let O=(p.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return O==="application/json"||O.endsWith("+json")}let w={match:p=>p.hasAttribute("merge"),identity:p=>p.getAttribute("merge")};function m(p,O,v){if(v.merge===!1)return null;let N=[w,...v.mergeTags||[]],R=new WeakMap,k=f=>{if(R.has(f))return R.get(f);let y=null;if(s(f)&&!f.getAttribute("src")&&!o(f)){let S=f;for(let T=0;T<N.length;T++)if(N[T].match(S)){if(!x(S))console.warn("[hyper-morph] merge ignored: script type is not JSON",S);else{let C=N[T].identity(S);C!=null&&C!==""&&(y={key:T+":"+C,raw:C,recognizer:N[T]})}break}}return R.set(f,y),y},h=new Set,E=f=>{let y=new Map,S=T=>{let C=k(T);C&&(y.has(C.key)?(h.add(C.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${C.raw}"`)):y.set(C.key,T))};s(f)&&S(f);for(let T of f.querySelectorAll("script"))S(T);return y},d=E(p),u=E(O.__hyperMorphRoot||O);if(d.size===0&&u.size===0)return null;let l=null;return{identityOf:k,disabled:h,oldByKey:d,newByKey:u,baseTexts:()=>{if(l)return l;l=new Map;let f=v.mergeBase;if(!f)return l;let y;typeof f=="string"?y=new DOMParser().parseFromString(f,"text/html").documentElement:f instanceof Document?y=f.documentElement:y=f;let S=T=>{let C=k(T);C&&!l.has(C.key)&&l.set(C.key,T.textContent)};s(y)&&S(y);for(let T of y.querySelectorAll("script"))S(T);return l}}}function b(p,O,v){let N=p.merge;if(!N)return!1;let R=N.identityOf(O);if(!R||N.disabled.has(R.key))return!1;let k=N.identityOf(v);if(!k||k.key!==R.key)return!1;let h=O,E=v,d=E.getAttribute("merge-key")||h.getAttribute("merge-key"),{text:u,warnings:l}=tt(N.baseTexts().get(R.key),h.textContent,E.textContent,{parse:R.recognizer.parse,keyCandidates:d?d.split(/[\s,]+/).filter(Boolean):void 0});for(let g of l)console.warn(`[hyper-morph] merge "${R.raw}": ${g}`);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:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:p=>p.getAttribute("im-preserve")==="true",shouldReAppend:p=>p.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},L={computeMatches(p,O){let{computeMatches:v}=r.session();return v(p,O)}};function j(p,O,v={}){p=on(p);let N=xt(O),R=rn(p,N,v),k=R.scripts.handle?new Set(Array.from(p.querySelectorAll("script")).map(u=>i(u,R.scripts.matchMode,R.merge))):null,h=V(R),E=U(R,p,N,u=>u.morphStyle==="innerHTML"?(I(u,p,N),Array.from(p.childNodes)):D(u,p,N)),d=u=>{h&&Y(R,h),P(R);let l=k?qe(u,k,R):[];return l.length>0?Promise.all(l).then(()=>u):u};return E instanceof Promise?E.then(d):d(E)}function P(p){for(let O of Array.from(p.pantry.childNodes))p.callbacks.beforeNodeRemoved(O)!==!1&&p.callbacks.afterNodeRemoved(O);p.pantry.remove()}function D(p,O,v){let N=xt(O);return I(p,N,v,O,O.nextSibling),Array.from(N.childNodes)}function V(p){if(!p.config.restoreFocus)return null;let O=document.activeElement;if(!(O instanceof HTMLInputElement||O instanceof HTMLTextAreaElement))return null;let{id:v,selectionStart:N,selectionEnd:R}=O;return{element:O,id:v,selectionStart:N,selectionEnd:R}}function Y(p,O){let v=O.element;if(O.id&&O.id!==document.activeElement?.getAttribute("id")&&(v=p.target.querySelector(`[id="${CSS.escape(O.id)}"]`),v?.focus()),v&&!v.selectionEnd&&O.selectionEnd!=null)try{v.setSelectionRange(O.selectionStart,O.selectionEnd)}catch{}}let I=function(){function p(u,l,g,f=null,y=null){l instanceof HTMLTemplateElement&&g instanceof HTMLTemplateElement&&(l=l.content,g=g.content),f||=l.firstChild;for(let S of g.childNodes){if(n(S))continue;if(f&&f!=y){let C=v(u,S,f,y);if(C){C!==f&&R(u,f,C),K(C,S,u),f=C.nextSibling;continue}}if(S instanceof Element){let C=S.getAttribute("id");if(u.persistentIds.has(C)){let _=k(l,C,f,u);K(_,S,u),f=_.nextSibling;continue}if(!u.idMap.has(S)){let _=u.hyperMatches.get(S);if(_&&!u.idMap.has(_)&&!d(_,l)){E(l,_,f),K(_,S,u),f=_.nextSibling;continue}}}let T=O(l,S,f,u);T&&(f=T.nextSibling)}for(;f&&f!=y;){let S=f;f=f.nextSibling,n(S)||N(u,S)}}function O(u,l,g,f){if(f.callbacks.beforeNodeAdded(l)===!1)return null;if(f.idMap.has(l)){let y=l,S=document.createElementNS(y.namespaceURI,y.localName);return u.insertBefore(S,g),K(S,l,f),f.callbacks.afterNodeAdded(S),S}else{let y=A(document.importNode(l,!0));return u.insertBefore(y,g),f.callbacks.afterNodeAdded(y),y}}let v=function(){function u(f,y,S,T){let C=y instanceof Element&&!f.idMap.has(y)?f.hyperMatches.get(y):null,_=null,q=y.nextSibling,Z=0,H=S;for(;H&&H!=T;){if(n(H)){H=H.nextSibling;continue}if(g(H,y)){if(l(f,H,y)||H===C&&!f.idMap.has(H))return H;if(_===null){let z=H instanceof Element&&f.hyperMatchedOldElements.has(H);!f.idMap.has(H)&&!z&&(_=H)}}if(_===null&&q&&g(H,q)&&(Z++,q=q.nextSibling,Z>=2&&(_=void 0)),f.activeElementAndParents.includes(H))break;H=H.nextSibling}return _||null}function l(f,y,S){let T=f.idMap.get(y),C=f.idMap.get(S);if(!C||!T)return!1;for(let _ of T)if(C.has(_))return!0;return!1}function g(f,y){let S=f,T=y;return S.nodeType===T.nodeType&&S.tagName===T.tagName&&(!S.getAttribute?.("id")||S.getAttribute?.("id")===T.getAttribute?.("id"))}return u}();function N(u,l){let g=l instanceof Element&&u.hyperMatchedOldElements.has(l)&&!u.idMap.has(l);if(u.idMap.has(l)||g)E(u.pantry,l,null);else{if(u.callbacks.beforeNodeRemoved(l)===!1)return;l.parentNode?.removeChild(l),u.callbacks.afterNodeRemoved(l)}}function R(u,l,g){let f=l;for(;f&&f!==g;){let y=f;f=f.nextSibling,n(y)||N(u,y)}return f}function k(u,l,g,f){let y=f.target.getAttribute?.("id")===l&&f.target||f.target.querySelector(`[id="${CSS.escape(l)}"]`)||f.pantry.querySelector(`[id="${CSS.escape(l)}"]`);return h(y,f),E(u,y,g),y}function h(u,l){let g=u.getAttribute("id");for(;u=u.parentNode;){let f=l.idMap.get(u);f&&(f.delete(g),f.size||l.idMap.delete(u))}}function E(u,l,g){if(u.moveBefore)try{u.moveBefore(l,g)}catch{u.insertBefore(l,g)}else u.insertBefore(l,g)}function d(u,l){let g=l instanceof Element?l:l.realParentNode;return!!g&&u.contains(g)}return p}(),K=function(){function p(h,E,d){return d.ignoreActive&&h===document.activeElement?null:(d.callbacks.beforeNodeMorphed(h,E)===!1||(h instanceof HTMLHeadElement&&d.head.ignore||(h instanceof HTMLHeadElement&&d.head.style!=="morph"?te(h,E,d):(O(h,E,d),b(d,h,E)||k(h,d)||I(d,h,E))),d.callbacks.afterNodeMorphed(h,E)),h)}function O(h,E,d){let u=E.nodeType;if(u===1){let l=h,g=E,f=l.attributes,y=g.attributes;for(let S of y)R(S.name,l,"update",d)||l.getAttribute(S.name)!==S.value&&l.setAttribute(S.name,S.value);for(let S=f.length-1;0<=S;S--){let T=f[S];if(T&&!g.hasAttribute(T.name)){if(R(T.name,l,"remove",d))continue;l.removeAttribute(T.name)}}k(l,d)||v(l,g,d)}(u===8||u===3)&&h.nodeValue!==E.nodeValue&&(h.nodeValue=E.nodeValue)}function v(h,E,d){if(h instanceof HTMLInputElement&&E instanceof HTMLInputElement&&E.type!=="file"){let u=E.value,l=h.value;N(h,E,"checked",d),N(h,E,"disabled",d),d.formStateSync==="property"&&h.indeterminate!==E.indeterminate&&(h.indeterminate=E.indeterminate),d.formStateSync==="property"?l!==u&&(R("value",h,"update",d)||(h.value=u)):E.hasAttribute("value")?l!==u&&(R("value",h,"update",d)||(h.setAttribute("value",u),h.value=u)):R("value",h,"remove",d)||(h.value="",h.removeAttribute("value"))}else if(h instanceof HTMLOptionElement&&E instanceof HTMLOptionElement)N(h,E,"selected",d);else if(h instanceof HTMLTextAreaElement&&E instanceof HTMLTextAreaElement){let u=E.value,l=h.value;if(R("value",h,"update",d)||(u!==l&&(h.value=u),d.formStateSync==="property"))return;h.firstChild&&h.firstChild.nodeValue!==u&&(h.firstChild.nodeValue=u)}}function N(h,E,d,u){let l=E[d],g=h[d];if(l!==g){let f=R(d,h,"update",u);if(f||(h[d]=E[d]),u.formStateSync==="property")return;l?f||h.setAttribute(d,""):R(d,h,"remove",u)||h.removeAttribute(d)}}function R(h,E,d,u){return h==="value"&&u.ignoreActiveValue&&E===document.activeElement?!0:u.callbacks.beforeAttributeUpdated(h,E,d)===!1}function k(h,E){return!!E.ignoreActiveValue&&h===document.activeElement&&h!==document.body}return p}();function U(p,O,v,N){if(p.head.block){let R=O.querySelector("head"),k=v.querySelector("head");if(R&&k){let h=te(R,k,p);return Promise.all(h).then(()=>(p.head.block=!1,p.head.ignore=!0,N(p)))}}return N(p)}function ee(p){return p.tagName==="SCRIPT"?!!p.getAttribute("src"):p.tagName==="LINK"?(p.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!p.getAttribute("href"):!1}function te(p,O,v){let N=[],R=[],k=[],h=[],E=v.scripts.matchMode,d=g=>{if(g.tagName==="SCRIPT")return i(g,E,v.merge);if(g.tagName==="LINK"&&E==="smart"){let f=g.getAttribute("href");if(f)try{let y=new URL(f,window.location.href);return`link:${g.getAttribute("rel")||""}:${y.origin}${y.pathname}${y.search}`}catch{}}return g.outerHTML},u=new Map;for(let g of O.children){if(n(g))continue;let f=d(g),y=u.get(f);y||(y=[],u.set(f,y)),y.push(g)}for(let g of p.children){let f=d(g),y=u.get(f),S=!!(y&&y.length),T=v.head.shouldReAppend(g),C=v.head.shouldPreserve(g);if(S||C)if(T)R.push(g);else{if(y&&y.length){let _=y.pop();y.length||u.delete(f),b(v,g,_)}k.push(g)}else v.head.style==="append"?T&&(R.push(g),h.push(g)):v.head.shouldRemove(g)!==!1&&!n(g)&&R.push(g)}for(let g of u.values())h.push(...g);let l=[];for(let g of h){let f=document.createRange().createContextualFragment(g.outerHTML).firstChild;if(v.callbacks.beforeNodeAdded(f)!==!1){if(f instanceof Element&&ee(f)){let y,S=new Promise(function(T){y=T});f.addEventListener("load",function(){y()}),f.addEventListener("error",function(){y()}),l.push(S)}p.appendChild(f),v.callbacks.afterNodeAdded(f),N.push(f)}}for(let g of R)v.callbacks.beforeNodeRemoved(g)!==!1&&(p.removeChild(g),v.callbacks.afterNodeRemoved(g));return v.head.afterHeadMorphed(p,{added:N,kept:k,removed:R}),l}function qe(p,O,v){if(!v.scripts.handle)return[];let N=[],R=[],k=[],h=[],E=v.scripts.matchMode,d=[];for(let l of p)if(l instanceof Element){s(l)&&d.push(l);for(let g of l.querySelectorAll("script"))s(g)&&d.push(g)}for(let l of d){if(l.closest("head")||o(l))continue;let g=i(l,E,v.merge),f=O.has(g),y=v.scripts.shouldPreserve(l),S=v.scripts.shouldReAppend(l);f||y?S?(R.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 g=document.createElement("script");for(let f of l.attributes)g.setAttribute(f.name,f.value);if(g.textContent=l.textContent,g.src){let f,y=new Promise(function(S){f=S});g.addEventListener("load",function(){f()}),g.addEventListener("error",function(){f()}),u.push(y)}l.replaceWith(g),v.callbacks.afterNodeAdded(g),N.push(g)}return v.scripts.afterScriptsHandled(v.target,{added:N,kept:k,removed:R}),u}let rn=function(){function p(d,u,l){let{persistentIds:g,idMap:f}=h(d,u),y=L.computeMatches(d,u);if(typeof l.key=="function"){let q=new Map,Z=new Set,H=B=>{let F=l.key(B);F!=null&&(q.has(F)?Z.add(F):q.set(F,B))};d instanceof Element&&H(d);for(let B of d.querySelectorAll("*"))H(B);for(let B of Z)q.delete(B);let z=new Map;for(let[B,F]of y)z.set(F,B);let ce=u.__hyperMorphRoot||u,ne=new Map,wt=new Set,vt=B=>{let F=l.key(B);F!=null&&(ne.has(F)?wt.add(F):ne.set(F,B))};ce instanceof Element&&vt(ce);for(let B of ce.querySelectorAll("*"))vt(B);for(let B of wt)ne.delete(B);for(let[B,F]of ne){let he=q.get(B);if(!he||he.tagName!==F.tagName)continue;let We=z.get(he);We&&We!==F&&y.delete(We);let Ve=y.get(F);Ve&&Ve!==he&&z.delete(Ve),y.set(F,he),z.set(he,F)}}let S=O(l),T=m(d,u,S.scripts);if(T){let q=new Map;for(let[Z,H]of y)q.set(H,Z);for(let[Z,H]of T.newByKey){if(T.disabled.has(Z))continue;let z=T.oldByKey.get(Z);if(!z)continue;let ce=q.get(z);ce&&ce!==H&&y.delete(ce);let ne=y.get(H);ne&&ne!==z&&q.delete(ne),y.set(H,z),q.set(z,H)}}let C=new Set;for(let q of y.values())C.add(q);let _=S.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(_))throw new Error(`Do not understand how to morph style ${_}`);return{target:d,newContent:u,config:S,morphStyle:_,ignoreActive:S.ignoreActive,ignoreActiveValue:S.ignoreActiveValue,restoreFocus:S.restoreFocus,formStateSync:S.formStateSync||"attribute",idMap:f,persistentIds:g,hyperMatches:y,hyperMatchedOldElements:C,merge:T,pantry:v(),activeElementAndParents:N(d),callbacks:S.callbacks,head:S.head,scripts:S.scripts}}function O(d){let u=Object.assign({},M);return Object.assign(u,d),u.callbacks=Object.assign({},M.callbacks,d.callbacks),u.head=Object.assign({},M.head,d.head),u.scripts=Object.assign({},M.scripts,d.scripts),u}function v(){let d=document.createElement("div");return d.hidden=!0,document.body.insertAdjacentElement("afterend",d),d}function N(d){let u=[],l=document.activeElement;if(l?.tagName!=="BODY"&&d.contains(l))for(;l&&(u.push(l),l!==d);)l=l.parentElement;return u}function R(d){let u=Array.from(d.querySelectorAll("[id]"));return d.getAttribute?.("id")&&u.push(d),u}function k(d,u,l,g){for(let f of g){let y=f.getAttribute("id");if(u.has(y)){let S=f;for(;S;){let T=d.get(S);if(T==null&&(T=new Set,d.set(S,T)),T.add(y),S===l)break;S=S.parentElement}}}}function h(d,u){let l=R(d),g=R(u),f=E(l,g),y=new Map;k(y,f,d,l);let S=u.__hyperMorphRoot||u;return k(y,f,S,g),{persistentIds:f,idMap:y}}function E(d,u){let l=new Set,g=new Map;for(let y of d){let S=y.getAttribute("id");g.has(S)?l.add(S):g.set(S,y.tagName)}let f=new Set;for(let y of u){let S=y.getAttribute("id");f.has(S)?l.add(S):g.get(S)===y.tagName&&f.add(S)}for(let y of l)f.delete(y);return f}return p}(),{normalizeElement:on,normalizeParent:xt}=function(){let p=new WeakSet;function O(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(p.has(h))return h;if(h instanceof Node){if(h.parentNode)return new N(h);{let E=document.createElement("div");return E.append(h),E}}else{let E=document.createElement("div");for(let d of[...h])E.append(d);return E}}class N{constructor(E){this.originalNode=E,this.realParentNode=E.parentNode,this.previousSibling=E.previousSibling,this.nextSibling=E.nextSibling}get childNodes(){let E=[],d=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;d&&d!=this.nextSibling;)E.push(d),d=d.nextSibling;return E}querySelectorAll(E){return this.childNodes.reduce((d,u)=>{if(u instanceof Element){u.matches(E)&&d.push(u);let l=u.querySelectorAll(E);for(let g=0;g<l.length;g++)d.push(l[g])}return d},[])}insertBefore(E,d){return this.realParentNode.insertBefore(E,d)}moveBefore(E,d){return this.realParentNode.moveBefore(E,d)}get __hyperMorphRoot(){return this.originalNode}}function R(h){let E=g=>`<${g}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,d=h.replace(/<!--[\s\S]*?-->/g,"");for(let g of["script","style","textarea","title"])d=d.replace(new RegExp(`${E(g)}[\\s\\S]*?</${g}\\s*>`,"gi"),"");let u=new RegExp(`${E("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),l;do l=d,d=d.replace(u,"");while(d!==l);return d}function k(h){let E=new DOMParser,d=R(h);if(d.match(/<\/html>/)||d.match(/<\/head>/)||d.match(/<\/body>/)){let u=E.parseFromString(h,"text/html");if(d.match(/<\/html>/))return p.add(u),u;{let l=u.firstChild;return l&&p.add(l),l}}else{let l=E.parseFromString("<body><template>"+h+"</template></body>","text/html").body.querySelector("template").content;return p.add(l),l}}return{normalizeElement:O,normalizeParent:v}}();return{morph:j,defaults:M,mergeJson:et,mergeScriptText:tt,parseJsonRelaxed:_e,parseRulesRelaxed:_t}}();var Lr=nt.morph,Hr=nt.defaults;var Ft=nt;function rt(e,t,{onWidgetRemoved:n}={}){Ft.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:!0,restoreFocus:!0,formStateSync:"property",callbacks:{beforeNodeRemoved(o){let r=Pe.get(o);r?.destroy&&r.destroy(),n?.(o)}}})}var zn="hha:upgrade-check:";function Q(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function ot(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ut(e,t){let n=ot(e),o=ot(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 Jn(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Gn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function st({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=Q(t,"hyper-source");if(!a)return null;let s=Q(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 A=`${zn}${c.href}:${s||"none"}`,x,w=e?null:Jn(A);if(w&&typeof w.checkedAt=="number"&&r-w.checkedAt<i)x=w.sourceVersion;else{try{let m=await o(c.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let b=await m.text(),M=new DOMParser().parseFromString(b,"text/html");x=Q(M,"hyper-version")}catch{x=null}Gn(A,{checkedAt:r,sourceVersion:x})}return x?{available:Ut(x,s||"0.0.0"),currentVersion:s,sourceVersion:x,sourceUrl:c.href}:null}var De=["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"],it=new Set(De),qt=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Wt=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Be={};ze(Be,{EmptyListInsert:()=>we,MAX_RULE_DEPTH:()=>be,MaxRuleDepthExceeded:()=>ue,RuleTargetReadOnly:()=>ve,RulesParseError:()=>ye,ShapeMismatch:()=>xe,UnknownRulesVersion:()=>le});var ye=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},le=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},be=20,ue=class extends Error{constructor(t){super(`rule depth exceeded ${be} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},xe=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},we=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}},ve=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function X(e,t,n,o={}){return at(e,t,n,{depth:0,path:[]},o)}function at(e,t,n,o,r){if(o.depth>be)throw new ue(o.path);if(typeof n=="string")return Yn(e,t,n,r);if(Array.isArray(n)){let[i,a]=n;return e.find(t,i,r).map((c,A)=>at(e,c,a,{depth:o.depth+1,path:[...o.path,A]},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 Yn(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 Vt(e,t,n.slice(1));let r=oe(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:Vt(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 Vt(e,t,n){if(it.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Zn(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Qn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var Xn={find(e,t,n={}){let o=Qn(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Zn(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}},W=Xn;function ct(e){try{return JSON.parse(e)}catch(t){throw new ye(`Invalid strict JSON: ${t.message}`,t)}}function fe(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 w=!1,m=a+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(w=!0),!w){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 w=s,m=a+1;for(;m<r.length&&r[m]!==w;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(a+1,m),quoted:!0,sourceQuote:w}),a=m+1;continue}let c=a,A;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let w=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],m=!1;for(let b of w){let M=b.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 w=r[c];for(c++;c<r.length&&r[c]!==w;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;A=r.substring(a,c);let x=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(A)?x=t.NUMBER:A==="true"||A==="false"||A==="null"?x=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(A)&&(x=t.SELECTOR),i.push({type:x,value:A,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,(A,x)=>x.length%2===0?x+'\\"':A)),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 ye("Invalid extraction rules syntax: "+r.message,r)}}var lt="1",Kt=/^[a-zA-Z0-9_-]+$/;function Ae(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Kt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Kt})`);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!==lt)throw new le(a);return{rules:fe(e.text(i)),tagNode:i}}var er="script[data-rules-name]";function zt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function Oe(e,t){let n=e.find(t,er,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let a=zt(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!==lt)throw new le(s);o.add(a),r.push({name:a,rules:fe(e.text(i))})}return r}function Fe(e,t){let n={};for(let{name:o,rules:r}of Oe(e,t))n[o]=X(e,t,r);return n}function ut(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Fe(W,t),version:Q(n,"hyper-version")}}var Se=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},Re=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}},ie=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},Te=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 Jt="text/hyper-upgrade";function ft(e,t){let n=e.find(t,`script[type="${Jt}"]`);if(n.length===0)return null;if(n.length>1)throw new Te(n.length);return e.text(n[0])||null}var tr=new Function("url","return import(url)");async function dt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await tr(n)}catch(r){throw new ie(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new ie("transform must `export default` a function");return o.default}var nr=.5;function ht(e,t,n,o,r,i,a,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(I=>e.remove(I));return}let A=r.length>c.length,x=c[0]||null;if(A&&!x&&(x=ir(e,t,n,s),!x))throw new we(i.path);let w=c.map(I=>rr(e,I,o,s)),m=null;if(x){m=e.clone(x),s.templateAttr&&e.removeAttr(m,s.templateAttr);let I=e.stripIds(m);I>0&&console.warn(`[hyper-html-api] stripped ${I} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let b=or(r,w,o),M=c[0]||x,L=e.parent(M),j=c.length>0?Yt(e,L,M):0,P=ar(e,c),D=new Set,V=[],Y=r.map((I,K)=>{let U=b[K];if(U>=0)return D.add(U),V.push(!1),c[U];V.push(!0);let ee=e.clone(m);return e.stripIds(ee),ee});if(c.forEach((I,K)=>{D.has(K)||e.remove(I)}),P){Y.forEach((I,K)=>{let U=j+K;e.children(L).findIndex(qe=>e.sameNode(qe,I))!==U&&e.insertAt(L,I,U)}),Gt(e,Y,o,r,i,a,s);return}cr(e,Y,V,L,j),Gt(e,Y,o,r,i,a,s)}function Gt(e,t,n,o,r,i,a){t.forEach((s,c)=>{if(n===null){let A=o[c],x=A==null?"":String(A);e.text(s)!==x&&e.text(s,x)}else{let A=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},a);A&&A!==s&&(t[c]=A)}})}function rr(e,t,n,o){return n===null?e.text(t):X(e,t,n,o)}function or(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((A,x)=>{if(r.has(x))return;let w=sr(i,A,n),m=w===c&&s>=0?Math.abs(x-a)<Math.abs(s-a):!1;(w>c||m)&&(c=w,s=x)}),c>=nr&&(o[a]=s,r.add(s))}),o}function sr(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 Yt(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 ir(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 ar(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 cr(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 A=i?Yt(e,c,i)+1:a++;e.insertAt(c,t[s],A),i=t[s]}}var Zt=new Set(["checked","selected","disabled","readOnly","paused"]);function ae(e,t,n,o,r={}){let i=[];if(pt(n,o,[],i),i.length)throw new xe(i);Ue(e,t,n,o,{depth:0,path:[]},r)}function Ue(e,t,n,o,r,i={}){if(r.depth>be)throw new ue(r.path);if(o===void 0)return t;if(typeof n=="string")return lr(e,t,n,o,r,i);if(Array.isArray(n)){let[a,s]=n;return ht(e,t,a,s,o,r,Ue,i),t}if(typeof n=="object"&&n!==null){for(let[a,s]of Object.entries(n)){let c=Ue(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 lr(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return ht(e,t,c,null,o,r,Ue,i),t}if(n.startsWith("@"))return Qt(e,t,n.slice(1),o);let a=oe(n);if(a!==-1){let c=n.slice(0,a),A=n.slice(a+1),x=c?e.find(t,c,i):[t];return x.length===0||Qt(e,x[0],A,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 Qt(e,t,n,o){if(Wt.has(n))throw new ve(n);if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}return qt.has(n)?(e.prop(t,n,ur(n,o)),t):(e.attr(t,n,o==null?"":String(o)),t)}function ur(e,t){return t==null?Zt.has(e)?!1:"":Zt.has(e)?!!t:t}function pt(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:ke([...n,i]),expected:"scalar",got:Ne(r)})}):o.push({path:ke(n),expected:"array",got:Ne(t)});return}t!==null&&typeof t=="object"&&o.push({path:ke(n),expected:"scalar",got:Ne(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:ke(n),expected:"array",got:Ne(t)});return}let r=e[1];t.forEach((i,a)=>pt(r,i,[...n,a],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:ke(n),expected:"object",got:Ne(t)});return}for(let[r,i]of Object.entries(e))pt(i,t[r],[...n,r],o)}}}function Ne(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function ke(e){return e.join(".")}function Ie(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=mt(t,e,n);return gt(t,e,n),{data:o,summary:n}}function mt(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=>mt(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let a=mt(i,t?.[r],n);a!==void 0&&(o[r]=a)}return o}}function gt(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)?gt(e[r],t[r],n):n.discarded+=de(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>gt(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=de(t))}}function de(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+de(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+de(n),0):1}function yt(e,t,n){let o=Oe(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:A,summary:x}=Ie(n[s],c);ae(e,t,c,A),i[s]=x,r.carriedOver+=x.carriedOver,r.discarded+=x.discarded,r.listItems+=x.listItems}for(let s of Object.keys(n))a.has(s)||(r.discarded+=de(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function bt({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||(P=>fetch(P)),!o)throw new Error("upgrade.run requires a document context");if(e=e||Q(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:Q(o,"hyper-version"),t=t||Fe(W,o);let s;try{s=await i(a.href)}catch(P){throw new Se(a.href,P)}if(!s.ok)throw new Se(a.href,new Error(`HTTP ${s.status}`));let c=await s.text(),A=new DOMParser().parseFromString(c,"text/html"),x=Q(A,"hyper-version"),w=t,m=!1,b=ft(W,A);if(b){let D=await(await dt(b))(w,{fromVersion:n,toVersion:x});if(!D||typeof D!="object"||Array.isArray(D))throw new ie("transform must return a plain object map of { rulesName: data }");w=D,m=!0}let{totals:M,byName:L,rulesTagCount:j}=yt(W,A,w);if(j===0&&Object.keys(w).length>0)throw new Re(a.href);return{html:fr(A),fromVersion:n,toVersion:x,summary:{transformApplied:m,totals:M,byName:L}}}function fr(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
4
+ `+e.documentElement.outerHTML}function At(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 Ae(e,o,n)}return null}function Xt(e,t,n,o){let r=At(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:()=>X(e,t,i,o),set:s=>ae(e,t,i,s,o)}}var Ce={extract:(e,t,n)=>X(W,e,t,n),apply:(e,t,n,o)=>ae(W,e,t,n,o),findRulesIn:(e,t)=>Ae(W,e,t),findRules:(e,t)=>At(W,e,t),bind:(e,t,n)=>Xt(W,e,t,n),parseStrict:ct,parseRelaxed:fe,ruleAttrIndex:oe,splitRule:me,errors:Be,DOM_PROPERTIES:De},St=e=>!!e&&typeof e.nodeType=="number";function en(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=W.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 Ae(W,t).rules}function Et(e,t){let n=St(e)?e:document,o=St(e)?t:e;return o===void 0?X(W,n,en(n)):Ce.bind(n,o).get()}function Mt(e,t,n){if(!St(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?ae(W,e,en(e),t):Ce.bind(e,n).set(t),e}var tn={buildForm:Ge,bindFormEvents:Ye,scaffold:pe,morphForm:rt,path:He},nn={checkForUpdate:st,run:bt,extractAll:ut,shapeMatch:Ie};var pr={engine:Ce,cms:tn,upgrade:nn,extractData:Et,applyData:Mt},mr=pr;return un(gr);})();
@@ -1,2 +1,2 @@
1
- var hyperHtmlApiUpgrade=(()=>{var Y=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var ie=(e,t)=>{for(var r in t)Y(e,r,{get:t[r],enumerable:!0})},be=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of we(t))!Se.call(e,n)&&n!==r&&Y(e,n,{get:()=>t[n],enumerable:!(o=Te(t,n))||o.enumerable});return e};var Ie=e=>be(Y({},"__esModule",{value:!0}),e);var Qe={};ie(Qe,{default:()=>Xe,engine:()=>re,upgrade:()=>Oe});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"],z=new Set(W),ce=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),le=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var B={};ie(B,{EmptyListInsert:()=>j,MAX_RULE_DEPTH:()=>P,MaxRuleDepthExceeded:()=>w,RuleTargetReadOnly:()=>C,RulesParseError:()=>_,ShapeMismatch:()=>L,UnknownRulesVersion:()=>T});var _=class extends Error{constructor(t,r){super(t),this.name="RulesParseError",this.cause=r}},T=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},P=20,w=class extends Error{constructor(t){super(`rule depth exceeded ${P} 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 E(e,t,r,o={}){return G(e,t,r,{depth:0,path:[]},o)}function G(e,t,r,o,n){if(o.depth>P)throw new w(o.path);if(typeof r=="string")return Ne(e,t,r,n);if(Array.isArray(r)){let[i,c]=r;return e.find(t,i,n).map((l,u)=>G(e,l,c,{depth:o.depth+1,path:[...o.path,u]},n))}if(typeof r=="object"&&r!==null){let i={};for(let[c,s]of Object.entries(r))i[c]=G(e,t,s,{depth:o.depth+1,path:[...o.path,c]},n);return i}return null}function Ne(e,t,r,o){if(r.endsWith("[]")){let i=r.slice(0,-2);return e.find(t,i,o).map(c=>e.text(c))}if(r.startsWith("@"))return fe(e,t,r.slice(1));if(r.includes("@")){let i=r.lastIndexOf("@"),c=r.slice(0,i),s=r.slice(i+1),l=c?e.find(t,c,o):[t];return l.length===0?null:fe(e,l[0],s)}if(r===".")return e.text(t);let n=e.find(t,r,o);return n.length===0?null:e.text(n[0])}function fe(e,t,r){if(z.has(r)){let n=e.prop(t,r);return n==null?null:String(n)}let o=e.attr(t,r);return o||null}var Me=.5;function X(e,t,r,o,n,i,c,s={}){let l=e.find(t,r,s);if(n.length===0){l.forEach(p=>e.remove(p));return}let u=n.length>l.length,f=l[0]||null;if(u&&!f&&(f=je(e,t,r,s),!f))throw new j(i.path);let d=l.map(p=>_e(e,p,o,s)),a=null;if(f){a=e.clone(f),s.templateAttr&&e.removeAttr(a,s.templateAttr);let p=e.stripIds(a);p>0&&console.warn(`[hyper-html-api] stripped ${p} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let R=Pe(n,d,o),y=l[0]||f,N=e.parent(y),K=l.length>0?Le(e,N,y):0,A=new Set,O=n.map((p,g)=>{let h=R[g];if(h>=0)return A.add(h),l[h];let M=e.clone(a);return e.stripIds(M),M});l.forEach((p,g)=>{A.has(g)||e.remove(p)}),O.forEach((p,g)=>{let h=K+g;e.children(N).findIndex(Ae=>e.sameNode(Ae,p))!==h&&e.insertAt(N,p,h)}),O.forEach((p,g)=>{if(o===null){let h=n[g],M=h==null?"":String(h);e.text(p)!==M&&e.text(p,M)}else{let h=c(e,p,o,n[g],{depth:i.depth+1,path:[...i.path,g]},s);h&&h!==p&&(O[g]=h)}})}function _e(e,t,r,o){return r===null?e.text(t):E(e,t,r,o)}function Pe(e,t,r){let o=new Array(e.length).fill(-1),n=new Set;return e.forEach((i,c)=>{let s=-1,l=-1;t.forEach((u,f)=>{if(n.has(f))return;let d=De(i,u,r),a=d===l&&s>=0?Math.abs(f-c)<Math.abs(s-c):!1;(d>l||a)&&(l=d,s=f)}),l>=Me&&(o[c]=s,n.add(s))}),o}function De(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 i of o)JSON.stringify(e?.[i])===JSON.stringify(t?.[i])&&n++;return n/o.length}function Le(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 je(e,t,r,o){if(!o.templateAttr)return null;let n=t;for(;n;){let i=e.find(n,r,{includeRulesTag:!1,templateAttr:null});for(let c of i)if(e.attr(c,o.templateAttr)!=null)return c;n=e.parent(n)}return null}var ae=new Set(["checked","selected","disabled","readOnly","paused"]);function S(e,t,r,o,n={}){let i=[];if(Q(r,o,[],i),i.length)throw new L(i);q(e,t,r,o,{depth:0,path:[]},n)}function q(e,t,r,o,n,i={}){if(n.depth>P)throw new w(n.path);if(o===void 0)return t;if(typeof r=="string")return Ce(e,t,r,o,n,i);if(Array.isArray(r)){let[c,s]=r;return X(e,t,c,s,o,n,q,i),t}if(typeof r=="object"&&r!==null){for(let[c,s]of Object.entries(r)){let l=q(e,t,s,o==null?o:o[c],{depth:n.depth+1,path:[...n.path,c]},i);l&&l!==t&&(t=l)}return t}return t}function Ce(e,t,r,o,n,i){if(r.endsWith("[]")){let s=r.slice(0,-2);return X(e,t,s,null,o,n,q,i),t}if(r.startsWith("@"))return ue(e,t,r.slice(1),o);if(r.includes("@")){let s=r.lastIndexOf("@"),l=r.slice(0,s),u=r.slice(s+1),f=l?e.find(t,l,i):[t];return f.length===0||ue(e,f[0],u,o),t}if(r===".")return e.text(t,o==null?"":String(o)),t;let c=e.find(t,r,i);return c.length===0||e.text(c[0],o==null?"":String(o)),t}function ue(e,t,r,o){if(le.has(r))throw new C(r);if(r==="outerHTML"){let n=o==null?"":String(o);return e.replaceWith(t,n)}return ce.has(r)?(e.prop(t,r,ke(r,o)),t):(e.attr(t,r,o==null?"":String(o)),t)}function ke(e,t){return t==null?ae.has(e)?!1:"":ae.has(e)?!!t:t}function Q(e,t,r,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((n,i)=>{typeof n=="object"&&n!==null&&o.push({path:$([...r,i]),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((i,c)=>Q(n,i,[...r,c],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,i]of Object.entries(e))Q(i,t[n],[...r,n],o)}}}function k(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function $(e){return e.join(".")}function Z(e){try{return JSON.parse(e)}catch(t){throw new _(`Invalid strict JSON: ${t.message}`,t)}}function b(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(n){let i=[],c=0;for(;c<n.length;){let s=n[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let d=!1,a=c+1;for(;a<n.length&&/\s/.test(n[a]);)a++;if(a<n.length&&/[a-zA-Z_]/.test(n[a])&&(d=!0),!d){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:t.COLON,value:s}),c++;continue}if(s===","){i.push({type:t.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let d=s,a=c+1;for(;a<n.length&&n[a]!==d;)n[a]==="\\"&&a++,a++;i.push({type:t.STRING,value:n.substring(c+1,a),quoted:!0,sourceQuote:d}),c=a+1;continue}let l=c,u;for(;l<n.length&&!/[{},]/.test(n[l]);)if(n[l]===":"){let d=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],a=!1;for(let R of d){let y=R.substring(1);if(n.substring(l+1,l+1+y.length)===y){a=!0,l+=y.length;break}}if(!a)break}else if(n[l]==="["){for(l++;l<n.length&&n[l]!=="]";){if(n[l]==='"'||n[l]==="'"){let d=n[l];for(l++;l<n.length&&n[l]!==d;)n[l]==="\\"&&l++,l++}l++}l<n.length&&n[l]==="]"&&l++}else l++;u=n.substring(c,l);let f=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(u)?f=t.NUMBER:u==="true"||u==="false"||u==="null"?f=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(u)&&(f=t.SELECTOR),i.push({type:f,value:u,quoted:!1}),c=l}return i}function o(n){let i="";for(let c=0;c<n.length;c++){let s=n[c];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let l=n[c+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(u,f)=>f.length%2===0?f+'\\"':u)),i+=`"${l}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let n=r(e),i=o(n);return JSON.parse(i)}catch(n){throw new _("Invalid extraction rules syntax: "+n.message,n)}}var ee="1",de=/^[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"||!de.test(r))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(r)} (must match ${de})`);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 i=n[0],c=e.attr(i,"data-rules-version");if(c!==ee)throw new T(c);return{rules:b(e.text(i)),tagNode:i}}function te(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 pe(e,t,r,o){let n=te(e,t,r);if(!n){let s=typeof r=="string"?`data-rules-name~="${r}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:c}=n;return{rules:i,tagNode:c,get:()=>E(e,t,i,o),set:s=>S(e,t,i,s,o)}}function Ue(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function He(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var We={find(e,t,r={}){let o=He(e);if(!o||!o.querySelectorAll)return[];let n=Array.from(o.querySelectorAll(t));r.includeRulesTag||(n=n.filter(s=>!Ue(s)));let i=[];r.skip&&i.push(r.skip);let c=r.templateAttr===null?null:r.templateAttr||"cms-template";if(c&&i.push("["+c+"]"),i.length){let s=i.join(", ");n=n.filter(l=>!l.closest||!l.closest(s))}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}},m=We;var re={extract:(e,t,r)=>E(m,e,t,r),apply:(e,t,r,o)=>S(m,e,t,r,o),findRulesIn:(e,t)=>U(m,e,t),findRules:(e,t)=>te(m,e,t),bind:(e,t,r)=>pe(m,e,t,r),parseStrict:Z,parseRelaxed:b,errors:B,DOM_PROPERTIES:W};var Be="hha:upgrade-check:";function x(e,t){let r=e.querySelector(`meta[name="${t}"]`),o=r?r.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function he(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function qe(e,t){let r=he(e),o=he(t);if(!r||!o)return!1;let n=Math.max(r.length,o.length);for(let i=0;i<n;i++){let c=r[i]||0,s=o[i]||0;if(c!==s)return c>s}return!1}function Fe(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Je(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function me({force:e=!1,doc:t,loc:r,fetchFn:o,now:n,ttlMs:i=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 c=x(t,"hyper-source");if(!c)return null;let s=x(t,"hyper-version"),l;try{l=new URL(c,r?r.href:void 0)}catch{return null}if(r&&l.origin===r.origin&&l.pathname===r.pathname)return null;let u=`${Be}${l.href}:${s||"none"}`,f,d=e?null:Fe(u);if(d&&typeof d.checkedAt=="number"&&n-d.checkedAt<i)f=d.sourceVersion;else{try{let a=await o(l.href);if(!a.ok)throw new Error(`HTTP ${a.status}`);let R=await a.text(),y=new DOMParser().parseFromString(R,"text/html");f=x(y,"hyper-version")}catch{f=null}Je(u,{checkedAt:n,sourceVersion:f})}return f?{available:qe(f,s||"0.0.0"),currentVersion:s,sourceVersion:f,sourceUrl:l.href}:null}var Ve="script[data-rules-name]";function ve(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function F(e,t){let r=e.find(t,Ve,{includeRulesTag:!0}),o=new Set,n=[];for(let i of r){let c=ve(e.attr(i,"data-rules-name"));if(!c)continue;if(o.has(c)){console.warn(`hyper-html-api: duplicate rules tag name "${c}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==ee)throw new T(s);o.add(c),n.push({name:c,rules:b(e.text(i))})}return n}function ne(e,t){let r={};for(let{name:o,rules:n}of F(e,t))r[o]=E(e,t,n);return r}function ye(e){let t=e||document,r=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:ne(m,t),version:x(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}},J=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}},I=class extends Error{constructor(t,r){super(t),this.name="UpgradeTransformInvalid",this.cause=r}},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 Ke="text/hyper-upgrade";function ge(e,t){let r=e.find(t,`script[type="${Ke}"]`);if(r.length===0)return null;if(r.length>1)throw new V(r.length);return e.text(r[0])||null}var Ye=new Function("url","return import(url)");async function Ee(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t),o;try{o=await Ye(r)}catch(n){throw new I(`transform failed to load: ${n&&n.message?n.message:n}`,n)}finally{URL.revokeObjectURL(r)}if(typeof o.default!="function")throw new I("transform must `export default` a function");return o.default}function v(e,t){let r={carriedOver:0,discarded:0,listItems:0},o=oe(t,e,r);return se(t,e,r),{data:o,summary:r}}function oe(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=>oe(o,n,r))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[n,i]of Object.entries(e)){let c=oe(i,t?.[n],r);c!==void 0&&(o[n]=c)}return o}}function se(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)?se(e[n],t[n],r):r.discarded+=D(t[n]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(n=>se(o,n,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=D(t))}}function D(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+D(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+D(r),0):1}function xe(e,t,r){let o=F(e,t),n={carriedOver:0,discarded:0,listItems:0},i={},c=new Set;for(let{name:s,rules:l}of o){if(c.add(s),!Object.prototype.hasOwnProperty.call(r,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:u,summary:f}=v(r[s],l);S(e,t,l,u),i[s]=f,n.carriedOver+=f.carriedOver,n.discarded+=f.discarded,n.listItems+=f.listItems}for(let s of Object.keys(r))c.has(s)||(n.discarded+=D(r[s]));return{totals:n,byName:i,rulesTagCount:o.length}}async function Re({sourceUrl:e,dataByName:t,fromVersion:r,doc:o,loc:n,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),i=i||(A=>fetch(A)),!o)throw new Error("upgrade.run requires a document context");if(e=e||x(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let c=new URL(e,n?n.href:void 0);r=r!==void 0?r:x(o,"hyper-version"),t=t||ne(m,o);let s;try{s=await i(c.href)}catch(A){throw new H(c.href,A)}if(!s.ok)throw new H(c.href,new Error(`HTTP ${s.status}`));let l=await s.text(),u=new DOMParser().parseFromString(l,"text/html"),f=x(u,"hyper-version"),d=t,a=!1,R=ge(m,u);if(R){let O=await(await Ee(R))(d,{fromVersion:r,toVersion:f});if(!O||typeof O!="object"||Array.isArray(O))throw new I("transform must return a plain object map of { rulesName: data }");d=O,a=!0}let{totals:y,byName:N,rulesTagCount:K}=xe(m,u,d);if(K===0&&Object.keys(d).length>0)throw new J(c.href);return{html:ze(u),fromVersion:r,toVersion:f,summary:{transformApplied:a,totals:y,byName:N}}}function ze(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
- `+e.documentElement.outerHTML}var Oe={checkForUpdate:me,run:Re,extractAll:ye,shapeMatch:v};var Ge={engine:re,upgrade:Oe},Xe=Ge;return Ie(Qe);})();
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 Ie={checkForUpdate:Ae,run:be,extractAll:Oe,shapeMatch:G};var nt={engine:ie,upgrade:Ie},ot=nt;return Le(st);})();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "apply",
10
10
  "CMS"
11
11
  ],
12
- "version": "0.5.2",
12
+ "version": "0.6.1",
13
13
  "homepage": "https://github.com/panphora/hyper-html-api",
14
14
  "bugs": {
15
15
  "url": "https://github.com/panphora/hyper-html-api/issues"
@@ -19,7 +19,8 @@
19
19
  "LICENSE",
20
20
  "README.md",
21
21
  "src/**/*.js",
22
- "dist/*.js"
22
+ "dist/*.js",
23
+ "conformance/**"
23
24
  ],
24
25
  "main": "src/hyper-html-api.js",
25
26
  "module": "src/hyper-html-api.js",
@@ -48,7 +49,9 @@
48
49
  "test:webkit": "web-test-runner --playwright --browsers webkit",
49
50
  "test:all": "web-test-runner --concurrency 1 --playwright --browsers chromium firefox webkit",
50
51
  "test:node": "node --test 'test-node/**/*.test.js'",
51
- "test:ci": "npm run test:node && npm run test:all -- --fail-only && node test/lib/ensure-full-coverage.cjs",
52
+ "conformance:generate": "node scripts/conformance.mjs generate",
53
+ "conformance:check": "node scripts/conformance.mjs check",
54
+ "test:ci": "npm run test:node && npm run conformance:check && npm run test:all -- --fail-only && node test/lib/ensure-full-coverage.cjs",
52
55
  "test:coverage": "npm run test:chrome && node test/lib/ensure-full-coverage.cjs",
53
56
  "format": "prettier --write .",
54
57
  "format:check": "prettier --check ."
@@ -65,7 +68,7 @@
65
68
  "@web/test-runner-playwright": "^0.11.0",
66
69
  "chai": "^4.3.6",
67
70
  "chai-dom": "^1.11.0",
68
- "cheerio": "^1.0.0-rc.12",
71
+ "cheerio": "1.2.0",
69
72
  "esbuild": "^0.24.0",
70
73
  "http-server": "^14.1.1",
71
74
  "jsdom": "^29.0.2",
@@ -30,6 +30,7 @@ import {
30
30
  } from './path.js'
31
31
  import { scaffold } from './scaffold.js'
32
32
  import { widgetHandles } from './widget-handles.js'
33
+ import { splitRule } from '../engine/rule-syntax.js'
33
34
 
34
35
  const BOOL_PROPS = new Set(['checked', 'selected', 'disabled', 'readOnly', 'paused'])
35
36
 
@@ -367,7 +368,7 @@ function invokeWidget(widget, ctx) {
367
368
  function widgetFor(rule, appRoot) {
368
369
  let propName = null
369
370
  if (rule.startsWith('@')) propName = rule.slice(1)
370
- else if (rule.includes('@')) propName = rule.split('@')[1] || null
371
+ else propName = splitRule(rule).prop
371
372
 
372
373
  if (propName && BOOL_PROPS.has(propName)) return { type: 'checkbox' }
373
374
  if (propName === 'innerHTML') return { type: 'textarea' }
@@ -399,7 +400,7 @@ function queryTarget(rule, appRoot) {
399
400
  if (!appRoot) return null
400
401
  if (rule === '.' || rule === '') return null
401
402
  if (rule.startsWith('@')) return null
402
- const selector = rule.includes('@') ? rule.split('@')[0] : rule
403
+ const selector = splitRule(rule).selector
403
404
  if (!selector) return null
404
405
  try {
405
406
  return appRoot.querySelector(selector)
package/src/dom-api.js CHANGED
@@ -12,6 +12,11 @@ export const engine = {
12
12
  bind: (root, source, opts) => engineMod.bind(domAdapter, root, source, opts),
13
13
  parseStrict: engineMod.parseStrict,
14
14
  parseRelaxed: engineMod.parseRelaxed,
15
+ // Adapter-free, like the parsers above: a consumer that has to split a rule
16
+ // the way the engine does needs this, and reimplementing it is exactly how
17
+ // four copies of the split drifted apart.
18
+ ruleAttrIndex: engineMod.ruleAttrIndex,
19
+ splitRule: engineMod.splitRule,
15
20
  errors: engineMod.errors,
16
21
  DOM_PROPERTIES: engineMod.DOM_PROPERTIES,
17
22
  }
@@ -9,6 +9,7 @@ import {
9
9
  ShapeMismatch,
10
10
  } from './errors.js'
11
11
  import { listDiff } from './diff.js'
12
+ import { ruleAttrIndex } from './rule-syntax.js'
12
13
 
13
14
  const BOOLEAN_PROPS = new Set(['checked', 'selected', 'disabled', 'readOnly', 'paused'])
14
15
 
@@ -64,8 +65,8 @@ function applyScalar(adapter, ctx, rule, value, trace, opts) {
64
65
  return writePropOrAttr(adapter, ctx, rule.slice(1), value)
65
66
  }
66
67
 
67
- if (rule.includes('@')) {
68
- const at = rule.lastIndexOf('@')
68
+ const at = ruleAttrIndex(rule)
69
+ if (at !== -1) {
69
70
  const selector = rule.slice(0, at)
70
71
  const name = rule.slice(at + 1)
71
72
  const matches = selector ? adapter.find(ctx, selector, opts) : [ctx]